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