@withpotter/pages-admin 0.13.0-next.73 → 0.13.0-next.74

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.
@@ -5,10 +5,10 @@ const FOLDABLE_GROUPS = /* @__PURE__ */ new Set([
5
5
  "Platform"
6
6
  ]);
7
7
  const foldsGroup = (label, rows, collapsed) => label !== null && FOLDABLE_GROUPS.has(label) && rows > 1 && !collapsed;
8
- const isGroupClosed = (folded, label, containsActive) => !containsActive && folded[label] === true;
8
+ const isGroupOpen = (choice, label, containsActive) => choice === void 0 ? containsActive : choice === label;
9
9
  export {
10
10
  FOLDABLE_GROUPS,
11
11
  foldsGroup,
12
- isGroupClosed
12
+ isGroupOpen
13
13
  };
14
14
  //# sourceMappingURL=nav-fold.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/admin/_shell/nav-fold.ts"],"sourcesContent":["/**\n * Which sidebar groups can fold, and which are folded. Pure, so it is tested\n * without a browser. The merchant rail's NavSection follows the same rules.\n */\n\n/** Folded groups by label; a group not listed is open. */\nexport type FoldMap = Record<string, boolean>;\n\n/** The groups that fold; every other group keeps its plain heading. */\nexport const FOLDABLE_GROUPS: ReadonlySet<string> = new Set([\n 'Workspaces',\n 'Operations',\n 'Inbox',\n 'Platform',\n]);\n\n/**\n * A group folds only when it is one of those, has more than one row to hide,\n * and the rail is wide: the icon-only rail has no headings to press.\n */\nexport const foldsGroup = (\n label: string | null,\n rows: number,\n collapsed: boolean,\n): label is string =>\n label !== null && FOLDABLE_GROUPS.has(label) && rows > 1 && !collapsed;\n\n/**\n * Folded by the admin's choice, except while the group owns the current page:\n * shut, the page you are on would have no lit row anywhere in the nav.\n */\nexport const isGroupClosed = (\n folded: FoldMap,\n label: string,\n containsActive: boolean,\n) => !containsActive && folded[label] === true;\n"],"mappings":"AASO,MAAM,kBAAuC,oBAAI,IAAI;AAAA,EAC1D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAMM,MAAM,aAAa,CACxB,OACA,MACA,cAEA,UAAU,QAAQ,gBAAgB,IAAI,KAAK,KAAK,OAAO,KAAK,CAAC;AAMxD,MAAM,gBAAgB,CAC3B,QACA,OACA,mBACG,CAAC,kBAAkB,OAAO,KAAK,MAAM;","names":[]}
1
+ {"version":3,"sources":["../../../src/admin/_shell/nav-fold.ts"],"sourcesContent":["/**\n * Which sidebar groups fold, and which one is open. Pure, so it is tested\n * without a browser. The merchant rail's hubs follow the same rules.\n */\n\n/** The group the admin opened: one, none, or no choice yet (`undefined`). */\nexport type GroupChoice = string | null | undefined;\n\n/** The groups that fold; every other group keeps its plain heading. */\nexport const FOLDABLE_GROUPS: ReadonlySet<string> = new Set([\n 'Workspaces',\n 'Operations',\n 'Inbox',\n 'Platform',\n]);\n\n/**\n * A group folds only when it is one of those, has more than one row to hide,\n * and the rail is wide: the icon-only rail has no headings to press.\n */\nexport const foldsGroup = (\n label: string | null,\n rows: number,\n collapsed: boolean,\n): label is string =>\n label !== null && FOLDABLE_GROUPS.has(label) && rows > 1 && !collapsed;\n\n/**\n * With no choice yet the group that owns the current page is open, so the page\n * you are on always has a lit row. Once a group is chosen it is the only one\n * open: opening a second closes the first, and choosing none closes them all.\n */\nexport const isGroupOpen = (\n choice: GroupChoice,\n label: string,\n containsActive: boolean,\n) => (choice === undefined ? containsActive : choice === label);\n"],"mappings":"AASO,MAAM,kBAAuC,oBAAI,IAAI;AAAA,EAC1D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAMM,MAAM,aAAa,CACxB,OACA,MACA,cAEA,UAAU,QAAQ,gBAAgB,IAAI,KAAK,KAAK,OAAO,KAAK,CAAC;AAOxD,MAAM,cAAc,CACzB,QACA,OACA,mBACI,WAAW,SAAY,iBAAiB,WAAW;","names":[]}
@@ -1,21 +1,23 @@
1
1
  "use client";
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
3
  import { ChevronDown } from "lucide-react";
