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,237 @@
1
+ import resolvePath from "../resolve/resolvePath.js";
2
+
3
+ const resolveCollection = ({ inNode, inContext, inRootData }) => {
4
+ const localNode = inNode;
5
+ const localContext = inContext;
6
+ const localRootData = inRootData;
7
+
8
+ const instruction = localNode && (localNode.jsonToSpec || (localNode.operation ? localNode : null));
9
+ if (!instruction) return undefined;
10
+
11
+ const sourceKey = instruction.source || instruction.iterateOn || instruction.$iterate;
12
+ if (!sourceKey) return undefined;
13
+
14
+ return resolvePath({ inData: localRootData, inPath: sourceKey })
15
+ || (localRootData && localRootData[sourceKey])
16
+ || resolvePath({ inData: localContext, inPath: sourceKey })
17
+ || (localContext && localContext[sourceKey]);
18
+ };
19
+
20
+ const expandSingleIteration = ({ inNode, inContext, inRootData }) => {
21
+ const localNode = inNode;
22
+ const localContext = inContext;
23
+ const localRootData = inRootData;
24
+
25
+ const instruction = localNode && (localNode.jsonToSpec || (localNode.operation ? localNode : null));
26
+ if (!instruction) return undefined;
27
+
28
+ const operationType = instruction.operation;
29
+ if (operationType !== "iterate" && !instruction.source && !instruction.$iterate) {
30
+ return undefined;
31
+ }
32
+
33
+ const sourceKey = instruction.source || instruction.iterateOn || instruction.$iterate;
34
+ const collection = resolveCollection({
35
+ inNode: localNode,
36
+ inContext: localContext,
37
+ inRootData: localRootData
38
+ }) || [];
39
+
40
+ if (!Array.isArray(collection)) {
41
+ if (localNode && localNode.tagName) {
42
+ const cloned = { ...localNode };
43
+ delete cloned.jsonToSpec;
44
+ cloned.children = [];
45
+ return cloned;
46
+ }
47
+ return [];
48
+ }
49
+
50
+ const template = instruction.template || instruction.item || {};
51
+ const filter = instruction.filter;
52
+
53
+ const filtered = collection.filter(item => {
54
+ if (!item || typeof item !== "object") return true;
55
+ if (filter && typeof filter === "object") {
56
+ for (const [key, value] of Object.entries(filter)) {
57
+ if (item[key] !== value) return false;
58
+ }
59
+ }
60
+ if (item.isVisible === false) return false;
61
+ return true;
62
+ });
63
+
64
+ const expandedChildren = [];
65
+ filtered.forEach((item, index) => {
66
+ const itemContext = {
67
+ ...localContext,
68
+ item,
69
+ ...(typeof item === "object" && item !== null ? item : {}),
70
+ $index: index,
71
+ $number: index + 1
72
+ };
73
+
74
+ if (sourceKey === "rows" || sourceKey.endsWith(".rows") || sourceKey === "items" || sourceKey.endsWith("Rows")) {
75
+ itemContext.row = item;
76
+ }
77
+
78
+ if (localContext.row && (item.field || item.columnName || item.name)) {
79
+ const fieldKey = item.field || item.columnName || item.name;
80
+ const cellValue = localContext.row[fieldKey];
81
+ if (cellValue !== undefined) {
82
+ itemContext.cellValue = cellValue;
83
+ itemContext.value = cellValue;
84
+ if (typeof item === "object" && item !== null && item.value === undefined) {
85
+ item.value = cellValue;
86
+ }
87
+ }
88
+ }
89
+
90
+ const templateNode = typeof template === "object" && template !== null
91
+ ? { ...template, __loopItemContext: itemContext }
92
+ : { tagName: "span", textContent: template, __loopItemContext: itemContext };
93
+
94
+ const expandedItem = operationNode({
95
+ inNode: templateNode,
96
+ inContext: itemContext,
97
+ inRootData: localRootData
98
+ });
99
+
100
+ if (Array.isArray(expandedItem)) {
101
+ expandedChildren.push(...expandedItem);
102
+ } else if (expandedItem !== null && expandedItem !== undefined) {
103
+ expandedChildren.push(expandedItem);
104
+ }
105
+ });
106
+
107
+ if (localNode && localNode.tagName) {
108
+ const cloned = { ...localNode };
109
+ delete cloned.jsonToSpec;
110
+ cloned.children = expandedChildren;
111
+ return cloned;
112
+ }
113
+
114
+ return expandedChildren;
115
+ };
116
+
117
+ const operationArrayNode = ({ inNode, inContext, inRootData }) => {
118
+ const localNode = inNode;
119
+ const localContext = inContext;
120
+ const localRootData = inRootData;
121
+
122
+ const flattened = [];
123
+
124
+ for (const child of localNode) {
125
+ const childContext = child && child.__loopItemContext
126
+ ? { ...localContext, ...child.__loopItemContext }
127
+ : localContext;
128
+
129
+ const processed = operationNode({
130
+ inNode: child,
131
+ inContext: childContext,
132
+ inRootData: localRootData
133
+ });
134
+
135
+ if (Array.isArray(processed)) {
136
+ flattened.push(...processed);
137
+ } else if (processed !== null && processed !== undefined) {
138
+ flattened.push(processed);
139
+ }
140
+ }
141
+
142
+ return flattened;
143
+ };
144
+
145
+ const operationStandardNode = ({ inNode, inContext, inRootData }) => {
146
+ const localNode = inNode;
147
+ const localContext = inContext;
148
+ const localRootData = inRootData;
149
+
150
+ const cloned = { ...localNode };
151
+
152
+ if (Array.isArray(cloned.children)) {
153
+ const processedChildren = [];
154
+ for (const child of cloned.children) {
155
+ const childContext = child && child.__loopItemContext
156
+ ? { ...localContext, ...child.__loopItemContext }
157
+ : localContext;
158
+
159
+ const processedChild = operationNode({
160
+ inNode: child,
161
+ inContext: childContext,
162
+ inRootData: localRootData
163
+ });
164
+
165
+ if (Array.isArray(processedChild)) {
166
+ processedChildren.push(...processedChild);
167
+ } else if (processedChild !== null && processedChild !== undefined) {
168
+ processedChildren.push(processedChild);
169
+ }
170
+ }
171
+ cloned.children = processedChildren;
172
+ }
173
+
174
+ return cloned;
175
+ };
176
+
177
+ export const operationNode = ({ inNode, inContext = {}, inRootData = {} } = {}) => {
178
+ const localNode = inNode;
179
+ const localContext = inContext;
180
+ const localRootData = inRootData;
181
+
182
+ if (localNode === null || localNode === undefined) return null;
183
+
184
+ if (Array.isArray(localNode)) {
185
+ return operationArrayNode({
186
+ inNode: localNode,
187
+ inContext: localContext,
188
+ inRootData: localRootData
189
+ });
190
+ }
191
+
192
+ if (typeof localNode !== "object") {
193
+ return localNode;
194
+ }
195
+
196
+ const iterationResult = expandSingleIteration({
197
+ inNode: localNode,
198
+ inContext: localContext,
199
+ inRootData: localRootData
200
+ });
201
+
202
+ if (iterationResult !== undefined) {
203
+ return iterationResult;
204
+ }
205
+
206
+ return operationStandardNode({
207
+ inNode: localNode,
208
+ inContext: localContext,
209
+ inRootData: localRootData
210
+ });
211
+ };
212
+
213
+ export const operation = (inStructureOrOptions, inData = {}) => {
214
+ let localStructure = inStructureOrOptions;
215
+ let localData = inData;
216
+ let localContext = {};
217
+
218
+ if (inStructureOrOptions && typeof inStructureOrOptions === "object" && !Array.isArray(inStructureOrOptions)) {
219
+ if ("inStructure" in inStructureOrOptions || "inTree" in inStructureOrOptions || "inNode" in inStructureOrOptions) {
220
+ localStructure = inStructureOrOptions.inStructure || inStructureOrOptions.inTree || inStructureOrOptions.inNode;
221
+ localData = inStructureOrOptions.inData || localData;
222
+ localContext = inStructureOrOptions.inContext || localContext;
223
+ } else if ("structure" in inStructureOrOptions) {
224
+ localStructure = inStructureOrOptions.structure;
225
+ localData = inStructureOrOptions.data || localData;
226
+ localContext = inStructureOrOptions.context || localContext;
227
+ }
228
+ }
229
+
230
+ return operationNode({
231
+ inNode: localStructure,
232
+ inContext: localContext,
233
+ inRootData: localData
234
+ });
235
+ };
236
+
237
+ export default operation;
@@ -0,0 +1,150 @@
1
+ import { injectStory } from "../story/storyInjector.js";
2
+
3
+ const otherArrayNode = ({ inNode, inContext, inRootData }) => {
4
+ const localNode = inNode;
5
+ const localContext = inContext;
6
+ const localRootData = inRootData;
7
+
8
+ const flattened = [];
9
+
10
+ for (const child of localNode) {
11
+ const childContext = child && child.__loopItemContext
12
+ ? { ...localContext, ...child.__loopItemContext }
13
+ : localContext;
14
+
15
+ const processed = otherNode({
16
+ inNode: child,
17
+ inContext: childContext,
18
+ inRootData: localRootData
19
+ });
20
+
21
+ if (Array.isArray(processed)) {
22
+ flattened.push(...processed);
23
+ } else if (processed !== null && processed !== undefined) {
24
+ flattened.push(processed);
25
+ }
26
+ }
27
+
28
+ return flattened;
29
+ };
30
+
31
+ const otherStandardNode = ({ inNode, inContext, inRootData }) => {
32
+ const localNode = inNode;
33
+ const localContext = inContext;
34
+ const localRootData = inRootData;
35
+
36
+ const currentItem = {
37
+ ...(typeof localContext.item === "object" ? localContext.item : {}),
38
+ ...localContext,
39
+ ...(localNode.__loopItemContext || {})
40
+ };
41
+
42
+ const clone = { ...localNode };
43
+
44
+ if (clone.attributes) {
45
+ clone.attributes = { ...clone.attributes };
46
+ const isFormField = ["input", "textarea", "select", "option"].includes(clone.tagName?.toLowerCase());
47
+ if (isFormField) {
48
+ const fieldName = currentItem.field || currentItem.columnName || currentItem.name;
49
+ if (currentItem.value !== undefined && currentItem.value !== null) {
50
+ clone.attributes.value = String(currentItem.value);
51
+ if (clone.tagName === "textarea" && !clone.textContent) {
52
+ clone.textContent = String(currentItem.value);
53
+ }
54
+ } else if (fieldName && localRootData[fieldName] !== undefined && localRootData[fieldName] !== null) {
55
+ clone.attributes.value = String(localRootData[fieldName]);
56
+ if (clone.tagName === "textarea" && !clone.textContent) {
57
+ clone.textContent = String(localRootData[fieldName]);
58
+ }
59
+ } else if (fieldName && localRootData.values && localRootData.values[fieldName] !== undefined && localRootData.values[fieldName] !== null) {
60
+ clone.attributes.value = String(localRootData.values[fieldName]);
61
+ if (clone.tagName === "textarea" && !clone.textContent) {
62
+ clone.textContent = String(localRootData.values[fieldName]);
63
+ }
64
+ }
65
+ }
66
+ }
67
+
68
+ const storyNode = injectStory(clone, localNode, currentItem, localRootData);
69
+
70
+ if ("jsonToSpec" in storyNode) {
71
+ delete storyNode.jsonToSpec;
72
+ }
73
+
74
+ if (Array.isArray(storyNode.children)) {
75
+ const processedChildren = [];
76
+ for (const child of storyNode.children) {
77
+ const childContext = child && child.__loopItemContext
78
+ ? { ...currentItem, ...child.__loopItemContext }
79
+ : currentItem;
80
+
81
+ const processedChild = otherNode({
82
+ inNode: child,
83
+ inContext: childContext,
84
+ inRootData: localRootData
85
+ });
86
+
87
+ if (Array.isArray(processedChild)) {
88
+ processedChildren.push(...processedChild);
89
+ } else if (processedChild !== null && processedChild !== undefined) {
90
+ processedChildren.push(processedChild);
91
+ }
92
+ }
93
+ storyNode.children = processedChildren;
94
+ }
95
+
96
+ delete storyNode.__loopItemContext;
97
+ return storyNode;
98
+ };
99
+
100
+ export const otherNode = ({ inNode, inContext = {}, inRootData = {} } = {}) => {
101
+ const localNode = inNode;
102
+ const localContext = inContext;
103
+ const localRootData = inRootData;
104
+
105
+ if (localNode === null || localNode === undefined) return null;
106
+
107
+ if (Array.isArray(localNode)) {
108
+ return otherArrayNode({
109
+ inNode: localNode,
110
+ inContext: localContext,
111
+ inRootData: localRootData
112
+ });
113
+ }
114
+
115
+ if (typeof localNode !== "object") {
116
+ return localNode;
117
+ }
118
+
119
+ return otherStandardNode({
120
+ inNode: localNode,
121
+ inContext: localContext,
122
+ inRootData: localRootData
123
+ });
124
+ };
125
+
126
+ export const other = (inStructureOrOptions, inData = {}) => {
127
+ let localStructure = inStructureOrOptions;
128
+ let localData = inData;
129
+ let localContext = {};
130
+
131
+ if (inStructureOrOptions && typeof inStructureOrOptions === "object" && !Array.isArray(inStructureOrOptions)) {
132
+ if ("inStructure" in inStructureOrOptions || "inTree" in inStructureOrOptions || "inNode" in inStructureOrOptions) {
133
+ localStructure = inStructureOrOptions.inStructure || inStructureOrOptions.inTree || inStructureOrOptions.inNode;
134
+ localData = inStructureOrOptions.inData || localData;
135
+ localContext = inStructureOrOptions.inContext || localContext;
136
+ } else if ("structure" in inStructureOrOptions) {
137
+ localStructure = inStructureOrOptions.structure;
138
+ localData = inStructureOrOptions.data || localData;
139
+ localContext = inStructureOrOptions.context || localContext;
140
+ }
141
+ }
142
+
143
+ return otherNode({
144
+ inNode: localStructure,
145
+ inContext: localContext,
146
+ inRootData: localData
147
+ });
148
+ };
149
+
150
+ export default other;
@@ -0,0 +1,47 @@
1
+ import operation from "../operation/operation.js";
2
+ import replace from "../replace/replace.js";
3
+ import other from "../other/other.js";
4
+
5
+ export const defaultPipeline = [operation, replace, other];
6
+ export const defaultPipeline2 = [replace];
7
+
8
+ export const pipeline = (inStructureOrOptions, inData = {}, inCustomSteps) => {
9
+ let localStructure = inStructureOrOptions;
10
+ let localData = inData;
11
+ let localSteps = inCustomSteps || defaultPipeline;
12
+ console.log("inCustomSteps : ", inCustomSteps, localSteps);
13
+
14
+ if (inStructureOrOptions && typeof inStructureOrOptions === "object" && !Array.isArray(inStructureOrOptions)) {
15
+ if ("inStructure" in inStructureOrOptions || "inTree" in inStructureOrOptions || "inNode" in inStructureOrOptions) {
16
+ localStructure = inStructureOrOptions.inStructure || inStructureOrOptions.inTree || inStructureOrOptions.inNode;
17
+ localData = inStructureOrOptions.inData || localData;
18
+ localSteps = inStructureOrOptions.inSteps || localSteps;
19
+ } else if ("structure" in inStructureOrOptions) {
20
+ localStructure = inStructureOrOptions.structure;
21
+ localData = inStructureOrOptions.data || localData;
22
+ localSteps = inStructureOrOptions.steps || localSteps;
23
+ }
24
+ }
25
+
26
+ let current = localStructure;
27
+ for (const step of localSteps) {
28
+ if (typeof step === "function") {
29
+ current = step({
30
+ inStructure: current,
31
+ inData: localData
32
+ });
33
+ }
34
+ }
35
+
36
+ return current;
37
+ };
38
+
39
+ export const pipe = (...inSteps) => {
40
+ const localSteps = inSteps.length > 0 ? inSteps : defaultPipeline;
41
+
42
+ return (inStructureOrOptions, inData = {}) => {
43
+ return pipeline(inStructureOrOptions, inData, localSteps);
44
+ };
45
+ };
46
+
47
+ export default pipeline;
@@ -0,0 +1,173 @@
1
+ import { interpolateValue, interpolateString } from "../value/interpolate.js";
2
+
3
+ const replaceArrayNode = ({ inNode, inContext, inRootData }) => {
4
+ const localNode = inNode;
5
+ const localContext = inContext;
6
+ const localRootData = inRootData;
7
+
8
+ const flattened = [];
9
+
10
+ for (const child of localNode) {
11
+ const childContext = child && child.__loopItemContext
12
+ ? { ...localContext, ...child.__loopItemContext }
13
+ : localContext;
14
+
15
+ const replaced = replaceNode({
16
+ inNode: child,
17
+ inContext: childContext,
18
+ inRootData: localRootData
19
+ });
20
+
21
+ if (Array.isArray(replaced)) {
22
+ flattened.push(...replaced);
23
+ } else if (replaced !== null && replaced !== undefined) {
24
+ flattened.push(replaced);
25
+ }
26
+ }
27
+
28
+ return flattened;
29
+ };
30
+
31
+ const replacePrimitiveNode = ({ inNode, inContext, inRootData }) => {
32
+ const localNode = inNode;
33
+ const localContext = inContext;
34
+ const localRootData = inRootData;
35
+
36
+ if (typeof localNode === "string") {
37
+ return interpolateString({
38
+ inText: localNode,
39
+ inItemContext: localContext,
40
+ inRootData: localRootData
41
+ });
42
+ }
43
+
44
+ return localNode;
45
+ };
46
+
47
+ const replaceStandardNode = ({ inNode, inContext, inRootData }) => {
48
+ const localNode = inNode;
49
+ const localContext = inContext;
50
+ const localRootData = inRootData;
51
+
52
+ const currentItem = {
53
+ ...(typeof localContext.item === "object" ? localContext.item : {}),
54
+ ...localContext,
55
+ ...(localNode.__loopItemContext || {})
56
+ };
57
+
58
+ const clone = { ...localNode };
59
+
60
+ if (clone.textContent && typeof clone.textContent === "string") {
61
+ clone.textContent = interpolateString({
62
+ inText: clone.textContent,
63
+ inItemContext: currentItem,
64
+ inRootData: localRootData
65
+ });
66
+ }
67
+
68
+ if (clone.attributes) {
69
+ clone.attributes = { ...clone.attributes };
70
+ for (const [name, value] of Object.entries(clone.attributes)) {
71
+ if (typeof value === "string") {
72
+ clone.attributes[name] = interpolateValue({
73
+ inValue: value,
74
+ inItemContext: currentItem,
75
+ inRootData: localRootData
76
+ });
77
+ }
78
+ }
79
+ }
80
+
81
+ if (clone.properties) {
82
+ clone.properties = { ...clone.properties };
83
+ for (const [name, value] of Object.entries(clone.properties)) {
84
+ if (typeof value === "string") {
85
+ clone.properties[name] = interpolateValue({
86
+ inValue: value,
87
+ inItemContext: currentItem,
88
+ inRootData: localRootData
89
+ });
90
+ }
91
+ }
92
+ }
93
+
94
+ if (Array.isArray(clone.children)) {
95
+ const replacedChildren = [];
96
+ for (const child of clone.children) {
97
+ const childContext = child && child.__loopItemContext
98
+ ? { ...currentItem, ...child.__loopItemContext }
99
+ : currentItem;
100
+
101
+ const replacedChild = replaceNode({
102
+ inNode: child,
103
+ inContext: childContext,
104
+ inRootData: localRootData
105
+ });
106
+
107
+ if (Array.isArray(replacedChild)) {
108
+ replacedChildren.push(...replacedChild);
109
+ } else if (replacedChild !== null && replacedChild !== undefined) {
110
+ replacedChildren.push(replacedChild);
111
+ }
112
+ }
113
+ clone.children = replacedChildren;
114
+ }
115
+
116
+ return clone;
117
+ };
118
+
119
+ export const replaceNode = ({ inNode, inContext = {}, inRootData = {} } = {}) => {
120
+ const localNode = inNode;
121
+ const localContext = inContext;
122
+ const localRootData = inRootData;
123
+
124
+ if (localNode === null || localNode === undefined) return null;
125
+
126
+ if (Array.isArray(localNode)) {
127
+ return replaceArrayNode({
128
+ inNode: localNode,
129
+ inContext: localContext,
130
+ inRootData: localRootData
131
+ });
132
+ }
133
+
134
+ if (typeof localNode !== "object") {
135
+ return replacePrimitiveNode({
136
+ inNode: localNode,
137
+ inContext: localContext,
138
+ inRootData: localRootData
139
+ });
140
+ }
141
+
142
+ return replaceStandardNode({
143
+ inNode: localNode,
144
+ inContext: localContext,
145
+ inRootData: localRootData
146
+ });
147
+ };
148
+
149
+ export const replace = (inStructureOrOptions, inData = {}) => {
150
+ let localStructure = inStructureOrOptions;
151
+ let localData = inData;
152
+ let localContext = {};
153
+
154
+ if (inStructureOrOptions && typeof inStructureOrOptions === "object" && !Array.isArray(inStructureOrOptions)) {
155
+ if ("inStructure" in inStructureOrOptions || "inTree" in inStructureOrOptions || "inNode" in inStructureOrOptions) {
156
+ localStructure = inStructureOrOptions.inStructure || inStructureOrOptions.inTree || inStructureOrOptions.inNode;
157
+ localData = inStructureOrOptions.inData || localData;
158
+ localContext = inStructureOrOptions.inContext || localContext;
159
+ } else if ("structure" in inStructureOrOptions) {
160
+ localStructure = inStructureOrOptions.structure;
161
+ localData = inStructureOrOptions.data || localData;
162
+ localContext = inStructureOrOptions.context || localContext;
163
+ }
164
+ }
165
+
166
+ return replaceNode({
167
+ inNode: localStructure,
168
+ inContext: localContext,
169
+ inRootData: localData
170
+ });
171
+ };
172
+
173
+ export default replace;
@@ -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";