occulite-ui 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +290 -2
  3. package/THIRD_PARTY_NOTICES.md +36 -0
  4. package/dist/clipboard.d.ts +26 -0
  5. package/dist/clipboard.js +70 -0
  6. package/dist/components/ContextMenu.svelte +158 -0
  7. package/dist/components/ContextMenu.svelte.d.ts +14 -0
  8. package/dist/components/DataTable.svelte +1990 -0
  9. package/dist/components/DataTable.svelte.d.ts +154 -0
  10. package/dist/components/Dialog.svelte +420 -0
  11. package/dist/components/Dialog.svelte.d.ts +55 -0
  12. package/dist/components/GithubLink.svelte +74 -0
  13. package/dist/components/GithubLink.svelte.d.ts +16 -0
  14. package/dist/components/Header.svelte +196 -0
  15. package/dist/components/Header.svelte.d.ts +42 -0
  16. package/dist/components/Icon.svelte +51 -0
  17. package/dist/components/Icon.svelte.d.ts +12 -0
  18. package/dist/components/LanguageSwitch.svelte +63 -0
  19. package/dist/components/LanguageSwitch.svelte.d.ts +17 -0
  20. package/dist/components/Loader.svelte +65 -0
  21. package/dist/components/Loader.svelte.d.ts +9 -0
  22. package/dist/components/MultiSelect.svelte +467 -0
  23. package/dist/components/MultiSelect.svelte.d.ts +28 -0
  24. package/dist/components/Notices.svelte +146 -0
  25. package/dist/components/Notices.svelte.d.ts +16 -0
  26. package/dist/components/PrimaryToolbarButton.svelte +189 -0
  27. package/dist/components/PrimaryToolbarButton.svelte.d.ts +34 -0
  28. package/dist/components/Tabs.svelte +118 -0
  29. package/dist/components/Tabs.svelte.d.ts +16 -0
  30. package/dist/components/ThemeSwitch.svelte +46 -0
  31. package/dist/components/ThemeSwitch.svelte.d.ts +11 -0
  32. package/dist/components/Toolbar.svelte +57 -0
  33. package/dist/components/Toolbar.svelte.d.ts +11 -0
  34. package/dist/components/ToolbarButton.svelte +126 -0
  35. package/dist/components/ToolbarButton.svelte.d.ts +22 -0
  36. package/dist/components/Tooltip.svelte +106 -0
  37. package/dist/components/Tooltip.svelte.d.ts +31 -0
  38. package/dist/components/TooltipBubble.svelte +65 -0
  39. package/dist/components/TooltipBubble.svelte.d.ts +18 -0
  40. package/dist/components/contextMenu.d.ts +19 -0
  41. package/dist/components/contextMenu.js +6 -0
  42. package/dist/components/dialogGeometry.d.ts +91 -0
  43. package/dist/components/dialogGeometry.js +140 -0
  44. package/dist/components/index.d.ts +22 -0
  45. package/dist/components/index.js +22 -0
  46. package/dist/components/multiSelect.d.ts +27 -0
  47. package/dist/components/multiSelect.js +26 -0
  48. package/dist/components/navigation.d.ts +34 -0
  49. package/dist/components/navigation.js +19 -0
  50. package/dist/components/tooltip.d.ts +29 -0
  51. package/dist/components/tooltip.js +27 -0
  52. package/dist/css/app.css +3 -0
  53. package/dist/css/base.css +84 -0
  54. package/dist/css/tokens.css +170 -0
  55. package/dist/dialog/index.d.ts +6 -0
  56. package/dist/dialog/index.js +6 -0
  57. package/dist/embedding/ShellEmbedding.svelte.d.ts +27 -0
  58. package/dist/embedding/ShellEmbedding.svelte.js +79 -0
  59. package/dist/embedding/constants.d.ts +23 -0
  60. package/dist/embedding/constants.js +54 -0
  61. package/dist/embedding/index.d.ts +2 -0
  62. package/dist/embedding/index.js +2 -0
  63. package/dist/externalLink.d.ts +15 -0
  64. package/dist/externalLink.js +20 -0
  65. package/dist/format.d.ts +6 -0
  66. package/dist/format.js +16 -0
  67. package/dist/i18n/i18n.svelte.d.ts +112 -0
  68. package/dist/i18n/i18n.svelte.js +211 -0
  69. package/dist/i18n/index.d.ts +3 -0
  70. package/dist/i18n/index.js +3 -0
  71. package/dist/i18n/messages.d.ts +9 -0
  72. package/dist/i18n/messages.js +58 -0
  73. package/dist/i18n/translator.d.ts +65 -0
  74. package/dist/i18n/translator.js +99 -0
  75. package/dist/icons/index.d.ts +17 -0
  76. package/dist/icons/index.js +11 -0
  77. package/dist/index.d.ts +16 -0
  78. package/dist/index.js +16 -0
  79. package/dist/notices/NoticesStore.svelte.d.ts +64 -0
  80. package/dist/notices/NoticesStore.svelte.js +127 -0
  81. package/dist/notices/index.d.ts +1 -0
  82. package/dist/notices/index.js +1 -0
  83. package/dist/storage.d.ts +11 -0
  84. package/dist/storage.js +27 -0
  85. package/dist/table/LocalColumnWidths.svelte.d.ts +32 -0
  86. package/dist/table/LocalColumnWidths.svelte.js +91 -0
  87. package/dist/table/columnMeasure.d.ts +24 -0
  88. package/dist/table/columnMeasure.js +82 -0
  89. package/dist/table/columnWidths.d.ts +60 -0
  90. package/dist/table/columnWidths.js +86 -0
  91. package/dist/table/dataTableContext.d.ts +26 -0
  92. package/dist/table/dataTableContext.js +16 -0
  93. package/dist/table/index.d.ts +6 -0
  94. package/dist/table/index.js +6 -0
  95. package/dist/table/metrics.d.ts +10 -0
  96. package/dist/table/metrics.js +10 -0
  97. package/dist/table/tableModel.d.ts +306 -0
  98. package/dist/table/tableModel.js +437 -0
  99. package/dist/theme/choices.d.ts +8 -0
  100. package/dist/theme/choices.js +6 -0
  101. package/dist/theme/index.d.ts +2 -0
  102. package/dist/theme/index.js +2 -0
  103. package/dist/theme/theme.svelte.d.ts +60 -0
  104. package/dist/theme/theme.svelte.js +108 -0
  105. package/package.json +137 -4
