@coffre/ui 0.1.18 → 0.2.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.
Files changed (235) hide show
  1. package/README.md +23 -3
  2. package/dist/{server/_coffre/assets/affordances-CKANXDTG.js → chunks/affordances-DAvsVz7u.js} +12 -7
  3. package/dist/chunks/affordances-DAvsVz7u.js.map +1 -0
  4. package/dist/chunks/directory-CSjWWUQ1.js +370 -0
  5. package/dist/chunks/directory-CSjWWUQ1.js.map +1 -0
  6. package/dist/{server/_coffre/assets/grants-DdKT11Ny.js → chunks/grants-saMQagmG.js} +41 -39
  7. package/dist/chunks/grants-saMQagmG.js.map +1 -0
  8. package/dist/chunks/icons-D-PfAfnH.js +203 -0
  9. package/dist/chunks/icons-D-PfAfnH.js.map +1 -0
  10. package/dist/chunks/mounted-jJmqqV_n.js +17 -0
  11. package/dist/chunks/mounted-jJmqqV_n.js.map +1 -0
  12. package/dist/{server/_coffre/assets/offboarding-CRz-K82H.js → chunks/offboarding-C6l30DZR.js} +70 -69
  13. package/dist/chunks/offboarding-C6l30DZR.js.map +1 -0
  14. package/dist/chunks/page-C5HcNqf2.js +190 -0
  15. package/dist/chunks/page-C5HcNqf2.js.map +1 -0
  16. package/dist/chunks/page-route-Drfw7lmn.js +20 -0
  17. package/dist/chunks/page-route-Drfw7lmn.js.map +1 -0
  18. package/dist/{server/_coffre/assets/principal-page-C-EFwJQw.js → chunks/principal-page-D_91OA0l.js} +105 -103
  19. package/dist/chunks/principal-page-D_91OA0l.js.map +1 -0
  20. package/dist/{server/_coffre/assets → chunks}/project-environments-lEzFHUt4.js +2 -0
  21. package/dist/chunks/project-environments-lEzFHUt4.js.map +1 -0
  22. package/dist/chunks/queries-CQ81o4so.js +376 -0
  23. package/dist/chunks/queries-CQ81o4so.js.map +1 -0
  24. package/dist/{server/_coffre/assets/row-state-C2P57xT1.js → chunks/row-state-0PsrEzOL.js} +22 -21
  25. package/dist/chunks/row-state-0PsrEzOL.js.map +1 -0
  26. package/dist/{server/_coffre/assets → chunks}/signin-errors-BEFlVDbQ.js +2 -0
  27. package/dist/chunks/signin-errors-BEFlVDbQ.js.map +1 -0
  28. package/dist/chunks/theme-B2vQolVR.js +86 -0
  29. package/dist/chunks/theme-B2vQolVR.js.map +1 -0
  30. package/dist/chunks/ui-DixXLQvQ.js +405 -0
  31. package/dist/chunks/ui-DixXLQvQ.js.map +1 -0
  32. package/dist/{server/_coffre/assets/use-action-B-xpvVRO.js → chunks/use-action-CWsg_YWU.js} +8 -6
  33. package/dist/chunks/use-action-CWsg_YWU.js.map +1 -0
  34. package/dist/{server/_coffre/assets/use-change-C8BCf3oU.js → chunks/use-change-c6CeLRin.js} +10 -474
  35. package/dist/chunks/use-change-c6CeLRin.js.map +1 -0
  36. package/dist/chunks/use-shell-jxd7Tzd-.js +26 -0
  37. package/dist/chunks/use-shell-jxd7Tzd-.js.map +1 -0
  38. package/dist/{server/_coffre/assets → chunks}/validation-BQtqPe2V.js +2 -0
  39. package/dist/chunks/validation-BQtqPe2V.js.map +1 -0
  40. package/dist/index.d.ts +386 -18
  41. package/dist/index.js +1147 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/pages/account.d.ts +9 -0
  44. package/dist/pages/account.js +334 -0
  45. package/dist/pages/account.js.map +1 -0
  46. package/dist/pages/audit.d.ts +3 -0
  47. package/dist/{server/_coffre/assets/audit-qB9G2AQJ.js → pages/audit.js} +102 -100
  48. package/dist/pages/audit.js.map +1 -0
  49. package/dist/pages/device-login.d.ts +9 -0
  50. package/dist/pages/device-login.js +211 -0
  51. package/dist/pages/device-login.js.map +1 -0
  52. package/dist/pages/environment.d.ts +3 -0
  53. package/dist/{server/_coffre/assets/projects._project._environment-C6uybzeU.js → pages/environment.js} +323 -469
  54. package/dist/pages/environment.js.map +1 -0
  55. package/dist/pages/login.d.ts +10 -0
  56. package/dist/pages/login.js +104 -0
  57. package/dist/pages/login.js.map +1 -0
  58. package/dist/pages/project.d.ts +2 -0
  59. package/dist/{server/_coffre/assets/projects._project.index-3CXwkyTh.js → pages/project.js} +223 -225
  60. package/dist/pages/project.js.map +1 -0
  61. package/dist/pages/projects.d.ts +3 -0
  62. package/dist/{server/_coffre/assets/projects.index-iSoBpRFz.js → pages/projects.js} +83 -81
  63. package/dist/pages/projects.js.map +1 -0
  64. package/dist/pages/settings.d.ts +3 -0
  65. package/dist/{server/_coffre/assets/settings-BDQTF5XW.js → pages/settings.js} +20 -18
  66. package/dist/pages/settings.js.map +1 -0
  67. package/dist/pages/token.d.ts +3 -0
  68. package/dist/{server/_coffre/assets/tokens._token-CrBMpcbN.js → pages/token.js} +195 -265
  69. package/dist/pages/token.js.map +1 -0
  70. package/dist/pages/tokens.d.ts +3 -0
  71. package/dist/pages/tokens.js +39 -0
  72. package/dist/pages/tokens.js.map +1 -0
  73. package/dist/pages/unregistered.d.ts +8 -0
  74. package/dist/pages/unregistered.js +54 -0
  75. package/dist/pages/unregistered.js.map +1 -0
  76. package/dist/pages/user.d.ts +3 -0
  77. package/dist/pages/user.js +16 -0
  78. package/dist/pages/user.js.map +1 -0
  79. package/dist/pages/users.d.ts +3 -0
  80. package/dist/pages/users.js +39 -0
  81. package/dist/pages/users.js.map +1 -0
  82. package/dist/project-BqIy8gYR.d.ts +5 -0
  83. package/dist/vite.d.ts +16 -0
  84. package/dist/vite.js +52 -0
  85. package/package.json +36 -21
  86. package/src/assets/icon.svg +1 -0
  87. package/src/components/affordances.ts +10 -4
  88. package/src/components/command-palette.tsx +229 -203
  89. package/src/components/directory.tsx +34 -38
  90. package/src/components/principal.tsx +7 -3
  91. package/src/components/shell.tsx +89 -127
  92. package/src/components/theme.tsx +14 -81
  93. package/src/components/ui.tsx +97 -68
  94. package/src/index.ts +29 -0
  95. package/src/layout.tsx +113 -0
  96. package/src/lib/coffre.ts +8 -4
  97. package/src/lib/mounted.ts +13 -0
  98. package/src/lib/page-context.ts +31 -0
  99. package/src/lib/page-route.ts +22 -0
  100. package/src/lib/preferences.tsx +46 -0
  101. package/src/options.ts +240 -0
  102. package/src/{routes → pages}/account.tsx +7 -24
  103. package/src/{routes → pages}/audit.tsx +5 -16
  104. package/src/{routes/auth.device.tsx → pages/device-login.tsx} +8 -21
  105. package/src/{routes/projects.$project.$environment.tsx → pages/environment.tsx} +43 -52
  106. package/src/{routes → pages}/login.tsx +5 -16
  107. package/src/{routes/projects.$project.index.tsx → pages/project.tsx} +38 -50
  108. package/src/{routes/projects.index.tsx → pages/projects.tsx} +2 -7
  109. package/src/{routes → pages}/settings.tsx +3 -10
  110. package/src/{routes/tokens.$token.tsx → pages/token.tsx} +6 -7
  111. package/src/{routes/tokens.index.tsx → pages/tokens.tsx} +3 -8
  112. package/src/{routes → pages}/unregistered.tsx +1 -6
  113. package/src/pages/user.tsx +10 -0
  114. package/src/{routes/users.index.tsx → pages/users.tsx} +3 -8
  115. package/src/register.ts +55 -0
  116. package/src/router.tsx +31 -62
  117. package/src/styles/globals.css +104 -46
  118. package/src/vite.ts +78 -0
  119. package/dist/client/.assetsignore +0 -2
  120. package/dist/client/_coffre/assets/account-BoLGAxbD.js +0 -2
  121. package/dist/client/_coffre/assets/account-CnnuRTDB.js +0 -1
  122. package/dist/client/_coffre/assets/affordances-CEafRJcN.js +0 -1
  123. package/dist/client/_coffre/assets/audit-CHSvKLWX.js +0 -1
  124. package/dist/client/_coffre/assets/audit-Cn4hmS4u.js +0 -2
  125. package/dist/client/_coffre/assets/auth.device-Co5vrpaA.js +0 -2
  126. package/dist/client/_coffre/assets/auth.device-DAlqWacc.js +0 -1
  127. package/dist/client/_coffre/assets/directory-H8Eh3MnS.js +0 -1
  128. package/dist/client/_coffre/assets/dist-Braunv_x.js +0 -1
  129. package/dist/client/_coffre/assets/globals-CpMrgkV6.css +0 -1
  130. package/dist/client/_coffre/assets/grants-DPDxJXU1.js +0 -1
  131. package/dist/client/_coffre/assets/icons-Dc_-t0lp.js +0 -1
  132. package/dist/client/_coffre/assets/index-sUCIXRgJ.js +0 -12
  133. package/dist/client/_coffre/assets/inter-cyrillic-ext-opsz-normal-CfYZpDVp.woff2 +0 -0
  134. package/dist/client/_coffre/assets/inter-cyrillic-opsz-normal-BFQXbQ-f.woff2 +0 -0
  135. package/dist/client/_coffre/assets/inter-greek-ext-opsz-normal-BmPQvyvo.woff2 +0 -0
  136. package/dist/client/_coffre/assets/inter-greek-opsz-normal-BM0NlUE_.woff2 +0 -0
  137. package/dist/client/_coffre/assets/inter-latin-ext-opsz-normal-DpK-iCPk.woff2 +0 -0
  138. package/dist/client/_coffre/assets/inter-latin-opsz-normal-BwkfbSeq.woff2 +0 -0
  139. package/dist/client/_coffre/assets/inter-vietnamese-opsz-normal-Ci9T9ieq.woff2 +0 -0
  140. package/dist/client/_coffre/assets/jetbrains-mono-cyrillic-ext-wght-normal-EocZY2iu.woff2 +0 -0
  141. package/dist/client/_coffre/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
  142. package/dist/client/_coffre/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
  143. package/dist/client/_coffre/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
  144. package/dist/client/_coffre/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
  145. package/dist/client/_coffre/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
  146. package/dist/client/_coffre/assets/link-DBINMwm6.js +0 -1
  147. package/dist/client/_coffre/assets/login-BZFYfL1Y.js +0 -1
  148. package/dist/client/_coffre/assets/login-CYCKWTOD.js +0 -2
  149. package/dist/client/_coffre/assets/offboarding-Bwpftp3g.js +0 -1
  150. package/dist/client/_coffre/assets/page-C_hnzdaR.js +0 -1
  151. package/dist/client/_coffre/assets/preload-helper-CLkO85Nq.js +0 -1
  152. package/dist/client/_coffre/assets/principal-page-DLho8TSJ.js +0 -1
  153. package/dist/client/_coffre/assets/project-environments-CfIH5kFM.js +0 -1
  154. package/dist/client/_coffre/assets/projects._project._environment-DHRRvQw0.js +0 -3
  155. package/dist/client/_coffre/assets/projects._project._environment-TLI-RjBZ.js +0 -2
  156. package/dist/client/_coffre/assets/projects._project.index-BO-8FZIY.js +0 -2
  157. package/dist/client/_coffre/assets/projects._project.index-DGl921dP.js +0 -1
  158. package/dist/client/_coffre/assets/projects.index-BDn7Bhoo.js +0 -1
  159. package/dist/client/_coffre/assets/row-state-DJ-KLamZ.js +0 -1
  160. package/dist/client/_coffre/assets/settings-q9G1QvR_.js +0 -1
  161. package/dist/client/_coffre/assets/signin-errors-CroZWZgm.js +0 -1
  162. package/dist/client/_coffre/assets/suspense-O8sP0mEC.js +0 -1
  163. package/dist/client/_coffre/assets/tokens._token-B_qczpT9.js +0 -2
  164. package/dist/client/_coffre/assets/tokens._token-T-sqwMbz.js +0 -2
  165. package/dist/client/_coffre/assets/tokens.index-CcXSZnAG.js +0 -1
  166. package/dist/client/_coffre/assets/ui-BXP2IqrW.js +0 -46
  167. package/dist/client/_coffre/assets/unregistered-D2JXJ90x.js +0 -1
  168. package/dist/client/_coffre/assets/use-action-BpzKWhgg.js +0 -1
  169. package/dist/client/_coffre/assets/use-change-CKj3Inq9.js +0 -1
  170. package/dist/client/_coffre/assets/use-shell-W0SusPkz.js +0 -1
  171. package/dist/client/_coffre/assets/useQuery-B-lxFSES.js +0 -1
  172. package/dist/client/_coffre/assets/useSuspenseQuery-BZ-nzHST.js +0 -1
  173. package/dist/client/_coffre/assets/users._user-Bb3BGYHl.js +0 -1
  174. package/dist/client/_coffre/assets/users._user-DXmvKrzE.js +0 -2
  175. package/dist/client/_coffre/assets/users.index-BvzP3qwW.js +0 -1
  176. package/dist/client/_coffre/assets/validation-9Cl_XS-l.js +0 -1
  177. package/dist/server/.vite/manifest.json +0 -668
  178. package/dist/server/_coffre/assets/_tanstack-start-manifest_v-GsKnGGRy.js +0 -162
  179. package/dist/server/_coffre/assets/account-CV-a2IU2.js +0 -329
  180. package/dist/server/_coffre/assets/account-hk6wcIXU.js +0 -162
  181. package/dist/server/_coffre/assets/async-local-storage-C10uQtMM.js +0 -3108
  182. package/dist/server/_coffre/assets/audit-C1_Ej6YB.js +0 -31
  183. package/dist/server/_coffre/assets/auth.device-6JRrWbSV.js +0 -210
  184. package/dist/server/_coffre/assets/auth.device-CLoAxC2T.js +0 -29
  185. package/dist/server/_coffre/assets/directory-B-_rqsPx.js +0 -371
  186. package/dist/server/_coffre/assets/dist-CnnV3t2g.js +0 -908
  187. package/dist/server/_coffre/assets/empty-plugin-adapters-Cq4--YW-.js +0 -5
  188. package/dist/server/_coffre/assets/globals-CpMrgkV6.css +0 -1
  189. package/dist/server/_coffre/assets/icons-DOFT-eWB.js +0 -1704
  190. package/dist/server/_coffre/assets/inter-cyrillic-ext-opsz-normal-CfYZpDVp.woff2 +0 -0
  191. package/dist/server/_coffre/assets/inter-cyrillic-opsz-normal-BFQXbQ-f.woff2 +0 -0
  192. package/dist/server/_coffre/assets/inter-greek-ext-opsz-normal-BmPQvyvo.woff2 +0 -0
  193. package/dist/server/_coffre/assets/inter-greek-opsz-normal-BM0NlUE_.woff2 +0 -0
  194. package/dist/server/_coffre/assets/inter-latin-ext-opsz-normal-DpK-iCPk.woff2 +0 -0
  195. package/dist/server/_coffre/assets/inter-latin-opsz-normal-BwkfbSeq.woff2 +0 -0
  196. package/dist/server/_coffre/assets/inter-vietnamese-opsz-normal-Ci9T9ieq.woff2 +0 -0
  197. package/dist/server/_coffre/assets/jetbrains-mono-cyrillic-ext-wght-normal-EocZY2iu.woff2 +0 -0
  198. package/dist/server/_coffre/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
  199. package/dist/server/_coffre/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
  200. package/dist/server/_coffre/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
  201. package/dist/server/_coffre/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
  202. package/dist/server/_coffre/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
  203. package/dist/server/_coffre/assets/lazyRouteComponent-CqBNCGuZ.js +0 -480
  204. package/dist/server/_coffre/assets/link-42ZWdjzZ.js +0 -422
  205. package/dist/server/_coffre/assets/login-DRKUKkaW.js +0 -22
  206. package/dist/server/_coffre/assets/login-DnwxVl4Y.js +0 -102
  207. package/dist/server/_coffre/assets/matchContext-qLfYbC6_.js +0 -56
  208. package/dist/server/_coffre/assets/page-D6n45dcK.js +0 -3561
  209. package/dist/server/_coffre/assets/projects._project._environment-CS8DdSMY.js +0 -48
  210. package/dist/server/_coffre/assets/projects._project.index-BGfcNpj0.js +0 -23
  211. package/dist/server/_coffre/assets/react-dom-bBoJXlK2.js +0 -1718
  212. package/dist/server/_coffre/assets/router-9BTgJhWG.js +0 -2322
  213. package/dist/server/_coffre/assets/start-DR3rN0St.js +0 -4
  214. package/dist/server/_coffre/assets/suspense-C-2QfDd2.js +0 -602
  215. package/dist/server/_coffre/assets/tokens._token-rY86Cjgp.js +0 -10
  216. package/dist/server/_coffre/assets/tokens.index-Bq5qDW9q.js +0 -37
  217. package/dist/server/_coffre/assets/ui-Cc0CGMtr.js +0 -14881
  218. package/dist/server/_coffre/assets/unregistered-D9ZKLOPJ.js +0 -53
  219. package/dist/server/_coffre/assets/use-shell-DwOzEi87.js +0 -462
  220. package/dist/server/_coffre/assets/useQuery-CTe86qFq.js +0 -8
  221. package/dist/server/_coffre/assets/useRouter-CaUSUNsw.js +0 -473
  222. package/dist/server/_coffre/assets/useSuspenseQuery-CSoHzrMb.js +0 -117
  223. package/dist/server/_coffre/assets/users._user-BmLKYeo_.js +0 -10
  224. package/dist/server/_coffre/assets/users._user-BmiHwQx3.js +0 -14
  225. package/dist/server/_coffre/assets/users.index-BiEax90r.js +0 -37
  226. package/dist/server/index.js +0 -13911
  227. package/src/assets/favicon-32.png +0 -0
  228. package/src/components/agentation.tsx +0 -34
  229. package/src/entry.ts +0 -19
  230. package/src/routeTree.gen.ts +0 -367
  231. package/src/routes/__root.tsx +0 -169
  232. package/src/routes/access.tsx +0 -11
  233. package/src/routes/index.tsx +0 -15
  234. package/src/routes/users.$user.tsx +0 -13
  235. package/src/types.ts +0 -21
