@fluentui/react-utilities 9.13.3 → 9.13.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.
Files changed (39) hide show
  1. package/CHANGELOG.json +43 -1
  2. package/CHANGELOG.md +22 -2
  3. package/lib/compose/isSlot.js +1 -2
  4. package/lib/compose/isSlot.js.map +1 -1
  5. package/lib/compose/resolveShorthand.js +2 -5
  6. package/lib/compose/resolveShorthand.js.map +1 -1
  7. package/lib/compose/slot.js +1 -2
  8. package/lib/compose/slot.js.map +1 -1
  9. package/lib/hooks/useOnClickOutside.js +18 -26
  10. package/lib/hooks/useOnClickOutside.js.map +1 -1
  11. package/lib/hooks/useOnScrollOutside.js +8 -13
  12. package/lib/hooks/useOnScrollOutside.js.map +1 -1
  13. package/lib/selection/useSelection.js +6 -4
  14. package/lib/selection/useSelection.js.map +1 -1
  15. package/lib/utils/isHTMLElement.js +2 -2
  16. package/lib/utils/isHTMLElement.js.map +1 -1
  17. package/lib/utils/mergeCallbacks.js +2 -3
  18. package/lib/utils/mergeCallbacks.js.map +1 -1
  19. package/lib/utils/properties.js +1 -2
  20. package/lib/utils/properties.js.map +1 -1
  21. package/lib-commonjs/compose/isSlot.js +1 -2
  22. package/lib-commonjs/compose/isSlot.js.map +1 -1
  23. package/lib-commonjs/compose/resolveShorthand.js +2 -5
  24. package/lib-commonjs/compose/resolveShorthand.js.map +1 -1
  25. package/lib-commonjs/compose/slot.js +1 -2
  26. package/lib-commonjs/compose/slot.js.map +1 -1
  27. package/lib-commonjs/hooks/useOnClickOutside.js +18 -25
  28. package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -1
  29. package/lib-commonjs/hooks/useOnScrollOutside.js +8 -12
  30. package/lib-commonjs/hooks/useOnScrollOutside.js.map +1 -1
  31. package/lib-commonjs/selection/useSelection.js +6 -4
  32. package/lib-commonjs/selection/useSelection.js.map +1 -1
  33. package/lib-commonjs/utils/isHTMLElement.js +2 -2
  34. package/lib-commonjs/utils/isHTMLElement.js.map +1 -1
  35. package/lib-commonjs/utils/mergeCallbacks.js +2 -3
  36. package/lib-commonjs/utils/mergeCallbacks.js.map +1 -1
  37. package/lib-commonjs/utils/properties.js +1 -2
  38. package/lib-commonjs/utils/properties.js.map +1 -1
  39. package/package.json +2 -2
package/CHANGELOG.json CHANGED
@@ -2,7 +2,49 @@
2
2
  "name": "@fluentui/react-utilities",
