Skip to content

Commit

Permalink
Add back the tree class paramater instead of abstract classes
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedsalem401 committed Sep 16, 2024
1 parent ef40cea commit d289046
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/commands/view/SelectPosition.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { $ } from '../../common';
import { SorterDirection } from '../../utils/sorter/Sorter';
import { SorterDirection } from '../../utils/sorter/types';
import { CommandObject } from './CommandAbstract';
export default {
/**
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/utils/sorter/ComponentSorter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default class ComponentSorter extends Sorter<Component> {
super({
// @ts-ignore
em,
treeClass: ComponentNode,
containerContext,
positionOptions,
dragBehavior,
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/utils/sorter/DropLocationDeterminer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { matches, findPosition, offset, isInFlow } from './SorterUtils';

interface DropLocationDeterminerOptions<T> {
em: EditorModel;
treeClass: (model: any) => TreeSorterBase<T>;
treeClass: new (model: any) => TreeSorterBase<T>;
containerContext: SorterContainerContext;
positionOptions: PositionOptions;
dragBehavior: SorterDragBehaviorOptions;
Expand All @@ -19,7 +19,7 @@ interface DropLocationDeterminerOptions<T> {

export class DropLocationDeterminer<T> extends View {
em?: EditorModel;
treeClass!: (model: any) => TreeSorterBase<T>;
treeClass!: new (model: any) => TreeSorterBase<T>;

positionOptions!: PositionOptions;
containerContext!: SorterContainerContext;
Expand Down Expand Up @@ -53,7 +53,7 @@ export class DropLocationDeterminer<T> extends View {
* */
startSort(sourceElement?: HTMLElement) {
const sourceModel = $(sourceElement).data('model')
const sourceNode = this.treeClass(sourceModel);
const sourceNode = new this.treeClass(sourceModel);
this.sourceNode = sourceNode;

this.bindDragEventHandlers(this.docs);
Expand All @@ -76,7 +76,7 @@ export class DropLocationDeterminer<T> extends View {
if (!mouseTargetEl) return

const mouseTargetModel = $(mouseTargetEl)?.data("model");
const mouseTargetNode = this.treeClass(mouseTargetModel);
const mouseTargetNode = new this.treeClass(mouseTargetModel);
const targetNode = this.getValidParentNode(mouseTargetNode);
if (!targetNode) return
const dims = this.dimsFromTarget(targetNode.getElement()!);
Expand Down
15 changes: 6 additions & 9 deletions packages/core/src/utils/sorter/Sorter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ export type RequiredEmAndTreeClassPartialSorterOptions<T> = Partial<SorterOption

export default class Sorter<T> extends View {
em!: EditorModel;
treeClass!: new (model: T) => TreeSorterBase<T>;
placeholder!: PlaceholderClass;
dropLocationDeterminer!: DropLocationDeterminer<T>;

positionOptions!: PositionOptions;
containerContext!: SorterContainerContext;
dragBehavior!: SorterDragBehaviorOptions;
eventHandlers?: SorterEventHandlers<T>;

options!: SorterOptions<T>;
docs: any;
sourceNode?: TreeSorterBase<T>;

// TODO
// @ts-ignore
initialize(sorterOptions: RequiredEmAndTreeClassPartialSorterOptions<T> = {}) {
Expand All @@ -40,6 +40,7 @@ export default class Sorter<T> extends View {
this.eventHandlers = mergedOptions.eventHandlers;

this.em = sorterOptions.em;
this.treeClass = sorterOptions.treeClass;
var el = mergedOptions.containerContext.container;
this.el = typeof el === 'string' ? document.querySelector(el)! : el!;
this.updateOffset();
Expand All @@ -61,7 +62,7 @@ export default class Sorter<T> extends View {

this.dropLocationDeterminer = new DropLocationDeterminer({
em: this.em,
treeClass: this.getNodeFromModel,
treeClass: this.treeClass,
containerContext: this.containerContext,
positionOptions: this.positionOptions,
dragBehavior: this.dragBehavior,
Expand All @@ -79,10 +80,6 @@ export default class Sorter<T> extends View {
});
}

// TODO
getNodeFromModel(model: T) {
return '' as any;
}

private getContainerEl(elem?: HTMLElement) {
if (elem) this.el = elem;
Expand Down Expand Up @@ -119,7 +116,7 @@ export default class Sorter<T> extends View {
}

const sourceModel = $(sourceElement).data("model");
this.sourceNode = this.getNodeFromModel(sourceModel)
this.sourceNode = new this.treeClass(sourceModel)
const docs = getDocuments(this.em, sourceElement);
this.updateDocs(docs)
this.dropLocationDeterminer.startSort(sourceElement);
Expand Down
5 changes: 1 addition & 4 deletions packages/core/src/utils/sorter/StyleManagerSorter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default class StyleManagerSorter extends Sorter<Layers | Layer> {
super({
// @ts-ignore
em,
treeClass: LayerNode,
containerContext,
positionOptions,
dragBehavior,
Expand All @@ -42,10 +43,6 @@ export default class StyleManagerSorter extends Sorter<Layers | Layer> {
});
}

getNodeFromModel(model: Layer): LayerNode {
return new LayerNode(model);
}

onLayerStartSort = (sourceNode: LayerNode) => {
this.em.clearSelection();
this.em.trigger('sorter:drag:start', sourceNode?.getElement(), sourceNode?.getmodel());
Expand Down

0 comments on commit d289046

Please sign in to comment.