@kaskad/component-tree 0.0.1 → 0.0.2

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.
Files changed (136) hide show
  1. package/fesm2022/kaskad-component-tree.mjs +2380 -0
  2. package/fesm2022/kaskad-component-tree.mjs.map +1 -0
  3. package/package.json +10 -10
  4. package/types/kaskad-component-tree.d.ts +582 -0
  5. package/esm2022/index.js +0 -12
  6. package/esm2022/index.js.map +0 -1
  7. package/esm2022/kaskad-component-tree.js +0 -5
  8. package/esm2022/kaskad-component-tree.js.map +0 -1
  9. package/esm2022/lib/component-lookup/index.js +0 -68
  10. package/esm2022/lib/component-lookup/index.js.map +0 -1
  11. package/esm2022/lib/component-lookup/traverses/array-traverser.js +0 -18
  12. package/esm2022/lib/component-lookup/traverses/array-traverser.js.map +0 -1
  13. package/esm2022/lib/component-lookup/traverses/component-traverser.js +0 -120
  14. package/esm2022/lib/component-lookup/traverses/component-traverser.js.map +0 -1
  15. package/esm2022/lib/component-lookup/traverses/index.js +0 -29
  16. package/esm2022/lib/component-lookup/traverses/index.js.map +0 -1
  17. package/esm2022/lib/component-lookup/traverses/object-traverser.js +0 -22
  18. package/esm2022/lib/component-lookup/traverses/object-traverser.js.map +0 -1
  19. package/esm2022/lib/component-lookup/types.js +0 -1
  20. package/esm2022/lib/component-lookup/types.js.map +0 -1
  21. package/esm2022/lib/component-tree-api.js +0 -121
  22. package/esm2022/lib/component-tree-api.js.map +0 -1
  23. package/esm2022/lib/computation/computation-frame.js +0 -27
  24. package/esm2022/lib/computation/computation-frame.js.map +0 -1
  25. package/esm2022/lib/computation/computation-stack.js +0 -83
  26. package/esm2022/lib/computation/computation-stack.js.map +0 -1
  27. package/esm2022/lib/computation/index.js +0 -3
  28. package/esm2022/lib/computation/index.js.map +0 -1
  29. package/esm2022/lib/config.js +0 -6
  30. package/esm2022/lib/config.js.map +0 -1
  31. package/esm2022/lib/mobx/component.js +0 -110
  32. package/esm2022/lib/mobx/component.js.map +0 -1
  33. package/esm2022/lib/mobx/create-root-node.js +0 -21
  34. package/esm2022/lib/mobx/create-root-node.js.map +0 -1
  35. package/esm2022/lib/mobx/ref-space.js +0 -25
  36. package/esm2022/lib/mobx/ref-space.js.map +0 -1
  37. package/esm2022/lib/mobx/store.js +0 -827
  38. package/esm2022/lib/mobx/store.js.map +0 -1
  39. package/esm2022/lib/node/create-node-options.js +0 -16
  40. package/esm2022/lib/node/create-node-options.js.map +0 -1
  41. package/esm2022/lib/node/creators/array-creator.js +0 -9
  42. package/esm2022/lib/node/creators/array-creator.js.map +0 -1
  43. package/esm2022/lib/node/creators/command-creator.js +0 -16
  44. package/esm2022/lib/node/creators/command-creator.js.map +0 -1
  45. package/esm2022/lib/node/creators/component-creator.js +0 -58
  46. package/esm2022/lib/node/creators/component-creator.js.map +0 -1
  47. package/esm2022/lib/node/creators/leaf-creator.js +0 -5
  48. package/esm2022/lib/node/creators/leaf-creator.js.map +0 -1
  49. package/esm2022/lib/node/creators/map-creator.js +0 -14
  50. package/esm2022/lib/node/creators/map-creator.js.map +0 -1
  51. package/esm2022/lib/node/creators/object-creator.js +0 -17
  52. package/esm2022/lib/node/creators/object-creator.js.map +0 -1
  53. package/esm2022/lib/node/creators/set-creator.js +0 -13
  54. package/esm2022/lib/node/creators/set-creator.js.map +0 -1
  55. package/esm2022/lib/node/creators/shape-creator.js +0 -15
  56. package/esm2022/lib/node/creators/shape-creator.js.map +0 -1
  57. package/esm2022/lib/node/creators/variant-shape-creator.js +0 -23
  58. package/esm2022/lib/node/creators/variant-shape-creator.js.map +0 -1
  59. package/esm2022/lib/node/guards.js +0 -5
  60. package/esm2022/lib/node/guards.js.map +0 -1
  61. package/esm2022/lib/node/node-creation.js +0 -47
  62. package/esm2022/lib/node/node-creation.js.map +0 -1
  63. package/esm2022/lib/node/node-type.js +0 -1
  64. package/esm2022/lib/node/node-type.js.map +0 -1
  65. package/esm2022/lib/node/node.js +0 -305
  66. package/esm2022/lib/node/node.js.map +0 -1
  67. package/esm2022/lib/parsers/index.js +0 -3
  68. package/esm2022/lib/parsers/index.js.map +0 -1
  69. package/esm2022/lib/parsers/node-selector.types.js +0 -1
  70. package/esm2022/lib/parsers/node-selector.types.js.map +0 -1
  71. package/esm2022/lib/parsers/parse-component-selector.js +0 -43
  72. package/esm2022/lib/parsers/parse-component-selector.js.map +0 -1
  73. package/esm2022/lib/parsers/parse-node-selector.js +0 -263
  74. package/esm2022/lib/parsers/parse-node-selector.js.map +0 -1
  75. package/esm2022/lib/types/command.js +0 -1
  76. package/esm2022/lib/types/command.js.map +0 -1
  77. package/esm2022/lib/types/index.js +0 -5
  78. package/esm2022/lib/types/index.js.map +0 -1
  79. package/esm2022/lib/types/node.guards.js +0 -7
  80. package/esm2022/lib/types/node.guards.js.map +0 -1
  81. package/esm2022/lib/types/schema.js +0 -1
  82. package/esm2022/lib/types/schema.js.map +0 -1
  83. package/esm2022/lib/util/extract-node-value.js +0 -45
  84. package/esm2022/lib/util/extract-node-value.js.map +0 -1
  85. package/esm2022/lib/util/format-source.js +0 -7
  86. package/esm2022/lib/util/format-source.js.map +0 -1
  87. package/esm2022/lib/util/get-component.js +0 -8
  88. package/esm2022/lib/util/get-component.js.map +0 -1
  89. package/esm2022/lib/util/id-generator.js +0 -10
  90. package/esm2022/lib/util/id-generator.js.map +0 -1
  91. package/esm2022/lib/util/traverse-node.js +0 -50
  92. package/esm2022/lib/util/traverse-node.js.map +0 -1
  93. package/index.d.ts +0 -11
  94. package/kaskad-component-tree.d.ts +0 -5
  95. package/lib/component-lookup/index.d.ts +0 -8
  96. package/lib/component-lookup/traverses/array-traverser.d.ts +0 -3
  97. package/lib/component-lookup/traverses/component-traverser.d.ts +0 -3
  98. package/lib/component-lookup/traverses/index.d.ts +0 -9
  99. package/lib/component-lookup/traverses/object-traverser.d.ts +0 -3
  100. package/lib/component-lookup/types.d.ts +0 -13
  101. package/lib/component-tree-api.d.ts +0 -21
  102. package/lib/computation/computation-frame.d.ts +0 -14
  103. package/lib/computation/computation-stack.d.ts +0 -48
  104. package/lib/computation/index.d.ts +0 -2
  105. package/lib/config.d.ts +0 -4
  106. package/lib/mobx/component.d.ts +0 -45
  107. package/lib/mobx/create-root-node.d.ts +0 -3
  108. package/lib/mobx/ref-space.d.ts +0 -10
  109. package/lib/mobx/store.d.ts +0 -238
  110. package/lib/node/create-node-options.d.ts +0 -12
  111. package/lib/node/creators/array-creator.d.ts +0 -4
  112. package/lib/node/creators/command-creator.d.ts +0 -4
  113. package/lib/node/creators/component-creator.d.ts +0 -4
  114. package/lib/node/creators/leaf-creator.d.ts +0 -4
  115. package/lib/node/creators/map-creator.d.ts +0 -4
  116. package/lib/node/creators/object-creator.d.ts +0 -4
  117. package/lib/node/creators/set-creator.d.ts +0 -4
  118. package/lib/node/creators/shape-creator.d.ts +0 -4
  119. package/lib/node/creators/variant-shape-creator.d.ts +0 -4
  120. package/lib/node/guards.d.ts +0 -3
  121. package/lib/node/node-creation.d.ts +0 -4
  122. package/lib/node/node-type.d.ts +0 -49
  123. package/lib/node/node.d.ts +0 -107
  124. package/lib/parsers/index.d.ts +0 -5
  125. package/lib/parsers/node-selector.types.d.ts +0 -25
  126. package/lib/parsers/parse-component-selector.d.ts +0 -8
  127. package/lib/parsers/parse-node-selector.d.ts +0 -87
  128. package/lib/types/command.d.ts +0 -3
  129. package/lib/types/index.d.ts +0 -4
  130. package/lib/types/node.guards.d.ts +0 -4
  131. package/lib/types/schema.d.ts +0 -13
  132. package/lib/util/extract-node-value.d.ts +0 -3
  133. package/lib/util/format-source.d.ts +0 -1
  134. package/lib/util/get-component.d.ts +0 -4
  135. package/lib/util/id-generator.d.ts +0 -5
  136. package/lib/util/traverse-node.d.ts +0 -26
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/component-tree/src/lib/component-lookup/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAA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;QACJ,CAAC;QAED,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED,SAAS,qBAAqB,CAAC,OAAwB;IACrD,IAAI,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC;IACzF,IAAI,OAAO,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,IAAI,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACnF,CAAC;IACD,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAChC,MAAM,IAAI,QAAQ,OAAO,CAAC,KAAK,GAAG,CAAC;IACrC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { ComponentId, ComponentValueType } from '@kaskad/types';\n\nimport { TComponent } from '../mobx/component';\nimport { ComponentStore } from '../mobx/store';\nimport { parseComponentSelector, SelectorSegment } from '../parsers';\nimport { traversesRegistry } from './traverses';\nimport { Context, NodeQueue, TraverseResult } from './types';\n\nexport { parseComponentSelector };\nexport type { SelectorSegment };\n\nexport function findComponent(relativeTo: ComponentId, selector: SelectorSegment[]): TComponent | null {\n const ids = findComponentsIds(relativeTo, selector);\n\n if (!ids.length) {\n return null;\n }\n\n if (ids.length > 1) {\n throw new Error(`Selector matched ${ids.length} components (expected 1): ${ids.join(', ')}`);\n }\n\n return ComponentStore.getInstance().getComponentOrThrow(ids[0]);\n}\n\nexport function findComponents(relativeTo: ComponentId, selector: SelectorSegment[]): TComponent[] {\n const ids = findComponentsIds(relativeTo, selector);\n return ids.map((componentId) => ComponentStore.getInstance().getComponentOrThrow(componentId));\n}\n\nexport function findComponentsIds(relativeTo: ComponentId, selector: SelectorSegment[]): ComponentId[] {\n const selectors = [selector];\n\n const foundComponents: TraverseResult = [];\n\n for (const parsedSelector of selectors) {\n if (parsedSelector.length === 0) {\n foundComponents.push(relativeTo);\n continue;\n }\n\n const startFrom: Context<ComponentValueType> = {\n currentNode: {\n valueType: { type: 'component' },\n value: relativeTo,\n },\n selectorSegments: parsedSelector,\n relativeTo,\n };\n\n const nodeQueue: NodeQueue = [startFrom];\n\n while (nodeQueue.length > 0) {\n const ctx = nodeQueue.shift();\n if (!ctx) break;\n const traverser = traversesRegistry.get(ctx.currentNode.valueType.type);\n traverser(ctx, nodeQueue, foundComponents);\n }\n }\n\n const uniqueComponents = Array.from(new Set(foundComponents));\n\n // Apply :nth(N) filtering if the last segment has an index\n const lastSegment = selector[selector.length - 1];\n if (lastSegment && lastSegment.index !== undefined) {\n const index = lastSegment.index;\n const actualIndex = index < 0 ? uniqueComponents.length + index : index;\n\n if (actualIndex < 0 || actualIndex >= uniqueComponents.length) {\n const selectorStr = selector.map(formatSelectorSegment).join(' ');\n throw new Error(\n `Index ${index} out of bounds for selector \"${selectorStr}\" (found ${uniqueComponents.length} elements)`,\n );\n }\n\n return [uniqueComponents[actualIndex]];\n }\n\n return uniqueComponents;\n}\n\nfunction formatSelectorSegment(segment: SelectorSegment): string {\n let result = segment.modifier ? segment.modifier + segment.qualifier : segment.qualifier;\n if (segment.conditions.length > 0) {\n result += segment.conditions.map(([key, value]) => `[${key}=${value}]`).join('');\n }\n if (segment.index !== undefined) {\n result += `:nth(${segment.index})`;\n }\n return result;\n}\n"]}
@@ -1,18 +0,0 @@
1
- export function traversArray(ctx, nodeQueue) {
2
- if (!ctx.selectorSegments.length) {
3
- return;
4
- }
5
- const arrayValue = ctx.currentNode.value || [];
6
- const description = ctx.currentNode.valueType;
7
- for (const item of arrayValue) {
8
- const childCtx = {
9
- ...ctx,
10
- currentNode: {
11
- valueType: description.item,
12
- value: item,
13
- },
14
- };
15
- nodeQueue.push(childCtx);
16
- }
17
- }
18
- //# sourceMappingURL=array-traverser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"array-traverser.js","sourceRoot":"","sources":["../../../../../../../libs/component-tree/src/lib/component-lookup/traverses/array-traverser.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,YAAY,CAAC,GAA4B,EAAE,SAAoB;IAC7E,IAAI,CAAC,GAAG,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC;QACjC,OAAO;IACT,CAAC;IAED,MAAM,UAAU,GAAG,GAAG,CAAC,WAAW,CAAC,KAAK,IAAI,EAAE,CAAC;IAC/C,MAAM,WAAW,GAAG,GAAG,CAAC,WAAW,CAAC,SAAS,CAAC;IAE9C,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC9B,MAAM,QAAQ,GAAuB;YACnC,GAAG,GAAG;YACN,WAAW,EAAE;gBACX,SAAS,EAAE,WAAW,CAAC,IAAI;gBAC3B,KAAK,EAAE,IAAI;aACZ;SACF,CAAC;QACF,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3B,CAAC;AACH,CAAC","sourcesContent":["import { ArrayValueType, ValueType } from '@kaskad/types';\n\nimport { Context, NodeQueue } from '../types';\n\nexport function traversArray(ctx: Context<ArrayValueType>, nodeQueue: NodeQueue) {\n if (!ctx.selectorSegments.length) {\n return;\n }\n\n const arrayValue = ctx.currentNode.value || [];\n const description = ctx.currentNode.valueType;\n\n for (const item of arrayValue) {\n const childCtx: Context<ValueType> = {\n ...ctx,\n currentNode: {\n valueType: description.item,\n value: item,\n },\n };\n nodeQueue.push(childCtx);\n }\n}\n"]}
@@ -1,120 +0,0 @@
1
- import { log } from '@kaskad/config';
2
- import { DefinitionStore } from '@kaskad/definition';
3
- import { ComponentStore } from '../../mobx/store';
4
- export function traversComponent(ctx, nodeQueue, foundComponents) {
5
- const componentId = ctx.currentNode.value;
6
- if (componentId === null)
7
- return;
8
- const segmentQueue = [...ctx.selectorSegments];
9
- const store = ComponentStore.getInstance();
10
- const currentComponent = store.getComponentOrThrow(componentId);
11
- while (segmentQueue.length > 0) {
12
- const selectorSegment = segmentQueue.shift();
13
- if (!selectorSegment)
14
- break;
15
- const isLastSelectorSegment = segmentQueue.length === 0;
16
- if (selectorSegment.modifier === '&') {
17
- const refSpace = store.getRefSpaceOrThrow(currentComponent.refSpaceId);
18
- const foundComponentId = refSpace.getComponentIdByRef(selectorSegment.qualifier);
19
- if (!foundComponentId) {
20
- if (!refSpace.parentRefSpaceId) {
21
- return;
22
- }
23
- const parentRefSpace = store.getRefSpaceOrThrow(refSpace.parentRefSpaceId);
24
- const foundInParent = parentRefSpace.getComponentIdByRef(selectorSegment.qualifier);
25
- if (!foundInParent) {
26
- return;
27
- }
28
- if (isLastSelectorSegment) {
29
- foundComponents.push(foundInParent);
30
- return;
31
- }
32
- addToQueue(currentComponent.id, {
33
- valueType: { type: 'component' },
34
- value: foundInParent,
35
- }, segmentQueue, nodeQueue);
36
- return;
37
- }
38
- if (isLastSelectorSegment) {
39
- foundComponents.push(foundComponentId);
40
- return;
41
- }
42
- continue;
43
- }
44
- if (selectorSegment.modifier === '^') {
45
- const matched = testComponentType(selectorSegment.qualifier, currentComponent.componentType) &&
46
- testConditions(selectorSegment.conditions, currentComponent);
47
- if (!matched) {
48
- addToQueue(currentComponent.id, {
49
- valueType: { type: 'component' },
50
- value: currentComponent.position.componentId,
51
- }, [selectorSegment, ...segmentQueue], nodeQueue);
52
- return;
53
- }
54
- if (isLastSelectorSegment) {
55
- foundComponents.push(componentId);
56
- }
57
- continue;
58
- }
59
- if (selectorSegment.modifier === ':') {
60
- if (!DefinitionStore.getInstance().hasComponentWithType(selectorSegment.qualifier)) {
61
- log.trace(`Component with type "${selectorSegment.qualifier}" does not exist.`);
62
- return;
63
- }
64
- if (currentComponent.id === ctx.relativeTo) {
65
- addComponentNodesToQueue(currentComponent, [selectorSegment, ...segmentQueue], nodeQueue);
66
- return;
67
- }
68
- const matched = testComponentType(selectorSegment.qualifier, currentComponent.componentType) &&
69
- testConditions(selectorSegment.conditions, currentComponent);
70
- if (!matched) {
71
- addComponentNodesToQueue(currentComponent, [selectorSegment, ...segmentQueue], nodeQueue);
72
- return;
73
- }
74
- if (isLastSelectorSegment) {
75
- foundComponents.push(componentId);
76
- return;
77
- }
78
- addToQueue(currentComponent.id, {
79
- valueType: { type: 'component' },
80
- value: currentComponent.id,
81
- }, segmentQueue, nodeQueue);
82
- return;
83
- }
84
- log.trace('Potentially invalid selector', ctx.selectorSegments);
85
- }
86
- }
87
- function testComponentType(qualifier, componentType) {
88
- return DefinitionStore.getInstance().getComponentTraits(componentType).includes(qualifier);
89
- }
90
- function testConditions(conditions, component) {
91
- return conditions.every((condition) => {
92
- const [key, expectedValue] = condition;
93
- if (!component.props.has(key))
94
- return false;
95
- const actualValue = String(extractNodeValue(component.props.get(key)));
96
- return actualValue === expectedValue;
97
- });
98
- }
99
- function addComponentNodesToQueue(component, selectorSegments, nodeQueue) {
100
- for (const node of component.props.values()) {
101
- addToQueue(component.id, {
102
- valueType: node.valueType,
103
- value: extractNodeValue(node),
104
- }, selectorSegments, nodeQueue);
105
- }
106
- }
107
- function addToQueue(componentId, node, selectorSegments, nodeQueue) {
108
- const childCtx = {
109
- selectorSegments,
110
- currentNode: node,
111
- relativeTo: componentId,
112
- };
113
- nodeQueue.push(childCtx);
114
- }
115
- function extractNodeValue(node) {
116
- if (!node)
117
- return null;
118
- return node.extractedValue;
119
- }
120
- //# sourceMappingURL=component-traverser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"component-traverser.js","sourceRoot":"","sources":["../../../../../../../libs/component-tree/src/lib/component-lookup/traverses/component-traverser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAIrD,OAA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QAEvC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QAE5C,MAAM,WAAW,GAAG,MAAM,CAAC,gBAAgB,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACvE,OAAO,WAAW,KAAK,aAAa,CAAC;IACvC,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,wBAAwB,CAAC,SAAqB,EAAE,gBAAmC,EAAE,SAAoB;IAChH,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;QAC5C,UAAU,CACR,SAAS,CAAC,EAAE,EACZ;YACE,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,KAAK,EAAE,gBAAgB,CAAC,IAAI,CAAC;SAC9B,EACD,gBAAgB,EAChB,SAAS,CACV,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CACjB,WAAwB,EACxB,IAAuC,EACvC,gBAAmC,EACnC,SAAoB;IAEpB,MAAM,QAAQ,GAAuB;QACnC,gBAAgB;QAChB,WAAW,EAAE,IAAI;QACjB,UAAU,EAAE,WAAW;KACxB,CAAC;IACF,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC3B,CAAC;AAED,SAAS,gBAAgB,CAAC,IAA8B;IACtD,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvB,OAAO,IAAI,CAAC,cAAc,CAAC;AAC7B,CAAC","sourcesContent":["import { log } from '@kaskad/config';\nimport { DefinitionStore } from '@kaskad/definition';\nimport { ComponentId, ComponentValueType, ValueType } from '@kaskad/types';\n\nimport { TComponent } from '../../mobx/component';\nimport { ComponentStore } from '../../mobx/store';\nimport { AbstractNode } from '../../node/node';\nimport { SelectorSegment } from '../../parsers';\nimport { Context, NodeQueue, TraverseResult } from '../types';\n\nexport function traversComponent(\n ctx: Context<ComponentValueType>,\n nodeQueue: NodeQueue,\n foundComponents: TraverseResult,\n) {\n const componentId = ctx.currentNode.value as ComponentId | null;\n if (componentId === null) return;\n\n const segmentQueue = [...ctx.selectorSegments];\n\n const store = ComponentStore.getInstance();\n const currentComponent = store.getComponentOrThrow(componentId);\n\n while (segmentQueue.length > 0) {\n const selectorSegment = segmentQueue.shift();\n if (!selectorSegment) break;\n const isLastSelectorSegment = segmentQueue.length === 0;\n\n if (selectorSegment.modifier === '&') {\n const refSpace = store.getRefSpaceOrThrow(currentComponent.refSpaceId);\n const foundComponentId = refSpace.getComponentIdByRef(selectorSegment.qualifier);\n\n if (!foundComponentId) {\n if (!refSpace.parentRefSpaceId) {\n return;\n }\n const parentRefSpace = store.getRefSpaceOrThrow(refSpace.parentRefSpaceId);\n const foundInParent = parentRefSpace.getComponentIdByRef(selectorSegment.qualifier);\n\n if (!foundInParent) {\n return;\n }\n\n if (isLastSelectorSegment) {\n foundComponents.push(foundInParent);\n return;\n }\n\n addToQueue(\n currentComponent.id,\n {\n valueType: { type: 'component' },\n value: foundInParent,\n },\n segmentQueue,\n nodeQueue,\n );\n return;\n }\n if (isLastSelectorSegment) {\n foundComponents.push(foundComponentId);\n return;\n }\n continue;\n }\n\n if (selectorSegment.modifier === '^') {\n const matched =\n testComponentType(selectorSegment.qualifier, currentComponent.componentType) &&\n testConditions(selectorSegment.conditions, currentComponent);\n\n if (!matched) {\n addToQueue(\n currentComponent.id,\n {\n valueType: { type: 'component' },\n value: currentComponent.position.componentId,\n },\n [selectorSegment, ...segmentQueue],\n nodeQueue,\n );\n\n return;\n }\n\n if (isLastSelectorSegment) {\n foundComponents.push(componentId);\n }\n continue;\n }\n\n if (selectorSegment.modifier === ':') {\n if (!DefinitionStore.getInstance().hasComponentWithType(selectorSegment.qualifier)) {\n log.trace(`Component with type \"${selectorSegment.qualifier}\" does not exist.`);\n return;\n }\n\n if (currentComponent.id === ctx.relativeTo) {\n addComponentNodesToQueue(currentComponent, [selectorSegment, ...segmentQueue], nodeQueue);\n return;\n }\n\n const matched =\n testComponentType(selectorSegment.qualifier, currentComponent.componentType) &&\n testConditions(selectorSegment.conditions, currentComponent);\n\n if (!matched) {\n addComponentNodesToQueue(currentComponent, [selectorSegment, ...segmentQueue], nodeQueue);\n return;\n }\n\n if (isLastSelectorSegment) {\n foundComponents.push(componentId);\n return;\n }\n\n addToQueue(\n currentComponent.id,\n {\n valueType: { type: 'component' },\n value: currentComponent.id,\n },\n segmentQueue,\n nodeQueue,\n );\n return;\n }\n\n log.trace('Potentially invalid selector', ctx.selectorSegments);\n }\n}\n\nfunction testComponentType(qualifier: string, componentType: string): boolean {\n return DefinitionStore.getInstance().getComponentTraits(componentType).includes(qualifier);\n}\n\nfunction testConditions(conditions: string[][], component: TComponent): boolean {\n return conditions.every((condition) => {\n const [key, expectedValue] = condition;\n\n if (!component.props.has(key)) return false;\n\n const actualValue = String(extractNodeValue(component.props.get(key)));\n return actualValue === expectedValue;\n });\n}\n\nfunction addComponentNodesToQueue(component: TComponent, selectorSegments: SelectorSegment[], nodeQueue: NodeQueue) {\n for (const node of component.props.values()) {\n addToQueue(\n component.id,\n {\n valueType: node.valueType,\n value: extractNodeValue(node),\n },\n selectorSegments,\n nodeQueue,\n );\n }\n}\n\nfunction addToQueue(\n componentId: ComponentId,\n node: Context<ValueType>['currentNode'],\n selectorSegments: SelectorSegment[],\n nodeQueue: NodeQueue,\n) {\n const childCtx: Context<ValueType> = {\n selectorSegments,\n currentNode: node,\n relativeTo: componentId,\n };\n nodeQueue.push(childCtx);\n}\n\nfunction extractNodeValue(node?: AbstractNode<ValueType>) {\n if (!node) return null;\n return node.extractedValue;\n}\n"]}
@@ -1,29 +0,0 @@
1
- import { traversArray } from './array-traverser';
2
- import { traversComponent } from './component-traverser';
3
- import { traversObject } from './object-traverser';
4
- export const traversesRegistry = {
5
- _registry: {
6
- array: traversArray,
7
- object: traversObject,
8
- component: traversComponent,
9
- map: () => [], // TODO: implement
10
- // the following node types cannot contain components
11
- set: () => [],
12
- unknown: () => [],
13
- boolean: () => [],
14
- string: () => [],
15
- number: () => [],
16
- componentSchema: () => [],
17
- validator: () => [],
18
- command: () => [],
19
- shape: () => [],
20
- variantShape: () => [],
21
- },
22
- get(type) {
23
- if (!this._registry[type]) {
24
- throw new Error(`Travers for type "${type}" not found`);
25
- }
26
- return this._registry[type];
27
- },
28
- };
29
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../libs/component-tree/src/lib/component-lookup/traverses/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AASnD,MAAM,CAAC,MAAM,iBAAiB,GAAa;IACzC,SAAS,EAAE;QACT,KAAK,EAAE,YAAY;QACnB,MAAM,EAAE,aAAa;QACrB,SAAS,EAAE,gBAAgB;QAC3B,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,kBAAkB;QAEjC,qDAAqD;QACrD,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE;QACb,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE;QACjB,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE;QACjB,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE;QAChB,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE;QAChB,eAAe,EAAE,GAAG,EAAE,CAAC,EAAE;QACzB,SAAS,EAAE,GAAG,EAAE,CAAC,EAAE;QACnB,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE;QACjB,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE;QACf,YAAY,EAAE,GAAG,EAAE,CAAC,EAAE;KACvB;IACD,GAAG,CAAC,IAAY;QACd,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,qBAAqB,IAAI,aAAa,CAAC,CAAC;QAC1D,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAc,CAAC;IAC3C,CAAC;CACF,CAAC","sourcesContent":["import { ValueType } from '@kaskad/types';\n\nimport { Context, NodeQueue, TraverseResult } from '../types';\nimport { traversArray } from './array-traverser';\nimport { traversComponent } from './component-traverser';\nimport { traversObject } from './object-traverser';\n\ntype TraversFn = (ctx: Context<ValueType>, nodeQueue: NodeQueue, foundComponents: TraverseResult) => void;\n\ntype Registry = {\n _registry: Record<string, unknown>;\n get(key: string): TraversFn;\n};\n\nexport const traversesRegistry: Registry = {\n _registry: {\n array: traversArray,\n object: traversObject,\n component: traversComponent,\n map: () => [], // TODO: implement\n\n // the following node types cannot contain components\n set: () => [],\n unknown: () => [],\n boolean: () => [],\n string: () => [],\n number: () => [],\n componentSchema: () => [],\n validator: () => [],\n command: () => [],\n shape: () => [],\n variantShape: () => [],\n },\n get(type: string) {\n if (!this._registry[type]) {\n throw new Error(`Travers for type \"${type}\" not found`);\n }\n return this._registry[type] as TraversFn;\n },\n};\n"]}
@@ -1,22 +0,0 @@
1
- export function traversObject(ctx, nodeQueue) {
2
- if (!ctx.selectorSegments.length) {
3
- return;
4
- }
5
- const description = ctx.currentNode.valueType;
6
- const objectNodeValue = ctx.currentNode.value;
7
- if (!objectNodeValue) {
8
- return;
9
- }
10
- Object.entries(description.fields).forEach(([fieldKey, fieldDescription]) => {
11
- const childCtx = {
12
- ...ctx,
13
- currentNode: {
14
- valueType: fieldDescription,
15
- value: objectNodeValue[fieldKey],
16
- },
17
- };
18
- nodeQueue.push(childCtx);
19
- });
20
- return;
21
- }
22
- //# sourceMappingURL=object-traverser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"object-traverser.js","sourceRoot":"","sources":["../../../../../../../libs/component-tree/src/lib/component-lookup/traverses/object-traverser.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,aAAa,CAAC,GAA6B,EAAE,SAAoB;IAC/E,IAAI,CAAC,GAAG,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC;QACjC,OAAO;IACT,CAAC;IAED,MAAM,WAAW,GAAG,GAAG,CAAC,WAAW,CAAC,SAA4B,CAAC;IAEjE,MAAM,eAAe,GAAG,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC;IAC9C,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,OAAO;IACT,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,EAAE,gBAAgB,CAAC,EAAE,EAAE;QAC1E,MAAM,QAAQ,GAAuB;YACnC,GAAG,GAAG;YACN,WAAW,EAAE;gBACX,SAAS,EAAE,gBAAgB;gBAC3B,KAAK,EAAE,eAAe,CAAC,QAAQ,CAAC;aACjC;SACF,CAAC;QACF,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IACH,OAAO;AACT,CAAC","sourcesContent":["import { ObjectValueType, ValueType } from '@kaskad/types';\n\nimport { Context, NodeQueue } from '../types';\n\nexport function traversObject(ctx: Context<ObjectValueType>, nodeQueue: NodeQueue) {\n if (!ctx.selectorSegments.length) {\n return;\n }\n\n const description = ctx.currentNode.valueType as ObjectValueType;\n\n const objectNodeValue = ctx.currentNode.value;\n if (!objectNodeValue) {\n return;\n }\n\n Object.entries(description.fields).forEach(([fieldKey, fieldDescription]) => {\n const childCtx: Context<ValueType> = {\n ...ctx,\n currentNode: {\n valueType: fieldDescription,\n value: objectNodeValue[fieldKey],\n },\n };\n nodeQueue.push(childCtx);\n });\n return;\n}\n"]}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../libs/component-tree/src/lib/component-lookup/types.ts"],"names":[],"mappings":"","sourcesContent":["import { ComponentId, ValueType } from '@kaskad/types';\n\nimport { NodeExtractedValue } from '../node/node-type';\nimport { SelectorSegment } from '../parsers';\n\nexport interface Context<T extends ValueType> {\n currentNode: {\n valueType: T;\n value: NodeExtractedValue<T> | null;\n };\n relativeTo: ComponentId;\n selectorSegments: SelectorSegment[];\n}\n\nexport type NodeQueue = Array<Context<ValueType>>;\nexport type TraverseResult = ComponentId[];\n"]}
@@ -1,121 +0,0 @@
1
- import { log } from '@kaskad/config';
2
- import { findComponentsIds, parseComponentSelector } from './component-lookup';
3
- import { ComponentStore } from './mobx/store';
4
- import { isCommandNode } from './types';
5
- export class ComponentTreeApi {
6
- static store = ComponentStore.getInstance();
7
- static findComponent(relativeTo, componentSelector) {
8
- return this.store.findComponent(relativeTo, componentSelector);
9
- }
10
- static findComponentsIds(relativeTo, componentSelector) {
11
- return findComponentsIds(relativeTo, parseComponentSelector(componentSelector));
12
- }
13
- static findComponents(relativeTo, componentSelector) {
14
- const ids = this.findComponentsIds(relativeTo, componentSelector);
15
- return ids.map((id) => this.store.getComponentOrThrow(id));
16
- }
17
- static getComponent(relativeTo, componentSelector) {
18
- const component = this.store.findComponent(relativeTo, componentSelector);
19
- if (!component) {
20
- throw new Error(`Component ${componentSelector} not found`);
21
- }
22
- return component;
23
- }
24
- static findNode(relativeTo, componentSelector) {
25
- return this.store.findNode(relativeTo, componentSelector);
26
- }
27
- static getNode(relativeTo, componentSelector) {
28
- return this.store.getNode(relativeTo, componentSelector);
29
- }
30
- static collectValuesArray(componentId, componentSelector, nodeSelector) {
31
- try {
32
- return this.store.collectValuesArray(componentId, componentSelector, nodeSelector);
33
- }
34
- catch (e) {
35
- log.error(`Error collecting values as array by component selector ${componentSelector}`, e);
36
- return [];
37
- }
38
- }
39
- static collectValuesMap(componentId, componentSelector, keyNodeSelector, valueNodeSelector) {
40
- try {
41
- return this.store.collectValuesMap(componentId, componentSelector, keyNodeSelector, valueNodeSelector);
42
- }
43
- catch (e) {
44
- log.error(`Error collecting values as map by component selector ${componentSelector}`, e);
45
- return {};
46
- }
47
- }
48
- static isCommandRunning(componentId, selector) {
49
- try {
50
- const node = this.getNode(componentId, selector);
51
- if (!isCommandNode(node)) {
52
- throw new Error(`Error`);
53
- }
54
- return node.viewModel.executing;
55
- }
56
- catch (e) {
57
- log.error(`Error checking command running state by selector ${selector}`, e);
58
- return false;
59
- }
60
- }
61
- static runCommandNode(componentId, selector, ...args) {
62
- try {
63
- const node = this.getNode(componentId, selector);
64
- if (!isCommandNode(node)) {
65
- throw new Error(`Node at "${selector}" is not a command`);
66
- }
67
- log.trace(`Running command "${selector}" on ${componentId}`);
68
- return node.viewModel.execute(...args);
69
- }
70
- catch (e) {
71
- log.error(`Error running command by selector "${selector}" with args:`, JSON.stringify(args), e);
72
- return null;
73
- }
74
- }
75
- static setNodeRawSchema(componentId, selector, value) {
76
- try {
77
- const node = this.getNode(componentId, selector);
78
- this.store.setNodeRawSchema(node, value);
79
- }
80
- catch (e) {
81
- log.error(`Error setting node by selector "${selector}" with value:`, value, e);
82
- }
83
- }
84
- static appendArrayItem(componentId, selector, item) {
85
- try {
86
- const arrayNode = this.store.getNode(componentId, selector);
87
- this.store.appendArrayItem(arrayNode, item);
88
- }
89
- catch (e) {
90
- log.error(`Error appending array item to selector "${selector}" with value:`, item, e);
91
- }
92
- }
93
- static insertArrayItem(componentId, selector, index, item) {
94
- try {
95
- const arrayNode = this.store.getNode(componentId, selector);
96
- this.store.insertArrayItem(arrayNode, index, item);
97
- }
98
- catch (e) {
99
- log.error(`Error inserting array item to selector "${selector}" with value:`, item, e);
100
- }
101
- }
102
- static removeArrayItem(componentId, selector, index) {
103
- try {
104
- const arrayNode = this.store.getNode(componentId, selector);
105
- this.store.removeArrayItem(arrayNode, index);
106
- }
107
- catch (e) {
108
- log.error(`Error removing array item from selector "${selector}" at index ${index}`, e);
109
- }
110
- }
111
- static replaceArrayItem(componentId, selector, index, item) {
112
- try {
113
- const arrayNode = this.store.getNode(componentId, selector);
114
- this.store.replaceArrayItem(arrayNode, index, item);
115
- }
116
- catch (e) {
117
- log.error(`Error replacing array item at selector "${selector}" at index ${index} with value:`, item, e);
118
- }
119
- }
120
- }
121
- //# sourceMappingURL=component-tree-api.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"component-tree-api.js","sourceRoot":"","sources":["../../../../../libs/component-tree/src/lib/component-tree-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAGrC,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAE/E,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,MAAM,OAAO,gBAAgB;IACnB,MAAM,CAAC,KAAK,GAAmB,cAAc,CAAC,WAAW,EAAE,CAAC;IAEpE,MAAM,CAAC,aAAa,CAAC,UAAuB,EAAE,iBAAyB;QACrE,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;IACjE,CAAC;IAED,MAAM,CAAC,iBAAiB,CAAC,UAAuB,EAAE,iBAAyB;QACzE,OAAO,iBAAiB,CAAC,UAAU,EAAE,sBAAsB,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAClF,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,UAAuB,EAAE,iBAAyB;QACtE,MAAM,GAAG,GAAG,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;QAClE,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,UAAuB,EAAE,iBAAyB;QACpE,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,UAAU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CAAC,KAAK,CAAC,eAAe,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAC/C,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,GAAG,CAAC,KAAK,CAAC,4CAA4C,QAAQ,cAAc,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;QAC1F,CAAC;IACH,CAAC;IAED,MAAM,CAAC,gBAAgB,CAAC,WAAwB,EAAE,QAAgB,EAAE,KAAa,EAAE,IAAa;QAC9F,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAY,WAAW,EAAE,QAAQ,CAAC,CAAC;YACvE,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QACtD,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,GAAG,CAAC,KAAK,CAAC,2CAA2C,QAAQ,cAAc,KAAK,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAC3G,CAAC;IACH,CAAC","sourcesContent":["import { log } from '@kaskad/config';\nimport { ComponentId, ValueType } from '@kaskad/types';\n\nimport { findComponentsIds, parseComponentSelector } from './component-lookup';\nimport { TComponent } from './mobx/component';\nimport { ComponentStore } from './mobx/store';\nimport { AbstractNode, ArrayNode } from './node/node';\nimport { isCommandNode } from './types';\n\nexport class ComponentTreeApi {\n private static store: ComponentStore = ComponentStore.getInstance();\n\n static findComponent(relativeTo: ComponentId, componentSelector: string): TComponent | null {\n return this.store.findComponent(relativeTo, componentSelector);\n }\n\n static findComponentsIds(relativeTo: ComponentId, componentSelector: string): ComponentId[] {\n return findComponentsIds(relativeTo, parseComponentSelector(componentSelector));\n }\n\n static findComponents(relativeTo: ComponentId, componentSelector: string): TComponent[] {\n const ids = this.findComponentsIds(relativeTo, componentSelector);\n return ids.map((id) => this.store.getComponentOrThrow(id));\n }\n\n static getComponent(relativeTo: ComponentId, componentSelector: string): TComponent {\n const component = this.store.findComponent(relativeTo, componentSelector);\n if (!component) {\n throw new Error(`Component ${componentSelector} not found`);\n }\n\n return component;\n }\n\n static findNode(relativeTo: ComponentId, componentSelector: string): AbstractNode<ValueType> | null {\n return this.store.findNode(relativeTo, componentSelector);\n }\n\n static getNode(relativeTo: ComponentId, componentSelector: string): AbstractNode<ValueType> {\n return this.store.getNode(relativeTo, componentSelector);\n }\n\n static collectValuesArray<T>(componentId: ComponentId, componentSelector: string, nodeSelector: string): T {\n try {\n return this.store.collectValuesArray<T>(componentId, componentSelector, nodeSelector);\n } catch (e) {\n log.error(`Error collecting values as array by component selector ${componentSelector}`, e);\n return [] as T;\n }\n }\n\n static collectValuesMap<T>(\n componentId: ComponentId,\n componentSelector: string,\n keyNodeSelector: string,\n valueNodeSelector: string,\n ): T {\n try {\n return this.store.collectValuesMap<T>(componentId, componentSelector, keyNodeSelector, valueNodeSelector);\n } catch (e) {\n log.error(`Error collecting values as map by component selector ${componentSelector}`, e);\n return {} as T;\n }\n }\n\n static isCommandRunning(componentId: ComponentId, selector: string): boolean {\n try {\n const node = this.getNode(componentId, selector);\n if (!isCommandNode(node)) {\n throw new Error(`Error`);\n }\n\n return node.viewModel.executing;\n } catch (e) {\n log.error(`Error checking command running state by selector ${selector}`, e);\n return false;\n }\n }\n\n static runCommandNode(componentId: ComponentId, selector: string, ...args: unknown[]): unknown {\n try {\n const node = this.getNode(componentId, selector);\n if (!isCommandNode(node)) {\n throw new Error(`Node at \"${selector}\" is not a command`);\n }\n\n log.trace(`Running command \"${selector}\" on ${componentId}`);\n return node.viewModel.execute(...args);\n } catch (e) {\n log.error(`Error running command by selector \"${selector}\" with args:`, JSON.stringify(args), e);\n return null;\n }\n }\n\n static setNodeRawSchema(componentId: ComponentId, selector: string, value: unknown): void {\n try {\n const node = this.getNode(componentId, selector);\n this.store.setNodeRawSchema(node, value);\n } catch (e) {\n log.error(`Error setting node by selector \"${selector}\" with value:`, value, e);\n }\n }\n\n static appendArrayItem(componentId: ComponentId, selector: string, item: unknown): void {\n try {\n const arrayNode = this.store.getNode<ArrayNode>(componentId, selector);\n this.store.appendArrayItem(arrayNode, item);\n } catch (e) {\n log.error(`Error appending array item to selector \"${selector}\" with value:`, item, e);\n }\n }\n\n static insertArrayItem(componentId: ComponentId, selector: string, index: number, item: unknown) {\n try {\n const arrayNode = this.store.getNode<ArrayNode>(componentId, selector);\n this.store.insertArrayItem(arrayNode, index, item);\n } catch (e) {\n log.error(`Error inserting array item to selector \"${selector}\" with value:`, item, e);\n }\n }\n\n static removeArrayItem(componentId: ComponentId, selector: string, index: number) {\n try {\n const arrayNode = this.store.getNode<ArrayNode>(componentId, selector);\n this.store.removeArrayItem(arrayNode, index);\n } catch (e) {\n log.error(`Error removing array item from selector \"${selector}\" at index ${index}`, e);\n }\n }\n\n static replaceArrayItem(componentId: ComponentId, selector: string, index: number, item: unknown) {\n try {\n const arrayNode = this.store.getNode<ArrayNode>(componentId, selector);\n this.store.replaceArrayItem(arrayNode, index, item);\n } catch (e) {\n log.error(`Error replacing array item at selector \"${selector}\" at index ${index} with value:`, item, e);\n }\n }\n}\n"]}
@@ -1,27 +0,0 @@
1
- import { makeObservable, observable, runInAction } from 'mobx';
2
- export class ComputationFrame {
3
- schema;
4
- disposers;
5
- activated = false;
6
- constructor(schema, disposers = [], activated = false) {
7
- this.schema = schema;
8
- this.disposers = disposers;
9
- this.activated = activated;
10
- makeObservable(this, {
11
- activated: observable.ref,
12
- });
13
- }
14
- /**
15
- * Mark this computation frame as activated.
16
- * This is an action that ensures MobX compliance.
17
- */
18
- markActivated() {
19
- runInAction(() => {
20
- this.activated = true;
21
- });
22
- }
23
- dispose() {
24
- this.disposers.forEach((d) => d());
25
- }
26
- }
27
- //# sourceMappingURL=computation-frame.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"computation-frame.js","sourceRoot":"","sources":["../../../../../../libs/component-tree/src/lib/computation/computation-frame.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAElF,MAAM,OAAO,gBAAgB;IAClB,MAAM,CAAoB;IAC1B,SAAS,CAAsB;IACxC,SAAS,GAAG,KAAK,CAAC;IAElB,YAAY,MAAyB,EAAE,YAAiC,EAAE,EAAE,SAAS,GAAG,KAAK;QAC3F,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAE3B,cAAc,CAAC,IAAI,EAAE;YACnB,SAAS,EAAE,UAAU,CAAC,GAAG;SAC1B,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,aAAa;QACX,WAAW,CAAC,GAAG,EAAE;YACf,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACxB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC;CACF","sourcesContent":["import { ComputationSchema } from '@kaskad/types';\nimport { IReactionDisposer, makeObservable, observable, runInAction } from 'mobx';\n\nexport class ComputationFrame {\n readonly schema: ComputationSchema;\n readonly disposers: IReactionDisposer[];\n activated = false;\n\n constructor(schema: ComputationSchema, disposers: IReactionDisposer[] = [], activated = false) {\n this.schema = schema;\n this.disposers = disposers;\n this.activated = activated;\n\n makeObservable(this, {\n activated: observable.ref,\n });\n }\n\n /**\n * Mark this computation frame as activated.\n * This is an action that ensures MobX compliance.\n */\n markActivated(): void {\n runInAction(() => {\n this.activated = true;\n });\n }\n\n dispose(): void {\n this.disposers.forEach((d) => d());\n }\n}\n"]}
@@ -1,83 +0,0 @@
1
- import { observable, runInAction } from 'mobx';
2
- import { ComputationFrame } from './computation-frame';
3
- /**
4
- * Manages a stack of computation frames for nested computations.
5
- * For example: formula → formula → template chain.
6
- */
7
- export class ComputationStack {
8
- /**
9
- * Maximum allowed stack depth to prevent infinite recursion.
10
- */
11
- static MAX_DEPTH = 10;
12
- _frames;
13
- constructor() {
14
- this._frames = observable.array([], { deep: false, name: 'computation-stack' });
15
- }
16
- /**
17
- * Get the topmost computation frame from the stack.
18
- * Returns null if stack is empty.
19
- */
20
- get top() {
21
- return this._frames[this._frames.length - 1] ?? null;
22
- }
23
- /**
24
- * Returns true if all frames in the stack are activated.
25
- * Empty stack returns true (vacuously).
26
- */
27
- get allActivated() {
28
- return this._frames.length === 0 || this._frames.every((f) => f.activated);
29
- }
30
- /**
31
- * Get the current stack depth.
32
- */
33
- get depth() {
34
- return this._frames.length;
35
- }
36
- /**
37
- * Check if the stack is empty.
38
- */
39
- get isEmpty() {
40
- return this._frames.length === 0;
41
- }
42
- /**
43
- * Push a new computation frame onto the stack.
44
- * Throws if depth limit is exceeded.
45
- */
46
- push(schema) {
47
- if (this._frames.length >= ComputationStack.MAX_DEPTH) {
48
- throw new Error(`Computation stack overflow: depth ${this._frames.length + 1} exceeds maximum ${ComputationStack.MAX_DEPTH}. ` +
49
- `This may indicate infinite recursion in computation chain.`);
50
- }
51
- return runInAction(() => {
52
- const frame = new ComputationFrame(schema, [], false);
53
- this._frames.push(frame);
54
- return frame;
55
- });
56
- }
57
- /**
58
- * Pop all frames from the given depth onward.
59
- * For example, if depth=2, this removes frames at indices 2, 3, 4, etc.
60
- * Useful when a computation at a specific depth re-evaluates and needs
61
- * to clear its results without affecting parent computations.
62
- */
63
- popFrom(depth) {
64
- runInAction(() => {
65
- while (this._frames.length > depth) {
66
- const frame = this._frames.pop();
67
- frame?.dispose();
68
- }
69
- });
70
- }
71
- /**
72
- * Dispose all frames in the stack.
73
- */
74
- dispose() {
75
- runInAction(() => {
76
- while (this._frames.length > 0) {
77
- const frame = this._frames.pop();
78
- frame?.dispose();
79
- }
80
- });
81
- }
82
- }
83
- //# sourceMappingURL=computation-stack.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"computation-stack.js","sourceRoot":"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;QACJ,CAAC;QAED,OAAO,WAAW,CAAC,GAAG,EAAE;YACtB,MAAM,KAAK,GAAG,IAAI,gBAAgB,CAAC,MAAM,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;YACtD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACzB,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,OAAO,CAAC,KAAa;QACnB,WAAW,CAAC,GAAG,EAAE;YACf,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,KAAK,EAAE,CAAC;gBACnC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;gBACjC,KAAK,EAAE,OAAO,EAAE,CAAC;YACnB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,OAAO;QACL,WAAW,CAAC,GAAG,EAAE;YACf,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC/B,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;gBACjC,KAAK,EAAE,OAAO,EAAE,CAAC;YACnB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC","sourcesContent":["import { ComputationSchema } from '@kaskad/types';\nimport { observable, runInAction } from 'mobx';\n\nimport { ComputationFrame } from './computation-frame';\n\n/**\n * Manages a stack of computation frames for nested computations.\n * For example: formula → formula → template chain.\n */\nexport class ComputationStack {\n /**\n * Maximum allowed stack depth to prevent infinite recursion.\n */\n static readonly MAX_DEPTH = 10;\n\n private readonly _frames: ComputationFrame[];\n\n constructor() {\n this._frames = observable.array([], { deep: false, name: 'computation-stack' });\n }\n\n /**\n * Get the topmost computation frame from the stack.\n * Returns null if stack is empty.\n */\n get top(): ComputationFrame | null {\n return this._frames[this._frames.length - 1] ?? null;\n }\n\n /**\n * Returns true if all frames in the stack are activated.\n * Empty stack returns true (vacuously).\n */\n get allActivated(): boolean {\n return this._frames.length === 0 || this._frames.every((f) => f.activated);\n }\n\n /**\n * Get the current stack depth.\n */\n get depth(): number {\n return this._frames.length;\n }\n\n /**\n * Check if the stack is empty.\n */\n get isEmpty(): boolean {\n return this._frames.length === 0;\n }\n\n /**\n * Push a new computation frame onto the stack.\n * Throws if depth limit is exceeded.\n */\n push(schema: ComputationSchema): ComputationFrame {\n if (this._frames.length >= ComputationStack.MAX_DEPTH) {\n throw new Error(\n `Computation stack overflow: depth ${this._frames.length + 1} exceeds maximum ${ComputationStack.MAX_DEPTH}. ` +\n `This may indicate infinite recursion in computation chain.`,\n );\n }\n\n return runInAction(() => {\n const frame = new ComputationFrame(schema, [], false);\n this._frames.push(frame);\n return frame;\n });\n }\n\n /**\n * Pop all frames from the given depth onward.\n * For example, if depth=2, this removes frames at indices 2, 3, 4, etc.\n * Useful when a computation at a specific depth re-evaluates and needs\n * to clear its results without affecting parent computations.\n */\n popFrom(depth: number): void {\n runInAction(() => {\n while (this._frames.length > depth) {\n const frame = this._frames.pop();\n frame?.dispose();\n }\n });\n }\n\n /**\n * Dispose all frames in the stack.\n */\n dispose(): void {\n runInAction(() => {\n while (this._frames.length > 0) {\n const frame = this._frames.pop();\n frame?.dispose();\n }\n });\n }\n}\n"]}
@@ -1,3 +0,0 @@
1
- export * from './computation-frame';
2
- export * from './computation-stack';
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
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"]}
@@ -1,6 +0,0 @@
1
- export const componentTreeConfig = {
2
- runCommand: (_node, ..._args) => {
3
- throw new Error('runCommand is not implemented. Please provide an implementation.');
4
- },
5
- };
6
- //# sourceMappingURL=config.js.map
@@ -1 +0,0 @@
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"]}