@nitrogenbuilder/connector-payload 0.1.10 → 0.1.12
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
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nitrogenbuilder/connector-payload
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Payload CMS 3.x plugin for visual page building with Nitrogen.
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
This project uses the `nitrogen-connector-payload` plugin for visual page building with Nitrogen. Here's how to install it in a fresh Payload CMS project:
|
|
8
|
-
|
|
9
|
-
### 1. Install Dependencies
|
|
5
|
+
## Install
|
|
10
6
|
|
|
11
7
|
```bash
|
|
12
|
-
pnpm add
|
|
13
|
-
pnpm add @nitrogenbuilder/client-react @nitrogenbuilder/client-core @nitrogenbuilder/types
|
|
8
|
+
pnpm add @nitrogenbuilder/connector-payload
|
|
14
9
|
```
|
|
15
10
|
|
|
16
|
-
|
|
11
|
+
## Setup
|
|
17
12
|
|
|
18
|
-
|
|
13
|
+
### 1. Add the plugin to your Payload config
|
|
19
14
|
|
|
20
15
|
```ts
|
|
21
|
-
import { nitrogenConnectorPlugin } from
|
|
22
|
-
|
|
23
|
-
export
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
]
|
|
16
|
+
import { nitrogenConnectorPlugin } from '@nitrogenbuilder/connector-payload'
|
|
17
|
+
|
|
18
|
+
export default buildConfig({
|
|
19
|
+
plugins: [
|
|
20
|
+
nitrogenConnectorPlugin({
|
|
21
|
+
collections: ['pages', 'posts'], // collections to enable Nitrogen editing on
|
|
22
|
+
}),
|
|
23
|
+
],
|
|
24
|
+
})
|
|
29
25
|
```
|
|
30
26
|
|
|
31
|
-
|
|
27
|
+
The plugin automatically:
|
|
28
|
+
- Injects `nitrogenData` and `pageSettings` JSON fields into each collection
|
|
29
|
+
- Adds an "Edit in Nitrogen" button to each document in the Payload admin
|
|
30
|
+
- Registers the `NitrogenTemplates` collection and `NitrogenSettings` global
|
|
31
|
+
- Creates all required API endpoints under `/api/nitrogen/v1/`
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
### 2. Wrap your page routes
|
|
34
34
|
|
|
35
35
|
```tsx
|
|
36
|
-
import { NitrogenWrapper } from '
|
|
36
|
+
import { NitrogenWrapper } from '@nitrogenbuilder/connector-payload/frontend'
|
|
37
37
|
|
|
38
38
|
export default async function Page({ params, searchParams }) {
|
|
39
39
|
const page = await queryPage(...)
|
|
@@ -41,7 +41,6 @@ export default async function Page({ params, searchParams }) {
|
|
|
41
41
|
|
|
42
42
|
return (
|
|
43
43
|
<NitrogenWrapper page={page} searchParams={search} collection="pages">
|
|
44
|
-
{/* Your regular page content */}
|
|
45
44
|
<RenderHero {...page.hero} />
|
|
46
45
|
<RenderBlocks blocks={page.layout} />
|
|
47
46
|
</NitrogenWrapper>
|
|
@@ -49,53 +48,66 @@ export default async function Page({ params, searchParams }) {
|
|
|
49
48
|
}
|
|
50
49
|
```
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
- Detects when the Nitrogen editor is requesting the page (via `?nitrogen-builder` query param)
|
|
55
|
-
- Checks if the page has Nitrogen data
|
|
56
|
-
- Renders the Nitrogen visual builder when needed, otherwise renders your regular content
|
|
51
|
+
`NitrogenWrapper` detects when the Nitrogen editor is loading the page (via `?nitrogen-builder` query param) and renders the visual builder. Otherwise it renders your normal content.
|
|
57
52
|
|
|
58
|
-
###
|
|
53
|
+
### 3. Register components
|
|
59
54
|
|
|
60
|
-
|
|
55
|
+
Create a client component that registers your Nitrogen components:
|
|
61
56
|
|
|
62
57
|
```tsx
|
|
63
58
|
// src/components/NitrogenComponents.tsx
|
|
64
59
|
"use client";
|
|
65
60
|
|
|
66
|
-
import { nitrogen } from
|
|
67
|
-
import type {
|
|
68
|
-
|
|
69
|
-
ComponentSettingsToProps,
|
|
70
|
-
} from "nitrogen-connector-payload/frontend";
|
|
71
|
-
import MyComponent from "./MyComponent";
|
|
61
|
+
import { nitrogen } from '@nitrogenbuilder/connector-payload'
|
|
62
|
+
import type { ComponentSettings, ComponentSettingsToProps } from '@nitrogenbuilder/connector-payload'
|
|
63
|
+
import MyComponent from './MyComponent'
|
|
72
64
|
|
|
73
65
|
const myComponentSettings = {
|
|
74
66
|
categories: {
|
|
75
67
|
content: {
|
|
76
|
-
label:
|
|
68
|
+
label: 'Content',
|
|
77
69
|
groups: {
|
|
78
70
|
content: {
|
|
79
|
-
label:
|
|
71
|
+
label: 'Content',
|
|
80
72
|
props: {
|
|
81
|
-
title: { type:
|
|
73
|
+
title: { type: 'string', default: 'Hello' },
|
|
82
74
|
},
|
|
83
75
|
},
|
|
84
76
|
},
|
|
85
77
|
},
|
|
86
78
|
},
|
|
87
|
-
} as const satisfies ComponentSettings
|
|
79
|
+
} as const satisfies ComponentSettings
|
|
88
80
|
|
|
89
|
-
|
|
90
|
-
nitrogen.registerModule("my-component", MyComponent, myComponentSettings);
|
|
81
|
+
nitrogen.registerModule('my-component', MyComponent, myComponentSettings)
|
|
91
82
|
|
|
92
|
-
export {}
|
|
83
|
+
export {}
|
|
93
84
|
```
|
|
94
85
|
|
|
95
86
|
Then import it in your page route:
|
|
96
87
|
|
|
97
88
|
```tsx
|
|
98
|
-
import
|
|
89
|
+
import '@/components/NitrogenComponents'
|
|
99
90
|
```
|
|
100
91
|
|
|
101
|
-
|
|
92
|
+
## Plugin Options
|
|
93
|
+
|
|
94
|
+
| Option | Type | Description |
|
|
95
|
+
|--------|------|-------------|
|
|
96
|
+
| `collections` | `string[]` | Slugs of existing Payload collections to enable Nitrogen editing on |
|
|
97
|
+
| `disabled` | `boolean` | Disable the plugin without removing it from config |
|
|
98
|
+
|
|
99
|
+
## Exports
|
|
100
|
+
|
|
101
|
+
| Export | Description |
|
|
102
|
+
|--------|-------------|
|
|
103
|
+
| `nitrogenConnectorPlugin` | The Payload plugin |
|
|
104
|
+
| `NitrogenWrapper` | Frontend wrapper component (from `/frontend`) |
|
|
105
|
+
| `NitrogenPageClient` | Low-level client component (from `/frontend`) |
|
|
106
|
+
| `nitrogen` | Re-export of `@nitrogenbuilder/client-core` |
|
|
107
|
+
| `ComponentSettings` | Type for component settings definitions |
|
|
108
|
+
| `ComponentSettingsToProps` | Type helper to derive props from settings |
|
|
109
|
+
| `NitrogenEditButton` | Admin UI button component |
|
|
110
|
+
| `NitrogenViewButton` | Admin UI view button component |
|
|
111
|
+
| `createCollectionEndpoints` | Factory for generating collection API endpoints |
|
|
112
|
+
| `buildDynamicData` | Helper for building dynamic data in page routes |
|
|
113
|
+
| `getNitrogenSettings` | Helper for fetching Nitrogen global settings |
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export const collectionPickerEndpoints = [
|
|
2
|
+
// GET /api/nitrogen/v1/collection/:slug
|
|
3
|
+
// Generic read-only endpoint for fetching any collection's documents for use
|
|
4
|
+
// in the nitrogen editor's CtrlRelationship control.
|
|
5
|
+
{
|
|
6
|
+
path: '/nitrogen/v1/collection/:slug',
|
|
7
|
+
method: 'get',
|
|
8
|
+
handler: async (req) => {
|
|
9
|
+
const { payload, routeParams } = req;
|
|
10
|
+
const collectionSlug = routeParams?.slug;
|
|
11
|
+
if (!collectionSlug) {
|
|
12
|
+
return Response.json({ error: 'Collection slug is required' }, { status: 400 });
|
|
13
|
+
}
|
|
14
|
+
const url = new URL(req.url || '', 'http://localhost');
|
|
15
|
+
const search = url.searchParams.get('search') || '';
|
|
16
|
+
const page = parseInt(url.searchParams.get('page') || '1', 10);
|
|
17
|
+
const limit = parseInt(url.searchParams.get('limit') || '50', 10);
|
|
18
|
+
const depth = parseInt(url.searchParams.get('depth') || '1', 10);
|
|
19
|
+
try {
|
|
20
|
+
const where = {};
|
|
21
|
+
if (search) {
|
|
22
|
+
where['or'] = [
|
|
23
|
+
{ title: { contains: search } },
|
|
24
|
+
{ name: { contains: search } },
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
const result = await payload.find({
|
|
28
|
+
collection: collectionSlug,
|
|
29
|
+
where,
|
|
30
|
+
page,
|
|
31
|
+
limit,
|
|
32
|
+
depth,
|
|
33
|
+
overrideAccess: false,
|
|
34
|
+
req,
|
|
35
|
+
});
|
|
36
|
+
return Response.json({
|
|
37
|
+
docs: result.docs,
|
|
38
|
+
totalDocs: result.totalDocs,
|
|
39
|
+
totalPages: result.totalPages,
|
|
40
|
+
page: result.page,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
45
|
+
if (message.includes('not found') || message.includes('Unknown collection')) {
|
|
46
|
+
return Response.json({ error: `Collection "${collectionSlug}" not found` }, { status: 404 });
|
|
47
|
+
}
|
|
48
|
+
return Response.json({ error: message }, { status: 500 });
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nitrogenbuilder/connector-payload",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "Nitrogen page builder connector plugin for Payload CMS 3.x",
|
|
5
5
|
"author": "Leonardo Dentzien <leo@torchmedia.ca>",
|
|
6
6
|
"type": "module",
|
|
@@ -24,11 +24,6 @@
|
|
|
24
24
|
"files": [
|
|
25
25
|
"dist"
|
|
26
26
|
],
|
|
27
|
-
"scripts": {
|
|
28
|
-
"build": "tsc",
|
|
29
|
-
"typecheck": "tsc --noEmit",
|
|
30
|
-
"prepublishOnly": "pnpm build"
|
|
31
|
-
},
|
|
32
27
|
"peerDependencies": {
|
|
33
28
|
"payload": "^3.0.0",
|
|
34
29
|
"next": "^15.0.0",
|
|
@@ -45,5 +40,9 @@
|
|
|
45
40
|
"@nitrogenbuilder/client-react": "link:../monogen/packages/client-react",
|
|
46
41
|
"@nitrogenbuilder/client-core": "link:../monogen/packages/client-core",
|
|
47
42
|
"@nitrogenbuilder/types": "link:../monogen/packages/types"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsc",
|
|
46
|
+
"typecheck": "tsc --noEmit"
|
|
48
47
|
}
|
|
49
|
-
}
|
|
48
|
+
}
|