@measured/puck 0.16.0-canary.cad95b8 → 0.16.0-canary.df1366f

Sign up to get free protection for your applications and to get access to all the features.
@@ -184,6 +184,12 @@ type ComponentConfig<ComponentProps extends DefaultComponentProps = DefaultCompo
184
184
  props?: Partial<ComponentProps>;
185
185
  readOnly?: Partial<Record<keyof ComponentProps, boolean>>;
186
186
  };
187
+ resolvePermissions?: (data: DataShape, params: {
188
+ changed: Partial<Record<keyof ComponentProps, boolean>>;
189
+ lastPermissions: Partial<Permissions> | undefined;
190
+ initialPermissions: Partial<Permissions>;
191
+ appState: AppState;
192
+ }) => Partial<Permissions>;
187
193
  };
188
194
  type Category<ComponentName> = {
189
195
  components?: ComponentName[];
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { U as UiState, D as Data, A as AppState, I as ItemSelector, F as Field, a as FieldProps, C as Config, b as DropZoneProps, P as Permissions, V as Viewports, c as DefaultComponentProps, d as DefaultRootProps, M as MappedItem, R as RootData, e as RootDataWithProps, f as ComponentData } from './Config-DCrYvDkL.js';
2
- export { r as Adaptor, q as ArrayField, m as ArrayState, B as BaseData, n as BaseField, j as ComponentConfig, g as Content, t as CustomField, s as ExternalField, E as ExternalFieldWithAdaptor, u as Fields, l as ItemWithId, N as NumberField, O as ObjectField, h as PuckComponent, i as PuckContext, p as RadioField, k as RootDataWithoutProps, S as SelectField, T as TextField, o as TextareaField } from './Config-DCrYvDkL.js';
1
+ import { U as UiState, D as Data, A as AppState, I as ItemSelector, F as Field, a as FieldProps, C as Config, b as DropZoneProps, P as Permissions, V as Viewports, c as DefaultComponentProps, d as DefaultRootProps, M as MappedItem, R as RootData, e as RootDataWithProps, f as ComponentData } from './Config-CkVFT1_w.js';
2
+ export { r as Adaptor, q as ArrayField, m as ArrayState, B as BaseData, n as BaseField, j as ComponentConfig, g as Content, t as CustomField, s as ExternalField, E as ExternalFieldWithAdaptor, u as Fields, l as ItemWithId, N as NumberField, O as ObjectField, h as PuckComponent, i as PuckContext, p as RadioField, k as RootDataWithoutProps, S as SelectField, T as TextField, o as TextareaField } from './Config-CkVFT1_w.js';
3
3
  import * as react from 'react';
4
4
  import { ReactNode, ReactElement, SyntheticEvent, CSSProperties } from 'react';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
@@ -107,6 +107,10 @@ type Overrides = OverridesGeneric<{
107
107
  children: ReactNode;
108
108
  name: string;
109
109
  }>;
110
+ iframe: RenderFunc<{
111
+ children: ReactNode;
112
+ document?: Document;
113
+ }>;
110
114
  outline: RenderFunc;
111
115
  puck: RenderFunc;
112
116
  }>;
