@fluentui/react-utilities 9.7.3 → 9.7.4

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/CHANGELOG.json CHANGED
@@ -2,7 +2,22 @@
2
2
  "name": "@fluentui/react-utilities",
3
3
  "entries": [
4
4
  {
5
- "date": "Tue, 04 Apr 2023 18:42:18 GMT",
5
+ "date": "Wed, 12 Apr 2023 09:28:17 GMT",
6
+ "tag": "@fluentui/react-utilities_v9.7.4",
7
+ "version": "9.7.4",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "olfedias@microsoft.com",
12
+ "package": "@fluentui/react-utilities",
13
+ "commit": "1539311d63dfa731f1bbf1e08ab002a43c52f9a0",
14
+ "comment": "fix(hooks): cleanup event listeners only when \"disabled\" is false"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Tue, 04 Apr 2023 18:44:50 GMT",
6
21
  "tag": "@fluentui/react-utilities_v9.7.3",
7
22
  "version": "9.7.3",
8
23
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,21 @@
1
1
  # Change Log - @fluentui/react-utilities
2
2
 
3
- This log was last generated on Tue, 04 Apr 2023 18:42:18 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 12 Apr 2023 09:28:17 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.7.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.7.4)
8
+
9
+ Wed, 12 Apr 2023 09:28:17 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.7.3..@fluentui/react-utilities_v9.7.4)
11
+
12
+ ### Patches
13
+
14
+ - fix(hooks): cleanup event listeners only when "disabled" is false ([PR #27516](https://github.com/microsoft/fluentui/pull/27516) by olfedias@microsoft.com)
15
+
7
16
  ## [9.7.3](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.7.3)
8
17
 
9
- Tue, 04 Apr 2023 18:42:18 GMT
18
+ Tue, 04 Apr 2023 18:44:50 GMT
10
19
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.7.2..@fluentui/react-utilities_v9.7.3)
11
20
 
12
21
  ### Patches
package/dist/index.d.ts CHANGED
@@ -618,7 +618,8 @@ export declare type UseOnClickOrScrollOutsideOptions = {
618
618
  refs: React_2.MutableRefObject<HTMLElement | undefined | null>[];
619
619
  /**
620
620
  * By default uses element.contains, but custom contain function can be provided
621
- * @param parentRef - provided parent ref
621
+ *
622
+ * @param parent - provided parent element
622
623
  * @param child - event target element
623
624
  */
624
625
  contains?(parent: HTMLElement | null, child: HTMLElement): boolean;
@@ -24,6 +24,9 @@ export const useOnClickOutside = options => {
24
24
  }
25
25
  });
