json-to-spec 23.1.1 → 24.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 +154 -154
- package/docs/dist/v21/min.js +116 -116
- package/docs/dist/v23/min.js +154 -154
- package/package.json +6 -6
- package/samples/table3/index.js +8 -10
- package/src/index.js +2 -2
- package/src/v24/buildSpec/buildSpecArray.js +16 -0
- package/src/v24/buildSpec/forArray/v1/index.js +27 -0
- package/src/v24/buildSpec/forArrayStrings/v1/index.js +24 -0
- package/src/v24/buildSpec/forObject/v1/index.js +47 -0
- package/src/v24/buildSpec/forSpec/v3/index.js +114 -0
- package/src/v24/buildSpec/guards.js +20 -0
- package/src/v24/buildSpec/index.js +122 -0
- package/src/v24/index.js +21 -0
- package/src/v24/meta.js +6 -0
- package/src/v24/registerGlobal.js +22 -0
package/docs/dist/min.js
CHANGED
|
@@ -1,154 +1,154 @@
|
|
|
1
|
-
const f = {
|
|
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"] = {
|
|
6
|
-
meta: f,
|
|
7
|
-
buildSpecElement: e
|
|
8
|
-
});
|
|
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];
|
|
26
|
-
}
|
|
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
|
|
62
|
-
});
|
|
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);
|
|
78
|
-
}
|
|
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
|
|
111
|
-
});
|
|
112
|
-
}
|
|
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
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
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
|
-
}) => {
|
|
141
|
-
try {
|
|
142
|
-
return i({
|
|
143
|
-
inSpecJson: e,
|
|
144
|
-
inShowLog: n,
|
|
145
|
-
inDataJson: o
|
|
146
|
-
});
|
|
147
|
-
} catch (t) {
|
|
148
|
-
console.log("error : ", t);
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
d(T);
|
|
152
|
-
export {
|
|
153
|
-
T as default
|
|
154
|
-
};
|
|
1
|
+
const f = {
|
|
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"] = {
|
|
6
|
+
meta: f,
|
|
7
|
+
buildSpecElement: e
|
|
8
|
+
});
|
|
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];
|
|
26
|
+
}
|
|
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
|
|
62
|
+
});
|
|
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);
|
|
78
|
+
}
|
|
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
|
|
111
|
+
});
|
|
112
|
+
}
|
|
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
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
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
|
+
}) => {
|
|
141
|
+
try {
|
|
142
|
+
return i({
|
|
143
|
+
inSpecJson: e,
|
|
144
|
+
inShowLog: n,
|
|
145
|
+
inDataJson: o
|
|
146
|
+
});
|
|
147
|
+
} catch (t) {
|
|
148
|
+
console.log("error : ", t);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
d(T);
|
|
152
|
+
export {
|
|
153
|
+
T as default
|
|
154
|
+
};
|
package/docs/dist/v21/min.js
CHANGED
|
@@ -1,116 +1,116 @@
|
|
|
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
|
|
8
|
-
});
|
|
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];
|
|
26
|
-
}
|
|
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
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
}, h = ({ inTemplate: e, inDataAsObject: t }) => {
|
|
55
|
-
let o = [];
|
|
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);
|
|
63
|
-
}
|
|
64
|
-
return o;
|
|
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]
|
|
81
|
-
});
|
|
82
|
-
e.children = r;
|
|
83
|
-
}
|
|
84
|
-
if (e.jsonToSpec.operation === "loopObject") {
|
|
85
|
-
const r = h({
|
|
86
|
-
inTemplate: e.jsonToSpec.template,
|
|
87
|
-
inDataAsObject: o
|
|
88
|
-
});
|
|
89
|
-
e.children = r;
|
|
90
|
-
}
|
|
91
|
-
e.isSpecBuilt = !0;
|
|
92
|
-
}
|
|
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
|
-
}) => {
|
|
103
|
-
try {
|
|
104
|
-
return a({
|
|
105
|
-
inSpecJson: e,
|
|
106
|
-
inShowLog: t,
|
|
107
|
-
inDataJson: o
|
|
108
|
-
});
|
|
109
|
-
} catch (r) {
|
|
110
|
-
console.log("error : ", r);
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
i(A);
|
|
114
|
-
export {
|
|
115
|
-
A as default
|
|
116
|
-
};
|
|
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
|
|
8
|
+
});
|
|
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];
|
|
26
|
+
}
|
|
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
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}, h = ({ inTemplate: e, inDataAsObject: t }) => {
|
|
55
|
+
let o = [];
|
|
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);
|
|
63
|
+
}
|
|
64
|
+
return o;
|
|
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]
|
|
81
|
+
});
|
|
82
|
+
e.children = r;
|
|
83
|
+
}
|
|
84
|
+
if (e.jsonToSpec.operation === "loopObject") {
|
|
85
|
+
const r = h({
|
|
86
|
+
inTemplate: e.jsonToSpec.template,
|
|
87
|
+
inDataAsObject: o
|
|
88
|
+
});
|
|
89
|
+
e.children = r;
|
|
90
|
+
}
|
|
91
|
+
e.isSpecBuilt = !0;
|
|
92
|
+
}
|
|
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
|
+
}) => {
|
|
103
|
+
try {
|
|
104
|
+
return a({
|
|
105
|
+
inSpecJson: e,
|
|
106
|
+
inShowLog: t,
|
|
107
|
+
inDataJson: o
|
|
108
|
+
});
|
|
109
|
+
} catch (r) {
|
|
110
|
+
console.log("error : ", r);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
i(A);
|
|
114
|
+
export {
|
|
115
|
+
A as default
|
|
116
|
+
};
|
package/docs/dist/v23/min.js
CHANGED
|
@@ -1,154 +1,154 @@
|
|
|
1
|
-
const f = {
|
|
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"] = {
|
|
6
|
-
meta: f,
|
|
7
|
-
buildSpecElement: e
|
|
8
|
-
});
|
|
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];
|
|
26
|
-
}
|
|
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
|
|
62
|
-
});
|
|
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);
|
|
78
|
-
}
|
|
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
|
|
111
|
-
});
|
|
112
|
-
}
|
|
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
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
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
|
-
}) => {
|
|
141
|
-
try {
|
|
142
|
-
return i({
|
|
143
|
-
inSpecJson: e,
|
|
144
|
-
inShowLog: n,
|
|
145
|
-
inDataJson: o
|
|
146
|
-
});
|
|
147
|
-
} catch (t) {
|
|
148
|
-
console.log("error : ", t);
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
d(T);
|
|
152
|
-
export {
|
|
153
|
-
T as default
|
|
154
|
-
};
|
|
1
|
+
const f = {
|
|
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"] = {
|
|
6
|
+
meta: f,
|
|
7
|
+
buildSpecElement: e
|
|
8
|
+
});
|
|
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];
|
|
26
|
+
}
|
|
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
|
|
62
|
+
});
|
|
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);
|
|
78
|
+
}
|
|
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
|
|
111
|
+
});
|
|
112
|
+
}
|
|
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
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
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
|
+
}) => {
|
|
141
|
+
try {
|
|
142
|
+
return i({
|
|
143
|
+
inSpecJson: e,
|
|
144
|
+
inShowLog: n,
|
|
145
|
+
inDataJson: o
|
|
146
|
+
});
|
|
147
|
+
} catch (t) {
|
|
148
|
+
console.log("error : ", t);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
d(T);
|
|
152
|
+
export {
|
|
153
|
+
T as default
|
|
154
|
+
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-to-spec",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "24.1.1",
|
|
4
4
|
"description": "Pure JSON Specification Compiler with jsonToSpec namespace: (structure, data) -> Spec JSON",
|
|
5
|
-
"main": "src/
|
|
6
|
-
"module": "./src/
|
|
5
|
+
"main": "src/v24/index.js",
|
|
6
|
+
"module": "./src/v24/index.js",
|
|
7
7
|
"files": [
|
|
8
8
|
"index.js",
|
|
9
9
|
"src",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"type": "module",
|
|
36
36
|
"exports": {
|
|
37
37
|
".": {
|
|
38
|
-
"import": "./src/
|
|
39
|
-
"require": "./src/
|
|
40
|
-
"default": "./src/
|
|
38
|
+
"import": "./src/v24/index.js",
|
|
39
|
+
"require": "./src/v24/index.js",
|
|
40
|
+
"default": "./src/v24/index.js"
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
"bugs": {
|
package/samples/table3/index.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
// import * as domEngine from "./json-to-dom.v27.min.js";
|
|
1
|
+
import buildSpecElement from "../../src/index.js";
|
|
3
2
|
|
|
4
|
-
import
|
|
3
|
+
import "https://keshavsoft.github.io/json-to-tag/dist/v4/min.js";
|
|
5
4
|
|
|
6
5
|
const folder = "input";
|
|
7
|
-
let actionBinding = null;
|
|
8
|
-
let state = { structure: null, data: null, compiled: null };
|
|
9
|
-
const htmlId2 = "table-body";
|
|
10
|
-
const htmlId1 = "body-row";
|
|
11
6
|
const htmlId = "table";
|
|
12
7
|
|
|
13
8
|
const loadInput = async () => {
|
|
@@ -23,8 +18,7 @@ const loadInput = async () => {
|
|
|
23
18
|
};
|
|
24
19
|
|
|
25
20
|
const render = (structure, data) => {
|
|
26
|
-
let specAsJsonToDom =
|
|
27
|
-
console.log("specAsJsonToDom------------ : ", specAsJsonToDom);
|
|
21
|
+
let specAsJsonToDom = buildSpecElement({ specJson: structure, dataJson: data });
|
|
28
22
|
|
|
29
23
|
if (!("tagName" in specAsJsonToDom)) {
|
|
30
24
|
specAsJsonToDom = specAsJsonToDom.children;
|
|
@@ -34,7 +28,11 @@ const render = (structure, data) => {
|
|
|
34
28
|
|
|
35
29
|
if (container) container.innerHTML = "";
|
|
36
30
|
|
|
37
|
-
|
|
31
|
+
const content = window.ks.jsonToTag.buildSpecElement(specAsJsonToDom);
|
|
32
|
+
container.append(content);
|
|
33
|
+
|
|
34
|
+
console.log("content : ", content);
|
|
35
|
+
|
|
38
36
|
};
|
|
39
37
|
|
|
40
38
|
const start = async () => {
|
package/src/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "./
|
|
2
|
-
export * from "./
|
|
1
|
+
export { default } from "./v24/index.js";
|
|
2
|
+
export * from "./v24/index.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import dispatchSpec from "./index.js";
|
|
2
|
+
|
|
3
|
+
export const buildSpecArray = ({ inArray = [], inShowLog = false, inDataJson }) => {
|
|
4
|
+
const localArray = inArray;
|
|
5
|
+
const localShowLog = inShowLog;
|
|
6
|
+
const localDataJson = inDataJson;
|
|
7
|
+
|
|
8
|
+
if (!Array.isArray(localArray)) return [];
|
|
9
|
+
|
|
10
|
+
return localArray.map(item => dispatchSpec({
|
|
11
|
+
inSpecJson: item,
|
|
12
|
+
inShowLog: localShowLog, inDataJson: localDataJson
|
|
13
|
+
})).flat().filter(Boolean);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default buildSpecArray;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import dispatchSpec from "../../index.js";
|
|
2
|
+
|
|
3
|
+
const startFunc = ({ inTemplate, inDataAsArray }) => {
|
|
4
|
+
|
|
5
|
+
const localDataAsArray = inDataAsArray;
|
|
6
|
+
const localTemplate = inTemplate;
|
|
7
|
+
|
|
8
|
+
if (!Array.isArray(localDataAsArray)) {
|
|
9
|
+
return [];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const childrenArray = localDataAsArray.map(element => {
|
|
13
|
+
|
|
14
|
+
// console.log("OUTER forArray element:", element);
|
|
15
|
+
|
|
16
|
+
const newTemplate = structuredClone(localTemplate);
|
|
17
|
+
|
|
18
|
+
return dispatchSpec({
|
|
19
|
+
inSpecJson: newTemplate,
|
|
20
|
+
inDataJson: element
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return childrenArray;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default startFunc;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import dispatchSpec from "../../index.js";
|
|
2
|
+
|
|
3
|
+
const startFunc = ({ inTemplate, inDataAsArray }) => {
|
|
4
|
+
|
|
5
|
+
const localDataAsArray = inDataAsArray;
|
|
6
|
+
const localTemplate = inTemplate;
|
|
7
|
+
|
|
8
|
+
if (!Array.isArray(localDataAsArray)) {
|
|
9
|
+
return [];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const childrenArray = localDataAsArray.map(element => {
|
|
13
|
+
const newTemplate = structuredClone(localTemplate);
|
|
14
|
+
|
|
15
|
+
return dispatchSpec({
|
|
16
|
+
inSpecJson: newTemplate,
|
|
17
|
+
inDataJson: element
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return childrenArray;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default startFunc;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import dispatchSpec from "../../index.js";
|
|
2
|
+
|
|
3
|
+
const startFunc = ({ inTemplate, inDataAsObject }) => {
|
|
4
|
+
|
|
5
|
+
const localDataAsObject = inDataAsObject;
|
|
6
|
+
const localTemplate = inTemplate;
|
|
7
|
+
|
|
8
|
+
if (
|
|
9
|
+
localDataAsObject === null ||
|
|
10
|
+
typeof localDataAsObject !== "object"
|
|
11
|
+
) {
|
|
12
|
+
return [];
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const childrenArray = [];
|
|
16
|
+
|
|
17
|
+
for (const [key, value] of Object.entries(localDataAsObject)) {
|
|
18
|
+
|
|
19
|
+
// console.log(
|
|
20
|
+
// "INNER:",
|
|
21
|
+
// key,
|
|
22
|
+
// value,
|
|
23
|
+
// typeof value
|
|
24
|
+
// );
|
|
25
|
+
|
|
26
|
+
const newTemplate = structuredClone(localTemplate);
|
|
27
|
+
|
|
28
|
+
const createdElement = dispatchSpec({
|
|
29
|
+
inSpecJson: newTemplate,
|
|
30
|
+
inDataJson: {
|
|
31
|
+
key,
|
|
32
|
+
value
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// console.log(
|
|
37
|
+
// "INNER createdElement:",
|
|
38
|
+
// createdElement
|
|
39
|
+
// );
|
|
40
|
+
|
|
41
|
+
childrenArray.push(createdElement);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return childrenArray;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default startFunc;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import buildSpec from "../../index.js";
|
|
2
|
+
|
|
3
|
+
const resolveTemplate = (template, data) => {
|
|
4
|
+
if (typeof template !== "string") {
|
|
5
|
+
return template;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
return template.replace(/\$\{([^}]+)\}/g, (_, path) => {
|
|
9
|
+
|
|
10
|
+
const keys = path.trim().split(".");
|
|
11
|
+
|
|
12
|
+
let value = data;
|
|
13
|
+
|
|
14
|
+
for (const key of keys) {
|
|
15
|
+
if (value === null || value === undefined) {
|
|
16
|
+
return "";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
value = value[key];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (
|
|
23
|
+
value === null ||
|
|
24
|
+
typeof value === "string" ||
|
|
25
|
+
typeof value === "number" ||
|
|
26
|
+
typeof value === "boolean"
|
|
27
|
+
) {
|
|
28
|
+
return String(value ?? "");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return value;
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const startFunc = ({ inSpecJson, inData, inShowLog }) => {
|
|
36
|
+
// console.log("inData : ", inData);
|
|
37
|
+
|
|
38
|
+
// Create a completely new tree.
|
|
39
|
+
const newSpec = structuredClone(inSpecJson);
|
|
40
|
+
|
|
41
|
+
if (typeof inData === 'string') {
|
|
42
|
+
// console.log("It's a string!");
|
|
43
|
+
// console.log("inData : ", inData, newSpec);
|
|
44
|
+
if ("textContent" in newSpec) {
|
|
45
|
+
if (newSpec.textContent === "${}") {
|
|
46
|
+
newSpec.textContent = inData;
|
|
47
|
+
} else if (typeof newSpec.textContent === "string") {
|
|
48
|
+
newSpec.textContent = newSpec.textContent.replaceAll("${}", () => inData);
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
if ("attributes" in newSpec) {
|
|
53
|
+
newSpec.attributes = Object.fromEntries(
|
|
54
|
+
Object.entries(newSpec.attributes).map(
|
|
55
|
+
([attributeName, attributeValue]) => [
|
|
56
|
+
attributeName,
|
|
57
|
+
attributeValue === "${}"
|
|
58
|
+
? inData
|
|
59
|
+
: (typeof attributeValue === "string"
|
|
60
|
+
? attributeValue.replaceAll("${}", () => inData)
|
|
61
|
+
: attributeValue)
|
|
62
|
+
]
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
} else {
|
|
68
|
+
if ("key" in inData && "value" in inData) {
|
|
69
|
+
|
|
70
|
+
if ("textContent" in newSpec) {
|
|
71
|
+
newSpec.textContent = resolveTemplate(
|
|
72
|
+
newSpec.textContent,
|
|
73
|
+
inData
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
} else {
|
|
78
|
+
|
|
79
|
+
if ("textContent" in newSpec) {
|
|
80
|
+
newSpec.textContent = resolveTemplate(
|
|
81
|
+
newSpec.textContent,
|
|
82
|
+
inData
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
if ("attributes" in newSpec) {
|
|
87
|
+
newSpec.attributes = Object.fromEntries(
|
|
88
|
+
Object.entries(newSpec.attributes).map(
|
|
89
|
+
([attributeName, attributeValue]) => [
|
|
90
|
+
attributeName,
|
|
91
|
+
resolveTemplate(attributeValue, inData)
|
|
92
|
+
]
|
|
93
|
+
)
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
if ("children" in newSpec) {
|
|
98
|
+
newSpec.children = newSpec.children.map((child) => {
|
|
99
|
+
return buildSpec({
|
|
100
|
+
inSpecJson: child,
|
|
101
|
+
inShowLog: inShowLog,
|
|
102
|
+
inDataJson: inData
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
return newSpec;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export default startFunc;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const isNullOrUndefined = ({ inSpec }) => {
|
|
2
|
+
const localSpec = inSpec;
|
|
3
|
+
return localSpec === null || localSpec === undefined;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export const isDomNode = ({ inSpec }) => {
|
|
7
|
+
const localSpec = inSpec;
|
|
8
|
+
return typeof Node !== "undefined" && localSpec instanceof Node;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const isSpecArray = ({ inSpecJson }) => {
|
|
12
|
+
const localSpec = inSpecJson;
|
|
13
|
+
return Array.isArray(localSpec);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default {
|
|
17
|
+
isNullOrUndefined,
|
|
18
|
+
isDomNode,
|
|
19
|
+
isSpecArray
|
|
20
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isNullOrUndefined,
|
|
3
|
+
isDomNode,
|
|
4
|
+
isSpecArray
|
|
5
|
+
} from "./guards.js";
|
|
6
|
+
|
|
7
|
+
import buildSpecArray from "./buildSpecArray.js";
|
|
8
|
+
import buildSingleElement from "./forSpec/v3/index.js";
|
|
9
|
+
import forArray from "./forArray/v1/index.js";
|
|
10
|
+
import forObject from "./forObject/v1/index.js";
|
|
11
|
+
import forArrayStrings from "./forArrayStrings/v1/index.js";
|
|
12
|
+
|
|
13
|
+
const dispatchSpec = ({
|
|
14
|
+
inSpecJson,
|
|
15
|
+
inShowLog = false,
|
|
16
|
+
inDataJson
|
|
17
|
+
} = {}) => {
|
|
18
|
+
|
|
19
|
+
if (isNullOrUndefined({ inSpec: inSpecJson })) {
|
|
20
|
+
return null;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
if (isDomNode({ inSpec: inSpecJson })) {
|
|
24
|
+
return inSpecJson;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
if (isSpecArray({ inSpecJson })) {
|
|
28
|
+
return buildSpecArray({
|
|
29
|
+
inArray: inSpecJson,
|
|
30
|
+
inShowLog,
|
|
31
|
+
inDataJson
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
if ("jsonToSpec" in inSpecJson) {
|
|
36
|
+
|
|
37
|
+
if (inSpecJson.jsonToSpec.operation === "loopArray") {
|
|
38
|
+
|
|
39
|
+
const fromArray = forArray({
|
|
40
|
+
inTemplate: inSpecJson.jsonToSpec.template,
|
|
41
|
+
inDataAsArray:
|
|
42
|
+
inDataJson[inSpecJson.jsonToSpec.source]
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const {
|
|
46
|
+
jsonToSpec,
|
|
47
|
+
...specWithoutJsonToSpec
|
|
48
|
+
} = inSpecJson;
|
|
49
|
+
|
|
50
|
+
const newSpec = {
|
|
51
|
+
...specWithoutJsonToSpec,
|
|
52
|
+
children: fromArray
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return buildSingleElement({
|
|
56
|
+
inSpecJson: newSpec,
|
|
57
|
+
inShowLog,
|
|
58
|
+
inData: inDataJson
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
// may be this can be deleted
|
|
62
|
+
// if (inSpecJson.jsonToSpec.operation === "loopArrayStrings") {
|
|
63
|
+
// debugger
|
|
64
|
+
// const fromArray = forArrayStrings({
|
|
65
|
+
// inTemplate: inSpecJson.jsonToSpec.template,
|
|
66
|
+
// inDataAsArray:
|
|
67
|
+
// inDataJson[inSpecJson.jsonToSpec.source]
|
|
68
|
+
// });
|
|
69
|
+
|
|
70
|
+
// const {
|
|
71
|
+
// jsonToSpec,
|
|
72
|
+
// ...specWithoutJsonToSpec
|
|
73
|
+
// } = inSpecJson;
|
|
74
|
+
|
|
75
|
+
// const newSpec = {
|
|
76
|
+
// ...specWithoutJsonToSpec,
|
|
77
|
+
// children: fromArray
|
|
78
|
+
// };
|
|
79
|
+
|
|
80
|
+
// return buildSingleElement({
|
|
81
|
+
// inSpecJson: newSpec,
|
|
82
|
+
// inShowLog,
|
|
83
|
+
// inData: inDataJson
|
|
84
|
+
// });
|
|
85
|
+
// };
|
|
86
|
+
|
|
87
|
+
if (inSpecJson.jsonToSpec.operation === "loopObject") {
|
|
88
|
+
|
|
89
|
+
const fromObject = forObject({
|
|
90
|
+
inTemplate: inSpecJson.jsonToSpec.template,
|
|
91
|
+
inDataAsObject: inDataJson
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const {
|
|
95
|
+
jsonToSpec,
|
|
96
|
+
...specWithoutJsonToSpec
|
|
97
|
+
} = inSpecJson;
|
|
98
|
+
|
|
99
|
+
const newSpec = {
|
|
100
|
+
...specWithoutJsonToSpec,
|
|
101
|
+
children: fromObject
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
return buildSingleElement({
|
|
105
|
+
inSpecJson: newSpec,
|
|
106
|
+
inShowLog,
|
|
107
|
+
inData: inDataJson
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const toReturnObject = buildSingleElement({
|
|
113
|
+
inSpecJson,
|
|
114
|
+
inShowLog,
|
|
115
|
+
inData: inDataJson
|
|
116
|
+
});
|
|
117
|
+
// console.log("toReturnObject : ", inSpecJson, toReturnObject);
|
|
118
|
+
|
|
119
|
+
return toReturnObject;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export default dispatchSpec;
|
package/src/v24/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import registerGlobal from "./registerGlobal.js";
|
|
2
|
+
import buildSpec from "./buildSpec/index.js";
|
|
3
|
+
|
|
4
|
+
const buildSpecElement = ({ specJson,
|
|
5
|
+
showLog, dataJson }) => {
|
|
6
|
+
try {
|
|
7
|
+
|
|
8
|
+
const element = buildSpec({
|
|
9
|
+
inSpecJson: specJson,
|
|
10
|
+
inShowLog: showLog, inDataJson: dataJson
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
return element;
|
|
14
|
+
} catch (error) {
|
|
15
|
+
console.log("error : ", error);
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
registerGlobal(buildSpecElement);
|
|
20
|
+
|
|
21
|
+
export default buildSpecElement;
|
package/src/v24/meta.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import meta from "./meta.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 3. registerGlobal - Orchestration Step 3
|
|
5
|
+
* Safely registers the json-to-dom public API onto globalThis.ks in browser / SSR environments.
|
|
6
|
+
*/
|
|
7
|
+
export const registerGlobal = (inFuncDefinition) => {
|
|
8
|
+
if (typeof globalThis === "undefined" || !inFuncDefinition) return;
|
|
9
|
+
|
|
10
|
+
globalThis.ks ??= {};
|
|
11
|
+
globalThis.ks["json-to-spec"] = {
|
|
12
|
+
meta,
|
|
13
|
+
buildSpecElement: inFuncDefinition
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
globalThis.ks.jsonToSpec = {
|
|
17
|
+
meta,
|
|
18
|
+
buildSpecElement: inFuncDefinition
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default registerGlobal;
|