@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,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/universal.ts
|
|
21
|
+
var universal_exports = {};
|
|
22
|
+
__export(universal_exports, {
|
|
23
|
+
deleteVal: () => deleteVal,
|
|
24
|
+
extractAllBlocksFromTpl: () => extractAllBlocksFromTpl,
|
|
25
|
+
genTagId: () => genTagId,
|
|
26
|
+
getVal: () => getVal,
|
|
27
|
+
setVal: () => setVal,
|
|
28
|
+
toArray: () => toArray
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(universal_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
|
+
});
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
// src/utils/getterSetterDeleter/utils/set_deleteVal.ts
|
|
2
|
+
var set_deleteVal = (action, data, valuePath, value) => {
|
|
3
|
+
if (valuePath === void 0) return;
|
|
4
|
+
if (valuePath === null && action === "set") {
|
|
5
|
+
data = value;
|
|
6
|
+
return data;
|
|
7
|
+
}
|
|
8
|
+
let dataRef = data;
|
|
9
|
+
const keysArray = valuePath.split(".");
|
|
10
|
+
const len = keysArray.length;
|
|
11
|
+
let valIsUndefined = false;
|
|
12
|
+
for (let i = 0; i < len - 1; i++) {
|
|
13
|
+
const key = keysArray[i];
|
|
14
|
+
if (!dataRef[key]) {
|
|
15
|
+
if (action === "set") {
|
|
16
|
+
const nextKey = keysArray[i + 1];
|
|
17
|
+
if (nextKey && !isNaN(parseInt(nextKey))) {
|
|
18
|
+
dataRef[key] = [];
|
|
19
|
+
} else {
|
|
20
|
+
dataRef[key] = {};
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
valIsUndefined = true;
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
dataRef = dataRef[key];
|
|
28
|
+
}
|
|
29
|
+
if (valIsUndefined) return void 0;
|
|
30
|
+
if (action === "set") {
|
|
31
|
+
dataRef[keysArray[len - 1]] = value;
|
|
32
|
+
return data;
|
|
33
|
+
} else if (action === "delete") {
|
|
34
|
+
if (Array.isArray(dataRef)) {
|
|
35
|
+
dataRef.splice(parseInt(keysArray[len - 1]), 1);
|
|
36
|
+
} else {
|
|
37
|
+
delete dataRef[keysArray[len - 1]];
|
|
38
|
+
}
|
|
39
|
+
return data;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// src/utils/getterSetterDeleter/deleteVal.ts
|
|
44
|
+
var deleteVal = (data, valuePath) => {
|
|
45
|
+
return set_deleteVal("delete", data, valuePath);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/utils/getterSetterDeleter/setVal.ts
|
|
49
|
+
var setVal = (data, valuePath, value) => {
|
|
50
|
+
return set_deleteVal("set", data, valuePath, value);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// src/utils/getterSetterDeleter/utils/flattenArrayOfArrays.ts
|
|
54
|
+
var flattenArrayOfArrays = ({
|
|
55
|
+
array,
|
|
56
|
+
flattenLastArray = true,
|
|
57
|
+
toReturn = []
|
|
58
|
+
}) => {
|
|
59
|
+
array.map((ary) => {
|
|
60
|
+
if (Array.isArray(ary)) {
|
|
61
|
+
if (flattenLastArray === true) {
|
|
62
|
+
if (ary.some((childAry) => !Array.isArray(childAry))) {
|
|
63
|
+
toReturn.push(ary);
|
|
64
|
+
} else {
|
|
65
|
+
flattenArrayOfArrays({ array: ary, flattenLastArray, toReturn });
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
flattenArrayOfArrays({ array: ary, flattenLastArray, toReturn });
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
toReturn.push(ary);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return toReturn;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// src/utils/getterSetterDeleter/getVal.ts
|
|
78
|
+
var getVal = (data, valuePath, options = {}, depthIdx = 0) => {
|
|
79
|
+
let value = null;
|
|
80
|
+
const getFinalVal = (data2, valuePath2, options2, depthIdx2) => {
|
|
81
|
+
return Array.isArray(data2) ? data2.map((R) => getValV2_getter(R, valuePath2, options2, depthIdx2)) : getValV2_getter(data2, valuePath2, options2, depthIdx2);
|
|
82
|
+
};
|
|
83
|
+
if (Array.isArray(valuePath)) {
|
|
84
|
+
for (let i = 0; i < valuePath.length; i++) {
|
|
85
|
+
value = getFinalVal(data, valuePath[i], options, depthIdx);
|
|
86
|
+
if (value) break;
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
value = getFinalVal(data, valuePath, options, depthIdx);
|
|
90
|
+
}
|
|
91
|
+
return value;
|
|
92
|
+
};
|
|
93
|
+
var getValV2_getter = (data, valuePath, options, depthIdx) => {
|
|
94
|
+
const { flattenIfValueIsArray = true } = options;
|
|
95
|
+
if (valuePath === null) return data;
|
|
96
|
+
let dataRef = data;
|
|
97
|
+
const keysArray = valuePath.split(".");
|
|
98
|
+
const len = keysArray.length;
|
|
99
|
+
let valIsUndefined = false;
|
|
100
|
+
let thisIterationFoundAry = false;
|
|
101
|
+
for (let i = 0; i < len - 1; i++) {
|
|
102
|
+
const key = keysArray[i];
|
|
103
|
+
if (!thisIterationFoundAry) {
|
|
104
|
+
if (!dataRef[key]) {
|
|
105
|
+
valIsUndefined = true;
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
dataRef = dataRef[key];
|
|
109
|
+
} else {
|
|
110
|
+
const nestedAryResponse = dataRef.map((dataRefItem) => {
|
|
111
|
+
const remainingValuePath = keysArray.filter((dd, ii) => ii >= i).join(".");
|
|
112
|
+
return getVal(dataRefItem, remainingValuePath, options, depthIdx + 1);
|
|
113
|
+
});
|
|
114
|
+
return flattenArrayOfArrays({
|
|
115
|
+
array: nestedAryResponse,
|
|
116
|
+
flattenLastArray: depthIdx === 0 && flattenIfValueIsArray === false ? false : true
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
if (Array.isArray(dataRef) && Number.isNaN(parseInt(keysArray[i + 1]))) thisIterationFoundAry = true;
|
|
120
|
+
}
|
|
121
|
+
if (valIsUndefined) return void 0;
|
|
122
|
+
if (thisIterationFoundAry) {
|
|
123
|
+
const toReturn = dataRef.map((d) => d[keysArray[len - 1]]);
|
|
124
|
+
return flattenArrayOfArrays({
|
|
125
|
+
array: toReturn,
|
|
126
|
+
flattenLastArray: flattenIfValueIsArray
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return dataRef[keysArray[len - 1]];
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// src/utils/genTagId.ts
|
|
133
|
+
var convertFromRichText = (value) => {
|
|
134
|
+
if (!value) return "";
|
|
135
|
+
let val = "";
|
|
136
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
137
|
+
return String(value);
|
|
138
|
+
}
|
|
139
|
+
if (typeof value === "object" && "blocks" in value && Array.isArray(value.blocks)) {
|
|
140
|
+
for (let i = 0; i < value.blocks.length; i++) {
|
|
141
|
+
const block = value.blocks[i];
|
|
142
|
+
if (block && block.text && block.text.length > 0) {
|
|
143
|
+
val = val + block.text;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return val;
|
|
148
|
+
};
|
|
149
|
+
var genTagId = (tagName) => {
|
|
150
|
+
let toReturn = convertFromRichText(tagName);
|
|
151
|
+
const regex = /[^\p{L}\p{N}\+]+/gui;
|
|
152
|
+
toReturn = toReturn.trim().toLowerCase().replace(regex, "_");
|
|
153
|
+
toReturn = toReturn.replace(/\+/g, "plus");
|
|
154
|
+
return toReturn.replace(/^_+|_+$/, "");
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// src/utils/toArray.ts
|
|
158
|
+
var toArray = (property) => {
|
|
159
|
+
if (!property && (property !== false && property !== 0)) return [];
|
|
160
|
+
if (Array.isArray(property)) return property;
|
|
161
|
+
return [property];
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// src/utils/extractAllBlocksFromTpl.ts
|
|
165
|
+
var extractAllBlocksFromTpl = ({
|
|
166
|
+
tpl,
|
|
167
|
+
buildersWhitelist
|
|
168
|
+
}) => {
|
|
169
|
+
if (tpl.category === "userProfiles") {
|
|
170
|
+
const allBlocksAry = [];
|
|
171
|
+
if (tpl.kp_templates?.myProfileConfig) {
|
|
172
|
+
_recursExtractBlocks({
|
|
173
|
+
data: tpl.kp_templates.myProfileConfig,
|
|
174
|
+
cb: (block) => allBlocksAry.push(block),
|
|
175
|
+
sectionStack: [],
|
|
176
|
+
blockPathPrefix: "kp_templates.myProfileConfig"
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
return allBlocksAry;
|
|
180
|
+
} else {
|
|
181
|
+
return extractAllBlocksFromStructuredTpls({ tpl, buildersWhitelist });
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
var _recursExtractBlocks = ({
|
|
185
|
+
data,
|
|
186
|
+
cb,
|
|
187
|
+
sectionStack = [],
|
|
188
|
+
blockPathPrefix = ""
|
|
189
|
+
}) => {
|
|
190
|
+
data.forEach((d, idx) => {
|
|
191
|
+
if (!d.blocks) {
|
|
192
|
+
cb({
|
|
193
|
+
...d,
|
|
194
|
+
sectionStack,
|
|
195
|
+
blockPath: `${blockPathPrefix}.${idx}`
|
|
196
|
+
});
|
|
197
|
+
} else {
|
|
198
|
+
_recursExtractBlocks({
|
|
199
|
+
data: d.blocks,
|
|
200
|
+
cb,
|
|
201
|
+
sectionStack: [...sectionStack, d],
|
|
202
|
+
blockPathPrefix: `${blockPathPrefix}.${idx}.blocks`
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
var extractAllBlocksFromStructuredTpls = ({
|
|
208
|
+
tpl,
|
|
209
|
+
buildersWhitelist
|
|
210
|
+
}) => {
|
|
211
|
+
const allBlocksAry = [];
|
|
212
|
+
if (tpl.kp_templates) {
|
|
213
|
+
for (let spaceId in tpl.kp_templates) {
|
|
214
|
+
let conf = tpl.kp_templates[spaceId];
|
|
215
|
+
if (conf.builder && buildersWhitelist && !buildersWhitelist.includes(conf.builder)) {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (!conf.subSpaces) {
|
|
219
|
+
_extractBlocksFromSomeBuilders({
|
|
220
|
+
conf,
|
|
221
|
+
confPath: `kp_templates.${spaceId}`,
|
|
222
|
+
allBlocksAry
|
|
223
|
+
});
|
|
224
|
+
} else {
|
|
225
|
+
conf.subSpaces.forEach((sub, subIdx) => {
|
|
226
|
+
if (sub.builder && buildersWhitelist && !buildersWhitelist.includes(sub.builder)) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
_extractBlocksFromSomeBuilders({
|
|
230
|
+
conf: sub,
|
|
231
|
+
confPath: `kp_templates.${spaceId}.subSpaces.${subIdx}`,
|
|
232
|
+
allBlocksAry
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (buildersWhitelist && !buildersWhitelist.includes("kp_settings")) {
|
|
239
|
+
return allBlocksAry;
|
|
240
|
+
}
|
|
241
|
+
if (tpl.kp_settings && tpl.kp_settings.length > 0) {
|
|
242
|
+
_recursExtractBlocks({
|
|
243
|
+
data: tpl.kp_settings,
|
|
244
|
+
cb: (block) => allBlocksAry.push(block),
|
|
245
|
+
blockPathPrefix: "kp_settings"
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
return allBlocksAry;
|
|
249
|
+
};
|
|
250
|
+
var _extractBlocksFromSomeBuilders = ({
|
|
251
|
+
conf,
|
|
252
|
+
confPath,
|
|
253
|
+
allBlocksAry
|
|
254
|
+
}) => {
|
|
255
|
+
if (conf.builder === "FormBuilder") {
|
|
256
|
+
const configs = conf.configs || [];
|
|
257
|
+
_recursExtractBlocks({
|
|
258
|
+
data: configs,
|
|
259
|
+
cb: (block) => allBlocksAry.push(block),
|
|
260
|
+
blockPathPrefix: `${confPath}.configs`
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
if (conf.builder === "MetaBuilder") {
|
|
264
|
+
const inputs = conf.configs?.inputs || {};
|
|
265
|
+
const inputBlockConfigsToPush = Object.keys(inputs).map((inputBlockKey) => {
|
|
266
|
+
const value = inputs[inputBlockKey];
|
|
267
|
+
return {
|
|
268
|
+
...value,
|
|
269
|
+
blockPath: `${confPath}.configs.inputs.${inputBlockKey}`
|
|
270
|
+
};
|
|
271
|
+
});
|
|
272
|
+
allBlocksAry.push(...inputBlockConfigsToPush);
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
export {
|
|
276
|
+
deleteVal,
|
|
277
|
+
extractAllBlocksFromTpl,
|
|
278
|
+
genTagId,
|
|
279
|
+
getVal,
|
|
280
|
+
setVal,
|
|
281
|
+
toArray
|
|
282
|
+
};
|
package/package.json
CHANGED
|
@@ -3,16 +3,43 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.3.
|
|
6
|
+
"version": "1.3.5",
|
|
7
7
|
"description": "Utility functions for both browser and Node.js",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"module": "dist/index.mjs",
|
|
10
10
|
"types": "dist/index.d.ts",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
"browser": {
|
|
14
|
+
"import": "./dist/browser.mjs",
|
|
15
|
+
"require": "./dist/browser.js",
|
|
16
|
+
"types": "./dist/browser.d.ts"
|
|
17
|
+
},
|
|
18
|
+
"node": {
|
|
19
|
+
"import": "./dist/node.mjs",
|
|
20
|
+
"require": "./dist/node.js",
|
|
21
|
+
"types": "./dist/node.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"default": {
|
|
24
|
+
"import": "./dist/universal.mjs",
|
|
25
|
+
"require": "./dist/universal.js",
|
|
26
|
+
"types": "./dist/universal.d.ts"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"./browser": {
|
|
30
|
+
"import": "./dist/browser.mjs",
|
|
31
|
+
"require": "./dist/browser.js",
|
|
32
|
+
"types": "./dist/browser.d.ts"
|
|
33
|
+
},
|
|
34
|
+
"./node": {
|
|
35
|
+
"import": "./dist/node.mjs",
|
|
36
|
+
"require": "./dist/node.js",
|
|
37
|
+
"types": "./dist/node.d.ts"
|
|
38
|
+
},
|
|
39
|
+
"./universal": {
|
|
40
|
+
"import": "./dist/universal.mjs",
|
|
41
|
+
"require": "./dist/universal.js",
|
|
42
|
+
"types": "./dist/universal.d.ts"
|
|
16
43
|
}
|
|
17
44
|
},
|
|
18
45
|
"files": [
|
|
@@ -24,7 +51,10 @@
|
|
|
24
51
|
}
|
|
25
52
|
},
|
|
26
53
|
"scripts": {
|
|
27
|
-
"build": "
|
|
54
|
+
"build": "npm run build:universal && npm run build:browser && npm run build:node",
|
|
55
|
+
"build:universal": "tsup src/universal.ts --format cjs,esm --dts --out-dir dist",
|
|
56
|
+
"build:browser": "tsup src/browser.ts --format cjs,esm --dts --out-dir dist",
|
|
57
|
+
"build:node": "tsup src/node.ts --format cjs,esm --dts --out-dir dist",
|
|
28
58
|
"prepublishOnly": "npm run build",
|
|
29
59
|
"semantic-release": "semantic-release"
|
|
30
60
|
},
|