@avocadostudio-ai/preview-adapter 0.2.0 → 0.2.3

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 (2) hide show
  1. package/README.md +80 -0
  2. package/package.json +11 -2
package/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # @avocadostudio-ai/preview-adapter
2
+
3
+ The bridge between a site rendering its own pages and the Avocado Studio editor
4
+ framing it: the `postMessage` protocol (`site-editor/v1`), the selection and
5
+ inline-editing overlay, and the live-draft store.
6
+
7
+ Most integrations get this transitively through
8
+ [`@avocadostudio-ai/site-sdk`](https://www.npmjs.com/package/@avocadostudio-ai/site-sdk)
9
+ and never import it. **Install it directly if your site renders drafts with its
10
+ own components** — see below.
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npm install @avocadostudio-ai/preview-adapter
16
+ ```
17
+
18
+ ## The one export you cannot get anywhere else
19
+
20
+ `site-sdk/editor` re-exports `LivePreviewProvider` but **not**
21
+ `useLivePreviewBlocks`, the hook that reads it. The SDK's own consumers of that
22
+ hook (`RenderedBlocks`, `PreviewBlock`) render Avocado's built-in block library
23
+ — which is exactly what a site with its own components cannot use.
24
+
25
+ So rendering a live draft through your own renderer means reaching for this
26
+ package:
27
+
28
+ ```tsx
29
+ import { LivePreviewProvider, useLivePreviewBlocks } from "@avocadostudio-ai/preview-adapter"
30
+
31
+ export function PreviewPage({ draft, ...rest }) {
32
+ return (
33
+ <LivePreviewProvider initialPage={draft}>
34
+ <PreviewBody draft={draft} {...rest} />
35
+ </LivePreviewProvider>
36
+ )
37
+ }
38
+
39
+ function PreviewBody({ draft, ...rest }) {
40
+ const live = useLivePreviewBlocks() // streams as the user edits
41
+ return <MyPageBuilder blocks={live ?? draft.blocks} {...rest} />
42
+ }
43
+ ```
44
+
45
+ `useLivePreviewBridgeApi` gives you the bridge itself if you need to drive it.
46
+
47
+ ## Styles
48
+
49
+ ```tsx
50
+ import "@avocadostudio-ai/preview-adapter/styles.css"
51
+ ```
52
+
53
+ Required in the preview route. Without it the overlay's outlines, badges and
54
+ field labels do not render, and a block that is genuinely selected looks like
55
+ nothing happened.
56
+
57
+ ## Making fields editable
58
+
59
+ The overlay finds a prop by the `data-editable-target="<propPath>"` attribute on
60
+ the node that renders it — `heading`, `cards[0].title`, `cards[0].imageUrl`.
61
+ Without those attributes you get block selection and no editable fields. This
62
+ has to go inside your own components; nothing can add it from the outside. Full
63
+ notes in
64
+ [the site-sdk README](https://www.npmjs.com/package/@avocadostudio-ai/site-sdk#making-fields-editable).
65
+
66
+ ## Subpaths
67
+
68
+ | Import | What it provides |
69
+ |---|---|
70
+ | `@avocadostudio-ai/preview-adapter` | `PreviewBridge`, `LivePreviewProvider`, `useLivePreviewBlocks`, `useLivePreviewBridgeApi`, `getPreviewWrapperProps`, and the bridge functions |
71
+ | `.../core` | The same bridge without the Next-specific wrapper |
72
+ | `.../styles.css` | The overlay stylesheet |
73
+
74
+ ## Peers
75
+
76
+ `next >= 15`, `react >= 19`.
77
+
78
+ ## License
79
+
80
+ Apache-2.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avocadostudio-ai/preview-adapter",
3
- "version": "0.2.0",
3
+ "version": "0.2.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -32,7 +32,7 @@
32
32
  "src/styles.css"
33
33
  ],
34
34
  "dependencies": {
35
- "@avocadostudio-ai/shared": "0.2.0"
35
+ "@avocadostudio-ai/shared": "0.2.3"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "next": ">=15.0.0",
@@ -49,6 +49,15 @@
49
49
  "typescript": "^5.7.3"
50
50
  },
51
51
  "description": "Preview bridge and editor overlay for Avocado Studio live preview",
52
+ "keywords": [
53
+ "avocado",
54
+ "avocado-studio",
55
+ "nextjs",
56
+ "live-preview",
57
+ "visual-editing",
58
+ "postmessage",
59
+ "overlay"
60
+ ],
52
61
  "license": "Apache-2.0",
53
62
  "homepage": "https://github.com/avocadostudio-ai/avocado/tree/main/packages/preview-adapter#readme",
54
63
  "bugs": {