@@ -1,13 +1,11 @@
1
- import {
2
- useEffect,
3
- useRef,
4
- useState,
5
- type MouseEvent,
6
- type PointerEvent,
7
- type ReactNode,
8
- } from 'react';
9
- import { AlertDialog, Dialog, Popover, Tooltip } from 'radix-ui';
1
+ import { useEffect, useRef, useState, type ReactElement, type ReactNode } from 'react';
2
+ import { AlertDialog } from '@base-ui/react/alert-dialog';
3
+ import { Dialog } from '@base-ui/react/dialog';
4
+ import { Menu } from '@base-ui/react/menu';
5
+ import { Popover } from '@base-ui/react/popover';
6
+ import { Tooltip } from '@base-ui/react/tooltip';
10
7
  import { AlertCircle, AlertTriangle, Check, Copy, Info, Loader, X } from './icons';
8
+ import { usePreferences } from '../lib/preferences';
11
9
 
12
10
  /* -------------------------------------------------------------------------- */
13
11
  /* Tooltip */
@@ -18,7 +16,7 @@ export function TooltipProvider({ children }: { children: ReactNode }) {
18
16
  // makes a row of controls feel immediate without the delay losing its
19
17
  // purpose (preventing accidental activation on a passing cursor).
20
18
  return (
21
- <Tooltip.Provider delayDuration={400} skipDelayDuration={300}>
19
+ <Tooltip.Provider delay={400} timeout={300}>
22
20
  {children}
23
21
  </Tooltip.Provider>
24
22
  );
@@ -31,15 +29,21 @@ export function Tip({
31
29
  }: {
32
30
  label: ReactNode;
33
31
  side?: 'top' | 'right' | 'bottom' | 'left';
34
- children: ReactNode;
32
+ children: ReactElement;
35
33
  }) {
34
+ const { portal } = usePreferences();
36
35
  return (
37
36
  <Tooltip.Root>
38
- <Tooltip.Trigger asChild>{children}</Tooltip.Trigger>
39
- <Tooltip.Portal>
40
- <Tooltip.Content className="tooltip" side={side} sideOffset={6} collisionPadding={8}>
41
- {label}
42
- </Tooltip.Content>
37
+ <Tooltip.Trigger render={children} />
38
+ <Tooltip.Portal container={portal}>
39
+ <Tooltip.Positioner
40
+ className="tooltip-positioner"
41
+ side={side}
42
+ sideOffset={6}
43
+ collisionPadding={8}
44
+ >
45
+ <Tooltip.Popup className="tooltip">{label}</Tooltip.Popup>
46
+ </Tooltip.Positioner>
43
47
  </Tooltip.Portal>
44
48
  </Tooltip.Root>
45
49
  );
@@ -63,46 +67,83 @@ export function Toggletip({
63
67
  side?: 'top' | 'right' | 'bottom' | 'left';
64
68
  /** `end` for a trigger at the right edge, so the tip opens leftwards. */
65
69
  align?: 'start' | 'center' | 'end';
66
- children: ReactNode;
70
+ children: ReactElement;
67
71
  }) {
72
+ const { portal } = usePreferences();
68
73
  const [open, setOpen] = useState(false);
69
- const pointer = useRef<string | null>(null);
74
+ const mouse = useRef(false);
70
75
  const hover = (next: boolean) => (event: { pointerType: string }) => {
71
76
  if (event.pointerType === 'mouse') setOpen(next);
72
77
  };
73
78
 
74
79
  return (
75
- <Popover.Root open={open} onOpenChange={setOpen}>
80
+ <Popover.Root
81
+ open={open}
82
+ onOpenChange={(next, { reason }) => {
83
+ const clicked = reason === 'trigger-press' && mouse.current;
84
+ mouse.current = false;
85
+ if (!clicked) setOpen(next);
86
+ }}
87
+ >
76
88
  <Popover.Trigger
77
- asChild
89
+ render={children}
78
90
  onPointerEnter={hover(true)}
79
91
  onPointerLeave={hover(false)}
80
- onPointerDown={(event: PointerEvent) => {
81
- pointer.current = event.pointerType;
82
- }}
83
- onClick={(event: MouseEvent) => {
84
- if (pointer.current === 'mouse') event.preventDefault();
85
- pointer.current = null;
92
+ onPointerDown={(event) => {
93
+ mouse.current = event.pointerType === 'mouse';
86
94
  }}
87
- >
88
- {children}
89
- </Popover.Trigger>
90
- <Popover.Portal>
91
- <Popover.Content
92
- className="tooltip"
95
+ />
96
+ <Popover.Portal container={portal}>
97
+ <Popover.Positioner
98
+ className="tooltip-positioner"
93
99
  side={side}
94
100
  align={align}
95
101
  sideOffset={6}
96
102
  collisionPadding={16}
97
- onOpenAutoFocus={(event: Event) => event.preventDefault()}
98
103
  >
99
- {label}
100
- </Popover.Content>
104
+ {/* Focus stays on the trigger, so there is nothing to return it to. */}
105
+ <Popover.Popup className="tooltip" initialFocus={false} finalFocus={false}>
106
+ {label}
107
+ </Popover.Popup>
108
+ </Popover.Positioner>
101
109
  </Popover.Portal>
102
110
  </Popover.Root>
103
111
  );
104
112
  }
105
113
 
114
+ /* -------------------------------------------------------------------------- */
115
+ /* Menu */
116
+ /* -------------------------------------------------------------------------- */
117
+
118
+ /**
119
+ * A menu's floating panel, placed against its `Menu.Trigger`.
120
+ *
121
+ * The callers keep the rest of Base UI's menu parts: the trigger, the items
122
+ * and their separators read better at the call site than behind props.
123
+ */
124
+ export function MenuPopup({
125
+ side,
126
+ align,
127
+ className,
128
+ children,
129
+ }: {
130
+ side?: 'top' | 'bottom';
131
+ align: 'start' | 'end';
132
+ className?: string;
133
+ children: ReactNode;
134
+ }) {
135
+ const { portal } = usePreferences();
136
+ return (
137
+ <Menu.Portal container={portal}>
138
+ <Menu.Positioner className="menu-positioner" side={side} align={align} sideOffset={6}>
139
+ <Menu.Popup className={className === undefined ? 'menu' : `menu ${className}`}>
140
+ {children}
141
+ </Menu.Popup>
142
+ </Menu.Positioner>
143
+ </Menu.Portal>
144
+ );
145
+ }
146
+
106
147
  /* -------------------------------------------------------------------------- */
107
148
  /* Feedback primitives */
108
149
  /* -------------------------------------------------------------------------- */
@@ -265,26 +306,23 @@ type ConfirmProps = {
265
306
  };
266
307
 
267
308
  function ConfirmContent({ title, body, confirmLabel, destructive, onConfirm }: ConfirmProps) {
309
+ const { portal } = usePreferences();
268
310
  return (
269
- <AlertDialog.Portal>
270
- <AlertDialog.Overlay className="overlay" />
271
- <AlertDialog.Content className="dialog dialog-confirm">
311
+ <AlertDialog.Portal container={portal}>
312
+ <AlertDialog.Backdrop className="overlay" />
313
+ <AlertDialog.Popup className="dialog dialog-confirm">
272
314
  <AlertDialog.Title className="dialog-title">{title}</AlertDialog.Title>
273
315
  <AlertDialog.Description className="dialog-body">{body}</AlertDialog.Description>
274
316
  <div className="dialog-actions">
275
- <AlertDialog.Cancel asChild>
276
- <button className="btn">Cancel</button>
277
- </AlertDialog.Cancel>
278
- <AlertDialog.Action asChild>
279
- <button
280
- className={`btn ${destructive === false ? 'btn-primary' : 'btn-danger'}`}
281
- onClick={onConfirm}
282
- >
283
- {confirmLabel}
284
- </button>
285
- </AlertDialog.Action>
317
+ <AlertDialog.Close className="btn">Cancel</AlertDialog.Close>
318
+ <AlertDialog.Close
319
+ className={`btn ${destructive === false ? 'btn-primary' : 'btn-danger'}`}
320
+ onClick={onConfirm}
321
+ >
322
+ {confirmLabel}
323
+ </AlertDialog.Close>
286
324
  </div>
287
- </AlertDialog.Content>
325
+ </AlertDialog.Popup>
288
326
  </AlertDialog.Portal>
289
327
  );
290
328
  }
@@ -293,12 +331,10 @@ export function ConfirmButton({
293
331
  trigger,
294
332
  disabled,
295
333
  ...confirm
296
- }: ConfirmProps & { trigger: ReactNode; disabled?: boolean }) {
334
+ }: ConfirmProps & { trigger: ReactElement; disabled?: boolean }) {
297
335
  return (
298
336
  <AlertDialog.Root>
299
- <AlertDialog.Trigger asChild disabled={disabled}>
300
- {trigger}
301
- </AlertDialog.Trigger>
337
+ <AlertDialog.Trigger render={trigger} disabled={disabled} />
302
338
  <ConfirmContent {...confirm} />
303
339
  </AlertDialog.Root>
304
340
  );
@@ -344,30 +380,23 @@ export function Modal({
344
380
  wide?: boolean;
345
381
  children: ReactNode;
346
382
  }) {
383
+ const { portal } = usePreferences();
347
384
  return (
348
385
  <Dialog.Root open={open} onOpenChange={onOpenChange}>
349
- <Dialog.Portal>
350
- <Dialog.Overlay className="overlay" />
351
- <Dialog.Content
352
- className={`dialog${wide ? ' dialog-wide' : ''}`}
353
- // Radix warns when a dialog has no description. Most of these forms
354
- // are their own explanation, so opt out rather than write a
355
- // paragraph of preamble for each one.
356
- {...(description === undefined ? { 'aria-describedby': undefined } : {})}
357
- >
386
+ <Dialog.Portal container={portal}>
387
+ <Dialog.Backdrop className="overlay" />
388
+ <Dialog.Popup className={`dialog${wide ? ' dialog-wide' : ''}`}>
358
389
  <div className="dialog-head">
359
390
  <Dialog.Title className="dialog-title">{title}</Dialog.Title>
360
- <Dialog.Close asChild>
361
- <button className="btn btn-quiet btn-sm btn-icon" aria-label="Close">
362
- <X size={15} />
363
- </button>
391
+ <Dialog.Close className="btn btn-quiet btn-sm btn-icon" aria-label="Close">
392
+ <X size={15} />
364
393
  </Dialog.Close>
365
394
  </div>
366
395
  {description !== undefined && (
367
396
  <Dialog.Description className="dialog-body">{description}</Dialog.Description>
368
397
  )}
369
398
  {children}
370
- </Dialog.Content>
399
+ </Dialog.Popup>
371
400
  </Dialog.Portal>
372
401
  </Dialog.Root>
373
402
  );
package/src/index.ts ADDED
@@ -0,0 +1,29 @@
1
+ // `@coffre/ui`: coffre's pages, for a deployment's own TanStack Start app.
2
+ // Each page's and layout's route options, which the deployment's file
3
+ // routes mount (`./options.ts`); `<CoffreProvider>`, around them in its root
4
+ // document; and the router they render in. Each page's component is at
5
+ // `@coffre/ui/pages/<name>`, and the stylesheet and icons are
6
+ // `@coffre/ui/styles.css`, `icon.svg` and `apple-touch-icon.png`.
7
+ export { CoffreProvider } from './layout.tsx';
8
+ export { useCoffre } from './lib/coffre.ts';
9
+ export { createRouter } from './router.tsx';
10
+ export {
11
+ access,
12
+ account,
13
+ audit,
14
+ deviceLogin,
15
+ environment,
16
+ home,
17
+ login,
18
+ project,
19
+ projects,
20
+ settings,
21
+ shell,
22
+ solo,
23
+ token,
24
+ tokens,
25
+ unregistered,
26
+ user,
27
+ users,
28
+ type CoffreContext,
29
+ } from './options.ts';
package/src/layout.tsx ADDED
@@ -0,0 +1,113 @@
1
+ // What coffre's pages render in: the provider the deployment's document puts
2
+ // them in; the shell, coffre's nav, for signed-in pages; and the solo frame
3
+ // of the sign-in pages. The routes that render the two are in routes.ts.
4
+ import { useMemo, useRef, useState, type ReactNode } from 'react';
5
+ import { Outlet, useRouter } from '@tanstack/react-router';
6
+ import { Toaster } from 'sonner';
7
+ import { Brand, Shell } from './components/shell';
8
+ import { TooltipProvider } from './components/ui';
9
+ import { ThemeToggle } from './components/theme';
10
+ import { PreferencesContext, rememberSidebar, rememberTheme, type Preferences, type Theme } from './lib/preferences';
11
+ import type { RouterContext } from './router';
12
+ import { LiveRegion } from './components/row-state';
13
+ import { useShell } from './lib/use-shell';
14
+
15
+ function Toasts() {
16
+ return (
17
+ <Toaster
18
+ position="bottom-right"
19
+ gap={10}
20
+ offset={20}
21
+ toastOptions={{
22
+ duration: 4200,
23
+ unstyled: true,
24
+ classNames: {
25
+ toast: 'toast',
26
+ title: 'toast-title',
27
+ description: 'toast-description',
28
+ actionButton: 'toast-action',
29
+ success: 'toast-success',
30
+ error: 'toast-error',
31
+ },
32
+ }}
33
+ />
34
+ );
35
+ }
36
+
37
+ /**
38
+ * What coffre's pages need around them, for the deployment's document to put
39
+ * in its body: `<body><CoffreProvider>{children}</CoffreProvider><Scripts /></body>`.
40
+ * coffre's element, drawn in the visitor's theme, its sidebar folded or not,
41
+ * as their cookies say, from the first byte: the server and the browser
42
+ * both render it from them, so nothing waits for a script. Tooltips, toasts
43
+ * and the live region, which the deployment's own pages may use too. The
44
+ * query client comes with the router (`createRouter`).
45
+ */
46
+ export function CoffreProvider({ children }: { children: ReactNode }) {
47
+ const initial = (useRouter().options.context as RouterContext).preferences;
48
+ const [theme, setThemeState] = useState(initial.theme);
49
+ const [sidebar, setSidebarState] = useState(initial.sidebar);
50
+ const portal = useRef<HTMLDivElement>(null);
51
+ const preferences = useMemo(
52
+ () => ({
53
+ theme,
54
+ sidebar,
55
+ setTheme: (next: Theme) => {
56
+ rememberTheme(next);
57
+ setThemeState(next);
58
+ },
59
+ setSidebar: (next: Preferences['sidebar']) => {
60
+ rememberSidebar(next);
61
+ setSidebarState(next);
62
+ },
63
+ portal,
64
+ }),
65
+ [theme, sidebar],
66
+ );
67
+ return (
68
+ <PreferencesContext.Provider value={preferences}>
69
+ <div
70
+ ref={portal}
71
+ className="coffre"
72
+ data-theme={theme === 'system' ? undefined : theme}
73
+ data-sidebar={sidebar === 'collapsed' ? 'collapsed' : undefined}
74
+ >
75
+ <TooltipProvider>
76
+ {children}
77
+ <Toasts />
78
+ <LiveRegion />
79
+ </TooltipProvider>
80
+ </div>
81
+ </PreferencesContext.Provider>
82
+ );
83
+ }
84
+
85
+ /** coffre's shell: the nav, around the signed-in pages. */
86
+ export function ShellLayout() {
87
+ const { principal, instanceRole, projects, capabilities, instance } = useShell();
88
+ return (
89
+ <>
90
+ <a className="skip-link" href="#content">
91
+ Skip to content
92
+ </a>
93
+ <Shell projects={projects} principal={principal} instanceRole={instanceRole} capabilities={capabilities} instance={instance}>
94
+ <Outlet />
95
+ </Shell>
96
+ </>
97
+ );
98
+ }
99
+
100
+ /** The sign-in pages' frame: coffre's mark and the theme, nothing else. */
101
+ export function SoloLayout() {
102
+ return (
103
+ <div className="solo">
104
+ <div className="solo-top">
105
+ <Brand />
106
+ <ThemeToggle />
107
+ </div>
108
+ <main className="solo-main" id="content">
109
+ <Outlet />
110
+ </main>
111
+ </div>
112
+ );
113
+ }
package/src/lib/coffre.ts CHANGED
@@ -1,13 +1,17 @@
1
1
  import { CoffreError, type CoffreClient } from '@coffre/client';
2
2
  import { useRouter } from '@tanstack/react-router';
3
3
 
4
+ import type { CoffreContext } from '../options';
5
+
4
6
  /**
5
- * The API as whoever is looking at the page. In the browser this is plain
6
- * `fetch` to `/api`, carrying the session cookie; mutations call it straight
7
- * from event handlers, and loaders read through `context.client`.
7
+ * The API as whoever is looking at the page, with their permissions: what
8
+ * coffre's pages call, and a deployment's own may too. In the browser this
9
+ * is plain `fetch` to `/api`, carrying the session cookie; on the server,
10
+ * the API in process. Components call it from event handlers; loaders read
11
+ * the same client as `context.coffre`.
8
12
  */
9
13
  export function useCoffre(): CoffreClient {
10
- return useRouter().options.context.client;
14
+ return (useRouter().options.context as CoffreContext).coffre;
11
15
  }
12
16
 
13
17
  /** A refusal the page words itself, shown as it is. */
@@ -0,0 +1,13 @@
1
+ import { useRouter } from '@tanstack/react-router';
2
+
3
+ /**
4
+ * Whether the deployment put a page at `path`, a route's full path such as
5
+ * `/audit` or `/projects/$project`: as a route of its own, or as the index
6
+ * of one (`/projects/`), as a file route at `projects.index.tsx` is. A
7
+ * deployment may leave any of coffre's pages out: the nav and the command
8
+ * palette offer only those it kept.
9
+ */
10
+ export function useMounted(): (path: string) => boolean {
11
+ const { routesByPath } = useRouter();
12
+ return (path) => Object.hasOwn(routesByPath, path) || Object.hasOwn(routesByPath, `${path}/`);
13
+ }
@@ -0,0 +1,31 @@
1
+ import type { CoffreClient } from '@coffre/client';
2
+ import { NO_MIDDLEWARE } from '@coffre/core/pages';
3
+ import { getGlobalStartContext } from '@tanstack/react-start';
4
+
5
+ import type { Preferences } from './preferences';
6
+
7
+ /** What coffre's middleware hands each request's render (`@coffre/server/start`). */
8
+ export type PageContext = { cspNonce: string; client: CoffreClient; preferences: Preferences };
9
+
10
+ export const DEFAULT_PREFERENCES: Preferences = { theme: 'system', sidebar: 'expanded' };
11
+
12
+
13
+ /**
14
+ * On the server, the request's page context: the visitor's API client, an
15
+ * in-process call with their credential, the response's nonce and their
16
+ * preferences, which coffre's middleware hands each request. A request it
17
+ * did not pass through fails here, saying so, rather than render a page
18
+ * with neither the client nor the headers. Undefined outside a request,
19
+ * where a router is built only to resolve a redirect, and renders nothing.
20
+ */
21
+ export function requestPage(): PageContext | undefined {
22
+ let context: Partial<PageContext> | undefined;
23
+ try {
24
+ context = getGlobalStartContext() as Partial<PageContext> | undefined;
25
+ } catch {
26
+ return undefined;
27
+ }
28
+ if (context === undefined) return undefined;
29
+ if (context.client === undefined) throw new Error(NO_MIDDLEWARE);
30
+ return context as PageContext;
31
+ }
@@ -0,0 +1,22 @@
1
+ import { useLoaderData, useParams, useSearch } from '@tanstack/react-router';
2
+
3
+ /** A page's route options, as `../options.ts` has them. */
4
+ type PageOptions = { loader?: (context: never) => unknown; validateSearch?: (search: never) => unknown };
5
+
6
+ type Params<TOptions extends PageOptions> = Parameters<NonNullable<TOptions['loader']>>[0] extends { params: infer P } ? P : object;
7
+
8
+ /** Untyped, as the router gives it for a match it cannot name. */
9
+ const read = (value: unknown) => value;
10
+
11
+ /**
12
+ * What a page's component reads of its route, wherever the deployment put
13
+ * it, typed by the page's options: the match it renders in, its loader's
14
+ * data, its params and its search. `pageRoute<typeof project>()`.
15
+ */
16
+ export function pageRoute<TOptions extends PageOptions>() {
17
+ return {
18
+ useLoaderData: () => read(useLoaderData({ strict: false })) as Awaited<ReturnType<NonNullable<TOptions['loader']>>>,
19
+ useParams: () => read(useParams({ strict: false })) as Params<TOptions>,
20
+ useSearch: () => read(useSearch({ strict: false })) as ReturnType<NonNullable<TOptions['validateSearch']>>,
21
+ };
22
+ }
@@ -0,0 +1,46 @@
1
+ import { createContext, useContext, type RefObject } from 'react';
2
+
3
+ import { PREFERENCE_COOKIES, preferencesIn, type Preferences } from '@coffre/core/pages';
4
+
5
+ export type { Preferences };
6
+
7
+ export type Theme = Preferences['theme'];
8
+
9
+ /**
10
+ * The preferences in the browser's cookies, as the server read them in the
11
+ * request's: each is a cookie, so the server renders the page as the
12
+ * visitor left it, from the first byte, and the browser hydrates the same.
13
+ */
14
+ export function browserPreferences(): Preferences {
15
+ return preferencesIn(document.cookie);
16
+ }
17
+
18
+ /** Keep a choice for a year; the default, by removing it. */
19
+ function remember(name: string, value: string | null) {
20
+ document.cookie =
21
+ value === null ? `${name}=; Path=/; SameSite=Lax; Max-Age=0` : `${name}=${value}; Path=/; SameSite=Lax; Max-Age=31536000`;
22
+ }
23
+
24
+ export function rememberTheme(theme: Theme) {
25
+ remember(PREFERENCE_COOKIES.theme, theme === 'system' ? null : theme);
26
+ }
27
+
28
+ export function rememberSidebar(sidebar: Preferences['sidebar']) {
29
+ remember(PREFERENCE_COOKIES.sidebar, sidebar === 'collapsed' ? 'collapsed' : null);
30
+ }
31
+
32
+ type PreferencesValue = Preferences & {
33
+ setTheme(theme: Theme): void;
34
+ setSidebar(sidebar: Preferences['sidebar']): void;
35
+ /** coffre's element, which menus, dialogs and tooltips render into, so they are drawn in its theme. */
36
+ portal: RefObject<HTMLDivElement | null>;
37
+ };
38
+
39
+ export const PreferencesContext = createContext<PreferencesValue | null>(null);
40
+
41
+ /** The visitor's preferences, and the switches, from `<CoffreProvider>`. */
42
+ export function usePreferences(): PreferencesValue {
43
+ const value = useContext(PreferencesContext);
44
+ if (value === null) throw new Error("coffre's pages render inside <CoffreProvider>, in the app's root document");
45
+ return value;
46
+ }