package/dist/index.js CHANGED
@@ -30539,18 +30539,77 @@ var useLoadedOverrides = ({
30539
30539
 
30540
30540
  // lib/get-permissions.ts
30541
30541
  init_react_import();
30542
+
30543
+ // lib/get-changed.ts
30544
+ init_react_import();
30545
+ var getChanged = (newItem, oldItem) => {
30546
+ return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
30547
+ const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
30548
+ const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
30549
+ return __spreadProps(__spreadValues({}, acc), {
30550
+ [item]: oldItemProps[item] !== newItemProps[item]
30551
+ });
30552
+ }, {}) : {};
30553
+ };
30554
+
30555
+ // lib/resolve-permissions.ts
30556
+ init_react_import();
30557
+ var resolvePermissions = ({
30558
+ selectedItem,
30559
+ config,
30560
+ changed,
30561
+ lastPermissions,
30562
+ initialPermissions,
30563
+ appState
30564
+ }) => {
30565
+ const componentConfig = selectedItem ? config.components[selectedItem.type] : null;
30566
+ if (selectedItem && (componentConfig == null ? void 0 : componentConfig.resolvePermissions)) {
30567
+ return componentConfig.resolvePermissions(selectedItem, {
30568
+ changed,
30569
+ lastPermissions,
30570
+ initialPermissions,
30571
+ appState
30572
+ });
30573
+ }
30574
+ return {};
30575
+ };
30576
+
30577
+ // lib/get-permissions.ts
30578
+ var cache = { lastPermissions: {}, lastSelected: {} };
30542
30579
  var getPermissions = ({
30543
30580
  selectedItem,
30544
30581
  type,
30545
30582
  globalPermissions,
30546
- config
30583
+ config,
30584
+ appState
30547
30585
  }) => {
30548
30586
  const componentType = type || selectedItem && selectedItem.type || "";
30587
+ const componentId = selectedItem && selectedItem.props.id || "";
30549
30588
  let componentPermissions = getInitialPermissions({
30550
30589
  componentType,
30551
30590
  config,
30552
30591
  globalPermissions
30553
30592
  });
30593
+ const changed = getChanged(selectedItem, cache.lastSelected);
30594
+ if (Object.values(changed).some((el) => el === true)) {
30595
+ const resolvedPermissions = resolvePermissions({
30596
+ selectedItem,
30597
+ config,
30598
+ changed,
30599
+ lastPermissions: cache.lastPermissions[componentId] || componentPermissions,
30600
+ initialPermissions: componentPermissions,
30601
+ appState
30602
+ });
30603
+ if (resolvedPermissions !== void 0) {
30604
+ componentPermissions = __spreadValues(__spreadValues({}, componentPermissions), resolvedPermissions);
30605
+ }
30606
+ cache.lastSelected = selectedItem;
30607
+ cache.lastPermissions[componentId] = componentPermissions;
30608
+ return componentPermissions;
30609
+ }
30610
+ if (Object.keys(componentId && cache.lastPermissions[componentId]).length !== 0) {
30611
+ componentPermissions = cache.lastPermissions[componentId];
30612
+ }
30554
30613
  return componentPermissions;
30555
30614
  };
