@measured/puck 0.19.0-canary.226c08da → 0.19.0-canary.22f5e3a3

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/dist/index.mjs CHANGED
@@ -7,10 +7,11 @@ import {
7
7
  __spreadProps,
8
8
  __spreadValues,
9
9
  __toESM,
10
- createIsSlotConfig,
10
+ defaultAppState,
11
+ defaultViewports,
11
12
  getChanged,
12
13
  init_react_import,
13
- isSlot,
14
+ migrate,
14
15
  resolveAllData,
15
16
  resolveComponentData,
16
17
  rootAreaId,
@@ -19,8 +20,9 @@ import {
19
20
  setupZone,
20
21
  transformProps,
21
22
  useSlots,
23
+ walkAppState,
22
24
  walkTree
23
- } from "./chunk-44RES7IE.mjs";
25
+ } from "./chunk-DDGE2CCN.mjs";
24
26
 
25
27
  // ../../node_modules/classnames/index.js
26
28
  var require_classnames = __commonJS({
@@ -700,198 +702,6 @@ init_react_import();
700
702
 
701
703
  // reducer/actions/set.ts
702
704
  init_react_import();
703
-
704
- // lib/data/walk-app-state.ts
705
- init_react_import();
706
-
707
- // lib/data/for-each-slot.ts
708
- init_react_import();
709
- var forEachSlot = (item, cb, recursive = false, isSlot2 = isSlot) => {
710
- const props = item.props || {};
711
- const propKeys = Object.keys(props);
712
- for (let i = 0; i < propKeys.length; i++) {
713
- const propKey = propKeys[i];
714
- const itemType = "type" in item ? item.type : "root";
715
- if (isSlot2(itemType, propKey, props[propKey])) {
716
- const content = props[propKey];
717
- cb(props.id, propKey, content);
718
- if (recursive) {
719
- content.forEach(
720
- (childItem) => __async(void 0, null, function* () {
721
- return forEachSlot(childItem, cb, true, isSlot2);
722
- })
723
- );
724
- }
725
- }
726
- }
727
- };
728
-
729
- // lib/data/for-related-zones.ts
730
- init_react_import();
731
-
732
- // lib/get-zone-id.ts
733
- init_react_import();
734
- var getZoneId = (zoneCompound) => {
735
- if (!zoneCompound) {
736
- return [];
737
- }
738
- if (zoneCompound && zoneCompound.indexOf(":") > -1) {
739
- return zoneCompound.split(":");
740
- }
741
- return [rootDroppableId, zoneCompound];
742
- };
743
-
744
- // lib/data/for-related-zones.ts
745
- function forRelatedZones(item, data, cb, path = []) {
746
- Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
747
- const [parentId] = getZoneId(zoneCompound);
748
- if (parentId === item.props.id) {
749
- cb(path, zoneCompound, content);
750
- }
751
- });
752
- }
753
-
754
- // lib/data/strip-slots.ts
755
- init_react_import();
756
- var stripSlots = (data) => {
757
- return __spreadProps(__spreadValues({}, data), {
758
- props: Object.entries(data.props).reduce(
759
- (acc, [propKey, propVal]) => {
760
- if (isSlot(propVal)) {
761
- return acc;
762
- }
763
- return __spreadProps(__spreadValues({}, acc), { [propKey]: propVal });
764
- },
765
- { id: data.props.id }
766
- )
767
- });
768
- };
769
-
770
- // lib/data/walk-app-state.ts
771
- function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
772
- var _a;
773
- let newZones = {};
774
- const newZoneIndex = {};
775
- const newNodeIndex = {};
776
- const processContent = (path, zoneCompound, content, zoneType, newId) => {
777
- var _a2;
778
- const [parentId] = zoneCompound.split(":");
779
- const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
780
- const [_2, zone] = zoneCompound.split(":");
781
- const newZoneCompound = `${newId || parentId}:${zone}`;
782
- const newContent2 = mappedContent.map(
783
- (zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
784
- );
785
- newZoneIndex[newZoneCompound] = {
786
- contentIds: newContent2.map((item) => item.props.id),
787
- type: zoneType
788
- };
789
- return [newZoneCompound, newContent2];
790
- };
791
- const processRelatedZones = (item, newId, initialPath) => {
792
- forRelatedZones(
793
- item,
794
- state.data,
795
- (relatedPath, relatedZoneCompound, relatedContent) => {
796
- const [zoneCompound, newContent2] = processContent(
797
- relatedPath,
798
- relatedZoneCompound,
799
- relatedContent,
800
- "dropzone",
801
- newId
802
- );
803
- newZones[zoneCompound] = newContent2;
804
- },
805
- initialPath
806
- );
807
- };
808
- const processItem = (item, path, index) => {
809
- const mappedItem = mapNodeOrSkip(item, path, index);
810
- if (!mappedItem) return item;
811
- const id = mappedItem.props.id;
812
- const newProps = __spreadValues({}, mappedItem.props);
813
- forEachSlot(
814
- mappedItem,
815
- (parentId2, slotId, content) => {
816
- const zoneCompound = `${parentId2}:${slotId}`;
817
- const [_2, newContent2] = processContent(
818
- path,
819
- zoneCompound,
820
- content,
821
- "slot",
822
- parentId2
823
- );
824
- newProps[slotId] = newContent2;
825
- },
826
- false,
827
- createIsSlotConfig(config)
828
- );
829
- processRelatedZones(item, id, path);
830
- const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
831
- const thisZoneCompound = path[path.length - 1];
832
- const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
833
- newNodeIndex[id] = {
834
- data: newItem,
835
- flatData: stripSlots(newItem),
836
- path,
837
- parentId,
838
- zone
839
- };
840
- const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
841
- if (newProps.id === "root") {
842
- delete finalData["type"];
843
- delete finalData.props["id"];
844
- }
845
- return finalData;
846
- };
847
- const zones = state.data.zones || {};
848
- const [_, newContent] = processContent(
849
- [],
850
- rootDroppableId,
851
- state.data.content,
852
- "root"
853
- );
854
- const processedContent = newContent;
855
- const zonesAlreadyProcessed = Object.keys(newZones);
856
- Object.keys(zones || {}).forEach((zoneCompound) => {
857
- const [parentId] = zoneCompound.split(":");
858
- if (zonesAlreadyProcessed.includes(zoneCompound)) {
859
- return;
860
- }
861
- const [_2, newContent2] = processContent(
862
- [rootDroppableId],
863
- zoneCompound,
864
- zones[zoneCompound],
865
- "dropzone",
866
- parentId
867
- );
868
- newZones[zoneCompound] = newContent2;
869
- }, newZones);
870
- const processedRoot = processItem(
871
- {
872
- type: "root",
873
- props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
874
- },
875
- [],
876
- -1
877
- );
878
- const root = __spreadProps(__spreadValues({}, state.data.root), {
879
- props: processedRoot.props
880
- });
881
- return __spreadProps(__spreadValues({}, state), {
882
- data: {
883
- root,
884
- content: processedContent,
885
- zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
886
- },
887
- indexes: {
888
- nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
889
- zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
890
- }
891
- });
892
- }
893
-
894
- // reducer/actions/set.ts
895
705
  var setAction = (state, action, appStore) => {
896
706
  if (typeof action.state === "object") {
897
707
  const newState = __spreadValues(__spreadValues({}, state), action.state);
@@ -1374,14 +1184,6 @@ function createReducer({
1374
1184
  );
1375
1185
  }
1376
1186
 
1377
- // components/ViewportControls/default-viewports.ts
1378
- init_react_import();
1379
- var defaultViewports = [
1380
- { width: 360, height: "auto", icon: "Smartphone", label: "Small" },
1381
- { width: 768, height: "auto", icon: "Tablet", label: "Medium" },
1382
- { width: 1280, height: "auto", icon: "Monitor", label: "Large" }
1383
- ];
1384
-
1385
1187
  // store/index.ts
1386
1188
  import { create as create2, useStore } from "zustand";
1387
1189
  import { subscribeWithSelector as subscribeWithSelector2 } from "zustand/middleware";
@@ -1902,31 +1704,6 @@ var toRoot = (item) => {
1902
1704
  };
1903
1705
 
1904
1706
  // store/index.ts
1905
- var defaultAppState = {
1906
- data: { content: [], root: {}, zones: {} },
1907
- ui: {
1908
- leftSideBarVisible: true,
1909
- rightSideBarVisible: true,
1910
- arrayState: {},
1911
- itemSelector: null,
1912
- componentList: {},
1913
- isDragging: false,
1914
- previewMode: "edit",
1915
- viewports: {
1916
- current: {
1917
- width: defaultViewports[0].width,
1918
- height: defaultViewports[0].height || "auto"
1919
- },
1920
- options: [],
1921
- controlsVisible: true
1922
- },
1923
- field: { focus: null }
1924
- },
1925
- indexes: {
1926
- nodes: {},
1927
- zones: {}
1928
- }
1929
- };
1930
1707
  var defaultPageFields = {
1931
1708
  title: { type: "text" }
1932
1709
  };
@@ -4010,6 +3787,23 @@ function useContextStore(context, selector) {
4010
3787
  // components/DraggableComponent/index.tsx
4011
3788
  import { useShallow as useShallow2 } from "zustand/react/shallow";
4012
3789
  import { useSortable as useSortable2 } from "@dnd-kit/react/sortable";
3790
+
3791
+ // lib/accumulate-transform.ts
3792
+ init_react_import();
3793
+ function accumulateTransform(el) {
3794
+ let matrix = new DOMMatrixReadOnly();
3795
+ let n = el.parentElement;
3796
+ while (n && n !== document.documentElement) {
3797
+ const t = getComputedStyle(n).transform;
3798
+ if (t && t !== "none") {
3799
+ matrix = new DOMMatrixReadOnly(t).multiply(matrix);
3800
+ }
3801
+ n = n.parentElement;
3802
+ }
3803
+ return { scaleX: matrix.a, scaleY: matrix.d };
3804
+ }
3805
+
3806
+ // components/DraggableComponent/index.tsx
4013
3807
  import { jsx as jsx20, jsxs as jsxs9 } from "react/jsx-runtime";
4014
3808
  var getClassName16 = get_class_name_factory_default("DraggableComponent", styles_module_default11);
4015
3809
  var DEBUG2 = false;
@@ -4149,11 +3943,16 @@ var DraggableComponent = ({
4149
3943
  x: deepScrollPosition.x - portalScroll.x - ((_b = portalContainerRect == null ? void 0 : portalContainerRect.left) != null ? _b : 0),
4150
3944
  y: deepScrollPosition.y - portalScroll.y - ((_c = portalContainerRect == null ? void 0 : portalContainerRect.top) != null ? _c : 0)
4151
3945
  };
3946
+ const untransformed = {
3947
+ height: ref.current.offsetHeight,
3948
+ width: ref.current.offsetWidth
3949
+ };
3950
+ const transform = accumulateTransform(ref.current);
4152
3951
  const style2 = {
4153
- left: `${rect.left + scroll.x}px`,
4154
- top: `${rect.top + scroll.y}px`,
4155
- height: `${rect.height}px`,
4156
- width: `${rect.width}px`
3952
+ left: `${(rect.left + scroll.x) / transform.scaleX}px`,
3953
+ top: `${(rect.top + scroll.y) / transform.scaleY}px`,
3954
+ height: `${untransformed.height}px`,
3955
+ width: `${untransformed.width}px`
4157
3956
  };
4158
3957
  return style2;
4159
3958
  }, [ref.current]);
@@ -5177,7 +4976,7 @@ var depthSort = (candidates) => {
5177
4976
  return 0;
5178
4977
  });
5179
4978
  };
