@measured/puck 0.19.0-canary.fb0e8e24 → 0.19.0
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-H4SMAS54.mjs +959 -0
- package/dist/index.css +177 -170
- package/dist/index.d.mts +14 -7
- package/dist/index.d.ts +14 -7
- package/dist/index.js +1355 -1309
- package/dist/index.mjs +1034 -1373
- package/dist/rsc.d.mts +2 -2
- package/dist/rsc.d.ts +2 -2
- package/dist/rsc.js +527 -159
- package/dist/rsc.mjs +3 -1
- package/dist/{walk-tree-CM-cu7GU.d.mts → walk-tree-DBd3aQ_5.d.mts} +30 -23
- package/dist/{walk-tree-CM-cu7GU.d.ts → walk-tree-DBd3aQ_5.d.ts} +30 -23
- package/package.json +12 -7
- package/dist/chunk-COT3ZFIM.mjs +0 -576
@@ -0,0 +1,959 @@
|
|
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
|
+
// lib/data/walk-tree.ts
|
88
|
+
init_react_import();
|
89
|
+
|
90
|
+
// lib/data/map-slots.ts
|
91
|
+
init_react_import();
|
92
|
+
|
93
|
+
// lib/data/default-slots.ts
|
94
|
+
init_react_import();
|
95
|
+
var defaultSlots = (value, fields) => Object.keys(fields).reduce(
|
96
|
+
(acc, fieldName) => fields[fieldName].type === "slot" ? __spreadValues({ [fieldName]: [] }, acc) : acc,
|
97
|
+
value
|
98
|
+
);
|
99
|
+
|
100
|
+
// lib/data/map-slots.ts
|
101
|
+
var isPromise = (v) => !!v && typeof v.then === "function";
|
102
|
+
var flatten = (values) => values.reduce((acc, item) => __spreadValues(__spreadValues({}, acc), item), {});
|
103
|
+
var containsPromise = (arr) => arr.some(isPromise);
|
104
|
+
var walkField = ({
|
105
|
+
value,
|
106
|
+
fields,
|
107
|
+
map,
|
108
|
+
propKey = "",
|
109
|
+
propPath = "",
|
110
|
+
id = "",
|
111
|
+
config,
|
112
|
+
recurseSlots = false
|
113
|
+
}) => {
|
114
|
+
var _a, _b, _c;
|
115
|
+
if (((_a = fields[propKey]) == null ? void 0 : _a.type) === "slot") {
|
116
|
+
const content = value || [];
|
117
|
+
const mappedContent = recurseSlots ? content.map((el) => {
|
118
|
+
var _a2;
|
119
|
+
const componentConfig = config.components[el.type];
|
120
|
+
if (!componentConfig) {
|
121
|
+
throw new Error(`Could not find component config for ${el.type}`);
|
122
|
+
}
|
123
|
+
const fields2 = (_a2 = componentConfig.fields) != null ? _a2 : {};
|
124
|
+
return walkField({
|
125
|
+
value: __spreadProps(__spreadValues({}, el), { props: defaultSlots(el.props, fields2) }),
|
126
|
+
fields: fields2,
|
127
|
+
map,
|
128
|
+
id: el.props.id,
|
129
|
+
config,
|
130
|
+
recurseSlots
|
131
|
+
});
|
132
|
+
}) : content;
|
133
|
+
if (containsPromise(mappedContent)) {
|
134
|
+
return Promise.all(mappedContent);
|
135
|
+
}
|
136
|
+
return map(mappedContent, id, propPath, fields[propKey], propPath);
|
137
|
+
}
|
138
|
+
if (value && typeof value === "object") {
|
139
|
+
if (Array.isArray(value)) {
|
140
|
+
const arrayFields = ((_b = fields[propKey]) == null ? void 0 : _b.type) === "array" ? fields[propKey].arrayFields : null;
|
141
|
+
if (!arrayFields) return value;
|
142
|
+
const newValue = value.map(
|
143
|
+
(el, idx) => walkField({
|
144
|
+
value: el,
|
145
|
+
fields: arrayFields,
|
146
|
+
map,
|
147
|
+
propKey,
|
148
|
+
propPath: `${propPath}[${idx}]`,
|
149
|
+
id,
|
150
|
+
config,
|
151
|
+
recurseSlots
|
152
|
+
})
|
153
|
+
);
|
154
|
+
if (containsPromise(newValue)) {
|
155
|
+
return Promise.all(newValue);
|
156
|
+
}
|
157
|
+
return newValue;
|
158
|
+
} else if ("$$typeof" in value) {
|
159
|
+
return value;
|
160
|
+
} else {
|
161
|
+
const objectFields = ((_c = fields[propKey]) == null ? void 0 : _c.type) === "object" ? fields[propKey].objectFields : fields;
|
162
|
+
return walkObject({
|
163
|
+
value,
|
164
|
+
fields: objectFields,
|
165
|
+
map,
|
166
|
+
id,
|
167
|
+
getPropPath: (k) => `${propPath}.${k}`,
|
168
|
+
config,
|
169
|
+
recurseSlots
|
170
|
+
});
|
171
|
+
}
|
172
|
+
}
|
173
|
+
return value;
|
174
|
+
};
|
175
|
+
var walkObject = ({
|
176
|
+
value,
|
177
|
+
fields,
|
178
|
+
map,
|
179
|
+
id,
|
180
|
+
getPropPath,
|
181
|
+
config,
|
182
|
+
recurseSlots
|
183
|
+
}) => {
|
184
|
+
const newProps = Object.entries(value).map(([k, v]) => {
|
185
|
+
const opts = {
|
186
|
+
value: v,
|
187
|
+
fields,
|
188
|
+
map,
|
189
|
+
propKey: k,
|
190
|
+
propPath: getPropPath(k),
|
191
|
+
id,
|
192
|
+
config,
|
193
|
+
recurseSlots
|
194
|
+
};
|
195
|
+
const newValue = walkField(opts);
|
196
|
+
if (isPromise(newValue)) {
|
197
|
+
return newValue.then((resolvedValue) => ({
|
198
|
+
[k]: resolvedValue
|
199
|
+
}));
|
200
|
+
}
|
201
|
+
return {
|
202
|
+
[k]: newValue
|
203
|
+
};
|
204
|
+
}, {});
|
205
|
+
if (containsPromise(newProps)) {
|
206
|
+
return Promise.all(newProps).then(flatten);
|
207
|
+
}
|
208
|
+
return flatten(newProps);
|
209
|
+
};
|
210
|
+
function mapSlots(item, map, config, recurseSlots = false) {
|
211
|
+
var _a, _b, _c, _d, _e;
|
212
|
+
const itemType = "type" in item ? item.type : "root";
|
213
|
+
const componentConfig = itemType === "root" ? config.root : (_a = config.components) == null ? void 0 : _a[itemType];
|
214
|
+
const newProps = walkObject({
|
215
|
+
value: defaultSlots((_b = item.props) != null ? _b : {}, (_c = componentConfig == null ? void 0 : componentConfig.fields) != null ? _c : {}),
|
216
|
+
fields: (_d = componentConfig == null ? void 0 : componentConfig.fields) != null ? _d : {},
|
217
|
+
map,
|
218
|
+
id: item.props ? (_e = item.props.id) != null ? _e : "root" : "root",
|
219
|
+
getPropPath: (k) => k,
|
220
|
+
config,
|
221
|
+
recurseSlots
|
222
|
+
});
|
223
|
+
if (isPromise(newProps)) {
|
224
|
+
return newProps.then((resolvedProps) => __spreadProps(__spreadValues({}, item), {
|
225
|
+
props: resolvedProps
|
226
|
+
}));
|
227
|
+
}
|
228
|
+
return __spreadProps(__spreadValues({}, item), {
|
229
|
+
props: newProps
|
230
|
+
});
|
231
|
+
}
|
232
|
+
|
233
|
+
// lib/data/walk-tree.ts
|
234
|
+
function walkTree(data, config, callbackFn) {
|
235
|
+
var _a, _b;
|
236
|
+
const walkItem = (item) => {
|
237
|
+
return mapSlots(
|
238
|
+
item,
|
239
|
+
(content, parentId, propName) => {
|
240
|
+
var _a2;
|
241
|
+
return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
|
242
|
+
},
|
243
|
+
config,
|
244
|
+
true
|
245
|
+
);
|
246
|
+
};
|
247
|
+
if ("props" in data) {
|
248
|
+
return walkItem(data);
|
249
|
+
}
|
250
|
+
const _data = data;
|
251
|
+
const zones = (_a = _data.zones) != null ? _a : {};
|
252
|
+
const mappedContent = _data.content.map(walkItem);
|
253
|
+
return {
|
254
|
+
root: walkItem(_data.root),
|
255
|
+
content: (_b = callbackFn(mappedContent, {
|
256
|
+
parentId: "root",
|
257
|
+
propName: "default-zone"
|
258
|
+
})) != null ? _b : mappedContent,
|
259
|
+
zones: Object.keys(zones).reduce(
|
260
|
+
(acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
|
261
|
+
[zoneCompound]: zones[zoneCompound].map(walkItem)
|
262
|
+
}),
|
263
|
+
{}
|
264
|
+
)
|
265
|
+
};
|
266
|
+
}
|
267
|
+
|
268
|
+
// components/ServerRender/index.tsx
|
269
|
+
init_react_import();
|
270
|
+
|
271
|
+
// lib/root-droppable-id.ts
|
272
|
+
init_react_import();
|
273
|
+
var rootAreaId = "root";
|
274
|
+
var rootZone = "default-zone";
|
275
|
+
var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
276
|
+
|
277
|
+
// lib/data/setup-zone.ts
|
278
|
+
init_react_import();
|
279
|
+
var setupZone = (data, zoneKey) => {
|
280
|
+
if (zoneKey === rootDroppableId) {
|
281
|
+
return data;
|
282
|
+
}
|
283
|
+
const newData = __spreadProps(__spreadValues({}, data), {
|
284
|
+
zones: data.zones ? __spreadValues({}, data.zones) : {}
|
285
|
+
});
|
286
|
+
newData.zones[zoneKey] = newData.zones[zoneKey] || [];
|
287
|
+
return newData;
|
288
|
+
};
|
289
|
+
|
290
|
+
// lib/use-slots.tsx
|
291
|
+
init_react_import();
|
292
|
+
import { useMemo } from "react";
|
293
|
+
function useSlots(config, item, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
|
294
|
+
const slotProps = useMemo(() => {
|
295
|
+
const mapped = mapSlots(
|
296
|
+
item,
|
297
|
+
(content, _parentId, propName, field, propPath) => {
|
298
|
+
const wildcardPath = propPath.replace(/\[\d+\]/g, "[*]");
|
299
|
+
const isReadOnly = (readOnly == null ? void 0 : readOnly[propPath]) || (readOnly == null ? void 0 : readOnly[wildcardPath]) || forceReadOnly;
|
300
|
+
const render = isReadOnly ? renderSlotRender : renderSlotEdit;
|
301
|
+
const Slot = (dzProps) => render(__spreadProps(__spreadValues({
|
302
|
+
allow: (field == null ? void 0 : field.type) === "slot" ? field.allow : [],
|
303
|
+
disallow: (field == null ? void 0 : field.type) === "slot" ? field.disallow : []
|
304
|
+
}, dzProps), {
|
305
|
+
zone: propName,
|
306
|
+
content
|
307
|
+
}));
|
308
|
+
return Slot;
|
309
|
+
},
|
310
|
+
config
|
311
|
+
).props;
|
312
|
+
return mapped;
|
313
|
+
}, [config, item, readOnly, forceReadOnly]);
|
314
|
+
const mergedProps = useMemo(
|
315
|
+
() => __spreadValues(__spreadValues({}, item.props), slotProps),
|
316
|
+
[item.props, slotProps]
|
317
|
+
);
|
318
|
+
return mergedProps;
|
319
|
+
}
|
320
|
+
|
321
|
+
// components/SlotRender/server.tsx
|
322
|
+
init_react_import();
|
323
|
+
import { forwardRef } from "react";
|
324
|
+
import { jsx } from "react/jsx-runtime";
|
325
|
+
var SlotRenderPure = (props) => /* @__PURE__ */ jsx(SlotRender, __spreadValues({}, props));
|
326
|
+
var Item = ({
|
327
|
+
config,
|
328
|
+
item,
|
329
|
+
metadata
|
330
|
+
}) => {
|
331
|
+
const Component = config.components[item.type];
|
332
|
+
const props = useSlots(config, item, (slotProps) => /* @__PURE__ */ jsx(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
|
333
|
+
return /* @__PURE__ */ jsx(
|
334
|
+
Component.render,
|
335
|
+
__spreadProps(__spreadValues({}, props), {
|
336
|
+
puck: __spreadProps(__spreadValues({}, props.puck), {
|
337
|
+
renderDropZone: DropZoneRender,
|
338
|
+
metadata: metadata || {}
|
339
|
+
})
|
340
|
+
})
|
341
|
+
);
|
342
|
+
};
|
343
|
+
var SlotRender = forwardRef(
|
344
|
+
function SlotRenderInternal({ className, style, content, config, metadata }, ref) {
|
345
|
+
return /* @__PURE__ */ jsx("div", { className, style, ref, children: content.map((item) => {
|
346
|
+
if (!config.components[item.type]) {
|
347
|
+
return null;
|
348
|
+
}
|
349
|
+
return /* @__PURE__ */ jsx(
|
350
|
+
Item,
|
351
|
+
{
|
352
|
+
config,
|
353
|
+
item,
|
354
|
+
metadata
|
355
|
+
},
|
356
|
+
item.props.id
|
357
|
+
);
|
358
|
+
}) });
|
359
|
+
}
|
360
|
+
);
|
361
|
+
|
362
|
+
// components/ServerRender/index.tsx
|
363
|
+
import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
|
364
|
+
function DropZoneRender({
|
365
|
+
zone,
|
366
|
+
data,
|
367
|
+
areaId = "root",
|
368
|
+
config,
|
369
|
+
metadata = {}
|
370
|
+
}) {
|
371
|
+
let zoneCompound = rootDroppableId;
|
372
|
+
let content = (data == null ? void 0 : data.content) || [];
|
373
|
+
if (!data || !config) {
|
374
|
+
return null;
|
375
|
+
}
|
376
|
+
if (areaId !== rootAreaId && zone !== rootZone) {
|
377
|
+
zoneCompound = `${areaId}:${zone}`;
|
378
|
+
content = setupZone(data, zoneCompound).zones[zoneCompound];
|
379
|
+
}
|
380
|
+
return /* @__PURE__ */ jsx2(Fragment, { children: content.map((item) => {
|
381
|
+
const Component = config.components[item.type];
|
382
|
+
const props = __spreadProps(__spreadValues({}, item.props), {
|
383
|
+
puck: {
|
384
|
+
renderDropZone: ({ zone: zone2 }) => /* @__PURE__ */ jsx2(
|
385
|
+
DropZoneRender,
|
386
|
+
{
|
387
|
+
zone: zone2,
|
388
|
+
data,
|
389
|
+
areaId: item.props.id,
|
390
|
+
config,
|
391
|
+
metadata
|
392
|
+
}
|
393
|
+
),
|
394
|
+
metadata,
|
395
|
+
dragRef: null,
|
396
|
+
isEditing: false
|
397
|
+
}
|
398
|
+
});
|
399
|
+
const renderItem = __spreadProps(__spreadValues({}, item), { props });
|
400
|
+
const propsWithSlots = useSlots(config, renderItem, (props2) => /* @__PURE__ */ jsx2(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
|
401
|
+
if (Component) {
|
402
|
+
return /* @__PURE__ */ jsx2(Component.render, __spreadValues({}, propsWithSlots), renderItem.props.id);
|
403
|
+
}
|
404
|
+
return null;
|
405
|
+
}) });
|
406
|
+
}
|
407
|
+
function Render({
|
408
|
+
config,
|
409
|
+
data,
|
410
|
+
metadata = {}
|
411
|
+
}) {
|
412
|
+
var _a;
|
413
|
+
const rootProps = "props" in data.root ? data.root.props : data.root;
|
414
|
+
const title = rootProps.title || "";
|
415
|
+
const props = __spreadProps(__spreadValues({}, rootProps), {
|
416
|
+
puck: {
|
417
|
+
renderDropZone: ({ zone }) => /* @__PURE__ */ jsx2(
|
418
|
+
DropZoneRender,
|
419
|
+
{
|
420
|
+
zone,
|
421
|
+
data,
|
422
|
+
config,
|
423
|
+
metadata
|
424
|
+
}
|
425
|
+
),
|
426
|
+
isEditing: false,
|
427
|
+
dragRef: null,
|
428
|
+
metadata
|
429
|
+
},
|
430
|
+
title,
|
431
|
+
editMode: false,
|
432
|
+
id: "puck-root"
|
433
|
+
});
|
434
|
+
const propsWithSlots = useSlots(config, { type: "root", props }, (props2) => /* @__PURE__ */ jsx2(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
|
435
|
+
if ((_a = config.root) == null ? void 0 : _a.render) {
|
436
|
+
return /* @__PURE__ */ jsx2(config.root.render, __spreadProps(__spreadValues({}, propsWithSlots), { children: /* @__PURE__ */ jsx2(
|
437
|
+
DropZoneRender,
|
438
|
+
{
|
439
|
+
config,
|
440
|
+
data,
|
441
|
+
zone: rootZone,
|
442
|
+
metadata
|
443
|
+
}
|
444
|
+
) }));
|
445
|
+
}
|
446
|
+
return /* @__PURE__ */ jsx2(
|
447
|
+
DropZoneRender,
|
448
|
+
{
|
449
|
+
config,
|
450
|
+
data,
|
451
|
+
zone: rootZone,
|
452
|
+
metadata
|
453
|
+
}
|
454
|
+
);
|
455
|
+
}
|
456
|
+
|
457
|
+
// lib/migrate.ts
|
458
|
+
init_react_import();
|
459
|
+
|
460
|
+
// store/default-app-state.ts
|
461
|
+
init_react_import();
|
462
|
+
|
463
|
+
// components/ViewportControls/default-viewports.ts
|
464
|
+
init_react_import();
|
465
|
+
var defaultViewports = [
|
466
|
+
{ width: 360, height: "auto", icon: "Smartphone", label: "Small" },
|
467
|
+
{ width: 768, height: "auto", icon: "Tablet", label: "Medium" },
|
468
|
+
{ width: 1280, height: "auto", icon: "Monitor", label: "Large" }
|
469
|
+
];
|
470
|
+
|
471
|
+
// store/default-app-state.ts
|
472
|
+
var defaultAppState = {
|
473
|
+
data: { content: [], root: {}, zones: {} },
|
474
|
+
ui: {
|
475
|
+
leftSideBarVisible: true,
|
476
|
+
rightSideBarVisible: true,
|
477
|
+
arrayState: {},
|
478
|
+
itemSelector: null,
|
479
|
+
componentList: {},
|
480
|
+
isDragging: false,
|
481
|
+
previewMode: "edit",
|
482
|
+
viewports: {
|
483
|
+
current: {
|
484
|
+
width: defaultViewports[0].width,
|
485
|
+
height: defaultViewports[0].height || "auto"
|
486
|
+
},
|
487
|
+
options: [],
|
488
|
+
controlsVisible: true
|
489
|
+
},
|
490
|
+
field: { focus: null }
|
491
|
+
},
|
492
|
+
indexes: {
|
493
|
+
nodes: {},
|
494
|
+
zones: {}
|
495
|
+
}
|
496
|
+
};
|
497
|
+
|
498
|
+
// lib/data/walk-app-state.ts
|
499
|
+
init_react_import();
|
500
|
+
|
501
|
+
// lib/data/for-related-zones.ts
|
502
|
+
init_react_import();
|
503
|
+
|
504
|
+
// lib/get-zone-id.ts
|
505
|
+
init_react_import();
|
506
|
+
var getZoneId = (zoneCompound) => {
|
507
|
+
if (!zoneCompound) {
|
508
|
+
return [];
|
509
|
+
}
|
510
|
+
if (zoneCompound && zoneCompound.indexOf(":") > -1) {
|
511
|
+
return zoneCompound.split(":");
|
512
|
+
}
|
513
|
+
return [rootDroppableId, zoneCompound];
|
514
|
+
};
|
515
|
+
|
516
|
+
// lib/data/for-related-zones.ts
|
517
|
+
function forRelatedZones(item, data, cb, path = []) {
|
518
|
+
Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
|
519
|
+
const [parentId] = getZoneId(zoneCompound);
|
520
|
+
if (parentId === item.props.id) {
|
521
|
+
cb(path, zoneCompound, content);
|
522
|
+
}
|
523
|
+
});
|
524
|
+
}
|
525
|
+
|
526
|
+
// lib/data/flatten-node.ts
|
527
|
+
init_react_import();
|
528
|
+
import { flatten as flatten2, unflatten } from "flat";
|
529
|
+
|
530
|
+
// lib/data/strip-slots.ts
|
531
|
+
init_react_import();
|
532
|
+
var stripSlots = (data, config) => {
|
533
|
+
return mapSlots(data, () => null, config);
|
534
|
+
};
|
535
|
+
|
536
|
+
// lib/data/flatten-node.ts
|
537
|
+
var flattenNode = (node, config) => {
|
538
|
+
return __spreadProps(__spreadValues({}, node), {
|
539
|
+
props: flatten2(stripSlots(node, config).props)
|
540
|
+
});
|
541
|
+
};
|
542
|
+
var expandNode = (node) => {
|
543
|
+
const props = unflatten(node.props);
|
544
|
+
return __spreadProps(__spreadValues({}, node), {
|
545
|
+
props
|
546
|
+
});
|
547
|
+
};
|
548
|
+
|
549
|
+
// lib/data/walk-app-state.ts
|
550
|
+
function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
|
551
|
+
var _a;
|
552
|
+
let newZones = {};
|
553
|
+
const newZoneIndex = {};
|
554
|
+
const newNodeIndex = {};
|
555
|
+
const processContent = (path, zoneCompound, content, zoneType, newId) => {
|
556
|
+
var _a2;
|
557
|
+
const [parentId] = zoneCompound.split(":");
|
558
|
+
const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
|
559
|
+
const [_2, zone] = zoneCompound.split(":");
|
560
|
+
const newZoneCompound = `${newId || parentId}:${zone}`;
|
561
|
+
const newContent2 = mappedContent.map(
|
562
|
+
(zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
|
563
|
+
);
|
564
|
+
newZoneIndex[newZoneCompound] = {
|
565
|
+
contentIds: newContent2.map((item) => item.props.id),
|
566
|
+
type: zoneType
|
567
|
+
};
|
568
|
+
return [newZoneCompound, newContent2];
|
569
|
+
};
|
570
|
+
const processRelatedZones = (item, newId, initialPath) => {
|
571
|
+
forRelatedZones(
|
572
|
+
item,
|
573
|
+
state.data,
|
574
|
+
(relatedPath, relatedZoneCompound, relatedContent) => {
|
575
|
+
const [zoneCompound, newContent2] = processContent(
|
576
|
+
relatedPath,
|
577
|
+
relatedZoneCompound,
|
578
|
+
relatedContent,
|
579
|
+
"dropzone",
|
580
|
+
newId
|
581
|
+
);
|
582
|
+
newZones[zoneCompound] = newContent2;
|
583
|
+
},
|
584
|
+
initialPath
|
585
|
+
);
|
586
|
+
};
|
587
|
+
const processItem = (item, path, index) => {
|
588
|
+
const mappedItem = mapNodeOrSkip(item, path, index);
|
589
|
+
if (!mappedItem) return item;
|
590
|
+
const id = mappedItem.props.id;
|
591
|
+
const newProps = __spreadProps(__spreadValues({}, mapSlots(
|
592
|
+
mappedItem,
|
593
|
+
(content, parentId2, slotId) => {
|
594
|
+
const zoneCompound = `${parentId2}:${slotId}`;
|
595
|
+
const [_2, newContent2] = processContent(
|
596
|
+
path,
|
597
|
+
zoneCompound,
|
598
|
+
content,
|
599
|
+
"slot",
|
600
|
+
parentId2
|
601
|
+
);
|
602
|
+
return newContent2;
|
603
|
+
},
|
604
|
+
config
|
605
|
+
).props), {
|
606
|
+
id
|
607
|
+
});
|
608
|
+
processRelatedZones(item, id, path);
|
609
|
+
const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
|
610
|
+
const thisZoneCompound = path[path.length - 1];
|
611
|
+
const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
|
612
|
+
newNodeIndex[id] = {
|
613
|
+
data: newItem,
|
614
|
+
flatData: flattenNode(newItem, config),
|
615
|
+
path,
|
616
|
+
parentId,
|
617
|
+
zone
|
618
|
+
};
|
619
|
+
const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
|
620
|
+
if (newProps.id === "root") {
|
621
|
+
delete finalData["type"];
|
622
|
+
delete finalData.props["id"];
|
623
|
+
}
|
624
|
+
return finalData;
|
625
|
+
};
|
626
|
+
const zones = state.data.zones || {};
|
627
|
+
const [_, newContent] = processContent(
|
628
|
+
[],
|
629
|
+
rootDroppableId,
|
630
|
+
state.data.content,
|
631
|
+
"root"
|
632
|
+
);
|
633
|
+
const processedContent = newContent;
|
634
|
+
const zonesAlreadyProcessed = Object.keys(newZones);
|
635
|
+
Object.keys(zones || {}).forEach((zoneCompound) => {
|
636
|
+
const [parentId] = zoneCompound.split(":");
|
637
|
+
if (zonesAlreadyProcessed.includes(zoneCompound)) {
|
638
|
+
return;
|
639
|
+
}
|
640
|
+
const [_2, newContent2] = processContent(
|
641
|
+
[rootDroppableId],
|
642
|
+
zoneCompound,
|
643
|
+
zones[zoneCompound],
|
644
|
+
"dropzone",
|
645
|
+
parentId
|
646
|
+
);
|
647
|
+
newZones[zoneCompound] = newContent2;
|
648
|
+
}, newZones);
|
649
|
+
const processedRoot = processItem(
|
650
|
+
{
|
651
|
+
type: "root",
|
652
|
+
props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
|
653
|
+
},
|
654
|
+
[],
|
655
|
+
-1
|
656
|
+
);
|
657
|
+
const root = __spreadProps(__spreadValues({}, state.data.root), {
|
658
|
+
props: processedRoot.props
|
659
|
+
});
|
660
|
+
return __spreadProps(__spreadValues({}, state), {
|
661
|
+
data: {
|
662
|
+
root,
|
663
|
+
content: processedContent,
|
664
|
+
zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
|
665
|
+
},
|
666
|
+
indexes: {
|
667
|
+
nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
|
668
|
+
zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
|
669
|
+
}
|
670
|
+
});
|
671
|
+
}
|
672
|
+
|
673
|
+
// lib/migrate.ts
|
674
|
+
var migrations = [
|
675
|
+
// Migrate root to root.props
|
676
|
+
(data) => {
|
677
|
+
const rootProps = data.root.props || data.root;
|
678
|
+
if (Object.keys(data.root).length > 0 && !data.root.props) {
|
679
|
+
console.warn(
|
680
|
+
"Migration applied: Root props moved from `root` to `root.props`."
|
681
|
+
);
|
682
|
+
return __spreadProps(__spreadValues({}, data), {
|
683
|
+
root: {
|
684
|
+
props: __spreadValues({}, rootProps)
|
685
|
+
}
|
686
|
+
});
|
687
|
+
}
|
688
|
+
return data;
|
689
|
+
},
|
690
|
+
// Migrate zones to slots
|
691
|
+
(data, config) => {
|
692
|
+
var _a;
|
693
|
+
if (!config) return data;
|
694
|
+
console.log("Migrating DropZones to slots...");
|
695
|
+
const updatedItems = {};
|
696
|
+
const appState = __spreadProps(__spreadValues({}, defaultAppState), { data });
|
697
|
+
const { indexes } = walkAppState(appState, config);
|
698
|
+
const deletedCompounds = [];
|
699
|
+
walkAppState(appState, config, (content, zoneCompound, zoneType) => {
|
700
|
+
var _a2, _b;
|
701
|
+
if (zoneType === "dropzone") {
|
702
|
+
const [id, slotName] = zoneCompound.split(":");
|
703
|
+
const nodeData = indexes.nodes[id].data;
|
704
|
+
const componentType = nodeData.type;
|
705
|
+
const configForComponent = id === "root" ? config.root : config.components[componentType];
|
706
|
+
if (((_b = (_a2 = configForComponent == null ? void 0 : configForComponent.fields) == null ? void 0 : _a2[slotName]) == null ? void 0 : _b.type) === "slot") {
|
707
|
+
updatedItems[id] = __spreadProps(__spreadValues({}, nodeData), {
|
708
|
+
props: __spreadProps(__spreadValues({}, nodeData.props), {
|
709
|
+
[slotName]: content
|
710
|
+
})
|
711
|
+
});
|
712
|
+
deletedCompounds.push(zoneCompound);
|
713
|
+
}
|
714
|
+
return content;
|
715
|
+
}
|
716
|
+
return content;
|
717
|
+
});
|
718
|
+
const updated = walkAppState(
|
719
|
+
appState,
|
720
|
+
config,
|
721
|
+
(content) => content,
|
722
|
+
(item) => {
|
723
|
+
var _a2;
|
724
|
+
return (_a2 = updatedItems[item.props.id]) != null ? _a2 : item;
|
725
|
+
}
|
726
|
+
);
|
727
|
+
deletedCompounds.forEach((zoneCompound) => {
|
728
|
+
var _a2;
|
729
|
+
const [_, propName] = zoneCompound.split(":");
|
730
|
+
console.log(
|
731
|
+
`\u2713 Success: Migrated "${zoneCompound}" from DropZone to slot field "${propName}"`
|
732
|
+
);
|
733
|
+
(_a2 = updated.data.zones) == null ? true : delete _a2[zoneCompound];
|
734
|
+
});
|
735
|
+
Object.keys((_a = updated.data.zones) != null ? _a : {}).forEach((zoneCompound) => {
|
736
|
+
const [_, propName] = zoneCompound.split(":");
|
737
|
+
throw new Error(
|
738
|
+
`Could not migrate DropZone "${zoneCompound}" to slot field. No slot exists with the name "${propName}".`
|
739
|
+
);
|
740
|
+
});
|
741
|
+
delete updated.data.zones;
|
742
|
+
return updated.data;
|
743
|
+
}
|
744
|
+
];
|
745
|
+
function migrate(data, config) {
|
746
|
+
return migrations == null ? void 0 : migrations.reduce(
|
747
|
+
(acc, migration) => migration(acc, config),
|
748
|
+
data
|
749
|
+
);
|
750
|
+
}
|
751
|
+
|
752
|
+
// lib/transform-props.ts
|
753
|
+
init_react_import();
|
754
|
+
|
755
|
+
// lib/data/default-data.ts
|
756
|
+
init_react_import();
|
757
|
+
var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
|
758
|
+
root: data.root || {},
|
759
|
+
content: data.content || []
|
760
|
+
});
|
761
|
+
|
762
|
+
// lib/transform-props.ts
|
763
|
+
function transformProps(data, propTransforms, config = { components: {} }) {
|
764
|
+
const mapItem = (item) => {
|
765
|
+
if (propTransforms[item.type]) {
|
766
|
+
return __spreadProps(__spreadValues({}, item), {
|
767
|
+
props: __spreadValues({
|
768
|
+
id: item.props.id
|
769
|
+
}, propTransforms[item.type](item.props))
|
770
|
+
});
|
771
|
+
}
|
772
|
+
return item;
|
773
|
+
};
|
774
|
+
const defaultedData = defaultData(data);
|
775
|
+
const rootProps = defaultedData.root.props || defaultedData.root;
|
776
|
+
let newRoot = __spreadValues({}, defaultedData.root);
|
777
|
+
if (propTransforms["root"]) {
|
778
|
+
newRoot.props = propTransforms["root"](rootProps);
|
779
|
+
}
|
780
|
+
const dataWithUpdatedRoot = __spreadProps(__spreadValues({}, defaultedData), { root: newRoot });
|
781
|
+
const updatedData = walkTree(
|
782
|
+
dataWithUpdatedRoot,
|
783
|
+
config,
|
784
|
+
(content) => content.map(mapItem)
|
785
|
+
);
|
786
|
+
if (!defaultedData.root.props) {
|
787
|
+
updatedData.root = updatedData.root.props;
|
788
|
+
}
|
789
|
+
return updatedData;
|
790
|
+
}
|
791
|
+
|
792
|
+
// lib/resolve-all-data.ts
|
793
|
+
init_react_import();
|
794
|
+
|
795
|
+
// lib/resolve-component-data.ts
|
796
|
+
init_react_import();
|
797
|
+
|
798
|
+
// lib/get-changed.ts
|
799
|
+
init_react_import();
|
800
|
+
import fdeq from "fast-deep-equal";
|
801
|
+
var getChanged = (newItem, oldItem) => {
|
802
|
+
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
803
|
+
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
804
|
+
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
805
|
+
return __spreadProps(__spreadValues({}, acc), {
|
806
|
+
[item]: !fdeq(oldItemProps[item], newItemProps[item])
|
807
|
+
});
|
808
|
+
}, {}) : {};
|
809
|
+
};
|
810
|
+
|
811
|
+
// lib/resolve-component-data.ts
|
812
|
+
import fdeq2 from "fast-deep-equal";
|
813
|
+
var cache = { lastChange: {} };
|
814
|
+
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
|
815
|
+
const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
|
816
|
+
const resolvedItem = __spreadValues({}, item);
|
817
|
+
const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
|
818
|
+
const id = "id" in item.props ? item.props.id : "root";
|
819
|
+
if (shouldRunResolver) {
|
820
|
+
const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
|
821
|
+
if (item && fdeq2(item, oldItem)) {
|
822
|
+
return { node: resolved, didChange: false };
|
823
|
+
}
|
824
|
+
const changed = getChanged(item, oldItem);
|
825
|
+
if (onResolveStart) {
|
826
|
+
onResolveStart(item);
|
827
|
+
}
|
828
|
+
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
829
|
+
changed,
|
830
|
+
lastData: oldItem,
|
831
|
+
metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
|
832
|
+
trigger
|
833
|
+
});
|
834
|
+
resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
|
835
|
+
if (Object.keys(readOnly).length) {
|
836
|
+
resolvedItem.readOnly = readOnly;
|
837
|
+
}
|
838
|
+
}
|
839
|
+
let itemWithResolvedChildren = yield mapSlots(
|
840
|
+
resolvedItem,
|
841
|
+
(content) => __async(void 0, null, function* () {
|
842
|
+
return yield Promise.all(
|
843
|
+
content.map(
|
844
|
+
(childItem) => __async(void 0, null, function* () {
|
845
|
+
return (yield resolveComponentData(
|
846
|
+
childItem,
|
847
|
+
config,
|
848
|
+
metadata,
|
849
|
+
onResolveStart,
|
850
|
+
onResolveEnd,
|
851
|
+
trigger
|
852
|
+
)).node;
|
853
|
+
})
|
854
|
+
)
|
855
|
+
);
|
856
|
+
}),
|
857
|
+
config
|
858
|
+
);
|
859
|
+
if (shouldRunResolver && onResolveEnd) {
|
860
|
+
onResolveEnd(resolvedItem);
|
861
|
+
}
|
862
|
+
cache.lastChange[id] = {
|
863
|
+
item,
|
864
|
+
resolved: itemWithResolvedChildren
|
865
|
+
};
|
866
|
+
return {
|
867
|
+
node: itemWithResolvedChildren,
|
868
|
+
didChange: !fdeq2(item, itemWithResolvedChildren)
|
869
|
+
};
|
870
|
+
});
|
871
|
+
|
872
|
+
// lib/data/to-component.ts
|
873
|
+
init_react_import();
|
874
|
+
var toComponent = (item) => {
|
875
|
+
return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
|
876
|
+
props: __spreadProps(__spreadValues({}, item.props), { id: "root" }),
|
877
|
+
type: "root"
|
878
|
+
});
|
879
|
+
};
|
880
|
+
|
881
|
+
// lib/resolve-all-data.ts
|
882
|
+
function resolveAllData(_0, _1) {
|
883
|
+
return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
|
884
|
+
var _a;
|
885
|
+
const defaultedData = defaultData(data);
|
886
|
+
const resolveNode = (_node) => __async(this, null, function* () {
|
887
|
+
const node = toComponent(_node);
|
888
|
+
onResolveStart == null ? void 0 : onResolveStart(node);
|
889
|
+
const resolved = (yield resolveComponentData(
|
890
|
+
node,
|
891
|
+
config,
|
892
|
+
metadata,
|
893
|
+
() => {
|
894
|
+
},
|
895
|
+
() => {
|
896
|
+
},
|
897
|
+
"force"
|
898
|
+
)).node;
|
899
|
+
const resolvedDeep = yield mapSlots(
|
900
|
+
resolved,
|
901
|
+
processContent,
|
902
|
+
config
|
903
|
+
);
|
904
|
+
onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
|
905
|
+
return resolvedDeep;
|
906
|
+
});
|
907
|
+
const processContent = (content) => __async(this, null, function* () {
|
908
|
+
return Promise.all(content.map(resolveNode));
|
909
|
+
});
|
910
|
+
const processZones = () => __async(this, null, function* () {
|
911
|
+
var _a2;
|
912
|
+
const zones = (_a2 = data.zones) != null ? _a2 : {};
|
913
|
+
Object.entries(zones).forEach((_02) => __async(this, [_02], function* ([zoneKey, content]) {
|
914
|
+
zones[zoneKey] = yield Promise.all(content.map(resolveNode));
|
915
|
+
}));
|
916
|
+
return zones;
|
917
|
+
});
|
918
|
+
const dynamic = {
|
919
|
+
root: yield resolveNode(defaultedData.root),
|
920
|
+
content: yield processContent(defaultedData.content),
|
921
|
+
zones: yield processZones()
|
922
|
+
};
|
923
|
+
Object.keys((_a = defaultedData.zones) != null ? _a : {}).forEach((zoneKey) => __async(this, null, function* () {
|
924
|
+
const content = defaultedData.zones[zoneKey];
|
925
|
+
dynamic.zones[zoneKey] = yield processContent(content);
|
926
|
+
}), {});
|
927
|
+
return dynamic;
|
928
|
+
});
|
929
|
+
}
|
930
|
+
|
931
|
+
export {
|
932
|
+
__spreadValues,
|
933
|
+
__spreadProps,
|
934
|
+
__objRest,
|
935
|
+
__commonJS,
|
936
|
+
__toESM,
|
937
|
+
__async,
|
938
|
+
init_react_import,
|
939
|
+
rootAreaId,
|
940
|
+
rootZone,
|
941
|
+
rootDroppableId,
|
942
|
+
defaultSlots,
|
943
|
+
walkField,
|
944
|
+
expandNode,
|
945
|
+
walkAppState,
|
946
|
+
walkTree,
|
947
|
+
setupZone,
|
948
|
+
defaultViewports,
|
949
|
+
getChanged,
|
950
|
+
resolveComponentData,
|
951
|
+
defaultAppState,
|
952
|
+
useSlots,
|
953
|
+
Render,
|
954
|
+
SlotRenderPure,
|
955
|
+
SlotRender,
|
956
|
+
migrate,
|
957
|
+
transformProps,
|
958
|
+
resolveAllData
|
959
|
+
};
|