@nitrogenbuilder/connector-payload 0.1.1 → 0.1.3
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/dist/collections/NitrogenTemplates.js +1 -1
- package/dist/components/LockedJsonField.d.ts +10 -0
- package/dist/components/LockedJsonField.js +38 -0
- package/dist/components/NitrogenEditButton.js +25 -15
- package/dist/components/NitrogenViewButton.d.ts +4 -0
- package/dist/components/NitrogenViewButton.js +52 -0
- package/dist/editor/NitrogenEditorLayout.d.ts +1 -1
- package/dist/editor/NitrogenEditorLayout.js +1 -1
- package/dist/frontend/NitrogenWrapper.d.ts +1 -1
- package/dist/frontend/NitrogenWrapper.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +18 -15
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@ export const NitrogenTemplates = {
|
|
|
7
7
|
edit: {
|
|
8
8
|
beforeDocumentControls: [
|
|
9
9
|
{
|
|
10
|
-
path: '
|
|
10
|
+
path: '@nitrogenbuilder/connector-payload/components/NitrogenEditButton#NitrogenEditButton',
|
|
11
11
|
clientProps: {
|
|
12
12
|
collection: 'nitrogen-templates',
|
|
13
13
|
},
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { useField } from "@payloadcms/ui";
|
|
5
|
+
export const LockedJsonField = ({ path, field }) => {
|
|
6
|
+
const [unlocked, setUnlocked] = useState(false);
|
|
7
|
+
const { value, setValue } = useField({ path });
|
|
8
|
+
const displayValue = value ? JSON.stringify(value, null, 2) : "";
|
|
9
|
+
return (_jsxs("div", { style: { marginBottom: "1.5rem" }, children: [_jsxs("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: "0.5rem" }, children: [_jsx("label", { style: { fontWeight: 500 }, children: field.name }), _jsx("button", { type: "button", onClick: () => setUnlocked(!unlocked), style: {
|
|
10
|
+
padding: "4px 12px",
|
|
11
|
+
fontSize: "12px",
|
|
12
|
+
background: unlocked ? "#ef4444" : "#6b7280",
|
|
13
|
+
color: "#fff",
|
|
14
|
+
border: "none",
|
|
15
|
+
borderRadius: "4px",
|
|
16
|
+
cursor: "pointer",
|
|
17
|
+
}, children: unlocked ? "Lock" : "Unlock Edit" })] }), _jsx("textarea", { value: displayValue, readOnly: !unlocked, onChange: (e) => {
|
|
18
|
+
if (!unlocked)
|
|
19
|
+
return;
|
|
20
|
+
try {
|
|
21
|
+
setValue(JSON.parse(e.target.value));
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// Allow typing invalid JSON while editing
|
|
25
|
+
}
|
|
26
|
+
}, style: {
|
|
27
|
+
width: "100%",
|
|
28
|
+
minHeight: "120px",
|
|
29
|
+
fontFamily: "monospace",
|
|
30
|
+
fontSize: "12px",
|
|
31
|
+
padding: "8px",
|
|
32
|
+
background: unlocked ? "#1a1a2e" : "#111",
|
|
33
|
+
color: unlocked ? "#e2e8f0" : "#888",
|
|
34
|
+
border: `1px solid ${unlocked ? "#ef4444" : "#333"}`,
|
|
35
|
+
borderRadius: "4px",
|
|
36
|
+
resize: "vertical",
|
|
37
|
+
} }), field.admin?.description && (_jsx("p", { style: { fontSize: "12px", color: "#888", marginTop: "4px" }, children: field.admin.description }))] }));
|
|
38
|
+
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, 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
|
+
const [hasDevelopmentUrl, setHasDevelopmentUrl] = useState(false);
|
|
7
8
|
useEffect(() => {
|
|
8
9
|
const segments = window.location.pathname.split("/").filter(Boolean);
|
|
9
10
|
// segments: ["admin", "collections", "{collection-slug}", "{id}"]
|
|
@@ -17,6 +18,9 @@ export const NitrogenEditButton = ({ collection }) => {
|
|
|
17
18
|
if (data.connectorToken) {
|
|
18
19
|
setToken(data.connectorToken);
|
|
19
20
|
}
|
|
21
|
+
if (data.developmentUrl) {
|
|
22
|
+
setHasDevelopmentUrl(true);
|
|
23
|
+
}
|
|
20
24
|
})
|
|
21
25
|
.catch((err) => {
|
|
22
26
|
console.error("Failed to fetch nitrogen settings:", err);
|
|
@@ -26,18 +30,24 @@ export const NitrogenEditButton = ({ collection }) => {
|
|
|
26
30
|
return null;
|
|
27
31
|
// Determine which query param to use based on collection type
|
|
28
32
|
const param = collection === "nitrogen-templates" ? "templateId" : "pageId";
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
const baseHref = `/nitrogen-editor?token=${encodeURIComponent(token)}&collection=${encodeURIComponent(collection)}&${param}=${id}`;
|
|
34
|
+
const buttonStyle = {
|
|
35
|
+
display: "inline-flex",
|
|
36
|
+
alignItems: "center",
|
|
37
|
+
gap: "8px",
|
|
38
|
+
padding: "8px 16px",
|
|
39
|
+
background: "#6366f1",
|
|
40
|
+
color: "#fff",
|
|
41
|
+
borderRadius: "4px",
|
|
42
|
+
textDecoration: "none",
|
|
43
|
+
fontSize: "14px",
|
|
44
|
+
fontWeight: 500,
|
|
45
|
+
};
|
|
46
|
+
if (!hasDevelopmentUrl) {
|
|
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: {
|
|
50
|
+
...buttonStyle,
|
|
51
|
+
background: "#374151",
|
|
52
|
+
}, children: "Edit (Dev)" })] }));
|
|
43
53
|
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useState, useEffect } from "react";
|
|
4
|
+
export const NitrogenViewButton = ({ collection }) => {
|
|
5
|
+
const [slug, setSlug] = useState(undefined);
|
|
6
|
+
const [frontendUrl, setFrontendUrl] = useState(undefined);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
// Get the document ID from the URL
|
|
9
|
+
const segments = window.location.pathname.split("/").filter(Boolean);
|
|
10
|
+
const docId = segments.length >= 4 ? segments[3] : undefined;
|
|
11
|
+
if (!docId)
|
|
12
|
+
return;
|
|
13
|
+
// Fetch the document to get its slug
|
|
14
|
+
fetch(`/api/${collection}/${docId}`)
|
|
15
|
+
.then((res) => res.json())
|
|
16
|
+
.then((data) => {
|
|
17
|
+
if (data.slug) {
|
|
18
|
+
setSlug(data.slug);
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
.catch((err) => {
|
|
22
|
+
console.error("Failed to fetch document:", err);
|
|
23
|
+
});
|
|
24
|
+
// Fetch nitrogen settings to get the frontend URL
|
|
25
|
+
fetch("/api/globals/nitrogen-settings")
|
|
26
|
+
.then((res) => res.json())
|
|
27
|
+
.then((data) => {
|
|
28
|
+
const url = data.developmentUrl || data.frontendUrl;
|
|
29
|
+
if (url) {
|
|
30
|
+
setFrontendUrl(url.replace(/\/$/, ""));
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
.catch((err) => {
|
|
34
|
+
console.error("Failed to fetch nitrogen settings:", err);
|
|
35
|
+
});
|
|
36
|
+
}, [collection]);
|
|
37
|
+
if (!slug || !frontendUrl)
|
|
38
|
+
return null;
|
|
39
|
+
const href = `${frontendUrl}/${slug}`;
|
|
40
|
+
return (_jsx("a", { href: href, target: "_blank", rel: "noopener noreferrer", style: {
|
|
41
|
+
display: "inline-flex",
|
|
42
|
+
alignItems: "center",
|
|
43
|
+
gap: "8px",
|
|
44
|
+
padding: "8px 16px",
|
|
45
|
+
background: "#10b981",
|
|
46
|
+
color: "#fff",
|
|
47
|
+
borderRadius: "4px",
|
|
48
|
+
textDecoration: "none",
|
|
49
|
+
fontSize: "14px",
|
|
50
|
+
fontWeight: 500,
|
|
51
|
+
}, children: "View Page" }));
|
|
52
|
+
};
|
|
@@ -7,7 +7,7 @@ import React from 'react';
|
|
|
7
7
|
* Mount this as the route-group root layout, e.g.
|
|
8
8
|
* `app/(nitrogen-editor)/layout.tsx`:
|
|
9
9
|
*
|
|
10
|
-
* import { NitrogenEditorLayout } from '
|
|
10
|
+
* import { NitrogenEditorLayout } from '@nitrogenbuilder/connector-payload/editor'
|
|
11
11
|
* export default NitrogenEditorLayout
|
|
12
12
|
*/
|
|
13
13
|
export default function NitrogenEditorLayout({ children, }: {
|
|
@@ -7,7 +7,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
7
7
|
* Mount this as the route-group root layout, e.g.
|
|
8
8
|
* `app/(nitrogen-editor)/layout.tsx`:
|
|
9
9
|
*
|
|
10
|
-
* import { NitrogenEditorLayout } from '
|
|
10
|
+
* import { NitrogenEditorLayout } from '@nitrogenbuilder/connector-payload/editor'
|
|
11
11
|
* export default NitrogenEditorLayout
|
|
12
12
|
*/
|
|
13
13
|
export default function NitrogenEditorLayout({ children, }) {
|
|
@@ -33,7 +33,7 @@ export interface NitrogenWrapperProps {
|
|
|
33
33
|
*
|
|
34
34
|
* Usage:
|
|
35
35
|
* ```tsx
|
|
36
|
-
* import { NitrogenWrapper } from '
|
|
36
|
+
* import { NitrogenWrapper } from '@nitrogenbuilder/connector-payload/frontend'
|
|
37
37
|
*
|
|
38
38
|
* export default async function Page({ params, searchParams }) {
|
|
39
39
|
* const page = await queryPage(...)
|
|
@@ -8,7 +8,7 @@ import { buildDynamicData, getNitrogenSettings } from '../endpoints/helpers';
|
|
|
8
8
|
*
|
|
9
9
|
* Usage:
|
|
10
10
|
* ```tsx
|
|
11
|
-
* import { NitrogenWrapper } from '
|
|
11
|
+
* import { NitrogenWrapper } from '@nitrogenbuilder/connector-payload/frontend'
|
|
12
12
|
*
|
|
13
13
|
* export default async function Page({ params, searchParams }) {
|
|
14
14
|
* const page = await queryPage(...)
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export declare const nitrogenConnectorPlugin: (options?: NitrogenConnectorPlugin
|
|
|
15
15
|
export { NitrogenTemplates } from "./collections/NitrogenTemplates";
|
|
16
16
|
export { NitrogenSettings } from "./globals/NitrogenSettings";
|
|
17
17
|
export { NitrogenEditButton } from "./components/NitrogenEditButton";
|
|
18
|
+
export { NitrogenViewButton } from "./components/NitrogenViewButton";
|
|
18
19
|
export { buildDynamicData, getNitrogenSettings } from "./endpoints/helpers";
|
|
19
20
|
export { createCollectionEndpoints } from "./endpoints/collection-endpoints";
|
|
20
21
|
export { nitrogen } from "@nitrogenbuilder/client-core";
|
package/dist/index.js
CHANGED
|
@@ -12,25 +12,23 @@ const nitrogenRequiredFields = [
|
|
|
12
12
|
{
|
|
13
13
|
name: "nitrogenData",
|
|
14
14
|
type: "json",
|
|
15
|
-
admin: {
|
|
15
|
+
admin: {
|
|
16
|
+
description: "Nitrogen page builder JSON module tree",
|
|
17
|
+
components: {
|
|
18
|
+
Field: "nitrogen-connector-payload/components/LockedJsonField#LockedJsonField",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
16
21
|
},
|
|
17
22
|
{
|
|
18
23
|
name: "pageSettings",
|
|
19
24
|
type: "json",
|
|
20
|
-
admin: {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
type: "select",
|
|
27
|
-
options: [
|
|
28
|
-
{ label: "Draft", value: "draft" },
|
|
29
|
-
{ label: "Published", value: "published" },
|
|
30
|
-
],
|
|
31
|
-
defaultValue: "draft",
|
|
25
|
+
admin: {
|
|
26
|
+
description: "Page-level Nitrogen settings",
|
|
27
|
+
components: {
|
|
28
|
+
Field: "nitrogen-connector-payload/components/LockedJsonField#LockedJsonField",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
32
31
|
},
|
|
33
|
-
{ name: "author", type: "relationship", relationTo: "users" },
|
|
34
32
|
];
|
|
35
33
|
export const nitrogenConnectorPlugin = (options = {}) => (incomingConfig) => {
|
|
36
34
|
if (options.disabled) {
|
|
@@ -59,7 +57,7 @@ export const nitrogenConnectorPlugin = (options = {}) => (incomingConfig) => {
|
|
|
59
57
|
// Find the existing collection in the config
|
|
60
58
|
const existingIndex = (config.collections || []).findIndex((col) => col.slug === slug);
|
|
61
59
|
if (existingIndex === -1) {
|
|
62
|
-
console.warn(`[
|
|
60
|
+
console.warn(`[@nitrogenbuilder/connector-payload] Collection "${slug}" not found in config. ` +
|
|
63
61
|
`Make sure it is defined before the nitrogen plugin runs.`);
|
|
64
62
|
continue;
|
|
65
63
|
}
|
|
@@ -110,6 +108,10 @@ export const nitrogenConnectorPlugin = (options = {}) => (incomingConfig) => {
|
|
|
110
108
|
...edit,
|
|
111
109
|
beforeDocumentControls: [
|
|
112
110
|
...beforeControls,
|
|
111
|
+
{
|
|
112
|
+
path: "nitrogen-connector-payload/components/NitrogenViewButton#NitrogenViewButton",
|
|
113
|
+
clientProps: { collection: slug },
|
|
114
|
+
},
|
|
113
115
|
{
|
|
114
116
|
path: "nitrogen-connector-payload/components/NitrogenEditButton#NitrogenEditButton",
|
|
115
117
|
clientProps: { collection: slug },
|
|
@@ -132,6 +134,7 @@ export { NitrogenTemplates } from "./collections/NitrogenTemplates";
|
|
|
132
134
|
export { NitrogenSettings } from "./globals/NitrogenSettings";
|
|
133
135
|
// Editor exports
|
|
134
136
|
export { NitrogenEditButton } from "./components/NitrogenEditButton";
|
|
137
|
+
export { NitrogenViewButton } from "./components/NitrogenViewButton";
|
|
135
138
|
// Helper exports for consumers building custom frontend routes
|
|
136
139
|
export { buildDynamicData, getNitrogenSettings } from "./endpoints/helpers";
|
|
137
140
|
// Collection endpoint factory for consumers who need custom endpoint generation
|
package/package.json
CHANGED