@nitrogenbuilder/connector-payload 0.1.20 → 0.1.21
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.
|
@@ -3,6 +3,15 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
3
3
|
import { useState, useEffect } from 'react';
|
|
4
4
|
import { Button } from '@payloadcms/ui';
|
|
5
5
|
import { nitrogenButtonGroupStyle, nitrogenEditDevButtonVars, nitrogenEditLiveButtonVars, nitrogenSecondaryButtonVars, 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 NitrogenEditButtonRuntime = ({ collection }) => {
|
|
7
16
|
const [id, setId] = useState(undefined);
|
|
8
17
|
const [token, setToken] = useState(undefined);
|
|
@@ -49,7 +58,7 @@ export const NitrogenEditButtonRuntime = ({ collection }) => {
|
|
|
49
58
|
if (data.instanceUrl) {
|
|
50
59
|
setInstanceUrl(data.instanceUrl.replace(/\/$/, ''));
|
|
51
60
|
}
|
|
52
|
-
const url = data
|
|
61
|
+
const url = getPreferredSiteUrl(data);
|
|
53
62
|
if (url) {
|
|
54
63
|
setFrontendUrl(url.replace(/\/$/, ''));
|
|
55
64
|
}
|
|
@@ -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,20 @@
|
|
|
1
|
-
import { jsx as _jsx,
|
|
2
|
-
import { getPayload } from
|
|
3
|
-
import { headers } from
|
|
4
|
-
import { redirect } from
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { getPayload } from "payload";
|
|
3
|
+
import { headers } from "next/headers";
|
|
4
|
+
import { redirect } from "next/navigation";
|
|
5
|
+
function getNitrogenApiUrl() {
|
|
6
|
+
const configuredBase = process.env.NEXT_PUBLIC_PAYLOAD_API_URL ||
|
|
7
|
+
process.env.NEXT_PUBLIC_SERVER_URL ||
|
|
8
|
+
"";
|
|
9
|
+
if (!configuredBase) {
|
|
10
|
+
return "/api/nitrogen/v1";
|
|
11
|
+
}
|
|
12
|
+
const normalizedBase = configuredBase.replace(/\/$/, "");
|
|
13
|
+
if (normalizedBase.endsWith("/api/nitrogen/v1")) {
|
|
14
|
+
return normalizedBase;
|
|
15
|
+
}
|
|
16
|
+
return `${normalizedBase}/api/nitrogen/v1`;
|
|
17
|
+
}
|
|
5
18
|
/**
|
|
6
19
|
* Creates a standalone editor page that loads the Nitrogen builder.
|
|
7
20
|
*
|
|
@@ -21,14 +34,16 @@ export function createNitrogenEditorPage(config) {
|
|
|
21
34
|
const headersList = await headers();
|
|
22
35
|
const { user } = await payload.auth({ headers: headersList });
|
|
23
36
|
if (!user) {
|
|
24
|
-
return redirect(
|
|
37
|
+
return redirect("/admin/login");
|
|
25
38
|
}
|
|
26
39
|
// Load global settings
|
|
27
40
|
const settings = (await payload.findGlobal({
|
|
28
|
-
slug:
|
|
41
|
+
slug: "nitrogen-settings",
|
|
29
42
|
}));
|
|
30
|
-
const isDevelopment = params.development ===
|
|
31
|
-
const siteUrl = isDevelopment
|
|
43
|
+
const isDevelopment = params.development === "true";
|
|
44
|
+
const siteUrl = isDevelopment
|
|
45
|
+
? settings.developmentUrl
|
|
46
|
+
: settings.frontendUrl;
|
|
32
47
|
const nitrogenConfig = settings.nitrogenConfig || {};
|
|
33
48
|
// Determine the postType for the editor's API calls
|
|
34
49
|
let postType;
|
|
@@ -36,53 +51,47 @@ export function createNitrogenEditorPage(config) {
|
|
|
36
51
|
postType = params.collection;
|
|
37
52
|
}
|
|
38
53
|
else if (params.templateId) {
|
|
39
|
-
postType =
|
|
54
|
+
postType = "nitrogen-templates";
|
|
40
55
|
}
|
|
41
56
|
else {
|
|
42
|
-
return redirect(
|
|
57
|
+
return redirect("/admin");
|
|
43
58
|
}
|
|
44
59
|
// Build the config object the builder reads from window.nitrogenConfig
|
|
45
60
|
const builderConfig = {
|
|
46
|
-
licenseKey: settings.licenseKey ||
|
|
61
|
+
licenseKey: settings.licenseKey || "",
|
|
47
62
|
provider: {
|
|
48
|
-
type:
|
|
49
|
-
apiUrl:
|
|
63
|
+
type: "payload",
|
|
64
|
+
apiUrl: getNitrogenApiUrl(),
|
|
50
65
|
collection: postType,
|
|
51
66
|
},
|
|
52
|
-
siteUrl: siteUrl ||
|
|
67
|
+
siteUrl: siteUrl || "",
|
|
53
68
|
urlMaps: nitrogenConfig.urlMaps || [],
|
|
54
69
|
wysiwygColors: nitrogenConfig.wysiwygColors || {},
|
|
55
|
-
cssInjection: nitrogenConfig.cssInjection ||
|
|
70
|
+
cssInjection: nitrogenConfig.cssInjection || "",
|
|
56
71
|
};
|
|
57
|
-
const editId = params.templateId || params.pageId ||
|
|
58
|
-
const
|
|
59
|
-
|
|
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: `${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: {
|
|
72
|
+
const editId = params.templateId || params.pageId || "";
|
|
73
|
+
const cdnBase = "https://cdn.jsdelivr.net/npm/@nitrogenbuilder/editor@0.5";
|
|
74
|
+
return (_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
75
|
__html: [
|
|
63
76
|
`window.nitrogenConfig = ${JSON.stringify(builderConfig)};`,
|
|
64
77
|
`window.nitrogenEditId = "${editId}";`,
|
|
65
78
|
// Inject authorId into the URL so the editor can read it from window.location.search
|
|
66
79
|
`(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(
|
|
80
|
+
].join(""),
|
|
68
81
|
} }), _jsxs("div", { id: "root", children: [_jsx("div", { style: {
|
|
69
|
-
position:
|
|
82
|
+
position: "fixed",
|
|
70
83
|
inset: 0,
|
|
71
84
|
zIndex: 9999999,
|
|
72
|
-
display:
|
|
73
|
-
alignItems:
|
|
74
|
-
justifyContent:
|
|
75
|
-
backgroundColor:
|
|
76
|
-
}, children: _jsx("img", { src:
|
|
77
|
-
|
|
78
|
-
:
|
|
79
|
-
|
|
80
|
-
maxWidth: '100%',
|
|
81
|
-
animation: 'nitrogen-loader-pulse 3s ease-in-out infinite',
|
|
85
|
+
display: "flex",
|
|
86
|
+
alignItems: "center",
|
|
87
|
+
justifyContent: "center",
|
|
88
|
+
backgroundColor: "#0F1214",
|
|
89
|
+
}, children: _jsx("img", { src: `${cdnBase}/logo-white.svg`, alt: "Loading\u2026", style: {
|
|
90
|
+
width: "24rem",
|
|
91
|
+
maxWidth: "100%",
|
|
92
|
+
animation: "nitrogen-loader-pulse 3s ease-in-out infinite",
|
|
82
93
|
} }) }), _jsx("style", { dangerouslySetInnerHTML: {
|
|
83
94
|
__html: `@keyframes nitrogen-loader-pulse{0%{transform:scale(1);opacity:0}50%{opacity:1}100%{transform:scale(1.05);opacity:0}}`,
|
|
84
|
-
} })] }),
|
|
85
|
-
__html: `import RefreshRuntime from "${editorOrigin}/@react-refresh";RefreshRuntime.injectIntoGlobalHook(window);window.$RefreshReg$ = () => {};window.$RefreshSig$ = () => (type) => type;window.__vite_plugin_react_preamble_installed__ = true;`,
|
|
86
|
-
} }), _jsx("script", { type: "module", src: `${editorOrigin}/@vite/client` }), _jsx("script", { type: "module", crossOrigin: "", src: `${editorOrigin}/src/main.tsx` })] })) : (_jsx("script", { type: "module", crossOrigin: "", src: `${cdnBase}/index.js` }))] }));
|
|
95
|
+
} })] }), _jsx("script", { type: "module", crossOrigin: "", src: `${cdnBase}/index.js` })] }));
|
|
87
96
|
};
|
|
88
97
|
}
|
package/package.json
CHANGED