@sveltia/ui 0.82.0 → 0.83.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/dist/components/grid/grid-col-header.svelte +121 -2
- package/dist/components/grid/grid-col-header.svelte.d.ts +35 -1
- package/dist/components/grid/grid-foot.svelte +5 -0
- package/dist/components/grid/grid-head.svelte +4 -0
- package/dist/components/grid/grid-row.svelte +55 -2
- package/dist/components/grid/grid-row.svelte.d.ts +4 -2
- package/dist/components/grid/grid.svelte +5 -0
- package/dist/components/text-editor/shiki/version.d.ts +1 -1
- package/dist/components/text-editor/shiki/version.js +1 -1
- package/dist/services/group.svelte.js +6 -1
- package/package.json +4 -4
|
@@ -1,20 +1,34 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
@component
|
|
3
|
-
The interactive version of `<TableColHeader>`.
|
|
3
|
+
The interactive version of `<TableColHeader>`. With `sortOrder` set, the header becomes sortable:
|
|
4
|
+
its content is wrapped in a button that indicates the current order and requests a new one.
|
|
4
5
|
@see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th
|
|
5
6
|
@see https://w3c.github.io/aria/#columnheader
|
|
7
|
+
@see https://www.w3.org/WAI/ARIA/apg/patterns/table/examples/sortable-table/
|
|
6
8
|
-->
|
|
7
9
|
<script>
|
|
10
|
+
import Button from '../button/button.svelte';
|
|
11
|
+
import Icon from '../icon/icon.svelte';
|
|
8
12
|
import TablePart from '../table/table-part.svelte';
|
|
9
13
|
|
|
10
14
|
/**
|
|
11
15
|
* @import { Snippet } from 'svelte';
|
|
16
|
+
* @import { Attachment } from 'svelte/attachments';
|
|
12
17
|
*/
|
|
13
18
|
|
|
14
19
|
/**
|
|
15
20
|
* @typedef {object} Props
|
|
16
21
|
* @property {string} [class] The `class` attribute on the wrapper element.
|
|
22
|
+
* @property {'ascending' | 'descending' | 'none'} [sortOrder] The order the column is sorted in,
|
|
23
|
+
* or `none` if it can be sorted but currently isn’t. An alias of the `aria-sort` attribute, which
|
|
24
|
+
* is only set on the sorted column, as the sortable table pattern recommends. When set, the
|
|
25
|
+
* content is rendered in a button that requests a new order with `onSort`; the button covers the
|
|
26
|
+
* whole cell, padding included. Leave it out for a header that can’t be sorted.
|
|
17
27
|
* @property {Snippet} [children] Primary slot content.
|
|
28
|
+
* @property {(event: CustomEvent<{ sortOrder: 'ascending' | 'descending' }>) => void} [onSort]
|
|
29
|
+
* Custom `Sort` event handler, called when the sort button is clicked. `detail.sortOrder` is the
|
|
30
|
+
* suggested next order: `descending` if the column is currently sorted in ascending order,
|
|
31
|
+
* otherwise `ascending`. The consumer sorts the rows and updates `sortOrder` accordingly.
|
|
18
32
|
*/
|
|
19
33
|
|
|
20
34
|
/**
|
|
@@ -22,9 +36,114 @@
|
|
|
22
36
|
*/
|
|
23
37
|
let {
|
|
24
38
|
/* eslint-disable prefer-const */
|
|
39
|
+
class: className,
|
|
40
|
+
sortOrder = undefined,
|
|
41
|
+
children,
|
|
42
|
+
onSort,
|
|
25
43
|
...restProps
|
|
26
44
|
/* eslint-enable prefer-const */
|
|
27
45
|
} = $props();
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Keep the sort button’s clicks and activation keys from the `<Grid>`, which would otherwise
|
|
49
|
+
* select or focus the header row, or prevent the key’s default action, and call `onSort` instead.
|
|
50
|
+
* Native listeners are used because the grid listens on its own element, which a delegated Svelte
|
|
51
|
+
* event handler would only reach after the grid has handled the event. The arrow keys are left
|
|
52
|
+
* alone, so they still move from the header row to the data rows.
|
|
53
|
+
* @type {Attachment}
|
|
54
|
+
*/
|
|
55
|
+
const handleSortButton = (element) => {
|
|
56
|
+
/**
|
|
57
|
+
* Handle the `click` event on the button.
|
|
58
|
+
* @param {Event} event `click` event.
|
|
59
|
+
*/
|
|
60
|
+
const onClick = (event) => {
|
|
61
|
+
event.stopPropagation();
|
|
62
|
+
onSort?.(
|
|
63
|
+
new CustomEvent('Sort', {
|
|
64
|
+
detail: { sortOrder: sortOrder === 'ascending' ? 'descending' : 'ascending' },
|
|
65
|
+
}),
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Handle the `keydown` event on the button.
|
|
71
|
+
* @param {Event} event `keydown` event.
|
|
72
|
+
*/
|
|
73
|
+
const onKeyDown = (event) => {
|
|
74
|
+
const { key } = /** @type {KeyboardEvent} */ (event);
|
|
75
|
+
|
|
76
|
+
if (key === 'Enter' || key === ' ') {
|
|
77
|
+
event.stopPropagation();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
element.addEventListener('click', onClick);
|
|
82
|
+
element.addEventListener('keydown', onKeyDown);
|
|
83
|
+
|
|
84
|
+
return () => {
|
|
85
|
+
element.removeEventListener('click', onClick);
|
|
86
|
+
element.removeEventListener('keydown', onKeyDown);
|
|
87
|
+
};
|
|
88
|
+
};
|
|
28
89
|
</script>
|
|
29
90
|
|
|
30
|
-
|
|
91
|
+
{#if sortOrder === undefined}
|
|
92
|
+
<TablePart {...restProps} role="columnheader" kind="grid-col-header" class={className}>
|
|
93
|
+
{@render children?.()}
|
|
94
|
+
</TablePart>
|
|
95
|
+
{:else}
|
|
96
|
+
<TablePart
|
|
97
|
+
{...restProps}
|
|
98
|
+
role="columnheader"
|
|
99
|
+
kind="grid-col-header"
|
|
100
|
+
class={className ? `sortable ${className}` : 'sortable'}
|
|
101
|
+
aria-sort={sortOrder === 'none' ? undefined : sortOrder}
|
|
102
|
+
>
|
|
103
|
+
<Button class="sort-button" {@attach handleSortButton}>
|
|
104
|
+
{@render children?.()}
|
|
105
|
+
{#snippet endIcon()}
|
|
106
|
+
<Icon
|
|
107
|
+
class="sort-icon {sortOrder}"
|
|
108
|
+
name={sortOrder === 'descending' ? 'arrow_downward' : 'arrow_upward'}
|
|
109
|
+
/>
|
|
110
|
+
{/snippet}
|
|
111
|
+
</Button>
|
|
112
|
+
</TablePart>
|
|
113
|
+
{/if}
|
|
114
|
+
|
|
115
|
+
<style>:global(:where(.sui.grid-col-header.sortable)) {
|
|
116
|
+
position: relative;
|
|
117
|
+
}
|
|
118
|
+
:global(.sui.grid-col-header.sortable) > :global(.sui.button.sort-button) {
|
|
119
|
+
justify-content: flex-start;
|
|
120
|
+
margin: 0;
|
|
121
|
+
border-radius: 0;
|
|
122
|
+
padding: 0;
|
|
123
|
+
width: 100%;
|
|
124
|
+
height: auto;
|
|
125
|
+
color: inherit;
|
|
126
|
+
font: inherit;
|
|
127
|
+
text-align: start;
|
|
128
|
+
}
|
|
129
|
+
:global(.sui.grid-col-header.sortable) > :global(.sui.button.sort-button::after) {
|
|
130
|
+
position: absolute;
|
|
131
|
+
inset: 0;
|
|
132
|
+
content: "";
|
|
133
|
+
}
|
|
134
|
+
:global(.sui.grid-col-header.sortable) > :global(.sui.button.sort-button) :global(.sort-icon) {
|
|
135
|
+
flex: none;
|
|
136
|
+
font-size: 16px;
|
|
137
|
+
transition: opacity 200ms;
|
|
138
|
+
}
|
|
139
|
+
:global(.sui.grid-col-header.sortable) > :global(.sui.button.sort-button) :global(.sort-icon.none) {
|
|
140
|
+
opacity: 0;
|
|
141
|
+
}
|
|
142
|
+
:global(.sui.grid-col-header.sortable) > :global(.sui.button.sort-button:is(:hover, :focus-visible)) :global(.sort-icon.none) {
|
|
143
|
+
opacity: 0.4;
|
|
144
|
+
}
|
|
145
|
+
@media (hover: none) {
|
|
146
|
+
:global(.sui.grid-col-header.sortable) > :global(.sui.button.sort-button) :global(.sort-icon.none) {
|
|
147
|
+
opacity: 0.4;
|
|
148
|
+
}
|
|
149
|
+
}</style>
|
|
@@ -4,28 +4,62 @@ type GridColHeader = {
|
|
|
4
4
|
$set?(props: Partial<Props & Record<string, any>>): void;
|
|
5
5
|
};
|
|
6
6
|
/**
|
|
7
|
-
* The interactive version of `<TableColHeader>`.
|
|
7
|
+
* The interactive version of `<TableColHeader>`. With `sortOrder` set, the header becomes sortable:
|
|
8
|
+
* its content is wrapped in a button that indicates the current order and requests a new one.
|
|
8
9
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th
|
|
9
10
|
* @see https://w3c.github.io/aria/#columnheader
|
|
11
|
+
* @see https://www.w3.org/WAI/ARIA/apg/patterns/table/examples/sortable-table/
|
|
10
12
|
*/
|
|
11
13
|
declare const GridColHeader: import("svelte").Component<{
|
|
12
14
|
/**
|
|
13
15
|
* The `class` attribute on the wrapper element.
|
|
14
16
|
*/
|
|
15
17
|
class?: string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* The order the column is sorted in,
|
|
20
|
+
* or `none` if it can be sorted but currently isn’t. An alias of the `aria-sort` attribute, which
|
|
21
|
+
* is only set on the sorted column, as the sortable table pattern recommends. When set, the
|
|
22
|
+
* content is rendered in a button that requests a new order with `onSort`; the button covers the
|
|
23
|
+
* whole cell, padding included. Leave it out for a header that can’t be sorted.
|
|
24
|
+
*/
|
|
25
|
+
sortOrder?: "none" | "ascending" | "descending" | undefined;
|
|
16
26
|
/**
|
|
17
27
|
* Primary slot content.
|
|
18
28
|
*/
|
|
19
29
|
children?: Snippet<[]> | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Custom `Sort` event handler, called when the sort button is clicked. `detail.sortOrder` is the
|
|
32
|
+
* suggested next order: `descending` if the column is currently sorted in ascending order,
|
|
33
|
+
* otherwise `ascending`. The consumer sorts the rows and updates `sortOrder` accordingly.
|
|
34
|
+
*/
|
|
35
|
+
onSort?: ((event: CustomEvent<{
|
|
36
|
+
sortOrder: "ascending" | "descending";
|
|
37
|
+
}>) => void) | undefined;
|
|
20
38
|
} & Record<string, any>, {}, "">;
|
|
21
39
|
type Props = {
|
|
22
40
|
/**
|
|
23
41
|
* The `class` attribute on the wrapper element.
|
|
24
42
|
*/
|
|
25
43
|
class?: string | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* The order the column is sorted in,
|
|
46
|
+
* or `none` if it can be sorted but currently isn’t. An alias of the `aria-sort` attribute, which
|
|
47
|
+
* is only set on the sorted column, as the sortable table pattern recommends. When set, the
|
|
48
|
+
* content is rendered in a button that requests a new order with `onSort`; the button covers the
|
|
49
|
+
* whole cell, padding included. Leave it out for a header that can’t be sorted.
|
|
50
|
+
*/
|
|
51
|
+
sortOrder?: "none" | "ascending" | "descending" | undefined;
|
|
26
52
|
/**
|
|
27
53
|
* Primary slot content.
|
|
28
54
|
*/
|
|
29
55
|
children?: Snippet<[]> | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Custom `Sort` event handler, called when the sort button is clicked. `detail.sortOrder` is the
|
|
58
|
+
* suggested next order: `descending` if the column is currently sorted in ascending order,
|
|
59
|
+
* otherwise `ascending`. The consumer sorts the rows and updates `sortOrder` accordingly.
|
|
60
|
+
*/
|
|
61
|
+
onSort?: ((event: CustomEvent<{
|
|
62
|
+
sortOrder: "ascending" | "descending";
|
|
63
|
+
}>) => void) | undefined;
|
|
30
64
|
};
|
|
31
65
|
import type { Snippet } from 'svelte';
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
-->
|
|
7
7
|
<script>
|
|
8
8
|
import { _ } from '@sveltia/i18n';
|
|
9
|
+
import { setContext } from 'svelte';
|
|
9
10
|
import TablePart from '../table/table-part.svelte';
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -26,6 +27,10 @@
|
|
|
26
27
|
...restProps
|
|
27
28
|
/* eslint-enable prefer-const */
|
|
28
29
|
} = $props();
|
|
30
|
+
|
|
31
|
+
// Tell the `<GridRow>`s inside that they are footer rows, such as a totals row, which can be
|
|
32
|
+
// focused but not selected, like header rows
|
|
33
|
+
setContext('sui:grid-unselectable-rows', true);
|
|
29
34
|
</script>
|
|
30
35
|
|
|
31
36
|
<TablePart
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
-->
|
|
7
7
|
<script>
|
|
8
8
|
import { _ } from '@sveltia/i18n';
|
|
9
|
+
import { setContext } from 'svelte';
|
|
9
10
|
import TablePart from '../table/table-part.svelte';
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -26,6 +27,9 @@
|
|
|
26
27
|
...restProps
|
|
27
28
|
/* eslint-enable prefer-const */
|
|
28
29
|
} = $props();
|
|
30
|
+
|
|
31
|
+
// Tell the `<GridRow>`s inside that they are header rows, which can be focused but not selected
|
|
32
|
+
setContext('sui:grid-unselectable-rows', true);
|
|
29
33
|
</script>
|
|
30
34
|
|
|
31
35
|
<TablePart
|
|
@@ -5,17 +5,20 @@
|
|
|
5
5
|
@see https://w3c.github.io/aria/#row
|
|
6
6
|
-->
|
|
7
7
|
<script>
|
|
8
|
+
import { getContext } from 'svelte';
|
|
8
9
|
import TablePart from '../table/table-part.svelte';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* @import { Snippet } from 'svelte';
|
|
13
|
+
* @import { Attachment } from 'svelte/attachments';
|
|
12
14
|
*/
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* @typedef {object} Props
|
|
16
18
|
* @property {string} [class] The `class` attribute on the wrapper element.
|
|
17
19
|
* @property {boolean} [selected] Whether to select the widget. An alias of the `aria-selected`
|
|
18
|
-
* attribute.
|
|
20
|
+
* attribute. Ignored on a header or footer row inside `<GridHead>` or `<GridFoot>`, which can
|
|
21
|
+
* never be selected.
|
|
19
22
|
* @property {Snippet} [children] Primary slot content.
|
|
20
23
|
* @property {(event: CustomEvent) => void} [onChange] Custom `Change` event handler.
|
|
21
24
|
* @property {(event: CustomEvent) => void} [onSelect] Custom `Select` event handler.
|
|
@@ -30,6 +33,56 @@
|
|
|
30
33
|
...restProps
|
|
31
34
|
/* eslint-enable prefer-const */
|
|
32
35
|
} = $props();
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Whether the row is a header or footer row inside `<GridHead>` or `<GridFoot>`. The grid’s arrow
|
|
39
|
+
* keys still land on it, but it can’t be selected, so it has no `aria-selected` state, even one
|
|
40
|
+
* passed as an attribute, and is marked for the group service to leave out of the selection.
|
|
41
|
+
*/
|
|
42
|
+
const isUnselectableRow = getContext('sui:grid-unselectable-rows') === true;
|
|
43
|
+
|
|
44
|
+
const attributes = $derived.by(() => {
|
|
45
|
+
if (!isUnselectableRow) {
|
|
46
|
+
return { ...restProps, 'aria-selected': selected };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const { 'aria-selected': _ariaSelected, ...rest } = restProps;
|
|
50
|
+
|
|
51
|
+
return { ...rest, 'data-selectable': 'false' };
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Move the focus from a header row to the first sort button in it when the row is activated,
|
|
56
|
+
* which the grid does by clicking the focused row on Enter. The arrow keys move from row to row,
|
|
57
|
+
* so this is how a keyboard user gets from the header row to the sort buttons, and on from there
|
|
58
|
+
* with Tab. A click on a cell is left alone, as the button covers its sortable cell.
|
|
59
|
+
* @type {Attachment}
|
|
60
|
+
*/
|
|
61
|
+
const focusSortButton = (element) => {
|
|
62
|
+
/**
|
|
63
|
+
* Handle the `click` event on the row.
|
|
64
|
+
* @param {Event} event `click` event.
|
|
65
|
+
*/
|
|
66
|
+
const listener = (event) => {
|
|
67
|
+
const button = /** @type {HTMLElement | null} */ (element.querySelector('.sort-button'));
|
|
68
|
+
|
|
69
|
+
if (event.target === element && button) {
|
|
70
|
+
// The grid would otherwise move the focus back to the row it has just clicked
|
|
71
|
+
event.stopPropagation();
|
|
72
|
+
button.focus();
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
element.addEventListener('click', listener);
|
|
77
|
+
|
|
78
|
+
return () => {
|
|
79
|
+
element.removeEventListener('click', listener);
|
|
80
|
+
};
|
|
81
|
+
};
|
|
33
82
|
</script>
|
|
34
83
|
|
|
35
|
-
|
|
84
|
+
{#if isUnselectableRow}
|
|
85
|
+
<TablePart {...attributes} role="row" kind="grid-row" tabindex="0" {@attach focusSortButton} />
|
|
86
|
+
{:else}
|
|
87
|
+
<TablePart {...attributes} role="row" kind="grid-row" tabindex="0" />
|
|
88
|
+
{/if}
|
|
@@ -15,7 +15,8 @@ declare const GridRow: import("svelte").Component<{
|
|
|
15
15
|
class?: string | undefined;
|
|
16
16
|
/**
|
|
17
17
|
* Whether to select the widget. An alias of the `aria-selected`
|
|
18
|
-
* attribute.
|
|
18
|
+
* attribute. Ignored on a header or footer row inside `<GridHead>` or `<GridFoot>`, which can
|
|
19
|
+
* never be selected.
|
|
19
20
|
*/
|
|
20
21
|
selected?: boolean | undefined;
|
|
21
22
|
/**
|
|
@@ -38,7 +39,8 @@ type Props = {
|
|
|
38
39
|
class?: string | undefined;
|
|
39
40
|
/**
|
|
40
41
|
* Whether to select the widget. An alias of the `aria-selected`
|
|
41
|
-
* attribute.
|
|
42
|
+
* attribute. Ignored on a header or footer row inside `<GridHead>` or `<GridFoot>`, which can
|
|
43
|
+
* never be selected.
|
|
42
44
|
*/
|
|
43
45
|
selected?: boolean | undefined;
|
|
44
46
|
/**
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
@see https://w3c.github.io/aria/#grid
|
|
6
6
|
-->
|
|
7
7
|
<script>
|
|
8
|
+
import { setContext } from 'svelte';
|
|
8
9
|
import { activateGroup } from '../../services/group.svelte.js';
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -38,6 +39,10 @@
|
|
|
38
39
|
...restProps
|
|
39
40
|
/* eslint-enable prefer-const */
|
|
40
41
|
} = $props();
|
|
42
|
+
|
|
43
|
+
// A grid nested in a header or footer cell of another grid has data rows of its own, so the
|
|
44
|
+
// outer grid’s `<GridHead>` or `<GridFoot>` doesn’t make them unselectable
|
|
45
|
+
setContext('sui:grid-unselectable-rows', false);
|
|
41
46
|
</script>
|
|
42
47
|
|
|
43
48
|
<div
|
|
@@ -480,7 +480,12 @@ export class Group {
|
|
|
480
480
|
focused ??
|
|
481
481
|
(holders.length === 1
|
|
482
482
|
? holders[0]
|
|
483
|
-
: ((this.rovingTabStop === 'selected' ? this.selected : undefined) ??
|
|
483
|
+
: ((this.rovingTabStop === 'selected' ? this.selected : undefined) ??
|
|
484
|
+
// The first member not marked as unselectable, so a grid’s header row or a row group
|
|
485
|
+
// caption isn’t where the user lands when they tab into it. A plain menu item can’t be
|
|
486
|
+
// selected either, but it’s still where a menu starts
|
|
487
|
+
activeMembers.find((element) => element.dataset.selectable !== 'false') ??
|
|
488
|
+
activeMembers[0]));
|
|
484
489
|
|
|
485
490
|
allMembers.forEach((element) => {
|
|
486
491
|
// Only touch the DOM when it changes; this runs on every mutation of a large widget. The
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltia/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.83.0",
|
|
4
4
|
"description": "A collection of Svelte components and utilities for building user interfaces.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -81,14 +81,14 @@
|
|
|
81
81
|
"eslint-config-airbnb-extended": "^3.3.0",
|
|
82
82
|
"eslint-config-prettier": "^10.1.8",
|
|
83
83
|
"eslint-plugin-import": "^2.32.0",
|
|
84
|
-
"eslint-plugin-jsdoc": "^65.3.
|
|
84
|
+
"eslint-plugin-jsdoc": "^65.3.2",
|
|
85
85
|
"eslint-plugin-package-json": "^1.10.1",
|
|
86
86
|
"eslint-plugin-svelte": "^3.23.1",
|
|
87
87
|
"globals": "^17.13.0",
|
|
88
88
|
"happy-dom": "^21.0.1",
|
|
89
|
-
"oxlint": "^1.
|
|
89
|
+
"oxlint": "^1.88.0",
|
|
90
90
|
"playwright": "^1.64.0",
|
|
91
|
-
"postcss": "^8.5.
|
|
91
|
+
"postcss": "^8.5.30",
|
|
92
92
|
"postcss-html": "^2.0.0",
|
|
93
93
|
"prettier": "^3.9.10",
|
|
94
94
|
"prettier-plugin-svelte": "^4.1.1",
|