json-renderers-build-table 1.9.1 → 1.19.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 +197 -14
- package/package.json +5 -2
- package/src/index.js +2 -3
- package/src/v17/index.js +5 -0
- package/src/v17/simple/base.json +53 -0
- package/src/v17/simple/index.js +56 -0
- package/src/v17/simple/instructions/double.json +19 -0
- package/src/v17/simple/instructions/single.json +38 -0
- package/src/v17/simple/spec.json +86 -0
- package/src/v17/simple/writePath/index.js +47 -0
- package/src/v17/spec.json +86 -0
- package/src/v18/bodyOnly/base.json +1 -0
- package/src/v18/bodyOnly/index.js +36 -0
- package/src/v18/bodyOnly/instructions/double.json +18 -0
- package/src/v18/bodyOnly/spec.json +86 -0
- package/src/v18/bodyOnly/writePath/index.js +47 -0
- package/src/v18/headerOnly/base.json +53 -0
- package/src/v18/headerOnly/index.js +42 -0
- package/src/v18/headerOnly/instructions/single.json +38 -0
- package/src/v18/headerOnly/spec.json +86 -0
- package/src/v18/headerOnly/writePath/index.js +47 -0
- package/src/v18/index.js +5 -0
- package/src/v18/simple/base.json +53 -0
- package/src/v18/simple/index.js +57 -0
- package/src/v18/simple/instructions/double.json +19 -0
- package/src/v18/simple/instructions/single.json +38 -0
- package/src/v18/simple/spec.json +86 -0
- package/src/v18/simple/writePath/index.js +47 -0
- package/src/v18/spec.json +86 -0
- package/src/v19/bodyOnly/base.json +1 -0
- package/src/v19/bodyOnly/index.js +36 -0
- package/src/v19/bodyOnly/instructions/double.json +18 -0
- package/src/v19/bodyOnly/spec.json +86 -0
- package/src/v19/headerOnly/base.json +53 -0
- package/src/v19/headerOnly/index.js +42 -0
- package/src/v19/headerOnly/instructions/single.json +38 -0
- package/src/v19/headerOnly/spec.json +86 -0
- package/src/v19/index.js +5 -0
- package/src/v19/simple/base.json +53 -0
- package/src/v19/simple/index.js +57 -0
- package/src/v19/simple/instructions/double.json +19 -0
- package/src/v19/simple/instructions/single.json +38 -0
- package/src/v19/simple/spec.json +86 -0
- package/src/v19/spec.json +86 -0
- package/src/v19/writePath/index.js +47 -0
- package/src/v5/index.js +0 -49
- package/src/v5/options/index.js +0 -18
- package/src/v5/options/showOptions/index.js +0 -39
- package/src/v5/options/showSerial/index.js +0 -19
- package/src/v5/render-requests.json +0 -70
- package/src/v5/table/body/cell/index.js +0 -12
- package/src/v5/table/body/cell/tag.json +0 -7
- package/src/v5/table/body/index.js +0 -17
- package/src/v5/table/body/row/index.js +0 -18
- package/src/v5/table/body/row/tag.json +0 -4
- package/src/v5/table/body/tag.json +0 -4
- package/src/v5/table/head/cell/index.js +0 -12
- package/src/v5/table/head/cell/tag.json +0 -7
- package/src/v5/table/head/index.js +0 -16
- package/src/v5/table/head/row/index.js +0 -14
- package/src/v5/table/head/row/tag.json +0 -4
- package/src/v5/table/head/tag.json +0 -4
- package/src/v5/table/index.js +0 -22
- package/src/v5/table/tag.json +0 -7
- package/src/v6/index.js +0 -29
- package/src/v6/options/index.js +0 -28
- package/src/v6/options/showFooter/cell/index.js +0 -16
- package/src/v6/options/showFooter/cell/tag.json +0 -4
- package/src/v6/options/showFooter/footer/index.js +0 -18
- package/src/v6/options/showFooter/footer/tag.json +0 -4
- package/src/v6/options/showFooter/index.js +0 -10
- package/src/v6/options/showFooter/input/index.js +0 -11
- package/src/v6/options/showFooter/input/tag.json +0 -7
- package/src/v6/options/showFooter/row/index.js +0 -35
- package/src/v6/options/showFooter/row/tag.json +0 -4
- package/src/v6/options/showFooterSave/button/tag.json +0 -7
- package/src/v6/options/showFooterSave/index.js +0 -14
- package/src/v6/options/showOptions/index.js +0 -39
- package/src/v6/options/showSerial/index.js +0 -19
- package/src/v6/render-requests.json +0 -90
- package/src/v6/table/body/cell/index.js +0 -12
- package/src/v6/table/body/cell/tag.json +0 -7
- package/src/v6/table/body/index.js +0 -17
- package/src/v6/table/body/row/index.js +0 -18
- package/src/v6/table/body/row/tag.json +0 -4
- package/src/v6/table/body/tag.json +0 -4
- package/src/v6/table/head/cell/index.js +0 -12
- package/src/v6/table/head/cell/tag.json +0 -7
- package/src/v6/table/head/index.js +0 -16
- package/src/v6/table/head/row/index.js +0 -14
- package/src/v6/table/head/row/tag.json +0 -4
- package/src/v6/table/head/tag.json +0 -4
- package/src/v6/table/index.js +0 -22
- package/src/v6/table/tag.json +0 -7
- package/src/v7/index.js +0 -29
- package/src/v7/options/index.js +0 -28
- package/src/v7/options/showFooter/cell/index.js +0 -16
- package/src/v7/options/showFooter/cell/tag.json +0 -4
- package/src/v7/options/showFooter/footer/index.js +0 -18
- package/src/v7/options/showFooter/footer/tag.json +0 -4
- package/src/v7/options/showFooter/index.js +0 -10
- package/src/v7/options/showFooter/input/index.js +0 -11
- package/src/v7/options/showFooter/input/tag.json +0 -7
- package/src/v7/options/showFooter/row/index.js +0 -35
- package/src/v7/options/showFooter/row/tag.json +0 -4
- package/src/v7/options/showFooterSave/button/tag.json +0 -7
- package/src/v7/options/showFooterSave/index.js +0 -14
- package/src/v7/options/showOptions/index.js +0 -39
- package/src/v7/options/showSerial/index.js +0 -19
- package/src/v7/render-requests.json +0 -90
- package/src/v7/table/body/cell/index.js +0 -12
- package/src/v7/table/body/cell/tag.json +0 -7
- package/src/v7/table/body/index.js +0 -17
- package/src/v7/table/body/row/index.js +0 -18
- package/src/v7/table/body/row/tag.json +0 -4
- package/src/v7/table/body/tag.json +0 -4
- package/src/v7/table/head/cell/index.js +0 -12
- package/src/v7/table/head/cell/tag.json +0 -7
- package/src/v7/table/head/index.js +0 -16
- package/src/v7/table/head/row/index.js +0 -14
- package/src/v7/table/head/row/tag.json +0 -4
- package/src/v7/table/head/tag.json +0 -4
- package/src/v7/table/index.js +0 -22
- package/src/v7/table/tag.json +0 -7
- package/src/v8/index.js +0 -29
- package/src/v8/options/index.js +0 -28
- package/src/v8/options/showFooter/cell/index.js +0 -16
- package/src/v8/options/showFooter/cell/tag.json +0 -4
- package/src/v8/options/showFooter/footer/index.js +0 -18
- package/src/v8/options/showFooter/footer/tag.json +0 -4
- package/src/v8/options/showFooter/index.js +0 -10
- package/src/v8/options/showFooter/input/index.js +0 -11
- package/src/v8/options/showFooter/input/tag.json +0 -7
- package/src/v8/options/showFooter/row/index.js +0 -35
- package/src/v8/options/showFooter/row/tag.json +0 -4
- package/src/v8/options/showFooterSave/button/tag.json +0 -7
- package/src/v8/options/showFooterSave/index.js +0 -14
- package/src/v8/options/showOptions/index.js +0 -39
- package/src/v8/options/showSerial/index.js +0 -19
- package/src/v8/render-requests.json +0 -90
- package/src/v8/table/body/cell/index.js +0 -12
- package/src/v8/table/body/cell/tag.json +0 -7
- package/src/v8/table/body/index.js +0 -17
- package/src/v8/table/body/row/index.js +0 -18
- package/src/v8/table/body/row/tag.json +0 -4
- package/src/v8/table/body/tag.json +0 -4
- package/src/v8/table/head/cell/index.js +0 -12
- package/src/v8/table/head/cell/tag.json +0 -7
- package/src/v8/table/head/index.js +0 -16
- package/src/v8/table/head/row/index.js +0 -14
- package/src/v8/table/head/row/tag.json +0 -4
- package/src/v8/table/head/tag.json +0 -4
- package/src/v8/table/index.js +0 -22
- package/src/v8/table/tag.json +0 -7
- package/src/v9/index.js +0 -28
- package/src/v9/table/index.js +0 -67
- package/src/v9/table/spec.json +0 -18
- package/src/v9/table/table.json +0 -24
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"narration": "Build the table body rows for the table using the configured columns and data.",
|
|
4
|
+
"destinationPath": {
|
|
5
|
+
"fileName": "base",
|
|
6
|
+
"filePath": [
|
|
7
|
+
"children"
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
"sourcePath": {
|
|
11
|
+
"fileName": "data",
|
|
12
|
+
"filePath": [
|
|
13
|
+
"columns"
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"func": "twoDimensional"
|
|
17
|
+
}
|
|
18
|
+
]
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
{
|
|
2
|
+
"buildBodyTr": {
|
|
3
|
+
"tagName": "tr",
|
|
4
|
+
"attributes": {
|
|
5
|
+
"class": "align-middle"
|
|
6
|
+
},
|
|
7
|
+
"children": []
|
|
8
|
+
},
|
|
9
|
+
"buildColGroup": {
|
|
10
|
+
"tagName": "col",
|
|
11
|
+
"attributes": {
|
|
12
|
+
"width": "${width}"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"buildHeader": {
|
|
16
|
+
"tagName": "th",
|
|
17
|
+
"textContent": "${columnName}",
|
|
18
|
+
"attributes": {
|
|
19
|
+
"class": "py-3 px-3 fw-semibold text-uppercase small"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"buildFooter": {
|
|
23
|
+
"tagName": "td",
|
|
24
|
+
"children": [
|
|
25
|
+
{
|
|
26
|
+
"tagName": "input",
|
|
27
|
+
"attributes": {
|
|
28
|
+
"type": "text",
|
|
29
|
+
"placeholder": "enter ${columnName}",
|
|
30
|
+
"name": "${columnName}",
|
|
31
|
+
"class": "form-control"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
"buildBodyCell": {
|
|
37
|
+
"tagName": "td",
|
|
38
|
+
"textContent": "${rowValue}",
|
|
39
|
+
"attributes": {
|
|
40
|
+
"class": "py-3 px-3 text-secondary"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"button": {
|
|
44
|
+
"tagName": "button",
|
|
45
|
+
"textContent": "${columnName}",
|
|
46
|
+
"attributes": {
|
|
47
|
+
"class": "btn btn-primary btn-sm"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"buttonCell": {
|
|
51
|
+
"tagName": "td",
|
|
52
|
+
"attributes": {
|
|
53
|
+
"class": "py-2 px-3 text-center"
|
|
54
|
+
},
|
|
55
|
+
"children": [
|
|
56
|
+
{
|
|
57
|
+
"tagName": "button",
|
|
58
|
+
"textContent": "${agg:count}",
|
|
59
|
+
"attributes": {
|
|
60
|
+
"class": "btn btn-primary btn-sm"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
"buildOption": {
|
|
66
|
+
"tagName": "option",
|
|
67
|
+
"textContent": "${rowValue}",
|
|
68
|
+
"attributes": {
|
|
69
|
+
"value": "${rowValue}"
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"buildSelect": {
|
|
73
|
+
"tagName": "select",
|
|
74
|
+
"attributes": {
|
|
75
|
+
"id": "LedgerName"
|
|
76
|
+
},
|
|
77
|
+
"children": []
|
|
78
|
+
},
|
|
79
|
+
"buildDataList": {
|
|
80
|
+
"tagName": "datalist",
|
|
81
|
+
"attributes": {
|
|
82
|
+
"data-name": "${columnName}"
|
|
83
|
+
},
|
|
84
|
+
"children": []
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { findByRole } from "json-transformer-funcs";
|
|
2
|
+
|
|
3
|
+
const toArray = val => (Array.isArray(val) ? val : [val]);
|
|
4
|
+
|
|
5
|
+
const actions = {
|
|
6
|
+
set: (parent, key, value) => {
|
|
7
|
+
parent[key] = value;
|
|
8
|
+
},
|
|
9
|
+
push: (parent, key, value) => {
|
|
10
|
+
parent[key].push(...toArray(value));
|
|
11
|
+
},
|
|
12
|
+
unshift: (parent, key, value) => {
|
|
13
|
+
parent[key].unshift(...toArray(value));
|
|
14
|
+
},
|
|
15
|
+
pushToRows: (parent, key, value) => {
|
|
16
|
+
parent[key].forEach(row => {
|
|
17
|
+
row.children.push(...structuredClone(toArray(value)));
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
unshiftToRows: (parent, key, value) => {
|
|
21
|
+
parent[key].forEach(row => {
|
|
22
|
+
row.children.unshift(...structuredClone(toArray(value)));
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
unshiftSerialToRows: (parent, key, value) => {
|
|
26
|
+
parent[key].forEach((row, rowIndex) => {
|
|
27
|
+
const item = structuredClone(value);
|
|
28
|
+
item.textContent = rowIndex + 1;
|
|
29
|
+
row.children.unshift(item);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const writePath = (registry, path, value) => {
|
|
35
|
+
const root = path.dataRole
|
|
36
|
+
? findByRole(registry[path.fileName], path.dataRole)
|
|
37
|
+
: registry[path.fileName];
|
|
38
|
+
|
|
39
|
+
const keys = [...(path.filePath ?? [])];
|
|
40
|
+
const lastKey = keys.pop();
|
|
41
|
+
const parent = keys.reduce((current, key) => current[key], root);
|
|
42
|
+
|
|
43
|
+
const actionHandler = actions[path.action] || actions.set;
|
|
44
|
+
actionHandler(parent, lastKey, value);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default writePath;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"tagName": "table",
|
|
3
|
+
"attributes": {
|
|
4
|
+
"class": "table table-hover table-striped align-middle border mb-0"
|
|
5
|
+
},
|
|
6
|
+
"children": [
|
|
7
|
+
{
|
|
8
|
+
"tagName": "colgroup",
|
|
9
|
+
"attributes": {
|
|
10
|
+
"data-role": "table-colgroup"
|
|
11
|
+
},
|
|
12
|
+
"children": []
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"tagName": "thead",
|
|
16
|
+
"attributes": {
|
|
17
|
+
"class": "table-dark",
|
|
18
|
+
"data-role": "table-header"
|
|
19
|
+
},
|
|
20
|
+
"children": [
|
|
21
|
+
{
|
|
22
|
+
"tagName": "tr",
|
|
23
|
+
"attributes": {
|
|
24
|
+
"data-role": "table-header-row"
|
|
25
|
+
},
|
|
26
|
+
"children": []
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"tagName": "tbody",
|
|
32
|
+
"attributes": {
|
|
33
|
+
"data-role": "table-body"
|
|
34
|
+
},
|
|
35
|
+
"children": []
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"tagName": "tfoot",
|
|
39
|
+
"attributes": {
|
|
40
|
+
"data-role": "table-footer"
|
|
41
|
+
},
|
|
42
|
+
"children": [
|
|
43
|
+
{
|
|
44
|
+
"tagName": "tr",
|
|
45
|
+
"attributes": {
|
|
46
|
+
"data-role": "table-footer-row"
|
|
47
|
+
},
|
|
48
|
+
"children": []
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import fromCollection from "json-transformer-funcs-one-dimension";
|
|
2
|
+
|
|
3
|
+
import { resolvePath } from "json-transformer-funcs";
|
|
4
|
+
|
|
5
|
+
import spec from "../spec.json" with { type: "json" };
|
|
6
|
+
import base from "./base.json" with { type: "json" };
|
|
7
|
+
|
|
8
|
+
import singleInstructions from "./instructions/single.json" with { type: "json" };
|
|
9
|
+
|
|
10
|
+
import writePath from "./writePath/index.js";
|
|
11
|
+
|
|
12
|
+
// 1. Keep the input, table structure, and templates together as the build context.
|
|
13
|
+
const registry = { data: {}, base, spec };
|
|
14
|
+
const functions = {
|
|
15
|
+
fromCollection
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// 2. Apply each instruction: read source, build result, write destination.
|
|
19
|
+
const runInstructions = instructions => {
|
|
20
|
+
instructions.forEach(instruction => {
|
|
21
|
+
const source = resolvePath(registry, instruction.sourcePath);
|
|
22
|
+
|
|
23
|
+
if (source) {
|
|
24
|
+
const result = functions[instruction.func](source, spec[instruction.templateKey]);
|
|
25
|
+
writePath(registry, instruction.destinationPath, result);
|
|
26
|
+
} else {
|
|
27
|
+
console.log(" !instruction : ", instruction);
|
|
28
|
+
console.log(" !source : ", source);
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// 3. Complete the table and return its JSON specification.
|
|
34
|
+
const startFunc = data => {
|
|
35
|
+
registry.data = data;
|
|
36
|
+
|
|
37
|
+
runInstructions(singleInstructions);
|
|
38
|
+
|
|
39
|
+
return base;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default startFunc;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"narration": "Build the column widths for the table using the configured columns.",
|
|
4
|
+
"destinationPath": {
|
|
5
|
+
"fileName": "base",
|
|
6
|
+
"dataRole": "table-colgroup",
|
|
7
|
+
"filePath": [
|
|
8
|
+
"children"
|
|
9
|
+
]
|
|
10
|
+
},
|
|
11
|
+
"sourcePath": {
|
|
12
|
+
"fileName": "data",
|
|
13
|
+
"filePath": [
|
|
14
|
+
"columns"
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
"templateKey": "buildColGroup",
|
|
18
|
+
"func": "fromCollection"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"narration": "Build the header row for the table using the configured columns.",
|
|
22
|
+
"destinationPath": {
|
|
23
|
+
"fileName": "base",
|
|
24
|
+
"dataRole": "table-header-row",
|
|
25
|
+
"filePath": [
|
|
26
|
+
"children"
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
"sourcePath": {
|
|
30
|
+
"fileName": "data",
|
|
31
|
+
"filePath": [
|
|
32
|
+
"columns"
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
"templateKey": "buildHeader",
|
|
36
|
+
"func": "fromCollection"
|
|
37
|
+
}
|
|
38
|
+
]
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
{
|
|
2
|
+
"buildBodyTr": {
|
|
3
|
+
"tagName": "tr",
|
|
4
|
+
"attributes": {
|
|
5
|
+
"class": "align-middle"
|
|
6
|
+
},
|
|
7
|
+
"children": []
|
|
8
|
+
},
|
|
9
|
+
"buildColGroup": {
|
|
10
|
+
"tagName": "col",
|
|
11
|
+
"attributes": {
|
|
12
|
+
"width": "${width}"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"buildHeader": {
|
|
16
|
+
"tagName": "th",
|
|
17
|
+
"textContent": "${columnName}",
|
|
18
|
+
"attributes": {
|
|
19
|
+
"class": "py-3 px-3 fw-semibold text-uppercase small"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"buildFooter": {
|
|
23
|
+
"tagName": "td",
|
|
24
|
+
"children": [
|
|
25
|
+
{
|
|
26
|
+
"tagName": "input",
|
|
27
|
+
"attributes": {
|
|
28
|
+
"type": "text",
|
|
29
|
+
"placeholder": "enter ${columnName}",
|
|
30
|
+
"name": "${columnName}",
|
|
31
|
+
"class": "form-control"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
"buildBodyCell": {
|
|
37
|
+
"tagName": "td",
|
|
38
|
+
"textContent": "${rowValue}",
|
|
39
|
+
"attributes": {
|
|
40
|
+
"class": "py-3 px-3 text-secondary"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"button": {
|
|
44
|
+
"tagName": "button",
|
|
45
|
+
"textContent": "${columnName}",
|
|
46
|
+
"attributes": {
|
|
47
|
+
"class": "btn btn-primary btn-sm"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"buttonCell": {
|
|
51
|
+
"tagName": "td",
|
|
52
|
+
"attributes": {
|
|
53
|
+
"class": "py-2 px-3 text-center"
|
|
54
|
+
},
|
|
55
|
+
"children": [
|
|
56
|
+
{
|
|
57
|
+
"tagName": "button",
|
|
58
|
+
"textContent": "${agg:count}",
|
|
59
|
+
"attributes": {
|
|
60
|
+
"class": "btn btn-primary btn-sm"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
"buildOption": {
|
|
66
|
+
"tagName": "option",
|
|
67
|
+
"textContent": "${rowValue}",
|
|
68
|
+
"attributes": {
|
|
69
|
+
"value": "${rowValue}"
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"buildSelect": {
|
|
73
|
+
"tagName": "select",
|
|
74
|
+
"attributes": {
|
|
75
|
+
"id": "LedgerName"
|
|
76
|
+
},
|
|
77
|
+
"children": []
|
|
78
|
+
},
|
|
79
|
+
"buildDataList": {
|
|
80
|
+
"tagName": "datalist",
|
|
81
|
+
"attributes": {
|
|
82
|
+
"data-name": "${columnName}"
|
|
83
|
+
},
|
|
84
|
+
"children": []
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { findByRole } from "json-transformer-funcs";
|
|
2
|
+
|
|
3
|
+
const toArray = val => (Array.isArray(val) ? val : [val]);
|
|
4
|
+
|
|
5
|
+
const actions = {
|
|
6
|
+
set: (parent, key, value) => {
|
|
7
|
+
parent[key] = value;
|
|
8
|
+
},
|
|
9
|
+
push: (parent, key, value) => {
|
|
10
|
+
parent[key].push(...toArray(value));
|
|
11
|
+
},
|
|
12
|
+
unshift: (parent, key, value) => {
|
|
13
|
+
parent[key].unshift(...toArray(value));
|
|
14
|
+
},
|
|
15
|
+
pushToRows: (parent, key, value) => {
|
|
16
|
+
parent[key].forEach(row => {
|
|
17
|
+
row.children.push(...structuredClone(toArray(value)));
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
unshiftToRows: (parent, key, value) => {
|
|
21
|
+
parent[key].forEach(row => {
|
|
22
|
+
row.children.unshift(...structuredClone(toArray(value)));
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
unshiftSerialToRows: (parent, key, value) => {
|
|
26
|
+
parent[key].forEach((row, rowIndex) => {
|
|
27
|
+
const item = structuredClone(value);
|
|
28
|
+
item.textContent = rowIndex + 1;
|
|
29
|
+
row.children.unshift(item);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const writePath = (registry, path, value) => {
|
|
35
|
+
const root = path.dataRole
|
|
36
|
+
? findByRole(registry[path.fileName], path.dataRole)
|
|
37
|
+
: registry[path.fileName];
|
|
38
|
+
|
|
39
|
+
const keys = [...(path.filePath ?? [])];
|
|
40
|
+
const lastKey = keys.pop();
|
|
41
|
+
const parent = keys.reduce((current, key) => current[key], root);
|
|
42
|
+
|
|
43
|
+
const actionHandler = actions[path.action] || actions.set;
|
|
44
|
+
actionHandler(parent, lastKey, value);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default writePath;
|
package/src/v18/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"tagName": "table",
|
|
3
|
+
"attributes": {
|
|
4
|
+
"class": "table table-hover table-striped align-middle border mb-0"
|
|
5
|
+
},
|
|
6
|
+
"children": [
|
|
7
|
+
{
|
|
8
|
+
"tagName": "colgroup",
|
|
9
|
+
"attributes": {
|
|
10
|
+
"data-role": "table-colgroup"
|
|
11
|
+
},
|
|
12
|
+
"children": []
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"tagName": "thead",
|
|
16
|
+
"attributes": {
|
|
17
|
+
"class": "table-dark",
|
|
18
|
+
"data-role": "table-header"
|
|
19
|
+
},
|
|
20
|
+
"children": [
|
|
21
|
+
{
|
|
22
|
+
"tagName": "tr",
|
|
23
|
+
"attributes": {
|
|
24
|
+
"data-role": "table-header-row"
|
|
25
|
+
},
|
|
26
|
+
"children": []
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"tagName": "tbody",
|
|
32
|
+
"attributes": {
|
|
33
|
+
"data-role": "table-body"
|
|
34
|
+
},
|
|
35
|
+
"children": []
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"tagName": "tfoot",
|
|
39
|
+
"attributes": {
|
|
40
|
+
"data-role": "table-footer"
|
|
41
|
+
},
|
|
42
|
+
"children": [
|
|
43
|
+
{
|
|
44
|
+
"tagName": "tr",
|
|
45
|
+
"attributes": {
|
|
46
|
+
"data-role": "table-footer-row"
|
|
47
|
+
},
|
|
48
|
+
"children": []
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import fromCollection from "json-transformer-funcs-one-dimension";
|
|
2
|
+
import twoDimensional from "json-transformer-funcs-two-dimensions";
|
|
3
|
+
|
|
4
|
+
import { resolvePath } from "json-transformer-funcs";
|
|
5
|
+
|
|
6
|
+
import spec from "../spec.json" with { type: "json" };
|
|
7
|
+
import base from "./base.json" with { type: "json" };
|
|
8
|
+
|
|
9
|
+
import singleInstructions from "./instructions/single.json" with { type: "json" };
|
|
10
|
+
import twoDimensionalInstructions from "./instructions/double.json" with { type: "json" };
|
|
11
|
+
|
|
12
|
+
import writePath from "./writePath/index.js";
|
|
13
|
+
|
|
14
|
+
// 1. Keep the input, table structure, and templates together as the build context.
|
|
15
|
+
const registry = { data: {}, base, spec };
|
|
16
|
+
const functions = {
|
|
17
|
+
fromCollection, twoDimensional
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// 2. Apply each instruction: read source, build result, write destination.
|
|
21
|
+
const runInstructions = instructions => {
|
|
22
|
+
instructions.forEach(instruction => {
|
|
23
|
+
const source = resolvePath(registry, instruction.sourcePath);
|
|
24
|
+
|
|
25
|
+
if (source) {
|
|
26
|
+
const result = functions[instruction.func](source, spec[instruction.templateKey]);
|
|
27
|
+
writePath(registry, instruction.destinationPath, result);
|
|
28
|
+
} else {
|
|
29
|
+
console.log(" !instruction : ", instruction);
|
|
30
|
+
console.log(" !source : ", source);
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const runInstructions2 = instructions => {
|
|
36
|
+
instructions.forEach(instruction => {
|
|
37
|
+
const result = functions[instruction.func](
|
|
38
|
+
registry.data.columns,
|
|
39
|
+
registry.data.data,
|
|
40
|
+
spec
|
|
41
|
+
);
|
|
42
|
+
writePath(registry, instruction.destinationPath, result);
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// 3. Complete the table and return its JSON specification.
|
|
47
|
+
const startFunc = data => {
|
|
48
|
+
registry.data = data;
|
|
49
|
+
console.log("registry : ", registry);
|
|
50
|
+
|
|
51
|
+
runInstructions(singleInstructions);
|
|
52
|
+
runInstructions2(twoDimensionalInstructions);
|
|
53
|
+
|
|
54
|
+
return base;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default startFunc;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"narration": "Build the table body rows for the table using the configured columns and data.",
|
|
4
|
+
"destinationPath": {
|
|
5
|
+
"fileName": "base",
|
|
6
|
+
"dataRole": "table-body",
|
|
7
|
+
"filePath": [
|
|
8
|
+
"children"
|
|
9
|
+
]
|
|
10
|
+
},
|
|
11
|
+
"sourcePath": {
|
|
12
|
+
"fileName": "data",
|
|
13
|
+
"filePath": [
|
|
14
|
+
"columns"
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
"func": "twoDimensional"
|
|
18
|
+
}
|
|
19
|
+
]
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"narration": "Build the column widths for the table using the configured columns.",
|
|
4
|
+
"destinationPath": {
|
|
5
|
+
"fileName": "base",
|
|
6
|
+
"dataRole": "table-colgroup",
|
|
7
|
+
"filePath": [
|
|
8
|
+
"children"
|
|
9
|
+
]
|
|
10
|
+
},
|
|
11
|
+
"sourcePath": {
|
|
12
|
+
"fileName": "data",
|
|
13
|
+
"filePath": [
|
|
14
|
+
"columns"
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
"templateKey": "buildColGroup",
|
|
18
|
+
"func": "fromCollection"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"narration": "Build the header row for the table using the configured columns.",
|
|
22
|
+
"destinationPath": {
|
|
23
|
+
"fileName": "base",
|
|
24
|
+
"dataRole": "table-header-row",
|
|
25
|
+
"filePath": [
|
|
26
|
+
"children"
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
"sourcePath": {
|
|
30
|
+
"fileName": "data",
|
|
31
|
+
"filePath": [
|
|
32
|
+
"columns"
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
"templateKey": "buildHeader",
|
|
36
|
+
"func": "fromCollection"
|
|
37
|
+
}
|
|
38
|
+
]
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
{
|
|
2
|
+
"buildBodyTr": {
|
|
3
|
+
"tagName": "tr",
|
|
4
|
+
"attributes": {
|
|
5
|
+
"class": "align-middle"
|
|
6
|
+
},
|
|
7
|
+
"children": []
|
|
8
|
+
},
|
|
9
|
+
"buildColGroup": {
|
|
10
|
+
"tagName": "col",
|
|
11
|
+
"attributes": {
|
|
12
|
+
"width": "${width}"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"buildHeader": {
|
|
16
|
+
"tagName": "th",
|
|
17
|
+
"textContent": "${columnName}",
|
|
18
|
+
"attributes": {
|
|
19
|
+
"class": "py-3 px-3 fw-semibold text-uppercase small"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"buildFooter": {
|
|
23
|
+
"tagName": "td",
|
|
24
|
+
"children": [
|
|
25
|
+
{
|
|
26
|
+
"tagName": "input",
|
|
27
|
+
"attributes": {
|
|
28
|
+
"type": "text",
|
|
29
|
+
"placeholder": "enter ${columnName}",
|
|
30
|
+
"name": "${columnName}",
|
|
31
|
+
"class": "form-control"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
"buildBodyCell": {
|
|
37
|
+
"tagName": "td",
|
|
38
|
+
"textContent": "${rowValue}",
|
|
39
|
+
"attributes": {
|
|
40
|
+
"class": "py-3 px-3 text-secondary"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"button": {
|
|
44
|
+
"tagName": "button",
|
|
45
|
+
"textContent": "${columnName}",
|
|
46
|
+
"attributes": {
|
|
47
|
+
"class": "btn btn-primary btn-sm"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"buttonCell": {
|
|
51
|
+
"tagName": "td",
|
|
52
|
+
"attributes": {
|
|
53
|
+
"class": "py-2 px-3 text-center"
|
|
54
|
+
},
|
|
55
|
+
"children": [
|
|
56
|
+
{
|
|
57
|
+
"tagName": "button",
|
|
58
|
+
"textContent": "${agg:count}",
|
|
59
|
+
"attributes": {
|
|
60
|
+
"class": "btn btn-primary btn-sm"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
"buildOption": {
|
|
66
|
+
"tagName": "option",
|
|
67
|
+
"textContent": "${rowValue}",
|
|
68
|
+
"attributes": {
|
|
69
|
+
"value": "${rowValue}"
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
"buildSelect": {
|
|
73
|
+
"tagName": "select",
|
|
74
|
+
"attributes": {
|
|
75
|
+
"id": "LedgerName"
|
|
76
|
+
},
|
|
77
|
+
"children": []
|
|
78
|
+
},
|
|
79
|
+
"buildDataList": {
|
|
80
|
+
"tagName": "datalist",
|
|
81
|
+
"attributes": {
|
|
82
|
+
"data-name": "${columnName}"
|
|
83
|
+
},
|
|
84
|
+
"children": []
|
|
85
|
+
}
|
|
86
|
+
}
|