3
3
  "entries": [
4
4
  {
5
- "date": "Wed, 06 Sep 2023 13:27:23 GMT",
5
+ "date": "Tue, 26 Sep 2023 17:44:20 GMT",
6
+ "tag": "@fluentui/react-utilities_v9.13.5",
7
+ "version": "9.13.5",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "yuanboxue@microsoft.com",
12
+ "package": "@fluentui/react-utilities",
13
+ "commit": "05a23f6f5f331841c9ac9fb63764440c543f791d",
14
+ "comment": "chore: trigger manual version bump after broken release"
15
+ },
16
+ {
17
+ "author": "beachball",
18
+ "package": "@fluentui/react-utilities",
19
+ "comment": "Bump @fluentui/keyboard-keys to v9.0.6",
20
+ "commit": "05a23f6f5f331841c9ac9fb63764440c543f791d"
21
+ }
22
+ ]
23
+ }
24
+ },
25
+ {
26
+ "date": "Tue, 26 Sep 2023 15:31:40 GMT",
27
+ "tag": "@fluentui/react-utilities_v9.13.4",
28
+ "version": "9.13.4",
29
+ "comments": {
30
+ "patch": [
31
+ {
32
+ "author": "martinhochel@microsoft.com",
33
+ "package": "@fluentui/react-utilities",
34
+ "commit": "e61473fa10195f6ebf2308205c1e72e91b711831",
35
+ "comment": "fix: bump swc core to mitigate transpilation memory leaks"
36
+ },
37
+ {
38
+ "author": "beachball",
39
+ "package": "@fluentui/react-utilities",
40
+ "comment": "Bump @fluentui/keyboard-keys to v9.0.5",
41
+ "commit": "e16520437e10cd824ac254dd797e32762b5de72d"
42
+ }
43
+ ]
44
+ }
45
+ },
46
+ {
47
+ "date": "Wed, 06 Sep 2023 13:31:31 GMT",
6
48
  "tag": "@fluentui/react-utilities_v9.13.3",
7
49
  "version": "9.13.3",
8
50
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,32 @@
1
1
  # Change Log - @fluentui/react-utilities
2
2
 
3
- This log was last generated on Wed, 06 Sep 2023 13:27:23 GMT and should not be manually modified.
3
+ This log was last generated on Tue, 26 Sep 2023 17:44:20 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.13.5](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.13.5)
8
+
9
+ Tue, 26 Sep 2023 17:44:20 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.13.4..@fluentui/react-utilities_v9.13.5)
11
+
12
+ ### Patches
13
+
14
+ - chore: trigger manual version bump after broken release ([PR #29303](https://github.com/microsoft/fluentui/pull/29303) by yuanboxue@microsoft.com)
15
+ - Bump @fluentui/keyboard-keys to v9.0.6 ([PR #29303](https://github.com/microsoft/fluentui/pull/29303) by beachball)
16
+
17
+ ## [9.13.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.13.4)
18
+
19
+ Tue, 26 Sep 2023 15:31:40 GMT
20
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.13.3..@fluentui/react-utilities_v9.13.4)
21
+
22
+ ### Patches
23
+
24
+ - fix: bump swc core to mitigate transpilation memory leaks ([PR #29253](https://github.com/microsoft/fluentui/pull/29253) by martinhochel@microsoft.com)
25
+ - Bump @fluentui/keyboard-keys to v9.0.5 ([PR #29300](https://github.com/microsoft/fluentui/pull/29300) by beachball)
26
+
7
27
  ## [9.13.3](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.13.3)
8
28
 
9
- Wed, 06 Sep 2023 13:27:23 GMT
29
+ Wed, 06 Sep 2023 13:31:31 GMT
10
30
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.13.2..@fluentui/react-utilities_v9.13.3)
11
31
 
12
32
  ### Patches
@@ -3,6 +3,5 @@ import { SLOT_ELEMENT_TYPE_SYMBOL } from './constants';
3
3
  * Guard method to ensure a given element is a slot.
4
4
  * This is mainly used internally to ensure a slot is being used as a component.
5
5
  */ export function isSlot(element) {
6
- var _element;
7
- return Boolean((_element = element) === null || _element === void 0 ? void 0 : _element.hasOwnProperty(SLOT_ELEMENT_TYPE_SYMBOL));
6
+ return Boolean(element === null || element === void 0 ? void 0 : element.hasOwnProperty(SLOT_ELEMENT_TYPE_SYMBOL));
8
7
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["isSlot.ts"],"sourcesContent":["import { SLOT_ELEMENT_TYPE_SYMBOL } from './constants';\nimport { SlotComponentType } from './types';\n\n/**\n * Guard method to ensure a given element is a slot.\n * This is mainly used internally to ensure a slot is being used as a component.\n */\nexport function isSlot<Props extends {}>(element: unknown): element is SlotComponentType<Props> {\n return Boolean((element as {} | undefined)?.hasOwnProperty(SLOT_ELEMENT_TYPE_SYMBOL));\n}\n"],"names":["SLOT_ELEMENT_TYPE_SYMBOL","isSlot","element","Boolean","hasOwnProperty"],"mappings":"AAAA,SAASA,wBAAwB,QAAQ,cAAc;AAGvD;;;CAGC,GACD,OAAO,SAASC,OAAyBC,OAAgB;QACvCA;IAAhB,OAAOC,SAASD,WAAAA,qBAAAA,+BAAD,AAACA,SAA4BE,cAAc,CAACJ;AAC7D"}
1
+ {"version":3,"sources":["isSlot.ts"],"sourcesContent":["import { SLOT_ELEMENT_TYPE_SYMBOL } from './constants';\nimport { SlotComponentType } from './types';\n\n/**\n * Guard method to ensure a given element is a slot.\n * This is mainly used internally to ensure a slot is being used as a component.\n */\nexport function isSlot<Props extends {}>(element: unknown): element is SlotComponentType<Props> {\n return Boolean((element as {} | undefined)?.hasOwnProperty(SLOT_ELEMENT_TYPE_SYMBOL));\n}\n"],"names":["SLOT_ELEMENT_TYPE_SYMBOL","isSlot","element","Boolean","hasOwnProperty"],"mappings":"AAAA,SAASA,wBAAwB,QAAQ,cAAc;AAGvD;;;CAGC,GACD,OAAO,SAASC,OAAyBC,OAAgB;IACvD,OAAOC,QAASD,oBAAAA,8BAAD,AAACA,QAA4BE,cAAc,CAACJ;AAC7D"}
@@ -4,13 +4,10 @@ import * as slot from './slot';
4
4
  * being passed down to getSlots method
5
5
  * @param value - the base shorthand props
6
6
  * @param options - options to resolve shorthand props
7
- */ export const resolveShorthand = (value, options)=>{
8
- var _options;
9
- return slot.optional(value, {
7
+ */ export const resolveShorthand = (value, options)=>slot.optional(value, {
10
8
  ...options,
11
- renderByDefault: (_options = options) === null || _options === void 0 ? void 0 : _options.required,
9
+ renderByDefault: options === null || options === void 0 ? void 0 : options.required,
12
10
  // elementType as undefined is the way to identify between a slot and a resolveShorthand call
13
11
  // in the case elementType is undefined assertSlots will fail, ensuring it'll only work with slot method.
14
12
  elementType: undefined
15
13
  });
16
- };
@@ -1 +1 @@
1
- {"version":3,"sources":["resolveShorthand.ts"],"sourcesContent":["import * as slot from './slot';\nimport type { SlotShorthandValue, UnknownSlotProps } from './types';\n\nexport type ResolveShorthandOptions<Props, Required extends boolean = false> = Required extends true\n ? { required: true; defaultProps?: Props }\n : { required?: Required; defaultProps?: Props };\n\nexport type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {\n <P extends Props>(value: P | SlotShorthandValue | undefined, options: ResolveShorthandOptions<P, true>): P;\n <P extends Props>(value: P | SlotShorthandValue | null | undefined, options?: ResolveShorthandOptions<P, boolean>):\n | P\n | undefined;\n};\n\n/**\n * Resolves shorthands into slot props, to ensure normalization of the signature\n * being passed down to getSlots method\n * @param value - the base shorthand props\n * @param options - options to resolve shorthand props\n */\nexport const resolveShorthand: ResolveShorthandFunction<UnknownSlotProps> = (value, options) =>\n slot.optional<UnknownSlotProps>(value, {\n ...options,\n renderByDefault: options?.required,\n // elementType as undefined is the way to identify between a slot and a resolveShorthand call\n // in the case elementType is undefined assertSlots will fail, ensuring it'll only work with slot method.\n elementType: undefined!,\n });\n"],"names":["slot","resolveShorthand","value","options","optional","renderByDefault","required","elementType","undefined"],"mappings":"AAAA,YAAYA,UAAU,SAAS;AAc/B;;;;;CAKC,GACD,OAAO,MAAMC,mBAA+D,CAACC,OAAOC;QAG/DA;WAFnBH,KAAKI,QAAQ,CAAmBF,OAAO;QACrC,GAAGC,OAAO;QACVE,eAAe,GAAEF,WAAAA,qBAAAA,+BAAAA,SAASG,QAAQ;QAClC,6FAA6F;QAC7F,yGAAyG;QACzGC,aAAaC;IACf;EAAG"}
1
+ {"version":3,"sources":["resolveShorthand.ts"],"sourcesContent":["import * as slot from './slot';\nimport type { SlotShorthandValue, UnknownSlotProps } from './types';\n\nexport type ResolveShorthandOptions<Props, Required extends boolean = false> = Required extends true\n ? { required: true; defaultProps?: Props }\n : { required?: Required; defaultProps?: Props };\n\nexport type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {\n <P extends Props>(value: P | SlotShorthandValue | undefined, options: ResolveShorthandOptions<P, true>): P;\n <P extends Props>(value: P | SlotShorthandValue | null | undefined, options?: ResolveShorthandOptions<P, boolean>):\n | P\n | undefined;\n};\n\n/**\n * Resolves shorthands into slot props, to ensure normalization of the signature\n * being passed down to getSlots method\n * @param value - the base shorthand props\n * @param options - options to resolve shorthand props\n */\nexport const resolveShorthand: ResolveShorthandFunction<UnknownSlotProps> = (value, options) =>\n slot.optional<UnknownSlotProps>(value, {\n ...options,\n renderByDefault: options?.required,\n // elementType as undefined is the way to identify between a slot and a resolveShorthand call\n // in the case elementType is undefined assertSlots will fail, ensuring it'll only work with slot method.\n elementType: undefined!,\n });\n"],"names":["slot","resolveShorthand","value","options","optional","renderByDefault","required","elementType","undefined"],"mappings":"AAAA,YAAYA,UAAU,SAAS;AAc/B;;;;;CAKC,GACD,OAAO,MAAMC,mBAA+D,CAACC,OAAOC,UAClFH,KAAKI,QAAQ,CAAmBF,OAAO;QACrC,GAAGC,OAAO;QACVE,eAAe,EAAEF,oBAAAA,8BAAAA,QAASG,QAAQ;QAClC,6FAA6F;QAC7F,yGAAyG;QACzGC,aAAaC;IACf,GAAG"}
@@ -21,9 +21,8 @@ import { SLOT_ELEMENT_TYPE_SYMBOL, SLOT_RENDER_FUNCTION_SYMBOL } from './constan
21
21
  [SLOT_ELEMENT_TYPE_SYMBOL]: elementType
22
22
  };
23
23
  if (props && typeof props.children === 'function') {
24
- var _defaultProps;
25
24
  propsWithMetadata[SLOT_RENDER_FUNCTION_SYMBOL] = props.children;
26
- propsWithMetadata.children = (_defaultProps = defaultProps) === null || _defaultProps === void 0 ? void 0 : _defaultProps.children;
25
+ propsWithMetadata.children = defaultProps === null || defaultProps === void 0 ? void 0 : defaultProps.children;
27
26
  }
28
27
  return propsWithMetadata;
29
28
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["slot.ts"],"sourcesContent":["import type {\n AsIntrinsicElement,\n SlotComponentType,\n SlotRenderFunction,\n SlotShorthandValue,\n UnknownSlotProps,\n} from './types';\nimport * as React from 'react';\nimport { SLOT_ELEMENT_TYPE_SYMBOL, SLOT_RENDER_FUNCTION_SYMBOL } from './constants';\n\nexport type SlotOptions<Props extends UnknownSlotProps> = {\n elementType:\n | React.ComponentType<Props>\n | (Props extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);\n defaultProps?: Partial<Props>;\n};\n\n/**\n * Creates a slot from a slot shorthand or properties (`props.SLOT_NAME` or `props` itself)\n * @param value - the value of the slot, it can be a slot shorthand, a slot component or a slot properties\n * @param options - values you can pass to alter the signature of a slot, those values are:\n *\n * * `elementType` - the base element type of a slot, defaults to `'div'`\n * * `defaultProps` - similar to a React component declaration, you can provide a slot default properties to be merged with the shorthand/properties provided.\n */\nexport function always<Props extends UnknownSlotProps>(\n value: Props | SlotShorthandValue | undefined,\n options: SlotOptions<Props>,\n): SlotComponentType<Props> {\n const { defaultProps, elementType } = options;\n\n const props = resolveShorthand(value);\n\n /**\n * Casting is required here as SlotComponentType is a function, not an object.\n * Although SlotComponentType has a function signature, it is still just an object.\n * This is required to make a slot callable (JSX compatible), this is the exact same approach\n * that is used on `@types/react` components\n */\n const propsWithMetadata = {\n ...defaultProps,\n ...props,\n [SLOT_ELEMENT_TYPE_SYMBOL]: elementType,\n } as SlotComponentType<Props>;\n\n if (props && typeof props.children === 'function') {\n propsWithMetadata[SLOT_RENDER_FUNCTION_SYMBOL] = props.children as SlotRenderFunction<Props>;\n propsWithMetadata.children = defaultProps?.children;\n }\n\n return propsWithMetadata;\n}\n\n/**\n * Creates a slot from a slot shorthand or properties (`props.SLOT_NAME` or `props` itself)\n * @param value - the value of the slot, it can be a slot shorthand, a slot component or a slot properties\n * @param options - values you can pass to alter the signature of a slot, those values are:\n *\n * * `elementType` - the base element type of a slot, defaults to `'div'`\n * * `defaultProps` - similar to a React component declaration, you can provide a slot default properties to be merged with the shorthand/properties provided\n * * `renderByDefault` - a boolean that indicates if a slot will be rendered even if it's base value is `undefined`.\n * By default if `props.SLOT_NAME` is `undefined` then `state.SLOT_NAME` becomes `undefined`\n * and nothing will be rendered, but if `renderByDefault = true` then `state.SLOT_NAME` becomes an object\n * with the values provided by `options.defaultProps` (or `{}`). This is useful for cases such as providing a default content\n * in case no shorthand is provided, like the case of the `expandIcon` slot for the `AccordionHeader`\n */\nexport function optional<Props extends UnknownSlotProps>(\n value: Props | SlotShorthandValue | undefined | null,\n options: { renderByDefault?: boolean } & SlotOptions<Props>,\n): SlotComponentType<Props> | undefined {\n if (value === null || (value === undefined && !options.renderByDefault)) {\n return undefined;\n }\n return always(value, options);\n}\n\n/**\n * Helper function that converts a slot shorthand or properties to a slot properties object\n * The main difference between this function and `slot` is that this function does not return the metadata required for a slot to be considered a properly renderable slot, it only converts the value to a slot properties object\n * @param value - the value of the slot, it can be a slot shorthand or a slot properties object\n */\nexport function resolveShorthand<Props extends UnknownSlotProps | null | undefined>(\n value: Props | SlotShorthandValue,\n): Props {\n if (\n typeof value === 'string' ||\n typeof value === 'number' ||\n Array.isArray(value) ||\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n React.isValidElement<any>(value)\n ) {\n return { children: value } as Props;\n }\n if (value && typeof value !== 'object' && process.env.NODE_ENV !== 'production') {\n // TODO: would be nice to have a link to slot documentation in this error message\n // eslint-disable-next-line no-console\n console.error(/** #__DE-INDENT__ */ `\n @fluentui/react-utilities [slot.${resolveShorthand.name}]:\n A slot got an invalid value \"${value}\" (${typeof value}).\n A valid value for a slot is a slot shorthand or slot properties object.\n Slot shorthands can be strings, numbers, arrays or JSX elements\n `);\n }\n\n return value;\n}\n"],"names":["React","SLOT_ELEMENT_TYPE_SYMBOL","SLOT_RENDER_FUNCTION_SYMBOL","always","value","options","defaultProps","elementType","props","resolveShorthand","propsWithMetadata","children","optional","undefined","renderByDefault","Array","isArray","isValidElement","process","env","NODE_ENV","console","error","name"],"mappings":"AAOA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,wBAAwB,EAAEC,2BAA2B,QAAQ,cAAc;AASpF;;;;;;;CAOC,GACD,OAAO,SAASC,OACdC,KAA6C,EAC7CC,OAA2B;IAE3B,MAAM,EAAEC,YAAY,EAAEC,WAAW,EAAE,GAAGF;IAEtC,MAAMG,QAAQC,iBAAiBL;IAE/B;;;;;GAKC,GACD,MAAMM,oBAAoB;QACxB,GAAGJ,YAAY;QACf,GAAGE,KAAK;QACR,CAACP,yBAAyB,EAAEM;IAC9B;IAEA,IAAIC,SAAS,OAAOA,MAAMG,QAAQ,KAAK,YAAY;YAEpBL;QAD7BI,iBAAiB,CAACR,4BAA4B,GAAGM,MAAMG,QAAQ;QAC/DD,kBAAkBC,QAAQ,IAAGL,gBAAAA,0BAAAA,oCAAAA,cAAcK,QAAQ;IACrD;IAEA,OAAOD;AACT;AAEA;;;;;;;;;;;;CAYC,GACD,OAAO,SAASE,SACdR,KAAoD,EACpDC,OAA2D;IAE3D,IAAID,UAAU,QAASA,UAAUS,aAAa,CAACR,QAAQS,eAAe,EAAG;QACvE,OAAOD;IACT;IACA,OAAOV,OAAOC,OAAOC;AACvB;AAEA;;;;CAIC,GACD,OAAO,SAASI,iBACdL,KAAiC;IAEjC,IACE,OAAOA,UAAU,YACjB,OAAOA,UAAU,YACjBW,MAAMC,OAAO,CAACZ,UACd,8DAA8D;IAC9DJ,MAAMiB,cAAc,CAAMb,QAC1B;QACA,OAAO;YAAEO,UAAUP;QAAM;IAC3B;IACA,IAAIA,SAAS,OAAOA,UAAU,YAAYc,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QAC/E,iFAAiF;QACjF,sCAAsC;QACtCC,QAAQC,KAAK,CAAuB,CAAC,gCACH,EAAEb,iBAAiBc,IAAI,CAAC;6BAC3B,EAAEnB,MAAM,GAAG,EAAE,OAAOA,MAAM;;+DAGzD,CAAC;IACH;IAEA,OAAOA;AACT"}
1
+ {"version":3,"sources":["slot.ts"],"sourcesContent":["import type {\n AsIntrinsicElement,\n SlotComponentType,\n SlotRenderFunction,\n SlotShorthandValue,\n UnknownSlotProps,\n} from './types';\nimport * as React from 'react';\nimport { SLOT_ELEMENT_TYPE_SYMBOL, SLOT_RENDER_FUNCTION_SYMBOL } from './constants';\n\nexport type SlotOptions<Props extends UnknownSlotProps> = {\n elementType:\n | React.ComponentType<Props>\n | (Props extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);\n defaultProps?: Partial<Props>;\n};\n\n/**\n * Creates a slot from a slot shorthand or properties (`props.SLOT_NAME` or `props` itself)\n * @param value - the value of the slot, it can be a slot shorthand, a slot component or a slot properties\n * @param options - values you can pass to alter the signature of a slot, those values are:\n *\n * * `elementType` - the base element type of a slot, defaults to `'div'`\n * * `defaultProps` - similar to a React component declaration, you can provide a slot default properties to be merged with the shorthand/properties provided.\n */\nexport function always<Props extends UnknownSlotProps>(\n value: Props | SlotShorthandValue | undefined,\n options: SlotOptions<Props>,\n): SlotComponentType<Props> {\n const { defaultProps, elementType } = options;\n\n const props = resolveShorthand(value);\n\n /**\n * Casting is required here as SlotComponentType is a function, not an object.\n * Although SlotComponentType has a function signature, it is still just an object.\n * This is required to make a slot callable (JSX compatible), this is the exact same approach\n * that is used on `@types/react` components\n */\n const propsWithMetadata = {\n ...defaultProps,\n ...props,\n [SLOT_ELEMENT_TYPE_SYMBOL]: elementType,\n } as SlotComponentType<Props>;\n\n if (props && typeof props.children === 'function') {\n propsWithMetadata[SLOT_RENDER_FUNCTION_SYMBOL] = props.children as SlotRenderFunction<Props>;\n propsWithMetadata.children = defaultProps?.children;\n }\n\n return propsWithMetadata;\n}\n\n/**\n * Creates a slot from a slot shorthand or properties (`props.SLOT_NAME` or `props` itself)\n * @param value - the value of the slot, it can be a slot shorthand, a slot component or a slot properties\n * @param options - values you can pass to alter the signature of a slot, those values are:\n *\n * * `elementType` - the base element type of a slot, defaults to `'div'`\n * * `defaultProps` - similar to a React component declaration, you can provide a slot default properties to be merged with the shorthand/properties provided\n * * `renderByDefault` - a boolean that indicates if a slot will be rendered even if it's base value is `undefined`.\n * By default if `props.SLOT_NAME` is `undefined` then `state.SLOT_NAME` becomes `undefined`\n * and nothing will be rendered, but if `renderByDefault = true` then `state.SLOT_NAME` becomes an object\n * with the values provided by `options.defaultProps` (or `{}`). This is useful for cases such as providing a default content\n * in case no shorthand is provided, like the case of the `expandIcon` slot for the `AccordionHeader`\n */\nexport function optional<Props extends UnknownSlotProps>(\n value: Props | SlotShorthandValue | undefined | null,\n options: { renderByDefault?: boolean } & SlotOptions<Props>,\n): SlotComponentType<Props> | undefined {\n if (value === null || (value === undefined && !options.renderByDefault)) {\n return undefined;\n }\n return always(value, options);\n}\n\n/**\n * Helper function that converts a slot shorthand or properties to a slot properties object\n * The main difference between this function and `slot` is that this function does not return the metadata required for a slot to be considered a properly renderable slot, it only converts the value to a slot properties object\n * @param value - the value of the slot, it can be a slot shorthand or a slot properties object\n */\nexport function resolveShorthand<Props extends UnknownSlotProps | null | undefined>(\n value: Props | SlotShorthandValue,\n): Props {\n if (\n typeof value === 'string' ||\n typeof value === 'number' ||\n Array.isArray(value) ||\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n React.isValidElement<any>(value)\n ) {\n return { children: value } as Props;\n }\n if (value && typeof value !== 'object' && process.env.NODE_ENV !== 'production') {\n // TODO: would be nice to have a link to slot documentation in this error message\n // eslint-disable-next-line no-console\n console.error(/** #__DE-INDENT__ */ `\n @fluentui/react-utilities [slot.${resolveShorthand.name}]:\n A slot got an invalid value \"${value}\" (${typeof value}).\n A valid value for a slot is a slot shorthand or slot properties object.\n Slot shorthands can be strings, numbers, arrays or JSX elements\n `);\n }\n\n return value;\n}\n"],"names":["React","SLOT_ELEMENT_TYPE_SYMBOL","SLOT_RENDER_FUNCTION_SYMBOL","always","value","options","defaultProps","elementType","props","resolveShorthand","propsWithMetadata","children","optional","undefined","renderByDefault","Array","isArray","isValidElement","process","env","NODE_ENV","console","error","name"],"mappings":"AAOA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,wBAAwB,EAAEC,2BAA2B,QAAQ,cAAc;AASpF;;;;;;;CAOC,GACD,OAAO,SAASC,OACdC,KAA6C,EAC7CC,OAA2B;IAE3B,MAAM,EAAEC,YAAY,EAAEC,WAAW,EAAE,GAAGF;IAEtC,MAAMG,QAAQC,iBAAiBL;IAE/B;;;;;GAKC,GACD,MAAMM,oBAAoB;QACxB,GAAGJ,YAAY;QACf,GAAGE,KAAK;QACR,CAACP,yBAAyB,EAAEM;IAC9B;IAEA,IAAIC,SAAS,OAAOA,MAAMG,QAAQ,KAAK,YAAY;QACjDD,iBAAiB,CAACR,4BAA4B,GAAGM,MAAMG,QAAQ;QAC/DD,kBAAkBC,QAAQ,GAAGL,yBAAAA,mCAAAA,aAAcK,QAAQ;IACrD;IAEA,OAAOD;AACT;AAEA;;;;;;;;;;;;CAYC,GACD,OAAO,SAASE,SACdR,KAAoD,EACpDC,OAA2D;IAE3D,IAAID,UAAU,QAASA,UAAUS,aAAa,CAACR,QAAQS,eAAe,EAAG;QACvE,OAAOD;IACT;IACA,OAAOV,OAAOC,OAAOC;AACvB;AAEA;;;;CAIC,GACD,OAAO,SAASI,iBACdL,KAAiC;IAEjC,IACE,OAAOA,UAAU,YACjB,OAAOA,UAAU,YACjBW,MAAMC,OAAO,CAACZ,UACd,8DAA8D;IAC9DJ,MAAMiB,cAAc,CAAMb,QAC1B;QACA,OAAO;YAAEO,UAAUP;QAAM;IAC3B;IACA,IAAIA,SAAS,OAAOA,UAAU,YAAYc,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QAC/E,iFAAiF;QACjF,sCAAsC;QACtCC,QAAQC,KAAK,CAAuB,CAAC,gCACH,EAAEb,iBAAiBc,IAAI,CAAC;6BAC3B,EAAEnB,MAAM,GAAG,EAAE,OAAOA,MAAM;;+DAGzD,CAAC;IACH;IAEA,OAAOA;AACT"}
@@ -1,9 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { useEventCallback } from './useEventCallback';
3
- const DEFAULT_CONTAINS = (parent, child)=>{
4
- var _parent;
5
- return !!((_parent = parent) === null || _parent === void 0 ? void 0 : _parent.contains(child));
6
- };
3
+ const DEFAULT_CONTAINS = (parent, child)=>!!(parent === null || parent === void 0 ? void 0 : parent.contains(child));
7
4
  /**
8
5
  * @internal
9
6
  * Utility to perform checks where a click/touch event was made outside a component
@@ -36,8 +33,6 @@ const DEFAULT_CONTAINS = (parent, child)=>{
36
33
  isMouseDownInsideRef.current = refs.some((ref)=>contains(ref.current || null, ev.target));
37
34
  });
38
35
  React.useEffect(()=>{
39
- var // use capture phase because React can update DOM before the event bubbles to the document
40
- _element, _element1, _element2, _element3;
41
36
  if (disabled) {
42
37
  return;
43
38
  }
@@ -53,20 +48,20 @@ const DEFAULT_CONTAINS = (parent, child)=>{
53
48
  }
54
49
  listener(event);
55
50
  };
56
- (_element = element) === null || _element === void 0 ? void 0 : _element.addEventListener('click', conditionalHandler, true);
57
- (_element1 = element) === null || _element1 === void 0 ? void 0 : _element1.addEventListener('touchstart', conditionalHandler, true);
58
- (_element2 = element) === null || _element2 === void 0 ? void 0 : _element2.addEventListener('contextmenu', conditionalHandler, true);
59
- (_element3 = element) === null || _element3 === void 0 ? void 0 : _element3.addEventListener('mousedown', handleMouseDown, true);
51
+ // use capture phase because React can update DOM before the event bubbles to the document
52
+ element === null || element === void 0 ? void 0 : element.addEventListener('click', conditionalHandler, true);
53
+ element === null || element === void 0 ? void 0 : element.addEventListener('touchstart', conditionalHandler, true);
54
+ element === null || element === void 0 ? void 0 : element.addEventListener('contextmenu', conditionalHandler, true);
55
+ element === null || element === void 0 ? void 0 : element.addEventListener('mousedown', handleMouseDown, true);
60
56
  // Garbage collect this event after it's no longer useful to avoid memory leaks
61
57
  timeoutId.current = window.setTimeout(()=>{
62
58
  currentEvent = undefined;
63
59
  }, 1);
64
60
  return ()=>{
65
- var _element, _element1, _element2, _element3;
66
- (_element = element) === null || _element === void 0 ? void 0 : _element.removeEventListener('click', conditionalHandler, true);
67
- (_element1 = element) === null || _element1 === void 0 ? void 0 : _element1.removeEventListener('touchstart', conditionalHandler, true);
68
- (_element2 = element) === null || _element2 === void 0 ? void 0 : _element2.removeEventListener('contextmenu', conditionalHandler, true);
69
- (_element3 = element) === null || _element3 === void 0 ? void 0 : _element3.removeEventListener('mousedown', handleMouseDown, true);
61
+ element === null || element === void 0 ? void 0 : element.removeEventListener('click', conditionalHandler, true);
62
+ element === null || element === void 0 ? void 0 : element.removeEventListener('touchstart', conditionalHandler, true);
63
+ element === null || element === void 0 ? void 0 : element.removeEventListener('contextmenu', conditionalHandler, true);
64
+ element === null || element === void 0 ? void 0 : element.removeEventListener('mousedown', handleMouseDown, true);
70
65
  clearTimeout(timeoutId.current);
71
66
  currentEvent = undefined;
72
67
  };
@@ -111,14 +106,12 @@ const FUI_FRAME_EVENT = 'fuiframefocus';
111
106
  });
112
107
  // Adds listener to the custom iframe focus event
113
108
  React.useEffect(()=>{
114
- var _targetDocument;
115
109
  if (disabled) {
116
110
  return;
117
111
  }
118
- (_targetDocument = targetDocument) === null || _targetDocument === void 0 ? void 0 : _targetDocument.addEventListener(FUI_FRAME_EVENT, listener, true);
112
+ targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.addEventListener(FUI_FRAME_EVENT, listener, true);
119
113
  return ()=>{
120
- var _targetDocument;
121
- (_targetDocument = targetDocument) === null || _targetDocument === void 0 ? void 0 : _targetDocument.removeEventListener(FUI_FRAME_EVENT, listener, true);
114
+ targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener(FUI_FRAME_EVENT, listener, true);
122
115
  };
123
116
  }, [
124
117
  targetDocument,
@@ -127,14 +120,13 @@ const FUI_FRAME_EVENT = 'fuiframefocus';
127
120
  ]);
128
121
  // Starts polling for the active element
129
122
  React.useEffect(()=>{
130
- var _targetDocument_defaultView, _targetDocument;
123
+ var _targetDocument_defaultView;
131
124
  if (disabled) {
132
125
  return;
133
126
  }
134
- timeoutRef.current = (_targetDocument = targetDocument) === null || _targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = _targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.setInterval(()=>{
135
- var _targetDocument, _activeElement, _activeElement1;
136
- const activeElement = (_targetDocument = targetDocument) === null || _targetDocument === void 0 ? void 0 : _targetDocument.activeElement;
137
- if (((_activeElement = activeElement) === null || _activeElement === void 0 ? void 0 : _activeElement.tagName) === 'IFRAME' || ((_activeElement1 = activeElement) === null || _activeElement1 === void 0 ? void 0 : _activeElement1.tagName) === 'WEBVIEW') {
127
+ timeoutRef.current = targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.setInterval(()=>{
128
+ const activeElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement;
129
+ if ((activeElement === null || activeElement === void 0 ? void 0 : activeElement.tagName) === 'IFRAME' || (activeElement === null || activeElement === void 0 ? void 0 : activeElement.tagName) === 'WEBVIEW') {
138
130
  const event = new CustomEvent(FUI_FRAME_EVENT, {
139
131
  bubbles: true
140
132
  });
@@ -142,8 +134,8 @@ const FUI_FRAME_EVENT = 'fuiframefocus';
142
134
  }
143
135
  }, pollDuration);
144
136
  return ()=>{
145
- var _targetDocument_defaultView, _targetDocument;
146
- (_targetDocument = targetDocument) === null || _targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = _targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.clearTimeout(timeoutRef.current);
137
+ var _targetDocument_defaultView;
138
+ targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.clearTimeout(timeoutRef.current);
147
139
  };
148
140
  }, [
149
141
  targetDocument,
@@ -1 +1 @@
1
- {"version":3,"sources":["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 * Disables custom focus event listeners for iframes\n */\n disabledFocusOnIframe?: boolean;\n\n /**\n * Called if the click is outside the element refs\n */\n callback: (ev: MouseEvent | TouchEvent) => void;\n};\n\nconst DEFAULT_CONTAINS: UseOnClickOrScrollOutsideOptions['contains'] = (parent, child) => !!parent?.contains(child);\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, disabledFocusOnIframe, contains = DEFAULT_CONTAINS } = options;\n const timeoutId = React.useRef<number | undefined>(undefined);\n\n useIFrameFocus({ element, disabled: disabledFocusOnIframe || disabled, callback, refs, contains });\n\n const isMouseDownInsideRef = React.useRef(false);\n const listener = useEventCallback((ev: MouseEvent | TouchEvent) => {\n if (isMouseDownInsideRef.current) {\n isMouseDownInsideRef.current = false;\n return;\n }\n\n const target = ev.composedPath()[0] as HTMLElement;\n const isOutside = refs.every(ref => !contains(ref.current || null, target));\n\n if (isOutside && !disabled) {\n callback(ev);\n }\n });\n\n const handleMouseDown = useEventCallback((ev: MouseEvent) => {\n // Selecting text from inside to outside will rigger click event.\n // In this case click event target is outside but mouse down event target is inside.\n // And this click event should be considered as inside click.\n isMouseDownInsideRef.current = refs.some(ref => contains(ref.current || null, ev.target as HTMLElement));\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 element?.addEventListener('mousedown', handleMouseDown, 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 element?.removeEventListener('mousedown', handleMouseDown, true);\n\n clearTimeout(timeoutId.current);\n currentEvent = undefined;\n };\n }, [listener, element, disabled, handleMouseDown]);\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\n extends Pick<UseOnClickOrScrollOutsideOptions, 'disabled' | 'element' | 'callback' | 'contains' | 'refs'> {\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 = DEFAULT_CONTAINS,\n pollDuration = 1000,\n refs,\n } = options;\n const timeoutRef = React.useRef<number>();\n\n const listener = useEventCallback((e: Event) => {\n const isOutside = refs.every(ref => !contains(ref.current || null, e.target as HTMLElement));\n\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"],"names":["React","useEventCallback","DEFAULT_CONTAINS","parent","child","contains","useOnClickOutside","options","refs","callback","element","disabled","disabledFocusOnIframe","timeoutId","useRef","undefined","useIFrameFocus","isMouseDownInsideRef","listener","ev","current","target","composedPath","isOutside","every","ref","handleMouseDown","some","useEffect","currentEvent","getWindowEvent","window","conditionalHandler","event","addEventListener","setTimeout","removeEventListener","clearTimeout","ownerDocument","defaultView","FUI_FRAME_EVENT","targetDocument","pollDuration","timeoutRef","e","setInterval","activeElement","tagName","CustomEvent","bubbles","dispatchEvent"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,gBAAgB,QAAQ,qBAAqB;AAuCtD,MAAMC,mBAAiE,CAACC,QAAQC;QAAYD;WAAF,CAAC,GAACA,UAAAA,oBAAAA,8BAAAA,QAAQE,QAAQ,CAACD;;AAE7G;;;CAGC,GACD,OAAO,MAAME,oBAAoB,CAACC;IAChC,MAAM,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,qBAAqB,EAAEP,WAAWH,gBAAgB,EAAE,GAAGK;IAClG,MAAMM,YAAYb,MAAMc,MAAM,CAAqBC;IAEnDC,eAAe;QAAEN;QAASC,UAAUC,yBAAyBD;QAAUF;QAAUD;QAAMH;IAAS;IAEhG,MAAMY,uBAAuBjB,MAAMc,MAAM,CAAC;IAC1C,MAAMI,WAAWjB,iBAAiB,CAACkB;QACjC,IAAIF,qBAAqBG,OAAO,EAAE;YAChCH,qBAAqBG,OAAO,GAAG;YAC/B;QACF;QAEA,MAAMC,SAASF,GAAGG,YAAY,EAAE,CAAC,EAAE;QACnC,MAAMC,YAAYf,KAAKgB,KAAK,CAACC,CAAAA,MAAO,CAACpB,SAASoB,IAAIL,OAAO,IAAI,MAAMC;QAEnE,IAAIE,aAAa,CAACZ,UAAU;YAC1BF,SAASU;QACX;IACF;IAEA,MAAMO,kBAAkBzB,iBAAiB,CAACkB;QACxC,iEAAiE;QACj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;QAEAgC,WAAWvB,OAAO,IAAGqB,kBAAAA,4BAAAA,uCAAAA,8BAAAA,gBAAgBF,WAAW,cAA3BE,kDAAAA,4BAA6BI,WAAW,CAAC;gBACtCJ,iBAElBK,gBAAuCA;YAF3C,MAAMA,iBAAgBL,kBAAAA,4BAAAA,sCAAAA,gBAAgBK,aAAa;YAEnD,IAAIA,EAAAA,iBAAAA,2BAAAA,qCAAAA,eAAeC,OAAO,MAAK,YAAYD,EAAAA,kBAAAA,2BAAAA,sCAAAA,gBAAeC,OAAO,MAAK,WAAW;gBAC/E,MAAMd,QAAQ,IAAIe,YAAYR,iBAAiB;oBAAES,SAAS;gBAAK;gBAC/DH,cAAcI,aAAa,CAACjB;YAC9B;QACF,GAAGS;QAEH,OAAO;gBACLD,6BAAAA;aAAAA,kBAAAA,4BAAAA,uCAAAA,8BAAAA,gBAAgBF,WAAW,cAA3BE,kDAAAA,4BAA6BJ,YAAY,CAACM,WAAWvB,OAAO;QAC9D;IACF,GAAG;QAACqB;QAAgB9B;QAAU+B;KAAa;AAC7C"}
1
+ {"version":3,"sources":["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 * Disables custom focus event listeners for iframes\n */\n disabledFocusOnIframe?: boolean;\n\n /**\n * Called if the click is outside the element refs\n */\n callback: (ev: MouseEvent | TouchEvent) => void;\n};\n\nconst DEFAULT_CONTAINS: UseOnClickOrScrollOutsideOptions['contains'] = (parent, child) => !!parent?.contains(child);\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, disabledFocusOnIframe, contains = DEFAULT_CONTAINS } = options;\n const timeoutId = React.useRef<number | undefined>(undefined);\n\n useIFrameFocus({ element, disabled: disabledFocusOnIframe || disabled, callback, refs, contains });\n\n const isMouseDownInsideRef = React.useRef(false);\n const listener = useEventCallback((ev: MouseEvent | TouchEvent) => {\n if (isMouseDownInsideRef.current) {\n isMouseDownInsideRef.current = false;\n return;\n }\n\n const target = ev.composedPath()[0] as HTMLElement;\n const isOutside = refs.every(ref => !contains(ref.current || null, target));\n\n if (isOutside && !disabled) {\n callback(ev);\n }\n });\n\n const handleMouseDown = useEventCallback((ev: MouseEvent) => {\n // Selecting text from inside to outside will rigger click event.\n // In this case click event target is outside but mouse down event target is inside.\n // And this click event should be considered as inside click.\n isMouseDownInsideRef.current = refs.some(ref => contains(ref.current || null, ev.target as HTMLElement));\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 element?.addEventListener('mousedown', handleMouseDown, 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 element?.removeEventListener('mousedown', handleMouseDown, true);\n\n clearTimeout(timeoutId.current);\n currentEvent = undefined;\n };\n }, [listener, element, disabled, handleMouseDown]);\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\n extends Pick<UseOnClickOrScrollOutsideOptions, 'disabled' | 'element' | 'callback' | 'contains' | 'refs'> {\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 = DEFAULT_CONTAINS,\n pollDuration = 1000,\n refs,\n } = options;\n const timeoutRef = React.useRef<number>();\n\n const listener = useEventCallback((e: Event) => {\n const isOutside = refs.every(ref => !contains(ref.current || null, e.target as HTMLElement));\n\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"],"names":["React","useEventCallback","DEFAULT_CONTAINS","parent","child","contains","useOnClickOutside","options","refs","callback","element","disabled","disabledFocusOnIframe","timeoutId","useRef","undefined","useIFrameFocus","isMouseDownInsideRef","listener","ev","current","target","composedPath","isOutside","every","ref","handleMouseDown","some","useEffect","currentEvent","getWindowEvent","window","conditionalHandler","event","addEventListener","setTimeout","removeEventListener","clearTimeout","ownerDocument","defaultView","FUI_FRAME_EVENT","targetDocument","pollDuration","timeoutRef","e","setInterval","activeElement","tagName","CustomEvent","bubbles","dispatchEvent"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,gBAAgB,QAAQ,qBAAqB;AAuCtD,MAAMC,mBAAiE,CAACC,QAAQC,QAAU,CAAC,EAACD,mBAAAA,6BAAAA,OAAQE,QAAQ,CAACD;AAE7G;;;CAGC,GACD,OAAO,MAAME,oBAAoB,CAACC;IAChC,MAAM,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,qBAAqB,EAAEP,WAAWH,gBAAgB,EAAE,GAAGK;IAClG,MAAMM,YAAYb,MAAMc,MAAM,CAAqBC;IAEnDC,eAAe;QAAEN;QAASC,UAAUC,yBAAyBD;QAAUF;QAAUD;QAAMH;IAAS;IAEhG,MAAMY,uBAAuBjB,MAAMc,MAAM,CAAC;IAC1C,MAAMI,WAAWjB,iBAAiB,CAACkB;QACjC,IAAIF,qBAAqBG,OAAO,EAAE;YAChCH,qBAAqBG,OAAO,GAAG;YAC/B;QACF;QAEA,MAAMC,SAASF,GAAGG,YAAY,EAAE,CAAC,EAAE;QACnC,MAAMC,YAAYf,KAAKgB,KAAK,CAACC,CAAAA,M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;QACF;QAEAgC,WAAWvB,OAAO,GAAGqB,2BAAAA,sCAAAA,8BAAAA,eAAgBF,WAAW,cAA3BE,kDAAAA,4BAA6BI,WAAW,CAAC;YAC5D,MAAMC,gBAAgBL,2BAAAA,qCAAAA,eAAgBK,aAAa;YAEnD,IAAIA,CAAAA,0BAAAA,oCAAAA,cAAeC,OAAO,MAAK,YAAYD,CAAAA,0BAAAA,oCAAAA,cAAeC,OAAO,MAAK,WAAW;gBAC/E,MAAMd,QAAQ,IAAIe,YAAYR,iBAAiB;oBAAES,SAAS;gBAAK;gBAC/DH,cAAcI,aAAa,CAACjB;YAC9B;QACF,GAAGS;QAEH,OAAO;gBACLD;YAAAA,2BAAAA,sCAAAA,8BAAAA,eAAgBF,WAAW,cAA3BE,kDAAAA,4BAA6BJ,YAAY,CAACM,WAAWvB,OAAO;QAC9D;IACF,GAAG;QAACqB;QAAgB9B;QAAU+B;KAAa;AAC7C"}
@@ -6,10 +6,7 @@ import { useEventCallback } from './useEventCallback';
6
6
  */ export const useOnScrollOutside = (options)=>{
7
7
  const { refs, callback, element, disabled, contains: containsProp } = options;
8
8
  const listener = useEventCallback((ev)=>{
9
- const contains = containsProp || ((parent, child)=>{
10
- var _parent;
11
- return !!((_parent = parent) === null || _parent === void 0 ? void 0 : _parent.contains(child));
12
- });
9
+ const contains = containsProp || ((parent, child)=>!!(parent === null || parent === void 0 ? void 0 : parent.contains(child)));
13
10
  const target = ev.composedPath()[0];
14
11
  const isOutside = refs.every((ref)=>!contains(ref.current || null, target));
15
12
  if (isOutside && !disabled) {
@@ -17,19 +14,17 @@ import { useEventCallback } from './useEventCallback';
17
14
  }
18
15
  });
19
16
  React.useEffect(()=>{
20
- var _element, _element1, // use capture phase because scroll does not bubble
21
- _element2;
22
17
  if (disabled) {
23
18
  return;
24
19
  }
25
- (_element = element) === null || _element === void 0 ? void 0 : _element.addEventListener('wheel', listener);
26
- (_element1 = element) === null || _element1 === void 0 ? void 0 : _element1.addEventListener('touchmove', listener);
27
- (_element2 = element) === null || _element2 === void 0 ? void 0 : _element2.addEventListener('scroll', listener, true);
20
+ element === null || element === void 0 ? void 0 : element.addEventListener('wheel', listener);
21
+ element === null || element === void 0 ? void 0 : element.addEventListener('touchmove', listener);
22
+ // use capture phase because scroll does not bubble
23
+ element === null || element === void 0 ? void 0 : element.addEventListener('scroll', listener, true);
28
24
  return ()=>{
29
- var _element, _element1, _element2;
30
- (_element = element) === null || _element === void 0 ? void 0 : _element.removeEventListener('wheel', listener);
31
- (_element1 = element) === null || _element1 === void 0 ? void 0 : _element1.removeEventListener('touchmove', listener);
32
- (_element2 = element) === null || _element2 === void 0 ? void 0 : _element2.removeEventListener('scroll', listener, true);
25
+ element === null || element === void 0 ? void 0 : element.removeEventListener('wheel', listener);
26
+ element === null || element === void 0 ? void 0 : element.removeEventListener('touchmove', listener);
27
+ element === null || element === void 0 ? void 0 : element.removeEventListener('scroll', listener, true);
33
28
  };
34
29
  }, [
35
30
  listener,
@@ -1 +1 @@
1
- {"version":3,"sources":["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: Event) => {\n const contains: UseOnClickOrScrollOutsideOptions['contains'] =\n containsProp || ((parent, child) => !!parent?.contains(child));\n\n const target = ev.composedPath()[0] as HTMLElement;\n const isOutside = refs.every(ref => !contains(ref.current || null, target));\n\n if (isOutside && !disabled) {\n callback(ev as MouseEvent | TouchEvent);\n }\n });\n\n React.useEffect(() => {\n if (disabled) {\n return;\n }\n\n element?.addEventListener('wheel', listener);\n element?.addEventListener('touchmove', listener);\n // use capture phase because scroll does not bubble\n element?.addEventListener('scroll', listener, true);\n\n return () => {\n element?.removeEventListener('wheel', listener);\n element?.removeEventListener('touchmove', listener);\n element?.removeEventListener('scroll', listener, true);\n };\n }, [listener, element, disabled]);\n};\n"],"names":["React","useEventCallback","useOnScrollOutside","options","refs","callback","element","disabled","contains","containsProp","listener","ev","parent","child","target","composedPath","isOutside","every","ref","current","useEffect","addEventListener","removeEventListener"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,gBAAgB,QAAQ,qBAAqB;AAGtD;;;CAGC,GACD,OAAO,MAAMC,qBAAqB,CAACC;IACjC,MAAM,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,UAAUC,YAAY,EAAE,GAAGN;IAEtE,MAAMO,WAAWT,iBAAiB,CAACU;QACjC,MAAMH,WACJC,gBAAiB,CAAA,CAACG,QAAQC;gBAAYD;mBAAF,CAAC,GAACA,UAAAA,oBAAAA,8BAAAA,QAAQJ,QAAQ,CAACK;SAAK;QAE9D,MAAMC,SAASH,GAAGI,YAAY,EAAE,CAAC,EAAE;QACnC,MAAMC,YAAYZ,KAAKa,KAAK,CAACC,CAAAA,MAAO,CAACV,SAASU,IAAIC,OAAO,IAAI,MAAML;QAEnE,IAAIE,aAAa,CAACT,UAAU;YAC1BF,SAASM;QACX;IACF;IAEAX,MAAMoB,SAAS,CAAC;YAKdd,UACAA,WACA,mDAAmD;QACnDA;QAPA,IAAIC,UAAU;YACZ;QACF;SAEAD,WAAAA,qBAAAA,+BAAAA,SAASe,gBAAgB,CAAC,SAASX;SACnCJ,YAAAA,qBAAAA,gCAAAA,UAASe,gBAAgB,CAAC,aAAaX;SAEvCJ,YAAAA,qBAAAA,gCAAAA,UAASe,gBAAgB,CAAC,UAAUX,UAAU;QAE9C,OAAO;gBACLJ,UACAA,WACAA;aAFAA,WAAAA,qBAAAA,+BAAAA,SAASgB,mBAAmB,CAAC,SAASZ;aACtCJ,YAAAA,qBAAAA,gCAAAA,UAASgB,mBAAmB,CAAC,aAAaZ;aAC1CJ,YAAAA,qBAAAA,gCAAAA,UAASgB,mBAAmB,CAAC,UAAUZ,UAAU;QACnD;IACF,GAAG;QAACA;QAAUJ;QAASC;KAAS;AAClC,EAAE"}
1
+ {"version":3,"sources":["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: Event) => {\n const contains: UseOnClickOrScrollOutsideOptions['contains'] =\n containsProp || ((parent, child) => !!parent?.contains(child));\n\n const target = ev.composedPath()[0] as HTMLElement;\n const isOutside = refs.every(ref => !contains(ref.current || null, target));\n\n if (isOutside && !disabled) {\n callback(ev as MouseEvent | TouchEvent);\n }\n });\n\n React.useEffect(() => {\n if (disabled) {\n return;\n }\n\n element?.addEventListener('wheel', listener);\n element?.addEventListener('touchmove', listener);\n // use capture phase because scroll does not bubble\n element?.addEventListener('scroll', listener, true);\n\n return () => {\n element?.removeEventListener('wheel', listener);\n element?.removeEventListener('touchmove', listener);\n element?.removeEventListener('scroll', listener, true);\n };\n }, [listener, element, disabled]);\n};\n"],"names":["React","useEventCallback","useOnScrollOutside","options","refs","callback","element","disabled","contains","containsProp","listener","ev","parent","child","target","composedPath","isOutside","every","ref","current","useEffect","addEventListener","removeEventListener"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,gBAAgB,QAAQ,qBAAqB;AAGtD;;;CAGC,GACD,OAAO,MAAMC,qBAAqB,CAACC;IACjC,MAAM,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,UAAUC,YAAY,EAAE,GAAGN;IAEtE,MAAMO,WAAWT,iBAAiB,CAACU;QACjC,MAAMH,WACJC,gBAAiB,CAAA,CAACG,QAAQC,QAAU,CAAC,EAACD,mBAAAA,6BAAAA,OAAQJ,QAAQ,CAACK,OAAK;QAE9D,MAAMC,SAASH,GAAGI,YAAY,EAAE,CAAC,EAAE;QACnC,MAAMC,YAAYZ,KAAKa,KAAK,CAACC,CAAAA,MAAO,CAACV,SAASU,IAAIC,OAAO,IAAI,MAAML;QAEnE,IAAIE,aAAa,CAACT,UAAU;YAC1BF,SAASM;QACX;IACF;IAEAX,MAAMoB,SAAS,CAAC;QACd,IAAIb,UAAU;YACZ;QACF;QAEAD,oBAAAA,8BAAAA,QAASe,gBAAgB,CAAC,SAASX;QACnCJ,oBAAAA,8BAAAA,QAASe,gBAAgB,CAAC,aAAaX;QACvC,mDAAmD;QACnDJ,oBAAAA,8BAAAA,QAASe,gBAAgB,CAAC,UAAUX,UAAU;QAE9C,OAAO;YACLJ,oBAAAA,8BAAAA,QAASgB,mBAAmB,CAAC,SAASZ;YACtCJ,oBAAAA,8BAAAA,QAASgB,mBAAmB,CAAC,aAAaZ;YAC1CJ,oBAAAA,8BAAAA,QAASgB,mBAAmB,CAAC,UAAUZ,UAAU;QACnD;IACF,GAAG;QAACA;QAAUJ;QAASC;KAAS;AAClC,EAAE"}
@@ -12,8 +12,8 @@ function useSelectionState(params) {
12
12
  ])
13
13
  });
14
14
  const changeSelection = (event, nextSelectedItems)=>{
15
- var _params_onSelectionChange, _params;
16
- (_params_onSelectionChange = (_params = params).onSelectionChange) === null || _params_onSelectionChange === void 0 ? void 0 : _params_onSelectionChange.call(_params, event, {
15
+ var _params_onSelectionChange;
16
+ (_params_onSelectionChange = params.onSelectionChange) === null || _params_onSelectionChange === void 0 ? void 0 : _params_onSelectionChange.call(params, event, {
17
17
  selectedItems: nextSelectedItems
18
18
  });
19
19
  setSelected(nextSelectedItems);
@@ -25,7 +25,6 @@ function useSelectionState(params) {
25
25
  }
26
26
  function useSingleSelection(params) {
27
27
  const [selected, changeSelection] = useSelectionState(params);
28
- var _selected_has;
29
28
  const methods = {
30
29
  deselectItem: (event)=>changeSelection(event, new Set()),
31
30
  selectItem: (event, itemId)=>changeSelection(event, new Set([
@@ -40,7 +39,10 @@ function useSingleSelection(params) {
40
39
  itemId
41
40
  ])),
42
41
  clearItems: (event)=>changeSelection(event, new Set()),
43
- isSelected: (itemId)=>(_selected_has = selected.has(itemId)) !== null && _selected_has !== void 0 ? _selected_has : false
42
+ isSelected: (itemId)=>{
43
+ var _selected_has;
44
+ return (_selected_has = selected.has(itemId)) !== null && _selected_has !== void 0 ? _selected_has : false;
45
+ }
44
46
  };
45
47
  return [
46
48
  selected,
@@ -1 +1 @@
1
- {"version":3,"sources":["useSelection.ts"],"sourcesContent":["import * as React from 'react';\nimport { SelectionHookParams, SelectionItemId, SelectionMethods } from './types';\nimport { useControllableState } from '../hooks/useControllableState';\nimport { createSetFromIterable } from '../utils/createSetFromIterable';\n\nfunction useSelectionState(params: Omit<SelectionHookParams, 'selectionMode'>) {\n const [selected, setSelected] = useControllableState<Set<SelectionItemId>>({\n initialState: new Set(),\n defaultState: React.useMemo(\n () => params.defaultSelectedItems && createSetFromIterable(params.defaultSelectedItems),\n [params.defaultSelectedItems],\n ),\n state: React.useMemo(\n () => params.selectedItems && createSetFromIterable(params.selectedItems),\n [params.selectedItems],\n ),\n });\n const changeSelection = (event: React.SyntheticEvent, nextSelectedItems: Set<SelectionItemId>) => {\n params.onSelectionChange?.(event, { selectedItems: nextSelectedItems });\n setSelected(nextSelectedItems);\n };\n return [selected, changeSelection] as const;\n}\n\nfunction useSingleSelection(params: Omit<SelectionHookParams, 'selectionMode'>) {\n const [selected, changeSelection] = useSelectionState(params);\n const methods: SelectionMethods = {\n deselectItem: event => changeSelection(event, new Set()),\n selectItem: (event, itemId) => changeSelection(event, new Set([itemId])),\n toggleAllItems: () => {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('[react-utilities]: `toggleAllItems` should not be used in single selection mode');\n }\n },\n toggleItem: (event, itemId) => changeSelection(event, new Set([itemId])),\n clearItems: event => changeSelection(event, new Set()),\n isSelected: itemId => selected.has(itemId) ?? false,\n };\n return [selected, methods] as const;\n}\n\nfunction useMultipleSelection(params: Omit<SelectionHookParams, 'selectionMode'>) {\n const [selected, changeSelection] = useSelectionState(params);\n const methods: SelectionMethods = {\n toggleItem: (event, itemId) => {\n const nextSelectedItems = new Set(selected);\n if (selected.has(itemId)) {\n nextSelectedItems.delete(itemId);\n } else {\n nextSelectedItems.add(itemId);\n }\n changeSelection(event, nextSelectedItems);\n },\n selectItem: (event, itemId) => {\n const nextSelectedItems = new Set(selected);\n nextSelectedItems.add(itemId);\n changeSelection(event, nextSelectedItems);\n },\n deselectItem: (event, itemId) => {\n const nextSelectedItems = new Set(selected);\n nextSelectedItems.delete(itemId);\n changeSelection(event, nextSelectedItems);\n },\n clearItems: event => {\n changeSelection(event, new Set());\n },\n isSelected: itemId => selected.has(itemId),\n toggleAllItems: (event, itemIds) => {\n const allItemsSelected = itemIds.every(itemId => selected.has(itemId));\n const nextSelectedItems = new Set(selected);\n if (allItemsSelected) {\n nextSelectedItems.clear();\n } else {\n itemIds.forEach(itemId => nextSelectedItems.add(itemId));\n }\n changeSelection(event, nextSelectedItems);\n },\n };\n return [selected, methods] as const;\n}\n\nexport function useSelection(params: SelectionHookParams) {\n if (params.selectionMode === 'multiselect') {\n // selectionMode is a static value, so we can safely ignore rules-of-hooks\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useMultipleSelection(params);\n }\n // selectionMode is a static value, so we can safely ignore rules-of-hooks\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useSingleSelection(params);\n}\n"],"names":["React","useControllableState","createSetFromIterable","useSelectionState","params","selected","setSelected","initialState","Set","defaultState","useMemo","defaultSelectedItems","state","selectedItems","changeSelection","event","nextSelectedItems","onSelectionChange","useSingleSelection","methods","deselectItem","selectItem","itemId","toggleAllItems","process","env","NODE_ENV","Error","toggleItem","clearItems","isSelected","has","useMultipleSelection","delete","add","itemIds","allItemsSelected","every","clear","forEach","useSelection","selectionMode"],"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Oc,mBAAmBd;AAC5B"}
1
+ {"version":3,"sources":["useSelection.ts"],"sourcesContent":["import * as React from 'react';\nimport { SelectionHookParams, SelectionItemId, SelectionMethods } from './types';\nimport { useControllableState } from '../hooks/useControllableState';\nimport { createSetFromIterable } from '../utils/createSetFromIterable';\n\nfunction useSelectionState(params: Omit<SelectionHookParams, 'selectionMode'>) {\n const [selected, setSelected] = useControllableState<Set<SelectionItemId>>({\n initialState: new Set(),\n defaultState: React.useMemo(\n () => params.defaultSelectedItems && createSetFromIterable(params.defaultSelectedItems),\n [params.defaultSelectedItems],\n ),\n state: React.useMemo(\n () => params.selectedItems && createSetFromIterable(params.selectedItems),\n [params.selectedItems],\n ),\n });\n const changeSelection = (event: React.SyntheticEvent, nextSelectedItems: Set<SelectionItemId>) => {\n params.onSelectionChange?.(event, { selectedItems: nextSelectedItems });\n setSelected(nextSelectedItems);\n };\n return [selected, changeSelection] as const;\n}\n\nfunction useSingleSelection(params: Omit<SelectionHookParams, 'selectionMode'>) {\n const [selected, changeSelection] = useSelectionState(params);\n const methods: SelectionMethods = {\n deselectItem: event => changeSelection(event, new Set()),\n selectItem: (event, itemId) => changeSelection(event, new Set([itemId])),\n toggleAllItems: () => {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('[react-utilities]: `toggleAllItems` should not be used in single selection mode');\n }\n },\n toggleItem: (event, itemId) => changeSelection(event, new Set([itemId])),\n clearItems: event => changeSelection(event, new Set()),\n isSelected: itemId => selected.has(itemId) ?? false,\n };\n return [selected, methods] as const;\n}\n\nfunction useMultipleSelection(params: Omit<SelectionHookParams, 'selectionMode'>) {\n const [selected, changeSelection] = useSelectionState(params);\n const methods: SelectionMethods = {\n toggleItem: (event, itemId) => {\n const nextSelectedItems = new Set(selected);\n if (selected.has(itemId)) {\n nextSelectedItems.delete(itemId);\n } else {\n nextSelectedItems.add(itemId);\n }\n changeSelection(event, nextSelectedItems);\n },\n selectItem: (event, itemId) => {\n const nextSelectedItems = new Set(selected);\n nextSelectedItems.add(itemId);\n changeSelection(event, nextSelectedItems);\n },\n deselectItem: (event, itemId) => {\n const nextSelectedItems = new Set(selected);\n nextSelectedItems.delete(itemId);\n changeSelection(event, nextSelectedItems);\n },\n clearItems: event => {\n changeSelection(event, new Set());\n },\n isSelected: itemId => selected.has(itemId),\n toggleAllItems: (event, itemIds) => {\n const allItemsSelected = itemIds.every(itemId => selected.has(itemId));\n const nextSelectedItems = new Set(selected);\n if (allItemsSelected) {\n nextSelectedItems.clear();\n } else {\n itemIds.forEach(itemId => nextSelectedItems.add(itemId));\n }\n changeSelection(event, nextSelectedItems);\n },\n };\n return [selected, methods] as const;\n}\n\nexport function useSelection(params: SelectionHookParams) {\n if (params.selectionMode === 'multiselect') {\n // selectionMode is a static value, so we can safely ignore rules-of-hooks\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useMultipleSelection(params);\n }\n // selectionMode is a static value, so we can safely ignore rules-of-hooks\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useSingleSelection(params);\n}\n"],"names":["React","useControllableState","createSetFromIterable","useSelectionState","params","selected","setSelected","initialState","Set","defaultState","useMemo","defaultSelectedItems","state","selectedItems","changeSelection","event","nextSelectedItems","onSelectionChange","useSingleSelection","methods","deselectItem","selectItem","itemId","toggleAllItems","process","env","NODE_ENV","Error","toggleItem","clearItems","isSelected","has","useMultipleSelection","delete","add","itemIds","allItemsSelected","every","clear","forEach","useSelection","selectionMode"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAE/B,SAASC,oBAAoB,QAAQ,gCAAgC;AACrE,SAASC,qBAAqB,QAAQ,iCAAiC;AAEvE,SAASC,kBAAkBC,MAAkD;IAC3E,MAAM,CAACC,UAAUC,YAAY,GAAGL,qBAA2C;QACzEM,cAAc,IAAIC;QAClBC,cAAcT,MAAMU,OAAO,CACzB,IAAMN,OAAOO,oBAAoB,IAAIT,sBAAsBE,OAAOO,oBAAoB,GACtF;YAACP,OAAOO,oBAAoB;SAAC;QAE/BC,OAAOZ,M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AAY,CAACN,OAAOO;YAClB,MAAMN,oBAAoB,IAAIR,IAAIH;YAClCW,kBAAkBkB,GAAG,CAACZ;YACtBR,gBAAgBC,OAAOC;QACzB;QACAI,cAAc,CAACL,OAAOO;YACpB,MAAMN,oBAAoB,IAAIR,IAAIH;YAClCW,kBAAkBiB,MAAM,CAACX;YACzBR,gBAAgBC,OAAOC;QACzB;QACAa,YAAYd,CAAAA;YACVD,gBAAgBC,OAAO,IAAIP;QAC7B;QACAsB,YAAYR,CAAAA,SAAUjB,SAAS0B,GAAG,CAACT;QACnCC,gBAAgB,CAACR,OAAOoB;YACtB,MAAMC,mBAAmBD,QAAQE,KAAK,CAACf,CAAAA,SAAUjB,SAAS0B,GAAG,CAACT;YAC9D,MAAMN,oBAAoB,IAAIR,IAAIH;YAClC,IAAI+B,kBAAkB;gBACpBpB,kBAAkBsB,KAAK;YACzB,OAAO;gBACLH,QAAQI,OAAO,CAACjB,CAAAA,SAAUN,kBAAkBkB,GAAG,CAACZ;YAClD;YACAR,gBAAgBC,OAAOC;QACzB;IACF;IACA,OAAO;QAACX;QAAUc;KAAQ;AAC5B;AAEA,OAAO,SAASqB,aAAapC,MAA2B;IACtD,IAAIA,OAAOqC,aAAa,KAAK,eAAe;QAC1C,0EAA0E;QAC1E,sDAAsD;QACtD,OAAOT,qBAAqB5B;IAC9B;IACA,0EAA0E;IAC1E,sDAAsD;IACtD,OAAOc,mBAAmBd;AAC5B"}
@@ -12,8 +12,8 @@
12
12
  * ```
13
13
  *
14
14
  */ export function isHTMLElement(element, options) {
15
- var _typedElement_ownerDocument, _typedElement, _options;
15
+ var _typedElement_ownerDocument;
16
16
  const typedElement = element;
17
17
  var _options_constructorName;
18
- return Boolean(((_typedElement = typedElement) === null || _typedElement === void 0 ? void 0 : (_typedElement_ownerDocument = _typedElement.ownerDocument) === null || _typedElement_ownerDocument === void 0 ? void 0 : _typedElement_ownerDocument.defaultView) && typedElement instanceof typedElement.ownerDocument.defaultView[(_options_constructorName = (_options = options) === null || _options === void 0 ? void 0 : _options.constructorName) !== null && _options_constructorName !== void 0 ? _options_constructorName : 'HTMLElement']);
18
+ return Boolean((typedElement === null || typedElement === void 0 ? void 0 : (_typedElement_ownerDocument = typedElement.ownerDocument) === null || _typedElement_ownerDocument === void 0 ? void 0 : _typedElement_ownerDocument.defaultView) && typedElement instanceof typedElement.ownerDocument.defaultView[(_options_constructorName = options === null || options === void 0 ? void 0 : options.constructorName) !== null && _options_constructorName !== void 0 ? _options_constructorName : 'HTMLElement']);
19
19
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["isHTMLElement.ts"],"sourcesContent":["/**\n * Verifies if a given node is an HTMLElement,\n * this method works seamlessly with frames and elements from different documents\n *\n * This is preferred over simply using `instanceof`.\n * Since `instanceof` might be problematic while operating with [multiple realms](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof#instanceof_and_multiple_realms)\n *\n * @example\n * ```ts\n * isHTMLElement(event.target) && event.target.focus()\n * isHTMLElement(event.target, {constructorName: 'HTMLInputElement'}) && event.target.value // some value\n * ```\n *\n */\nexport function isHTMLElement<ConstructorName extends HTMLElementConstructorName = 'HTMLElement'>(\n element?: unknown,\n options?: {\n /**\n * Can be used to provide a custom constructor instead of `HTMLElement`,\n * Like `HTMLInputElement` for example.\n */\n constructorName?: ConstructorName;\n },\n): element is InstanceType<(typeof globalThis)[ConstructorName]> {\n const typedElement = element as Node | null | undefined;\n return Boolean(\n typedElement?.ownerDocument?.defaultView &&\n typedElement instanceof typedElement.ownerDocument.defaultView[options?.constructorName ?? 'HTMLElement'],\n );\n}\n\n/**\n * @internal\n */\nexport type HTMLElementConstructorName =\n | 'HTMLElement'\n | 'HTMLAnchorElement'\n | 'HTMLAreaElement'\n | 'HTMLAudioElement'\n | 'HTMLBaseElement'\n | 'HTMLBodyElement'\n | 'HTMLBRElement'\n | 'HTMLButtonElement'\n | 'HTMLCanvasElement'\n | 'HTMLDataElement'\n | 'HTMLDataListElement'\n | 'HTMLDetailsElement'\n // NOTE: dialog is not supported in safari 14, also it was removed from lib-dom starting typescript 4.4\n // | 'HTMLDialogElement'\n | 'HTMLDivElement'\n | 'HTMLDListElement'\n | 'HTMLEmbedElement'\n | 'HTMLFieldSetElement'\n | 'HTMLFormElement'\n | 'HTMLHeadingElement'\n | 'HTMLHeadElement'\n | 'HTMLHRElement'\n | 'HTMLHtmlElement'\n | 'HTMLIFrameElement'\n | 'HTMLImageElement'\n | 'HTMLInputElement'\n | 'HTMLModElement'\n | 'HTMLLabelElement'\n | 'HTMLLegendElement'\n | 'HTMLLIElement'\n | 'HTMLLinkElement'\n | 'HTMLMapElement'\n | 'HTMLMetaElement'\n | 'HTMLMeterElement'\n | 'HTMLObjectElement'\n | 'HTMLOListElement'\n | 'HTMLOptGroupElement'\n | 'HTMLOptionElement'\n | 'HTMLOutputElement'\n | 'HTMLParagraphElement'\n | 'HTMLParamElement'\n | 'HTMLPreElement'\n | 'HTMLProgressElement'\n | 'HTMLQuoteElement'\n | 'HTMLSlotElement'\n | 'HTMLScriptElement'\n | 'HTMLSelectElement'\n | 'HTMLSourceElement'\n | 'HTMLSpanElement'\n | 'HTMLStyleElement'\n | 'HTMLTableElement'\n | 'HTMLTableColElement'\n | 'HTMLTableRowElement'\n | 'HTMLTableSectionElement'\n | 'HTMLTemplateElement'\n | 'HTMLTextAreaElement'\n | 'HTMLTimeElement'\n | 'HTMLTitleElement'\n | 'HTMLTrackElement'\n | 'HTMLUListElement'\n | 'HTMLVideoElement';\n"],"names":["isHTMLElement","element","options","typedElement","Boolean","ownerDocument","defaultView","constructorName"],"mappings":"AAAA;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASA,cACdC,OAAiB,EACjBC,OAMC;QAICC,6BAAAA,eACiED;IAHnE,MAAMC,eAAeF;QAG8CC;IAFnE,OAAOE,QACLD,EAAAA,gBAAAA,0BAAAA,qCAAAA,8BAAAA,cAAcE,aAAa,cAA3BF,kDAAAA,4BAA6BG,WAAW,KACtCH,wBAAwBA,aAAaE,aAAa,CAACC,WAAW,CAACJ,CAAAA,4BAAAA,WAAAA,qBAAAA,+BAAAA,SAASK,eAAe,cAAxBL,sCAAAA,2BAA4B,cAAc;AAE/G"}
1
+ {"version":3,"sources":["isHTMLElement.ts"],"sourcesContent":["/**\n * Verifies if a given node is an HTMLElement,\n * this method works seamlessly with frames and elements from different documents\n *\n * This is preferred over simply using `instanceof`.\n * Since `instanceof` might be problematic while operating with [multiple realms](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof#instanceof_and_multiple_realms)\n *\n * @example\n * ```ts\n * isHTMLElement(event.target) && event.target.focus()\n * isHTMLElement(event.target, {constructorName: 'HTMLInputElement'}) && event.target.value // some value\n * ```\n *\n */\nexport function isHTMLElement<ConstructorName extends HTMLElementConstructorName = 'HTMLElement'>(\n element?: unknown,\n options?: {\n /**\n * Can be used to provide a custom constructor instead of `HTMLElement`,\n * Like `HTMLInputElement` for example.\n */\n constructorName?: ConstructorName;\n },\n): element is InstanceType<(typeof globalThis)[ConstructorName]> {\n const typedElement = element as Node | null | undefined;\n return Boolean(\n typedElement?.ownerDocument?.defaultView &&\n typedElement instanceof typedElement.ownerDocument.defaultView[options?.constructorName ?? 'HTMLElement'],\n );\n}\n\n/**\n * @internal\n */\nexport type HTMLElementConstructorName =\n | 'HTMLElement'\n | 'HTMLAnchorElement'\n | 'HTMLAreaElement'\n | 'HTMLAudioElement'\n | 'HTMLBaseElement'\n | 'HTMLBodyElement'\n | 'HTMLBRElement'\n | 'HTMLButtonElement'\n | 'HTMLCanvasElement'\n | 'HTMLDataElement'\n | 'HTMLDataListElement'\n | 'HTMLDetailsElement'\n // NOTE: dialog is not supported in safari 14, also it was removed from lib-dom starting typescript 4.4\n // | 'HTMLDialogElement'\n | 'HTMLDivElement'\n | 'HTMLDListElement'\n | 'HTMLEmbedElement'\n | 'HTMLFieldSetElement'\n | 'HTMLFormElement'\n | 'HTMLHeadingElement'\n | 'HTMLHeadElement'\n | 'HTMLHRElement'\n | 'HTMLHtmlElement'\n | 'HTMLIFrameElement'\n | 'HTMLImageElement'\n | 'HTMLInputElement'\n | 'HTMLModElement'\n | 'HTMLLabelElement'\n | 'HTMLLegendElement'\n | 'HTMLLIElement'\n | 'HTMLLinkElement'\n | 'HTMLMapElement'\n | 'HTMLMetaElement'\n | 'HTMLMeterElement'\n | 'HTMLObjectElement'\n | 'HTMLOListElement'\n | 'HTMLOptGroupElement'\n | 'HTMLOptionElement'\n | 'HTMLOutputElement'\n | 'HTMLParagraphElement'\n | 'HTMLParamElement'\n | 'HTMLPreElement'\n | 'HTMLProgressElement'\n | 'HTMLQuoteElement'\n | 'HTMLSlotElement'\n | 'HTMLScriptElement'\n | 'HTMLSelectElement'\n | 'HTMLSourceElement'\n | 'HTMLSpanElement'\n | 'HTMLStyleElement'\n | 'HTMLTableElement'\n | 'HTMLTableColElement'\n | 'HTMLTableRowElement'\n | 'HTMLTableSectionElement'\n | 'HTMLTemplateElement'\n | 'HTMLTextAreaElement'\n | 'HTMLTimeElement'\n | 'HTMLTitleElement'\n | 'HTMLTrackElement'\n | 'HTMLUListElement'\n | 'HTMLVideoElement';\n"],"names":["isHTMLElement","element","options","typedElement","Boolean","ownerDocument","defaultView","constructorName"],"mappings":"AAAA;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASA,cACdC,OAAiB,EACjBC,OAMC;QAICC;IAFF,MAAMA,eAAeF;QAG8CC;IAFnE,OAAOE,QACLD,CAAAA,yBAAAA,oCAAAA,8BAAAA,aAAcE,aAAa,cAA3BF,kDAAAA,4BAA6BG,WAAW,KACtCH,wBAAwBA,aAAaE,aAAa,CAACC,WAAW,CAACJ,CAAAA,2BAAAA,oBAAAA,8BAAAA,QAASK,eAAe,cAAxBL,sCAAAA,2BAA4B,cAAc;AAE/G"}
@@ -22,8 +22,7 @@
22
22
  * @returns A function that that calls the provided functions in order
23
23
  */ export function mergeCallbacks(callback1, callback2) {
24
24
  return (...args)=>{
25
- var _callback1, _callback2;
26
- (_callback1 = callback1) === null || _callback1 === void 0 ? void 0 : _callback1(...args);
27
- (_callback2 = callback2) === null || _callback2 === void 0 ? void 0 : _callback2(...args);
25
+ callback1 === null || callback1 === void 0 ? void 0 : callback1(...args);
26
+ callback2 === null || callback2 === void 0 ? void 0 : callback2(...args);
28
27
  };
29
28
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["mergeCallbacks.ts"],"sourcesContent":["/**\n * @internal\n * Combine two event callbacks into a single callback function that calls each one in order.\n *\n * Usage example:\n * ```ts\n * state.slot.onChange = mergeCallbacks(state.slot.onChange, ev => {\n * // Handle onChange\n * });\n * ```\n *\n * The primary use is to avoid the need to capture an existing callback (`state.slot.onChange` in the example) to a\n * local variable before replacing with a new listener that calls the existing one. This helps avoid bugs like:\n * * Infinite recursion by calling the re-assigned state.slot.onChange if it's not captured to a local variable.\n * * Missing a call to the original onChange due to an early return or other conditional.\n *\n * If you need a callback that is stable between renders, wrap the result in {@link useEventCallback}.\n *\n * @param callback1 - The first callback to be called, or undefined\n * @param callback2 - The second callback to be called, or undefined\n *\n * @returns A function that that calls the provided functions in order\n */\nexport function mergeCallbacks<Args extends unknown[]>(\n callback1: ((...args: Args) => void) | undefined,\n callback2: ((...args: Args) => void) | undefined,\n) {\n return (...args: Args) => {\n callback1?.(...args);\n callback2?.(...args);\n };\n}\n"],"names":["mergeCallbacks","callback1","callback2","args"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;CAsBC,GACD,OAAO,SAASA,eACdC,SAAgD,EAChDC,SAAgD;IAEhD,OAAO,CAAC,GAAGC;YACTF,YACAC;SADAD,aAAAA,uBAAAA,iCAAAA,cAAeE;SACfD,aAAAA,uBAAAA,iCAAAA,cAAeC;IACjB;AACF"}
1
+ {"version":3,"sources":["mergeCallbacks.ts"],"sourcesContent":["/**\n * @internal\n * Combine two event callbacks into a single callback function that calls each one in order.\n *\n * Usage example:\n * ```ts\n * state.slot.onChange = mergeCallbacks(state.slot.onChange, ev => {\n * // Handle onChange\n * });\n * ```\n *\n * The primary use is to avoid the need to capture an existing callback (`state.slot.onChange` in the example) to a\n * local variable before replacing with a new listener that calls the existing one. This helps avoid bugs like:\n * * Infinite recursion by calling the re-assigned state.slot.onChange if it's not captured to a local variable.\n * * Missing a call to the original onChange due to an early return or other conditional.\n *\n * If you need a callback that is stable between renders, wrap the result in {@link useEventCallback}.\n *\n * @param callback1 - The first callback to be called, or undefined\n * @param callback2 - The second callback to be called, or undefined\n *\n * @returns A function that that calls the provided functions in order\n */\nexport function mergeCallbacks<Args extends unknown[]>(\n callback1: ((...args: Args) => void) | undefined,\n callback2: ((...args: Args) => void) | undefined,\n) {\n return (...args: Args) => {\n callback1?.(...args);\n callback2?.(...args);\n };\n}\n"],"names":["mergeCallbacks","callback1","callback2","args"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;CAsBC,GACD,OAAO,SAASA,eACdC,SAAgD,EAChDC,SAAgD;IAEhD,OAAO,CAAC,GAAGC;QACTF,sBAAAA,gCAAAA,aAAeE;QACfD,sBAAAA,gCAAAA,aAAeC;IACjB;AACF"}
@@ -402,9 +402,8 @@ props, allowedPropNames, excludedPropNames) {
402
402
  const result = {};
403
403
  const keys = Object.keys(props);
404
404
  for (const key of keys){
405
- var _excludedPropNames;
406
405
  const isNativeProp = !isArray && allowedPropNames[key] || isArray && allowedPropNames.indexOf(key) >= 0 || key.indexOf('data-') === 0 || key.indexOf('aria-') === 0;
407
- if (isNativeProp && (!excludedPropNames || ((_excludedPropNames = excludedPropNames) === null || _excludedPropNames === void 0 ? void 0 : _excludedPropNames.indexOf(key)) === -1)) {
406
+ if (isNativeProp && (!excludedPropNames || (excludedPropNames === null || excludedPropNames === void 0 ? void 0 : excludedPropNames.indexOf(key)) === -1)) {
408
407
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
409
408
  result[key] = props[key];
410
409
  }