5180
- var getZoneId2 = (candidate) => {
4979
+ var getZoneId = (candidate) => {
5181
4980
  let id = candidate == null ? void 0 : candidate.id;
5182
4981
  if (!candidate) return null;
5183
4982
  if (candidate.type === "component") {
@@ -5284,7 +5083,7 @@ var findDeepestCandidate = (position, manager) => {
5284
5083
  return true;
5285
5084
  });
5286
5085
  filteredCandidates.reverse();
5287
- const zone = getZoneId2(filteredCandidates[0]);
5086
+ const zone = getZoneId(filteredCandidates[0]);
5288
5087
  const area = (_a = filteredCandidates[0]) == null ? void 0 : _a.data.areaId;
5289
5088
  return { zone, area };
5290
5089
  }
@@ -5747,6 +5546,13 @@ var DragDropContextClient = ({
5747
5546
  dragMode.current = isNewComponent ? "new" : "existing";
5748
5547
  initialSelector.current = void 0;
5749
5548
  zoneStore.setState({ draggedItem: event.operation.source });
5549
+ dispatch({
5550
+ type: "setUi",
5551
+ ui: {
5552
+ isDragging: true
5553
+ },
5554
+ recordHistory: false
5555
+ });
5750
5556
  },
5751
5557
  children: /* @__PURE__ */ jsx24(ZoneStoreProvider, { store: zoneStore, children: /* @__PURE__ */ jsx24(DropZoneProvider, { value: nextContextValue, children }) })
5752
5558
  }
@@ -7639,6 +7445,13 @@ function usePuck() {
7639
7445
  }, []);
