@nitrogenbuilder/connector-payload 0.1.21 → 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,13 +1,16 @@
1
1
  'use client';
2
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } 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
  import { Button } from '@payloadcms/ui';
5
- import { nitrogenButtonGroupStyle, nitrogenEditDevButtonVars, nitrogenEditLiveButtonVars, nitrogenSecondaryButtonVars, nitrogenViewButtonVars, } from './nitrogenAdminButtonStyles';
6
- function getPreferredSiteUrl(data) {
5
+ import { nitrogenButtonGroupStyle, nitrogenEditDevButtonVars, nitrogenEditLiveButtonVars, nitrogenViewButtonVars, } from './nitrogenAdminButtonStyles';
6
+ function isLocalAdminHost() {
7
7
  const hostname = window.location.hostname;
8
- const isLocalAdmin = hostname === 'localhost' ||
8
+ return (hostname === 'localhost' ||
9
9
  hostname === '127.0.0.1' ||
10
- hostname === '[::1]';
10
+ hostname === '[::1]');
11
+ }
12
+ function getPreferredSiteUrl(data) {
13
+ const isLocalAdmin = isLocalAdminHost();
11
14
  const preferredUrl = isLocalAdmin ? data.developmentUrl : data.frontendUrl;
12
15
  const fallbackUrl = isLocalAdmin ? data.frontendUrl : data.developmentUrl;
13
16
  return preferredUrl || fallbackUrl || '';
@@ -15,7 +18,6 @@ function getPreferredSiteUrl(data) {
15
18
  export const NitrogenEditButtonRuntime = ({ collection }) => {
16
19
  const [id, setId] = useState(undefined);
17
20
  const [token, setToken] = useState(undefined);
18
- const [hasDevelopmentUrl, setHasDevelopmentUrl] = useState(false);
19
21
  const [slug, setSlug] = useState(undefined);
20
22
  const [frontendUrl, setFrontendUrl] = useState(undefined);
21
23
  const [instanceUrl, setInstanceUrl] = useState(undefined);
@@ -52,9 +54,6 @@ export const NitrogenEditButtonRuntime = ({ collection }) => {
52
54
  if (data.connectorToken) {
53
55
  setToken(data.connectorToken);
54
56
  }
55
- if (data.developmentUrl) {
56
- setHasDevelopmentUrl(true);
57
- }
58
57
  if (data.instanceUrl) {
59
58
  setInstanceUrl(data.instanceUrl.replace(/\/$/, ''));
60
59
  }
@@ -71,14 +70,14 @@ export const NitrogenEditButtonRuntime = ({ collection }) => {
71
70
  return null;
72
71
  const param = collection === 'nitrogen-templates' ? 'templateId' : 'pageId';
73
72
  const editorBase = instanceUrl ?? '';
74
- const baseHref = `${editorBase}/nitrogen-editor?token=${encodeURIComponent(token)}&collection=${encodeURIComponent(collection)}&${param}=${id}&authorId=${encodeURIComponent(authorId)}`;
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;
75
78
  return (_jsxs("div", { style: nitrogenButtonGroupStyle, children: [slug && frontendUrl && (_jsx(Button, { buttonStyle: "primary", el: "anchor", margin: false, newTab: true, url: `${frontendUrl}/${slug}`, extraButtonProps: {
76
79
  style: nitrogenViewButtonVars,
77
- }, children: "View Page" })), hasDevelopmentUrl ? (_jsxs(_Fragment, { children: [_jsx(Button, { buttonStyle: "primary", el: "anchor", margin: false, newTab: true, url: baseHref, extraButtonProps: {
78
- style: nitrogenEditLiveButtonVars,
79
- }, children: "Edit (Live)" }), _jsx(Button, { buttonStyle: "primary", el: "anchor", margin: false, newTab: true, url: `${baseHref}&development=true`, extraButtonProps: {
80
- style: nitrogenEditDevButtonVars,
81
- }, children: "Edit (Dev)" })] })) : (_jsx(Button, { buttonStyle: "secondary", el: "anchor", margin: false, newTab: true, url: baseHref, extraButtonProps: {
82
- style: nitrogenSecondaryButtonVars,
83
- }, 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" })] }));
84
83
  };
@@ -1,8 +1,11 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { getPayload } from "payload";
3
3
  import { headers } from "next/headers";
4
4
  import { redirect } from "next/navigation";
5
- function getNitrogenApiUrl() {
5
+ function getNitrogenApiUrl(isDevelopment) {
6
+ if (isDevelopment) {
7
+ return "/api/nitrogen/v1";
8
+ }
6
9
  const configuredBase = process.env.NEXT_PUBLIC_PAYLOAD_API_URL ||
7
10
  process.env.NEXT_PUBLIC_SERVER_URL ||
8
11
  "";
@@ -61,7 +64,7 @@ export function createNitrogenEditorPage(config) {
61
64
  licenseKey: settings.licenseKey || "",
62
65
  provider: {
63
66
  type: "payload",
64
- apiUrl: getNitrogenApiUrl(),
67
+ apiUrl: getNitrogenApiUrl(isDevelopment),
65
68
  collection: postType,
66
69
  },
67
70
  siteUrl: siteUrl || "",
@@ -70,8 +73,10 @@ export function createNitrogenEditorPage(config) {
70
73
  cssInjection: nitrogenConfig.cssInjection || "",
71
74
  };
72
75
  const editId = params.templateId || params.pageId || "";
76
+ const isEditorDev = isDevelopment && !!settings.instanceUrl;
77
+ const editorOrigin = settings.instanceUrl?.replace(/\/$/, "") || "";
73
78
  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: {
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: {
75
80
  __html: [
76
81
  `window.nitrogenConfig = ${JSON.stringify(builderConfig)};`,
77
82
  `window.nitrogenEditId = "${editId}";`,
@@ -86,12 +91,16 @@ export function createNitrogenEditorPage(config) {
86
91
  alignItems: "center",
87
92
  justifyContent: "center",
88
93
  backgroundColor: "#0F1214",
89
- }, children: _jsx("img", { src: `${cdnBase}/logo-white.svg`, alt: "Loading\u2026", style: {
94
+ }, children: _jsx("img", { src: isEditorDev
95
+ ? `${editorOrigin}/src/components/logo-white.svg`
96
+ : `${cdnBase}/logo-white.svg`, alt: "Loading\u2026", style: {
90
97
  width: "24rem",
91
98
  maxWidth: "100%",
92
99
  animation: "nitrogen-loader-pulse 3s ease-in-out infinite",
93
100
  } }) }), _jsx("style", { dangerouslySetInnerHTML: {
94
101
  __html: `@keyframes nitrogen-loader-pulse{0%{transform:scale(1);opacity:0}50%{opacity:1}100%{transform:scale(1.05);opacity:0}}`,
95
- } })] }), _jsx("script", { type: "module", crossOrigin: "", src: `${cdnBase}/index.js` })] }));
102
+ } })] }), isEditorDev ? (_jsxs(_Fragment, { children: [_jsx("script", { type: "module", dangerouslySetInnerHTML: {
103
+ __html: `import RefreshRuntime from "${editorOrigin}/@react-refresh";RefreshRuntime.injectIntoGlobalHook(window);window.$RefreshReg$ = () => {};window.$RefreshSig$ = () => (type) => type;window.__vite_plugin_react_preamble_installed__ = true;`,
104
+ } }), _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` }))] }));
96
105
  };
97
106
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitrogenbuilder/connector-payload",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
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",