bits-ui 2.9.4 → 2.9.5
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.
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { FloatingLayer } from "../../utilities/floating-layer/index.js";
|
|
7
7
|
|
|
8
8
|
let {
|
|
9
|
+
disabled = false,
|
|
9
10
|
open = $bindable(false),
|
|
10
11
|
onOpenChange = noop,
|
|
11
12
|
onOpenChangeComplete = noop,
|
|
@@ -15,6 +16,7 @@
|
|
|
15
16
|
}: LinkPreviewRootProps = $props();
|
|
16
17
|
|
|
17
18
|
LinkPreviewRootState.create({
|
|
19
|
+
disabled: box.with(() => disabled),
|
|
18
20
|
open: box.with(
|
|
19
21
|
() => open,
|
|
20
22
|
(v) => {
|
|
@@ -3,6 +3,7 @@ import type { BitsFocusEvent, BitsPointerEvent, OnChangeFn, RefAttachment, WithR
|
|
|
3
3
|
interface LinkPreviewRootStateOpts extends WritableBoxedValues<{
|
|
4
4
|
open: boolean;
|
|
5
5
|
}>, ReadableBoxedValues<{
|
|
6
|
+
disabled: boolean;
|
|
6
7
|
openDelay: number;
|
|
7
8
|
closeDelay: number;
|
|
8
9
|
onOpenChangeComplete: OnChangeFn<boolean>;
|
|
@@ -76,7 +76,7 @@ export class LinkPreviewRootState {
|
|
|
76
76
|
}
|
|
77
77
|
handleOpen() {
|
|
78
78
|
this.clearTimeout();
|
|
79
|
-
if (this.opts.open.current)
|
|
79
|
+
if (this.opts.open.current || this.opts.disabled.current)
|
|
80
80
|
return;
|
|
81
81
|
this.isOpening = true;
|
|
82
82
|
this.timeout = this.domContext.setTimeout(() => {
|
|
@@ -11,6 +11,7 @@ const lockMap = new SvelteMap();
|
|
|
11
11
|
let initialBodyStyle = $state(null);
|
|
12
12
|
let stopTouchMoveListener = null;
|
|
13
13
|
let cleanupTimeoutId = null;
|
|
14
|
+
let isInCleanupTransition = false;
|
|
14
15
|
const anyLocked = box.with(() => {
|
|
15
16
|
for (const value of lockMap.values()) {
|
|
16
17
|
if (value)
|
|
@@ -35,7 +36,6 @@ const bodyLockStackCount = new SharedState(() => {
|
|
|
35
36
|
isIOS && stopTouchMoveListener?.();
|
|
36
37
|
// reset initialBodyStyle so next locker captures the correct styles
|
|
37
38
|
initialBodyStyle = null;
|
|
38
|
-
hasEverBeenLocked = false;
|
|
39
39
|
}
|
|
40
40
|
function cancelPendingCleanup() {
|
|
41
41
|
if (cleanupTimeoutId === null)
|
|
@@ -45,6 +45,7 @@ const bodyLockStackCount = new SharedState(() => {
|
|
|
45
45
|
}
|
|
46
46
|
function scheduleCleanupIfNoNewLocks(delay, callback) {
|
|
47
47
|
cancelPendingCleanup();
|
|
48
|
+
isInCleanupTransition = true;
|
|
48
49
|
cleanupScheduledAt = Date.now();
|
|
49
50
|
const currentCleanupId = cleanupScheduledAt;
|
|
50
51
|
/**
|
|
@@ -64,24 +65,20 @@ const bodyLockStackCount = new SharedState(() => {
|
|
|
64
65
|
return;
|
|
65
66
|
// ensure no new locks were added during the delay
|
|
66
67
|
if (!isAnyLocked(lockMap)) {
|
|
68
|
+
isInCleanupTransition = false;
|
|
67
69
|
callback();
|
|
68
70
|
}
|
|
71
|
+
else {
|
|
72
|
+
isInCleanupTransition = false;
|
|
73
|
+
}
|
|
69
74
|
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// to handle same-tick destroy/create scenarios (~1 frame)
|
|
73
|
-
cleanupTimeoutId = window.setTimeout(cleanupFn, 16);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
cleanupTimeoutId = window.setTimeout(cleanupFn, delay);
|
|
77
|
-
}
|
|
75
|
+
const actualDelay = delay === null ? 24 : delay;
|
|
76
|
+
cleanupTimeoutId = window.setTimeout(cleanupFn, actualDelay);
|
|
78
77
|
}
|
|
79
|
-
// track if we've ever applied lock styles in this session
|
|
80
|
-
let hasEverBeenLocked = false;
|
|
81
78
|
function ensureInitialStyleCaptured() {
|
|
82
|
-
|
|
79
|
+
// only capture initial style once, when no locks exist and no cleanup is in progress
|
|
80
|
+
if (initialBodyStyle === null && lockMap.size === 0 && !isInCleanupTransition) {
|
|
83
81
|
initialBodyStyle = document.body.getAttribute("style");
|
|
84
|
-
hasEverBeenLocked = true;
|
|
85
82
|
}
|
|
86
83
|
}
|
|
87
84
|
watch(() => anyLocked.current, () => {
|
|
@@ -89,6 +86,8 @@ const bodyLockStackCount = new SharedState(() => {
|
|
|
89
86
|
return;
|
|
90
87
|
// ensure we've captured the initial style before applying any lock styles
|
|
91
88
|
ensureInitialStyleCaptured();
|
|
89
|
+
// if we're applying lock styles, we're no longer in a cleanup transition
|
|
90
|
+
isInCleanupTransition = false;
|
|
92
91
|
const bodyStyle = getComputedStyle(document.body);
|
|
93
92
|
// TODO: account for RTL direction, etc.
|
|
94
93
|
const verticalScrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
|