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