@simmalugnt-se/payload-editor-assistant 0.9.0 → 0.9.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.1
4
+
5
+ - The assistant no longer shows on Payload's sign-in pages (login, logout, forgot and reset
6
+ password, first user, unauthorized). Right after signing in, the panel opened on the login page
7
+ before Admin loaded.
8
+
3
9
  ## 0.9.0
4
10
 
5
11
  - Translation: on a document with localized text that is empty in the open language but filled in
@@ -1,6 +1,8 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useAuth, useTranslation } from "@payloadcms/ui";
3
+ import { useAuth, useConfig, useTranslation } from "@payloadcms/ui";
4
+ import { usePathname } from "next/navigation";
5
+ import { isAuthView } from "../view.js";
4
6
  import { useAssistantState } from "./assistant-context.js";
5
7
  import { COPY, uiLanguage } from "./copy.js";
6
8
  /** The one control that opens and closes the assistant panel, in Admin's header. */
@@ -8,7 +10,9 @@ export function EditorAssistantAction() {
8
10
  const { user } = useAuth();
9
11
  const { i18n } = useTranslation();
10
12
  const { open, setOpen } = useAssistantState();
11
- if (!user) {
13
+ const { config } = useConfig();
14
+ const pathname = usePathname();
15
+ if (!user || isAuthView(pathname ?? "", config.routes.admin, config.admin.routes)) {
12
16
  return null;
13
17
  }
14
18
  return (_jsxs("button", { "aria-expanded": open, className: open ? "ea-trigger ea-trigger--open" : "ea-trigger", onClick: (event) => {
@@ -1,14 +1,19 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useAuth } from "@payloadcms/ui";
3
+ import { useAuth, useConfig } from "@payloadcms/ui";
4
+ import { usePathname } from "next/navigation";
4
5
  import "../styles/assistant.css";
6
+ import { isAuthView } from "../view.js";
5
7
  import { AssistantStateProvider, useAssistantState } from "./assistant-context.js";
6
8
  import { ChangedFieldsHighlight } from "./ChangedFieldsHighlight.js";
7
9
  import { EditorAssistantAside } from "./EditorAssistantAside.js";
8
10
  import { useNavRoom } from "./nav-room.js";
9
11
  export function EditorAssistantProvider({ children, shortcuts = [], collections = [], }) {
10
12
  const { user } = useAuth();
11
- return (_jsx(AssistantStateProvider, { shortcuts: shortcuts, collections: collections, userId: user?.id, children: user ? _jsx(EditorAssistantShell, { children: children }) : children }));
13
+ const { config } = useConfig();
14
+ const pathname = usePathname();
15
+ const signingIn = isAuthView(pathname ?? "", config.routes.admin, config.admin.routes);
16
+ return (_jsx(AssistantStateProvider, { shortcuts: shortcuts, collections: collections, userId: user?.id, children: user && !signingIn ? _jsx(EditorAssistantShell, { children: children }) : children }));
12
17
  }
13
18
  function EditorAssistantShell({ children }) {
14
19
  const { open } = useAssistantState();
package/dist/view.d.ts CHANGED
@@ -15,6 +15,12 @@ export type AdminView = {
15
15
  };
16
16
  export type AdminViewKind = AdminView["kind"];
17
17
  export declare function parseAdminView(pathname: string, adminRoute?: string): AdminView;
18
+ /**
19
+ * Whether the path is one of Payload's sign-in pages (login, logout, forgot, reset, first user,
20
+ * unauthorized). The assistant does not show there, even in the moment after signing in when the
21
+ * user is known but the login page is still open.
22
+ */
23
+ export declare function isAuthView(pathname: string, adminRoute: string, routes?: Partial<Record<string, string>>): boolean;
18
24
  /** Keep only views that point at something the host allowlisted. */
19
25
  export declare function sanitizeAdminView(value: unknown, allowed: {
20
26
  collections: Record<string, unknown>;
package/dist/view.js CHANGED
@@ -24,6 +24,33 @@ export function parseAdminView(pathname, adminRoute = "/admin") {
24
24
  }
25
25
  return { kind: "other" };
26
26
  }
27
+ /** Payload's own sign-in routes (`admin.routes`), with Payload's defaults. */
28
+ const AUTH_ROUTES = {
29
+ login: "/login",
30
+ logout: "/logout",
31
+ inactivity: "/logout-inactivity",
32
+ forgot: "/forgot",
33
+ reset: "/reset",
34
+ createFirstUser: "/create-first-user",
35
+ unauthorized: "/unauthorized",
36
+ };
37
+ /**
38
+ * Whether the path is one of Payload's sign-in pages (login, logout, forgot, reset, first user,
39
+ * unauthorized). The assistant does not show there, even in the moment after signing in when the
40
+ * user is known but the login page is still open.
41
+ */
42
+ export function isAuthView(pathname, adminRoute, routes = {}) {
43
+ const base = trimSlashes(adminRoute);
44
+ const path = trimSlashes(pathname.split(/[?#]/)[0] ?? "");
45
+ const rest = base ? stripPrefix(path, base) : path;
46
+ if (!rest) {
47
+ return false;
48
+ }
49
+ return Object.entries(AUTH_ROUTES).some(([key, fallback]) => {
50
+ const route = trimSlashes(routes[key] ?? fallback);
51
+ return Boolean(route) && (rest === route || rest.startsWith(`${route}/`));
52
+ });
53
+ }
27
54
  /** Keep only views that point at something the host allowlisted. */
28
55
  export function sanitizeAdminView(value, allowed) {
29
56
  if (!value || typeof value !== "object") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simmalugnt-se/payload-editor-assistant",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "Context-aware editor assistant plugin for Payload Admin",
5
5
  "keywords": [
6
6
  "payload",