@measured/puck 0.21.0-canary.304940ae → 0.21.0-canary.38e79ba8

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.
@@ -1074,26 +1074,34 @@ var createPermissionsSlice = (set, get) => {
1074
1074
  const resolvePermissions = (..._0) => __async(null, [..._0], function* (params = {}, force) {
1075
1075
  const { state, permissions, config } = get();
1076
1076
  const { cache, globalPermissions } = permissions;
1077
- const resolveDataForItem = (item2, force2 = false) => __async(null, null, function* () {
1078
- var _a, _b, _c;
1077
+ const resolvePermissionsForItem = (item2, force2 = false) => __async(null, null, function* () {
1078
+ var _a, _b;
1079
1079
  const { config: config2, state: appState, setComponentLoading } = get();
1080
+ const itemCache = cache[item2.props.id];
1081
+ const nodes = appState.indexes.nodes;
1082
+ const parentId = (_a = nodes[item2.props.id]) == null ? void 0 : _a.parentId;
1083
+ const parentNode = parentId ? nodes[parentId] : null;
1084
+ const parentData = (_b = parentNode == null ? void 0 : parentNode.data) != null ? _b : null;
1080
1085
  const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
1081
1086
  if (!componentConfig) {
1082
1087
  return;
1083
1088
  }
1084
1089
  const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
1085
1090
  if (componentConfig.resolvePermissions) {
1086
- const changed = getChanged(item2, (_a = cache[item2.props.id]) == null ? void 0 : _a.lastData);
1087
- if (Object.values(changed).some((el) => el === true) || force2) {
1091
+ const changed = getChanged(item2, itemCache == null ? void 0 : itemCache.lastData);
1092
+ const propsChanged = Object.values(changed).some((el) => el === true);
1093
+ const parentChanged = (itemCache == null ? void 0 : itemCache.lastParentId) !== parentId;
1094
+ if (propsChanged || parentChanged || force2) {
1088
1095
  const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
1089
1096
  const resolvedPermissions = yield componentConfig.resolvePermissions(
1090
1097
  item2,
1091
1098
  {
1092
1099
  changed,
1093
- lastPermissions: ((_b = cache[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1100
+ lastPermissions: (itemCache == null ? void 0 : itemCache.lastPermissions) || null,
1094
1101
  permissions: initialPermissions,
1095
1102
  appState: makeStatePublic(appState),
1096
- lastData: ((_c = cache[item2.props.id]) == null ? void 0 : _c.lastData) || null
1103
+ lastData: (itemCache == null ? void 0 : itemCache.lastData) || null,
1104
+ parent: parentData
1097
1105
  }
1098
1106
  );
1099
1107
  const latest = get().permissions;
@@ -1101,6 +1109,7 @@ var createPermissionsSlice = (set, get) => {
1101
1109
  permissions: __spreadProps(__spreadValues({}, latest), {
1102
1110
  cache: __spreadProps(__spreadValues({}, latest.cache), {
1103
1111
  [item2.props.id]: {
1112
+ lastParentId: parentId,
1104
1113
  lastData: item2,
1105
1114
  lastPermissions: resolvedPermissions
1106
1115
  }
@@ -1114,9 +1123,9 @@ var createPermissionsSlice = (set, get) => {
1114
1123
  }
1115
1124
  }
1116
1125
  });
1117
- const resolveDataForRoot = (force2 = false) => {
1126
+ const resolvePermissionsForRoot = (force2 = false) => {
1118
1127
  const { state: appState } = get();
1119
- resolveDataForItem(
1128
+ resolvePermissionsForItem(
1120
1129
  // Shim the root data in by conforming to component data shape
1121
1130
  {
1122
1131
  type: "root",
@@ -1127,16 +1136,16 @@ var createPermissionsSlice = (set, get) => {
1127
1136
  };
1128
1137
  const { item, type, root } = params;
1129
1138
  if (item) {
1130
- yield resolveDataForItem(item, force);
1139
+ yield resolvePermissionsForItem(item, force);
1131
1140
  } else if (type) {
1132
1141
  flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(null, null, function* () {
1133
- yield resolveDataForItem(item2, force);
1142
+ yield resolvePermissionsForItem(item2, force);
1134
1143
  }));
1135
1144
  } else if (root) {
1136
- resolveDataForRoot(force);
1145
+ resolvePermissionsForRoot(force);
1137
1146
  } else {
1138
1147
  flattenData(state, config).map((item2) => __async(null, null, function* () {
1139
- yield resolveDataForItem(item2, force);
1148
+ yield resolvePermissionsForItem(item2, force);
1140
1149
  }));
1141
1150
  }
1142
1151
  });
@@ -6420,7 +6429,15 @@ var generateUsePuck = (store) => {
6420
6429
  selectedItem: store.selectedItem || null,
6421
6430
  getItemBySelector: (selector) => getItem(selector, store.state),
6422
6431
  getItemById: (id) => store.state.indexes.nodes[id].data,
6423
- getSelectorForId: (id) => getSelectorForId(store.state, id)
6432
+ getSelectorForId: (id) => getSelectorForId(store.state, id),
6433
+ getParentById: (id) => {
6434
+ const node = store.state.indexes.nodes[id];
6435
+ const parentId = node.parentId;
6436
+ if (parentId === null) return;
6437
+ const parentNode = store.state.indexes.nodes[parentId];
6438
+ if (!parentNode) return;
6439
+ return parentNode.data;
6440
+ }
6424
6441
  };
6425
6442
  return storeData;
6426
6443
  };
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-BqwnaCVe.mjs';
2
- export { ad as Adaptor, ab as ArrayField, B as ArrayState, ar as AsFieldProps, X as BaseData, a5 as BaseField, af as CacheOpts, J as ComponentConfigExtensions, T as ComponentConfigParams, a0 as ComponentDataMap, _ as ComponentDataOptionalId, a3 as ComponentMetadata, Q as ConfigParams, a1 as Content, ai as CustomField, ah as CustomFieldRender, ao as DefaultComponentProps, L as DefaultComponents, al as DefaultRootFieldProps, an as DefaultRootProps, am as DefaultRootRenderProps, o as Direction, p as DragAxis, ag as ExternalField, ae as ExternalFieldWithAdaptor, N as ExtractConfigParams, at as ExtractField, a4 as FieldMetadata, y as FieldRenderFunctions, u as FieldTransformFn, s as FieldTransformFnParams, z as ItemWithId, $ as MappedItem, a7 as NumberField, ac as ObjectField, x as OverrideKey, G as PuckComponent, ak as PuckContext, a2 as PuckMetadata, aa as RadioField, K as RootConfig, Z as RootData, Y as RootDataWithoutProps, a9 as SelectField, S as Slot, E as SlotComponent, aj as SlotField, a6 as TextField, a8 as TextareaField, q as Viewport, as as WithChildren, ap as WithId, aq as WithPuckProps, W as WithSlotProps, m as migrate, v as overrideKeys, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-BqwnaCVe.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-bsPSSmt9.mjs';
2
+ export { ad as Adaptor, ab as ArrayField, B as ArrayState, ar as AsFieldProps, X as BaseData, a5 as BaseField, af as CacheOpts, J as ComponentConfigExtensions, T as ComponentConfigParams, a0 as ComponentDataMap, _ as ComponentDataOptionalId, a3 as ComponentMetadata, Q as ConfigParams, a1 as Content, ai as CustomField, ah as CustomFieldRender, ao as DefaultComponentProps, L as DefaultComponents, al as DefaultRootFieldProps, an as DefaultRootProps, am as DefaultRootRenderProps, o as Direction, p as DragAxis, ag as ExternalField, ae as ExternalFieldWithAdaptor, N as ExtractConfigParams, at as ExtractField, a4 as FieldMetadata, y as FieldRenderFunctions, u as FieldTransformFn, s as FieldTransformFnParams, z as ItemWithId, $ as MappedItem, a7 as NumberField, ac as ObjectField, x as OverrideKey, G as PuckComponent, ak as PuckContext, a2 as PuckMetadata, aa as RadioField, K as RootConfig, Z as RootData, Y as RootDataWithoutProps, a9 as SelectField, S as Slot, E as SlotComponent, aj as SlotField, a6 as TextField, a8 as TextareaField, q as Viewport, as as WithChildren, ap as WithId, aq as WithPuckProps, W as WithSlotProps, m as migrate, v as overrideKeys, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-bsPSSmt9.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';
@@ -47,6 +47,7 @@ type RefreshPermissions<UserConfig extends Config = Config> = (params?: Permissi
47
47
  type Cache = Record<string, {
48
48
  lastPermissions: Partial<Permissions>;
49
49
  lastData: ComponentData | null;
50
+ lastParentId: string | null;
50
51
  }>;
51
52
  type PermissionsSlice = {
52
53
  cache: Cache;
@@ -271,6 +272,7 @@ type UsePuckData<UserConfig extends Config = Config, G extends UserGenerics<User
271
272
  getItemBySelector: (selector: ItemSelector) => G["UserComponentData"] | undefined;
272
273
  getItemById: (id: string) => G["UserComponentData"] | undefined;
273
274
  getSelectorForId: (id: string) => Required<ItemSelector> | undefined;
275
+ getParentById: (id: string) => ComponentData | undefined;
274
276
  history: {
275
277
  back: HistorySlice["back"];
276
278
  forward: HistorySlice["forward"];
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-BqwnaCVe.js';
2
- export { ad as Adaptor, ab as ArrayField, B as ArrayState, ar as AsFieldProps, X as BaseData, a5 as BaseField, af as CacheOpts, J as ComponentConfigExtensions, T as ComponentConfigParams, a0 as ComponentDataMap, _ as ComponentDataOptionalId, a3 as ComponentMetadata, Q as ConfigParams, a1 as Content, ai as CustomField, ah as CustomFieldRender, ao as DefaultComponentProps, L as DefaultComponents, al as DefaultRootFieldProps, an as DefaultRootProps, am as DefaultRootRenderProps, o as Direction, p as DragAxis, ag as ExternalField, ae as ExternalFieldWithAdaptor, N as ExtractConfigParams, at as ExtractField, a4 as FieldMetadata, y as FieldRenderFunctions, u as FieldTransformFn, s as FieldTransformFnParams, z as ItemWithId, $ as MappedItem, a7 as NumberField, ac as ObjectField, x as OverrideKey, G as PuckComponent, ak as PuckContext, a2 as PuckMetadata, aa as RadioField, K as RootConfig, Z as RootData, Y as RootDataWithoutProps, a9 as SelectField, S as Slot, E as SlotComponent, aj as SlotField, a6 as TextField, a8 as TextareaField, q as Viewport, as as WithChildren, ap as WithId, aq as WithPuckProps, W as WithSlotProps, m as migrate, v as overrideKeys, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-BqwnaCVe.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-bsPSSmt9.js';
2
+ export { ad as Adaptor, ab as ArrayField, B as ArrayState, ar as AsFieldProps, X as BaseData, a5 as BaseField, af as CacheOpts, J as ComponentConfigExtensions, T as ComponentConfigParams, a0 as ComponentDataMap, _ as ComponentDataOptionalId, a3 as ComponentMetadata, Q as ConfigParams, a1 as Content, ai as CustomField, ah as CustomFieldRender, ao as DefaultComponentProps, L as DefaultComponents, al as DefaultRootFieldProps, an as DefaultRootProps, am as DefaultRootRenderProps, o as Direction, p as DragAxis, ag as ExternalField, ae as ExternalFieldWithAdaptor, N as ExtractConfigParams, at as ExtractField, a4 as FieldMetadata, y as FieldRenderFunctions, u as FieldTransformFn, s as FieldTransformFnParams, z as ItemWithId, $ as MappedItem, a7 as NumberField, ac as ObjectField, x as OverrideKey, G as PuckComponent, ak as PuckContext, a2 as PuckMetadata, aa as RadioField, K as RootConfig, Z as RootData, Y as RootDataWithoutProps, a9 as SelectField, S as Slot, E as SlotComponent, aj as SlotField, a6 as TextField, a8 as TextareaField, q as Viewport, as as WithChildren, ap as WithId, aq as WithPuckProps, W as WithSlotProps, m as migrate, v as overrideKeys, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-bsPSSmt9.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';
@@ -47,6 +47,7 @@ type RefreshPermissions<UserConfig extends Config = Config> = (params?: Permissi
47
47
  type Cache = Record<string, {
48
48
  lastPermissions: Partial<Permissions>;
49
49
  lastData: ComponentData | null;
50
+ lastParentId: string | null;
50
51
  }>;
51
52
  type PermissionsSlice = {
52
53
  cache: Cache;
@@ -271,6 +272,7 @@ type UsePuckData<UserConfig extends Config = Config, G extends UserGenerics<User
271
272
  getItemBySelector: (selector: ItemSelector) => G["UserComponentData"] | undefined;
272
273
  getItemById: (id: string) => G["UserComponentData"] | undefined;
273
274
  getSelectorForId: (id: string) => Required<ItemSelector> | undefined;
275
+ getParentById: (id: string) => ComponentData | undefined;
274
276
  history: {
275
277
  back: HistorySlice["back"];
276
278
  forward: HistorySlice["forward"];
package/dist/index.js CHANGED
@@ -1979,26 +1979,34 @@ var createPermissionsSlice = (set, get) => {
1979
1979
  const resolvePermissions = (..._0) => __async(null, [..._0], function* (params = {}, force) {
1980
1980
  const { state, permissions, config } = get();
1981
1981
  const { cache: cache2, globalPermissions } = permissions;
1982
- const resolveDataForItem = (item2, force2 = false) => __async(null, null, function* () {
1983
- var _a, _b, _c;
1982
+ const resolvePermissionsForItem = (item2, force2 = false) => __async(null, null, function* () {
1983
+ var _a, _b;
1984
1984
  const { config: config2, state: appState, setComponentLoading } = get();
1985
+ const itemCache = cache2[item2.props.id];
1986
+ const nodes = appState.indexes.nodes;
1987
+ const parentId = (_a = nodes[item2.props.id]) == null ? void 0 : _a.parentId;
1988
+ const parentNode = parentId ? nodes[parentId] : null;
1989
+ const parentData = (_b = parentNode == null ? void 0 : parentNode.data) != null ? _b : null;
1985
1990
  const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
1986
1991
  if (!componentConfig) {
1987
1992
  return;
1988
1993
  }
1989
1994
  const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
1990
1995
  if (componentConfig.resolvePermissions) {
1991
- const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
1992
- if (Object.values(changed).some((el) => el === true) || force2) {
1996
+ const changed = getChanged(item2, itemCache == null ? void 0 : itemCache.lastData);
1997
+ const propsChanged = Object.values(changed).some((el) => el === true);
1998
+ const parentChanged = (itemCache == null ? void 0 : itemCache.lastParentId) !== parentId;
1999
+ if (propsChanged || parentChanged || force2) {
1993
2000
  const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
1994
2001
  const resolvedPermissions = yield componentConfig.resolvePermissions(
1995
2002
  item2,
1996
2003
  {
1997
2004
  changed,
1998
- lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
2005
+ lastPermissions: (itemCache == null ? void 0 : itemCache.lastPermissions) || null,
1999
2006
  permissions: initialPermissions,
2000
2007
  appState: makeStatePublic(appState),
2001
- lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
2008
+ lastData: (itemCache == null ? void 0 : itemCache.lastData) || null,
2009
+ parent: parentData
2002
2010
  }
2003
2011
  );
2004
2012
  const latest = get().permissions;
@@ -2006,6 +2014,7 @@ var createPermissionsSlice = (set, get) => {
2006
2014
  permissions: __spreadProps(__spreadValues({}, latest), {
2007
2015
  cache: __spreadProps(__spreadValues({}, latest.cache), {
2008
2016
  [item2.props.id]: {
2017
+ lastParentId: parentId,
2009
2018
  lastData: item2,
2010
2019
  lastPermissions: resolvedPermissions
2011
2020
  }
@@ -2019,9 +2028,9 @@ var createPermissionsSlice = (set, get) => {
2019
2028
  }
2020
2029
  }
2021
2030
  });
2022
- const resolveDataForRoot = (force2 = false) => {
2031
+ const resolvePermissionsForRoot = (force2 = false) => {
2023
2032
  const { state: appState } = get();
2024
- resolveDataForItem(
2033
+ resolvePermissionsForItem(
2025
2034
  // Shim the root data in by conforming to component data shape
2026
2035
  {
2027
2036
  type: "root",
@@ -2032,16 +2041,16 @@ var createPermissionsSlice = (set, get) => {
2032
2041
  };
2033
2042
  const { item, type, root } = params;
2034
2043
  if (item) {
2035
- yield resolveDataForItem(item, force);
2044
+ yield resolvePermissionsForItem(item, force);
2036
2045
  } else if (type) {
2037
2046
  flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(null, null, function* () {
2038
- yield resolveDataForItem(item2, force);
2047
+ yield resolvePermissionsForItem(item2, force);
2039
2048
  }));
2040
2049
  } else if (root) {
2041
- resolveDataForRoot(force);
2050
+ resolvePermissionsForRoot(force);
2042
2051
  } else {
2043
2052
  flattenData(state, config).map((item2) => __async(null, null, function* () {
2044
- yield resolveDataForItem(item2, force);
2053
+ yield resolvePermissionsForItem(item2, force);
2045
2054
  }));
2046
2055
  }
2047
2056
  });
@@ -8734,7 +8743,15 @@ var generateUsePuck = (store) => {
8734
8743
  selectedItem: store.selectedItem || null,
8735
8744
  getItemBySelector: (selector) => getItem(selector, store.state),
8736
8745
  getItemById: (id) => store.state.indexes.nodes[id].data,
8737
- getSelectorForId: (id) => getSelectorForId(store.state, id)
8746
+ getSelectorForId: (id) => getSelectorForId(store.state, id),
8747
+ getParentById: (id) => {
8748
+ const node = store.state.indexes.nodes[id];
8749
+ const parentId = node.parentId;
8750
+ if (parentId === null) return;
8751
+ const parentNode = store.state.indexes.nodes[parentId];
8752
+ if (!parentNode) return;
8753
+ return parentNode.data;
8754
+ }
8738
8755
  };
8739
8756
  return storeData;
8740
8757
  };
package/dist/index.mjs CHANGED
@@ -18,7 +18,7 @@ import {
18
18
  setDeep,
19
19
  useGetPuck,
20
20
  usePuck
21
- } from "./chunk-QNMNHBNQ.mjs";
21
+ } from "./chunk-CISJM3HZ.mjs";
22
22
  import {
23
23
  init_react_import,
24
24
  migrate,
@@ -1,4 +1,4 @@
1
- export { ad as Adaptor, A as AppState, ab as ArrayField, B as ArrayState, ar as AsFieldProps, X as BaseData, a5 as BaseField, af as CacheOpts, f as ComponentConfig, J as ComponentConfigExtensions, T as ComponentConfigParams, a as ComponentData, a0 as ComponentDataMap, _ as ComponentDataOptionalId, a3 as ComponentMetadata, C as Config, Q as ConfigParams, a1 as Content, ai as CustomField, ah as CustomFieldRender, j as Data, ao as DefaultComponentProps, L as DefaultComponents, al as DefaultRootFieldProps, an as DefaultRootProps, am as DefaultRootRenderProps, o as Direction, p as DragAxis, ag as ExternalField, ae as ExternalFieldWithAdaptor, N as ExtractConfigParams, at as ExtractField, h as Field, a4 as FieldMetadata, 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, $ as MappedItem, M as Metadata, a7 as NumberField, ac as ObjectField, k as OnAction, x as OverrideKey, O as Overrides, P as Permissions, d as Plugin, b as PuckAction, G as PuckComponent, ak as PuckContext, a2 as PuckMetadata, aa as RadioField, c as ResolveDataTrigger, K as RootConfig, Z as RootData, R as RootDataWithProps, Y as RootDataWithoutProps, a9 as SelectField, S as Slot, E as SlotComponent, aj as SlotField, a6 as TextField, a8 as TextareaField, e as UiState, U as UserGenerics, q as Viewport, V as Viewports, as as WithChildren, ap as WithId, aq as WithPuckProps, W as WithSlotProps, m as migrate, v as overrideKeys, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-BqwnaCVe.mjs';
1
+ export { ad as Adaptor, A as AppState, ab as ArrayField, B as ArrayState, ar as AsFieldProps, X as BaseData, a5 as BaseField, af as CacheOpts, f as ComponentConfig, J as ComponentConfigExtensions, T as ComponentConfigParams, a as ComponentData, a0 as ComponentDataMap, _ as ComponentDataOptionalId, a3 as ComponentMetadata, C as Config, Q as ConfigParams, a1 as Content, ai as CustomField, ah as CustomFieldRender, j as Data, ao as DefaultComponentProps, L as DefaultComponents, al as DefaultRootFieldProps, an as DefaultRootProps, am as DefaultRootRenderProps, o as Direction, p as DragAxis, ag as ExternalField, ae as ExternalFieldWithAdaptor, N as ExtractConfigParams, at as ExtractField, h as Field, a4 as FieldMetadata, 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, $ as MappedItem, M as Metadata, a7 as NumberField, ac as ObjectField, k as OnAction, x as OverrideKey, O as Overrides, P as Permissions, d as Plugin, b as PuckAction, G as PuckComponent, ak as PuckContext, a2 as PuckMetadata, aa as RadioField, c as ResolveDataTrigger, K as RootConfig, Z as RootData, R as RootDataWithProps, Y as RootDataWithoutProps, a9 as SelectField, S as Slot, E as SlotComponent, aj as SlotField, a6 as TextField, a8 as TextareaField, e as UiState, U as UserGenerics, q as Viewport, V as Viewports, as as WithChildren, ap as WithId, aq as WithPuckProps, W as WithSlotProps, m as migrate, v as overrideKeys, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-bsPSSmt9.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 { ad as Adaptor, A as AppState, ab as ArrayField, B as ArrayState, ar as AsFieldProps, X as BaseData, a5 as BaseField, af as CacheOpts, f as ComponentConfig, J as ComponentConfigExtensions, T as ComponentConfigParams, a as ComponentData, a0 as ComponentDataMap, _ as ComponentDataOptionalId, a3 as ComponentMetadata, C as Config, Q as ConfigParams, a1 as Content, ai as CustomField, ah as CustomFieldRender, j as Data, ao as DefaultComponentProps, L as DefaultComponents, al as DefaultRootFieldProps, an as DefaultRootProps, am as DefaultRootRenderProps, o as Direction, p as DragAxis, ag as ExternalField, ae as ExternalFieldWithAdaptor, N as ExtractConfigParams, at as ExtractField, h as Field, a4 as FieldMetadata, 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, $ as MappedItem, M as Metadata, a7 as NumberField, ac as ObjectField, k as OnAction, x as OverrideKey, O as Overrides, P as Permissions, d as Plugin, b as PuckAction, G as PuckComponent, ak as PuckContext, a2 as PuckMetadata, aa as RadioField, c as ResolveDataTrigger, K as RootConfig, Z as RootData, R as RootDataWithProps, Y as RootDataWithoutProps, a9 as SelectField, S as Slot, E as SlotComponent, aj as SlotField, a6 as TextField, a8 as TextareaField, e as UiState, U as UserGenerics, q as Viewport, V as Viewports, as as WithChildren, ap as WithId, aq as WithPuckProps, W as WithSlotProps, m as migrate, v as overrideKeys, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-BqwnaCVe.js';
1
+ export { ad as Adaptor, A as AppState, ab as ArrayField, B as ArrayState, ar as AsFieldProps, X as BaseData, a5 as BaseField, af as CacheOpts, f as ComponentConfig, J as ComponentConfigExtensions, T as ComponentConfigParams, a as ComponentData, a0 as ComponentDataMap, _ as ComponentDataOptionalId, a3 as ComponentMetadata, C as Config, Q as ConfigParams, a1 as Content, ai as CustomField, ah as CustomFieldRender, j as Data, ao as DefaultComponentProps, L as DefaultComponents, al as DefaultRootFieldProps, an as DefaultRootProps, am as DefaultRootRenderProps, o as Direction, p as DragAxis, ag as ExternalField, ae as ExternalFieldWithAdaptor, N as ExtractConfigParams, at as ExtractField, h as Field, a4 as FieldMetadata, 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, $ as MappedItem, M as Metadata, a7 as NumberField, ac as ObjectField, k as OnAction, x as OverrideKey, O as Overrides, P as Permissions, d as Plugin, b as PuckAction, G as PuckComponent, ak as PuckContext, a2 as PuckMetadata, aa as RadioField, c as ResolveDataTrigger, K as RootConfig, Z as RootData, R as RootDataWithProps, Y as RootDataWithoutProps, a9 as SelectField, S as Slot, E as SlotComponent, aj as SlotField, a6 as TextField, a8 as TextareaField, e as UiState, U as UserGenerics, q as Viewport, V as Viewports, as as WithChildren, ap as WithId, aq as WithPuckProps, W as WithSlotProps, m as migrate, v as overrideKeys, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-bsPSSmt9.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';
@@ -1979,26 +1979,34 @@ var createPermissionsSlice = (set, get) => {
1979
1979
  const resolvePermissions = (..._0) => __async(null, [..._0], function* (params = {}, force) {
1980
1980
  const { state, permissions, config } = get();
1981
1981
  const { cache: cache2, globalPermissions } = permissions;
1982
- const resolveDataForItem = (item2, force2 = false) => __async(null, null, function* () {
1983
- var _a, _b, _c;
1982
+ const resolvePermissionsForItem = (item2, force2 = false) => __async(null, null, function* () {
1983
+ var _a, _b;
1984
1984
  const { config: config2, state: appState, setComponentLoading } = get();
1985
+ const itemCache = cache2[item2.props.id];
1986
+ const nodes = appState.indexes.nodes;
1987
+ const parentId = (_a = nodes[item2.props.id]) == null ? void 0 : _a.parentId;
1988
+ const parentNode = parentId ? nodes[parentId] : null;
1989
+ const parentData = (_b = parentNode == null ? void 0 : parentNode.data) != null ? _b : null;
1985
1990
  const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
1986
1991
  if (!componentConfig) {
1987
1992
  return;
1988
1993
  }
1989
1994
  const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
1990
1995
  if (componentConfig.resolvePermissions) {
1991
- const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
1992
- if (Object.values(changed).some((el) => el === true) || force2) {
1996
+ const changed = getChanged(item2, itemCache == null ? void 0 : itemCache.lastData);
1997
+ const propsChanged = Object.values(changed).some((el) => el === true);
1998
+ const parentChanged = (itemCache == null ? void 0 : itemCache.lastParentId) !== parentId;
1999
+ if (propsChanged || parentChanged || force2) {
1993
2000
  const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
1994
2001
  const resolvedPermissions = yield componentConfig.resolvePermissions(
1995
2002
  item2,
1996
2003
  {
1997
2004
  changed,
1998
- lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
2005
+ lastPermissions: (itemCache == null ? void 0 : itemCache.lastPermissions) || null,
1999
2006
  permissions: initialPermissions,
2000
2007
  appState: makeStatePublic(appState),
2001
- lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
2008
+ lastData: (itemCache == null ? void 0 : itemCache.lastData) || null,
2009
+ parent: parentData
2002
2010
  }
2003
2011
  );
2004
2012
  const latest = get().permissions;
@@ -2006,6 +2014,7 @@ var createPermissionsSlice = (set, get) => {
2006
2014
  permissions: __spreadProps(__spreadValues({}, latest), {
2007
2015
  cache: __spreadProps(__spreadValues({}, latest.cache), {
2008
2016
  [item2.props.id]: {
2017
+ lastParentId: parentId,
2009
2018
  lastData: item2,
2010
2019
  lastPermissions: resolvedPermissions
2011
2020
  }
@@ -2019,9 +2028,9 @@ var createPermissionsSlice = (set, get) => {
2019
2028
  }
2020
2029
  }
2021
2030
  });
2022
- const resolveDataForRoot = (force2 = false) => {
2031
+ const resolvePermissionsForRoot = (force2 = false) => {
2023
2032
  const { state: appState } = get();
2024
- resolveDataForItem(
2033
+ resolvePermissionsForItem(
2025
2034
  // Shim the root data in by conforming to component data shape
2026
2035
  {
2027
2036
  type: "root",
@@ -2032,16 +2041,16 @@ var createPermissionsSlice = (set, get) => {
2032
2041
  };
2033
2042
  const { item, type, root } = params;
2034
2043
  if (item) {
2035
- yield resolveDataForItem(item, force);
2044
+ yield resolvePermissionsForItem(item, force);
2036
2045
  } else if (type) {
2037
2046
  flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(null, null, function* () {
2038
- yield resolveDataForItem(item2, force);
2047
+ yield resolvePermissionsForItem(item2, force);
2039
2048
  }));
2040
2049
  } else if (root) {
2041
- resolveDataForRoot(force);
2050
+ resolvePermissionsForRoot(force);
2042
2051
  } else {
2043
2052
  flattenData(state, config).map((item2) => __async(null, null, function* () {
2044
- yield resolveDataForItem(item2, force);
2053
+ yield resolvePermissionsForItem(item2, force);
2045
2054
  }));
2046
2055
  }
2047
2056
  });
@@ -8734,7 +8743,15 @@ var generateUsePuck = (store) => {
8734
8743
  selectedItem: store.selectedItem || null,
8735
8744
  getItemBySelector: (selector) => getItem(selector, store.state),
8736
8745
  getItemById: (id) => store.state.indexes.nodes[id].data,
8737
- getSelectorForId: (id) => getSelectorForId(store.state, id)
8746
+ getSelectorForId: (id) => getSelectorForId(store.state, id),
8747
+ getParentById: (id) => {
8748
+ const node = store.state.indexes.nodes[id];
8749
+ const parentId = node.parentId;
8750
+ if (parentId === null) return;
8751
+ const parentNode = store.state.indexes.nodes[parentId];
8752
+ if (!parentNode) return;
8753
+ return parentNode.data;
8754
+ }
8738
8755
  };
8739
8756
  return storeData;
8740
8757
  };
@@ -18,7 +18,7 @@ import {
18
18
  setDeep,
19
19
  useGetPuck,
20
20
  usePuck
21
- } from "./chunk-QNMNHBNQ.mjs";
21
+ } from "./chunk-CISJM3HZ.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-BqwnaCVe.mjs';
3
- export { m as migrate, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-BqwnaCVe.mjs';
2
+ import { C as Config, U as UserGenerics, M as Metadata } from './walk-tree-bsPSSmt9.mjs';
3
+ export { m as migrate, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-bsPSSmt9.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-BqwnaCVe.js';
3
- export { m as migrate, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-BqwnaCVe.js';
2
+ import { C as Config, U as UserGenerics, M as Metadata } from './walk-tree-bsPSSmt9.js';
3
+ export { m as migrate, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-bsPSSmt9.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, }: {
@@ -1,4 +1,4 @@
1
- import { ReactElement, CSSProperties, ElementType, ReactNode, JSX } from 'react';
1
+ import { ReactElement, ReactNode, CSSProperties, ElementType, JSX } from 'react';
2
2
 
3
3
  type ItemSelector = {
4
4
  index: number;
@@ -53,7 +53,7 @@ interface ArrayField<Props extends {
53
53
  } ? Field<Props[0][SubPropName], UserField> | UserField : Field<Props[0][SubPropName], UserField>;
54
54
  };
55
55
  defaultItemProps?: Props[0] | ((index: number) => Props[0]);
56
- getItemSummary?: (item: Props[0], index?: number) => string;
56
+ getItemSummary?: (item: Props[0], index?: number) => ReactNode;
57
57
  max?: number;
58
58
  min?: number;
59
59
  }
@@ -80,7 +80,7 @@ type ExternalFieldWithAdaptor<Props extends any = {
80
80
  placeholder?: string;
81
81
  adaptor: Adaptor<any, any, Props>;
82
82
  adaptorParams?: object;
83
- getItemSummary: (item: NotUndefined<Props>, index?: number) => string;
83
+ getItemSummary: (item: NotUndefined<Props>, index?: number) => ReactNode;
84
84
  };
85
85
  type CacheOpts = {
86
86
  enabled?: boolean;
@@ -97,7 +97,7 @@ interface ExternalField<Props extends any = {
97
97
  }) => Promise<any[] | null>;
98
98
  mapProp?: (value: any) => Props;
99
99
  mapRow?: (value: any) => Record<string, string | number | ReactElement>;
100
- getItemSummary?: (item: NotUndefined<Props>, index?: number) => string;
100
+ getItemSummary?: (item: NotUndefined<Props>, index?: number) => ReactNode;
101
101
  showSearch?: boolean;
102
102
  renderFooter?: (props: {
103
103
  items: any[];
@@ -240,6 +240,7 @@ UserField extends BaseField = {}> = {
240
240
  permissions: Partial<Permissions>;
241
241
  appState: AppState;
242
242
  lastData: DataShape | null;
243
+ parent: ComponentData | null;
243
244
  }) => Promise<Partial<Permissions>> | Partial<Permissions>;
244
245
  metadata?: ComponentMetadata;
245
246
  } & ComponentConfigExtensions;
@@ -1,4 +1,4 @@
1
- import { ReactElement, CSSProperties, ElementType, ReactNode, JSX } from 'react';
1
+ import { ReactElement, ReactNode, CSSProperties, ElementType, JSX } from 'react';
2
2
 
3
3
  type ItemSelector = {
4
4
  index: number;
@@ -53,7 +53,7 @@ interface ArrayField<Props extends {
53
53
  } ? Field<Props[0][SubPropName], UserField> | UserField : Field<Props[0][SubPropName], UserField>;
54
54
  };
55
55
  defaultItemProps?: Props[0] | ((index: number) => Props[0]);
56
- getItemSummary?: (item: Props[0], index?: number) => string;
56
+ getItemSummary?: (item: Props[0], index?: number) => ReactNode;
57
57
  max?: number;
58
58
  min?: number;
59
59
  }
@@ -80,7 +80,7 @@ type ExternalFieldWithAdaptor<Props extends any = {
80
80
  placeholder?: string;
81
81
  adaptor: Adaptor<any, any, Props>;
82
82
  adaptorParams?: object;
83
- getItemSummary: (item: NotUndefined<Props>, index?: number) => string;
83
+ getItemSummary: (item: NotUndefined<Props>, index?: number) => ReactNode;
84
84
  };
85
85
  type CacheOpts = {
86
86
  enabled?: boolean;
@@ -97,7 +97,7 @@ interface ExternalField<Props extends any = {
97
97
  }) => Promise<any[] | null>;
98
98
  mapProp?: (value: any) => Props;
99
99
  mapRow?: (value: any) => Record<string, string | number | ReactElement>;
100
- getItemSummary?: (item: NotUndefined<Props>, index?: number) => string;
100
+ getItemSummary?: (item: NotUndefined<Props>, index?: number) => ReactNode;
101
101
  showSearch?: boolean;
102
102
  renderFooter?: (props: {
103
103
  items: any[];
@@ -240,6 +240,7 @@ UserField extends BaseField = {}> = {
240
240
  permissions: Partial<Permissions>;
241
241
  appState: AppState;
242
242
  lastData: DataShape | null;
243
+ parent: ComponentData | null;
243
244
  }) => Promise<Partial<Permissions>> | Partial<Permissions>;
244
245
  metadata?: ComponentMetadata;
245
246
  } & ComponentConfigExtensions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@measured/puck",
3
- "version": "0.21.0-canary.304940ae",
3
+ "version": "0.21.0-canary.38e79ba8",
4
4
  "description": "The open-source visual editor for React",
5
5
  "author": "Chris Villa <chris@puckeditor.com>",
6
6
  "repository": "measuredco/puck",