json-renderers-build-table 1.17.3 → 1.22.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 (160) hide show
  1. package/README.md +197 -14
  2. package/package.json +3 -3
  3. package/src/index.js +2 -2
  4. package/src/v17/index.js +5 -5
  5. package/src/v17/simple/index.js +55 -55
  6. package/src/v17/spec.json +85 -85
  7. package/src/v18/bodyOnly/base.json +1 -0
  8. package/src/v18/bodyOnly/index.js +36 -0
  9. package/src/v18/bodyOnly/instructions/double.json +18 -0
  10. package/src/{v16 → v18/bodyOnly}/spec.json +86 -65
  11. package/src/{v16/common/writePath.js → v18/bodyOnly/writePath/index.js} +47 -55
  12. package/src/v18/headerOnly/index.js +42 -0
  13. package/src/{v15/simpleTable/config/instructions.json → v18/headerOnly/instructions/single.json} +8 -8
  14. package/src/{v14 → v18/headerOnly}/spec.json +22 -1
  15. package/src/{v14/buildSpec → v18/headerOnly}/writePath/index.js +8 -16
  16. package/src/v18/index.js +5 -0
  17. package/src/v18/simple/index.js +57 -0
  18. package/src/{v15/buildSpec/config/rowInstructions.json → v18/simple/instructions/double.json} +4 -5
  19. package/src/{v16/simpleTable/config/instructions.json → v18/simple/instructions/single.json} +38 -38
  20. package/src/{v15 → v18/simple}/spec.json +22 -1
  21. package/src/{v15/buildSpec → v18/simple}/writePath/index.js +8 -16
  22. package/src/v18/spec.json +86 -0
  23. package/src/v19/bodyOnly/base.json +1 -0
  24. package/src/v19/bodyOnly/index.js +36 -0
  25. package/src/v19/bodyOnly/instructions/double.json +18 -0
  26. package/src/v19/bodyOnly/spec.json +86 -0
  27. package/src/v19/headerOnly/index.js +42 -0
  28. package/src/{v14/buildSpec/config/columnInstructions.json → v19/headerOnly/instructions/single.json} +2 -20
  29. package/src/v19/headerOnly/spec.json +86 -0
  30. package/src/v19/index.js +5 -0
  31. package/src/v19/simple/index.js +57 -0
  32. package/src/{v15/tableHeadless/config/instructions.json → v19/simple/instructions/double.json} +4 -5
  33. package/src/v19/simple/instructions/single.json +38 -0
  34. package/src/v19/simple/spec.json +86 -0
  35. package/src/v19/spec.json +86 -0
  36. package/src/{v15/common/writePath.js → v19/writePath/index.js} +8 -16
  37. package/src/v20/bodyOnly/base.json +1 -0
  38. package/src/v20/bodyOnly/index.js +18 -0
  39. package/src/v20/bodyOnly/instructions/double.json +18 -0
  40. package/src/v20/bodyOnly/spec.json +86 -0
  41. package/src/v20/doubleInstruction/index.js +19 -0
  42. package/src/v20/headerOnly/base.json +53 -0
  43. package/src/v20/headerOnly/index.js +18 -0
  44. package/src/v20/headerOnly/instructions/single.json +38 -0
  45. package/src/v20/headerOnly/spec.json +86 -0
  46. package/src/v20/index.js +5 -0
  47. package/src/v20/simple/base.json +53 -0
  48. package/src/v20/simple/index.js +22 -0
  49. package/src/{v14/buildSpec/config/rowInstructions.json → v20/simple/instructions/double.json} +4 -5
  50. package/src/v20/simple/instructions/single.json +38 -0
  51. package/src/v20/simple/spec.json +86 -0
  52. package/src/v20/singleInstruction/index.js +17 -0
  53. package/src/v20/spec.json +86 -0
  54. package/src/v20/writePath/index.js +62 -0
  55. package/src/v21/bodyOnly/base.json +1 -0
  56. package/src/v21/bodyOnly/index.js +18 -0
  57. package/src/v21/bodyOnly/instructions/double.json +18 -0
  58. package/src/v21/bodyOnly/spec.json +86 -0
  59. package/src/v21/doubleInstruction/index.js +21 -0
  60. package/src/v21/guards/index.js +10 -0
  61. package/src/v21/guards/references/func/index.js +8 -0
  62. package/src/v21/guards/references/index.js +9 -0
  63. package/src/v21/guards/references/templateKey/index.js +8 -0
  64. package/src/v21/guards/structure/destinationPath/index.js +8 -0
  65. package/src/v21/guards/structure/func/index.js +8 -0
  66. package/src/v21/guards/structure/index.js +15 -0
  67. package/src/v21/guards/structure/sourcePath/index.js +8 -0
  68. package/src/v21/guards/structure/templateKey/index.js +9 -0
  69. package/src/v21/headerOnly/base.json +53 -0
  70. package/src/v21/headerOnly/index.js +18 -0
  71. package/src/v21/headerOnly/instructions/single.json +38 -0
  72. package/src/v21/headerOnly/spec.json +86 -0
  73. package/src/v21/index.js +5 -0
  74. package/src/v21/simple/base.json +53 -0
  75. package/src/v21/simple/index.js +22 -0
  76. package/src/v21/simple/instructions/double.json +19 -0
  77. package/src/v21/simple/instructions/single.json +38 -0
  78. package/src/v21/simple/spec.json +86 -0
  79. package/src/v21/singleInstruction/index.js +19 -0
  80. package/src/v21/spec.json +86 -0
  81. package/src/v21/writePath/index.js +62 -0
  82. package/src/v22/builders/bodyOnly/base.json +1 -0
  83. package/src/v22/builders/bodyOnly/index.js +18 -0
  84. package/src/v22/builders/bodyOnly/instructions/double.json +18 -0
  85. package/src/v22/builders/footerOnly/base.json +3 -0
  86. package/src/v22/builders/footerOnly/index.js +21 -0
  87. package/src/v22/builders/footerOnly/instructions/single.json +19 -0
  88. package/src/v22/builders/headerOnly/base.json +53 -0
  89. package/src/v22/builders/headerOnly/index.js +18 -0
  90. package/src/v22/builders/headerOnly/instructions/single.json +38 -0
  91. package/src/v22/builders/simple/base.json +53 -0
  92. package/src/v22/builders/simple/index.js +22 -0
  93. package/src/v22/builders/simple/instructions/double.json +19 -0
  94. package/src/v22/builders/simple/instructions/single.json +38 -0
  95. package/src/v22/builders/spec.json +86 -0
  96. package/src/v22/builders/withFooter/base.json +53 -0
  97. package/src/v22/builders/withFooter/index.js +22 -0
  98. package/src/v22/builders/withFooter/instructions/double.json +19 -0
  99. package/src/{v15/buildSpec/config/columnInstructions.json → v22/builders/withFooter/instructions/single.json} +3 -3
  100. package/src/v22/doubleInstruction/index.js +21 -0
  101. package/src/v22/guards/index.js +10 -0
  102. package/src/v22/guards/references/func/index.js +8 -0
  103. package/src/v22/guards/references/index.js +9 -0
  104. package/src/v22/guards/references/templateKey/index.js +8 -0
  105. package/src/v22/guards/structure/destinationPath/index.js +8 -0
  106. package/src/v22/guards/structure/func/index.js +8 -0
  107. package/src/v22/guards/structure/index.js +15 -0
  108. package/src/v22/guards/structure/sourcePath/index.js +8 -0
  109. package/src/v22/guards/structure/templateKey/index.js +9 -0
  110. package/src/v22/index.js +7 -0
  111. package/src/v22/singleInstruction/index.js +32 -0
  112. package/src/v22/spec.json +86 -0
  113. package/src/v22/writePath/index.js +62 -0
  114. package/src/v14/buildSpec/config/optionsInstructions.json +0 -82
  115. package/src/v14/buildSpec/config/serialInstructions.json +0 -82
  116. package/src/v14/buildSpec/index.js +0 -147
  117. package/src/v14/index.js +0 -56
  118. package/src/v14/register/index.js +0 -30
  119. package/src/v14/register/meta.js +0 -6
  120. package/src/v15/buildSpec/config/optionsInstructions.json +0 -82
  121. package/src/v15/buildSpec/config/serialInstructions.json +0 -82
  122. package/src/v15/buildSpec/index.js +0 -147
  123. package/src/v15/common/runner.js +0 -33
  124. package/src/v15/index.js +0 -85
  125. package/src/v15/register/index.js +0 -30
  126. package/src/v15/register/meta.js +0 -6
  127. package/src/v15/simpleTable/config/base.json +0 -31
  128. package/src/v15/simpleTable/index.js +0 -58
  129. package/src/v15/tableFullGrid/config/instructions.json +0 -234
  130. package/src/v15/tableFullGrid/index.js +0 -76
  131. package/src/v15/tableHeadless/config/base.json +0 -15
  132. package/src/v15/tableHeadless/index.js +0 -58
  133. package/src/v15/tableWithButtonCell/config/base.json +0 -38
  134. package/src/v15/tableWithButtonCell/config/instructions.json +0 -56
  135. package/src/v15/tableWithButtonCell/index.js +0 -57
  136. package/src/v15/tableWithFooter/config/instructions.json +0 -74
  137. package/src/v15/tableWithFooter/index.js +0 -58
  138. package/src/v15/tableWithOptions/config/base.json +0 -38
  139. package/src/v15/tableWithOptions/config/instructions.json +0 -116
  140. package/src/v15/tableWithOptions/index.js +0 -66
  141. package/src/v15/tableWithSerial/config/base.json +0 -38
  142. package/src/v15/tableWithSerial/config/instructions.json +0 -116
  143. package/src/v15/tableWithSerial/index.js +0 -66
  144. package/src/v15/tableWithWidths/config/base.json +0 -38
  145. package/src/v15/tableWithWidths/config/instructions.json +0 -56
  146. package/src/v15/tableWithWidths/index.js +0 -58
  147. package/src/v16/common/runner.js +0 -33
  148. package/src/v16/index.js +0 -7
  149. package/src/v16/simpleTable/config/base.json +0 -31
  150. package/src/v16/simpleTable/index.js +0 -58
  151. package/src/v16/tableWithOptions/config/base.json +0 -38
  152. package/src/v16/tableWithOptions/config/instructions.json +0 -116
  153. package/src/v16/tableWithOptions/index.js +0 -66
  154. package/src/v16/tableWithSerial/config/base.json +0 -38
  155. package/src/v16/tableWithSerial/config/instructions.json +0 -116
  156. package/src/v16/tableWithSerial/index.js +0 -66
  157. /package/src/{v14/buildSpec/config → v18/headerOnly}/base.json +0 -0
  158. /package/src/{v15/buildSpec/config → v18/simple}/base.json +0 -0
  159. /package/src/{v15/tableFullGrid/config → v19/headerOnly}/base.json +0 -0
  160. /package/src/{v15/tableWithFooter/config → v19/simple}/base.json +0 -0
