@nitrogenbuilder/connector-payload 0.1.6 → 0.1.9
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,17 +1,30 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useState, useEffect } from "react";
|
|
4
4
|
export const NitrogenEditButton = ({ collection }) => {
|
|
5
5
|
const [id, setId] = useState(undefined);
|
|
6
6
|
const [token, setToken] = useState(undefined);
|
|
7
7
|
const [hasDevelopmentUrl, setHasDevelopmentUrl] = useState(false);
|
|
8
|
+
const [slug, setSlug] = useState(undefined);
|
|
9
|
+
const [frontendUrl, setFrontendUrl] = useState(undefined);
|
|
8
10
|
useEffect(() => {
|
|
9
11
|
const segments = window.location.pathname.split("/").filter(Boolean);
|
|
10
|
-
|
|
11
|
-
if (
|
|
12
|
-
setId(
|
|
12
|
+
const docId = segments.length >= 4 ? segments[3] : undefined;
|
|
13
|
+
if (docId) {
|
|
14
|
+
setId(docId);
|
|
15
|
+
// Fetch the document to get its slug (for View button)
|
|
16
|
+
fetch(`/api/${collection}/${docId}`)
|
|
17
|
+
.then((res) => res.json())
|
|
18
|
+
.then((data) => {
|
|
19
|
+
if (data.slug) {
|
|
20
|
+
setSlug(data.slug);
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
.catch((err) => {
|
|
24
|
+
console.error("Failed to fetch document:", err);
|
|
25
|
+
});
|
|
13
26
|
}
|
|
14
|
-
// Fetch the connector token from NitrogenSettings global
|
|
27
|
+
// Fetch the connector token and URLs from NitrogenSettings global
|
|
15
28
|
fetch("/api/globals/nitrogen-settings")
|
|
16
29
|
.then((res) => res.json())
|
|
17
30
|
.then((data) => {
|
|
@@ -21,14 +34,17 @@ export const NitrogenEditButton = ({ collection }) => {
|
|
|
21
34
|
if (data.developmentUrl) {
|
|
22
35
|
setHasDevelopmentUrl(true);
|
|
23
36
|
}
|
|
37
|
+
const url = data.frontendUrl;
|
|
38
|
+
if (url) {
|
|
39
|
+
setFrontendUrl(url.replace(/\/$/, ""));
|
|
40
|
+
}
|
|
24
41
|
})
|
|
25
42
|
.catch((err) => {
|
|
26
43
|
console.error("Failed to fetch nitrogen settings:", err);
|
|
27
44
|
});
|
|
28
|
-
}, []);
|
|
45
|
+
}, [collection]);
|
|
29
46
|
if (!id || !token)
|
|
30
47
|
return null;
|
|
31
|
-
// Determine which query param to use based on collection type
|
|
32
48
|
const param = collection === "nitrogen-templates" ? "templateId" : "pageId";
|
|
33
49
|
const baseHref = `/nitrogen-editor?token=${encodeURIComponent(token)}&collection=${encodeURIComponent(collection)}&${param}=${id}`;
|
|
34
50
|
const buttonStyle = {
|
|
@@ -43,11 +59,11 @@ export const NitrogenEditButton = ({ collection }) => {
|
|
|
43
59
|
fontSize: "14px",
|
|
44
60
|
fontWeight: 500,
|
|
45
61
|
};
|
|
46
|
-
|
|
47
|
-
return (_jsx("a", { href: baseHref, target: "_blank", rel: "noopener noreferrer", style: buttonStyle, children: "Edit with Nitrogen" }));
|
|
48
|
-
}
|
|
49
|
-
return (_jsxs("div", { style: { display: "flex", gap: "8px" }, children: [_jsx("a", { href: baseHref, target: "_blank", rel: "noopener noreferrer", style: buttonStyle, children: "Edit (Live)" }), _jsx("a", { href: `${baseHref}&development=true`, target: "_blank", rel: "noopener noreferrer", style: {
|
|
62
|
+
return (_jsxs("div", { style: { display: "flex", gap: "8px", alignItems: "center" }, children: [slug && frontendUrl && (_jsx("a", { href: `${frontendUrl}/${slug}`, target: "_blank", rel: "noopener noreferrer", style: {
|
|
50
63
|
...buttonStyle,
|
|
51
|
-
background: "#
|
|
52
|
-
}, children: "Edit (
|
|
64
|
+
background: "#10b981",
|
|
65
|
+
}, children: "View Page" })), hasDevelopmentUrl ? (_jsxs(_Fragment, { children: [_jsx("a", { href: baseHref, target: "_blank", rel: "noopener noreferrer", style: buttonStyle, children: "Edit (Live)" }), _jsx("a", { href: `${baseHref}&development=true`, target: "_blank", rel: "noopener noreferrer", style: {
|
|
66
|
+
...buttonStyle,
|
|
67
|
+
background: "#374151",
|
|
68
|
+
}, children: "Edit (Dev)" })] })) : (_jsx("a", { href: baseHref, target: "_blank", rel: "noopener noreferrer", style: buttonStyle, children: "Edit with Nitrogen" }))] }));
|
|
53
69
|
};
|
|
@@ -14,7 +14,10 @@ export declare function buildPageResponse(doc: NitrogenPageDoc | NitrogenTemplat
|
|
|
14
14
|
dynamic_data: JsonObject;
|
|
15
15
|
settings: JsonObject;
|
|
16
16
|
nitrogen_settings: {
|
|
17
|
-
variables?:
|
|
17
|
+
variables?: Record<string, {
|
|
18
|
+
type?: string;
|
|
19
|
+
value?: string | boolean;
|
|
20
|
+
}> | Array<{
|
|
18
21
|
name: string;
|
|
19
22
|
value?: string;
|
|
20
23
|
}>;
|
|
@@ -31,7 +34,10 @@ export declare function buildListItemResponse(doc: NitrogenPageDoc | NitrogenTem
|
|
|
31
34
|
content: string;
|
|
32
35
|
settings: JsonObject;
|
|
33
36
|
nitrogen_settings: {
|
|
34
|
-
variables?:
|
|
37
|
+
variables?: Record<string, {
|
|
38
|
+
type?: string;
|
|
39
|
+
value?: string | boolean;
|
|
40
|
+
}> | Array<{
|
|
35
41
|
name: string;
|
|
36
42
|
value?: string;
|
|
37
43
|
}>;
|
|
@@ -19,9 +19,17 @@ export function buildDynamicData(doc, globalSettings) {
|
|
|
19
19
|
: '',
|
|
20
20
|
},
|
|
21
21
|
};
|
|
22
|
-
|
|
22
|
+
const rawVars = globalSettings?.nitrogenConfig?.variables;
|
|
23
|
+
if (rawVars && typeof rawVars === 'object' && !Array.isArray(rawVars)) {
|
|
23
24
|
const vars = {};
|
|
24
|
-
for (const
|
|
25
|
+
for (const [name, variable] of Object.entries(rawVars)) {
|
|
26
|
+
vars[name] = String(variable?.value ?? '');
|
|
27
|
+
}
|
|
28
|
+
dynamicData['Global Variables'] = vars;
|
|
29
|
+
}
|
|
30
|
+
else if (Array.isArray(rawVars)) {
|
|
31
|
+
const vars = {};
|
|
32
|
+
for (const item of rawVars) {
|
|
25
33
|
if (item.name) {
|
|
26
34
|
vars[item.name] = item.value ?? '';
|
|
27
35
|
}
|
package/dist/index.js
CHANGED
|
@@ -108,10 +108,6 @@ export const nitrogenConnectorPlugin = (options = {}) => (incomingConfig) => {
|
|
|
108
108
|
...edit,
|
|
109
109
|
beforeDocumentControls: [
|
|
110
110
|
...beforeControls,
|
|
111
|
-
{
|
|
112
|
-
path: "@nitrogenbuilder/connector-payload/components/NitrogenViewButton#NitrogenViewButton",
|
|
113
|
-
clientProps: { collection: slug },
|
|
114
|
-
},
|
|
115
111
|
{
|
|
116
112
|
path: "@nitrogenbuilder/connector-payload/components/NitrogenEditButton#NitrogenEditButton",
|
|
117
113
|
clientProps: { collection: slug },
|
package/dist/types.d.ts
CHANGED
|
@@ -38,7 +38,10 @@ export interface NitrogenSettingsGlobal {
|
|
|
38
38
|
nitrogenConfig?: NitrogenConfig;
|
|
39
39
|
}
|
|
40
40
|
export interface NitrogenConfig {
|
|
41
|
-
variables?:
|
|
41
|
+
variables?: Record<string, {
|
|
42
|
+
type?: string;
|
|
43
|
+
value?: string | boolean;
|
|
44
|
+
}> | Array<{
|
|
42
45
|
name: string;
|
|
43
46
|
value?: string;
|
|
44
47
|
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nitrogenbuilder/connector-payload",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
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",
|
|
@@ -46,4 +46,4 @@
|
|
|
46
46
|
"@nitrogenbuilder/client-core": "link:../monogen/packages/client-core",
|
|
47
47
|
"@nitrogenbuilder/types": "link:../monogen/packages/types"
|
|
48
48
|
}
|
|
49
|
-
}
|
|
49
|
+
}
|