@measured/puck 0.20.0-canary.755737e8 → 0.20.0-canary.7ccbeece
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 +31 -27
- package/dist/chunk-AR5UHF65.mjs +9038 -0
- package/dist/{chunk-IM42S4YL.mjs → chunk-HUKJ36SA.mjs} +402 -301
- package/dist/index.css +390 -413
- package/dist/index.d.mts +17 -8
- package/dist/index.d.ts +17 -8
- package/dist/index.js +3367 -2806
- package/dist/index.mjs +29 -8553
- package/dist/no-external.css +1978 -0
- package/dist/no-external.d.mts +4 -0
- package/dist/no-external.d.ts +4 -0
- package/dist/no-external.js +9972 -0
- package/dist/no-external.mjs +56 -0
- package/dist/rsc.d.mts +2 -2
- package/dist/rsc.d.ts +2 -2
- package/dist/rsc.js +188 -78
- package/dist/rsc.mjs +5 -1
- package/dist/{walk-tree-6PP75PCU.d.mts → walk-tree-B57SgEEc.d.mts} +62 -35
- package/dist/{walk-tree-6PP75PCU.d.ts → walk-tree-B57SgEEc.d.ts} +62 -35
- package/package.json +3 -2
|
@@ -84,36 +84,10 @@ var init_react_import = __esm({
|
|
|
84
84
|
}
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
-
//
|
|
88
|
-
init_react_import();
|
|
89
|
-
|
|
90
|
-
// components/ServerRender/index.tsx
|
|
91
|
-
init_react_import();
|
|
92
|
-
|
|
93
|
-
// lib/root-droppable-id.ts
|
|
94
|
-
init_react_import();
|
|
95
|
-
var rootAreaId = "root";
|
|
96
|
-
var rootZone = "default-zone";
|
|
97
|
-
var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
|
98
|
-
|
|
99
|
-
// lib/data/setup-zone.ts
|
|
100
|
-
init_react_import();
|
|
101
|
-
var setupZone = (data, zoneKey) => {
|
|
102
|
-
if (zoneKey === rootDroppableId) {
|
|
103
|
-
return data;
|
|
104
|
-
}
|
|
105
|
-
const newData = __spreadProps(__spreadValues({}, data), {
|
|
106
|
-
zones: data.zones ? __spreadValues({}, data.zones) : {}
|
|
107
|
-
});
|
|
108
|
-
newData.zones[zoneKey] = newData.zones[zoneKey] || [];
|
|
109
|
-
return newData;
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
// lib/use-slots.tsx
|
|
87
|
+
// lib/data/walk-tree.ts
|
|
113
88
|
init_react_import();
|
|
114
|
-
import { useMemo } from "react";
|
|
115
89
|
|
|
116
|
-
// lib/data/map-
|
|
90
|
+
// lib/data/map-fields.ts
|
|
117
91
|
init_react_import();
|
|
118
92
|
|
|
119
93
|
// lib/data/default-slots.ts
|
|
@@ -123,14 +97,14 @@ var defaultSlots = (value, fields) => Object.keys(fields).reduce(
|
|
|
123
97
|
value
|
|
124
98
|
);
|
|
125
99
|
|
|
126
|
-
// lib/data/map-
|
|
100
|
+
// lib/data/map-fields.ts
|
|
127
101
|
var isPromise = (v) => !!v && typeof v.then === "function";
|
|
128
102
|
var flatten = (values) => values.reduce((acc, item) => __spreadValues(__spreadValues({}, acc), item), {});
|
|
129
103
|
var containsPromise = (arr) => arr.some(isPromise);
|
|
130
104
|
var walkField = ({
|
|
131
105
|
value,
|
|
132
106
|
fields,
|
|
133
|
-
|
|
107
|
+
mappers,
|
|
134
108
|
propKey = "",
|
|
135
109
|
propPath = "",
|
|
136
110
|
id = "",
|
|
@@ -138,7 +112,9 @@ var walkField = ({
|
|
|
138
112
|
recurseSlots = false
|
|
139
113
|
}) => {
|
|
140
114
|
var _a, _b, _c;
|
|
141
|
-
|
|
115
|
+
const fieldType = (_a = fields[propKey]) == null ? void 0 : _a.type;
|
|
116
|
+
const map = mappers[fieldType];
|
|
117
|
+
if (map && fieldType === "slot") {
|
|
142
118
|
const content = value || [];
|
|
143
119
|
const mappedContent = recurseSlots ? content.map((el) => {
|
|
144
120
|
var _a2;
|
|
@@ -150,7 +126,7 @@ var walkField = ({
|
|
|
150
126
|
return walkField({
|
|
151
127
|
value: __spreadProps(__spreadValues({}, el), { props: defaultSlots(el.props, fields2) }),
|
|
152
128
|
fields: fields2,
|
|
153
|
-
|
|
129
|
+
mappers,
|
|
154
130
|
id: el.props.id,
|
|
155
131
|
config,
|
|
156
132
|
recurseSlots
|
|
@@ -159,7 +135,21 @@ var walkField = ({
|
|
|
159
135
|
if (containsPromise(mappedContent)) {
|
|
160
136
|
return Promise.all(mappedContent);
|
|
161
137
|
}
|
|
162
|
-
return map(
|
|
138
|
+
return map({
|
|
139
|
+
value: mappedContent,
|
|
140
|
+
parentId: id,
|
|
141
|
+
propName: propKey,
|
|
142
|
+
field: fields[propKey],
|
|
143
|
+
propPath
|
|
144
|
+
});
|
|
145
|
+
} else if (map && fields[propKey]) {
|
|
146
|
+
return map({
|
|
147
|
+
value,
|
|
148
|
+
parentId: id,
|
|
149
|
+
propName: propKey,
|
|
150
|
+
field: fields[propKey],
|
|
151
|
+
propPath
|
|
152
|
+
});
|
|
163
153
|
}
|
|
164
154
|
if (value && typeof value === "object") {
|
|
165
155
|
if (Array.isArray(value)) {
|
|
@@ -169,7 +159,7 @@ var walkField = ({
|
|
|
169
159
|
(el, idx) => walkField({
|
|
170
160
|
value: el,
|
|
171
161
|
fields: arrayFields,
|
|
172
|
-
|
|
162
|
+
mappers,
|
|
173
163
|
propKey,
|
|
174
164
|
propPath: `${propPath}[${idx}]`,
|
|
175
165
|
id,
|
|
@@ -188,7 +178,7 @@ var walkField = ({
|
|
|
188
178
|
return walkObject({
|
|
189
179
|
value,
|
|
190
180
|
fields: objectFields,
|
|
191
|
-
|
|
181
|
+
mappers,
|
|
192
182
|
id,
|
|
193
183
|
getPropPath: (k) => `${propPath}.${k}`,
|
|
194
184
|
config,
|
|
@@ -201,7 +191,7 @@ var walkField = ({
|
|
|
201
191
|
var walkObject = ({
|
|
202
192
|
value,
|
|
203
193
|
fields,
|
|
204
|
-
|
|
194
|
+
mappers,
|
|
205
195
|
id,
|
|
206
196
|
getPropPath,
|
|
207
197
|
config,
|
|
@@ -211,7 +201,7 @@ var walkObject = ({
|
|
|
211
201
|
const opts = {
|
|
212
202
|
value: v,
|
|
213
203
|
fields,
|
|
214
|
-
|
|
204
|
+
mappers,
|
|
215
205
|
propKey: k,
|
|
216
206
|
propPath: getPropPath(k),
|
|
217
207
|
id,
|
|
@@ -233,14 +223,14 @@ var walkObject = ({
|
|
|
233
223
|
}
|
|
234
224
|
return flatten(newProps);
|
|
235
225
|
};
|
|
236
|
-
function
|
|
226
|
+
function mapFields(item, mappers, config, recurseSlots = false) {
|
|
237
227
|
var _a, _b, _c, _d, _e;
|
|
238
228
|
const itemType = "type" in item ? item.type : "root";
|
|
239
229
|
const componentConfig = itemType === "root" ? config.root : (_a = config.components) == null ? void 0 : _a[itemType];
|
|
240
230
|
const newProps = walkObject({
|
|
241
231
|
value: defaultSlots((_b = item.props) != null ? _b : {}, (_c = componentConfig == null ? void 0 : componentConfig.fields) != null ? _c : {}),
|
|
242
232
|
fields: (_d = componentConfig == null ? void 0 : componentConfig.fields) != null ? _d : {},
|
|
243
|
-
|
|
233
|
+
mappers,
|
|
244
234
|
id: item.props ? (_e = item.props.id) != null ? _e : "root" : "root",
|
|
245
235
|
getPropPath: (k) => k,
|
|
246
236
|
config,
|
|
@@ -256,35 +246,132 @@ function mapSlots(item, map, config, recurseSlots = false) {
|
|
|
256
246
|
});
|
|
257
247
|
}
|
|
258
248
|
|
|
259
|
-
// lib/
|
|
260
|
-
function
|
|
261
|
-
|
|
262
|
-
|
|
249
|
+
// lib/data/walk-tree.ts
|
|
250
|
+
function walkTree(data, config, callbackFn) {
|
|
251
|
+
var _a, _b;
|
|
252
|
+
const walkItem = (item) => {
|
|
253
|
+
return mapFields(
|
|
263
254
|
item,
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
disallow: (field == null ? void 0 : field.type) === "slot" ? field.disallow : []
|
|
271
|
-
}, dzProps), {
|
|
272
|
-
zone: propName,
|
|
273
|
-
content
|
|
274
|
-
}));
|
|
275
|
-
return Slot;
|
|
255
|
+
{
|
|
256
|
+
slot: ({ value, parentId, propName }) => {
|
|
257
|
+
var _a2;
|
|
258
|
+
const content = value;
|
|
259
|
+
return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
|
|
260
|
+
}
|
|
276
261
|
},
|
|
277
|
-
config
|
|
278
|
-
|
|
262
|
+
config,
|
|
263
|
+
true
|
|
264
|
+
);
|
|
265
|
+
};
|
|
266
|
+
if ("props" in data) {
|
|
267
|
+
return walkItem(data);
|
|
268
|
+
}
|
|
269
|
+
const _data = data;
|
|
270
|
+
const zones = (_a = _data.zones) != null ? _a : {};
|
|
271
|
+
const mappedContent = _data.content.map(walkItem);
|
|
272
|
+
return {
|
|
273
|
+
root: walkItem(_data.root),
|
|
274
|
+
content: (_b = callbackFn(mappedContent, {
|
|
275
|
+
parentId: "root",
|
|
276
|
+
propName: "default-zone"
|
|
277
|
+
})) != null ? _b : mappedContent,
|
|
278
|
+
zones: Object.keys(zones).reduce(
|
|
279
|
+
(acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
|
|
280
|
+
[zoneCompound]: zones[zoneCompound].map(walkItem)
|
|
281
|
+
}),
|
|
282
|
+
{}
|
|
283
|
+
)
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// components/ServerRender/index.tsx
|
|
288
|
+
init_react_import();
|
|
289
|
+
|
|
290
|
+
// lib/root-droppable-id.ts
|
|
291
|
+
init_react_import();
|
|
292
|
+
var rootAreaId = "root";
|
|
293
|
+
var rootZone = "default-zone";
|
|
294
|
+
var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
|
295
|
+
|
|
296
|
+
// lib/data/setup-zone.ts
|
|
297
|
+
init_react_import();
|
|
298
|
+
var setupZone = (data, zoneKey) => {
|
|
299
|
+
if (zoneKey === rootDroppableId) {
|
|
300
|
+
return data;
|
|
301
|
+
}
|
|
302
|
+
const newData = __spreadProps(__spreadValues({}, data), {
|
|
303
|
+
zones: data.zones ? __spreadValues({}, data.zones) : {}
|
|
304
|
+
});
|
|
305
|
+
newData.zones[zoneKey] = newData.zones[zoneKey] || [];
|
|
306
|
+
return newData;
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
// lib/use-slots.tsx
|
|
310
|
+
init_react_import();
|
|
311
|
+
|
|
312
|
+
// lib/field-transforms/use-field-transforms.tsx
|
|
313
|
+
init_react_import();
|
|
314
|
+
import { useMemo } from "react";
|
|
315
|
+
function useFieldTransforms(config, item, transforms, readOnly, forceReadOnly) {
|
|
316
|
+
const mappers = useMemo(() => {
|
|
317
|
+
return Object.keys(transforms).reduce((acc, _fieldType) => {
|
|
318
|
+
const fieldType = _fieldType;
|
|
319
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
320
|
+
[fieldType]: (_a) => {
|
|
321
|
+
var _b = _a, {
|
|
322
|
+
parentId
|
|
323
|
+
} = _b, params = __objRest(_b, [
|
|
324
|
+
"parentId"
|
|
325
|
+
]);
|
|
326
|
+
const wildcardPath = params.propPath.replace(/\[\d+\]/g, "[*]");
|
|
327
|
+
const isReadOnly = (readOnly == null ? void 0 : readOnly[params.propPath]) || (readOnly == null ? void 0 : readOnly[wildcardPath]) || forceReadOnly || false;
|
|
328
|
+
const fn = transforms[fieldType];
|
|
329
|
+
return fn == null ? void 0 : fn(__spreadProps(__spreadValues({}, params), {
|
|
330
|
+
isReadOnly,
|
|
331
|
+
componentId: parentId
|
|
332
|
+
}));
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}, {});
|
|
336
|
+
}, [transforms, readOnly, forceReadOnly]);
|
|
337
|
+
const transformedProps = useMemo(() => {
|
|
338
|
+
const mapped = mapFields(item, mappers, config).props;
|
|
279
339
|
return mapped;
|
|
280
|
-
}, [config, item,
|
|
340
|
+
}, [config, item, mappers]);
|
|
281
341
|
const mergedProps = useMemo(
|
|
282
|
-
() => __spreadValues(__spreadValues({}, item.props),
|
|
283
|
-
[item.props,
|
|
342
|
+
() => __spreadValues(__spreadValues({}, item.props), transformedProps),
|
|
343
|
+
[item.props, transformedProps]
|
|
284
344
|
);
|
|
285
345
|
return mergedProps;
|
|
286
346
|
}
|
|
287
347
|
|
|
348
|
+
// lib/field-transforms/default-transforms/slot-transform.tsx
|
|
349
|
+
init_react_import();
|
|
350
|
+
var getSlotTransform = (renderSlotEdit, renderSlotRender = renderSlotEdit) => ({
|
|
351
|
+
slot: ({ value: content, propName, field, isReadOnly }) => {
|
|
352
|
+
const render = isReadOnly ? renderSlotRender : renderSlotEdit;
|
|
353
|
+
const Slot = (dzProps) => render(__spreadProps(__spreadValues({
|
|
354
|
+
allow: (field == null ? void 0 : field.type) === "slot" ? field.allow : [],
|
|
355
|
+
disallow: (field == null ? void 0 : field.type) === "slot" ? field.disallow : []
|
|
356
|
+
}, dzProps), {
|
|
357
|
+
zone: propName,
|
|
358
|
+
content
|
|
359
|
+
}));
|
|
360
|
+
return Slot;
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
// lib/use-slots.tsx
|
|
365
|
+
function useSlots(config, item, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
|
|
366
|
+
return useFieldTransforms(
|
|
367
|
+
config,
|
|
368
|
+
item,
|
|
369
|
+
getSlotTransform(renderSlotEdit, renderSlotRender),
|
|
370
|
+
readOnly,
|
|
371
|
+
forceReadOnly
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
|
|
288
375
|
// components/SlotRender/server.tsx
|
|
289
376
|
init_react_import();
|
|
290
377
|
import { forwardRef } from "react";
|
|
@@ -421,221 +508,6 @@ function Render({
|
|
|
421
508
|
);
|
|
422
509
|
}
|
|
423
510
|
|
|
424
|
-
// lib/resolve-all-data.ts
|
|
425
|
-
init_react_import();
|
|
426
|
-
|
|
427
|
-
// lib/resolve-component-data.ts
|
|
428
|
-
init_react_import();
|
|
429
|
-
|
|
430
|
-
// lib/get-changed.ts
|
|
431
|
-
init_react_import();
|
|
432
|
-
import fdeq from "fast-deep-equal";
|
|
433
|
-
var getChanged = (newItem, oldItem) => {
|
|
434
|
-
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
|
435
|
-
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
|
436
|
-
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
|
437
|
-
return __spreadProps(__spreadValues({}, acc), {
|
|
438
|
-
[item]: !fdeq(oldItemProps[item], newItemProps[item])
|
|
439
|
-
});
|
|
440
|
-
}, {}) : {};
|
|
441
|
-
};
|
|
442
|
-
|
|
443
|
-
// lib/resolve-component-data.ts
|
|
444
|
-
import fdeq2 from "fast-deep-equal";
|
|
445
|
-
var cache = { lastChange: {} };
|
|
446
|
-
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
|
|
447
|
-
const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
|
|
448
|
-
const resolvedItem = __spreadValues({}, item);
|
|
449
|
-
const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
|
|
450
|
-
const id = "id" in item.props ? item.props.id : "root";
|
|
451
|
-
if (shouldRunResolver) {
|
|
452
|
-
const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
|
|
453
|
-
if (item && fdeq2(item, oldItem)) {
|
|
454
|
-
return { node: resolved, didChange: false };
|
|
455
|
-
}
|
|
456
|
-
const changed = getChanged(item, oldItem);
|
|
457
|
-
if (onResolveStart) {
|
|
458
|
-
onResolveStart(item);
|
|
459
|
-
}
|
|
460
|
-
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
|
461
|
-
changed,
|
|
462
|
-
lastData: oldItem,
|
|
463
|
-
metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
|
|
464
|
-
trigger
|
|
465
|
-
});
|
|
466
|
-
resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
|
|
467
|
-
if (Object.keys(readOnly).length) {
|
|
468
|
-
resolvedItem.readOnly = readOnly;
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
let itemWithResolvedChildren = yield mapSlots(
|
|
472
|
-
resolvedItem,
|
|
473
|
-
(content) => __async(void 0, null, function* () {
|
|
474
|
-
return yield Promise.all(
|
|
475
|
-
content.map(
|
|
476
|
-
(childItem) => __async(void 0, null, function* () {
|
|
477
|
-
return (yield resolveComponentData(
|
|
478
|
-
childItem,
|
|
479
|
-
config,
|
|
480
|
-
metadata,
|
|
481
|
-
onResolveStart,
|
|
482
|
-
onResolveEnd,
|
|
483
|
-
trigger
|
|
484
|
-
)).node;
|
|
485
|
-
})
|
|
486
|
-
)
|
|
487
|
-
);
|
|
488
|
-
}),
|
|
489
|
-
config
|
|
490
|
-
);
|
|
491
|
-
if (shouldRunResolver && onResolveEnd) {
|
|
492
|
-
onResolveEnd(resolvedItem);
|
|
493
|
-
}
|
|
494
|
-
cache.lastChange[id] = {
|
|
495
|
-
item,
|
|
496
|
-
resolved: itemWithResolvedChildren
|
|
497
|
-
};
|
|
498
|
-
return {
|
|
499
|
-
node: itemWithResolvedChildren,
|
|
500
|
-
didChange: !fdeq2(item, itemWithResolvedChildren)
|
|
501
|
-
};
|
|
502
|
-
});
|
|
503
|
-
|
|
504
|
-
// lib/data/default-data.ts
|
|
505
|
-
init_react_import();
|
|
506
|
-
var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
|
|
507
|
-
root: data.root || {},
|
|
508
|
-
content: data.content || []
|
|
509
|
-
});
|
|
510
|
-
|
|
511
|
-
// lib/data/to-component.ts
|
|
512
|
-
init_react_import();
|
|
513
|
-
var toComponent = (item) => {
|
|
514
|
-
return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
|
|
515
|
-
props: __spreadProps(__spreadValues({}, item.props), { id: "root" }),
|
|
516
|
-
type: "root"
|
|
517
|
-
});
|
|
518
|
-
};
|
|
519
|
-
|
|
520
|
-
// lib/resolve-all-data.ts
|
|
521
|
-
function resolveAllData(_0, _1) {
|
|
522
|
-
return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
|
|
523
|
-
var _a;
|
|
524
|
-
const defaultedData = defaultData(data);
|
|
525
|
-
const resolveNode = (_node) => __async(this, null, function* () {
|
|
526
|
-
const node = toComponent(_node);
|
|
527
|
-
onResolveStart == null ? void 0 : onResolveStart(node);
|
|
528
|
-
const resolved = (yield resolveComponentData(
|
|
529
|
-
node,
|
|
530
|
-
config,
|
|
531
|
-
metadata,
|
|
532
|
-
() => {
|
|
533
|
-
},
|
|
534
|
-
() => {
|
|
535
|
-
},
|
|
536
|
-
"force"
|
|
537
|
-
)).node;
|
|
538
|
-
const resolvedDeep = yield mapSlots(
|
|
539
|
-
resolved,
|
|
540
|
-
processContent,
|
|
541
|
-
config
|
|
542
|
-
);
|
|
543
|
-
onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
|
|
544
|
-
return resolvedDeep;
|
|
545
|
-
});
|
|
546
|
-
const processContent = (content) => __async(this, null, function* () {
|
|
547
|
-
return Promise.all(content.map(resolveNode));
|
|
548
|
-
});
|
|
549
|
-
const processZones = () => __async(this, null, function* () {
|
|
550
|
-
var _a2;
|
|
551
|
-
const zones = (_a2 = data.zones) != null ? _a2 : {};
|
|
552
|
-
Object.entries(zones).forEach((_02) => __async(this, [_02], function* ([zoneKey, content]) {
|
|
553
|
-
zones[zoneKey] = yield Promise.all(content.map(resolveNode));
|
|
554
|
-
}));
|
|
555
|
-
return zones;
|
|
556
|
-
});
|
|
557
|
-
const dynamic = {
|
|
558
|
-
root: yield resolveNode(defaultedData.root),
|
|
559
|
-
content: yield processContent(defaultedData.content),
|
|
560
|
-
zones: yield processZones()
|
|
561
|
-
};
|
|
562
|
-
Object.keys((_a = defaultedData.zones) != null ? _a : {}).forEach((zoneKey) => __async(this, null, function* () {
|
|
563
|
-
const content = defaultedData.zones[zoneKey];
|
|
564
|
-
dynamic.zones[zoneKey] = yield processContent(content);
|
|
565
|
-
}), {});
|
|
566
|
-
return dynamic;
|
|
567
|
-
});
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
// lib/transform-props.ts
|
|
571
|
-
init_react_import();
|
|
572
|
-
|
|
573
|
-
// lib/data/walk-tree.ts
|
|
574
|
-
init_react_import();
|
|
575
|
-
function walkTree(data, config, callbackFn) {
|
|
576
|
-
var _a, _b;
|
|
577
|
-
const walkItem = (item) => {
|
|
578
|
-
return mapSlots(
|
|
579
|
-
item,
|
|
580
|
-
(content, parentId, propName) => {
|
|
581
|
-
var _a2;
|
|
582
|
-
return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
|
|
583
|
-
},
|
|
584
|
-
config,
|
|
585
|
-
true
|
|
586
|
-
);
|
|
587
|
-
};
|
|
588
|
-
if ("props" in data) {
|
|
589
|
-
return walkItem(data);
|
|
590
|
-
}
|
|
591
|
-
const _data = data;
|
|
592
|
-
const zones = (_a = _data.zones) != null ? _a : {};
|
|
593
|
-
const mappedContent = _data.content.map(walkItem);
|
|
594
|
-
return {
|
|
595
|
-
root: walkItem(_data.root),
|
|
596
|
-
content: (_b = callbackFn(mappedContent, {
|
|
597
|
-
parentId: "root",
|
|
598
|
-
propName: "default-zone"
|
|
599
|
-
})) != null ? _b : mappedContent,
|
|
600
|
-
zones: Object.keys(zones).reduce(
|
|
601
|
-
(acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
|
|
602
|
-
[zoneCompound]: zones[zoneCompound].map(walkItem)
|
|
603
|
-
}),
|
|
604
|
-
{}
|
|
605
|
-
)
|
|
606
|
-
};
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
// lib/transform-props.ts
|
|
610
|
-
function transformProps(data, propTransforms, config = { components: {} }) {
|
|
611
|
-
const mapItem = (item) => {
|
|
612
|
-
if (propTransforms[item.type]) {
|
|
613
|
-
return __spreadProps(__spreadValues({}, item), {
|
|
614
|
-
props: __spreadValues({
|
|
615
|
-
id: item.props.id
|
|
616
|
-
}, propTransforms[item.type](item.props))
|
|
617
|
-
});
|
|
618
|
-
}
|
|
619
|
-
return item;
|
|
620
|
-
};
|
|
621
|
-
const defaultedData = defaultData(data);
|
|
622
|
-
const rootProps = defaultedData.root.props || defaultedData.root;
|
|
623
|
-
let newRoot = __spreadValues({}, defaultedData.root);
|
|
624
|
-
if (propTransforms["root"]) {
|
|
625
|
-
newRoot.props = propTransforms["root"](rootProps);
|
|
626
|
-
}
|
|
627
|
-
const dataWithUpdatedRoot = __spreadProps(__spreadValues({}, defaultedData), { root: newRoot });
|
|
628
|
-
const updatedData = walkTree(
|
|
629
|
-
dataWithUpdatedRoot,
|
|
630
|
-
config,
|
|
631
|
-
(content) => content.map(mapItem)
|
|
632
|
-
);
|
|
633
|
-
if (!defaultedData.root.props) {
|
|
634
|
-
updatedData.root = updatedData.root.props;
|
|
635
|
-
}
|
|
636
|
-
return updatedData;
|
|
637
|
-
}
|
|
638
|
-
|
|
639
511
|
// lib/migrate.ts
|
|
640
512
|
init_react_import();
|
|
641
513
|
|
|
@@ -712,7 +584,7 @@ import flat from "flat";
|
|
|
712
584
|
// lib/data/strip-slots.ts
|
|
713
585
|
init_react_import();
|
|
714
586
|
var stripSlots = (data, config) => {
|
|
715
|
-
return
|
|
587
|
+
return mapFields(data, { slot: () => null }, config);
|
|
716
588
|
};
|
|
717
589
|
|
|
718
590
|
// lib/data/flatten-node.ts
|
|
@@ -771,18 +643,21 @@ function walkAppState(state, config, mapContent = (content) => content, mapNodeO
|
|
|
771
643
|
const mappedItem = mapNodeOrSkip(item, path, index);
|
|
772
644
|
if (!mappedItem) return item;
|
|
773
645
|
const id = mappedItem.props.id;
|
|
774
|
-
const newProps = __spreadProps(__spreadValues({},
|
|
646
|
+
const newProps = __spreadProps(__spreadValues({}, mapFields(
|
|
775
647
|
mappedItem,
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
648
|
+
{
|
|
649
|
+
slot: ({ value, parentId: parentId2, propPath }) => {
|
|
650
|
+
const content = value;
|
|
651
|
+
const zoneCompound = `${parentId2}:${propPath}`;
|
|
652
|
+
const [_2, newContent2] = processContent(
|
|
653
|
+
path,
|
|
654
|
+
zoneCompound,
|
|
655
|
+
content,
|
|
656
|
+
"slot",
|
|
657
|
+
parentId2
|
|
658
|
+
);
|
|
659
|
+
return newContent2;
|
|
660
|
+
}
|
|
786
661
|
},
|
|
787
662
|
config
|
|
788
663
|
).props), {
|
|
@@ -871,8 +746,8 @@ var migrations = [
|
|
|
871
746
|
return data;
|
|
872
747
|
},
|
|
873
748
|
// Migrate zones to slots
|
|
874
|
-
(data, config) => {
|
|
875
|
-
var _a;
|
|
749
|
+
(data, config, migrationOptions) => {
|
|
750
|
+
var _a, _b;
|
|
876
751
|
if (!config) return data;
|
|
877
752
|
console.log("Migrating DropZones to slots...");
|
|
878
753
|
const updatedItems = {};
|
|
@@ -880,13 +755,13 @@ var migrations = [
|
|
|
880
755
|
const { indexes } = walkAppState(appState, config);
|
|
881
756
|
const deletedCompounds = [];
|
|
882
757
|
walkAppState(appState, config, (content, zoneCompound, zoneType) => {
|
|
883
|
-
var _a2,
|
|
758
|
+
var _a2, _b2, _c;
|
|
884
759
|
if (zoneType === "dropzone") {
|
|
885
760
|
const [id, slotName] = zoneCompound.split(":");
|
|
886
761
|
const nodeData = indexes.nodes[id].data;
|
|
887
762
|
const componentType = nodeData.type;
|
|
888
763
|
const configForComponent = id === "root" ? config.root : config.components[componentType];
|
|
889
|
-
if (((
|
|
764
|
+
if (((_b2 = (_a2 = configForComponent == null ? void 0 : configForComponent.fields) == null ? void 0 : _a2[slotName]) == null ? void 0 : _b2.type) === "slot") {
|
|
890
765
|
updatedItems[id] = __spreadProps(__spreadValues({}, nodeData), {
|
|
891
766
|
props: __spreadProps(__spreadValues(__spreadValues({}, nodeData.props), (_c = updatedItems[id]) == null ? void 0 : _c.props), {
|
|
892
767
|
[slotName]: content
|
|
@@ -915,7 +790,49 @@ var migrations = [
|
|
|
915
790
|
);
|
|
916
791
|
(_a2 = updated.data.zones) == null ? true : delete _a2[zoneCompound];
|
|
917
792
|
});
|
|
918
|
-
|
|
793
|
+
if (migrationOptions == null ? void 0 : migrationOptions.migrateDynamicZonesForComponent) {
|
|
794
|
+
const unmigratedZonesGrouped = {};
|
|
795
|
+
Object.keys((_a = updated.data.zones) != null ? _a : {}).forEach((zoneCompound) => {
|
|
796
|
+
var _a2;
|
|
797
|
+
const [componentId, propName] = zoneCompound.split(":");
|
|
798
|
+
const content = (_a2 = updated.data.zones) == null ? void 0 : _a2[zoneCompound];
|
|
799
|
+
if (!content) {
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
if (!unmigratedZonesGrouped[componentId]) {
|
|
803
|
+
unmigratedZonesGrouped[componentId] = {};
|
|
804
|
+
}
|
|
805
|
+
if (!unmigratedZonesGrouped[componentId][propName]) {
|
|
806
|
+
unmigratedZonesGrouped[componentId][propName] = content;
|
|
807
|
+
}
|
|
808
|
+
});
|
|
809
|
+
Object.keys(unmigratedZonesGrouped).forEach((componentId) => {
|
|
810
|
+
updated.data = walkTree(updated.data, config, (content) => {
|
|
811
|
+
return content.map((child) => {
|
|
812
|
+
var _a2;
|
|
813
|
+
if (child.props.id !== componentId) {
|
|
814
|
+
return child;
|
|
815
|
+
}
|
|
816
|
+
const migrateFn = (_a2 = migrationOptions == null ? void 0 : migrationOptions.migrateDynamicZonesForComponent) == null ? void 0 : _a2[child.type];
|
|
817
|
+
if (!migrateFn) {
|
|
818
|
+
return child;
|
|
819
|
+
}
|
|
820
|
+
const zones = unmigratedZonesGrouped[componentId];
|
|
821
|
+
const migratedProps = migrateFn(child.props, zones);
|
|
822
|
+
Object.keys(zones).forEach((propName) => {
|
|
823
|
+
var _a3;
|
|
824
|
+
const zoneCompound = `${componentId}:${propName}`;
|
|
825
|
+
console.log(`\u2713 Success: Migrated "${zoneCompound}" DropZone`);
|
|
826
|
+
(_a3 = updated.data.zones) == null ? true : delete _a3[zoneCompound];
|
|
827
|
+
});
|
|
828
|
+
return __spreadProps(__spreadValues({}, child), {
|
|
829
|
+
props: migratedProps
|
|
830
|
+
});
|
|
831
|
+
});
|
|
832
|
+
});
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
Object.keys((_b = updated.data.zones) != null ? _b : {}).forEach((zoneCompound) => {
|
|
919
836
|
const [_, propName] = zoneCompound.split(":");
|
|
920
837
|
throw new Error(
|
|
921
838
|
`Could not migrate DropZone "${zoneCompound}" to slot field. No slot exists with the name "${propName}".`
|
|
@@ -925,13 +842,195 @@ var migrations = [
|
|
|
925
842
|
return updated.data;
|
|
926
843
|
}
|
|
927
844
|
];
|
|
928
|
-
function migrate(data, config) {
|
|
845
|
+
function migrate(data, config, migrationOptions) {
|
|
929
846
|
return migrations == null ? void 0 : migrations.reduce(
|
|
930
|
-
(acc, migration) => migration(acc, config),
|
|
847
|
+
(acc, migration) => migration(acc, config, migrationOptions),
|
|
931
848
|
data
|
|
932
849
|
);
|
|
933
850
|
}
|
|
934
851
|
|
|
852
|
+
// lib/transform-props.ts
|
|
853
|
+
init_react_import();
|
|
854
|
+
|
|
855
|
+
// lib/data/default-data.ts
|
|
856
|
+
init_react_import();
|
|
857
|
+
var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
|
|
858
|
+
root: data.root || {},
|
|
859
|
+
content: data.content || []
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
// lib/transform-props.ts
|
|
863
|
+
function transformProps(data, propTransforms, config = { components: {} }) {
|
|
864
|
+
const mapItem = (item) => {
|
|
865
|
+
if (propTransforms[item.type]) {
|
|
866
|
+
return __spreadProps(__spreadValues({}, item), {
|
|
867
|
+
props: __spreadValues({
|
|
868
|
+
id: item.props.id
|
|
869
|
+
}, propTransforms[item.type](item.props))
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
return item;
|
|
873
|
+
};
|
|
874
|
+
const defaultedData = defaultData(data);
|
|
875
|
+
const rootProps = defaultedData.root.props || defaultedData.root;
|
|
876
|
+
let newRoot = __spreadValues({}, defaultedData.root);
|
|
877
|
+
if (propTransforms["root"]) {
|
|
878
|
+
newRoot.props = propTransforms["root"](rootProps);
|
|
879
|
+
}
|
|
880
|
+
const dataWithUpdatedRoot = __spreadProps(__spreadValues({}, defaultedData), { root: newRoot });
|
|
881
|
+
const updatedData = walkTree(
|
|
882
|
+
dataWithUpdatedRoot,
|
|
883
|
+
config,
|
|
884
|
+
(content) => content.map(mapItem)
|
|
885
|
+
);
|
|
886
|
+
if (!defaultedData.root.props) {
|
|
887
|
+
updatedData.root = updatedData.root.props;
|
|
888
|
+
}
|
|
889
|
+
return updatedData;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
// lib/resolve-all-data.ts
|
|
893
|
+
init_react_import();
|
|
894
|
+
|
|
895
|
+
// lib/resolve-component-data.ts
|
|
896
|
+
init_react_import();
|
|
897
|
+
|
|
898
|
+
// lib/get-changed.ts
|
|
899
|
+
init_react_import();
|
|
900
|
+
import fdeq from "fast-deep-equal";
|
|
901
|
+
var getChanged = (newItem, oldItem) => {
|
|
902
|
+
return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
|
|
903
|
+
const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
|
|
904
|
+
const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
|
|
905
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
906
|
+
[item]: !fdeq(oldItemProps[item], newItemProps[item])
|
|
907
|
+
});
|
|
908
|
+
}, {}) : {};
|
|
909
|
+
};
|
|
910
|
+
|
|
911
|
+
// lib/resolve-component-data.ts
|
|
912
|
+
import fdeq2 from "fast-deep-equal";
|
|
913
|
+
var cache = { lastChange: {} };
|
|
914
|
+
var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
|
|
915
|
+
const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
|
|
916
|
+
const resolvedItem = __spreadValues({}, item);
|
|
917
|
+
const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
|
|
918
|
+
const id = "id" in item.props ? item.props.id : "root";
|
|
919
|
+
if (shouldRunResolver) {
|
|
920
|
+
const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
|
|
921
|
+
if (item && fdeq2(item, oldItem)) {
|
|
922
|
+
return { node: resolved, didChange: false };
|
|
923
|
+
}
|
|
924
|
+
const changed = getChanged(item, oldItem);
|
|
925
|
+
if (onResolveStart) {
|
|
926
|
+
onResolveStart(item);
|
|
927
|
+
}
|
|
928
|
+
const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
|
|
929
|
+
changed,
|
|
930
|
+
lastData: oldItem,
|
|
931
|
+
metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
|
|
932
|
+
trigger
|
|
933
|
+
});
|
|
934
|
+
resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
|
|
935
|
+
if (Object.keys(readOnly).length) {
|
|
936
|
+
resolvedItem.readOnly = readOnly;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
let itemWithResolvedChildren = yield mapFields(
|
|
940
|
+
resolvedItem,
|
|
941
|
+
{
|
|
942
|
+
slot: (_02) => __async(void 0, [_02], function* ({ value }) {
|
|
943
|
+
const content = value;
|
|
944
|
+
return yield Promise.all(
|
|
945
|
+
content.map(
|
|
946
|
+
(childItem) => __async(void 0, null, function* () {
|
|
947
|
+
return (yield resolveComponentData(
|
|
948
|
+
childItem,
|
|
949
|
+
config,
|
|
950
|
+
metadata,
|
|
951
|
+
onResolveStart,
|
|
952
|
+
onResolveEnd,
|
|
953
|
+
trigger
|
|
954
|
+
)).node;
|
|
955
|
+
})
|
|
956
|
+
)
|
|
957
|
+
);
|
|
958
|
+
})
|
|
959
|
+
},
|
|
960
|
+
config
|
|
961
|
+
);
|
|
962
|
+
if (shouldRunResolver && onResolveEnd) {
|
|
963
|
+
onResolveEnd(resolvedItem);
|
|
964
|
+
}
|
|
965
|
+
cache.lastChange[id] = {
|
|
966
|
+
item,
|
|
967
|
+
resolved: itemWithResolvedChildren
|
|
968
|
+
};
|
|
969
|
+
return {
|
|
970
|
+
node: itemWithResolvedChildren,
|
|
971
|
+
didChange: !fdeq2(item, itemWithResolvedChildren)
|
|
972
|
+
};
|
|
973
|
+
});
|
|
974
|
+
|
|
975
|
+
// lib/data/to-component.ts
|
|
976
|
+
init_react_import();
|
|
977
|
+
var toComponent = (item) => {
|
|
978
|
+
return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
|
|
979
|
+
props: __spreadProps(__spreadValues({}, item.props), { id: "root" }),
|
|
980
|
+
type: "root"
|
|
981
|
+
});
|
|
982
|
+
};
|
|
983
|
+
|
|
984
|
+
// lib/resolve-all-data.ts
|
|
985
|
+
function resolveAllData(_0, _1) {
|
|
986
|
+
return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
|
|
987
|
+
var _a;
|
|
988
|
+
const defaultedData = defaultData(data);
|
|
989
|
+
const resolveNode = (_node) => __async(this, null, function* () {
|
|
990
|
+
const node = toComponent(_node);
|
|
991
|
+
onResolveStart == null ? void 0 : onResolveStart(node);
|
|
992
|
+
const resolved = (yield resolveComponentData(
|
|
993
|
+
node,
|
|
994
|
+
config,
|
|
995
|
+
metadata,
|
|
996
|
+
() => {
|
|
997
|
+
},
|
|
998
|
+
() => {
|
|
999
|
+
},
|
|
1000
|
+
"force"
|
|
1001
|
+
)).node;
|
|
1002
|
+
const resolvedDeep = yield mapFields(
|
|
1003
|
+
resolved,
|
|
1004
|
+
{ slot: ({ value }) => processContent(value) },
|
|
1005
|
+
config
|
|
1006
|
+
);
|
|
1007
|
+
onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
|
|
1008
|
+
return resolvedDeep;
|
|
1009
|
+
});
|
|
1010
|
+
const processContent = (content) => __async(this, null, function* () {
|
|
1011
|
+
return Promise.all(content.map(resolveNode));
|
|
1012
|
+
});
|
|
1013
|
+
const processZones = () => __async(this, null, function* () {
|
|
1014
|
+
var _a2;
|
|
1015
|
+
const zones = (_a2 = data.zones) != null ? _a2 : {};
|
|
1016
|
+
Object.entries(zones).forEach((_02) => __async(this, [_02], function* ([zoneKey, content]) {
|
|
1017
|
+
zones[zoneKey] = yield Promise.all(content.map(resolveNode));
|
|
1018
|
+
}));
|
|
1019
|
+
return zones;
|
|
1020
|
+
});
|
|
1021
|
+
const dynamic = {
|
|
1022
|
+
root: yield resolveNode(defaultedData.root),
|
|
1023
|
+
content: yield processContent(defaultedData.content),
|
|
1024
|
+
zones: yield processZones()
|
|
1025
|
+
};
|
|
1026
|
+
Object.keys((_a = defaultedData.zones) != null ? _a : {}).forEach((zoneKey) => __async(this, null, function* () {
|
|
1027
|
+
const content = defaultedData.zones[zoneKey];
|
|
1028
|
+
dynamic.zones[zoneKey] = yield processContent(content);
|
|
1029
|
+
}), {});
|
|
1030
|
+
return dynamic;
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
|
|
935
1034
|
export {
|
|
936
1035
|
__spreadValues,
|
|
937
1036
|
__spreadProps,
|
|
@@ -949,15 +1048,17 @@ export {
|
|
|
949
1048
|
walkAppState,
|
|
950
1049
|
walkTree,
|
|
951
1050
|
setupZone,
|
|
1051
|
+
defaultViewports,
|
|
1052
|
+
getChanged,
|
|
1053
|
+
resolveComponentData,
|
|
1054
|
+
defaultAppState,
|
|
1055
|
+
useFieldTransforms,
|
|
1056
|
+
getSlotTransform,
|
|
952
1057
|
useSlots,
|
|
1058
|
+
Render,
|
|
953
1059
|
SlotRenderPure,
|
|
954
1060
|
SlotRender,
|
|
955
|
-
|
|
956
|
-
getChanged,
|
|
957
|
-
resolveComponentData,
|
|
958
|
-
resolveAllData,
|
|
1061
|
+
migrate,
|
|
959
1062
|
transformProps,
|
|
960
|
-
|
|
961
|
-
defaultAppState,
|
|
962
|
-
migrate
|
|
1063
|
+
resolveAllData
|
|
963
1064
|
};
|