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

Method createNode

packages/core/src/document/document.ts:183–218  ·  view source on GitHub ↗
(schema: NodeSchema, checkId = true)

Source from the content-addressed store, hash-verified

181
182 @action
183 createNode(schema: NodeSchema, checkId = true) {
184 if (schema?.id && this.hasNode(schema.id)) {
185 schema.id = undefined
186 }
187
188 let node: Node | null = null
189 let isNewNode = false
190
191 if (schema?.id) {
192 node = this.getNode(schema.id)
193 if (node && node.componentName === schema.componentName) {
194 if (node.parent) {
195 node.internalSetParent(null, false)
196 }
197 node.import(schema, checkId)
198 } else if (node) {
199 node = null
200 }
201 }
202
203 if (!node) {
204 node = new Node(this, schema)
205 isNewNode = true
206 }
207
208 this.nodes.add(node)
209 this._nodesMap.set(node.id, node)
210 this.emitter.emit(NODE_EVENT.ADD, node)
211
212 // 追踪物料使用:仅对新创建的节点增加使用计数
213 if (isNewNode && node.componentName) {
214 this.designer.materials.incrementUsage(node.materialUsageKey)
215 }
216
217 return node
218 }
219
220 getNode(id: string) {
221 return this._nodesMap.get(id) || null

Callers 9

constructorMethod · 0.95
replaceChildMethod · 0.80
insertChildFunction · 0.80
ensureNodeFunction · 0.80
constructorMethod · 0.80
importMethod · 0.80
mergeChildrenMethod · 0.80
valueFunction · 0.80
executeOperationFunction · 0.80

Calls 8

hasNodeMethod · 0.95
getNodeMethod · 0.95
internalSetParentMethod · 0.80
setMethod · 0.65
incrementUsageMethod · 0.65
importMethod · 0.45
addMethod · 0.45
emitMethod · 0.45

Tested by

no test coverage detected