@kaskad/component-tree 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/esm2022/index.js +12 -0
- package/esm2022/index.js.map +1 -0
- package/esm2022/kaskad-component-tree.js +5 -0
- package/esm2022/kaskad-component-tree.js.map +1 -0
- package/esm2022/lib/component-lookup/index.js +68 -0
- package/esm2022/lib/component-lookup/index.js.map +1 -0
- package/esm2022/lib/component-lookup/traverses/array-traverser.js +18 -0
- package/esm2022/lib/component-lookup/traverses/array-traverser.js.map +1 -0
- package/esm2022/lib/component-lookup/traverses/component-traverser.js +120 -0
- package/esm2022/lib/component-lookup/traverses/component-traverser.js.map +1 -0
- package/esm2022/lib/component-lookup/traverses/index.js +29 -0
- package/esm2022/lib/component-lookup/traverses/index.js.map +1 -0
- package/esm2022/lib/component-lookup/traverses/object-traverser.js +22 -0
- package/esm2022/lib/component-lookup/traverses/object-traverser.js.map +1 -0
- package/esm2022/lib/component-lookup/types.js +1 -0
- package/esm2022/lib/component-lookup/types.js.map +1 -0
- package/esm2022/lib/component-tree-api.js +121 -0
- package/esm2022/lib/component-tree-api.js.map +1 -0
- package/esm2022/lib/computation/computation-frame.js +27 -0
- package/esm2022/lib/computation/computation-frame.js.map +1 -0
- package/esm2022/lib/computation/computation-stack.js +83 -0
- package/esm2022/lib/computation/computation-stack.js.map +1 -0
- package/esm2022/lib/computation/index.js +3 -0
- package/esm2022/lib/computation/index.js.map +1 -0
- package/esm2022/lib/config.js +6 -0
- package/esm2022/lib/config.js.map +1 -0
- package/esm2022/lib/mobx/component.js +110 -0
- package/esm2022/lib/mobx/component.js.map +1 -0
- package/esm2022/lib/mobx/create-root-node.js +21 -0
- package/esm2022/lib/mobx/create-root-node.js.map +1 -0
- package/esm2022/lib/mobx/ref-space.js +25 -0
- package/esm2022/lib/mobx/ref-space.js.map +1 -0
- package/esm2022/lib/mobx/store.js +827 -0
- package/esm2022/lib/mobx/store.js.map +1 -0
- package/esm2022/lib/node/create-node-options.js +16 -0
- package/esm2022/lib/node/create-node-options.js.map +1 -0
- package/esm2022/lib/node/creators/array-creator.js +9 -0
- package/esm2022/lib/node/creators/array-creator.js.map +1 -0
- package/esm2022/lib/node/creators/command-creator.js +16 -0
- package/esm2022/lib/node/creators/command-creator.js.map +1 -0
- package/esm2022/lib/node/creators/component-creator.js +58 -0
- package/esm2022/lib/node/creators/component-creator.js.map +1 -0
- package/esm2022/lib/node/creators/leaf-creator.js +5 -0
- package/esm2022/lib/node/creators/leaf-creator.js.map +1 -0
- package/esm2022/lib/node/creators/map-creator.js +14 -0
- package/esm2022/lib/node/creators/map-creator.js.map +1 -0
- package/esm2022/lib/node/creators/object-creator.js +17 -0
- package/esm2022/lib/node/creators/object-creator.js.map +1 -0
- package/esm2022/lib/node/creators/set-creator.js +13 -0
- package/esm2022/lib/node/creators/set-creator.js.map +1 -0
- package/esm2022/lib/node/creators/shape-creator.js +15 -0
- package/esm2022/lib/node/creators/shape-creator.js.map +1 -0
- package/esm2022/lib/node/creators/variant-shape-creator.js +23 -0
- package/esm2022/lib/node/creators/variant-shape-creator.js.map +1 -0
- package/esm2022/lib/node/guards.js +5 -0
- package/esm2022/lib/node/guards.js.map +1 -0
- package/esm2022/lib/node/node-creation.js +47 -0
- package/esm2022/lib/node/node-creation.js.map +1 -0
- package/esm2022/lib/node/node-type.js +1 -0
- package/esm2022/lib/node/node-type.js.map +1 -0
- package/esm2022/lib/node/node.js +305 -0
- package/esm2022/lib/node/node.js.map +1 -0
- package/esm2022/lib/parsers/index.js +3 -0
- package/esm2022/lib/parsers/index.js.map +1 -0
- package/esm2022/lib/parsers/node-selector.types.js +1 -0
- package/esm2022/lib/parsers/node-selector.types.js.map +1 -0
- package/esm2022/lib/parsers/parse-component-selector.js +43 -0
- package/esm2022/lib/parsers/parse-component-selector.js.map +1 -0
- package/esm2022/lib/parsers/parse-node-selector.js +263 -0
- package/esm2022/lib/parsers/parse-node-selector.js.map +1 -0
- package/esm2022/lib/types/command.js +1 -0
- package/esm2022/lib/types/command.js.map +1 -0
- package/esm2022/lib/types/index.js +5 -0
- package/esm2022/lib/types/index.js.map +1 -0
- package/esm2022/lib/types/node.guards.js +7 -0
- package/esm2022/lib/types/node.guards.js.map +1 -0
- package/esm2022/lib/types/schema.js +1 -0
- package/esm2022/lib/types/schema.js.map +1 -0
- package/esm2022/lib/util/extract-node-value.js +45 -0
- package/esm2022/lib/util/extract-node-value.js.map +1 -0
- package/esm2022/lib/util/format-source.js +7 -0
- package/esm2022/lib/util/format-source.js.map +1 -0
- package/esm2022/lib/util/get-component.js +8 -0
- package/esm2022/lib/util/get-component.js.map +1 -0
- package/esm2022/lib/util/id-generator.js +10 -0
- package/esm2022/lib/util/id-generator.js.map +1 -0
- package/esm2022/lib/util/traverse-node.js +50 -0
- package/esm2022/lib/util/traverse-node.js.map +1 -0
- package/index.d.ts +11 -0
- package/kaskad-component-tree.d.ts +5 -0
- package/lib/component-lookup/index.d.ts +8 -0
- package/lib/component-lookup/traverses/array-traverser.d.ts +3 -0
- package/lib/component-lookup/traverses/component-traverser.d.ts +3 -0
- package/lib/component-lookup/traverses/index.d.ts +9 -0
- package/lib/component-lookup/traverses/object-traverser.d.ts +3 -0
- package/lib/component-lookup/types.d.ts +13 -0
- package/lib/component-tree-api.d.ts +21 -0
- package/lib/computation/computation-frame.d.ts +14 -0
- package/lib/computation/computation-stack.d.ts +48 -0
- package/lib/computation/index.d.ts +2 -0
- package/lib/config.d.ts +4 -0
- package/lib/mobx/component.d.ts +45 -0
- package/lib/mobx/create-root-node.d.ts +3 -0
- package/lib/mobx/ref-space.d.ts +10 -0
- package/lib/mobx/store.d.ts +238 -0
- package/lib/node/create-node-options.d.ts +12 -0
- package/lib/node/creators/array-creator.d.ts +4 -0
- package/lib/node/creators/command-creator.d.ts +4 -0
- package/lib/node/creators/component-creator.d.ts +4 -0
- package/lib/node/creators/leaf-creator.d.ts +4 -0
- package/lib/node/creators/map-creator.d.ts +4 -0
- package/lib/node/creators/object-creator.d.ts +4 -0
- package/lib/node/creators/set-creator.d.ts +4 -0
- package/lib/node/creators/shape-creator.d.ts +4 -0
- package/lib/node/creators/variant-shape-creator.d.ts +4 -0
- package/lib/node/guards.d.ts +3 -0
- package/lib/node/node-creation.d.ts +4 -0
- package/lib/node/node-type.d.ts +49 -0
- package/lib/node/node.d.ts +107 -0
- package/lib/parsers/index.d.ts +5 -0
- package/lib/parsers/node-selector.types.d.ts +25 -0
- package/lib/parsers/parse-component-selector.d.ts +8 -0
- package/lib/parsers/parse-node-selector.d.ts +87 -0
- package/lib/types/command.d.ts +3 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/node.guards.d.ts +4 -0
- package/lib/types/schema.d.ts +13 -0
- package/lib/util/extract-node-value.d.ts +3 -0
- package/lib/util/format-source.d.ts +1 -0
- package/lib/util/get-component.d.ts +4 -0
- package/lib/util/id-generator.d.ts +5 -0
- package/lib/util/traverse-node.d.ts +26 -0
- package/package.json +26 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/component-tree/src/lib/computation/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC","sourcesContent":["export * from './computation-frame';\nexport * from './computation-stack';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../../libs/component-tree/src/lib/config.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,UAAU,EAAE,CAAC,KAAkB,EAAE,GAAG,KAAgB,EAAoB,EAAE;QACxE,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;IACtF,CAAC;CACF,CAAC","sourcesContent":["import { CommandNode } from './node/node';\n\nexport const componentTreeConfig = {\n runCommand: (_node: CommandNode, ..._args: unknown[]): Promise<unknown> => {\n throw new Error('runCommand is not implemented. Please provide an implementation.');\n },\n};\n"]}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { action, makeObservable, observable } from 'mobx';
|
|
2
|
+
import { parseNodeSelector } from '../parsers';
|
|
3
|
+
import { formatSource } from '../util/format-source';
|
|
4
|
+
import { traverseNode } from '../util/traverse-node';
|
|
5
|
+
export class TComponent {
|
|
6
|
+
id;
|
|
7
|
+
position;
|
|
8
|
+
refSpaceId;
|
|
9
|
+
sourceUrl;
|
|
10
|
+
componentType;
|
|
11
|
+
props;
|
|
12
|
+
variables;
|
|
13
|
+
onNodeChange;
|
|
14
|
+
handlerDisposers = [];
|
|
15
|
+
constructor(config) {
|
|
16
|
+
this.id = config.id;
|
|
17
|
+
this.position = config.position;
|
|
18
|
+
this.refSpaceId = config.refSpaceId;
|
|
19
|
+
this.sourceUrl = config.sourceUrl ?? null;
|
|
20
|
+
this.componentType = config.componentType;
|
|
21
|
+
this.props = config.props;
|
|
22
|
+
this.variables = config.variables;
|
|
23
|
+
this.onNodeChange = config.onNodeChange;
|
|
24
|
+
makeObservable(this, {
|
|
25
|
+
props: observable.shallow,
|
|
26
|
+
variables: observable.shallow,
|
|
27
|
+
setVariable: action,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
setVariable(variableName, node) {
|
|
31
|
+
this.variables.set(variableName, node);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Find a node by selector. Returns null if the node is not found.
|
|
35
|
+
* This is an alias for getNode for consistency with ComponentStore's API.
|
|
36
|
+
*/
|
|
37
|
+
findNode(nodeSelector) {
|
|
38
|
+
const parsed = parseNodeSelector(nodeSelector);
|
|
39
|
+
return this.findNodeFromParsed(parsed);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get a node by selector. Throws an error if the node is not found.
|
|
43
|
+
* Use findNode() for optional lookups that return null instead of throwing.
|
|
44
|
+
*
|
|
45
|
+
* Note: Even if the selector contains optional chaining (?.), this method will throw
|
|
46
|
+
* if the node is not found. Use findNode() for optional chaining support.
|
|
47
|
+
*/
|
|
48
|
+
getNode(nodeSelector) {
|
|
49
|
+
const parsed = parseNodeSelector(nodeSelector);
|
|
50
|
+
return this.getNodeFromParsed(parsed);
|
|
51
|
+
}
|
|
52
|
+
findNodeFromParsed(parsed) {
|
|
53
|
+
// Handle variable access
|
|
54
|
+
if (parsed.kind === 'variable') {
|
|
55
|
+
const varNode = this.variables.get(parsed.head);
|
|
56
|
+
if (!varNode) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return traverseNode(varNode, parsed.tail);
|
|
60
|
+
}
|
|
61
|
+
// Handle property access
|
|
62
|
+
const propNode = this.props.get(parsed.head);
|
|
63
|
+
if (!propNode) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
return traverseNode(propNode, parsed.tail);
|
|
67
|
+
}
|
|
68
|
+
getNodeFromParsed(parsed) {
|
|
69
|
+
const src = formatSource(this.sourceUrl);
|
|
70
|
+
// Handle variable access
|
|
71
|
+
if (parsed.kind === 'variable') {
|
|
72
|
+
const varNode = this.variables.get(parsed.head);
|
|
73
|
+
if (!varNode) {
|
|
74
|
+
throw new Error(`${src} Variable '${parsed.head}' does not exist in component '${this.id}' (type: ${this.componentType})`);
|
|
75
|
+
}
|
|
76
|
+
const result = traverseNode(varNode, parsed.tail);
|
|
77
|
+
if (!result) {
|
|
78
|
+
throw new Error(`${src} Node not found for variable path '${parsed.head}${parsed.tail.map((s) => `.${s.key}`).join('')}' in component '${this.id}'`);
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
// Handle property access - strict mode, always throw if not found
|
|
83
|
+
const propNode = this.props.get(parsed.head);
|
|
84
|
+
if (!propNode) {
|
|
85
|
+
throw new Error(`${src} Property '${parsed.head}' does not exist on component '${this.id}' (type: ${this.componentType}). ` +
|
|
86
|
+
`Available properties: [${Array.from(this.props.keys()).join(', ')}]`);
|
|
87
|
+
}
|
|
88
|
+
const result = traverseNode(propNode, parsed.tail);
|
|
89
|
+
if (!result) {
|
|
90
|
+
throw new Error(`${src} Node not found for property path '${parsed.head}${parsed.tail.map((s) => `.${s.key}`).join('')}' in component '${this.id}'`);
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
getNodeValue(nodeSelector) {
|
|
95
|
+
// Use findNode to support optional chaining and return null if not found
|
|
96
|
+
const node = this.findNode(nodeSelector);
|
|
97
|
+
return node ? node.extractedValue : null;
|
|
98
|
+
}
|
|
99
|
+
dispose() {
|
|
100
|
+
this.handlerDisposers.forEach((disposer) => disposer());
|
|
101
|
+
this.handlerDisposers = [];
|
|
102
|
+
for (const [, prop] of this.props.entries()) {
|
|
103
|
+
prop.dispose();
|
|
104
|
+
}
|
|
105
|
+
for (const [, variable] of this.variables.entries()) {
|
|
106
|
+
variable.dispose();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../../../../../libs/component-tree/src/lib/mobx/component.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAqB,cAAc,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAG7E,OAAO,EAAgB,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE7D,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAarD,MAAM,OAAO,UAAU;IACZ,EAAE,CAAc;IAChB,QAAQ,CAAe;IACvB,UAAU,CAAa;IAChC,SAAS,CAAgB;IACzB,aAAa,CAAS;IACtB,KAAK,CAAuC;IAC5C,SAAS,CAAuC;IAChD,YAAY,CAAsB;IAClC,gBAAgB,GAAwB,EAAE,CAAC;IAE3C,YAAY,MAA6B;QACvC,IAAI,CAAC,EAAE,GAAG,MAAM,CAAC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CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YAC5C,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,CAAC;QAED,KAAK,MAAM,CAAC,EAAE,QAAQ,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,CAAC;YACpD,QAAQ,CAAC,OAAO,EAAE,CAAC;QACrB,CAAC;IACH,CAAC;CACF","sourcesContent":["import { ComponentId, NodePosition, RefSpaceId, ValueType } from '@kaskad/types';\nimport { action, IReactionDisposer, makeObservable, observable } from 'mobx';\n\nimport { AbstractNode } from '../node/node';\nimport { NodeSelector, parseNodeSelector } from '../parsers';\nimport { NodeChangeHandler } from '../types';\nimport { formatSource } from '../util/format-source';\nimport { traverseNode } from '../util/traverse-node';\n\nexport interface ComponentCreateConfig {\n id: ComponentId;\n componentType: string;\n position: NodePosition;\n refSpaceId: RefSpaceId;\n props: Map<string, AbstractNode<ValueType>>;\n variables: Map<string, AbstractNode<ValueType>>;\n onNodeChange: NodeChangeHandler[];\n sourceUrl?: string;\n}\n\nexport class TComponent {\n readonly id: ComponentId;\n readonly position: NodePosition;\n readonly refSpaceId: RefSpaceId;\n sourceUrl: string | null;\n componentType: string;\n props: Map<string, AbstractNode<ValueType>>;\n variables: Map<string, AbstractNode<ValueType>>;\n onNodeChange: NodeChangeHandler[];\n handlerDisposers: IReactionDisposer[] = [];\n\n constructor(config: ComponentCreateConfig) {\n this.id = config.id;\n this.position = config.position;\n this.refSpaceId = config.refSpaceId;\n this.sourceUrl = config.sourceUrl ?? null;\n this.componentType = config.componentType;\n this.props = config.props;\n this.variables = config.variables;\n this.onNodeChange = config.onNodeChange;\n\n makeObservable(this, {\n props: observable.shallow,\n variables: observable.shallow,\n setVariable: action,\n });\n }\n\n setVariable(variableName: string, node: AbstractNode<ValueType>) {\n this.variables.set(variableName, node);\n }\n\n /**\n * Find a node by selector. Returns null if the node is not found.\n * This is an alias for getNode for consistency with ComponentStore's API.\n */\n findNode(nodeSelector: string): AbstractNode<ValueType> | null {\n const parsed = parseNodeSelector(nodeSelector);\n return this.findNodeFromParsed(parsed);\n }\n\n /**\n * Get a node by selector. Throws an error if the node is not found.\n * Use findNode() for optional lookups that return null instead of throwing.\n *\n * Note: Even if the selector contains optional chaining (?.), this method will throw\n * if the node is not found. Use findNode() for optional chaining support.\n */\n getNode(nodeSelector: string): AbstractNode<ValueType> {\n const parsed = parseNodeSelector(nodeSelector);\n return this.getNodeFromParsed(parsed);\n }\n\n findNodeFromParsed(parsed: Omit<NodeSelector, 'componentSelector'>): AbstractNode<ValueType> | null {\n // Handle variable access\n if (parsed.kind === 'variable') {\n const varNode = this.variables.get(parsed.head);\n if (!varNode) {\n return null;\n }\n\n return traverseNode(varNode, parsed.tail);\n }\n\n // Handle property access\n const propNode = this.props.get(parsed.head);\n if (!propNode) {\n return null;\n }\n\n return traverseNode(propNode, parsed.tail);\n }\n\n getNodeFromParsed(parsed: Omit<NodeSelector, 'componentSelector'>): AbstractNode<ValueType> {\n const src = formatSource(this.sourceUrl);\n\n // Handle variable access\n if (parsed.kind === 'variable') {\n const varNode = this.variables.get(parsed.head);\n if (!varNode) {\n throw new Error(\n `${src} Variable '${parsed.head}' does not exist in component '${this.id}' (type: ${this.componentType})`,\n );\n }\n\n const result = traverseNode(varNode, parsed.tail);\n if (!result) {\n throw new Error(\n `${src} Node not found for variable path '${parsed.head}${parsed.tail.map((s) => `.${s.key}`).join('')}' in component '${this.id}'`,\n );\n }\n return result;\n }\n\n // Handle property access - strict mode, always throw if not found\n const propNode = this.props.get(parsed.head);\n if (!propNode) {\n throw new Error(\n `${src} Property '${parsed.head}' does not exist on component '${this.id}' (type: ${this.componentType}). ` +\n `Available properties: [${Array.from(this.props.keys()).join(', ')}]`,\n );\n }\n\n const result = traverseNode(propNode, parsed.tail);\n if (!result) {\n throw new Error(\n `${src} Node not found for property path '${parsed.head}${parsed.tail.map((s) => `.${s.key}`).join('')}' in component '${this.id}'`,\n );\n }\n return result;\n }\n\n getNodeValue<T>(nodeSelector: string): T | null {\n // Use findNode to support optional chaining and return null if not found\n const node = this.findNode(nodeSelector);\n return node ? (node.extractedValue as T) : null;\n }\n\n dispose() {\n this.handlerDisposers.forEach((disposer) => disposer());\n this.handlerDisposers = [];\n\n for (const [, prop] of this.props.entries()) {\n prop.dispose();\n }\n\n for (const [, variable] of this.variables.entries()) {\n variable.dispose();\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createNode } from '../node/node-creation';
|
|
2
|
+
import { RefSpace } from './ref-space';
|
|
3
|
+
import { ComponentStore } from './store';
|
|
4
|
+
export function createRootNode(refSpaceId, schema, ownerComponentId, parentRefSpaceId, sourceUrl) {
|
|
5
|
+
const opts = {
|
|
6
|
+
refSpaceId: refSpaceId,
|
|
7
|
+
position: { componentId: ownerComponentId, path: [] },
|
|
8
|
+
components: {},
|
|
9
|
+
refs: {},
|
|
10
|
+
sourceUrl,
|
|
11
|
+
};
|
|
12
|
+
const root = createNode(schema, opts);
|
|
13
|
+
const refSpace = new RefSpace(refSpaceId, parentRefSpaceId);
|
|
14
|
+
const store = ComponentStore.getInstance();
|
|
15
|
+
store.addRefSpace(refSpace);
|
|
16
|
+
store.addComponents(opts.components);
|
|
17
|
+
const refs = opts.refs[refSpaceId] ?? {};
|
|
18
|
+
refSpace.addRefs(refs);
|
|
19
|
+
return root;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=create-root-node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-root-node.js","sourceRoot":"","sources":["../../../../../../libs/component-tree/src/lib/mobx/create-root-node.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,MAAM,UAAU,cAAc,CAC5B,UAAsB,EACtB,MAAkB,EAClB,gBAAoC,EACpC,gBAAmC,EACnC,SAAkB;IAElB,MAAM,IAAI,GAAsB;QAC9B,UAAU,EAAE,UAAU;QACtB,QAAQ,EAAE,EAAE,WAAW,EAAE,gBAAgB,EAAE,IAAI,EAAE,EAAE,EAAE;QACrD,UAAU,EAAE,EAAE;QACd,IAAI,EAAE,EAAE;QACR,SAAS;KACV,CAAC;IACF,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACtC,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC;IAC5D,MAAM,KAAK,GAAG,cAAc,CAAC,WAAW,EAAE,CAAC;IAE3C,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC5B,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAErC,MAAM,IAAI,GAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAA8D,IAAI,EAAE,CAAC;IACvG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { ComponentId, ComponentRef, NodeSchema, RefSpaceId, ValueType } from '@kaskad/types';\n\nimport { CreateNodeOptions } from '../node/create-node-options';\nimport { AbstractNode } from '../node/node';\nimport { createNode } from '../node/node-creation';\nimport { RefSpace } from './ref-space';\nimport { ComponentStore } from './store';\n\nexport function createRootNode(\n refSpaceId: RefSpaceId,\n schema: NodeSchema,\n ownerComponentId: ComponentId | null,\n parentRefSpaceId: RefSpaceId | null,\n sourceUrl?: string,\n): AbstractNode<ValueType> {\n const opts: CreateNodeOptions = {\n refSpaceId: refSpaceId,\n position: { componentId: ownerComponentId, path: [] },\n components: {},\n refs: {},\n sourceUrl,\n };\n const root = createNode(schema, opts);\n const refSpace = new RefSpace(refSpaceId, parentRefSpaceId);\n const store = ComponentStore.getInstance();\n\n store.addRefSpace(refSpace);\n store.addComponents(opts.components);\n\n const refs = (opts.refs[refSpaceId] as unknown as Record<ComponentRef, ComponentId> | undefined) ?? {};\n refSpace.addRefs(refs);\n\n return root;\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { observable, runInAction } from 'mobx';
|
|
2
|
+
export class RefSpace {
|
|
3
|
+
id;
|
|
4
|
+
parentRefSpaceId;
|
|
5
|
+
byRef;
|
|
6
|
+
constructor(id, parentRefSpaceId = null) {
|
|
7
|
+
this.id = id;
|
|
8
|
+
this.parentRefSpaceId = parentRefSpaceId;
|
|
9
|
+
this.byRef = observable.map({}, { name: 'by-ref-map', deep: false });
|
|
10
|
+
}
|
|
11
|
+
get refs() {
|
|
12
|
+
return this.byRef;
|
|
13
|
+
}
|
|
14
|
+
addRefs(refs) {
|
|
15
|
+
runInAction(() => {
|
|
16
|
+
for (const ref in refs) {
|
|
17
|
+
this.byRef.set(ref, refs[ref]);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
getComponentIdByRef(ref) {
|
|
22
|
+
return this.byRef.get(ref) || null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=ref-space.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ref-space.js","sourceRoot":"","sources":["../../../../../../libs/component-tree/src/lib/mobx/ref-space.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAE/C,MAAM,OAAO,QAAQ;IAIV;IACA;IAJQ,KAAK,CAAiC;IAEvD,YACS,EAAc,EACd,mBAAsC,IAAI;QAD1C,OAAE,GAAF,EAAE,CAAY;QACd,qBAAgB,GAAhB,gBAAgB,CAA0B;QAEjD,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACvE,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,OAAO,CAAC,IAAuC;QAC7C,WAAW,CAAC,GAAG,EAAE;YACf,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;gBACvB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YACjC,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,mBAAmB,CAAC,GAAW;QAC7B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;IACrC,CAAC;CACF","sourcesContent":["import { ComponentId, ComponentRef, RefSpaceId } from '@kaskad/types';\nimport { observable, runInAction } from 'mobx';\n\nexport class RefSpace {\n private readonly byRef: Map<ComponentRef, ComponentId>;\n\n constructor(\n public id: RefSpaceId,\n public parentRefSpaceId: RefSpaceId | null = null,\n ) {\n this.byRef = observable.map({}, { name: 'by-ref-map', deep: false });\n }\n\n get refs() {\n return this.byRef;\n }\n\n addRefs(refs: Record<ComponentRef, ComponentId>) {\n runInAction(() => {\n for (const ref in refs) {\n this.byRef.set(ref, refs[ref]);\n }\n });\n }\n\n getComponentIdByRef(ref: string): ComponentId | null {\n return this.byRef.get(ref) || null;\n }\n}\n"]}
|