@fluentui/react-utilities 9.9.0 → 9.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.json CHANGED
@@ -2,7 +2,37 @@
2
2
  "name": "@fluentui/react-utilities",
3
3
  "entries": [
4
4
  {
5
- "date": "Thu, 18 May 2023 00:35:49 GMT",
5
+ "date": "Thu, 25 May 2023 09:57:45 GMT",
6
+ "tag": "@fluentui/react-utilities_v9.9.1",
7
+ "version": "9.9.1",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "olfedias@microsoft.com",
12
+ "package": "@fluentui/react-utilities",
13
+ "commit": "4e463381ae0a63a07c45a2618bdce46423c65505",
14
+ "comment": "fix(react-utilities): fix dispatcher behavior"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Wed, 24 May 2023 20:45:37 GMT",
21
+ "tag": "@fluentui/react-utilities_v9.9.0",
22
+ "version": "9.9.0",
23
+ "comments": {
24
+ "none": [
25
+ {
26
+ "author": "olfedias@microsoft.com",
27
+ "package": "@fluentui/react-utilities",
28
+ "commit": "69e0617a93cb44ef42f3bd19284b7dc5fe27fed3",
29
+ "comment": "chore: update test-ssr script"
30
+ }
31
+ ]
32
+ }
33
+ },
34
+ {
35
+ "date": "Thu, 18 May 2023 00:39:19 GMT",
6
36
  "tag": "@fluentui/react-utilities_v9.9.0",
7
37
  "version": "9.9.0",
8
38
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,21 @@
1
1
  # Change Log - @fluentui/react-utilities
2
2
 
3
- This log was last generated on Thu, 18 May 2023 00:35:49 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 25 May 2023 09:57:45 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.9.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.9.1)
8
+
9
+ Thu, 25 May 2023 09:57:45 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.9.0..@fluentui/react-utilities_v9.9.1)
11
+
12
+ ### Patches
13
+
14
+ - fix(react-utilities): fix dispatcher behavior ([PR #27978](https://github.com/microsoft/fluentui/pull/27978) by olfedias@microsoft.com)
15
+
7
16
  ## [9.9.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.9.0)
8
17
 
9
- Thu, 18 May 2023 00:35:49 GMT
18
+ Thu, 18 May 2023 00:39:19 GMT
10
19
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.8.1..@fluentui/react-utilities_v9.9.0)
11
20
 
12
21
  ### Minor changes
@@ -1,4 +1,7 @@
1
1
  import * as React from 'react';
2
+ function isFactoryDispatch(newState) {
3
+ return typeof newState === 'function';
4
+ }
2
5
  /**
3
6
  * @internal
4
7
  *
@@ -23,13 +26,22 @@ export const useControllableState = options => {
23
26
  }
24
27
  return isInitializer(options.defaultState) ? options.defaultState() : options.defaultState;
25
28
  });
26
- return useIsControlled(options.state) ? [options.state, noop] : [internalState, setInternalState];
29
+ // Heads up!
30
+ // This part is specific for controlled mode and mocks behavior of React dispatcher function.
31
+ const stateValueRef = React.useRef(options.state);
32
+ React.useEffect(() => {
33
+ stateValueRef.current = options.state;
34
+ }, [options.state]);
35
+ const setControlledState = React.useCallback(newState => {
36
+ if (isFactoryDispatch(newState)) {
37
+ newState(stateValueRef.current);
38
+ }
39
+ }, []);
40
+ return useIsControlled(options.state) ? [options.state, setControlledState] : [internalState, setInternalState];
27
41
  };
28
42
  function isInitializer(value) {
29
43
  return typeof value === 'function';
30
44
  }
31
- function noop() {
32
- /* noop */}
33
45
  /**
34
46
  * Helper hook to handle previous comparison of controlled/uncontrolled
35
47
  * Prints an error when isControlled value switches between subsequent renders
@@ -1 +1 @@
1
- {"version":3,"names":["React","useControllableState","options","internalState","setInternalState","useState","defaultState","undefined","initialState","isInitializer","useIsControlled","state","noop","value","controlledValue","isControlled","process","env","NODE_ENV","useEffect","error","Error","controlWarning","undefinedWarning","console","stack","join"],"sources":["../../src/hooks/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\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 return useIsControlled(options.state) ? [options.state, noop] : [internalState, setInternalState];\n};\n\nfunction isInitializer<State>(value: State | (() => State)): value is () => State {\n return typeof value === 'function';\n}\n\nfunction noop() {\n /* noop */\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(\n [\n // Default react error\n 'A component is changing ' + controlWarning + '. This is likely caused by the value',\n '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 ].join(' '),\n );\n }\n }, [isControlled, controlledValue]);\n }\n\n return isControlled;\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AAqBvB;;;;;;;;;;;;;;;;;AAiBA,OAAO,MAAMC,oBAAA,GACXC,OAAA,IACyD;EACzD,MAAM,CAACC,aAAA,EAAeC,gBAAA,CAAiB,GAAGJ,KAAA,CAAMK,QAAQ,CAAQ,MAAM;IACpE,IAAIH,OAAA,CAAQI,YAAY,KAAKC,SAAA,EAAW;MACtC,OAAOL,OAAA,CAAQM,YAAY;IAC7B;IACA,OAAOC,aAAA,CAAcP,OAAA,CAAQI,YAAY,IAAIJ,OAAA,CAAQI,YAAY,KAAKJ,OAAA,CAAQI,YAAY;EAC5F;EACA,OAAOI,eAAA,CAAgBR,OAAA,CAAQS,KAAK,IAAI,CAACT,OAAA,CAAQS,KAAK,EAAEC,IAAA,CAAK,GAAG,CAACT,aAAA,EAAeC,gBAAA,CAAiB;AACnG;AAEA,SAASK,cAAqBI,KAA4B,EAAwB;EAChF,OAAO,OAAOA,KAAA,KAAU;AAC1B;AAEA,SAASD,KAAA,EAAO;EACd;AAGF;;;;;AAKA,MAAMF,eAAA,GAAsBI,eAAA,IAAyD;EACnF,MAAM,CAACC,YAAA,CAAa,GAAGf,KAAA,CAAMK,QAAQ,CAAU,MAAMS,eAAA,KAAoBP,SAAA;EAEzE,IAAIS,OAAA,CAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;IACzC;IACA;IACAlB,KAAA,CAAMmB,SAAS,CAAC,MAAM;MACpB,IAAIJ,YAAA,MAAkBD,eAAA,KAAoBP,SAAQ,GAAI;QACpD,MAAMa,KAAA,GAAQ,IAAIC,KAAA;QAElB,MAAMC,cAAA,GAAiBP,YAAA,GACnB,0CACA,wCAAwC;QAE5C,MAAMQ,gBAAA,GAAmBR,YAAA,GAAe,4BAA4B,wBAAwB;QAE5F;QACAS,OAAA,CAAQJ,KAAK,CACX;QACE;QACA,6BAA6BE,cAAA,GAAiB,wCAC9C,mBAAmBC,gBAAA,GAAmB,oCACtC,sGACA,6DACAH,KAAA,CAAMK,KAAK,CACZ,CAACC,IAAI,CAAC;MAEX;IACF,GAAG,CAACX,YAAA,EAAcD,eAAA,CAAgB;EACpC;EAEA,OAAOC,YAAA;AACT"}
1
+ {"version":3,"names":["React","isFactoryDispatch","newState","useControllableState","options","internalState","setInternalState","useState","defaultState","undefined","initialState","isInitializer","stateValueRef","useRef","state","useEffect","current","setControlledState","useCallback","useIsControlled","value","controlledValue","isControlled","process","env","NODE_ENV","error","Error","controlWarning","undefinedWarning","console","stack","join"],"sources":["../../src/hooks/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(\n [\n // Default react error\n 'A component is changing ' + controlWarning + '. This is likely caused by the value',\n '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 ].join(' '),\n );\n }\n }, [isControlled, controlledValue]);\n }\n\n return isControlled;\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AAqBvB,SAASC,kBAAyBC,QAAqC,EAA2C;EAChH,OAAO,OAAOA,QAAA,KAAa;AAC7B;AAEA;;;;;;;;;;;;;;;;;AAiBA,OAAO,MAAMC,oBAAA,GACXC,OAAA,IACyD;EACzD,MAAM,CAACC,aAAA,EAAeC,gBAAA,CAAiB,GAAGN,KAAA,CAAMO,QAAQ,CAAQ,MAAM;IACpE,IAAIH,OAAA,CAAQI,YAAY,KAAKC,SAAA,EAAW;MACtC,OAAOL,OAAA,CAAQM,YAAY;IAC7B;IACA,OAAOC,aAAA,CAAcP,OAAA,CAAQI,YAAY,IAAIJ,OAAA,CAAQI,YAAY,KAAKJ,OAAA,CAAQI,YAAY;EAC5F;EAEA;EACA;EAEA,MAAMI,aAAA,GAAgBZ,KAAA,CAAMa,MAAM,CAAoBT,OAAA,CAAQU,KAAK;EAEnEd,KAAA,CAAMe,SAAS,CAAC,MAAM;IACpBH,aAAA,CAAcI,OAAO,GAAGZ,OAAA,CAAQU,KAAK;EACvC,GAAG,CAACV,OAAA,CAAQU,KAAK,CAAC;EAElB,MAAMG,kBAAA,GAAqBjB,KAAA,CAAMkB,WAAW,CAAEhB,QAAA,IAA0C;IACtF,IAAID,iBAAA,CAAkBC,QAAA,GAAW;MAC/BA,QAAA,CAASU,aAAA,CAAcI,OAAO;IAChC;EACF,GAAG,EAAE;EAEL,OAAOG,eAAA,CAAgBf,OAAA,CAAQU,KAAK,IAAI,CAACV,OAAA,CAAQU,KAAK,EAAEG,kBAAA,CAAmB,GAAG,CAACZ,aAAA,EAAeC,gBAAA,CAAiB;AACjH;AAEA,SAASK,cAAqBS,KAA4B,EAAwB;EAChF,OAAO,OAAOA,KAAA,KAAU;AAC1B;AAEA;;;;;AAKA,MAAMD,eAAA,GAAsBE,eAAA,IAAyD;EACnF,MAAM,CAACC,YAAA,CAAa,GAAGtB,KAAA,CAAMO,QAAQ,CAAU,MAAMc,eAAA,KAAoBZ,SAAA;EAEzE,IAAIc,OAAA,CAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;IACzC;IACA;IACAzB,KAAA,CAAMe,SAAS,CAAC,MAAM;MACpB,IAAIO,YAAA,MAAkBD,eAAA,KAAoBZ,SAAQ,GAAI;QACpD,MAAMiB,KAAA,GAAQ,IAAIC,KAAA;QAElB,MAAMC,cAAA,GAAiBN,YAAA,GACnB,0CACA,wCAAwC;QAE5C,MAAMO,gBAAA,GAAmBP,YAAA,GAAe,4BAA4B,wBAAwB;QAE5F;QACAQ,OAAA,CAAQJ,KAAK,CACX;QACE;QACA,6BAA6BE,cAAA,GAAiB,wCAC9C,mBAAmBC,gBAAA,GAAmB,oCACtC,sGACA,6DACAH,KAAA,CAAMK,KAAK,CACZ,CAACC,IAAI,CAAC;MAEX;IACF,GAAG,CAACV,YAAA,EAAcD,eAAA,CAAgB;EACpC;EAEA,OAAOC,YAAA;AACT"}
@@ -8,6 +8,9 @@ Object.defineProperty(exports, "useControllableState", {
8
8
  });
9
9
  const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
10
10
  const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
11
+ function isFactoryDispatch(newState) {
12
+ return typeof newState === 'function';
13
+ }
11
14
  const useControllableState = (options)=>{
12
15
  const [internalState, setInternalState] = _react.useState(()=>{
13
16
  if (options.defaultState === undefined) {
@@ -15,9 +18,22 @@ const useControllableState = (options)=>{
15
18
  }
16
19
  return isInitializer(options.defaultState) ? options.defaultState() : options.defaultState;
17
20
  });
21
+ // Heads up!
22
+ // This part is specific for controlled mode and mocks behavior of React dispatcher function.
23
+ const stateValueRef = _react.useRef(options.state);
24
+ _react.useEffect(()=>{
25
+ stateValueRef.current = options.state;
26
+ }, [
27
+ options.state
28
+ ]);
29
+ const setControlledState = _react.useCallback((newState)=>{
30
+ if (isFactoryDispatch(newState)) {
31
+ newState(stateValueRef.current);
32
+ }
33
+ }, []);
18
34
  return useIsControlled(options.state) ? [
19
35
  options.state,
20
- noop
36
+ setControlledState
21
37
  ] : [
22
38
  internalState,
23
39
  setInternalState
@@ -26,8 +42,6 @@ const useControllableState = (options)=>{
26
42
  function isInitializer(value) {
27
43
  return typeof value === 'function';
28
44
  }
29
- function noop() {
30
- /* noop */ }
31
45
  /**
32
46
  * Helper hook to handle previous comparison of controlled/uncontrolled
33
47
  * Prints an error when isControlled value switches between subsequent renders
@@ -1 +1 @@
1
- {"version":3,"sources":["../../lib/hooks/useControllableState.js"],"sourcesContent":["import * as React from 'react';\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 = 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 return useIsControlled(options.state) ? [options.state, noop] : [internalState, setInternalState];\n};\nfunction isInitializer(value) {\n return typeof value === 'function';\n}\nfunction noop() {\n /* noop */}\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 = 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([\n // Default react error\n 'A component is changing ' + controlWarning + '. This is likely caused by the value', 'changing from ' + undefinedWarning + ' value, which should not happen.', 'Decide between using a controlled or uncontrolled input element for the lifetime of the component.', 'More info: https://reactjs.org/link/controlled-components', error.stack].join(' '));\n }\n }, [isControlled, controlledValue]);\n }\n return isControlled;\n};\n//# sourceMappingURL=useControllableState.js.map"],"names":["useControllableState","options","internalState","setInternalState","React","useState","defaultState","undefined","initialState","isInitializer","useIsControlled","state","noop","value","controlledValue","isControlled","process","env","NODE_ENV","useEffect","error","Error","controlWarning","undefinedWarning","console","stack","join"],"mappings":";;;;+BAkBaA;;aAAAA;;;6DAlBU;AAkBhB,MAAMA,uBAAuBC,CAAAA,UAAW;IAC7C,MAAM,CAACC,eAAeC,iBAAiB,GAAGC,OAAMC,QAAQ,CAAC,IAAM;QAC7D,IAAIJ,QAAQK,YAAY,KAAKC,WAAW;YACtC,OAAON,QAAQO,YAAY;QAC7B,CAAC;QACD,OAAOC,cAAcR,QAAQK,YAAY,IAAIL,QAAQK,YAAY,KAAKL,QAAQK,YAAY;IAC5F;IACA,OAAOI,gBAAgBT,QAAQU,KAAK,IAAI;QAACV,QAAQU,KAAK;QAAEC;KAAK,GAAG;QAACV;QAAeC;KAAiB;AACnG;AACA,SAASM,cAAcI,KAAK,EAAE;IAC5B,OAAO,OAAOA,UAAU;AAC1B;AACA,SAASD,OAAO;AACd,QAAQ,GAAE;AACZ;;;;CAIC,GACD,MAAMF,kBAAkBI,CAAAA,kBAAmB;IACzC,MAAM,CAACC,aAAa,GAAGX,OAAMC,QAAQ,CAAC,IAAMS,oBAAoBP;IAChE,IAAIS,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,wFAAwF;QACxF,sDAAsD;QACtDd,OAAMe,SAAS,CAAC,IAAM;YACpB,IAAIJ,iBAAkBD,CAAAA,oBAAoBP,SAAQ,GAAI;gBACpD,MAAMa,QAAQ,IAAIC;gBAClB,MAAMC,iBAAiBP,eAAe,0CAA0C,wCAAwC;gBACxH,MAAMQ,mBAAmBR,eAAe,4BAA4B,wBAAwB;gBAC5F,sCAAsC;gBACtCS,QAAQJ,KAAK,CAAC;oBACd,sBAAsB;oBACtB,6BAA6BE,iBAAiB;oBAAwC,mBAAmBC,mBAAmB;oBAAoC;oBAAsG;oBAA6DH,MAAMK,KAAK;iBAAC,CAACC,IAAI,CAAC;YACvV,CAAC;QACH,GAAG;YAACX;YAAcD;SAAgB;IACpC,CAAC;IACD,OAAOC;AACT,GACA,gDAAgD"}
1
+ {"version":3,"sources":["../../lib/hooks/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 */\nexport 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 }, [options.state]);\n const setControlledState = React.useCallback(newState => {\n if (isFactoryDispatch(newState)) {\n newState(stateValueRef.current);\n }\n }, []);\n return useIsControlled(options.state) ? [options.state, setControlledState] : [internalState, setInternalState];\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 */\nconst 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([\n // Default react error\n 'A component is changing ' + controlWarning + '. This is likely caused by the value', 'changing from ' + undefinedWarning + ' value, which should not happen.', 'Decide between using a controlled or uncontrolled input element for the lifetime of the component.', 'More info: https://reactjs.org/link/controlled-components', error.stack].join(' '));\n }\n }, [isControlled, controlledValue]);\n }\n return isControlled;\n};\n//# sourceMappingURL=useControllableState.js.map"],"names":["useControllableState","isFactoryDispatch","newState","options","internalState","setInternalState","React","useState","defaultState","undefined","initialState","isInitializer","stateValueRef","useRef","state","useEffect","current","setControlledState","useCallback","useIsControlled","value","controlledValue","isControlled","process","env","NODE_ENV","error","Error","controlWarning","undefinedWarning","console","stack","join"],"mappings":";;;;+BAqBaA;;aAAAA;;;6DArBU;AACvB,SAASC,kBAAkBC,QAAQ,EAAE;IACnC,OAAO,OAAOA,aAAa;AAC7B;AAkBO,MAAMF,uBAAuBG,CAAAA,UAAW;IAC7C,MAAM,CAACC,eAAeC,iBAAiB,GAAGC,OAAMC,QAAQ,CAAC,IAAM;QAC7D,IAAIJ,QAAQK,YAAY,KAAKC,WAAW;YACtC,OAAON,QAAQO,YAAY;QAC7B,CAAC;QACD,OAAOC,cAAcR,QAAQK,YAAY,IAAIL,QAAQK,YAAY,KAAKL,QAAQK,YAAY;IAC5F;IACA,YAAY;IACZ,6FAA6F;IAC7F,MAAMI,gBAAgBN,OAAMO,MAAM,CAACV,QAAQW,KAAK;IAChDR,OAAMS,SAAS,CAAC,IAAM;QACpBH,cAAcI,OAAO,GAAGb,QAAQW,KAAK;IACvC,GAAG;QAACX,QAAQW,KAAK;KAAC;IAClB,MAAMG,qBAAqBX,OAAMY,WAAW,CAAChB,CAAAA,WAAY;QACvD,IAAID,kBAAkBC,WAAW;YAC/BA,SAASU,cAAcI,OAAO;QAChC,CAAC;IACH,GAAG,EAAE;IACL,OAAOG,gBAAgBhB,QAAQW,KAAK,IAAI;QAACX,QAAQW,KAAK;QAAEG;KAAmB,GAAG;QAACb;QAAeC;KAAiB;AACjH;AACA,SAASM,cAAcS,KAAK,EAAE;IAC5B,OAAO,OAAOA,UAAU;AAC1B;AACA;;;;CAIC,GACD,MAAMD,kBAAkBE,CAAAA,kBAAmB;IACzC,MAAM,CAACC,aAAa,GAAGhB,OAAMC,QAAQ,CAAC,IAAMc,oBAAoBZ;IAChE,IAAIc,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,wFAAwF;QACxF,sDAAsD;QACtDnB,OAAMS,SAAS,CAAC,IAAM;YACpB,IAAIO,iBAAkBD,CAAAA,oBAAoBZ,SAAQ,GAAI;gBACpD,MAAMiB,QAAQ,IAAIC;gBAClB,MAAMC,iBAAiBN,eAAe,0CAA0C,wCAAwC;gBACxH,MAAMO,mBAAmBP,eAAe,4BAA4B,wBAAwB;gBAC5F,sCAAsC;gBACtCQ,QAAQJ,KAAK,CAAC;oBACd,sBAAsB;oBACtB,6BAA6BE,iBAAiB;oBAAwC,mBAAmBC,mBAAmB;oBAAoC;oBAAsG;oBAA6DH,MAAMK,KAAK;iBAAC,CAACC,IAAI,CAAC;YACvV,CAAC;QACH,GAAG;YAACV;YAAcD;SAAgB;IACpC,CAAC;IACD,OAAOC;AACT,GACA,gDAAgD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-utilities",
3
- "version": "9.9.0",
3
+ "version": "9.9.1",
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,7 @@
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
25
  },
26
26
  "devDependencies": {
27
27
  "@fluentui/eslint-plugin": "*",