package/README.md CHANGED
@@ -1,28 +1,211 @@
1
1
  # json-renderers-build-table
2
2
 
3
- Focused table specification builder extracted from the table work in `json-renderers-build`.
3
+ > Build a complete HTML table JSON specification from columns + data — declaratively.
4
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.
5
+ ---
6
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:
7
+ ## Why this exists
8
8
 
9
- ```js
10
- import render, { renderRequests } from "json-renderers-build-table";
9
+ Building a `<table>` from raw data is repetitive work that quickly becomes messy:
10
+
11
+ - You scatter `createElement` calls across your codebase
12
+ - Adding a column means touching the header, the body cells, the footer, and the colgroup
13
+ - Swapping a cell style for one column (e.g. a badge instead of plain text) means rewriting imperative DOM code
14
+ - Testing is hard because the logic is entangled with the DOM
15
+
16
+ This library inverts that. **You describe what the table should look like in JSON.** The library stamps it out.
17
+
18
+ The result is a plain JSON object — a DOM specification — that you hand to a renderer like [`@keshavsoft/json-to-tag`](https://keshavsoft.github.io/json-to-tag/dist/v9/min.js). The renderer turns it into real DOM elements. The builder never touches the DOM.
19
+
20
+ ---
21
+
22
+ ## The core idea: declarative instructions over a shared registry
23
+
24
+ Every build runs through three layers:
25
+
26
+ ```
27
+ 1. Registry holds { data, base, spec }
28
+ data = your columns + rows
29
+ base = the empty table skeleton (colgroup, thead, tbody, tfoot)
30
+ spec = named cell/row templates
31
+
32
+ 2. Instructions a JSON array that says:
33
+ "read THIS source path,
34
+ apply THIS template,
35
+ write the result to THIS destination"
36
+
37
+ 3. writePath navigates the base tree by data-role anchor
38
+ and writes using a named action
39
+ (set / push / unshift / pushToRows / ...)
40
+ ```
41
+
42
+ Because the instructions are JSON, you can read a build sequence without tracing any JavaScript. Each instruction has a `narration` field that explains itself in plain English.
11
43
 
12
- const request = structuredClone(renderRequests.tableWithSerialAndActions);
13
- request.data = [{ itemName: "0.11-25", baseUnit: "kgs" }];
44
+ ---
14
45
 
15
- const table = render(request);
46
+ ## How a table gets built (v18 `simple`)
47
+
48
+ ```
49
+ columns.json batches.json
50
+ \ /
51
+ simple({ columns, data })
52
+ |
53
+ | registry = { data, base, spec }
54
+ |
55
+ +-- single instructions (fromCollection)
56
+ | colgroup children (one <col> per column)
57
+ | thead > tr children (one <th> per column)
58
+ |
59
+ +-- double instructions (twoDimensional)
60
+ tbody children (one <tr> per row, one <td> per column)
61
+ |
62
+ +-- returns base (fully populated JSON tree)
16
63
  ```
17
64
 
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.
65
+ The returned `base` is a plain JavaScript object:
66
+
67
+ ```json
68
+ {
69
+ "tagName": "table",
70
+ "attributes": { "class": "table table-hover ..." },
71
+ "children": [
72
+ { "tagName": "colgroup", "children": [ "..." ] },
73
+ { "tagName": "thead", "children": [ { "tagName": "tr", "children": [ "..." ] } ] },
74
+ { "tagName": "tbody", "children": [ "..." ] },
75
+ { "tagName": "tfoot", "children": [ "..." ] }
76
+ ]
77
+ }
78
+ ```
19
79
 
20
- To add a footer row with one text input per column, enable `showFooter`:
80
+ Hand that to any spec-to-DOM renderer and you get a real table element.
81
+
82
+ ---
83
+
84
+ ## Quick start
21
85
 
22
86
  ```js
