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