Skip to content

Commit

Permalink
Remove container argument from startSort
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedsalem401 committed Sep 19, 2024
1 parent f2ed0b1 commit 88d91c9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/commands/view/SelectPosition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default {
});

if (opts.onStart) this.sorter.onStart = opts.onStart;
trg && this.sorter.startSort(trg, { container });
trg && this.sorter.startSort(trg);
},

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/Droppable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export default class Droppable {
}
})
let dropModel = this.getTempDropModel(content);
sorter.startSort(dropModel.view?.el, { container: this.el });
sorter.startSort(dropModel.view?.el);
this.sorter = sorter;
dragStop = () => {
sorter.endMove();
Expand Down
24 changes: 17 additions & 7 deletions packages/core/src/utils/sorter/Sorter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,8 @@ export default class Sorter<T>{
* Picking component to move
* @param {HTMLElement} sourceElement
* */
startSort(sourceElement?: HTMLElement, options: { container?: HTMLElement } = {}) {
// Check if the start element is a valid one, if not, try the closest valid one
if (sourceElement && !matches(sourceElement, `${this.containerContext.itemSel}, ${this.containerContext.containerSel}`)) {
sourceElement = closest(sourceElement, this.containerContext.itemSel)!;
}
startSort(sourceElement?: HTMLElement) {
sourceElement = this.findValidSourceElement(sourceElement);

const sourceModel = $(sourceElement).data("model");
const sourceNode = new this.treeClass(sourceModel);
Expand All @@ -119,9 +116,22 @@ export default class Sorter<T>{
this.dropLocationDeterminer.startSort(sourceNode);
this.bindDragEventHandlers(docs);

if (this.eventHandlers && isFunction(this.eventHandlers.onStartSort)) {
this.eventHandlers.onStartSort(this.sourceNode!, this.containerContext.container)
this.eventHandlers?.onStartSort?.(this.sourceNode, this.containerContext.container);
this.em.trigger('sorter:drag:start', sourceElement, sourceModel);
}

/**
* Finds the closest valid source element within the container context.
* @param sourceElement - The initial source element to check.
* @returns The closest valid source element, or null if none is found.
*/
private findValidSourceElement(sourceElement?: HTMLElement): HTMLElement | undefined {
if (sourceElement && !matches(sourceElement, `${this.containerContext.itemSel}, ${this.containerContext.containerSel}`)) {
sourceElement = closest(sourceElement, this.containerContext.itemSel)!;
}

return sourceElement;
}

private bindDragEventHandlers(docs: Document[]) {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/utils/sorter/SorterUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ export function getMergedOptions<T>(sorterOptions: RequiredEmAndTreeClassPartial
ignoreViewChildren: false,
selectOnEnd: true,
},
eventHandlers: {}
};

const mergedOptions: Omit<SorterOptions<T>, 'em' | 'treeClass'> = {
Expand Down

0 comments on commit 88d91c9

Please sign in to comment.