@fluentui/react-utilities 9.18.9 → 9.18.11
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.md +21 -2
- package/lib/hooks/useAnimationFrame.js +5 -5
- package/lib/hooks/useAnimationFrame.js.map +1 -1
- package/lib/hooks/useControllableState.js +13 -1
- package/lib/hooks/useControllableState.js.map +1 -1
- package/lib/hooks/useId.js +1 -0
- package/lib/hooks/useId.js.map +1 -1
- package/lib/hooks/useMergedRefs.js +1 -0
- package/lib/hooks/useMergedRefs.js.map +1 -1
- package/lib/hooks/useTimeout.js +8 -2
- package/lib/hooks/useTimeout.js.map +1 -1
- package/lib/selection/useSelection.js +1 -0
- package/lib/selection/useSelection.js.map +1 -1
- package/lib-commonjs/hooks/useAnimationFrame.js +5 -5
- package/lib-commonjs/hooks/useAnimationFrame.js.map +1 -1
- package/lib-commonjs/hooks/useControllableState.js +13 -1
- package/lib-commonjs/hooks/useControllableState.js.map +1 -1
- package/lib-commonjs/hooks/useId.js +1 -0
- package/lib-commonjs/hooks/useId.js.map +1 -1
- package/lib-commonjs/hooks/useMergedRefs.js +1 -0
- package/lib-commonjs/hooks/useMergedRefs.js.map +1 -1
- package/lib-commonjs/hooks/useTimeout.js +8 -2
- package/lib-commonjs/hooks/useTimeout.js.map +1 -1
- package/lib-commonjs/selection/useSelection.js +1 -0
- package/lib-commonjs/selection/useSelection.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
@@ -1,12 +1,31 @@
|
|
1
1
|
# Change Log - @fluentui/react-utilities
|
2
2
|
|
3
|
-
This log was last generated on Mon,
|
3
|
+
This log was last generated on Mon, 01 Jul 2024 20:25:52 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
+
## [9.18.11](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.18.11)
|
8
|
+
|
9
|
+
Mon, 01 Jul 2024 20:25:52 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.18.10..@fluentui/react-utilities_v9.18.11)
|
11
|
+
|
12
|
+
### Patches
|
13
|
+
|
14
|
+
- chore: add eslint react-compiler ([PR #31457](https://github.com/microsoft/fluentui/pull/31457) by seanmonahan@microsoft.com)
|
15
|
+
|
16
|
+
## [9.18.10](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.18.10)
|
17
|
+
|
18
|
+
Thu, 06 Jun 2024 15:26:43 GMT
|
19
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.18.9..@fluentui/react-utilities_v9.18.10)
|
20
|
+
|
21
|
+
### Patches
|
22
|
+
|
23
|
+
- chore: useControllableState warns if controlled and uncontrolled at the same time ([PR #31461](https://github.com/microsoft/fluentui/pull/31461) by bernardo.sunderhus@gmail.com)
|
24
|
+
- fix: use globals from Fluent context. ([PR #30967](https://github.com/microsoft/fluentui/pull/30967) by seanmonahan@microsoft.com)
|
25
|
+
|
7
26
|
## [9.18.9](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.18.9)
|
8
27
|
|
9
|
-
Mon, 20 May 2024 12:
|
28
|
+
Mon, 20 May 2024 12:45:09 GMT
|
10
29
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.18.8..@fluentui/react-utilities_v9.18.9)
|
11
30
|
|
12
31
|
### Patches
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { canUseDOM } from '../ssr/canUseDOM';
|
2
1
|
import { useBrowserTimer } from './useBrowserTimer';
|
2
|
+
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
|
3
3
|
const setAnimationFrameNoop = (callback)=>{
|
4
4
|
callback(0);
|
5
5
|
return 0;
|
@@ -13,9 +13,9 @@ const cancelAnimationFrameNoop = (handle)=>handle;
|
|
13
13
|
*
|
14
14
|
* @returns A pair of [requestAnimationFrame, cancelAnimationFrame] that are stable between renders.
|
15
15
|
*/ export function useAnimationFrame() {
|
16
|
-
const
|
17
|
-
|
18
|
-
const setAnimationFrame =
|
19
|
-
const clearAnimationFrame =
|
16
|
+
const { targetDocument } = useFluent();
|
17
|
+
const win = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView;
|
18
|
+
const setAnimationFrame = win ? win.requestAnimationFrame : setAnimationFrameNoop;
|
19
|
+
const clearAnimationFrame = win ? win.cancelAnimationFrame : cancelAnimationFrameNoop;
|
20
20
|
return useBrowserTimer(setAnimationFrame, clearAnimationFrame);
|
21
21
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useAnimationFrame.ts"],"sourcesContent":["import {
|
1
|
+
{"version":3,"sources":["useAnimationFrame.ts"],"sourcesContent":["import { useBrowserTimer } from './useBrowserTimer';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nconst setAnimationFrameNoop = (callback: FrameRequestCallback) => {\n callback(0);\n return 0;\n};\nconst cancelAnimationFrameNoop = (handle: number) => handle;\n\n/**\n * @internal\n * Helper to manage a browser requestAnimationFrame.\n * Ensures that the requestAnimationFrame isn't set multiple times at once and is cleaned up\n * when the component is unloaded.\n *\n * @returns A pair of [requestAnimationFrame, cancelAnimationFrame] that are stable between renders.\n */\nexport function useAnimationFrame() {\n const { targetDocument } = useFluent();\n const win = targetDocument?.defaultView;\n\n const setAnimationFrame = win ? win.requestAnimationFrame : setAnimationFrameNoop;\n const clearAnimationFrame = win ? win.cancelAnimationFrame : cancelAnimationFrameNoop;\n\n return useBrowserTimer(setAnimationFrame, clearAnimationFrame);\n}\n"],"names":["useBrowserTimer","useFluent_unstable","useFluent","setAnimationFrameNoop","callback","cancelAnimationFrameNoop","handle","useAnimationFrame","targetDocument","win","defaultView","setAnimationFrame","requestAnimationFrame","clearAnimationFrame","cancelAnimationFrame"],"mappings":"AAAA,SAASA,eAAe,QAAQ,oBAAoB;AACpD,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAElF,MAAMC,wBAAwB,CAACC;IAC7BA,SAAS;IACT,OAAO;AACT;AACA,MAAMC,2BAA2B,CAACC,SAAmBA;AAErD;;;;;;;CAOC,GACD,OAAO,SAASC;IACd,MAAM,EAAEC,cAAc,EAAE,GAAGN;IAC3B,MAAMO,MAAMD,2BAAAA,qCAAAA,eAAgBE,WAAW;IAEvC,MAAMC,oBAAoBF,MAAMA,IAAIG,qBAAqB,GAAGT;IAC5D,MAAMU,sBAAsBJ,MAAMA,IAAIK,oBAAoB,GAAGT;IAE7D,OAAOL,gBAAgBW,mBAAmBE;AAC5C"}
|
@@ -19,6 +19,17 @@ function isFactoryDispatch(newState) {
|
|
19
19
|
* Meaning that if a state is `controlled`, calls to the dispatcher do not modify the state.
|
20
20
|
*
|
21
21
|
*/ export const useControllableState = (options)=>{
|
22
|
+
'use no memo';
|
23
|
+
if (process.env.NODE_ENV !== 'production') {
|
24
|
+
if (options.state !== undefined && options.defaultState !== undefined) {
|
25
|
+
// eslint-disable-next-line no-console
|
26
|
+
console.error(`@fluentui/react-utilities [useControllableState]:
|
27
|
+
A component must be either controlled or uncontrolled (specify either the state or the defaultState, but not both).
|
28
|
+
Decide between using a controlled or uncontrolled component and remove one of this props.
|
29
|
+
More info: https://reactjs.org/link/controlled-components
|
30
|
+
${new Error().stack}`);
|
31
|
+
}
|
32
|
+
}
|
22
33
|
const [internalState, setInternalState] = React.useState(()=>{
|
23
34
|
if (options.defaultState === undefined) {
|
24
35
|
return options.initialState;
|
@@ -54,6 +65,7 @@ function isInitializer(value) {
|
|
54
65
|
* Prints an error when isControlled value switches between subsequent renders
|
55
66
|
* @returns - whether the value is controlled
|
56
67
|
*/ const useIsControlled = (controlledValue)=>{
|
68
|
+
'use no memo';
|
57
69
|
const [isControlled] = React.useState(()=>controlledValue !== undefined);
|
58
70
|
if (process.env.NODE_ENV !== 'production') {
|
59
71
|
// We don't want these warnings in production even though it is against native behaviour
|
@@ -64,7 +76,7 @@ function isInitializer(value) {
|
|
64
76
|
const controlWarning = isControlled ? 'a controlled value to be uncontrolled' : 'an uncontrolled value to be controlled';
|
65
77
|
const undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined';
|
66
78
|
// eslint-disable-next-line no-console
|
67
|
-
console.error(`@fluentui/react-utilities [
|
79
|
+
console.error(`@fluentui/react-utilities [useControllableState]:
|
68
80
|
A component is changing ${controlWarning}. This is likely caused by the value changing from ${undefinedWarning} value, which should not happen.
|
69
81
|
Decide between using a controlled or uncontrolled input element for the lifetime of the component.
|
70
82
|
More info: https://reactjs.org/link/controlled-components
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useControllableState.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n */\nexport type UseControllableStateOptions<State> = {\n /**\n * User-provided default state or initializer, for uncontrolled usage.\n */\n defaultState?: State | (() => State);\n /**\n * User-provided controlled state. `undefined` means internal state will be used.\n */\n state: State | undefined;\n /**\n * Used as the initial state if `state` and `defaultState` are both `undefined`.\n * If `undefined` is the correct initial state, pass that here.\n */\n initialState: State;\n};\n\nfunction isFactoryDispatch<State>(newState: React.SetStateAction<State>): newState is (prevState: State) => State {\n return typeof newState === 'function';\n}\n\n/**\n * @internal\n *\n * A [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate)-like hook\n * to manage a value that could be either `controlled` or `uncontrolled`,\n * such as a checked state or text input string.\n *\n * @see https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components for more details on `controlled`/`uncontrolled`\n *\n * @returns an array of the current value and an updater (dispatcher) function.\n * The updater function is referentially stable (won't change during the component's lifecycle).\n * It can take either a new value, or a function which is passed the previous value and returns the new value.\n *\n * ❗️❗️ Calls to the dispatcher will only modify the state if the state is `uncontrolled`.\n * Meaning that if a state is `controlled`, calls to the dispatcher do not modify the state.\n *\n */\nexport const useControllableState = <State>(\n options: UseControllableStateOptions<State>,\n): [State, React.Dispatch<React.SetStateAction<State>>] => {\n const [internalState, setInternalState] = React.useState<State>(() => {\n if (options.defaultState === undefined) {\n return options.initialState;\n }\n return isInitializer(options.defaultState) ? options.defaultState() : options.defaultState;\n });\n\n // Heads up!\n // This part is specific for controlled mode and mocks behavior of React dispatcher function.\n\n const stateValueRef = React.useRef<State | undefined>(options.state);\n\n React.useEffect(() => {\n stateValueRef.current = options.state;\n }, [options.state]);\n\n const setControlledState = React.useCallback((newState: React.SetStateAction<State>) => {\n if (isFactoryDispatch(newState)) {\n newState(stateValueRef.current as State);\n }\n }, []);\n\n return useIsControlled(options.state) ? [options.state, setControlledState] : [internalState, setInternalState];\n};\n\nfunction isInitializer<State>(value: State | (() => State)): value is () => State {\n return typeof value === 'function';\n}\n\n/**\n * Helper hook to handle previous comparison of controlled/uncontrolled\n * Prints an error when isControlled value switches between subsequent renders\n * @returns - whether the value is controlled\n */\nconst useIsControlled = <V>(controlledValue: V | undefined): controlledValue is V => {\n const [isControlled] = React.useState<boolean>(() => controlledValue !== undefined);\n\n if (process.env.NODE_ENV !== 'production') {\n // We don't want these warnings in production even though it is against native behaviour\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (isControlled !== (controlledValue !== undefined)) {\n const error = new Error();\n\n const controlWarning = isControlled\n ? 'a controlled value to be uncontrolled'\n : 'an uncontrolled value to be controlled';\n\n const undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined';\n\n // eslint-disable-next-line no-console\n console.error(/** #__DE-INDENT__ */ `\n @fluentui/react-utilities [
|
1
|
+
{"version":3,"sources":["useControllableState.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n */\nexport type UseControllableStateOptions<State> = {\n /**\n * User-provided default state or initializer, for uncontrolled usage.\n */\n defaultState?: State | (() => State);\n /**\n * User-provided controlled state. `undefined` means internal state will be used.\n */\n state: State | undefined;\n /**\n * Used as the initial state if `state` and `defaultState` are both `undefined`.\n * If `undefined` is the correct initial state, pass that here.\n */\n initialState: State;\n};\n\nfunction isFactoryDispatch<State>(newState: React.SetStateAction<State>): newState is (prevState: State) => State {\n return typeof newState === 'function';\n}\n\n/**\n * @internal\n *\n * A [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate)-like hook\n * to manage a value that could be either `controlled` or `uncontrolled`,\n * such as a checked state or text input string.\n *\n * @see https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components for more details on `controlled`/`uncontrolled`\n *\n * @returns an array of the current value and an updater (dispatcher) function.\n * The updater function is referentially stable (won't change during the component's lifecycle).\n * It can take either a new value, or a function which is passed the previous value and returns the new value.\n *\n * ❗️❗️ Calls to the dispatcher will only modify the state if the state is `uncontrolled`.\n * Meaning that if a state is `controlled`, calls to the dispatcher do not modify the state.\n *\n */\nexport const useControllableState = <State>(\n options: UseControllableStateOptions<State>,\n): [State, React.Dispatch<React.SetStateAction<State>>] => {\n 'use no memo';\n\n if (process.env.NODE_ENV !== 'production') {\n if (options.state !== undefined && options.defaultState !== undefined) {\n // eslint-disable-next-line no-console\n console.error(/** #__DE-INDENT__ */ `\n @fluentui/react-utilities [useControllableState]:\n A component must be either controlled or uncontrolled (specify either the state or the defaultState, but not both).\n Decide between using a controlled or uncontrolled component and remove one of this props.\n More info: https://reactjs.org/link/controlled-components\n ${new Error().stack}\n `);\n }\n }\n const [internalState, setInternalState] = React.useState<State>(() => {\n if (options.defaultState === undefined) {\n return options.initialState;\n }\n return isInitializer(options.defaultState) ? options.defaultState() : options.defaultState;\n });\n\n // Heads up!\n // This part is specific for controlled mode and mocks behavior of React dispatcher function.\n\n const stateValueRef = React.useRef<State | undefined>(options.state);\n\n React.useEffect(() => {\n stateValueRef.current = options.state;\n }, [options.state]);\n\n const setControlledState = React.useCallback((newState: React.SetStateAction<State>) => {\n if (isFactoryDispatch(newState)) {\n newState(stateValueRef.current as State);\n }\n }, []);\n\n return useIsControlled(options.state) ? [options.state, setControlledState] : [internalState, setInternalState];\n};\n\nfunction isInitializer<State>(value: State | (() => State)): value is () => State {\n return typeof value === 'function';\n}\n\n/**\n * Helper hook to handle previous comparison of controlled/uncontrolled\n * Prints an error when isControlled value switches between subsequent renders\n * @returns - whether the value is controlled\n */\nconst useIsControlled = <V>(controlledValue: V | undefined): controlledValue is V => {\n 'use no memo';\n\n const [isControlled] = React.useState<boolean>(() => controlledValue !== undefined);\n\n if (process.env.NODE_ENV !== 'production') {\n // We don't want these warnings in production even though it is against native behaviour\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (isControlled !== (controlledValue !== undefined)) {\n const error = new Error();\n\n const controlWarning = isControlled\n ? 'a controlled value to be uncontrolled'\n : 'an uncontrolled value to be controlled';\n\n const undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined';\n\n // eslint-disable-next-line no-console\n console.error(/** #__DE-INDENT__ */ `\n @fluentui/react-utilities [useControllableState]:\n A component is changing ${controlWarning}. This is likely caused by the value changing from ${undefinedWarning} value, which should not happen.\n Decide between using a controlled or uncontrolled input element for the lifetime of the component.\n More info: https://reactjs.org/link/controlled-components\n ${error.stack}\n `);\n }\n }, [isControlled, controlledValue]);\n }\n\n return isControlled;\n};\n"],"names":["React","isFactoryDispatch","newState","useControllableState","options","process","env","NODE_ENV","state","undefined","defaultState","console","error","Error","stack","internalState","setInternalState","useState","initialState","isInitializer","stateValueRef","useRef","useEffect","current","setControlledState","useCallback","useIsControlled","value","controlledValue","isControlled","controlWarning","undefinedWarning"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAqB/B,SAASC,kBAAyBC,QAAqC;IACrE,OAAO,OAAOA,aAAa;AAC7B;AAEA;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,MAAMC,uBAAuB,CAClCC;IAEA;IAEA,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,IAAIH,QAAQI,KAAK,KAAKC,aAAaL,QAAQM,YAAY,KAAKD,WAAW;YACrE,sCAAsC;YACtCE,QAAQC,KAAK,CAAuB,CAAC;;;;AAKrC,EAAE,IAAIC,QAAQC,KAAK,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EC,iBAAiB;;;AAG/G,EAAEnB,MAAME,KAAK,CAAC,AAChB,CAAC;YACH;QACF,GAAG;YAACe;YAAcD;SAAgB;IACpC;IAEA,OAAOC;AACT"}
|
package/lib/hooks/useId.js
CHANGED
@@ -21,6 +21,7 @@ function useIdPrefix() {
|
|
21
21
|
* without conditioning the hook call
|
22
22
|
* @returns The ID
|
23
23
|
*/ export function useId(prefix = 'fui-', providedId) {
|
24
|
+
'use no memo';
|
24
25
|
const contextValue = useSSRContext();
|
25
26
|
const idPrefix = useIdPrefix();
|
26
27
|
// Checking if useId is available on React, if it is, we use it to generate the id. String concatenation is used to
|
package/lib/hooks/useId.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useId.ts"],"sourcesContent":["import * as React from 'react';\nimport { defaultSSRContextValue, useSSRContext } from '../ssr/index';\n\nconst IdPrefixContext = React.createContext<string | undefined>(undefined);\n\n/**\n * Allows to define a prefix that will be used for all IDs generated by useId() hook. It's useful to avoid collisions\n * between different bundles.\n */\nexport const IdPrefixProvider = IdPrefixContext.Provider;\n\nfunction useIdPrefix(): string {\n return React.useContext(IdPrefixContext) || '';\n}\n\n/**\n * Resets generated IDs, should be used only in tests.\n */\nexport function resetIdsForTests(): void {\n defaultSSRContextValue.current = 0;\n}\n\n/**\n * Hook to generate a unique ID.\n *\n * @param prefix - Optional prefix for the ID. Defaults to 'fui-'.\n * @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,\n * without conditioning the hook call\n * @returns The ID\n */\nexport function useId(prefix: string = 'fui-', providedId?: string): string {\n const contextValue = useSSRContext();\n const idPrefix = useIdPrefix();\n\n // Checking if useId is available on React, if it is, we use it to generate the id. String concatenation is used to\n // prevent bundlers from complaining with older versions of React.\n const _useId = (React as never)['use' + 'Id'] as (() => string) | undefined;\n\n if (_useId) {\n const generatedId = _useId();\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const escapedId = React.useMemo(() => generatedId.replace(/:/g, ''), [generatedId]);\n\n return providedId || `${idPrefix}${prefix}${escapedId}`;\n }\n\n // Hooks appear to be running conditionally, but they will always run in the same order since it's based on\n // the version of React being used. This is safe to ignore.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return React.useMemo(() => {\n if (providedId) {\n return providedId;\n }\n\n return `${idPrefix}${prefix}${++contextValue.current}`;\n }, [idPrefix, prefix, providedId, contextValue]);\n}\n"],"names":["React","defaultSSRContextValue","useSSRContext","IdPrefixContext","createContext","undefined","IdPrefixProvider","Provider","useIdPrefix","useContext","resetIdsForTests","current","useId","prefix","providedId","contextValue","idPrefix","_useId","generatedId","escapedId","useMemo","replace"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,sBAAsB,EAAEC,aAAa,QAAQ,eAAe;AAErE,MAAMC,kBAAkBH,MAAMI,aAAa,CAAqBC;AAEhE;;;CAGC,GACD,OAAO,MAAMC,mBAAmBH,gBAAgBI,QAAQ,CAAC;AAEzD,SAASC;IACP,OAAOR,MAAMS,UAAU,CAACN,oBAAoB;AAC9C;AAEA;;CAEC,GACD,OAAO,SAASO;IACdT,uBAAuBU,OAAO,GAAG;AACnC;AAEA;;;;;;;CAOC,GACD,OAAO,SAASC,MAAMC,SAAiB,MAAM,EAAEC,UAAmB;IAChE,MAAMC,eAAeb;IACrB,MAAMc,WAAWR;IAEjB,mHAAmH;IACnH,kEAAkE;IAClE,MAAMS,SAAS,AAACjB,KAAe,CAAC,QAAQ,KAAK;IAE7C,IAAIiB,QAAQ;QACV,MAAMC,cAAcD;QAEpB,sDAAsD;QACtD,MAAME,YAAYnB,MAAMoB,OAAO,CAAC,IAAMF,YAAYG,OAAO,CAAC,MAAM,KAAK;YAACH;SAAY;QAElF,OAAOJ,cAAc,CAAC,EAAEE,SAAS,EAAEH,OAAO,EAAEM,UAAU,CAAC;IACzD;IAEA,2GAA2G;IAC3G,2DAA2D;IAC3D,sDAAsD;IACtD,OAAOnB,MAAMoB,OAAO,CAAC;QACnB,IAAIN,YAAY;YACd,OAAOA;QACT;QAEA,OAAO,CAAC,EAAEE,SAAS,EAAEH,OAAO,EAAE,EAAEE,aAAaJ,OAAO,CAAC,CAAC;IACxD,GAAG;QAACK;QAAUH;QAAQC;QAAYC;KAAa;AACjD"}
|
1
|
+
{"version":3,"sources":["useId.ts"],"sourcesContent":["import * as React from 'react';\nimport { defaultSSRContextValue, useSSRContext } from '../ssr/index';\n\nconst IdPrefixContext = React.createContext<string | undefined>(undefined);\n\n/**\n * Allows to define a prefix that will be used for all IDs generated by useId() hook. It's useful to avoid collisions\n * between different bundles.\n */\nexport const IdPrefixProvider = IdPrefixContext.Provider;\n\nfunction useIdPrefix(): string {\n return React.useContext(IdPrefixContext) || '';\n}\n\n/**\n * Resets generated IDs, should be used only in tests.\n */\nexport function resetIdsForTests(): void {\n defaultSSRContextValue.current = 0;\n}\n\n/**\n * Hook to generate a unique ID.\n *\n * @param prefix - Optional prefix for the ID. Defaults to 'fui-'.\n * @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,\n * without conditioning the hook call\n * @returns The ID\n */\nexport function useId(prefix: string = 'fui-', providedId?: string): string {\n 'use no memo';\n\n const contextValue = useSSRContext();\n const idPrefix = useIdPrefix();\n\n // Checking if useId is available on React, if it is, we use it to generate the id. String concatenation is used to\n // prevent bundlers from complaining with older versions of React.\n const _useId = (React as never)['use' + 'Id'] as (() => string) | undefined;\n\n if (_useId) {\n const generatedId = _useId();\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const escapedId = React.useMemo(() => generatedId.replace(/:/g, ''), [generatedId]);\n\n return providedId || `${idPrefix}${prefix}${escapedId}`;\n }\n\n // Hooks appear to be running conditionally, but they will always run in the same order since it's based on\n // the version of React being used. This is safe to ignore.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return React.useMemo(() => {\n if (providedId) {\n return providedId;\n }\n\n return `${idPrefix}${prefix}${++contextValue.current}`;\n }, [idPrefix, prefix, providedId, contextValue]);\n}\n"],"names":["React","defaultSSRContextValue","useSSRContext","IdPrefixContext","createContext","undefined","IdPrefixProvider","Provider","useIdPrefix","useContext","resetIdsForTests","current","useId","prefix","providedId","contextValue","idPrefix","_useId","generatedId","escapedId","useMemo","replace"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,sBAAsB,EAAEC,aAAa,QAAQ,eAAe;AAErE,MAAMC,kBAAkBH,MAAMI,aAAa,CAAqBC;AAEhE;;;CAGC,GACD,OAAO,MAAMC,mBAAmBH,gBAAgBI,QAAQ,CAAC;AAEzD,SAASC;IACP,OAAOR,MAAMS,UAAU,CAACN,oBAAoB;AAC9C;AAEA;;CAEC,GACD,OAAO,SAASO;IACdT,uBAAuBU,OAAO,GAAG;AACnC;AAEA;;;;;;;CAOC,GACD,OAAO,SAASC,MAAMC,SAAiB,MAAM,EAAEC,UAAmB;IAChE;IAEA,MAAMC,eAAeb;IACrB,MAAMc,WAAWR;IAEjB,mHAAmH;IACnH,kEAAkE;IAClE,MAAMS,SAAS,AAACjB,KAAe,CAAC,QAAQ,KAAK;IAE7C,IAAIiB,QAAQ;QACV,MAAMC,cAAcD;QAEpB,sDAAsD;QACtD,MAAME,YAAYnB,MAAMoB,OAAO,CAAC,IAAMF,YAAYG,OAAO,CAAC,MAAM,KAAK;YAACH;SAAY;QAElF,OAAOJ,cAAc,CAAC,EAAEE,SAAS,EAAEH,OAAO,EAAEM,UAAU,CAAC;IACzD;IAEA,2GAA2G;IAC3G,2DAA2D;IAC3D,sDAAsD;IACtD,OAAOnB,MAAMoB,OAAO,CAAC;QACnB,IAAIN,YAAY;YACd,OAAOA;QACT;QAEA,OAAO,CAAC,EAAEE,SAAS,EAAEH,OAAO,EAAE,EAAEE,aAAaJ,OAAO,CAAC,CAAC;IACxD,GAAG;QAACK;QAAUH;QAAQC;QAAYC;KAAa;AACjD"}
|
@@ -5,6 +5,7 @@ import * as React from 'react';
|
|
5
5
|
* @param refs - Refs to collectively update with one ref value.
|
6
6
|
* @returns A function with an attached "current" prop, so that it can be treated like a RefObject.
|
7
7
|
*/ export function useMergedRefs(...refs) {
|
8
|
+
'use no memo';
|
8
9
|
const mergedCallback = React.useCallback((value)=>{
|
9
10
|
// Update the "current" prop hanging on the function.
|
10
11
|
mergedCallback.current = value;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useMergedRefs.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * A Ref function which can be treated like a ref object in that it has an attached\n * current property, which will be updated as the ref is evaluated.\n */\nexport type RefObjectFunction<T> = React.RefObject<T> & ((value: T) => void);\n\n/**\n * React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that\n * updates all provided refs\n * @param refs - Refs to collectively update with one ref value.\n * @returns A function with an attached \"current\" prop, so that it can be treated like a RefObject.\n */\nexport function useMergedRefs<T>(...refs: (React.Ref<T> | undefined)[]): RefObjectFunction<T> {\n const mergedCallback: RefObjectFunction<T> = React.useCallback(\n (value: T) => {\n // Update the \"current\" prop hanging on the function.\n (mergedCallback as unknown as React.MutableRefObject<T>).current = value;\n\n for (const ref of refs) {\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref) {\n // work around the immutability of the React.Ref type\n (ref as unknown as React.MutableRefObject<T>).current = value;\n }\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps -- already exhaustive\n [...refs],\n ) as unknown as RefObjectFunction<T>;\n\n return mergedCallback;\n}\n"],"names":["React","useMergedRefs","refs","mergedCallback","useCallback","value","current","ref"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAQ/B;;;;;CAKC,GACD,OAAO,SAASC,cAAiB,GAAGC,IAAkC;IACpE,MAAMC,iBAAuCH,MAAMI,WAAW,CAC5D,CAACC;QACC,qDAAqD;QACpDF,eAAwDG,OAAO,GAAGD;QAEnE,KAAK,MAAME,OAAOL,KAAM;YACtB,IAAI,OAAOK,QAAQ,YAAY;gBAC7BA,IAAIF;YACN,OAAO,IAAIE,KAAK;gBACd,qDAAqD;gBACpDA,IAA6CD,OAAO,GAAGD;YAC1D;QACF;IACF,GACA,6EAA6E;IAC7E;WAAIH;KAAK;IAGX,OAAOC;AACT"}
|
1
|
+
{"version":3,"sources":["useMergedRefs.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * A Ref function which can be treated like a ref object in that it has an attached\n * current property, which will be updated as the ref is evaluated.\n */\nexport type RefObjectFunction<T> = React.RefObject<T> & ((value: T) => void);\n\n/**\n * React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that\n * updates all provided refs\n * @param refs - Refs to collectively update with one ref value.\n * @returns A function with an attached \"current\" prop, so that it can be treated like a RefObject.\n */\nexport function useMergedRefs<T>(...refs: (React.Ref<T> | undefined)[]): RefObjectFunction<T> {\n 'use no memo';\n\n const mergedCallback: RefObjectFunction<T> = React.useCallback(\n (value: T) => {\n // Update the \"current\" prop hanging on the function.\n (mergedCallback as unknown as React.MutableRefObject<T>).current = value;\n\n for (const ref of refs) {\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref) {\n // work around the immutability of the React.Ref type\n (ref as unknown as React.MutableRefObject<T>).current = value;\n }\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps -- already exhaustive\n [...refs],\n ) as unknown as RefObjectFunction<T>;\n\n return mergedCallback;\n}\n"],"names":["React","useMergedRefs","refs","mergedCallback","useCallback","value","current","ref"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAQ/B;;;;;CAKC,GACD,OAAO,SAASC,cAAiB,GAAGC,IAAkC;IACpE;IAEA,MAAMC,iBAAuCH,MAAMI,WAAW,CAC5D,CAACC;QACC,qDAAqD;QACpDF,eAAwDG,OAAO,GAAGD;QAEnE,KAAK,MAAME,OAAOL,KAAM;YACtB,IAAI,OAAOK,QAAQ,YAAY;gBAC7BA,IAAIF;YACN,OAAO,IAAIE,KAAK;gBACd,qDAAqD;gBACpDA,IAA6CD,OAAO,GAAGD;YAC1D;QACF;IACF,GACA,6EAA6E;IAC7E;WAAIH;KAAK;IAGX,OAAOC;AACT"}
|
package/lib/hooks/useTimeout.js
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
import { useBrowserTimer } from './useBrowserTimer';
|
2
|
+
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
|
3
|
+
const setTimeoutNoop = (_callback)=>-1;
|
4
|
+
const clearTimeoutNoop = (_handle)=>undefined;
|
2
5
|
/**
|
3
6
|
* @internal
|
4
7
|
* Helper to manage a browser timeout.
|
@@ -7,6 +10,9 @@ import { useBrowserTimer } from './useBrowserTimer';
|
|
7
10
|
*
|
8
11
|
* @returns A pair of [setTimeout, clearTimeout] that are stable between renders.
|
9
12
|
*/ export function useTimeout() {
|
10
|
-
|
11
|
-
|
13
|
+
const { targetDocument } = useFluent();
|
14
|
+
const win = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView;
|
15
|
+
const setTimerFn = win ? win.setTimeout : setTimeoutNoop;
|
16
|
+
const clearTimerFn = win ? win.clearTimeout : clearTimeoutNoop;
|
17
|
+
return useBrowserTimer(setTimerFn, clearTimerFn);
|
12
18
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useTimeout.ts"],"sourcesContent":["import { useBrowserTimer } from './useBrowserTimer';\n\n/**\n * @internal\n * Helper to manage a browser timeout.\n * Ensures that the timeout isn't set multiple times at once and is cleaned up\n * when the component is unloaded.\n *\n * @returns A pair of [setTimeout, clearTimeout] that are stable between renders.\n */\nexport function useTimeout() {\n
|
1
|
+
{"version":3,"sources":["useTimeout.ts"],"sourcesContent":["import { useBrowserTimer } from './useBrowserTimer';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nconst setTimeoutNoop = (_callback: Function) => -1;\nconst clearTimeoutNoop = (_handle: number) => undefined;\n\n/**\n * @internal\n * Helper to manage a browser timeout.\n * Ensures that the timeout isn't set multiple times at once and is cleaned up\n * when the component is unloaded.\n *\n * @returns A pair of [setTimeout, clearTimeout] that are stable between renders.\n */\nexport function useTimeout() {\n const { targetDocument } = useFluent();\n const win = targetDocument?.defaultView;\n\n const setTimerFn = win ? win.setTimeout : setTimeoutNoop;\n const clearTimerFn = win ? win.clearTimeout : clearTimeoutNoop;\n\n return useBrowserTimer(setTimerFn, clearTimerFn);\n}\n"],"names":["useBrowserTimer","useFluent_unstable","useFluent","setTimeoutNoop","_callback","clearTimeoutNoop","_handle","undefined","useTimeout","targetDocument","win","defaultView","setTimerFn","setTimeout","clearTimerFn","clearTimeout"],"mappings":"AAAA,SAASA,eAAe,QAAQ,oBAAoB;AACpD,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAElF,MAAMC,iBAAiB,CAACC,YAAwB,CAAC;AACjD,MAAMC,mBAAmB,CAACC,UAAoBC;AAE9C;;;;;;;CAOC,GACD,OAAO,SAASC;IACd,MAAM,EAAEC,cAAc,EAAE,GAAGP;IAC3B,MAAMQ,MAAMD,2BAAAA,qCAAAA,eAAgBE,WAAW;IAEvC,MAAMC,aAAaF,MAAMA,IAAIG,UAAU,GAAGV;IAC1C,MAAMW,eAAeJ,MAAMA,IAAIK,YAAY,GAAGV;IAE9C,OAAOL,gBAAgBY,YAAYE;AACrC"}
|
@@ -92,6 +92,7 @@ function useMultipleSelection(params) {
|
|
92
92
|
];
|
93
93
|
}
|
94
94
|
export function useSelection(params) {
|
95
|
+
'use no memo';
|
95
96
|
if (params.selectionMode === 'multiselect') {
|
96
97
|
// selectionMode is a static value, so we can safely ignore rules-of-hooks
|
97
98
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
@@ -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"],"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,MAAMU,OAAO,CAClB,IAAMN,OAAOS,aAAa,IAAIX,sBAAsBE,OAAOS,aAAa,GACxE;YAACT,OAAOS,aAAa;SAAC;IAE1B;IACA,MAAMC,kBAAkB,CAACC,OAA6BC;YACpDZ;SAAAA,4BAAAA,OAAOa,iBAAiB,cAAxBb,gDAAAA,+BAAAA,QAA2BW,OAAO;YAAEF,eAAeG;QAAkB;QACrEV,YAAYU;IACd;IACA,OAAO;QAACX;QAAUS;KAAg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B;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"}
|
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 'use no memo';\n\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,MAAMU,OAAO,CAClB,IAAMN,OAAOS,aAAa,IAAIX,sBAAsBE,OAAOS,aAAa,GACxE;YAACT,OAAOS,aAAa;SAAC;IAE1B;IACA,MAAMC,kBAAkB,CAACC,OAA6BC;YACpDZ;SAAAA,4BAAAA,OAAOa,iBAAiB,cAAxBb,gDAAAA,+BAAAA,QAA2BW,OAAO;YAAEF,eAAeG;QAAkB;QACrEV,YAAYU;IACd;IACA,OAAO;QAACX;QAAUS;KAAgB;AACpC;AAEA,SAASI,mBAAmBd,MAAkD;IAC5E,MAAM,CAACC,UAAUS,gBAAgB,GAAGX,kBAAkBC;IACtD,MAAMe,UAA4B;QAChCC,cAAcL,CAAAA,QAASD,gBAAgBC,OAAO,IAAIP;QAClDa,YAAY,CAACN,OAAOO,SAAWR,gBAAgBC,OAAO,IAAIP,IAAI;gBAACc;aAAO;QACtEC,gBAAgB;YACd,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;gBACzC,MAAM,IAAIC,MAAM;YAClB;QACF;QACAC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BC,OAAOC;QACzB;IACF;IACA,OAAO;QAACX;QAAUc;KAAQ;AAC5B;AAEA,OAAO,SAASqB,aAAapC,MAA2B;IACtD;IAEA,IAAIA,OAAOqC,aAAa,KAAK,eAAe;QAC1C,0EAA0E;QAC1E,sDAAsD;QACtD,OAAOT,qBAAqB5B;IAC9B;IACA,0EAA0E;IAC1E,sDAAsD;IACtD,OAAOc,mBAAmBd;AAC5B"}
|
@@ -8,17 +8,17 @@ Object.defineProperty(exports, "useAnimationFrame", {
|
|
8
8
|
return useAnimationFrame;
|
9
9
|
}
|
10
10
|
});
|
11
|
-
const _canUseDOM = require("../ssr/canUseDOM");
|
12
11
|
const _useBrowserTimer = require("./useBrowserTimer");
|
12
|
+
const _reactsharedcontexts = require("@fluentui/react-shared-contexts");
|
13
13
|
const setAnimationFrameNoop = (callback)=>{
|
14
14
|
callback(0);
|
15
15
|
return 0;
|
16
16
|
};
|
17
17
|
const cancelAnimationFrameNoop = (handle)=>handle;
|
18
18
|
function useAnimationFrame() {
|
19
|
-
const
|
20
|
-
|
21
|
-
const setAnimationFrame =
|
22
|
-
const clearAnimationFrame =
|
19
|
+
const { targetDocument } = (0, _reactsharedcontexts.useFluent_unstable)();
|
20
|
+
const win = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView;
|
21
|
+
const setAnimationFrame = win ? win.requestAnimationFrame : setAnimationFrameNoop;
|
22
|
+
const clearAnimationFrame = win ? win.cancelAnimationFrame : cancelAnimationFrameNoop;
|
23
23
|
return (0, _useBrowserTimer.useBrowserTimer)(setAnimationFrame, clearAnimationFrame);
|
24
24
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useAnimationFrame.js"],"sourcesContent":["import {
|
1
|
+
{"version":3,"sources":["useAnimationFrame.js"],"sourcesContent":["import { useBrowserTimer } from './useBrowserTimer';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nconst setAnimationFrameNoop = (callback)=>{\n callback(0);\n return 0;\n};\nconst cancelAnimationFrameNoop = (handle)=>handle;\n/**\n * @internal\n * Helper to manage a browser requestAnimationFrame.\n * Ensures that the requestAnimationFrame isn't set multiple times at once and is cleaned up\n * when the component is unloaded.\n *\n * @returns A pair of [requestAnimationFrame, cancelAnimationFrame] that are stable between renders.\n */ export function useAnimationFrame() {\n const { targetDocument } = useFluent();\n const win = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView;\n const setAnimationFrame = win ? win.requestAnimationFrame : setAnimationFrameNoop;\n const clearAnimationFrame = win ? win.cancelAnimationFrame : cancelAnimationFrameNoop;\n return useBrowserTimer(setAnimationFrame, clearAnimationFrame);\n}\n"],"names":["useAnimationFrame","setAnimationFrameNoop","callback","cancelAnimationFrameNoop","handle","targetDocument","useFluent","win","defaultView","setAnimationFrame","requestAnimationFrame","clearAnimationFrame","cancelAnimationFrame","useBrowserTimer"],"mappings":";;;;+BAcoBA;;;eAAAA;;;iCAdY;qCACgB;AAChD,MAAMC,wBAAwB,CAACC;IAC3BA,SAAS;IACT,OAAO;AACX;AACA,MAAMC,2BAA2B,CAACC,SAASA;AAQhC,SAASJ;IAChB,MAAM,EAAEK,cAAc,EAAE,GAAGC,IAAAA,uCAAS;IACpC,MAAMC,MAAMF,mBAAmB,QAAQA,mBAAmB,KAAK,IAAI,KAAK,IAAIA,eAAeG,WAAW;IACtG,MAAMC,oBAAoBF,MAAMA,IAAIG,qBAAqB,GAAGT;IAC5D,MAAMU,sBAAsBJ,MAAMA,IAAIK,oBAAoB,GAAGT;IAC7D,OAAOU,IAAAA,gCAAe,EAACJ,mBAAmBE;AAC9C"}
|
@@ -14,6 +14,17 @@ function isFactoryDispatch(newState) {
|
|
14
14
|
return typeof newState === 'function';
|
15
15
|
}
|
16
16
|
const useControllableState = (options)=>{
|
17
|
+
'use no memo';
|
18
|
+
if (process.env.NODE_ENV !== 'production') {
|
19
|
+
if (options.state !== undefined && options.defaultState !== undefined) {
|
20
|
+
// eslint-disable-next-line no-console
|
21
|
+
console.error(`@fluentui/react-utilities [useControllableState]:
|
22
|
+
A component must be either controlled or uncontrolled (specify either the state or the defaultState, but not both).
|
23
|
+
Decide between using a controlled or uncontrolled component and remove one of this props.
|
24
|
+
More info: https://reactjs.org/link/controlled-components
|
25
|
+
${new Error().stack}`);
|
26
|
+
}
|
27
|
+
}
|
17
28
|
const [internalState, setInternalState] = _react.useState(()=>{
|
18
29
|
if (options.defaultState === undefined) {
|
19
30
|
return options.initialState;
|
@@ -49,6 +60,7 @@ function isInitializer(value) {
|
|
49
60
|
* Prints an error when isControlled value switches between subsequent renders
|
50
61
|
* @returns - whether the value is controlled
|
51
62
|
*/ const useIsControlled = (controlledValue)=>{
|
63
|
+
'use no memo';
|
52
64
|
const [isControlled] = _react.useState(()=>controlledValue !== undefined);
|
53
65
|
if (process.env.NODE_ENV !== 'production') {
|
54
66
|
// We don't want these warnings in production even though it is against native behaviour
|
@@ -59,7 +71,7 @@ function isInitializer(value) {
|
|
59
71
|
const controlWarning = isControlled ? 'a controlled value to be uncontrolled' : 'an uncontrolled value to be controlled';
|
60
72
|
const undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined';
|
61
73
|
// eslint-disable-next-line no-console
|
62
|
-
console.error(`@fluentui/react-utilities [
|
74
|
+
console.error(`@fluentui/react-utilities [useControllableState]:
|
63
75
|
A component is changing ${controlWarning}. This is likely caused by the value changing from ${undefinedWarning} value, which should not happen.
|
64
76
|
Decide between using a controlled or uncontrolled input element for the lifetime of the component.
|
65
77
|
More info: https://reactjs.org/link/controlled-components
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useControllableState.js"],"sourcesContent":["import * as React from 'react';\nfunction isFactoryDispatch(newState) {\n return typeof newState === 'function';\n}\n/**\n * @internal\n *\n * A [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate)-like hook\n * to manage a value that could be either `controlled` or `uncontrolled`,\n * such as a checked state or text input string.\n *\n * @see https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components for more details on `controlled`/`uncontrolled`\n *\n * @returns an array of the current value and an updater (dispatcher) function.\n * The updater function is referentially stable (won't change during the component's lifecycle).\n * It can take either a new value, or a function which is passed the previous value and returns the new value.\n *\n * ❗️❗️ Calls to the dispatcher will only modify the state if the state is `uncontrolled`.\n * Meaning that if a state is `controlled`, calls to the dispatcher do not modify the state.\n *\n */ export const useControllableState = (options)=>{\n const [internalState, setInternalState] = React.useState(()=>{\n if (options.defaultState === undefined) {\n return options.initialState;\n }\n return isInitializer(options.defaultState) ? options.defaultState() : options.defaultState;\n });\n // Heads up!\n // This part is specific for controlled mode and mocks behavior of React dispatcher function.\n const stateValueRef = React.useRef(options.state);\n React.useEffect(()=>{\n stateValueRef.current = options.state;\n }, [\n options.state\n ]);\n const setControlledState = React.useCallback((newState)=>{\n if (isFactoryDispatch(newState)) {\n newState(stateValueRef.current);\n }\n }, []);\n return useIsControlled(options.state) ? [\n options.state,\n setControlledState\n ] : [\n internalState,\n setInternalState\n ];\n};\nfunction isInitializer(value) {\n return typeof value === 'function';\n}\n/**\n * Helper hook to handle previous comparison of controlled/uncontrolled\n * Prints an error when isControlled value switches between subsequent renders\n * @returns - whether the value is controlled\n */ const useIsControlled = (controlledValue)=>{\n const [isControlled] = React.useState(()=>controlledValue !== undefined);\n if (process.env.NODE_ENV !== 'production') {\n // We don't want these warnings in production even though it is against native behaviour\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(()=>{\n if (isControlled !== (controlledValue !== undefined)) {\n const error = new Error();\n const controlWarning = isControlled ? 'a controlled value to be uncontrolled' : 'an uncontrolled value to be controlled';\n const undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined';\n // eslint-disable-next-line no-console\n console.error(`@fluentui/react-utilities [
|
1
|
+
{"version":3,"sources":["useControllableState.js"],"sourcesContent":["import * as React from 'react';\nfunction isFactoryDispatch(newState) {\n return typeof newState === 'function';\n}\n/**\n * @internal\n *\n * A [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate)-like hook\n * to manage a value that could be either `controlled` or `uncontrolled`,\n * such as a checked state or text input string.\n *\n * @see https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components for more details on `controlled`/`uncontrolled`\n *\n * @returns an array of the current value and an updater (dispatcher) function.\n * The updater function is referentially stable (won't change during the component's lifecycle).\n * It can take either a new value, or a function which is passed the previous value and returns the new value.\n *\n * ❗️❗️ Calls to the dispatcher will only modify the state if the state is `uncontrolled`.\n * Meaning that if a state is `controlled`, calls to the dispatcher do not modify the state.\n *\n */ export const useControllableState = (options)=>{\n 'use no memo';\n if (process.env.NODE_ENV !== 'production') {\n if (options.state !== undefined && options.defaultState !== undefined) {\n // eslint-disable-next-line no-console\n console.error(`@fluentui/react-utilities [useControllableState]:\nA component must be either controlled or uncontrolled (specify either the state or the defaultState, but not both).\nDecide between using a controlled or uncontrolled component and remove one of this props.\nMore info: https://reactjs.org/link/controlled-components\n${new Error().stack}`);\n }\n }\n const [internalState, setInternalState] = React.useState(()=>{\n if (options.defaultState === undefined) {\n return options.initialState;\n }\n return isInitializer(options.defaultState) ? options.defaultState() : options.defaultState;\n });\n // Heads up!\n // This part is specific for controlled mode and mocks behavior of React dispatcher function.\n const stateValueRef = React.useRef(options.state);\n React.useEffect(()=>{\n stateValueRef.current = options.state;\n }, [\n options.state\n ]);\n const setControlledState = React.useCallback((newState)=>{\n if (isFactoryDispatch(newState)) {\n newState(stateValueRef.current);\n }\n }, []);\n return useIsControlled(options.state) ? [\n options.state,\n setControlledState\n ] : [\n internalState,\n setInternalState\n ];\n};\nfunction isInitializer(value) {\n return typeof value === 'function';\n}\n/**\n * Helper hook to handle previous comparison of controlled/uncontrolled\n * Prints an error when isControlled value switches between subsequent renders\n * @returns - whether the value is controlled\n */ const useIsControlled = (controlledValue)=>{\n 'use no memo';\n const [isControlled] = React.useState(()=>controlledValue !== undefined);\n if (process.env.NODE_ENV !== 'production') {\n // We don't want these warnings in production even though it is against native behaviour\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(()=>{\n if (isControlled !== (controlledValue !== undefined)) {\n const error = new Error();\n const controlWarning = isControlled ? 'a controlled value to be uncontrolled' : 'an uncontrolled value to be controlled';\n const undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined';\n // eslint-disable-next-line no-console\n console.error(`@fluentui/react-utilities [useControllableState]:\nA component is changing ${controlWarning}. This is likely caused by the value changing from ${undefinedWarning} value, which should not happen.\nDecide between using a controlled or uncontrolled input element for the lifetime of the component.\nMore info: https://reactjs.org/link/controlled-components\n${error.stack}`);\n }\n }, [\n isControlled,\n controlledValue\n ]);\n }\n return isControlled;\n};\n"],"names":["useControllableState","isFactoryDispatch","newState","options","process","env","NODE_ENV","state","undefined","defaultState","console","error","Error","stack","internalState","setInternalState","React","useState","initialState","isInitializer","stateValueRef","useRef","useEffect","current","setControlledState","useCallback","useIsControlled","value","controlledValue","isControlled","controlWarning","undefinedWarning"],"mappings":";;;;+BAoBiBA;;;eAAAA;;;;iEApBM;AACvB,SAASC,kBAAkBC,QAAQ;IAC/B,OAAO,OAAOA,aAAa;AAC/B;AAiBW,MAAMF,uBAAuB,CAACG;IACrC;IACA,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACvC,IAAIH,QAAQI,KAAK,KAAKC,aAAaL,QAAQM,YAAY,KAAKD,WAAW;YACnE,sCAAsC;YACtCE,QAAQC,KAAK,CAAC,CAAC;;;;AAI3B,EAAE,IAAIC,QAAQC,KAAK,CAAC,CAAC;QACb;IACJ;IACA,MAAM,CAACC,eAAeC,iBAAiB,GAAGC,OAAMC,QAAQ,CAAC;QACrD,IAAId,QAAQM,YAAY,KAAKD,WAAW;YACpC,OAAOL,QAAQe,YAAY;QAC/B;QACA,OAAOC,cAAchB,QAAQM,YAAY,IAAIN,QAAQM,YAAY,KAAKN,QAAQM,YAAY;IAC9F;IACA,YAAY;IACZ,6FAA6F;IAC7F,MAAMW,gBAAgBJ,OAAMK,MAAM,CAAClB,QAAQI,KAAK;IAChDS,OAAMM,SAAS,CAAC;QACZF,cAAcG,OAAO,GAAGpB,QAAQI,KAAK;IACzC,GAAG;QACCJ,QAAQI,KAAK;KAChB;IACD,MAAMiB,qBAAqBR,OAAMS,WAAW,CAAC,CAACvB;QAC1C,IAAID,kBAAkBC,WAAW;YAC7BA,SAASkB,cAAcG,OAAO;QAClC;IACJ,GAAG,EAAE;IACL,OAAOG,gBAAgBvB,QAAQI,KAAK,IAAI;QACpCJ,QAAQI,KAAK;QACbiB;KACH,GAAG;QACAV;QACAC;KACH;AACL;AACA,SAASI,cAAcQ,KAAK;IACxB,OAAO,OAAOA,UAAU;AAC5B;AACA;;;;CAIC,GAAG,MAAMD,kBAAkB,CAACE;IACzB;IACA,MAAM,CAACC,aAAa,GAAGb,OAAMC,QAAQ,CAAC,IAAIW,oBAAoBpB;IAC9D,IAAIJ,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACvC,wFAAwF;QACxF,sDAAsD;QACtDU,OAAMM,SAAS,CAAC;YACZ,IAAIO,iBAAkBD,CAAAA,oBAAoBpB,SAAQ,GAAI;gBAClD,MAAMG,QAAQ,IAAIC;gBAClB,MAAMkB,iBAAiBD,eAAe,0CAA0C;gBAChF,MAAME,mBAAmBF,eAAe,4BAA4B;gBACpE,sCAAsC;gBACtCnB,QAAQC,KAAK,CAAC,CAAC;wBACP,EAAEmB,eAAe,mDAAmD,EAAEC,iBAAiB;;;AAG/G,EAAEpB,MAAME,KAAK,CAAC,CAAC;YACH;QACJ,GAAG;YACCgB;YACAD;SACH;IACL;IACA,OAAOC;AACX"}
|
@@ -31,6 +31,7 @@ function resetIdsForTests() {
|
|
31
31
|
_index.defaultSSRContextValue.current = 0;
|
32
32
|
}
|
33
33
|
function useId(prefix = 'fui-', providedId) {
|
34
|
+
'use no memo';
|
34
35
|
const contextValue = (0, _index.useSSRContext)();
|
35
36
|
const idPrefix = useIdPrefix();
|
36
37
|
// Checking if useId is available on React, if it is, we use it to generate the id. String concatenation is used to
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useId.js"],"sourcesContent":["import * as React from 'react';\nimport { defaultSSRContextValue, useSSRContext } from '../ssr/index';\nconst IdPrefixContext = React.createContext(undefined);\n/**\n * Allows to define a prefix that will be used for all IDs generated by useId() hook. It's useful to avoid collisions\n * between different bundles.\n */ export const IdPrefixProvider = IdPrefixContext.Provider;\nfunction useIdPrefix() {\n return React.useContext(IdPrefixContext) || '';\n}\n/**\n * Resets generated IDs, should be used only in tests.\n */ export function resetIdsForTests() {\n defaultSSRContextValue.current = 0;\n}\n/**\n * Hook to generate a unique ID.\n *\n * @param prefix - Optional prefix for the ID. Defaults to 'fui-'.\n * @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,\n * without conditioning the hook call\n * @returns The ID\n */ export function useId(prefix = 'fui-', providedId) {\n const contextValue = useSSRContext();\n const idPrefix = useIdPrefix();\n // Checking if useId is available on React, if it is, we use it to generate the id. String concatenation is used to\n // prevent bundlers from complaining with older versions of React.\n const _useId = React['use' + 'Id'];\n if (_useId) {\n const generatedId = _useId();\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const escapedId = React.useMemo(()=>generatedId.replace(/:/g, ''), [\n generatedId\n ]);\n return providedId || `${idPrefix}${prefix}${escapedId}`;\n }\n // Hooks appear to be running conditionally, but they will always run in the same order since it's based on\n // the version of React being used. This is safe to ignore.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return React.useMemo(()=>{\n if (providedId) {\n return providedId;\n }\n return `${idPrefix}${prefix}${++contextValue.current}`;\n }, [\n idPrefix,\n prefix,\n providedId,\n contextValue\n ]);\n}\n"],"names":["IdPrefixProvider","resetIdsForTests","useId","IdPrefixContext","React","createContext","undefined","Provider","useIdPrefix","useContext","defaultSSRContextValue","current","prefix","providedId","contextValue","useSSRContext","idPrefix","_useId","generatedId","escapedId","useMemo","replace"],"mappings":";;;;;;;;;;;IAMiBA,gBAAgB;eAAhBA;;IAMGC,gBAAgB;eAAhBA;;IAUAC,KAAK;eAALA;;;;iEAtBG;uBAC+B;AACtD,MAAMC,gCAAkBC,OAAMC,aAAa,CAACC;AAIjC,MAAMN,mBAAmBG,gBAAgBI,QAAQ;AAC5D,SAASC;IACL,OAAOJ,OAAMK,UAAU,CAACN,oBAAoB;AAChD;AAGW,SAASF;IAChBS,6BAAsB,CAACC,OAAO,GAAG;AACrC;AAQW,SAAST,MAAMU,SAAS,MAAM,EAAEC,UAAU;IACjD,MAAMC,eAAeC,IAAAA,oBAAa;IAClC,MAAMC,WAAWR;IACjB,mHAAmH;IACnH,kEAAkE;IAClE,MAAMS,SAASb,MAAK,CAAC,QAAQ,KAAK;IAClC,IAAIa,QAAQ;QACR,MAAMC,cAAcD;QACpB,sDAAsD;QACtD,MAAME,YAAYf,OAAMgB,OAAO,CAAC,IAAIF,YAAYG,OAAO,CAAC,MAAM,KAAK;YAC/DH;SACH;QACD,OAAOL,cAAc,CAAC,EAAEG,SAAS,EAAEJ,OAAO,EAAEO,UAAU,CAAC;IAC3D;IACA,2GAA2G;IAC3G,2DAA2D;IAC3D,sDAAsD;IACtD,OAAOf,OAAMgB,OAAO,CAAC;QACjB,IAAIP,YAAY;YACZ,OAAOA;QACX;QACA,OAAO,CAAC,EAAEG,SAAS,EAAEJ,OAAO,EAAE,EAAEE,aAAaH,OAAO,CAAC,CAAC;IAC1D,GAAG;QACCK;QACAJ;QACAC;QACAC;KACH;AACL"}
|
1
|
+
{"version":3,"sources":["useId.js"],"sourcesContent":["import * as React from 'react';\nimport { defaultSSRContextValue, useSSRContext } from '../ssr/index';\nconst IdPrefixContext = React.createContext(undefined);\n/**\n * Allows to define a prefix that will be used for all IDs generated by useId() hook. It's useful to avoid collisions\n * between different bundles.\n */ export const IdPrefixProvider = IdPrefixContext.Provider;\nfunction useIdPrefix() {\n return React.useContext(IdPrefixContext) || '';\n}\n/**\n * Resets generated IDs, should be used only in tests.\n */ export function resetIdsForTests() {\n defaultSSRContextValue.current = 0;\n}\n/**\n * Hook to generate a unique ID.\n *\n * @param prefix - Optional prefix for the ID. Defaults to 'fui-'.\n * @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,\n * without conditioning the hook call\n * @returns The ID\n */ export function useId(prefix = 'fui-', providedId) {\n 'use no memo';\n const contextValue = useSSRContext();\n const idPrefix = useIdPrefix();\n // Checking if useId is available on React, if it is, we use it to generate the id. String concatenation is used to\n // prevent bundlers from complaining with older versions of React.\n const _useId = React['use' + 'Id'];\n if (_useId) {\n const generatedId = _useId();\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const escapedId = React.useMemo(()=>generatedId.replace(/:/g, ''), [\n generatedId\n ]);\n return providedId || `${idPrefix}${prefix}${escapedId}`;\n }\n // Hooks appear to be running conditionally, but they will always run in the same order since it's based on\n // the version of React being used. This is safe to ignore.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return React.useMemo(()=>{\n if (providedId) {\n return providedId;\n }\n return `${idPrefix}${prefix}${++contextValue.current}`;\n }, [\n idPrefix,\n prefix,\n providedId,\n contextValue\n ]);\n}\n"],"names":["IdPrefixProvider","resetIdsForTests","useId","IdPrefixContext","React","createContext","undefined","Provider","useIdPrefix","useContext","defaultSSRContextValue","current","prefix","providedId","contextValue","useSSRContext","idPrefix","_useId","generatedId","escapedId","useMemo","replace"],"mappings":";;;;;;;;;;;IAMiBA,gBAAgB;eAAhBA;;IAMGC,gBAAgB;eAAhBA;;IAUAC,KAAK;eAALA;;;;iEAtBG;uBAC+B;AACtD,MAAMC,gCAAkBC,OAAMC,aAAa,CAACC;AAIjC,MAAMN,mBAAmBG,gBAAgBI,QAAQ;AAC5D,SAASC;IACL,OAAOJ,OAAMK,UAAU,CAACN,oBAAoB;AAChD;AAGW,SAASF;IAChBS,6BAAsB,CAACC,OAAO,GAAG;AACrC;AAQW,SAAST,MAAMU,SAAS,MAAM,EAAEC,UAAU;IACjD;IACA,MAAMC,eAAeC,IAAAA,oBAAa;IAClC,MAAMC,WAAWR;IACjB,mHAAmH;IACnH,kEAAkE;IAClE,MAAMS,SAASb,MAAK,CAAC,QAAQ,KAAK;IAClC,IAAIa,QAAQ;QACR,MAAMC,cAAcD;QACpB,sDAAsD;QACtD,MAAME,YAAYf,OAAMgB,OAAO,CAAC,IAAIF,YAAYG,OAAO,CAAC,MAAM,KAAK;YAC/DH;SACH;QACD,OAAOL,cAAc,CAAC,EAAEG,SAAS,EAAEJ,OAAO,EAAEO,UAAU,CAAC;IAC3D;IACA,2GAA2G;IAC3G,2DAA2D;IAC3D,sDAAsD;IACtD,OAAOf,OAAMgB,OAAO,CAAC;QACjB,IAAIP,YAAY;YACZ,OAAOA;QACX;QACA,OAAO,CAAC,EAAEG,SAAS,EAAEJ,OAAO,EAAE,EAAEE,aAAaH,OAAO,CAAC,CAAC;IAC1D,GAAG;QACCK;QACAJ;QACAC;QACAC;KACH;AACL"}
|
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "useMergedRefs", {
|
|
11
11
|
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
12
12
|
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
13
13
|
function useMergedRefs(...refs) {
|
14
|
+
'use no memo';
|
14
15
|
const mergedCallback = _react.useCallback((value)=>{
|
15
16
|
// Update the "current" prop hanging on the function.
|
16
17
|
mergedCallback.current = value;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useMergedRefs.js"],"sourcesContent":["import * as React from 'react';\n/**\n * React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that\n * updates all provided refs\n * @param refs - Refs to collectively update with one ref value.\n * @returns A function with an attached \"current\" prop, so that it can be treated like a RefObject.\n */ export function useMergedRefs(...refs) {\n const mergedCallback = React.useCallback((value)=>{\n // Update the \"current\" prop hanging on the function.\n mergedCallback.current = value;\n for (const ref of refs){\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref) {\n // work around the immutability of the React.Ref type\n ref.current = value;\n }\n }\n }, // eslint-disable-next-line react-hooks/exhaustive-deps -- already exhaustive\n [\n ...refs\n ]);\n return mergedCallback;\n}\n"],"names":["useMergedRefs","refs","mergedCallback","React","useCallback","value","current","ref"],"mappings":";;;;+BAMoBA;;;eAAAA;;;;iEANG;AAMZ,SAASA,cAAc,GAAGC,IAAI;IACrC,MAAMC,iBAAiBC,OAAMC,WAAW,CAAC,CAACC;QACtC,qDAAqD;QACrDH,eAAeI,OAAO,GAAGD;QACzB,KAAK,MAAME,OAAON,KAAK;YACnB,IAAI,OAAOM,QAAQ,YAAY;gBAC3BA,IAAIF;YACR,OAAO,IAAIE,KAAK;gBACZ,qDAAqD;gBACrDA,IAAID,OAAO,GAAGD;YAClB;QACJ;IACJ,GACA;WACOJ;KACN;IACD,OAAOC;AACX"}
|
1
|
+
{"version":3,"sources":["useMergedRefs.js"],"sourcesContent":["import * as React from 'react';\n/**\n * React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that\n * updates all provided refs\n * @param refs - Refs to collectively update with one ref value.\n * @returns A function with an attached \"current\" prop, so that it can be treated like a RefObject.\n */ export function useMergedRefs(...refs) {\n 'use no memo';\n const mergedCallback = React.useCallback((value)=>{\n // Update the \"current\" prop hanging on the function.\n mergedCallback.current = value;\n for (const ref of refs){\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref) {\n // work around the immutability of the React.Ref type\n ref.current = value;\n }\n }\n }, // eslint-disable-next-line react-hooks/exhaustive-deps -- already exhaustive\n [\n ...refs\n ]);\n return mergedCallback;\n}\n"],"names":["useMergedRefs","refs","mergedCallback","React","useCallback","value","current","ref"],"mappings":";;;;+BAMoBA;;;eAAAA;;;;iEANG;AAMZ,SAASA,cAAc,GAAGC,IAAI;IACrC;IACA,MAAMC,iBAAiBC,OAAMC,WAAW,CAAC,CAACC;QACtC,qDAAqD;QACrDH,eAAeI,OAAO,GAAGD;QACzB,KAAK,MAAME,OAAON,KAAK;YACnB,IAAI,OAAOM,QAAQ,YAAY;gBAC3BA,IAAIF;YACR,OAAO,IAAIE,KAAK;gBACZ,qDAAqD;gBACrDA,IAAID,OAAO,GAAGD;YAClB;QACJ;IACJ,GACA;WACOJ;KACN;IACD,OAAOC;AACX"}
|
@@ -9,7 +9,13 @@ Object.defineProperty(exports, "useTimeout", {
|
|
9
9
|
}
|
10
10
|
});
|
11
11
|
const _useBrowserTimer = require("./useBrowserTimer");
|
12
|
+
const _reactsharedcontexts = require("@fluentui/react-shared-contexts");
|
13
|
+
const setTimeoutNoop = (_callback)=>-1;
|
14
|
+
const clearTimeoutNoop = (_handle)=>undefined;
|
12
15
|
function useTimeout() {
|
13
|
-
|
14
|
-
|
16
|
+
const { targetDocument } = (0, _reactsharedcontexts.useFluent_unstable)();
|
17
|
+
const win = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView;
|
18
|
+
const setTimerFn = win ? win.setTimeout : setTimeoutNoop;
|
19
|
+
const clearTimerFn = win ? win.clearTimeout : clearTimeoutNoop;
|
20
|
+
return (0, _useBrowserTimer.useBrowserTimer)(setTimerFn, clearTimerFn);
|
15
21
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useTimeout.js"],"sourcesContent":["import { useBrowserTimer } from './useBrowserTimer';\n/**\n * @internal\n * Helper to manage a browser timeout.\n * Ensures that the timeout isn't set multiple times at once and is cleaned up\n * when the component is unloaded.\n *\n * @returns A pair of [setTimeout, clearTimeout] that are stable between renders.\n */ export function useTimeout() {\n
|
1
|
+
{"version":3,"sources":["useTimeout.js"],"sourcesContent":["import { useBrowserTimer } from './useBrowserTimer';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nconst setTimeoutNoop = (_callback)=>-1;\nconst clearTimeoutNoop = (_handle)=>undefined;\n/**\n * @internal\n * Helper to manage a browser timeout.\n * Ensures that the timeout isn't set multiple times at once and is cleaned up\n * when the component is unloaded.\n *\n * @returns A pair of [setTimeout, clearTimeout] that are stable between renders.\n */ export function useTimeout() {\n const { targetDocument } = useFluent();\n const win = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView;\n const setTimerFn = win ? win.setTimeout : setTimeoutNoop;\n const clearTimerFn = win ? win.clearTimeout : clearTimeoutNoop;\n return useBrowserTimer(setTimerFn, clearTimerFn);\n}\n"],"names":["useTimeout","setTimeoutNoop","_callback","clearTimeoutNoop","_handle","undefined","targetDocument","useFluent","win","defaultView","setTimerFn","setTimeout","clearTimerFn","clearTimeout","useBrowserTimer"],"mappings":";;;;+BAWoBA;;;eAAAA;;;iCAXY;qCACgB;AAChD,MAAMC,iBAAiB,CAACC,YAAY,CAAC;AACrC,MAAMC,mBAAmB,CAACC,UAAUC;AAQzB,SAASL;IAChB,MAAM,EAAEM,cAAc,EAAE,GAAGC,IAAAA,uCAAS;IACpC,MAAMC,MAAMF,mBAAmB,QAAQA,mBAAmB,KAAK,IAAI,KAAK,IAAIA,eAAeG,WAAW;IACtG,MAAMC,aAAaF,MAAMA,IAAIG,UAAU,GAAGV;IAC1C,MAAMW,eAAeJ,MAAMA,IAAIK,YAAY,GAAGV;IAC9C,OAAOW,IAAAA,gCAAe,EAACJ,YAAYE;AACvC"}
|
@@ -103,6 +103,7 @@ function useMultipleSelection(params) {
|
|
103
103
|
];
|
104
104
|
}
|
105
105
|
function useSelection(params) {
|
106
|
+
'use no memo';
|
106
107
|
if (params.selectionMode === 'multiselect') {
|
107
108
|
// selectionMode is a static value, so we can safely ignore rules-of-hooks
|
108
109
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useSelection.js"],"sourcesContent":["import * as React from 'react';\nimport { useControllableState } from '../hooks/useControllableState';\nimport { createSetFromIterable } from '../utils/createSetFromIterable';\nfunction useSelectionState(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 setSelected(nextSelectedItems);\n };\n return [\n selected,\n changeSelection\n ];\n}\nfunction useSingleSelection(params) {\n const [selected, changeSelection] = useSelectionState(params);\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)=>{\n var _selected_has;\n return (_selected_has = selected.has(itemId)) !== null && _selected_has !== void 0 ? _selected_has : false;\n }\n };\n return [\n selected,\n methods\n ];\n}\nfunction useMultipleSelection(params) {\n const [selected, changeSelection] = useSelectionState(params);\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","useSelectionState","params","selected","setSelected","useControllableState","initialState","Set","defaultState","React","useMemo","defaultSelectedItems","createSetFromIterable","state","selectedItems","changeSelection","event","nextSelectedItems","_params_onSelectionChange","onSelectionChange","call","useSingleSelection","methods","deselectItem","selectItem","itemId","toggleAllItems","process","env","NODE_ENV","Error","toggleItem","clearItems","isSelected","_selected_has","has","useMultipleSelection","delete","add","itemIds","allItemsSelected","every","clear","forEach","selectionMode"],"mappings":";;;;+BA6FgBA;;;eAAAA;;;;iEA7FO;sCACc;uCACC;AACtC,SAASC,kBAAkBC,MAAM;IAC7B,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;QAC5B,IAAIC;QACHA,CAAAA,4BAA4BhB,OAAOiB,iBAAiB,AAAD,MAAO,QAAQD,8BAA8B,KAAK,IAAI,KAAK,IAAIA,0BAA0BE,IAAI,CAAClB,QAAQc,OAAO;YAC7JF,eAAeG;QACnB;QACAb,YAAYa;IACh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B;QACAe,YAAY,CAAChB;YACTD,gBAAgBC,OAAO,IAAIT;QAC/B;QACA0B,YAAY,CAACR,SAAStB,SAASgC,GAAG,CAACV;QACnCC,gBAAgB,CAACV,OAAOuB;YACpB,MAAMC,mBAAmBD,QAAQE,KAAK,CAAC,CAAChB,SAAStB,SAASgC,GAAG,CAACV;YAC9D,MAAMR,oBAAoB,IAAIV,IAAIJ;YAClC,IAAIqC,kBAAkB;gBAClBvB,kBAAkByB,KAAK;YAC3B,OAAO;gBACHH,QAAQI,OAAO,CAAC,CAAClB,SAASR,kBAAkBqB,GAAG,CAACb;YACpD;YACAV,gBAAgBC,OAAOC;QAC3B;IACJ;IACA,OAAO;QACHd;QACAmB;KACH;AACL;AACO,SAAStB,aAAaE,MAAM;IAC/B,IAAIA,OAAO0C,aAAa,KAAK,eAAe;QACxC,0EAA0E;QAC1E,sDAAsD;QACtD,OAAOR,qBAAqBlC;IAChC;IACA,0EAA0E;IAC1E,sDAAsD;IACtD,OAAOmB,mBAAmBnB;AAC9B"}
|
1
|
+
{"version":3,"sources":["useSelection.js"],"sourcesContent":["import * as React from 'react';\nimport { useControllableState } from '../hooks/useControllableState';\nimport { createSetFromIterable } from '../utils/createSetFromIterable';\nfunction useSelectionState(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 setSelected(nextSelectedItems);\n };\n return [\n selected,\n changeSelection\n ];\n}\nfunction useSingleSelection(params) {\n const [selected, changeSelection] = useSelectionState(params);\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)=>{\n var _selected_has;\n return (_selected_has = selected.has(itemId)) !== null && _selected_has !== void 0 ? _selected_has : false;\n }\n };\n return [\n selected,\n methods\n ];\n}\nfunction useMultipleSelection(params) {\n const [selected, changeSelection] = useSelectionState(params);\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 'use no memo';\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","useSelectionState","params","selected","setSelected","useControllableState","initialState","Set","defaultState","React","useMemo","defaultSelectedItems","createSetFromIterable","state","selectedItems","changeSelection","event","nextSelectedItems","_params_onSelectionChange","onSelectionChange","call","useSingleSelection","methods","deselectItem","selectItem","itemId","toggleAllItems","process","env","NODE_ENV","Error","toggleItem","clearItems","isSelected","_selected_has","has","useMultipleSelection","delete","add","itemIds","allItemsSelected","every","clear","forEach","selectionMode"],"mappings":";;;;+BA6FgBA;;;eAAAA;;;;iEA7FO;sCACc;uCACC;AACtC,SAASC,kBAAkBC,MAAM;IAC7B,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;QAC5B,IAAIC;QACHA,CAAAA,4BAA4BhB,OAAOiB,iBAAiB,AAAD,MAAO,QAAQD,8BAA8B,KAAK,IAAI,KAAK,IAAIA,0BAA0BE,IAAI,CAAClB,QAAQc,OAAO;YAC7JF,eAAeG;QACnB;QACAb,YAAYa;IAChB;IACA,OAAO;QACHd;QACAY;KACH;AACL;AACA,SAASM,mBAAmBnB,MAAM;IAC9B,MAAM,CAACC,UAAUY,gBAAgB,GAAGd,kBAAkBC;IACtD,MAAMoB,UAAU;QACZC,cAAc,CAACP,QAAQD,gBAAgBC,OAAO,IAAIT;QAClDiB,YAAY,CAACR,OAAOS,SAASV,gBAAgBC,OAAO,IAAIT,IAAI;gBACpDkB;aACH;QACLC,gBAAgB;YACZ,IAAIC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ByB,KAAK;YAC3B,OAAO;gBACHH,QAAQI,OAAO,CAAC,CAAClB,SAASR,kBAAkBqB,GAAG,CAACb;YACpD;YACAV,gBAAgBC,OAAOC;QAC3B;IACJ;IACA,OAAO;QACHd;QACAmB;KACH;AACL;AACO,SAAStB,aAAaE,MAAM;IAC/B;IACA,IAAIA,OAAO0C,aAAa,KAAK,eAAe;QACxC,0EAA0E;QAC1E,sDAAsD;QACtD,OAAOR,qBAAqBlC;IAChC;IACA,0EAA0E;IAC1E,sDAAsD;IACtD,OAAOmB,mBAAmBnB;AAC9B"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fluentui/react-utilities",
|
3
|
-
"version": "9.18.
|
3
|
+
"version": "9.18.11",
|
4
4
|
"description": "A set of general React-specific utilities.",
|
5
5
|
"main": "lib-commonjs/index.js",
|
6
6
|
"module": "lib/index.js",
|
@@ -19,7 +19,7 @@
|
|
19
19
|
"just": "just-scripts",
|
20
20
|
"lint": "just-scripts lint",
|
21
21
|
"test": "jest --passWithNoTests",
|
22
|
-
"type-check": "
|
22
|
+
"type-check": "just-scripts type-check",
|
23
23
|
"generate-api": "just-scripts generate-api",
|
24
24
|
"test-ssr": "test-ssr \"./stories/**/*.stories.tsx\"",
|
25
25
|
"e2e": "cypress run --component",
|