@nitrogenbuilder/connector-payload 0.1.20 → 0.1.22
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,12 +1,23 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as _jsx,
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useState, useEffect } from 'react';
|
|
4
4
|
import { Button } from '@payloadcms/ui';
|
|
5
|
-
import { nitrogenButtonGroupStyle, nitrogenEditDevButtonVars, nitrogenEditLiveButtonVars,
|
|
5
|
+
import { nitrogenButtonGroupStyle, nitrogenEditDevButtonVars, nitrogenEditLiveButtonVars, nitrogenViewButtonVars, } from './nitrogenAdminButtonStyles';
|
|
6
|
+
function isLocalAdminHost() {
|
|
7
|
+
const hostname = window.location.hostname;
|
|
8
|
+
return (hostname === 'localhost' ||
|
|
9
|
+
hostname === '127.0.0.1' ||
|
|
10
|
+
hostname === '[::1]');
|
|
11
|
+
}
|
|
12
|
+
function getPreferredSiteUrl(data) {
|
|
13
|
+
const isLocalAdmin = isLocalAdminHost();
|
|
14
|
+
const preferredUrl = isLocalAdmin ? data.developmentUrl : data.frontendUrl;
|
|
15
|
+
const fallbackUrl = isLocalAdmin ? data.frontendUrl : data.developmentUrl;
|
|
16
|
+
return preferredUrl || fallbackUrl || '';
|
|
17
|
+
}
|
|
6
18
|
export const NitrogenEditButtonRuntime = ({ collection }) => {
|
|
7
19
|
const [id, setId] = useState(undefined);
|
|
8
20
|
const [token, setToken] = useState(undefined);
|
|
9
|
-
const [hasDevelopmentUrl, setHasDevelopmentUrl] = useState(false);
|
|
10
21
|
const [slug, setSlug] = useState(undefined);
|
|
11
22
|
const [frontendUrl, setFrontendUrl] = useState(undefined);
|
|
12
23
|
const [instanceUrl, setInstanceUrl] = useState(undefined);
|
|
@@ -43,13 +54,10 @@ export const NitrogenEditButtonRuntime = ({ collection }) => {
|
|
|
43
54
|
if (data.connectorToken) {
|
|
44
55
|
setToken(data.connectorToken);
|
|
45
56
|
}
|
|
46
|
-
if (data.developmentUrl) {
|
|
47
|
-
setHasDevelopmentUrl(true);
|
|
48
|
-
}
|
|
49
57
|
if (data.instanceUrl) {
|
|
50
58
|
setInstanceUrl(data.instanceUrl.replace(/\/$/, ''));
|
|
51
59
|
}
|
|
52
|
-
const url = data
|
|
60
|
+
const url = getPreferredSiteUrl(data);
|
|
53
61
|
if (url) {
|
|
54
62
|
setFrontendUrl(url.replace(/\/$/, ''));
|
|
55
63
|
}
|
|
@@ -62,14 +70,14 @@ export const NitrogenEditButtonRuntime = ({ collection }) => {
|
|
|
62
70
|
return null;
|
|
63
71
|
const param = collection === 'nitrogen-templates' ? 'templateId' : 'pageId';
|
|
64
72
|
const editorBase = instanceUrl ?? '';
|
|
65
|
-
const
|
|
73
|
+
const isDevelopmentMode = isLocalAdminHost();
|
|
74
|
+
const editHref = `${editorBase}/nitrogen-editor?token=${encodeURIComponent(token)}&collection=${encodeURIComponent(collection)}&${param}=${id}&authorId=${encodeURIComponent(authorId)}${isDevelopmentMode ? '&development=true' : ''}`;
|
|
75
|
+
const editButtonVars = isDevelopmentMode
|
|
76
|
+
? nitrogenEditDevButtonVars
|
|
77
|
+
: nitrogenEditLiveButtonVars;
|
|
66
78
|
return (_jsxs("div", { style: nitrogenButtonGroupStyle, children: [slug && frontendUrl && (_jsx(Button, { buttonStyle: "primary", el: "anchor", margin: false, newTab: true, url: `${frontendUrl}/${slug}`, extraButtonProps: {
|
|
67
79
|
style: nitrogenViewButtonVars,
|
|
68
|
-
}, children: "View Page" })),
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
style: nitrogenEditDevButtonVars,
|
|
72
|
-
}, children: "Edit (Dev)" })] })) : (_jsx(Button, { buttonStyle: "secondary", el: "anchor", margin: false, newTab: true, url: baseHref, extraButtonProps: {
|
|
73
|
-
style: nitrogenSecondaryButtonVars,
|
|
74
|
-
}, children: "Edit with Nitrogen" }))] }));
|
|
80
|
+
}, children: "View Page" })), _jsx(Button, { buttonStyle: "primary", el: "anchor", margin: false, newTab: true, url: editHref, extraButtonProps: {
|
|
81
|
+
style: editButtonVars,
|
|
82
|
+
}, children: "Edit with Nitrogen" })] }));
|
|
75
83
|
};
|
|
@@ -3,9 +3,18 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
3
3
|
import { useState, useEffect } from 'react';
|
|
4
4
|
import { Button } from '@payloadcms/ui';
|
|
5
5
|
import { nitrogenViewButtonVars } from './nitrogenAdminButtonStyles';
|
|
6
|
+
function getPreferredSiteUrl(data) {
|
|
7
|
+
const hostname = window.location.hostname;
|
|
8
|
+
const isLocalAdmin = hostname === 'localhost' ||
|
|
9
|
+
hostname === '127.0.0.1' ||
|
|
10
|
+
hostname === '[::1]';
|
|
11
|
+
const preferredUrl = isLocalAdmin ? data.developmentUrl : data.frontendUrl;
|
|
12
|
+
const fallbackUrl = isLocalAdmin ? data.frontendUrl : data.developmentUrl;
|
|
13
|
+
return preferredUrl || fallbackUrl || '';
|
|
14
|
+
}
|
|
6
15
|
export const NitrogenViewButtonRuntime = ({ collection }) => {
|
|
7
16
|
const [slug, setSlug] = useState(undefined);
|
|
8
|
-
const [
|
|
17
|
+
const [siteUrl, setSiteUrl] = useState(undefined);
|
|
9
18
|
useEffect(() => {
|
|
10
19
|
const segments = window.location.pathname.split('/').filter(Boolean);
|
|
11
20
|
const docId = segments.length >= 4 ? segments[3] : undefined;
|
|
@@ -24,19 +33,19 @@ export const NitrogenViewButtonRuntime = ({ collection }) => {
|
|
|
24
33
|
fetch('/api/globals/nitrogen-settings')
|
|
25
34
|
.then((res) => res.json())
|
|
26
35
|
.then((data) => {
|
|
27
|
-
const url = data
|
|
36
|
+
const url = getPreferredSiteUrl(data);
|
|
28
37
|
if (url) {
|
|
29
|
-
|
|
38
|
+
setSiteUrl(url.replace(/\/$/, ''));
|
|
30
39
|
}
|
|
31
40
|
})
|
|
32
41
|
.catch((err) => {
|
|
33
42
|
console.error('Failed to fetch nitrogen settings:', err);
|
|
34
43
|
});
|
|
35
44
|
}, [collection]);
|
|
36
|
-
if (!slug || !
|
|
45
|
+
if (!slug || !siteUrl) {
|
|
37
46
|
return null;
|
|
38
47
|
}
|
|
39
|
-
const href = `${
|
|
48
|
+
const href = `${siteUrl}/${slug}`;
|
|
40
49
|
return (_jsx(Button, { buttonStyle: "primary", el: "anchor", margin: false, newTab: true, url: href, extraButtonProps: {
|
|
41
50
|
style: nitrogenViewButtonVars,
|
|
42
51
|
}, children: "View Page" }));
|
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { getPayload } from
|
|
3
|
-
import { headers } from
|
|
4
|
-
import { redirect } from
|
|
2
|
+
import { getPayload } from "payload";
|
|
3
|
+
import { headers } from "next/headers";
|
|
4
|
+
import { redirect } from "next/navigation";
|
|
5
|
+
function getNitrogenApiUrl(isDevelopment) {
|
|
6
|
+
if (isDevelopment) {
|
|
7
|
+
return "/api/nitrogen/v1";
|
|
8
|
+
}
|
|
9
|
+
const configuredBase = process.env.NEXT_PUBLIC_PAYLOAD_API_URL ||
|
|
10
|
+
process.env.NEXT_PUBLIC_SERVER_URL ||
|
|
11
|
+
"";
|
|
12
|
+
if (!configuredBase) {
|
|
13
|
+
return "/api/nitrogen/v1";
|
|
14
|
+
}
|
|
15
|
+
const normalizedBase = configuredBase.replace(/\/$/, "");
|
|
16
|
+
if (normalizedBase.endsWith("/api/nitrogen/v1")) {
|
|
17
|
+
return normalizedBase;
|
|
18
|
+
}
|
|
19
|
+
return `${normalizedBase}/api/nitrogen/v1`;
|
|
20
|
+
}
|
|
5
21
|
/**
|
|
6
22
|
* Creates a standalone editor page that loads the Nitrogen builder.
|
|
7
23
|
*
|
|
@@ -21,14 +37,16 @@ export function createNitrogenEditorPage(config) {
|
|
|
21
37
|
const headersList = await headers();
|
|
22
38
|
const { user } = await payload.auth({ headers: headersList });
|
|
23
39
|
if (!user) {
|
|
24
|
-
return redirect(
|
|
40
|
+
return redirect("/admin/login");
|
|
25
41
|
}
|
|
26
42
|
// Load global settings
|
|
27
43
|
const settings = (await payload.findGlobal({
|
|
28
|
-
slug:
|
|
44
|
+
slug: "nitrogen-settings",
|
|
29
45
|
}));
|
|
30
|
-
const isDevelopment = params.development ===
|
|
31
|
-
const siteUrl = isDevelopment
|
|
46
|
+
const isDevelopment = params.development === "true";
|
|
47
|
+
const siteUrl = isDevelopment
|
|
48
|
+
? settings.developmentUrl
|
|
49
|
+
: settings.frontendUrl;
|
|
32
50
|
const nitrogenConfig = settings.nitrogenConfig || {};
|
|
33
51
|
// Determine the postType for the editor's API calls
|
|
34
52
|
let postType;
|
|
@@ -36,49 +54,49 @@ export function createNitrogenEditorPage(config) {
|
|
|
36
54
|
postType = params.collection;
|
|
37
55
|
}
|
|
38
56
|
else if (params.templateId) {
|
|
39
|
-
postType =
|
|
57
|
+
postType = "nitrogen-templates";
|
|
40
58
|
}
|
|
41
59
|
else {
|
|
42
|
-
return redirect(
|
|
60
|
+
return redirect("/admin");
|
|
43
61
|
}
|
|
44
62
|
// Build the config object the builder reads from window.nitrogenConfig
|
|
45
63
|
const builderConfig = {
|
|
46
|
-
licenseKey: settings.licenseKey ||
|
|
64
|
+
licenseKey: settings.licenseKey || "",
|
|
47
65
|
provider: {
|
|
48
|
-
type:
|
|
49
|
-
apiUrl:
|
|
66
|
+
type: "payload",
|
|
67
|
+
apiUrl: getNitrogenApiUrl(isDevelopment),
|
|
50
68
|
collection: postType,
|
|
51
69
|
},
|
|
52
|
-
siteUrl: siteUrl ||
|
|
70
|
+
siteUrl: siteUrl || "",
|
|
53
71
|
urlMaps: nitrogenConfig.urlMaps || [],
|
|
54
72
|
wysiwygColors: nitrogenConfig.wysiwygColors || {},
|
|
55
|
-
cssInjection: nitrogenConfig.cssInjection ||
|
|
73
|
+
cssInjection: nitrogenConfig.cssInjection || "",
|
|
56
74
|
};
|
|
57
|
-
const editId = params.templateId || params.pageId ||
|
|
75
|
+
const editId = params.templateId || params.pageId || "";
|
|
58
76
|
const isEditorDev = isDevelopment && !!settings.instanceUrl;
|
|
59
|
-
const editorOrigin = settings.instanceUrl?.replace(/\/$/,
|
|
60
|
-
const cdnBase =
|
|
77
|
+
const editorOrigin = settings.instanceUrl?.replace(/\/$/, "") || "";
|
|
78
|
+
const cdnBase = "https://cdn.jsdelivr.net/npm/@nitrogenbuilder/editor@0.5";
|
|
61
79
|
return (_jsxs(_Fragment, { children: [isEditorDev ? (_jsxs(_Fragment, { children: [_jsx("link", { rel: "stylesheet", crossOrigin: "", href: `${editorOrigin}/fa620pro/css/all.css` }), _jsx("link", { rel: "stylesheet", crossOrigin: "", href: `${editorOrigin}/fa620pro/css/sharp-solid.css` }), _jsx("link", { rel: "stylesheet", crossOrigin: "", href: `${editorOrigin}/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
80
|
__html: [
|
|
63
81
|
`window.nitrogenConfig = ${JSON.stringify(builderConfig)};`,
|
|
64
82
|
`window.nitrogenEditId = "${editId}";`,
|
|
65
83
|
// Inject authorId into the URL so the editor can read it from window.location.search
|
|
66
84
|
`(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(
|
|
85
|
+
].join(""),
|
|
68
86
|
} }), _jsxs("div", { id: "root", children: [_jsx("div", { style: {
|
|
69
|
-
position:
|
|
87
|
+
position: "fixed",
|
|
70
88
|
inset: 0,
|
|
71
89
|
zIndex: 9999999,
|
|
72
|
-
display:
|
|
73
|
-
alignItems:
|
|
74
|
-
justifyContent:
|
|
75
|
-
backgroundColor:
|
|
90
|
+
display: "flex",
|
|
91
|
+
alignItems: "center",
|
|
92
|
+
justifyContent: "center",
|
|
93
|
+
backgroundColor: "#0F1214",
|
|
76
94
|
}, children: _jsx("img", { src: isEditorDev
|
|
77
95
|
? `${editorOrigin}/src/components/logo-white.svg`
|
|
78
96
|
: `${cdnBase}/logo-white.svg`, alt: "Loading\u2026", style: {
|
|
79
|
-
width:
|
|
80
|
-
maxWidth:
|
|
81
|
-
animation:
|
|
97
|
+
width: "24rem",
|
|
98
|
+
maxWidth: "100%",
|
|
99
|
+
animation: "nitrogen-loader-pulse 3s ease-in-out infinite",
|
|
82
100
|
} }) }), _jsx("style", { dangerouslySetInnerHTML: {
|
|
83
101
|
__html: `@keyframes nitrogen-loader-pulse{0%{transform:scale(1);opacity:0}50%{opacity:1}100%{transform:scale(1.05);opacity:0}}`,
|
|
84
102
|
} })] }), isEditorDev ? (_jsxs(_Fragment, { children: [_jsx("script", { type: "module", dangerouslySetInnerHTML: {
|
package/package.json
CHANGED