@momentum-design/components 0.129.36 → 0.129.38

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 (35) hide show
  1. package/dist/browser/index.js +263 -264
  2. package/dist/browser/index.js.map +4 -4
  3. package/dist/components/bullet/bullet.component.d.ts +16 -6
  4. package/dist/components/bullet/bullet.component.js +16 -6
  5. package/dist/components/bullet/bullet.styles.js +5 -6
  6. package/dist/components/divider/divider.component.d.ts +50 -55
  7. package/dist/components/divider/divider.component.js +50 -55
  8. package/dist/components/marker/marker.component.d.ts +20 -15
  9. package/dist/components/marker/marker.component.js +20 -15
  10. package/dist/components/popover/popover.component.d.ts +5 -2
  11. package/dist/components/popover/popover.component.js +39 -21
  12. package/dist/components/popover/popover.constants.d.ts +6 -1
  13. package/dist/components/popover/popover.constants.js +6 -1
  14. package/dist/components/staticcheckbox/staticcheckbox.component.d.ts +22 -11
  15. package/dist/components/staticcheckbox/staticcheckbox.component.js +22 -11
  16. package/dist/components/staticradio/staticradio.component.d.ts +21 -11
  17. package/dist/components/staticradio/staticradio.component.js +21 -11
  18. package/dist/components/statictoggle/statictoggle.component.d.ts +25 -12
  19. package/dist/components/statictoggle/statictoggle.component.js +25 -12
  20. package/dist/custom-elements.json +169 -79
  21. package/dist/react/bullet/index.d.ts +16 -6
  22. package/dist/react/bullet/index.js +16 -6
  23. package/dist/react/divider/index.d.ts +33 -38
  24. package/dist/react/divider/index.js +33 -38
  25. package/dist/react/marker/index.d.ts +17 -12
  26. package/dist/react/marker/index.js +17 -12
  27. package/dist/react/staticcheckbox/index.d.ts +22 -11
  28. package/dist/react/staticcheckbox/index.js +22 -11
  29. package/dist/react/staticradio/index.d.ts +21 -11
  30. package/dist/react/staticradio/index.js +21 -11
  31. package/dist/react/statictoggle/index.d.ts +25 -12
  32. package/dist/react/statictoggle/index.js +25 -12
  33. package/dist/utils/controllers/Timers.d.ts +49 -0
  34. package/dist/utils/controllers/Timers.js +96 -0
  35. package/package.json +1 -1
