@measured/puck 0.18.3-canary.b44056f → 0.19.0-canary.01a27f78
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-HGAPIQP5.mjs +949 -0
- package/dist/index.css +201 -184
- package/dist/index.d.mts +155 -56
- package/dist/index.d.ts +155 -56
- package/dist/index.js +4452 -3605
- package/dist/index.mjs +3548 -3349
- package/dist/rsc.d.mts +4 -3
- package/dist/rsc.d.ts +4 -3
- package/dist/rsc.js +724 -123
- package/dist/rsc.mjs +9 -71
- package/dist/{resolve-all-data-ppm982Jh.d.mts → walk-tree-DBd3aQ_5.d.mts} +137 -41
- package/dist/{resolve-all-data-ppm982Jh.d.ts → walk-tree-DBd3aQ_5.d.ts} +137 -41
- package/package.json +18 -11
- package/dist/chunk-CHWFBYEM.mjs +0 -256
package/dist/rsc.js
CHANGED
@@ -68,7 +68,10 @@ var __async = (__this, __arguments, generator) => {
|
|
68
68
|
var rsc_exports = {};
|
69
69
|
__export(rsc_exports, {
|
70
70
|
Render: () => Render,
|
71
|
-
|
71
|
+
migrate: () => migrate,
|
72
|
+
resolveAllData: () => resolveAllData,
|
73
|
+
transformProps: () => transformProps,
|
74
|
+
walkTree: () => walkTree
|
72
75
|
});
|
73
76
|
module.exports = __toCommonJS(rsc_exports);
|
74
77
|
|
@@ -76,9 +79,11 @@ module.exports = __toCommonJS(rsc_exports);
|
|
76
79
|
var import_react = __toESM(require("react"));
|
77
80
|
|
78
81
|
// lib/root-droppable-id.ts
|
79
|
-
var
|
82
|
+
var rootAreaId = "root";
|
83
|
+
var rootZone = "default-zone";
|
84
|
+
var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
80
85
|
|
81
|
-
// lib/setup-zone.ts
|
86
|
+
// lib/data/setup-zone.ts
|
82
87
|
var setupZone = (data, zoneKey) => {
|
83
88
|
if (zoneKey === rootDroppableId) {
|
84
89
|
return data;
|
@@ -90,189 +95,785 @@ var setupZone = (data, zoneKey) => {
|
|
90
95
|
return newData;
|
91
96
|
};
|
92
97
|
|
93
|
-
//
|
98
|
+
// lib/use-slots.tsx
|
99
|
+
var import_react2 = require("react");
|
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) {
|
236
|
+
const slotProps = (0, import_react2.useMemo)(() => {
|
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;
|
243
|
+
const Slot = (dzProps) => render(__spreadProps(__spreadValues({
|
244
|
+
allow: (field == null ? void 0 : field.type) === "slot" ? field.allow : [],
|
245
|
+
disallow: (field == null ? void 0 : field.type) === "slot" ? field.disallow : []
|
246
|
+
}, dzProps), {
|
247
|
+
zone: propName,
|
248
|
+
content
|
249
|
+
}));
|
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;
|
261
|
+
}
|
262
|
+
|
263
|
+
// components/SlotRender/server.tsx
|
264
|
+
var import_react3 = require("react");
|
94
265
|
var import_jsx_runtime = require("react/jsx-runtime");
|
266
|
+
var SlotRenderPure = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SlotRender, __spreadValues({}, props));
|
267
|
+
var Item = ({
|
268
|
+
config,
|
269
|
+
item,
|
270
|
+
metadata
|
271
|
+
}) => {
|
272
|
+
const Component = config.components[item.type];
|
273
|
+
const props = useSlots(config, item, (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
|
274
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
275
|
+
Component.render,
|
276
|
+
__spreadProps(__spreadValues({}, props), {
|
277
|
+
puck: __spreadProps(__spreadValues({}, props.puck), {
|
278
|
+
renderDropZone: DropZoneRender,
|
279
|
+
metadata: metadata || {}
|
280
|
+
})
|
281
|
+
})
|
282
|
+
);
|
283
|
+
};
|
284
|
+
var SlotRender = (0, import_react3.forwardRef)(
|
285
|
+
function SlotRenderInternal({ className, style, content, config, metadata }, ref) {
|
286
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className, style, ref, children: content.map((item) => {
|
287
|
+
if (!config.components[item.type]) {
|
288
|
+
return null;
|
289
|
+
}
|
290
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
291
|
+
Item,
|
292
|
+
{
|
293
|
+
config,
|
294
|
+
item,
|
295
|
+
metadata
|
296
|
+
},
|
297
|
+
item.props.id
|
298
|
+
);
|
299
|
+
}) });
|
300
|
+
}
|
301
|
+
);
|
302
|
+
|
303
|
+
// components/ServerRender/index.tsx
|
304
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
95
305
|
function DropZoneRender({
|
96
306
|
zone,
|
97
307
|
data,
|
98
308
|
areaId = "root",
|
99
|
-
config
|
309
|
+
config,
|
310
|
+
metadata = {}
|
100
311
|
}) {
|
101
312
|
let zoneCompound = rootDroppableId;
|
102
313
|
let content = (data == null ? void 0 : data.content) || [];
|
103
314
|
if (!data || !config) {
|
104
315
|
return null;
|
105
316
|
}
|
106
|
-
if (areaId
|
317
|
+
if (areaId !== rootAreaId && zone !== rootZone) {
|
107
318
|
zoneCompound = `${areaId}:${zone}`;
|
108
319
|
content = setupZone(data, zoneCompound).zones[zoneCompound];
|
109
320
|
}
|
110
|
-
return /* @__PURE__ */ (0,
|
321
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: content.map((item) => {
|
111
322
|
const Component = config.components[item.type];
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
areaId: item.props.id,
|
123
|
-
config
|
124
|
-
}
|
125
|
-
)
|
323
|
+
const props = __spreadProps(__spreadValues({}, item.props), {
|
324
|
+
puck: {
|
325
|
+
renderDropZone: ({ zone: zone2 }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
326
|
+
DropZoneRender,
|
327
|
+
{
|
328
|
+
zone: zone2,
|
329
|
+
data,
|
330
|
+
areaId: item.props.id,
|
331
|
+
config,
|
332
|
+
metadata
|
126
333
|
}
|
127
|
-
|
128
|
-
|
129
|
-
|
334
|
+
),
|
335
|
+
metadata,
|
336
|
+
dragRef: null,
|
337
|
+
isEditing: false
|
338
|
+
}
|
339
|
+
});
|
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 })));
|
342
|
+
if (Component) {
|
343
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Component.render, __spreadValues({}, propsWithSlots), renderItem.props.id);
|
130
344
|
}
|
131
345
|
return null;
|
132
346
|
}) });
|
133
347
|
}
|
134
|
-
function Render({
|
348
|
+
function Render({
|
349
|
+
config,
|
350
|
+
data,
|
351
|
+
metadata = {}
|
352
|
+
}) {
|
135
353
|
var _a;
|
354
|
+
const rootProps = "props" in data.root ? data.root.props : data.root;
|
355
|
+
const title = rootProps.title || "";
|
356
|
+
const props = __spreadProps(__spreadValues({}, rootProps), {
|
357
|
+
puck: {
|
358
|
+
renderDropZone: ({ zone }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
359
|
+
DropZoneRender,
|
360
|
+
{
|
361
|
+
zone,
|
362
|
+
data,
|
363
|
+
config,
|
364
|
+
metadata
|
365
|
+
}
|
366
|
+
),
|
367
|
+
isEditing: false,
|
368
|
+
dragRef: null,
|
369
|
+
metadata
|
370
|
+
},
|
371
|
+
title,
|
372
|
+
editMode: false,
|
373
|
+
id: "puck-root"
|
374
|
+
});
|
375
|
+
const propsWithSlots = useSlots(config, { type: "root", props }, (props2) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
|
136
376
|
if ((_a = config.root) == null ? void 0 : _a.render) {
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
},
|
147
|
-
title,
|
148
|
-
editMode: false,
|
149
|
-
id: "puck-root",
|
150
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropZoneRender, { config, data, zone: rootDroppableId })
|
151
|
-
})
|
152
|
-
);
|
377
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(config.root.render, __spreadProps(__spreadValues({}, propsWithSlots), { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
378
|
+
DropZoneRender,
|
379
|
+
{
|
380
|
+
config,
|
381
|
+
data,
|
382
|
+
zone: rootZone,
|
383
|
+
metadata
|
384
|
+
}
|
385
|
+
) }));
|
153
386
|
}
|
154
|
-
return /* @__PURE__ */ (0,
|
387
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
388
|
+
DropZoneRender,
|
389
|
+
{
|
390
|
+
config,
|
391
|
+
data,
|
392
|
+
zone: rootZone,
|
393
|
+
metadata
|
394
|
+
}
|
395
|
+
);
|
155
396
|
}
|
156
397
|
|
157
398
|
// lib/get-changed.ts
|
399
|
+
var import_fast_deep_equal = __toESM(require("fast-deep-equal"));
|
158
400
|
var getChanged = (newItem, oldItem) => {
|
159
401
|
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
160
402
|
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
161
403
|
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
162
404
|
return __spreadProps(__spreadValues({}, acc), {
|
163
|
-
[item]: oldItemProps[item]
|
405
|
+
[item]: !(0, import_fast_deep_equal.default)(oldItemProps[item], newItemProps[item])
|
164
406
|
});
|
165
407
|
}, {}) : {};
|
166
408
|
};
|
167
409
|
|
168
410
|
// lib/resolve-component-data.ts
|
411
|
+
var import_fast_deep_equal2 = __toESM(require("fast-deep-equal"));
|
169
412
|
var cache = { lastChange: {} };
|
170
|
-
var
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
}))
|
180
|
-
);
|
181
|
-
});
|
182
|
-
var resolveComponentData = (item, config, onResolveStart, onResolveEnd) => __async(void 0, null, function* () {
|
183
|
-
const configForItem = config.components[item.type];
|
184
|
-
if (configForItem.resolveData) {
|
185
|
-
const { item: oldItem = null, resolved = {} } = cache.lastChange[item.props.id] || {};
|
186
|
-
if (item && item === oldItem) {
|
187
|
-
return resolved;
|
413
|
+
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
|
414
|
+
const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
|
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) {
|
419
|
+
const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
|
420
|
+
if (item && (0, import_fast_deep_equal2.default)(item, oldItem)) {
|
421
|
+
return { node: resolved, didChange: false };
|
188
422
|
}
|
189
423
|
const changed = getChanged(item, oldItem);
|
190
424
|
if (onResolveStart) {
|
191
425
|
onResolveStart(item);
|
192
426
|
}
|
193
|
-
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
194
|
-
|
195
|
-
|
427
|
+
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
428
|
+
changed,
|
429
|
+
lastData: oldItem,
|
430
|
+
metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
|
431
|
+
trigger
|
196
432
|
});
|
433
|
+
resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
|
197
434
|
if (Object.keys(readOnly).length) {
|
198
435
|
resolvedItem.readOnly = readOnly;
|
199
436
|
}
|
200
|
-
cache.lastChange[item.props.id] = {
|
201
|
-
item,
|
202
|
-
resolved: resolvedItem
|
203
|
-
};
|
204
|
-
if (onResolveEnd) {
|
205
|
-
onResolveEnd(resolvedItem);
|
206
|
-
}
|
207
|
-
return resolvedItem;
|
208
437
|
}
|
209
|
-
|
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
|
+
};
|
210
469
|
});
|
211
470
|
|
212
|
-
// lib/
|
213
|
-
var cache2 = {};
|
214
|
-
function resolveRootData(data, config) {
|
215
|
-
return __async(this, null, function* () {
|
216
|
-
var _a, _b, _c, _d, _e;
|
217
|
-
if (((_a = config.root) == null ? void 0 : _a.resolveData) && data.root.props) {
|
218
|
-
if (((_b = cache2.lastChange) == null ? void 0 : _b.original) === data.root) {
|
219
|
-
return cache2.lastChange.resolved;
|
220
|
-
}
|
221
|
-
const changed = getChanged(data.root, (_c = cache2.lastChange) == null ? void 0 : _c.original);
|
222
|
-
const rootWithProps = data.root;
|
223
|
-
const resolvedRoot = yield (_e = config.root) == null ? void 0 : _e.resolveData(rootWithProps, {
|
224
|
-
changed,
|
225
|
-
lastData: ((_d = cache2.lastChange) == null ? void 0 : _d.original) || {}
|
226
|
-
});
|
227
|
-
cache2.lastChange = {
|
228
|
-
original: data.root,
|
229
|
-
resolved: resolvedRoot
|
230
|
-
};
|
231
|
-
return __spreadProps(__spreadValues(__spreadValues({}, data.root), resolvedRoot), {
|
232
|
-
props: __spreadValues(__spreadValues({}, data.root.props), resolvedRoot.props)
|
233
|
-
});
|
234
|
-
}
|
235
|
-
return data.root;
|
236
|
-
});
|
237
|
-
}
|
238
|
-
|
239
|
-
// lib/default-data.ts
|
471
|
+
// lib/data/default-data.ts
|
240
472
|
var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
|
241
473
|
root: data.root || {},
|
242
474
|
content: data.content || []
|
243
475
|
});
|
244
476
|
|
477
|
+
// lib/data/to-component.ts
|
478
|
+
var toComponent = (item) => {
|
479
|
+
return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
|
480
|
+
props: __spreadProps(__spreadValues({}, item.props), { id: "root" }),
|
481
|
+
type: "root"
|
482
|
+
});
|
483
|
+
};
|
484
|
+
|
245
485
|
// lib/resolve-all-data.ts
|
246
|
-
function resolveAllData(
|
247
|
-
return __async(this,
|
486
|
+
function resolveAllData(_0, _1) {
|
487
|
+
return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
|
488
|
+
var _a;
|
248
489
|
const defaultedData = defaultData(data);
|
249
|
-
const
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
const zoneKey = zoneKeys[i];
|
255
|
-
resolvedZones[zoneKey] = yield resolveAllComponentData(
|
256
|
-
zones[zoneKey],
|
490
|
+
const resolveNode = (_node) => __async(this, null, function* () {
|
491
|
+
const node = toComponent(_node);
|
492
|
+
onResolveStart == null ? void 0 : onResolveStart(node);
|
493
|
+
const resolved = (yield resolveComponentData(
|
494
|
+
node,
|
257
495
|
config,
|
258
|
-
|
259
|
-
|
496
|
+
metadata,
|
497
|
+
() => {
|
498
|
+
},
|
499
|
+
() => {
|
500
|
+
},
|
501
|
+
"force"
|
502
|
+
)).node;
|
503
|
+
const resolvedDeep = yield mapSlots(
|
504
|
+
resolved,
|
505
|
+
processContent,
|
506
|
+
config
|
260
507
|
);
|
508
|
+
onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
|
509
|
+
return resolvedDeep;
|
510
|
+
});
|
511
|
+
const processContent = (content) => __async(this, null, function* () {
|
512
|
+
return Promise.all(content.map(resolveNode));
|
513
|
+
});
|
514
|
+
const processZones = () => __async(this, null, function* () {
|
515
|
+
var _a2;
|
516
|
+
const zones = (_a2 = data.zones) != null ? _a2 : {};
|
517
|
+
Object.entries(zones).forEach((_02) => __async(this, [_02], function* ([zoneKey, content]) {
|
518
|
+
zones[zoneKey] = yield Promise.all(content.map(resolveNode));
|
519
|
+
}));
|
520
|
+
return zones;
|
521
|
+
});
|
522
|
+
const dynamic = {
|
523
|
+
root: yield resolveNode(defaultedData.root),
|
524
|
+
content: yield processContent(defaultedData.content),
|
525
|
+
zones: yield processZones()
|
526
|
+
};
|
527
|
+
Object.keys((_a = defaultedData.zones) != null ? _a : {}).forEach((zoneKey) => __async(this, null, function* () {
|
528
|
+
const content = defaultedData.zones[zoneKey];
|
529
|
+
dynamic.zones[zoneKey] = yield processContent(content);
|
530
|
+
}), {});
|
531
|
+
return dynamic;
|
532
|
+
});
|
533
|
+
}
|
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
|
+
|
570
|
+
// lib/transform-props.ts
|
571
|
+
function transformProps(data, propTransforms, config = { components: {} }) {
|
572
|
+
const mapItem = (item) => {
|
573
|
+
if (propTransforms[item.type]) {
|
574
|
+
return __spreadProps(__spreadValues({}, item), {
|
575
|
+
props: __spreadValues({
|
576
|
+
id: item.props.id
|
577
|
+
}, propTransforms[item.type](item.props))
|
578
|
+
});
|
261
579
|
}
|
262
|
-
return
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
580
|
+
return item;
|
581
|
+
};
|
582
|
+
const defaultedData = defaultData(data);
|
583
|
+
const rootProps = defaultedData.root.props || defaultedData.root;
|
584
|
+
let newRoot = __spreadValues({}, defaultedData.root);
|
585
|
+
if (propTransforms["root"]) {
|
586
|
+
newRoot.props = propTransforms["root"](rootProps);
|
587
|
+
}
|
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
|
271
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
|
272
780
|
});
|
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
|
+
);
|
273
871
|
}
|
274
872
|
// Annotate the CommonJS export names for ESM import in node:
|
275
873
|
0 && (module.exports = {
|
276
874
|
Render,
|
277
|
-
|
875
|
+
migrate,
|
876
|
+
resolveAllData,
|
877
|
+
transformProps,
|
878
|
+
walkTree
|
278
879
|
});
|