-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6960f22
commit dfe5e3a
Showing
11 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './mutation'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { TreeNode } from '../../models' | ||
import { IEngineContext } from '../../types' | ||
|
||
export interface IMutationNodeEventData { | ||
//事件发生的数据源 | ||
source: TreeNode | TreeNode[] | ||
//事件发生的目标对象 | ||
target: TreeNode | TreeNode[] | ||
// 事件发生的来源对象 | ||
originSourceParents?: TreeNode | TreeNode[] | ||
//扩展数据 | ||
extra?: any | ||
} | ||
|
||
export class AbstractMutationNodeEvent { | ||
data: IMutationNodeEventData | ||
context: IEngineContext | ||
constructor(data: IMutationNodeEventData) { | ||
this.data = data | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { AbstractMutationNodeEvent } from './AbstractMutationNodeEvent'; | ||
import { ICustomEvent } from '@/app/shared/event'; | ||
|
||
export class DragNodeEvent extends AbstractMutationNodeEvent implements ICustomEvent { | ||
type = 'drag:node'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './DragNodeEvent'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './engine'; | ||
export * from './tree-node'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { uid } from '@/app/shared/uid'; | ||
|
||
export interface ITreeNode { | ||
componentName?: string; | ||
sourceName?: string; | ||
operation?: any; | ||
hidden?: boolean; | ||
isSourceNode?: boolean; | ||
id?: string; | ||
props?: Record<string | number | symbol, any>; | ||
children?: ITreeNode[]; | ||
} | ||
|
||
const TreeNodes = new Map<string, TreeNode>(); | ||
|
||
export class TreeNode { | ||
parent: TreeNode; | ||
|
||
root: TreeNode; | ||
|
||
rootOperation: any; | ||
|
||
id: string; | ||
|
||
depth = 0; | ||
|
||
hidden = false; | ||
|
||
componentName = 'NO_NAME_COMPONENT'; | ||
|
||
sourceName = ''; | ||
|
||
props: ITreeNode['props'] = {}; | ||
|
||
children: TreeNode[] = []; | ||
|
||
isSelfSourceNode: boolean; | ||
|
||
constructor(node?: ITreeNode, parent?: TreeNode) { | ||
if (node instanceof TreeNode) { | ||
return node; | ||
} | ||
this.id = node.id || uid(); | ||
if (parent) { | ||
this.parent = parent; | ||
this.depth = parent.depth + 1; | ||
this.root = parent.root; | ||
TreeNodes.set(this.id, this); | ||
} else { | ||
this.root = this; | ||
this.rootOperation = node.operation; | ||
this.isSelfSourceNode = node.isSourceNode || false; | ||
TreeNodes.set(this.id, this); | ||
} | ||
if (node) { | ||
} | ||
} | ||
|
||
get previous() { | ||
if (this.parent === this || !this.parent) return null; | ||
return this.parent.children[this.index - 1]; | ||
} | ||
|
||
get next() { | ||
if (this.parent === this || !this.parent) return null; | ||
return this.parent.children[this.index + 1]; | ||
} | ||
|
||
get siblings() { | ||
if (this.parent) { | ||
return this.parent.children.filter(node => node !== this); | ||
} | ||
return []; | ||
} | ||
|
||
get index() { | ||
if (this.parent === this || !this.parent) return 0; | ||
return this.parent.children.indexOf(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface ICustomEvent<EventData = any, EventContext = any> { | ||
type: string; | ||
data?: EventData; | ||
context?: EventContext; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
let IDX = 36, | ||
HEX = '' | ||
while (IDX--) HEX += IDX.toString(36) | ||
|
||
export function uid(len?: number) { | ||
let str = '', | ||
num = len || 11 | ||
while (num--) str += HEX[(Math.random() * 36) | 0] | ||
return str | ||
} |