Skip to content

Commit 46cca26

Browse files
committed
feat: replace existing plugin API with plugin overrides
1 parent 66c3fe6 commit 46cca26

File tree

6 files changed

+84
-78
lines changed

6 files changed

+84
-78
lines changed

apps/docs/pages/docs/api-reference/components/puck.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function Editor() {
3535
| [`onChange()`](#onchangedata) | `onChange: (data) => {}` | Function | - |
3636
| [`onPublish()`](#onpublishdata) | `onPublish: async (data) => {}` | Function | - |
3737
| [`overrides`](#overrides) | `overrides: { header: () => <div /> }` | [Overrides](/docs/api-reference/overrides) | - |
38-
| [`plugins`](#plugins) | `plugins: [myPlugin]` | Plugin[] | - |
38+
| [`plugins`](#plugins) | `plugins: [myPlugin]` | [Plugin\[\]](/docs/api-reference/plugin) | - |
3939
| [`ui`](#ui) | `ui: {leftSideBarVisible: false}` | [AppState.ui](/docs/api-reference/app-state#ui) | - |
4040

4141
## Required props
@@ -197,7 +197,7 @@ export function Editor() {
197197

198198
### `plugins`
199199

200-
An array of plugins to enhance Puck's behaviour. See the [Plugin API reference](/docs/api-reference/plugins).
200+
An array of plugins to enhance Puck's behaviour. See the [Plugin API reference](/docs/api-reference/plugin).
201201

202202
```tsx {6} copy
203203
import headingAnalyzer from "@measured/puck-plugin-heading-analyzer";
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Plugin
2+
3+
> **⚠️ The plugin API is highly experimental and is likely to experience breaking changes.**
4+
5+
A plugins is an extensions that enhances the capabilities of Puck.
6+
7+
```tsx showLineNumbers copy {3-9, 15}
8+
import { Puck } from "@measured/puck";
9+
10+
const MyPlugin = {
11+
overrides: {
12+
componentItem: ({ name }) => (
13+
<div style={{ backgroundColor: "hotpink" }}>{name}</div>
14+
),
15+
},
16+
};
17+
18+
export function Editor() {
19+
return (
20+
<Puck
21+
// ...
22+
plugins={[MyPlugin]}
23+
/>
24+
);
25+
}
26+
```
27+
28+
## Params
29+
30+
| Prop | Example | Type | Status |
31+
| ------------------------- | -------------------------------------- | ------------------------------------------ | ------ |
32+
| [`overrides`](#overrides) | `overrides: { fields: () => <div /> }` | [Overrides](/docs/api-reference/overrides) | - |
33+
34+
### `overrides`
35+
36+
Override the render functions for specific portions of the Puck UI. Implements the [`overrides` API](/docs/api-reference/overrides).

apps/docs/pages/docs/api-reference/plugins.mdx

Lines changed: 0 additions & 20 deletions
This file was deleted.

apps/docs/pages/docs/api-reference/plugins/_meta.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

apps/docs/pages/docs/api-reference/plugins/functions.mdx

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,55 @@
11
# Plugin API
22

3-
Puck provides an experimental plugin API to create sharable extensions to Puck.
3+
> **⚠️ The plugin API is highly experimental and is likely to experience breaking changes.**
4+
5+
The plugin API enables developers to distribute plugins to customize the Puck interface.
46

57
## Official plugins
68

79
- [`heading-analyzer`](https://github.com/measuredco/puck/tree/main/packages/plugin-heading-analyzer): Analyze the heading outline of your page and be warned when you're not respecting WCAG 2 accessibility standards.
810

11+
## Community plugins
12+
13+
Please see the [awesome-puck repo](https://github.com/measuredco/awesome-puck) for a full list of community plugins.
14+
915
## Developing a plugin
1016

11-
Please see the [API reference](/docs/api-reference/plugins) for documentation.
17+
Plugins implement the same [`overrides`](/docs/api-reference/overrides) API used to build [custom interfaces](custom-interfaces#ui-overrides):
18+
19+
```tsx showLineNumbers copy {3-9, 15}
20+
import { Puck } from "@measured/puck";
21+
22+
const MyPlugin = {
23+
overrides: {
24+
componentItem: ({ name }) => (
25+
<div style={{ backgroundColor: "hotpink" }}>{name}</div>
26+
),
27+
},
28+
};
29+
30+
export function Editor() {
31+
return (
32+
<Puck
33+
// ...
34+
plugins={[MyPlugin]}
35+
/>
36+
);
37+
}
38+
```
39+
40+
## Plugin currying
41+
42+
Plugins are rendered in the order they are defined. All overrides are _curried_, meaning that the return node of one plugin will be passed as `children` to the next plugin.
43+
44+
This may result in some incompatible plugin combinations. To improve your chance of building a widely compatible plugin, consider:
45+
46+
1. Implementing as few override methods as you need
47+
2. Always rendering `children` if possible
48+
49+
## Custom fields
50+
51+
Plugins enable full UI overhauls. If you're creating a field for a specific use-case, you might be better off distributing a [custom field](custom-fields).
52+
53+
## Further reading
54+
55+
- [Plugin API reference](/docs/api-reference/plugin)

0 commit comments

Comments
 (0)