Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
clauderic committed Sep 18, 2024
1 parent d302511 commit 8b44605
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
18 changes: 16 additions & 2 deletions packages/abstract/src/core/plugins/registry.ts
Original file line number Diff line number Diff line change
@@ -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<
Expand All @@ -19,7 +24,16 @@ export class PluginRegistry<
#previousValues: PluginConstructor<T>[] = [];

public set values(entries: Plugins<T>) {
const descriptors = entries.map(descriptor);
const descriptors = entries
.map(descriptor)
.reduceRight<PluginDescriptor<T>[]>((acc, descriptor) => {
if (acc.some(({plugin}) => plugin === descriptor.plugin)) {
// Filter out duplicate plugins
return acc;
}

return [descriptor, ...acc];
}, []);
const constructors = descriptors.map(({plugin}) => plugin);

for (const plugin of this.#previousValues) {
Expand Down
12 changes: 9 additions & 3 deletions packages/dom/src/core/plugins/feedback/Feedback.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -364,8 +364,12 @@ export class Feedback extends Plugin<DragDropManager, FeedbackOptions> {

styles.reset();

if (moved && element.isConnected) {
placeholder?.replaceWith(element);
if (
placeholder &&
(moved || placeholder.parentElement !== element.parentElement) &&
element.isConnected
) {
placeholder.replaceWith(element);
}

placeholder?.remove();
Expand Down Expand Up @@ -480,6 +484,8 @@ export class Feedback extends Plugin<DragDropManager, FeedbackOptions> {
style?.remove();
};
}

static configure = configurator(Feedback);
}

function createPlaceholder(source: Draggable) {
Expand Down

0 comments on commit 8b44605

Please sign in to comment.