26
26
  React.useEffect(() => {
27
+ if (disabled) {
28
+ return;
29
+ }
27
30
  // Store the current event to avoid triggering handlers immediately
28
31
  // Note this depends on a deprecated but extremely well supported quirk of the web platform
29
32
  // https://github.com/facebook/react/issues/20074
@@ -36,12 +39,10 @@ export const useOnClickOutside = options => {
36
39
  }
37
40
  listener(event);
38
41
  };
39
- if (!disabled) {
40
- // use capture phase because React can update DOM before the event bubbles to the document
41
- element === null || element === void 0 ? void 0 : element.addEventListener('click', conditionalHandler, true);
42
- element === null || element === void 0 ? void 0 : element.addEventListener('touchstart', conditionalHandler, true);
43
- element === null || element === void 0 ? void 0 : element.addEventListener('contextmenu', conditionalHandler, true);
44
- }
42
+ // use capture phase because React can update DOM before the event bubbles to the document
43
+ element === null || element === void 0 ? void 0 : element.addEventListener('click', conditionalHandler, true);
44
+ element === null || element === void 0 ? void 0 : element.addEventListener('touchstart', conditionalHandler, true);
45
+ element === null || element === void 0 ? void 0 : element.addEventListener('contextmenu', conditionalHandler, true);
45
46
  // Garbage collect this event after it's no longer useful to avoid memory leaks
46
47
  timeoutId.current = window.setTimeout(() => {
47
48
  currentEvent = undefined;
@@ -102,27 +103,29 @@ const useIFrameFocus = options => {
102
103
  });
103
104
  // Adds listener to the custom iframe focus event
104
105
  React.useEffect(() => {
105
- if (!disabled) {
106
- targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.addEventListener(FUI_FRAME_EVENT, listener, true);
107
- return () => {
108
- targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener(FUI_FRAME_EVENT, listener, true);
109
- };
106
+ if (disabled) {
107
+ return;
110
108
  }
109
+ targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.addEventListener(FUI_FRAME_EVENT, listener, true);
110
+ return () => {
111
+ targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener(FUI_FRAME_EVENT, listener, true);
112
+ };
111
113
  }, [targetDocument, disabled, listener]);
112
114
  // Starts polling for the active element
113
115
  React.useEffect(() => {
114
- if (!disabled) {
115
- var _targetDocument_defaultView;
116
- timeoutRef.current = targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.setInterval(() => {
117
- const activeElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement;
118
- if ((activeElement === null || activeElement === void 0 ? void 0 : activeElement.tagName) === 'IFRAME' || (activeElement === null || activeElement === void 0 ? void 0 : activeElement.tagName) === 'WEBVIEW') {
119
- const event = new CustomEvent(FUI_FRAME_EVENT, {
120
- bubbles: true
121
- });
122
- activeElement.dispatchEvent(event);
123
- }
124
- }, pollDuration);
116
+ var _targetDocument_defaultView;
117
+ if (disabled) {
118
+ return;
125
119
  }
120
+ timeoutRef.current = targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.setInterval(() => {
121
+ const activeElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement;
122
+ if ((activeElement === null || activeElement === void 0 ? void 0 : activeElement.tagName) === 'IFRAME' || (activeElement === null || activeElement === void 0 ? void 0 : activeElement.tagName) === 'WEBVIEW') {
123
+ const event = new CustomEvent(FUI_FRAME_EVENT, {
124
+ bubbles: true
125
+ });
126
+ activeElement.dispatchEvent(event);
127
+ }
128
+ }, pollDuration);
126
129
  return () => {
127
130
  var _targetDocument_defaultView;
128
131
  targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.clearTimeout(timeoutRef.current);
@@ -1 +1 @@
1
- {"version":3,"names":["React","useEventCallback","useOnClickOutside","options","refs","callback","element","disabled","contains","containsProp","timeoutId","useRef","undefined","useIFrameFocus","listener","ev","parent","child","isOutside","every","ref","current","target","useEffect","currentEvent","getWindowEvent","window","conditionalHandler","event","addEventListener","setTimeout","removeEventListener","clearTimeout","_target_ownerDocument","_target_ownerDocument_defaultView","_target_ownerDocument_defaultView_event","ownerDocument","defaultView","FUI_FRAME_EVENT","targetDocument","pollDuration","timeoutRef","e","_targetDocument_defaultView","setInterval","activeElement","tagName","CustomEvent","bubbles","dispatchEvent"],"sources":["../../src/hooks/useOnClickOutside.ts"],"sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from './useEventCallback';\n\n/**\n * @internal\n */\nexport type UseOnClickOrScrollOutsideOptions = {\n /**\n * The element to listen for the click event\n */\n element: Document | undefined;\n /**\n * Refs to elements that check if the click is outside\n */\n refs: React.MutableRefObject<HTMLElement | undefined | null>[];\n\n /**\n * By default uses element.contains, but custom contain function can be provided\n * @param parentRef - provided parent ref\n * @param child - event target element\n */\n contains?(parent: HTMLElement | null, child: HTMLElement): boolean;\n\n /**\n * Disables event listeners\n */\n disabled?: boolean;\n\n /**\n * Called if the click is outside the element refs\n */\n callback: (ev: MouseEvent | TouchEvent) => void;\n};\n\n/**\n * @internal\n * Utility to perform checks where a click/touch event was made outside a component\n */\nexport const useOnClickOutside = (options: UseOnClickOrScrollOutsideOptions) => {\n const { refs, callback, element, disabled, contains: containsProp } = options;\n const timeoutId = React.useRef<number | undefined>(undefined);\n useIFrameFocus(options);\n\n const listener = useEventCallback((ev: MouseEvent | TouchEvent) => {\n const contains: UseOnClickOrScrollOutsideOptions['contains'] =\n containsProp || ((parent, child) => !!parent?.contains(child));\n\n const isOutside = refs.every(ref => !contains(ref.current || null, ev.target as HTMLElement));\n if (isOutside && !disabled) {\n callback(ev);\n }\n });\n\n React.useEffect(() => {\n // Store the current event to avoid triggering handlers immediately\n // Note this depends on a deprecated but extremely well supported quirk of the web platform\n // https://github.com/facebook/react/issues/20074\n let currentEvent = getWindowEvent(window);\n\n const conditionalHandler = (event: MouseEvent | TouchEvent) => {\n // Skip if this event is the same as the one running when we added the handlers\n if (event === currentEvent) {\n currentEvent = undefined;\n return;\n }\n\n listener(event);\n };\n\n if (!disabled) {\n // use capture phase because React can update DOM before the event bubbles to the document\n element?.addEventListener('click', conditionalHandler, true);\n element?.addEventListener('touchstart', conditionalHandler, true);\n element?.addEventListener('contextmenu', conditionalHandler, true);\n }\n\n // Garbage collect this event after it's no longer useful to avoid memory leaks\n timeoutId.current = window.setTimeout(() => {\n currentEvent = undefined;\n }, 1);\n\n return () => {\n element?.removeEventListener('click', conditionalHandler, true);\n element?.removeEventListener('touchstart', conditionalHandler, true);\n element?.removeEventListener('contextmenu', conditionalHandler, true);\n\n clearTimeout(timeoutId.current);\n currentEvent = undefined;\n };\n }, [listener, element, disabled]);\n};\n\nconst getWindowEvent = (target: Node | Window): Event | undefined => {\n if (target) {\n if (typeof (target as Window).window === 'object' && (target as Window).window === target) {\n // eslint-disable-next-line deprecation/deprecation\n return target.event;\n }\n\n // eslint-disable-next-line deprecation/deprecation\n return (target as Node).ownerDocument?.defaultView?.event ?? undefined;\n }\n\n return undefined;\n};\n\nconst FUI_FRAME_EVENT = 'fuiframefocus';\n\ninterface UseIFrameFocusOptions extends UseOnClickOrScrollOutsideOptions {\n /**\n * Millisecond duration to poll\n */\n pollDuration?: number;\n}\n\n/**\n * Since click events do not propagate past iframes, we use focus to detect if a\n * click has happened inside an iframe, since the only ways of focusing inside an\n * iframe are:\n * - clicking inside\n * - tabbing inside\n *\n * Polls the value of `document.activeElement`. If it is an iframe, then dispatch\n * a custom DOM event. When the custom event is received call the provided callback\n */\nconst useIFrameFocus = (options: UseIFrameFocusOptions) => {\n const {\n disabled,\n element: targetDocument,\n callback,\n contains: containsProp = (parent, child) => !!parent?.contains(child),\n pollDuration = 1000,\n refs,\n } = options;\n const timeoutRef = React.useRef<number>();\n\n const listener = useEventCallback((e: Event) => {\n const contains = containsProp || ((parent, child) => !!parent?.contains(child));\n\n const isOutside = refs.every(ref => !contains(ref.current || null, e.target as HTMLElement));\n if (isOutside && !disabled) {\n callback(e as MouseEvent);\n }\n });\n\n // Adds listener to the custom iframe focus event\n React.useEffect(() => {\n if (!disabled) {\n targetDocument?.addEventListener(FUI_FRAME_EVENT, listener, true);\n return () => {\n targetDocument?.removeEventListener(FUI_FRAME_EVENT, listener, true);\n };\n }\n }, [targetDocument, disabled, listener]);\n\n // Starts polling for the active element\n React.useEffect(() => {\n if (!disabled) {\n timeoutRef.current = targetDocument?.defaultView?.setInterval(() => {\n const activeElement = targetDocument?.activeElement;\n if (activeElement?.tagName === 'IFRAME' || activeElement?.tagName === 'WEBVIEW') {\n const event = new CustomEvent(FUI_FRAME_EVENT, { bubbles: true });\n activeElement.dispatchEvent(event);\n }\n }, pollDuration);\n }\n return () => {\n targetDocument?.defaultView?.clearTimeout(timeoutRef.current);\n };\n }, [targetDocument, disabled, pollDuration]);\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,gBAAgB,QAAQ;AAiCjC;;;;AAIA,OAAO,MAAMC,iBAAA,GAAqBC,OAAA,IAA8C;EAC9E,MAAM;IAAEC,IAAA;IAAMC,QAAA;IAAUC,OAAA;IAASC,QAAA;IAAUC,QAAA,EAAUC;EAAY,CAAE,GAAGN,OAAA;EACtE,MAAMO,SAAA,GAAYV,KAAA,CAA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,aAAAA,aAAA,uBAAAA,aAAA,CAAeC,OAAO,MAAK,WAAW;UAC/E,MAAMlB,KAAA,GAAQ,IAAImB,WAAA,CAAYT,eAAA,EAAiB;YAAEU,OAAA,EAAS;UAAK;UAC/DH,aAAA,CAAcI,aAAa,CAACrB,KAAA;QAC9B;MACF,GAAGY,YAAA;IACL;IACA,OAAO,MAAM;UACXG,2BAAA;MAAAJ,cAAA,aAAAA,cAAA,wBAAAI,2BAAA,GAAAJ,cAAA,CAAgBF,WAAW,cAA3BM,2BAAA,uBAAAA,2BAAA,CAA6BX,YAAA,CAAaS,UAAA,CAAWpB,OAAO;IAC9D;EACF,GAAG,CAACkB,cAAA,EAAgBhC,QAAA,EAAUiC,YAAA,CAAa;AAC7C"}
1
+ {"version":3,"names":["React","useEventCallback","useOnClickOutside","options","refs","callback","element","disabled","contains","containsProp","timeoutId","useRef","undefined","useIFrameFocus","listener","ev","parent","child","isOutside","every","ref","current","target","useEffect","currentEvent","getWindowEvent","window","conditionalHandler","event","addEventListener","setTimeout","removeEventListener","clearTimeout","_target_ownerDocument","_target_ownerDocument_defaultView","_target_ownerDocument_defaultView_event","ownerDocument","defaultView","FUI_FRAME_EVENT","targetDocument","pollDuration","timeoutRef","e","_targetDocument_defaultView","setInterval","activeElement","tagName","CustomEvent","bubbles","dispatchEvent"],"sources":["../../src/hooks/useOnClickOutside.ts"],"sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from './useEventCallback';\n\n/**\n * @internal\n */\nexport type UseOnClickOrScrollOutsideOptions = {\n /**\n * The element to listen for the click event\n */\n element: Document | undefined;\n /**\n * Refs to elements that check if the click is outside\n */\n refs: React.MutableRefObject<HTMLElement | undefined | null>[];\n\n /**\n * By default uses element.contains, but custom contain function can be provided\n *\n * @param parent - provided parent element\n * @param child - event target element\n */\n contains?(parent: HTMLElement | null, child: HTMLElement): boolean;\n\n /**\n * Disables event listeners\n */\n disabled?: boolean;\n\n /**\n * Called if the click is outside the element refs\n */\n callback: (ev: MouseEvent | TouchEvent) => void;\n};\n\n/**\n * @internal\n * Utility to perform checks where a click/touch event was made outside a component\n */\nexport const useOnClickOutside = (options: UseOnClickOrScrollOutsideOptions) => {\n const { refs, callback, element, disabled, contains: containsProp } = options;\n const timeoutId = React.useRef<number | undefined>(undefined);\n useIFrameFocus(options);\n\n const listener = useEventCallback((ev: MouseEvent | TouchEvent) => {\n const contains: UseOnClickOrScrollOutsideOptions['contains'] =\n containsProp || ((parent, child) => !!parent?.contains(child));\n\n const isOutside = refs.every(ref => !contains(ref.current || null, ev.target as HTMLElement));\n if (isOutside && !disabled) {\n callback(ev);\n }\n });\n\n React.useEffect(() => {\n if (disabled) {\n return;\n }\n\n // Store the current event to avoid triggering handlers immediately\n // Note this depends on a deprecated but extremely well supported quirk of the web platform\n // https://github.com/facebook/react/issues/20074\n let currentEvent = getWindowEvent(window);\n\n const conditionalHandler = (event: MouseEvent | TouchEvent) => {\n // Skip if this event is the same as the one running when we added the handlers\n if (event === currentEvent) {\n currentEvent = undefined;\n return;\n }\n\n listener(event);\n };\n\n // use capture phase because React can update DOM before the event bubbles to the document\n element?.addEventListener('click', conditionalHandler, true);\n element?.addEventListener('touchstart', conditionalHandler, true);\n element?.addEventListener('contextmenu', conditionalHandler, true);\n\n // Garbage collect this event after it's no longer useful to avoid memory leaks\n timeoutId.current = window.setTimeout(() => {\n currentEvent = undefined;\n }, 1);\n\n return () => {\n element?.removeEventListener('click', conditionalHandler, true);\n element?.removeEventListener('touchstart', conditionalHandler, true);\n element?.removeEventListener('contextmenu', conditionalHandler, true);\n\n clearTimeout(timeoutId.current);\n currentEvent = undefined;\n };\n }, [listener, element, disabled]);\n};\n\nconst getWindowEvent = (target: Node | Window): Event | undefined => {\n if (target) {\n if (typeof (target as Window).window === 'object' && (target as Window).window === target) {\n // eslint-disable-next-line deprecation/deprecation\n return target.event;\n }\n\n // eslint-disable-next-line deprecation/deprecation\n return (target as Node).ownerDocument?.defaultView?.event ?? undefined;\n }\n\n return undefined;\n};\n\nconst FUI_FRAME_EVENT = 'fuiframefocus';\n\ninterface UseIFrameFocusOptions extends UseOnClickOrScrollOutsideOptions {\n /**\n * Millisecond duration to poll\n */\n pollDuration?: number;\n}\n\n/**\n * Since click events do not propagate past iframes, we use focus to detect if a\n * click has happened inside an iframe, since the only ways of focusing inside an\n * iframe are:\n * - clicking inside\n * - tabbing inside\n *\n * Polls the value of `document.activeElement`. If it is an iframe, then dispatch\n * a custom DOM event. When the custom event is received call the provided callback\n */\nconst useIFrameFocus = (options: UseIFrameFocusOptions) => {\n const {\n disabled,\n element: targetDocument,\n callback,\n contains: containsProp = (parent, child) => !!parent?.contains(child),\n pollDuration = 1000,\n refs,\n } = options;\n const timeoutRef = React.useRef<number>();\n\n const listener = useEventCallback((e: Event) => {\n const contains = containsProp || ((parent, child) => !!parent?.contains(child));\n\n const isOutside = refs.every(ref => !contains(ref.current || null, e.target as HTMLElement));\n if (isOutside && !disabled) {\n callback(e as MouseEvent);\n }\n });\n\n // Adds listener to the custom iframe focus event\n React.useEffect(() => {\n if (disabled) {\n return;\n }\n\n targetDocument?.addEventListener(FUI_FRAME_EVENT, listener, true);\n\n return () => {\n targetDocument?.removeEventListener(FUI_FRAME_EVENT, listener, true);\n };\n }, [targetDocument, disabled, listener]);\n\n // Starts polling for the active element\n React.useEffect(() => {\n if (disabled) {\n return;\n }\n\n timeoutRef.current = targetDocument?.defaultView?.setInterval(() => {\n const activeElement = targetDocument?.activeElement;\n\n if (activeElement?.tagName === 'IFRAME' || activeElement?.tagName === 'WEBVIEW') {\n const event = new CustomEvent(FUI_FRAME_EVENT, { bubbles: true });\n activeElement.dispatchEvent(event);\n }\n }, pollDuration);\n\n return () => {\n targetDocument?.defaultView?.clearTimeout(timeoutRef.current);\n };\n }, [targetDocument, disabled, pollDuration]);\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,gBAAgB,QAAQ;AAkCjC;;;;AAIA,OAAO,MAAMC,iBAAA,GAAqBC,OAAA,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MAAM;MAClE,MAAMC,aAAA,GAAgBN,cAAA,aAAAA,cAAA,uBAAAA,cAAA,CAAgBM,aAAa;MAEnD,IAAI,CAAAA,aAAA,aAAAA,aAAA,uBAAAA,aAAA,CAAeC,OAAO,MAAK,YAAY,CAAAD,aAAA,aAAAA,aAAA,uBAAAA,aAAA,CAAeC,OAAO,MAAK,WAAW;QAC/E,MAAMlB,KAAA,GAAQ,IAAImB,WAAA,CAAYT,eAAA,EAAiB;UAAEU,OAAA,EAAS;QAAK;QAC/DH,aAAA,CAAcI,aAAa,CAACrB,KAAA;MAC9B;IACF,GAAGY,YAAA;IAEH,OAAO,MAAM;UACXG,2BAAA;MAAAJ,cAAA,aAAAA,cAAA,wBAAAI,2BAAA,GAAAJ,cAAA,CAAgBF,WAAW,cAA3BM,2BAAA,uBAAAA,2BAAA,CAA6BX,YAAA,CAAaS,UAAA,CAAWpB,OAAO;IAC9D;EACF,GAAG,CAACkB,cAAA,EAAgBhC,QAAA,EAAUiC,YAAA,CAAa;AAC7C"}
@@ -22,10 +22,11 @@ export const useOnScrollOutside = options => {
22
22
  }
23
23
  });
24
24
  React.useEffect(() => {
25
- if (!disabled) {
26
- element === null || element === void 0 ? void 0 : element.addEventListener('wheel', listener);
27
- element === null || element === void 0 ? void 0 : element.addEventListener('touchmove', listener);
25
+ if (disabled) {
26
+ return;
28
27
  }
28
+ element === null || element === void 0 ? void 0 : element.addEventListener('wheel', listener);
29
+ element === null || element === void 0 ? void 0 : element.addEventListener('touchmove', listener);
29
30
  return () => {
30
31
  element === null || element === void 0 ? void 0 : element.removeEventListener('wheel', listener);
31
32
  element === null || element === void 0 ? void 0 : element.removeEventListener('touchmove', listener);
@@ -1 +1 @@
1
- {"version":3,"names":["React","useEventCallback","useOnScrollOutside","options","refs","callback","element","disabled","contains","containsProp","listener","ev","parent","child","isOutside","every","ref","current","target","useEffect","addEventListener","removeEventListener"],"sources":["../../src/hooks/useOnScrollOutside.ts"],"sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from './useEventCallback';\nimport type { UseOnClickOrScrollOutsideOptions } from './useOnClickOutside';\n\n/**\n * @internal\n * Utility to perform checks where a click/touch event was made outside a component\n */\nexport const useOnScrollOutside = (options: UseOnClickOrScrollOutsideOptions) => {\n const { refs, callback, element, disabled, contains: containsProp } = options;\n\n const listener = useEventCallback((ev: MouseEvent | TouchEvent) => {\n const contains: UseOnClickOrScrollOutsideOptions['contains'] =\n containsProp || ((parent, child) => !!parent?.contains(child));\n\n const isOutside = refs.every(ref => !contains(ref.current || null, ev.target as HTMLElement));\n if (isOutside && !disabled) {\n callback(ev);\n }\n });\n\n React.useEffect(() => {\n if (!disabled) {\n element?.addEventListener('wheel', listener);\n element?.addEventListener('touchmove', listener);\n }\n\n return () => {\n element?.removeEventListener('wheel', listener);\n element?.removeEventListener('touchmove', listener);\n };\n }, [listener, element, disabled]);\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,gBAAgB,QAAQ;AAGjC;;;;AAIA,OAAO,MAAMC,kBAAA,GAAsBC,OAAA,IAA8C;EAC/E,MAAM;IAAEC,IAAA;IAAMC,QAAA;IAAUC,OAAA;IAASC,QAAA;IAAUC,QAAA,EAAUC;EAAY,CAAE,GAAGN,OAAA;EAEtE,MAAMO,QAAA,GAAWT,gBAAA,CAAkBU,EAAA,IAAgC;IACjE,MAAMH,QAAA,GACJC,YAAA,KAAiB,CAACG,MAAA,EAAQC,KAAA;MAAU,QAAC,EAACD,MAAA,aAAAA,MAAA,uBAAAA,MAAA,CAAQJ,QAAQ,CAACK,KAAA;KAAK;IAE9D,MAAMC,SAAA,GAAYV,IAAA,CAAKW,KAAK,CAACC,GAAA,IAAO,CAACR,QAAA,CAASQ,GAAA,CAAIC,OAAO,IAAI,IAAI,EAAEN,EAAA,CAAGO,MAAM;IAC5E,IAAIJ,SAAA,IAAa,CAACP,QAAA,EAAU;MAC1BF,QAAA,CAASM,EAAA;IACX;EACF;EAEAX,KAAA,CAAMmB,SAAS,CAAC,MAAM;IACpB,IAAI,CAACZ,QAAA,EAAU;MACbD,OAAA,aAAAA,OAAA,uBAAAA,OAAA,CAASc,gBAAgB,CAAC,SAASV,QAAA;MACnCJ,OAAA,aAAAA,OAAA,uBAAAA,OAAA,CAASc,gBAAgB,CAAC,aAAaV,QAAA;IACzC;IAEA,OAAO,MAAM;MACXJ,OAAA,aAAAA,OAAA,uBAAAA,OAAA,CAASe,mBAAmB,CAAC,SAASX,QAAA;MACtCJ,OAAA,aAAAA,OAAA,uBAAAA,OAAA,CAASe,mBAAmB,CAAC,aAAaX,QAAA;IAC5C;EACF,GAAG,CAACA,QAAA,EAAUJ,OAAA,EAASC,QAAA,CAAS;AAClC"}
1
+ {"version":3,"names":["React","useEventCallback","useOnScrollOutside","options","refs","callback","element","disabled","contains","containsProp","listener","ev","parent","child","isOutside","every","ref","current","target","useEffect","addEventListener","removeEventListener"],"sources":["../../src/hooks/useOnScrollOutside.ts"],"sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from './useEventCallback';\nimport type { UseOnClickOrScrollOutsideOptions } from './useOnClickOutside';\n\n/**\n * @internal\n * Utility to perform checks where a click/touch event was made outside a component\n */\nexport const useOnScrollOutside = (options: UseOnClickOrScrollOutsideOptions) => {\n const { refs, callback, element, disabled, contains: containsProp } = options;\n\n const listener = useEventCallback((ev: MouseEvent | TouchEvent) => {\n const contains: UseOnClickOrScrollOutsideOptions['contains'] =\n containsProp || ((parent, child) => !!parent?.contains(child));\n\n const isOutside = refs.every(ref => !contains(ref.current || null, ev.target as HTMLElement));\n if (isOutside && !disabled) {\n callback(ev);\n }\n });\n\n React.useEffect(() => {\n if (disabled) {\n return;\n }\n\n element?.addEventListener('wheel', listener);\n element?.addEventListener('touchmove', listener);\n\n return () => {\n element?.removeEventListener('wheel', listener);\n element?.removeEventListener('touchmove', listener);\n };\n }, [listener, element, disabled]);\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,gBAAgB,QAAQ;AAGjC;;;;AAIA,OAAO,MAAMC,kBAAA,GAAsBC,OAAA,IAA8C;EAC/E,MAAM;IAAEC,IAAA;IAAMC,QAAA;IAAUC,OAAA;IAASC,QAAA;IAAUC,QAAA,EAAUC;EAAY,CAAE,GAAGN,OAAA;EAEtE,MAAMO,QAAA,GAAWT,gBAAA,CAAkBU,EAAA,IAAgC;IACjE,MAAMH,QAAA,GACJC,YAAA,KAAiB,CAACG,MAAA,EAAQC,KAAA;MAAU,QAAC,EAACD,MAAA,aAAAA,MAAA,uBAAAA,MAAA,CAAQJ,QAAQ,CAACK,KAAA;KAAK;IAE9D,MAAMC,SAAA,GAAYV,IAAA,CAAKW,KAAK,CAACC,GAAA,IAAO,CAACR,QAAA,CAASQ,GAAA,CAAIC,OAAO,IAAI,IAAI,EAAEN,EAAA,CAAGO,MAAM;IAC5E,IAAIJ,SAAA,IAAa,CAACP,QAAA,EAAU;MAC1BF,QAAA,CAASM,EAAA;IACX;EACF;EAEAX,KAAA,CAAMmB,SAAS,CAAC,MAAM;IACpB,IAAIZ,QAAA,EAAU;MACZ;IACF;IAEAD,OAAA,aAAAA,OAAA,uBAAAA,OAAA,CAASc,gBAAgB,CAAC,SAASV,QAAA;IACnCJ,OAAA,aAAAA,OAAA,uBAAAA,OAAA,CAASc,gBAAgB,CAAC,aAAaV,QAAA;IAEvC,OAAO,MAAM;MACXJ,OAAA,aAAAA,OAAA,uBAAAA,OAAA,CAASe,mBAAmB,CAAC,SAASX,QAAA;MACtCJ,OAAA,aAAAA,OAAA,uBAAAA,OAAA,CAASe,mBAAmB,CAAC,aAAaX,QAAA;IAC5C;EACF,GAAG,CAACA,QAAA,EAAUJ,OAAA,EAASC,QAAA,CAAS;AAClC"}
@@ -23,6 +23,9 @@ const useOnClickOutside = (options)=>{
23
23
  }
24
24
  });
25
25
  _react.useEffect(()=>{
26
+ if (disabled) {
27
+ return;
28
+ }
26
29
  // Store the current event to avoid triggering handlers immediately
27
30
  // Note this depends on a deprecated but extremely well supported quirk of the web platform
28
31
  // https://github.com/facebook/react/issues/20074
@@ -35,12 +38,10 @@ const useOnClickOutside = (options)=>{
35
38
  }
36
39
  listener(event);
37
40
  };
38
- if (!disabled) {
39
- // use capture phase because React can update DOM before the event bubbles to the document
40
- element === null || element === void 0 ? void 0 : element.addEventListener('click', conditionalHandler, true);
41
- element === null || element === void 0 ? void 0 : element.addEventListener('touchstart', conditionalHandler, true);
42
- element === null || element === void 0 ? void 0 : element.addEventListener('contextmenu', conditionalHandler, true);
43
- }
41
+ // use capture phase because React can update DOM before the event bubbles to the document
42
+ element === null || element === void 0 ? void 0 : element.addEventListener('click', conditionalHandler, true);
43
+ element === null || element === void 0 ? void 0 : element.addEventListener('touchstart', conditionalHandler, true);
44
+ element === null || element === void 0 ? void 0 : element.addEventListener('contextmenu', conditionalHandler, true);
44
45
  // Garbage collect this event after it's no longer useful to avoid memory leaks
45
46
  timeoutId.current = window.setTimeout(()=>{
46
47
  currentEvent = undefined;
@@ -97,12 +98,13 @@ const FUI_FRAME_EVENT = 'fuiframefocus';
97
98
  });
98
99
  // Adds listener to the custom iframe focus event
99
100
  _react.useEffect(()=>{
100
- if (!disabled) {
101
- targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.addEventListener(FUI_FRAME_EVENT, listener, true);
102
- return ()=>{
103
- targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener(FUI_FRAME_EVENT, listener, true);
104
- };
101
+ if (disabled) {
102
+ return;
105
103
  }
104
+ targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.addEventListener(FUI_FRAME_EVENT, listener, true);
105
+ return ()=>{
106
+ targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener(FUI_FRAME_EVENT, listener, true);
107
+ };
106
108
  }, [
107
109
  targetDocument,
108
110
  disabled,
@@ -110,18 +112,19 @@ const FUI_FRAME_EVENT = 'fuiframefocus';
110
112
  ]);
111
113
  // Starts polling for the active element
112
114
  _react.useEffect(()=>{
113
- if (!disabled) {
114
- var _targetDocument_defaultView;
115
- timeoutRef.current = targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.setInterval(()=>{
116
- const activeElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement;
117
- if ((activeElement === null || activeElement === void 0 ? void 0 : activeElement.tagName) === 'IFRAME' || (activeElement === null || activeElement === void 0 ? void 0 : activeElement.tagName) === 'WEBVIEW') {
118
- const event = new CustomEvent(FUI_FRAME_EVENT, {
119
- bubbles: true
120
- });
121
- activeElement.dispatchEvent(event);
122
- }
123
- }, pollDuration);
115
+ var _targetDocument_defaultView;
116
+ if (disabled) {
117
+ return;
124
118
  }
119
+ timeoutRef.current = targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.setInterval(()=>{
120
+ const activeElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement;
121
+ if ((activeElement === null || activeElement === void 0 ? void 0 : activeElement.tagName) === 'IFRAME' || (activeElement === null || activeElement === void 0 ? void 0 : activeElement.tagName) === 'WEBVIEW') {
122
+ const event = new CustomEvent(FUI_FRAME_EVENT, {
123
+ bubbles: true
124
+ });
125
+ activeElement.dispatchEvent(event);
126
+ }
127
+ }, pollDuration);
125
128
  return ()=>{
126
129
  var _targetDocument_defaultView;
127
130
  targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.clearTimeout(timeoutRef.current);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../lib/hooks/useOnClickOutside.js"],"sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from './useEventCallback';\n/**\n * @internal\n * Utility to perform checks where a click/touch event was made outside a component\n */\nexport const useOnClickOutside = options => {\n const {\n refs,\n callback,\n element,\n disabled,\n contains: containsProp\n } = options;\n const timeoutId = React.useRef(undefined);\n useIFrameFocus(options);\n const listener = useEventCallback(ev => {\n const contains = containsProp || ((parent, child) => {\n return !!(parent === null || parent === void 0 ? void 0 : parent.contains(child));\n });\n const isOutside = refs.every(ref => !contains(ref.current || null, ev.target));\n if (isOutside && !disabled) {\n callback(ev);\n }\n });\n React.useEffect(() => {\n // Store the current event to avoid triggering handlers immediately\n // Note this depends on a deprecated but extremely well supported quirk of the web platform\n // https://github.com/facebook/react/issues/20074\n let currentEvent = getWindowEvent(window);\n const conditionalHandler = event => {\n // Skip if this event is the same as the one running when we added the handlers\n if (event === currentEvent) {\n currentEvent = undefined;\n return;\n }\n listener(event);\n };\n if (!disabled) {\n // use capture phase because React can update DOM before the event bubbles to the document\n element === null || element === void 0 ? void 0 : element.addEventListener('click', conditionalHandler, true);\n element === null || element === void 0 ? void 0 : element.addEventListener('touchstart', conditionalHandler, true);\n element === null || element === void 0 ? void 0 : element.addEventListener('contextmenu', conditionalHandler, true);\n }\n // Garbage collect this event after it's no longer useful to avoid memory leaks\n timeoutId.current = window.setTimeout(() => {\n currentEvent = undefined;\n }, 1);\n return () => {\n element === null || element === void 0 ? void 0 : element.removeEventListener('click', conditionalHandler, true);\n element === null || element === void 0 ? void 0 : element.removeEventListener('touchstart', conditionalHandler, true);\n element === null || element === void 0 ? void 0 : element.removeEventListener('contextmenu', conditionalHandler, true);\n clearTimeout(timeoutId.current);\n currentEvent = undefined;\n };\n }, [listener, element, disabled]);\n};\nconst getWindowEvent = target => {\n if (target) {\n var _target_ownerDocument, _target_ownerDocument_defaultView;\n if (typeof target.window === 'object' && target.window === target) {\n // eslint-disable-next-line deprecation/deprecation\n return target.event;\n }\n var _target_ownerDocument_defaultView_event;\n // eslint-disable-next-line deprecation/deprecation\n return (_target_ownerDocument_defaultView_event = (_target_ownerDocument = target.ownerDocument) === null || _target_ownerDocument === void 0 ? void 0 : (_target_ownerDocument_defaultView = _target_ownerDocument.defaultView) === null || _target_ownerDocument_defaultView === void 0 ? void 0 : _target_ownerDocument_defaultView.event) !== null && _target_ownerDocument_defaultView_event !== void 0 ? _target_ownerDocument_defaultView_event : undefined;\n }\n return undefined;\n};\nconst FUI_FRAME_EVENT = 'fuiframefocus';\n/**\n * Since click events do not propagate past iframes, we use focus to detect if a\n * click has happened inside an iframe, since the only ways of focusing inside an\n * iframe are:\n * - clicking inside\n * - tabbing inside\n *\n * Polls the value of `document.activeElement`. If it is an iframe, then dispatch\n * a custom DOM event. When the custom event is received call the provided callback\n */\nconst useIFrameFocus = options => {\n const {\n disabled,\n element: targetDocument,\n callback,\n contains: containsProp = (parent, child) => {\n return !!(parent === null || parent === void 0 ? void 0 : parent.contains(child));\n },\n pollDuration = 1000,\n refs\n } = options;\n const timeoutRef = React.useRef();\n const listener = useEventCallback(e => {\n const contains = containsProp || ((parent, child) => {\n return !!(parent === null || parent === void 0 ? void 0 : parent.contains(child));\n });\n const isOutside = refs.every(ref => !contains(ref.current || null, e.target));\n if (isOutside && !disabled) {\n callback(e);\n }\n });\n // Adds listener to the custom iframe focus event\n React.useEffect(() => {\n if (!disabled) {\n targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.addEventListener(FUI_FRAME_EVENT, listener, true);\n return () => {\n targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener(FUI_FRAME_EVENT, listener, true);\n };\n }\n }, [targetDocument, disabled, listener]);\n // Starts polling for the active element\n React.useEffect(() => {\n if (!disabled) {\n var _targetDocument_defaultView;\n timeoutRef.current = targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.setInterval(() => {\n const activeElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement;\n if ((activeElement === null || activeElement === void 0 ? void 0 : activeElement.tagName) === 'IFRAME' || (activeElement === null || activeElement === void 0 ? void 0 : activeElement.tagName) === 'WEBVIEW') {\n const event = new CustomEvent(FUI_FRAME_EVENT, {\n bubbles: true\n });\n activeElement.dispatchEvent(event);\n }\n }, pollDuration);\n }\n return () => {\n var _targetDocument_defaultView;\n targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.clearTimeout(timeoutRef.current);\n };\n }, [targetDocument, disabled, pollDuration]);\n};\n//# sourceMappingURL=useOnClickOutside.js.map"],"names":["useOnClickOutside","options","refs","callback","element","disabled","contains","containsProp","timeoutId","React","useRef","undefined","useIFrameFocus","listener","useEventCallback","ev","parent","child","isOutside","every","ref","current","target","useEffect","currentEvent","getWindowEvent","window","conditionalHandler","event","addEventListener","setTimeout","removeEventListener","clearTimeout","_target_ownerDocument","_target_ownerDocument_defaultView","_target_ownerDocument_defaultView_event","ownerDocument","defaultView","FUI_FRAME_EVENT","targetDocument","pollDuration","timeoutRef","e","_targetDocument_defaultView","setInterval","activeElement","tagName","CustomEvent","bubbles","dispatchEvent"],"mappings":";;;;+BAMaA;;aAAAA;;;6DANU;kCACU;AAK1B,MAAMA,oBAAoBC,CAAAA,UAAW;IAC1C,MAAM,EACJC,KAAI,EACJC,SAAQ,EACRC,QAAO,EACPC,SAAQ,EACRC,UAAUC,aAAY,EACvB,GAAGN;IACJ,MAAMO,YAAYC,OAAMC,MAAM,CAACC;IAC/BC,eAAeX;IACf,MAAMY,WAAWC,IAAAA,kCAAgB,EAACC,CAAAA,KAAM;QACtC,MAAMT,WAAWC,gBAAiB,CAAA,CAACS,QAAQC,QAAU;YACnD,OAAO,CAAC,CAAED,CAAAA,WAAW,IAAI,IAAIA,WAAW,KAAK,IAAI,KAAK,IAAIA,OAAOV,QAAQ,CAACW,MAAM,AAAD;QACjF,CAAA;QACA,MAAMC,YAAYhB,KAAKiB,KAAK,CAACC,CAAAA,MAAO,CAACd,SAASc,IAAIC,OAAO,IAAI,IAAI,EAAEN,GAAGO,MAAM;Q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GY,aAAa;QAClB,CAAC;QACD,OAAO,IAAM;YACX,IAAIG;YACJJ,mBAAmB,IAAI,IAAIA,mBAAmB,KAAK,IAAI,KAAK,IAAI,AAACI,CAAAA,8BAA8BJ,eAAeF,WAAW,AAAD,MAAO,IAAI,IAAIM,gCAAgC,KAAK,IAAI,KAAK,IAAIA,4BAA4BX,YAAY,CAACS,WAAWpB,OAAO,CAAC;QACvP;IACF,GAAG;QAACkB;QAAgBlC;QAAUmC;KAAa;AAC7C,GACA,6CAA6C"}
1
+ {"version":3,"sources":["../../lib/hooks/useOnClickOutside.js"],"sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from './useEventCallback';\n/**\n * @internal\n * Utility to perform checks where a click/touch event was made outside a component\n */\nexport const useOnClickOutside = options => {\n const {\n refs,\n callback,\n element,\n disabled,\n contains: containsProp\n } = options;\n const timeoutId = React.useRef(undefined);\n useIFrameFocus(options);\n const listener = useEventCallback(ev => {\n const contains = containsProp || ((parent, child) => {\n return !!(parent === null || parent === void 0 ? void 0 : parent.contains(child));\n });\n const isOutside = refs.every(ref => !contains(ref.current || null, ev.target));\n if (isOutside && !disabled) {\n callback(ev);\n }\n });\n React.useEffect(() => {\n if (disabled) {\n return;\n }\n // Store the current event to avoid triggering handlers immediately\n // Note this depends on a deprecated but extremely well supported quirk of the web platform\n // https://github.com/facebook/react/issues/20074\n let currentEvent = getWindowEvent(window);\n const conditionalHandler = event => {\n // Skip if this event is the same as the one running when we added the handlers\n if (event === currentEvent) {\n currentEvent = undefined;\n return;\n }\n listener(event);\n };\n // use capture phase because React can update DOM before the event bubbles to the document\n element === null || element === void 0 ? void 0 : element.addEventListener('click', conditionalHandler, true);\n element === null || element === void 0 ? void 0 : element.addEventListener('touchstart', conditionalHandler, true);\n element === null || element === void 0 ? void 0 : element.addEventListener('contextmenu', conditionalHandler, true);\n // Garbage collect this event after it's no longer useful to avoid memory leaks\n timeoutId.current = window.setTimeout(() => {\n currentEvent = undefined;\n }, 1);\n return () => {\n element === null || element === void 0 ? void 0 : element.removeEventListener('click', conditionalHandler, true);\n element === null || element === void 0 ? void 0 : element.removeEventListener('touchstart', conditionalHandler, true);\n element === null || element === void 0 ? void 0 : element.removeEventListener('contextmenu', conditionalHandler, true);\n clearTimeout(timeoutId.current);\n currentEvent = undefined;\n };\n }, [listener, element, disabled]);\n};\nconst getWindowEvent = target => {\n if (target) {\n var _target_ownerDocument, _target_ownerDocument_defaultView;\n if (typeof target.window === 'object' && target.window === target) {\n // eslint-disable-next-line deprecation/deprecation\n return target.event;\n }\n var _target_ownerDocument_defaultView_event;\n // eslint-disable-next-line deprecation/deprecation\n return (_target_ownerDocument_defaultView_event = (_target_ownerDocument = target.ownerDocument) === null || _target_ownerDocument === void 0 ? void 0 : (_target_ownerDocument_defaultView = _target_ownerDocument.defaultView) === null || _target_ownerDocument_defaultView === void 0 ? void 0 : _target_ownerDocument_defaultView.event) !== null && _target_ownerDocument_defaultView_event !== void 0 ? _target_ownerDocument_defaultView_event : undefined;\n }\n return undefined;\n};\nconst FUI_FRAME_EVENT = 'fuiframefocus';\n/**\n * Since click events do not propagate past iframes, we use focus to detect if a\n * click has happened inside an iframe, since the only ways of focusing inside an\n * iframe are:\n * - clicking inside\n * - tabbing inside\n *\n * Polls the value of `document.activeElement`. If it is an iframe, then dispatch\n * a custom DOM event. When the custom event is received call the provided callback\n */\nconst useIFrameFocus = options => {\n const {\n disabled,\n element: targetDocument,\n callback,\n contains: containsProp = (parent, child) => {\n return !!(parent === null || parent === void 0 ? void 0 : parent.contains(child));\n },\n pollDuration = 1000,\n refs\n } = options;\n const timeoutRef = React.useRef();\n const listener = useEventCallback(e => {\n const contains = containsProp || ((parent, child) => {\n return !!(parent === null || parent === void 0 ? void 0 : parent.contains(child));\n });\n const isOutside = refs.every(ref => !contains(ref.current || null, e.target));\n if (isOutside && !disabled) {\n callback(e);\n }\n });\n // Adds listener to the custom iframe focus event\n React.useEffect(() => {\n if (disabled) {\n return;\n }\n targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.addEventListener(FUI_FRAME_EVENT, listener, true);\n return () => {\n targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener(FUI_FRAME_EVENT, listener, true);\n };\n }, [targetDocument, disabled, listener]);\n // Starts polling for the active element\n React.useEffect(() => {\n var _targetDocument_defaultView;\n if (disabled) {\n return;\n }\n timeoutRef.current = targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.setInterval(() => {\n const activeElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement;\n if ((activeElement === null || activeElement === void 0 ? void 0 : activeElement.tagName) === 'IFRAME' || (activeElement === null || activeElement === void 0 ? void 0 : activeElement.tagName) === 'WEBVIEW') {\n const event = new CustomEvent(FUI_FRAME_EVENT, {\n bubbles: true\n });\n activeElement.dispatchEvent(event);\n }\n }, pollDuration);\n return () => {\n var _targetDocument_defaultView;\n targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.clearTimeout(timeoutRef.current);\n };\n }, [targetDocument, disabled, pollDuration]);\n};\n//# sourceMappingURL=useOnClickOutside.js.map"],"names":["useOnClickOutside","options","refs","callback","element","disabled","contains","containsProp","timeoutId","React","useRef","undefined","useIFrameFocus","listener","useEventCallback","ev","parent","child","isOutside","every","ref","current","target","useEffect","currentEvent","getWindowEvent","window","conditionalHandler","event","addEventListener","setTimeout","removeEventListener","clearTimeout","_target_ownerDocument","_target_ownerDocument_defaultView","_target_ownerDocument_defaultView_event","ownerDocument","defaultView","FUI_FRAME_EVENT","targetDocument","pollDuration","timeoutRef","e","_targetDocument_defaultView","setInterval","activeElement","tagName","CustomEvent","bubbles","dispatchEvent"],"mappings":";;;;+BAMaA;;aAAAA;;;6DANU;kCACU;AAK1B,MAAMA,oBAAoBC,CAAAA,UAAW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AD,MAAO,IAAI,IAAIM,gCAAgC,KAAK,IAAI,KAAK,IAAIA,4BAA4BC,WAAW,CAAC,IAAM;YAC1P,MAAMC,gBAAgBN,mBAAmB,IAAI,IAAIA,mBAAmB,KAAK,IAAI,KAAK,IAAIA,eAAeM,aAAa;YAClH,IAAI,AAACA,CAAAA,kBAAkB,IAAI,IAAIA,kBAAkB,KAAK,IAAI,KAAK,IAAIA,cAAcC,OAAO,AAAD,MAAO,YAAY,AAACD,CAAAA,kBAAkB,IAAI,IAAIA,kBAAkB,KAAK,IAAI,KAAK,IAAIA,cAAcC,OAAO,AAAD,MAAO,WAAW;gBAC7M,MAAMlB,QAAQ,IAAImB,YAAYT,iBAAiB;oBAC7CU,SAAS,IAAI;gBACf;gBACAH,cAAcI,aAAa,CAACrB;YAC9B,CAAC;QACH,GAAGY,aAAa;QAChB,OAAO,IAAM;YACX,IAAIG;YACJJ,mBAAmB,IAAI,IAAIA,mBAAmB,KAAK,IAAI,KAAK,IAAI,AAACI,CAAAA,8BAA8BJ,eAAeF,WAAW,AAAD,MAAO,IAAI,IAAIM,gCAAgC,KAAK,IAAI,KAAK,IAAIA,4BAA4BX,YAAY,CAACS,WAAWpB,OAAO,CAAC;QACvP;IACF,GAAG;QAACkB;QAAgBlC;QAAUmC;KAAa;AAC7C,GACA,6CAA6C"}
@@ -21,10 +21,11 @@ const useOnScrollOutside = (options)=>{
21
21
  }
22
22
  });
23
23
  _react.useEffect(()=>{
24
- if (!disabled) {
25
- element === null || element === void 0 ? void 0 : element.addEventListener('wheel', listener);
26
- element === null || element === void 0 ? void 0 : element.addEventListener('touchmove', listener);
24
+ if (disabled) {
25
+ return;
27
26
  }
27
+ element === null || element === void 0 ? void 0 : element.addEventListener('wheel', listener);
28
+ element === null || element === void 0 ? void 0 : element.addEventListener('touchmove', listener);
28
29
  return ()=>{
29
30
  element === null || element === void 0 ? void 0 : element.removeEventListener('wheel', listener);
30
31
  element === null || element === void 0 ? void 0 : element.removeEventListener('touchmove', listener);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../lib/hooks/useOnScrollOutside.js"],"sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from './useEventCallback';\n/**\n * @internal\n * Utility to perform checks where a click/touch event was made outside a component\n */\nexport const useOnScrollOutside = options => {\n const {\n refs,\n callback,\n element,\n disabled,\n contains: containsProp\n } = options;\n const listener = useEventCallback(ev => {\n const contains = containsProp || ((parent, child) => {\n return !!(parent === null || parent === void 0 ? void 0 : parent.contains(child));\n });\n const isOutside = refs.every(ref => !contains(ref.current || null, ev.target));\n if (isOutside && !disabled) {\n callback(ev);\n }\n });\n React.useEffect(() => {\n if (!disabled) {\n element === null || element === void 0 ? void 0 : element.addEventListener('wheel', listener);\n element === null || element === void 0 ? void 0 : element.addEventListener('touchmove', listener);\n }\n return () => {\n element === null || element === void 0 ? void 0 : element.removeEventListener('wheel', listener);\n element === null || element === void 0 ? void 0 : element.removeEventListener('touchmove', listener);\n };\n }, [listener, element, disabled]);\n};\n//# sourceMappingURL=useOnScrollOutside.js.map"],"names":["useOnScrollOutside","options","refs","callback","element","disabled","contains","containsProp","listener","useEventCallback","ev","parent","child","isOutside","every","ref","current","target","React","useEffect","addEventListener","removeEventListener"],"mappings":";;;;+BAMaA;;aAAAA;;;6DANU;kCACU;AAK1B,MAAMA,qBAAqBC,CAAAA,UAAW;IAC3C,MAAM,EACJC,KAAI,EACJC,SAAQ,EACRC,QAAO,EACPC,SAAQ,EACRC,UAAUC,aAAY,EACvB,GAAGN;IACJ,MAAMO,WAAWC,IAAAA,kCAAgB,EAACC,CAAAA,KAAM;QACtC,MAAMJ,WAAWC,gBAAiB,CAAA,CAACI,QAAQC,QAAU;YACnD,OAAO,CAAC,CAAED,CAAAA,WAAW,IAAI,IAAIA,WAAW,KAAK,IAAI,KAAK,IAAIA,OAAOL,QAAQ,CAACM,MAAM,AAAD;QACjF,CAAA;QACA,MAAMC,YAAYX,KAAKY,KAAK,CAACC,CAAAA,MAAO,CAACT,SAASS,IAAIC,OAAO,IAAI,IAAI,EAAEN,GAAGO,MAAM;QAC5E,IAAIJ,aAAa,CAACR,UAAU;YAC1BF,SAASO;QACX,CAAC;IACH;IACAQ,OAAMC,SAAS,CAAC,IAAM;QACpB,IAAI,CAACd,UAAU;YACbD,YAAY,IAAI,IAAIA,YAAY,KAAK,IAAI,KAAK,IAAIA,QAAQgB,gBAAgB,CAAC,SAASZ,SAAS;YAC7FJ,YAAY,IAAI,IAAIA,YAAY,KAAK,IAAI,KAAK,IAAIA,QAAQgB,gBAAgB,CAAC,aAAaZ,SAAS;QACnG,CAAC;QACD,OAAO,IAAM;YACXJ,YAAY,IAAI,IAAIA,YAAY,KAAK,IAAI,KAAK,IAAIA,QAAQiB,mBAAmB,CAAC,SAASb,SAAS;YAChGJ,YAAY,IAAI,IAAIA,YAAY,KAAK,IAAI,KAAK,IAAIA,QAAQiB,mBAAmB,CAAC,aAAab,SAAS;QACtG;IACF,GAAG;QAACA;QAAUJ;QAASC;KAAS;AAClC,GACA,8CAA8C"}
1
+ {"version":3,"sources":["../../lib/hooks/useOnScrollOutside.js"],"sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from './useEventCallback';\n/**\n * @internal\n * Utility to perform checks where a click/touch event was made outside a component\n */\nexport const useOnScrollOutside = options => {\n const {\n refs,\n callback,\n element,\n disabled,\n contains: containsProp\n } = options;\n const listener = useEventCallback(ev => {\n const contains = containsProp || ((parent, child) => {\n return !!(parent === null || parent === void 0 ? void 0 : parent.contains(child));\n });\n const isOutside = refs.every(ref => !contains(ref.current || null, ev.target));\n if (isOutside && !disabled) {\n callback(ev);\n }\n });\n React.useEffect(() => {\n if (disabled) {\n return;\n }\n element === null || element === void 0 ? void 0 : element.addEventListener('wheel', listener);\n element === null || element === void 0 ? void 0 : element.addEventListener('touchmove', listener);\n return () => {\n element === null || element === void 0 ? void 0 : element.removeEventListener('wheel', listener);\n element === null || element === void 0 ? void 0 : element.removeEventListener('touchmove', listener);\n };\n }, [listener, element, disabled]);\n};\n//# sourceMappingURL=useOnScrollOutside.js.map"],"names":["useOnScrollOutside","options","refs","callback","element","disabled","contains","containsProp","listener","useEventCallback","ev","parent","child","isOutside","every","ref","current","target","React","useEffect","addEventListener","removeEventListener"],"mappings":";;;;+BAMaA;;aAAAA;;;6DANU;kCACU;AAK1B,MAAMA,qBAAqBC,CAAAA,UAAW;IAC3C,MAAM,EACJC,KAAI,EACJC,SAAQ,EACRC,QAAO,EACPC,SAAQ,EACRC,UAAUC,aAAY,EACvB,GAAGN;IACJ,MAAMO,WAAWC,IAAAA,kCAAgB,EAACC,CAAAA,KAAM;QACtC,MAAMJ,WAAWC,gBAAiB,CAAA,CAACI,QAAQC,QAAU;YACnD,OAAO,CAAC,CAAED,CAAAA,WAAW,IAAI,IAAIA,WAAW,KAAK,IAAI,KAAK,IAAIA,OAAOL,QAAQ,CAACM,MAAM,AAAD;QACjF,CAAA;QACA,MAAMC,YAAYX,KAAKY,KAAK,CAACC,CAAAA,MAAO,CAACT,SAASS,IAAIC,OAAO,IAAI,IAAI,EAAEN,GAAGO,MAAM;QAC5E,IAAIJ,aAAa,CAACR,UAAU;YAC1BF,SAASO;QACX,CAAC;IACH;IACAQ,OAAMC,SAAS,CAAC,IAAM;QACpB,IAAId,UAAU;YACZ;QACF,CAAC;QACDD,YAAY,IAAI,IAAIA,YAAY,KAAK,IAAI,KAAK,IAAIA,QAAQgB,gBAAgB,CAAC,SAASZ,SAAS;QAC7FJ,YAAY,IAAI,IAAIA,YAAY,KAAK,IAAI,KAAK,IAAIA,QAAQgB,gBAAgB,CAAC,aAAaZ,SAAS;QACjG,OAAO,IAAM;YACXJ,YAAY,IAAI,IAAIA,YAAY,KAAK,IAAI,KAAK,IAAIA,QAAQiB,mBAAmB,CAAC,SAASb,SAAS;YAChGJ,YAAY,IAAI,IAAIA,YAAY,KAAK,IAAI,KAAK,IAAIA,QAAQiB,mBAAmB,CAAC,aAAab,SAAS;QACtG;IACF,GAAG;QAACA;QAAUJ;QAASC;KAAS;AAClC,GACA,8CAA8C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-utilities",
3
- "version": "9.7.3",
3
+ "version": "9.7.4",
4
4
  "description": "A set of general React-specific utilities.",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",