@mondarth/ui 0.0.0-stage → 0.0.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 +83 -3
- package/README.md +0 -3
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
A warning beside what it is about: a triangle with `!`, which, pointed at, focused or pressed, shows its callout, what
|
|
3
|
+
is wrong. The callout describes the mark for a screen reader, so the warning is heard where it is seen. Escape hides
|
|
4
|
+
it again. A `CalloutMark` in the warning's tone.
|
|
5
|
+
-->
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import CalloutMark from './CalloutMark.svelte';
|
|
8
|
+
|
|
9
|
+
import type { Snippet } from 'svelte';
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
/** What the mark is called, such as "Warning", in the application's words. */
|
|
13
|
+
label: string;
|
|
14
|
+
/** What is wrong. */
|
|
15
|
+
children: Snippet;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let { label, children }: Props = $props();
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<CalloutMark {label} tone="warning" {children}>
|
|
22
|
+
{#snippet icon()}
|
|
23
|
+
<svg viewBox="0 0 24 24" width="18" height="18" aria-hidden="true">
|
|
24
|
+
<path
|
|
25
|
+
d="M12 3 2 20h20z M12 10v4 M12 17h.01"
|
|
26
|
+
fill="none"
|
|
27
|
+
stroke="currentColor"
|
|
28
|
+
stroke-width="2"
|
|
29
|
+
stroke-linecap="round"
|
|
30
|
+
stroke-linejoin="round" />
|
|
31
|
+
</svg>
|
|
32
|
+
{/snippet}
|
|
33
|
+
</CalloutMark>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** What the mark is called, such as "Warning", in the application's words. */
|
|
4
|
+
label: string;
|
|
5
|
+
/** What is wrong. */
|
|
6
|
+
children: Snippet;
|
|
7
|
+
}
|
|
8
|
+
declare const WarningMark: import("svelte").Component<Props, {}, "">;
|
|
9
|
+
type WarningMark = ReturnType<typeof WarningMark>;
|
|
10
|
+
export default WarningMark;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Attachment } from 'svelte/attachments';
|
|
2
|
+
/** An entry of a context menu. */
|
|
3
|
+
export interface MenuItem {
|
|
4
|
+
/** What it says, in the application's words. */
|
|
5
|
+
readonly label: string;
|
|
6
|
+
/** What it does, once chosen; the menu has closed by then. */
|
|
7
|
+
readonly onSelect: () => void;
|
|
8
|
+
/** Shown but not chosen. */
|
|
9
|
+
readonly disabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/** What a context menu holds. */
|
|
12
|
+
export interface ContextMenuOptions {
|
|
13
|
+
/** Its entries; with none, there is no menu, and the browser's own shows. */
|
|
14
|
+
readonly items: readonly MenuItem[];
|
|
15
|
+
/** What it is a menu of, for a screen reader, such as "Actions for Catalogue". */
|
|
16
|
+
readonly label: string;
|
|
17
|
+
/** What one opened from the keyboard opens under: the element with the menu, if none is given. */
|
|
18
|
+
readonly anchor?: HTMLElement | null | undefined;
|
|
19
|
+
}
|
|
20
|
+
/** Where a menu opens: at a point in the window, or under an element, from its left edge. */
|
|
21
|
+
export type MenuPlace = {
|
|
22
|
+
readonly x: number;
|
|
23
|
+
readonly y: number;
|
|
24
|
+
} | HTMLElement;
|
|
25
|
+
/**
|
|
26
|
+
* Opens a context menu, closing any other open.
|
|
27
|
+
* @param options - What it holds
|
|
28
|
+
* @param at - Where it opens
|
|
29
|
+
* @param returnTo - Where the focus goes back to, when it closes: where it is now, if not given
|
|
30
|
+
* @returns Whether it opened: not with no entries
|
|
31
|
+
*/
|
|
32
|
+
export declare function openContextMenu(options: ContextMenuOptions, at: MenuPlace, returnTo?: HTMLElement): boolean;
|
|
33
|
+
/** Closes the context menu open, if one is, leaving the focus where it is. */
|
|
34
|
+
export declare function closeContextMenu(): void;
|
|
35
|
+
/**
|
|
36
|
+
* Gives an element a context menu: `<li {@attach contextMenu(() => ({ items, label }))}>`. The innermost element with
|
|
37
|
+
* one has the right-click and the keys, so that one within another opens its own, or none, never its parent's.
|
|
38
|
+
* @param options - What the menu holds, asked for each time it opens
|
|
39
|
+
* @returns The attachment
|
|
40
|
+
*/
|
|
41
|
+
export declare function contextMenu(options: () => ContextMenuOptions): Attachment<HTMLElement>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context menus: a menu of what can be done with something, opened where it is asked for. Any element can have one,
|
|
3
|
+
* with {@link contextMenu}: a right-click opens it at the pointer, and Shift+F10 or the Menu key opens it under the
|
|
4
|
+
* element. A button, such as a "⋯", opens one with {@link openContextMenu}. One is open at a time; Escape, Tab, a choice
|
|
5
|
+
* or a click anywhere else closes it, the focus going back to where it was asked for, but not after a click elsewhere.
|
|
6
|
+
*/
|
|
7
|
+
import { mount, unmount } from 'svelte';
|
|
8
|
+
import ContextMenu from './ContextMenu.svelte';
|
|
9
|
+
/** Closes the menu open, if one is. */
|
|
10
|
+
let closeOpen = null;
|
|
11
|
+
/**
|
|
12
|
+
* Opens a context menu, closing any other open.
|
|
13
|
+
* @param options - What it holds
|
|
14
|
+
* @param at - Where it opens
|
|
15
|
+
* @param returnTo - Where the focus goes back to, when it closes: where it is now, if not given
|
|
16
|
+
* @returns Whether it opened: not with no entries
|
|
17
|
+
*/
|
|
18
|
+
export function openContextMenu(options, at, returnTo) {
|
|
19
|
+
if (options.items.length === 0)
|
|
20
|
+
return false;
|
|
21
|
+
closeContextMenu();
|
|
22
|
+
let x;
|
|
23
|
+
let y;
|
|
24
|
+
if (at instanceof HTMLElement) {
|
|
25
|
+
const box = at.getBoundingClientRect();
|
|
26
|
+
x = box.left;
|
|
27
|
+
y = box.bottom;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
({ x, y } = at);
|
|
31
|
+
}
|
|
32
|
+
// What has the focus is an HTML or SVG element, either of which takes it back.
|
|
33
|
+
const back = returnTo ?? document.activeElement;
|
|
34
|
+
// Called while it is the one open: opening another closes it first, which ends what could call it.
|
|
35
|
+
const close = (refocus) => {
|
|
36
|
+
closeOpen = null;
|
|
37
|
+
void unmount(menu);
|
|
38
|
+
if (refocus)
|
|
39
|
+
back?.focus();
|
|
40
|
+
};
|
|
41
|
+
const menu = mount(ContextMenu, {
|
|
42
|
+
target: document.body,
|
|
43
|
+
props: { items: options.items, x, y, label: options.label, onClose: close },
|
|
44
|
+
});
|
|
45
|
+
closeOpen = close;
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
/** Closes the context menu open, if one is, leaving the focus where it is. */
|
|
49
|
+
export function closeContextMenu() {
|
|
50
|
+
closeOpen?.(false);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Gives an element a context menu: `<li {@attach contextMenu(() => ({ items, label }))}>`. The innermost element with
|
|
54
|
+
* one has the right-click and the keys, so that one within another opens its own, or none, never its parent's.
|
|
55
|
+
* @param options - What the menu holds, asked for each time it opens
|
|
56
|
+
* @returns The attachment
|
|
57
|
+
*/
|
|
58
|
+
export function contextMenu(options) {
|
|
59
|
+
return element => {
|
|
60
|
+
const onContextMenu = (event) => {
|
|
61
|
+
event.stopPropagation();
|
|
62
|
+
if (openContextMenu(options(), { x: event.clientX, y: event.clientY }, element))
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
};
|
|
65
|
+
const onKeydown = (event) => {
|
|
66
|
+
if (!((event.key === 'F10' && event.shiftKey) || event.key === 'ContextMenu'))
|
|
67
|
+
return;
|
|
68
|
+
event.stopPropagation();
|
|
69
|
+
const asked = options();
|
|
70
|
+
if (openContextMenu(asked, asked.anchor ?? element, element))
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
};
|
|
73
|
+
element.addEventListener('contextmenu', onContextMenu);
|
|
74
|
+
element.addEventListener('keydown', onKeydown);
|
|
75
|
+
return () => {
|
|
76
|
+
element.removeEventListener('contextmenu', onContextMenu);
|
|
77
|
+
element.removeEventListener('keydown', onKeydown);
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
}
|
package/dist/dates.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The locale to write dates in: the first of the reader's languages, by their browser's `Accept-Language`, that is a
|
|
3
|
+
* regional form of the page's own language, as `en-GB` of `en`; or else the page's language itself.
|
|
4
|
+
*
|
|
5
|
+
* @param acceptLanguage - The request's `Accept-Language` header, if any
|
|
6
|
+
* @param language - The page's language, such as `en`
|
|
7
|
+
* @returns The locale
|
|
8
|
+
*/
|
|
9
|
+
export declare function dateLocaleOf(acceptLanguage: string | null, language: string): string;
|
|
10
|
+
/** Writing dates and times. */
|
|
11
|
+
export interface Dates {
|
|
12
|
+
/** A day, such as 22/11/2026. */
|
|
13
|
+
readonly date: (when: Date) => string;
|
|
14
|
+
/** A day and time, such as 22/11/2026, 09:00:00. */
|
|
15
|
+
readonly dateTime: (when: Date) => string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Writing dates and times in a locale.
|
|
19
|
+
*
|
|
20
|
+
* @param locale - The locale
|
|
21
|
+
* @returns How
|
|
22
|
+
*/
|
|
23
|
+
export declare function datesIn(locale: string): Dates;
|
|
24
|
+
/**
|
|
25
|
+
* Sets the locale every page and component under the caller writes dates in: the root layout's, from the server.
|
|
26
|
+
*
|
|
27
|
+
* @param locale - The locale, as it is now: asked each time a date is written
|
|
28
|
+
*/
|
|
29
|
+
export declare function setDateLocale(locale: () => string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Writing dates and times as the reader does: in the locale the root layout set, or the page's language where none
|
|
32
|
+
* is, as in a component shown alone.
|
|
33
|
+
*
|
|
34
|
+
* @param language - The page's language, as it is now
|
|
35
|
+
* @returns How
|
|
36
|
+
*/
|
|
37
|
+
export declare function useDates(language: () => string): Dates;
|
package/dist/dates.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dates and times, as each reader writes them: in the regional form of the page's language their browser prefers,
|
|
3
|
+
* such as `en-GB` (22/11/2026) or `en-US` (11/22/2026) on the English pages, from its `Accept-Language`. The server
|
|
4
|
+
* works it out once a request (`dateLocaleOf`, in the root layout), and every page and component formats with it
|
|
5
|
+
* (`useDates`), so that the server and the browser write a date alike.
|
|
6
|
+
*/
|
|
7
|
+
import { getContext, setContext } from 'svelte';
|
|
8
|
+
const KEY = Symbol('date-locale');
|
|
9
|
+
/**
|
|
10
|
+
* The locale to write dates in: the first of the reader's languages, by their browser's `Accept-Language`, that is a
|
|
11
|
+
* regional form of the page's own language, as `en-GB` of `en`; or else the page's language itself.
|
|
12
|
+
*
|
|
13
|
+
* @param acceptLanguage - The request's `Accept-Language` header, if any
|
|
14
|
+
* @param language - The page's language, such as `en`
|
|
15
|
+
* @returns The locale
|
|
16
|
+
*/
|
|
17
|
+
export function dateLocaleOf(acceptLanguage, language) {
|
|
18
|
+
const tags = (acceptLanguage ?? '')
|
|
19
|
+
.split(',')
|
|
20
|
+
.map(part => part.replace(/;.*/, '').trim())
|
|
21
|
+
.filter(tag => tag.includes('-'));
|
|
22
|
+
for (const tag of tags) {
|
|
23
|
+
const [primary] = tag.split('-');
|
|
24
|
+
if (primary?.toLowerCase() !== language.toLowerCase())
|
|
25
|
+
continue;
|
|
26
|
+
try {
|
|
27
|
+
// Written as the locale writes itself, as `en-US` of `en-us`.
|
|
28
|
+
return new Intl.Locale(tag).toString();
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// A tag that is no locale at all, as `en-!!`: the next one.
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return language;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Writing dates and times in a locale.
|
|
38
|
+
*
|
|
39
|
+
* @param locale - The locale
|
|
40
|
+
* @returns How
|
|
41
|
+
*/
|
|
42
|
+
export function datesIn(locale) {
|
|
43
|
+
return {
|
|
44
|
+
date: when => when.toLocaleDateString(locale),
|
|
45
|
+
dateTime: when => when.toLocaleString(locale),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Sets the locale every page and component under the caller writes dates in: the root layout's, from the server.
|
|
50
|
+
*
|
|
51
|
+
* @param locale - The locale, as it is now: asked each time a date is written
|
|
52
|
+
*/
|
|
53
|
+
export function setDateLocale(locale) {
|
|
54
|
+
setContext(KEY, locale);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Writing dates and times as the reader does: in the locale the root layout set, or the page's language where none
|
|
58
|
+
* is, as in a component shown alone.
|
|
59
|
+
*
|
|
60
|
+
* @param language - The page's language, as it is now
|
|
61
|
+
* @returns How
|
|
62
|
+
*/
|
|
63
|
+
export function useDates(language) {
|
|
64
|
+
const locale = getContext(KEY) ?? language;
|
|
65
|
+
return {
|
|
66
|
+
date: when => datesIn(locale()).date(when),
|
|
67
|
+
dateTime: when => datesIn(locale()).dateTime(when),
|
|
68
|
+
};
|
|
69
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Svelte pieces Mondarth's applications share, so that each looks, and reads, as one with the others: the logo, the
|
|
3
|
+
* page's frame, the top bar, the user navigation menu, the language picker, buttons, fields, checkboxes, dialogs, tables, trees and their menus, badges, panels, notices
|
|
4
|
+
* and callouts, and a workspace's layout: a resizable drawer, its toggle, and resizable panes. Each takes its words from the application, which translates them,
|
|
5
|
+
* so that this package holds none of its own.
|
|
6
|
+
*
|
|
7
|
+
* Dates written as each reader writes them are in `@mondarth/ui/dates`, language names in `@mondarth/ui/language`, and
|
|
8
|
+
* the theme's colours, as CSS custom properties, in `@mondarth/ui/theme.css`.
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
export { default as AppShell } from './AppShell.svelte';
|
|
13
|
+
export { default as Badge } from './Badge.svelte';
|
|
14
|
+
export { default as Brand } from './Brand.svelte';
|
|
15
|
+
export { default as Button } from './Button.svelte';
|
|
16
|
+
export { default as Callout } from './Callout.svelte';
|
|
17
|
+
export { default as CalloutMark } from './CalloutMark.svelte';
|
|
18
|
+
export { default as Checkbox } from './Checkbox.svelte';
|
|
19
|
+
export { default as ContextMenu } from './ContextMenu.svelte';
|
|
20
|
+
export { default as Dialog } from './Dialog.svelte';
|
|
21
|
+
export { default as DrawerLayout } from './DrawerLayout.svelte';
|
|
22
|
+
export { default as DrawerToggle } from './DrawerToggle.svelte';
|
|
23
|
+
export { default as ExpandableList } from './ExpandableList.svelte';
|
|
24
|
+
export { default as Field } from './Field.svelte';
|
|
25
|
+
export { default as FooterLinks } from './FooterLinks.svelte';
|
|
26
|
+
export { default as LanguagePicker } from './LanguagePicker.svelte';
|
|
27
|
+
export { default as Logo } from './Logo.svelte';
|
|
28
|
+
export { default as Notice } from './Notice.svelte';
|
|
29
|
+
export { default as Panel } from './Panel.svelte';
|
|
30
|
+
export { default as Prose } from './Prose.svelte';
|
|
31
|
+
export { default as ReturnLink } from './ReturnLink.svelte';
|
|
32
|
+
export { default as SplitPanes } from './SplitPanes.svelte';
|
|
33
|
+
export { default as Splitter } from './Splitter.svelte';
|
|
34
|
+
export { default as Table } from './Table.svelte';
|
|
35
|
+
export { default as Toast } from './Toast.svelte';
|
|
36
|
+
export { default as TopBar } from './TopBar.svelte';
|
|
37
|
+
export { default as Tree } from './Tree.svelte';
|
|
38
|
+
export { default as UserMenu } from './UserMenu.svelte';
|
|
39
|
+
export { default as WarningMark } from './WarningMark.svelte';
|
|
40
|
+
export type { FieldControl } from './Field.svelte';
|
|
41
|
+
export type { ProfileMenuItem, TopBarAccount, TopBarLink } from './top-bar.js';
|
|
42
|
+
export type { TreeNode, TreeRow } from './tree.js';
|
|
43
|
+
export type { ContextMenuOptions, MenuItem, MenuPlace } from './context-menu.js';
|
|
44
|
+
export { parentIds, visibleRows } from './tree.js';
|
|
45
|
+
export { SITES, type Site } from './site.js';
|
|
46
|
+
export { closeContextMenu, contextMenu, openContextMenu } from './context-menu.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Svelte pieces Mondarth's applications share, so that each looks, and reads, as one with the others: the logo, the
|
|
3
|
+
* page's frame, the top bar, the user navigation menu, the language picker, buttons, fields, checkboxes, dialogs, tables, trees and their menus, badges, panels, notices
|
|
4
|
+
* and callouts, and a workspace's layout: a resizable drawer, its toggle, and resizable panes. Each takes its words from the application, which translates them,
|
|
5
|
+
* so that this package holds none of its own.
|
|
6
|
+
*
|
|
7
|
+
* Dates written as each reader writes them are in `@mondarth/ui/dates`, language names in `@mondarth/ui/language`, and
|
|
8
|
+
* the theme's colours, as CSS custom properties, in `@mondarth/ui/theme.css`.
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
export { default as AppShell } from './AppShell.svelte';
|
|
13
|
+
export { default as Badge } from './Badge.svelte';
|
|
14
|
+
export { default as Brand } from './Brand.svelte';
|
|
15
|
+
export { default as Button } from './Button.svelte';
|
|
16
|
+
export { default as Callout } from './Callout.svelte';
|
|
17
|
+
export { default as CalloutMark } from './CalloutMark.svelte';
|
|
18
|
+
export { default as Checkbox } from './Checkbox.svelte';
|
|
19
|
+
export { default as ContextMenu } from './ContextMenu.svelte';
|
|
20
|
+
export { default as Dialog } from './Dialog.svelte';
|
|
21
|
+
export { default as DrawerLayout } from './DrawerLayout.svelte';
|
|
22
|
+
export { default as DrawerToggle } from './DrawerToggle.svelte';
|
|
23
|
+
export { default as ExpandableList } from './ExpandableList.svelte';
|
|
24
|
+
export { default as Field } from './Field.svelte';
|
|
25
|
+
export { default as FooterLinks } from './FooterLinks.svelte';
|
|
26
|
+
export { default as LanguagePicker } from './LanguagePicker.svelte';
|
|
27
|
+
export { default as Logo } from './Logo.svelte';
|
|
28
|
+
export { default as Notice } from './Notice.svelte';
|
|
29
|
+
export { default as Panel } from './Panel.svelte';
|
|
30
|
+
export { default as Prose } from './Prose.svelte';
|
|
31
|
+
export { default as ReturnLink } from './ReturnLink.svelte';
|
|
32
|
+
export { default as SplitPanes } from './SplitPanes.svelte';
|
|
33
|
+
export { default as Splitter } from './Splitter.svelte';
|
|
34
|
+
export { default as Table } from './Table.svelte';
|
|
35
|
+
export { default as Toast } from './Toast.svelte';
|
|
36
|
+
export { default as TopBar } from './TopBar.svelte';
|
|
37
|
+
export { default as Tree } from './Tree.svelte';
|
|
38
|
+
export { default as UserMenu } from './UserMenu.svelte';
|
|
39
|
+
export { default as WarningMark } from './WarningMark.svelte';
|
|
40
|
+
export { parentIds, visibleRows } from './tree.js';
|
|
41
|
+
export { SITES } from './site.js';
|
|
42
|
+
export { closeContextMenu, contextMenu, openContextMenu } from './context-menu.js';
|
package/dist/language.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A language's name, in itself, with a capital as that language writes one: `English`, `Español`.
|
|
3
|
+
*
|
|
4
|
+
* @param locale - The language's code, such as `es`
|
|
5
|
+
* @returns Its name
|
|
6
|
+
*/
|
|
7
|
+
export function languageName(locale) {
|
|
8
|
+
const name = new Intl.DisplayNames([locale], { type: 'language' }).of(locale) ??
|
|
9
|
+
/* istanbul ignore next -- `of` gives undefined only for a code the runtime does not know, which no application's is */
|
|
10
|
+
locale;
|
|
11
|
+
return name.charAt(0).toLocaleUpperCase(locale) + name.slice(1);
|
|
12
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a layout remembers for its viewer, such as a drawer's width: kept in the browser's local storage under a key of
|
|
3
|
+
* the application's, as a convenience alone. Storage can be missing, full or blocked (a private window, cleared site
|
|
4
|
+
* data), so a read gives nothing and a write is dropped, and the layout works as if nothing was kept.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* What was kept under a key, if it is what is wanted.
|
|
8
|
+
* @param key - The application's key
|
|
9
|
+
* @param valid - Whether a value read back is one to use
|
|
10
|
+
* @returns The value; `undefined` if none was kept, or storage cannot be read
|
|
11
|
+
*/
|
|
12
|
+
export declare function recall<T>(key: string, valid: (value: unknown) => value is T): T | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Keep a value under a key, if storage takes it.
|
|
15
|
+
* @param key - The application's key
|
|
16
|
+
* @param value - The value, as JSON
|
|
17
|
+
*/
|
|
18
|
+
export declare function remember(key: string, value: unknown): void;
|
|
19
|
+
/**
|
|
20
|
+
* Whether a value is a finite number.
|
|
21
|
+
* @param value - The value
|
|
22
|
+
* @returns `true` if it is
|
|
23
|
+
*/
|
|
24
|
+
export declare const isNumber: (value: unknown) => value is number;
|
|
25
|
+
/**
|
|
26
|
+
* Whether a value is `true` or `false`.
|
|
27
|
+
* @param value - The value
|
|
28
|
+
* @returns `true` if it is
|
|
29
|
+
*/
|
|
30
|
+
export declare const isBoolean: (value: unknown) => value is boolean;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a layout remembers for its viewer, such as a drawer's width: kept in the browser's local storage under a key of
|
|
3
|
+
* the application's, as a convenience alone. Storage can be missing, full or blocked (a private window, cleared site
|
|
4
|
+
* data), so a read gives nothing and a write is dropped, and the layout works as if nothing was kept.
|
|
5
|
+
*/
|
|
6
|
+
/** The prefix every key is kept under, apart from the applications' own. */
|
|
7
|
+
const PREFIX = 'mdr:';
|
|
8
|
+
/**
|
|
9
|
+
* What was kept under a key, if it is what is wanted.
|
|
10
|
+
* @param key - The application's key
|
|
11
|
+
* @param valid - Whether a value read back is one to use
|
|
12
|
+
* @returns The value; `undefined` if none was kept, or storage cannot be read
|
|
13
|
+
*/
|
|
14
|
+
export function recall(key, valid) {
|
|
15
|
+
try {
|
|
16
|
+
const kept = globalThis.localStorage.getItem(PREFIX + key);
|
|
17
|
+
if (kept === null)
|
|
18
|
+
return undefined;
|
|
19
|
+
const value = JSON.parse(kept);
|
|
20
|
+
return valid(value) ? value : undefined;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Keep a value under a key, if storage takes it.
|
|
28
|
+
* @param key - The application's key
|
|
29
|
+
* @param value - The value, as JSON
|
|
30
|
+
*/
|
|
31
|
+
export function remember(key, value) {
|
|
32
|
+
try {
|
|
33
|
+
globalThis.localStorage.setItem(PREFIX + key, JSON.stringify(value));
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// Storage is a convenience: the layout works without it.
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Whether a value is a finite number.
|
|
41
|
+
* @param value - The value
|
|
42
|
+
* @returns `true` if it is
|
|
43
|
+
*/
|
|
44
|
+
export const isNumber = (value) => typeof value === 'number' && Number.isFinite(value);
|
|
45
|
+
/**
|
|
46
|
+
* Whether a value is `true` or `false`.
|
|
47
|
+
* @param value - The value
|
|
48
|
+
* @returns `true` if it is
|
|
49
|
+
*/
|
|
50
|
+
export const isBoolean = (value) => typeof value === 'boolean';
|
package/dist/site.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mondarth's websites, each by the name the design tokens give it (`data-site`): mondarth.com, and its sites, the
|
|
3
|
+
* documentation among them. One list, so that every component that takes a site knows them all.
|
|
4
|
+
*/
|
|
5
|
+
export declare const SITES: readonly ["mondarth", "catalogue", "aide", "accounts", "docs"];
|
|
6
|
+
/** A Mondarth website, by the name the design tokens give it. */
|
|
7
|
+
export type Site = (typeof SITES)[number];
|
package/dist/site.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mondarth's websites, each by the name the design tokens give it (`data-site`): mondarth.com, and its sites, the
|
|
3
|
+
* documentation among them. One list, so that every component that takes a site knows them all.
|
|
4
|
+
*/
|
|
5
|
+
export const SITES = ['mondarth', 'catalogue', 'aide', 'accounts', 'docs'];
|
package/dist/theme.css
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Mondarth's theme, which every application shares: the design tokens' custom properties (`--mdr-*`, light, or dark
|
|
3
|
+
* where the browser prefers it or the page asks for it with `data-theme`), and the page's base.
|
|
4
|
+
*/
|
|
5
|
+
@import '@mondarth/design-tokens/tokens.css';
|
|
6
|
+
|
|
7
|
+
body {
|
|
8
|
+
margin: 0;
|
|
9
|
+
background: var(--mdr-color-background);
|
|
10
|
+
color: var(--mdr-color-text);
|
|
11
|
+
font-family: var(--mdr-font-family-sans);
|
|
12
|
+
line-height: var(--mdr-font-line-height-body);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/* Links: the accent, underlined in text so that colour is not the only sign of one, and a visible focus. */
|
|
16
|
+
a {
|
|
17
|
+
color: var(--mdr-color-accent);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
a:focus-visible {
|
|
21
|
+
outline: var(--mdr-border-width-focus) solid var(--mdr-color-focus);
|
|
22
|
+
outline-offset: 2px;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/*
|
|
26
|
+
* Form controls, native ones as a page writes them, in the theme: low in specificity (`:where`), so that a component or
|
|
27
|
+
* a page sets its own over them. A checkbox or a radio keeps the browser's own drawing, in the accent.
|
|
28
|
+
*/
|
|
29
|
+
:where(input:not([type='checkbox'], [type='radio'], [type='hidden']), select, textarea) {
|
|
30
|
+
box-sizing: border-box;
|
|
31
|
+
max-width: 100%;
|
|
32
|
+
padding: var(--mdr-space-2) var(--mdr-space-3);
|
|
33
|
+
border: var(--mdr-border-width-thin) solid var(--mdr-color-border-strong);
|
|
34
|
+
border-radius: var(--mdr-radius-small);
|
|
35
|
+
background: var(--mdr-color-surface);
|
|
36
|
+
color: var(--mdr-color-text);
|
|
37
|
+
font: inherit;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
:where(input, select, textarea):focus-visible {
|
|
41
|
+
outline: var(--mdr-border-width-focus) solid var(--mdr-color-focus);
|
|
42
|
+
outline-offset: 1px;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
:where(input, select, textarea)[aria-invalid='true'] {
|
|
46
|
+
border-color: var(--mdr-color-danger);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
:where(input[type='checkbox'], input[type='radio']) {
|
|
50
|
+
accent-color: var(--mdr-color-accent);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* Hidden but for screen readers: words a sighted reader has from what is around them. */
|
|
54
|
+
.mdr-visually-hidden {
|
|
55
|
+
position: absolute;
|
|
56
|
+
width: 1px;
|
|
57
|
+
height: 1px;
|
|
58
|
+
overflow: hidden;
|
|
59
|
+
clip-path: inset(50%);
|
|
60
|
+
white-space: nowrap;
|
|
61
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** A link of the top bar's menu. */
|
|
2
|
+
export interface TopBarLink {
|
|
3
|
+
readonly href: string;
|
|
4
|
+
readonly label: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* An entry of the profile menu: a link, or an action posted as a form, such as signing out, which a link must not do.
|
|
8
|
+
*/
|
|
9
|
+
export type ProfileMenuItem = {
|
|
10
|
+
readonly href: string;
|
|
11
|
+
readonly label: string;
|
|
12
|
+
} | {
|
|
13
|
+
readonly action: string;
|
|
14
|
+
readonly label: string;
|
|
15
|
+
};
|
|
16
|
+
/** The signed-in user, as the top bar shows them: the button to their menu, and what is in it. */
|
|
17
|
+
export interface TopBarAccount {
|
|
18
|
+
/** The name they are shown by, on the button. */
|
|
19
|
+
readonly name: string;
|
|
20
|
+
/** What the button says to a screen reader, naming them. */
|
|
21
|
+
readonly label: string;
|
|
22
|
+
/** The menu's entries, in order. */
|
|
23
|
+
readonly items: readonly ProfileMenuItem[];
|
|
24
|
+
}
|
|
25
|
+
/** Whether an entry of the profile menu is an action, posted as a form. */
|
|
26
|
+
export declare const isAction: (item: ProfileMenuItem) => item is {
|
|
27
|
+
readonly action: string;
|
|
28
|
+
readonly label: string;
|
|
29
|
+
};
|
package/dist/top-bar.js
ADDED
package/dist/tree.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** A node of a {@link Tree}: its own id and label, a detail beside it, and its children. */
|
|
2
|
+
export interface TreeNode {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly label: string;
|
|
5
|
+
/** A short detail shown beside the label, such as a count or a status. */
|
|
6
|
+
readonly detail?: string;
|
|
7
|
+
/** Shown faded, as something retired is. */
|
|
8
|
+
readonly muted?: boolean;
|
|
9
|
+
readonly children?: readonly TreeNode[];
|
|
10
|
+
}
|
|
11
|
+
/** A row of a tree as it shows: its node, how deep, and its parent's id. */
|
|
12
|
+
export interface TreeRow {
|
|
13
|
+
readonly node: TreeNode;
|
|
14
|
+
readonly level: number;
|
|
15
|
+
readonly parent: string | null;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The rows a tree shows, in order: every node whose ancestors are all expanded.
|
|
19
|
+
* @param nodes - The tree's top nodes
|
|
20
|
+
* @param expanded - The ids of the nodes expanded
|
|
21
|
+
* @returns The rows
|
|
22
|
+
*/
|
|
23
|
+
export declare function visibleRows(nodes: readonly TreeNode[], expanded: ReadonlySet<string>): TreeRow[];
|
|
24
|
+
/**
|
|
25
|
+
* The ids of every node that has children, as a tree opens fully expanded.
|
|
26
|
+
* @param nodes - The tree's top nodes
|
|
27
|
+
* @returns The ids
|
|
28
|
+
*/
|
|
29
|
+
export declare function parentIds(nodes: readonly TreeNode[]): string[];
|
package/dist/tree.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rows a tree shows, in order: every node whose ancestors are all expanded.
|
|
3
|
+
* @param nodes - The tree's top nodes
|
|
4
|
+
* @param expanded - The ids of the nodes expanded
|
|
5
|
+
* @returns The rows
|
|
6
|
+
*/
|
|
7
|
+
export function visibleRows(nodes, expanded) {
|
|
8
|
+
const rows = [];
|
|
9
|
+
const walk = (list, level, parent) => {
|
|
10
|
+
for (const node of list) {
|
|
11
|
+
rows.push({ node, level, parent });
|
|
12
|
+
if (node.children !== undefined && node.children.length > 0 && expanded.has(node.id)) {
|
|
13
|
+
walk(node.children, level + 1, node.id);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
walk(nodes, 1, null);
|
|
18
|
+
return rows;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The ids of every node that has children, as a tree opens fully expanded.
|
|
22
|
+
* @param nodes - The tree's top nodes
|
|
23
|
+
* @returns The ids
|
|
24
|
+
*/
|
|
25
|
+
export function parentIds(nodes) {
|
|
26
|
+
return nodes.flatMap(node => node.children !== undefined && node.children.length > 0 ? [node.id, ...parentIds(node.children)] : []);
|
|
27
|
+
}
|