@measured/puck 0.20.0-canary.68dd73b8 → 0.20.0-canary.6cf56a8a

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,34 +84,8 @@ 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
90
  // lib/data/map-slots.ts
117
91
  init_react_import();
@@ -256,7 +230,66 @@ function mapSlots(item, map, config, recurseSlots = false) {
256
230
  });
257
231
  }
258
232
 
233
+ // lib/data/walk-tree.ts
234
+ function walkTree(data, config, callbackFn) {
235
+ var _a, _b;
236
+ const walkItem = (item) => {
237
+ return mapSlots(
238
+ item,
239
+ (content, parentId, propName) => {
240
+ var _a2;
241
+ return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
242
+ },
243
+ config,
244
+ true
245
+ );
246
+ };
247
+ if ("props" in data) {
248
+ return walkItem(data);
249
+ }
250
+ const _data = data;
251
+ const zones = (_a = _data.zones) != null ? _a : {};
252
+ const mappedContent = _data.content.map(walkItem);
253
+ return {
254
+ root: walkItem(_data.root),
255
+ content: (_b = callbackFn(mappedContent, {
256
+ parentId: "root",
257
+ propName: "default-zone"
258
+ })) != null ? _b : mappedContent,
259
+ zones: Object.keys(zones).reduce(
260
+ (acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
261
+ [zoneCompound]: zones[zoneCompound].map(walkItem)
262
+ }),
263
+ {}
264
+ )
265
+ };
266
+ }
267
+
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
+
259
290
  // lib/use-slots.tsx
