@crediblemark/build 0.22.0

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.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/dist/Editor-XZF6CWVW.css +404 -0
  3. package/dist/Editor-ZC67OU2A.mjs +205 -0
  4. package/dist/Render-JBFI6HYN.mjs +55 -0
  5. package/dist/Render-WCX4AXOX.css +102 -0
  6. package/dist/actions-CEH_5LMY.d.mts +838 -0
  7. package/dist/actions-CEH_5LMY.d.ts +838 -0
  8. package/dist/chunk-3AJBFQU4.mjs +560 -0
  9. package/dist/chunk-4SQOX3ZQ.mjs +476 -0
  10. package/dist/chunk-B4BOBGYB.mjs +42 -0
  11. package/dist/chunk-CDMESQDA.mjs +148 -0
  12. package/dist/chunk-DSXRK4QJ.mjs +704 -0
  13. package/dist/chunk-GUJDGRSM.mjs +469 -0
  14. package/dist/chunk-HHBUU7WF.mjs +35 -0
  15. package/dist/chunk-IJHL7BIR.mjs +11 -0
  16. package/dist/chunk-PHGC6QYB.mjs +105 -0
  17. package/dist/chunk-QF3GD5WQ.mjs +65 -0
  18. package/dist/chunk-U2NVBXAC.mjs +2064 -0
  19. package/dist/chunk-VFD76OD5.mjs +55 -0
  20. package/dist/chunk-VGDMWS44.mjs +107 -0
  21. package/dist/chunk-VKBVSWU3.mjs +8538 -0
  22. package/dist/chunk-YH7AXYKP.mjs +109 -0
  23. package/dist/full-ABQQRJAO.css +301 -0
  24. package/dist/full-LJRK5736.mjs +94 -0
  25. package/dist/index-CkSfgrvw.d.ts +117 -0
  26. package/dist/index-Cxwg4vUV.d.mts +117 -0
  27. package/dist/index.css +2576 -0
  28. package/dist/index.d.mts +310 -0
  29. package/dist/index.d.ts +310 -0
  30. package/dist/index.js +15012 -0
  31. package/dist/index.mjs +83 -0
  32. package/dist/internal.d.mts +27 -0
  33. package/dist/internal.d.ts +27 -0
  34. package/dist/internal.js +960 -0
  35. package/dist/internal.mjs +13 -0
  36. package/dist/loaded-DWCENJKQ.mjs +55 -0
  37. package/dist/loaded-N7VXUR4O.mjs +59 -0
  38. package/dist/loaded-NE2PIHUQ.mjs +56 -0
  39. package/dist/loaded-SMEIWWHS.css +87 -0
  40. package/dist/no-external.css +2574 -0
  41. package/dist/no-external.d.mts +21 -0
  42. package/dist/no-external.d.ts +21 -0
  43. package/dist/no-external.js +15012 -0
  44. package/dist/no-external.mjs +83 -0
  45. package/dist/rsc.css +102 -0
  46. package/dist/rsc.d.mts +27 -0
  47. package/dist/rsc.d.ts +27 -0
  48. package/dist/rsc.js +1466 -0
  49. package/dist/rsc.mjs +147 -0
  50. package/dist/walk-tree-B4ZvMfxS.d.ts +29 -0
  51. package/dist/walk-tree-C78ZVz19.d.mts +29 -0
  52. package/package.json +145 -0
