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.
- package/LICENSE +21 -0
- package/README.md +290 -2
- package/THIRD_PARTY_NOTICES.md +36 -0
- package/dist/clipboard.d.ts +26 -0
- package/dist/clipboard.js +70 -0
- package/dist/components/ContextMenu.svelte +158 -0
- package/dist/components/ContextMenu.svelte.d.ts +14 -0
- package/dist/components/DataTable.svelte +1990 -0
- package/dist/components/DataTable.svelte.d.ts +154 -0
- package/dist/components/Dialog.svelte +420 -0
- package/dist/components/Dialog.svelte.d.ts +55 -0
- package/dist/components/GithubLink.svelte +74 -0
- package/dist/components/GithubLink.svelte.d.ts +16 -0
- package/dist/components/Header.svelte +196 -0
- package/dist/components/Header.svelte.d.ts +42 -0
- package/dist/components/Icon.svelte +51 -0
- package/dist/components/Icon.svelte.d.ts +12 -0
- package/dist/components/LanguageSwitch.svelte +63 -0
- package/dist/components/LanguageSwitch.svelte.d.ts +17 -0
- package/dist/components/Loader.svelte +65 -0
- package/dist/components/Loader.svelte.d.ts +9 -0
- package/dist/components/MultiSelect.svelte +467 -0
- package/dist/components/MultiSelect.svelte.d.ts +28 -0
- package/dist/components/Notices.svelte +146 -0
- package/dist/components/Notices.svelte.d.ts +16 -0
- package/dist/components/PrimaryToolbarButton.svelte +189 -0
- package/dist/components/PrimaryToolbarButton.svelte.d.ts +34 -0
- package/dist/components/Tabs.svelte +118 -0
- package/dist/components/Tabs.svelte.d.ts +16 -0
- package/dist/components/ThemeSwitch.svelte +46 -0
- package/dist/components/ThemeSwitch.svelte.d.ts +11 -0
- package/dist/components/Toolbar.svelte +57 -0
- package/dist/components/Toolbar.svelte.d.ts +11 -0
- package/dist/components/ToolbarButton.svelte +126 -0
- package/dist/components/ToolbarButton.svelte.d.ts +22 -0
- package/dist/components/Tooltip.svelte +106 -0
- package/dist/components/Tooltip.svelte.d.ts +31 -0
- package/dist/components/TooltipBubble.svelte +65 -0
- package/dist/components/TooltipBubble.svelte.d.ts +18 -0
- package/dist/components/contextMenu.d.ts +19 -0
- package/dist/components/contextMenu.js +6 -0
- package/dist/components/dialogGeometry.d.ts +91 -0
- package/dist/components/dialogGeometry.js +140 -0
- package/dist/components/index.d.ts +22 -0
- package/dist/components/index.js +22 -0
- package/dist/components/multiSelect.d.ts +27 -0
- package/dist/components/multiSelect.js +26 -0
- package/dist/components/navigation.d.ts +34 -0
- package/dist/components/navigation.js +19 -0
- package/dist/components/tooltip.d.ts +29 -0
- package/dist/components/tooltip.js +27 -0
- package/dist/css/app.css +3 -0
- package/dist/css/base.css +84 -0
- package/dist/css/tokens.css +170 -0
- package/dist/dialog/index.d.ts +6 -0
- package/dist/dialog/index.js +6 -0
- package/dist/embedding/ShellEmbedding.svelte.d.ts +27 -0
- package/dist/embedding/ShellEmbedding.svelte.js +79 -0
- package/dist/embedding/constants.d.ts +23 -0
- package/dist/embedding/constants.js +54 -0
- package/dist/embedding/index.d.ts +2 -0
- package/dist/embedding/index.js +2 -0
- package/dist/externalLink.d.ts +15 -0
- package/dist/externalLink.js +20 -0
- package/dist/format.d.ts +6 -0
- package/dist/format.js +16 -0
- package/dist/i18n/i18n.svelte.d.ts +112 -0
- package/dist/i18n/i18n.svelte.js +211 -0
- package/dist/i18n/index.d.ts +3 -0
- package/dist/i18n/index.js +3 -0
- package/dist/i18n/messages.d.ts +9 -0
- package/dist/i18n/messages.js +58 -0
- package/dist/i18n/translator.d.ts +65 -0
- package/dist/i18n/translator.js +99 -0
- package/dist/icons/index.d.ts +17 -0
- package/dist/icons/index.js +11 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +16 -0
- package/dist/notices/NoticesStore.svelte.d.ts +64 -0
- package/dist/notices/NoticesStore.svelte.js +127 -0
- package/dist/notices/index.d.ts +1 -0
- package/dist/notices/index.js +1 -0
- package/dist/storage.d.ts +11 -0
- package/dist/storage.js +27 -0
- package/dist/table/LocalColumnWidths.svelte.d.ts +32 -0
- package/dist/table/LocalColumnWidths.svelte.js +91 -0
- package/dist/table/columnMeasure.d.ts +24 -0
- package/dist/table/columnMeasure.js +82 -0
- package/dist/table/columnWidths.d.ts +60 -0
- package/dist/table/columnWidths.js +86 -0
- package/dist/table/dataTableContext.d.ts +26 -0
- package/dist/table/dataTableContext.js +16 -0
- package/dist/table/index.d.ts +6 -0
- package/dist/table/index.js +6 -0
- package/dist/table/metrics.d.ts +10 -0
- package/dist/table/metrics.js +10 -0
- package/dist/table/tableModel.d.ts +306 -0
- package/dist/table/tableModel.js +437 -0
- package/dist/theme/choices.d.ts +8 -0
- package/dist/theme/choices.js +6 -0
- package/dist/theme/index.d.ts +2 -0
- package/dist/theme/index.js +2 -0
- package/dist/theme/theme.svelte.d.ts +60 -0
- package/dist/theme/theme.svelte.js +108 -0
- package/package.json +137 -4
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
import { type DataTableColumn, type DataTableColumnGroup, type FlatRow, type SortState } from '../table/tableModel.js';
|
|
3
|
+
declare function $$render<T>(): {
|
|
4
|
+
props: {
|
|
5
|
+
rows: T[];
|
|
6
|
+
columns: DataTableColumn<T>[];
|
|
7
|
+
/**
|
|
8
|
+
* Header cells spanning several columns, in a row above the column labels (jqGrid's
|
|
9
|
+
* `setGroupHeaders`): the Funk grid puts every BidCos interface over its own columns.
|
|
10
|
+
*/
|
|
11
|
+
columnGroups?: DataTableColumnGroup[] | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* What the rows belong to - the interface, in every grid of this app. When it changes the
|
|
14
|
+
* column filters are cleared and the body scrolls to the top: a filter typed for one
|
|
15
|
+
* interface's addresses hid every device of the next one while the count still said how
|
|
16
|
+
* many there were.
|
|
17
|
+
*/
|
|
18
|
+
scope?: string | undefined;
|
|
19
|
+
/** Stable identity of a row - the address, in every grid of this app. */
|
|
20
|
+
getId: (row: T) => string;
|
|
21
|
+
/** Sub-rows of a row; a device's channels. Absent means no expander column. */
|
|
22
|
+
subRows?: ((row: T) => readonly T[]) | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* The columns of the sub-rows, when they differ from the parent's - the channel sub-grid of
|
|
25
|
+
* 2.x had its own (INDEX, TYPE, DIRECTION, roles, ...). Given, the sub-rows are drawn with
|
|
26
|
+
* these columns under their own label row; absent, a channel shares the device columns.
|
|
27
|
+
*/
|
|
28
|
+
subColumns?: DataTableColumn<T>[] | undefined;
|
|
29
|
+
/** Row height in pixels; the virtualiser needs it to be uniform. `--hmm-row-height`. */
|
|
30
|
+
rowHeight?: number;
|
|
31
|
+
/** Fixed body height. Without one the body fills its parent and is measured. */
|
|
32
|
+
height?: number | undefined;
|
|
33
|
+
overscan?: number;
|
|
34
|
+
/** Show the per-column filter row under the column labels, as the 2.x filter toolbar did. */
|
|
35
|
+
columnFilterRow?: boolean;
|
|
36
|
+
caption?: string | undefined;
|
|
37
|
+
/** What the body says when there are no rows at all. */
|
|
38
|
+
emptyText?: string;
|
|
39
|
+
/** What the body says when there are rows but the filters hide every one of them. */
|
|
40
|
+
noMatchText?: string | undefined;
|
|
41
|
+
/** The button under that text; it empties the column filters. */
|
|
42
|
+
clearFilterLabel?: string | undefined;
|
|
43
|
+
/** Replaces `countText` while a filter is active: "Showing 0 of 31". */
|
|
44
|
+
showingText?: ((shown: number, total: number) => string) | undefined;
|
|
45
|
+
filterLabel?: string | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* The tab's actions - buttons, selection controls - drawn at the left of the header band.
|
|
48
|
+
* A tab has no toolbar strip of its own above the grid any more.
|
|
49
|
+
*/
|
|
50
|
+
toolbar?: Snippet | undefined;
|
|
51
|
+
/** Accessible name of that group of actions; the caption when none is given. */
|
|
52
|
+
toolbarLabel?: string | undefined;
|
|
53
|
+
/** Right of the band, before the count: what a tab has to say about its own state. */
|
|
54
|
+
status?: Snippet | undefined;
|
|
55
|
+
/** Right of the band: "4 Geräte". */
|
|
56
|
+
countText?: string | undefined;
|
|
57
|
+
selected?: string[];
|
|
58
|
+
expanded?: string[];
|
|
59
|
+
/**
|
|
60
|
+
* The needle every filterable column is searched for, on top of the per-column fields.
|
|
61
|
+
*
|
|
62
|
+
* No control of the table draws it. It exists because a page may set it from outside: a link
|
|
63
|
+
* that opens another page already narrowed to one item, where no per-column field means
|
|
64
|
+
* "this column **or** that one".
|
|
65
|
+
*/
|
|
66
|
+
filter?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Draw a search field in the header band that edits {@link filter}: one needle over every
|
|
69
|
+
* filterable column, beside - or, with `columnFilterRow={false}`, instead of - the fields
|
|
70
|
+
* of the single columns.
|
|
71
|
+
*/
|
|
72
|
+
searchBox?: boolean;
|
|
73
|
+
/** The search field's placeholder and name; the kit's "Filter all columns" by default. */
|
|
74
|
+
searchLabel?: string | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* What the fields of the filter row hold, by column key. Bindable, like {@link filter} and
|
|
77
|
+
* {@link sort}: an app that keeps the three in its address sets them from it and writes them
|
|
78
|
+
* back when they change - a reload, a link and the back button then show the same rows.
|
|
79
|
+
*/
|
|
80
|
+
columnFilters?: Record<string, string>;
|
|
81
|
+
sort?: SortState | undefined;
|
|
82
|
+
/** The user changed the sorting: a click on a column label. `undefined` is "as the rows came". */
|
|
83
|
+
onsortchange?: ((sort: SortState | undefined) => void) | undefined;
|
|
84
|
+
/** The user changed a filter: typed into a field, chose from a list, cleared them. */
|
|
85
|
+
onfilterchange?: ((filters: {
|
|
86
|
+
filter: string;
|
|
87
|
+
columnFilters: Record<string, string>;
|
|
88
|
+
}) => void) | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* The locale text is sorted in. German by default (`DEFAULT_COLLATION`), which is the same
|
|
91
|
+
* order for English text, so a table has one order on every machine.
|
|
92
|
+
*/
|
|
93
|
+
locale?: string | undefined;
|
|
94
|
+
/** The first choice of a column's filter list, which filters nothing; the kit's "All". */
|
|
95
|
+
allLabel?: string | undefined;
|
|
96
|
+
/** A test id for a row, where a page's tests name its rows. */
|
|
97
|
+
rowTestId?: ((row: T) => string | undefined) | undefined;
|
|
98
|
+
/** Extra classes for a row - a row the page draws paler. The rules for them are the page's. */
|
|
99
|
+
rowClass?: ((row: T) => string | undefined) | undefined;
|
|
100
|
+
/** Double click, or Enter on the focused row. */
|
|
101
|
+
onactivate?: ((row: T) => void) | undefined;
|
|
102
|
+
/** Right click on a row; the table has already called `preventDefault()`. */
|
|
103
|
+
onrowcontextmenu?: ((row: T, event: MouseEvent) => void) | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* The column whose cell renames its row on a double click - the name, in every grid
|
|
106
|
+
* of this app. A double click anywhere else on the row still goes to `onactivate`.
|
|
107
|
+
*/
|
|
108
|
+
renameColumn?: string;
|
|
109
|
+
/** Whether a row can be renamed at all; absent, every row can. The `:0` channel cannot. */
|
|
110
|
+
canRename?: ((row: T) => boolean) | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* Opens the rename dialog for a row - on a double click on its name cell, on F2, and
|
|
113
|
+
* on Enter where the table has no `onactivate`. Absent, the table renames nothing.
|
|
114
|
+
*/
|
|
115
|
+
onrename?: ((row: T) => void) | undefined;
|
|
116
|
+
/** Draws one cell; without it the cell is the column's text value. */
|
|
117
|
+
cell?: Snippet<[T, DataTableColumn<T>, FlatRow<T>]> | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* The name the column widths of this table are kept under, per profile.
|
|
120
|
+
* A storage key rather than a test id, so it stays the same when a test id is renamed.
|
|
121
|
+
* Without one - or outside the app - the widths last as long as the table does.
|
|
122
|
+
*/
|
|
123
|
+
tableId?: string | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* The name the widths of the columns only the sub-grid has are kept under -
|
|
126
|
+
* `devices-channels`, `radio-peers`. Every expanded sub-grid of the table is drawn on the
|
|
127
|
+
* one template, so one width applies to all of them. Without one they last as long as the
|
|
128
|
+
* table does.
|
|
129
|
+
*/
|
|
130
|
+
subTableId?: string | undefined;
|
|
131
|
+
testId?: string | undefined;
|
|
132
|
+
};
|
|
133
|
+
exports: {};
|
|
134
|
+
bindings: "selected" | "expanded" | "filter" | "columnFilters" | "sort";
|
|
135
|
+
slots: {};
|
|
136
|
+
events: {};
|
|
137
|
+
};
|
|
138
|
+
declare class __sveltets_Render<T> {
|
|
139
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
140
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
141
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
142
|
+
bindings(): "selected" | "expanded" | "filter" | "columnFilters" | "sort";
|
|
143
|
+
exports(): {};
|
|
144
|
+
}
|
|
145
|
+
interface $$IsomorphicComponent {
|
|
146
|
+
new <T>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
147
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
148
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
149
|
+
<T>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
150
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
151
|
+
}
|
|
152
|
+
declare const DataTable: $$IsomorphicComponent;
|
|
153
|
+
type DataTable<T> = InstanceType<typeof DataTable<T>>;
|
|
154
|
+
export default DataTable;
|
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import {t as kitT} from '../i18n/i18n.svelte.js';
|
|
3
|
+
import type {Snippet} from 'svelte';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
DEFAULT_LIMITS,
|
|
7
|
+
VIEWPORT_MARGIN,
|
|
8
|
+
fitLimits,
|
|
9
|
+
moveDialog,
|
|
10
|
+
recallDialog,
|
|
11
|
+
rememberDialog,
|
|
12
|
+
resizeDialog,
|
|
13
|
+
type DialogBox,
|
|
14
|
+
type ResizeEdge,
|
|
15
|
+
} from './dialogGeometry.js';
|
|
16
|
+
|
|
17
|
+
interface Props {
|
|
18
|
+
open?: boolean;
|
|
19
|
+
title?: string;
|
|
20
|
+
/** Modal by default, as every jQuery UI dialog of 2.7 was. */
|
|
21
|
+
modal?: boolean;
|
|
22
|
+
width?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Fixed height. Without one a dialog is as tall as its content, up to the viewport; with
|
|
25
|
+
* one its box does not change while it is open, whatever the content does (nothing
|
|
26
|
+
* may change size when its content or state changes). Give one to every dialog whose
|
|
27
|
+
* content can grow after it opened - the paramset and link editors.
|
|
28
|
+
*/
|
|
29
|
+
height?: string | undefined;
|
|
30
|
+
/** ESC and the close button close the dialog. Off for a dialog that must be answered. */
|
|
31
|
+
closable?: boolean;
|
|
32
|
+
onclose?: (() => void) | undefined;
|
|
33
|
+
children?: Snippet | undefined;
|
|
34
|
+
/** The button row at the bottom right. */
|
|
35
|
+
buttons?: Snippet | undefined;
|
|
36
|
+
closeLabel?: string | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* The narrowest and the shortest the user may drag this dialog class.
|
|
39
|
+
*
|
|
40
|
+
* Without a `minWidth` the minimum *is* the designed `width`: a form that was laid out for
|
|
41
|
+
* 560 px does not reflow, and dragging it narrower would give its content area a horizontal
|
|
42
|
+
* scrollbar - which a dialog must never show, not even after a resize. A dialog
|
|
43
|
+
* whose content really does reflow says how far down it goes; the paramset and link editors
|
|
44
|
+
* do, their parameter rows are two columns that shrink.
|
|
45
|
+
*/
|
|
46
|
+
minWidth?: number | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* The shortest this dialog opens at and the shortest the user may drag it, in px.
|
|
49
|
+
*
|
|
50
|
+
* Without one a dialog without a `height` is as tall as its content, and the drag floor is
|
|
51
|
+
* `DEFAULT_LIMITS.minHeight`. With one the body may be taller than its content -
|
|
52
|
+
* the "Create link" dialog opened a few rows tall and its channel lists unfolded inside that
|
|
53
|
+
* small box. Either way it stays inside the window: the minimum is `min(minHeight, 100vh -
|
|
54
|
+
* 32px)`, the same margin as the `max-height`, so a short window keeps the buttons on
|
|
55
|
+
* screen and the body scrolls. A box the user dragged replaces it.
|
|
56
|
+
*/
|
|
57
|
+
minHeight?: number | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* The distance of the top edge from the window's, for a dialog that is as tall as its
|
|
60
|
+
* content and grows while it is open. A centred one would move its top - and the control
|
|
61
|
+
* just clicked - up by half of every growth; anchored, it grows downwards only.
|
|
62
|
+
*/
|
|
63
|
+
top?: string | undefined;
|
|
64
|
+
/** Draggable by the title bar, resizable by the edges and the bottom-right corner. */
|
|
65
|
+
movable?: boolean;
|
|
66
|
+
testId?: string | undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
let {
|
|
70
|
+
open = $bindable(false),
|
|
71
|
+
title = '',
|
|
72
|
+
modal = true,
|
|
73
|
+
width = '640px',
|
|
74
|
+
height = undefined,
|
|
75
|
+
closable = true,
|
|
76
|
+
onclose = undefined,
|
|
77
|
+
children = undefined,
|
|
78
|
+
buttons = undefined,
|
|
79
|
+
closeLabel: closeLabelProp = undefined,
|
|
80
|
+
minWidth = undefined,
|
|
81
|
+
minHeight = undefined,
|
|
82
|
+
movable = true,
|
|
83
|
+
top = undefined,
|
|
84
|
+
testId = undefined,
|
|
85
|
+
}: Props = $props();
|
|
86
|
+
|
|
87
|
+
// the kit's catalogue, read reactively: a language switch re-renders it
|
|
88
|
+
const closeLabel = $derived(closeLabelProp ?? kitT('Close'));
|
|
89
|
+
|
|
90
|
+
let element = $state<HTMLDialogElement | undefined>(undefined);
|
|
91
|
+
let previouslyFocused: HTMLElement | undefined;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The box the user dragged this dialog to, or `undefined` while it is still where it was
|
|
95
|
+
* designed to be. Set, it wins over `width`/`height` and over the browser's centring; unset,
|
|
96
|
+
* nothing about the dialog changes from its laid-out size.
|
|
97
|
+
*/
|
|
98
|
+
let geometry = $state<DialogBox | undefined>(undefined);
|
|
99
|
+
/** The dialog *class*, not the dialog: what a remembered geometry is keyed by. */
|
|
100
|
+
const geometryKey = $derived(testId ?? title);
|
|
101
|
+
/** `640px` -> 640; anything else (a `min()`, a percentage) falls back to the floor. */
|
|
102
|
+
const designedWidth = $derived(Number(/^(\d+)px$/.exec(width)?.[1] ?? Number.NaN));
|
|
103
|
+
const limits = $derived({
|
|
104
|
+
minWidth:
|
|
105
|
+
minWidth ??
|
|
106
|
+
(Number.isNaN(designedWidth) ? DEFAULT_LIMITS.minWidth : Math.max(DEFAULT_LIMITS.minWidth, designedWidth)),
|
|
107
|
+
minHeight: minHeight ?? DEFAULT_LIMITS.minHeight,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Native `<dialog>` instead of jQuery UI.
|
|
112
|
+
*
|
|
113
|
+
* 2.7 stacked its dialogs by hand and jQuery UI's `_focusTabbable` then walked into a dialog
|
|
114
|
+
* that was already gone - opening a paramset dialog out of the link dialog could throw and
|
|
115
|
+
* leave the app with a modal overlay and no dialog under it. `showModal()`
|
|
116
|
+
* maintains the browser's own top layer, so two dialogs stack correctly, ESC is handled by the
|
|
117
|
+
* platform, and focus is restored by this component to whatever had it before.
|
|
118
|
+
*/
|
|
119
|
+
$effect(() => {
|
|
120
|
+
const dialog = element;
|
|
121
|
+
if (!dialog) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (open && !dialog.open) {
|
|
125
|
+
previouslyFocused = document.activeElement instanceof HTMLElement ? document.activeElement : undefined;
|
|
126
|
+
// Where the user left this dialog class last time, before it is shown, so it never
|
|
127
|
+
// appears centred and then jumps.
|
|
128
|
+
geometry = geometryKey === '' ? undefined : recallDialog(geometryKey);
|
|
129
|
+
if (modal) {
|
|
130
|
+
dialog.showModal();
|
|
131
|
+
} else {
|
|
132
|
+
dialog.show();
|
|
133
|
+
}
|
|
134
|
+
} else if (!open && dialog.open) {
|
|
135
|
+
dialog.close();
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
function close(): void {
|
|
140
|
+
open = false;
|
|
141
|
+
// Close the native dialog before the focus goes back. While a modal dialog is open
|
|
142
|
+
// everything outside it is inert, so a focus() on the opener would be dropped and the
|
|
143
|
+
// grid would depend on the browser's own restore, which comes a flush later - an F2
|
|
144
|
+
// pressed right after the dialog closed could land on nothing.
|
|
145
|
+
if (element?.open) {
|
|
146
|
+
element.close();
|
|
147
|
+
}
|
|
148
|
+
onclose?.();
|
|
149
|
+
previouslyFocused?.focus();
|
|
150
|
+
previouslyFocused = undefined;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function viewport(): {width: number; height: number} {
|
|
154
|
+
return {width: window.innerWidth, height: window.innerHeight};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* One pointer gesture, for the title bar and for every resize handle.
|
|
159
|
+
*
|
|
160
|
+
* Plain pointer events on `window` rather than a library: a drag has to keep working when the
|
|
161
|
+
* pointer leaves the handle - which it does immediately - and `window` sees the moves wherever
|
|
162
|
+
* they happen, including over the modal backdrop. The listeners live exactly as long as the
|
|
163
|
+
* gesture. Nothing here touches focus or the tab order, so the native dialog's focus trap and
|
|
164
|
+
* its ESC are exactly what they were, and the handles are `aria-hidden` divs the keyboard
|
|
165
|
+
* never reaches.
|
|
166
|
+
*/
|
|
167
|
+
function startGesture(event: PointerEvent, edge: ResizeEdge | 'move'): void {
|
|
168
|
+
const dialog = element;
|
|
169
|
+
if (!dialog || !movable || event.button !== 0) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const rect = dialog.getBoundingClientRect();
|
|
173
|
+
const start: DialogBox = {left: rect.left, top: rect.top, width: rect.width, height: rect.height};
|
|
174
|
+
const originX = event.clientX;
|
|
175
|
+
const originY = event.clientY;
|
|
176
|
+
event.preventDefault();
|
|
177
|
+
|
|
178
|
+
const onMove = (move: PointerEvent): void => {
|
|
179
|
+
const dx = move.clientX - originX;
|
|
180
|
+
const dy = move.clientY - originY;
|
|
181
|
+
geometry =
|
|
182
|
+
edge === 'move'
|
|
183
|
+
? moveDialog(start, dx, dy, viewport())
|
|
184
|
+
: resizeDialog(start, edge, dx, dy, viewport(), fitLimits(limits, viewport()));
|
|
185
|
+
};
|
|
186
|
+
const onEnd = (): void => {
|
|
187
|
+
window.removeEventListener('pointermove', onMove);
|
|
188
|
+
window.removeEventListener('pointerup', onEnd);
|
|
189
|
+
window.removeEventListener('pointercancel', onEnd);
|
|
190
|
+
if (geometry && geometryKey !== '') {
|
|
191
|
+
rememberDialog(geometryKey, geometry);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
window.addEventListener('pointermove', onMove);
|
|
195
|
+
window.addEventListener('pointerup', onEnd);
|
|
196
|
+
window.addEventListener('pointercancel', onEnd);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** The close button is inside the title bar and must not start a drag. */
|
|
200
|
+
function onTitleBarPointerDown(event: PointerEvent): void {
|
|
201
|
+
if ((event.target as HTMLElement).closest('button') !== null) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
startGesture(event, 'move');
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const EDGES: readonly ResizeEdge[] = ['n', 'e', 's', 'w', 'se'];
|
|
208
|
+
|
|
209
|
+
function onCancel(event: Event): void {
|
|
210
|
+
// ESC. A dialog that is not closable stays open, which is what the 2.x "RPC execution"
|
|
211
|
+
// dialog did while a call was running.
|
|
212
|
+
event.preventDefault();
|
|
213
|
+
if (closable) {
|
|
214
|
+
close();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
</script>
|
|
218
|
+
|
|
219
|
+
<dialog
|
|
220
|
+
bind:this={element}
|
|
221
|
+
class="hmm-dialog"
|
|
222
|
+
class:hmm-dialog-placed={geometry !== undefined}
|
|
223
|
+
style:width={geometry === undefined ? width : `${geometry.width}px`}
|
|
224
|
+
style:height={geometry === undefined ? height : `${geometry.height}px`}
|
|
225
|
+
style:min-height={geometry === undefined && minHeight !== undefined
|
|
226
|
+
? `min(${minHeight}px, calc(100vh - ${VIEWPORT_MARGIN}px))`
|
|
227
|
+
: undefined}
|
|
228
|
+
style:margin-top={geometry === undefined ? top : undefined}
|
|
229
|
+
style:max-height={geometry === undefined && top !== undefined
|
|
230
|
+
? `calc(100vh - ${top} - ${VIEWPORT_MARGIN / 2}px)`
|
|
231
|
+
: undefined}
|
|
232
|
+
style:left={geometry === undefined ? undefined : `${geometry.left}px`}
|
|
233
|
+
style:top={geometry === undefined ? undefined : `${geometry.top}px`}
|
|
234
|
+
data-testid={testId}
|
|
235
|
+
aria-label={title === '' ? undefined : title}
|
|
236
|
+
oncancel={onCancel}
|
|
237
|
+
onclose={() => {
|
|
238
|
+
if (open) {
|
|
239
|
+
close();
|
|
240
|
+
}
|
|
241
|
+
}}
|
|
242
|
+
>
|
|
243
|
+
<!-- The title bar is the drag handle. It carries no keyboard behaviour of its own, so the
|
|
244
|
+
dialog's focus order is the close button and then the content, as before. -->
|
|
245
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
246
|
+
<div class="hmm-dialog-titlebar" class:hmm-dialog-titlebar-movable={movable} onpointerdown={onTitleBarPointerDown}>
|
|
247
|
+
<span class="hmm-dialog-title">{title}</span>
|
|
248
|
+
{#if closable}
|
|
249
|
+
<button type="button" class="hmm-dialog-close" aria-label={closeLabel} onclick={close}>✕</button>
|
|
250
|
+
{/if}
|
|
251
|
+
</div>
|
|
252
|
+
<div class="hmm-dialog-body">
|
|
253
|
+
{#if children}{@render children()}{/if}
|
|
254
|
+
</div>
|
|
255
|
+
{#if buttons}
|
|
256
|
+
<div class="hmm-dialog-buttons">{@render buttons()}</div>
|
|
257
|
+
{/if}
|
|
258
|
+
{#if movable}
|
|
259
|
+
{#each EDGES as edge (edge)}
|
|
260
|
+
<div
|
|
261
|
+
class="hmm-dialog-resize hmm-dialog-resize-{edge}"
|
|
262
|
+
data-resize={edge}
|
|
263
|
+
aria-hidden="true"
|
|
264
|
+
onpointerdown={(event) => startGesture(event, edge)}
|
|
265
|
+
></div>
|
|
266
|
+
{/each}
|
|
267
|
+
{/if}
|
|
268
|
+
</dialog>
|
|
269
|
+
|
|
270
|
+
<style>
|
|
271
|
+
.hmm-dialog {
|
|
272
|
+
max-width: calc(100vw - 32px);
|
|
273
|
+
max-height: calc(100vh - 32px);
|
|
274
|
+
padding: 0;
|
|
275
|
+
border: 1px solid var(--hmm-border-strong);
|
|
276
|
+
border-radius: var(--hmm-radius);
|
|
277
|
+
background: var(--hmm-bg);
|
|
278
|
+
color: var(--hmm-fg);
|
|
279
|
+
font-family: var(--hmm-font);
|
|
280
|
+
font-size: var(--hmm-font-size);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/* Only while it is open: an unconditional flex display would beat the browser's own rule for a
|
|
284
|
+
closed dialog and show every one of them inside the page.
|
|
285
|
+
The title bar and the button row keep their size; the body is what scrolls, so a dialog
|
|
286
|
+
never grows a second scrollbar around a list that already has one. */
|
|
287
|
+
.hmm-dialog[open] {
|
|
288
|
+
display: flex;
|
|
289
|
+
flex-direction: column;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/* Once the user has placed it, the box is the geometry and nothing else: no centring margin,
|
|
293
|
+
and no `max-width`/`max-height` second-guessing a size that was already clamped to the
|
|
294
|
+
viewport when it was dragged. */
|
|
295
|
+
.hmm-dialog-placed {
|
|
296
|
+
margin: 0;
|
|
297
|
+
inset-inline-end: auto;
|
|
298
|
+
inset-block-end: auto;
|
|
299
|
+
max-width: none;
|
|
300
|
+
max-height: none;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
.hmm-dialog::backdrop {
|
|
304
|
+
background: var(--hmm-backdrop);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
.hmm-dialog-titlebar {
|
|
308
|
+
display: flex;
|
|
309
|
+
flex: 0 0 auto;
|
|
310
|
+
align-items: center;
|
|
311
|
+
gap: 8px;
|
|
312
|
+
padding: 4px 6px;
|
|
313
|
+
background: var(--hmm-header-bg);
|
|
314
|
+
border-bottom: 1px solid var(--hmm-border);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
.hmm-dialog-titlebar-movable {
|
|
318
|
+
cursor: move;
|
|
319
|
+
/* A drag that selects the title instead of moving the dialog is the classic annoyance. */
|
|
320
|
+
user-select: none;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
.hmm-dialog-title {
|
|
324
|
+
font-weight: bold;
|
|
325
|
+
flex: 1 1 auto;
|
|
326
|
+
overflow: hidden;
|
|
327
|
+
text-overflow: ellipsis;
|
|
328
|
+
white-space: nowrap;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
.hmm-dialog-close {
|
|
332
|
+
border: 1px solid transparent;
|
|
333
|
+
border-radius: var(--hmm-radius);
|
|
334
|
+
background: none;
|
|
335
|
+
cursor: pointer;
|
|
336
|
+
line-height: 1;
|
|
337
|
+
padding: 2px 6px;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
.hmm-dialog-close:hover {
|
|
341
|
+
border-color: var(--hmm-border);
|
|
342
|
+
background: var(--hmm-accent-bg);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
.hmm-dialog-body {
|
|
346
|
+
display: flex;
|
|
347
|
+
flex-direction: column;
|
|
348
|
+
flex: 1 1 auto;
|
|
349
|
+
min-height: 0;
|
|
350
|
+
padding: 10px;
|
|
351
|
+
overflow: auto;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/* The body is a column, so a block of the dialog's content keeps its natural height and the
|
|
355
|
+
one part that is meant to scroll (a parameter list) claims the rest with its own flex. */
|
|
356
|
+
.hmm-dialog-body > :global(*) {
|
|
357
|
+
flex-shrink: 0;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/* Wraps only when the buttons do not fit on one line - on a phone, where the German labels of
|
|
361
|
+
the "Create link" dialog ran off the left edge. Every dialog whose buttons fit looks
|
|
362
|
+
as before. */
|
|
363
|
+
.hmm-dialog-buttons {
|
|
364
|
+
display: flex;
|
|
365
|
+
flex: 0 0 auto;
|
|
366
|
+
flex-wrap: wrap;
|
|
367
|
+
justify-content: flex-end;
|
|
368
|
+
gap: 6px;
|
|
369
|
+
padding: 6px 10px;
|
|
370
|
+
border-top: 1px solid var(--hmm-border-muted);
|
|
371
|
+
background: var(--hmm-bg-sunken);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/* Invisible grips, six pixels wide, inside the frame: a handle that hangs over the edge would
|
|
375
|
+
make the dialog itself scrollable, which a dialog must never be. */
|
|
376
|
+
.hmm-dialog-resize {
|
|
377
|
+
position: absolute;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
.hmm-dialog-resize-n,
|
|
381
|
+
.hmm-dialog-resize-s {
|
|
382
|
+
left: 0;
|
|
383
|
+
right: 0;
|
|
384
|
+
height: 6px;
|
|
385
|
+
cursor: ns-resize;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
.hmm-dialog-resize-n {
|
|
389
|
+
top: 0;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
.hmm-dialog-resize-s {
|
|
393
|
+
bottom: 0;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
.hmm-dialog-resize-e,
|
|
397
|
+
.hmm-dialog-resize-w {
|
|
398
|
+
top: 0;
|
|
399
|
+
bottom: 0;
|
|
400
|
+
width: 6px;
|
|
401
|
+
cursor: ew-resize;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
.hmm-dialog-resize-e {
|
|
405
|
+
right: 0;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
.hmm-dialog-resize-w {
|
|
409
|
+
left: 0;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/* Last in the source, so the corner wins over the two edges it overlaps. */
|
|
413
|
+
.hmm-dialog-resize-se {
|
|
414
|
+
right: 0;
|
|
415
|
+
bottom: 0;
|
|
416
|
+
width: 16px;
|
|
417
|
+
height: 16px;
|
|
418
|
+
cursor: nwse-resize;
|
|
419
|
+
}
|
|
420
|
+
</style>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
interface Props {
|
|
3
|
+
open?: boolean;
|
|
4
|
+
title?: string;
|
|
5
|
+
/** Modal by default, as every jQuery UI dialog of 2.7 was. */
|
|
6
|
+
modal?: boolean;
|
|
7
|
+
width?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Fixed height. Without one a dialog is as tall as its content, up to the viewport; with
|
|
10
|
+
* one its box does not change while it is open, whatever the content does (nothing
|
|
11
|
+
* may change size when its content or state changes). Give one to every dialog whose
|
|
12
|
+
* content can grow after it opened - the paramset and link editors.
|
|
13
|
+
*/
|
|
14
|
+
height?: string | undefined;
|
|
15
|
+
/** ESC and the close button close the dialog. Off for a dialog that must be answered. */
|
|
16
|
+
closable?: boolean;
|
|
17
|
+
onclose?: (() => void) | undefined;
|
|
18
|
+
children?: Snippet | undefined;
|
|
19
|
+
/** The button row at the bottom right. */
|
|
20
|
+
buttons?: Snippet | undefined;
|
|
21
|
+
closeLabel?: string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* The narrowest and the shortest the user may drag this dialog class.
|
|
24
|
+
*
|
|
25
|
+
* Without a `minWidth` the minimum *is* the designed `width`: a form that was laid out for
|
|
26
|
+
* 560 px does not reflow, and dragging it narrower would give its content area a horizontal
|
|
27
|
+
* scrollbar - which a dialog must never show, not even after a resize. A dialog
|
|
28
|
+
* whose content really does reflow says how far down it goes; the paramset and link editors
|
|
29
|
+
* do, their parameter rows are two columns that shrink.
|
|
30
|
+
*/
|
|
31
|
+
minWidth?: number | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* The shortest this dialog opens at and the shortest the user may drag it, in px.
|
|
34
|
+
*
|
|
35
|
+
* Without one a dialog without a `height` is as tall as its content, and the drag floor is
|
|
36
|
+
* `DEFAULT_LIMITS.minHeight`. With one the body may be taller than its content -
|
|
37
|
+
* the "Create link" dialog opened a few rows tall and its channel lists unfolded inside that
|
|
38
|
+
* small box. Either way it stays inside the window: the minimum is `min(minHeight, 100vh -
|
|
39
|
+
* 32px)`, the same margin as the `max-height`, so a short window keeps the buttons on
|
|
40
|
+
* screen and the body scrolls. A box the user dragged replaces it.
|
|
41
|
+
*/
|
|
42
|
+
minHeight?: number | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* The distance of the top edge from the window's, for a dialog that is as tall as its
|
|
45
|
+
* content and grows while it is open. A centred one would move its top - and the control
|
|
46
|
+
* just clicked - up by half of every growth; anchored, it grows downwards only.
|
|
47
|
+
*/
|
|
48
|
+
top?: string | undefined;
|
|
49
|
+
/** Draggable by the title bar, resizable by the edges and the bottom-right corner. */
|
|
50
|
+
movable?: boolean;
|
|
51
|
+
testId?: string | undefined;
|
|
52
|
+
}
|
|
53
|
+
declare const Dialog: import("svelte").Component<Props, {}, "open">;
|
|
54
|
+
type Dialog = ReturnType<typeof Dialog>;
|
|
55
|
+
export default Dialog;
|