@measured/puck 0.19.0-canary.b918900 → 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 +122 -123
- package/dist/index.d.ts +122 -123
- package/dist/index.js +3257 -2692
- package/dist/index.mjs +2401 -2443
- package/dist/rsc.d.mts +2 -2
- package/dist/rsc.d.ts +2 -2
- package/dist/rsc.js +663 -134
- package/dist/rsc.mjs +9 -104
- package/dist/{resolve-all-data-wwgDuTnC.d.mts → walk-tree-lpK_Xw1z.d.mts} +117 -28
- package/dist/{resolve-all-data-wwgDuTnC.d.ts → walk-tree-lpK_Xw1z.d.ts} +117 -28
- package/package.json +8 -6
- 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,187 @@ 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/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");
|
96
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");
|
97
279
|
function DropZoneRender({
|
98
280
|
zone,
|
99
281
|
data,
|
@@ -110,28 +292,27 @@ function DropZoneRender({
|
|
110
292
|
zoneCompound = `${areaId}:${zone}`;
|
111
293
|
content = setupZone(data, zoneCompound).zones[zoneCompound];
|
112
294
|
}
|
113
|
-
return /* @__PURE__ */ (0,
|
295
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: content.map((item) => {
|
114
296
|
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
|
-
),
|
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,
|
130
306
|
metadata
|
131
307
|
}
|
132
|
-
|
133
|
-
|
134
|
-
|
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);
|
135
316
|
}
|
136
317
|
return null;
|
137
318
|
}) });
|
@@ -139,44 +320,43 @@ function DropZoneRender({
|
|
139
320
|
function Render({
|
140
321
|
config,
|
141
322
|
data,
|
142
|
-
metadata
|
323
|
+
metadata = {}
|
143
324
|
}) {
|
144
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 })));
|
145
348
|
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
|
-
);
|
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
|
+
) }));
|
178
358
|
}
|
179
|
-
return /* @__PURE__ */ (0,
|
359
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
180
360
|
DropZoneRender,
|
181
361
|
{
|
182
362
|
config,
|
@@ -199,26 +379,15 @@ var getChanged = (newItem, oldItem) => {
|
|
199
379
|
};
|
200
380
|
|
201
381
|
// lib/resolve-component-data.ts
|
382
|
+
var import_fast_deep_equal = __toESM(require("fast-deep-equal"));
|
202
383
|
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;
|
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 };
|
222
391
|
}
|
223
392
|
const changed = getChanged(item, oldItem);
|
224
393
|
if (onResolveStart) {
|
@@ -227,97 +396,457 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
|
|
227
396
|
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
228
397
|
changed,
|
229
398
|
lastData: oldItem,
|
230
|
-
metadata
|
399
|
+
metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
|
400
|
+
trigger
|
231
401
|
});
|
232
|
-
|
402
|
+
let resolvedItem = __spreadProps(__spreadValues({}, item), {
|
233
403
|
props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
|
234
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
|
+
}
|
235
429
|
if (Object.keys(readOnly).length) {
|
236
430
|
resolvedItem.readOnly = readOnly;
|
237
431
|
}
|
238
|
-
cache.lastChange[
|
432
|
+
cache.lastChange[id] = {
|
239
433
|
item,
|
240
434
|
resolved: resolvedItem
|
241
435
|
};
|
242
436
|
if (onResolveEnd) {
|
243
437
|
onResolveEnd(resolvedItem);
|
244
438
|
}
|
245
|
-
return resolvedItem;
|
439
|
+
return { node: resolvedItem, didChange: !(0, import_fast_deep_equal.default)(item, resolvedItem) };
|
246
440
|
}
|
247
|
-
return item;
|
441
|
+
return { node: item, didChange: false };
|
248
442
|
});
|
249
443
|
|
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
|
444
|
+
// lib/data/default-data.ts
|
279
445
|
var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
|
280
446
|
root: data.root || {},
|
281
447
|
content: data.content || []
|
282
448
|
});
|
283
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
|
+
|
284
458
|
// lib/resolve-all-data.ts
|
285
459
|
function resolveAllData(_0, _1) {
|
286
460
|
return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
|
461
|
+
var _a;
|
287
462
|
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],
|
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,
|
300
468
|
config,
|
301
469
|
metadata,
|
302
|
-
|
303
|
-
|
470
|
+
() => {
|
471
|
+
},
|
472
|
+
() => {
|
473
|
+
},
|
474
|
+
"force",
|
475
|
+
false
|
476
|
+
)).node;
|
477
|
+
const resolvedDeep = yield mapSlotsAsync(
|
478
|
+
resolved,
|
479
|
+
processContent,
|
480
|
+
false
|
304
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
|
+
});
|
305
552
|
}
|
306
|
-
return
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
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
|
316
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
|
317
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
|
+
);
|
318
844
|
}
|
319
845
|
// Annotate the CommonJS export names for ESM import in node:
|
320
846
|
0 && (module.exports = {
|
321
847
|
Render,
|
322
|
-
|
848
|
+
migrate,
|
849
|
+
resolveAllData,
|
850
|
+
transformProps,
|
851
|
+
walkTree
|
323
852
|
});
|