json-to-spec 19.1.0

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 (217) hide show
  1. package/README.md +118 -0
  2. package/docs/demo.html +426 -0
  3. package/docs/dist/min.js +164 -0
  4. package/docs/dist/v1/min.js +124 -0
  5. package/docs/dist/v17/min.js +355 -0
  6. package/docs/dist/v18/min.js +160 -0
  7. package/docs/dist/v19/min.js +164 -0
  8. package/docs/dist/v2/min.js +129 -0
  9. package/docs/dist/v3/min.js +201 -0
  10. package/docs/index.html +248 -0
  11. package/docs/pages/architecture.html +115 -0
  12. package/docs/pages/how-it-works.html +125 -0
  13. package/docs/pages/what-not.html +100 -0
  14. package/docs/pages/what.html +105 -0
  15. package/docs/pages/why.html +88 -0
  16. package/docs/samples/form.html +265 -0
  17. package/docs/samples/index.html +112 -0
  18. package/docs/samples/table.html +306 -0
  19. package/index.js +2 -0
  20. package/package.json +50 -0
  21. package/samples/dataList/index.html +31 -0
  22. package/samples/dataList/index.js +62 -0
  23. package/samples/dataList/input/data.json +5043 -0
  24. package/samples/dataList/input/structure.json +38 -0
  25. package/samples/dataList copy/index.html +30 -0
  26. package/samples/dataList copy/index.js +61 -0
  27. package/samples/dataList copy/input/data.json +35307 -0
  28. package/samples/dataList copy/input/structure.json +18 -0
  29. package/samples/form/index.html +29 -0
  30. package/samples/form/index.js +64 -0
  31. package/samples/form/input/data.json +9 -0
  32. package/samples/form/input/structure.json +192 -0
  33. package/samples/form-/data.json +42 -0
  34. package/samples/form-/structure.json +110 -0
  35. package/samples/select/index.html +31 -0
  36. package/samples/select/index.js +61 -0
  37. package/samples/select/input/data.json +35287 -0
  38. package/samples/select/input/select.json +18 -0
  39. package/samples/select/input/structure.json +47 -0
  40. package/samples/table/index.html +29 -0
  41. package/samples/table/index.js +61 -0
  42. package/samples/table/input/data.json +35287 -0
  43. package/samples/table/input/structure copy.json +47 -0
  44. package/samples/table/input/structure.json +86 -0
  45. package/samples/table/input/table.json +135 -0
  46. package/samples/table-/data.json +68 -0
  47. package/samples/table-/structure.json +235 -0
  48. package/src/index.js +2 -0
  49. package/src/v10/index.js +96 -0
  50. package/src/v10/instructionEngine/compile/compileTree.js +191 -0
  51. package/src/v10/instructionEngine/compileTree.js +1 -0
  52. package/src/v10/instructionEngine/expandIteration.js +1 -0
  53. package/src/v10/instructionEngine/index.js +29 -0
  54. package/src/v10/instructionEngine/interpolate.js +2 -0
  55. package/src/v10/instructionEngine/iteration/expandIteration.js +95 -0
  56. package/src/v10/instructionEngine/operation/operation.js +237 -0
  57. package/src/v10/instructionEngine/other/other.js +150 -0
  58. package/src/v10/instructionEngine/pipeline/pipeline.js +47 -0
  59. package/src/v10/instructionEngine/replace/replace.js +173 -0
  60. package/src/v10/instructionEngine/resolve/resolvePath.js +18 -0
  61. package/src/v10/instructionEngine/resolve/resolveTokenValue.js +22 -0
  62. package/src/v10/instructionEngine/resolvePath.js +1 -0
  63. package/src/v10/instructionEngine/resolveTokenValue.js +1 -0
  64. package/src/v10/instructionEngine/story/storyInjector.js +50 -0
  65. package/src/v10/instructionEngine/storyInjector.js +1 -0
  66. package/src/v10/instructionEngine/value/interpolate.js +38 -0
  67. package/src/v11/index.js +116 -0
  68. package/src/v11/iterate.js +270 -0
  69. package/src/v11/replace.js +169 -0
  70. package/src/v11/resolvePath.js +29 -0
  71. package/src/v12/index.js +122 -0
  72. package/src/v12/iterate/bindFormValues.js +74 -0
  73. package/src/v12/iterate/expandIteration.js +181 -0
  74. package/src/v12/iterate/index.js +10 -0
  75. package/src/v12/iterate/iterate.js +56 -0
  76. package/src/v12/iterate/iterateNode.js +86 -0
  77. package/src/v12/iterate/resolveCollection.js +37 -0
  78. package/src/v12/iterate.js +270 -0
  79. package/src/v12/replace.js +169 -0
  80. package/src/v12/resolvePath.js +29 -0
  81. package/src/v13/index.js +110 -0
  82. package/src/v13/iterate/bindFormValues.js +74 -0
  83. package/src/v13/iterate/expandIteration.js +188 -0
  84. package/src/v13/iterate/index.js +9 -0
  85. package/src/v13/iterate/iterate.js +32 -0
  86. package/src/v13/iterate/iterateNode.js +86 -0
  87. package/src/v13/iterate/resolveCollection.js +37 -0
  88. package/src/v13/iterate/walk.js +90 -0
  89. package/src/v13/iterate.js +270 -0
  90. package/src/v13/replace.js +169 -0
  91. package/src/v13/resolvePath.js +29 -0
  92. package/src/v14/index.js +112 -0
  93. package/src/v14/iterate/bindFormValues.js +74 -0
  94. package/src/v14/iterate/expandIteration.js +188 -0
  95. package/src/v14/iterate/index.js +9 -0
  96. package/src/v14/iterate/iterate.js +32 -0
  97. package/src/v14/iterate/resolveCollection.js +37 -0
  98. package/src/v14/iterate/walk/walk copy 2.js +114 -0
  99. package/src/v14/iterate/walk/walk copy.js +90 -0
  100. package/src/v14/iterate/walk/walk.js +98 -0
  101. package/src/v14/iterate.js +270 -0
  102. package/src/v14/replace/index.js +16 -0
  103. package/src/v14/replace/walk.js +90 -0
  104. package/src/v14/replace.js +153 -0
  105. package/src/v14/resolvePath.js +29 -0
  106. package/src/v15/index.js +123 -0
  107. package/src/v15/iterate/bindFormValues.js +74 -0
  108. package/src/v15/iterate/expandIteration.js +188 -0
  109. package/src/v15/iterate/index.js +9 -0
  110. package/src/v15/iterate/iterate.js +32 -0
  111. package/src/v15/iterate/resolveCollection.js +37 -0
  112. package/src/v15/iterate/walk/walk copy 2.js +114 -0
  113. package/src/v15/iterate/walk/walk copy.js +90 -0
  114. package/src/v15/iterate/walk/walk.js +195 -0
  115. package/src/v15/iterate.js +270 -0
  116. package/src/v15/replace/index.js +16 -0
  117. package/src/v15/replace/walk.js +90 -0
  118. package/src/v15/replace.js +155 -0
  119. package/src/v15/resolvePath.js +29 -0
  120. package/src/v16/index.js +129 -0
  121. package/src/v16/iterate/bindFormValues.js +74 -0
  122. package/src/v16/iterate/expandIteration.js +188 -0
  123. package/src/v16/iterate/index.js +9 -0
  124. package/src/v16/iterate/iterate.js +32 -0
  125. package/src/v16/iterate/resolveCollection.js +37 -0
  126. package/src/v16/iterate/walk/walk copy 2.js +114 -0
  127. package/src/v16/iterate/walk/walk copy.js +90 -0
  128. package/src/v16/iterate/walk/walk.js +196 -0
  129. package/src/v16/iterate.js +270 -0
  130. package/src/v16/replace/index.js +16 -0
  131. package/src/v16/replace/walk.js +90 -0
  132. package/src/v16/replace.js +155 -0
  133. package/src/v16/resolvePath.js +29 -0
  134. package/src/v17/index.js +119 -0
  135. package/src/v17/iterate/bindFormValues.js +74 -0
  136. package/src/v17/iterate/expandIteration.js +188 -0
  137. package/src/v17/iterate/index.js +9 -0
  138. package/src/v17/iterate/iterate.js +32 -0
  139. package/src/v17/iterate/resolveCollection.js +37 -0
  140. package/src/v17/iterate/walk/iterateDo.js +42 -0
  141. package/src/v17/iterate/walk/replaceWithData.js +60 -0
  142. package/src/v17/iterate/walk/walk.js +94 -0
  143. package/src/v17/iterate.js +270 -0
  144. package/src/v17/replace/index.js +16 -0
  145. package/src/v17/replace/walk.js +90 -0
  146. package/src/v17/replace.js +160 -0
  147. package/src/v17/resolvePath.js +29 -0
  148. package/src/v18/index.js +66 -0
  149. package/src/v18/meta.js +7 -0
  150. package/src/v18/registerGlobal.js +17 -0
  151. package/src/v18/replace.js +18 -0
  152. package/src/v18/resolvePath.js +29 -0
  153. package/src/v18/walk/iterate/v1/index.js +42 -0
  154. package/src/v18/walk/iterate/v2/index.js +32 -0
  155. package/src/v18/walk/iterate/v3/index.js +46 -0
  156. package/src/v18/walk/iterate/v4/createChildren.js +24 -0
  157. package/src/v18/walk/iterate/v4/index.js +25 -0
  158. package/src/v18/walk/replaceWithData/v1/index.js +42 -0
  159. package/src/v18/walk/replaceWithData/v1/replaceCommon.js +21 -0
  160. package/src/v18/walk/replaceWithData/v2/index.js +105 -0
  161. package/src/v18/walk/replaceWithData/v2/replaceCommon.js +21 -0
  162. package/src/v18/walk/replaceWithData/v3/index.js +15 -0
  163. package/src/v18/walk/replaceWithData/v3/replaceAttributes.js +29 -0
  164. package/src/v18/walk/replaceWithData/v3/replaceCommon.js +23 -0
  165. package/src/v18/walk/replaceWithData/v3/replaceNodeValue.js +27 -0
  166. package/src/v18/walk/walk.js +94 -0
  167. package/src/v19/index.js +55 -0
  168. package/src/v19/meta.js +7 -0
  169. package/src/v19/registerGlobal.js +17 -0
  170. package/src/v19/replace.js +18 -0
  171. package/src/v19/resolvePath.js +29 -0
  172. package/src/v19/walk/iterate/v1/index.js +42 -0
  173. package/src/v19/walk/iterate/v2/index.js +32 -0
  174. package/src/v19/walk/iterate/v3/index.js +46 -0
  175. package/src/v19/walk/iterate/v4/createChildren.js +27 -0
  176. package/src/v19/walk/iterate/v4/index.js +25 -0
  177. package/src/v19/walk/replaceWithData/v1/index.js +42 -0
  178. package/src/v19/walk/replaceWithData/v1/replaceCommon.js +21 -0
  179. package/src/v19/walk/replaceWithData/v2/index.js +105 -0
  180. package/src/v19/walk/replaceWithData/v2/replaceCommon.js +21 -0
  181. package/src/v19/walk/replaceWithData/v3/index.js +15 -0
  182. package/src/v19/walk/replaceWithData/v3/replaceAttributes.js +29 -0
  183. package/src/v19/walk/replaceWithData/v3/replaceCommon.js +23 -0
  184. package/src/v19/walk/replaceWithData/v3/replaceNodeValue.js +27 -0
  185. package/src/v19/walk/walk.js +97 -0
  186. package/src/v8/index.js +69 -0
  187. package/src/v8/instructionEngine/compile/compileTree.js +191 -0
  188. package/src/v8/instructionEngine/compileTree.js +1 -0
  189. package/src/v8/instructionEngine/expandIteration.js +1 -0
  190. package/src/v8/instructionEngine/index.js +16 -0
  191. package/src/v8/instructionEngine/interpolate.js +2 -0
  192. package/src/v8/instructionEngine/iteration/expandIteration.js +95 -0
  193. package/src/v8/instructionEngine/resolve/resolvePath.js +18 -0
  194. package/src/v8/instructionEngine/resolve/resolveTokenValue.js +22 -0
  195. package/src/v8/instructionEngine/resolvePath.js +1 -0
  196. package/src/v8/instructionEngine/resolveTokenValue.js +1 -0
  197. package/src/v8/instructionEngine/story/storyInjector.js +50 -0
  198. package/src/v8/instructionEngine/storyInjector.js +1 -0
  199. package/src/v8/instructionEngine/value/interpolate.js +38 -0
  200. package/src/v9/index.js +96 -0
  201. package/src/v9/instructionEngine/compile/compileTree.js +191 -0
  202. package/src/v9/instructionEngine/compileTree.js +1 -0
  203. package/src/v9/instructionEngine/expandIteration.js +1 -0
  204. package/src/v9/instructionEngine/index.js +29 -0
  205. package/src/v9/instructionEngine/interpolate.js +2 -0
  206. package/src/v9/instructionEngine/iteration/expandIteration.js +95 -0
  207. package/src/v9/instructionEngine/operation/operation.js +237 -0
  208. package/src/v9/instructionEngine/other/other.js +150 -0
  209. package/src/v9/instructionEngine/pipeline/pipeline.js +47 -0
  210. package/src/v9/instructionEngine/replace/replace.js +173 -0
  211. package/src/v9/instructionEngine/resolve/resolvePath.js +18 -0
  212. package/src/v9/instructionEngine/resolve/resolveTokenValue.js +22 -0
  213. package/src/v9/instructionEngine/resolvePath.js +1 -0
  214. package/src/v9/instructionEngine/resolveTokenValue.js +1 -0
  215. package/src/v9/instructionEngine/story/storyInjector.js +50 -0
  216. package/src/v9/instructionEngine/storyInjector.js +1 -0
  217. package/src/v9/instructionEngine/value/interpolate.js +38 -0
