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
package/docs/dist/min.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
const p = {
|
|
2
|
+
version: "19.0.0",
|
|
3
|
+
name: "json-to-spec/v19",
|
|
4
|
+
description: "Minimalist 2-layer compiler: pure value replace + jsonToSpec iterate"
|
|
5
|
+
}, d = (r) => {
|
|
6
|
+
typeof globalThis > "u" || !r || (globalThis.ks ?? (globalThis.ks = {}), globalThis.ks["json-to-spec"] = {
|
|
7
|
+
meta: p,
|
|
8
|
+
compile: r
|
|
9
|
+
});
|
|
10
|
+
}, f = ({ inData: r, inDataKey: o }) => {
|
|
11
|
+
const t = o;
|
|
12
|
+
if (t === "") return r;
|
|
13
|
+
let n = r[t];
|
|
14
|
+
return t.includes(".") && (n = t.split(".").reduce(
|
|
15
|
+
(s, c) => s == null ? void 0 : s[c],
|
|
16
|
+
r
|
|
17
|
+
)), n;
|
|
18
|
+
}, y = ({
|
|
19
|
+
inNode: r,
|
|
20
|
+
inData: o
|
|
21
|
+
} = {}) => {
|
|
22
|
+
const t = r, n = o;
|
|
23
|
+
if (!(t != null && t.textContent)) return "no-textContent";
|
|
24
|
+
if (typeof t.textContent != "string") return "not-a-string";
|
|
25
|
+
if (!t.textContent.includes("${")) return "no-template-token";
|
|
26
|
+
const e = t.textContent.replace(/^\$\{/, "").replace(/\}$/, "");
|
|
27
|
+
t.textContent = f({
|
|
28
|
+
inData: n,
|
|
29
|
+
inDataKey: e
|
|
30
|
+
});
|
|
31
|
+
}, h = ({
|
|
32
|
+
inNode: r,
|
|
33
|
+
inData: o
|
|
34
|
+
} = {}) => {
|
|
35
|
+
const t = r, n = o;
|
|
36
|
+
if ("attributes" in t) {
|
|
37
|
+
const e = Object.fromEntries(
|
|
38
|
+
Object.entries(t.attributes || {}).map(([a, s]) => [
|
|
39
|
+
a,
|
|
40
|
+
typeof s == "string" && s.includes("${") ? f({
|
|
41
|
+
inData: n,
|
|
42
|
+
inDataKey: s.replace(/^\$\{/, "").replace(/\}$/, "")
|
|
43
|
+
}) : s
|
|
44
|
+
])
|
|
45
|
+
);
|
|
46
|
+
t.attributes = { ...e };
|
|
47
|
+
}
|
|
48
|
+
}, j = ({
|
|
49
|
+
inNode: r,
|
|
50
|
+
inData: o
|
|
51
|
+
} = {}) => {
|
|
52
|
+
const t = r, n = o;
|
|
53
|
+
y({ inNode: t, inData: n }), h({ inNode: t, inData: n });
|
|
54
|
+
}, A = ({
|
|
55
|
+
inTemplate: r,
|
|
56
|
+
inSourceValues: o
|
|
57
|
+
} = {}) => {
|
|
58
|
+
const t = o;
|
|
59
|
+
return t === void 0 ? void 0 : t.map((e) => {
|
|
60
|
+
const a = structuredClone(r);
|
|
61
|
+
return i({
|
|
62
|
+
inNode: a,
|
|
63
|
+
inData: e,
|
|
64
|
+
inOperation: "replace"
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}, D = ({
|
|
68
|
+
inNode: r,
|
|
69
|
+
inData: o,
|
|
70
|
+
inShowLog: t
|
|
71
|
+
} = {}) => {
|
|
72
|
+
const n = r, e = o;
|
|
73
|
+
if (!("jsonToSpec" in n) || !("operation" in n.jsonToSpec) || n.jsonToSpec.operation !== "iterate" || !("source" in n.jsonToSpec)) return;
|
|
74
|
+
const a = e[n.jsonToSpec.source], s = A({
|
|
75
|
+
inTemplate: n.jsonToSpec.template,
|
|
76
|
+
inSourceValues: a
|
|
77
|
+
});
|
|
78
|
+
n.children = s;
|
|
79
|
+
}, l = ({ inNode: r, inData: o, inOperation: t }) => {
|
|
80
|
+
const n = r, e = t;
|
|
81
|
+
if (Array.isArray(n)) {
|
|
82
|
+
const a = [];
|
|
83
|
+
for (const s of n) {
|
|
84
|
+
const c = i({
|
|
85
|
+
inNode: s,
|
|
86
|
+
inData: o,
|
|
87
|
+
inOperation: e
|
|
88
|
+
});
|
|
89
|
+
Array.isArray(c) ? a.push(...c) : c != null && a.push(c);
|
|
90
|
+
}
|
|
91
|
+
return a;
|
|
92
|
+
}
|
|
93
|
+
}, i = ({
|
|
94
|
+
inNode: r,
|
|
95
|
+
inData: o = {},
|
|
96
|
+
inOperation: t,
|
|
97
|
+
inShowLog: n = !1
|
|
98
|
+
} = {}) => {
|
|
99
|
+
const e = r, a = o, s = t;
|
|
100
|
+
if (n && console.log("walk ", r, o, t), e == null)
|
|
101
|
+
return e;
|
|
102
|
+
if (Array.isArray(e))
|
|
103
|
+
return l({
|
|
104
|
+
inNode: e,
|
|
105
|
+
inData: o,
|
|
106
|
+
inOperation: s
|
|
107
|
+
});
|
|
108
|
+
if ("children" in e && Array.isArray(e == null ? void 0 : e.children) && (e.children = l({
|
|
109
|
+
inNode: e == null ? void 0 : e.children,
|
|
110
|
+
inData: o,
|
|
111
|
+
inOperation: s
|
|
112
|
+
})), typeof e != "object")
|
|
113
|
+
return e;
|
|
114
|
+
switch (s) {
|
|
115
|
+
case "replace":
|
|
116
|
+
typeof e == "object" && j({
|
|
117
|
+
inNode: e,
|
|
118
|
+
inData: o
|
|
119
|
+
});
|
|
120
|
+
break;
|
|
121
|
+
case "iterateDo":
|
|
122
|
+
D({
|
|
123
|
+
inNode: e,
|
|
124
|
+
inData: a,
|
|
125
|
+
inShowLog: n
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return e;
|
|
129
|
+
}, u = ({ inStructureAsJson: r, inDataAsJson: o, inOperation: t, inShowLog: n }) => {
|
|
130
|
+
try {
|
|
131
|
+
return i({
|
|
132
|
+
inNode: r,
|
|
133
|
+
inData: o,
|
|
134
|
+
inOperation: t,
|
|
135
|
+
inShowLog: n
|
|
136
|
+
});
|
|
137
|
+
} catch (e) {
|
|
138
|
+
throw console.error("[json-to-spec/v17] replace error:", e), e;
|
|
139
|
+
}
|
|
140
|
+
}, m = (r, o = {}, t = !1) => {
|
|
141
|
+
let n = r, e = o;
|
|
142
|
+
t && console.log(p.name, n, e);
|
|
143
|
+
try {
|
|
144
|
+
const a = u({
|
|
145
|
+
inStructureAsJson: n,
|
|
146
|
+
inDataAsJson: e,
|
|
147
|
+
inOperation: "iterateDo",
|
|
148
|
+
inShowLog: t
|
|
149
|
+
}), s = u({
|
|
150
|
+
inStructureAsJson: a,
|
|
151
|
+
inDataAsJson: e,
|
|
152
|
+
inOperation: "replace",
|
|
153
|
+
inShowLog: t
|
|
154
|
+
});
|
|
155
|
+
return t && console.log("iteratedData : ", a, s), s;
|
|
156
|
+
} catch (a) {
|
|
157
|
+
throw console.error("[json-to-spec/v19] compile error:", a), a;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
d(m);
|
|
161
|
+
export {
|
|
162
|
+
m as compile,
|
|
163
|
+
m as default
|
|
164
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
const h = ({ inData: c, inPath: f }) => {
|
|
2
|
+
const s = c, t = f;
|
|
3
|
+
if (s == null) return;
|
|
4
|
+
if (t == null || t === "" || t === ".")
|
|
5
|
+
return s;
|
|
6
|
+
const i = Array.isArray(t) ? t : String(t).split(".");
|
|
7
|
+
let n = s;
|
|
8
|
+
for (const b of i) {
|
|
9
|
+
if (n == null)
|
|
10
|
+
return;
|
|
11
|
+
n = n[b];
|
|
12
|
+
}
|
|
13
|
+
return n;
|
|
14
|
+
}, D = ({ inText: c, inItemContext: f, inRootData: s }) => {
|
|
15
|
+
const t = c, i = f, n = s;
|
|
16
|
+
return typeof t != "string" || !t.includes("${") ? t : t.replace(/\$\{([^}]+)\}/g, (b, o) => {
|
|
17
|
+
const l = o.trim();
|
|
18
|
+
let e = h({ inData: i, inPath: l });
|
|
19
|
+
return e === void 0 && n && (e = h({ inData: n, inPath: l })), e != null ? String(e) : "";
|
|
20
|
+
});
|
|
21
|
+
}, y = ({ inNode: c, inContext: f = {}, inRootData: s = {} } = {}) => {
|
|
22
|
+
const t = c, i = f || {}, n = s || {};
|
|
23
|
+
if (t == null) return null;
|
|
24
|
+
if (Array.isArray(t)) {
|
|
25
|
+
const e = [];
|
|
26
|
+
for (const u of t) {
|
|
27
|
+
const r = y({
|
|
28
|
+
inNode: u,
|
|
29
|
+
inContext: i,
|
|
30
|
+
inRootData: n
|
|
31
|
+
});
|
|
32
|
+
Array.isArray(r) ? e.push(...r) : r != null && e.push(r);
|
|
33
|
+
}
|
|
34
|
+
return e;
|
|
35
|
+
}
|
|
36
|
+
if (typeof t != "object")
|
|
37
|
+
return D({
|
|
38
|
+
inText: t,
|
|
39
|
+
inItemContext: i.item,
|
|
40
|
+
inRootData: n
|
|
41
|
+
});
|
|
42
|
+
if (t.operation === "iterate" || !!t.$iterate) {
|
|
43
|
+
const e = t.source || t.iterateOn || t.$iterate, u = n && n[e] || h({ inData: n, inPath: e }) || i && i[e] || h({ inData: i, inPath: e });
|
|
44
|
+
if (!Array.isArray(u)) return [];
|
|
45
|
+
const r = t.template || t.item || {}, x = t.filter, A = u.filter((a) => {
|
|
46
|
+
if (!a || typeof a != "object") return !0;
|
|
47
|
+
if (x && typeof x == "object") {
|
|
48
|
+
for (const [m, d] of Object.entries(x))
|
|
49
|
+
if (a[m] !== d) return !1;
|
|
50
|
+
}
|
|
51
|
+
return a.isVisible !== !1;
|
|
52
|
+
}), C = [];
|
|
53
|
+
return A.forEach((a, m) => {
|
|
54
|
+
const d = {
|
|
55
|
+
...i,
|
|
56
|
+
item: a,
|
|
57
|
+
...typeof a == "object" && a !== null ? a : {},
|
|
58
|
+
$index: m,
|
|
59
|
+
$number: m + 1
|
|
60
|
+
};
|
|
61
|
+
if ((e === "rows" || e.endsWith(".rows") || e === "items") && (d.row = a), i.row && (a.field || a.columnName || a.name)) {
|
|
62
|
+
const N = a.field || a.columnName || a.name, v = i.row[N];
|
|
63
|
+
v !== void 0 && (d.cellValue = v, d.value = v);
|
|
64
|
+
}
|
|
65
|
+
const p = y({
|
|
66
|
+
inNode: r,
|
|
67
|
+
inContext: d,
|
|
68
|
+
inRootData: n
|
|
69
|
+
});
|
|
70
|
+
Array.isArray(p) ? C.push(...p) : p != null && C.push(p);
|
|
71
|
+
}), C;
|
|
72
|
+
}
|
|
73
|
+
const o = { ...t }, l = i.item || i;
|
|
74
|
+
if (l.type === "textarea" && o.tagName === "input" && (o.tagName = "textarea", o.attributes && (o.attributes = { ...o.attributes }, delete o.attributes.type)), o.textContent && (o.textContent = D({
|
|
75
|
+
inText: o.textContent,
|
|
76
|
+
inItemContext: l,
|
|
77
|
+
inRootData: n
|
|
78
|
+
})), o.attributes) {
|
|
79
|
+
o.attributes = { ...o.attributes };
|
|
80
|
+
for (const [u, r] of Object.entries(o.attributes))
|
|
81
|
+
typeof r == "string" && (o.attributes[u] = D({
|
|
82
|
+
inText: r,
|
|
83
|
+
inItemContext: l,
|
|
84
|
+
inRootData: n
|
|
85
|
+
}));
|
|
86
|
+
const e = l.field || l.columnName || l.name;
|
|
87
|
+
l.value !== void 0 && l.value !== null ? o.attributes.value = String(l.value) : e && n[e] !== void 0 && n[e] !== null ? o.attributes.value = String(n[e]) : e && n.values && n.values[e] !== void 0 && n.values[e] !== null && (o.attributes.value = String(n.values[e]));
|
|
88
|
+
}
|
|
89
|
+
if (Array.isArray(o.children)) {
|
|
90
|
+
const e = [];
|
|
91
|
+
for (const u of o.children) {
|
|
92
|
+
const r = y({
|
|
93
|
+
inNode: u,
|
|
94
|
+
inContext: i,
|
|
95
|
+
inRootData: n
|
|
96
|
+
});
|
|
97
|
+
Array.isArray(r) ? e.push(...r) : r != null && e.push(r);
|
|
98
|
+
}
|
|
99
|
+
o.children = e;
|
|
100
|
+
}
|
|
101
|
+
return o;
|
|
102
|
+
}, g = {
|
|
103
|
+
version: "1.0.0",
|
|
104
|
+
name: "json-to-spec/v1",
|
|
105
|
+
description: "Compiles structure.json with data.json into valid JSON specs ready for json-to-dom"
|
|
106
|
+
}, j = ({
|
|
107
|
+
inStructure: c,
|
|
108
|
+
inTree: f,
|
|
109
|
+
inData: s = {}
|
|
110
|
+
} = {}) => {
|
|
111
|
+
const t = c || f, i = s || {};
|
|
112
|
+
return y({
|
|
113
|
+
inNode: t,
|
|
114
|
+
inContext: i,
|
|
115
|
+
inRootData: i
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
export {
|
|
119
|
+
j as compile,
|
|
120
|
+
y as compileNode,
|
|
121
|
+
j as default,
|
|
122
|
+
g as meta,
|
|
123
|
+
h as resolvePath
|
|
124
|
+
};
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
const m = ({ inData: i, inPath: s }) => {
|
|
2
|
+
const n = i, t = s;
|
|
3
|
+
if (n == null) return;
|
|
4
|
+
if (t == null || t === "" || t === ".")
|
|
5
|
+
return n;
|
|
6
|
+
const e = Array.isArray(t) ? t : String(t).split(".");
|
|
7
|
+
let r = n;
|
|
8
|
+
for (const o of e) {
|
|
9
|
+
if (r == null) return;
|
|
10
|
+
r = r[o];
|
|
11
|
+
}
|
|
12
|
+
return r;
|
|
13
|
+
}, v = ({ inData: i, inDataKey: s }) => {
|
|
14
|
+
const n = s;
|
|
15
|
+
let t = i[n];
|
|
16
|
+
return n.includes(".") && (t = n.split(".").reduce(
|
|
17
|
+
(o, a) => o == null ? void 0 : o[a],
|
|
18
|
+
i
|
|
19
|
+
)), t;
|
|
20
|
+
}, E = ({
|
|
21
|
+
inNode: i,
|
|
22
|
+
inData: s
|
|
23
|
+
} = {}) => {
|
|
24
|
+
if ("textContent" in i && i.textContent.includes("${")) {
|
|
25
|
+
const n = i.textContent.replace(/^\$\{/, "").replace(/\}$/, "");
|
|
26
|
+
i.textContent = v({ inData: s, inDataKey: n });
|
|
27
|
+
}
|
|
28
|
+
if ("attributes" in i) {
|
|
29
|
+
const n = Object.fromEntries(
|
|
30
|
+
Object.entries(i.attributes || {}).map(([t, e]) => [
|
|
31
|
+
t,
|
|
32
|
+
typeof e == "string" && e.includes("${") ? v({
|
|
33
|
+
inData: s,
|
|
34
|
+
inDataKey: e.replace(/^\$\{/, "").replace(/\}$/, "")
|
|
35
|
+
}) : e
|
|
36
|
+
])
|
|
37
|
+
);
|
|
38
|
+
i.attributes = { ...n };
|
|
39
|
+
}
|
|
40
|
+
}, M = ({
|
|
41
|
+
inNode: i,
|
|
42
|
+
inData: s
|
|
43
|
+
} = {}) => {
|
|
44
|
+
var t, e, r;
|
|
45
|
+
const n = i;
|
|
46
|
+
if ("jsonToSpec" in n && "operation" in (n == null ? void 0 : n.jsonToSpec) && ((t = n == null ? void 0 : n.jsonToSpec) == null ? void 0 : t.operation) === "iterate" && "source" in (n == null ? void 0 : n.jsonToSpec) && ((e = n == null ? void 0 : n.jsonToSpec) == null ? void 0 : e.source) === "columns") {
|
|
47
|
+
const a = s[(r = n == null ? void 0 : n.jsonToSpec) == null ? void 0 : r.source].map((l) => {
|
|
48
|
+
var p;
|
|
49
|
+
const u = structuredClone((p = n == null ? void 0 : n.jsonToSpec) == null ? void 0 : p.template);
|
|
50
|
+
return C({
|
|
51
|
+
inNode: u,
|
|
52
|
+
inData: l,
|
|
53
|
+
inOperation: "replace"
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
n.children = a;
|
|
57
|
+
}
|
|
58
|
+
}, $ = ({ inNode: i, inData: s, inOperation: n }) => {
|
|
59
|
+
const t = i, e = n;
|
|
60
|
+
if (Array.isArray(t)) {
|
|
61
|
+
const r = [];
|
|
62
|
+
for (const o of t) {
|
|
63
|
+
const a = C({
|
|
64
|
+
inNode: o,
|
|
65
|
+
inData: s,
|
|
66
|
+
inOperation: e
|
|
67
|
+
});
|
|
68
|
+
Array.isArray(a) ? r.push(...a) : a != null && r.push(a);
|
|
69
|
+
}
|
|
70
|
+
return r;
|
|
71
|
+
}
|
|
72
|
+
}, C = ({
|
|
73
|
+
inNode: i,
|
|
74
|
+
inData: s = {},
|
|
75
|
+
inOperation: n
|
|
76
|
+
} = {}) => {
|
|
77
|
+
const t = i, e = n;
|
|
78
|
+
if (t == null)
|
|
79
|
+
return t;
|
|
80
|
+
if (Array.isArray(t))
|
|
81
|
+
return $({
|
|
82
|
+
inNode: t,
|
|
83
|
+
inData: s,
|
|
84
|
+
inOperation: e
|
|
85
|
+
});
|
|
86
|
+
if ("children" in t && Array.isArray(t == null ? void 0 : t.children) && (t.children = $({
|
|
87
|
+
inNode: t == null ? void 0 : t.children,
|
|
88
|
+
inData: s,
|
|
89
|
+
inOperation: e
|
|
90
|
+
})), typeof t != "object")
|
|
91
|
+
return t;
|
|
92
|
+
switch (e) {
|
|
93
|
+
case "replace":
|
|
94
|
+
typeof t == "object" && E({
|
|
95
|
+
inNode: t,
|
|
96
|
+
inData: s
|
|
97
|
+
});
|
|
98
|
+
break;
|
|
99
|
+
case "iterateDo":
|
|
100
|
+
M({
|
|
101
|
+
inNode: t,
|
|
102
|
+
inData: s
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return t;
|
|
106
|
+
}, w = ({ inPath: i, inContext: s, inData: n }) => {
|
|
107
|
+
const t = i, e = s, r = n;
|
|
108
|
+
let o = m({ inData: e, inPath: t });
|
|
109
|
+
return o === void 0 && e && typeof e == "object" && (e.item && typeof e.item == "object" && (o = m({ inData: e.item, inPath: t })), o === void 0 && e.row && typeof e.row == "object" && (o = m({ inData: e.row, inPath: t }))), o === void 0 && r && (o = m({ inData: r, inPath: t })), o;
|
|
110
|
+
}, g = ({ inValue: i, inContext: s, inData: n }) => {
|
|
111
|
+
const t = i, e = s, r = n;
|
|
112
|
+
if (typeof t != "string" || !t.includes("${"))
|
|
113
|
+
return t;
|
|
114
|
+
const o = !!(e && (e.item || Object.keys(e).length > 0)), a = t.match(/^\$\{([^}]+)\}$/);
|
|
115
|
+
if (a) {
|
|
116
|
+
const l = w({
|
|
117
|
+
inPath: a[1].trim(),
|
|
118
|
+
inContext: e,
|
|
119
|
+
inData: r
|
|
120
|
+
});
|
|
121
|
+
return l ?? (o ? "" : t);
|
|
122
|
+
}
|
|
123
|
+
return t.replace(/\$\{([^}]+)\}/g, (l, u) => {
|
|
124
|
+
const f = w({
|
|
125
|
+
inPath: u.trim(),
|
|
126
|
+
inContext: e,
|
|
127
|
+
inData: r
|
|
128
|
+
});
|
|
129
|
+
return f != null ? String(f) : o ? "" : l;
|
|
130
|
+
});
|
|
131
|
+
}, T = ({ inNode: i, inContext: s = {}, inData: n = {} } = {}) => {
|
|
132
|
+
const t = i, e = s, r = n;
|
|
133
|
+
if (t == null) return t;
|
|
134
|
+
if (Array.isArray(t))
|
|
135
|
+
return t.map((a) => T({
|
|
136
|
+
inNode: a,
|
|
137
|
+
inContext: e,
|
|
138
|
+
inData: r
|
|
139
|
+
}));
|
|
140
|
+
if (typeof t == "string")
|
|
141
|
+
return g({
|
|
142
|
+
inValue: t,
|
|
143
|
+
inContext: e,
|
|
144
|
+
inData: r
|
|
145
|
+
});
|
|
146
|
+
if (typeof t != "object")
|
|
147
|
+
return t;
|
|
148
|
+
const o = { ...t };
|
|
149
|
+
if (o.textContent && typeof o.textContent == "string" && (o.textContent = g({
|
|
150
|
+
inValue: o.textContent,
|
|
151
|
+
inContext: e,
|
|
152
|
+
inData: r
|
|
153
|
+
})), o.attributes) {
|
|
154
|
+
o.attributes = { ...o.attributes };
|
|
155
|
+
for (const [a, l] of Object.entries(o.attributes))
|
|
156
|
+
typeof l == "string" && (o.attributes[a] = g({
|
|
157
|
+
inValue: l,
|
|
158
|
+
inContext: e,
|
|
159
|
+
inData: r
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
if (o.properties) {
|
|
163
|
+
o.properties = { ...o.properties };
|
|
164
|
+
for (const [a, l] of Object.entries(o.properties))
|
|
165
|
+
typeof l == "string" && (o.properties[a] = g({
|
|
166
|
+
inValue: l,
|
|
167
|
+
inContext: e,
|
|
168
|
+
inData: r
|
|
169
|
+
}));
|
|
170
|
+
}
|
|
171
|
+
return Array.isArray(o.children) && (o.children = o.children.map((a) => T({
|
|
172
|
+
inNode: a,
|
|
173
|
+
inContext: e,
|
|
174
|
+
inData: r
|
|
175
|
+
}))), o;
|
|
176
|
+
}, x = ({ inStructureAsJson: i, inDataAsJson: s, inOperation: n }) => C({
|
|
177
|
+
inNode: i,
|
|
178
|
+
inData: s,
|
|
179
|
+
inOperation: n
|
|
180
|
+
}), R = ({ inNode: i, inContext: s, inData: n }) => {
|
|
181
|
+
const t = i, e = s, r = n, o = t && (t.jsonToSpec || (t.operation ? t : null));
|
|
182
|
+
if (!o) return;
|
|
183
|
+
const a = o.source || o.iterateOn || o.$iterate;
|
|
184
|
+
if (a)
|
|
185
|
+
return m({
|
|
186
|
+
inData: r,
|
|
187
|
+
inPath: a
|
|
188
|
+
}) || r && r[a] || m({
|
|
189
|
+
inData: e,
|
|
190
|
+
inPath: a
|
|
191
|
+
}) || e && e[a];
|
|
192
|
+
}, N = ({ inNode: i, inItem: s, inData: n }) => {
|
|
193
|
+
var o;
|
|
194
|
+
const t = i, e = s, r = n;
|
|
195
|
+
if (!t || typeof t != "object")
|
|
196
|
+
return t;
|
|
197
|
+
if (t.attributes && [
|
|
198
|
+
"input",
|
|
199
|
+
"textarea",
|
|
200
|
+
"select",
|
|
201
|
+
"option"
|
|
202
|
+
].includes((o = t.tagName) == null ? void 0 : o.toLowerCase())) {
|
|
203
|
+
const l = e.field || e.columnName || e.name;
|
|
204
|
+
e.value !== void 0 && e.value !== null ? (t.attributes.value = String(e.value), t.tagName === "textarea" && !t.textContent && (t.textContent = String(e.value))) : l && r[l] !== void 0 && r[l] !== null && (t.attributes.value = String(
|
|
205
|
+
r[l]
|
|
206
|
+
), t.tagName === "textarea" && !t.textContent && (t.textContent = String(
|
|
207
|
+
r[l]
|
|
208
|
+
)));
|
|
209
|
+
}
|
|
210
|
+
return Array.isArray(t.children) && t.children.forEach((a) => {
|
|
211
|
+
N({
|
|
212
|
+
inNode: a,
|
|
213
|
+
inItem: e,
|
|
214
|
+
inData: r
|
|
215
|
+
});
|
|
216
|
+
}), t;
|
|
217
|
+
}, k = ({
|
|
218
|
+
inNode: i,
|
|
219
|
+
inContext: s,
|
|
220
|
+
inData: n,
|
|
221
|
+
walk: t
|
|
222
|
+
}) => {
|
|
223
|
+
const e = i, r = s, o = n, a = e && (e.jsonToSpec || (e.operation ? e : null));
|
|
224
|
+
if (!a || a.operation !== "iterate" && !a.source && !a.$iterate)
|
|
225
|
+
return;
|
|
226
|
+
const u = a.source || a.iterateOn || a.$iterate, f = R({
|
|
227
|
+
inNode: e,
|
|
228
|
+
inContext: r,
|
|
229
|
+
inData: o
|
|
230
|
+
}) || [];
|
|
231
|
+
if (!Array.isArray(f)) {
|
|
232
|
+
if (e && e.tagName) {
|
|
233
|
+
const c = { ...e };
|
|
234
|
+
return delete c.jsonToSpec, c.children = [], c;
|
|
235
|
+
}
|
|
236
|
+
return [];
|
|
237
|
+
}
|
|
238
|
+
const p = a.template || a.item || {}, A = a.filter, F = f.filter((c) => {
|
|
239
|
+
if (!c || typeof c != "object")
|
|
240
|
+
return !0;
|
|
241
|
+
if (A && typeof A == "object") {
|
|
242
|
+
for (const [D, d] of Object.entries(A))
|
|
243
|
+
if (c[D] !== d)
|
|
244
|
+
return !1;
|
|
245
|
+
}
|
|
246
|
+
return c.isVisible !== !1;
|
|
247
|
+
}), j = [];
|
|
248
|
+
if (F.forEach((c, D) => {
|
|
249
|
+
const d = {
|
|
250
|
+
...r,
|
|
251
|
+
item: c,
|
|
252
|
+
...typeof c == "object" && c !== null ? c : {},
|
|
253
|
+
$index: D,
|
|
254
|
+
$number: D + 1
|
|
255
|
+
};
|
|
256
|
+
if ((u === "rows" || u.endsWith(".rows") || u === "items" || u.endsWith("Rows")) && (d.row = c), r.row && (c.field || c.columnName || c.name)) {
|
|
257
|
+
const S = c.field || c.columnName || c.name, h = r.row[S];
|
|
258
|
+
h !== void 0 && (d.cellValue = h, d.value = h, typeof c == "object" && c !== null && c.value === void 0 && (c.value = h));
|
|
259
|
+
}
|
|
260
|
+
const K = typeof p == "object" && p !== null ? JSON.parse(JSON.stringify(p)) : {
|
|
261
|
+
tagName: "span",
|
|
262
|
+
textContent: p
|
|
263
|
+
}, J = t({
|
|
264
|
+
inNode: K,
|
|
265
|
+
inContext: d,
|
|
266
|
+
inData: o,
|
|
267
|
+
inOperation: ({ inNode: S, inContext: h, inData: I }) => k({
|
|
268
|
+
inNode: S,
|
|
269
|
+
inContext: h,
|
|
270
|
+
inData: I,
|
|
271
|
+
walk: t
|
|
272
|
+
})
|
|
273
|
+
}), y = T({
|
|
274
|
+
inNode: J,
|
|
275
|
+
inContext: d,
|
|
276
|
+
inData: o
|
|
277
|
+
});
|
|
278
|
+
N({
|
|
279
|
+
inNode: y,
|
|
280
|
+
inItem: c,
|
|
281
|
+
inData: o
|
|
282
|
+
}), Array.isArray(y) ? j.push(...y) : y != null && j.push(y);
|
|
283
|
+
}), e && e.tagName) {
|
|
284
|
+
const c = { ...e };
|
|
285
|
+
return delete c.jsonToSpec, c.children = j, c;
|
|
286
|
+
}
|
|
287
|
+
return j;
|
|
288
|
+
}, b = ({
|
|
289
|
+
inStructure: i,
|
|
290
|
+
inData: s = {},
|
|
291
|
+
inContext: n = {}
|
|
292
|
+
} = {}) => C({
|
|
293
|
+
inNode: i,
|
|
294
|
+
inData: s,
|
|
295
|
+
inOperation: ({ inNode: t, inContext: e, inData: r }) => k({
|
|
296
|
+
inNode: t,
|
|
297
|
+
inContext: e,
|
|
298
|
+
inData: r,
|
|
299
|
+
walk: C
|
|
300
|
+
})
|
|
301
|
+
}), P = b, W = {
|
|
302
|
+
version: "17.0.0",
|
|
303
|
+
name: "json-to-spec/v17",
|
|
304
|
+
description: "Minimalist 2-layer compiler: pure value replace + jsonToSpec iterate"
|
|
305
|
+
}, O = ({ inStructure: i, inData: s = {}, inSteps: n = [x, b] } = {}) => {
|
|
306
|
+
const t = s, e = n;
|
|
307
|
+
let r = i;
|
|
308
|
+
for (const o of e)
|
|
309
|
+
typeof o == "function" && (r = o({ inStructure: r, inData: t }));
|
|
310
|
+
return r;
|
|
311
|
+
}, B = (...i) => {
|
|
312
|
+
const s = i.length > 0 ? i : [x, b];
|
|
313
|
+
return (n, t = {}) => O({ inStructure: n, inData: t, inSteps: s });
|
|
314
|
+
}, V = (i, s = {}) => {
|
|
315
|
+
let n = i, t = s;
|
|
316
|
+
console.log("ccccccccccccc-------- : ", t);
|
|
317
|
+
const e = x({
|
|
318
|
+
inStructureAsJson: n,
|
|
319
|
+
inDataAsJson: t,
|
|
320
|
+
inOperation: "iterateDo"
|
|
321
|
+
}), r = x({
|
|
322
|
+
inStructureAsJson: e,
|
|
323
|
+
inDataAsJson: t,
|
|
324
|
+
inOperation: "replace"
|
|
325
|
+
});
|
|
326
|
+
return console.log("replaced : ", r), r;
|
|
327
|
+
}, L = {
|
|
328
|
+
replace: x,
|
|
329
|
+
iterate: b,
|
|
330
|
+
operation: P,
|
|
331
|
+
pipeline: O,
|
|
332
|
+
pipe: B,
|
|
333
|
+
compile: V
|
|
334
|
+
};
|
|
335
|
+
typeof globalThis < "u" && (globalThis.ks ?? (globalThis.ks = {}), globalThis.ks["json-to-spec"] = {
|
|
336
|
+
meta: W,
|
|
337
|
+
compile: V,
|
|
338
|
+
replace: x,
|
|
339
|
+
iterate: b,
|
|
340
|
+
operation: P,
|
|
341
|
+
pipeline: O,
|
|
342
|
+
jsonToSpec: L
|
|
343
|
+
});
|
|
344
|
+
export {
|
|
345
|
+
V as compile,
|
|
346
|
+
V as default,
|
|
347
|
+
b as iterate,
|
|
348
|
+
L as jsonToSpec,
|
|
349
|
+
W as meta,
|
|
350
|
+
P as operation,
|
|
351
|
+
B as pipe,
|
|
352
|
+
O as pipeline,
|
|
353
|
+
x as replace,
|
|
354
|
+
T as replaceNode
|
|
355
|
+
};
|