@sveltia/ui 0.81.3 → 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/drawer/drawer.svelte.d.ts +2 -2
- 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/alignment.d.ts +2 -0
- package/dist/components/text-editor/alignment.js +40 -0
- package/dist/components/text-editor/block.d.ts +4 -0
- package/dist/components/text-editor/block.js +65 -0
- package/dist/components/text-editor/constants.d.ts +22 -2
- package/dist/components/text-editor/constants.js +40 -1
- package/dist/components/text-editor/core.d.ts +7 -0
- package/dist/components/text-editor/core.js +61 -7
- package/dist/components/text-editor/floating-link-editor.svelte +58 -6
- package/dist/components/text-editor/html.js +21 -4
- package/dist/components/text-editor/lexical-root.svelte +27 -0
- package/dist/components/text-editor/shiki/version.d.ts +1 -1
- package/dist/components/text-editor/shiki/version.js +1 -1
- package/dist/components/text-editor/table-cell-menu-button.svelte +228 -0
- package/dist/components/text-editor/table-cell-menu-button.svelte.d.ts +12 -0
- package/dist/components/text-editor/table.d.ts +18 -0
- package/dist/components/text-editor/table.js +277 -0
- package/dist/components/text-editor/text-editor.svelte +5 -0
- package/dist/components/text-editor/toolbar/align-menu-button.svelte +84 -0
- package/dist/components/text-editor/toolbar/align-menu-button.svelte.d.ts +10 -0
- package/dist/components/text-editor/toolbar/insert-horizontal-rule-button.svelte +65 -0
- package/dist/components/text-editor/toolbar/insert-horizontal-rule-button.svelte.d.ts +30 -0
- package/dist/components/text-editor/toolbar/insert-link-button.svelte +17 -1
- package/dist/components/text-editor/toolbar/insert-table-button.svelte +209 -0
- package/dist/components/text-editor/toolbar/insert-table-button.svelte.d.ts +24 -0
- package/dist/components/text-editor/toolbar/menu.d.ts +1 -0
- package/dist/components/text-editor/toolbar/menu.js +32 -0
- package/dist/components/text-editor/toolbar/table-action-menu.svelte +96 -0
- package/dist/components/text-editor/toolbar/table-action-menu.svelte.d.ts +21 -0
- package/dist/components/text-editor/toolbar/text-editor-toolbar.svelte +75 -7
- package/dist/components/text-editor/transformers/hr.d.ts +5 -0
- package/dist/components/text-editor/transformers/hr.js +7 -1
- package/dist/components/text-editor/transformers/table.js +3 -2
- package/dist/locales/ar.yaml +28 -0
- package/dist/locales/bg.yaml +28 -0
- package/dist/locales/ca.yaml +28 -0
- package/dist/locales/cs.yaml +28 -0
- package/dist/locales/da.yaml +28 -0
- package/dist/locales/de.yaml +28 -0
- package/dist/locales/el.yaml +28 -0
- package/dist/locales/en-CA.yaml +28 -0
- package/dist/locales/en-GB.yaml +28 -0
- package/dist/locales/en-US.yaml +28 -0
- package/dist/locales/es-CO.yaml +28 -0
- package/dist/locales/fa.yaml +28 -0
- package/dist/locales/fi.yaml +28 -0
- package/dist/locales/fr.yaml +28 -0
- package/dist/locales/he.yaml +28 -0
- package/dist/locales/hr.yaml +28 -0
- package/dist/locales/it.yaml +28 -0
- package/dist/locales/ja.yaml +28 -0
- package/dist/locales/ko.yaml +28 -0
- package/dist/locales/nl.yaml +28 -0
- package/dist/locales/pl.yaml +28 -0
- package/dist/locales/pt-BR.yaml +28 -0
- package/dist/locales/pt-PT.yaml +28 -0
- package/dist/locales/ru.yaml +28 -0
- package/dist/locales/sk.yaml +28 -0
- package/dist/locales/sv.yaml +28 -0
- package/dist/locales/tr.yaml +28 -0
- package/dist/locales/uk.yaml +28 -0
- package/dist/locales/vi.yaml +28 -0
- package/dist/locales/zh-CN.yaml +28 -0
- package/dist/locales/zh-TW.yaml +28 -0
- package/dist/services/group.svelte.js +6 -1
- package/dist/typedefs.d.ts +10 -1
- package/dist/typedefs.js +5 -1
- package/package.json +4 -4
|
@@ -31,7 +31,7 @@ declare const Drawer: import("svelte").Component<ModalProps & {
|
|
|
31
31
|
/**
|
|
32
32
|
* Position of the drawer.
|
|
33
33
|
*/
|
|
34
|
-
position?: "
|
|
34
|
+
position?: "left" | "right" | "top" | "bottom" | undefined;
|
|
35
35
|
/**
|
|
36
36
|
* Width or height of the
|
|
37
37
|
* drawer.
|
|
@@ -97,7 +97,7 @@ type Props = {
|
|
|
97
97
|
/**
|
|
98
98
|
* Position of the drawer.
|
|
99
99
|
*/
|
|
100
|
-
position?: "
|
|
100
|
+
position?: "left" | "right" | "top" | "bottom" | undefined;
|
|
101
101
|
/**
|
|
102
102
|
* Width or height of the
|
|
103
103
|
* drawer.
|
|
@@ -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
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text alignment helpers for the rich text editor. Alignment is only available for HTML, as
|
|
3
|
+
* Markdown has no syntax for it. Functions starting with `$` must be called within an editor update
|
|
4
|
+
* or read.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { $findMatchingParent as findMatchingParent } from '@lexical/utils';
|
|
8
|
+
import {
|
|
9
|
+
$getSelection as getSelection,
|
|
10
|
+
$isElementNode as isElementNode,
|
|
11
|
+
$isRangeSelection as isRangeSelection,
|
|
12
|
+
} from 'lexical';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @import { ElementFormatType, ElementNode } from 'lexical';
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Get the text alignment of the block the selection’s anchor is in, like a paragraph, a heading or
|
|
20
|
+
* a list item.
|
|
21
|
+
* @returns {ElementFormatType} Alignment. An empty string means the default alignment, as well as
|
|
22
|
+
* no selection.
|
|
23
|
+
*/
|
|
24
|
+
export const $getSelectedAlignment = () => {
|
|
25
|
+
const selection = getSelection();
|
|
26
|
+
|
|
27
|
+
if (!isRangeSelection(selection)) {
|
|
28
|
+
return '';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const block = /** @type {ElementNode | null} */ (
|
|
32
|
+
findMatchingParent(
|
|
33
|
+
selection.anchor.getNode(),
|
|
34
|
+
(node) => isElementNode(node) && !node.isInline(),
|
|
35
|
+
)
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
// The caret can be on the root itself, between blocks, like next to a horizontal rule
|
|
39
|
+
return block?.getFormatType() ?? '';
|
|
40
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for inserting block nodes, like a table or a horizontal rule, into the rich text editor.
|
|
3
|
+
* Functions starting with `$` must be called within an editor update.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { $createHorizontalRuleNode as createHorizontalRuleNode } from '@lexical/extension';
|
|
7
|
+
import { $insertNodeToNearestRoot as insertNodeToNearestRoot } from '@lexical/utils';
|
|
8
|
+
import {
|
|
9
|
+
$createParagraphNode as createParagraphNode,
|
|
10
|
+
$getPreviousSelection as getPreviousSelection,
|
|
11
|
+
$getSelection as getSelection,
|
|
12
|
+
$isElementNode as isElementNode,
|
|
13
|
+
$isParagraphNode as isParagraphNode,
|
|
14
|
+
$isRangeSelection as isRangeSelection,
|
|
15
|
+
$isRootNode as isRootNode,
|
|
16
|
+
$setSelection as setSelection,
|
|
17
|
+
} from 'lexical';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @import { LexicalNode } from 'lexical';
|
|
21
|
+
* @import { HorizontalRuleNode } from '@lexical/extension';
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Insert the given block node at the selection, which is restored if the focus has moved to the
|
|
26
|
+
* toolbar or a dialog in the meantime. The node takes the place of the empty paragraph the caret is
|
|
27
|
+
* in, rather than leaving the paragraph above it. Otherwise, the block the caret is in is split at
|
|
28
|
+
* the caret, and the node is inserted in between.
|
|
29
|
+
* @template {LexicalNode} T
|
|
30
|
+
* @param {T} node Node.
|
|
31
|
+
* @returns {T} The node, once inserted.
|
|
32
|
+
*/
|
|
33
|
+
export const $insertBlockNode = (node) => {
|
|
34
|
+
const selection = getSelection() ?? getPreviousSelection();
|
|
35
|
+
|
|
36
|
+
if (selection && !getSelection()) {
|
|
37
|
+
setSelection(selection.clone());
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const anchor = isRangeSelection(selection) ? selection.anchor.getNode() : null;
|
|
41
|
+
|
|
42
|
+
if (isParagraphNode(anchor) && anchor.isEmpty() && isRootNode(anchor.getParent())) {
|
|
43
|
+
return anchor.replace(node);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return insertNodeToNearestRoot(node);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Insert a horizontal rule at the selection, and move the caret to the start of the block after it,
|
|
51
|
+
* or a new paragraph if there’s none to type in.
|
|
52
|
+
* @returns {HorizontalRuleNode} The rule.
|
|
53
|
+
*/
|
|
54
|
+
export const $insertHorizontalRule = () => {
|
|
55
|
+
const rule = $insertBlockNode(createHorizontalRuleNode());
|
|
56
|
+
const next = rule.getNextSibling();
|
|
57
|
+
|
|
58
|
+
if (isElementNode(next)) {
|
|
59
|
+
next.selectStart();
|
|
60
|
+
} else {
|
|
61
|
+
rule.insertAfter(createParagraphNode()).selectStart();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return rule;
|
|
65
|
+
};
|
|
@@ -44,9 +44,10 @@ export const NODE_MAP: Record<Exclude<TextEditorBlockType | "link", "paragraph">
|
|
|
44
44
|
/**
|
|
45
45
|
* Map of Lexical transformers for each block type. The `paragraph` block type is excluded because
|
|
46
46
|
* it is the default block type.
|
|
47
|
-
* @type {Record<Exclude<TextEditorNodeType, 'paragraph'>,
|
|
47
|
+
* @type {Record<Exclude<TextEditorNodeType, 'paragraph' | 'table' | 'horizontal-rule' | 'align'>,
|
|
48
|
+
* Transformer[]>}
|
|
48
49
|
*/
|
|
49
|
-
export const TRANSFORMER_MAP: Record<Exclude<TextEditorNodeType, "paragraph">, Transformer[]>;
|
|
50
|
+
export const TRANSFORMER_MAP: Record<Exclude<TextEditorNodeType, "paragraph" | "table" | "horizontal-rule" | "align">, Transformer[]>;
|
|
50
51
|
/**
|
|
51
52
|
* List of Markdown tags that should be disabled in the editor when converting Lexical nodes to
|
|
52
53
|
* Markdown (but not when converting Markdown to Lexical nodes because we don’t want to lose any
|
|
@@ -69,6 +70,25 @@ export const IMPORT_UPDATE_TAG: "sui-import";
|
|
|
69
70
|
* @type {LexicalCommand<void>}
|
|
70
71
|
*/
|
|
71
72
|
export const OPEN_LINK_EDITOR_COMMAND: LexicalCommand<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Text alignments offered by the alignment menu, which is only available for HTML, as Markdown
|
|
75
|
+
* has no syntax for alignment. Like most editors, it offers the physical sides rather than the
|
|
76
|
+
* logical `start` and `end`, which are still kept as is when the HTML has them.
|
|
77
|
+
* @type {{ type: 'left' | 'center' | 'right' | 'justify', labelKey: string, icon: string }[]}
|
|
78
|
+
*/
|
|
79
|
+
export const ALIGNMENT_OPTIONS: {
|
|
80
|
+
type: "left" | "center" | "right" | "justify";
|
|
81
|
+
labelKey: string;
|
|
82
|
+
icon: string;
|
|
83
|
+
}[];
|
|
84
|
+
/**
|
|
85
|
+
* Default number of rows, including the header row, and columns of a new table.
|
|
86
|
+
*/
|
|
87
|
+
export const DEFAULT_TABLE_SIZE: 3;
|
|
88
|
+
/**
|
|
89
|
+
* Maximum number of rows and columns of a new table.
|
|
90
|
+
*/
|
|
91
|
+
export const MAX_TABLE_SIZE: 50;
|
|
72
92
|
import type { EditorThemeClasses } from 'lexical';
|
|
73
93
|
import type { TextEditorFormatType } from '../../typedefs.js';
|
|
74
94
|
import type { TextEditorInlineType } from '../../typedefs.js';
|
|
@@ -49,6 +49,11 @@ export const EDITOR_THEME = {
|
|
|
49
49
|
},
|
|
50
50
|
},
|
|
51
51
|
code: 'code-block',
|
|
52
|
+
// Lexical wraps a table with an element to scroll it horizontally when the table button is
|
|
53
|
+
// enabled; see `initEditor()`
|
|
54
|
+
tableScrollableWrapper: 'table-wrapper',
|
|
55
|
+
tableCellSelected: 'selected',
|
|
56
|
+
tableSelection: 'table-selection',
|
|
52
57
|
};
|
|
53
58
|
|
|
54
59
|
/**
|
|
@@ -136,6 +141,16 @@ export const AVAILABLE_BUTTONS = {
|
|
|
136
141
|
icon: 'code_blocks',
|
|
137
142
|
inline: false,
|
|
138
143
|
},
|
|
144
|
+
table: {
|
|
145
|
+
labelKey: 'insert_table',
|
|
146
|
+
icon: 'table',
|
|
147
|
+
inline: false,
|
|
148
|
+
},
|
|
149
|
+
'horizontal-rule': {
|
|
150
|
+
labelKey: 'insert_horizontal_rule',
|
|
151
|
+
icon: 'horizontal_rule',
|
|
152
|
+
inline: false,
|
|
153
|
+
},
|
|
139
154
|
};
|
|
140
155
|
|
|
141
156
|
/**
|
|
@@ -187,7 +202,8 @@ export const NODE_MAP = {
|
|
|
187
202
|
/**
|
|
188
203
|
* Map of Lexical transformers for each block type. The `paragraph` block type is excluded because
|
|
189
204
|
* it is the default block type.
|
|
190
|
-
* @type {Record<Exclude<TextEditorNodeType, 'paragraph'>,
|
|
205
|
+
* @type {Record<Exclude<TextEditorNodeType, 'paragraph' | 'table' | 'horizontal-rule' | 'align'>,
|
|
206
|
+
* Transformer[]>}
|
|
191
207
|
*/
|
|
192
208
|
export const TRANSFORMER_MAP = {
|
|
193
209
|
// ELEMENT_TRANSFORMERS
|
|
@@ -247,3 +263,26 @@ export const IMPORT_UPDATE_TAG = 'sui-import';
|
|
|
247
263
|
* @type {LexicalCommand<void>}
|
|
248
264
|
*/
|
|
249
265
|
export const OPEN_LINK_EDITOR_COMMAND = createCommand('OPEN_LINK_EDITOR_COMMAND');
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Text alignments offered by the alignment menu, which is only available for HTML, as Markdown
|
|
269
|
+
* has no syntax for alignment. Like most editors, it offers the physical sides rather than the
|
|
270
|
+
* logical `start` and `end`, which are still kept as is when the HTML has them.
|
|
271
|
+
* @type {{ type: 'left' | 'center' | 'right' | 'justify', labelKey: string, icon: string }[]}
|
|
272
|
+
*/
|
|
273
|
+
export const ALIGNMENT_OPTIONS = [
|
|
274
|
+
{ type: 'left', labelKey: 'align_left', icon: 'format_align_left' },
|
|
275
|
+
{ type: 'center', labelKey: 'align_center', icon: 'format_align_center' },
|
|
276
|
+
{ type: 'right', labelKey: 'align_right', icon: 'format_align_right' },
|
|
277
|
+
{ type: 'justify', labelKey: 'align_justify', icon: 'format_align_justify' },
|
|
278
|
+
];
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Default number of rows, including the header row, and columns of a new table.
|
|
282
|
+
*/
|
|
283
|
+
export const DEFAULT_TABLE_SIZE = 3;
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Maximum number of rows and columns of a new table.
|
|
287
|
+
*/
|
|
288
|
+
export const MAX_TABLE_SIZE = 50;
|
|
@@ -24,9 +24,16 @@ export type InitEditorResult = {
|
|
|
24
24
|
*/
|
|
25
25
|
dispose: () => void;
|
|
26
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* Payload of `TOGGLE_LINK_COMMAND` with the URL and the link attributes, like `target`.
|
|
29
|
+
*/
|
|
30
|
+
export type LinkAttributesWithURL = LinkAttributes & {
|
|
31
|
+
url: string;
|
|
32
|
+
};
|
|
27
33
|
import type { LexicalEditor } from 'lexical';
|
|
28
34
|
import type { TextEditorSelectionState } from '../../typedefs.js';
|
|
29
35
|
import type { Transformer } from '@lexical/markdown';
|
|
30
36
|
import type { TextEditorValueFormat } from '../../typedefs.js';
|
|
31
37
|
import type { TextEditorComponent } from '../../typedefs.js';
|
|
32
38
|
import type { TextEditorConfig } from '../../typedefs.js';
|
|
39
|
+
import type { LinkAttributes } from '@lexical/link';
|