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