23
- const request = structuredClone(renderRequests.tableWithFooter);
24
- request.data = myData;
25
- const table = render(request);
87
+ import { simple } from "./docs/dist/v18/min.js";
88
+
89
+ const columns = [
90
+ {
91
+ columnName: "itemName",
92
+ width: "300px",
93
+ template: { body: { tr: "buildBodyTr", cell: "buildBodyCell" } }
94
+ },
95
+ {
96
+ columnName: "baseUnit",
97
+ width: "200px",
98
+ template: { body: { tr: "buildBodyTr", cell: "buildBodyCell" } }
99
+ },
100
+ {
101
+ columnName: "batches",
102
+ width: "100px",
103
+ template: { body: { tr: "buildBodyTr", cell: "buttonCell" } }
104
+ }
105
+ ];
106
+
107
+ const data = [
108
+ { itemName: "0.11-25", baseUnit: "kgs", batches: 1 },
109
+ { itemName: "0.11-30", baseUnit: "kgs", batches: 0 }
110
+ ];
111
+
112
+ const spec = simple({ columns, data });
113
+
114
+ // spec is a plain JSON tree — pass it to your DOM renderer
115
+ const element = window.ks.jsonToTag.buildSpecElement(spec);
116
+ document.getElementById("container").appendChild(element);
26
117
  ```
27
118
 
28
- Use `showFooterSave` to add a separate footer row with the same inputs and a Save button in the last input cell.
119
+ ---
120
+
121
+ ## What each column config means
122
+
123
+ | Field | Purpose |
124
+ |---|---|
125
+ | `columnName` | Maps to the data property on each row object |
126
+ | `width` | Written into the `<col>` element in the colgroup |
127
+ | `template.body.tr` | Key into `spec.json` — which `<tr>` template to use for body rows |
128
+ | `template.body.cell` | Key into `spec.json` — which `<td>` template to use for this column's cells |
129
+
130
+ You change the look of a column's cells by pointing `template.body.cell` at a different key in `spec.json`. No JavaScript changes needed.
131
+
132
+ ---
133
+
134
+ ## Cell templates (`spec.json`)
135
+
136
+ Pre-built templates in `src/v18/spec.json`:
137
+
138
+ | Key | Renders |
139
+ |---|---|
140
+ | `buildBodyCell` | Plain `<td>` with the row value as text |
141
+ | `buttonCell` | `<td>` containing a `<button>` showing the aggregate count |
142
+ | `buildHeader` | `<th>` with uppercase text |
143
+ | `buildColGroup` | `<col>` with a width attribute |
144
+ | `buildFooter` | `<td>` with a text `<input>` for footer rows |
145
+ | `buildOption` | `<option>` element |
146
+ | `buildSelect` | `<select>` container |
147
+ | `buildDataList` | `<datalist>` container |
148
+
149
+ ---
150
+
151
+ ## Why columns drive everything
152
+
153
+ A column definition is the single source of truth for **one vertical slice** of the table:
154
+
155
+ - its header cell (`buildHeader` template)
156
+ - its width (`buildColGroup` template)
157
+ - its body cell template (`template.body.cell`)
158
+ - its footer cell (if enabled)
159
+
160
+ Adding a column = adding one object to the columns array.
161
+ Removing a column = removing it.
162
+ The instructions loop over columns automatically.
163
+ There is no imperative "add a th, then add a td, then add a col" sequence to maintain.
164
+
165
+ ---
166
+
167
+ ## Build
168
+
169
+ ```bash
170
+ npm install
171
+ npm run build
172
+ # output: docs/dist/v18/min.js
173
+ ```
174
+
175
+ The Vite config auto-detects the highest `vN` folder under `src/` and builds that version. No config changes needed when a new version is added.
176
+
177
+ ---
178
+
179
+ ## Run the sample
180
+
181
+ ```bash
182
+ npx serve
183
+ # open http://localhost:PORT/samples/v18/simpleTable/
184
+ ```
185
+
186
+ ---
187
+
188
+ ## Project structure
189
+
190
+ ```
191
+ src/
192
+ v18/
193
+ index.js exports { simple }
194
+ spec.json named cell/row templates
195
+ simple/
196
+ index.js the build runner (registry + instructions)
197
+ base.json empty table skeleton with data-role anchors
198
+ instructions/
199
+ single.json fromCollection instructions (colgroup, thead)
200
+ double.json twoDimensional instruction (tbody)
201
+ writePath/
202
+ index.js tree writer with named actions
203
+
204
+ samples/
205
+ v18/
206
+ simpleTable/ live demo: columns.json + batches.json
207
+
208
+ docs/
209
+ dist/
210
+ v18/min.js pre-built bundle (committed, served via GitHub Pages)
211
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-renderers-build-table",
3
- "version": "1.17.3",
3
+ "version": "1.22.2",
4
4
  "description": "Focused table specification builder with configurable rows and cells",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -18,9 +18,9 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@keshavsoft/json-to-tag": "^1.9.3",
