| 16 | } |
| 17 | |
| 18 | export class Node<Schema extends NodeSchema = NodeSchema> { |
| 19 | protected emitter = createEventBus('Node') |
| 20 | |
| 21 | readonly isNode = true |
| 22 | |
| 23 | readonly id: string |
| 24 | |
| 25 | readonly componentName: string |
| 26 | |
| 27 | protected _children: NodeChildren | null |
| 28 | |
| 29 | @observable.ref private accessor _parent: Node | null = null |
| 30 | |
| 31 | get parent() { |
| 32 | return this._parent |
| 33 | } |
| 34 | |
| 35 | get children() { |
| 36 | return this._children |
| 37 | } |
| 38 | |
| 39 | get childrenNodes() { |
| 40 | return this._children ? this._children.children : [] |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * if the node is the root node or not linked, return -1 |
| 45 | */ |
| 46 | @computed |
| 47 | get index() { |
| 48 | if (!this.parent) { |
| 49 | return -1 |
| 50 | } |
| 51 | |
| 52 | return this.parent!.children!.indexOf(this) |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * z-index level of this node |
| 57 | */ |
| 58 | @computed |
| 59 | get zLevel(): number { |
| 60 | if (this._parent) { |
| 61 | return this._parent.zLevel + 1 |
| 62 | } |
| 63 | return 0 |
| 64 | } |
| 65 | |
| 66 | @computed |
| 67 | get title() { |
| 68 | const t = this.getExtraProp('title') |
| 69 | if (t) { |
| 70 | const v = t.getAsString() |
| 71 | if (v) { |
| 72 | return v |
| 73 | } |
| 74 | } |
| 75 | return this.componentMeta.title |
nothing calls this directly
no test coverage detected