@augment-vir/web 31.72.1 → 31.73.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.
@@ -0,0 +1,2 @@
1
+ import { type MaybePromise } from '@augment-vir/common';
2
+ export declare function listenToElementDisconnect(element: Element, listener: () => MaybePromise<void>): () => void;
@@ -0,0 +1,21 @@
1
+ export function listenToElementDisconnect(element, listener) {
2
+ if (!element.isConnected) {
3
+ /**
4
+ * If the element already is not connected, immediately fire the listener and then do
5
+ * nothing else.
6
+ */
7
+ void listener();
8
+ return () => { };
9
+ }
10
+ const observer = new MutationObserver(async () => {
11
+ if (!element.isConnected) {
12
+ observer.disconnect();
13
+ await listener();
14
+ }
15
+ });
16
+ observer.observe(document.body, {
17
+ childList: true,
18
+ subtree: true,
19
+ });
20
+ return () => observer.disconnect();
21
+ }
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export * from './augments/elements/element-position.js';
6
6
  export * from './augments/elements/element-text.js';
7
7
  export * from './augments/elements/element-visibility.js';
8
8
  export * from './augments/elements/event-target.js';
9
+ export * from './augments/elements/listen-to-disconnect.js';
9
10
  export * from './augments/elements/overflow.js';
10
11
  export * from './augments/elements/query-through-shadow.js';
11
12
  export * from './augments/elements/tag-or-definition.js';
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ export * from './augments/elements/element-position.js';
6
6
  export * from './augments/elements/element-text.js';
7
7
  export * from './augments/elements/element-visibility.js';
8
8
  export * from './augments/elements/event-target.js';
9
+ export * from './augments/elements/listen-to-disconnect.js';
9
10
  export * from './augments/elements/overflow.js';
10
11
  export * from './augments/elements/query-through-shadow.js';
11
12
  export * from './augments/elements/tag-or-definition.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/web",
3
- "version": "31.72.1",
3
+ "version": "31.73.0",
4
4
  "description": "A collection of augments, helpers types, functions, and classes only for web (frontend) JavaScript environments.",
5
5
  "keywords": [
6
6
  "augment",
@@ -36,14 +36,14 @@
36
36
  "test:update": "npm test"
37
37
  },
38
38
  "dependencies": {
39
- "@augment-vir/assert": "^31.72.1",
40
- "@augment-vir/common": "^31.72.1",
39
+ "@augment-vir/assert": "^31.73.0",
40
+ "@augment-vir/common": "^31.73.0",
41
41
  "@date-vir/duration": "^8.3.2",
42
42
  "html-spec-tags": "^2.2.3",
43
43
  "type-fest": "^5.6.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@augment-vir/test": "^31.72.1",
46
+ "@augment-vir/test": "^31.73.0",
47
47
  "bowser": "^2.14.1",
48
48
  "typescript": "^5.9.3"
49
49
  },