element-vir 16.4.7 → 16.5.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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PartInfo } from 'lit/directive.js';
|
|
2
2
|
export type OnResizeCallback = (
|
|
3
3
|
/** Only these two properties are supported in all major modern browsers */
|
|
4
|
-
|
|
4
|
+
size: Readonly<Pick<ResizeObserverEntry, 'target' | 'contentRect'>>, element: Element) => void;
|
|
5
5
|
export declare const onResize: (callback: OnResizeCallback) => import("lit-html/directive").DirectiveResult<{
|
|
6
6
|
new (partInfo: PartInfo): {
|
|
7
7
|
element: Element | undefined;
|
|
@@ -15,19 +15,20 @@ class extends Directive {
|
|
|
15
15
|
console.error(entries);
|
|
16
16
|
throw new Error(`${directiveName} observation triggered but the first entry was empty.`);
|
|
17
17
|
}
|
|
18
|
-
this.callback?.({ target: resizeEntry.target, contentRect: resizeEntry.contentRect });
|
|
18
|
+
this.callback?.({ target: resizeEntry.target, contentRect: resizeEntry.contentRect }, this.element);
|
|
19
19
|
}
|
|
20
20
|
update(partInfo, [callback]) {
|
|
21
21
|
assertIsElementPartInfo(partInfo, directiveName);
|
|
22
22
|
this.callback = callback;
|
|
23
23
|
const newElement = partInfo.element;
|
|
24
|
+
const oldElement = this.element;
|
|
24
25
|
// if the element changes we need to observe the new one
|
|
25
|
-
if (newElement !==
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
if (newElement !== oldElement) {
|
|
27
|
+
this.element = newElement;
|
|
28
|
+
if (oldElement) {
|
|
29
|
+
this.resizeObserver.unobserve(oldElement);
|
|
28
30
|
}
|
|
29
31
|
this.resizeObserver.observe(newElement);
|
|
30
|
-
this.element = newElement;
|
|
31
32
|
}
|
|
32
33
|
return this.render(callback);
|
|
33
34
|
}
|