@puckeditor/core 0.21.0-canary.08cd0aca

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 +114 -0
  2. package/dist/Editor-IQP25PUX.css +404 -0
  3. package/dist/Editor-L7XD2QW3.mjs +204 -0
  4. package/dist/Render-3OV4N4MT.css +102 -0
  5. package/dist/Render-FXZX6NFH.mjs +55 -0
  6. package/dist/actions-BkBoKAc5.d.mts +838 -0
  7. package/dist/actions-BkBoKAc5.d.ts +838 -0
  8. package/dist/chunk-7TZD3NRP.mjs +450 -0
  9. package/dist/chunk-AHX7X7NZ.mjs +156 -0
  10. package/dist/chunk-AOEDIUVK.mjs +11 -0
  11. package/dist/chunk-GLWC4QRX.mjs +8074 -0
  12. package/dist/chunk-HLB66X4S.mjs +1813 -0
  13. package/dist/chunk-M6W7YEVX.mjs +95 -0
  14. package/dist/chunk-MNNPATDB.mjs +63 -0
  15. package/dist/chunk-QIJR53IK.mjs +528 -0
  16. package/dist/chunk-RYILZVCB.mjs +708 -0
  17. package/dist/chunk-UFXHMVJE.mjs +53 -0
  18. package/dist/chunk-V5I7CVLT.mjs +103 -0
  19. package/dist/chunk-WB2EIKOA.mjs +445 -0
  20. package/dist/chunk-Y2EFNT5P.mjs +108 -0
  21. package/dist/chunk-YBJ32VYI.mjs +33 -0
  22. package/dist/chunk-ZPR7EC3T.mjs +111 -0
  23. package/dist/full-2GJTAAZE.css +301 -0
  24. package/dist/full-4UGAOTTB.mjs +93 -0
  25. package/dist/index-bqD1SEOb.d.mts +118 -0
  26. package/dist/index-lt1zf5WR.d.ts +118 -0
  27. package/dist/index.css +2629 -0
  28. package/dist/index.d.mts +309 -0
  29. package/dist/index.d.ts +309 -0
  30. package/dist/index.js +14191 -0
  31. package/dist/index.mjs +78 -0
  32. package/dist/internal.d.mts +27 -0
  33. package/dist/internal.d.ts +27 -0
  34. package/dist/internal.js +926 -0
  35. package/dist/internal.mjs +13 -0
  36. package/dist/loaded-5AM4V5PV.mjs +57 -0
  37. package/dist/loaded-G2WSQZO7.mjs +57 -0
  38. package/dist/loaded-MYALJBRK.mjs +60 -0
  39. package/dist/loaded-RVWBFK7L.css +87 -0
  40. package/dist/no-external.css +2631 -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 +14194 -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 +1444 -0
  49. package/dist/rsc.mjs +130 -0
  50. package/dist/walk-tree-CRRDqx6_.d.mts +29 -0
  51. package/dist/walk-tree-CS7sEpfG.d.ts +29 -0
  52. package/package.json +137 -0
