json-renderers 1.19.1 → 1.20.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 +508 -503
- package/docs/dist/v18/min.js +2049 -2049
- package/docs/dist/v19/min.js +2054 -2054
- package/docs/dist/v20/min.js +2059 -0
- package/docs/samples/datalist/windowks.html +350 -350
- package/docs/samples/select/windowks.html +358 -358
- package/package.json +2 -1
- package/src/index.js +2 -2
- package/src/v20/buildSpec/index.js +28 -0
- package/src/v20/common/deriveColumnsFromData.js +20 -0
- package/src/v20/index.js +41 -0
- package/src/v20/meta.js +6 -0
- package/src/v20/registerGlobal.js +16 -0
- package/src/v20/renderToDom/index.js +47 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-renderers",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.1",
|
|
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",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"vite": "^5.4.2"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
+
"@keshavsoft/json-to-dom": "^1.41.5",
|
|
43
44
|
"@keshavsoft/json-to-tag": "^1.10.3",
|
|
44
45
|
"json-renderers-build": "^1.26.1",
|
|
45
46
|
"json-renderers-guard": "^1.5.3"
|
package/src/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export { default } from "./
|
|
1
|
+
export * from "./v20/index.js";
|
|
2
|
+
export { default } from "./v20/index.js";
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
inOptions
|
|
10
|
+
} = {}) => {
|
|
11
|
+
const localData = inData ?? [];
|
|
12
|
+
const localColumns = inColumns;
|
|
13
|
+
const localType = inType;
|
|
14
|
+
const localShowLog = inShowLog;
|
|
15
|
+
const localOptions = inOptions;
|
|
16
|
+
|
|
17
|
+
const specAsJsonToDom = jsonRenderBuild({
|
|
18
|
+
type: localType,
|
|
19
|
+
data: localData,
|
|
20
|
+
columns: localColumns,
|
|
21
|
+
showLog: localShowLog,
|
|
22
|
+
options: localOptions
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return specAsJsonToDom;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default startFunc;
|
|
@@ -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;
|
package/src/v20/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import registerGlobal from "./registerGlobal.js";
|
|
2
|
+
|
|
3
|
+
import guardFunc from "json-renderers-guard";
|
|
4
|
+
import jsonToTag from "@keshavsoft/json-to-tag";
|
|
5
|
+
import jsonToDom from "@keshavsoft/json-to-dom";
|
|
6
|
+
|
|
7
|
+
import buildSpec from "./buildSpec/index.js";
|
|
8
|
+
import renderToDom from "./renderToDom/index.js";
|
|
9
|
+
|
|
10
|
+
// Main orchestrator: coordinates validation, spec building, and DOM rendering
|
|
11
|
+
const render = (config = {}) => {
|
|
12
|
+
guardFunc(config);
|
|
13
|
+
const showLog = config?.showLog;
|
|
14
|
+
const localOptions = config?.options;
|
|
15
|
+
|
|
16
|
+
if (showLog) console.log("first : ", config?.options, config?.columns, config?.data, config?.appendPosition);
|
|
17
|
+
|
|
18
|
+
const spec = buildSpec({
|
|
19
|
+
inColumns: config.columns,
|
|
20
|
+
inData: config.data,
|
|
21
|
+
inType: config.type,
|
|
22
|
+
inShowLog: config.showLog,
|
|
23
|
+
inOptions: localOptions
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const builtSpec = jsonToTag(spec);
|
|
27
|
+
|
|
28
|
+
const dom = jsonToDom({
|
|
29
|
+
buildSpec: builtSpec,
|
|
30
|
+
targetHtmlId: config.targetHtmlId,
|
|
31
|
+
appendPosition: config.appendPosition,
|
|
32
|
+
showLog: config.showLog
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return dom;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
registerGlobal(render);
|
|
39
|
+
|
|
40
|
+
export { render };
|
|
41
|
+
export default render;
|
package/src/v20/meta.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
globalThis.ks.jsonRenderers = {
|
|
11
|
+
meta,
|
|
12
|
+
render: localDefinition
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default registerGlobal;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import jsonToTag from "@keshavsoft/json-to-tag";
|
|
2
|
+
|
|
3
|
+
// --- Story of DOM Rendering and Mounting ---
|
|
4
|
+
const renderToDom = ({
|
|
5
|
+
inSpec,
|
|
6
|
+
inTargetHtmlId,
|
|
7
|
+
inAppendPosition,
|
|
8
|
+
inShowLog = false
|
|
9
|
+
} = {}) => {
|
|
10
|
+
const localSpec = inSpec;
|
|
11
|
+
const localTargetHtmlId = inTargetHtmlId;
|
|
12
|
+
const localAppendPosition = inAppendPosition;
|
|
13
|
+
const localShowLog = inShowLog;
|
|
14
|
+
|
|
15
|
+
const content = jsonToTag(localSpec);
|
|
16
|
+
|
|
17
|
+
if (localShowLog) console.log("renderToDom 1 (content):", content);
|
|
18
|
+
|
|
19
|
+
const container = document.getElementById(localTargetHtmlId);
|
|
20
|
+
if (!container) return null;
|
|
21
|
+
|
|
22
|
+
const isCollection = Array.isArray(content) ||
|
|
23
|
+
content instanceof NodeList ||
|
|
24
|
+
content instanceof HTMLCollection;
|
|
25
|
+
|
|
26
|
+
if (isCollection) {
|
|
27
|
+
if (localAppendPosition === "prepend") {
|
|
28
|
+
container.prepend(...content);
|
|
29
|
+
} else {
|
|
30
|
+
container.append(...content);
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
if (localAppendPosition === "prepend") {
|
|
34
|
+
container.prepend(content);
|
|
35
|
+
} else {
|
|
36
|
+
container.innerHTML = "";
|
|
37
|
+
container.append(content);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (localShowLog) console.log("renderToDom 2 (mounted):", container);
|
|
42
|
+
|
|
43
|
+
return container;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export { renderToDom };
|
|
47
|
+
export default renderToDom;
|