@radix-ui/react-dismissable-layer 1.0.6-rc.5 → 1.1.0-rc.1
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/index.d.mts +13 -12
- package/dist/index.d.ts +13 -12
- package/dist/index.js +222 -270
- package/dist/index.js.map +7 -1
- package/dist/index.mjs +198 -262
- package/dist/index.mjs.map +7 -1
- package/package.json +6 -7
- package/dist/index.d.ts.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import * as Radix from
|
|
3
|
-
import { Primitive } from
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as Radix from '@radix-ui/react-primitive';
|
|
3
|
+
import { Primitive } from '@radix-ui/react-primitive';
|
|
4
|
+
|
|
5
|
+
declare type PrimitiveDivProps = Radix.ComponentPropsWithoutRef<typeof Primitive.div>;
|
|
6
|
+
interface DismissableLayerProps extends PrimitiveDivProps {
|
|
6
7
|
/**
|
|
7
8
|
* When `true`, hover/focus/click interactions will be disabled on elements outside
|
|
8
9
|
* the `DismissableLayer`. Users will need to click twice on outside elements to
|
|
@@ -35,17 +36,17 @@ export interface DismissableLayerProps extends PrimitiveDivProps {
|
|
|
35
36
|
*/
|
|
36
37
|
onDismiss?: () => void;
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
+
declare const DismissableLayer: React.ForwardRefExoticComponent<DismissableLayerProps & React.RefAttributes<HTMLDivElement>>;
|
|
39
40
|
interface DismissableLayerBranchProps extends PrimitiveDivProps {
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
-
type PointerDownOutsideEvent = CustomEvent<{
|
|
42
|
+
declare const DismissableLayerBranch: React.ForwardRefExoticComponent<DismissableLayerBranchProps & React.RefAttributes<HTMLDivElement>>;
|
|
43
|
+
declare type PointerDownOutsideEvent = CustomEvent<{
|
|
43
44
|
originalEvent: PointerEvent;
|
|
44
45
|
}>;
|
|
45
|
-
type FocusOutsideEvent = CustomEvent<{
|
|
46
|
+
declare type FocusOutsideEvent = CustomEvent<{
|
|
46
47
|
originalEvent: FocusEvent;
|
|
47
48
|
}>;
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
declare const Root: React.ForwardRefExoticComponent<DismissableLayerProps & React.RefAttributes<HTMLDivElement>>;
|
|
50
|
+
declare const Branch: React.ForwardRefExoticComponent<DismissableLayerBranchProps & React.RefAttributes<HTMLDivElement>>;
|
|
50
51
|
|
|
51
|
-
|
|
52
|
+
export { Branch, DismissableLayer, DismissableLayerBranch, type DismissableLayerProps, Root };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import * as Radix from
|
|
3
|
-
import { Primitive } from
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as Radix from '@radix-ui/react-primitive';
|
|
3
|
+
import { Primitive } from '@radix-ui/react-primitive';
|
|
4
|
+
|
|
5
|
+
declare type PrimitiveDivProps = Radix.ComponentPropsWithoutRef<typeof Primitive.div>;
|
|
6
|
+
interface DismissableLayerProps extends PrimitiveDivProps {
|
|
6
7
|
/**
|
|
7
8
|
* When `true`, hover/focus/click interactions will be disabled on elements outside
|
|
8
9
|
* the `DismissableLayer`. Users will need to click twice on outside elements to
|
|
@@ -35,17 +36,17 @@ export interface DismissableLayerProps extends PrimitiveDivProps {
|
|
|
35
36
|
*/
|
|
36
37
|
onDismiss?: () => void;
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
+
declare const DismissableLayer: React.ForwardRefExoticComponent<DismissableLayerProps & React.RefAttributes<HTMLDivElement>>;
|
|
39
40
|
interface DismissableLayerBranchProps extends PrimitiveDivProps {
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
-
type PointerDownOutsideEvent = CustomEvent<{
|
|
42
|
+
declare const DismissableLayerBranch: React.ForwardRefExoticComponent<DismissableLayerBranchProps & React.RefAttributes<HTMLDivElement>>;
|
|
43
|
+
declare type PointerDownOutsideEvent = CustomEvent<{
|
|
43
44
|
originalEvent: PointerEvent;
|
|
44
45
|
}>;
|
|
45
|
-
type FocusOutsideEvent = CustomEvent<{
|
|
46
|
+
declare type FocusOutsideEvent = CustomEvent<{
|
|
46
47
|
originalEvent: FocusEvent;
|
|
47
48
|
}>;
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
declare const Root: React.ForwardRefExoticComponent<DismissableLayerProps & React.RefAttributes<HTMLDivElement>>;
|
|
50
|
+
declare const Branch: React.ForwardRefExoticComponent<DismissableLayerBranchProps & React.RefAttributes<HTMLDivElement>>;
|
|
50
51
|
|
|
51
|
-
|
|
52
|
+
export { Branch, DismissableLayer, DismissableLayerBranch, type DismissableLayerProps, Root };
|
package/dist/index.js
CHANGED
|
@@ -1,293 +1,245 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
1
|
+
"use strict";
|
|
2
|
+
(() => {
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
10
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
11
|
+
}) : x)(function(x) {
|
|
12
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
13
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
14
|
+
});
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
8
31
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
...context.layersWithOutsidePointerEventsDisabled
|
|
51
|
-
].slice(-1); // prettier-ignore
|
|
52
|
-
const highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled); // prettier-ignore
|
|
53
|
-
const index = node1 ? layers.indexOf(node1) : -1;
|
|
54
|
-
const isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0;
|
|
55
|
-
const isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex;
|
|
56
|
-
const pointerDownOutside = $d715e0554b679f1f$var$usePointerDownOutside((event)=>{
|
|
32
|
+
// packages/react/dismissable-layer/src/DismissableLayer.tsx
|
|
33
|
+
var React = __toESM(__require("react"));
|
|
34
|
+
var import_primitive = __require("@radix-ui/primitive");
|
|
35
|
+
var import_react_primitive = __require("@radix-ui/react-primitive");
|
|
36
|
+
var import_react_compose_refs = __require("@radix-ui/react-compose-refs");
|
|
37
|
+
var import_react_use_callback_ref = __require("@radix-ui/react-use-callback-ref");
|
|
38
|
+
var import_react_use_escape_keydown = __require("@radix-ui/react-use-escape-keydown");
|
|
39
|
+
var import_jsx_runtime = __require("react/jsx-runtime");
|
|
40
|
+
var DISMISSABLE_LAYER_NAME = "DismissableLayer";
|
|
41
|
+
var CONTEXT_UPDATE = "dismissableLayer.update";
|
|
42
|
+
var POINTER_DOWN_OUTSIDE = "dismissableLayer.pointerDownOutside";
|
|
43
|
+
var FOCUS_OUTSIDE = "dismissableLayer.focusOutside";
|
|
44
|
+
var originalBodyPointerEvents;
|
|
45
|
+
var DismissableLayerContext = React.createContext({
|
|
46
|
+
layers: /* @__PURE__ */ new Set(),
|
|
47
|
+
layersWithOutsidePointerEventsDisabled: /* @__PURE__ */ new Set(),
|
|
48
|
+
branches: /* @__PURE__ */ new Set()
|
|
49
|
+
});
|
|
50
|
+
var DismissableLayer = React.forwardRef(
|
|
51
|
+
(props, forwardedRef) => {
|
|
52
|
+
const {
|
|
53
|
+
disableOutsidePointerEvents = false,
|
|
54
|
+
onEscapeKeyDown,
|
|
55
|
+
onPointerDownOutside,
|
|
56
|
+
onFocusOutside,
|
|
57
|
+
onInteractOutside,
|
|
58
|
+
onDismiss,
|
|
59
|
+
...layerProps
|
|
60
|
+
} = props;
|
|
61
|
+
const context = React.useContext(DismissableLayerContext);
|
|
62
|
+
const [node, setNode] = React.useState(null);
|
|
63
|
+
const ownerDocument = node?.ownerDocument ?? globalThis?.document;
|
|
64
|
+
const [, force] = React.useState({});
|
|
65
|
+
const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, (node2) => setNode(node2));
|
|
66
|
+
const layers = Array.from(context.layers);
|
|
67
|
+
const [highestLayerWithOutsidePointerEventsDisabled] = [...context.layersWithOutsidePointerEventsDisabled].slice(-1);
|
|
68
|
+
const highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled);
|
|
69
|
+
const index = node ? layers.indexOf(node) : -1;
|
|
70
|
+
const isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0;
|
|
71
|
+
const isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex;
|
|
72
|
+
const pointerDownOutside = usePointerDownOutside((event) => {
|
|
57
73
|
const target = event.target;
|
|
58
|
-
const isPointerDownOnBranch = [
|
|
59
|
-
...context.branches
|
|
60
|
-
].some((branch)=>branch.contains(target)
|
|
61
|
-
);
|
|
74
|
+
const isPointerDownOnBranch = [...context.branches].some((branch) => branch.contains(target));
|
|
62
75
|
if (!isPointerEventsEnabled || isPointerDownOnBranch) return;
|
|
63
|
-
onPointerDownOutside
|
|
64
|
-
onInteractOutside
|
|
65
|
-
if (!event.defaultPrevented) onDismiss
|
|
66
|
-
|
|
67
|
-
|
|
76
|
+
onPointerDownOutside?.(event);
|
|
77
|
+
onInteractOutside?.(event);
|
|
78
|
+
if (!event.defaultPrevented) onDismiss?.();
|
|
79
|
+
}, ownerDocument);
|
|
80
|
+
const focusOutside = useFocusOutside((event) => {
|
|
68
81
|
const target = event.target;
|
|
69
|
-
const isFocusInBranch = [
|
|
70
|
-
...context.branches
|
|
71
|
-
].some((branch)=>branch.contains(target)
|
|
72
|
-
);
|
|
82
|
+
const isFocusInBranch = [...context.branches].some((branch) => branch.contains(target));
|
|
73
83
|
if (isFocusInBranch) return;
|
|
74
|
-
onFocusOutside
|
|
75
|
-
onInteractOutside
|
|
76
|
-
if (!event.defaultPrevented) onDismiss
|
|
77
|
-
|
|
78
|
-
|
|
84
|
+
onFocusOutside?.(event);
|
|
85
|
+
onInteractOutside?.(event);
|
|
86
|
+
if (!event.defaultPrevented) onDismiss?.();
|
|
87
|
+
}, ownerDocument);
|
|
88
|
+
(0, import_react_use_escape_keydown.useEscapeKeydown)((event) => {
|
|
79
89
|
const isHighestLayer = index === context.layers.size - 1;
|
|
80
90
|
if (!isHighestLayer) return;
|
|
81
|
-
onEscapeKeyDown
|
|
91
|
+
onEscapeKeyDown?.(event);
|
|
82
92
|
if (!event.defaultPrevented && onDismiss) {
|
|
83
|
-
|
|
84
|
-
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
onDismiss();
|
|
85
95
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (!
|
|
96
|
+
}, ownerDocument);
|
|
97
|
+
React.useEffect(() => {
|
|
98
|
+
if (!node) return;
|
|
89
99
|
if (disableOutsidePointerEvents) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
if (context.layersWithOutsidePointerEventsDisabled.size === 0) {
|
|
101
|
+
originalBodyPointerEvents = ownerDocument.body.style.pointerEvents;
|
|
102
|
+
ownerDocument.body.style.pointerEvents = "none";
|
|
103
|
+
}
|
|
104
|
+
context.layersWithOutsidePointerEventsDisabled.add(node);
|
|
95
105
|
}
|
|
96
|
-
context.layers.add(
|
|
97
|
-
|
|
98
|
-
return ()=>{
|
|
99
|
-
|
|
106
|
+
context.layers.add(node);
|
|
107
|
+
dispatchUpdate();
|
|
108
|
+
return () => {
|
|
109
|
+
if (disableOutsidePointerEvents && context.layersWithOutsidePointerEventsDisabled.size === 1) {
|
|
110
|
+
ownerDocument.body.style.pointerEvents = originalBodyPointerEvents;
|
|
111
|
+
}
|
|
100
112
|
};
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
* We purposefully prevent combining this effect with the `disableOutsidePointerEvents` effect
|
|
109
|
-
* because a change to `disableOutsidePointerEvents` would remove this layer from the stack
|
|
110
|
-
* and add it to the end again so the layering order wouldn't be _creation order_.
|
|
111
|
-
* We only want them to be removed from context stacks when unmounted.
|
|
112
|
-
*/ $g2vWm$react.useEffect(()=>{
|
|
113
|
-
return ()=>{
|
|
114
|
-
if (!node1) return;
|
|
115
|
-
context.layers.delete(node1);
|
|
116
|
-
context.layersWithOutsidePointerEventsDisabled.delete(node1);
|
|
117
|
-
$d715e0554b679f1f$var$dispatchUpdate();
|
|
113
|
+
}, [node, ownerDocument, disableOutsidePointerEvents, context]);
|
|
114
|
+
React.useEffect(() => {
|
|
115
|
+
return () => {
|
|
116
|
+
if (!node) return;
|
|
117
|
+
context.layers.delete(node);
|
|
118
|
+
context.layersWithOutsidePointerEventsDisabled.delete(node);
|
|
119
|
+
dispatchUpdate();
|
|
118
120
|
};
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
style: {
|
|
133
|
-
pointerEvents: isBodyPointerEventsDisabled ? isPointerEventsEnabled ? 'auto' : 'none' : undefined,
|
|
121
|
+
}, [node, context]);
|
|
122
|
+
React.useEffect(() => {
|
|
123
|
+
const handleUpdate = () => force({});
|
|
124
|
+
document.addEventListener(CONTEXT_UPDATE, handleUpdate);
|
|
125
|
+
return () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate);
|
|
126
|
+
}, []);
|
|
127
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
128
|
+
import_react_primitive.Primitive.div,
|
|
129
|
+
{
|
|
130
|
+
...layerProps,
|
|
131
|
+
ref: composedRefs,
|
|
132
|
+
style: {
|
|
133
|
+
pointerEvents: isBodyPointerEventsDisabled ? isPointerEventsEnabled ? "auto" : "none" : void 0,
|
|
134
134
|
...props.style
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
displayName: $d715e0554b679f1f$var$DISMISSABLE_LAYER_NAME
|
|
143
|
-
});
|
|
144
|
-
/* -------------------------------------------------------------------------------------------------
|
|
145
|
-
* DismissableLayerBranch
|
|
146
|
-
* -----------------------------------------------------------------------------------------------*/ const $d715e0554b679f1f$var$BRANCH_NAME = 'DismissableLayerBranch';
|
|
147
|
-
const $d715e0554b679f1f$export$4d5eb2109db14228 = /*#__PURE__*/ $g2vWm$react.forwardRef((props, forwardedRef)=>{
|
|
148
|
-
const context = $g2vWm$react.useContext($d715e0554b679f1f$var$DismissableLayerContext);
|
|
149
|
-
const ref = $g2vWm$react.useRef(null);
|
|
150
|
-
const composedRefs = $g2vWm$radixuireactcomposerefs.useComposedRefs(forwardedRef, ref);
|
|
151
|
-
$g2vWm$react.useEffect(()=>{
|
|
152
|
-
const node = ref.current;
|
|
153
|
-
if (node) {
|
|
154
|
-
context.branches.add(node);
|
|
155
|
-
return ()=>{
|
|
156
|
-
context.branches.delete(node);
|
|
157
|
-
};
|
|
135
|
+
},
|
|
136
|
+
onFocusCapture: (0, import_primitive.composeEventHandlers)(props.onFocusCapture, focusOutside.onFocusCapture),
|
|
137
|
+
onBlurCapture: (0, import_primitive.composeEventHandlers)(props.onBlurCapture, focusOutside.onBlurCapture),
|
|
138
|
+
onPointerDownCapture: (0, import_primitive.composeEventHandlers)(
|
|
139
|
+
props.onPointerDownCapture,
|
|
140
|
+
pointerDownOutside.onPointerDownCapture
|
|
141
|
+
)
|
|
158
142
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const handlePointerDownOutside = $g2vWm$radixuireactusecallbackref.useCallbackRef(onPointerDownOutside);
|
|
175
|
-
const isPointerInsideReactTreeRef = $g2vWm$react.useRef(false);
|
|
176
|
-
const handleClickRef = $g2vWm$react.useRef(()=>{});
|
|
177
|
-
$g2vWm$react.useEffect(()=>{
|
|
178
|
-
const handlePointerDown = (event)=>{
|
|
179
|
-
if (event.target && !isPointerInsideReactTreeRef.current) {
|
|
180
|
-
const eventDetail = {
|
|
181
|
-
originalEvent: event
|
|
182
|
-
};
|
|
183
|
-
function handleAndDispatchPointerDownOutsideEvent() {
|
|
184
|
-
$d715e0554b679f1f$var$handleAndDispatchCustomEvent($d715e0554b679f1f$var$POINTER_DOWN_OUTSIDE, handlePointerDownOutside, eventDetail, {
|
|
185
|
-
discrete: true
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* On touch devices, we need to wait for a click event because browsers implement
|
|
190
|
-
* a ~350ms delay between the time the user stops touching the display and when the
|
|
191
|
-
* browser executres events. We need to ensure we don't reactivate pointer-events within
|
|
192
|
-
* this timeframe otherwise the browser may execute events that should have been prevented.
|
|
193
|
-
*
|
|
194
|
-
* Additionally, this also lets us deal automatically with cancellations when a click event
|
|
195
|
-
* isn't raised because the page was considered scrolled/drag-scrolled, long-pressed, etc.
|
|
196
|
-
*
|
|
197
|
-
* This is why we also continuously remove the previous listener, because we cannot be
|
|
198
|
-
* certain that it was raised, and therefore cleaned-up.
|
|
199
|
-
*/ if (event.pointerType === 'touch') {
|
|
200
|
-
ownerDocument.removeEventListener('click', handleClickRef.current);
|
|
201
|
-
handleClickRef.current = handleAndDispatchPointerDownOutsideEvent;
|
|
202
|
-
ownerDocument.addEventListener('click', handleClickRef.current, {
|
|
203
|
-
once: true
|
|
204
|
-
});
|
|
205
|
-
} else handleAndDispatchPointerDownOutsideEvent();
|
|
206
|
-
} else // We need to remove the event listener in case the outside click has been canceled.
|
|
207
|
-
// See: https://github.com/radix-ui/primitives/issues/2171
|
|
208
|
-
ownerDocument.removeEventListener('click', handleClickRef.current);
|
|
209
|
-
isPointerInsideReactTreeRef.current = false;
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
);
|
|
146
|
+
DismissableLayer.displayName = DISMISSABLE_LAYER_NAME;
|
|
147
|
+
var BRANCH_NAME = "DismissableLayerBranch";
|
|
148
|
+
var DismissableLayerBranch = React.forwardRef((props, forwardedRef) => {
|
|
149
|
+
const context = React.useContext(DismissableLayerContext);
|
|
150
|
+
const ref = React.useRef(null);
|
|
151
|
+
const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, ref);
|
|
152
|
+
React.useEffect(() => {
|
|
153
|
+
const node = ref.current;
|
|
154
|
+
if (node) {
|
|
155
|
+
context.branches.add(node);
|
|
156
|
+
return () => {
|
|
157
|
+
context.branches.delete(node);
|
|
210
158
|
};
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
159
|
+
}
|
|
160
|
+
}, [context.branches]);
|
|
161
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.div, { ...props, ref: composedRefs });
|
|
162
|
+
});
|
|
163
|
+
DismissableLayerBranch.displayName = BRANCH_NAME;
|
|
164
|
+
function usePointerDownOutside(onPointerDownOutside, ownerDocument = globalThis?.document) {
|
|
165
|
+
const handlePointerDownOutside = (0, import_react_use_callback_ref.useCallbackRef)(onPointerDownOutside);
|
|
166
|
+
const isPointerInsideReactTreeRef = React.useRef(false);
|
|
167
|
+
const handleClickRef = React.useRef(() => {
|
|
168
|
+
});
|
|
169
|
+
React.useEffect(() => {
|
|
170
|
+
const handlePointerDown = (event) => {
|
|
171
|
+
if (event.target && !isPointerInsideReactTreeRef.current) {
|
|
172
|
+
let handleAndDispatchPointerDownOutsideEvent2 = function() {
|
|
173
|
+
handleAndDispatchCustomEvent(
|
|
174
|
+
POINTER_DOWN_OUTSIDE,
|
|
175
|
+
handlePointerDownOutside,
|
|
176
|
+
eventDetail,
|
|
177
|
+
{ discrete: true }
|
|
178
|
+
);
|
|
179
|
+
};
|
|
180
|
+
var handleAndDispatchPointerDownOutsideEvent = handleAndDispatchPointerDownOutsideEvent2;
|
|
181
|
+
const eventDetail = { originalEvent: event };
|
|
182
|
+
if (event.pointerType === "touch") {
|
|
183
|
+
ownerDocument.removeEventListener("click", handleClickRef.current);
|
|
184
|
+
handleClickRef.current = handleAndDispatchPointerDownOutsideEvent2;
|
|
185
|
+
ownerDocument.addEventListener("click", handleClickRef.current, { once: true });
|
|
186
|
+
} else {
|
|
187
|
+
handleAndDispatchPointerDownOutsideEvent2();
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
ownerDocument.removeEventListener("click", handleClickRef.current);
|
|
191
|
+
}
|
|
192
|
+
isPointerInsideReactTreeRef.current = false;
|
|
193
|
+
};
|
|
194
|
+
const timerId = window.setTimeout(() => {
|
|
195
|
+
ownerDocument.addEventListener("pointerdown", handlePointerDown);
|
|
196
|
+
}, 0);
|
|
197
|
+
return () => {
|
|
198
|
+
window.clearTimeout(timerId);
|
|
199
|
+
ownerDocument.removeEventListener("pointerdown", handlePointerDown);
|
|
200
|
+
ownerDocument.removeEventListener("click", handleClickRef.current);
|
|
201
|
+
};
|
|
202
|
+
}, [ownerDocument, handlePointerDownOutside]);
|
|
235
203
|
return {
|
|
236
|
-
|
|
237
|
-
|
|
204
|
+
// ensures we check React component tree (not just DOM tree)
|
|
205
|
+
onPointerDownCapture: () => isPointerInsideReactTreeRef.current = true
|
|
238
206
|
};
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
ownerDocument.addEventListener('focusin', handleFocus);
|
|
258
|
-
return ()=>ownerDocument.removeEventListener('focusin', handleFocus)
|
|
259
|
-
;
|
|
260
|
-
}, [
|
|
261
|
-
ownerDocument,
|
|
262
|
-
handleFocusOutside
|
|
263
|
-
]);
|
|
207
|
+
}
|
|
208
|
+
function useFocusOutside(onFocusOutside, ownerDocument = globalThis?.document) {
|
|
209
|
+
const handleFocusOutside = (0, import_react_use_callback_ref.useCallbackRef)(onFocusOutside);
|
|
210
|
+
const isFocusInsideReactTreeRef = React.useRef(false);
|
|
211
|
+
React.useEffect(() => {
|
|
212
|
+
const handleFocus = (event) => {
|
|
213
|
+
if (event.target && !isFocusInsideReactTreeRef.current) {
|
|
214
|
+
const eventDetail = { originalEvent: event };
|
|
215
|
+
handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, eventDetail, {
|
|
216
|
+
discrete: false
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
ownerDocument.addEventListener("focusin", handleFocus);
|
|
221
|
+
return () => ownerDocument.removeEventListener("focusin", handleFocus);
|
|
222
|
+
}, [ownerDocument, handleFocusOutside]);
|
|
264
223
|
return {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
onBlurCapture: ()=>isFocusInsideReactTreeRef.current = false
|
|
224
|
+
onFocusCapture: () => isFocusInsideReactTreeRef.current = true,
|
|
225
|
+
onBlurCapture: () => isFocusInsideReactTreeRef.current = false
|
|
268
226
|
};
|
|
269
|
-
}
|
|
270
|
-
function
|
|
271
|
-
const event = new CustomEvent(
|
|
227
|
+
}
|
|
228
|
+
function dispatchUpdate() {
|
|
229
|
+
const event = new CustomEvent(CONTEXT_UPDATE);
|
|
272
230
|
document.dispatchEvent(event);
|
|
273
|
-
}
|
|
274
|
-
function
|
|
231
|
+
}
|
|
232
|
+
function handleAndDispatchCustomEvent(name, handler, detail, { discrete }) {
|
|
275
233
|
const target = detail.originalEvent.target;
|
|
276
|
-
const event = new CustomEvent(name, {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
}
|
|
287
|
-
const $d715e0554b679f1f$export$be92b6f5f03c0fe9 = $d715e0554b679f1f$export$177fb62ff3ec1f22;
|
|
288
|
-
const $d715e0554b679f1f$export$aecb2ddcb55c95be = $d715e0554b679f1f$export$4d5eb2109db14228;
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
234
|
+
const event = new CustomEvent(name, { bubbles: false, cancelable: true, detail });
|
|
235
|
+
if (handler) target.addEventListener(name, handler, { once: true });
|
|
236
|
+
if (discrete) {
|
|
237
|
+
(0, import_react_primitive.dispatchDiscreteCustomEvent)(target, event);
|
|
238
|
+
} else {
|
|
239
|
+
target.dispatchEvent(event);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
var Root = DismissableLayer;
|
|
243
|
+
var Branch = DismissableLayerBranch;
|
|
244
|
+
})();
|
|
293
245
|
//# sourceMappingURL=index.js.map
|