4
+ import { AnimatePresence, motion, useReducedMotion } from "motion/react";
5
+ import { eases } from "@withpotter/lib/motion";
4
6
  import { isActive } from "./nav-filter";
5
- import { foldsGroup } from "./nav-fold";
7
+ import { foldsGroup, isGroupOpen } from "./nav-fold";
6
8
  import { NavRow } from "./nav-row";
7
- import { useGroupFold } from "./use-group-fold";
8
9
  import styles from "./sidebar.module.css";
9
10
  function NavGroupView({
10
11
  group,
11
12
  pathname,
12
13
  collapsed,
13
- canSupport
14
+ canSupport,
15
+ choice,
16
+ onToggle
14
17
  }) {
18
+ const reduced = useReducedMotion();
15
19
  const { label, items } = group;
16
20
  const containsActive = items.some((item) => isActive(item, pathname));
17
- const { closed, toggle } = useGroupFold(label ?? "", containsActive);
18
- const folds = foldsGroup(label, items.length, collapsed);
19
21
  const rows = items.map((item) => /* @__PURE__ */ jsx(
20
22
  NavRow,
21
23
  {
@@ -26,34 +28,41 @@ function NavGroupView({
26
28
  },
27
29
  item.href
28
30
  ));
29
- if (!folds)
31
+ if (!foldsGroup(label, items.length, collapsed))
30
32
  return /* @__PURE__ */ jsxs("div", { className: styles.group, children: [
31
33
  label && /* @__PURE__ */ jsx("div", { className: styles.groupLabel, children: label }),
32
34
  rows
33
35
  ] });
36
+ const open = isGroupOpen(choice, label, containsActive);
34
37
  return /* @__PURE__ */ jsxs("div", { className: styles.group, children: [
35
38
  /* @__PURE__ */ jsxs(
36
39
  "button",
37
40
  {
38
41
  type: "button",
39
42
  className: `${styles.groupLabel} ${styles.groupToggle}`,
40
- "aria-expanded": !closed,
41
- onClick: toggle,
43
+ "aria-expanded": open,
44
+ onClick: () => onToggle(label, !open),
42
45
  children: [
43
46
  /* @__PURE__ */ jsx("span", { children: label }),
44
- /* @__PURE__ */ jsx(
45
- ChevronDown,
46
- {
47
- size: 14,
48
- className: styles.groupChevron,
49
- "data-closed": closed,
50
- "aria-hidden": true
51
- }
52
- )
47
+ /* @__PURE__ */ jsx(ChevronDown, { size: 14, className: styles.groupChevron, "aria-hidden": true })
53
48
  ]
54
49
  }
55
50
  ),
56
- !closed && rows
51
+ /* @__PURE__ */ jsx(AnimatePresence, { initial: false, children: open && /* @__PURE__ */ jsx(
52
+ motion.div,
53
+ {
54
+ className: styles.groupRows,
55
+ initial: { height: 0, opacity: 0 },
56
+ animate: { height: "auto", opacity: 1 },
57
+ exit: { height: 0, opacity: 0 },
58
+ transition: reduced ? { duration: 0 } : {
59
+ height: { duration: 0.24, ease: eases.settle },
60
+ opacity: { duration: 0.16, ease: eases.out }
61
+ },
62
+ style: { overflow: "hidden" },
63
+ children: rows
64
+ }
65
+ ) })
57
66
  ] });
58
67
  }
59
68
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/admin/_shell/nav-group.tsx"],"sourcesContent":["'use client';\n\nimport { ChevronDown } from 'lucide-react';\nimport type { NavGroup } from './nav-config';\nimport { isActive } from './nav-filter';\nimport { foldsGroup } from './nav-fold';\nimport { NavRow } from './nav-row';\nimport { useGroupFold } from './use-group-fold';\nimport styles from './sidebar.module.css';\n\n/**\n * One sidebar group. With a heading and more than one row, the heading is a\n * button that folds the rows away; the choice is remembered. The group that\n * holds the current page stays open, and the icon-only rail shows every row.\n */\nexport function NavGroupView({\n group,\n pathname,\n collapsed,\n canSupport,\n}: {\n group: NavGroup;\n pathname: string;\n collapsed: boolean;\n canSupport: boolean;\n}) {\n const { label, items } = group;\n const containsActive = items.some((item) => isActive(item, pathname));\n const { closed, toggle } = useGroupFold(label ?? '', containsActive);\n const folds = foldsGroup(label, items.length, collapsed);\n\n const rows = items.map((item) => (\n <NavRow\n key={item.href}\n item={item}\n active={isActive(item, pathname)}\n collapsed={collapsed}\n canSupport={canSupport}\n />\n ));\n\n if (!folds)\n return (\n <div className={styles.group}>\n {label && <div className={styles.groupLabel}>{label}</div>}\n {rows}\n </div>\n );\n\n return (\n <div className={styles.group}>\n <button\n type=\"button\"\n className={`${styles.groupLabel} ${styles.groupToggle}`}\n aria-expanded={!closed}\n onClick={toggle}\n >\n <span>{label}</span>\n <ChevronDown\n size={14}\n className={styles.groupChevron}\n data-closed={closed}\n aria-hidden\n />\n </button>\n {/* Not drawn while folded: the hover glide measures every row it finds. */}\n {!closed && rows}\n </div>\n );\n}\n"],"mappings":";AAgCI,cAWE,YAXF;AA9BJ,SAAS,mBAAmB;AAE5B,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AACvB,SAAS,oBAAoB;AAC7B,OAAO,YAAY;AAOZ,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAKG;AACD,QAAM,EAAE,OAAO,MAAM,IAAI;AACzB,QAAM,iBAAiB,MAAM,KAAK,CAAC,SAAS,SAAS,MAAM,QAAQ,CAAC;AACpE,QAAM,EAAE,QAAQ,OAAO,IAAI,aAAa,SAAS,IAAI,cAAc;AACnE,QAAM,QAAQ,WAAW,OAAO,MAAM,QAAQ,SAAS;AAEvD,QAAM,OAAO,MAAM,IAAI,CAAC,SACtB;AAAA,IAAC;AAAA;AAAA,MAEC;AAAA,MACA,QAAQ,SAAS,MAAM,QAAQ;AAAA,MAC/B;AAAA,MACA;AAAA;AAAA,IAJK,KAAK;AAAA,EAKZ,CACD;AAED,MAAI,CAAC;AACH,WACE,qBAAC,SAAI,WAAW,OAAO,OACpB;AAAA,eAAS,oBAAC,SAAI,WAAW,OAAO,YAAa,iBAAM;AAAA,MACnD;AAAA,OACH;AAGJ,SACE,qBAAC,SAAI,WAAW,OAAO,OACrB;AAAA;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,WAAW,GAAG,OAAO,UAAU,IAAI,OAAO,WAAW;AAAA,QACrD,iBAAe,CAAC;AAAA,QAChB,SAAS;AAAA,QAET;AAAA,8BAAC,UAAM,iBAAM;AAAA,UACb;AAAA,YAAC;AAAA;AAAA,cACC,MAAM;AAAA,cACN,WAAW,OAAO;AAAA,cAClB,eAAa;AAAA,cACb,eAAW;AAAA;AAAA,UACb;AAAA;AAAA;AAAA,IACF;AAAA,IAEC,CAAC,UAAU;AAAA,KACd;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/admin/_shell/nav-group.tsx"],"sourcesContent":["'use client';\n\nimport { ChevronDown } from 'lucide-react';\nimport { AnimatePresence, motion, useReducedMotion } from 'motion/react';\nimport { eases } from '@withpotter/lib/motion';\nimport type { NavGroup } from './nav-config';\nimport { isActive } from './nav-filter';\nimport { foldsGroup, isGroupOpen, type GroupChoice } from './nav-fold';\nimport { NavRow } from './nav-row';\nimport styles from './sidebar.module.css';\n\n/**\n * One sidebar group. With a heading and more than one row, the heading is a\n * button that opens and closes the rows, and only one group is open at a time.\n * The group holding the current page is open until another is chosen, and the\n * icon-only rail shows every row.\n */\nexport function NavGroupView({\n group,\n pathname,\n collapsed,\n canSupport,\n choice,\n onToggle,\n}: {\n group: NavGroup;\n pathname: string;\n collapsed: boolean;\n canSupport: boolean;\n choice: GroupChoice;\n onToggle: (label: string, next: boolean) => void;\n}) {\n const reduced = useReducedMotion();\n const { label, items } = group;\n const containsActive = items.some((item) => isActive(item, pathname));\n\n const rows = items.map((item) => (\n <NavRow\n key={item.href}\n item={item}\n active={isActive(item, pathname)}\n collapsed={collapsed}\n canSupport={canSupport}\n />\n ));\n\n if (!foldsGroup(label, items.length, collapsed))\n return (\n <div className={styles.group}>\n {label && <div className={styles.groupLabel}>{label}</div>}\n {rows}\n </div>\n );\n\n const open = isGroupOpen(choice, label, containsActive);\n\n return (\n <div className={styles.group}>\n <button\n type=\"button\"\n className={`${styles.groupLabel} ${styles.groupToggle}`}\n aria-expanded={open}\n onClick={() => onToggle(label, !open)}\n >\n <span>{label}</span>\n <ChevronDown size={14} className={styles.groupChevron} aria-hidden />\n </button>\n {/* The rows grow and collapse rather than blink, as the merchant rail's\n hubs do: height so the groups below move with them, opacity finishing\n early on the way in. Clipped, or the rows spill past the closing box. */}\n <AnimatePresence initial={false}>\n {open && (\n <motion.div\n className={styles.groupRows}\n initial={{ height: 0, opacity: 0 }}\n animate={{ height: 'auto', opacity: 1 }}\n exit={{ height: 0, opacity: 0 }}\n transition={\n reduced\n ? { duration: 0 }\n : {\n height: { duration: 0.24, ease: eases.settle },\n opacity: { duration: 0.16, ease: eases.out },\n }\n }\n style={{ overflow: 'hidden' }}\n >\n {rows}\n </motion.div>\n )}\n </AnimatePresence>\n </div>\n );\n}\n"],"mappings":";AAqCI,cAWE,YAXF;AAnCJ,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB,QAAQ,wBAAwB;AAC1D,SAAS,aAAa;AAEtB,SAAS,gBAAgB;AACzB,SAAS,YAAY,mBAAqC;AAC1D,SAAS,cAAc;AACvB,OAAO,YAAY;AAQZ,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAOG;AACD,QAAM,UAAU,iBAAiB;AACjC,QAAM,EAAE,OAAO,MAAM,IAAI;AACzB,QAAM,iBAAiB,MAAM,KAAK,CAAC,SAAS,SAAS,MAAM,QAAQ,CAAC;AAEpE,QAAM,OAAO,MAAM,IAAI,CAAC,SACtB;AAAA,IAAC;AAAA;AAAA,MAEC;AAAA,MACA,QAAQ,SAAS,MAAM,QAAQ;AAAA,MAC/B;AAAA,MACA;AAAA;AAAA,IAJK,KAAK;AAAA,EAKZ,CACD;AAED,MAAI,CAAC,WAAW,OAAO,MAAM,QAAQ,SAAS;AAC5C,WACE,qBAAC,SAAI,WAAW,OAAO,OACpB;AAAA,eAAS,oBAAC,SAAI,WAAW,OAAO,YAAa,iBAAM;AAAA,MACnD;AAAA,OACH;AAGJ,QAAM,OAAO,YAAY,QAAQ,OAAO,cAAc;AAEtD,SACE,qBAAC,SAAI,WAAW,OAAO,OACrB;AAAA;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,WAAW,GAAG,OAAO,UAAU,IAAI,OAAO,WAAW;AAAA,QACrD,iBAAe;AAAA,QACf,SAAS,MAAM,SAAS,OAAO,CAAC,IAAI;AAAA,QAEpC;AAAA,8BAAC,UAAM,iBAAM;AAAA,UACb,oBAAC,eAAY,MAAM,IAAI,WAAW,OAAO,cAAc,eAAW,MAAC;AAAA;AAAA;AAAA,IACrE;AAAA,IAIA,oBAAC,mBAAgB,SAAS,OACvB,kBACC;AAAA,MAAC,OAAO;AAAA,MAAP;AAAA,QACC,WAAW,OAAO;AAAA,QAClB,SAAS,EAAE,QAAQ,GAAG,SAAS,EAAE;AAAA,QACjC,SAAS,EAAE,QAAQ,QAAQ,SAAS,EAAE;AAAA,QACtC,MAAM,EAAE,QAAQ,GAAG,SAAS,EAAE;AAAA,QAC9B,YACE,UACI,EAAE,UAAU,EAAE,IACd;AAAA,UACE,QAAQ,EAAE,UAAU,MAAM,MAAM,MAAM,OAAO;AAAA,UAC7C,SAAS,EAAE,UAAU,MAAM,MAAM,MAAM,IAAI;AAAA,QAC7C;AAAA,QAEN,OAAO,EAAE,UAAU,SAAS;AAAA,QAE3B;AAAA;AAAA,IACH,GAEJ;AAAA,KACF;AAEJ;","names":[]}
@@ -2,6 +2,7 @@
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
3
  import { isActive } from "./nav-filter";
4
4
  import { NavGroupView } from "./nav-group";
5
+ import { useOpenGroup } from "./use-open-group";
5
6
  import { SidebarFooter } from "./sidebar-footer";
6
7
  import { useFluidHover } from "./use-fluid-hover";
7
8
  import { UserMenu } from "./user-menu";
@@ -17,6 +18,7 @@ function Sidebar({
17
18
  onSearch
18
19
  }) {
19
20
  const hover = useFluidHover();
21
+ const { choice, setGroupOpen } = useOpenGroup(pathname);
20
22
  const settings = groups.flatMap((group) => group.items).find((item) => item.href === FOOT_HREF);
21
23
  const navGroups = groups.map((group) => ({
22
24
  ...group,
@@ -50,7 +52,9 @@ function Sidebar({
50
52
  group,
51
53
  pathname,
52
54
  collapsed,
53
- canSupport
55
+ canSupport,
56
+ choice,
57
+ onToggle: setGroupOpen
54
58
  },
55
59
  group.label ?? index
56
60
  ))
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/admin/_shell/sidebar.tsx"],"sourcesContent":["'use client';\n\nimport type { NavGroup } from './nav-config';\nimport { isActive } from './nav-filter';\nimport { NavGroupView } from './nav-group';\nimport { SidebarFooter } from './sidebar-footer';\nimport { useFluidHover } from './use-fluid-hover';\nimport { UserMenu } from './user-menu';\nimport styles from './sidebar.module.css';\n\n/** Settings lives in the pinned foot, beside the theme switch. */\nconst FOOT_HREF = '/admin/settings';\n\nexport function Sidebar({\n groups,\n pathname,\n canSupport,\n collapsed,\n email,\n role,\n onSearch,\n}: {\n groups: NavGroup[];\n pathname: string;\n canSupport: boolean;\n collapsed: boolean;\n email: string;\n role: string;\n onSearch: () => void;\n}) {\n const hover = useFluidHover();\n const settings = groups\n .flatMap((group) => group.items)\n .find((item) => item.href === FOOT_HREF);\n const navGroups = groups\n .map((group) => ({\n ...group,\n items: group.items.filter((item) => item.href !== FOOT_HREF),\n }))\n .filter((group) => group.items.length);\n\n return (\n <aside className={styles.sidebar} data-collapsed={collapsed}>\n <UserMenu email={email} role={role} collapsed={collapsed} />\n\n <nav\n className={styles.nav}\n aria-label=\"Admin\"\n onPointerMove={hover.onPointerMove}\n onPointerLeave={hover.onPointerLeave}\n >\n <span\n aria-hidden\n className={styles.glide}\n data-visible={Boolean(hover.rect)}\n style={\n hover.rect\n ? {\n transform: `translateY(${hover.rect.top}px)`,\n height: hover.rect.height,\n }\n : undefined\n }\n />\n {navGroups.map((group, index) => (\n <NavGroupView\n key={group.label ?? index}\n group={group}\n pathname={pathname}\n collapsed={collapsed}\n canSupport={canSupport}\n />\n ))}\n </nav>\n\n <SidebarFooter\n collapsed={collapsed}\n showSettings={Boolean(settings)}\n settingsActive={settings ? isActive(settings, pathname) : false}\n onSearch={onSearch}\n />\n </aside>\n );\n}\n"],"mappings":";AA2CM,cAEA,YAFA;AAxCN,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,gBA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C1D;AAAA;AAAA,IACF;AAAA,KACF;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/admin/_shell/sidebar.tsx"],"sourcesContent":["'use client';\n\nimport type { NavGroup } from './nav-config';\nimport { isActive } from './nav-filter';\nimport { NavGroupView } from './nav-group';\nimport { useOpenGroup } from './use-open-group';\nimport { SidebarFooter } from './sidebar-footer';\nimport { useFluidHover } from './use-fluid-hover';\nimport { UserMenu } from './user-menu';\nimport styles from './sidebar.module.css';\n\n/** Settings lives in the pinned foot, beside the theme switch. */\nconst FOOT_HREF = '/admin/settings';\n\nexport function Sidebar({\n groups,\n pathname,\n canSupport,\n collapsed,\n email,\n role,\n onSearch,\n}: {\n groups: NavGroup[];\n pathname: string;\n canSupport: boolean;\n collapsed: boolean;\n email: string;\n role: string;\n onSearch: () => void;\n}) {\n const hover = useFluidHover();\n const { choice, setGroupOpen } = useOpenGroup(pathname);\n const settings = groups\n .flatMap((group) => group.items)\n .find((item) => item.href === FOOT_HREF);\n const navGroups = groups\n .map((group) => ({\n ...group,\n items: group.items.filter((item) => item.href !== FOOT_HREF),\n }))\n .filter((group) => group.items.length);\n\n return (\n <aside className={styles.sidebar} data-collapsed={collapsed}>\n <UserMenu email={email} role={role} collapsed={collapsed} />\n\n <nav\n className={styles.nav}\n aria-label=\"Admin\"\n onPointerMove={hover.onPointerMove}\n onPointerLeave={hover.onPointerLeave}\n >\n <span\n aria-hidden\n className={styles.glide}\n data-visible={Boolean(hover.rect)}\n style={\n hover.rect\n ? {\n transform: `translateY(${hover.rect.top}px)`,\n height: hover.rect.height,\n }\n : undefined\n }\n />\n {navGroups.map((group, index) => (\n <NavGroupView\n key={group.label ?? index}\n group={group}\n pathname={pathname}\n collapsed={collapsed}\n canSupport={canSupport}\n choice={choice}\n onToggle={setGroupOpen}\n />\n ))}\n </nav>\n\n <SidebarFooter\n collapsed={collapsed}\n showSettings={Boolean(settings)}\n settingsActive={settings ? isActive(settings, pathname) : false}\n onSearch={onSearch}\n />\n </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;AAAA,cACA;AAAA,cACA;AAAA,cACA,UAAU;AAAA;AAAA,YANL,MAAM,SAAS;AAAA,UAOtB,CACD;AAAA;AAAA;AAAA,IACH;AAAA,IAEA;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA,cAAc,QAAQ,QAAQ;AAAA,QAC9B,gBAAgB,WAAW,SAAS,UAAU,QAAQ,IAAI;AAAA,QAC1D;AAAA;AAAA,IACF;AAAA,KACF;AAEJ;","names":[]}
@@ -92,20 +92,37 @@
92
92
  flex: none;
93
93
  opacity: 0;
94
94
  transition:
95
- opacity var(--adm-fast),
96
- transform var(--adm-fast);
95
+ transform var(--adm-fast),
96
+ opacity var(--adm-fast);
97
97
  }
98
98
 
99
+ /* The chevron arrives on hover, as on the merchant rail, and stays while the
100
+ group is open, rotated, to say the rows below belong to this heading. A
101
+ keyboard has no pointer and touch has no hover, so those keep it too. */
99
102
  .groupToggle:hover .groupChevron,
100
- .groupToggle:focus-visible .groupChevron {
103
+ .groupToggle:focus-visible .groupChevron,
104
+ .groupToggle[aria-expanded='true'] .groupChevron {
101
105
  opacity: 1;
102
106
  }
103
107
 
104
- /* A folded group always shows its chevron: otherwise the only sign that rows
105
- are hidden is their absence. */
106
- .groupChevron[data-closed='true'] {
107
- opacity: 1;
108
- transform: rotate(-90deg);
108
+ .groupToggle[aria-expanded='true'] .groupChevron {
109
+ transform: rotate(180deg);
110
+ }
111
+
112
+ @media (hover: none) {
113
+ .groupChevron {
114
+ opacity: 1;
115
+ }
116
+ }
117
+
118
+ /* The rows of a folding group, laid out like the group's own. The padding keeps
119
+ a focus ring from being clipped by the closing box; the margin takes it back. */
120
+ .groupRows {
121
+ display: flex;
122
+ flex-direction: column;
123
+ gap: 2px;
124
+ padding: 2px;
125
+ margin: -2px;
109
126
  }
110
127
 
111
128
  .link {
@@ -0,0 +1,16 @@
1
+ "use client";
2
+ import { useState } from "react";
3
+ function useOpenGroup(pathname) {
4
+ const [choice, setChoice] = useState(void 0);
5
+ const setGroupOpen = (label, next) => setChoice(next ? label : null);
6
+ const [choiceRoute, setChoiceRoute] = useState(pathname);
7
+ if (choiceRoute !== pathname) {
8
+ setChoiceRoute(pathname);
9
+ setChoice(void 0);
10
+ }
11
+ return { choice, setGroupOpen };
12
+ }
13
+ export {
14
+ useOpenGroup
15
+ };
16
+ //# sourceMappingURL=use-open-group.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/admin/_shell/use-open-group.ts"],"sourcesContent":["'use client';\n\nimport { useState } from 'react';\nimport type { GroupChoice } from './nav-fold';\n\n/**\n * Which sidebar group is showing its rows: ONE, none, or \"not said yet\"\n * (`undefined`, which leaves the group owning the current page open). The\n * merchant rail's useOpenHub, for the admin's groups.\n */\nexport function useOpenGroup(pathname: string) {\n const [choice, setChoice] = useState<GroupChoice>(undefined);\n const setGroupOpen = (label: string, next: boolean) =>\n setChoice(next ? label : null);\n // A new route retires the choice, or arriving from inside the page would\n // leave the rail on the last group pressed, with the current row hidden.\n // Adjusted during render, not in an effect, so no stale frame paints first.\n const [choiceRoute, setChoiceRoute] = useState(pathname);\n\n if (choiceRoute !== pathname) {\n setChoiceRoute(pathname);\n setChoice(undefined);\n }\n\n return { choice, setGroupOpen };\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AAQlB,SAAS,aAAa,UAAkB;AAC7C,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAsB,MAAS;AAC3D,QAAM,eAAe,CAAC,OAAe,SACnC,UAAU,OAAO,QAAQ,IAAI;AAI/B,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,QAAQ;AAEvD,MAAI,gBAAgB,UAAU;AAC5B,mBAAe,QAAQ;AACvB,cAAU,MAAS;AAAA,EACrB;AAEA,SAAO,EAAE,QAAQ,aAAa;AAChC;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@withpotter/pages-admin",
3
- "version": "0.13.0-next.73",
3
+ "version": "0.13.0-next.74",
4
4
  "description": "Box console platform-admin routes: overview, revenue, accounts, tenants, admins, roles, audit.",
5
5
  "license": "UNLICENSED",
6
6
  "sideEffects": false,
@@ -31,9 +31,9 @@
31
31
  "dependencies": {
32
32
  "@radix-ui/react-popover": "^1.1.23",
33
33
  "@tanstack/react-query": "^5.90.20",
34
- "@withpotter/lib": "^0.13.0-next.73",
35
- "@withpotter/platform-admin": "^0.13.0-next.73",
36
- "@withpotter/ui-kit": "^0.13.0-next.73",
34
+ "@withpotter/lib": "^0.13.0-next.74",
35
+ "@withpotter/platform-admin": "^0.13.0-next.74",
36
+ "@withpotter/ui-kit": "^0.13.0-next.74",
37
37
  "lucide-react": "^0.562.0",
38
38
  "motion": "^12.42.2"
39
39
  },
@@ -1,50 +0,0 @@
1
- "use client";
2
- import { useCallback, useSyncExternalStore } from "react";
3
- import { isGroupClosed } from "./nav-fold";
4
- const STORAGE_KEY = "pb_admin_nav_closed";
5
- let closedCache = {};
6
- let closedRaw = null;
7
- const listeners = /* @__PURE__ */ new Set();
8
- function readClosed() {
9
- if (typeof window === "undefined") return closedCache;
10
- let raw = null;
11
- try {
12
- raw = localStorage.getItem(STORAGE_KEY);
13
- } catch {
14
- return closedCache;
15
- }
16
- if (raw !== closedRaw) {
17
- closedRaw = raw;
18
- try {
19
- closedCache = raw ? JSON.parse(raw) : {};
20
- } catch {
21
- closedCache = {};
22
- }
23
- }
24
- return closedCache;
25
- }
26
- const serverSnapshot = () => closedCache;
27
- function subscribe(fn) {
28
- listeners.add(fn);
29
- return () => listeners.delete(fn);
30
- }
31
- function setClosed(label, closed) {
32
- const next = { ...readClosed(), [label]: closed };
33
- try {
34
- localStorage.setItem(STORAGE_KEY, JSON.stringify(next));
35
- } catch {
36
- }
37
- closedRaw = JSON.stringify(next);
38
- closedCache = next;
39
- listeners.forEach((fn) => fn());
40
- }
41
- function useGroupFold(label, containsActive) {
42
- const folded = useSyncExternalStore(subscribe, readClosed, serverSnapshot);
43
- const closed = isGroupClosed(folded, label, containsActive);
44
- const toggle = useCallback(() => setClosed(label, !closed), [label, closed]);
45
- return { closed, toggle };
46
- }
47
- export {
48
- useGroupFold
49
- };
50
- //# sourceMappingURL=use-group-fold.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/admin/_shell/use-group-fold.ts"],"sourcesContent":["'use client';\n\nimport { useCallback, useSyncExternalStore } from 'react';\nimport { isGroupClosed, type FoldMap } from './nav-fold';\n\nconst STORAGE_KEY = 'pb_admin_nav_closed';\n\n/**\n * Which groups the admin has folded away, as an external store. localStorage\n * does not exist while the server renders, so reading it into state would\n * mismatch the HTML; useSyncExternalStore is built for this (the merchant\n * rail's NavSection does the same).\n */\nlet closedCache: FoldMap = {};\nlet closedRaw: string | null = null;\nconst listeners = new Set<() => void>();\n\nfunction readClosed(): FoldMap {\n if (typeof window === 'undefined') return closedCache;\n\n let raw: string | null = null;\n\n try {\n raw = localStorage.getItem(STORAGE_KEY);\n } catch {\n return closedCache;\n }\n\n // Cached by raw string so the snapshot is stable between renders; a fresh\n // object every call makes useSyncExternalStore loop.\n if (raw !== closedRaw) {\n closedRaw = raw;\n\n try {\n closedCache = raw ? JSON.parse(raw) : {};\n } catch {\n closedCache = {};\n }\n }\n\n return closedCache;\n}\n\n/** The server has no localStorage, so nothing is folded on first paint. */\nconst serverSnapshot = () => closedCache;\n\nfunction subscribe(fn: () => void) {\n listeners.add(fn);\n\n return () => listeners.delete(fn);\n}\n\nfunction setClosed(label: string, closed: boolean) {\n const next = { ...readClosed(), [label]: closed };\n\n try {\n localStorage.setItem(STORAGE_KEY, JSON.stringify(next));\n } catch {\n /* private mode: the choice just won't survive the visit */\n }\n\n closedRaw = JSON.stringify(next);\n closedCache = next;\n listeners.forEach((fn) => fn());\n}\n\nexport function useGroupFold(label: string, containsActive: boolean) {\n const folded = useSyncExternalStore(subscribe, readClosed, serverSnapshot);\n const closed = isGroupClosed(folded, label, containsActive);\n const toggle = useCallback(() => setClosed(label, !closed), [label, closed]);\n\n return { closed, toggle };\n}\n"],"mappings":";AAEA,SAAS,aAAa,4BAA4B;AAClD,SAAS,qBAAmC;AAE5C,MAAM,cAAc;AAQpB,IAAI,cAAuB,CAAC;AAC5B,IAAI,YAA2B;AAC/B,MAAM,YAAY,oBAAI,IAAgB;AAEtC,SAAS,aAAsB;AAC7B,MAAI,OAAO,WAAW,YAAa,QAAO;AAE1C,MAAI,MAAqB;AAEzB,MAAI;AACF,UAAM,aAAa,QAAQ,WAAW;AAAA,EACxC,QAAQ;AACN,WAAO;AAAA,EACT;AAIA,MAAI,QAAQ,WAAW;AACrB,gBAAY;AAEZ,QAAI;AACF,oBAAc,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;AAAA,IACzC,QAAQ;AACN,oBAAc,CAAC;AAAA,IACjB;AAAA,EACF;AAEA,SAAO;AACT;AAGA,MAAM,iBAAiB,MAAM;AAE7B,SAAS,UAAU,IAAgB;AACjC,YAAU,IAAI,EAAE;AAEhB,SAAO,MAAM,UAAU,OAAO,EAAE;AAClC;AAEA,SAAS,UAAU,OAAe,QAAiB;AACjD,QAAM,OAAO,EAAE,GAAG,WAAW,GAAG,CAAC,KAAK,GAAG,OAAO;AAEhD,MAAI;AACF,iBAAa,QAAQ,aAAa,KAAK,UAAU,IAAI,CAAC;AAAA,EACxD,QAAQ;AAAA,EAER;AAEA,cAAY,KAAK,UAAU,IAAI;AAC/B,gBAAc;AACd,YAAU,QAAQ,CAAC,OAAO,GAAG,CAAC;AAChC;AAEO,SAAS,aAAa,OAAe,gBAAyB;AACnE,QAAM,SAAS,qBAAqB,WAAW,YAAY,cAAc;AACzE,QAAM,SAAS,cAAc,QAAQ,OAAO,cAAc;AAC1D,QAAM,SAAS,YAAY,MAAM,UAAU,OAAO,CAAC,MAAM,GAAG,CAAC,OAAO,MAAM,CAAC;AAE3E,SAAO,EAAE,QAAQ,OAAO;AAC1B;","names":[]}