@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.
- package/dist/browser.d.mts +128 -0
- package/dist/browser.d.ts +128 -0
- package/dist/browser.js +314 -0
- package/dist/browser.mjs +282 -0
- package/dist/{index.d.mts → node.d.mts} +127 -35
- package/dist/{index.d.ts → node.d.ts} +127 -35
- package/dist/{index.js → node.js} +282 -166
- package/dist/{index.mjs → node.mjs} +276 -161
- package/dist/universal.d.mts +128 -0
- package/dist/universal.d.ts +128 -0
- package/dist/universal.js +314 -0
- package/dist/universal.mjs +282 -0
- package/package.json +35 -5
|
@@ -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 };
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/browser.ts
|
|
21
|
+
var browser_exports = {};
|
|
22
|
+
__export(browser_exports, {
|
|
23
|
+
deleteVal: () => deleteVal,
|
|
24
|
+
extractAllBlocksFromTpl: () => extractAllBlocksFromTpl,
|
|
25
|
+
genTagId: () => genTagId,
|
|
26
|
+
getVal: () => getVal,
|
|
27
|
+
setVal: () => setVal,
|
|
28
|
+
toArray: () => toArray
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(browser_exports);
|
|
31
|
+
|
|
32
|
+
// src/utils/getterSetterDeleter/utils/set_deleteVal.ts
|
|
33
|
+
var set_deleteVal = (action, data, valuePath, value) => {
|
|
34
|
+
if (valuePath === void 0) return;
|
|
35
|
+
if (valuePath === null && action === "set") {
|
|
36
|
+
data = value;
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
let dataRef = data;
|
|
40
|
+
const keysArray = valuePath.split(".");
|
|
41
|
+
const len = keysArray.length;
|
|
42
|
+
let valIsUndefined = false;
|
|
43
|
+
for (let i = 0; i < len - 1; i++) {
|
|
44
|
+
const key = keysArray[i];
|
|
45
|
+
if (!dataRef[key]) {
|
|
46
|
+
if (action === "set") {
|
|
47
|
+
const nextKey = keysArray[i + 1];
|
|
48
|
+
if (nextKey && !isNaN(parseInt(nextKey))) {
|
|
49
|
+
dataRef[key] = [];
|
|
50
|
+
} else {
|
|
51
|
+
dataRef[key] = {};
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
valIsUndefined = true;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
dataRef = dataRef[key];
|
|
59
|
+
}
|
|
60
|
+
if (valIsUndefined) return void 0;
|
|
61
|
+
if (action === "set") {
|
|
62
|
+
dataRef[keysArray[len - 1]] = value;
|
|
63
|
+
return data;
|
|
64
|
+
} else if (action === "delete") {
|
|
65
|
+
if (Array.isArray(dataRef)) {
|
|
66
|
+
dataRef.splice(parseInt(keysArray[len - 1]), 1);
|
|
67
|
+
} else {
|
|
68
|
+
delete dataRef[keysArray[len - 1]];
|
|
69
|
+
}
|
|
70
|
+
return data;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// src/utils/getterSetterDeleter/deleteVal.ts
|
|
75
|
+
var deleteVal = (data, valuePath) => {
|
|
76
|
+
return set_deleteVal("delete", data, valuePath);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// src/utils/getterSetterDeleter/setVal.ts
|
|
80
|
+
var setVal = (data, valuePath, value) => {
|
|
81
|
+
return set_deleteVal("set", data, valuePath, value);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// src/utils/getterSetterDeleter/utils/flattenArrayOfArrays.ts
|
|
85
|
+
var flattenArrayOfArrays = ({
|
|
86
|
+
array,
|
|
87
|
+
flattenLastArray = true,
|
|
88
|
+
toReturn = []
|
|
89
|
+
}) => {
|
|
90
|
+
array.map((ary) => {
|
|
91
|
+
if (Array.isArray(ary)) {
|
|
92
|
+
if (flattenLastArray === true) {
|
|
93
|
+
if (ary.some((childAry) => !Array.isArray(childAry))) {
|
|
94
|
+
toReturn.push(ary);
|
|
95
|
+
} else {
|
|
96
|
+
flattenArrayOfArrays({ array: ary, flattenLastArray, toReturn });
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
flattenArrayOfArrays({ array: ary, flattenLastArray, toReturn });
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
toReturn.push(ary);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
return toReturn;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// src/utils/getterSetterDeleter/getVal.ts
|
|
109
|
+
var getVal = (data, valuePath, options = {}, depthIdx = 0) => {
|
|
110
|
+
let value = null;
|
|
111
|
+
const getFinalVal = (data2, valuePath2, options2, depthIdx2) => {
|
|
112
|
+
return Array.isArray(data2) ? data2.map((R) => getValV2_getter(R, valuePath2, options2, depthIdx2)) : getValV2_getter(data2, valuePath2, options2, depthIdx2);
|
|
113
|
+
};
|
|
114
|
+
if (Array.isArray(valuePath)) {
|
|
115
|
+
for (let i = 0; i < valuePath.length; i++) {
|
|
116
|
+
value = getFinalVal(data, valuePath[i], options, depthIdx);
|
|
117
|
+
if (value) break;
|
|
118
|
+
}
|
|
119
|
+
} else {
|
|
120
|
+
value = getFinalVal(data, valuePath, options, depthIdx);
|
|
121
|
+
}
|
|
122
|
+
return value;
|
|
123
|
+
};
|
|
124
|
+
var getValV2_getter = (data, valuePath, options, depthIdx) => {
|
|
125
|
+
const { flattenIfValueIsArray = true } = options;
|
|
126
|
+
if (valuePath === null) return data;
|
|
127
|
+
let dataRef = data;
|
|
128
|
+
const keysArray = valuePath.split(".");
|
|
129
|
+
const len = keysArray.length;
|
|
130
|
+
let valIsUndefined = false;
|
|
131
|
+
let thisIterationFoundAry = false;
|
|
132
|
+
for (let i = 0; i < len - 1; i++) {
|
|
133
|
+
const key = keysArray[i];
|
|
134
|
+
if (!thisIterationFoundAry) {
|
|
135
|
+
if (!dataRef[key]) {
|
|
136
|
+
valIsUndefined = true;
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
dataRef = dataRef[key];
|
|
140
|
+
} else {
|
|
141
|
+
const nestedAryResponse = dataRef.map((dataRefItem) => {
|
|
142
|
+
const remainingValuePath = keysArray.filter((dd, ii) => ii >= i).join(".");
|
|
143
|
+
return getVal(dataRefItem, remainingValuePath, options, depthIdx + 1);
|
|
144
|
+
});
|
|
145
|
+
return flattenArrayOfArrays({
|
|
146
|
+
array: nestedAryResponse,
|
|
147
|
+
flattenLastArray: depthIdx === 0 && flattenIfValueIsArray === false ? false : true
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
if (Array.isArray(dataRef) && Number.isNaN(parseInt(keysArray[i + 1]))) thisIterationFoundAry = true;
|
|
151
|
+
}
|
|
152
|
+
if (valIsUndefined) return void 0;
|
|
153
|
+
if (thisIterationFoundAry) {
|
|
154
|
+
const toReturn = dataRef.map((d) => d[keysArray[len - 1]]);
|
|
155
|
+
return flattenArrayOfArrays({
|
|
156
|
+
array: toReturn,
|
|
157
|
+
flattenLastArray: flattenIfValueIsArray
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
return dataRef[keysArray[len - 1]];
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// src/utils/genTagId.ts
|
|
164
|
+
var convertFromRichText = (value) => {
|
|
165
|
+
if (!value) return "";
|
|
166
|
+
let val = "";
|
|
167
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
168
|
+
return String(value);
|
|
169
|
+
}
|
|
170
|
+
if (typeof value === "object" && "blocks" in value && Array.isArray(value.blocks)) {
|
|
171
|
+
for (let i = 0; i < value.blocks.length; i++) {
|
|
172
|
+
const block = value.blocks[i];
|
|
173
|
+
if (block && block.text && block.text.length > 0) {
|
|
174
|
+
val = val + block.text;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return val;
|
|
179
|
+
};
|
|
180
|
+
var genTagId = (tagName) => {
|
|
181
|
+
let toReturn = convertFromRichText(tagName);
|
|
182
|
+
const regex = /[^\p{L}\p{N}\+]+/gui;
|
|
183
|
+
toReturn = toReturn.trim().toLowerCase().replace(regex, "_");
|
|
184
|
+
toReturn = toReturn.replace(/\+/g, "plus");
|
|
185
|
+
return toReturn.replace(/^_+|_+$/, "");
|
|
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
|
+
};
|
|
306
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
307
|
+
0 && (module.exports = {
|
|
308
|
+
deleteVal,
|
|
309
|
+
extractAllBlocksFromTpl,
|
|
310
|
+
genTagId,
|
|
311
|
+
getVal,
|
|
312
|
+
setVal,
|
|
313
|
+
toArray
|
|
314
|
+
});
|