json-renderers-run-instructions 1.11.2 → 1.15.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.
Files changed (48) hide show
  1. package/package.json +2 -5
  2. package/src/index.js +3 -3
  3. package/src/{v11 → v12}/index.js +178 -219
  4. package/src/{v10 → v12}/registerGlobal/index.js +1 -1
  5. package/src/v12/registerGlobal/meta.js +6 -0
  6. package/src/{v10 → v12}/runOptions/index.js +66 -70
  7. package/src/v12/transformers/columnOnRow.js +33 -0
  8. package/src/v12/transformers/index.js +21 -0
  9. package/src/v13/index.js +49 -0
  10. package/src/{v11 → v13}/registerGlobal/index.js +1 -1
  11. package/src/v13/registerGlobal/meta.js +6 -0
  12. package/src/{v11 → v13}/runOptions/index.js +66 -70
  13. package/src/v13/transformers/columnOnRow.js +33 -0
  14. package/src/v13/transformers/index.js +21 -0
  15. package/src/v13/types/columnOnRow.js +34 -0
  16. package/src/v13/types/helpers/guards.js +38 -0
  17. package/src/v13/types/helpers/resolveSource.js +27 -0
  18. package/src/v13/types/helpers/writeResult.js +19 -0
  19. package/src/v13/types/index.js +33 -0
  20. package/src/v13/types/rowOnColumn.js +22 -0
  21. package/src/v13/types/single.js +28 -0
  22. package/src/v14/index.js +48 -0
  23. package/src/v14/registerGlobal/index.js +16 -0
  24. package/src/{v10 → v14}/registerGlobal/meta.js +1 -1
  25. package/src/v14/runOptions/index.js +77 -0
  26. package/src/v15/index.js +48 -0
  27. package/src/v15/registerGlobal/index.js +16 -0
  28. package/src/{v11 → v15}/registerGlobal/meta.js +1 -1
  29. package/src/v15/runOptions/index.js +77 -0
  30. package/src/v10/index.js +0 -218
  31. package/src/v10/runOptions/instructionsWithTargets/index.js +0 -31
  32. package/src/v10-2/index.js +0 -202
  33. package/src/v10-2/runOptions/index.js +0 -52
  34. package/src/v10-2/runOptions/instructionsWithTargets/index.js +0 -31
  35. package/src/v10-old/index.js +0 -195
  36. package/src/v10-old/runOptions/index.js +0 -117
  37. package/src/v10-old/runOptions/instructionsWithTargets/index.js +0 -31
  38. package/src/v11/runOptions/instructionsWithTargets/index.js +0 -31
  39. package/src/v6/index.js +0 -68
  40. package/src/v7/index.js +0 -57
  41. package/src/v8/definitions.json +0 -165
  42. package/src/v8/index.js +0 -193
  43. package/src/v8/instructions.json +0 -275
  44. package/src/v8/spec.json +0 -900
  45. package/src/v9/index.js +0 -195
  46. package/src/v9/runOptions/index.js +0 -48
  47. package/src/v9/runOptions/insertSearch/index.js +0 -28
  48. package/src/v9/runOptions/instructionsWithTargets/index.js +0 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-renderers-run-instructions",
3
- "version": "1.11.2",
3
+ "version": "1.15.1",
4
4
  "description": "Reusable instruction execution and JSON-to-DOM mounting runtime for JSON renderers",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -12,14 +12,11 @@
12
12
  "README.md"
13
13
  ],
14
14
  "scripts": {
15
- "test": "node --test",
16
15
  "build": "npx @keshavsoft/build-cli"
17
16
  },
