@nitrogenbuilder/connector-payload 0.1.51 → 0.1.52
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/components/HiddenPreviewButton.d.ts +1 -0
- package/dist/components/HiddenPreviewButton.js +3 -0
- package/dist/components/NitrogenEditButtonRuntime.js +24 -8
- package/dist/components/resolveNitrogenViewAction.d.ts +10 -0
- package/dist/components/resolveNitrogenViewAction.js +8 -0
- package/dist/editor/NitrogenEditorPage.js +0 -3
- package/dist/index.js +8 -0
- package/package.json +2 -8
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function HiddenPreviewButton(): null;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useState, useEffect } from 'react';
|
|
4
|
-
import { Button } from '@payloadcms/ui';
|
|
4
|
+
import { Button, useFormFields, useLivePreviewContext } from '@payloadcms/ui';
|
|
5
5
|
import { nitrogenButtonGroupStyle, nitrogenEditDevButtonVars, nitrogenEditLiveButtonVars, nitrogenViewButtonVars, } from './nitrogenAdminButtonStyles.js';
|
|
6
|
+
import { resolveNitrogenViewAction } from './resolveNitrogenViewAction.js';
|
|
6
7
|
function isLocalAdminHost() {
|
|
7
8
|
const hostname = window.location.hostname;
|
|
8
9
|
return (hostname === 'localhost' ||
|
|
@@ -78,10 +79,13 @@ export const NitrogenEditButtonRuntime = ({ collection, routePattern }) => {
|
|
|
78
79
|
const [token, setToken] = useState(undefined);
|
|
79
80
|
const [slug, setSlug] = useState(undefined);
|
|
80
81
|
const [documentRelativePath, setDocumentRelativePath] = useState(undefined);
|
|
82
|
+
const [persistedStatus, setPersistedStatus] = useState(undefined);
|
|
81
83
|
const [frontendUrl, setFrontendUrl] = useState(undefined);
|
|
82
84
|
const [instanceUrl, setInstanceUrl] = useState(undefined);
|
|
83
85
|
const [authorId, setAuthorId] = useState(undefined);
|
|
84
86
|
const [templateSlug, setTemplateSlug] = useState(undefined);
|
|
87
|
+
const formStatus = useFormFields(([fields]) => fields?._status?.value);
|
|
88
|
+
const { isPreviewEnabled, previewURL } = useLivePreviewContext();
|
|
85
89
|
useEffect(() => {
|
|
86
90
|
const segments = window.location.pathname.split('/').filter(Boolean);
|
|
87
91
|
const docId = segments.length >= 4 ? segments[3] : undefined;
|
|
@@ -92,6 +96,7 @@ export const NitrogenEditButtonRuntime = ({ collection, routePattern }) => {
|
|
|
92
96
|
.then((res) => res.json())
|
|
93
97
|
.then((data) => {
|
|
94
98
|
setDocumentRelativePath(getBreadcrumbRelativePath(data));
|
|
99
|
+
setPersistedStatus(typeof data._status === 'string' ? data._status : undefined);
|
|
95
100
|
if (data.slug) {
|
|
96
101
|
setSlug(data.slug);
|
|
97
102
|
}
|
|
@@ -163,17 +168,28 @@ export const NitrogenEditButtonRuntime = ({ collection, routePattern }) => {
|
|
|
163
168
|
? `/nitrogen-templates/${trimSlashes(slug || '')}`
|
|
164
169
|
: documentRelativePath ||
|
|
165
170
|
buildRelativePath(slug || '', routePattern, templateSlug ?? undefined);
|
|
166
|
-
const
|
|
171
|
+
const canBuildPublicHref = Boolean(slug &&
|
|
172
|
+
frontendUrl &&
|
|
173
|
+
(collection === 'nitrogen-templates' ||
|
|
174
|
+
routePattern ||
|
|
175
|
+
templateSlug !== undefined));
|
|
176
|
+
const publicHref = canBuildPublicHref
|
|
177
|
+
? `${frontendUrl}${viewRelativePath}`
|
|
178
|
+
: undefined;
|
|
179
|
+
const viewAction = resolveNitrogenViewAction({
|
|
180
|
+
documentStatus: formStatus ?? persistedStatus,
|
|
181
|
+
isPreviewEnabled,
|
|
182
|
+
previewURL,
|
|
183
|
+
publicHref,
|
|
184
|
+
});
|
|
167
185
|
const editButtonVars = isDevelopmentMode
|
|
168
186
|
? nitrogenEditDevButtonVars
|
|
169
187
|
: nitrogenEditLiveButtonVars;
|
|
170
|
-
return (_jsxs("div", { style: nitrogenButtonGroupStyle, children: [
|
|
171
|
-
frontendUrl &&
|
|
172
|
-
(collection === 'nitrogen-templates' ||
|
|
173
|
-
routePattern ||
|
|
174
|
-
templateSlug !== undefined) && (_jsx(Button, { buttonStyle: "primary", el: "anchor", margin: false, newTab: true, url: viewHref, extraButtonProps: {
|
|
188
|
+
return (_jsxs("div", { style: nitrogenButtonGroupStyle, children: [viewAction && (_jsx(Button, { buttonStyle: "primary", el: "anchor", margin: false, newTab: true, url: viewAction.href, extraButtonProps: {
|
|
175
189
|
style: nitrogenViewButtonVars,
|
|
176
|
-
}, children: collection === 'nitrogen-templates'
|
|
190
|
+
}, children: collection === 'nitrogen-templates'
|
|
191
|
+
? 'View Template'
|
|
192
|
+
: viewAction.label })), _jsx(Button, { buttonStyle: "primary", el: "anchor", margin: false, newTab: true, url: editHref, extraButtonProps: {
|
|
177
193
|
style: editButtonVars,
|
|
178
194
|
}, children: "Edit with Nitrogen" })] }));
|
|
179
195
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type NitrogenViewAction = {
|
|
2
|
+
href: string;
|
|
3
|
+
label: 'Preview Draft' | 'View Page';
|
|
4
|
+
};
|
|
5
|
+
export declare function resolveNitrogenViewAction({ documentStatus, isPreviewEnabled, previewURL, publicHref, }: {
|
|
6
|
+
documentStatus?: unknown;
|
|
7
|
+
isPreviewEnabled: boolean;
|
|
8
|
+
previewURL?: string;
|
|
9
|
+
publicHref?: string;
|
|
10
|
+
}): NitrogenViewAction | null;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function resolveNitrogenViewAction({ documentStatus, isPreviewEnabled, previewURL, publicHref, }) {
|
|
2
|
+
if (documentStatus === 'draft') {
|
|
3
|
+
const href = isPreviewEnabled ? previewURL?.trim() : '';
|
|
4
|
+
return href ? { href, label: 'Preview Draft' } : null;
|
|
5
|
+
}
|
|
6
|
+
const href = publicHref?.trim();
|
|
7
|
+
return href ? { href, label: 'View Page' } : null;
|
|
8
|
+
}
|
|
@@ -68,9 +68,6 @@ export function createNitrogenEditorPage(config) {
|
|
|
68
68
|
type: "payload",
|
|
69
69
|
apiUrl: getNitrogenApiUrl(isPreviewDevelopment),
|
|
70
70
|
collection: params.collection,
|
|
71
|
-
// Shown as a "Sign in" button in the editor when the CMS session has
|
|
72
|
-
// expired (e.g. a save fails with 401/403).
|
|
73
|
-
loginUrl: "/admin/login",
|
|
74
71
|
},
|
|
75
72
|
siteUrl: siteUrl || "",
|
|
76
73
|
urlMaps: nitrogenConfig.urlMaps || [],
|
package/dist/index.js
CHANGED
|
@@ -198,6 +198,7 @@ export const nitrogenConnectorPlugin = (options = {}) => (incomingConfig) => {
|
|
|
198
198
|
const beforeControls = "beforeDocumentControls" in edit
|
|
199
199
|
? edit.beforeDocumentControls || []
|
|
200
200
|
: [];
|
|
201
|
+
const shouldHideDefaultPreviewButton = Boolean(adminConfig.preview) && !("PreviewButton" in edit);
|
|
201
202
|
config.collections[existingIndex] = {
|
|
202
203
|
...col,
|
|
203
204
|
admin: {
|
|
@@ -206,6 +207,13 @@ export const nitrogenConnectorPlugin = (options = {}) => (incomingConfig) => {
|
|
|
206
207
|
...components,
|
|
207
208
|
edit: {
|
|
208
209
|
...edit,
|
|
210
|
+
...(shouldHideDefaultPreviewButton
|
|
211
|
+
? {
|
|
212
|
+
PreviewButton: {
|
|
213
|
+
path: "@nitrogenbuilder/connector-payload/components/HiddenPreviewButton#HiddenPreviewButton",
|
|
214
|
+
},
|
|
215
|
+
}
|
|
216
|
+
: {}),
|
|
209
217
|
beforeDocumentControls: [
|
|
210
218
|
...beforeControls,
|
|
211
219
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nitrogenbuilder/connector-payload",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.52",
|
|
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",
|
|
@@ -54,11 +54,5 @@
|
|
|
54
54
|
"@nitrogenbuilder/client-react": "link:../monogen/packages/client-react",
|
|
55
55
|
"@nitrogenbuilder/client-core": "link:../monogen/packages/client-core",
|
|
56
56
|
"@nitrogenbuilder/types": "link:../monogen/packages/types"
|
|
57
|
-
},
|
|
58
|
-
"pnpm": {
|
|
59
|
-
"onlyBuiltDependencies": [
|
|
60
|
-
"esbuild",
|
|
61
|
-
"sharp"
|
|
62
|
-
]
|
|
63
57
|
}
|
|
64
|
-
}
|
|
58
|
+
}
|