@plenary/react 0.1.0 → 0.1.1
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 +97 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# @plenary/react
|
|
2
|
+
|
|
3
|
+
The React renderer for Plenary's page builder: render an entry's `blocks`
|
|
4
|
+
component tree, register your own components so editors can use them, and
|
|
5
|
+
embed the live-preview bridge that lets the Plenary console edit your site
|
|
6
|
+
in place.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install @plenary/react @plenary/client
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
ESM-only; React 18 or 19.
|
|
13
|
+
|
|
14
|
+
## Rendering a page
|
|
15
|
+
|
|
16
|
+
`PlenaryPage` is an async server component that renders a `PlenaryDocument` —
|
|
17
|
+
the JSON DOM stored in an entry's `blocks` field:
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { createClient } from "@plenary/client";
|
|
21
|
+
import { PlenaryPage } from "@plenary/react";
|
|
22
|
+
|
|
23
|
+
const plenary = createClient({
|
|
24
|
+
baseUrl: process.env.PLENARY_URL!,
|
|
25
|
+
siteKey: "main",
|
|
26
|
+
apiKey: process.env.PLENARY_API_KEY!,
|
|
27
|
+
locale: "en",
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export default async function Page({ params }) {
|
|
31
|
+
const entry = await plenary.getEntry("page", params.slug);
|
|
32
|
+
return <PlenaryPage document={entry.data.blocks} client={plenary} />;
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The built-in components — `Box`, `Section`, `Text`, `Image`, `Video`, `Form` —
|
|
37
|
+
cover layout, media (with server-generated variants and focal-point crops),
|
|
38
|
+
and form rendering out of the box. Pass a `client` so media and form props
|
|
39
|
+
resolve; interactive pieces (form submission) need your tree wrapped in a
|
|
40
|
+
`PlenaryProvider`:
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
import { PlenaryProvider } from "@plenary/react";
|
|
44
|
+
|
|
45
|
+
<PlenaryProvider client={plenary}>{children}</PlenaryProvider>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Registering your own components
|
|
49
|
+
|
|
50
|
+
Editors can only place components the site registers. Registration pairs a
|
|
51
|
+
React component with the metadata the console's page builder needs — prop
|
|
52
|
+
definitions, named slots, style panels:
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
import { register } from "@plenary/react";
|
|
56
|
+
|
|
57
|
+
function Hero({ heading, children }) {
|
|
58
|
+
return (
|
|
59
|
+
<header>
|
|
60
|
+
<h1>{heading}</h1>
|
|
61
|
+
{children}
|
|
62
|
+
</header>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
register(Hero, {
|
|
67
|
+
key: "hero",
|
|
68
|
+
label: "Hero",
|
|
69
|
+
props: [{ key: "heading", type: "text" }],
|
|
70
|
+
slots: [{ name: "children", label: "Content" }],
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`registerTheme` declares the site's design tokens so the console's style
|
|
75
|
+
editor offers them alongside raw CSS.
|
|
76
|
+
|
|
77
|
+
## Live preview
|
|
78
|
+
|
|
79
|
+
`PlenaryBridge` (from `@plenary/react/bridge`) turns a page into a live
|
|
80
|
+
preview surface for the console: rendered inside the page builder's iframe,
|
|
81
|
+
it receives draft edits over postMessage and re-renders in place, reporting
|
|
82
|
+
the registered component manifest back to the editor.
|
|
83
|
+
|
|
84
|
+
```tsx
|
|
85
|
+
import { PlenaryBridge } from "@plenary/react/bridge";
|
|
86
|
+
|
|
87
|
+
<PlenaryBridge
|
|
88
|
+
region="blocks"
|
|
89
|
+
editorOrigins={["https://cms.example.com", "http://localhost:*"]}
|
|
90
|
+
/>
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Only messages from `editorOrigins` are honored — exact origins,
|
|
94
|
+
`https://*.example.com` subdomain patterns, or `http://localhost:*` port
|
|
95
|
+
patterns; everything else is ignored.
|
|
96
|
+
|
|
97
|
+
Full documentation at [docs.plenarycms.com](https://docs.plenarycms.com).
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @plenary/react — the DOM renderer, component registry, and built-in\n * components (Box/Section/Text/Image/Video/Form) for rendering a Page's `dom`\n * tree. Custom components register on top of the built-ins
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @plenary/react — the DOM renderer, component registry, and built-in\n * components (Box/Section/Text/Image/Video/Form) for rendering a Page's `dom`\n * tree. Custom components register on top of the built-ins; the preview bridge\n * lives in the `./bridge` export.\n */\n\nexport {\n PlenaryPage,\n renderDocument,\n renderDocumentSync,\n type PlenaryPageProps,\n type SyncRenderOptions,\n} from \"./render.js\";\nexport {\n Registry,\n registry,\n register,\n registerTheme,\n Plenary,\n getManifest,\n getTheme,\n} from \"./registry.js\";\nexport { Box, type BoxProps } from \"./components/Box.js\";\nexport { Section, type SectionProps } from \"./components/Section.js\";\nexport { Text, type TextProps } from \"./components/Text.js\";\nexport { Image, type ImageProps } from \"./components/Image.js\";\nexport { Video, type VideoProps } from \"./components/Video.js\";\nexport { Form, type FormProps } from \"./components/Form.js\";\nexport { Placeholder, type PlaceholderProps } from \"./components/Placeholder.js\";\nexport {\n resolveMedia,\n toResolvedMedia,\n type MediaValue,\n type ResolvedMedia,\n} from \"./media.js\";\nexport { toResolvedForm, type FormValue, type ResolvedForm } from \"./form.js\";\nexport {\n PlenaryProvider,\n usePlenaryClient,\n type PlenaryProviderProps,\n} from \"./context.js\";\nexport type {\n PlenaryComponent,\n RegisteredComponent,\n RenderContext,\n SlotProps,\n} from \"./types.js\";\n"],"mappings":"AAOA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,WAA0B;AACnC,SAAS,eAAkC;AAC3C,SAAS,YAA4B;AACrC,SAAS,aAA8B;AACvC,SAAS,aAA8B;AACvC,SAAS,YAA4B;AACrC,SAAS,mBAA0C;AACnD;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,sBAAyD;AAClE;AAAA,EACE;AAAA,EACA;AAAA,OAEK;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plenary/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Plenary React renderer, component registry, built-in components, and preview bridge.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@plenary/client": "0.1.
|
|
24
|
-
"@plenary/core": "0.1.
|
|
23
|
+
"@plenary/client": "0.1.1",
|
|
24
|
+
"@plenary/core": "0.1.1"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"react": "^18 || ^19",
|