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