json-to-spec 20.1.1 → 21.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 +98 -308
- 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/package.json +1 -1
- 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/docs/dist/min.js
CHANGED
|
@@ -1,326 +1,116 @@
|
|
|
1
|
-
const
|
|
2
|
-
version: "
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
compile: n
|
|
1
|
+
const u = {
|
|
2
|
+
version: "v21.0",
|
|
3
|
+
description: "Pure spec engine no document at all"
|
|
4
|
+
}, i = (e) => {
|
|
5
|
+
typeof globalThis > "u" || !e || (globalThis.ks ?? (globalThis.ks = {}), globalThis.ks["json-to-spec"] = {
|
|
6
|
+
meta: u,
|
|
7
|
+
buildSpecElement: e
|
|
9
8
|
});
|
|
10
|
-
},
|
|
11
|
-
const t =
|
|
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
|
+
}, f = ({ inSpec: e }) => {
|
|
10
|
+
const t = e;
|
|
11
|
+
return t == null;
|
|
12
|
+
}, d = ({ inSpec: e }) => typeof Node < "u" && e instanceof Node, p = ({ inSpecJson: e }) => Array.isArray(e), y = ({ inArray: e = [], inShowLog: t = !1, inDataJson: o }) => {
|
|
13
|
+
const r = e, l = t, n = o;
|
|
14
|
+
return Array.isArray(r) ? r.map((c) => a({
|
|
15
|
+
inSpecJson: c,
|
|
16
|
+
inShowLog: l,
|
|
17
|
+
inDataJson: n
|
|
18
|
+
})).flat().filter(Boolean) : [];
|
|
19
|
+
}, s = (e, t) => typeof e != "string" ? e : e.replace(/\$\{([^}]+)\}/g, (o, r) => {
|
|
20
|
+
const l = r.trim().split(".");
|
|
21
|
+
let n = t;
|
|
22
|
+
for (const c of l) {
|
|
23
|
+
if (n == null)
|
|
24
|
+
return "";
|
|
25
|
+
n = n[c];
|
|
47
26
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
27
|
+
return n === null || typeof n == "string" || typeof n == "number" || typeof n == "boolean" ? String(n ?? "") : n;
|
|
28
|
+
}), m = ({ inSpecJson: e, inData: t, inShowLog: o }) => ("key" in t && "value" in t ? "textContent" in e && (e.textContent = s(
|
|
29
|
+
e.textContent,
|
|
30
|
+
t
|
|
31
|
+
)) : ("textContent" in e && (e.textContent = s(
|
|
32
|
+
e.textContent,
|
|
33
|
+
t
|
|
34
|
+
)), "attributes" in e && (e.attributes = Object.fromEntries(
|
|
35
|
+
Object.entries(e.attributes).map(
|
|
36
|
+
([r, l]) => [
|
|
37
|
+
r,
|
|
38
|
+
s(l, t)
|
|
39
|
+
]
|
|
40
|
+
)
|
|
41
|
+
)), "children" in e && (e.children = e.children.map((r) => a({
|
|
42
|
+
inSpecJson: r,
|
|
43
|
+
inShowLog: o,
|
|
44
|
+
inDataJson: t
|
|
45
|
+
})))), e), b = ({ inTemplate: e, inDataAsArray: t }) => {
|
|
46
|
+
const o = t, r = e;
|
|
47
|
+
return o.map((n) => {
|
|
48
|
+
const c = structuredClone(r);
|
|
49
|
+
return a({
|
|
50
|
+
inSpecJson: c,
|
|
51
|
+
inDataJson: n
|
|
65
52
|
});
|
|
66
53
|
});
|
|
67
|
-
},
|
|
68
|
-
inNode: n,
|
|
69
|
-
inData: r,
|
|
70
|
-
inShowLog: t
|
|
71
|
-
} = {}) => {
|
|
72
|
-
const e = n, o = r;
|
|
73
|
-
if (!("jsonToSpec" in e) || !("operation" in e.jsonToSpec) || e.jsonToSpec.operation !== "iterate" || !("source" in e.jsonToSpec)) return;
|
|
74
|
-
const s = o[e.jsonToSpec.source], c = T({
|
|
75
|
-
inTemplate: e.jsonToSpec.template,
|
|
76
|
-
inSourceValues: s
|
|
77
|
-
});
|
|
78
|
-
e.children = c;
|
|
79
|
-
}, x = ({
|
|
80
|
-
inNode: n,
|
|
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);
|
|
54
|
+
}, h = ({ inTemplate: e, inDataAsObject: t }) => {
|
|
120
55
|
let o = [];
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
56
|
+
console.log("11111111--------loopObject : ", t);
|
|
57
|
+
for (const [r, l] of Object.entries(t)) {
|
|
58
|
+
const n = structuredClone(e), c = a({
|
|
59
|
+
inSpecJson: n,
|
|
60
|
+
inDataJson: { key: r, value: l }
|
|
61
|
+
});
|
|
62
|
+
o.push(c);
|
|
124
63
|
}
|
|
125
64
|
return o;
|
|
126
|
-
},
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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 };
|
|
174
|
-
}
|
|
175
|
-
}, V = ({
|
|
176
|
-
inNode: n,
|
|
177
|
-
inData: r
|
|
178
|
-
} = {}) => {
|
|
179
|
-
const t = n, e = r;
|
|
180
|
-
F({ inNode: t, inData: e }), g({ inNode: t, inData: e });
|
|
181
|
-
}, w = ({
|
|
182
|
-
inTemplate: n,
|
|
183
|
-
inSourceValuesAsArray: r,
|
|
184
|
-
inShowLog: t
|
|
185
|
-
} = {}) => {
|
|
186
|
-
const e = r;
|
|
187
|
-
if (e === void 0 || !Array.isArray(e)) return;
|
|
188
|
-
t && console.log("loopObject:createChildren:1 ", n, inSourceValues);
|
|
189
|
-
let o = [];
|
|
190
|
-
return e.forEach((s) => {
|
|
191
|
-
var a, i;
|
|
192
|
-
const c = structuredClone(n);
|
|
193
|
-
if ("jsonToSpec" in c) {
|
|
194
|
-
const y = (a = c == null ? void 0 : c.jsonToSpec) == null ? void 0 : a.source;
|
|
195
|
-
let u = {};
|
|
196
|
-
u[y] = s, l({
|
|
197
|
-
inNode: c,
|
|
198
|
-
inData: u,
|
|
199
|
-
inOperation: (i = c == null ? void 0 : c.jsonToSpec) == null ? void 0 : i.operation,
|
|
200
|
-
inShowLog: t
|
|
65
|
+
}, a = ({ inSpecJson: e, inShowLog: t = !1, inDataJson: o } = {}) => {
|
|
66
|
+
if (f({ inSpec: e })) return null;
|
|
67
|
+
if (d({ inSpec: e })) return e;
|
|
68
|
+
if (p({ inSpecJson: e }))
|
|
69
|
+
return y({
|
|
70
|
+
inArray: e,
|
|
71
|
+
inShowLog: t,
|
|
72
|
+
inDataJson: o
|
|
73
|
+
});
|
|
74
|
+
if ("jsonToSpec" in e) {
|
|
75
|
+
if ("isSpecBuilt" in e)
|
|
76
|
+
return e;
|
|
77
|
+
if (e.jsonToSpec.operation === "loopArray") {
|
|
78
|
+
const r = b({
|
|
79
|
+
inTemplate: e.jsonToSpec.template,
|
|
80
|
+
inDataAsArray: o[e.jsonToSpec.source]
|
|
201
81
|
});
|
|
82
|
+
e.children = r;
|
|
202
83
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
inShowLog: t
|
|
208
|
-
}), V({ inNode: c, inData: s }), o.push(c);
|
|
209
|
-
}), o;
|
|
210
|
-
}, K = ({
|
|
211
|
-
inNode: n,
|
|
212
|
-
inData: r,
|
|
213
|
-
inShowLog: t
|
|
214
|
-
} = {}) => {
|
|
215
|
-
const e = n, o = r;
|
|
216
|
-
if (t && console.log("loopObject:1 ", n, r), !("jsonToSpec" in e) || !("operation" in e.jsonToSpec) || e.jsonToSpec.operation !== "loopArray" || !("source" in e.jsonToSpec)) return;
|
|
217
|
-
const s = o[e.jsonToSpec.source];
|
|
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
|
|
84
|
+
if (e.jsonToSpec.operation === "loopObject") {
|
|
85
|
+
const r = h({
|
|
86
|
+
inTemplate: e.jsonToSpec.template,
|
|
87
|
+
inDataAsObject: o
|
|
235
88
|
});
|
|
236
|
-
|
|
89
|
+
e.children = r;
|
|
237
90
|
}
|
|
238
|
-
|
|
91
|
+
e.isSpecBuilt = !0;
|
|
239
92
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
} = {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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
|
-
}
|
|
296
|
-
return o;
|
|
297
|
-
}, E = ({ inStructureAsJson: n, inDataAsJson: r, inOperation: t, inShowLog: e }) => {
|
|
298
|
-
try {
|
|
299
|
-
return l({
|
|
300
|
-
inNode: n,
|
|
301
|
-
inData: r,
|
|
302
|
-
inOperation: t,
|
|
303
|
-
inShowLog: e
|
|
304
|
-
});
|
|
305
|
-
} catch (o) {
|
|
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);
|
|
93
|
+
return m({
|
|
94
|
+
inSpecJson: e,
|
|
95
|
+
inShowLog: t,
|
|
96
|
+
inData: o
|
|
97
|
+
});
|
|
98
|
+
}, A = ({
|
|
99
|
+
specJson: e,
|
|
100
|
+
showLog: t,
|
|
101
|
+
dataJson: o
|
|
102
|
+
}) => {
|
|
311
103
|
try {
|
|
312
|
-
return
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
inShowLog: t
|
|
104
|
+
return a({
|
|
105
|
+
inSpecJson: e,
|
|
106
|
+
inShowLog: t,
|
|
107
|
+
inDataJson: o
|
|
317
108
|
});
|
|
318
|
-
} catch (
|
|
319
|
-
|
|
109
|
+
} catch (r) {
|
|
110
|
+
console.log("error : ", r);
|
|
320
111
|
}
|
|
321
112
|
};
|
|
322
|
-
|
|
113
|
+
i(A);
|
|
323
114
|
export {
|
|
324
|
-
|
|
325
|
-
P as default
|
|
115
|
+
A as default
|
|
326
116
|
};
|