21
- "json-transformer-funcs": "^1.24.4",
21
+ "json-transformer-funcs": "^1.24.7",
22
22
  "json-transformer-funcs-one-dimension": "^1.5.2",
23
- "json-transformer-funcs-primitive": "^1.7.1",
23
+ "json-transformer-funcs-primitive": "^1.9.2",
24
24
  "json-transformer-funcs-two-dimensions": "^1.6.1"
25
25
  },
26
26
  "devDependencies": {
package/src/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./v17/index.js";
2
- export { default } from "./v17/index.js";
1
+ export * from "./v22/index.js";
2
+ export { default } from "./v22/index.js";
package/src/v17/index.js CHANGED
@@ -1,5 +1,5 @@
1
- // V16 exposes three focused table scenarios. Each scenario owns its config and instructions.
2
- // Only genuinely shared execution helpers live in ./common.
3
- import simple from "./simple/index.js";
4
-
5
- export { simple };
1
+ // V16 exposes three focused table scenarios. Each scenario owns its config and instructions.
2
+ // Only genuinely shared execution helpers live in ./common.
3
+ import simple from "./simple/index.js";
4
+
5
+ export { simple };
@@ -1,56 +1,56 @@
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
-
50
- runInstructions(singleInstructions);
51
- runInstructions2(twoDimensionalInstructions);
52
-
53
- return base;
54
- };
55
-
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
+
50
+ runInstructions(singleInstructions);
51
+ runInstructions2(twoDimensionalInstructions);
52
+
53
+ return base;
54
+ };
55
+
56
56
  export default startFunc;
