@cmssy/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 +99 -0
- package/package.json +16 -1
package/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# @cmssy/react
|
|
2
|
+
|
|
3
|
+
React building blocks for a [cmssy](https://cmssy.com) headless site: define
|
|
4
|
+
blocks, render published content, fetch data from the public delivery API, and
|
|
5
|
+
drive the live editor bridge. Framework-agnostic React; for Next.js App Router
|
|
6
|
+
wiring use [`@cmssy/next`](https://www.npmjs.com/package/@cmssy/next).
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pnpm add @cmssy/react
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Define a block
|
|
13
|
+
|
|
14
|
+
A block is a plain React component plus a field schema the editor reads.
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
import { defineBlock, fields } from "@cmssy/react";
|
|
18
|
+
import Hero from "./Hero";
|
|
19
|
+
|
|
20
|
+
export const heroBlock = defineBlock({
|
|
21
|
+
type: "hero",
|
|
22
|
+
label: "Hero",
|
|
23
|
+
component: Hero,
|
|
24
|
+
props: {
|
|
25
|
+
heading: fields.singleLine({ label: "Heading", required: true }),
|
|
26
|
+
subheading: fields.multiLine({ label: "Subheading" }),
|
|
27
|
+
cta: fields.link({ label: "CTA" }),
|
|
28
|
+
image: fields.media({ label: "Image" }),
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`fields` covers `singleLine`, `multiLine`, `link`, `media`, `boolean`,
|
|
34
|
+
`repeater`, and more. The block component receives `{ content }` resolved from
|
|
35
|
+
the CMS at runtime.
|
|
36
|
+
|
|
37
|
+
## Render published content
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
import { fetchPage, CmssyServerPage } from "@cmssy/react";
|
|
41
|
+
|
|
42
|
+
const page = await fetchPage(
|
|
43
|
+
{ apiUrl: "https://api.cmssy.io/graphql", workspaceSlug: "acme" },
|
|
44
|
+
pathSegments,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
return <CmssyServerPage page={page} blocks={blocks} locale="en" />;
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`CmssyServerLayout` renders header/footer layout groups the same way. Both are
|
|
51
|
+
Server Components — no block JavaScript ships to the client unless a block needs
|
|
52
|
+
it.
|
|
53
|
+
|
|
54
|
+
## Fetch data
|
|
55
|
+
|
|
56
|
+
One generic GraphQL client over the public API — write your own queries (or use
|
|
57
|
+
the exported documents):
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { createCmssyClient, MODEL_RECORDS_QUERY } from "@cmssy/react";
|
|
61
|
+
|
|
62
|
+
const cmssy = createCmssyClient({
|
|
63
|
+
apiUrl: "https://api.cmssy.io/graphql",
|
|
64
|
+
workspaceSlug: "acme",
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// raw query (you own scoping)
|
|
68
|
+
await cmssy.query(MY_QUERY, vars);
|
|
69
|
+
|
|
70
|
+
// workspace-scoped (auto x-workspace-id header + $workspaceId var)
|
|
71
|
+
const { publicModelRecords } = await cmssy.queryScoped(MODEL_RECORDS_QUERY, {
|
|
72
|
+
modelSlug: "posts",
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Ready-made documents + result types: `SITE_CONFIG_QUERY`,
|
|
77
|
+
`MODEL_DEFINITIONS_QUERY`, `MODEL_RECORDS_QUERY`, `FORM_QUERY`,
|
|
78
|
+
`SUBMIT_FORM_MUTATION`.
|
|
79
|
+
|
|
80
|
+
## Live editor (client)
|
|
81
|
+
|
|
82
|
+
`@cmssy/react/client` exposes the lazy editor + layout wrappers that keep block
|
|
83
|
+
chunks isolated:
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
"use client";
|
|
87
|
+
import { CmssyLazyEditor } from "@cmssy/react/client";
|
|
88
|
+
|
|
89
|
+
export const CmssyEditor = (props) => (
|
|
90
|
+
<CmssyLazyEditor {...props} load={() => import("./blocks")} />
|
|
91
|
+
);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The editor talks to the cmssy admin over the `cmssy:*` bridge protocol for live
|
|
95
|
+
preview.
|
|
96
|
+
|
|
97
|
+
## License
|
|
98
|
+
|
|
99
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmssy/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "React blocks, renderers, data client and editor bridge for cmssy headless sites",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cmssy",
|
|
7
|
+
"cms",
|
|
8
|
+
"headless",
|
|
9
|
+
"react",
|
|
10
|
+
"blocks",
|
|
11
|
+
"graphql"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://cmssy.com",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/cmssy-io/cmssy-sdk.git",
|
|
17
|
+
"directory": "packages/react"
|
|
18
|
+
},
|
|
4
19
|
"type": "module",
|
|
5
20
|
"license": "MIT",
|
|
6
21
|
"publishConfig": {
|