@fluentui/react-context-selector 9.1.4 → 9.1.6

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,60 @@
2
2
  "name": "@fluentui/react-context-selector",
3
3
  "entries": [
4
4
  {
5
- "date": "Wed, 04 Jan 2023 01:36:22 GMT",
5
+ "date": "Thu, 26 Jan 2023 13:27:45 GMT",
6
+ "tag": "@fluentui/react-context-selector_v9.1.6",
7
+ "version": "9.1.6",
8
+ "comments": {
9
+ "none": [
10
+ {
11
+ "author": "miroslav.stastny@microsoft.com",
12
+ "package": "@fluentui/react-context-selector",
13
+ "commit": "6f29c8f65b2db6125efbd2a7ec2d7abdd0f44601",
14
+ "comment": "chore: fix a typo in jsdoc"
15
+ }
16
+ ],
17
+ "patch": [
18
+ {
19
+ "author": "beachball",
20
+ "package": "@fluentui/react-context-selector",
21
+ "comment": "Bump @fluentui/react-utilities to v9.5.0",
22
+ "commit": "403e1370f1effca7d3db131eda381abf31cf66b1"
23
+ }
24
+ ]
25
+ }
26
+ },
27
+ {
28
+ "date": "Mon, 16 Jan 2023 08:39:00 GMT",
29
+ "tag": "@fluentui/react-context-selector_v9.1.5",
30
+ "version": "9.1.5",
31
+ "comments": {
32
+ "none": [
33
+ {
34
+ "author": "martinhochel@microsoft.com",
35
+ "package": "@fluentui/react-context-selector",
36
+ "commit": "64bb45980d68de1219c6b36a7db5363f0a9cff9f",
37
+ "comment": "chore: migrate to packaged scripts"
38
+ }
39
+ ]
40
+ }
41
+ },
42
+ {
43
+ "date": "Mon, 09 Jan 2023 14:35:02 GMT",
44
+ "tag": "@fluentui/react-context-selector_v9.1.5",
45
+ "version": "9.1.5",
46
+ "comments": {
47
+ "patch": [
48
+ {
49
+ "author": "beachball",
50
+ "package": "@fluentui/react-context-selector",
51
+ "comment": "Bump @fluentui/react-utilities to v9.4.0",
52
+ "commit": "d246e70eba59a37ec311dbf933b0745d34cb700d"
53
+ }
54
+ ]
55
+ }
56
+ },
57
+ {
58
+ "date": "Wed, 04 Jan 2023 01:41:01 GMT",
6
59
  "tag": "@fluentui/react-context-selector_v9.1.4",
7
60
  "version": "9.1.4",
8
61
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,30 @@
1
1
  # Change Log - @fluentui/react-context-selector
2
2
 
3
- This log was last generated on Wed, 04 Jan 2023 01:36:22 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 26 Jan 2023 13:27:45 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.1.6](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.1.6)
8
+
9
+ Thu, 26 Jan 2023 13:27:45 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.5..@fluentui/react-context-selector_v9.1.6)
11
+
12
+ ### Patches
13
+
14
+ - Bump @fluentui/react-utilities to v9.5.0 ([PR #26496](https://github.com/microsoft/fluentui/pull/26496) by beachball)
15
+
16
+ ## [9.1.5](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.1.5)
17
+
18
+ Mon, 09 Jan 2023 14:35:02 GMT
19
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.4..@fluentui/react-context-selector_v9.1.5)
20
+
21
+ ### Patches
22
+
23
+ - Bump @fluentui/react-utilities to v9.4.0 ([PR #26255](https://github.com/microsoft/fluentui/pull/26255) by beachball)
24
+
7
25
  ## [9.1.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.1.4)
8
26
 
9
- Wed, 04 Jan 2023 01:36:22 GMT
27
+ Wed, 04 Jan 2023 01:41:01 GMT
10
28
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.3..@fluentui/react-context-selector_v9.1.4)
11
29
 
12
30
  ### Patches
package/dist/index.d.ts CHANGED
@@ -44,7 +44,7 @@ export declare const createContext: <Value>(defaultValue: Value) => Context<Valu
44
44
  * @internal
45
45
  * This hook returns context selected value by selector.
46
46
  * It will only accept context created by `createContext`.
47
- * It will trigger re-render if only the selected value is referencially changed.
47
+ * It will trigger re-render if only the selected value is referentially changed.
48
48
  */
49
49
  export declare const useContextSelector: <Value, SelectedValue>(context: Context<Value>, selector: ContextSelector<Value, SelectedValue>) => SelectedValue;
50
50
 
@@ -4,7 +4,7 @@ import * as React from 'react';
4
4
  * @internal
5
5
  * This hook returns context selected value by selector.
6
6
  * It will only accept context created by `createContext`.
7
- * It will trigger re-render if only the selected value is referencially changed.
7
+ * It will trigger re-render if only the selected value is referentially changed.
8
8
  */
9
9
  export const useContextSelector = (context, selector) => {
10
10
  const contextValue = React.useContext(context);
@@ -1 +1 @@
1
- {"version":3,"mappings":"AAAA,SAASA,yBAAyB,QAAQ,2BAA2B;AACrE,OAAO,KAAKC,KAAK,MAAM,OAAO;AAa9B;;;;;;AAMA,OAAO,MAAMC,kBAAkB,GAAG,CAChCC,OAAuB,EACvBC,QAA+C,KAC9B;EACjB,MAAMC,YAAY,GAAGJ,KAAK,CAACK,UAAU,CAAEH,OAAmD,CAAC;EAE3F,MAAM;IACJI,KAAK,EAAE;MAAEC,OAAO,EAAED;IAAK,CAAE;IACzBE,OAAO,EAAE;MAAED,OAAO,EAAEC;IAAO,CAAE;IAC7BC;EAAS,CACV,GAAGL,YAAY;EAChB,MAAMM,QAAQ,GAAGP,QAAQ,CAACG,KAAK,CAAC;EAEhC,MAAM,CAACK,KAAK,EAAEC,QAAQ,CAAC,GAAGZ,KAAK,CAACa,UAAU,CACxC,CACEC,SAAmF,EACnFC,OAEoC,KACD;IACnC,IAAI,CAACA,OAAO,EAAE;MACZ;MACA,OAAO,CAACT,KAAK,EAAEI,QAAQ,CAAU;;IAGnC,IAAIK,OAAO,CAAC,CAAC,CAAC,IAAIP,OAAO,EAAE;MACzB,IAAIQ,QAAQ,CAACF,SAAS,CAAC,CAAC,CAAC,EAAEJ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AAC,IAAI,CAAC,GAAGA,CAAC,KAAK,CAAC,GAAGC,CAAC,CAAC,IAAMD,CAAC,KAAKA,CAAC,IAAIC,CAAC,KAAKA,CAAE,CAAC;EAAA;AAEtE;AAEA;AACA,MAAMV,QAAQ;AACZ;AACA;AACA,OAAOW,MAAM,CAACH,EAAE,KAAK,UAAU,GAAGG,MAAM,CAACH,EAAE,GAAGA,EAAE","names":["useIsomorphicLayoutEffect","React","useContextSelector","context","selector","contextValue","useContext","value","current","version","listeners","selected","state","dispatch","useReducer","prevState","payload","objectIs","nextSelected","e","undefined","push","index","indexOf","splice","is","x","y","Object"],"sourceRoot":"../src/","sources":["packages/react-components/react-context-selector/src/useContextSelector.ts"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { Context, ContextSelector, ContextValue, ContextVersion } from './types';\n\n/**\n * Narrowing React.Reducer type to be more easily usable below.\n * No need to export this as it's for internal reducer usage.\n */\ntype ContextReducer<Value, SelectedValue> = React.Reducer<\n readonly [Value, SelectedValue],\n undefined | readonly [ContextVersion, Value]\n>;\n\n/**\n * @internal\n * This hook returns context selected value by selector.\n * It will only accept context created by `createContext`.\n * It will trigger re-render if only the selected value is referencially changed.\n */\nexport const useContextSelector = <Value, SelectedValue>(\n context: Context<Value>,\n selector: ContextSelector<Value, SelectedValue>,\n): SelectedValue => {\n const contextValue = React.useContext((context as unknown) as Context<ContextValue<Value>>);\n\n const {\n value: { current: value },\n version: { current: version },\n listeners,\n } = contextValue;\n const selected = selector(value);\n\n const [state, dispatch] = React.useReducer<ContextReducer<Value, SelectedValue>>(\n (\n prevState: readonly [Value /* contextValue */, SelectedValue /* selector(value) */],\n payload:\n | undefined // undefined from render below\n | readonly [ContextVersion, Value], // from provider effect\n ): readonly [Value, SelectedValue] => {\n if (!payload) {\n // early bail out when is dispatched during render\n return [value, selected] as const;\n }\n\n if (payload[0] <= version) {\n if (objectIs(prevState[1], selected)) {\n return prevState; // bail out\n }\n\n return [value, selected] as const;\n }\n\n try {\n if (objectIs(prevState[0], payload[1])) {\n return prevState; // do not update\n }\n\n const nextSelected = selector(payload[1]);\n\n if (objectIs(prevState[1], nextSelected)) {\n return prevState; // do not update\n }\n\n return [payload[1], nextSelected] as const;\n } catch (e) {\n // ignored (stale props or some other reason)\n }\n\n // explicitly spread to enforce typing\n return [prevState[0], prevState[1]] as const; // schedule update\n },\n [value, selected] as const,\n );\n\n if (!objectIs(state[1], selected)) {\n // schedule re-render\n // this is safe because it's self contained\n dispatch(undefined);\n }\n\n useIsomorphicLayoutEffect(() => {\n listeners.push(dispatch);\n\n return () => {\n const index = listeners.indexOf(dispatch);\n listeners.splice(index, 1);\n };\n }, [listeners]);\n\n return state[1] as SelectedValue;\n};\n\n/**\n * inlined Object.is polyfill to avoid requiring consumers ship their own\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction is(x: any, y: any) {\n return (\n (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst objectIs: (x: any, y: any) => boolean =\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore fallback to native if it exists (not in IE11)\n typeof Object.is === 'function' ? Object.is : is;\n"]}
1
+ {"version":3,"mappings":"AAAA,SAASA,yBAAyB,QAAQ,2BAA2B;AACrE,OAAO,KAAKC,KAAK,MAAM,OAAO;AAa9B;;;;;;AAMA,OAAO,MAAMC,kBAAkB,GAAG,CAChCC,OAAuB,EACvBC,QAA+C,KAC9B;EACjB,MAAMC,YAAY,GAAGJ,KAAK,CAACK,UAAU,CAAEH,OAAmD,CAAC;EAE3F,MAAM;IACJI,KAAK,EAAE;MAAEC,OAAO,EAAED;IAAK,CAAE;IACzBE,OAAO,EAAE;MAAED,OAAO,EAAEC;IAAO,CAAE;IAC7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SAAS,CAACW,IAAI,CAACR,QAAQ,CAAC;IAExB,OAAO,MAAK;MACV,MAAMS,KAAK,GAAGZ,SAAS,CAACa,OAAO,CAACV,QAAQ,CAAC;MACzCH,SAAS,CAACc,MAAM,CAACF,KAAK,EAAE,CAAC,CAAC;IAC5B,CAAC;EACH,CAAC,EAAE,CAACZ,SAAS,CAAC,CAAC;EAEf,OAAOE,KAAK,CAAC,CAAC,CAAkB;AAClC,CAAC;AAED;;;;AAIA;AACA,SAASa,EAAE,CAACC,CAAM,EAAEC,CAAM;EACxB,OACGD,CAAC,KAAKC,CAAC,KAAKD,CAAC,KAAK,CAAC,IAAI,CAAC,GAAGA,CAAC,KAAK,CAAC,GAAGC,CAAC,CAAC,IAAMD,CAAC,KAAKA,CAAC,IAAIC,CAAC,KAAKA,CAAE,CAAC;EAAA;AAEtE;AAEA;AACA,MAAMV,QAAQ;AACZ;AACA;AACA,OAAOW,MAAM,CAACH,EAAE,KAAK,UAAU,GAAGG,MAAM,CAACH,EAAE,GAAGA,EAAE","names":["useIsomorphicLayoutEffect","React","useContextSelector","context","selector","contextValue","useContext","value","current","version","listeners","selected","state","dispatch","useReducer","prevState","payload","objectIs","nextSelected","e","undefined","push","index","indexOf","splice","is","x","y","Object"],"sourceRoot":"../src/","sources":["packages/react-components/react-context-selector/src/useContextSelector.ts"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { Context, ContextSelector, ContextValue, ContextVersion } from './types';\n\n/**\n * Narrowing React.Reducer type to be more easily usable below.\n * No need to export this as it's for internal reducer usage.\n */\ntype ContextReducer<Value, SelectedValue> = React.Reducer<\n readonly [Value, SelectedValue],\n undefined | readonly [ContextVersion, Value]\n>;\n\n/**\n * @internal\n * This hook returns context selected value by selector.\n * It will only accept context created by `createContext`.\n * It will trigger re-render if only the selected value is referentially changed.\n */\nexport const useContextSelector = <Value, SelectedValue>(\n context: Context<Value>,\n selector: ContextSelector<Value, SelectedValue>,\n): SelectedValue => {\n const contextValue = React.useContext((context as unknown) as Context<ContextValue<Value>>);\n\n const {\n value: { current: value },\n version: { current: version },\n listeners,\n } = contextValue;\n const selected = selector(value);\n\n const [state, dispatch] = React.useReducer<ContextReducer<Value, SelectedValue>>(\n (\n prevState: readonly [Value /* contextValue */, SelectedValue /* selector(value) */],\n payload:\n | undefined // undefined from render below\n | readonly [ContextVersion, Value], // from provider effect\n ): readonly [Value, SelectedValue] => {\n if (!payload) {\n // early bail out when is dispatched during render\n return [value, selected] as const;\n }\n\n if (payload[0] <= version) {\n if (objectIs(prevState[1], selected)) {\n return prevState; // bail out\n }\n\n return [value, selected] as const;\n }\n\n try {\n if (objectIs(prevState[0], payload[1])) {\n return prevState; // do not update\n }\n\n const nextSelected = selector(payload[1]);\n\n if (objectIs(prevState[1], nextSelected)) {\n return prevState; // do not update\n }\n\n return [payload[1], nextSelected] as const;\n } catch (e) {\n // ignored (stale props or some other reason)\n }\n\n // explicitly spread to enforce typing\n return [prevState[0], prevState[1]] as const; // schedule update\n },\n [value, selected] as const,\n );\n\n if (!objectIs(state[1], selected)) {\n // schedule re-render\n // this is safe because it's self contained\n dispatch(undefined);\n }\n\n useIsomorphicLayoutEffect(() => {\n listeners.push(dispatch);\n\n return () => {\n const index = listeners.indexOf(dispatch);\n listeners.splice(index, 1);\n };\n }, [listeners]);\n\n return state[1] as SelectedValue;\n};\n\n/**\n * inlined Object.is polyfill to avoid requiring consumers ship their own\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction is(x: any, y: any) {\n return (\n (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst objectIs: (x: any, y: any) => boolean =\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore fallback to native if it exists (not in IE11)\n typeof Object.is === 'function' ? Object.is : is;\n"]}
@@ -6,7 +6,7 @@ define(["require", "exports", "@fluentui/react-utilities", "react"], function (r
6
6
  * @internal
7
7
  * This hook returns context selected value by selector.
8
8
  * It will only accept context created by `createContext`.
9
- * It will trigger re-render if only the selected value is referencially changed.
9
+ * It will trigger re-render if only the selected value is referentially changed.
10
10
  */
11
11
  var useContextSelector = function (context, selector) {
12
12
  var contextValue = React.useContext(context);
@@ -1 +1 @@
1
- {"version":3,"file":"useContextSelector.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/react-context-selector/src/useContextSelector.ts"],"names":[],"mappings":";;;;IAcA;;;;;OAKG;IACI,IAAM,kBAAkB,GAAG,UAChC,OAAuB,EACvB,QAA+C;QAE/C,IAAM,YAAY,GAAG,KAAK,CAAC,UAAU,CAAE,OAAmD,CAAC,CAAC;QAGjF,IAAS,KAAK,GAGrB,YAAY,cAHS,EACH,OAAO,GAEzB,YAAY,gBAFa,EAC3B,SAAS,GACP,YAAY,UADL,CACM;QACjB,IAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QAE3B,IAAA,KAAoB,KAAK,CAAC,UAAU,CACxC,UACE,SAAmF,EACnF,OAEoC;YAEpC,IAAI,CAAC,OAAO,EAAE;gBACZ,kDAAkD;gBAClD,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAU,CAAC;aACnC;YAED,IAAI,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,EAAE;gBACzB,IAAI,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE;oBACpC,OAAO,SAAS,CAAC,CAAC,WAAW;iBAC9B;gBAED,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAU,CAAC;aACnC;YAED,IAAI;gBACF,IAAI,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;oBACtC,OAAO,SAAS,CAAC,CAAC,gBAAgB;iBACnC;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C,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,sCAAsC;SACzG,CAAC;IACJ,CAAC;IAED,8DAA8D;IAC9D,IAAM,QAAQ;IACZ,6DAA6D;IAC7D,2DAA2D;IAC3D,OAAO,MAAM,CAAC,EAAE,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC","sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { Context, ContextSelector, ContextValue, ContextVersion } from './types';\n\n/**\n * Narrowing React.Reducer type to be more easily usable below.\n * No need to export this as it's for internal reducer usage.\n */\ntype ContextReducer<Value, SelectedValue> = React.Reducer<\n readonly [Value, SelectedValue],\n undefined | readonly [ContextVersion, Value]\n>;\n\n/**\n * @internal\n * This hook returns context selected value by selector.\n * It will only accept context created by `createContext`.\n * It will trigger re-render if only the selected value is referencially changed.\n */\nexport const useContextSelector = <Value, SelectedValue>(\n context: Context<Value>,\n selector: ContextSelector<Value, SelectedValue>,\n): SelectedValue => {\n const contextValue = React.useContext((context as unknown) as Context<ContextValue<Value>>);\n\n const {\n value: { current: value },\n version: { current: version },\n listeners,\n } = contextValue;\n const selected = selector(value);\n\n const [state, dispatch] = React.useReducer<ContextReducer<Value, SelectedValue>>(\n (\n prevState: readonly [Value /* contextValue */, SelectedValue /* selector(value) */],\n payload:\n | undefined // undefined from render below\n | readonly [ContextVersion, Value], // from provider effect\n ): readonly [Value, SelectedValue] => {\n if (!payload) {\n // early bail out when is dispatched during render\n return [value, selected] as const;\n }\n\n if (payload[0] <= version) {\n if (objectIs(prevState[1], selected)) {\n return prevState; // bail out\n }\n\n return [value, selected] as const;\n }\n\n try {\n if (objectIs(prevState[0], payload[1])) {\n return prevState; // do not update\n }\n\n const nextSelected = selector(payload[1]);\n\n if (objectIs(prevState[1], nextSelected)) {\n return prevState; // do not update\n }\n\n return [payload[1], nextSelected] as const;\n } catch (e) {\n // ignored (stale props or some other reason)\n }\n\n // explicitly spread to enforce typing\n return [prevState[0], prevState[1]] as const; // schedule update\n },\n [value, selected] as const,\n );\n\n if (!objectIs(state[1], selected)) {\n // schedule re-render\n // this is safe because it's self contained\n dispatch(undefined);\n }\n\n useIsomorphicLayoutEffect(() => {\n listeners.push(dispatch);\n\n return () => {\n const index = listeners.indexOf(dispatch);\n listeners.splice(index, 1);\n };\n }, [listeners]);\n\n return state[1] as SelectedValue;\n};\n\n/**\n * inlined Object.is polyfill to avoid requiring consumers ship their own\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction is(x: any, y: any) {\n return (\n (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst objectIs: (x: any, y: any) => boolean =\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore fallback to native if it exists (not in IE11)\n typeof Object.is === 'function' ? Object.is : is;\n"]}
1
+ {"version":3,"file":"useContextSelector.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/react-context-selector/src/useContextSelector.ts"],"names":[],"mappings":";;;;IAcA;;;;;OAKG;IACI,IAAM,kBAAkB,GAAG,UAChC,OAAuB,EACvB,QAA+C;QAE/C,IAAM,YAAY,GAAG,KAAK,CAAC,UAAU,CAAE,OAAmD,CAAC,CAAC;QAGjF,IAAS,KAAK,GAGrB,YAAY,cAHS,EACH,OAAO,GAEzB,YAAY,gBAFa,EAC3B,SAAS,GACP,YAAY,UADL,CACM;QACjB,IAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QAE3B,IAAA,KAAoB,KAAK,CAAC,UAAU,CACxC,UACE,SAAmF,EACnF,OAEoC;YAEpC,IAAI,CAAC,OAAO,EAAE;g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,GAAG,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;gBAC1C,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YAC7B,CAAC,CAAC;QACJ,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;QAEhB,OAAO,KAAK,CAAC,CAAC,CAAkB,CAAC;IACnC,CAAC,CAAC;IAvEW,QAAA,kBAAkB,sBAuE7B;IAEF;;;OAGG;IACH,8DAA8D;IAC9D,SAAS,EAAE,CAAC,CAAM,EAAE,CAAM;QACxB,OAAO,CACL,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,sCAAsC;SACzG,CAAC;IACJ,CAAC;IAED,8DAA8D;IAC9D,IAAM,QAAQ;IACZ,6DAA6D;IAC7D,2DAA2D;IAC3D,OAAO,MAAM,CAAC,EAAE,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC","sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { Context, ContextSelector, ContextValue, ContextVersion } from './types';\n\n/**\n * Narrowing React.Reducer type to be more easily usable below.\n * No need to export this as it's for internal reducer usage.\n */\ntype ContextReducer<Value, SelectedValue> = React.Reducer<\n readonly [Value, SelectedValue],\n undefined | readonly [ContextVersion, Value]\n>;\n\n/**\n * @internal\n * This hook returns context selected value by selector.\n * It will only accept context created by `createContext`.\n * It will trigger re-render if only the selected value is referentially changed.\n */\nexport const useContextSelector = <Value, SelectedValue>(\n context: Context<Value>,\n selector: ContextSelector<Value, SelectedValue>,\n): SelectedValue => {\n const contextValue = React.useContext((context as unknown) as Context<ContextValue<Value>>);\n\n const {\n value: { current: value },\n version: { current: version },\n listeners,\n } = contextValue;\n const selected = selector(value);\n\n const [state, dispatch] = React.useReducer<ContextReducer<Value, SelectedValue>>(\n (\n prevState: readonly [Value /* contextValue */, SelectedValue /* selector(value) */],\n payload:\n | undefined // undefined from render below\n | readonly [ContextVersion, Value], // from provider effect\n ): readonly [Value, SelectedValue] => {\n if (!payload) {\n // early bail out when is dispatched during render\n return [value, selected] as const;\n }\n\n if (payload[0] <= version) {\n if (objectIs(prevState[1], selected)) {\n return prevState; // bail out\n }\n\n return [value, selected] as const;\n }\n\n try {\n if (objectIs(prevState[0], payload[1])) {\n return prevState; // do not update\n }\n\n const nextSelected = selector(payload[1]);\n\n if (objectIs(prevState[1], nextSelected)) {\n return prevState; // do not update\n }\n\n return [payload[1], nextSelected] as const;\n } catch (e) {\n // ignored (stale props or some other reason)\n }\n\n // explicitly spread to enforce typing\n return [prevState[0], prevState[1]] as const; // schedule update\n },\n [value, selected] as const,\n );\n\n if (!objectIs(state[1], selected)) {\n // schedule re-render\n // this is safe because it's self contained\n dispatch(undefined);\n }\n\n useIsomorphicLayoutEffect(() => {\n listeners.push(dispatch);\n\n return () => {\n const index = listeners.indexOf(dispatch);\n listeners.splice(index, 1);\n };\n }, [listeners]);\n\n return state[1] as SelectedValue;\n};\n\n/**\n * inlined Object.is polyfill to avoid requiring consumers ship their own\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction is(x: any, y: any) {\n return (\n (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst objectIs: (x: any, y: any) => boolean =\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore fallback to native if it exists (not in IE11)\n typeof Object.is === 'function' ? Object.is : is;\n"]}
@@ -10,7 +10,7 @@ const React = /*#__PURE__*/require("react");
10
10
  * @internal
11
11
  * This hook returns context selected value by selector.
12
12
  * It will only accept context created by `createContext`.
13
- * It will trigger re-render if only the selected value is referencially changed.
13
+ * It will trigger re-render if only the selected value is referentially changed.
14
14
  */
15
15
  const useContextSelector = (context, selector) => {
16
16
  const contextValue = React.useContext(context);
@@ -1 +1 @@
1
- {"version":3,"mappings":";;;;;;AAAA;AACA;AAaA;;;;;;AAMO,MAAMA,kBAAkB,GAAG,CAChCC,OAAuB,EACvBC,QAA+C,KAC9B;EACjB,MAAMC,YAAY,GAAGC,KAAK,CAACC,UAAU,CAAEJ,OAAmD,CAAC;EAE3F,MAAM;IACJK,KAAK,EAAE;MAAEC,OAAO,EAAED;IAAK,CAAE;IACzBE,OAAO,EAAE;MAAED,OAAO,EAAEC;IAAO,CAAE;IAC7BC;EAAS,CACV,GAAGN,YAAY;EAChB,MAAMO,QAAQ,GAAGR,QAAQ,CAACI,KAAK,CAAC;EAEhC,MAAM,CAACK,KAAK,EAAEC,QAAQ,CAAC,GAAGR,KAAK,CAACS,UAAU,CACxC,CACEC,SAAmF,EACnFC,OAEoC,KACD;IACnC,IAAI,CAACA,OAAO,EAAE;MACZ;MACA,OAAO,CAACT,KAAK,EAAEI,QAAQ,CAAU;;IAGnC,IAAIK,OAAO,CAAC,CAAC,CAAC,IAAIP,OAAO,EAAE;MACzB,IAAIQ,QAAQ,CAACF,SAAS,CAAC,CAAC,CAAC,EAAEJ,QAAQ,CAAC,EAAE;QACpC,OAAOI,SAAS,CAAC,CAAC;;;MAGpB,OAAO,CAACR,KAAK,EAAEI,QAAQ,CAAU;;IAGnC,IAAI;MACF,IAAIM,QAAQ,CAACF,SAAS,CAAC,CAAC,CAAC,EAAEC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;QACtC,OAAOD,SAAS,CAAC,CAAC;;;MAGpB,MAAMG,YAAY,GAAGf,QAAQ,CAACa,OAAO,CAAC,CAAC,CAAC,CAAC;MAEzC,IAAIC,QAAQ,CAACF,SAAS,CAAC,CAAC,CAAC,EAAEG,YAAY,CAAC,EAAE;QACxC,OAAOH,SAAS,CAAC,CAAC;;;MAGpB,OAAO,CAACC,OAAO,CAAC,CAAC,CAAC,EAAEE,YAAY,CAAU;KAC3C,CAAC,OAAOC,CAAC,EAAE;MACV;IAAA;IAGF;IACA,OAAO,CAACJ,SAAS,CAAC,CAAC,CAAC,EAAEA,SAAS,CAAC,CAAC,CAAC,CAAU,CAAC,CAAC;EAChD,CAAC,EACD,CAACR,KAAK,EAAEI,QAAQ,CAAU,CAC3B;EAED,IAAI,CAACM,QAAQ,CAACL,KAAK,CAAC,CAAC,CAAC,EAAED,QAAQ,CAAC,EAAE;IACjC;IACA;IACAE,QAAQ,CAACO,SAAS,CAAC;;EAGrBC,2CAAyB,CAAC,MAAK;IAC7BX,SAAS,CAACY,IAAI,CAACT,QAAQ,CAAC;IAExB,OAAO,MAAK;MACV,MAAMU,KAAK,GAAGb,SAAS,CAACc,OAAO,CAACX,QAAQ,CAAC;MACzCH,SAAS,CAACe,MAAM,CAACF,KAAK,EAAE,CAAC,CAAC;IAC5B,CAAC;EACH,CAAC,EAAE,CAACb,SAAS,CAAC,CAAC;EAEf,OAAOE,KAAK,CAAC,CAAC,CAAkB;AAClC,CAAC;AAvEYc,0BAAkB;AAyE/B;;;;AAIA;AACA,SAASC,EAAE,CAACC,CAAM,EAAEC,CAAM;EACxB,OACGD,CAAC,KAAKC,CAAC,KAAKD,CAAC,KAAK,CAAC,IAAI,CAAC,GAAGA,CAAC,KAAK,CAAC,GAAGC,CAAC,CAAC,IAAMD,CAAC,KAAKA,CAAC,IAAIC,CAAC,KAAKA,CAAE,CAAC;EAAA;AAEtE;AAEA;AACA,MAAMZ,QAAQ;AACZ;AACA;AACA,OAAOa,MAAM,CAACH,EAAE,KAAK,UAAU,GAAGG,MAAM,CAACH,EAAE,GAAGA,EAAE","names":["useContextSelector","context","selector","contextValue","React","useContext","value","current","version","listeners","selected","state","dispatch","useReducer","prevState","payload","objectIs","nextSelected","e","undefined","react_utilities_1","push","index","indexOf","splice","exports","is","x","y","Object"],"sourceRoot":"../src/","sources":["packages/react-components/react-context-selector/src/useContextSelector.ts"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { Context, ContextSelector, ContextValue, ContextVersion } from './types';\n\n/**\n * Narrowing React.Reducer type to be more easily usable below.\n * No need to export this as it's for internal reducer usage.\n */\ntype ContextReducer<Value, SelectedValue> = React.Reducer<\n readonly [Value, SelectedValue],\n undefined | readonly [ContextVersion, Value]\n>;\n\n/**\n * @internal\n * This hook returns context selected value by selector.\n * It will only accept context created by `createContext`.\n * It will trigger re-render if only the selected value is referencially changed.\n */\nexport const useContextSelector = <Value, SelectedValue>(\n context: Context<Value>,\n selector: ContextSelector<Value, SelectedValue>,\n): SelectedValue => {\n const contextValue = React.useContext((context as unknown) as Context<ContextValue<Value>>);\n\n const {\n value: { current: value },\n version: { current: version },\n listeners,\n } = contextValue;\n const selected = selector(value);\n\n const [state, dispatch] = React.useReducer<ContextReducer<Value, SelectedValue>>(\n (\n prevState: readonly [Value /* contextValue */, SelectedValue /* selector(value) */],\n payload:\n | undefined // undefined from render below\n | readonly [ContextVersion, Value], // from provider effect\n ): readonly [Value, SelectedValue] => {\n if (!payload) {\n // early bail out when is dispatched during render\n return [value, selected] as const;\n }\n\n if (payload[0] <= version) {\n if (objectIs(prevState[1], selected)) {\n return prevState; // bail out\n }\n\n return [value, selected] as const;\n }\n\n try {\n if (objectIs(prevState[0], payload[1])) {\n return prevState; // do not update\n }\n\n const nextSelected = selector(payload[1]);\n\n if (objectIs(prevState[1], nextSelected)) {\n return prevState; // do not update\n }\n\n return [payload[1], nextSelected] as const;\n } catch (e) {\n // ignored (stale props or some other reason)\n }\n\n // explicitly spread to enforce typing\n return [prevState[0], prevState[1]] as const; // schedule update\n },\n [value, selected] as const,\n );\n\n if (!objectIs(state[1], selected)) {\n // schedule re-render\n // this is safe because it's self contained\n dispatch(undefined);\n }\n\n useIsomorphicLayoutEffect(() => {\n listeners.push(dispatch);\n\n return () => {\n const index = listeners.indexOf(dispatch);\n listeners.splice(index, 1);\n };\n }, [listeners]);\n\n return state[1] as SelectedValue;\n};\n\n/**\n * inlined Object.is polyfill to avoid requiring consumers ship their own\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction is(x: any, y: any) {\n return (\n (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst objectIs: (x: any, y: any) => boolean =\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore fallback to native if it exists (not in IE11)\n typeof Object.is === 'function' ? Object.is : is;\n"]}
1
+ {"version":3,"mappings":";;;;;;AAAA;AACA;AAaA;;;;;;AAMO,MAAMA,kBAAkB,GAAG,CAChCC,OAAuB,EACvBC,QAA+C,KAC9B;EACjB,MAAMC,YAAY,GAAGC,KAAK,CAACC,UAAU,CAAEJ,OAAmD,CAAC;EAE3F,MAAM;IACJK,KAAK,EAAE;MAAEC,OAAO,EAAED;IAAK,CAAE;IACzBE,OAAO,EAAE;MAAED,OAAO,EAAEC;IAAO,CAAE;IAC7BC;EAAS,CACV,GAAGN,YAAY;EAChB,MAAMO,QAAQ,GAAGR,QAAQ,CAACI,KAAK,CAAC;EAEhC,MAAM,CAACK,KAAK,EAAEC,QAAQ,CAAC,GAAGR,KAAK,CAACS,UAAU,CACxC,CACEC,SAAmF,EACnFC,OAEoC,KACD;IACnC,IAAI,CAACA,OAAO,EAAE;MACZ;MACA,OAAO,CAACT,KAAK,EAAEI,QAAQ,CAAU;;IAGnC,IAAIK,OAAO,CAAC,CAAC,CAAC,IAAIP,OAAO,EAAE;MACzB,IAAIQ,QAAQ,CAACF,SAAS,CAAC,CAAC,CAAC,EAAEJ,QAAQ,CAAC,EAAE;QACp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AI,CAAC,GAAGA,CAAC,KAAK,CAAC,GAAGC,CAAC,CAAC,IAAMD,CAAC,KAAKA,CAAC,IAAIC,CAAC,KAAKA,CAAE,CAAC;EAAA;AAEtE;AAEA;AACA,MAAMZ,QAAQ;AACZ;AACA;AACA,OAAOa,MAAM,CAACH,EAAE,KAAK,UAAU,GAAGG,MAAM,CAACH,EAAE,GAAGA,EAAE","names":["useContextSelector","context","selector","contextValue","React","useContext","value","current","version","listeners","selected","state","dispatch","useReducer","prevState","payload","objectIs","nextSelected","e","undefined","react_utilities_1","push","index","indexOf","splice","exports","is","x","y","Object"],"sourceRoot":"../src/","sources":["packages/react-components/react-context-selector/src/useContextSelector.ts"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { Context, ContextSelector, ContextValue, ContextVersion } from './types';\n\n/**\n * Narrowing React.Reducer type to be more easily usable below.\n * No need to export this as it's for internal reducer usage.\n */\ntype ContextReducer<Value, SelectedValue> = React.Reducer<\n readonly [Value, SelectedValue],\n undefined | readonly [ContextVersion, Value]\n>;\n\n/**\n * @internal\n * This hook returns context selected value by selector.\n * It will only accept context created by `createContext`.\n * It will trigger re-render if only the selected value is referentially changed.\n */\nexport const useContextSelector = <Value, SelectedValue>(\n context: Context<Value>,\n selector: ContextSelector<Value, SelectedValue>,\n): SelectedValue => {\n const contextValue = React.useContext((context as unknown) as Context<ContextValue<Value>>);\n\n const {\n value: { current: value },\n version: { current: version },\n listeners,\n } = contextValue;\n const selected = selector(value);\n\n const [state, dispatch] = React.useReducer<ContextReducer<Value, SelectedValue>>(\n (\n prevState: readonly [Value /* contextValue */, SelectedValue /* selector(value) */],\n payload:\n | undefined // undefined from render below\n | readonly [ContextVersion, Value], // from provider effect\n ): readonly [Value, SelectedValue] => {\n if (!payload) {\n // early bail out when is dispatched during render\n return [value, selected] as const;\n }\n\n if (payload[0] <= version) {\n if (objectIs(prevState[1], selected)) {\n return prevState; // bail out\n }\n\n return [value, selected] as const;\n }\n\n try {\n if (objectIs(prevState[0], payload[1])) {\n return prevState; // do not update\n }\n\n const nextSelected = selector(payload[1]);\n\n if (objectIs(prevState[1], nextSelected)) {\n return prevState; // do not update\n }\n\n return [payload[1], nextSelected] as const;\n } catch (e) {\n // ignored (stale props or some other reason)\n }\n\n // explicitly spread to enforce typing\n return [prevState[0], prevState[1]] as const; // schedule update\n },\n [value, selected] as const,\n );\n\n if (!objectIs(state[1], selected)) {\n // schedule re-render\n // this is safe because it's self contained\n dispatch(undefined);\n }\n\n useIsomorphicLayoutEffect(() => {\n listeners.push(dispatch);\n\n return () => {\n const index = listeners.indexOf(dispatch);\n listeners.splice(index, 1);\n };\n }, [listeners]);\n\n return state[1] as SelectedValue;\n};\n\n/**\n * inlined Object.is polyfill to avoid requiring consumers ship their own\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction is(x: any, y: any) {\n return (\n (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst objectIs: (x: any, y: any) => boolean =\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore fallback to native if it exists (not in IE11)\n typeof Object.is === 'function' ? Object.is : is;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-context-selector",
3
- "version": "9.1.4",
3
+ "version": "9.1.6",
4
4
  "description": "React useContextSelector hook in userland",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",
@@ -23,10 +23,11 @@
23
23
  },
24
24
  "devDependencies": {
25
25
  "@fluentui/eslint-plugin": "*",
26
- "@fluentui/scripts": "*"
26
+ "@fluentui/scripts-api-extractor": "*",
27
+ "@fluentui/scripts-tasks": "*"
27
28
  },
28
29
  "dependencies": {
29
- "@fluentui/react-utilities": "^9.3.1",
30
+ "@fluentui/react-utilities": "^9.5.0",
30
31
  "tslib": "^2.1.0"
31
32
  },
32
33
  "peerDependencies": {