occulite-ui 0.1.0 → 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/README.md +122 -3
- package/dist/components/DataTable.svelte +128 -10
- package/dist/components/DataTable.svelte.d.ts +34 -2
- package/dist/components/Header.svelte +196 -0
- package/dist/components/Header.svelte.d.ts +42 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +2 -0
- package/dist/components/navigation.d.ts +34 -0
- package/dist/components/navigation.js +19 -0
- package/dist/i18n/messages.js +1 -0
- package/dist/table/tableModel.d.ts +63 -2
- package/dist/table/tableModel.js +81 -11
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ openccu-lite's embedding contract, so a page inside the system's shell follows t
|
|
|
7
7
|
and language.
|
|
8
8
|
|
|
9
9
|
Its consumers are [homematic-manager](https://github.com/hobbyquaker/homematic-manager), the
|
|
10
|
-
system's own web interface ([occulited](https://github.com/
|
|
10
|
+
system's own web interface ([occulited](https://github.com/openccu-lite/occulited)) and the addons
|
|
11
11
|
for openccu-lite and the classic CCU.
|
|
12
12
|
|
|
13
13
|
**Status: 0.x.** The API is settling; in 0.x a minor version may break (the
|
|
@@ -60,7 +60,7 @@ mount(App, {target: document.getElementById('app')!});
|
|
|
60
60
|
|
|
61
61
|
```svelte
|
|
62
62
|
<script lang="ts">
|
|
63
|
-
import {DataTable,
|
|
63
|
+
import {DataTable, Header, Notices, ThemeSwitch} from 'occulite-ui';
|
|
64
64
|
import {NoticesStore} from 'occulite-ui/notices';
|
|
65
65
|
import {t} from 'occulite-ui/i18n';
|
|
66
66
|
import {cycleTheme, theme} from 'occulite-ui/theme';
|
|
@@ -72,7 +72,7 @@ mount(App, {target: document.getElementById('app')!});
|
|
|
72
72
|
{#if !theme.followsShell}
|
|
73
73
|
<ThemeSwitch theme={theme.choice} onclick={cycleTheme} />
|
|
74
74
|
{/if}
|
|
75
|
-
<
|
|
75
|
+
<Header title="My app" items={[{id: 'devices', label: t('Devices')}]} bind:active={tab} />
|
|
76
76
|
<DataTable rows={[]} columns={[{key: 'name', label: t('Name')}]} getId={(row) => row.id} />
|
|
77
77
|
<Notices notices={notices.visible} ondismiss={(id) => notices.dismiss(id)} />
|
|
78
78
|
```
|
|
@@ -100,6 +100,125 @@ kit's catalogue in the page's language, and re-renders when the language changes
|
|
|
100
100
|
A denser app sets `--hmm-row-height` to another height (26 px, say) and passes the same number to
|
|
101
101
|
`DataTable`'s `rowHeight`: the virtualiser needs it as a number.
|
|
102
102
|
|
|
103
|
+
### The bar on top: `Header`
|
|
104
|
+
|
|
105
|
+
`Header` is the bar homematic-manager has on top: the app's name, its places as tabs, and a group
|
|
106
|
+
of the page's own items at the right. One flat line of `--hmm-header-height` (36 px) on the header
|
|
107
|
+
ground with a hairline under it and 10 px at the sides; the tabs are as tall as the bar and lie
|
|
108
|
+
on the hairline, everything else stands in the middle of the line. Below 64rem (1024 px) the bar
|
|
109
|
+
is two such lines - the name and the items, then the tabs, which scroll in their strip and keep
|
|
110
|
+
the open one in view (`narrow={false}` keeps one line, for an app with a minimum width of its own).
|
|
111
|
+
|
|
112
|
+
```svelte
|
|
113
|
+
<script lang="ts">
|
|
114
|
+
import {Header, ThemeSwitch, type NavItem} from 'occulite-ui';
|
|
115
|
+
|
|
116
|
+
const items: NavItem[] = [
|
|
117
|
+
{id: 'programs', label: t('Programs'), href: '#/programs'},
|
|
118
|
+
{id: 'variables', label: t('System variables'), badge: alarms || undefined},
|
|
119
|
+
];
|
|
120
|
+
let active = $state('programs');
|
|
121
|
+
</script>
|
|
122
|
+
|
|
123
|
+
<Header title="Logic" {items} bind:active onnavigate={(id) => show(id)}>
|
|
124
|
+
{#snippet actions()}
|
|
125
|
+
<span class="hmm-header-text" title={version}>{version}</span>
|
|
126
|
+
<ThemeSwitch theme={theme.choice} onclick={cycleTheme} />
|
|
127
|
+
{/snippet}
|
|
128
|
+
</Header>
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
- The navigation is data: `NavItem` is `{id, label, badge?, icon?, href?}`, `active` the open id
|
|
132
|
+
(an id the items do not have shows the first), `onnavigate(id, item)` the user's choice. An app
|
|
133
|
+
that must ask before it leaves a place binds `active` to a getter and a setter
|
|
134
|
+
(`bind:active={() => tab, go}`) and decides in the setter. Nothing of the model is the bar's:
|
|
135
|
+
another navigation component - a sidebar, a drawer - takes the same three props, so an app
|
|
136
|
+
swaps one for the other without touching its routes. The header's tabs are buttons and show
|
|
137
|
+
the label and the badge; `icon` and `href` are for a navigation that has room for a mark or
|
|
138
|
+
draws links.
|
|
139
|
+
- `brand` (a snippet) replaces the name: a logo, a control of the app's own.
|
|
140
|
+
- `actions` is the group at the right. Controls keep their box (make them 24 px tall, as
|
|
141
|
+
`ThemeSwitch` and the toolbar buttons are); an element with the class `hmm-header-text` is
|
|
142
|
+
small, muted text that is cut when the line is short - give it a `title`.
|
|
143
|
+
- `activeNavId`, `navItem` and `neighbourNavItem` are the model's helpers.
|
|
144
|
+
|
|
145
|
+
### Tables: `DataTable`
|
|
146
|
+
|
|
147
|
+
One table for every app: a header band (actions at the left, a search and a count at the right),
|
|
148
|
+
the column labels, a row of filter fields, and rows of `--hmm-row-height` (30 px) in a body that
|
|
149
|
+
scrolls under a head that stays. The rows are virtualised, so the table needs a height: it fills
|
|
150
|
+
its parent (give that a height, or make it a flex item that has one), or takes `height` in pixels.
|
|
151
|
+
A column has its width (`width` as a weight, `fixed: true` for pixels, `minWidth`), so nothing
|
|
152
|
+
moves when the table is sorted or filtered; a text that does not fit is cut and whole in its
|
|
153
|
+
tooltip. When the columns need more than the table has - a phone - the body scrolls sideways
|
|
154
|
+
inside the table and the head follows; the page never does.
|
|
155
|
+
|
|
156
|
+
```svelte
|
|
157
|
+
<script lang="ts">
|
|
158
|
+
import {DataTable} from 'occulite-ui';
|
|
159
|
+
import type {DataTableColumn, SortState} from 'occulite-ui/table';
|
|
160
|
+
|
|
161
|
+
const columns: DataTableColumn<Variable>[] = [
|
|
162
|
+
{key: 'name', label: t('Name'), width: 260, minWidth: 150},
|
|
163
|
+
{
|
|
164
|
+
key: 'type',
|
|
165
|
+
label: t('Type'),
|
|
166
|
+
width: 116,
|
|
167
|
+
fixed: true,
|
|
168
|
+
value: (row) => t('type.' + row.type), // what the cell shows and the search reads
|
|
169
|
+
filterValue: (row) => row.type, // what the column's own filter compares
|
|
170
|
+
filterOptions: TYPES.map((id) => ({value: id, label: t('type.' + id)})),
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
key: 'time',
|
|
174
|
+
label: t('Last written'),
|
|
175
|
+
width: 150,
|
|
176
|
+
fixed: true,
|
|
177
|
+
value: (row) => formatDate(row.time),
|
|
178
|
+
sortValue: (row) => Date.parse(row.time), // what the column sorts by
|
|
179
|
+
emptyLast: true,
|
|
180
|
+
},
|
|
181
|
+
];
|
|
182
|
+
let sort = $state<SortState | undefined>();
|
|
183
|
+
let filter = $state('');
|
|
184
|
+
let columnFilters = $state<Record<string, string>>({});
|
|
185
|
+
</script>
|
|
186
|
+
|
|
187
|
+
<DataTable
|
|
188
|
+
{rows}
|
|
189
|
+
{columns}
|
|
190
|
+
getId={(row) => row.id}
|
|
191
|
+
bind:sort
|
|
192
|
+
bind:filter
|
|
193
|
+
bind:columnFilters
|
|
194
|
+
searchBox
|
|
195
|
+
countText={t('{n} variables', {n: rows.length})}
|
|
196
|
+
/>
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
- **Sorting.** A click on a column label sorts ascending, the next one descending, the third
|
|
200
|
+
shows the rows as they came. Numbers sort as numbers, text with German collation (`locale`,
|
|
201
|
+
`'de'` by default: umlauts with their base letters, digits as numbers - the same order for
|
|
202
|
+
English text, and the same on every machine), empty cells last (`emptyLast` keeps them last in
|
|
203
|
+
both directions). The sort is stable: rows that compare equal keep the order they came in. A
|
|
204
|
+
column that shows one thing and sorts by another names it as `sortValue`.
|
|
205
|
+
- **Filtering.** `searchBox` draws a search field in the band: every word of it has to be
|
|
206
|
+
somewhere in the row's filterable columns. The filter row (`columnFilterRow`, on by default)
|
|
207
|
+
has a field per column - "contains" - or, for a column with `filterOptions`, a list of choices
|
|
208
|
+
that matches exactly; `filterValue` is what the column's own filter compares where that is not
|
|
209
|
+
the text of the cell (an id behind a translated label). When the filters hide every row the
|
|
210
|
+
table says so and offers to clear them.
|
|
211
|
+
- **State from outside.** `sort`, `filter` and `columnFilters` are bindable props, and
|
|
212
|
+
`onsortchange` / `onfilterchange` report what the user changed. An app that keeps the three in
|
|
213
|
+
its address sets them from it and writes them back, and a reload, a link and the back button
|
|
214
|
+
show the same rows in the same order.
|
|
215
|
+
- **Cells.** Without a `cell` snippet a cell is the column's text; with one the app draws it - a
|
|
216
|
+
pill, a field, buttons - and `value` stays what is sorted, searched and filtered. `rowTestId`
|
|
217
|
+
and `rowClass` put a test id and the app's own classes on a row.
|
|
218
|
+
- **More.** Sub-rows with columns of their own, selection (click, ctrl, shift), a context menu,
|
|
219
|
+
renaming, a copy button per column, resizable columns kept by `setDataTableEnvironment`, column
|
|
220
|
+
groups: see the props of `DataTable.svelte` and `occulite-ui/table`.
|
|
221
|
+
|
|
103
222
|
### Inside openccu-lite's shell
|
|
104
223
|
|
|
105
224
|
The system frames an addon page as a same-origin iframe, puts `theme=` and `lang=` on the frame
|
|
@@ -101,7 +101,36 @@
|
|
|
101
101
|
* "this column **or** that one".
|
|
102
102
|
*/
|
|
103
103
|
filter?: string;
|
|
104
|
+
/**
|
|
105
|
+
* Draw a search field in the header band that edits {@link filter}: one needle over every
|
|
106
|
+
* filterable column, beside - or, with `columnFilterRow={false}`, instead of - the fields
|
|
107
|
+
* of the single columns.
|
|
108
|
+
*/
|
|
109
|
+
searchBox?: boolean;
|
|
110
|
+
/** The search field's placeholder and name; the kit's "Filter all columns" by default. */
|
|
111
|
+
searchLabel?: string | undefined;
|
|
112
|
+
/**
|
|
113
|
+
* What the fields of the filter row hold, by column key. Bindable, like {@link filter} and
|
|
114
|
+
* {@link sort}: an app that keeps the three in its address sets them from it and writes them
|
|
115
|
+
* back when they change - a reload, a link and the back button then show the same rows.
|
|
116
|
+
*/
|
|
117
|
+
columnFilters?: Record<string, string>;
|
|
104
118
|
sort?: SortState | undefined;
|
|
119
|
+
/** The user changed the sorting: a click on a column label. `undefined` is "as the rows came". */
|
|
120
|
+
onsortchange?: ((sort: SortState | undefined) => void) | undefined;
|
|
121
|
+
/** The user changed a filter: typed into a field, chose from a list, cleared them. */
|
|
122
|
+
onfilterchange?: ((filters: {filter: string; columnFilters: Record<string, string>}) => void) | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* The locale text is sorted in. German by default (`DEFAULT_COLLATION`), which is the same
|
|
125
|
+
* order for English text, so a table has one order on every machine.
|
|
126
|
+
*/
|
|
127
|
+
locale?: string | undefined;
|
|
128
|
+
/** The first choice of a column's filter list, which filters nothing; the kit's "All". */
|
|
129
|
+
allLabel?: string | undefined;
|
|
130
|
+
/** A test id for a row, where a page's tests name its rows. */
|
|
131
|
+
rowTestId?: ((row: T) => string | undefined) | undefined;
|
|
132
|
+
/** Extra classes for a row - a row the page draws paler. The rules for them are the page's. */
|
|
133
|
+
rowClass?: ((row: T) => string | undefined) | undefined;
|
|
105
134
|
/** Double click, or Enter on the focused row. */
|
|
106
135
|
onactivate?: ((row: T) => void) | undefined;
|
|
107
136
|
/** Right click on a row; the table has already called `preventDefault()`. */
|
|
@@ -161,7 +190,16 @@
|
|
|
161
190
|
selected = $bindable([]),
|
|
162
191
|
expanded = $bindable([]),
|
|
163
192
|
filter = $bindable(''),
|
|
193
|
+
searchBox = false,
|
|
194
|
+
searchLabel: searchLabelProp = undefined,
|
|
195
|
+
columnFilters = $bindable({}),
|
|
164
196
|
sort = $bindable(undefined),
|
|
197
|
+
onsortchange = undefined,
|
|
198
|
+
onfilterchange = undefined,
|
|
199
|
+
locale = undefined,
|
|
200
|
+
allLabel: allLabelProp = undefined,
|
|
201
|
+
rowTestId = undefined,
|
|
202
|
+
rowClass = undefined,
|
|
165
203
|
onactivate = undefined,
|
|
166
204
|
onrowcontextmenu = undefined,
|
|
167
205
|
renameColumn = 'name',
|
|
@@ -184,8 +222,9 @@
|
|
|
184
222
|
const noMatchText = $derived(noMatchTextProp ?? t('No row matches the filter'));
|
|
185
223
|
const clearFilterLabel = $derived(clearFilterLabelProp ?? t('Clear filter'));
|
|
186
224
|
const filterLabel = $derived(filterLabelProp ?? t('Filter'));
|
|
225
|
+
const searchLabel = $derived(searchLabelProp ?? t('Filter all columns'));
|
|
226
|
+
const allLabel = $derived(allLabelProp ?? t('All'));
|
|
187
227
|
|
|
188
|
-
let columnFilters = $state<Record<string, string>>({});
|
|
189
228
|
let scrollTop = $state(0);
|
|
190
229
|
let measuredHeight = $state(0);
|
|
191
230
|
let focusIndex = $state(0);
|
|
@@ -261,7 +300,7 @@
|
|
|
261
300
|
* the row underneath. It is part of the head, so it stays put while the body scrolls.
|
|
262
301
|
*/
|
|
263
302
|
const hasBand = $derived(
|
|
264
|
-
caption !== undefined || toolbar !== undefined || status !== undefined || countText !== undefined,
|
|
303
|
+
caption !== undefined || toolbar !== undefined || status !== undefined || countText !== undefined || searchBox,
|
|
265
304
|
);
|
|
266
305
|
const selectedSet = $derived(new Set(selected));
|
|
267
306
|
|
|
@@ -275,6 +314,7 @@
|
|
|
275
314
|
globalFilter: filter,
|
|
276
315
|
columnFilters,
|
|
277
316
|
sort,
|
|
317
|
+
locale,
|
|
278
318
|
subColumns,
|
|
279
319
|
subHeader: subColumns !== undefined,
|
|
280
320
|
}),
|
|
@@ -292,6 +332,33 @@
|
|
|
292
332
|
|
|
293
333
|
function clearFilters(): void {
|
|
294
334
|
columnFilters = {};
|
|
335
|
+
// the search field is the table's own: what was typed into it is cleared with the rest. A
|
|
336
|
+
// needle a page set from outside, with no field of the table for it, stays the page's.
|
|
337
|
+
if (searchBox) {
|
|
338
|
+
filter = '';
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function filtersChanged(): void {
|
|
343
|
+
onfilterchange?.({filter, columnFilters});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function setColumnFilter(key: string, value: string): void {
|
|
347
|
+
const next = {...columnFilters};
|
|
348
|
+
if (value === '') {
|
|
349
|
+
// no entry rather than an empty one: what an app writes into its address stays short
|
|
350
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete -- a record by column key
|
|
351
|
+
delete next[key];
|
|
352
|
+
} else {
|
|
353
|
+
next[key] = value;
|
|
354
|
+
}
|
|
355
|
+
columnFilters = next;
|
|
356
|
+
filtersChanged();
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function setSearch(value: string): void {
|
|
360
|
+
filter = value;
|
|
361
|
+
filtersChanged();
|
|
295
362
|
}
|
|
296
363
|
|
|
297
364
|
// The scope is the interface; a filter belongs to the rows it was typed for.
|
|
@@ -361,6 +428,7 @@
|
|
|
361
428
|
} else {
|
|
362
429
|
sort = undefined;
|
|
363
430
|
}
|
|
431
|
+
onsortchange?.(sort);
|
|
364
432
|
}
|
|
365
433
|
|
|
366
434
|
function toggleExpanded(id: string): void {
|
|
@@ -1138,6 +1206,19 @@
|
|
|
1138
1206
|
</div>
|
|
1139
1207
|
{/if}
|
|
1140
1208
|
<div class="hmm-table-trailing">
|
|
1209
|
+
{#if searchBox}
|
|
1210
|
+
<input
|
|
1211
|
+
class="hmm-input hmm-table-search"
|
|
1212
|
+
type="search"
|
|
1213
|
+
placeholder={searchLabel}
|
|
1214
|
+
aria-label={searchLabel}
|
|
1215
|
+
value={filter}
|
|
1216
|
+
data-testid={testId === undefined ? undefined : `${testId}-search`}
|
|
1217
|
+
oninput={(event) => {
|
|
1218
|
+
setSearch(event.currentTarget.value);
|
|
1219
|
+
}}
|
|
1220
|
+
/>
|
|
1221
|
+
{/if}
|
|
1141
1222
|
{#if status}{@render status()}{/if}
|
|
1142
1223
|
{#if hiddenByFilter && showingText !== undefined}
|
|
1143
1224
|
<span class="hmm-table-count" data-testid={testId === undefined ? undefined : `${testId}-count`}
|
|
@@ -1268,17 +1349,30 @@
|
|
|
1268
1349
|
{#if hasExpander}<div class="hmm-tf-spacer"></div>{/if}
|
|
1269
1350
|
{#each visibleColumns as column (column.key)}
|
|
1270
1351
|
<div class="hmm-tf" style:grid-column={layout.track[column.key]}>
|
|
1271
|
-
{#if isFilterable(column)}
|
|
1352
|
+
{#if isFilterable(column) && column.filterOptions !== undefined}
|
|
1353
|
+
<select
|
|
1354
|
+
class="hmm-select hmm-tf-input hmm-tf-select"
|
|
1355
|
+
aria-label={`${filterLabel}: ${column.label}`}
|
|
1356
|
+
value={columnFilters[column.key] ?? ''}
|
|
1357
|
+
data-filter-key={column.key}
|
|
1358
|
+
onchange={(event) => {
|
|
1359
|
+
setColumnFilter(column.key, event.currentTarget.value);
|
|
1360
|
+
}}
|
|
1361
|
+
>
|
|
1362
|
+
<option value="">{allLabel}</option>
|
|
1363
|
+
{#each column.filterOptions as option (option.value)}
|
|
1364
|
+
<option value={option.value}>{option.label}</option>
|
|
1365
|
+
{/each}
|
|
1366
|
+
</select>
|
|
1367
|
+
{:else if isFilterable(column)}
|
|
1272
1368
|
<input
|
|
1273
1369
|
class="hmm-input hmm-tf-input"
|
|
1274
1370
|
type="search"
|
|
1275
1371
|
aria-label={`${filterLabel}: ${column.label}`}
|
|
1276
1372
|
value={columnFilters[column.key] ?? ''}
|
|
1373
|
+
data-filter-key={column.key}
|
|
1277
1374
|
oninput={(event) => {
|
|
1278
|
-
|
|
1279
|
-
...columnFilters,
|
|
1280
|
-
[column.key]: event.currentTarget.value,
|
|
1281
|
-
};
|
|
1375
|
+
setColumnFilter(column.key, event.currentTarget.value);
|
|
1282
1376
|
}}
|
|
1283
1377
|
/>
|
|
1284
1378
|
{/if}
|
|
@@ -1301,7 +1395,10 @@
|
|
|
1301
1395
|
type="button"
|
|
1302
1396
|
class="hmm-button hmm-table-clear"
|
|
1303
1397
|
data-testid={testId === undefined ? undefined : `${testId}-clear-filter`}
|
|
1304
|
-
onclick={
|
|
1398
|
+
onclick={() => {
|
|
1399
|
+
clearFilters();
|
|
1400
|
+
filtersChanged();
|
|
1401
|
+
}}>{clearFilterLabel}</button
|
|
1305
1402
|
>
|
|
1306
1403
|
{:else}
|
|
1307
1404
|
{emptyText}
|
|
@@ -1315,7 +1412,10 @@
|
|
|
1315
1412
|
target for the pointer, which is what every 2.x grid row was. -->
|
|
1316
1413
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
1317
1414
|
<div
|
|
1318
|
-
class=
|
|
1415
|
+
class={['hmm-tr', flatRow.kind === 'row' && rowClass?.(flatRow.row)]}
|
|
1416
|
+
data-testid={flatRow.kind === 'row' && flatRow.depth === 0
|
|
1417
|
+
? rowTestId?.(flatRow.row)
|
|
1418
|
+
: undefined}
|
|
1319
1419
|
class:hmm-tr-even={(window_.start + index) % 2 === 1}
|
|
1320
1420
|
class:hmm-tr-selected={selectedSet.has(flatRow.id)}
|
|
1321
1421
|
class:hmm-tr-child={flatRow.depth > 0 && flatRow.kind === 'row'}
|
|
@@ -1464,8 +1564,13 @@
|
|
|
1464
1564
|
grid reads as a table with a head rather than as a strip with a table under it. */
|
|
1465
1565
|
.hmm-table-band {
|
|
1466
1566
|
display: flex;
|
|
1567
|
+
/* a narrow window: the count and the search go under the actions rather than out of the band */
|
|
1568
|
+
flex-wrap: wrap;
|
|
1467
1569
|
align-items: center;
|
|
1468
|
-
gap: 8px;
|
|
1570
|
+
gap: 4px 8px;
|
|
1571
|
+
/* as tall with a plain button or a search field in it as with the 26 px toolbar buttons */
|
|
1572
|
+
box-sizing: border-box;
|
|
1573
|
+
min-height: 33px;
|
|
1469
1574
|
padding: 3px 6px;
|
|
1470
1575
|
background: var(--hmm-header-bg);
|
|
1471
1576
|
border-bottom: 1px solid var(--hmm-border-muted);
|
|
@@ -1501,6 +1606,14 @@
|
|
|
1501
1606
|
white-space: nowrap;
|
|
1502
1607
|
}
|
|
1503
1608
|
|
|
1609
|
+
/* The search over all columns: as tall as a toolbar button, and it gives way before the band wraps. */
|
|
1610
|
+
.hmm-table-search {
|
|
1611
|
+
flex: 0 1 14rem;
|
|
1612
|
+
width: 14rem;
|
|
1613
|
+
min-width: 6rem;
|
|
1614
|
+
color: var(--hmm-fg);
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1504
1617
|
.hmm-table-grid {
|
|
1505
1618
|
display: flex;
|
|
1506
1619
|
flex-direction: column;
|
|
@@ -1677,6 +1790,11 @@
|
|
|
1677
1790
|
height: 20px;
|
|
1678
1791
|
}
|
|
1679
1792
|
|
|
1793
|
+
/* a list of choices in the filter row: the field's box, the text not cut by the control's own padding */
|
|
1794
|
+
.hmm-tf-select {
|
|
1795
|
+
padding: 0 2px;
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1680
1798
|
.hmm-table-body {
|
|
1681
1799
|
flex: 1 1 auto;
|
|
1682
1800
|
min-height: 0;
|
|
@@ -64,7 +64,39 @@ declare function $$render<T>(): {
|
|
|
64
64
|
* "this column **or** that one".
|
|
65
65
|
*/
|
|
66
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>;
|
|
67
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;
|
|
68
100
|
/** Double click, or Enter on the focused row. */
|
|
69
101
|
onactivate?: ((row: T) => void) | undefined;
|
|
70
102
|
/** Right click on a row; the table has already called `preventDefault()`. */
|
|
@@ -99,7 +131,7 @@ declare function $$render<T>(): {
|
|
|
99
131
|
testId?: string | undefined;
|
|
100
132
|
};
|
|
101
133
|
exports: {};
|
|
102
|
-
bindings: "selected" | "expanded" | "filter" | "sort";
|
|
134
|
+
bindings: "selected" | "expanded" | "filter" | "columnFilters" | "sort";
|
|
103
135
|
slots: {};
|
|
104
136
|
events: {};
|
|
105
137
|
};
|
|
@@ -107,7 +139,7 @@ declare class __sveltets_Render<T> {
|
|
|
107
139
|
props(): ReturnType<typeof $$render<T>>['props'];
|
|
108
140
|
events(): ReturnType<typeof $$render<T>>['events'];
|
|
109
141
|
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
110
|
-
bindings(): "selected" | "expanded" | "filter" | "sort";
|
|
142
|
+
bindings(): "selected" | "expanded" | "filter" | "columnFilters" | "sort";
|
|
111
143
|
exports(): {};
|
|
112
144
|
}
|
|
113
145
|
interface $$IsomorphicComponent {
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type {Snippet} from 'svelte';
|
|
3
|
+
|
|
4
|
+
import {activeNavId, navItem, type NavItem} from './navigation.js';
|
|
5
|
+
import Tabs from './Tabs.svelte';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The bar on top of an app: its name, its navigation as tabs, and a group of the page's own
|
|
9
|
+
* items at the right - homematic-manager's bar, measured: one flat line of the header height
|
|
10
|
+
* (`--hmm-header-height`, 36 px) on the header ground with a hairline under it, 10 px at the
|
|
11
|
+
* sides, the tabs as tall as the bar and lying on the hairline, everything else in the middle
|
|
12
|
+
* of the line. Nothing wraps inside the line: the tabs give way and scroll in their own strip.
|
|
13
|
+
*
|
|
14
|
+
* Below 64rem (1024 px) the bar is two such lines - the name and the page's items, then the
|
|
15
|
+
* tabs over the whole width; `narrow={false}` keeps the one line, for an app with a minimum
|
|
16
|
+
* width of its own.
|
|
17
|
+
*
|
|
18
|
+
* The navigation is data (`NavItem`), so an app can hand the same items, the same `active`
|
|
19
|
+
* and the same `onnavigate` to another navigation component.
|
|
20
|
+
*/
|
|
21
|
+
interface Props {
|
|
22
|
+
/** The app's name, drawn as the page's `h1`. */
|
|
23
|
+
title?: string | undefined;
|
|
24
|
+
/** Replaces the name: a logo, a control of the app's own. As tall as it likes up to the bar. */
|
|
25
|
+
brand?: Snippet | undefined;
|
|
26
|
+
/** The places of the app. With none the bar has no tabs. */
|
|
27
|
+
items?: readonly NavItem[];
|
|
28
|
+
/** The id of the open place. */
|
|
29
|
+
active?: string;
|
|
30
|
+
/** The user chose a place. Without `bind:active` the app sets `active` itself - after asking, say. */
|
|
31
|
+
onnavigate?: ((id: string, item: NavItem) => void) | undefined;
|
|
32
|
+
/** The accessible name of the navigation; the kit's "Tabs" by default. */
|
|
33
|
+
navLabel?: string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* The group at the right: a count, the version, a help link, the theme switch. Controls
|
|
36
|
+
* keep their box; an element with the class `hmm-header-text` is muted, small text that is
|
|
37
|
+
* cut when the line is short (give it a `title`).
|
|
38
|
+
*/
|
|
39
|
+
actions?: Snippet | undefined;
|
|
40
|
+
/** Two lines below 64rem. */
|
|
41
|
+
narrow?: boolean;
|
|
42
|
+
testId?: string | undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let {
|
|
46
|
+
title = undefined,
|
|
47
|
+
brand = undefined,
|
|
48
|
+
items = [],
|
|
49
|
+
active = $bindable(''),
|
|
50
|
+
onnavigate = undefined,
|
|
51
|
+
navLabel = undefined,
|
|
52
|
+
actions = undefined,
|
|
53
|
+
narrow = true,
|
|
54
|
+
testId = undefined,
|
|
55
|
+
}: Props = $props();
|
|
56
|
+
|
|
57
|
+
let root = $state<HTMLElement | undefined>(undefined);
|
|
58
|
+
const shown = $derived(activeNavId(items, active));
|
|
59
|
+
|
|
60
|
+
function select(id: string): void {
|
|
61
|
+
const item = navItem(items, id);
|
|
62
|
+
if (item !== undefined) {
|
|
63
|
+
onnavigate?.(id, item);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// where the tabs scroll in their strip (a narrow window), the open one is brought into it
|
|
68
|
+
$effect(() => {
|
|
69
|
+
const tab = root?.querySelector(`[role="tab"][aria-selected="true"]`);
|
|
70
|
+
void shown;
|
|
71
|
+
tab?.scrollIntoView({block: 'nearest', inline: 'nearest'});
|
|
72
|
+
});
|
|
73
|
+
</script>
|
|
74
|
+
|
|
75
|
+
<header class="hmm-header" class:hmm-header-narrow={narrow} data-testid={testId} bind:this={root}>
|
|
76
|
+
{#if brand}
|
|
77
|
+
<div class="hmm-header-brand">{@render brand()}</div>
|
|
78
|
+
{:else if title !== undefined}
|
|
79
|
+
<h1 class="hmm-header-title">{title}</h1>
|
|
80
|
+
{/if}
|
|
81
|
+
{#if items.length > 0}
|
|
82
|
+
<!--
|
|
83
|
+
The tabs take the choice and hand it on: with `bind:active` on the header the bar
|
|
84
|
+
follows at once, without it the app decides (a page with unsaved changes asks first).
|
|
85
|
+
-->
|
|
86
|
+
<Tabs
|
|
87
|
+
tabs={[...items]}
|
|
88
|
+
bind:active={() => shown, (id) => (active = id)}
|
|
89
|
+
onselect={select}
|
|
90
|
+
label={navLabel}
|
|
91
|
+
testId={testId === undefined ? undefined : `${testId}-nav`}
|
|
92
|
+
/>
|
|
93
|
+
{/if}
|
|
94
|
+
{#if actions}
|
|
95
|
+
<div class="hmm-header-actions" data-testid={testId === undefined ? undefined : `${testId}-actions`}>
|
|
96
|
+
{@render actions()}
|
|
97
|
+
</div>
|
|
98
|
+
{/if}
|
|
99
|
+
</header>
|
|
100
|
+
|
|
101
|
+
<style>
|
|
102
|
+
.hmm-header {
|
|
103
|
+
display: flex;
|
|
104
|
+
align-items: center;
|
|
105
|
+
gap: 8px;
|
|
106
|
+
box-sizing: border-box;
|
|
107
|
+
height: var(--hmm-header-height);
|
|
108
|
+
padding: 0 10px;
|
|
109
|
+
background: var(--hmm-header-bg);
|
|
110
|
+
border-bottom: 1px solid var(--hmm-border);
|
|
111
|
+
flex: 0 0 auto;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.hmm-header-title {
|
|
115
|
+
flex: none;
|
|
116
|
+
font-size: 1.05rem;
|
|
117
|
+
font-weight: 600;
|
|
118
|
+
line-height: 1;
|
|
119
|
+
margin: 0 4px 0 0;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.hmm-header-brand {
|
|
123
|
+
display: flex;
|
|
124
|
+
align-items: center;
|
|
125
|
+
flex: none;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/* The tabs give way before the bar grows, and scroll: a scroll bar would take its height from them. */
|
|
129
|
+
.hmm-header > :global(.hmm-tabs) {
|
|
130
|
+
flex: 0 1 auto;
|
|
131
|
+
min-width: 0;
|
|
132
|
+
overflow-x: auto;
|
|
133
|
+
scrollbar-width: none;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.hmm-header > :global(.hmm-tabs > .hmm-tab) {
|
|
137
|
+
flex: none;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.hmm-header-actions {
|
|
141
|
+
display: flex;
|
|
142
|
+
align-items: center;
|
|
143
|
+
gap: 8px;
|
|
144
|
+
/* gives way before the bar grows: a text is cut (its tooltip says it), a control keeps its box */
|
|
145
|
+
flex: 0 1 auto;
|
|
146
|
+
min-width: 0;
|
|
147
|
+
margin-left: auto;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.hmm-header-actions > :global(:not(.hmm-header-text)) {
|
|
151
|
+
flex: none;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.hmm-header-actions > :global(.hmm-header-text) {
|
|
155
|
+
flex: 0 1 auto;
|
|
156
|
+
min-width: 0;
|
|
157
|
+
max-width: 11rem;
|
|
158
|
+
overflow: hidden;
|
|
159
|
+
text-overflow: ellipsis;
|
|
160
|
+
white-space: nowrap;
|
|
161
|
+
color: var(--hmm-fg-muted);
|
|
162
|
+
font-size: var(--hmm-font-size-small);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/* Two lines of the bar's height: the name and the page's items, then the tabs over the whole width. */
|
|
166
|
+
@media (max-width: 64rem) {
|
|
167
|
+
.hmm-header-narrow {
|
|
168
|
+
flex-wrap: wrap;
|
|
169
|
+
height: auto;
|
|
170
|
+
row-gap: 0;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.hmm-header-narrow > .hmm-header-title,
|
|
174
|
+
.hmm-header-narrow > .hmm-header-brand,
|
|
175
|
+
.hmm-header-narrow > .hmm-header-actions {
|
|
176
|
+
display: flex;
|
|
177
|
+
align-items: center;
|
|
178
|
+
height: calc(var(--hmm-header-height) - 1px);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/* the group takes what the name leaves and never a line of its own: its texts are cut first */
|
|
182
|
+
.hmm-header-narrow > .hmm-header-actions {
|
|
183
|
+
flex: 1 1 0;
|
|
184
|
+
justify-content: flex-end;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.hmm-header-narrow > :global(.hmm-tabs) {
|
|
188
|
+
order: 3;
|
|
189
|
+
flex: 0 0 100%;
|
|
190
|
+
/* the hairline between the two lines, then tabs as tall as the bar's */
|
|
191
|
+
height: calc(var(--hmm-header-height) + 1px);
|
|
192
|
+
box-sizing: border-box;
|
|
193
|
+
border-top: 1px solid var(--hmm-border);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
</style>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import { type NavItem } from './navigation.js';
|
|
3
|
+
/**
|
|
4
|
+
* The bar on top of an app: its name, its navigation as tabs, and a group of the page's own
|
|
5
|
+
* items at the right - homematic-manager's bar, measured: one flat line of the header height
|
|
6
|
+
* (`--hmm-header-height`, 36 px) on the header ground with a hairline under it, 10 px at the
|
|
7
|
+
* sides, the tabs as tall as the bar and lying on the hairline, everything else in the middle
|
|
8
|
+
* of the line. Nothing wraps inside the line: the tabs give way and scroll in their own strip.
|
|
9
|
+
*
|
|
10
|
+
* Below 64rem (1024 px) the bar is two such lines - the name and the page's items, then the
|
|
11
|
+
* tabs over the whole width; `narrow={false}` keeps the one line, for an app with a minimum
|
|
12
|
+
* width of its own.
|
|
13
|
+
*
|
|
14
|
+
* The navigation is data (`NavItem`), so an app can hand the same items, the same `active`
|
|
15
|
+
* and the same `onnavigate` to another navigation component.
|
|
16
|
+
*/
|
|
17
|
+
interface Props {
|
|
18
|
+
/** The app's name, drawn as the page's `h1`. */
|
|
19
|
+
title?: string | undefined;
|
|
20
|
+
/** Replaces the name: a logo, a control of the app's own. As tall as it likes up to the bar. */
|
|
21
|
+
brand?: Snippet | undefined;
|
|
22
|
+
/** The places of the app. With none the bar has no tabs. */
|
|
23
|
+
items?: readonly NavItem[];
|
|
24
|
+
/** The id of the open place. */
|
|
25
|
+
active?: string;
|
|
26
|
+
/** The user chose a place. Without `bind:active` the app sets `active` itself - after asking, say. */
|
|
27
|
+
onnavigate?: ((id: string, item: NavItem) => void) | undefined;
|
|
28
|
+
/** The accessible name of the navigation; the kit's "Tabs" by default. */
|
|
29
|
+
navLabel?: string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* The group at the right: a count, the version, a help link, the theme switch. Controls
|
|
32
|
+
* keep their box; an element with the class `hmm-header-text` is muted, small text that is
|
|
33
|
+
* cut when the line is short (give it a `title`).
|
|
34
|
+
*/
|
|
35
|
+
actions?: Snippet | undefined;
|
|
36
|
+
/** Two lines below 64rem. */
|
|
37
|
+
narrow?: boolean;
|
|
38
|
+
testId?: string | undefined;
|
|
39
|
+
}
|
|
40
|
+
declare const Header: import("svelte").Component<Props, {}, "active">;
|
|
41
|
+
type Header = ReturnType<typeof Header>;
|
|
42
|
+
export default Header;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export * from './contextMenu.js';
|
|
2
2
|
export * from './dialogGeometry.js';
|
|
3
3
|
export * from './multiSelect.js';
|
|
4
|
+
export * from './navigation.js';
|
|
4
5
|
export * from './tooltip.js';
|
|
5
6
|
export { default as ContextMenu } from './ContextMenu.svelte';
|
|
6
7
|
export { default as DataTable } from './DataTable.svelte';
|
|
7
8
|
export { default as Dialog } from './Dialog.svelte';
|
|
9
|
+
export { default as Header } from './Header.svelte';
|
|
8
10
|
export { default as GithubLink } from './GithubLink.svelte';
|
|
9
11
|
export { default as Icon } from './Icon.svelte';
|
|
10
12
|
export { default as LanguageSwitch } from './LanguageSwitch.svelte';
|
package/dist/components/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export * from './contextMenu.js';
|
|
2
2
|
export * from './dialogGeometry.js';
|
|
3
3
|
export * from './multiSelect.js';
|
|
4
|
+
export * from './navigation.js';
|
|
4
5
|
export * from './tooltip.js';
|
|
5
6
|
export { default as ContextMenu } from './ContextMenu.svelte';
|
|
6
7
|
export { default as DataTable } from './DataTable.svelte';
|
|
7
8
|
export { default as Dialog } from './Dialog.svelte';
|
|
9
|
+
export { default as Header } from './Header.svelte';
|
|
8
10
|
export { default as GithubLink } from './GithubLink.svelte';
|
|
9
11
|
export { default as Icon } from './Icon.svelte';
|
|
10
12
|
export { default as LanguageSwitch } from './LanguageSwitch.svelte';
|
|
@@ -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
|
+
}
|
package/dist/i18n/messages.js
CHANGED
|
@@ -22,6 +22,7 @@ export const KIT_MESSAGES = {
|
|
|
22
22
|
// filters and selections
|
|
23
23
|
Filter: { de: 'Filter', en: 'Filter' },
|
|
24
24
|
'Filter all columns': { de: 'Alle Spalten filtern', en: 'Filter all columns' },
|
|
25
|
+
All: { de: 'Alle', en: 'All' },
|
|
25
26
|
'Clear filter': { de: 'Filter löschen', en: 'Clear filter' },
|
|
26
27
|
'No row matches the filter': { de: 'Keine Zeile passt zum Filter', en: 'No row matches the filter' },
|
|
27
28
|
'Check all': { de: 'Alle auswählen', en: 'Check all' },
|
|
@@ -36,6 +36,13 @@ export interface DataTableColumn<T> {
|
|
|
36
36
|
readonly align?: 'left' | 'center' | 'right';
|
|
37
37
|
/** Sortable by default. */
|
|
38
38
|
readonly sortable?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Empty cells stay last when the column is sorted descending too. By default the direction
|
|
41
|
+
* reverses the whole order, so a descending sort puts the empty cells on top - right for a
|
|
42
|
+
* name column, where the nameless devices then stand out, wrong for a value most rows have,
|
|
43
|
+
* such as a battery life: the rows without one would hide the longest.
|
|
44
|
+
*/
|
|
45
|
+
readonly emptyLast?: boolean;
|
|
39
46
|
/** Part of the filter by default. */
|
|
40
47
|
readonly filterable?: boolean;
|
|
41
48
|
/** Not drawn - the 2.x grid hid SUBTYPE for BidCos and the name columns on request. */
|
|
@@ -56,7 +63,38 @@ export interface DataTableColumn<T> {
|
|
|
56
63
|
readonly onactivate?: (row: T) => void;
|
|
57
64
|
/** Reads the value; defaults to `row[key]`. */
|
|
58
65
|
readonly value?: (row: T) => CellValue;
|
|
66
|
+
/**
|
|
67
|
+
* What the column is sorted by, where that is not what it shows: a time stamp for a cell that
|
|
68
|
+
* shows a formatted date, a rank for a state. The filters keep reading {@link value} - the
|
|
69
|
+
* text the user sees. Defaults to {@link value}.
|
|
70
|
+
*/
|
|
71
|
+
readonly sortValue?: (row: T) => CellValue;
|
|
72
|
+
/**
|
|
73
|
+
* The column's field in the filter row is a list of these choices instead of a text field, and
|
|
74
|
+
* a row matches the chosen one when its {@link filterValue} (or its text) **is** that value -
|
|
75
|
+
* for a column with a handful of values: a type, a state. The first entry of the list the table
|
|
76
|
+
* draws is its own "all", which filters nothing.
|
|
77
|
+
*/
|
|
78
|
+
readonly filterOptions?: readonly FilterOption[];
|
|
79
|
+
/**
|
|
80
|
+
* What the column's own filter compares, where that is not the text the cell shows - the
|
|
81
|
+
* language-independent id behind a translated label, so a filter kept in an address works in
|
|
82
|
+
* every language. The table's search over all columns keeps reading {@link value}. Defaults to
|
|
83
|
+
* {@link value}.
|
|
84
|
+
*/
|
|
85
|
+
readonly filterValue?: (row: T) => CellValue;
|
|
86
|
+
}
|
|
87
|
+
/** One choice of a column's filter list ({@link DataTableColumn.filterOptions}). */
|
|
88
|
+
export interface FilterOption {
|
|
89
|
+
readonly value: string;
|
|
90
|
+
readonly label: string;
|
|
59
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* The collation the tables sort text with when none is named: German, which sorts the umlauts
|
|
94
|
+
* with their base letters (ä with a) and is the same order for English text. Named rather than
|
|
95
|
+
* left to the browser, so a table has one order on every machine.
|
|
96
|
+
*/
|
|
97
|
+
export declare const DEFAULT_COLLATION = "de";
|
|
60
98
|
export type SortDirection = 'asc' | 'desc';
|
|
61
99
|
export interface SortState {
|
|
62
100
|
readonly key: string;
|
|
@@ -95,14 +133,35 @@ export declare function isSortable<T>(column: DataTableColumn<T>): boolean;
|
|
|
95
133
|
export declare function isFilterable<T>(column: DataTableColumn<T>): boolean;
|
|
96
134
|
/** Case-insensitive "contains", which is the `cn` default search of the 2.x filter toolbar. */
|
|
97
135
|
export declare function matchesText(haystack: string, needle: string): boolean;
|
|
98
|
-
/**
|
|
136
|
+
/** The text a column's own filter compares: its {@link DataTableColumn.filterValue}, or the cell's text. */
|
|
137
|
+
export declare function filterText<T>(row: T, column: DataTableColumn<T>): string;
|
|
138
|
+
/** What a column is sorted by: its {@link DataTableColumn.sortValue}, or the cell's value. */
|
|
139
|
+
export declare function sortValue<T>(row: T, column: DataTableColumn<T>): CellValue;
|
|
140
|
+
/**
|
|
141
|
+
* Does a row pass a column's own filter? A text field is "contains"; a list of choices
|
|
142
|
+
* ({@link DataTableColumn.filterOptions}) is "is".
|
|
143
|
+
*/
|
|
144
|
+
export declare function matchesColumnFilter<T>(row: T, column: DataTableColumn<T>, needle: string): boolean;
|
|
145
|
+
/** Does a row match the search over all columns and every per-column filter? */
|
|
99
146
|
export declare function matchesFilters<T>(row: T, columns: readonly DataTableColumn<T>[], globalFilter: string, columnFilters: Readonly<Record<string, string>>): boolean;
|
|
147
|
+
/**
|
|
148
|
+
* The words of a search over all columns. A row matches when every one of them is somewhere in its
|
|
149
|
+
* filterable columns - "regen markise" finds the program named "Markise" that the rain triggers,
|
|
150
|
+
* and a single word is the plain "contains" it always was.
|
|
151
|
+
*/
|
|
152
|
+
export declare function searchWords(needle: string): string[];
|
|
100
153
|
/**
|
|
101
154
|
* Compares two cell values. Numbers compare numerically, everything else compares as text with
|
|
102
155
|
* `localeCompare`, and an empty cell always sorts last - the 2.x grid put the nameless devices at
|
|
103
156
|
* the end, not at the top.
|
|
104
157
|
*/
|
|
105
|
-
export declare function compareCells(a: CellValue, b: CellValue): number;
|
|
158
|
+
export declare function compareCells(a: CellValue, b: CellValue, collator?: Intl.Collator): number;
|
|
159
|
+
/**
|
|
160
|
+
* The collator of a locale the way every table compares text: digits as numbers ("Kanal 2" before
|
|
161
|
+
* "Kanal 10"), case and accents only where nothing else tells two texts apart. One per locale,
|
|
162
|
+
* kept: a sort calls it for every pair.
|
|
163
|
+
*/
|
|
164
|
+
export declare function tableCollator(locale?: string): Intl.Collator;
|
|
106
165
|
export interface BuildRowsOptions<T> {
|
|
107
166
|
readonly rows: readonly T[];
|
|
108
167
|
readonly columns: readonly DataTableColumn<T>[];
|
|
@@ -112,6 +171,8 @@ export interface BuildRowsOptions<T> {
|
|
|
112
171
|
readonly globalFilter?: string;
|
|
113
172
|
readonly columnFilters?: Readonly<Record<string, string>>;
|
|
114
173
|
readonly sort?: SortState | undefined;
|
|
174
|
+
/** The locale text is sorted in; {@link DEFAULT_COLLATION} when none is named. */
|
|
175
|
+
readonly locale?: string | undefined;
|
|
115
176
|
/**
|
|
116
177
|
* The columns the sub-rows have of their own. Without them a channel is drawn with the device
|
|
117
178
|
* columns (the plain behaviour); with them the filter also reads a channel through its own
|
package/dist/table/tableModel.js
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
* filtered, sorted and flattened into what the virtualiser draws. It has no DOM in it, so all of
|
|
4
4
|
* this is tested directly rather than through a rendered grid.
|
|
5
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';
|
|
6
12
|
export function cellValue(row, column) {
|
|
7
13
|
if (column.value) {
|
|
8
14
|
return column.value(row);
|
|
@@ -34,29 +40,63 @@ export function isFilterable(column) {
|
|
|
34
40
|
export function matchesText(haystack, needle) {
|
|
35
41
|
return haystack.toLowerCase().includes(needle.toLowerCase());
|
|
36
42
|
}
|
|
37
|
-
/**
|
|
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? */
|
|
38
67
|
export function matchesFilters(row, columns, globalFilter, columnFilters) {
|
|
39
68
|
for (const column of columns) {
|
|
40
69
|
const needle = columnFilters[column.key];
|
|
41
|
-
if (needle !== undefined &&
|
|
70
|
+
if (needle !== undefined && !matchesColumnFilter(row, column, needle)) {
|
|
42
71
|
return false;
|
|
43
72
|
}
|
|
44
73
|
}
|
|
45
|
-
|
|
74
|
+
const words = searchWords(globalFilter);
|
|
75
|
+
if (words.length === 0) {
|
|
46
76
|
return true;
|
|
47
77
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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 !== '');
|
|
51
91
|
}
|
|
52
92
|
/**
|
|
53
93
|
* Compares two cell values. Numbers compare numerically, everything else compares as text with
|
|
54
94
|
* `localeCompare`, and an empty cell always sorts last - the 2.x grid put the nameless devices at
|
|
55
95
|
* the end, not at the top.
|
|
56
96
|
*/
|
|
57
|
-
export function compareCells(a, b) {
|
|
58
|
-
const aEmpty = a
|
|
59
|
-
const bEmpty = b
|
|
97
|
+
export function compareCells(a, b, collator = tableCollator()) {
|
|
98
|
+
const aEmpty = isEmptyCell(a);
|
|
99
|
+
const bEmpty = isEmptyCell(b);
|
|
60
100
|
if (aEmpty || bEmpty) {
|
|
61
101
|
return aEmpty && bEmpty ? 0 : aEmpty ? 1 : -1;
|
|
62
102
|
}
|
|
@@ -66,7 +106,25 @@ export function compareCells(a, b) {
|
|
|
66
106
|
if (typeof a === 'boolean' && typeof b === 'boolean') {
|
|
67
107
|
return Number(a) - Number(b);
|
|
68
108
|
}
|
|
69
|
-
return String(a)
|
|
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 === '';
|
|
70
128
|
}
|
|
71
129
|
/**
|
|
72
130
|
* Filters, sorts and flattens. A parent survives the filter when it matches itself or when one of
|
|
@@ -87,7 +145,19 @@ export function buildRows(options) {
|
|
|
87
145
|
const column = columns.find((candidate) => candidate.key === sort.key);
|
|
88
146
|
if (column && isSortable(column)) {
|
|
89
147
|
const factor = sort.direction === 'asc' ? 1 : -1;
|
|
90
|
-
|
|
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
|
+
});
|
|
91
161
|
}
|
|
92
162
|
}
|
|
93
163
|
const flat = [];
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "occulite-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Svelte 5 UI kit with openccu-lite's look: design tokens, light and dark themes, de/en handling, DataTable, dialogs, menus, notices",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Sebastian 'hobbyquaker' Raff <hobbyquaker@gmail.com>",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/
|
|
10
|
+
"url": "git+https://github.com/openccu-lite/occulite-ui.git"
|
|
11
11
|
},
|
|
12
12
|
"bugs": {
|
|
13
|
-
"url": "https://github.com/
|
|
13
|
+
"url": "https://github.com/openccu-lite/occulite-ui/issues"
|
|
14
14
|
},
|
|
15
|
-
"homepage": "https://github.com/
|
|
15
|
+
"homepage": "https://github.com/openccu-lite/occulite-ui#readme",
|
|
16
16
|
"keywords": [
|
|
17
17
|
"svelte",
|
|
18
18
|
"svelte5",
|