@@ -0,0 +1,49 @@
1
+ import { ReactiveController, type ReactiveControllerHost } from 'lit';
2
+ /**
3
+ * Handle setTimeout and setInterval timers for a host, automatically clearing them on disconnect.
4
+ */
5
+ export declare class Timers implements ReactiveController {
6
+ private nameToIntervalId;
7
+ private nameToTimeoutId;
8
+ constructor(host: ReactiveControllerHost);
9
+ hostDisconnected(): void;
10
+ /**
11
+ * Wrapper around `window.setInterval` that tracks the interval ID for cleanup on disconnect.
12
+ * If an interval with the same name already exists, it is cleared before setting the new one.
13
+ *
14
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval}
15
+ * @param name - Name to identify the interval timer
16
+ * @param handler - Function that is called every `ms` milliseconds
17
+ * @param ms - Delay in milliseconds between each call to `handler`
18
+ * @param args - Additional arguments passed to `handler`
19
+ * @returns The interval ID returned by `window.setInterval`
20
+ */
21
+ setInterval<TArgs extends any[]>(name: string, handler: (...args: TArgs) => void, ms?: number, ...args: TArgs): number;
22
+ /**
23
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/clearInterval}
24
+ * @param id - The name or ID of the interval to clear
25
+ */
26
+ clearInterval(id: string | number): void;
27
+ /**
28
+ * Wrapper around `window.setTimeout` that tracks the timeout ID for cleanup on disconnect.
29
+ * If a timeout with the same name already exists, it is cleared before setting the new one.
30
+ * When the timeout executes, it removes itself from the tracking map.
31
+ *
32
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout}
33
+ * @param name - Name to identify the timeout
34
+ * @param handler - Function that is called after `ms` milliseconds
35
+ * @param ms - Delay in milliseconds before calling `handler`
36
+ * @param args - Additional arguments passed to `handler`
37
+ * @returns The timeout id returned by `window.setTimeout`
38
+ */
39
+ setTimeout<TArgs extends any[]>(name: string, handler: (...args: TArgs) => void, ms?: number, ...args: TArgs): number;
40
+ /**
41
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/clearTimeout}
42
+ * @param id - The name or ID of the timeout to clear
43
+ */
44
+ clearTimeout(id: string | number): void;
45
+ /**
46
+ * @internal
47
+ */
48
+ private getNameAndIdFromIdentifier;
49
+ }
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Handle setTimeout and setInterval timers for a host, automatically clearing them on disconnect.
3
+ */
4
+ export class Timers {
5
+ constructor(host) {
6
+ this.nameToIntervalId = new Map();
7
+ this.nameToTimeoutId = new Map();
8
+ host.addController(this);
9
+ }
10
+ hostDisconnected() {
11
+ [...this.nameToIntervalId.values()].forEach(clearInterval);
12
+ this.nameToIntervalId.clear();
13
+ [...this.nameToTimeoutId.values()].forEach(clearTimeout);
14
+ this.nameToTimeoutId.clear();
15
+ }
16
+ /**
17
+ * Wrapper around `window.setInterval` that tracks the interval ID for cleanup on disconnect.
18
+ * If an interval with the same name already exists, it is cleared before setting the new one.
19
+ *
20
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval}
21
+ * @param name - Name to identify the interval timer
22
+ * @param handler - Function that is called every `ms` milliseconds
23
+ * @param ms - Delay in milliseconds between each call to `handler`
24
+ * @param args - Additional arguments passed to `handler`
25
+ * @returns The interval ID returned by `window.setInterval`
26
+ */
27
+ setInterval(name, handler, ms, ...args) {
28
+ if (this.nameToIntervalId.has(name)) {
29
+ clearInterval(this.nameToIntervalId.get(name));
30
+ }
31
+ const id = window.setInterval(handler, ms, ...args);
32
+ this.nameToIntervalId.set(name, id);
33
+ return id;
34
+ }
35
+ /**
36
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/clearInterval}
37
+ * @param id - The name or ID of the interval to clear
38
+ */
39
+ clearInterval(id) {
40
+ const [intervalName, intervalId] = this.getNameAndIdFromIdentifier(this.nameToIntervalId, id);
41
+ if (intervalId !== undefined) {
42
+ clearInterval(intervalId);
43
+ }
44
+ if (intervalName) {
45
+ this.nameToIntervalId.delete(intervalName);
46
+ }
47
+ }
48
+ /**
49
+ * Wrapper around `window.setTimeout` that tracks the timeout ID for cleanup on disconnect.
50
+ * If a timeout with the same name already exists, it is cleared before setting the new one.
51
+ * When the timeout executes, it removes itself from the tracking map.
52
+ *
53
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout}
54
+ * @param name - Name to identify the timeout
55
+ * @param handler - Function that is called after `ms` milliseconds
56
+ * @param ms - Delay in milliseconds before calling `handler`
57
+ * @param args - Additional arguments passed to `handler`
58
+ * @returns The timeout id returned by `window.setTimeout`
59
+ */
60
+ setTimeout(name, handler, ms, ...args) {
61
+ if (this.nameToTimeoutId.has(name)) {
62
+ clearTimeout(this.nameToTimeoutId.get(name));
63
+ }
64
+ const id = window.setTimeout((...args) => {
65
+ handler(...args);
66
+ this.nameToTimeoutId.delete(name);
67
+ }, ms, ...args);
68
+ this.nameToTimeoutId.set(name, id);
69
+ return id;
70
+ }
71
+ /**
72
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/clearTimeout}
73
+ * @param id - The name or ID of the timeout to clear
74
+ */
75
+ clearTimeout(id) {
76
+ const [timeoutName, timeoutId] = this.getNameAndIdFromIdentifier(this.nameToTimeoutId, id);
77
+ if (timeoutId !== undefined) {
78
+ window.clearTimeout(timeoutId);
79
+ }
80
+ if (timeoutName) {
81
+ this.nameToTimeoutId.delete(timeoutName);
82
+ }
83
+ }
84
+ /**
85
+ * @internal
86
+ */
87
+ getNameAndIdFromIdentifier(map, id) {
88
+ var _a;
89
+ if (typeof id === 'number') {
90
+ const timerId = id;
91
+ const timerName = (_a = [...map.entries()].find(([, value]) => value === id)) === null || _a === void 0 ? void 0 : _a[0];
92
+ return [timerName, timerId];
93
+ }
94
+ return [id, map.get(id)];
95
+ }
96
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@momentum-design/components",
3
3
  "packageManager": "yarn@3.2.4",
4
- "version": "0.129.36",
4
+ "version": "0.129.38",
5
5
  "engines": {
6
6
  "node": ">=20.0.0",
7
7
  "npm": ">=8.0.0"