@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/node.d.ts 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 };
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,
@@ -331,7 +332,9 @@ __export(node_exports, {
331
332
  getVal: () => getVal,
332
333
  initializeGlobalConfig: () => initializeGlobalConfig,
333
334
  multiConnectToMongoDB: () => multiConnectToMongoDB,
335
+ recursivelyExtractBlocks: () => _recursExtractBlocks,
334
336
  setVal: () => setVal,
337
+ toArray: () => toArray,
335
338
  updateGlobalConfig: () => updateGlobalConfig
336
339
  });
337
340
  module.exports = __toCommonJS(node_exports);
@@ -492,6 +495,125 @@ var genTagId = (tagName) => {
492
495
  return toReturn.replace(/^_+|_+$/, "");
493
496
  };
494
497
 
498
+ // src/utils/toArray.ts
499
+ var toArray = (property) => {
500
+ if (!property && (property !== false && property !== 0)) return [];
501
+ if (Array.isArray(property)) return property;
502
+ return [property];
503
+ };
504
+
505
+ // src/utils/extractAllBlocksFromTpl.ts
506
+ var extractAllBlocksFromTpl = ({
507
+ tpl,
508
+ buildersWhitelist
509
+ }) => {
510
+ if (tpl.category === "userProfiles") {
511
+ const allBlocksAry = [];
512
+ if (tpl.kp_templates?.myProfileConfig) {
513
+ _recursExtractBlocks({
514
+ data: tpl.kp_templates.myProfileConfig,
515
+ cb: (block) => allBlocksAry.push(block),
516
+ sectionStack: [],
517
+ blockPathPrefix: "kp_templates.myProfileConfig"
518
+ });
519
+ }
520
+ return allBlocksAry;
521
+ } else {
522
+ return extractAllBlocksFromStructuredTpls({ tpl, buildersWhitelist });
523
+ }
524
+ };
525
+ var _recursExtractBlocks = ({
526
+ data,
527
+ cb,
528
+ sectionStack = [],
529
+ blockPathPrefix = ""
530
+ }) => {
531
+ data.forEach((d, idx) => {
532
+ if (!d.blocks) {
533
+ cb({
534
+ ...d,
535
+ sectionStack,
536
+ blockPath: `${blockPathPrefix}.${idx}`
537
+ });
538
+ } else {
539
+ _recursExtractBlocks({
540
+ data: d.blocks,
541
+ cb,
542
+ sectionStack: [...sectionStack, d],
543
+ blockPathPrefix: `${blockPathPrefix}.${idx}.blocks`
544
+ });
545
+ }
546
+ });
547
+ };
548
+ var extractAllBlocksFromStructuredTpls = ({
549
+ tpl,
550
+ buildersWhitelist
551
+ }) => {
552
+ const allBlocksAry = [];
553
+ if (tpl.kp_templates) {
554
+ for (let spaceId in tpl.kp_templates) {
555
+ let conf = tpl.kp_templates[spaceId];
556
+ if (conf.builder && buildersWhitelist && !buildersWhitelist.includes(conf.builder)) {
557
+ continue;
558
+ }
559
+ if (!conf.subSpaces) {
560
+ _extractBlocksFromSomeBuilders({
561
+ conf,
562
+ confPath: `kp_templates.${spaceId}`,
563
+ allBlocksAry
564
+ });
565
+ } else {
566
+ conf.subSpaces.forEach((sub, subIdx) => {
567
+ if (sub.builder && buildersWhitelist && !buildersWhitelist.includes(sub.builder)) {
568
+ return;
569
+ }
570
+ _extractBlocksFromSomeBuilders({
571
+ conf: sub,
572
+ confPath: `kp_templates.${spaceId}.subSpaces.${subIdx}`,
573
+ allBlocksAry
574
+ });
575
+ });
576
+ }
577
+ }
578
+ }
579
+ if (buildersWhitelist && !buildersWhitelist.includes("kp_settings")) {
580
+ return allBlocksAry;
581
+ }
582
+ if (tpl.kp_settings && tpl.kp_settings.length > 0) {
583
+ _recursExtractBlocks({
584
+ data: tpl.kp_settings,
585
+ cb: (block) => allBlocksAry.push(block),
586
+ blockPathPrefix: "kp_settings"
587
+ });
588
+ }
589
+ return allBlocksAry;
590
+ };
591
+ var _extractBlocksFromSomeBuilders = ({
592
+ conf,
593
+ confPath,
594
+ allBlocksAry
595
+ }) => {
596
+ if (conf.builder === "FormBuilder") {
597
+ const configs = conf.configs || [];
598
+ _recursExtractBlocks({
599
+ data: configs,
600
+ cb: (block) => allBlocksAry.push(block),
601
+ blockPathPrefix: `${confPath}.configs`
602
+ });
603
+ }
604
+ if (conf.builder === "MetaBuilder") {
605
+ const inputs = conf.configs?.inputs || {};
606
+ const inputBlockConfigsToPush = Object.keys(inputs).map((inputBlockKey) => {
607
+ const value = inputs[inputBlockKey];
608
+ return {
609
+ ...value,
610
+ blockPath: `${confPath}.configs.inputs.${inputBlockKey}`
611
+ };
612
+ });
613
+ allBlocksAry.push(...inputBlockConfigsToPush);
614
+ }
615
+ };
616
+
495
617
  // src/db/mongodb.ts
496
618
  var import_mongoose = __toESM(require("mongoose"));
497
619
 
@@ -738,6 +860,7 @@ var getAIConfigs = async ({
738
860
  0 && (module.exports = {
739
861
  connectToRedis,
740
862
  deleteVal,
863
+ extractAllBlocksFromTpl,
741
864
  genTagId,
742
865
  getAIConfigs,
743
866
  getAnnotationsModelByTenant,
@@ -750,6 +873,8 @@ var getAIConfigs = async ({
750
873
  getVal,
751
874
  initializeGlobalConfig,
752
875
  multiConnectToMongoDB,
876
+ recursivelyExtractBlocks,
753
877
  setVal,
878
+ toArray,
754
879
  updateGlobalConfig
755
880
  });
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,
@@ -706,6 +826,8 @@ export {
706
826
  getVal,
707
827
  initializeGlobalConfig,
708
828
  multiConnectToMongoDB,
829
+ _recursExtractBlocks as recursivelyExtractBlocks,
709
830
  setVal,
831
+ toArray,
710
832
  updateGlobalConfig
711
833
  };
@@ -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
- export { deleteVal, genTagId, getVal, setVal };
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 };
@@ -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
- export { deleteVal, genTagId, getVal, setVal };
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 };