18
17
  "dependencies": {
18
+ "json-renderers-run-instructions-steps": "^1.3.1",
19
19
  "json-renderers-run-options": "^1.2.1",
20
- "json-transformer-funcs-one-dimension": "^1.9.9",
21
- "json-transformer-funcs-primitive": "^1.9.3",
22
- "json-transformer-funcs-row-on-column": "^1.2.1",
23
20
  "json-write-path": "^1.6.1",
24
21
  "jsonpathly": "^4.0.0",
25
22
  "spec-repo": "^1.19.2"
package/src/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export * from "./v11/index.js";
2
-
3
- export { default } from "./v11/index.js";
1
+ export * from "./v14/index.js";
2
+
3
+ export { default } from "./v14/index.js";
@@ -1,219 +1,178 @@
1
- import rowOnColumnFunc from "json-transformer-funcs-row-on-column";
2
- import fromCollection from "json-transformer-funcs-one-dimension";
3
- import applyTemplate from "json-transformer-funcs-primitive";
4
- import writePath from "json-write-path";
5
- import { query } from "jsonpathly";
6
- import registerGlobal from "./registerGlobal/index.js";
7
-
8
- import { spec, instructions, definitions } from "spec-repo";
9
-
10
- import runOptions from "./runOptions/index.js";
11
-
12
- const transformerFunctions = {
13
- fromCollection,
14
- applyTemplate
15
- };
16
-
17
- const resolveSource = (sourcePath, context) => {
18
- if (!sourcePath) return null;
19
-
20
- const root = context[sourcePath.fileName];
21
- if (root === undefined) {
22
- throw new Error(`Context entry not found: ${sourcePath.fileName}`);
23
- }
24
-
25
- if (sourcePath.jsonPath) {
26
- const matches = query(root, sourcePath.jsonPath, { returnArray: true });
27
- if (matches.length === 0) {
28
- if (Array.isArray(root)) return root;
29
- return [];
30
- }
31
- return matches.length === 1 ? matches[0] : matches;
32
- }
33
-
34
- if (Array.isArray(sourcePath.filePath) && sourcePath.filePath.length > 0) {
35
- return sourcePath.filePath.reduce((curr, key) => (curr ? curr[key] : undefined), root);
36
- }
37
-
38
- return root;
39
- };
40
-
41
- const checkDestinationExists = (destinationPath, context) => {
42
- if (!destinationPath) return true;
43
- const root = context[destinationPath.fileName];
44
- if (root === undefined) return false;
45
-
46
- if (destinationPath.jsonPath) {
47
- const matches = query(root, destinationPath.jsonPath, { returnArray: true });
48
- return matches.length > 0;
49
- }
50
-
51
- return true;
52
- };
53
-
54
- const executeInstruction = ({ instruction, context, spec, showLog = false }) => {
55
- if (!instruction) return null;
56
-
57
- // Handle array of sub-instructions (e.g. serial, options, search)
58
- if (Array.isArray(instruction)) {
59
- return instruction.map(step => executeInstruction({ instruction: step, context, spec, showLog }));
60
- }
61
-
62
- // Auto-normalize legacy dataRole to jsonPath
63
- if (instruction.destinationPath?.dataRole && !instruction.destinationPath?.jsonPath) {
64
- instruction.destinationPath.jsonPath = `$..*[?@.attributes['data-role'] == '${instruction.destinationPath.dataRole}']`;
65
- }
66
-
67
- // Skip if instruction has skipIf condition and target already exists
68
- if (instruction.skipIf && query(context.base, instruction.skipIf, { returnArray: true }).length > 0) {
69
- return null;
70
- }
71
-
72
- // If destination node does not exist in current base (e.g. footer row on a table without footer), safely skip
73
- if (!checkDestinationExists(instruction.destinationPath, context)) {
74
- if (showLog) {
75
- console.warn(`Destination node not found for ${instruction.destinationPath?.jsonPath}, skipping instruction.`);
76
- }
77
- return null;
78
- }
79
-
80
- const type = instruction.type ?? (instruction.templateKey?.columnKey ? "rowOnColumn" : "single");
81
-
82
- // 1. rowOnColumn instruction (e.g. buildBody for table)
83
- if (type === "rowOnColumn") {
84
- const columnKey = instruction?.templateKey?.columnKey;
85
- const rowKey = instruction?.templateKey?.rowKey;
86
- const columnSpec = spec[columnKey];
87
- const rowSpec = spec[rowKey];
88
-
89
- const columns = context.data?.columns ?? context.columns;
90
- const rows = context.data?.data ?? (Array.isArray(context.data) ? context.data : context.rows);
91
-
92
- const result = rowOnColumnFunc({
93
- columns,
94
- data: rows,
95
- columnSpec,
96
- rowSpec
97
- });
98
-
99
- writePath(context, instruction.destinationPath, result, showLog);
100
- return result;
101
- }
102
-
103
- // 2. columnOnRow instruction (e.g. buildSelectWithOptions, buildDataListWithOptions)
104
- if (type === "columnOnRow") {
105
- const columnKey = instruction?.templateKey?.columnKey;
106
- const rowKey = instruction?.templateKey?.rowKey;
107
- const columnSpec = spec[columnKey];
108
- const rowSpec = spec[rowKey];
109
-
110
- const columns = context.data?.columns ?? context.columns ?? [];
111
- const rows = context.data?.data ?? (Array.isArray(context.data) ? context.data : context.rows ?? []);
112
-
113
- const result = columns.map(column => {
114
- const container = applyTemplate(column, columnSpec);
115
-
116
- let optionsList = [];
117
- if (Array.isArray(column.options) && column.options.length > 0) {
118
- optionsList = column.options.map(opt =>
119
- typeof opt === "object" ? opt : { rowValue: opt }
120
- );
121
- } else if (Array.isArray(rows) && rows.length > 0) {
122
- optionsList = rows.map(r => ({
123
- ...r,
124
- rowValue: r[column.columnName] ?? r.value ?? r
125
- }));
126
- }
127
-
128
- container.children = optionsList.map(item => applyTemplate(item, rowSpec));
129
- return container;
130
- });
131
-
132
- if (!instruction.destinationPath?.filePath || instruction.destinationPath.filePath.length === 0) {
133
- context[instruction.destinationPath.fileName] = result;
134
- } else {
135
- writePath(context, instruction.destinationPath, result, showLog);
136
- }
137
- return result;
138
- }
139
-
140
- // 3. single instruction (e.g. buildColgroup, buildHeader, buildFooter, buildFormField, buildOptionsArray)
141
- const template = instruction.templateKey ? spec[instruction.templateKey] : null;
142
- const source = resolveSource(instruction.sourcePath, context);
143
-
144
- let result;
145
- if (instruction.func === null || instruction.func === undefined) {
146
- result = structuredClone(template);
147
- } else if (transformerFunctions[instruction.func]) {
148
- result = transformerFunctions[instruction.func](source, template);
149
- } else {
150
- throw new Error(`Unknown function: ${instruction.func}`);
151
- }
152
-
153
- // If destination filePath is empty (e.g. writing directly into an array base like selectOptionsOnlyBase)
154
- if (!instruction.destinationPath?.filePath || instruction.destinationPath.filePath.length === 0) {
155
- if (Array.isArray(context[instruction.destinationPath.fileName])) {
156
- context[instruction.destinationPath.fileName].push(...(Array.isArray(result) ? result : [result]));
157
- } else {
158
- context[instruction.destinationPath.fileName] = result;
159
- }
160
- } else {
161
- writePath(context, instruction.destinationPath, result, showLog);
162
- }
163
-
164
- return result;
165
- };
166
-
167
- const startFunc = ({
168
- instructionMainKey,
169
- instructionSubKey,
170
- data,
171
- options,
172
- showLog = false
173
- } = {}) => {
174
- const definition = definitions[instructionMainKey]?.[instructionSubKey];
175
- if (!definition) {
176
- throw new Error(`Definition not found: ${instructionMainKey}.${instructionSubKey}`);
177
- }
178
-
179
- const baseKey = definition.baseFromSpec;
180
- const instructionsToRun = definition.instructions ?? [];
181
- const optionDefs = (definition.options && typeof definition.options === "object")
182
- ? definition.options
183
- : (definitions[instructionMainKey]?.options ?? instructions.options?.[definition.options] ?? {});
184
-
185
- const base = structuredClone(spec[baseKey]);
186
-
187
- const context = { base, data };
188
-
189
- instructionsToRun.forEach(instructionKeyOrObj => {
190
- if (showLog) console.log("instruction : ", instructionKeyOrObj);
191
-
192
- const instruction = typeof instructionKeyOrObj === "string"
193
- ? instructions[instructionKeyOrObj]
194
- : instructionKeyOrObj;
195
-
196
- if (!instruction) {
197
- if (showLog) console.warn(`Instruction not found: ${instructionKeyOrObj}`);
198
- return;
199
- }
200
-
201
- executeInstruction({ instruction, context, spec, showLog });
202
- });
203
-
204
- runOptions({
205
- base: context?.base,
206
- options,
207
- optionDefs,
208
- instructions,
209
- spec,
210
- executeInstruction: ({ instruction }) => executeInstruction({ instruction, context, spec, showLog }),
211
- showLog
212
- });
213
-
214
- return context?.base;
215
- };
216
-
217
- export default startFunc;
218
-
219
- registerGlobal(startFunc);
1
+ import writePath from "json-write-path";
2
+ import { query } from "jsonpathly";
3
+ import { spec, instructions, definitions } from "spec-repo";
4
+
5
+ import { matrixTransformers, singleTransformers } from "./transformers/index.js";
6
+ import runOptions from "./runOptions/index.js";
7
+ import registerGlobal from "./registerGlobal/index.js";
8
+
9
+ const resolveSource = (sourcePath, context) => {
10
+ if (!sourcePath) return null;
11
+
12
+ const root = context[sourcePath.fileName];
13
+ if (root === undefined) {
14
+ throw new Error(`Context entry not found: ${sourcePath.fileName}`);
15
+ }
16
+
17
+ if (sourcePath.jsonPath) {
18
+ const matches = query(root, sourcePath.jsonPath, { returnArray: true });
19
+ if (matches.length === 0) {
20
+ if (Array.isArray(root)) return root;
21
+ return [];
22
+ }
23
+ return matches.length === 1 ? matches[0] : matches;
24
+ }
25
+
26
+ if (Array.isArray(sourcePath.filePath) && sourcePath.filePath.length > 0) {
27
+ return sourcePath.filePath.reduce((curr, key) => (curr ? curr[key] : undefined), root);
28
+ }
29
+
30
+ return root;
31
+ };
32
+
33
+ const checkDestinationExists = (destinationPath, context) => {
34
+ if (!destinationPath) return true;
35
+ const root = context[destinationPath.fileName];
36
+ if (root === undefined) return false;
37
+
38
+ if (destinationPath.jsonPath) {
39
+ const matches = query(root, destinationPath.jsonPath, { returnArray: true });
40
+ return matches.length > 0;
41
+ }
42
+
43
+ return true;
44
+ };
45
+
46
+ const writeResult = (context, destinationPath, result, showLog = false) => {
47
+ if (!destinationPath) return;
48
+
49
+ if (!destinationPath.filePath || destinationPath.filePath.length === 0) {
50
+ const target = context[destinationPath.fileName];
51
+ if (Array.isArray(target)) {
52
+ target.push(...(Array.isArray(result) ? result : [result]));
53
+ } else {
54
+ context[destinationPath.fileName] = result;
55
+ }
56
+ return;
57
+ }
58
+
59
+ writePath(context, destinationPath, result, showLog);
60
+ };
61
+
62
+ const transformMatrix = ({ instruction, context, spec }) => {
63
+ const fn = matrixTransformers[instruction.type] ?? matrixTransformers.rowOnColumn;
64
+ const columnSpec = spec[instruction?.templateKey?.columnKey];
65
+ const rowSpec = spec[instruction?.templateKey?.rowKey];
66
+
67
+ const columns = context.data?.columns ?? context.columns ?? [];
68
+ const rows = context.data?.data ?? (Array.isArray(context.data) ? context.data : context.rows ?? []);
69
+
70
+ return fn({ columns, data: rows, rows, columnSpec, rowSpec });
71
+ };
72
+
73
+ const transformSingle = ({ instruction, context, spec }) => {
74
+ const template = instruction.templateKey ? spec[instruction.templateKey] : null;
75
+ const source = resolveSource(instruction.sourcePath, context);
76
+
77
+ if (instruction.func === null || instruction.func === undefined) {
78
+ return structuredClone(template);
79
+ }
80
+
81
+ const fn = singleTransformers[instruction.func];
82
+ if (!fn) {
83
+ throw new Error(`Unknown function: ${instruction.func}`);
84
+ }
85
+
86
+ return fn(source, template);
87
+ };
88
+
89
+ const executeInstruction = ({ instruction, context, spec, showLog = false }) => {
90
+ if (!instruction) return null;
91
+
92
+ if (Array.isArray(instruction)) {
93
+ return instruction.map(step => executeInstruction({ instruction: step, context, spec, showLog }));
94
+ }
95
+
96
+ // Auto-normalize legacy dataRole to jsonPath
97
+ if (instruction.destinationPath?.dataRole && !instruction.destinationPath?.jsonPath) {
98
+ instruction.destinationPath.jsonPath = `$..*[?@.attributes['data-role'] == '${instruction.destinationPath.dataRole}']`;
99
+ }
100
+
101
+ // Skip if instruction has skipIf condition and target already exists
102
+ if (instruction.skipIf && query(context.base, instruction.skipIf, { returnArray: true }).length > 0) {
103
+ return null;
104
+ }
105
+
106
+ // If destination node does not exist in current base, safely skip
107
+ if (!checkDestinationExists(instruction.destinationPath, context)) {
108
+ if (showLog) {
109
+ console.warn(`Destination node not found for ${instruction.destinationPath?.jsonPath}, skipping instruction.`);
110
+ }
111
+ return null;
112
+ }
113
+
114
+ const isMatrix = instruction.type === "rowOnColumn" ||
115
+ instruction.type === "columnOnRow" ||
116
+ Boolean(instruction.templateKey?.columnKey);
117
+
118
+ const result = isMatrix
119
+ ? transformMatrix({ instruction, context, spec })
120
+ : transformSingle({ instruction, context, spec });
121
+
122
+ writeResult(context, instruction.destinationPath, result, showLog);
123
+
124
+ return result;
125
+ };
126
+
127
+ const startFunc = ({
128
+ instructionMainKey,
129
+ instructionSubKey,
130
+ data,
131
+ options,
132
+ showLog = false
133
+ } = {}) => {
134
+ const definition = definitions[instructionMainKey]?.[instructionSubKey];
135
+ if (!definition) {
136
+ throw new Error(`Definition not found: ${instructionMainKey}.${instructionSubKey}`);
137
+ }
138
+
139
+ const baseKey = definition.baseFromSpec;
140
+ const instructionsToRun = definition.instructions ?? [];
141
+ const optionDefs = (definition.options && typeof definition.options === "object")
142
+ ? definition.options
143
+ : (definitions[instructionMainKey]?.options ?? instructions.options?.[definition.options] ?? {});
144
+
145
+ const base = structuredClone(spec[baseKey]);
146
+ const context = { base, data };
147
+
148
+ instructionsToRun.forEach(instructionKeyOrObj => {
149
+ if (showLog) console.log("instruction : ", instructionKeyOrObj);
150
+
151
+ const instruction = typeof instructionKeyOrObj === "string"
152
+ ? instructions[instructionKeyOrObj]
153
+ : instructionKeyOrObj;
154
+
155
+ if (!instruction) {
156
+ if (showLog) console.warn(`Instruction not found: ${instructionKeyOrObj}`);
157
+ return;
158
+ }
159
+
160
+ executeInstruction({ instruction, context, spec, showLog });
161
+ });
162
+
163
+ runOptions({
164
+ base: context?.base,
165
+ options,
166
+ optionDefs,
167
+ instructions,
168
+ spec,
169
+ executeInstruction: ({ instruction }) => executeInstruction({ instruction, context, spec, showLog }),
170
+ showLog
171
+ });
172
+
173
+ return context?.base;
174
+ };
175
+
176
+ export default startFunc;
177
+
178
+ registerGlobal(startFunc);
@@ -13,4 +13,4 @@ const registerGlobal = (renderFunc) => {
13
13
  };
14
14
  };
