@measured/puck 0.16.0-canary.6386bd1 → 0.16.0-canary.7c79787

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
@@ -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 },
@@ -33191,6 +33194,38 @@ var Canvas = () => {
33191
33194
  );
33192
33195
  };
33193
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
+
33194
33229
  // components/Puck/index.tsx
33195
33230
  var import_jsx_runtime36 = require("react/jsx-runtime");
33196
33231
  var getClassName26 = get_class_name_factory_default("Puck", styles_module_default14);
@@ -33436,16 +33471,12 @@ function Puck({
33436
33471
  }
33437
33472
  if (droppedItem.source.droppableId.startsWith("component-list") && droppedItem.destination) {
33438
33473
  const [_, componentType] = droppedItem.draggableId.split("::");
33439
- dispatch({
33440
- type: "insert",
33441
- componentType: componentType || droppedItem.draggableId,
33442
- destinationIndex: droppedItem.destination.index,
33443
- destinationZone: droppedItem.destination.droppableId
33444
- });
33445
- setItemSelector({
33446
- index: droppedItem.destination.index,
33447
- zone: droppedItem.destination.droppableId
33448
- });
33474
+ insertComponent(
33475
+ componentType || droppedItem.draggableId,
33476
+ droppedItem.destination.droppableId,
33477
+ droppedItem.destination.index,
33478
+ { config, dispatch, resolveData, state: appState }
33479
+ );
33449
33480
  return;
33450
33481
  } else {
33451
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.6386bd1",
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",