@okf/ootils 1.3.3 → 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.
@@ -293,10 +293,280 @@ var require_Tpl = __commonJS({
293
293
  }
294
294
  });
295
295
 
296
- // src/utils/testFn.ts
297
- function add(a, b) {
298
- return a + b;
299
- }
296
+ // src/utils/getterSetterDeleter/utils/set_deleteVal.ts
297
+ var set_deleteVal = (action, data, valuePath, value) => {
298
+ if (valuePath === void 0) return;
299
+ if (valuePath === null && action === "set") {
300
+ data = value;
301
+ return data;
302
+ }
303
+ let dataRef = data;
304
+ const keysArray = valuePath.split(".");
305
+ const len = keysArray.length;
306
+ let valIsUndefined = false;
307
+ for (let i = 0; i < len - 1; i++) {
308
+ const key = keysArray[i];
309
+ if (!dataRef[key]) {
310
+ if (action === "set") {
311
+ const nextKey = keysArray[i + 1];
312
+ if (nextKey && !isNaN(parseInt(nextKey))) {
313
+ dataRef[key] = [];
314
+ } else {
315
+ dataRef[key] = {};
316
+ }
317
+ } else {
318
+ valIsUndefined = true;
319
+ break;
320
+ }
321
+ }
322
+ dataRef = dataRef[key];
323
+ }
324
+ if (valIsUndefined) return void 0;
325
+ if (action === "set") {
326
+ dataRef[keysArray[len - 1]] = value;
327
+ return data;
328
+ } else if (action === "delete") {
329
+ if (Array.isArray(dataRef)) {
330
+ dataRef.splice(parseInt(keysArray[len - 1]), 1);
331
+ } else {
332
+ delete dataRef[keysArray[len - 1]];
333
+ }
334
+ return data;
335
+ }
336
+ };
337
+
338
+ // src/utils/getterSetterDeleter/deleteVal.ts
339
+ var deleteVal = (data, valuePath) => {
340
+ return set_deleteVal("delete", data, valuePath);
341
+ };
342
+
343
+ // src/utils/getterSetterDeleter/setVal.ts
344
+ var setVal = (data, valuePath, value) => {
345
+ return set_deleteVal("set", data, valuePath, value);
346
+ };
347
+
348
+ // src/utils/getterSetterDeleter/utils/flattenArrayOfArrays.ts
349
+ var flattenArrayOfArrays = ({
350
+ array,
351
+ flattenLastArray = true,
352
+ toReturn = []
353
+ }) => {
354
+ array.map((ary) => {
355
+ if (Array.isArray(ary)) {
356
+ if (flattenLastArray === true) {
357
+ if (ary.some((childAry) => !Array.isArray(childAry))) {
358
+ toReturn.push(ary);
359
+ } else {
360
+ flattenArrayOfArrays({ array: ary, flattenLastArray, toReturn });
361
+ }
362
+ } else {
363
+ flattenArrayOfArrays({ array: ary, flattenLastArray, toReturn });
364
+ }
365
+ } else {
366
+ toReturn.push(ary);
367
+ }
368
+ });
369
+ return toReturn;
370
+ };
371
+
372
+ // src/utils/getterSetterDeleter/getVal.ts
373
+ var getVal = (data, valuePath, options = {}, depthIdx = 0) => {
374
+ let value = null;
375
+ const getFinalVal = (data2, valuePath2, options2, depthIdx2) => {
376
+ return Array.isArray(data2) ? data2.map((R) => getValV2_getter(R, valuePath2, options2, depthIdx2)) : getValV2_getter(data2, valuePath2, options2, depthIdx2);
377
+ };
378
+ if (Array.isArray(valuePath)) {
379
+ for (let i = 0; i < valuePath.length; i++) {
380
+ value = getFinalVal(data, valuePath[i], options, depthIdx);
381
+ if (value) break;
382
+ }
383
+ } else {
384
+ value = getFinalVal(data, valuePath, options, depthIdx);
385
+ }
386
+ return value;
387
+ };
388
+ var getValV2_getter = (data, valuePath, options, depthIdx) => {
389
+ const { flattenIfValueIsArray = true } = options;
390
+ if (valuePath === null) return data;
391
+ let dataRef = data;
392
+ const keysArray = valuePath.split(".");
393
+ const len = keysArray.length;
394
+ let valIsUndefined = false;
395
+ let thisIterationFoundAry = false;
396
+ for (let i = 0; i < len - 1; i++) {
397
+ const key = keysArray[i];
398
+ if (!thisIterationFoundAry) {
399
+ if (!dataRef[key]) {
400
+ valIsUndefined = true;
401
+ break;
402
+ }
403
+ dataRef = dataRef[key];
404
+ } else {
405
+ const nestedAryResponse = dataRef.map((dataRefItem) => {
406
+ const remainingValuePath = keysArray.filter((dd, ii) => ii >= i).join(".");
407
+ return getVal(dataRefItem, remainingValuePath, options, depthIdx + 1);
408
+ });
409
+ return flattenArrayOfArrays({
410
+ array: nestedAryResponse,
411
+ flattenLastArray: depthIdx === 0 && flattenIfValueIsArray === false ? false : true
412
+ });
413
+ }
414
+ if (Array.isArray(dataRef) && Number.isNaN(parseInt(keysArray[i + 1]))) thisIterationFoundAry = true;
415
+ }
416
+ if (valIsUndefined) return void 0;
417
+ if (thisIterationFoundAry) {
418
+ const toReturn = dataRef.map((d) => d[keysArray[len - 1]]);
419
+ return flattenArrayOfArrays({
420
+ array: toReturn,
421
+ flattenLastArray: flattenIfValueIsArray
422
+ });
423
+ }
424
+ return dataRef[keysArray[len - 1]];
425
+ };
426
+
427
+ // src/utils/genTagId.ts
428
+ var convertFromRichText = (value) => {
429
+ if (!value) return "";
430
+ let val = "";
431
+ if (typeof value === "string" || typeof value === "number") {
432
+ return String(value);
433
+ }
434
+ if (typeof value === "object" && "blocks" in value && Array.isArray(value.blocks)) {
435
+ for (let i = 0; i < value.blocks.length; i++) {
436
+ const block = value.blocks[i];
437
+ if (block && block.text && block.text.length > 0) {
438
+ val = val + block.text;
439
+ }
440
+ }
441
+ }
442
+ return val;
443
+ };
444
+ var genTagId = (tagName) => {
445
+ let toReturn = convertFromRichText(tagName);
446
+ const regex = /[^\p{L}\p{N}\+]+/gui;
447
+ toReturn = toReturn.trim().toLowerCase().replace(regex, "_");
448
+ toReturn = toReturn.replace(/\+/g, "plus");
449
+ return toReturn.replace(/^_+|_+$/, "");
450
+ };
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
+ };
300
570
 
