@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/universal.js CHANGED
@@ -21,9 +21,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var universal_exports = {};
22
22
  __export(universal_exports, {
23
23
  deleteVal: () => deleteVal,
24
+ extractAllBlocksFromTpl: () => extractAllBlocksFromTpl,
24
25
  genTagId: () => genTagId,
25
26
  getVal: () => getVal,
26
- setVal: () => setVal
27
+ recursivelyExtractBlocks: () => _recursExtractBlocks,
28
+ setVal: () => setVal,
29
+ toArray: () => toArray
27
30
  });
28
31
  module.exports = __toCommonJS(universal_exports);
29
32
 
@@ -182,10 +185,132 @@ var genTagId = (tagName) => {
182
185
  toReturn = toReturn.replace(/\+/g, "plus");
183
186
  return toReturn.replace(/^_+|_+$/, "");
184
187
  };
188
+
189
+ // src/utils/toArray.ts
190
+ var toArray = (property) => {
191
+ if (!property && (property !== false && property !== 0)) return [];
192
+ if (Array.isArray(property)) return property;
193
+ return [property];
194
+ };
195
+
196
+ // src/utils/extractAllBlocksFromTpl.ts
197
+ var extractAllBlocksFromTpl = ({
198
+ tpl,
199
+ buildersWhitelist
200
+ }) => {
201
+ if (tpl.category === "userProfiles") {
202
+ const allBlocksAry = [];
203
+ if (tpl.kp_templates?.myProfileConfig) {
204
+ _recursExtractBlocks({
205
+ data: tpl.kp_templates.myProfileConfig,
206
+ cb: (block) => allBlocksAry.push(block),
207
+ sectionStack: [],
208
+ blockPathPrefix: "kp_templates.myProfileConfig"
209
+ });
210
+ }
211
+ return allBlocksAry;
212
+ } else {
213
+ return extractAllBlocksFromStructuredTpls({ tpl, buildersWhitelist });
214
+ }
215
+ };
216
+ var _recursExtractBlocks = ({
217
+ data,
218
+ cb,
219
+ sectionStack = [],
220
+ blockPathPrefix = ""
221
+ }) => {
222
+ data.forEach((d, idx) => {
223
+ if (!d.blocks) {
224
+ cb({
225
+ ...d,
226
+ sectionStack,
227
+ blockPath: `${blockPathPrefix}.${idx}`
228
+ });
229
+ } else {
230
+ _recursExtractBlocks({
231
+ data: d.blocks,
232
+ cb,
233
+ sectionStack: [...sectionStack, d],
234
+ blockPathPrefix: `${blockPathPrefix}.${idx}.blocks`
235
+ });
236
+ }
237
+ });
238
+ };
239
+ var extractAllBlocksFromStructuredTpls = ({
240
+ tpl,
241
+ buildersWhitelist
242
+ }) => {
243
+ const allBlocksAry = [];
244
+ if (tpl.kp_templates) {
245
+ for (let spaceId in tpl.kp_templates) {
246
+ let conf = tpl.kp_templates[spaceId];
247
+ if (conf.builder && buildersWhitelist && !buildersWhitelist.includes(conf.builder)) {
248
+ continue;
249
+ }
250
+ if (!conf.subSpaces) {
251
+ _extractBlocksFromSomeBuilders({
252
+ conf,
253
+ confPath: `kp_templates.${spaceId}`,
254
+ allBlocksAry
255
+ });
256
+ } else {
257
+ conf.subSpaces.forEach((sub, subIdx) => {
258
+ if (sub.builder && buildersWhitelist && !buildersWhitelist.includes(sub.builder)) {
259
+ return;
260
+ }
261
+ _extractBlocksFromSomeBuilders({
262
+ conf: sub,
263
+ confPath: `kp_templates.${spaceId}.subSpaces.${subIdx}`,
264
+ allBlocksAry
265
+ });
266
+ });
267
+ }
268
+ }
269
+ }
270
+ if (buildersWhitelist && !buildersWhitelist.includes("kp_settings")) {
271
+ return allBlocksAry;
272
+ }
273
+ if (tpl.kp_settings && tpl.kp_settings.length > 0) {
274
+ _recursExtractBlocks({
275
+ data: tpl.kp_settings,
276
+ cb: (block) => allBlocksAry.push(block),
277
+ blockPathPrefix: "kp_settings"
278
+ });
279
+ }
280
+ return allBlocksAry;
281
+ };
282
+ var _extractBlocksFromSomeBuilders = ({
283
+ conf,
284
+ confPath,
285
+ allBlocksAry
286
+ }) => {
287
+ if (conf.builder === "FormBuilder") {
288
+ const configs = conf.configs || [];
289
+ _recursExtractBlocks({
290
+ data: configs,
291
+ cb: (block) => allBlocksAry.push(block),
292
+ blockPathPrefix: `${confPath}.configs`
293
+ });
294
+ }
295
+ if (conf.builder === "MetaBuilder") {
296
+ const inputs = conf.configs?.inputs || {};
297
+ const inputBlockConfigsToPush = Object.keys(inputs).map((inputBlockKey) => {
298
+ const value = inputs[inputBlockKey];
299
+ return {
300
+ ...value,
301
+ blockPath: `${confPath}.configs.inputs.${inputBlockKey}`
302
+ };
303
+ });
304
+ allBlocksAry.push(...inputBlockConfigsToPush);
305
+ }
306
+ };
185
307
  // Annotate the CommonJS export names for ESM import in node:
186
308
  0 && (module.exports = {
187
309
  deleteVal,
310
+ extractAllBlocksFromTpl,
188
311
  genTagId,
189
312
  getVal,
190
- setVal
313
+ recursivelyExtractBlocks,
314
+ setVal,
315
+ toArray
191
316
  });
@@ -153,9 +153,131 @@ var genTagId = (tagName) => {
153
153
  toReturn = toReturn.replace(/\+/g, "plus");
154
154
  return toReturn.replace(/^_+|_+$/, "");
155
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
+ };
156
275
  export {
157
276
  deleteVal,
277
+ extractAllBlocksFromTpl,
158
278
  genTagId,
159
279
  getVal,
160
- setVal
280
+ _recursExtractBlocks as recursivelyExtractBlocks,
281
+ setVal,
282
+ toArray
161
283
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.3.4",
6
+ "version": "1.3.6",
7
7
  "description": "Utility functions for both browser and Node.js",
8
8
  "main": "dist/index.js",
9
9
  "module": "dist/index.mjs",