@measured/puck 0.3.0 → 0.3.2

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.
Files changed (3) hide show
  1. package/README.md +57 -16
  2. package/dist/index.js +2 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -7,13 +7,14 @@ The self-hosted, drag and drop editor for React.
7
7
  - ✍️ **Inline editing**: Author content directly via puck for convenience
8
8
  - ⭐️ **No vendor lock-in**: Self-host or integrate with your existing application
9
9
 
10
- ![puck](https://github.com/measuredco/puck/assets/985961/10257000-ece7-4728-9e71-6204d2f1540e)
11
-
12
10
  [See demo](https://puck-demo-six.vercel.app/custom/edit)
13
11
 
14
12
  ## Example
15
13
 
14
+ Render the editor:
15
+
16
16
  ```jsx
17
+ // Editor.jsx
17
18
  import { Puck } from "puck";
18
19
 
19
20
  // Create puck component config
@@ -31,20 +32,25 @@ const config = {
31
32
  };
32
33
 
33
34
  // Describe the initial data
34
- const data = {
35
- content: [
36
- {
37
- type: "HeadingBlock",
38
- props: {
39
- title: "Home Page",
40
- },
41
- },
42
- ],
43
- };
35
+ const initialData = {};
36
+
37
+ // Save the data to your database
38
+ const save = (data) => {};
39
+
40
+ // Render Puck editor
41
+ export function Editor() {
42
+ return <Puck config={config} data={data} onPublish={save} />;
43
+ }
44
+ ```
45
+
46
+ Render the page:
47
+
48
+ ```jsx
49
+ // Page.jsx
50
+ import { Render } from "puck";
44
51
 
45
- // Render Puck
46
52
  export function Page() {
47
- return <Puck config={config} data={data} />;
53
+ return <Render config={config} data={data} />;
48
54
  }
49
55
  ```
50
56
 
@@ -80,8 +86,6 @@ Puck can be configured to work with plugins. Plugins can extend the functionalit
80
86
 
81
87
  The plugin API follows a React paradigm. Each plugin passed to the Puck editor can provide three functions:
82
88
 
83
- #### `Plugin`
84
-
85
89
  - `renderPage` (`Component`): Render the root node of the preview content
86
90
  - `renderPageFields` (`Component`): Render the page fields
87
91
  - `renderFields` (`Component`): Render the fields for the currently selected component
@@ -106,6 +110,24 @@ const myPlugin = {
106
110
 
107
111
  ## Reference
108
112
 
113
+ ### `<Puck>`
114
+
115
+ The `<Puck>` component renders the Puck editor.
116
+
117
+ - **config** (`Config`): Puck component configuration
118
+ - **data** (`Data`): Initial data to render
119
+ - **onChange** (`(Data) => void` [optional]): Callback that triggers when the user makes a change
120
+ - **onPublish** (`(Data) => void` [optional]): Callback that triggers when the user hits the "Publish" button
121
+ - **renderHeader** (`Component` [optional]): Render function for overriding the Puck header component
122
+ - **plugins** (`Plugin[]` [optional]): Array of plugins that can be used to enhance Puck
123
+
124
+ ### `<Render>`
125
+
126
+ The `<Render>` component renders a user-facing page using Puck data.
127
+
128
+ - **config** (`Config`): Puck component configuration
129
+ - **data** (`Data`): Data to render
130
+
109
131
  ### `Config`
110
132
 
111
133
  The `Config` object describes which components Puck should render, how they should render and which inputs are available to them.
@@ -134,6 +156,8 @@ A `Field` represents a user input field shown in the Puck interface.
134
156
  - **options** (`object[]`): array of items to render for select-type inputs
135
157
  - **label** (`string`)
136
158
  - **value** (`string`)
159
+ - **adaptor** (`Adaptor`): Content adaptor if using the `external` input type
160
+ - **adaptorParams** (`object`): Paramaters passed to the adaptor
137
161
 
138
162
  ### `Data`
139
163
 
@@ -147,6 +171,23 @@ The `Data` object stores the state of a page.
147
171
  - **props** (object):
148
172
  - **[prop]** (string): User defined data from component fields
149
173
 
174
+ ### `Adaptor`
175
+
176
+ An `Adaptor` can be used to load content from an external content repository, like Strapi.js.
177
+
178
+ - **name** (`string`): The human-readable name of the adaptor
179
+ - **fetchList** (`(adaptorParams: object) => object`): Fetch a list of content and return an array
180
+
181
+ > NB Using an adaptor on the reserved field name `_data` will spread the resulting data over your object, and lock the overridden fields.
182
+
183
+ ### `Plugin`
184
+
185
+ Plugins that can be used to enhance Puck.
186
+
187
+ - **renderPage** (`Component`): Render the root node of the preview content
188
+ - **renderPageFields** (`Component`): Render the page fields
189
+ - **renderFields** (`Component`): Render the fields for the currently selected component
190
+
150
191
  ## License
151
192
 
152
193
  MIT © [Measured Co.](https://github.com/measuredco)
package/dist/index.js CHANGED
@@ -1036,7 +1036,8 @@ function Puck({
1036
1036
  {
1037
1037
  style: {
1038
1038
  textAlign: "center",
1039
- color: "var(--puck-color-grey-6)"
1039
+ color: "var(--puck-color-grey-6)",
1040
+ fontFamily: "var(--puck-font-stack)"
1040
1041
  },
1041
1042
  children: "Add items to your page"
1042
1043
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@measured/puck",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",