@okf/ootils 1.3.4 → 1.3.6
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/dist/browser.d.mts +121 -1
- package/dist/browser.d.ts +121 -1
- package/dist/browser.js +127 -2
- package/dist/browser.mjs +123 -1
- package/dist/node.d.mts +121 -1
- package/dist/node.d.ts +121 -1
- package/dist/node.js +125 -0
- package/dist/node.mjs +122 -0
- package/dist/universal.d.mts +121 -1
- package/dist/universal.d.ts +121 -1
- package/dist/universal.js +127 -2
- package/dist/universal.mjs +123 -1
- package/package.json +1 -1
package/dist/browser.d.mts
CHANGED
|
@@ -31,4 +31,124 @@ interface RichTextValue {
|
|
|
31
31
|
type TagNameInput = string | number | RichTextValue | null | undefined;
|
|
32
32
|
declare const genTagId: (tagName: TagNameInput) => string;
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Converts a value to an array, ensuring the result is always an array type.
|
|
36
|
+
*
|
|
37
|
+
* This utility function normalizes input values by:
|
|
38
|
+
* - Returning the input unchanged if it's already an array
|
|
39
|
+
* - Wrapping single values in an array
|
|
40
|
+
* - Preserving meaningful falsy values (false, 0) by wrapping them in arrays
|
|
41
|
+
* - Converting other falsy values (null, undefined, empty string) to empty arrays
|
|
42
|
+
*
|
|
43
|
+
* @template T - The type of the input value(s)
|
|
44
|
+
* @param {T | T[] | null | undefined | false | 0} property - The value to convert to an array
|
|
45
|
+
* @returns {T[]} An array containing the input value(s)
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* toArray("hello") // ["hello"]
|
|
50
|
+
* toArray(["a", "b"]) // ["a", "b"] (unchanged)
|
|
51
|
+
* toArray(42) // [42]
|
|
52
|
+
* toArray(false) // [false] (preserved)
|
|
53
|
+
* toArray(0) // [0] (preserved)
|
|
54
|
+
* toArray(null) // []
|
|
55
|
+
* toArray(undefined) // []
|
|
56
|
+
* toArray("") // []
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
declare const toArray: <T>(property: T | T[] | null | undefined | false | 0) => T[];
|
|
60
|
+
|
|
61
|
+
interface Block {
|
|
62
|
+
[key: string]: any;
|
|
63
|
+
comp?: string;
|
|
64
|
+
valuePath?: string;
|
|
65
|
+
blocks?: Block[];
|
|
66
|
+
}
|
|
67
|
+
interface ExtractedBlock extends Block {
|
|
68
|
+
sectionStack: Section[];
|
|
69
|
+
blockPath: string;
|
|
70
|
+
}
|
|
71
|
+
interface Section {
|
|
72
|
+
[key: string]: any;
|
|
73
|
+
blocks?: Block[];
|
|
74
|
+
}
|
|
75
|
+
interface Template {
|
|
76
|
+
category: string;
|
|
77
|
+
kp_templates?: {
|
|
78
|
+
[spaceId: string]: SpaceConfig;
|
|
79
|
+
} & {
|
|
80
|
+
myProfileConfig?: Block[];
|
|
81
|
+
};
|
|
82
|
+
kp_settings?: Block[];
|
|
83
|
+
}
|
|
84
|
+
interface SpaceConfig {
|
|
85
|
+
builder?: 'FormBuilder' | 'MetaBuilder' | 'kp_settings' | string;
|
|
86
|
+
configs?: Block[] | {
|
|
87
|
+
inputs: {
|
|
88
|
+
[key: string]: Block;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
subSpaces?: SpaceConfig[];
|
|
92
|
+
}
|
|
93
|
+
type BuilderType = 'FormBuilder' | 'MetaBuilder' | 'kp_settings' | string;
|
|
94
|
+
/**
|
|
95
|
+
* Extracts all blocks from a template configuration, preserving their hierarchical context.
|
|
96
|
+
*
|
|
97
|
+
* This function traverses template structures and extracts individual block configurations
|
|
98
|
+
* while maintaining information about their location (blockPath) and parent sections
|
|
99
|
+
* (sectionStack). This metadata is crucial for:
|
|
100
|
+
* - Updating block properties at their exact location
|
|
101
|
+
* - Handling display conditions that affect entire sections
|
|
102
|
+
* - Managing nested block hierarchies in form builders
|
|
103
|
+
*
|
|
104
|
+
* @param {Object} params - Extraction parameters
|
|
105
|
+
* @param {Template} params.tpl - The template configuration to extract blocks from
|
|
106
|
+
* @param {BuilderType[]} [params.buildersWhitelist] - Optional list of builders to extract from.
|
|
107
|
+
* If provided, only blocks from these builders will be included
|
|
108
|
+
* @returns {ExtractedBlock[]} Array of blocks with added sectionStack and blockPath metadata
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const blocks = extractAllBlocksFromTpl({
|
|
113
|
+
* tpl: templateConfig,
|
|
114
|
+
* buildersWhitelist: ['FormBuilder', 'kp_settings']
|
|
115
|
+
* });
|
|
116
|
+
*
|
|
117
|
+
* // Each block will have:
|
|
118
|
+
* // - Original block properties (type, label, valuePath, etc.)
|
|
119
|
+
* // - sectionStack: Array of parent sections for display condition handling
|
|
120
|
+
* // - blockPath: Dot-notation path for precise updates (e.g., "kp_templates.header.configs.0")
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
declare const extractAllBlocksFromTpl: ({ tpl, buildersWhitelist }: {
|
|
124
|
+
tpl: Template;
|
|
125
|
+
buildersWhitelist?: BuilderType[];
|
|
126
|
+
}) => ExtractedBlock[];
|
|
127
|
+
/**
|
|
128
|
+
* Recursively extracts blocks from a hierarchical data structure.
|
|
129
|
+
*
|
|
130
|
+
* This is the core traversal function that handles nested sections and blocks.
|
|
131
|
+
* It preserves two critical pieces of metadata:
|
|
132
|
+
*
|
|
133
|
+
* 1. **sectionStack**: Array of parent sections - Essential for display condition handling.
|
|
134
|
+
* When sections have display conditions, we need to know which blocks belong to
|
|
135
|
+
* hidden sections to exclude them from indexes and processing.
|
|
136
|
+
*
|
|
137
|
+
* 2. **blockPath**: Dot-notation path to the block's location - Required for precise updates.
|
|
138
|
+
* Used when modifying block properties or updating valuePaths in display conditions.
|
|
139
|
+
* See 'modifyValuesAndValuePaths' for detailed usage.
|
|
140
|
+
*
|
|
141
|
+
* @param {Object} params - Extraction parameters
|
|
142
|
+
* @param {Block[]} params.data - Array of blocks/sections to process
|
|
143
|
+
* @param {Function} params.cb - Callback function to handle each extracted block
|
|
144
|
+
* @param {Section[]} params.sectionStack - Current stack of parent sections
|
|
145
|
+
* @param {string} params.blockPathPrefix - Current path prefix for building blockPath
|
|
146
|
+
*/
|
|
147
|
+
declare const _recursExtractBlocks: ({ data, cb, sectionStack, blockPathPrefix }: {
|
|
148
|
+
data: Block[];
|
|
149
|
+
cb: (block: ExtractedBlock) => void;
|
|
150
|
+
sectionStack?: Section[];
|
|
151
|
+
blockPathPrefix?: string;
|
|
152
|
+
}) => void;
|
|
153
|
+
|
|
154
|
+
export { deleteVal, extractAllBlocksFromTpl, genTagId, getVal, _recursExtractBlocks as recursivelyExtractBlocks, setVal, toArray };
|
package/dist/browser.d.ts
CHANGED
|
@@ -31,4 +31,124 @@ interface RichTextValue {
|
|
|
31
31
|
type TagNameInput = string | number | RichTextValue | null | undefined;
|
|
32
32
|
declare const genTagId: (tagName: TagNameInput) => string;
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Converts a value to an array, ensuring the result is always an array type.
|
|
36
|
+
*
|
|
37
|
+
* This utility function normalizes input values by:
|
|
38
|
+
* - Returning the input unchanged if it's already an array
|
|
39
|
+
* - Wrapping single values in an array
|
|
40
|
+
* - Preserving meaningful falsy values (false, 0) by wrapping them in arrays
|
|
41
|
+
* - Converting other falsy values (null, undefined, empty string) to empty arrays
|
|
42
|
+
*
|
|
43
|
+
* @template T - The type of the input value(s)
|
|
44
|
+
* @param {T | T[] | null | undefined | false | 0} property - The value to convert to an array
|
|
45
|
+
* @returns {T[]} An array containing the input value(s)
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* toArray("hello") // ["hello"]
|
|
50
|
+
* toArray(["a", "b"]) // ["a", "b"] (unchanged)
|
|
51
|
+
* toArray(42) // [42]
|
|
52
|
+
* toArray(false) // [false] (preserved)
|
|
53
|
+
* toArray(0) // [0] (preserved)
|
|
54
|
+
* toArray(null) // []
|
|
55
|
+
* toArray(undefined) // []
|
|
56
|
+
* toArray("") // []
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
declare const toArray: <T>(property: T | T[] | null | undefined | false | 0) => T[];
|
|
60
|
+
|
|
61
|
+
interface Block {
|
|
62
|
+
[key: string]: any;
|
|
63
|
+
comp?: string;
|
|
64
|
+
valuePath?: string;
|
|
65
|
+
blocks?: Block[];
|
|
66
|
+
}
|
|
67
|
+
interface ExtractedBlock extends Block {
|
|
68
|
+
sectionStack: Section[];
|
|
69
|
+
blockPath: string;
|
|
70
|
+
}
|
|
71
|
+
interface Section {
|
|
72
|
+
[key: string]: any;
|
|
73
|
+
blocks?: Block[];
|
|
74
|
+
}
|
|
75
|
+
interface Template {
|
|
76
|
+
category: string;
|
|
77
|
+
kp_templates?: {
|
|
78
|
+
[spaceId: string]: SpaceConfig;
|
|
79
|
+
} & {
|
|
80
|
+
myProfileConfig?: Block[];
|
|
81
|
+
};
|
|
82
|
+
kp_settings?: Block[];
|
|
83
|
+
}
|
|
84
|
+
interface SpaceConfig {
|
|
85
|
+
builder?: 'FormBuilder' | 'MetaBuilder' | 'kp_settings' | string;
|
|
86
|
+
configs?: Block[] | {
|
|
87
|
+
inputs: {
|
|
88
|
+
[key: string]: Block;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
subSpaces?: SpaceConfig[];
|
|
92
|
+
}
|
|
93
|
+
type BuilderType = 'FormBuilder' | 'MetaBuilder' | 'kp_settings' | string;
|
|
94
|
+
/**
|
|
95
|
+
* Extracts all blocks from a template configuration, preserving their hierarchical context.
|
|
96
|
+
*
|
|
97
|
+
* This function traverses template structures and extracts individual block configurations
|
|
98
|
+
* while maintaining information about their location (blockPath) and parent sections
|
|
99
|
+
* (sectionStack). This metadata is crucial for:
|
|
100
|
+
* - Updating block properties at their exact location
|
|
101
|
+
* - Handling display conditions that affect entire sections
|
|
102
|
+
* - Managing nested block hierarchies in form builders
|
|
103
|
+
*
|
|
104
|
+
* @param {Object} params - Extraction parameters
|
|
105
|
+
* @param {Template} params.tpl - The template configuration to extract blocks from
|
|
106
|
+
* @param {BuilderType[]} [params.buildersWhitelist] - Optional list of builders to extract from.
|
|
107
|
+
* If provided, only blocks from these builders will be included
|
|
108
|
+
* @returns {ExtractedBlock[]} Array of blocks with added sectionStack and blockPath metadata
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const blocks = extractAllBlocksFromTpl({
|
|
113
|
+
* tpl: templateConfig,
|
|
114
|
+
* buildersWhitelist: ['FormBuilder', 'kp_settings']
|
|
115
|
+
* });
|
|
116
|
+
*
|
|
117
|
+
* // Each block will have:
|
|
118
|
+
* // - Original block properties (type, label, valuePath, etc.)
|
|
119
|
+
* // - sectionStack: Array of parent sections for display condition handling
|
|
120
|
+
* // - blockPath: Dot-notation path for precise updates (e.g., "kp_templates.header.configs.0")
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
declare const extractAllBlocksFromTpl: ({ tpl, buildersWhitelist }: {
|
|
124
|
+
tpl: Template;
|
|
125
|
+
buildersWhitelist?: BuilderType[];
|
|
126
|
+
}) => ExtractedBlock[];
|
|
127
|
+
/**
|
|
128
|
+
* Recursively extracts blocks from a hierarchical data structure.
|
|
129
|
+
*
|
|
130
|
+
* This is the core traversal function that handles nested sections and blocks.
|
|
131
|
+
* It preserves two critical pieces of metadata:
|
|
132
|
+
*
|
|
133
|
+
* 1. **sectionStack**: Array of parent sections - Essential for display condition handling.
|
|
134
|
+
* When sections have display conditions, we need to know which blocks belong to
|
|
135
|
+
* hidden sections to exclude them from indexes and processing.
|
|
136
|
+
*
|
|
137
|
+
* 2. **blockPath**: Dot-notation path to the block's location - Required for precise updates.
|
|
138
|
+
* Used when modifying block properties or updating valuePaths in display conditions.
|
|
139
|
+
* See 'modifyValuesAndValuePaths' for detailed usage.
|
|
140
|
+
*
|
|
141
|
+
* @param {Object} params - Extraction parameters
|
|
142
|
+
* @param {Block[]} params.data - Array of blocks/sections to process
|
|
143
|
+
* @param {Function} params.cb - Callback function to handle each extracted block
|
|
144
|
+
* @param {Section[]} params.sectionStack - Current stack of parent sections
|
|
145
|
+
* @param {string} params.blockPathPrefix - Current path prefix for building blockPath
|
|
146
|
+
*/
|
|
147
|
+
declare const _recursExtractBlocks: ({ data, cb, sectionStack, blockPathPrefix }: {
|
|
148
|
+
data: Block[];
|
|
149
|
+
cb: (block: ExtractedBlock) => void;
|
|
150
|
+
sectionStack?: Section[];
|
|
151
|
+
blockPathPrefix?: string;
|
|
152
|
+
}) => void;
|
|
153
|
+
|
|
154
|
+
export { deleteVal, extractAllBlocksFromTpl, genTagId, getVal, _recursExtractBlocks as recursivelyExtractBlocks, setVal, toArray };
|
package/dist/browser.js
CHANGED
|
@@ -21,9 +21,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var browser_exports = {};
|
|
22
22
|
__export(browser_exports, {
|
|
23
23
|
deleteVal: () => deleteVal,
|
|
24
|
+
extractAllBlocksFromTpl: () => extractAllBlocksFromTpl,
|
|
24
25
|
genTagId: () => genTagId,
|
|
25
26
|
getVal: () => getVal,
|
|
26
|
-
|
|
27
|
+
recursivelyExtractBlocks: () => _recursExtractBlocks,
|
|
28
|
+
setVal: () => setVal,
|
|
29
|
+
toArray: () => toArray
|
|
27
30
|
});
|
|
28
31
|
module.exports = __toCommonJS(browser_exports);
|
|
29
32
|
|
|
@@ -182,10 +185,132 @@ var genTagId = (tagName) => {
|
|
|
182
185
|
toReturn = toReturn.replace(/\+/g, "plus");
|
|
183
186
|
return toReturn.replace(/^_+|_+$/, "");
|
|
184
187
|
};
|
|
188
|
+
|
|
189
|
+
// src/utils/toArray.ts
|
|
190
|
+
var toArray = (property) => {
|
|
191
|
+
if (!property && (property !== false && property !== 0)) return [];
|
|
192
|
+
if (Array.isArray(property)) return property;
|
|
193
|
+
return [property];
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
// src/utils/extractAllBlocksFromTpl.ts
|
|
197
|
+
var extractAllBlocksFromTpl = ({
|
|
198
|
+
tpl,
|
|
199
|
+
buildersWhitelist
|
|
200
|
+
}) => {
|
|
201
|
+
if (tpl.category === "userProfiles") {
|
|
202
|
+
const allBlocksAry = [];
|
|
203
|
+
if (tpl.kp_templates?.myProfileConfig) {
|
|
204
|
+
_recursExtractBlocks({
|
|
205
|
+
data: tpl.kp_templates.myProfileConfig,
|
|
206
|
+
cb: (block) => allBlocksAry.push(block),
|
|
207
|
+
sectionStack: [],
|
|
208
|
+
blockPathPrefix: "kp_templates.myProfileConfig"
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
return allBlocksAry;
|
|
212
|
+
} else {
|
|
213
|
+
return extractAllBlocksFromStructuredTpls({ tpl, buildersWhitelist });
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
var _recursExtractBlocks = ({
|
|
217
|
+
data,
|
|
218
|
+
cb,
|
|
219
|
+
sectionStack = [],
|
|
220
|
+
blockPathPrefix = ""
|
|
221
|
+
}) => {
|
|
222
|
+
data.forEach((d, idx) => {
|
|
223
|
+
if (!d.blocks) {
|
|
224
|
+
cb({
|
|
225
|
+
...d,
|
|
226
|
+
sectionStack,
|
|
227
|
+
blockPath: `${blockPathPrefix}.${idx}`
|
|
228
|
+
});
|
|
229
|
+
} else {
|
|
230
|
+
_recursExtractBlocks({
|
|
231
|
+
data: d.blocks,
|
|
232
|
+
cb,
|
|
233
|
+
sectionStack: [...sectionStack, d],
|
|
234
|
+
blockPathPrefix: `${blockPathPrefix}.${idx}.blocks`
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
};
|
|
239
|
+
var extractAllBlocksFromStructuredTpls = ({
|
|
240
|
+
tpl,
|
|
241
|
+
buildersWhitelist
|
|
242
|
+
}) => {
|
|
243
|
+
const allBlocksAry = [];
|
|
244
|
+
if (tpl.kp_templates) {
|
|
245
|
+
for (let spaceId in tpl.kp_templates) {
|
|
246
|
+
let conf = tpl.kp_templates[spaceId];
|
|
247
|
+
if (conf.builder && buildersWhitelist && !buildersWhitelist.includes(conf.builder)) {
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
if (!conf.subSpaces) {
|
|
251
|
+
_extractBlocksFromSomeBuilders({
|
|
252
|
+
conf,
|
|
253
|
+
confPath: `kp_templates.${spaceId}`,
|
|
254
|
+
allBlocksAry
|
|
255
|
+
});
|
|
256
|
+
} else {
|
|
257
|
+
conf.subSpaces.forEach((sub, subIdx) => {
|
|
258
|
+
if (sub.builder && buildersWhitelist && !buildersWhitelist.includes(sub.builder)) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
_extractBlocksFromSomeBuilders({
|
|
262
|
+
conf: sub,
|
|
263
|
+
confPath: `kp_templates.${spaceId}.subSpaces.${subIdx}`,
|
|
264
|
+
allBlocksAry
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (buildersWhitelist && !buildersWhitelist.includes("kp_settings")) {
|
|
271
|
+
return allBlocksAry;
|
|
272
|
+
}
|
|
273
|
+
if (tpl.kp_settings && tpl.kp_settings.length > 0) {
|
|
274
|
+
_recursExtractBlocks({
|
|
275
|
+
data: tpl.kp_settings,
|
|
276
|
+
cb: (block) => allBlocksAry.push(block),
|
|
277
|
+
blockPathPrefix: "kp_settings"
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
return allBlocksAry;
|
|
281
|
+
};
|
|
282
|
+
var _extractBlocksFromSomeBuilders = ({
|
|
283
|
+
conf,
|
|
284
|
+
confPath,
|
|
285
|
+
allBlocksAry
|
|
286
|
+
}) => {
|
|
287
|
+
if (conf.builder === "FormBuilder") {
|
|
288
|
+
const configs = conf.configs || [];
|
|
289
|
+
_recursExtractBlocks({
|
|
290
|
+
data: configs,
|
|
291
|
+
cb: (block) => allBlocksAry.push(block),
|
|
292
|
+
blockPathPrefix: `${confPath}.configs`
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
if (conf.builder === "MetaBuilder") {
|
|
296
|
+
const inputs = conf.configs?.inputs || {};
|
|
297
|
+
const inputBlockConfigsToPush = Object.keys(inputs).map((inputBlockKey) => {
|
|
298
|
+
const value = inputs[inputBlockKey];
|
|
299
|
+
return {
|
|
300
|
+
...value,
|
|
301
|
+
blockPath: `${confPath}.configs.inputs.${inputBlockKey}`
|
|
302
|
+
};
|
|
303
|
+
});
|
|
304
|
+
allBlocksAry.push(...inputBlockConfigsToPush);
|
|
305
|
+
}
|
|
306
|
+
};
|
|
185
307
|
// Annotate the CommonJS export names for ESM import in node:
|
|
186
308
|
0 && (module.exports = {
|
|
187
309
|
deleteVal,
|
|
310
|
+
extractAllBlocksFromTpl,
|
|
188
311
|
genTagId,
|
|
189
312
|
getVal,
|
|
190
|
-
|
|
313
|
+
recursivelyExtractBlocks,
|
|
314
|
+
setVal,
|
|
315
|
+
toArray
|
|
191
316
|
});
|
package/dist/browser.mjs
CHANGED
|
@@ -153,9 +153,131 @@ var genTagId = (tagName) => {
|
|
|
153
153
|
toReturn = toReturn.replace(/\+/g, "plus");
|
|
154
154
|
return toReturn.replace(/^_+|_+$/, "");
|
|
155
155
|
};
|
|
156
|
+
|
|
157
|
+
// src/utils/toArray.ts
|
|
158
|
+
var toArray = (property) => {
|
|
159
|
+
if (!property && (property !== false && property !== 0)) return [];
|
|
160
|
+
if (Array.isArray(property)) return property;
|
|
161
|
+
return [property];
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// src/utils/extractAllBlocksFromTpl.ts
|
|
165
|
+
var extractAllBlocksFromTpl = ({
|
|
166
|
+
tpl,
|
|
167
|
+
buildersWhitelist
|
|
168
|
+
}) => {
|
|
169
|
+
if (tpl.category === "userProfiles") {
|
|
170
|
+
const allBlocksAry = [];
|
|
171
|
+
if (tpl.kp_templates?.myProfileConfig) {
|
|
172
|
+
_recursExtractBlocks({
|
|
173
|
+
data: tpl.kp_templates.myProfileConfig,
|
|
174
|
+
cb: (block) => allBlocksAry.push(block),
|
|
175
|
+
sectionStack: [],
|
|
176
|
+
blockPathPrefix: "kp_templates.myProfileConfig"
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
return allBlocksAry;
|
|
180
|
+
} else {
|
|
181
|
+
return extractAllBlocksFromStructuredTpls({ tpl, buildersWhitelist });
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
var _recursExtractBlocks = ({
|
|
185
|
+
data,
|
|
186
|
+
cb,
|
|
187
|
+
sectionStack = [],
|
|
188
|
+
blockPathPrefix = ""
|
|
189
|
+
}) => {
|
|
190
|
+
data.forEach((d, idx) => {
|
|
191
|
+
if (!d.blocks) {
|
|
192
|
+
cb({
|
|
193
|
+
...d,
|
|
194
|
+
sectionStack,
|
|
195
|
+
blockPath: `${blockPathPrefix}.${idx}`
|
|
196
|
+
});
|
|
197
|
+
} else {
|
|
198
|
+
_recursExtractBlocks({
|
|
199
|
+
data: d.blocks,
|
|
200
|
+
cb,
|
|
201
|
+
sectionStack: [...sectionStack, d],
|
|
202
|
+
blockPathPrefix: `${blockPathPrefix}.${idx}.blocks`
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
var extractAllBlocksFromStructuredTpls = ({
|
|
208
|
+
tpl,
|
|
209
|
+
buildersWhitelist
|
|
210
|
+
}) => {
|
|
211
|
+
const allBlocksAry = [];
|
|
212
|
+
if (tpl.kp_templates) {
|
|
213
|
+
for (let spaceId in tpl.kp_templates) {
|
|
214
|
+
let conf = tpl.kp_templates[spaceId];
|
|
215
|
+
if (conf.builder && buildersWhitelist && !buildersWhitelist.includes(conf.builder)) {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (!conf.subSpaces) {
|
|
219
|
+
_extractBlocksFromSomeBuilders({
|
|
220
|
+
conf,
|
|
221
|
+
confPath: `kp_templates.${spaceId}`,
|
|
222
|
+
allBlocksAry
|
|
223
|
+
});
|
|
224
|
+
} else {
|
|
225
|
+
conf.subSpaces.forEach((sub, subIdx) => {
|
|
226
|
+
if (sub.builder && buildersWhitelist && !buildersWhitelist.includes(sub.builder)) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
_extractBlocksFromSomeBuilders({
|
|
230
|
+
conf: sub,
|
|
231
|
+
confPath: `kp_templates.${spaceId}.subSpaces.${subIdx}`,
|
|
232
|
+
allBlocksAry
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (buildersWhitelist && !buildersWhitelist.includes("kp_settings")) {
|
|
239
|
+
return allBlocksAry;
|
|
240
|
+
}
|
|
241
|
+
if (tpl.kp_settings && tpl.kp_settings.length > 0) {
|
|
242
|
+
_recursExtractBlocks({
|
|
243
|
+
data: tpl.kp_settings,
|
|
244
|
+
cb: (block) => allBlocksAry.push(block),
|
|
245
|
+
blockPathPrefix: "kp_settings"
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
return allBlocksAry;
|
|
249
|
+
};
|
|
250
|
+
var _extractBlocksFromSomeBuilders = ({
|
|
251
|
+
conf,
|
|
252
|
+
confPath,
|
|
253
|
+
allBlocksAry
|
|
254
|
+
}) => {
|
|
255
|
+
if (conf.builder === "FormBuilder") {
|
|
256
|
+
const configs = conf.configs || [];
|
|
257
|
+
_recursExtractBlocks({
|
|
258
|
+
data: configs,
|
|
259
|
+
cb: (block) => allBlocksAry.push(block),
|
|
260
|
+
blockPathPrefix: `${confPath}.configs`
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
if (conf.builder === "MetaBuilder") {
|
|
264
|
+
const inputs = conf.configs?.inputs || {};
|
|
265
|
+
const inputBlockConfigsToPush = Object.keys(inputs).map((inputBlockKey) => {
|
|
266
|
+
const value = inputs[inputBlockKey];
|
|
267
|
+
return {
|
|
268
|
+
...value,
|
|
269
|
+
blockPath: `${confPath}.configs.inputs.${inputBlockKey}`
|
|
270
|
+
};
|
|
271
|
+
});
|
|
272
|
+
allBlocksAry.push(...inputBlockConfigsToPush);
|
|
273
|
+
}
|
|
274
|
+
};
|
|
156
275
|
export {
|
|
157
276
|
deleteVal,
|
|
277
|
+
extractAllBlocksFromTpl,
|
|
158
278
|
genTagId,
|
|
159
279
|
getVal,
|
|
160
|
-
|
|
280
|
+
_recursExtractBlocks as recursivelyExtractBlocks,
|
|
281
|
+
setVal,
|
|
282
|
+
toArray
|
|
161
283
|
};
|
package/dist/node.d.mts
CHANGED
|
@@ -34,6 +34,126 @@ interface RichTextValue {
|
|
|
34
34
|
type TagNameInput = string | number | RichTextValue | null | undefined;
|
|
35
35
|
declare const genTagId: (tagName: TagNameInput) => string;
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Converts a value to an array, ensuring the result is always an array type.
|
|
39
|
+
*
|
|
40
|
+
* This utility function normalizes input values by:
|
|
41
|
+
* - Returning the input unchanged if it's already an array
|
|
42
|
+
* - Wrapping single values in an array
|
|
43
|
+
* - Preserving meaningful falsy values (false, 0) by wrapping them in arrays
|
|
44
|
+
* - Converting other falsy values (null, undefined, empty string) to empty arrays
|
|
45
|
+
*
|
|
46
|
+
* @template T - The type of the input value(s)
|
|
47
|
+
* @param {T | T[] | null | undefined | false | 0} property - The value to convert to an array
|
|
48
|
+
* @returns {T[]} An array containing the input value(s)
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* toArray("hello") // ["hello"]
|
|
53
|
+
* toArray(["a", "b"]) // ["a", "b"] (unchanged)
|
|
54
|
+
* toArray(42) // [42]
|
|
55
|
+
* toArray(false) // [false] (preserved)
|
|
56
|
+
* toArray(0) // [0] (preserved)
|
|
57
|
+
* toArray(null) // []
|
|
58
|
+
* toArray(undefined) // []
|
|
59
|
+
* toArray("") // []
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
declare const toArray: <T>(property: T | T[] | null | undefined | false | 0) => T[];
|
|
63
|
+
|
|
64
|
+
interface Block {
|
|
65
|
+
[key: string]: any;
|
|
66
|
+
comp?: string;
|
|
67
|
+
valuePath?: string;
|
|
68
|
+
blocks?: Block[];
|
|
69
|
+
}
|
|
70
|
+
interface ExtractedBlock extends Block {
|
|
71
|
+
sectionStack: Section[];
|
|
72
|
+
blockPath: string;
|
|
73
|
+
}
|
|
74
|
+
interface Section {
|
|
75
|
+
[key: string]: any;
|
|
76
|
+
blocks?: Block[];
|
|
77
|
+
}
|
|
78
|
+
interface Template$1 {
|
|
79
|
+
category: string;
|
|
80
|
+
kp_templates?: {
|
|
81
|
+
[spaceId: string]: SpaceConfig;
|
|
82
|
+
} & {
|
|
83
|
+
myProfileConfig?: Block[];
|
|
84
|
+
};
|
|
85
|
+
kp_settings?: Block[];
|
|
86
|
+
}
|
|
87
|
+
interface SpaceConfig {
|
|
88
|
+
builder?: 'FormBuilder' | 'MetaBuilder' | 'kp_settings' | string;
|
|
89
|
+
configs?: Block[] | {
|
|
90
|
+
inputs: {
|
|
91
|
+
[key: string]: Block;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
subSpaces?: SpaceConfig[];
|
|
95
|
+
}
|
|
96
|
+
type BuilderType = 'FormBuilder' | 'MetaBuilder' | 'kp_settings' | string;
|
|
97
|
+
/**
|
|
98
|
+
* Extracts all blocks from a template configuration, preserving their hierarchical context.
|
|
99
|
+
*
|
|
100
|
+
* This function traverses template structures and extracts individual block configurations
|
|
101
|
+
* while maintaining information about their location (blockPath) and parent sections
|
|
102
|
+
* (sectionStack). This metadata is crucial for:
|
|
103
|
+
* - Updating block properties at their exact location
|
|
104
|
+
* - Handling display conditions that affect entire sections
|
|
105
|
+
* - Managing nested block hierarchies in form builders
|
|
106
|
+
*
|
|
107
|
+
* @param {Object} params - Extraction parameters
|
|
108
|
+
* @param {Template} params.tpl - The template configuration to extract blocks from
|
|
109
|
+
* @param {BuilderType[]} [params.buildersWhitelist] - Optional list of builders to extract from.
|
|
110
|
+
* If provided, only blocks from these builders will be included
|
|
111
|
+
* @returns {ExtractedBlock[]} Array of blocks with added sectionStack and blockPath metadata
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const blocks = extractAllBlocksFromTpl({
|
|
116
|
+
* tpl: templateConfig,
|
|
117
|
+
* buildersWhitelist: ['FormBuilder', 'kp_settings']
|
|
118
|
+
* });
|
|
119
|
+
*
|
|
120
|
+
* // Each block will have:
|
|
121
|
+
* // - Original block properties (type, label, valuePath, etc.)
|
|
122
|
+
* // - sectionStack: Array of parent sections for display condition handling
|
|
123
|
+
* // - blockPath: Dot-notation path for precise updates (e.g., "kp_templates.header.configs.0")
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
declare const extractAllBlocksFromTpl: ({ tpl, buildersWhitelist }: {
|
|
127
|
+
tpl: Template$1;
|
|
128
|
+
buildersWhitelist?: BuilderType[];
|
|
129
|
+
}) => ExtractedBlock[];
|
|
130
|
+
/**
|
|
131
|
+
* Recursively extracts blocks from a hierarchical data structure.
|
|
132
|
+
*
|
|
133
|
+
* This is the core traversal function that handles nested sections and blocks.
|
|
134
|
+
* It preserves two critical pieces of metadata:
|
|
135
|
+
*
|
|
136
|
+
* 1. **sectionStack**: Array of parent sections - Essential for display condition handling.
|
|
137
|
+
* When sections have display conditions, we need to know which blocks belong to
|
|
138
|
+
* hidden sections to exclude them from indexes and processing.
|
|
139
|
+
*
|
|
140
|
+
* 2. **blockPath**: Dot-notation path to the block's location - Required for precise updates.
|
|
141
|
+
* Used when modifying block properties or updating valuePaths in display conditions.
|
|
142
|
+
* See 'modifyValuesAndValuePaths' for detailed usage.
|
|
143
|
+
*
|
|
144
|
+
* @param {Object} params - Extraction parameters
|
|
145
|
+
* @param {Block[]} params.data - Array of blocks/sections to process
|
|
146
|
+
* @param {Function} params.cb - Callback function to handle each extracted block
|
|
147
|
+
* @param {Section[]} params.sectionStack - Current stack of parent sections
|
|
148
|
+
* @param {string} params.blockPathPrefix - Current path prefix for building blockPath
|
|
149
|
+
*/
|
|
150
|
+
declare const _recursExtractBlocks: ({ data, cb, sectionStack, blockPathPrefix }: {
|
|
151
|
+
data: Block[];
|
|
152
|
+
cb: (block: ExtractedBlock) => void;
|
|
153
|
+
sectionStack?: Section[];
|
|
154
|
+
blockPathPrefix?: string;
|
|
155
|
+
}) => void;
|
|
156
|
+
|
|
37
157
|
interface DbConnections {
|
|
38
158
|
[clusterName: string]: Connection;
|
|
39
159
|
}
|
|
@@ -175,4 +295,4 @@ declare const getAIConfigs: ({ tenant }: GetAIConfigsParams) => Promise<AIconfig
|
|
|
175
295
|
declare const connectToRedis: () => Promise<void>;
|
|
176
296
|
declare const getRedisClient: () => IORedis;
|
|
177
297
|
|
|
178
|
-
export { connectToRedis, deleteVal, genTagId, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, multiConnectToMongoDB, setVal, updateGlobalConfig };
|
|
298
|
+
export { connectToRedis, deleteVal, extractAllBlocksFromTpl, genTagId, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, multiConnectToMongoDB, _recursExtractBlocks as recursivelyExtractBlocks, setVal, toArray, updateGlobalConfig };
|