@coffre/ui 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +8 -2
- package/dist/client/.assetsignore +2 -0
- package/dist/client/_coffre/assets/account-C3Zo1l5A.js +1 -0
- package/dist/client/_coffre/assets/account-C4bNbeO7.js +2 -0
- package/dist/client/_coffre/assets/affordances-DiuJIiR2.js +1 -0
- package/dist/client/_coffre/assets/audit-1xLyuxGz.js +2 -0
- package/dist/client/_coffre/assets/audit-Dab2GuRj.js +1 -0
- package/dist/client/_coffre/assets/auth.device-BfCfeBWe.js +2 -0
- package/dist/client/_coffre/assets/auth.device-D2pCLF-X.js +1 -0
- package/dist/client/_coffre/assets/coffre-C7qL3HGR.js +1 -0
- package/dist/client/_coffre/assets/directory-C2Ou4SQv.js +1 -0
- package/dist/client/_coffre/assets/globals-Dgq4Jy0x.css +1 -0
- package/dist/client/_coffre/assets/grants-fqTtJ-aW.js +1 -0
- package/dist/client/_coffre/assets/index-BpGwbjmM.js +12 -0
- 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/login-CR9CBXlw.js +2 -0
- package/dist/client/_coffre/assets/login-DZizFxa4.js +1 -0
- package/dist/client/_coffre/assets/offboarding-DOLJQcXU.js +1 -0
- package/dist/client/_coffre/assets/page-BxW2MwaX.js +1 -0
- package/dist/client/_coffre/assets/preload-helper-BHuP8_FL.js +46 -0
- package/dist/client/_coffre/assets/principal-page-xnBZVURr.js +1 -0
- package/dist/client/_coffre/assets/project-environments-CfIH5kFM.js +1 -0
- package/dist/client/_coffre/assets/projects._project._environment-CrWjQmIA.js +2 -0
- package/dist/client/_coffre/assets/projects._project._environment-CwRVG9Ne.js +3 -0
- package/dist/client/_coffre/assets/projects._project.index-CCDEuE-z.js +2 -0
- package/dist/client/_coffre/assets/projects._project.index-DCJsmnD7.js +1 -0
- package/dist/client/_coffre/assets/projects.index-B8eV8JIn.js +1 -0
- package/dist/client/_coffre/assets/projects.index-BNEC7Oz8.js +2 -0
- package/dist/client/_coffre/assets/settings-2BPsenNM.js +2 -0
- package/dist/client/_coffre/assets/settings-BrS0-wEt.js +1 -0
- package/dist/client/_coffre/assets/signin-errors-CroZWZgm.js +1 -0
- package/dist/client/_coffre/assets/tokens._token-B3-YwuKp.js +2 -0
- package/dist/client/_coffre/assets/tokens._token-D_hsbHx6.js +1 -0
- package/dist/client/_coffre/assets/tokens.index-BdKE2Jv8.js +2 -0
- package/dist/client/_coffre/assets/tokens.index-XvA4XRxh.js +1 -0
- package/dist/client/_coffre/assets/unregistered-CTRMtBIy.js +1 -0
- package/dist/client/_coffre/assets/use-action-DgAf-tiX.js +1 -0
- package/dist/client/_coffre/assets/users._user-BFPXcJ4y.js +2 -0
- package/dist/client/_coffre/assets/users._user-DEtMeSoh.js +1 -0
- package/dist/client/_coffre/assets/users.index-B03beUHq.js +1 -0
- package/dist/client/_coffre/assets/users.index-D8hwzM6P.js +2 -0
- package/dist/client/_coffre/assets/validation-9Cl_XS-l.js +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/server/.vite/manifest.json +572 -0
- package/dist/server/_coffre/assets/_tanstack-start-manifest_v-B6CZDfrB.js +133 -0
- package/dist/server/_coffre/assets/account-B71_b5xc.js +296 -0
- package/dist/server/_coffre/assets/account-BoO6ZqMc.js +176 -0
- package/dist/server/_coffre/assets/affordances-BNaXjMOb.js +46 -0
- package/dist/server/_coffre/assets/async-local-storage-C0cwgkEr.js +3107 -0
- package/dist/server/_coffre/assets/audit-CwRFnSAY.js +74 -0
- package/dist/server/_coffre/assets/audit-t1sYjtrf.js +964 -0
- package/dist/server/_coffre/assets/auth.device-1IcJ475s.js +208 -0
- package/dist/server/_coffre/assets/auth.device-CJwZYYtn.js +29 -0
- package/dist/server/_coffre/assets/coffre-1hxT2E_U.js +278 -0
- package/dist/server/_coffre/assets/directory-wm_JQUfk.js +396 -0
- package/dist/server/_coffre/assets/empty-plugin-adapters-Cq4--YW-.js +5 -0
- package/dist/server/_coffre/assets/globals-Dgq4Jy0x.css +1 -0
- package/dist/server/_coffre/assets/grants-BmhEY1vz.js +243 -0
- 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/login-B5O5LPXV.js +100 -0
- package/dist/server/_coffre/assets/login-Bvc4gp0X.js +22 -0
- package/dist/server/_coffre/assets/offboarding-CvSilnSm.js +330 -0
- package/dist/server/_coffre/assets/page-BjXk0Ehu.js +2003 -0
- package/dist/server/_coffre/assets/principal-page-DkwNGzM2.js +617 -0
- package/dist/server/_coffre/assets/project-environments-lEzFHUt4.js +9 -0
- package/dist/server/_coffre/assets/projects._project._environment-7grhqlgq.js +2227 -0
- package/dist/server/_coffre/assets/projects._project._environment-ByEf6pmz.js +55 -0
- package/dist/server/_coffre/assets/projects._project.index-B1bjowP-.js +932 -0
- package/dist/server/_coffre/assets/projects._project.index-DU8wtoHD.js +22 -0
- package/dist/server/_coffre/assets/projects.index-B0DoHbCz.js +280 -0
- package/dist/server/_coffre/assets/projects.index-kMDA6pMy.js +54 -0
- package/dist/server/_coffre/assets/react-dom-qCTiwGGR.js +1352 -0
- package/dist/server/_coffre/assets/router-ChU_CwCX.js +2028 -0
- package/dist/server/_coffre/assets/settings-CM9-h7in.js +18 -0
- package/dist/server/_coffre/assets/settings-Cg5qOGij.js +60 -0
- package/dist/server/_coffre/assets/signin-errors-BEFlVDbQ.js +28 -0
- package/dist/server/_coffre/assets/start-DR3rN0St.js +4 -0
- package/dist/server/_coffre/assets/tokens._token-CCpaPMAk.js +268 -0
- package/dist/server/_coffre/assets/tokens._token-Di4OZdAA.js +18 -0
- package/dist/server/_coffre/assets/tokens.index-Do3OHR31.js +34 -0
- package/dist/server/_coffre/assets/tokens.index-tDKq4AFh.js +10 -0
- package/dist/server/_coffre/assets/ui-BNzhIAQP.js +15710 -0
- package/dist/server/_coffre/assets/unregistered-BqaWYFJK.js +51 -0
- package/dist/server/_coffre/assets/use-action-BkJXC5JM.js +953 -0
- package/dist/server/_coffre/assets/useStore-DWGPqzXR.js +892 -0
- package/dist/server/_coffre/assets/users._user-BenYva93.js +15 -0
- package/dist/server/_coffre/assets/users._user-Cp039Va-.js +10 -0
- package/dist/server/_coffre/assets/users.index-BrzG1Ecq.js +10 -0
- package/dist/server/_coffre/assets/users.index-DQ_45DQl.js +34 -0
- package/dist/server/_coffre/assets/validation-BQtqPe2V.js +27 -0
- package/dist/server/index.js +13910 -0
- package/package.json +58 -3
- package/src/components/affordances.ts +80 -0
- package/src/components/agentation.tsx +34 -0
- package/src/components/command-palette.tsx +271 -0
- package/src/components/directory.tsx +448 -0
- package/src/components/grants.tsx +204 -0
- package/src/components/icons.tsx +283 -0
- package/src/components/offboarding.tsx +286 -0
- package/src/components/page.tsx +128 -0
- package/src/components/principal-page.tsx +549 -0
- package/src/components/principal-picker.tsx +168 -0
- package/src/components/principal.tsx +53 -0
- package/src/components/route-states.tsx +60 -0
- package/src/components/service-tokens.tsx +212 -0
- package/src/components/shell.tsx +641 -0
- package/src/components/syncs.tsx +581 -0
- package/src/components/theme.tsx +141 -0
- package/src/components/tile.tsx +22 -0
- package/src/components/ui.tsx +440 -0
- package/src/entry.ts +19 -0
- package/src/lib/access-plan.ts +201 -0
- package/src/lib/audit-sentences.ts +468 -0
- package/src/lib/capabilities.ts +45 -0
- package/src/lib/coffre.ts +57 -0
- package/src/lib/project-access.ts +95 -0
- package/src/lib/project-environments.ts +23 -0
- package/src/lib/reveal.ts +21 -0
- package/src/lib/secret-edit-batch.ts +181 -0
- package/src/lib/signin-errors.ts +33 -0
- package/src/lib/use-action.ts +50 -0
- package/src/lib/validation.ts +27 -0
- package/src/routeTree.gen.ts +367 -0
- package/src/router.tsx +84 -0
- package/src/routes/__root.tsx +192 -0
- package/src/routes/access.tsx +11 -0
- package/src/routes/account.tsx +359 -0
- package/src/routes/audit.tsx +545 -0
- package/src/routes/auth.device.tsx +200 -0
- package/src/routes/index.tsx +15 -0
- package/src/routes/login.tsx +129 -0
- package/src/routes/projects.$project.$environment.tsx +1659 -0
- package/src/routes/projects.$project.index.tsx +917 -0
- package/src/routes/projects.index.tsx +353 -0
- package/src/routes/settings.tsx +72 -0
- package/src/routes/tokens.$token.tsx +35 -0
- package/src/routes/tokens.index.tsx +37 -0
- package/src/routes/unregistered.tsx +59 -0
- package/src/routes/users.$user.tsx +13 -0
- package/src/routes/users.index.tsx +37 -0
- package/src/shared/models.ts +55 -0
- package/src/styles/globals.css +4118 -0
- package/src/types.ts +21 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { DropdownMenu } from 'radix-ui';
|
|
3
|
+
import { Check, Monitor, Moon, Sun } from './icons';
|
|
4
|
+
|
|
5
|
+
export type Theme = 'system' | 'light' | 'dark';
|
|
6
|
+
|
|
7
|
+
const STORAGE_KEY = 'coffre-theme';
|
|
8
|
+
const CHANGE_EVENT = 'coffre-theme-change';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Applied before first paint, inlined in <head>.
|
|
12
|
+
*
|
|
13
|
+
* Without this the page renders in the system palette and then snaps to the
|
|
14
|
+
* stored choice once React hydrates -- a full-screen flash on every load for
|
|
15
|
+
* anyone who overrode it. Kept as a string so it runs synchronously; there is
|
|
16
|
+
* no way to do this correctly from a component.
|
|
17
|
+
*/
|
|
18
|
+
export const themeBootScript = `(function(){try{var t=localStorage.getItem(${JSON.stringify(
|
|
19
|
+
STORAGE_KEY,
|
|
20
|
+
)});if(t==="light"||t==="dark"){document.documentElement.setAttribute("data-theme",t)}}catch(e){}})()`;
|
|
21
|
+
|
|
22
|
+
function stored(): Theme {
|
|
23
|
+
try {
|
|
24
|
+
const value = localStorage.getItem(STORAGE_KEY);
|
|
25
|
+
return value === 'light' || value === 'dark' ? value : 'system';
|
|
26
|
+
} catch {
|
|
27
|
+
return 'system';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function apply(theme: Theme) {
|
|
32
|
+
const root = document.documentElement;
|
|
33
|
+
try {
|
|
34
|
+
if (theme === 'system') localStorage.removeItem(STORAGE_KEY);
|
|
35
|
+
else localStorage.setItem(STORAGE_KEY, theme);
|
|
36
|
+
} catch {
|
|
37
|
+
// Storage refused (private mode); the choice still holds for this page.
|
|
38
|
+
}
|
|
39
|
+
if (theme === 'system') root.removeAttribute('data-theme');
|
|
40
|
+
else root.setAttribute('data-theme', theme);
|
|
41
|
+
window.dispatchEvent(new CustomEvent(CHANGE_EVENT));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const OPTIONS: { value: Theme; label: string; Icon: typeof Sun }[] = [
|
|
45
|
+
{ value: 'system', label: 'Match system', Icon: Monitor },
|
|
46
|
+
{ value: 'light', label: 'Light', Icon: Sun },
|
|
47
|
+
{ value: 'dark', label: 'Dark', Icon: Moon },
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The stored choice, kept in step with changes made elsewhere (the command
|
|
52
|
+
* palette, another tab).
|
|
53
|
+
*
|
|
54
|
+
* Server-rendered markup cannot know the stored preference, so it starts on
|
|
55
|
+
* "system" and corrects itself on mount. Any other approach hydration-mismatches.
|
|
56
|
+
*/
|
|
57
|
+
function useTheme(): Theme {
|
|
58
|
+
const [theme, setThemeState] = useState<Theme>('system');
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
const sync = () => setThemeState(stored());
|
|
62
|
+
sync();
|
|
63
|
+
window.addEventListener(CHANGE_EVENT, sync);
|
|
64
|
+
window.addEventListener('storage', sync);
|
|
65
|
+
return () => {
|
|
66
|
+
window.removeEventListener(CHANGE_EVENT, sync);
|
|
67
|
+
window.removeEventListener('storage', sync);
|
|
68
|
+
};
|
|
69
|
+
}, []);
|
|
70
|
+
|
|
71
|
+
return theme;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The theme as a radio group inside a dropdown menu (the account menu). */
|
|
75
|
+
export function ThemeMenuItems() {
|
|
76
|
+
const theme = useTheme();
|
|
77
|
+
return (
|
|
78
|
+
<DropdownMenu.RadioGroup value={theme} onValueChange={(value: string) => apply(value as Theme)}>
|
|
79
|
+
{OPTIONS.map(({ value, label, Icon }) => (
|
|
80
|
+
<DropdownMenu.RadioItem key={value} value={value} className="menu-item">
|
|
81
|
+
<Icon size={15} />
|
|
82
|
+
{label}
|
|
83
|
+
<DropdownMenu.ItemIndicator className="menu-check">
|
|
84
|
+
<Check size={14} />
|
|
85
|
+
</DropdownMenu.ItemIndicator>
|
|
86
|
+
</DropdownMenu.RadioItem>
|
|
87
|
+
))}
|
|
88
|
+
</DropdownMenu.RadioGroup>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Three glyphs, one of them pressed, for pages without the account menu.
|
|
94
|
+
* A menu for a three-way choice costs a click to find out the current value.
|
|
95
|
+
*/
|
|
96
|
+
export function ThemeToggle() {
|
|
97
|
+
const theme = useTheme();
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<div className="theme-choice" role="group" aria-label="Colour scheme">
|
|
101
|
+
{OPTIONS.map(({ value, label, Icon }) => (
|
|
102
|
+
<button
|
|
103
|
+
key={value}
|
|
104
|
+
type="button"
|
|
105
|
+
aria-pressed={theme === value}
|
|
106
|
+
aria-label={label}
|
|
107
|
+
title={label}
|
|
108
|
+
onClick={() => apply(value)}
|
|
109
|
+
>
|
|
110
|
+
<Icon size={14} />
|
|
111
|
+
</button>
|
|
112
|
+
))}
|
|
113
|
+
</div>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Imperative theme setter, so the command palette can offer the same options. */
|
|
118
|
+
export function setTheme(theme: Theme) {
|
|
119
|
+
apply(theme);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** The theme as three large choices, for the Settings page. */
|
|
123
|
+
export function ThemeCards() {
|
|
124
|
+
const theme = useTheme();
|
|
125
|
+
return (
|
|
126
|
+
<div className="choice-grid" role="group" aria-label="Colour scheme">
|
|
127
|
+
{OPTIONS.map(({ value, label, Icon }) => (
|
|
128
|
+
<button
|
|
129
|
+
key={value}
|
|
130
|
+
type="button"
|
|
131
|
+
className="choice"
|
|
132
|
+
aria-pressed={theme === value}
|
|
133
|
+
onClick={() => apply(value)}
|
|
134
|
+
>
|
|
135
|
+
<Icon size={16} />
|
|
136
|
+
{label}
|
|
137
|
+
</button>
|
|
138
|
+
))}
|
|
139
|
+
</div>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const HUES = ['blue', 'green', 'amber', 'violet'] as const;
|
|
2
|
+
|
|
3
|
+
/** The same name always lands on the same tint, on every screen (FNV-1a). */
|
|
4
|
+
export function tileHue(name: string): (typeof HUES)[number] {
|
|
5
|
+
let hash = 0x811c9dc5;
|
|
6
|
+
for (const char of name) hash = Math.imul(hash ^ char.charCodeAt(0), 0x01000193) >>> 0;
|
|
7
|
+
return HUES[hash % HUES.length];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A letter on a tint, standing in for a project wherever its name appears.
|
|
12
|
+
*
|
|
13
|
+
* It is a recognition aid, not information: the name is always beside it, so
|
|
14
|
+
* the tile is hidden from assistive technology.
|
|
15
|
+
*/
|
|
16
|
+
export function Tile({ name, size = 'sm' }: { name: string; size?: 'sm' | 'lg' }) {
|
|
17
|
+
return (
|
|
18
|
+
<span className={`tile tile-${tileHue(name)}${size === 'lg' ? ' tile-lg' : ''}`} aria-hidden>
|
|
19
|
+
{name.slice(0, 1)}
|
|
20
|
+
</span>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,440 @@
|
|
|
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';
|
|
10
|
+
import { AlertCircle, AlertTriangle, Check, Copy, Info, Loader, X } from './icons';
|
|
11
|
+
|
|
12
|
+
/* -------------------------------------------------------------------------- */
|
|
13
|
+
/* Tooltip */
|
|
14
|
+
/* -------------------------------------------------------------------------- */
|
|
15
|
+
|
|
16
|
+
export function TooltipProvider({ children }: { children: ReactNode }) {
|
|
17
|
+
// 400ms before the first tip; afterwards adjacent tips open instantly, which
|
|
18
|
+
// makes a row of controls feel immediate without the delay losing its
|
|
19
|
+
// purpose (preventing accidental activation on a passing cursor).
|
|
20
|
+
return (
|
|
21
|
+
<Tooltip.Provider delayDuration={400} skipDelayDuration={300}>
|
|
22
|
+
{children}
|
|
23
|
+
</Tooltip.Provider>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function Tip({
|
|
28
|
+
label,
|
|
29
|
+
side,
|
|
30
|
+
children,
|
|
31
|
+
}: {
|
|
32
|
+
label: ReactNode;
|
|
33
|
+
side?: 'top' | 'right' | 'bottom' | 'left';
|
|
34
|
+
children: ReactNode;
|
|
35
|
+
}) {
|
|
36
|
+
return (
|
|
37
|
+
<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>
|
|
43
|
+
</Tooltip.Portal>
|
|
44
|
+
</Tooltip.Root>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The same bubble as Tip, for a note a touch screen must reach too.
|
|
50
|
+
*
|
|
51
|
+
* A tooltip opens on hover and focus only, so on a phone it never opens. This
|
|
52
|
+
* one also opens on a tap, which means its trigger has to be a real button.
|
|
53
|
+
* With a mouse, hover alone drives it: a click would otherwise close the note
|
|
54
|
+
* the hover just opened.
|
|
55
|
+
*/
|
|
56
|
+
export function Toggletip({
|
|
57
|
+
label,
|
|
58
|
+
side,
|
|
59
|
+
align,
|
|
60
|
+
children,
|
|
61
|
+
}: {
|
|
62
|
+
label: ReactNode;
|
|
63
|
+
side?: 'top' | 'right' | 'bottom' | 'left';
|
|
64
|
+
/** `end` for a trigger at the right edge, so the tip opens leftwards. */
|
|
65
|
+
align?: 'start' | 'center' | 'end';
|
|
66
|
+
children: ReactNode;
|
|
67
|
+
}) {
|
|
68
|
+
const [open, setOpen] = useState(false);
|
|
69
|
+
const pointer = useRef<string | null>(null);
|
|
70
|
+
const hover = (next: boolean) => (event: { pointerType: string }) => {
|
|
71
|
+
if (event.pointerType === 'mouse') setOpen(next);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<Popover.Root open={open} onOpenChange={setOpen}>
|
|
76
|
+
<Popover.Trigger
|
|
77
|
+
asChild
|
|
78
|
+
onPointerEnter={hover(true)}
|
|
79
|
+
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;
|
|
86
|
+
}}
|
|
87
|
+
>
|
|
88
|
+
{children}
|
|
89
|
+
</Popover.Trigger>
|
|
90
|
+
<Popover.Portal>
|
|
91
|
+
<Popover.Content
|
|
92
|
+
className="tooltip"
|
|
93
|
+
side={side}
|
|
94
|
+
align={align}
|
|
95
|
+
sideOffset={6}
|
|
96
|
+
collisionPadding={16}
|
|
97
|
+
onOpenAutoFocus={(event: Event) => event.preventDefault()}
|
|
98
|
+
>
|
|
99
|
+
{label}
|
|
100
|
+
</Popover.Content>
|
|
101
|
+
</Popover.Portal>
|
|
102
|
+
</Popover.Root>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/* -------------------------------------------------------------------------- */
|
|
107
|
+
/* Feedback primitives */
|
|
108
|
+
/* -------------------------------------------------------------------------- */
|
|
109
|
+
|
|
110
|
+
export function Spinner({ size = 14 }: { size?: number }) {
|
|
111
|
+
return <Loader size={size} className="spinner" />;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function ErrorLine({ error }: { error: string | null }) {
|
|
115
|
+
if (error === null) return null;
|
|
116
|
+
return (
|
|
117
|
+
<p className="error-line" role="alert">
|
|
118
|
+
<AlertCircle size={14} />
|
|
119
|
+
<span>{error}</span>
|
|
120
|
+
</p>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const NOTICE_ICON = {
|
|
125
|
+
info: Info,
|
|
126
|
+
good: Check,
|
|
127
|
+
bad: AlertTriangle,
|
|
128
|
+
neutral: Info,
|
|
129
|
+
} as const;
|
|
130
|
+
|
|
131
|
+
export function Notice({
|
|
132
|
+
tone = 'neutral',
|
|
133
|
+
children,
|
|
134
|
+
}: {
|
|
135
|
+
tone?: keyof typeof NOTICE_ICON;
|
|
136
|
+
children: ReactNode;
|
|
137
|
+
}) {
|
|
138
|
+
const Icon = NOTICE_ICON[tone];
|
|
139
|
+
return (
|
|
140
|
+
<div
|
|
141
|
+
className={`notice${tone === 'neutral' ? '' : ` notice-${tone}`}`}
|
|
142
|
+
role={tone === 'bad' ? 'alert' : undefined}
|
|
143
|
+
>
|
|
144
|
+
<Icon size={16} />
|
|
145
|
+
<div>{children}</div>
|
|
146
|
+
</div>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Nothing here yet, said in a sentence.
|
|
152
|
+
*
|
|
153
|
+
* It sits where the table would have been, left-aligned like the rows it
|
|
154
|
+
* stands in for, rather than as a centred illustration.
|
|
155
|
+
*/
|
|
156
|
+
export function EmptyState({
|
|
157
|
+
title,
|
|
158
|
+
children,
|
|
159
|
+
actions,
|
|
160
|
+
}: {
|
|
161
|
+
title: string;
|
|
162
|
+
children?: ReactNode;
|
|
163
|
+
actions?: ReactNode;
|
|
164
|
+
}) {
|
|
165
|
+
return (
|
|
166
|
+
<div className="empty">
|
|
167
|
+
<p className="empty-title">{title}</p>
|
|
168
|
+
{children !== undefined && <p className="empty-body">{children}</p>}
|
|
169
|
+
{actions !== undefined && <div className="empty-actions">{actions}</div>}
|
|
170
|
+
</div>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/* -------------------------------------------------------------------------- */
|
|
175
|
+
/* Text */
|
|
176
|
+
/* -------------------------------------------------------------------------- */
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* An identifier that wraps after its underscores rather than mid-word.
|
|
180
|
+
*
|
|
181
|
+
* To the line breaker `DOCUSIGN_INTEGRATION_KEY` is one word, so a narrow
|
|
182
|
+
* column cuts it wherever room runs out (`…_KE` / `Y`). A <wbr> after each
|
|
183
|
+
* underscore offers the natural places instead. Copied text is unchanged, and
|
|
184
|
+
* `overflow-wrap: anywhere` still catches a segment too long for any line.
|
|
185
|
+
*/
|
|
186
|
+
export function breakAfterUnderscores(text: string): ReactNode {
|
|
187
|
+
return text
|
|
188
|
+
.split('_')
|
|
189
|
+
.flatMap((part, index) => (index === 0 ? [part] : ['_', <wbr key={index} />, part]));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/* -------------------------------------------------------------------------- */
|
|
193
|
+
/* Copy */
|
|
194
|
+
/* -------------------------------------------------------------------------- */
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Copy to clipboard with a settled confirmation.
|
|
198
|
+
*
|
|
199
|
+
* The glyph turns into a check, and screen readers hear "Copied", for 1.4s --
|
|
200
|
+
* long enough to be noticed after the eye has moved on, short enough not to
|
|
201
|
+
* look stuck.
|
|
202
|
+
*/
|
|
203
|
+
export function CopyButton({
|
|
204
|
+
value,
|
|
205
|
+
label = 'Copy',
|
|
206
|
+
variant = 'icon',
|
|
207
|
+
}: {
|
|
208
|
+
value: string;
|
|
209
|
+
label?: string;
|
|
210
|
+
/** `act` sits among a table row's actions; `icon` anywhere else. */
|
|
211
|
+
variant?: 'icon' | 'act';
|
|
212
|
+
}) {
|
|
213
|
+
const [copied, setCopied] = useState(false);
|
|
214
|
+
const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
215
|
+
|
|
216
|
+
useEffect(() => () => {
|
|
217
|
+
if (timer.current !== null) clearTimeout(timer.current);
|
|
218
|
+
}, []);
|
|
219
|
+
|
|
220
|
+
async function copy() {
|
|
221
|
+
try {
|
|
222
|
+
await navigator.clipboard.writeText(value);
|
|
223
|
+
} catch {
|
|
224
|
+
return; // Clipboard denied; say nothing rather than claim success.
|
|
225
|
+
}
|
|
226
|
+
setCopied(true);
|
|
227
|
+
if (timer.current !== null) clearTimeout(timer.current);
|
|
228
|
+
timer.current = setTimeout(() => setCopied(false), 1400);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return (
|
|
232
|
+
<Tip label={copied ? 'Copied' : label}>
|
|
233
|
+
<button
|
|
234
|
+
type="button"
|
|
235
|
+
className={variant === 'act' ? 'act act-icon' : 'btn btn-quiet btn-sm btn-icon'}
|
|
236
|
+
aria-label={label}
|
|
237
|
+
onClick={copy}
|
|
238
|
+
>
|
|
239
|
+
{copied ? <Check size={14} className="copied" /> : <Copy size={14} />}
|
|
240
|
+
<span className="visually-hidden" aria-live="polite">
|
|
241
|
+
{copied ? 'Copied' : ''}
|
|
242
|
+
</span>
|
|
243
|
+
</button>
|
|
244
|
+
</Tip>
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/* -------------------------------------------------------------------------- */
|
|
249
|
+
/* Confirmation */
|
|
250
|
+
/* -------------------------------------------------------------------------- */
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Confirmation for actions with reach.
|
|
254
|
+
*
|
|
255
|
+
* Reserved for changes that affect other people or other screens (archiving a
|
|
256
|
+
* project, revoking a grant). Restoring one secret is reversible and gets an
|
|
257
|
+
* undo toast instead -- a dialog on every action trains people to dismiss them.
|
|
258
|
+
*/
|
|
259
|
+
type ConfirmProps = {
|
|
260
|
+
title: ReactNode;
|
|
261
|
+
body: ReactNode;
|
|
262
|
+
confirmLabel: string;
|
|
263
|
+
destructive?: boolean;
|
|
264
|
+
onConfirm: () => void;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
function ConfirmContent({ title, body, confirmLabel, destructive, onConfirm }: ConfirmProps) {
|
|
268
|
+
return (
|
|
269
|
+
<AlertDialog.Portal>
|
|
270
|
+
<AlertDialog.Overlay className="overlay" />
|
|
271
|
+
<AlertDialog.Content className="dialog dialog-confirm">
|
|
272
|
+
<AlertDialog.Title className="dialog-title">{title}</AlertDialog.Title>
|
|
273
|
+
<AlertDialog.Description className="dialog-body">{body}</AlertDialog.Description>
|
|
274
|
+
<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>
|
|
286
|
+
</div>
|
|
287
|
+
</AlertDialog.Content>
|
|
288
|
+
</AlertDialog.Portal>
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export function ConfirmButton({
|
|
293
|
+
trigger,
|
|
294
|
+
disabled,
|
|
295
|
+
...confirm
|
|
296
|
+
}: ConfirmProps & { trigger: ReactNode; disabled?: boolean }) {
|
|
297
|
+
return (
|
|
298
|
+
<AlertDialog.Root>
|
|
299
|
+
<AlertDialog.Trigger asChild disabled={disabled}>
|
|
300
|
+
{trigger}
|
|
301
|
+
</AlertDialog.Trigger>
|
|
302
|
+
<ConfirmContent {...confirm} />
|
|
303
|
+
</AlertDialog.Root>
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* The same confirmation, opened from something that is not a trigger.
|
|
309
|
+
*
|
|
310
|
+
* A menu item cannot be one: it unmounts as the menu closes, taking the dialog
|
|
311
|
+
* with it. So the caller keeps the open state and the dialog lives outside the
|
|
312
|
+
* menu entirely.
|
|
313
|
+
*/
|
|
314
|
+
export function ConfirmDialog({
|
|
315
|
+
open,
|
|
316
|
+
onOpenChange,
|
|
317
|
+
...confirm
|
|
318
|
+
}: ConfirmProps & { open: boolean; onOpenChange: (open: boolean) => void }) {
|
|
319
|
+
return (
|
|
320
|
+
<AlertDialog.Root open={open} onOpenChange={onOpenChange}>
|
|
321
|
+
<ConfirmContent {...confirm} />
|
|
322
|
+
</AlertDialog.Root>
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* A plain modal, for a task you chose to begin.
|
|
328
|
+
*
|
|
329
|
+
* Distinct from ConfirmButton: that one interrupts to ask about something you
|
|
330
|
+
* already started, this one holds a form.
|
|
331
|
+
*/
|
|
332
|
+
export function Modal({
|
|
333
|
+
open,
|
|
334
|
+
onOpenChange,
|
|
335
|
+
title,
|
|
336
|
+
description,
|
|
337
|
+
wide = false,
|
|
338
|
+
children,
|
|
339
|
+
}: {
|
|
340
|
+
open: boolean;
|
|
341
|
+
onOpenChange: (open: boolean) => void;
|
|
342
|
+
title: ReactNode;
|
|
343
|
+
description?: ReactNode;
|
|
344
|
+
wide?: boolean;
|
|
345
|
+
children: ReactNode;
|
|
346
|
+
}) {
|
|
347
|
+
return (
|
|
348
|
+
<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
|
+
>
|
|
358
|
+
<div className="dialog-head">
|
|
359
|
+
<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>
|
|
364
|
+
</Dialog.Close>
|
|
365
|
+
</div>
|
|
366
|
+
{description !== undefined && (
|
|
367
|
+
<Dialog.Description className="dialog-body">{description}</Dialog.Description>
|
|
368
|
+
)}
|
|
369
|
+
{children}
|
|
370
|
+
</Dialog.Content>
|
|
371
|
+
</Dialog.Portal>
|
|
372
|
+
</Dialog.Root>
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/* -------------------------------------------------------------------------- */
|
|
377
|
+
/* Time */
|
|
378
|
+
/* -------------------------------------------------------------------------- */
|
|
379
|
+
|
|
380
|
+
const RELATIVE_STEPS: [limit: number, divisor: number, unit: Intl.RelativeTimeFormatUnit][] = [
|
|
381
|
+
[60, 1, 'second'],
|
|
382
|
+
[3600, 60, 'minute'],
|
|
383
|
+
[86400, 3600, 'hour'],
|
|
384
|
+
[2592000, 86400, 'day'],
|
|
385
|
+
[31536000, 2592000, 'month'],
|
|
386
|
+
[Infinity, 31536000, 'year'],
|
|
387
|
+
];
|
|
388
|
+
|
|
389
|
+
function relative(iso: string, now: number, style: 'long' | 'narrow' = 'long'): string {
|
|
390
|
+
const delta = (new Date(iso).getTime() - now) / 1000;
|
|
391
|
+
const magnitude = Math.abs(delta);
|
|
392
|
+
const [, divisor, unit] = RELATIVE_STEPS.find(([limit]) => magnitude < limit)!;
|
|
393
|
+
const formatter = new Intl.RelativeTimeFormat('en', { numeric: 'auto', style });
|
|
394
|
+
return formatter.format(Math.round(delta / divisor), unit);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function absolute(iso: string, precise: boolean): string {
|
|
398
|
+
return iso.replace('T', ' ').replace('Z', '').slice(0, precise ? 23 : 19);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* A timestamp. Absolute UTC by default, "3 hours ago" on hover.
|
|
403
|
+
*
|
|
404
|
+
* Absolute is the default on purpose: in the audit log this is evidence, and
|
|
405
|
+
* someone reading it is often transcribing it into a finding. `relative` flips
|
|
406
|
+
* the two, in the short form ("5h ago"), for glanceable metadata like "last
|
|
407
|
+
* written". The relative form can
|
|
408
|
+
* differ between server and client by a rounding step, so that one text node
|
|
409
|
+
* opts out of the hydration check rather than render a placeholder first.
|
|
410
|
+
*/
|
|
411
|
+
export function Timestamp({
|
|
412
|
+
iso,
|
|
413
|
+
precise = false,
|
|
414
|
+
display = 'absolute',
|
|
415
|
+
}: {
|
|
416
|
+
iso: string;
|
|
417
|
+
precise?: boolean;
|
|
418
|
+
display?: 'absolute' | 'relative';
|
|
419
|
+
}) {
|
|
420
|
+
const [now, setNow] = useState<number | null>(null);
|
|
421
|
+
useEffect(() => setNow(Date.now()), [iso]);
|
|
422
|
+
|
|
423
|
+
if (display === 'relative') {
|
|
424
|
+
return (
|
|
425
|
+
<Tip label={`${absolute(iso, precise)} UTC`}>
|
|
426
|
+
<time dateTime={iso} suppressHydrationWarning>
|
|
427
|
+
{relative(iso, now ?? Date.now(), 'narrow')}
|
|
428
|
+
</time>
|
|
429
|
+
</Tip>
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
const body = (
|
|
434
|
+
<time className="mono" dateTime={iso}>
|
|
435
|
+
{absolute(iso, precise)}
|
|
436
|
+
</time>
|
|
437
|
+
);
|
|
438
|
+
if (now === null) return body;
|
|
439
|
+
return <Tip label={relative(iso, now)}>{body}</Tip>;
|
|
440
|
+
}
|
package/src/entry.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import handler from '@tanstack/react-start/server-entry';
|
|
2
|
+
|
|
3
|
+
import type { Ui } from './types.ts';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `@coffre/ui`: Start's handler for the pages, nothing else. The server
|
|
7
|
+
* around it answers `/api` and sign-in, and hands every other GET here with
|
|
8
|
+
* the request's nonce and API client; see `router.tsx`.
|
|
9
|
+
*/
|
|
10
|
+
export function createUi(): Ui {
|
|
11
|
+
return { fetch: async (request, init) => handler.fetch(request, init) };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// The build's Worker entry must have a default `fetch`. Nothing deploys the
|
|
15
|
+
// UI alone: without a client from the server a page has no API to ask.
|
|
16
|
+
export default {
|
|
17
|
+
fetch: (request: Request) =>
|
|
18
|
+
new Response('coffre/ui renders pages for @coffre/server; it does not run alone', { status: 501 }),
|
|
19
|
+
};
|