package/dist/rsc.js ADDED
@@ -0,0 +1,1444 @@
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:/home/runner/work/puck/puck/packages/core/components/RichTextEditor/styles.module.css/#css-module-data
190
+ var init_css_module_data = __esm({
191
+ "css-module:/home/runner/work/puck/puck/packages/core/components/RichTextEditor/styles.module.css/#css-module-data"() {
192
+ }
193
+ });
194
+
195
+ // css-module:/home/runner/work/puck/puck/packages/core/components/RichTextEditor/styles.module.css#css-module
196
+ var styles_module_default;
197
+ var init_styles_module = __esm({
198
+ "css-module:/home/runner/work/puck/puck/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_z25h4_1", "RichTextEditor--editor": "_RichTextEditor--editor_z25h4_50", "RichTextEditor--disabled": "_RichTextEditor--disabled_z25h4_107", "RichTextEditor--isActive": "_RichTextEditor--isActive_z25h4_111", "RichTextEditor-menu": "_RichTextEditor-menu_z25h4_117" };
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, defaultPuckRichTextOptions, PuckRichText;
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
+ defaultPuckRichTextOptions = {
230
+ textAlign: {
231
+ types: ["heading", "paragraph"]
232
+ }
233
+ };
234
+ PuckRichText = import_core.Extension.create({
235
+ name: "puckRichText",
236
+ addExtensions() {
237
+ const extensions = [];
238
+ const options = __spreadValues(__spreadValues({}, this.options), defaultPuckRichTextOptions);
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.bulletList !== false) {
246
+ extensions.push(import_extension_list.BulletList.configure(options.bulletList));
247
+ }
248
+ if (options.code !== false) {
249
+ extensions.push(import_extension_code.Code.configure(options.code));
250
+ }
251
+ if (options.codeBlock !== false) {
252
+ extensions.push(import_extension_code_block.CodeBlock.configure(options.codeBlock));
253
+ }
254
+ if (options.document !== false) {
255
+ extensions.push(import_extension_document.Document.configure(options.document));
256
+ }
257
+ if (options.hardBreak !== false) {
258
+ extensions.push(import_extension_hard_break.HardBreak.configure(options.hardBreak));
259
+ }
260
+ if (options.heading !== false) {
261
+ extensions.push(import_extension_heading.Heading.configure(options.heading));
262
+ }
263
+ if (options.horizontalRule !== false) {
264
+ extensions.push(import_extension_horizontal_rule.HorizontalRule.configure(options.horizontalRule));
265
+ }
266
+ if (options.italic !== false) {
267
+ extensions.push(import_extension_italic.Italic.configure(options.italic));
268
+ }
269
+ if (options.listItem !== false) {
270
+ extensions.push(import_extension_list.ListItem.configure(options.listItem));
271
+ }
272
+ if (options.listKeymap !== false) {
273
+ extensions.push(import_extension_list.ListKeymap.configure(options == null ? void 0 : options.listKeymap));
274
+ }
275
+ if (options.link !== false) {
276
+ extensions.push(import_extension_link.Link.configure(options == null ? void 0 : options.link));
277
+ }
278
+ if (options.orderedList !== false) {
279
+ extensions.push(import_extension_list.OrderedList.configure(options.orderedList));
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
+ () => [PuckRichText.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
+ // components/RichTextEditor/lib/use-richtext-props.tsx
647
+ var import_jsx_runtime3 = require("react/jsx-runtime");
648
+ function useRichtextProps(fields, props) {
649
+ const findAllRichtextKeys = (fields2) => {
650
+ if (!fields2) return [];
651
+ const result = [];
652
+ for (const [key, field] of Object.entries(fields2)) {
653
+ if (field.type === "richtext") {
654
+ result.push(key);
655
+ }
656
+ }
657
+ return result;
658
+ };
659
+ const richtextKeys = (0, import_react4.useMemo)(() => findAllRichtextKeys(fields), [fields]);
660
+ const richtextProps = (0, import_react4.useMemo)(() => {
661
+ if (!(richtextKeys == null ? void 0 : richtextKeys.length)) return {};
662
+ const RichTextRender2 = (0, import_react4.lazy)(
663
+ () => Promise.resolve().then(() => (init_Render(), Render_exports)).then((m) => ({
664
+ default: m.RichTextRender
665
+ }))
666
+ );
667
+ return richtextKeys.reduce((acc, key) => {
668
+ acc[key] = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react4.Suspense, { fallback: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(RichTextRenderFallback, { content: props[key] }), children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
669
+ RichTextRender2,
670
+ {
671
+ content: props[key],
672
+ field: fields[key]
673
+ }
674
+ ) });
675
+ return acc;
676
+ }, {});
677
+ }, [richtextKeys, props, fields]);
678
+ return richtextProps;
679
+ }
680
+
681
+ // components/SlotRender/server.tsx
682
+ var import_jsx_runtime4 = require("react/jsx-runtime");
683
+ var SlotRenderPure = (props) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SlotRender, __spreadValues({}, props));
684
+ var Item = ({
685
+ config,
686
+ item,
687
+ metadata
688
+ }) => {
689
+ const Component = config.components[item.type];
690
+ const props = useSlots(config, item, (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
691
+ const richtextProps = useRichtextProps(Component.fields, props);
692
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
693
+ Component.render,
694
+ __spreadProps(__spreadValues(__spreadValues({}, props), richtextProps), {
695
+ puck: __spreadProps(__spreadValues({}, props.puck), {
696
+ metadata: metadata || {}
697
+ })
698
+ })
699
+ );
700
+ };
701
+ var SlotRender = (0, import_react5.forwardRef)(
702
+ function SlotRenderInternal({ className, style, content, config, metadata, as }, ref) {
703
+ const El = as != null ? as : "div";
704
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(El, { className, style, ref, children: content.map((item) => {
705
+ if (!config.components[item.type]) {
706
+ return null;
707
+ }
708
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
709
+ Item,
710
+ {
711
+ config,
712
+ item,
713
+ metadata
714
+ },
715
+ item.props.id
716
+ );
717
+ }) });
718
+ }
719
+ );
720
+
721
+ // components/ServerRender/index.tsx
722
+ var import_jsx_runtime5 = require("react/jsx-runtime");
723
+ function DropZoneRender({
724
+ zone,
725
+ data,
726
+ areaId = "root",
727
+ config,
728
+ metadata = {}
729
+ }) {
730
+ let zoneCompound = rootDroppableId;
731
+ let content = (data == null ? void 0 : data.content) || [];
732
+ if (!data || !config) {
733
+ return null;
734
+ }
735
+ if (areaId !== rootAreaId && zone !== rootZone) {
736
+ zoneCompound = `${areaId}:${zone}`;
737
+ content = setupZone(data, zoneCompound).zones[zoneCompound];
738
+ }
739
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: content.map((item) => {
740
+ const Component = config.components[item.type];
741
+ const props = __spreadProps(__spreadValues({}, item.props), {
742
+ puck: {
743
+ renderDropZone: ({ zone: zone2 }) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
744
+ DropZoneRender,
745
+ {
746
+ zone: zone2,
747
+ data,
748
+ areaId: item.props.id,
749
+ config,
750
+ metadata
751
+ }
752
+ ),
753
+ metadata,
754
+ dragRef: null,
755
+ isEditing: false
756
+ }
757
+ });
758
+ const renderItem = __spreadProps(__spreadValues({}, item), { props });
759
+ const propsWithSlots = useSlots(config, renderItem, (props2) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
760
+ if (Component) {
761
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Component.render, __spreadValues({}, propsWithSlots), renderItem.props.id);
762
+ }
763
+ return null;
764
+ }) });
765
+ }
766
+ function Render({
767
+ config,
768
+ data,
769
+ metadata = {}
770
+ }) {
771
+ var _a, _b;
772
+ const rootProps = "props" in data.root ? data.root.props : data.root;
773
+ const title = rootProps.title || "";
774
+ const props = __spreadProps(__spreadValues({}, rootProps), {
775
+ puck: {
776
+ renderDropZone: ({ zone }) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
777
+ DropZoneRender,
778
+ {
779
+ zone,
780
+ data,
781
+ config,
782
+ metadata
783
+ }
784
+ ),
785
+ isEditing: false,
786
+ dragRef: null,
787
+ metadata
788
+ },
789
+ title,
790
+ editMode: false,
791
+ id: "puck-root"
792
+ });
793
+ const propsWithSlots = useSlots(config, { type: "root", props }, (props2) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
794
+ const richtextProps = useRichtextProps((_a = config.root) == null ? void 0 : _a.fields, props);
795
+ if ((_b = config.root) == null ? void 0 : _b.render) {
796
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(config.root.render, __spreadProps(__spreadValues(__spreadValues({}, propsWithSlots), richtextProps), { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
797
+ DropZoneRender,
798
+ {
799
+ config,
800
+ data,
801
+ zone: rootZone,
802
+ metadata
803
+ }
804
+ ) }));
805
+ }
806
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
807
+ DropZoneRender,
808
+ {
809
+ config,
810
+ data,
811
+ zone: rootZone,
812
+ metadata
813
+ }
814
+ );
815
+ }
816
+
817
+ // lib/resolve-all-data.ts
818
+ init_react_import();
819
+
820
+ // lib/resolve-component-data.ts
821
+ init_react_import();
822
+
823
+ // lib/data/to-component.ts
824
+ init_react_import();
825
+ var toComponent = (item) => {
826
+ return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
827
+ props: __spreadProps(__spreadValues({}, item.props), { id: "root" }),
828
+ type: "root"
829
+ });
830
+ };
831
+
832
+ // lib/get-changed.ts
833
+ init_react_import();
834
+ var import_fast_equals = require("fast-equals");
835
+ var getChanged = (newItem, oldItem) => {
836
+ return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
837
+ const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
838
+ const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
839
+ return __spreadProps(__spreadValues({}, acc), {
840
+ [item]: !(0, import_fast_equals.deepEqual)(oldItemProps[item], newItemProps[item])
841
+ });
842
+ }, {}) : {};
843
+ };
844
+
845
+ // lib/resolve-component-data.ts
846
+ var import_fast_equals2 = require("fast-equals");
847
+ var cache = { lastChange: {} };
848
+ var resolveComponentData = (_0, _1, ..._2) => __async(null, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", parent = null) {
849
+ const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
850
+ const resolvedItem = __spreadValues({}, item);
851
+ const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
852
+ const id = "id" in item.props ? item.props.id : "root";
853
+ if (shouldRunResolver) {
854
+ const {
855
+ item: oldItem = null,
856
+ resolved = {},
857
+ parentId: oldParentId = null
858
+ } = cache.lastChange[id] || {};
859
+ const isRootOrInserted = oldParentId === null;
860
+ const parentChanged = !isRootOrInserted && (parent == null ? void 0 : parent.props.id) !== oldParentId;
861
+ const dataChanged = item && !(0, import_fast_equals2.deepEqual)(item, oldItem);
862
+ const shouldSkip = trigger === "move" && !parentChanged || trigger !== "move" && trigger !== "force" && !dataChanged;
863
+ if (shouldSkip) {
864
+ return { node: resolved, didChange: false };
865
+ }
866
+ const changed = getChanged(item, oldItem);
867
+ if (onResolveStart) {
868
+ onResolveStart(item);
869
+ }
870
+ const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
871
+ changed,
872
+ lastData: oldItem,
873
+ metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
874
+ trigger,
875
+ parent
876
+ });
877
+ resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
878
+ if (Object.keys(readOnly).length) {
879
+ resolvedItem.readOnly = readOnly;
880
+ }
881
+ }
882
+ const itemAsComponentData = toComponent(resolvedItem);
883
+ let itemWithResolvedChildren = yield mapFields(
884
+ resolvedItem,
885
+ {
886
+ slot: (_02) => __async(null, [_02], function* ({ value }) {
887
+ const content = value;
888
+ return yield Promise.all(
889
+ content.map(
890
+ (childItem) => __async(null, null, function* () {
891
+ return (yield resolveComponentData(
892
+ childItem,
893
+ config,
894
+ metadata,
895
+ onResolveStart,
896
+ onResolveEnd,
897
+ trigger,
898
+ itemAsComponentData
899
+ )).node;
900
+ })
901
+ )
902
+ );
903
+ })
904
+ },
905
+ config
906
+ );
907
+ if (shouldRunResolver && onResolveEnd) {
908
+ onResolveEnd(resolvedItem);
909
+ }
910
+ cache.lastChange[id] = {
911
+ item,
912
+ resolved: itemWithResolvedChildren,
913
+ parentId: parent == null ? void 0 : parent.props.id
914
+ };
915
+ return {
916
+ node: itemWithResolvedChildren,
917
+ didChange: !(0, import_fast_equals2.deepEqual)(item, itemWithResolvedChildren)
918
+ };
919
+ });
920
+
921
+ // lib/group-zones-by-component.ts
922
+ init_react_import();
923
+
924
+ // lib/get-zone-id.ts
925
+ init_react_import();
926
+ var getZoneId = (zoneCompound) => {
927
+ if (!zoneCompound) {
928
+ return [];
929
+ }
930
+ if (zoneCompound && zoneCompound.indexOf(":") > -1) {
931
+ return zoneCompound.split(":");
932
+ }
933
+ return [rootDroppableId, zoneCompound];
934
+ };
935
+
936
+ // lib/group-zones-by-component.ts
937
+ var groupZonesByComponent = (data) => {
938
+ var _a;
939
+ const zoneEntries = Object.entries((_a = data.zones) != null ? _a : {});
940
+ return zoneEntries.reduce((acc, [zoneCompound, zoneContent]) => {
941
+ const [componentId, zoneName] = getZoneId(zoneCompound);
942
+ if (!componentId.length || !zoneName.length) return acc;
943
+ if (!acc[componentId]) {
944
+ acc[componentId] = [];
945
+ }
946
+ acc[componentId].push({ zoneCompound, content: zoneContent });
947
+ return acc;
948
+ }, {});
949
+ };
950
+
951
+ // lib/data/default-data.ts
952
+ init_react_import();
953
+ var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
954
+ root: data.root || {},
955
+ content: data.content || []
956
+ });
957
+
958
+ // lib/resolve-all-data.ts
959
+ function resolveAllData(_0, _1) {
960
+ return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
961
+ const defaultedData = defaultData(data);
962
+ const zonesByComponent = groupZonesByComponent(defaultedData);
963
+ let resolvedZones = {};
964
+ const resolveNode = (_node, parent) => __async(null, null, function* () {
965
+ const node = toComponent(_node);
966
+ onResolveStart == null ? void 0 : onResolveStart(node);
967
+ const resolved = (yield resolveComponentData(
968
+ node,
969
+ config,
970
+ metadata,
971
+ () => {
972
+ },
973
+ () => {
974
+ },
975
+ "force",
976
+ parent
977
+ )).node;
978
+ const resolvedAsComponent = toComponent(resolved);
979
+ const resolvedDeepPromise = mapFields(
980
+ resolved,
981
+ {
982
+ slot: ({ value }) => processContent(value, resolvedAsComponent)
983
+ },
984
+ config
985
+ );
986
+ let resolveZonePromises = [];
987
+ if (zonesByComponent[resolvedAsComponent.props.id]) {
988
+ resolveZonePromises = zonesByComponent[resolvedAsComponent.props.id].map(
989
+ (_02) => __async(null, [_02], function* ({ zoneCompound, content }) {
990
+ resolvedZones[zoneCompound] = yield processContent(
991
+ content,
992
+ resolvedAsComponent
993
+ );
994
+ })
995
+ );
996
+ }
997
+ const resolvedDeep = yield resolvedDeepPromise;
998
+ yield Promise.all(resolveZonePromises);
999
+ onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
1000
+ return resolvedDeep;
1001
+ });
1002
+ const processContent = (content, parent) => __async(null, null, function* () {
1003
+ return Promise.all(content.map((item) => resolveNode(item, parent)));
1004
+ });
1005
+ const result = defaultData({});
1006
+ result.root = yield resolveNode(defaultedData.root, null);
1007
+ result.content = yield processContent(
1008
+ defaultedData.content,
1009
+ toComponent(result.root)
1010
+ );
1011
+ result.zones = resolvedZones;
1012
+ return result;
1013
+ });
1014
+ }
1015
+
1016
+ // lib/transform-props.ts
1017
+ init_react_import();
1018
+
1019
+ // lib/data/walk-tree.ts
1020
+ init_react_import();
1021
+ function walkTree(data, config, callbackFn) {
1022
+ var _a, _b;
1023
+ const walkItem = (item) => {
1024
+ return mapFields(
1025
+ item,
1026
+ {
1027
+ slot: ({ value, parentId, propName }) => {
1028
+ var _a2;
1029
+ const content = value;
1030
+ return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
1031
+ }
1032
+ },
1033
+ config,
1034
+ true
1035
+ );
1036
+ };
1037
+ if ("props" in data) {
1038
+ return walkItem(data);
1039
+ }
1040
+ const _data = data;
1041
+ const zones = (_a = _data.zones) != null ? _a : {};
1042
+ const mappedContent = _data.content.map(walkItem);
1043
+ return {
1044
+ root: walkItem(_data.root),
1045
+ content: (_b = callbackFn(mappedContent, {
1046
+ parentId: "root",
1047
+ propName: "default-zone"
1048
+ })) != null ? _b : mappedContent,
1049
+ zones: Object.keys(zones).reduce(
1050
+ (acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
1051
+ [zoneCompound]: zones[zoneCompound].map(walkItem)
1052
+ }),
1053
+ {}
1054
+ )
1055
+ };
1056
+ }
1057
+
1058
+ // lib/transform-props.ts
1059
+ function transformProps(data, propTransforms, config = { components: {} }) {
1060
+ const mapItem = (item) => {
1061
+ if (propTransforms[item.type]) {
1062
+ return __spreadProps(__spreadValues({}, item), {
1063
+ props: __spreadValues({
1064
+ id: item.props.id
1065
+ }, propTransforms[item.type](item.props))
1066
+ });
1067
+ }
1068
+ return item;
1069
+ };
1070
+ const defaultedData = defaultData(data);
1071
+ const rootProps = defaultedData.root.props || defaultedData.root;
1072
+ let newRoot = __spreadValues({}, defaultedData.root);
1073
+ if (propTransforms["root"]) {
1074
+ newRoot.props = propTransforms["root"](rootProps);
1075
+ }
1076
+ const dataWithUpdatedRoot = __spreadProps(__spreadValues({}, defaultedData), { root: newRoot });
1077
+ const updatedData = walkTree(
1078
+ dataWithUpdatedRoot,
1079
+ config,
1080
+ (content) => content.map(mapItem)
1081
+ );
1082
+ if (!defaultedData.root.props) {
1083
+ updatedData.root = updatedData.root.props;
1084
+ }
1085
+ return updatedData;
1086
+ }
1087
+
1088
+ // lib/migrate.ts
1089
+ init_react_import();
1090
+
1091
+ // store/default-app-state.ts
1092
+ init_react_import();
1093
+
1094
+ // components/ViewportControls/default-viewports.ts
1095
+ init_react_import();
1096
+ var defaultViewports = [
1097
+ { width: 360, height: "auto", icon: "Smartphone", label: "Small" },
1098
+ { width: 768, height: "auto", icon: "Tablet", label: "Medium" },
1099
+ { width: 1280, height: "auto", icon: "Monitor", label: "Large" },
1100
+ { width: "100%", height: "auto", icon: "FullWidth", label: "Full-width" }
1101
+ ];
1102
+
1103
+ // store/default-app-state.ts
1104
+ var defaultAppState = {
1105
+ data: { content: [], root: {}, zones: {} },
1106
+ ui: {
1107
+ leftSideBarVisible: true,
1108
+ rightSideBarVisible: true,
1109
+ arrayState: {},
1110
+ itemSelector: null,
1111
+ componentList: {},
1112
+ isDragging: false,
1113
+ previewMode: "edit",
1114
+ viewports: {
1115
+ current: {
1116
+ width: defaultViewports[0].width,
1117
+ height: defaultViewports[0].height || "auto"
1118
+ },
1119
+ options: [],
1120
+ controlsVisible: true
1121
+ },
1122
+ field: { focus: null },
1123
+ plugin: { current: null }
1124
+ },
1125
+ indexes: {
1126
+ nodes: {},
1127
+ zones: {}
1128
+ }
1129
+ };
1130
+
1131
+ // lib/data/walk-app-state.ts
1132
+ init_react_import();
1133
+
1134
+ // lib/data/for-related-zones.ts
1135
+ init_react_import();
1136
+ function forRelatedZones(item, data, cb, path = []) {
1137
+ Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
1138
+ const [parentId] = getZoneId(zoneCompound);
1139
+ if (parentId === item.props.id) {
1140
+ cb(path, zoneCompound, content);
1141
+ }
1142
+ });
1143
+ }
1144
+
1145
+ // lib/data/flatten-node.ts
1146
+ init_react_import();
1147
+ var import_flat = __toESM(require("flat"));
1148
+
1149
+ // lib/data/strip-slots.ts
1150
+ init_react_import();
1151
+ var stripSlots = (data, config) => {
1152
+ return mapFields(data, { slot: () => null }, config);
1153
+ };
1154
+
1155
+ // lib/data/flatten-node.ts
1156
+ var { flatten: flatten2, unflatten } = import_flat.default;
1157
+ var isPureObject = (val) => val != null && Object.prototype.toString.call(val) === "[object Object]";
1158
+ var emptyArrayStr = "__puck_[]";
1159
+ var emptyObjectStr = "__puck_{}";
1160
+ function encodeEmptyObjects(props = {}) {
1161
+ const result = {};
1162
+ for (const key in props) {
1163
+ if (!Object.prototype.hasOwnProperty.call(props, key)) continue;
1164
+ const val = props[key];
1165
+ if (Array.isArray(val) && val.length === 0) {
1166
+ result[key] = emptyArrayStr;
1167
+ } else if (isPureObject(val) && Object.keys(val).length === 0) {
1168
+ result[key] = emptyObjectStr;
1169
+ } else {
1170
+ result[key] = val;
1171
+ }
1172
+ }
1173
+ return result;
1174
+ }
1175
+ var flattenNode = (node, config) => {
1176
+ return __spreadProps(__spreadValues({}, node), {
1177
+ props: encodeEmptyObjects(flatten2(stripSlots(node, config).props))
1178
+ });
1179
+ };
1180
+
1181
+ // lib/data/walk-app-state.ts
1182
+ function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
1183
+ var _a;
1184
+ let newZones = {};
1185
+ const newZoneIndex = {};
1186
+ const newNodeIndex = {};
1187
+ const processContent = (path, zoneCompound, content, zoneType, newId) => {
1188
+ var _a2;
1189
+ const [parentId] = zoneCompound.split(":");
1190
+ const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
1191
+ const [_2, zone] = zoneCompound.split(":");
1192
+ const newZoneCompound = `${newId || parentId}:${zone}`;
1193
+ const newContent2 = mappedContent.map(
1194
+ (zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
1195
+ );
1196
+ newZoneIndex[newZoneCompound] = {
1197
+ contentIds: newContent2.map((item) => item.props.id),
1198
+ type: zoneType
1199
+ };
1200
+ return [newZoneCompound, newContent2];
1201
+ };
1202
+ const processRelatedZones = (item, newId, initialPath) => {
1203
+ forRelatedZones(
1204
+ item,
1205
+ state.data,
1206
+ (relatedPath, relatedZoneCompound, relatedContent) => {
1207
+ const [zoneCompound, newContent2] = processContent(
1208
+ relatedPath,
1209
+ relatedZoneCompound,
1210
+ relatedContent,
1211
+ "dropzone",
1212
+ newId
1213
+ );
1214
+ newZones[zoneCompound] = newContent2;
1215
+ },
1216
+ initialPath
1217
+ );
1218
+ };
1219
+ const processItem = (item, path, index) => {
1220
+ const mappedItem = mapNodeOrSkip(item, path, index);
1221
+ if (!mappedItem) return item;
1222
+ const id = mappedItem.props.id;
1223
+ const newProps = __spreadProps(__spreadValues({}, mapFields(
1224
+ mappedItem,
1225
+ {
1226
+ slot: ({ value, parentId: parentId2, propPath }) => {
1227
+ const content = value;
1228
+ const zoneCompound = `${parentId2}:${propPath}`;
1229
+ const [_2, newContent2] = processContent(
1230
+ path,
1231
+ zoneCompound,
1232
+ content,
1233
+ "slot",
1234
+ parentId2
1235
+ );
1236
+ return newContent2;
1237
+ }
1238
+ },
1239
+ config
1240
+ ).props), {
1241
+ id
1242
+ });
1243
+ processRelatedZones(item, id, path);
1244
+ const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
1245
+ const thisZoneCompound = path[path.length - 1];
1246
+ const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
1247
+ newNodeIndex[id] = {
1248
+ data: newItem,
1249
+ flatData: flattenNode(newItem, config),
1250
+ path,
1251
+ parentId,
1252
+ zone
1253
+ };
1254
+ const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
1255
+ if (newProps.id === "root") {
1256
+ delete finalData["type"];
1257
+ delete finalData.props["id"];
1258
+ }
1259
+ return finalData;
1260
+ };
1261
+ const zones = state.data.zones || {};
1262
+ const [_, newContent] = processContent(
1263
+ [],
1264
+ rootDroppableId,
1265
+ state.data.content,
1266
+ "root"
1267
+ );
1268
+ const processedContent = newContent;
1269
+ const zonesAlreadyProcessed = Object.keys(newZones);
1270
+ Object.keys(zones || {}).forEach((zoneCompound) => {
1271
+ const [parentId] = zoneCompound.split(":");
1272
+ if (zonesAlreadyProcessed.includes(zoneCompound)) {
1273
+ return;
1274
+ }
1275
+ const [_2, newContent2] = processContent(
1276
+ [rootDroppableId],
1277
+ zoneCompound,
1278
+ zones[zoneCompound],
1279
+ "dropzone",
1280
+ parentId
1281
+ );
1282
+ newZones[zoneCompound] = newContent2;
1283
+ }, newZones);
1284
+ const processedRoot = processItem(
1285
+ {
1286
+ type: "root",
1287
+ props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
1288
+ },
1289
+ [],
1290
+ -1
1291
+ );
1292
+ const root = __spreadProps(__spreadValues({}, state.data.root), {
1293
+ props: processedRoot.props
1294
+ });
1295
+ return __spreadProps(__spreadValues({}, state), {
1296
+ data: {
1297
+ root,
1298
+ content: processedContent,
1299
+ zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
1300
+ },
1301
+ indexes: {
1302
+ nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
1303
+ zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
1304
+ }
1305
+ });
1306
+ }
1307
+
1308
+ // lib/migrate.ts
1309
+ var migrations = [
1310
+ // Migrate root to root.props
1311
+ (data) => {
1312
+ const rootProps = data.root.props || data.root;
1313
+ if (Object.keys(data.root).length > 0 && !data.root.props) {
1314
+ console.warn(
1315
+ "Migration applied: Root props moved from `root` to `root.props`."
1316
+ );
1317
+ return __spreadProps(__spreadValues({}, data), {
1318
+ root: {
1319
+ props: __spreadValues({}, rootProps)
1320
+ }
1321
+ });
1322
+ }
1323
+ return data;
1324
+ },
1325
+ // Migrate zones to slots
1326
+ (data, config, migrationOptions) => {
1327
+ var _a, _b;
1328
+ if (!config) return data;
1329
+ console.log("Migrating DropZones to slots...");
1330
+ const updatedItems = {};
1331
+ const appState = __spreadProps(__spreadValues({}, defaultAppState), { data });
1332
+ const { indexes } = walkAppState(appState, config);
1333
+ const deletedCompounds = [];
1334
+ walkAppState(appState, config, (content, zoneCompound, zoneType) => {
1335
+ var _a2, _b2, _c;
1336
+ if (zoneType === "dropzone") {
1337
+ const [id, slotName] = zoneCompound.split(":");
1338
+ const nodeData = indexes.nodes[id].data;
1339
+ const componentType = nodeData.type;
1340
+ const configForComponent = id === "root" ? config.root : config.components[componentType];
1341
+ if (((_b2 = (_a2 = configForComponent == null ? void 0 : configForComponent.fields) == null ? void 0 : _a2[slotName]) == null ? void 0 : _b2.type) === "slot") {
1342
+ updatedItems[id] = __spreadProps(__spreadValues({}, nodeData), {
1343
+ props: __spreadProps(__spreadValues(__spreadValues({}, nodeData.props), (_c = updatedItems[id]) == null ? void 0 : _c.props), {
1344
+ [slotName]: content
1345
+ })
1346
+ });
1347
+ deletedCompounds.push(zoneCompound);
1348
+ }
1349
+ return content;
1350
+ }
1351
+ return content;
1352
+ });
1353
+ const updated = walkAppState(
1354
+ appState,
1355
+ config,
1356
+ (content) => content,
1357
+ (item) => {
1358
+ var _a2;
1359
+ return (_a2 = updatedItems[item.props.id]) != null ? _a2 : item;
1360
+ }
1361
+ );
1362
+ deletedCompounds.forEach((zoneCompound) => {
1363
+ var _a2;
1364
+ const [_, propName] = zoneCompound.split(":");
1365
+ console.log(
1366
+ `\u2713 Success: Migrated "${zoneCompound}" from DropZone to slot field "${propName}"`
1367
+ );
1368
+ (_a2 = updated.data.zones) == null ? true : delete _a2[zoneCompound];
1369
+ });
1370
+ if (migrationOptions == null ? void 0 : migrationOptions.migrateDynamicZonesForComponent) {
1371
+ const unmigratedZonesGrouped = {};
1372
+ Object.keys((_a = updated.data.zones) != null ? _a : {}).forEach((zoneCompound) => {
1373
+ var _a2;
1374
+ const [componentId, propName] = zoneCompound.split(":");
1375
+ const content = (_a2 = updated.data.zones) == null ? void 0 : _a2[zoneCompound];
1376
+ if (!content) {
1377
+ return;
1378
+ }
1379
+ if (!unmigratedZonesGrouped[componentId]) {
1380
+ unmigratedZonesGrouped[componentId] = {};
1381
+ }
1382
+ if (!unmigratedZonesGrouped[componentId][propName]) {
1383
+ unmigratedZonesGrouped[componentId][propName] = content;
1384
+ }
1385
+ });
1386
+ Object.keys(unmigratedZonesGrouped).forEach((componentId) => {
1387
+ updated.data = walkTree(updated.data, config, (content) => {
1388
+ return content.map((child) => {
1389
+ var _a2;
1390
+ if (child.props.id !== componentId) {
1391
+ return child;
1392
+ }
1393
+ const migrateFn = (_a2 = migrationOptions == null ? void 0 : migrationOptions.migrateDynamicZonesForComponent) == null ? void 0 : _a2[child.type];
1394
+ if (!migrateFn) {
1395
+ return child;
1396
+ }
1397
+ const zones = unmigratedZonesGrouped[componentId];
1398
+ const migratedProps = migrateFn(child.props, zones);
1399
+ Object.keys(zones).forEach((propName) => {
1400
+ var _a3;
1401
+ const zoneCompound = `${componentId}:${propName}`;
1402
+ console.log(`\u2713 Success: Migrated "${zoneCompound}" DropZone`);
1403
+ (_a3 = updated.data.zones) == null ? true : delete _a3[zoneCompound];
1404
+ });
1405
+ return __spreadProps(__spreadValues({}, child), {
1406
+ props: migratedProps
1407
+ });
1408
+ });
1409
+ });
1410
+ });
1411
+ }
1412
+ Object.keys((_b = updated.data.zones) != null ? _b : {}).forEach((zoneCompound) => {
1413
+ const [_, propName] = zoneCompound.split(":");
1414
+ throw new Error(
1415
+ `Could not migrate DropZone "${zoneCompound}" to slot field. No slot exists with the name "${propName}".`
1416
+ );
1417
+ });
1418
+ delete updated.data.zones;
1419
+ return updated.data;
1420
+ }
1421
+ ];
1422
+ function migrate(data, config, migrationOptions) {
1423
+ return migrations == null ? void 0 : migrations.reduce(
1424
+ (acc, migration) => migration(acc, config, migrationOptions),
1425
+ data
1426
+ );
1427
+ }
1428
+ // Annotate the CommonJS export names for ESM import in node:
1429
+ 0 && (module.exports = {
1430
+ Render,
1431
+ migrate,
1432
+ resolveAllData,
1433
+ transformProps,
1434
+ walkTree
1435
+ });
1436
+ /*! Bundled license information:
1437
+
1438
+ classnames/index.js:
1439
+ (*!
1440
+ Copyright (c) 2018 Jed Watson.
1441
+ Licensed under the MIT License (MIT), see
1442
+ http://jedwatson.github.io/classnames
1443
+ *)
1444
+ */