Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedsalem401 committed Dec 6, 2024
1 parent 84a6926 commit 1664be8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 4 additions & 1 deletion packages/core/src/block_manager/view/BlockView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ export default class BlockView extends View<Block> {
const el = dropModel.view?.el;
const sources = el ? [{ element: el, dragSource: { content } }] : [];
const selected = em.getSelected();
let target, valid, insertAt, index = 0;
let target,
valid,
insertAt,
index = 0;

// If there is a selected component, try first to append
// the block inside, otherwise, try to place it as a next sibling
Expand Down
12 changes: 8 additions & 4 deletions packages/core/src/utils/sorter/Sorter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,25 @@ export default class Sorter<T, NodeType extends SortableTreeNode<T>> {
this.em.trigger('sorter:drag:start', sources[0], sourcesWithModel[0]);
}

validTarget(targetEl: HTMLElement | undefined, sources: { element?: HTMLElement; dragSource?: DragSource<T> }[], index: number): boolean {
validTarget(
targetEl: HTMLElement | undefined,
sources: { element?: HTMLElement; dragSource?: DragSource<T> }[],
index: number,
): boolean {
if (!targetEl) return false;
const targetModel = $(targetEl).data('model');
if (!targetModel) return false;

const targetNode = new this.treeClass(targetModel)
const targetNode = new this.treeClass(targetModel);
const { sourceNodes } = this.getSourceNodes(sources);
const canMove = sourceNodes.some((node) => targetNode.canMove(node, index));
return canMove;
}

private getSourceNodes(sources: { element?: HTMLElement; dragSource?: DragSource<T>; }[]) {
private getSourceNodes(sources: { element?: HTMLElement; dragSource?: DragSource<T> }[]) {
const validSources = sources.filter((source) => !!source.dragSource || this.findValidSourceElement(source.element));

const sourcesWithModel: { model: T; content?: any; }[] = validSources.map((source) => {
const sourcesWithModel: { model: T; content?: any }[] = validSources.map((source) => {
return {
model: $(source.element)?.data('model'),
content: source.dragSource,
Expand Down

0 comments on commit 1664be8

Please sign in to comment.