291
+ init_react_import();
292
+ import { useMemo } from "react";
260
293
  function useSlots(config, item, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
261
294
  const slotProps = useMemo(() => {
262
295
  const mapped = mapSlots(
@@ -421,221 +454,6 @@ function Render({
421
454
  );
422
455
  }
423
456
 
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
457
  // lib/migrate.ts
640
458
  init_react_import();
641
459
 
@@ -974,6 +792,185 @@ function migrate(data, config, migrationOptions) {
974
792
  );
975
793
  }
976
794
 
795
+ // lib/transform-props.ts
796
+ init_react_import();
797
+
798
+ // lib/data/default-data.ts
799
+ init_react_import();
800
+ var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
801
+ root: data.root || {},
802
+ content: data.content || []
803
+ });
804
+
805
+ // lib/transform-props.ts
806
+ function transformProps(data, propTransforms, config = { components: {} }) {
807
+ const mapItem = (item) => {
808
+ if (propTransforms[item.type]) {
809
+ return __spreadProps(__spreadValues({}, item), {
810
+ props: __spreadValues({
811
+ id: item.props.id
812
+ }, propTransforms[item.type](item.props))
813
+ });
814
+ }
815
+ return item;
816
+ };
817
+ const defaultedData = defaultData(data);
818
+ const rootProps = defaultedData.root.props || defaultedData.root;
819
+ let newRoot = __spreadValues({}, defaultedData.root);
820
+ if (propTransforms["root"]) {
821
+ newRoot.props = propTransforms["root"](rootProps);
822
+ }
823
+ const dataWithUpdatedRoot = __spreadProps(__spreadValues({}, defaultedData), { root: newRoot });
824
+ const updatedData = walkTree(
825
+ dataWithUpdatedRoot,
826
+ config,
827
+ (content) => content.map(mapItem)
828
+ );
829
+ if (!defaultedData.root.props) {
830
+ updatedData.root = updatedData.root.props;
831
+ }
832
+ return updatedData;
833
+ }
834
+
835
+ // lib/resolve-all-data.ts
836
+ init_react_import();
837
+
838
+ // lib/resolve-component-data.ts
839
+ init_react_import();
840
+
841
+ // lib/get-changed.ts
842
+ init_react_import();
843
+ import fdeq from "fast-deep-equal";
844
+ var getChanged = (newItem, oldItem) => {
845
+ return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
846
+ const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
847
+ const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
848
+ return __spreadProps(__spreadValues({}, acc), {
849
+ [item]: !fdeq(oldItemProps[item], newItemProps[item])
850
+ });
851
+ }, {}) : {};
852
+ };
853
+
854
+ // lib/resolve-component-data.ts
855
+ import fdeq2 from "fast-deep-equal";
856
+ var cache = { lastChange: {} };
857
+ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
858
+ const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
859
+ const resolvedItem = __spreadValues({}, item);
860
+ const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
861
+ const id = "id" in item.props ? item.props.id : "root";
862
+ if (shouldRunResolver) {
863
+ const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
864
+ if (item && fdeq2(item, oldItem)) {
865
+ return { node: resolved, didChange: false };
866
+ }
867
+ const changed = getChanged(item, oldItem);
868
+ if (onResolveStart) {
869
+ onResolveStart(item);
870
+ }
871
+ const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
872
+ changed,
873
+ lastData: oldItem,
874
+ metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
875
+ trigger
876
+ });
877
+ resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
878
+ if (Object.keys(readOnly).length) {
879
+ resolvedItem.readOnly = readOnly;
880
+ }
881
+ }
882
+ let itemWithResolvedChildren = yield mapSlots(
883
+ resolvedItem,
884
+ (content) => __async(void 0, null, function* () {
885
+ return yield Promise.all(
886
+ content.map(
887
+ (childItem) => __async(void 0, null, function* () {
888
+ return (yield resolveComponentData(
889
+ childItem,
890
+ config,
891
+ metadata,
892
+ onResolveStart,
893
+ onResolveEnd,
894
+ trigger
895
+ )).node;
896
+ })
897
+ )
898
+ );
899
+ }),
900
+ config
901
+ );
902
+ if (shouldRunResolver && onResolveEnd) {
903
+ onResolveEnd(resolvedItem);
904
+ }
905
+ cache.lastChange[id] = {
906
+ item,
907
+ resolved: itemWithResolvedChildren
908
+ };
909
+ return {
910
+ node: itemWithResolvedChildren,
911
+ didChange: !fdeq2(item, itemWithResolvedChildren)
912
+ };
913
+ });
914
+
915
+ // lib/data/to-component.ts
916
+ init_react_import();
917
+ var toComponent = (item) => {
918
+ return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
919
+ props: __spreadProps(__spreadValues({}, item.props), { id: "root" }),
920
+ type: "root"
921
+ });
922
+ };
923
+
924
+ // lib/resolve-all-data.ts
925
+ function resolveAllData(_0, _1) {
926
+ return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
927
+ var _a;
928
+ const defaultedData = defaultData(data);
929
+ const resolveNode = (_node) => __async(this, null, function* () {
930
+ const node = toComponent(_node);
931
+ onResolveStart == null ? void 0 : onResolveStart(node);
932
+ const resolved = (yield resolveComponentData(
933
+ node,
934
+ config,
935
+ metadata,
936
+ () => {
937
+ },
938
+ () => {
939
+ },
940
+ "force"
941
+ )).node;
942
+ const resolvedDeep = yield mapSlots(
943
+ resolved,
944
+ processContent,
945
+ config
946
+ );
947
+ onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
948
+ return resolvedDeep;
949
+ });
950
+ const processContent = (content) => __async(this, null, function* () {
951
+ return Promise.all(content.map(resolveNode));
952
+ });
953
+ const processZones = () => __async(this, null, function* () {
954
+ var _a2;
955
+ const zones = (_a2 = data.zones) != null ? _a2 : {};
956
+ Object.entries(zones).forEach((_02) => __async(this, [_02], function* ([zoneKey, content]) {
957
+ zones[zoneKey] = yield Promise.all(content.map(resolveNode));
958
+ }));
959
+ return zones;
960
+ });
961
+ const dynamic = {
962
+ root: yield resolveNode(defaultedData.root),
963
+ content: yield processContent(defaultedData.content),
964
+ zones: yield processZones()
965
+ };
966
+ Object.keys((_a = defaultedData.zones) != null ? _a : {}).forEach((zoneKey) => __async(this, null, function* () {
967
+ const content = defaultedData.zones[zoneKey];
968
+ dynamic.zones[zoneKey] = yield processContent(content);
969
+ }), {});
970
+ return dynamic;
971
+ });
972
+ }
973
+
977
974
  export {
978
975
  __spreadValues,
979
976
  __spreadProps,
@@ -991,15 +988,15 @@ export {
991
988
  walkAppState,
992
989
  walkTree,
993
990
  setupZone,
991
+ defaultViewports,
992
+ getChanged,
993
+ resolveComponentData,
994
+ defaultAppState,
994
995
  useSlots,
996
+ Render,
995
997
  SlotRenderPure,
996
998
  SlotRender,
997
- Render,
998
- getChanged,
999
- resolveComponentData,
1000
- resolveAllData,
999
+ migrate,
1001
1000
  transformProps,
1002
- defaultViewports,
1003
- defaultAppState,
1004
- migrate
1001
+ resolveAllData
1005
1002
  };