@measured/puck 0.10.0-canary.c276b23 → 0.10.0-canary.e308381
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +16 -2
- package/dist/index.d.ts +8 -5
- package/dist/index.js +25 -10
- package/package.json +1 -1
package/README.md
CHANGED
@@ -112,7 +112,11 @@ The plugin API follows a React paradigm. Each plugin passed to the Puck editor c
|
|
112
112
|
- `renderRootFields` (`Component`): Render the root fields
|
113
113
|
- `renderFields` (`Component`): Render the fields for the currently selected component
|
114
114
|
|
115
|
-
Each render function receives
|
115
|
+
Each render function receives three props:
|
116
|
+
|
117
|
+
- **children** (`ReactNode`): The normal contents of the root or field. You must render this.
|
118
|
+
- **state** (`AppState`): The current application state, including data and UI state
|
119
|
+
- **dispatch** (`(action: PuckAction) => void`): The Puck dispatcher, used for making data changes or updating the UI. See the [action definitions](https://github.com/measuredco/puck/blob/main/packages/core/reducer/actions.tsx) for a full reference of available mutations.
|
116
120
|
|
117
121
|
#### Example
|
118
122
|
|
@@ -285,9 +289,19 @@ A `Field` represents a user input field shown in the Puck interface.
|
|
285
289
|
- **onChange** (`(value: any) => void`): Callback to change the value
|
286
290
|
- **readOnly** (`boolean` | `undefined`): Whether or not the field should be in readOnly mode
|
287
291
|
|
292
|
+
### `AppState`
|
293
|
+
|
294
|
+
The `AppState` object stores the puck application state.
|
295
|
+
|
296
|
+
- **data** (`Data`): The page data currently being rendered
|
297
|
+
- **ui** (`object`):
|
298
|
+
- **leftSideBarVisible** (boolean): Whether or not the left side bar is visible
|
299
|
+
- **itemSelector** (object): An object describing which item is selected
|
300
|
+
- **arrayState** (object): An object describing the internal state of array items
|
301
|
+
|
288
302
|
### `Data`
|
289
303
|
|
290
|
-
The `Data` object stores the puck
|
304
|
+
The `Data` object stores the puck page data.
|
291
305
|
|
292
306
|
- **root** (`object`):
|
293
307
|
- **title** (string): Title of the content, typically used for the page title
|
package/dist/index.d.ts
CHANGED
@@ -250,15 +250,18 @@ declare const IconButton: ({ children, href, onClick, variant, type, disabled, t
|
|
250
250
|
type Plugin = {
|
251
251
|
renderRootFields?: (props: {
|
252
252
|
children: ReactNode;
|
253
|
-
|
253
|
+
dispatch: (action: PuckAction) => void;
|
254
|
+
state: AppState;
|
254
255
|
}) => ReactElement<any>;
|
255
256
|
renderRoot?: (props: {
|
256
257
|
children: ReactNode;
|
257
|
-
|
258
|
+
dispatch: (action: PuckAction) => void;
|
259
|
+
state: AppState;
|
258
260
|
}) => ReactElement<any>;
|
259
261
|
renderFields?: (props: {
|
260
262
|
children: ReactNode;
|
261
|
-
|
263
|
+
dispatch: (action: PuckAction) => void;
|
264
|
+
state: AppState;
|
262
265
|
}) => ReactElement<any>;
|
263
266
|
};
|
264
267
|
|
@@ -270,11 +273,11 @@ declare function Puck({ config, data: initialData, onChange, onPublish, plugins,
|
|
270
273
|
plugins?: Plugin[];
|
271
274
|
renderHeader?: (props: {
|
272
275
|
children: ReactNode;
|
273
|
-
data: Data;
|
274
276
|
dispatch: (action: PuckAction) => void;
|
277
|
+
state: AppState;
|
275
278
|
}) => ReactElement;
|
276
279
|
renderHeaderActions?: (props: {
|
277
|
-
|
280
|
+
state: AppState;
|
278
281
|
dispatch: (action: PuckAction) => void;
|
279
282
|
}) => ReactElement;
|
280
283
|
headerTitle?: string;
|
package/dist/index.js
CHANGED
@@ -4557,12 +4557,13 @@ var defaultPageFields = {
|
|
4557
4557
|
};
|
4558
4558
|
var PluginRenderer = ({
|
4559
4559
|
children,
|
4560
|
-
|
4560
|
+
dispatch,
|
4561
|
+
state,
|
4561
4562
|
plugins,
|
4562
4563
|
renderMethod
|
4563
4564
|
}) => {
|
4564
4565
|
return plugins.filter((item) => item[renderMethod]).map((item) => item[renderMethod]).reduce(
|
4565
|
-
(accChildren, Item) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Item, {
|
4566
|
+
(accChildren, Item) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Item, { dispatch, state, children: accChildren }),
|
4566
4567
|
children
|
4567
4568
|
);
|
4568
4569
|
};
|
@@ -4610,7 +4611,8 @@ function Puck({
|
|
4610
4611
|
{
|
4611
4612
|
plugins,
|
4612
4613
|
renderMethod: "renderRoot",
|
4613
|
-
|
4614
|
+
dispatch: pageProps.dispatch,
|
4615
|
+
state: pageProps.state,
|
4614
4616
|
children: ((_a2 = config.root) == null ? void 0 : _a2.render) ? (_b2 = config.root) == null ? void 0 : _b2.render(__spreadProps(__spreadValues({}, pageProps), { editMode: true })) : pageProps.children
|
4615
4617
|
}
|
4616
4618
|
);
|
@@ -4623,7 +4625,8 @@ function Puck({
|
|
4623
4625
|
{
|
4624
4626
|
plugins,
|
4625
4627
|
renderMethod: "renderRootFields",
|
4626
|
-
|
4628
|
+
dispatch: props.dispatch,
|
4629
|
+
state: props.state,
|
4627
4630
|
children: props.children
|
4628
4631
|
}
|
4629
4632
|
),
|
@@ -4635,7 +4638,8 @@ function Puck({
|
|
4635
4638
|
{
|
4636
4639
|
plugins,
|
4637
4640
|
renderMethod: "renderFields",
|
4638
|
-
|
4641
|
+
dispatch: props.dispatch,
|
4642
|
+
state: props.state,
|
4639
4643
|
children: props.children
|
4640
4644
|
}
|
4641
4645
|
),
|
@@ -4753,8 +4757,8 @@ function Puck({
|
|
4753
4757
|
children: "Publish"
|
4754
4758
|
}
|
4755
4759
|
),
|
4756
|
-
|
4757
|
-
|
4760
|
+
dispatch,
|
4761
|
+
state: appState
|
4758
4762
|
}) : /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
|
4759
4763
|
"div",
|
4760
4764
|
{
|
@@ -4849,7 +4853,10 @@ function Puck({
|
|
4849
4853
|
}
|
4850
4854
|
)
|
4851
4855
|
] }),
|
4852
|
-
renderHeaderActions && renderHeaderActions({
|
4856
|
+
renderHeaderActions && renderHeaderActions({
|
4857
|
+
state: appState,
|
4858
|
+
dispatch
|
4859
|
+
}),
|
4853
4860
|
/* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
4854
4861
|
Button,
|
4855
4862
|
{
|
@@ -4940,7 +4947,15 @@ function Puck({
|
|
4940
4947
|
style: {
|
4941
4948
|
border: "1px solid var(--puck-color-grey-8)"
|
4942
4949
|
},
|
4943
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
4950
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
4951
|
+
Page,
|
4952
|
+
__spreadProps(__spreadValues({
|
4953
|
+
dispatch,
|
4954
|
+
state: appState
|
4955
|
+
}, data.root), {
|
4956
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(DropZone, { zone: rootDroppableId })
|
4957
|
+
})
|
4958
|
+
)
|
4944
4959
|
}
|
4945
4960
|
)
|
4946
4961
|
}
|
@@ -4970,7 +4985,7 @@ function Puck({
|
|
4970
4985
|
flexDirection: "column",
|
4971
4986
|
background: "var(--puck-color-white)"
|
4972
4987
|
},
|
4973
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(FieldWrapper, {
|
4988
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(FieldWrapper, { dispatch, state: appState, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
4974
4989
|
SidebarSection,
|
4975
4990
|
{
|
4976
4991
|
noPadding: true,
|