json-renderers 1.13.2 → 1.13.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-renderers",
3
- "version": "1.13.2",
3
+ "version": "1.13.3",
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",
@@ -30,6 +30,6 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@keshavsoft/json-to-tag": "^1.9.3",
33
- "json-renderers-build": "^1.2.1"
33
+ "json-renderers-build": "^1.3.2"
34
34
  }
35
35
  }
@@ -1,13 +1,11 @@
1
1
  import jsonRenderBuild from "json-renderers-build";
2
2
  import jsonToTag from "@keshavsoft/json-to-tag";
3
3
 
4
- import skeletonJson from './skeleton.json' with { type: 'json' };
5
-
6
4
  // --- Story of Table Render ---
7
5
  const startFunc = ({
8
6
  inTargetHtmlId,
9
- inColumns,
10
- inData, inAppendPosition
7
+ inColumns, type,
8
+ inData
11
9
  } = {}) => {
12
10
  debugger
13
11
  const localTargetHtmlId = inTargetHtmlId;
@@ -20,20 +18,11 @@ const startFunc = ({
20
18
  data: localData,
21
19
  columns: localColumns
22
20
  });
23
- console.log("specAsJsonToDom : ", inAppendPosition, specAsJsonToDom);
24
-
25
- const container = document.getElementById(localTargetHtmlId);
26
21
 
27
22
  const content = jsonToTag(specAsJsonToDom);
28
23
 
29
- if (inAppendPosition === "prepend") {
30
- container.prepend(content);
31
- } else {
32
-
33
- if (container) container.innerHTML = "";
24
+ return content;
34
25
 
35
- container.append(content);
36
- };
37
26
  };
38
27
 
39
28
  export default startFunc;
package/src/v13/index.js CHANGED
@@ -1,44 +1,39 @@
1
1
  import registerGlobal from "./registerGlobal.js";
2
2
 
3
- import renderTable from "./table/index.js";
4
-
5
- const RENDERER_MAP = {
6
- table: renderTable
7
- };
3
+ import buildSpec from "./buildSpec/index.js";
8
4
 
9
5
  const render = ({
10
6
  type = "table",
11
7
  targetHtmlId,
12
8
  data,
13
9
  classToApply,
14
- inTargetHtmlId,
15
- inData,
16
10
  columns,
17
- inColumns,
18
11
  appendPosition
19
12
  } = {}) => {
20
13
  const rawType = type;
21
- const resolvedType = typeof rawType === "string" ? rawType.toLowerCase() : "table";
22
- const renderer = RENDERER_MAP[resolvedType];
23
14
 
24
- if (!renderer) {
25
- console.error(
26
- `[Renderer] Unknown renderer type "${rawType}". Available types: ${Object.keys(RENDERER_MAP).join(", ")}`
27
- );
28
- return null;
29
- }
30
-
31
- const localTargetHtmlId = inTargetHtmlId ?? targetHtmlId;
32
- const localData = inData ?? data;
33
- const localColumns = inColumns ?? columns;
15
+ const localTargetHtmlId = targetHtmlId;
16
+ const localData = data;
17
+ const localColumns = columns;
34
18
 
35
19
  // Default to table renderer
36
- return renderer({
20
+ const content = buildSpec({
37
21
  inTargetHtmlId: localTargetHtmlId,
38
22
  inColumns: localColumns,
39
- inData: localData,
40
- inAppendPosition: appendPosition
23
+ inData: localData, type: rawType
41
24
  });
25
+
26
+ const container = document.getElementById(localTargetHtmlId);
27
+
28
+ if (appendPosition === "prepend") {
29
+ container.prepend(content);
30
+ } else {
31
+ if (container) container.innerHTML = "";
32
+
33
+ container.append(content);
34
+ };
35
+
36
+ return container;
42
37
  };
43
38
 
44
39
  registerGlobal(render);
@@ -1,32 +0,0 @@
1
- import jsonToSpec from "json-to-spec";
2
- import jsonToTag from "@keshavsoft/json-to-tag";
3
-
4
- import skeletonJson from './skeleton.json' with { type: 'json' };
5
-
6
- // --- Story of Table Render ---
7
- const startFunc = ({
8
- inTargetHtmlId,
9
- inData
10
- } = {}) => {
11
- const localTargetHtmlId = inTargetHtmlId ?? targetHtmlId;
12
- const localData = inData ?? [];
13
- const localColumns = inColumns;
14
-
15
- let specAsJsonToDom = jsonToSpec(skeletonJson, {
16
- arrayOfStrings: localData
17
- });
18
-
19
- if (!("tagName" in specAsJsonToDom)) {
20
- specAsJsonToDom = specAsJsonToDom.children;
21
- };
22
-
23
- const container = document.getElementById(localTargetHtmlId);
24
-
25
- if (container) container.innerHTML = "";
26
-
27
- const content = jsonToTag(specAsJsonToDom);
28
-
29
- container.append(content);
30
- };
31
-
32
- export default startFunc;
@@ -1,18 +0,0 @@
1
- {
2
- "tagName": "select",
3
- "attributes": {
4
- "id": "arrayOfStrings"
5
- },
6
- "jsonToSpec": {
7
- "operation": "loopArray",
8
- "source": "arrayOfStrings",
9
- "template": {
10
- "tagName": "option",
11
- "attributes": {
12
- "value": "${}"
13
- },
14
- "textContent": "${}"
15
- }
16
- },
17
- "children": []
18
- }
@@ -1,47 +0,0 @@
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
- }