bits-ui 1.0.0-next.0 → 1.0.0-next.2
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.
- package/dist/bits/link-preview/link-preview.svelte.js +2 -1
- package/dist/bits/listbox/listbox.svelte.js +1 -0
- package/dist/bits/menu/components/menu-sub-content.svelte +1 -0
- package/dist/bits/menu/menu.svelte.d.ts +7 -1
- package/dist/bits/menu/menu.svelte.js +7 -3
- package/dist/bits/select/select.svelte.js +8 -9
- package/dist/bits/utilities/popper-layer/popper-layer.svelte +3 -1
- package/dist/bits/utilities/scroll-lock/scroll-lock.svelte +1 -6
- package/package.json +1 -1
|
@@ -9,6 +9,7 @@ import { getTabbableCandidates } from "../../internal/focus.js";
|
|
|
9
9
|
import { createContext } from "../../internal/createContext.js";
|
|
10
10
|
import { useGraceArea } from "../../internal/useGraceArea.svelte.js";
|
|
11
11
|
import { onDestroyEffect } from "../../internal/onDestroyEffect.svelte.js";
|
|
12
|
+
import { afterSleep } from "../../internal/afterSleep.js";
|
|
12
13
|
const CONTENT_ATTR = "data-link-preview-content";
|
|
13
14
|
const TRIGGER_ATTR = "data-link-preview-trigger";
|
|
14
15
|
class LinkPreviewRootState {
|
|
@@ -35,7 +36,7 @@ class LinkPreviewRootState {
|
|
|
35
36
|
const handlePointerUp = () => {
|
|
36
37
|
this.containsSelection = false;
|
|
37
38
|
this.isPointerDownOnContent = false;
|
|
38
|
-
|
|
39
|
+
afterSleep(1, () => {
|
|
39
40
|
const isSelection = document.getSelection()?.toString() !== "";
|
|
40
41
|
if (isSelection) {
|
|
41
42
|
this.hasSelection = true;
|
|
@@ -86,7 +86,9 @@ declare class MenuContentState {
|
|
|
86
86
|
open: boolean;
|
|
87
87
|
};
|
|
88
88
|
props: {
|
|
89
|
-
readonly [x: string]: string | ((e: KeyboardEvent) => void) | ((e: PointerEvent) => void)
|
|
89
|
+
readonly [x: string]: string | ((e: KeyboardEvent) => void) | ((e: PointerEvent) => void) | {
|
|
90
|
+
readonly pointerEvents: "auto";
|
|
91
|
+
};
|
|
90
92
|
readonly id: string;
|
|
91
93
|
readonly role: "menu";
|
|
92
94
|
readonly "aria-orientation": "horizontal" | "vertical";
|
|
@@ -95,6 +97,10 @@ declare class MenuContentState {
|
|
|
95
97
|
readonly onblur: (e: FocusEvent) => void;
|
|
96
98
|
readonly onpointermove: (e: PointerEvent) => void;
|
|
97
99
|
readonly onfocus: () => void;
|
|
100
|
+
readonly dir: Direction;
|
|
101
|
+
readonly style: {
|
|
102
|
+
readonly pointerEvents: "auto";
|
|
103
|
+
};
|
|
98
104
|
};
|
|
99
105
|
createItem(props: MenuItemSharedStateProps & MenuItemStateProps): MenuItemState;
|
|
100
106
|
createCheckboxItem(props: MenuItemSharedStateProps & MenuItemStateProps & MenuCheckboxItemStateProps): MenuCheckboxItemState;
|
|
@@ -310,6 +310,10 @@ class MenuContentState {
|
|
|
310
310
|
onblur: this.#onblur,
|
|
311
311
|
onpointermove: this.#onpointermove,
|
|
312
312
|
onfocus: this.#onfocus,
|
|
313
|
+
dir: this.parentMenu.root.dir.current,
|
|
314
|
+
style: {
|
|
315
|
+
pointerEvents: "auto",
|
|
316
|
+
},
|
|
313
317
|
}));
|
|
314
318
|
createItem(props) {
|
|
315
319
|
const item = new MenuItemSharedState(props, this);
|
|
@@ -420,7 +424,7 @@ class MenuItemState {
|
|
|
420
424
|
return;
|
|
421
425
|
e.currentTarget.click();
|
|
422
426
|
/**
|
|
423
|
-
* We prevent default browser
|
|
427
|
+
* We prevent default browser behavior for selection keys as they should trigger
|
|
424
428
|
* a selection only:
|
|
425
429
|
* - prevents space from scrolling the page.
|
|
426
430
|
* - if keydown causes focus to move, prevents keydown from firing on the new target.
|
|
@@ -467,9 +471,9 @@ class MenuItemState {
|
|
|
467
471
|
}
|
|
468
472
|
class MenuSubTriggerState {
|
|
469
473
|
#item;
|
|
470
|
-
// The menu this
|
|
474
|
+
// The menu this sub-trigger item belongs within
|
|
471
475
|
#content;
|
|
472
|
-
// the menu this
|
|
476
|
+
// the menu this sub-trigger item opens
|
|
473
477
|
#submenu;
|
|
474
478
|
#openTimer = $state(null);
|
|
475
479
|
constructor(item, content, submenu) {
|
|
@@ -18,6 +18,7 @@ import { clamp } from "../../internal/clamp.js";
|
|
|
18
18
|
import { noop } from "../../internal/callbacks.js";
|
|
19
19
|
import { addEventListener } from "../../internal/events.js";
|
|
20
20
|
import { sleep } from "../../internal/sleep.js";
|
|
21
|
+
import { afterSleep } from "../../internal/afterSleep.js";
|
|
21
22
|
export const OPEN_KEYS = [kbd.SPACE, kbd.ENTER, kbd.ARROW_UP, kbd.ARROW_DOWN];
|
|
22
23
|
export const SELECTION_KEYS = [" ", kbd.ENTER];
|
|
23
24
|
export const CONTENT_MARGIN = 10;
|
|
@@ -78,11 +79,11 @@ export class SelectRootState {
|
|
|
78
79
|
};
|
|
79
80
|
focusTriggerNode = (preventScroll = true) => {
|
|
80
81
|
const node = this.triggerNode;
|
|
81
|
-
if (node)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
});
|
|
85
|
-
}
|
|
82
|
+
if (!node)
|
|
83
|
+
return;
|
|
84
|
+
afterSleep(1, () => {
|
|
85
|
+
node.focus({ preventScroll });
|
|
86
|
+
});
|
|
86
87
|
};
|
|
87
88
|
onNativeOptionAdd = (option) => {
|
|
88
89
|
this.#nativeOptionsSet.set(option.current.value, option);
|
|
@@ -94,15 +95,13 @@ export class SelectRootState {
|
|
|
94
95
|
const node = this.contentFragment;
|
|
95
96
|
if (!node)
|
|
96
97
|
return [];
|
|
97
|
-
|
|
98
|
-
return candidates;
|
|
98
|
+
return Array.from(node.querySelectorAll(`[${ITEM_ATTR}]:not([data-disabled])`));
|
|
99
99
|
};
|
|
100
100
|
getCandidateNodes = () => {
|
|
101
101
|
const node = this.contentNode;
|
|
102
102
|
if (!node)
|
|
103
103
|
return [];
|
|
104
|
-
|
|
105
|
-
return candidates;
|
|
104
|
+
return Array.from(node.querySelectorAll(`[${ITEM_ATTR}]:not([data-disabled])`));
|
|
106
105
|
};
|
|
107
106
|
createTrigger(props) {
|
|
108
107
|
return new SelectTriggerState(props, this);
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { untrack } from "svelte";
|
|
3
2
|
import type { ScrollLockProps } from "./index.js";
|
|
4
3
|
import { useBodyScrollLock } from "../../../internal/useBodyScrollLock.svelte.js";
|
|
5
4
|
|
|
6
5
|
let { preventScroll = true }: ScrollLockProps = $props();
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
if (preventScroll) {
|
|
10
|
-
untrack(() => useBodyScrollLock(preventScroll));
|
|
11
|
-
}
|
|
12
|
-
});
|
|
7
|
+
useBodyScrollLock(preventScroll);
|
|
13
8
|
</script>
|