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,437 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pure part of the data table: what a column is, how a cell value is read, and how rows are
|
|
3
|
+
* filtered, sorted and flattened into what the virtualiser draws. It has no DOM in it, so all of
|
|
4
|
+
* this is tested directly rather than through a rendered grid.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The collation the tables sort text with when none is named: German, which sorts the umlauts
|
|
8
|
+
* with their base letters (ä with a) and is the same order for English text. Named rather than
|
|
9
|
+
* left to the browser, so a table has one order on every machine.
|
|
10
|
+
*/
|
|
11
|
+
export const DEFAULT_COLLATION = 'de';
|
|
12
|
+
export function cellValue(row, column) {
|
|
13
|
+
if (column.value) {
|
|
14
|
+
return column.value(row);
|
|
15
|
+
}
|
|
16
|
+
const value = row[column.key];
|
|
17
|
+
if (value === undefined || value === null) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
// "[object Object]" for an array or a struct, which is what 2.x put in the cell and what
|
|
24
|
+
// `tableModel.test.ts` pins down. Every real column has a `value` function, so this is the
|
|
25
|
+
// fallback for a column that was configured by key alone.
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string -- deliberate, see above
|
|
27
|
+
return String(value);
|
|
28
|
+
}
|
|
29
|
+
export function cellText(row, column) {
|
|
30
|
+
const value = cellValue(row, column);
|
|
31
|
+
return value === undefined ? '' : String(value);
|
|
32
|
+
}
|
|
33
|
+
export function isSortable(column) {
|
|
34
|
+
return column.sortable !== false && column.hidden !== true;
|
|
35
|
+
}
|
|
36
|
+
export function isFilterable(column) {
|
|
37
|
+
return column.filterable !== false && column.hidden !== true;
|
|
38
|
+
}
|
|
39
|
+
/** Case-insensitive "contains", which is the `cn` default search of the 2.x filter toolbar. */
|
|
40
|
+
export function matchesText(haystack, needle) {
|
|
41
|
+
return haystack.toLowerCase().includes(needle.toLowerCase());
|
|
42
|
+
}
|
|
43
|
+
/** The text a column's own filter compares: its {@link DataTableColumn.filterValue}, or the cell's text. */
|
|
44
|
+
export function filterText(row, column) {
|
|
45
|
+
if (column.filterValue === undefined) {
|
|
46
|
+
return cellText(row, column);
|
|
47
|
+
}
|
|
48
|
+
const value = column.filterValue(row);
|
|
49
|
+
return value === undefined ? '' : String(value);
|
|
50
|
+
}
|
|
51
|
+
/** What a column is sorted by: its {@link DataTableColumn.sortValue}, or the cell's value. */
|
|
52
|
+
export function sortValue(row, column) {
|
|
53
|
+
return column.sortValue === undefined ? cellValue(row, column) : column.sortValue(row);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Does a row pass a column's own filter? A text field is "contains"; a list of choices
|
|
57
|
+
* ({@link DataTableColumn.filterOptions}) is "is".
|
|
58
|
+
*/
|
|
59
|
+
export function matchesColumnFilter(row, column, needle) {
|
|
60
|
+
if (needle === '') {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
const text = filterText(row, column);
|
|
64
|
+
return column.filterOptions === undefined ? matchesText(text, needle) : text === needle;
|
|
65
|
+
}
|
|
66
|
+
/** Does a row match the search over all columns and every per-column filter? */
|
|
67
|
+
export function matchesFilters(row, columns, globalFilter, columnFilters) {
|
|
68
|
+
for (const column of columns) {
|
|
69
|
+
const needle = columnFilters[column.key];
|
|
70
|
+
if (needle !== undefined && !matchesColumnFilter(row, column, needle)) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const words = searchWords(globalFilter);
|
|
75
|
+
if (words.length === 0) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
const texts = columns.filter((column) => isFilterable(column)).map((column) => cellText(row, column).toLowerCase());
|
|
79
|
+
return words.every((word) => texts.some((text) => text.includes(word)));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The words of a search over all columns. A row matches when every one of them is somewhere in its
|
|
83
|
+
* filterable columns - "regen markise" finds the program named "Markise" that the rain triggers,
|
|
84
|
+
* and a single word is the plain "contains" it always was.
|
|
85
|
+
*/
|
|
86
|
+
export function searchWords(needle) {
|
|
87
|
+
return needle
|
|
88
|
+
.toLowerCase()
|
|
89
|
+
.split(/\s+/)
|
|
90
|
+
.filter((word) => word !== '');
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Compares two cell values. Numbers compare numerically, everything else compares as text with
|
|
94
|
+
* `localeCompare`, and an empty cell always sorts last - the 2.x grid put the nameless devices at
|
|
95
|
+
* the end, not at the top.
|
|
96
|
+
*/
|
|
97
|
+
export function compareCells(a, b, collator = tableCollator()) {
|
|
98
|
+
const aEmpty = isEmptyCell(a);
|
|
99
|
+
const bEmpty = isEmptyCell(b);
|
|
100
|
+
if (aEmpty || bEmpty) {
|
|
101
|
+
return aEmpty && bEmpty ? 0 : aEmpty ? 1 : -1;
|
|
102
|
+
}
|
|
103
|
+
if (typeof a === 'number' && typeof b === 'number') {
|
|
104
|
+
return a - b;
|
|
105
|
+
}
|
|
106
|
+
if (typeof a === 'boolean' && typeof b === 'boolean') {
|
|
107
|
+
return Number(a) - Number(b);
|
|
108
|
+
}
|
|
109
|
+
return collator.compare(String(a), String(b));
|
|
110
|
+
}
|
|
111
|
+
const collators = new Map();
|
|
112
|
+
/**
|
|
113
|
+
* The collator of a locale the way every table compares text: digits as numbers ("Kanal 2" before
|
|
114
|
+
* "Kanal 10"), case and accents only where nothing else tells two texts apart. One per locale,
|
|
115
|
+
* kept: a sort calls it for every pair.
|
|
116
|
+
*/
|
|
117
|
+
export function tableCollator(locale = DEFAULT_COLLATION) {
|
|
118
|
+
let collator = collators.get(locale);
|
|
119
|
+
if (collator === undefined) {
|
|
120
|
+
collator = new Intl.Collator(locale, { numeric: true, sensitivity: 'base' });
|
|
121
|
+
collators.set(locale, collator);
|
|
122
|
+
}
|
|
123
|
+
return collator;
|
|
124
|
+
}
|
|
125
|
+
/** An empty cell: no value, or the empty string. */
|
|
126
|
+
function isEmptyCell(value) {
|
|
127
|
+
return value === undefined || value === '';
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Filters, sorts and flattens. A parent survives the filter when it matches itself or when one of
|
|
131
|
+
* its children does, so filtering for a channel type still shows the device it belongs to.
|
|
132
|
+
*/
|
|
133
|
+
export function buildRows(options) {
|
|
134
|
+
const { rows, columns, getId, children, expanded } = options;
|
|
135
|
+
const globalFilter = options.globalFilter ?? '';
|
|
136
|
+
const columnFilters = options.columnFilters ?? {};
|
|
137
|
+
const childColumns = options.subColumns ?? columns;
|
|
138
|
+
const hasFilter = globalFilter.trim() !== '' || Object.values(columnFilters).some((value) => value !== '');
|
|
139
|
+
const kept = hasFilter
|
|
140
|
+
? rows.filter((row) => matchesFilters(row, columns, globalFilter, columnFilters) ||
|
|
141
|
+
(children?.(row) ?? []).some((child) => matchesFilters(child, childColumns, globalFilter, columnFilters)))
|
|
142
|
+
: [...rows];
|
|
143
|
+
const sort = options.sort;
|
|
144
|
+
if (sort) {
|
|
145
|
+
const column = columns.find((candidate) => candidate.key === sort.key);
|
|
146
|
+
if (column && isSortable(column)) {
|
|
147
|
+
const factor = sort.direction === 'asc' ? 1 : -1;
|
|
148
|
+
const emptyLast = column.emptyLast === true;
|
|
149
|
+
const collator = tableCollator(options.locale);
|
|
150
|
+
// `Array.prototype.sort` is stable: rows that compare equal keep the order they came in,
|
|
151
|
+
// in both directions - so a table sorted by its type keeps the order of its rows inside a type
|
|
152
|
+
kept.sort((a, b) => {
|
|
153
|
+
const aValue = sortValue(a, column);
|
|
154
|
+
const bValue = sortValue(b, column);
|
|
155
|
+
// compareCells puts an empty cell last; emptyLast keeps it there in both directions
|
|
156
|
+
if (emptyLast && (isEmptyCell(aValue) || isEmptyCell(bValue))) {
|
|
157
|
+
return compareCells(aValue, bValue, collator);
|
|
158
|
+
}
|
|
159
|
+
return factor * compareCells(aValue, bValue, collator);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const flat = [];
|
|
164
|
+
for (const row of kept) {
|
|
165
|
+
const id = getId(row);
|
|
166
|
+
const subRows = children?.(row) ?? [];
|
|
167
|
+
const isExpanded = expanded.has(id);
|
|
168
|
+
flat.push({
|
|
169
|
+
id,
|
|
170
|
+
key: id,
|
|
171
|
+
row,
|
|
172
|
+
depth: 0,
|
|
173
|
+
hasChildren: subRows.length > 0,
|
|
174
|
+
expanded: isExpanded,
|
|
175
|
+
rootId: id,
|
|
176
|
+
kind: 'row',
|
|
177
|
+
});
|
|
178
|
+
if (!isExpanded) {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (options.subHeader === true && subRows.length > 0) {
|
|
182
|
+
flat.push({
|
|
183
|
+
id: `${id}::header`,
|
|
184
|
+
key: `${id}::header`,
|
|
185
|
+
row,
|
|
186
|
+
depth: 1,
|
|
187
|
+
hasChildren: false,
|
|
188
|
+
expanded: false,
|
|
189
|
+
rootId: id,
|
|
190
|
+
kind: 'header',
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
for (const child of subRows) {
|
|
194
|
+
flat.push({
|
|
195
|
+
id: getId(child),
|
|
196
|
+
key: `${id}/${getId(child)}`,
|
|
197
|
+
row: child,
|
|
198
|
+
depth: 1,
|
|
199
|
+
hasChildren: false,
|
|
200
|
+
expanded: false,
|
|
201
|
+
rootId: id,
|
|
202
|
+
kind: 'row',
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return flat;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* The slice of rows to draw for a scroll position. `overscan` rows above and below keep the fast
|
|
210
|
+
* scroll from showing gaps.
|
|
211
|
+
*/
|
|
212
|
+
export function visibleWindow(total, scrollTop, viewportHeight, rowHeight, overscan = 6) {
|
|
213
|
+
if (total === 0 || rowHeight <= 0) {
|
|
214
|
+
return { start: 0, end: 0 };
|
|
215
|
+
}
|
|
216
|
+
const visible = Math.max(1, Math.ceil((viewportHeight <= 0 ? rowHeight : viewportHeight) / rowHeight));
|
|
217
|
+
// Clamped to the last row: a viewport that is still scrolled far down after the rows shrank
|
|
218
|
+
// (a filter was typed, an interface was switched) must not render an empty window.
|
|
219
|
+
const first = Math.max(0, Math.min(total - 1, Math.floor(scrollTop / rowHeight) - overscan));
|
|
220
|
+
const last = Math.min(total, first + visible + overscan * 2);
|
|
221
|
+
return { start: first, end: last };
|
|
222
|
+
}
|
|
223
|
+
/** The narrowest a proportional column may become before the grid starts to scroll sideways. */
|
|
224
|
+
const MIN_TRACK_PX = 56;
|
|
225
|
+
/** The weight of a column that declares no width: as much as an ordinary text column. */
|
|
226
|
+
const DEFAULT_WEIGHT = 120;
|
|
227
|
+
/** The track of the expand button in front of every row of a table with sub-rows. */
|
|
228
|
+
const EXPANDER_PX = 22;
|
|
229
|
+
/**
|
|
230
|
+
* `minmax(<min>px, <width>fr)` unless the column asked to stay fixed, or the user gave it pixels.
|
|
231
|
+
*
|
|
232
|
+
* The declared width is a weight, the way `she`'s tables give their `<col>`s a percentage under
|
|
233
|
+
* `table-layout: fixed`: the grid then fills its container exactly, whatever the window is, so
|
|
234
|
+
* there is no ragged strip on the right at one size and no horizontal scrollbar at another. The
|
|
235
|
+
* minimum keeps a text column readable; below it the grid scrolls, which is what it did before.
|
|
236
|
+
*
|
|
237
|
+
* A width the user dragged or fitted is pixels, and the columns nobody touched share what
|
|
238
|
+
* is left by their weights - so widening one column takes the room from the others, not from the
|
|
239
|
+
* window, until they are at their minimum and the grid scrolls sideways.
|
|
240
|
+
*/
|
|
241
|
+
function trackSize(track, userWidth) {
|
|
242
|
+
if (track.width === undefined && userWidth === undefined) {
|
|
243
|
+
return `minmax(${MIN_TRACK_PX}px, ${DEFAULT_WEIGHT}fr)`;
|
|
244
|
+
}
|
|
245
|
+
if (track.fixed && track.width !== undefined) {
|
|
246
|
+
return `${track.width}px`;
|
|
247
|
+
}
|
|
248
|
+
if (userWidth !== undefined) {
|
|
249
|
+
return `${userWidth}px`;
|
|
250
|
+
}
|
|
251
|
+
const width = track.width ?? DEFAULT_WEIGHT;
|
|
252
|
+
return `minmax(${proportionalMinimum(track)}px, ${width}fr)`;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* The narrowest a proportional track is drawn: the grid's minimum, or less for a column designed
|
|
256
|
+
* narrower than that - unless the column names its own (a column of two marks and
|
|
257
|
+
* button, which a shared minimum of 56 px cut off in a narrow window).
|
|
258
|
+
*/
|
|
259
|
+
function proportionalMinimum(track) {
|
|
260
|
+
if (track.minWidth !== undefined) {
|
|
261
|
+
return track.minWidth;
|
|
262
|
+
}
|
|
263
|
+
return Math.min(track.width ?? MIN_TRACK_PX, MIN_TRACK_PX);
|
|
264
|
+
}
|
|
265
|
+
/** The narrowest a track can be drawn: what the grid needs before it scrolls sideways. */
|
|
266
|
+
function trackMinimum(track, userWidth) {
|
|
267
|
+
if (track.fixed && track.width !== undefined) {
|
|
268
|
+
return track.width;
|
|
269
|
+
}
|
|
270
|
+
if (userWidth !== undefined) {
|
|
271
|
+
return userWidth;
|
|
272
|
+
}
|
|
273
|
+
return proportionalMinimum(track);
|
|
274
|
+
}
|
|
275
|
+
function trackOf(column) {
|
|
276
|
+
return {
|
|
277
|
+
key: column.key,
|
|
278
|
+
width: column.width,
|
|
279
|
+
fixed: column.fixed === true,
|
|
280
|
+
...(column.minWidth === undefined ? {} : { minWidth: column.minWidth }),
|
|
281
|
+
...(column.keepMinWidth === true && column.minWidth !== undefined ? { keepMinWidth: true } : {}),
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* The user's width as it is drawn. A column of buttons stops at its own minimum whatever is
|
|
286
|
+
* stored - a hand-edited `localStorage`, or a width from before the column had a minimum - so the
|
|
287
|
+
* drag in `DataTable` is not the only lock on that door.
|
|
288
|
+
*/
|
|
289
|
+
function drawnUserWidth(track, userWidth) {
|
|
290
|
+
if (userWidth === undefined || track.keepMinWidth !== true || track.minWidth === undefined) {
|
|
291
|
+
return userWidth;
|
|
292
|
+
}
|
|
293
|
+
return Math.max(userWidth, track.minWidth);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* The layout's template with the widths a user gave some of its columns.
|
|
297
|
+
*
|
|
298
|
+
* Fixed columns ignore a width - they keep their pixels. `minWidth` is what every row, the head and
|
|
299
|
+
* the filter row are drawn at least as wide as: when the pixels add up to more than the window, the
|
|
300
|
+
* body scrolls sideways, and a row whose box stopped at the window's edge would leave its hover and
|
|
301
|
+
* selection background behind while its cells scroll on.
|
|
302
|
+
*/
|
|
303
|
+
export function sizedTemplate(layout, widths = {}) {
|
|
304
|
+
const parts = layout.expander ? [`${EXPANDER_PX}px`] : [];
|
|
305
|
+
let minWidth = layout.expander ? EXPANDER_PX : 0;
|
|
306
|
+
for (const track of layout.tracks) {
|
|
307
|
+
const userWidth = track.fixed ? undefined : drawnUserWidth(track, widths[track.key]);
|
|
308
|
+
parts.push(trackSize(track, userWidth));
|
|
309
|
+
minWidth += trackMinimum(track, userWidth);
|
|
310
|
+
}
|
|
311
|
+
return { template: parts.join(' '), minWidth };
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* The one grid the whole table is drawn on - the device rows, the channel sub-grid and the head.
|
|
315
|
+
*
|
|
316
|
+
* The sub-grid used to get a template of its own, so a channel's Name started where the
|
|
317
|
+
* device's icon did and no column of the sub-grid stood under the column it belongs to. After
|
|
318
|
+
* the first look: "table columns are not regularly sized when the channel sub-grid is expanded".
|
|
319
|
+
*
|
|
320
|
+
* Columns are therefore merged **by key** into one track list: a key both depths know shares one
|
|
321
|
+
* track and keeps the parent's width, so expanding a device can never move a device column; a key
|
|
322
|
+
* only the sub-grid has gets a track of its own, inserted after the track its predecessor sits in,
|
|
323
|
+
* so the sub-grid keeps its reading order. A depth that has nothing for a track leaves it empty -
|
|
324
|
+
* which is why every cell is placed explicitly rather than by auto-flow.
|
|
325
|
+
*/
|
|
326
|
+
export function tableLayout(columns, subColumns, expander) {
|
|
327
|
+
const tracks = columns.filter((column) => column.hidden !== true).map((column) => trackOf(column));
|
|
328
|
+
const subKeys = [];
|
|
329
|
+
let next = 0;
|
|
330
|
+
for (const column of subColumns ?? []) {
|
|
331
|
+
if (column.hidden === true) {
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
const found = tracks.findIndex((track) => track.key === column.key);
|
|
335
|
+
if (found >= 0) {
|
|
336
|
+
next = found + 1;
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
tracks.splice(next, 0, trackOf(column));
|
|
340
|
+
subKeys.push(column.key);
|
|
341
|
+
next += 1;
|
|
342
|
+
}
|
|
343
|
+
const offset = expander ? 2 : 1;
|
|
344
|
+
const track = {};
|
|
345
|
+
for (const [index, entry] of tracks.entries()) {
|
|
346
|
+
track[entry.key] = index + offset;
|
|
347
|
+
}
|
|
348
|
+
return { template: sizedTemplate({ tracks, expander }).template, track, tracks, expander, subKeys };
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* The widths the one template is drawn with: the table's own for the columns of its
|
|
352
|
+
* rows, the sub-grid's for the columns only the sub-grid has. Each side is kept under its own table
|
|
353
|
+
* id, so an entry for a column the other side owns - a stale or hand-edited one - is left out
|
|
354
|
+
* rather than sizing that column from the wrong place.
|
|
355
|
+
*/
|
|
356
|
+
export function layoutWidths(layout, parentWidths, subWidths) {
|
|
357
|
+
const subKeys = new Set(layout.subKeys);
|
|
358
|
+
const widths = {};
|
|
359
|
+
for (const [key, width] of Object.entries(parentWidths)) {
|
|
360
|
+
if (!subKeys.has(key)) {
|
|
361
|
+
widths[key] = width;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
for (const [key, width] of Object.entries(subWidths)) {
|
|
365
|
+
if (subKeys.has(key)) {
|
|
366
|
+
widths[key] = width;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return widths;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* The spans of the group headers, on the same tracks the layout gives the columns. A group spans
|
|
373
|
+
* from its leftmost visible column to its rightmost one; a group whose columns are all hidden or
|
|
374
|
+
* unknown is dropped.
|
|
375
|
+
*/
|
|
376
|
+
export function groupSpans(groups, columns, layout) {
|
|
377
|
+
const visible = new Set(columns.filter((column) => column.hidden !== true).map((column) => column.key));
|
|
378
|
+
const spans = [];
|
|
379
|
+
for (const group of groups) {
|
|
380
|
+
const tracks = group.columns
|
|
381
|
+
.filter((key) => visible.has(key))
|
|
382
|
+
.map((key) => layout.track[key])
|
|
383
|
+
.filter((track) => track !== undefined);
|
|
384
|
+
if (tracks.length === 0) {
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
spans.push({
|
|
388
|
+
key: group.key,
|
|
389
|
+
label: group.label,
|
|
390
|
+
sublabel: group.sublabel,
|
|
391
|
+
start: Math.min(...tracks),
|
|
392
|
+
end: Math.max(...tracks) + 1,
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
return spans;
|
|
396
|
+
}
|
|
397
|
+
/** Is any filter - the outside needle or a column field - narrowing the rows? */
|
|
398
|
+
export function hasActiveFilter(globalFilter, columnFilters) {
|
|
399
|
+
return globalFilter.trim() !== '' || Object.values(columnFilters).some((value) => value.trim() !== '');
|
|
400
|
+
}
|
|
401
|
+
/** The `grid-template-columns` for a set of columns, plus the leading expander when there is one. */
|
|
402
|
+
export function gridTemplate(columns, expander) {
|
|
403
|
+
return tableLayout(columns, undefined, expander).template;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* The ids a shift-click selects: everything between the anchor and the clicked row, in the order
|
|
407
|
+
* the grid currently shows them.
|
|
408
|
+
*/
|
|
409
|
+
export function rangeIds(rows, anchorId, targetId) {
|
|
410
|
+
const anchor = rows.findIndex((row) => row.id === anchorId);
|
|
411
|
+
const target = rows.findIndex((row) => row.id === targetId);
|
|
412
|
+
if (anchor === -1 || target === -1) {
|
|
413
|
+
return target === -1 ? [] : [targetId];
|
|
414
|
+
}
|
|
415
|
+
const [from, to] = anchor <= target ? [anchor, target] : [target, anchor];
|
|
416
|
+
return rows
|
|
417
|
+
.slice(from, to + 1)
|
|
418
|
+
.filter((row) => row.kind !== 'header')
|
|
419
|
+
.map((row) => row.id);
|
|
420
|
+
}
|
|
421
|
+
/** Click, ctrl/meta-click and shift-click, as every grid in 2.7 behaved. */
|
|
422
|
+
export function nextSelection(rows, selected, anchorId, targetId, modifiers) {
|
|
423
|
+
if (modifiers.shift === true && anchorId !== undefined) {
|
|
424
|
+
return { selected: rangeIds(rows, anchorId, targetId), anchorId };
|
|
425
|
+
}
|
|
426
|
+
if (modifiers.ctrl === true) {
|
|
427
|
+
const set = new Set(selected);
|
|
428
|
+
if (set.has(targetId)) {
|
|
429
|
+
set.delete(targetId);
|
|
430
|
+
}
|
|
431
|
+
else {
|
|
432
|
+
set.add(targetId);
|
|
433
|
+
}
|
|
434
|
+
return { selected: [...set], anchorId: targetId };
|
|
435
|
+
}
|
|
436
|
+
return { selected: [targetId], anchorId: targetId };
|
|
437
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** What a theme switch stores: `system` lets `prefers-color-scheme` decide. */
|
|
2
|
+
export type ThemeChoice = 'system' | 'light' | 'dark';
|
|
3
|
+
/** The order the theme switch cycles through. */
|
|
4
|
+
export declare const THEME_CHOICES: readonly ThemeChoice[];
|
|
5
|
+
/** The theme a choice resolves to on screen. */
|
|
6
|
+
export type ResolvedTheme = 'light' | 'dark';
|
|
7
|
+
/** A theme choice, or `undefined` for anything else (a stored value from an older app, a URL parameter). */
|
|
8
|
+
export declare function themeOf(value: unknown): ThemeChoice | undefined;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** The order the theme switch cycles through. */
|
|
2
|
+
export const THEME_CHOICES = ['system', 'light', 'dark'];
|
|
3
|
+
/** A theme choice, or `undefined` for anything else (a stored value from an older app, a URL parameter). */
|
|
4
|
+
export function themeOf(value) {
|
|
5
|
+
return value === 'system' || value === 'light' || value === 'dark' ? value : undefined;
|
|
6
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type ShellEmbedding } from '../embedding/ShellEmbedding.svelte.js';
|
|
2
|
+
import { type StorageLike } from '../storage.js';
|
|
3
|
+
import { type ResolvedTheme, type ThemeChoice } from './choices.js';
|
|
4
|
+
/** `system` -> `light` -> `dark` -> `system`, the order a theme button cycles through. */
|
|
5
|
+
export declare function nextTheme(choice: ThemeChoice): ThemeChoice;
|
|
6
|
+
/**
|
|
7
|
+
* Puts a choice on the document: `light`/`dark` as `data-theme` on `<html>`, `system` as no
|
|
8
|
+
* attribute at all, so `prefers-color-scheme` in `tokens.css` decides.
|
|
9
|
+
*/
|
|
10
|
+
export declare function applyTheme(choice: ThemeChoice, root?: HTMLElement | undefined): void;
|
|
11
|
+
/**
|
|
12
|
+
* The page's theme: the app's own choice, or the shell's while the page is embedded in
|
|
13
|
+
* openccu-lite's shell and follows it.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ThemeState {
|
|
16
|
+
#private;
|
|
17
|
+
/** The app's own choice, as its switch shows it and its storage keeps it. */
|
|
18
|
+
choice: ThemeChoice;
|
|
19
|
+
/** The theme in effect: the shell's while embedded and following, the app's choice otherwise. */
|
|
20
|
+
get value(): ThemeChoice;
|
|
21
|
+
/**
|
|
22
|
+
* Whether the shell decides: an app hides its own theme switch then, because the shell has one.
|
|
23
|
+
*/
|
|
24
|
+
get followsShell(): boolean;
|
|
25
|
+
/** `light` or `dark`, with `system` resolved through `prefers-color-scheme`. Reactive. */
|
|
26
|
+
get resolved(): ResolvedTheme;
|
|
27
|
+
/** @internal set by `initTheme` */
|
|
28
|
+
follow(shell: ShellEmbedding | undefined): void;
|
|
29
|
+
}
|
|
30
|
+
export declare const theme: ThemeState;
|
|
31
|
+
export interface InitThemeOptions {
|
|
32
|
+
/** The `localStorage` key the app keeps its choice in (`myapp.theme`); none stores nothing. */
|
|
33
|
+
readonly storageKey?: string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* `shell` (the default): inside openccu-lite's shell the page shows the shell's theme and
|
|
36
|
+
* follows it. `none`: the app's own choice only - a page in a classic CCU's WebUI frame, say,
|
|
37
|
+
* which has no shell message and follows the browser unless its own choice says otherwise.
|
|
38
|
+
*/
|
|
39
|
+
readonly follow?: 'shell' | 'none';
|
|
40
|
+
/** The storage to use; `localStorage` where the browser allows it. */
|
|
41
|
+
readonly storage?: StorageLike | undefined;
|
|
42
|
+
/** The embedding to follow; the page's shared one by default. */
|
|
43
|
+
readonly shell?: ShellEmbedding | undefined;
|
|
44
|
+
/** Where `data-theme` goes; `<html>` by default. `null` leaves the document alone. */
|
|
45
|
+
readonly root?: HTMLElement | null | undefined;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Reads the stored choice, starts following the shell and keeps `data-theme` on `<html>` in step
|
|
49
|
+
* with the theme in effect. Call it once, before mounting the app. Returns a function that stops
|
|
50
|
+
* it.
|
|
51
|
+
*/
|
|
52
|
+
export declare function initTheme(options?: InitThemeOptions): () => void;
|
|
53
|
+
/** Sets and stores the app's own choice. */
|
|
54
|
+
export declare function setTheme(choice: ThemeChoice): void;
|
|
55
|
+
/** The next choice in the cycle, set and stored. */
|
|
56
|
+
export declare function cycleTheme(): void;
|
|
57
|
+
/** Is the page dark right now? Reactive. */
|
|
58
|
+
export declare function isDark(): boolean;
|
|
59
|
+
/** `light` or `dark`, right now. Reactive. */
|
|
60
|
+
export declare function resolvedTheme(): ResolvedTheme;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { MediaQuery } from 'svelte/reactivity';
|
|
2
|
+
import { shellEmbedding } from '../embedding/ShellEmbedding.svelte.js';
|
|
3
|
+
import { defaultStorage, readStored, writeStored } from '../storage.js';
|
|
4
|
+
import { THEME_CHOICES, themeOf } from './choices.js';
|
|
5
|
+
/** `system` -> `light` -> `dark` -> `system`, the order a theme button cycles through. */
|
|
6
|
+
export function nextTheme(choice) {
|
|
7
|
+
const index = THEME_CHOICES.indexOf(choice);
|
|
8
|
+
return THEME_CHOICES[(index + 1) % THEME_CHOICES.length] ?? 'system';
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Puts a choice on the document: `light`/`dark` as `data-theme` on `<html>`, `system` as no
|
|
12
|
+
* attribute at all, so `prefers-color-scheme` in `tokens.css` decides.
|
|
13
|
+
*/
|
|
14
|
+
export function applyTheme(choice, root = defaultRoot()) {
|
|
15
|
+
if (!root) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (choice === 'system') {
|
|
19
|
+
root.removeAttribute('data-theme');
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
root.setAttribute('data-theme', choice);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function defaultRoot() {
|
|
26
|
+
return typeof document === 'undefined' ? undefined : document.documentElement;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The page's theme: the app's own choice, or the shell's while the page is embedded in
|
|
30
|
+
* openccu-lite's shell and follows it.
|
|
31
|
+
*/
|
|
32
|
+
export class ThemeState {
|
|
33
|
+
/** The app's own choice, as its switch shows it and its storage keeps it. */
|
|
34
|
+
choice = $state('system');
|
|
35
|
+
#shell = $state.raw(undefined);
|
|
36
|
+
#dark;
|
|
37
|
+
/** The theme in effect: the shell's while embedded and following, the app's choice otherwise. */
|
|
38
|
+
get value() {
|
|
39
|
+
const shell = this.#shell;
|
|
40
|
+
return shell?.embedded === true && shell.theme !== undefined ? shell.theme : this.choice;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Whether the shell decides: an app hides its own theme switch then, because the shell has one.
|
|
44
|
+
*/
|
|
45
|
+
get followsShell() {
|
|
46
|
+
return this.#shell?.embedded === true;
|
|
47
|
+
}
|
|
48
|
+
/** `light` or `dark`, with `system` resolved through `prefers-color-scheme`. Reactive. */
|
|
49
|
+
get resolved() {
|
|
50
|
+
const value = this.value;
|
|
51
|
+
if (value !== 'system') {
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
this.#dark ??= new MediaQuery('(prefers-color-scheme: dark)', false);
|
|
55
|
+
return this.#dark.current ? 'dark' : 'light';
|
|
56
|
+
}
|
|
57
|
+
/** @internal set by `initTheme` */
|
|
58
|
+
follow(shell) {
|
|
59
|
+
this.#shell = shell;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export const theme = new ThemeState();
|
|
63
|
+
let setup = { storageKey: undefined, storage: undefined };
|
|
64
|
+
/**
|
|
65
|
+
* Reads the stored choice, starts following the shell and keeps `data-theme` on `<html>` in step
|
|
66
|
+
* with the theme in effect. Call it once, before mounting the app. Returns a function that stops
|
|
67
|
+
* it.
|
|
68
|
+
*/
|
|
69
|
+
export function initTheme(options = {}) {
|
|
70
|
+
setup = { storageKey: options.storageKey, storage: options.storage ?? defaultStorage() };
|
|
71
|
+
const stored = setup.storageKey === undefined ? undefined : themeOf(readStored(setup.storage, setup.storageKey));
|
|
72
|
+
theme.choice = stored ?? 'system';
|
|
73
|
+
theme.follow(options.follow === 'none' ? undefined : (options.shell ?? shellEmbedding()));
|
|
74
|
+
const root = options.root === null ? undefined : (options.root ?? defaultRoot());
|
|
75
|
+
if (root === undefined) {
|
|
76
|
+
return () => {
|
|
77
|
+
theme.follow(undefined);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const stop = $effect.root(() => {
|
|
81
|
+
$effect(() => {
|
|
82
|
+
applyTheme(theme.value, root);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
return () => {
|
|
86
|
+
stop();
|
|
87
|
+
theme.follow(undefined);
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/** Sets and stores the app's own choice. */
|
|
91
|
+
export function setTheme(choice) {
|
|
92
|
+
theme.choice = choice;
|
|
93
|
+
if (setup.storageKey !== undefined) {
|
|
94
|
+
writeStored(setup.storage, setup.storageKey, choice);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** The next choice in the cycle, set and stored. */
|
|
98
|
+
export function cycleTheme() {
|
|
99
|
+
setTheme(nextTheme(theme.choice));
|
|
100
|
+
}
|
|
101
|
+
/** Is the page dark right now? Reactive. */
|
|
102
|
+
export function isDark() {
|
|
103
|
+
return theme.resolved === 'dark';
|
|
104
|
+
}
|
|
105
|
+
/** `light` or `dark`, right now. Reactive. */
|
|
106
|
+
export function resolvedTheme() {
|
|
107
|
+
return theme.resolved;
|
|
108
|
+
}
|