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