@measured/puck 0.20.0-canary.274fe3d9 → 0.20.0-canary.29cd4d52
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 +9 -9
- package/dist/{chunk-4KAREQPB.mjs → chunk-DCZ7BU3G.mjs} +2908 -2275
- package/dist/{chunk-32MJ3X3H.mjs → chunk-NFK5JVZW.mjs} +199 -237
- package/dist/index.css +160 -77
- package/dist/index.d.mts +19 -7
- package/dist/index.d.ts +19 -7
- package/dist/index.js +1695 -1057
- package/dist/index.mjs +6 -2
- package/dist/no-external.css +160 -77
- package/dist/no-external.d.mts +2 -2
- package/dist/no-external.d.ts +2 -2
- package/dist/no-external.js +1695 -1057
- package/dist/no-external.mjs +6 -2
- package/dist/rsc.d.mts +2 -2
- package/dist/rsc.d.ts +2 -2
- package/dist/rsc.js +138 -71
- package/dist/rsc.mjs +105 -2
- package/dist/{walk-tree-DrNRq2FV.d.mts → walk-tree-CiAkCQEp.d.mts} +180 -99
- package/dist/{walk-tree-DrNRq2FV.d.ts → walk-tree-CiAkCQEp.d.ts} +180 -99
- package/package.json +1 -1
|
@@ -87,7 +87,7 @@ var init_react_import = __esm({
|
|
|
87
87
|
// lib/data/walk-tree.ts
|
|
88
88
|
init_react_import();
|
|
89
89
|
|
|
90
|
-
// lib/data/map-
|
|
90
|
+
// lib/data/map-fields.ts
|
|
91
91
|
init_react_import();
|
|
92
92
|
|
|
93
93
|
// lib/data/default-slots.ts
|
|
@@ -97,14 +97,14 @@ var defaultSlots = (value, fields) => Object.keys(fields).reduce(
|
|
|
97
97
|
value
|
|
98
98
|
);
|
|
99
99
|
|
|
100
|
-
// lib/data/map-
|
|
100
|
+
// lib/data/map-fields.ts
|
|
101
101
|
var isPromise = (v) => !!v && typeof v.then === "function";
|
|
102
102
|
var flatten = (values) => values.reduce((acc, item) => __spreadValues(__spreadValues({}, acc), item), {});
|
|
103
103
|
var containsPromise = (arr) => arr.some(isPromise);
|
|
104
104
|
var walkField = ({
|
|
105
105
|
value,
|
|
106
106
|
fields,
|
|
107
|
-
|
|
107
|
+
mappers,
|
|
108
108
|
propKey = "",
|
|
109
109
|
propPath = "",
|
|
110
110
|
id = "",
|
|
@@ -112,7 +112,9 @@ var walkField = ({
|
|
|
112
112
|
recurseSlots = false
|
|
113
113
|
}) => {
|
|
114
114
|
var _a, _b, _c;
|
|
115
|
-
|
|
115
|
+
const fieldType = (_a = fields[propKey]) == null ? void 0 : _a.type;
|
|
116
|
+
const map = mappers[fieldType];
|
|
117
|
+
if (map && fieldType === "slot") {
|
|
116
118
|
const content = value || [];
|
|
117
119
|
const mappedContent = recurseSlots ? content.map((el) => {
|
|
118
120
|
var _a2;
|
|
@@ -124,7 +126,7 @@ var walkField = ({
|
|
|
124
126
|
return walkField({
|
|
125
127
|
value: __spreadProps(__spreadValues({}, el), { props: defaultSlots(el.props, fields2) }),
|
|
126
128
|
fields: fields2,
|
|
127
|
-
|
|
129
|
+
mappers,
|
|
128
130
|
id: el.props.id,
|
|
129
131
|
config,
|
|
130
132
|
recurseSlots
|
|
@@ -133,7 +135,21 @@ var walkField = ({
|
|
|
133
135
|
if (containsPromise(mappedContent)) {
|
|
134
136
|
return Promise.all(mappedContent);
|
|
135
137
|
}
|
|
136
|
-
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
|
+
});
|
|
137
153
|
}
|
|
138
154
|
if (value && typeof value === "object") {
|
|
139
155
|
if (Array.isArray(value)) {
|
|
@@ -143,7 +159,7 @@ var walkField = ({
|
|
|
143
159
|
(el, idx) => walkField({
|
|
144
160
|
value: el,
|
|
145
161
|
fields: arrayFields,
|
|
146
|
-
|
|
162
|
+
mappers,
|
|
147
163
|
propKey,
|
|
148
164
|
propPath: `${propPath}[${idx}]`,
|
|
149
165
|
id,
|
|
@@ -162,7 +178,7 @@ var walkField = ({
|
|
|
162
178
|
return walkObject({
|
|
163
179
|
value,
|
|
164
180
|
fields: objectFields,
|
|
165
|
-
|
|
181
|
+
mappers,
|
|
166
182
|
id,
|
|
167
183
|
getPropPath: (k) => `${propPath}.${k}`,
|
|
168
184
|
config,
|
|
@@ -175,7 +191,7 @@ var walkField = ({
|
|
|
175
191
|
var walkObject = ({
|
|
176
192
|
value,
|
|
177
193
|
fields,
|
|
178
|
-
|
|
194
|
+
mappers,
|
|
179
195
|
id,
|
|
180
196
|
getPropPath,
|
|
181
197
|
config,
|
|
@@ -185,7 +201,7 @@ var walkObject = ({
|
|
|
185
201
|
const opts = {
|
|
186
202
|
value: v,
|
|
187
203
|
fields,
|
|
188
|
-
|
|
204
|
+
mappers,
|
|
189
205
|
propKey: k,
|
|
190
206
|
propPath: getPropPath(k),
|
|
191
207
|
id,
|
|
@@ -207,14 +223,14 @@ var walkObject = ({
|
|
|
207
223
|
}
|
|
208
224
|
return flatten(newProps);
|
|
209
225
|
};
|
|
210
|
-
function
|
|
226
|
+
function mapFields(item, mappers, config, recurseSlots = false) {
|
|
211
227
|
var _a, _b, _c, _d, _e;
|
|
212
228
|
const itemType = "type" in item ? item.type : "root";
|
|
213
229
|
const componentConfig = itemType === "root" ? config.root : (_a = config.components) == null ? void 0 : _a[itemType];
|
|
214
230
|
const newProps = walkObject({
|
|
215
231
|
value: defaultSlots((_b = item.props) != null ? _b : {}, (_c = componentConfig == null ? void 0 : componentConfig.fields) != null ? _c : {}),
|
|
216
232
|
fields: (_d = componentConfig == null ? void 0 : componentConfig.fields) != null ? _d : {},
|
|
217
|
-
|
|
233
|
+
mappers,
|
|
218
234
|
id: item.props ? (_e = item.props.id) != null ? _e : "root" : "root",
|
|
219
235
|
getPropPath: (k) => k,
|
|
220
236
|
config,
|
|
@@ -234,11 +250,14 @@ function mapSlots(item, map, config, recurseSlots = false) {
|
|
|
234
250
|
function walkTree(data, config, callbackFn) {
|
|
235
251
|
var _a, _b;
|
|
236
252
|
const walkItem = (item) => {
|
|
237
|
-
return
|
|
253
|
+
return mapFields(
|
|
238
254
|
item,
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
255
|
+
{
|
|
256
|
+
slot: ({ value, parentId, propName }) => {
|
|
257
|
+
var _a2;
|
|
258
|
+
const content = value;
|
|
259
|
+
return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
|
|
260
|
+
}
|
|
242
261
|
},
|
|
243
262
|
config,
|
|
244
263
|
true
|
|
@@ -265,195 +284,6 @@ function walkTree(data, config, callbackFn) {
|
|
|
265
284
|
};
|
|
266
285
|
}
|
|
267
286
|
|
|
268
|
-
// components/ServerRender/index.tsx
|
|
269
|
-
init_react_import();
|
|
270
|
-
|
|
271
|
-
// lib/root-droppable-id.ts
|
|
272
|
-
init_react_import();
|
|
273
|
-
var rootAreaId = "root";
|
|
274
|
-
var rootZone = "default-zone";
|
|
275
|
-
var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
|
276
|
-
|
|
277
|
-
// lib/data/setup-zone.ts
|
|
278
|
-
init_react_import();
|
|
279
|
-
var setupZone = (data, zoneKey) => {
|
|
280
|
-
if (zoneKey === rootDroppableId) {
|
|
281
|
-
return data;
|
|
282
|
-
}
|
|
283
|
-
const newData = __spreadProps(__spreadValues({}, data), {
|
|
284
|
-
zones: data.zones ? __spreadValues({}, data.zones) : {}
|
|
285
|
-
});
|
|
286
|
-
newData.zones[zoneKey] = newData.zones[zoneKey] || [];
|
|
287
|
-
return newData;
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
// lib/use-slots.tsx
|
|
291
|
-
init_react_import();
|
|
292
|
-
import { useMemo } from "react";
|
|
293
|
-
function useSlots(config, item, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
|
|
294
|
-
const slotProps = useMemo(() => {
|
|
295
|
-
const mapped = mapSlots(
|
|
296
|
-
item,
|
|
297
|
-
(content, _parentId, propName, field, propPath) => {
|
|
298
|
-
const wildcardPath = propPath.replace(/\[\d+\]/g, "[*]");
|
|
299
|
-
const isReadOnly = (readOnly == null ? void 0 : readOnly[propPath]) || (readOnly == null ? void 0 : readOnly[wildcardPath]) || forceReadOnly;
|
|
300
|
-
const render = isReadOnly ? renderSlotRender : renderSlotEdit;
|
|
301
|
-
const Slot = (dzProps) => render(__spreadProps(__spreadValues({
|
|
302
|
-
allow: (field == null ? void 0 : field.type) === "slot" ? field.allow : [],
|
|
303
|
-
disallow: (field == null ? void 0 : field.type) === "slot" ? field.disallow : []
|
|
304
|
-
}, dzProps), {
|
|
305
|
-
zone: propName,
|
|
306
|
-
content
|
|
307
|
-
}));
|
|
308
|
-
return Slot;
|
|
309
|
-
},
|
|
310
|
-
config
|
|
311
|
-
).props;
|
|
312
|
-
return mapped;
|
|
313
|
-
}, [config, item, readOnly, forceReadOnly]);
|
|
314
|
-
const mergedProps = useMemo(
|
|
315
|
-
() => __spreadValues(__spreadValues({}, item.props), slotProps),
|
|
316
|
-
[item.props, slotProps]
|
|
317
|
-
);
|
|
318
|
-
return mergedProps;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// components/SlotRender/server.tsx
|
|
322
|
-
init_react_import();
|
|
323
|
-
import { forwardRef } from "react";
|
|
324
|
-
import { jsx } from "react/jsx-runtime";
|
|
325
|
-
var SlotRenderPure = (props) => /* @__PURE__ */ jsx(SlotRender, __spreadValues({}, props));
|
|
326
|
-
var Item = ({
|
|
327
|
-
config,
|
|
328
|
-
item,
|
|
329
|
-
metadata
|
|
330
|
-
}) => {
|
|
331
|
-
const Component = config.components[item.type];
|
|
332
|
-
const props = useSlots(config, item, (slotProps) => /* @__PURE__ */ jsx(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
|
|
333
|
-
return /* @__PURE__ */ jsx(
|
|
334
|
-
Component.render,
|
|
335
|
-
__spreadProps(__spreadValues({}, props), {
|
|
336
|
-
puck: __spreadProps(__spreadValues({}, props.puck), {
|
|
337
|
-
renderDropZone: DropZoneRender,
|
|
338
|
-
metadata: metadata || {}
|
|
339
|
-
})
|
|
340
|
-
})
|
|
341
|
-
);
|
|
342
|
-
};
|
|
343
|
-
var SlotRender = forwardRef(
|
|
344
|
-
function SlotRenderInternal({ className, style, content, config, metadata }, ref) {
|
|
345
|
-
return /* @__PURE__ */ jsx("div", { className, style, ref, children: content.map((item) => {
|
|
346
|
-
if (!config.components[item.type]) {
|
|
347
|
-
return null;
|
|
348
|
-
}
|
|
349
|
-
return /* @__PURE__ */ jsx(
|
|
350
|
-
Item,
|
|
351
|
-
{
|
|
352
|
-
config,
|
|
353
|
-
item,
|
|
354
|
-
metadata
|
|
355
|
-
},
|
|
356
|
-
item.props.id
|
|
357
|
-
);
|
|
358
|
-
}) });
|
|
359
|
-
}
|
|
360
|
-
);
|
|
361
|
-
|
|
362
|
-
// components/ServerRender/index.tsx
|
|
363
|
-
import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
|
|
364
|
-
function DropZoneRender({
|
|
365
|
-
zone,
|
|
366
|
-
data,
|
|
367
|
-
areaId = "root",
|
|
368
|
-
config,
|
|
369
|
-
metadata = {}
|
|
370
|
-
}) {
|
|
371
|
-
let zoneCompound = rootDroppableId;
|
|
372
|
-
let content = (data == null ? void 0 : data.content) || [];
|
|
373
|
-
if (!data || !config) {
|
|
374
|
-
return null;
|
|
375
|
-
}
|
|
376
|
-
if (areaId !== rootAreaId && zone !== rootZone) {
|
|
377
|
-
zoneCompound = `${areaId}:${zone}`;
|
|
378
|
-
content = setupZone(data, zoneCompound).zones[zoneCompound];
|
|
379
|
-
}
|
|
380
|
-
return /* @__PURE__ */ jsx2(Fragment, { children: content.map((item) => {
|
|
381
|
-
const Component = config.components[item.type];
|
|
382
|
-
const props = __spreadProps(__spreadValues({}, item.props), {
|
|
383
|
-
puck: {
|
|
384
|
-
renderDropZone: ({ zone: zone2 }) => /* @__PURE__ */ jsx2(
|
|
385
|
-
DropZoneRender,
|
|
386
|
-
{
|
|
387
|
-
zone: zone2,
|
|
388
|
-
data,
|
|
389
|
-
areaId: item.props.id,
|
|
390
|
-
config,
|
|
391
|
-
metadata
|
|
392
|
-
}
|
|
393
|
-
),
|
|
394
|
-
metadata,
|
|
395
|
-
dragRef: null,
|
|
396
|
-
isEditing: false
|
|
397
|
-
}
|
|
398
|
-
});
|
|
399
|
-
const renderItem = __spreadProps(__spreadValues({}, item), { props });
|
|
400
|
-
const propsWithSlots = useSlots(config, renderItem, (props2) => /* @__PURE__ */ jsx2(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
|
|
401
|
-
if (Component) {
|
|
402
|
-
return /* @__PURE__ */ jsx2(Component.render, __spreadValues({}, propsWithSlots), renderItem.props.id);
|
|
403
|
-
}
|
|
404
|
-
return null;
|
|
405
|
-
}) });
|
|
406
|
-
}
|
|
407
|
-
function Render({
|
|
408
|
-
config,
|
|
409
|
-
data,
|
|
410
|
-
metadata = {}
|
|
411
|
-
}) {
|
|
412
|
-
var _a;
|
|
413
|
-
const rootProps = "props" in data.root ? data.root.props : data.root;
|
|
414
|
-
const title = rootProps.title || "";
|
|
415
|
-
const props = __spreadProps(__spreadValues({}, rootProps), {
|
|
416
|
-
puck: {
|
|
417
|
-
renderDropZone: ({ zone }) => /* @__PURE__ */ jsx2(
|
|
418
|
-
DropZoneRender,
|
|
419
|
-
{
|
|
420
|
-
zone,
|
|
421
|
-
data,
|
|
422
|
-
config,
|
|
423
|
-
metadata
|
|
424
|
-
}
|
|
425
|
-
),
|
|
426
|
-
isEditing: false,
|
|
427
|
-
dragRef: null,
|
|
428
|
-
metadata
|
|
429
|
-
},
|
|
430
|
-
title,
|
|
431
|
-
editMode: false,
|
|
432
|
-
id: "puck-root"
|
|
433
|
-
});
|
|
434
|
-
const propsWithSlots = useSlots(config, { type: "root", props }, (props2) => /* @__PURE__ */ jsx2(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
|
|
435
|
-
if ((_a = config.root) == null ? void 0 : _a.render) {
|
|
436
|
-
return /* @__PURE__ */ jsx2(config.root.render, __spreadProps(__spreadValues({}, propsWithSlots), { children: /* @__PURE__ */ jsx2(
|
|
437
|
-
DropZoneRender,
|
|
438
|
-
{
|
|
439
|
-
config,
|
|
440
|
-
data,
|
|
441
|
-
zone: rootZone,
|
|
442
|
-
metadata
|
|
443
|
-
}
|
|
444
|
-
) }));
|
|
445
|
-
}
|
|
446
|
-
return /* @__PURE__ */ jsx2(
|
|
447
|
-
DropZoneRender,
|
|
448
|
-
{
|
|
449
|
-
config,
|
|
450
|
-
data,
|
|
451
|
-
zone: rootZone,
|
|
452
|
-
metadata
|
|
453
|
-
}
|
|
454
|
-
);
|
|
455
|
-
}
|
|
456
|
-
|
|
457
287
|
// lib/migrate.ts
|
|
458
288
|
init_react_import();
|
|
459
289
|
|
|
@@ -503,6 +333,14 @@ init_react_import();
|
|
|
503
333
|
|
|
504
334
|
// lib/get-zone-id.ts
|
|
505
335
|
init_react_import();
|
|
336
|
+
|
|
337
|
+
// lib/root-droppable-id.ts
|
|
338
|
+
init_react_import();
|
|
339
|
+
var rootAreaId = "root";
|
|
340
|
+
var rootZone = "default-zone";
|
|
341
|
+
var rootDroppableId = `${rootAreaId}:${rootZone}`;
|
|
342
|
+
|
|
343
|
+
// lib/get-zone-id.ts
|
|
506
344
|
var getZoneId = (zoneCompound) => {
|
|
507
345
|
if (!zoneCompound) {
|
|
508
346
|
return [];
|
|
@@ -530,7 +368,7 @@ import flat from "flat";
|
|
|
530
368
|
// lib/data/strip-slots.ts
|
|
531
369
|
init_react_import();
|
|
532
370
|
var stripSlots = (data, config) => {
|
|
533
|
-
return
|
|
371
|
+
return mapFields(data, { slot: () => null }, config);
|
|
534
372
|
};
|
|
535
373
|
|
|
536
374
|
// lib/data/flatten-node.ts
|
|
@@ -589,18 +427,21 @@ function walkAppState(state, config, mapContent = (content) => content, mapNodeO
|
|
|
589
427
|
const mappedItem = mapNodeOrSkip(item, path, index);
|
|
590
428
|
if (!mappedItem) return item;
|
|
591
429
|
const id = mappedItem.props.id;
|
|
592
|
-
const newProps = __spreadProps(__spreadValues({},
|
|
430
|
+
const newProps = __spreadProps(__spreadValues({}, mapFields(
|
|
593
431
|
mappedItem,
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
432
|
+
{
|
|
433
|
+
slot: ({ value, parentId: parentId2, propPath }) => {
|
|
434
|
+
const content = value;
|
|
435
|
+
const zoneCompound = `${parentId2}:${propPath}`;
|
|
436
|
+
const [_2, newContent2] = processContent(
|
|
437
|
+
path,
|
|
438
|
+
zoneCompound,
|
|
439
|
+
content,
|
|
440
|
+
"slot",
|
|
441
|
+
parentId2
|
|
442
|
+
);
|
|
443
|
+
return newContent2;
|
|
444
|
+
}
|
|
604
445
|
},
|
|
605
446
|
config
|
|
606
447
|
).props), {
|
|
@@ -879,24 +720,27 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
|
|
|
879
720
|
resolvedItem.readOnly = readOnly;
|
|
880
721
|
}
|
|
881
722
|
}
|
|
882
|
-
let itemWithResolvedChildren = yield
|
|
723
|
+
let itemWithResolvedChildren = yield mapFields(
|
|
883
724
|
resolvedItem,
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
content
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
725
|
+
{
|
|
726
|
+
slot: (_02) => __async(void 0, [_02], function* ({ value }) {
|
|
727
|
+
const content = value;
|
|
728
|
+
return yield Promise.all(
|
|
729
|
+
content.map(
|
|
730
|
+
(childItem) => __async(void 0, null, function* () {
|
|
731
|
+
return (yield resolveComponentData(
|
|
732
|
+
childItem,
|
|
733
|
+
config,
|
|
734
|
+
metadata,
|
|
735
|
+
onResolveStart,
|
|
736
|
+
onResolveEnd,
|
|
737
|
+
trigger
|
|
738
|
+
)).node;
|
|
739
|
+
})
|
|
740
|
+
)
|
|
741
|
+
);
|
|
742
|
+
})
|
|
743
|
+
},
|
|
900
744
|
config
|
|
901
745
|
);
|
|
902
746
|
if (shouldRunResolver && onResolveEnd) {
|
|
@@ -939,9 +783,9 @@ function resolveAllData(_0, _1) {
|
|
|
939
783
|
},
|
|
940
784
|
"force"
|
|
941
785
|
)).node;
|
|
942
|
-
const resolvedDeep = yield
|
|
786
|
+
const resolvedDeep = yield mapFields(
|
|
943
787
|
resolved,
|
|
944
|
-
processContent,
|
|
788
|
+
{ slot: ({ value }) => processContent(value) },
|
|
945
789
|
config
|
|
946
790
|
);
|
|
947
791
|
onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
|
|
@@ -971,6 +815,123 @@ function resolveAllData(_0, _1) {
|
|
|
971
815
|
});
|
|
972
816
|
}
|
|
973
817
|
|
|
818
|
+
// lib/data/setup-zone.ts
|
|
819
|
+
init_react_import();
|
|
820
|
+
var setupZone = (data, zoneKey) => {
|
|
821
|
+
if (zoneKey === rootDroppableId) {
|
|
822
|
+
return data;
|
|
823
|
+
}
|
|
824
|
+
const newData = __spreadProps(__spreadValues({}, data), {
|
|
825
|
+
zones: data.zones ? __spreadValues({}, data.zones) : {}
|
|
826
|
+
});
|
|
827
|
+
newData.zones[zoneKey] = newData.zones[zoneKey] || [];
|
|
828
|
+
return newData;
|
|
829
|
+
};
|
|
830
|
+
|
|
831
|
+
// lib/field-transforms/use-field-transforms.tsx
|
|
832
|
+
init_react_import();
|
|
833
|
+
import { useMemo } from "react";
|
|
834
|
+
function useFieldTransforms(config, item, transforms, readOnly, forceReadOnly) {
|
|
835
|
+
const mappers = useMemo(() => {
|
|
836
|
+
return Object.keys(transforms).reduce((acc, _fieldType) => {
|
|
837
|
+
const fieldType = _fieldType;
|
|
838
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
839
|
+
[fieldType]: (_a) => {
|
|
840
|
+
var _b = _a, {
|
|
841
|
+
parentId
|
|
842
|
+
} = _b, params = __objRest(_b, [
|
|
843
|
+
"parentId"
|
|
844
|
+
]);
|
|
845
|
+
const wildcardPath = params.propPath.replace(/\[\d+\]/g, "[*]");
|
|
846
|
+
const isReadOnly = (readOnly == null ? void 0 : readOnly[params.propPath]) || (readOnly == null ? void 0 : readOnly[wildcardPath]) || forceReadOnly || false;
|
|
847
|
+
const fn = transforms[fieldType];
|
|
848
|
+
return fn == null ? void 0 : fn(__spreadProps(__spreadValues({}, params), {
|
|
849
|
+
isReadOnly,
|
|
850
|
+
componentId: parentId
|
|
851
|
+
}));
|
|
852
|
+
}
|
|
853
|
+
});
|
|
854
|
+
}, {});
|
|
855
|
+
}, [transforms, readOnly, forceReadOnly]);
|
|
856
|
+
const transformedProps = useMemo(() => {
|
|
857
|
+
const mapped = mapFields(item, mappers, config).props;
|
|
858
|
+
return mapped;
|
|
859
|
+
}, [config, item, mappers]);
|
|
860
|
+
const mergedProps = useMemo(
|
|
861
|
+
() => __spreadValues(__spreadValues({}, item.props), transformedProps),
|
|
862
|
+
[item.props, transformedProps]
|
|
863
|
+
);
|
|
864
|
+
return mergedProps;
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
// lib/field-transforms/default-transforms/slot-transform.tsx
|
|
868
|
+
init_react_import();
|
|
869
|
+
var getSlotTransform = (renderSlotEdit, renderSlotRender = renderSlotEdit) => ({
|
|
870
|
+
slot: ({ value: content, propName, field, isReadOnly }) => {
|
|
871
|
+
const render = isReadOnly ? renderSlotRender : renderSlotEdit;
|
|
872
|
+
const Slot = (dzProps) => render(__spreadProps(__spreadValues({
|
|
873
|
+
allow: (field == null ? void 0 : field.type) === "slot" ? field.allow : [],
|
|
874
|
+
disallow: (field == null ? void 0 : field.type) === "slot" ? field.disallow : []
|
|
875
|
+
}, dzProps), {
|
|
876
|
+
zone: propName,
|
|
877
|
+
content
|
|
878
|
+
}));
|
|
879
|
+
return Slot;
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
|
|
883
|
+
// lib/use-slots.tsx
|
|
884
|
+
init_react_import();
|
|
885
|
+
function useSlots(config, item, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
|
|
886
|
+
return useFieldTransforms(
|
|
887
|
+
config,
|
|
888
|
+
item,
|
|
889
|
+
getSlotTransform(renderSlotEdit, renderSlotRender),
|
|
890
|
+
readOnly,
|
|
891
|
+
forceReadOnly
|
|
892
|
+
);
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
// components/SlotRender/server.tsx
|
|
896
|
+
init_react_import();
|
|
897
|
+
import { forwardRef } from "react";
|
|
898
|
+
import { jsx } from "react/jsx-runtime";
|
|
899
|
+
var SlotRenderPure = (props) => /* @__PURE__ */ jsx(SlotRender, __spreadValues({}, props));
|
|
900
|
+
var Item = ({
|
|
901
|
+
config,
|
|
902
|
+
item,
|
|
903
|
+
metadata
|
|
904
|
+
}) => {
|
|
905
|
+
const Component = config.components[item.type];
|
|
906
|
+
const props = useSlots(config, item, (slotProps) => /* @__PURE__ */ jsx(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
|
|
907
|
+
return /* @__PURE__ */ jsx(
|
|
908
|
+
Component.render,
|
|
909
|
+
__spreadProps(__spreadValues({}, props), {
|
|
910
|
+
puck: __spreadProps(__spreadValues({}, props.puck), {
|
|
911
|
+
metadata: metadata || {}
|
|
912
|
+
})
|
|
913
|
+
})
|
|
914
|
+
);
|
|
915
|
+
};
|
|
916
|
+
var SlotRender = forwardRef(
|
|
917
|
+
function SlotRenderInternal({ className, style, content, config, metadata }, ref) {
|
|
918
|
+
return /* @__PURE__ */ jsx("div", { className, style, ref, children: content.map((item) => {
|
|
919
|
+
if (!config.components[item.type]) {
|
|
920
|
+
return null;
|
|
921
|
+
}
|
|
922
|
+
return /* @__PURE__ */ jsx(
|
|
923
|
+
Item,
|
|
924
|
+
{
|
|
925
|
+
config,
|
|
926
|
+
item,
|
|
927
|
+
metadata
|
|
928
|
+
},
|
|
929
|
+
item.props.id
|
|
930
|
+
);
|
|
931
|
+
}) });
|
|
932
|
+
}
|
|
933
|
+
);
|
|
934
|
+
|
|
974
935
|
export {
|
|
975
936
|
__spreadValues,
|
|
976
937
|
__spreadProps,
|
|
@@ -992,8 +953,9 @@ export {
|
|
|
992
953
|
getChanged,
|
|
993
954
|
resolveComponentData,
|
|
994
955
|
defaultAppState,
|
|
956
|
+
useFieldTransforms,
|
|
957
|
+
getSlotTransform,
|
|
995
958
|
useSlots,
|
|
996
|
-
Render,
|
|
997
959
|
SlotRenderPure,
|
|
998
960
|
SlotRender,
|
|
999
961
|
migrate,
|