@tableslayer/ui 0.1.23 → 0.1.25
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
|
<script lang="ts">
|
|
2
|
-
import { computePosition, offset, flip, shift,
|
|
2
|
+
import { computePosition, offset, flip, shift, autoUpdate } from '@floating-ui/dom';
|
|
3
3
|
import { Button, type ConfirmActionButtonProps } from './';
|
|
4
|
-
import {
|
|
4
|
+
import { onDestroy } from 'svelte';
|
|
5
5
|
|
|
6
6
|
let {
|
|
7
7
|
trigger,
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
let portalContainer: HTMLDivElement | null = null;
|
|
20
20
|
let isShowingConfirm = $state(false);
|
|
21
21
|
let floatingStyles = $state('');
|
|
22
|
+
let cleanupAutoUpdate: (() => void) | null = null;
|
|
22
23
|
|
|
23
24
|
// Handle portal mounting
|
|
24
25
|
$effect(() => {
|
|
@@ -36,16 +37,31 @@
|
|
|
36
37
|
}
|
|
37
38
|
});
|
|
38
39
|
|
|
40
|
+
// Set up autoUpdate when popover is shown
|
|
41
|
+
$effect(() => {
|
|
42
|
+
if (isShowingConfirm && triggerElement && popoverElement) {
|
|
43
|
+
cleanupAutoUpdate = autoUpdate(triggerElement, popoverElement, updatePosition);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return () => {
|
|
47
|
+
if (cleanupAutoUpdate) {
|
|
48
|
+
cleanupAutoUpdate();
|
|
49
|
+
cleanupAutoUpdate = null;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
|
|
39
54
|
onDestroy(() => {
|
|
40
55
|
if (portalContainer?.parentNode) {
|
|
41
56
|
portalContainer.parentNode.removeChild(portalContainer);
|
|
42
57
|
}
|
|
58
|
+
if (cleanupAutoUpdate) {
|
|
59
|
+
cleanupAutoUpdate();
|
|
60
|
+
}
|
|
43
61
|
});
|
|
44
62
|
|
|
45
63
|
const toggleShowConfirm = async () => {
|
|
46
64
|
isShowingConfirm = true;
|
|
47
|
-
await tick();
|
|
48
|
-
updatePosition();
|
|
49
65
|
};
|
|
50
66
|
|
|
51
67
|
const triggerProps = {
|
|
@@ -61,8 +77,11 @@
|
|
|
61
77
|
|
|
62
78
|
computePosition(triggerElement, popoverElement, {
|
|
63
79
|
placement: positioning?.placement,
|
|
64
|
-
middleware: [
|
|
65
|
-
|
|
80
|
+
middleware: [
|
|
81
|
+
offset(({ rects }) => -rects.reference.height / 2 - rects.floating.height / 2),
|
|
82
|
+
flip({ boundary: document.body }),
|
|
83
|
+
shift({ padding: 8, crossAxis: true, boundary: document.body })
|
|
84
|
+
]
|
|
66
85
|
})
|
|
67
86
|
.then(({ x, y, strategy }) => {
|
|
68
87
|
floatingStyles = `position: ${strategy}; left: ${x}px; top: ${y}px;`;
|