@radix-ui/react-dismissable-layer 0.1.6-rc.2 → 0.1.6-rc.5

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.
@@ -1 +1 @@
1
- {"mappings":"A;A;A;AA0BA,yBAAyB,MAAM,wBAAwB,CAAC,OAAO,UAAU,GAAG,CAAC,CAAC;AAC9E,sCAAgC,SAAQ,iBAAiB;IACvD;A;A;A;OAIG;IACH,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC;A;A;OAGG;IACH,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IACjD;A;A;OAGG;IACH,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,IAAI,CAAC;IAChE;A;A;OAGG;IACH,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;IACpD;A;A;A;OAIG;IACH,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,uBAAuB,GAAG,iBAAiB,KAAK,IAAI,CAAC;IACjF;A;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB;AAED,OAAA,MAAM,8GAkGL,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;AAwFpE,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"],"sourcesContent":[null,null],"names":[],"version":3,"file":"index.d.ts.map"}
1
+ {"mappings":";;;AA0BA,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,8GAkGL,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;AAwFpE,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 * from './DismissableLayer';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
package/dist/index.js CHANGED
@@ -1,2 +1,269 @@
1
- var e,t,n,r=require("@radix-ui/react-use-escape-keydown").useEscapeKeydown,s=require("@radix-ui/react-use-callback-ref").useCallbackRef,i=require("@radix-ui/react-use-body-pointer-events").useBodyPointerEvents,u=require("@radix-ui/react-compose-refs").useComposedRefs,o=require("@radix-ui/react-primitive").Primitive,a=require("@radix-ui/primitive").composeEventHandlers,d=(e={},t=require("react"),Object.keys(t).forEach((function(n){"default"!==n&&"__esModule"!==n&&Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[n]}})})),e),c=(n=require("@babel/runtime/helpers/extends"))&&n.__esModule?n.default:n;const l=/*#__PURE__*/d.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),f=/*#__PURE__*/d.forwardRef(((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:f,onPointerDownOutside:v,onFocusOutside:E,onInteractOutside:b,onDismiss:y,...w}=e,C=d.useContext(l),[h,P]=d.useState(null),[,x]=d.useState({}),D=u(t,(e=>P(e))),O=Array.from(C.layers),[L]=[...C.layersWithOutsidePointerEventsDisabled].slice(-1),g=O.indexOf(L),q=h?O.indexOf(h):-1,R=C.layersWithOutsidePointerEventsDisabled.size>0,B=q>=g,F=function(e){const t=s(e),n=d.useRef(!1);return d.useEffect((()=>{const e=e=>{if(e.target&&!n.current){m("dismissableLayer.pointerDownOutside",t,{originalEvent:e})}n.current=!1},r=window.setTimeout((()=>{document.addEventListener("pointerdown",e)}),0);return()=>{window.clearTimeout(r),document.removeEventListener("pointerdown",e)}}),[t]),{onPointerDownCapture:()=>n.current=!0}}((e=>{const t=e.target,n=[...C.branches].some((e=>e.contains(t)));B&&!n&&(null==v||v(e),null==b||b(e),e.defaultPrevented||null==y||y())})),S=function(e){const t=s(e),n=d.useRef(!1);return d.useEffect((()=>{const e=e=>{if(e.target&&!n.current){m("dismissableLayer.focusOutside",t,{originalEvent:e})}};return document.addEventListener("focusin",e),()=>document.removeEventListener("focusin",e)}),[t]),{onFocusCapture:()=>n.current=!0,onBlurCapture:()=>n.current=!1}}((e=>{const t=e.target;[...C.branches].some((e=>e.contains(t)))||(null==E||E(e),null==b||b(e),e.defaultPrevented||null==y||y())}));return r((e=>{q===C.layers.size-1&&(null==f||f(e),e.defaultPrevented||null==y||y())})),i({disabled:n}),d.useEffect((()=>{h&&(n&&C.layersWithOutsidePointerEventsDisabled.add(h),C.layers.add(h),p())}),[h,n,C]),d.useEffect((()=>()=>{h&&(C.layers.delete(h),C.layersWithOutsidePointerEventsDisabled.delete(h),p())}),[h,C]),d.useEffect((()=>{const e=()=>x({});return document.addEventListener("dismissableLayer.update",e),()=>document.removeEventListener("dismissableLayer.update",e)}),[]),/*#__PURE__*/d.createElement(o.div,c({},w,{ref:D,style:{pointerEvents:R?B?"auto":"none":void 0,...e.style},onFocusCapture:a(e.onFocusCapture,S.onFocusCapture),onBlurCapture:a(e.onBlurCapture,S.onBlurCapture),onPointerDownCapture:a(e.onPointerDownCapture,F.onPointerDownCapture)}))}));exports.DismissableLayer=f;const v=/*#__PURE__*/d.forwardRef(((e,t)=>{const n=d.useContext(l),r=d.useRef(null),s=u(t,r);return d.useEffect((()=>{const e=r.current;if(e)return n.branches.add(e),()=>{n.branches.delete(e)}}),[n.branches]),/*#__PURE__*/d.createElement(o.div,c({},e,{ref:s}))}));function p(){const e=new Event("dismissableLayer.update");document.dispatchEvent(e)}function m(e,t,n){const r=n.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});return t&&r.addEventListener(e,t,{once:!0}),!r.dispatchEvent(s)}exports.DismissableLayerBranch=v;const E=f;exports.Root=E;const b=v;exports.Branch=b;
1
+ var $g2vWm$babelruntimehelpersextends = require("@babel/runtime/helpers/extends");
2
+ var $g2vWm$react = require("react");
3
+ var $g2vWm$radixuiprimitive = require("@radix-ui/primitive");
4
+ var $g2vWm$radixuireactprimitive = require("@radix-ui/react-primitive");
5
+ var $g2vWm$radixuireactcomposerefs = require("@radix-ui/react-compose-refs");
6
+ var $g2vWm$radixuireactusebodypointerevents = require("@radix-ui/react-use-body-pointer-events");
7
+ var $g2vWm$radixuireactusecallbackref = require("@radix-ui/react-use-callback-ref");
8
+ var $g2vWm$radixuireactuseescapekeydown = require("@radix-ui/react-use-escape-keydown");
9
+
10
+ function $parcel$exportWildcard(dest, source) {
11
+ Object.keys(source).forEach(function(key) {
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;
25
+ }
26
+ function $parcel$interopDefault(a) {
27
+ return a && a.__esModule ? a.default : a;
28
+ }
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
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+ /* -------------------------------------------------------------------------------------------------
47
+ * DismissableLayer
48
+ * -----------------------------------------------------------------------------------------------*/ const $d715e0554b679f1f$var$DISMISSABLE_LAYER_NAME = 'DismissableLayer';
49
+ const $d715e0554b679f1f$var$CONTEXT_UPDATE = 'dismissableLayer.update';
50
+ const $d715e0554b679f1f$var$POINTER_DOWN_OUTSIDE = 'dismissableLayer.pointerDownOutside';
51
+ const $d715e0554b679f1f$var$FOCUS_OUTSIDE = 'dismissableLayer.focusOutside';
52
+ const $d715e0554b679f1f$var$DismissableLayerContext = /*#__PURE__*/ $g2vWm$react.createContext({
53
+ layers: new Set(),
54
+ layersWithOutsidePointerEventsDisabled: new Set(),
55
+ branches: new Set()
56
+ });
57
+ const $d715e0554b679f1f$export$177fb62ff3ec1f22 = /*#__PURE__*/ $g2vWm$react.forwardRef((props, forwardedRef)=>{
58
+ const { disableOutsidePointerEvents: disableOutsidePointerEvents = false , onEscapeKeyDown: onEscapeKeyDown , onPointerDownOutside: onPointerDownOutside , onFocusOutside: onFocusOutside , onInteractOutside: onInteractOutside , onDismiss: onDismiss , ...layerProps } = props;
59
+ const context = $g2vWm$react.useContext($d715e0554b679f1f$var$DismissableLayerContext);
60
+ const [node1, setNode] = $g2vWm$react.useState(null);
61
+ const [, force] = $g2vWm$react.useState({});
62
+ const composedRefs = $g2vWm$radixuireactcomposerefs.useComposedRefs(forwardedRef, (node)=>setNode(node)
63
+ );
64
+ const layers = Array.from(context.layers);
65
+ const [highestLayerWithOutsidePointerEventsDisabled] = [
66
+ ...context.layersWithOutsidePointerEventsDisabled
67
+ ].slice(-1); // prettier-ignore
68
+ const highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled); // prettier-ignore
69
+ const index = node1 ? layers.indexOf(node1) : -1;
70
+ const isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0;
71
+ const isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex;
72
+ const pointerDownOutside = $d715e0554b679f1f$var$usePointerDownOutside((event)=>{
73
+ const target = event.target;
74
+ const isPointerDownOnBranch = [
75
+ ...context.branches
76
+ ].some((branch)=>branch.contains(target)
77
+ );
78
+ if (!isPointerEventsEnabled || isPointerDownOnBranch) return;
79
+ onPointerDownOutside === null || onPointerDownOutside === void 0 || onPointerDownOutside(event);
80
+ onInteractOutside === null || onInteractOutside === void 0 || onInteractOutside(event);
81
+ if (!event.defaultPrevented) onDismiss === null || onDismiss === void 0 || onDismiss();
82
+ });
83
+ const focusOutside = $d715e0554b679f1f$var$useFocusOutside((event)=>{
84
+ const target = event.target;
85
+ const isFocusInBranch = [
86
+ ...context.branches
87
+ ].some((branch)=>branch.contains(target)
88
+ );
89
+ if (isFocusInBranch) return;
90
+ onFocusOutside === null || onFocusOutside === void 0 || onFocusOutside(event);
91
+ onInteractOutside === null || onInteractOutside === void 0 || onInteractOutside(event);
92
+ if (!event.defaultPrevented) onDismiss === null || onDismiss === void 0 || onDismiss();
93
+ });
94
+ $g2vWm$radixuireactuseescapekeydown.useEscapeKeydown((event)=>{
95
+ const isHighestLayer = index === context.layers.size - 1;
96
+ if (!isHighestLayer) return;
97
+ onEscapeKeyDown === null || onEscapeKeyDown === void 0 || onEscapeKeyDown(event);
98
+ if (!event.defaultPrevented) onDismiss === null || onDismiss === void 0 || onDismiss();
99
+ });
100
+ $g2vWm$radixuireactusebodypointerevents.useBodyPointerEvents({
101
+ disabled: disableOutsidePointerEvents
102
+ });
103
+ $g2vWm$react.useEffect(()=>{
104
+ if (!node1) return;
105
+ if (disableOutsidePointerEvents) context.layersWithOutsidePointerEventsDisabled.add(node1);
106
+ context.layers.add(node1);
107
+ $d715e0554b679f1f$var$dispatchUpdate();
108
+ }, [
109
+ node1,
110
+ disableOutsidePointerEvents,
111
+ context
112
+ ]);
113
+ /**
114
+ * We purposefully prevent combining this effect with the `disableOutsidePointerEvents` effect
115
+ * because a change to `disableOutsidePointerEvents` would remove this layer from the stack
116
+ * and add it to the end again so the layering order wouldn't be _creation order_.
117
+ * We only want them to be removed from context stacks when unmounted.
118
+ */ $g2vWm$react.useEffect(()=>{
119
+ return ()=>{
120
+ if (!node1) return;
121
+ context.layers.delete(node1);
122
+ context.layersWithOutsidePointerEventsDisabled.delete(node1);
123
+ $d715e0554b679f1f$var$dispatchUpdate();
124
+ };
125
+ }, [
126
+ node1,
127
+ context
128
+ ]);
129
+ $g2vWm$react.useEffect(()=>{
130
+ const handleUpdate = ()=>force({})
131
+ ;
132
+ document.addEventListener($d715e0554b679f1f$var$CONTEXT_UPDATE, handleUpdate);
133
+ return ()=>document.removeEventListener($d715e0554b679f1f$var$CONTEXT_UPDATE, handleUpdate)
134
+ ;
135
+ }, []);
136
+ return /*#__PURE__*/ $g2vWm$react.createElement($g2vWm$radixuireactprimitive.Primitive.div, ($parcel$interopDefault($g2vWm$babelruntimehelpersextends))({}, layerProps, {
137
+ ref: composedRefs,
138
+ style: {
139
+ pointerEvents: isBodyPointerEventsDisabled ? isPointerEventsEnabled ? 'auto' : 'none' : undefined,
140
+ ...props.style
141
+ },
142
+ onFocusCapture: $g2vWm$radixuiprimitive.composeEventHandlers(props.onFocusCapture, focusOutside.onFocusCapture),
143
+ onBlurCapture: $g2vWm$radixuiprimitive.composeEventHandlers(props.onBlurCapture, focusOutside.onBlurCapture),
144
+ onPointerDownCapture: $g2vWm$radixuiprimitive.composeEventHandlers(props.onPointerDownCapture, pointerDownOutside.onPointerDownCapture)
145
+ }));
146
+ });
147
+ /*#__PURE__*/ Object.assign($d715e0554b679f1f$export$177fb62ff3ec1f22, {
148
+ displayName: $d715e0554b679f1f$var$DISMISSABLE_LAYER_NAME
149
+ });
150
+ /* -------------------------------------------------------------------------------------------------
151
+ * DismissableLayerBranch
152
+ * -----------------------------------------------------------------------------------------------*/ const $d715e0554b679f1f$var$BRANCH_NAME = 'DismissableLayerBranch';
153
+ const $d715e0554b679f1f$export$4d5eb2109db14228 = /*#__PURE__*/ $g2vWm$react.forwardRef((props, forwardedRef)=>{
154
+ const context = $g2vWm$react.useContext($d715e0554b679f1f$var$DismissableLayerContext);
155
+ const ref = $g2vWm$react.useRef(null);
156
+ const composedRefs = $g2vWm$radixuireactcomposerefs.useComposedRefs(forwardedRef, ref);
157
+ $g2vWm$react.useEffect(()=>{
158
+ const node = ref.current;
159
+ if (node) {
160
+ context.branches.add(node);
161
+ return ()=>{
162
+ context.branches.delete(node);
163
+ };
164
+ }
165
+ }, [
166
+ context.branches
167
+ ]);
168
+ return /*#__PURE__*/ $g2vWm$react.createElement($g2vWm$radixuireactprimitive.Primitive.div, ($parcel$interopDefault($g2vWm$babelruntimehelpersextends))({}, props, {
169
+ ref: composedRefs
170
+ }));
171
+ });
172
+ /*#__PURE__*/ Object.assign($d715e0554b679f1f$export$4d5eb2109db14228, {
173
+ displayName: $d715e0554b679f1f$var$BRANCH_NAME
174
+ });
175
+ /* -----------------------------------------------------------------------------------------------*/ /**
176
+ * Listens for `pointerdown` outside a react subtree. We use `pointerdown` rather than `pointerup`
177
+ * to mimic layer dismissing behaviour present in OS.
178
+ * Returns props to pass to the node we want to check for outside events.
179
+ */ function $d715e0554b679f1f$var$usePointerDownOutside(onPointerDownOutside) {
180
+ const handlePointerDownOutside = $g2vWm$radixuireactusecallbackref.useCallbackRef(onPointerDownOutside);
181
+ const isPointerInsideReactTreeRef = $g2vWm$react.useRef(false);
182
+ $g2vWm$react.useEffect(()=>{
183
+ const handlePointerDown = (event)=>{
184
+ if (event.target && !isPointerInsideReactTreeRef.current) {
185
+ const eventDetail = {
186
+ originalEvent: event
187
+ };
188
+ $d715e0554b679f1f$var$dispatchCustomEvent($d715e0554b679f1f$var$POINTER_DOWN_OUTSIDE, handlePointerDownOutside, eventDetail);
189
+ }
190
+ isPointerInsideReactTreeRef.current = false;
191
+ };
192
+ /**
193
+ * if this hook executes in a component that mounts via a `pointerdown` event, the event
194
+ * would bubble up to the document and trigger a `pointerDownOutside` event. We avoid
195
+ * this by delaying the event listener registration on the document.
196
+ * This is not React specific, but rather how the DOM works, ie:
197
+ * ```
198
+ * button.addEventListener('pointerdown', () => {
199
+ * console.log('I will log');
200
+ * document.addEventListener('pointerdown', () => {
201
+ * console.log('I will also log');
202
+ * })
203
+ * });
204
+ */ const timerId = window.setTimeout(()=>{
205
+ document.addEventListener('pointerdown', handlePointerDown);
206
+ }, 0);
207
+ return ()=>{
208
+ window.clearTimeout(timerId);
209
+ document.removeEventListener('pointerdown', handlePointerDown);
210
+ };
211
+ }, [
212
+ handlePointerDownOutside
213
+ ]);
214
+ return {
215
+ // ensures we check React component tree (not just DOM tree)
216
+ onPointerDownCapture: ()=>isPointerInsideReactTreeRef.current = true
217
+ };
218
+ }
219
+ /**
220
+ * Listens for when focus happens outside a react subtree.
221
+ * Returns props to pass to the root (node) of the subtree we want to check.
222
+ */ function $d715e0554b679f1f$var$useFocusOutside(onFocusOutside) {
223
+ const handleFocusOutside = $g2vWm$radixuireactusecallbackref.useCallbackRef(onFocusOutside);
224
+ const isFocusInsideReactTreeRef = $g2vWm$react.useRef(false);
225
+ $g2vWm$react.useEffect(()=>{
226
+ const handleFocus = (event)=>{
227
+ if (event.target && !isFocusInsideReactTreeRef.current) {
228
+ const eventDetail = {
229
+ originalEvent: event
230
+ };
231
+ $d715e0554b679f1f$var$dispatchCustomEvent($d715e0554b679f1f$var$FOCUS_OUTSIDE, handleFocusOutside, eventDetail);
232
+ }
233
+ };
234
+ document.addEventListener('focusin', handleFocus);
235
+ return ()=>document.removeEventListener('focusin', handleFocus)
236
+ ;
237
+ }, [
238
+ handleFocusOutside
239
+ ]);
240
+ return {
241
+ onFocusCapture: ()=>isFocusInsideReactTreeRef.current = true
242
+ ,
243
+ onBlurCapture: ()=>isFocusInsideReactTreeRef.current = false
244
+ };
245
+ }
246
+ function $d715e0554b679f1f$var$dispatchUpdate() {
247
+ const event = new Event($d715e0554b679f1f$var$CONTEXT_UPDATE);
248
+ document.dispatchEvent(event);
249
+ }
250
+ function $d715e0554b679f1f$var$dispatchCustomEvent(name, handler, detail) {
251
+ const target = detail.originalEvent.target;
252
+ const event = new CustomEvent(name, {
253
+ bubbles: false,
254
+ cancelable: true,
255
+ detail: detail
256
+ });
257
+ if (handler) target.addEventListener(name, handler, {
258
+ once: true
259
+ });
260
+ return !target.dispatchEvent(event);
261
+ }
262
+ const $d715e0554b679f1f$export$be92b6f5f03c0fe9 = $d715e0554b679f1f$export$177fb62ff3ec1f22;
263
+ const $d715e0554b679f1f$export$aecb2ddcb55c95be = $d715e0554b679f1f$export$4d5eb2109db14228;
264
+
265
+
266
+ $parcel$exportWildcard(module.exports, $d715e0554b679f1f$exports);
267
+
268
+
2
269
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings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AiBqC,EAAMC,EAA0B,CAAEK,MAAM,KACrEnD,EAAO4C,cAAc7C,oCAG/B,MAAMqD,EAAOzF,iBACb,MAAM0F,EAASX","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/react/dismissable-layer/src/DismissableLayer.tsx"],"sourcesContent":["function $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$reexport(e, n, v) {\n Object.defineProperty(e, n, {get: v, enumerable: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n\nvar $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\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":["dest","source","a","Object","keys","forEach","key","defineProperty","enumerable","get","__esModule","default","DismissableLayerContext","React","createContext","layers","Set","layersWithOutsidePointerEventsDisabled","branches","DismissableLayer","forwardRef","props","forwardedRef","disableOutsidePointerEvents","onEscapeKeyDown","onPointerDownOutside","onFocusOutside","onInteractOutside","onDismiss","layerProps","context","useContext","node","setNode","useState","force","composedRefs","useComposedRefs","Array","from","highestLayerWithOutsidePointerEventsDisabled","slice","highestLayerWithOutsidePointerEventsDisabledIndex","indexOf","index","isBodyPointerEventsDisabled","size","isPointerEventsEnabled","pointerDownOutside","handlePointerDownOutside","useCallbackRef","isPointerInsideReactTreeRef","useRef","useEffect","handlePointerDown","event","target","current","dispatchCustomEvent","originalEvent","timerId","window","setTimeout","document","addEventListener","clearTimeout","removeEventListener","onPointerDownCapture","usePointerDownOutside","isPointerDownOnBranch","some","branch","contains","defaultPrevented","focusOutside","handleFocusOutside","isFocusInsideReactTreeRef","handleFocus","onFocusCapture","onBlurCapture","useFocusOutside","useEscapeKeydown","useBodyPointerEvents","disabled","add","dispatchUpdate","delete","handleUpdate","_react","createElement","Primitive","div","_babelRuntimeHelpersExtends","ref","style","pointerEvents","undefined","composeEventHandlers","DismissableLayerBranch","Event","dispatchEvent","name","handler","detail","CustomEvent","bubbles","cancelable","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,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,2 +1,250 @@
1
- import{useEscapeKeydown as e}from"@radix-ui/react-use-escape-keydown";import{useCallbackRef as t}from"@radix-ui/react-use-callback-ref";import{useBodyPointerEvents as n}from"@radix-ui/react-use-body-pointer-events";import{useComposedRefs as r}from"@radix-ui/react-compose-refs";import{Primitive as s}from"@radix-ui/react-primitive";import{composeEventHandlers as o}from"@radix-ui/primitive";import*as i from"react";import a from"@babel/runtime/helpers/esm/extends";const u=/*#__PURE__*/i.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set});export const DismissableLayer=/*#__PURE__*/i.forwardRef(((l,m)=>{const{disableOutsidePointerEvents:f=!1,onEscapeKeyDown:p,onPointerDownOutside:v,onFocusOutside:b,onInteractOutside:E,onDismiss:y,...w}=l,h=i.useContext(u),[D,x]=i.useState(null),[,C]=i.useState({}),L=r(m,(e=>x(e))),P=Array.from(h.layers),[O]=[...h.layersWithOutsidePointerEventsDisabled].slice(-1),g=P.indexOf(O),B=D?P.indexOf(D):-1,R=h.layersWithOutsidePointerEventsDisabled.size>0,F=B>=g,S=function(e){const n=t(e),r=i.useRef(!1);return i.useEffect((()=>{const e=e=>{if(e.target&&!r.current){d("dismissableLayer.pointerDownOutside",n,{originalEvent:e})}r.current=!1},t=window.setTimeout((()=>{document.addEventListener("pointerdown",e)}),0);return()=>{window.clearTimeout(t),document.removeEventListener("pointerdown",e)}}),[n]),{onPointerDownCapture:()=>r.current=!0}}((e=>{const t=e.target,n=[...h.branches].some((e=>e.contains(t)));F&&!n&&(null==v||v(e),null==E||E(e),e.defaultPrevented||null==y||y())})),W=function(e){const n=t(e),r=i.useRef(!1);return i.useEffect((()=>{const e=e=>{if(e.target&&!r.current){d("dismissableLayer.focusOutside",n,{originalEvent:e})}};return document.addEventListener("focusin",e),()=>document.removeEventListener("focusin",e)}),[n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}((e=>{const t=e.target;[...h.branches].some((e=>e.contains(t)))||(null==b||b(e),null==E||E(e),e.defaultPrevented||null==y||y())}));return e((e=>{B===h.layers.size-1&&(null==p||p(e),e.defaultPrevented||null==y||y())})),n({disabled:f}),i.useEffect((()=>{D&&(f&&h.layersWithOutsidePointerEventsDisabled.add(D),h.layers.add(D),c())}),[D,f,h]),i.useEffect((()=>()=>{D&&(h.layers.delete(D),h.layersWithOutsidePointerEventsDisabled.delete(D),c())}),[D,h]),i.useEffect((()=>{const e=()=>C({});return document.addEventListener("dismissableLayer.update",e),()=>document.removeEventListener("dismissableLayer.update",e)}),[]),/*#__PURE__*/i.createElement(s.div,a({},w,{ref:L,style:{pointerEvents:R?F?"auto":"none":void 0,...l.style},onFocusCapture:o(l.onFocusCapture,W.onFocusCapture),onBlurCapture:o(l.onBlurCapture,W.onBlurCapture),onPointerDownCapture:o(l.onPointerDownCapture,S.onPointerDownCapture)}))}));/*#__PURE__*/export const DismissableLayerBranch=/*#__PURE__*/i.forwardRef(((e,t)=>{const n=i.useContext(u),o=i.useRef(null),c=r(t,o);return i.useEffect((()=>{const e=o.current;if(e)return n.branches.add(e),()=>{n.branches.delete(e)}}),[n.branches]),/*#__PURE__*/i.createElement(s.div,a({},e,{ref:c}))}));/*#__PURE__*/function c(){const e=new Event("dismissableLayer.update");document.dispatchEvent(e)}function d(e,t,n){const r=n.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});return t&&r.addEventListener(e,t,{once:!0}),!r.dispatchEvent(s)}export const Root=DismissableLayer;export const Branch=DismissableLayerBranch;
1
+ import $kqwpH$babelruntimehelpersesmextends from "@babel/runtime/helpers/esm/extends";
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
+ import {composeEventHandlers as $kqwpH$composeEventHandlers} from "@radix-ui/primitive";
4
+ import {Primitive as $kqwpH$Primitive} from "@radix-ui/react-primitive";
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
+ import {useCallbackRef as $kqwpH$useCallbackRef} from "@radix-ui/react-use-callback-ref";
8
+ import {useEscapeKeydown as $kqwpH$useEscapeKeydown} from "@radix-ui/react-use-escape-keydown";
9
+
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
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+ /* -------------------------------------------------------------------------------------------------
28
+ * DismissableLayer
29
+ * -----------------------------------------------------------------------------------------------*/ const $5cb92bef7577960e$var$DISMISSABLE_LAYER_NAME = 'DismissableLayer';
30
+ const $5cb92bef7577960e$var$CONTEXT_UPDATE = 'dismissableLayer.update';
31
+ const $5cb92bef7577960e$var$POINTER_DOWN_OUTSIDE = 'dismissableLayer.pointerDownOutside';
32
+ const $5cb92bef7577960e$var$FOCUS_OUTSIDE = 'dismissableLayer.focusOutside';
33
+ const $5cb92bef7577960e$var$DismissableLayerContext = /*#__PURE__*/ $kqwpH$createContext({
34
+ layers: new Set(),
35
+ layersWithOutsidePointerEventsDisabled: new Set(),
36
+ branches: new Set()
37
+ });
38
+ const $5cb92bef7577960e$export$177fb62ff3ec1f22 = /*#__PURE__*/ $kqwpH$forwardRef((props, forwardedRef)=>{
39
+ const { disableOutsidePointerEvents: disableOutsidePointerEvents = false , onEscapeKeyDown: onEscapeKeyDown , onPointerDownOutside: onPointerDownOutside , onFocusOutside: onFocusOutside , onInteractOutside: onInteractOutside , onDismiss: onDismiss , ...layerProps } = props;
40
+ const context = $kqwpH$useContext($5cb92bef7577960e$var$DismissableLayerContext);
41
+ const [node1, setNode] = $kqwpH$useState(null);
42
+ const [, force] = $kqwpH$useState({});
43
+ const composedRefs = $kqwpH$useComposedRefs(forwardedRef, (node)=>setNode(node)
44
+ );
45
+ const layers = Array.from(context.layers);
46
+ const [highestLayerWithOutsidePointerEventsDisabled] = [
47
+ ...context.layersWithOutsidePointerEventsDisabled
48
+ ].slice(-1); // prettier-ignore
49
+ const highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled); // prettier-ignore
50
+ const index = node1 ? layers.indexOf(node1) : -1;
51
+ const isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0;
52
+ const isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex;
53
+ const pointerDownOutside = $5cb92bef7577960e$var$usePointerDownOutside((event)=>{
54
+ const target = event.target;
55
+ const isPointerDownOnBranch = [
56
+ ...context.branches
57
+ ].some((branch)=>branch.contains(target)
58
+ );
59
+ if (!isPointerEventsEnabled || isPointerDownOnBranch) return;
60
+ onPointerDownOutside === null || onPointerDownOutside === void 0 || onPointerDownOutside(event);
61
+ onInteractOutside === null || onInteractOutside === void 0 || onInteractOutside(event);
62
+ if (!event.defaultPrevented) onDismiss === null || onDismiss === void 0 || onDismiss();
63
+ });
64
+ const focusOutside = $5cb92bef7577960e$var$useFocusOutside((event)=>{
65
+ const target = event.target;
66
+ const isFocusInBranch = [
67
+ ...context.branches
68
+ ].some((branch)=>branch.contains(target)
69
+ );
70
+ if (isFocusInBranch) return;
71
+ onFocusOutside === null || onFocusOutside === void 0 || onFocusOutside(event);
72
+ onInteractOutside === null || onInteractOutside === void 0 || onInteractOutside(event);
73
+ if (!event.defaultPrevented) onDismiss === null || onDismiss === void 0 || onDismiss();
74
+ });
75
+ $kqwpH$useEscapeKeydown((event)=>{
76
+ const isHighestLayer = index === context.layers.size - 1;
77
+ if (!isHighestLayer) return;
78
+ onEscapeKeyDown === null || onEscapeKeyDown === void 0 || onEscapeKeyDown(event);
79
+ if (!event.defaultPrevented) onDismiss === null || onDismiss === void 0 || onDismiss();
80
+ });
81
+ $kqwpH$useBodyPointerEvents({
82
+ disabled: disableOutsidePointerEvents
83
+ });
84
+ $kqwpH$useEffect(()=>{
85
+ if (!node1) return;
86
+ if (disableOutsidePointerEvents) context.layersWithOutsidePointerEventsDisabled.add(node1);
87
+ context.layers.add(node1);
88
+ $5cb92bef7577960e$var$dispatchUpdate();
89
+ }, [
90
+ node1,
91
+ disableOutsidePointerEvents,
92
+ context
93
+ ]);
94
+ /**
95
+ * We purposefully prevent combining this effect with the `disableOutsidePointerEvents` effect
96
+ * because a change to `disableOutsidePointerEvents` would remove this layer from the stack
97
+ * and add it to the end again so the layering order wouldn't be _creation order_.
98
+ * We only want them to be removed from context stacks when unmounted.
99
+ */ $kqwpH$useEffect(()=>{
100
+ return ()=>{
101
+ if (!node1) return;
102
+ context.layers.delete(node1);
103
+ context.layersWithOutsidePointerEventsDisabled.delete(node1);
104
+ $5cb92bef7577960e$var$dispatchUpdate();
105
+ };
106
+ }, [
107
+ node1,
108
+ context
109
+ ]);
110
+ $kqwpH$useEffect(()=>{
111
+ const handleUpdate = ()=>force({})
112
+ ;
113
+ document.addEventListener($5cb92bef7577960e$var$CONTEXT_UPDATE, handleUpdate);
114
+ return ()=>document.removeEventListener($5cb92bef7577960e$var$CONTEXT_UPDATE, handleUpdate)
115
+ ;
116
+ }, []);
117
+ return /*#__PURE__*/ $kqwpH$createElement($kqwpH$Primitive.div, $kqwpH$babelruntimehelpersesmextends({}, layerProps, {
118
+ ref: composedRefs,
119
+ style: {
120
+ pointerEvents: isBodyPointerEventsDisabled ? isPointerEventsEnabled ? 'auto' : 'none' : undefined,
121
+ ...props.style
122
+ },
123
+ onFocusCapture: $kqwpH$composeEventHandlers(props.onFocusCapture, focusOutside.onFocusCapture),
124
+ onBlurCapture: $kqwpH$composeEventHandlers(props.onBlurCapture, focusOutside.onBlurCapture),
125
+ onPointerDownCapture: $kqwpH$composeEventHandlers(props.onPointerDownCapture, pointerDownOutside.onPointerDownCapture)
126
+ }));
127
+ });
128
+ /*#__PURE__*/ Object.assign($5cb92bef7577960e$export$177fb62ff3ec1f22, {
129
+ displayName: $5cb92bef7577960e$var$DISMISSABLE_LAYER_NAME
130
+ });
131
+ /* -------------------------------------------------------------------------------------------------
132
+ * DismissableLayerBranch
133
+ * -----------------------------------------------------------------------------------------------*/ const $5cb92bef7577960e$var$BRANCH_NAME = 'DismissableLayerBranch';
134
+ const $5cb92bef7577960e$export$4d5eb2109db14228 = /*#__PURE__*/ $kqwpH$forwardRef((props, forwardedRef)=>{
135
+ const context = $kqwpH$useContext($5cb92bef7577960e$var$DismissableLayerContext);
136
+ const ref = $kqwpH$useRef(null);
137
+ const composedRefs = $kqwpH$useComposedRefs(forwardedRef, ref);
138
+ $kqwpH$useEffect(()=>{
139
+ const node = ref.current;
140
+ if (node) {
141
+ context.branches.add(node);
142
+ return ()=>{
143
+ context.branches.delete(node);
144
+ };
145
+ }
146
+ }, [
147
+ context.branches
148
+ ]);
149
+ return /*#__PURE__*/ $kqwpH$createElement($kqwpH$Primitive.div, $kqwpH$babelruntimehelpersesmextends({}, props, {
150
+ ref: composedRefs
151
+ }));
152
+ });
153
+ /*#__PURE__*/ Object.assign($5cb92bef7577960e$export$4d5eb2109db14228, {
154
+ displayName: $5cb92bef7577960e$var$BRANCH_NAME
155
+ });
156
+ /* -----------------------------------------------------------------------------------------------*/ /**
157
+ * Listens for `pointerdown` outside a react subtree. We use `pointerdown` rather than `pointerup`
158
+ * to mimic layer dismissing behaviour present in OS.
159
+ * Returns props to pass to the node we want to check for outside events.
160
+ */ function $5cb92bef7577960e$var$usePointerDownOutside(onPointerDownOutside) {
161
+ const handlePointerDownOutside = $kqwpH$useCallbackRef(onPointerDownOutside);
162
+ const isPointerInsideReactTreeRef = $kqwpH$useRef(false);
163
+ $kqwpH$useEffect(()=>{
164
+ const handlePointerDown = (event)=>{
165
+ if (event.target && !isPointerInsideReactTreeRef.current) {
166
+ const eventDetail = {
167
+ originalEvent: event
168
+ };
169
+ $5cb92bef7577960e$var$dispatchCustomEvent($5cb92bef7577960e$var$POINTER_DOWN_OUTSIDE, handlePointerDownOutside, eventDetail);
170
+ }
171
+ isPointerInsideReactTreeRef.current = false;
172
+ };
173
+ /**
174
+ * if this hook executes in a component that mounts via a `pointerdown` event, the event
175
+ * would bubble up to the document and trigger a `pointerDownOutside` event. We avoid
176
+ * this by delaying the event listener registration on the document.
177
+ * This is not React specific, but rather how the DOM works, ie:
178
+ * ```
179
+ * button.addEventListener('pointerdown', () => {
180
+ * console.log('I will log');
181
+ * document.addEventListener('pointerdown', () => {
182
+ * console.log('I will also log');
183
+ * })
184
+ * });
185
+ */ const timerId = window.setTimeout(()=>{
186
+ document.addEventListener('pointerdown', handlePointerDown);
187
+ }, 0);
188
+ return ()=>{
189
+ window.clearTimeout(timerId);
190
+ document.removeEventListener('pointerdown', handlePointerDown);
191
+ };
192
+ }, [
193
+ handlePointerDownOutside
194
+ ]);
195
+ return {
196
+ // ensures we check React component tree (not just DOM tree)
197
+ onPointerDownCapture: ()=>isPointerInsideReactTreeRef.current = true
198
+ };
199
+ }
200
+ /**
201
+ * Listens for when focus happens outside a react subtree.
202
+ * Returns props to pass to the root (node) of the subtree we want to check.
203
+ */ function $5cb92bef7577960e$var$useFocusOutside(onFocusOutside) {
204
+ const handleFocusOutside = $kqwpH$useCallbackRef(onFocusOutside);
205
+ const isFocusInsideReactTreeRef = $kqwpH$useRef(false);
206
+ $kqwpH$useEffect(()=>{
207
+ const handleFocus = (event)=>{
208
+ if (event.target && !isFocusInsideReactTreeRef.current) {
209
+ const eventDetail = {
210
+ originalEvent: event
211
+ };
212
+ $5cb92bef7577960e$var$dispatchCustomEvent($5cb92bef7577960e$var$FOCUS_OUTSIDE, handleFocusOutside, eventDetail);
213
+ }
214
+ };
215
+ document.addEventListener('focusin', handleFocus);
216
+ return ()=>document.removeEventListener('focusin', handleFocus)
217
+ ;
218
+ }, [
219
+ handleFocusOutside
220
+ ]);
221
+ return {
222
+ onFocusCapture: ()=>isFocusInsideReactTreeRef.current = true
223
+ ,
224
+ onBlurCapture: ()=>isFocusInsideReactTreeRef.current = false
225
+ };
226
+ }
227
+ function $5cb92bef7577960e$var$dispatchUpdate() {
228
+ const event = new Event($5cb92bef7577960e$var$CONTEXT_UPDATE);
229
+ document.dispatchEvent(event);
230
+ }
231
+ function $5cb92bef7577960e$var$dispatchCustomEvent(name, handler, detail) {
232
+ const target = detail.originalEvent.target;
233
+ const event = new CustomEvent(name, {
234
+ bubbles: false,
235
+ cancelable: true,
236
+ detail: detail
237
+ });
238
+ if (handler) target.addEventListener(name, handler, {
239
+ once: true
240
+ });
241
+ return !target.dispatchEvent(event);
242
+ }
243
+ const $5cb92bef7577960e$export$be92b6f5f03c0fe9 = $5cb92bef7577960e$export$177fb62ff3ec1f22;
244
+ const $5cb92bef7577960e$export$aecb2ddcb55c95be = $5cb92bef7577960e$export$4d5eb2109db14228;
245
+
246
+
247
+
248
+
249
+ export {$5cb92bef7577960e$export$177fb62ff3ec1f22 as DismissableLayer, $5cb92bef7577960e$export$4d5eb2109db14228 as DismissableLayerBranch, $5cb92bef7577960e$export$be92b6f5f03c0fe9 as Root, $5cb92bef7577960e$export$aecb2ddcb55c95be as Branch};
2
250
  //# sourceMappingURL=index.module.js.map
@@ -1 +1 @@
1
- {"mappings":"idAcA,MAKMA,eAA0BC,EAAMC,cAAc,CAClDC,OAAQ,IAAIC,IACZC,uCAAwC,IAAID,IAC5CE,SAAU,IAAIF,aAuChB,MAAMG,8BAAmBN,EAAMO,YAC7B,CAACC,EAAOC,KACN,MAAMC,4BACJA,GAA8B,EAD1BC,gBAEJA,EAFIC,qBAGJA,EAHIC,eAIJA,EAJIC,kBAKJA,EALIC,UAMJA,KACGC,GACDR,EACES,EAAUjB,EAAMkB,WAAWnB,IAC1BoB,EAAMC,GAAWpB,EAAMqB,SAAyC,OACjE,CAAGC,GAAStB,EAAMqB,SAAS,IAC3BE,EAAeC,EAAgBf,GAAeU,GAASC,EAAQD,KAC/DjB,EAASuB,MAAMC,KAAKT,EAAQf,SAC3ByB,GAAgD,IAAIV,EAAQb,wCAAwCwB,OAAO,GAC5GC,EAAoD3B,EAAO4B,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AAMrB,EAAO6D,EAAIpC,QACjB,GAAIzB,EAEF,OADAF,EAAQZ,SAASkE,IAAIpD,GACd,KACLF,EAAQZ,SAASoE,OAAOtD,MAG3B,CAACF,EAAQZ,wBAELsE,EAAAC,cAACC,EAAUC,IAAXC,EAAA,GAAmBvE,EAAnB,CAA0BwE,IAAKzD,qBAgFxC,SAASiD,IACP,MAAM9B,EAAQ,IAAI4C,MAhQG,2BAiQrBpC,SAASqC,cAAc7C,GAGzB,SAASG,EACP2C,EACAC,EACAC,GAEA,MAAM/C,EAAS+C,EAAO5C,cAAcH,OAC9BD,EAAQ,IAAIiD,YAAYH,EAAM,CAAEI,SAAS,EAAOC,YAAY,EAAMH,OAAAA,IAExE,OADID,GAAS9C,EAAOQ,iBAAiBqC,EAAMC,EAA0B,CAAEK,MAAM,KACrEnD,EAAO4C,cAAc7C,UAG/B,MAAMqD,KAAOzF,wBACb,MAAM0F,OAASX","sources":["./packages/react/dismissable-layer/src/DismissableLayer.tsx"],"sourcesContent":["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":["DismissableLayerContext","React","createContext","layers","Set","layersWithOutsidePointerEventsDisabled","branches","DismissableLayer","forwardRef","props","forwardedRef","disableOutsidePointerEvents","onEscapeKeyDown","onPointerDownOutside","onFocusOutside","onInteractOutside","onDismiss","layerProps","context","useContext","node","setNode","useState","force","composedRefs","useComposedRefs","Array","from","highestLayerWithOutsidePointerEventsDisabled","slice","highestLayerWithOutsidePointerEventsDisabledIndex","indexOf","index","isBodyPointerEventsDisabled","size","isPointerEventsEnabled","pointerDownOutside","handlePointerDownOutside","useCallbackRef","isPointerInsideReactTreeRef","useRef","useEffect","handlePointerDown","event","target","current","dispatchCustomEvent","originalEvent","timerId","window","setTimeout","document","addEventListener","clearTimeout","removeEventListener","onPointerDownCapture","usePointerDownOutside","isPointerDownOnBranch","some","branch","contains","defaultPrevented","focusOutside","handleFocusOutside","isFocusInsideReactTreeRef","handleFocus","onFocusCapture","onBlurCapture","useFocusOutside","useEscapeKeydown","useBodyPointerEvents","disabled","add","dispatchUpdate","delete","handleUpdate","_react","createElement","Primitive","div","_babelRuntimeHelpersEsmExtends","ref","style","pointerEvents","undefined","composeEventHandlers","DismissableLayerBranch","Event","dispatchEvent","name","handler","detail","CustomEvent","bubbles","cancelable","once","Root","Branch"],"version":3,"file":"index.module.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;A;;;;;;;;ACUA;;oGAEA,CAEA,MAAMO,4CAAsB,GAAG,kBAA/B,AAAA;AACA,MAAMC,oCAAc,GAAG,y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,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radix-ui/react-dismissable-layer",
3
- "version": "0.1.6-rc.2",
3
+ "version": "0.1.6-rc.5",
4
4
  "license": "MIT",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -18,11 +18,11 @@
18
18
  "dependencies": {
19
19
  "@babel/runtime": "^7.13.10",
20
20
  "@radix-ui/primitive": "0.1.0",
21
- "@radix-ui/react-compose-refs": "0.1.1-rc.2",
22
- "@radix-ui/react-primitive": "0.1.5-rc.2",
23
- "@radix-ui/react-use-body-pointer-events": "0.1.2-rc.2",
24
- "@radix-ui/react-use-callback-ref": "0.1.1-rc.2",
25
- "@radix-ui/react-use-escape-keydown": "0.1.1-rc.2"
21
+ "@radix-ui/react-compose-refs": "0.1.1-rc.5",
22
+ "@radix-ui/react-primitive": "0.1.5-rc.5",
23
+ "@radix-ui/react-use-body-pointer-events": "0.1.2-rc.5",
24
+ "@radix-ui/react-use-callback-ref": "0.1.1-rc.5",
25
+ "@radix-ui/react-use-escape-keydown": "0.1.1-rc.5"
26
26
  },
27
27
  "devDependencies": {
28
28
  "react-remove-scroll": "^2.4.0"