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,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively walks a JSON structure for the replace phase.
|
|
3
|
+
*
|
|
4
|
+
* The walker knows only how to traverse.
|
|
5
|
+
* The supplied operation decides what to do with each node.
|
|
6
|
+
*/
|
|
7
|
+
const walk = ({
|
|
8
|
+
inNode,
|
|
9
|
+
inContext = {},
|
|
10
|
+
inData = {},
|
|
11
|
+
inOperation
|
|
12
|
+
} = {}) => {
|
|
13
|
+
const localNode = inNode;
|
|
14
|
+
const localContext = inContext;
|
|
15
|
+
const localData = inData;
|
|
16
|
+
|
|
17
|
+
if (localNode === null || localNode === undefined) {
|
|
18
|
+
return localNode;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (Array.isArray(localNode)) {
|
|
22
|
+
const results = [];
|
|
23
|
+
|
|
24
|
+
for (const child of localNode) {
|
|
25
|
+
const result = walk({
|
|
26
|
+
inNode: child,
|
|
27
|
+
inContext: localContext,
|
|
28
|
+
inData: localData,
|
|
29
|
+
inOperation
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (Array.isArray(result)) {
|
|
33
|
+
results.push(...result);
|
|
34
|
+
} else if (result !== null && result !== undefined) {
|
|
35
|
+
results.push(result);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return results;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (typeof localNode !== "object") {
|
|
43
|
+
return localNode;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const operatedNode = typeof inOperation === "function"
|
|
47
|
+
? inOperation({
|
|
48
|
+
inNode: localNode,
|
|
49
|
+
inContext: localContext,
|
|
50
|
+
inData: localData
|
|
51
|
+
})
|
|
52
|
+
: localNode;
|
|
53
|
+
|
|
54
|
+
const localOperatedNode =
|
|
55
|
+
operatedNode === undefined
|
|
56
|
+
? localNode
|
|
57
|
+
: operatedNode;
|
|
58
|
+
|
|
59
|
+
if (localOperatedNode === null) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (Array.isArray(localOperatedNode)) {
|
|
64
|
+
return walk({
|
|
65
|
+
inNode: localOperatedNode,
|
|
66
|
+
inContext: localContext,
|
|
67
|
+
inData: localData,
|
|
68
|
+
inOperation
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (typeof localOperatedNode !== "object") {
|
|
73
|
+
return localOperatedNode;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const clone = { ...localOperatedNode };
|
|
77
|
+
|
|
78
|
+
if (Array.isArray(clone.children)) {
|
|
79
|
+
clone.children = walk({
|
|
80
|
+
inNode: clone.children,
|
|
81
|
+
inContext: localContext,
|
|
82
|
+
inData: localData,
|
|
83
|
+
inOperation
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return clone;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export default walk;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import resolvePath from "./resolvePath.js";
|
|
2
|
+
import walk from "./iterate/walk/walk.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Resolves a token expression path against local context first, then root data.
|
|
6
|
+
*/
|
|
7
|
+
const resolveTokenValue = ({ inPath, inContext, inData }) => {
|
|
8
|
+
const localPath = inPath;
|
|
9
|
+
const localContext = inContext;
|
|
10
|
+
const localData = inData;
|
|
11
|
+
|
|
12
|
+
let value = resolvePath({ inData: localContext, inPath: localPath });
|
|
13
|
+
|
|
14
|
+
if (value === undefined && localContext && typeof localContext === "object") {
|
|
15
|
+
if (localContext.item && typeof localContext.item === "object") {
|
|
16
|
+
value = resolvePath({ inData: localContext.item, inPath: localPath });
|
|
17
|
+
}
|
|
18
|
+
if (value === undefined && localContext.row && typeof localContext.row === "object") {
|
|
19
|
+
value = resolvePath({ inData: localContext.row, inPath: localPath });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (value === undefined && localData) {
|
|
24
|
+
value = resolvePath({ inData: localData, inPath: localPath });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return value;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Replaces ${path} tokens in a string value.
|
|
32
|
+
*/
|
|
33
|
+
const replaceValue = ({ inValue, inContext, inData }) => {
|
|
34
|
+
const localValue = inValue;
|
|
35
|
+
const localContext = inContext;
|
|
36
|
+
const localData = inData;
|
|
37
|
+
|
|
38
|
+
if (typeof localValue !== "string" || !localValue.includes("${")) {
|
|
39
|
+
return localValue;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const hasItemContext = Boolean(localContext && (localContext.item || Object.keys(localContext).length > 0));
|
|
43
|
+
|
|
44
|
+
// Exact match: "${path}" -> preserve primitive types (boolean, number, object)
|
|
45
|
+
const exactMatch = localValue.match(/^\$\{([^}]+)\}$/);
|
|
46
|
+
if (exactMatch) {
|
|
47
|
+
const token = resolveTokenValue({
|
|
48
|
+
inPath: exactMatch[1].trim(),
|
|
49
|
+
inContext: localContext,
|
|
50
|
+
inData: localData
|
|
51
|
+
});
|
|
52
|
+
return token !== undefined && token !== null ? token : (hasItemContext ? "" : localValue);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Substring interpolation: "Hello ${name}" -> string replacement
|
|
56
|
+
return localValue.replace(/\$\{([^}]+)\}/g, (fullMatch, expr) => {
|
|
57
|
+
const token = resolveTokenValue({
|
|
58
|
+
inPath: expr.trim(),
|
|
59
|
+
inContext: localContext,
|
|
60
|
+
inData: localData
|
|
61
|
+
});
|
|
62
|
+
return token !== undefined && token !== null ? String(token) : (hasItemContext ? "" : fullMatch);
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Recursively walks a JSON tree and replaces all ${...} tokens against data.
|
|
68
|
+
*/
|
|
69
|
+
export const replaceNode = ({ inNode, inContext = {}, inData = {} } = {}) => {
|
|
70
|
+
const localNode = inNode;
|
|
71
|
+
const localContext = inContext;
|
|
72
|
+
const localData = inData;
|
|
73
|
+
|
|
74
|
+
if (localNode === null || localNode === undefined) return localNode;
|
|
75
|
+
|
|
76
|
+
if (Array.isArray(localNode)) {
|
|
77
|
+
return localNode.map(child => replaceNode({
|
|
78
|
+
inNode: child,
|
|
79
|
+
inContext: localContext,
|
|
80
|
+
inData: localData
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (typeof localNode === "string") {
|
|
85
|
+
return replaceValue({
|
|
86
|
+
inValue: localNode,
|
|
87
|
+
inContext: localContext,
|
|
88
|
+
inData: localData
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (typeof localNode !== "object") {
|
|
93
|
+
return localNode;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const clone = { ...localNode };
|
|
97
|
+
|
|
98
|
+
if (clone.textContent && typeof clone.textContent === "string") {
|
|
99
|
+
clone.textContent = replaceValue({
|
|
100
|
+
inValue: clone.textContent,
|
|
101
|
+
inContext: localContext,
|
|
102
|
+
inData: localData
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (clone.attributes) {
|
|
107
|
+
clone.attributes = { ...clone.attributes };
|
|
108
|
+
for (const [name, val] of Object.entries(clone.attributes)) {
|
|
109
|
+
if (typeof val === "string") {
|
|
110
|
+
clone.attributes[name] = replaceValue({
|
|
111
|
+
inValue: val,
|
|
112
|
+
inContext: localContext,
|
|
113
|
+
inData: localData
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (clone.properties) {
|
|
120
|
+
clone.properties = { ...clone.properties };
|
|
121
|
+
for (const [name, val] of Object.entries(clone.properties)) {
|
|
122
|
+
if (typeof val === "string") {
|
|
123
|
+
clone.properties[name] = replaceValue({
|
|
124
|
+
inValue: val,
|
|
125
|
+
inContext: localContext,
|
|
126
|
+
inData: localData
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (Array.isArray(clone.children)) {
|
|
133
|
+
clone.children = clone.children.map(child => replaceNode({
|
|
134
|
+
inNode: child,
|
|
135
|
+
inContext: localContext,
|
|
136
|
+
inData: localData
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return clone;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Main replace function: (structure, data) -> replaced JSON structure
|
|
145
|
+
*/
|
|
146
|
+
export const replace = ({ inStructureAsJson, inDataAsJson, inOperation }) => {
|
|
147
|
+
// console.log("inDataAsJson-------- : ", inDataAsJson);
|
|
148
|
+
|
|
149
|
+
return walk({
|
|
150
|
+
inNode: inStructureAsJson,
|
|
151
|
+
inData: inDataAsJson, inOperation
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export default replace;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves a dot-delimited path or array of keys from a data object.
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} inArgs
|
|
5
|
+
* @param {Object} inArgs.inData - Target object to resolve from
|
|
6
|
+
* @param {string|Array} inArgs.inPath - Key or dot-path (e.g. "meta.formTitle", "columns")
|
|
7
|
+
* @returns {*} Resolved value or undefined
|
|
8
|
+
*/
|
|
9
|
+
export const resolvePath = ({ inData, inPath }) => {
|
|
10
|
+
const localData = inData;
|
|
11
|
+
const localPath = inPath;
|
|
12
|
+
|
|
13
|
+
if (localData === null || localData === undefined) return undefined;
|
|
14
|
+
if (localPath === undefined || localPath === null || localPath === "" || localPath === ".") {
|
|
15
|
+
return localData;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const segments = Array.isArray(localPath) ? localPath : String(localPath).split(".");
|
|
19
|
+
let current = localData;
|
|
20
|
+
|
|
21
|
+
for (const segment of segments) {
|
|
22
|
+
if (current === null || current === undefined) return undefined;
|
|
23
|
+
current = current[segment];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return current;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default resolvePath;
|
package/src/v17/index.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* json-to-spec v11
|
|
3
|
+
*
|
|
4
|
+
* Minimalist 2-Layer Specification Compiler:
|
|
5
|
+
* 1. replace: Pure ${...} token replacement across JSON structures.
|
|
6
|
+
* 2. iterate: Evaluates jsonToSpec operations, expanding collections into clean children.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { replace, replaceNode } from "./replace.js";
|
|
10
|
+
|
|
11
|
+
// import { iterate, iterateNode, operation } from "./iterate.js";
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
iterate,
|
|
15
|
+
operation
|
|
16
|
+
} from "./iterate/index.js";
|
|
17
|
+
|
|
18
|
+
export const meta = {
|
|
19
|
+
version: "17.0.0",
|
|
20
|
+
name: "json-to-spec/v17",
|
|
21
|
+
description: "Minimalist 2-layer compiler: pure value replace + jsonToSpec iterate"
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Executes a custom pipeline of transformations over the structure.
|
|
26
|
+
*/
|
|
27
|
+
export const pipeline = ({ inStructure, inData = {}, inSteps = [replace, iterate] } = {}) => {
|
|
28
|
+
const localData = inData;
|
|
29
|
+
const localSteps = inSteps;
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
let current = inStructure;
|
|
33
|
+
for (const step of localSteps) {
|
|
34
|
+
if (typeof step === "function") {
|
|
35
|
+
current = step({ inStructure: current, inData: localData });
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return current;
|
|
39
|
+
} catch (err) {
|
|
40
|
+
console.error("[json-to-spec/v17] pipeline error:", err);
|
|
41
|
+
throw err;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const pipe = (...inSteps) => {
|
|
46
|
+
const localSteps = inSteps.length > 0 ? inSteps : [replace, iterate];
|
|
47
|
+
return (inStructure, inData = {}) => {
|
|
48
|
+
return pipeline({ inStructure, inData, inSteps: localSteps });
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Main compiler entry point:
|
|
54
|
+
* 1. Replace values: replace(structure, data)
|
|
55
|
+
* 2. Iterate/Operate: iterate(replacedStructure, data)
|
|
56
|
+
*/
|
|
57
|
+
export const compile = (inStructureOrOptions, inData = {}) => {
|
|
58
|
+
let localStructure = inStructureOrOptions;
|
|
59
|
+
let localData = inData;
|
|
60
|
+
|
|
61
|
+
console.log("ccccccccccccc-------- : ", localData);
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const iteratedData = replace({
|
|
65
|
+
inStructureAsJson: localStructure,
|
|
66
|
+
inDataAsJson: localData,
|
|
67
|
+
inOperation: "iterateDo"
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const replacedData = replace({
|
|
71
|
+
inStructureAsJson: iteratedData,
|
|
72
|
+
inDataAsJson: localData,
|
|
73
|
+
inOperation: "replace"
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
console.log("iteratedData : ", iteratedData, replacedData);
|
|
77
|
+
|
|
78
|
+
// const spec = iterate({
|
|
79
|
+
// inStructure: replaced,
|
|
80
|
+
// inData: localData
|
|
81
|
+
// });
|
|
82
|
+
|
|
83
|
+
return replacedData;
|
|
84
|
+
} catch (err) {
|
|
85
|
+
console.error("[json-to-spec/v17] compile error:", err);
|
|
86
|
+
throw err;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const jsonToSpec = {
|
|
91
|
+
replace,
|
|
92
|
+
iterate,
|
|
93
|
+
operation,
|
|
94
|
+
pipeline,
|
|
95
|
+
pipe,
|
|
96
|
+
compile
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export {
|
|
100
|
+
replace,
|
|
101
|
+
replaceNode,
|
|
102
|
+
iterate,
|
|
103
|
+
operation
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
if (typeof globalThis !== "undefined") {
|
|
107
|
+
globalThis.ks ??= {};
|
|
108
|
+
globalThis.ks["json-to-spec"] = {
|
|
109
|
+
meta,
|
|
110
|
+
compile,
|
|
111
|
+
replace,
|
|
112
|
+
iterate,
|
|
113
|
+
operation,
|
|
114
|
+
pipeline,
|
|
115
|
+
jsonToSpec
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export default compile;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively binds form field values into
|
|
3
|
+
* input, textarea, select and option nodes.
|
|
4
|
+
*/
|
|
5
|
+
const bindFormValues = ({ inNode, inItem, inData }) => {
|
|
6
|
+
const localNode = inNode;
|
|
7
|
+
const localItem = inItem;
|
|
8
|
+
const localData = inData;
|
|
9
|
+
|
|
10
|
+
if (!localNode || typeof localNode !== "object") {
|
|
11
|
+
return localNode;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (localNode.attributes) {
|
|
15
|
+
const isFormField = [
|
|
16
|
+
"input",
|
|
17
|
+
"textarea",
|
|
18
|
+
"select",
|
|
19
|
+
"option"
|
|
20
|
+
].includes(localNode.tagName?.toLowerCase());
|
|
21
|
+
|
|
22
|
+
if (isFormField) {
|
|
23
|
+
const fieldName =
|
|
24
|
+
localItem.field ||
|
|
25
|
+
localItem.columnName ||
|
|
26
|
+
localItem.name;
|
|
27
|
+
|
|
28
|
+
if (
|
|
29
|
+
localItem.value !== undefined &&
|
|
30
|
+
localItem.value !== null
|
|
31
|
+
) {
|
|
32
|
+
localNode.attributes.value = String(localItem.value);
|
|
33
|
+
|
|
34
|
+
if (
|
|
35
|
+
localNode.tagName === "textarea" &&
|
|
36
|
+
!localNode.textContent
|
|
37
|
+
) {
|
|
38
|
+
localNode.textContent = String(localItem.value);
|
|
39
|
+
}
|
|
40
|
+
} else if (
|
|
41
|
+
fieldName &&
|
|
42
|
+
localData[fieldName] !== undefined &&
|
|
43
|
+
localData[fieldName] !== null
|
|
44
|
+
) {
|
|
45
|
+
localNode.attributes.value = String(
|
|
46
|
+
localData[fieldName]
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
if (
|
|
50
|
+
localNode.tagName === "textarea" &&
|
|
51
|
+
!localNode.textContent
|
|
52
|
+
) {
|
|
53
|
+
localNode.textContent = String(
|
|
54
|
+
localData[fieldName]
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (Array.isArray(localNode.children)) {
|
|
62
|
+
localNode.children.forEach(child => {
|
|
63
|
+
bindFormValues({
|
|
64
|
+
inNode: child,
|
|
65
|
+
inItem: localItem,
|
|
66
|
+
inData: localData
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return localNode;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export default bindFormValues;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import resolveCollection from "./resolveCollection.js";
|
|
2
|
+
import bindFormValues from "./bindFormValues.js";
|
|
3
|
+
import { replaceNode } from "../replace.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Expands a single iteration directive into an array of
|
|
7
|
+
* specification nodes.
|
|
8
|
+
*/
|
|
9
|
+
const expandIteration = ({
|
|
10
|
+
inNode,
|
|
11
|
+
inContext,
|
|
12
|
+
inData,
|
|
13
|
+
walk
|
|
14
|
+
}) => {
|
|
15
|
+
const localNode = inNode;
|
|
16
|
+
const localContext = inContext;
|
|
17
|
+
const localData = inData;
|
|
18
|
+
|
|
19
|
+
const instruction = localNode && (
|
|
20
|
+
localNode.jsonToSpec ||
|
|
21
|
+
(localNode.operation ? localNode : null)
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
if (!instruction) return undefined;
|
|
25
|
+
|
|
26
|
+
const operationType = instruction.operation;
|
|
27
|
+
|
|
28
|
+
if (
|
|
29
|
+
operationType !== "iterate" &&
|
|
30
|
+
!instruction.source &&
|
|
31
|
+
!instruction.$iterate
|
|
32
|
+
) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const sourceKey =
|
|
37
|
+
instruction.source ||
|
|
38
|
+
instruction.iterateOn ||
|
|
39
|
+
instruction.$iterate;
|
|
40
|
+
|
|
41
|
+
const collection = resolveCollection({
|
|
42
|
+
inNode: localNode,
|
|
43
|
+
inContext: localContext,
|
|
44
|
+
inData: localData
|
|
45
|
+
}) || [];
|
|
46
|
+
|
|
47
|
+
if (!Array.isArray(collection)) {
|
|
48
|
+
if (localNode && localNode.tagName) {
|
|
49
|
+
const cloned = { ...localNode };
|
|
50
|
+
delete cloned.jsonToSpec;
|
|
51
|
+
cloned.children = [];
|
|
52
|
+
return cloned;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const template =
|
|
59
|
+
instruction.template ||
|
|
60
|
+
instruction.item ||
|
|
61
|
+
{};
|
|
62
|
+
|
|
63
|
+
const filter = instruction.filter;
|
|
64
|
+
|
|
65
|
+
const filtered = collection.filter(item => {
|
|
66
|
+
if (!item || typeof item !== "object") {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (filter && typeof filter === "object") {
|
|
71
|
+
for (const [key, value] of Object.entries(filter)) {
|
|
72
|
+
if (item[key] !== value) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (item.isVisible === false) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return true;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const expandedChildren = [];
|
|
86
|
+
|
|
87
|
+
filtered.forEach((item, index) => {
|
|
88
|
+
const itemContext = {
|
|
89
|
+
...localContext,
|
|
90
|
+
item,
|
|
91
|
+
...(typeof item === "object" && item !== null ? item : {}),
|
|
92
|
+
$index: index,
|
|
93
|
+
$number: index + 1
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
if (
|
|
97
|
+
sourceKey === "rows" ||
|
|
98
|
+
sourceKey.endsWith(".rows") ||
|
|
99
|
+
sourceKey === "items" ||
|
|
100
|
+
sourceKey.endsWith("Rows")
|
|
101
|
+
) {
|
|
102
|
+
itemContext.row = item;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (
|
|
106
|
+
localContext.row &&
|
|
107
|
+
(item.field || item.columnName || item.name)
|
|
108
|
+
) {
|
|
109
|
+
const fieldKey =
|
|
110
|
+
item.field ||
|
|
111
|
+
item.columnName ||
|
|
112
|
+
item.name;
|
|
113
|
+
|
|
114
|
+
const cellValue = localContext.row[fieldKey];
|
|
115
|
+
|
|
116
|
+
if (cellValue !== undefined) {
|
|
117
|
+
itemContext.cellValue = cellValue;
|
|
118
|
+
itemContext.value = cellValue;
|
|
119
|
+
|
|
120
|
+
if (
|
|
121
|
+
typeof item === "object" &&
|
|
122
|
+
item !== null &&
|
|
123
|
+
item.value === undefined
|
|
124
|
+
) {
|
|
125
|
+
item.value = cellValue;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const rawTemplate =
|
|
131
|
+
typeof template === "object" &&
|
|
132
|
+
template !== null
|
|
133
|
+
? JSON.parse(JSON.stringify(template))
|
|
134
|
+
: {
|
|
135
|
+
tagName: "span",
|
|
136
|
+
textContent: template
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const iteratedTemplate = walk({
|
|
140
|
+
inNode: rawTemplate,
|
|
141
|
+
inContext: itemContext,
|
|
142
|
+
inData: localData,
|
|
143
|
+
inOperation: ({ inNode, inContext, inData }) => {
|
|
144
|
+
return expandIteration({
|
|
145
|
+
inNode,
|
|
146
|
+
inContext,
|
|
147
|
+
inData,
|
|
148
|
+
walk
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const replacedTemplate = replaceNode({
|
|
154
|
+
inNode: iteratedTemplate,
|
|
155
|
+
inContext: itemContext,
|
|
156
|
+
inData: localData
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
bindFormValues({
|
|
160
|
+
inNode: replacedTemplate,
|
|
161
|
+
inItem: item,
|
|
162
|
+
inData: localData
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
if (Array.isArray(replacedTemplate)) {
|
|
166
|
+
expandedChildren.push(...replacedTemplate);
|
|
167
|
+
} else if (
|
|
168
|
+
replacedTemplate !== null &&
|
|
169
|
+
replacedTemplate !== undefined
|
|
170
|
+
) {
|
|
171
|
+
expandedChildren.push(replacedTemplate);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
if (localNode && localNode.tagName) {
|
|
176
|
+
const cloned = { ...localNode };
|
|
177
|
+
|
|
178
|
+
delete cloned.jsonToSpec;
|
|
179
|
+
|
|
180
|
+
cloned.children = expandedChildren;
|
|
181
|
+
|
|
182
|
+
return cloned;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return expandedChildren;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
export default expandIteration;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import walk from "./walk/walk.js";
|
|
2
|
+
import expandIteration from "./expandIteration.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Iterates a structure by walking the tree
|
|
6
|
+
* and applying the iteration operation to each node.
|
|
7
|
+
*/
|
|
8
|
+
const iterate = ({
|
|
9
|
+
inStructure,
|
|
10
|
+
inData = {},
|
|
11
|
+
inContext = {}
|
|
12
|
+
} = {}) => {
|
|
13
|
+
return walk({
|
|
14
|
+
inNode: inStructure,
|
|
15
|
+
inData,
|
|
16
|
+
inContext,
|
|
17
|
+
inOperation: ({ inNode, inContext, inData }) => {
|
|
18
|
+
return expandIteration({
|
|
19
|
+
inNode,
|
|
20
|
+
inContext,
|
|
21
|
+
inData,
|
|
22
|
+
walk
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export {
|
|
29
|
+
iterate
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default iterate;
|