@measured/puck 0.16.0-canary.2c52d27 → 0.16.0-canary.3298831

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ type InsertAction = {
10
10
  componentType: string;
11
11
  destinationIndex: number;
12
12
  destinationZone: string;
13
+ id?: string;
13
14
  };
14
15
  type DuplicateAction = {
15
16
  type: "duplicate";
package/dist/index.js CHANGED
@@ -31282,34 +31282,37 @@ var replaceAction = (data, action) => {
31282
31282
  })
31283
31283
  });
31284
31284
  };
31285
- var reduceData = (data, action, config) => {
31286
- if (action.type === "insert") {
31287
- const emptyComponentData = {
31288
- type: action.componentType,
31289
- props: __spreadProps(__spreadValues({}, config.components[action.componentType].defaultProps || {}), {
31290
- id: generateId(action.componentType)
31291
- })
31292
- };
31293
- if (action.destinationZone === rootDroppableId) {
31294
- return __spreadProps(__spreadValues({}, data), {
31295
- content: insert(
31296
- data.content,
31297
- action.destinationIndex,
31298
- emptyComponentData
31299
- )
31300
- });
31301
- }
31302
- const newData = setupZone(data, action.destinationZone);
31285
+ var insertAction = (data, action, config) => {
31286
+ const emptyComponentData = {
31287
+ type: action.componentType,
31288
+ props: __spreadProps(__spreadValues({}, config.components[action.componentType].defaultProps || {}), {
31289
+ id: action.id || generateId(action.componentType)
31290
+ })
31291
+ };
31292
+ if (action.destinationZone === rootDroppableId) {
31303
31293
  return __spreadProps(__spreadValues({}, data), {
31304
- zones: __spreadProps(__spreadValues({}, newData.zones), {
31305
- [action.destinationZone]: insert(
31306
- newData.zones[action.destinationZone],
31307
- action.destinationIndex,
31308
- emptyComponentData
31309
- )
31310
- })
31294
+ content: insert(
31295
+ data.content,
31296
+ action.destinationIndex,
31297
+ emptyComponentData
31298
+ )
31311
31299
  });
31312
31300
  }
31301
+ const newData = setupZone(data, action.destinationZone);
31302
+ return __spreadProps(__spreadValues({}, data), {
31303
+ zones: __spreadProps(__spreadValues({}, newData.zones), {
31304
+ [action.destinationZone]: insert(
31305
+ newData.zones[action.destinationZone],
31306
+ action.destinationIndex,
31307
+ emptyComponentData
31308
+ )
31309
+ })
31310
+ });
31311
+ };
31312
+ var reduceData = (data, action, config) => {
31313
+ if (action.type === "insert") {
31314
+ return insertAction(data, action, config);
31315
+ }
31313
31316
  if (action.type === "duplicate") {
31314
31317
  const item = getItem(
31315
31318
  { index: action.sourceIndex, zone: action.sourceZone },
@@ -31773,20 +31776,8 @@ var MenuBar = ({
31773
31776
  },
31774
31777
  children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: getClassName19("inner"), children: [
31775
31778
  /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: getClassName19("history"), children: [
31776
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(IconButton, { title: "undo", disabled: !hasPast, onClick: back, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
31777
- Undo2,
31778
- {
31779
- size: 21,
31780
- stroke: hasPast ? "var(--puck-color-black)" : "var(--puck-color-grey-08)"
31781
- }
31782
- ) }),
31783
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(IconButton, { title: "redo", disabled: !hasFuture, onClick: forward, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
31784
- Redo2,
31785
- {
31786
- size: 21,
31787
- stroke: hasFuture ? "var(--puck-color-black)" : "var(--puck-color-grey-08)"
31788
- }
31789
- ) })
31779
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(IconButton, { title: "undo", disabled: !hasPast, onClick: back, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Undo2, { size: 21 }) }),
31780
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(IconButton, { title: "redo", disabled: !hasFuture, onClick: forward, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Redo2, { size: 21 }) })
31790
31781
  ] }),
31791
31782
  /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_jsx_runtime25.Fragment, { children: renderHeaderActions && renderHeaderActions({
31792
31783
  state: appState,
@@ -33203,6 +33194,38 @@ var Canvas = () => {
33203
33194
  );
33204
33195
  };
33205
33196
 
33197
+ // lib/insert-component.ts
33198
+ init_react_import();
33199
+ var insertComponent = (componentType, zone, index, {
33200
+ config,
33201
+ dispatch,
33202
+ resolveData,
33203
+ state
33204
+ }) => {
33205
+ const id = generateId(componentType);
33206
+ const insertActionData = {
33207
+ type: "insert",
33208
+ componentType,
33209
+ destinationIndex: index,
33210
+ destinationZone: zone,
33211
+ id
33212
+ };
33213
+ const insertedData = insertAction(state.data, insertActionData, config);
33214
+ dispatch(__spreadProps(__spreadValues({}, insertActionData), {
33215
+ // Dispatch insert rather set, as user's may rely on this via onAction
33216
+ recordHistory: false
33217
+ }));
33218
+ const itemSelector = {
33219
+ index,
33220
+ zone
33221
+ };
33222
+ dispatch({ type: "setUi", ui: { itemSelector } });
33223
+ resolveData({
33224
+ data: insertedData,
33225
+ ui: __spreadProps(__spreadValues({}, state.ui), { itemSelector })
33226
+ });
33227
+ };
33228
+
33206
33229
  // components/Puck/index.tsx
33207
33230
  var import_jsx_runtime36 = require("react/jsx-runtime");
33208
33231
  var getClassName26 = get_class_name_factory_default("Puck", styles_module_default14);
@@ -33448,16 +33471,12 @@ function Puck({
33448
33471
  }
33449
33472
  if (droppedItem.source.droppableId.startsWith("component-list") && droppedItem.destination) {
33450
33473
  const [_, componentType] = droppedItem.draggableId.split("::");
33451
- dispatch({
33452
- type: "insert",
33453
- componentType: componentType || droppedItem.draggableId,
33454
- destinationIndex: droppedItem.destination.index,
33455
- destinationZone: droppedItem.destination.droppableId
33456
- });
33457
- setItemSelector({
33458
- index: droppedItem.destination.index,
33459
- zone: droppedItem.destination.droppableId
33460
- });
33474
+ insertComponent(
33475
+ componentType || droppedItem.draggableId,
33476
+ droppedItem.destination.droppableId,
33477
+ droppedItem.destination.index,
33478
+ { config, dispatch, resolveData, state: appState }
33479
+ );
33461
33480
  return;
33462
33481
  } else {
33463
33482
  const { source, destination } = droppedItem;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@measured/puck",
3
- "version": "0.16.0-canary.2c52d27",
3
+ "version": "0.16.0-canary.3298831",
4
4
  "author": "Measured Corporation Ltd <hello@measured.co>",
5
5
  "repository": "measuredco/puck",
6
6
  "bugs": "https://github.com/measuredco/puck/issues",