json-renderers-build 1.3.6 → 1.5.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.
@@ -0,0 +1,320 @@
1
+ const g = {
2
+ version: "v4.0.0",
3
+ description: "build table from store data and render to DOM uses json-to-spec, json-to-dom under the hood"
4
+ }, j = (t) => {
5
+ var r;
6
+ typeof globalThis > "u" || !t || (globalThis.ks ?? (globalThis.ks = {}), (r = globalThis.ks).jsonRenderersBuild ?? (r.jsonRenderersBuild = {
7
+ meta: g,
8
+ renderToDom: t
9
+ }));
10
+ }, E = {
11
+ version: "v32",
12
+ description: "JSON-to-DOM engine with centralized traversal and responsibility-focused construction"
13
+ }, N = ({ inFuncDefinition: t } = {}) => {
14
+ if (typeof globalThis > "u" || !t) return;
15
+ globalThis.ks ?? (globalThis.ks = {});
16
+ const r = {
17
+ meta: E,
18
+ buildSpecElement: t
19
+ };
20
+ globalThis.ks.jsonToSpec = r;
21
+ }, O = (t, r) => f(t, r), b = (t, r) => Array.isArray(t) ? t.map((e) => O(e, r)).flat(1 / 0).filter(Boolean) : [], x = (t, r) => {
22
+ if ("source" in t && (t == null ? void 0 : t.source) in r) {
23
+ const e = r[t == null ? void 0 : t.source];
24
+ if (Array.isArray(e))
25
+ return e.map((o) => {
26
+ const c = t == null ? void 0 : t.template;
27
+ if (c)
28
+ return f(c, o);
29
+ });
30
+ }
31
+ }, F = (t, r) => {
32
+ let e = [];
33
+ for (const [n, o] of Object.entries(r)) {
34
+ const c = t == null ? void 0 : t.template;
35
+ if (c) {
36
+ const a = f(c, {
37
+ key: n,
38
+ value: o
39
+ });
40
+ e.push(a);
41
+ }
42
+ }
43
+ return e;
44
+ }, R = (t, r) => {
45
+ if ("source" in t && (t == null ? void 0 : t.source) in r) {
46
+ const e = r[t == null ? void 0 : t.source];
47
+ if (Array.isArray(e))
48
+ return e.map((o) => {
49
+ const c = t == null ? void 0 : t.template;
50
+ if (c)
51
+ return f(c, o);
52
+ });
53
+ }
54
+ }, D = (t, r) => {
55
+ if ("operation" in t) {
56
+ if (t.operation === "loopArray")
57
+ return x(t, r);
58
+ if (t.operation === "loopObject")
59
+ return F(t, r);
60
+ if (t.operation === "loopCollection")
61
+ return R(t, r);
62
+ }
63
+ }, A = (t, r) => {
64
+ if (typeof r == "string") return r;
65
+ if (typeof t != "string") return t;
66
+ if (t === "${value}")
67
+ return r.value;
68
+ const e = t.match(/^\$\{(.+?)\}$/);
69
+ if (e) {
70
+ const n = e[1];
71
+ return (r == null ? void 0 : r[n]) ?? "";
72
+ }
73
+ return t;
74
+ }, k = (t, r) => {
75
+ let e = {};
76
+ for (const [n, o] of Object.entries(t)) {
77
+ const c = A(o, r);
78
+ e[n] = c;
79
+ }
80
+ return e;
81
+ }, C = (t, r) => {
82
+ if ("tagName" in t) {
83
+ if ("textContent" in t) {
84
+ const e = A(t.textContent, r);
85
+ t.textContent = e;
86
+ }
87
+ if ("attributes" in t) {
88
+ const e = k(t.attributes, r);
89
+ t.attributes = e;
90
+ }
91
+ }
92
+ }, w = (t, r) => {
93
+ if (!t || typeof t != "object" || Array.isArray(t)) return null;
94
+ const e = structuredClone(t);
95
+ if (!e) return null;
96
+ if ("tagName" in e && C(e, r), "jsonToSpec" in e) {
97
+ const n = e == null ? void 0 : e.jsonToSpec, o = D(n, r);
98
+ Array.isArray(o) ? e.children = o : e.children = [o], delete e.jsonToSpec;
99
+ }
100
+ if (Array.isArray(e == null ? void 0 : e.children)) {
101
+ const n = b(e == null ? void 0 : e.children, r);
102
+ e.children = n;
103
+ }
104
+ return e;
105
+ }, f = (t, r) => t == null ? null : typeof Node < "u" && t instanceof Node ? t : Array.isArray(t) ? b(t, r) : typeof t == "object" ? w(t, r) : typeof t == "string" || typeof t == "number" ? document.createTextNode(String(t)) : t, y = (t, r) => f(t, r);
106
+ N({
107
+ inFuncDefinition: y
108
+ });
109
+ const V = {
110
+ default: {
111
+ tagName: "table",
112
+ attributes: {
113
+ class: "table table-hover table-striped mb-0"
114
+ },
115
+ children: [
116
+ {
117
+ tagName: "thead",
118
+ children: [
119
+ {
120
+ tagName: "tr",
121
+ jsonToSpec: {
122
+ operation: "loopCollection",
123
+ source: "columns",
124
+ template: {
125
+ tagName: "th",
126
+ textContent: "${title}"
127
+ }
128
+ },
129
+ children: []
130
+ }
131
+ ]
132
+ },
133
+ {
134
+ tagName: "tbody",
135
+ jsonToSpec: {
136
+ operation: "loopCollection",
137
+ source: "data",
138
+ template: {
139
+ tagName: "tr",
140
+ jsonToSpec: {
141
+ operation: "loopObject",
142
+ source: "data",
143
+ template: {
144
+ tagName: "td",
145
+ textContent: "${value}"
146
+ }
147
+ },
148
+ children: []
149
+ }
150
+ },
151
+ children: []
152
+ }
153
+ ]
154
+ }
155
+ }, I = ({
156
+ inColumns: t,
157
+ inData: r
158
+ } = {}) => {
159
+ const e = r ?? [], n = t;
160
+ return y(V.default, {
161
+ columns: n,
162
+ data: e
163
+ });
164
+ }, K = "select", B = {
165
+ id: "LedgerName"
166
+ }, M = {
167
+ operation: "loopArray",
168
+ source: "arrayOfStrings",
169
+ template: {
170
+ tagName: "option",
171
+ attributes: {
172
+ value: "${}"
173
+ },
174
+ textContent: "${}"
175
+ }
176
+ }, T = [], G = {
177
+ tagName: K,
178
+ attributes: B,
179
+ jsonToSpec: M,
180
+ children: T
181
+ }, z = ({
182
+ inData: t
183
+ } = {}) => y(G, {
184
+ arrayOfStrings: t ?? []
185
+ }), $ = ({ inItems: t, inRecipe: r, inExecute: e }) => {
186
+ const n = t, o = r, c = e;
187
+ return n.map((a) => d({
188
+ inSource: a,
189
+ inRecipe: o,
190
+ inExecute: c
191
+ })).flat(1 / 0).filter(Boolean);
192
+ }, L = ({ inSource: t, inRecipe: r, inExecute: e }) => {
193
+ const n = t, o = r, c = e;
194
+ let a = n;
195
+ typeof c == "function" && (a = c({
196
+ inSource: n,
197
+ inRecipe: o
198
+ }));
199
+ for (const [l, u] of Object.entries(a))
200
+ Array.isArray(u) && o && l in o && (a[l] = $({
201
+ inItems: u,
202
+ inRecipe: o[l],
203
+ inExecute: c
204
+ }));
205
+ return a;
206
+ }, d = ({ inSource: t, inRecipe: r, inExecute: e }) => {
207
+ const n = t, o = r, c = e;
208
+ return Array.isArray(n) ? $({
209
+ inItems: n,
210
+ inRecipe: o,
211
+ inExecute: c
212
+ }) : typeof n == "object" && n !== null ? L({
213
+ inSource: n,
214
+ inRecipe: o,
215
+ inExecute: c
216
+ }) : n;
217
+ }, P = ({ inKey: t, inDirective: r }) => {
218
+ const e = t, n = r;
219
+ return (n == null ? void 0 : n.alterKey) || e;
220
+ }, U = ({ inValue: t, inDirective: r, inExecute: e }) => {
221
+ const n = t, o = r, c = e;
222
+ return o && "transform" in o ? d({
223
+ inSource: n,
224
+ inRecipe: o,
225
+ inExecute: c
226
+ }) : n;
227
+ }, _ = ({ inValue: t, inDirective: r }) => {
228
+ const e = t, n = r;
229
+ return (n == null ? void 0 : n.valueType) === "array" && !Array.isArray(e) ? [e] : e;
230
+ }, q = ({ inValue: t, inDirective: r }) => {
231
+ const e = t, n = r;
232
+ return n != null && n.valueKey && e && typeof e == "object" ? e[n.valueKey] : e;
233
+ }, H = ({ inSource: t, inTransform: r, inExecute: e }) => {
234
+ const n = t, o = r, c = e, a = {};
235
+ for (const [l, u] of Object.entries(n)) {
236
+ if (!(l in o))
237
+ continue;
238
+ const i = o[l], h = P({ inKey: l, inDirective: i });
239
+ let s = u;
240
+ s = U({
241
+ inValue: s,
242
+ inDirective: i,
243
+ inExecute: c
244
+ }), s = _({ inValue: s, inDirective: i }), s = q({ inValue: s, inDirective: i }), a[h] = s;
245
+ }
246
+ return a;
247
+ };
248
+ function v(t, r) {
249
+ for (const e in t)
250
+ typeof t[e] == "object" && t[e] !== null ? v(t[e], r) : typeof t[e] == "string" && t[e] === "${}" && (t[e] = r);
251
+ return t;
252
+ }
253
+ const Q = ({ inSource: t, inOperation: r, inExecute: e }) => {
254
+ const n = t, o = r;
255
+ for (const [c, a] of Object.entries(o))
256
+ if ("operationType" in a && a.operationType === "loopArray" && c in n) {
257
+ const l = n[c].map((u) => {
258
+ const i = { ...a == null ? void 0 : a.template };
259
+ return v(i, u), i;
260
+ });
261
+ n[c] = l;
262
+ }
263
+ return n;
264
+ }, m = ({ inSource: t, inRecipe: r }) => {
265
+ let e = t;
266
+ const n = r;
267
+ return n && typeof n == "object" && "transform" in n && (e = H({
268
+ inSource: e,
269
+ inTransform: n.transform,
270
+ inExecute: m
271
+ })), n && typeof n == "object" && "operation" in n && (e = Q({
272
+ inSource: e,
273
+ inOperation: n.operation,
274
+ inExecute: m
275
+ })), e;
276
+ }, W = (t, r) => d({
277
+ inSource: t,
278
+ inRecipe: r,
279
+ inExecute: m
280
+ }), X = {
281
+ children: ""
282
+ }, Y = {
283
+ children: {
284
+ operationType: "loopArray",
285
+ template: {
286
+ tagName: "option",
287
+ attributes: {
288
+ value: "${}"
289
+ },
290
+ textContent: "${}"
291
+ }
292
+ }
293
+ }, Z = {
294
+ transform: X,
295
+ operation: Y
296
+ }, S = ({
297
+ inData: t
298
+ } = {}) => W({
299
+ Children: t ?? []
300
+ }, Z), p = {
301
+ table: I,
302
+ select: z,
303
+ selectOptionsOnly: S
304
+ }, J = ({
305
+ type: t = "table",
306
+ data: r,
307
+ columns: e
308
+ } = {}) => {
309
+ const n = t, o = p[n];
310
+ return o ? o({
311
+ inColumns: e,
312
+ inData: r
313
+ }) : (console.error(
314
+ `[Renderer] Unknown renderer type "${n}". Available types: ${Object.keys(p).join(", ")}`
315
+ ), null);
316
+ };
317
+ j(J);
318
+ export {
319
+ J as default
320
+ };