json-renderers 1.10.1 → 1.12.2

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,646 @@
1
+ const F = {
2
+ version: "v12.0.0",
3
+ description: "build table from store data and render to DOM uses json-to-spec, json-to-dom under the hood"
4
+ }, S = (t) => {
5
+ var e;
6
+ typeof globalThis > "u" || !t || (globalThis.ks ?? (globalThis.ks = {}), (e = globalThis.ks).jsonRenderers ?? (e.jsonRenderers = {
7
+ meta: F,
8
+ renderToDom: t
9
+ }));
10
+ }, D = {
11
+ version: "v32",
12
+ description: "JSON-to-DOM engine with centralized traversal and responsibility-focused construction"
13
+ }, G = ({ inFuncDefinition: t } = {}) => {
14
+ if (typeof globalThis > "u" || !t) return;
15
+ globalThis.ks ?? (globalThis.ks = {});
16
+ const e = {
17
+ meta: D,
18
+ buildSpecElement: t
19
+ };
20
+ globalThis.ks.jsonToSpec = e;
21
+ }, z = (t, e) => d(t, e), b = (t, e) => Array.isArray(t) ? t.map((l) => z(l, e)).flat(1 / 0).filter(Boolean) : [], I = (t, e) => {
22
+ if ("source" in t && (t == null ? void 0 : t.source) in e) {
23
+ const l = e[t == null ? void 0 : t.source];
24
+ if (Array.isArray(l))
25
+ return l.map((n) => {
26
+ const r = t == null ? void 0 : t.template;
27
+ if (r)
28
+ return d(r, n);
29
+ });
30
+ }
31
+ }, L = (t, e) => {
32
+ let l = [];
33
+ for (const [o, n] of Object.entries(e)) {
34
+ const r = t == null ? void 0 : t.template;
35
+ if (r) {
36
+ const a = d(r, {
37
+ key: o,
38
+ value: n
39
+ });
40
+ l.push(a);
41
+ }
42
+ }
43
+ return l;
44
+ }, R = (t, e) => {
45
+ if ("source" in t && (t == null ? void 0 : t.source) in e) {
46
+ const l = e[t == null ? void 0 : t.source];
47
+ if (Array.isArray(l))
48
+ return l.map((n) => {
49
+ const r = t == null ? void 0 : t.template;
50
+ if (r)
51
+ return d(r, n);
52
+ });
53
+ }
54
+ }, M = (t, e) => {
55
+ if ("operation" in t) {
56
+ if (t.operation === "loopArray")
57
+ return I(t, e);
58
+ if (t.operation === "loopObject")
59
+ return L(t, e);
60
+ if (t.operation === "loopCollection")
61
+ return R(t, e);
62
+ }
63
+ }, m = (t, e) => {
64
+ if (typeof e == "string") return e;
65
+ if (typeof t != "string") return t;
66
+ if (t === "${value}")
67
+ return e.value;
68
+ const l = t.match(/^\$\{(.+?)\}$/);
69
+ if (l) {
70
+ const o = l[1];
71
+ return (e == null ? void 0 : e[o]) ?? "";
72
+ }
73
+ return t;
74
+ }, V = (t, e) => {
75
+ let l = {};
76
+ for (const [o, n] of Object.entries(t)) {
77
+ const r = m(n, e);
78
+ l[o] = r;
79
+ }
80
+ return l;
81
+ }, q = (t, e) => {
82
+ if ("tagName" in t) {
83
+ if ("textContent" in t) {
84
+ const l = m(t.textContent, e);
85
+ t.textContent = l;
86
+ }
87
+ if ("attributes" in t) {
88
+ const l = V(t.attributes, e);
89
+ t.attributes = l;
90
+ }
91
+ }
92
+ }, P = (t, e) => {
93
+ if (!t || typeof t != "object" || Array.isArray(t)) return null;
94
+ const l = structuredClone(t);
95
+ if (!l) return null;
96
+ if ("tagName" in l && q(l, e), "jsonToSpec" in l) {
97
+ const o = l == null ? void 0 : l.jsonToSpec, n = M(o, e);
98
+ Array.isArray(n) ? l.children = n : l.children = [n], delete l.jsonToSpec;
99
+ }
100
+ if (Array.isArray(l == null ? void 0 : l.children)) {
101
+ const o = b(l == null ? void 0 : l.children, e);
102
+ l.children = o;
103
+ }
104
+ return l;
105
+ }, d = (t, e) => {
106
+ if (t == null) return null;
107
+ debugger;
108
+ return typeof Node < "u" && t instanceof Node ? t : Array.isArray(t) ? b(t, e) : typeof t == "object" ? P(t, e) : typeof t == "string" || typeof t == "number" ? document.createTextNode(String(t)) : t;
109
+ }, y = (t, e) => d(t, e);
110
+ G({
111
+ inFuncDefinition: y
112
+ });
113
+ const H = {
114
+ version: "v9",
115
+ description: "JSON-to-DOM engine with SVG namespace support, mixed text content, and centralized traversal"
116
+ }, B = ({ inFuncDefinition: t, inReviewSpec: e } = {}) => {
117
+ if (typeof globalThis > "u" || !t) return;
118
+ globalThis.ks ?? (globalThis.ks = {});
119
+ const l = {
120
+ meta: H,
121
+ buildSpecElement: t,
122
+ reviewSpec: e
123
+ };
124
+ globalThis.ks["json-to-tag"] = l, globalThis.ks.jsonToTag = l;
125
+ }, _ = (t) => t == null ? null : typeof Node < "u" && t instanceof Node ? t : typeof t == "string" || typeof t == "number" ? document.createTextNode(String(t)) : typeof t == "object" && (t.nodeType === 3 || t.tagName === "#text" || !t.tagName && (t.textContent !== void 0 || t.text !== void 0)) ? document.createTextNode(t.textContent ?? t.text ?? "") : T(t), p = (t) => Array.isArray(t) ? t.map(_).flat(1 / 0).filter(Boolean) : [], U = (t) => (t == null, t), K = "http://www.w3.org/2000/svg", X = /* @__PURE__ */ new Set([
126
+ "svg",
127
+ "path",
128
+ "symbol",
129
+ "use",
130
+ "g",
131
+ "circle",
132
+ "ellipse",
133
+ "rect",
134
+ "line",
135
+ "polyline",
136
+ "polygon",
137
+ "text",
138
+ "tspan",
139
+ "defs",
140
+ "clippath",
141
+ "mask",
142
+ "pattern",
143
+ "marker",
144
+ "lineargradient",
145
+ "radialgradient",
146
+ "stop",
147
+ "image",
148
+ "filter",
149
+ "fegaussianblur",
150
+ "femerge",
151
+ "femergenode"
152
+ ]), Q = ({ inTagName: t }) => {
153
+ const e = t == null ? void 0 : t.toLowerCase();
154
+ if (!e) return null;
155
+ if (e === "checkbox") {
156
+ const l = document.createElement("input");
157
+ return l.type = "checkbox", l;
158
+ }
159
+ return X.has(e) ? document.createElementNS(K, e) : document.createElement(e);
160
+ }, W = ({ inElement: t, inTextContent: e }) => (!t || e === void 0 || e === null || (t.textContent = e), t), Y = ({ inElement: t, inProperties: e }) => (t && e && typeof e == "object" && Object.assign(t, e), t), Z = "http://www.w3.org/1999/xlink", J = ({ inElement: t, inAttributes: e }) => {
161
+ const l = t, o = e;
162
+ if (!l || !o || typeof o != "object")
163
+ return l;
164
+ const n = typeof SVGElement < "u" ? l instanceof SVGElement : l.namespaceURI === "http://www.w3.org/2000/svg";
165
+ return Object.entries(o).forEach(([r, a]) => {
166
+ if (r === "class") {
167
+ n ? l.setAttribute("class", String(a)) : l.className = a;
168
+ return;
169
+ }
170
+ if (r === "xlink:href" || r === "href") {
171
+ if (a != null) {
172
+ const s = String(a);
173
+ if (n)
174
+ try {
175
+ l.setAttributeNS(Z, "href", s);
176
+ } catch {
177
+ }
178
+ l.setAttribute("href", s), l.setAttribute("xlink:href", s);
179
+ }
180
+ return;
181
+ }
182
+ if (typeof a == "boolean") {
183
+ a ? l.setAttribute(r, "") : l.removeAttribute(r);
184
+ return;
185
+ }
186
+ a != null && l.setAttribute(r, String(a));
187
+ }), l;
188
+ }, tt = ({ inElement: t, inClassList: e }) => {
189
+ if (!t || !e) return t;
190
+ const l = typeof e == "string" ? e.split(/\s+/).filter(Boolean) : Array.isArray(e) ? e.filter((o) => typeof o == "string" && o.trim()) : [];
191
+ return l.length && t.classList.add(...l), t;
192
+ }, et = (t) => {
193
+ if (!t || typeof t != "object" || Array.isArray(t) || !t.tagName) return null;
194
+ const e = Q({ inTagName: t.tagName });
195
+ if (!e) return null;
196
+ if (W({
197
+ inElement: e,
198
+ inTextContent: U(t.textContent),
199
+ inTagName: t.tagName
200
+ }), Y({
201
+ inElement: e,
202
+ inProperties: t.properties
203
+ }), J({
204
+ inElement: e,
205
+ inAttributes: t.attributes
206
+ }), tt({
207
+ inElement: e,
208
+ inClassList: t.classList
209
+ }), Array.isArray(t.children)) {
210
+ const l = p(t.children);
211
+ l.length && e.append(...l);
212
+ }
213
+ return e;
214
+ }, T = (t) => t == null ? null : typeof Node < "u" && t instanceof Node ? t : Array.isArray(t) ? p(t) : typeof t == "object" ? et(t) : typeof t == "string" || typeof t == "number" ? document.createTextNode(String(t)) : null, lt = "./tags.schema.json", rt = {
215
+ allowsTextContent: !1,
216
+ allowsChildren: !0,
217
+ allowedAttributes: [
218
+ "title",
219
+ "role"
220
+ ],
221
+ childTags: []
222
+ }, ot = {
223
+ allowsTextContent: !1,
224
+ allowsChildren: !1,
225
+ allowedAttributes: [
226
+ "type",
227
+ "placeholder",
228
+ "value",
229
+ "name",
230
+ "disabled",
231
+ "readonly",
232
+ "required",
233
+ "list"
234
+ ]
235
+ }, nt = {
236
+ allowsTextContent: !1,
237
+ allowsChildren: !1,
238
+ allowedAttributes: [
239
+ "type",
240
+ "checked",
241
+ "name",
242
+ "value",
243
+ "disabled",
244
+ "required"
245
+ ]
246
+ }, at = {
247
+ allowsTextContent: !1,
248
+ allowsChildren: !0,
249
+ allowedAttributes: [
250
+ "span"
251
+ ],
252
+ childTags: [
253
+ "col"
254
+ ]
255
+ }, st = {
256
+ allowsTextContent: !1,
257
+ allowsChildren: !1,
258
+ allowedAttributes: [
259
+ "span",
260
+ "style",
261
+ "width"
262
+ ]
263
+ }, it = {
264
+ allowsTextContent: !0,
265
+ allowsChildren: !0,
266
+ allowedAttributes: [
267
+ "for"
268
+ ],
269
+ childTags: []
270
+ }, ut = {
271
+ allowsTextContent: !1,
272
+ allowsChildren: !0,
273
+ allowedAttributes: [
274
+ "action",
275
+ "method",
276
+ "autocomplete",
277
+ "enctype",
278
+ "name",
279
+ "novalidate",
280
+ "target"
281
+ ],
282
+ childTags: []
283
+ }, ct = {
284
+ allowsTextContent: !1,
285
+ allowsChildren: !0,
286
+ allowedAttributes: [
287
+ "name",
288
+ "disabled",
289
+ "required",
290
+ "multiple",
291
+ "size"
292
+ ],
293
+ childTags: [
294
+ "option"
295
+ ]
296
+ }, dt = {
297
+ allowsTextContent: !0,
298
+ allowsChildren: !0,
299
+ allowedAttributes: [],
300
+ childTags: []
301
+ }, ft = {
302
+ allowsTextContent: !0,
303
+ allowsChildren: !0,
304
+ allowedAttributes: [],
305
+ childTags: []
306
+ }, ht = {
307
+ allowsTextContent: !0,
308
+ allowsChildren: !0,
309
+ allowedAttributes: [],
310
+ childTags: []
311
+ }, gt = {
312
+ allowsTextContent: !0,
313
+ allowsChildren: !0,
314
+ allowedAttributes: [],
315
+ childTags: []
316
+ }, wt = {
317
+ allowsTextContent: !1,
318
+ allowsChildren: !1,
319
+ allowedAttributes: [
320
+ "src",
321
+ "alt",
322
+ "width",
323
+ "height",
324
+ "loading"
325
+ ]
326
+ }, bt = {
327
+ allowsTextContent: !0,
328
+ allowsChildren: !0,
329
+ allowedAttributes: [
330
+ "type",
331
+ "disabled",
332
+ "name",
333
+ "value"
334
+ ],
335
+ childTags: []
336
+ }, mt = {
337
+ allowsTextContent: !1,
338
+ allowsChildren: !0,
339
+ allowedAttributes: [
340
+ "border",
341
+ "cellpadding",
342
+ "cellspacing"
343
+ ],
344
+ childTags: [
345
+ "caption",
346
+ "colgroup",
347
+ "thead",
348
+ "tbody",
349
+ "tfoot",
350
+ "tr"
351
+ ]
352
+ }, yt = {
353
+ allowsTextContent: !1,
354
+ allowsChildren: !0,
355
+ allowedAttributes: [],
356
+ childTags: [
357
+ "tr"
358
+ ]
359
+ }, pt = {
360
+ allowsTextContent: !1,
361
+ allowsChildren: !0,
362
+ allowedAttributes: [],
363
+ childTags: [
364
+ "tr"
365
+ ]
366
+ }, Tt = {
367
+ allowsTextContent: !1,
368
+ allowsChildren: !0,
369
+ allowedAttributes: [],
370
+ childTags: [
371
+ "tr"
372
+ ]
373
+ }, Ct = {
374
+ allowsTextContent: !1,
375
+ allowsChildren: !0,
376
+ allowedAttributes: [],
377
+ childTags: [
378
+ "td",
379
+ "th"
380
+ ]
381
+ }, At = {
382
+ allowsTextContent: !0,
383
+ allowsChildren: !0,
384
+ allowedAttributes: [
385
+ "scope",
386
+ "colspan",
387
+ "rowspan"
388
+ ],
389
+ childTags: []
390
+ }, xt = {
391
+ allowsTextContent: !0,
392
+ allowsChildren: !0,
393
+ allowedAttributes: [
394
+ "colspan",
395
+ "rowspan"
396
+ ],
397
+ childTags: []
398
+ }, vt = {
399
+ allowsTextContent: !1,
400
+ allowsChildren: !0,
401
+ allowedAttributes: [],
402
+ childTags: [
403
+ "option"
404
+ ]
405
+ }, jt = {
406
+ allowsTextContent: !0,
407
+ allowsChildren: !1,
408
+ allowedAttributes: [
409
+ "value",
410
+ "label",
411
+ "selected",
412
+ "disabled"
413
+ ]
414
+ }, Nt = {
415
+ allowsTextContent: !1,
416
+ allowsChildren: !0,
417
+ allowedAttributes: [
418
+ "role"
419
+ ],
420
+ childTags: []
421
+ }, kt = {
422
+ allowsTextContent: !0,
423
+ allowsChildren: !0,
424
+ allowedAttributes: [
425
+ "href",
426
+ "target",
427
+ "rel",
428
+ "title",
429
+ "download"
430
+ ],
431
+ childTags: []
432
+ }, $t = {
433
+ allowsTextContent: !0,
434
+ allowsChildren: !0,
435
+ allowedAttributes: [
436
+ "aria-hidden"
437
+ ],
438
+ childTags: []
439
+ }, Et = {
440
+ allowsTextContent: !0,
441
+ allowsChildren: !0,
442
+ allowedAttributes: [],
443
+ childTags: []
444
+ }, Ot = {
445
+ allowsTextContent: !1,
446
+ allowsChildren: !0,
447
+ allowedAttributes: [
448
+ "type"
449
+ ],
450
+ childTags: [
451
+ "li"
452
+ ]
453
+ }, Ft = {
454
+ allowsTextContent: !0,
455
+ allowsChildren: !0,
456
+ allowedAttributes: [
457
+ "value"
458
+ ],
459
+ childTags: []
460
+ }, St = {
461
+ allowsTextContent: !1,
462
+ allowsChildren: !1,
463
+ allowedAttributes: []
464
+ }, Dt = {
465
+ $schema: lt,
466
+ div: rt,
467
+ input: ot,
468
+ checkbox: nt,
469
+ colgroup: at,
470
+ col: st,
471
+ label: it,
472
+ form: ut,
473
+ select: ct,
474
+ p: dt,
475
+ h1: ft,
476
+ h2: ht,
477
+ span: gt,
478
+ img: wt,
479
+ button: bt,
480
+ table: mt,
481
+ thead: yt,
482
+ tbody: pt,
483
+ tfoot: Tt,
484
+ tr: Ct,
485
+ th: At,
486
+ td: xt,
487
+ datalist: vt,
488
+ option: jt,
489
+ header: Nt,
490
+ a: kt,
491
+ i: $t,
492
+ small: Et,
493
+ ul: Ot,
494
+ li: Ft,
495
+ hr: St
496
+ }, h = ({ inSpec: t }) => {
497
+ const e = t;
498
+ if (!e) return [];
499
+ if (Array.isArray(e))
500
+ return e.flatMap((o) => h({ inSpec: o }));
501
+ if (typeof e != "object") return [];
502
+ const l = [];
503
+ return typeof e.tagName == "string" && e.tagName.trim().length > 0 && l.push(e.tagName.toLowerCase()), Array.isArray(e.children) && e.children.length > 0 && e.children.forEach((o) => {
504
+ const n = h({ inSpec: o });
505
+ l.push(...n);
506
+ }), l;
507
+ }, Gt = ({ inTagsFound: t, inAllowedTags: e }) => {
508
+ const l = t ?? [], o = e ?? {}, n = new Set(
509
+ Object.keys(o).filter((i) => i !== "$schema").map((i) => i.toLowerCase())
510
+ ), r = {}, a = [], s = [];
511
+ l.forEach((i) => {
512
+ r[i] = (r[i] || 0) + 1, n.has(i) ? a.includes(i) || a.push(i) : s.includes(i) || s.push(i);
513
+ });
514
+ const u = l.length, c = s.length === 0;
515
+ return {
516
+ totalTags: u,
517
+ tagCounts: r,
518
+ uniqueTags: Object.keys(r),
519
+ recognizedTags: a,
520
+ unrecognizedTags: s,
521
+ areAllTagsPresent: c
522
+ };
523
+ }, zt = ({ inSpec: t, inTags: e = Dt } = {}) => {
524
+ const l = t, o = e, n = h({ inSpec: l }), r = Gt({
525
+ inTagsFound: n,
526
+ inAllowedTags: o
527
+ });
528
+ return {
529
+ areAllTagsPresent: r.areAllTagsPresent,
530
+ totalTags: r.totalTags,
531
+ tagCounts: r.tagCounts,
532
+ uniqueTags: r.uniqueTags,
533
+ recognizedTags: r.recognizedTags,
534
+ unrecognizedTags: r.unrecognizedTags
535
+ };
536
+ }, C = (t = {}) => {
537
+ const e = (t == null ? void 0 : t.spec) ?? (t == null ? void 0 : t.inSpec) ?? t;
538
+ return T(e);
539
+ };
540
+ B({
541
+ inFuncDefinition: C,
542
+ inReviewSpec: zt
543
+ });
544
+ const It = {
545
+ default: {
546
+ tagName: "table",
547
+ attributes: {
548
+ class: "table table-hover table-striped mb-0"
549
+ },
550
+ children: [
551
+ {
552
+ tagName: "thead",
553
+ children: [
554
+ {
555
+ tagName: "tr",
556
+ jsonToSpec: {
557
+ operation: "loopCollection",
558
+ source: "columns",
559
+ template: {
560
+ tagName: "th",
561
+ textContent: "${title}"
562
+ }
563
+ },
564
+ children: []
565
+ }
566
+ ]
567
+ },
568
+ {
569
+ tagName: "tbody",
570
+ jsonToSpec: {
571
+ operation: "loopCollection",
572
+ source: "data",
573
+ template: {
574
+ tagName: "tr",
575
+ jsonToSpec: {
576
+ operation: "loopObject",
577
+ source: "data",
578
+ template: {
579
+ tagName: "td",
580
+ textContent: "${value}"
581
+ }
582
+ },
583
+ children: []
584
+ }
585
+ },
586
+ children: []
587
+ }
588
+ ]
589
+ }
590
+ }, Lt = ({
591
+ targetHtmlId: t,
592
+ inTargetHtmlId: e,
593
+ inColumns: l,
594
+ inData: o
595
+ } = {}) => {
596
+ const n = e ?? t, r = o ?? [], a = l;
597
+ let s = y(It.default, {
598
+ columns: a,
599
+ data: r
600
+ });
601
+ "tagName" in s || (s = s.children);
602
+ const u = document.getElementById(n);
603
+ u && (u.innerHTML = "");
604
+ const c = C(s);
605
+ u.append(c);
606
+ }, w = {
607
+ table: Lt
608
+ }, Rt = ({
609
+ type: t = "table",
610
+ targetHtmlId: e,
611
+ data: l,
612
+ classToApply: o,
613
+ inTargetHtmlId: n,
614
+ inData: r,
615
+ columns: a,
616
+ inColumns: s,
617
+ colGroup: u,
618
+ inColGroup: c,
619
+ footerData: i,
620
+ inFooterData: A,
621
+ config: x,
622
+ inConfig: v,
623
+ variant: j,
624
+ skeletonType: N,
625
+ inSkeletonType: k,
626
+ showLog: $ = !1,
627
+ inShowLog: E
628
+ } = {}) => {
629
+ const f = t, O = typeof f == "string" ? f.toLowerCase() : "table", g = w[O];
630
+ return g ? g({
631
+ targetHtmlId: n ?? e,
632
+ inColumns: s ?? a,
633
+ inData: r ?? l,
634
+ inColGroup: c ?? u,
635
+ inFooterData: A ?? i ?? [],
636
+ inConfig: v ?? x ?? {},
637
+ inSkeletonType: k ?? N ?? j ?? "default",
638
+ inShowLog: E ?? $ ?? !1
639
+ }) : (console.error(
640
+ `[Renderer] Unknown renderer type "${f}". Available types: ${Object.keys(w).join(", ")}`
641
+ ), null);
642
+ };
643
+ S(Rt);
644
+ export {
645
+ Rt as default
646
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-renderers",
3
- "version": "1.10.1",
3
+ "version": "1.12.2",
4
4
  "description": "Standalone, config-driven Table renderer built on top of json-to-dom",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -29,7 +29,7 @@
29
29
  "vite": "^5.4.2"
30
30
  },
31
31
  "dependencies": {
32
- "@keshavsoft/json-to-tag": "^1.9.2",
33
- "json-to-spec": "^32.1.1"
32
+ "@keshavsoft/json-to-tag": "^1.9.3",
33
+ "json-to-spec": "^32.1.2"
34
34
  }
35
35
  }
package/src/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./v10/index.js";
2
- export { default } from "./v10/index.js";
1
+ export * from "./v12/index.js";
2
+ export { default } from "./v12/index.js";
@@ -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 @@
1
+ {}