@measured/puck 0.19.4-canary.fde74e8a → 0.20.0-canary.14d96817
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/README.md +30 -29
- package/dist/chunk-ICVTPWJU.mjs +7326 -0
- package/dist/chunk-TA2T47AQ.mjs +2859 -0
- package/dist/index.css +123 -47
- package/dist/index.d.mts +17 -8
- package/dist/index.d.ts +17 -8
- package/dist/index.js +3219 -2509
- package/dist/index.mjs +29 -8454
- package/dist/no-external.css +1969 -0
- package/dist/no-external.d.mts +4 -0
- package/dist/no-external.d.ts +4 -0
- package/dist/no-external.js +10022 -0
- package/dist/no-external.mjs +56 -0
- package/dist/rsc.css +26 -0
- package/dist/rsc.d.mts +2 -2
- package/dist/rsc.d.ts +2 -2
- package/dist/rsc.js +1955 -488
- package/dist/rsc.mjs +5 -1
- package/dist/{walk-tree-DrJNb8b-.d.mts → walk-tree-B57SgEEc.d.mts} +62 -31
- package/dist/{walk-tree-DrJNb8b-.d.ts → walk-tree-B57SgEEc.d.ts} +62 -31
- package/package.json +3 -2
- package/dist/chunk-IM42S4YL.mjs +0 -963
package/dist/rsc.js
CHANGED
|
@@ -22,6 +22,24 @@ var __spreadValues = (a, b) => {
|
|
|
22
22
|
return a;
|
|
23
23
|
};
|
|
24
24
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __objRest = (source, exclude) => {
|
|
26
|
+
var target = {};
|
|
27
|
+
for (var prop in source)
|
|
28
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
if (source != null && __getOwnPropSymbols)
|
|
31
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
+
target[prop] = source[prop];
|
|
34
|
+
}
|
|
35
|
+
return target;
|
|
36
|
+
};
|
|
37
|
+
var __esm = (fn, res) => function __init() {
|
|
38
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
39
|
+
};
|
|
40
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
41
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
42
|
+
};
|
|
25
43
|
var __export = (target, all) => {
|
|
26
44
|
for (var name in all)
|
|
27
45
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -64,7 +82,78 @@ var __async = (__this, __arguments, generator) => {
|
|
|
64
82
|
});
|
|
65
83
|
};
|
|
66
84
|
|
|
67
|
-
//
|
|
85
|
+
// ../tsup-config/react-import.js
|
|
86
|
+
var import_react;
|
|
87
|
+
var init_react_import = __esm({
|
|
88
|
+
"../tsup-config/react-import.js"() {
|
|
89
|
+
"use strict";
|
|
90
|
+
import_react = __toESM(require("react"));
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// ../../node_modules/classnames/index.js
|
|
95
|
+
var require_classnames = __commonJS({
|
|
96
|
+
"../../node_modules/classnames/index.js"(exports2, module2) {
|
|
97
|
+
"use strict";
|
|
98
|
+
init_react_import();
|
|
99
|
+
(function() {
|
|
100
|
+
"use strict";
|
|
101
|
+
var hasOwn = {}.hasOwnProperty;
|
|
102
|
+
function classNames() {
|
|
103
|
+
var classes = "";
|
|
104
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
105
|
+
var arg = arguments[i];
|
|
106
|
+
if (arg) {
|
|
107
|
+
classes = appendClass(classes, parseValue(arg));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return classes;
|
|
111
|
+
}
|
|
112
|
+
function parseValue(arg) {
|
|
113
|
+
if (typeof arg === "string" || typeof arg === "number") {
|
|
114
|
+
return arg;
|
|
115
|
+
}
|
|
116
|
+
if (typeof arg !== "object") {
|
|
117
|
+
return "";
|
|
118
|
+
}
|
|
119
|
+
if (Array.isArray(arg)) {
|
|
120
|
+
return classNames.apply(null, arg);
|
|
121
|
+
}
|
|
122
|
+
if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
|
|
123
|
+
return arg.toString();
|
|
124
|
+
}
|
|
125
|
+
var classes = "";
|
|
126
|
+
for (var key in arg) {
|
|
127
|
+
if (hasOwn.call(arg, key) && arg[key]) {
|
|
128
|
+
classes = appendClass(classes, key);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return classes;
|
|
132
|
+
}
|
|
133
|
+
function appendClass(value, newClass) {
|
|
134
|
+
if (!newClass) {
|
|
135
|
+
return value;
|
|
136
|
+
}
|
|
137
|
+
if (value) {
|
|
138
|
+
return value + " " + newClass;
|
|
139
|
+
}
|
|
140
|
+
return value + newClass;
|
|
141
|
+
}
|
|
142
|
+
if (typeof module2 !== "undefined" && module2.exports) {
|
|
143
|
+
classNames.default = classNames;
|
|
144
|
+
module2.exports = classNames;
|
|
145
|
+
} else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
|
|
146
|
+
define("classnames", [], function() {
|
|
147
|
+
return classNames;
|
|
148
|
+
});
|
|
149
|
+
} else {
|
|
150
|
+
window.classNames = classNames;
|
|
151
|
+
}
|
|
152
|
+
})();
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// bundle/rsc.tsx
|
|
68
157
|
var rsc_exports = {};
|
|
69
158
|
__export(rsc_exports, {
|
|
70
159
|
Render: () => Render,
|
|
@@ -74,16 +163,19 @@ __export(rsc_exports, {
|
|
|
74
163
|
walkTree: () => walkTree
|
|
75
164
|
});
|
|
76
165
|
module.exports = __toCommonJS(rsc_exports);
|
|
166
|
+
init_react_import();
|
|
77
167
|
|
|
78
|
-
//
|
|
79
|
-
|
|
168
|
+
// components/ServerRender/index.tsx
|
|
169
|
+
init_react_import();
|
|
80
170
|
|
|
81
171
|
// lib/root-droppable-id.ts
|
|
172
|
+
init_react_import();
|
|
82
173
|
var rootAreaId = "root";
|
|
83
174
|
var rootZone = "default-zone";
|
|
84
175
|
var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
|
85
176
|
|
|
86
177
|
// lib/data/setup-zone.ts
|
|
178
|
+
init_react_import();
|
|
87
179
|
var setupZone = (data, zoneKey) => {
|
|
88
180
|
if (zoneKey === rootDroppableId) {
|
|
89
181
|
return data;
|
|
@@ -96,22 +188,30 @@ var setupZone = (data, zoneKey) => {
|
|
|
96
188
|
};
|
|
97
189
|
|
|
98
190
|
// lib/use-slots.tsx
|
|
191
|
+
init_react_import();
|
|
192
|
+
|
|
193
|
+
// lib/field-transforms/use-field-transforms.tsx
|
|
194
|
+
init_react_import();
|
|
99
195
|
var import_react2 = require("react");
|
|
100
196
|
|
|
197
|
+
// lib/data/map-fields.ts
|
|
198
|
+
init_react_import();
|
|
199
|
+
|
|
101
200
|
// lib/data/default-slots.ts
|
|
201
|
+
init_react_import();
|
|
102
202
|
var defaultSlots = (value, fields) => Object.keys(fields).reduce(
|
|
103
203
|
(acc, fieldName) => fields[fieldName].type === "slot" ? __spreadValues({ [fieldName]: [] }, acc) : acc,
|
|
104
204
|
value
|
|
105
205
|
);
|
|
106
206
|
|
|
107
|
-
// lib/data/map-
|
|
207
|
+
// lib/data/map-fields.ts
|
|
108
208
|
var isPromise = (v) => !!v && typeof v.then === "function";
|
|
109
209
|
var flatten = (values) => values.reduce((acc, item) => __spreadValues(__spreadValues({}, acc), item), {});
|
|
110
210
|
var containsPromise = (arr) => arr.some(isPromise);
|
|
111
211
|
var walkField = ({
|
|
112
212
|
value,
|
|
113
213
|
fields,
|
|
114
|
-
|
|
214
|
+
mappers,
|
|
115
215
|
propKey = "",
|
|
116
216
|
propPath = "",
|
|
117
217
|
id = "",
|
|
@@ -119,7 +219,9 @@ var walkField = ({
|
|
|
119
219
|
recurseSlots = false
|
|
120
220
|
}) => {
|
|
121
221
|
var _a, _b, _c;
|
|
122
|
-
|
|
222
|
+
const fieldType = (_a = fields[propKey]) == null ? void 0 : _a.type;
|
|
223
|
+
const map = mappers[fieldType];
|
|
224
|
+
if (map && fieldType === "slot") {
|
|
123
225
|
const content = value || [];
|
|
124
226
|
const mappedContent = recurseSlots ? content.map((el) => {
|
|
125
227
|
var _a2;
|
|
@@ -131,7 +233,7 @@ var walkField = ({
|
|
|
131
233
|
return walkField({
|
|
132
234
|
value: __spreadProps(__spreadValues({}, el), { props: defaultSlots(el.props, fields2) }),
|
|
133
235
|
fields: fields2,
|
|
134
|
-
|
|
236
|
+
mappers,
|
|
135
237
|
id: el.props.id,
|
|
136
238
|
config,
|
|
137
239
|
recurseSlots
|
|
@@ -140,7 +242,21 @@ var walkField = ({
|
|
|
140
242
|
if (containsPromise(mappedContent)) {
|
|
141
243
|
return Promise.all(mappedContent);
|
|
142
244
|
}
|
|
143
|
-
return map(
|
|
245
|
+
return map({
|
|
246
|
+
value: mappedContent,
|
|
247
|
+
parentId: id,
|
|
248
|
+
propName: propKey,
|
|
249
|
+
field: fields[propKey],
|
|
250
|
+
propPath
|
|
251
|
+
});
|
|
252
|
+
} else if (map && fields[propKey]) {
|
|
253
|
+
return map({
|
|
254
|
+
value,
|
|
255
|
+
parentId: id,
|
|
256
|
+
propName: propKey,
|
|
257
|
+
field: fields[propKey],
|
|
258
|
+
propPath
|
|
259
|
+
});
|
|
144
260
|
}
|
|
145
261
|
if (value && typeof value === "object") {
|
|
146
262
|
if (Array.isArray(value)) {
|
|
@@ -150,7 +266,7 @@ var walkField = ({
|
|
|
150
266
|
(el, idx) => walkField({
|
|
151
267
|
value: el,
|
|
152
268
|
fields: arrayFields,
|
|
153
|
-
|
|
269
|
+
mappers,
|
|
154
270
|
propKey,
|
|
155
271
|
propPath: `${propPath}[${idx}]`,
|
|
156
272
|
id,
|
|
@@ -169,7 +285,7 @@ var walkField = ({
|
|
|
169
285
|
return walkObject({
|
|
170
286
|
value,
|
|
171
287
|
fields: objectFields,
|
|
172
|
-
|
|
288
|
+
mappers,
|
|
173
289
|
id,
|
|
174
290
|
getPropPath: (k) => `${propPath}.${k}`,
|
|
175
291
|
config,
|
|
@@ -182,7 +298,7 @@ var walkField = ({
|
|
|
182
298
|
var walkObject = ({
|
|
183
299
|
value,
|
|
184
300
|
fields,
|
|
185
|
-
|
|
301
|
+
mappers,
|
|
186
302
|
id,
|
|
187
303
|
getPropPath,
|
|
188
304
|
config,
|
|
@@ -192,7 +308,7 @@ var walkObject = ({
|
|
|
192
308
|
const opts = {
|
|
193
309
|
value: v,
|
|
194
310
|
fields,
|
|
195
|
-
|
|
311
|
+
mappers,
|
|
196
312
|
propKey: k,
|
|
197
313
|
propPath: getPropPath(k),
|
|
198
314
|
id,
|
|
@@ -214,14 +330,14 @@ var walkObject = ({
|
|
|
214
330
|
}
|
|
215
331
|
return flatten(newProps);
|
|
216
332
|
};
|
|
217
|
-
function
|
|
333
|
+
function mapFields(item, mappers, config, recurseSlots = false) {
|
|
218
334
|
var _a, _b, _c, _d, _e;
|
|
219
335
|
const itemType = "type" in item ? item.type : "root";
|
|
220
336
|
const componentConfig = itemType === "root" ? config.root : (_a = config.components) == null ? void 0 : _a[itemType];
|
|
221
337
|
const newProps = walkObject({
|
|
222
338
|
value: defaultSlots((_b = item.props) != null ? _b : {}, (_c = componentConfig == null ? void 0 : componentConfig.fields) != null ? _c : {}),
|
|
223
339
|
fields: (_d = componentConfig == null ? void 0 : componentConfig.fields) != null ? _d : {},
|
|
224
|
-
|
|
340
|
+
mappers,
|
|
225
341
|
id: item.props ? (_e = item.props.id) != null ? _e : "root" : "root",
|
|
226
342
|
getPropPath: (k) => k,
|
|
227
343
|
config,
|
|
@@ -237,258 +353,1786 @@ function mapSlots(item, map, config, recurseSlots = false) {
|
|
|
237
353
|
});
|
|
238
354
|
}
|
|
239
355
|
|
|
240
|
-
// lib/use-
|
|
241
|
-
function
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
356
|
+
// lib/field-transforms/use-field-transforms.tsx
|
|
357
|
+
function useFieldTransforms(config, item, transforms, readOnly, forceReadOnly) {
|
|
358
|
+
const mappers = (0, import_react2.useMemo)(() => {
|
|
359
|
+
return Object.keys(transforms).reduce((acc, _fieldType) => {
|
|
360
|
+
const fieldType = _fieldType;
|
|
361
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
362
|
+
[fieldType]: (_a) => {
|
|
363
|
+
var _b = _a, {
|
|
364
|
+
parentId
|
|
365
|
+
} = _b, params = __objRest(_b, [
|
|
366
|
+
"parentId"
|
|
367
|
+
]);
|
|
368
|
+
const wildcardPath = params.propPath.replace(/\[\d+\]/g, "[*]");
|
|
369
|
+
const isReadOnly = (readOnly == null ? void 0 : readOnly[params.propPath]) || (readOnly == null ? void 0 : readOnly[wildcardPath]) || forceReadOnly || false;
|
|
370
|
+
const fn = transforms[fieldType];
|
|
371
|
+
return fn == null ? void 0 : fn(__spreadProps(__spreadValues({}, params), {
|
|
372
|
+
isReadOnly,
|
|
373
|
+
componentId: parentId
|
|
374
|
+
}));
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
}, {});
|
|
378
|
+
}, [transforms, readOnly, forceReadOnly]);
|
|
379
|
+
const transformedProps = (0, import_react2.useMemo)(() => {
|
|
380
|
+
const mapped = mapFields(item, mappers, config).props;
|
|
260
381
|
return mapped;
|
|
261
|
-
}, [config, item,
|
|
382
|
+
}, [config, item, mappers]);
|
|
262
383
|
const mergedProps = (0, import_react2.useMemo)(
|
|
263
|
-
() => __spreadValues(__spreadValues({}, item.props),
|
|
264
|
-
[item.props,
|
|
384
|
+
() => __spreadValues(__spreadValues({}, item.props), transformedProps),
|
|
385
|
+
[item.props, transformedProps]
|
|
265
386
|
);
|
|
266
387
|
return mergedProps;
|
|
267
388
|
}
|
|
268
389
|
|
|
269
|
-
//
|
|
270
|
-
|
|
271
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
272
|
-
var SlotRenderPure = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SlotRender, __spreadValues({}, props));
|
|
273
|
-
var Item = ({
|
|
274
|
-
config,
|
|
275
|
-
item,
|
|
276
|
-
metadata
|
|
277
|
-
}) => {
|
|
278
|
-
const Component = config.components[item.type];
|
|
279
|
-
const props = useSlots(config, item, (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
|
|
280
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
281
|
-
Component.render,
|
|
282
|
-
__spreadProps(__spreadValues({}, props), {
|
|
283
|
-
puck: __spreadProps(__spreadValues({}, props.puck), {
|
|
284
|
-
renderDropZone: DropZoneRender,
|
|
285
|
-
metadata: metadata || {}
|
|
286
|
-
})
|
|
287
|
-
})
|
|
288
|
-
);
|
|
289
|
-
};
|
|
290
|
-
var SlotRender = (0, import_react3.forwardRef)(
|
|
291
|
-
function SlotRenderInternal({ className, style, content, config, metadata }, ref) {
|
|
292
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className, style, ref, children: content.map((item) => {
|
|
293
|
-
if (!config.components[item.type]) {
|
|
294
|
-
return null;
|
|
295
|
-
}
|
|
296
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
297
|
-
Item,
|
|
298
|
-
{
|
|
299
|
-
config,
|
|
300
|
-
item,
|
|
301
|
-
metadata
|
|
302
|
-
},
|
|
303
|
-
item.props.id
|
|
304
|
-
);
|
|
305
|
-
}) });
|
|
306
|
-
}
|
|
307
|
-
);
|
|
390
|
+
// lib/field-transforms/default-transforms.tsx
|
|
391
|
+
init_react_import();
|
|
308
392
|
|
|
309
|
-
// components/
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
if (areaId !== rootAreaId && zone !== rootZone) {
|
|
324
|
-
zoneCompound = `${areaId}:${zone}`;
|
|
325
|
-
content = setupZone(data, zoneCompound).zones[zoneCompound];
|
|
326
|
-
}
|
|
327
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: content.map((item) => {
|
|
328
|
-
const Component = config.components[item.type];
|
|
329
|
-
const props = __spreadProps(__spreadValues({}, item.props), {
|
|
330
|
-
puck: {
|
|
331
|
-
renderDropZone: ({ zone: zone2 }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
332
|
-
DropZoneRender,
|
|
333
|
-
{
|
|
334
|
-
zone: zone2,
|
|
335
|
-
data,
|
|
336
|
-
areaId: item.props.id,
|
|
337
|
-
config,
|
|
338
|
-
metadata
|
|
339
|
-
}
|
|
340
|
-
),
|
|
341
|
-
metadata,
|
|
342
|
-
dragRef: null,
|
|
343
|
-
isEditing: false
|
|
344
|
-
}
|
|
345
|
-
});
|
|
346
|
-
const renderItem = __spreadProps(__spreadValues({}, item), { props });
|
|
347
|
-
const propsWithSlots = useSlots(config, renderItem, (props2) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
|
|
348
|
-
if (Component) {
|
|
349
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Component.render, __spreadValues({}, propsWithSlots), renderItem.props.id);
|
|
350
|
-
}
|
|
351
|
-
return null;
|
|
352
|
-
}) });
|
|
353
|
-
}
|
|
354
|
-
function Render({
|
|
355
|
-
config,
|
|
356
|
-
data,
|
|
357
|
-
metadata = {}
|
|
358
|
-
}) {
|
|
359
|
-
var _a;
|
|
360
|
-
const rootProps = "props" in data.root ? data.root.props : data.root;
|
|
361
|
-
const title = rootProps.title || "";
|
|
362
|
-
const props = __spreadProps(__spreadValues({}, rootProps), {
|
|
363
|
-
puck: {
|
|
364
|
-
renderDropZone: ({ zone }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
365
|
-
DropZoneRender,
|
|
366
|
-
{
|
|
367
|
-
zone,
|
|
368
|
-
data,
|
|
369
|
-
config,
|
|
370
|
-
metadata
|
|
371
|
-
}
|
|
372
|
-
),
|
|
373
|
-
isEditing: false,
|
|
374
|
-
dragRef: null,
|
|
375
|
-
metadata
|
|
376
|
-
},
|
|
377
|
-
title,
|
|
378
|
-
editMode: false,
|
|
379
|
-
id: "puck-root"
|
|
393
|
+
// components/InlineTextField/index.tsx
|
|
394
|
+
init_react_import();
|
|
395
|
+
var import_react9 = require("react");
|
|
396
|
+
|
|
397
|
+
// lib/overlay-portal/index.tsx
|
|
398
|
+
init_react_import();
|
|
399
|
+
var registerOverlayPortal = (el, opts = {}) => {
|
|
400
|
+
if (!el) return;
|
|
401
|
+
const { disableDrag = false, disableDragOnFocus = true } = opts;
|
|
402
|
+
const stopPropagation = (e) => {
|
|
403
|
+
e.stopPropagation();
|
|
404
|
+
};
|
|
405
|
+
el.addEventListener("mouseover", stopPropagation, {
|
|
406
|
+
capture: true
|
|
380
407
|
});
|
|
381
|
-
const
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
408
|
+
const onFocus = () => {
|
|
409
|
+
setTimeout(() => {
|
|
410
|
+
el.addEventListener("pointerdown", stopPropagation, {
|
|
411
|
+
capture: true
|
|
412
|
+
});
|
|
413
|
+
}, 200);
|
|
414
|
+
};
|
|
415
|
+
const onBlur = () => {
|
|
416
|
+
el.removeEventListener("pointerdown", stopPropagation, {
|
|
417
|
+
capture: true
|
|
418
|
+
});
|
|
419
|
+
};
|
|
420
|
+
if (disableDragOnFocus) {
|
|
421
|
+
el.addEventListener("focus", onFocus, { capture: true });
|
|
422
|
+
el.addEventListener("blur", onBlur, { capture: true });
|
|
423
|
+
} else if (disableDrag) {
|
|
424
|
+
el.addEventListener("pointerdown", stopPropagation, {
|
|
425
|
+
capture: true
|
|
426
|
+
});
|
|
392
427
|
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
{
|
|
396
|
-
|
|
397
|
-
data,
|
|
398
|
-
zone: rootZone,
|
|
399
|
-
metadata
|
|
400
|
-
}
|
|
401
|
-
);
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
// lib/get-changed.ts
|
|
405
|
-
var import_fast_deep_equal = __toESM(require("fast-deep-equal"));
|
|
406
|
-
var getChanged = (newItem, oldItem) => {
|
|
407
|
-
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
|
408
|
-
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
|
409
|
-
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
|
410
|
-
return __spreadProps(__spreadValues({}, acc), {
|
|
411
|
-
[item]: !(0, import_fast_deep_equal.default)(oldItemProps[item], newItemProps[item])
|
|
428
|
+
el.setAttribute("data-puck-overlay-portal", "true");
|
|
429
|
+
return () => {
|
|
430
|
+
el.removeEventListener("mouseover", stopPropagation, {
|
|
431
|
+
capture: true
|
|
412
432
|
});
|
|
413
|
-
|
|
433
|
+
if (disableDragOnFocus) {
|
|
434
|
+
el.removeEventListener("focus", onFocus, { capture: true });
|
|
435
|
+
el.removeEventListener("blur", onFocus, { capture: true });
|
|
436
|
+
} else if (disableDrag) {
|
|
437
|
+
el.removeEventListener("pointerdown", stopPropagation, {
|
|
438
|
+
capture: true
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
el.removeAttribute("data-puck-overlay-portal");
|
|
442
|
+
};
|
|
414
443
|
};
|
|
415
444
|
|
|
416
|
-
//
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
|
|
437
|
-
trigger
|
|
438
|
-
});
|
|
439
|
-
resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
|
|
440
|
-
if (Object.keys(readOnly).length) {
|
|
441
|
-
resolvedItem.readOnly = readOnly;
|
|
442
|
-
}
|
|
445
|
+
// store/index.ts
|
|
446
|
+
init_react_import();
|
|
447
|
+
|
|
448
|
+
// reducer/index.ts
|
|
449
|
+
init_react_import();
|
|
450
|
+
|
|
451
|
+
// reducer/actions/set.ts
|
|
452
|
+
init_react_import();
|
|
453
|
+
|
|
454
|
+
// lib/data/walk-app-state.ts
|
|
455
|
+
init_react_import();
|
|
456
|
+
|
|
457
|
+
// lib/data/for-related-zones.ts
|
|
458
|
+
init_react_import();
|
|
459
|
+
|
|
460
|
+
// lib/get-zone-id.ts
|
|
461
|
+
init_react_import();
|
|
462
|
+
var getZoneId = (zoneCompound) => {
|
|
463
|
+
if (!zoneCompound) {
|
|
464
|
+
return [];
|
|
443
465
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
(content) => __async(void 0, null, function* () {
|
|
447
|
-
return yield Promise.all(
|
|
448
|
-
content.map(
|
|
449
|
-
(childItem) => __async(void 0, null, function* () {
|
|
450
|
-
return (yield resolveComponentData(
|
|
451
|
-
childItem,
|
|
452
|
-
config,
|
|
453
|
-
metadata,
|
|
454
|
-
onResolveStart,
|
|
455
|
-
onResolveEnd,
|
|
456
|
-
trigger
|
|
457
|
-
)).node;
|
|
458
|
-
})
|
|
459
|
-
)
|
|
460
|
-
);
|
|
461
|
-
}),
|
|
462
|
-
config
|
|
463
|
-
);
|
|
464
|
-
if (shouldRunResolver && onResolveEnd) {
|
|
465
|
-
onResolveEnd(resolvedItem);
|
|
466
|
+
if (zoneCompound && zoneCompound.indexOf(":") > -1) {
|
|
467
|
+
return zoneCompound.split(":");
|
|
466
468
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
resolved: itemWithResolvedChildren
|
|
470
|
-
};
|
|
471
|
-
return {
|
|
472
|
-
node: itemWithResolvedChildren,
|
|
473
|
-
didChange: !(0, import_fast_deep_equal2.default)(item, itemWithResolvedChildren)
|
|
474
|
-
};
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
// lib/data/default-data.ts
|
|
478
|
-
var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
|
|
479
|
-
root: data.root || {},
|
|
480
|
-
content: data.content || []
|
|
481
|
-
});
|
|
469
|
+
return [rootDroppableId, zoneCompound];
|
|
470
|
+
};
|
|
482
471
|
|
|
483
|
-
// lib/data/
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
472
|
+
// lib/data/for-related-zones.ts
|
|
473
|
+
function forRelatedZones(item, data, cb, path = []) {
|
|
474
|
+
Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
|
|
475
|
+
const [parentId] = getZoneId(zoneCompound);
|
|
476
|
+
if (parentId === item.props.id) {
|
|
477
|
+
cb(path, zoneCompound, content);
|
|
478
|
+
}
|
|
488
479
|
});
|
|
489
|
-
}
|
|
480
|
+
}
|
|
490
481
|
|
|
491
|
-
// lib/
|
|
482
|
+
// lib/data/flatten-node.ts
|
|
483
|
+
init_react_import();
|
|
484
|
+
var import_flat = __toESM(require("flat"));
|
|
485
|
+
|
|
486
|
+
// lib/data/strip-slots.ts
|
|
487
|
+
init_react_import();
|
|
488
|
+
var stripSlots = (data, config) => {
|
|
489
|
+
return mapFields(data, { slot: () => null }, config);
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
// lib/data/flatten-node.ts
|
|
493
|
+
var { flatten: flatten2, unflatten } = import_flat.default;
|
|
494
|
+
var flattenNode = (node, config) => {
|
|
495
|
+
return __spreadProps(__spreadValues({}, node), {
|
|
496
|
+
props: flatten2(stripSlots(node, config).props)
|
|
497
|
+
});
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
// lib/data/walk-app-state.ts
|
|
501
|
+
function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
|
|
502
|
+
var _a;
|
|
503
|
+
let newZones = {};
|
|
504
|
+
const newZoneIndex = {};
|
|
505
|
+
const newNodeIndex = {};
|
|
506
|
+
const processContent = (path, zoneCompound, content, zoneType, newId) => {
|
|
507
|
+
var _a2;
|
|
508
|
+
const [parentId] = zoneCompound.split(":");
|
|
509
|
+
const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
|
|
510
|
+
const [_2, zone] = zoneCompound.split(":");
|
|
511
|
+
const newZoneCompound = `${newId || parentId}:${zone}`;
|
|
512
|
+
const newContent2 = mappedContent.map(
|
|
513
|
+
(zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
|
|
514
|
+
);
|
|
515
|
+
newZoneIndex[newZoneCompound] = {
|
|
516
|
+
contentIds: newContent2.map((item) => item.props.id),
|
|
517
|
+
type: zoneType
|
|
518
|
+
};
|
|
519
|
+
return [newZoneCompound, newContent2];
|
|
520
|
+
};
|
|
521
|
+
const processRelatedZones = (item, newId, initialPath) => {
|
|
522
|
+
forRelatedZones(
|
|
523
|
+
item,
|
|
524
|
+
state.data,
|
|
525
|
+
(relatedPath, relatedZoneCompound, relatedContent) => {
|
|
526
|
+
const [zoneCompound, newContent2] = processContent(
|
|
527
|
+
relatedPath,
|
|
528
|
+
relatedZoneCompound,
|
|
529
|
+
relatedContent,
|
|
530
|
+
"dropzone",
|
|
531
|
+
newId
|
|
532
|
+
);
|
|
533
|
+
newZones[zoneCompound] = newContent2;
|
|
534
|
+
},
|
|
535
|
+
initialPath
|
|
536
|
+
);
|
|
537
|
+
};
|
|
538
|
+
const processItem = (item, path, index) => {
|
|
539
|
+
const mappedItem = mapNodeOrSkip(item, path, index);
|
|
540
|
+
if (!mappedItem) return item;
|
|
541
|
+
const id = mappedItem.props.id;
|
|
542
|
+
const newProps = __spreadProps(__spreadValues({}, mapFields(
|
|
543
|
+
mappedItem,
|
|
544
|
+
{
|
|
545
|
+
slot: ({ value, parentId: parentId2, propPath }) => {
|
|
546
|
+
const content = value;
|
|
547
|
+
const zoneCompound = `${parentId2}:${propPath}`;
|
|
548
|
+
const [_2, newContent2] = processContent(
|
|
549
|
+
path,
|
|
550
|
+
zoneCompound,
|
|
551
|
+
content,
|
|
552
|
+
"slot",
|
|
553
|
+
parentId2
|
|
554
|
+
);
|
|
555
|
+
return newContent2;
|
|
556
|
+
}
|
|
557
|
+
},
|
|
558
|
+
config
|
|
559
|
+
).props), {
|
|
560
|
+
id
|
|
561
|
+
});
|
|
562
|
+
processRelatedZones(item, id, path);
|
|
563
|
+
const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
|
|
564
|
+
const thisZoneCompound = path[path.length - 1];
|
|
565
|
+
const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
|
|
566
|
+
newNodeIndex[id] = {
|
|
567
|
+
data: newItem,
|
|
568
|
+
flatData: flattenNode(newItem, config),
|
|
569
|
+
path,
|
|
570
|
+
parentId,
|
|
571
|
+
zone
|
|
572
|
+
};
|
|
573
|
+
const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
|
|
574
|
+
if (newProps.id === "root") {
|
|
575
|
+
delete finalData["type"];
|
|
576
|
+
delete finalData.props["id"];
|
|
577
|
+
}
|
|
578
|
+
return finalData;
|
|
579
|
+
};
|
|
580
|
+
const zones = state.data.zones || {};
|
|
581
|
+
const [_, newContent] = processContent(
|
|
582
|
+
[],
|
|
583
|
+
rootDroppableId,
|
|
584
|
+
state.data.content,
|
|
585
|
+
"root"
|
|
586
|
+
);
|
|
587
|
+
const processedContent = newContent;
|
|
588
|
+
const zonesAlreadyProcessed = Object.keys(newZones);
|
|
589
|
+
Object.keys(zones || {}).forEach((zoneCompound) => {
|
|
590
|
+
const [parentId] = zoneCompound.split(":");
|
|
591
|
+
if (zonesAlreadyProcessed.includes(zoneCompound)) {
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
const [_2, newContent2] = processContent(
|
|
595
|
+
[rootDroppableId],
|
|
596
|
+
zoneCompound,
|
|
597
|
+
zones[zoneCompound],
|
|
598
|
+
"dropzone",
|
|
599
|
+
parentId
|
|
600
|
+
);
|
|
601
|
+
newZones[zoneCompound] = newContent2;
|
|
602
|
+
}, newZones);
|
|
603
|
+
const processedRoot = processItem(
|
|
604
|
+
{
|
|
605
|
+
type: "root",
|
|
606
|
+
props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
|
|
607
|
+
},
|
|
608
|
+
[],
|
|
609
|
+
-1
|
|
610
|
+
);
|
|
611
|
+
const root = __spreadProps(__spreadValues({}, state.data.root), {
|
|
612
|
+
props: processedRoot.props
|
|
613
|
+
});
|
|
614
|
+
return __spreadProps(__spreadValues({}, state), {
|
|
615
|
+
data: {
|
|
616
|
+
root,
|
|
617
|
+
content: processedContent,
|
|
618
|
+
zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
|
|
619
|
+
},
|
|
620
|
+
indexes: {
|
|
621
|
+
nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
|
|
622
|
+
zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
|
|
623
|
+
}
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// reducer/actions/set.ts
|
|
628
|
+
var setAction = (state, action, appStore) => {
|
|
629
|
+
if (typeof action.state === "object") {
|
|
630
|
+
const newState = __spreadValues(__spreadValues({}, state), action.state);
|
|
631
|
+
if (action.state.indexes) {
|
|
632
|
+
return newState;
|
|
633
|
+
}
|
|
634
|
+
console.warn(
|
|
635
|
+
"`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
|
636
|
+
);
|
|
637
|
+
return walkAppState(newState, appStore.config);
|
|
638
|
+
}
|
|
639
|
+
return __spreadValues(__spreadValues({}, state), action.state(state));
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
// reducer/actions/insert.ts
|
|
643
|
+
init_react_import();
|
|
644
|
+
|
|
645
|
+
// lib/data/insert.ts
|
|
646
|
+
init_react_import();
|
|
647
|
+
var insert = (list, index, item) => {
|
|
648
|
+
const result = Array.from(list || []);
|
|
649
|
+
result.splice(index, 0, item);
|
|
650
|
+
return result;
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
// lib/generate-id.ts
|
|
654
|
+
init_react_import();
|
|
655
|
+
var import_uuid = require("uuid");
|
|
656
|
+
var generateId = (type) => type ? `${type}-${(0, import_uuid.v4)()}` : (0, import_uuid.v4)();
|
|
657
|
+
|
|
658
|
+
// lib/data/get-ids-for-parent.ts
|
|
659
|
+
init_react_import();
|
|
660
|
+
var getIdsForParent = (zoneCompound, state) => {
|
|
661
|
+
const [parentId] = zoneCompound.split(":");
|
|
662
|
+
const node = state.indexes.nodes[parentId];
|
|
663
|
+
return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
|
|
664
|
+
};
|
|
665
|
+
|
|
666
|
+
// lib/data/populate-ids.ts
|
|
667
|
+
init_react_import();
|
|
668
|
+
|
|
669
|
+
// lib/data/walk-tree.ts
|
|
670
|
+
init_react_import();
|
|
671
|
+
function walkTree(data, config, callbackFn) {
|
|
672
|
+
var _a, _b;
|
|
673
|
+
const walkItem = (item) => {
|
|
674
|
+
return mapFields(
|
|
675
|
+
item,
|
|
676
|
+
{
|
|
677
|
+
slot: ({ value, parentId, propName }) => {
|
|
678
|
+
var _a2;
|
|
679
|
+
const content = value;
|
|
680
|
+
return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
|
|
681
|
+
}
|
|
682
|
+
},
|
|
683
|
+
config,
|
|
684
|
+
true
|
|
685
|
+
);
|
|
686
|
+
};
|
|
687
|
+
if ("props" in data) {
|
|
688
|
+
return walkItem(data);
|
|
689
|
+
}
|
|
690
|
+
const _data = data;
|
|
691
|
+
const zones = (_a = _data.zones) != null ? _a : {};
|
|
692
|
+
const mappedContent = _data.content.map(walkItem);
|
|
693
|
+
return {
|
|
694
|
+
root: walkItem(_data.root),
|
|
695
|
+
content: (_b = callbackFn(mappedContent, {
|
|
696
|
+
parentId: "root",
|
|
697
|
+
propName: "default-zone"
|
|
698
|
+
})) != null ? _b : mappedContent,
|
|
699
|
+
zones: Object.keys(zones).reduce(
|
|
700
|
+
(acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
|
|
701
|
+
[zoneCompound]: zones[zoneCompound].map(walkItem)
|
|
702
|
+
}),
|
|
703
|
+
{}
|
|
704
|
+
)
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// lib/data/populate-ids.ts
|
|
709
|
+
var populateIds = (data, config, override = false) => {
|
|
710
|
+
const id = generateId(data.type);
|
|
711
|
+
return walkTree(
|
|
712
|
+
__spreadProps(__spreadValues({}, data), {
|
|
713
|
+
props: override ? __spreadProps(__spreadValues({}, data.props), { id }) : __spreadValues({}, data.props)
|
|
714
|
+
}),
|
|
715
|
+
config,
|
|
716
|
+
(contents) => contents.map((item) => {
|
|
717
|
+
const id2 = generateId(item.type);
|
|
718
|
+
return __spreadProps(__spreadValues({}, item), {
|
|
719
|
+
props: override ? __spreadProps(__spreadValues({}, item.props), { id: id2 }) : __spreadValues({ id: id2 }, item.props)
|
|
720
|
+
});
|
|
721
|
+
})
|
|
722
|
+
);
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
// reducer/actions/insert.ts
|
|
726
|
+
function insertAction(state, action, appStore) {
|
|
727
|
+
const id = action.id || generateId(action.componentType);
|
|
728
|
+
const emptyComponentData = populateIds(
|
|
729
|
+
{
|
|
730
|
+
type: action.componentType,
|
|
731
|
+
props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
|
|
732
|
+
id
|
|
733
|
+
})
|
|
734
|
+
},
|
|
735
|
+
appStore.config
|
|
736
|
+
);
|
|
737
|
+
const [parentId] = action.destinationZone.split(":");
|
|
738
|
+
const idsInPath = getIdsForParent(action.destinationZone, state);
|
|
739
|
+
return walkAppState(
|
|
740
|
+
state,
|
|
741
|
+
appStore.config,
|
|
742
|
+
(content, zoneCompound) => {
|
|
743
|
+
if (zoneCompound === action.destinationZone) {
|
|
744
|
+
return insert(
|
|
745
|
+
content || [],
|
|
746
|
+
action.destinationIndex,
|
|
747
|
+
emptyComponentData
|
|
748
|
+
);
|
|
749
|
+
}
|
|
750
|
+
return content;
|
|
751
|
+
},
|
|
752
|
+
(childItem, path) => {
|
|
753
|
+
if (childItem.props.id === id || childItem.props.id === parentId) {
|
|
754
|
+
return childItem;
|
|
755
|
+
} else if (idsInPath.includes(childItem.props.id)) {
|
|
756
|
+
return childItem;
|
|
757
|
+
} else if (path.includes(action.destinationZone)) {
|
|
758
|
+
return childItem;
|
|
759
|
+
}
|
|
760
|
+
return null;
|
|
761
|
+
}
|
|
762
|
+
);
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
// reducer/actions/replace.ts
|
|
766
|
+
init_react_import();
|
|
767
|
+
var replaceAction = (state, action, appStore) => {
|
|
768
|
+
const [parentId] = action.destinationZone.split(":");
|
|
769
|
+
const idsInPath = getIdsForParent(action.destinationZone, state);
|
|
770
|
+
const originalId = state.indexes.zones[action.destinationZone].contentIds[action.destinationIndex];
|
|
771
|
+
const idChanged = originalId !== action.data.props.id;
|
|
772
|
+
if (idChanged) {
|
|
773
|
+
throw new Error(
|
|
774
|
+
`Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
const newSlotIds = [];
|
|
778
|
+
const data = walkTree(action.data, appStore.config, (contents, opts) => {
|
|
779
|
+
newSlotIds.push(`${opts.parentId}:${opts.propName}`);
|
|
780
|
+
return contents.map((item) => {
|
|
781
|
+
const id = generateId(item.type);
|
|
782
|
+
return __spreadProps(__spreadValues({}, item), {
|
|
783
|
+
props: __spreadValues({ id }, item.props)
|
|
784
|
+
});
|
|
785
|
+
});
|
|
786
|
+
});
|
|
787
|
+
const stateWithDeepSlotsRemoved = __spreadValues({}, state);
|
|
788
|
+
Object.keys(state.indexes.zones).forEach((zoneCompound) => {
|
|
789
|
+
const id = zoneCompound.split(":")[0];
|
|
790
|
+
if (id === originalId) {
|
|
791
|
+
if (!newSlotIds.includes(zoneCompound)) {
|
|
792
|
+
delete stateWithDeepSlotsRemoved.indexes.zones[zoneCompound];
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
});
|
|
796
|
+
return walkAppState(
|
|
797
|
+
stateWithDeepSlotsRemoved,
|
|
798
|
+
appStore.config,
|
|
799
|
+
(content, zoneCompound) => {
|
|
800
|
+
const newContent = [...content];
|
|
801
|
+
if (zoneCompound === action.destinationZone) {
|
|
802
|
+
newContent[action.destinationIndex] = data;
|
|
803
|
+
}
|
|
804
|
+
return newContent;
|
|
805
|
+
},
|
|
806
|
+
(childItem, path) => {
|
|
807
|
+
const pathIds = path.map((p) => p.split(":")[0]);
|
|
808
|
+
if (childItem.props.id === data.props.id) {
|
|
809
|
+
return data;
|
|
810
|
+
} else if (childItem.props.id === parentId) {
|
|
811
|
+
return childItem;
|
|
812
|
+
} else if (idsInPath.indexOf(childItem.props.id) > -1) {
|
|
813
|
+
return childItem;
|
|
814
|
+
} else if (pathIds.indexOf(data.props.id) > -1) {
|
|
815
|
+
return childItem;
|
|
816
|
+
}
|
|
817
|
+
return null;
|
|
818
|
+
}
|
|
819
|
+
);
|
|
820
|
+
};
|
|
821
|
+
|
|
822
|
+
// reducer/actions/replace-root.ts
|
|
823
|
+
init_react_import();
|
|
824
|
+
var replaceRootAction = (state, action, appStore) => {
|
|
825
|
+
return walkAppState(
|
|
826
|
+
state,
|
|
827
|
+
appStore.config,
|
|
828
|
+
(content) => content,
|
|
829
|
+
(childItem) => {
|
|
830
|
+
if (childItem.props.id === "root") {
|
|
831
|
+
return __spreadProps(__spreadValues({}, childItem), {
|
|
832
|
+
props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
|
|
833
|
+
readOnly: action.root.readOnly
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
return childItem;
|
|
837
|
+
}
|
|
838
|
+
);
|
|
839
|
+
};
|
|
840
|
+
|
|
841
|
+
// reducer/actions/duplicate.ts
|
|
842
|
+
init_react_import();
|
|
843
|
+
|
|
844
|
+
// lib/data/get-item.ts
|
|
845
|
+
init_react_import();
|
|
846
|
+
function getItem(selector, state) {
|
|
847
|
+
var _a, _b;
|
|
848
|
+
const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
|
|
849
|
+
return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
// reducer/actions/duplicate.ts
|
|
853
|
+
function duplicateAction(state, action, appStore) {
|
|
854
|
+
const item = getItem(
|
|
855
|
+
{ index: action.sourceIndex, zone: action.sourceZone },
|
|
856
|
+
state
|
|
857
|
+
);
|
|
858
|
+
const idsInPath = getIdsForParent(action.sourceZone, state);
|
|
859
|
+
const newItem = __spreadProps(__spreadValues({}, item), {
|
|
860
|
+
props: __spreadProps(__spreadValues({}, item.props), {
|
|
861
|
+
id: generateId(item.type)
|
|
862
|
+
})
|
|
863
|
+
});
|
|
864
|
+
const modified = walkAppState(
|
|
865
|
+
state,
|
|
866
|
+
appStore.config,
|
|
867
|
+
(content, zoneCompound) => {
|
|
868
|
+
if (zoneCompound === action.sourceZone) {
|
|
869
|
+
return insert(content, action.sourceIndex + 1, item);
|
|
870
|
+
}
|
|
871
|
+
return content;
|
|
872
|
+
},
|
|
873
|
+
(childItem, path, index) => {
|
|
874
|
+
const zoneCompound = path[path.length - 1];
|
|
875
|
+
const parents = path.map((p) => p.split(":")[0]);
|
|
876
|
+
if (parents.indexOf(newItem.props.id) > -1) {
|
|
877
|
+
return __spreadProps(__spreadValues({}, childItem), {
|
|
878
|
+
props: __spreadProps(__spreadValues({}, childItem.props), {
|
|
879
|
+
id: generateId(childItem.type)
|
|
880
|
+
})
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
|
|
884
|
+
return newItem;
|
|
885
|
+
}
|
|
886
|
+
const [sourceZoneParent] = action.sourceZone.split(":");
|
|
887
|
+
if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
|
|
888
|
+
return childItem;
|
|
889
|
+
}
|
|
890
|
+
return null;
|
|
891
|
+
}
|
|
892
|
+
);
|
|
893
|
+
return __spreadProps(__spreadValues({}, modified), {
|
|
894
|
+
ui: __spreadProps(__spreadValues({}, modified.ui), {
|
|
895
|
+
itemSelector: {
|
|
896
|
+
index: action.sourceIndex + 1,
|
|
897
|
+
zone: action.sourceZone
|
|
898
|
+
}
|
|
899
|
+
})
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
// reducer/actions/reorder.ts
|
|
904
|
+
init_react_import();
|
|
905
|
+
|
|
906
|
+
// reducer/actions/move.ts
|
|
907
|
+
init_react_import();
|
|
908
|
+
|
|
909
|
+
// lib/data/remove.ts
|
|
910
|
+
init_react_import();
|
|
911
|
+
var remove = (list, index) => {
|
|
912
|
+
const result = Array.from(list);
|
|
913
|
+
result.splice(index, 1);
|
|
914
|
+
return result;
|
|
915
|
+
};
|
|
916
|
+
|
|
917
|
+
// reducer/actions/move.ts
|
|
918
|
+
var moveAction = (state, action, appStore) => {
|
|
919
|
+
if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
|
|
920
|
+
return state;
|
|
921
|
+
}
|
|
922
|
+
const item = getItem(
|
|
923
|
+
{ zone: action.sourceZone, index: action.sourceIndex },
|
|
924
|
+
state
|
|
925
|
+
);
|
|
926
|
+
if (!item) return state;
|
|
927
|
+
const idsInSourcePath = getIdsForParent(action.sourceZone, state);
|
|
928
|
+
const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
|
|
929
|
+
return walkAppState(
|
|
930
|
+
state,
|
|
931
|
+
appStore.config,
|
|
932
|
+
(content, zoneCompound) => {
|
|
933
|
+
if (zoneCompound === action.sourceZone && zoneCompound === action.destinationZone) {
|
|
934
|
+
return insert(
|
|
935
|
+
remove(content, action.sourceIndex),
|
|
936
|
+
action.destinationIndex,
|
|
937
|
+
item
|
|
938
|
+
);
|
|
939
|
+
} else if (zoneCompound === action.sourceZone) {
|
|
940
|
+
return remove(content, action.sourceIndex);
|
|
941
|
+
} else if (zoneCompound === action.destinationZone) {
|
|
942
|
+
return insert(content, action.destinationIndex, item);
|
|
943
|
+
}
|
|
944
|
+
return content;
|
|
945
|
+
},
|
|
946
|
+
(childItem, path) => {
|
|
947
|
+
const [sourceZoneParent] = action.sourceZone.split(":");
|
|
948
|
+
const [destinationZoneParent] = action.destinationZone.split(":");
|
|
949
|
+
const childId = childItem.props.id;
|
|
950
|
+
if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1 || path.includes(action.destinationZone)) {
|
|
951
|
+
return childItem;
|
|
952
|
+
}
|
|
953
|
+
return null;
|
|
954
|
+
}
|
|
955
|
+
);
|
|
956
|
+
};
|
|
957
|
+
|
|
958
|
+
// reducer/actions/reorder.ts
|
|
959
|
+
var reorderAction = (state, action, appStore) => {
|
|
960
|
+
return moveAction(
|
|
961
|
+
state,
|
|
962
|
+
{
|
|
963
|
+
type: "move",
|
|
964
|
+
sourceIndex: action.sourceIndex,
|
|
965
|
+
sourceZone: action.destinationZone,
|
|
966
|
+
destinationIndex: action.destinationIndex,
|
|
967
|
+
destinationZone: action.destinationZone
|
|
968
|
+
},
|
|
969
|
+
appStore
|
|
970
|
+
);
|
|
971
|
+
};
|
|
972
|
+
|
|
973
|
+
// reducer/actions/remove.ts
|
|
974
|
+
init_react_import();
|
|
975
|
+
var removeAction = (state, action, appStore) => {
|
|
976
|
+
const item = getItem({ index: action.index, zone: action.zone }, state);
|
|
977
|
+
const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
|
|
978
|
+
(acc, [nodeId, nodeData]) => {
|
|
979
|
+
const pathIds = nodeData.path.map((p) => p.split(":")[0]);
|
|
980
|
+
if (pathIds.includes(item.props.id)) {
|
|
981
|
+
return [...acc, nodeId];
|
|
982
|
+
}
|
|
983
|
+
return acc;
|
|
984
|
+
},
|
|
985
|
+
[item.props.id]
|
|
986
|
+
);
|
|
987
|
+
const newState = walkAppState(
|
|
988
|
+
state,
|
|
989
|
+
appStore.config,
|
|
990
|
+
(content, zoneCompound) => {
|
|
991
|
+
if (zoneCompound === action.zone) {
|
|
992
|
+
return remove(content, action.index);
|
|
993
|
+
}
|
|
994
|
+
return content;
|
|
995
|
+
}
|
|
996
|
+
);
|
|
997
|
+
Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
|
|
998
|
+
const parentId = zoneCompound.split(":")[0];
|
|
999
|
+
if (nodesToDelete.includes(parentId) && newState.data.zones) {
|
|
1000
|
+
delete newState.data.zones[zoneCompound];
|
|
1001
|
+
}
|
|
1002
|
+
});
|
|
1003
|
+
Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
|
|
1004
|
+
const parentId = zoneCompound.split(":")[0];
|
|
1005
|
+
if (nodesToDelete.includes(parentId)) {
|
|
1006
|
+
delete newState.indexes.zones[zoneCompound];
|
|
1007
|
+
}
|
|
1008
|
+
});
|
|
1009
|
+
nodesToDelete.forEach((id) => {
|
|
1010
|
+
delete newState.indexes.nodes[id];
|
|
1011
|
+
});
|
|
1012
|
+
return newState;
|
|
1013
|
+
};
|
|
1014
|
+
|
|
1015
|
+
// reducer/actions/register-zone.ts
|
|
1016
|
+
init_react_import();
|
|
1017
|
+
var zoneCache = {};
|
|
1018
|
+
function registerZoneAction(state, action) {
|
|
1019
|
+
if (zoneCache[action.zone]) {
|
|
1020
|
+
return __spreadProps(__spreadValues({}, state), {
|
|
1021
|
+
data: __spreadProps(__spreadValues({}, state.data), {
|
|
1022
|
+
zones: __spreadProps(__spreadValues({}, state.data.zones), {
|
|
1023
|
+
[action.zone]: zoneCache[action.zone]
|
|
1024
|
+
})
|
|
1025
|
+
}),
|
|
1026
|
+
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
|
1027
|
+
zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
|
|
1028
|
+
[action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
|
|
1029
|
+
contentIds: zoneCache[action.zone].map((item) => item.props.id),
|
|
1030
|
+
type: "dropzone"
|
|
1031
|
+
})
|
|
1032
|
+
})
|
|
1033
|
+
})
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
1036
|
+
return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
|
|
1037
|
+
}
|
|
1038
|
+
function unregisterZoneAction(state, action) {
|
|
1039
|
+
const _zones = __spreadValues({}, state.data.zones || {});
|
|
1040
|
+
const zoneIndex = __spreadValues({}, state.indexes.zones || {});
|
|
1041
|
+
if (_zones[action.zone]) {
|
|
1042
|
+
zoneCache[action.zone] = _zones[action.zone];
|
|
1043
|
+
delete _zones[action.zone];
|
|
1044
|
+
}
|
|
1045
|
+
delete zoneIndex[action.zone];
|
|
1046
|
+
return __spreadProps(__spreadValues({}, state), {
|
|
1047
|
+
data: __spreadProps(__spreadValues({}, state.data), {
|
|
1048
|
+
zones: _zones
|
|
1049
|
+
}),
|
|
1050
|
+
indexes: __spreadProps(__spreadValues({}, state.indexes), {
|
|
1051
|
+
zones: zoneIndex
|
|
1052
|
+
})
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
// reducer/actions/set-data.ts
|
|
1057
|
+
init_react_import();
|
|
1058
|
+
var setDataAction = (state, action, appStore) => {
|
|
1059
|
+
if (typeof action.data === "object") {
|
|
1060
|
+
console.warn(
|
|
1061
|
+
"`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
|
|
1062
|
+
);
|
|
1063
|
+
return walkAppState(
|
|
1064
|
+
__spreadProps(__spreadValues({}, state), {
|
|
1065
|
+
data: __spreadValues(__spreadValues({}, state.data), action.data)
|
|
1066
|
+
}),
|
|
1067
|
+
appStore.config
|
|
1068
|
+
);
|
|
1069
|
+
}
|
|
1070
|
+
return walkAppState(
|
|
1071
|
+
__spreadProps(__spreadValues({}, state), {
|
|
1072
|
+
data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
|
|
1073
|
+
}),
|
|
1074
|
+
appStore.config
|
|
1075
|
+
);
|
|
1076
|
+
};
|
|
1077
|
+
|
|
1078
|
+
// reducer/actions/set-ui.ts
|
|
1079
|
+
init_react_import();
|
|
1080
|
+
var setUiAction = (state, action) => {
|
|
1081
|
+
if (typeof action.ui === "object") {
|
|
1082
|
+
return __spreadProps(__spreadValues({}, state), {
|
|
1083
|
+
ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
return __spreadProps(__spreadValues({}, state), {
|
|
1087
|
+
ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
|
|
1088
|
+
});
|
|
1089
|
+
};
|
|
1090
|
+
|
|
1091
|
+
// lib/data/make-state-public.ts
|
|
1092
|
+
init_react_import();
|
|
1093
|
+
var makeStatePublic = (state) => {
|
|
1094
|
+
const { data, ui } = state;
|
|
1095
|
+
return { data, ui };
|
|
1096
|
+
};
|
|
1097
|
+
|
|
1098
|
+
// reducer/actions.tsx
|
|
1099
|
+
init_react_import();
|
|
1100
|
+
|
|
1101
|
+
// reducer/index.ts
|
|
1102
|
+
function storeInterceptor(reducer, record, onAction) {
|
|
1103
|
+
return (state, action) => {
|
|
1104
|
+
const newAppState = reducer(state, action);
|
|
1105
|
+
const isValidType = ![
|
|
1106
|
+
"registerZone",
|
|
1107
|
+
"unregisterZone",
|
|
1108
|
+
"setData",
|
|
1109
|
+
"setUi",
|
|
1110
|
+
"set"
|
|
1111
|
+
].includes(action.type);
|
|
1112
|
+
if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
|
|
1113
|
+
if (record) record(newAppState);
|
|
1114
|
+
}
|
|
1115
|
+
onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
|
|
1116
|
+
return newAppState;
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1119
|
+
function createReducer({
|
|
1120
|
+
record,
|
|
1121
|
+
onAction,
|
|
1122
|
+
appStore
|
|
1123
|
+
}) {
|
|
1124
|
+
return storeInterceptor(
|
|
1125
|
+
(state, action) => {
|
|
1126
|
+
if (action.type === "set") {
|
|
1127
|
+
return setAction(state, action, appStore);
|
|
1128
|
+
}
|
|
1129
|
+
if (action.type === "insert") {
|
|
1130
|
+
return insertAction(state, action, appStore);
|
|
1131
|
+
}
|
|
1132
|
+
if (action.type === "replace") {
|
|
1133
|
+
return replaceAction(state, action, appStore);
|
|
1134
|
+
}
|
|
1135
|
+
if (action.type === "replaceRoot") {
|
|
1136
|
+
return replaceRootAction(state, action, appStore);
|
|
1137
|
+
}
|
|
1138
|
+
if (action.type === "duplicate") {
|
|
1139
|
+
return duplicateAction(state, action, appStore);
|
|
1140
|
+
}
|
|
1141
|
+
if (action.type === "reorder") {
|
|
1142
|
+
return reorderAction(state, action, appStore);
|
|
1143
|
+
}
|
|
1144
|
+
if (action.type === "move") {
|
|
1145
|
+
return moveAction(state, action, appStore);
|
|
1146
|
+
}
|
|
1147
|
+
if (action.type === "remove") {
|
|
1148
|
+
return removeAction(state, action, appStore);
|
|
1149
|
+
}
|
|
1150
|
+
if (action.type === "registerZone") {
|
|
1151
|
+
return registerZoneAction(state, action);
|
|
1152
|
+
}
|
|
1153
|
+
if (action.type === "unregisterZone") {
|
|
1154
|
+
return unregisterZoneAction(state, action);
|
|
1155
|
+
}
|
|
1156
|
+
if (action.type === "setData") {
|
|
1157
|
+
return setDataAction(state, action, appStore);
|
|
1158
|
+
}
|
|
1159
|
+
if (action.type === "setUi") {
|
|
1160
|
+
return setUiAction(state, action);
|
|
1161
|
+
}
|
|
1162
|
+
return state;
|
|
1163
|
+
},
|
|
1164
|
+
record,
|
|
1165
|
+
onAction
|
|
1166
|
+
);
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
// components/ViewportControls/default-viewports.ts
|
|
1170
|
+
init_react_import();
|
|
1171
|
+
var defaultViewports = [
|
|
1172
|
+
{ width: 360, height: "auto", icon: "Smartphone", label: "Small" },
|
|
1173
|
+
{ width: 768, height: "auto", icon: "Tablet", label: "Medium" },
|
|
1174
|
+
{ width: 1280, height: "auto", icon: "Monitor", label: "Large" }
|
|
1175
|
+
];
|
|
1176
|
+
|
|
1177
|
+
// store/index.ts
|
|
1178
|
+
var import_zustand2 = require("zustand");
|
|
1179
|
+
var import_middleware2 = require("zustand/middleware");
|
|
1180
|
+
var import_react7 = require("react");
|
|
1181
|
+
|
|
1182
|
+
// store/slices/history.ts
|
|
1183
|
+
init_react_import();
|
|
1184
|
+
var import_react4 = require("react");
|
|
1185
|
+
|
|
1186
|
+
// lib/use-hotkey.ts
|
|
1187
|
+
init_react_import();
|
|
1188
|
+
var import_react3 = require("react");
|
|
1189
|
+
var import_zustand = require("zustand");
|
|
1190
|
+
var import_middleware = require("zustand/middleware");
|
|
1191
|
+
var useHotkeyStore = (0, import_zustand.create)()(
|
|
1192
|
+
(0, import_middleware.subscribeWithSelector)((set) => ({
|
|
1193
|
+
held: {},
|
|
1194
|
+
hold: (key) => set((s) => s.held[key] ? s : { held: __spreadProps(__spreadValues({}, s.held), { [key]: true }) }),
|
|
1195
|
+
release: (key) => set((s) => s.held[key] ? { held: __spreadProps(__spreadValues({}, s.held), { [key]: false }) } : s),
|
|
1196
|
+
reset: (held = {}) => set(() => ({ held })),
|
|
1197
|
+
triggers: {}
|
|
1198
|
+
}))
|
|
1199
|
+
);
|
|
1200
|
+
|
|
1201
|
+
// store/slices/history.ts
|
|
1202
|
+
var EMPTY_HISTORY_INDEX = 0;
|
|
1203
|
+
function debounce(func, timeout = 300) {
|
|
1204
|
+
let timer;
|
|
1205
|
+
return (...args) => {
|
|
1206
|
+
clearTimeout(timer);
|
|
1207
|
+
timer = setTimeout(() => {
|
|
1208
|
+
func(...args);
|
|
1209
|
+
}, timeout);
|
|
1210
|
+
};
|
|
1211
|
+
}
|
|
1212
|
+
var tidyState = (state) => {
|
|
1213
|
+
return __spreadProps(__spreadValues({}, state), {
|
|
1214
|
+
ui: __spreadProps(__spreadValues({}, state.ui), {
|
|
1215
|
+
field: {
|
|
1216
|
+
focus: null
|
|
1217
|
+
}
|
|
1218
|
+
})
|
|
1219
|
+
});
|
|
1220
|
+
};
|
|
1221
|
+
var createHistorySlice = (set, get) => {
|
|
1222
|
+
const record = debounce((state) => {
|
|
1223
|
+
const { histories, index } = get().history;
|
|
1224
|
+
const history = {
|
|
1225
|
+
state,
|
|
1226
|
+
id: generateId("history")
|
|
1227
|
+
};
|
|
1228
|
+
const newHistories = [...histories.slice(0, index + 1), history];
|
|
1229
|
+
set({
|
|
1230
|
+
history: __spreadProps(__spreadValues({}, get().history), {
|
|
1231
|
+
histories: newHistories,
|
|
1232
|
+
index: newHistories.length - 1
|
|
1233
|
+
})
|
|
1234
|
+
});
|
|
1235
|
+
}, 250);
|
|
1236
|
+
return {
|
|
1237
|
+
initialAppState: {},
|
|
1238
|
+
index: EMPTY_HISTORY_INDEX,
|
|
1239
|
+
histories: [],
|
|
1240
|
+
hasPast: () => get().history.index > EMPTY_HISTORY_INDEX,
|
|
1241
|
+
hasFuture: () => get().history.index < get().history.histories.length - 1,
|
|
1242
|
+
prevHistory: () => {
|
|
1243
|
+
const { history } = get();
|
|
1244
|
+
return history.hasPast() ? history.histories[history.index - 1] : null;
|
|
1245
|
+
},
|
|
1246
|
+
nextHistory: () => {
|
|
1247
|
+
const s = get().history;
|
|
1248
|
+
return s.hasFuture() ? s.histories[s.index + 1] : null;
|
|
1249
|
+
},
|
|
1250
|
+
currentHistory: () => get().history.histories[get().history.index],
|
|
1251
|
+
back: () => {
|
|
1252
|
+
var _a;
|
|
1253
|
+
const { history, dispatch } = get();
|
|
1254
|
+
if (history.hasPast()) {
|
|
1255
|
+
const state = tidyState(
|
|
1256
|
+
((_a = history.prevHistory()) == null ? void 0 : _a.state) || history.initialAppState
|
|
1257
|
+
);
|
|
1258
|
+
dispatch({
|
|
1259
|
+
type: "set",
|
|
1260
|
+
state
|
|
1261
|
+
});
|
|
1262
|
+
set({ history: __spreadProps(__spreadValues({}, history), { index: history.index - 1 }) });
|
|
1263
|
+
}
|
|
1264
|
+
},
|
|
1265
|
+
forward: () => {
|
|
1266
|
+
var _a;
|
|
1267
|
+
const { history, dispatch } = get();
|
|
1268
|
+
if (history.hasFuture()) {
|
|
1269
|
+
const state = (_a = history.nextHistory()) == null ? void 0 : _a.state;
|
|
1270
|
+
dispatch({ type: "set", state: state ? tidyState(state) : {} });
|
|
1271
|
+
set({ history: __spreadProps(__spreadValues({}, history), { index: history.index + 1 }) });
|
|
1272
|
+
}
|
|
1273
|
+
},
|
|
1274
|
+
setHistories: (histories) => {
|
|
1275
|
+
var _a;
|
|
1276
|
+
const { dispatch, history } = get();
|
|
1277
|
+
dispatch({
|
|
1278
|
+
type: "set",
|
|
1279
|
+
state: ((_a = histories[histories.length - 1]) == null ? void 0 : _a.state) || history.initialAppState
|
|
1280
|
+
});
|
|
1281
|
+
set({ history: __spreadProps(__spreadValues({}, history), { histories, index: histories.length - 1 }) });
|
|
1282
|
+
},
|
|
1283
|
+
setHistoryIndex: (index) => {
|
|
1284
|
+
var _a;
|
|
1285
|
+
const { dispatch, history } = get();
|
|
1286
|
+
dispatch({
|
|
1287
|
+
type: "set",
|
|
1288
|
+
state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
|
|
1289
|
+
});
|
|
1290
|
+
set({ history: __spreadProps(__spreadValues({}, history), { index }) });
|
|
1291
|
+
},
|
|
1292
|
+
record
|
|
1293
|
+
};
|
|
1294
|
+
};
|
|
1295
|
+
|
|
1296
|
+
// store/slices/nodes.ts
|
|
1297
|
+
init_react_import();
|
|
1298
|
+
var createNodesSlice = (set, get) => ({
|
|
1299
|
+
nodes: {},
|
|
1300
|
+
registerNode: (id, node) => {
|
|
1301
|
+
const s = get().nodes;
|
|
1302
|
+
const emptyNode = {
|
|
1303
|
+
id,
|
|
1304
|
+
methods: {
|
|
1305
|
+
sync: () => null,
|
|
1306
|
+
hideOverlay: () => null,
|
|
1307
|
+
showOverlay: () => null
|
|
1308
|
+
},
|
|
1309
|
+
element: null
|
|
1310
|
+
};
|
|
1311
|
+
const existingNode = s.nodes[id];
|
|
1312
|
+
set({
|
|
1313
|
+
nodes: __spreadProps(__spreadValues({}, s), {
|
|
1314
|
+
nodes: __spreadProps(__spreadValues({}, s.nodes), {
|
|
1315
|
+
[id]: __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, emptyNode), existingNode), node), {
|
|
1316
|
+
id
|
|
1317
|
+
})
|
|
1318
|
+
})
|
|
1319
|
+
})
|
|
1320
|
+
});
|
|
1321
|
+
},
|
|
1322
|
+
unregisterNode: (id) => {
|
|
1323
|
+
const s = get().nodes;
|
|
1324
|
+
const existingNode = s.nodes[id];
|
|
1325
|
+
if (existingNode) {
|
|
1326
|
+
const newNodes = __spreadValues({}, s.nodes);
|
|
1327
|
+
delete newNodes[id];
|
|
1328
|
+
set({
|
|
1329
|
+
nodes: __spreadProps(__spreadValues({}, s), {
|
|
1330
|
+
nodes: newNodes
|
|
1331
|
+
})
|
|
1332
|
+
});
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
});
|
|
1336
|
+
|
|
1337
|
+
// store/slices/permissions.ts
|
|
1338
|
+
init_react_import();
|
|
1339
|
+
var import_react5 = require("react");
|
|
1340
|
+
|
|
1341
|
+
// lib/data/flatten-data.ts
|
|
1342
|
+
init_react_import();
|
|
1343
|
+
var flattenData = (state, config) => {
|
|
1344
|
+
const data = [];
|
|
1345
|
+
walkAppState(
|
|
1346
|
+
state,
|
|
1347
|
+
config,
|
|
1348
|
+
(content) => content,
|
|
1349
|
+
(item) => {
|
|
1350
|
+
data.push(item);
|
|
1351
|
+
return null;
|
|
1352
|
+
}
|
|
1353
|
+
);
|
|
1354
|
+
return data;
|
|
1355
|
+
};
|
|
1356
|
+
|
|
1357
|
+
// lib/get-changed.ts
|
|
1358
|
+
init_react_import();
|
|
1359
|
+
var import_fast_deep_equal = __toESM(require("fast-deep-equal"));
|
|
1360
|
+
var getChanged = (newItem, oldItem) => {
|
|
1361
|
+
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
|
1362
|
+
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
|
1363
|
+
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
|
1364
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
1365
|
+
[item]: !(0, import_fast_deep_equal.default)(oldItemProps[item], newItemProps[item])
|
|
1366
|
+
});
|
|
1367
|
+
}, {}) : {};
|
|
1368
|
+
};
|
|
1369
|
+
|
|
1370
|
+
// store/slices/permissions.ts
|
|
1371
|
+
var createPermissionsSlice = (set, get) => {
|
|
1372
|
+
const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
|
|
1373
|
+
const { state, permissions, config } = get();
|
|
1374
|
+
const { cache: cache2, globalPermissions } = permissions;
|
|
1375
|
+
const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
|
|
1376
|
+
var _a, _b, _c;
|
|
1377
|
+
const { config: config2, state: appState, setComponentLoading } = get();
|
|
1378
|
+
const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
|
|
1379
|
+
if (!componentConfig) {
|
|
1380
|
+
return;
|
|
1381
|
+
}
|
|
1382
|
+
const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
|
|
1383
|
+
if (componentConfig.resolvePermissions) {
|
|
1384
|
+
const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
|
|
1385
|
+
if (Object.values(changed).some((el) => el === true) || force2) {
|
|
1386
|
+
const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
|
|
1387
|
+
const resolvedPermissions = yield componentConfig.resolvePermissions(
|
|
1388
|
+
item2,
|
|
1389
|
+
{
|
|
1390
|
+
changed,
|
|
1391
|
+
lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
|
|
1392
|
+
permissions: initialPermissions,
|
|
1393
|
+
appState: makeStatePublic(appState),
|
|
1394
|
+
lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
|
|
1395
|
+
}
|
|
1396
|
+
);
|
|
1397
|
+
const latest = get().permissions;
|
|
1398
|
+
set({
|
|
1399
|
+
permissions: __spreadProps(__spreadValues({}, latest), {
|
|
1400
|
+
cache: __spreadProps(__spreadValues({}, latest.cache), {
|
|
1401
|
+
[item2.props.id]: {
|
|
1402
|
+
lastData: item2,
|
|
1403
|
+
lastPermissions: resolvedPermissions
|
|
1404
|
+
}
|
|
1405
|
+
}),
|
|
1406
|
+
resolvedPermissions: __spreadProps(__spreadValues({}, latest.resolvedPermissions), {
|
|
1407
|
+
[item2.props.id]: resolvedPermissions
|
|
1408
|
+
})
|
|
1409
|
+
})
|
|
1410
|
+
});
|
|
1411
|
+
clearTimeout2();
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
});
|
|
1415
|
+
const resolveDataForRoot = (force2 = false) => {
|
|
1416
|
+
const { state: appState } = get();
|
|
1417
|
+
resolveDataForItem(
|
|
1418
|
+
// Shim the root data in by conforming to component data shape
|
|
1419
|
+
{
|
|
1420
|
+
type: "root",
|
|
1421
|
+
props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
|
|
1422
|
+
},
|
|
1423
|
+
force2
|
|
1424
|
+
);
|
|
1425
|
+
};
|
|
1426
|
+
const { item, type, root } = params;
|
|
1427
|
+
if (item) {
|
|
1428
|
+
yield resolveDataForItem(item, force);
|
|
1429
|
+
} else if (type) {
|
|
1430
|
+
flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
|
|
1431
|
+
yield resolveDataForItem(item2, force);
|
|
1432
|
+
}));
|
|
1433
|
+
} else if (root) {
|
|
1434
|
+
resolveDataForRoot(force);
|
|
1435
|
+
} else {
|
|
1436
|
+
flattenData(state, config).map((item2) => __async(void 0, null, function* () {
|
|
1437
|
+
yield resolveDataForItem(item2, force);
|
|
1438
|
+
}));
|
|
1439
|
+
}
|
|
1440
|
+
});
|
|
1441
|
+
const refreshPermissions = (params) => resolvePermissions(params, true);
|
|
1442
|
+
return {
|
|
1443
|
+
cache: {},
|
|
1444
|
+
globalPermissions: {
|
|
1445
|
+
drag: true,
|
|
1446
|
+
edit: true,
|
|
1447
|
+
delete: true,
|
|
1448
|
+
duplicate: true,
|
|
1449
|
+
insert: true
|
|
1450
|
+
},
|
|
1451
|
+
resolvedPermissions: {},
|
|
1452
|
+
getPermissions: ({ item, type, root } = {}) => {
|
|
1453
|
+
const { config, permissions } = get();
|
|
1454
|
+
const { globalPermissions, resolvedPermissions } = permissions;
|
|
1455
|
+
if (item) {
|
|
1456
|
+
const componentConfig = config.components[item.type];
|
|
1457
|
+
const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
|
|
1458
|
+
const resolvedForItem = resolvedPermissions[item.props.id];
|
|
1459
|
+
return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
|
|
1460
|
+
} else if (type) {
|
|
1461
|
+
const componentConfig = config.components[type];
|
|
1462
|
+
return __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
|
|
1463
|
+
} else if (root) {
|
|
1464
|
+
const rootConfig = config.root;
|
|
1465
|
+
const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
|
|
1466
|
+
const resolvedForItem = resolvedPermissions["root"];
|
|
1467
|
+
return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
|
|
1468
|
+
}
|
|
1469
|
+
return globalPermissions;
|
|
1470
|
+
},
|
|
1471
|
+
resolvePermissions,
|
|
1472
|
+
refreshPermissions
|
|
1473
|
+
};
|
|
1474
|
+
};
|
|
1475
|
+
|
|
1476
|
+
// store/slices/fields.ts
|
|
1477
|
+
init_react_import();
|
|
1478
|
+
var import_react6 = require("react");
|
|
1479
|
+
var createFieldsSlice = (_set, _get) => {
|
|
1480
|
+
return {
|
|
1481
|
+
fields: {},
|
|
1482
|
+
loading: false,
|
|
1483
|
+
lastResolvedData: {},
|
|
1484
|
+
id: void 0
|
|
1485
|
+
};
|
|
1486
|
+
};
|
|
1487
|
+
|
|
1488
|
+
// lib/resolve-component-data.ts
|
|
1489
|
+
init_react_import();
|
|
1490
|
+
var import_fast_deep_equal2 = __toESM(require("fast-deep-equal"));
|
|
1491
|
+
var cache = { lastChange: {} };
|
|
1492
|
+
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
|
|
1493
|
+
const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
|
|
1494
|
+
const resolvedItem = __spreadValues({}, item);
|
|
1495
|
+
const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
|
|
1496
|
+
const id = "id" in item.props ? item.props.id : "root";
|
|
1497
|
+
if (shouldRunResolver) {
|
|
1498
|
+
const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
|
|
1499
|
+
if (item && (0, import_fast_deep_equal2.default)(item, oldItem)) {
|
|
1500
|
+
return { node: resolved, didChange: false };
|
|
1501
|
+
}
|
|
1502
|
+
const changed = getChanged(item, oldItem);
|
|
1503
|
+
if (onResolveStart) {
|
|
1504
|
+
onResolveStart(item);
|
|
1505
|
+
}
|
|
1506
|
+
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
|
1507
|
+
changed,
|
|
1508
|
+
lastData: oldItem,
|
|
1509
|
+
metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
|
|
1510
|
+
trigger
|
|
1511
|
+
});
|
|
1512
|
+
resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
|
|
1513
|
+
if (Object.keys(readOnly).length) {
|
|
1514
|
+
resolvedItem.readOnly = readOnly;
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
let itemWithResolvedChildren = yield mapFields(
|
|
1518
|
+
resolvedItem,
|
|
1519
|
+
{
|
|
1520
|
+
slot: (_02) => __async(void 0, [_02], function* ({ value }) {
|
|
1521
|
+
const content = value;
|
|
1522
|
+
return yield Promise.all(
|
|
1523
|
+
content.map(
|
|
1524
|
+
(childItem) => __async(void 0, null, function* () {
|
|
1525
|
+
return (yield resolveComponentData(
|
|
1526
|
+
childItem,
|
|
1527
|
+
config,
|
|
1528
|
+
metadata,
|
|
1529
|
+
onResolveStart,
|
|
1530
|
+
onResolveEnd,
|
|
1531
|
+
trigger
|
|
1532
|
+
)).node;
|
|
1533
|
+
})
|
|
1534
|
+
)
|
|
1535
|
+
);
|
|
1536
|
+
})
|
|
1537
|
+
},
|
|
1538
|
+
config
|
|
1539
|
+
);
|
|
1540
|
+
if (shouldRunResolver && onResolveEnd) {
|
|
1541
|
+
onResolveEnd(resolvedItem);
|
|
1542
|
+
}
|
|
1543
|
+
cache.lastChange[id] = {
|
|
1544
|
+
item,
|
|
1545
|
+
resolved: itemWithResolvedChildren
|
|
1546
|
+
};
|
|
1547
|
+
return {
|
|
1548
|
+
node: itemWithResolvedChildren,
|
|
1549
|
+
didChange: !(0, import_fast_deep_equal2.default)(item, itemWithResolvedChildren)
|
|
1550
|
+
};
|
|
1551
|
+
});
|
|
1552
|
+
|
|
1553
|
+
// lib/data/to-root.ts
|
|
1554
|
+
init_react_import();
|
|
1555
|
+
var toRoot = (item) => {
|
|
1556
|
+
if ("type" in item && item.type !== "root") {
|
|
1557
|
+
throw new Error("Converting non-root item to root.");
|
|
1558
|
+
}
|
|
1559
|
+
const { readOnly } = item;
|
|
1560
|
+
if (item.props) {
|
|
1561
|
+
if ("id" in item.props) {
|
|
1562
|
+
const _a = item.props, { id } = _a, props = __objRest(_a, ["id"]);
|
|
1563
|
+
return { props, readOnly };
|
|
1564
|
+
}
|
|
1565
|
+
return { props: item.props, readOnly };
|
|
1566
|
+
}
|
|
1567
|
+
return { props: {}, readOnly };
|
|
1568
|
+
};
|
|
1569
|
+
|
|
1570
|
+
// store/default-app-state.ts
|
|
1571
|
+
init_react_import();
|
|
1572
|
+
var defaultAppState = {
|
|
1573
|
+
data: { content: [], root: {}, zones: {} },
|
|
1574
|
+
ui: {
|
|
1575
|
+
leftSideBarVisible: true,
|
|
1576
|
+
rightSideBarVisible: true,
|
|
1577
|
+
arrayState: {},
|
|
1578
|
+
itemSelector: null,
|
|
1579
|
+
componentList: {},
|
|
1580
|
+
isDragging: false,
|
|
1581
|
+
previewMode: "edit",
|
|
1582
|
+
viewports: {
|
|
1583
|
+
current: {
|
|
1584
|
+
width: defaultViewports[0].width,
|
|
1585
|
+
height: defaultViewports[0].height || "auto"
|
|
1586
|
+
},
|
|
1587
|
+
options: [],
|
|
1588
|
+
controlsVisible: true
|
|
1589
|
+
},
|
|
1590
|
+
field: { focus: null }
|
|
1591
|
+
},
|
|
1592
|
+
indexes: {
|
|
1593
|
+
nodes: {},
|
|
1594
|
+
zones: {}
|
|
1595
|
+
}
|
|
1596
|
+
};
|
|
1597
|
+
|
|
1598
|
+
// store/index.ts
|
|
1599
|
+
var defaultPageFields = {
|
|
1600
|
+
title: { type: "text" }
|
|
1601
|
+
};
|
|
1602
|
+
var createAppStore = (initialAppStore) => (0, import_zustand2.create)()(
|
|
1603
|
+
(0, import_middleware2.subscribeWithSelector)((set, get) => {
|
|
1604
|
+
var _a, _b;
|
|
1605
|
+
return __spreadProps(__spreadValues({
|
|
1606
|
+
state: defaultAppState,
|
|
1607
|
+
config: { components: {} },
|
|
1608
|
+
componentState: {},
|
|
1609
|
+
plugins: [],
|
|
1610
|
+
overrides: {},
|
|
1611
|
+
viewports: defaultViewports,
|
|
1612
|
+
zoomConfig: {
|
|
1613
|
+
autoZoom: 1,
|
|
1614
|
+
rootHeight: 0,
|
|
1615
|
+
zoom: 1
|
|
1616
|
+
},
|
|
1617
|
+
status: "LOADING",
|
|
1618
|
+
iframe: {},
|
|
1619
|
+
metadata: {},
|
|
1620
|
+
fieldTransforms: {}
|
|
1621
|
+
}, initialAppStore), {
|
|
1622
|
+
fields: createFieldsSlice(set, get),
|
|
1623
|
+
history: createHistorySlice(set, get),
|
|
1624
|
+
nodes: createNodesSlice(set, get),
|
|
1625
|
+
permissions: createPermissionsSlice(set, get),
|
|
1626
|
+
getComponentConfig: (type) => {
|
|
1627
|
+
var _a2;
|
|
1628
|
+
const { config, selectedItem } = get();
|
|
1629
|
+
const rootFields = ((_a2 = config.root) == null ? void 0 : _a2.fields) || defaultPageFields;
|
|
1630
|
+
return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
|
|
1631
|
+
},
|
|
1632
|
+
selectedItem: ((_a = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _a.ui.itemSelector) ? getItem(
|
|
1633
|
+
(_b = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _b.ui.itemSelector,
|
|
1634
|
+
initialAppStore.state
|
|
1635
|
+
) : null,
|
|
1636
|
+
dispatch: (action) => set((s) => {
|
|
1637
|
+
var _a2, _b2;
|
|
1638
|
+
const { record } = get().history;
|
|
1639
|
+
const dispatch = createReducer({
|
|
1640
|
+
record,
|
|
1641
|
+
appStore: s
|
|
1642
|
+
});
|
|
1643
|
+
const state = dispatch(s.state, action);
|
|
1644
|
+
const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
|
|
1645
|
+
(_b2 = (_a2 = get()).onAction) == null ? void 0 : _b2.call(_a2, action, state, get().state);
|
|
1646
|
+
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
|
1647
|
+
}),
|
|
1648
|
+
setZoomConfig: (zoomConfig) => set({ zoomConfig }),
|
|
1649
|
+
setStatus: (status) => set({ status }),
|
|
1650
|
+
setComponentState: (componentState) => set({ componentState }),
|
|
1651
|
+
pendingLoadTimeouts: {},
|
|
1652
|
+
setComponentLoading: (id, loading = true, defer = 0) => {
|
|
1653
|
+
const { setComponentState, pendingLoadTimeouts } = get();
|
|
1654
|
+
const loadId = generateId();
|
|
1655
|
+
const setLoading = () => {
|
|
1656
|
+
var _a2;
|
|
1657
|
+
const { componentState } = get();
|
|
1658
|
+
setComponentState(__spreadProps(__spreadValues({}, componentState), {
|
|
1659
|
+
[id]: __spreadProps(__spreadValues({}, componentState[id]), {
|
|
1660
|
+
loadingCount: (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) + 1
|
|
1661
|
+
})
|
|
1662
|
+
}));
|
|
1663
|
+
};
|
|
1664
|
+
const unsetLoading = () => {
|
|
1665
|
+
var _a2;
|
|
1666
|
+
const { componentState } = get();
|
|
1667
|
+
clearTimeout(timeout);
|
|
1668
|
+
delete pendingLoadTimeouts[loadId];
|
|
1669
|
+
set({ pendingLoadTimeouts });
|
|
1670
|
+
setComponentState(__spreadProps(__spreadValues({}, componentState), {
|
|
1671
|
+
[id]: __spreadProps(__spreadValues({}, componentState[id]), {
|
|
1672
|
+
loadingCount: Math.max(
|
|
1673
|
+
(((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) - 1,
|
|
1674
|
+
0
|
|
1675
|
+
)
|
|
1676
|
+
})
|
|
1677
|
+
}));
|
|
1678
|
+
};
|
|
1679
|
+
const timeout = setTimeout(() => {
|
|
1680
|
+
if (loading) {
|
|
1681
|
+
setLoading();
|
|
1682
|
+
} else {
|
|
1683
|
+
unsetLoading();
|
|
1684
|
+
}
|
|
1685
|
+
delete pendingLoadTimeouts[loadId];
|
|
1686
|
+
set({ pendingLoadTimeouts });
|
|
1687
|
+
}, defer);
|
|
1688
|
+
set({
|
|
1689
|
+
pendingLoadTimeouts: __spreadProps(__spreadValues({}, pendingLoadTimeouts), {
|
|
1690
|
+
[id]: timeout
|
|
1691
|
+
})
|
|
1692
|
+
});
|
|
1693
|
+
return unsetLoading;
|
|
1694
|
+
},
|
|
1695
|
+
unsetComponentLoading: (id) => {
|
|
1696
|
+
const { setComponentLoading } = get();
|
|
1697
|
+
setComponentLoading(id, false);
|
|
1698
|
+
},
|
|
1699
|
+
// Helper
|
|
1700
|
+
setUi: (ui, recordHistory) => set((s) => {
|
|
1701
|
+
const dispatch = createReducer({
|
|
1702
|
+
record: () => {
|
|
1703
|
+
},
|
|
1704
|
+
appStore: s
|
|
1705
|
+
});
|
|
1706
|
+
const state = dispatch(s.state, {
|
|
1707
|
+
type: "setUi",
|
|
1708
|
+
ui,
|
|
1709
|
+
recordHistory
|
|
1710
|
+
});
|
|
1711
|
+
const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
|
|
1712
|
+
return __spreadProps(__spreadValues({}, s), { state, selectedItem });
|
|
1713
|
+
}),
|
|
1714
|
+
resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
|
|
1715
|
+
const { config, metadata, setComponentLoading, permissions } = get();
|
|
1716
|
+
const timeouts = {};
|
|
1717
|
+
return yield resolveComponentData(
|
|
1718
|
+
componentData,
|
|
1719
|
+
config,
|
|
1720
|
+
metadata,
|
|
1721
|
+
(item) => {
|
|
1722
|
+
const id = "id" in item.props ? item.props.id : "root";
|
|
1723
|
+
timeouts[id] = setComponentLoading(id, true, 50);
|
|
1724
|
+
},
|
|
1725
|
+
(item) => __async(void 0, null, function* () {
|
|
1726
|
+
const id = "id" in item.props ? item.props.id : "root";
|
|
1727
|
+
if ("type" in item) {
|
|
1728
|
+
yield permissions.refreshPermissions({ item });
|
|
1729
|
+
} else {
|
|
1730
|
+
yield permissions.refreshPermissions({ root: true });
|
|
1731
|
+
}
|
|
1732
|
+
timeouts[id]();
|
|
1733
|
+
}),
|
|
1734
|
+
trigger
|
|
1735
|
+
);
|
|
1736
|
+
}),
|
|
1737
|
+
resolveAndCommitData: () => __async(void 0, null, function* () {
|
|
1738
|
+
const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
|
|
1739
|
+
walkAppState(
|
|
1740
|
+
state,
|
|
1741
|
+
config,
|
|
1742
|
+
(content) => content,
|
|
1743
|
+
(childItem) => {
|
|
1744
|
+
resolveComponentData2(childItem, "load").then((resolved) => {
|
|
1745
|
+
const { state: state2 } = get();
|
|
1746
|
+
const node = state2.indexes.nodes[resolved.node.props.id];
|
|
1747
|
+
if (node && resolved.didChange) {
|
|
1748
|
+
if (resolved.node.props.id === "root") {
|
|
1749
|
+
dispatch({
|
|
1750
|
+
type: "replaceRoot",
|
|
1751
|
+
root: toRoot(resolved.node)
|
|
1752
|
+
});
|
|
1753
|
+
} else {
|
|
1754
|
+
const zoneCompound = `${node.parentId}:${node.zone}`;
|
|
1755
|
+
const parentZone = state2.indexes.zones[zoneCompound];
|
|
1756
|
+
const index = parentZone.contentIds.indexOf(
|
|
1757
|
+
resolved.node.props.id
|
|
1758
|
+
);
|
|
1759
|
+
dispatch({
|
|
1760
|
+
type: "replace",
|
|
1761
|
+
data: resolved.node,
|
|
1762
|
+
destinationIndex: index,
|
|
1763
|
+
destinationZone: zoneCompound
|
|
1764
|
+
});
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
});
|
|
1768
|
+
return childItem;
|
|
1769
|
+
}
|
|
1770
|
+
);
|
|
1771
|
+
})
|
|
1772
|
+
});
|
|
1773
|
+
})
|
|
1774
|
+
);
|
|
1775
|
+
var appStoreContext = (0, import_react7.createContext)(createAppStore());
|
|
1776
|
+
function useAppStoreApi() {
|
|
1777
|
+
return (0, import_react7.useContext)(appStoreContext);
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1780
|
+
// css-module:/home/runner/work/puck/puck/packages/core/components/InlineTextField/styles.module.css#css-module
|
|
1781
|
+
init_react_import();
|
|
1782
|
+
var styles_module_default = { "InlineTextField": "_InlineTextField_ilw2a_1" };
|
|
1783
|
+
|
|
1784
|
+
// lib/index.ts
|
|
1785
|
+
init_react_import();
|
|
1786
|
+
|
|
1787
|
+
// lib/filter.ts
|
|
1788
|
+
init_react_import();
|
|
1789
|
+
|
|
1790
|
+
// lib/get-class-name-factory.ts
|
|
1791
|
+
init_react_import();
|
|
1792
|
+
var import_classnames = __toESM(require_classnames());
|
|
1793
|
+
var getClassNameFactory = (rootClass, styles, config = { baseClass: "" }) => (options = {}) => {
|
|
1794
|
+
if (typeof options === "string") {
|
|
1795
|
+
const descendant = options;
|
|
1796
|
+
const style = styles[`${rootClass}-${descendant}`];
|
|
1797
|
+
if (style) {
|
|
1798
|
+
return config.baseClass + styles[`${rootClass}-${descendant}`] || "";
|
|
1799
|
+
}
|
|
1800
|
+
return "";
|
|
1801
|
+
} else if (typeof options === "object") {
|
|
1802
|
+
const modifiers = options;
|
|
1803
|
+
const prefixedModifiers = {};
|
|
1804
|
+
for (let modifier in modifiers) {
|
|
1805
|
+
prefixedModifiers[styles[`${rootClass}--${modifier}`]] = modifiers[modifier];
|
|
1806
|
+
}
|
|
1807
|
+
const c = styles[rootClass];
|
|
1808
|
+
return config.baseClass + (0, import_classnames.default)(__spreadValues({
|
|
1809
|
+
[c]: !!c
|
|
1810
|
+
}, prefixedModifiers));
|
|
1811
|
+
} else {
|
|
1812
|
+
return config.baseClass + styles[rootClass] || "";
|
|
1813
|
+
}
|
|
1814
|
+
};
|
|
1815
|
+
var get_class_name_factory_default = getClassNameFactory;
|
|
1816
|
+
|
|
1817
|
+
// lib/data/reorder.ts
|
|
1818
|
+
init_react_import();
|
|
1819
|
+
|
|
1820
|
+
// lib/data/replace.ts
|
|
1821
|
+
init_react_import();
|
|
1822
|
+
|
|
1823
|
+
// lib/use-reset-auto-zoom.ts
|
|
1824
|
+
init_react_import();
|
|
1825
|
+
var import_react8 = require("react");
|
|
1826
|
+
|
|
1827
|
+
// lib/get-zoom-config.ts
|
|
1828
|
+
init_react_import();
|
|
1829
|
+
|
|
1830
|
+
// lib/use-reset-auto-zoom.ts
|
|
1831
|
+
var import_shallow = require("zustand/react/shallow");
|
|
1832
|
+
|
|
1833
|
+
// lib/data/set-deep.ts
|
|
1834
|
+
init_react_import();
|
|
1835
|
+
function setDeep(node, path, newVal) {
|
|
1836
|
+
const parts = path.split(".");
|
|
1837
|
+
const newNode = __spreadValues({}, node);
|
|
1838
|
+
let cur = newNode;
|
|
1839
|
+
for (let i = 0; i < parts.length; i++) {
|
|
1840
|
+
const [prop, idxStr] = parts[i].replace("]", "").split("[");
|
|
1841
|
+
const isLast = i === parts.length - 1;
|
|
1842
|
+
if (idxStr !== void 0) {
|
|
1843
|
+
if (!Array.isArray(cur[prop])) {
|
|
1844
|
+
cur[prop] = [];
|
|
1845
|
+
}
|
|
1846
|
+
const idx = Number(idxStr);
|
|
1847
|
+
if (isLast) {
|
|
1848
|
+
cur[prop][idx] = newVal;
|
|
1849
|
+
continue;
|
|
1850
|
+
}
|
|
1851
|
+
if (cur[prop][idx] === void 0) cur[prop][idx] = {};
|
|
1852
|
+
cur = cur[prop][idx];
|
|
1853
|
+
continue;
|
|
1854
|
+
}
|
|
1855
|
+
if (isLast) {
|
|
1856
|
+
cur[prop] = newVal;
|
|
1857
|
+
continue;
|
|
1858
|
+
}
|
|
1859
|
+
if (cur[prop] === void 0) {
|
|
1860
|
+
cur[prop] = {};
|
|
1861
|
+
}
|
|
1862
|
+
cur = cur[prop];
|
|
1863
|
+
}
|
|
1864
|
+
return __spreadValues(__spreadValues({}, node), newNode);
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
// components/InlineTextField/index.tsx
|
|
1868
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1869
|
+
var getClassName = get_class_name_factory_default("InlineTextField", styles_module_default);
|
|
1870
|
+
var InlineTextFieldInternal = ({
|
|
1871
|
+
propPath,
|
|
1872
|
+
componentId,
|
|
1873
|
+
value,
|
|
1874
|
+
isReadOnly,
|
|
1875
|
+
opts = {}
|
|
1876
|
+
}) => {
|
|
1877
|
+
var _a;
|
|
1878
|
+
const ref = (0, import_react9.useRef)(null);
|
|
1879
|
+
const appStoreApi = useAppStoreApi();
|
|
1880
|
+
const disableLineBreaks = (_a = opts.disableLineBreaks) != null ? _a : false;
|
|
1881
|
+
(0, import_react9.useEffect)(() => {
|
|
1882
|
+
const appStore = appStoreApi.getState();
|
|
1883
|
+
const data = appStore.state.indexes.nodes[componentId].data;
|
|
1884
|
+
const componentConfig = appStore.getComponentConfig(data.type);
|
|
1885
|
+
if (!componentConfig) {
|
|
1886
|
+
throw new Error(
|
|
1887
|
+
`InlineTextField Error: No config defined for ${data.type}`
|
|
1888
|
+
);
|
|
1889
|
+
}
|
|
1890
|
+
if (ref.current) {
|
|
1891
|
+
if (value !== ref.current.innerText) {
|
|
1892
|
+
ref.current.replaceChildren(value);
|
|
1893
|
+
}
|
|
1894
|
+
const cleanupPortal = registerOverlayPortal(ref.current);
|
|
1895
|
+
const handleInput = (e) => __async(void 0, null, function* () {
|
|
1896
|
+
var _a2;
|
|
1897
|
+
const appStore2 = appStoreApi.getState();
|
|
1898
|
+
const node = appStore2.state.indexes.nodes[componentId];
|
|
1899
|
+
const zoneCompound = `${node.parentId}:${node.zone}`;
|
|
1900
|
+
const index = (_a2 = appStore2.state.indexes.zones[zoneCompound]) == null ? void 0 : _a2.contentIds.indexOf(
|
|
1901
|
+
componentId
|
|
1902
|
+
);
|
|
1903
|
+
const newProps = setDeep(node.data.props, propPath, e.target.innerText);
|
|
1904
|
+
const resolvedData = yield appStore2.resolveComponentData(
|
|
1905
|
+
__spreadProps(__spreadValues({}, node.data), { props: newProps }),
|
|
1906
|
+
"replace"
|
|
1907
|
+
);
|
|
1908
|
+
appStore2.dispatch({
|
|
1909
|
+
type: "replace",
|
|
1910
|
+
data: resolvedData.node,
|
|
1911
|
+
destinationIndex: index,
|
|
1912
|
+
destinationZone: zoneCompound
|
|
1913
|
+
});
|
|
1914
|
+
});
|
|
1915
|
+
ref.current.addEventListener("input", handleInput);
|
|
1916
|
+
return () => {
|
|
1917
|
+
var _a2;
|
|
1918
|
+
(_a2 = ref.current) == null ? void 0 : _a2.removeEventListener("input", handleInput);
|
|
1919
|
+
cleanupPortal == null ? void 0 : cleanupPortal();
|
|
1920
|
+
};
|
|
1921
|
+
}
|
|
1922
|
+
}, [appStoreApi, ref.current, value]);
|
|
1923
|
+
const [isHovering, setIsHovering] = (0, import_react9.useState)(false);
|
|
1924
|
+
const [isFocused, setIsFocused] = (0, import_react9.useState)(false);
|
|
1925
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1926
|
+
"span",
|
|
1927
|
+
{
|
|
1928
|
+
className: getClassName(),
|
|
1929
|
+
ref,
|
|
1930
|
+
contentEditable: isHovering || isFocused ? "plaintext-only" : "false",
|
|
1931
|
+
onClick: (e) => {
|
|
1932
|
+
e.preventDefault();
|
|
1933
|
+
e.stopPropagation();
|
|
1934
|
+
},
|
|
1935
|
+
onClickCapture: (e) => {
|
|
1936
|
+
e.preventDefault();
|
|
1937
|
+
e.stopPropagation();
|
|
1938
|
+
},
|
|
1939
|
+
onKeyDown: (e) => {
|
|
1940
|
+
if (disableLineBreaks && e.key === "Enter" || isReadOnly) {
|
|
1941
|
+
e.preventDefault();
|
|
1942
|
+
}
|
|
1943
|
+
},
|
|
1944
|
+
onMouseOverCapture: () => setIsHovering(true),
|
|
1945
|
+
onMouseOutCapture: () => setIsHovering(false),
|
|
1946
|
+
onFocus: () => setIsFocused(true),
|
|
1947
|
+
onBlur: () => setIsFocused(false)
|
|
1948
|
+
}
|
|
1949
|
+
);
|
|
1950
|
+
};
|
|
1951
|
+
var InlineTextField = (0, import_react9.memo)(InlineTextFieldInternal);
|
|
1952
|
+
|
|
1953
|
+
// lib/field-transforms/default-transforms.tsx
|
|
1954
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1955
|
+
var getSlotTransform = (renderSlotEdit, renderSlotRender = renderSlotEdit) => ({
|
|
1956
|
+
slot: ({ value: content, propName, field, isReadOnly }) => {
|
|
1957
|
+
const render = isReadOnly ? renderSlotRender : renderSlotEdit;
|
|
1958
|
+
const Slot = (dzProps) => render(__spreadProps(__spreadValues({
|
|
1959
|
+
allow: (field == null ? void 0 : field.type) === "slot" ? field.allow : [],
|
|
1960
|
+
disallow: (field == null ? void 0 : field.type) === "slot" ? field.disallow : []
|
|
1961
|
+
}, dzProps), {
|
|
1962
|
+
zone: propName,
|
|
1963
|
+
content
|
|
1964
|
+
}));
|
|
1965
|
+
return Slot;
|
|
1966
|
+
}
|
|
1967
|
+
});
|
|
1968
|
+
|
|
1969
|
+
// lib/use-slots.tsx
|
|
1970
|
+
function useSlots(config, item, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
|
|
1971
|
+
return useFieldTransforms(
|
|
1972
|
+
config,
|
|
1973
|
+
item,
|
|
1974
|
+
getSlotTransform(renderSlotEdit, renderSlotRender),
|
|
1975
|
+
readOnly,
|
|
1976
|
+
forceReadOnly
|
|
1977
|
+
);
|
|
1978
|
+
}
|
|
1979
|
+
|
|
1980
|
+
// components/SlotRender/server.tsx
|
|
1981
|
+
init_react_import();
|
|
1982
|
+
var import_react10 = require("react");
|
|
1983
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1984
|
+
var SlotRenderPure = (props) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SlotRender, __spreadValues({}, props));
|
|
1985
|
+
var Item = ({
|
|
1986
|
+
config,
|
|
1987
|
+
item,
|
|
1988
|
+
metadata
|
|
1989
|
+
}) => {
|
|
1990
|
+
const Component = config.components[item.type];
|
|
1991
|
+
const props = useSlots(config, item, (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
|
|
1992
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1993
|
+
Component.render,
|
|
1994
|
+
__spreadProps(__spreadValues({}, props), {
|
|
1995
|
+
puck: __spreadProps(__spreadValues({}, props.puck), {
|
|
1996
|
+
renderDropZone: DropZoneRender,
|
|
1997
|
+
metadata: metadata || {}
|
|
1998
|
+
})
|
|
1999
|
+
})
|
|
2000
|
+
);
|
|
2001
|
+
};
|
|
2002
|
+
var SlotRender = (0, import_react10.forwardRef)(
|
|
2003
|
+
function SlotRenderInternal({ className, style, content, config, metadata }, ref) {
|
|
2004
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className, style, ref, children: content.map((item) => {
|
|
2005
|
+
if (!config.components[item.type]) {
|
|
2006
|
+
return null;
|
|
2007
|
+
}
|
|
2008
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
2009
|
+
Item,
|
|
2010
|
+
{
|
|
2011
|
+
config,
|
|
2012
|
+
item,
|
|
2013
|
+
metadata
|
|
2014
|
+
},
|
|
2015
|
+
item.props.id
|
|
2016
|
+
);
|
|
2017
|
+
}) });
|
|
2018
|
+
}
|
|
2019
|
+
);
|
|
2020
|
+
|
|
2021
|
+
// components/ServerRender/index.tsx
|
|
2022
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
2023
|
+
function DropZoneRender({
|
|
2024
|
+
zone,
|
|
2025
|
+
data,
|
|
2026
|
+
areaId = "root",
|
|
2027
|
+
config,
|
|
2028
|
+
metadata = {}
|
|
2029
|
+
}) {
|
|
2030
|
+
let zoneCompound = rootDroppableId;
|
|
2031
|
+
let content = (data == null ? void 0 : data.content) || [];
|
|
2032
|
+
if (!data || !config) {
|
|
2033
|
+
return null;
|
|
2034
|
+
}
|
|
2035
|
+
if (areaId !== rootAreaId && zone !== rootZone) {
|
|
2036
|
+
zoneCompound = `${areaId}:${zone}`;
|
|
2037
|
+
content = setupZone(data, zoneCompound).zones[zoneCompound];
|
|
2038
|
+
}
|
|
2039
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: content.map((item) => {
|
|
2040
|
+
const Component = config.components[item.type];
|
|
2041
|
+
const props = __spreadProps(__spreadValues({}, item.props), {
|
|
2042
|
+
puck: {
|
|
2043
|
+
renderDropZone: ({ zone: zone2 }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2044
|
+
DropZoneRender,
|
|
2045
|
+
{
|
|
2046
|
+
zone: zone2,
|
|
2047
|
+
data,
|
|
2048
|
+
areaId: item.props.id,
|
|
2049
|
+
config,
|
|
2050
|
+
metadata
|
|
2051
|
+
}
|
|
2052
|
+
),
|
|
2053
|
+
metadata,
|
|
2054
|
+
dragRef: null,
|
|
2055
|
+
isEditing: false
|
|
2056
|
+
}
|
|
2057
|
+
});
|
|
2058
|
+
const renderItem = __spreadProps(__spreadValues({}, item), { props });
|
|
2059
|
+
const propsWithSlots = useSlots(config, renderItem, (props2) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
|
|
2060
|
+
if (Component) {
|
|
2061
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Component.render, __spreadValues({}, propsWithSlots), renderItem.props.id);
|
|
2062
|
+
}
|
|
2063
|
+
return null;
|
|
2064
|
+
}) });
|
|
2065
|
+
}
|
|
2066
|
+
function Render({
|
|
2067
|
+
config,
|
|
2068
|
+
data,
|
|
2069
|
+
metadata = {}
|
|
2070
|
+
}) {
|
|
2071
|
+
var _a;
|
|
2072
|
+
const rootProps = "props" in data.root ? data.root.props : data.root;
|
|
2073
|
+
const title = rootProps.title || "";
|
|
2074
|
+
const props = __spreadProps(__spreadValues({}, rootProps), {
|
|
2075
|
+
puck: {
|
|
2076
|
+
renderDropZone: ({ zone }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2077
|
+
DropZoneRender,
|
|
2078
|
+
{
|
|
2079
|
+
zone,
|
|
2080
|
+
data,
|
|
2081
|
+
config,
|
|
2082
|
+
metadata
|
|
2083
|
+
}
|
|
2084
|
+
),
|
|
2085
|
+
isEditing: false,
|
|
2086
|
+
dragRef: null,
|
|
2087
|
+
metadata
|
|
2088
|
+
},
|
|
2089
|
+
title,
|
|
2090
|
+
editMode: false,
|
|
2091
|
+
id: "puck-root"
|
|
2092
|
+
});
|
|
2093
|
+
const propsWithSlots = useSlots(config, { type: "root", props }, (props2) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
|
|
2094
|
+
if ((_a = config.root) == null ? void 0 : _a.render) {
|
|
2095
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(config.root.render, __spreadProps(__spreadValues({}, propsWithSlots), { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2096
|
+
DropZoneRender,
|
|
2097
|
+
{
|
|
2098
|
+
config,
|
|
2099
|
+
data,
|
|
2100
|
+
zone: rootZone,
|
|
2101
|
+
metadata
|
|
2102
|
+
}
|
|
2103
|
+
) }));
|
|
2104
|
+
}
|
|
2105
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2106
|
+
DropZoneRender,
|
|
2107
|
+
{
|
|
2108
|
+
config,
|
|
2109
|
+
data,
|
|
2110
|
+
zone: rootZone,
|
|
2111
|
+
metadata
|
|
2112
|
+
}
|
|
2113
|
+
);
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2116
|
+
// lib/resolve-all-data.ts
|
|
2117
|
+
init_react_import();
|
|
2118
|
+
|
|
2119
|
+
// lib/data/default-data.ts
|
|
2120
|
+
init_react_import();
|
|
2121
|
+
var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
|
|
2122
|
+
root: data.root || {},
|
|
2123
|
+
content: data.content || []
|
|
2124
|
+
});
|
|
2125
|
+
|
|
2126
|
+
// lib/data/to-component.ts
|
|
2127
|
+
init_react_import();
|
|
2128
|
+
var toComponent = (item) => {
|
|
2129
|
+
return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
|
|
2130
|
+
props: __spreadProps(__spreadValues({}, item.props), { id: "root" }),
|
|
2131
|
+
type: "root"
|
|
2132
|
+
});
|
|
2133
|
+
};
|
|
2134
|
+
|
|
2135
|
+
// lib/resolve-all-data.ts
|
|
492
2136
|
function resolveAllData(_0, _1) {
|
|
493
2137
|
return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
|
|
494
2138
|
var _a;
|
|
@@ -506,9 +2150,9 @@ function resolveAllData(_0, _1) {
|
|
|
506
2150
|
},
|
|
507
2151
|
"force"
|
|
508
2152
|
)).node;
|
|
509
|
-
const resolvedDeep = yield
|
|
2153
|
+
const resolvedDeep = yield mapFields(
|
|
510
2154
|
resolved,
|
|
511
|
-
processContent,
|
|
2155
|
+
{ slot: ({ value }) => processContent(value) },
|
|
512
2156
|
config
|
|
513
2157
|
);
|
|
514
2158
|
onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
|
|
@@ -538,42 +2182,8 @@ function resolveAllData(_0, _1) {
|
|
|
538
2182
|
});
|
|
539
2183
|
}
|
|
540
2184
|
|
|
541
|
-
// lib/data/walk-tree.ts
|
|
542
|
-
function walkTree(data, config, callbackFn) {
|
|
543
|
-
var _a, _b;
|
|
544
|
-
const walkItem = (item) => {
|
|
545
|
-
return mapSlots(
|
|
546
|
-
item,
|
|
547
|
-
(content, parentId, propName) => {
|
|
548
|
-
var _a2;
|
|
549
|
-
return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
|
|
550
|
-
},
|
|
551
|
-
config,
|
|
552
|
-
true
|
|
553
|
-
);
|
|
554
|
-
};
|
|
555
|
-
if ("props" in data) {
|
|
556
|
-
return walkItem(data);
|
|
557
|
-
}
|
|
558
|
-
const _data = data;
|
|
559
|
-
const zones = (_a = _data.zones) != null ? _a : {};
|
|
560
|
-
const mappedContent = _data.content.map(walkItem);
|
|
561
|
-
return {
|
|
562
|
-
root: walkItem(_data.root),
|
|
563
|
-
content: (_b = callbackFn(mappedContent, {
|
|
564
|
-
parentId: "root",
|
|
565
|
-
propName: "default-zone"
|
|
566
|
-
})) != null ? _b : mappedContent,
|
|
567
|
-
zones: Object.keys(zones).reduce(
|
|
568
|
-
(acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
|
|
569
|
-
[zoneCompound]: zones[zoneCompound].map(walkItem)
|
|
570
|
-
}),
|
|
571
|
-
{}
|
|
572
|
-
)
|
|
573
|
-
};
|
|
574
|
-
}
|
|
575
|
-
|
|
576
2185
|
// lib/transform-props.ts
|
|
2186
|
+
init_react_import();
|
|
577
2187
|
function transformProps(data, propTransforms, config = { components: {} }) {
|
|
578
2188
|
const mapItem = (item) => {
|
|
579
2189
|
if (propTransforms[item.type]) {
|
|
@@ -603,202 +2213,8 @@ function transformProps(data, propTransforms, config = { components: {} }) {
|
|
|
603
2213
|
return updatedData;
|
|
604
2214
|
}
|
|
605
2215
|
|
|
606
|
-
// components/ViewportControls/default-viewports.ts
|
|
607
|
-
var defaultViewports = [
|
|
608
|
-
{ width: 360, height: "auto", icon: "Smartphone", label: "Small" },
|
|
609
|
-
{ width: 768, height: "auto", icon: "Tablet", label: "Medium" },
|
|
610
|
-
{ width: 1280, height: "auto", icon: "Monitor", label: "Large" }
|
|
611
|
-
];
|
|
612
|
-
|
|
613
|
-
// store/default-app-state.ts
|
|
614
|
-
var defaultAppState = {
|
|
615
|
-
data: { content: [], root: {}, zones: {} },
|
|
616
|
-
ui: {
|
|
617
|
-
leftSideBarVisible: true,
|
|
618
|
-
rightSideBarVisible: true,
|
|
619
|
-
arrayState: {},
|
|
620
|
-
itemSelector: null,
|
|
621
|
-
componentList: {},
|
|
622
|
-
isDragging: false,
|
|
623
|
-
previewMode: "edit",
|
|
624
|
-
viewports: {
|
|
625
|
-
current: {
|
|
626
|
-
width: defaultViewports[0].width,
|
|
627
|
-
height: defaultViewports[0].height || "auto"
|
|
628
|
-
},
|
|
629
|
-
options: [],
|
|
630
|
-
controlsVisible: true
|
|
631
|
-
},
|
|
632
|
-
field: { focus: null }
|
|
633
|
-
},
|
|
634
|
-
indexes: {
|
|
635
|
-
nodes: {},
|
|
636
|
-
zones: {}
|
|
637
|
-
}
|
|
638
|
-
};
|
|
639
|
-
|
|
640
|
-
// lib/get-zone-id.ts
|
|
641
|
-
var getZoneId = (zoneCompound) => {
|
|
642
|
-
if (!zoneCompound) {
|
|
643
|
-
return [];
|
|
644
|
-
}
|
|
645
|
-
if (zoneCompound && zoneCompound.indexOf(":") > -1) {
|
|
646
|
-
return zoneCompound.split(":");
|
|
647
|
-
}
|
|
648
|
-
return [rootDroppableId, zoneCompound];
|
|
649
|
-
};
|
|
650
|
-
|
|
651
|
-
// lib/data/for-related-zones.ts
|
|
652
|
-
function forRelatedZones(item, data, cb, path = []) {
|
|
653
|
-
Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
|
|
654
|
-
const [parentId] = getZoneId(zoneCompound);
|
|
655
|
-
if (parentId === item.props.id) {
|
|
656
|
-
cb(path, zoneCompound, content);
|
|
657
|
-
}
|
|
658
|
-
});
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
// lib/data/flatten-node.ts
|
|
662
|
-
var import_flat = __toESM(require("flat"));
|
|
663
|
-
|
|
664
|
-
// lib/data/strip-slots.ts
|
|
665
|
-
var stripSlots = (data, config) => {
|
|
666
|
-
return mapSlots(data, () => null, config);
|
|
667
|
-
};
|
|
668
|
-
|
|
669
|
-
// lib/data/flatten-node.ts
|
|
670
|
-
var { flatten: flatten2, unflatten } = import_flat.default;
|
|
671
|
-
var flattenNode = (node, config) => {
|
|
672
|
-
return __spreadProps(__spreadValues({}, node), {
|
|
673
|
-
props: flatten2(stripSlots(node, config).props)
|
|
674
|
-
});
|
|
675
|
-
};
|
|
676
|
-
|
|
677
|
-
// lib/data/walk-app-state.ts
|
|
678
|
-
function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
|
|
679
|
-
var _a;
|
|
680
|
-
let newZones = {};
|
|
681
|
-
const newZoneIndex = {};
|
|
682
|
-
const newNodeIndex = {};
|
|
683
|
-
const processContent = (path, zoneCompound, content, zoneType, newId) => {
|
|
684
|
-
var _a2;
|
|
685
|
-
const [parentId] = zoneCompound.split(":");
|
|
686
|
-
const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
|
|
687
|
-
const [_2, zone] = zoneCompound.split(":");
|
|
688
|
-
const newZoneCompound = `${newId || parentId}:${zone}`;
|
|
689
|
-
const newContent2 = mappedContent.map(
|
|
690
|
-
(zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
|
|
691
|
-
);
|
|
692
|
-
newZoneIndex[newZoneCompound] = {
|
|
693
|
-
contentIds: newContent2.map((item) => item.props.id),
|
|
694
|
-
type: zoneType
|
|
695
|
-
};
|
|
696
|
-
return [newZoneCompound, newContent2];
|
|
697
|
-
};
|
|
698
|
-
const processRelatedZones = (item, newId, initialPath) => {
|
|
699
|
-
forRelatedZones(
|
|
700
|
-
item,
|
|
701
|
-
state.data,
|
|
702
|
-
(relatedPath, relatedZoneCompound, relatedContent) => {
|
|
703
|
-
const [zoneCompound, newContent2] = processContent(
|
|
704
|
-
relatedPath,
|
|
705
|
-
relatedZoneCompound,
|
|
706
|
-
relatedContent,
|
|
707
|
-
"dropzone",
|
|
708
|
-
newId
|
|
709
|
-
);
|
|
710
|
-
newZones[zoneCompound] = newContent2;
|
|
711
|
-
},
|
|
712
|
-
initialPath
|
|
713
|
-
);
|
|
714
|
-
};
|
|
715
|
-
const processItem = (item, path, index) => {
|
|
716
|
-
const mappedItem = mapNodeOrSkip(item, path, index);
|
|
717
|
-
if (!mappedItem) return item;
|
|
718
|
-
const id = mappedItem.props.id;
|
|
719
|
-
const newProps = __spreadProps(__spreadValues({}, mapSlots(
|
|
720
|
-
mappedItem,
|
|
721
|
-
(content, parentId2, slotId) => {
|
|
722
|
-
const zoneCompound = `${parentId2}:${slotId}`;
|
|
723
|
-
const [_2, newContent2] = processContent(
|
|
724
|
-
path,
|
|
725
|
-
zoneCompound,
|
|
726
|
-
content,
|
|
727
|
-
"slot",
|
|
728
|
-
parentId2
|
|
729
|
-
);
|
|
730
|
-
return newContent2;
|
|
731
|
-
},
|
|
732
|
-
config
|
|
733
|
-
).props), {
|
|
734
|
-
id
|
|
735
|
-
});
|
|
736
|
-
processRelatedZones(item, id, path);
|
|
737
|
-
const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
|
|
738
|
-
const thisZoneCompound = path[path.length - 1];
|
|
739
|
-
const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
|
|
740
|
-
newNodeIndex[id] = {
|
|
741
|
-
data: newItem,
|
|
742
|
-
flatData: flattenNode(newItem, config),
|
|
743
|
-
path,
|
|
744
|
-
parentId,
|
|
745
|
-
zone
|
|
746
|
-
};
|
|
747
|
-
const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
|
|
748
|
-
if (newProps.id === "root") {
|
|
749
|
-
delete finalData["type"];
|
|
750
|
-
delete finalData.props["id"];
|
|
751
|
-
}
|
|
752
|
-
return finalData;
|
|
753
|
-
};
|
|
754
|
-
const zones = state.data.zones || {};
|
|
755
|
-
const [_, newContent] = processContent(
|
|
756
|
-
[],
|
|
757
|
-
rootDroppableId,
|
|
758
|
-
state.data.content,
|
|
759
|
-
"root"
|
|
760
|
-
);
|
|
761
|
-
const processedContent = newContent;
|
|
762
|
-
const zonesAlreadyProcessed = Object.keys(newZones);
|
|
763
|
-
Object.keys(zones || {}).forEach((zoneCompound) => {
|
|
764
|
-
const [parentId] = zoneCompound.split(":");
|
|
765
|
-
if (zonesAlreadyProcessed.includes(zoneCompound)) {
|
|
766
|
-
return;
|
|
767
|
-
}
|
|
768
|
-
const [_2, newContent2] = processContent(
|
|
769
|
-
[rootDroppableId],
|
|
770
|
-
zoneCompound,
|
|
771
|
-
zones[zoneCompound],
|
|
772
|
-
"dropzone",
|
|
773
|
-
parentId
|
|
774
|
-
);
|
|
775
|
-
newZones[zoneCompound] = newContent2;
|
|
776
|
-
}, newZones);
|
|
777
|
-
const processedRoot = processItem(
|
|
778
|
-
{
|
|
779
|
-
type: "root",
|
|
780
|
-
props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
|
|
781
|
-
},
|
|
782
|
-
[],
|
|
783
|
-
-1
|
|
784
|
-
);
|
|
785
|
-
const root = __spreadProps(__spreadValues({}, state.data.root), {
|
|
786
|
-
props: processedRoot.props
|
|
787
|
-
});
|
|
788
|
-
return __spreadProps(__spreadValues({}, state), {
|
|
789
|
-
data: {
|
|
790
|
-
root,
|
|
791
|
-
content: processedContent,
|
|
792
|
-
zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
|
|
793
|
-
},
|
|
794
|
-
indexes: {
|
|
795
|
-
nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
|
|
796
|
-
zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
|
|
797
|
-
}
|
|
798
|
-
});
|
|
799
|
-
}
|
|
800
|
-
|
|
801
2216
|
// lib/migrate.ts
|
|
2217
|
+
init_react_import();
|
|
802
2218
|
var migrations = [
|
|
803
2219
|
// Migrate root to root.props
|
|
804
2220
|
(data) => {
|
|
@@ -816,8 +2232,8 @@ var migrations = [
|
|
|
816
2232
|
return data;
|
|
817
2233
|
},
|
|
818
2234
|
// Migrate zones to slots
|
|
819
|
-
(data, config) => {
|
|
820
|
-
var _a;
|
|
2235
|
+
(data, config, migrationOptions) => {
|
|
2236
|
+
var _a, _b;
|
|
821
2237
|
if (!config) return data;
|
|
822
2238
|
console.log("Migrating DropZones to slots...");
|
|
823
2239
|
const updatedItems = {};
|
|
@@ -825,13 +2241,13 @@ var migrations = [
|
|
|
825
2241
|
const { indexes } = walkAppState(appState, config);
|
|
826
2242
|
const deletedCompounds = [];
|
|
827
2243
|
walkAppState(appState, config, (content, zoneCompound, zoneType) => {
|
|
828
|
-
var _a2,
|
|
2244
|
+
var _a2, _b2, _c;
|
|
829
2245
|
if (zoneType === "dropzone") {
|
|
830
2246
|
const [id, slotName] = zoneCompound.split(":");
|
|
831
2247
|
const nodeData = indexes.nodes[id].data;
|
|
832
2248
|
const componentType = nodeData.type;
|
|
833
2249
|
const configForComponent = id === "root" ? config.root : config.components[componentType];
|
|
834
|
-
if (((
|
|
2250
|
+
if (((_b2 = (_a2 = configForComponent == null ? void 0 : configForComponent.fields) == null ? void 0 : _a2[slotName]) == null ? void 0 : _b2.type) === "slot") {
|
|
835
2251
|
updatedItems[id] = __spreadProps(__spreadValues({}, nodeData), {
|
|
836
2252
|
props: __spreadProps(__spreadValues(__spreadValues({}, nodeData.props), (_c = updatedItems[id]) == null ? void 0 : _c.props), {
|
|
837
2253
|
[slotName]: content
|
|
@@ -860,7 +2276,49 @@ var migrations = [
|
|
|
860
2276
|
);
|
|
861
2277
|
(_a2 = updated.data.zones) == null ? true : delete _a2[zoneCompound];
|
|
862
2278
|
});
|
|
863
|
-
|
|
2279
|
+
if (migrationOptions == null ? void 0 : migrationOptions.migrateDynamicZonesForComponent) {
|
|
2280
|
+
const unmigratedZonesGrouped = {};
|
|
2281
|
+
Object.keys((_a = updated.data.zones) != null ? _a : {}).forEach((zoneCompound) => {
|
|
2282
|
+
var _a2;
|
|
2283
|
+
const [componentId, propName] = zoneCompound.split(":");
|
|
2284
|
+
const content = (_a2 = updated.data.zones) == null ? void 0 : _a2[zoneCompound];
|
|
2285
|
+
if (!content) {
|
|
2286
|
+
return;
|
|
2287
|
+
}
|
|
2288
|
+
if (!unmigratedZonesGrouped[componentId]) {
|
|
2289
|
+
unmigratedZonesGrouped[componentId] = {};
|
|
2290
|
+
}
|
|
2291
|
+
if (!unmigratedZonesGrouped[componentId][propName]) {
|
|
2292
|
+
unmigratedZonesGrouped[componentId][propName] = content;
|
|
2293
|
+
}
|
|
2294
|
+
});
|
|
2295
|
+
Object.keys(unmigratedZonesGrouped).forEach((componentId) => {
|
|
2296
|
+
updated.data = walkTree(updated.data, config, (content) => {
|
|
2297
|
+
return content.map((child) => {
|
|
2298
|
+
var _a2;
|
|
2299
|
+
if (child.props.id !== componentId) {
|
|
2300
|
+
return child;
|
|
2301
|
+
}
|
|
2302
|
+
const migrateFn = (_a2 = migrationOptions == null ? void 0 : migrationOptions.migrateDynamicZonesForComponent) == null ? void 0 : _a2[child.type];
|
|
2303
|
+
if (!migrateFn) {
|
|
2304
|
+
return child;
|
|
2305
|
+
}
|
|
2306
|
+
const zones = unmigratedZonesGrouped[componentId];
|
|
2307
|
+
const migratedProps = migrateFn(child.props, zones);
|
|
2308
|
+
Object.keys(zones).forEach((propName) => {
|
|
2309
|
+
var _a3;
|
|
2310
|
+
const zoneCompound = `${componentId}:${propName}`;
|
|
2311
|
+
console.log(`\u2713 Success: Migrated "${zoneCompound}" DropZone`);
|
|
2312
|
+
(_a3 = updated.data.zones) == null ? true : delete _a3[zoneCompound];
|
|
2313
|
+
});
|
|
2314
|
+
return __spreadProps(__spreadValues({}, child), {
|
|
2315
|
+
props: migratedProps
|
|
2316
|
+
});
|
|
2317
|
+
});
|
|
2318
|
+
});
|
|
2319
|
+
});
|
|
2320
|
+
}
|
|
2321
|
+
Object.keys((_b = updated.data.zones) != null ? _b : {}).forEach((zoneCompound) => {
|
|
864
2322
|
const [_, propName] = zoneCompound.split(":");
|
|
865
2323
|
throw new Error(
|
|
866
2324
|
`Could not migrate DropZone "${zoneCompound}" to slot field. No slot exists with the name "${propName}".`
|
|
@@ -870,9 +2328,9 @@ var migrations = [
|
|
|
870
2328
|
return updated.data;
|
|
871
2329
|
}
|
|
872
2330
|
];
|
|
873
|
-
function migrate(data, config) {
|
|
2331
|
+
function migrate(data, config, migrationOptions) {
|
|
874
2332
|
return migrations == null ? void 0 : migrations.reduce(
|
|
875
|
-
(acc, migration) => migration(acc, config),
|
|
2333
|
+
(acc, migration) => migration(acc, config, migrationOptions),
|
|
876
2334
|
data
|
|
877
2335
|
);
|
|
878
2336
|
}
|
|
@@ -884,3 +2342,12 @@ function migrate(data, config) {
|
|
|
884
2342
|
transformProps,
|
|
885
2343
|
walkTree
|
|
886
2344
|
});
|
|
2345
|
+
/*! Bundled license information:
|
|
2346
|
+
|
|
2347
|
+
classnames/index.js:
|
|
2348
|
+
(*!
|
|
2349
|
+
Copyright (c) 2018 Jed Watson.
|
|
2350
|
+
Licensed under the MIT License (MIT), see
|
|
2351
|
+
http://jedwatson.github.io/classnames
|
|
2352
|
+
*)
|
|
2353
|
+
*/
|