json-renderers-build 1.9.2 → 1.10.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.
Files changed (146) hide show
  1. package/package.json +2 -2
  2. package/src/index.js +2 -2
  3. package/src/v10/index.js +42 -0
  4. package/src/{v2 → v10}/meta.js +1 -1
  5. package/src/v10/select/index.js +21 -0
  6. package/src/{v6/selectOptionsOnly → v10/select/options}/index.js +2 -4
  7. package/src/{v4/selectOptionsOnly → v10/select/options}/skeleton.json +1 -1
  8. package/src/v10/table/footer/empty/cell/index.js +5 -0
  9. package/src/v10/table/footer/empty/cell/tag.json +6 -0
  10. package/src/v10/table/footer/empty/index.js +6 -0
  11. package/src/v10/table/footer/empty/row/index.js +10 -0
  12. package/src/v10/table/footer/empty/row/tag.json +7 -0
  13. package/src/v10/table/footer/index.js +28 -0
  14. package/src/v10/table/footer/inputs/cell/index.js +15 -0
  15. package/src/v10/table/footer/inputs/cell/tag.json +7 -0
  16. package/src/v10/table/footer/inputs/index.js +6 -0
  17. package/src/v10/table/footer/inputs/input/tag.json +9 -0
  18. package/src/v10/table/footer/inputs/row/index.js +10 -0
  19. package/src/v10/table/footer/inputs/row/tag.json +7 -0
  20. package/src/v10/table/footer/inputsWithSave/button/tag.json +8 -0
  21. package/src/v10/table/footer/inputsWithSave/cell/index.js +20 -0
  22. package/src/v10/table/footer/inputsWithSave/cell/tag.json +7 -0
  23. package/src/v10/table/footer/inputsWithSave/index.js +6 -0
  24. package/src/v10/table/footer/inputsWithSave/input/tag.json +9 -0
  25. package/src/v10/table/footer/inputsWithSave/row/index.js +13 -0
  26. package/src/v10/table/footer/inputsWithSave/row/tag.json +7 -0
  27. package/src/v10/table/footer/tag.json +7 -0
  28. package/src/v10/table/footer/totals/cell/index.js +21 -0
  29. package/src/v10/table/footer/totals/cell/tag.json +7 -0
  30. package/src/v10/table/footer/totals/index.js +6 -0
  31. package/src/v10/table/footer/totals/row/index.js +12 -0
  32. package/src/v10/table/footer/totals/row/tag.json +7 -0
  33. package/src/v10/table/index.js +33 -0
  34. package/src/v10/table/options/index.js +16 -0
  35. package/src/v10/table/options/showOptions/index.js +39 -0
  36. package/src/v10/table/options/showSerial/index.js +19 -0
  37. package/src/v10/table/render-requests.json +107 -0
  38. package/src/v10/table/table/body/cell/index.js +12 -0
  39. package/src/v10/table/table/body/cell/tag.json +7 -0
  40. package/src/v10/table/table/body/index.js +17 -0
  41. package/src/v10/table/table/body/row/index.js +18 -0
  42. package/src/v10/table/table/body/row/tag.json +4 -0
  43. package/src/v10/table/table/body/tag.json +4 -0
  44. package/src/v10/table/table/head/cell/index.js +12 -0
  45. package/src/v10/table/table/head/cell/tag.json +7 -0
  46. package/src/v10/table/table/head/index.js +16 -0
  47. package/src/v10/table/table/head/row/index.js +14 -0
  48. package/src/v10/table/table/head/row/tag.json +4 -0
  49. package/src/v10/table/table/head/tag.json +4 -0
  50. package/src/v10/table/table/index.js +36 -0
  51. package/src/v10/table/table/tag.json +7 -0
  52. package/src/v10/tableFromSpec/footer/empty/cell/index.js +5 -0
  53. package/src/v10/tableFromSpec/footer/empty/cell/tag.json +6 -0
  54. package/src/v10/tableFromSpec/footer/empty/index.js +6 -0
  55. package/src/v10/tableFromSpec/footer/empty/row/index.js +10 -0
  56. package/src/v10/tableFromSpec/footer/empty/row/tag.json +7 -0
  57. package/src/v10/tableFromSpec/footer/index.js +28 -0
  58. package/src/v10/tableFromSpec/footer/inputs/cell/index.js +15 -0
  59. package/src/v10/tableFromSpec/footer/inputs/cell/tag.json +7 -0
  60. package/src/v10/tableFromSpec/footer/inputs/index.js +6 -0
  61. package/src/v10/tableFromSpec/footer/inputs/input/tag.json +9 -0
  62. package/src/v10/tableFromSpec/footer/inputs/row/index.js +10 -0
  63. package/src/v10/tableFromSpec/footer/inputs/row/tag.json +7 -0
  64. package/src/v10/tableFromSpec/footer/inputsWithSave/button/tag.json +8 -0
  65. package/src/v10/tableFromSpec/footer/inputsWithSave/cell/index.js +20 -0
  66. package/src/v10/tableFromSpec/footer/inputsWithSave/cell/tag.json +7 -0
  67. package/src/v10/tableFromSpec/footer/inputsWithSave/index.js +6 -0
  68. package/src/v10/tableFromSpec/footer/inputsWithSave/input/tag.json +9 -0
  69. package/src/v10/tableFromSpec/footer/inputsWithSave/row/index.js +13 -0
  70. package/src/v10/tableFromSpec/footer/inputsWithSave/row/tag.json +7 -0
  71. package/src/v10/tableFromSpec/footer/tag.json +7 -0
  72. package/src/v10/tableFromSpec/footer/totals/cell/index.js +21 -0
  73. package/src/v10/tableFromSpec/footer/totals/cell/tag.json +7 -0
  74. package/src/v10/tableFromSpec/footer/totals/index.js +6 -0
  75. package/src/v10/tableFromSpec/footer/totals/row/index.js +12 -0
  76. package/src/v10/tableFromSpec/footer/totals/row/tag.json +7 -0
  77. package/src/v10/tableFromSpec/index.js +32 -0
  78. package/src/v10/tableFromSpec/options/index.js +18 -0
  79. package/src/v10/tableFromSpec/options/showOptions/index.js +39 -0
  80. package/src/v10/tableFromSpec/options/showSerial/index.js +20 -0
  81. package/src/v10/tableFromSpec/render-requests.json +107 -0
  82. package/src/v10/tableFromSpec/table/body/index.js +16 -0
  83. package/src/v10/tableFromSpec/table/body/spec.json +16 -0
  84. package/src/v10/tableFromSpec/table/body/tag.json +4 -0
  85. package/src/v10/tableFromSpec/table/findKey.js +17 -0
  86. package/src/v10/tableFromSpec/table/head/index.js +19 -0
  87. package/src/v10/tableFromSpec/table/head/spec.json +13 -0
  88. package/src/v10/tableFromSpec/table/index.js +22 -0
  89. package/src/v10/tableFromSpec/table/tag.json +24 -0
  90. package/src/v1/index.js +0 -62
  91. package/src/v1/meta.js +0 -6
  92. package/src/v1/registerGlobal.js +0 -14
  93. package/src/v1/select/index.js +0 -32
  94. package/src/v1/select/skeleton.json +0 -18
  95. package/src/v1/table/index.js +0 -36
  96. package/src/v1/table/skeleton.json +0 -47
  97. package/src/v2/common/deriveColumnsFromData.js +0 -20
  98. package/src/v2/index.js +0 -62
  99. package/src/v2/select/index.js +0 -32
  100. package/src/v2/select/skeleton.json +0 -18
  101. package/src/v2/table/index.js +0 -23
  102. package/src/v2/table/skeleton.json +0 -47
  103. package/src/v3/common/deriveColumnsFromData.js +0 -20
  104. package/src/v3/index.js +0 -40
  105. package/src/v3/meta.js +0 -6
  106. package/src/v3/registerGlobal.js +0 -14
  107. package/src/v3/select/index.js +0 -18
  108. package/src/v3/select/skeleton.json +0 -18
  109. package/src/v3/selectOptionsOnly/index.js +0 -18
  110. package/src/v3/selectOptionsOnly/skeleton.json +0 -14
  111. package/src/v3/table/index.js +0 -20
  112. package/src/v3/table/skeleton.json +0 -47
  113. package/src/v4/common/deriveColumnsFromData.js +0 -20
  114. package/src/v4/index.js +0 -40
  115. package/src/v4/meta.js +0 -6
  116. package/src/v4/registerGlobal.js +0 -14
  117. package/src/v4/select/index.js +0 -20
  118. package/src/v4/selectOptionsOnly/index.js +0 -19
  119. package/src/v4/table/index.js +0 -20
  120. package/src/v4/table/skeleton.json +0 -47
  121. package/src/v5/common/deriveColumnsFromData.js +0 -20
  122. package/src/v5/index.js +0 -40
  123. package/src/v5/meta.js +0 -6
  124. package/src/v5/registerGlobal.js +0 -14
  125. package/src/v5/select/index.js +0 -20
  126. package/src/v5/select/skeleton.json +0 -7
  127. package/src/v5/selectOptionsOnly/index.js +0 -19
  128. package/src/v5/selectOptionsOnly/skeleton.json +0 -17
  129. package/src/v5/table/index.js +0 -20
  130. package/src/v5/table/skeleton.json +0 -47
  131. package/src/v5/tableHeadCells/index.js +0 -19
  132. package/src/v5/tableHeadCells/skeleton.json +0 -17
  133. package/src/v6/common/deriveColumnsFromData.js +0 -20
  134. package/src/v6/index.js +0 -40
  135. package/src/v6/meta.js +0 -6
  136. package/src/v6/registerGlobal.js +0 -14
  137. package/src/v6/select/index.js +0 -20
  138. package/src/v6/select/skeleton.json +0 -7
  139. package/src/v6/selectOptionsOnly/skeleton.json +0 -17
  140. package/src/v6/table/index.js +0 -20
  141. package/src/v6/table/skeleton.json +0 -47
  142. package/src/v6/tableHeadCells/index.js +0 -19
  143. package/src/v6/tableHeadCells/skeleton.json +0 -17
  144. /package/src/{v1 → v10}/common/deriveColumnsFromData.js +0 -0
  145. /package/src/{v2 → v10}/registerGlobal.js +0 -0
  146. /package/src/{v4 → v10}/select/skeleton.json +0 -0