@@ -0,0 +1,106 @@
1
+ <script lang="ts">
2
+ import type {Snippet} from 'svelte';
3
+
4
+ import {TOOLTIP_DELAY_MS, type TooltipAnchor} from './tooltip.js';
5
+ import TooltipBubble from './TooltipBubble.svelte';
6
+
7
+ /**
8
+ * The tooltip of the toolbar buttons.
9
+ *
10
+ * 2.x and 3.0 up to `3.0.0-beta.8` used the `title` attribute, which hands the whole job to
11
+ * the browser - and the browser decides when to show it. On macOS that wait was measured at
12
+ * four to five seconds by the reporter while it is a few hundred milliseconds elsewhere, and
13
+ * on a **disabled** button there is no tooltip at all: a disabled control dispatches no
14
+ * pointer events, so the `reason` a button is greyed out - the one text the user needs there -
15
+ * was exactly the one that never appeared.
16
+ *
17
+ * So the delay is ours: {@link delayMs} after the pointer arrives, or at once on keyboard
18
+ * focus, and the anchor is a span around the control, which receives the pointer even when the
19
+ * control inside it is disabled (`.hmm-toolbar-button:disabled` has `pointer-events: none`
20
+ * for that). The bubble, its placement and its delay are shared with the grid's cut-off cells
21
+ *.
22
+ *
23
+ * The text is also on the anchor as `data-tooltip`, which is what a test that only wants to
24
+ * know *what* a control would say reads - the `title` attribute used to be that seam.
25
+ */
26
+ interface Props {
27
+ /** What the tooltip says; empty means no tooltip at all. */
28
+ text: string;
29
+ /** How long the pointer has to rest before it appears. */
30
+ delayMs?: number;
31
+ children: Snippet;
32
+ testId?: string | undefined;
33
+ }
34
+
35
+ let {text, delayMs = TOOLTIP_DELAY_MS, children, testId = undefined}: Props = $props();
36
+
37
+ let rect = $state<TooltipAnchor | undefined>(undefined);
38
+ let anchor = $state<HTMLElement | undefined>(undefined);
39
+ let timer: ReturnType<typeof setTimeout> | undefined;
40
+
41
+ function show(): void {
42
+ if (text === '' || !anchor) {
43
+ return;
44
+ }
45
+ const {left, top, bottom} = anchor.getBoundingClientRect();
46
+ rect = {left, top, bottom};
47
+ }
48
+
49
+ function schedule(): void {
50
+ if (text === '' || rect !== undefined) {
51
+ return;
52
+ }
53
+ clear();
54
+ timer = setTimeout(show, delayMs);
55
+ }
56
+
57
+ function clear(): void {
58
+ if (timer !== undefined) {
59
+ clearTimeout(timer);
60
+ timer = undefined;
61
+ }
62
+ }
63
+
64
+ function hide(): void {
65
+ clear();
66
+ rect = undefined;
67
+ }
68
+
69
+ $effect(() => clear);
70
+ </script>
71
+
72
+ <!--
73
+ A span, not a button: it only listens, and it must not become a tab stop or a second control -
74
+ the interactive thing is the button inside it, which keeps its own role and label. `focusin`/`focusout` bubble out of the control inside
75
+ it, so the keyboard gets the tooltip without a delay, and Escape closes it the way it closes
76
+ every other transient thing in this app.
77
+ -->
78
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
79
+ <span
80
+ class="hmm-tooltip-anchor"
81
+ bind:this={anchor}
82
+ data-testid={testId}
83
+ data-tooltip={text === '' ? undefined : text}
84
+ onpointerenter={schedule}
85
+ onpointerleave={hide}
86
+ onpointerdown={hide}
87
+ onfocusin={show}
88
+ onfocusout={hide}
89
+ onkeydown={(event) => {
90
+ if (event.key === 'Escape') {
91
+ hide();
92
+ }
93
+ }}
94
+ >
95
+ {@render children()}
96
+ {#if rect !== undefined && text !== ''}
97
+ <TooltipBubble {text} anchor={rect} />
98
+ {/if}
99
+ </span>
100
+
101
+ <style>
102
+ .hmm-tooltip-anchor {
103
+ display: inline-flex;
104
+ align-items: center;
105
+ }
106
+ </style>
@@ -0,0 +1,31 @@
1
+ import type { Snippet } from 'svelte';
2
+ /**
3
+ * The tooltip of the toolbar buttons.
4
+ *
5
+ * 2.x and 3.0 up to `3.0.0-beta.8` used the `title` attribute, which hands the whole job to
6
+ * the browser - and the browser decides when to show it. On macOS that wait was measured at
7
+ * four to five seconds by the reporter while it is a few hundred milliseconds elsewhere, and
8
+ * on a **disabled** button there is no tooltip at all: a disabled control dispatches no
9
+ * pointer events, so the `reason` a button is greyed out - the one text the user needs there -
10
+ * was exactly the one that never appeared.
11
+ *
12
+ * So the delay is ours: {@link delayMs} after the pointer arrives, or at once on keyboard
13
+ * focus, and the anchor is a span around the control, which receives the pointer even when the
14
+ * control inside it is disabled (`.hmm-toolbar-button:disabled` has `pointer-events: none`
15
+ * for that). The bubble, its placement and its delay are shared with the grid's cut-off cells
16
+ *.
17
+ *
18
+ * The text is also on the anchor as `data-tooltip`, which is what a test that only wants to
19
+ * know *what* a control would say reads - the `title` attribute used to be that seam.
20
+ */
21
+ interface Props {
22
+ /** What the tooltip says; empty means no tooltip at all. */
23
+ text: string;
24
+ /** How long the pointer has to rest before it appears. */
25
+ delayMs?: number;
26
+ children: Snippet;
27
+ testId?: string | undefined;
28
+ }
29
+ declare const Tooltip: import("svelte").Component<Props, {}, "">;
30
+ type Tooltip = ReturnType<typeof Tooltip>;
31
+ export default Tooltip;
@@ -0,0 +1,65 @@
1
+ <script lang="ts">
2
+ import {placeTooltip, type TooltipAnchor} from './tooltip.js';
3
+
4
+ /**
5
+ * The bubble of the app's own tooltip: what `Tooltip` shows next to a toolbar
6
+ * button, and what a grid shows next to a cell whose text is cut off.
7
+ *
8
+ * Positioned `fixed` from the anchor's rectangle so no `overflow` of a toolbar or a table clips
9
+ * it, below the anchor unless that runs past the bottom of the window. The caller must render it
10
+ * outside anything with a `transform` - the grid's row window has one, and a fixed element
11
+ * inside a transformed one is positioned against that instead of the window.
12
+ */
13
+ interface Props {
14
+ text: string;
15
+ anchor: TooltipAnchor;
16
+ testId?: string | undefined;
17
+ }
18
+
19
+ let {text, anchor, testId = undefined}: Props = $props();
20
+
21
+ let bubble = $state<HTMLSpanElement | undefined>(undefined);
22
+ let height = $state(0);
23
+
24
+ const position = $derived(placeTooltip(anchor, {width: window.innerWidth, height: window.innerHeight}, height));
25
+
26
+ $effect(() => {
27
+ // measured again whenever the text changes, because that is what changes the height
28
+ void text;
29
+ if (bubble) {
30
+ height = bubble.offsetHeight;
31
+ }
32
+ });
33
+ </script>
34
+
35
+ <span
36
+ class="hmm-tooltip"
37
+ role="tooltip"
38
+ bind:this={bubble}
39
+ data-testid={testId}
40
+ style:left={`${String(position.left)}px`}
41
+ style:top={`${String(position.top)}px`}>{text}</span
42
+ >
43
+
44
+ <style>
45
+ .hmm-tooltip {
46
+ position: fixed;
47
+ z-index: 1000;
48
+ max-width: 280px;
49
+ padding: 3px 6px;
50
+ border: 1px solid var(--hmm-border-strong);
51
+ border-radius: var(--hmm-radius);
52
+ background: var(--hmm-bg);
53
+ color: var(--hmm-fg);
54
+ font-size: var(--hmm-font-size-small);
55
+ font-weight: normal;
56
+ letter-spacing: normal;
57
+ line-height: 1.35;
58
+ text-align: left;
59
+ white-space: normal;
60
+ /* an address or a type has no space to wrap at */
61
+ overflow-wrap: anywhere;
62
+ pointer-events: none;
63
+ box-shadow: var(--hmm-shadow-menu);
64
+ }
65
+ </style>
@@ -0,0 +1,18 @@
1
+ import { type TooltipAnchor } from './tooltip.js';
2
+ /**
3
+ * The bubble of the app's own tooltip: what `Tooltip` shows next to a toolbar
4
+ * button, and what a grid shows next to a cell whose text is cut off.
5
+ *
6
+ * Positioned `fixed` from the anchor's rectangle so no `overflow` of a toolbar or a table clips
7
+ * it, below the anchor unless that runs past the bottom of the window. The caller must render it
8
+ * outside anything with a `transform` - the grid's row window has one, and a fixed element
9
+ * inside a transformed one is positioned against that instead of the window.
10
+ */
11
+ interface Props {
12
+ text: string;
13
+ anchor: TooltipAnchor;
14
+ testId?: string | undefined;
15
+ }
16
+ declare const TooltipBubble: import("svelte").Component<Props, {}, "">;
17
+ type TooltipBubble = ReturnType<typeof TooltipBubble>;
18
+ export default TooltipBubble;
@@ -0,0 +1,19 @@
1
+ /** One entry of {@link ContextMenu}; a separator has no label. */
2
+ export interface ContextMenuItem {
3
+ readonly id: string;
4
+ readonly label?: string;
5
+ readonly separator?: boolean;
6
+ readonly disabled?: boolean;
7
+ readonly danger?: boolean;
8
+ }
9
+ /** Keeps a menu inside the viewport, the way jQuery UI's `position` collision handling did. */
10
+ export declare function clampMenuPosition(x: number, y: number, menu: {
11
+ width: number;
12
+ height: number;
13
+ }, viewport: {
14
+ width: number;
15
+ height: number;
16
+ }, margin?: number): {
17
+ x: number;
18
+ y: number;
19
+ };
@@ -0,0 +1,6 @@
1
+ /** Keeps a menu inside the viewport, the way jQuery UI's `position` collision handling did. */
2
+ export function clampMenuPosition(x, y, menu, viewport, margin = 4) {
3
+ const maxX = Math.max(margin, viewport.width - menu.width - margin);
4
+ const maxY = Math.max(margin, viewport.height - menu.height - margin);
5
+ return { x: Math.min(Math.max(margin, x), maxX), y: Math.min(Math.max(margin, y), maxY) };
6
+ }
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Where a dialog sits and how big it is once the user has said so.
3
+ *
4
+ * A dialog is dragged by its title bar and resized by its
5
+ * edges and its bottom-right corner, and the geometry it ends up with is remembered *per dialog
6
+ * class* - open the paramset editor again and it is where you left it, the way every window manager
7
+ * behaves. Remembered for the session only: this module is plain module state, nothing writes to
8
+ * `localStorage`, and a reload starts from the designed size again. A geometry that outlived the
9
+ * page would follow a user onto a smaller screen and hide the buttons.
10
+ *
11
+ * The arithmetic is here rather than in the component because it is the part with the rules in it -
12
+ * the minimum that keeps a dialog usable, the viewport that bounds the maximum, and the edge that
13
+ * stays put while the opposite one moves. None of it needs a DOM.
14
+ */
15
+ /** A dialog's box in viewport coordinates, in CSS pixels. */
16
+ export interface DialogBox {
17
+ readonly left: number;
18
+ readonly top: number;
19
+ readonly width: number;
20
+ readonly height: number;
21
+ }
22
+ export interface Viewport {
23
+ readonly width: number;
24
+ readonly height: number;
25
+ }
26
+ /** Below this a dialog is a frame with no content in it; each dialog class may ask for more. */
27
+ export interface SizeLimits {
28
+ readonly minWidth: number;
29
+ readonly minHeight: number;
30
+ }
31
+ /**
32
+ * The handles. The four edges plus the bottom-right corner is what is asked for, and
33
+ * `se` is the one corner a pointer finds without aiming.
34
+ */
35
+ export type ResizeEdge = 'n' | 'e' | 's' | 'w' | 'se';
36
+ export declare const DEFAULT_LIMITS: SizeLimits;
37
+ /** What a dialog leaves free around itself: its CSS `max-height` is `100vh` minus this. */
38
+ export declare const VIEWPORT_MARGIN = 32;
39
+ /**
40
+ * The limits of a drag on this window.
41
+ *
42
+ * `resizeDialog` lets the minimum win over the viewport, which was harmless while no dialog asked
43
+ * for more than 320 px. A wide dialog asks for 650, and on a 640 px phone the
44
+ * first touch on an edge would have made it 650 tall and pushed its buttons off the screen. So the
45
+ * height floor is capped the way the opened dialog is, at the viewport minus the margin; the width
46
+ * floor is left as it is.
47
+ */
48
+ export declare function fitLimits(limits: SizeLimits, viewport: Viewport): SizeLimits;
49
+ /** Dragged by the title bar: the size never changes, and the box never leaves the viewport. */
50
+ export declare function moveDialog(box: DialogBox, dx: number, dy: number, viewport: Viewport): DialogBox;
51
+ /**
52
+ * Dragged by an edge or the corner.
53
+ *
54
+ * The edge the pointer holds is the one that moves; the opposite one stays where it is, which is
55
+ * why `w` and `n` recompute `left`/`top` from the far edge after the size was clamped. The size is
56
+ * bounded below by the dialog class's minimum and above by the viewport, so a dialog can neither be
57
+ * squeezed into a title bar nor be dragged bigger than the window that has to show it.
58
+ */
59
+ export declare function resizeDialog(box: DialogBox, edge: ResizeEdge, dx: number, dy: number, viewport: Viewport, limits?: SizeLimits): DialogBox;
60
+ /** Half the window is what the drawer opens at. */
61
+ export declare const PANEL_DEFAULT_FRACTION = 0.5;
62
+ /** Below this the drawer is a title bar with one row under it. */
63
+ export declare const PANEL_MIN_HEIGHT = 120;
64
+ /**
65
+ * How tall the drawer may be.
66
+ *
67
+ * The maximum is the viewport minus whatever stays above it - the header - so the drawer can never
68
+ * push the tab bar and the interface picker off the screen. On a window too short for even the
69
+ * minimum the minimum wins: a drawer squeezed to nothing is a drawer that cannot be closed again,
70
+ * because its close button is in the part that was squeezed away.
71
+ */
72
+ export declare function panelLimits(viewportHeight: number, reservedHeight: number): {
73
+ min: number;
74
+ max: number;
75
+ };
76
+ /** What the drawer opens at: half the viewport, inside the limits. */
77
+ export declare function defaultPanelHeight(viewportHeight: number, reservedHeight: number): number;
78
+ /**
79
+ * Dragged by the top edge.
80
+ *
81
+ * The drawer's bottom is the window's bottom, so the top edge moving up by `dy` makes the drawer
82
+ * `dy` taller - hence the minus. A drag that would take it past a limit stops at the limit rather
83
+ * than being ignored, which is what makes the edge feel like it hits a wall instead of sticking.
84
+ */
85
+ export declare function resizePanel(height: number, dy: number, viewportHeight: number, reservedHeight: number): number;
86
+ export declare function rememberPanelHeight(key: string, height: number): void;
87
+ export declare function recallPanelHeight(key: string): number | undefined;
88
+ export declare function rememberDialog(key: string, box: DialogBox): void;
89
+ export declare function recallDialog(key: string): DialogBox | undefined;
90
+ /** Only for tests: one test's dragged dialog - or drawer - is not the next one's starting point. */
91
+ export declare function forgetDialogGeometry(): void;
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Where a dialog sits and how big it is once the user has said so.
3
+ *
4
+ * A dialog is dragged by its title bar and resized by its
5
+ * edges and its bottom-right corner, and the geometry it ends up with is remembered *per dialog
6
+ * class* - open the paramset editor again and it is where you left it, the way every window manager
7
+ * behaves. Remembered for the session only: this module is plain module state, nothing writes to
8
+ * `localStorage`, and a reload starts from the designed size again. A geometry that outlived the
9
+ * page would follow a user onto a smaller screen and hide the buttons.
10
+ *
11
+ * The arithmetic is here rather than in the component because it is the part with the rules in it -
12
+ * the minimum that keeps a dialog usable, the viewport that bounds the maximum, and the edge that
13
+ * stays put while the opposite one moves. None of it needs a DOM.
14
+ */
15
+ export const DEFAULT_LIMITS = { minWidth: 320, minHeight: 160 };
16
+ /** What a dialog leaves free around itself: its CSS `max-height` is `100vh` minus this. */
17
+ export const VIEWPORT_MARGIN = 32;
18
+ /**
19
+ * The limits of a drag on this window.
20
+ *
21
+ * `resizeDialog` lets the minimum win over the viewport, which was harmless while no dialog asked
22
+ * for more than 320 px. A wide dialog asks for 650, and on a 640 px phone the
23
+ * first touch on an edge would have made it 650 tall and pushed its buttons off the screen. So the
24
+ * height floor is capped the way the opened dialog is, at the viewport minus the margin; the width
25
+ * floor is left as it is.
26
+ */
27
+ export function fitLimits(limits, viewport) {
28
+ return { ...limits, minHeight: Math.max(0, Math.min(limits.minHeight, viewport.height - VIEWPORT_MARGIN)) };
29
+ }
30
+ function clamp(value, low, high) {
31
+ return Math.min(Math.max(value, low), Math.max(low, high));
32
+ }
33
+ /** Keeps a box inside the viewport without changing its size. */
34
+ function place(box, viewport) {
35
+ return {
36
+ ...box,
37
+ left: Math.round(clamp(box.left, 0, viewport.width - box.width)),
38
+ top: Math.round(clamp(box.top, 0, viewport.height - box.height)),
39
+ };
40
+ }
41
+ /** Dragged by the title bar: the size never changes, and the box never leaves the viewport. */
42
+ export function moveDialog(box, dx, dy, viewport) {
43
+ return place({ ...box, left: box.left + dx, top: box.top + dy }, viewport);
44
+ }
45
+ /**
46
+ * Dragged by an edge or the corner.
47
+ *
48
+ * The edge the pointer holds is the one that moves; the opposite one stays where it is, which is
49
+ * why `w` and `n` recompute `left`/`top` from the far edge after the size was clamped. The size is
50
+ * bounded below by the dialog class's minimum and above by the viewport, so a dialog can neither be
51
+ * squeezed into a title bar nor be dragged bigger than the window that has to show it.
52
+ */
53
+ export function resizeDialog(box, edge, dx, dy, viewport, limits = DEFAULT_LIMITS) {
54
+ const right = box.left + box.width;
55
+ const bottom = box.top + box.height;
56
+ const west = edge === 'w';
57
+ const north = edge === 'n';
58
+ const horizontal = west || edge === 'e' || edge === 'se';
59
+ const vertical = north || edge === 's' || edge === 'se';
60
+ const maxWidth = Math.max(limits.minWidth, west ? right : viewport.width - box.left);
61
+ const maxHeight = Math.max(limits.minHeight, north ? bottom : viewport.height - box.top);
62
+ const width = horizontal
63
+ ? Math.round(clamp(box.width + (west ? -dx : dx), limits.minWidth, Math.min(maxWidth, viewport.width)))
64
+ : box.width;
65
+ const height = vertical
66
+ ? Math.round(clamp(box.height + (north ? -dy : dy), limits.minHeight, Math.min(maxHeight, viewport.height)))
67
+ : box.height;
68
+ return place({
69
+ left: west ? right - width : box.left,
70
+ top: north ? bottom - height : box.top,
71
+ width,
72
+ height,
73
+ }, viewport);
74
+ }
75
+ /*
76
+ * The bottom drawer - the RPC log panel.
77
+ *
78
+ * A drawer is not a dialog: it is glued to the bottom edge, it has one dimension the user can
79
+ * change and one handle to change it with. The clamping is the same problem, though, so it is the
80
+ * same arithmetic here rather than a second set of rules in the component: a minimum that keeps
81
+ * the drawer usable, a maximum that leaves the application visible, and no DOM.
82
+ */
83
+ /** Half the window is what the drawer opens at. */
84
+ export const PANEL_DEFAULT_FRACTION = 0.5;
85
+ /** Below this the drawer is a title bar with one row under it. */
86
+ export const PANEL_MIN_HEIGHT = 120;
87
+ /**
88
+ * How tall the drawer may be.
89
+ *
90
+ * The maximum is the viewport minus whatever stays above it - the header - so the drawer can never
91
+ * push the tab bar and the interface picker off the screen. On a window too short for even the
92
+ * minimum the minimum wins: a drawer squeezed to nothing is a drawer that cannot be closed again,
93
+ * because its close button is in the part that was squeezed away.
94
+ */
95
+ export function panelLimits(viewportHeight, reservedHeight) {
96
+ return { min: PANEL_MIN_HEIGHT, max: Math.max(PANEL_MIN_HEIGHT, viewportHeight - reservedHeight) };
97
+ }
98
+ /** What the drawer opens at: half the viewport, inside the limits. */
99
+ export function defaultPanelHeight(viewportHeight, reservedHeight) {
100
+ const { min, max } = panelLimits(viewportHeight, reservedHeight);
101
+ return Math.round(clamp(viewportHeight * PANEL_DEFAULT_FRACTION, min, max));
102
+ }
103
+ /**
104
+ * Dragged by the top edge.
105
+ *
106
+ * The drawer's bottom is the window's bottom, so the top edge moving up by `dy` makes the drawer
107
+ * `dy` taller - hence the minus. A drag that would take it past a limit stops at the limit rather
108
+ * than being ignored, which is what makes the edge feel like it hits a wall instead of sticking.
109
+ */
110
+ export function resizePanel(height, dy, viewportHeight, reservedHeight) {
111
+ const { min, max } = panelLimits(viewportHeight, reservedHeight);
112
+ return Math.round(clamp(height - dy, min, max));
113
+ }
114
+ /** What the drawer was left at, for as long as the page lives - same rule as a dialog's box. */
115
+ const rememberedPanels = new Map();
116
+ export function rememberPanelHeight(key, height) {
117
+ rememberedPanels.set(key, height);
118
+ }
119
+ export function recallPanelHeight(key) {
120
+ return rememberedPanels.get(key);
121
+ }
122
+ /**
123
+ * What each dialog class was left at, for as long as the page lives.
124
+ *
125
+ * Keyed by the dialog's `data-testid`, which is the one identifier every dialog in this app already
126
+ * has and which does not change with the device the dialog was opened on - "the paramset editor",
127
+ * not "the paramset editor of MEQ0123456:1".
128
+ */
129
+ const remembered = new Map();
130
+ export function rememberDialog(key, box) {
131
+ remembered.set(key, box);
132
+ }
133
+ export function recallDialog(key) {
134
+ return remembered.get(key);
135
+ }
136
+ /** Only for tests: one test's dragged dialog - or drawer - is not the next one's starting point. */
137
+ export function forgetDialogGeometry() {
138
+ remembered.clear();
139
+ rememberedPanels.clear();
140
+ }
@@ -0,0 +1,22 @@
1
+ export * from './contextMenu.js';
2
+ export * from './dialogGeometry.js';
3
+ export * from './multiSelect.js';
4
+ export * from './navigation.js';
5
+ export * from './tooltip.js';
6
+ export { default as ContextMenu } from './ContextMenu.svelte';
7
+ export { default as DataTable } from './DataTable.svelte';
8
+ export { default as Dialog } from './Dialog.svelte';
9
+ export { default as Header } from './Header.svelte';
10
+ export { default as GithubLink } from './GithubLink.svelte';
11
+ export { default as Icon } from './Icon.svelte';
12
+ export { default as LanguageSwitch } from './LanguageSwitch.svelte';
13
+ export { default as Loader } from './Loader.svelte';
14
+ export { default as MultiSelect } from './MultiSelect.svelte';
15
+ export { default as Notices } from './Notices.svelte';
16
+ export { default as PrimaryToolbarButton } from './PrimaryToolbarButton.svelte';
17
+ export { default as Tabs } from './Tabs.svelte';
18
+ export { default as ThemeSwitch } from './ThemeSwitch.svelte';
19
+ export { default as Toolbar } from './Toolbar.svelte';
20
+ export { default as ToolbarButton } from './ToolbarButton.svelte';
21
+ export { default as Tooltip } from './Tooltip.svelte';
22
+ export { default as TooltipBubble } from './TooltipBubble.svelte';
@@ -0,0 +1,22 @@
1
+ export * from './contextMenu.js';
2
+ export * from './dialogGeometry.js';
3
+ export * from './multiSelect.js';
4
+ export * from './navigation.js';
5
+ export * from './tooltip.js';
6
+ export { default as ContextMenu } from './ContextMenu.svelte';
7
+ export { default as DataTable } from './DataTable.svelte';
8
+ export { default as Dialog } from './Dialog.svelte';
9
+ export { default as Header } from './Header.svelte';
10
+ export { default as GithubLink } from './GithubLink.svelte';
11
+ export { default as Icon } from './Icon.svelte';
12
+ export { default as LanguageSwitch } from './LanguageSwitch.svelte';
13
+ export { default as Loader } from './Loader.svelte';
14
+ export { default as MultiSelect } from './MultiSelect.svelte';
15
+ export { default as Notices } from './Notices.svelte';
16
+ export { default as PrimaryToolbarButton } from './PrimaryToolbarButton.svelte';
17
+ export { default as Tabs } from './Tabs.svelte';
18
+ export { default as ThemeSwitch } from './ThemeSwitch.svelte';
19
+ export { default as Toolbar } from './Toolbar.svelte';
20
+ export { default as ToolbarButton } from './ToolbarButton.svelte';
21
+ export { default as Tooltip } from './Tooltip.svelte';
22
+ export { default as TooltipBubble } from './TooltipBubble.svelte';
@@ -0,0 +1,27 @@
1
+ /** One entry of {@link MultiSelect}. */
2
+ export interface MultiSelectOption {
3
+ readonly value: string;
4
+ readonly label: string;
5
+ readonly disabled?: boolean;
6
+ /**
7
+ * Small, muted text after the label on the first line - the device a channel belongs to
8
+ *. An entry with a `hint` or a `description` is drawn on two lines; one with neither
9
+ * looks exactly as before.
10
+ */
11
+ readonly hint?: string | undefined;
12
+ /** A small, muted, monospaced second line - `3: VIRTUAL_SWITCH_TRANSMITTER`. */
13
+ readonly description?: string | undefined;
14
+ }
15
+ /**
16
+ * The entries whose label, hint, description or value contains the filter text, case-insensitively.
17
+ *
18
+ * The value is searched as well because the link dialog no longer prints the address:
19
+ * someone who works by address types part of it and still finds the channel.
20
+ */
21
+ export declare function filterOptions(options: readonly MultiSelectOption[], filter: string): MultiSelectOption[];
22
+ /**
23
+ * The index the highlight moves to: `delta` steps from `from`, skipping disabled entries and
24
+ * stopping at the ends rather than wrapping (a long list is read top to bottom). Added for the
25
+ * keyboard navigation openccu-lite's port of this widget needed ; one kit.
26
+ */
27
+ export declare function step(options: readonly MultiSelectOption[], from: number, delta: number): number;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The entries whose label, hint, description or value contains the filter text, case-insensitively.
3
+ *
4
+ * The value is searched as well because the link dialog no longer prints the address:
5
+ * someone who works by address types part of it and still finds the channel.
6
+ */
7
+ export function filterOptions(options, filter) {
8
+ const needle = filter.trim().toLowerCase();
9
+ if (needle === '') {
10
+ return [...options];
11
+ }
12
+ return options.filter((option) => [option.label, option.hint, option.description, option.value].some((text) => text !== undefined && text.toLowerCase().includes(needle)));
13
+ }
14
+ /**
15
+ * The index the highlight moves to: `delta` steps from `from`, skipping disabled entries and
16
+ * stopping at the ends rather than wrapping (a long list is read top to bottom). Added for the
17
+ * keyboard navigation openccu-lite's port of this widget needed ; one kit.
18
+ */
19
+ export function step(options, from, delta) {
20
+ for (let i = from + delta; i >= 0 && i < options.length; i += delta) {
21
+ if (options[i]?.disabled !== true) {
22
+ return i;
23
+ }
24
+ }
25
+ return from;
26
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * An app's navigation as data: the places it has, and which one is open.
3
+ *
4
+ * The model is not the bar's. `Header` draws the items as the tabs of the bar on top; another
5
+ * navigation - a sidebar, a drawer - draws the same items its own way. An app that keeps its
6
+ * items, its `active` id and its `onnavigate` in one place swaps one for the other without
7
+ * touching its routes.
8
+ */
9
+ export interface NavItem {
10
+ /** Names the place; what `active` holds and `onnavigate` reports - an app's route id. */
11
+ readonly id: string;
12
+ readonly label: string;
13
+ /** Drawn after the label: "Service messages (9)". */
14
+ readonly badge?: string | number;
15
+ /**
16
+ * A glyph or a short text mark for a navigation that has room for one beside the label, or
17
+ * that shows nothing else when it is folded. The header's tabs show the label alone.
18
+ */
19
+ readonly icon?: string;
20
+ /**
21
+ * The address of the place (`#/programs`), for a navigation that draws links: a link can be
22
+ * opened in a new tab and copied. The header's tabs are buttons and only report the item.
23
+ */
24
+ readonly href?: string;
25
+ }
26
+ /** The item an id names, or `undefined` for an id the navigation does not have. */
27
+ export declare function navItem(items: readonly NavItem[], id: string): NavItem | undefined;
28
+ /**
29
+ * The id that is open: `active` when the navigation has it, otherwise the first item's - an app
30
+ * whose address names a place that is gone still shows one.
31
+ */
32
+ export declare function activeNavId(items: readonly NavItem[], active: string): string;
33
+ /** The item `delta` places after the open one, around the ends - what an arrow key or a swipe moves to. */
34
+ export declare function neighbourNavItem(items: readonly NavItem[], active: string, delta: number): NavItem | undefined;
@@ -0,0 +1,19 @@
1
+ /** The item an id names, or `undefined` for an id the navigation does not have. */
2
+ export function navItem(items, id) {
3
+ return items.find((item) => item.id === id);
4
+ }
5
+ /**
6
+ * The id that is open: `active` when the navigation has it, otherwise the first item's - an app
7
+ * whose address names a place that is gone still shows one.
8
+ */
9
+ export function activeNavId(items, active) {
10
+ return navItem(items, active)?.id ?? items[0]?.id ?? '';
11
+ }
12
+ /** The item `delta` places after the open one, around the ends - what an arrow key or a swipe moves to. */
13
+ export function neighbourNavItem(items, active, delta) {
14
+ if (items.length === 0) {
15
+ return undefined;
16
+ }
17
+ const index = Math.max(0, items.findIndex((item) => item.id === active));
18
+ return items[(((index + delta) % items.length) + items.length) % items.length];
19
+ }