@okf/ootils 1.3.4 → 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.
@@ -153,9 +153,130 @@ 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
+ setVal,
281
+ toArray
161
282
  };
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.5",
7
7
  "description": "Utility functions for both browser and Node.js",
8
8
  "main": "dist/index.js",
9
9
  "module": "dist/index.mjs",