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.
- package/README.md +118 -0
- package/docs/demo.html +426 -0
- package/docs/dist/min.js +164 -0
- package/docs/dist/v1/min.js +124 -0
- package/docs/dist/v17/min.js +355 -0
- package/docs/dist/v18/min.js +160 -0
- package/docs/dist/v19/min.js +164 -0
- package/docs/dist/v2/min.js +129 -0
- package/docs/dist/v3/min.js +201 -0
- package/docs/index.html +248 -0
- package/docs/pages/architecture.html +115 -0
- package/docs/pages/how-it-works.html +125 -0
- package/docs/pages/what-not.html +100 -0
- package/docs/pages/what.html +105 -0
- package/docs/pages/why.html +88 -0
- package/docs/samples/form.html +265 -0
- package/docs/samples/index.html +112 -0
- package/docs/samples/table.html +306 -0
- package/index.js +2 -0
- package/package.json +50 -0
- package/samples/dataList/index.html +31 -0
- package/samples/dataList/index.js +62 -0
- package/samples/dataList/input/data.json +5043 -0
- package/samples/dataList/input/structure.json +38 -0
- package/samples/dataList copy/index.html +30 -0
- package/samples/dataList copy/index.js +61 -0
- package/samples/dataList copy/input/data.json +35307 -0
- package/samples/dataList copy/input/structure.json +18 -0
- package/samples/form/index.html +29 -0
- package/samples/form/index.js +64 -0
- package/samples/form/input/data.json +9 -0
- package/samples/form/input/structure.json +192 -0
- package/samples/form-/data.json +42 -0
- package/samples/form-/structure.json +110 -0
- package/samples/select/index.html +31 -0
- package/samples/select/index.js +61 -0
- package/samples/select/input/data.json +35287 -0
- package/samples/select/input/select.json +18 -0
- package/samples/select/input/structure.json +47 -0
- package/samples/table/index.html +29 -0
- package/samples/table/index.js +61 -0
- package/samples/table/input/data.json +35287 -0
- package/samples/table/input/structure copy.json +47 -0
- package/samples/table/input/structure.json +86 -0
- package/samples/table/input/table.json +135 -0
- package/samples/table-/data.json +68 -0
- package/samples/table-/structure.json +235 -0
- package/src/index.js +2 -0
- package/src/v10/index.js +96 -0
- package/src/v10/instructionEngine/compile/compileTree.js +191 -0
- package/src/v10/instructionEngine/compileTree.js +1 -0
- package/src/v10/instructionEngine/expandIteration.js +1 -0
- package/src/v10/instructionEngine/index.js +29 -0
- package/src/v10/instructionEngine/interpolate.js +2 -0
- package/src/v10/instructionEngine/iteration/expandIteration.js +95 -0
- package/src/v10/instructionEngine/operation/operation.js +237 -0
- package/src/v10/instructionEngine/other/other.js +150 -0
- package/src/v10/instructionEngine/pipeline/pipeline.js +47 -0
- package/src/v10/instructionEngine/replace/replace.js +173 -0
- package/src/v10/instructionEngine/resolve/resolvePath.js +18 -0
- package/src/v10/instructionEngine/resolve/resolveTokenValue.js +22 -0
- package/src/v10/instructionEngine/resolvePath.js +1 -0
- package/src/v10/instructionEngine/resolveTokenValue.js +1 -0
- package/src/v10/instructionEngine/story/storyInjector.js +50 -0
- package/src/v10/instructionEngine/storyInjector.js +1 -0
- package/src/v10/instructionEngine/value/interpolate.js +38 -0
- package/src/v11/index.js +116 -0
- package/src/v11/iterate.js +270 -0
- package/src/v11/replace.js +169 -0
- package/src/v11/resolvePath.js +29 -0
- package/src/v12/index.js +122 -0
- package/src/v12/iterate/bindFormValues.js +74 -0
- package/src/v12/iterate/expandIteration.js +181 -0
- package/src/v12/iterate/index.js +10 -0
- package/src/v12/iterate/iterate.js +56 -0
- package/src/v12/iterate/iterateNode.js +86 -0
- package/src/v12/iterate/resolveCollection.js +37 -0
- package/src/v12/iterate.js +270 -0
- package/src/v12/replace.js +169 -0
- package/src/v12/resolvePath.js +29 -0
- package/src/v13/index.js +110 -0
- package/src/v13/iterate/bindFormValues.js +74 -0
- package/src/v13/iterate/expandIteration.js +188 -0
- package/src/v13/iterate/index.js +9 -0
- package/src/v13/iterate/iterate.js +32 -0
- package/src/v13/iterate/iterateNode.js +86 -0
- package/src/v13/iterate/resolveCollection.js +37 -0
- package/src/v13/iterate/walk.js +90 -0
- package/src/v13/iterate.js +270 -0
- package/src/v13/replace.js +169 -0
- package/src/v13/resolvePath.js +29 -0
- package/src/v14/index.js +112 -0
- package/src/v14/iterate/bindFormValues.js +74 -0
- package/src/v14/iterate/expandIteration.js +188 -0
- package/src/v14/iterate/index.js +9 -0
- package/src/v14/iterate/iterate.js +32 -0
- package/src/v14/iterate/resolveCollection.js +37 -0
- package/src/v14/iterate/walk/walk copy 2.js +114 -0
- package/src/v14/iterate/walk/walk copy.js +90 -0
- package/src/v14/iterate/walk/walk.js +98 -0
- package/src/v14/iterate.js +270 -0
- package/src/v14/replace/index.js +16 -0
- package/src/v14/replace/walk.js +90 -0
- package/src/v14/replace.js +153 -0
- package/src/v14/resolvePath.js +29 -0
- package/src/v15/index.js +123 -0
- package/src/v15/iterate/bindFormValues.js +74 -0
- package/src/v15/iterate/expandIteration.js +188 -0
- package/src/v15/iterate/index.js +9 -0
- package/src/v15/iterate/iterate.js +32 -0
- package/src/v15/iterate/resolveCollection.js +37 -0
- package/src/v15/iterate/walk/walk copy 2.js +114 -0
- package/src/v15/iterate/walk/walk copy.js +90 -0
- package/src/v15/iterate/walk/walk.js +195 -0
- package/src/v15/iterate.js +270 -0
- package/src/v15/replace/index.js +16 -0
- package/src/v15/replace/walk.js +90 -0
- package/src/v15/replace.js +155 -0
- package/src/v15/resolvePath.js +29 -0
- package/src/v16/index.js +129 -0
- package/src/v16/iterate/bindFormValues.js +74 -0
- package/src/v16/iterate/expandIteration.js +188 -0
- package/src/v16/iterate/index.js +9 -0
- package/src/v16/iterate/iterate.js +32 -0
- package/src/v16/iterate/resolveCollection.js +37 -0
- package/src/v16/iterate/walk/walk copy 2.js +114 -0
- package/src/v16/iterate/walk/walk copy.js +90 -0
- package/src/v16/iterate/walk/walk.js +196 -0
- package/src/v16/iterate.js +270 -0
- package/src/v16/replace/index.js +16 -0
- package/src/v16/replace/walk.js +90 -0
- package/src/v16/replace.js +155 -0
- package/src/v16/resolvePath.js +29 -0
- package/src/v17/index.js +119 -0
- package/src/v17/iterate/bindFormValues.js +74 -0
- package/src/v17/iterate/expandIteration.js +188 -0
- package/src/v17/iterate/index.js +9 -0
- package/src/v17/iterate/iterate.js +32 -0
- package/src/v17/iterate/resolveCollection.js +37 -0
- package/src/v17/iterate/walk/iterateDo.js +42 -0
- package/src/v17/iterate/walk/replaceWithData.js +60 -0
- package/src/v17/iterate/walk/walk.js +94 -0
- package/src/v17/iterate.js +270 -0
- package/src/v17/replace/index.js +16 -0
- package/src/v17/replace/walk.js +90 -0
- package/src/v17/replace.js +160 -0
- package/src/v17/resolvePath.js +29 -0
- package/src/v18/index.js +66 -0
- package/src/v18/meta.js +7 -0
- package/src/v18/registerGlobal.js +17 -0
- package/src/v18/replace.js +18 -0
- package/src/v18/resolvePath.js +29 -0
- package/src/v18/walk/iterate/v1/index.js +42 -0
- package/src/v18/walk/iterate/v2/index.js +32 -0
- package/src/v18/walk/iterate/v3/index.js +46 -0
- package/src/v18/walk/iterate/v4/createChildren.js +24 -0
- package/src/v18/walk/iterate/v4/index.js +25 -0
- package/src/v18/walk/replaceWithData/v1/index.js +42 -0
- package/src/v18/walk/replaceWithData/v1/replaceCommon.js +21 -0
- package/src/v18/walk/replaceWithData/v2/index.js +105 -0
- package/src/v18/walk/replaceWithData/v2/replaceCommon.js +21 -0
- package/src/v18/walk/replaceWithData/v3/index.js +15 -0
- package/src/v18/walk/replaceWithData/v3/replaceAttributes.js +29 -0
- package/src/v18/walk/replaceWithData/v3/replaceCommon.js +23 -0
- package/src/v18/walk/replaceWithData/v3/replaceNodeValue.js +27 -0
- package/src/v18/walk/walk.js +94 -0
- package/src/v19/index.js +55 -0
- package/src/v19/meta.js +7 -0
- package/src/v19/registerGlobal.js +17 -0
- package/src/v19/replace.js +18 -0
- package/src/v19/resolvePath.js +29 -0
- package/src/v19/walk/iterate/v1/index.js +42 -0
- package/src/v19/walk/iterate/v2/index.js +32 -0
- package/src/v19/walk/iterate/v3/index.js +46 -0
- package/src/v19/walk/iterate/v4/createChildren.js +27 -0
- package/src/v19/walk/iterate/v4/index.js +25 -0
- package/src/v19/walk/replaceWithData/v1/index.js +42 -0
- package/src/v19/walk/replaceWithData/v1/replaceCommon.js +21 -0
- package/src/v19/walk/replaceWithData/v2/index.js +105 -0
- package/src/v19/walk/replaceWithData/v2/replaceCommon.js +21 -0
- package/src/v19/walk/replaceWithData/v3/index.js +15 -0
- package/src/v19/walk/replaceWithData/v3/replaceAttributes.js +29 -0
- package/src/v19/walk/replaceWithData/v3/replaceCommon.js +23 -0
- package/src/v19/walk/replaceWithData/v3/replaceNodeValue.js +27 -0
- package/src/v19/walk/walk.js +97 -0
- package/src/v8/index.js +69 -0
- package/src/v8/instructionEngine/compile/compileTree.js +191 -0
- package/src/v8/instructionEngine/compileTree.js +1 -0
- package/src/v8/instructionEngine/expandIteration.js +1 -0
- package/src/v8/instructionEngine/index.js +16 -0
- package/src/v8/instructionEngine/interpolate.js +2 -0
- package/src/v8/instructionEngine/iteration/expandIteration.js +95 -0
- package/src/v8/instructionEngine/resolve/resolvePath.js +18 -0
- package/src/v8/instructionEngine/resolve/resolveTokenValue.js +22 -0
- package/src/v8/instructionEngine/resolvePath.js +1 -0
- package/src/v8/instructionEngine/resolveTokenValue.js +1 -0
- package/src/v8/instructionEngine/story/storyInjector.js +50 -0
- package/src/v8/instructionEngine/storyInjector.js +1 -0
- package/src/v8/instructionEngine/value/interpolate.js +38 -0
- package/src/v9/index.js +96 -0
- package/src/v9/instructionEngine/compile/compileTree.js +191 -0
- package/src/v9/instructionEngine/compileTree.js +1 -0
- package/src/v9/instructionEngine/expandIteration.js +1 -0
- package/src/v9/instructionEngine/index.js +29 -0
- package/src/v9/instructionEngine/interpolate.js +2 -0
- package/src/v9/instructionEngine/iteration/expandIteration.js +95 -0
- package/src/v9/instructionEngine/operation/operation.js +237 -0
- package/src/v9/instructionEngine/other/other.js +150 -0
- package/src/v9/instructionEngine/pipeline/pipeline.js +47 -0
- package/src/v9/instructionEngine/replace/replace.js +173 -0
- package/src/v9/instructionEngine/resolve/resolvePath.js +18 -0
- package/src/v9/instructionEngine/resolve/resolveTokenValue.js +22 -0
- package/src/v9/instructionEngine/resolvePath.js +1 -0
- package/src/v9/instructionEngine/resolveTokenValue.js +1 -0
- package/src/v9/instructionEngine/story/storyInjector.js +50 -0
- package/src/v9/instructionEngine/storyInjector.js +1 -0
- package/src/v9/instructionEngine/value/interpolate.js +38 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { interpolateString } from "../value/interpolate.js";
|
|
2
|
+
|
|
3
|
+
export const injectStory = (cloned, originalNode, currentItem, inRootData) => {
|
|
4
|
+
if (typeof originalNode.story !== "string" || originalNode.story.trim() === "") return cloned;
|
|
5
|
+
|
|
6
|
+
const storyText = interpolateString({
|
|
7
|
+
inText: originalNode.story,
|
|
8
|
+
inItemContext: currentItem,
|
|
9
|
+
inRootData
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const storyTitle = typeof originalNode.storyTitle === "string" && originalNode.storyTitle.trim() !== ""
|
|
13
|
+
? interpolateString({
|
|
14
|
+
inText: originalNode.storyTitle,
|
|
15
|
+
inItemContext: currentItem,
|
|
16
|
+
inRootData
|
|
17
|
+
})
|
|
18
|
+
: null;
|
|
19
|
+
|
|
20
|
+
const storyTag = (typeof originalNode.storyTag === "string" && originalNode.storyTag.trim() !== "") ? originalNode.storyTag : "p";
|
|
21
|
+
const storyClass = (typeof originalNode.storyClass === "string" && originalNode.storyClass.trim() !== "") ? originalNode.storyClass : "story text-muted small";
|
|
22
|
+
const storyPosition = originalNode.storyPosition === "append" ? "append" : "prepend";
|
|
23
|
+
|
|
24
|
+
const nextChildren = Array.isArray(cloned.children) ? cloned.children : [];
|
|
25
|
+
const storyNodes = [];
|
|
26
|
+
|
|
27
|
+
if (storyTitle) {
|
|
28
|
+
storyNodes.push({
|
|
29
|
+
tagName: "strong",
|
|
30
|
+
attributes: { class: "story-title d-block" },
|
|
31
|
+
textContent: storyTitle
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
storyNodes.push({
|
|
36
|
+
tagName: storyTag,
|
|
37
|
+
attributes: { class: storyClass },
|
|
38
|
+
textContent: storyText
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if (storyPosition === "prepend") {
|
|
42
|
+
cloned.children = [...storyNodes, ...nextChildren];
|
|
43
|
+
} else {
|
|
44
|
+
cloned.children = [...nextChildren, ...storyNodes];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return cloned;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default injectStory;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { injectStory, default } from "./story/storyInjector.js";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { resolveTokenValue } from "../resolve/resolveTokenValue.js";
|
|
2
|
+
|
|
3
|
+
export const interpolateValue = ({ inValue, inItemContext, inRootData }) => {
|
|
4
|
+
if (typeof inValue !== "string" || !inValue.includes("${")) {
|
|
5
|
+
return inValue;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const exactMatch = inValue.match(/^\$\{([^}]+)\}$/);
|
|
9
|
+
if (exactMatch) {
|
|
10
|
+
const token = resolveTokenValue({
|
|
11
|
+
inPath: exactMatch[1].trim(),
|
|
12
|
+
inItemContext,
|
|
13
|
+
inRootData
|
|
14
|
+
});
|
|
15
|
+
return token !== undefined && token !== null ? token : "";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return inValue.replace(/\$\{([^}]+)\}/g, (_, expr) => {
|
|
19
|
+
const token = resolveTokenValue({
|
|
20
|
+
inPath: expr.trim(),
|
|
21
|
+
inItemContext,
|
|
22
|
+
inRootData
|
|
23
|
+
});
|
|
24
|
+
return token !== undefined && token !== null ? String(token) : "";
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const interpolateString = ({ inText, inItemContext, inRootData }) => {
|
|
29
|
+
const value = interpolateValue({
|
|
30
|
+
inValue: inText,
|
|
31
|
+
inItemContext,
|
|
32
|
+
inRootData
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return value !== undefined && value !== null ? String(value) : "";
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default { interpolateValue, interpolateString };
|
package/src/v9/index.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* json-to-spec v9
|
|
3
|
+
*
|
|
4
|
+
* Modular 3-Stage Specification Compiler:
|
|
5
|
+
* 1. operation: detects and expands iterations and structural directives
|
|
6
|
+
* 2. replace: resolves dynamic token interpolation in strings, text, attributes & properties
|
|
7
|
+
* 3. other: applies form control value bindings, story injection, and cleans up metadata
|
|
8
|
+
*
|
|
9
|
+
* All three applications can be invoked independently, chained in custom pipelines,
|
|
10
|
+
* or executed via compile().
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import operation from "./instructionEngine/operation/operation.js";
|
|
14
|
+
import replace from "./instructionEngine/replace/replace.js";
|
|
15
|
+
import other from "./instructionEngine/other/other.js";
|
|
16
|
+
import { pipeline, pipe, defaultPipeline } from "./instructionEngine/pipeline/pipeline.js";
|
|
17
|
+
|
|
18
|
+
export const meta = {
|
|
19
|
+
version: "9.0.0",
|
|
20
|
+
name: "json-to-spec/v9",
|
|
21
|
+
description: "Pure JSON Specification Compiler with decoupled operation, replace, and other pipeline stages"
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Compiles a JSON UI structure tree containing `jsonToSpec` operations with a data payload.
|
|
26
|
+
*
|
|
27
|
+
* Outside API:
|
|
28
|
+
* - compile(structureJson, dataJson)
|
|
29
|
+
* - compile({ inStructure, inData, inSteps })
|
|
30
|
+
* - compile({ structure, data, steps })
|
|
31
|
+
*
|
|
32
|
+
* @param {Object|Array} inStructureOrOptions - The UI structure JSON tree or options object
|
|
33
|
+
* @param {Object} [inData] - Data payload containing collections and values
|
|
34
|
+
* @returns {Object|Array} - Compiled 100% pure JSON specification ready for json-to-dom
|
|
35
|
+
*/
|
|
36
|
+
export const compile = (inStructureOrOptions, inData = {}) => {
|
|
37
|
+
let localStructure = inStructureOrOptions;
|
|
38
|
+
let localData = inData || {};
|
|
39
|
+
let localSteps = defaultPipeline;
|
|
40
|
+
|
|
41
|
+
if (inStructureOrOptions && typeof inStructureOrOptions === "object" && !Array.isArray(inStructureOrOptions)) {
|
|
42
|
+
if ("inStructure" in inStructureOrOptions || "inTree" in inStructureOrOptions || "inNode" in inStructureOrOptions) {
|
|
43
|
+
localStructure = inStructureOrOptions.inStructure || inStructureOrOptions.inTree || inStructureOrOptions.inNode;
|
|
44
|
+
localData = inStructureOrOptions.inData || localData;
|
|
45
|
+
localSteps = inStructureOrOptions.inSteps || localSteps;
|
|
46
|
+
} else if ("structure" in inStructureOrOptions) {
|
|
47
|
+
localStructure = inStructureOrOptions.structure;
|
|
48
|
+
localData = inStructureOrOptions.data || localData;
|
|
49
|
+
localSteps = inStructureOrOptions.steps || localSteps;
|
|
50
|
+
} else if ("context" in inStructureOrOptions) {
|
|
51
|
+
localStructure = inStructureOrOptions.context;
|
|
52
|
+
localData = inStructureOrOptions.data || localData;
|
|
53
|
+
localSteps = inStructureOrOptions.steps || localSteps;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return pipeline({
|
|
58
|
+
inStructure: localStructure,
|
|
59
|
+
inData: localData,
|
|
60
|
+
inSteps: localSteps
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const jsonToSpec = {
|
|
65
|
+
operation,
|
|
66
|
+
replace,
|
|
67
|
+
other,
|
|
68
|
+
pipeline,
|
|
69
|
+
pipe,
|
|
70
|
+
compile
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export {
|
|
74
|
+
operation,
|
|
75
|
+
replace,
|
|
76
|
+
other,
|
|
77
|
+
pipeline,
|
|
78
|
+
pipe,
|
|
79
|
+
defaultPipeline
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
if (typeof globalThis !== "undefined") {
|
|
83
|
+
globalThis.ks ??= {};
|
|
84
|
+
globalThis.ks["json-to-spec"] = {
|
|
85
|
+
meta,
|
|
86
|
+
compile,
|
|
87
|
+
pipeline,
|
|
88
|
+
pipe,
|
|
89
|
+
operation,
|
|
90
|
+
replace,
|
|
91
|
+
other,
|
|
92
|
+
jsonToSpec
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
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,29 @@
|
|
|
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
|
+
import { operation, operationNode } from "./operation/operation.js";
|
|
7
|
+
import { replace, replaceNode } from "./replace/replace.js";
|
|
8
|
+
import { other, otherNode } from "./other/other.js";
|
|
9
|
+
import { pipeline, pipe, defaultPipeline } from "./pipeline/pipeline.js";
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
compileNode,
|
|
13
|
+
expandIterationNode,
|
|
14
|
+
interpolateValue,
|
|
15
|
+
interpolateString,
|
|
16
|
+
injectStory,
|
|
17
|
+
resolvePath,
|
|
18
|
+
operation,
|
|
19
|
+
operationNode,
|
|
20
|
+
replace,
|
|
21
|
+
replaceNode,
|
|
22
|
+
other,
|
|
23
|
+
otherNode,
|
|
24
|
+
pipeline,
|
|
25
|
+
pipe,
|
|
26
|
+
defaultPipeline
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default compileNode;
|
|
@@ -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;
|