@sveltia/ui 0.88.0 → 0.88.2

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.
Files changed (28) hide show
  1. package/dist/components/listbox/option.svelte +7 -4
  2. package/dist/components/resizable-pane/resizable-handle.svelte +15 -7
  3. package/dist/components/resizable-pane/resizable-pane-group.svelte +204 -20
  4. package/dist/components/resizable-pane/resizable-pane.svelte +25 -6
  5. package/dist/components/scroll/infinite-scroll.svelte +36 -7
  6. package/dist/components/slider/slider.svelte +10 -1
  7. package/dist/components/text-editor/core.js +30 -7
  8. package/dist/components/text-editor/markdown.d.ts +1 -1
  9. package/dist/components/text-editor/markdown.js +137 -59
  10. package/dist/components/text-editor/shiki/version.d.ts +1 -1
  11. package/dist/components/text-editor/shiki/version.js +1 -1
  12. package/dist/components/text-editor/transformers/block-escape.d.ts +4 -0
  13. package/dist/components/text-editor/transformers/block-escape.js +53 -2
  14. package/dist/components/text-editor/transformers/raw-syntax.js +70 -8
  15. package/dist/components/text-editor/transformers/table.js +43 -3
  16. package/dist/components/text-field/masked-input.svelte +1 -13
  17. package/dist/components/text-field/text-input.svelte +1 -1
  18. package/dist/components/toast/toast.svelte +19 -8
  19. package/dist/components/tree/tree-item.svelte +7 -4
  20. package/dist/components/util/popup.svelte +1 -1
  21. package/dist/services/group.svelte.js +32 -1
  22. package/dist/services/popup-position.js +20 -10
  23. package/dist/services/popup.svelte.d.ts +10 -1
  24. package/dist/services/popup.svelte.js +18 -5
  25. package/dist/services/tree.svelte.js +23 -7
  26. package/dist/typedefs.d.ts +9 -4
  27. package/dist/typedefs.js +6 -3
  28. package/package.json +20 -20
@@ -55,10 +55,8 @@
55
55
  hidden = false,
56
56
  disabled = false,
57
57
  label = '',
