@canonical/svelte-ds-app-launchpad 0.45.0 → 0.47.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.
@@ -151,7 +151,7 @@
151
151
  Tooltip requires JavaScript to function correctly. If JavaScript is disabled, the tooltip content will not be accessible.
152
152
  TODO(no-js): Investigate how to handle tooltips without JavaScript.
153
153
 
154
- The tooltip enables a short "chaining" window (~350ms) after it closes. If any tooltip's trigger is hovered or focused within this window, the tooltip bypasses `delay` and opens immediately.
154
+ The tooltip enables "chaining" while it is visible and for a short window (~350ms) after the last tooltip closes. If any tooltip's trigger is hovered or focused during this time, the tooltip bypasses `delay` and opens immediately.
155
155
 
156
156
  ## Example Usage
157
157
  ```svelte
@@ -6,7 +6,7 @@ import type { TooltipProps } from "./types.js";
6
6
  * Tooltip requires JavaScript to function correctly. If JavaScript is disabled, the tooltip content will not be accessible.
7
7
  * TODO(no-js): Investigate how to handle tooltips without JavaScript.
8
8
  *
9
- * The tooltip enables a short "chaining" window (~350ms) after it closes. If any tooltip's trigger is hovered or focused within this window, the tooltip bypasses `delay` and opens immediately.
9
+ * The tooltip enables "chaining" while it is visible and for a short window (~350ms) after the last tooltip closes. If any tooltip's trigger is hovered or focused during this time, the tooltip bypasses `delay` and opens immediately.
10
10
  *
11
11
  * ## Example Usage
12
12
  * ```svelte
@@ -1,18 +1,13 @@
1
1
  /**
2
- * Manages the chaining state for tooltips, allowing for a grace period during which tooltips can be shown without delay.
2
+ * Keeps chaining active while any tooltip is visible and for a grace period after the last one closes.
3
3
  */
4
4
  export declare class ChainingManager {
5
- /**
6
- * The duration (in milliseconds) for which chaining remains active after being set to true.
7
- */
8
- private readonly chainingThreshold;
9
- private _chaining;
10
- private chainingTimeout;
5
+ #private;
11
6
  constructor(
12
7
  /**
13
- * The duration (in milliseconds) for which chaining remains active after being set to true.
8
+ * The duration (in milliseconds) for which chaining remains active after the last tooltip closes.
14
9
  */
15
10
  chainingThreshold: number);
16
- set chaining(value: boolean);
17
11
  get chaining(): boolean;
12
+ acquire(): () => void;
18
13
  }
@@ -1,29 +1,37 @@
1
1
  /**
2
- * Manages the chaining state for tooltips, allowing for a grace period during which tooltips can be shown without delay.
2
+ * Keeps chaining active while any tooltip is visible and for a grace period after the last one closes.
3
3
  */
4
4
  export class ChainingManager {
5
- chainingThreshold;
6
- _chaining = false;
7
- chainingTimeout = null;
5
+ #chainingThreshold;
6
+ #activeCount = 0;
7
+ #chainingTimeout = null;
8
8
  constructor(
9
9
  /**
10
- * The duration (in milliseconds) for which chaining remains active after being set to true.
10
+ * The duration (in milliseconds) for which chaining remains active after the last tooltip closes.
11
11
  */
12
12
  chainingThreshold) {
13
- this.chainingThreshold = chainingThreshold;
14
- }
15
- set chaining(value) {
16
- this._chaining = value;
17
- if (this.chainingTimeout !== null)
18
- clearTimeout(this.chainingTimeout);
19
- if (value) {
20
- this.chainingTimeout = setTimeout(() => {
21
- this._chaining = false;
22
- this.chainingTimeout = null;
23
- }, this.chainingThreshold);
24
- }
13
+ this.#chainingThreshold = chainingThreshold;
25
14
  }
26
15
  get chaining() {
27
- return this._chaining;
16
+ return this.#activeCount > 0 || this.#chainingTimeout !== null;
17
+ }
18
+ acquire() {
19
+ if (this.#chainingTimeout !== null) {
20
+ clearTimeout(this.#chainingTimeout);
21
+ this.#chainingTimeout = null;
22
+ }
23
+ this.#activeCount += 1;
24
+ let released = false;
25
+ return () => {
26
+ if (released)
27
+ return;
28
+ released = true;
29
+ this.#activeCount -= 1;
30
+ if (this.#activeCount === 0) {
31
+ this.#chainingTimeout = setTimeout(() => {
32
+ this.#chainingTimeout = null;
33
+ }, this.#chainingThreshold);
34
+ }
35
+ };
28
36
  }
29
37
  }
