json-renderers 1.18.8 → 1.19.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/src/v16/index.js DELETED
@@ -1,106 +0,0 @@
1
- import registerGlobal from "./registerGlobal.js";
2
- import guardFunc from "./guard.js";
3
- import buildSpec from "./buildSpec/index.js";
4
-
5
- // Pure function: builds and validates the JSON configuration without touching DOM
6
- const getSpec = ({
7
- type = "table",
8
- targetHtmlId,
9
- data,
10
- columns,
11
- classToApply,
12
- appendPosition,
13
- showLog = false
14
- } = {}) => {
15
- const localType = type;
16
- const localTargetHtmlId = targetHtmlId;
17
- const localData = data;
18
- const localColumns = columns;
19
- const localClassToApply = classToApply;
20
- const localAppendPosition = appendPosition;
21
- const localShowLog = showLog;
22
-
23
- const specJson = {
24
- type: localType,
25
- targetHtmlId: localTargetHtmlId,
26
- data: localData,
27
- columns: localColumns,
28
- classToApply: localClassToApply,
29
- appendPosition: localAppendPosition,
30
- showLog: localShowLog
31
- };
32
-
33
- // Internal call using the in-convention
34
- guardFunc({ inConfig: specJson });
35
-
36
- return specJson;
37
- };
38
-
39
- // Render function: Public API accepting clean single options object
40
- const render = ({
41
- type = "table",
42
- targetHtmlId,
43
- data,
44
- columns,
45
- classToApply,
46
- appendPosition,
47
- showLog = false
48
- } = {}) => {
49
- // 1. Get and validate the clean JSON specification
50
- const specJson = getSpec({
51
- type,
52
- targetHtmlId,
53
- data,
54
- columns,
55
- classToApply,
56
- appendPosition,
57
- showLog
58
- });
59
-
60
- if (specJson.showLog) console.log("showLog 1 (spec):", specJson);
61
-
62
- // 2. Build DOM content via buildSpec
63
- const content = buildSpec({
64
- inTargetHtmlId: specJson.targetHtmlId,
65
- inColumns: specJson.columns,
66
- inData: specJson.data,
67
- inType: specJson.type,
68
- inShowLog: specJson.showLog
69
- });
70
-
71
- if (specJson.showLog) console.log("showLog 2 (content):", content);
72
-
73
- const container = document.getElementById(specJson.targetHtmlId);
74
- if (specJson.showLog) console.log("showLog 3 (container):", container);
75
-
76
- if (!container) return null;
77
-
78
- const isCollection = Array.isArray(content) ||
79
- content instanceof NodeList ||
80
- content instanceof HTMLCollection;
81
-
82
- if (isCollection) {
83
- if (specJson.appendPosition === "prepend") {
84
- container.prepend(...content);
85
- } else {
86
- container.append(...content);
87
- }
88
- } else {
89
- if (specJson.appendPosition === "prepend") {
90
- container.prepend(content);
91
- } else {
92
- container.innerHTML = "";
93
- container.append(content);
94
- }
95
- }
96
-
97
- if (specJson.showLog) console.log("showLog 4 (mounted):", container);
98
-
99
- return container;
100
- };
101
-
102
- registerGlobal({ render, getSpec });
103
-
104
- export { render, getSpec, buildSpec };
105
-
106
- export default render;
@@ -1,27 +0,0 @@
1
- import meta from "./meta.js";
2
-
3
- export const registerGlobal = (inDefinition) => {
4
- const localDefinition = inDefinition;
5
-
6
- if (typeof globalThis === "undefined" || !localDefinition) return;
7
-
8
- globalThis.ks ??= {};
9
-
10
- const renderFunc = typeof localDefinition === "function"
11
- ? localDefinition
12
- : localDefinition.render;
13
-
14
- const getSpecFunc = typeof localDefinition === "object"
15
- ? localDefinition.getSpec
16
- : undefined;
17
-
18
- globalThis.ks.jsonRenderers = {
19
- meta,
20
- renderToDom: renderFunc,
21
- render: renderFunc,
22
- ...(getSpecFunc ? { getSpec: getSpecFunc } : {}),
23
- ...(typeof localDefinition === "object" ? localDefinition : {})
24
- };
25
- };
26
-
27
- export default registerGlobal;