@sveltia/ui 0.88.0 → 0.88.1

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.
@@ -35,6 +35,14 @@
35
35
 
36
36
  const loading = $derived(items.length > loadedItemSize);
37
37
 
38
+ /**
39
+ * The scroll container found for the spinner, kept once found. Looking it up reads the computed
40
+ * style and the scroll size of every ancestor, which forces a layout each time a chunk has been
41
+ * rendered. The list only grows from then on, so a container that scrolls keeps doing so.
42
+ * @type {HTMLElement | null}
43
+ */
44
+ let scrollContainer = null;
45
+
38
46
  /**
39
47
  * Get the nearest ancestor of the given element that scrolls vertically. An ancestor that can
40
48
  * scroll but whose content fits, like one growing with the list or a horizontal scroller, doesn’t
@@ -80,7 +88,7 @@
80
88
  loadedItemSize += itemChunkSize;
81
89
  }
82
90
  },
83
- { root: getScrollContainer(spinner), rootMargin: '0px 0px 500px 0px' },
91
+ { root: (scrollContainer ??= getScrollContainer(spinner)), rootMargin: '0px 0px 500px 0px' },
84
92
  );
85
93
 
86
94
  observer.observe(spinner);
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * Version of this package, used to resolve the prebuilt Shiki engine chunk from a CDN.
3
3
  */
4
- export const UI_VERSION: "0.88.0";
4
+ export const UI_VERSION: "0.88.1";
@@ -3,4 +3,4 @@
3
3
  /**
4
4
  * Version of this package, used to resolve the prebuilt Shiki engine chunk from a CDN.
5
5
  */
6
- export const UI_VERSION = '0.88.0';
6
+ export const UI_VERSION = '0.88.1';
@@ -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[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltia/ui",
3
- "version": "0.88.0",
3
+ "version": "0.88.1",
4
4
  "description": "A collection of Svelte components and utilities for building user interfaces.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -62,7 +62,7 @@
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",
65
+ "@sveltia/utils": "^0.13.0",
66
66
  "lexical": "^0.52.0"
67
67
  },
68
68
  "devDependencies": {
@@ -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",