@measured/puck 0.19.0-canary.d9be813b → 0.19.0-canary.db75e42b

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