| 36 | } |
| 37 | |
| 38 | export class SplootNode { |
| 39 | parent: ParentReference |
| 40 | type: string |
| 41 | matchingID: string |
| 42 | properties: { [key: string]: any } // Depends on the type |
| 43 | childSets: { [key: string]: ChildSet } |
| 44 | childSetOrder: string[] |
| 45 | childSetWrapPriorityOrder: string[] |
| 46 | enableMutations: boolean |
| 47 | mutationObservers: NodeObserver[] |
| 48 | isValid: boolean |
| 49 | invalidReason: string |
| 50 | invalidChildSetID: string |
| 51 | invalidChildIndex: number |
| 52 | invalidNode: number |
| 53 | isRepeatableBlock: boolean |
| 54 | metadata: Map<string, any> |
| 55 | |
| 56 | constructor(parent: ParentReference, type: string) { |
| 57 | this.parent = parent |
| 58 | this.type = type |
| 59 | this.matchingID = generateMatchingID() |
| 60 | this.isValid = true |
| 61 | this.invalidReason = '' |
| 62 | this.childSets = {} |
| 63 | this.childSetOrder = [] |
| 64 | this.childSetWrapPriorityOrder = null |
| 65 | this.properties = {} |
| 66 | this.enableMutations = false |
| 67 | this.mutationObservers = [] |
| 68 | this.isRepeatableBlock = false |
| 69 | this.metadata = new Map() |
| 70 | } |
| 71 | |
| 72 | get hasChildSets(): boolean { |
| 73 | return this.childSetOrder.length !== 0 |
| 74 | } |
| 75 | |
| 76 | addChildSet(name: string, type: ChildSetType, category: NodeCategory, minChildren = 0, maxChildren = -1) { |
| 77 | this.childSets[name] = new ChildSet(this, name, type, category, minChildren, maxChildren) |
| 78 | this.childSetOrder.push(name) |
| 79 | } |
| 80 | |
| 81 | getChildrenToKeepOnDelete(): SplootNode[] { |
| 82 | return [] |
| 83 | } |
| 84 | |
| 85 | getWrapInsertChildSet(childNode: SplootNode): ChildSet { |
| 86 | const order = this.childSetWrapPriorityOrder ? this.childSetWrapPriorityOrder : this.childSetOrder |
| 87 | for (const childSetID of order) { |
| 88 | const childSet = this.getChildSet(childSetID) |
| 89 | if (childSet.getCount() === 0) { |
| 90 | if (isAdaptableToPasteDesintation(childNode, childSet.nodeCategory)) { |
| 91 | return childSet |
| 92 | } |
| 93 | } else { |
| 94 | const firstChild = childSet.getChild(0) |
| 95 | if (firstChild.isEmpty()) { |
nothing calls this directly
no outgoing calls
no test coverage detected