58
- // svelte-ignore state_referenced_locally
59
- value = label,
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();
@@ -362,6 +362,10 @@ export class Group {
362
362
  // the cached lists. Only the attributes that decide membership are watched, so the group’s own
363
363
  // writes — the selected state and the roving `tabindex` — don’t needlessly discard the cache.
364
364
  this.observer = new globalThis.MutationObserver((records) => {
365
+ if (!this.#affectsMembers(records)) {
366
+ return;
367
+ }
368
+
365
369
  this.#memberCache = undefined;
366
370
 
367
371
  // Members rendered after activation — rows that arrive with the data, say — start out with
@@ -567,7 +571,7 @@ export class Group {
567
571
  * @type {{ all: HTMLElement[], active: HTMLElement[] }}
568
572
  */
569
573
  get #members() {
570
- if (this.observer.takeRecords().length) {
574
+ if (this.#affectsMembers(this.observer.takeRecords())) {
571
575
  this.#memberCache = undefined;
572
576
  }
573
577
 
@@ -583,6 +587,33 @@ export class Group {
583
587
  return this.#memberCache;
584
588
  }
585
589
 
590
+ /**
591
+ * Check whether any of the given mutations adds, removes, disables or hides a member. The subtree
592
+ * is observed as a whole, so most changes happen inside a member — a cell rendering its content,
593
+ * an image arriving — and leave the member lists as they were. Recomputing the lists, and the
594
+ * roving tab stop with them, on each of those would cost a query over every member of a widget
595
+ * that can hold thousands.
596
+ * @param {MutationRecord[]} records Mutations.
597
+ * @returns {boolean} Whether the member lists may have changed.
598
+ */
599
+ #affectsMembers(records) {
600
+ const { selector } = this;
601
+
602
+ /**
603
+ * Check whether the given node is a member or holds one.
604
+ * @param {Node} node Node.
605
+ * @returns {boolean} Result.
606
+ */
607
+ const hasMember = (node) =>
608
+ node instanceof Element && (node.matches(selector) || !!node.querySelector(selector));
609
+
610
+ return records.some(({ type, target, addedNodes, removedNodes }) =>
611
+ type === 'attributes'
612
+ ? target instanceof Element && target.matches(selector)
613
+ : [...addedNodes].some(hasMember) || [...removedNodes].some(hasMember),
614
+ );
615
+ }
616
+
586
617
  /**
587
618
  * List of all the members.
588
619
  * @type {HTMLElement[]}
@@ -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, change the position
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
- if (rect.left + contentWidth > viewport.width - 8) {
182
- position = /** @type {PopupPosition} */ (position.replace('-left', '-right'));
183
- }
184
- }
185
-
186
- if (position.endsWith('-right')) {
187
- if (rect.right - contentWidth < 8) {
188
- position = /** @type {PopupPosition} */ (position.replace('-right', '-left'));
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): void;
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
- if (this.popupElement) {
376
- this.popupElement.hidden = true;
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 (this.popupElement) {
384
- this.popupElement.hidden = false;
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, { childList: true, subtree: true });
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
- if (!item.matches('[hidden], [aria-hidden="true"]')) {
185
- items.push(item);
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
- // A collapsed parent hides everything below it, so there is nothing to descend into
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
- if (!item) {
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
- const currentItem = target ?? this.currentItem ?? activeItems[0];
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());
@@ -1162,16 +1162,21 @@ export type PaneGroupContext = {
1162
1162
  */
1163
1163
  sizes: number[];
1164
1164
  /**
1165
- * Register a pane and
1166
- * return its index.
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 and return its index.
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: () => number;
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 }} registerPane Register a pane and
515
- * return its index.
516
- * @property {() => number} registerHandle Register a resize handle and return its index.
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.0",
3
+ "version": "0.88.2",
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.52.0",
51
- "@lexical/dragon": "^0.52.0",
52
- "@lexical/extension": "^0.52.0",
53
- "@lexical/history": "^0.52.0",
54
- "@lexical/html": "^0.52.0",
55
- "@lexical/link": "^0.52.0",
56
- "@lexical/list": "^0.52.0",
57
- "@lexical/markdown": "^0.52.0",
58
- "@lexical/rich-text": "^0.52.0",
59
- "@lexical/selection": "^0.52.0",
60
- "@lexical/table": "^0.52.0",
61
- "@lexical/utils": "^0.52.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.12.4",
66
- "lexical": "^0.52.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",
@@ -82,13 +82,13 @@
82
82
  "eslint-config-prettier": "^10.1.8",
83
83
  "eslint-plugin-import": "^2.32.0",
84
84
  "eslint-plugin-jsdoc": "^65.4.2",
85
- "eslint-plugin-package-json": "^1.11.0",
85
+ "eslint-plugin-package-json": "^1.12.0",
86
86
  "eslint-plugin-svelte": "^3.23.1",
87
87
  "globals": "^17.13.0",
88
88
  "happy-dom": "^21.0.4",
89
- "oxlint": "^1.89.0",
89
+ "oxlint": "^1.90.0",
90
90
  "playwright": "^1.64.1",
91
- "postcss": "^8.5.31",
91
+ "postcss": "^8.5.32",
92
92
  "postcss-html": "^2.0.0",
93
93
  "prettier": "^3.9.10",
94
94
  "prettier-plugin-svelte": "^4.1.1",
@@ -97,8 +97,8 @@
97
97
  "shiki": "^4.5.0",
98
98
  "stylelint": "^17.16.0",
99
99
  "stylelint-config-recommended-scss": "^17.0.1",
100
- "stylelint-scss": "^7.3.0",
101
- "svelte": "^5.57.2",
100
+ "stylelint-scss": "^7.4.0",
101
+ "svelte": "^5.57.3",
102
102
  "svelte-check": "^4.7.7",
103
103
  "svelte-preprocess": "^6.0.5",
104
104
  "tslib": "^2.8.1",