package/src/v17/spec.json CHANGED
@@ -1,86 +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
- }
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
86
  }
@@ -0,0 +1 @@
1
+ []
@@ -0,0 +1,36 @@
1
+ import twoDimensional from "json-transformer-funcs-two-dimensions";
2
+
3
+ import spec from "../spec.json" with { type: "json" };
4
+ import base from "./base.json" with { type: "json" };
5
+
6
+ import twoDimensionalInstructions from "./instructions/double.json" with { type: "json" };
7
+
8
+ import writePath from "./writePath/index.js";
9
+
10
+ // 1. Keep the input, table structure, and templates together as the build context.
11
+ const registry = { data: {}, base, spec };
12
+ const functions = {
13
+ twoDimensional
14
+ };
15
+
16
+ const runInstructions2 = instructions => {
17
+ instructions.forEach(instruction => {
18
+ const result = functions[instruction.func](
19
+ registry.data.columns,
20
+ registry.data.data,
21
+ spec
22
+ );
23
+ writePath(registry, instruction.destinationPath, result);
24
+ });
25
+ };
26
+
27
+ // 3. Complete the table and return its JSON specification.
28
+ const startFunc = data => {
29
+ registry.data = data;
30
+
31
+ runInstructions2(twoDimensionalInstructions);
32
+
33
+ return base.children;
34
+ };
35
+
36
+ export default startFunc;
@@ -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
+ ]