@measured/puck 0.19.0-canary.32a6f78 → 0.19.0-canary.4b545576

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.
package/dist/rsc.js CHANGED
@@ -9,6 +9,9 @@ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
9
  var __getProtoOf = Object.getPrototypeOf;
10
10
  var __hasOwnProp = Object.prototype.hasOwnProperty;
11
11
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __typeError = (msg) => {
13
+ throw TypeError(msg);
14
+ };
12
15
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
16
  var __spreadValues = (a, b) => {
14
17
  for (var prop in b || (b = {}))
@@ -22,6 +25,24 @@ var __spreadValues = (a, b) => {
22
25
  return a;
23
26
  };
24
27
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
28
+ var __objRest = (source, exclude) => {
29
+ var target = {};
30
+ for (var prop in source)
31
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
32
+ target[prop] = source[prop];
33
+ if (source != null && __getOwnPropSymbols)
34
+ for (var prop of __getOwnPropSymbols(source)) {
35
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
36
+ target[prop] = source[prop];
37
+ }
38
+ return target;
39
+ };
40
+ var __esm = (fn, res) => function __init() {
41
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
42
+ };
43
+ var __commonJS = (cb, mod) => function __require() {
44
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
45
+ };
25
46
  var __export = (target, all) => {
26
47
  for (var name in all)
27
48
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -43,6 +64,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
43
64
  mod
44
65
  ));
45
66
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
67
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
68
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
69
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
70
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
46
71
  var __async = (__this, __arguments, generator) => {
47
72
  return new Promise((resolve, reject) => {
48
73
  var fulfilled = (value) => {
@@ -64,21 +89,98 @@ var __async = (__this, __arguments, generator) => {
64
89
  });
65
90
  };
66
91
 
92
+ // ../tsup-config/react-import.js
93
+ var import_react;
94
+ var init_react_import = __esm({
95
+ "../tsup-config/react-import.js"() {
96
+ "use strict";
97
+ import_react = __toESM(require("react"));
98
+ }
99
+ });
100
+
101
+ // ../../node_modules/classnames/index.js
102
+ var require_classnames = __commonJS({
103
+ "../../node_modules/classnames/index.js"(exports2, module2) {
104
+ "use strict";
105
+ init_react_import();
106
+ (function() {
107
+ "use strict";
108
+ var hasOwn = {}.hasOwnProperty;
109
+ function classNames() {
110
+ var classes = "";
111
+ for (var i = 0; i < arguments.length; i++) {
112
+ var arg = arguments[i];
113
+ if (arg) {
114
+ classes = appendClass(classes, parseValue(arg));
115
+ }
116
+ }
117
+ return classes;
118
+ }
119
+ function parseValue(arg) {
120
+ if (typeof arg === "string" || typeof arg === "number") {
121
+ return arg;
122
+ }
123
+ if (typeof arg !== "object") {
124
+ return "";
125
+ }
126
+ if (Array.isArray(arg)) {
127
+ return classNames.apply(null, arg);
128
+ }
129
+ if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
130
+ return arg.toString();
131
+ }
132
+ var classes = "";
133
+ for (var key in arg) {
134
+ if (hasOwn.call(arg, key) && arg[key]) {
135
+ classes = appendClass(classes, key);
136
+ }
137
+ }
138
+ return classes;
139
+ }
140
+ function appendClass(value, newClass) {
141
+ if (!newClass) {
142
+ return value;
143
+ }
144
+ if (value) {
145
+ return value + " " + newClass;
146
+ }
147
+ return value + newClass;
148
+ }
149
+ if (typeof module2 !== "undefined" && module2.exports) {
150
+ classNames.default = classNames;
151
+ module2.exports = classNames;
152
+ } else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
153
+ define("classnames", [], function() {
154
+ return classNames;
155
+ });
156
+ } else {
157
+ window.classNames = classNames;
158
+ }
159
+ })();
160
+ }
161
+ });
162
+
67
163
  // rsc.tsx
68
164
  var rsc_exports = {};
69
165
  __export(rsc_exports, {
70
166
  Render: () => Render,
71
- resolveAllData: () => resolveAllData
167
+ resolveAllData: () => resolveAllData,
168
+ transformProps: () => transformProps
72
169
  });
73
170
  module.exports = __toCommonJS(rsc_exports);
171
+ init_react_import();
74
172
 
75
- // ../tsup-config/react-import.js
76
- var import_react = __toESM(require("react"));
173
+ // components/ServerRender/index.tsx
174
+ init_react_import();
77
175
 
78
176
  // lib/root-droppable-id.ts
79
- var rootDroppableId = "default-zone";
177
+ init_react_import();
178
+ var rootAreaId = "root";
179
+ var rootZone = "default-zone";
180
+ var rootDroppableId = `${rootAreaId}:${rootZone}`;
80
181
 
81
- // lib/setup-zone.ts
182
+ // lib/data/setup-zone.ts
183
+ init_react_import();
82
184
  var setupZone = (data, zoneKey) => {
83
185
  if (zoneKey === rootDroppableId) {
84
186
  return data;
@@ -90,232 +192,3823 @@ var setupZone = (data, zoneKey) => {
90
192
  return newData;
91
193
  };
92
194
 
93
- // components/ServerRender/index.tsx
94
- var import_jsx_runtime = require("react/jsx-runtime");
95
- function DropZoneRender({
96
- zone,
97
- data,
98
- areaId = "root",
99
- config,
100
- metadata = {}
101
- }) {
102
- let zoneCompound = rootDroppableId;
103
- let content = (data == null ? void 0 : data.content) || [];
104
- if (!data || !config) {
105
- return null;
106
- }
107
- if (areaId && zone && zone !== rootDroppableId) {
108
- zoneCompound = `${areaId}:${zone}`;
109
- content = setupZone(data, zoneCompound).zones[zoneCompound];
110
- }
111
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: content.map((item) => {
112
- const Component = config.components[item.type];
113
- if (Component) {
114
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
115
- Component.render,
116
- __spreadProps(__spreadValues({}, item.props), {
117
- puck: {
118
- renderDropZone: ({ zone: zone2 }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
119
- DropZoneRender,
120
- {
121
- zone: zone2,
122
- data,
123
- areaId: item.props.id,
124
- config,
125
- metadata
126
- }
127
- ),
128
- metadata
129
- }
130
- }),
131
- item.props.id
132
- );
195
+ // lib/use-slots.tsx
196
+ init_react_import();
197
+ var import_react2 = require("react");
198
+ function useSlots(config, props, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
199
+ const slotProps = (0, import_react2.useMemo)(() => {
200
+ if (!(config == null ? void 0 : config.fields)) return props;
201
+ const slotProps2 = {};
202
+ const fieldKeys = Object.keys(config.fields);
203
+ for (let i = 0; i < fieldKeys.length; i++) {
204
+ const fieldKey = fieldKeys[i];
205
+ const field = config.fields[fieldKey];
206
+ if ((field == null ? void 0 : field.type) === "slot") {
207
+ const content = props[fieldKey] || [];
208
+ const render = (readOnly == null ? void 0 : readOnly[fieldKey]) || forceReadOnly ? renderSlotRender : renderSlotEdit;
209
+ const Slot = (dzProps) => render(__spreadProps(__spreadValues({
210
+ allow: field.allow,
211
+ disallow: field.disallow
212
+ }, dzProps), {
213
+ zone: fieldKey,
214
+ content
215
+ }));
216
+ slotProps2[fieldKey] = Slot;
217
+ }
133
218
  }
134
- return null;
135
- }) });
219
+ return slotProps2;
220
+ }, [config, readOnly, forceReadOnly]);
221
+ return __spreadValues(__spreadValues({}, props), slotProps);
136
222
  }
137
- function Render({
138
- config,
139
- data,
140
- metadata
141
- }) {
142
- var _a;
143
- if ((_a = config.root) == null ? void 0 : _a.render) {
144
- const rootProps = data.root.props || data.root;
145
- const title = rootProps.title || "";
146
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
147
- config.root.render,
148
- __spreadProps(__spreadValues({}, rootProps), {
149
- puck: {
150
- renderDropZone: ({ zone }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
151
- DropZoneRender,
152
- {
153
- zone,
154
- data,
155
- config,
156
- metadata
157
- }
158
- ),
159
- isEditing: false,
160
- dragRef: null
161
- },
162
- title,
163
- editMode: false,
164
- id: "puck-root",
165
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
166
- DropZoneRender,
167
- {
168
- config,
169
- data,
170
- zone: rootDroppableId,
171
- metadata
172
- }
173
- )
174
- })
223
+
224
+ // components/SlotRender/index.tsx
225
+ init_react_import();
226
+ var import_react26 = require("react");
227
+
228
+ // components/DropZone/index.tsx
229
+ init_react_import();
230
+ var import_react25 = require("react");
231
+
232
+ // components/DraggableComponent/index.tsx
233
+ init_react_import();
234
+ var import_react13 = require("react");
235
+
236
+ // css-module:/home/runner/work/puck/puck/packages/core/components/DraggableComponent/styles.module.css#css-module
237
+ init_react_import();
238
+ var styles_module_default = { "DraggableComponent": "_DraggableComponent_qzbgx_1", "DraggableComponent-overlay": "_DraggableComponent-overlay_qzbgx_12", "DraggableComponent-loadingOverlay": "_DraggableComponent-loadingOverlay_qzbgx_29", "DraggableComponent--hover": "_DraggableComponent--hover_qzbgx_45", "DraggableComponent--isLocked": "_DraggableComponent--isLocked_qzbgx_45", "DraggableComponent--isSelected": "_DraggableComponent--isSelected_qzbgx_54", "DraggableComponent-actionsOverlay": "_DraggableComponent-actionsOverlay_qzbgx_66", "DraggableComponent-actions": "_DraggableComponent-actions_qzbgx_66" };
239
+
240
+ // lib/get-class-name-factory.ts
241
+ init_react_import();
242
+ var import_classnames = __toESM(require_classnames());
243
+ var getClassNameFactory = (rootClass, styles, config = { baseClass: "" }) => (options = {}) => {
244
+ if (typeof options === "string") {
245
+ const descendant = options;
246
+ const style = styles[`${rootClass}-${descendant}`];
247
+ if (style) {
248
+ return config.baseClass + styles[`${rootClass}-${descendant}`] || "";
249
+ }
250
+ return "";
251
+ } else if (typeof options === "object") {
252
+ const modifiers = options;
253
+ const prefixedModifiers = {};
254
+ for (let modifier in modifiers) {
255
+ prefixedModifiers[styles[`${rootClass}--${modifier}`]] = modifiers[modifier];
256
+ }
257
+ const c = styles[rootClass];
258
+ return config.baseClass + (0, import_classnames.default)(__spreadValues({
259
+ [c]: !!c
260
+ }, prefixedModifiers));
261
+ } else {
262
+ return config.baseClass + styles[rootClass] || "";
263
+ }
264
+ };
265
+ var get_class_name_factory_default = getClassNameFactory;
266
+
267
+ // ../../node_modules/lucide-react/dist/esm/lucide-react.js
268
+ init_react_import();
269
+
270
+ // ../../node_modules/lucide-react/dist/esm/createLucideIcon.js
271
+ init_react_import();
272
+ var import_react4 = require("react");
273
+
274
+ // ../../node_modules/lucide-react/dist/esm/shared/src/utils.js
275
+ init_react_import();
276
+ var toKebabCase = (string) => string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
277
+ var mergeClasses = (...classes) => classes.filter((className, index, array) => {
278
+ return Boolean(className) && className.trim() !== "" && array.indexOf(className) === index;
279
+ }).join(" ").trim();
280
+
281
+ // ../../node_modules/lucide-react/dist/esm/Icon.js
282
+ init_react_import();
283
+ var import_react3 = require("react");
284
+
285
+ // ../../node_modules/lucide-react/dist/esm/defaultAttributes.js
286
+ init_react_import();
287
+ var defaultAttributes = {
288
+ xmlns: "http://www.w3.org/2000/svg",
289
+ width: 24,
290
+ height: 24,
291
+ viewBox: "0 0 24 24",
292
+ fill: "none",
293
+ stroke: "currentColor",
294
+ strokeWidth: 2,
295
+ strokeLinecap: "round",
296
+ strokeLinejoin: "round"
297
+ };
298
+
299
+ // ../../node_modules/lucide-react/dist/esm/Icon.js
300
+ var Icon = (0, import_react3.forwardRef)(
301
+ (_a, ref) => {
302
+ var _b = _a, {
303
+ color = "currentColor",
304
+ size = 24,
305
+ strokeWidth = 2,
306
+ absoluteStrokeWidth,
307
+ className = "",
308
+ children,
309
+ iconNode
310
+ } = _b, rest = __objRest(_b, [
311
+ "color",
312
+ "size",
313
+ "strokeWidth",
314
+ "absoluteStrokeWidth",
315
+ "className",
316
+ "children",
317
+ "iconNode"
318
+ ]);
319
+ return (0, import_react3.createElement)(
320
+ "svg",
321
+ __spreadValues(__spreadProps(__spreadValues({
322
+ ref
323
+ }, defaultAttributes), {
324
+ width: size,
325
+ height: size,
326
+ stroke: color,
327
+ strokeWidth: absoluteStrokeWidth ? Number(strokeWidth) * 24 / Number(size) : strokeWidth,
328
+ className: mergeClasses("lucide", className)
329
+ }), rest),
330
+ [
331
+ ...iconNode.map(([tag, attrs]) => (0, import_react3.createElement)(tag, attrs)),
332
+ ...Array.isArray(children) ? children : [children]
333
+ ]
175
334
  );
176
335
  }
177
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
178
- DropZoneRender,
179
- {
180
- config,
181
- data,
182
- zone: rootDroppableId,
183
- metadata
336
+ );
337
+
338
+ // ../../node_modules/lucide-react/dist/esm/createLucideIcon.js
339
+ var createLucideIcon = (iconName, iconNode) => {
340
+ const Component = (0, import_react4.forwardRef)(
341
+ (_a, ref) => {
342
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
343
+ return (0, import_react4.createElement)(Icon, __spreadValues({
344
+ ref,
345
+ iconNode,
346
+ className: mergeClasses(`lucide-${toKebabCase(iconName)}`, className)
347
+ }, props));
184
348
  }
185
349
  );
350
+ Component.displayName = `${iconName}`;
351
+ return Component;
352
+ };
353
+
354
+ // ../../node_modules/lucide-react/dist/esm/icons/copy.js
355
+ init_react_import();
356
+ var Copy = createLucideIcon("Copy", [
357
+ ["rect", { width: "14", height: "14", x: "8", y: "8", rx: "2", ry: "2", key: "17jyea" }],
358
+ ["path", { d: "M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2", key: "zix9uf" }]
359
+ ]);
360
+
361
+ // ../../node_modules/lucide-react/dist/esm/icons/corner-left-up.js
362
+ init_react_import();
363
+ var CornerLeftUp = createLucideIcon("CornerLeftUp", [
364
+ ["polyline", { points: "14 9 9 4 4 9", key: "m9oyvo" }],
365
+ ["path", { d: "M20 20h-7a4 4 0 0 1-4-4V4", key: "1blwi3" }]
366
+ ]);
367
+
368
+ // ../../node_modules/lucide-react/dist/esm/icons/trash.js
369
+ init_react_import();
370
+ var Trash = createLucideIcon("Trash", [
371
+ ["path", { d: "M3 6h18", key: "d0wm0j" }],
372
+ ["path", { d: "M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6", key: "4alrt4" }],
373
+ ["path", { d: "M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2", key: "v07s0e" }]
374
+ ]);
375
+
376
+ // store/index.ts
377
+ init_react_import();
378
+
379
+ // reducer/index.ts
380
+ init_react_import();
381
+
382
+ // reducer/actions/set.ts
383
+ init_react_import();
384
+
385
+ // lib/data/walk-tree.ts
386
+ init_react_import();
387
+
388
+ // lib/data/for-each-slot.ts
389
+ init_react_import();
390
+
391
+ // lib/data/is-slot.ts
392
+ init_react_import();
393
+ var isSlot = (prop) => {
394
+ var _a, _b;
395
+ return Array.isArray(prop) && typeof ((_a = prop[0]) == null ? void 0 : _a.type) === "string" && typeof ((_b = prop[0]) == null ? void 0 : _b.props) === "object";
396
+ };
397
+ var createIsSlotConfig = (config) => (itemType, propName, propValue) => {
398
+ var _a, _b;
399
+ const configForComponent = itemType === "root" ? config == null ? void 0 : config.root : config == null ? void 0 : config.components[itemType];
400
+ if (!configForComponent) return isSlot(propValue);
401
+ return ((_b = (_a = configForComponent.fields) == null ? void 0 : _a[propName]) == null ? void 0 : _b.type) === "slot";
402
+ };
403
+
404
+ // lib/data/for-each-slot.ts
405
+ var forEachSlot = (item, cb, recursive = false, isSlot2 = isSlot) => {
406
+ const props = item.props || {};
407
+ const propKeys = Object.keys(props);
408
+ for (let i = 0; i < propKeys.length; i++) {
409
+ const propKey = propKeys[i];
410
+ const itemType = "type" in item ? item.type : "root";
411
+ if (isSlot2(itemType, propKey, props[propKey])) {
412
+ const content = props[propKey];
413
+ cb(props.id, propKey, content);
414
+ if (recursive) {
415
+ content.forEach(
416
+ (childItem) => __async(void 0, null, function* () {
417
+ return forEachSlot(childItem, cb, true, isSlot2);
418
+ })
419
+ );
420
+ }
421
+ }
422
+ }
423
+ };
424
+
425
+ // lib/data/for-related-zones.ts
426
+ init_react_import();
427
+
428
+ // lib/get-zone-id.ts
429
+ init_react_import();
430
+ var getZoneId = (zoneCompound) => {
431
+ if (!zoneCompound) {
432
+ return [];
433
+ }
434
+ if (zoneCompound && zoneCompound.indexOf(":") > -1) {
435
+ return zoneCompound.split(":");
436
+ }
437
+ return [rootDroppableId, zoneCompound];
438
+ };
439
+
440
+ // lib/data/for-related-zones.ts
441
+ function forRelatedZones(item, data, cb, path = []) {
442
+ Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
443
+ const [parentId] = getZoneId(zoneCompound);
444
+ if (parentId === item.props.id) {
445
+ cb(path, zoneCompound, content);
446
+ }
447
+ });
186
448
  }
187
449
 
188
- // lib/get-changed.ts
189
- var getChanged = (newItem, oldItem) => {
190
- return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
191
- const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
192
- const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
193
- return __spreadProps(__spreadValues({}, acc), {
194
- [item]: oldItemProps[item] !== newItemProps[item]
195
- });
196
- }, {}) : {};
450
+ // lib/data/strip-slots.ts
451
+ init_react_import();
452
+ var stripSlots = (data) => {
453
+ return __spreadProps(__spreadValues({}, data), {
454
+ props: Object.entries(data.props).reduce(
455
+ (acc, [propKey, propVal]) => {
456
+ if (isSlot(propVal)) {
457
+ return acc;
458
+ }
459
+ return __spreadProps(__spreadValues({}, acc), { [propKey]: propVal });
460
+ },
461
+ { id: data.props.id }
462
+ )
463
+ });
197
464
  };
198
465
 