@@ -4,8 +4,8 @@ import type { ChainingManager } from "./ChainingManager.js";
4
4
  * where successive tooltips open without delay.
5
5
  *
6
6
  * The returned getter reflects whether the tooltip should currently be considered open
7
- * (after any applied delay). When `getOpen()` becomes false the delayed state resets and
8
- * briefly enables chaining for the next open.
7
+ * (after any applied delay). Visible tooltips register with the shared manager
8
+ * until they close or are destroyed.
9
9
  *
10
10
  * @param getOpen - Reactive getter indicating the raw (immediate) open intent.
11
11
  * @param getDelay - Reactive getter providing the delay in milliseconds before showing.
@@ -4,8 +4,8 @@ import { untrack } from "svelte";
4
4
  * where successive tooltips open without delay.
5
5
  *
6
6
  * The returned getter reflects whether the tooltip should currently be considered open
7
- * (after any applied delay). When `getOpen()` becomes false the delayed state resets and
8
- * briefly enables chaining for the next open.
7
+ * (after any applied delay). Visible tooltips register with the shared manager
8
+ * until they close or are destroyed.
9
9
  *
10
10
  * @param getOpen - Reactive getter indicating the raw (immediate) open intent.
11
11
  * @param getDelay - Reactive getter providing the delay in milliseconds before showing.
@@ -29,14 +29,10 @@ export function useDelayedOpen(getOpen, getDelay, chainingManager) {
29
29
  }
30
30
  delayedOpen = false;
31
31
  });
32
- let firstRun = true;
33
32
  $effect(() => {
34
- // Each time the tooltip closes, enable chaining for a short period
35
- // Skip first run. Be sure to read `delayedOpen` first to ensure the effect runs again when it changes
36
- if (!delayedOpen && !firstRun) {
37
- chainingManager.chaining = true;
33
+ if (delayedOpen) {
34
+ return chainingManager.acquire();
38
35
  }
39
- firstRun = false;
40
36
  });
41
37
  return () => delayedOpen;
42
38
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@canonical/svelte-ds-app-launchpad",
3
3
  "description": "Launchpad-specific components for the Pragma design system.",
4
- "version": "0.45.0",
4
+ "version": "0.47.0",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -64,14 +64,14 @@
64
64
  "devDependencies": {
65
65
  "@biomejs/biome": "2.5.15",
66
66
  "@canonical/biome-config": "0.43.0",
67
- "@canonical/storybook-config": "^0.45.0",
68
- "@canonical/storybook-helpers": "^0.45.0",
69
- "@canonical/svelte-ssr-test": "^0.45.0",
70
- "@canonical/typescript-config-svelte": "^0.45.0",
71
- "@canonical/webarchitect": "0.43.0",
67
+ "@canonical/storybook-config": "^0.47.0",
68
+ "@canonical/storybook-helpers": "^0.47.0",
69
+ "@canonical/svelte-ssr-test": "^0.47.0",
70
+ "@canonical/typescript-config-svelte": "^0.47.0",
71
+ "@canonical/webarchitect": "0.44.0",
72
72
  "@storybook/addon-docs": "^10.6.0",
73
73
  "@storybook/addon-svelte-csf": "^5.1.3",
74
- "@sveltejs/package": "3.0.0",
74
+ "@sveltejs/package": "3.0.2",
75
75
  "@sveltejs/vite-plugin-svelte": "^7.0.0",
76
76
  "@types/bun": "^1.3.10",
77
77
  "@vitest/browser": "^5.0.0",
@@ -85,13 +85,13 @@
85
85
  "vitest-browser-svelte": "^3.0.0"
86
86
  },
87
87
  "dependencies": {
88
- "@canonical/design-tokens": "0.43.0",
89
- "@canonical/styles": "^0.45.0",
90
- "@canonical/svelte-icons": "^0.0.9",
88
+ "@canonical/design-tokens": "0.44.0",
89
+ "@canonical/styles": "^0.47.0",
90
+ "@canonical/svelte-icons": "^0.1.0",
91
91
  "@floating-ui/dom": "^1.7.6"
92
92
  },
93
93
  "peerDependencies": {
94
94
  "svelte": "^5.47.1"
95
95
  },
96
- "gitHead": "f8c2473f9aa92d14c24f0976f2f02ebc4944f32f"
96
+ "gitHead": "f846e7e21001a0fcbc4cd9f28c14a55cea7f4974"
97
97
  }