@fluentui/react-context-selector 0.0.0-nightly-20230317-1454.1 → 0.0.0-nightly-20230322-0439.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/.swcrc CHANGED
@@ -1,15 +1,5 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/swcrc",
3
- "env": {
4
- "targets": {
5
- "chrome": "84",
6
- "edge": "84",
7
- "firefox": "75",
8
- "opera": "73",
9
- "safari": "14.1"
10
- },
11
- "bugfixes": true
12
- },
13
3
  "exclude": [
14
4
  "/testing",
15
5
  "/**/*.cy.ts",
@@ -32,7 +22,8 @@
32
22
  "runtime": "classic",
33
23
  "useSpread": true
34
24
  }
35
- }
25
+ },
26
+ "target": "es2019"
36
27
  },
37
28
  "minify": false,
38
29
  "sourceMaps": true
package/CHANGELOG.json CHANGED
@@ -2,9 +2,9 @@
2
2
  "name": "@fluentui/react-context-selector",
3
3
  "entries": [
4
4
  {
5
- "date": "Fri, 17 Mar 2023 15:00:14 GMT",
6
- "tag": "@fluentui/react-context-selector_v0.0.0-nightly-20230317-1454.1",
7
- "version": "0.0.0-nightly-20230317-1454.1",
5
+ "date": "Wed, 22 Mar 2023 04:46:41 GMT",
6
+ "tag": "@fluentui/react-context-selector_v0.0.0-nightly-20230322-0439.1",
7
+ "version": "0.0.0-nightly-20230322-0439.1",
8
8
  "comments": {
9
9
  "prerelease": [
10
10
  {
@@ -16,8 +16,35 @@
16
16
  {
17
17
  "author": "beachball",
18
18
  "package": "@fluentui/react-context-selector",
19
- "comment": "Bump @fluentui/react-utilities to v0.0.0-nightly-20230317-1454.1",
20
- "commit": "636275472966fa37b1efc14ac2e70ad32bd39b86"
19
+ "comment": "Bump @fluentui/react-utilities to v0.0.0-nightly-20230322-0439.1",
20
+ "commit": "49dde84493fc2c3e96abac5ce918169c9668ba66"
21
+ }
22
+ ]
23
+ }
24
+ },
25
+ {
26
+ "date": "Tue, 21 Mar 2023 21:23:30 GMT",
27
+ "tag": "@fluentui/react-context-selector_v9.1.15",
28
+ "version": "9.1.15",
29
+ "comments": {
30
+ "patch": [
31
+ {
32
+ "author": "tristan.watanabe@gmail.com",
33
+ "package": "@fluentui/react-context-selector",
34
+ "commit": "ead1c6d4c2ac3f3596b62b8cbc07b0a03041f11f",
35
+ "comment": "fix: add node field to package.json exports map."
36
+ },
37
+ {
38
+ "author": "tristan.watanabe@gmail.com",
39
+ "package": "@fluentui/react-context-selector",
40
+ "commit": "2fac1a139149bd13b76b1306207bc988dca9c72c",
41
+ "comment": "chore: migrate to swc transpilation approach."
42
+ },
43
+ {
44
+ "author": "beachball",
45
+ "package": "@fluentui/react-context-selector",
46
+ "comment": "Bump @fluentui/react-utilities to v9.7.2",
47
+ "commit": "b7a26f6263c80e3253c6b8338c33b73bae33e2b5"
21
48
  }
22
49
  ]
23
50
  }
package/CHANGELOG.md CHANGED
@@ -1,18 +1,29 @@
1
1
  # Change Log - @fluentui/react-context-selector
2
2
 
3
- This log was last generated on Fri, 17 Mar 2023 15:00:14 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 22 Mar 2023 04:46:41 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## [0.0.0-nightly-20230317-1454.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v0.0.0-nightly-20230317-1454.1)
7
+ ## [0.0.0-nightly-20230322-0439.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v0.0.0-nightly-20230322-0439.1)
8
8
 
9
- Fri, 17 Mar 2023 15:00:14 GMT
10
- [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.14..@fluentui/react-context-selector_v0.0.0-nightly-20230317-1454.1)
9
+ Wed, 22 Mar 2023 04:46:41 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.15..@fluentui/react-context-selector_v0.0.0-nightly-20230322-0439.1)
11
11
 
12
12
  ### Changes
13
13
 
14
14
  - Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/not available) by fluentui-internal@service.microsoft.com)
