@okf/ootils 1.3.4 → 1.3.5
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 +95 -1
- package/dist/browser.d.ts +95 -1
- package/dist/browser.js +125 -2
- package/dist/browser.mjs +122 -1
- package/dist/node.d.mts +95 -1
- package/dist/node.d.ts +95 -1
- package/dist/node.js +123 -0
- package/dist/node.mjs +121 -0
- package/dist/universal.d.mts +95 -1
- package/dist/universal.d.ts +95 -1
- package/dist/universal.js +125 -2
- package/dist/universal.mjs +122 -1
- package/package.json +1 -1
package/dist/node.js
CHANGED
|
@@ -319,6 +319,7 @@ var node_exports = {};
|
|
|
319
319
|
__export(node_exports, {
|
|
320
320
|
connectToRedis: () => connectToRedis,
|
|
321
321
|
deleteVal: () => deleteVal,
|
|
322
|
+
extractAllBlocksFromTpl: () => extractAllBlocksFromTpl,
|
|
322
323
|
genTagId: () => genTagId,
|
|
323
324
|
getAIConfigs: () => getAIConfigs,
|
|
324
325
|
getAnnotationsModelByTenant: () => getAnnotationsModelByTenant,
|
|
@@ -332,6 +333,7 @@ __export(node_exports, {
|
|
|
332
333
|
initializeGlobalConfig: () => initializeGlobalConfig,
|
|
333
334
|
multiConnectToMongoDB: () => multiConnectToMongoDB,
|
|
334
335
|
setVal: () => setVal,
|
|
336
|
+
toArray: () => toArray,
|
|
335
337
|
updateGlobalConfig: () => updateGlobalConfig
|
|
336
338
|
});
|
|
337
339
|
module.exports = __toCommonJS(node_exports);
|
|
@@ -492,6 +494,125 @@ var genTagId = (tagName) => {
|
|
|
492
494
|
return toReturn.replace(/^_+|_+$/, "");
|
|
493
495
|
};
|
|
494
496
|
|
|
497
|
+
// src/utils/toArray.ts
|
|
498
|
+
var toArray = (property) => {
|
|
499
|
+
if (!property && (property !== false && property !== 0)) return [];
|
|
500
|
+
if (Array.isArray(property)) return property;
|
|
501
|
+
return [property];
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
// src/utils/extractAllBlocksFromTpl.ts
|
|
505
|
+
var extractAllBlocksFromTpl = ({
|
|
506
|
+
tpl,
|
|
507
|
+
buildersWhitelist
|
|
508
|
+
}) => {
|
|
509
|
+
if (tpl.category === "userProfiles") {
|
|
510
|
+
const allBlocksAry = [];
|
|
511
|
+
if (tpl.kp_templates?.myProfileConfig) {
|
|
512
|
+
_recursExtractBlocks({
|
|
513
|
+
data: tpl.kp_templates.myProfileConfig,
|
|
514
|
+
cb: (block) => allBlocksAry.push(block),
|
|
515
|
+
sectionStack: [],
|
|
516
|
+
blockPathPrefix: "kp_templates.myProfileConfig"
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
return allBlocksAry;
|
|
520
|
+
} else {
|
|
521
|
+
return extractAllBlocksFromStructuredTpls({ tpl, buildersWhitelist });
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
var _recursExtractBlocks = ({
|
|
525
|
+
data,
|
|
526
|
+
cb,
|
|
527
|
+
sectionStack = [],
|
|
528
|
+
blockPathPrefix = ""
|
|
529
|
+
}) => {
|
|
530
|
+
data.forEach((d, idx) => {
|
|
531
|
+
if (!d.blocks) {
|
|
532
|
+
cb({
|
|
533
|
+
...d,
|
|
534
|
+
sectionStack,
|
|
535
|
+
blockPath: `${blockPathPrefix}.${idx}`
|
|
536
|
+
});
|
|
537
|
+
} else {
|
|
538
|
+
_recursExtractBlocks({
|
|
539
|
+
data: d.blocks,
|
|
540
|
+
cb,
|
|
541
|
+
sectionStack: [...sectionStack, d],
|
|
542
|
+
blockPathPrefix: `${blockPathPrefix}.${idx}.blocks`
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
};
|
|
547
|
+
var extractAllBlocksFromStructuredTpls = ({
|
|
548
|
+
tpl,
|
|
549
|
+
buildersWhitelist
|
|
550
|
+
}) => {
|
|
551
|
+
const allBlocksAry = [];
|
|
552
|
+
if (tpl.kp_templates) {
|
|
553
|
+
for (let spaceId in tpl.kp_templates) {
|
|
554
|
+
let conf = tpl.kp_templates[spaceId];
|
|
555
|
+
if (conf.builder && buildersWhitelist && !buildersWhitelist.includes(conf.builder)) {
|
|
556
|
+
continue;
|
|
557
|
+
}
|
|
558
|
+
if (!conf.subSpaces) {
|
|
559
|
+
_extractBlocksFromSomeBuilders({
|
|
560
|
+
conf,
|
|
561
|
+
confPath: `kp_templates.${spaceId}`,
|
|
562
|
+
allBlocksAry
|
|
563
|
+
});
|
|
564
|
+
} else {
|
|
565
|
+
conf.subSpaces.forEach((sub, subIdx) => {
|
|
566
|
+
if (sub.builder && buildersWhitelist && !buildersWhitelist.includes(sub.builder)) {
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
_extractBlocksFromSomeBuilders({
|
|
570
|
+
conf: sub,
|
|
571
|
+
confPath: `kp_templates.${spaceId}.subSpaces.${subIdx}`,
|
|
572
|
+
allBlocksAry
|
|
573
|
+
});
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
if (buildersWhitelist && !buildersWhitelist.includes("kp_settings")) {
|
|
579
|
+
return allBlocksAry;
|
|
580
|
+
}
|
|
581
|
+
if (tpl.kp_settings && tpl.kp_settings.length > 0) {
|
|
582
|
+
_recursExtractBlocks({
|
|
583
|
+
data: tpl.kp_settings,
|
|
584
|
+
cb: (block) => allBlocksAry.push(block),
|
|
585
|
+
blockPathPrefix: "kp_settings"
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
return allBlocksAry;
|
|
589
|
+
};
|
|
590
|
+
var _extractBlocksFromSomeBuilders = ({
|
|
591
|
+
conf,
|
|
592
|
+
confPath,
|
|
593
|
+
allBlocksAry
|
|
594
|
+
}) => {
|
|
595
|
+
if (conf.builder === "FormBuilder") {
|
|
596
|
+
const configs = conf.configs || [];
|
|
597
|
+
_recursExtractBlocks({
|
|
598
|
+
data: configs,
|
|
599
|
+
cb: (block) => allBlocksAry.push(block),
|
|
600
|
+
blockPathPrefix: `${confPath}.configs`
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
if (conf.builder === "MetaBuilder") {
|
|
604
|
+
const inputs = conf.configs?.inputs || {};
|
|
605
|
+
const inputBlockConfigsToPush = Object.keys(inputs).map((inputBlockKey) => {
|
|
606
|
+
const value = inputs[inputBlockKey];
|
|
607
|
+
return {
|
|
608
|
+
...value,
|
|
609
|
+
blockPath: `${confPath}.configs.inputs.${inputBlockKey}`
|
|
610
|
+
};
|
|
611
|
+
});
|
|
612
|
+
allBlocksAry.push(...inputBlockConfigsToPush);
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
|
|
495
616
|
// src/db/mongodb.ts
|
|
496
617
|
var import_mongoose = __toESM(require("mongoose"));
|
|
497
618
|
|
|
@@ -738,6 +859,7 @@ var getAIConfigs = async ({
|
|
|
738
859
|
0 && (module.exports = {
|
|
739
860
|
connectToRedis,
|
|
740
861
|
deleteVal,
|
|
862
|
+
extractAllBlocksFromTpl,
|
|
741
863
|
genTagId,
|
|
742
864
|
getAIConfigs,
|
|
743
865
|
getAnnotationsModelByTenant,
|
|
@@ -751,5 +873,6 @@ var getAIConfigs = async ({
|
|
|
751
873
|
initializeGlobalConfig,
|
|
752
874
|
multiConnectToMongoDB,
|
|
753
875
|
setVal,
|
|
876
|
+
toArray,
|
|
754
877
|
updateGlobalConfig
|
|
755
878
|
});
|
package/dist/node.mjs
CHANGED
|
@@ -449,6 +449,125 @@ var genTagId = (tagName) => {
|
|
|
449
449
|
return toReturn.replace(/^_+|_+$/, "");
|
|
450
450
|
};
|
|
451
451
|
|
|
452
|
+
// src/utils/toArray.ts
|
|
453
|
+
var toArray = (property) => {
|
|
454
|
+
if (!property && (property !== false && property !== 0)) return [];
|
|
455
|
+
if (Array.isArray(property)) return property;
|
|
456
|
+
return [property];
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
// src/utils/extractAllBlocksFromTpl.ts
|
|
460
|
+
var extractAllBlocksFromTpl = ({
|
|
461
|
+
tpl,
|
|
462
|
+
buildersWhitelist
|
|
463
|
+
}) => {
|
|
464
|
+
if (tpl.category === "userProfiles") {
|
|
465
|
+
const allBlocksAry = [];
|
|
466
|
+
if (tpl.kp_templates?.myProfileConfig) {
|
|
467
|
+
_recursExtractBlocks({
|
|
468
|
+
data: tpl.kp_templates.myProfileConfig,
|
|
469
|
+
cb: (block) => allBlocksAry.push(block),
|
|
470
|
+
sectionStack: [],
|
|
471
|
+
blockPathPrefix: "kp_templates.myProfileConfig"
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
return allBlocksAry;
|
|
475
|
+
} else {
|
|
476
|
+
return extractAllBlocksFromStructuredTpls({ tpl, buildersWhitelist });
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
var _recursExtractBlocks = ({
|
|
480
|
+
data,
|
|
481
|
+
cb,
|
|
482
|
+
sectionStack = [],
|
|
483
|
+
blockPathPrefix = ""
|
|
484
|
+
}) => {
|
|
485
|
+
data.forEach((d, idx) => {
|
|
486
|
+
if (!d.blocks) {
|
|
487
|
+
cb({
|
|
488
|
+
...d,
|
|
489
|
+
sectionStack,
|
|
490
|
+
blockPath: `${blockPathPrefix}.${idx}`
|
|
491
|
+
});
|
|
492
|
+
} else {
|
|
493
|
+
_recursExtractBlocks({
|
|
494
|
+
data: d.blocks,
|
|
495
|
+
cb,
|
|
496
|
+
sectionStack: [...sectionStack, d],
|
|
497
|
+
blockPathPrefix: `${blockPathPrefix}.${idx}.blocks`
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
};
|
|
502
|
+
var extractAllBlocksFromStructuredTpls = ({
|
|
503
|
+
tpl,
|
|
504
|
+
buildersWhitelist
|
|
505
|
+
}) => {
|
|
506
|
+
const allBlocksAry = [];
|
|
507
|
+
if (tpl.kp_templates) {
|
|
508
|
+
for (let spaceId in tpl.kp_templates) {
|
|
509
|
+
let conf = tpl.kp_templates[spaceId];
|
|
510
|
+
if (conf.builder && buildersWhitelist && !buildersWhitelist.includes(conf.builder)) {
|
|
511
|
+
continue;
|
|
512
|
+
}
|
|
513
|
+
if (!conf.subSpaces) {
|
|
514
|
+
_extractBlocksFromSomeBuilders({
|
|
515
|
+
conf,
|
|
516
|
+
confPath: `kp_templates.${spaceId}`,
|
|
517
|
+
allBlocksAry
|
|
518
|
+
});
|
|
519
|
+
} else {
|
|
520
|
+
conf.subSpaces.forEach((sub, subIdx) => {
|
|
521
|
+
if (sub.builder && buildersWhitelist && !buildersWhitelist.includes(sub.builder)) {
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
_extractBlocksFromSomeBuilders({
|
|
525
|
+
conf: sub,
|
|
526
|
+
confPath: `kp_templates.${spaceId}.subSpaces.${subIdx}`,
|
|
527
|
+
allBlocksAry
|
|
528
|
+
});
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
if (buildersWhitelist && !buildersWhitelist.includes("kp_settings")) {
|
|
534
|
+
return allBlocksAry;
|
|
535
|
+
}
|
|
536
|
+
if (tpl.kp_settings && tpl.kp_settings.length > 0) {
|
|
537
|
+
_recursExtractBlocks({
|
|
538
|
+
data: tpl.kp_settings,
|
|
539
|
+
cb: (block) => allBlocksAry.push(block),
|
|
540
|
+
blockPathPrefix: "kp_settings"
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
return allBlocksAry;
|
|
544
|
+
};
|
|
545
|
+
var _extractBlocksFromSomeBuilders = ({
|
|
546
|
+
conf,
|
|
547
|
+
confPath,
|
|
548
|
+
allBlocksAry
|
|
549
|
+
}) => {
|
|
550
|
+
if (conf.builder === "FormBuilder") {
|
|
551
|
+
const configs = conf.configs || [];
|
|
552
|
+
_recursExtractBlocks({
|
|
553
|
+
data: configs,
|
|
554
|
+
cb: (block) => allBlocksAry.push(block),
|
|
555
|
+
blockPathPrefix: `${confPath}.configs`
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
if (conf.builder === "MetaBuilder") {
|
|
559
|
+
const inputs = conf.configs?.inputs || {};
|
|
560
|
+
const inputBlockConfigsToPush = Object.keys(inputs).map((inputBlockKey) => {
|
|
561
|
+
const value = inputs[inputBlockKey];
|
|
562
|
+
return {
|
|
563
|
+
...value,
|
|
564
|
+
blockPath: `${confPath}.configs.inputs.${inputBlockKey}`
|
|
565
|
+
};
|
|
566
|
+
});
|
|
567
|
+
allBlocksAry.push(...inputBlockConfigsToPush);
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
|
|
452
571
|
// src/db/mongodb.ts
|
|
453
572
|
import mongoose from "mongoose";
|
|
454
573
|
|
|
@@ -694,6 +813,7 @@ var getAIConfigs = async ({
|
|
|
694
813
|
export {
|
|
695
814
|
connectToRedis,
|
|
696
815
|
deleteVal,
|
|
816
|
+
extractAllBlocksFromTpl,
|
|
697
817
|
genTagId,
|
|
698
818
|
getAIConfigs,
|
|
699
819
|
getAnnotationsModelByTenant,
|
|
@@ -707,5 +827,6 @@ export {
|
|
|
707
827
|
initializeGlobalConfig,
|
|
708
828
|
multiConnectToMongoDB,
|
|
709
829
|
setVal,
|
|
830
|
+
toArray,
|
|
710
831
|
updateGlobalConfig
|
|
711
832
|
};
|
package/dist/universal.d.mts
CHANGED
|
@@ -31,4 +31,98 @@ 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
|
+
export { deleteVal, extractAllBlocksFromTpl, genTagId, getVal, setVal, toArray };
|
package/dist/universal.d.ts
CHANGED
|
@@ -31,4 +31,98 @@ 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
|
+
export { deleteVal, extractAllBlocksFromTpl, genTagId, getVal, setVal, toArray };
|
package/dist/universal.js
CHANGED
|
@@ -21,9 +21,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var universal_exports = {};
|
|
22
22
|
__export(universal_exports, {
|
|
23
23
|
deleteVal: () => deleteVal,
|
|
24
|
+
extractAllBlocksFromTpl: () => extractAllBlocksFromTpl,
|
|
24
25
|
genTagId: () => genTagId,
|
|
25
26
|
getVal: () => getVal,
|
|
26
|
-
setVal: () => setVal
|
|
27
|
+
setVal: () => setVal,
|
|
28
|
+
toArray: () => toArray
|
|
27
29
|
});
|
|
28
30
|
module.exports = __toCommonJS(universal_exports);
|
|
29
31
|
|
|
@@ -182,10 +184,131 @@ var genTagId = (tagName) => {
|
|
|
182
184
|
toReturn = toReturn.replace(/\+/g, "plus");
|
|
183
185
|
return toReturn.replace(/^_+|_+$/, "");
|
|
184
186
|
};
|
|
187
|
+
|
|
188
|
+
// src/utils/toArray.ts
|
|
189
|
+
var toArray = (property) => {
|
|
190
|
+
if (!property && (property !== false && property !== 0)) return [];
|
|
191
|
+
if (Array.isArray(property)) return property;
|
|
192
|
+
return [property];
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// src/utils/extractAllBlocksFromTpl.ts
|
|
196
|
+
var extractAllBlocksFromTpl = ({
|
|
197
|
+
tpl,
|
|
198
|
+
buildersWhitelist
|
|
199
|
+
}) => {
|
|
200
|
+
if (tpl.category === "userProfiles") {
|
|
201
|
+
const allBlocksAry = [];
|
|
202
|
+
if (tpl.kp_templates?.myProfileConfig) {
|
|
203
|
+
_recursExtractBlocks({
|
|
204
|
+
data: tpl.kp_templates.myProfileConfig,
|
|
205
|
+
cb: (block) => allBlocksAry.push(block),
|
|
206
|
+
sectionStack: [],
|
|
207
|
+
blockPathPrefix: "kp_templates.myProfileConfig"
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
return allBlocksAry;
|
|
211
|
+
} else {
|
|
212
|
+
return extractAllBlocksFromStructuredTpls({ tpl, buildersWhitelist });
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
var _recursExtractBlocks = ({
|
|
216
|
+
data,
|
|
217
|
+
cb,
|
|
218
|
+
sectionStack = [],
|
|
219
|
+
blockPathPrefix = ""
|
|
220
|
+
}) => {
|
|
221
|
+
data.forEach((d, idx) => {
|
|
222
|
+
if (!d.blocks) {
|
|
223
|
+
cb({
|
|
224
|
+
...d,
|
|
225
|
+
sectionStack,
|
|
226
|
+
blockPath: `${blockPathPrefix}.${idx}`
|
|
227
|
+
});
|
|
228
|
+
} else {
|
|
229
|
+
_recursExtractBlocks({
|
|
230
|
+
data: d.blocks,
|
|
231
|
+
cb,
|
|
232
|
+
sectionStack: [...sectionStack, d],
|
|
233
|
+
blockPathPrefix: `${blockPathPrefix}.${idx}.blocks`
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
var extractAllBlocksFromStructuredTpls = ({
|
|
239
|
+
tpl,
|
|
240
|
+
buildersWhitelist
|
|
241
|
+
}) => {
|
|
242
|
+
const allBlocksAry = [];
|
|
243
|
+
if (tpl.kp_templates) {
|
|
244
|
+
for (let spaceId in tpl.kp_templates) {
|
|
245
|
+
let conf = tpl.kp_templates[spaceId];
|
|
246
|
+
if (conf.builder && buildersWhitelist && !buildersWhitelist.includes(conf.builder)) {
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
if (!conf.subSpaces) {
|
|
250
|
+
_extractBlocksFromSomeBuilders({
|
|
251
|
+
conf,
|
|
252
|
+
confPath: `kp_templates.${spaceId}`,
|
|
253
|
+
allBlocksAry
|
|
254
|
+
});
|
|
255
|
+
} else {
|
|
256
|
+
conf.subSpaces.forEach((sub, subIdx) => {
|
|
257
|
+
if (sub.builder && buildersWhitelist && !buildersWhitelist.includes(sub.builder)) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
_extractBlocksFromSomeBuilders({
|
|
261
|
+
conf: sub,
|
|
262
|
+
confPath: `kp_templates.${spaceId}.subSpaces.${subIdx}`,
|
|
263
|
+
allBlocksAry
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (buildersWhitelist && !buildersWhitelist.includes("kp_settings")) {
|
|
270
|
+
return allBlocksAry;
|
|
271
|
+
}
|
|
272
|
+
if (tpl.kp_settings && tpl.kp_settings.length > 0) {
|
|
273
|
+
_recursExtractBlocks({
|
|
274
|
+
data: tpl.kp_settings,
|
|
275
|
+
cb: (block) => allBlocksAry.push(block),
|
|
276
|
+
blockPathPrefix: "kp_settings"
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
return allBlocksAry;
|
|
280
|
+
};
|
|
281
|
+
var _extractBlocksFromSomeBuilders = ({
|
|
282
|
+
conf,
|
|
283
|
+
confPath,
|
|
284
|
+
allBlocksAry
|
|
285
|
+
}) => {
|
|
286
|
+
if (conf.builder === "FormBuilder") {
|
|
287
|
+
const configs = conf.configs || [];
|
|
288
|
+
_recursExtractBlocks({
|
|
289
|
+
data: configs,
|
|
290
|
+
cb: (block) => allBlocksAry.push(block),
|
|
291
|
+
blockPathPrefix: `${confPath}.configs`
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
if (conf.builder === "MetaBuilder") {
|
|
295
|
+
const inputs = conf.configs?.inputs || {};
|
|
296
|
+
const inputBlockConfigsToPush = Object.keys(inputs).map((inputBlockKey) => {
|
|
297
|
+
const value = inputs[inputBlockKey];
|
|
298
|
+
return {
|
|
299
|
+
...value,
|
|
300
|
+
blockPath: `${confPath}.configs.inputs.${inputBlockKey}`
|
|
301
|
+
};
|
|
302
|
+
});
|
|
303
|
+
allBlocksAry.push(...inputBlockConfigsToPush);
|
|
304
|
+
}
|
|
305
|
+
};
|
|
185
306
|
// Annotate the CommonJS export names for ESM import in node:
|
|
186
307
|
0 && (module.exports = {
|
|
187
308
|
deleteVal,
|
|
309
|
+
extractAllBlocksFromTpl,
|
|
188
310
|
genTagId,
|
|
189
311
|
getVal,
|
|
190
|
-
setVal
|
|
312
|
+
setVal,
|
|
313
|
+
toArray
|
|
191
314
|
});
|