json-renderers 1.16.1 → 1.17.7
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/README.md +6 -1
- package/docs/dist/min.js +716 -1179
- package/docs/dist/v16/min.js +1576 -0
- package/docs/dist/v17/min.js +1047 -0
- package/package.json +2 -2
- package/src/index.js +2 -2
- package/src/v16/buildSpec/index.js +40 -40
- package/src/v16/common/deriveColumnsFromData.js +20 -20
- package/src/v16/guard.js +38 -38
- package/src/v16/index.js +106 -110
- package/src/v16/meta.js +6 -6
- package/src/v16/registerGlobal.js +27 -27
- package/src/v17/buildSpec/index.js +25 -0
- package/src/v17/configSpec.json +9 -0
- package/src/v17/getSpec.js +12 -0
- package/src/v17/guard.js +41 -0
- package/src/v17/index.js +32 -0
- package/src/{v11 → v17}/meta.js +1 -1
- package/src/v17/registerGlobal.js +28 -0
- package/src/v17/renderToDom/index.js +47 -0
- package/src/v17/validateConfig.js +37 -0
- package/src/v11/dataLists/fragments.json +0 -1
- package/src/v11/dataLists/index.js +0 -32
- package/src/v11/dataLists/skeleton.json +0 -38
- package/src/v11/index.js +0 -62
- package/src/v11/registerGlobal.js +0 -14
- package/src/v11/select/fragments.json +0 -1
- package/src/v11/select/index.js +0 -34
- package/src/v11/select/skeleton.json +0 -23
- package/src/v11/table/index.js +0 -35
- package/src/v11/table/skeleton.json +0 -47
- package/src/v12/common/deriveColumnsFromData.js +0 -20
- package/src/v12/index.js +0 -62
- package/src/v12/meta.js +0 -6
- package/src/v12/registerGlobal.js +0 -14
- package/src/v12/table/index.js +0 -35
- package/src/v12/table/skeleton.json +0 -47
- package/src/v13/buildSpec/index.js +0 -39
- package/src/v13/common/deriveColumnsFromData.js +0 -20
- package/src/v13/index.js +0 -81
- package/src/v13/meta.js +0 -6
- package/src/v13/registerGlobal.js +0 -14
- /package/src/{v11 → v17}/common/deriveColumnsFromData.js +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-renderers",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.7",
|
|
4
4
|
"description": "Browser DOM component renderer built on top of json-renderers-build and @keshavsoft/json-to-tag",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -41,6 +41,6 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@keshavsoft/json-to-tag": "^1.9.3",
|
|
44
|
-
"json-renderers-build": "^1.
|
|
44
|
+
"json-renderers-build": "^1.20.1"
|
|
45
45
|
}
|
|
46
46
|
}
|
package/src/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export { default } from "./
|
|
1
|
+
export * from "./v17/index.js";
|
|
2
|
+
export { default } from "./v17/index.js";
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import jsonRenderBuild from "json-renderers-build";
|
|
2
|
-
import jsonToTag from "@keshavsoft/json-to-tag";
|
|
3
|
-
|
|
4
|
-
// --- Story of Table Render ---
|
|
5
|
-
const startFunc = ({
|
|
6
|
-
inTargetHtmlId,
|
|
7
|
-
inColumns,
|
|
8
|
-
inType = "table",
|
|
9
|
-
inData,
|
|
10
|
-
inShowLog = false
|
|
11
|
-
} = {}) => {
|
|
12
|
-
const localTargetHtmlId = inTargetHtmlId;
|
|
13
|
-
const localData = inData ?? [];
|
|
14
|
-
const localColumns = inColumns;
|
|
15
|
-
const localType = inType;
|
|
16
|
-
const localShowLog = inShowLog;
|
|
17
|
-
|
|
18
|
-
if (localShowLog) console.log("buildSpec 1 :", localTargetHtmlId, localData, localColumns);
|
|
19
|
-
|
|
20
|
-
let specAsJsonToDom = jsonRenderBuild({
|
|
21
|
-
type: localType,
|
|
22
|
-
targetHtmlId: localTargetHtmlId,
|
|
23
|
-
data: localData,
|
|
24
|
-
columns: localColumns
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
let jsonToSend = specAsJsonToDom;
|
|
28
|
-
|
|
29
|
-
const content = jsonToTag(jsonToSend);
|
|
30
|
-
|
|
31
|
-
if (localShowLog) {
|
|
32
|
-
console.log("buildSpec 2 :", jsonToSend, content);
|
|
33
|
-
console.log("buildSpec 3 :", content);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return content;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export { startFunc };
|
|
40
|
-
export default startFunc;
|
|
1
|
+
import jsonRenderBuild from "json-renderers-build";
|
|
2
|
+
import jsonToTag from "@keshavsoft/json-to-tag";
|
|
3
|
+
|
|
4
|
+
// --- Story of Table Render ---
|
|
5
|
+
const startFunc = ({
|
|
6
|
+
inTargetHtmlId,
|
|
7
|
+
inColumns,
|
|
8
|
+
inType = "table",
|
|
9
|
+
inData,
|
|
10
|
+
inShowLog = false
|
|
11
|
+
} = {}) => {
|
|
12
|
+
const localTargetHtmlId = inTargetHtmlId;
|
|
13
|
+
const localData = inData ?? [];
|
|
14
|
+
const localColumns = inColumns;
|
|
15
|
+
const localType = inType;
|
|
16
|
+
const localShowLog = inShowLog;
|
|
17
|
+
|
|
18
|
+
if (localShowLog) console.log("buildSpec 1 :", localTargetHtmlId, localData, localColumns);
|
|
19
|
+
|
|
20
|
+
let specAsJsonToDom = jsonRenderBuild({
|
|
21
|
+
type: localType,
|
|
22
|
+
targetHtmlId: localTargetHtmlId,
|
|
23
|
+
data: localData,
|
|
24
|
+
columns: localColumns
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
let jsonToSend = specAsJsonToDom;
|
|
28
|
+
|
|
29
|
+
const content = jsonToTag(jsonToSend);
|
|
30
|
+
|
|
31
|
+
if (localShowLog) {
|
|
32
|
+
console.log("buildSpec 2 :", jsonToSend, content);
|
|
33
|
+
console.log("buildSpec 3 :", content);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return content;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { startFunc };
|
|
40
|
+
export default startFunc;
|
|
@@ -1,20 +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;
|
|
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;
|
package/src/v16/guard.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
const guardFunc = ({ inConfig } = {}) => {
|
|
2
|
-
const localConfig = inConfig;
|
|
3
|
-
|
|
4
|
-
if (!localConfig || typeof localConfig !== "object") {
|
|
5
|
-
console.error("Config must be an object");
|
|
6
|
-
throw new TypeError("Config must be an object");
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
if (localConfig
|
|
10
|
-
console.error("type must be
|
|
11
|
-
throw new Error("type must be
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (!Array.isArray(localConfig.data)) {
|
|
15
|
-
console.error("data must be an Array");
|
|
16
|
-
throw new TypeError("data must be an Array");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (typeof localConfig.targetHtmlId !== "string" || !localConfig.targetHtmlId.trim()) {
|
|
20
|
-
console.error("targetHtmlId must be a non-empty string");
|
|
21
|
-
throw new TypeError("targetHtmlId must be a non-empty string");
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (!Array.isArray(localConfig.columns)) {
|
|
25
|
-
console.error("columns must be an array");
|
|
26
|
-
throw new TypeError("columns must be an array");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (localConfig.showLog !== undefined && typeof localConfig.showLog !== "boolean") {
|
|
30
|
-
console.error("showLog must be a boolean");
|
|
31
|
-
throw new TypeError("showLog must be a boolean");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return true;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export { guardFunc };
|
|
38
|
-
export default guardFunc;
|
|
1
|
+
const guardFunc = ({ inConfig } = {}) => {
|
|
2
|
+
const localConfig = inConfig;
|
|
3
|
+
|
|
4
|
+
if (!localConfig || typeof localConfig !== "object") {
|
|
5
|
+
console.error("Config must be an object");
|
|
6
|
+
throw new TypeError("Config must be an object");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (typeof localConfig?.type !== "string") {
|
|
10
|
+
console.error("type must be string only");
|
|
11
|
+
throw new Error("type must be string only");
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
if (!Array.isArray(localConfig.data)) {
|
|
15
|
+
console.error("data must be an Array");
|
|
16
|
+
throw new TypeError("data must be an Array");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (typeof localConfig.targetHtmlId !== "string" || !localConfig.targetHtmlId.trim()) {
|
|
20
|
+
console.error("targetHtmlId must be a non-empty string");
|
|
21
|
+
throw new TypeError("targetHtmlId must be a non-empty string");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!Array.isArray(localConfig.columns)) {
|
|
25
|
+
console.error("columns must be an array");
|
|
26
|
+
throw new TypeError("columns must be an array");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (localConfig.showLog !== undefined && typeof localConfig.showLog !== "boolean") {
|
|
30
|
+
console.error("showLog must be a boolean");
|
|
31
|
+
throw new TypeError("showLog must be a boolean");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return true;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { guardFunc };
|
|
38
|
+
export default guardFunc;
|
package/src/v16/index.js
CHANGED
|
@@ -1,110 +1,106 @@
|
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
export { render, getSpec, guardFunc, buildSpec };
|
|
108
|
-
|
|
109
|
-
// 2. As a single function (default export)
|
|
110
|
-
export default render;
|
|
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;
|
package/src/v16/meta.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export const meta = {
|
|
2
|
-
version: "v16.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;
|
|
1
|
+
export const meta = {
|
|
2
|
+
version: "v16.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;
|
|
@@ -1,27 +1,27 @@
|
|
|
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;
|
|
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;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import jsonRenderBuild from "json-renderers-build";
|
|
2
|
+
|
|
3
|
+
// --- Story of Spec Build ---
|
|
4
|
+
const startFunc = ({
|
|
5
|
+
inColumns,
|
|
6
|
+
inType = "table",
|
|
7
|
+
inData,
|
|
8
|
+
inShowLog = false
|
|
9
|
+
} = {}) => {
|
|
10
|
+
const localData = inData ?? [];
|
|
11
|
+
const localColumns = inColumns;
|
|
12
|
+
const localType = inType;
|
|
13
|
+
const localShowLog = inShowLog;
|
|
14
|
+
|
|
15
|
+
const specAsJsonToDom = jsonRenderBuild({
|
|
16
|
+
type: localType,
|
|
17
|
+
data: localData,
|
|
18
|
+
columns: localColumns,
|
|
19
|
+
showLog: localShowLog
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return specAsJsonToDom;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default startFunc;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import spec from "./configSpec.json" with { type: "json" };
|
|
2
|
+
|
|
3
|
+
// Returns the specification object when called
|
|
4
|
+
const getSpec = () => {
|
|
5
|
+
return { ...spec };
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// Also attach properties directly to getSpec so it functions as both an object and a callable function
|
|
9
|
+
Object.assign(getSpec, spec);
|
|
10
|
+
|
|
11
|
+
export { getSpec, spec };
|
|
12
|
+
export default getSpec;
|
package/src/v17/guard.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import spec from "./configSpec.json" with { type: "json" };
|
|
2
|
+
|
|
3
|
+
const guardFunc = ({ inConfig } = {}) => {
|
|
4
|
+
const localConfig = inConfig;
|
|
5
|
+
|
|
6
|
+
if (!localConfig || typeof localConfig !== "object") {
|
|
7
|
+
console.error("Config must be an object");
|
|
8
|
+
throw new TypeError("Config must be an object");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Dynamic schema validation against spec.json keys and types
|
|
12
|
+
for (const key of Object.keys(spec)) {
|
|
13
|
+
// 1. All keys are compulsory
|
|
14
|
+
if (!(key in localConfig) || localConfig[key] === undefined) {
|
|
15
|
+
console.error(`Missing compulsory key: "${key}"`);
|
|
16
|
+
throw new Error(`Missing compulsory key: "${key}"`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 2. Type validation derived from spec.json
|
|
20
|
+
if (Array.isArray(spec[key])) {
|
|
21
|
+
if (!Array.isArray(localConfig[key])) {
|
|
22
|
+
console.error(`${key} must be an Array`);
|
|
23
|
+
throw new TypeError(`${key} must be an Array`);
|
|
24
|
+
}
|
|
25
|
+
} else if (typeof localConfig[key] !== typeof spec[key]) {
|
|
26
|
+
console.error(`${key} must be of type ${typeof spec[key]}`);
|
|
27
|
+
throw new TypeError(`${key} must be of type ${typeof spec[key]}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Specific business rule: targetHtmlId must be a non-empty string
|
|
32
|
+
if (typeof localConfig.targetHtmlId === "string" && !localConfig.targetHtmlId.trim()) {
|
|
33
|
+
console.error("targetHtmlId must be a non-empty string");
|
|
34
|
+
throw new TypeError("targetHtmlId must be a non-empty string");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return true;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { guardFunc };
|
|
41
|
+
export default guardFunc;
|
package/src/v17/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import registerGlobal from "./registerGlobal.js";
|
|
2
|
+
import validateConfig from "./validateConfig.js";
|
|
3
|
+
import getSpec from "./getSpec.js";
|
|
4
|
+
import buildSpec from "./buildSpec/index.js";
|
|
5
|
+
import renderToDom from "./renderToDom/index.js";
|
|
6
|
+
|
|
7
|
+
// Main orchestrator: coordinates validation, spec building, and DOM rendering
|
|
8
|
+
const render = (options = {}) => {
|
|
9
|
+
const config = validateConfig(options);
|
|
10
|
+
const showLog = config?.showLog;
|
|
11
|
+
|
|
12
|
+
if (showLog) console.log("first : ", config?.columns, config?.data, config?.appendPosition);
|
|
13
|
+
|
|
14
|
+
const spec = buildSpec({
|
|
15
|
+
inColumns: config.columns,
|
|
16
|
+
inData: config.data,
|
|
17
|
+
inType: config.type,
|
|
18
|
+
inShowLog: config.showLog
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return renderToDom({
|
|
22
|
+
inSpec: spec,
|
|
23
|
+
inTargetHtmlId: config.targetHtmlId,
|
|
24
|
+
inAppendPosition: config.appendPosition,
|
|
25
|
+
inShowLog: config.showLog
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
registerGlobal({ render, getSpec, validateConfig, buildSpec, renderToDom });
|
|
30
|
+
|
|
31
|
+
export { render, getSpec, validateConfig, buildSpec, renderToDom };
|
|
32
|
+
export default render;
|
package/src/{v11 → v17}/meta.js
RENAMED
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
...(typeof localDefinition === "object" ? localDefinition : {}),
|
|
21
|
+
render: renderFunc,
|
|
22
|
+
renderToDom: renderFunc,
|
|
23
|
+
domMount: localDefinition?.renderToDom,
|
|
24
|
+
...(getSpecFunc ? { getSpec: getSpecFunc } : {})
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default registerGlobal;
|