json-renderers-build-table 0.0.0-stage → 1.9.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/README.md +28 -3
- package/package.json +25 -5
- package/src/index.js +3 -0
- package/src/v5/index.js +49 -0
- package/src/v5/options/index.js +18 -0
- package/src/v5/options/showOptions/index.js +39 -0
- package/src/v5/options/showSerial/index.js +19 -0
- package/src/v5/render-requests.json +70 -0
- package/src/v5/table/body/cell/index.js +12 -0
- package/src/v5/table/body/cell/tag.json +7 -0
- package/src/v5/table/body/index.js +17 -0
- package/src/v5/table/body/row/index.js +18 -0
- package/src/v5/table/body/row/tag.json +4 -0
- package/src/v5/table/body/tag.json +4 -0
- package/src/v5/table/head/cell/index.js +12 -0
- package/src/v5/table/head/cell/tag.json +7 -0
- package/src/v5/table/head/index.js +16 -0
- package/src/v5/table/head/row/index.js +14 -0
- package/src/v5/table/head/row/tag.json +4 -0
- package/src/v5/table/head/tag.json +4 -0
- package/src/v5/table/index.js +22 -0
- package/src/v5/table/tag.json +7 -0
- package/src/v6/index.js +29 -0
- package/src/v6/options/index.js +28 -0
- package/src/v6/options/showFooter/cell/index.js +16 -0
- package/src/v6/options/showFooter/cell/tag.json +4 -0
- package/src/v6/options/showFooter/footer/index.js +18 -0
- package/src/v6/options/showFooter/footer/tag.json +4 -0
- package/src/v6/options/showFooter/index.js +10 -0
- package/src/v6/options/showFooter/input/index.js +11 -0
- package/src/v6/options/showFooter/input/tag.json +7 -0
- package/src/v6/options/showFooter/row/index.js +35 -0
- package/src/v6/options/showFooter/row/tag.json +4 -0
- package/src/v6/options/showFooterSave/button/tag.json +7 -0
- package/src/v6/options/showFooterSave/index.js +14 -0
- package/src/v6/options/showOptions/index.js +39 -0
- package/src/v6/options/showSerial/index.js +19 -0
- package/src/v6/render-requests.json +90 -0
- package/src/v6/table/body/cell/index.js +12 -0
- package/src/v6/table/body/cell/tag.json +7 -0
- package/src/v6/table/body/index.js +17 -0
- package/src/v6/table/body/row/index.js +18 -0
- package/src/v6/table/body/row/tag.json +4 -0
- package/src/v6/table/body/tag.json +4 -0
- package/src/v6/table/head/cell/index.js +12 -0
- package/src/v6/table/head/cell/tag.json +7 -0
- package/src/v6/table/head/index.js +16 -0
- package/src/v6/table/head/row/index.js +14 -0
- package/src/v6/table/head/row/tag.json +4 -0
- package/src/v6/table/head/tag.json +4 -0
- package/src/v6/table/index.js +22 -0
- package/src/v6/table/tag.json +7 -0
- package/src/v7/index.js +29 -0
- package/src/v7/options/index.js +28 -0
- package/src/v7/options/showFooter/cell/index.js +16 -0
- package/src/v7/options/showFooter/cell/tag.json +4 -0
- package/src/v7/options/showFooter/footer/index.js +18 -0
- package/src/v7/options/showFooter/footer/tag.json +4 -0
- package/src/v7/options/showFooter/index.js +10 -0
- package/src/v7/options/showFooter/input/index.js +11 -0
- package/src/v7/options/showFooter/input/tag.json +7 -0
- package/src/v7/options/showFooter/row/index.js +35 -0
- package/src/v7/options/showFooter/row/tag.json +4 -0
- package/src/v7/options/showFooterSave/button/tag.json +7 -0
- package/src/v7/options/showFooterSave/index.js +14 -0
- package/src/v7/options/showOptions/index.js +39 -0
- package/src/v7/options/showSerial/index.js +19 -0
- package/src/v7/render-requests.json +90 -0
- package/src/v7/table/body/cell/index.js +12 -0
- package/src/v7/table/body/cell/tag.json +7 -0
- package/src/v7/table/body/index.js +17 -0
- package/src/v7/table/body/row/index.js +18 -0
- package/src/v7/table/body/row/tag.json +4 -0
- package/src/v7/table/body/tag.json +4 -0
- package/src/v7/table/head/cell/index.js +12 -0
- package/src/v7/table/head/cell/tag.json +7 -0
- package/src/v7/table/head/index.js +16 -0
- package/src/v7/table/head/row/index.js +14 -0
- package/src/v7/table/head/row/tag.json +4 -0
- package/src/v7/table/head/tag.json +4 -0
- package/src/v7/table/index.js +22 -0
- package/src/v7/table/tag.json +7 -0
- package/src/v8/index.js +29 -0
- package/src/v8/options/index.js +28 -0
- package/src/v8/options/showFooter/cell/index.js +16 -0
- package/src/v8/options/showFooter/cell/tag.json +4 -0
- package/src/v8/options/showFooter/footer/index.js +18 -0
- package/src/v8/options/showFooter/footer/tag.json +4 -0
- package/src/v8/options/showFooter/index.js +10 -0
- package/src/v8/options/showFooter/input/index.js +11 -0
- package/src/v8/options/showFooter/input/tag.json +7 -0
- package/src/v8/options/showFooter/row/index.js +35 -0
- package/src/v8/options/showFooter/row/tag.json +4 -0
- package/src/v8/options/showFooterSave/button/tag.json +7 -0
- package/src/v8/options/showFooterSave/index.js +14 -0
- package/src/v8/options/showOptions/index.js +39 -0
- package/src/v8/options/showSerial/index.js +19 -0
- package/src/v8/render-requests.json +90 -0
- package/src/v8/table/body/cell/index.js +12 -0
- package/src/v8/table/body/cell/tag.json +7 -0
- package/src/v8/table/body/index.js +17 -0
- package/src/v8/table/body/row/index.js +18 -0
- package/src/v8/table/body/row/tag.json +4 -0
- package/src/v8/table/body/tag.json +4 -0
- package/src/v8/table/head/cell/index.js +12 -0
- package/src/v8/table/head/cell/tag.json +7 -0
- package/src/v8/table/head/index.js +16 -0
- package/src/v8/table/head/row/index.js +14 -0
- package/src/v8/table/head/row/tag.json +4 -0
- package/src/v8/table/head/tag.json +4 -0
- package/src/v8/table/index.js +22 -0
- package/src/v8/table/tag.json +7 -0
- package/src/v9/index.js +28 -0
- package/src/v9/table/index.js +67 -0
- package/src/v9/table/spec.json +18 -0
- package/src/v9/table/table.json +24 -0
package/README.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# json-renderers-build-table
|
|
2
|
+
|
|
3
|
+
Focused table specification builder extracted from the table work in `json-renderers-build`.
|
|
4
|
+
|
|
5
|
+
The package builds JSON DOM specifications for table sections. Table data remains separate from table and row options, so row actions, row attributes, and custom cell elements can evolve without adding table-specific behavior to the generic renderer package.
|
|
6
|
+
|
|
7
|
+
Use the exported `renderRequests` JSON catalog to see complete requests for each supported flavor. It includes a basic table, serial numbers, default or custom actions, combined options, and standalone table head/body requests:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import render, { renderRequests } from "json-renderers-build-table";
|
|
11
|
+
|
|
12
|
+
const request = structuredClone(renderRequests.tableWithSerialAndActions);
|
|
13
|
+
request.data = [{ itemName: "0.11-25", baseUnit: "kgs" }];
|
|
14
|
+
|
|
15
|
+
const table = render(request);
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The catalog is also available as `render.requests` when importing the default renderer. Clone a catalog entry before changing it so the shared examples remain unchanged.
|
|
19
|
+
|
|
20
|
+
To add a footer row with one text input per column, enable `showFooter`:
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
const request = structuredClone(renderRequests.tableWithFooter);
|
|
24
|
+
request.data = myData;
|
|
25
|
+
const table = render(request);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Use `showFooterSave` to add a separate footer row with the same inputs and a Save button in the last input cell.
|
package/package.json
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "json-renderers-build-table",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
1
|
+
{
|
|
2
|
+
"name": "json-renderers-build-table",
|
|
3
|
+
"version": "1.9.1",
|
|
4
|
+
"description": "Focused table specification builder with configurable rows and cells",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"test": "node test/v1/index.js && node test/v2/index.js && node test/v3/index.js && node test/v4/index.js && node test/v5/index.js",
|
|
16
|
+
"dev": "vite",
|
|
17
|
+
"build": "vite build"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@keshavsoft/json-to-tag": "^1.9.3",
|
|
21
|
+
"json-transformer-funcs": "^1.3.1"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"vite": "^8.3.4"
|
|
25
|
+
}
|
|
6
26
|
}
|
package/src/index.js
ADDED
package/src/v5/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import renderTable, {
|
|
2
|
+
renderTableHead,
|
|
3
|
+
renderTableBody
|
|
4
|
+
} from "./table/index.js";
|
|
5
|
+
|
|
6
|
+
import applyOptions from "./options/index.js";
|
|
7
|
+
import renderRequests from "./render-requests.json" with { type: "json" };
|
|
8
|
+
|
|
9
|
+
const render = ({
|
|
10
|
+
type = "table",
|
|
11
|
+
data = [],
|
|
12
|
+
columns = [],
|
|
13
|
+
options = {}
|
|
14
|
+
} = {}) => {
|
|
15
|
+
if (type === "table") {
|
|
16
|
+
const spec = renderTable({
|
|
17
|
+
inColumns: columns,
|
|
18
|
+
inData: data
|
|
19
|
+
});
|
|
20
|
+
console.log("inOptions : ", options);
|
|
21
|
+
|
|
22
|
+
return applyOptions(spec, options);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (type === "tableHead" || type === "head") {
|
|
26
|
+
return renderTableHead({
|
|
27
|
+
inColumns: columns
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (type === "tableBody" || type === "body") {
|
|
32
|
+
return renderTableBody({
|
|
33
|
+
inData: data,
|
|
34
|
+
inColumns: columns
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
throw new Error(`Unknown table renderer type "${type}".`);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
render,
|
|
43
|
+
renderRequests,
|
|
44
|
+
renderTable,
|
|
45
|
+
renderTableHead,
|
|
46
|
+
renderTableBody
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
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,19 @@
|
|
|
1
|
+
const applyShowSerial = (inSpec) => {
|
|
2
|
+
const [thead, tbody] = inSpec.children;
|
|
3
|
+
|
|
4
|
+
// prepend <th>#</th> to head row
|
|
5
|
+
thead.children[0].children.unshift({
|
|
6
|
+
tagName: "th",
|
|
7
|
+
textContent: "#"
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// prepend <td>{rowIndex}</td> to each body row
|
|
11
|
+
tbody.children.forEach((tr, index) => {
|
|
12
|
+
tr.children.unshift({
|
|
13
|
+
tagName: "td",
|
|
14
|
+
textContent: String(index + 1)
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default applyShowSerial;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"table": {
|
|
3
|
+
"type": "table",
|
|
4
|
+
"data": [
|
|
5
|
+
{ "itemName": "0.09/30mm", "baseUnit": "kgs" }
|
|
6
|
+
],
|
|
7
|
+
"columns": ["itemName", "baseUnit"],
|
|
8
|
+
"options": {}
|
|
9
|
+
},
|
|
10
|
+
"tableWithSerial": {
|
|
11
|
+
"type": "table",
|
|
12
|
+
"data": [
|
|
13
|
+
{ "itemName": "0.09/30mm", "baseUnit": "kgs" }
|
|
14
|
+
],
|
|
15
|
+
"columns": ["itemName", "baseUnit"],
|
|
16
|
+
"options": {
|
|
17
|
+
"showSerial": true
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"tableWithDefaultAction": {
|
|
21
|
+
"type": "table",
|
|
22
|
+
"data": [
|
|
23
|
+
{ "itemName": "0.09/30mm", "baseUnit": "kgs" }
|
|
24
|
+
],
|
|
25
|
+
"columns": ["itemName", "baseUnit"],
|
|
26
|
+
"options": {
|
|
27
|
+
"showOptions": true
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"tableWithCustomActions": {
|
|
31
|
+
"type": "table",
|
|
32
|
+
"data": [
|
|
33
|
+
{ "itemName": "0.09/30mm", "baseUnit": "kgs" }
|
|
34
|
+
],
|
|
35
|
+
"columns": ["itemName", "baseUnit"],
|
|
36
|
+
"options": {
|
|
37
|
+
"showOptions": [
|
|
38
|
+
{ "label": "Show", "type": "button" },
|
|
39
|
+
{ "label": "Edit", "type": "button" }
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"tableWithSerialAndActions": {
|
|
44
|
+
"type": "table",
|
|
45
|
+
"data": [
|
|
46
|
+
{ "itemName": "0.09/30mm", "baseUnit": "kgs" }
|
|
47
|
+
],
|
|
48
|
+
"columns": ["itemName", "baseUnit"],
|
|
49
|
+
"options": {
|
|
50
|
+
"showSerial": true,
|
|
51
|
+
"showOptions": [
|
|
52
|
+
{ "label": "Show", "type": "button" }
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"tableHead": {
|
|
57
|
+
"type": "tableHead",
|
|
58
|
+
"data": [],
|
|
59
|
+
"columns": ["itemName", "baseUnit"],
|
|
60
|
+
"options": {}
|
|
61
|
+
},
|
|
62
|
+
"tableBody": {
|
|
63
|
+
"type": "tableBody",
|
|
64
|
+
"data": [
|
|
65
|
+
{ "itemName": "0.09/30mm", "baseUnit": "kgs" }
|
|
66
|
+
],
|
|
67
|
+
"columns": ["itemName", "baseUnit"],
|
|
68
|
+
"options": {}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import tagJson from "./tag.json" with { type: "json" };
|
|
2
|
+
|
|
3
|
+
const buildBodyCell = ({ inValue } = {}) => {
|
|
4
|
+
const td = structuredClone(tagJson);
|
|
5
|
+
|
|
6
|
+
td.attributes.value = inValue;
|
|
7
|
+
td.textContent = inValue;
|
|
8
|
+
|
|
9
|
+
return td;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default buildBodyCell;
|
|
@@ -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,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,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,22 @@
|
|
|
1
|
+
import tagJson from "./tag.json" with { type: "json" };
|
|
2
|
+
import renderTableHead from "./head/index.js";
|
|
3
|
+
import renderTableBody from "./body/index.js";
|
|
4
|
+
|
|
5
|
+
const renderTable = ({
|
|
6
|
+
inColumns = [],
|
|
7
|
+
inData = []
|
|
8
|
+
} = {}) => {
|
|
9
|
+
const table = structuredClone(tagJson);
|
|
10
|
+
|
|
11
|
+
const children = [
|
|
12
|
+
renderTableHead({ inColumns }),
|
|
13
|
+
renderTableBody({ inData, inColumns })
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
table.children = children;
|
|
17
|
+
|
|
18
|
+
return table;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { renderTableHead, renderTableBody };
|
|
22
|
+
export default renderTable;
|
package/src/v6/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
type = "table",
|
|
8
|
+
data = [],
|
|
9
|
+
columns = [],
|
|
10
|
+
options = {}
|
|
11
|
+
} = {}) => {
|
|
12
|
+
if (type === "table") {
|
|
13
|
+
const spec = renderTable({
|
|
14
|
+
inColumns: columns,
|
|
15
|
+
inData: data
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return applyOptions(spec, options, columns);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
throw new Error(`Unknown table renderer type "${type}".`);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
render,
|
|
26
|
+
renderRequests
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default render;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import applyShowSerial from "./showSerial/index.js";
|
|
2
|
+
import applyShowOptions from "./showOptions/index.js";
|
|
3
|
+
import applyShowFooter from "./showFooter/index.js";
|
|
4
|
+
import applyShowFooterSave from "./showFooterSave/index.js";
|
|
5
|
+
|
|
6
|
+
const applyOptions = (inSpec, inOptions = {}, inColumns = []) => {
|
|
7
|
+
// console.log("inOptions : ", inOptions);
|
|
8
|
+
|
|
9
|
+
if (inOptions.showSerial) {
|
|
10
|
+
applyShowSerial(inSpec);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (inOptions.showOptions) {
|
|
14
|
+
applyShowOptions(inSpec, inOptions.showOptions);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (inOptions.showFooter) {
|
|
18
|
+
applyShowFooter(inSpec, inColumns, inOptions);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (inOptions.showFooterSave) {
|
|
22
|
+
applyShowFooterSave(inSpec, inColumns, inOptions);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return inSpec;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default applyOptions;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import tagJson from "./tag.json" with { type: "json" };
|
|
2
|
+
import buildFooterInput from "../input/index.js";
|
|
3
|
+
|
|
4
|
+
const buildFooterCell = ({ inColumn, inChildren = [] } = {}) => {
|
|
5
|
+
const td = structuredClone(tagJson);
|
|
6
|
+
|
|
7
|
+
if (inColumn !== undefined) {
|
|
8
|
+
td.children.push(buildFooterInput({ inColumn }));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
td.children.push(...inChildren);
|
|
12
|
+
|
|
13
|
+
return td;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default buildFooterCell;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import tagJson from "./tag.json" with { type: "json" };
|
|
2
|
+
import buildFooterRow from "../row/index.js";
|
|
3
|
+
|
|
4
|
+
const buildFooter = ({ inColumns = [], inOptions = {}, inSaveButton } = {}) => {
|
|
5
|
+
const tfoot = structuredClone(tagJson);
|
|
6
|
+
|
|
7
|
+
tfoot.children = [
|
|
8
|
+
buildFooterRow({
|
|
9
|
+
inColumns,
|
|
10
|
+
inOptions,
|
|
11
|
+
inSaveButton
|
|
12
|
+
})
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
return tfoot;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default buildFooter;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import tagJson from "./tag.json" with { type: "json" };
|
|
2
|
+
import buildFooterCell from "../cell/index.js";
|
|
3
|
+
|
|
4
|
+
const buildFooterRow = ({
|
|
5
|
+
inColumns = [],
|
|
6
|
+
inOptions = {},
|
|
7
|
+
inSaveButton
|
|
8
|
+
} = {}) => {
|
|
9
|
+
const tr = structuredClone(tagJson);
|
|
10
|
+
const columns = [...inColumns];
|
|
11
|
+
|
|
12
|
+
if (columns.length === 0 && inSaveButton) {
|
|
13
|
+
tr.children = [buildFooterCell({ inChildren: [inSaveButton] })];
|
|
14
|
+
return tr;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
tr.children = columns.map((column, index) => buildFooterCell({
|
|
18
|
+
inColumn: column,
|
|
19
|
+
inChildren: inSaveButton && index === columns.length - 1
|
|
20
|
+
? [inSaveButton]
|
|
21
|
+
: []
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
if (inOptions.showSerial) {
|
|
25
|
+
tr.children.unshift(buildFooterCell());
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (inOptions.showOptions) {
|
|
29
|
+
tr.children.push(buildFooterCell());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return tr;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default buildFooterRow;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import buildFooter from "../showFooter/footer/index.js";
|
|
2
|
+
import tagJson from "./button/tag.json" with { type: "json" };
|
|
3
|
+
|
|
4
|
+
const applyShowFooterSave = (inSpec, inColumns, inOptions) => {
|
|
5
|
+
const button = structuredClone(tagJson);
|
|
6
|
+
|
|
7
|
+
inSpec.children.push(buildFooter({
|
|
8
|
+
inColumns,
|
|
9
|
+
inOptions,
|
|
10
|
+
inSaveButton: button
|
|
11
|
+
}));
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default applyShowFooterSave;
|