@fluentui/react-context-selector 9.1.1 → 9.1.3
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 +39 -1
- package/CHANGELOG.md +20 -2
- package/lib/createContext.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/types.js.map +1 -1
- package/lib/useContextSelector.js.map +1 -1
- package/lib/useHasParentContext.js.map +1 -1
- package/lib-amd/createContext.js +54 -0
- package/lib-amd/createContext.js.map +1 -0
- package/lib-amd/index.js +9 -0
- package/lib-amd/index.js.map +1 -0
- package/lib-amd/types.js +5 -0
- package/lib-amd/types.js.map +1 -0
- package/lib-amd/useContextSelector.js +72 -0
- package/lib-amd/useContextSelector.js.map +1 -0
- package/lib-amd/useHasParentContext.js +22 -0
- package/lib-amd/useHasParentContext.js.map +1 -0
- package/lib-commonjs/createContext.js.map +1 -1
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/useContextSelector.js.map +1 -1
- package/lib-commonjs/useHasParentContext.js.map +1 -1
- package/package.json +4 -5
package/CHANGELOG.json
CHANGED
@@ -2,7 +2,45 @@
|
|
2
2
|
"name": "@fluentui/react-context-selector",
|
3
3
|
"entries": [
|
4
4
|
{
|
5
|
-
"date": "
|
5
|
+
"date": "Tue, 20 Dec 2022 14:55:58 GMT",
|
6
|
+
"tag": "@fluentui/react-context-selector_v9.1.3",
|
7
|
+
"version": "9.1.3",
|
8
|
+
"comments": {
|
9
|
+
"patch": [
|
10
|
+
{
|
11
|
+
"author": "beachball",
|
12
|
+
"package": "@fluentui/react-context-selector",
|
13
|
+
"comment": "Bump @fluentui/react-utilities to v9.3.0",
|
14
|
+
"commit": "e7530bc179fd0e303448083c76a4af41a0e15322"
|
15
|
+
}
|
16
|
+
]
|
17
|
+
}
|
18
|
+
},
|
19
|
+
{
|
20
|
+
"date": "Thu, 17 Nov 2022 23:05:38 GMT",
|
21
|
+
"tag": "@fluentui/react-context-selector_v9.1.2",
|
22
|
+
"version": "9.1.2",
|
23
|
+
"comments": {
|
24
|
+
"none": [
|
25
|
+
{
|
26
|
+
"author": "martinhochel@microsoft.com",
|
27
|
+
"package": "@fluentui/react-context-selector",
|
28
|
+
"commit": "ea768501802d65d63ddc63fff3816fb6b5008ae4",
|
29
|
+
"comment": "chore: update package scaffold"
|
30
|
+
}
|
31
|
+
],
|
32
|
+
"patch": [
|
33
|
+
{
|
34
|
+
"author": "beachball",
|
35
|
+
"package": "@fluentui/react-context-selector",
|
36
|
+
"comment": "Bump @fluentui/react-utilities to v9.2.2",
|
37
|
+
"commit": "94e156be5d3b5790d82dccf08c32672733fb9335"
|
38
|
+
}
|
39
|
+
]
|
40
|
+
}
|
41
|
+
},
|
42
|
+
{
|
43
|
+
"date": "Fri, 11 Nov 2022 14:58:01 GMT",
|
6
44
|
"tag": "@fluentui/react-context-selector_v9.1.1",
|
7
45
|
"version": "9.1.1",
|
8
46
|
"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
|
3
|
+
This log was last generated on Tue, 20 Dec 2022 14:55:58 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
+
## [9.1.3](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.1.3)
|
8
|
+
|
9
|
+
Tue, 20 Dec 2022 14:55:58 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.2..@fluentui/react-context-selector_v9.1.3)
|
11
|
+
|
12
|
+
### Patches
|
13
|
+
|
14
|
+
- Bump @fluentui/react-utilities to v9.3.0 ([PR #26047](https://github.com/microsoft/fluentui/pull/26047) by beachball)
|
15
|
+
|
16
|
+
## [9.1.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.1.2)
|
17
|
+
|
18
|
+
Thu, 17 Nov 2022 23:05:38 GMT
|
19
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.1..@fluentui/react-context-selector_v9.1.2)
|
20
|
+
|
21
|
+
### Patches
|
22
|
+
|
23
|
+
- Bump @fluentui/react-utilities to v9.2.2 ([PR #25683](https://github.com/microsoft/fluentui/pull/25683) by beachball)
|
24
|
+
|
7
25
|
## [9.1.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.1.1)
|
8
26
|
|
9
|
-
Fri, 11 Nov 2022 14:
|
27
|
+
Fri, 11 Nov 2022 14:58:01 GMT
|
10
28
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.0..@fluentui/react-context-selector_v9.1.1)
|
11
29
|
|
12
30
|
### Patches
|
package/lib/createContext.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["createContext.ts"],"names":[],"mappings":"AAAA,SAAS,yBAAT,QAA0C,2BAA1C;AACA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,uBAAuB,IAAI,cAApC,EAAoD,wBAAwB,IAAI,eAAhF,QAAuG,WAAvG;;AAIA,MAAM,cAAc,GAAW,QAAR,IAAyD;EAC9E,MAAM,QAAQ,GAAyC,KAAK,IAAG;IAC7D;IACA,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAN,CAAa,KAAK,CAAC,KAAnB,CAAjB,CAF6D,CAG7D;;IACA,MAAM,UAAU,GAAG,KAAK,CAAC,MAAN,CAAa,CAAb,CAAnB,CAJ6D,CAM7D;;IACA,MAAM,YAAY,GAAG,KAAK,CAAC,MAAN,EAArB;;IAEA,IAAI,CAAC,YAAY,CAAC,OAAlB,EAA2B;MACzB,YAAY,CAAC,OAAb,GAAuB;QACrB,KAAK,EAAE,QADc;QAErB,OAAO,EAAE,UAFY;QAGrB,SAAS,EAAE;MAHU,CAAvB;IAKD;;IAED,yBAAyB,CAAC,MAAK;MAC7B,QAAQ,CAAC,OAAT,GAAmB,KAAK,CAAC,KAAzB;MACA,UAAU,CAAC,OAAX,IAAsB,CAAtB;MAEA,eAAe,CAAC,cAAD,EAAiB,MAAK;QAClC,YAAY,CAAC,OAAb,CAA6C,SAA7C,CAAuD,OAAvD,CAA+D,QAAQ,IAAG;UACzE,QAAQ,CAAC,CAAC,UAAU,CAAC,OAAZ,EAAqB,KAAK,CAAC,KAA3B,CAAD,CAAR;QACD,CAFA;MAGF,CAJc,CAAf;IAKD,CATwB,EAStB,CAAC,KAAK,CAAC,KAAP,CATsB,CAAzB;IAWA,oBAAO,KAAK,CAAC,aAAN,CAAoB,QAApB,EAA8B;MAAE,KAAK,EAAE,YAAY,CAAC;IAAtB,CAA9B,EAA+D,KAAK,CAAC,QAArE,CAAP;EACD,CA7BD;EA+BA;;;EACA,IAAI,OAAO,CAAC,GAAR,CAAY,QAAZ,KAAyB,YAA7B,EAA2C;IACzC,QAAQ,CAAC,WAAT,GAAuB,0BAAvB;EACD;;EAED,OAAQ,QAAR;AACD,CAtCD;AAwCA;;AAEG;;;AACH,OAAO,MAAM,aAAa,GAAW,YAAR,IAA+C;EAC1E;EACA,MAAM,OAAO,gBAAG,KAAK,CAAC,aAAN,CAAyC;IACvD,KAAK,EAAE;MAAE,OAAO,EAAE;IAAX,CADgD;IAEvD,OAAO,EAAE;MAAE,OAAO,EAAE,CAAC;IAAZ,CAF8C;IAGvD,SAAS,EAAE;EAH4C,CAAzC,CAAhB;EAMA,OAAO,CAAC,QAAR,GAAmB,cAAc,CAAQ,OAAO,CAAC,QAAhB,CAAjC,CAR0E,CAU1E;;EACA,OAAS,OAAsC,CAAC,QAAhD;EAEA,OAAQ,OAAR;AACD,CAdM","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"],"sourceRoot":"../src/"}
|
1
|
+
{"version":3,"sources":["packages/react-components/react-context-selector/src/createContext.ts"],"names":[],"mappings":"AAAA,SAAS,yBAAT,QAA0C,2BAA1C;AACA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,uBAAuB,IAAI,cAApC,EAAoD,wBAAwB,IAAI,eAAhF,QAAuG,WAAvG;;AAIA,MAAM,cAAc,GAAW,QAAR,IAAyD;EAC9E,MAAM,QAAQ,GAAyC,KAAK,IAAG;IAC7D;IACA,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAN,CAAa,KAAK,CAAC,K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S,EAAE;EAH4C,CAAzC,CAAhB;EAMA,OAAO,CAAC,QAAR,GAAmB,cAAc,CAAQ,OAAO,CAAC,QAAhB,CAAjC,CAR0E,CAU1E;;EACA,OAAS,OAAsC,CAAC,QAAhD;EAEA,OAAQ,OAAR;AACD,CAdM","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"],"sourceRoot":"../src/"}
|
package/lib/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC","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"]}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["packages/react-components/react-context-selector/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC","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"]}
|
package/lib/types.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"../src/","sources":["types.ts"],"names":[],"mappings":"","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"]}
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"../src/","sources":["packages/react-components/react-context-selector/src/types.ts"],"names":[],"mappings":"","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"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useContextSelector.ts"],"names":[],"mappings":"AAAA,SAAS,yBAAT,QAA0C,2BAA1C;AACA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAaA;;;;;AAKG;;AACH,OAAO,MAAM,kBAAkB,GAAG,CAChC,OADgC,EAEhC,QAFgC,KAGf;EACjB,MAAM,YAAY,GAAG,KAAK,CAAC,UAAN,CAAkB,OAAlB,CAArB;EAEA,MAAM;IACJ,KAAK,EAAE;MAAE,OAAO,EAAE;IAAX,CADH;IAEJ,OAAO,EAAE;MAAE,OAAO,EAAE;IAAX,CA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C,MAAK;IAC7B,SAAS,CAAC,IAAV,CAAe,QAAf;IAEA,OAAO,MAAK;MACV,MAAM,KAAK,GAAG,SAAS,CAAC,OAAV,CAAkB,QAAlB,CAAd;MACA,SAAS,CAAC,MAAV,CAAiB,KAAjB,EAAwB,CAAxB;IACD,CAHD;EAID,CAPwB,EAOtB,CAAC,SAAD,CAPsB,CAAzB;EASA,OAAO,KAAK,CAAC,CAAD,CAAZ;AACD,CAvEM;AAyEP;;;AAGG;AACH;;AACA,SAAS,EAAT,CAAY,CAAZ,EAAoB,CAApB,EAA0B;EACxB,OACG,CAAC,KAAK,CAAN,KAAY,CAAC,KAAK,CAAN,IAAW,IAAI,CAAJ,KAAU,IAAI,CAArC,CAAD,IAA8C,CAAC,KAAK,CAAN,IAAW,CAAC,KAAK,CADjE,CACoE;EADpE;AAGD,C,CAED;;;AACA,MAAM,QAAQ,GACZ;AACA;AACA,OAAO,MAAM,CAAC,EAAd,KAAqB,UAArB,GAAkC,MAAM,CAAC,EAAzC,GAA8C,EAHhD","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"],"sourceRoot":"../src/"}
|
1
|
+
{"version":3,"sources":["packages/react-components/react-context-selector/src/useContextSelector.ts"],"names":[],"mappings":"AAAA,SAAS,yBAAT,QAA0C,2BAA1C;AACA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AA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CAAD,CAAxB,CAAP,CA/BmC,CA+BW;EAC/C,CAtCuB,EAuCxB,CAAC,KAAD,EAAQ,QAAR,CAvCwB,CAA1B;;EA0CA,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAD,CAAN,EAAW,QAAX,CAAb,EAAmC;IACjC;IACA;IACA,QAAQ,CAAC,SAAD,CAAR;EACD;;EAED,yBAAyB,CAAC,MAAK;IAC7B,SAAS,CAAC,IAAV,CAAe,QAAf;IAEA,OAAO,MAAK;MACV,MAAM,KAAK,GAAG,SAAS,CAAC,OAAV,CAAkB,QAAlB,CAAd;MACA,SAAS,CAAC,MAAV,CAAiB,KAAjB,EAAwB,CAAxB;IACD,CAHD;EAID,CAPwB,EAOtB,CAAC,SAAD,CAPsB,CAAzB;EASA,OAAO,KAAK,CAAC,CAAD,CAAZ;AACD,CAvEM;AAyEP;;;AAGG;AACH;;AACA,SAAS,EAAT,CAAY,CAAZ,EAAoB,CAApB,EAA0B;EACxB,OACG,CAAC,KAAK,CAAN,KAAY,CAAC,KAAK,CAAN,IAAW,IAAI,CAAJ,KAAU,IAAI,CAArC,CAAD,IAA8C,CAAC,KAAK,CAAN,IAAW,CAAC,KAAK,CADjE,CACoE;EADpE;AAGD,C,CAED;;;AACA,MAAM,QAAQ,GACZ;AACA;AACA,OAAO,MAAM,CAAC,EAAd,KAAqB,UAArB,GAAkC,MAAM,CAAC,EAAzC,GAA8C,EAHhD","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"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useHasParentContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAGA;;;;;;;AAOG;;AACH,OAAM,SAAU,mBAAV,CAAqC,OAArC,EAA4D;EAChE,MAAM,YAAY,GAAG,KAAK,CAAC,UAAN,CAAkB,OAAlB,CAArB;;EAEA,IAAI,YAAY,CAAC,OAAjB,EAA0B;IACxB,OAAO,YAAY,CAAC,OAAb,CAAqB,OAArB,KAAiC,CAAC,CAAzC;EACD;;EAED,OAAO,KAAP;AACD","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"],"sourceRoot":"../src/"}
|
1
|
+
{"version":3,"sources":["packages/react-components/react-context-selector/src/useHasParentContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAGA;;;;;;;AAOG;;AACH,OAAM,SAAU,mBAAV,CAAqC,OAArC,EAA4D;EAChE,MAAM,YAAY,GAAG,KAAK,CAAC,UAAN,CAAkB,OAAlB,CAArB;;EAEA,IAAI,YAAY,CAAC,OAAjB,EAA0B;IACxB,OAAO,YAAY,CAAC,OAAb,CAAqB,OAArB,KAAiC,CAAC,CAAzC;EACD;;EAED,OAAO,KAAP;AACD","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"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
define(["require", "exports", "@fluentui/react-utilities", "react", "scheduler"], function (require, exports, react_utilities_1, React, scheduler_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.createContext = void 0;
|
5
|
+
var createProvider = function (Original) {
|
6
|
+
var Provider = function (props) {
|
7
|
+
// Holds an actual "props.value"
|
8
|
+
var valueRef = React.useRef(props.value);
|
9
|
+
// Used to sync context updates and avoid stale values, can be considered as render/effect counter of Provider.
|
10
|
+
var versionRef = React.useRef(0);
|
11
|
+
// A stable object, is used to avoid context updates via mutation of its values.
|
12
|
+
var contextValue = React.useRef();
|
13
|
+
if (!contextValue.current) {
|
14
|
+
contextValue.current = {
|
15
|
+
value: valueRef,
|
16
|
+
version: versionRef,
|
17
|
+
listeners: [],
|
18
|
+
};
|
19
|
+
}
|
20
|
+
react_utilities_1.useIsomorphicLayoutEffect(function () {
|
21
|
+
valueRef.current = props.value;
|
22
|
+
versionRef.current += 1;
|
23
|
+
scheduler_1.unstable_runWithPriority(scheduler_1.unstable_NormalPriority, function () {
|
24
|
+
contextValue.current.listeners.forEach(function (listener) {
|
25
|
+
listener([versionRef.current, props.value]);
|
26
|
+
});
|
27
|
+
});
|
28
|
+
}, [props.value]);
|
29
|
+
return React.createElement(Original, { value: contextValue.current }, props.children);
|
30
|
+
};
|
31
|
+
/* istanbul ignore else */
|
32
|
+
if (process.env.NODE_ENV !== 'production') {
|
33
|
+
Provider.displayName = 'ContextSelector.Provider';
|
34
|
+
}
|
35
|
+
return Provider;
|
36
|
+
};
|
37
|
+
/**
|
38
|
+
* @internal
|
39
|
+
*/
|
40
|
+
var createContext = function (defaultValue) {
|
41
|
+
// eslint-disable-next-line @fluentui/no-context-default-value
|
42
|
+
var context = React.createContext({
|
43
|
+
value: { current: defaultValue },
|
44
|
+
version: { current: -1 },
|
45
|
+
listeners: [],
|
46
|
+
});
|
47
|
+
context.Provider = createProvider(context.Provider);
|
48
|
+
// We don't support Consumer API
|
49
|
+
delete context.Consumer;
|
50
|
+
return context;
|
51
|
+
};
|
52
|
+
exports.createContext = createContext;
|
53
|
+
});
|
54
|
+
//# sourceMappingURL=createContext.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"createContext.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/react-context-selector/src/createContext.ts"],"names":[],"mappings":";;;;IAMA,IAAM,cAAc,GAAG,UAAQ,QAA6C;QAC1E,IAAM,QAAQ,GAAyC,UAAA,KAAK;YAC1D,gCAAgC;YAChC,IAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC3C,+GAA+G;YAC/G,IAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAEnC,gFAAgF;YAChF,IAAM,YAAY,GAAG,KAAK,CAAC,MAAM,EAAuB,CAAC;YAEzD,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE;gBACzB,YAAY,CAAC,OAAO,GAAG;oBACrB,KAAK,EAAE,QAAQ;oBACf,OAAO,EAAE,UAAU;oBACnB,SAAS,EAAE,EAAE;iBACd,CAAC;aACH;YAED,2CAAyB,CAAC;gBACxB,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC;gBAC/B,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC;gBAExB,oCAAe,CAAC,mCAAc,EAAE;oBAC7B,YAAY,CAAC,OAA+B,CAAC,SAAS,CAAC,OAAO,CAAC,UAAA,QAAQ;wBACtE,QAAQ,CAAC,CAAC,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;oBAC9C,CAAC,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;YACL,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;YAElB,OAAO,KAAK,CAAC,aAAa,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,YAAY,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;QACxF,CAAC,CAAC;QAEF,0BAA0B;QAC1B,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;YACzC,QAAQ,CAAC,WAAW,GAAG,0BAA0B,CAAC;SACnD;QAED,OAAQ,QAA2D,CAAC;IACtE,CAAC,CAAC;IAEF;;OAEG;IACI,IAAM,aAAa,GAAG,UAAQ,YAAmB;QACtD,8DAA8D;QAC9D,IAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CAAsB;YACvD,KAAK,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE;YAChC,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE;YACxB,SAAS,EAAE,EAAE;SACd,CAAC,CAAC;QAEH,OAAO,CAAC,QAAQ,GAAG,cAAc,CAAQ,OAAO,CAAC,QAAQ,CAAC,CAAC;QAE3D,gCAAgC;QAChC,OAAS,OAAsC,CAAC,QAAQ,CAAC;QAEzD,OAAQ,OAAqC,CAAC;IAChD,CAAC,CAAC;IAdW,QAAA,aAAa,iBAcxB","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"]}
|
package/lib-amd/index.js
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
define(["require", "exports", "./createContext", "./useContextSelector", "./useHasParentContext"], function (require, exports, createContext_1, useContextSelector_1, useHasParentContext_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.useHasParentContext = exports.useContextSelector = exports.createContext = void 0;
|
5
|
+
Object.defineProperty(exports, "createContext", { enumerable: true, get: function () { return createContext_1.createContext; } });
|
6
|
+
Object.defineProperty(exports, "useContextSelector", { enumerable: true, get: function () { return useContextSelector_1.useContextSelector; } });
|
7
|
+
Object.defineProperty(exports, "useHasParentContext", { enumerable: true, get: function () { return useHasParentContext_1.useHasParentContext; } });
|
8
|
+
});
|
9
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/react-context-selector/src/index.ts"],"names":[],"mappings":";;;;IAAS,8GAAA,aAAa,OAAA;IACb,wHAAA,kBAAkB,OAAA;IAClB,0HAAA,mBAAmB,OAAA","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"]}
|
package/lib-amd/types.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/react-context-selector/src/types.ts"],"names":[],"mappings":"","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"]}
|
@@ -0,0 +1,72 @@
|
|
1
|
+
define(["require", "exports", "@fluentui/react-utilities", "react"], function (require, exports, react_utilities_1, React) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.useContextSelector = void 0;
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
* This hook returns context selected value by selector.
|
8
|
+
* It will only accept context created by `createContext`.
|
9
|
+
* It will trigger re-render if only the selected value is referencially changed.
|
10
|
+
*/
|
11
|
+
var useContextSelector = function (context, selector) {
|
12
|
+
var contextValue = React.useContext(context);
|
13
|
+
var value = contextValue.value.current, version = contextValue.version.current, listeners = contextValue.listeners;
|
14
|
+
var selected = selector(value);
|
15
|
+
var _a = React.useReducer(function (prevState, payload) {
|
16
|
+
if (!payload) {
|
17
|
+
// early bail out when is dispatched during render
|
18
|
+
return [value, selected];
|
19
|
+
}
|
20
|
+
if (payload[0] <= version) {
|
21
|
+
if (objectIs(prevState[1], selected)) {
|
22
|
+
return prevState; // bail out
|
23
|
+
}
|
24
|
+
return [value, selected];
|
25
|
+
}
|
26
|
+
try {
|
27
|
+
if (objectIs(prevState[0], payload[1])) {
|
28
|
+
return prevState; // do not update
|
29
|
+
}
|
30
|
+
var nextSelected = selector(payload[1]);
|
31
|
+
if (objectIs(prevState[1], nextSelected)) {
|
32
|
+
return prevState; // do not update
|
33
|
+
}
|
34
|
+
return [payload[1], nextSelected];
|
35
|
+
}
|
36
|
+
catch (e) {
|
37
|
+
// ignored (stale props or some other reason)
|
38
|
+
}
|
39
|
+
// explicitly spread to enforce typing
|
40
|
+
return [prevState[0], prevState[1]]; // schedule update
|
41
|
+
}, [value, selected]), state = _a[0], dispatch = _a[1];
|
42
|
+
if (!objectIs(state[1], selected)) {
|
43
|
+
// schedule re-render
|
44
|
+
// this is safe because it's self contained
|
45
|
+
dispatch(undefined);
|
46
|
+
}
|
47
|
+
react_utilities_1.useIsomorphicLayoutEffect(function () {
|
48
|
+
listeners.push(dispatch);
|
49
|
+
return function () {
|
50
|
+
var index = listeners.indexOf(dispatch);
|
51
|
+
listeners.splice(index, 1);
|
52
|
+
};
|
53
|
+
}, [listeners]);
|
54
|
+
return state[1];
|
55
|
+
};
|
56
|
+
exports.useContextSelector = useContextSelector;
|
57
|
+
/**
|
58
|
+
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
59
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
60
|
+
*/
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
62
|
+
function is(x, y) {
|
63
|
+
return ((x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare
|
64
|
+
);
|
65
|
+
}
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
67
|
+
var objectIs =
|
68
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
69
|
+
// @ts-ignore fallback to native if it exists (not in IE11)
|
70
|
+
typeof Object.is === 'function' ? Object.is : is;
|
71
|
+
});
|
72
|
+
//# sourceMappingURL=useContextSelector.js.map
|
@@ -0,0 +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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,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 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"]}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
define(["require", "exports", "react"], function (require, exports, React) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.useHasParentContext = void 0;
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
* Utility hook for contexts created by react-context-selector to determine if a parent context exists
|
8
|
+
* WARNING: This hook will not work for native React contexts
|
9
|
+
*
|
10
|
+
* @param context - context created by react-context-selector
|
11
|
+
* @returns whether the hook is wrapped by a parent context
|
12
|
+
*/
|
13
|
+
function useHasParentContext(context) {
|
14
|
+
var contextValue = React.useContext(context);
|
15
|
+
if (contextValue.version) {
|
16
|
+
return contextValue.version.current !== -1;
|
17
|
+
}
|
18
|
+
return false;
|
19
|
+
}
|
20
|
+
exports.useHasParentContext = useHasParentContext;
|
21
|
+
});
|
22
|
+
//# sourceMappingURL=useHasParentContext.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useHasParentContext.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/react-context-selector/src/useHasParentContext.ts"],"names":[],"mappings":";;;;IAGA;;;;;;;OAOG;IACH,SAAgB,mBAAmB,CAAQ,OAAuB;QAChE,IAAM,YAAY,GAAG,KAAK,CAAC,UAAU,CAAE,OAAmD,CAAC,CAAC;QAE5F,IAAI,YAAY,CAAC,OAAO,EAAE;YACxB,OAAO,YAAY,CAAC,OAAO,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC;SAC5C;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IARD,kDAQC","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"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["createContext.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AACA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,WAAA,gBA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GAAW,YAAR,IAA+C;EAC1E;EACA,MAAM,OAAO,GAAG,KAAK,CAAC,aAAN,CAAyC;IACvD,KAAK,EAAE;MAAE,OAAO,EAAE;IAAX,CADgD;IAEvD,OAAO,EAAE;MAAE,OAAO,EAAE,CAAC;IAAZ,CAF8C;IAGvD,SAAS,EAAE;EAH4C,CAAzC,CAAhB;EAMA,OAAO,CAAC,QAAR,GAAmB,cAAc,CAAQ,OAAO,CAAC,QAAhB,CAAjC,CAR0E,CAU1E;;EACA,OAAS,OAAsC,CAAC,QAAhD;EAEA,OAAQ,OAAR;AACD,CAdM;;AAAM,OAAA,CAAA,aAAA,GAAa,aAAb","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"],"sourceRoot":"../src/"}
|
1
|
+
{"version":3,"sources":["packages/react-components/react-context-selector/src/createContext.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AACA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,WAAA,gBAAA,OAAA,CAAA,WAAA,CAAA;;AAIA,MAAM,cAAc,GAAW,QAAR,IAAyD;EAC9E,MAAM,QAAQ,GAAyC,KAAK,IAAG;IAC7D;IACA,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAN,CAAa,KAAK,CAAC,KAAnB,CAAjB,CAF6D,CAG7D;;IACA,MAAM,UAAU,GAAG,KAAK,CAAC,MAAN,CAAa,CAAb,CAAnB,CAJ6D,CAM7D;;IACA,MAAM,YAAY,GAAG,KAAK,CAAC,MAAN,EAArB;;IAEA,IAAI,CAAC,YAAY,CAAC,OAAlB,EAA2B;MACzB,YAAY,CAAC,OAAb,GAAuB;QACrB,KAAK,EAAE,QADc;QAErB,OAAO,EAAE,UAFY;QAGrB,SAAS,EAAE;MAHU,CAAvB;IAKD;;IAED,iBAAA,CAAA,yBAAA,CAA0B,MAAK;MAC7B,QAAQ,CAAC,OAAT,GAAmB,KAAK,CAAC,KAAzB;MACA,UAAU,CAAC,OAAX,IAAsB,CAAtB;MAEA,WAAA,CAAA,wBAAA,CAAgB,WAAA,CAAA,uBAAhB,EAAgC,MAAK;QAClC,YAAY,CAAC,OAAb,CAA6C,SAA7C,CAAuD,OAAvD,CAA+D,QAAQ,IAAG;UACzE,QAAQ,CAAC,CAAC,UAAU,CAAC,OAAZ,EAAqB,KAAK,CAAC,KAA3B,CAAD,CAAR;QACD,CAFA;MAGF,CAJD;IAKD,CATD,EASG,CAAC,KAAK,CAAC,KAAP,CATH;IAWA,OAAO,KAAK,CAAC,aAAN,CAAoB,QAApB,EAA8B;MAAE,KAAK,EAAE,YAAY,CAAC;IAAtB,CAA9B,EAA+D,KAAK,CAAC,QAArE,CAAP;EACD,CA7BD;EA+BA;;;EACA,IAAI,OAAO,CAAC,GAAR,CAAY,QAAZ,KAAyB,YAA7B,EAA2C;IACzC,QAAQ,CAAC,WAAT,GAAuB,0BAAvB;EACD;;EAED,OAAQ,QAAR;AACD,CAtCD;AAwCA;;AAEG;;;AACI,MAAM,aAAa,GAAW,YAAR,IAA+C;EAC1E;EACA,MAAM,OAAO,GAAG,KAAK,CAAC,aAAN,CAAyC;IACvD,KAAK,EAAE;MAAE,OAAO,EAAE;IAAX,CADgD;IAEvD,OAAO,EAAE;MAAE,OAAO,EAAE,CAAC;IAAZ,CAF8C;IAGvD,SAAS,EAAE;EAH4C,CAAzC,CAAhB;EAMA,OAAO,CAAC,QAAR,GAAmB,cAAc,CAAQ,OAAO,CAAC,QAAhB,CAAjC,CAR0E,CAU1E;;EACA,OAAS,OAAsC,CAAC,QAAhD;EAEA,OAAQ,OAAR;AACD,CAdM;;AAAM,OAAA,CAAA,aAAA,GAAa,aAAb","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"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,eAAA,gBAAA,OAAA,CAAA,iBAAA,CAAA;;AAAS,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,eAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,eAAA,CAAA,aAAA;EAAa;AAAb,CAAA;;AACT,IAAA,oBAAA,gBAAA,OAAA,CAAA,sBAAA,CAAA;;AAAS,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,oBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,oBAAA,CAAA,kBAAA;EAAkB;AAAlB,CAAA;;AACT,IAAA,qBAAA,gBAAA,OAAA,CAAA,uBAAA,CAAA;;AAAS,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,qBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,qBAAA,CAAA,mBAAA;EAAmB;AAAnB,CAAA","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"],"sourceRoot":"../src/"}
|
1
|
+
{"version":3,"sources":["packages/react-components/react-context-selector/src/index.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,eAAA,gBAAA,OAAA,CAAA,iBAAA,CAAA;;AAAS,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,eAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,eAAA,CAAA,aAAA;EAAa;AAAb,CAAA;;AACT,IAAA,oBAAA,gBAAA,OAAA,CAAA,sBAAA,CAAA;;AAAS,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,oBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,oBAAA,CAAA,kBAAA;EAAkB;AAAlB,CAAA;;AACT,IAAA,qBAAA,gBAAA,OAAA,CAAA,uBAAA,CAAA;;AAAS,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,qBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,qBAAA,CAAA,mBAAA;EAAmB;AAAnB,CAAA","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"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useContextSelector.ts"],"names":[],"mappings":";;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AAO,CAAP,EAAU,CACV;IACD,CA5BkC,CA8BnC;;;IACA,OAAO,CAAC,SAAS,CAAC,CAAD,CAAV,EAAe,SAAS,CAAC,CAAD,CAAxB,CAAP,CA/BmC,CA+BW;EAC/C,CAtCuB,EAuCxB,CAAC,KAAD,EAAQ,QAAR,CAvCwB,CAA1B;;EA0CA,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAD,CAAN,EAAW,QAAX,CAAb,EAAmC;IACjC;IACA;IACA,QAAQ,CAAC,SAAD,CAAR;EACD;;EAED,iBAAA,CAAA,yBAAA,CAA0B,MAAK;IAC7B,SAAS,CAAC,IAAV,CAAe,QAAf;IAEA,OAAO,MAAK;MACV,MAAM,KAAK,GAAG,SAAS,CAAC,OAAV,CAAkB,QAAlB,CAAd;MACA,SAAS,CAAC,MAAV,CAAiB,KAAjB,EAAwB,CAAxB;IACD,CAHD;EAID,CAPD,EAOG,CAAC,SAAD,CAPH;EASA,OAAO,KAAK,CAAC,CAAD,CAAZ;AACD,CAvEM;;AAAM,OAAA,CAAA,kBAAA,GAAkB,kBAAlB;AAyEb;;;AAGG;AACH;;AACA,SAAS,EAAT,CAAY,CAAZ,EAAoB,CAApB,EAA0B;EACxB,OACG,CAAC,KAAK,CAAN,KAAY,CAAC,KAAK,CAAN,IAAW,IAAI,CAAJ,KAAU,IAAI,CAArC,CAAD,IAA8C,CAAC,KAAK,CAAN,IAAW,CAAC,KAAK,CADjE,CACoE;EADpE;AAGD,C,CAED;;;AACA,MAAM,QAAQ,GACZ;AACA;AACA,OAAO,MAAM,CAAC,EAAd,KAAqB,UAArB,GAAkC,MAAM,CAAC,EAAzC,GAA8C,EAHhD","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"],"sourceRoot":"../src/"}
|
1
|
+
{"version":3,"sources":["packages/react-components/react-context-selector/src/useContextSelector.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AACA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAaA;;;;;AAKG;;;AACI,MAAM,kBAAkB,GAAG,CAChC,OADgC,EAEhC,QAFgC,KAGf;EACjB,MAAM,YAAY,GAAG,KAAK,CAAC,UAAN,CAAkB,OAAlB,CAArB;EAEA,MAAM;IACJ,KAAK,EAAE;MAAE,OAAO,EAAE;IAAX,CADH;IAEJ,OAAO,EAAE;MAAE,OAAO,EAAE;IAAX,CAFL;IAGJ;EAHI,IAIF,YAJJ;EAKA,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAD,CAAzB;EAEA,MAAM,CAAC,KAAD,EAAQ,QAAR,IAAoB,KAAK,CAAC,UAAN,CACxB,CACE,SADF,EAEE,OAFF,KAKqC;IACnC,IAAI,CAAC,OAAL,EAAc;MACZ;MACA,OAAO,CAAC,KAAD,EAAQ,QAAR,CAAP;IACD;;IAED,IAAI,OAAO,CAAC,CAAD,CAAP,IAAc,OAAlB,EAA2B;MACzB,IAAI,QAAQ,CAAC,SAAS,CAAC,CAAD,CAAV,EAAe,QAAf,CAAZ,EAAsC;QACpC,OAAO,SAAP,CADoC,CAClB;MACnB;;MAED,OAAO,CAAC,KAAD,EAAQ,QAAR,CAAP;IACD;;IAED,IAAI;MACF,IAAI,QAAQ,CAAC,SAAS,CAAC,CAAD,CAAV,EAAe,OAAO,CAAC,CA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D,C,CAED;;;AACA,MAAM,QAAQ,GACZ;AACA;AACA,OAAO,MAAM,CAAC,EAAd,KAAqB,UAArB,GAAkC,MAAM,CAAC,EAAzC,GAA8C,EAHhD","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"],"sourceRoot":"../src/"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useHasParentContext.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAGA;;;;;;;AAOG;;;AACH,SAAgB,mBAAhB,CAA2C,OAA3C,EAAkE;EAChE,MAAM,YAAY,GAAG,KAAK,CAAC,UAAN,CAAkB,OAAlB,CAArB;;EAEA,IAAI,YAAY,CAAC,OAAjB,EAA0B;IACxB,OAAO,YAAY,CAAC,OAAb,CAAqB,OAArB,KAAiC,CAAC,CAAzC;EACD;;EAED,OAAO,KAAP;AACD;;AARD,OAAA,CAAA,mBAAA,GAAA,mBAAA","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"],"sourceRoot":"../src/"}
|
1
|
+
{"version":3,"sources":["packages/react-components/react-context-selector/src/useHasParentContext.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAGA;;;;;;;AAOG;;;AACH,SAAgB,mBAAhB,CAA2C,OAA3C,EAAkE;EAChE,MAAM,YAAY,GAAG,KAAK,CAAC,UAAN,CAAkB,OAAlB,CAArB;;EAEA,IAAI,YAAY,CAAC,OAAjB,EAA0B;IACxB,OAAO,YAAY,CAAC,OAAb,CAAqB,OAArB,KAAiC,CAAC,CAAzC;EACD;;EAED,OAAO,KAAP;AACD;;AARD,OAAA,CAAA,mBAAA,GAAA,mBAAA","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"],"sourceRoot":"../src/"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fluentui/react-context-selector",
|
3
|
-
"version": "9.1.
|
3
|
+
"version": "9.1.3",
|
4
4
|
"description": "React useContextSelector hook in userland",
|
5
5
|
"main": "lib-commonjs/index.js",
|
6
6
|
"module": "lib/index.js",
|
@@ -18,16 +18,15 @@
|
|
18
18
|
"just": "just-scripts",
|
19
19
|
"lint": "just-scripts lint",
|
20
20
|
"test": "jest --passWithNoTests",
|
21
|
-
"
|
22
|
-
"
|
23
|
-
"type-check": "tsc -b tsconfig.json"
|
21
|
+
"type-check": "tsc -b tsconfig.json",
|
22
|
+
"generate-api": "tsc -p ./tsconfig.lib.json --emitDeclarationOnly && just-scripts api-extractor"
|
24
23
|
},
|
25
24
|
"devDependencies": {
|
26
25
|
"@fluentui/eslint-plugin": "*",
|
27
26
|
"@fluentui/scripts": "^1.0.0"
|
28
27
|
},
|
29
28
|
"dependencies": {
|
30
|
-
"@fluentui/react-utilities": "^9.
|
29
|
+
"@fluentui/react-utilities": "^9.3.0",
|
31
30
|
"tslib": "^2.1.0"
|
32
31
|
},
|
33
32
|
"peerDependencies": {
|