@measured/puck 0.19.4-canary.fde74e8a → 0.20.0-canary.0708ce21

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.
@@ -0,0 +1,2859 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __objRest = (source, exclude) => {
25
+ var target = {};
26
+ for (var prop in source)
27
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
28
+ target[prop] = source[prop];
29
+ if (source != null && __getOwnPropSymbols)
30
+ for (var prop of __getOwnPropSymbols(source)) {
31
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
32
+ target[prop] = source[prop];
33
+ }
34
+ return target;
35
+ };
36
+ var __esm = (fn, res) => function __init() {
37
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
38
+ };
39
+ var __commonJS = (cb, mod) => function __require() {
40
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
41
+ };
42
+ var __copyProps = (to, from, except, desc) => {
43
+ if (from && typeof from === "object" || typeof from === "function") {
44
+ for (let key of __getOwnPropNames(from))
45
+ if (!__hasOwnProp.call(to, key) && key !== except)
46
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
47
+ }
48
+ return to;
49
+ };
50
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
51
+ // If the importer is in node compatibility mode or this is not an ESM
52
+ // file that has been converted to a CommonJS file using a Babel-
53
+ // compatible transform (i.e. "__esModule" has not been set), then set
54
+ // "default" to the CommonJS "module.exports" for node compatibility.
55
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
56
+ mod
57
+ ));
58
+ var __async = (__this, __arguments, generator) => {
59
+ return new Promise((resolve, reject) => {
60
+ var fulfilled = (value) => {
61
+ try {
62
+ step(generator.next(value));
63
+ } catch (e) {
64
+ reject(e);
65
+ }
66
+ };
67
+ var rejected = (value) => {
68
+ try {
69
+ step(generator.throw(value));
70
+ } catch (e) {
71
+ reject(e);
72
+ }
73
+ };
74
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
75
+ step((generator = generator.apply(__this, __arguments)).next());
76
+ });
77
+ };
78
+
79
+ // ../tsup-config/react-import.js
80
+ import React from "react";
81
+ var init_react_import = __esm({
82
+ "../tsup-config/react-import.js"() {
83
+ "use strict";
84
+ }
85
+ });
86
+
87
+ // ../../node_modules/classnames/index.js
88
+ var require_classnames = __commonJS({
89
+ "../../node_modules/classnames/index.js"(exports, module) {
90
+ "use strict";
91
+ init_react_import();
92
+ (function() {
93
+ "use strict";
94
+ var hasOwn = {}.hasOwnProperty;
95
+ function classNames() {
96
+ var classes = "";
97
+ for (var i = 0; i < arguments.length; i++) {
98
+ var arg = arguments[i];
99
+ if (arg) {
100
+ classes = appendClass(classes, parseValue(arg));
101
+ }
102
+ }
103
+ return classes;
104
+ }
105
+ function parseValue(arg) {
106
+ if (typeof arg === "string" || typeof arg === "number") {
107
+ return arg;
108
+ }
109
+ if (typeof arg !== "object") {
110
+ return "";
111
+ }
112
+ if (Array.isArray(arg)) {
113
+ return classNames.apply(null, arg);
114
+ }
115
+ if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
116
+ return arg.toString();
117
+ }
118
+ var classes = "";
119
+ for (var key in arg) {
120
+ if (hasOwn.call(arg, key) && arg[key]) {
121
+ classes = appendClass(classes, key);
122
+ }
123
+ }
124
+ return classes;
125
+ }
126
+ function appendClass(value, newClass) {
127
+ if (!newClass) {
128
+ return value;
129
+ }
130
+ if (value) {
131
+ return value + " " + newClass;
132
+ }
133
+ return value + newClass;
134
+ }
135
+ if (typeof module !== "undefined" && module.exports) {
136
+ classNames.default = classNames;
137
+ module.exports = classNames;
138
+ } else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
139
+ define("classnames", [], function() {
140
+ return classNames;
141
+ });
142
+ } else {
143
+ window.classNames = classNames;
144
+ }
145
+ })();
146
+ }
147
+ });
148
+
149
+ // lib/data/walk-tree.ts
150
+ init_react_import();
151
+
152
+ // lib/data/map-fields.ts
153
+ init_react_import();
154
+
155
+ // lib/data/default-slots.ts
156
+ init_react_import();
157
+ var defaultSlots = (value, fields) => Object.keys(fields).reduce(
158
+ (acc, fieldName) => fields[fieldName].type === "slot" ? __spreadValues({ [fieldName]: [] }, acc) : acc,
159
+ value
160
+ );
161
+
162
+ // lib/data/map-fields.ts
163
+ var isPromise = (v) => !!v && typeof v.then === "function";
164
+ var flatten = (values) => values.reduce((acc, item) => __spreadValues(__spreadValues({}, acc), item), {});
165
+ var containsPromise = (arr) => arr.some(isPromise);
166
+ var walkField = ({
167
+ value,
168
+ fields,
169
+ mappers,
170
+ propKey = "",
171
+ propPath = "",
172
+ id = "",
173
+ config,
174
+ recurseSlots = false
175
+ }) => {
176
+ var _a, _b, _c;
177
+ const fieldType = (_a = fields[propKey]) == null ? void 0 : _a.type;
178
+ const map = mappers[fieldType];
179
+ if (map && fieldType === "slot") {
180
+ const content = value || [];
181
+ const mappedContent = recurseSlots ? content.map((el) => {
182
+ var _a2;
183
+ const componentConfig = config.components[el.type];
184
+ if (!componentConfig) {
185
+ throw new Error(`Could not find component config for ${el.type}`);
186
+ }
187
+ const fields2 = (_a2 = componentConfig.fields) != null ? _a2 : {};
188
+ return walkField({
189
+ value: __spreadProps(__spreadValues({}, el), { props: defaultSlots(el.props, fields2) }),
190
+ fields: fields2,
191
+ mappers,
192
+ id: el.props.id,
193
+ config,
194
+ recurseSlots
195
+ });
196
+ }) : content;
197
+ if (containsPromise(mappedContent)) {
198
+ return Promise.all(mappedContent);
199
+ }
200
+ return map({
201
+ value: mappedContent,
202
+ parentId: id,
203
+ propName: propKey,
204
+ field: fields[propKey],
205
+ propPath
206
+ });
207
+ } else if (map && fields[propKey]) {
208
+ return map({
209
+ value,
210
+ parentId: id,
211
+ propName: propKey,
212
+ field: fields[propKey],
213
+ propPath
214
+ });
215
+ }
216
+ if (value && typeof value === "object") {
217
+ if (Array.isArray(value)) {
218
+ const arrayFields = ((_b = fields[propKey]) == null ? void 0 : _b.type) === "array" ? fields[propKey].arrayFields : null;
219
+ if (!arrayFields) return value;
220
+ const newValue = value.map(
221
+ (el, idx) => walkField({
222
+ value: el,
223
+ fields: arrayFields,
224
+ mappers,
225
+ propKey,
226
+ propPath: `${propPath}[${idx}]`,
227
+ id,
228
+ config,
229
+ recurseSlots
230
+ })
231
+ );
232
+ if (containsPromise(newValue)) {
233
+ return Promise.all(newValue);
234
+ }
235
+ return newValue;
236
+ } else if ("$$typeof" in value) {
237
+ return value;
238
+ } else {
239
+ const objectFields = ((_c = fields[propKey]) == null ? void 0 : _c.type) === "object" ? fields[propKey].objectFields : fields;
240
+ return walkObject({
241
+ value,
242
+ fields: objectFields,
243
+ mappers,
244
+ id,
245
+ getPropPath: (k) => `${propPath}.${k}`,
246
+ config,
247
+ recurseSlots
248
+ });
249
+ }
250
+ }
251
+ return value;
252
+ };
253
+ var walkObject = ({
254
+ value,
255
+ fields,
256
+ mappers,
257
+ id,
258
+ getPropPath,
259
+ config,
260
+ recurseSlots
261
+ }) => {
262
+ const newProps = Object.entries(value).map(([k, v]) => {
263
+ const opts = {
264
+ value: v,
265
+ fields,
266
+ mappers,
267
+ propKey: k,
268
+ propPath: getPropPath(k),
269
+ id,
270
+ config,
271
+ recurseSlots
272
+ };
273
+ const newValue = walkField(opts);
274
+ if (isPromise(newValue)) {
275
+ return newValue.then((resolvedValue) => ({
276
+ [k]: resolvedValue
277
+ }));
278
+ }
279
+ return {
280
+ [k]: newValue
281
+ };
282
+ }, {});
283
+ if (containsPromise(newProps)) {
284
+ return Promise.all(newProps).then(flatten);
285
+ }
286
+ return flatten(newProps);
287
+ };
288
+ function mapFields(item, mappers, config, recurseSlots = false) {
289
+ var _a, _b, _c, _d, _e;
290
+ const itemType = "type" in item ? item.type : "root";
291
+ const componentConfig = itemType === "root" ? config.root : (_a = config.components) == null ? void 0 : _a[itemType];
292
+ const newProps = walkObject({
293
+ value: defaultSlots((_b = item.props) != null ? _b : {}, (_c = componentConfig == null ? void 0 : componentConfig.fields) != null ? _c : {}),
294
+ fields: (_d = componentConfig == null ? void 0 : componentConfig.fields) != null ? _d : {},
295
+ mappers,
296
+ id: item.props ? (_e = item.props.id) != null ? _e : "root" : "root",
297
+ getPropPath: (k) => k,
298
+ config,
299
+ recurseSlots
300
+ });
301
+ if (isPromise(newProps)) {
302
+ return newProps.then((resolvedProps) => __spreadProps(__spreadValues({}, item), {
303
+ props: resolvedProps
304
+ }));
305
+ }
306
+ return __spreadProps(__spreadValues({}, item), {
307
+ props: newProps
308
+ });
309
+ }
310
+
311
+ // lib/data/walk-tree.ts
312
+ function walkTree(data, config, callbackFn) {
313
+ var _a, _b;
314
+ const walkItem = (item) => {
315
+ return mapFields(
316
+ item,
317
+ {
318
+ slot: ({ value, parentId, propName }) => {
319
+ var _a2;
320
+ const content = value;
321
+ return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
322
+ }
323
+ },
324
+ config,
325
+ true
326
+ );
327
+ };
328
+ if ("props" in data) {
329
+ return walkItem(data);
330
+ }
331
+ const _data = data;
332
+ const zones = (_a = _data.zones) != null ? _a : {};
333
+ const mappedContent = _data.content.map(walkItem);
334
+ return {
335
+ root: walkItem(_data.root),
336
+ content: (_b = callbackFn(mappedContent, {
337
+ parentId: "root",
338
+ propName: "default-zone"
339
+ })) != null ? _b : mappedContent,
340
+ zones: Object.keys(zones).reduce(
341
+ (acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
342
+ [zoneCompound]: zones[zoneCompound].map(walkItem)
343
+ }),
344
+ {}
345
+ )
346
+ };
347
+ }
348
+
349
+ // lib/overlay-portal/index.tsx
350
+ init_react_import();
351
+ var registerOverlayPortal = (el, opts = {}) => {
352
+ if (!el) return;
353
+ const { disableDrag = false, disableDragOnFocus = true } = opts;
354
+ const stopPropagation = (e) => {
355
+ e.stopPropagation();
356
+ };
357
+ el.addEventListener("mouseover", stopPropagation, {
358
+ capture: true
359
+ });
360
+ const onFocus = () => {
361
+ setTimeout(() => {
362
+ el.addEventListener("pointerdown", stopPropagation, {
363
+ capture: true
364
+ });
365
+ }, 200);
366
+ };
367
+ const onBlur = () => {
368
+ el.removeEventListener("pointerdown", stopPropagation, {
369
+ capture: true
370
+ });
371
+ };
372
+ if (disableDragOnFocus) {
373
+ el.addEventListener("focus", onFocus, { capture: true });
374
+ el.addEventListener("blur", onBlur, { capture: true });
375
+ } else if (disableDrag) {
376
+ el.addEventListener("pointerdown", stopPropagation, {
377
+ capture: true
378
+ });
379
+ }
380
+ el.setAttribute("data-puck-overlay-portal", "true");
381
+ return () => {
382
+ el.removeEventListener("mouseover", stopPropagation, {
383
+ capture: true
384
+ });
385
+ if (disableDragOnFocus) {
386
+ el.removeEventListener("focus", onFocus, { capture: true });
387
+ el.removeEventListener("blur", onFocus, { capture: true });
388
+ } else if (disableDrag) {
389
+ el.removeEventListener("pointerdown", stopPropagation, {
390
+ capture: true
391
+ });
392
+ }
393
+ el.removeAttribute("data-puck-overlay-portal");
394
+ };
395
+ };
396
+
397
+ // lib/data/set-deep.ts
398
+ init_react_import();
399
+ function setDeep(node, path, newVal) {
400
+ const parts = path.split(".");
401
+ const newNode = __spreadValues({}, node);
402
+ let cur = newNode;
403
+ for (let i = 0; i < parts.length; i++) {
404
+ const [prop, idxStr] = parts[i].replace("]", "").split("[");
405
+ const isLast = i === parts.length - 1;
406
+ if (idxStr !== void 0) {
407
+ if (!Array.isArray(cur[prop])) {
408
+ cur[prop] = [];
409
+ }
410
+ const idx = Number(idxStr);
411
+ if (isLast) {
412
+ cur[prop][idx] = newVal;
413
+ continue;
414
+ }
415
+ if (cur[prop][idx] === void 0) cur[prop][idx] = {};
416
+ cur = cur[prop][idx];
417
+ continue;
418
+ }
419
+ if (isLast) {
420
+ cur[prop] = newVal;
421
+ continue;
422
+ }
423
+ if (cur[prop] === void 0) {
424
+ cur[prop] = {};
425
+ }
426
+ cur = cur[prop];
427
+ }
428
+ return __spreadValues(__spreadValues({}, node), newNode);
429
+ }
430
+
431
+ // components/ServerRender/index.tsx
432
+ init_react_import();
433
+
434
+ // lib/root-droppable-id.ts
435
+ init_react_import();
436
+ var rootAreaId = "root";
437
+ var rootZone = "default-zone";
438
+ var rootDroppableId = `${rootAreaId}:${rootZone}`;
439
+
440
+ // lib/data/setup-zone.ts
441
+ init_react_import();
442
+ var setupZone = (data, zoneKey) => {
443
+ if (zoneKey === rootDroppableId) {
444
+ return data;
445
+ }
446
+ const newData = __spreadProps(__spreadValues({}, data), {
447
+ zones: data.zones ? __spreadValues({}, data.zones) : {}
448
+ });
449
+ newData.zones[zoneKey] = newData.zones[zoneKey] || [];
450
+ return newData;
451
+ };
452
+
453
+ // lib/use-slots.tsx
454
+ init_react_import();
455
+
456
+ // lib/field-transforms/use-field-transforms.tsx
457
+ init_react_import();
458
+ import { useMemo } from "react";
459
+ function useFieldTransforms(config, item, transforms, readOnly, forceReadOnly) {
460
+ const mappers = useMemo(() => {
461
+ return Object.keys(transforms).reduce((acc, _fieldType) => {
462
+ const fieldType = _fieldType;
463
+ return __spreadProps(__spreadValues({}, acc), {
464
+ [fieldType]: (_a) => {
465
+ var _b = _a, {
466
+ parentId
467
+ } = _b, params = __objRest(_b, [
468
+ "parentId"
469
+ ]);
470
+ const wildcardPath = params.propPath.replace(/\[\d+\]/g, "[*]");
471
+ const isReadOnly = (readOnly == null ? void 0 : readOnly[params.propPath]) || (readOnly == null ? void 0 : readOnly[wildcardPath]) || forceReadOnly || false;
472
+ const fn = transforms[fieldType];
473
+ return fn == null ? void 0 : fn(__spreadProps(__spreadValues({}, params), {
474
+ isReadOnly,
475
+ componentId: parentId
476
+ }));
477
+ }
478
+ });
479
+ }, {});
480
+ }, [transforms, readOnly, forceReadOnly]);
481
+ const transformedProps = useMemo(() => {
482
+ const mapped = mapFields(item, mappers, config).props;
483
+ return mapped;
484
+ }, [config, item, mappers]);
485
+ const mergedProps = useMemo(
486
+ () => __spreadValues(__spreadValues({}, item.props), transformedProps),
487
+ [item.props, transformedProps]
488
+ );
489
+ return mergedProps;
490
+ }
491
+
492
+ // lib/field-transforms/default-transforms.tsx
493
+ init_react_import();
494
+
495
+ // components/InlineTextField/index.tsx
496
+ init_react_import();
497
+ import { memo, useEffect as useEffect5, useRef, useState } from "react";
498
+
499
+ // store/index.ts
500
+ init_react_import();
501
+
502
+ // reducer/index.ts
503
+ init_react_import();
504
+
505
+ // reducer/actions/set.ts
506
+ init_react_import();
507
+
508
+ // lib/data/walk-app-state.ts
509
+ init_react_import();
510
+
511
+ // lib/data/for-related-zones.ts
512
+ init_react_import();
513
+
514
+ // lib/get-zone-id.ts
515
+ init_react_import();
516
+ var getZoneId = (zoneCompound) => {
517
+ if (!zoneCompound) {
518
+ return [];
519
+ }
520
+ if (zoneCompound && zoneCompound.indexOf(":") > -1) {
521
+ return zoneCompound.split(":");
522
+ }
523
+ return [rootDroppableId, zoneCompound];
524
+ };
525
+
526
+ // lib/data/for-related-zones.ts
527
+ function forRelatedZones(item, data, cb, path = []) {
528
+ Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
529
+ const [parentId] = getZoneId(zoneCompound);
530
+ if (parentId === item.props.id) {
531
+ cb(path, zoneCompound, content);
532
+ }
533
+ });
534
+ }
535
+
536
+ // lib/data/flatten-node.ts
537
+ init_react_import();
538
+ import flat from "flat";
539
+
540
+ // lib/data/strip-slots.ts
541
+ init_react_import();
542
+ var stripSlots = (data, config) => {
543
+ return mapFields(data, { slot: () => null }, config);
544
+ };
545
+
546
+ // lib/data/flatten-node.ts
547
+ var { flatten: flatten2, unflatten } = flat;
548
+ var flattenNode = (node, config) => {
549
+ return __spreadProps(__spreadValues({}, node), {
550
+ props: flatten2(stripSlots(node, config).props)
551
+ });
552
+ };
553
+ var expandNode = (node) => {
554
+ const props = unflatten(node.props);
555
+ return __spreadProps(__spreadValues({}, node), {
556
+ props
557
+ });
558
+ };
559
+
560
+ // lib/data/walk-app-state.ts
561
+ function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
562
+ var _a;
563
+ let newZones = {};
564
+ const newZoneIndex = {};
565
+ const newNodeIndex = {};
566
+ const processContent = (path, zoneCompound, content, zoneType, newId) => {
567
+ var _a2;
568
+ const [parentId] = zoneCompound.split(":");
569
+ const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
570
+ const [_2, zone] = zoneCompound.split(":");
571
+ const newZoneCompound = `${newId || parentId}:${zone}`;
572
+ const newContent2 = mappedContent.map(
573
+ (zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
574
+ );
575
+ newZoneIndex[newZoneCompound] = {
576
+ contentIds: newContent2.map((item) => item.props.id),
577
+ type: zoneType
578
+ };
579
+ return [newZoneCompound, newContent2];
580
+ };
581
+ const processRelatedZones = (item, newId, initialPath) => {
582
+ forRelatedZones(
583
+ item,
584
+ state.data,
585
+ (relatedPath, relatedZoneCompound, relatedContent) => {
586
+ const [zoneCompound, newContent2] = processContent(
587
+ relatedPath,
588
+ relatedZoneCompound,
589
+ relatedContent,
590
+ "dropzone",
591
+ newId
592
+ );
593
+ newZones[zoneCompound] = newContent2;
594
+ },
595
+ initialPath
596
+ );
597
+ };
598
+ const processItem = (item, path, index) => {
599
+ const mappedItem = mapNodeOrSkip(item, path, index);
600
+ if (!mappedItem) return item;
601
+ const id = mappedItem.props.id;
602
+ const newProps = __spreadProps(__spreadValues({}, mapFields(
603
+ mappedItem,
604
+ {
605
+ slot: ({ value, parentId: parentId2, propPath }) => {
606
+ const content = value;
607
+ const zoneCompound = `${parentId2}:${propPath}`;
608
+ const [_2, newContent2] = processContent(
609
+ path,
610
+ zoneCompound,
611
+ content,
612
+ "slot",
613
+ parentId2
614
+ );
615
+ return newContent2;
616
+ }
617
+ },
618
+ config
619
+ ).props), {
620
+ id
621
+ });
622
+ processRelatedZones(item, id, path);
623
+ const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
624
+ const thisZoneCompound = path[path.length - 1];
625
+ const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
626
+ newNodeIndex[id] = {
627
+ data: newItem,
628
+ flatData: flattenNode(newItem, config),
629
+ path,
630
+ parentId,
631
+ zone
632
+ };
633
+ const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
634
+ if (newProps.id === "root") {
635
+ delete finalData["type"];
636
+ delete finalData.props["id"];
637
+ }
638
+ return finalData;
639
+ };
640
+ const zones = state.data.zones || {};
641
+ const [_, newContent] = processContent(
642
+ [],
643
+ rootDroppableId,
644
+ state.data.content,
645
+ "root"
646
+ );
647
+ const processedContent = newContent;
648
+ const zonesAlreadyProcessed = Object.keys(newZones);
649
+ Object.keys(zones || {}).forEach((zoneCompound) => {
650
+ const [parentId] = zoneCompound.split(":");
651
+ if (zonesAlreadyProcessed.includes(zoneCompound)) {
652
+ return;
653
+ }
654
+ const [_2, newContent2] = processContent(
655
+ [rootDroppableId],
656
+ zoneCompound,
657
+ zones[zoneCompound],
658
+ "dropzone",
659
+ parentId
660
+ );
661
+ newZones[zoneCompound] = newContent2;
662
+ }, newZones);
663
+ const processedRoot = processItem(
664
+ {
665
+ type: "root",
666
+ props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
667
+ },
668
+ [],
669
+ -1
670
+ );
671
+ const root = __spreadProps(__spreadValues({}, state.data.root), {
672
+ props: processedRoot.props
673
+ });
674
+ return __spreadProps(__spreadValues({}, state), {
675
+ data: {
676
+ root,
677
+ content: processedContent,
678
+ zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
679
+ },
680
+ indexes: {
681
+ nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
682
+ zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
683
+ }
684
+ });
685
+ }
686
+
687
+ // reducer/actions/set.ts
688
+ var setAction = (state, action, appStore) => {
689
+ if (typeof action.state === "object") {
690
+ const newState = __spreadValues(__spreadValues({}, state), action.state);
691
+ if (action.state.indexes) {
692
+ return newState;
693
+ }
694
+ console.warn(
695
+ "`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
696
+ );
697
+ return walkAppState(newState, appStore.config);
698
+ }
699
+ return __spreadValues(__spreadValues({}, state), action.state(state));
700
+ };
701
+
702
+ // reducer/actions/insert.ts
703
+ init_react_import();
704
+
705
+ // lib/data/insert.ts
706
+ init_react_import();
707
+ var insert = (list, index, item) => {
708
+ const result = Array.from(list || []);
709
+ result.splice(index, 0, item);
710
+ return result;
711
+ };
712
+
713
+ // lib/generate-id.ts
714
+ init_react_import();
715
+ import { v4 as uuidv4 } from "uuid";
716
+ var generateId = (type) => type ? `${type}-${uuidv4()}` : uuidv4();
717
+
718
+ // lib/data/get-ids-for-parent.ts
719
+ init_react_import();
720
+ var getIdsForParent = (zoneCompound, state) => {
721
+ const [parentId] = zoneCompound.split(":");
722
+ const node = state.indexes.nodes[parentId];
723
+ return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
724
+ };
725
+
726
+ // lib/data/populate-ids.ts
727
+ init_react_import();
728
+ var populateIds = (data, config, override = false) => {
729
+ const id = generateId(data.type);
730
+ return walkTree(
731
+ __spreadProps(__spreadValues({}, data), {
732
+ props: override ? __spreadProps(__spreadValues({}, data.props), { id }) : __spreadValues({}, data.props)
733
+ }),
734
+ config,
735
+ (contents) => contents.map((item) => {
736
+ const id2 = generateId(item.type);
737
+ return __spreadProps(__spreadValues({}, item), {
738
+ props: override ? __spreadProps(__spreadValues({}, item.props), { id: id2 }) : __spreadValues({ id: id2 }, item.props)
739
+ });
740
+ })
741
+ );
742
+ };
743
+
744
+ // reducer/actions/insert.ts
745
+ function insertAction(state, action, appStore) {
746
+ const id = action.id || generateId(action.componentType);
747
+ const emptyComponentData = populateIds(
748
+ {
749
+ type: action.componentType,
750
+ props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
751
+ id
752
+ })
753
+ },
754
+ appStore.config
755
+ );
756
+ const [parentId] = action.destinationZone.split(":");
757
+ const idsInPath = getIdsForParent(action.destinationZone, state);
758
+ return walkAppState(
759
+ state,
760
+ appStore.config,
761
+ (content, zoneCompound) => {
762
+ if (zoneCompound === action.destinationZone) {
763
+ return insert(
764
+ content || [],
765
+ action.destinationIndex,
766
+ emptyComponentData
767
+ );
768
+ }
769
+ return content;
770
+ },
771
+ (childItem, path) => {
772
+ if (childItem.props.id === id || childItem.props.id === parentId) {
773
+ return childItem;
774
+ } else if (idsInPath.includes(childItem.props.id)) {
775
+ return childItem;
776
+ } else if (path.includes(action.destinationZone)) {
777
+ return childItem;
778
+ }
779
+ return null;
780
+ }
781
+ );
782
+ }
783
+
784
+ // reducer/actions/replace.ts
785
+ init_react_import();
786
+ var replaceAction = (state, action, appStore) => {
787
+ const [parentId] = action.destinationZone.split(":");
788
+ const idsInPath = getIdsForParent(action.destinationZone, state);
789
+ const originalId = state.indexes.zones[action.destinationZone].contentIds[action.destinationIndex];
790
+ const idChanged = originalId !== action.data.props.id;
791
+ if (idChanged) {
792
+ throw new Error(
793
+ `Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
794
+ );
795
+ }
796
+ const newSlotIds = [];
797
+ const data = walkTree(action.data, appStore.config, (contents, opts) => {
798
+ newSlotIds.push(`${opts.parentId}:${opts.propName}`);
799
+ return contents.map((item) => {
800
+ const id = generateId(item.type);
801
+ return __spreadProps(__spreadValues({}, item), {
802
+ props: __spreadValues({ id }, item.props)
803
+ });
804
+ });
805
+ });
806
+ const stateWithDeepSlotsRemoved = __spreadValues({}, state);
807
+ Object.keys(state.indexes.zones).forEach((zoneCompound) => {
808
+ const id = zoneCompound.split(":")[0];
809
+ if (id === originalId) {
810
+ if (!newSlotIds.includes(zoneCompound)) {
811
+ delete stateWithDeepSlotsRemoved.indexes.zones[zoneCompound];
812
+ }
813
+ }
814
+ });
815
+ return walkAppState(
816
+ stateWithDeepSlotsRemoved,
817
+ appStore.config,
818
+ (content, zoneCompound) => {
819
+ const newContent = [...content];
820
+ if (zoneCompound === action.destinationZone) {
821
+ newContent[action.destinationIndex] = data;
822
+ }
823
+ return newContent;
824
+ },
825
+ (childItem, path) => {
826
+ const pathIds = path.map((p) => p.split(":")[0]);
827
+ if (childItem.props.id === data.props.id) {
828
+ return data;
829
+ } else if (childItem.props.id === parentId) {
830
+ return childItem;
831
+ } else if (idsInPath.indexOf(childItem.props.id) > -1) {
832
+ return childItem;
833
+ } else if (pathIds.indexOf(data.props.id) > -1) {
834
+ return childItem;
835
+ }
836
+ return null;
837
+ }
838
+ );
839
+ };
840
+
841
+ // reducer/actions/replace-root.ts
842
+ init_react_import();
843
+ var replaceRootAction = (state, action, appStore) => {
844
+ return walkAppState(
845
+ state,
846
+ appStore.config,
847
+ (content) => content,
848
+ (childItem) => {
849
+ if (childItem.props.id === "root") {
850
+ return __spreadProps(__spreadValues({}, childItem), {
851
+ props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
852
+ readOnly: action.root.readOnly
853
+ });
854
+ }
855
+ return childItem;
856
+ }
857
+ );
858
+ };
859
+
860
+ // reducer/actions/duplicate.ts
861
+ init_react_import();
862
+
863
+ // lib/data/get-item.ts
864
+ init_react_import();
865
+ function getItem(selector, state) {
866
+ var _a, _b;
867
+ const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
868
+ return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
869
+ }
870
+
871
+ // reducer/actions/duplicate.ts
872
+ function duplicateAction(state, action, appStore) {
873
+ const item = getItem(
874
+ { index: action.sourceIndex, zone: action.sourceZone },
875
+ state
876
+ );
877
+ const idsInPath = getIdsForParent(action.sourceZone, state);
878
+ const newItem = __spreadProps(__spreadValues({}, item), {
879
+ props: __spreadProps(__spreadValues({}, item.props), {
880
+ id: generateId(item.type)
881
+ })
882
+ });
883
+ const modified = walkAppState(
884
+ state,
885
+ appStore.config,
886
+ (content, zoneCompound) => {
887
+ if (zoneCompound === action.sourceZone) {
888
+ return insert(content, action.sourceIndex + 1, item);
889
+ }
890
+ return content;
891
+ },
892
+ (childItem, path, index) => {
893
+ const zoneCompound = path[path.length - 1];
894
+ const parents = path.map((p) => p.split(":")[0]);
895
+ if (parents.indexOf(newItem.props.id) > -1) {
896
+ return __spreadProps(__spreadValues({}, childItem), {
897
+ props: __spreadProps(__spreadValues({}, childItem.props), {
898
+ id: generateId(childItem.type)
899
+ })
900
+ });
901
+ }
902
+ if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
903
+ return newItem;
904
+ }
905
+ const [sourceZoneParent] = action.sourceZone.split(":");
906
+ if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
907
+ return childItem;
908
+ }
909
+ return null;
910
+ }
911
+ );
912
+ return __spreadProps(__spreadValues({}, modified), {
913
+ ui: __spreadProps(__spreadValues({}, modified.ui), {
914
+ itemSelector: {
915
+ index: action.sourceIndex + 1,
916
+ zone: action.sourceZone
917
+ }
918
+ })
919
+ });
920
+ }
921
+
922
+ // reducer/actions/reorder.ts
923
+ init_react_import();
924
+
925
+ // reducer/actions/move.ts
926
+ init_react_import();
927
+
928
+ // lib/data/remove.ts
929
+ init_react_import();
930
+ var remove = (list, index) => {
931
+ const result = Array.from(list);
932
+ result.splice(index, 1);
933
+ return result;
934
+ };
935
+
936
+ // reducer/actions/move.ts
937
+ var moveAction = (state, action, appStore) => {
938
+ if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
939
+ return state;
940
+ }
941
+ const item = getItem(
942
+ { zone: action.sourceZone, index: action.sourceIndex },
943
+ state
944
+ );
945
+ if (!item) return state;
946
+ const idsInSourcePath = getIdsForParent(action.sourceZone, state);
947
+ const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
948
+ return walkAppState(
949
+ state,
950
+ appStore.config,
951
+ (content, zoneCompound) => {
952
+ if (zoneCompound === action.sourceZone && zoneCompound === action.destinationZone) {
953
+ return insert(
954
+ remove(content, action.sourceIndex),
955
+ action.destinationIndex,
956
+ item
957
+ );
958
+ } else if (zoneCompound === action.sourceZone) {
959
+ return remove(content, action.sourceIndex);
960
+ } else if (zoneCompound === action.destinationZone) {
961
+ return insert(content, action.destinationIndex, item);
962
+ }
963
+ return content;
964
+ },
965
+ (childItem, path) => {
966
+ const [sourceZoneParent] = action.sourceZone.split(":");
967
+ const [destinationZoneParent] = action.destinationZone.split(":");
968
+ const childId = childItem.props.id;
969
+ if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1 || path.includes(action.destinationZone)) {
970
+ return childItem;
971
+ }
972
+ return null;
973
+ }
974
+ );
975
+ };
976
+
977
+ // reducer/actions/reorder.ts
978
+ var reorderAction = (state, action, appStore) => {
979
+ return moveAction(
980
+ state,
981
+ {
982
+ type: "move",
983
+ sourceIndex: action.sourceIndex,
984
+ sourceZone: action.destinationZone,
985
+ destinationIndex: action.destinationIndex,
986
+ destinationZone: action.destinationZone
987
+ },
988
+ appStore
989
+ );
990
+ };
991
+
992
+ // reducer/actions/remove.ts
993
+ init_react_import();
994
+ var removeAction = (state, action, appStore) => {
995
+ const item = getItem({ index: action.index, zone: action.zone }, state);
996
+ const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
997
+ (acc, [nodeId, nodeData]) => {
998
+ const pathIds = nodeData.path.map((p) => p.split(":")[0]);
999
+ if (pathIds.includes(item.props.id)) {
1000
+ return [...acc, nodeId];
1001
+ }
1002
+ return acc;
1003
+ },
1004
+ [item.props.id]
1005
+ );
1006
+ const newState = walkAppState(
1007
+ state,
1008
+ appStore.config,
1009
+ (content, zoneCompound) => {
1010
+ if (zoneCompound === action.zone) {
1011
+ return remove(content, action.index);
1012
+ }
1013
+ return content;
1014
+ }
1015
+ );
1016
+ Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
1017
+ const parentId = zoneCompound.split(":")[0];
1018
+ if (nodesToDelete.includes(parentId) && newState.data.zones) {
1019
+ delete newState.data.zones[zoneCompound];
1020
+ }
1021
+ });
1022
+ Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
1023
+ const parentId = zoneCompound.split(":")[0];
1024
+ if (nodesToDelete.includes(parentId)) {
1025
+ delete newState.indexes.zones[zoneCompound];
1026
+ }
1027
+ });
1028
+ nodesToDelete.forEach((id) => {
1029
+ delete newState.indexes.nodes[id];
1030
+ });
1031
+ return newState;
1032
+ };
1033
+
1034
+ // reducer/actions/register-zone.ts
1035
+ init_react_import();
1036
+ var zoneCache = {};
1037
+ function registerZoneAction(state, action) {
1038
+ if (zoneCache[action.zone]) {
1039
+ return __spreadProps(__spreadValues({}, state), {
1040
+ data: __spreadProps(__spreadValues({}, state.data), {
1041
+ zones: __spreadProps(__spreadValues({}, state.data.zones), {
1042
+ [action.zone]: zoneCache[action.zone]
1043
+ })
1044
+ }),
1045
+ indexes: __spreadProps(__spreadValues({}, state.indexes), {
1046
+ zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
1047
+ [action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
1048
+ contentIds: zoneCache[action.zone].map((item) => item.props.id),
1049
+ type: "dropzone"
1050
+ })
1051
+ })
1052
+ })
1053
+ });
1054
+ }
1055
+ return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
1056
+ }
1057
+ function unregisterZoneAction(state, action) {
1058
+ const _zones = __spreadValues({}, state.data.zones || {});
1059
+ const zoneIndex = __spreadValues({}, state.indexes.zones || {});
1060
+ if (_zones[action.zone]) {
1061
+ zoneCache[action.zone] = _zones[action.zone];
1062
+ delete _zones[action.zone];
1063
+ }
1064
+ delete zoneIndex[action.zone];
1065
+ return __spreadProps(__spreadValues({}, state), {
1066
+ data: __spreadProps(__spreadValues({}, state.data), {
1067
+ zones: _zones
1068
+ }),
1069
+ indexes: __spreadProps(__spreadValues({}, state.indexes), {
1070
+ zones: zoneIndex
1071
+ })
1072
+ });
1073
+ }
1074
+
1075
+ // reducer/actions/set-data.ts
1076
+ init_react_import();
1077
+ var setDataAction = (state, action, appStore) => {
1078
+ if (typeof action.data === "object") {
1079
+ console.warn(
1080
+ "`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
1081
+ );
1082
+ return walkAppState(
1083
+ __spreadProps(__spreadValues({}, state), {
1084
+ data: __spreadValues(__spreadValues({}, state.data), action.data)
1085
+ }),
1086
+ appStore.config
1087
+ );
1088
+ }
1089
+ return walkAppState(
1090
+ __spreadProps(__spreadValues({}, state), {
1091
+ data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
1092
+ }),
1093
+ appStore.config
1094
+ );
1095
+ };
1096
+
1097
+ // reducer/actions/set-ui.ts
1098
+ init_react_import();
1099
+ var setUiAction = (state, action) => {
1100
+ if (typeof action.ui === "object") {
1101
+ return __spreadProps(__spreadValues({}, state), {
1102
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
1103
+ });
1104
+ }
1105
+ return __spreadProps(__spreadValues({}, state), {
1106
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
1107
+ });
1108
+ };
1109
+
1110
+ // lib/data/make-state-public.ts
1111
+ init_react_import();
1112
+ var makeStatePublic = (state) => {
1113
+ const { data, ui } = state;
1114
+ return { data, ui };
1115
+ };
1116
+
1117
+ // reducer/actions.tsx
1118
+ init_react_import();
1119
+
1120
+ // reducer/index.ts
1121
+ function storeInterceptor(reducer, record, onAction) {
1122
+ return (state, action) => {
1123
+ const newAppState = reducer(state, action);
1124
+ const isValidType = ![
1125
+ "registerZone",
1126
+ "unregisterZone",
1127
+ "setData",
1128
+ "setUi",
1129
+ "set"
1130
+ ].includes(action.type);
1131
+ if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
1132
+ if (record) record(newAppState);
1133
+ }
1134
+ onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
1135
+ return newAppState;
1136
+ };
1137
+ }
1138
+ function createReducer({
1139
+ record,
1140
+ onAction,
1141
+ appStore
1142
+ }) {
1143
+ return storeInterceptor(
1144
+ (state, action) => {
1145
+ if (action.type === "set") {
1146
+ return setAction(state, action, appStore);
1147
+ }
1148
+ if (action.type === "insert") {
1149
+ return insertAction(state, action, appStore);
1150
+ }
1151
+ if (action.type === "replace") {
1152
+ return replaceAction(state, action, appStore);
1153
+ }
1154
+ if (action.type === "replaceRoot") {
1155
+ return replaceRootAction(state, action, appStore);
1156
+ }
1157
+ if (action.type === "duplicate") {
1158
+ return duplicateAction(state, action, appStore);
1159
+ }
1160
+ if (action.type === "reorder") {
1161
+ return reorderAction(state, action, appStore);
1162
+ }
1163
+ if (action.type === "move") {
1164
+ return moveAction(state, action, appStore);
1165
+ }
1166
+ if (action.type === "remove") {
1167
+ return removeAction(state, action, appStore);
1168
+ }
1169
+ if (action.type === "registerZone") {
1170
+ return registerZoneAction(state, action);
1171
+ }
1172
+ if (action.type === "unregisterZone") {
1173
+ return unregisterZoneAction(state, action);
1174
+ }
1175
+ if (action.type === "setData") {
1176
+ return setDataAction(state, action, appStore);
1177
+ }
1178
+ if (action.type === "setUi") {
1179
+ return setUiAction(state, action);
1180
+ }
1181
+ return state;
1182
+ },
1183
+ record,
1184
+ onAction
1185
+ );
1186
+ }
1187
+
1188
+ // components/ViewportControls/default-viewports.ts
1189
+ init_react_import();
1190
+ var defaultViewports = [
1191
+ { width: 360, height: "auto", icon: "Smartphone", label: "Small" },
1192
+ { width: 768, height: "auto", icon: "Tablet", label: "Medium" },
1193
+ { width: 1280, height: "auto", icon: "Monitor", label: "Large" }
1194
+ ];
1195
+
1196
+ // store/index.ts
1197
+ import { create as create2, useStore } from "zustand";
1198
+ import { subscribeWithSelector as subscribeWithSelector2 } from "zustand/middleware";
1199
+ import { createContext, useContext } from "react";
1200
+
1201
+ // store/slices/history.ts
1202
+ init_react_import();
1203
+ import { useEffect as useEffect2 } from "react";
1204
+
1205
+ // lib/use-hotkey.ts
1206
+ init_react_import();
1207
+ import { useEffect } from "react";
1208
+ import { create } from "zustand";
1209
+ import { subscribeWithSelector } from "zustand/middleware";
1210
+ var keyCodeMap = {
1211
+ ControlLeft: "ctrl",
1212
+ ControlRight: "ctrl",
1213
+ MetaLeft: "meta",
1214
+ MetaRight: "meta",
1215
+ ShiftLeft: "shift",
1216
+ ShiftRight: "shift",
1217
+ KeyA: "a",
1218
+ KeyB: "b",
1219
+ KeyC: "c",
1220
+ KeyD: "d",
1221
+ KeyE: "e",
1222
+ KeyF: "f",
1223
+ KeyG: "g",
1224
+ KeyH: "h",
1225
+ KeyI: "i",
1226
+ KeyJ: "j",
1227
+ KeyK: "k",
1228
+ KeyL: "l",
1229
+ KeyM: "m",
1230
+ KeyN: "n",
1231
+ KeyO: "o",
1232
+ KeyP: "p",
1233
+ KeyQ: "q",
1234
+ KeyR: "r",
1235
+ KeyS: "s",
1236
+ KeyT: "t",
1237
+ KeyU: "u",
1238
+ KeyV: "v",
1239
+ KeyW: "w",
1240
+ KeyX: "x",
1241
+ KeyY: "y",
1242
+ KeyZ: "z"
1243
+ };
1244
+ var useHotkeyStore = create()(
1245
+ subscribeWithSelector((set) => ({
1246
+ held: {},
1247
+ hold: (key) => set((s) => s.held[key] ? s : { held: __spreadProps(__spreadValues({}, s.held), { [key]: true }) }),
1248
+ release: (key) => set((s) => s.held[key] ? { held: __spreadProps(__spreadValues({}, s.held), { [key]: false }) } : s),
1249
+ reset: (held = {}) => set(() => ({ held })),
1250
+ triggers: {}
1251
+ }))
1252
+ );
1253
+ var monitorHotkeys = (doc) => {
1254
+ const onKeyDown = (e) => {
1255
+ const key = keyCodeMap[e.code];
1256
+ if (key) {
1257
+ useHotkeyStore.getState().hold(key);
1258
+ const { held, triggers } = useHotkeyStore.getState();
1259
+ Object.values(triggers).forEach(({ combo, cb }) => {
1260
+ const conditionMet = Object.entries(combo).every(
1261
+ ([key2, value]) => value === !!held[key2]
1262
+ ) && Object.entries(held).every(
1263
+ ([key2, value]) => value === !!combo[key2]
1264
+ );
1265
+ if (conditionMet) {
1266
+ e.preventDefault();
1267
+ cb();
1268
+ }
1269
+ });
1270
+ if (key !== "meta" && key !== "ctrl" && key !== "shift") {
1271
+ useHotkeyStore.getState().release(key);
1272
+ }
1273
+ }
1274
+ };
1275
+ const onKeyUp = (e) => {
1276
+ const key = keyCodeMap[e.code];
1277
+ if (key) {
1278
+ if (key === "meta") {
1279
+ useHotkeyStore.getState().reset();
1280
+ } else {
1281
+ useHotkeyStore.getState().release(key);
1282
+ }
1283
+ }
1284
+ };
1285
+ const onVisibilityChanged = (e) => {
1286
+ if (document.visibilityState === "hidden") {
1287
+ useHotkeyStore.getState().reset();
1288
+ }
1289
+ };
1290
+ doc.addEventListener("keydown", onKeyDown);
1291
+ doc.addEventListener("keyup", onKeyUp);
1292
+ doc.addEventListener("visibilitychange", onVisibilityChanged);
1293
+ return () => {
1294
+ doc.removeEventListener("keydown", onKeyDown);
1295
+ doc.removeEventListener("keyup", onKeyUp);
1296
+ doc.removeEventListener("visibilitychange", onVisibilityChanged);
1297
+ };
1298
+ };
1299
+ var useMonitorHotkeys = () => {
1300
+ useEffect(() => monitorHotkeys(document), []);
1301
+ };
1302
+ var useHotkey = (combo, cb) => {
1303
+ useEffect(
1304
+ () => useHotkeyStore.setState((s) => ({
1305
+ triggers: __spreadProps(__spreadValues({}, s.triggers), {
1306
+ [`${Object.keys(combo).join("+")}`]: { combo, cb }
1307
+ })
1308
+ })),
1309
+ []
1310
+ );
1311
+ };
1312
+
1313
+ // store/slices/history.ts
1314
+ var EMPTY_HISTORY_INDEX = 0;
1315
+ function debounce(func, timeout = 300) {
1316
+ let timer;
1317
+ return (...args) => {
1318
+ clearTimeout(timer);
1319
+ timer = setTimeout(() => {
1320
+ func(...args);
1321
+ }, timeout);
1322
+ };
1323
+ }
1324
+ var tidyState = (state) => {
1325
+ return __spreadProps(__spreadValues({}, state), {
1326
+ ui: __spreadProps(__spreadValues({}, state.ui), {
1327
+ field: {
1328
+ focus: null
1329
+ }
1330
+ })
1331
+ });
1332
+ };
1333
+ var createHistorySlice = (set, get) => {
1334
+ const record = debounce((state) => {
1335
+ const { histories, index } = get().history;
1336
+ const history = {
1337
+ state,
1338
+ id: generateId("history")
1339
+ };
1340
+ const newHistories = [...histories.slice(0, index + 1), history];
1341
+ set({
1342
+ history: __spreadProps(__spreadValues({}, get().history), {
1343
+ histories: newHistories,
1344
+ index: newHistories.length - 1
1345
+ })
1346
+ });
1347
+ }, 250);
1348
+ return {
1349
+ initialAppState: {},
1350
+ index: EMPTY_HISTORY_INDEX,
1351
+ histories: [],
1352
+ hasPast: () => get().history.index > EMPTY_HISTORY_INDEX,
1353
+ hasFuture: () => get().history.index < get().history.histories.length - 1,
1354
+ prevHistory: () => {
1355
+ const { history } = get();
1356
+ return history.hasPast() ? history.histories[history.index - 1] : null;
1357
+ },
1358
+ nextHistory: () => {
1359
+ const s = get().history;
1360
+ return s.hasFuture() ? s.histories[s.index + 1] : null;
1361
+ },
1362
+ currentHistory: () => get().history.histories[get().history.index],
1363
+ back: () => {
1364
+ var _a;
1365
+ const { history, dispatch } = get();
1366
+ if (history.hasPast()) {
1367
+ const state = tidyState(
1368
+ ((_a = history.prevHistory()) == null ? void 0 : _a.state) || history.initialAppState
1369
+ );
1370
+ dispatch({
1371
+ type: "set",
1372
+ state
1373
+ });
1374
+ set({ history: __spreadProps(__spreadValues({}, history), { index: history.index - 1 }) });
1375
+ }
1376
+ },
1377
+ forward: () => {
1378
+ var _a;
1379
+ const { history, dispatch } = get();
1380
+ if (history.hasFuture()) {
1381
+ const state = (_a = history.nextHistory()) == null ? void 0 : _a.state;
1382
+ dispatch({ type: "set", state: state ? tidyState(state) : {} });
1383
+ set({ history: __spreadProps(__spreadValues({}, history), { index: history.index + 1 }) });
1384
+ }
1385
+ },
1386
+ setHistories: (histories) => {
1387
+ var _a;
1388
+ const { dispatch, history } = get();
1389
+ dispatch({
1390
+ type: "set",
1391
+ state: ((_a = histories[histories.length - 1]) == null ? void 0 : _a.state) || history.initialAppState
1392
+ });
1393
+ set({ history: __spreadProps(__spreadValues({}, history), { histories, index: histories.length - 1 }) });
1394
+ },
1395
+ setHistoryIndex: (index) => {
1396
+ var _a;
1397
+ const { dispatch, history } = get();
1398
+ dispatch({
1399
+ type: "set",
1400
+ state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
1401
+ });
1402
+ set({ history: __spreadProps(__spreadValues({}, history), { index }) });
1403
+ },
1404
+ record
1405
+ };
1406
+ };
1407
+ function useRegisterHistorySlice(appStore, {
1408
+ histories,
1409
+ index,
1410
+ initialAppState
1411
+ }) {
1412
+ useEffect2(
1413
+ () => appStore.setState({
1414
+ history: __spreadProps(__spreadValues({}, appStore.getState().history), {
1415
+ histories,
1416
+ index,
1417
+ initialAppState
1418
+ })
1419
+ }),
1420
+ [histories, index, initialAppState]
1421
+ );
1422
+ const back = () => {
1423
+ appStore.getState().history.back();
1424
+ };
1425
+ const forward = () => {
1426
+ appStore.getState().history.forward();
1427
+ };
1428
+ useHotkey({ meta: true, z: true }, back);
1429
+ useHotkey({ meta: true, shift: true, z: true }, forward);
1430
+ useHotkey({ meta: true, y: true }, forward);
1431
+ useHotkey({ ctrl: true, z: true }, back);
1432
+ useHotkey({ ctrl: true, shift: true, z: true }, forward);
1433
+ useHotkey({ ctrl: true, y: true }, forward);
1434
+ }
1435
+
1436
+ // store/slices/nodes.ts
1437
+ init_react_import();
1438
+ var createNodesSlice = (set, get) => ({
1439
+ nodes: {},
1440
+ registerNode: (id, node) => {
1441
+ const s = get().nodes;
1442
+ const emptyNode = {
1443
+ id,
1444
+ methods: {
1445
+ sync: () => null,
1446
+ hideOverlay: () => null,
1447
+ showOverlay: () => null
1448
+ },
1449
+ element: null
1450
+ };
1451
+ const existingNode = s.nodes[id];
1452
+ set({
1453
+ nodes: __spreadProps(__spreadValues({}, s), {
1454
+ nodes: __spreadProps(__spreadValues({}, s.nodes), {
1455
+ [id]: __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, emptyNode), existingNode), node), {
1456
+ id
1457
+ })
1458
+ })
1459
+ })
1460
+ });
1461
+ },
1462
+ unregisterNode: (id) => {
1463
+ const s = get().nodes;
1464
+ const existingNode = s.nodes[id];
1465
+ if (existingNode) {
1466
+ const newNodes = __spreadValues({}, s.nodes);
1467
+ delete newNodes[id];
1468
+ set({
1469
+ nodes: __spreadProps(__spreadValues({}, s), {
1470
+ nodes: newNodes
1471
+ })
1472
+ });
1473
+ }
1474
+ }
1475
+ });
1476
+
1477
+ // store/slices/permissions.ts
1478
+ init_react_import();
1479
+ import { useEffect as useEffect3 } from "react";
1480
+
1481
+ // lib/data/flatten-data.ts
1482
+ init_react_import();
1483
+ var flattenData = (state, config) => {
1484
+ const data = [];
1485
+ walkAppState(
1486
+ state,
1487
+ config,
1488
+ (content) => content,
1489
+ (item) => {
1490
+ data.push(item);
1491
+ return null;
1492
+ }
1493
+ );
1494
+ return data;
1495
+ };
1496
+
1497
+ // lib/get-changed.ts
1498
+ init_react_import();
1499
+ import fdeq from "fast-deep-equal";
1500
+ var getChanged = (newItem, oldItem) => {
1501
+ return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
1502
+ const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
1503
+ const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
1504
+ return __spreadProps(__spreadValues({}, acc), {
1505
+ [item]: !fdeq(oldItemProps[item], newItemProps[item])
1506
+ });
1507
+ }, {}) : {};
1508
+ };
1509
+
1510
+ // store/slices/permissions.ts
1511
+ var createPermissionsSlice = (set, get) => {
1512
+ const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
1513
+ const { state, permissions, config } = get();
1514
+ const { cache: cache2, globalPermissions } = permissions;
1515
+ const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
1516
+ var _a, _b, _c;
1517
+ const { config: config2, state: appState, setComponentLoading } = get();
1518
+ const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
1519
+ if (!componentConfig) {
1520
+ return;
1521
+ }
1522
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
1523
+ if (componentConfig.resolvePermissions) {
1524
+ const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
1525
+ if (Object.values(changed).some((el) => el === true) || force2) {
1526
+ const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
1527
+ const resolvedPermissions = yield componentConfig.resolvePermissions(
1528
+ item2,
1529
+ {
1530
+ changed,
1531
+ lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1532
+ permissions: initialPermissions,
1533
+ appState: makeStatePublic(appState),
1534
+ lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
1535
+ }
1536
+ );
1537
+ const latest = get().permissions;
1538
+ set({
1539
+ permissions: __spreadProps(__spreadValues({}, latest), {
1540
+ cache: __spreadProps(__spreadValues({}, latest.cache), {
1541
+ [item2.props.id]: {
1542
+ lastData: item2,
1543
+ lastPermissions: resolvedPermissions
1544
+ }
1545
+ }),
1546
+ resolvedPermissions: __spreadProps(__spreadValues({}, latest.resolvedPermissions), {
1547
+ [item2.props.id]: resolvedPermissions
1548
+ })
1549
+ })
1550
+ });
1551
+ clearTimeout2();
1552
+ }
1553
+ }
1554
+ });
1555
+ const resolveDataForRoot = (force2 = false) => {
1556
+ const { state: appState } = get();
1557
+ resolveDataForItem(
1558
+ // Shim the root data in by conforming to component data shape
1559
+ {
1560
+ type: "root",
1561
+ props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
1562
+ },
1563
+ force2
1564
+ );
1565
+ };
1566
+ const { item, type, root } = params;
1567
+ if (item) {
1568
+ yield resolveDataForItem(item, force);
1569
+ } else if (type) {
1570
+ flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
1571
+ yield resolveDataForItem(item2, force);
1572
+ }));
1573
+ } else if (root) {
1574
+ resolveDataForRoot(force);
1575
+ } else {
1576
+ flattenData(state, config).map((item2) => __async(void 0, null, function* () {
1577
+ yield resolveDataForItem(item2, force);
1578
+ }));
1579
+ }
1580
+ });
1581
+ const refreshPermissions = (params) => resolvePermissions(params, true);
1582
+ return {
1583
+ cache: {},
1584
+ globalPermissions: {
1585
+ drag: true,
1586
+ edit: true,
1587
+ delete: true,
1588
+ duplicate: true,
1589
+ insert: true
1590
+ },
1591
+ resolvedPermissions: {},
1592
+ getPermissions: ({ item, type, root } = {}) => {
1593
+ const { config, permissions } = get();
1594
+ const { globalPermissions, resolvedPermissions } = permissions;
1595
+ if (item) {
1596
+ const componentConfig = config.components[item.type];
1597
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
1598
+ const resolvedForItem = resolvedPermissions[item.props.id];
1599
+ return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
1600
+ } else if (type) {
1601
+ const componentConfig = config.components[type];
1602
+ return __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
1603
+ } else if (root) {
1604
+ const rootConfig = config.root;
1605
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
1606
+ const resolvedForItem = resolvedPermissions["root"];
1607
+ return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
1608
+ }
1609
+ return globalPermissions;
1610
+ },
1611
+ resolvePermissions,
1612
+ refreshPermissions
1613
+ };
1614
+ };
1615
+ var useRegisterPermissionsSlice = (appStore, globalPermissions) => {
1616
+ useEffect3(() => {
1617
+ const { permissions } = appStore.getState();
1618
+ const { globalPermissions: existingGlobalPermissions } = permissions;
1619
+ appStore.setState({
1620
+ permissions: __spreadProps(__spreadValues({}, permissions), {
1621
+ globalPermissions: __spreadValues(__spreadValues({}, existingGlobalPermissions), globalPermissions)
1622
+ })
1623
+ });
1624
+ permissions.resolvePermissions();
1625
+ }, [globalPermissions]);
1626
+ useEffect3(() => {
1627
+ return appStore.subscribe(
1628
+ (s) => s.state.data,
1629
+ () => {
1630
+ appStore.getState().permissions.resolvePermissions();
1631
+ }
1632
+ );
1633
+ }, []);
1634
+ useEffect3(() => {
1635
+ return appStore.subscribe(
1636
+ (s) => s.config,
1637
+ () => {
1638
+ appStore.getState().permissions.resolvePermissions();
1639
+ }
1640
+ );
1641
+ }, []);
1642
+ };
1643
+
1644
+ // store/slices/fields.ts
1645
+ init_react_import();
1646
+ import { useCallback, useEffect as useEffect4 } from "react";
1647
+ var createFieldsSlice = (_set, _get) => {
1648
+ return {
1649
+ fields: {},
1650
+ loading: false,
1651
+ lastResolvedData: {},
1652
+ id: void 0
1653
+ };
1654
+ };
1655
+ var useRegisterFieldsSlice = (appStore, id) => {
1656
+ const resolveFields = useCallback(
1657
+ (reset) => __async(void 0, null, function* () {
1658
+ var _a, _b;
1659
+ const { fields, lastResolvedData } = appStore.getState().fields;
1660
+ const nodes = appStore.getState().state.indexes.nodes;
1661
+ const node = nodes[id || "root"];
1662
+ const componentData = node == null ? void 0 : node.data;
1663
+ const parentNode = (node == null ? void 0 : node.parentId) ? nodes[node.parentId] : null;
1664
+ const parent = (parentNode == null ? void 0 : parentNode.data) || null;
1665
+ const { getComponentConfig, state } = appStore.getState();
1666
+ const componentConfig = getComponentConfig(componentData == null ? void 0 : componentData.type);
1667
+ if (!componentData || !componentConfig) return;
1668
+ const defaultFields = componentConfig.fields || {};
1669
+ const resolver = componentConfig.resolveFields;
1670
+ let lastFields = fields;
1671
+ if (reset) {
1672
+ appStore.setState((s) => ({
1673
+ fields: __spreadProps(__spreadValues({}, s.fields), { fields: defaultFields, id })
1674
+ }));
1675
+ lastFields = defaultFields;
1676
+ }
1677
+ if (resolver) {
1678
+ const timeout = setTimeout(() => {
1679
+ appStore.setState((s) => ({
1680
+ fields: __spreadProps(__spreadValues({}, s.fields), { loading: true })
1681
+ }));
1682
+ }, 50);
1683
+ const lastData = ((_a = lastResolvedData.props) == null ? void 0 : _a.id) === id ? lastResolvedData : null;
1684
+ const changed = getChanged(componentData, lastData);
1685
+ const newFields = yield resolver(componentData, {
1686
+ changed,
1687
+ fields: defaultFields,
1688
+ lastFields,
1689
+ lastData,
1690
+ appState: makeStatePublic(state),
1691
+ parent
1692
+ });
1693
+ clearTimeout(timeout);
1694
+ if (((_b = appStore.getState().selectedItem) == null ? void 0 : _b.props.id) !== id) {
1695
+ return;
1696
+ }
1697
+ appStore.setState({
1698
+ fields: {
1699
+ fields: newFields,
1700
+ loading: false,
1701
+ lastResolvedData: componentData,
1702
+ id
1703
+ }
1704
+ });
1705
+ } else {
1706
+ appStore.setState((s) => ({
1707
+ fields: __spreadProps(__spreadValues({}, s.fields), { fields: defaultFields, id })
1708
+ }));
1709
+ }
1710
+ }),
1711
+ [id]
1712
+ );
1713
+ useEffect4(() => {
1714
+ resolveFields(true);
1715
+ return appStore.subscribe(
1716
+ (s) => s.state.indexes.nodes[id || "root"],
1717
+ () => resolveFields()
1718
+ );
1719
+ }, [id]);
1720
+ };
1721
+
1722
+ // lib/resolve-component-data.ts
1723
+ init_react_import();
1724
+ import fdeq2 from "fast-deep-equal";
1725
+ var cache = { lastChange: {} };
1726
+ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
1727
+ const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
1728
+ const resolvedItem = __spreadValues({}, item);
1729
+ const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
1730
+ const id = "id" in item.props ? item.props.id : "root";
1731
+ if (shouldRunResolver) {
1732
+ const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
1733
+ if (item && fdeq2(item, oldItem)) {
1734
+ return { node: resolved, didChange: false };
1735
+ }
1736
+ const changed = getChanged(item, oldItem);
1737
+ if (onResolveStart) {
1738
+ onResolveStart(item);
1739
+ }
1740
+ const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
1741
+ changed,
1742
+ lastData: oldItem,
1743
+ metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
1744
+ trigger
1745
+ });
1746
+ resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
1747
+ if (Object.keys(readOnly).length) {
1748
+ resolvedItem.readOnly = readOnly;
1749
+ }
1750
+ }
1751
+ let itemWithResolvedChildren = yield mapFields(
1752
+ resolvedItem,
1753
+ {
1754
+ slot: (_02) => __async(void 0, [_02], function* ({ value }) {
1755
+ const content = value;
1756
+ return yield Promise.all(
1757
+ content.map(
1758
+ (childItem) => __async(void 0, null, function* () {
1759
+ return (yield resolveComponentData(
1760
+ childItem,
1761
+ config,
1762
+ metadata,
1763
+ onResolveStart,
1764
+ onResolveEnd,
1765
+ trigger
1766
+ )).node;
1767
+ })
1768
+ )
1769
+ );
1770
+ })
1771
+ },
1772
+ config
1773
+ );
1774
+ if (shouldRunResolver && onResolveEnd) {
1775
+ onResolveEnd(resolvedItem);
1776
+ }
1777
+ cache.lastChange[id] = {
1778
+ item,
1779
+ resolved: itemWithResolvedChildren
1780
+ };
1781
+ return {
1782
+ node: itemWithResolvedChildren,
1783
+ didChange: !fdeq2(item, itemWithResolvedChildren)
1784
+ };
1785
+ });
1786
+
1787
+ // lib/data/to-root.ts
1788
+ init_react_import();
1789
+ var toRoot = (item) => {
1790
+ if ("type" in item && item.type !== "root") {
1791
+ throw new Error("Converting non-root item to root.");
1792
+ }
1793
+ const { readOnly } = item;
1794
+ if (item.props) {
1795
+ if ("id" in item.props) {
1796
+ const _a = item.props, { id } = _a, props = __objRest(_a, ["id"]);
1797
+ return { props, readOnly };
1798
+ }
1799
+ return { props: item.props, readOnly };
1800
+ }
1801
+ return { props: {}, readOnly };
1802
+ };
1803
+
1804
+ // store/default-app-state.ts
1805
+ init_react_import();
1806
+ var defaultAppState = {
1807
+ data: { content: [], root: {}, zones: {} },
1808
+ ui: {
1809
+ leftSideBarVisible: true,
1810
+ rightSideBarVisible: true,
1811
+ arrayState: {},
1812
+ itemSelector: null,
1813
+ componentList: {},
1814
+ isDragging: false,
1815
+ previewMode: "edit",
1816
+ viewports: {
1817
+ current: {
1818
+ width: defaultViewports[0].width,
1819
+ height: defaultViewports[0].height || "auto"
1820
+ },
1821
+ options: [],
1822
+ controlsVisible: true
1823
+ },
1824
+ field: { focus: null }
1825
+ },
1826
+ indexes: {
1827
+ nodes: {},
1828
+ zones: {}
1829
+ }
1830
+ };
1831
+
1832
+ // store/index.ts
1833
+ var defaultPageFields = {
1834
+ title: { type: "text" }
1835
+ };
1836
+ var createAppStore = (initialAppStore) => create2()(
1837
+ subscribeWithSelector2((set, get) => {
1838
+ var _a, _b;
1839
+ return __spreadProps(__spreadValues({
1840
+ state: defaultAppState,
1841
+ config: { components: {} },
1842
+ componentState: {},
1843
+ plugins: [],
1844
+ overrides: {},
1845
+ viewports: defaultViewports,
1846
+ zoomConfig: {
1847
+ autoZoom: 1,
1848
+ rootHeight: 0,
1849
+ zoom: 1
1850
+ },
1851
+ status: "LOADING",
1852
+ iframe: {},
1853
+ metadata: {},
1854
+ fieldTransforms: {}
1855
+ }, initialAppStore), {
1856
+ fields: createFieldsSlice(set, get),
1857
+ history: createHistorySlice(set, get),
1858
+ nodes: createNodesSlice(set, get),
1859
+ permissions: createPermissionsSlice(set, get),
1860
+ getComponentConfig: (type) => {
1861
+ var _a2;
1862
+ const { config, selectedItem } = get();
1863
+ const rootFields = ((_a2 = config.root) == null ? void 0 : _a2.fields) || defaultPageFields;
1864
+ return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
1865
+ },
1866
+ selectedItem: ((_a = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _a.ui.itemSelector) ? getItem(
1867
+ (_b = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _b.ui.itemSelector,
1868
+ initialAppStore.state
1869
+ ) : null,
1870
+ dispatch: (action) => set((s) => {
1871
+ var _a2, _b2;
1872
+ const { record } = get().history;
1873
+ const dispatch = createReducer({
1874
+ record,
1875
+ appStore: s
1876
+ });
1877
+ const state = dispatch(s.state, action);
1878
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1879
+ (_b2 = (_a2 = get()).onAction) == null ? void 0 : _b2.call(_a2, action, state, get().state);
1880
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1881
+ }),
1882
+ setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1883
+ setStatus: (status) => set({ status }),
1884
+ setComponentState: (componentState) => set({ componentState }),
1885
+ pendingLoadTimeouts: {},
1886
+ setComponentLoading: (id, loading = true, defer = 0) => {
1887
+ const { setComponentState, pendingLoadTimeouts } = get();
1888
+ const loadId = generateId();
1889
+ const setLoading = () => {
1890
+ var _a2;
1891
+ const { componentState } = get();
1892
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1893
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1894
+ loadingCount: (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) + 1
1895
+ })
1896
+ }));
1897
+ };
1898
+ const unsetLoading = () => {
1899
+ var _a2;
1900
+ const { componentState } = get();
1901
+ clearTimeout(timeout);
1902
+ delete pendingLoadTimeouts[loadId];
1903
+ set({ pendingLoadTimeouts });
1904
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1905
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1906
+ loadingCount: Math.max(
1907
+ (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) - 1,
1908
+ 0
1909
+ )
1910
+ })
1911
+ }));
1912
+ };
1913
+ const timeout = setTimeout(() => {
1914
+ if (loading) {
1915
+ setLoading();
1916
+ } else {
1917
+ unsetLoading();
1918
+ }
1919
+ delete pendingLoadTimeouts[loadId];
1920
+ set({ pendingLoadTimeouts });
1921
+ }, defer);
1922
+ set({
1923
+ pendingLoadTimeouts: __spreadProps(__spreadValues({}, pendingLoadTimeouts), {
1924
+ [id]: timeout
1925
+ })
1926
+ });
1927
+ return unsetLoading;
1928
+ },
1929
+ unsetComponentLoading: (id) => {
1930
+ const { setComponentLoading } = get();
1931
+ setComponentLoading(id, false);
1932
+ },
1933
+ // Helper
1934
+ setUi: (ui, recordHistory) => set((s) => {
1935
+ const dispatch = createReducer({
1936
+ record: () => {
1937
+ },
1938
+ appStore: s
1939
+ });
1940
+ const state = dispatch(s.state, {
1941
+ type: "setUi",
1942
+ ui,
1943
+ recordHistory
1944
+ });
1945
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1946
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1947
+ }),
1948
+ resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
1949
+ const { config, metadata, setComponentLoading, permissions } = get();
1950
+ const timeouts = {};
1951
+ return yield resolveComponentData(
1952
+ componentData,
1953
+ config,
1954
+ metadata,
1955
+ (item) => {
1956
+ const id = "id" in item.props ? item.props.id : "root";
1957
+ timeouts[id] = setComponentLoading(id, true, 50);
1958
+ },
1959
+ (item) => __async(void 0, null, function* () {
1960
+ const id = "id" in item.props ? item.props.id : "root";
1961
+ if ("type" in item) {
1962
+ yield permissions.refreshPermissions({ item });
1963
+ } else {
1964
+ yield permissions.refreshPermissions({ root: true });
1965
+ }
1966
+ timeouts[id]();
1967
+ }),
1968
+ trigger
1969
+ );
1970
+ }),
1971
+ resolveAndCommitData: () => __async(void 0, null, function* () {
1972
+ const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
1973
+ walkAppState(
1974
+ state,
1975
+ config,
1976
+ (content) => content,
1977
+ (childItem) => {
1978
+ resolveComponentData2(childItem, "load").then((resolved) => {
1979
+ const { state: state2 } = get();
1980
+ const node = state2.indexes.nodes[resolved.node.props.id];
1981
+ if (node && resolved.didChange) {
1982
+ if (resolved.node.props.id === "root") {
1983
+ dispatch({
1984
+ type: "replaceRoot",
1985
+ root: toRoot(resolved.node)
1986
+ });
1987
+ } else {
1988
+ const zoneCompound = `${node.parentId}:${node.zone}`;
1989
+ const parentZone = state2.indexes.zones[zoneCompound];
1990
+ const index = parentZone.contentIds.indexOf(
1991
+ resolved.node.props.id
1992
+ );
1993
+ dispatch({
1994
+ type: "replace",
1995
+ data: resolved.node,
1996
+ destinationIndex: index,
1997
+ destinationZone: zoneCompound
1998
+ });
1999
+ }
2000
+ }
2001
+ });
2002
+ return childItem;
2003
+ }
2004
+ );
2005
+ })
2006
+ });
2007
+ })
2008
+ );
2009
+ var appStoreContext = createContext(createAppStore());
2010
+ function useAppStore(selector) {
2011
+ const context = useContext(appStoreContext);
2012
+ return useStore(context, selector);
2013
+ }
2014
+ function useAppStoreApi() {
2015
+ return useContext(appStoreContext);
2016
+ }
2017
+
2018
+ // css-module:/home/runner/work/puck/puck/packages/core/components/InlineTextField/styles.module.css#css-module
2019
+ init_react_import();
2020
+ var styles_module_default = { "InlineTextField": "_InlineTextField_ilw2a_1" };
2021
+
2022
+ // lib/index.ts
2023
+ init_react_import();
2024
+
2025
+ // lib/filter.ts
2026
+ init_react_import();
2027
+
2028
+ // lib/get-class-name-factory.ts
2029
+ init_react_import();
2030
+ var import_classnames = __toESM(require_classnames());
2031
+ var getClassNameFactory = (rootClass, styles, config = { baseClass: "" }) => (options = {}) => {
2032
+ if (typeof options === "string") {
2033
+ const descendant = options;
2034
+ const style = styles[`${rootClass}-${descendant}`];
2035
+ if (style) {
2036
+ return config.baseClass + styles[`${rootClass}-${descendant}`] || "";
2037
+ }
2038
+ return "";
2039
+ } else if (typeof options === "object") {
2040
+ const modifiers = options;
2041
+ const prefixedModifiers = {};
2042
+ for (let modifier in modifiers) {
2043
+ prefixedModifiers[styles[`${rootClass}--${modifier}`]] = modifiers[modifier];
2044
+ }
2045
+ const c = styles[rootClass];
2046
+ return config.baseClass + (0, import_classnames.default)(__spreadValues({
2047
+ [c]: !!c
2048
+ }, prefixedModifiers));
2049
+ } else {
2050
+ return config.baseClass + styles[rootClass] || "";
2051
+ }
2052
+ };
2053
+ var get_class_name_factory_default = getClassNameFactory;
2054
+
2055
+ // lib/data/reorder.ts
2056
+ init_react_import();
2057
+ var reorder = (list, startIndex, endIndex) => {
2058
+ const result = Array.from(list);
2059
+ const [removed] = result.splice(startIndex, 1);
2060
+ result.splice(endIndex, 0, removed);
2061
+ return result;
2062
+ };
2063
+
2064
+ // lib/data/replace.ts
2065
+ init_react_import();
2066
+ var replace = (list, index, newItem) => {
2067
+ const result = Array.from(list);
2068
+ result.splice(index, 1);
2069
+ result.splice(index, 0, newItem);
2070
+ return result;
2071
+ };
2072
+
2073
+ // lib/use-reset-auto-zoom.ts
2074
+ init_react_import();
2075
+ import { useCallback as useCallback2 } from "react";
2076
+
2077
+ // lib/get-zoom-config.ts
2078
+ init_react_import();
2079
+
2080
+ // ../../node_modules/css-box-model/dist/css-box-model.esm.js
2081
+ init_react_import();
2082
+
2083
+ // ../../node_modules/tiny-invariant/dist/esm/tiny-invariant.js
2084
+ init_react_import();
2085
+ var isProduction = process.env.NODE_ENV === "production";
2086
+ var prefix = "Invariant failed";
2087
+ function invariant(condition, message) {
2088
+ if (condition) {
2089
+ return;
2090
+ }
2091
+ if (isProduction) {
2092
+ throw new Error(prefix);
2093
+ }
2094
+ var provided = typeof message === "function" ? message() : message;
2095
+ var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
2096
+ throw new Error(value);
2097
+ }
2098
+
2099
+ // ../../node_modules/css-box-model/dist/css-box-model.esm.js
2100
+ var getRect = function getRect2(_ref) {
2101
+ var top = _ref.top, right = _ref.right, bottom = _ref.bottom, left = _ref.left;
2102
+ var width = right - left;
2103
+ var height = bottom - top;
2104
+ var rect = {
2105
+ top,
2106
+ right,
2107
+ bottom,
2108
+ left,
2109
+ width,
2110
+ height,
2111
+ x: left,
2112
+ y: top,
2113
+ center: {
2114
+ x: (right + left) / 2,
2115
+ y: (bottom + top) / 2
2116
+ }
2117
+ };
2118
+ return rect;
2119
+ };
2120
+ var expand = function expand2(target, expandBy) {
2121
+ return {
2122
+ top: target.top - expandBy.top,
2123
+ left: target.left - expandBy.left,
2124
+ bottom: target.bottom + expandBy.bottom,
2125
+ right: target.right + expandBy.right
2126
+ };
2127
+ };
2128
+ var shrink = function shrink2(target, shrinkBy) {
2129
+ return {
2130
+ top: target.top + shrinkBy.top,
2131
+ left: target.left + shrinkBy.left,
2132
+ bottom: target.bottom - shrinkBy.bottom,
2133
+ right: target.right - shrinkBy.right
2134
+ };
2135
+ };
2136
+ var noSpacing = {
2137
+ top: 0,
2138
+ right: 0,
2139
+ bottom: 0,
2140
+ left: 0
2141
+ };
2142
+ var createBox = function createBox2(_ref2) {
2143
+ var borderBox = _ref2.borderBox, _ref2$margin = _ref2.margin, margin = _ref2$margin === void 0 ? noSpacing : _ref2$margin, _ref2$border = _ref2.border, border = _ref2$border === void 0 ? noSpacing : _ref2$border, _ref2$padding = _ref2.padding, padding = _ref2$padding === void 0 ? noSpacing : _ref2$padding;
2144
+ var marginBox = getRect(expand(borderBox, margin));
2145
+ var paddingBox = getRect(shrink(borderBox, border));
2146
+ var contentBox = getRect(shrink(paddingBox, padding));
2147
+ return {
2148
+ marginBox,
2149
+ borderBox: getRect(borderBox),
2150
+ paddingBox,
2151
+ contentBox,
2152
+ margin,
2153
+ border,
2154
+ padding
2155
+ };
2156
+ };
2157
+ var parse = function parse2(raw) {
2158
+ var value = raw.slice(0, -2);
2159
+ var suffix = raw.slice(-2);
2160
+ if (suffix !== "px") {
2161
+ return 0;
2162
+ }
2163
+ var result = Number(value);
2164
+ !!isNaN(result) ? process.env.NODE_ENV !== "production" ? invariant(false, "Could not parse value [raw: " + raw + ", without suffix: " + value + "]") : invariant(false) : void 0;
2165
+ return result;
2166
+ };
2167
+ var calculateBox = function calculateBox2(borderBox, styles) {
2168
+ var margin = {
2169
+ top: parse(styles.marginTop),
2170
+ right: parse(styles.marginRight),
2171
+ bottom: parse(styles.marginBottom),
2172
+ left: parse(styles.marginLeft)
2173
+ };
2174
+ var padding = {
2175
+ top: parse(styles.paddingTop),
2176
+ right: parse(styles.paddingRight),
2177
+ bottom: parse(styles.paddingBottom),
2178
+ left: parse(styles.paddingLeft)
2179
+ };
2180
+ var border = {
2181
+ top: parse(styles.borderTopWidth),
2182
+ right: parse(styles.borderRightWidth),
2183
+ bottom: parse(styles.borderBottomWidth),
2184
+ left: parse(styles.borderLeftWidth)
2185
+ };
2186
+ return createBox({
2187
+ borderBox,
2188
+ margin,
2189
+ padding,
2190
+ border
2191
+ });
2192
+ };
2193
+ var getBox = function getBox2(el) {
2194
+ var borderBox = el.getBoundingClientRect();
2195
+ var styles = window.getComputedStyle(el);
2196
+ return calculateBox(borderBox, styles);
2197
+ };
2198
+
2199
+ // lib/get-zoom-config.ts
2200
+ var RESET_ZOOM_SMALLER_THAN_FRAME = true;
2201
+ var getZoomConfig = (uiViewport, frame, zoom) => {
2202
+ const box = getBox(frame);
2203
+ const { width: frameWidth, height: frameHeight } = box.contentBox;
2204
+ const viewportHeight = uiViewport.height === "auto" ? frameHeight : uiViewport.height;
2205
+ let rootHeight = 0;
2206
+ let autoZoom = 1;
2207
+ if (uiViewport.width > frameWidth || viewportHeight > frameHeight) {
2208
+ const widthZoom = Math.min(frameWidth / uiViewport.width, 1);
2209
+ const heightZoom = Math.min(frameHeight / viewportHeight, 1);
2210
+ zoom = widthZoom;
2211
+ if (widthZoom < heightZoom) {
2212
+ rootHeight = viewportHeight / zoom;
2213
+ } else {
2214
+ rootHeight = viewportHeight;
2215
+ zoom = heightZoom;
2216
+ }
2217
+ autoZoom = zoom;
2218
+ } else {
2219
+ if (RESET_ZOOM_SMALLER_THAN_FRAME) {
2220
+ autoZoom = 1;
2221
+ zoom = 1;
2222
+ rootHeight = viewportHeight;
2223
+ }
2224
+ }
2225
+ return { autoZoom, rootHeight, zoom };
2226
+ };
2227
+
2228
+ // lib/use-reset-auto-zoom.ts
2229
+ import { useShallow } from "zustand/react/shallow";
2230
+ var useResetAutoZoom = (frameRef) => {
2231
+ const { viewports, zoomConfig, setZoomConfig } = useAppStore(
2232
+ useShallow((s) => ({
2233
+ viewports: s.state.ui.viewports,
2234
+ zoomConfig: s.zoomConfig,
2235
+ setZoomConfig: s.setZoomConfig
2236
+ }))
2237
+ );
2238
+ const resetAutoZoom = useCallback2(
2239
+ (options) => {
2240
+ const newViewports = (options == null ? void 0 : options.viewports) || viewports;
2241
+ if (!(options == null ? void 0 : options.isResettingRef)) {
2242
+ if (frameRef.current) {
2243
+ setZoomConfig(
2244
+ getZoomConfig(
2245
+ newViewports == null ? void 0 : newViewports.current,
2246
+ frameRef.current,
2247
+ zoomConfig.zoom
2248
+ )
2249
+ );
2250
+ }
2251
+ return;
2252
+ }
2253
+ const {
2254
+ isResettingRef,
2255
+ setShowTransition,
2256
+ showTransition = false
2257
+ } = options;
2258
+ if (!isResettingRef.current) {
2259
+ isResettingRef.current = true;
2260
+ if (setShowTransition) {
2261
+ setShowTransition(showTransition);
2262
+ }
2263
+ if (frameRef.current) {
2264
+ setZoomConfig(
2265
+ getZoomConfig(
2266
+ newViewports == null ? void 0 : newViewports.current,
2267
+ frameRef.current,
2268
+ zoomConfig.zoom
2269
+ )
2270
+ );
2271
+ }
2272
+ setTimeout(() => {
2273
+ isResettingRef.current = false;
2274
+ }, 0);
2275
+ }
2276
+ },
2277
+ [frameRef, zoomConfig, viewports, setZoomConfig]
2278
+ );
2279
+ return resetAutoZoom;
2280
+ };
2281
+
2282
+ // components/InlineTextField/index.tsx
2283
+ import { jsx } from "react/jsx-runtime";
2284
+ var getClassName = get_class_name_factory_default("InlineTextField", styles_module_default);
2285
+ var InlineTextFieldInternal = ({
2286
+ propPath,
2287
+ componentId,
2288
+ value,
2289
+ isReadOnly,
2290
+ opts = {}
2291
+ }) => {
2292
+ var _a;
2293
+ const ref = useRef(null);
2294
+ const appStoreApi = useAppStoreApi();
2295
+ const disableLineBreaks = (_a = opts.disableLineBreaks) != null ? _a : false;
2296
+ useEffect5(() => {
2297
+ const appStore = appStoreApi.getState();
2298
+ const data = appStore.state.indexes.nodes[componentId].data;
2299
+ const componentConfig = appStore.getComponentConfig(data.type);
2300
+ if (!componentConfig) {
2301
+ throw new Error(
2302
+ `InlineTextField Error: No config defined for ${data.type}`
2303
+ );
2304
+ }
2305
+ if (ref.current) {
2306
+ if (value !== ref.current.innerText) {
2307
+ ref.current.replaceChildren(value);
2308
+ }
2309
+ const cleanupPortal = registerOverlayPortal(ref.current);
2310
+ const handleInput = (e) => __async(void 0, null, function* () {
2311
+ var _a2;
2312
+ const appStore2 = appStoreApi.getState();
2313
+ const node = appStore2.state.indexes.nodes[componentId];
2314
+ const zoneCompound = `${node.parentId}:${node.zone}`;
2315
+ const index = (_a2 = appStore2.state.indexes.zones[zoneCompound]) == null ? void 0 : _a2.contentIds.indexOf(
2316
+ componentId
2317
+ );
2318
+ const newProps = setDeep(node.data.props, propPath, e.target.innerText);
2319
+ const resolvedData = yield appStore2.resolveComponentData(
2320
+ __spreadProps(__spreadValues({}, node.data), { props: newProps }),
2321
+ "replace"
2322
+ );
2323
+ appStore2.dispatch({
2324
+ type: "replace",
2325
+ data: resolvedData.node,
2326
+ destinationIndex: index,
2327
+ destinationZone: zoneCompound
2328
+ });
2329
+ });
2330
+ ref.current.addEventListener("input", handleInput);
2331
+ return () => {
2332
+ var _a2;
2333
+ (_a2 = ref.current) == null ? void 0 : _a2.removeEventListener("input", handleInput);
2334
+ cleanupPortal == null ? void 0 : cleanupPortal();
2335
+ };
2336
+ }
2337
+ }, [appStoreApi, ref.current, value]);
2338
+ const [isHovering, setIsHovering] = useState(false);
2339
+ const [isFocused, setIsFocused] = useState(false);
2340
+ return /* @__PURE__ */ jsx(
2341
+ "span",
2342
+ {
2343
+ className: getClassName(),
2344
+ ref,
2345
+ contentEditable: isHovering || isFocused ? "plaintext-only" : "false",
2346
+ onClick: (e) => {
2347
+ e.preventDefault();
2348
+ e.stopPropagation();
2349
+ },
2350
+ onClickCapture: (e) => {
2351
+ e.preventDefault();
2352
+ e.stopPropagation();
2353
+ },
2354
+ onKeyDown: (e) => {
2355
+ if (disableLineBreaks && e.key === "Enter" || isReadOnly) {
2356
+ e.preventDefault();
2357
+ }
2358
+ },
2359
+ onMouseOverCapture: () => setIsHovering(true),
2360
+ onMouseOutCapture: () => setIsHovering(false),
2361
+ onFocus: () => setIsFocused(true),
2362
+ onBlur: () => setIsFocused(false)
2363
+ }
2364
+ );
2365
+ };
2366
+ var InlineTextField = memo(InlineTextFieldInternal);
2367
+
2368
+ // lib/field-transforms/default-transforms.tsx
2369
+ import { jsx as jsx2 } from "react/jsx-runtime";
2370
+ var getSlotTransform = (renderSlotEdit, renderSlotRender = renderSlotEdit) => ({
2371
+ slot: ({ value: content, propName, field, isReadOnly }) => {
2372
+ const render = isReadOnly ? renderSlotRender : renderSlotEdit;
2373
+ const Slot = (dzProps) => render(__spreadProps(__spreadValues({
2374
+ allow: (field == null ? void 0 : field.type) === "slot" ? field.allow : [],
2375
+ disallow: (field == null ? void 0 : field.type) === "slot" ? field.disallow : []
2376
+ }, dzProps), {
2377
+ zone: propName,
2378
+ content
2379
+ }));
2380
+ return Slot;
2381
+ }
2382
+ });
2383
+ var getInlineTextTransform = () => ({
2384
+ text: ({ value, componentId, field, propPath, isReadOnly }) => {
2385
+ if (field.contentEditable) {
2386
+ return /* @__PURE__ */ jsx2(
2387
+ InlineTextField,
2388
+ {
2389
+ propPath,
2390
+ componentId,
2391
+ value,
2392
+ opts: { disableLineBreaks: true },
2393
+ isReadOnly
2394
+ }
2395
+ );
2396
+ }
2397
+ return value;
2398
+ },
2399
+ textarea: ({ value, componentId, field, propPath, isReadOnly }) => {
2400
+ if (field.contentEditable) {
2401
+ return /* @__PURE__ */ jsx2(
2402
+ InlineTextField,
2403
+ {
2404
+ propPath,
2405
+ componentId,
2406
+ value,
2407
+ isReadOnly
2408
+ }
2409
+ );
2410
+ }
2411
+ return value;
2412
+ },
2413
+ custom: ({ value, componentId, field, propPath, isReadOnly }) => {
2414
+ if (field.contentEditable && typeof value === "string") {
2415
+ return /* @__PURE__ */ jsx2(
2416
+ InlineTextField,
2417
+ {
2418
+ propPath,
2419
+ componentId,
2420
+ value,
2421
+ isReadOnly
2422
+ }
2423
+ );
2424
+ }
2425
+ return value;
2426
+ }
2427
+ });
2428
+
2429
+ // lib/use-slots.tsx
2430
+ function useSlots(config, item, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
2431
+ return useFieldTransforms(
2432
+ config,
2433
+ item,
2434
+ getSlotTransform(renderSlotEdit, renderSlotRender),
2435
+ readOnly,
2436
+ forceReadOnly
2437
+ );
2438
+ }
2439
+
2440
+ // components/SlotRender/server.tsx
2441
+ init_react_import();
2442
+ import { forwardRef } from "react";
2443
+ import { jsx as jsx3 } from "react/jsx-runtime";
2444
+ var SlotRenderPure = (props) => /* @__PURE__ */ jsx3(SlotRender, __spreadValues({}, props));
2445
+ var Item = ({
2446
+ config,
2447
+ item,
2448
+ metadata
2449
+ }) => {
2450
+ const Component = config.components[item.type];
2451
+ const props = useSlots(config, item, (slotProps) => /* @__PURE__ */ jsx3(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
2452
+ return /* @__PURE__ */ jsx3(
2453
+ Component.render,
2454
+ __spreadProps(__spreadValues({}, props), {
2455
+ puck: __spreadProps(__spreadValues({}, props.puck), {
2456
+ renderDropZone: DropZoneRender,
2457
+ metadata: metadata || {}
2458
+ })
2459
+ })
2460
+ );
2461
+ };
2462
+ var SlotRender = forwardRef(
2463
+ function SlotRenderInternal({ className, style, content, config, metadata }, ref) {
2464
+ return /* @__PURE__ */ jsx3("div", { className, style, ref, children: content.map((item) => {
2465
+ if (!config.components[item.type]) {
2466
+ return null;
2467
+ }
2468
+ return /* @__PURE__ */ jsx3(
2469
+ Item,
2470
+ {
2471
+ config,
2472
+ item,
2473
+ metadata
2474
+ },
2475
+ item.props.id
2476
+ );
2477
+ }) });
2478
+ }
2479
+ );
2480
+
2481
+ // components/ServerRender/index.tsx
2482
+ import { Fragment, jsx as jsx4 } from "react/jsx-runtime";
2483
+ function DropZoneRender({
2484
+ zone,
2485
+ data,
2486
+ areaId = "root",
2487
+ config,
2488
+ metadata = {}
2489
+ }) {
2490
+ let zoneCompound = rootDroppableId;
2491
+ let content = (data == null ? void 0 : data.content) || [];
2492
+ if (!data || !config) {
2493
+ return null;
2494
+ }
2495
+ if (areaId !== rootAreaId && zone !== rootZone) {
2496
+ zoneCompound = `${areaId}:${zone}`;
2497
+ content = setupZone(data, zoneCompound).zones[zoneCompound];
2498
+ }
2499
+ return /* @__PURE__ */ jsx4(Fragment, { children: content.map((item) => {
2500
+ const Component = config.components[item.type];
2501
+ const props = __spreadProps(__spreadValues({}, item.props), {
2502
+ puck: {
2503
+ renderDropZone: ({ zone: zone2 }) => /* @__PURE__ */ jsx4(
2504
+ DropZoneRender,
2505
+ {
2506
+ zone: zone2,
2507
+ data,
2508
+ areaId: item.props.id,
2509
+ config,
2510
+ metadata
2511
+ }
2512
+ ),
2513
+ metadata,
2514
+ dragRef: null,
2515
+ isEditing: false
2516
+ }
2517
+ });
2518
+ const renderItem = __spreadProps(__spreadValues({}, item), { props });
2519
+ const propsWithSlots = useSlots(config, renderItem, (props2) => /* @__PURE__ */ jsx4(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
2520
+ if (Component) {
2521
+ return /* @__PURE__ */ jsx4(Component.render, __spreadValues({}, propsWithSlots), renderItem.props.id);
2522
+ }
2523
+ return null;
2524
+ }) });
2525
+ }
2526
+ function Render({
2527
+ config,
2528
+ data,
2529
+ metadata = {}
2530
+ }) {
2531
+ var _a;
2532
+ const rootProps = "props" in data.root ? data.root.props : data.root;
2533
+ const title = rootProps.title || "";
2534
+ const props = __spreadProps(__spreadValues({}, rootProps), {
2535
+ puck: {
2536
+ renderDropZone: ({ zone }) => /* @__PURE__ */ jsx4(
2537
+ DropZoneRender,
2538
+ {
2539
+ zone,
2540
+ data,
2541
+ config,
2542
+ metadata
2543
+ }
2544
+ ),
2545
+ isEditing: false,
2546
+ dragRef: null,
2547
+ metadata
2548
+ },
2549
+ title,
2550
+ editMode: false,
2551
+ id: "puck-root"
2552
+ });
2553
+ const propsWithSlots = useSlots(config, { type: "root", props }, (props2) => /* @__PURE__ */ jsx4(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
2554
+ if ((_a = config.root) == null ? void 0 : _a.render) {
2555
+ return /* @__PURE__ */ jsx4(config.root.render, __spreadProps(__spreadValues({}, propsWithSlots), { children: /* @__PURE__ */ jsx4(
2556
+ DropZoneRender,
2557
+ {
2558
+ config,
2559
+ data,
2560
+ zone: rootZone,
2561
+ metadata
2562
+ }
2563
+ ) }));
2564
+ }
2565
+ return /* @__PURE__ */ jsx4(
2566
+ DropZoneRender,
2567
+ {
2568
+ config,
2569
+ data,
2570
+ zone: rootZone,
2571
+ metadata
2572
+ }
2573
+ );
2574
+ }
2575
+
2576
+ // lib/migrate.ts
2577
+ init_react_import();
2578
+ var migrations = [
2579
+ // Migrate root to root.props
2580
+ (data) => {
2581
+ const rootProps = data.root.props || data.root;
2582
+ if (Object.keys(data.root).length > 0 && !data.root.props) {
2583
+ console.warn(
2584
+ "Migration applied: Root props moved from `root` to `root.props`."
2585
+ );
2586
+ return __spreadProps(__spreadValues({}, data), {
2587
+ root: {
2588
+ props: __spreadValues({}, rootProps)
2589
+ }
2590
+ });
2591
+ }
2592
+ return data;
2593
+ },
2594
+ // Migrate zones to slots
2595
+ (data, config, migrationOptions) => {
2596
+ var _a, _b;
2597
+ if (!config) return data;
2598
+ console.log("Migrating DropZones to slots...");
2599
+ const updatedItems = {};
2600
+ const appState = __spreadProps(__spreadValues({}, defaultAppState), { data });
2601
+ const { indexes } = walkAppState(appState, config);
2602
+ const deletedCompounds = [];
2603
+ walkAppState(appState, config, (content, zoneCompound, zoneType) => {
2604
+ var _a2, _b2, _c;
2605
+ if (zoneType === "dropzone") {
2606
+ const [id, slotName] = zoneCompound.split(":");
2607
+ const nodeData = indexes.nodes[id].data;
2608
+ const componentType = nodeData.type;
2609
+ const configForComponent = id === "root" ? config.root : config.components[componentType];
2610
+ if (((_b2 = (_a2 = configForComponent == null ? void 0 : configForComponent.fields) == null ? void 0 : _a2[slotName]) == null ? void 0 : _b2.type) === "slot") {
2611
+ updatedItems[id] = __spreadProps(__spreadValues({}, nodeData), {
2612
+ props: __spreadProps(__spreadValues(__spreadValues({}, nodeData.props), (_c = updatedItems[id]) == null ? void 0 : _c.props), {
2613
+ [slotName]: content
2614
+ })
2615
+ });
2616
+ deletedCompounds.push(zoneCompound);
2617
+ }
2618
+ return content;
2619
+ }
2620
+ return content;
2621
+ });
2622
+ const updated = walkAppState(
2623
+ appState,
2624
+ config,
2625
+ (content) => content,
2626
+ (item) => {
2627
+ var _a2;
2628
+ return (_a2 = updatedItems[item.props.id]) != null ? _a2 : item;
2629
+ }
2630
+ );
2631
+ deletedCompounds.forEach((zoneCompound) => {
2632
+ var _a2;
2633
+ const [_, propName] = zoneCompound.split(":");
2634
+ console.log(
2635
+ `\u2713 Success: Migrated "${zoneCompound}" from DropZone to slot field "${propName}"`
2636
+ );
2637
+ (_a2 = updated.data.zones) == null ? true : delete _a2[zoneCompound];
2638
+ });
2639
+ if (migrationOptions == null ? void 0 : migrationOptions.migrateDynamicZonesForComponent) {
2640
+ const unmigratedZonesGrouped = {};
2641
+ Object.keys((_a = updated.data.zones) != null ? _a : {}).forEach((zoneCompound) => {
2642
+ var _a2;
2643
+ const [componentId, propName] = zoneCompound.split(":");
2644
+ const content = (_a2 = updated.data.zones) == null ? void 0 : _a2[zoneCompound];
2645
+ if (!content) {
2646
+ return;
2647
+ }
2648
+ if (!unmigratedZonesGrouped[componentId]) {
2649
+ unmigratedZonesGrouped[componentId] = {};
2650
+ }
2651
+ if (!unmigratedZonesGrouped[componentId][propName]) {
2652
+ unmigratedZonesGrouped[componentId][propName] = content;
2653
+ }
2654
+ });
2655
+ Object.keys(unmigratedZonesGrouped).forEach((componentId) => {
2656
+ updated.data = walkTree(updated.data, config, (content) => {
2657
+ return content.map((child) => {
2658
+ var _a2;
2659
+ if (child.props.id !== componentId) {
2660
+ return child;
2661
+ }
2662
+ const migrateFn = (_a2 = migrationOptions == null ? void 0 : migrationOptions.migrateDynamicZonesForComponent) == null ? void 0 : _a2[child.type];
2663
+ if (!migrateFn) {
2664
+ return child;
2665
+ }
2666
+ const zones = unmigratedZonesGrouped[componentId];
2667
+ const migratedProps = migrateFn(child.props, zones);
2668
+ Object.keys(zones).forEach((propName) => {
2669
+ var _a3;
2670
+ const zoneCompound = `${componentId}:${propName}`;
2671
+ console.log(`\u2713 Success: Migrated "${zoneCompound}" DropZone`);
2672
+ (_a3 = updated.data.zones) == null ? true : delete _a3[zoneCompound];
2673
+ });
2674
+ return __spreadProps(__spreadValues({}, child), {
2675
+ props: migratedProps
2676
+ });
2677
+ });
2678
+ });
2679
+ });
2680
+ }
2681
+ Object.keys((_b = updated.data.zones) != null ? _b : {}).forEach((zoneCompound) => {
2682
+ const [_, propName] = zoneCompound.split(":");
2683
+ throw new Error(
2684
+ `Could not migrate DropZone "${zoneCompound}" to slot field. No slot exists with the name "${propName}".`
2685
+ );
2686
+ });
2687
+ delete updated.data.zones;
2688
+ return updated.data;
2689
+ }
2690
+ ];
2691
+ function migrate(data, config, migrationOptions) {
2692
+ return migrations == null ? void 0 : migrations.reduce(
2693
+ (acc, migration) => migration(acc, config, migrationOptions),
2694
+ data
2695
+ );
2696
+ }
2697
+
2698
+ // lib/transform-props.ts
2699
+ init_react_import();
2700
+
2701
+ // lib/data/default-data.ts
2702
+ init_react_import();
2703
+ var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
2704
+ root: data.root || {},
2705
+ content: data.content || []
2706
+ });
2707
+
2708
+ // lib/transform-props.ts
2709
+ function transformProps(data, propTransforms, config = { components: {} }) {
2710
+ const mapItem = (item) => {
2711
+ if (propTransforms[item.type]) {
2712
+ return __spreadProps(__spreadValues({}, item), {
2713
+ props: __spreadValues({
2714
+ id: item.props.id
2715
+ }, propTransforms[item.type](item.props))
2716
+ });
2717
+ }
2718
+ return item;
2719
+ };
2720
+ const defaultedData = defaultData(data);
2721
+ const rootProps = defaultedData.root.props || defaultedData.root;
2722
+ let newRoot = __spreadValues({}, defaultedData.root);
2723
+ if (propTransforms["root"]) {
2724
+ newRoot.props = propTransforms["root"](rootProps);
2725
+ }
2726
+ const dataWithUpdatedRoot = __spreadProps(__spreadValues({}, defaultedData), { root: newRoot });
2727
+ const updatedData = walkTree(
2728
+ dataWithUpdatedRoot,
2729
+ config,
2730
+ (content) => content.map(mapItem)
2731
+ );
2732
+ if (!defaultedData.root.props) {
2733
+ updatedData.root = updatedData.root.props;
2734
+ }
2735
+ return updatedData;
2736
+ }
2737
+
2738
+ // lib/resolve-all-data.ts
2739
+ init_react_import();
2740
+
2741
+ // lib/data/to-component.ts
2742
+ init_react_import();
2743
+ var toComponent = (item) => {
2744
+ return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
2745
+ props: __spreadProps(__spreadValues({}, item.props), { id: "root" }),
2746
+ type: "root"
2747
+ });
2748
+ };
2749
+
2750
+ // lib/resolve-all-data.ts
2751
+ function resolveAllData(_0, _1) {
2752
+ return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
2753
+ var _a;
2754
+ const defaultedData = defaultData(data);
2755
+ const resolveNode = (_node) => __async(this, null, function* () {
2756
+ const node = toComponent(_node);
2757
+ onResolveStart == null ? void 0 : onResolveStart(node);
2758
+ const resolved = (yield resolveComponentData(
2759
+ node,
2760
+ config,
2761
+ metadata,
2762
+ () => {
2763
+ },
2764
+ () => {
2765
+ },
2766
+ "force"
2767
+ )).node;
2768
+ const resolvedDeep = yield mapFields(
2769
+ resolved,
2770
+ { slot: ({ value }) => processContent(value) },
2771
+ config
2772
+ );
2773
+ onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
2774
+ return resolvedDeep;
2775
+ });
2776
+ const processContent = (content) => __async(this, null, function* () {
2777
+ return Promise.all(content.map(resolveNode));
2778
+ });
2779
+ const processZones = () => __async(this, null, function* () {
2780
+ var _a2;
2781
+ const zones = (_a2 = data.zones) != null ? _a2 : {};
2782
+ Object.entries(zones).forEach((_02) => __async(this, [_02], function* ([zoneKey, content]) {
2783
+ zones[zoneKey] = yield Promise.all(content.map(resolveNode));
2784
+ }));
2785
+ return zones;
2786
+ });
2787
+ const dynamic = {
2788
+ root: yield resolveNode(defaultedData.root),
2789
+ content: yield processContent(defaultedData.content),
2790
+ zones: yield processZones()
2791
+ };
2792
+ Object.keys((_a = defaultedData.zones) != null ? _a : {}).forEach((zoneKey) => __async(this, null, function* () {
2793
+ const content = defaultedData.zones[zoneKey];
2794
+ dynamic.zones[zoneKey] = yield processContent(content);
2795
+ }), {});
2796
+ return dynamic;
2797
+ });
2798
+ }
2799
+
2800
+ export {
2801
+ __spreadValues,
2802
+ __spreadProps,
2803
+ __objRest,
2804
+ __async,
2805
+ init_react_import,
2806
+ get_class_name_factory_default,
2807
+ reorder,
2808
+ replace,
2809
+ rootAreaId,
2810
+ rootZone,
2811
+ rootDroppableId,
2812
+ defaultSlots,
2813
+ walkField,
2814
+ expandNode,
2815
+ walkAppState,
2816
+ insert,
2817
+ generateId,
2818
+ walkTree,
2819
+ populateIds,
2820
+ insertAction,
2821
+ getItem,
2822
+ setupZone,
2823
+ makeStatePublic,
2824
+ defaultViewports,
2825
+ monitorHotkeys,
2826
+ useMonitorHotkeys,
2827
+ useHotkey,
2828
+ useRegisterHistorySlice,
2829
+ useRegisterPermissionsSlice,
2830
+ useRegisterFieldsSlice,
2831
+ defaultAppState,
2832
+ createAppStore,
2833
+ appStoreContext,
2834
+ useAppStore,
2835
+ useAppStoreApi,
2836
+ getBox,
2837
+ useResetAutoZoom,
2838
+ useFieldTransforms,
2839
+ registerOverlayPortal,
2840
+ setDeep,
2841
+ getSlotTransform,
2842
+ getInlineTextTransform,
2843
+ useSlots,
2844
+ Render,
2845
+ SlotRenderPure,
2846
+ SlotRender,
2847
+ migrate,
2848
+ transformProps,
2849
+ resolveAllData
2850
+ };
2851
+ /*! Bundled license information:
2852
+
2853
+ classnames/index.js:
2854
+ (*!
2855
+ Copyright (c) 2018 Jed Watson.
2856
+ Licensed under the MIT License (MIT), see
2857
+ http://jedwatson.github.io/classnames
2858
+ *)
2859
+ */