@sveltia/ui 0.88.1 → 0.88.3
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/listbox/option.svelte +7 -4
- package/dist/components/resizable-pane/resizable-handle.svelte +15 -7
- package/dist/components/resizable-pane/resizable-pane-group.svelte +204 -20
- package/dist/components/resizable-pane/resizable-pane.svelte +25 -6
- package/dist/components/scroll/infinite-scroll.svelte +32 -11
- package/dist/components/slider/slider.svelte +10 -1
- package/dist/components/text-editor/core.js +30 -7
- package/dist/components/text-editor/markdown.d.ts +1 -1
- package/dist/components/text-editor/markdown.js +137 -59
- 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/transformers/block-escape.d.ts +4 -0
- package/dist/components/text-editor/transformers/block-escape.js +53 -2
- package/dist/components/text-editor/transformers/raw-syntax.js +70 -8
- package/dist/components/text-editor/transformers/table.js +43 -3
- package/dist/components/text-field/emoji-autocomplete.svelte +11 -9
- package/dist/components/text-field/masked-input.svelte +1 -13
- package/dist/components/text-field/text-input.svelte +1 -1
- package/dist/components/toast/toast.svelte +19 -8
- package/dist/components/tree/tree-item.svelte +7 -4
- package/dist/components/util/popup.svelte +1 -1
- package/dist/services/popup-position.js +20 -10
- package/dist/services/popup.svelte.d.ts +10 -1
- package/dist/services/popup.svelte.js +18 -5
- package/dist/services/tree.svelte.js +23 -7
- package/dist/typedefs.d.ts +9 -4
- package/dist/typedefs.js +6 -3
- package/package.json +15 -15
|
@@ -244,13 +244,23 @@
|
|
|
244
244
|
* @type {HTMLElement | undefined}
|
|
245
245
|
*/
|
|
246
246
|
let toast = $state();
|
|
247
|
+
/**
|
|
248
|
+
* Whether the pointer is over the toast.
|
|
249
|
+
* @type {boolean}
|
|
250
|
+
*/
|
|
251
|
+
let hovered = $state(false);
|
|
252
|
+
/**
|
|
253
|
+
* Whether the focus is inside the toast.
|
|
254
|
+
* @type {boolean}
|
|
255
|
+
*/
|
|
256
|
+
let focused = $state(false);
|
|
247
257
|
/**
|
|
248
258
|
* Whether the pointer is over the toast or the focus is inside it. The auto-hide countdown is
|
|
249
259
|
* held while it is, so a toast with a control in it can’t vanish from under the user (WCAG
|
|
250
|
-
* 2.2.1).
|
|
251
|
-
*
|
|
260
|
+
* 2.2.1). Both are tracked apart, so the pointer leaving doesn’t release the hold of the focus,
|
|
261
|
+
* or the other way around.
|
|
252
262
|
*/
|
|
253
|
-
|
|
263
|
+
const held = $derived(hovered || focused);
|
|
254
264
|
/**
|
|
255
265
|
* Whether the content is in the DOM tree. It lags behind {@link show} on the way out, so the
|
|
256
266
|
* toast can fade before the content goes. On the way in, the content is inserted rather than
|
|
@@ -304,7 +314,8 @@
|
|
|
304
314
|
toast.remove();
|
|
305
315
|
// A detached element gets no `pointerleave` or `focusout`, so release the hold here, or the
|
|
306
316
|
// countdown would never start the next time the toast is shown
|
|
307
|
-
|
|
317
|
+
hovered = false;
|
|
318
|
+
focused = false;
|
|
308
319
|
|
|
309
320
|
// Close the base once the last toast is gone
|
|
310
321
|
if (!popover.querySelector('.toast') && popover.matches(':popover-open')) {
|
|
@@ -374,16 +385,16 @@
|
|
|
374
385
|
class={['sui', 'toast', position]}
|
|
375
386
|
aria-hidden={!show}
|
|
376
387
|
onpointerenter={() => {
|
|
377
|
-
|
|
388
|
+
hovered = true;
|
|
378
389
|
}}
|
|
379
390
|
onpointerleave={() => {
|
|
380
|
-
|
|
391
|
+
hovered = false;
|
|
381
392
|
}}
|
|
382
393
|
onfocusin={() => {
|
|
383
|
-
|
|
394
|
+
focused = true;
|
|
384
395
|
}}
|
|
385
396
|
onfocusout={(event) => {
|
|
386
|
-
|
|
397
|
+
focused = !!event.relatedTarget && !!toast?.contains(/** @type {Node} */ (event.relatedTarget));
|
|
387
398
|
}}
|
|
388
399
|
>
|
|
389
400
|
{#if rendered}
|
|
@@ -55,10 +55,8 @@
|
|
|
55
55
|
hidden = false,
|
|
56
56
|
disabled = false,
|
|
57
57
|
label = '',
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
// svelte-ignore state_referenced_locally
|
|
61
|
-
valueType = getValueType(value),
|
|
58
|
+
value: _value = undefined,
|
|
59
|
+
valueType: _valueType = undefined,
|
|
62
60
|
children,
|
|
63
61
|
items,
|
|
64
62
|
startIcon,
|
|
@@ -72,6 +70,11 @@
|
|
|
72
70
|
} = $props();
|
|
73
71
|
|
|
74
72
|
const id = $props.id();
|
|
73
|
+
|
|
74
|
+
// The label is the default, followed when it changes, like on a locale switch. A prop fallback
|
|
75
|
+
// would only take its first value
|
|
76
|
+
const value = $derived(_value === undefined ? label : _value);
|
|
77
|
+
const valueType = $derived(_valueType === undefined ? getValueType(value) : _valueType);
|
|
75
78
|
/** Nesting level of the item, starting with 1 for the root level items. */
|
|
76
79
|
const level = /** @type {number} */ (getContext('sui:tree-item-level') ?? 0) + 1;
|
|
77
80
|
|
|
@@ -152,7 +152,7 @@
|
|
|
152
152
|
// a nested popup shares the `<dialog>` with its parent and only the content is its own.
|
|
153
153
|
$effect(() => {
|
|
154
154
|
if (popupInstance && dialogElement && content) {
|
|
155
|
-
popupInstance.attachPopupElement(dialogElement, content);
|
|
155
|
+
popupInstance.attachPopupElement(dialogElement, content, { nested: !!parentDialogElement });
|
|
156
156
|
|
|
157
157
|
return () => {
|
|
158
158
|
popupInstance?.detachPopupElement();
|
|
@@ -176,17 +176,27 @@ export const calculatePopupStyle = ({
|
|
|
176
176
|
flipVertically('-bottom', '-top', upwardMargin, downwardMargin);
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
// If the popup overflows the viewport,
|
|
179
|
+
// If the popup overflows the viewport, align it with the anchor’s other edge, but only when that
|
|
180
|
+
// side has more room. Checking each side on its own would flip a popup that fits neither way
|
|
181
|
+
// over and straight back, leaving it on whichever side was checked last
|
|
180
182
|
if (position.endsWith('-left')) {
|
|
181
|
-
|
|
182
|
-
position
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
183
|
+
({ position } = flip({
|
|
184
|
+
position,
|
|
185
|
+
from: '-left',
|
|
186
|
+
to: '-right',
|
|
187
|
+
size: contentWidth,
|
|
188
|
+
room: viewport.width - rect.left - 8,
|
|
189
|
+
otherRoom: rect.right - 8,
|
|
190
|
+
}));
|
|
191
|
+
} else if (position.endsWith('-right')) {
|
|
192
|
+
({ position } = flip({
|
|
193
|
+
position,
|
|
194
|
+
from: '-right',
|
|
195
|
+
to: '-left',
|
|
196
|
+
size: contentWidth,
|
|
197
|
+
room: rect.right - 8,
|
|
198
|
+
otherRoom: viewport.width - rect.left - 8,
|
|
199
|
+
}));
|
|
190
200
|
}
|
|
191
201
|
|
|
192
202
|
// The two checks above align a dropdown that opens below or above its anchor, so neither
|
|
@@ -45,6 +45,11 @@ declare class Popup {
|
|
|
45
45
|
* @type {HTMLElement | undefined}
|
|
46
46
|
*/
|
|
47
47
|
contentElement: HTMLElement | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Whether the {@link popupElement} is shared with a parent popup, as a submenu’s is.
|
|
50
|
+
* @type {boolean}
|
|
51
|
+
*/
|
|
52
|
+
nested: boolean;
|
|
48
53
|
/**
|
|
49
54
|
* ID of the animation frame requested to recalculate the position after a resize.
|
|
50
55
|
* @type {number}
|
|
@@ -64,8 +69,12 @@ declare class Popup {
|
|
|
64
69
|
* popup shares this with its parent, so it must not be labelled as belonging to this popup.
|
|
65
70
|
* @param {HTMLElement} [contentElement] Element holding this popup’s content. When omitted, the
|
|
66
71
|
* `popupElement` is assumed to hold the content on its own.
|
|
72
|
+
* @param {object} [options] Options.
|
|
73
|
+
* @param {boolean} [options.nested] Whether the `popupElement` is shared with a parent popup.
|
|
67
74
|
*/
|
|
68
|
-
attachPopupElement(popupElement: HTMLDialogElement, contentElement?: HTMLElement
|
|
75
|
+
attachPopupElement(popupElement: HTMLDialogElement, contentElement?: HTMLElement, { nested }?: {
|
|
76
|
+
nested?: boolean | undefined;
|
|
77
|
+
}): void;
|
|
69
78
|
/**
|
|
70
79
|
* Detach the `<dialog>` element, typically because it’s being unmounted. The anchor’s
|
|
71
80
|
* `aria-controls` attribute is removed as well, since the content is leaving the DOM tree.
|
|
@@ -80,6 +80,12 @@ class Popup {
|
|
|
80
80
|
*/
|
|
81
81
|
contentElement = undefined;
|
|
82
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Whether the {@link popupElement} is shared with a parent popup, as a submenu’s is.
|
|
85
|
+
* @type {boolean}
|
|
86
|
+
*/
|
|
87
|
+
nested = false;
|
|
88
|
+
|
|
83
89
|
/**
|
|
84
90
|
* Function that removes the event listeners added to the current {@link popupElement}.
|
|
85
91
|
* @type {(() => void) | undefined}
|
|
@@ -217,8 +223,10 @@ class Popup {
|
|
|
217
223
|
* popup shares this with its parent, so it must not be labelled as belonging to this popup.
|
|
218
224
|
* @param {HTMLElement} [contentElement] Element holding this popup’s content. When omitted, the
|
|
219
225
|
* `popupElement` is assumed to hold the content on its own.
|
|
226
|
+
* @param {object} [options] Options.
|
|
227
|
+
* @param {boolean} [options.nested] Whether the `popupElement` is shared with a parent popup.
|
|
220
228
|
*/
|
|
221
|
-
attachPopupElement(popupElement, contentElement) {
|
|
229
|
+
attachPopupElement(popupElement, contentElement, { nested = false } = {}) {
|
|
222
230
|
if (this.popupElement === popupElement && this.contentElement === contentElement) {
|
|
223
231
|
return;
|
|
224
232
|
}
|
|
@@ -226,6 +234,7 @@ class Popup {
|
|
|
226
234
|
this.detachPopupElement();
|
|
227
235
|
this.popupElement = popupElement;
|
|
228
236
|
this.contentElement = contentElement;
|
|
237
|
+
this.nested = nested;
|
|
229
238
|
this.viewportResizeObserver.observe(popupElement);
|
|
230
239
|
|
|
231
240
|
// Identify the popup by the element that actually holds its content. Labelling the `<dialog>`
|
|
@@ -372,16 +381,20 @@ class Popup {
|
|
|
372
381
|
* Hide the popup immediately (when the anchor is being hidden).
|
|
373
382
|
*/
|
|
374
383
|
async hideImmediately() {
|
|
375
|
-
|
|
376
|
-
|
|
384
|
+
// A submenu only hides its own content, not the `<dialog>` it shares with its parent menu,
|
|
385
|
+
// which would make the whole menu blink and drop the focus in it
|
|
386
|
+
const element = this.nested ? this.contentElement : this.popupElement;
|
|
387
|
+
|
|
388
|
+
if (element) {
|
|
389
|
+
element.hidden = true;
|
|
377
390
|
}
|
|
378
391
|
|
|
379
392
|
this.open = false;
|
|
380
393
|
await sleep(50);
|
|
381
394
|
|
|
382
395
|
// The element may have been unmounted in the meantime
|
|
383
|
-
if (
|
|
384
|
-
|
|
396
|
+
if (element?.isConnected) {
|
|
397
|
+
element.hidden = false;
|
|
385
398
|
}
|
|
386
399
|
}
|
|
387
400
|
|
|
@@ -79,7 +79,9 @@ export class Tree {
|
|
|
79
79
|
/** @type {(event: FocusEvent) => void} */
|
|
80
80
|
this._onFocusIn = activateBefore(this, (event) => this.onFocusIn(event));
|
|
81
81
|
|
|
82
|
-
// The items can be added or removed at any time, e.g. when a subtree is lazily rendered
|
|
82
|
+
// The items can be added or removed at any time, e.g. when a subtree is lazily rendered, and
|
|
83
|
+
// collapsed, hidden or disabled from outside, e.g. with a “collapse all” button, which can take
|
|
84
|
+
// the tab stop out of reach
|
|
83
85
|
this.observer = new globalThis.MutationObserver(() => {
|
|
84
86
|
this.update();
|
|
85
87
|
});
|
|
@@ -110,7 +112,12 @@ export class Tree {
|
|
|
110
112
|
|
|
111
113
|
this.activated = true;
|
|
112
114
|
this.update();
|
|
113
|
-
this.observer.observe(parent, {
|
|
115
|
+
this.observer.observe(parent, {
|
|
116
|
+
childList: true,
|
|
117
|
+
subtree: true,
|
|
118
|
+
attributes: true,
|
|
119
|
+
attributeFilter: ['hidden', 'aria-hidden', 'aria-disabled', 'aria-expanded'],
|
|
120
|
+
});
|
|
114
121
|
parent.dispatchEvent(new CustomEvent('Initialized'));
|
|
115
122
|
}
|
|
116
123
|
|
|
@@ -181,11 +188,14 @@ export class Tree {
|
|
|
181
188
|
|
|
182
189
|
const item = /** @type {HTMLElement} */ (child);
|
|
183
190
|
|
|
184
|
-
|
|
185
|
-
|
|
191
|
+
// A hidden item hides everything below it, and so does a collapsed parent, so there is
|
|
192
|
+
// nothing to descend into
|
|
193
|
+
if (item.matches('[hidden], [aria-hidden="true"]')) {
|
|
194
|
+
return;
|
|
186
195
|
}
|
|
187
196
|
|
|
188
|
-
|
|
197
|
+
items.push(item);
|
|
198
|
+
|
|
189
199
|
if (this.isParent(item) && !this.isExpanded(item)) {
|
|
190
200
|
return;
|
|
191
201
|
}
|
|
@@ -560,7 +570,8 @@ export class Tree {
|
|
|
560
570
|
/** @type {HTMLElement} */ (event.target).closest(ITEM_SELECTOR)
|
|
561
571
|
);
|
|
562
572
|
|
|
563
|
-
|
|
573
|
+
// A disabled item can still take focus from a click, but it’s never the tab stop
|
|
574
|
+
if (!item || item.matches('[aria-disabled="true"]')) {
|
|
564
575
|
return;
|
|
565
576
|
}
|
|
566
577
|
|
|
@@ -624,7 +635,12 @@ export class Tree {
|
|
|
624
635
|
/** @type {HTMLElement} */ (event.target).closest(ITEM_SELECTOR)
|
|
625
636
|
);
|
|
626
637
|
|
|
627
|
-
|
|
638
|
+
// Keys pressed on a disabled item, which a click can focus, act on the tab stop instead
|
|
639
|
+
const currentItem =
|
|
640
|
+
(target && activeItems.includes(target) ? target : undefined) ??
|
|
641
|
+
this.currentItem ??
|
|
642
|
+
activeItems[0];
|
|
643
|
+
|
|
628
644
|
const index = activeItems.indexOf(currentItem);
|
|
629
645
|
// In RTL, the Left and Right arrow keys are swapped
|
|
630
646
|
const { prevKey: backwardKey, nextKey: forwardKey } = getArrowKeys('horizontal', isRTL());
|
package/dist/typedefs.d.ts
CHANGED
|
@@ -1162,16 +1162,21 @@ export type PaneGroupContext = {
|
|
|
1162
1162
|
*/
|
|
1163
1163
|
sizes: number[];
|
|
1164
1164
|
/**
|
|
1165
|
-
* Register a pane
|
|
1166
|
-
*
|
|
1165
|
+
* Register a pane. The index is its current position among the panes, which changes
|
|
1166
|
+
* as panes are shown and hidden. `unregister` removes the pane, giving its space to the others.
|
|
1167
1167
|
*/
|
|
1168
1168
|
registerPane: (def: ResizablePaneDefinition) => {
|
|
1169
1169
|
index: number;
|
|
1170
|
+
unregister: () => void;
|
|
1170
1171
|
};
|
|
1171
1172
|
/**
|
|
1172
|
-
* Register a resize handle
|
|
1173
|
+
* Register a resize handle with a function
|
|
1174
|
+
* to get its element. The index is its current position among the handles.
|
|
1173
1175
|
*/
|
|
1174
|
-
registerHandle: () =>
|
|
1176
|
+
registerHandle: (getElement: () => HTMLElement | undefined) => {
|
|
1177
|
+
index: number;
|
|
1178
|
+
unregister: () => void;
|
|
1179
|
+
};
|
|
1175
1180
|
/**
|
|
1176
1181
|
* Resize panes around a
|
|
1177
1182
|
* handle by the given delta.
|
package/dist/typedefs.js
CHANGED
|
@@ -511,9 +511,12 @@
|
|
|
511
511
|
* @typedef {object} PaneGroupContext
|
|
512
512
|
* @property {'horizontal' | 'vertical'} direction Layout direction of the panes.
|
|
513
513
|
* @property {number[]} sizes Current pane sizes as percentages.
|
|
514
|
-
* @property {(def: ResizablePaneDefinition) => { index: number
|
|
515
|
-
*
|
|
516
|
-
*
|
|
514
|
+
* @property {(def: ResizablePaneDefinition) => { index: number, unregister: () => void }}
|
|
515
|
+
* registerPane Register a pane. The index is its current position among the panes, which changes
|
|
516
|
+
* as panes are shown and hidden. `unregister` removes the pane, giving its space to the others.
|
|
517
|
+
* @property {(getElement: () => HTMLElement | undefined) => {
|
|
518
|
+
* index: number, unregister: () => void }} registerHandle Register a resize handle with a function
|
|
519
|
+
* to get its element. The index is its current position among the handles.
|
|
517
520
|
* @property {(handleIndex: number, deltaPercent: number) => void} resize Resize panes around a
|
|
518
521
|
* handle by the given delta.
|
|
519
522
|
* @property {(handleIndex: number) => void} toggleCollapse Toggle collapse of the primary pane
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltia/ui",
|
|
3
|
-
"version": "0.88.
|
|
3
|
+
"version": "0.88.3",
|
|
4
4
|
"description": "A collection of Svelte components and utilities for building user interfaces.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -47,23 +47,23 @@
|
|
|
47
47
|
"!dist/test-utils"
|
|
48
48
|
],
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@lexical/code-core": "^0.
|
|
51
|
-
"@lexical/dragon": "^0.
|
|
52
|
-
"@lexical/extension": "^0.
|
|
53
|
-
"@lexical/history": "^0.
|
|
54
|
-
"@lexical/html": "^0.
|
|
55
|
-
"@lexical/link": "^0.
|
|
56
|
-
"@lexical/list": "^0.
|
|
57
|
-
"@lexical/markdown": "^0.
|
|
58
|
-
"@lexical/rich-text": "^0.
|
|
59
|
-
"@lexical/selection": "^0.
|
|
60
|
-
"@lexical/table": "^0.
|
|
61
|
-
"@lexical/utils": "^0.
|
|
50
|
+
"@lexical/code-core": "^0.53.0",
|
|
51
|
+
"@lexical/dragon": "^0.53.0",
|
|
52
|
+
"@lexical/extension": "^0.53.0",
|
|
53
|
+
"@lexical/history": "^0.53.0",
|
|
54
|
+
"@lexical/html": "^0.53.0",
|
|
55
|
+
"@lexical/link": "^0.53.0",
|
|
56
|
+
"@lexical/list": "^0.53.0",
|
|
57
|
+
"@lexical/markdown": "^0.53.0",
|
|
58
|
+
"@lexical/rich-text": "^0.53.0",
|
|
59
|
+
"@lexical/selection": "^0.53.0",
|
|
60
|
+
"@lexical/table": "^0.53.0",
|
|
61
|
+
"@lexical/utils": "^0.53.0",
|
|
62
62
|
"@shikijs/langs": "4.5.0",
|
|
63
63
|
"@shikijs/themes": "4.5.0",
|
|
64
64
|
"@sveltia/i18n": "^1.5.0",
|
|
65
|
-
"@sveltia/utils": "^0.13.
|
|
66
|
-
"lexical": "^0.
|
|
65
|
+
"@sveltia/utils": "^0.13.1",
|
|
66
|
+
"lexical": "^0.53.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@fontsource-variable/material-symbols-outlined": "5.3.9",
|