bits-ui 2.11.0 → 2.11.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/context-menu/components/context-menu-trigger.svelte +8 -1
- package/dist/bits/menu/menu.svelte.js +10 -0
- package/dist/bits/tooltip/tooltip.svelte.js +4 -4
- package/dist/bits/utilities/dismissible-layer/use-dismissable-layer.svelte.d.ts +3 -2
- package/dist/bits/utilities/dismissible-layer/use-dismissable-layer.svelte.js +4 -2
- package/dist/internal/timeout-fn.d.ts +1 -10
- package/dist/internal/timeout-fn.js +3 -10
- package/package.json +1 -1
|
@@ -24,7 +24,14 @@
|
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
const mergedProps = $derived(
|
|
27
|
-
mergeProps(
|
|
27
|
+
mergeProps(
|
|
28
|
+
restProps,
|
|
29
|
+
triggerState.props,
|
|
30
|
+
{ style: { pointerEvents: "auto" } },
|
|
31
|
+
{
|
|
32
|
+
style: restProps.style,
|
|
33
|
+
}
|
|
34
|
+
)
|
|
28
35
|
);
|
|
29
36
|
</script>
|
|
30
37
|
|
|
@@ -13,6 +13,7 @@ import { DOMTypeahead } from "../../internal/dom-typeahead.svelte.js";
|
|
|
13
13
|
import { RovingFocusGroup } from "../../internal/roving-focus-group.js";
|
|
14
14
|
import { GraceArea } from "../../internal/grace-area.svelte.js";
|
|
15
15
|
import { OpenChangeComplete } from "../../internal/open-change-complete.js";
|
|
16
|
+
import { getTopMostDismissableLayer } from "../utilities/dismissible-layer/use-dismissable-layer.svelte.js";
|
|
16
17
|
export const CONTEXT_MENU_TRIGGER_ATTR = "data-context-menu-trigger";
|
|
17
18
|
const MenuRootContext = new Context("Menu.Root");
|
|
18
19
|
const MenuMenuContext = new Context("Menu.Root | Menu.Sub");
|
|
@@ -880,6 +881,15 @@ export class ContextMenuTriggerState {
|
|
|
880
881
|
oncontextmenu(e) {
|
|
881
882
|
if (e.defaultPrevented || this.opts.disabled.current)
|
|
882
883
|
return;
|
|
884
|
+
const topMostLayer = getTopMostDismissableLayer();
|
|
885
|
+
if (topMostLayer) {
|
|
886
|
+
const topLayerRef = topMostLayer[0].opts.ref.current;
|
|
887
|
+
const topLayerRefContainsTrigger = topLayerRef?.contains(this.opts.ref.current);
|
|
888
|
+
if (!topLayerRefContainsTrigger &&
|
|
889
|
+
!topLayerRef?.hasAttribute?.("data-context-menu-content")) {
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
883
893
|
this.#clearLongPressTimer();
|
|
884
894
|
this.#handleOpen(e);
|
|
885
895
|
e.preventDefault();
|
|
@@ -25,7 +25,7 @@ export class TooltipProviderState {
|
|
|
25
25
|
this.opts = opts;
|
|
26
26
|
this.#timerFn = new TimeoutFn(() => {
|
|
27
27
|
this.isOpenDelayed = true;
|
|
28
|
-
}, this.opts.skipDelayDuration.current
|
|
28
|
+
}, this.opts.skipDelayDuration.current);
|
|
29
29
|
}
|
|
30
30
|
#startTimer = () => {
|
|
31
31
|
const skipDuration = this.opts.skipDelayDuration.current;
|
|
@@ -86,7 +86,7 @@ export class TooltipRootState {
|
|
|
86
86
|
this.#timerFn = new TimeoutFn(() => {
|
|
87
87
|
this.#wasOpenDelayed = true;
|
|
88
88
|
this.opts.open.current = true;
|
|
89
|
-
}, this.delayDuration ?? 0
|
|
89
|
+
}, this.delayDuration ?? 0);
|
|
90
90
|
new OpenChangeComplete({
|
|
91
91
|
open: this.opts.open,
|
|
92
92
|
ref: boxWith(() => this.contentNode),
|
|
@@ -100,7 +100,7 @@ export class TooltipRootState {
|
|
|
100
100
|
this.#timerFn = new TimeoutFn(() => {
|
|
101
101
|
this.#wasOpenDelayed = true;
|
|
102
102
|
this.opts.open.current = true;
|
|
103
|
-
}, this.delayDuration
|
|
103
|
+
}, this.delayDuration);
|
|
104
104
|
});
|
|
105
105
|
watch(() => this.opts.open.current, (isOpen) => {
|
|
106
106
|
if (isOpen) {
|
|
@@ -109,7 +109,7 @@ export class TooltipRootState {
|
|
|
109
109
|
else {
|
|
110
110
|
this.provider.onClose(this);
|
|
111
111
|
}
|
|
112
|
-
});
|
|
112
|
+
}, { lazy: true });
|
|
113
113
|
}
|
|
114
114
|
handleOpen = () => {
|
|
115
115
|
this.#timerFn.stop();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type WritableBox, type ReadableBoxedValues } from "svelte-toolbelt";
|
|
2
|
-
import type { DismissibleLayerImplProps } from "./types.js";
|
|
1
|
+
import { type ReadableBox, type WritableBox, type ReadableBoxedValues } from "svelte-toolbelt";
|
|
2
|
+
import type { DismissibleLayerImplProps, InteractOutsideBehaviorType } from "./types.js";
|
|
3
3
|
interface DismissibleLayerStateOpts extends ReadableBoxedValues<Required<Omit<DismissibleLayerImplProps, "children" | "ref">>> {
|
|
4
4
|
ref: WritableBox<HTMLElement | null>;
|
|
5
5
|
}
|
|
@@ -13,6 +13,7 @@ export declare class DismissibleLayerState {
|
|
|
13
13
|
onblurcapture: () => void;
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
+
export declare function getTopMostDismissableLayer(layersArr?: [DismissibleLayerState, ReadableBox<InteractOutsideBehaviorType>][]): [DismissibleLayerState, ReadableBox<InteractOutsideBehaviorType>] | undefined;
|
|
16
17
|
export type FocusOutsideEvent = CustomEvent<{
|
|
17
18
|
originalEvent: FocusEvent;
|
|
18
19
|
}>;
|
|
@@ -166,7 +166,9 @@ export class DismissibleLayerState {
|
|
|
166
166
|
onblurcapture: this.#onblurcapture,
|
|
167
167
|
};
|
|
168
168
|
}
|
|
169
|
-
function
|
|
169
|
+
export function getTopMostDismissableLayer(layersArr = [
|
|
170
|
+
...globalThis.bitsDismissableLayers,
|
|
171
|
+
]) {
|
|
170
172
|
return layersArr.findLast(([_, { current: behaviorType }]) => behaviorType === "close" || behaviorType === "ignore");
|
|
171
173
|
}
|
|
172
174
|
function isResponsibleLayer(node) {
|
|
@@ -177,7 +179,7 @@ function isResponsibleLayer(node) {
|
|
|
177
179
|
* responsible for the outside interaction. Otherwise, we know that all layers defer so
|
|
178
180
|
* the first layer is the responsible one.
|
|
179
181
|
*/
|
|
180
|
-
const topMostLayer =
|
|
182
|
+
const topMostLayer = getTopMostDismissableLayer(layersArr);
|
|
181
183
|
if (topMostLayer)
|
|
182
184
|
return topMostLayer[0].opts.ref.current === node;
|
|
183
185
|
const [firstLayerNode] = layersArr[0];
|
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
import type { AnyFn } from "./types.js";
|
|
2
|
-
type TimeoutFnOptions = {
|
|
3
|
-
/**
|
|
4
|
-
* Start the timer immediate after calling this function
|
|
5
|
-
*
|
|
6
|
-
* @default true
|
|
7
|
-
*/
|
|
8
|
-
immediate?: boolean;
|
|
9
|
-
};
|
|
10
2
|
export declare class TimeoutFn<T extends AnyFn> {
|
|
11
3
|
#private;
|
|
12
|
-
constructor(cb: T, interval: number
|
|
4
|
+
constructor(cb: T, interval: number);
|
|
13
5
|
stop(): void;
|
|
14
6
|
start(...args: Parameters<T> | []): void;
|
|
15
7
|
}
|
|
16
|
-
export {};
|
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
import { onDestroyEffect } from "svelte-toolbelt";
|
|
2
|
-
import { BROWSER } from "esm-env";
|
|
3
|
-
const defaultOpts = {
|
|
4
|
-
immediate: true,
|
|
5
|
-
};
|
|
6
2
|
export class TimeoutFn {
|
|
7
|
-
#opts;
|
|
8
3
|
#interval;
|
|
9
4
|
#cb;
|
|
10
5
|
#timer = null;
|
|
11
|
-
constructor(cb, interval
|
|
6
|
+
constructor(cb, interval) {
|
|
12
7
|
this.#cb = cb;
|
|
13
8
|
this.#interval = interval;
|
|
14
|
-
this.#opts = { ...defaultOpts, ...opts };
|
|
15
9
|
this.stop = this.stop.bind(this);
|
|
16
10
|
this.start = this.start.bind(this);
|
|
17
|
-
if (this.#opts.immediate && BROWSER) {
|
|
18
|
-
this.start();
|
|
19
|
-
}
|
|
20
11
|
onDestroyEffect(this.stop);
|
|
21
12
|
}
|
|
22
13
|
#clear() {
|
|
@@ -26,9 +17,11 @@ export class TimeoutFn {
|
|
|
26
17
|
}
|
|
27
18
|
}
|
|
28
19
|
stop() {
|
|
20
|
+
console.log("stopping timeout");
|
|
29
21
|
this.#clear();
|
|
30
22
|
}
|
|
31
23
|
start(...args) {
|
|
24
|
+
console.log("starting timeout");
|
|
32
25
|
this.#clear();
|
|
33
26
|
this.#timer = window.setTimeout(() => {
|
|
34
27
|
this.#timer = null;
|