@measured/puck 0.16.1-canary.ed282b9 → 0.16.2-canary.18657a4

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.mjs CHANGED
@@ -5,10 +5,15 @@ import {
5
5
  __spreadProps,
6
6
  __spreadValues,
7
7
  __toESM,
8
+ defaultData,
9
+ getChanged,
8
10
  init_react_import,
11
+ resolveAllData,
12
+ resolveComponentData,
13
+ resolveRootData,
9
14
  rootDroppableId,
10
15
  setupZone
11
- } from "./chunk-LM7YWFFF.mjs";
16
+ } from "./chunk-YNVK2PUD.mjs";
12
17
 
13
18
  // ../../node_modules/classnames/index.js
14
19
  var require_classnames = __commonJS({
@@ -138,7 +143,7 @@ var get_class_name_factory_default = getClassNameFactory;
138
143
 
139
144
  // css-module:/home/runner/work/puck/puck/packages/core/components/ActionBar/styles.module.css#css-module
140
145
  init_react_import();
141
- var styles_module_default = { "ActionBar": "_ActionBar_1xlbj_1", "ActionBar-actionsLabel": "_ActionBar-actionsLabel_1xlbj_16", "ActionBar-group": "_ActionBar-group_1xlbj_29", "ActionBar-action": "_ActionBar-action_1xlbj_16" };
146
+ var styles_module_default = { "ActionBar": "_ActionBar_151w5_1", "ActionBar-actionsLabel": "_ActionBar-actionsLabel_151w5_16", "ActionBar-group": "_ActionBar-group_151w5_29", "ActionBar-action": "_ActionBar-action_151w5_16" };
142
147
 
143
148
  // components/ActionBar/index.tsx
144
149
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -180,6 +185,7 @@ import {
180
185
  useCallback as useCallback5,
181
186
  useEffect as useEffect9,
182
187
  useMemo as useMemo2,
188
+ useRef as useRef2,
183
189
  useState as useState10
184
190
  } from "react";
185
191
 
@@ -633,43 +639,30 @@ var flattenData = (data) => {
633
639
  );
634
640
  };
635
641
 
636
- // lib/get-changed.ts
637
- init_react_import();
638
- var getChanged = (newItem, oldItem) => {
639
- return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
640
- const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
641
- const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
642
- return __spreadProps(__spreadValues({}, acc), {
643
- [item]: oldItemProps[item] !== newItemProps[item]
644
- });
645
- }, {}) : {};
646
- };
647
-
648
642
  // lib/use-resolved-permissions.ts