7640
7446
  return createUsePuck()((s) => s);
7641
7447
  }
7448
+ function useGetPuck() {
7449
+ const usePuckApi = useContext10(UsePuckStoreContext);
7450
+ if (!usePuckApi) {
7451
+ throw new Error("usePuckGet must be used inside <Puck>.");
7452
+ }
7453
+ return usePuckApi.getState;
7454
+ }
7642
7455
 
7643
7456
  // components/Puck/index.tsx
7644
7457
  import fdeq from "fast-deep-equal";
@@ -8062,86 +7875,6 @@ Puck.Components = Components;
8062
7875
  Puck.Fields = Fields;
8063
7876
  Puck.Outline = Outline;
8064
7877
  Puck.Preview = Preview3;
8065
-
8066
- // lib/migrate.ts
8067
- init_react_import();
8068
- var migrations = [
8069
- // Migrate root to root.props
8070
- (data) => {
8071
- const rootProps = data.root.props || data.root;
8072
- if (Object.keys(data.root).length > 0 && !data.root.props) {
8073
- console.warn(
8074
- "Migration applied: Root props moved from `root` to `root.props`."
8075
- );
8076
- return __spreadProps(__spreadValues({}, data), {
8077
- root: {
8078
- props: __spreadValues({}, rootProps)
8079
- }
8080
- });
8081
- }
8082
- return data;
8083
- },
8084
- // Migrate zones to slots
8085
- (data, config) => {
8086
- var _a;
8087
- if (!config) return data;
8088
- console.log("Migrating DropZones to slots...");
8089
- const updatedItems = {};
8090
- const appState = __spreadProps(__spreadValues({}, defaultAppState), { data });
8091
- const { indexes } = walkAppState(appState, config);
8092
- const deletedCompounds = [];
8093
- walkAppState(appState, config, (content, zoneCompound, zoneType) => {
8094
- var _a2, _b;
8095
- if (zoneType === "dropzone") {
8096
- const [id, slotName] = zoneCompound.split(":");
8097
- const nodeData = indexes.nodes[id].data;
8098
- const componentType = nodeData.type;
8099
- const configForComponent = config.components[componentType];
8100
- if (((_b = (_a2 = configForComponent == null ? void 0 : configForComponent.fields) == null ? void 0 : _a2[slotName]) == null ? void 0 : _b.type) === "slot") {
8101
- updatedItems[id] = __spreadProps(__spreadValues({}, nodeData), {
8102
- props: __spreadProps(__spreadValues({}, nodeData.props), {
8103
- [slotName]: content
8104
- })
8105
- });
8106
- deletedCompounds.push(zoneCompound);
8107
- }
8108
- return content;
8109
- }
8110
- return content;
8111
- });
8112
- const updated = walkAppState(
8113
- appState,
8114
- config,
8115
- (content) => content,
8116
- (item) => {
8117
- var _a2;
8118
- return (_a2 = updatedItems[item.props.id]) != null ? _a2 : item;
8119
- }
8120
- );
8121
- deletedCompounds.forEach((zoneCompound) => {
8122
- var _a2;
8123
- const [_, propName] = zoneCompound.split(":");
8124
- console.log(
8125
- `\u2713 Success: Migrated "${zoneCompound}" from DropZone to slot field "${propName}"`
8126
- );
8127
- (_a2 = updated.data.zones) == null ? true : delete _a2[zoneCompound];
8128
- });
8129
- Object.keys((_a = updated.data.zones) != null ? _a : {}).forEach((zoneCompound) => {
8130
- const [_, propName] = zoneCompound.split(":");
8131
- throw new Error(
8132
- `Could not migrate DropZone "${zoneCompound}" to slot field. No slot exists with the name "${propName}".`
8133
- );
8134
- });
8135
- delete updated.data.zones;
8136
- return updated.data;
8137
- }
8138
- ];
8139
- function migrate(data, config) {
8140
- return migrations == null ? void 0 : migrations.reduce(
8141
- (acc, migration) => migration(acc, config),
8142
- data
8143
- );
8144
- }
8145
7878
  export {
8146
7879
  Action,
8147
7880
  ActionBar,
@@ -8161,6 +7894,7 @@ export {
8161
7894
  renderContext,
8162
7895
  resolveAllData,
8163
7896
  transformProps,
7897
+ useGetPuck,
8164
7898
  usePuck,
8165
7899
  walkTree
8166
7900
  };
package/dist/rsc.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { a as Config, U as UserGenerics, M as Metadata } from './walk-tree-CM-cu7GU.mjs';
3
- export { af as resolveAllData, ae as transformProps, w as walkTree } from './walk-tree-CM-cu7GU.mjs';
2
+ import { a as Config, U as UserGenerics, M as Metadata } from './walk-tree-DOB5QZVq.mjs';
3
+ export { af as migrate, ah as resolveAllData, ag as transformProps, w as walkTree } from './walk-tree-DOB5QZVq.mjs';
4
4
  import 'react';
5
5
 
6
6
  declare function Render<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>>({ config, data, metadata, }: {
package/dist/rsc.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { a as Config, U as UserGenerics, M as Metadata } from './walk-tree-CM-cu7GU.js';
3
- export { af as resolveAllData, ae as transformProps, w as walkTree } from './walk-tree-CM-cu7GU.js';
2
+ import { a as Config, U as UserGenerics, M as Metadata } from './walk-tree-DOB5QZVq.js';
3
+ export { af as migrate, ah as resolveAllData, ag as transformProps, w as walkTree } from './walk-tree-DOB5QZVq.js';
4
4
  import 'react';
5
5
 
6
6
  declare function Render<UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>>({ config, data, metadata, }: {