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