@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.
- package/README.md +23 -3
- package/dist/{server/_coffre/assets/affordances-CKANXDTG.js → chunks/affordances-DAvsVz7u.js} +12 -7
- package/dist/chunks/affordances-DAvsVz7u.js.map +1 -0
- package/dist/chunks/directory-CSjWWUQ1.js +370 -0
- package/dist/chunks/directory-CSjWWUQ1.js.map +1 -0
- package/dist/{server/_coffre/assets/grants-DdKT11Ny.js → chunks/grants-saMQagmG.js} +41 -39
- package/dist/chunks/grants-saMQagmG.js.map +1 -0
- package/dist/chunks/icons-D-PfAfnH.js +203 -0
- package/dist/chunks/icons-D-PfAfnH.js.map +1 -0
- package/dist/chunks/mounted-jJmqqV_n.js +17 -0
- package/dist/chunks/mounted-jJmqqV_n.js.map +1 -0
- package/dist/{server/_coffre/assets/offboarding-CRz-K82H.js → chunks/offboarding-C6l30DZR.js} +70 -69
- package/dist/chunks/offboarding-C6l30DZR.js.map +1 -0
- package/dist/chunks/page-C5HcNqf2.js +190 -0
- package/dist/chunks/page-C5HcNqf2.js.map +1 -0
- package/dist/chunks/page-route-Drfw7lmn.js +20 -0
- package/dist/chunks/page-route-Drfw7lmn.js.map +1 -0
- package/dist/{server/_coffre/assets/principal-page-C-EFwJQw.js → chunks/principal-page-D_91OA0l.js} +105 -103
- package/dist/chunks/principal-page-D_91OA0l.js.map +1 -0
- package/dist/{server/_coffre/assets → chunks}/project-environments-lEzFHUt4.js +2 -0
- package/dist/chunks/project-environments-lEzFHUt4.js.map +1 -0
- package/dist/chunks/queries-CQ81o4so.js +376 -0
- package/dist/chunks/queries-CQ81o4so.js.map +1 -0
- package/dist/{server/_coffre/assets/row-state-C2P57xT1.js → chunks/row-state-0PsrEzOL.js} +22 -21
- package/dist/chunks/row-state-0PsrEzOL.js.map +1 -0
- package/dist/{server/_coffre/assets → chunks}/signin-errors-BEFlVDbQ.js +2 -0
- package/dist/chunks/signin-errors-BEFlVDbQ.js.map +1 -0
- package/dist/chunks/theme-B2vQolVR.js +86 -0
- package/dist/chunks/theme-B2vQolVR.js.map +1 -0
- package/dist/chunks/ui-DixXLQvQ.js +405 -0
- package/dist/chunks/ui-DixXLQvQ.js.map +1 -0
- package/dist/{server/_coffre/assets/use-action-B-xpvVRO.js → chunks/use-action-CWsg_YWU.js} +8 -6
- package/dist/chunks/use-action-CWsg_YWU.js.map +1 -0
- package/dist/{server/_coffre/assets/use-change-C8BCf3oU.js → chunks/use-change-c6CeLRin.js} +10 -474
- package/dist/chunks/use-change-c6CeLRin.js.map +1 -0
- package/dist/chunks/use-shell-jxd7Tzd-.js +26 -0
- package/dist/chunks/use-shell-jxd7Tzd-.js.map +1 -0
- package/dist/{server/_coffre/assets → chunks}/validation-BQtqPe2V.js +2 -0
- package/dist/chunks/validation-BQtqPe2V.js.map +1 -0
- package/dist/index.d.ts +386 -18
- package/dist/index.js +1147 -0
- package/dist/index.js.map +1 -0
- package/dist/pages/account.d.ts +9 -0
- package/dist/pages/account.js +334 -0
- package/dist/pages/account.js.map +1 -0
- package/dist/pages/audit.d.ts +3 -0
- package/dist/{server/_coffre/assets/audit-qB9G2AQJ.js → pages/audit.js} +102 -100
- package/dist/pages/audit.js.map +1 -0
- package/dist/pages/device-login.d.ts +9 -0
- package/dist/pages/device-login.js +211 -0
- package/dist/pages/device-login.js.map +1 -0
- package/dist/pages/environment.d.ts +3 -0
- package/dist/{server/_coffre/assets/projects._project._environment-C6uybzeU.js → pages/environment.js} +323 -469
- package/dist/pages/environment.js.map +1 -0
- package/dist/pages/login.d.ts +10 -0
- package/dist/pages/login.js +104 -0
- package/dist/pages/login.js.map +1 -0
- package/dist/pages/project.d.ts +2 -0
- package/dist/{server/_coffre/assets/projects._project.index-3CXwkyTh.js → pages/project.js} +223 -225
- package/dist/pages/project.js.map +1 -0
- package/dist/pages/projects.d.ts +3 -0
- package/dist/{server/_coffre/assets/projects.index-iSoBpRFz.js → pages/projects.js} +83 -81
- package/dist/pages/projects.js.map +1 -0
- package/dist/pages/settings.d.ts +3 -0
- package/dist/{server/_coffre/assets/settings-BDQTF5XW.js → pages/settings.js} +20 -18
- package/dist/pages/settings.js.map +1 -0
- package/dist/pages/token.d.ts +3 -0
- package/dist/{server/_coffre/assets/tokens._token-CrBMpcbN.js → pages/token.js} +195 -265
- package/dist/pages/token.js.map +1 -0
- package/dist/pages/tokens.d.ts +3 -0
- package/dist/pages/tokens.js +39 -0
- package/dist/pages/tokens.js.map +1 -0
- package/dist/pages/unregistered.d.ts +8 -0
- package/dist/pages/unregistered.js +54 -0
- package/dist/pages/unregistered.js.map +1 -0
- package/dist/pages/user.d.ts +3 -0
- package/dist/pages/user.js +16 -0
- package/dist/pages/user.js.map +1 -0
- package/dist/pages/users.d.ts +3 -0
- package/dist/pages/users.js +39 -0
- package/dist/pages/users.js.map +1 -0
- package/dist/project-BqIy8gYR.d.ts +5 -0
- package/dist/vite.d.ts +16 -0
- package/dist/vite.js +52 -0
- package/package.json +36 -21
- package/src/assets/icon.svg +1 -0
- package/src/components/affordances.ts +10 -4
- package/src/components/command-palette.tsx +229 -203
- package/src/components/directory.tsx +34 -38
- package/src/components/principal.tsx +7 -3
- package/src/components/shell.tsx +89 -127
- package/src/components/theme.tsx +14 -81
- package/src/components/ui.tsx +97 -68
- package/src/index.ts +29 -0
- package/src/layout.tsx +113 -0
- package/src/lib/coffre.ts +8 -4
- package/src/lib/mounted.ts +13 -0
- package/src/lib/page-context.ts +31 -0
- package/src/lib/page-route.ts +22 -0
- package/src/lib/preferences.tsx +46 -0
- package/src/options.ts +240 -0
- package/src/{routes → pages}/account.tsx +7 -24
- package/src/{routes → pages}/audit.tsx +5 -16
- package/src/{routes/auth.device.tsx → pages/device-login.tsx} +8 -21
- package/src/{routes/projects.$project.$environment.tsx → pages/environment.tsx} +43 -52
- package/src/{routes → pages}/login.tsx +5 -16
- package/src/{routes/projects.$project.index.tsx → pages/project.tsx} +38 -50
- package/src/{routes/projects.index.tsx → pages/projects.tsx} +2 -7
- package/src/{routes → pages}/settings.tsx +3 -10
- package/src/{routes/tokens.$token.tsx → pages/token.tsx} +6 -7
- package/src/{routes/tokens.index.tsx → pages/tokens.tsx} +3 -8
- package/src/{routes → pages}/unregistered.tsx +1 -6
- package/src/pages/user.tsx +10 -0
- package/src/{routes/users.index.tsx → pages/users.tsx} +3 -8
- package/src/register.ts +55 -0
- package/src/router.tsx +31 -62
- package/src/styles/globals.css +104 -46
- package/src/vite.ts +78 -0
- package/dist/client/.assetsignore +0 -2
- package/dist/client/_coffre/assets/account-BoLGAxbD.js +0 -2
- package/dist/client/_coffre/assets/account-CnnuRTDB.js +0 -1
- package/dist/client/_coffre/assets/affordances-CEafRJcN.js +0 -1
- package/dist/client/_coffre/assets/audit-CHSvKLWX.js +0 -1
- package/dist/client/_coffre/assets/audit-Cn4hmS4u.js +0 -2
- package/dist/client/_coffre/assets/auth.device-Co5vrpaA.js +0 -2
- package/dist/client/_coffre/assets/auth.device-DAlqWacc.js +0 -1
- package/dist/client/_coffre/assets/directory-H8Eh3MnS.js +0 -1
- package/dist/client/_coffre/assets/dist-Braunv_x.js +0 -1
- package/dist/client/_coffre/assets/globals-CpMrgkV6.css +0 -1
- package/dist/client/_coffre/assets/grants-DPDxJXU1.js +0 -1
- package/dist/client/_coffre/assets/icons-Dc_-t0lp.js +0 -1
- package/dist/client/_coffre/assets/index-sUCIXRgJ.js +0 -12
- package/dist/client/_coffre/assets/inter-cyrillic-ext-opsz-normal-CfYZpDVp.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-cyrillic-opsz-normal-BFQXbQ-f.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-greek-ext-opsz-normal-BmPQvyvo.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-greek-opsz-normal-BM0NlUE_.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-latin-ext-opsz-normal-DpK-iCPk.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-latin-opsz-normal-BwkfbSeq.woff2 +0 -0
- package/dist/client/_coffre/assets/inter-vietnamese-opsz-normal-Ci9T9ieq.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-cyrillic-ext-wght-normal-EocZY2iu.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
- package/dist/client/_coffre/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
- package/dist/client/_coffre/assets/link-DBINMwm6.js +0 -1
- package/dist/client/_coffre/assets/login-BZFYfL1Y.js +0 -1
- package/dist/client/_coffre/assets/login-CYCKWTOD.js +0 -2
- package/dist/client/_coffre/assets/offboarding-Bwpftp3g.js +0 -1
- package/dist/client/_coffre/assets/page-C_hnzdaR.js +0 -1
- package/dist/client/_coffre/assets/preload-helper-CLkO85Nq.js +0 -1
- package/dist/client/_coffre/assets/principal-page-DLho8TSJ.js +0 -1
- package/dist/client/_coffre/assets/project-environments-CfIH5kFM.js +0 -1
- package/dist/client/_coffre/assets/projects._project._environment-DHRRvQw0.js +0 -3
- package/dist/client/_coffre/assets/projects._project._environment-TLI-RjBZ.js +0 -2
- package/dist/client/_coffre/assets/projects._project.index-BO-8FZIY.js +0 -2
- package/dist/client/_coffre/assets/projects._project.index-DGl921dP.js +0 -1
- package/dist/client/_coffre/assets/projects.index-BDn7Bhoo.js +0 -1
- package/dist/client/_coffre/assets/row-state-DJ-KLamZ.js +0 -1
- package/dist/client/_coffre/assets/settings-q9G1QvR_.js +0 -1
- package/dist/client/_coffre/assets/signin-errors-CroZWZgm.js +0 -1
- package/dist/client/_coffre/assets/suspense-O8sP0mEC.js +0 -1
- package/dist/client/_coffre/assets/tokens._token-B_qczpT9.js +0 -2
- package/dist/client/_coffre/assets/tokens._token-T-sqwMbz.js +0 -2
- package/dist/client/_coffre/assets/tokens.index-CcXSZnAG.js +0 -1
- package/dist/client/_coffre/assets/ui-BXP2IqrW.js +0 -46
- package/dist/client/_coffre/assets/unregistered-D2JXJ90x.js +0 -1
- package/dist/client/_coffre/assets/use-action-BpzKWhgg.js +0 -1
- package/dist/client/_coffre/assets/use-change-CKj3Inq9.js +0 -1
- package/dist/client/_coffre/assets/use-shell-W0SusPkz.js +0 -1
- package/dist/client/_coffre/assets/useQuery-B-lxFSES.js +0 -1
- package/dist/client/_coffre/assets/useSuspenseQuery-BZ-nzHST.js +0 -1
- package/dist/client/_coffre/assets/users._user-Bb3BGYHl.js +0 -1
- package/dist/client/_coffre/assets/users._user-DXmvKrzE.js +0 -2
- package/dist/client/_coffre/assets/users.index-BvzP3qwW.js +0 -1
- package/dist/client/_coffre/assets/validation-9Cl_XS-l.js +0 -1
- package/dist/server/.vite/manifest.json +0 -668
- package/dist/server/_coffre/assets/_tanstack-start-manifest_v-GsKnGGRy.js +0 -162
- package/dist/server/_coffre/assets/account-CV-a2IU2.js +0 -329
- package/dist/server/_coffre/assets/account-hk6wcIXU.js +0 -162
- package/dist/server/_coffre/assets/async-local-storage-C10uQtMM.js +0 -3108
- package/dist/server/_coffre/assets/audit-C1_Ej6YB.js +0 -31
- package/dist/server/_coffre/assets/auth.device-6JRrWbSV.js +0 -210
- package/dist/server/_coffre/assets/auth.device-CLoAxC2T.js +0 -29
- package/dist/server/_coffre/assets/directory-B-_rqsPx.js +0 -371
- package/dist/server/_coffre/assets/dist-CnnV3t2g.js +0 -908
- package/dist/server/_coffre/assets/empty-plugin-adapters-Cq4--YW-.js +0 -5
- package/dist/server/_coffre/assets/globals-CpMrgkV6.css +0 -1
- package/dist/server/_coffre/assets/icons-DOFT-eWB.js +0 -1704
- package/dist/server/_coffre/assets/inter-cyrillic-ext-opsz-normal-CfYZpDVp.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-cyrillic-opsz-normal-BFQXbQ-f.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-greek-ext-opsz-normal-BmPQvyvo.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-greek-opsz-normal-BM0NlUE_.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-latin-ext-opsz-normal-DpK-iCPk.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-latin-opsz-normal-BwkfbSeq.woff2 +0 -0
- package/dist/server/_coffre/assets/inter-vietnamese-opsz-normal-Ci9T9ieq.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-cyrillic-ext-wght-normal-EocZY2iu.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
- package/dist/server/_coffre/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
- package/dist/server/_coffre/assets/lazyRouteComponent-CqBNCGuZ.js +0 -480
- package/dist/server/_coffre/assets/link-42ZWdjzZ.js +0 -422
- package/dist/server/_coffre/assets/login-DRKUKkaW.js +0 -22
- package/dist/server/_coffre/assets/login-DnwxVl4Y.js +0 -102
- package/dist/server/_coffre/assets/matchContext-qLfYbC6_.js +0 -56
- package/dist/server/_coffre/assets/page-D6n45dcK.js +0 -3561
- package/dist/server/_coffre/assets/projects._project._environment-CS8DdSMY.js +0 -48
- package/dist/server/_coffre/assets/projects._project.index-BGfcNpj0.js +0 -23
- package/dist/server/_coffre/assets/react-dom-bBoJXlK2.js +0 -1718
- package/dist/server/_coffre/assets/router-9BTgJhWG.js +0 -2322
- package/dist/server/_coffre/assets/start-DR3rN0St.js +0 -4
- package/dist/server/_coffre/assets/suspense-C-2QfDd2.js +0 -602
- package/dist/server/_coffre/assets/tokens._token-rY86Cjgp.js +0 -10
- package/dist/server/_coffre/assets/tokens.index-Bq5qDW9q.js +0 -37
- package/dist/server/_coffre/assets/ui-Cc0CGMtr.js +0 -14881
- package/dist/server/_coffre/assets/unregistered-D9ZKLOPJ.js +0 -53
- package/dist/server/_coffre/assets/use-shell-DwOzEi87.js +0 -462
- package/dist/server/_coffre/assets/useQuery-CTe86qFq.js +0 -8
- package/dist/server/_coffre/assets/useRouter-CaUSUNsw.js +0 -473
- package/dist/server/_coffre/assets/useSuspenseQuery-CSoHzrMb.js +0 -117
- package/dist/server/_coffre/assets/users._user-BmLKYeo_.js +0 -10
- package/dist/server/_coffre/assets/users._user-BmiHwQx3.js +0 -14
- package/dist/server/_coffre/assets/users.index-BiEax90r.js +0 -37
- package/dist/server/index.js +0 -13911
- package/src/assets/favicon-32.png +0 -0
- package/src/components/agentation.tsx +0 -34
- package/src/entry.ts +0 -19
- package/src/routeTree.gen.ts +0 -367
- package/src/routes/__root.tsx +0 -169
- package/src/routes/access.tsx +0 -11
- package/src/routes/index.tsx +0 -15
- package/src/routes/users.$user.tsx +0 -13
- package/src/types.ts +0 -21
package/src/components/ui.tsx
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
|
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:
|
|
32
|
+
children: ReactElement;
|
|
35
33
|
}) {
|
|
34
|
+
const { portal } = usePreferences();
|
|
36
35
|
return (
|
|
37
36
|
<Tooltip.Root>
|
|
38
|
-
<Tooltip.Trigger
|
|
39
|
-
<Tooltip.Portal>
|
|
40
|
-
<Tooltip.
|
|
41
|
-
|
|
42
|
-
|
|
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:
|
|
70
|
+
children: ReactElement;
|
|
67
71
|
}) {
|
|
72
|
+
const { portal } = usePreferences();
|
|
68
73
|
const [open, setOpen] = useState(false);
|
|
69
|
-
const
|
|
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
|
|
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
|
-
|
|
89
|
+
render={children}
|
|
78
90
|
onPointerEnter={hover(true)}
|
|
79
91
|
onPointerLeave={hover(false)}
|
|
80
|
-
onPointerDown={(event
|
|
81
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
{
|
|
100
|
-
|
|
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.
|
|
271
|
-
<AlertDialog.
|
|
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.
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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.
|
|
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:
|
|
334
|
+
}: ConfirmProps & { trigger: ReactElement; disabled?: boolean }) {
|
|
297
335
|
return (
|
|
298
336
|
<AlertDialog.Root>
|
|
299
|
-
<AlertDialog.Trigger
|
|
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.
|
|
351
|
-
<Dialog.
|
|
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
|
|
361
|
-
<
|
|
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.
|
|
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
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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.
|
|
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
|
+
}
|