diff --git a/packages/abstract/src/core/plugins/registry.ts b/packages/abstract/src/core/plugins/registry.ts index b80c86bf..4347d3de 100644 --- a/packages/abstract/src/core/plugins/registry.ts +++ b/packages/abstract/src/core/plugins/registry.ts @@ -1,6 +1,11 @@ import {DragDropManager} from '../manager/index.ts'; import {CorePlugin, type Plugin} from './plugin.ts'; -import type {InferPluginOptions, PluginConstructor, Plugins} from './types.ts'; +import type { + InferPluginOptions, + PluginDescriptor, + PluginConstructor, + Plugins, +} from './types.ts'; import {descriptor} from './utilities.ts'; export class PluginRegistry< @@ -19,7 +24,17 @@ export class PluginRegistry< #previousValues: PluginConstructor[] = []; public set values(entries: Plugins) { - const descriptors = entries.map(descriptor); + const descriptors = entries + .map(descriptor) + .reduceRight[]>((acc, descriptor) => { + if (acc.some(({plugin}) => plugin === descriptor.plugin)) { + // Filter out duplicate plugins + return acc; + } + + return [descriptor, ...acc]; + }, []) + .reverse(); const constructors = descriptors.map(({plugin}) => plugin); for (const plugin of this.#previousValues) { diff --git a/packages/dom/src/core/plugins/feedback/Feedback.ts b/packages/dom/src/core/plugins/feedback/Feedback.ts index 6336a4c7..88cf8d08 100644 --- a/packages/dom/src/core/plugins/feedback/Feedback.ts +++ b/packages/dom/src/core/plugins/feedback/Feedback.ts @@ -1,5 +1,5 @@ import {effect, untracked, type CleanupFunction} from '@dnd-kit/state'; -import {Plugin} from '@dnd-kit/abstract'; +import {configurator, Plugin} from '@dnd-kit/abstract'; import { animateTransform, cloneElement, @@ -364,8 +364,12 @@ export class Feedback extends Plugin { styles.reset(); - if (moved && element.isConnected) { - placeholder?.replaceWith(element); + if ( + placeholder && + (moved || placeholder.parentElement !== element.parentElement) && + element.isConnected + ) { + placeholder.replaceWith(element); } placeholder?.remove(); @@ -480,6 +484,8 @@ export class Feedback extends Plugin { style?.remove(); }; } + + static configure = configurator(Feedback); } function createPlaceholder(source: Draggable) {