@measured/puck 0.20.0-canary.f768aab9 → 0.20.1-canary.38076a94

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.
@@ -84,36 +84,10 @@ var init_react_import = __esm({
84
84
  }
85
85
  });
86
86
 
87
- // rsc.tsx
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-slots.ts
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-slots.ts
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
- map,
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
- if (((_a = fields[propKey]) == null ? void 0 : _a.type) === "slot") {
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
- map,
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(mappedContent, id, propPath, fields[propKey], propPath);
138
+ return map({
139
+ value: mappedContent,
140
+ parentId: id,
141
+ propName: propPath,
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
- map,
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
- map,
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
- map,
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
- map,
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 mapSlots(item, map, config, recurseSlots = false) {
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
- map,
233
+ mappers,
244
234
  id: item.props ? (_e = item.props.id) != null ? _e : "root" : "root",
245
235
  getPropPath: (k) => k,
246
236
  config,
@@ -256,330 +246,18 @@ function mapSlots(item, map, config, recurseSlots = false) {
256
246
  });
257
247
  }
258
248
 
259
- // lib/use-slots.tsx
260
- function useSlots(config, item, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
261
- const slotProps = useMemo(() => {
262
- const mapped = mapSlots(
263
- item,
264
- (content, _parentId, propName, field, propPath) => {
265
- const wildcardPath = propPath.replace(/\[\d+\]/g, "[*]");
266
- const isReadOnly = (readOnly == null ? void 0 : readOnly[propPath]) || (readOnly == null ? void 0 : readOnly[wildcardPath]) || forceReadOnly;
267
- const render = isReadOnly ? renderSlotRender : renderSlotEdit;
268
- const Slot = (dzProps) => render(__spreadProps(__spreadValues({
269
- allow: (field == null ? void 0 : field.type) === "slot" ? field.allow : [],
270
- disallow: (field == null ? void 0 : field.type) === "slot" ? field.disallow : []
271
- }, dzProps), {
272
- zone: propName,
273
- content
274
- }));
275
- return Slot;
276
- },
277
- config
278
- ).props;
279
- return mapped;
280
- }, [config, item, readOnly, forceReadOnly]);
281
- const mergedProps = useMemo(
282
- () => __spreadValues(__spreadValues({}, item.props), slotProps),
283
- [item.props, slotProps]
284
- );
285
- return mergedProps;
286
- }
287
-
288
- // components/SlotRender/server.tsx
289
- init_react_import();
290
- import { forwardRef } from "react";
291
- import { jsx } from "react/jsx-runtime";
292
- var SlotRenderPure = (props) => /* @__PURE__ */ jsx(SlotRender, __spreadValues({}, props));
293
- var Item = ({
294
- config,
295
- item,
296
- metadata
297
- }) => {
298
- const Component = config.components[item.type];
299
- const props = useSlots(config, item, (slotProps) => /* @__PURE__ */ jsx(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
300
- return /* @__PURE__ */ jsx(
301
- Component.render,
302
- __spreadProps(__spreadValues({}, props), {
303
- puck: __spreadProps(__spreadValues({}, props.puck), {
304
- renderDropZone: DropZoneRender,
305
- metadata: metadata || {}
306
- })
307
- })
308
- );
309
- };
310
- var SlotRender = forwardRef(
311
- function SlotRenderInternal({ className, style, content, config, metadata }, ref) {
312
- return /* @__PURE__ */ jsx("div", { className, style, ref, children: content.map((item) => {
313
- if (!config.components[item.type]) {
314
- return null;
315
- }
316
- return /* @__PURE__ */ jsx(
317
- Item,
318
- {
319
- config,
320
- item,
321
- metadata
322
- },
323
- item.props.id
324
- );
325
- }) });
326
- }
327
- );
328
-
329
- // components/ServerRender/index.tsx
330
- import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
331
- function DropZoneRender({
332
- zone,
333
- data,
334
- areaId = "root",
335
- config,
336
- metadata = {}
337
- }) {
338
- let zoneCompound = rootDroppableId;
339
- let content = (data == null ? void 0 : data.content) || [];
340
- if (!data || !config) {
341
- return null;
342
- }
343
- if (areaId !== rootAreaId && zone !== rootZone) {
344
- zoneCompound = `${areaId}:${zone}`;
345
- content = setupZone(data, zoneCompound).zones[zoneCompound];
346
- }
347
- return /* @__PURE__ */ jsx2(Fragment, { children: content.map((item) => {
348
- const Component = config.components[item.type];
349
- const props = __spreadProps(__spreadValues({}, item.props), {
350
- puck: {
351
- renderDropZone: ({ zone: zone2 }) => /* @__PURE__ */ jsx2(
352
- DropZoneRender,
353
- {
354
- zone: zone2,
355
- data,
356
- areaId: item.props.id,
357
- config,
358
- metadata
359
- }
360
- ),
361
- metadata,
362
- dragRef: null,
363
- isEditing: false
364
- }
365
- });
366
- const renderItem = __spreadProps(__spreadValues({}, item), { props });
367
- const propsWithSlots = useSlots(config, renderItem, (props2) => /* @__PURE__ */ jsx2(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
368
- if (Component) {
369
- return /* @__PURE__ */ jsx2(Component.render, __spreadValues({}, propsWithSlots), renderItem.props.id);
370
- }
371
- return null;
372
- }) });
373
- }
374
- function Render({
375
- config,
376
- data,
377
- metadata = {}
378
- }) {
379
- var _a;
380
- const rootProps = "props" in data.root ? data.root.props : data.root;
381
- const title = rootProps.title || "";
382
- const props = __spreadProps(__spreadValues({}, rootProps), {
383
- puck: {
384
- renderDropZone: ({ zone }) => /* @__PURE__ */ jsx2(
385
- DropZoneRender,
386
- {
387
- zone,
388
- data,
389
- config,
390
- metadata
391
- }
392
- ),
393
- isEditing: false,
394
- dragRef: null,
395
- metadata
396
- },
397
- title,
398
- editMode: false,
399
- id: "puck-root"
400
- });
401
- const propsWithSlots = useSlots(config, { type: "root", props }, (props2) => /* @__PURE__ */ jsx2(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
402
- if ((_a = config.root) == null ? void 0 : _a.render) {
403
- return /* @__PURE__ */ jsx2(config.root.render, __spreadProps(__spreadValues({}, propsWithSlots), { children: /* @__PURE__ */ jsx2(
404
- DropZoneRender,
405
- {
406
- config,
407
- data,
408
- zone: rootZone,
409
- metadata
410
- }
411
- ) }));
412
- }
413
- return /* @__PURE__ */ jsx2(
414
- DropZoneRender,
415
- {
416
- config,
417
- data,
418
- zone: rootZone,
419
- metadata
420
- }
421
- );
422
- }
423
-
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
249
  // lib/data/walk-tree.ts
574
- init_react_import();
575
250
  function walkTree(data, config, callbackFn) {
576
251
  var _a, _b;
577
252
  const walkItem = (item) => {
578
- return mapSlots(
253
+ return mapFields(
579
254
  item,
580
- (content, parentId, propName) => {
581
- var _a2;
582
- return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
255
+ {
256
+ slot: ({ value, parentId, propName }) => {
257
+ var _a2;
258
+ const content = value;
259
+ return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
260
+ }
583
261
  },
584
262
  config,
585
263
  true
@@ -606,36 +284,6 @@ function walkTree(data, config, callbackFn) {
606
284
  };
607
285
  }
608
286
 
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
287
  // lib/migrate.ts
640
288
  init_react_import();
641
289
 
@@ -684,7 +332,15 @@ init_react_import();
684
332
  init_react_import();
685
333
 
686
334
  // lib/get-zone-id.ts
687
- init_react_import();
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
688
344
  var getZoneId = (zoneCompound) => {
689
345
  if (!zoneCompound) {
690
346
  return [];
@@ -712,7 +368,7 @@ import flat from "flat";
712
368
  // lib/data/strip-slots.ts
713
369
  init_react_import();
714
370
  var stripSlots = (data, config) => {
715
- return mapSlots(data, () => null, config);
371
+ return mapFields(data, { slot: () => null }, config);
716
372
  };
717
373
 
718
374
  // lib/data/flatten-node.ts
@@ -771,18 +427,21 @@ function walkAppState(state, config, mapContent = (content) => content, mapNodeO
771
427
  const mappedItem = mapNodeOrSkip(item, path, index);
772
428
  if (!mappedItem) return item;
773
429
  const id = mappedItem.props.id;
774
- const newProps = __spreadProps(__spreadValues({}, mapSlots(
430
+ const newProps = __spreadProps(__spreadValues({}, mapFields(
775
431
  mappedItem,
776
- (content, parentId2, slotId) => {
777
- const zoneCompound = `${parentId2}:${slotId}`;
778
- const [_2, newContent2] = processContent(
779
- path,
780
- zoneCompound,
781
- content,
782
- "slot",
783
- parentId2
784
- );
785
- return newContent2;
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
+ }
786
445
  },
787
446
  config
788
447
  ).props), {
@@ -974,6 +633,305 @@ function migrate(data, config, migrationOptions) {
974
633
  );
975
634
  }
976
635
 
636
+ // lib/transform-props.ts
637
+ init_react_import();
638
+
639
+ // lib/data/default-data.ts
640
+ init_react_import();
641
+ var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
642
+ root: data.root || {},
643
+ content: data.content || []
644
+ });
645
+
646
+ // lib/transform-props.ts
647
+ function transformProps(data, propTransforms, config = { components: {} }) {
648
+ const mapItem = (item) => {
649
+ if (propTransforms[item.type]) {
650
+ return __spreadProps(__spreadValues({}, item), {
651
+ props: __spreadValues({
652
+ id: item.props.id
653
+ }, propTransforms[item.type](item.props))
654
+ });
655
+ }
656
+ return item;
657
+ };
658
+ const defaultedData = defaultData(data);
659
+ const rootProps = defaultedData.root.props || defaultedData.root;
660
+ let newRoot = __spreadValues({}, defaultedData.root);
661
+ if (propTransforms["root"]) {
662
+ newRoot.props = propTransforms["root"](rootProps);
663
+ }
664
+ const dataWithUpdatedRoot = __spreadProps(__spreadValues({}, defaultedData), { root: newRoot });
665
+ const updatedData = walkTree(
666
+ dataWithUpdatedRoot,
667
+ config,
668
+ (content) => content.map(mapItem)
669
+ );
670
+ if (!defaultedData.root.props) {
671
+ updatedData.root = updatedData.root.props;
672
+ }
673
+ return updatedData;
674
+ }
675
+
676
+ // lib/resolve-all-data.ts
677
+ init_react_import();
678
+
679
+ // lib/resolve-component-data.ts
680
+ init_react_import();
681
+
682
+ // lib/get-changed.ts
683
+ init_react_import();
684
+ import fdeq from "fast-deep-equal";
685
+ var getChanged = (newItem, oldItem) => {
686
+ return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
687
+ const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
688
+ const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
689
+ return __spreadProps(__spreadValues({}, acc), {
690
+ [item]: !fdeq(oldItemProps[item], newItemProps[item])
691
+ });
692
+ }, {}) : {};
693
+ };
694
+
695
+ // lib/resolve-component-data.ts
696
+ import fdeq2 from "fast-deep-equal";
697
+ var cache = { lastChange: {} };
698
+ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
699
+ const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
700
+ const resolvedItem = __spreadValues({}, item);
701
+ const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
702
+ const id = "id" in item.props ? item.props.id : "root";
703
+ if (shouldRunResolver) {
704
+ const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
705
+ if (item && fdeq2(item, oldItem)) {
706
+ return { node: resolved, didChange: false };
707
+ }
708
+ const changed = getChanged(item, oldItem);
709
+ if (onResolveStart) {
710
+ onResolveStart(item);
711
+ }
712
+ const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
713
+ changed,
714
+ lastData: oldItem,
715
+ metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
716
+ trigger
717
+ });
718
+ resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
719
+ if (Object.keys(readOnly).length) {
720
+ resolvedItem.readOnly = readOnly;
721
+ }
722
+ }
723
+ let itemWithResolvedChildren = yield mapFields(
724
+ resolvedItem,
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
+ },
744
+ config
745
+ );
746
+ if (shouldRunResolver && onResolveEnd) {
747
+ onResolveEnd(resolvedItem);
748
+ }
749
+ cache.lastChange[id] = {
750
+ item,
751
+ resolved: itemWithResolvedChildren
752
+ };
753
+ return {
754
+ node: itemWithResolvedChildren,
755
+ didChange: !fdeq2(item, itemWithResolvedChildren)
756
+ };
757
+ });
758
+
759
+ // lib/data/to-component.ts
760
+ init_react_import();
761
+ var toComponent = (item) => {
762
+ return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
763
+ props: __spreadProps(__spreadValues({}, item.props), { id: "root" }),
764
+ type: "root"
765
+ });
766
+ };
767
+
768
+ // lib/resolve-all-data.ts
769
+ function resolveAllData(_0, _1) {
770
+ return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
771
+ var _a;
772
+ const defaultedData = defaultData(data);
773
+ const resolveNode = (_node) => __async(this, null, function* () {
774
+ const node = toComponent(_node);
775
+ onResolveStart == null ? void 0 : onResolveStart(node);
776
+ const resolved = (yield resolveComponentData(
777
+ node,
778
+ config,
779
+ metadata,
780
+ () => {
781
+ },
782
+ () => {
783
+ },
784
+ "force"
785
+ )).node;
786
+ const resolvedDeep = yield mapFields(
787
+ resolved,
788
+ { slot: ({ value }) => processContent(value) },
789
+ config
790
+ );
791
+ onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
792
+ return resolvedDeep;
793
+ });
794
+ const processContent = (content) => __async(this, null, function* () {
795
+ return Promise.all(content.map(resolveNode));
796
+ });
797
+ const processZones = () => __async(this, null, function* () {
798
+ var _a2;
799
+ const zones = (_a2 = data.zones) != null ? _a2 : {};
800
+ Object.entries(zones).forEach((_02) => __async(this, [_02], function* ([zoneKey, content]) {
801
+ zones[zoneKey] = yield Promise.all(content.map(resolveNode));
802
+ }));
803
+ return zones;
804
+ });
805
+ const dynamic = {
806
+ root: yield resolveNode(defaultedData.root),
807
+ content: yield processContent(defaultedData.content),
808
+ zones: yield processZones()
809
+ };
810
+ Object.keys((_a = defaultedData.zones) != null ? _a : {}).forEach((zoneKey) => __async(this, null, function* () {
811
+ const content = defaultedData.zones[zoneKey];
812
+ dynamic.zones[zoneKey] = yield processContent(content);
813
+ }), {});
814
+ return dynamic;
815
+ });
816
+ }
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
+
977
935
  export {
978
936
  __spreadValues,
979
937
  __spreadProps,
@@ -991,15 +949,16 @@ export {
991
949
  walkAppState,
992
950
  walkTree,
993
951
  setupZone,
952
+ defaultViewports,
953
+ getChanged,
954
+ resolveComponentData,
955
+ defaultAppState,
956
+ useFieldTransforms,
957
+ getSlotTransform,
994
958
  useSlots,
995
959
  SlotRenderPure,
996
960
  SlotRender,
997
- Render,
998
- getChanged,
999
- resolveComponentData,
1000
- resolveAllData,
961
+ migrate,
1001
962
  transformProps,
1002
- defaultViewports,
1003
- defaultAppState,
1004
- migrate
963
+ resolveAllData
1005
964
  };