@measured/puck 0.16.0-canary.60fe631 → 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 +5 -1
- package/dist/index.js +86 -60
- package/package.json +1 -1
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";
|
@@ -207,6 +208,8 @@ type HistoryStore<D = any> = {
|
|
207
208
|
setHistoryIndex: (index: number) => void;
|
208
209
|
};
|
209
210
|
|
211
|
+
type OnAction = (action: PuckAction, appState: AppState, prevAppState: AppState) => void;
|
212
|
+
|
210
213
|
type PathData = Record<string, {
|
211
214
|
path: string[];
|
212
215
|
label: string;
|
@@ -263,13 +266,14 @@ type IframeConfig = {
|
|
263
266
|
enabled?: boolean;
|
264
267
|
};
|
265
268
|
|
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, }: {
|
269
|
+
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
270
|
children?: ReactNode;
|
268
271
|
config: UserConfig;
|
269
272
|
data: Partial<Data>;
|
270
273
|
ui?: Partial<UiState>;
|
271
274
|
onChange?: (data: Data) => void;
|
272
275
|
onPublish?: (data: Data) => void;
|
276
|
+
onAction?: OnAction;
|
273
277
|
plugins?: Plugin[];
|
274
278
|
overrides?: Partial<Overrides>;
|
275
279
|
renderHeader?: (props: {
|
package/dist/index.js
CHANGED
@@ -31282,34 +31282,37 @@ var replaceAction = (data, action) => {
|
|
31282
31282
|
})
|
31283
31283
|
});
|
31284
31284
|
};
|
31285
|
-
var
|
31286
|
-
|
31287
|
-
|
31288
|
-
|
31289
|
-
|
31290
|
-
|
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
|
-
|
31305
|
-
|
31306
|
-
|
31307
|
-
|
31308
|
-
|
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 },
|
@@ -31473,7 +31476,7 @@ var reduceUi = (ui, action) => {
|
|
31473
31476
|
init_react_import();
|
31474
31477
|
|
31475
31478
|
// reducer/index.ts
|
31476
|
-
var storeInterceptor = (reducer, record) => {
|
31479
|
+
var storeInterceptor = (reducer, record, onAction) => {
|
31477
31480
|
return (state, action) => {
|
31478
31481
|
const newAppState = reducer(state, action);
|
31479
31482
|
const isValidType = ![
|
@@ -31486,6 +31489,7 @@ var storeInterceptor = (reducer, record) => {
|
|
31486
31489
|
if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
|
31487
31490
|
if (record) record(newAppState);
|
31488
31491
|
}
|
31492
|
+
onAction == null ? void 0 : onAction(action, newAppState, state);
|
31489
31493
|
return newAppState;
|
31490
31494
|
};
|
31491
31495
|
};
|
@@ -31497,16 +31501,21 @@ var setAction = (state, action) => {
|
|
31497
31501
|
};
|
31498
31502
|
function createReducer({
|
31499
31503
|
config,
|
31500
|
-
record
|
31504
|
+
record,
|
31505
|
+
onAction
|
31501
31506
|
}) {
|
31502
|
-
return storeInterceptor(
|
31503
|
-
|
31504
|
-
|
31505
|
-
|
31506
|
-
|
31507
|
-
|
31508
|
-
|
31509
|
-
|
31507
|
+
return storeInterceptor(
|
31508
|
+
(state, action) => {
|
31509
|
+
const data = reduceData(state.data, action, config);
|
31510
|
+
const ui = reduceUi(state.ui, action);
|
31511
|
+
if (action.type === "set") {
|
31512
|
+
return setAction(state, action);
|
31513
|
+
}
|
31514
|
+
return { data, ui };
|
31515
|
+
},
|
31516
|
+
record,
|
31517
|
+
onAction
|
31518
|
+
);
|
31510
31519
|
}
|
31511
31520
|
|
31512
31521
|
// lib/flush-zones.ts
|
@@ -31767,20 +31776,8 @@ var MenuBar = ({
|
|
31767
31776
|
},
|
31768
31777
|
children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: getClassName19("inner"), children: [
|
31769
31778
|
/* @__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
|
-
|
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
|
-
) })
|
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 }) })
|
31784
31781
|
] }),
|
31785
31782
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_jsx_runtime25.Fragment, { children: renderHeaderActions && renderHeaderActions({
|
31786
31783
|
state: appState,
|
@@ -33197,6 +33194,38 @@ var Canvas = () => {
|
|
33197
33194
|
);
|
33198
33195
|
};
|
33199
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
|
+
|
33200
33229
|
// components/Puck/index.tsx
|
33201
33230
|
var import_jsx_runtime36 = require("react/jsx-runtime");
|
33202
33231
|
var getClassName26 = get_class_name_factory_default("Puck", styles_module_default14);
|
@@ -33208,6 +33237,7 @@ function Puck({
|
|
33208
33237
|
ui: initialUi,
|
33209
33238
|
onChange,
|
33210
33239
|
onPublish,
|
33240
|
+
onAction,
|
33211
33241
|
plugins = [],
|
33212
33242
|
overrides = {},
|
33213
33243
|
renderHeader,
|
@@ -33224,7 +33254,7 @@ function Puck({
|
|
33224
33254
|
var _a;
|
33225
33255
|
const historyStore = useHistoryStore(initialHistory);
|
33226
33256
|
const [reducer] = (0, import_react30.useState)(
|
33227
|
-
() => createReducer({ config, record: historyStore.record })
|
33257
|
+
() => createReducer({ config, record: historyStore.record, onAction })
|
33228
33258
|
);
|
33229
33259
|
const [initialAppState] = (0, import_react30.useState)(() => {
|
33230
33260
|
var _a2, _b, _c, _d, _e, _f, _g;
|
@@ -33441,16 +33471,12 @@ function Puck({
|
|
33441
33471
|
}
|
33442
33472
|
if (droppedItem.source.droppableId.startsWith("component-list") && droppedItem.destination) {
|
33443
33473
|
const [_, componentType] = droppedItem.draggableId.split("::");
|
33444
|
-
|
33445
|
-
|
33446
|
-
|
33447
|
-
|
33448
|
-
|
33449
|
-
|
33450
|
-
setItemSelector({
|
33451
|
-
index: droppedItem.destination.index,
|
33452
|
-
zone: droppedItem.destination.droppableId
|
33453
|
-
});
|
33474
|
+
insertComponent(
|
33475
|
+
componentType || droppedItem.draggableId,
|
33476
|
+
droppedItem.destination.droppableId,
|
33477
|
+
droppedItem.destination.index,
|
33478
|
+
{ config, dispatch, resolveData, state: appState }
|
33479
|
+
);
|
33454
33480
|
return;
|
33455
33481
|
} else {
|
33456
33482
|
const { source, destination } = droppedItem;
|
package/package.json
CHANGED