15
15
 
16
- export default registerGlobal;
16
+ export default registerGlobal;
@@ -0,0 +1,6 @@
1
+ export const meta = {
2
+ name: "json-renderers-run-instructions",
3
+ version: "1.12.0"
4
+ };
5
+
6
+ export default meta;
@@ -1,70 +1,66 @@
1
- const isObject = value => value !== null && typeof value === "object" && !Array.isArray(value);
2
-
3
- const getFeatureOptions = (options, featureKey) => {
4
- if (!isObject(options)) return null;
5
- if (options[featureKey] !== undefined) return options[featureKey];
6
- const prefixed = `show${featureKey.charAt(0).toUpperCase()}${featureKey.slice(1)}`;
7
- if (options[prefixed] !== undefined) return options[prefixed];
8
- return null;
9
- };
10
-
11
- /**
12
- * 2-level loop for applying option switches from definitions.json:
13
- * Level 1: Loop over feature groups (search, serial, options)
14
- * Level 2: Loop over switches inside the feature (showLabel, showHelper, showInput...)
15
- */
16
- const runOptions = ({
17
- base,
18
- options = {},
19
- optionDefs = {},
20
- instructions = {},
21
- spec = {},
22
- executeInstruction,
23
- showLog = false
24
- } = {}) => {
25
- if (!base || !isObject(options) || !isObject(optionDefs) || typeof executeInstruction !== "function") {
26
- return base;
27
- }
28
-
29
- // Level 1: Loop over feature groups (e.g. search, serial, options)
30
- for (const [featureKey, featureSwitches] of Object.entries(optionDefs)) {
31
- if (!isObject(featureSwitches)) continue;
32
-
33
- const userFeature = getFeatureOptions(options, featureKey);
34
- if (!userFeature) continue;
35
-
36
- const isBool = typeof userFeature === "boolean" && userFeature === true;
37
- const isObj = isObject(userFeature);
38
- if (!isBool && !isObj) continue;
39
-
40
- // Check if any switch in this feature group is active
41
- const hasActiveSwitch = Object.entries(featureSwitches).some(
42
- ([switchKey]) => switchKey !== "initialize" && (isBool || userFeature[switchKey] === true)
43
- );
44
- if (!hasActiveSwitch) continue;
45
-
46
- // Step 1: Run initialize instruction first if present (e.g. "searchFrame")
47
- if (featureSwitches.initialize && instructions[featureSwitches.initialize]) {
48
- executeInstruction({
49
- instruction: instructions[featureSwitches.initialize]
50
- });
51
- }
52
-
53
- // Level 2: Loop over switches and execute each enabled instruction (e.g. "searchLabel")
54
- for (const [switchKey, instructionKey] of Object.entries(featureSwitches)) {
55
- if (switchKey === "initialize") continue;
56
-
57
- const isEnabled = isBool || userFeature[switchKey] === true;
58
- if (isEnabled && instructions[instructionKey]) {
59
- executeInstruction({
60
- instruction: instructions[instructionKey]
61
- });
62
- }
63
- }
64
- }
65
-
66
- return base;
67
- };
68
-
69
- export { runOptions };
70
- export default runOptions;
1
+ const isObject = value => value !== null && typeof value === "object" && !Array.isArray(value);
2
+
3
+ const getFeatureOptions = (options, featureKey) => {
4
+ if (!isObject(options)) return null;
5
+ if (options[featureKey] !== undefined) return options[featureKey];
6
+ const prefixed = `show${featureKey.charAt(0).toUpperCase()}${featureKey.slice(1)}`;
7
+ if (options[prefixed] !== undefined) return options[prefixed];
8
+ return null;
9
+ };
10
+
11
+ /**
12
+ * 2-level loop for applying option switches from definitions.json:
13
+ * Level 1: Loop over feature groups (search, serial, options)
14
+ * Level 2: Loop over switches inside the feature (showLabel, showHelper, showInput...)
15
+ */
16
+ const runOptions = ({
17
+ base,
18
+ options = {},
19
+ optionDefs = {},
20
+ instructions = {},
21
+ spec = {},
22
+ executeInstruction,
23
+ showLog = false
24
+ } = {}) => {
25
+ if (!base || !isObject(options) || !isObject(optionDefs) || typeof executeInstruction !== "function") {
26
+ return base;
27
+ }
28
+
29
+ for (const [featureKey, featureSwitches] of Object.entries(optionDefs)) {
30
+ if (!isObject(featureSwitches)) continue;
31
+
32
+ const userFeature = getFeatureOptions(options, featureKey);
33
+ if (!userFeature) continue;
34
+
35
+ const isBool = typeof userFeature === "boolean" && userFeature === true;
36
+ const isObj = isObject(userFeature);
37
+ if (!isBool && !isObj) continue;
38
+
39
+ const hasActiveSwitch = Object.entries(featureSwitches).some(
40
+ ([switchKey]) => switchKey !== "initialize" && (isBool || userFeature[switchKey] === true)
41
+ );
42
+ if (!hasActiveSwitch) continue;
43
+
44
+ if (featureSwitches.initialize && instructions[featureSwitches.initialize]) {
45
+ executeInstruction({
46
+ instruction: instructions[featureSwitches.initialize]
47
+ });
48
+ }
49
+
50
+ for (const [switchKey, instructionKey] of Object.entries(featureSwitches)) {
51
+ if (switchKey === "initialize") continue;
52
+
53
+ const isEnabled = isBool || userFeature[switchKey] === true;
54
+ if (isEnabled && instructions[instructionKey]) {
55
+ executeInstruction({
56
+ instruction: instructions[instructionKey]
57
+ });
58
+ }
59
+ }
60
+ }
61
+
62
+ return base;
63
+ };
64
+
65
+ export { runOptions };
66
+ export default runOptions;
@@ -0,0 +1,33 @@
1
+ import applyTemplate from "json-transformer-funcs-primitive";
2
+
3
+ /**
4
+ * Pure transformer: maps columns onto rows (e.g. for selects with options or datalists).
5
+ * Symmetrical counterpart to rowOnColumn.
6
+ */
7
+ const columnOnRow = ({
8
+ columns = [],
9
+ rows = [],
10
+ columnSpec,
11
+ rowSpec
12
+ } = {}) => {
13
+ return columns.map(column => {
14
+ const container = applyTemplate(column, columnSpec);
15
+
16
+ let optionsList = [];
17
+ if (Array.isArray(column.options) && column.options.length > 0) {
18
+ optionsList = column.options.map(opt =>
19
+ typeof opt === "object" ? opt : { rowValue: opt }
20
+ );
21
+ } else if (Array.isArray(rows) && rows.length > 0) {
22
+ optionsList = rows.map(r => ({
23
+ ...r,
24
+ rowValue: r[column.columnName] ?? r.value ?? r
25
+ }));
26
+ }
27
+
28
+ container.children = optionsList.map(item => applyTemplate(item, rowSpec));
29
+ return container;
30
+ });
31
+ };
32
+
33
+ export default columnOnRow;
@@ -0,0 +1,21 @@
1
+ import fromCollection from "json-transformer-funcs-one-dimension";
2
+ import applyTemplate from "json-transformer-funcs-primitive";
3
+ import rowOnColumn from "json-transformer-funcs-row-on-column";
4
+ import columnOnRow from "./columnOnRow.js";
5
+
6
+ export const matrixTransformers = {
7
+ rowOnColumn,
8
+ columnOnRow
9
+ };
10
+
11
+ export const singleTransformers = {
12
+ fromCollection,
13
+ applyTemplate
14
+ };
15
+
16
+ export {
17
+ fromCollection,
18
+ applyTemplate,
19
+ rowOnColumn,
20
+ columnOnRow
21
+ };