json-instructions 0.0.0-stage → 1.2.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 CHANGED
@@ -1,3 +1,211 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # json-renderers-build-table
2
+
3
+ > Build a complete HTML table JSON specification from columns + data — declaratively.
4
+
5
+ ---
6
+
7
+ ## Why this exists
8
+
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.
43
+
44
+ ---
45
+
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)
63
+ ```
64
+
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
+ ```
79
+
80
+ Hand that to any spec-to-DOM renderer and you get a real table element.
81
+
82
+ ---
83
+
84
+ ## Quick start
85
+
86
+ ```js
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);
117
+ ```
118
+
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,26 @@
1
- {
2
- "name": "json-instructions",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "json-instructions",
3
+ "version": "1.2.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/v24/index.js",
16
+ "dev": "vite",
17
+ "build": "vite build"
18
+ },
19
+ "dependencies": {
20
+ "json-transformer-funcs": "^1.24.8",
21
+ "json-transformer-funcs-primitive": "^1.9.3"
22
+ },
23
+ "devDependencies": {
24
+ "vite": "^8.3.4"
25
+ }
26
+ }
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./v2/index.js";
2
+ export { default } from "./v2/index.js";
@@ -0,0 +1,25 @@
1
+ import insertSerial from "./insertSerial/index.js";
2
+ import insertOptions from "./insertOptions/index.js";
3
+ import insertSearch from "./insertSearch/index.js";
4
+
5
+ const startFunc = ({ inOptions = {}, inBase, showLog = false, returnLog = [] }) => {
6
+ const localOptions = inOptions;
7
+
8
+ const localBase = inBase;
9
+
10
+ if (localOptions.showSerial || localOptions.serial) {
11
+ insertSerial(localBase, localOptions.serial || {}, showLog, returnLog);
12
+ }
13
+
14
+ if (localOptions.showOptions || localOptions.options) {
15
+ insertOptions(localBase, localOptions.options || {}, showLog, returnLog);
16
+ };
17
+
18
+ if (localOptions.showSearch) {
19
+ insertSearch();
20
+ };
21
+
22
+ return localBase;
23
+ };
24
+
25
+ export default startFunc;
@@ -0,0 +1,47 @@
1
+ import applyTemplate from "json-transformer-funcs-primitive";
2
+ import { findByRole } from "json-transformer-funcs";
3
+
4
+ import spec from "../../builders/spec.json" with { type: "json" };
5
+ import singleInstructions from "./instructions/single.json" with { type: "json" };
6
+ import footerInstructions from "./instructions/footer.json" with { type: "json" };
7
+
8
+ import runSingleInstructions from "../../singleInstruction/index.js";
9
+
10
+ const functions = { applyTemplate };
11
+
12
+ const insertOptions = (input = {}, config = {}, showLog = false, returnLog = []) => {
13
+ let localTableSpec = input;
14
+ let localOptions = config;
15
+
16
+ if (input && typeof input === "object" && "inTableSpec" in input) {
17
+ localTableSpec = input.inTableSpec;
18
+ localOptions = input.inOptions || config;
19
+ }
20
+
21
+ const localOptionsMerged = {
22
+ col: { width: "100px" },
23
+ header: { columnName: "options" },
24
+ body: { columnName: "show" },
25
+ footer: {},
26
+ ...localOptions
27
+ };
28
+
29
+ const registry = {
30
+ data: {
31
+ options: localOptionsMerged
32
+ },
33
+ base: localTableSpec,
34
+ spec
35
+ };
36
+
37
+ runSingleInstructions(singleInstructions, registry, functions, spec, showLog, returnLog);
38
+
39
+ const footerRow = findByRole(localTableSpec, "table-footer-row");
40
+ if (footerRow && Array.isArray(footerRow.children) && footerRow.children.length > 0) {
41
+ runSingleInstructions(footerInstructions, registry, functions, spec, showLog, returnLog);
42
+ }
43
+
44
+ return localTableSpec;
45
+ };
46
+
47
+ export default insertOptions;
@@ -0,0 +1,22 @@
1
+ [
2
+ {
3
+ "narration": "Append an empty cell into the table footer row if footer row is present.",
4
+ "destinationPath": {
5
+ "fileName": "base",
6
+ "dataRole": "table-footer-row",
7
+ "filePath": [
8
+ "children"
9
+ ],
10
+ "action": "push"
11
+ },
12
+ "sourcePath": {
13
+ "fileName": "data",
14
+ "filePath": [
15
+ "options",
16
+ "footer"
17
+ ]
18
+ },
19
+ "templateKey": "emptyCell",
20
+ "func": "applyTemplate"
21
+ }
22
+ ]
@@ -0,0 +1,62 @@
1
+ [
2
+ {
3
+ "narration": "Append the options column width to the table colgroup.",
4
+ "destinationPath": {
5
+ "fileName": "base",
6
+ "dataRole": "table-colgroup",
7
+ "filePath": [
8
+ "children"
9
+ ],
10
+ "action": "push"
11
+ },
12
+ "sourcePath": {
13
+ "fileName": "data",
14
+ "filePath": [
15
+ "options",
16
+ "col"
17
+ ]
18
+ },
19
+ "templateKey": "buildColGroup",
20
+ "func": "applyTemplate"
21
+ },
22
+ {
23
+ "narration": "Append the options header cell to the table header row.",
24
+ "destinationPath": {
25
+ "fileName": "base",
26
+ "dataRole": "table-header-row",
27
+ "filePath": [
28
+ "children"
29
+ ],
30
+ "action": "push"
31
+ },
32
+ "sourcePath": {
33
+ "fileName": "data",
34
+ "filePath": [
35
+ "options",
36
+ "header"
37
+ ]
38
+ },
39
+ "templateKey": "buildHeader",
40
+ "func": "applyTemplate"
41
+ },
42
+ {
43
+ "narration": "Append the options button cell into each table body row.",
44
+ "destinationPath": {
45
+ "fileName": "base",
46
+ "dataRole": "table-body",
47
+ "filePath": [
48
+ "children"
49
+ ],
50
+ "action": "pushToRows"
51
+ },
52
+ "sourcePath": {
53
+ "fileName": "data",
54
+ "filePath": [
55
+ "options",
56
+ "body"
57
+ ]
58
+ },
59
+ "templateKey": "optionsButtonCell",
60
+ "func": "applyTemplate"
61
+ }
62
+ ]
@@ -0,0 +1,7 @@
1
+ import template from "./instructions/template.json" with { type: "json" };
2
+
3
+ const startFunc = (input = {}, config = {}, showLog = false, returnLog = []) => {
4
+ return template;
5
+ };
6
+
7
+ export default startFunc;
@@ -0,0 +1,20 @@
1
+ {
2
+ "tagName": "div",
3
+ "children": [
4
+ {
5
+ "tagName": "label",
6
+ "textContent": "KeshavSoft"
7
+ },
8
+ {
9
+ "tagName": "input",
10
+ "attributes": {
11
+ "value": "KeshavSoft",
12
+ "placeholder": "KeshavSoft"
13
+ }
14
+ },
15
+ {
16
+ "tagName": "button",
17
+ "textContent": "show"
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,47 @@
1
+ import applyTemplate from "json-transformer-funcs-primitive";
2
+ import { findByRole } from "json-transformer-funcs";
3
+
4
+ import spec from "../../builders/spec.json" with { type: "json" };
5
+ import singleInstructions from "./instructions/single.json" with { type: "json" };
6
+ import footerInstructions from "./instructions/footer.json" with { type: "json" };
7
+
8
+ import runSingleInstructions from "../../singleInstruction/index.js";
9
+
10
+ const functions = { applyTemplate };
11
+
12
+ const insertSerial = (input = {}, config = {}, showLog = false, returnLog = []) => {
13
+ let localTableSpec = input;
14
+ let localSerial = config;
15
+
16
+ if (input && typeof input === "object" && "inTableSpec" in input) {
17
+ localTableSpec = input.inTableSpec;
18
+ localSerial = input.inSerial || config;
19
+ }
20
+
21
+ const localSerialMerged = {
22
+ col: { width: "50px" },
23
+ header: { columnName: "#" },
24
+ body: {},
25
+ footer: {},
26
+ ...localSerial
27
+ };
28
+
29
+ const registry = {
30
+ data: {
31
+ serial: localSerialMerged
32
+ },
33
+ base: localTableSpec,
34
+ spec
35
+ };
36
+
37
+ runSingleInstructions(singleInstructions, registry, functions, spec, showLog, returnLog);
38
+
39
+ const footerRow = findByRole(localTableSpec, "table-footer-row");
40
+ if (footerRow && Array.isArray(footerRow.children) && footerRow.children.length > 0) {
41
+ runSingleInstructions(footerInstructions, registry, functions, spec, showLog, returnLog);
42
+ }
43
+
44
+ return localTableSpec;
45
+ };
46
+
47
+ export default insertSerial;
@@ -0,0 +1,22 @@
1
+ [
2
+ {
3
+ "narration": "Prepend an empty cell into the table footer row if footer row is present.",
4
+ "destinationPath": {
5
+ "fileName": "base",
6
+ "dataRole": "table-footer-row",
7
+ "filePath": [
8
+ "children"
9
+ ],
10
+ "action": "unshift"
11
+ },
12
+ "sourcePath": {
13
+ "fileName": "data",
14
+ "filePath": [
15
+ "serial",
16
+ "footer"
17
+ ]
18
+ },
19
+ "templateKey": "emptyCell",
20
+ "func": "applyTemplate"
21
+ }
22
+ ]
@@ -0,0 +1,62 @@
1
+ [
2
+ {
3
+ "narration": "Prepend the serial column width to the table colgroup.",
4
+ "destinationPath": {
5
+ "fileName": "base",
6
+ "dataRole": "table-colgroup",
7
+ "filePath": [
8
+ "children"
9
+ ],
10
+ "action": "unshift"
11
+ },
12
+ "sourcePath": {
13
+ "fileName": "data",
14
+ "filePath": [
15
+ "serial",
16
+ "col"
17
+ ]
18
+ },
19
+ "templateKey": "buildColGroup",
20
+ "func": "applyTemplate"
21
+ },
22
+ {
23
+ "narration": "Prepend the serial header cell to the table header row.",
24
+ "destinationPath": {
25
+ "fileName": "base",
26
+ "dataRole": "table-header-row",
27
+ "filePath": [
28
+ "children"
29
+ ],
30
+ "action": "unshift"
31
+ },
32
+ "sourcePath": {
33
+ "fileName": "data",
34
+ "filePath": [
35
+ "serial",
36
+ "header"
37
+ ]
38
+ },
39
+ "templateKey": "buildHeader",
40
+ "func": "applyTemplate"
41
+ },
42
+ {
43
+ "narration": "Prepend the serial number cell into each table body row.",
44
+ "destinationPath": {
45
+ "fileName": "base",
46
+ "dataRole": "table-body",
47
+ "filePath": [
48
+ "children"
49
+ ],
50
+ "action": "unshiftSerialToRows"
51
+ },
52
+ "sourcePath": {
53
+ "fileName": "data",
54
+ "filePath": [
55
+ "serial",
56
+ "body"
57
+ ]
58
+ },
59
+ "templateKey": "buildBodyCell",
60
+ "func": "applyTemplate"
61
+ }
62
+ ]
@@ -0,0 +1,21 @@
1
+ import simple from "./builders/simple/index.js";
2
+ import headerOnly from "./builders/headerOnly/index.js";
3
+ import bodyOnly from "./builders/bodyOnly/index.js";
4
+ import withFooter from "./builders/withFooter/index.js";
5
+ import footerOnly from "./builders/footerOnly/index.js";
6
+
7
+ export {
8
+ simple,
9
+ headerOnly,
10
+ bodyOnly,
11
+ withFooter,
12
+ footerOnly
13
+ };
14
+
15
+ export default {
16
+ simple,
17
+ headerOnly,
18
+ bodyOnly,
19
+ withFooter,
20
+ footerOnly
21
+ };
@@ -0,0 +1,25 @@
1
+ import insertSerial from "./insertSerial/index.js";
2
+ import insertOptions from "./insertOptions/index.js";
3
+ import insertSearch from "./insertSearch/index.js";
4
+
5
+ const startFunc = ({ inOptions = {}, inBase, showLog = false, returnLog = [] }) => {
6
+ const localOptions = inOptions;
7
+
8
+ const localBase = inBase;
9
+
10
+ if (localOptions.showSerial || localOptions.serial) {
11
+ insertSerial(localBase, localOptions.serial || {}, showLog, returnLog);
12
+ }
13
+
14
+ if (localOptions.showOptions || localOptions.options) {
15
+ insertOptions(localBase, localOptions.options || {}, showLog, returnLog);
16
+ };
17
+
18
+ if (localOptions.showSearch) {
19
+ insertSearch();
20
+ };
21
+
22
+ return localBase;
23
+ };
24
+
25
+ export default startFunc;
@@ -0,0 +1,47 @@
1
+ import applyTemplate from "json-transformer-funcs-primitive";
2
+ import { findByRole } from "json-transformer-funcs";
3
+
4
+ import spec from "../../../spec.json" with { type: "json" };
5
+ import singleInstructions from "./instructions/single.json" with { type: "json" };
6
+ import footerInstructions from "./instructions/footer.json" with { type: "json" };
7
+
8
+ import runSingleInstructions from "../../singleInstruction/index.js";
9
+
10
+ const functions = { applyTemplate };
11
+
12
+ const insertOptions = (input = {}, config = {}, showLog = false, returnLog = []) => {
13
+ let localTableSpec = input;
14
+ let localOptions = config;
15
+
16
+ if (input && typeof input === "object" && "inTableSpec" in input) {
17
+ localTableSpec = input.inTableSpec;
18
+ localOptions = input.inOptions || config;
19
+ }
20
+
21
+ const localOptionsMerged = {
22
+ col: { width: "100px" },
23
+ header: { columnName: "options" },
24
+ body: { columnName: "show" },
25
+ footer: {},
26
+ ...localOptions
27
+ };
28
+
29
+ const registry = {
30
+ data: {
31
+ options: localOptionsMerged
32
+ },
33
+ base: localTableSpec,
34
+ spec
35
+ };
36
+
37
+ runSingleInstructions(singleInstructions, registry, functions, spec, showLog, returnLog);
38
+
39
+ const footerRow = findByRole(localTableSpec, "table-footer-row");
40
+ if (footerRow && Array.isArray(footerRow.children) && footerRow.children.length > 0) {
41
+ runSingleInstructions(footerInstructions, registry, functions, spec, showLog, returnLog);
42
+ }
43
+
44
+ return localTableSpec;
45
+ };
46
+
47
+ export default insertOptions;
@@ -0,0 +1,22 @@
1
+ [
2
+ {
3
+ "narration": "Append an empty cell into the table footer row if footer row is present.",
4
+ "destinationPath": {
5
+ "fileName": "base",
6
+ "dataRole": "table-footer-row",
7
+ "filePath": [
8
+ "children"
9
+ ],
10
+ "action": "push"
11
+ },
12
+ "sourcePath": {
13
+ "fileName": "data",
14
+ "filePath": [
15
+ "options",
16
+ "footer"
17
+ ]
18
+ },
19
+ "templateKey": "emptyCell",
20
+ "func": "applyTemplate"
21
+ }
22
+ ]
@@ -0,0 +1,62 @@
1
+ [
2
+ {
3
+ "narration": "Append the options column width to the table colgroup.",
4
+ "destinationPath": {
5
+ "fileName": "base",
6
+ "dataRole": "table-colgroup",
7
+ "filePath": [
8
+ "children"
9
+ ],
10
+ "action": "push"
11
+ },
12
+ "sourcePath": {
13
+ "fileName": "data",
14
+ "filePath": [
15
+ "options",
16
+ "col"
17
+ ]
18
+ },
19
+ "templateKey": "buildColGroup",
20
+ "func": "applyTemplate"
21
+ },
22
+ {
23
+ "narration": "Append the options header cell to the table header row.",
24
+ "destinationPath": {
25
+ "fileName": "base",
26
+ "dataRole": "table-header-row",
27
+ "filePath": [
28
+ "children"
29
+ ],
30
+ "action": "push"
31
+ },
32
+ "sourcePath": {
33
+ "fileName": "data",
34
+ "filePath": [
35
+ "options",
36
+ "header"
37
+ ]
38
+ },
39
+ "templateKey": "buildHeader",
40
+ "func": "applyTemplate"
41
+ },
42
+ {
43
+ "narration": "Append the options button cell into each table body row.",
44
+ "destinationPath": {
45
+ "fileName": "base",
46
+ "dataRole": "table-body",
47
+ "filePath": [
48
+ "children"
49
+ ],
50
+ "action": "pushToRows"
51
+ },
52
+ "sourcePath": {
53
+ "fileName": "data",
54
+ "filePath": [
55
+ "options",
56
+ "body"
57
+ ]
58
+ },
59
+ "templateKey": "optionsButtonCell",
60
+ "func": "applyTemplate"
61
+ }
62
+ ]
@@ -0,0 +1,7 @@
1
+ import template from "./instructions/template.json" with { type: "json" };
2
+
3
+ const startFunc = (input = {}, config = {}, showLog = false, returnLog = []) => {
4
+ return template;
5
+ };
6
+
7
+ export default startFunc;
@@ -0,0 +1,20 @@
1
+ {
2
+ "tagName": "div",
3
+ "children": [
4
+ {
5
+ "tagName": "label",
6
+ "textContent": "KeshavSoft"
7
+ },
8
+ {
9
+ "tagName": "input",
10
+ "attributes": {
11
+ "value": "KeshavSoft",
12
+ "placeholder": "KeshavSoft"
13
+ }
14
+ },
15
+ {
16
+ "tagName": "button",
17
+ "textContent": "show"
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,47 @@
1
+ import applyTemplate from "json-transformer-funcs-primitive";
2
+ import { findByRole } from "json-transformer-funcs";
3
+
4
+ import spec from "../../../spec.json" with { type: "json" };
5
+ import singleInstructions from "./instructions/single.json" with { type: "json" };
6
+ import footerInstructions from "./instructions/footer.json" with { type: "json" };
7
+
8
+ import runSingleInstructions from "../../singleInstruction/index.js";
9
+
10
+ const functions = { applyTemplate };
11
+
12
+ const insertSerial = (input = {}, config = {}, showLog = false, returnLog = []) => {
13
+ let localTableSpec = input;
14
+ let localSerial = config;
15
+
16
+ if (input && typeof input === "object" && "inTableSpec" in input) {
17
+ localTableSpec = input.inTableSpec;
18
+ localSerial = input.inSerial || config;
19
+ }
20
+
21
+ const localSerialMerged = {
22
+ col: { width: "50px" },
23
+ header: { columnName: "#" },
24
+ body: {},
25
+ footer: {},
26
+ ...localSerial
27
+ };
28
+
29
+ const registry = {
30
+ data: {
31
+ serial: localSerialMerged
32
+ },
33
+ base: localTableSpec,
34
+ spec
35
+ };
36
+
37
+ runSingleInstructions(singleInstructions, registry, functions, spec, showLog, returnLog);
38
+
39
+ const footerRow = findByRole(localTableSpec, "table-footer-row");
40
+ if (footerRow && Array.isArray(footerRow.children) && footerRow.children.length > 0) {
41
+ runSingleInstructions(footerInstructions, registry, functions, spec, showLog, returnLog);
42
+ }
43
+
44
+ return localTableSpec;
45
+ };
46
+
47
+ export default insertSerial;
@@ -0,0 +1,22 @@
1
+ [
2
+ {
3
+ "narration": "Prepend an empty cell into the table footer row if footer row is present.",
4
+ "destinationPath": {
5
+ "fileName": "base",
6
+ "dataRole": "table-footer-row",
7
+ "filePath": [
8
+ "children"
9
+ ],
10
+ "action": "unshift"
11
+ },
12
+ "sourcePath": {
13
+ "fileName": "data",
14
+ "filePath": [
15
+ "serial",
16
+ "footer"
17
+ ]
18
+ },
19
+ "templateKey": "emptyCell",
20
+ "func": "applyTemplate"
21
+ }
22
+ ]
@@ -0,0 +1,62 @@
1
+ [
2
+ {
3
+ "narration": "Prepend the serial column width to the table colgroup.",
4
+ "destinationPath": {
5
+ "fileName": "base",
6
+ "dataRole": "table-colgroup",
7
+ "filePath": [
8
+ "children"
9
+ ],
10
+ "action": "unshift"
11
+ },
12
+ "sourcePath": {
13
+ "fileName": "data",
14
+ "filePath": [
15
+ "serial",
16
+ "col"
17
+ ]
18
+ },
19
+ "templateKey": "buildColGroup",
20
+ "func": "applyTemplate"
21
+ },
22
+ {
23
+ "narration": "Prepend the serial header cell to the table header row.",
24
+ "destinationPath": {
25
+ "fileName": "base",
26
+ "dataRole": "table-header-row",
27
+ "filePath": [
28
+ "children"
29
+ ],
30
+ "action": "unshift"
31
+ },
32
+ "sourcePath": {
33
+ "fileName": "data",
34
+ "filePath": [
35
+ "serial",
36
+ "header"
37
+ ]
38
+ },
39
+ "templateKey": "buildHeader",
40
+ "func": "applyTemplate"
41
+ },
42
+ {
43
+ "narration": "Prepend the serial number cell into each table body row.",
44
+ "destinationPath": {
45
+ "fileName": "base",
46
+ "dataRole": "table-body",
47
+ "filePath": [
48
+ "children"
49
+ ],
50
+ "action": "unshiftSerialToRows"
51
+ },
52
+ "sourcePath": {
53
+ "fileName": "data",
54
+ "filePath": [
55
+ "serial",
56
+ "body"
57
+ ]
58
+ },
59
+ "templateKey": "buildBodyCell",
60
+ "func": "applyTemplate"
61
+ }
62
+ ]