MCPcopy Create free account
hub / github.com/Easy-Editor/EasyEditor / NodeChildren

Class NodeChildren

packages/core/src/document/node/node-children.ts:11–326  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9}
10
11export class NodeChildren {
12 private emitter = createEventBus('NodeChildren')
13
14 readonly owner: Node
15
16 getNode() {
17 return this.owner
18 }
19
20 @observable.shallow accessor children: Node[] = []
21
22 @computed
23 get size(): number {
24 return this.children.length
25 }
26
27 get isEmptyNode(): boolean {
28 return this.size < 1
29 }
30
31 isEmpty() {
32 return this.isEmptyNode
33 }
34
35 constructor(owner: Node, data?: NodeSchema[]) {
36 this.owner = owner
37 this.children = (Array.isArray(data) ? data : []).map(child => {
38 return this.owner.document.createNode(child)
39 })
40 this.internalInitParent()
41 }
42
43 export(stage: TRANSFORM_STAGE = TRANSFORM_STAGE.SAVE) {
44 return this.children.map(node => {
45 const data = node.export(stage)
46 return data
47 })
48 }
49
50 @action
51 import(data?: NodeSchema | NodeSchema[], checkId = false) {
52 data = (data ? (Array.isArray(data) ? data : [data]) : []).filter(d => !!d)
53
54 const originChildren = this.children.slice()
55 this.children.forEach(child => child.internalSetParent(null))
56
57 const children = new Array<Node>(data.length)
58 for (let i = 0, l = data.length; i < l; i++) {
59 const child = originChildren[i]
60 const item = data[i]
61
62 let node: Node | undefined | null
63 if (isNodeSchema(item) && !checkId && child && child.componentName === item.componentName) {
64 node = child
65 node.import(item)
66 } else {
67 node = this.owner.document?.createNode(item, checkId)
68 }

Callers

nothing calls this directly

Calls 1

createEventBusFunction · 0.90

Tested by

no test coverage detected