@radix-ui/react-dismissable-layer 0.1.6-rc.7 → 1.0.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.ts.map +1 -1
- package/dist/index.js +53 -36
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +48 -22
- package/dist/index.module.js.map +1 -1
- package/package.json +9 -9
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;
|
|
1
|
+
{"mappings":";;;AA2BA,yBAAyB,MAAM,wBAAwB,CAAC,OAAO,UAAU,GAAG,CAAC,CAAC;AAC9E,sCAAgC,SAAQ,iBAAiB;IACvD;;;;OAIG;IACH,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC;;;OAGG;IACH,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IACjD;;;OAGG;IACH,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,IAAI,CAAC;IAChE;;;OAGG;IACH,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;IACpD;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,uBAAuB,GAAG,iBAAiB,KAAK,IAAI,CAAC;IACjF;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB;AAED,OAAA,MAAM,8GAiHL,CAAC;AAWF,qCAAsC,SAAQ,iBAAiB;CAAG;AAElE,OAAA,MAAM,0HAmBJ,CAAC;AAMH,+BAA+B,WAAW,CAAC;IAAE,aAAa,EAAE,YAAY,CAAA;CAAE,CAAC,CAAC;AAC5E,yBAAyB,WAAW,CAAC;IAAE,aAAa,EAAE,UAAU,CAAA;CAAE,CAAC,CAAC;AA8HpE,OAAA,MAAM,kGAAuB,CAAC;AAC9B,OAAA,MAAM,0GAA+B,CAAC","sources":["packages/react/dismissable-layer/src/packages/react/dismissable-layer/src/DismissableLayer.tsx","packages/react/dismissable-layer/src/packages/react/dismissable-layer/src/index.ts","packages/react/dismissable-layer/src/index.ts"],"sourcesContent":[null,null,"export {\n DismissableLayer,\n DismissableLayerBranch,\n //\n Root,\n Branch,\n} from './DismissableLayer';\nexport type { DismissableLayerProps } from './DismissableLayer';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
|
package/dist/index.js
CHANGED
|
@@ -3,39 +3,20 @@ var $g2vWm$react = require("react");
|
|
|
3
3
|
var $g2vWm$radixuiprimitive = require("@radix-ui/primitive");
|
|
4
4
|
var $g2vWm$radixuireactprimitive = require("@radix-ui/react-primitive");
|
|
5
5
|
var $g2vWm$radixuireactcomposerefs = require("@radix-ui/react-compose-refs");
|
|
6
|
-
var $g2vWm$radixuireactusebodypointerevents = require("@radix-ui/react-use-body-pointer-events");
|
|
7
6
|
var $g2vWm$radixuireactusecallbackref = require("@radix-ui/react-use-callback-ref");
|
|
8
7
|
var $g2vWm$radixuireactuseescapekeydown = require("@radix-ui/react-use-escape-keydown");
|
|
9
8
|
|
|
10
|
-
function $parcel$
|
|
11
|
-
Object.
|
|
12
|
-
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
Object.defineProperty(dest, key, {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: function get() {
|
|
19
|
-
return source[key];
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
return dest;
|
|
9
|
+
function $parcel$export(e, n, v, s) {
|
|
10
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
25
11
|
}
|
|
26
12
|
function $parcel$interopDefault(a) {
|
|
27
13
|
return a && a.__esModule ? a.default : a;
|
|
28
14
|
}
|
|
29
|
-
function $parcel$export(e, n, v, s) {
|
|
30
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
31
|
-
}
|
|
32
|
-
var $d715e0554b679f1f$exports = {};
|
|
33
|
-
|
|
34
|
-
$parcel$export($d715e0554b679f1f$exports, "DismissableLayer", () => $d715e0554b679f1f$export$177fb62ff3ec1f22);
|
|
35
|
-
$parcel$export($d715e0554b679f1f$exports, "DismissableLayerBranch", () => $d715e0554b679f1f$export$4d5eb2109db14228);
|
|
36
|
-
$parcel$export($d715e0554b679f1f$exports, "Root", () => $d715e0554b679f1f$export$be92b6f5f03c0fe9);
|
|
37
|
-
$parcel$export($d715e0554b679f1f$exports, "Branch", () => $d715e0554b679f1f$export$aecb2ddcb55c95be);
|
|
38
15
|
|
|
16
|
+
$parcel$export(module.exports, "DismissableLayer", () => $d715e0554b679f1f$export$177fb62ff3ec1f22);
|
|
17
|
+
$parcel$export(module.exports, "DismissableLayerBranch", () => $d715e0554b679f1f$export$4d5eb2109db14228);
|
|
18
|
+
$parcel$export(module.exports, "Root", () => $d715e0554b679f1f$export$be92b6f5f03c0fe9);
|
|
19
|
+
$parcel$export(module.exports, "Branch", () => $d715e0554b679f1f$export$aecb2ddcb55c95be);
|
|
39
20
|
|
|
40
21
|
|
|
41
22
|
|
|
@@ -49,6 +30,7 @@ $parcel$export($d715e0554b679f1f$exports, "Branch", () => $d715e0554b679f1f$expo
|
|
|
49
30
|
const $d715e0554b679f1f$var$CONTEXT_UPDATE = 'dismissableLayer.update';
|
|
50
31
|
const $d715e0554b679f1f$var$POINTER_DOWN_OUTSIDE = 'dismissableLayer.pointerDownOutside';
|
|
51
32
|
const $d715e0554b679f1f$var$FOCUS_OUTSIDE = 'dismissableLayer.focusOutside';
|
|
33
|
+
let $d715e0554b679f1f$var$originalBodyPointerEvents;
|
|
52
34
|
const $d715e0554b679f1f$var$DismissableLayerContext = /*#__PURE__*/ $g2vWm$react.createContext({
|
|
53
35
|
layers: new Set(),
|
|
54
36
|
layersWithOutsidePointerEventsDisabled: new Set(),
|
|
@@ -95,16 +77,25 @@ const $d715e0554b679f1f$export$177fb62ff3ec1f22 = /*#__PURE__*/ $g2vWm$react.for
|
|
|
95
77
|
const isHighestLayer = index === context.layers.size - 1;
|
|
96
78
|
if (!isHighestLayer) return;
|
|
97
79
|
onEscapeKeyDown === null || onEscapeKeyDown === void 0 || onEscapeKeyDown(event);
|
|
98
|
-
if (!event.defaultPrevented
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
80
|
+
if (!event.defaultPrevented && onDismiss) {
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
onDismiss();
|
|
83
|
+
}
|
|
102
84
|
});
|
|
103
85
|
$g2vWm$react.useEffect(()=>{
|
|
104
86
|
if (!node1) return;
|
|
105
|
-
if (disableOutsidePointerEvents)
|
|
87
|
+
if (disableOutsidePointerEvents) {
|
|
88
|
+
if (context.layersWithOutsidePointerEventsDisabled.size === 0) {
|
|
89
|
+
$d715e0554b679f1f$var$originalBodyPointerEvents = document.body.style.pointerEvents;
|
|
90
|
+
document.body.style.pointerEvents = 'none';
|
|
91
|
+
}
|
|
92
|
+
context.layersWithOutsidePointerEventsDisabled.add(node1);
|
|
93
|
+
}
|
|
106
94
|
context.layers.add(node1);
|
|
107
95
|
$d715e0554b679f1f$var$dispatchUpdate();
|
|
96
|
+
return ()=>{
|
|
97
|
+
if (disableOutsidePointerEvents && context.layersWithOutsidePointerEventsDisabled.size === 1) document.body.style.pointerEvents = $d715e0554b679f1f$var$originalBodyPointerEvents;
|
|
98
|
+
};
|
|
108
99
|
}, [
|
|
109
100
|
node1,
|
|
110
101
|
disableOutsidePointerEvents,
|
|
@@ -179,13 +170,36 @@ const $d715e0554b679f1f$export$4d5eb2109db14228 = /*#__PURE__*/ $g2vWm$react.for
|
|
|
179
170
|
*/ function $d715e0554b679f1f$var$usePointerDownOutside(onPointerDownOutside) {
|
|
180
171
|
const handlePointerDownOutside = $g2vWm$radixuireactusecallbackref.useCallbackRef(onPointerDownOutside);
|
|
181
172
|
const isPointerInsideReactTreeRef = $g2vWm$react.useRef(false);
|
|
173
|
+
const handleClickRef = $g2vWm$react.useRef(()=>{});
|
|
182
174
|
$g2vWm$react.useEffect(()=>{
|
|
183
175
|
const handlePointerDown = (event)=>{
|
|
184
176
|
if (event.target && !isPointerInsideReactTreeRef.current) {
|
|
185
177
|
const eventDetail = {
|
|
186
178
|
originalEvent: event
|
|
187
179
|
};
|
|
188
|
-
|
|
180
|
+
function handleAndDispatchPointerDownOutsideEvent() {
|
|
181
|
+
$d715e0554b679f1f$var$handleAndDispatchCustomEvent($d715e0554b679f1f$var$POINTER_DOWN_OUTSIDE, handlePointerDownOutside, eventDetail, {
|
|
182
|
+
discrete: true
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* On touch devices, we need to wait for a click event because browsers implement
|
|
187
|
+
* a ~350ms delay between the time the user stops touching the display and when the
|
|
188
|
+
* browser executres events. We need to ensure we don't reactivate pointer-events within
|
|
189
|
+
* this timeframe otherwise the browser may execute events that should have been prevented.
|
|
190
|
+
*
|
|
191
|
+
* Additionally, this also lets us deal automatically with cancellations when a click event
|
|
192
|
+
* isn't raised because the page was considered scrolled/drag-scrolled, long-pressed, etc.
|
|
193
|
+
*
|
|
194
|
+
* This is why we also continuously remove the previous listener, because we cannot be
|
|
195
|
+
* certain that it was raised, and therefore cleaned-up.
|
|
196
|
+
*/ if (event.pointerType === 'touch') {
|
|
197
|
+
document.removeEventListener('click', handleClickRef.current);
|
|
198
|
+
handleClickRef.current = handleAndDispatchPointerDownOutsideEvent;
|
|
199
|
+
document.addEventListener('click', handleClickRef.current, {
|
|
200
|
+
once: true
|
|
201
|
+
});
|
|
202
|
+
} else handleAndDispatchPointerDownOutsideEvent();
|
|
189
203
|
}
|
|
190
204
|
isPointerInsideReactTreeRef.current = false;
|
|
191
205
|
};
|
|
@@ -207,6 +221,7 @@ const $d715e0554b679f1f$export$4d5eb2109db14228 = /*#__PURE__*/ $g2vWm$react.for
|
|
|
207
221
|
return ()=>{
|
|
208
222
|
window.clearTimeout(timerId);
|
|
209
223
|
document.removeEventListener('pointerdown', handlePointerDown);
|
|
224
|
+
document.removeEventListener('click', handleClickRef.current);
|
|
210
225
|
};
|
|
211
226
|
}, [
|
|
212
227
|
handlePointerDownOutside
|
|
@@ -228,7 +243,9 @@ const $d715e0554b679f1f$export$4d5eb2109db14228 = /*#__PURE__*/ $g2vWm$react.for
|
|
|
228
243
|
const eventDetail = {
|
|
229
244
|
originalEvent: event
|
|
230
245
|
};
|
|
231
|
-
$d715e0554b679f1f$var$
|
|
246
|
+
$d715e0554b679f1f$var$handleAndDispatchCustomEvent($d715e0554b679f1f$var$FOCUS_OUTSIDE, handleFocusOutside, eventDetail, {
|
|
247
|
+
discrete: false
|
|
248
|
+
});
|
|
232
249
|
}
|
|
233
250
|
};
|
|
234
251
|
document.addEventListener('focusin', handleFocus);
|
|
@@ -244,10 +261,10 @@ const $d715e0554b679f1f$export$4d5eb2109db14228 = /*#__PURE__*/ $g2vWm$react.for
|
|
|
244
261
|
};
|
|
245
262
|
}
|
|
246
263
|
function $d715e0554b679f1f$var$dispatchUpdate() {
|
|
247
|
-
const event = new
|
|
264
|
+
const event = new CustomEvent($d715e0554b679f1f$var$CONTEXT_UPDATE);
|
|
248
265
|
document.dispatchEvent(event);
|
|
249
266
|
}
|
|
250
|
-
function $d715e0554b679f1f$var$
|
|
267
|
+
function $d715e0554b679f1f$var$handleAndDispatchCustomEvent(name, handler, detail, { discrete: discrete }) {
|
|
251
268
|
const target = detail.originalEvent.target;
|
|
252
269
|
const event = new CustomEvent(name, {
|
|
253
270
|
bubbles: false,
|
|
@@ -257,13 +274,13 @@ function $d715e0554b679f1f$var$dispatchCustomEvent(name, handler, detail) {
|
|
|
257
274
|
if (handler) target.addEventListener(name, handler, {
|
|
258
275
|
once: true
|
|
259
276
|
});
|
|
260
|
-
|
|
277
|
+
if (discrete) $g2vWm$radixuireactprimitive.dispatchDiscreteCustomEvent(target, event);
|
|
278
|
+
else target.dispatchEvent(event);
|
|
261
279
|
}
|
|
262
280
|
const $d715e0554b679f1f$export$be92b6f5f03c0fe9 = $d715e0554b679f1f$export$177fb62ff3ec1f22;
|
|
263
281
|
const $d715e0554b679f1f$export$aecb2ddcb55c95be = $d715e0554b679f1f$export$4d5eb2109db14228;
|
|
264
282
|
|
|
265
283
|
|
|
266
|
-
$parcel$exportWildcard(module.exports, $d715e0554b679f1f$exports);
|
|
267
284
|
|
|
268
285
|
|
|
269
286
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;A;;;;;;;;ACUA;;oGAEA,CAEA,MAAMO,4CAAsB,GAAG,kBAA/B,AAAA;AACA,MAAMC,oCAAc,GAAG,yBAAvB,AAAA;AACA,MAAMC,0CAAoB,GAAG,qCAA7B,AAAA;AACA,MAAMC,mCAAa,GAAG,+BAAtB,AAAA;AAEA,MAAMC,6CAAuB,GAAA,aAAGX,CAAAA,0BAAA,CAAoB;IAClDa,MAAM,EAAE,IAAIC,GAAJ,EAD0C;IAElDC,sCAAsC,EAAE,IAAID,GAAJ,EAFU;IAGlDE,QAAQ,EAAE,IAAIF,GAAJ,EAAVE;CAH8B,CAAhC,AAAoD;AA0CpD,MAAMC,yCAAgB,GAAA,aAAGjB,CAAAA,uBAAA,CACvB,CAACmB,KAAD,EAAQC,YAAR,GAAyB;IACvB,MAAM,+BACJC,2BAA2B,GAAG,KAD1B,G,iBAEJC,eAFI,CAAA,E,sBAGJC,oBAHI,CAAA,E,gBAIJC,cAJI,CAAA,E,mBAKJC,iBALI,CAAA,E,WAMJC,SANI,CAAA,EAOJ,GAAGC,UAAH,EAPI,GAQFR,KARJ,AAAM;IASN,MAAMS,OAAO,GAAG5B,uBAAA,CAAiBW,6CAAjB,CAAhB,AAAA;IACA,MAAM,CAACmB,KAAD,EAAOC,OAAP,CAAA,GAAkB/B,qBAAA,CAA+C,IAA/C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EAIE;IACA,MAAM/C,MAAM,GAAG+C,MAAM,CAACb,aAAP,CAAqBlC,MAApC,AAAA;IACA,MAAMD,KAAK,GAAG,IAAIiD,WAAJ,CAAgBH,IAAhB,EAAsB;QAAEI,OAAO,EAAE,KAAX;QAAkBC,UAAU,EAAE,IAA9B;Q,QAAoCH,MAAAA;KAA1D,CAAd,AAAoC;IACpC,IAAID,OAAJ,EAAa9C,MAAM,CAACiB,gBAAP,CAAwB4B,IAAxB,EAA8BC,OAA9B,EAAwD;QAAEK,IAAI,EAAE,IAANA;KAA1D,CAAwD,CAAA;IACrE,OAAO,CAACnD,MAAM,CAAC4C,aAAP,CAAqB7C,KAArB,CAAR,CAAA;CACD;AAED,MAAMqD,yCAAI,GAAGnF,yCAAb,AAAA;AACA,MAAMoF,yCAAM,GAAG3B,yCAAf,AAAA;;AD/RA","sources":["packages/react/dismissable-layer/src/index.ts","packages/react/dismissable-layer/src/DismissableLayer.tsx"],"sourcesContent":["export * from './DismissableLayer';\n","import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { useBodyPointerEvents } from '@radix-ui/react-use-body-pointer-events';\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\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 [, 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 });\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 });\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 });\n\n useBodyPointerEvents({ disabled: disableOutsidePointerEvents });\n\n React.useEffect(() => {\n if (!node) return;\n if (disableOutsidePointerEvents) context.layersWithOutsidePointerEventsDisabled.add(node);\n context.layers.add(node);\n dispatchUpdate();\n }, [node, 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(onPointerDownOutside?: (event: PointerDownOutsideEvent) => void) {\n const handlePointerDownOutside = useCallbackRef(onPointerDownOutside) as EventListener;\n const isPointerInsideReactTreeRef = React.useRef(false);\n\n React.useEffect(() => {\n const handlePointerDown = (event: PointerEvent) => {\n if (event.target && !isPointerInsideReactTreeRef.current) {\n const eventDetail = { originalEvent: event };\n dispatchCustomEvent(POINTER_DOWN_OUTSIDE, handlePointerDownOutside, eventDetail);\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 document.addEventListener('pointerdown', handlePointerDown);\n }, 0);\n return () => {\n window.clearTimeout(timerId);\n document.removeEventListener('pointerdown', handlePointerDown);\n };\n }, [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(onFocusOutside?: (event: FocusOutsideEvent) => void) {\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 dispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, eventDetail);\n }\n };\n document.addEventListener('focusin', handleFocus);\n return () => document.removeEventListener('focusin', handleFocus);\n }, [handleFocusOutside]);\n\n return {\n onFocusCapture: () => (isFocusInsideReactTreeRef.current = true),\n onBlurCapture: () => (isFocusInsideReactTreeRef.current = false),\n };\n}\n\nfunction dispatchUpdate() {\n const event = new Event(CONTEXT_UPDATE);\n document.dispatchEvent(event);\n}\n\nfunction dispatchCustomEvent<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) {\n const target = detail.originalEvent.target as HTMLElement;\n const event = new CustomEvent(name, { bubbles: false, cancelable: true, detail });\n if (handler) target.addEventListener(name, handler as EventListener, { once: true });\n return !target.dispatchEvent(event);\n}\n\nconst Root = DismissableLayer;\nconst Branch = DismissableLayerBranch;\n\nexport {\n DismissableLayer,\n DismissableLayerBranch,\n //\n Root,\n Branch,\n};\nexport type { DismissableLayerProps };\n"],"names":["React","composeEventHandlers","Primitive","useComposedRefs","useBodyPointerEvents","useCallbackRef","useEscapeKeydown","DISMISSABLE_LAYER_NAME","CONTEXT_UPDATE","POINTER_DOWN_OUTSIDE","FOCUS_OUTSIDE","DismissableLayerContext","createContext","layers","Set","layersWithOutsidePointerEventsDisabled","branches","DismissableLayer","forwardRef","props","forwardedRef","disableOutsidePointerEvents","onEscapeKeyDown","onPointerDownOutside","onFocusOutside","onInteractOutside","onDismiss","layerProps","context","useContext","node","setNode","useState","force","composedRefs","Array","from","highestLayerWithOutsidePointerEventsDisabled","slice","highestLayerWithOutsidePointerEventsDisabledIndex","indexOf","index","isBodyPointerEventsDisabled","size","isPointerEventsEnabled","pointerDownOutside","usePointerDownOutside","event","target","isPointerDownOnBranch","some","branch","contains","defaultPrevented","focusOutside","useFocusOutside","isFocusInBranch","isHighestLayer","disabled","useEffect","add","dispatchUpdate","delete","handleUpdate","document","addEventListener","removeEventListener","pointerEvents","undefined","style","onFocusCapture","onBlurCapture","onPointerDownCapture","BRANCH_NAME","DismissableLayerBranch","ref","useRef","current","handlePointerDownOutside","isPointerInsideReactTreeRef","handlePointerDown","eventDetail","originalEvent","dispatchCustomEvent","timerId","window","setTimeout","clearTimeout","handleFocusOutside","isFocusInsideReactTreeRef","handleFocus","Event","dispatchEvent","name","handler","detail","CustomEvent","bubbles","cancelable","once","Root","Branch"],"version":3,"file":"index.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;A;;;;;;;AC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AAb,AAAA;AACA,MAAMG,yCAAM,GAAGF,yCAAf,AAAA;;ADrVA","sources":["packages/react/dismissable-layer/src/index.ts","packages/react/dismissable-layer/src/DismissableLayer.tsx"],"sourcesContent":["export {\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 [, 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 });\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 });\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 });\n\n React.useEffect(() => {\n if (!node) return;\n if (disableOutsidePointerEvents) {\n if (context.layersWithOutsidePointerEventsDisabled.size === 0) {\n originalBodyPointerEvents = document.body.style.pointerEvents;\n document.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 document.body.style.pointerEvents = originalBodyPointerEvents;\n }\n };\n }, [node, 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(onPointerDownOutside?: (event: PointerDownOutsideEvent) => void) {\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 document.removeEventListener('click', handleClickRef.current);\n handleClickRef.current = handleAndDispatchPointerDownOutsideEvent;\n document.addEventListener('click', handleClickRef.current, { once: true });\n } else {\n handleAndDispatchPointerDownOutsideEvent();\n }\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 document.addEventListener('pointerdown', handlePointerDown);\n }, 0);\n return () => {\n window.clearTimeout(timerId);\n document.removeEventListener('pointerdown', handlePointerDown);\n document.removeEventListener('click', handleClickRef.current);\n };\n }, [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(onFocusOutside?: (event: FocusOutsideEvent) => void) {\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 document.addEventListener('focusin', handleFocus);\n return () => document.removeEventListener('focusin', handleFocus);\n }, [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"],"names":["DismissableLayer","DismissableLayerBranch","Root","Branch","React","composeEventHandlers","Primitive","dispatchDiscreteCustomEvent","useComposedRefs","useCallbackRef","useEscapeKeydown","DISMISSABLE_LAYER_NAME","CONTEXT_UPDATE","POINTER_DOWN_OUTSIDE","FOCUS_OUTSIDE","originalBodyPointerEvents","DismissableLayerContext","createContext","layers","Set","layersWithOutsidePointerEventsDisabled","branches","forwardRef","props","forwardedRef","disableOutsidePointerEvents","onEscapeKeyDown","onPointerDownOutside","onFocusOutside","onInteractOutside","onDismiss","layerProps","context","useContext","node","setNode","useState","force","composedRefs","Array","from","highestLayerWithOutsidePointerEventsDisabled","slice","highestLayerWithOutsidePointerEventsDisabledIndex","indexOf","index","isBodyPointerEventsDisabled","size","isPointerEventsEnabled","pointerDownOutside","usePointerDownOutside","event","target","isPointerDownOnBranch","some","branch","contains","defaultPrevented","focusOutside","useFocusOutside","isFocusInBranch","isHighestLayer","preventDefault","useEffect","document","body","style","pointerEvents","add","dispatchUpdate","delete","handleUpdate","addEventListener","removeEventListener","undefined","onFocusCapture","onBlurCapture","onPointerDownCapture","BRANCH_NAME","ref","useRef","current","handlePointerDownOutside","isPointerInsideReactTreeRef","handleClickRef","handlePointerDown","eventDetail","originalEvent","handleAndDispatchPointerDownOutsideEvent","handleAndDispatchCustomEvent","discrete","pointerType","once","timerId","window","setTimeout","clearTimeout","handleFocusOutside","isFocusInsideReactTreeRef","handleFocus","CustomEvent","dispatchEvent","name","handler","detail","bubbles","cancelable"],"version":3,"file":"index.js.map"}
|
package/dist/index.module.js
CHANGED
|
@@ -1,22 +1,11 @@
|
|
|
1
1
|
import $kqwpH$babelruntimehelpersesmextends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import {createContext as $kqwpH$createContext, forwardRef as $kqwpH$forwardRef, useContext as $kqwpH$useContext, useState as $kqwpH$useState, useEffect as $kqwpH$useEffect, createElement as $kqwpH$createElement, useRef as $kqwpH$useRef} from "react";
|
|
3
3
|
import {composeEventHandlers as $kqwpH$composeEventHandlers} from "@radix-ui/primitive";
|
|
4
|
-
import {Primitive as $kqwpH$Primitive} from "@radix-ui/react-primitive";
|
|
4
|
+
import {Primitive as $kqwpH$Primitive, dispatchDiscreteCustomEvent as $kqwpH$dispatchDiscreteCustomEvent} from "@radix-ui/react-primitive";
|
|
5
5
|
import {useComposedRefs as $kqwpH$useComposedRefs} from "@radix-ui/react-compose-refs";
|
|
6
|
-
import {useBodyPointerEvents as $kqwpH$useBodyPointerEvents} from "@radix-ui/react-use-body-pointer-events";
|
|
7
6
|
import {useCallbackRef as $kqwpH$useCallbackRef} from "@radix-ui/react-use-callback-ref";
|
|
8
7
|
import {useEscapeKeydown as $kqwpH$useEscapeKeydown} from "@radix-ui/react-use-escape-keydown";
|
|
9
8
|
|
|
10
|
-
function $parcel$export(e, n, v, s) {
|
|
11
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
12
|
-
}
|
|
13
|
-
var $5cb92bef7577960e$exports = {};
|
|
14
|
-
|
|
15
|
-
$parcel$export($5cb92bef7577960e$exports, "DismissableLayer", () => $5cb92bef7577960e$export$177fb62ff3ec1f22);
|
|
16
|
-
$parcel$export($5cb92bef7577960e$exports, "DismissableLayerBranch", () => $5cb92bef7577960e$export$4d5eb2109db14228);
|
|
17
|
-
$parcel$export($5cb92bef7577960e$exports, "Root", () => $5cb92bef7577960e$export$be92b6f5f03c0fe9);
|
|
18
|
-
$parcel$export($5cb92bef7577960e$exports, "Branch", () => $5cb92bef7577960e$export$aecb2ddcb55c95be);
|
|
19
|
-
|
|
20
9
|
|
|
21
10
|
|
|
22
11
|
|
|
@@ -30,6 +19,7 @@ $parcel$export($5cb92bef7577960e$exports, "Branch", () => $5cb92bef7577960e$expo
|
|
|
30
19
|
const $5cb92bef7577960e$var$CONTEXT_UPDATE = 'dismissableLayer.update';
|
|
31
20
|
const $5cb92bef7577960e$var$POINTER_DOWN_OUTSIDE = 'dismissableLayer.pointerDownOutside';
|
|
32
21
|
const $5cb92bef7577960e$var$FOCUS_OUTSIDE = 'dismissableLayer.focusOutside';
|
|
22
|
+
let $5cb92bef7577960e$var$originalBodyPointerEvents;
|
|
33
23
|
const $5cb92bef7577960e$var$DismissableLayerContext = /*#__PURE__*/ $kqwpH$createContext({
|
|
34
24
|
layers: new Set(),
|
|
35
25
|
layersWithOutsidePointerEventsDisabled: new Set(),
|
|
@@ -76,16 +66,25 @@ const $5cb92bef7577960e$export$177fb62ff3ec1f22 = /*#__PURE__*/ $kqwpH$forwardRe
|
|
|
76
66
|
const isHighestLayer = index === context.layers.size - 1;
|
|
77
67
|
if (!isHighestLayer) return;
|
|
78
68
|
onEscapeKeyDown === null || onEscapeKeyDown === void 0 || onEscapeKeyDown(event);
|
|
79
|
-
if (!event.defaultPrevented
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
69
|
+
if (!event.defaultPrevented && onDismiss) {
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
onDismiss();
|
|
72
|
+
}
|
|
83
73
|
});
|
|
84
74
|
$kqwpH$useEffect(()=>{
|
|
85
75
|
if (!node1) return;
|
|
86
|
-
if (disableOutsidePointerEvents)
|
|
76
|
+
if (disableOutsidePointerEvents) {
|
|
77
|
+
if (context.layersWithOutsidePointerEventsDisabled.size === 0) {
|
|
78
|
+
$5cb92bef7577960e$var$originalBodyPointerEvents = document.body.style.pointerEvents;
|
|
79
|
+
document.body.style.pointerEvents = 'none';
|
|
80
|
+
}
|
|
81
|
+
context.layersWithOutsidePointerEventsDisabled.add(node1);
|
|
82
|
+
}
|
|
87
83
|
context.layers.add(node1);
|
|
88
84
|
$5cb92bef7577960e$var$dispatchUpdate();
|
|
85
|
+
return ()=>{
|
|
86
|
+
if (disableOutsidePointerEvents && context.layersWithOutsidePointerEventsDisabled.size === 1) document.body.style.pointerEvents = $5cb92bef7577960e$var$originalBodyPointerEvents;
|
|
87
|
+
};
|
|
89
88
|
}, [
|
|
90
89
|
node1,
|
|
91
90
|
disableOutsidePointerEvents,
|
|
@@ -160,13 +159,36 @@ const $5cb92bef7577960e$export$4d5eb2109db14228 = /*#__PURE__*/ $kqwpH$forwardRe
|
|
|
160
159
|
*/ function $5cb92bef7577960e$var$usePointerDownOutside(onPointerDownOutside) {
|
|
161
160
|
const handlePointerDownOutside = $kqwpH$useCallbackRef(onPointerDownOutside);
|
|
162
161
|
const isPointerInsideReactTreeRef = $kqwpH$useRef(false);
|
|
162
|
+
const handleClickRef = $kqwpH$useRef(()=>{});
|
|
163
163
|
$kqwpH$useEffect(()=>{
|
|
164
164
|
const handlePointerDown = (event)=>{
|
|
165
165
|
if (event.target && !isPointerInsideReactTreeRef.current) {
|
|
166
166
|
const eventDetail = {
|
|
167
167
|
originalEvent: event
|
|
168
168
|
};
|
|
169
|
-
|
|
169
|
+
function handleAndDispatchPointerDownOutsideEvent() {
|
|
170
|
+
$5cb92bef7577960e$var$handleAndDispatchCustomEvent($5cb92bef7577960e$var$POINTER_DOWN_OUTSIDE, handlePointerDownOutside, eventDetail, {
|
|
171
|
+
discrete: true
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* On touch devices, we need to wait for a click event because browsers implement
|
|
176
|
+
* a ~350ms delay between the time the user stops touching the display and when the
|
|
177
|
+
* browser executres events. We need to ensure we don't reactivate pointer-events within
|
|
178
|
+
* this timeframe otherwise the browser may execute events that should have been prevented.
|
|
179
|
+
*
|
|
180
|
+
* Additionally, this also lets us deal automatically with cancellations when a click event
|
|
181
|
+
* isn't raised because the page was considered scrolled/drag-scrolled, long-pressed, etc.
|
|
182
|
+
*
|
|
183
|
+
* This is why we also continuously remove the previous listener, because we cannot be
|
|
184
|
+
* certain that it was raised, and therefore cleaned-up.
|
|
185
|
+
*/ if (event.pointerType === 'touch') {
|
|
186
|
+
document.removeEventListener('click', handleClickRef.current);
|
|
187
|
+
handleClickRef.current = handleAndDispatchPointerDownOutsideEvent;
|
|
188
|
+
document.addEventListener('click', handleClickRef.current, {
|
|
189
|
+
once: true
|
|
190
|
+
});
|
|
191
|
+
} else handleAndDispatchPointerDownOutsideEvent();
|
|
170
192
|
}
|
|
171
193
|
isPointerInsideReactTreeRef.current = false;
|
|
172
194
|
};
|
|
@@ -188,6 +210,7 @@ const $5cb92bef7577960e$export$4d5eb2109db14228 = /*#__PURE__*/ $kqwpH$forwardRe
|
|
|
188
210
|
return ()=>{
|
|
189
211
|
window.clearTimeout(timerId);
|
|
190
212
|
document.removeEventListener('pointerdown', handlePointerDown);
|
|
213
|
+
document.removeEventListener('click', handleClickRef.current);
|
|
191
214
|
};
|
|
192
215
|
}, [
|
|
193
216
|
handlePointerDownOutside
|
|
@@ -209,7 +232,9 @@ const $5cb92bef7577960e$export$4d5eb2109db14228 = /*#__PURE__*/ $kqwpH$forwardRe
|
|
|
209
232
|
const eventDetail = {
|
|
210
233
|
originalEvent: event
|
|
211
234
|
};
|
|
212
|
-
$5cb92bef7577960e$var$
|
|
235
|
+
$5cb92bef7577960e$var$handleAndDispatchCustomEvent($5cb92bef7577960e$var$FOCUS_OUTSIDE, handleFocusOutside, eventDetail, {
|
|
236
|
+
discrete: false
|
|
237
|
+
});
|
|
213
238
|
}
|
|
214
239
|
};
|
|
215
240
|
document.addEventListener('focusin', handleFocus);
|
|
@@ -225,10 +250,10 @@ const $5cb92bef7577960e$export$4d5eb2109db14228 = /*#__PURE__*/ $kqwpH$forwardRe
|
|
|
225
250
|
};
|
|
226
251
|
}
|
|
227
252
|
function $5cb92bef7577960e$var$dispatchUpdate() {
|
|
228
|
-
const event = new
|
|
253
|
+
const event = new CustomEvent($5cb92bef7577960e$var$CONTEXT_UPDATE);
|
|
229
254
|
document.dispatchEvent(event);
|
|
230
255
|
}
|
|
231
|
-
function $5cb92bef7577960e$var$
|
|
256
|
+
function $5cb92bef7577960e$var$handleAndDispatchCustomEvent(name, handler, detail, { discrete: discrete }) {
|
|
232
257
|
const target = detail.originalEvent.target;
|
|
233
258
|
const event = new CustomEvent(name, {
|
|
234
259
|
bubbles: false,
|
|
@@ -238,7 +263,8 @@ function $5cb92bef7577960e$var$dispatchCustomEvent(name, handler, detail) {
|
|
|
238
263
|
if (handler) target.addEventListener(name, handler, {
|
|
239
264
|
once: true
|
|
240
265
|
});
|
|
241
|
-
|
|
266
|
+
if (discrete) $kqwpH$dispatchDiscreteCustomEvent(target, event);
|
|
267
|
+
else target.dispatchEvent(event);
|
|
242
268
|
}
|
|
243
269
|
const $5cb92bef7577960e$export$be92b6f5f03c0fe9 = $5cb92bef7577960e$export$177fb62ff3ec1f22;
|
|
244
270
|
const $5cb92bef7577960e$export$aecb2ddcb55c95be = $5cb92bef7577960e$export$4d5eb2109db14228;
|
package/dist/index.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;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C,KAArB,CAAR,CAAA;CACD;AAED,MAAMqD,yCAAI,GAAGnF,yCAAb,AAAA;AACA,MAAMoF,yCAAM,GAAG3B,yCAAf,AAAA;;AD/RA","sources":["packages/react/dismissable-layer/src/index.ts","packages/react/dismissable-layer/src/DismissableLayer.tsx"],"sourcesContent":["export * from './DismissableLayer';\n","import * as React from 'react';\nimport { composeEventHandlers } from '@radix-ui/primitive';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { useComposedRefs } from '@radix-ui/react-compose-refs';\nimport { useBodyPointerEvents } from '@radix-ui/react-use-body-pointer-events';\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\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 [, 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 });\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 });\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 });\n\n useBodyPointerEvents({ disabled: disableOutsidePointerEvents });\n\n React.useEffect(() => {\n if (!node) return;\n if (disableOutsidePointerEvents) context.layersWithOutsidePointerEventsDisabled.add(node);\n context.layers.add(node);\n dispatchUpdate();\n }, [node, 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(onPointerDownOutside?: (event: PointerDownOutsideEvent) => void) {\n const handlePointerDownOutside = useCallbackRef(onPointerDownOutside) as EventListener;\n const isPointerInsideReactTreeRef = React.useRef(false);\n\n React.useEffect(() => {\n const handlePointerDown = (event: PointerEvent) => {\n if (event.target && !isPointerInsideReactTreeRef.current) {\n const eventDetail = { originalEvent: event };\n dispatchCustomEvent(POINTER_DOWN_OUTSIDE, handlePointerDownOutside, eventDetail);\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 document.addEventListener('pointerdown', handlePointerDown);\n }, 0);\n return () => {\n window.clearTimeout(timerId);\n document.removeEventListener('pointerdown', handlePointerDown);\n };\n }, [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(onFocusOutside?: (event: FocusOutsideEvent) => void) {\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 dispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, eventDetail);\n }\n };\n document.addEventListener('focusin', handleFocus);\n return () => document.removeEventListener('focusin', handleFocus);\n }, [handleFocusOutside]);\n\n return {\n onFocusCapture: () => (isFocusInsideReactTreeRef.current = true),\n onBlurCapture: () => (isFocusInsideReactTreeRef.current = false),\n };\n}\n\nfunction dispatchUpdate() {\n const event = new Event(CONTEXT_UPDATE);\n document.dispatchEvent(event);\n}\n\nfunction dispatchCustomEvent<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) {\n const target = detail.originalEvent.target as HTMLElement;\n const event = new CustomEvent(name, { bubbles: false, cancelable: true, detail });\n if (handler) target.addEventListener(name, handler as EventListener, { once: true });\n return !target.dispatchEvent(event);\n}\n\nconst Root = DismissableLayer;\nconst Branch = DismissableLayerBranch;\n\nexport {\n DismissableLayer,\n DismissableLayerBranch,\n //\n Root,\n Branch,\n};\nexport type { DismissableLayerProps };\n"],"names":["React","composeEventHandlers","Primitive","useComposedRefs","useBodyPointerEvents","useCallbackRef","useEscapeKeydown","DISMISSABLE_LAYER_NAME","CONTEXT_UPDATE","POINTER_DOWN_OUTSIDE","FOCUS_OUTSIDE","DismissableLayerContext","createContext","layers","Set","layersWithOutsidePointerEventsDisabled","branches","DismissableLayer","forwardRef","props","forwardedRef","disableOutsidePointerEvents","onEscapeKeyDown","onPointerDownOutside","onFocusOutside","onInteractOutside","onDismiss","layerProps","context","useContext","node","setNode","useState","force","composedRefs","Array","from","highestLayerWithOutsidePointerEventsDisabled","slice","highestLayerWithOutsidePointerEventsDisabledIndex","indexOf","index","isBodyPointerEventsDisabled","size","isPointerEventsEnabled","pointerDownOutside","usePointerDownOutside","event","target","isPointerDownOnBranch","some","branch","contains","defaultPrevented","focusOutside","useFocusOutside","isFocusInBranch","isHighestLayer","disabled","useEffect","add","dispatchUpdate","delete","handleUpdate","document","addEventListener","removeEventListener","pointerEvents","undefined","style","onFocusCapture","onBlurCapture","onPointerDownCapture","BRANCH_NAME","DismissableLayerBranch","ref","useRef","current","handlePointerDownOutside","isPointerInsideReactTreeRef","handlePointerDown","eventDetail","originalEvent","dispatchCustomEvent","timerId","window","setTimeout","clearTimeout","handleFocusOutside","isFocusInsideReactTreeRef","handleFocus","Event","dispatchEvent","name","handler","detail","CustomEvent","bubbles","cancelable","once","Root","Branch"],"version":3,"file":"index.module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;A;;;;;;;ACSA;;oGAEA,CAEA,MAAMW,4CAAsB,GAAG,kBAA/B,AAAA;AACA,MAAMC,oCAAc,GAAG,yBAAvB,AAAA;AACA,MAAMC,0CAAoB,GAAG,qCAA7B,AAAA;AACA,MAAMC,mCAAa,GAAG,+BAAtB,AAAA;AAEA,IAAIC,+CAAJ,AAAA;AAEA,MAAMC,6CAAuB,GAAA,aAAGZ,CAAAA,oBAAA,CAAoB;IAClDc,MAAM,EAAE,IAAIC,GAAJ,EAD0C;IAElDC,sCAAsC,EAAE,IAAID,GAAJ,EAFU;IAGlDE,QAAQ,EAAE,IAAIF,GAAJ,EAAVE;CAH8B,CAAhC,AAAoD;AA0CpD,MAAM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FF,CAAO;CAIR;AAED,SAASP,oCAAT,GAA0B;IACxB,MAAMlB,KAAK,GAAG,IAAIiD,WAAJ,CAAgBxF,oCAAhB,CAAd,AAAA;IACAoD,QAAQ,CAACqC,aAAT,CAAuBlD,KAAvB,CAAAa,CAAAA;CACD;AAED,SAASyB,kDAAT,CACEa,IADF,EAEEC,OAFF,EAGEC,MAHF,EAIE,E,UAAEd,QAAAA,CAAAA,EAJJ,EAKE;IACA,MAAMtC,MAAM,GAAGoD,MAAM,CAACjB,aAAP,CAAqBnC,MAApC,AAAA;IACA,MAAMD,KAAK,GAAG,IAAIiD,WAAJ,CAAgBE,IAAhB,EAAsB;QAAEG,OAAO,EAAE,KAAX;QAAkBC,UAAU,EAAE,IAA9B;Q,QAAoCF,MAAAA;KAA1D,CAAd,AAAoC;IACpC,IAAID,OAAJ,EAAanD,MAAM,CAACoB,gBAAP,CAAwB8B,IAAxB,EAA8BC,OAA9B,EAAwD;QAAEX,IAAI,EAAE,IAANA;KAA1D,CAAwD,CAAA;IAErE,IAAIF,QAAJ,EACEnF,kCAA2B,CAAC6C,MAAD,EAASD,KAAT,CAA3B,CAAA5C;SAEA6C,MAAM,CAACiD,aAAP,CAAqBlD,KAArB,CAAAC,CAAAA;CAEH;AAED,MAAMlD,yCAAI,GAAGF,yCAAb,AAAA;AACA,MAAMG,yCAAM,GAAGF,yCAAf,AAAA;;ADrVA","sources":["packages/react/dismissable-layer/src/index.ts","packages/react/dismissable-layer/src/DismissableLayer.tsx"],"sourcesContent":["export {\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 [, 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 });\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 });\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 });\n\n React.useEffect(() => {\n if (!node) return;\n if (disableOutsidePointerEvents) {\n if (context.layersWithOutsidePointerEventsDisabled.size === 0) {\n originalBodyPointerEvents = document.body.style.pointerEvents;\n document.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 document.body.style.pointerEvents = originalBodyPointerEvents;\n }\n };\n }, [node, 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(onPointerDownOutside?: (event: PointerDownOutsideEvent) => void) {\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 document.removeEventListener('click', handleClickRef.current);\n handleClickRef.current = handleAndDispatchPointerDownOutsideEvent;\n document.addEventListener('click', handleClickRef.current, { once: true });\n } else {\n handleAndDispatchPointerDownOutsideEvent();\n }\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 document.addEventListener('pointerdown', handlePointerDown);\n }, 0);\n return () => {\n window.clearTimeout(timerId);\n document.removeEventListener('pointerdown', handlePointerDown);\n document.removeEventListener('click', handleClickRef.current);\n };\n }, [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(onFocusOutside?: (event: FocusOutsideEvent) => void) {\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 document.addEventListener('focusin', handleFocus);\n return () => document.removeEventListener('focusin', handleFocus);\n }, [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"],"names":["DismissableLayer","DismissableLayerBranch","Root","Branch","React","composeEventHandlers","Primitive","dispatchDiscreteCustomEvent","useComposedRefs","useCallbackRef","useEscapeKeydown","DISMISSABLE_LAYER_NAME","CONTEXT_UPDATE","POINTER_DOWN_OUTSIDE","FOCUS_OUTSIDE","originalBodyPointerEvents","DismissableLayerContext","createContext","layers","Set","layersWithOutsidePointerEventsDisabled","branches","forwardRef","props","forwardedRef","disableOutsidePointerEvents","onEscapeKeyDown","onPointerDownOutside","onFocusOutside","onInteractOutside","onDismiss","layerProps","context","useContext","node","setNode","useState","force","composedRefs","Array","from","highestLayerWithOutsidePointerEventsDisabled","slice","highestLayerWithOutsidePointerEventsDisabledIndex","indexOf","index","isBodyPointerEventsDisabled","size","isPointerEventsEnabled","pointerDownOutside","usePointerDownOutside","event","target","isPointerDownOnBranch","some","branch","contains","defaultPrevented","focusOutside","useFocusOutside","isFocusInBranch","isHighestLayer","preventDefault","useEffect","document","body","style","pointerEvents","add","dispatchUpdate","delete","handleUpdate","addEventListener","removeEventListener","undefined","onFocusCapture","onBlurCapture","onPointerDownCapture","BRANCH_NAME","ref","useRef","current","handlePointerDownOutside","isPointerInsideReactTreeRef","handleClickRef","handlePointerDown","eventDetail","originalEvent","handleAndDispatchPointerDownOutsideEvent","handleAndDispatchCustomEvent","discrete","pointerType","once","timerId","window","setTimeout","clearTimeout","handleFocusOutside","isFocusInsideReactTreeRef","handleFocus","CustomEvent","dispatchEvent","name","handler","detail","bubbles","cancelable"],"version":3,"file":"index.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@radix-ui/react-dismissable-layer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-rc.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,18 +17,18 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@babel/runtime": "^7.13.10",
|
|
20
|
-
"@radix-ui/primitive": "0.1
|
|
21
|
-
"@radix-ui/react-compose-refs": "0.
|
|
22
|
-
"@radix-ui/react-primitive": "0.
|
|
23
|
-
"@radix-ui/react-use-
|
|
24
|
-
"@radix-ui/react-use-
|
|
25
|
-
"@radix-ui/react-use-escape-keydown": "0.1.1-rc.7"
|
|
20
|
+
"@radix-ui/primitive": "1.0.0-rc.1",
|
|
21
|
+
"@radix-ui/react-compose-refs": "1.0.0-rc.1",
|
|
22
|
+
"@radix-ui/react-primitive": "1.0.0-rc.1",
|
|
23
|
+
"@radix-ui/react-use-callback-ref": "1.0.0-rc.1",
|
|
24
|
+
"@radix-ui/react-use-escape-keydown": "1.0.0-rc.1"
|
|
26
25
|
},
|
|
27
26
|
"devDependencies": {
|
|
28
|
-
"react-remove-scroll": "
|
|
27
|
+
"react-remove-scroll": "2.5.4"
|
|
29
28
|
},
|
|
30
29
|
"peerDependencies": {
|
|
31
|
-
"react": "^16.8 || ^17.0 || ^18.0"
|
|
30
|
+
"react": "^16.8 || ^17.0 || ^18.0",
|
|
31
|
+
"react-dom": "^16.8 || ^17.0 || ^18.0"
|
|
32
32
|
},
|
|
33
33
|
"homepage": "https://radix-ui.com/primitives",
|
|
34
34
|
"repository": {
|