@fluentui/react-utilities 9.9.3 → 9.10.0
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 +39 -1
- package/CHANGELOG.md +20 -2
- package/dist/index.d.ts +38 -0
- package/lib/hooks/useOnClickOutside.js +2 -1
- package/lib/hooks/useOnClickOutside.js.map +1 -1
- package/lib/hooks/useOnScrollOutside.js +2 -1
- package/lib/hooks/useOnScrollOutside.js.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/selection/index.js +2 -0
- package/lib/selection/index.js.map +1 -0
- package/lib/selection/types.js +1 -0
- package/lib/selection/types.js.map +1 -0
- package/lib/selection/useSelection.js +113 -0
- package/lib/selection/useSelection.js.map +1 -0
- package/lib/utils/createSetFromIterable.js +5 -0
- package/lib/utils/createSetFromIterable.js.map +1 -0
- package/lib-commonjs/hooks/useOnClickOutside.js +2 -1
- package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -1
- package/lib-commonjs/hooks/useOnScrollOutside.js +2 -1
- package/lib-commonjs/hooks/useOnScrollOutside.js.map +1 -1
- package/lib-commonjs/index.js +3 -1
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/selection/index.js +7 -0
- package/lib-commonjs/selection/index.js.map +1 -0
- package/lib-commonjs/selection/types.js +6 -0
- package/lib-commonjs/selection/types.js.map +1 -0
- package/lib-commonjs/selection/useSelection.js +122 -0
- package/lib-commonjs/selection/useSelection.js.map +1 -0
- package/lib-commonjs/utils/createSetFromIterable.js +13 -0
- package/lib-commonjs/utils/createSetFromIterable.js.map +1 -0
- package/package.json +4 -2
package/CHANGELOG.json
CHANGED
@@ -2,7 +2,45 @@
|
|
2
2
|
"name": "@fluentui/react-utilities",
|
3
3
|
"entries": [
|
4
4
|
{
|
5
|
-
"date": "
|
5
|
+
"date": "Wed, 28 Jun 2023 11:08:37 GMT",
|
6
|
+
"tag": "@fluentui/react-utilities_v9.10.0",
|
7
|
+
"version": "9.10.0",
|
8
|
+
"comments": {
|
9
|
+
"none": [
|
10
|
+
{
|
11
|
+
"author": "martinhochel@microsoft.com",
|
12
|
+
"package": "@fluentui/react-utilities",
|
13
|
+
"commit": "fbe878e9c9785588197481f172c42c2c0a230292",
|
14
|
+
"comment": "fix: update .npmignore to unify v8 packages and exclude project.json"
|
15
|
+
}
|
16
|
+
],
|
17
|
+
"minor": [
|
18
|
+
{
|
19
|
+
"author": "bernardo.sunderhus@gmail.com",
|
20
|
+
"package": "@fluentui/react-utilities",
|
21
|
+
"commit": "f154811cb3580595c319de809ea51a798dfd4555",
|
22
|
+
"comment": "feat: creates useSelection hook"
|
23
|
+
}
|
24
|
+
]
|
25
|
+
}
|
26
|
+
},
|
27
|
+
{
|
28
|
+
"date": "Mon, 26 Jun 2023 09:53:54 GMT",
|
29
|
+
"tag": "@fluentui/react-utilities_v9.9.4",
|
30
|
+
"version": "9.9.4",
|
31
|
+
"comments": {
|
32
|
+
"patch": [
|
33
|
+
{
|
34
|
+
"author": "olfedias@microsoft.com",
|
35
|
+
"package": "@fluentui/react-utilities",
|
36
|
+
"commit": "025ea2c9c6fb2184e67505081a7a307e95c6c009",
|
37
|
+
"comment": "fix: add compatibility with shadow"
|
38
|
+
}
|
39
|
+
]
|
40
|
+
}
|
41
|
+
},
|
42
|
+
{
|
43
|
+
"date": "Tue, 20 Jun 2023 12:39:06 GMT",
|
6
44
|
"tag": "@fluentui/react-utilities_v9.9.3",
|
7
45
|
"version": "9.9.3",
|
8
46
|
"comments": {
|
package/CHANGELOG.md
CHANGED
@@ -1,12 +1,30 @@
|
|
1
1
|
# Change Log - @fluentui/react-utilities
|
2
2
|
|
3
|
-
This log was last generated on
|
3
|
+
This log was last generated on Wed, 28 Jun 2023 11:08:37 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
+
## [9.10.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.10.0)
|
8
|
+
|
9
|
+
Wed, 28 Jun 2023 11:08:37 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.9.4..@fluentui/react-utilities_v9.10.0)
|
11
|
+
|
12
|
+
### Minor changes
|
13
|
+
|
14
|
+
- feat: creates useSelection hook ([PR #28335](https://github.com/microsoft/fluentui/pull/28335) by bernardo.sunderhus@gmail.com)
|
15
|
+
|
16
|
+
## [9.9.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.9.4)
|
17
|
+
|
18
|
+
Mon, 26 Jun 2023 09:53:54 GMT
|
19
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.9.3..@fluentui/react-utilities_v9.9.4)
|
20
|
+
|
21
|
+
### Patches
|
22
|
+
|
23
|
+
- fix: add compatibility with shadow ([PR #28307](https://github.com/microsoft/fluentui/pull/28307) by olfedias@microsoft.com)
|
24
|
+
|
7
25
|
## [9.9.3](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.9.3)
|
8
26
|
|
9
|
-
Tue, 20 Jun 2023 12:
|
27
|
+
Tue, 20 Jun 2023 12:39:06 GMT
|
10
28
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.9.2..@fluentui/react-utilities_v9.9.3)
|
11
29
|
|
12
30
|
### Patches
|
package/dist/index.d.ts
CHANGED
@@ -363,6 +363,12 @@ declare type ObscureEventName = 'onLostPointerCaptureCapture';
|
|
363
363
|
*/
|
364
364
|
export declare function omit<TObj extends Record<string, any>, Exclusions extends (keyof TObj)[]>(obj: TObj, exclusions: Exclusions): Omit<TObj, Exclusions[number]>;
|
365
365
|
|
366
|
+
export declare type OnSelectionChangeCallback = (event: React_2.SyntheticEvent, selectedItems: Set<SelectionItemId>) => void;
|
367
|
+
|
368
|
+
export declare type OnSelectionChangeData = {
|
369
|
+
selectedItems: Set<SelectionItemId>;
|
370
|
+
};
|
371
|
+
|
366
372
|
/**
|
367
373
|
* @internal
|
368
374
|
*/
|
@@ -439,6 +445,36 @@ export declare type ResolveShorthandOptions<Props, Required extends boolean = fa
|
|
439
445
|
defaultProps?: Props;
|
440
446
|
};
|
441
447
|
|
448
|
+
export declare type SelectionHookParams = {
|
449
|
+
selectionMode: SelectionMode_2;
|
450
|
+
/**
|
451
|
+
* Used in uncontrolled mode to set initial selected items on mount
|
452
|
+
*/
|
453
|
+
defaultSelectedItems?: Iterable<SelectionItemId>;
|
454
|
+
/**
|
455
|
+
* Used to control selected items
|
456
|
+
*/
|
457
|
+
selectedItems?: Iterable<SelectionItemId>;
|
458
|
+
/**
|
459
|
+
* Called when selection changes
|
460
|
+
*/
|
461
|
+
onSelectionChange?(event: React_2.SyntheticEvent, data: OnSelectionChangeData): void;
|
462
|
+
};
|
463
|
+
|
464
|
+
export declare type SelectionItemId = string | number;
|
465
|
+
|
466
|
+
export declare interface SelectionMethods {
|
467
|
+
toggleItem(event: React_2.SyntheticEvent, id: SelectionItemId): void;
|
468
|
+
selectItem(event: React_2.SyntheticEvent, id: SelectionItemId): void;
|
469
|
+
deselectItem(event: React_2.SyntheticEvent, id: SelectionItemId): void;
|
470
|
+
clearItems(event: React_2.SyntheticEvent): void;
|
471
|
+
isSelected(id: SelectionItemId): boolean;
|
472
|
+
toggleAllItems(event: React_2.SyntheticEvent, itemIds: SelectionItemId[]): void;
|
473
|
+
}
|
474
|
+
|
475
|
+
declare type SelectionMode_2 = 'single' | 'multiselect';
|
476
|
+
export { SelectionMode_2 as SelectionMode }
|
477
|
+
|
442
478
|
/**
|
443
479
|
* The props type and shorthand value for a slot. Type is either a single intrinsic element like `'div'`,
|
444
480
|
* or a component like `typeof Button`.
|
@@ -707,6 +743,8 @@ declare interface UseScrollbarWidthOptions {
|
|
707
743
|
force?: boolean;
|
708
744
|
}
|
709
745
|
|
746
|
+
export declare function useSelection(params: SelectionHookParams): readonly [Set<SelectionItemId>, SelectionMethods];
|
747
|
+
|
710
748
|
/**
|
711
749
|
* @internal
|
712
750
|
* Helper to manage a browser timeout.
|
@@ -11,7 +11,8 @@ import { useEventCallback } from './useEventCallback';
|
|
11
11
|
const contains = containsProp || ((parent, child)=>{
|
12
12
|
return !!(parent === null || parent === void 0 ? void 0 : parent.contains(child));
|
13
13
|
});
|
14
|
-
const
|
14
|
+
const target = ev.composedPath()[0];
|
15
|
+
const isOutside = refs.every((ref)=>!contains(ref.current || null, target));
|
15
16
|
if (isOutside && !disabled) {
|
16
17
|
callback(ev);
|
17
18
|
}
|
@@ -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 * 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,
|
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 * 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 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 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"],"names":["React","useEventCallback","useOnClickOutside","options","refs","callback","element","disabled","contains","containsProp","timeoutId","useRef","undefined","useIFrameFocus","listener","ev","parent","child","target","composedPath","isOutside","every","ref","current","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;AAkCtD;;;CAGC,GACD,OAAO,MAAMC,oBAAoB,CAACC,UAA8C;IAC9E,MAAM,EAAEC,KAAI,EAAEC,SAAQ,EAAEC,QAAO,EAAEC,SAAQ,EAAEC,UAAUC,aAAY,EAAE,GAAGN;IACtE,MAAMO,YAAYV,MAAMW,MAAM,CAAqBC;IACnDC,eAAeV;IAEf,MAAMW,WAAWb,iBAAiB,CAACc,KAAgC;QACjE,MAAMP,WACJC,gBAAiB,CAAA,CAACO,QAAQC;YAAU,OAAA,CAAC,EAACD,mBAAAA,oBAAAA,KAAAA,IAAAA,OAAQR,QAAQ,CAACS;SAAK;QAE9D,MAAMC,SAASH,GAAGI,YAAY,EAAE,CAAC,EAAE;QACnC,MAAMC,YAAYhB,KAAKiB,KAAK,CAACC,CAAAA,MAAO,CAACd,SAASc,IAAIC,OAAO,IAAI,IAAI,EAAEL;QAEnE,IAAIE,aAAa,CAACb,UAAU;YAC1BF,SAASU;QACX,CAAC;IACH;IAEAf,MAAMwB,SAAS,CAAC,IAAM;QACpB,IAAIjB,UAAU;YACZ;QACF,CAAC;QAED,mEAAmE;QACnE,2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O,GAAGc,2BAAAA,4BAAAA,KAAAA,IAAAA,CAAAA,8BAAAA,eAAgBF,WAAW,cAA3BE,yCAAAA,KAAAA,IAAAA,4BAA6BI,YAAY,IAAM;YAClE,MAAMC,gBAAgBL,2BAAAA,4BAAAA,KAAAA,IAAAA,eAAgBK,aAAa;YAEnD,IAAIA,CAAAA,0BAAAA,2BAAAA,KAAAA,IAAAA,cAAeC,OAAO,AAAD,MAAM,YAAYD,CAAAA,0BAAAA,2BAAAA,KAAAA,IAAAA,cAAeC,OAAO,AAAD,MAAM,WAAW;gBAC/E,MAAMd,QAAQ,IAAIe,YAAYR,iBAAiB;oBAAES,SAAS,IAAI;gBAAC;gBAC/DH,cAAcI,aAAa,CAACjB;YAC9B,CAAC;QACH,GAAGS;QAEH,OAAO,IAAM;gBACXD;YAAAA,2BAAAA,4BAAAA,KAAAA,IAAAA,CAAAA,8BAAAA,eAAgBF,WAAW,cAA3BE,yCAAAA,KAAAA,IAAAA,4BAA6BJ,aAAaM,WAAWhB,OAAO;QAC9D;IACF,GAAG;QAACc;QAAgB9B;QAAU+B;KAAa;AAC7C"}
|
@@ -9,7 +9,8 @@ import { useEventCallback } from './useEventCallback';
|
|
9
9
|
const contains = containsProp || ((parent, child)=>{
|
10
10
|
return !!(parent === null || parent === void 0 ? void 0 : parent.contains(child));
|
11
11
|
});
|
12
|
-
const
|
12
|
+
const target = ev.composedPath()[0];
|
13
|
+
const isOutside = refs.every((ref)=>!contains(ref.current || null, target));
|
13
14
|
if (isOutside && !disabled) {
|
14
15
|
callback(ev);
|
15
16
|
}
|
@@ -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: 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,
|
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: MouseEvent | TouchEvent) => {\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);\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"],"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,UAA8C;IAC/E,MAAM,EAAEC,KAAI,EAAEC,SAAQ,EAAEC,QAAO,EAAEC,SAAQ,EAAEC,UAAUC,aAAY,EAAE,GAAGN;IAEtE,MAAMO,WAAWT,iBAAiB,CAACU,KAAgC;QACjE,MAAMH,WACJC,gBAAiB,CAAA,CAACG,QAAQC;YAAU,OAAA,CAAC,EAACD,mBAAAA,oBAAAA,KAAAA,IAAAA,OAAQJ,QAAQ,CAACK;SAAK;QAE9D,MAAMC,SAASH,GAAGI,YAAY,EAAE,CAAC,EAAE;QACnC,MAAMC,YAAYZ,KAAKa,KAAK,CAACC,CAAAA,MAAO,CAACV,SAASU,IAAIC,OAAO,IAAI,IAAI,EAAEL;QAEnE,IAAIE,aAAa,CAACT,UAAU;YAC1BF,SAASM;QACX,CAAC;IACH;IAEAX,MAAMoB,SAAS,CAAC,IAAM;QACpB,IAAIb,UAAU;YACZ;QACF,CAAC;QAEDD,oBAAAA,qBAAAA,KAAAA,IAAAA,QAASe,gBAAgB,CAAC,SAASX;QACnCJ,oBAAAA,qBAAAA,KAAAA,IAAAA,QAASe,gBAAgB,CAAC,aAAaX;QAEvC,OAAO,IAAM;YACXJ,oBAAAA,qBAAAA,KAAAA,IAAAA,QAASgB,mBAAmB,CAAC,SAASZ;YACtCJ,oBAAAA,qBAAAA,KAAAA,IAAAA,QAASgB,mBAAmB,CAAC,aAAaZ;QAC5C;IACF,GAAG;QAACA;QAAUJ;QAASC;KAAS;AAClC,EAAE"}
|
package/lib/index.js
CHANGED
@@ -4,3 +4,4 @@ export { canUseDOM, useIsSSR, SSRProvider } from './ssr/index';
|
|
4
4
|
export { clamp, getNativeElementProps, getPartitionedNativeProps, getRTLSafeKey, mergeCallbacks, isHTMLElement, isInteractiveHTMLElement, omit, createPriorityQueue } from './utils/index';
|
5
5
|
export { applyTriggerPropsToChildren, getTriggerChild, isFluentTrigger } from './trigger/index';
|
6
6
|
export { isTouchEvent, isMouseEvent, getEventClientCoords } from './events/index';
|
7
|
+
export { useSelection } from './selection/index';
|
package/lib/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["index.ts"],"sourcesContent":["export {\n getSlots,\n getSlotsNext,\n resolveShorthand,\n isResolvedShorthand,\n SLOT_RENDER_FUNCTION_SYMBOL,\n} from './compose/index';\nexport type {\n ExtractSlotProps,\n ComponentProps,\n ComponentState,\n ForwardRefComponent,\n ResolveShorthandFunction,\n ResolveShorthandOptions,\n Slot,\n Slots,\n SlotClassNames,\n SlotPropsRecord,\n SlotRenderFunction,\n SlotShorthandValue,\n UnknownSlotProps,\n} from './compose/index';\n\nexport {\n IdPrefixProvider,\n resetIdsForTests,\n useControllableState,\n useEventCallback,\n useFirstMount,\n useForceUpdate,\n useId,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n useOnClickOutside,\n useOnScrollOutside,\n usePrevious,\n useScrollbarWidth,\n useTimeout,\n} from './hooks/index';\nexport type { RefObjectFunction, UseControllableStateOptions, UseOnClickOrScrollOutsideOptions } from './hooks/index';\n\nexport { canUseDOM, useIsSSR, SSRProvider } from './ssr/index';\n\nexport {\n clamp,\n getNativeElementProps,\n getPartitionedNativeProps,\n getRTLSafeKey,\n mergeCallbacks,\n isHTMLElement,\n isInteractiveHTMLElement,\n omit,\n createPriorityQueue,\n} from './utils/index';\n\nexport type { PriorityQueue } from './utils/priorityQueue';\n\nexport { applyTriggerPropsToChildren, getTriggerChild, isFluentTrigger } from './trigger/index';\n\nexport type { FluentTriggerComponent, TriggerProps } from './trigger/index';\n\n/**\n * Event utils\n */\nexport type { NativeTouchOrMouseEvent, ReactTouchOrMouseEvent, TouchOrMouseEvent } from './events/index';\nexport { isTouchEvent, isMouseEvent, getEventClientCoords } from './events/index';\n"],"names":["getSlots","getSlotsNext","resolveShorthand","isResolvedShorthand","SLOT_RENDER_FUNCTION_SYMBOL","IdPrefixProvider","resetIdsForTests","useControllableState","useEventCallback","useFirstMount","useForceUpdate","useId","useIsomorphicLayoutEffect","useMergedRefs","useOnClickOutside","useOnScrollOutside","usePrevious","useScrollbarWidth","useTimeout","canUseDOM","useIsSSR","SSRProvider","clamp","getNativeElementProps","getPartitionedNativeProps","getRTLSafeKey","mergeCallbacks","isHTMLElement","isInteractiveHTMLElement","omit","createPriorityQueue","applyTriggerPropsToChildren","getTriggerChild","isFluentTrigger","isTouchEvent","isMouseEvent","getEventClientCoords"],"mappings":"AAAA,SACEA,QAAQ,EACRC,YAAY,EACZC,gBAAgB,EAChBC,mBAAmB,EACnBC,2BAA2B,QACtB,kBAAkB;AAiBzB,SACEC,gBAAgB,EAChBC,gBAAgB,EAChBC,oBAAoB,EACpBC,gBAAgB,EAChBC,aAAa,EACbC,cAAc,EACdC,KAAK,EACLC,yBAAyB,EACzBC,aAAa,EACbC,iBAAiB,EACjBC,kBAAkB,EAClBC,WAAW,EACXC,iBAAiB,EACjBC,UAAU,QACL,gBAAgB;AAGvB,SAASC,SAAS,EAAEC,QAAQ,EAAEC,WAAW,QAAQ,cAAc;AAE/D,SACEC,KAAK,EACLC,qBAAqB,EACrBC,yBAAyB,EACzBC,aAAa,EACbC,cAAc,EACdC,aAAa,EACbC,wBAAwB,EACxBC,IAAI,EACJC,mBAAmB,QACd,gBAAgB;AAIvB,SAASC,2BAA2B,EAAEC,eAAe,EAAEC,eAAe,QAAQ,kBAAkB;AAQhG,SAASC,YAAY,EAAEC,YAAY,EAAEC,oBAAoB,QAAQ,iBAAiB"}
|
1
|
+
{"version":3,"sources":["index.ts"],"sourcesContent":["export {\n getSlots,\n getSlotsNext,\n resolveShorthand,\n isResolvedShorthand,\n SLOT_RENDER_FUNCTION_SYMBOL,\n} from './compose/index';\nexport type {\n ExtractSlotProps,\n ComponentProps,\n ComponentState,\n ForwardRefComponent,\n ResolveShorthandFunction,\n ResolveShorthandOptions,\n Slot,\n Slots,\n SlotClassNames,\n SlotPropsRecord,\n SlotRenderFunction,\n SlotShorthandValue,\n UnknownSlotProps,\n} from './compose/index';\n\nexport {\n IdPrefixProvider,\n resetIdsForTests,\n useControllableState,\n useEventCallback,\n useFirstMount,\n useForceUpdate,\n useId,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n useOnClickOutside,\n useOnScrollOutside,\n usePrevious,\n useScrollbarWidth,\n useTimeout,\n} from './hooks/index';\nexport type { RefObjectFunction, UseControllableStateOptions, UseOnClickOrScrollOutsideOptions } from './hooks/index';\n\nexport { canUseDOM, useIsSSR, SSRProvider } from './ssr/index';\n\nexport {\n clamp,\n getNativeElementProps,\n getPartitionedNativeProps,\n getRTLSafeKey,\n mergeCallbacks,\n isHTMLElement,\n isInteractiveHTMLElement,\n omit,\n createPriorityQueue,\n} from './utils/index';\n\nexport type { PriorityQueue } from './utils/priorityQueue';\n\nexport { applyTriggerPropsToChildren, getTriggerChild, isFluentTrigger } from './trigger/index';\n\nexport type { FluentTriggerComponent, TriggerProps } from './trigger/index';\n\n/**\n * Event utils\n */\nexport type { NativeTouchOrMouseEvent, ReactTouchOrMouseEvent, TouchOrMouseEvent } from './events/index';\nexport { isTouchEvent, isMouseEvent, getEventClientCoords } from './events/index';\n\nexport type {\n SelectionMode,\n OnSelectionChangeCallback,\n OnSelectionChangeData,\n SelectionItemId,\n SelectionHookParams,\n SelectionMethods,\n} from './selection/index';\nexport { useSelection } from './selection/index';\n"],"names":["getSlots","getSlotsNext","resolveShorthand","isResolvedShorthand","SLOT_RENDER_FUNCTION_SYMBOL","IdPrefixProvider","resetIdsForTests","useControllableState","useEventCallback","useFirstMount","useForceUpdate","useId","useIsomorphicLayoutEffect","useMergedRefs","useOnClickOutside","useOnScrollOutside","usePrevious","useScrollbarWidth","useTimeout","canUseDOM","useIsSSR","SSRProvider","clamp","getNativeElementProps","getPartitionedNativeProps","getRTLSafeKey","mergeCallbacks","isHTMLElement","isInteractiveHTMLElement","omit","createPriorityQueue","applyTriggerPropsToChildren","getTriggerChild","isFluentTrigger","isTouchEvent","isMouseEvent","getEventClientCoords","useSelection"],"mappings":"AAAA,SACEA,QAAQ,EACRC,YAAY,EACZC,gBAAgB,EAChBC,mBAAmB,EACnBC,2BAA2B,QACtB,kBAAkB;AAiBzB,SACEC,gBAAgB,EAChBC,gBAAgB,EAChBC,oBAAoB,EACpBC,gBAAgB,EAChBC,aAAa,EACbC,cAAc,EACdC,KAAK,EACLC,yBAAyB,EACzBC,aAAa,EACbC,iBAAiB,EACjBC,kBAAkB,EAClBC,WAAW,EACXC,iBAAiB,EACjBC,UAAU,QACL,gBAAgB;AAGvB,SAASC,SAAS,EAAEC,QAAQ,EAAEC,WAAW,QAAQ,cAAc;AAE/D,SACEC,KAAK,EACLC,qBAAqB,EACrBC,yBAAyB,EACzBC,aAAa,EACbC,cAAc,EACdC,aAAa,EACbC,wBAAwB,EACxBC,IAAI,EACJC,mBAAmB,QACd,gBAAgB;AAIvB,SAASC,2BAA2B,EAAEC,eAAe,EAAEC,eAAe,QAAQ,kBAAkB;AAQhG,SAASC,YAAY,EAAEC,YAAY,EAAEC,oBAAoB,QAAQ,iBAAiB;AAUlF,SAASC,YAAY,QAAQ,oBAAoB"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["index.ts"],"sourcesContent":["export * from './types';\nexport * from './useSelection';\n"],"names":[],"mappings":"AAAA,cAAc,UAAU;AACxB,cAAc,iBAAiB"}
|
@@ -0,0 +1 @@
|
|
1
|
+
import * as React from 'react';
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["types.ts"],"sourcesContent":["import * as React from 'react';\n\nexport type SelectionMode = 'single' | 'multiselect';\n\nexport interface SelectionMethods {\n toggleItem(event: React.SyntheticEvent, id: SelectionItemId): void;\n selectItem(event: React.SyntheticEvent, id: SelectionItemId): void;\n deselectItem(event: React.SyntheticEvent, id: SelectionItemId): void;\n clearItems(event: React.SyntheticEvent): void;\n isSelected(id: SelectionItemId): boolean;\n toggleAllItems(event: React.SyntheticEvent, itemIds: SelectionItemId[]): void;\n}\n\nexport type SelectionItemId = string | number;\n\nexport type OnSelectionChangeCallback = (event: React.SyntheticEvent, selectedItems: Set<SelectionItemId>) => void;\n\nexport type OnSelectionChangeData = {\n selectedItems: Set<SelectionItemId>;\n};\n\nexport type SelectionHookParams = {\n selectionMode: SelectionMode;\n /**\n * Used in uncontrolled mode to set initial selected items on mount\n */\n defaultSelectedItems?: Iterable<SelectionItemId>;\n /**\n * Used to control selected items\n */\n selectedItems?: Iterable<SelectionItemId>;\n /**\n * Called when selection changes\n */\n onSelectionChange?(event: React.SyntheticEvent, data: OnSelectionChangeData): void;\n};\n"],"names":["React"],"mappings":"AAAA,YAAYA,WAAW,QAAQ"}
|
@@ -0,0 +1,113 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import { useControllableState } from '../hooks/useControllableState';
|
3
|
+
import { createSetFromIterable } from '../utils/createSetFromIterable';
|
4
|
+
function useSingleSelection(params) {
|
5
|
+
const [selected, setSelected] = useControllableState({
|
6
|
+
initialState: new Set(),
|
7
|
+
defaultState: React.useMemo(()=>params.defaultSelectedItems && createSetFromIterable(params.defaultSelectedItems), [
|
8
|
+
params.defaultSelectedItems
|
9
|
+
]),
|
10
|
+
state: React.useMemo(()=>params.selectedItems && createSetFromIterable(params.selectedItems), [
|
11
|
+
params.selectedItems
|
12
|
+
])
|
13
|
+
});
|
14
|
+
const changeSelection = (event, nextSelectedItems)=>{
|
15
|
+
var _params_onSelectionChange;
|
16
|
+
(_params_onSelectionChange = params.onSelectionChange) === null || _params_onSelectionChange === void 0 ? void 0 : _params_onSelectionChange.call(params, event, {
|
17
|
+
selectedItems: nextSelectedItems
|
18
|
+
});
|
19
|
+
if (!event.isDefaultPrevented()) {
|
20
|
+
setSelected(nextSelectedItems);
|
21
|
+
}
|
22
|
+
};
|
23
|
+
var _selected_has;
|
24
|
+
const methods = {
|
25
|
+
deselectItem: (event)=>changeSelection(event, new Set()),
|
26
|
+
selectItem: (event, itemId)=>changeSelection(event, new Set([
|
27
|
+
itemId
|
28
|
+
])),
|
29
|
+
toggleAllItems: ()=>{
|
30
|
+
if (process.env.NODE_ENV !== 'production') {
|
31
|
+
throw new Error('[react-utilities]: `toggleAllItems` should not be used in single selection mode');
|
32
|
+
}
|
33
|
+
},
|
34
|
+
toggleItem: (event, itemId)=>changeSelection(event, new Set([
|
35
|
+
itemId
|
36
|
+
])),
|
37
|
+
clearItems: (event)=>changeSelection(event, new Set()),
|
38
|
+
isSelected: (itemId)=>(_selected_has = selected.has(itemId)) !== null && _selected_has !== void 0 ? _selected_has : false
|
39
|
+
};
|
40
|
+
return [
|
41
|
+
selected,
|
42
|
+
methods
|
43
|
+
];
|
44
|
+
}
|
45
|
+
function useMultipleSelection(params) {
|
46
|
+
const [selected, setSelected] = useControllableState({
|
47
|
+
initialState: new Set(),
|
48
|
+
defaultState: React.useMemo(()=>params.defaultSelectedItems && createSetFromIterable(params.defaultSelectedItems), [
|
49
|
+
params.defaultSelectedItems
|
50
|
+
]),
|
51
|
+
state: React.useMemo(()=>params.selectedItems && createSetFromIterable(params.selectedItems), [
|
52
|
+
params.selectedItems
|
53
|
+
])
|
54
|
+
});
|
55
|
+
const changeSelection = (event, nextSelectedItems)=>{
|
56
|
+
var _params_onSelectionChange;
|
57
|
+
(_params_onSelectionChange = params.onSelectionChange) === null || _params_onSelectionChange === void 0 ? void 0 : _params_onSelectionChange.call(params, event, {
|
58
|
+
selectedItems: nextSelectedItems
|
59
|
+
});
|
60
|
+
if (!event.isDefaultPrevented()) {
|
61
|
+
setSelected(nextSelectedItems);
|
62
|
+
}
|
63
|
+
};
|
64
|
+
const methods = {
|
65
|
+
toggleItem: (event, itemId)=>{
|
66
|
+
const nextSelectedItems = new Set(selected);
|
67
|
+
if (selected.has(itemId)) {
|
68
|
+
nextSelectedItems.delete(itemId);
|
69
|
+
} else {
|
70
|
+
nextSelectedItems.add(itemId);
|
71
|
+
}
|
72
|
+
changeSelection(event, nextSelectedItems);
|
73
|
+
},
|
74
|
+
selectItem: (event, itemId)=>{
|
75
|
+
const nextSelectedItems = new Set(selected);
|
76
|
+
nextSelectedItems.add(itemId);
|
77
|
+
changeSelection(event, nextSelectedItems);
|
78
|
+
},
|
79
|
+
deselectItem: (event, itemId)=>{
|
80
|
+
const nextSelectedItems = new Set(selected);
|
81
|
+
nextSelectedItems.delete(itemId);
|
82
|
+
changeSelection(event, nextSelectedItems);
|
83
|
+
},
|
84
|
+
clearItems: (event)=>{
|
85
|
+
changeSelection(event, new Set());
|
86
|
+
},
|
87
|
+
isSelected: (itemId)=>selected.has(itemId),
|
88
|
+
toggleAllItems: (event, itemIds)=>{
|
89
|
+
const allItemsSelected = itemIds.every((itemId)=>selected.has(itemId));
|
90
|
+
const nextSelectedItems = new Set(selected);
|
91
|
+
if (allItemsSelected) {
|
92
|
+
nextSelectedItems.clear();
|
93
|
+
} else {
|
94
|
+
itemIds.forEach((itemId)=>nextSelectedItems.add(itemId));
|
95
|
+
}
|
96
|
+
changeSelection(event, nextSelectedItems);
|
97
|
+
}
|
98
|
+
};
|
99
|
+
return [
|
100
|
+
selected,
|
101
|
+
methods
|
102
|
+
];
|
103
|
+
}
|
104
|
+
export function useSelection(params) {
|
105
|
+
if (params.selectionMode === 'multiselect') {
|
106
|
+
// selectionMode is a static value, so we can safely ignore rules-of-hooks
|
107
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
108
|
+
return useMultipleSelection(params);
|
109
|
+
}
|
110
|
+
// selectionMode is a static value, so we can safely ignore rules-of-hooks
|
111
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
112
|
+
return useSingleSelection(params);
|
113
|
+
}
|
@@ -0,0 +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 useSingleSelection(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 if (!event.isDefaultPrevented()) {\n setSelected(nextSelectedItems);\n }\n };\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, 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 if (!event.isDefaultPrevented()) {\n setSelected(nextSelectedItems);\n }\n };\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","useSingleSelection","params","selected","setSelected","initialState","Set","defaultState","useMemo","defaultSelectedItems","state","selectedItems","changeSelection","event","nextSelectedItems","onSelectionChange","isDefaultPrevented","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,mBAAmBC,MAAkD,EAAE;IAC9E,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,MAAMU,OAAO,CAClB,IAAMN,OAAOS,aAAa,IAAIX,sBAAsBE,OAAOS,aAAa,GACxE;YAACT,OAAOS,aAAa;SAAC;IAE1B;IACA,MAAMC,kBAAkB,CAACC,OAA6BC,oBAA4C;YAChGZ;QAAAA,CAAAA,4BAAAA,OAAOa,iBAAiB,cAAxBb,uCAAAA,KAAAA,IAAAA,0BAAA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
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["createSetFromIterable.ts"],"sourcesContent":["/**\n * Creates a set from a given iterable, in case the iterable is a set itself, returns the given set instead.\n */\nexport function createSetFromIterable<V>(iterable: Iterable<V>): Set<V> {\n return iterable instanceof Set ? iterable : new Set(iterable);\n}\n"],"names":["createSetFromIterable","iterable","Set"],"mappings":"AAAA;;CAEC,GACD,OAAO,SAASA,sBAAyBC,QAAqB,EAAU;IACtE,OAAOA,oBAAoBC,MAAMD,WAAW,IAAIC,IAAID,SAAS;AAC/D,CAAC"}
|
@@ -17,7 +17,8 @@ const useOnClickOutside = (options)=>{
|
|
17
17
|
const contains = containsProp || ((parent, child)=>{
|
18
18
|
return !!(parent === null || parent === void 0 ? void 0 : parent.contains(child));
|
19
19
|
});
|
20
|
-
const
|
20
|
+
const target = ev.composedPath()[0];
|
21
|
+
const isOutside = refs.every((ref)=>!contains(ref.current || null, target));
|
21
22
|
if (isOutside && !disabled) {
|
22
23
|
callback(ev);
|
23
24
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["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 */ export const useOnClickOutside = (options)=>{\n const { refs , callback , element , disabled , contains: containsProp } = 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 }, [\n listener,\n element,\n disabled\n ]);\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 */ const useIFrameFocus = (options)=>{\n const { disabled , element: targetDocument , callback , contains: containsProp = (parent, child)=>{\n return !!(parent === null || parent === void 0 ? void 0 : parent.contains(child));\n } , pollDuration =1000 , refs } = 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 }, [\n targetDocument,\n disabled,\n listener\n ]);\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 }, [\n targetDocument,\n disabled,\n pollDuration\n ]);\n};\n"],"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":";;;;+BAKiBA;;aAAAA;;;6DALM;kCACU;AAItB,MAAMA,oBAAoB,CAACC,UAAU;IAC5C,MAAM,EAAEC,KAAI,EAAGC,SAAQ,EAAGC,QAAO,EAAGC,SAAQ,EAAGC,UAAUC,aAAY,EAAG,GAAGN;IAC3E,MAAMO,YAAYC,OAAMC,MAAM,CAACC;IAC/BC,eAAeX;IACf,MAAMY,WAAWC,IAAAA,kCAAgB,EAAC,CAACC,KAAK;QACpC,MAAMT,WAAWC,gBAAiB,CAAA,CAACS,QAAQC,QAAQ;YAC/C,OAAO,CAAC,CAAED,CAAAA,WAAW,IAAI,IAAIA,WAAW,KAAK,IAAI,KAAK,IAAIA,OAAOV,QAAQ,CAACW,MAAM,AAAD;QACnF,CAAA;QACA,MAAMC,YAAYhB,KAAKiB,KAAK,CAAC,CAACC,MAAM,CAACd,SAASc,IAAIC,OAAO,IAAI,IAAI,EAAEN,GAAGO,MAAM;QAC5E,IAAIJ,aAAa,CAACb,UAAU;YACxBF,SAASY;QACb,CAAC;IACL;IACAN,OAAMc,SAAS,CAAC,IAAI;QAChB,IAAIlB,UAAU;YACV;QACJ,CAAC;QACD,mEAAmE;QACnE,2FAA2F;QAC3F,iDAAiD;QACjD,IAAImB,eAAeC,eAAeC;QAClC,MAAMC,qBAAqB,CAACC,QAAQ;YAChC,+EAA+E;YAC/E,IAAIA,UAAUJ,cAAc;gBACxBA,eAAeb;gBACf;YACJ,CAAC;YACDE,SAASe;QACb;QACA,0FAA0F;QAC1FxB,YAAY,IAAI,IAAIA,YAAY,KAAK,IAA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IAAI,KAAK,IAAIA,eAAeR,mBAAmB,CAACO,iBAAiBzB,UAAU,IAAI,CAAC;QACvI;IACJ,GAAG;QACC0B;QACAlC;QACAQ;KACH;IACD,wCAAwC;IACxCJ,OAAMc,SAAS,CAAC,IAAI;QAChB,IAAIoB;QACJ,IAAItC,UAAU;YACV;QACJ,CAAC;QACDoC,WAAWpB,OAAO,GAAGkB,mBAAmB,IAAI,IAAIA,mBAAmB,KAAK,IAAI,KAAK,IAAI,AAACI,CAAAA,8BAA8BJ,eAAeF,WAAW,AAAD,MAAO,IAAI,IAAIM,gCAAgC,KAAK,IAAI,KAAK,IAAIA,4BAA4BC,WAAW,CAAC,IAAI;YACtP,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;gBAC3M,MAAMlB,QAAQ,IAAImB,YAAYT,iBAAiB;oBAC3CU,SAAS,IAAI;gBACjB;gBACAH,cAAcI,aAAa,CAACrB;YAChC,CAAC;QACL,GAAGY,aAAa;QAChB,OAAO,IAAI;YACP,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;QACzP;IACJ,GAAG;QACCkB;QACAlC;QACAmC;KACH;AACL"}
|
1
|
+
{"version":3,"sources":["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 */ export const useOnClickOutside = (options)=>{\n const { refs , callback , element , disabled , contains: containsProp } = 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 target = ev.composedPath()[0];\n const isOutside = refs.every((ref)=>!contains(ref.current || null, 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 }, [\n listener,\n element,\n disabled\n ]);\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 */ const useIFrameFocus = (options)=>{\n const { disabled , element: targetDocument , callback , contains: containsProp = (parent, child)=>{\n return !!(parent === null || parent === void 0 ? void 0 : parent.contains(child));\n } , pollDuration =1000 , refs } = 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 }, [\n targetDocument,\n disabled,\n listener\n ]);\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 }, [\n targetDocument,\n disabled,\n pollDuration\n ]);\n};\n"],"names":["useOnClickOutside","options","refs","callback","element","disabled","contains","containsProp","timeoutId","React","useRef","undefined","useIFrameFocus","listener","useEventCallback","ev","parent","child","target","composedPath","isOutside","every","ref","current","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":";;;;+BAKiBA;;aAAAA;;;6DALM;kCACU;AAItB,MAAMA,oBAAoB,CAACC,UAAU;IAC5C,MAAM,EAAEC,KAAI,EAAGC,SAAQ,EAAGC,QAAO,EAAGC,SAAQ,EAAGC,UAAUC,aAAY,EAAG,GAAGN;IAC3E,MAAMO,YAAYC,OAAMC,MAAM,CAACC;IAC/BC,eAAeX;IACf,MAAMY,WAAWC,IAAAA,kCAAgB,EAAC,CAACC,KAAK;QACpC,MAAMT,WAAWC,gBAAiB,CAAA,CAACS,QAAQC,QAAQ;YAC/C,OAAO,CAAC,CAAED,CAAAA,WAAW,IAAI,IAAIA,WAAW,KAAK,IAAI,KAAK,IAAIA,OAAOV,QAAQ,CAACW,MAAM,AAAD;QACnF,C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IA,cAAcC,OAAO,AAAD,MAAO,WAAW;gBAC3M,MAAMlB,QAAQ,IAAImB,YAAYT,iBAAiB;oBAC3CU,SAAS,IAAI;gBACjB;gBACAH,cAAcI,aAAa,CAACrB;YAChC,CAAC;QACL,GAAGY,aAAa;QAChB,OAAO,IAAI;YACP,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,WAAWnB,OAAO,CAAC;QACzP;IACJ,GAAG;QACCiB;QACAnC;QACAoC;KACH;AACL"}
|
@@ -15,7 +15,8 @@ const useOnScrollOutside = (options)=>{
|
|
15
15
|
const contains = containsProp || ((parent, child)=>{
|
16
16
|
return !!(parent === null || parent === void 0 ? void 0 : parent.contains(child));
|
17
17
|
});
|
18
|
-
const
|
18
|
+
const target = ev.composedPath()[0];
|
19
|
+
const isOutside = refs.every((ref)=>!contains(ref.current || null, target));
|
19
20
|
if (isOutside && !disabled) {
|
20
21
|
callback(ev);
|
21
22
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["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 */ export const useOnScrollOutside = (options)=>{\n const { refs , callback , element , disabled , contains: containsProp } = 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,
|
1
|
+
{"version":3,"sources":["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 */ export const useOnScrollOutside = (options)=>{\n const { refs , callback , element , disabled , contains: containsProp } = 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 target = ev.composedPath()[0];\n const isOutside = refs.every((ref)=>!contains(ref.current || null, 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 }, [\n listener,\n element,\n disabled\n ]);\n};\n"],"names":["useOnScrollOutside","options","refs","callback","element","disabled","contains","containsProp","listener","useEventCallback","ev","parent","child","target","composedPath","isOutside","every","ref","current","React","useEffect","addEventListener","removeEventListener"],"mappings":";;;;+BAKiBA;;aAAAA;;;6DALM;kCACU;AAItB,MAAMA,qBAAqB,CAACC,UAAU;IAC7C,MAAM,EAAEC,KAAI,EAAGC,SAAQ,EAAGC,QAAO,EAAGC,SAAQ,EAAGC,UAAUC,aAAY,EAAG,GAAGN;IAC3E,MAAMO,WAAWC,IAAAA,kCAAgB,EAAC,CAACC,KAAK;QACpC,MAAMJ,WAAWC,gBAAiB,CAAA,CAACI,QAAQC,QAAQ;YAC/C,OAAO,CAAC,CAAED,CAAAA,WAAW,IAAI,IAAIA,WAAW,KAAK,IAAI,KAAK,IAAIA,OAAOL,QAAQ,CAACM,MAAM,AAAD;QACnF,CAAA;QACA,MAAMC,SAASH,GAAGI,YAAY,EAAE,CAAC,EAAE;QACnC,MAAMC,YAAYb,KAAKc,KAAK,CAAC,CAACC,MAAM,CAACX,SAASW,IAAIC,OAAO,IAAI,IAAI,EAAEL;QACnE,IAAIE,aAAa,CAACV,UAAU;YACxBF,SAASO;QACb,CAAC;IACL;IACAS,OAAMC,SAAS,CAAC,IAAI;QAChB,IAAIf,UAAU;YACV;QACJ,CAAC;QACDD,YAAY,IAAI,IAAIA,YAAY,KAAK,IAAI,KAAK,IAAIA,QAAQiB,gBAAgB,CAAC,SAASb,SAAS;QAC7FJ,YAAY,IAAI,IAAIA,YAAY,KAAK,IAAI,KAAK,IAAIA,QAAQiB,gBAAgB,CAAC,aAAab,SAAS;QACjG,OAAO,IAAI;YACPJ,YAAY,IAAI,IAAIA,YAAY,KAAK,IAAI,KAAK,IAAIA,QAAQkB,mBAAmB,CAAC,SAASd,SAAS;YAChGJ,YAAY,IAAI,IAAIA,YAAY,KAAK,IAAI,KAAK,IAAIA,QAAQkB,mBAAmB,CAAC,aAAad,SAAS;QACxG;IACJ,GAAG;QACCA;QACAJ;QACAC;KACH;AACL"}
|
package/lib-commonjs/index.js
CHANGED
@@ -45,7 +45,8 @@ _export(exports, {
|
|
45
45
|
isFluentTrigger: ()=>_index4.isFluentTrigger,
|
46
46
|
isTouchEvent: ()=>_index5.isTouchEvent,
|
47
47
|
isMouseEvent: ()=>_index5.isMouseEvent,
|
48
|
-
getEventClientCoords: ()=>_index5.getEventClientCoords
|
48
|
+
getEventClientCoords: ()=>_index5.getEventClientCoords,
|
49
|
+
useSelection: ()=>_index6.useSelection
|
49
50
|
});
|
50
51
|
const _index = require("./compose/index");
|
51
52
|
const _index1 = require("./hooks/index");
|
@@ -53,3 +54,4 @@ const _index2 = require("./ssr/index");
|
|
53
54
|
const _index3 = require("./utils/index");
|
54
55
|
const _index4 = require("./trigger/index");
|
55
56
|
const _index5 = require("./events/index");
|
57
|
+
const _index6 = require("./selection/index");
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["index.js"],"sourcesContent":["export { getSlots, getSlotsNext, resolveShorthand, isResolvedShorthand, SLOT_RENDER_FUNCTION_SYMBOL } from './compose/index';\nexport { IdPrefixProvider, resetIdsForTests, useControllableState, useEventCallback, useFirstMount, useForceUpdate, useId, useIsomorphicLayoutEffect, useMergedRefs, useOnClickOutside, useOnScrollOutside, usePrevious, useScrollbarWidth, useTimeout } from './hooks/index';\nexport { canUseDOM, useIsSSR, SSRProvider } from './ssr/index';\nexport { clamp, getNativeElementProps, getPartitionedNativeProps, getRTLSafeKey, mergeCallbacks, isHTMLElement, isInteractiveHTMLElement, omit, createPriorityQueue } from './utils/index';\nexport { applyTriggerPropsToChildren, getTriggerChild, isFluentTrigger } from './trigger/index';\nexport { isTouchEvent, isMouseEvent, getEventClientCoords } from './events/index';\n"],"names":["getSlots","getSlotsNext","resolveShorthand","isResolvedShorthand","SLOT_RENDER_FUNCTION_SYMBOL","IdPrefixProvider","resetIdsForTests","useControllableState","useEventCallback","useFirstMount","useForceUpdate","useId","useIsomorphicLayoutEffect","useMergedRefs","useOnClickOutside","useOnScrollOutside","usePrevious","useScrollbarWidth","useTimeout","canUseDOM","useIsSSR","SSRProvider","clamp","getNativeElementProps","getPartitionedNativeProps","getRTLSafeKey","mergeCallbacks","isHTMLElement","isInteractiveHTMLElement","omit","createPriorityQueue","applyTriggerPropsToChildren","getTriggerChild","isFluentTrigger","isTouchEvent","isMouseEvent","getEventClientCoords"],"mappings":";;;;;;;;;;;IAASA,QAAQ,MAARA,eAAQ;IAAEC,YAAY,MAAZA,mBAAY;IAAEC,gBAAgB,MAAhBA,uBAAgB;IAAEC,mBAAmB,MAAnBA,0BAAmB;IAAEC,2BAA2B,MAA3BA,kCAA2B;IAC1FC,gBAAgB,MAAhBA,wBAAgB;IAAEC,gBAAgB,MAAhBA,wBAAgB;IAAEC,oBAAoB,MAApBA,4BAAoB;IAAEC,gBAAgB,MAAhBA,wBAAgB;IAAEC,aAAa,MAAbA,qBAAa;IAAEC,cAAc,MAAdA,sBAAc;IAAEC,KAAK,MAALA,aAAK;IAAEC,yBAAyB,MAAzBA,iCAAyB;IAAEC,aAAa,MAAbA,qBAAa;IAAEC,iBAAiB,MAAjBA,yBAAiB;IAAEC,kBAAkB,MAAlBA,0BAAkB;IAAEC,WAAW,MAAXA,mBAAW;IAAEC,iBAAiB,MAAjBA,yBAAiB;IAAEC,UAAU,MAAVA,kBAAU;IAC7OC,SAAS,MAATA,iBAAS;IAAEC,QAAQ,MAARA,gBAAQ;IAAEC,WAAW,MAAXA,mBAAW;IAChCC,KAAK,MAALA,aAAK;IAAEC,qBAAqB,MAArBA,6BAAqB;IAAEC,yBAAyB,MAAzBA,iCAAyB;IAAEC,aAAa,MAAbA,qBAAa;IAAEC,cAAc,MAAdA,sBAAc;IAAEC,aAAa,MAAbA,qBAAa;IAAEC,wBAAwB,MAAxBA,gCAAwB;IAAEC,IAAI,MAAJA,YAAI;IAAEC,mBAAmB,MAAnBA,2BAAmB;IAC1JC,2BAA2B,MAA3BA,mCAA2B;IAAEC,eAAe,MAAfA,uBAAe;IAAEC,eAAe,MAAfA,uBAAe;IAC7DC,YAAY,MAAZA,oBAAY;IAAEC,YAAY,MAAZA,oBAAY;IAAEC,oBAAoB,MAApBA,4BAAoB;;
|
1
|
+
{"version":3,"sources":["index.js"],"sourcesContent":["export { getSlots, getSlotsNext, resolveShorthand, isResolvedShorthand, SLOT_RENDER_FUNCTION_SYMBOL } from './compose/index';\nexport { IdPrefixProvider, resetIdsForTests, useControllableState, useEventCallback, useFirstMount, useForceUpdate, useId, useIsomorphicLayoutEffect, useMergedRefs, useOnClickOutside, useOnScrollOutside, usePrevious, useScrollbarWidth, useTimeout } from './hooks/index';\nexport { canUseDOM, useIsSSR, SSRProvider } from './ssr/index';\nexport { clamp, getNativeElementProps, getPartitionedNativeProps, getRTLSafeKey, mergeCallbacks, isHTMLElement, isInteractiveHTMLElement, omit, createPriorityQueue } from './utils/index';\nexport { applyTriggerPropsToChildren, getTriggerChild, isFluentTrigger } from './trigger/index';\nexport { isTouchEvent, isMouseEvent, getEventClientCoords } from './events/index';\nexport { useSelection } from './selection/index';\n"],"names":["getSlots","getSlotsNext","resolveShorthand","isResolvedShorthand","SLOT_RENDER_FUNCTION_SYMBOL","IdPrefixProvider","resetIdsForTests","useControllableState","useEventCallback","useFirstMount","useForceUpdate","useId","useIsomorphicLayoutEffect","useMergedRefs","useOnClickOutside","useOnScrollOutside","usePrevious","useScrollbarWidth","useTimeout","canUseDOM","useIsSSR","SSRProvider","clamp","getNativeElementProps","getPartitionedNativeProps","getRTLSafeKey","mergeCallbacks","isHTMLElement","isInteractiveHTMLElement","omit","createPriorityQueue","applyTriggerPropsToChildren","getTriggerChild","isFluentTrigger","isTouchEvent","isMouseEvent","getEventClientCoords","useSelection"],"mappings":";;;;;;;;;;;IAASA,QAAQ,MAARA,eAAQ;IAAEC,YAAY,MAAZA,mBAAY;IAAEC,gBAAgB,MAAhBA,uBAAgB;IAAEC,mBAAmB,MAAnBA,0BAAmB;IAAEC,2BAA2B,MAA3BA,kCAA2B;IAC1FC,gBAAgB,MAAhBA,wBAAgB;IAAEC,gBAAgB,MAAhBA,wBAAgB;IAAEC,oBAAoB,MAApBA,4BAAoB;IAAEC,gBAAgB,MAAhBA,wBAAgB;IAAEC,aAAa,MAAbA,qBAAa;IAAEC,cAAc,MAAdA,sBAAc;IAAEC,KAAK,MAALA,aAAK;IAAEC,yBAAyB,MAAzBA,iCAAyB;IAAEC,aAAa,MAAbA,qBAAa;IAAEC,iBAAiB,MAAjBA,yBAAiB;IAAEC,kBAAkB,MAAlBA,0BAAkB;IAAEC,WAAW,MAAXA,mBAAW;IAAEC,iBAAiB,MAAjBA,yBAAiB;IAAEC,UAAU,MAAVA,kBAAU;IAC7OC,SAAS,MAATA,iBAAS;IAAEC,QAAQ,MAARA,gBAAQ;IAAEC,WAAW,MAAXA,mBAAW;IAChCC,KAAK,MAALA,aAAK;IAAEC,qBAAqB,MAArBA,6BAAqB;IAAEC,yBAAyB,MAAzBA,iCAAyB;IAAEC,aAAa,MAAbA,qBAAa;IAAEC,cAAc,MAAdA,sBAAc;IAAEC,aAAa,MAAbA,qBAAa;IAAEC,wBAAwB,MAAxBA,gCAAwB;IAAEC,IAAI,MAAJA,YAAI;IAAEC,mBAAmB,MAAnBA,2BAAmB;IAC1JC,2BAA2B,MAA3BA,mCAA2B;IAAEC,eAAe,MAAfA,uBAAe;IAAEC,eAAe,MAAfA,uBAAe;IAC7DC,YAAY,MAAZA,oBAAY;IAAEC,YAAY,MAAZA,oBAAY;IAAEC,oBAAoB,MAApBA,4BAAoB;IAChDC,YAAY,MAAZA,oBAAY;;uBANsF;wBACmJ;wBAC7M;wBAC0H;wBAC7F;wBACb;wBACpC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["index.js"],"sourcesContent":["export * from './types';\nexport * from './useSelection';\n"],"names":[],"mappings":";;;;;oBAAc;oBACA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["types.js"],"sourcesContent":["import * as React from 'react';\n"],"names":[],"mappings":";;;;;6DAAuB"}
|
@@ -0,0 +1,122 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
Object.defineProperty(exports, "useSelection", {
|
6
|
+
enumerable: true,
|
7
|
+
get: ()=>useSelection
|
8
|
+
});
|
9
|
+
const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
|
10
|
+
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
11
|
+
const _useControllableState = require("../hooks/useControllableState");
|
12
|
+
const _createSetFromIterable = require("../utils/createSetFromIterable");
|
13
|
+
function useSingleSelection(params) {
|
14
|
+
const [selected, setSelected] = (0, _useControllableState.useControllableState)({
|
15
|
+
initialState: new Set(),
|
16
|
+
defaultState: _react.useMemo(()=>params.defaultSelectedItems && (0, _createSetFromIterable.createSetFromIterable)(params.defaultSelectedItems), [
|
17
|
+
params.defaultSelectedItems
|
18
|
+
]),
|
19
|
+
state: _react.useMemo(()=>params.selectedItems && (0, _createSetFromIterable.createSetFromIterable)(params.selectedItems), [
|
20
|
+
params.selectedItems
|
21
|
+
])
|
22
|
+
});
|
23
|
+
const changeSelection = (event, nextSelectedItems)=>{
|
24
|
+
var _params_onSelectionChange;
|
25
|
+
(_params_onSelectionChange = params.onSelectionChange) === null || _params_onSelectionChange === void 0 ? void 0 : _params_onSelectionChange.call(params, event, {
|
26
|
+
selectedItems: nextSelectedItems
|
27
|
+
});
|
28
|
+
if (!event.isDefaultPrevented()) {
|
29
|
+
setSelected(nextSelectedItems);
|
30
|
+
}
|
31
|
+
};
|
32
|
+
var _selected_has;
|
33
|
+
const methods = {
|
34
|
+
deselectItem: (event)=>changeSelection(event, new Set()),
|
35
|
+
selectItem: (event, itemId)=>changeSelection(event, new Set([
|
36
|
+
itemId
|
37
|
+
])),
|
38
|
+
toggleAllItems: ()=>{
|
39
|
+
if (process.env.NODE_ENV !== 'production') {
|
40
|
+
throw new Error('[react-utilities]: `toggleAllItems` should not be used in single selection mode');
|
41
|
+
}
|
42
|
+
},
|
43
|
+
toggleItem: (event, itemId)=>changeSelection(event, new Set([
|
44
|
+
itemId
|
45
|
+
])),
|
46
|
+
clearItems: (event)=>changeSelection(event, new Set()),
|
47
|
+
isSelected: (itemId)=>(_selected_has = selected.has(itemId)) !== null && _selected_has !== void 0 ? _selected_has : false
|
48
|
+
};
|
49
|
+
return [
|
50
|
+
selected,
|
51
|
+
methods
|
52
|
+
];
|
53
|
+
}
|
54
|
+
function useMultipleSelection(params) {
|
55
|
+
const [selected, setSelected] = (0, _useControllableState.useControllableState)({
|
56
|
+
initialState: new Set(),
|
57
|
+
defaultState: _react.useMemo(()=>params.defaultSelectedItems && (0, _createSetFromIterable.createSetFromIterable)(params.defaultSelectedItems), [
|
58
|
+
params.defaultSelectedItems
|
59
|
+
]),
|
60
|
+
state: _react.useMemo(()=>params.selectedItems && (0, _createSetFromIterable.createSetFromIterable)(params.selectedItems), [
|
61
|
+
params.selectedItems
|
62
|
+
])
|
63
|
+
});
|
64
|
+
const changeSelection = (event, nextSelectedItems)=>{
|
65
|
+
var _params_onSelectionChange;
|
66
|
+
(_params_onSelectionChange = params.onSelectionChange) === null || _params_onSelectionChange === void 0 ? void 0 : _params_onSelectionChange.call(params, event, {
|
67
|
+
selectedItems: nextSelectedItems
|
68
|
+
});
|
69
|
+
if (!event.isDefaultPrevented()) {
|
70
|
+
setSelected(nextSelectedItems);
|
71
|
+
}
|
72
|
+
};
|
73
|
+
const methods = {
|
74
|
+
toggleItem: (event, itemId)=>{
|
75
|
+
const nextSelectedItems = new Set(selected);
|
76
|
+
if (selected.has(itemId)) {
|
77
|
+
nextSelectedItems.delete(itemId);
|
78
|
+
} else {
|
79
|
+
nextSelectedItems.add(itemId);
|
80
|
+
}
|
81
|
+
changeSelection(event, nextSelectedItems);
|
82
|
+
},
|
83
|
+
selectItem: (event, itemId)=>{
|
84
|
+
const nextSelectedItems = new Set(selected);
|
85
|
+
nextSelectedItems.add(itemId);
|
86
|
+
changeSelection(event, nextSelectedItems);
|
87
|
+
},
|
88
|
+
deselectItem: (event, itemId)=>{
|
89
|
+
const nextSelectedItems = new Set(selected);
|
90
|
+
nextSelectedItems.delete(itemId);
|
91
|
+
changeSelection(event, nextSelectedItems);
|
92
|
+
},
|
93
|
+
clearItems: (event)=>{
|
94
|
+
changeSelection(event, new Set());
|
95
|
+
},
|
96
|
+
isSelected: (itemId)=>selected.has(itemId),
|
97
|
+
toggleAllItems: (event, itemIds)=>{
|
98
|
+
const allItemsSelected = itemIds.every((itemId)=>selected.has(itemId));
|
99
|
+
const nextSelectedItems = new Set(selected);
|
100
|
+
if (allItemsSelected) {
|
101
|
+
nextSelectedItems.clear();
|
102
|
+
} else {
|
103
|
+
itemIds.forEach((itemId)=>nextSelectedItems.add(itemId));
|
104
|
+
}
|
105
|
+
changeSelection(event, nextSelectedItems);
|
106
|
+
}
|
107
|
+
};
|
108
|
+
return [
|
109
|
+
selected,
|
110
|
+
methods
|
111
|
+
];
|
112
|
+
}
|
113
|
+
function useSelection(params) {
|
114
|
+
if (params.selectionMode === 'multiselect') {
|
115
|
+
// selectionMode is a static value, so we can safely ignore rules-of-hooks
|
116
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
117
|
+
return useMultipleSelection(params);
|
118
|
+
}
|
119
|
+
// selectionMode is a static value, so we can safely ignore rules-of-hooks
|
120
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
121
|
+
return useSingleSelection(params);
|
122
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["useSelection.js"],"sourcesContent":["import * as React from 'react';\nimport { useControllableState } from '../hooks/useControllableState';\nimport { createSetFromIterable } from '../utils/createSetFromIterable';\nfunction useSingleSelection(params) {\n const [selected, setSelected] = useControllableState({\n initialState: new Set(),\n defaultState: React.useMemo(()=>params.defaultSelectedItems && createSetFromIterable(params.defaultSelectedItems), [\n params.defaultSelectedItems\n ]),\n state: React.useMemo(()=>params.selectedItems && createSetFromIterable(params.selectedItems), [\n params.selectedItems\n ])\n });\n const changeSelection = (event, nextSelectedItems)=>{\n var _params_onSelectionChange;\n (_params_onSelectionChange = params.onSelectionChange) === null || _params_onSelectionChange === void 0 ? void 0 : _params_onSelectionChange.call(params, event, {\n selectedItems: nextSelectedItems\n });\n if (!event.isDefaultPrevented()) {\n setSelected(nextSelectedItems);\n }\n };\n var _selected_has;\n const methods = {\n deselectItem: (event)=>changeSelection(event, new Set()),\n selectItem: (event, itemId)=>changeSelection(event, new Set([\n itemId\n ])),\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([\n itemId\n ])),\n clearItems: (event)=>changeSelection(event, new Set()),\n isSelected: (itemId)=>(_selected_has = selected.has(itemId)) !== null && _selected_has !== void 0 ? _selected_has : false\n };\n return [\n selected,\n methods\n ];\n}\nfunction useMultipleSelection(params) {\n const [selected, setSelected] = useControllableState({\n initialState: new Set(),\n defaultState: React.useMemo(()=>params.defaultSelectedItems && createSetFromIterable(params.defaultSelectedItems), [\n params.defaultSelectedItems\n ]),\n state: React.useMemo(()=>params.selectedItems && createSetFromIterable(params.selectedItems), [\n params.selectedItems\n ])\n });\n const changeSelection = (event, nextSelectedItems)=>{\n var _params_onSelectionChange;\n (_params_onSelectionChange = params.onSelectionChange) === null || _params_onSelectionChange === void 0 ? void 0 : _params_onSelectionChange.call(params, event, {\n selectedItems: nextSelectedItems\n });\n if (!event.isDefaultPrevented()) {\n setSelected(nextSelectedItems);\n }\n };\n const methods = {\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 [\n selected,\n methods\n ];\n}\nexport function useSelection(params) {\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":["useSelection","useSingleSelection","params","selected","setSelected","useControllableState","initialState","Set","defaultState","React","useMemo","defaultSelectedItems","createSetFromIterable","state","selectedItems","changeSelection","event","nextSelectedItems","_params_onSelectionChange","onSelectionChange","call","isDefaultPrevented","_selected_has","methods","deselectItem","selectItem","itemId","toggleAllItems","process","env","NODE_ENV","Error","toggleItem","clearItems","isSelected","has","useMultipleSelection","delete","add","itemIds","allItemsSelected","every","clear","forEach","selectionMode"],"mappings":";;;;+BAuGgBA;;aAAAA;;;6DAvGO;sCACc;uCACC;AACtC,SAASC,mBAAmBC,MAAM,EAAE;IAChC,MAAM,CAACC,UAAUC,YAAY,GAAGC,IAAAA,0CAAoB,EAAC;QACjDC,cAAc,IAAIC;QAClBC,cAAcC,OAAMC,OAAO,CAAC,IAAIR,OAAOS,oBAAoB,IAAIC,IAAAA,4CAAqB,EAACV,OAAOS,oBAAoB,GAAG;YAC/GT,OAAOS,oBAAoB;SAC9B;QACDE,OAAOJ,OAAMC,OAAO,CAAC,IAAIR,OAAOY,aAAa,IAAIF,IAAAA,4CAAqB,EAACV,OAAOY,aAAa,GAAG;YAC1FZ,OAAOY,aAAa;SACvB;IACL;IACA,MAAMC,kBAAkB,CAACC,OAAOC,oBAAoB;QAChD,IAAIC;QACHA,CAAAA,4BAA4BhB,OAAOiB,iBAAiB,AAAD,MAAO,IAAI,IAAID,8BAA8B,KAAK,IAAI,KAAK,IAAIA,0BAA0BE,IAAI,CAAClB,QAAQc,OAAO;YAC7JF,eAAeG;QACnB,EAAE;QACF,IAAI,CAACD,MAAMK,kBAAkB,IAAI;YAC7BjB,YAAYa;QAChB,CAAC;IACL;IACA,IAAIK;IACJ,MAAMC,UAAU;QACZC,cAAc,CAACR,QAAQD,gBAAgBC,OAAO,IAAIT;QAClDkB,YAAY,CAACT,OAAOU,SAASX,gBAAgBC,OAAO,IAAIT,IAAI;gBACpDmB;aACH;QACLC,gBAAgB,IAAI;YAChB,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;gBACvC,MAAM,IAAIC,MAAM,mFAAmF;YACvG,CAAC;QACL;QACAC,YAAY,CAAChB,OAAOU,SAASX,gBAAgBC,OAAO,IAAIT,IAAI;gBACpDmB;aACH;QACLO,YA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G,CAACZ;YACtBX,gBAAgBC,OAAOC;QAC3B;QACAO,cAAc,CAACR,OAAOU,SAAS;YAC3B,MAAMT,oBAAoB,IAAIV,IAAIJ;YAClCc,kBAAkBoB,MAAM,CAACX;YACzBX,gBAAgBC,OAAOC;QAC3B;QACAgB,YAAY,CAACjB,QAAQ;YACjBD,gBAAgBC,OAAO,IAAIT;QAC/B;QACA2B,YAAY,CAACR,SAASvB,SAASgC,GAAG,CAACT;QACnCC,gBAAgB,CAACX,OAAOuB,UAAU;YAC9B,MAAMC,mBAAmBD,QAAQE,KAAK,CAAC,CAACf,SAASvB,SAASgC,GAAG,CAACT;YAC9D,MAAMT,oBAAoB,IAAIV,IAAIJ;YAClC,IAAIqC,kBAAkB;gBAClBvB,kBAAkByB,KAAK;YAC3B,OAAO;gBACHH,QAAQI,OAAO,CAAC,CAACjB,SAAST,kBAAkBqB,GAAG,CAACZ;YACpD,CAAC;YACDX,gBAAgBC,OAAOC;QAC3B;IACJ;IACA,OAAO;QACHd;QACAoB;KACH;AACL;AACO,SAASvB,aAAaE,MAAM,EAAE;IACjC,IAAIA,OAAO0C,aAAa,KAAK,eAAe;QACxC,0EAA0E;QAC1E,sDAAsD;QACtD,OAAOR,qBAAqBlC;IAChC,CAAC;IACD,0EAA0E;IAC1E,sDAAsD;IACtD,OAAOD,mBAAmBC;AAC9B"}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/**
|
2
|
+
* Creates a set from a given iterable, in case the iterable is a set itself, returns the given set instead.
|
3
|
+
*/ "use strict";
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
Object.defineProperty(exports, "createSetFromIterable", {
|
8
|
+
enumerable: true,
|
9
|
+
get: ()=>createSetFromIterable
|
10
|
+
});
|
11
|
+
function createSetFromIterable(iterable) {
|
12
|
+
return iterable instanceof Set ? iterable : new Set(iterable);
|
13
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["createSetFromIterable.js"],"sourcesContent":["/**\n * Creates a set from a given iterable, in case the iterable is a set itself, returns the given set instead.\n */ export function createSetFromIterable(iterable) {\n return iterable instanceof Set ? iterable : new Set(iterable);\n}\n"],"names":["createSetFromIterable","iterable","Set"],"mappings":"AAAA;;CAEC;;;;+BAAmBA;;aAAAA;;AAAT,SAASA,sBAAsBC,QAAQ,EAAE;IAChD,OAAOA,oBAAoBC,MAAMD,WAAW,IAAIC,IAAID,SAAS;AACjE"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fluentui/react-utilities",
|
3
|
-
"version": "9.
|
3
|
+
"version": "9.10.0",
|
4
4
|
"description": "A set of general React-specific utilities.",
|
5
5
|
"main": "lib-commonjs/index.js",
|
6
6
|
"module": "lib/index.js",
|
@@ -21,7 +21,9 @@
|
|
21
21
|
"test": "jest --passWithNoTests",
|
22
22
|
"type-check": "tsc -b tsconfig.json",
|
23
23
|
"generate-api": "just-scripts generate-api",
|
24
|
-
"test-ssr": "test-ssr \"./stories/**/*.stories.tsx\""
|
24
|
+
"test-ssr": "test-ssr \"./stories/**/*.stories.tsx\"",
|
25
|
+
"e2e": "cypress run --component",
|
26
|
+
"e2e:local": "cypress open --component"
|
25
27
|
},
|
26
28
|
"devDependencies": {
|
27
29
|
"@fluentui/eslint-plugin": "*",
|