package/dist/rsc.js ADDED
@@ -0,0 +1,1466 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
11
+ var __commonJS = (cb, mod) => function __require() {
12
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13
+ };
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27
+ // If the importer is in node compatibility mode or this is not an ESM
28
+ // file that has been converted to a CommonJS file using a Babel-
29
+ // compatible transform (i.e. "__esModule" has not been set), then set
30
+ // "default" to the CommonJS "module.exports" for node compatibility.
31
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
32
+ mod
33
+ ));
34
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
+
36
+ // react-import.js
37
+ var import_react;
38
+ var init_react_import = __esm({
39
+ "react-import.js"() {
40
+ "use strict";
41
+ import_react = __toESM(require("react"));
42
+ }
43
+ });
44
+
45
+ // ../node_modules/classnames/index.js
46
+ var require_classnames = __commonJS({
47
+ "../node_modules/classnames/index.js"(exports2, module2) {
48
+ "use strict";
49
+ init_react_import();
50
+ (function() {
51
+ "use strict";
52
+ var hasOwn = {}.hasOwnProperty;
53
+ function classNames() {
54
+ var classes = "";
55
+ for (var i = 0; i < arguments.length; i++) {
56
+ var arg = arguments[i];
57
+ if (arg) {
58
+ classes = appendClass(classes, parseValue(arg));
59
+ }
60
+ }
61
+ return classes;
62
+ }
63
+ function parseValue(arg) {
64
+ if (typeof arg === "string" || typeof arg === "number") {
65
+ return arg;
66
+ }
67
+ if (typeof arg !== "object") {
68
+ return "";
69
+ }
70
+ if (Array.isArray(arg)) {
71
+ return classNames.apply(null, arg);
72
+ }
73
+ if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
74
+ return arg.toString();
75
+ }
76
+ var classes = "";
77
+ for (var key in arg) {
78
+ if (hasOwn.call(arg, key) && arg[key]) {
79
+ classes = appendClass(classes, key);
80
+ }
81
+ }
82
+ return classes;
83
+ }
84
+ function appendClass(value, newClass) {
85
+ if (!newClass) {
86
+ return value;
87
+ }
88
+ if (value) {
89
+ return value + " " + newClass;
90
+ }
91
+ return value + newClass;
92
+ }
93
+ if (typeof module2 !== "undefined" && module2.exports) {
94
+ classNames.default = classNames;
95
+ module2.exports = classNames;
96
+ } else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
97
+ define("classnames", [], function() {
98
+ return classNames;
99
+ });
100
+ } else {
101
+ window.classNames = classNames;
102
+ }
103
+ })();
104
+ }
105
+ });
106
+
107
+ // lib/get-class-name-factory.ts
108
+ var import_classnames, getClassNameFactory, get_class_name_factory_default;
109
+ var init_get_class_name_factory = __esm({
110
+ "lib/get-class-name-factory.ts"() {
111
+ "use strict";
112
+ init_react_import();
113
+ import_classnames = __toESM(require_classnames());
114
+ getClassNameFactory = (rootClass, styles, config = { baseClass: "" }) => (options = {}) => {
115
+ if (typeof options === "string") {
116
+ const descendant = options;
117
+ const style = styles[`${rootClass}-${descendant}`];
118
+ if (style) {
119
+ return config.baseClass + styles[`${rootClass}-${descendant}`] || "";
120
+ }
121
+ return "";
122
+ } else if (typeof options === "object") {
123
+ const modifiers = options;
124
+ const prefixedModifiers = {};
125
+ for (let modifier in modifiers) {
126
+ prefixedModifiers[styles[`${rootClass}--${modifier}`]] = modifiers[modifier];
127
+ }
128
+ const c = styles[rootClass];
129
+ return config.baseClass + (0, import_classnames.default)({
130
+ [c]: !!c,
131
+ // only apply the class if it exists
132
+ ...prefixedModifiers
133
+ });
134
+ } else {
135
+ return config.baseClass + styles[rootClass] || "";
136
+ }
137
+ };
138
+ get_class_name_factory_default = getClassNameFactory;
139
+ }
140
+ });
141
+
142
+ // css-module:/home/crediblemark/Project/NEXT_CMS/packages/components/RichTextEditor/styles.module.css/#css-module-data
143
+ var init_css_module_data = __esm({
144
+ "css-module:/home/crediblemark/Project/NEXT_CMS/packages/components/RichTextEditor/styles.module.css/#css-module-data"() {
145
+ }
146
+ });
147
+
148
+ // css-module:/home/crediblemark/Project/NEXT_CMS/packages/components/RichTextEditor/styles.module.css#css-module
149
+ var styles_module_default;
150
+ var init_styles_module = __esm({
151
+ "css-module:/home/crediblemark/Project/NEXT_CMS/packages/components/RichTextEditor/styles.module.css#css-module"() {
152
+ "use strict";
153
+ init_react_import();
154
+ init_css_module_data();
155
+ styles_module_default = { "RichTextEditor": "_RichTextEditor_hp4qf_1", "RichTextEditor--editor": "_RichTextEditor--editor_hp4qf_50", "RichTextEditor--disabled": "_RichTextEditor--disabled_hp4qf_107", "RichTextEditor--isActive": "_RichTextEditor--isActive_hp4qf_111", "RichTextEditor-menu": "_RichTextEditor-menu_hp4qf_117" };
156
+ }
157
+ });
158
+
159
+ // components/RichTextEditor/extension.ts
160
+ var import_core, import_extension_blockquote, import_extension_bold, import_extension_code, import_extension_code_block, import_extension_document, import_extension_hard_break, import_extension_heading, import_extension_horizontal_rule, import_extension_italic, import_extension_link, import_extension_list, import_extension_paragraph, import_extension_strike, import_extension_text, import_extension_text_align, import_extension_underline, defaultCredBuildRichTextOptions, CredBuildRichText;
161
+ var init_extension = __esm({
162
+ "components/RichTextEditor/extension.ts"() {
163
+ "use strict";
164
+ init_react_import();
165
+ import_core = require("@tiptap/core");
166
+ import_extension_blockquote = require("@tiptap/extension-blockquote");
167
+ import_extension_bold = require("@tiptap/extension-bold");
168
+ import_extension_code = require("@tiptap/extension-code");
169
+ import_extension_code_block = require("@tiptap/extension-code-block");
170
+ import_extension_document = require("@tiptap/extension-document");
171
+ import_extension_hard_break = require("@tiptap/extension-hard-break");
172
+ import_extension_heading = require("@tiptap/extension-heading");
173
+ import_extension_horizontal_rule = require("@tiptap/extension-horizontal-rule");
174
+ import_extension_italic = require("@tiptap/extension-italic");
175
+ import_extension_link = require("@tiptap/extension-link");
176
+ import_extension_list = require("@tiptap/extension-list");
177
+ import_extension_paragraph = require("@tiptap/extension-paragraph");
178
+ import_extension_strike = require("@tiptap/extension-strike");
179
+ import_extension_text = require("@tiptap/extension-text");
180
+ import_extension_text_align = __toESM(require("@tiptap/extension-text-align"));
181
+ import_extension_underline = require("@tiptap/extension-underline");
182
+ defaultCredBuildRichTextOptions = {
183
+ textAlign: {
184
+ types: ["heading", "paragraph"]
185
+ }
186
+ };
187
+ CredBuildRichText = import_core.Extension.create({
188
+ name: "credbuildRichText",
189
+ addExtensions() {
190
+ const extensions = [];
191
+ const options = {
192
+ ...this.options,
193
+ ...defaultCredBuildRichTextOptions
194
+ };
195
+ if (options.bold !== false) {
196
+ extensions.push(import_extension_bold.Bold.configure(options.bold));
197
+ }
198
+ if (options.blockquote !== false) {
199
+ extensions.push(import_extension_blockquote.Blockquote.configure(options.blockquote));
200
+ }
201
+ if (options.code !== false) {
202
+ extensions.push(import_extension_code.Code.configure(options.code));
203
+ }
204
+ if (options.codeBlock !== false) {
205
+ extensions.push(import_extension_code_block.CodeBlock.configure(options.codeBlock));
206
+ }
207
+ if (options.document !== false) {
208
+ extensions.push(import_extension_document.Document.configure(options.document));
209
+ }
210
+ if (options.hardBreak !== false) {
211
+ extensions.push(import_extension_hard_break.HardBreak.configure(options.hardBreak));
212
+ }
213
+ if (options.heading !== false) {
214
+ extensions.push(import_extension_heading.Heading.configure(options.heading));
215
+ }
216
+ if (options.horizontalRule !== false) {
217
+ extensions.push(import_extension_horizontal_rule.HorizontalRule.configure(options.horizontalRule));
218
+ }
219
+ if (options.italic !== false) {
220
+ extensions.push(import_extension_italic.Italic.configure(options.italic));
221
+ }
222
+ if (options.listItem !== false) {
223
+ extensions.push(import_extension_list.ListItem.configure(options.listItem));
224
+ if (options.bulletList !== false) {
225
+ extensions.push(import_extension_list.BulletList.configure(options.bulletList));
226
+ }
227
+ if (options.orderedList !== false) {
228
+ extensions.push(import_extension_list.OrderedList.configure(options.orderedList));
229
+ }
230
+ }
231
+ if (options.listKeymap !== false) {
232
+ extensions.push(import_extension_list.ListKeymap.configure(options?.listKeymap));
233
+ }
234
+ if (options.link !== false) {
235
+ extensions.push(import_extension_link.Link.configure(options?.link));
236
+ }
237
+ if (options.paragraph !== false) {
238
+ extensions.push(import_extension_paragraph.Paragraph.configure(options.paragraph));
239
+ }
240
+ if (options.strike !== false) {
241
+ extensions.push(import_extension_strike.Strike.configure(options.strike));
242
+ }
243
+ if (options.text !== false) {
244
+ extensions.push(import_extension_text.Text.configure(options.text));
245
+ }
246
+ if (options.textAlign !== false) {
247
+ extensions.push(import_extension_text_align.default.configure(options.textAlign));
248
+ }
249
+ if (options.underline !== false) {
250
+ extensions.push(import_extension_underline.Underline.configure(options?.underline));
251
+ }
252
+ return extensions;
253
+ }
254
+ });
255
+ }
256
+ });
257
+
258
+ // components/RichTextEditor/components/Render.tsx
259
+ var Render_exports = {};
260
+ __export(Render_exports, {
261
+ RichTextRender: () => RichTextRender
262
+ });
263
+ function RichTextRender({
264
+ content,
265
+ field
266
+ }) {
267
+ const { tiptap = {}, options } = field;
268
+ const { extensions = [] } = tiptap;
269
+ const loadedExtensions = (0, import_react3.useMemo)(
270
+ () => [CredBuildRichText.configure(options), ...extensions],
271
+ [extensions, options]
272
+ );
273
+ const normalized = (0, import_react3.useMemo)(() => {
274
+ if (typeof content === "object" && content?.type === "doc") {
275
+ return content;
276
+ }
277
+ if (typeof content === "string") {
278
+ const isHtml = /<\/?[a-z][\s\S]*>/i.test(content);
279
+ if (isHtml) {
280
+ return (0, import_html.generateJSON)(content, loadedExtensions);
281
+ }
282
+ return {
283
+ type: "doc",
284
+ content: [
285
+ { type: "paragraph", content: [{ type: "text", text: content }] }
286
+ ]
287
+ };
288
+ }
289
+ return { type: "doc", content: [] };
290
+ }, [content, loadedExtensions]);
291
+ const html = (0, import_react3.useMemo)(() => {
292
+ return (0, import_html.generateHTML)(normalized, loadedExtensions);
293
+ }, [normalized, loadedExtensions]);
294
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: getClassName2(), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "rich-text", dangerouslySetInnerHTML: { __html: html } }) });
295
+ }
296
+ var import_html, import_react3, import_jsx_runtime2, getClassName2;
297
+ var init_Render = __esm({
298
+ "components/RichTextEditor/components/Render.tsx"() {
299
+ "use strict";
300
+ init_react_import();
301
+ import_html = require("@tiptap/html");
302
+ import_react3 = require("react");
303
+ init_get_class_name_factory();
304
+ init_styles_module();
305
+ init_extension();
306
+ import_jsx_runtime2 = require("react/jsx-runtime");
307
+ getClassName2 = get_class_name_factory_default("RichTextEditor", styles_module_default);
308
+ }
309
+ });
310
+
311
+ // bundle/rsc.tsx
312
+ var rsc_exports = {};
313
+ __export(rsc_exports, {
314
+ Render: () => Render,
315
+ migrate: () => migrate,
316
+ resolveAllData: () => resolveAllData,
317
+ transformProps: () => transformProps,
318
+ walkTree: () => walkTree
319
+ });
320
+ module.exports = __toCommonJS(rsc_exports);
321
+ init_react_import();
322
+
323
+ // components/ServerRender/index.tsx
324
+ init_react_import();
325
+
326
+ // lib/root-droppable-id.ts
327
+ init_react_import();
328
+ var rootAreaId = "root";
329
+ var rootZone = "default-zone";
330
+ var rootDroppableId = `${rootAreaId}:${rootZone}`;
331
+
332
+ // lib/data/setup-zone.ts
333
+ init_react_import();
334
+ var setupZone = (data, zoneKey) => {
335
+ if (zoneKey === rootDroppableId) {
336
+ return data;
337
+ }
338
+ const newData = {
339
+ ...data,
340
+ zones: data.zones ? { ...data.zones } : {}
341
+ };
342
+ newData.zones[zoneKey] = newData.zones[zoneKey] || [];
343
+ return newData;
344
+ };
345
+
346
+ // lib/use-slots.tsx
347
+ init_react_import();
348
+
349
+ // lib/field-transforms/use-field-transforms.tsx
350
+ init_react_import();
351
+ var import_react2 = require("react");
352
+
353
+ // lib/data/map-fields.ts
354
+ init_react_import();
355
+
356
+ // lib/data/default-slots.ts
357
+ init_react_import();
358
+ var defaultSlots = (value, fields) => Object.keys(fields).reduce(
359
+ (acc, fieldName) => fields[fieldName].type === "slot" ? { [fieldName]: [], ...acc } : acc,
360
+ value
361
+ );
362
+
363
+ // lib/data/map-fields.ts
364
+ var isPromise = (v) => !!v && typeof v.then === "function";
365
+ var flatten = (values) => values.reduce((acc, item) => ({ ...acc, ...item }), {});
366
+ var containsPromise = (arr) => arr.some(isPromise);
367
+ var walkField = ({
368
+ value,
369
+ fields,
370
+ mappers,
371
+ propKey = "",
372
+ propPath = "",
373
+ id = "",
374
+ config,
375
+ recurseSlots = false
376
+ }) => {
377
+ const fieldType = fields[propKey]?.type;
378
+ const map = mappers[fieldType];
379
+ if (map && fieldType === "slot") {
380
+ const content = value || [];
381
+ const mappedContent = recurseSlots ? content.map((el) => {
382
+ const componentConfig = config.components[el.type];
383
+ if (!componentConfig) {
384
+ throw new Error(`Could not find component config for ${el.type}`);
385
+ }
386
+ const fields2 = componentConfig.fields ?? {};
387
+ return walkField({
388
+ value: { ...el, props: defaultSlots(el.props, fields2) },
389
+ fields: fields2,
390
+ mappers,
391
+ id: el.props.id,
392
+ config,
393
+ recurseSlots
394
+ });
395
+ }) : content;
396
+ if (containsPromise(mappedContent)) {
397
+ return Promise.all(mappedContent);
398
+ }
399
+ return map({
400
+ value: mappedContent,
401
+ parentId: id,
402
+ propName: propPath,
403
+ field: fields[propKey],
404
+ propPath
405
+ });
406
+ } else if (map && fields[propKey]) {
407
+ return map({
408
+ value,
409
+ parentId: id,
410
+ propName: propKey,
411
+ field: fields[propKey],
412
+ propPath
413
+ });
414
+ }
415
+ if (value && typeof value === "object") {
416
+ if (Array.isArray(value)) {
417
+ const arrayFields = fields[propKey]?.type === "array" ? fields[propKey].arrayFields : null;
418
+ if (!arrayFields) return value;
419
+ const newValue = value.map(
420
+ (el, idx) => walkField({
421
+ value: el,
422
+ fields: arrayFields,
423
+ mappers,
424
+ propKey,
425
+ propPath: `${propPath}[${idx}]`,
426
+ id,
427
+ config,
428
+ recurseSlots
429
+ })
430
+ );
431
+ if (containsPromise(newValue)) {
432
+ return Promise.all(newValue);
433
+ }
434
+ return newValue;
435
+ } else if ("$$typeof" in value) {
436
+ return value;
437
+ } else {
438
+ const objectFields = fields[propKey]?.type === "object" ? fields[propKey].objectFields : fields;
439
+ return walkObject({
440
+ value,
441
+ fields: objectFields,
442
+ mappers,
443
+ id,
444
+ getPropPath: (k) => `${propPath}.${k}`,
445
+ config,
446
+ recurseSlots
447
+ });
448
+ }
449
+ }
450
+ return value;
451
+ };
452
+ var walkObject = ({
453
+ value,
454
+ fields,
455
+ mappers,
456
+ id,
457
+ getPropPath,
458
+ config,
459
+ recurseSlots
460
+ }) => {
461
+ const newProps = Object.entries(value).map(([k, v]) => {
462
+ const opts = {
463
+ value: v,
464
+ fields,
465
+ mappers,
466
+ propKey: k,
467
+ propPath: getPropPath(k),
468
+ id,
469
+ config,
470
+ recurseSlots
471
+ };
472
+ const newValue = walkField(opts);
473
+ if (isPromise(newValue)) {
474
+ return newValue.then((resolvedValue) => ({
475
+ [k]: resolvedValue
476
+ }));
477
+ }
478
+ return {
479
+ [k]: newValue
480
+ };
481
+ }, {});
482
+ if (containsPromise(newProps)) {
483
+ return Promise.all(newProps).then(flatten);
484
+ }
485
+ return flatten(newProps);
486
+ };
487
+ function mapFields(item, mappers, config, recurseSlots = false, shouldDefaultSlots = true) {
488
+ const itemType = "type" in item ? item.type : "root";
489
+ const componentConfig = itemType === "root" ? config.root : config.components?.[itemType];
490
+ const newProps = walkObject({
491
+ value: shouldDefaultSlots ? defaultSlots(item.props ?? {}, componentConfig?.fields ?? {}) : item.props,
492
+ fields: componentConfig?.fields ?? {},
493
+ mappers,
494
+ id: item.props ? item.props.id ?? "root" : "root",
495
+ getPropPath: (k) => k,
496
+ config,
497
+ recurseSlots
498
+ });
499
+ if (isPromise(newProps)) {
500
+ return newProps.then((resolvedProps) => ({
501
+ ...item,
502
+ props: resolvedProps
503
+ }));
504
+ }
505
+ return {
506
+ ...item,
507
+ props: newProps
508
+ };
509
+ }
510
+
511
+ // lib/field-transforms/build-mappers.ts
512
+ init_react_import();
513
+ function buildMappers(transforms, readOnly, forceReadOnly) {
514
+ return Object.keys(transforms).reduce((acc, _fieldType) => {
515
+ const fieldType = _fieldType;
516
+ return {
517
+ ...acc,
518
+ [fieldType]: ({
519
+ parentId,
520
+ ...params
521
+ }) => {
522
+ const wildcardPath = params.propPath.replace(/\[\d+\]/g, "[*]");
523
+ const isReadOnly = readOnly?.[params.propPath] || readOnly?.[wildcardPath] || forceReadOnly || false;
524
+ const fn = transforms[fieldType];
525
+ return fn?.({
526
+ ...params,
527
+ isReadOnly,
528
+ componentId: parentId
529
+ });
530
+ }
531
+ };
532
+ }, {});
533
+ }
534
+
535
+ // lib/field-transforms/use-field-transforms.tsx
536
+ function useFieldTransforms(config, item, transforms, readOnly, forceReadOnly) {
537
+ const mappers = (0, import_react2.useMemo)(
538
+ () => buildMappers(transforms, readOnly, forceReadOnly),
539
+ [transforms, readOnly, forceReadOnly]
540
+ );
541
+ const transformedProps = (0, import_react2.useMemo)(() => {
542
+ return mapFields(item, mappers, config).props;
543
+ }, [config, item, mappers]);
544
+ const mergedProps = (0, import_react2.useMemo)(
545
+ () => ({ ...item.props, ...transformedProps }),
546
+ [item.props, transformedProps]
547
+ );
548
+ return mergedProps;
549
+ }
550
+
551
+ // lib/field-transforms/default-transforms/slot-transform.tsx
552
+ init_react_import();
553
+ var getSlotTransform = (renderSlotEdit, renderSlotRender = renderSlotEdit) => ({
554
+ slot: ({ value: content, propName, field, isReadOnly }) => {
555
+ const render = isReadOnly ? renderSlotRender : renderSlotEdit;
556
+ const Slot = (dzProps) => render({
557
+ allow: field?.type === "slot" ? field.allow : [],
558
+ disallow: field?.type === "slot" ? field.disallow : [],
559
+ ...dzProps,
560
+ zone: propName,
561
+ content
562
+ });
563
+ return Slot;
564
+ }
565
+ });
566
+
567
+ // lib/use-slots.tsx
568
+ function useSlots(config, item, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
569
+ return useFieldTransforms(
570
+ config,
571
+ item,
572
+ getSlotTransform(renderSlotEdit, renderSlotRender),
573
+ readOnly,
574
+ forceReadOnly
575
+ );
576
+ }
577
+
578
+ // components/SlotRender/server.tsx
579
+ init_react_import();
580
+ var import_react5 = require("react");
581
+
582
+ // components/RichTextEditor/lib/use-richtext-props.tsx
583
+ init_react_import();
584
+ var import_react4 = require("react");
585
+
586
+ // components/RichTextEditor/components/RenderFallback.tsx
587
+ init_react_import();
588
+ init_get_class_name_factory();
589
+ init_styles_module();
590
+ var import_jsx_runtime = require("react/jsx-runtime");
591
+ var getClassName = get_class_name_factory_default("RichTextEditor", styles_module_default);
592
+ function RichTextRenderFallback({ content }) {
593
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: getClassName(), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
594
+ "div",
595
+ {
596
+ className: "rich-text",
597
+ dangerouslySetInnerHTML: { __html: content }
598
+ }
599
+ ) });
600
+ }
601
+
602
+ // lib/generate-id.ts
603
+ init_react_import();
604
+ var import_uuid = require("uuid");
605
+ var generateId = (type) => type ? `${type}-${(0, import_uuid.v4)()}` : (0, import_uuid.v4)();
606
+
607
+ // components/RichTextEditor/lib/mapDeep.ts
608
+ init_react_import();
609
+ var mapDeep = (source, path, render) => {
610
+ if (!source) {
611
+ return null;
612
+ }
613
+ if (path.length === 0) {
614
+ return render(source);
615
+ }
616
+ const [key, ...rest] = path;
617
+ if (Array.isArray(source)) {
618
+ return source.map((item) => mapDeep(item, path, render));
619
+ }
620
+ return {
621
+ ...source,
622
+ [key]: mapDeep(source[key], rest, render)
623
+ };
624
+ };
625
+
626
+ // components/RichTextEditor/lib/use-richtext-props.tsx
627
+ var import_jsx_runtime3 = require("react/jsx-runtime");
628
+ var findAllRichtextKeys = (fields, path = []) => {
629
+ if (!fields) return [];
630
+ const result = [];
631
+ for (const [key, field] of Object.entries(fields)) {
632
+ const currentPath = [...path, key];
633
+ if (field.type === "richtext") {
634
+ result.push({
635
+ path: currentPath,
636
+ field
637
+ });
638
+ }
639
+ if (field.type === "array" && "arrayFields" in field) {
640
+ result.push(...findAllRichtextKeys(field.arrayFields, currentPath));
641
+ }
642
+ if (field.type === "object" && "objectFields" in field) {
643
+ result.push(...findAllRichtextKeys(field.objectFields, currentPath));
644
+ }
645
+ }
646
+ return result;
647
+ };
648
+ function useRichtextProps(fields, props) {
649
+ const richtextKeys = (0, import_react4.useMemo)(() => findAllRichtextKeys(fields), [fields]);
650
+ const richtextProps = (0, import_react4.useMemo)(() => {
651
+ if (!richtextKeys?.length) return {};
652
+ const RichTextRender2 = (0, import_react4.lazy)(
653
+ () => Promise.resolve().then(() => (init_Render(), Render_exports)).then((m) => ({
654
+ default: m.RichTextRender
655
+ }))
656
+ );
657
+ let result = { ...props };
658
+ for (const { path, field } of richtextKeys) {
659
+ result = mapDeep(result, path, (content) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
660
+ import_react4.Suspense,
661
+ {
662
+ fallback: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(RichTextRenderFallback, { content }),
663
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(RichTextRender2, { content, field })
664
+ },
665
+ generateId()
666
+ ));
667
+ }
668
+ return result;
669
+ }, [richtextKeys, props]);
670
+ return richtextProps;
671
+ }
672
+
673
+ // components/SlotRender/server.tsx
674
+ var import_jsx_runtime4 = require("react/jsx-runtime");
675
+ var SlotRenderPure = (props) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SlotRender, { ...props });
676
+ var Item = ({
677
+ config,
678
+ item,
679
+ metadata
680
+ }) => {
681
+ const Component = config.components[item.type];
682
+ const props = useSlots(config, item, (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SlotRenderPure, { ...slotProps, config, metadata }));
683
+ const richtextProps = useRichtextProps(Component.fields, props);
684
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
685
+ Component.render,
686
+ {
687
+ ...props,
688
+ ...richtextProps,
689
+ credbuild: {
690
+ ...props.credbuild,
691
+ metadata: metadata || {}
692
+ }
693
+ }
694
+ );
695
+ };
696
+ var SlotRender = (0, import_react5.forwardRef)(
697
+ function SlotRenderInternal({ className, style, content, config, metadata, as }, ref) {
698
+ const El = as ?? "div";
699
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(El, { className, style, ref, children: content.map((item) => {
700
+ if (!config.components[item.type]) {
701
+ return null;
702
+ }
703
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
704
+ Item,
705
+ {
706
+ config,
707
+ item,
708
+ metadata
709
+ },
710
+ item.props.id
711
+ );
712
+ }) });
713
+ }
714
+ );
715
+
716
+ // components/ServerRender/index.tsx
717
+ var import_jsx_runtime5 = require("react/jsx-runtime");
718
+ function DropZoneRenderItem({
719
+ item,
720
+ data,
721
+ config,
722
+ metadata
723
+ }) {
724
+ const Component = config.components[item.type];
725
+ const props = {
726
+ ...item.props,
727
+ credbuild: {
728
+ renderDropZone: ({ zone }) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
729
+ DropZoneRender,
730
+ {
731
+ zone,
732
+ data,
733
+ areaId: item.props.id,
734
+ config,
735
+ metadata
736
+ }
737
+ ),
738
+ metadata,
739
+ dragRef: null,
740
+ isEditing: false
741
+ }
742
+ };
743
+ const renderItem = { ...item, props };
744
+ const propsWithSlots = useSlots(config, renderItem, (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SlotRenderPure, { ...slotProps, config, metadata }));
745
+ const richtextProps = useRichtextProps(Component?.fields, propsWithSlots);
746
+ if (!Component) {
747
+ return null;
748
+ }
749
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Component.render, { ...propsWithSlots, ...richtextProps });
750
+ }
751
+ function DropZoneRender({
752
+ zone,
753
+ data,
754
+ areaId = "root",
755
+ config,
756
+ metadata = {}
757
+ }) {
758
+ let zoneCompound = rootDroppableId;
759
+ let content = data?.content || [];
760
+ if (!data || !config) {
761
+ return null;
762
+ }
763
+ if (areaId !== rootAreaId && zone !== rootZone) {
764
+ zoneCompound = `${areaId}:${zone}`;
765
+ content = setupZone(data, zoneCompound).zones[zoneCompound];
766
+ }
767
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: content.map((item) => {
768
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
769
+ DropZoneRenderItem,
770
+ {
771
+ item,
772
+ data,
773
+ config,
774
+ metadata
775
+ },
776
+ item.props.id
777
+ );
778
+ }) });
779
+ }
780
+ function Render({
781
+ config,
782
+ data,
783
+ metadata = {}
784
+ }) {
785
+ const rootProps = "props" in data.root ? data.root.props : data.root;
786
+ const title = rootProps.title || "";
787
+ const props = {
788
+ ...rootProps,
789
+ credbuild: {
790
+ renderDropZone: ({ zone }) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
791
+ DropZoneRender,
792
+ {
793
+ zone,
794
+ data,
795
+ config,
796
+ metadata
797
+ }
798
+ ),
799
+ isEditing: false,
800
+ dragRef: null,
801
+ metadata
802
+ },
803
+ title,
804
+ editMode: false,
805
+ id: "credbuild-root"
806
+ };
807
+ const propsWithSlots = useSlots(config, { type: "root", props }, (props2) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SlotRenderPure, { ...props2, config, metadata }));
808
+ const richtextProps = useRichtextProps(config.root?.fields, props);
809
+ if (config.root?.render) {
810
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(config.root.render, { ...propsWithSlots, ...richtextProps, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
811
+ DropZoneRender,
812
+ {
813
+ config,
814
+ data,
815
+ zone: rootZone,
816
+ metadata
817
+ }
818
+ ) });
819
+ }
820
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
821
+ DropZoneRender,
822
+ {
823
+ config,
824
+ data,
825
+ zone: rootZone,
826
+ metadata
827
+ }
828
+ );
829
+ }
830
+
831
+ // lib/resolve-all-data.ts
832
+ init_react_import();
833
+
834
+ // lib/resolve-component-data.ts
835
+ init_react_import();
836
+
837
+ // lib/data/to-component.ts
838
+ init_react_import();
839
+ var toComponent = (item) => {
840
+ return "type" in item ? item : {
841
+ ...item,
842
+ props: { ...item.props, id: "root" },
843
+ type: "root"
844
+ };
845
+ };
846
+
847
+ // lib/get-changed.ts
848
+ init_react_import();
849
+ var import_fast_equals = require("fast-equals");
850
+ var getChanged = (newItem, oldItem) => {
851
+ return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
852
+ const newItemProps = newItem?.props || {};
853
+ const oldItemProps = oldItem?.props || {};
854
+ return {
855
+ ...acc,
856
+ [item]: !(0, import_fast_equals.deepEqual)(oldItemProps[item], newItemProps[item])
857
+ };
858
+ }, {}) : {};
859
+ };
860
+
861
+ // lib/resolve-component-data.ts
862
+ var import_fast_equals2 = require("fast-equals");
863
+ var cache = { lastChange: {} };
864
+ var resolveComponentData = async (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", parent = null) => {
865
+ const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
866
+ const resolvedItem = {
867
+ ...item
868
+ };
869
+ const shouldRunResolver = configForItem?.resolveData && item.props;
870
+ const id = "id" in item.props ? item.props.id : "root";
871
+ if (shouldRunResolver) {
872
+ const {
873
+ item: oldItem = null,
874
+ resolved = {},
875
+ parentId: oldParentId = null
876
+ } = cache.lastChange[id] || {};
877
+ const isRootOrInserted = oldParentId === null;
878
+ const parentChanged = !isRootOrInserted && parent?.props.id !== oldParentId;
879
+ const dataChanged = item && !(0, import_fast_equals2.deepEqual)(item, oldItem);
880
+ const shouldSkip = trigger === "move" && !parentChanged || trigger !== "move" && trigger !== "force" && !dataChanged;
881
+ if (shouldSkip) {
882
+ return { node: resolved, didChange: false };
883
+ }
884
+ const changed = getChanged(item, oldItem);
885
+ if (onResolveStart) {
886
+ onResolveStart(item);
887
+ }
888
+ const { props: resolvedProps, readOnly = {} } = await configForItem.resolveData(item, {
889
+ changed,
890
+ lastData: oldItem,
891
+ metadata: { ...metadata, ...configForItem.metadata },
892
+ trigger,
893
+ parent
894
+ });
895
+ resolvedItem.props = {
896
+ ...item.props,
897
+ ...resolvedProps
898
+ };
899
+ if (Object.keys(readOnly).length) {
900
+ resolvedItem.readOnly = readOnly;
901
+ }
902
+ }
903
+ const itemAsComponentData = toComponent(resolvedItem);
904
+ let itemWithResolvedChildren = await mapFields(
905
+ resolvedItem,
906
+ {
907
+ slot: async ({ value }) => {
908
+ const content = value;
909
+ return await Promise.all(
910
+ content.map(
911
+ async (childItem) => (await resolveComponentData(
912
+ childItem,
913
+ config,
914
+ metadata,
915
+ onResolveStart,
916
+ onResolveEnd,
917
+ trigger,
918
+ itemAsComponentData
919
+ )).node
920
+ )
921
+ );
922
+ }
923
+ },
924
+ config
925
+ );
926
+ if (shouldRunResolver && onResolveEnd) {
927
+ onResolveEnd(resolvedItem);
928
+ }
929
+ cache.lastChange[id] = {
930
+ item,
931
+ resolved: itemWithResolvedChildren,
932
+ parentId: parent?.props.id
933
+ };
934
+ return {
935
+ node: itemWithResolvedChildren,
936
+ didChange: !(0, import_fast_equals2.deepEqual)(item, itemWithResolvedChildren)
937
+ };
938
+ };
939
+
940
+ // lib/group-zones-by-component.ts
941
+ init_react_import();
942
+
943
+ // lib/get-zone-id.ts
944
+ init_react_import();
945
+ var getZoneId = (zoneCompound) => {
946
+ if (!zoneCompound) {
947
+ return [];
948
+ }
949
+ if (zoneCompound && zoneCompound.indexOf(":") > -1) {
950
+ return zoneCompound.split(":");
951
+ }
952
+ return [rootDroppableId, zoneCompound];
953
+ };
954
+
955
+ // lib/group-zones-by-component.ts
956
+ var groupZonesByComponent = (data) => {
957
+ const zoneEntries = Object.entries(data.zones ?? {});
958
+ return zoneEntries.reduce((acc, [zoneCompound, zoneContent]) => {
959
+ const [componentId, zoneName] = getZoneId(zoneCompound);
960
+ if (!componentId.length || !zoneName.length) return acc;
961
+ if (!acc[componentId]) {
962
+ acc[componentId] = [];
963
+ }
964
+ acc[componentId].push({ zoneCompound, content: zoneContent });
965
+ return acc;
966
+ }, {});
967
+ };
968
+
969
+ // lib/data/default-data.ts
970
+ init_react_import();
971
+ var defaultData = (data) => ({
972
+ ...data,
973
+ root: data.root || {},
974
+ content: data.content || []
975
+ });
976
+
977
+ // lib/resolve-all-data.ts
978
+ async function resolveAllData(data, config, metadata = {}, onResolveStart, onResolveEnd) {
979
+ const defaultedData = defaultData(data);
980
+ const zonesByComponent = groupZonesByComponent(defaultedData);
981
+ let resolvedZones = {};
982
+ const resolveNode = async (_node, parent) => {
983
+ const node = toComponent(_node);
984
+ onResolveStart?.(node);
985
+ const resolved = (await resolveComponentData(
986
+ node,
987
+ config,
988
+ metadata,
989
+ () => {
990
+ },
991
+ () => {
992
+ },
993
+ "force",
994
+ parent
995
+ )).node;
996
+ const resolvedAsComponent = toComponent(resolved);
997
+ const resolvedDeepPromise = mapFields(
998
+ resolved,
999
+ {
1000
+ slot: ({ value }) => processContent(value, resolvedAsComponent)
1001
+ },
1002
+ config
1003
+ );
1004
+ let resolveZonePromises = [];
1005
+ if (zonesByComponent[resolvedAsComponent.props.id]) {
1006
+ resolveZonePromises = zonesByComponent[resolvedAsComponent.props.id].map(
1007
+ async ({ zoneCompound, content }) => {
1008
+ resolvedZones[zoneCompound] = await processContent(
1009
+ content,
1010
+ resolvedAsComponent
1011
+ );
1012
+ }
1013
+ );
1014
+ }
1015
+ const resolvedDeep = await resolvedDeepPromise;
1016
+ await Promise.all(resolveZonePromises);
1017
+ onResolveEnd?.(toComponent(resolvedDeep));
1018
+ return resolvedDeep;
1019
+ };
1020
+ const processContent = async (content, parent) => {
1021
+ return Promise.all(content.map((item) => resolveNode(item, parent)));
1022
+ };
1023
+ const result = defaultData({});
1024
+ result.root = await resolveNode(defaultedData.root, null);
1025
+ result.content = await processContent(
1026
+ defaultedData.content,
1027
+ toComponent(result.root)
1028
+ );
1029
+ result.zones = resolvedZones;
1030
+ return result;
1031
+ }
1032
+
1033
+ // lib/transform-props.ts
1034
+ init_react_import();
1035
+
1036
+ // lib/data/walk-tree.ts
1037
+ init_react_import();
1038
+ function walkTree(data, config, callbackFn) {
1039
+ const walkItem = (item) => {
1040
+ return mapFields(
1041
+ item,
1042
+ {
1043
+ slot: ({ value, parentId, propName }) => {
1044
+ const content = value;
1045
+ return callbackFn(content, { parentId, propName }) ?? content;
1046
+ }
1047
+ },
1048
+ config,
1049
+ true
1050
+ );
1051
+ };
1052
+ if ("props" in data) {
1053
+ return walkItem(data);
1054
+ }
1055
+ const _data = data;
1056
+ const zones = _data.zones ?? {};
1057
+ const mappedContent = _data.content.map(walkItem);
1058
+ return {
1059
+ root: walkItem(_data.root),
1060
+ content: callbackFn(mappedContent, {
1061
+ parentId: "root",
1062
+ propName: "default-zone"
1063
+ }) ?? mappedContent,
1064
+ zones: Object.keys(zones).reduce(
1065
+ (acc, zoneCompound) => ({
1066
+ ...acc,
1067
+ [zoneCompound]: zones[zoneCompound].map(walkItem)
1068
+ }),
1069
+ {}
1070
+ )
1071
+ };
1072
+ }
1073
+
1074
+ // lib/transform-props.ts
1075
+ function transformProps(data, propTransforms, config = { components: {} }) {
1076
+ const mapItem = (item) => {
1077
+ if (propTransforms[item.type]) {
1078
+ return {
1079
+ ...item,
1080
+ props: {
1081
+ id: item.props.id,
1082
+ ...propTransforms[item.type](item.props)
1083
+ }
1084
+ };
1085
+ }
1086
+ return item;
1087
+ };
1088
+ const defaultedData = defaultData(data);
1089
+ const rootProps = defaultedData.root.props || defaultedData.root;
1090
+ let newRoot = { ...defaultedData.root };
1091
+ if (propTransforms["root"]) {
1092
+ newRoot.props = propTransforms["root"](rootProps);
1093
+ }
1094
+ const dataWithUpdatedRoot = { ...defaultedData, root: newRoot };
1095
+ const updatedData = walkTree(
1096
+ dataWithUpdatedRoot,
1097
+ config,
1098
+ (content) => content.map(mapItem)
1099
+ );
1100
+ if (!defaultedData.root.props) {
1101
+ updatedData.root = updatedData.root.props;
1102
+ }
1103
+ return updatedData;
1104
+ }
1105
+
1106
+ // lib/migrate.ts
1107
+ init_react_import();
1108
+
1109
+ // store/default-app-state.ts
1110
+ init_react_import();
1111
+
1112
+ // components/ViewportControls/default-viewports.ts
1113
+ init_react_import();
1114
+ var defaultViewports = [
1115
+ { width: 360, height: "auto", icon: "Smartphone", label: "Small" },
1116
+ { width: 768, height: "auto", icon: "Tablet", label: "Medium" },
1117
+ { width: 1280, height: "auto", icon: "Monitor", label: "Large" },
1118
+ { width: "100%", height: "auto", icon: "FullWidth", label: "Full-width" }
1119
+ ];
1120
+
1121
+ // store/default-app-state.ts
1122
+ var defaultAppState = {
1123
+ data: { content: [], root: {}, zones: {} },
1124
+ ui: {
1125
+ leftSideBarVisible: true,
1126
+ rightSideBarVisible: true,
1127
+ arrayState: {},
1128
+ itemSelector: null,
1129
+ componentList: {},
1130
+ isDragging: false,
1131
+ previewMode: "edit",
1132
+ viewports: {
1133
+ current: {
1134
+ width: defaultViewports[0].width,
1135
+ height: defaultViewports[0].height || "auto"
1136
+ },
1137
+ options: [],
1138
+ controlsVisible: true
1139
+ },
1140
+ field: { focus: null },
1141
+ plugin: { current: null }
1142
+ },
1143
+ indexes: {
1144
+ nodes: {},
1145
+ zones: {}
1146
+ }
1147
+ };
1148
+
1149
+ // lib/data/walk-app-state.ts
1150
+ init_react_import();
1151
+
1152
+ // lib/data/for-related-zones.ts
1153
+ init_react_import();
1154
+ function forRelatedZones(item, data, cb, path = []) {
1155
+ Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
1156
+ const [parentId] = getZoneId(zoneCompound);
1157
+ if (parentId === item.props.id) {
1158
+ cb(path, zoneCompound, content);
1159
+ }
1160
+ });
1161
+ }
1162
+
1163
+ // lib/data/flatten-node.ts
1164
+ init_react_import();
1165
+ var import_flat = __toESM(require("flat"));
1166
+
1167
+ // lib/data/strip-slots.ts
1168
+ init_react_import();
1169
+ var stripSlots = (data, config) => {
1170
+ return mapFields(data, { slot: () => null }, config);
1171
+ };
1172
+
1173
+ // lib/data/flatten-node.ts
1174
+ var { flatten: flatten2, unflatten } = import_flat.default;
1175
+ var isPureObject = (val) => val != null && Object.prototype.toString.call(val) === "[object Object]";
1176
+ var emptyArrayStr = "__credbuild_[]";
1177
+ var emptyObjectStr = "__credbuild_{}";
1178
+ function encodeEmptyObjects(props = {}) {
1179
+ const result = {};
1180
+ for (const key in props) {
1181
+ if (!Object.prototype.hasOwnProperty.call(props, key)) continue;
1182
+ const val = props[key];
1183
+ if (Array.isArray(val) && val.length === 0) {
1184
+ result[key] = emptyArrayStr;
1185
+ } else if (isPureObject(val) && Object.keys(val).length === 0) {
1186
+ result[key] = emptyObjectStr;
1187
+ } else {
1188
+ result[key] = val;
1189
+ }
1190
+ }
1191
+ return result;
1192
+ }
1193
+ var flattenNode = (node, config) => {
1194
+ return {
1195
+ ...node,
1196
+ props: encodeEmptyObjects(flatten2(stripSlots(node, config).props))
1197
+ };
1198
+ };
1199
+
1200
+ // lib/data/walk-app-state.ts
1201
+ function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
1202
+ let newZones = {};
1203
+ const newZoneIndex = {};
1204
+ const newNodeIndex = {};
1205
+ const processContent = (path, zoneCompound, content, zoneType, newId) => {
1206
+ const [parentId] = zoneCompound.split(":");
1207
+ const mappedContent = (mapContent(content, zoneCompound, zoneType) ?? content) || [];
1208
+ const [_2, zone] = zoneCompound.split(":");
1209
+ const newZoneCompound = `${newId || parentId}:${zone}`;
1210
+ const newContent2 = mappedContent.map(
1211
+ (zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
1212
+ );
1213
+ newZoneIndex[newZoneCompound] = {
1214
+ contentIds: newContent2.map((item) => item.props.id),
1215
+ type: zoneType
1216
+ };
1217
+ return [newZoneCompound, newContent2];
1218
+ };
1219
+ const processRelatedZones = (item, newId, initialPath) => {
1220
+ forRelatedZones(
1221
+ item,
1222
+ state.data,
1223
+ (relatedPath, relatedZoneCompound, relatedContent) => {
1224
+ const [zoneCompound, newContent2] = processContent(
1225
+ relatedPath,
1226
+ relatedZoneCompound,
1227
+ relatedContent,
1228
+ "dropzone",
1229
+ newId
1230
+ );
1231
+ newZones[zoneCompound] = newContent2;
1232
+ },
1233
+ initialPath
1234
+ );
1235
+ };
1236
+ const processItem = (item, path, index) => {
1237
+ const mappedItem = mapNodeOrSkip(item, path, index);
1238
+ if (!mappedItem) return item;
1239
+ const id = mappedItem.props.id;
1240
+ const newProps = {
1241
+ ...mapFields(
1242
+ mappedItem,
1243
+ {
1244
+ slot: ({ value, parentId: parentId2, propPath }) => {
1245
+ const content = value;
1246
+ const zoneCompound = `${parentId2}:${propPath}`;
1247
+ const [_2, newContent2] = processContent(
1248
+ path,
1249
+ zoneCompound,
1250
+ content,
1251
+ "slot",
1252
+ parentId2
1253
+ );
1254
+ return newContent2;
1255
+ }
1256
+ },
1257
+ config
1258
+ ).props,
1259
+ id
1260
+ };
1261
+ processRelatedZones(item, id, path);
1262
+ const newItem = { ...mappedItem, props: newProps };
1263
+ const thisZoneCompound = path[path.length - 1];
1264
+ const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
1265
+ newNodeIndex[id] = {
1266
+ data: newItem,
1267
+ flatData: flattenNode(newItem, config),
1268
+ path,
1269
+ parentId,
1270
+ zone
1271
+ };
1272
+ const finalData = { ...newItem, props: { ...newItem.props } };
1273
+ if (newProps.id === "root") {
1274
+ delete finalData["type"];
1275
+ delete finalData.props["id"];
1276
+ }
1277
+ return finalData;
1278
+ };
1279
+ const zones = state.data.zones || {};
1280
+ const [_, newContent] = processContent(
1281
+ [],
1282
+ rootDroppableId,
1283
+ state.data.content,
1284
+ "root"
1285
+ );
1286
+ const processedContent = newContent;
1287
+ const zonesAlreadyProcessed = Object.keys(newZones);
1288
+ Object.keys(zones || {}).forEach((zoneCompound) => {
1289
+ const [parentId] = zoneCompound.split(":");
1290
+ if (zonesAlreadyProcessed.includes(zoneCompound)) {
1291
+ return;
1292
+ }
1293
+ const [_2, newContent2] = processContent(
1294
+ [rootDroppableId],
1295
+ zoneCompound,
1296
+ zones[zoneCompound],
1297
+ "dropzone",
1298
+ parentId
1299
+ );
1300
+ newZones[zoneCompound] = newContent2;
1301
+ }, newZones);
1302
+ let rootAsComponent = toComponent({
1303
+ props: { ...state.data.root.props ?? state.data.root }
1304
+ });
1305
+ if (state.data.root.readOnly) {
1306
+ rootAsComponent.readOnly = state.data.root.readOnly;
1307
+ }
1308
+ const processedRoot = processItem(rootAsComponent, [], -1);
1309
+ const root = {
1310
+ ...state.data.root,
1311
+ ...processedRoot
1312
+ };
1313
+ return {
1314
+ ...state,
1315
+ data: {
1316
+ root,
1317
+ content: processedContent,
1318
+ zones: {
1319
+ ...state.data.zones,
1320
+ ...newZones
1321
+ }
1322
+ },
1323
+ indexes: {
1324
+ nodes: { ...state.indexes.nodes, ...newNodeIndex },
1325
+ zones: { ...state.indexes.zones, ...newZoneIndex }
1326
+ }
1327
+ };
1328
+ }
1329
+
1330
+ // lib/migrate.ts
1331
+ var migrations = [
1332
+ // Migrate root to root.props
1333
+ (data) => {
1334
+ const rootProps = data.root.props || data.root;
1335
+ if (Object.keys(data.root).length > 0 && !data.root.props) {
1336
+ console.warn(
1337
+ "Migration applied: Root props moved from `root` to `root.props`."
1338
+ );
1339
+ return {
1340
+ ...data,
1341
+ root: {
1342
+ props: {
1343
+ ...rootProps
1344
+ }
1345
+ }
1346
+ };
1347
+ }
1348
+ return data;
1349
+ },
1350
+ // Migrate zones to slots
1351
+ (data, config, migrationOptions) => {
1352
+ if (!config) return data;
1353
+ console.log("Migrating DropZones to slots...");
1354
+ const updatedItems = {};
1355
+ const appState = { ...defaultAppState, data };
1356
+ const { indexes } = walkAppState(appState, config);
1357
+ const deletedCompounds = [];
1358
+ walkAppState(appState, config, (content, zoneCompound, zoneType) => {
1359
+ if (zoneType === "dropzone") {
1360
+ const [id, slotName] = zoneCompound.split(":");
1361
+ const nodeData = indexes.nodes[id].data;
1362
+ const componentType = nodeData.type;
1363
+ const configForComponent = id === "root" ? config.root : config.components[componentType];
1364
+ if (configForComponent?.fields?.[slotName]?.type === "slot") {
1365
+ updatedItems[id] = {
1366
+ ...nodeData,
1367
+ props: {
1368
+ ...nodeData.props,
1369
+ ...updatedItems[id]?.props,
1370
+ [slotName]: content
1371
+ }
1372
+ };
1373
+ deletedCompounds.push(zoneCompound);
1374
+ }
1375
+ return content;
1376
+ }
1377
+ return content;
1378
+ });
1379
+ const updated = walkAppState(
1380
+ appState,
1381
+ config,
1382
+ (content) => content,
1383
+ (item) => {
1384
+ return updatedItems[item.props.id] ?? item;
1385
+ }
1386
+ );
1387
+ deletedCompounds.forEach((zoneCompound) => {
1388
+ const [_, propName] = zoneCompound.split(":");
1389
+ console.log(
1390
+ `\u2713 Success: Migrated "${zoneCompound}" from DropZone to slot field "${propName}"`
1391
+ );
1392
+ delete updated.data.zones?.[zoneCompound];
1393
+ });
1394
+ if (migrationOptions?.migrateDynamicZonesForComponent) {
1395
+ const unmigratedZonesGrouped = {};
1396
+ Object.keys(updated.data.zones ?? {}).forEach((zoneCompound) => {
1397
+ const [componentId, propName] = zoneCompound.split(":");
1398
+ const content = updated.data.zones?.[zoneCompound];
1399
+ if (!content) {
1400
+ return;
1401
+ }
1402
+ if (!unmigratedZonesGrouped[componentId]) {
1403
+ unmigratedZonesGrouped[componentId] = {};
1404
+ }
1405
+ if (!unmigratedZonesGrouped[componentId][propName]) {
1406
+ unmigratedZonesGrouped[componentId][propName] = content;
1407
+ }
1408
+ });
1409
+ Object.keys(unmigratedZonesGrouped).forEach((componentId) => {
1410
+ updated.data = walkTree(updated.data, config, (content) => {
1411
+ return content.map((child) => {
1412
+ if (child.props.id !== componentId) {
1413
+ return child;
1414
+ }
1415
+ const migrateFn = migrationOptions?.migrateDynamicZonesForComponent?.[child.type];
1416
+ if (!migrateFn) {
1417
+ return child;
1418
+ }
1419
+ const zones = unmigratedZonesGrouped[componentId];
1420
+ const migratedProps = migrateFn(child.props, zones);
1421
+ Object.keys(zones).forEach((propName) => {
1422
+ const zoneCompound = `${componentId}:${propName}`;
1423
+ console.log(`\u2713 Success: Migrated "${zoneCompound}" DropZone`);
1424
+ delete updated.data.zones?.[zoneCompound];
1425
+ });
1426
+ return {
1427
+ ...child,
1428
+ props: migratedProps
1429
+ };
1430
+ });
1431
+ });
1432
+ });
1433
+ }
1434
+ Object.keys(updated.data.zones ?? {}).forEach((zoneCompound) => {
1435
+ const [_, propName] = zoneCompound.split(":");
1436
+ throw new Error(
1437
+ `Could not migrate DropZone "${zoneCompound}" to slot field. No slot exists with the name "${propName}".`
1438
+ );
1439
+ });
1440
+ delete updated.data.zones;
1441
+ return updated.data;
1442
+ }
1443
+ ];
1444
+ function migrate(data, config, migrationOptions) {
1445
+ return migrations?.reduce(
1446
+ (acc, migration) => migration(acc, config, migrationOptions),
1447
+ data
1448
+ );
1449
+ }
1450
+ // Annotate the CommonJS export names for ESM import in node:
1451
+ 0 && (module.exports = {
1452
+ Render,
1453
+ migrate,
1454
+ resolveAllData,
1455
+ transformProps,
1456
+ walkTree
1457
+ });
1458
+ /*! Bundled license information:
1459
+
1460
+ classnames/index.js:
1461
+ (*!
1462
+ Copyright (c) 2018 Jed Watson.
1463
+ Licensed under the MIT License (MIT), see
1464
+ http://jedwatson.github.io/classnames
1465
+ *)
1466
+ */