@pantheon-systems/p1-next-sdk 0.26.1 → 0.27.0

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,4 +1,15 @@
1
1
  import { type ReactNode } from "react";
2
+ import type { P1EditorRouter } from "./editor-client/types";
3
+ /**
4
+ * The Next.js App Router as a P1 router: what the P1 editor navigates with, and
5
+ * what `P1NextRouterProvider` provides to P1 components. It has no side effects,
6
+ * so it may be called any number of times in a tree.
7
+ */
8
+ export declare function useP1NextRouter(): P1EditorRouter;
9
+ /** Refreshes on history navigation, unless a component above already does. */
10
+ export declare function HistoryRefreshOwner({ children }: {
11
+ children: ReactNode;
12
+ }): import("react").JSX.Element;
2
13
  export declare function P1NextRouterProvider({ children }: {
3
14
  children: ReactNode;
4
15
  }): import("react").JSX.Element;
@@ -1,14 +1,29 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { useRouter, usePathname, useSearchParams } from "next/navigation";
4
- import { useMemo, useEffect, useRef } from "react";
4
+ import { createContext, useContext, useMemo, useEffect, useRef } from "react";
5
5
  import { P1RouterContext } from "@pantheon-systems/puck-css";
6
- export function P1NextRouterProvider({ children }) {
6
+ const HistoryRefreshOwnedContext = createContext(false);
7
+ export function useP1NextRouter() {
7
8
  const nextRouter = useRouter();
8
9
  const pathname = usePathname();
9
10
  const searchParams = useSearchParams();
11
+ return useMemo(() => ({
12
+ refresh: () => nextRouter.refresh(),
13
+ replace: (url, options) => nextRouter.replace(url, options),
14
+ push: (href) => nextRouter.push(href),
15
+ pathname,
16
+ searchParams,
17
+ }), [nextRouter, pathname, searchParams]);
18
+ }
19
+ function useRefreshOnHistoryNavigation() {
20
+ const nextRouter = useRouter();
21
+ const pathname = usePathname();
22
+ const ownedAbove = useContext(HistoryRefreshOwnedContext);
10
23
  const isInitialMount = useRef(true);
11
24
  useEffect(() => {
25
+ if (ownedAbove)
26
+ return;
12
27
  const handler = (event) => {
13
28
  if (event.persisted) {
14
29
  nextRouter.refresh();
@@ -16,19 +31,22 @@ export function P1NextRouterProvider({ children }) {
16
31
  };
17
32
  window.addEventListener("pageshow", handler);
18
33
  return () => window.removeEventListener("pageshow", handler);
19
- }, [nextRouter]);
34
+ }, [nextRouter, ownedAbove]);
20
35
  useEffect(() => {
21
36
  if (isInitialMount.current) {
22
37
  isInitialMount.current = false;
23
38
  return;
24
39
  }
40
+ if (ownedAbove)
41
+ return;
25
42
  nextRouter.refresh();
26
- }, [pathname, nextRouter]);
27
- const router = useMemo(() => ({
28
- refresh: () => nextRouter.refresh(),
29
- replace: (url, options) => nextRouter.replace(url, options),
30
- pathname,
31
- searchParams,
32
- }), [nextRouter, pathname, searchParams]);
33
- return (_jsx(P1RouterContext.Provider, { value: router, children: children }));
43
+ }, [pathname, nextRouter, ownedAbove]);
44
+ }
45
+ export function HistoryRefreshOwner({ children }) {
46
+ useRefreshOnHistoryNavigation();
47
+ return (_jsx(HistoryRefreshOwnedContext.Provider, { value: true, children: children }));
48
+ }
49
+ export function P1NextRouterProvider({ children }) {
50
+ const router = useP1NextRouter();
51
+ return (_jsx(HistoryRefreshOwner, { children: _jsx(P1RouterContext.Provider, { value: router, children: children }) }));
34
52
  }
@@ -1,2 +1,2 @@
1
- /** The dashboard's Plan and usage page, where "See usage" in the used-up tokens notice goes. */
1
+ /** The dashboard's Plan and usage page, where "View usage" in the used-up tokens notice goes. */
2
2
  export declare function planAndUsageUrl(dashboardUrl: string | undefined): string;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Builds the editor client component an app mounts at its P1 editor route.
2
+ * Builds the editor component a site mounts at its P1 editor route.
3
3
  *
4
4
  * The shell around the Puck canvas — provider nesting, auth gating, document
5
5
  * loading, the remote-datasource context, the post-login return redirect, and