@@ -0,0 +1,21 @@
1
+ const startFunc = ({ inData, inDataKey }) => {
2
+ const dataKey = inDataKey;
3
+ // console.log("dataKey : ", dataKey, inData);
4
+
5
+ let valueToReturn = inData[dataKey];
6
+
7
+ if (dataKey.includes(".")) {
8
+ const keysOfArray = dataKey.split(".");
9
+
10
+ const value = keysOfArray.reduce(
11
+ (current, key) => current?.[key],
12
+ inData
13
+ );
14
+
15
+ valueToReturn = value;
16
+ };
17
+
18
+ return valueToReturn;
19
+ };
20
+
21
+ export default startFunc;
@@ -0,0 +1,15 @@
1
+ import replaceNodeValue from "./replaceNodeValue.js";
2
+ import replaceAttributes from "./replaceAttributes.js";
3
+
4
+ const startFunc = ({
5
+ inNode,
6
+ inData,
7
+ } = {}) => {
8
+ const localNode = inNode;
9
+ const localData = inData;
10
+
11
+ replaceNodeValue({ inNode: localNode, inData: localData });
12
+ replaceAttributes({ inNode: localNode, inData: localData });
13
+ };
14
+
15
+ export default startFunc;
@@ -0,0 +1,29 @@
1
+ import replaceCommonFunc from "./replaceCommon.js";
2
+
3
+ const startFunc = ({
4
+ inNode,
5
+ inData,
6
+ } = {}) => {
7
+ const localNode = inNode;
8
+ const localData = inData;
9
+
10
+ if ("attributes" in localNode) {
11
+ const attributes = Object.fromEntries(
12
+ Object.entries(localNode.attributes || {}).map(([key, value]) => [
13
+ key,
14
+ typeof value === "string" && value.includes("${")
15
+ ? replaceCommonFunc({
16
+ inData: localData,
17
+ inDataKey: value
18
+ .replace(/^\$\{/, "")
19
+ .replace(/\}$/, "")
20
+ })
21
+ : value
22
+ ])
23
+ );
24
+
25
+ localNode.attributes = { ...attributes };
26
+ };
27
+ };
28
+
29
+ export default startFunc;
@@ -0,0 +1,23 @@
1
+ const startFunc = ({ inData, inDataKey }) => {
2
+ const dataKey = inDataKey;
3
+ // console.log("dataKey : ", dataKey, inData);
4
+
5
+ if (dataKey === "") return inData;
6
+
7
+ let valueToReturn = inData[dataKey];
8
+
9
+ if (dataKey.includes(".")) {
10
+ const keysOfArray = dataKey.split(".");
11
+
12
+ const value = keysOfArray.reduce(
13
+ (current, key) => current?.[key],
14
+ inData
15
+ );
16
+
17
+ valueToReturn = value;
18
+ };
19
+
20
+ return valueToReturn;
21
+ };
22
+
23
+ export default startFunc;
@@ -0,0 +1,27 @@
1
+ import replaceCommonFunc from "./replaceCommon.js";
2
+
3
+ const startFunc = ({
4
+ inNode,
5
+ inData,
6
+ } = {}) => {
7
+ const localNode = inNode;
8
+ const localData = inData;
9
+
10
+ if (!localNode?.textContent) return "no-textContent";
11
+
12
+ if (typeof localNode.textContent !== "string") return "not-a-string";
13
+
14
+ if (!localNode.textContent.includes("${")) return "no-template-token";
15
+
16
+ const dataKey = localNode.textContent
17
+ .replace(/^\$\{/, "")
18
+ .replace(/\}$/, "");
19
+
20
+ localNode.textContent = replaceCommonFunc({
21
+ inData: localData,
22
+ inDataKey: dataKey
23
+ });
24
+
25
+ };
26
+
27
+ export default startFunc;
@@ -0,0 +1,97 @@
1
+ import replaceWithData from "./replaceWithData/v3/index.js";
2
+ import iterateDo from "./iterate/v4/index.js";
3
+
4
+ const forArray = ({ inNode, inData, inOperation }) => {
5
+ const localNode = inNode;
6
+ const localData = inData;
7
+ const localOperation = inOperation;
8
+
9
+ // console.log("forArray : ", inNode, inOperation);
10
+
11
+ if (Array.isArray(localNode)) {
12
+ const results = [];
13
+
14
+ for (const child of localNode) {
15
+ const result = walk({
16
+ inNode: child,
17
+ inData, inOperation: localOperation
18
+ });
19
+
20
+ if (Array.isArray(result)) {
21
+ results.push(...result);
22
+ } else if (result !== null && result !== undefined) {
23
+ results.push(result);
24
+ };
25
+ };
26
+
27
+ return results;
28
+ };
29
+ };
30
+
31
+ /**
32
+ * Recursively walks a JSON structure.
33
+ *
34
+ * The walker knows only how to traverse.
35
+ * The supplied operation decides what to do with each node.
36
+ */
37
+ const walk = ({
38
+ inNode,
39
+ inData = {},
40
+ inOperation,
41
+ inShowLog = false
42
+ } = {}) => {
43
+ const localNode = inNode;
44
+ const localData = inData;
45
+ const localOperation = inOperation;
46
+
47
+ if (inShowLog) console.log("walk ", inNode, inData, inOperation);
48
+ // debugger
49
+ if (localNode === null || localNode === undefined) {
50
+ return localNode;
51
+ };
52
+
53
+ if (Array.isArray(localNode)) {
54
+ return forArray({
55
+ inNode: localNode, inData,
56
+ inOperation: localOperation
57
+ });
58
+ };
59
+
60
+ if ("children" in localNode) {
61
+ if (Array.isArray(localNode?.children)) {
62
+ localNode.children = forArray({
63
+ inNode: localNode?.children,
64
+ inData, inOperation: localOperation
65
+ });
66
+ };
67
+ };
68
+
69
+ if (typeof localNode !== "object") {
70
+ return localNode;
71
+ };
72
+
73
+ // console.log("localOperation :", localOperation);
74
+
75
+ switch (localOperation) {
76
+ case "replace":
77
+ if (typeof localNode === "object") {
78
+ // console.log("yyyyyyyyyy :", typeof localNode === "object");
79
+ replaceWithData({
80
+ inNode: localNode,
81
+ inData
82
+ });
83
+ };
84
+ break;
85
+ case "iterateDo":
86
+ iterateDo({
87
+ inNode: localNode,
88
+ inData: localData, inShowLog
89
+ });
90
+ default:
91
+ break;
92
+ };
93
+
94
+ return localNode;
95
+ };
96
+
97
+ export default walk;
@@ -0,0 +1,69 @@
1
+ /**
2
+ * json-to-spec v7
3
+ *
4
+ * Clear separation of responsibilities:
5
+ * - value replacement is handled by interpolation helpers
6
+ * - iteration is handled by the dedicated expandIteration layer
7
+ * - story injection remains a separate final step
8
+ */
9
+
10
+ import compileNode from "./instructionEngine/compileTree.js";
11
+
12
+ export const meta = {
13
+ version: "8.0.0",
14
+ name: "json-to-spec/v7",
15
+ description: "Pure JSON Specification Compiler with separate interpolation and iteration phases"
16
+ };
17
+
18
+ /**
19
+ * Compiles a JSON UI structure tree containing `jsonToSpec` operations with a data payload.
20
+ *
21
+ * Outside API:
22
+ * - compile(structureJson, dataJson)
23
+ * - compile({ structure, data }) or compile({ context, data })
24
+ *
25
+ * @param {Object|Array} inStructureOrOptions - The UI structure JSON tree or options object
26
+ * @param {Object} [inData] - Data payload containing collections and values
27
+ * @returns {Object|Array} - Compiled 100% pure JSON specification ready for json-to-dom
28
+ */
29
+ const compile = (inStructureOrOptions, inData = {}) => {
30
+ let localStructure = inStructureOrOptions;
31
+ let localData = inData || {};
32
+
33
+ console.log("aaaaaaaaaa : ", localStructure, localData);
34
+
35
+
36
+ if (inStructureOrOptions && typeof inStructureOrOptions === "object" && !Array.isArray(inStructureOrOptions)) {
37
+ // Support options object formats
38
+ if ("structure" in inStructureOrOptions && ("data" in inStructureOrOptions || inData === undefined || Object.keys(inData).length === 0)) {
39
+ localStructure = inStructureOrOptions.structure;
40
+ localData = inStructureOrOptions.data || localData;
41
+ } else if ("context" in inStructureOrOptions && ("data" in inStructureOrOptions || inData === undefined || Object.keys(inData).length === 0)) {
42
+ localStructure = inStructureOrOptions.context;
43
+ localData = inStructureOrOptions.data || localData;
44
+ } else if ("inStructure" in inStructureOrOptions || "inContext" in inStructureOrOptions || "inTree" in inStructureOrOptions) {
45
+ localStructure = inStructureOrOptions.inStructure || inStructureOrOptions.inContext || inStructureOrOptions.inTree;
46
+ localData = inStructureOrOptions.inData || localData;
47
+ }
48
+ };
49
+ console.log("aaaaaaaaaa : ", localStructure, localData);
50
+
51
+ return compileNode({
52
+ inNode: localStructure,
53
+ inContext: localData,
54
+ inRootData: localData
55
+ });
56
+ };
57
+
58
+ if (typeof globalThis !== "undefined") {
59
+ globalThis.ks ??= {};
60
+ console.log("aaaaaaaaaa : ", meta);
61
+
62
+ globalThis.ks["json-to-spec"] = {
63
+ meta,
64
+ compile
65
+ };
66
+
67
+ };
68
+
69
+ export default compile;
@@ -0,0 +1,191 @@
1
+ import { interpolateValue, interpolateString } from "../value/interpolate.js";
2
+ import { injectStory } from "../story/storyInjector.js";
3
+ import { expandIterationNode } from "../iteration/expandIteration.js";
4
+
5
+ const compileArrayNode = ({ inNode, inContext, inRootData }) => {
6
+ const flattened = [];
7
+
8
+ for (const child of inNode) {
9
+ const childContext = child && child.__loopItemContext
10
+ ? { ...inContext, ...child.__loopItemContext }
11
+ : inContext;
12
+
13
+ const compiledChild = compileNode({
14
+ inNode: child,
15
+ inContext: childContext,
16
+ inRootData
17
+ });
18
+
19
+ if (Array.isArray(compiledChild)) {
20
+ flattened.push(...compiledChild);
21
+ } else if (compiledChild !== null && compiledChild !== undefined) {
22
+ flattened.push(compiledChild);
23
+ }
24
+ }
25
+
26
+ return flattened;
27
+ };
28
+
29
+ const compilePrimitiveNode = ({ inNode, inContext, inRootData }) => {
30
+ return interpolateString({
31
+ inText: inNode,
32
+ inItemContext: inContext,
33
+ inRootData
34
+ });
35
+ };
36
+
37
+ const applyValueBindings = ({ inNode, inItemContext, inRootData }) => {
38
+ const clone = { ...inNode };
39
+
40
+ if (clone.textContent) {
41
+ clone.textContent = interpolateString({
42
+ inText: clone.textContent,
43
+ inItemContext,
44
+ inRootData
45
+ });
46
+ }
47
+
48
+ if (clone.attributes) {
49
+ clone.attributes = { ...clone.attributes };
50
+ for (const [name, value] of Object.entries(clone.attributes)) {
51
+ if (typeof value === "string") {
52
+ clone.attributes[name] = interpolateValue({
53
+ inValue: value,
54
+ inItemContext,
55
+ inRootData
56
+ });
57
+ }
58
+ }
59
+ }
60
+
61
+ if (clone.properties) {
62
+ clone.properties = { ...clone.properties };
63
+ for (const [name, value] of Object.entries(clone.properties)) {
64
+ if (typeof value === "string") {
65
+ clone.properties[name] = interpolateValue({
66
+ inValue: value,
67
+ inItemContext,
68
+ inRootData
69
+ });
70
+ }
71
+ }
72
+ }
73
+
74
+ return clone;
75
+ };
76
+
77
+ const compileStandardNode = ({ inNode, inContext, inRootData }) => {
78
+ const currentItem = {
79
+ ...(typeof inContext.item === "object" ? inContext.item : {}),
80
+ ...inContext
81
+ };
82
+
83
+ const withBindings = applyValueBindings({
84
+ inNode: { ...inNode },
85
+ inItemContext: currentItem,
86
+ inRootData
87
+ });
88
+
89
+ if ("jsonToSpec" in withBindings) {
90
+ delete withBindings.jsonToSpec;
91
+ }
92
+
93
+ if (withBindings.attributes) {
94
+ const isFormField = ["input", "textarea", "select", "option"].includes(withBindings.tagName?.toLowerCase());
95
+ if (isFormField) {
96
+ const fieldName = currentItem.field || currentItem.columnName || currentItem.name;
97
+ if (currentItem.value !== undefined && currentItem.value !== null) {
98
+ withBindings.attributes.value = String(currentItem.value);
99
+ if (withBindings.tagName === "textarea" && !withBindings.textContent) {
100
+ withBindings.textContent = String(currentItem.value);
101
+ }
102
+ } else if (fieldName && inRootData[fieldName] !== undefined && inRootData[fieldName] !== null) {
103
+ withBindings.attributes.value = String(inRootData[fieldName]);
104
+ if (withBindings.tagName === "textarea" && !withBindings.textContent) {
105
+ withBindings.textContent = String(inRootData[fieldName]);
106
+ }
107
+ } else if (fieldName && inRootData.values && inRootData.values[fieldName] !== undefined && inRootData.values[fieldName] !== null) {
108
+ withBindings.attributes.value = String(inRootData.values[fieldName]);
109
+ if (withBindings.tagName === "textarea" && !withBindings.textContent) {
110
+ withBindings.textContent = String(inRootData.values[fieldName]);
111
+ }
112
+ }
113
+ }
114
+ }
115
+
116
+ const storyNode = injectStory(withBindings, inNode, currentItem, inRootData);
117
+
118
+ if (Array.isArray(storyNode.children)) {
119
+ const compiledChildren = [];
120
+ for (const child of storyNode.children) {
121
+ const childContext = child && child.__loopItemContext
122
+ ? { ...inContext, ...child.__loopItemContext }
123
+ : inContext;
124
+
125
+ const compiledChild = compileNode({
126
+ inNode: child,
127
+ inContext: childContext,
128
+ inRootData
129
+ });
130
+
131
+ if (Array.isArray(compiledChild)) {
132
+ compiledChildren.push(...compiledChild);
133
+ } else if (compiledChild !== null && compiledChild !== undefined) {
134
+ compiledChildren.push(compiledChild);
135
+ }
136
+ }
137
+ storyNode.children = compiledChildren;
138
+ }
139
+
140
+ delete storyNode.__loopItemContext;
141
+ return storyNode;
142
+ };
143
+
144
+ export const compileNode = ({ inNode, inContext = {}, inRootData = {} } = {}) => {
145
+ if (inNode === null || inNode === undefined) return null;
146
+
147
+ if (Array.isArray(inNode)) {
148
+ return compileArrayNode({
149
+ inNode,
150
+ inContext,
151
+ inRootData
152
+ });
153
+ }
154
+
155
+ if (typeof inNode !== "object") {
156
+ return compilePrimitiveNode({
157
+ inNode,
158
+ inContext,
159
+ inRootData
160
+ });
161
+ }
162
+
163
+ const iterationResult = expandIterationNode({
164
+ inNode,
165
+ inContext,
166
+ inRootData
167
+ });
168
+
169
+ if (iterationResult !== undefined) {
170
+ if (Array.isArray(iterationResult)) {
171
+ return compileArrayNode({
172
+ inNode: iterationResult,
173
+ inContext,
174
+ inRootData
175
+ });
176
+ }
177
+ return compileStandardNode({
178
+ inNode: iterationResult,
179
+ inContext,
180
+ inRootData
181
+ });
182
+ }
183
+
184
+ return compileStandardNode({
185
+ inNode,
186
+ inContext,
187
+ inRootData
188
+ });
189
+ };
190
+
191
+ export default compileNode;
@@ -0,0 +1 @@
1
+ export { compileNode, default } from "./compile/compileTree.js";
@@ -0,0 +1 @@
1
+ export { expandIterationNode, default } from "./iteration/expandIteration.js";
@@ -0,0 +1,16 @@
1
+ import compileNode from "./compile/compileTree.js";
2
+ import resolvePath from "./resolve/resolvePath.js";
3
+ import { expandIterationNode } from "./iteration/expandIteration.js";
4
+ import { interpolateValue, interpolateString } from "./value/interpolate.js";
5
+ import { injectStory } from "./story/storyInjector.js";
6
+
7
+ export {
8
+ compileNode,
9
+ expandIterationNode,
10
+ interpolateValue,
11
+ interpolateString,
12
+ injectStory,
13
+ resolvePath
14
+ };
15
+
16
+ export default compileNode;
@@ -0,0 +1,2 @@
1
+ export { interpolateValue, interpolateString } from "./value/interpolate.js";
2
+ export { default } from "./value/interpolate.js";
@@ -0,0 +1,95 @@
1
+ import resolvePath from "../resolve/resolvePath.js";
2
+
3
+ const resolveCollection = ({ inNode, inContext, inRootData }) => {
4
+ const instruction = inNode && inNode.jsonToSpec;
5
+ if (!instruction) return undefined;
6
+
7
+ const sourceKey = instruction.source || instruction.iterateOn || instruction.$iterate;
8
+ if (!sourceKey) return undefined;
9
+
10
+ return resolvePath({ inData: inRootData, inPath: sourceKey })
11
+ || (inRootData && inRootData[sourceKey])
12
+ || resolvePath({ inData: inContext, inPath: sourceKey })
13
+ || (inContext && inContext[sourceKey]);
14
+ };
15
+
16
+ export const expandIterationNode = ({ inNode, inContext = {}, inRootData = {} }) => {
17
+ const instruction = inNode && inNode.jsonToSpec;
18
+ if (!instruction) return undefined;
19
+
20
+ const operation = instruction.operation;
21
+ if (operation !== "iterate" && !instruction.source && !instruction.$iterate) {
22
+ return undefined;
23
+ }
24
+
25
+ const sourceKey = instruction.source || instruction.iterateOn || instruction.$iterate;
26
+ const collection = resolveCollection({ inNode, inContext, inRootData }) || [];
27
+
28
+ if (!Array.isArray(collection)) {
29
+ if (inNode && inNode.tagName) {
30
+ const cloned = { ...inNode };
31
+ delete cloned.jsonToSpec;
32
+ cloned.children = [];
33
+ return cloned;
34
+ }
35
+ return [];
36
+ }
37
+
38
+ const template = instruction.template || instruction.item || {};
39
+ const filter = instruction.filter;
40
+
41
+ const filtered = collection.filter(item => {
42
+ if (!item || typeof item !== "object") return true;
43
+ if (filter && typeof filter === "object") {
44
+ for (const [key, value] of Object.entries(filter)) {
45
+ if (item[key] !== value) return false;
46
+ }
47
+ }
48
+ if (item.isVisible === false) return false;
49
+ return true;
50
+ });
51
+
52
+ const expandedChildren = [];
53
+ filtered.forEach((item, index) => {
54
+ const itemContext = {
55
+ ...inContext,
56
+ item,
57
+ ...(typeof item === "object" && item !== null ? item : {}),
58
+ $index: index,
59
+ $number: index + 1
60
+ };
61
+
62
+ if (sourceKey === "rows" || sourceKey.endsWith(".rows") || sourceKey === "items" || sourceKey.endsWith("Rows")) {
63
+ itemContext.row = item;
64
+ }
65
+
66
+ if (inContext.row && (item.field || item.columnName || item.name)) {
67
+ const fieldKey = item.field || item.columnName || item.name;
68
+ const cellValue = inContext.row[fieldKey];
69
+ if (cellValue !== undefined) {
70
+ itemContext.cellValue = cellValue;
71
+ itemContext.value = cellValue;
72
+ if (typeof item === "object" && item !== null && item.value === undefined) {
73
+ item.value = cellValue;
74
+ }
75
+ }
76
+ }
77
+
78
+ const templateNode = typeof template === "object" && template !== null
79
+ ? { ...template, __loopItemContext: itemContext }
80
+ : { tagName: "span", textContent: template, __loopItemContext: itemContext };
81
+
82
+ expandedChildren.push(templateNode);
83
+ });
84
+
85
+ if (inNode && inNode.tagName) {
86
+ const cloned = { ...inNode };
87
+ delete cloned.jsonToSpec;
88
+ cloned.children = expandedChildren;
89
+ return cloned;
90
+ }
91
+
92
+ return expandedChildren;
93
+ };
94
+
95
+ export default expandIterationNode;
@@ -0,0 +1,18 @@
1
+ export const resolvePath = ({ inData, inPath }) => {
2
+ if (inData === null || inData === undefined) return undefined;
3
+ if (inPath === undefined || inPath === null || inPath === "" || inPath === ".") {
4
+ return inData;
5
+ }
6
+
7
+ const segments = Array.isArray(inPath) ? inPath : String(inPath).split(".");
8
+ let current = inData;
9
+
10
+ for (const segment of segments) {
11
+ if (current === null || current === undefined) return undefined;
12
+ current = current[segment];
13
+ }
14
+
15
+ return current;
16
+ };
17
+
18
+ export default resolvePath;
@@ -0,0 +1,22 @@
1
+ import resolvePath from "./resolvePath.js";
2
+
3
+ export const resolveTokenValue = ({ inPath, inItemContext, inRootData }) => {
4
+ let value = resolvePath({ inData: inItemContext, inPath });
5
+
6
+ if (value === undefined && inItemContext && typeof inItemContext === "object") {
7
+ if (inItemContext.item && typeof inItemContext.item === "object") {
8
+ value = resolvePath({ inData: inItemContext.item, inPath });
9
+ }
10
+ if (value === undefined && inItemContext.row && typeof inItemContext.row === "object") {
11
+ value = resolvePath({ inData: inItemContext.row, inPath });
12
+ }
13
+ }
14
+
15
+ if (value === undefined && inRootData) {
16
+ value = resolvePath({ inData: inRootData, inPath });
17
+ }
18
+
19
+ return value;
20
+ };
21
+
22
+ export default resolveTokenValue;
@@ -0,0 +1 @@
1
+ export { resolvePath, default } from "./resolve/resolvePath.js";
@@ -0,0 +1 @@
1
+ export { resolveTokenValue, default } from "./resolve/resolveTokenValue.js";