@radix-ui/react-dismissable-layer 1.1.0-rc.1 → 1.1.0-rc.3

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.js CHANGED
@@ -1,245 +1,253 @@
1
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
- ));
2
+ "use client";
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 __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
30
 
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) => {
73
- const target = event.target;
74
- const isPointerDownOnBranch = [...context.branches].some((branch) => branch.contains(target));
75
- if (!isPointerEventsEnabled || isPointerDownOnBranch) return;
76
- onPointerDownOutside?.(event);
77
- onInteractOutside?.(event);
78
- if (!event.defaultPrevented) onDismiss?.();
79
- }, ownerDocument);
80
- const focusOutside = useFocusOutside((event) => {
81
- const target = event.target;
82
- const isFocusInBranch = [...context.branches].some((branch) => branch.contains(target));
83
- if (isFocusInBranch) return;
84
- onFocusOutside?.(event);
85
- onInteractOutside?.(event);
86
- if (!event.defaultPrevented) onDismiss?.();
87
- }, ownerDocument);
88
- (0, import_react_use_escape_keydown.useEscapeKeydown)((event) => {
89
- const isHighestLayer = index === context.layers.size - 1;
90
- if (!isHighestLayer) return;
91
- onEscapeKeyDown?.(event);
92
- if (!event.defaultPrevented && onDismiss) {
93
- event.preventDefault();
94
- onDismiss();
31
+ // packages/react/dismissable-layer/src/index.ts
32
+ var src_exports = {};
33
+ __export(src_exports, {
34
+ Branch: () => Branch,
35
+ DismissableLayer: () => DismissableLayer,
36
+ DismissableLayerBranch: () => DismissableLayerBranch,
37
+ Root: () => Root
38
+ });
39
+ module.exports = __toCommonJS(src_exports);
40
+
41
+ // packages/react/dismissable-layer/src/DismissableLayer.tsx
42
+ var React = __toESM(require("react"));
43
+ var import_primitive = require("@radix-ui/primitive");
44
+ var import_react_primitive = require("@radix-ui/react-primitive");
45
+ var import_react_compose_refs = require("@radix-ui/react-compose-refs");
46
+ var import_react_use_callback_ref = require("@radix-ui/react-use-callback-ref");
47
+ var import_react_use_escape_keydown = require("@radix-ui/react-use-escape-keydown");
48
+ var import_jsx_runtime = require("react/jsx-runtime");
49
+ var DISMISSABLE_LAYER_NAME = "DismissableLayer";
50
+ var CONTEXT_UPDATE = "dismissableLayer.update";
51
+ var POINTER_DOWN_OUTSIDE = "dismissableLayer.pointerDownOutside";
52
+ var FOCUS_OUTSIDE = "dismissableLayer.focusOutside";
53
+ var originalBodyPointerEvents;
54
+ var DismissableLayerContext = React.createContext({
55
+ layers: /* @__PURE__ */ new Set(),
56
+ layersWithOutsidePointerEventsDisabled: /* @__PURE__ */ new Set(),
57
+ branches: /* @__PURE__ */ new Set()
58
+ });
59
+ var DismissableLayer = React.forwardRef(
60
+ (props, forwardedRef) => {
61
+ const {
62
+ disableOutsidePointerEvents = false,
63
+ onEscapeKeyDown,
64
+ onPointerDownOutside,
65
+ onFocusOutside,
66
+ onInteractOutside,
67
+ onDismiss,
68
+ ...layerProps
69
+ } = props;
70
+ const context = React.useContext(DismissableLayerContext);
71
+ const [node, setNode] = React.useState(null);
72
+ const ownerDocument = node?.ownerDocument ?? globalThis?.document;
73
+ const [, force] = React.useState({});
74
+ const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, (node2) => setNode(node2));
75
+ const layers = Array.from(context.layers);
76
+ const [highestLayerWithOutsidePointerEventsDisabled] = [...context.layersWithOutsidePointerEventsDisabled].slice(-1);
77
+ const highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled);
78
+ const index = node ? layers.indexOf(node) : -1;
79
+ const isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0;
80
+ const isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex;
81
+ const pointerDownOutside = usePointerDownOutside((event) => {
82
+ const target = event.target;
83
+ const isPointerDownOnBranch = [...context.branches].some((branch) => branch.contains(target));
84
+ if (!isPointerEventsEnabled || isPointerDownOnBranch) return;
85
+ onPointerDownOutside?.(event);
86
+ onInteractOutside?.(event);
87
+ if (!event.defaultPrevented) onDismiss?.();
88
+ }, ownerDocument);
89
+ const focusOutside = useFocusOutside((event) => {
90
+ const target = event.target;
91
+ const isFocusInBranch = [...context.branches].some((branch) => branch.contains(target));
92
+ if (isFocusInBranch) return;
93
+ onFocusOutside?.(event);
94
+ onInteractOutside?.(event);
95
+ if (!event.defaultPrevented) onDismiss?.();
96
+ }, ownerDocument);
97
+ (0, import_react_use_escape_keydown.useEscapeKeydown)((event) => {
98
+ const isHighestLayer = index === context.layers.size - 1;
99
+ if (!isHighestLayer) return;
100
+ onEscapeKeyDown?.(event);
101
+ if (!event.defaultPrevented && onDismiss) {
102
+ event.preventDefault();
103
+ onDismiss();
104
+ }
105
+ }, ownerDocument);
106
+ React.useEffect(() => {
107
+ if (!node) return;
108
+ if (disableOutsidePointerEvents) {
109
+ if (context.layersWithOutsidePointerEventsDisabled.size === 0) {
110
+ originalBodyPointerEvents = ownerDocument.body.style.pointerEvents;
111
+ ownerDocument.body.style.pointerEvents = "none";
95
112
  }
96
- }, ownerDocument);
97
- React.useEffect(() => {
98
- if (!node) return;
99
- if (disableOutsidePointerEvents) {
100
- if (context.layersWithOutsidePointerEventsDisabled.size === 0) {
101
- originalBodyPointerEvents = ownerDocument.body.style.pointerEvents;
102
- ownerDocument.body.style.pointerEvents = "none";
103
- }
104
- context.layersWithOutsidePointerEventsDisabled.add(node);
113
+ context.layersWithOutsidePointerEventsDisabled.add(node);
114
+ }
115
+ context.layers.add(node);
116
+ dispatchUpdate();
117
+ return () => {
118
+ if (disableOutsidePointerEvents && context.layersWithOutsidePointerEventsDisabled.size === 1) {
119
+ ownerDocument.body.style.pointerEvents = originalBodyPointerEvents;
105
120
  }
106
- context.layers.add(node);
121
+ };
122
+ }, [node, ownerDocument, disableOutsidePointerEvents, context]);
123
+ React.useEffect(() => {
124
+ return () => {
125
+ if (!node) return;
126
+ context.layers.delete(node);
127
+ context.layersWithOutsidePointerEventsDisabled.delete(node);
107
128
  dispatchUpdate();
108
- return () => {
109
- if (disableOutsidePointerEvents && context.layersWithOutsidePointerEventsDisabled.size === 1) {
110
- ownerDocument.body.style.pointerEvents = originalBodyPointerEvents;
111
- }
112
- };
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();
120
- };
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
- ...props.style
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
- )
142
- }
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);
129
+ };
130
+ }, [node, context]);
152
131
  React.useEffect(() => {
153
- const node = ref.current;
154
- if (node) {
155
- context.branches.add(node);
156
- return () => {
157
- context.branches.delete(node);
158
- };
132
+ const handleUpdate = () => force({});
133
+ document.addEventListener(CONTEXT_UPDATE, handleUpdate);
134
+ return () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate);
135
+ }, []);
136
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
137
+ import_react_primitive.Primitive.div,
138
+ {
139
+ ...layerProps,
140
+ ref: composedRefs,
141
+ style: {
142
+ pointerEvents: isBodyPointerEventsDisabled ? isPointerEventsEnabled ? "auto" : "none" : void 0,
143
+ ...props.style
144
+ },
145
+ onFocusCapture: (0, import_primitive.composeEventHandlers)(props.onFocusCapture, focusOutside.onFocusCapture),
146
+ onBlurCapture: (0, import_primitive.composeEventHandlers)(props.onBlurCapture, focusOutside.onBlurCapture),
147
+ onPointerDownCapture: (0, import_primitive.composeEventHandlers)(
148
+ props.onPointerDownCapture,
149
+ pointerDownOutside.onPointerDownCapture
150
+ )
159
151
  }