649
643
  var useResolvedPermissions = (config, appState, globalPermissions, setComponentLoading, unsetComponentLoading) => {
650
- const [cache3, setCache] = useState2({});
644
+ const [cache, setCache] = useState2({});
651
645
  const [resolvedPermissions, setResolvedPermissions] = useState2({});
652
646
  const resolveDataForItem = useCallback(
653
647
  (item, force = false) => __async(void 0, null, function* () {
654
648
  var _a, _b, _c;
655
- setComponentLoading == null ? void 0 : setComponentLoading(item.props.id);
656
649
  const componentConfig = item.type === "root" ? config.root : config.components[item.type];
657
650
  if (!componentConfig) {
658
- unsetComponentLoading == null ? void 0 : unsetComponentLoading(item.props.id);
659
651
  return;
660
652
  }
661
653
  const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
662
654
  if (componentConfig.resolvePermissions) {
663
- const changed = getChanged(item, (_a = cache3[item.props.id]) == null ? void 0 : _a.lastData);
655
+ const changed = getChanged(item, (_a = cache[item.props.id]) == null ? void 0 : _a.lastData);
664
656
  if (Object.values(changed).some((el) => el === true) || force) {
657
+ setComponentLoading == null ? void 0 : setComponentLoading(item.props.id);
665
658
  const resolvedPermissions2 = yield componentConfig.resolvePermissions(
666
659
  item,
667
660
  {
668
661
  changed,
669
- lastPermissions: ((_b = cache3[item.props.id]) == null ? void 0 : _b.lastPermissions) || null,
662
+ lastPermissions: ((_b = cache[item.props.id]) == null ? void 0 : _b.lastPermissions) || null,
670
663
  permissions: initialPermissions,
671
664
  appState,
672
- lastData: ((_c = cache3[item.props.id]) == null ? void 0 : _c.lastData) || null
665
+ lastData: ((_c = cache[item.props.id]) == null ? void 0 : _c.lastData) || null
673
666
  }
674
667
  );
675
668
  setCache((_cache) => __spreadProps(__spreadValues({}, _cache), {
@@ -681,11 +674,11 @@ var useResolvedPermissions = (config, appState, globalPermissions, setComponentL
681
674
  setResolvedPermissions((p) => __spreadProps(__spreadValues({}, p), {
682
675
  [item.props.id]: resolvedPermissions2
683
676
  }));
677
+ unsetComponentLoading == null ? void 0 : unsetComponentLoading(item.props.id);
684
678
  }
685
679
  }
686
- unsetComponentLoading == null ? void 0 : unsetComponentLoading(item.props.id);
687
680
  }),
688
- [config, globalPermissions, appState, cache3]
681
+ [config, globalPermissions, appState, cache]
689
682
  );
690
683
  const resolveDataForRoot = (force = false) => {
691
684
  resolveDataForItem(
@@ -729,12 +722,12 @@ var useResolvedPermissions = (config, appState, globalPermissions, setComponentL
729
722
  ({ item, type, root } = {}) => {
730
723
  if (item) {
731
724
  const componentConfig = config.components[item.type];
732
- const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
725
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
733
726
  const resolvedForItem = resolvedPermissions[item.props.id];
734
727
  return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
735
728
  } else if (type) {
736
729
  const componentConfig = config.components[type];
737
- return __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
730
+ return __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
738
731
  } else if (root) {
739
732
  const rootConfig = config.root;
740
733
  const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
@@ -755,53 +748,6 @@ var useResolvedPermissions = (config, appState, globalPermissions, setComponentL
755
748
  init_react_import();
756
749
  import { useCallback as useCallback2, useEffect as useEffect2, useState as useState3 } from "react";
757
750
 
758
- // lib/resolve-component-data.ts
759
- init_react_import();
760
- var cache = { lastChange: {} };
761
- var resolveAllComponentData = (content, config, onResolveStart, onResolveEnd) => __async(void 0, null, function* () {
762
- return yield Promise.all(
763
- content.map((item) => __async(void 0, null, function* () {
764
- return yield resolveComponentData(
765
- item,
766
- config,
767
- onResolveStart,
768
- onResolveEnd
769
- );
770
- }))
771
- );
772
- });
773
- var resolveComponentData = (item, config, onResolveStart, onResolveEnd) => __async(void 0, null, function* () {
774
- const configForItem = config.components[item.type];
775
- if (configForItem.resolveData) {
776
- const { item: oldItem = null, resolved = {} } = cache.lastChange[item.props.id] || {};
777
- if (item && item === oldItem) {
778
- return resolved;
779
- }
780
- const changed = getChanged(item, oldItem);
781
- if (onResolveStart) {
782
- onResolveStart(item);
783
- }
784
- const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, { changed, lastData: oldItem });
785
- const { readOnly: existingReadOnly = {} } = item || {};
786
- const newReadOnly = __spreadValues(__spreadValues({}, existingReadOnly), readOnly);
787
- const resolvedItem = __spreadProps(__spreadValues({}, item), {
788
- props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
789
- });
790
- if (Object.keys(newReadOnly).length) {
791
- resolvedItem.readOnly = newReadOnly;
792
- }
793
- cache.lastChange[item.props.id] = {
794
- item,
795
- resolved: resolvedItem
796
- };
797
- if (onResolveEnd) {
798
- onResolveEnd(resolvedItem);
799
- }
800
- return resolvedItem;
801
- }
802
- return item;
803
- });
804
-
805
751
  // lib/apply-dynamic-props.ts
806
752
  init_react_import();
807
753
  var applyDynamicProps = (data, dynamicProps, rootData) => {
@@ -820,34 +766,6 @@ var applyDynamicProps = (data, dynamicProps, rootData) => {
820
766
  });
821
767
  };
822
768
 
823
- // lib/resolve-root-data.ts
824
- init_react_import();
825
- var cache2 = {};
826
- function resolveRootData(data, config) {
827
- return __async(this, null, function* () {
828
- var _a, _b, _c, _d, _e;
829
- if (((_a = config.root) == null ? void 0 : _a.resolveData) && data.root.props) {
830
- if (((_b = cache2.lastChange) == null ? void 0 : _b.original) === data.root) {
831
- return cache2.lastChange.resolved;
832
- }
833
- const changed = getChanged(data.root, (_c = cache2.lastChange) == null ? void 0 : _c.original);
834
- const rootWithProps = data.root;
835
- const resolvedRoot = yield (_e = config.root) == null ? void 0 : _e.resolveData(rootWithProps, {
836
- changed,
837
- lastData: ((_d = cache2.lastChange) == null ? void 0 : _d.original) || {}
838
- });
839
- cache2.lastChange = {
840
- original: data.root,
841
- resolved: resolvedRoot
842
- };
843
- return __spreadProps(__spreadValues(__spreadValues({}, data.root), resolvedRoot), {
844
- props: __spreadValues(__spreadValues({}, data.root.props), resolvedRoot.props)
845
- });
846
- }
847
- return data.root;
848
- });
849
- }
850
-
851
769
  // lib/use-resolved-data.ts
852
770
  var useResolvedData = (appState, config, dispatch, setComponentLoading, unsetComponentLoading, refreshPermissions) => {
853
771
  const [{ resolverKey, newAppState }, setResolverState] = useState3({
@@ -2220,9 +2138,12 @@ function AutoFieldInternal(props) {
2220
2138
  const Render2 = render[field.type];
2221
2139
  return /* @__PURE__ */ jsx20(Render2, __spreadProps(__spreadValues({}, mergedProps), { children }));
2222
2140
  }
2141
+ var RECENT_CHANGE_TIMEOUT = 200;
2223
2142
  function AutoFieldPrivate(props) {
2224
2143
  const { value, onChange } = props;
2225
2144
  const [localValue, setLocalValue] = useState10(value);
2145
+ const [recentlyChanged, setRecentlyChanged] = useState10(false);
2146
+ const timeoutRef = useRef2();
2226
2147
  const onChangeDb = useDebouncedCallback(
2227
2148
  (val, ui) => {
2228
2149
  onChange(val, ui);
@@ -2232,10 +2153,17 @@ function AutoFieldPrivate(props) {
2232
2153
  );
2233
2154
  const onChangeLocal = useCallback5((val, ui) => {
2234
2155
  setLocalValue(val);
2156
+ setRecentlyChanged(true);
2157
+ clearTimeout(timeoutRef.current);
2158
+ timeoutRef.current = setTimeout(() => {
2159
+ setRecentlyChanged(false);
2160
+ }, RECENT_CHANGE_TIMEOUT);
2235
2161
  onChangeDb(val, ui);
2236
2162
  }, []);
2237
2163
  useEffect9(() => {
2238
- setLocalValue(value);
2164
+ if (!recentlyChanged) {
2165
+ setLocalValue(value);
2166
+ }
2239
2167
  }, [value]);
2240
2168
  const localProps = {
2241
2169
  value: localValue,
@@ -2243,8 +2171,16 @@ function AutoFieldPrivate(props) {
2243
2171
  };
2244
2172
  return /* @__PURE__ */ jsx20(AutoFieldInternal, __spreadValues(__spreadValues({}, props), localProps));
2245
2173
  }
2246
- var DefaultLabel = (props) => /* @__PURE__ */ jsx20("div", __spreadValues({}, props));
2247
2174
  function AutoField(props) {
2175
+ const DefaultLabel = useMemo2(() => {
2176
+ const DefaultLabel2 = (labelProps) => /* @__PURE__ */ jsx20(
2177
+ "div",
2178
+ __spreadProps(__spreadValues({}, labelProps), {
2179
+ className: getClassName15({ readOnly: props.readOnly })
2180
+ })
2181
+ );
2182
+ return DefaultLabel2;
2183
+ }, [props.readOnly]);
2248
2184
  return /* @__PURE__ */ jsx20(AutoFieldInternal, __spreadProps(__spreadValues({}, props), { Label: DefaultLabel }));
2249
2185
  }
2250
2186
 
@@ -3587,7 +3523,7 @@ var DefaultFields = ({
3587
3523
  return /* @__PURE__ */ jsx27(Fragment12, { children });
3588
3524
  };
3589
3525
  var useResolvedFields = () => {
3590
- var _a;
3526
+ var _a, _b;
3591
3527
  const { selectedItem, state, config } = useAppContext();
3592
3528
  const { data } = state;
3593
3529
  const rootFields = ((_a = config.root) == null ? void 0 : _a.fields) || defaultPageFields;
@@ -3599,14 +3535,17 @@ var useResolvedFields = () => {
3599
3535
  const [fieldsLoading, setFieldsLoading] = useState15(false);
3600
3536
  const defaultResolveFields = (_componentData, _params) => defaultFields;
3601
3537
  const componentData = selectedItem ? selectedItem : { props: rootProps, readOnly: data.root.readOnly };
3538
+ const hasComponentResolver = selectedItem && (componentConfig == null ? void 0 : componentConfig.resolveFields);
3539
+ const hasRootResolver = !selectedItem && ((_b = config.root) == null ? void 0 : _b.resolveFields);
3540
+ const hasResolver = hasComponentResolver || hasRootResolver;
3602
3541
  const resolveFields = useCallback7(
3603
3542
  (..._0) => __async(void 0, [..._0], function* (fields = {}) {
3604
- var _a2, _b, _c;
3543
+ var _a2;
3605
3544
  const lastData = ((_a2 = lastSelectedData.props) == null ? void 0 : _a2.id) === componentData.props.id ? lastSelectedData : null;
3606
3545
  const changed = getChanged(componentData, lastData);
3607
3546
  setLastSelectedData(componentData);
3608
- if (selectedItem && (componentConfig == null ? void 0 : componentConfig.resolveFields)) {
3609
- return yield componentConfig == null ? void 0 : componentConfig.resolveFields(
3547
+ if (hasComponentResolver) {
3548
+ return yield componentConfig.resolveFields(
3610
3549
  componentData,
3611
3550
  {
3612
3551
  changed,
@@ -3617,8 +3556,8 @@ var useResolvedFields = () => {
3617
3556
  }
3618
3557
  );
3619
3558
  }
3620
- if (!selectedItem && ((_b = config.root) == null ? void 0 : _b.resolveFields)) {
3621
- return yield (_c = config.root) == null ? void 0 : _c.resolveFields(componentData, {
3559
+ if (hasRootResolver) {
3560
+ return yield config.root.resolveFields(componentData, {
3622
3561
  changed,
3623
3562
  fields,
3624
3563
  lastFields: resolvedFields,
@@ -3636,12 +3575,16 @@ var useResolvedFields = () => {
3636
3575
  [data, config, componentData, selectedItem, resolvedFields, state]
3637
3576
  );
3638
3577
  useEffect13(() => {
3639
- setFieldsLoading(true);
3640
- resolveFields(defaultFields).then((fields) => {
3641
- setResolvedFields(fields || {});
3642
- setFieldsLoading(false);
3643
- });
3644
- }, [data, defaultFields, state.ui.itemSelector]);
3578
+ if (hasResolver) {
3579
+ setFieldsLoading(true);
3580
+ resolveFields(defaultFields).then((fields) => {
3581
+ setResolvedFields(fields || {});
3582
+ setFieldsLoading(false);
3583
+ });
3584
+ } else {
3585
+ setResolvedFields(defaultFields);
3586
+ }
3587
+ }, [data, defaultFields, state.ui.itemSelector, hasResolver]);
3645
3588
  return [resolvedFields, fieldsLoading];
3646
3589
  };
3647
3590
  var Fields = () => {
@@ -3950,7 +3893,7 @@ import {
3950
3893
  createContext as createContext4,
3951
3894
  useContext as useContext5,
3952
3895
  useEffect as useEffect15,
3953
- useRef as useRef2,
3896
+ useRef as useRef3,
3954
3897
  useState as useState17
3955
3898
  } from "react";
3956
3899
  import hash from "object-hash";
@@ -4175,7 +4118,7 @@ function AutoFrame(_a) {
4175
4118
  ]);
4176
4119
  const [loaded, setLoaded] = useState17(false);
4177
4120
  const [ctx, setCtx] = useState17({});
4178
- const ref = useRef2(null);
4121
+ const ref = useRef3(null);
4179
4122
  const [mountTarget, setMountTarget] = useState17();
4180
4123
  useEffect15(() => {
4181
4124
  var _a2;
@@ -4724,7 +4667,7 @@ import {
4724
4667
  useCallback as useCallback10,
4725
4668
  useEffect as useEffect17,
4726
4669
  useMemo as useMemo11,
4727
- useRef as useRef3,
4670
+ useRef as useRef4,
4728
4671
  useState as useState20
4729
4672
  } from "react";
4730
4673
 
@@ -4873,7 +4816,7 @@ var ViewportControls = ({
4873
4816
 
4874
4817
  // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Canvas/styles.module.css#css-module
4875
4818
  init_react_import();
4876
- var styles_module_default21 = { "PuckCanvas": "_PuckCanvas_esbg1_1", "PuckCanvas-controls": "_PuckCanvas-controls_esbg1_16", "PuckCanvas-inner": "_PuckCanvas-inner_esbg1_21", "PuckCanvas-root": "_PuckCanvas-root_esbg1_32", "PuckCanvas--ready": "_PuckCanvas--ready_esbg1_56", "PuckCanvas-loader": "_PuckCanvas-loader_esbg1_60", "PuckCanvas--showLoader": "_PuckCanvas--showLoader_esbg1_70" };
4819
+ var styles_module_default21 = { "PuckCanvas": "_PuckCanvas_avf1c_1", "PuckCanvas-controls": "_PuckCanvas-controls_avf1c_16", "PuckCanvas-inner": "_PuckCanvas-inner_avf1c_21", "PuckCanvas-root": "_PuckCanvas-root_avf1c_32", "PuckCanvas--ready": "_PuckCanvas--ready_avf1c_57", "PuckCanvas-loader": "_PuckCanvas-loader_avf1c_62", "PuckCanvas--showLoader": "_PuckCanvas--showLoader_avf1c_72" };
4877
4820
 
4878
4821
  // lib/get-zoom-config.ts
4879
4822
  init_react_import();
@@ -4913,7 +4856,7 @@ var Canvas = () => {
4913
4856
  const { status, iframe } = useAppContext();
4914
4857
  const { dispatch, state, overrides, setUi, zoomConfig, setZoomConfig } = useAppContext();
4915
4858
  const { ui } = state;
4916
- const frameRef = useRef3(null);
4859
+ const frameRef = useRef4(null);
4917
4860
  const [showTransition, setShowTransition] = useState20(false);
4918
4861
  const defaultRender = useMemo11(() => {
4919
4862
  const PuckDefault = ({ children }) => /* @__PURE__ */ jsx36(Fragment17, { children });
@@ -5658,15 +5601,6 @@ function migrate(data) {
5658
5601
 
5659
5602
  // lib/transform-props.ts
5660
5603
  init_react_import();
5661
-
5662
- // lib/default-data.ts
5663
- init_react_import();
5664
- var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
5665
- root: data.root || {},
5666
- content: data.content || []
5667
- });
5668
-
5669
- // lib/transform-props.ts
5670
5604
  function transformProps(data, propTransforms) {
5671
5605
  const mapItem = (item) => {
5672
5606
  if (propTransforms[item.type]) {
@@ -5699,37 +5633,6 @@ function transformProps(data, propTransforms) {
5699
5633
  return afterPropTransforms;
5700
5634
  }
5701
5635
 
5702
- // lib/resolve-all-data.ts
5703
- init_react_import();
5704
- function resolveAllData(data, config, onResolveStart, onResolveEnd) {
5705
- return __async(this, null, function* () {
5706
- const defaultedData = defaultData(data);
5707
- const dynamicRoot = yield resolveRootData(defaultedData, config);
5708
- const { zones = {} } = data;
5709
- const zoneKeys = Object.keys(zones);
5710
- const resolvedZones = {};
5711
- for (let i = 0; i < zoneKeys.length; i++) {
5712
- const zoneKey = zoneKeys[i];
5713
- resolvedZones[zoneKey] = yield resolveAllComponentData(
5714
- zones[zoneKey],
5715
- config,
5716
- onResolveStart,
5717
- onResolveEnd
5718
- );
5719
- }
5720
- return __spreadProps(__spreadValues({}, defaultedData), {
5721
- root: dynamicRoot,
5722
- content: yield resolveAllComponentData(
5723
- defaultedData.content,
5724
- config,
5725
- onResolveStart,
5726
- onResolveEnd
5727
- ),
5728
- zones: resolvedZones
5729
- });
5730
- });
5731
- }
5732
-
5733
5636
  // lib/use-puck.ts
5734
5637
  init_react_import();
5735
5638
  var usePuck = () => {
@@ -440,4 +440,6 @@ type PuckAction = {
440
440
  recordHistory?: boolean;
441
441
  } & (ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
442
442
 
443
- export { type DefaultRootProps as $, type AppState as A, type BaseData as B, type Config as C, type Data as D, type ExtractPropsFromConfig as E, type Field as F, type RadioField as G, type History as H, type ItemSelector as I, type ArrayField as J, type ObjectField as K, type Adaptor as L, type MappedItem as M, type NumberField as N, type OnAction as O, type PuckAction as P, type ExternalFieldWithAdaptor as Q, type RootDataWithProps as R, type SelectField as S, type TextField as T, type UserGenerics as U, type Viewports as V, type ExternalField as W, type CustomField as X, type Fields as Y, type PuckContext as Z, type DefaultRootRenderProps as _, type FieldProps as a, type WithId as a0, type WithPuckProps as a1, type AsFieldProps as a2, type WithChildren as a3, type DropZoneProps as b, type UiState as c, type Permissions as d, type Plugin as e, type Overrides as f, type IframeConfig as g, type InitialHistory as h, type DefaultComponentProps as i, type DefaultRootFieldProps as j, type ComponentData as k, type ExtractRootPropsFromConfig as l, type ComponentDataMap as m, type Viewport as n, overrideKeys as o, type OverrideKey as p, type FieldRenderFunctions as q, type ItemWithId as r, type ArrayState as s, type PuckComponent as t, type ComponentConfig as u, type RootDataWithoutProps as v, type RootData as w, type Content as x, type BaseField as y, type TextareaField as z };
443
+ declare function resolveAllData<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends Record<string, any> = DefaultRootFieldProps>(data: Partial<Data>, config: Config, onResolveStart?: (item: ComponentData) => void, onResolveEnd?: (item: ComponentData) => void): Promise<Data<Props, RootProps>>;
444
+
445
+ export { type DefaultRootProps as $, type AppState as A, type BaseData as B, type Config as C, type Data as D, type ExtractPropsFromConfig as E, type Field as F, type RadioField as G, type History as H, type ItemSelector as I, type ArrayField as J, type ObjectField as K, type Adaptor as L, type MappedItem as M, type NumberField as N, type OnAction as O, type PuckAction as P, type ExternalFieldWithAdaptor as Q, type RootDataWithProps as R, type SelectField as S, type TextField as T, type UserGenerics as U, type Viewports as V, type ExternalField as W, type CustomField as X, type Fields as Y, type PuckContext as Z, type DefaultRootRenderProps as _, type FieldProps as a, type WithId as a0, type WithPuckProps as a1, type AsFieldProps as a2, type WithChildren as a3, resolveAllData as a4, type DropZoneProps as b, type UiState as c, type Permissions as d, type Plugin as e, type Overrides as f, type IframeConfig as g, type InitialHistory as h, type DefaultComponentProps as i, type DefaultRootFieldProps as j, type ExtractRootPropsFromConfig as k, type ComponentDataMap as l, type Viewport as m, type OverrideKey as n, overrideKeys as o, type FieldRenderFunctions as p, type ItemWithId as q, type ArrayState as r, type PuckComponent as s, type ComponentConfig as t, type RootDataWithoutProps as u, type RootData as v, type ComponentData as w, type Content as x, type BaseField as y, type TextareaField as z };
@@ -440,4 +440,6 @@ type PuckAction = {
440
440
  recordHistory?: boolean;
441
441
  } & (ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
442
442
 
443
- export { type DefaultRootProps as $, type AppState as A, type BaseData as B, type Config as C, type Data as D, type ExtractPropsFromConfig as E, type Field as F, type RadioField as G, type History as H, type ItemSelector as I, type ArrayField as J, type ObjectField as K, type Adaptor as L, type MappedItem as M, type NumberField as N, type OnAction as O, type PuckAction as P, type ExternalFieldWithAdaptor as Q, type RootDataWithProps as R, type SelectField as S, type TextField as T, type UserGenerics as U, type Viewports as V, type ExternalField as W, type CustomField as X, type Fields as Y, type PuckContext as Z, type DefaultRootRenderProps as _, type FieldProps as a, type WithId as a0, type WithPuckProps as a1, type AsFieldProps as a2, type WithChildren as a3, type DropZoneProps as b, type UiState as c, type Permissions as d, type Plugin as e, type Overrides as f, type IframeConfig as g, type InitialHistory as h, type DefaultComponentProps as i, type DefaultRootFieldProps as j, type ComponentData as k, type ExtractRootPropsFromConfig as l, type ComponentDataMap as m, type Viewport as n, overrideKeys as o, type OverrideKey as p, type FieldRenderFunctions as q, type ItemWithId as r, type ArrayState as s, type PuckComponent as t, type ComponentConfig as u, type RootDataWithoutProps as v, type RootData as w, type Content as x, type BaseField as y, type TextareaField as z };
443
+ declare function resolveAllData<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends Record<string, any> = DefaultRootFieldProps>(data: Partial<Data>, config: Config, onResolveStart?: (item: ComponentData) => void, onResolveEnd?: (item: ComponentData) => void): Promise<Data<Props, RootProps>>;
444
+
445
+ export { type DefaultRootProps as $, type AppState as A, type BaseData as B, type Config as C, type Data as D, type ExtractPropsFromConfig as E, type Field as F, type RadioField as G, type History as H, type ItemSelector as I, type ArrayField as J, type ObjectField as K, type Adaptor as L, type MappedItem as M, type NumberField as N, type OnAction as O, type PuckAction as P, type ExternalFieldWithAdaptor as Q, type RootDataWithProps as R, type SelectField as S, type TextField as T, type UserGenerics as U, type Viewports as V, type ExternalField as W, type CustomField as X, type Fields as Y, type PuckContext as Z, type DefaultRootRenderProps as _, type FieldProps as a, type WithId as a0, type WithPuckProps as a1, type AsFieldProps as a2, type WithChildren as a3, resolveAllData as a4, type DropZoneProps as b, type UiState as c, type Permissions as d, type Plugin as e, type Overrides as f, type IframeConfig as g, type InitialHistory as h, type DefaultComponentProps as i, type DefaultRootFieldProps as j, type ExtractRootPropsFromConfig as k, type ComponentDataMap as l, type Viewport as m, type OverrideKey as n, overrideKeys as o, type FieldRenderFunctions as p, type ItemWithId as q, type ArrayState as r, type PuckComponent as s, type ComponentConfig as t, type RootDataWithoutProps as u, type RootData as v, type ComponentData as w, type Content as x, type BaseField as y, type TextareaField as z };
package/dist/rsc.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { C as Config, D as Data } from './actions-9pHbVtMU.mjs';
2
+ import { C as Config, D as Data } from './resolve-all-data-CaDAfEAK.mjs';
3
+ export { a4 as resolveAllData } from './resolve-all-data-CaDAfEAK.mjs';
3
4
  import 'react';
4
5
 
5
6
  declare function Render<UserConfig extends Config = Config>({ config, data, }: {
package/dist/rsc.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { C as Config, D as Data } from './actions-9pHbVtMU.js';
2
+ import { C as Config, D as Data } from './resolve-all-data-CaDAfEAK.js';
3
+ export { a4 as resolveAllData } from './resolve-all-data-CaDAfEAK.js';
3
4
  import 'react';
4
5
 
5
6
  declare function Render<UserConfig extends Config = Config>({ config, data, }: {
package/dist/rsc.js CHANGED
@@ -43,11 +43,32 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
43
43
  mod
44
44
  ));
45
45
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
46
+ var __async = (__this, __arguments, generator) => {
47
+ return new Promise((resolve, reject) => {
48
+ var fulfilled = (value) => {
49
+ try {
50
+ step(generator.next(value));
51
+ } catch (e) {
52
+ reject(e);
53
+ }
54
+ };
55
+ var rejected = (value) => {
56
+ try {
57
+ step(generator.throw(value));
58
+ } catch (e) {
59
+ reject(e);
60
+ }
61
+ };
62
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
63
+ step((generator = generator.apply(__this, __arguments)).next());
64
+ });
65
+ };
46
66
 
47
67
  // rsc.tsx
48
68
  var rsc_exports = {};
49
69
  __export(rsc_exports, {
50
- Render: () => Render
70
+ Render: () => Render,
71
+ resolveAllData: () => resolveAllData
51
72
  });
52
73
  module.exports = __toCommonJS(rsc_exports);
53
74
 
@@ -134,7 +155,128 @@ function Render({
134
155
  }
135
156
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DropZoneRender, { config, data, zone: rootDroppableId });
136
157
  }
158
+
159
+ // lib/get-changed.ts
160
+ var getChanged = (newItem, oldItem) => {
161
+ return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
162
+ const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
163
+ const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
164
+ return __spreadProps(__spreadValues({}, acc), {
165
+ [item]: oldItemProps[item] !== newItemProps[item]
166
+ });
167
+ }, {}) : {};
168
+ };
169
+
170
+ // lib/resolve-component-data.ts
171
+ var cache = { lastChange: {} };
172
+ var resolveAllComponentData = (content, config, onResolveStart, onResolveEnd) => __async(void 0, null, function* () {
173
+ return yield Promise.all(
174
+ content.map((item) => __async(void 0, null, function* () {
175
+ return yield resolveComponentData(
176
+ item,
177
+ config,
178
+ onResolveStart,
179
+ onResolveEnd
180
+ );
181
+ }))
182
+ );
183
+ });
184
+ var resolveComponentData = (item, config, onResolveStart, onResolveEnd) => __async(void 0, null, function* () {
185
+ const configForItem = config.components[item.type];
186
+ if (configForItem.resolveData) {
187
+ const { item: oldItem = null, resolved = {} } = cache.lastChange[item.props.id] || {};
188
+ if (item && item === oldItem) {
189
+ return resolved;
190
+ }
191
+ const changed = getChanged(item, oldItem);
192
+ if (onResolveStart) {
193
+ onResolveStart(item);
194
+ }
195
+ const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, { changed, lastData: oldItem });
196
+ const { readOnly: existingReadOnly = {} } = item || {};
197
+ const newReadOnly = __spreadValues(__spreadValues({}, existingReadOnly), readOnly);
198
+ const resolvedItem = __spreadProps(__spreadValues({}, item), {
199
+ props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
200
+ });
201
+ if (Object.keys(newReadOnly).length) {
202
+ resolvedItem.readOnly = newReadOnly;
203
+ }
204
+ cache.lastChange[item.props.id] = {
205
+ item,
206
+ resolved: resolvedItem
207
+ };
208
+ if (onResolveEnd) {
209
+ onResolveEnd(resolvedItem);
210
+ }
211
+ return resolvedItem;
212
+ }
213
+ return item;
214
+ });
215
+
216
+ // lib/resolve-root-data.ts
217
+ var cache2 = {};
218
+ function resolveRootData(data, config) {
219
+ return __async(this, null, function* () {
220
+ var _a, _b, _c, _d, _e;
221
+ if (((_a = config.root) == null ? void 0 : _a.resolveData) && data.root.props) {
222
+ if (((_b = cache2.lastChange) == null ? void 0 : _b.original) === data.root) {
223
+ return cache2.lastChange.resolved;
224
+ }
225
+ const changed = getChanged(data.root, (_c = cache2.lastChange) == null ? void 0 : _c.original);
226
+ const rootWithProps = data.root;
227
+ const resolvedRoot = yield (_e = config.root) == null ? void 0 : _e.resolveData(rootWithProps, {
228
+ changed,
229
+ lastData: ((_d = cache2.lastChange) == null ? void 0 : _d.original) || {}
230
+ });
231
+ cache2.lastChange = {
232
+ original: data.root,
233
+ resolved: resolvedRoot
234
+ };
235
+ return __spreadProps(__spreadValues(__spreadValues({}, data.root), resolvedRoot), {
236
+ props: __spreadValues(__spreadValues({}, data.root.props), resolvedRoot.props)
237
+ });
238
+ }
239
+ return data.root;
240
+ });
241
+ }
242
+
243
+ // lib/default-data.ts
244
+ var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
245
+ root: data.root || {},
246
+ content: data.content || []
247
+ });
248
+
249
+ // lib/resolve-all-data.ts
250
+ function resolveAllData(data, config, onResolveStart, onResolveEnd) {
251
+ return __async(this, null, function* () {
252
+ const defaultedData = defaultData(data);
253
+ const dynamicRoot = yield resolveRootData(defaultedData, config);
254
+ const { zones = {} } = data;
255
+ const zoneKeys = Object.keys(zones);
256
+ const resolvedZones = {};
257
+ for (let i = 0; i < zoneKeys.length; i++) {
258
+ const zoneKey = zoneKeys[i];
259
+ resolvedZones[zoneKey] = yield resolveAllComponentData(
260
+ zones[zoneKey],
261
+ config,
262
+ onResolveStart,
263
+ onResolveEnd
264
+ );
265
+ }
266
+ return __spreadProps(__spreadValues({}, defaultedData), {
267
+ root: dynamicRoot,
268
+ content: yield resolveAllComponentData(
269
+ defaultedData.content,
270
+ config,
271
+ onResolveStart,
272
+ onResolveEnd
273
+ ),
274
+ zones: resolvedZones
275
+ });
276
+ });
277
+ }
137
278
  // Annotate the CommonJS export names for ESM import in node:
138
279
  0 && (module.exports = {
139
- Render
280
+ Render,
281
+ resolveAllData
140
282
  });
package/dist/rsc.mjs CHANGED
@@ -2,9 +2,10 @@ import {
2
2
  __spreadProps,
3
3
  __spreadValues,
4
4
  init_react_import,
5
+ resolveAllData,
5
6
  rootDroppableId,
6
7
  setupZone
7
- } from "./chunk-LM7YWFFF.mjs";
8
+ } from "./chunk-YNVK2PUD.mjs";
8
9
 
9
10
  // rsc.tsx
10
11
  init_react_import();
@@ -76,5 +77,6 @@ function Render({
76
77
  return /* @__PURE__ */ jsx(DropZoneRender, { config, data, zone: rootDroppableId });
77
78
  }
78
79
  export {
79
- Render
80
+ Render,
81
+ resolveAllData
80
82
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@measured/puck",
3
- "version": "0.16.1-canary.ed282b9",
3
+ "version": "0.16.2-canary.18657a4",
4
4
  "author": "Measured Corporation Ltd <hello@measured.co>",
5
5
  "repository": "measuredco/puck",
6
6
  "bugs": "https://github.com/measuredco/puck/issues",