199
- // lib/resolve-component-data.ts
200
- var cache = { lastChange: {} };
201
- var resolveAllComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (content, config, metadata = {}, onResolveStart, onResolveEnd) {
202
- return yield Promise.all(
203
- content.map((item) => __async(void 0, null, function* () {
204
- return yield resolveComponentData(
205
- item,
206
- config,
207
- metadata,
208
- onResolveStart,
209
- onResolveEnd
210
- );
211
- }))
466
+ // lib/data/walk-tree.ts
467
+ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
468
+ var _a;
469
+ let newZones = {};
470
+ const newZoneIndex = {};
471
+ const newNodeIndex = {};
472
+ const processContent = (path, zoneCompound, content, zoneType, newId) => {
473
+ var _a2;
474
+ const [parentId] = zoneCompound.split(":");
475
+ const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
476
+ const [_2, zone] = zoneCompound.split(":");
477
+ const newZoneCompound = `${newId || parentId}:${zone}`;
478
+ const newContent2 = mappedContent.map(
479
+ (zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
480
+ );
481
+ newZoneIndex[newZoneCompound] = {
482
+ contentIds: newContent2.map((item) => item.props.id),
483
+ type: zoneType
484
+ };
485
+ return [newZoneCompound, newContent2];
486
+ };
487
+ const processRelatedZones = (item, newId, initialPath) => {
488
+ forRelatedZones(
489
+ item,
490
+ state.data,
491
+ (relatedPath, relatedZoneCompound, relatedContent) => {
492
+ const [zoneCompound, newContent2] = processContent(
493
+ relatedPath,
494
+ relatedZoneCompound,
495
+ relatedContent,
496
+ "dropzone",
497
+ newId
498
+ );
499
+ newZones[zoneCompound] = newContent2;
500
+ },
501
+ initialPath
502
+ );
503
+ };
504
+ const processItem = (item, path, index) => {
505
+ const mappedItem = mapNodeOrSkip(item, path, index);
506
+ if (!mappedItem) return item;
507
+ const id = mappedItem.props.id;
508
+ const newProps = __spreadValues({}, mappedItem.props);
509
+ forEachSlot(
510
+ mappedItem,
511
+ (parentId2, slotId, content) => {
512
+ const zoneCompound = `${parentId2}:${slotId}`;
513
+ const [_2, newContent2] = processContent(
514
+ path,
515
+ zoneCompound,
516
+ content,
517
+ "slot",
518
+ parentId2
519
+ );
520
+ newProps[slotId] = newContent2;
521
+ },
522
+ false,
523
+ createIsSlotConfig(config)
524
+ );
525
+ processRelatedZones(item, id, path);
526
+ const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
527
+ const thisZoneCompound = path[path.length - 1];
528
+ const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
529
+ newNodeIndex[id] = {
530
+ data: newItem,
531
+ flatData: stripSlots(newItem),
532
+ path,
533
+ parentId,
534
+ zone
535
+ };
536
+ const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
537
+ if (newProps.id === "root") {
538
+ delete finalData["type"];
539
+ delete finalData.props["id"];
540
+ }
541
+ return finalData;
542
+ };
543
+ const zones = state.data.zones || {};
544
+ const [_, newContent] = processContent(
545
+ [],
546
+ rootDroppableId,
547
+ state.data.content,
548
+ "root"
212
549
  );
213
- });
214
- var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd) {
215
- const configForItem = config.components[item.type];
216
- if (configForItem.resolveData) {
217
- const { item: oldItem = null, resolved = {} } = cache.lastChange[item.props.id] || {};
218
- if (item && item === oldItem) {
219
- return resolved;
550
+ const processedContent = newContent;
551
+ const zonesAlreadyProcessed = Object.keys(newZones);
552
+ Object.keys(zones || {}).forEach((zoneCompound) => {
553
+ const [parentId] = zoneCompound.split(":");
554
+ if (zonesAlreadyProcessed.includes(zoneCompound)) {
555
+ return;
220
556
  }
221
- const changed = getChanged(item, oldItem);
222
- if (onResolveStart) {
223
- onResolveStart(item);
557
+ const [_2, newContent2] = processContent(
558
+ [rootDroppableId],
559
+ zoneCompound,
560
+ zones[zoneCompound],
561
+ "dropzone",
562
+ parentId
563
+ );
564
+ newZones[zoneCompound] = newContent2;
565
+ }, newZones);
566
+ const processedRoot = processItem(
567
+ {
568
+ type: "root",
569
+ props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
570
+ },
571
+ [],
572
+ -1
573
+ );
574
+ const root = __spreadProps(__spreadValues({}, state.data.root), {
575
+ props: processedRoot.props
576
+ });
577
+ return __spreadProps(__spreadValues({}, state), {
578
+ data: {
579
+ root,
580
+ content: processedContent,
581
+ zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
582
+ },
583
+ indexes: {
584
+ nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
585
+ zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
224
586
  }
225
- const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
226
- changed,
227
- lastData: oldItem,
228
- metadata
229
- });
230
- const resolvedItem = __spreadProps(__spreadValues({}, item), {
231
- props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
232
- });
233
- if (Object.keys(readOnly).length) {
234
- resolvedItem.readOnly = readOnly;
587
+ });
588
+ }
589
+
590
+ // reducer/actions/set.ts
591
+ var setAction = (state, action, appStore) => {
592
+ if (typeof action.state === "object") {
593
+ const newState = __spreadValues(__spreadValues({}, state), action.state);
594
+ if (action.state.indexes) {
595
+ return newState;
235
596
  }
236
- cache.lastChange[item.props.id] = {
237
- item,
238
- resolved: resolvedItem
239
- };
240
- if (onResolveEnd) {
241
- onResolveEnd(resolvedItem);
597
+ console.warn(
598
+ "`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
599
+ );
600
+ return walkTree(newState, appStore.config);
601
+ }
602
+ return __spreadValues(__spreadValues({}, state), action.state(state));
603
+ };
604
+
605
+ // reducer/actions/insert.ts
606
+ init_react_import();
607
+
608
+ // lib/data/insert.ts
609
+ init_react_import();
610
+ var insert = (list, index, item) => {
611
+ const result = Array.from(list || []);
612
+ result.splice(index, 0, item);
613
+ return result;
614
+ };
615
+
616
+ // lib/generate-id.ts
617
+ init_react_import();
618
+ var import_uuid = require("uuid");
619
+ var generateId = (type) => type ? `${type}-${(0, import_uuid.v4)()}` : (0, import_uuid.v4)();
620
+
621
+ // lib/data/get-ids-for-parent.ts
622
+ init_react_import();
623
+ var getIdsForParent = (zoneCompound, state) => {
624
+ const [parentId] = zoneCompound.split(":");
625
+ const node = state.indexes.nodes[parentId];
626
+ return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
627
+ };
628
+
629
+ // reducer/actions/insert.ts
630
+ function insertAction(state, action, appStore) {
631
+ const id = action.id || generateId(action.componentType);
632
+ const emptyComponentData = {
633
+ type: action.componentType,
634
+ props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
635
+ id
636
+ })
637
+ };
638
+ const [parentId] = action.destinationZone.split(":");
639
+ const idsInPath = getIdsForParent(action.destinationZone, state);
640
+ return walkTree(
641
+ state,
642
+ appStore.config,
643
+ (content, zoneCompound) => {
644
+ if (zoneCompound === action.destinationZone) {
645
+ return insert(
646
+ content || [],
647
+ action.destinationIndex,
648
+ emptyComponentData
649
+ );
650
+ }
651
+ return content;
652
+ },
653
+ (childItem, path) => {
654
+ if (childItem.props.id === id || childItem.props.id === parentId) {
655
+ return childItem;
656
+ } else if (idsInPath.includes(childItem.props.id)) {
657
+ return childItem;
658
+ } else if (path.includes(action.destinationZone)) {
659
+ return childItem;
660
+ }
661
+ return null;
242
662
  }
243
- return resolvedItem;
663
+ );
664
+ }
665
+
666
+ // reducer/actions/replace.ts
667
+ init_react_import();
668
+ var replaceAction = (state, action, appStore) => {
669
+ const [parentId] = action.destinationZone.split(":");
670
+ const idsInPath = getIdsForParent(action.destinationZone, state);
671
+ const originalId = state.indexes.zones[action.destinationZone].contentIds[action.destinationIndex];
672
+ const idChanged = originalId !== action.data.props.id;
673
+ if (idChanged) {
674
+ throw new Error(
675
+ `Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
676
+ );
244
677
  }
245
- return item;
246
- });
678
+ return walkTree(
679
+ state,
680
+ appStore.config,
681
+ (content, zoneCompound) => {
682
+ const newContent = [...content];
683
+ if (zoneCompound === action.destinationZone) {
684
+ newContent[action.destinationIndex] = action.data;
685
+ }
686
+ return newContent;
687
+ },
688
+ (childItem, path) => {
689
+ const pathIds = path.map((p) => p.split(":")[0]);
690
+ if (childItem.props.id === action.data.props.id) {
691
+ return action.data;
692
+ } else if (childItem.props.id === parentId) {
693
+ return childItem;
694
+ } else if (idsInPath.indexOf(childItem.props.id) > -1) {
695
+ return childItem;
696
+ } else if (pathIds.indexOf(action.data.props.id) > -1) {
697
+ return childItem;
698
+ }
699
+ return null;
700
+ }
701
+ );
702
+ };
247
703
 
248
- // lib/resolve-root-data.ts
249
- var cache2 = {};
250
- function resolveRootData(data, config, metadata) {
251
- return __async(this, null, function* () {
252
- var _a, _b, _c, _d, _e;
253
- if (((_a = config.root) == null ? void 0 : _a.resolveData) && data.root.props) {
254
- if (((_b = cache2.lastChange) == null ? void 0 : _b.original) === data.root) {
255
- return cache2.lastChange.resolved;
256
- }
257
- const changed = getChanged(data.root, (_c = cache2.lastChange) == null ? void 0 : _c.original);
258
- const rootWithProps = data.root;
259
- const resolvedRoot = yield (_e = config.root) == null ? void 0 : _e.resolveData(rootWithProps, {
260
- changed,
261
- lastData: ((_d = cache2.lastChange) == null ? void 0 : _d.original) || {},
262
- metadata: metadata || {}
263
- });
264
- cache2.lastChange = {
265
- original: data.root,
266
- resolved: resolvedRoot
267
- };
268
- return __spreadProps(__spreadValues(__spreadValues({}, data.root), resolvedRoot), {
269
- props: __spreadValues(__spreadValues({}, data.root.props), resolvedRoot.props)
270
- });
704
+ // reducer/actions/replace-root.ts
705
+ init_react_import();
706
+ var replaceRootAction = (state, action, appStore) => {
707
+ return walkTree(
708
+ state,
709
+ appStore.config,
710
+ (content) => content,
711
+ (childItem) => {
712
+ if (childItem.props.id === "root") {
713
+ return __spreadProps(__spreadValues({}, childItem), {
714
+ props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
715
+ readOnly: action.root.readOnly
716
+ });
717
+ }
718
+ return childItem;
719
+ }
720
+ );
721
+ };
722
+
723
+ // reducer/actions/duplicate.ts
724
+ init_react_import();
725
+
726
+ // lib/data/get-item.ts
727
+ init_react_import();
728
+ function getItem(selector, state) {
729
+ var _a, _b;
730
+ const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
731
+ return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
732
+ }
733
+
734
+ // reducer/actions/duplicate.ts
735
+ function duplicateAction(state, action, appStore) {
736
+ const item = getItem(
737
+ { index: action.sourceIndex, zone: action.sourceZone },
738
+ state
739
+ );
740
+ const idsInPath = getIdsForParent(action.sourceZone, state);
741
+ const newItem = __spreadProps(__spreadValues({}, item), {
742
+ props: __spreadProps(__spreadValues({}, item.props), {
743
+ id: generateId(item.type)
744
+ })
745
+ });
746
+ const modified = walkTree(
747
+ state,
748
+ appStore.config,
749
+ (content, zoneCompound) => {
750
+ if (zoneCompound === action.sourceZone) {
751
+ return insert(content, action.sourceIndex + 1, item);
752
+ }
753
+ return content;
754
+ },
755
+ (childItem, path, index) => {
756
+ const zoneCompound = path[path.length - 1];
757
+ const parents = path.map((p) => p.split(":")[0]);
758
+ if (parents.indexOf(newItem.props.id) > -1) {
759
+ return __spreadProps(__spreadValues({}, childItem), {
760
+ props: __spreadProps(__spreadValues({}, childItem.props), {
761
+ id: generateId(childItem.type)
762
+ })
763
+ });
764
+ }
765
+ if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
766
+ return newItem;
767
+ }
768
+ const [sourceZoneParent] = action.sourceZone.split(":");
769
+ if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
770
+ return childItem;
771
+ }
772
+ return null;
271
773
  }
272
- return data.root;
774
+ );
775
+ return __spreadProps(__spreadValues({}, modified), {
776
+ ui: __spreadProps(__spreadValues({}, modified.ui), {
777
+ itemSelector: {
778
+ index: action.sourceIndex + 1,
779
+ zone: action.sourceZone
780
+ }
781
+ })
273
782
  });
274
783
  }
275
784
 
276
- // lib/default-data.ts
277
- var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
278
- root: data.root || {},
279
- content: data.content || []
280
- });
785
+ // reducer/actions/reorder.ts
786
+ init_react_import();
281
787
 
282
- // lib/resolve-all-data.ts
283
- function resolveAllData(_0, _1) {
284
- return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
285
- const defaultedData = defaultData(data);
286
- const dynamicRoot = yield resolveRootData(
287
- defaultedData,
288
- config,
289
- metadata
290
- );
291
- const { zones = {} } = data;
292
- const zoneKeys = Object.keys(zones);
293
- const resolvedZones = {};
294
- for (let i = 0; i < zoneKeys.length; i++) {
295
- const zoneKey = zoneKeys[i];
296
- resolvedZones[zoneKey] = yield resolveAllComponentData(
297
- zones[zoneKey],
298
- config,
299
- metadata,
300
- onResolveStart,
301
- onResolveEnd
302
- );
788
+ // reducer/actions/move.ts
789
+ init_react_import();
790
+
791
+ // lib/data/remove.ts
792
+ init_react_import();
793
+ var remove = (list, index) => {
794
+ const result = Array.from(list);
795
+ result.splice(index, 1);
796
+ return result;
797
+ };
798
+
799
+ // reducer/actions/move.ts
800
+ var moveAction = (state, action, appStore) => {
801
+ if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
802
+ return state;
803
+ }
804
+ const item = getItem(
805
+ { zone: action.sourceZone, index: action.sourceIndex },
806
+ state
807
+ );
808
+ if (!item) return state;
809
+ const idsInSourcePath = getIdsForParent(action.sourceZone, state);
810
+ const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
811
+ return walkTree(
812
+ state,
813
+ appStore.config,
814
+ (content, zoneCompound) => {
815
+ if (zoneCompound === action.sourceZone && zoneCompound === action.destinationZone) {
816
+ return insert(
817
+ remove(content, action.sourceIndex),
818
+ action.destinationIndex,
819
+ item
820
+ );
821
+ } else if (zoneCompound === action.sourceZone) {
822
+ return remove(content, action.sourceIndex);
823
+ } else if (zoneCompound === action.destinationZone) {
824
+ return insert(content, action.destinationIndex, item);
825
+ }
826
+ return content;
827
+ },
828
+ (childItem, path) => {
829
+ const [sourceZoneParent] = action.sourceZone.split(":");
830
+ const [destinationZoneParent] = action.destinationZone.split(":");
831
+ const childId = childItem.props.id;
832
+ if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1 || path.includes(action.destinationZone)) {
833
+ return childItem;
834
+ }
835
+ return null;
303
836
  }
304
- return __spreadProps(__spreadValues({}, defaultedData), {
305
- root: dynamicRoot,
306
- content: yield resolveAllComponentData(
307
- defaultedData.content,
308
- config,
309
- metadata,
310
- onResolveStart,
311
- onResolveEnd
312
- ),
313
- zones: resolvedZones
837
+ );
838
+ };
839
+
840
+ // reducer/actions/reorder.ts
841
+ var reorderAction = (state, action, appStore) => {
842
+ return moveAction(
843
+ state,
844
+ {
845
+ type: "move",
846
+ sourceIndex: action.sourceIndex,
847
+ sourceZone: action.destinationZone,
848
+ destinationIndex: action.destinationIndex,
849
+ destinationZone: action.destinationZone
850
+ },
851
+ appStore
852
+ );
853
+ };
854
+
855
+ // reducer/actions/remove.ts
856
+ init_react_import();
857
+ var removeAction = (state, action, appStore) => {
858
+ const item = getItem({ index: action.index, zone: action.zone }, state);
859
+ const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
860
+ (acc, [nodeId, nodeData]) => {
861
+ const pathIds = nodeData.path.map((p) => p.split(":")[0]);
862
+ if (pathIds.includes(item.props.id)) {
863
+ return [...acc, nodeId];
864
+ }
865
+ return acc;
866
+ },
867
+ [item.props.id]
868
+ );
869
+ const newState = walkTree(
870
+ state,
871
+ appStore.config,
872
+ (content, zoneCompound) => {
873
+ if (zoneCompound === action.zone) {
874
+ return remove(content, action.index);
875
+ }
876
+ return content;
877
+ }
878
+ );
879
+ Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
880
+ const parentId = zoneCompound.split(":")[0];
881
+ if (nodesToDelete.includes(parentId) && newState.data.zones) {
882
+ delete newState.data.zones[zoneCompound];
883
+ }
884
+ });
885
+ Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
886
+ const parentId = zoneCompound.split(":")[0];
887
+ if (nodesToDelete.includes(parentId)) {
888
+ delete newState.indexes.zones[zoneCompound];
889
+ }
890
+ });
891
+ nodesToDelete.forEach((id) => {
892
+ delete newState.indexes.nodes[id];
893
+ });
894
+ return newState;
895
+ };
896
+
897
+ // reducer/actions/register-zone.ts
898
+ init_react_import();
899
+ var zoneCache = {};
900
+ function registerZoneAction(state, action) {
901
+ if (zoneCache[action.zone]) {
902
+ return __spreadProps(__spreadValues({}, state), {
903
+ data: __spreadProps(__spreadValues({}, state.data), {
904
+ zones: __spreadProps(__spreadValues({}, state.data.zones), {
905
+ [action.zone]: zoneCache[action.zone]
906
+ })
907
+ }),
908
+ indexes: __spreadProps(__spreadValues({}, state.indexes), {
909
+ zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
910
+ [action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
911
+ contentIds: zoneCache[action.zone].map((item) => item.props.id),
912
+ type: "dropzone"
913
+ })
914
+ })
915
+ })
314
916
  });
917
+ }
918
+ return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
919
+ }
920
+ function unregisterZoneAction(state, action) {
921
+ const _zones = __spreadValues({}, state.data.zones || {});
922
+ const zoneIndex = __spreadValues({}, state.indexes.zones || {});
923
+ if (_zones[action.zone]) {
924
+ zoneCache[action.zone] = _zones[action.zone];
925
+ delete _zones[action.zone];
926
+ }
927
+ delete zoneIndex[action.zone];
928
+ return __spreadProps(__spreadValues({}, state), {
929
+ data: __spreadProps(__spreadValues({}, state.data), {
930
+ zones: _zones
931
+ }),
932
+ indexes: __spreadProps(__spreadValues({}, state.indexes), {
933
+ zones: zoneIndex
934
+ })
315
935
  });
316
936
  }
317
- // Annotate the CommonJS export names for ESM import in node:
318
- 0 && (module.exports = {
319
- Render,
320
- resolveAllData
321
- });
937
+
938
+ // reducer/actions/set-data.ts
939
+ init_react_import();
940
+ var setDataAction = (state, action, appStore) => {
941
+ if (typeof action.data === "object") {
942
+ console.warn(
943
+ "`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
944
+ );
945
+ return walkTree(
946
+ __spreadProps(__spreadValues({}, state), {
947
+ data: __spreadValues(__spreadValues({}, state.data), action.data)
948
+ }),
949
+ appStore.config
950
+ );
951
+ }
952
+ return walkTree(
953
+ __spreadProps(__spreadValues({}, state), {
954
+ data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
955
+ }),
956
+ appStore.config
957
+ );
958
+ };
959
+
960
+ // reducer/actions/set-ui.ts
961
+ init_react_import();
962
+ var setUiAction = (state, action) => {
963
+ if (typeof action.ui === "object") {
964
+ return __spreadProps(__spreadValues({}, state), {
965
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
966
+ });
967
+ }
968
+ return __spreadProps(__spreadValues({}, state), {
969
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
970
+ });
971
+ };
972
+
973
+ // lib/data/make-state-public.ts
974
+ init_react_import();
975
+ var makeStatePublic = (state) => {
976
+ const { data, ui } = state;
977
+ return { data, ui };
978
+ };
979
+
980
+ // reducer/actions.tsx
981
+ init_react_import();
982
+
983
+ // reducer/index.ts
984
+ function storeInterceptor(reducer, record, onAction) {
985
+ return (state, action) => {
986
+ const newAppState = reducer(state, action);
987
+ const isValidType = ![
988
+ "registerZone",
989
+ "unregisterZone",
990
+ "setData",
991
+ "setUi",
992
+ "set"
993
+ ].includes(action.type);
994
+ if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
995
+ if (record) record(newAppState);
996
+ }
997
+ onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
998
+ return newAppState;
999
+ };
1000
+ }
1001
+ function createReducer({
1002
+ record,
1003
+ onAction,
1004
+ appStore
1005
+ }) {
1006
+ return storeInterceptor(
1007
+ (state, action) => {
1008
+ if (action.type === "set") {
1009
+ return setAction(state, action, appStore);
1010
+ }
1011
+ if (action.type === "insert") {
1012
+ return insertAction(state, action, appStore);
1013
+ }
1014
+ if (action.type === "replace") {
1015
+ return replaceAction(state, action, appStore);
1016
+ }
1017
+ if (action.type === "replaceRoot") {
1018
+ return replaceRootAction(state, action, appStore);
1019
+ }
1020
+ if (action.type === "duplicate") {
1021
+ return duplicateAction(state, action, appStore);
1022
+ }
1023
+ if (action.type === "reorder") {
1024
+ return reorderAction(state, action, appStore);
1025
+ }
1026
+ if (action.type === "move") {
1027
+ return moveAction(state, action, appStore);
1028
+ }
1029
+ if (action.type === "remove") {
1030
+ return removeAction(state, action, appStore);
1031
+ }
1032
+ if (action.type === "registerZone") {
1033
+ return registerZoneAction(state, action);
1034
+ }
1035
+ if (action.type === "unregisterZone") {
1036
+ return unregisterZoneAction(state, action);
1037
+ }
1038
+ if (action.type === "setData") {
1039
+ return setDataAction(state, action, appStore);
1040
+ }
1041
+ if (action.type === "setUi") {
1042
+ return setUiAction(state, action);
1043
+ }
1044
+ return state;
1045
+ },
1046
+ record,
1047
+ onAction
1048
+ );
1049
+ }
1050
+
1051
+ // components/ViewportControls/default-viewports.ts
1052
+ init_react_import();
1053
+ var defaultViewports = [
1054
+ { width: 360, height: "auto", icon: "Smartphone", label: "Small" },
1055
+ { width: 768, height: "auto", icon: "Tablet", label: "Medium" },
1056
+ { width: 1280, height: "auto", icon: "Monitor", label: "Large" }
1057
+ ];
1058
+
1059
+ // store/index.ts
1060
+ var import_zustand2 = require("zustand");
1061
+ var import_middleware2 = require("zustand/middleware");
1062
+ var import_react9 = require("react");
1063
+
1064
+ // store/slices/history.ts
1065
+ init_react_import();
1066
+ var import_react6 = require("react");
1067
+
1068
+ // lib/use-hotkey.ts
1069
+ init_react_import();
1070
+ var import_react5 = require("react");
1071
+ var import_zustand = require("zustand");
1072
+ var import_middleware = require("zustand/middleware");
1073
+ var useHotkeyStore = (0, import_zustand.create)()(
1074
+ (0, import_middleware.subscribeWithSelector)((set) => ({
1075
+ held: {},
1076
+ hold: (key) => set((s) => s.held[key] ? s : { held: __spreadProps(__spreadValues({}, s.held), { [key]: true }) }),
1077
+ release: (key) => set((s) => s.held[key] ? { held: __spreadProps(__spreadValues({}, s.held), { [key]: false }) } : s),
1078
+ reset: (held = {}) => set(() => ({ held })),
1079
+ triggers: {}
1080
+ }))
1081
+ );
1082
+
1083
+ // store/slices/history.ts
1084
+ var EMPTY_HISTORY_INDEX = 0;
1085
+ function debounce(func, timeout2 = 300) {
1086
+ let timer;
1087
+ return (...args) => {
1088
+ clearTimeout(timer);
1089
+ timer = setTimeout(() => {
1090
+ func(...args);
1091
+ }, timeout2);
1092
+ };
1093
+ }
1094
+ var tidyState = (state) => {
1095
+ return __spreadProps(__spreadValues({}, state), {
1096
+ ui: __spreadProps(__spreadValues({}, state.ui), {
1097
+ field: {
1098
+ focus: null
1099
+ }
1100
+ })
1101
+ });
1102
+ };
1103
+ var createHistorySlice = (set, get) => {
1104
+ const record = debounce((state) => {
1105
+ const { histories, index } = get().history;
1106
+ const history = {
1107
+ state,
1108
+ id: generateId("history")
1109
+ };
1110
+ const newHistories = [...histories.slice(0, index + 1), history];
1111
+ set({
1112
+ history: __spreadProps(__spreadValues({}, get().history), {
1113
+ histories: newHistories,
1114
+ index: newHistories.length - 1
1115
+ })
1116
+ });
1117
+ }, 250);
1118
+ return {
1119
+ initialAppState: {},
1120
+ index: EMPTY_HISTORY_INDEX,
1121
+ histories: [],
1122
+ hasPast: () => get().history.index > EMPTY_HISTORY_INDEX,
1123
+ hasFuture: () => get().history.index < get().history.histories.length - 1,
1124
+ prevHistory: () => {
1125
+ const { history } = get();
1126
+ return history.hasPast() ? history.histories[history.index - 1] : null;
1127
+ },
1128
+ nextHistory: () => {
1129
+ const s = get().history;
1130
+ return s.hasFuture() ? s.histories[s.index + 1] : null;
1131
+ },
1132
+ currentHistory: () => get().history.histories[get().history.index],
1133
+ back: () => {
1134
+ var _a;
1135
+ const { history, dispatch } = get();
1136
+ if (history.hasPast()) {
1137
+ const state = tidyState(
1138
+ ((_a = history.prevHistory()) == null ? void 0 : _a.state) || history.initialAppState
1139
+ );
1140
+ dispatch({
1141
+ type: "set",
1142
+ state
1143
+ });
1144
+ set({ history: __spreadProps(__spreadValues({}, history), { index: history.index - 1 }) });
1145
+ }
1146
+ },
1147
+ forward: () => {
1148
+ var _a;
1149
+ const { history, dispatch } = get();
1150
+ if (history.hasFuture()) {
1151
+ const state = (_a = history.nextHistory()) == null ? void 0 : _a.state;
1152
+ dispatch({ type: "set", state: state ? tidyState(state) : {} });
1153
+ set({ history: __spreadProps(__spreadValues({}, history), { index: history.index + 1 }) });
1154
+ }
1155
+ },
1156
+ setHistories: (histories) => {
1157
+ var _a;
1158
+ const { dispatch, history } = get();
1159
+ dispatch({
1160
+ type: "set",
1161
+ state: ((_a = history.histories[history.histories.length - 1]) == null ? void 0 : _a.state) || history.initialAppState
1162
+ });
1163
+ set({ history: __spreadProps(__spreadValues({}, history), { histories, index: histories.length - 1 }) });
1164
+ },
1165
+ setHistoryIndex: (index) => {
1166
+ var _a;
1167
+ const { dispatch, history } = get();
1168
+ dispatch({
1169
+ type: "set",
1170
+ state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
1171
+ });
1172
+ set({ history: __spreadProps(__spreadValues({}, history), { index }) });
1173
+ },
1174
+ record
1175
+ };
1176
+ };
1177
+
1178
+ // store/slices/nodes.ts
1179
+ init_react_import();
1180
+ var createNodesSlice = (set, get) => ({
1181
+ nodes: {},
1182
+ registerNode: (id, node) => {
1183
+ const s = get().nodes;
1184
+ const emptyNode = {
1185
+ id,
1186
+ methods: { sync: () => null },
1187
+ element: null
1188
+ };
1189
+ const existingNode = s.nodes[id];
1190
+ set({
1191
+ nodes: __spreadProps(__spreadValues({}, s), {
1192
+ nodes: __spreadProps(__spreadValues({}, s.nodes), {
1193
+ [id]: __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, emptyNode), existingNode), node), {
1194
+ id
1195
+ })
1196
+ })
1197
+ })
1198
+ });
1199
+ },
1200
+ unregisterNode: (id) => {
1201
+ const s = get().nodes;
1202
+ const existingNode = s.nodes[id];
1203
+ if (existingNode) {
1204
+ const newNodes = __spreadValues({}, s.nodes);
1205
+ delete newNodes[id];
1206
+ set({
1207
+ nodes: __spreadProps(__spreadValues({}, s), {
1208
+ nodes: newNodes
1209
+ })
1210
+ });
1211
+ }
1212
+ }
1213
+ });
1214
+
1215
+ // store/slices/permissions.ts
1216
+ init_react_import();
1217
+ var import_react7 = require("react");
1218
+
1219
+ // lib/data/flatten-data.ts
1220
+ init_react_import();
1221
+ var flattenData = (state, config) => {
1222
+ const data = [];
1223
+ walkTree(
1224
+ state,
1225
+ config,
1226
+ (content) => content,
1227
+ (item) => {
1228
+ data.push(item);
1229
+ return null;
1230
+ }
1231
+ );
1232
+ return data;
1233
+ };
1234
+
1235
+ // lib/get-changed.ts
1236
+ init_react_import();
1237
+ var getChanged = (newItem, oldItem) => {
1238
+ return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
1239
+ const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
1240
+ const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
1241
+ return __spreadProps(__spreadValues({}, acc), {
1242
+ [item]: oldItemProps[item] !== newItemProps[item]
1243
+ });
1244
+ }, {}) : {};
1245
+ };
1246
+
1247
+ // store/slices/permissions.ts
1248
+ var createPermissionsSlice = (set, get) => {
1249
+ const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
1250
+ const { state, permissions, config } = get();
1251
+ const { cache: cache2, globalPermissions } = permissions;
1252
+ const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
1253
+ var _a, _b, _c;
1254
+ const { config: config2, state: appState, setComponentLoading } = get();
1255
+ const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
1256
+ if (!componentConfig) {
1257
+ return;
1258
+ }
1259
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
1260
+ if (componentConfig.resolvePermissions) {
1261
+ const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
1262
+ if (Object.values(changed).some((el) => el === true) || force2) {
1263
+ const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
1264
+ const resolvedPermissions = yield componentConfig.resolvePermissions(
1265
+ item2,
1266
+ {
1267
+ changed,
1268
+ lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1269
+ permissions: initialPermissions,
1270
+ appState: makeStatePublic(appState),
1271
+ lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
1272
+ }
1273
+ );
1274
+ const latest = get().permissions;
1275
+ set({
1276
+ permissions: __spreadProps(__spreadValues({}, latest), {
1277
+ cache: __spreadProps(__spreadValues({}, latest.cache), {
1278
+ [item2.props.id]: {
1279
+ lastData: item2,
1280
+ lastPermissions: resolvedPermissions
1281
+ }
1282
+ }),
1283
+ resolvedPermissions: __spreadProps(__spreadValues({}, latest.resolvedPermissions), {
1284
+ [item2.props.id]: resolvedPermissions
1285
+ })
1286
+ })
1287
+ });
1288
+ clearTimeout2();
1289
+ }
1290
+ }
1291
+ });
1292
+ const resolveDataForRoot = (force2 = false) => {
1293
+ const { state: appState } = get();
1294
+ resolveDataForItem(
1295
+ // Shim the root data in by conforming to component data shape
1296
+ {
1297
+ type: "root",
1298
+ props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
1299
+ },
1300
+ force2
1301
+ );
1302
+ };
1303
+ const { item, type, root } = params;
1304
+ if (item) {
1305
+ yield resolveDataForItem(item, force);
1306
+ } else if (type) {
1307
+ flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
1308
+ yield resolveDataForItem(item2, force);
1309
+ }));
1310
+ } else if (root) {
1311
+ resolveDataForRoot(force);
1312
+ } else {
1313
+ flattenData(state, config).map((item2) => __async(void 0, null, function* () {
1314
+ yield resolveDataForItem(item2, force);
1315
+ }));
1316
+ }
1317
+ });
1318
+ const refreshPermissions = (params) => resolvePermissions(params, true);
1319
+ return {
1320
+ cache: {},
1321
+ globalPermissions: {
1322
+ drag: true,
1323
+ edit: true,
1324
+ delete: true,
1325
+ duplicate: true,
1326
+ insert: true
1327
+ },
1328
+ resolvedPermissions: {},
1329
+ getPermissions: ({ item, type, root } = {}) => {
1330
+ const { config, permissions } = get();
1331
+ const { globalPermissions, resolvedPermissions } = permissions;
1332
+ if (item) {
1333
+ const componentConfig = config.components[item.type];
1334
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
1335
+ const resolvedForItem = resolvedPermissions[item.props.id];
1336
+ return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
1337
+ } else if (type) {
1338
+ const componentConfig = config.components[type];
1339
+ return __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
1340
+ } else if (root) {
1341
+ const rootConfig = config.root;
1342
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
1343
+ const resolvedForItem = resolvedPermissions["root"];
1344
+ return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
1345
+ }
1346
+ return globalPermissions;
1347
+ },
1348
+ resolvePermissions,
1349
+ refreshPermissions
1350
+ };
1351
+ };
1352
+
1353
+ // store/slices/fields.ts
1354
+ init_react_import();
1355
+ var import_react8 = require("react");
1356
+ var createFieldsSlice = (_set, _get) => {
1357
+ return {
1358
+ fields: {},
1359
+ loading: false,
1360
+ lastResolvedData: {}
1361
+ };
1362
+ };
1363
+
1364
+ // lib/resolve-component-data.ts
1365
+ init_react_import();
1366
+
1367
+ // lib/data/map-slots.ts
1368
+ init_react_import();
1369
+ function mapSlotsAsync(_0, _1) {
1370
+ return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
1371
+ const props = __spreadValues({}, item.props);
1372
+ const propKeys = Object.keys(props);
1373
+ for (let i = 0; i < propKeys.length; i++) {
1374
+ const propKey = propKeys[i];
1375
+ const itemType = "type" in item ? item.type : "root";
1376
+ if (isSlot2(itemType, propKey, props[propKey])) {
1377
+ const content = props[propKey];
1378
+ const mappedContent = recursive ? yield Promise.all(
1379
+ content.map((item2) => __async(this, null, function* () {
1380
+ return yield mapSlotsAsync(item2, map, recursive, isSlot2);
1381
+ }))
1382
+ ) : content;
1383
+ props[propKey] = yield map(mappedContent, propKey);
1384
+ }
1385
+ }
1386
+ return __spreadProps(__spreadValues({}, item), { props });
1387
+ });
1388
+ }
1389
+
1390
+ // lib/resolve-component-data.ts
1391
+ var import_fast_deep_equal = __toESM(require("fast-deep-equal"));
1392
+ var cache = { lastChange: {} };
1393
+ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", recursive = true) {
1394
+ const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
1395
+ if ((configForItem == null ? void 0 : configForItem.resolveData) && item.props) {
1396
+ const id = "id" in item.props ? item.props.id : "root";
1397
+ const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
1398
+ if (item && (0, import_fast_deep_equal.default)(item, oldItem)) {
1399
+ return { node: resolved, didChange: false };
1400
+ }
1401
+ const changed = getChanged(item, oldItem);
1402
+ if (onResolveStart) {
1403
+ onResolveStart(item);
1404
+ }
1405
+ const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
1406
+ changed,
1407
+ lastData: oldItem,
1408
+ metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
1409
+ trigger
1410
+ });
1411
+ let resolvedItem = __spreadProps(__spreadValues({}, item), {
1412
+ props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
1413
+ });
1414
+ if (recursive) {
1415
+ resolvedItem = yield mapSlotsAsync(
1416
+ resolvedItem,
1417
+ (content) => __async(void 0, null, function* () {
1418
+ return Promise.all(
1419
+ content.map(
1420
+ (childItem) => __async(void 0, null, function* () {
1421
+ return (yield resolveComponentData(
1422
+ childItem,
1423
+ config,
1424
+ metadata,
1425
+ onResolveStart,
1426
+ onResolveEnd,
1427
+ trigger,
1428
+ false
1429
+ )).node;
1430
+ })
1431
+ )
1432
+ );
1433
+ }),
1434
+ false,
1435
+ createIsSlotConfig(config)
1436
+ );
1437
+ }
1438
+ if (Object.keys(readOnly).length) {
1439
+ resolvedItem.readOnly = readOnly;
1440
+ }
1441
+ cache.lastChange[id] = {
1442
+ item,
1443
+ resolved: resolvedItem
1444
+ };
1445
+ if (onResolveEnd) {
1446
+ onResolveEnd(resolvedItem);
1447
+ }
1448
+ return { node: resolvedItem, didChange: !(0, import_fast_deep_equal.default)(item, resolvedItem) };
1449
+ }
1450
+ return { node: item, didChange: false };
1451
+ });
1452
+
1453
+ // lib/data/to-root.ts
1454
+ init_react_import();
1455
+ var toRoot = (item) => {
1456
+ if ("type" in item && item.type !== "root") {
1457
+ throw new Error("Converting non-root item to root.");
1458
+ }
1459
+ const { readOnly } = item;
1460
+ if (item.props) {
1461
+ if ("id" in item.props) {
1462
+ const _a = item.props, { id } = _a, props = __objRest(_a, ["id"]);
1463
+ return { props, readOnly };
1464
+ }
1465
+ return { props: item.props, readOnly };
1466
+ }
1467
+ return { props: {}, readOnly };
1468
+ };
1469
+
1470
+ // store/index.ts
1471
+ var defaultAppState = {
1472
+ data: { content: [], root: {}, zones: {} },
1473
+ ui: {
1474
+ leftSideBarVisible: true,
1475
+ rightSideBarVisible: true,
1476
+ arrayState: {},
1477
+ itemSelector: null,
1478
+ componentList: {},
1479
+ isDragging: false,
1480
+ previewMode: "edit",
1481
+ viewports: {
1482
+ current: {
1483
+ width: defaultViewports[0].width,
1484
+ height: defaultViewports[0].height || "auto"
1485
+ },
1486
+ options: [],
1487
+ controlsVisible: true
1488
+ },
1489
+ field: { focus: null }
1490
+ },
1491
+ indexes: {
1492
+ nodes: {},
1493
+ zones: {}
1494
+ }
1495
+ };
1496
+ var defaultPageFields = {
1497
+ title: { type: "text" }
1498
+ };
1499
+ var createAppStore = (initialAppStore) => (0, import_zustand2.create)()(
1500
+ (0, import_middleware2.subscribeWithSelector)((set, get) => {
1501
+ var _a, _b;
1502
+ return __spreadProps(__spreadValues({
1503
+ state: defaultAppState,
1504
+ config: { components: {} },
1505
+ componentState: {},
1506
+ plugins: [],
1507
+ overrides: {},
1508
+ viewports: defaultViewports,
1509
+ zoomConfig: {
1510
+ autoZoom: 1,
1511
+ rootHeight: 0,
1512
+ zoom: 1
1513
+ },
1514
+ status: "LOADING",
1515
+ iframe: {},
1516
+ metadata: {}
1517
+ }, initialAppStore), {
1518
+ fields: createFieldsSlice(set, get),
1519
+ history: createHistorySlice(set, get),
1520
+ nodes: createNodesSlice(set, get),
1521
+ permissions: createPermissionsSlice(set, get),
1522
+ getComponentConfig: (type) => {
1523
+ var _a2;
1524
+ const { config, selectedItem } = get();
1525
+ const rootFields = ((_a2 = config.root) == null ? void 0 : _a2.fields) || defaultPageFields;
1526
+ return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
1527
+ },
1528
+ selectedItem: ((_a = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _a.ui.itemSelector) ? getItem(
1529
+ (_b = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _b.ui.itemSelector,
1530
+ initialAppStore.state
1531
+ ) : null,
1532
+ dispatch: (action) => set((s) => {
1533
+ var _a2, _b2;
1534
+ const { record } = get().history;
1535
+ const dispatch = createReducer({
1536
+ record,
1537
+ appStore: s
1538
+ });
1539
+ const state = dispatch(s.state, action);
1540
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1541
+ (_b2 = (_a2 = get()).onAction) == null ? void 0 : _b2.call(_a2, action, state, get().state);
1542
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1543
+ }),
1544
+ setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1545
+ setStatus: (status) => set({ status }),
1546
+ setComponentState: (componentState) => set({ componentState }),
1547
+ pendingLoadTimeouts: {},
1548
+ setComponentLoading: (id, loading = true, defer = 0) => {
1549
+ const { setComponentState, pendingLoadTimeouts } = get();
1550
+ const loadId = generateId();
1551
+ const setLoading = () => {
1552
+ var _a2;
1553
+ const { componentState } = get();
1554
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1555
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1556
+ loadingCount: (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) + 1
1557
+ })
1558
+ }));
1559
+ };
1560
+ const unsetLoading = () => {
1561
+ var _a2;
1562
+ const { componentState } = get();
1563
+ clearTimeout(timeout2);
1564
+ delete pendingLoadTimeouts[loadId];
1565
+ set({ pendingLoadTimeouts });
1566
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1567
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1568
+ loadingCount: Math.max(
1569
+ (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) - 1,
1570
+ 0
1571
+ )
1572
+ })
1573
+ }));
1574
+ };
1575
+ const timeout2 = setTimeout(() => {
1576
+ if (loading) {
1577
+ setLoading();
1578
+ } else {
1579
+ unsetLoading();
1580
+ }
1581
+ delete pendingLoadTimeouts[loadId];
1582
+ set({ pendingLoadTimeouts });
1583
+ }, defer);
1584
+ set({
1585
+ pendingLoadTimeouts: __spreadProps(__spreadValues({}, pendingLoadTimeouts), {
1586
+ [id]: timeout2
1587
+ })
1588
+ });
1589
+ return unsetLoading;
1590
+ },
1591
+ unsetComponentLoading: (id) => {
1592
+ const { setComponentLoading } = get();
1593
+ setComponentLoading(id, false);
1594
+ },
1595
+ // Helper
1596
+ setUi: (ui, recordHistory) => set((s) => {
1597
+ const dispatch = createReducer({
1598
+ record: () => {
1599
+ },
1600
+ appStore: s
1601
+ });
1602
+ const state = dispatch(s.state, {
1603
+ type: "setUi",
1604
+ ui,
1605
+ recordHistory
1606
+ });
1607
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1608
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1609
+ }),
1610
+ resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
1611
+ const { config, metadata, setComponentLoading, permissions } = get();
1612
+ const timeouts = {};
1613
+ return yield resolveComponentData(
1614
+ componentData,
1615
+ config,
1616
+ metadata,
1617
+ (item) => {
1618
+ const id = "id" in item.props ? item.props.id : "root";
1619
+ timeouts[id] = setComponentLoading(id, true, 50);
1620
+ },
1621
+ (item) => __async(void 0, null, function* () {
1622
+ const id = "id" in item.props ? item.props.id : "root";
1623
+ if ("type" in item) {
1624
+ yield permissions.refreshPermissions({ item });
1625
+ } else {
1626
+ yield permissions.refreshPermissions({ root: true });
1627
+ }
1628
+ timeouts[id]();
1629
+ }),
1630
+ trigger
1631
+ );
1632
+ }),
1633
+ resolveAndCommitData: () => __async(void 0, null, function* () {
1634
+ const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
1635
+ walkTree(
1636
+ state,
1637
+ config,
1638
+ (content) => content,
1639
+ (childItem) => {
1640
+ resolveComponentData2(childItem, "load").then((resolved) => {
1641
+ const { state: state2 } = get();
1642
+ const node = state2.indexes.nodes[resolved.node.props.id];
1643
+ if (node && resolved.didChange) {
1644
+ if (resolved.node.props.id === "root") {
1645
+ dispatch({
1646
+ type: "replaceRoot",
1647
+ root: toRoot(resolved.node)
1648
+ });
1649
+ } else {
1650
+ const zoneCompound = `${node.parentId}:${node.zone}`;
1651
+ const parentZone = state2.indexes.zones[zoneCompound];
1652
+ const index = parentZone.contentIds.indexOf(
1653
+ resolved.node.props.id
1654
+ );
1655
+ dispatch({
1656
+ type: "replace",
1657
+ data: resolved.node,
1658
+ destinationIndex: index,
1659
+ destinationZone: zoneCompound
1660
+ });
1661
+ }
1662
+ }
1663
+ });
1664
+ return childItem;
1665
+ }
1666
+ );
1667
+ })
1668
+ });
1669
+ })
1670
+ );
1671
+ var appStoreContext = (0, import_react9.createContext)(createAppStore());
1672
+ function useAppStore(selector) {
1673
+ const context = (0, import_react9.useContext)(appStoreContext);
1674
+ return (0, import_zustand2.useStore)(context, selector);
1675
+ }
1676
+ function useAppStoreApi() {
1677
+ return (0, import_react9.useContext)(appStoreContext);
1678
+ }
1679
+
1680
+ // components/Loader/index.tsx
1681
+ init_react_import();
1682
+
1683
+ // lib/index.ts
1684
+ init_react_import();
1685
+
1686
+ // lib/filter.ts
1687
+ init_react_import();
1688
+
1689
+ // lib/data/reorder.ts
1690
+ init_react_import();
1691
+
1692
+ // lib/data/replace.ts
1693
+ init_react_import();
1694
+
1695
+ // css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
1696
+ init_react_import();
1697
+ var styles_module_default2 = { "Loader": "_Loader_nacdm_13", "loader-animation": "_loader-animation_nacdm_1" };
1698
+
1699
+ // components/Loader/index.tsx
1700
+ var import_jsx_runtime = require("react/jsx-runtime");
1701
+ var getClassName = get_class_name_factory_default("Loader", styles_module_default2);
1702
+ var Loader = (_a) => {
1703
+ var _b = _a, {
1704
+ color,
1705
+ size = 16
1706
+ } = _b, props = __objRest(_b, [
1707
+ "color",
1708
+ "size"
1709
+ ]);
1710
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1711
+ "span",
1712
+ __spreadValues({
1713
+ className: getClassName(),
1714
+ style: {
1715
+ width: size,
1716
+ height: size,
1717
+ color
1718
+ },
1719
+ "aria-label": "loading"
1720
+ }, props)
1721
+ );
1722
+ };
1723
+
1724
+ // components/ActionBar/index.tsx
1725
+ init_react_import();
1726
+
1727
+ // css-module:/home/runner/work/puck/puck/packages/core/components/ActionBar/styles.module.css#css-module
1728
+ init_react_import();
1729
+ var styles_module_default3 = { "ActionBar": "_ActionBar_rvadt_1", "ActionBar-label": "_ActionBar-label_rvadt_18", "ActionBar-action": "_ActionBar-action_rvadt_30", "ActionBar-group": "_ActionBar-group_rvadt_38" };
1730
+
1731
+ // components/ActionBar/index.tsx
1732
+ var import_jsx_runtime2 = require("react/jsx-runtime");
1733
+ var getClassName2 = get_class_name_factory_default("ActionBar", styles_module_default3);
1734
+ var ActionBar = ({
1735
+ label,
1736
+ children
1737
+ }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1738
+ "div",
1739
+ {
1740
+ className: getClassName2(),
1741
+ onClick: (e) => {
1742
+ e.stopPropagation();
1743
+ },
1744
+ children: [
1745
+ label && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ActionBar.Group, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: getClassName2("label"), children: label }) }),
1746
+ children
1747
+ ]
1748
+ }
1749
+ );
1750
+ var Action = ({
1751
+ children,
1752
+ label,
1753
+ onClick
1754
+ }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1755
+ "button",
1756
+ {
1757
+ type: "button",
1758
+ className: getClassName2("action"),
1759
+ onClick,
1760
+ title: label,
1761
+ children
1762
+ }
1763
+ );
1764
+ var Group = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: getClassName2("group"), children });
1765
+ var Label = ({ label }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: getClassName2("label"), children: label });
1766
+ ActionBar.Action = Action;
1767
+ ActionBar.Label = Label;
1768
+ ActionBar.Group = Group;
1769
+
1770
+ // components/DraggableComponent/index.tsx
1771
+ var import_react_dom = require("react-dom");
1772
+
1773
+ // lib/dnd/collision/dynamic/index.ts
1774
+ init_react_import();
1775
+ var import_abstract8 = require("@dnd-kit/abstract");
1776
+
1777
+ // lib/dnd/collision/directional/index.ts
1778
+ init_react_import();
1779
+ var import_abstract = require("@dnd-kit/abstract");
1780
+
1781
+ // lib/dnd/collision/collision-debug.ts
1782
+ init_react_import();
1783
+ var DEBUG = false;
1784
+ var debugElements = {};
1785
+ var timeout;
1786
+ var collisionDebug = (a, b, id, color, label) => {
1787
+ if (!DEBUG) return;
1788
+ const debugId = `${id}-debug`;
1789
+ clearTimeout(timeout);
1790
+ timeout = setTimeout(() => {
1791
+ Object.entries(debugElements).forEach(([id2, { svg }]) => {
1792
+ svg.remove();
1793
+ delete debugElements[id2];
1794
+ });
1795
+ }, 1e3);
1796
+ requestAnimationFrame(() => {
1797
+ var _a, _b;
1798
+ const existingEl = debugElements[debugId];
1799
+ let line = (_a = debugElements[debugId]) == null ? void 0 : _a.line;
1800
+ let text = (_b = debugElements[debugId]) == null ? void 0 : _b.text;
1801
+ if (!existingEl) {
1802
+ const svgNs = "http://www.w3.org/2000/svg";
1803
+ const svg = document.createElementNS(svgNs, "svg");
1804
+ line = document.createElementNS(svgNs, "line");
1805
+ text = document.createElementNS(svgNs, "text");
1806
+ svg.setAttribute("id", debugId);
1807
+ svg.setAttribute(
1808
+ "style",
1809
+ "position: fixed; height: 100%; width: 100%; pointer-events: none; top: 0px; left: 0px;"
1810
+ );
1811
+ svg.appendChild(line);
1812
+ svg.appendChild(text);
1813
+ text.setAttribute("fill", `black`);
1814
+ document.body.appendChild(svg);
1815
+ debugElements[debugId] = { svg, line, text };
1816
+ }
1817
+ line.setAttribute("x1", a.x.toString());
1818
+ line.setAttribute("x2", b.x.toString());
1819
+ line.setAttribute("y1", a.y.toString());
1820
+ line.setAttribute("y2", b.y.toString());
1821
+ line.setAttribute("style", `stroke:${color};stroke-width:2`);
1822
+ text.setAttribute("x", (a.x - (a.x - b.x) / 2).toString());
1823
+ text.setAttribute("y", (a.y - (a.y - b.y) / 2).toString());
1824
+ if (label) {
1825
+ text.innerHTML = label;
1826
+ }
1827
+ });
1828
+ };
1829
+
1830
+ // lib/dnd/collision/directional/index.ts
1831
+ var distanceChange = "increasing";
1832
+ var directionalCollision = (input, previous) => {
1833
+ var _a;
1834
+ const { dragOperation, droppable } = input;
1835
+ const { shape: dropShape } = droppable;
1836
+ const { position } = dragOperation;
1837
+ const dragShape = (_a = dragOperation.shape) == null ? void 0 : _a.current;
1838
+ if (!dragShape || !dropShape) return null;
1839
+ const dropCenter = dropShape.center;
1840
+ const distanceToPrevious = Math.sqrt(
1841
+ Math.pow(dropCenter.x - previous.x, 2) + Math.pow(dropCenter.y - previous.y, 2)
1842
+ );
1843
+ const distanceToCurrent = Math.sqrt(
1844
+ Math.pow(dropCenter.x - position.current.x, 2) + Math.pow(dropCenter.y - position.current.y, 2)
1845
+ );
1846
+ distanceChange = distanceToCurrent === distanceToPrevious ? distanceChange : distanceToCurrent < distanceToPrevious ? "decreasing" : "increasing";
1847
+ collisionDebug(
1848
+ dragShape.center,
1849
+ dropCenter,
1850
+ droppable.id.toString(),
1851
+ "rebeccapurple"
1852
+ );
1853
+ if (distanceChange === "decreasing") {
1854
+ return {
1855
+ id: droppable.id,
1856
+ value: 1,
1857
+ type: import_abstract.CollisionType.Collision
1858
+ };
1859
+ }
1860
+ return null;
1861
+ };
1862
+
1863
+ // lib/dnd/collision/dynamic/get-direction.ts
1864
+ init_react_import();
1865
+ var getDirection = (dragAxis, delta) => {
1866
+ if (dragAxis === "dynamic") {
1867
+ if (Math.abs(delta.y) > Math.abs(delta.x)) {
1868
+ return delta.y === 0 ? null : delta.y > 0 ? "down" : "up";
1869
+ } else {
1870
+ return delta.x === 0 ? null : delta.x > 0 ? "right" : "left";
1871
+ }
1872
+ } else if (dragAxis === "x") {
1873
+ return delta.x === 0 ? null : delta.x > 0 ? "right" : "left";
1874
+ }
1875
+ return delta.y === 0 ? null : delta.y > 0 ? "down" : "up";
1876
+ };
1877
+
1878
+ // lib/dnd/collision/dynamic/get-midpoint-impact.ts
1879
+ init_react_import();
1880
+ var getMidpointImpact = (dragShape, dropShape, direction, offsetMultiplier = 0) => {
1881
+ const dragRect = dragShape.boundingRectangle;
1882
+ const dropCenter = dropShape.center;
1883
+ if (direction === "down") {
1884
+ const offset2 = offsetMultiplier * dropShape.boundingRectangle.height;
1885
+ return dragRect.bottom >= dropCenter.y + offset2;
1886
+ } else if (direction === "up") {
1887
+ const offset2 = offsetMultiplier * dropShape.boundingRectangle.height;
1888
+ return dragRect.top < dropCenter.y - offset2;
1889
+ } else if (direction === "left") {
1890
+ const offset2 = offsetMultiplier * dropShape.boundingRectangle.width;
1891
+ return dropCenter.x - offset2 >= dragRect.left;
1892
+ }
1893
+ const offset = offsetMultiplier * dropShape.boundingRectangle.width;
1894
+ return dragRect.right - offset >= dropCenter.x;
1895
+ };
1896
+
1897
+ // lib/dnd/collision/dynamic/track-movement-interval.ts
1898
+ init_react_import();
1899
+ var import_geometry = require("@dnd-kit/geometry");
1900
+ var INTERVAL_SENSITIVITY = 10;
1901
+ var intervalCache = {
1902
+ current: { x: 0, y: 0 },
1903
+ delta: { x: 0, y: 0 },
1904
+ previous: { x: 0, y: 0 },
1905
+ direction: null
1906
+ };
1907
+ var trackMovementInterval = (point, dragAxis = "dynamic") => {
1908
+ intervalCache.current = point;
1909
+ intervalCache.delta = {
1910
+ x: point.x - intervalCache.previous.x,
1911
+ y: point.y - intervalCache.previous.y
1912
+ };
1913
+ intervalCache.direction = getDirection(dragAxis, intervalCache.delta) || intervalCache.direction;
1914
+ if (Math.abs(intervalCache.delta.x) > INTERVAL_SENSITIVITY || Math.abs(intervalCache.delta.y) > INTERVAL_SENSITIVITY) {
1915
+ intervalCache.previous = import_geometry.Point.from(point);
1916
+ }
1917
+ return intervalCache;
1918
+ };
1919
+
1920
+ // ../../node_modules/@dnd-kit/collision/dist/index.js
1921
+ init_react_import();
1922
+ var import_abstract2 = require("@dnd-kit/abstract");
1923
+ var import_geometry2 = require("@dnd-kit/geometry");
1924
+ var import_abstract3 = require("@dnd-kit/abstract");
1925
+ var import_geometry3 = require("@dnd-kit/geometry");
1926
+ var import_abstract4 = require("@dnd-kit/abstract");
1927
+ var import_geometry4 = require("@dnd-kit/geometry");
1928
+ var import_abstract5 = require("@dnd-kit/abstract");
1929
+ var import_geometry5 = require("@dnd-kit/geometry");
1930
+ var import_abstract6 = require("@dnd-kit/abstract");
1931
+ var import_geometry6 = require("@dnd-kit/geometry");
1932
+ var import_abstract7 = require("@dnd-kit/abstract");
1933
+ var import_geometry7 = require("@dnd-kit/geometry");
1934
+ var pointerIntersection = ({
1935
+ dragOperation,
1936
+ droppable
1937
+ }) => {
1938
+ const pointerCoordinates = dragOperation.position.current;
1939
+ if (!pointerCoordinates) {
1940
+ return null;
1941
+ }
1942
+ const { id } = droppable;
1943
+ if (!droppable.shape) {
1944
+ return null;
1945
+ }
1946
+ if (droppable.shape.containsPoint(pointerCoordinates)) {
1947
+ const distance = import_geometry2.Point.distance(droppable.shape.center, pointerCoordinates);
1948
+ return {
1949
+ id,
1950
+ value: 1 / distance,
1951
+ type: import_abstract2.CollisionType.PointerIntersection,
1952
+ priority: import_abstract2.CollisionPriority.High
1953
+ };
1954
+ }
1955
+ return null;
1956
+ };
1957
+ var closestCorners = (input) => {
1958
+ const { dragOperation, droppable } = input;
1959
+ const { shape, position } = dragOperation;
1960
+ if (!droppable.shape) {
1961
+ return null;
1962
+ }
1963
+ const shapeCorners = shape ? import_geometry4.Rectangle.from(shape.current.boundingRectangle).corners : void 0;
1964
+ const distance = import_geometry4.Rectangle.from(
1965
+ droppable.shape.boundingRectangle
1966
+ ).corners.reduce(
1967
+ (acc, corner, index) => {
1968
+ var _a;
1969
+ return acc + import_geometry4.Point.distance(
1970
+ import_geometry4.Point.from(corner),
1971
+ (_a = shapeCorners == null ? void 0 : shapeCorners[index]) != null ? _a : position.current
1972
+ );
1973
+ },
1974
+ 0
1975
+ );
1976
+ const value = distance / 4;
1977
+ return {
1978
+ id: droppable.id,
1979
+ value: 1 / value,
1980
+ type: import_abstract4.CollisionType.Collision,
1981
+ priority: import_abstract4.CollisionPriority.Normal
1982
+ };
1983
+ };
1984
+
1985
+ // lib/dnd/collision/dynamic/store.ts
1986
+ init_react_import();
1987
+ var import_vanilla = require("zustand/vanilla");
1988
+ var collisionStore = (0, import_vanilla.createStore)(() => ({
1989
+ fallbackEnabled: false,
1990
+ direction: null,
1991
+ collisionMap: {}
1992
+ }));
1993
+
1994
+ // lib/dnd/collision/dynamic/index.ts
1995
+ var flushNext = "";
1996
+ var createDynamicCollisionDetector = (dragAxis, midpointOffset = 0.05) => (input) => {
1997
+ var _a, _b, _c, _d, _e;
1998
+ const { dragOperation, droppable } = input;
1999
+ const { position } = dragOperation;
2000
+ const dragShape = (_a = dragOperation.shape) == null ? void 0 : _a.current;
2001
+ const { shape: dropShape } = droppable;
2002
+ if (!dragShape || !dropShape) {
2003
+ return null;
2004
+ }
2005
+ const { center: dragCenter } = dragShape;
2006
+ const { collisionMap, fallbackEnabled } = collisionStore.getState();
2007
+ const interval = trackMovementInterval(position.current, dragAxis);
2008
+ collisionStore.setState({ direction: interval.direction });
2009
+ collisionStore.setState({
2010
+ collisionMap: __spreadProps(__spreadValues({}, collisionMap), {
2011
+ [droppable.id]: {
2012
+ direction: interval.direction
2013
+ }
2014
+ })
2015
+ });
2016
+ const { center: dropCenter } = dropShape;
2017
+ const overMidpoint = getMidpointImpact(
2018
+ dragShape,
2019
+ dropShape,
2020
+ interval.direction,
2021
+ midpointOffset
2022
+ );
2023
+ if (((_b = dragOperation.source) == null ? void 0 : _b.id) === droppable.id) {
2024
+ const collision = directionalCollision(input, interval.previous);
2025
+ collisionDebug(dragCenter, dropCenter, droppable.id.toString(), "yellow");
2026
+ if (collision) {
2027
+ return __spreadProps(__spreadValues({}, collision), {
2028
+ priority: import_abstract8.CollisionPriority.Highest
2029
+ });
2030
+ }
2031
+ }
2032
+ const intersectionArea = dragShape.intersectionArea(dropShape);
2033
+ const intersectionRatio = intersectionArea / dropShape.area;
2034
+ if (intersectionArea && overMidpoint) {
2035
+ collisionDebug(
2036
+ dragCenter,
2037
+ dropCenter,
2038
+ droppable.id.toString(),
2039
+ "green",
2040
+ interval.direction
2041
+ );
2042
+ const collision = {
2043
+ id: droppable.id,
2044
+ value: intersectionRatio,
2045
+ priority: import_abstract8.CollisionPriority.High,
2046
+ type: import_abstract8.CollisionType.Collision
2047
+ };
2048
+ const shouldFlushId = flushNext === droppable.id;
2049
+ flushNext = "";
2050
+ return __spreadProps(__spreadValues({}, collision), { id: shouldFlushId ? "flush" : collision.id });
2051
+ }
2052
+ if (fallbackEnabled && ((_c = dragOperation.source) == null ? void 0 : _c.id) !== droppable.id) {
2053
+ const xAxisIntersection = dropShape.boundingRectangle.right > dragShape.boundingRectangle.left && dropShape.boundingRectangle.left < dragShape.boundingRectangle.right;
2054
+ const yAxisIntersection = dropShape.boundingRectangle.bottom > dragShape.boundingRectangle.top && dropShape.boundingRectangle.top < dragShape.boundingRectangle.bottom;
2055
+ if (dragAxis === "y" && xAxisIntersection || yAxisIntersection) {
2056
+ const fallbackCollision = closestCorners(input);
2057
+ if (fallbackCollision) {
2058
+ const direction = getDirection(dragAxis, {
2059
+ x: dragShape.center.x - (((_d = droppable.shape) == null ? void 0 : _d.center.x) || 0),
2060
+ y: dragShape.center.y - (((_e = droppable.shape) == null ? void 0 : _e.center.y) || 0)
2061
+ });
2062
+ collisionMap[droppable.id] = {
2063
+ direction
2064
+ };
2065
+ if (intersectionArea) {
2066
+ collisionDebug(
2067
+ dragCenter,
2068
+ dropCenter,
2069
+ droppable.id.toString(),
2070
+ "red",
2071
+ direction || ""
2072
+ );
2073
+ flushNext = droppable.id;
2074
+ return __spreadProps(__spreadValues({}, fallbackCollision), {
2075
+ priority: import_abstract8.CollisionPriority.Low
2076
+ });
2077
+ }
2078
+ collisionDebug(
2079
+ dragCenter,
2080
+ dropCenter,
2081
+ droppable.id.toString(),
2082
+ "orange",
2083
+ direction || ""
2084
+ );
2085
+ return __spreadProps(__spreadValues({}, fallbackCollision), { priority: import_abstract8.CollisionPriority.Lowest });
2086
+ }
2087
+ }
2088
+ }
2089
+ collisionDebug(dragCenter, dropCenter, droppable.id.toString(), "hotpink");
2090
+ delete collisionMap[droppable.id];
2091
+ collisionStore.setState({
2092
+ collisionMap
2093
+ });
2094
+ return null;
2095
+ };
2096
+
2097
+ // lib/dnd/dnd-kit/safe.ts
2098
+ init_react_import();
2099
+ var import_react10 = require("@dnd-kit/react");
2100
+ var import_sortable = require("@dnd-kit/react/sortable");
2101
+ function useDroppableSafe(input) {
2102
+ if (typeof window === "undefined") {
2103
+ return { ref: () => {
2104
+ } };
2105
+ }
2106
+ return (0, import_react10.useDroppable)(input);
2107
+ }
2108
+ function useDraggableSafe(input) {
2109
+ if (typeof window === "undefined") {
2110
+ return { ref: () => {
2111
+ } };
2112
+ }
2113
+ return (0, import_react10.useDraggable)(input);
2114
+ }
2115
+ function useSortableSafe(input) {
2116
+ if (typeof window === "undefined") {
2117
+ return {
2118
+ ref: () => {
2119
+ },
2120
+ isDragging: false,
2121
+ isDropping: false,
2122
+ handleRef: () => {
2123
+ }
2124
+ };
2125
+ }
2126
+ return (0, import_sortable.useSortable)(input);
2127
+ }
2128
+
2129
+ // lib/get-deep-scroll-position.ts
2130
+ init_react_import();
2131
+ function getDeepScrollPosition(element) {
2132
+ let totalScroll = {
2133
+ x: 0,
2134
+ y: 0
2135
+ };
2136
+ let current = element;
2137
+ while (current && current !== document.documentElement) {
2138
+ const parent = current.parentElement;
2139
+ if (parent) {
2140
+ totalScroll.x += parent.scrollLeft;
2141
+ totalScroll.y += parent.scrollTop;
2142
+ }
2143
+ current = parent;
2144
+ }
2145
+ return totalScroll;
2146
+ }
2147
+
2148
+ // components/DropZone/context.tsx
2149
+ init_react_import();
2150
+ var import_react11 = require("react");
2151
+ var import_zustand3 = require("zustand");
2152
+ var import_jsx_runtime3 = require("react/jsx-runtime");
2153
+ var dropZoneContext = (0, import_react11.createContext)(null);
2154
+ var ZoneStoreContext = (0, import_react11.createContext)(
2155
+ (0, import_zustand3.createStore)(() => ({
2156
+ zoneDepthIndex: {},
2157
+ nextZoneDepthIndex: {},
2158
+ areaDepthIndex: {},
2159
+ nextAreaDepthIndex: {},
2160
+ draggedItem: null,
2161
+ previewIndex: {}
2162
+ }))
2163
+ );
2164
+ var DropZoneProvider = ({
2165
+ children,
2166
+ value
2167
+ }) => {
2168
+ const [hoveringComponent, setHoveringComponent] = (0, import_react11.useState)();
2169
+ const dispatch = useAppStore((s) => s.dispatch);
2170
+ const registerZone = (0, import_react11.useCallback)(
2171
+ (zoneCompound) => {
2172
+ dispatch({
2173
+ type: "registerZone",
2174
+ zone: zoneCompound
2175
+ });
2176
+ },
2177
+ [dispatch]
2178
+ );
2179
+ const unregisterZone = (0, import_react11.useCallback)(
2180
+ (zoneCompound) => {
2181
+ dispatch({
2182
+ type: "unregisterZone",
2183
+ zone: zoneCompound
2184
+ });
2185
+ },
2186
+ [dispatch]
2187
+ );
2188
+ const memoValue = (0, import_react11.useMemo)(
2189
+ () => __spreadValues({
2190
+ hoveringComponent,
2191
+ setHoveringComponent,
2192
+ registerZone,
2193
+ unregisterZone
2194
+ }, value),
2195
+ [value, hoveringComponent]
2196
+ );
2197
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children: memoValue && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(dropZoneContext.Provider, { value: memoValue, children }) });
2198
+ };
2199
+
2200
+ // lib/use-context-store.ts
2201
+ init_react_import();
2202
+ var import_react12 = require("react");
2203
+ var import_zustand4 = require("zustand");
2204
+ var import_shallow = require("zustand/react/shallow");
2205
+ function useContextStore(context, selector) {
2206
+ const store = (0, import_react12.useContext)(context);
2207
+ if (!store) {
2208
+ throw new Error("useContextStore must be used inside context");
2209
+ }
2210
+ return (0, import_zustand4.useStore)(store, (0, import_shallow.useShallow)(selector));
2211
+ }
2212
+
2213
+ // components/DraggableComponent/index.tsx
2214
+ var import_shallow2 = require("zustand/react/shallow");
2215
+ var import_jsx_runtime4 = require("react/jsx-runtime");
2216
+ var getClassName3 = get_class_name_factory_default("DraggableComponent", styles_module_default);
2217
+ var DEBUG2 = false;
2218
+ var space = 8;
2219
+ var actionsOverlayTop = space * 6.5;
2220
+ var actionsTop = -(actionsOverlayTop - 8);
2221
+ var actionsSide = space;
2222
+ var DefaultActionBar = ({
2223
+ label,
2224
+ children,
2225
+ parentAction
2226
+ }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(ActionBar, { children: [
2227
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(ActionBar.Group, { children: [
2228
+ parentAction,
2229
+ label && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ActionBar.Label, { label })
2230
+ ] }),
2231
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ActionBar.Group, { children })
2232
+ ] });
2233
+ var DraggableComponent = ({
2234
+ children,
2235
+ depth,
2236
+ componentType,
2237
+ id,
2238
+ index,
2239
+ zoneCompound,
2240
+ isLoading = false,
2241
+ isSelected = false,
2242
+ debug,
2243
+ label,
2244
+ isEnabled,
2245
+ autoDragAxis,
2246
+ userDragAxis,
2247
+ inDroppableZone = true
2248
+ }) => {
2249
+ const zoom = useAppStore(
2250
+ (s) => {
2251
+ var _a;
2252
+ return ((_a = s.selectedItem) == null ? void 0 : _a.props.id) === id ? s.zoomConfig.zoom : 1;
2253
+ }
2254
+ );
2255
+ const overrides = useAppStore((s) => s.overrides);
2256
+ const dispatch = useAppStore((s) => s.dispatch);
2257
+ const iframe = useAppStore((s) => s.iframe);
2258
+ const ctx = (0, import_react13.useContext)(dropZoneContext);
2259
+ const [localZones, setLocalZones] = (0, import_react13.useState)({});
2260
+ const registerLocalZone = (0, import_react13.useCallback)(
2261
+ (zoneCompound2, active) => {
2262
+ var _a;
2263
+ (_a = ctx == null ? void 0 : ctx.registerLocalZone) == null ? void 0 : _a.call(ctx, zoneCompound2, active);
2264
+ setLocalZones((obj) => __spreadProps(__spreadValues({}, obj), {
2265
+ [zoneCompound2]: active
2266
+ }));
2267
+ },
2268
+ [setLocalZones]
2269
+ );
2270
+ const unregisterLocalZone = (0, import_react13.useCallback)(
2271
+ (zoneCompound2) => {
2272
+ var _a;
2273
+ (_a = ctx == null ? void 0 : ctx.unregisterLocalZone) == null ? void 0 : _a.call(ctx, zoneCompound2);
2274
+ setLocalZones((obj) => {
2275
+ const newLocalZones = __spreadValues({}, obj);
2276
+ delete newLocalZones[zoneCompound2];
2277
+ return newLocalZones;
2278
+ });
2279
+ },
2280
+ [setLocalZones]
2281
+ );
2282
+ const containsActiveZone = Object.values(localZones).filter(Boolean).length > 0;
2283
+ const path = useAppStore((0, import_shallow2.useShallow)((s) => {
2284
+ var _a;
2285
+ return (_a = s.state.indexes.nodes[id]) == null ? void 0 : _a.path;
2286
+ }));
2287
+ const permissions = useAppStore(
2288
+ (0, import_shallow2.useShallow)((s) => {
2289
+ const item = getItem({ index, zone: zoneCompound }, s.state);
2290
+ return s.permissions.getPermissions({ item });
2291
+ })
2292
+ );
2293
+ const userIsDragging = useContextStore(
2294
+ ZoneStoreContext,
2295
+ (s) => !!s.draggedItem
2296
+ );
2297
+ const canCollide = permissions.drag || userIsDragging;
2298
+ const disabled = !isEnabled || !canCollide;
2299
+ const [dragAxis, setDragAxis] = (0, import_react13.useState)(userDragAxis || autoDragAxis);
2300
+ const { ref: sortableRef, isDragging: thisIsDragging } = useSortableSafe({
2301
+ id,
2302
+ index,
2303
+ group: zoneCompound,
2304
+ type: "component",
2305
+ data: {
2306
+ areaId: ctx == null ? void 0 : ctx.areaId,
2307
+ zone: zoneCompound,
2308
+ index,
2309
+ componentType,
2310
+ containsActiveZone,
2311
+ depth,
2312
+ path: path || [],
2313
+ inDroppableZone
2314
+ },
2315
+ collisionPriority: isEnabled ? depth : 0,
2316
+ collisionDetector: createDynamicCollisionDetector(dragAxis),
2317
+ disabled,
2318
+ // "Out of the way" transition from react-beautiful-dnd
2319
+ transition: {
2320
+ duration: 200,
2321
+ easing: "cubic-bezier(0.2, 0, 0, 1)"
2322
+ }
2323
+ });
2324
+ const ref = (0, import_react13.useRef)(null);
2325
+ const refSetter = (0, import_react13.useCallback)(
2326
+ (el) => {
2327
+ sortableRef(el);
2328
+ if (el) {
2329
+ ref.current = el;
2330
+ }
2331
+ },
2332
+ [sortableRef]
2333
+ );
2334
+ const [portalEl, setPortalEl] = (0, import_react13.useState)();
2335
+ (0, import_react13.useEffect)(() => {
2336
+ var _a, _b, _c;
2337
+ setPortalEl(
2338
+ iframe.enabled ? (_a = ref.current) == null ? void 0 : _a.ownerDocument.body : (_c = (_b = ref.current) == null ? void 0 : _b.closest("[data-puck-preview]")) != null ? _c : document.body
2339
+ );
2340
+ }, [iframe.enabled, ref.current]);
2341
+ const getStyle = (0, import_react13.useCallback)(() => {
2342
+ var _a, _b, _c;
2343
+ if (!ref.current) return;
2344
+ const rect = ref.current.getBoundingClientRect();
2345
+ const deepScrollPosition = getDeepScrollPosition(ref.current);
2346
+ const portalContainerEl = iframe.enabled ? null : (_a = ref.current) == null ? void 0 : _a.closest("[data-puck-preview]");
2347
+ const portalContainerRect = portalContainerEl == null ? void 0 : portalContainerEl.getBoundingClientRect();
2348
+ const portalScroll = portalContainerEl ? getDeepScrollPosition(portalContainerEl) : { x: 0, y: 0 };
2349
+ const scroll = {
2350
+ x: deepScrollPosition.x - portalScroll.x - ((_b = portalContainerRect == null ? void 0 : portalContainerRect.left) != null ? _b : 0),
2351
+ y: deepScrollPosition.y - portalScroll.y - ((_c = portalContainerRect == null ? void 0 : portalContainerRect.top) != null ? _c : 0)
2352
+ };
2353
+ const style2 = {
2354
+ left: `${rect.left + scroll.x}px`,
2355
+ top: `${rect.top + scroll.y}px`,
2356
+ height: `${rect.height}px`,
2357
+ width: `${rect.width}px`
2358
+ };
2359
+ return style2;
2360
+ }, [ref.current]);
2361
+ const [style, setStyle] = (0, import_react13.useState)();
2362
+ const sync = (0, import_react13.useCallback)(() => {
2363
+ setStyle(getStyle());
2364
+ }, [ref.current, iframe]);
2365
+ (0, import_react13.useEffect)(() => {
2366
+ if (ref.current && !userIsDragging) {
2367
+ const observer = new ResizeObserver(sync);
2368
+ observer.observe(ref.current);
2369
+ return () => {
2370
+ observer.disconnect();
2371
+ };
2372
+ }
2373
+ }, [ref.current, userIsDragging]);
2374
+ const registerNode = useAppStore((s) => s.nodes.registerNode);
2375
+ (0, import_react13.useEffect)(() => {
2376
+ var _a;
2377
+ registerNode(id, { methods: { sync }, element: (_a = ref.current) != null ? _a : null });
2378
+ return () => {
2379
+ registerNode(id, { methods: { sync: () => null }, element: null });
2380
+ };
2381
+ }, [id, zoneCompound, index, componentType, sync]);
2382
+ const CustomActionBar = (0, import_react13.useMemo)(
2383
+ () => overrides.actionBar || DefaultActionBar,
2384
+ [overrides.actionBar]
2385
+ );
2386
+ const onClick = (0, import_react13.useCallback)(
2387
+ (e) => {
2388
+ e.stopPropagation();
2389
+ dispatch({
2390
+ type: "setUi",
2391
+ ui: {
2392
+ itemSelector: { index, zone: zoneCompound }
2393
+ }
2394
+ });
2395
+ },
2396
+ [index, zoneCompound, id]
2397
+ );
2398
+ const appStore = useAppStoreApi();
2399
+ const onSelectParent = (0, import_react13.useCallback)(() => {
2400
+ const { nodes, zones } = appStore.getState().state.indexes;
2401
+ const node = nodes[id];
2402
+ const parentNode = (node == null ? void 0 : node.parentId) ? nodes[node == null ? void 0 : node.parentId] : null;
2403
+ if (!parentNode || !node.parentId) {
2404
+ return;
2405
+ }
2406
+ const parentZoneCompound = `${parentNode.parentId}:${parentNode.zone}`;
2407
+ const parentIndex = zones[parentZoneCompound].contentIds.indexOf(
2408
+ node.parentId
2409
+ );
2410
+ dispatch({
2411
+ type: "setUi",
2412
+ ui: {
2413
+ itemSelector: {
2414
+ zone: parentZoneCompound,
2415
+ index: parentIndex
2416
+ }
2417
+ }
2418
+ });
2419
+ }, [ctx, path]);
2420
+ const onDuplicate = (0, import_react13.useCallback)(() => {
2421
+ dispatch({
2422
+ type: "duplicate",
2423
+ sourceIndex: index,
2424
+ sourceZone: zoneCompound
2425
+ });
2426
+ }, [index, zoneCompound]);
2427
+ const onDelete = (0, import_react13.useCallback)(() => {
2428
+ dispatch({
2429
+ type: "remove",
2430
+ index,
2431
+ zone: zoneCompound
2432
+ });
2433
+ }, [index, zoneCompound]);
2434
+ const [hover, setHover] = (0, import_react13.useState)(false);
2435
+ const indicativeHover = (ctx == null ? void 0 : ctx.hoveringComponent) === id;
2436
+ (0, import_react13.useEffect)(() => {
2437
+ if (!ref.current) {
2438
+ return;
2439
+ }
2440
+ const el = ref.current;
2441
+ const _onMouseOver = (e) => {
2442
+ if (userIsDragging) {
2443
+ if (thisIsDragging) {
2444
+ setHover(true);
2445
+ } else {
2446
+ setHover(false);
2447
+ }
2448
+ } else {
2449
+ setHover(true);
2450
+ }
2451
+ e.stopPropagation();
2452
+ };
2453
+ const _onMouseOut = (e) => {
2454
+ e.stopPropagation();
2455
+ setHover(false);
2456
+ };
2457
+ el.setAttribute("data-puck-component", id);
2458
+ el.setAttribute("data-puck-dnd", id);
2459
+ el.style.position = "relative";
2460
+ el.addEventListener("click", onClick);
2461
+ el.addEventListener("mouseover", _onMouseOver);
2462
+ el.addEventListener("mouseout", _onMouseOut);
2463
+ return () => {
2464
+ el.removeAttribute("data-puck-component");
2465
+ el.removeAttribute("data-puck-dnd");
2466
+ el.removeEventListener("click", onClick);
2467
+ el.removeEventListener("mouseover", _onMouseOver);
2468
+ el.removeEventListener("mouseout", _onMouseOut);
2469
+ };
2470
+ }, [
2471
+ ref,
2472
+ onClick,
2473
+ containsActiveZone,
2474
+ zoneCompound,
2475
+ id,
2476
+ userIsDragging,
2477
+ thisIsDragging,
2478
+ inDroppableZone
2479
+ ]);
2480
+ (0, import_react13.useEffect)(() => {
2481
+ if (ref.current && disabled) {
2482
+ ref.current.setAttribute("data-puck-disabled", "");
2483
+ return () => {
2484
+ var _a;
2485
+ (_a = ref.current) == null ? void 0 : _a.removeAttribute("data-puck-disabled");
2486
+ };
2487
+ }
2488
+ }, [disabled, ref]);
2489
+ const [isVisible, setIsVisible] = (0, import_react13.useState)(false);
2490
+ (0, import_react13.useEffect)(() => {
2491
+ sync();
2492
+ if ((isSelected || hover || indicativeHover) && !userIsDragging) {
2493
+ setIsVisible(true);
2494
+ } else {
2495
+ setIsVisible(false);
2496
+ }
2497
+ }, [isSelected, hover, indicativeHover, iframe, userIsDragging]);
2498
+ const syncActionsPosition = (0, import_react13.useCallback)(
2499
+ (el) => {
2500
+ if (el) {
2501
+ const view = el.ownerDocument.defaultView;
2502
+ if (view) {
2503
+ const rect = el.getBoundingClientRect();
2504
+ const diffLeft = rect.x;
2505
+ const exceedsBoundsLeft = diffLeft < 0;
2506
+ const diffTop = rect.y;
2507
+ const exceedsBoundsTop = diffTop < 0;
2508
+ if (exceedsBoundsLeft) {
2509
+ el.style.transformOrigin = "left top";
2510
+ el.style.left = "0px";
2511
+ }
2512
+ if (exceedsBoundsTop) {
2513
+ el.style.top = "12px";
2514
+ if (!exceedsBoundsLeft) {
2515
+ el.style.transformOrigin = "right top";
2516
+ }
2517
+ }
2518
+ }
2519
+ }
2520
+ },
2521
+ [zoom]
2522
+ );
2523
+ (0, import_react13.useEffect)(() => {
2524
+ if (userDragAxis) {
2525
+ setDragAxis(userDragAxis);
2526
+ return;
2527
+ }
2528
+ if (ref.current) {
2529
+ const computedStyle = window.getComputedStyle(ref.current);
2530
+ if (computedStyle.display === "inline" || computedStyle.display === "inline-block") {
2531
+ setDragAxis("x");
2532
+ return;
2533
+ }
2534
+ }
2535
+ setDragAxis(autoDragAxis);
2536
+ }, [ref, userDragAxis, autoDragAxis]);
2537
+ const parentAction = (ctx == null ? void 0 : ctx.areaId) && (ctx == null ? void 0 : ctx.areaId) !== "root" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ActionBar.Action, { onClick: onSelectParent, label: "Select parent", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CornerLeftUp, { size: 16 }) });
2538
+ const nextContextValue = (0, import_react13.useMemo)(
2539
+ () => __spreadProps(__spreadValues({}, ctx), {
2540
+ areaId: id,
2541
+ zoneCompound,
2542
+ index,
2543
+ depth: depth + 1,
2544
+ registerLocalZone,
2545
+ unregisterLocalZone
2546
+ }),
2547
+ [
2548
+ ctx,
2549
+ id,
2550
+ zoneCompound,
2551
+ index,
2552
+ depth,
2553
+ registerLocalZone,
2554
+ unregisterLocalZone
2555
+ ]
2556
+ );
2557
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(DropZoneProvider, { value: nextContextValue, children: [
2558
+ isVisible && (0, import_react_dom.createPortal)(
2559
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
2560
+ "div",
2561
+ {
2562
+ className: getClassName3({
2563
+ isSelected,
2564
+ isDragging: thisIsDragging,
2565
+ hover: hover || indicativeHover
2566
+ }),
2567
+ style: __spreadValues({}, style),
2568
+ "data-puck-overlay": true,
2569
+ children: [
2570
+ debug,
2571
+ isLoading && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: getClassName3("loadingOverlay"), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Loader, {}) }),
2572
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2573
+ "div",
2574
+ {
2575
+ className: getClassName3("actionsOverlay"),
2576
+ style: {
2577
+ top: actionsOverlayTop / zoom
2578
+ },
2579
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2580
+ "div",
2581
+ {
2582
+ className: getClassName3("actions"),
2583
+ style: {
2584
+ transform: `scale(${1 / zoom}`,
2585
+ top: actionsTop / zoom,
2586
+ right: 0,
2587
+ paddingLeft: actionsSide,
2588
+ paddingRight: actionsSide
2589
+ },
2590
+ ref: syncActionsPosition,
2591
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
2592
+ CustomActionBar,
2593
+ {
2594
+ parentAction,
2595
+ label: DEBUG2 ? id : label,
2596
+ children: [
2597
+ permissions.duplicate && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ActionBar.Action, { onClick: onDuplicate, label: "Duplicate", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Copy, { size: 16 }) }),
2598
+ permissions.delete && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ActionBar.Action, { onClick: onDelete, label: "Delete", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Trash, { size: 16 }) })
2599
+ ]
2600
+ }
2601
+ )
2602
+ }
2603
+ )
2604
+ }
2605
+ ),
2606
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: getClassName3("overlay") })
2607
+ ]
2608
+ }
2609
+ ),
2610
+ portalEl || document.body
2611
+ ),
2612
+ children(refSetter)
2613
+ ] });
2614
+ };
2615
+
2616
+ // css-module:/home/runner/work/puck/puck/packages/core/components/DropZone/styles.module.css#css-module
2617
+ init_react_import();
2618
+ var styles_module_default4 = { "DropZone": "_DropZone_3dmev_1", "DropZone--hasChildren": "_DropZone--hasChildren_3dmev_11", "DropZone--userIsDragging": "_DropZone--userIsDragging_3dmev_19", "DropZone--isAreaSelected": "_DropZone--isAreaSelected_3dmev_23", "DropZone--hoveringOverArea": "_DropZone--hoveringOverArea_3dmev_24", "DropZone--isRootZone": "_DropZone--isRootZone_3dmev_24", "DropZone--isDestination": "_DropZone--isDestination_3dmev_34", "DropZone-item": "_DropZone-item_3dmev_46", "DropZone-hitbox": "_DropZone-hitbox_3dmev_50", "DropZone--isEnabled": "_DropZone--isEnabled_3dmev_58", "DropZone--isAnimating": "_DropZone--isAnimating_3dmev_67" };
2619
+
2620
+ // components/Drawer/index.tsx
2621
+ init_react_import();
2622
+
2623
+ // css-module:/home/runner/work/puck/puck/packages/core/components/Drawer/styles.module.css#css-module
2624
+ init_react_import();
2625
+ var styles_module_default5 = { "Drawer": "_Drawer_fkqfo_1", "Drawer-draggable": "_Drawer-draggable_fkqfo_8", "Drawer-draggableBg": "_Drawer-draggableBg_fkqfo_12", "Drawer-draggableFg": "_Drawer-draggableFg_fkqfo_21", "DrawerItem-draggable": "_DrawerItem-draggable_fkqfo_25", "DrawerItem--disabled": "_DrawerItem--disabled_fkqfo_38", "DrawerItem": "_DrawerItem_fkqfo_25", "Drawer--isDraggingFrom": "_Drawer--isDraggingFrom_fkqfo_48", "DrawerItem-name": "_DrawerItem-name_fkqfo_66" };
2626
+
2627
+ // components/DragIcon/index.tsx
2628
+ init_react_import();
2629
+
2630
+ // css-module:/home/runner/work/puck/puck/packages/core/components/DragIcon/styles.module.css#css-module
2631
+ init_react_import();
2632
+ var styles_module_default6 = { "DragIcon": "_DragIcon_17p8x_1", "DragIcon--disabled": "_DragIcon--disabled_17p8x_8" };
2633
+
2634
+ // components/DragIcon/index.tsx
2635
+ var import_jsx_runtime5 = require("react/jsx-runtime");
2636
+ var getClassName4 = get_class_name_factory_default("DragIcon", styles_module_default6);
2637
+ var DragIcon = ({ isDragDisabled }) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: getClassName4({ disabled: isDragDisabled }), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("svg", { viewBox: "0 0 20 20", width: "12", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", { d: "M7 2a2 2 0 1 0 .001 4.001A2 2 0 0 0 7 2zm0 6a2 2 0 1 0 .001 4.001A2 2 0 0 0 7 8zm0 6a2 2 0 1 0 .001 4.001A2 2 0 0 0 7 14zm6-8a2 2 0 1 0-.001-4.001A2 2 0 0 0 13 6zm0 2a2 2 0 1 0 .001 4.001A2 2 0 0 0 13 8zm0 6a2 2 0 1 0 .001 4.001A2 2 0 0 0 13 14z" }) }) });
2638
+
2639
+ // components/Drawer/index.tsx
2640
+ var import_react18 = require("react");
2641
+
2642
+ // components/DragDropContext/index.tsx
2643
+ init_react_import();
2644
+ var import_react16 = require("@dnd-kit/react");
2645
+ var import_react17 = require("react");
2646
+ var import_dom = require("@dnd-kit/dom");
2647
+
2648
+ // lib/dnd/NestedDroppablePlugin.ts
2649
+ init_react_import();
2650
+ var import_abstract9 = require("@dnd-kit/abstract");
2651
+
2652
+ // lib/throttle.ts
2653
+ init_react_import();
2654
+
2655
+ // lib/get-frame.ts
2656
+ init_react_import();
2657
+
2658
+ // lib/global-position.ts
2659
+ init_react_import();
2660
+
2661
+ // lib/bubble-pointer-event.ts
2662
+ init_react_import();
2663
+
2664
+ // lib/insert-component.ts
2665
+ init_react_import();
2666
+
2667
+ // components/DragDropContext/index.tsx
2668
+ var import_use_debounce = require("use-debounce");
2669
+ var import_zustand5 = require("zustand");
2670
+
2671
+ // lib/get-deep-dir.ts
2672
+ init_react_import();
2673
+
2674
+ // lib/dnd/use-sensors.ts
2675
+ init_react_import();
2676
+ var import_react14 = require("react");
2677
+
2678
+ // lib/dnd/PointerSensor.ts
2679
+ init_react_import();
2680
+ var import_state = require("@dnd-kit/state");
2681
+ var import_abstract10 = require("@dnd-kit/abstract");
2682
+ var import_geometry8 = require("@dnd-kit/geometry");
2683
+ var import_utilities = require("@dnd-kit/dom/utilities");
2684
+ var _clearTimeout;
2685
+ var _PointerSensor = class _PointerSensor extends import_abstract10.Sensor {
2686
+ constructor(manager, options) {
2687
+ super(manager);
2688
+ this.manager = manager;
2689
+ this.options = options;
2690
+ this.listeners = new import_utilities.Listeners();
2691
+ this.cleanup = /* @__PURE__ */ new Set();
2692
+ this.source = void 0;
2693
+ this.started = false;
2694
+ __privateAdd(this, _clearTimeout);
2695
+ this.handleCancel = this.handleCancel.bind(this);
2696
+ this.handlePointerUp = this.handlePointerUp.bind(this);
2697
+ this.handleKeyDown = this.handleKeyDown.bind(this);
2698
+ (0, import_state.effect)(() => {
2699
+ const unbindGlobal = this.bindGlobal(options != null ? options : {});
2700
+ return () => {
2701
+ unbindGlobal();
2702
+ };
2703
+ });
2704
+ }
2705
+ bind(source, options = this.options) {
2706
+ const unbind = (0, import_state.effect)(() => {
2707
+ var _a;
2708
+ const target = (_a = source.handle) != null ? _a : source.element;
2709
+ const listener = (event) => {
2710
+ if ((0, import_utilities.isPointerEvent)(event)) {
2711
+ this.handlePointerDown(event, source, options);
2712
+ }
2713
+ };
2714
+ if (target) {
2715
+ patchWindow(target.ownerDocument.defaultView);
2716
+ target.addEventListener("pointerdown", listener);
2717
+ return () => {
2718
+ target.removeEventListener("pointerdown", listener);
2719
+ };
2720
+ }
2721
+ });
2722
+ return unbind;
2723
+ }
2724
+ bindGlobal(options) {
2725
+ const documents = /* @__PURE__ */ new Set();
2726
+ for (const draggable of this.manager.registry.draggables.value) {
2727
+ if (draggable.element) {
2728
+ documents.add((0, import_utilities.getDocument)(draggable.element));
2729
+ }
2730
+ }
2731
+ for (const droppable of this.manager.registry.droppables.value) {
2732
+ if (droppable.element) {
2733
+ documents.add((0, import_utilities.getDocument)(droppable.element));
2734
+ }
2735
+ }
2736
+ const unbindFns = Array.from(documents).map(
2737
+ (doc) => this.listeners.bind(doc, [
2738
+ {
2739
+ type: "pointermove",
2740
+ listener: (event) => this.handlePointerMove(event, doc, options)
2741
+ },
2742
+ {
2743
+ type: "pointerup",
2744
+ listener: this.handlePointerUp,
2745
+ options: {
2746
+ capture: true
2747
+ }
2748
+ },
2749
+ {
2750
+ // Cancel activation if there is a competing Drag and Drop interaction
2751
+ type: "dragstart",
2752
+ listener: this.handleDragStart
2753
+ }
2754
+ ])
2755
+ );
2756
+ return () => {
2757
+ unbindFns.forEach((unbind) => unbind());
2758
+ };
2759
+ }
2760
+ handlePointerDown(event, source, options = {}) {
2761
+ if (this.disabled || !event.isPrimary || event.button !== 0 || !(0, import_utilities.isElement)(event.target) || source.disabled) {
2762
+ return;
2763
+ }
2764
+ const offset = (0, import_utilities.getFrameTransform)(source.element);
2765
+ this.initialCoordinates = {
2766
+ x: event.clientX * offset.scaleX + offset.x,
2767
+ y: event.clientY * offset.scaleY + offset.y
2768
+ };
2769
+ this.source = source;
2770
+ const { activationConstraints } = options;
2771
+ const constraints = typeof activationConstraints === "function" ? activationConstraints(event, source) : activationConstraints;
2772
+ event.stopImmediatePropagation();
2773
+ if (!(constraints == null ? void 0 : constraints.delay) && !(constraints == null ? void 0 : constraints.distance)) {
2774
+ this.handleStart(source, event);
2775
+ } else {
2776
+ const { delay } = constraints;
2777
+ if (delay) {
2778
+ const timeout2 = setTimeout(
2779
+ () => this.handleStart(source, event),
2780
+ delay.value
2781
+ );
2782
+ __privateSet(this, _clearTimeout, () => {
2783
+ clearTimeout(timeout2);
2784
+ __privateSet(this, _clearTimeout, void 0);
2785
+ });
2786
+ }
2787
+ }
2788
+ const cleanup = () => {
2789
+ var _a;
2790
+ (_a = __privateGet(this, _clearTimeout)) == null ? void 0 : _a.call(this);
2791
+ this.initialCoordinates = void 0;
2792
+ this.source = void 0;
2793
+ };
2794
+ this.cleanup.add(cleanup);
2795
+ }
2796
+ handlePointerMove(event, doc, options) {
2797
+ if (!this.source) {
2798
+ return;
2799
+ }
2800
+ const ownerDocument = this.source.element && (0, import_utilities.getDocument)(this.source.element);
2801
+ if (doc !== ownerDocument) {
2802
+ return;
2803
+ }
2804
+ const coordinates = {
2805
+ x: event.clientX,
2806
+ y: event.clientY
2807
+ };
2808
+ const offset = (0, import_utilities.getFrameTransform)(this.source.element);
2809
+ coordinates.x = coordinates.x * offset.scaleX + offset.x;
2810
+ coordinates.y = coordinates.y * offset.scaleY + offset.y;
2811
+ if (this.manager.dragOperation.status.dragging) {
2812
+ event.preventDefault();
2813
+ event.stopPropagation();
2814
+ this.manager.actions.move({ to: coordinates });
2815
+ return;
2816
+ }
2817
+ if (!this.initialCoordinates) {
2818
+ return;
2819
+ }
2820
+ const delta = {
2821
+ x: coordinates.x - this.initialCoordinates.x,
2822
+ y: coordinates.y - this.initialCoordinates.y
2823
+ };
2824
+ const { activationConstraints } = options;
2825
+ const constraints = typeof activationConstraints === "function" ? activationConstraints(event, this.source) : activationConstraints;
2826
+ const { distance, delay } = constraints != null ? constraints : {};
2827
+ if (distance) {
2828
+ if (distance.tolerance != null && (0, import_geometry8.exceedsDistance)(delta, distance.tolerance)) {
2829
+ return this.handleCancel();
2830
+ }
2831
+ if ((0, import_geometry8.exceedsDistance)(delta, distance.value)) {
2832
+ return this.handleStart(this.source, event);
2833
+ }
2834
+ }
2835
+ if (delay) {
2836
+ if ((0, import_geometry8.exceedsDistance)(delta, delay.tolerance)) {
2837
+ return this.handleCancel();
2838
+ }
2839
+ }
2840
+ }
2841
+ handlePointerUp(event) {
2842
+ if (!this.source) {
2843
+ return;
2844
+ }
2845
+ event.preventDefault();
2846
+ event.stopPropagation();
2847
+ const { status } = this.manager.dragOperation;
2848
+ if (!status.idle) {
2849
+ const canceled = !status.initialized;
2850
+ this.manager.actions.stop({ canceled });
2851
+ } else if (this.started) {
2852
+ setTimeout(() => {
2853
+ if (!this.manager.dragOperation.status.idle) {
2854
+ this.manager.actions.stop({ canceled: false });
2855
+ }
2856
+ }, 10);
2857
+ }
2858
+ this.cleanup.forEach((cleanup) => cleanup());
2859
+ this.cleanup.clear();
2860
+ }
2861
+ handleKeyDown(event) {
2862
+ if (event.key === "Escape") {
2863
+ event.preventDefault();
2864
+ this.handleCancel();
2865
+ }
2866
+ }
2867
+ handleStart(source, event) {
2868
+ var _a;
2869
+ const { manager, initialCoordinates } = this;
2870
+ (_a = __privateGet(this, _clearTimeout)) == null ? void 0 : _a.call(this);
2871
+ if (!initialCoordinates || manager.dragOperation.status.initialized || this.started) {
2872
+ return;
2873
+ }
2874
+ if (event.defaultPrevented) {
2875
+ return;
2876
+ }
2877
+ this.started = true;
2878
+ event.preventDefault();
2879
+ (0, import_state.batch)(() => {
2880
+ manager.actions.setDragSource(source.id);
2881
+ manager.actions.start({ coordinates: initialCoordinates, event });
2882
+ });
2883
+ const ownerDocument = (0, import_utilities.getDocument)(event.target);
2884
+ const unbind = this.listeners.bind(ownerDocument, [
2885
+ {
2886
+ // Prevent scrolling on touch devices
2887
+ type: "touchmove",
2888
+ listener: preventDefault,
2889
+ options: {
2890
+ passive: false
2891
+ }
2892
+ },
2893
+ {
2894
+ // Prevent click events
2895
+ type: "click",
2896
+ listener: preventDefault
2897
+ },
2898
+ {
2899
+ type: "keydown",
2900
+ listener: this.handleKeyDown
2901
+ }
2902
+ ]);
2903
+ ownerDocument.body.setPointerCapture(event.pointerId);
2904
+ this.cleanup.add(unbind);
2905
+ this.cleanup.add(() => {
2906
+ this.started = false;
2907
+ });
2908
+ }
2909
+ handleDragStart(event) {
2910
+ const { target } = event;
2911
+ if (!(0, import_utilities.isElement)(target)) {
2912
+ return;
2913
+ }
2914
+ const isNativeDraggable = (0, import_utilities.isHTMLElement)(target) && target.draggable && target.getAttribute("draggable") === "true";
2915
+ if (isNativeDraggable) {
2916
+ this.handleCancel();
2917
+ } else {
2918
+ preventDefault(event);
2919
+ }
2920
+ }
2921
+ handleCancel() {
2922
+ const { dragOperation } = this.manager;
2923
+ if (dragOperation.status.initialized) {
2924
+ this.manager.actions.stop({ canceled: true });
2925
+ }
2926
+ this.cleanup.forEach((cleanup) => cleanup());
2927
+ this.cleanup.clear();
2928
+ }
2929
+ destroy() {
2930
+ this.listeners.clear();
2931
+ }
2932
+ };
2933
+ _clearTimeout = new WeakMap();
2934
+ _PointerSensor.configure = (0, import_abstract10.configurator)(_PointerSensor);
2935
+ var PointerSensor = _PointerSensor;
2936
+ function preventDefault(event) {
2937
+ event.preventDefault();
2938
+ }
2939
+ function noop() {
2940
+ }
2941
+ var windows = /* @__PURE__ */ new WeakSet();
2942
+ function patchWindow(window2) {
2943
+ if (!window2 || windows.has(window2)) {
2944
+ return;
2945
+ }
2946
+ window2.addEventListener("touchmove", noop, {
2947
+ capture: false,
2948
+ passive: false
2949
+ });
2950
+ windows.add(window2);
2951
+ }
2952
+
2953
+ // lib/dnd/use-sensors.ts
2954
+ var import_utilities2 = require("@dnd-kit/dom/utilities");
2955
+
2956
+ // lib/use-safe-id.ts
2957
+ init_react_import();
2958
+ var import_react15 = __toESM(require("react"));
2959
+ var useSafeId = () => {
2960
+ if (typeof import_react15.default.useId !== "undefined") {
2961
+ return import_react15.default.useId();
2962
+ }
2963
+ const [id] = (0, import_react15.useState)(generateId());
2964
+ return id;
2965
+ };
2966
+
2967
+ // components/DragDropContext/index.tsx
2968
+ var import_jsx_runtime6 = require("react/jsx-runtime");
2969
+ var dragListenerContext = (0, import_react17.createContext)({
2970
+ dragListeners: {}
2971
+ });
2972
+ function useDragListener(type, fn, deps = []) {
2973
+ const { setDragListeners } = (0, import_react17.useContext)(dragListenerContext);
2974
+ (0, import_react17.useEffect)(() => {
2975
+ if (setDragListeners) {
2976
+ setDragListeners((old) => __spreadProps(__spreadValues({}, old), {
2977
+ [type]: [...old[type] || [], fn]
2978
+ }));
2979
+ }
2980
+ }, deps);
2981
+ }
2982
+
2983
+ // components/Drawer/index.tsx
2984
+ var import_jsx_runtime7 = require("react/jsx-runtime");
2985
+ var getClassName5 = get_class_name_factory_default("Drawer", styles_module_default5);
2986
+ var getClassNameItem = get_class_name_factory_default("DrawerItem", styles_module_default5);
2987
+ var DrawerItemInner = ({
2988
+ children,
2989
+ name,
2990
+ label,
2991
+ dragRef,
2992
+ isDragDisabled
2993
+ }) => {
2994
+ const CustomInner = (0, import_react18.useMemo)(
2995
+ () => children || (({ children: children2 }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: getClassNameItem("default"), children: children2 })),
2996
+ [children]
2997
+ );
2998
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2999
+ "div",
3000
+ {
3001
+ className: getClassNameItem({ disabled: isDragDisabled }),
3002
+ ref: dragRef,
3003
+ onMouseDown: (e) => e.preventDefault(),
3004
+ "data-testid": dragRef ? `drawer-item:${name}` : "",
3005
+ "data-puck-drawer-item": true,
3006
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CustomInner, { name, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: getClassNameItem("draggableWrapper"), children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: getClassNameItem("draggable"), children: [
3007
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: getClassNameItem("name"), children: label != null ? label : name }),
3008
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: getClassNameItem("icon"), children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(DragIcon, {}) })
3009
+ ] }) }) })
3010
+ }
3011
+ );
3012
+ };
3013
+ var DrawerItemDraggable = ({
3014
+ children,
3015
+ name,
3016
+ label,
3017
+ id,
3018
+ isDragDisabled
3019
+ }) => {
3020
+ const { ref } = useDraggableSafe({
3021
+ id,
3022
+ data: { type: "drawer", componentType: name },
3023
+ disabled: isDragDisabled
3024
+ });
3025
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: getClassName5("draggable"), children: [
3026
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: getClassName5("draggableBg"), children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(DrawerItemInner, { name, label, children }) }),
3027
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: getClassName5("draggableFg"), children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3028
+ DrawerItemInner,
3029
+ {
3030
+ name,
3031
+ label,
3032
+ dragRef: ref,
3033
+ isDragDisabled,
3034
+ children
3035
+ }
3036
+ ) })
3037
+ ] });
3038
+ };
3039
+ var DrawerItem = ({
3040
+ name,
3041
+ children,
3042
+ id,
3043
+ label,
3044
+ index,
3045
+ isDragDisabled
3046
+ }) => {
3047
+ const resolvedId = id || name;
3048
+ const [dynamicId, setDynamicId] = (0, import_react18.useState)(generateId(resolvedId));
3049
+ if (typeof index !== "undefined") {
3050
+ console.error(
3051
+ "Warning: The `index` prop on Drawer.Item is deprecated and no longer required."
3052
+ );
3053
+ }
3054
+ useDragListener(
3055
+ "dragend",
3056
+ () => {
3057
+ setDynamicId(generateId(resolvedId));
3058
+ },
3059
+ [resolvedId]
3060
+ );
3061
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3062
+ DrawerItemDraggable,
3063
+ {
3064
+ name,
3065
+ label,
3066
+ id: dynamicId,
3067
+ isDragDisabled,
3068
+ children
3069
+ }
3070
+ ) }, dynamicId);
3071
+ };
3072
+ var Drawer = ({
3073
+ children,
3074
+ droppableId,
3075
+ direction
3076
+ }) => {
3077
+ if (droppableId) {
3078
+ console.error(
3079
+ "Warning: The `droppableId` prop on Drawer is deprecated and no longer required."
3080
+ );
3081
+ }
3082
+ if (direction) {
3083
+ console.error(
3084
+ "Warning: The `direction` prop on Drawer is deprecated and no longer required to achieve multi-directional dragging."
3085
+ );
3086
+ }
3087
+ const id = useSafeId();
3088
+ const { ref } = useDroppableSafe({
3089
+ id,
3090
+ type: "void",
3091
+ collisionPriority: 0
3092
+ // Never collide with this, but we use it so NestedDroppablePlugin respects the Drawer
3093
+ });
3094
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3095
+ "div",
3096
+ {
3097
+ className: getClassName5(),
3098
+ ref,
3099
+ "data-puck-dnd": id,
3100
+ "data-puck-drawer": true,
3101
+ children
3102
+ }
3103
+ );
3104
+ };
3105
+ Drawer.Item = DrawerItem;
3106
+
3107
+ // components/DropZone/lib/use-min-empty-height.ts
3108
+ init_react_import();
3109
+ var import_react19 = require("react");
3110
+ var useMinEmptyHeight = ({
3111
+ zoneCompound,
3112
+ userMinEmptyHeight,
3113
+ ref
3114
+ }) => {
3115
+ const appStore = useAppStoreApi();
3116
+ const [prevHeight, setPrevHeight] = (0, import_react19.useState)(0);
3117
+ const [isAnimating, setIsAnimating] = (0, import_react19.useState)(false);
3118
+ const { draggedItem, isZone } = useContextStore(ZoneStoreContext, (s) => {
3119
+ var _a, _b;
3120
+ return {
3121
+ draggedItem: ((_a = s.draggedItem) == null ? void 0 : _a.data.zone) === zoneCompound ? s.draggedItem : null,
3122
+ isZone: ((_b = s.draggedItem) == null ? void 0 : _b.data.zone) === zoneCompound
3123
+ };
3124
+ });
3125
+ (0, import_react19.useEffect)(() => {
3126
+ if (draggedItem && ref.current) {
3127
+ if (isZone) {
3128
+ const rect = ref.current.getBoundingClientRect();
3129
+ setPrevHeight(rect.height);
3130
+ setIsAnimating(true);
3131
+ return;
3132
+ }
3133
+ }
3134
+ setPrevHeight(0);
3135
+ setTimeout(() => {
3136
+ var _a, _b;
3137
+ const zones = appStore.getState().state.indexes.zones;
3138
+ const nodes = appStore.getState().nodes;
3139
+ const selectedItem = appStore.getState().selectedItem;
3140
+ const contentIds = ((_a = zones[zoneCompound]) == null ? void 0 : _a.contentIds) || [];
3141
+ contentIds.forEach((contentId) => {
3142
+ const node = nodes.nodes[contentId];
3143
+ node == null ? void 0 : node.methods.sync();
3144
+ });
3145
+ if (selectedItem) {
3146
+ (_b = nodes.nodes[selectedItem.props.id]) == null ? void 0 : _b.methods.sync();
3147
+ }
3148
+ setIsAnimating(false);
3149
+ }, 400);
3150
+ }, [ref.current, draggedItem, zoneCompound]);
3151
+ return [prevHeight || userMinEmptyHeight, isAnimating];
3152
+ };
3153
+
3154
+ // lib/assign-refs.ts
3155
+ init_react_import();
3156
+ function assignRef(ref, node) {
3157
+ if (typeof ref === "function") {
3158
+ ref(node);
3159
+ } else if (ref && typeof ref === "object" && "current" in ref) {
3160
+ ref.current = node;
3161
+ }
3162
+ }
3163
+ function assignRefs(refs, node) {
3164
+ refs.forEach((ref) => {
3165
+ assignRef(ref, node);
3166
+ });
3167
+ }
3168
+
3169
+ // components/DropZone/lib/use-content-with-preview.ts
3170
+ init_react_import();
3171
+ var import_react22 = require("react");
3172
+
3173
+ // lib/dnd/use-rendered-callback.ts
3174
+ init_react_import();
3175
+ var import_react20 = require("@dnd-kit/react");
3176
+ var import_react21 = require("react");
3177
+ function useRenderedCallback(callback, deps) {
3178
+ const manager = (0, import_react20.useDragDropManager)();
3179
+ return (0, import_react21.useCallback)(
3180
+ (...args) => __async(this, null, function* () {
3181
+ yield manager == null ? void 0 : manager.renderer.rendering;
3182
+ return callback(...args);
3183
+ }),
3184
+ [...deps, manager]
3185
+ );
3186
+ }
3187
+
3188
+ // components/DropZone/lib/use-content-with-preview.ts
3189
+ var useContentIdsWithPreview = (contentIds, zoneCompound) => {
3190
+ const { draggedItemId, preview, previewExists } = useContextStore(
3191
+ ZoneStoreContext,
3192
+ (s) => {
3193
+ var _a;
3194
+ return {
3195
+ draggedItemId: (_a = s.draggedItem) == null ? void 0 : _a.id,
3196
+ preview: s.previewIndex[zoneCompound],
3197
+ previewExists: Object.keys(s.previewIndex || {}).length > 0
3198
+ };
3199
+ }
3200
+ );
3201
+ const isDragging = useAppStore((s) => s.state.ui.isDragging);
3202
+ const [contentIdsWithPreview, setContentIdsWithPreview] = (0, import_react22.useState)(contentIds);
3203
+ const [localPreview, setLocalPreview] = (0, import_react22.useState)(
3204
+ preview
3205
+ );
3206
+ const updateContent = useRenderedCallback(
3207
+ (contentIds2, preview2, isDragging2) => {
3208
+ if (isDragging2 && !previewExists) {
3209
+ return;
3210
+ }
3211
+ if (preview2) {
3212
+ if (preview2.type === "insert") {
3213
+ setContentIdsWithPreview(
3214
+ insert(
3215
+ contentIds2.filter((id) => id !== preview2.props.id),
3216
+ preview2.index,
3217
+ preview2.props.id
3218
+ )
3219
+ );
3220
+ } else {
3221
+ setContentIdsWithPreview(
3222
+ insert(
3223
+ contentIds2.filter((id) => id !== preview2.props.id),
3224
+ preview2.index,
3225
+ preview2.props.id
3226
+ )
3227
+ );
3228
+ }
3229
+ } else {
3230
+ setContentIdsWithPreview(
3231
+ previewExists ? contentIds2.filter((id) => id !== draggedItemId) : contentIds2
3232
+ );
3233
+ }
3234
+ setLocalPreview(preview2);
3235
+ },
3236
+ [draggedItemId, previewExists]
3237
+ );
3238
+ (0, import_react22.useEffect)(() => {
3239
+ updateContent(contentIds, preview, isDragging);
3240
+ }, [contentIds, preview, isDragging]);
3241
+ return [contentIdsWithPreview, localPreview];
3242
+ };
3243
+
3244
+ // components/DropZone/lib/use-drag-axis.ts
3245
+ init_react_import();
3246
+ var import_react23 = require("react");
3247
+ var GRID_DRAG_AXIS = "dynamic";
3248
+ var FLEX_ROW_DRAG_AXIS = "x";
3249
+ var DEFAULT_DRAG_AXIS = "y";
3250
+ var useDragAxis = (ref, collisionAxis) => {
3251
+ const status = useAppStore((s) => s.status);
3252
+ const [dragAxis, setDragAxis] = (0, import_react23.useState)(
3253
+ collisionAxis || DEFAULT_DRAG_AXIS
3254
+ );
3255
+ const calculateDragAxis = (0, import_react23.useCallback)(() => {
3256
+ if (ref.current) {
3257
+ const computedStyle = window.getComputedStyle(ref.current);
3258
+ if (computedStyle.display === "grid") {
3259
+ setDragAxis(GRID_DRAG_AXIS);
3260
+ } else if (computedStyle.display === "flex" && computedStyle.flexDirection === "row") {
3261
+ setDragAxis(FLEX_ROW_DRAG_AXIS);
3262
+ } else {
3263
+ setDragAxis(DEFAULT_DRAG_AXIS);
3264
+ }
3265
+ }
3266
+ }, [ref.current]);
3267
+ (0, import_react23.useEffect)(() => {
3268
+ const onViewportChange = () => {
3269
+ calculateDragAxis();
3270
+ };
3271
+ window.addEventListener("viewportchange", onViewportChange);
3272
+ return () => {
3273
+ window.removeEventListener("viewportchange", onViewportChange);
3274
+ };
3275
+ }, []);
3276
+ (0, import_react23.useEffect)(calculateDragAxis, [status, collisionAxis]);
3277
+ return [dragAxis, calculateDragAxis];
3278
+ };
3279
+
3280
+ // components/DropZone/index.tsx
3281
+ var import_shallow3 = require("zustand/react/shallow");
3282
+
3283
+ // components/Render/index.tsx
3284
+ init_react_import();
3285
+ var import_react24 = __toESM(require("react"));
3286
+ var import_jsx_runtime8 = require("react/jsx-runtime");
3287
+ var renderContext = import_react24.default.createContext({
3288
+ config: { components: {} },
3289
+ data: { root: {}, content: [] },
3290
+ metadata: {}
3291
+ });
3292
+
3293
+ // components/DropZone/index.tsx
3294
+ var import_jsx_runtime9 = require("react/jsx-runtime");
3295
+ var getClassName6 = get_class_name_factory_default("DropZone", styles_module_default4);
3296
+ var getRandomColor = () => `#${Math.floor(Math.random() * 16777215).toString(16)}`;
3297
+ var RENDER_DEBUG = false;
3298
+ var DropZoneEditPure = (props) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(DropZoneEdit, __spreadValues({}, props));
3299
+ var DropZoneChild = ({
3300
+ zoneCompound,
3301
+ componentId,
3302
+ preview,
3303
+ index,
3304
+ isEnabled,
3305
+ dragAxis,
3306
+ collisionAxis,
3307
+ inDroppableZone
3308
+ }) => {
3309
+ var _a, _b;
3310
+ const metadata = useAppStore((s) => s.metadata);
3311
+ const ctx = (0, import_react25.useContext)(dropZoneContext);
3312
+ const { depth = 1 } = ctx != null ? ctx : {};
3313
+ const nodeProps = useAppStore(
3314
+ (0, import_shallow3.useShallow)((s) => {
3315
+ var _a2;
3316
+ return (_a2 = s.state.indexes.nodes[componentId]) == null ? void 0 : _a2.flatData.props;
3317
+ })
3318
+ );
3319
+ const nodeType = useAppStore(
3320
+ (s) => {
3321
+ var _a2;
3322
+ return (_a2 = s.state.indexes.nodes[componentId]) == null ? void 0 : _a2.data.type;
3323
+ }
3324
+ );
3325
+ const nodeReadOnly = useAppStore(
3326
+ (0, import_shallow3.useShallow)((s) => {
3327
+ var _a2;
3328
+ return (_a2 = s.state.indexes.nodes[componentId]) == null ? void 0 : _a2.data.readOnly;
3329
+ })
3330
+ );
3331
+ const node = { type: nodeType, props: nodeProps };
3332
+ const item = nodeProps ? node : (preview == null ? void 0 : preview.componentType) ? { type: preview.componentType, props: preview.props } : null;
3333
+ const componentConfig = useAppStore(
3334
+ (s) => (item == null ? void 0 : item.type) ? s.config.components[item.type] : null
3335
+ );
3336
+ const puckProps = {
3337
+ renderDropZone: DropZoneEditPure,
3338
+ isEditing: true,
3339
+ dragRef: null,
3340
+ metadata: __spreadValues(__spreadValues({}, metadata), componentConfig == null ? void 0 : componentConfig.metadata)
3341
+ };
3342
+ const overrides = useAppStore((s) => s.overrides);
3343
+ const isLoading = useAppStore(
3344
+ (s) => {
3345
+ var _a2;
3346
+ return ((_a2 = s.componentState[componentId]) == null ? void 0 : _a2.loadingCount) > 0;
3347
+ }
3348
+ );
3349
+ const isSelected = useAppStore(
3350
+ (s) => {
3351
+ var _a2;
3352
+ return ((_a2 = s.selectedItem) == null ? void 0 : _a2.props.id) === componentId || false;
3353
+ }
3354
+ );
3355
+ let label = (_b = (_a = componentConfig == null ? void 0 : componentConfig.label) != null ? _a : item == null ? void 0 : item.type.toString()) != null ? _b : "Component";
3356
+ const renderPreview = (0, import_react25.useMemo)(
3357
+ () => function Preview3() {
3358
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(DrawerItemInner, { name: label, children: overrides.componentItem });
3359
+ },
3360
+ [componentId, label, overrides]
3361
+ );
3362
+ const defaultsProps = (0, import_react25.useMemo)(
3363
+ () => __spreadProps(__spreadValues(__spreadValues({}, componentConfig == null ? void 0 : componentConfig.defaultProps), item == null ? void 0 : item.props), {
3364
+ puck: puckProps,
3365
+ editMode: true
3366
+ // DEPRECATED
3367
+ }),
3368
+ [componentConfig == null ? void 0 : componentConfig.defaultProps, item == null ? void 0 : item.props, puckProps]
3369
+ );
3370
+ const defaultedPropsWithSlots = useSlots(
3371
+ componentConfig,
3372
+ defaultsProps,
3373
+ DropZoneEditPure,
3374
+ (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ContextSlotRender, { componentId, zone: slotProps.zone }),
3375
+ nodeReadOnly,
3376
+ isLoading
3377
+ );
3378
+ if (!item) return;
3379
+ let Render2 = componentConfig ? componentConfig.render : () => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { style: { padding: 48, textAlign: "center" }, children: [
3380
+ "No configuration for ",
3381
+ item.type
3382
+ ] });
3383
+ let componentType = item.type;
3384
+ const isPreview = componentId === (preview == null ? void 0 : preview.props.id) && preview.type === "insert";
3385
+ if (isPreview) {
3386
+ Render2 = renderPreview;
3387
+ }
3388
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3389
+ DraggableComponent,
3390
+ {
3391
+ id: componentId,
3392
+ componentType,
3393
+ zoneCompound,
3394
+ depth: depth + 1,
3395
+ index,
3396
+ isLoading,
3397
+ isSelected,
3398
+ label,
3399
+ isEnabled,
3400
+ autoDragAxis: dragAxis,
3401
+ userDragAxis: collisionAxis,
3402
+ inDroppableZone,
3403
+ children: (dragRef) => (componentConfig == null ? void 0 : componentConfig.inline) && !isPreview ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3404
+ Render2,
3405
+ __spreadProps(__spreadValues({}, defaultedPropsWithSlots), {
3406
+ puck: __spreadProps(__spreadValues({}, defaultedPropsWithSlots.puck), {
3407
+ dragRef
3408
+ })
3409
+ })
3410
+ ) }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { ref: dragRef, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Render2, __spreadValues({}, defaultedPropsWithSlots)) })
3411
+ }
3412
+ );
3413
+ };
3414
+ var DropZoneChildMemo = (0, import_react25.memo)(DropZoneChild);
3415
+ var DropZoneEdit = (0, import_react25.forwardRef)(
3416
+ function DropZoneEditInternal({
3417
+ zone,
3418
+ allow,
3419
+ disallow,
3420
+ style,
3421
+ className,
3422
+ minEmptyHeight: userMinEmptyHeight = 128,
3423
+ collisionAxis
3424
+ }, userRef) {
3425
+ const ctx = (0, import_react25.useContext)(dropZoneContext);
3426
+ const {
3427
+ // These all need setting via context
3428
+ areaId,
3429
+ depth = 0,
3430
+ registerLocalZone,
3431
+ unregisterLocalZone
3432
+ } = ctx != null ? ctx : {};
3433
+ const path = useAppStore(
3434
+ (0, import_shallow3.useShallow)((s) => {
3435
+ var _a;
3436
+ return areaId ? (_a = s.state.indexes.nodes[areaId]) == null ? void 0 : _a.path : null;
3437
+ })
3438
+ );
3439
+ let zoneCompound = rootDroppableId;
3440
+ if (areaId) {
3441
+ if (zone !== rootDroppableId) {
3442
+ zoneCompound = `${areaId}:${zone}`;
3443
+ }
3444
+ }
3445
+ const isRootZone = zoneCompound === rootDroppableId || zone === rootDroppableId || areaId === "root";
3446
+ const {
3447
+ isDeepestZone,
3448
+ inNextDeepestArea,
3449
+ draggedComponentType,
3450
+ userIsDragging
3451
+ } = useContextStore(ZoneStoreContext, (s) => {
3452
+ var _a, _b;
3453
+ return {
3454
+ isDeepestZone: (_a = s.zoneDepthIndex[zoneCompound]) != null ? _a : false,
3455
+ inNextDeepestArea: s.nextAreaDepthIndex[areaId || ""],
3456
+ draggedComponentType: (_b = s.draggedItem) == null ? void 0 : _b.data.componentType,
3457
+ userIsDragging: !!s.draggedItem
3458
+ };
3459
+ });
3460
+ const zoneContentIds = useAppStore(
3461
+ (0, import_shallow3.useShallow)((s) => {
3462
+ var _a;
3463
+ return (_a = s.state.indexes.zones[zoneCompound]) == null ? void 0 : _a.contentIds;
3464
+ })
3465
+ );
3466
+ const zoneType = useAppStore(
3467
+ (0, import_shallow3.useShallow)((s) => {
3468
+ var _a;
3469
+ return (_a = s.state.indexes.zones[zoneCompound]) == null ? void 0 : _a.type;
3470
+ })
3471
+ );
3472
+ (0, import_react25.useEffect)(() => {
3473
+ if (!zoneType || zoneType === "dropzone") {
3474
+ if (zoneCompound !== rootDroppableId) {
3475
+ console.warn(
3476
+ "DropZones have been deprecated in favor of slot fields and will be removed in a future version of Puck. Please see the migration guide: https://www.puckeditor.com/docs/guides/migrations/dropzones-to-slots"
3477
+ );
3478
+ }
3479
+ if (ctx == null ? void 0 : ctx.registerZone) {
3480
+ ctx == null ? void 0 : ctx.registerZone(zoneCompound);
3481
+ }
3482
+ return () => {
3483
+ if (ctx == null ? void 0 : ctx.unregisterZone) {
3484
+ ctx == null ? void 0 : ctx.unregisterZone(zoneCompound);
3485
+ }
3486
+ };
3487
+ }
3488
+ }, [zoneType]);
3489
+ const contentIds = (0, import_react25.useMemo)(() => {
3490
+ return zoneContentIds || [];
3491
+ }, [zoneContentIds]);
3492
+ const ref = (0, import_react25.useRef)(null);
3493
+ const acceptsTarget = (0, import_react25.useCallback)(
3494
+ (componentType) => {
3495
+ if (!componentType) {
3496
+ return true;
3497
+ }
3498
+ if (disallow) {
3499
+ const defaultedAllow = allow || [];
3500
+ const filteredDisallow = (disallow || []).filter(
3501
+ (item) => defaultedAllow.indexOf(item) === -1
3502
+ );
3503
+ if (filteredDisallow.indexOf(componentType) !== -1) {
3504
+ return false;
3505
+ }
3506
+ } else if (allow) {
3507
+ if (allow.indexOf(componentType) === -1) {
3508
+ return false;
3509
+ }
3510
+ }
3511
+ return true;
3512
+ },
3513
+ [allow, disallow]
3514
+ );
3515
+ (0, import_react25.useEffect)(() => {
3516
+ if (registerLocalZone) {
3517
+ registerLocalZone(zoneCompound, acceptsTarget(draggedComponentType));
3518
+ }
3519
+ return () => {
3520
+ if (unregisterLocalZone) {
3521
+ unregisterLocalZone(zoneCompound);
3522
+ }
3523
+ };
3524
+ }, [draggedComponentType, zoneCompound]);
3525
+ const hoveringOverArea = inNextDeepestArea || isRootZone;
3526
+ let isEnabled = true;
3527
+ if (userIsDragging) {
3528
+ isEnabled = isDeepestZone;
3529
+ }
3530
+ if (isEnabled) {
3531
+ isEnabled = acceptsTarget(draggedComponentType);
3532
+ }
3533
+ const [contentIdsWithPreview, preview] = useContentIdsWithPreview(
3534
+ contentIds,
3535
+ zoneCompound
3536
+ );
3537
+ const isDropEnabled = isEnabled && (preview ? contentIdsWithPreview.length === 1 : contentIdsWithPreview.length === 0);
3538
+ const droppableConfig = {
3539
+ id: zoneCompound,
3540
+ collisionPriority: isEnabled ? depth : 0,
3541
+ disabled: !isDropEnabled,
3542
+ collisionDetector: pointerIntersection,
3543
+ type: "dropzone",
3544
+ data: {
3545
+ areaId,
3546
+ depth,
3547
+ isDroppableTarget: acceptsTarget(draggedComponentType),
3548
+ path: path || []
3549
+ }
3550
+ };
3551
+ const { ref: dropRef } = useDroppableSafe(droppableConfig);
3552
+ const isAreaSelected = useAppStore(
3553
+ (s) => (s == null ? void 0 : s.selectedItem) && areaId === (s == null ? void 0 : s.selectedItem.props.id)
3554
+ );
3555
+ const [dragAxis] = useDragAxis(ref, collisionAxis);
3556
+ const [minEmptyHeight, isAnimating] = useMinEmptyHeight({
3557
+ zoneCompound,
3558
+ userMinEmptyHeight,
3559
+ ref
3560
+ });
3561
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3562
+ "div",
3563
+ {
3564
+ className: `${getClassName6({
3565
+ isRootZone,
3566
+ userIsDragging,
3567
+ hoveringOverArea,
3568
+ isEnabled,
3569
+ isAreaSelected,
3570
+ hasChildren: contentIds.length > 0,
3571
+ isAnimating
3572
+ })}${className ? ` ${className}` : ""}`,
3573
+ ref: (node) => {
3574
+ assignRefs([ref, dropRef, userRef], node);
3575
+ },
3576
+ "data-testid": `dropzone:${zoneCompound}`,
3577
+ "data-puck-dropzone": zoneCompound,
3578
+ style: __spreadProps(__spreadValues({}, style), {
3579
+ "--min-empty-height": `${minEmptyHeight}px`,
3580
+ backgroundColor: RENDER_DEBUG ? getRandomColor() : style == null ? void 0 : style.backgroundColor
3581
+ }),
3582
+ children: contentIdsWithPreview.map((componentId, i) => {
3583
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3584
+ DropZoneChildMemo,
3585
+ {
3586
+ zoneCompound,
3587
+ componentId,
3588
+ preview,
3589
+ dragAxis,
3590
+ isEnabled,
3591
+ index: i,
3592
+ collisionAxis,
3593
+ inDroppableZone: acceptsTarget(draggedComponentType)
3594
+ },
3595
+ componentId
3596
+ );
3597
+ })
3598
+ }
3599
+ );
3600
+ }
3601
+ );
3602
+ var DropZoneRenderItem = ({
3603
+ config,
3604
+ item,
3605
+ metadata
3606
+ }) => {
3607
+ const Component = config.components[item.type];
3608
+ const props = useSlots(Component, item.props, (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
3609
+ const nextContextValue = (0, import_react25.useMemo)(
3610
+ () => ({
3611
+ areaId: props.id,
3612
+ depth: 1
3613
+ }),
3614
+ [props]
3615
+ );
3616
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(DropZoneProvider, { value: nextContextValue, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3617
+ Component.render,
3618
+ __spreadProps(__spreadValues({}, props), {
3619
+ puck: __spreadProps(__spreadValues({}, props.puck), {
3620
+ renderDropZone: DropZoneRenderPure,
3621
+ metadata: __spreadValues(__spreadValues({}, metadata), Component.metadata)
3622
+ })
3623
+ })
3624
+ ) }, props.id);
3625
+ };
3626
+ var DropZoneRenderPure = (props) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(DropZoneRender, __spreadValues({}, props));
3627
+ var DropZoneRender = (0, import_react25.forwardRef)(
3628
+ function DropZoneRenderInternal({ className, style, zone }, ref) {
3629
+ const ctx = (0, import_react25.useContext)(dropZoneContext);
3630
+ const { areaId = "root" } = ctx || {};
3631
+ const { config, data, metadata } = (0, import_react25.useContext)(renderContext);
3632
+ let zoneCompound = rootDroppableId;
3633
+ let content = (data == null ? void 0 : data.content) || [];
3634
+ (0, import_react25.useEffect)(() => {
3635
+ if (!content) {
3636
+ if (ctx == null ? void 0 : ctx.registerZone) {
3637
+ ctx == null ? void 0 : ctx.registerZone(zoneCompound);
3638
+ }
3639
+ return () => {
3640
+ if (ctx == null ? void 0 : ctx.unregisterZone) {
3641
+ ctx == null ? void 0 : ctx.unregisterZone(zoneCompound);
3642
+ }
3643
+ };
3644
+ }
3645
+ }, [content]);
3646
+ if (!data || !config) {
3647
+ return null;
3648
+ }
3649
+ if (areaId !== rootAreaId && zone !== rootZone) {
3650
+ zoneCompound = `${areaId}:${zone}`;
3651
+ content = setupZone(data, zoneCompound).zones[zoneCompound];
3652
+ }
3653
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className, style, ref, children: content.map((item) => {
3654
+ const Component = config.components[item.type];
3655
+ if (Component) {
3656
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3657
+ DropZoneRenderItem,
3658
+ {
3659
+ config,
3660
+ item,
3661
+ metadata
3662
+ },
3663
+ item.props.id
3664
+ );
3665
+ }
3666
+ return null;
3667
+ }) });
3668
+ }
3669
+ );
3670
+ var DropZone = (0, import_react25.forwardRef)(
3671
+ function DropZone2(props, ref) {
3672
+ const ctx = (0, import_react25.useContext)(dropZoneContext);
3673
+ if ((ctx == null ? void 0 : ctx.mode) === "edit") {
3674
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(DropZoneEdit, __spreadProps(__spreadValues({}, props), { ref })) });
3675
+ }
3676
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(DropZoneRender, __spreadProps(__spreadValues({}, props), { ref })) });
3677
+ }
3678
+ );
3679
+
3680
+ // components/SlotRender/index.tsx
3681
+ var import_jsx_runtime10 = require("react/jsx-runtime");
3682
+ var SlotRenderPure = (props) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(SlotRender, __spreadValues({}, props));
3683
+ var ContextSlotRender = ({
3684
+ componentId,
3685
+ zone
3686
+ }) => {
3687
+ const config = useAppStore((s) => s.config);
3688
+ const metadata = useAppStore((s) => s.metadata);
3689
+ const slotContent = useAppStore(
3690
+ (s) => {
3691
+ var _a, _b;
3692
+ return (_b = (_a = s.state.indexes.nodes[componentId]) == null ? void 0 : _a.data.props[zone]) != null ? _b : null;
3693
+ }
3694
+ );
3695
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3696
+ SlotRenderPure,
3697
+ {
3698
+ content: slotContent,
3699
+ zone,
3700
+ config,
3701
+ metadata
3702
+ }
3703
+ );
3704
+ };
3705
+ var Item = ({
3706
+ config,
3707
+ item,
3708
+ metadata
3709
+ }) => {
3710
+ const Component = config.components[item.type];
3711
+ const props = useSlots(Component, item.props, (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
3712
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3713
+ Component.render,
3714
+ __spreadProps(__spreadValues({}, props), {
3715
+ puck: __spreadProps(__spreadValues({}, props.puck), {
3716
+ renderDropZone: DropZoneRenderPure,
3717
+ metadata: metadata || {}
3718
+ })
3719
+ })
3720
+ );
3721
+ };
3722
+ var SlotRender = (0, import_react26.forwardRef)(
3723
+ function SlotRenderInternal({ className, style, content, config, metadata }, ref) {
3724
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className, style, ref, children: content.map((item) => {
3725
+ if (!config.components[item.type]) {
3726
+ return null;
3727
+ }
3728
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3729
+ Item,
3730
+ {
3731
+ config,
3732
+ item,
3733
+ metadata
3734
+ },
3735
+ item.props.id
3736
+ );
3737
+ }) });
3738
+ }
3739
+ );
3740
+
3741
+ // components/ServerRender/index.tsx
3742
+ var import_jsx_runtime11 = require("react/jsx-runtime");
3743
+ function DropZoneRender2({
3744
+ zone,
3745
+ data,
3746
+ areaId = "root",
3747
+ config,
3748
+ metadata = {}
3749
+ }) {
3750
+ let zoneCompound = rootDroppableId;
3751
+ let content = (data == null ? void 0 : data.content) || [];
3752
+ if (!data || !config) {
3753
+ return null;
3754
+ }
3755
+ if (areaId !== rootAreaId && zone !== rootZone) {
3756
+ zoneCompound = `${areaId}:${zone}`;
3757
+ content = setupZone(data, zoneCompound).zones[zoneCompound];
3758
+ }
3759
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_jsx_runtime11.Fragment, { children: content.map((item) => {
3760
+ const Component = config.components[item.type];
3761
+ const props = __spreadProps(__spreadValues({}, item.props), {
3762
+ puck: {
3763
+ renderDropZone: ({ zone: zone2 }) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3764
+ DropZoneRender2,
3765
+ {
3766
+ zone: zone2,
3767
+ data,
3768
+ areaId: item.props.id,
3769
+ config,
3770
+ metadata
3771
+ }
3772
+ ),
3773
+ metadata
3774
+ }
3775
+ });
3776
+ const propsWithSlots = useSlots(config.root, props, (props2) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
3777
+ if (Component) {
3778
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Component.render, __spreadValues({}, propsWithSlots), item.props.id);
3779
+ }
3780
+ return null;
3781
+ }) });
3782
+ }
3783
+ function Render({
3784
+ config,
3785
+ data,
3786
+ metadata = {}
3787
+ }) {
3788
+ var _a;
3789
+ const rootProps = data.root.props || data.root;
3790
+ const title = rootProps.title || "";
3791
+ const props = __spreadProps(__spreadValues({}, rootProps), {
3792
+ puck: {
3793
+ renderDropZone: ({ zone }) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3794
+ DropZoneRender2,
3795
+ {
3796
+ zone,
3797
+ data,
3798
+ config,
3799
+ metadata
3800
+ }
3801
+ ),
3802
+ isEditing: false,
3803
+ dragRef: null,
3804
+ metadata
3805
+ },
3806
+ title,
3807
+ editMode: false,
3808
+ id: "puck-root"
3809
+ });
3810
+ const propsWithSlots = useSlots(config.root, props, (props2) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
3811
+ if ((_a = config.root) == null ? void 0 : _a.render) {
3812
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(config.root.render, __spreadProps(__spreadValues({}, propsWithSlots), { children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3813
+ DropZoneRender2,
3814
+ {
3815
+ config,
3816
+ data,
3817
+ zone: rootZone,
3818
+ metadata
3819
+ }
3820
+ ) }));
3821
+ }
3822
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3823
+ DropZoneRender2,
3824
+ {
3825
+ config,
3826
+ data,
3827
+ zone: rootZone,
3828
+ metadata
3829
+ }
3830
+ );
3831
+ }
3832
+
3833
+ // lib/resolve-all-data.ts
3834
+ init_react_import();
3835
+
3836
+ // lib/data/default-data.ts
3837
+ init_react_import();
3838
+ var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
3839
+ root: data.root || {},
3840
+ content: data.content || []
3841
+ });
3842
+
3843
+ // lib/data/to-component.ts
3844
+ init_react_import();
3845
+ var toComponent = (item) => {
3846
+ return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
3847
+ props: __spreadProps(__spreadValues({}, item.props), { id: "root" }),
3848
+ type: "root"
3849
+ });
3850
+ };
3851
+
3852
+ // lib/resolve-all-data.ts
3853
+ function resolveAllData(_0, _1) {
3854
+ return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
3855
+ var _a;
3856
+ const defaultedData = defaultData(data);
3857
+ const resolveNode = (_node) => __async(this, null, function* () {
3858
+ const node = toComponent(_node);
3859
+ onResolveStart == null ? void 0 : onResolveStart(node);
3860
+ const resolved = (yield resolveComponentData(
3861
+ node,
3862
+ config,
3863
+ metadata,
3864
+ () => {
3865
+ },
3866
+ () => {
3867
+ },
3868
+ "force",
3869
+ false
3870
+ )).node;
3871
+ const resolvedDeep = yield mapSlotsAsync(
3872
+ resolved,
3873
+ processContent,
3874
+ false
3875
+ );
3876
+ onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
3877
+ return resolvedDeep;
3878
+ });
3879
+ const processContent = (content) => __async(this, null, function* () {
3880
+ return Promise.all(content.map(resolveNode));
3881
+ });
3882
+ const processZones = () => __async(this, null, function* () {
3883
+ var _a2;
3884
+ const zones = (_a2 = data.zones) != null ? _a2 : {};
3885
+ Object.entries(zones).forEach((_02) => __async(this, [_02], function* ([zoneKey, content]) {
3886
+ zones[zoneKey] = yield Promise.all(content.map(resolveNode));
3887
+ }));
3888
+ return zones;
3889
+ });
3890
+ const dynamic = {
3891
+ root: yield resolveNode(defaultedData.root),
3892
+ content: yield processContent(defaultedData.content),
3893
+ zones: yield processZones()
3894
+ };
3895
+ Object.keys((_a = defaultedData.zones) != null ? _a : {}).forEach((zoneKey) => __async(this, null, function* () {
3896
+ const content = defaultedData.zones[zoneKey];
3897
+ dynamic.zones[zoneKey] = yield processContent(content);
3898
+ }), {});
3899
+ return dynamic;
3900
+ });
3901
+ }
3902
+
3903
+ // lib/transform-props.ts
3904
+ init_react_import();
3905
+ function transformProps(data, propTransforms) {
3906
+ const mapItem = (item) => {
3907
+ if (propTransforms[item.type]) {
3908
+ return __spreadProps(__spreadValues({}, item), {
3909
+ props: propTransforms[item.type](item.props)
3910
+ });
3911
+ }
3912
+ return item;
3913
+ };
3914
+ const defaultedData = defaultData(data);
3915
+ const rootProps = defaultedData.root.props || defaultedData.root;
3916
+ let newRoot = __spreadValues({}, defaultedData.root);
3917
+ if (propTransforms["root"]) {
3918
+ if (defaultedData.root.props) {
3919
+ newRoot.props = propTransforms["root"](rootProps);
3920
+ } else {
3921
+ newRoot = propTransforms["root"](rootProps);
3922
+ }
3923
+ }
3924
+ const afterPropTransforms = __spreadProps(__spreadValues({}, defaultedData), {
3925
+ root: newRoot,
3926
+ content: defaultedData.content.map(mapItem),
3927
+ zones: Object.keys(data.zones || {}).reduce(
3928
+ (acc, zoneKey) => __spreadProps(__spreadValues({}, acc), {
3929
+ [zoneKey]: data.zones[zoneKey].map(mapItem)
3930
+ }),
3931
+ {}
3932
+ )
3933
+ });
3934
+ return afterPropTransforms;
3935
+ }
3936
+ // Annotate the CommonJS export names for ESM import in node:
3937
+ 0 && (module.exports = {
3938
+ Render,
3939
+ resolveAllData,
3940
+ transformProps
3941
+ });
3942
+ /*! Bundled license information:
3943
+
3944
+ classnames/index.js:
3945
+ (*!
3946
+ Copyright (c) 2018 Jed Watson.
3947
+ Licensed under the MIT License (MIT), see
3948
+ http://jedwatson.github.io/classnames
3949
+ *)
3950
+
3951
+ lucide-react/dist/esm/shared/src/utils.js:
3952
+ (**
3953
+ * @license lucide-react v0.468.0 - ISC
3954
+ *
3955
+ * This source code is licensed under the ISC license.
3956
+ * See the LICENSE file in the root directory of this source tree.
3957
+ *)
3958
+
3959
+ lucide-react/dist/esm/defaultAttributes.js:
3960
+ (**
3961
+ * @license lucide-react v0.468.0 - ISC
3962
+ *
3963
+ * This source code is licensed under the ISC license.
3964
+ * See the LICENSE file in the root directory of this source tree.
3965
+ *)
3966
+
3967
+ lucide-react/dist/esm/Icon.js:
3968
+ (**
3969
+ * @license lucide-react v0.468.0 - ISC
3970
+ *
3971
+ * This source code is licensed under the ISC license.
3972
+ * See the LICENSE file in the root directory of this source tree.
3973
+ *)
3974
+
3975
+ lucide-react/dist/esm/createLucideIcon.js:
3976
+ (**
3977
+ * @license lucide-react v0.468.0 - ISC
3978
+ *
3979
+ * This source code is licensed under the ISC license.
3980
+ * See the LICENSE file in the root directory of this source tree.
3981
+ *)
3982
+
3983
+ lucide-react/dist/esm/icons/copy.js:
3984
+ (**
3985
+ * @license lucide-react v0.468.0 - ISC
3986
+ *
3987
+ * This source code is licensed under the ISC license.
3988
+ * See the LICENSE file in the root directory of this source tree.
3989
+ *)
3990
+
3991
+ lucide-react/dist/esm/icons/corner-left-up.js:
3992
+ (**
3993
+ * @license lucide-react v0.468.0 - ISC
3994
+ *
3995
+ * This source code is licensed under the ISC license.
3996
+ * See the LICENSE file in the root directory of this source tree.
3997
+ *)
3998
+
3999
+ lucide-react/dist/esm/icons/trash.js:
4000
+ (**
4001
+ * @license lucide-react v0.468.0 - ISC
4002
+ *
4003
+ * This source code is licensed under the ISC license.
4004
+ * See the LICENSE file in the root directory of this source tree.
4005
+ *)
4006
+
4007
+ lucide-react/dist/esm/lucide-react.js:
4008
+ (**
4009
+ * @license lucide-react v0.468.0 - ISC
4010
+ *
4011
+ * This source code is licensed under the ISC license.
4012
+ * See the LICENSE file in the root directory of this source tree.
4013
+ *)
4014
+ */