@measured/puck 0.11.0-canary.b28404f → 0.11.0-canary.f9033e2
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/README.md +27 -33
- package/dist/index.css +228 -172
- package/dist/index.d.ts +46 -50
- package/dist/index.js +30524 -1014
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -277,19 +277,9 @@ When the user interacts with this adaptor, they'll be presented with a list of i
|
|
|
277
277
|
|
|
278
278
|
Dynamic prop resolution allows developers to resolve props for components without saving the data to the Puck data model.
|
|
279
279
|
|
|
280
|
-
###
|
|
281
|
-
|
|
282
|
-
`resolveProps` is defined in the component config, and allows the developer to make asynchronous calls to change the props after they've been set by Puck.
|
|
283
|
-
|
|
284
|
-
#### Args
|
|
285
|
-
|
|
286
|
-
- **props** (`object`): the current props for your component stored in the Puck data
|
|
287
|
-
|
|
288
|
-
#### Response
|
|
280
|
+
### resolveData()
|
|
289
281
|
|
|
290
|
-
|
|
291
|
-
- **readOnly** (`object`): an object describing which fields on the component are currently read-only
|
|
292
|
-
- **[prop]** (`boolean`): boolean describing whether or not the prop field is read-only
|
|
282
|
+
`resolveData` is defined in the component config, and allows the developer to make asynchronous calls to change the [ComponentData](#componentdata) after they've been set by Puck. Receives [ComponentData](#componentdata) and returns [ComponentData](#componentdata).
|
|
293
283
|
|
|
294
284
|
#### Examples
|
|
295
285
|
|
|
@@ -309,7 +299,7 @@ const config = {
|
|
|
309
299
|
type: "text",
|
|
310
300
|
},
|
|
311
301
|
},
|
|
312
|
-
|
|
302
|
+
resolveData: async (props) => {
|
|
313
303
|
return {
|
|
314
304
|
props: {
|
|
315
305
|
title: props.text,
|
|
@@ -329,7 +319,7 @@ const config = {
|
|
|
329
319
|
|
|
330
320
|
##### Combining with adaptors
|
|
331
321
|
|
|
332
|
-
A more advanced pattern is to combine the `
|
|
322
|
+
A more advanced pattern is to combine the `resolveData` method with the adaptors to dynamically fetch data when rendering the component.
|
|
333
323
|
|
|
334
324
|
```tsx
|
|
335
325
|
const myAdaptor = {
|
|
@@ -355,7 +345,7 @@ const config = {
|
|
|
355
345
|
type: "text",
|
|
356
346
|
},
|
|
357
347
|
},
|
|
358
|
-
|
|
348
|
+
resolveData: async (props) => {
|
|
359
349
|
if (!myData.id) {
|
|
360
350
|
return { props, readOnly: { title: false } };
|
|
361
351
|
}
|
|
@@ -381,14 +371,16 @@ const config = {
|
|
|
381
371
|
};
|
|
382
372
|
```
|
|
383
373
|
|
|
384
|
-
###
|
|
374
|
+
### resolveAllData()
|
|
375
|
+
|
|
376
|
+
`resolveAllData` is a utility function exported by Puck to enable the developer to run all their `resolveData` methods before rendering the component with `<Render>`.
|
|
385
377
|
|
|
386
|
-
`resolveData`
|
|
378
|
+
If your `resolveData` methods rely on any external APIs, you should run this before rendering your page.
|
|
387
379
|
|
|
388
380
|
```tsx
|
|
389
|
-
import {
|
|
381
|
+
import { resolveAllData } from "@measured/puck";
|
|
390
382
|
|
|
391
|
-
const resolvedData =
|
|
383
|
+
const resolvedData = resolveAllData(data, config);
|
|
392
384
|
```
|
|
393
385
|
|
|
394
386
|
## Reference
|
|
@@ -431,18 +423,13 @@ The `Config` object describes which components Puck should render, how they shou
|
|
|
431
423
|
- **title** (`Field`): Title of the content, typically used for the page title.
|
|
432
424
|
- **[fieldName]** (`Field`): User defined fields, used to describe the input data stored in the `root` key.
|
|
433
425
|
- **render** (`Component`): Render a React component at the root of your component tree. Useful for defining context providers.
|
|
426
|
+
- **resolveData** (`async (data: ComponentData) => ComponentData` [optional]): Function to dynamically change props before rendering the root.
|
|
434
427
|
- **components** (`object`): Definitions for each of the components you want to show in the visual editor
|
|
435
428
|
- **[componentName]** (`object`)
|
|
436
429
|
- **fields** (`Field`): The Field objects describing the input data stored against this component.
|
|
437
430
|
- **render** (`Component`): Render function for your React component. Receives props as defined in fields.
|
|
438
431
|
- **defaultProps** (`object` [optional]): Default props to pass to your component. Will show in fields.
|
|
439
|
-
- **
|
|
440
|
-
- Args
|
|
441
|
-
- **props** (`object`): the current props for your component stored in the Puck data
|
|
442
|
-
- Response
|
|
443
|
-
- **props** (`object`): the resolved props for your component. Will not be stored in the Puck data
|
|
444
|
-
- **readOnly** (`object`): an object describing which fields on the component are currently read-only
|
|
445
|
-
- **[prop]** (`boolean`): boolean describing whether or not the prop field is read-only
|
|
432
|
+
- **resolveData** (`async (data: ComponentData) => ComponentData` [optional]): Function to dynamically change props before rendering the component.
|
|
446
433
|
- **categories** (`object`): Component categories for rendering in the side bar or restricting in DropZones
|
|
447
434
|
- **[categoryName]** (`object`)
|
|
448
435
|
- **components** (`sting[]`, [optional]): Array containing the names of components in this category
|
|
@@ -532,13 +519,20 @@ The `AppState` object stores the puck application state.
|
|
|
532
519
|
|
|
533
520
|
The `Data` object stores the puck page data.
|
|
534
521
|
|
|
535
|
-
- **root** (`
|
|
536
|
-
- **
|
|
537
|
-
|
|
538
|
-
- **content** (`
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
522
|
+
- **root** (`ComponentData`): The component data for the root of your configuration.
|
|
523
|
+
- **props** (object): Extends `ComponentData.props`, with some additional props
|
|
524
|
+
- **title** (`string`, [optional]): Title of the content, typically used for the page title
|
|
525
|
+
- **content** (`ComponentData[]`): Component data for the main content
|
|
526
|
+
- **zones** (`object`, [optional]): Component data for all DropZones
|
|
527
|
+
**[zoneCompound]** (`ComponentData[]`): Component data for a specific DropZone `zone` within a component instance
|
|
528
|
+
|
|
529
|
+
### `ComponentData`
|
|
530
|
+
|
|
531
|
+
- **type** (`string`): Component name
|
|
532
|
+
- **props** (`object`):
|
|
533
|
+
- **[prop]** (`any`): User defined data from component fields
|
|
534
|
+
- **readOnly** (`object`): Object describing which fields on the component are currently read-only. Can use dot-notation for arrays, like `array[1].text` or `array[*].text`.
|
|
535
|
+
- **[prop]** (`boolean`): boolean describing whether or not the prop field is read-only
|
|
542
536
|
|
|
543
537
|
### `Plugin`
|
|
544
538
|
|