@nitrogenbuilder/connector-payload 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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SanitizedConfig } from 'payload';
|
|
1
2
|
interface NitrogenEditorSearchParams {
|
|
2
3
|
pageId?: string;
|
|
3
4
|
templateId?: string;
|
|
@@ -5,16 +6,17 @@ interface NitrogenEditorSearchParams {
|
|
|
5
6
|
development?: string;
|
|
6
7
|
}
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
+
* Creates a standalone editor page that loads the Nitrogen builder.
|
|
9
10
|
*
|
|
10
11
|
* Mount this in your Next.js app at e.g. `app/(app)/nitrogen-editor/page.tsx`:
|
|
11
12
|
*
|
|
12
|
-
* import {
|
|
13
|
-
*
|
|
13
|
+
* import { createNitrogenEditorPage } from '@nitrogenbuilder/connector-payload/editor'
|
|
14
|
+
* import configPromise from '@payload-config'
|
|
15
|
+
* export default createNitrogenEditorPage(configPromise)
|
|
14
16
|
*
|
|
15
17
|
* Accessible at `/nitrogen-editor?pageId=xxx` or `/nitrogen-editor?templateId=xxx`.
|
|
16
18
|
*/
|
|
17
|
-
export
|
|
19
|
+
export declare function createNitrogenEditorPage(config: Promise<SanitizedConfig>): ({ searchParams, }: {
|
|
18
20
|
searchParams: Promise<NitrogenEditorSearchParams>;
|
|
19
|
-
})
|
|
21
|
+
}) => Promise<import("react/jsx-runtime").JSX.Element>;
|
|
20
22
|
export {};
|
|
@@ -3,85 +3,86 @@ import { getPayload } from 'payload';
|
|
|
3
3
|
import { headers } from 'next/headers';
|
|
4
4
|
import { redirect } from 'next/navigation';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Creates a standalone editor page that loads the Nitrogen builder.
|
|
7
7
|
*
|
|
8
8
|
* Mount this in your Next.js app at e.g. `app/(app)/nitrogen-editor/page.tsx`:
|
|
9
9
|
*
|
|
10
|
-
* import {
|
|
11
|
-
*
|
|
10
|
+
* import { createNitrogenEditorPage } from '@nitrogenbuilder/connector-payload/editor'
|
|
11
|
+
* import configPromise from '@payload-config'
|
|
12
|
+
* export default createNitrogenEditorPage(configPromise)
|
|
12
13
|
*
|
|
13
14
|
* Accessible at `/nitrogen-editor?pageId=xxx` or `/nitrogen-editor?templateId=xxx`.
|
|
14
15
|
*/
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
16
|
+
export function createNitrogenEditorPage(config) {
|
|
17
|
+
return async function NitrogenEditorPage({ searchParams, }) {
|
|
18
|
+
const payload = await getPayload({ config });
|
|
19
|
+
const params = await searchParams;
|
|
20
|
+
// Authenticate — redirect to login if not authenticated
|
|
21
|
+
const headersList = await headers();
|
|
22
|
+
const { user } = await payload.auth({ headers: headersList });
|
|
23
|
+
if (!user) {
|
|
24
|
+
return redirect('/admin/login');
|
|
25
|
+
}
|
|
26
|
+
// Load global settings
|
|
27
|
+
const settings = (await payload.findGlobal({
|
|
28
|
+
slug: 'nitrogen-settings',
|
|
29
|
+
}));
|
|
30
|
+
const isDevelopment = params.development === 'true';
|
|
31
|
+
const siteUrl = isDevelopment ? settings.developmentUrl : settings.frontendUrl;
|
|
32
|
+
const nitrogenConfig = settings.nitrogenConfig || {};
|
|
33
|
+
// Determine the postType for the editor's API calls
|
|
34
|
+
let postType;
|
|
35
|
+
if (params.collection) {
|
|
36
|
+
postType = params.collection;
|
|
37
|
+
}
|
|
38
|
+
else if (params.templateId) {
|
|
39
|
+
postType = 'nitrogen-templates';
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
return redirect('/admin');
|
|
43
|
+
}
|
|
44
|
+
// Build the config object the builder reads from window.nitrogenConfig
|
|
45
|
+
const builderConfig = {
|
|
46
|
+
licenseKey: settings.licenseKey || '',
|
|
47
|
+
provider: {
|
|
48
|
+
type: 'payload',
|
|
49
|
+
apiUrl: '/api/nitrogen/v1',
|
|
50
|
+
collection: postType,
|
|
51
|
+
},
|
|
52
|
+
siteUrl: siteUrl || '',
|
|
53
|
+
urlMaps: nitrogenConfig.urlMaps || [],
|
|
54
|
+
wysiwygColors: nitrogenConfig.wysiwygColors || {},
|
|
55
|
+
cssInjection: nitrogenConfig.cssInjection || '',
|
|
56
|
+
};
|
|
57
|
+
const editId = params.templateId || params.pageId || '';
|
|
58
|
+
const isEditorDev = process.env.NITROGEN_EDITOR_DEV === 'true';
|
|
59
|
+
const viteOrigin = 'http://localhost:5173';
|
|
60
|
+
const cdnBase = 'https://cdn.jsdelivr.net/npm/@nitrogenbuilder/editor@0.4';
|
|
61
|
+
return (_jsxs(_Fragment, { children: [isEditorDev ? (_jsxs(_Fragment, { children: [_jsx("link", { rel: "stylesheet", crossOrigin: "", href: `${viteOrigin}/fa620pro/css/all.css` }), _jsx("link", { rel: "stylesheet", crossOrigin: "", href: `${viteOrigin}/fa620pro/css/sharp-solid.css` }), _jsx("link", { rel: "stylesheet", crossOrigin: "", href: `${viteOrigin}/src/index.scss` })] })) : (_jsxs(_Fragment, { children: [_jsx("link", { rel: "stylesheet", crossOrigin: "", href: `${cdnBase}/fa620pro/css/all.css` }), _jsx("link", { rel: "stylesheet", crossOrigin: "", href: `${cdnBase}/fa620pro/css/sharp-solid.css` }), _jsx("link", { rel: "stylesheet", crossOrigin: "", href: `${cdnBase}/index.css` })] })), _jsx("script", { dangerouslySetInnerHTML: {
|
|
62
|
+
__html: [
|
|
63
|
+
`window.nitrogenConfig = ${JSON.stringify(builderConfig)};`,
|
|
64
|
+
`window.nitrogenEditId = "${editId}";`,
|
|
65
|
+
// Inject authorId into the URL so the editor can read it from window.location.search
|
|
66
|
+
`(function(){var u=new URL(window.location.href);if(!u.searchParams.has("authorId")){u.searchParams.set("authorId",${JSON.stringify(String(user.id))});window.history.replaceState(null,"",u.toString())}})();`,
|
|
67
|
+
].join(''),
|
|
68
|
+
} }), _jsxs("div", { id: "root", children: [_jsx("div", { style: {
|
|
69
|
+
position: 'fixed',
|
|
70
|
+
inset: 0,
|
|
71
|
+
zIndex: 9999999,
|
|
72
|
+
display: 'flex',
|
|
73
|
+
alignItems: 'center',
|
|
74
|
+
justifyContent: 'center',
|
|
75
|
+
backgroundColor: '#0F1214',
|
|
76
|
+
}, children: _jsx("img", { src: isEditorDev
|
|
77
|
+
? `${viteOrigin}/src/components/logo-white.svg`
|
|
78
|
+
: `${cdnBase}/logo-white.svg`, alt: "Loading\u2026", style: {
|
|
79
|
+
width: '24rem',
|
|
80
|
+
maxWidth: '100%',
|
|
81
|
+
animation: 'nitrogen-loader-pulse 3s ease-in-out infinite',
|
|
82
|
+
} }) }), _jsx("style", { dangerouslySetInnerHTML: {
|
|
83
|
+
__html: `@keyframes nitrogen-loader-pulse{0%{transform:scale(1);opacity:0}50%{opacity:1}100%{transform:scale(1.05);opacity:0}}`,
|
|
84
|
+
} })] }), isEditorDev ? (_jsxs(_Fragment, { children: [_jsx("script", { type: "module", dangerouslySetInnerHTML: {
|
|
85
|
+
__html: `import RefreshRuntime from "${viteOrigin}/@react-refresh";RefreshRuntime.injectIntoGlobalHook(window);window.$RefreshReg$ = () => {};window.$RefreshSig$ = () => (type) => type;window.__vite_plugin_react_preamble_installed__ = true;`,
|
|
86
|
+
} }), _jsx("script", { type: "module", src: `${viteOrigin}/@vite/client` }), _jsx("script", { type: "module", crossOrigin: "", src: `${viteOrigin}/src/main.tsx` })] })) : (_jsx("script", { type: "module", crossOrigin: "", src: `${cdnBase}/index.js` }))] }));
|
|
56
87
|
};
|
|
57
|
-
const editId = params.templateId || params.pageId || '';
|
|
58
|
-
const isEditorDev = process.env.NITROGEN_EDITOR_DEV === 'true';
|
|
59
|
-
const viteOrigin = 'http://localhost:5173';
|
|
60
|
-
const cdnBase = 'https://cdn.jsdelivr.net/npm/@nitrogenbuilder/editor@0.4';
|
|
61
|
-
return (_jsxs(_Fragment, { children: [isEditorDev ? (_jsxs(_Fragment, { children: [_jsx("link", { rel: "stylesheet", crossOrigin: "", href: `${viteOrigin}/fa620pro/css/all.css` }), _jsx("link", { rel: "stylesheet", crossOrigin: "", href: `${viteOrigin}/fa620pro/css/sharp-solid.css` }), _jsx("link", { rel: "stylesheet", crossOrigin: "", href: `${viteOrigin}/src/index.scss` })] })) : (_jsxs(_Fragment, { children: [_jsx("link", { rel: "stylesheet", crossOrigin: "", href: `${cdnBase}/fa620pro/css/all.css` }), _jsx("link", { rel: "stylesheet", crossOrigin: "", href: `${cdnBase}/fa620pro/css/sharp-solid.css` }), _jsx("link", { rel: "stylesheet", crossOrigin: "", href: `${cdnBase}/index.css` })] })), _jsx("script", { dangerouslySetInnerHTML: {
|
|
62
|
-
__html: [
|
|
63
|
-
`window.nitrogenConfig = ${JSON.stringify(builderConfig)};`,
|
|
64
|
-
`window.nitrogenEditId = "${editId}";`,
|
|
65
|
-
// Inject authorId into the URL so the editor can read it from window.location.search
|
|
66
|
-
`(function(){var u=new URL(window.location.href);if(!u.searchParams.has("authorId")){u.searchParams.set("authorId",${JSON.stringify(String(user.id))});window.history.replaceState(null,"",u.toString())}})();`,
|
|
67
|
-
].join(''),
|
|
68
|
-
} }), _jsxs("div", { id: "root", children: [_jsx("div", { style: {
|
|
69
|
-
position: 'fixed',
|
|
70
|
-
inset: 0,
|
|
71
|
-
zIndex: 9999999,
|
|
72
|
-
display: 'flex',
|
|
73
|
-
alignItems: 'center',
|
|
74
|
-
justifyContent: 'center',
|
|
75
|
-
backgroundColor: '#0F1214',
|
|
76
|
-
}, children: _jsx("img", { src: isEditorDev
|
|
77
|
-
? `${viteOrigin}/src/components/logo-white.svg`
|
|
78
|
-
: `${cdnBase}/logo-white.svg`, alt: "Loading\u2026", style: {
|
|
79
|
-
width: '24rem',
|
|
80
|
-
maxWidth: '100%',
|
|
81
|
-
animation: 'nitrogen-loader-pulse 3s ease-in-out infinite',
|
|
82
|
-
} }) }), _jsx("style", { dangerouslySetInnerHTML: {
|
|
83
|
-
__html: `@keyframes nitrogen-loader-pulse{0%{transform:scale(1);opacity:0}50%{opacity:1}100%{transform:scale(1.05);opacity:0}}`,
|
|
84
|
-
} })] }), isEditorDev ? (_jsxs(_Fragment, { children: [_jsx("script", { type: "module", dangerouslySetInnerHTML: {
|
|
85
|
-
__html: `import RefreshRuntime from "${viteOrigin}/@react-refresh";RefreshRuntime.injectIntoGlobalHook(window);window.$RefreshReg$ = () => {};window.$RefreshSig$ = () => (type) => type;window.__vite_plugin_react_preamble_installed__ = true;`,
|
|
86
|
-
} }), _jsx("script", { type: "module", src: `${viteOrigin}/@vite/client` }), _jsx("script", { type: "module", crossOrigin: "", src: `${viteOrigin}/src/main.tsx` })] })) : (_jsx("script", { type: "module", crossOrigin: "", src: `${cdnBase}/index.js` }))] }));
|
|
87
88
|
}
|
package/dist/editor/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createNitrogenEditorPage } from './NitrogenEditorPage';
|
|
2
2
|
export { default as NitrogenEditorLayout } from './NitrogenEditorLayout';
|
package/dist/editor/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createNitrogenEditorPage } from './NitrogenEditorPage';
|
|
2
2
|
export { default as NitrogenEditorLayout } from './NitrogenEditorLayout';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import type { SanitizedConfig } from 'payload';
|
|
2
3
|
import type { BuilderModule } from '@nitrogenbuilder/types';
|
|
3
4
|
export interface NitrogenWrapperProps {
|
|
4
5
|
/**
|
|
@@ -17,6 +18,10 @@ export interface NitrogenWrapperProps {
|
|
|
17
18
|
* The Payload collection this page belongs to.
|
|
18
19
|
*/
|
|
19
20
|
collection: string;
|
|
21
|
+
/**
|
|
22
|
+
* The Payload config promise. Import from '@payload-config' in your app and pass it here.
|
|
23
|
+
*/
|
|
24
|
+
config: Promise<SanitizedConfig>;
|
|
20
25
|
/**
|
|
21
26
|
* Regular page content to render when not in Nitrogen mode.
|
|
22
27
|
*/
|
|
@@ -41,5 +46,5 @@ export interface NitrogenWrapperProps {
|
|
|
41
46
|
* }
|
|
42
47
|
* ```
|
|
43
48
|
*/
|
|
44
|
-
export declare function NitrogenWrapper({ page, searchParams, collection, children, }: NitrogenWrapperProps): Promise<import("react/jsx-runtime").JSX.Element>;
|
|
49
|
+
export declare function NitrogenWrapper({ page, searchParams, collection, config, children, }: NitrogenWrapperProps): Promise<import("react/jsx-runtime").JSX.Element>;
|
|
45
50
|
export default NitrogenWrapper;
|
|
@@ -21,7 +21,7 @@ import { buildDynamicData, getNitrogenSettings } from '../endpoints/helpers';
|
|
|
21
21
|
* }
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
export async function NitrogenWrapper({ page, searchParams, collection, children, }) {
|
|
24
|
+
export async function NitrogenWrapper({ page, searchParams, collection, config, children, }) {
|
|
25
25
|
const isBuilder = searchParams['nitrogen-builder'] !== undefined;
|
|
26
26
|
const hasNitrogenData = Array.isArray(page.nitrogenData) && page.nitrogenData.length > 0;
|
|
27
27
|
// If not in builder mode and no Nitrogen data, render regular content
|
|
@@ -29,8 +29,7 @@ export async function NitrogenWrapper({ page, searchParams, collection, children
|
|
|
29
29
|
return _jsx(_Fragment, { children: children });
|
|
30
30
|
}
|
|
31
31
|
// Fetch Nitrogen settings and build dynamic data
|
|
32
|
-
const
|
|
33
|
-
const payload = await getPayload({ config: payloadConfig });
|
|
32
|
+
const payload = await getPayload({ config });
|
|
34
33
|
const settings = await getNitrogenSettings(payload);
|
|
35
34
|
const dynamicData = buildDynamicData(page, settings);
|
|
36
35
|
return (_jsx(NitrogenPageClient, { pageId: String(page.id), pageData: page.nitrogenData || [], dynamicData: dynamicData, isBuilder: isBuilder, collection: collection }));
|
package/package.json
CHANGED