15
- - Bump @fluentui/react-utilities to v0.0.0-nightly-20230317-1454.1 ([commit](https://github.com/microsoft/fluentui/commit/636275472966fa37b1efc14ac2e70ad32bd39b86) by beachball)
15
+ - Bump @fluentui/react-utilities to v0.0.0-nightly-20230322-0439.1 ([commit](https://github.com/microsoft/fluentui/commit/49dde84493fc2c3e96abac5ce918169c9668ba66) by beachball)
16
+
17
+ ## [9.1.15](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.1.15)
18
+
19
+ Tue, 21 Mar 2023 21:23:30 GMT
20
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.14..@fluentui/react-context-selector_v9.1.15)
21
+
22
+ ### Patches
23
+
24
+ - fix: add node field to package.json exports map. ([PR #27154](https://github.com/microsoft/fluentui/pull/27154) by tristan.watanabe@gmail.com)
25
+ - chore: migrate to swc transpilation approach. ([PR #27250](https://github.com/microsoft/fluentui/pull/27250) by tristan.watanabe@gmail.com)
26
+ - Bump @fluentui/react-utilities to v9.7.2 ([PR #27271](https://github.com/microsoft/fluentui/pull/27271) by beachball)
16
27
 
17
28
  ## [9.1.14](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.1.14)
18
29
 
@@ -1,6 +1,6 @@
1
- import { useIsomorphicLayoutEffect } from "@fluentui/react-utilities";
2
- import * as React from "react";
3
- import { unstable_NormalPriority as NormalPriority, unstable_runWithPriority as runWithPriority } from "scheduler";
1
+ import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';
2
+ import * as React from 'react';
3
+ import { unstable_NormalPriority as NormalPriority, unstable_runWithPriority as runWithPriority } from 'scheduler';
4
4
  const createProvider = Original => {
5
5
  const Provider = props => {
6
6
  // Holds an actual "props.value"
@@ -30,8 +30,8 @@ const createProvider = Original => {
30
30
  }, props.children);
31
31
  };
32
32
  /* istanbul ignore else */
33
- if (process.env.NODE_ENV !== "production") {
34
- Provider.displayName = "ContextSelector.Provider";
33
+ if (process.env.NODE_ENV !== 'production') {
34
+ Provider.displayName = 'ContextSelector.Provider';
35
35
  }
36
36
  return Provider;
37
37
  };
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { createContext } from "./createContext";
2
- export { useContextSelector } from "./useContextSelector";
3
- export { useHasParentContext } from "./useHasParentContext";
1
+ export { createContext } from './createContext';
2
+ export { useContextSelector } from './useContextSelector';
3
+ export { useHasParentContext } from './useHasParentContext';
4
4
  //# sourceMappingURL=index.js.map
package/lib/types.js CHANGED
@@ -1,2 +1,2 @@
1
- import * as React from "react";
1
+ import * as React from 'react';
2
2
  //# sourceMappingURL=types.js.map
@@ -1,5 +1,5 @@
1
- import { useIsomorphicLayoutEffect } from "@fluentui/react-utilities";
2
- import * as React from "react";
1
+ import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';
2
+ import * as React from 'react';
3
3
  /**
4
4
  * @internal
5
5
  * This hook returns context selected value by selector.
@@ -73,5 +73,5 @@ function is(x, y) {
73
73
  const objectIs =
74
74
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
75
75
  // @ts-ignore fallback to native if it exists (not in IE11)
76
- typeof Object.is === "function" ? Object.is : is;
76
+ typeof Object.is === 'function' ? Object.is : is;
77
77
  //# sourceMappingURL=useContextSelector.js.map
@@ -1,4 +1,4 @@
1
- import * as React from "react";
1
+ import * as React from 'react';
2
2
  /**
3
3
  * @internal
4
4
  * Utility hook for contexts created by react-context-selector to determine if a parent context exists
@@ -43,8 +43,8 @@ const createProvider = (Original)=>{
43
43
  value: contextValue.current
44
44
  }, props.children);
45
45
  };
46
- /* istanbul ignore else */ if (process.env.NODE_ENV !== "production") {
47
- Provider.displayName = "ContextSelector.Provider";
46
+ /* istanbul ignore else */ if (process.env.NODE_ENV !== 'production') {
47
+ Provider.displayName = 'ContextSelector.Provider';
48
48
  }
49
49
  return Provider;
50
50
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../lib/createContext.js"],"sourcesContent":["import { useIsomorphicLayoutEffect } from \"@fluentui/react-utilities\";\nimport * as React from \"react\";\nimport { unstable_NormalPriority as NormalPriority, unstable_runWithPriority as runWithPriority } from \"scheduler\";\nconst createProvider = Original => {\n const Provider = props => {\n // Holds an actual \"props.value\"\n const valueRef = React.useRef(props.value);\n // Used to sync context updates and avoid stale values, can be considered as render/effect counter of Provider.\n const versionRef = React.useRef(0);\n // A stable object, is used to avoid context updates via mutation of its values.\n const contextValue = React.useRef();\n if (!contextValue.current) {\n contextValue.current = {\n value: valueRef,\n version: versionRef,\n listeners: []\n };\n }\n useIsomorphicLayoutEffect(() => {\n valueRef.current = props.value;\n versionRef.current += 1;\n runWithPriority(NormalPriority, () => {\n contextValue.current.listeners.forEach(listener => {\n listener([versionRef.current, props.value]);\n });\n });\n }, [props.value]);\n return /*#__PURE__*/React.createElement(Original, {\n value: contextValue.current\n }, props.children);\n };\n /* istanbul ignore else */\n if (process.env.NODE_ENV !== \"production\") {\n Provider.displayName = \"ContextSelector.Provider\";\n }\n return Provider;\n};\n/**\n * @internal\n */\nexport const createContext = defaultValue => {\n // eslint-disable-next-line @fluentui/no-context-default-value\n const context = /*#__PURE__*/React.createContext({\n value: {\n current: defaultValue\n },\n version: {\n current: -1\n },\n listeners: []\n });\n context.Provider = createProvider(context.Provider);\n // We don't support Consumer API\n delete context.Consumer;\n return context;\n};\n//# sourceMappingURL=createContext.js.map"],"names":["createContext","createProvider","Original","Provider","props","valueRef","React","useRef","value","versionRef","contextValue","current","version","listeners","useIsomorphicLayoutEffect","runWithPriority","NormalPriority","forEach","listener","createElement","children","process","env","NODE_ENV","displayName","defaultValue","context","Consumer"],"mappings":";;;;+BAwCaA;;aAAAA;;;gCAxC6B;6DACnB;2BACgF;AACvG,MAAMC,iBAAiBC,CAAAA,WAAY;IACjC,MAAMC,WAAWC,CAAAA,QAAS;QACxB,gCAAgC;QAChC,MAAMC,WAAWC,OAAMC,MAAM,CAACH,MAAMI,KAAK;QACzC,+GAA+G;QAC/G,MAAMC,aAAaH,OAAMC,MAAM,CAAC;QAChC,gFAAgF;QAChF,MAAMG,eAAeJ,OAAMC,MAAM;QACjC,IAAI,CAACG,aAAaC,OAAO,EAAE;YACzBD,aAAaC,OAAO,GAAG;gBACrBH,OAAOH;gBACPO,SAASH;gBACTI,WAAW,EAAE;YACf;QACF,CAAC;QACDC,IAAAA,yCAAyB,EAAC,IAAM;YAC9BT,SAASM,OAAO,GAAGP,MAAMI,KAAK;YAC9BC,WAAWE,OAAO,IAAI;YACtBI,IAAAA,mCAAe,EAACC,kCAAc,EAAE,IAAM;gBACpCN,aAAaC,OAAO,CAACE,SAAS,CAACI,OAAO,CAACC,CAAAA,WAAY;oBACjDA,SAAS;wBAACT,WAAWE,OAAO;wBAAEP,MAAMI,KAAK;qBAAC;gBAC5C;YACF;QACF,GAAG;YAACJ,MAAMI,KAAK;SAAC;QAChB,OAAO,WAAW,GAAEF,OAAMa,aAAa,CAACjB,UAAU;YAChDM,OAAOE,aAAaC,OAAO;QAC7B,GAAGP,MAAMgB,QAAQ;IACnB;IACA,wBAAwB,GACxB,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzCpB,SAASqB,WAAW,GAAG;IACzB,CAAC;IACD,OAAOrB;AACT;AAIO,MAAMH,gBAAgByB,CAAAA,eAAgB;IAC3C,8DAA8D;IAC9D,MAAMC,UAAU,WAAW,GAAEpB,OAAMN,aAAa,CAAC;QAC/CQ,OAAO;YACLG,SAASc;QACX;QACAb,SAAS;YACPD,SAAS,CAAC;QACZ;QACAE,WAAW,EAAE;IACf;IACAa,QAAQvB,QAAQ,GAAGF,eAAeyB,QAAQvB,QAAQ;IAClD,gCAAgC;IAChC,OAAOuB,QAAQC,QAAQ;IACvB,OAAOD;AACT,GACA,yCAAyC"}
1
+ {"version":3,"sources":["../lib/createContext.js"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { unstable_NormalPriority as NormalPriority, unstable_runWithPriority as runWithPriority } from 'scheduler';\nconst createProvider = Original => {\n const Provider = props => {\n // Holds an actual \"props.value\"\n const valueRef = React.useRef(props.value);\n // Used to sync context updates and avoid stale values, can be considered as render/effect counter of Provider.\n const versionRef = React.useRef(0);\n // A stable object, is used to avoid context updates via mutation of its values.\n const contextValue = React.useRef();\n if (!contextValue.current) {\n contextValue.current = {\n value: valueRef,\n version: versionRef,\n listeners: []\n };\n }\n useIsomorphicLayoutEffect(() => {\n valueRef.current = props.value;\n versionRef.current += 1;\n runWithPriority(NormalPriority, () => {\n contextValue.current.listeners.forEach(listener => {\n listener([versionRef.current, props.value]);\n });\n });\n }, [props.value]);\n return /*#__PURE__*/React.createElement(Original, {\n value: contextValue.current\n }, props.children);\n };\n /* istanbul ignore else */\n if (process.env.NODE_ENV !== 'production') {\n Provider.displayName = 'ContextSelector.Provider';\n }\n return Provider;\n};\n/**\n * @internal\n */\nexport const createContext = defaultValue => {\n // eslint-disable-next-line @fluentui/no-context-default-value\n const context = /*#__PURE__*/React.createContext({\n value: {\n current: defaultValue\n },\n version: {\n current: -1\n },\n listeners: []\n });\n context.Provider = createProvider(context.Provider);\n // We don't support Consumer API\n delete context.Consumer;\n return context;\n};\n//# sourceMappingURL=createContext.js.map"],"names":["createContext","createProvider","Original","Provider","props","valueRef","React","useRef","value","versionRef","contextValue","current","version","listeners","useIsomorphicLayoutEffect","runWithPriority","NormalPriority","forEach","listener","createElement","children","process","env","NODE_ENV","displayName","defaultValue","context","Consumer"],"mappings":";;;;+BAwCaA;;aAAAA;;;gCAxC6B;6DACnB;2BACgF;AACvG,MAAMC,iBAAiBC,CAAAA,WAAY;IACjC,MAAMC,WAAWC,CAAAA,QAAS;QACxB,gCAAgC;QAChC,MAAMC,WAAWC,OAAMC,MAAM,CAACH,MAAMI,KAAK;QACzC,+GAA+G;QAC/G,MAAMC,aAAaH,OAAMC,MAAM,CAAC;QAChC,gFAAgF;QAChF,MAAMG,eAAeJ,OAAMC,MAAM;QACjC,IAAI,CAACG,aAAaC,OAAO,EAAE;YACzBD,aAAaC,OAAO,GAAG;gBACrBH,OAAOH;gBACPO,SAASH;gBACTI,WAAW,EAAE;YACf;QACF,CAAC;QACDC,IAAAA,yCAAyB,EAAC,IAAM;YAC9BT,SAASM,OAAO,GAAGP,MAAMI,KAAK;YAC9BC,WAAWE,OAAO,IAAI;YACtBI,IAAAA,mCAAe,EAACC,kCAAc,EAAE,IAAM;gBACpCN,aAAaC,OAAO,CAACE,SAAS,CAACI,OAAO,CAACC,CAAAA,WAAY;oBACjDA,SAAS;wBAACT,WAAWE,OAAO;wBAAEP,MAAMI,KAAK;qBAAC;gBAC5C;YACF;QACF,GAAG;YAACJ,MAAMI,KAAK;SAAC;QAChB,OAAO,WAAW,GAAEF,OAAMa,aAAa,CAACjB,UAAU;YAChDM,OAAOE,aAAaC,OAAO;QAC7B,GAAGP,MAAMgB,QAAQ;IACnB;IACA,wBAAwB,GACxB,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzCpB,SAASqB,WAAW,GAAG;IACzB,CAAC;IACD,OAAOrB;AACT;AAIO,MAAMH,gBAAgByB,CAAAA,eAAgB;IAC3C,8DAA8D;IAC9D,MAAMC,UAAU,WAAW,GAAEpB,OAAMN,aAAa,CAAC;QAC/CQ,OAAO;YACLG,SAASc;QACX;QACAb,SAAS;YACPD,SAAS,CAAC;QACZ;QACAE,WAAW,EAAE;IACf;IACAa,QAAQvB,QAAQ,GAAGF,eAAeyB,QAAQvB,QAAQ;IAClD,gCAAgC;IAChC,OAAOuB,QAAQC,QAAQ;IACvB,OAAOD;AACT,GACA,yCAAyC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../lib/index.js"],"sourcesContent":["export { createContext } from \"./createContext\";\nexport { useContextSelector } from \"./useContextSelector\";\nexport { useHasParentContext } from \"./useHasParentContext\";\n//# sourceMappingURL=index.js.map"],"names":["createContext","useContextSelector","useHasParentContext"],"mappings":";;;;;;;;;;;IAASA,aAAa,MAAbA,4BAAa;IACbC,kBAAkB,MAAlBA,sCAAkB;IAClBC,mBAAmB,MAAnBA,wCAAmB;;+BAFE;oCACK;qCACC;CACpC,iCAAiC"}
1
+ {"version":3,"sources":["../lib/index.js"],"sourcesContent":["export { createContext } from './createContext';\nexport { useContextSelector } from './useContextSelector';\nexport { useHasParentContext } from './useHasParentContext';\n//# sourceMappingURL=index.js.map"],"names":["createContext","useContextSelector","useHasParentContext"],"mappings":";;;;;;;;;;;IAASA,aAAa,MAAbA,4BAAa;IACbC,kBAAkB,MAAlBA,sCAAkB;IAClBC,mBAAmB,MAAnBA,wCAAmB;;+BAFE;oCACK;qCACC;CACpC,iCAAiC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../lib/types.js"],"sourcesContent":["import * as React from \"react\";\n//# sourceMappingURL=types.js.map"],"names":[],"mappings":";;;;;6DAAuB;CACvB,iCAAiC"}
1
+ {"version":3,"sources":["../lib/types.js"],"sourcesContent":["import * as React from 'react';\n//# sourceMappingURL=types.js.map"],"names":[],"mappings":";;;;;6DAAuB;CACvB,iCAAiC"}
@@ -81,6 +81,6 @@ function is(x, y) {
81
81
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
82
  const objectIs = // eslint-disable-next-line @typescript-eslint/ban-ts-comment
83
83
  // @ts-ignore fallback to native if it exists (not in IE11)
84
- typeof Object.is === "function" ? Object.is : is; //# sourceMappingURL=useContextSelector.js.map
84
+ typeof Object.is === 'function' ? Object.is : is; //# sourceMappingURL=useContextSelector.js.map
85
85
 
86
86
  //# sourceMappingURL=useContextSelector.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../lib/useContextSelector.js"],"sourcesContent":["import { useIsomorphicLayoutEffect } from \"@fluentui/react-utilities\";\nimport * as React from \"react\";\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 = (context, selector) => {\n const contextValue = React.useContext(context);\n const {\n value: {\n current: value\n },\n version: {\n current: version\n },\n listeners\n } = contextValue;\n const selected = selector(value);\n const [state, dispatch] = React.useReducer((prevState, payload) => {\n if (!payload) {\n // early bail out when is dispatched during render\n return [value, selected];\n }\n if (payload[0] <= version) {\n if (objectIs(prevState[1], selected)) {\n return prevState; // bail out\n }\n\n return [value, selected];\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 if (objectIs(prevState[1], nextSelected)) {\n return prevState; // do not update\n }\n\n return [payload[1], nextSelected];\n } catch (e) {\n // ignored (stale props or some other reason)\n }\n // explicitly spread to enforce typing\n return [prevState[0], prevState[1]]; // schedule update\n }, [value, selected]);\n if (!objectIs(state[1], selected)) {\n // schedule re-render\n // this is safe because it's self contained\n dispatch(undefined);\n }\n useIsomorphicLayoutEffect(() => {\n listeners.push(dispatch);\n return () => {\n const index = listeners.indexOf(dispatch);\n listeners.splice(index, 1);\n };\n }, [listeners]);\n return state[1];\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 */ // eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction is(x, y) {\n return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare\n ;\n}\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst objectIs =\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore fallback to native if it exists (not in IE11)\ntypeof Object.is === \"function\" ? Object.is : is;\n//# sourceMappingURL=useContextSelector.js.map"],"names":["useContextSelector","context","selector","contextValue","React","useContext","value","current","version","listeners","selected","state","dispatch","useReducer","prevState","payload","objectIs","nextSelected","e","undefined","useIsomorphicLayoutEffect","push","index","indexOf","splice","is","x","y","Object"],"mappings":";;;;+BAQaA;;aAAAA;;;gCAR6B;6DACnB;AAOhB,MAAMA,qBAAqB,CAACC,SAASC,WAAa;IACvD,MAAMC,eAAeC,OAAMC,UAAU,CAACJ;IACtC,MAAM,EACJK,OAAO,EACLC,SAASD,MAAK,EACf,CAAA,EACDE,SAAS,EACPD,SAASC,QAAO,EACjB,CAAA,EACDC,UAAS,EACV,GAAGN;IACJ,MAAMO,WAAWR,SAASI;IAC1B,MAAM,CAACK,OAAOC,SAAS,GAAGR,OAAMS,UAAU,CAAC,CAACC,WAAWC,UAAY;QACjE,IAAI,CAACA,SAAS;YACZ,kDAAkD;YAClD,OAAO;gBAACT;gBAAOI;aAAS;QAC1B,CAAC;QACD,IAAIK,OAAO,CAAC,EAAE,IAAIP,SAAS;YACzB,IAAIQ,SAASF,SAAS,CAAC,EAAE,EAAEJ,WAAW;gBACpC,OAAOI,WAAW,WAAW;YAC/B,CAAC;YAED,OAAO;gBAACR;gBAAOI;aAAS;QAC1B,CAAC;QACD,IAAI;YACF,IAAIM,SAASF,SAAS,CAAC,EAAE,EAAEC,OAAO,CAAC,EAAE,GAAG;gBACtC,OAAOD,WAAW,gBAAgB;YACpC,CAAC;YAED,MAAMG,eAAef,SAASa,OAAO,CAAC,EAAE;YACxC,IAAIC,SAASF,SAAS,CAAC,EAAE,EAAEG,eAAe;gBACxC,OAAOH,WAAW,gBAAgB;YACpC,CAAC;YAED,OAAO;gBAACC,OAAO,CAAC,EAAE;gBAAEE;aAAa;QACnC,EAAE,OAAOC,GAAG;QACV,6CAA6C;QAC/C;QACA,sCAAsC;QACtC,OAAO;YAACJ,SAAS,CAAC,EAAE;YAAEA,SAAS,CAAC,EAAE;SAAC,EAAE,kBAAkB;IACzD,GAAG;QAACR;QAAOI;KAAS;IACpB,IAAI,CAACM,SAASL,KAAK,CAAC,EAAE,EAAED,WAAW;QACjC,qBAAqB;QACrB,2CAA2C;QAC3CE,SAASO;IACX,CAAC;IACDC,IAAAA,yCAAyB,EAAC,IAAM;QAC9BX,UAAUY,IAAI,CAACT;QACf,OAAO,IAAM;YACX,MAAMU,QAAQb,UAAUc,OAAO,CAACX;YAChCH,UAAUe,MAAM,CAACF,OAAO;QAC1B;IACF,GAAG;QAACb;KAAU;IACd,OAAOE,KAAK,CAAC,EAAE;AACjB;AACA;;;CAGC,GAAG,8DAA8D;AAClE,SAASc,GAAGC,CAAC,EAAEC,CAAC,EAAE;IAChB,OAAOD,MAAMC,KAAMD,CAAAA,MAAM,KAAK,IAAIA,MAAM,IAAIC,CAAAA,KAAMD,MAAMA,KAAKC,MAAMA,EAAE,sCAAsC;;AAE7G;AACA,8DAA8D;AAC9D,MAAMX,WACN,6DAA6D;AAC7D,2DAA2D;AAC3D,OAAOY,OAAOH,EAAE,KAAK,aAAaG,OAAOH,EAAE,GAAGA,EAAE,EAChD,8CAA8C"}
1
+ {"version":3,"sources":["../lib/useContextSelector.js"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\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 = (context, selector) => {\n const contextValue = React.useContext(context);\n const {\n value: {\n current: value\n },\n version: {\n current: version\n },\n listeners\n } = contextValue;\n const selected = selector(value);\n const [state, dispatch] = React.useReducer((prevState, payload) => {\n if (!payload) {\n // early bail out when is dispatched during render\n return [value, selected];\n }\n if (payload[0] <= version) {\n if (objectIs(prevState[1], selected)) {\n return prevState; // bail out\n }\n\n return [value, selected];\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 if (objectIs(prevState[1], nextSelected)) {\n return prevState; // do not update\n }\n\n return [payload[1], nextSelected];\n } catch (e) {\n // ignored (stale props or some other reason)\n }\n // explicitly spread to enforce typing\n return [prevState[0], prevState[1]]; // schedule update\n }, [value, selected]);\n if (!objectIs(state[1], selected)) {\n // schedule re-render\n // this is safe because it's self contained\n dispatch(undefined);\n }\n useIsomorphicLayoutEffect(() => {\n listeners.push(dispatch);\n return () => {\n const index = listeners.indexOf(dispatch);\n listeners.splice(index, 1);\n };\n }, [listeners]);\n return state[1];\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 */ // eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction is(x, y) {\n return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare\n ;\n}\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst objectIs =\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore fallback to native if it exists (not in IE11)\ntypeof Object.is === 'function' ? Object.is : is;\n//# sourceMappingURL=useContextSelector.js.map"],"names":["useContextSelector","context","selector","contextValue","React","useContext","value","current","version","listeners","selected","state","dispatch","useReducer","prevState","payload","objectIs","nextSelected","e","undefined","useIsomorphicLayoutEffect","push","index","indexOf","splice","is","x","y","Object"],"mappings":";;;;+BAQaA;;aAAAA;;;gCAR6B;6DACnB;AAOhB,MAAMA,qBAAqB,CAACC,SAASC,WAAa;IACvD,MAAMC,eAAeC,OAAMC,UAAU,CAACJ;IACtC,MAAM,EACJK,OAAO,EACLC,SAASD,MAAK,EACf,CAAA,EACDE,SAAS,EACPD,SAASC,QAAO,EACjB,CAAA,EACDC,UAAS,EACV,GAAGN;IACJ,MAAMO,WAAWR,SAASI;IAC1B,MAAM,CAACK,OAAOC,SAAS,GAAGR,OAAMS,UAAU,CAAC,CAACC,WAAWC,UAAY;QACjE,IAAI,CAACA,SAAS;YACZ,kDAAkD;YAClD,OAAO;gBAACT;gBAAOI;aAAS;QAC1B,CAAC;QACD,IAAIK,OAAO,CAAC,EAAE,IAAIP,SAAS;YACzB,IAAIQ,SAASF,SAAS,CAAC,EAAE,EAAEJ,WAAW;gBACpC,OAAOI,WAAW,WAAW;YAC/B,CAAC;YAED,OAAO;gBAACR;gBAAOI;aAAS;QAC1B,CAAC;QACD,IAAI;YACF,IAAIM,SAASF,SAAS,CAAC,EAAE,EAAEC,OAAO,CAAC,EAAE,GAAG;gBACtC,OAAOD,WAAW,gBAAgB;YACpC,CAAC;YAED,MAAMG,eAAef,SAASa,OAAO,CAAC,EAAE;YACxC,IAAIC,SAASF,SAAS,CAAC,EAAE,EAAEG,eAAe;gBACxC,OAAOH,WAAW,gBAAgB;YACpC,CAAC;YAED,OAAO;gBAACC,OAAO,CAAC,EAAE;gBAAEE;aAAa;QACnC,EAAE,OAAOC,GAAG;QACV,6CAA6C;QAC/C;QACA,sCAAsC;QACtC,OAAO;YAACJ,SAAS,CAAC,EAAE;YAAEA,SAAS,CAAC,EAAE;SAAC,EAAE,kBAAkB;IACzD,GAAG;QAACR;QAAOI;KAAS;IACpB,IAAI,CAACM,SAASL,KAAK,CAAC,EAAE,EAAED,WAAW;QACjC,qBAAqB;QACrB,2CAA2C;QAC3CE,SAASO;IACX,CAAC;IACDC,IAAAA,yCAAyB,EAAC,IAAM;QAC9BX,UAAUY,IAAI,CAACT;QACf,OAAO,IAAM;YACX,MAAMU,QAAQb,UAAUc,OAAO,CAACX;YAChCH,UAAUe,MAAM,CAACF,OAAO;QAC1B;IACF,GAAG;QAACb;KAAU;IACd,OAAOE,KAAK,CAAC,EAAE;AACjB;AACA;;;CAGC,GAAG,8DAA8D;AAClE,SAASc,GAAGC,CAAC,EAAEC,CAAC,EAAE;IAChB,OAAOD,MAAMC,KAAMD,CAAAA,MAAM,KAAK,IAAIA,MAAM,IAAIC,CAAAA,KAAMD,MAAMA,KAAKC,MAAMA,EAAE,sCAAsC;;AAE7G;AACA,8DAA8D;AAC9D,MAAMX,WACN,6DAA6D;AAC7D,2DAA2D;AAC3D,OAAOY,OAAOH,EAAE,KAAK,aAAaG,OAAOH,EAAE,GAAGA,EAAE,EAChD,8CAA8C"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../lib/useHasParentContext.js"],"sourcesContent":["import * as React from \"react\";\n/**\n * @internal\n * Utility hook for contexts created by react-context-selector to determine if a parent context exists\n * WARNING: This hook will not work for native React contexts\n *\n * @param context - context created by react-context-selector\n * @returns whether the hook is wrapped by a parent context\n */\nexport function useHasParentContext(context) {\n const contextValue = React.useContext(context);\n if (contextValue.version) {\n return contextValue.version.current !== -1;\n }\n return false;\n}\n//# sourceMappingURL=useHasParentContext.js.map"],"names":["useHasParentContext","context","contextValue","React","useContext","version","current"],"mappings":";;;;+BASgBA;;aAAAA;;;6DATO;AAShB,SAASA,oBAAoBC,OAAO,EAAE;IAC3C,MAAMC,eAAeC,OAAMC,UAAU,CAACH;IACtC,IAAIC,aAAaG,OAAO,EAAE;QACxB,OAAOH,aAAaG,OAAO,CAACC,OAAO,KAAK,CAAC;IAC3C,CAAC;IACD,OAAO,KAAK;AACd,EACA,+CAA+C"}
1
+ {"version":3,"sources":["../lib/useHasParentContext.js"],"sourcesContent":["import * as React from 'react';\n/**\n * @internal\n * Utility hook for contexts created by react-context-selector to determine if a parent context exists\n * WARNING: This hook will not work for native React contexts\n *\n * @param context - context created by react-context-selector\n * @returns whether the hook is wrapped by a parent context\n */\nexport function useHasParentContext(context) {\n const contextValue = React.useContext(context);\n if (contextValue.version) {\n return contextValue.version.current !== -1;\n }\n return false;\n}\n//# sourceMappingURL=useHasParentContext.js.map"],"names":["useHasParentContext","context","contextValue","React","useContext","version","current"],"mappings":";;;;+BASgBA;;aAAAA;;;6DATO;AAShB,SAASA,oBAAoBC,OAAO,EAAE;IAC3C,MAAMC,eAAeC,OAAMC,UAAU,CAACH;IACtC,IAAIC,aAAaG,OAAO,EAAE;QACxB,OAAOH,aAAaG,OAAO,CAACC,OAAO,KAAK,CAAC;IAC3C,CAAC;IACD,OAAO,KAAK;AACd,EACA,+CAA+C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-context-selector",
3
- "version": "0.0.0-nightly-20230317-1454.1",
3
+ "version": "0.0.0-nightly-20230322-0439.1",
4
4
  "description": "React useContextSelector hook in userland",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",
@@ -27,7 +27,7 @@
27
27
  "@fluentui/scripts-tasks": "*"
28
28
  },
29
29
  "dependencies": {
30
- "@fluentui/react-utilities": "0.0.0-nightly-20230317-1454.1",
30
+ "@fluentui/react-utilities": "0.0.0-nightly-20230322-0439.1",
31
31
  "@swc/helpers": "^0.4.14"
32
32
  },
33
33
  "peerDependencies": {
@@ -41,6 +41,7 @@
41
41
  "exports": {
42
42
  ".": {
43
43
  "types": "./dist/index.d.ts",
44
+ "node": "./lib-commonjs/index.js",
44
45
  "import": "./lib/index.js",
45
46
  "require": "./lib-commonjs/index.js"
46
47
  },