json-to-spec 20.1.1 → 23.1.1
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/docs/dist/min.js +137 -309
- package/docs/dist/v17/min.js +355 -355
- package/docs/dist/v18/min.js +160 -160
- package/docs/dist/v19/min.js +164 -164
- package/docs/dist/v20/min.js +326 -326
- package/docs/dist/v21/min.js +116 -0
- package/docs/dist/v23/min.js +154 -0
- package/package.json +6 -6
- package/samples/form/input/data.json +8 -8
- package/samples/form/input/structure.json +191 -191
- package/samples/form1/input/data.json +37 -37
- package/samples/table/input/structure.json +13 -13
- package/samples/table1/input/structure.json +10 -10
- package/samples/table2/input/structure.json +18 -18
- package/samples/table3/input/structure.json +44 -44
- package/src/index.js +2 -2
- package/src/v21/buildSpec/buildChildrenNodes.js +24 -0
- package/src/v21/buildSpec/buildSingleElement.js +18 -0
- package/src/v21/buildSpec/buildSpecArray.js +16 -0
- package/src/v21/buildSpec/forArray/v1/index.js +22 -0
- package/src/v21/buildSpec/forObject/v1/index.js +22 -0
- package/src/v21/buildSpec/forSpec/v3/index.js +91 -0
- package/src/v21/buildSpec/forSpec.js +76 -0
- package/src/v21/buildSpec/guards.js +26 -0
- package/src/v21/buildSpec/index.js +53 -0
- package/src/v21/index.js +21 -0
- package/src/v21/meta.js +6 -0
- package/src/v21/registerGlobal.js +17 -0
- package/src/v22/buildSpec/buildChildrenNodes.js +24 -0
- package/src/v22/buildSpec/buildSingleElement.js +18 -0
- package/src/v22/buildSpec/buildSpecArray.js +16 -0
- package/src/v22/buildSpec/forArray/v1/index.js +27 -0
- package/src/v22/buildSpec/forObject/v1/index.js +47 -0
- package/src/v22/buildSpec/forSpec/v3/index.js +84 -0
- package/src/v22/buildSpec/forSpec.js +76 -0
- package/src/v22/buildSpec/guards.js +26 -0
- package/src/v22/buildSpec/index.js +97 -0
- package/src/v22/index.js +21 -0
- package/src/v22/meta.js +6 -0
- package/src/v22/registerGlobal.js +17 -0
- package/src/v23/buildSpec/buildSpecArray.js +16 -0
- package/src/v23/buildSpec/forArray/v1/index.js +27 -0
- package/src/v23/buildSpec/forArrayStrings/v1/index.js +24 -0
- package/src/v23/buildSpec/forObject/v1/index.js +47 -0
- package/src/v23/buildSpec/forSpec/v3/index.js +114 -0
- package/src/v23/buildSpec/guards.js +20 -0
- package/src/v23/buildSpec/index.js +122 -0
- package/src/v23/index.js +21 -0
- package/src/v23/meta.js +6 -0
- package/src/v23/registerGlobal.js +17 -0
package/docs/dist/min.js
CHANGED
|
@@ -1,326 +1,154 @@
|
|
|
1
1
|
const f = {
|
|
2
|
-
version: "
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
typeof globalThis > "u" || !n || (globalThis.ks ?? (globalThis.ks = {}), globalThis.ks["json-to-spec"] = {
|
|
2
|
+
version: "v23.0",
|
|
3
|
+
description: "Pure spec engine no document at all"
|
|
4
|
+
}, d = (e) => {
|
|
5
|
+
typeof globalThis > "u" || !e || (globalThis.ks ?? (globalThis.ks = {}), globalThis.ks["json-to-spec"] = {
|
|
7
6
|
meta: f,
|
|
8
|
-
|
|
7
|
+
buildSpecElement: e
|
|
9
8
|
});
|
|
10
|
-
},
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
t.textContent = d({
|
|
28
|
-
inData: e,
|
|
29
|
-
inDataKey: o
|
|
30
|
-
});
|
|
31
|
-
}, C = ({
|
|
32
|
-
inNode: n,
|
|
33
|
-
inData: r
|
|
34
|
-
} = {}) => {
|
|
35
|
-
const t = n, e = r;
|
|
36
|
-
if ("attributes" in t) {
|
|
37
|
-
const o = Object.fromEntries(
|
|
38
|
-
Object.entries(t.attributes || {}).map(([s, c]) => [
|
|
39
|
-
s,
|
|
40
|
-
typeof c == "string" && c.includes("${") ? d({
|
|
41
|
-
inData: e,
|
|
42
|
-
inDataKey: c.replace(/^\$\{/, "").replace(/\}$/, "")
|
|
43
|
-
}) : c
|
|
44
|
-
])
|
|
45
|
-
);
|
|
46
|
-
t.attributes = { ...o };
|
|
9
|
+
}, y = ({ inSpec: e }) => {
|
|
10
|
+
const n = e;
|
|
11
|
+
return n == null;
|
|
12
|
+
}, m = ({ inSpec: e }) => typeof Node < "u" && e instanceof Node, b = ({ inSpecJson: e }) => Array.isArray(e), A = ({ inArray: e = [], inShowLog: n = !1, inDataJson: o }) => {
|
|
13
|
+
const t = e, c = n, r = o;
|
|
14
|
+
return Array.isArray(t) ? t.map((s) => i({
|
|
15
|
+
inSpecJson: s,
|
|
16
|
+
inShowLog: c,
|
|
17
|
+
inDataJson: r
|
|
18
|
+
})).flat().filter(Boolean) : [];
|
|
19
|
+
}, a = (e, n) => typeof e != "string" ? e : e.replace(/\$\{([^}]+)\}/g, (o, t) => {
|
|
20
|
+
const c = t.trim().split(".");
|
|
21
|
+
let r = n;
|
|
22
|
+
for (const s of c) {
|
|
23
|
+
if (r == null)
|
|
24
|
+
return "";
|
|
25
|
+
r = r[s];
|
|
47
26
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
} = {}) =>
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
27
|
+
return r === null || typeof r == "string" || typeof r == "number" || typeof r == "boolean" ? String(r ?? "") : r;
|
|
28
|
+
}), u = ({ inSpecJson: e, inData: n, inShowLog: o }) => {
|
|
29
|
+
const t = structuredClone(e);
|
|
30
|
+
return typeof n == "string" ? ("textContent" in t && (t.textContent === "${}" ? t.textContent = n : typeof t.textContent == "string" && (t.textContent = t.textContent.replaceAll("${}", () => n))), "attributes" in t && (t.attributes = Object.fromEntries(
|
|
31
|
+
Object.entries(t.attributes).map(
|
|
32
|
+
([c, r]) => [
|
|
33
|
+
c,
|
|
34
|
+
r === "${}" ? n : typeof r == "string" ? r.replaceAll("${}", () => n) : r
|
|
35
|
+
]
|
|
36
|
+
)
|
|
37
|
+
))) : "key" in n && "value" in n ? "textContent" in t && (t.textContent = a(
|
|
38
|
+
t.textContent,
|
|
39
|
+
n
|
|
40
|
+
)) : ("textContent" in t && (t.textContent = a(
|
|
41
|
+
t.textContent,
|
|
42
|
+
n
|
|
43
|
+
)), "attributes" in t && (t.attributes = Object.fromEntries(
|
|
44
|
+
Object.entries(t.attributes).map(
|
|
45
|
+
([c, r]) => [
|
|
46
|
+
c,
|
|
47
|
+
a(r, n)
|
|
48
|
+
]
|
|
49
|
+
)
|
|
50
|
+
)), "children" in t && (t.children = t.children.map((c) => i({
|
|
51
|
+
inSpecJson: c,
|
|
52
|
+
inShowLog: o,
|
|
53
|
+
inDataJson: n
|
|
54
|
+
})))), t;
|
|
55
|
+
}, j = ({ inTemplate: e, inDataAsArray: n }) => {
|
|
56
|
+
const o = n, t = e;
|
|
57
|
+
return Array.isArray(o) ? o.map((r) => {
|
|
58
|
+
const s = structuredClone(t);
|
|
59
|
+
return i({
|
|
60
|
+
inSpecJson: s,
|
|
61
|
+
inDataJson: r
|
|
65
62
|
});
|
|
66
|
-
});
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
inData: r
|
|
82
|
-
} = {}) => {
|
|
83
|
-
const t = n;
|
|
84
|
-
if (!(t != null && t.textContent)) return "no-textContent";
|
|
85
|
-
if (typeof t.textContent != "string") return "not-a-string";
|
|
86
|
-
if (!t.textContent.includes("${")) return "no-template-token";
|
|
87
|
-
t.textContent === "${key}" && (t.textContent = r.key), t.textContent === "${value}" && (t.textContent = r.value);
|
|
88
|
-
}, A = ({
|
|
89
|
-
inNode: n,
|
|
90
|
-
inData: r
|
|
91
|
-
} = {}) => {
|
|
92
|
-
const t = n;
|
|
93
|
-
if ("attributes" in t) {
|
|
94
|
-
const e = Object.fromEntries(
|
|
95
|
-
Object.entries(t.attributes).map(([o, s]) => {
|
|
96
|
-
let c = s;
|
|
97
|
-
return s === "${key}" ? c = r.key : s === "${value}" && (c = r.value), [o, c];
|
|
98
|
-
})
|
|
99
|
-
);
|
|
100
|
-
t.attributes = { ...e };
|
|
101
|
-
}
|
|
102
|
-
}, j = ({
|
|
103
|
-
inNode: n,
|
|
104
|
-
inData: r
|
|
105
|
-
} = {}) => {
|
|
106
|
-
const t = n, e = r;
|
|
107
|
-
x({ inNode: t, inData: e }), A({ inNode: t, inData: e });
|
|
108
|
-
};
|
|
109
|
-
function m(n) {
|
|
110
|
-
return n !== null && typeof n == "object" && Object.getPrototypeOf(n) === Object.prototype;
|
|
111
|
-
}
|
|
112
|
-
const h = ({
|
|
113
|
-
inTemplate: n,
|
|
114
|
-
inSourceValues: r,
|
|
115
|
-
inShowLog: t
|
|
116
|
-
} = {}) => {
|
|
117
|
-
const e = r;
|
|
118
|
-
if (e === void 0 || !m(e)) return;
|
|
119
|
-
t && console.log("loopObject:createChildren:1 ", n, r);
|
|
120
|
-
let o = [];
|
|
121
|
-
for (const [s, c] of Object.entries(e)) {
|
|
122
|
-
const a = structuredClone(n);
|
|
123
|
-
j({ inNode: a, inData: { key: s, value: c } }), o.push(a);
|
|
124
|
-
}
|
|
125
|
-
return o;
|
|
126
|
-
}, D = ({
|
|
127
|
-
inNode: n,
|
|
128
|
-
inData: r,
|
|
129
|
-
inShowLog: t
|
|
130
|
-
} = {}) => {
|
|
131
|
-
const e = n, o = r;
|
|
132
|
-
if (t && console.log("loopObject:1 ", n, r), !("jsonToSpec" in e) || !("operation" in e.jsonToSpec) || e.jsonToSpec.operation !== "loopObject" || !("source" in e.jsonToSpec)) return;
|
|
133
|
-
t && console.log("loopObject:2 ", n, r);
|
|
134
|
-
const s = o[e.jsonToSpec.source], c = h({
|
|
135
|
-
inTemplate: e.jsonToSpec.template,
|
|
136
|
-
inSourceValues: s,
|
|
137
|
-
inShowLog: t
|
|
138
|
-
});
|
|
139
|
-
e.children = c;
|
|
140
|
-
};
|
|
141
|
-
function S(n) {
|
|
142
|
-
return n !== null && typeof n == "object" && Object.getPrototypeOf(n) === Object.prototype;
|
|
143
|
-
}
|
|
144
|
-
const N = ({
|
|
145
|
-
inNode: n,
|
|
146
|
-
inData: r
|
|
147
|
-
} = {}) => {
|
|
148
|
-
if (Object.keys(r).map((o) => `\${${o}}`).includes(n.textContent)) {
|
|
149
|
-
const o = n.textContent.slice(2, -1);
|
|
150
|
-
n.textContent = r[o];
|
|
151
|
-
}
|
|
152
|
-
}, F = ({
|
|
153
|
-
inNode: n,
|
|
154
|
-
inData: r
|
|
155
|
-
} = {}) => {
|
|
156
|
-
const t = n, e = r;
|
|
157
|
-
if (!(t != null && t.textContent)) return "no-textContent";
|
|
158
|
-
if (typeof t.textContent != "string") return "not-a-string";
|
|
159
|
-
if (!t.textContent.includes("${")) return "no-template-token";
|
|
160
|
-
S(e) ? N({ inNode: n, inData: r }) : t.textContent === "${}" && (t.textContent = e);
|
|
161
|
-
}, g = ({
|
|
162
|
-
inNode: n,
|
|
163
|
-
inData: r
|
|
164
|
-
} = {}) => {
|
|
165
|
-
const t = n;
|
|
166
|
-
if ("attributes" in t) {
|
|
167
|
-
const e = Object.fromEntries(
|
|
168
|
-
Object.entries(t.attributes).map(([o, s]) => {
|
|
169
|
-
let c = s;
|
|
170
|
-
return s === "${}" && (c = r.key), [o, c];
|
|
171
|
-
})
|
|
172
|
-
);
|
|
173
|
-
t.attributes = { ...e };
|
|
63
|
+
}) : [];
|
|
64
|
+
}, S = ({ inTemplate: e, inDataAsObject: n }) => {
|
|
65
|
+
const o = n, t = e;
|
|
66
|
+
if (o === null || typeof o != "object")
|
|
67
|
+
return [];
|
|
68
|
+
const c = [];
|
|
69
|
+
for (const [r, s] of Object.entries(o)) {
|
|
70
|
+
const l = structuredClone(t), p = i({
|
|
71
|
+
inSpecJson: l,
|
|
72
|
+
inDataJson: {
|
|
73
|
+
key: r,
|
|
74
|
+
value: s
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
c.push(p);
|
|
174
78
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
79
|
+
return c;
|
|
80
|
+
}, i = ({
|
|
81
|
+
inSpecJson: e,
|
|
82
|
+
inShowLog: n = !1,
|
|
83
|
+
inDataJson: o
|
|
84
|
+
} = {}) => {
|
|
85
|
+
if (y({ inSpec: e }))
|
|
86
|
+
return null;
|
|
87
|
+
if (m({ inSpec: e }))
|
|
88
|
+
return e;
|
|
89
|
+
if (b({ inSpecJson: e }))
|
|
90
|
+
return A({
|
|
91
|
+
inArray: e,
|
|
92
|
+
inShowLog: n,
|
|
93
|
+
inDataJson: o
|
|
94
|
+
});
|
|
95
|
+
if ("jsonToSpec" in e) {
|
|
96
|
+
if (e.jsonToSpec.operation === "loopArray") {
|
|
97
|
+
const c = j({
|
|
98
|
+
inTemplate: e.jsonToSpec.template,
|
|
99
|
+
inDataAsArray: o[e.jsonToSpec.source]
|
|
100
|
+
}), {
|
|
101
|
+
jsonToSpec: r,
|
|
102
|
+
...s
|
|
103
|
+
} = e, l = {
|
|
104
|
+
...s,
|
|
105
|
+
children: c
|
|
106
|
+
};
|
|
107
|
+
return u({
|
|
108
|
+
inSpecJson: l,
|
|
109
|
+
inShowLog: n,
|
|
110
|
+
inData: o
|
|
201
111
|
});
|
|
202
112
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
},
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
if (!Array.isArray(s)) return;
|
|
219
|
-
t && console.log("loopObject:2 ", n, r);
|
|
220
|
-
const c = w({
|
|
221
|
-
inTemplate: e.jsonToSpec.template,
|
|
222
|
-
inSourceValuesAsArray: s,
|
|
223
|
-
inShowLog: t
|
|
224
|
-
});
|
|
225
|
-
e.children = c;
|
|
226
|
-
}, p = ({ inNode: n, inData: r, inOperation: t }) => {
|
|
227
|
-
const e = n, o = r, s = t;
|
|
228
|
-
if (Array.isArray(e)) {
|
|
229
|
-
const c = [];
|
|
230
|
-
for (const a of e) {
|
|
231
|
-
const i = l({
|
|
232
|
-
inNode: a,
|
|
233
|
-
inData: o,
|
|
234
|
-
inOperation: s
|
|
113
|
+
if (e.jsonToSpec.operation === "loopObject") {
|
|
114
|
+
const c = S({
|
|
115
|
+
inTemplate: e.jsonToSpec.template,
|
|
116
|
+
inDataAsObject: o
|
|
117
|
+
}), {
|
|
118
|
+
jsonToSpec: r,
|
|
119
|
+
...s
|
|
120
|
+
} = e, l = {
|
|
121
|
+
...s,
|
|
122
|
+
children: c
|
|
123
|
+
};
|
|
124
|
+
return u({
|
|
125
|
+
inSpecJson: l,
|
|
126
|
+
inShowLog: n,
|
|
127
|
+
inData: o
|
|
235
128
|
});
|
|
236
|
-
Array.isArray(i) ? c.push(...i) : i != null && c.push(i);
|
|
237
129
|
}
|
|
238
|
-
return c;
|
|
239
|
-
}
|
|
240
|
-
}, l = ({
|
|
241
|
-
inNode: n,
|
|
242
|
-
inData: r = {},
|
|
243
|
-
inOperation: t,
|
|
244
|
-
inShowLog: e = !1
|
|
245
|
-
} = {}) => {
|
|
246
|
-
const o = n, s = r, c = t;
|
|
247
|
-
if (e && console.log("walk ", n, r, t), o == null)
|
|
248
|
-
return o;
|
|
249
|
-
if (Array.isArray(o))
|
|
250
|
-
return p({
|
|
251
|
-
inNode: o,
|
|
252
|
-
inData: r,
|
|
253
|
-
inOperation: c
|
|
254
|
-
});
|
|
255
|
-
if ("children" in o && Array.isArray(o == null ? void 0 : o.children) && (o.children = p({
|
|
256
|
-
inNode: o == null ? void 0 : o.children,
|
|
257
|
-
inData: r,
|
|
258
|
-
inOperation: c
|
|
259
|
-
})), typeof o != "object")
|
|
260
|
-
return o;
|
|
261
|
-
switch (e && console.log("localOperation ", c), c) {
|
|
262
|
-
case "replace":
|
|
263
|
-
typeof o == "object" && $({
|
|
264
|
-
inNode: o,
|
|
265
|
-
inData: r
|
|
266
|
-
});
|
|
267
|
-
break;
|
|
268
|
-
case "replaceObject":
|
|
269
|
-
typeof o == "object" && j({
|
|
270
|
-
inNode: o,
|
|
271
|
-
inData: r
|
|
272
|
-
});
|
|
273
|
-
break;
|
|
274
|
-
case "iterateDo":
|
|
275
|
-
k({
|
|
276
|
-
inNode: o,
|
|
277
|
-
inData: s,
|
|
278
|
-
inShowLog: e
|
|
279
|
-
});
|
|
280
|
-
break;
|
|
281
|
-
case "loopObject":
|
|
282
|
-
D({
|
|
283
|
-
inNode: o,
|
|
284
|
-
inData: s,
|
|
285
|
-
inShowLog: e
|
|
286
|
-
});
|
|
287
|
-
break;
|
|
288
|
-
case "loopArray":
|
|
289
|
-
K({
|
|
290
|
-
inNode: o,
|
|
291
|
-
inData: s,
|
|
292
|
-
inShowLog: e
|
|
293
|
-
});
|
|
294
|
-
break;
|
|
295
130
|
}
|
|
296
|
-
return
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
throw console.error("[json-to-spec/v17] replace error:", o), o;
|
|
307
|
-
}
|
|
308
|
-
}, P = (n, r = {}, t = !1) => {
|
|
309
|
-
let e = n, o = r;
|
|
310
|
-
t && console.log(f.name, e, o);
|
|
131
|
+
return u({
|
|
132
|
+
inSpecJson: e,
|
|
133
|
+
inShowLog: n,
|
|
134
|
+
inData: o
|
|
135
|
+
});
|
|
136
|
+
}, T = ({
|
|
137
|
+
specJson: e,
|
|
138
|
+
showLog: n,
|
|
139
|
+
dataJson: o
|
|
140
|
+
}) => {
|
|
311
141
|
try {
|
|
312
|
-
return
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
inShowLog: t
|
|
142
|
+
return i({
|
|
143
|
+
inSpecJson: e,
|
|
144
|
+
inShowLog: n,
|
|
145
|
+
inDataJson: o
|
|
317
146
|
});
|
|
318
|
-
} catch (
|
|
319
|
-
|
|
147
|
+
} catch (t) {
|
|
148
|
+
console.log("error : ", t);
|
|
320
149
|
}
|
|
321
150
|
};
|
|
322
|
-
|
|
151
|
+
d(T);
|
|
323
152
|
export {
|
|
324
|
-
|
|
325
|
-
P as default
|
|
153
|
+
T as default
|
|
326
154
|
};
|