@nitrogenbuilder/connector-payload 0.1.0
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 +101 -0
- package/dist/collection-registry.d.ts +7 -0
- package/dist/collection-registry.js +12 -0
- package/dist/collections/NitrogenTemplates.d.ts +2 -0
- package/dist/collections/NitrogenTemplates.js +78 -0
- package/dist/components/NitrogenEditButton.d.ts +4 -0
- package/dist/components/NitrogenEditButton.js +43 -0
- package/dist/editor/NitrogenEditorLayout.d.ts +15 -0
- package/dist/editor/NitrogenEditorLayout.js +15 -0
- package/dist/editor/NitrogenEditorPage.d.ts +20 -0
- package/dist/editor/NitrogenEditorPage.js +87 -0
- package/dist/editor/index.d.ts +2 -0
- package/dist/editor/index.js +2 -0
- package/dist/endpoints/all.d.ts +2 -0
- package/dist/endpoints/all.js +48 -0
- package/dist/endpoints/collection-endpoints.d.ts +8 -0
- package/dist/endpoints/collection-endpoints.js +168 -0
- package/dist/endpoints/helpers.d.ts +64 -0
- package/dist/endpoints/helpers.js +104 -0
- package/dist/endpoints/media.d.ts +2 -0
- package/dist/endpoints/media.js +93 -0
- package/dist/endpoints/menu.d.ts +2 -0
- package/dist/endpoints/menu.js +19 -0
- package/dist/endpoints/nitrogen-settings.d.ts +2 -0
- package/dist/endpoints/nitrogen-settings.js +22 -0
- package/dist/endpoints/templates.d.ts +2 -0
- package/dist/endpoints/templates.js +114 -0
- package/dist/frontend/NitrogenPageClient.d.ts +16 -0
- package/dist/frontend/NitrogenPageClient.js +55 -0
- package/dist/frontend/NitrogenWrapper.d.ts +45 -0
- package/dist/frontend/NitrogenWrapper.js +38 -0
- package/dist/frontend/index.d.ts +7 -0
- package/dist/frontend/index.js +8 -0
- package/dist/globals/NitrogenSettings.d.ts +2 -0
- package/dist/globals/NitrogenSettings.js +41 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +140 -0
- package/dist/types.d.ts +125 -0
- package/dist/types.js +7 -0
- package/package.json +49 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Plugin } from "payload";
|
|
2
|
+
export interface NitrogenConnectorPluginOptions {
|
|
3
|
+
/** Disable the plugin without removing it from config */
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Existing Payload collections to enable Nitrogen editing on.
|
|
7
|
+
* The plugin will inject the required fields (nitrogenData, pageSettings, etc.)
|
|
8
|
+
* and generate API endpoints for each collection.
|
|
9
|
+
*
|
|
10
|
+
* Example: `collections: ['pages', 'blog-posts']`
|
|
11
|
+
*/
|
|
12
|
+
collections?: string[];
|
|
13
|
+
}
|
|
14
|
+
export declare const nitrogenConnectorPlugin: (options?: NitrogenConnectorPluginOptions) => Plugin;
|
|
15
|
+
export { NitrogenTemplates } from "./collections/NitrogenTemplates";
|
|
16
|
+
export { NitrogenSettings } from "./globals/NitrogenSettings";
|
|
17
|
+
export { NitrogenEditButton } from "./components/NitrogenEditButton";
|
|
18
|
+
export { buildDynamicData, getNitrogenSettings } from "./endpoints/helpers";
|
|
19
|
+
export { createCollectionEndpoints } from "./endpoints/collection-endpoints";
|
|
20
|
+
export { nitrogen } from "@nitrogenbuilder/client-core";
|
|
21
|
+
export type { ComponentSettings, ComponentSettingsToProps, } from "@nitrogenbuilder/types";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { NitrogenTemplates } from "./collections/NitrogenTemplates";
|
|
2
|
+
import { NitrogenSettings } from "./globals/NitrogenSettings";
|
|
3
|
+
import { templatesEndpoints } from "./endpoints/templates";
|
|
4
|
+
import { mediaEndpoints } from "./endpoints/media";
|
|
5
|
+
import { nitrogenSettingsEndpoints } from "./endpoints/nitrogen-settings";
|
|
6
|
+
import { allEndpoints } from "./endpoints/all";
|
|
7
|
+
import { menuEndpoints } from "./endpoints/menu";
|
|
8
|
+
import { createCollectionEndpoints } from "./endpoints/collection-endpoints";
|
|
9
|
+
import { registerCollection } from "./collection-registry";
|
|
10
|
+
/** Fields required by Nitrogen that will be injected into collections if missing */
|
|
11
|
+
const nitrogenRequiredFields = [
|
|
12
|
+
{
|
|
13
|
+
name: "nitrogenData",
|
|
14
|
+
type: "json",
|
|
15
|
+
admin: { description: "Nitrogen page builder JSON module tree" },
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: "pageSettings",
|
|
19
|
+
type: "json",
|
|
20
|
+
admin: { description: "Page-level Nitrogen settings" },
|
|
21
|
+
},
|
|
22
|
+
{ name: "title", type: "text", required: true },
|
|
23
|
+
{ name: "slug", type: "text", required: true, unique: true, index: true },
|
|
24
|
+
{
|
|
25
|
+
name: "status",
|
|
26
|
+
type: "select",
|
|
27
|
+
options: [
|
|
28
|
+
{ label: "Draft", value: "draft" },
|
|
29
|
+
{ label: "Published", value: "published" },
|
|
30
|
+
],
|
|
31
|
+
defaultValue: "draft",
|
|
32
|
+
},
|
|
33
|
+
{ name: "author", type: "relationship", relationTo: "users" },
|
|
34
|
+
];
|
|
35
|
+
export const nitrogenConnectorPlugin = (options = {}) => (incomingConfig) => {
|
|
36
|
+
if (options.disabled) {
|
|
37
|
+
return incomingConfig;
|
|
38
|
+
}
|
|
39
|
+
const config = { ...incomingConfig };
|
|
40
|
+
// Add Nitrogen templates collection
|
|
41
|
+
config.collections = [...(config.collections || []), NitrogenTemplates];
|
|
42
|
+
// Add Nitrogen global settings
|
|
43
|
+
config.globals = [...(config.globals || []), NitrogenSettings];
|
|
44
|
+
// Add Nitrogen API endpoints
|
|
45
|
+
config.endpoints = [
|
|
46
|
+
...(config.endpoints || []),
|
|
47
|
+
...templatesEndpoints,
|
|
48
|
+
...mediaEndpoints,
|
|
49
|
+
...nitrogenSettingsEndpoints,
|
|
50
|
+
...allEndpoints,
|
|
51
|
+
...menuEndpoints,
|
|
52
|
+
];
|
|
53
|
+
// Register templates collection
|
|
54
|
+
registerCollection("nitrogen-templates", "nitrogen-templates");
|
|
55
|
+
registerCollection("nitrogen_template", "nitrogen-templates");
|
|
56
|
+
// Process collections
|
|
57
|
+
const additionalCollections = options.collections || [];
|
|
58
|
+
for (const slug of additionalCollections) {
|
|
59
|
+
// Find the existing collection in the config
|
|
60
|
+
const existingIndex = (config.collections || []).findIndex((col) => col.slug === slug);
|
|
61
|
+
if (existingIndex === -1) {
|
|
62
|
+
console.warn(`[nitrogen-connector-payload] Collection "${slug}" not found in config. ` +
|
|
63
|
+
`Make sure it is defined before the nitrogen plugin runs.`);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
// Inject missing fields — recurse into rows, tabs, groups, collapsibles
|
|
67
|
+
const existing = config.collections[existingIndex];
|
|
68
|
+
const existingFieldNames = new Set();
|
|
69
|
+
function collectFieldNames(fields) {
|
|
70
|
+
for (const f of fields) {
|
|
71
|
+
if ("name" in f && f.name) {
|
|
72
|
+
existingFieldNames.add(f.name);
|
|
73
|
+
}
|
|
74
|
+
// Recurse into container field types
|
|
75
|
+
if ("fields" in f && Array.isArray(f.fields)) {
|
|
76
|
+
collectFieldNames(f.fields);
|
|
77
|
+
}
|
|
78
|
+
if ("tabs" in f && Array.isArray(f.tabs)) {
|
|
79
|
+
for (const tab of f.tabs) {
|
|
80
|
+
if ("fields" in tab && Array.isArray(tab.fields)) {
|
|
81
|
+
collectFieldNames(tab.fields);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
collectFieldNames(existing.fields);
|
|
88
|
+
const fieldsToAdd = nitrogenRequiredFields.filter((f) => "name" in f && !existingFieldNames.has(f.name));
|
|
89
|
+
if (fieldsToAdd.length > 0) {
|
|
90
|
+
config.collections[existingIndex] = {
|
|
91
|
+
...existing,
|
|
92
|
+
fields: [...existing.fields, ...fieldsToAdd],
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
// Inject NitrogenEditButton admin component
|
|
96
|
+
const col = config.collections[existingIndex];
|
|
97
|
+
const adminConfig = col.admin || {};
|
|
98
|
+
const components = adminConfig.components || {};
|
|
99
|
+
const edit = components.edit || {};
|
|
100
|
+
const beforeControls = "beforeDocumentControls" in edit
|
|
101
|
+
? edit.beforeDocumentControls || []
|
|
102
|
+
: [];
|
|
103
|
+
config.collections[existingIndex] = {
|
|
104
|
+
...col,
|
|
105
|
+
admin: {
|
|
106
|
+
...adminConfig,
|
|
107
|
+
components: {
|
|
108
|
+
...components,
|
|
109
|
+
edit: {
|
|
110
|
+
...edit,
|
|
111
|
+
beforeDocumentControls: [
|
|
112
|
+
...beforeControls,
|
|
113
|
+
{
|
|
114
|
+
path: "nitrogen-connector-payload/components/NitrogenEditButton#NitrogenEditButton",
|
|
115
|
+
clientProps: { collection: slug },
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
// Generate and register endpoints for this collection
|
|
123
|
+
const collectionEndpoints = createCollectionEndpoints(slug, slug);
|
|
124
|
+
config.endpoints = [...(config.endpoints || []), ...collectionEndpoints];
|
|
125
|
+
// Register in the collection registry for the `all` endpoint
|
|
126
|
+
registerCollection(slug, slug);
|
|
127
|
+
}
|
|
128
|
+
return config;
|
|
129
|
+
};
|
|
130
|
+
// Re-export for consumers who need direct access
|
|
131
|
+
export { NitrogenTemplates } from "./collections/NitrogenTemplates";
|
|
132
|
+
export { NitrogenSettings } from "./globals/NitrogenSettings";
|
|
133
|
+
// Editor exports
|
|
134
|
+
export { NitrogenEditButton } from "./components/NitrogenEditButton";
|
|
135
|
+
// Helper exports for consumers building custom frontend routes
|
|
136
|
+
export { buildDynamicData, getNitrogenSettings } from "./endpoints/helpers";
|
|
137
|
+
// Collection endpoint factory for consumers who need custom endpoint generation
|
|
138
|
+
export { createCollectionEndpoints } from "./endpoints/collection-endpoints";
|
|
139
|
+
// Re-export @nitrogenbuilder packages for convenience
|
|
140
|
+
export { nitrogen } from "@nitrogenbuilder/client-core";
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nitrogen Connector — Shared Types
|
|
3
|
+
*
|
|
4
|
+
* Document interfaces matching the Payload collection/global schemas,
|
|
5
|
+
* plus request body shapes used by the API endpoints.
|
|
6
|
+
*/
|
|
7
|
+
import type { BuilderModule } from '@nitrogenbuilder/types';
|
|
8
|
+
export type JsonObject = Record<string, unknown>;
|
|
9
|
+
export type NitrogenModule = BuilderModule;
|
|
10
|
+
interface NitrogenDocBase {
|
|
11
|
+
id: string | number;
|
|
12
|
+
title: string;
|
|
13
|
+
slug: string;
|
|
14
|
+
status?: 'draft' | 'published';
|
|
15
|
+
author?: string | number | {
|
|
16
|
+
id: string | number;
|
|
17
|
+
name?: string;
|
|
18
|
+
email?: string;
|
|
19
|
+
};
|
|
20
|
+
nitrogenData?: JsonObject | JsonObject[];
|
|
21
|
+
createdAt: string;
|
|
22
|
+
updatedAt: string;
|
|
23
|
+
}
|
|
24
|
+
export interface NitrogenPageDoc extends NitrogenDocBase {
|
|
25
|
+
pageSettings?: JsonObject;
|
|
26
|
+
}
|
|
27
|
+
export interface NitrogenTemplateDoc extends NitrogenDocBase {
|
|
28
|
+
templateType?: string;
|
|
29
|
+
associatedCollection?: string;
|
|
30
|
+
templateSettings?: JsonObject;
|
|
31
|
+
}
|
|
32
|
+
export interface NitrogenSettingsGlobal {
|
|
33
|
+
licenseKey?: string;
|
|
34
|
+
connectorToken?: string;
|
|
35
|
+
instanceUrl?: string;
|
|
36
|
+
frontendUrl?: string;
|
|
37
|
+
developmentUrl?: string;
|
|
38
|
+
nitrogenConfig?: NitrogenConfig;
|
|
39
|
+
}
|
|
40
|
+
export interface NitrogenConfig {
|
|
41
|
+
variables?: Array<{
|
|
42
|
+
name: string;
|
|
43
|
+
value?: string;
|
|
44
|
+
}>;
|
|
45
|
+
[key: string]: unknown;
|
|
46
|
+
}
|
|
47
|
+
export interface MediaDoc {
|
|
48
|
+
id: string | number;
|
|
49
|
+
filename?: string;
|
|
50
|
+
mimeType?: string;
|
|
51
|
+
alt?: string;
|
|
52
|
+
url?: string;
|
|
53
|
+
width?: number;
|
|
54
|
+
height?: number;
|
|
55
|
+
filesize?: number;
|
|
56
|
+
sizes?: {
|
|
57
|
+
thumbnail?: MediaSize;
|
|
58
|
+
medium?: MediaSize;
|
|
59
|
+
large?: MediaSize;
|
|
60
|
+
[key: string]: MediaSize | undefined;
|
|
61
|
+
};
|
|
62
|
+
createdAt: string;
|
|
63
|
+
}
|
|
64
|
+
export interface MediaSize {
|
|
65
|
+
url?: string;
|
|
66
|
+
width?: number;
|
|
67
|
+
height?: number;
|
|
68
|
+
}
|
|
69
|
+
export interface PageCreateRequestBody {
|
|
70
|
+
data?: {
|
|
71
|
+
title?: string;
|
|
72
|
+
slug?: string;
|
|
73
|
+
author?: string | number;
|
|
74
|
+
};
|
|
75
|
+
title?: string;
|
|
76
|
+
slug?: string;
|
|
77
|
+
author?: string | number;
|
|
78
|
+
}
|
|
79
|
+
export interface PageUpdateRequestBody {
|
|
80
|
+
data?: PageUpdateData;
|
|
81
|
+
title?: string;
|
|
82
|
+
author?: string | number;
|
|
83
|
+
data_content?: string | JsonObject[];
|
|
84
|
+
settings?: JsonObject;
|
|
85
|
+
}
|
|
86
|
+
interface PageUpdateData {
|
|
87
|
+
title?: string;
|
|
88
|
+
author?: string | number;
|
|
89
|
+
data?: string | JsonObject[];
|
|
90
|
+
settings?: JsonObject;
|
|
91
|
+
}
|
|
92
|
+
export interface TemplateUpdateRequestBody {
|
|
93
|
+
data?: TemplateUpdateData;
|
|
94
|
+
title?: string;
|
|
95
|
+
author?: string | number;
|
|
96
|
+
data_content?: string | JsonObject[];
|
|
97
|
+
templateType?: string;
|
|
98
|
+
settings?: JsonObject;
|
|
99
|
+
}
|
|
100
|
+
interface TemplateUpdateData {
|
|
101
|
+
title?: string;
|
|
102
|
+
author?: string | number;
|
|
103
|
+
data?: string | JsonObject[];
|
|
104
|
+
templateType?: string;
|
|
105
|
+
settings?: JsonObject;
|
|
106
|
+
}
|
|
107
|
+
export interface SlugLookupRequestBody {
|
|
108
|
+
slug?: string;
|
|
109
|
+
data?: {
|
|
110
|
+
slug?: string;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export interface MediaUpdateRequestBody {
|
|
114
|
+
id: string | number;
|
|
115
|
+
alt?: string;
|
|
116
|
+
}
|
|
117
|
+
export interface RenderDataRequestBody {
|
|
118
|
+
pageData?: NitrogenModule[];
|
|
119
|
+
requestedData?: JsonObject & {
|
|
120
|
+
id?: string | number;
|
|
121
|
+
};
|
|
122
|
+
/** Which Payload collection to fetch dynamic data from */
|
|
123
|
+
collection?: string;
|
|
124
|
+
}
|
|
125
|
+
export {};
|
package/dist/types.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nitrogenbuilder/connector-payload",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Nitrogen page builder connector plugin for Payload CMS 3.x",
|
|
5
|
+
"author": "Leonardo Dentzien <leo@torchmedia.ca>",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./editor": {
|
|
15
|
+
"types": "./dist/editor/index.d.ts",
|
|
16
|
+
"default": "./dist/editor/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./frontend": {
|
|
19
|
+
"types": "./dist/frontend/index.d.ts",
|
|
20
|
+
"default": "./dist/frontend/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./components/*": "./dist/components/*"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc",
|
|
29
|
+
"typecheck": "tsc --noEmit",
|
|
30
|
+
"prepublishOnly": "pnpm build"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"payload": "^3.0.0",
|
|
34
|
+
"next": "^15.0.0",
|
|
35
|
+
"react": "^19.0.0",
|
|
36
|
+
"@payloadcms/ui": "^3.0.0",
|
|
37
|
+
"@nitrogenbuilder/client-react": ">=0.3.0",
|
|
38
|
+
"@nitrogenbuilder/client-core": ">=0.3.0",
|
|
39
|
+
"@nitrogenbuilder/types": ">=0.3.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/react": "^19.0.0",
|
|
43
|
+
"@types/node": "^22.0.0",
|
|
44
|
+
"typescript": "^5.7.0",
|
|
45
|
+
"@nitrogenbuilder/client-react": "link:../monogen/packages/client-react",
|
|
46
|
+
"@nitrogenbuilder/client-core": "link:../monogen/packages/client-core",
|
|
47
|
+
"@nitrogenbuilder/types": "link:../monogen/packages/types"
|
|
48
|
+
}
|
|
49
|
+
}
|