@@ -13,17 +13,16 @@
13
13
  * wants on top of the defaults.
14
14
  *
15
15
  * Usage:
16
- * // app/p1/(editor)/[[...p1]]/editor-client.tsx
17
- * "use client";
18
- * import { createP1EditorClient } from "@pantheon-systems/p1-next-sdk";
19
- * import "@pantheon-systems/p1-next-sdk/editor.css";
20
- * import config from "@/puck.config";
21
- *
22
- * export const EditorClientWrapper = createP1EditorClient({
16
+ * const P1Editor = createP1Editor({
23
17
  * puckConfig: config,
24
18
  * signInPage: <MySignInPage />,
25
19
  * });
26
20
  *
21
+ * // In the route, with the site's own router:
22
+ * <P1Editor router={router} />
23
+ *
24
+ * Next.js apps use `createP1EditorClient`, which passes the Next.js router in.
25
+ *
27
26
  * The stylesheet is imported by the route rather than by this module: it is
28
27
  * only wanted where the editor actually mounts, and importing it here would put
29
28
  * the editor's CSS on every page that touches this package.
@@ -33,5 +32,7 @@
33
32
  * each reading its inputs from the `EditorRuntime` this factory builds.
34
33
  */
35
34
  import React from "react";
36
- import type { CreateP1EditorClientOptions } from "./types";
37
- export declare function createP1EditorClient(options: CreateP1EditorClientOptions): () => React.JSX.Element;
35
+ import type { CreateP1EditorClientOptions, P1EditorRouter } from "./types";
36
+ export declare function createP1Editor(options: CreateP1EditorClientOptions): ({ router }: {
37
+ router: P1EditorRouter;
38
+ }) => React.JSX.Element;
@@ -2,9 +2,9 @@
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { EditorShell } from "./editor-shell";
4
4
  import { createEditorRuntime } from "./runtime";
5
- export function createP1EditorClient(options) {
5
+ export function createP1Editor(options) {
6
6
  const runtime = createEditorRuntime(options);
7
- return function P1EditorClient() {
8
- return _jsx(EditorShell, { runtime: runtime });
7
+ return function P1Editor({ router }) {
8
+ return _jsx(EditorShell, { runtime: runtime, router: router });
9
9
  };
10
10
  }
@@ -1,10 +1,12 @@
1
1
  import React from "react";
2
2
  import type { EditorRuntime } from "./runtime";
3
+ import type { P1EditorRouter } from "./types";
3
4
  /**
4
5
  * Everything that depends on which document is open: loading it, assembling the
5
6
  * plugin set, navigating between documents, and claiming a post-login redirect.
6
7
  */
7
- export declare function EditorContent({ runtime, path, }: {
8
+ export declare function EditorContent({ runtime, router, path, }: {
8
9
  runtime: EditorRuntime;
10
+ router: P1EditorRouter;
9
11
  path: string;
10
12
  }): React.JSX.Element;
@@ -1,15 +1,13 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { useCallback, useMemo } from "react";
4
- import { useRouter } from "next/navigation";
3
+ import { useCallback, useMemo, useRef } from "react";
5
4
  import { editorPathHref, useEditorContext, useP1Auth, useP1Editor, useP1Plugins, useRemoteDatasourceContext, } from "@pantheon-systems/puck-css";
6
5
  import { useP1ExperimentalFeatures } from "../experimental-features";
7
6
  import { p1UserFlagKey } from "../launchdarkly/user-key";
8
7
  import { EditorCanvas } from "./editor-canvas";
9
8
  import { useReturnToRedirect } from "./return-to";
10
9
  import { useBusinessAccountId } from "./use-business-account-id";
11
- export function EditorContent({ runtime, path, }) {
12
- const router = useRouter();
10
+ export function EditorContent({ runtime, router, path, }) {
13
11
  const { data: editorCtx } = useEditorContext(path);
14
12
  const datasourceRegistry = editorCtx?.remoteDatasourceRegistry ?? [];
15
13
  const { context: datasourceContext } = useRemoteDatasourceContext(path, datasourceRegistry);
@@ -21,9 +19,11 @@ export function EditorContent({ runtime, path, }) {
21
19
  siteId: runtime.config?.siteId,
22
20
  businessAccountId,
23
21
  });
22
+ const routerRef = useRef(router);
23
+ routerRef.current = router;
24
24
  const openDocument = useCallback((documentPath) => {
25
- router.push(`${editorPathHref(documentPath)}${window.location.search}`);
26
- }, [router]);
25
+ routerRef.current.push(`${editorPathHref(documentPath)}${window.location.search}`);
26
+ }, []);
27
27
  const ctx = useMemo(() => ({ path, openDocument }), [path, openDocument]);
28
28
  const extensions = runtime.useExtensions(ctx);
29
29
  const additionalPlugins = useMemo(() => [...p1Plugins, ...runtime.plugins, ...(extensions.plugins ?? [])], [p1Plugins, runtime.plugins, extensions.plugins]);
@@ -47,6 +47,7 @@ export function EditorContent({ runtime, path, }) {
47
47
  ...runtime.overrideOptions,
48
48
  ...extensions.overrideOptions,
49
49
  threadsEnabled: features.isEnabled("threads"),
50
+ commentEditDeleteEnabled: features.isEnabled("commentEditDelete"),
50
51
  },
51
52
  });
52
53
  return (_jsx(EditorCanvas, { redirecting: redirecting, loading: loading, reloading: reloading, error: error, hasContent: hasContent, canvasKey: `${puckKey}${extensions.editorKeySuffix ?? ""}`, puckProps: puckProps, datasourceRegistry: datasourceRegistry, datasourceContext: datasourceContext }));
@@ -1,9 +1,11 @@
1
1
  import React from "react";
2
2
  import type { EditorRuntime } from "./runtime";
3
+ import type { P1EditorRouter } from "./types";
3
4
  /**
4
5
  * The editor's outermost frame: which document the URL names, and the
5
6
  * providers and auth gate the content sits in.
6
7
  */
7
- export declare function EditorShell({ runtime }: {
8
+ export declare function EditorShell({ runtime, router, }: {
8
9
  runtime: EditorRuntime;
10
+ router: P1EditorRouter;
9
11
  }): React.JSX.Element;
@@ -1,17 +1,14 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { usePathname } from "next/navigation";
4
- import { P1App, P1QueryProvider } from "@pantheon-systems/puck-css";
5
- import { P1NextRouterProvider } from "../P1NextRouterProvider";
3
+ import { P1App, P1QueryProvider, P1RouterContext } from "@pantheon-systems/puck-css";
6
4
  import { editorPagePathFromUrlPath } from "../editor-paths";
7
5
  import { EditorContent } from "./editor-content";
8
6
  import { EditorMessage } from "./editor-message";
9
- export function EditorShell({ runtime }) {
10
- const pathname = usePathname();
11
- const path = editorPagePathFromUrlPath(pathname);
7
+ export function EditorShell({ runtime, router, }) {
8
+ const path = editorPagePathFromUrlPath(router.pathname);
12
9
  if (!runtime.config) {
13
10
  return (_jsx(EditorMessage, { testId: "editor-unavailable", title: "Editor unavailable", detail: runtime.configError ?? "P1 configuration is missing.", hint: "Set NEXT_PUBLIC_CSS_BASE_URL and NEXT_PUBLIC_CSS_SITE_ID environment variables to enable the editor." }));
14
11
  }
15
- const editor = _jsx(EditorContent, { runtime: runtime, path: path });
16
- return (_jsx(P1QueryProvider, { children: _jsx(P1NextRouterProvider, { children: _jsx(P1App, { config: runtime.config, loginFallback: runtime.signInPage, children: runtime.wrapEditor ? runtime.wrapEditor(editor) : editor }) }) }));
12
+ const editor = _jsx(EditorContent, { runtime: runtime, router: router, path: path });
13
+ return (_jsx(P1QueryProvider, { children: _jsx(P1RouterContext.Provider, { value: router, children: _jsx(P1App, { config: runtime.config, loginFallback: runtime.signInPage, logoUrl: runtime.pluginOptions.logoUrl, children: runtime.wrapEditor ? runtime.wrapEditor(editor) : editor }) }) }));
17
14
  }
@@ -1,2 +1,2 @@
1
- export { createP1EditorClient } from "./create-p1-editor-client";
2
- export type { CreateP1EditorClientOptions, P1EditorContext, P1EditorExtensions, } from "./types";
1
+ export { createP1Editor } from "./create-p1-editor";
2
+ export type { CreateP1EditorClientOptions, P1EditorContext, P1EditorExtensions, P1EditorRouter, } from "./types";
@@ -1 +1 @@
1
- export { createP1EditorClient } from "./create-p1-editor-client";
1
+ export { createP1Editor } from "./create-p1-editor";
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { useEffect, useState } from "react";
2
+ import { useEffect, useRef, useState } from "react";
3
3
  const RETURN_TO_KEY = "p1_return_to";
4
4
  function sameOriginPath(returnTo) {
5
5
  try {
@@ -14,6 +14,8 @@ function sameOriginPath(returnTo) {
14
14
  }
15
15
  export function useReturnToRedirect(router) {
16
16
  const [redirecting, setRedirecting] = useState(false);
17
+ const routerRef = useRef(router);
18
+ routerRef.current = router;
17
19
  useEffect(() => {
18
20
  const returnTo = localStorage.getItem(RETURN_TO_KEY);
19
21
  if (!returnTo)
@@ -23,7 +25,7 @@ export function useReturnToRedirect(router) {
23
25
  if (!href)
24
26
  return;
25
27
  setRedirecting(true);
26
- router.push(href);
27
- }, [router]);
28
+ routerRef.current.push(href);
29
+ }, []);
28
30
  return redirecting;
29
31
  }
@@ -7,8 +7,16 @@
7
7
  */
8
8
  import type React from "react";
9
9
  import type { Config, Plugin } from "@puckeditor/core";
10
- import type { UseP1EditorOptions, UseP1OverridesOptions } from "@pantheon-systems/puck-css";
10
+ import type { P1Router, UseP1EditorOptions, UseP1OverridesOptions } from "@pantheon-systems/puck-css";
11
11
  export type EditorPluginOptions = NonNullable<UseP1EditorOptions["pluginOptions"]>;
12
+ /**
13
+ * Navigation the editor takes from the site that loads it. The editor reads the
14
+ * open document from `pathname` and moves between documents with `push`.
15
+ */
16
+ export type P1EditorRouter = P1Router & {
17
+ /** Navigates to `href` and adds an entry to the browser history. */
18
+ push(href: string): void;
19
+ };
12
20
  /**
13
21
  * What a customization slot is told about the editor as it renders.
14
22
  */
@@ -14,6 +14,8 @@ export declare const P1_EXPERIMENTAL_FEATURE_FLAGS: {
14
14
  readonly goLiveStub: "p-1-go-live-stub";
15
15
  /** Offering to put a new page in its section when its slug is a path. */
16
16
  readonly sectionNesting: "p1-section-nesting";
17
+ /** Editing and deleting your own comment messages. */
18
+ readonly commentEditDelete: "p1-comment-edit-delete";
17
19
  };
18
20
  export type P1ExperimentalFeature = keyof typeof P1_EXPERIMENTAL_FEATURE_FLAGS;
19
21
  export declare const P1_EXPERIMENTAL_FEATURES: P1ExperimentalFeature[];
@@ -3,6 +3,7 @@ export const P1_EXPERIMENTAL_FEATURE_FLAGS = {
3
3
  chatbot: "p1-chatbot",
4
4
  goLiveStub: "p-1-go-live-stub",
5
5
  sectionNesting: "p1-section-nesting",
6
+ commentEditDelete: "p1-comment-edit-delete",
6
7
  };
7
8
  export const P1_EXPERIMENTAL_FEATURES = Object.keys(P1_EXPERIMENTAL_FEATURE_FLAGS);
8
9
  export const BUSINESS_ACCOUNT_TARGETED_FEATURES = [];
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export { P1NextRouterProvider } from "./P1NextRouterProvider";
1
+ export { P1NextRouterProvider, useP1NextRouter } from "./P1NextRouterProvider";
2
2
  export { parseEditorSegments, editorPagePathFromUrlPath, } from "./editor-paths";
3
- export { createP1EditorClient } from "./editor-client";
4
- export type { CreateP1EditorClientOptions, P1EditorContext, P1EditorExtensions, } from "./editor-client";
3
+ export { createP1EditorClient } from "./next-editor-client";
4
+ export type { CreateP1EditorClientOptions, P1EditorContext, P1EditorExtensions, P1EditorRouter, } from "./editor-client";
5
5
  export { useP1ExperimentalFeatures } from "./experimental-features";
6
6
  export type { P1ExperimentalFeature, P1ExperimentalFeatures, UseP1ExperimentalFeaturesOptions, } from "./experimental-features";
7
7
  export { P1LocalizationProvider, useP1Localization, type P1Localization, type PublishedPageLocalization, } from "./localization-react";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export { P1NextRouterProvider } from "./P1NextRouterProvider";
1
+ export { P1NextRouterProvider, useP1NextRouter } from "./P1NextRouterProvider";
2
2
  export { parseEditorSegments, editorPagePathFromUrlPath, } from "./editor-paths";
3
- export { createP1EditorClient } from "./editor-client";
3
+ export { createP1EditorClient } from "./next-editor-client";
4
4
  export { useP1ExperimentalFeatures } from "./experimental-features";
5
5
  export { P1LocalizationProvider, useP1Localization, } from "./localization-react";
@@ -0,0 +1,21 @@
1
+ import React from "react";
2
+ import type { CreateP1EditorClientOptions } from "./editor-client/types";
3
+ /**
4
+ * Builds the editor client component a Next.js app mounts at its P1 editor
5
+ * route, navigating with the Next.js App Router.
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * // app/p1/(editor)/[[...p1]]/editor-client.tsx
10
+ * "use client";
11
+ * import { createP1EditorClient } from "@pantheon-systems/p1-next-sdk";
12
+ * import "@pantheon-systems/p1-next-sdk/editor.css";
13
+ * import config from "@/puck.config";
14
+ *
15
+ * export const EditorClientWrapper = createP1EditorClient({
16
+ * puckConfig: config,
17
+ * signInPage: <MySignInPage />,
18
+ * });
19
+ * ```
20
+ */
21
+ export declare function createP1EditorClient(options: CreateP1EditorClientOptions): () => React.JSX.Element;
@@ -0,0 +1,11 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { createP1Editor } from "./editor-client/create-p1-editor";
4
+ import { HistoryRefreshOwner, useP1NextRouter } from "./P1NextRouterProvider";
5
+ export function createP1EditorClient(options) {
6
+ const EditorClient = createP1Editor(options);
7
+ return function P1EditorClient() {
8
+ const router = useP1NextRouter();
9
+ return (_jsx(HistoryRefreshOwner, { children: _jsx(EditorClient, { router: router }) }));
10
+ };
11
+ }
@@ -0,0 +1,20 @@
1
+ # Migration Guide: Puck 0.24
2
+
3
+ This guide is for existing projects on `@puckeditor/core` 0.21, 0.22 or 0.23. The SDK and `@pantheon-systems/puck-css` now require `@puckeditor/core` `>=0.24.0` as a peer, and new projects from `create-p1-starter-kit` pin `0.24.0`.
4
+
5
+ ## Steps
6
+
7
+ 1. Pin Puck in your `package.json`:
8
+
9
+ ```json
10
+ "@puckeditor/core": "0.24.0"
11
+ ```
12
+
13
+ 2. Upgrade `@pantheon-systems/p1-next-sdk` and `@pantheon-systems/puck-css` to the versions released with this change, then reinstall.
14
+
15
+ 3. If your lockfile or package manager overrides pin `@tiptap/core` or `@tiptap/pm`, move them to `3.34.0` or remove the pin. Puck 0.24's rich-text extensions require a matching `@tiptap/core`.
16
+
17
+ ## What changes in the editor
18
+
19
+ - The editor theme re-declares more of Puck's color tokens, so custom overrides of `--puck-color-*` variables on `.puck-editor-theme` keep winning, including in modals that render inside the editor root.
20
+ - Inspector fields are padded and separated by Puck itself. Field sections and fields that a block does not assign to a group get the same spacing as grouped ones. If you restyled `[class*="_PuckFields-field_"]`, re-check the spacing.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pantheon-systems/p1-next-sdk",
3
- "version": "0.26.1",
3
+ "version": "0.27.0",
4
4
  "license": "UNLICENSED",
5
5
  "description": "Next.js SDK for P1 editor integration",
6
6
  "publishConfig": {
@@ -47,16 +47,16 @@
47
47
  "!dist/**/*.map"
48
48
  ],
49
49
  "dependencies": {
50
- "@pantheon-systems/css-client": "0.26.1",
51
- "@pantheon-systems/p1-ai-chat": "0.11.0",
52
- "@pantheon-systems/puck-css": "0.26.1",
50
+ "@pantheon-systems/css-client": "0.27.0",
51
+ "@pantheon-systems/p1-ai-chat": "0.11.1",
52
+ "@pantheon-systems/puck-css": "0.27.0",
53
53
  "cookie": "^1.1.1",
54
54
  "launchdarkly-js-client-sdk": "^3.9.3",
55
55
  "server-only": "^0.0.1"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "@pantheon-systems/pds-toolkit-react": ">=2.0.0-alpha.92",
59
- "@puckeditor/core": ">=0.21.0",
59
+ "@puckeditor/core": ">=0.24.0",
60
60
  "next": ">=14.0.0",
61
61
  "react": ">=18.0.0",
62
62
  "react-dom": ">=18.0.0"