@@ -0,0 +1,17 @@
1
+ import tagJson from "./tag.json" with { type: "json" };
2
+ import buildBodyRow from "./row/index.js";
3
+
4
+ const renderTableBody = ({ inData = [], inColumns = [] } = {}) => {
5
+ const tbody = structuredClone(tagJson);
6
+
7
+ const children = inData.map(row => buildBodyRow({
8
+ inRow: row,
9
+ inColumns
10
+ }));
11
+
12
+ tbody.children = children;
13
+
14
+ return tbody;
15
+ };
16
+
17
+ export default renderTableBody;
@@ -0,0 +1,18 @@
1
+ import tagJson from "./tag.json" with { type: "json" };
2
+ import buildBodyCell from "../cell/index.js";
3
+
4
+ const buildBodyRow = ({ inRow, inColumns = [] } = {}) => {
5
+ const tr = structuredClone(tagJson);
6
+
7
+ const children = inColumns.map(column => {
8
+ const value = Array.isArray(inRow) ? inRow[column] : inRow?.[column];
9
+
10
+ return buildBodyCell({ inValue: value });
11
+ });
12
+
13
+ tr.children = children;
14
+
15
+ return tr;
16
+ };
17
+
18
+ export default buildBodyRow;
@@ -0,0 +1,4 @@
1
+ {
2
+ "tagName": "tr",
3
+ "children": []
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "tagName": "tbody",
3
+ "children": []
4
+ }
@@ -0,0 +1,12 @@
1
+ import tagJson from "./tag.json" with { type: "json" };
2
+
3
+ const buildHeadCell = ({ inColumn } = {}) => {
4
+ const th = structuredClone(tagJson);
5
+
6
+ th.attributes.value = inColumn;
7
+ th.textContent = inColumn;
8
+
9
+ return th;
10
+ };
11
+
12
+ export default buildHeadCell;
@@ -0,0 +1,7 @@
1
+ {
2
+ "tagName": "th",
3
+ "attributes": {
4
+ "value": ""
5
+ },
6
+ "textContent": ""
7
+ }
@@ -0,0 +1,16 @@
1
+ import tagJson from "./tag.json" with { type: "json" };
2
+ import buildHeadRow from "./row/index.js";
3
+
4
+ const renderTableHead = ({ inColumns = [] } = {}) => {
5
+ const thead = structuredClone(tagJson);
6
+
7
+ const children = [
8
+ buildHeadRow({ inColumns })
9
+ ];
10
+
11
+ thead.children = children;
12
+
13
+ return thead;
14
+ };
15
+
16
+ export default renderTableHead;
@@ -0,0 +1,14 @@
1
+ import tagJson from "./tag.json" with { type: "json" };
2
+ import buildHeadCell from "../cell/index.js";
3
+
4
+ const buildHeadRow = ({ inColumns = [] } = {}) => {
5
+ const tr = structuredClone(tagJson);
6
+
7
+ const children = inColumns.map(column => buildHeadCell({ inColumn: column }));
8
+
9
+ tr.children = children;
10
+
11
+ return tr;
12
+ };
13
+
14
+ export default buildHeadRow;
@@ -0,0 +1,4 @@
1
+ {
2
+ "tagName": "tr",
3
+ "children": []
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "tagName": "thead",
3
+ "children": []
4
+ }
@@ -0,0 +1,36 @@
1
+ import tagJson from "./tag.json" with { type: "json" };
2
+ import renderTableHead from "./head/index.js";
3
+ import renderTableBody from "./body/index.js";
4
+ import renderTableFooter from "../footer/index.js";
5
+
6
+ const renderTable = ({
7
+ inColumns = [],
8
+ inData = [],
9
+ inFooter = []
10
+ } = {}) => {
11
+ const table = structuredClone(tagJson);
12
+
13
+ const children = [
14
+ renderTableHead({ inColumns }),
15
+ renderTableBody({ inData, inColumns })
16
+ ];
17
+
18
+ if (!Array.isArray(inFooter)) {
19
+ throw new TypeError("The footer property must be an array of footer names.");
20
+ }
21
+
22
+ if (inFooter.length > 0) {
23
+ children.push(renderTableFooter({
24
+ inFooter,
25
+ inColumns,
26
+ inData
27
+ }));
28
+ }
29
+
30
+ table.children = children;
31
+
32
+ return table;
33
+ };
34
+
35
+ export { renderTableHead, renderTableBody };
36
+ export default renderTable;
@@ -0,0 +1,7 @@
1
+ {
2
+ "tagName": "table",
3
+ "attributes": {
4
+ "class": "table table-hover table-striped mb-0"
5
+ },
6
+ "children": []
7
+ }
@@ -0,0 +1,5 @@
1
+ import tagJson from "./tag.json" with { type: "json" };
2
+
3
+ const renderCell = () => structuredClone(tagJson);
4
+
5
+ export default renderCell;
@@ -0,0 +1,6 @@
1
+ {
2
+ "tagName": "td",
3
+ "attributes": {
4
+ "class": "align-middle py-2"
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ import renderRow from "./row/index.js";
2
+
3
+ const renderEmpty = ({ inColumns = [] } = {}) =>
4
+ renderRow({ inColumns });
5
+
6
+ export default renderEmpty;
@@ -0,0 +1,10 @@
1
+ import tagJson from "./tag.json" with { type: "json" };
2
+ import renderCell from "../cell/index.js";
3
+
4
+ const renderRow = ({ inColumns = [] } = {}) => {
5
+ const row = structuredClone(tagJson);
6
+ row.children = inColumns.map(() => renderCell());
7
+ return row;
8
+ };
9
+
10
+ export default renderRow;
@@ -0,0 +1,7 @@
1
+ {
2
+ "tagName": "tr",
3
+ "attributes": {
4
+ "class": "align-middle"
5
+ },
6
+ "children": []
7
+ }
@@ -0,0 +1,28 @@
1
+ import tagJson from "./tag.json" with { type: "json" };
2
+ import renderInputs from "./inputs/index.js";
3
+ import renderInputsWithSave from "./inputsWithSave/index.js";
4
+ import renderTotals from "./totals/index.js";
5
+ import renderEmpty from "./empty/index.js";
6
+
7
+ const footerBuilders = {
8
+ inputs: renderInputs,
9
+ inputsWithSave: renderInputsWithSave,
10
+ totals: renderTotals,
11
+ empty: renderEmpty
12
+ };
13
+
14
+ const renderTableFooter = ({ inFooter = [], inColumns = [], inData = [] } = {}) => {
15
+ const tfoot = structuredClone(tagJson);
16
+
17
+ tfoot.children = inFooter.map(footerName => {
18
+ if (!Object.hasOwn(footerBuilders, footerName)) {
19
+ throw new Error(`Unknown footer "${footerName}".`);
20
+ }
21
+
22
+ return footerBuilders[footerName]({ inColumns, inData });
23
+ });
24
+
25
+ return tfoot;
26
+ };
27
+
28
+ export default renderTableFooter;
@@ -0,0 +1,15 @@
1
+ import cellJson from "./tag.json" with { type: "json" };
2
+ import inputJson from "../input/tag.json" with { type: "json" };
3
+
4
+ const renderCell = ({ inColumn } = {}) => {
5
+ const cell = structuredClone(cellJson);
6
+ const input = structuredClone(inputJson);
7
+
8
+ input.attributes.name = inColumn;
9
+ input.attributes.placeholder = inColumn;
10
+ cell.children.push(input);
11
+
12
+ return cell;
13
+ };
14
+
15
+ export default renderCell;
@@ -0,0 +1,7 @@
1
+ {
2
+ "tagName": "td",
3
+ "attributes": {
4
+ "class": "align-middle py-2"
5
+ },
6
+ "children": []
7
+ }
@@ -0,0 +1,6 @@
1
+ import renderRow from "./row/index.js";
2
+
3
+ const renderInputs = ({ inColumns = [] } = {}) =>
4
+ renderRow({ inColumns });
5
+
6
+ export default renderInputs;
@@ -0,0 +1,9 @@
1
+ {
2
+ "tagName": "input",
3
+ "attributes": {
4
+ "type": "text",
5
+ "name": "",
6
+ "placeholder": "",
7
+ "class": "form-control form-control-sm"
8
+ }
9
+ }
@@ -0,0 +1,10 @@
1
+ import tagJson from "./tag.json" with { type: "json" };
2
+ import renderCell from "../cell/index.js";
3
+
4
+ const renderRow = ({ inColumns = [] } = {}) => {
5
+ const row = structuredClone(tagJson);
6
+ row.children = inColumns.map(inColumn => renderCell({ inColumn }));
7
+ return row;
8
+ };
9
+
10
+ export default renderRow;
@@ -0,0 +1,7 @@
1
+ {
2
+ "tagName": "tr",
3
+ "attributes": {
4
+ "class": "align-middle"
5
+ },
6
+ "children": []
7
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "tagName": "button",
3
+ "attributes": {
4
+ "type": "button",
5
+ "class": "btn btn-primary btn-sm ms-2"
6
+ },
7
+ "textContent": "Save"
8
+ }
@@ -0,0 +1,20 @@
1
+ import cellJson from "./tag.json" with { type: "json" };
2
+ import inputJson from "../input/tag.json" with { type: "json" };
3
+ import buttonJson from "../button/tag.json" with { type: "json" };
4
+
5
+ const renderCell = ({ inColumn, inSave = false } = {}) => {
6
+ const cell = structuredClone(cellJson);
7
+ const input = structuredClone(inputJson);
8
+
9
+ input.attributes.name = inColumn;
10
+ input.attributes.placeholder = inColumn;
11
+ cell.children.push(input);
12
+
13
+ if (inSave) {
14
+ cell.children.push(structuredClone(buttonJson));
15
+ }
16
+
17
+ return cell;
18
+ };
19
+
20
+ export default renderCell;
@@ -0,0 +1,7 @@
1
+ {
2
+ "tagName": "td",
3
+ "attributes": {
4
+ "class": "align-middle py-2"
5
+ },
6
+ "children": []
7
+ }
@@ -0,0 +1,6 @@
1
+ import renderRow from "./row/index.js";
2
+
3
+ const renderInputsWithSave = ({ inColumns = [] } = {}) =>
4
+ renderRow({ inColumns });
5
+
6
+ export default renderInputsWithSave;
@@ -0,0 +1,9 @@
1
+ {
2
+ "tagName": "input",
3
+ "attributes": {
4
+ "type": "text",
5
+ "name": "",
6
+ "placeholder": "",
7
+ "class": "form-control form-control-sm"
8
+ }
9
+ }
@@ -0,0 +1,13 @@
1
+ import tagJson from "./tag.json" with { type: "json" };
2
+ import renderCell from "../cell/index.js";
3
+
4
+ const renderRow = ({ inColumns = [] } = {}) => {
5
+ const row = structuredClone(tagJson);
6
+ row.children = inColumns.map((inColumn, index) => renderCell({
7
+ inColumn,
8
+ inSave: index === inColumns.length - 1
9
+ }));
10
+ return row;
11
+ };
12
+
13
+ export default renderRow;
@@ -0,0 +1,7 @@
1
+ {
2
+ "tagName": "tr",
3
+ "attributes": {
4
+ "class": "align-middle"
5
+ },
6
+ "children": []
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "tagName": "tfoot",
3
+ "attributes": {
4
+ "class": "table-light"
5
+ },
6
+ "children": []
7
+ }
@@ -0,0 +1,21 @@
1
+ import tagJson from "./tag.json" with { type: "json" };
2
+
3
+ const getValue = (row, column) =>
4
+ Array.isArray(row) ? row[column] : row?.[column];
5
+
6
+ const renderCell = ({ inColumn, inIndex, inData = [] } = {}) => {
7
+ const cell = structuredClone(tagJson);
8
+ const values = inData
9
+ .map(row => getValue(row, inColumn))
10
+ .filter(value => value !== null && value !== undefined && String(value).trim() !== "")
11
+ .map(Number)
12
+ .filter(Number.isFinite);
13
+
14
+ cell.textContent = values.length
15
+ ? String(values.reduce((sum, value) => sum + value, 0))
16
+ : inIndex === 0 ? "Total" : "";
17
+
18
+ return cell;
19
+ };
20
+
21
+ export default renderCell;
@@ -0,0 +1,7 @@
1
+ {
2
+ "tagName": "td",
3
+ "attributes": {
4
+ "class": "align-middle py-2"
5
+ },
6
+ "textContent": ""
7
+ }
@@ -0,0 +1,6 @@
1
+ import renderRow from "./row/index.js";
2
+
3
+ const renderTotals = ({ inColumns = [], inData = [] } = {}) =>
4
+ renderRow({ inColumns, inData });
5
+
6
+ export default renderTotals;
@@ -0,0 +1,12 @@
1
+ import tagJson from "./tag.json" with { type: "json" };
2
+ import renderCell from "../cell/index.js";
3
+
4
+ const renderRow = ({ inColumns = [], inData = [] } = {}) => {
5
+ const row = structuredClone(tagJson);
6
+ row.children = inColumns.map((inColumn, inIndex) =>
7
+ renderCell({ inColumn, inIndex, inData })
8
+ );
9
+ return row;
10
+ };
11
+
12
+ export default renderRow;
@@ -0,0 +1,7 @@
1
+ {
2
+ "tagName": "tr",
3
+ "attributes": {
4
+ "class": "fw-semibold align-middle"
5
+ },
6
+ "children": []
7
+ }
@@ -0,0 +1,32 @@
1
+ import renderTable from "./table/index.js";
2
+
3
+ import applyOptions from "./options/index.js";
4
+ import renderRequests from "./render-requests.json" with { type: "json" };
5
+
6
+ const render = ({
7
+ inData,
8
+ inColumns,
9
+ footer = [],
10
+ options
11
+ } = {}) => {
12
+ const spec = renderTable({
13
+ inColumns,
14
+ inData,
15
+ inFooter: footer
16
+ });
17
+
18
+ if (options) {
19
+ return applyOptions(spec, options);
20
+ };
21
+
22
+ return spec;
23
+ };
24
+
25
+ render.requests = renderRequests;
26
+
27
+ export {
28
+ render,
29
+ renderRequests
30
+ };
31
+
32
+ export default render;
@@ -0,0 +1,18 @@
1
+ import applyShowSerial from "./showSerial/index.js";
2
+ import applyShowOptions from "./showOptions/index.js";
3
+
4
+ const applyOptions = (inSpec, inOptions = {}) => {
5
+ // console.log("inOptions : ", inOptions);
6
+
7
+ if (inOptions.showSerial) {
8
+ applyShowSerial(inSpec);
9
+ }
10
+
11
+ if (inOptions.showOptions) {
12
+ applyShowOptions(inSpec, inOptions.showOptions);
13
+ }
14
+
15
+ return inSpec;
16
+ };
17
+
18
+ export default applyOptions;
@@ -0,0 +1,39 @@
1
+ const resolveButtons = (inShowOptions) => {
2
+ if (inShowOptions === true) {
3
+ return [{ label: "Apply", type: "button" }];
4
+ }
5
+
6
+ if (Array.isArray(inShowOptions)) {
7
+ return inShowOptions;
8
+ }
9
+
10
+ return [];
11
+ };
12
+
13
+ const applyShowOptions = (inSpec, inShowOptions) => {
14
+ const buttons = resolveButtons(inShowOptions);
15
+
16
+ if (buttons.length === 0) return;
17
+
18
+ const [thead, tbody] = inSpec.children;
19
+
20
+ // append <th>Actions</th> to head row
21
+ thead.children[0].children.push({
22
+ tagName: "th",
23
+ textContent: "Actions"
24
+ });
25
+
26
+ // append <td> with buttons to each body row
27
+ tbody.children.forEach(tr => {
28
+ tr.children.push({
29
+ tagName: "td",
30
+ children: buttons.map(btn => ({
31
+ tagName: "button",
32
+ attributes: { type: btn.type || "button" },
33
+ textContent: btn.label
34
+ }))
35
+ });
36
+ });
37
+ };
38
+
39
+ export default applyShowOptions;
@@ -0,0 +1,20 @@
1
+ const applyShowSerial = (inSpec) => {
2
+ const [thead, tbody] = inSpec.children;
3
+ console.log("aaaaaaa--", thead.children[0]);
4
+
5
+ // prepend <th>#</th> to head row
6
+ thead.children[0].children.unshift({
7
+ tagName: "th",
8
+ textContent: "#"
9
+ });
10
+
11
+ // prepend <td>{rowIndex}</td> to each body row
12
+ tbody.children.forEach((tr, index) => {
13
+ tr.children.unshift({
14
+ tagName: "td",
15
+ textContent: String(index + 1)
16
+ });
17
+ });
18
+ };
19
+
20
+ export default applyShowSerial;