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