@fluentui/react-context-selector 0.0.0-nightly-20230530-0415.1 → 0.0.0-nightly-20230601-0418.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 +20 -5
- package/CHANGELOG.md +14 -5
- package/lib/createContext.js +0 -2
- package/lib/createContext.js.map +1 -1
- package/lib/index.js +0 -2
- package/lib/index.js.map +1 -1
- package/lib/types.js +0 -2
- package/lib/types.js.map +1 -1
- package/lib/useContextSelector.js +0 -2
- package/lib/useContextSelector.js.map +1 -1
- package/lib/useHasParentContext.js +0 -2
- package/lib/useHasParentContext.js.map +1 -1
- package/lib-commonjs/createContext.js +1 -3
- package/lib-commonjs/createContext.js.map +1 -1
- package/lib-commonjs/index.js +0 -3
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/types.js +0 -3
- package/lib-commonjs/types.js.map +1 -1
- package/lib-commonjs/useContextSelector.js +1 -3
- package/lib-commonjs/useContextSelector.js.map +1 -1
- package/lib-commonjs/useHasParentContext.js +1 -3
- package/lib-commonjs/useHasParentContext.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.json
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"name": "@fluentui/react-context-selector",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
6
|
-
"tag": "@fluentui/react-context-selector_v0.0.0-nightly-
|
|
7
|
-
"version": "0.0.0-nightly-
|
|
5
|
+
"date": "Thu, 01 Jun 2023 04:23:31 GMT",
|
|
6
|
+
"tag": "@fluentui/react-context-selector_v0.0.0-nightly-20230601-0418.1",
|
|
7
|
+
"version": "0.0.0-nightly-20230601-0418.1",
|
|
8
8
|
"comments": {
|
|
9
9
|
"prerelease": [
|
|
10
10
|
{
|
|
@@ -16,8 +16,23 @@
|
|
|
16
16
|
{
|
|
17
17
|
"author": "beachball",
|
|
18
18
|
"package": "@fluentui/react-context-selector",
|
|
19
|
-
"comment": "Bump @fluentui/react-utilities to v0.0.0-nightly-
|
|
20
|
-
"commit": "
|
|
19
|
+
"comment": "Bump @fluentui/react-utilities to v0.0.0-nightly-20230601-0418.1",
|
|
20
|
+
"commit": "cff4b1279089b5951ed39ce6213d3bdd6d573d0b"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"date": "Wed, 31 May 2023 06:46:23 GMT",
|
|
27
|
+
"tag": "@fluentui/react-context-selector_v9.1.22",
|
|
28
|
+
"version": "9.1.22",
|
|
29
|
+
"comments": {
|
|
30
|
+
"patch": [
|
|
31
|
+
{
|
|
32
|
+
"author": "beachball",
|
|
33
|
+
"package": "@fluentui/react-context-selector",
|
|
34
|
+
"comment": "Bump @fluentui/react-utilities to v9.9.2",
|
|
35
|
+
"commit": "17ca96c6b7f684f36a5c63e40e78b4986a86c713"
|
|
21
36
|
}
|
|
22
37
|
]
|
|
23
38
|
}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
# Change Log - @fluentui/react-context-selector
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Thu, 01 Jun 2023 04:23:31 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
-
## [0.0.0-nightly-
|
|
7
|
+
## [0.0.0-nightly-20230601-0418.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v0.0.0-nightly-20230601-0418.1)
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.
|
|
9
|
+
Thu, 01 Jun 2023 04:23:31 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.22..@fluentui/react-context-selector_v0.0.0-nightly-20230601-0418.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-
|
|
15
|
+
- Bump @fluentui/react-utilities to v0.0.0-nightly-20230601-0418.1 ([commit](https://github.com/microsoft/fluentui/commit/cff4b1279089b5951ed39ce6213d3bdd6d573d0b) by beachball)
|
|
16
|
+
|
|
17
|
+
## [9.1.22](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.1.22)
|
|
18
|
+
|
|
19
|
+
Wed, 31 May 2023 06:46:23 GMT
|
|
20
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.21..@fluentui/react-context-selector_v9.1.22)
|
|
21
|
+
|
|
22
|
+
### Patches
|
|
23
|
+
|
|
24
|
+
- Bump @fluentui/react-utilities to v9.9.2 ([PR #28054](https://github.com/microsoft/fluentui/pull/28054) by beachball)
|
|
16
25
|
|
|
17
26
|
## [9.1.21](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.1.21)
|
|
18
27
|
|
package/lib/createContext.js
CHANGED
package/lib/createContext.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["createContext.ts"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { unstable_NormalPriority as NormalPriority, unstable_runWithPriority as runWithPriority } from 'scheduler';\n\nimport { Context, ContextValue } from './types';\n\nconst createProvider = <Value>(Original: React.Provider<ContextValue<Value>>) => {\n const Provider: React.FC<React.ProviderProps<Value>> = 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\n // A stable object, is used to avoid context updates via mutation of its values.\n const contextValue = React.useRef<ContextValue<Value>>();\n\n if (!contextValue.current) {\n contextValue.current = {\n value: valueRef,\n version: versionRef,\n listeners: [],\n };\n }\n\n useIsomorphicLayoutEffect(() => {\n valueRef.current = props.value;\n versionRef.current += 1;\n\n runWithPriority(NormalPriority, () => {\n (contextValue.current as ContextValue<Value>).listeners.forEach(listener => {\n listener([versionRef.current, props.value]);\n });\n });\n }, [props.value]);\n\n return React.createElement(Original, { value: contextValue.current }, props.children);\n };\n\n /* istanbul ignore else */\n if (process.env.NODE_ENV !== 'production') {\n Provider.displayName = 'ContextSelector.Provider';\n }\n\n return Provider as unknown as React.Provider<ContextValue<Value>>;\n};\n\n/**\n * @internal\n */\nexport const createContext = <Value>(defaultValue: Value): Context<Value> => {\n // eslint-disable-next-line @fluentui/no-context-default-value\n const context = React.createContext<ContextValue<Value>>({\n value: { current: defaultValue },\n version: { current: -1 },\n listeners: [],\n });\n\n context.Provider = createProvider<Value>(context.Provider);\n\n // We don't support Consumer API\n delete (context as unknown as Context<Value>).Consumer;\n\n return context as unknown as Context<Value>;\n};\n"],"names":["useIsomorphicLayoutEffect","React","unstable_NormalPriority","NormalPriority","unstable_runWithPriority","runWithPriority","createProvider","Original","Provider","props","valueRef","useRef","value","versionRef","contextValue","current","version","listeners","forEach","listener","createElement","children","process","env","NODE_ENV","displayName","createContext","defaultValue","context","Consumer"],"mappings":"AAAA,SAASA,yBAAyB,QAAQ,4BAA4B;AACtE,YAAYC,WAAW,QAAQ;AAC/B,SAASC,2BAA2BC,cAAc,EAAEC,4BAA4BC,eAAe,QAAQ,YAAY;AAInH,MAAMC,iBAAiB,CAAQC,WAAkD;IAC/E,MAAMC,WAAiDC,CAAAA,QAAS;QAC9D,gCAAgC;QAChC,MAAMC,WAAWT,MAAMU,MAAM,CAACF,MAAMG,KAAK;QACzC,+GAA+G;QAC/G,MAAMC,aAAaZ,MAAMU,MAAM,CAAC;QAEhC,gFAAgF;QAChF,MAAMG,eAAeb,MAAMU,MAAM;QAEjC,IAAI,CAACG,aAAaC,OAAO,EAAE;YACzBD,aAAaC,OAAO,GAAG;gBACrBH,OAAOF;gBACPM,SAASH;gBACTI,WAAW,EAAE;YACf;QACF,CAAC;QAEDjB,0BAA0B,IAAM;YAC9BU,SAASK,OAAO,GAAGN,MAAMG,KAAK;YAC9BC,WAAWE,OAAO,IAAI;YAEtBV,gBAAgBF,gBAAgB,IAAM;gBACnCW,aAAaC,OAAO,CAAyBE,SAAS,CAACC,OAAO,CAACC,CAAAA,WAAY;oBAC1EA,SAAS;wBAACN,WAAWE,OAAO;wBAAEN,MAAMG,KAAK;qBAAC;gBAC5C;YACF;QACF,GAAG;YAACH,MAAMG,KAAK;SAAC;QAEhB,OAAOX,MAAMmB,aAAa,CAACb,UAAU;YAAEK,OAAOE,aAAaC,OAAO;QAAC,GAAGN,MAAMY,QAAQ;IACtF;IAEA,wBAAwB,GACxB,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzChB,SAASiB,WAAW,GAAG;IACzB,CAAC;IAED,OAAOjB;AACT;AAEA;;CAEC,GACD,OAAO,MAAMkB,gBAAgB,CAAQC,eAAwC;IAC3E,8DAA8D;IAC9D,MAAMC,UAAU3B,MAAMyB,aAAa,CAAsB;QACvDd,OAAO;YAAEG,SAASY;QAAa;QAC/BX,SAAS;YAAED,SAAS,CAAC;QAAE;QACvBE,WAAW,EAAE;IACf;IAEAW,QAAQpB,QAAQ,GAAGF,eAAsBsB,QAAQpB,QAAQ;IAEzD,gCAAgC;IAChC,OAAO,AAACoB,QAAsCC,QAAQ;IAEtD,OAAOD;AACT,EAAE"}
|
package/lib/index.js
CHANGED
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["index.ts"],"sourcesContent":["export { createContext } from './createContext';\nexport { useContextSelector } from './useContextSelector';\nexport { useHasParentContext } from './useHasParentContext';\n// eslint-disable-next-line @fluentui/ban-context-export\nexport type { Context, ContextSelector, ContextValue, ContextValues, ContextVersion } from './types';\n"],"names":["createContext","useContextSelector","useHasParentContext"],"mappings":"AAAA,SAASA,aAAa,QAAQ,kBAAkB;AAChD,SAASC,kBAAkB,QAAQ,uBAAuB;AAC1D,SAASC,mBAAmB,QAAQ,wBAAwB"}
|
package/lib/types.js
CHANGED
package/lib/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["types.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n */\nexport type Context<Value> = React.Context<Value> & {\n Provider: React.FC<React.ProviderProps<Value>>;\n Consumer: never;\n};\n\nexport type ContextSelector<Value, SelectedValue> = (value: Value) => SelectedValue;\n\n/**\n * @internal\n */\nexport type ContextVersion = number;\n\n/**\n * @internal\n */\nexport type ContextValue<Value> = {\n /** Holds a set of subscribers from components. */\n listeners: ((payload: readonly [ContextVersion, Value]) => void)[];\n\n /** Holds an actual value of React's context that will be propagated down for computations. */\n value: React.MutableRefObject<Value>;\n\n /** A version field is used to sync a context value and consumers. */\n version: React.MutableRefObject<ContextVersion>;\n};\n\n/**\n * @internal\n */\nexport type ContextValues<Value> = ContextValue<Value> & {\n /** List of listners to publish changes */\n listeners: ((payload: readonly [ContextVersion, Record<string, Value>]) => void)[];\n};\n"],"names":["React"],"mappings":"AAAA,YAAYA,WAAW,QAAQ"}
|
|
@@ -78,5 +78,3 @@ function is(x, y) {
|
|
|
78
78
|
const objectIs = // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
79
79
|
// @ts-ignore fallback to native if it exists (not in IE11)
|
|
80
80
|
typeof Object.is === 'function' ? Object.is : is;
|
|
81
|
-
|
|
82
|
-
//# sourceMappingURL=useContextSelector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["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"],"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"],"mappings":"AAAA,SAASA,yBAAyB,QAAQ,4BAA4B;AACtE,YAAYC,WAAW,QAAQ;AAa/B;;;;;CAKC,GACD,OAAO,MAAMC,qBAAqB,CAChCC,SACAC,WACkB;IAClB,MAAMC,eAAeJ,MAAMK,UAAU,CAACH;IAEtC,MAAM,EACJI,OAAO,EAAEC,SAASD,MAAK,EAAE,CAAA,EACzBE,SAAS,EAAED,SAASC,QAAO,EAAE,CAAA,EAC7BC,UAAS,EACV,GAAGL;IACJ,MAAMM,WAAWP,SAASG;IAE1B,MAAM,CAACK,OAAOC,SAAS,GAAGZ,MAAMa,UAAU,CACxC,CACEC,WACAC,UAGoC;QACpC,IAAI,CAACA,SAAS;YACZ,kDAAkD;YAClD,OAAO;gBAACT;gBAAOI;aAAS;QAC1B,CAAC;QAED,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;QAED,IAAI;YACF,IAAIM,SAASF,SAAS,CAAC,EAAE,EAAEC,OAAO,CAAC,EAAE,GAAG;gBACtC,OAAOD,WAAW,gBAAgB;YACpC,CAAC;YAED,MAAMG,eAAed,SAASY,OAAO,CAAC,EAAE;YAExC,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;QAEA,sCAAsC;QACtC,OAAO;YAACJ,SAAS,CAAC,EAAE;YAAEA,SAAS,CAAC,EAAE;SAAC,EAAW,kBAAkB;IAClE,GACA;QAACR;QAAOI;KAAS;IAGnB,IAAI,CAACM,SAASL,KAAK,CAAC,EAAE,EAAED,WAAW;QACjC,qBAAqB;QACrB,2CAA2C;QAC3CE,SAASO;IACX,CAAC;IAEDpB,0BAA0B,IAAM;QAC9BU,UAAUW,IAAI,CAACR;QAEf,OAAO,IAAM;YACX,MAAMS,QAAQZ,UAAUa,OAAO,CAACV;YAChCH,UAAUc,MAAM,CAACF,OAAO;QAC1B;IACF,GAAG;QAACZ;KAAU;IAEd,OAAOE,KAAK,CAAC,EAAE;AACjB,EAAE;AAEF;;;CAGC,GACD,8DAA8D;AAC9D,SAASa,GAAGC,CAAM,EAAEC,CAAM,EAAE;IAC1B,OACE,AAACD,MAAMC,KAAMD,CAAAA,MAAM,KAAK,IAAIA,MAAM,IAAIC,CAAAA,KAAQD,MAAMA,KAAKC,MAAMA,EAAG,sCAAsC;;AAE5G;AAEA,8DAA8D;AAC9D,MAAMV,WACJ,6DAA6D;AAC7D,2DAA2D;AAC3D,OAAOW,OAAOH,EAAE,KAAK,aAAaG,OAAOH,EAAE,GAAGA,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["useHasParentContext.ts"],"sourcesContent":["import * as React from 'react';\nimport { Context, ContextValue } from './types';\n\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<Value>(context: Context<Value>) {\n const contextValue = React.useContext(context as unknown as Context<ContextValue<Value>>);\n\n if (contextValue.version) {\n return contextValue.version.current !== -1;\n }\n\n return false;\n}\n"],"names":["React","useHasParentContext","context","contextValue","useContext","version","current"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAG/B;;;;;;;CAOC,GACD,OAAO,SAASC,oBAA2BC,OAAuB,EAAE;IAClE,MAAMC,eAAeH,MAAMI,UAAU,CAACF;IAEtC,IAAIC,aAAaE,OAAO,EAAE;QACxB,OAAOF,aAAaE,OAAO,CAACC,OAAO,KAAK,CAAC;IAC3C,CAAC;IAED,OAAO,KAAK;AACd,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["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([\n versionRef.current,\n props.value\n ]);\n });\n });\n }, [\n props.value\n ]);\n return React.createElement(Original, {\n value: contextValue.current\n }, props.children);\n };\n /* istanbul ignore else */ if (process.env.NODE_ENV !== 'production') {\n Provider.displayName = 'ContextSelector.Provider';\n }\n return Provider;\n};\n/**\n * @internal\n */ export const createContext = (defaultValue)=>{\n // eslint-disable-next-line @fluentui/no-context-default-value\n const context = 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"],"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":";;;;+BA2CiBA;;aAAAA;;;gCA3CyB;6DACnB;2BACgF;AACvG,MAAMC,iBAAiB,CAACC,WAAW;IAC/B,MAAMC,WAAW,CAACC,QAAQ;QACtB,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;YACvBD,aAAaC,OAAO,GAAG;gBACnBH,OAAOH;gBACPO,SAASH;gBACTI,WAAW,EAAE;YACjB;QACJ,CAAC;QACDC,IAAAA,yCAAyB,EAAC,IAAI;YAC1BT,SAASM,OAAO,GAAGP,MAAMI,KAAK;YAC9BC,WAAWE,OAAO,IAAI;YACtBI,IAAAA,mCAAe,EAACC,kCAAc,EAAE,IAAI;gBAChCN,aAAaC,OAAO,CAACE,SAAS,CAACI,OAAO,CAAC,CAACC,WAAW;oBAC/CA,SAAS;wBACLT,WAAWE,OAAO;wBAClBP,MAAMI,KAAK;qBACd;gBACL;YACJ;QACJ,GAAG;YACCJ,MAAMI,KAAK;SACd;QACD,qBAAOF,OAAMa,aAAa,CAACjB,UAAU;YACjCM,OAAOE,aAAaC,OAAO;QAC/B,GAAGP,MAAMgB,QAAQ;IACrB;IACA,wBAAwB,GAAG,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QAClEpB,SAASqB,WAAW,GAAG;IAC3B,CAAC;IACD,OAAOrB;AACX;AAGW,MAAMH,gBAAgB,CAACyB,eAAe;IAC7C,8DAA8D;IAC9D,MAAMC,wBAAUpB,OAAMN,aAAa,CAAC;QAChCQ,OAAO;YACHG,SAASc;QACb;QACAb,SAAS;YACLD,SAAS,CAAC;QACd;QACAE,WAAW,EAAE;IACjB;IACAa,QAAQvB,QAAQ,GAAGF,eAAeyB,QAAQvB,QAAQ;IAClD,gCAAgC;IAChC,OAAOuB,QAAQC,QAAQ;IACvB,OAAOD;AACX"}
|
package/lib-commonjs/index.js
CHANGED
|
@@ -16,6 +16,3 @@ _export(exports, {
|
|
|
16
16
|
const _createContext = require("./createContext");
|
|
17
17
|
const _useContextSelector = require("./useContextSelector");
|
|
18
18
|
const _useHasParentContext = require("./useHasParentContext");
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
|
20
|
-
|
|
21
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["index.js"],"sourcesContent":["export { createContext } from './createContext';\nexport { useContextSelector } from './useContextSelector';\nexport { useHasParentContext } from './useHasParentContext';\n"],"names":["createContext","useContextSelector","useHasParentContext"],"mappings":";;;;;;;;;;;IAASA,aAAa,MAAbA,4BAAa;IACbC,kBAAkB,MAAlBA,sCAAkB;IAClBC,mBAAmB,MAAnBA,wCAAmB;;+BAFE;oCACK;qCACC"}
|
package/lib-commonjs/types.js
CHANGED
|
@@ -4,6 +4,3 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
|
|
6
6
|
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
|
7
|
-
//# sourceMappingURL=types.js.map
|
|
8
|
-
|
|
9
|
-
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["types.js"],"sourcesContent":["import * as React from 'react';\n"],"names":[],"mappings":";;;;;6DAAuB"}
|
|
@@ -80,6 +80,4 @@ function is(x, y) {
|
|
|
80
80
|
}
|
|
81
81
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
82
82
|
const objectIs = // @ts-ignore fallback to native if it exists (not in IE11)
|
|
83
|
-
typeof Object.is === 'function' ? Object.is : is;
|
|
84
|
-
|
|
85
|
-
//# sourceMappingURL=useContextSelector.js.map
|
|
83
|
+
typeof Object.is === 'function' ? Object.is : is;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["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 */ export const useContextSelector = (context, selector)=>{\n const contextValue = React.useContext(context);\n const { value: { current: value } , version: { current: version } , listeners } = 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 [\n value,\n selected\n ];\n }\n if (payload[0] <= version) {\n if (objectIs(prevState[1], selected)) {\n return prevState; // bail out\n }\n return [\n value,\n selected\n ];\n }\n try {\n if (objectIs(prevState[0], payload[1])) {\n return prevState; // do not update\n }\n const nextSelected = selector(payload[1]);\n if (objectIs(prevState[1], nextSelected)) {\n return prevState; // do not update\n }\n return [\n payload[1],\n nextSelected\n ];\n } catch (e) {\n // ignored (stale props or some other reason)\n }\n // explicitly spread to enforce typing\n return [\n prevState[0],\n prevState[1]\n ]; // schedule update\n }, [\n value,\n selected\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 useIsomorphicLayoutEffect(()=>{\n listeners.push(dispatch);\n return ()=>{\n const index = listeners.indexOf(dispatch);\n listeners.splice(index, 1);\n };\n }, [\n listeners\n ]);\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 = // 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"],"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":";;;;+BAOiBA;;aAAAA;;;gCAPyB;6DACnB;AAMZ,MAAMA,qBAAqB,CAACC,SAASC,WAAW;IACvD,MAAMC,eAAeC,OAAMC,UAAU,CAACJ;IACtC,MAAM,EAAEK,OAAO,EAAEC,SAASD,MAAK,EAAG,CAAA,EAAGE,SAAS,EAAED,SAASC,QAAO,EAAG,CAAA,EAAGC,UAAS,EAAG,GAAGN;IACrF,MAAMO,WAAWR,SAASI;IAC1B,MAAM,CAACK,OAAOC,SAAS,GAAGR,OAAMS,UAAU,CAAC,CAACC,WAAWC,UAAU;QAC7D,IAAI,CAACA,SAAS;YACV,kDAAkD;YAClD,OAAO;gBACHT;gBACAI;aACH;QACL,CAAC;QACD,IAAIK,OAAO,CAAC,EAAE,IAAIP,SAAS;YACvB,IAAIQ,SAASF,SAAS,CAAC,EAAE,EAAEJ,WAAW;gBAClC,OAAOI,WAAW,WAAW;YACjC,CAAC;YACD,OAAO;gBACHR;gBACAI;aACH;QACL,CAAC;QACD,IAAI;YACA,IAAIM,SAASF,SAAS,CAAC,EAAE,EAAEC,OAAO,CAAC,EAAE,GAAG;gBACpC,OAAOD,WAAW,gBAAgB;YACtC,CAAC;YACD,MAAMG,eAAef,SAASa,OAAO,CAAC,EAAE;YACxC,IAAIC,SAASF,SAAS,CAAC,EAAE,EAAEG,eAAe;gBACtC,OAAOH,WAAW,gBAAgB;YACtC,CAAC;YACD,OAAO;gBACHC,OAAO,CAAC,EAAE;gBACVE;aACH;QACL,EAAE,OAAOC,GAAG;QACZ,6CAA6C;QAC7C;QACA,sCAAsC;QACtC,OAAO;YACHJ,SAAS,CAAC,EAAE;YACZA,SAAS,CAAC,EAAE;SACf,EAAE,kBAAkB;IACzB,GAAG;QACCR;QACAI;KACH;IACD,IAAI,CAACM,SAASL,KAAK,CAAC,EAAE,EAAED,WAAW;QAC/B,qBAAqB;QACrB,2CAA2C;QAC3CE,SAASO;IACb,CAAC;IACDC,IAAAA,yCAAyB,EAAC,IAAI;QAC1BX,UAAUY,IAAI,CAACT;QACf,OAAO,IAAI;YACP,MAAMU,QAAQb,UAAUc,OAAO,CAACX;YAChCH,UAAUe,MAAM,CAACF,OAAO;QAC5B;IACJ,GAAG;QACCb;KACH;IACD,OAAOE,KAAK,CAAC,EAAE;AACnB;AACA;;;CAGC,GAAG,8DAA8D;AAClE,SAASc,GAAGC,CAAC,EAAEC,CAAC,EAAE;IACd,OAAOD,MAAMC,KAAMD,CAAAA,MAAM,KAAK,IAAIA,MAAM,IAAIC,CAAAA,KAAMD,MAAMA,KAAKC,MAAMA,EAAE,sCAAsC;;AAE/G;AACA,8DAA8D;AAC9D,MAAMX,WACN,2DAA2D;AAC3D,OAAOY,OAAOH,EAAE,KAAK,aAAaG,OAAOH,EAAE,GAAGA,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["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 */ export 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"],"names":["useHasParentContext","context","contextValue","React","useContext","version","current"],"mappings":";;;;+BAQoBA;;aAAAA;;;6DARG;AAQZ,SAASA,oBAAoBC,OAAO,EAAE;IAC7C,MAAMC,eAAeC,OAAMC,UAAU,CAACH;IACtC,IAAIC,aAAaG,OAAO,EAAE;QACtB,OAAOH,aAAaG,OAAO,CAACC,OAAO,KAAK,CAAC;IAC7C,CAAC;IACD,OAAO,KAAK;AAChB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui/react-context-selector",
|
|
3
|
-
"version": "0.0.0-nightly-
|
|
3
|
+
"version": "0.0.0-nightly-20230601-0418.1",
|
|
4
4
|
"description": "React useContextSelector hook in userland",
|
|
5
5
|
"main": "lib-commonjs/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@fluentui/scripts-tasks": "*"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@fluentui/react-utilities": "0.0.0-nightly-
|
|
31
|
+
"@fluentui/react-utilities": "0.0.0-nightly-20230601-0418.1",
|
|
32
32
|
"@swc/helpers": "^0.4.14"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|