30556
30615
  var getInitialPermissions = ({
@@ -30602,7 +30661,8 @@ var DraggableComponent = ({
30602
30661
  plugins,
30603
30662
  selectedItem,
30604
30663
  config,
30605
- globalPermissions
30664
+ globalPermissions,
30665
+ state
30606
30666
  } = useAppContext();
30607
30667
  const isModifierHeld = useModifierHeld("Alt");
30608
30668
  const El = status !== "LOADING" ? import_dnd4.Draggable : DefaultDraggable;
@@ -30624,7 +30684,8 @@ var DraggableComponent = ({
30624
30684
  const permissions = selectedItem && getPermissions({
30625
30685
  selectedItem,
30626
30686
  globalPermissions: globalPermissions || {},
30627
- config
30687
+ config,
30688
+ appState: state
30628
30689
  });
30629
30690
  return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
30630
30691
  El,
@@ -30979,7 +31040,8 @@ function DropZoneEdit({ zone, allow, disallow, style }) {
30979
31040
  appContext2.state.data
30980
31041
  ),
30981
31042
  config: appContext2.config,
30982
- globalPermissions: appContext2.globalPermissions || {}
31043
+ globalPermissions: appContext2.globalPermissions || {},
31044
+ appState: appContext2.state
30983
31045
  }).drag;
30984
31046
  return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
30985
31047
  "div",
@@ -31689,21 +31751,7 @@ var import_react20 = require("react");
31689
31751
 
31690
31752
  // lib/resolve-component-data.ts
31691
31753
  init_react_import();
31692
-
31693
- // lib/get-changed.ts
31694
- init_react_import();
31695
- var getChanged = (newItem, oldItem) => {
31696
- return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
31697
- const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
31698
- const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
31699
- return __spreadProps(__spreadValues({}, acc), {
31700
- [item]: oldItemProps[item] !== newItemProps[item]
31701
- });
31702
- }, {}) : {};
31703
- };
31704
-
31705
- // lib/resolve-component-data.ts
31706
- var cache = { lastChange: {} };
31754
+ var cache2 = { lastChange: {} };
31707
31755
  var resolveAllComponentData = (content, config, onResolveStart, onResolveEnd) => __async(void 0, null, function* () {
31708
31756
  return yield Promise.all(
31709
31757
  content.map((item) => __async(void 0, null, function* () {
@@ -31719,7 +31767,7 @@ var resolveAllComponentData = (content, config, onResolveStart, onResolveEnd) =>
31719
31767
  var resolveComponentData = (item, config, onResolveStart, onResolveEnd) => __async(void 0, null, function* () {
31720
31768
  const configForItem = config.components[item.type];
31721
31769
  if (configForItem.resolveData) {
31722
- const { item: oldItem = {}, resolved = {} } = cache.lastChange[item.props.id] || {};
31770
+ const { item: oldItem = {}, resolved = {} } = cache2.lastChange[item.props.id] || {};
31723
31771
  if (item && item === oldItem) {
31724
31772
  return resolved;
31725
31773
  }
@@ -31736,7 +31784,7 @@ var resolveComponentData = (item, config, onResolveStart, onResolveEnd) => __asy
31736
31784
  if (Object.keys(newReadOnly).length) {
31737
31785
  resolvedItem.readOnly = newReadOnly;
31738
31786
  }
31739
- cache.lastChange[item.props.id] = {
31787
+ cache2.lastChange[item.props.id] = {
31740
31788
  item,
31741
31789
  resolved: resolvedItem
31742
31790
  };
@@ -31768,20 +31816,20 @@ var applyDynamicProps = (data, dynamicProps, rootData) => {
31768
31816
 
31769
31817
  // lib/resolve-root-data.ts
31770
31818
  init_react_import();
31771
- var cache2 = {};
31819
+ var cache3 = {};
31772
31820
  var resolveRootData = (data, config) => __async(void 0, null, function* () {
31773
31821
  var _a, _b, _c, _d, _e;
31774
31822
  if (((_a = config.root) == null ? void 0 : _a.resolveData) && data.root.props) {
31775
- if (((_b = cache2.lastChange) == null ? void 0 : _b.original) === data.root) {
31776
- return cache2.lastChange.resolved;
31823
+ if (((_b = cache3.lastChange) == null ? void 0 : _b.original) === data.root) {
31824
+ return cache3.lastChange.resolved;
31777
31825
  }
31778
- const changed = getChanged(data.root, (_c = cache2.lastChange) == null ? void 0 : _c.original);
31826
+ const changed = getChanged(data.root, (_c = cache3.lastChange) == null ? void 0 : _c.original);
31779
31827
  const rootWithProps = data.root;
31780
31828
  const resolvedRoot = yield (_e = config.root) == null ? void 0 : _e.resolveData(rootWithProps, {
31781
31829
  changed,
31782
- lastData: ((_d = cache2.lastChange) == null ? void 0 : _d.original) || {}
31830
+ lastData: ((_d = cache3.lastChange) == null ? void 0 : _d.original) || {}
31783
31831
  });
31784
- cache2.lastChange = {
31832
+ cache3.lastChange = {
31785
31833
  original: data.root,
31786
31834
  resolved: resolvedRoot
31787
31835
  };
@@ -32116,7 +32164,8 @@ var Fields = () => {
32116
32164
  const { edit } = getPermissions({
32117
32165
  selectedItem,
32118
32166
  config,
32119
- globalPermissions: globalPermissions || {}
32167
+ globalPermissions: globalPermissions || {},
32168
+ appState: state
32120
32169
  });
32121
32170
  return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
32122
32171
  AutoFieldPrivate,
@@ -32174,11 +32223,12 @@ var ComponentListItem = ({
32174
32223
  label,
32175
32224
  index
32176
32225
  }) => {
32177
- const { overrides, config, globalPermissions } = useAppContext();
32226
+ const { overrides, config, globalPermissions, state } = useAppContext();
32178
32227
  const canInsert = getPermissions({
32179
32228
  type: name,
32180
32229
  config,
32181
- globalPermissions: globalPermissions || {}
32230
+ globalPermissions: globalPermissions || {},
32231
+ appState: state
32182
32232
  }).insert;
32183
32233
  return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
32184
32234
  Drawer.Item,
@@ -32540,10 +32590,11 @@ init_react_import();
32540
32590
  var styles_module_default18 = { "PuckPreview": "_PuckPreview_rxwlr_1", "PuckPreview-frame": "_PuckPreview-frame_rxwlr_5" };
32541
32591
 
32542
32592
  // components/Puck/components/Preview/index.tsx
32593
+ var import_react_frame_component2 = require("react-frame-component");
32543
32594
  var import_jsx_runtime33 = require("react/jsx-runtime");
32544
32595
  var getClassName23 = get_class_name_factory_default("PuckPreview", styles_module_default18);
32545
32596
  var Preview = ({ id = "puck-preview" }) => {
32546
- const { config, dispatch, state, setStatus, iframe } = useAppContext();
32597
+ const { config, dispatch, state, setStatus, iframe, overrides } = useAppContext();
32547
32598
  const Page = (0, import_react25.useCallback)(
32548
32599
  (pageProps) => {
32549
32600
  var _a, _b;
@@ -32557,6 +32608,7 @@ var Preview = ({ id = "puck-preview" }) => {
32557
32608
  },
32558
32609
  [config.root]
32559
32610
  );
32611
+ const Frame2 = (0, import_react25.useMemo)(() => overrides.iframe || "div", [overrides]);
32560
32612
  const rootProps = state.data.root.props || state.data.root;
32561
32613
  const ref = (0, import_react25.useRef)(null);
32562
32614
  return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
@@ -32577,7 +32629,9 @@ var Preview = ({ id = "puck-preview" }) => {
32577
32629
  onStylesLoaded: () => {
32578
32630
  setStatus("READY");
32579
32631
  },
32580
- children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Page, __spreadProps(__spreadValues({ dispatch, state }, rootProps), { children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(DropZone, { zone: rootDroppableId }) }))
32632
+ children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_react_frame_component2.FrameContextConsumer, { children: ({ document: document2 }) => {
32633
+ return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Frame2, { document: document2, children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Page, __spreadProps(__spreadValues({ dispatch, state }, rootProps), { children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(DropZone, { zone: rootDroppableId }) })) });
32634
+ } })
32581
32635
  }
32582
32636
  ) : /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("div", { id: "preview-frame", className: getClassName23("frame"), children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Page, __spreadProps(__spreadValues({ dispatch, state }, rootProps), { children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(DropZone, { zone: rootDroppableId }) })) })
32583
32637
  }
@@ -33953,7 +34007,8 @@ var usePuck = () => {
33953
34007
  selectedItem: item || currentItem,
33954
34008
  type,
33955
34009
  globalPermissions: globalPermissions || {},
33956
- config
34010
+ config,
34011
+ appState
33957
34012
  });
33958
34013
  },
33959
34014
  history: {
package/dist/rsc.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { C as Config, D as Data } from './Config-DCrYvDkL.js';
2
+ import { C as Config, D as Data } from './Config-CkVFT1_w.js';
3
3
  import 'react';
4
4
 
5
5
  declare function Render<UserConfig extends Config = Config>({ config, data, }: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@measured/puck",
3
- "version": "0.16.0-canary.cad95b8",
3
+ "version": "0.16.0-canary.df1366f",
4
4
  "author": "Measured Corporation Ltd <hello@measured.co>",
5
5
  "repository": "measuredco/puck",
6
6
  "bugs": "https://github.com/measuredco/puck/issues",