@measured/puck 0.16.0-canary.60fe631 → 0.16.0-canary.6386bd1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -207,6 +207,8 @@ type HistoryStore<D = any> = {
207
207
  setHistoryIndex: (index: number) => void;
208
208
  };
209
209
 
210
+ type OnAction = (action: PuckAction, appState: AppState, prevAppState: AppState) => void;
211
+
210
212
  type PathData = Record<string, {
211
213
  path: string[];
212
214
  label: string;
@@ -263,13 +265,14 @@ type IframeConfig = {
263
265
  enabled?: boolean;
264
266
  };
265
267
 
266
- declare function Puck<UserConfig extends Config = Config>({ children, config, data: initialData, ui: initialUi, onChange, onPublish, plugins, overrides, renderHeader, renderHeaderActions, headerTitle, headerPath, viewports, iframe, dnd, initialHistory, }: {
268
+ declare function Puck<UserConfig extends Config = Config>({ children, config, data: initialData, ui: initialUi, onChange, onPublish, onAction, plugins, overrides, renderHeader, renderHeaderActions, headerTitle, headerPath, viewports, iframe, dnd, initialHistory, }: {
267
269
  children?: ReactNode;
268
270
  config: UserConfig;
269
271
  data: Partial<Data>;
270
272
  ui?: Partial<UiState>;
271
273
  onChange?: (data: Data) => void;
272
274
  onPublish?: (data: Data) => void;
275
+ onAction?: OnAction;
273
276
  plugins?: Plugin[];
274
277
  overrides?: Partial<Overrides>;
275
278
  renderHeader?: (props: {
package/dist/index.js CHANGED
@@ -31473,7 +31473,7 @@ var reduceUi = (ui, action) => {
31473
31473
  init_react_import();
31474
31474
 
31475
31475
  // reducer/index.ts
31476
- var storeInterceptor = (reducer, record) => {
31476
+ var storeInterceptor = (reducer, record, onAction) => {
31477
31477
  return (state, action) => {
31478
31478
  const newAppState = reducer(state, action);
31479
31479
  const isValidType = ![
@@ -31486,6 +31486,7 @@ var storeInterceptor = (reducer, record) => {
31486
31486
  if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
31487
31487
  if (record) record(newAppState);
31488
31488
  }
31489
+ onAction == null ? void 0 : onAction(action, newAppState, state);
31489
31490
  return newAppState;
31490
31491
  };
31491
31492
  };
@@ -31497,16 +31498,21 @@ var setAction = (state, action) => {
31497
31498
  };
31498
31499
  function createReducer({
31499
31500
  config,
31500
- record
31501
+ record,
31502
+ onAction
31501
31503
  }) {
31502
- return storeInterceptor((state, action) => {
31503
- const data = reduceData(state.data, action, config);
31504
- const ui = reduceUi(state.ui, action);
31505
- if (action.type === "set") {
31506
- return setAction(state, action);
31507
- }
31508
- return { data, ui };
31509
- }, record);
31504
+ return storeInterceptor(
31505
+ (state, action) => {
31506
+ const data = reduceData(state.data, action, config);
31507
+ const ui = reduceUi(state.ui, action);
31508
+ if (action.type === "set") {
31509
+ return setAction(state, action);
31510
+ }
31511
+ return { data, ui };
31512
+ },
31513
+ record,
31514
+ onAction
31515
+ );
31510
31516
  }
31511
31517
 
31512
31518
  // lib/flush-zones.ts
@@ -31767,20 +31773,8 @@ var MenuBar = ({
31767
31773
  },
31768
31774
  children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: getClassName19("inner"), children: [
31769
31775
  /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: getClassName19("history"), children: [
31770
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(IconButton, { title: "undo", disabled: !hasPast, onClick: back, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
31771
- Undo2,
31772
- {
31773
- size: 21,
31774
- stroke: hasPast ? "var(--puck-color-black)" : "var(--puck-color-grey-08)"
31775
- }
31776
- ) }),
31777
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(IconButton, { title: "redo", disabled: !hasFuture, onClick: forward, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
31778
- Redo2,
31779
- {
31780
- size: 21,
31781
- stroke: hasFuture ? "var(--puck-color-black)" : "var(--puck-color-grey-08)"
31782
- }
31783
- ) })
31776
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(IconButton, { title: "undo", disabled: !hasPast, onClick: back, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Undo2, { size: 21 }) }),
31777
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(IconButton, { title: "redo", disabled: !hasFuture, onClick: forward, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Redo2, { size: 21 }) })
31784
31778
  ] }),
31785
31779
  /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_jsx_runtime25.Fragment, { children: renderHeaderActions && renderHeaderActions({
31786
31780
  state: appState,
@@ -33208,6 +33202,7 @@ function Puck({
33208
33202
  ui: initialUi,
33209
33203
  onChange,
33210
33204
  onPublish,
33205
+ onAction,
33211
33206
  plugins = [],
33212
33207
  overrides = {},
33213
33208
  renderHeader,
@@ -33224,7 +33219,7 @@ function Puck({
33224
33219
  var _a;
33225
33220
  const historyStore = useHistoryStore(initialHistory);
33226
33221
  const [reducer] = (0, import_react30.useState)(
33227
- () => createReducer({ config, record: historyStore.record })
33222
+ () => createReducer({ config, record: historyStore.record, onAction })
33228
33223
  );
33229
33224
  const [initialAppState] = (0, import_react30.useState)(() => {
33230
33225
  var _a2, _b, _c, _d, _e, _f, _g;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@measured/puck",
3
- "version": "0.16.0-canary.60fe631",
3
+ "version": "0.16.0-canary.6386bd1",
4
4
  "author": "Measured Corporation Ltd <hello@measured.co>",
5
5
  "repository": "measuredco/puck",
6
6
  "bugs": "https://github.com/measuredco/puck/issues",