160
- }, [context.branches]);
161
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.div, { ...props, ref: composedRefs });
152
+ );
153
+ }
154
+ );
155
+ DismissableLayer.displayName = DISMISSABLE_LAYER_NAME;
156
+ var BRANCH_NAME = "DismissableLayerBranch";
157
+ var DismissableLayerBranch = React.forwardRef((props, forwardedRef) => {
158
+ const context = React.useContext(DismissableLayerContext);
159
+ const ref = React.useRef(null);
160
+ const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, ref);
161
+ React.useEffect(() => {
162
+ const node = ref.current;
163
+ if (node) {
164
+ context.branches.add(node);
165
+ return () => {
166
+ context.branches.delete(node);
167
+ };
168
+ }
169
+ }, [context.branches]);
170
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.div, { ...props, ref: composedRefs });
171
+ });
172
+ DismissableLayerBranch.displayName = BRANCH_NAME;
173
+ function usePointerDownOutside(onPointerDownOutside, ownerDocument = globalThis?.document) {
174
+ const handlePointerDownOutside = (0, import_react_use_callback_ref.useCallbackRef)(onPointerDownOutside);
175
+ const isPointerInsideReactTreeRef = React.useRef(false);
176
+ const handleClickRef = React.useRef(() => {
162
177
  });
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 {
178
+ React.useEffect(() => {
179
+ const handlePointerDown = (event) => {
180
+ if (event.target && !isPointerInsideReactTreeRef.current) {
181
+ let handleAndDispatchPointerDownOutsideEvent2 = function() {
182
+ handleAndDispatchCustomEvent(
183
+ POINTER_DOWN_OUTSIDE,
184
+ handlePointerDownOutside,
185
+ eventDetail,
186
+ { discrete: true }
187
+ );
188
+ };
189
+ var handleAndDispatchPointerDownOutsideEvent = handleAndDispatchPointerDownOutsideEvent2;
190
+ const eventDetail = { originalEvent: event };
191
+ if (event.pointerType === "touch") {
190
192
  ownerDocument.removeEventListener("click", handleClickRef.current);
193
+ handleClickRef.current = handleAndDispatchPointerDownOutsideEvent2;
194
+ ownerDocument.addEventListener("click", handleClickRef.current, { once: true });
195
+ } else {
196
+ handleAndDispatchPointerDownOutsideEvent2();
191
197
  }
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);
198
+ } else {
200
199
  ownerDocument.removeEventListener("click", handleClickRef.current);
201
- };
202
- }, [ownerDocument, handlePointerDownOutside]);
203
- return {
204
- // ensures we check React component tree (not just DOM tree)
205
- onPointerDownCapture: () => isPointerInsideReactTreeRef.current = true
200
+ }
201
+ isPointerInsideReactTreeRef.current = false;
206
202
  };
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]);
223
- return {
224
- onFocusCapture: () => isFocusInsideReactTreeRef.current = true,
225
- onBlurCapture: () => isFocusInsideReactTreeRef.current = false
203
+ const timerId = window.setTimeout(() => {
204
+ ownerDocument.addEventListener("pointerdown", handlePointerDown);
205
+ }, 0);
206
+ return () => {
207
+ window.clearTimeout(timerId);
208
+ ownerDocument.removeEventListener("pointerdown", handlePointerDown);
209
+ ownerDocument.removeEventListener("click", handleClickRef.current);
226
210
  };
211
+ }, [ownerDocument, handlePointerDownOutside]);
212
+ return {
213
+ // ensures we check React component tree (not just DOM tree)
214
+ onPointerDownCapture: () => isPointerInsideReactTreeRef.current = true
215
+ };
216
+ }
217
+ function useFocusOutside(onFocusOutside, ownerDocument = globalThis?.document) {
218
+ const handleFocusOutside = (0, import_react_use_callback_ref.useCallbackRef)(onFocusOutside);
219
+ const isFocusInsideReactTreeRef = React.useRef(false);
220
+ React.useEffect(() => {
221
+ const handleFocus = (event) => {
222
+ if (event.target && !isFocusInsideReactTreeRef.current) {
223
+ const eventDetail = { originalEvent: event };
224
+ handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, eventDetail, {
225
+ discrete: false
226
+ });
227
+ }
228
+ };
229
+ ownerDocument.addEventListener("focusin", handleFocus);
230
+ return () => ownerDocument.removeEventListener("focusin", handleFocus);
231
+ }, [ownerDocument, handleFocusOutside]);
232
+ return {
233
+ onFocusCapture: () => isFocusInsideReactTreeRef.current = true,
234
+ onBlurCapture: () => isFocusInsideReactTreeRef.current = false
235
+ };
236
+ }
237
+ function dispatchUpdate() {
238
+ const event = new CustomEvent(CONTEXT_UPDATE);
239
+ document.dispatchEvent(event);
240
+ }
241
+ function handleAndDispatchCustomEvent(name, handler, detail, { discrete }) {
242
+ const target = detail.originalEvent.target;
243
+ const event = new CustomEvent(name, { bubbles: false, cancelable: true, detail });
244
+ if (handler) target.addEventListener(name, handler, { once: true });
245
+ if (discrete) {
246
+ (0, import_react_primitive.dispatchDiscreteCustomEvent)(target, event);
247
+ } else {
248
+ target.dispatchEvent(event);
227
249
  }
228
- function dispatchUpdate() {
229
- const event = new CustomEvent(CONTEXT_UPDATE);
230
- document.dispatchEvent(event);
231
- }
232
- function handleAndDispatchCustomEvent(name, handler, detail, { discrete }) {
233
- const target = detail.originalEvent.target;
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
- })();
250
+ }
251
+ var Root = DismissableLayer;
252
+ var Branch = DismissableLayerBranch;
245
253
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/DismissableLayer.tsx"],
4
- "sourcesContent": ["import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { Primitive, dispatchDiscreteCustomEvent } from '@radix-ui/react-primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { useCallbackRef } from '@radix-ui/react-use-callback-ref';\nimport { useEscapeKeydown } from '@radix-ui/react-use-escape-keydown';\n\nimport type * as Radix from '@radix-ui/react-primitive';\n\n/* -------------------------------------------------------------------------------------------------\n * DismissableLayer\n * -----------------------------------------------------------------------------------------------*/\n\nconst DISMISSABLE_LAYER_NAME = 'DismissableLayer';\nconst CONTEXT_UPDATE = 'dismissableLayer.update';\nconst POINTER_DOWN_OUTSIDE = 'dismissableLayer.pointerDownOutside';\nconst FOCUS_OUTSIDE = 'dismissableLayer.focusOutside';\n\nlet originalBodyPointerEvents: string;\n\nconst DismissableLayerContext = React.createContext({\n layers: new Set<DismissableLayerElement>(),\n layersWithOutsidePointerEventsDisabled: new Set<DismissableLayerElement>(),\n branches: new Set<DismissableLayerBranchElement>(),\n});\n\ntype DismissableLayerElement = React.ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = Radix.ComponentPropsWithoutRef<typeof Primitive.div>;\ninterface DismissableLayerProps extends PrimitiveDivProps {\n /**\n * When `true`, hover/focus/click interactions will be disabled on elements outside\n * the `DismissableLayer`. Users will need to click twice on outside elements to\n * interact with them: once to close the `DismissableLayer`, and again to trigger the element.\n */\n disableOutsidePointerEvents?: boolean;\n /**\n * Event handler called when the escape key is down.\n * Can be prevented.\n */\n onEscapeKeyDown?: (event: KeyboardEvent) => void;\n /**\n * Event handler called when the a `pointerdown` event happens outside of the `DismissableLayer`.\n * Can be prevented.\n */\n onPointerDownOutside?: (event: PointerDownOutsideEvent) => void;\n /**\n * Event handler called when the focus moves outside of the `DismissableLayer`.\n * Can be prevented.\n */\n onFocusOutside?: (event: FocusOutsideEvent) => void;\n /**\n * Event handler called when an interaction happens outside the `DismissableLayer`.\n * Specifically, when a `pointerdown` event happens outside or focus moves outside of it.\n * Can be prevented.\n */\n onInteractOutside?: (event: PointerDownOutsideEvent | FocusOutsideEvent) => void;\n /**\n * Handler called when the `DismissableLayer` should be dismissed\n */\n onDismiss?: () => void;\n}\n\nconst DismissableLayer = React.forwardRef<DismissableLayerElement, DismissableLayerProps>(\n (props, forwardedRef) => {\n const {\n disableOutsidePointerEvents = false,\n onEscapeKeyDown,\n onPointerDownOutside,\n onFocusOutside,\n onInteractOutside,\n onDismiss,\n ...layerProps\n } = props;\n const context = React.useContext(DismissableLayerContext);\n const [node, setNode] = React.useState<DismissableLayerElement | null>(null);\n const ownerDocument = node?.ownerDocument ?? globalThis?.document;\n const [, force] = React.useState({});\n const composedRefs = useComposedRefs(forwardedRef, (node) => setNode(node));\n const layers = Array.from(context.layers);\n const [highestLayerWithOutsidePointerEventsDisabled] = [...context.layersWithOutsidePointerEventsDisabled].slice(-1); // prettier-ignore\n const highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled); // prettier-ignore\n const index = node ? layers.indexOf(node) : -1;\n const isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0;\n const isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex;\n\n const pointerDownOutside = usePointerDownOutside((event) => {\n const target = event.target as HTMLElement;\n const isPointerDownOnBranch = [...context.branches].some((branch) => branch.contains(target));\n if (!isPointerEventsEnabled || isPointerDownOnBranch) return;\n onPointerDownOutside?.(event);\n onInteractOutside?.(event);\n if (!event.defaultPrevented) onDismiss?.();\n }, ownerDocument);\n\n const focusOutside = useFocusOutside((event) => {\n const target = event.target as HTMLElement;\n const isFocusInBranch = [...context.branches].some((branch) => branch.contains(target));\n if (isFocusInBranch) return;\n onFocusOutside?.(event);\n onInteractOutside?.(event);\n if (!event.defaultPrevented) onDismiss?.();\n }, ownerDocument);\n\n useEscapeKeydown((event) => {\n const isHighestLayer = index === context.layers.size - 1;\n if (!isHighestLayer) return;\n onEscapeKeyDown?.(event);\n if (!event.defaultPrevented && onDismiss) {\n event.preventDefault();\n onDismiss();\n }\n }, ownerDocument);\n\n React.useEffect(() => {\n if (!node) return;\n if (disableOutsidePointerEvents) {\n if (context.layersWithOutsidePointerEventsDisabled.size === 0) {\n originalBodyPointerEvents = ownerDocument.body.style.pointerEvents;\n ownerDocument.body.style.pointerEvents = 'none';\n }\n context.layersWithOutsidePointerEventsDisabled.add(node);\n }\n context.layers.add(node);\n dispatchUpdate();\n return () => {\n if (\n disableOutsidePointerEvents &&\n context.layersWithOutsidePointerEventsDisabled.size === 1\n ) {\n ownerDocument.body.style.pointerEvents = originalBodyPointerEvents;\n }\n };\n }, [node, ownerDocument, disableOutsidePointerEvents, context]);\n\n /**\n * We purposefully prevent combining this effect with the `disableOutsidePointerEvents` effect\n * because a change to `disableOutsidePointerEvents` would remove this layer from the stack\n * and add it to the end again so the layering order wouldn't be _creation order_.\n * We only want them to be removed from context stacks when unmounted.\n */\n React.useEffect(() => {\n return () => {\n if (!node) return;\n context.layers.delete(node);\n context.layersWithOutsidePointerEventsDisabled.delete(node);\n dispatchUpdate();\n };\n }, [node, context]);\n\n React.useEffect(() => {\n const handleUpdate = () => force({});\n document.addEventListener(CONTEXT_UPDATE, handleUpdate);\n return () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate);\n }, []);\n\n return (\n <Primitive.div\n {...layerProps}\n ref={composedRefs}\n style={{\n pointerEvents: isBodyPointerEventsDisabled\n ? isPointerEventsEnabled\n ? 'auto'\n : 'none'\n : undefined,\n ...props.style,\n }}\n onFocusCapture={composeEventHandlers(props.onFocusCapture, focusOutside.onFocusCapture)}\n onBlurCapture={composeEventHandlers(props.onBlurCapture, focusOutside.onBlurCapture)}\n onPointerDownCapture={composeEventHandlers(\n props.onPointerDownCapture,\n pointerDownOutside.onPointerDownCapture\n )}\n />\n );\n }\n);\n\nDismissableLayer.displayName = DISMISSABLE_LAYER_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * DismissableLayerBranch\n * -----------------------------------------------------------------------------------------------*/\n\nconst BRANCH_NAME = 'DismissableLayerBranch';\n\ntype DismissableLayerBranchElement = React.ElementRef<typeof Primitive.div>;\ninterface DismissableLayerBranchProps extends PrimitiveDivProps {}\n\nconst DismissableLayerBranch = React.forwardRef<\n DismissableLayerBranchElement,\n DismissableLayerBranchProps\n>((props, forwardedRef) => {\n const context = React.useContext(DismissableLayerContext);\n const ref = React.useRef<DismissableLayerBranchElement>(null);\n const composedRefs = useComposedRefs(forwardedRef, ref);\n\n React.useEffect(() => {\n const node = ref.current;\n if (node) {\n context.branches.add(node);\n return () => {\n context.branches.delete(node);\n };\n }\n }, [context.branches]);\n\n return <Primitive.div {...props} ref={composedRefs} />;\n});\n\nDismissableLayerBranch.displayName = BRANCH_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\ntype PointerDownOutsideEvent = CustomEvent<{ originalEvent: PointerEvent }>;\ntype FocusOutsideEvent = CustomEvent<{ originalEvent: FocusEvent }>;\n\n/**\n * Listens for `pointerdown` outside a react subtree. We use `pointerdown` rather than `pointerup`\n * to mimic layer dismissing behaviour present in OS.\n * Returns props to pass to the node we want to check for outside events.\n */\nfunction usePointerDownOutside(\n onPointerDownOutside?: (event: PointerDownOutsideEvent) => void,\n ownerDocument: Document = globalThis?.document\n) {\n const handlePointerDownOutside = useCallbackRef(onPointerDownOutside) as EventListener;\n const isPointerInsideReactTreeRef = React.useRef(false);\n const handleClickRef = React.useRef(() => {});\n\n React.useEffect(() => {\n const handlePointerDown = (event: PointerEvent) => {\n if (event.target && !isPointerInsideReactTreeRef.current) {\n const eventDetail = { originalEvent: event };\n\n function handleAndDispatchPointerDownOutsideEvent() {\n handleAndDispatchCustomEvent(\n POINTER_DOWN_OUTSIDE,\n handlePointerDownOutside,\n eventDetail,\n { discrete: true }\n );\n }\n\n /**\n * On touch devices, we need to wait for a click event because browsers implement\n * a ~350ms delay between the time the user stops touching the display and when the\n * browser executres events. We need to ensure we don't reactivate pointer-events within\n * this timeframe otherwise the browser may execute events that should have been prevented.\n *\n * Additionally, this also lets us deal automatically with cancellations when a click event\n * isn't raised because the page was considered scrolled/drag-scrolled, long-pressed, etc.\n *\n * This is why we also continuously remove the previous listener, because we cannot be\n * certain that it was raised, and therefore cleaned-up.\n */\n if (event.pointerType === 'touch') {\n ownerDocument.removeEventListener('click', handleClickRef.current);\n handleClickRef.current = handleAndDispatchPointerDownOutsideEvent;\n ownerDocument.addEventListener('click', handleClickRef.current, { once: true });\n } else {\n handleAndDispatchPointerDownOutsideEvent();\n }\n } else {\n // We need to remove the event listener in case the outside click has been canceled.\n // See: https://github.com/radix-ui/primitives/issues/2171\n ownerDocument.removeEventListener('click', handleClickRef.current);\n }\n isPointerInsideReactTreeRef.current = false;\n };\n /**\n * if this hook executes in a component that mounts via a `pointerdown` event, the event\n * would bubble up to the document and trigger a `pointerDownOutside` event. We avoid\n * this by delaying the event listener registration on the document.\n * This is not React specific, but rather how the DOM works, ie:\n * ```\n * button.addEventListener('pointerdown', () => {\n * console.log('I will log');\n * document.addEventListener('pointerdown', () => {\n * console.log('I will also log');\n * })\n * });\n */\n const timerId = window.setTimeout(() => {\n ownerDocument.addEventListener('pointerdown', handlePointerDown);\n }, 0);\n return () => {\n window.clearTimeout(timerId);\n ownerDocument.removeEventListener('pointerdown', handlePointerDown);\n ownerDocument.removeEventListener('click', handleClickRef.current);\n };\n }, [ownerDocument, handlePointerDownOutside]);\n\n return {\n // ensures we check React component tree (not just DOM tree)\n onPointerDownCapture: () => (isPointerInsideReactTreeRef.current = true),\n };\n}\n\n/**\n * Listens for when focus happens outside a react subtree.\n * Returns props to pass to the root (node) of the subtree we want to check.\n */\nfunction useFocusOutside(\n onFocusOutside?: (event: FocusOutsideEvent) => void,\n ownerDocument: Document = globalThis?.document\n) {\n const handleFocusOutside = useCallbackRef(onFocusOutside) as EventListener;\n const isFocusInsideReactTreeRef = React.useRef(false);\n\n React.useEffect(() => {\n const handleFocus = (event: FocusEvent) => {\n if (event.target && !isFocusInsideReactTreeRef.current) {\n const eventDetail = { originalEvent: event };\n handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, eventDetail, {\n discrete: false,\n });\n }\n };\n ownerDocument.addEventListener('focusin', handleFocus);\n return () => ownerDocument.removeEventListener('focusin', handleFocus);\n }, [ownerDocument, handleFocusOutside]);\n\n return {\n onFocusCapture: () => (isFocusInsideReactTreeRef.current = true),\n onBlurCapture: () => (isFocusInsideReactTreeRef.current = false),\n };\n}\n\nfunction dispatchUpdate() {\n const event = new CustomEvent(CONTEXT_UPDATE);\n document.dispatchEvent(event);\n}\n\nfunction handleAndDispatchCustomEvent<E extends CustomEvent, OriginalEvent extends Event>(\n name: string,\n handler: ((event: E) => void) | undefined,\n detail: { originalEvent: OriginalEvent } & (E extends CustomEvent<infer D> ? D : never),\n { discrete }: { discrete: boolean }\n) {\n const target = detail.originalEvent.target;\n const event = new CustomEvent(name, { bubbles: false, cancelable: true, detail });\n if (handler) target.addEventListener(name, handler as EventListener, { once: true });\n\n if (discrete) {\n dispatchDiscreteCustomEvent(target, event);\n } else {\n target.dispatchEvent(event);\n }\n}\n\nconst Root = DismissableLayer;\nconst Branch = DismissableLayerBranch;\n\nexport {\n DismissableLayer,\n DismissableLayerBranch,\n //\n Root,\n Branch,\n};\nexport type { DismissableLayerProps };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,cAAuB;AACvB,yBAAqC;AACrC,+BAAuD;AACvD,kCAAgC;AAChC,sCAA+B;AAC/B,wCAAiC;AAuJ3B;AA/IN,MAAM,yBAAyB;AAC/B,MAAM,iBAAiB;AACvB,MAAM,uBAAuB;AAC7B,MAAM,gBAAgB;AAEtB,MAAI;AAEJ,MAAM,0BAAgC,oBAAc;AAAA,IAClD,QAAQ,oBAAI,IAA6B;AAAA,IACzC,wCAAwC,oBAAI,IAA6B;AAAA,IACzE,UAAU,oBAAI,IAAmC;AAAA,EACnD,CAAC;AAsCD,MAAM,mBAAyB;AAAA,IAC7B,CAAC,OAAO,iBAAiB;AACvB,YAAM;AAAA,QACJ,8BAA8B;AAAA,QAC9B;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,GAAG;AAAA,MACL,IAAI;AACJ,YAAM,UAAgB,iBAAW,uBAAuB;AACxD,YAAM,CAAC,MAAM,OAAO,IAAU,eAAyC,IAAI;AAC3E,YAAM,gBAAgB,MAAM,iBAAiB,YAAY;AACzD,YAAM,CAAC,EAAE,KAAK,IAAU,eAAS,CAAC,CAAC;AACnC,YAAM,mBAAe,2CAAgB,cAAc,CAACA,UAAS,QAAQA,KAAI,CAAC;AAC1E,YAAM,SAAS,MAAM,KAAK,QAAQ,MAAM;AACxC,YAAM,CAAC,4CAA4C,IAAI,CAAC,GAAG,QAAQ,sCAAsC,EAAE,MAAM,EAAE;AACnH,YAAM,oDAAoD,OAAO,QAAQ,4CAA4C;AACrH,YAAM,QAAQ,OAAO,OAAO,QAAQ,IAAI,IA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UAAU;AAAA,IACrE;AAAA,EACF;AAMA,WAAS,gBACP,gBACA,gBAA0B,YAAY,UACtC;AACA,UAAM,yBAAqB,8CAAe,cAAc;AACxD,UAAM,4BAAkC,aAAO,KAAK;AAEpD,IAAM,gBAAU,MAAM;AACpB,YAAM,cAAc,CAAC,UAAsB;AACzC,YAAI,MAAM,UAAU,CAAC,0BAA0B,SAAS;AACtD,gBAAM,cAAc,EAAE,eAAe,MAAM;AAC3C,uCAA6B,eAAe,oBAAoB,aAAa;AAAA,YAC3E,UAAU;AAAA,UACZ,CAAC;AAAA,QACH;AAAA,MACF;AACA,oBAAc,iBAAiB,WAAW,WAAW;AACrD,aAAO,MAAM,cAAc,oBAAoB,WAAW,WAAW;AAAA,IACvE,GAAG,CAAC,eAAe,kBAAkB,CAAC;AAEtC,WAAO;AAAA,MACL,gBAAgB,MAAO,0BAA0B,UAAU;AAAA,MAC3D,eAAe,MAAO,0BAA0B,UAAU;AAAA,IAC5D;AAAA,EACF;AAEA,WAAS,iBAAiB;AACxB,UAAM,QAAQ,IAAI,YAAY,cAAc;AAC5C,aAAS,cAAc,KAAK;AAAA,EAC9B;AAEA,WAAS,6BACP,MACA,SACA,QACA,EAAE,SAAS,GACX;AACA,UAAM,SAAS,OAAO,cAAc;AACpC,UAAM,QAAQ,IAAI,YAAY,MAAM,EAAE,SAAS,OAAO,YAAY,MAAM,OAAO,CAAC;AAChF,QAAI,QAAS,QAAO,iBAAiB,MAAM,SAA0B,EAAE,MAAM,KAAK,CAAC;AAEnF,QAAI,UAAU;AACZ,8DAA4B,QAAQ,KAAK;AAAA,IAC3C,OAAO;AACL,aAAO,cAAc,KAAK;AAAA,IAC5B;AAAA,EACF;AAEA,MAAM,OAAO;AACb,MAAM,SAAS;",
3
+ "sources": ["../src/index.ts", "../src/DismissableLayer.tsx"],
4
+ "sourcesContent": ["'use client';\nexport {\n DismissableLayer,\n DismissableLayerBranch,\n //\n Root,\n Branch,\n} from './DismissableLayer';\nexport type { DismissableLayerProps } from './DismissableLayer';\n", "import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { Primitive, dispatchDiscreteCustomEvent } from '@radix-ui/react-primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { useCallbackRef } from '@radix-ui/react-use-callback-ref';\nimport { useEscapeKeydown } from '@radix-ui/react-use-escape-keydown';\n\nimport type * as Radix from '@radix-ui/react-primitive';\n\n/* -------------------------------------------------------------------------------------------------\n * DismissableLayer\n * -----------------------------------------------------------------------------------------------*/\n\nconst DISMISSABLE_LAYER_NAME = 'DismissableLayer';\nconst CONTEXT_UPDATE = 'dismissableLayer.update';\nconst POINTER_DOWN_OUTSIDE = 'dismissableLayer.pointerDownOutside';\nconst FOCUS_OUTSIDE = 'dismissableLayer.focusOutside';\n\nlet originalBodyPointerEvents: string;\n\nconst DismissableLayerContext = React.createContext({\n layers: new Set<DismissableLayerElement>(),\n layersWithOutsidePointerEventsDisabled: new Set<DismissableLayerElement>(),\n branches: new Set<DismissableLayerBranchElement>(),\n});\n\ntype DismissableLayerElement = React.ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = Radix.ComponentPropsWithoutRef<typeof Primitive.div>;\ninterface DismissableLayerProps extends PrimitiveDivProps {\n /**\n * When `true`, hover/focus/click interactions will be disabled on elements outside\n * the `DismissableLayer`. Users will need to click twice on outside elements to\n * interact with them: once to close the `DismissableLayer`, and again to trigger the element.\n */\n disableOutsidePointerEvents?: boolean;\n /**\n * Event handler called when the escape key is down.\n * Can be prevented.\n */\n onEscapeKeyDown?: (event: KeyboardEvent) => void;\n /**\n * Event handler called when the a `pointerdown` event happens outside of the `DismissableLayer`.\n * Can be prevented.\n */\n onPointerDownOutside?: (event: PointerDownOutsideEvent) => void;\n /**\n * Event handler called when the focus moves outside of the `DismissableLayer`.\n * Can be prevented.\n */\n onFocusOutside?: (event: FocusOutsideEvent) => void;\n /**\n * Event handler called when an interaction happens outside the `DismissableLayer`.\n * Specifically, when a `pointerdown` event happens outside or focus moves outside of it.\n * Can be prevented.\n */\n onInteractOutside?: (event: PointerDownOutsideEvent | FocusOutsideEvent) => void;\n /**\n * Handler called when the `DismissableLayer` should be dismissed\n */\n onDismiss?: () => void;\n}\n\nconst DismissableLayer = React.forwardRef<DismissableLayerElement, DismissableLayerProps>(\n (props, forwardedRef) => {\n const {\n disableOutsidePointerEvents = false,\n onEscapeKeyDown,\n onPointerDownOutside,\n onFocusOutside,\n onInteractOutside,\n onDismiss,\n ...layerProps\n } = props;\n const context = React.useContext(DismissableLayerContext);\n const [node, setNode] = React.useState<DismissableLayerElement | null>(null);\n const ownerDocument = node?.ownerDocument ?? globalThis?.document;\n const [, force] = React.useState({});\n const composedRefs = useComposedRefs(forwardedRef, (node) => setNode(node));\n const layers = Array.from(context.layers);\n const [highestLayerWithOutsidePointerEventsDisabled] = [...context.layersWithOutsidePointerEventsDisabled].slice(-1); // prettier-ignore\n const highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled); // prettier-ignore\n const index = node ? layers.indexOf(node) : -1;\n const isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0;\n const isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex;\n\n const pointerDownOutside = usePointerDownOutside((event) => {\n const target = event.target as HTMLElement;\n const isPointerDownOnBranch = [...context.branches].some((branch) => branch.contains(target));\n if (!isPointerEventsEnabled || isPointerDownOnBranch) return;\n onPointerDownOutside?.(event);\n onInteractOutside?.(event);\n if (!event.defaultPrevented) onDismiss?.();\n }, ownerDocument);\n\n const focusOutside = useFocusOutside((event) => {\n const target = event.target as HTMLElement;\n const isFocusInBranch = [...context.branches].some((branch) => branch.contains(target));\n if (isFocusInBranch) return;\n onFocusOutside?.(event);\n onInteractOutside?.(event);\n if (!event.defaultPrevented) onDismiss?.();\n }, ownerDocument);\n\n useEscapeKeydown((event) => {\n const isHighestLayer = index === context.layers.size - 1;\n if (!isHighestLayer) return;\n onEscapeKeyDown?.(event);\n if (!event.defaultPrevented && onDismiss) {\n event.preventDefault();\n onDismiss();\n }\n }, ownerDocument);\n\n React.useEffect(() => {\n if (!node) return;\n if (disableOutsidePointerEvents) {\n if (context.layersWithOutsidePointerEventsDisabled.size === 0) {\n originalBodyPointerEvents = ownerDocument.body.style.pointerEvents;\n ownerDocument.body.style.pointerEvents = 'none';\n }\n context.layersWithOutsidePointerEventsDisabled.add(node);\n }\n context.layers.add(node);\n dispatchUpdate();\n return () => {\n if (\n disableOutsidePointerEvents &&\n context.layersWithOutsidePointerEventsDisabled.size === 1\n ) {\n ownerDocument.body.style.pointerEvents = originalBodyPointerEvents;\n }\n };\n }, [node, ownerDocument, disableOutsidePointerEvents, context]);\n\n /**\n * We purposefully prevent combining this effect with the `disableOutsidePointerEvents` effect\n * because a change to `disableOutsidePointerEvents` would remove this layer from the stack\n * and add it to the end again so the layering order wouldn't be _creation order_.\n * We only want them to be removed from context stacks when unmounted.\n */\n React.useEffect(() => {\n return () => {\n if (!node) return;\n context.layers.delete(node);\n context.layersWithOutsidePointerEventsDisabled.delete(node);\n dispatchUpdate();\n };\n }, [node, context]);\n\n React.useEffect(() => {\n const handleUpdate = () => force({});\n document.addEventListener(CONTEXT_UPDATE, handleUpdate);\n return () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate);\n }, []);\n\n return (\n <Primitive.div\n {...layerProps}\n ref={composedRefs}\n style={{\n pointerEvents: isBodyPointerEventsDisabled\n ? isPointerEventsEnabled\n ? 'auto'\n : 'none'\n : undefined,\n ...props.style,\n }}\n onFocusCapture={composeEventHandlers(props.onFocusCapture, focusOutside.onFocusCapture)}\n onBlurCapture={composeEventHandlers(props.onBlurCapture, focusOutside.onBlurCapture)}\n onPointerDownCapture={composeEventHandlers(\n props.onPointerDownCapture,\n pointerDownOutside.onPointerDownCapture\n )}\n />\n );\n }\n);\n\nDismissableLayer.displayName = DISMISSABLE_LAYER_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * DismissableLayerBranch\n * -----------------------------------------------------------------------------------------------*/\n\nconst BRANCH_NAME = 'DismissableLayerBranch';\n\ntype DismissableLayerBranchElement = React.ElementRef<typeof Primitive.div>;\ninterface DismissableLayerBranchProps extends PrimitiveDivProps {}\n\nconst DismissableLayerBranch = React.forwardRef<\n DismissableLayerBranchElement,\n DismissableLayerBranchProps\n>((props, forwardedRef) => {\n const context = React.useContext(DismissableLayerContext);\n const ref = React.useRef<DismissableLayerBranchElement>(null);\n const composedRefs = useComposedRefs(forwardedRef, ref);\n\n React.useEffect(() => {\n const node = ref.current;\n if (node) {\n context.branches.add(node);\n return () => {\n context.branches.delete(node);\n };\n }\n }, [context.branches]);\n\n return <Primitive.div {...props} ref={composedRefs} />;\n});\n\nDismissableLayerBranch.displayName = BRANCH_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\ntype PointerDownOutsideEvent = CustomEvent<{ originalEvent: PointerEvent }>;\ntype FocusOutsideEvent = CustomEvent<{ originalEvent: FocusEvent }>;\n\n/**\n * Listens for `pointerdown` outside a react subtree. We use `pointerdown` rather than `pointerup`\n * to mimic layer dismissing behaviour present in OS.\n * Returns props to pass to the node we want to check for outside events.\n */\nfunction usePointerDownOutside(\n onPointerDownOutside?: (event: PointerDownOutsideEvent) => void,\n ownerDocument: Document = globalThis?.document\n) {\n const handlePointerDownOutside = useCallbackRef(onPointerDownOutside) as EventListener;\n const isPointerInsideReactTreeRef = React.useRef(false);\n const handleClickRef = React.useRef(() => {});\n\n React.useEffect(() => {\n const handlePointerDown = (event: PointerEvent) => {\n if (event.target && !isPointerInsideReactTreeRef.current) {\n const eventDetail = { originalEvent: event };\n\n function handleAndDispatchPointerDownOutsideEvent() {\n handleAndDispatchCustomEvent(\n POINTER_DOWN_OUTSIDE,\n handlePointerDownOutside,\n eventDetail,\n { discrete: true }\n );\n }\n\n /**\n * On touch devices, we need to wait for a click event because browsers implement\n * a ~350ms delay between the time the user stops touching the display and when the\n * browser executres events. We need to ensure we don't reactivate pointer-events within\n * this timeframe otherwise the browser may execute events that should have been prevented.\n *\n * Additionally, this also lets us deal automatically with cancellations when a click event\n * isn't raised because the page was considered scrolled/drag-scrolled, long-pressed, etc.\n *\n * This is why we also continuously remove the previous listener, because we cannot be\n * certain that it was raised, and therefore cleaned-up.\n */\n if (event.pointerType === 'touch') {\n ownerDocument.removeEventListener('click', handleClickRef.current);\n handleClickRef.current = handleAndDispatchPointerDownOutsideEvent;\n ownerDocument.addEventListener('click', handleClickRef.current, { once: true });\n } else {\n handleAndDispatchPointerDownOutsideEvent();\n }\n } else {\n // We need to remove the event listener in case the outside click has been canceled.\n // See: https://github.com/radix-ui/primitives/issues/2171\n ownerDocument.removeEventListener('click', handleClickRef.current);\n }\n isPointerInsideReactTreeRef.current = false;\n };\n /**\n * if this hook executes in a component that mounts via a `pointerdown` event, the event\n * would bubble up to the document and trigger a `pointerDownOutside` event. We avoid\n * this by delaying the event listener registration on the document.\n * This is not React specific, but rather how the DOM works, ie:\n * ```\n * button.addEventListener('pointerdown', () => {\n * console.log('I will log');\n * document.addEventListener('pointerdown', () => {\n * console.log('I will also log');\n * })\n * });\n */\n const timerId = window.setTimeout(() => {\n ownerDocument.addEventListener('pointerdown', handlePointerDown);\n }, 0);\n return () => {\n window.clearTimeout(timerId);\n ownerDocument.removeEventListener('pointerdown', handlePointerDown);\n ownerDocument.removeEventListener('click', handleClickRef.current);\n };\n }, [ownerDocument, handlePointerDownOutside]);\n\n return {\n // ensures we check React component tree (not just DOM tree)\n onPointerDownCapture: () => (isPointerInsideReactTreeRef.current = true),\n };\n}\n\n/**\n * Listens for when focus happens outside a react subtree.\n * Returns props to pass to the root (node) of the subtree we want to check.\n */\nfunction useFocusOutside(\n onFocusOutside?: (event: FocusOutsideEvent) => void,\n ownerDocument: Document = globalThis?.document\n) {\n const handleFocusOutside = useCallbackRef(onFocusOutside) as EventListener;\n const isFocusInsideReactTreeRef = React.useRef(false);\n\n React.useEffect(() => {\n const handleFocus = (event: FocusEvent) => {\n if (event.target && !isFocusInsideReactTreeRef.current) {\n const eventDetail = { originalEvent: event };\n handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, eventDetail, {\n discrete: false,\n });\n }\n };\n ownerDocument.addEventListener('focusin', handleFocus);\n return () => ownerDocument.removeEventListener('focusin', handleFocus);\n }, [ownerDocument, handleFocusOutside]);\n\n return {\n onFocusCapture: () => (isFocusInsideReactTreeRef.current = true),\n onBlurCapture: () => (isFocusInsideReactTreeRef.current = false),\n };\n}\n\nfunction dispatchUpdate() {\n const event = new CustomEvent(CONTEXT_UPDATE);\n document.dispatchEvent(event);\n}\n\nfunction handleAndDispatchCustomEvent<E extends CustomEvent, OriginalEvent extends Event>(\n name: string,\n handler: ((event: E) => void) | undefined,\n detail: { originalEvent: OriginalEvent } & (E extends CustomEvent<infer D> ? D : never),\n { discrete }: { discrete: boolean }\n) {\n const target = detail.originalEvent.target;\n const event = new CustomEvent(name, { bubbles: false, cancelable: true, detail });\n if (handler) target.addEventListener(name, handler as EventListener, { once: true });\n\n if (discrete) {\n dispatchDiscreteCustomEvent(target, event);\n } else {\n target.dispatchEvent(event);\n }\n}\n\nconst Root = DismissableLayer;\nconst Branch = DismissableLayerBranch;\n\nexport {\n DismissableLayer,\n DismissableLayerBranch,\n //\n Root,\n Branch,\n};\nexport type { DismissableLayerProps };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,uBAAqC;AACrC,6BAAuD;AACvD,gCAAgC;AAChC,oCAA+B;AAC/B,sCAAiC;AAuJ3B;AA/IN,IAAM,yBAAyB;AAC/B,IAAM,iBAAiB;AACvB,IAAM,uBAAuB;AAC7B,IAAM,gBAAgB;AAEtB,IAAI;AAEJ,IAAM,0BAAgC,oBAAc;AAAA,EAClD,QAAQ,oBAAI,IAA6B;AAAA,EACzC,wCAAwC,oBAAI,IAA6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AA0B,UAAU;AAAA,EAC5D;AACF;AAEA,SAAS,iBAAiB;AACxB,QAAM,QAAQ,IAAI,YAAY,cAAc;AAC5C,WAAS,cAAc,KAAK;AAC9B;AAEA,SAAS,6BACP,MACA,SACA,QACA,EAAE,SAAS,GACX;AACA,QAAM,SAAS,OAAO,cAAc;AACpC,QAAM,QAAQ,IAAI,YAAY,MAAM,EAAE,SAAS,OAAO,YAAY,MAAM,OAAO,CAAC;AAChF,MAAI,QAAS,QAAO,iBAAiB,MAAM,SAA0B,EAAE,MAAM,KAAK,CAAC;AAEnF,MAAI,UAAU;AACZ,4DAA4B,QAAQ,KAAK;AAAA,EAC3C,OAAO;AACL,WAAO,cAAc,KAAK;AAAA,EAC5B;AACF;AAEA,IAAM,OAAO;AACb,IAAM,SAAS;",
6
6
  "names": ["node", "handleAndDispatchPointerDownOutsideEvent"]
7
7
  }
package/dist/index.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ "use client";
2
+
1
3
  // packages/react/dismissable-layer/src/DismissableLayer.tsx
2
4
  import * as React from "react";
3
5
  import { composeEventHandlers } from "@radix-ui/primitive";
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/DismissableLayer.tsx"],
4
4
  "sourcesContent": ["import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { Primitive, dispatchDiscreteCustomEvent } from '@radix-ui/react-primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { useCallbackRef } from '@radix-ui/react-use-callback-ref';\nimport { useEscapeKeydown } from '@radix-ui/react-use-escape-keydown';\n\nimport type * as Radix from '@radix-ui/react-primitive';\n\n/* -------------------------------------------------------------------------------------------------\n * DismissableLayer\n * -----------------------------------------------------------------------------------------------*/\n\nconst DISMISSABLE_LAYER_NAME = 'DismissableLayer';\nconst CONTEXT_UPDATE = 'dismissableLayer.update';\nconst POINTER_DOWN_OUTSIDE = 'dismissableLayer.pointerDownOutside';\nconst FOCUS_OUTSIDE = 'dismissableLayer.focusOutside';\n\nlet originalBodyPointerEvents: string;\n\nconst DismissableLayerContext = React.createContext({\n layers: new Set<DismissableLayerElement>(),\n layersWithOutsidePointerEventsDisabled: new Set<DismissableLayerElement>(),\n branches: new Set<DismissableLayerBranchElement>(),\n});\n\ntype DismissableLayerElement = React.ElementRef<typeof Primitive.div>;\ntype PrimitiveDivProps = Radix.ComponentPropsWithoutRef<typeof Primitive.div>;\ninterface DismissableLayerProps extends PrimitiveDivProps {\n /**\n * When `true`, hover/focus/click interactions will be disabled on elements outside\n * the `DismissableLayer`. Users will need to click twice on outside elements to\n * interact with them: once to close the `DismissableLayer`, and again to trigger the element.\n */\n disableOutsidePointerEvents?: boolean;\n /**\n * Event handler called when the escape key is down.\n * Can be prevented.\n */\n onEscapeKeyDown?: (event: KeyboardEvent) => void;\n /**\n * Event handler called when the a `pointerdown` event happens outside of the `DismissableLayer`.\n * Can be prevented.\n */\n onPointerDownOutside?: (event: PointerDownOutsideEvent) => void;\n /**\n * Event handler called when the focus moves outside of the `DismissableLayer`.\n * Can be prevented.\n */\n onFocusOutside?: (event: FocusOutsideEvent) => void;\n /**\n * Event handler called when an interaction happens outside the `DismissableLayer`.\n * Specifically, when a `pointerdown` event happens outside or focus moves outside of it.\n * Can be prevented.\n */\n onInteractOutside?: (event: PointerDownOutsideEvent | FocusOutsideEvent) => void;\n /**\n * Handler called when the `DismissableLayer` should be dismissed\n */\n onDismiss?: () => void;\n}\n\nconst DismissableLayer = React.forwardRef<DismissableLayerElement, DismissableLayerProps>(\n (props, forwardedRef) => {\n const {\n disableOutsidePointerEvents = false,\n onEscapeKeyDown,\n onPointerDownOutside,\n onFocusOutside,\n onInteractOutside,\n onDismiss,\n ...layerProps\n } = props;\n const context = React.useContext(DismissableLayerContext);\n const [node, setNode] = React.useState<DismissableLayerElement | null>(null);\n const ownerDocument = node?.ownerDocument ?? globalThis?.document;\n const [, force] = React.useState({});\n const composedRefs = useComposedRefs(forwardedRef, (node) => setNode(node));\n const layers = Array.from(context.layers);\n const [highestLayerWithOutsidePointerEventsDisabled] = [...context.layersWithOutsidePointerEventsDisabled].slice(-1); // prettier-ignore\n const highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled); // prettier-ignore\n const index = node ? layers.indexOf(node) : -1;\n const isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0;\n const isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex;\n\n const pointerDownOutside = usePointerDownOutside((event) => {\n const target = event.target as HTMLElement;\n const isPointerDownOnBranch = [...context.branches].some((branch) => branch.contains(target));\n if (!isPointerEventsEnabled || isPointerDownOnBranch) return;\n onPointerDownOutside?.(event);\n onInteractOutside?.(event);\n if (!event.defaultPrevented) onDismiss?.();\n }, ownerDocument);\n\n const focusOutside = useFocusOutside((event) => {\n const target = event.target as HTMLElement;\n const isFocusInBranch = [...context.branches].some((branch) => branch.contains(target));\n if (isFocusInBranch) return;\n onFocusOutside?.(event);\n onInteractOutside?.(event);\n if (!event.defaultPrevented) onDismiss?.();\n }, ownerDocument);\n\n useEscapeKeydown((event) => {\n const isHighestLayer = index === context.layers.size - 1;\n if (!isHighestLayer) return;\n onEscapeKeyDown?.(event);\n if (!event.defaultPrevented && onDismiss) {\n event.preventDefault();\n onDismiss();\n }\n }, ownerDocument);\n\n React.useEffect(() => {\n if (!node) return;\n if (disableOutsidePointerEvents) {\n if (context.layersWithOutsidePointerEventsDisabled.size === 0) {\n originalBodyPointerEvents = ownerDocument.body.style.pointerEvents;\n ownerDocument.body.style.pointerEvents = 'none';\n }\n context.layersWithOutsidePointerEventsDisabled.add(node);\n }\n context.layers.add(node);\n dispatchUpdate();\n return () => {\n if (\n disableOutsidePointerEvents &&\n context.layersWithOutsidePointerEventsDisabled.size === 1\n ) {\n ownerDocument.body.style.pointerEvents = originalBodyPointerEvents;\n }\n };\n }, [node, ownerDocument, disableOutsidePointerEvents, context]);\n\n /**\n * We purposefully prevent combining this effect with the `disableOutsidePointerEvents` effect\n * because a change to `disableOutsidePointerEvents` would remove this layer from the stack\n * and add it to the end again so the layering order wouldn't be _creation order_.\n * We only want them to be removed from context stacks when unmounted.\n */\n React.useEffect(() => {\n return () => {\n if (!node) return;\n context.layers.delete(node);\n context.layersWithOutsidePointerEventsDisabled.delete(node);\n dispatchUpdate();\n };\n }, [node, context]);\n\n React.useEffect(() => {\n const handleUpdate = () => force({});\n document.addEventListener(CONTEXT_UPDATE, handleUpdate);\n return () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate);\n }, []);\n\n return (\n <Primitive.div\n {...layerProps}\n ref={composedRefs}\n style={{\n pointerEvents: isBodyPointerEventsDisabled\n ? isPointerEventsEnabled\n ? 'auto'\n : 'none'\n : undefined,\n ...props.style,\n }}\n onFocusCapture={composeEventHandlers(props.onFocusCapture, focusOutside.onFocusCapture)}\n onBlurCapture={composeEventHandlers(props.onBlurCapture, focusOutside.onBlurCapture)}\n onPointerDownCapture={composeEventHandlers(\n props.onPointerDownCapture,\n pointerDownOutside.onPointerDownCapture\n )}\n />\n );\n }\n);\n\nDismissableLayer.displayName = DISMISSABLE_LAYER_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * DismissableLayerBranch\n * -----------------------------------------------------------------------------------------------*/\n\nconst BRANCH_NAME = 'DismissableLayerBranch';\n\ntype DismissableLayerBranchElement = React.ElementRef<typeof Primitive.div>;\ninterface DismissableLayerBranchProps extends PrimitiveDivProps {}\n\nconst DismissableLayerBranch = React.forwardRef<\n DismissableLayerBranchElement,\n DismissableLayerBranchProps\n>((props, forwardedRef) => {\n const context = React.useContext(DismissableLayerContext);\n const ref = React.useRef<DismissableLayerBranchElement>(null);\n const composedRefs = useComposedRefs(forwardedRef, ref);\n\n React.useEffect(() => {\n const node = ref.current;\n if (node) {\n context.branches.add(node);\n return () => {\n context.branches.delete(node);\n };\n }\n }, [context.branches]);\n\n return <Primitive.div {...props} ref={composedRefs} />;\n});\n\nDismissableLayerBranch.displayName = BRANCH_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\ntype PointerDownOutsideEvent = CustomEvent<{ originalEvent: PointerEvent }>;\ntype FocusOutsideEvent = CustomEvent<{ originalEvent: FocusEvent }>;\n\n/**\n * Listens for `pointerdown` outside a react subtree. We use `pointerdown` rather than `pointerup`\n * to mimic layer dismissing behaviour present in OS.\n * Returns props to pass to the node we want to check for outside events.\n */\nfunction usePointerDownOutside(\n onPointerDownOutside?: (event: PointerDownOutsideEvent) => void,\n ownerDocument: Document = globalThis?.document\n) {\n const handlePointerDownOutside = useCallbackRef(onPointerDownOutside) as EventListener;\n const isPointerInsideReactTreeRef = React.useRef(false);\n const handleClickRef = React.useRef(() => {});\n\n React.useEffect(() => {\n const handlePointerDown = (event: PointerEvent) => {\n if (event.target && !isPointerInsideReactTreeRef.current) {\n const eventDetail = { originalEvent: event };\n\n function handleAndDispatchPointerDownOutsideEvent() {\n handleAndDispatchCustomEvent(\n POINTER_DOWN_OUTSIDE,\n handlePointerDownOutside,\n eventDetail,\n { discrete: true }\n );\n }\n\n /**\n * On touch devices, we need to wait for a click event because browsers implement\n * a ~350ms delay between the time the user stops touching the display and when the\n * browser executres events. We need to ensure we don't reactivate pointer-events within\n * this timeframe otherwise the browser may execute events that should have been prevented.\n *\n * Additionally, this also lets us deal automatically with cancellations when a click event\n * isn't raised because the page was considered scrolled/drag-scrolled, long-pressed, etc.\n *\n * This is why we also continuously remove the previous listener, because we cannot be\n * certain that it was raised, and therefore cleaned-up.\n */\n if (event.pointerType === 'touch') {\n ownerDocument.removeEventListener('click', handleClickRef.current);\n handleClickRef.current = handleAndDispatchPointerDownOutsideEvent;\n ownerDocument.addEventListener('click', handleClickRef.current, { once: true });\n } else {\n handleAndDispatchPointerDownOutsideEvent();\n }\n } else {\n // We need to remove the event listener in case the outside click has been canceled.\n // See: https://github.com/radix-ui/primitives/issues/2171\n ownerDocument.removeEventListener('click', handleClickRef.current);\n }\n isPointerInsideReactTreeRef.current = false;\n };\n /**\n * if this hook executes in a component that mounts via a `pointerdown` event, the event\n * would bubble up to the document and trigger a `pointerDownOutside` event. We avoid\n * this by delaying the event listener registration on the document.\n * This is not React specific, but rather how the DOM works, ie:\n * ```\n * button.addEventListener('pointerdown', () => {\n * console.log('I will log');\n * document.addEventListener('pointerdown', () => {\n * console.log('I will also log');\n * })\n * });\n */\n const timerId = window.setTimeout(() => {\n ownerDocument.addEventListener('pointerdown', handlePointerDown);\n }, 0);\n return () => {\n window.clearTimeout(timerId);\n ownerDocument.removeEventListener('pointerdown', handlePointerDown);\n ownerDocument.removeEventListener('click', handleClickRef.current);\n };\n }, [ownerDocument, handlePointerDownOutside]);\n\n return {\n // ensures we check React component tree (not just DOM tree)\n onPointerDownCapture: () => (isPointerInsideReactTreeRef.current = true),\n };\n}\n\n/**\n * Listens for when focus happens outside a react subtree.\n * Returns props to pass to the root (node) of the subtree we want to check.\n */\nfunction useFocusOutside(\n onFocusOutside?: (event: FocusOutsideEvent) => void,\n ownerDocument: Document = globalThis?.document\n) {\n const handleFocusOutside = useCallbackRef(onFocusOutside) as EventListener;\n const isFocusInsideReactTreeRef = React.useRef(false);\n\n React.useEffect(() => {\n const handleFocus = (event: FocusEvent) => {\n if (event.target && !isFocusInsideReactTreeRef.current) {\n const eventDetail = { originalEvent: event };\n handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, eventDetail, {\n discrete: false,\n });\n }\n };\n ownerDocument.addEventListener('focusin', handleFocus);\n return () => ownerDocument.removeEventListener('focusin', handleFocus);\n }, [ownerDocument, handleFocusOutside]);\n\n return {\n onFocusCapture: () => (isFocusInsideReactTreeRef.current = true),\n onBlurCapture: () => (isFocusInsideReactTreeRef.current = false),\n };\n}\n\nfunction dispatchUpdate() {\n const event = new CustomEvent(CONTEXT_UPDATE);\n document.dispatchEvent(event);\n}\n\nfunction handleAndDispatchCustomEvent<E extends CustomEvent, OriginalEvent extends Event>(\n name: string,\n handler: ((event: E) => void) | undefined,\n detail: { originalEvent: OriginalEvent } & (E extends CustomEvent<infer D> ? D : never),\n { discrete }: { discrete: boolean }\n) {\n const target = detail.originalEvent.target;\n const event = new CustomEvent(name, { bubbles: false, cancelable: true, detail });\n if (handler) target.addEventListener(name, handler as EventListener, { once: true });\n\n if (discrete) {\n dispatchDiscreteCustomEvent(target, event);\n } else {\n target.dispatchEvent(event);\n }\n}\n\nconst Root = DismissableLayer;\nconst Branch = DismissableLayerBranch;\n\nexport {\n DismissableLayer,\n DismissableLayerBranch,\n //\n Root,\n Branch,\n};\nexport type { DismissableLayerProps };\n"],
5
- "mappings": ";AAAA,YAAY,WAAW;AACvB,SAAS,4BAA4B;AACrC,SAAS,WAAW,mCAAmC;AACvD,SAAS,uBAAuB;AAChC,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AAuJ3B;AA/IN,IAAM,yBAAyB;AAC/B,IAAM,iBAAiB;AACvB,IAAM,uBAAuB;AAC7B,IAAM,gBAAgB;AAEtB,IAAI;AAEJ,IAAM,0BAAgC,oBAAc;AAAA,EAClD,QAAQ,oBAAI,IAA6B;AAAA,EACzC,wCAAwC,oBAAI,IAA6B;AAAA,EACzE,UAAU,oBAAI,IAAmC;AACnD,CAAC;AAsCD,IAAM,mBAAyB;AAAA,EAC7B,CAAC,OAAO,iBAAiB;AACvB,UAAM;AAAA,MACJ,8BAA8B;AAAA,MAC9B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IACL,IAAI;AACJ,UAAM,UAAgB,iBAAW,uBAAuB;AACxD,UAAM,CAAC,MAAM,OAAO,IAAU,eAAyC,IAAI;AAC3E,UAAM,gBAAgB,MAAM,iBAAiB,YAAY;AACzD,UAAM,CAAC,EAAE,KAAK,IAAU,eAAS,CAAC,CAAC;AACnC,UAAM,eAAe,gBAAgB,cAAc,CAACA,UAAS,QAAQA,KAAI,CAAC;AAC1E,UAAM,SAAS,MAAM,KAAK,QAAQ,MAAM;AACxC,UAA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;AAC3C,qCAA6B,eAAe,oBAAoB,aAAa;AAAA,UAC3E,UAAU;AAAA,QACZ,CAAC;AAAA,MACH;AAAA,IACF;AACA,kBAAc,iBAAiB,WAAW,WAAW;AACrD,WAAO,MAAM,cAAc,oBAAoB,WAAW,WAAW;AAAA,EACvE,GAAG,CAAC,eAAe,kBAAkB,CAAC;AAEtC,SAAO;AAAA,IACL,gBAAgB,MAAO,0BAA0B,UAAU;AAAA,IAC3D,eAAe,MAAO,0BAA0B,UAAU;AAAA,EAC5D;AACF;AAEA,SAAS,iBAAiB;AACxB,QAAM,QAAQ,IAAI,YAAY,cAAc;AAC5C,WAAS,cAAc,KAAK;AAC9B;AAEA,SAAS,6BACP,MACA,SACA,QACA,EAAE,SAAS,GACX;AACA,QAAM,SAAS,OAAO,cAAc;AACpC,QAAM,QAAQ,IAAI,YAAY,MAAM,EAAE,SAAS,OAAO,YAAY,MAAM,OAAO,CAAC;AAChF,MAAI,QAAS,QAAO,iBAAiB,MAAM,SAA0B,EAAE,MAAM,KAAK,CAAC;AAEnF,MAAI,UAAU;AACZ,gCAA4B,QAAQ,KAAK;AAAA,EAC3C,OAAO;AACL,WAAO,cAAc,KAAK;AAAA,EAC5B;AACF;AAEA,IAAM,OAAO;AACb,IAAM,SAAS;",
6
6
  "names": ["node", "handleAndDispatchPointerDownOutsideEvent"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radix-ui/react-dismissable-layer",
3
- "version": "1.1.0-rc.1",
3
+ "version": "1.1.0-rc.3",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": {
@@ -28,11 +28,11 @@
28
28
  "version": "yarn version"
29
29
  },
30
30
  "dependencies": {
31
- "@radix-ui/primitive": "1.1.0-rc.1",
32
- "@radix-ui/react-compose-refs": "1.1.0-rc.1",
33
- "@radix-ui/react-primitive": "1.1.0-rc.1",
34
- "@radix-ui/react-use-callback-ref": "1.1.0-rc.1",
35
- "@radix-ui/react-use-escape-keydown": "1.1.0-rc.1"
31
+ "@radix-ui/primitive": "1.1.0-rc.3",
32
+ "@radix-ui/react-compose-refs": "1.1.0-rc.3",
33
+ "@radix-ui/react-primitive": "1.1.0-rc.3",
34
+ "@radix-ui/react-use-callback-ref": "1.1.0-rc.3",
35
+ "@radix-ui/react-use-escape-keydown": "1.1.0-rc.3"
36
36
  },
37
37
  "devDependencies": {
38
38
  "react-remove-scroll": "2.5.7"