@measured/puck-plugin-heading-analyzer 0.16.0-canary.60fe631 → 0.16.0-canary.7c79787

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/dist/index.js +84 -60
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -74977,34 +74977,37 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
74977
74977
  })
74978
74978
  });
74979
74979
  };
74980
- var reduceData = (data, action, config) => {
74981
- if (action.type === "insert") {
74982
- const emptyComponentData = {
74983
- type: action.componentType,
74984
- props: __spreadProps2(__spreadValues2({}, config.components[action.componentType].defaultProps || {}), {
74985
- id: generateId(action.componentType)
74986
- })
74987
- };
74988
- if (action.destinationZone === rootDroppableId2) {
74989
- return __spreadProps2(__spreadValues2({}, data), {
74990
- content: insert(
74991
- data.content,
74992
- action.destinationIndex,
74993
- emptyComponentData
74994
- )
74995
- });
74996
- }
74997
- const newData = setupZone2(data, action.destinationZone);
74980
+ var insertAction = (data, action, config) => {
74981
+ const emptyComponentData = {
74982
+ type: action.componentType,
74983
+ props: __spreadProps2(__spreadValues2({}, config.components[action.componentType].defaultProps || {}), {
74984
+ id: action.id || generateId(action.componentType)
74985
+ })
74986
+ };
74987
+ if (action.destinationZone === rootDroppableId2) {
74998
74988
  return __spreadProps2(__spreadValues2({}, data), {
74999
- zones: __spreadProps2(__spreadValues2({}, newData.zones), {
75000
- [action.destinationZone]: insert(
75001
- newData.zones[action.destinationZone],
75002
- action.destinationIndex,
75003
- emptyComponentData
75004
- )
75005
- })
74989
+ content: insert(
74990
+ data.content,
74991
+ action.destinationIndex,
74992
+ emptyComponentData
74993
+ )
75006
74994
  });
75007
74995
  }
74996
+ const newData = setupZone2(data, action.destinationZone);
74997
+ return __spreadProps2(__spreadValues2({}, data), {
74998
+ zones: __spreadProps2(__spreadValues2({}, newData.zones), {
74999
+ [action.destinationZone]: insert(
75000
+ newData.zones[action.destinationZone],
75001
+ action.destinationIndex,
75002
+ emptyComponentData
75003
+ )
75004
+ })
75005
+ });
75006
+ };
75007
+ var reduceData = (data, action, config) => {
75008
+ if (action.type === "insert") {
75009
+ return insertAction(data, action, config);
75010
+ }
75008
75011
  if (action.type === "duplicate") {
75009
75012
  const item = getItem2(
75010
75013
  { index: action.sourceIndex, zone: action.sourceZone },
@@ -75162,7 +75165,7 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
75162
75165
  return ui;
75163
75166
  };
75164
75167
  init_react_import2();
75165
- var storeInterceptor = (reducer2, record) => {
75168
+ var storeInterceptor = (reducer2, record, onAction) => {
75166
75169
  return (state, action) => {
75167
75170
  const newAppState = reducer2(state, action);
75168
75171
  const isValidType = ![
@@ -75175,6 +75178,7 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
75175
75178
  if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
75176
75179
  if (record) record(newAppState);
75177
75180
  }
75181
+ onAction == null ? void 0 : onAction(action, newAppState, state);
75178
75182
  return newAppState;
75179
75183
  };
75180
75184
  };
@@ -75186,16 +75190,21 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
75186
75190
  };
75187
75191
  function createReducer({
75188
75192
  config,
75189
- record
75193
+ record,
75194
+ onAction
75190
75195
  }) {
75191
- return storeInterceptor((state, action) => {
75192
- const data = reduceData(state.data, action, config);
75193
- const ui = reduceUi(state.ui, action);
75194
- if (action.type === "set") {
75195
- return setAction(state, action);
75196
- }
75197
- return { data, ui };
75198
- }, record);
75196
+ return storeInterceptor(
75197
+ (state, action) => {
75198
+ const data = reduceData(state.data, action, config);
75199
+ const ui = reduceUi(state.ui, action);
75200
+ if (action.type === "set") {
75201
+ return setAction(state, action);
75202
+ }
75203
+ return { data, ui };
75204
+ },
75205
+ record,
75206
+ onAction
75207
+ );
75199
75208
  }
75200
75209
  init_react_import2();
75201
75210
  var flushZones = (appState) => {
@@ -75434,20 +75443,8 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
75434
75443
  },
75435
75444
  children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: getClassName19("inner"), children: [
75436
75445
  /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: getClassName19("history"), children: [
75437
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(IconButton, { title: "undo", disabled: !hasPast, onClick: back, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
75438
- Undo2,
75439
- {
75440
- size: 21,
75441
- stroke: hasPast ? "var(--puck-color-black)" : "var(--puck-color-grey-08)"
75442
- }
75443
- ) }),
75444
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(IconButton, { title: "redo", disabled: !hasFuture, onClick: forward, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
75445
- Redo2,
75446
- {
75447
- size: 21,
75448
- stroke: hasFuture ? "var(--puck-color-black)" : "var(--puck-color-grey-08)"
75449
- }
75450
- ) })
75446
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(IconButton, { title: "undo", disabled: !hasPast, onClick: back, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Undo2, { size: 21 }) }),
75447
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(IconButton, { title: "redo", disabled: !hasFuture, onClick: forward, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Redo2, { size: 21 }) })
75451
75448
  ] }),
