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