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