75452
75449
  /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_jsx_runtime25.Fragment, { children: renderHeaderActions && renderHeaderActions({
75453
75450
  state: appState,
@@ -76783,6 +76780,36 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
76783
76780
  }
76784
76781
  );
76785
76782
  };
76783
+ init_react_import2();
76784
+ var insertComponent = (componentType, zone, index, {
76785
+ config,
76786
+ dispatch,
76787
+ resolveData,
76788
+ state
76789
+ }) => {
76790
+ const id = generateId(componentType);
76791
+ const insertActionData = {
76792
+ type: "insert",
76793
+ componentType,
76794
+ destinationIndex: index,
76795
+ destinationZone: zone,
76796
+ id
76797
+ };
76798
+ const insertedData = insertAction(state.data, insertActionData, config);
76799
+ dispatch(__spreadProps2(__spreadValues2({}, insertActionData), {
76800
+ // Dispatch insert rather set, as user's may rely on this via onAction
76801
+ recordHistory: false
76802
+ }));
76803
+ const itemSelector = {
76804
+ index,
76805
+ zone
76806
+ };
76807
+ dispatch({ type: "setUi", ui: { itemSelector } });
76808
+ resolveData({
76809
+ data: insertedData,
76810
+ ui: __spreadProps2(__spreadValues2({}, state.ui), { itemSelector })
76811
+ });
76812
+ };
76786
76813
  var import_jsx_runtime36 = require("react/jsx-runtime");
76787
76814
  var getClassName26 = get_class_name_factory_default2("Puck", styles_module_default14);
76788
76815
  var getLayoutClassName = get_class_name_factory_default2("PuckLayout", styles_module_default14);
@@ -76793,6 +76820,7 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
76793
76820
  ui: initialUi,
76794
76821
  onChange,
76795
76822
  onPublish,
76823
+ onAction,
76796
76824
  plugins = [],
76797
76825
  overrides = {},
76798
76826
  renderHeader,
@@ -76809,7 +76837,7 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
76809
76837
  var _a3;
76810
76838
  const historyStore = useHistoryStore(initialHistory);
76811
76839
  const [reducer2] = (0, import_react30.useState)(
76812
- () => createReducer({ config, record: historyStore.record })
76840
+ () => createReducer({ config, record: historyStore.record, onAction })
76813
76841
  );
76814
76842
  const [initialAppState] = (0, import_react30.useState)(() => {
76815
76843
  var _a22, _b2, _c, _d, _e, _f, _g;
@@ -77026,16 +77054,12 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
77026
77054
  }
77027
77055
  if (droppedItem.source.droppableId.startsWith("component-list") && droppedItem.destination) {
77028
77056
  const [_, componentType] = droppedItem.draggableId.split("::");
77029
- dispatch({
77030
- type: "insert",
77031
- componentType: componentType || droppedItem.draggableId,
77032
- destinationIndex: droppedItem.destination.index,
77033
- destinationZone: droppedItem.destination.droppableId
77034
- });
77035
- setItemSelector({
77036
- index: droppedItem.destination.index,
77037
- zone: droppedItem.destination.droppableId
77038
- });
77057
+ insertComponent(
77058
+ componentType || droppedItem.draggableId,
77059
+ droppedItem.destination.droppableId,
77060
+ droppedItem.destination.index,
77061
+ { config, dispatch, resolveData, state: appState }
77062
+ );
77039
77063
  return;
77040
77064
  } else {
77041
77065
  const { source, destination } = droppedItem;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@measured/puck-plugin-heading-analyzer",
3
- "version": "0.16.0-canary.60fe631",
3
+ "version": "0.16.0-canary.7c79787",
4
4
  "author": "Measured Corporation Ltd <hello@measured.co>",
5
5
  "repository": "measuredco/puck",
6
6
  "bugs": "https://github.com/measuredco/puck/issues",
@@ -18,7 +18,7 @@
18
18
  "dist"
19
19
  ],
20
20
  "devDependencies": {
21
- "@measured/puck": "^0.16.0-canary.60fe631",
21
+ "@measured/puck": "^0.16.0-canary.7c79787",
22
22
  "@types/react": "^18.2.0",
23
23
  "@types/react-dom": "^18.2.0",
24
24
  "eslint": "^7.32.0",