@measured/puck 0.21.0-canary.68f85428 → 0.21.0-canary.6c44fdb9

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.
@@ -2986,8 +2986,9 @@ var ArrayField = ({
2986
2986
  var _a;
2987
2987
  if (isDraggingAny) return;
2988
2988
  const existingValue = value || [];
2989
+ const defaultProps = typeof field.defaultItemProps === "function" ? field.defaultItemProps(existingValue.length) : (_a = field.defaultItemProps) != null ? _a : {};
2989
2990
  const newItem = defaultSlots(
2990
- uniqifyItem((_a = field.defaultItemProps) != null ? _a : {}),
2991
+ uniqifyItem(defaultProps),
2991
2992
  field.arrayFields
2992
2993
  );
2993
2994
  const newValue = [...existingValue, newItem];
@@ -3162,11 +3163,13 @@ var ExternalInput = ({
3162
3163
  id,
3163
3164
  readOnly
3164
3165
  }) => {
3166
+ var _a;
3165
3167
  const {
3166
3168
  mapProp = (val) => val,
3167
3169
  mapRow = (val) => val,
3168
3170
  filterFields
3169
3171
  } = field || {};
3172
+ const { enabled: shouldCacheData } = (_a = field.cache) != null ? _a : { enabled: true };
3170
3173
  const [data, setData] = useState6([]);
3171
3174
  const [isOpen, setOpen] = useState6(false);
3172
3175
  const [isLoading, setIsLoading] = useState6(true);
@@ -3192,11 +3195,18 @@ var ExternalInput = ({
3192
3195
  (query, filters2) => __async(void 0, null, function* () {
3193
3196
  setIsLoading(true);
3194
3197
  const cacheKey = `${id}-${query}-${JSON.stringify(filters2)}`;
3195
- const listData = dataCache[cacheKey] || (yield field.fetchList({ query, filters: filters2 }));
3198
+ let listData;
3199
+ if (shouldCacheData && dataCache[cacheKey]) {
3200
+ listData = dataCache[cacheKey];
3201
+ } else {
3202
+ listData = yield field.fetchList({ query, filters: filters2 });
3203
+ }
3196
3204
  if (listData) {
3197
3205
  setData(listData);
3198
3206
  setIsLoading(false);
3199
- dataCache[cacheKey] = listData;
3207
+ if (shouldCacheData) {
3208
+ dataCache[cacheKey] = listData;
3209
+ }
3200
3210
  }
3201
3211
  }),
3202
3212
  [id, field]
@@ -3260,6 +3270,7 @@ var ExternalInput = ({
3260
3270
  }),
3261
3271
  onSubmit: (e) => {
3262
3272
  e.preventDefault();
3273
+ e.stopPropagation();
3263
3274
  search(searchQuery, filters);
3264
3275
  },
3265
3276
  children: [
@@ -4170,12 +4181,14 @@ var DraggableComponent = ({
4170
4181
  }
4171
4182
  return cleanup;
4172
4183
  }, [permissions.drag, zoneCompound]);
4184
+ const [, setRerender] = useState10(0);
4173
4185
  const ref = useRef2(null);
4174
4186
  const refSetter = useCallback7(
4175
4187
  (el) => {
4176
4188
  sortableRef(el);
4177
- if (el) {
4189
+ if (ref.current !== el) {
4178
4190
  ref.current = el;
4191
+ setRerender((update) => update + 1);
4179
4192
  }
4180
4193
  },
4181
4194
  [sortableRef]
@@ -8695,7 +8708,7 @@ function PuckProvider({ children }) {
8695
8708
  });
8696
8709
  const previousData = useRef12(null);
8697
8710
  useEffect29(() => {
8698
- appStore.subscribe(
8711
+ return appStore.subscribe(
8699
8712
  (s) => s.state.data,
8700
8713
  (data) => {
8701
8714
  if (onChange) {
@@ -8705,7 +8718,7 @@ function PuckProvider({ children }) {
8705
8718
  }
8706
8719
  }
8707
8720
  );
8708
- }, []);
8721
+ }, [onChange]);
8709
8722
  useRegisterPermissionsSlice(appStore, permissions);
8710
8723
  const uPuckStore = useRegisterUsePuckStore(appStore);
8711
8724
  useEffect29(() => {
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { H as History, P as Permissions, a as ComponentData, C as Config, U as UserGenerics, F as Fields, b as PuckAction, R as RootDataWithProps, c as ResolveDataTrigger, d as Plugin, O as Overrides, V as Viewports, I as IframeConfig, e as UiState, f as ComponentConfig, A as AppState, M as Metadata, g as FieldTransforms, h as Field, i as FieldProps, D as DropZoneProps, j as Data, k as OnAction, l as InitialHistory, n as ItemSelector } from './walk-tree-Ctf3FZQI.mjs';
2
- export { a7 as Adaptor, a5 as ArrayField, B as ArrayState, ak as AsFieldProps, N as BaseData, $ as BaseField, Z as ComponentDataMap, X as ComponentDataOptionalId, _ as Content, ab as CustomField, aa as CustomFieldRender, ah as DefaultComponentProps, K as DefaultComponents, ae as DefaultRootFieldProps, ag as DefaultRootProps, af as DefaultRootRenderProps, o as Direction, p as DragAxis, a9 as ExternalField, a8 as ExternalFieldWithAdaptor, L as ExtractConfigParams, am as ExtractField, y as FieldRenderFunctions, u as FieldTransformFn, s as FieldTransformFnParams, z as ItemWithId, Y as MappedItem, a1 as NumberField, a6 as ObjectField, x as OverrideKey, G as PuckComponent, ad as PuckContext, a4 as RadioField, J as RootConfig, T as RootData, Q as RootDataWithoutProps, a3 as SelectField, S as Slot, E as SlotComponent, ac as SlotField, a0 as TextField, a2 as TextareaField, q as Viewport, al as WithChildren, ai as WithId, aj as WithPuckProps, W as WithSlotProps, m as migrate, v as overrideKeys, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-Ctf3FZQI.mjs';
1
+ import { H as History, P as Permissions, a as ComponentData, C as Config, U as UserGenerics, F as Fields, b as PuckAction, R as RootDataWithProps, c as ResolveDataTrigger, d as Plugin, O as Overrides, V as Viewports, I as IframeConfig, e as UiState, f as ComponentConfig, A as AppState, M as Metadata, g as FieldTransforms, h as Field, i as FieldProps, D as DropZoneProps, j as Data, k as OnAction, l as InitialHistory, n as ItemSelector } from './walk-tree-Dj9qGgeA.mjs';
2
+ export { a7 as Adaptor, a5 as ArrayField, B as ArrayState, al as AsFieldProps, N as BaseData, $ as BaseField, a9 as CacheOpts, Z as ComponentDataMap, X as ComponentDataOptionalId, _ as Content, ac as CustomField, ab as CustomFieldRender, ai as DefaultComponentProps, K as DefaultComponents, af as DefaultRootFieldProps, ah as DefaultRootProps, ag as DefaultRootRenderProps, o as Direction, p as DragAxis, aa as ExternalField, a8 as ExternalFieldWithAdaptor, L as ExtractConfigParams, an as ExtractField, y as FieldRenderFunctions, u as FieldTransformFn, s as FieldTransformFnParams, z as ItemWithId, Y as MappedItem, a1 as NumberField, a6 as ObjectField, x as OverrideKey, G as PuckComponent, ae as PuckContext, a4 as RadioField, J as RootConfig, T as RootData, Q as RootDataWithoutProps, a3 as SelectField, S as Slot, E as SlotComponent, ad as SlotField, a0 as TextField, a2 as TextareaField, q as Viewport, am as WithChildren, aj as WithId, ak as WithPuckProps, W as WithSlotProps, m as migrate, v as overrideKeys, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-Dj9qGgeA.mjs';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import * as react from 'react';
5
5
  import react__default, { ReactNode, SyntheticEvent, ReactElement } from 'react';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { H as History, P as Permissions, a as ComponentData, C as Config, U as UserGenerics, F as Fields, b as PuckAction, R as RootDataWithProps, c as ResolveDataTrigger, d as Plugin, O as Overrides, V as Viewports, I as IframeConfig, e as UiState, f as ComponentConfig, A as AppState, M as Metadata, g as FieldTransforms, h as Field, i as FieldProps, D as DropZoneProps, j as Data, k as OnAction, l as InitialHistory, n as ItemSelector } from './walk-tree-Ctf3FZQI.js';
2
- export { a7 as Adaptor, a5 as ArrayField, B as ArrayState, ak as AsFieldProps, N as BaseData, $ as BaseField, Z as ComponentDataMap, X as ComponentDataOptionalId, _ as Content, ab as CustomField, aa as CustomFieldRender, ah as DefaultComponentProps, K as DefaultComponents, ae as DefaultRootFieldProps, ag as DefaultRootProps, af as DefaultRootRenderProps, o as Direction, p as DragAxis, a9 as ExternalField, a8 as ExternalFieldWithAdaptor, L as ExtractConfigParams, am as ExtractField, y as FieldRenderFunctions, u as FieldTransformFn, s as FieldTransformFnParams, z as ItemWithId, Y as MappedItem, a1 as NumberField, a6 as ObjectField, x as OverrideKey, G as PuckComponent, ad as PuckContext, a4 as RadioField, J as RootConfig, T as RootData, Q as RootDataWithoutProps, a3 as SelectField, S as Slot, E as SlotComponent, ac as SlotField, a0 as TextField, a2 as TextareaField, q as Viewport, al as WithChildren, ai as WithId, aj as WithPuckProps, W as WithSlotProps, m as migrate, v as overrideKeys, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-Ctf3FZQI.js';
1
+ import { H as History, P as Permissions, a as ComponentData, C as Config, U as UserGenerics, F as Fields, b as PuckAction, R as RootDataWithProps, c as ResolveDataTrigger, d as Plugin, O as Overrides, V as Viewports, I as IframeConfig, e as UiState, f as ComponentConfig, A as AppState, M as Metadata, g as FieldTransforms, h as Field, i as FieldProps, D as DropZoneProps, j as Data, k as OnAction, l as InitialHistory, n as ItemSelector } from './walk-tree-Dj9qGgeA.js';
2
+ export { a7 as Adaptor, a5 as ArrayField, B as ArrayState, al as AsFieldProps, N as BaseData, $ as BaseField, a9 as CacheOpts, Z as ComponentDataMap, X as ComponentDataOptionalId, _ as Content, ac as CustomField, ab as CustomFieldRender, ai as DefaultComponentProps, K as DefaultComponents, af as DefaultRootFieldProps, ah as DefaultRootProps, ag as DefaultRootRenderProps, o as Direction, p as DragAxis, aa as ExternalField, a8 as ExternalFieldWithAdaptor, L as ExtractConfigParams, an as ExtractField, y as FieldRenderFunctions, u as FieldTransformFn, s as FieldTransformFnParams, z as ItemWithId, Y as MappedItem, a1 as NumberField, a6 as ObjectField, x as OverrideKey, G as PuckComponent, ae as PuckContext, a4 as RadioField, J as RootConfig, T as RootData, Q as RootDataWithoutProps, a3 as SelectField, S as Slot, E as SlotComponent, ad as SlotField, a0 as TextField, a2 as TextareaField, q as Viewport, am as WithChildren, aj as WithId, ak as WithPuckProps, W as WithSlotProps, m as migrate, v as overrideKeys, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-Dj9qGgeA.js';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import * as react from 'react';
5
5
  import react__default, { ReactNode, SyntheticEvent, ReactElement } from 'react';
package/dist/index.js CHANGED
@@ -3535,8 +3535,9 @@ var ArrayField = ({
3535
3535
  var _a;
3536
3536
  if (isDraggingAny) return;
3537
3537
  const existingValue = value || [];
3538
+ const defaultProps = typeof field.defaultItemProps === "function" ? field.defaultItemProps(existingValue.length) : (_a = field.defaultItemProps) != null ? _a : {};
3538
3539
  const newItem = defaultSlots(
3539
- uniqifyItem((_a = field.defaultItemProps) != null ? _a : {}),
3540
+ uniqifyItem(defaultProps),
3540
3541
  field.arrayFields
3541
3542
  );
3542
3543
  const newValue = [...existingValue, newItem];
@@ -3795,11 +3796,13 @@ var ExternalInput = ({
3795
3796
  id,
3796
3797
  readOnly
3797
3798
  }) => {
3799
+ var _a;
3798
3800
  const {
3799
3801
  mapProp = (val) => val,
3800
3802
  mapRow = (val) => val,
3801
3803
  filterFields
3802
3804
  } = field || {};
3805
+ const { enabled: shouldCacheData } = (_a = field.cache) != null ? _a : { enabled: true };
3803
3806
  const [data, setData] = (0, import_react17.useState)([]);
3804
3807
  const [isOpen, setOpen] = (0, import_react17.useState)(false);
3805
3808
  const [isLoading, setIsLoading] = (0, import_react17.useState)(true);
@@ -3825,11 +3828,18 @@ var ExternalInput = ({
3825
3828
  (query, filters2) => __async(void 0, null, function* () {
3826
3829
  setIsLoading(true);
3827
3830
  const cacheKey = `${id}-${query}-${JSON.stringify(filters2)}`;
3828
- const listData = dataCache[cacheKey] || (yield field.fetchList({ query, filters: filters2 }));
3831
+ let listData;
3832
+ if (shouldCacheData && dataCache[cacheKey]) {
3833
+ listData = dataCache[cacheKey];
3834
+ } else {
3835
+ listData = yield field.fetchList({ query, filters: filters2 });
3836
+ }
3829
3837
  if (listData) {
3830
3838
  setData(listData);
3831
3839
  setIsLoading(false);
3832
- dataCache[cacheKey] = listData;
3840
+ if (shouldCacheData) {
3841
+ dataCache[cacheKey] = listData;
3842
+ }
3833
3843
  }
3834
3844
  }),
3835
3845
  [id, field]
@@ -3893,6 +3903,7 @@ var ExternalInput = ({
3893
3903
  }),
3894
3904
  onSubmit: (e) => {
3895
3905
  e.preventDefault();
3906
+ e.stopPropagation();
3896
3907
  search(searchQuery, filters);
3897
3908
  },
3898
3909
  children: [
@@ -4796,12 +4807,14 @@ var DraggableComponent = ({
4796
4807
  }
4797
4808
  return cleanup;
4798
4809
  }, [permissions.drag, zoneCompound]);
4810
+ const [, setRerender] = (0, import_react24.useState)(0);
4799
4811
  const ref = (0, import_react24.useRef)(null);
4800
4812
  const refSetter = (0, import_react24.useCallback)(
4801
4813
  (el) => {
4802
4814
  sortableRef(el);
4803
- if (el) {
4815
+ if (ref.current !== el) {
4804
4816
  ref.current = el;
4817
+ setRerender((update) => update + 1);
4805
4818
  }
4806
4819
  },
4807
4820
  [sortableRef]
@@ -9395,7 +9408,7 @@ function PuckProvider({ children }) {
9395
9408
  });
9396
9409
  const previousData = (0, import_react60.useRef)(null);
9397
9410
  (0, import_react60.useEffect)(() => {
9398
- appStore.subscribe(
9411
+ return appStore.subscribe(
9399
9412
  (s) => s.state.data,
9400
9413
  (data) => {
9401
9414
  if (onChange) {
@@ -9405,7 +9418,7 @@ function PuckProvider({ children }) {
9405
9418
  }
9406
9419
  }
9407
9420
  );
9408
- }, []);
9421
+ }, [onChange]);
9409
9422
  useRegisterPermissionsSlice(appStore, permissions);
9410
9423
  const uPuckStore = useRegisterUsePuckStore(appStore);
9411
9424
  (0, import_react60.useEffect)(() => {
package/dist/index.mjs CHANGED
@@ -18,7 +18,7 @@ import {
18
18
  setDeep,
19
19
  useGetPuck,
20
20
  usePuck
21
- } from "./chunk-AO6Y47WD.mjs";
21
+ } from "./chunk-YRZRLNQC.mjs";
22
22
  import {
23
23
  init_react_import,
24
24
  migrate,
@@ -1,4 +1,4 @@
1
- export { a7 as Adaptor, A as AppState, a5 as ArrayField, B as ArrayState, ak as AsFieldProps, N as BaseData, $ as BaseField, f as ComponentConfig, a as ComponentData, Z as ComponentDataMap, X as ComponentDataOptionalId, C as Config, _ as Content, ab as CustomField, aa as CustomFieldRender, j as Data, ah as DefaultComponentProps, K as DefaultComponents, ae as DefaultRootFieldProps, ag as DefaultRootProps, af as DefaultRootRenderProps, o as Direction, p as DragAxis, a9 as ExternalField, a8 as ExternalFieldWithAdaptor, L as ExtractConfigParams, am as ExtractField, h as Field, i as FieldProps, y as FieldRenderFunctions, u as FieldTransformFn, s as FieldTransformFnParams, g as FieldTransforms, F as Fields, H as History, I as IframeConfig, l as InitialHistory, z as ItemWithId, Y as MappedItem, M as Metadata, a1 as NumberField, a6 as ObjectField, k as OnAction, x as OverrideKey, O as Overrides, P as Permissions, d as Plugin, b as PuckAction, G as PuckComponent, ad as PuckContext, a4 as RadioField, c as ResolveDataTrigger, J as RootConfig, T as RootData, R as RootDataWithProps, Q as RootDataWithoutProps, a3 as SelectField, S as Slot, E as SlotComponent, ac as SlotField, a0 as TextField, a2 as TextareaField, e as UiState, U as UserGenerics, q as Viewport, V as Viewports, al as WithChildren, ai as WithId, aj as WithPuckProps, W as WithSlotProps, m as migrate, v as overrideKeys, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-Ctf3FZQI.mjs';
1
+ export { a7 as Adaptor, A as AppState, a5 as ArrayField, B as ArrayState, al as AsFieldProps, N as BaseData, $ as BaseField, a9 as CacheOpts, f as ComponentConfig, a as ComponentData, Z as ComponentDataMap, X as ComponentDataOptionalId, C as Config, _ as Content, ac as CustomField, ab as CustomFieldRender, j as Data, ai as DefaultComponentProps, K as DefaultComponents, af as DefaultRootFieldProps, ah as DefaultRootProps, ag as DefaultRootRenderProps, o as Direction, p as DragAxis, aa as ExternalField, a8 as ExternalFieldWithAdaptor, L as ExtractConfigParams, an as ExtractField, h as Field, i as FieldProps, y as FieldRenderFunctions, u as FieldTransformFn, s as FieldTransformFnParams, g as FieldTransforms, F as Fields, H as History, I as IframeConfig, l as InitialHistory, z as ItemWithId, Y as MappedItem, M as Metadata, a1 as NumberField, a6 as ObjectField, k as OnAction, x as OverrideKey, O as Overrides, P as Permissions, d as Plugin, b as PuckAction, G as PuckComponent, ae as PuckContext, a4 as RadioField, c as ResolveDataTrigger, J as RootConfig, T as RootData, R as RootDataWithProps, Q as RootDataWithoutProps, a3 as SelectField, S as Slot, E as SlotComponent, ad as SlotField, a0 as TextField, a2 as TextareaField, e as UiState, U as UserGenerics, q as Viewport, V as Viewports, am as WithChildren, aj as WithId, ak as WithPuckProps, W as WithSlotProps, m as migrate, v as overrideKeys, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-Dj9qGgeA.mjs';
2
2
  export { Action, ActionBar, AutoField, Button, Drawer, DropZone, FieldLabel, Group, IconButton, Label, Puck, PuckApi, Render, UsePuckData, createUsePuck, registerOverlayPortal, renderContext, setDeep, useGetPuck, usePuck } from './index.mjs';
3
3
  import 'react';
4
4
  import 'react/jsx-runtime';
@@ -1,4 +1,4 @@
1
- export { a7 as Adaptor, A as AppState, a5 as ArrayField, B as ArrayState, ak as AsFieldProps, N as BaseData, $ as BaseField, f as ComponentConfig, a as ComponentData, Z as ComponentDataMap, X as ComponentDataOptionalId, C as Config, _ as Content, ab as CustomField, aa as CustomFieldRender, j as Data, ah as DefaultComponentProps, K as DefaultComponents, ae as DefaultRootFieldProps, ag as DefaultRootProps, af as DefaultRootRenderProps, o as Direction, p as DragAxis, a9 as ExternalField, a8 as ExternalFieldWithAdaptor, L as ExtractConfigParams, am as ExtractField, h as Field, i as FieldProps, y as FieldRenderFunctions, u as FieldTransformFn, s as FieldTransformFnParams, g as FieldTransforms, F as Fields, H as History, I as IframeConfig, l as InitialHistory, z as ItemWithId, Y as MappedItem, M as Metadata, a1 as NumberField, a6 as ObjectField, k as OnAction, x as OverrideKey, O as Overrides, P as Permissions, d as Plugin, b as PuckAction, G as PuckComponent, ad as PuckContext, a4 as RadioField, c as ResolveDataTrigger, J as RootConfig, T as RootData, R as RootDataWithProps, Q as RootDataWithoutProps, a3 as SelectField, S as Slot, E as SlotComponent, ac as SlotField, a0 as TextField, a2 as TextareaField, e as UiState, U as UserGenerics, q as Viewport, V as Viewports, al as WithChildren, ai as WithId, aj as WithPuckProps, W as WithSlotProps, m as migrate, v as overrideKeys, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-Ctf3FZQI.js';
1
+ export { a7 as Adaptor, A as AppState, a5 as ArrayField, B as ArrayState, al as AsFieldProps, N as BaseData, $ as BaseField, a9 as CacheOpts, f as ComponentConfig, a as ComponentData, Z as ComponentDataMap, X as ComponentDataOptionalId, C as Config, _ as Content, ac as CustomField, ab as CustomFieldRender, j as Data, ai as DefaultComponentProps, K as DefaultComponents, af as DefaultRootFieldProps, ah as DefaultRootProps, ag as DefaultRootRenderProps, o as Direction, p as DragAxis, aa as ExternalField, a8 as ExternalFieldWithAdaptor, L as ExtractConfigParams, an as ExtractField, h as Field, i as FieldProps, y as FieldRenderFunctions, u as FieldTransformFn, s as FieldTransformFnParams, g as FieldTransforms, F as Fields, H as History, I as IframeConfig, l as InitialHistory, z as ItemWithId, Y as MappedItem, M as Metadata, a1 as NumberField, a6 as ObjectField, k as OnAction, x as OverrideKey, O as Overrides, P as Permissions, d as Plugin, b as PuckAction, G as PuckComponent, ae as PuckContext, a4 as RadioField, c as ResolveDataTrigger, J as RootConfig, T as RootData, R as RootDataWithProps, Q as RootDataWithoutProps, a3 as SelectField, S as Slot, E as SlotComponent, ad as SlotField, a0 as TextField, a2 as TextareaField, e as UiState, U as UserGenerics, q as Viewport, V as Viewports, am as WithChildren, aj as WithId, ak as WithPuckProps, W as WithSlotProps, m as migrate, v as overrideKeys, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-Dj9qGgeA.js';
2
2
  export { Action, ActionBar, AutoField, Button, Drawer, DropZone, FieldLabel, Group, IconButton, Label, Puck, PuckApi, Render, UsePuckData, createUsePuck, registerOverlayPortal, renderContext, setDeep, useGetPuck, usePuck } from './index.js';
3
3
  import 'react';
4
4
  import 'react/jsx-runtime';
@@ -3535,8 +3535,9 @@ var ArrayField = ({
3535
3535
  var _a;
3536
3536
  if (isDraggingAny) return;
3537
3537
  const existingValue = value || [];
3538
+ const defaultProps = typeof field.defaultItemProps === "function" ? field.defaultItemProps(existingValue.length) : (_a = field.defaultItemProps) != null ? _a : {};
3538
3539
  const newItem = defaultSlots(
3539
- uniqifyItem((_a = field.defaultItemProps) != null ? _a : {}),
3540
+ uniqifyItem(defaultProps),
3540
3541
  field.arrayFields
3541
3542
  );
3542
3543
  const newValue = [...existingValue, newItem];
@@ -3795,11 +3796,13 @@ var ExternalInput = ({
3795
3796
  id,
3796
3797
  readOnly
3797
3798
  }) => {
3799
+ var _a;
3798
3800
  const {
3799
3801
  mapProp = (val) => val,
3800
3802
  mapRow = (val) => val,
3801
3803
  filterFields
3802
3804
  } = field || {};
3805
+ const { enabled: shouldCacheData } = (_a = field.cache) != null ? _a : { enabled: true };
3803
3806
  const [data, setData] = (0, import_react17.useState)([]);
3804
3807
  const [isOpen, setOpen] = (0, import_react17.useState)(false);
3805
3808
  const [isLoading, setIsLoading] = (0, import_react17.useState)(true);
@@ -3825,11 +3828,18 @@ var ExternalInput = ({
3825
3828
  (query, filters2) => __async(void 0, null, function* () {
3826
3829
  setIsLoading(true);
3827
3830
  const cacheKey = `${id}-${query}-${JSON.stringify(filters2)}`;
3828
- const listData = dataCache[cacheKey] || (yield field.fetchList({ query, filters: filters2 }));
3831
+ let listData;
3832
+ if (shouldCacheData && dataCache[cacheKey]) {
3833
+ listData = dataCache[cacheKey];
3834
+ } else {
3835
+ listData = yield field.fetchList({ query, filters: filters2 });
3836
+ }
3829
3837
  if (listData) {
3830
3838
  setData(listData);
3831
3839
  setIsLoading(false);
3832
- dataCache[cacheKey] = listData;
3840
+ if (shouldCacheData) {
3841
+ dataCache[cacheKey] = listData;
3842
+ }
3833
3843
  }
3834
3844
  }),
3835
3845
  [id, field]
@@ -3893,6 +3903,7 @@ var ExternalInput = ({
3893
3903
  }),
3894
3904
  onSubmit: (e) => {
3895
3905
  e.preventDefault();
3906
+ e.stopPropagation();
3896
3907
  search(searchQuery, filters);
3897
3908
  },
3898
3909
  children: [
@@ -4796,12 +4807,14 @@ var DraggableComponent = ({
4796
4807
  }
4797
4808
  return cleanup;
4798
4809
  }, [permissions.drag, zoneCompound]);
4810
+ const [, setRerender] = (0, import_react24.useState)(0);
4799
4811
  const ref = (0, import_react24.useRef)(null);
4800
4812
  const refSetter = (0, import_react24.useCallback)(
4801
4813
  (el) => {
4802
4814
  sortableRef(el);
4803
- if (el) {
4815
+ if (ref.current !== el) {
4804
4816
  ref.current = el;
4817
+ setRerender((update) => update + 1);
4805
4818
  }
4806
4819
  },
4807
4820
  [sortableRef]
@@ -9395,7 +9408,7 @@ function PuckProvider({ children }) {
9395
9408
  });
9396
9409
  const previousData = (0, import_react60.useRef)(null);
9397
9410
  (0, import_react60.useEffect)(() => {
9398
- appStore.subscribe(
9411
+ return appStore.subscribe(
9399
9412
  (s) => s.state.data,
9400
9413
  (data) => {
9401
9414
  if (onChange) {
@@ -9405,7 +9418,7 @@ function PuckProvider({ children }) {
9405
9418
  }
9406
9419
  }
9407
9420
  );
9408
- }, []);
9421
+ }, [onChange]);
9409
9422
  useRegisterPermissionsSlice(appStore, permissions);
9410
9423
  const uPuckStore = useRegisterUsePuckStore(appStore);
9411
9424
  (0, import_react60.useEffect)(() => {
@@ -18,7 +18,7 @@ import {
18
18
  setDeep,
19
19
  useGetPuck,
20
20
  usePuck
21
- } from "./chunk-AO6Y47WD.mjs";
21
+ } from "./chunk-YRZRLNQC.mjs";
22
22
  import {
23
23
  init_react_import,
24
24
  migrate,
package/dist/rsc.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { C as Config, U as UserGenerics, M as Metadata } from './walk-tree-Ctf3FZQI.mjs';
3
- export { m as migrate, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-Ctf3FZQI.mjs';
2
+ import { C as Config, U as UserGenerics, M as Metadata } from './walk-tree-Dj9qGgeA.mjs';
3
+ export { m as migrate, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-Dj9qGgeA.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 { C as Config, U as UserGenerics, M as Metadata } from './walk-tree-Ctf3FZQI.js';
3
- export { m as migrate, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-Ctf3FZQI.js';
2
+ import { C as Config, U as UserGenerics, M as Metadata } from './walk-tree-Dj9qGgeA.js';
3
+ export { m as migrate, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-Dj9qGgeA.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, }: {
@@ -52,7 +52,7 @@ type ArrayField<Props extends {
52
52
  type: PropertyKey;
53
53
  } ? Field<Props[0][SubPropName], UserField> | UserField : Field<Props[0][SubPropName], UserField>;
54
54
  };
55
- defaultItemProps?: Props[0];
55
+ defaultItemProps?: Props[0] | ((index: number) => Props[0]);
56
56
  getItemSummary?: (item: Props[0], index?: number) => string;
57
57
  max?: number;
58
58
  min?: number;
@@ -82,10 +82,14 @@ type ExternalFieldWithAdaptor<Props extends any = {
82
82
  adaptorParams?: object;
83
83
  getItemSummary: (item: NotUndefined<Props>, index?: number) => string;
84
84
  };
85
+ type CacheOpts = {
86
+ enabled?: boolean;
87
+ };
85
88
  type ExternalField<Props extends any = {
86
89
  [key: string]: any;
87
90
  }> = BaseField & {
88
91
  type: "external";
92
+ cache?: CacheOpts;
89
93
  placeholder?: string;
90
94
  fetchList: (params: {
91
95
  query: string;
@@ -631,4 +635,4 @@ type WalkTreeOptions = {
631
635
  };
632
636
  declare function walkTree<T extends ComponentData | RootData | G["UserData"], UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>>(data: T, config: UserConfig, callbackFn: (data: Content, options: WalkTreeOptions) => Content | null | void): T;
633
637
 
634
- export { type BaseField as $, type AppState as A, type ArrayState as B, type Config as C, type DropZoneProps as D, type SlotComponent as E, type Fields as F, type PuckComponent as G, type History as H, type IframeConfig as I, type RootConfig as J, type DefaultComponents as K, type ExtractConfigParams as L, type Metadata as M, type BaseData as N, type Overrides as O, type Permissions as P, type RootDataWithoutProps as Q, type RootDataWithProps as R, type Slot as S, type RootData as T, type UserGenerics as U, type Viewports as V, type WithSlotProps as W, type ComponentDataOptionalId as X, type MappedItem as Y, type ComponentDataMap as Z, type Content as _, type ComponentData as a, type TextField as a0, type NumberField as a1, type TextareaField as a2, type SelectField as a3, type RadioField as a4, type ArrayField as a5, type ObjectField as a6, type Adaptor as a7, type ExternalFieldWithAdaptor as a8, type ExternalField as a9, type CustomFieldRender as aa, type CustomField as ab, type SlotField as ac, type PuckContext as ad, type DefaultRootFieldProps as ae, type DefaultRootRenderProps as af, type DefaultRootProps as ag, type DefaultComponentProps as ah, type WithId as ai, type WithPuckProps as aj, type AsFieldProps as ak, type WithChildren as al, type ExtractField as am, type PuckAction as b, type ResolveDataTrigger as c, type Plugin as d, type UiState as e, type ComponentConfig as f, type FieldTransforms as g, type Field as h, type FieldProps as i, type Data as j, type OnAction as k, type InitialHistory as l, migrate as m, type ItemSelector as n, type Direction as o, type DragAxis as p, type Viewport as q, resolveAllData as r, type FieldTransformFnParams as s, transformProps as t, type FieldTransformFn as u, overrideKeys as v, walkTree as w, type OverrideKey as x, type FieldRenderFunctions as y, type ItemWithId as z };
638
+ export { type BaseField as $, type AppState as A, type ArrayState as B, type Config as C, type DropZoneProps as D, type SlotComponent as E, type Fields as F, type PuckComponent as G, type History as H, type IframeConfig as I, type RootConfig as J, type DefaultComponents as K, type ExtractConfigParams as L, type Metadata as M, type BaseData as N, type Overrides as O, type Permissions as P, type RootDataWithoutProps as Q, type RootDataWithProps as R, type Slot as S, type RootData as T, type UserGenerics as U, type Viewports as V, type WithSlotProps as W, type ComponentDataOptionalId as X, type MappedItem as Y, type ComponentDataMap as Z, type Content as _, type ComponentData as a, type TextField as a0, type NumberField as a1, type TextareaField as a2, type SelectField as a3, type RadioField as a4, type ArrayField as a5, type ObjectField as a6, type Adaptor as a7, type ExternalFieldWithAdaptor as a8, type CacheOpts as a9, type ExternalField as aa, type CustomFieldRender as ab, type CustomField as ac, type SlotField as ad, type PuckContext as ae, type DefaultRootFieldProps as af, type DefaultRootRenderProps as ag, type DefaultRootProps as ah, type DefaultComponentProps as ai, type WithId as aj, type WithPuckProps as ak, type AsFieldProps as al, type WithChildren as am, type ExtractField as an, type PuckAction as b, type ResolveDataTrigger as c, type Plugin as d, type UiState as e, type ComponentConfig as f, type FieldTransforms as g, type Field as h, type FieldProps as i, type Data as j, type OnAction as k, type InitialHistory as l, migrate as m, type ItemSelector as n, type Direction as o, type DragAxis as p, type Viewport as q, resolveAllData as r, type FieldTransformFnParams as s, transformProps as t, type FieldTransformFn as u, overrideKeys as v, walkTree as w, type OverrideKey as x, type FieldRenderFunctions as y, type ItemWithId as z };
@@ -52,7 +52,7 @@ type ArrayField<Props extends {
52
52
  type: PropertyKey;
53
53
  } ? Field<Props[0][SubPropName], UserField> | UserField : Field<Props[0][SubPropName], UserField>;
54
54
  };
55
- defaultItemProps?: Props[0];
55
+ defaultItemProps?: Props[0] | ((index: number) => Props[0]);
56
56
  getItemSummary?: (item: Props[0], index?: number) => string;
57
57
  max?: number;
58
58
  min?: number;
@@ -82,10 +82,14 @@ type ExternalFieldWithAdaptor<Props extends any = {
82
82
  adaptorParams?: object;
83
83
  getItemSummary: (item: NotUndefined<Props>, index?: number) => string;
84
84
  };
85
+ type CacheOpts = {
86
+ enabled?: boolean;
87
+ };
85
88
  type ExternalField<Props extends any = {
86
89
  [key: string]: any;
87
90
  }> = BaseField & {
88
91
  type: "external";
92
+ cache?: CacheOpts;
89
93
  placeholder?: string;
90
94
  fetchList: (params: {
91
95
  query: string;
@@ -631,4 +635,4 @@ type WalkTreeOptions = {
631
635
  };
632
636
  declare function walkTree<T extends ComponentData | RootData | G["UserData"], UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>>(data: T, config: UserConfig, callbackFn: (data: Content, options: WalkTreeOptions) => Content | null | void): T;
633
637
 
634
- export { type BaseField as $, type AppState as A, type ArrayState as B, type Config as C, type DropZoneProps as D, type SlotComponent as E, type Fields as F, type PuckComponent as G, type History as H, type IframeConfig as I, type RootConfig as J, type DefaultComponents as K, type ExtractConfigParams as L, type Metadata as M, type BaseData as N, type Overrides as O, type Permissions as P, type RootDataWithoutProps as Q, type RootDataWithProps as R, type Slot as S, type RootData as T, type UserGenerics as U, type Viewports as V, type WithSlotProps as W, type ComponentDataOptionalId as X, type MappedItem as Y, type ComponentDataMap as Z, type Content as _, type ComponentData as a, type TextField as a0, type NumberField as a1, type TextareaField as a2, type SelectField as a3, type RadioField as a4, type ArrayField as a5, type ObjectField as a6, type Adaptor as a7, type ExternalFieldWithAdaptor as a8, type ExternalField as a9, type CustomFieldRender as aa, type CustomField as ab, type SlotField as ac, type PuckContext as ad, type DefaultRootFieldProps as ae, type DefaultRootRenderProps as af, type DefaultRootProps as ag, type DefaultComponentProps as ah, type WithId as ai, type WithPuckProps as aj, type AsFieldProps as ak, type WithChildren as al, type ExtractField as am, type PuckAction as b, type ResolveDataTrigger as c, type Plugin as d, type UiState as e, type ComponentConfig as f, type FieldTransforms as g, type Field as h, type FieldProps as i, type Data as j, type OnAction as k, type InitialHistory as l, migrate as m, type ItemSelector as n, type Direction as o, type DragAxis as p, type Viewport as q, resolveAllData as r, type FieldTransformFnParams as s, transformProps as t, type FieldTransformFn as u, overrideKeys as v, walkTree as w, type OverrideKey as x, type FieldRenderFunctions as y, type ItemWithId as z };
638
+ export { type BaseField as $, type AppState as A, type ArrayState as B, type Config as C, type DropZoneProps as D, type SlotComponent as E, type Fields as F, type PuckComponent as G, type History as H, type IframeConfig as I, type RootConfig as J, type DefaultComponents as K, type ExtractConfigParams as L, type Metadata as M, type BaseData as N, type Overrides as O, type Permissions as P, type RootDataWithoutProps as Q, type RootDataWithProps as R, type Slot as S, type RootData as T, type UserGenerics as U, type Viewports as V, type WithSlotProps as W, type ComponentDataOptionalId as X, type MappedItem as Y, type ComponentDataMap as Z, type Content as _, type ComponentData as a, type TextField as a0, type NumberField as a1, type TextareaField as a2, type SelectField as a3, type RadioField as a4, type ArrayField as a5, type ObjectField as a6, type Adaptor as a7, type ExternalFieldWithAdaptor as a8, type CacheOpts as a9, type ExternalField as aa, type CustomFieldRender as ab, type CustomField as ac, type SlotField as ad, type PuckContext as ae, type DefaultRootFieldProps as af, type DefaultRootRenderProps as ag, type DefaultRootProps as ah, type DefaultComponentProps as ai, type WithId as aj, type WithPuckProps as ak, type AsFieldProps as al, type WithChildren as am, type ExtractField as an, type PuckAction as b, type ResolveDataTrigger as c, type Plugin as d, type UiState as e, type ComponentConfig as f, type FieldTransforms as g, type Field as h, type FieldProps as i, type Data as j, type OnAction as k, type InitialHistory as l, migrate as m, type ItemSelector as n, type Direction as o, type DragAxis as p, type Viewport as q, resolveAllData as r, type FieldTransformFnParams as s, transformProps as t, type FieldTransformFn as u, overrideKeys as v, walkTree as w, type OverrideKey as x, type FieldRenderFunctions as y, type ItemWithId as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@measured/puck",
3
- "version": "0.21.0-canary.68f85428",
3
+ "version": "0.21.0-canary.6c44fdb9",
4
4
  "description": "The open-source visual editor for React",
5
5
  "author": "Chris Villa <chris@puckeditor.com>",
6
6
  "repository": "measuredco/puck",