@mondarth/ui 0.0.0-stage → 0.8.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/dist/AppShell.svelte +107 -0
- package/dist/AppShell.svelte.d.ts +14 -0
- package/dist/Badge.svelte +54 -0
- package/dist/Badge.svelte.d.ts +9 -0
- package/dist/Brand.svelte +62 -0
- package/dist/Brand.svelte.d.ts +14 -0
- package/dist/Button.svelte +73 -0
- package/dist/Button.svelte.d.ts +10 -0
- package/dist/Callout.svelte +40 -0
- package/dist/Callout.svelte.d.ts +9 -0
- package/dist/CalloutMark.svelte +104 -0
- package/dist/CalloutMark.svelte.d.ts +14 -0
- package/dist/Checkbox.svelte +60 -0
- package/dist/Checkbox.svelte.d.ts +15 -0
- package/dist/ContextMenu.svelte +151 -0
- package/dist/ContextMenu.svelte.d.ts +15 -0
- package/dist/Dialog.svelte +73 -0
- package/dist/Dialog.svelte.d.ts +14 -0
- package/dist/DrawerLayout.svelte +182 -0
- package/dist/DrawerLayout.svelte.d.ts +26 -0
- package/dist/DrawerToggle.svelte +66 -0
- package/dist/DrawerToggle.svelte.d.ts +11 -0
- package/dist/ExpandableList.svelte +164 -0
- package/dist/ExpandableList.svelte.d.ts +46 -0
- package/dist/Field.svelte +109 -0
- package/dist/Field.svelte.d.ts +28 -0
- package/dist/FooterLinks.svelte +54 -0
- package/dist/FooterLinks.svelte.d.ts +15 -0
- package/dist/LanguagePicker.svelte +48 -0
- package/dist/LanguagePicker.svelte.d.ts +33 -0
- package/dist/Logo.svelte +36 -0
- package/dist/Logo.svelte.d.ts +12 -0
- package/dist/Notice.svelte +116 -0
- package/dist/Notice.svelte.d.ts +13 -0
- package/dist/Panel.svelte +41 -0
- package/dist/Panel.svelte.d.ts +11 -0
- package/dist/Prose.svelte +23 -0
- package/dist/Prose.svelte.d.ts +8 -0
- package/dist/ReturnLink.svelte +50 -0
- package/dist/ReturnLink.svelte.d.ts +12 -0
- package/dist/SplitPanes.svelte +92 -0
- package/dist/SplitPanes.svelte.d.ts +21 -0
- package/dist/Splitter.svelte +160 -0
- package/dist/Splitter.svelte.d.ts +20 -0
- package/dist/Table.svelte +65 -0
- package/dist/Table.svelte.d.ts +12 -0
- package/dist/Toast.svelte +143 -0
- package/dist/Toast.svelte.d.ts +18 -0
- package/dist/TopBar.svelte +68 -0
- package/dist/TopBar.svelte.d.ts +19 -0
- package/dist/Tree.svelte +367 -0
- package/dist/Tree.svelte.d.ts +27 -0
- package/dist/UserMenu.svelte +209 -0
- package/dist/UserMenu.svelte.d.ts +10 -0
- package/dist/WarningMark.svelte +33 -0
- package/dist/WarningMark.svelte.d.ts +10 -0
- package/dist/context-menu.d.ts +41 -0
- package/dist/context-menu.js +80 -0
- package/dist/dates.d.ts +37 -0
- package/dist/dates.js +69 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +42 -0
- package/dist/language.d.ts +7 -0
- package/dist/language.js +12 -0
- package/dist/remembered.d.ts +30 -0
- package/dist/remembered.js +50 -0
- package/dist/site.d.ts +7 -0
- package/dist/site.js +5 -0
- package/dist/theme.css +61 -0
- package/dist/top-bar.d.ts +29 -0
- package/dist/top-bar.js +2 -0
- package/dist/tree.d.ts +29 -0
- package/dist/tree.js +27 -0
- package/package.json +84 -3
- package/README.md +0 -3
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The bar along the top of every page: the application's menu, if it has one, then whatever it puts beside it, such as
|
|
3
|
+
the language picker, and, at the far right, the user navigation menu (`UserMenu`): the way to sign in or register,
|
|
4
|
+
or, once signed in, the user's own menu.
|
|
5
|
+
-->
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import type { Snippet } from 'svelte';
|
|
8
|
+
|
|
9
|
+
import UserMenu from './UserMenu.svelte';
|
|
10
|
+
|
|
11
|
+
import type { TopBarAccount, TopBarLink } from './top-bar.js';
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
/** What the bar is labelled, as a landmark. */
|
|
15
|
+
label: string;
|
|
16
|
+
/** The menu's links, if the application has any beside the user menu. */
|
|
17
|
+
links?: readonly TopBarLink[];
|
|
18
|
+
/** The signed-in user, and their menu; none while signed out. */
|
|
19
|
+
account: TopBarAccount | null;
|
|
20
|
+
/** Where to sign in or register while signed out, and what the link says. */
|
|
21
|
+
signIn: TopBarLink;
|
|
22
|
+
/** What goes between the menu and the user menu, such as the language picker. */
|
|
23
|
+
children?: Snippet;
|
|
24
|
+
/** What goes at the bar's start, before the menu, such as a `DrawerToggle`. */
|
|
25
|
+
start?: Snippet | undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let { label, links = [], account, signIn, children, start }: Props = $props();
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<nav aria-label={label}>
|
|
32
|
+
{#if start}<div class="start">{@render start()}</div>{/if}
|
|
33
|
+
<ul class="menu">
|
|
34
|
+
{#each links as link (link.href)}
|
|
35
|
+
<li><a href={link.href}>{link.label}</a></li>
|
|
36
|
+
{/each}
|
|
37
|
+
</ul>
|
|
38
|
+
{@render children?.()}
|
|
39
|
+
<UserMenu {account} {signIn} />
|
|
40
|
+
</nav>
|
|
41
|
+
|
|
42
|
+
<style>
|
|
43
|
+
/* Its pieces wrap onto another line, at the right, where the page is too narrow for them, as on a phone. */
|
|
44
|
+
nav {
|
|
45
|
+
display: flex;
|
|
46
|
+
flex-wrap: wrap;
|
|
47
|
+
gap: var(--mdr-space-2) var(--mdr-space-4);
|
|
48
|
+
align-items: center;
|
|
49
|
+
justify-content: flex-end;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.menu {
|
|
53
|
+
flex: 1;
|
|
54
|
+
display: flex;
|
|
55
|
+
gap: var(--mdr-space-4);
|
|
56
|
+
margin: 0;
|
|
57
|
+
padding: 0;
|
|
58
|
+
list-style: none;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.start {
|
|
62
|
+
margin-inline-end: auto;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.menu a {
|
|
66
|
+
color: var(--mdr-color-accent);
|
|
67
|
+
}
|
|
68
|
+
</style>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { TopBarAccount, TopBarLink } from './top-bar.js';
|
|
3
|
+
interface Props {
|
|
4
|
+
/** What the bar is labelled, as a landmark. */
|
|
5
|
+
label: string;
|
|
6
|
+
/** The menu's links, if the application has any beside the user menu. */
|
|
7
|
+
links?: readonly TopBarLink[];
|
|
8
|
+
/** The signed-in user, and their menu; none while signed out. */
|
|
9
|
+
account: TopBarAccount | null;
|
|
10
|
+
/** Where to sign in or register while signed out, and what the link says. */
|
|
11
|
+
signIn: TopBarLink;
|
|
12
|
+
/** What goes between the menu and the user menu, such as the language picker. */
|
|
13
|
+
children?: Snippet;
|
|
14
|
+
/** What goes at the bar's start, before the menu, such as a `DrawerToggle`. */
|
|
15
|
+
start?: Snippet | undefined;
|
|
16
|
+
}
|
|
17
|
+
declare const TopBar: import("svelte").Component<Props, {}, "">;
|
|
18
|
+
type TopBar = ReturnType<typeof TopBar>;
|
|
19
|
+
export default TopBar;
|
package/dist/Tree.svelte
ADDED
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
A tree, as of a hierarchy an admin manages: each node's label, a detail beside it, and its children, which open and
|
|
3
|
+
close. It is one stop on the Tab key; the arrow keys move along it, Right and Left open and close a node or move into
|
|
4
|
+
and out of it, Home and End go to its ends, and Enter or Space selects. Where the application gives a menu of what
|
|
5
|
+
can be done with a node, a right-click, Shift+F10 or the Menu key, or the node's own "⋯" button, opens it there.
|
|
6
|
+
The node `renaming` names has its label as a text box, in place, its text chosen: Enter, or leaving it, renames the
|
|
7
|
+
node (`onRename`), unless it is empty or unchanged, and Escape leaves it as it was; either way the focus goes back to
|
|
8
|
+
the node from the keyboard.
|
|
9
|
+
-->
|
|
10
|
+
<script lang="ts">
|
|
11
|
+
import { contextMenu, openContextMenu } from './context-menu.js';
|
|
12
|
+
import { parentIds, visibleRows } from './tree.js';
|
|
13
|
+
|
|
14
|
+
import type { ContextMenuOptions, MenuItem } from './context-menu.js';
|
|
15
|
+
import type { TreeNode } from './tree.js';
|
|
16
|
+
|
|
17
|
+
interface Props {
|
|
18
|
+
/** The top nodes. */
|
|
19
|
+
nodes: readonly TreeNode[];
|
|
20
|
+
/** What the tree is, for a screen reader, such as "Services". */
|
|
21
|
+
label: string;
|
|
22
|
+
/** The id of the node selected, if any. */
|
|
23
|
+
selected?: string | null;
|
|
24
|
+
/** The ids of the nodes open: all of them, at first. */
|
|
25
|
+
expanded?: string[];
|
|
26
|
+
/** Selects a node, as a click, Enter or Space does. */
|
|
27
|
+
onSelect?: ((node: TreeNode) => void) | undefined;
|
|
28
|
+
/** What can be done with a node, in a menu; none, and there is no menu. */
|
|
29
|
+
menu?: ((node: TreeNode) => readonly MenuItem[]) | undefined;
|
|
30
|
+
/** What a node's menu is, for a screen reader and its "⋯" button, such as "Actions for Catalogue". */
|
|
31
|
+
menuLabel?: (node: TreeNode) => string;
|
|
32
|
+
/** The id of the node being renamed, in place, if any. */
|
|
33
|
+
renaming?: string | null;
|
|
34
|
+
/** Renames a node, given its new name, trimmed, and not its old one. */
|
|
35
|
+
onRename?: ((node: TreeNode, name: string) => void) | undefined;
|
|
36
|
+
/** What a node's text box is, for a screen reader, such as "Name of Saved Filter 1". */
|
|
37
|
+
renameLabel?: (node: TreeNode) => string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let {
|
|
41
|
+
nodes,
|
|
42
|
+
label,
|
|
43
|
+
selected = $bindable(null),
|
|
44
|
+
expanded = $bindable(parentIds(nodes)),
|
|
45
|
+
onSelect,
|
|
46
|
+
menu,
|
|
47
|
+
menuLabel = node => node.label,
|
|
48
|
+
renaming = $bindable(null),
|
|
49
|
+
onRename,
|
|
50
|
+
renameLabel = node => node.label,
|
|
51
|
+
}: Props = $props();
|
|
52
|
+
|
|
53
|
+
const open = $derived(new Set(expanded));
|
|
54
|
+
const rows = $derived(visibleRows(nodes, open));
|
|
55
|
+
/** The node the Tab key comes to, and the arrow keys move from. */
|
|
56
|
+
let current = $state<string | null>(null);
|
|
57
|
+
const focusable = $derived(
|
|
58
|
+
rows.some(({ node }) => node.id === current) ? current : (selected ?? rows[0]?.node.id ?? null),
|
|
59
|
+
);
|
|
60
|
+
let tree: HTMLUListElement | undefined = $state();
|
|
61
|
+
|
|
62
|
+
const hasChildren = (node: TreeNode) => node.children !== undefined && node.children.length > 0;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Moves the focus to a node's row.
|
|
66
|
+
* @param id - The node's id
|
|
67
|
+
*/
|
|
68
|
+
function focus(id: string): void {
|
|
69
|
+
current = id;
|
|
70
|
+
tree?.querySelector<HTMLElement>(`[data-id="${CSS.escape(id)}"]`)?.focus();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Opens a node, or closes it.
|
|
75
|
+
* @param id - The node's id
|
|
76
|
+
* @param on - Open or not
|
|
77
|
+
*/
|
|
78
|
+
function toggle(id: string, on: boolean): void {
|
|
79
|
+
expanded = on ? [...new Set([...expanded, id])] : expanded.filter(other => other !== id);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Selects a node.
|
|
84
|
+
* @param node - The node
|
|
85
|
+
*/
|
|
86
|
+
function select(node: TreeNode): void {
|
|
87
|
+
selected = node.id;
|
|
88
|
+
current = node.id;
|
|
89
|
+
onSelect?.(node);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* A node's menu: what can be done with it, opened under its row from the keyboard or its "⋯" button.
|
|
94
|
+
* @param node - The node
|
|
95
|
+
* @returns The menu
|
|
96
|
+
*/
|
|
97
|
+
function menuOf(node: TreeNode): ContextMenuOptions {
|
|
98
|
+
return {
|
|
99
|
+
items: menu?.(node) ?? [],
|
|
100
|
+
label: menuLabel(node),
|
|
101
|
+
anchor: tree?.querySelector<HTMLElement>(`[data-id="${CSS.escape(node.id)}"] > .row`),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Finishes renaming a node: renames it, if the name is new and not empty.
|
|
107
|
+
* @param node - The node
|
|
108
|
+
* @param name - What was entered, or nothing, to leave it as it was
|
|
109
|
+
* @param refocus - Whether the focus goes back to the node, as from the keyboard
|
|
110
|
+
*/
|
|
111
|
+
function finishRenaming(node: TreeNode, name: string | undefined, refocus: boolean): void {
|
|
112
|
+
// Once: Enter's removing the text box blurs it too.
|
|
113
|
+
if (renaming !== node.id) return;
|
|
114
|
+
renaming = null;
|
|
115
|
+
const trimmed = name?.trim() ?? '';
|
|
116
|
+
if (trimmed !== '' && trimmed !== node.label) onRename?.(node, trimmed);
|
|
117
|
+
if (refocus) focus(node.id);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The text box a node is renamed in takes the focus, its text chosen, to be typed over.
|
|
122
|
+
* @param input - The text box
|
|
123
|
+
*/
|
|
124
|
+
const chosen = (input: HTMLInputElement) => {
|
|
125
|
+
input.focus();
|
|
126
|
+
input.select();
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Moves along the tree from the keyboard.
|
|
131
|
+
* @param event - The key pressed
|
|
132
|
+
* @param node - The node whose row has the focus
|
|
133
|
+
* @param parent - Its parent's id
|
|
134
|
+
*/
|
|
135
|
+
function onKeydown(event: KeyboardEvent, node: TreeNode, parent: string | null): void {
|
|
136
|
+
// Only the row's own keys: not those of what is within it.
|
|
137
|
+
if (event.target !== event.currentTarget) return;
|
|
138
|
+
const at = rows.findIndex(row => row.node.id === node.id);
|
|
139
|
+
const go = (index: number) => {
|
|
140
|
+
const row = rows[index];
|
|
141
|
+
if (row !== undefined) focus(row.node.id);
|
|
142
|
+
};
|
|
143
|
+
switch (event.key) {
|
|
144
|
+
case 'ArrowDown':
|
|
145
|
+
go(at + 1);
|
|
146
|
+
break;
|
|
147
|
+
case 'ArrowUp':
|
|
148
|
+
go(at - 1);
|
|
149
|
+
break;
|
|
150
|
+
case 'Home':
|
|
151
|
+
go(0);
|
|
152
|
+
break;
|
|
153
|
+
case 'End':
|
|
154
|
+
go(rows.length - 1);
|
|
155
|
+
break;
|
|
156
|
+
case 'ArrowRight':
|
|
157
|
+
if (!hasChildren(node)) return;
|
|
158
|
+
if (open.has(node.id)) go(at + 1);
|
|
159
|
+
else toggle(node.id, true);
|
|
160
|
+
break;
|
|
161
|
+
case 'ArrowLeft':
|
|
162
|
+
if (hasChildren(node) && open.has(node.id)) toggle(node.id, false);
|
|
163
|
+
else if (parent !== null) focus(parent);
|
|
164
|
+
else return;
|
|
165
|
+
break;
|
|
166
|
+
case 'Enter':
|
|
167
|
+
case ' ':
|
|
168
|
+
select(node);
|
|
169
|
+
break;
|
|
170
|
+
default:
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
event.preventDefault();
|
|
174
|
+
}
|
|
175
|
+
</script>
|
|
176
|
+
|
|
177
|
+
{#snippet branch(list: readonly TreeNode[], level: number, parent: string | null)}
|
|
178
|
+
{#each list as node (node.id)}
|
|
179
|
+
{@const children = hasChildren(node)}
|
|
180
|
+
<li
|
|
181
|
+
role="treeitem"
|
|
182
|
+
data-id={node.id}
|
|
183
|
+
aria-level={level}
|
|
184
|
+
aria-selected={node.id === selected}
|
|
185
|
+
aria-expanded={children ? open.has(node.id) : undefined}
|
|
186
|
+
tabindex={node.id === focusable ? 0 : -1}
|
|
187
|
+
onkeydown={event => {
|
|
188
|
+
onKeydown(event, node, parent);
|
|
189
|
+
}}
|
|
190
|
+
onfocus={event => {
|
|
191
|
+
if (event.target === event.currentTarget) current = node.id;
|
|
192
|
+
}}
|
|
193
|
+
{@attach contextMenu(() => menuOf(node))}>
|
|
194
|
+
<!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions -->
|
|
195
|
+
<div
|
|
196
|
+
class={['row', { selected: node.id === selected, muted: node.muted === true }]}
|
|
197
|
+
style:--depth={level - 1}
|
|
198
|
+
onclick={() => {
|
|
199
|
+
select(node);
|
|
200
|
+
}}>
|
|
201
|
+
{#if children}
|
|
202
|
+
<span
|
|
203
|
+
class="caret"
|
|
204
|
+
aria-hidden="true"
|
|
205
|
+
onclick={event => {
|
|
206
|
+
event.stopPropagation();
|
|
207
|
+
toggle(node.id, !open.has(node.id));
|
|
208
|
+
}}>
|
|
209
|
+
{open.has(node.id) ? '▾' : '▸'}
|
|
210
|
+
</span>
|
|
211
|
+
{:else}
|
|
212
|
+
<span class="caret" aria-hidden="true"></span>
|
|
213
|
+
{/if}
|
|
214
|
+
{#if node.id === renaming}
|
|
215
|
+
<input
|
|
216
|
+
class="rename"
|
|
217
|
+
value={node.label}
|
|
218
|
+
aria-label={renameLabel(node)}
|
|
219
|
+
{@attach chosen}
|
|
220
|
+
onclick={event => {
|
|
221
|
+
event.stopPropagation();
|
|
222
|
+
}}
|
|
223
|
+
onkeydown={event => {
|
|
224
|
+
if (event.key === 'Enter') {
|
|
225
|
+
event.preventDefault();
|
|
226
|
+
finishRenaming(node, event.currentTarget.value, true);
|
|
227
|
+
} else if (event.key === 'Escape') {
|
|
228
|
+
event.preventDefault();
|
|
229
|
+
finishRenaming(node, undefined, true);
|
|
230
|
+
}
|
|
231
|
+
}}
|
|
232
|
+
onblur={event => {
|
|
233
|
+
finishRenaming(node, event.currentTarget.value, false);
|
|
234
|
+
}} />
|
|
235
|
+
{:else}
|
|
236
|
+
<span class="label">{node.label}</span>
|
|
237
|
+
{/if}
|
|
238
|
+
{#if node.detail !== undefined}
|
|
239
|
+
<span class="detail">{node.detail}</span>
|
|
240
|
+
{/if}
|
|
241
|
+
{#if menu !== undefined}
|
|
242
|
+
<button
|
|
243
|
+
type="button"
|
|
244
|
+
class="more"
|
|
245
|
+
tabindex="-1"
|
|
246
|
+
aria-label={menuLabel(node)}
|
|
247
|
+
aria-haspopup="menu"
|
|
248
|
+
onclick={event => {
|
|
249
|
+
event.stopPropagation();
|
|
250
|
+
const options = menuOf(node);
|
|
251
|
+
const item = event.currentTarget.closest<HTMLElement>('[role="treeitem"]') ?? undefined;
|
|
252
|
+
openContextMenu(options, options.anchor ?? event.currentTarget, item);
|
|
253
|
+
}}>
|
|
254
|
+
⋯
|
|
255
|
+
</button>
|
|
256
|
+
{/if}
|
|
257
|
+
</div>
|
|
258
|
+
{#if children && open.has(node.id)}
|
|
259
|
+
<ul role="group">
|
|
260
|
+
{@render branch(node.children ?? [], level + 1, node.id)}
|
|
261
|
+
</ul>
|
|
262
|
+
{/if}
|
|
263
|
+
</li>
|
|
264
|
+
{/each}
|
|
265
|
+
{/snippet}
|
|
266
|
+
|
|
267
|
+
<ul class="tree" role="tree" aria-label={label} bind:this={tree}>
|
|
268
|
+
{@render branch(nodes, 1, null)}
|
|
269
|
+
</ul>
|
|
270
|
+
|
|
271
|
+
<style>
|
|
272
|
+
.tree,
|
|
273
|
+
.tree ul {
|
|
274
|
+
margin: 0;
|
|
275
|
+
padding: 0;
|
|
276
|
+
list-style: none;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
[role='treeitem'] {
|
|
280
|
+
outline: none;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
.row {
|
|
284
|
+
display: flex;
|
|
285
|
+
gap: var(--mdr-space-2);
|
|
286
|
+
align-items: center;
|
|
287
|
+
padding: var(--mdr-space-1) var(--mdr-space-2);
|
|
288
|
+
padding-inline-start: calc(var(--mdr-space-2) + var(--depth) * var(--mdr-space-5));
|
|
289
|
+
border-radius: var(--mdr-radius-small);
|
|
290
|
+
cursor: pointer;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/* As wide as the label it takes the place of may grow. */
|
|
294
|
+
.rename {
|
|
295
|
+
flex: 1;
|
|
296
|
+
min-width: 0;
|
|
297
|
+
padding: 0 var(--mdr-space-1);
|
|
298
|
+
font: inherit;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
.row:hover {
|
|
302
|
+
background: var(--mdr-color-subtle);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
[role='treeitem']:focus-visible > .row {
|
|
306
|
+
outline: var(--mdr-border-width-focus) solid var(--mdr-color-focus);
|
|
307
|
+
outline-offset: -2px;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
.row.selected {
|
|
311
|
+
background: var(--mdr-color-subtle);
|
|
312
|
+
box-shadow: inset var(--mdr-border-width-rule) 0 0 var(--mdr-color-accent);
|
|
313
|
+
font-weight: var(--mdr-font-weight-strong);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
.row.muted .label {
|
|
317
|
+
color: var(--mdr-color-text-muted);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
.caret {
|
|
321
|
+
flex: none;
|
|
322
|
+
width: 1em;
|
|
323
|
+
color: var(--mdr-color-text-muted);
|
|
324
|
+
text-align: center;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
.label {
|
|
328
|
+
flex: 1;
|
|
329
|
+
min-width: 0;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
.detail {
|
|
333
|
+
color: var(--mdr-color-text-muted);
|
|
334
|
+
font-size: var(--mdr-font-size-small);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/* Shown on the row's hover or focus, for a pointer that cannot right-click, such as a finger. */
|
|
338
|
+
.more {
|
|
339
|
+
flex: none;
|
|
340
|
+
padding: 0 var(--mdr-space-2);
|
|
341
|
+
border: 0;
|
|
342
|
+
border-radius: var(--mdr-radius-small);
|
|
343
|
+
background: none;
|
|
344
|
+
color: var(--mdr-color-text-muted);
|
|
345
|
+
font: inherit;
|
|
346
|
+
line-height: 1.4;
|
|
347
|
+
cursor: pointer;
|
|
348
|
+
opacity: 0;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
.row:hover .more,
|
|
352
|
+
[role='treeitem']:focus-visible > .row .more,
|
|
353
|
+
.more:focus-visible {
|
|
354
|
+
opacity: 1;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
.more:hover {
|
|
358
|
+
background: var(--mdr-color-border);
|
|
359
|
+
color: var(--mdr-color-text);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
@media (hover: none) {
|
|
363
|
+
.more {
|
|
364
|
+
opacity: 1;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
</style>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { MenuItem } from './context-menu.js';
|
|
2
|
+
import type { TreeNode } from './tree.js';
|
|
3
|
+
interface Props {
|
|
4
|
+
/** The top nodes. */
|
|
5
|
+
nodes: readonly TreeNode[];
|
|
6
|
+
/** What the tree is, for a screen reader, such as "Services". */
|
|
7
|
+
label: string;
|
|
8
|
+
/** The id of the node selected, if any. */
|
|
9
|
+
selected?: string | null;
|
|
10
|
+
/** The ids of the nodes open: all of them, at first. */
|
|
11
|
+
expanded?: string[];
|
|
12
|
+
/** Selects a node, as a click, Enter or Space does. */
|
|
13
|
+
onSelect?: ((node: TreeNode) => void) | undefined;
|
|
14
|
+
/** What can be done with a node, in a menu; none, and there is no menu. */
|
|
15
|
+
menu?: ((node: TreeNode) => readonly MenuItem[]) | undefined;
|
|
16
|
+
/** What a node's menu is, for a screen reader and its "⋯" button, such as "Actions for Catalogue". */
|
|
17
|
+
menuLabel?: (node: TreeNode) => string;
|
|
18
|
+
/** The id of the node being renamed, in place, if any. */
|
|
19
|
+
renaming?: string | null;
|
|
20
|
+
/** Renames a node, given its new name, trimmed, and not its old one. */
|
|
21
|
+
onRename?: ((node: TreeNode, name: string) => void) | undefined;
|
|
22
|
+
/** What a node's text box is, for a screen reader, such as "Name of Saved Filter 1". */
|
|
23
|
+
renameLabel?: (node: TreeNode) => string;
|
|
24
|
+
}
|
|
25
|
+
declare const Tree: import("svelte").Component<Props, {}, "selected" | "expanded" | "renaming">;
|
|
26
|
+
type Tree = ReturnType<typeof Tree>;
|
|
27
|
+
export default Tree;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The user navigation menu, shared by every Mondarth website: while signed out, the way to sign in or register; once
|
|
3
|
+
signed in, the button showing the name the user is shown by, which opens their menu: their profile, their
|
|
4
|
+
subscription, the admin pages for an admin, and signing out, or whatever entries the application gives it.
|
|
5
|
+
|
|
6
|
+
The menu is a disclosure (`<details>`), which opens without a script; with one, Escape closes it and gives the focus
|
|
7
|
+
back to its button, and so does a click anywhere else. Each application gives the entries, in its own words.
|
|
8
|
+
-->
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import { isAction } from './top-bar.js';
|
|
11
|
+
|
|
12
|
+
import type { TopBarAccount, TopBarLink } from './top-bar.js';
|
|
13
|
+
|
|
14
|
+
interface Props {
|
|
15
|
+
/** The signed-in user, and their menu; none while signed out. */
|
|
16
|
+
account: TopBarAccount | null;
|
|
17
|
+
/** Where to sign in or register while signed out, and what the link says. */
|
|
18
|
+
signIn: TopBarLink;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let { account, signIn }: Props = $props();
|
|
22
|
+
|
|
23
|
+
let open = $state(false);
|
|
24
|
+
let details: HTMLDetailsElement | undefined = $state();
|
|
25
|
+
let items: HTMLUListElement | undefined = $state();
|
|
26
|
+
/**
|
|
27
|
+
* Whether the menu opens from the button's start, rightwards in a left-to-right page: only where opening from its
|
|
28
|
+
* end, as at the far right of the bar, would run it off the window.
|
|
29
|
+
*/
|
|
30
|
+
let fromStart = $state(false);
|
|
31
|
+
|
|
32
|
+
/** Closes the menu, giving the focus back to its button where it was within the menu. */
|
|
33
|
+
function close(refocus: boolean): void {
|
|
34
|
+
open = false;
|
|
35
|
+
if (refocus) details?.querySelector('summary')?.focus();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
$effect(() => {
|
|
39
|
+
if (!open) {
|
|
40
|
+
fromStart = false;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const box = items?.getBoundingClientRect();
|
|
44
|
+
if (box !== undefined && box.left < 0) fromStart = true;
|
|
45
|
+
const onKey = (event: KeyboardEvent) => {
|
|
46
|
+
if (event.key === 'Escape') close(details?.contains(document.activeElement) === true);
|
|
47
|
+
};
|
|
48
|
+
const onPointer = (event: PointerEvent) => {
|
|
49
|
+
if (!(event.target instanceof Node) || details?.contains(event.target) !== true) close(false);
|
|
50
|
+
};
|
|
51
|
+
document.addEventListener('keydown', onKey);
|
|
52
|
+
document.addEventListener('pointerdown', onPointer);
|
|
53
|
+
return () => {
|
|
54
|
+
document.removeEventListener('keydown', onKey);
|
|
55
|
+
document.removeEventListener('pointerdown', onPointer);
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
{#if account === null}
|
|
61
|
+
<a class="sign-in" href={signIn.href}>{signIn.label}</a>
|
|
62
|
+
{:else}
|
|
63
|
+
<details class="account" bind:this={details} bind:open>
|
|
64
|
+
<summary class="profile" aria-label={account.label}><span class="name">{account.name}</span></summary>
|
|
65
|
+
<ul class="items" class:from-start={fromStart} bind:this={items}>
|
|
66
|
+
{#each account.items as item (item.label)}
|
|
67
|
+
<li>
|
|
68
|
+
{#if isAction(item)}
|
|
69
|
+
<form method="POST" action={item.action}><button type="submit">{item.label}</button></form>
|
|
70
|
+
{:else}
|
|
71
|
+
<a href={item.href}>{item.label}</a>
|
|
72
|
+
{/if}
|
|
73
|
+
</li>
|
|
74
|
+
{/each}
|
|
75
|
+
</ul>
|
|
76
|
+
</details>
|
|
77
|
+
{/if}
|
|
78
|
+
|
|
79
|
+
<style>
|
|
80
|
+
.profile,
|
|
81
|
+
.sign-in {
|
|
82
|
+
display: inline-flex;
|
|
83
|
+
gap: var(--mdr-space-2);
|
|
84
|
+
align-items: center;
|
|
85
|
+
padding: var(--mdr-space-1) var(--mdr-space-3);
|
|
86
|
+
border: var(--mdr-border-width-thin) solid var(--mdr-color-border-strong);
|
|
87
|
+
border-radius: var(--mdr-radius-pill);
|
|
88
|
+
color: var(--mdr-color-text);
|
|
89
|
+
text-decoration: none;
|
|
90
|
+
white-space: nowrap;
|
|
91
|
+
cursor: pointer;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.profile:hover,
|
|
95
|
+
.profile:focus-visible,
|
|
96
|
+
.sign-in:hover,
|
|
97
|
+
.sign-in:focus-visible {
|
|
98
|
+
border-color: var(--mdr-color-accent);
|
|
99
|
+
color: var(--mdr-color-accent);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.profile:focus-visible,
|
|
103
|
+
.sign-in:focus-visible {
|
|
104
|
+
outline: var(--mdr-border-width-focus) solid var(--mdr-color-focus);
|
|
105
|
+
outline-offset: 2px;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/* The way in, for a visitor: the main action of the bar, in the gear's gold. */
|
|
109
|
+
.sign-in {
|
|
110
|
+
border-color: var(--mdr-color-action);
|
|
111
|
+
background: var(--mdr-color-action);
|
|
112
|
+
color: var(--mdr-color-text-on-action);
|
|
113
|
+
font-weight: var(--mdr-font-weight-strong);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.sign-in:hover,
|
|
117
|
+
.sign-in:focus-visible {
|
|
118
|
+
border-color: var(--mdr-color-text);
|
|
119
|
+
color: var(--mdr-color-text-on-action);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/* As wide as its button, wherever it is placed, so that the menu hangs from the button. */
|
|
123
|
+
.account {
|
|
124
|
+
position: relative;
|
|
125
|
+
display: inline-block;
|
|
126
|
+
max-width: 100%;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/* A long name is cut short, its whole in the button's label. */
|
|
130
|
+
.profile {
|
|
131
|
+
max-width: 14rem;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.name {
|
|
135
|
+
overflow: hidden;
|
|
136
|
+
text-overflow: ellipsis;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/* The button's own marker gives way to the dot and a caret. */
|
|
140
|
+
.profile {
|
|
141
|
+
list-style: none;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.profile::-webkit-details-marker {
|
|
145
|
+
display: none;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.profile::before {
|
|
149
|
+
content: '';
|
|
150
|
+
width: 0.6rem;
|
|
151
|
+
height: 0.6rem;
|
|
152
|
+
border-radius: 50%;
|
|
153
|
+
background: var(--mdr-color-accent);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.profile::after {
|
|
157
|
+
content: '▾';
|
|
158
|
+
font-size: var(--mdr-font-size-small);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.account[open] .profile::after {
|
|
162
|
+
content: '▴';
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.items {
|
|
166
|
+
position: absolute;
|
|
167
|
+
inset-inline-end: 0;
|
|
168
|
+
z-index: 10;
|
|
169
|
+
display: grid;
|
|
170
|
+
min-width: 12rem;
|
|
171
|
+
margin: var(--mdr-space-1) 0 0;
|
|
172
|
+
padding: var(--mdr-space-1) 0;
|
|
173
|
+
border: var(--mdr-border-width-thin) solid var(--mdr-color-border);
|
|
174
|
+
border-radius: var(--mdr-radius-small);
|
|
175
|
+
background: var(--mdr-color-surface);
|
|
176
|
+
list-style: none;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.items.from-start {
|
|
180
|
+
inset-inline: 0 auto;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.items a,
|
|
184
|
+
.items button {
|
|
185
|
+
display: block;
|
|
186
|
+
box-sizing: border-box;
|
|
187
|
+
width: 100%;
|
|
188
|
+
padding: var(--mdr-space-2) var(--mdr-space-4);
|
|
189
|
+
border: 0;
|
|
190
|
+
background: none;
|
|
191
|
+
color: var(--mdr-color-text);
|
|
192
|
+
font: inherit;
|
|
193
|
+
text-align: start;
|
|
194
|
+
text-decoration: none;
|
|
195
|
+
cursor: pointer;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.items a:hover,
|
|
199
|
+
.items a:focus-visible,
|
|
200
|
+
.items button:hover,
|
|
201
|
+
.items button:focus-visible {
|
|
202
|
+
background: var(--mdr-color-subtle);
|
|
203
|
+
color: var(--mdr-color-accent);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.items form {
|
|
207
|
+
margin: 0;
|
|
208
|
+
}
|
|
209
|
+
</style>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TopBarAccount, TopBarLink } from './top-bar.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** The signed-in user, and their menu; none while signed out. */
|
|
4
|
+
account: TopBarAccount | null;
|
|
5
|
+
/** Where to sign in or register while signed out, and what the link says. */
|
|
6
|
+
signIn: TopBarLink;
|
|
7
|
+
}
|
|
8
|
+
declare const UserMenu: import("svelte").Component<Props, {}, "">;
|
|
9
|
+
type UserMenu = ReturnType<typeof UserMenu>;
|
|
10
|
+
export default UserMenu;
|