301
571
  // src/db/mongodb.ts
302
572
  import mongoose from "mongoose";
@@ -540,166 +810,10 @@ var getAIConfigs = async ({
540
810
  }
541
811
  });
542
812
  };
543
-
544
- // src/utils/getterSetterDeleter/utils/set_deleteVal.ts
545
- var set_deleteVal = (action, data, valuePath, value) => {
546
- if (valuePath === void 0) return;
547
- if (valuePath === null && action === "set") {
548
- data = value;
549
- return data;
550
- }
551
- let dataRef = data;
552
- const keysArray = valuePath.split(".");
553
- const len = keysArray.length;
554
- let valIsUndefined = false;
555
- for (let i = 0; i < len - 1; i++) {
556
- const key = keysArray[i];
557
- if (!dataRef[key]) {
558
- if (action === "set") {
559
- const nextKey = keysArray[i + 1];
560
- if (nextKey && !isNaN(parseInt(nextKey))) {
561
- dataRef[key] = [];
562
- } else {
563
- dataRef[key] = {};
564
- }
565
- } else {
566
- valIsUndefined = true;
567
- break;
568
- }
569
- }
570
- dataRef = dataRef[key];
571
- }
572
- if (valIsUndefined) return void 0;
573
- if (action === "set") {
574
- dataRef[keysArray[len - 1]] = value;
575
- return data;
576
- } else if (action === "delete") {
577
- if (Array.isArray(dataRef)) {
578
- dataRef.splice(parseInt(keysArray[len - 1]), 1);
579
- } else {
580
- delete dataRef[keysArray[len - 1]];
581
- }
582
- return data;
583
- }
584
- };
585
-
586
- // src/utils/getterSetterDeleter/deleteVal.ts
587
- var deleteVal = (data, valuePath) => {
588
- return set_deleteVal("delete", data, valuePath);
589
- };
590
-
591
- // src/utils/getterSetterDeleter/setVal.ts
592
- var setVal = (data, valuePath, value) => {
593
- return set_deleteVal("set", data, valuePath, value);
594
- };
595
-
596
- // src/utils/getterSetterDeleter/utils/flattenArrayOfArrays.ts
597
- var flattenArrayOfArrays = ({
598
- array,
599
- flattenLastArray = true,
600
- toReturn = []
601
- }) => {
602
- array.map((ary) => {
603
- if (Array.isArray(ary)) {
604
- if (flattenLastArray === true) {
605
- if (ary.some((childAry) => !Array.isArray(childAry))) {
606
- toReturn.push(ary);
607
- } else {
608
- flattenArrayOfArrays({ array: ary, flattenLastArray, toReturn });
609
- }
610
- } else {
611
- flattenArrayOfArrays({ array: ary, flattenLastArray, toReturn });
612
- }
613
- } else {
614
- toReturn.push(ary);
615
- }
616
- });
617
- return toReturn;
618
- };
619
-
620
- // src/utils/getterSetterDeleter/getVal.ts
621
- var getVal = (data, valuePath, options = {}, depthIdx = 0) => {
622
- let value = null;
623
- const getFinalVal = (data2, valuePath2, options2, depthIdx2) => {
624
- return Array.isArray(data2) ? data2.map((R) => getValV2_getter(R, valuePath2, options2, depthIdx2)) : getValV2_getter(data2, valuePath2, options2, depthIdx2);
625
- };
626
- if (Array.isArray(valuePath)) {
627
- for (let i = 0; i < valuePath.length; i++) {
628
- value = getFinalVal(data, valuePath[i], options, depthIdx);
629
- if (value) break;
630
- }
631
- } else {
632
- value = getFinalVal(data, valuePath, options, depthIdx);
633
- }
634
- return value;
635
- };
636
- var getValV2_getter = (data, valuePath, options, depthIdx) => {
637
- const { flattenIfValueIsArray = true } = options;
638
- if (valuePath === null) return data;
639
- let dataRef = data;
640
- const keysArray = valuePath.split(".");
641
- const len = keysArray.length;
642
- let valIsUndefined = false;
643
- let thisIterationFoundAry = false;
644
- for (let i = 0; i < len - 1; i++) {
645
- const key = keysArray[i];
646
- if (!thisIterationFoundAry) {
647
- if (!dataRef[key]) {
648
- valIsUndefined = true;
649
- break;
650
- }
651
- dataRef = dataRef[key];
652
- } else {
653
- const nestedAryResponse = dataRef.map((dataRefItem) => {
654
- const remainingValuePath = keysArray.filter((dd, ii) => ii >= i).join(".");
655
- return getVal(dataRefItem, remainingValuePath, options, depthIdx + 1);
656
- });
657
- return flattenArrayOfArrays({
658
- array: nestedAryResponse,
659
- flattenLastArray: depthIdx === 0 && flattenIfValueIsArray === false ? false : true
660
- });
661
- }
662
- if (Array.isArray(dataRef) && Number.isNaN(parseInt(keysArray[i + 1]))) thisIterationFoundAry = true;
663
- }
664
- if (valIsUndefined) return void 0;
665
- if (thisIterationFoundAry) {
666
- const toReturn = dataRef.map((d) => d[keysArray[len - 1]]);
667
- return flattenArrayOfArrays({
668
- array: toReturn,
669
- flattenLastArray: flattenIfValueIsArray
670
- });
671
- }
672
- return dataRef[keysArray[len - 1]];
673
- };
674
-
675
- // src/utils/genTagId.ts
676
- var convertFromRichText = (value) => {
677
- if (!value) return "";
678
- let val = "";
679
- if (typeof value === "string" || typeof value === "number") {
680
- return String(value);
681
- }
682
- if (typeof value === "object" && "blocks" in value && Array.isArray(value.blocks)) {
683
- for (let i = 0; i < value.blocks.length; i++) {
684
- const block = value.blocks[i];
685
- if (block && block.text && block.text.length > 0) {
686
- val = val + block.text;
687
- }
688
- }
689
- }
690
- return val;
691
- };
692
- var genTagId = (tagName) => {
693
- let toReturn = convertFromRichText(tagName);
694
- const regex = /[^\p{L}\p{N}\+]+/gui;
695
- toReturn = toReturn.trim().toLowerCase().replace(regex, "_");
696
- toReturn = toReturn.replace(/\+/g, "plus");
697
- return toReturn.replace(/^_+|_+$/, "");
698
- };
699
813
  export {
700
- add,
701
814
  connectToRedis,
702
815
  deleteVal,
816
+ extractAllBlocksFromTpl,
703
817
  genTagId,
704
818
  getAIConfigs,
705
819
  getAnnotationsModelByTenant,
@@ -713,5 +827,6 @@ export {
713
827
  initializeGlobalConfig,
714
828
  multiConnectToMongoDB,
715
829
  setVal,
830
+ toArray,
716
831
  updateGlobalConfig
717
832
  };
@@ -0,0 +1,128 @@
1
+ declare const deleteVal: (data: any, valuePath: string) => any;
2
+
3
+ type ValuePath = string | string[];
4
+ type DataValue = any;
5
+ interface GetValOptions {
6
+ flattenIfValueIsArray?: boolean;
7
+ }
8
+
9
+ declare const setVal: (data: any, valuePath: string, value: DataValue) => any;
10
+
11
+ /**
12
+ *
13
+ * @param {*} data
14
+ * @param {*} valuePath
15
+ * @returns
16
+ * - if target value is an array found inside an array, it will flatten them out so that there is a single array
17
+ * - if target value is an array NOT found inside an array, that will be returned as is.
18
+ * - if target value is a string/object/number/boolean found inside an array of arrays, then the inner arrays will be flattened so that there is a single array
19
+ * - if target value is a string/object/number/boolean NOT found inside an array, it will be returned as is.
20
+ */
21
+ declare const getVal: (data: any, valuePath: ValuePath, options?: GetValOptions, depthIdx?: number) => any;
22
+
23
+ interface RichTextBlock {
24
+ text: string;
25
+ [key: string]: any;
26
+ }
27
+ interface RichTextValue {
28
+ blocks: RichTextBlock[];
29
+ [key: string]: any;
30
+ }
31
+ type TagNameInput = string | number | RichTextValue | null | undefined;
32
+ declare const genTagId: (tagName: TagNameInput) => string;
33
+
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 };
@@ -0,0 +1,128 @@
1
+ declare const deleteVal: (data: any, valuePath: string) => any;
2
+
3
+ type ValuePath = string | string[];
4
+ type DataValue = any;
5
+ interface GetValOptions {
6
+ flattenIfValueIsArray?: boolean;
7
+ }
8
+
9
+ declare const setVal: (data: any, valuePath: string, value: DataValue) => any;
10
+
11
+ /**
12
+ *
13
+ * @param {*} data
14
+ * @param {*} valuePath
15
+ * @returns
16
+ * - if target value is an array found inside an array, it will flatten them out so that there is a single array
17
+ * - if target value is an array NOT found inside an array, that will be returned as is.
18
+ * - if target value is a string/object/number/boolean found inside an array of arrays, then the inner arrays will be flattened so that there is a single array
19
+ * - if target value is a string/object/number/boolean NOT found inside an array, it will be returned as is.
20
+ */
21
+ declare const getVal: (data: any, valuePath: ValuePath, options?: GetValOptions, depthIdx?: number) => any;
22
+
23
+ interface RichTextBlock {
24
+ text: string;
25
+ [key: string]: any;
26
+ }
27
+ interface RichTextValue {
28
+ blocks: RichTextBlock[];
29
+ [key: string]: any;
30
+ }
31
+ type TagNameInput = string | number | RichTextValue | null | undefined;
32
+ declare const genTagId: (tagName: TagNameInput) => string;
33
+
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 };