Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
clauderic committed Jun 3, 2024
1 parent aa2a151 commit d349edf
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function Example({style = styles}) {

return (
<DragDropProvider
onDragOver={(event) => {
onDragEnd={(event) => {
const {source, target} = event.operation;

if (source && target) {
Expand Down
10 changes: 5 additions & 5 deletions packages/dom/src/core/entities/draggable/draggable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ export class Draggable<T extends Data = Data> extends AbstractDraggable<T> {
public sensors: Sensors | undefined;

constructor(
input: Input<T>,
{element, handle, feedback = 'default', sensors, ...input}: Input<T>,
public manager: AbstractDragDropManager<any, any>
) {
const {feedback = 'default'} = input;
const config = {...input, feedback};

super(config, manager);
super(input, manager);

this.element = element;
this.handle = handle;
this.feedback = feedback;
this.sensors = sensors;

const cleanupEffect = effect(() => {
const sensors = this.sensors?.map(descriptor) ?? [...manager.sensors];
Expand Down
5 changes: 5 additions & 0 deletions packages/dom/src/core/plugins/feedback/Feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ export class Feedback extends Plugin<DragDropManager> {
resizeObserver.disconnect();

styles.reset();

if (element.isConnected) {
placeholder.replaceWith(element);
}

placeholder.remove();
element.removeAttribute(ATTRIBUTE);

Expand Down
52 changes: 25 additions & 27 deletions packages/dom/src/sortable/sortable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,6 @@ export class Sortable<T extends Data = Data> {
@reactive
group: UniqueIdentifier | undefined;

@reactive
element: Element | undefined;

@reactive
source: Element | undefined;

@reactive
target: Element | undefined;

transition: SortableTransition | null;

constructor(
Expand Down Expand Up @@ -167,24 +158,6 @@ export class Sortable<T extends Data = Data> {
this.droppable.disabled = !target;
}
},
() => {
const {element} = this;

this.droppable.element = element;
this.draggable.element = element;
},
() => {
const {target} = this;
const element = untracked(() => this.element);

this.droppable.element = !target && element ? element : target;
},
() => {
const {source} = this;
const element = untracked(() => this.element);

this.draggable.element = !source && element ? element : source;
},
...(inputEffects?.(this) ?? [])
);

Expand Down Expand Up @@ -243,6 +216,31 @@ export class Sortable<T extends Data = Data> {
});
}

public set element(element: Element | undefined) {
this.draggable.element = element;
this.droppable.element = element;
}

public get element() {
return this.droppable.element ?? this.draggable.element;
}

public set target(target: Element | undefined) {
this.droppable.element = target;
}

public get target() {
return this.droppable.element;
}

public set source(source: Element | undefined) {
this.draggable.element = source;
}

public get source() {
return this.draggable.element;
}

public get disabled() {
return this.draggable.disabled && this.droppable.disabled;
}
Expand Down

0 comments on commit d349edf

Please sign in to comment.