@fluentui/react-context-selector 0.0.0-nightly-20230302-0419.1 → 0.0.0-nightly-20230306-0424.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 +5 -5
- package/CHANGELOG.md +5 -5
- package/lib/createContext.js.map +1 -1
- package/lib/useContextSelector.js.map +1 -1
- package/lib/useHasParentContext.js.map +1 -1
- package/lib-commonjs/createContext.js.map +1 -1
- package/lib-commonjs/useContextSelector.js.map +1 -1
- 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": "Mon, 06 Mar 2023 04:32:56 GMT",
|
|
6
|
+
"tag": "@fluentui/react-context-selector_v0.0.0-nightly-20230306-0424.1",
|
|
7
|
+
"version": "0.0.0-nightly-20230306-0424.1",
|
|
8
8
|
"comments": {
|
|
9
9
|
"prerelease": [
|
|
10
10
|
{
|
|
@@ -16,8 +16,8 @@
|
|
|
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-20230306-0424.1",
|
|
20
|
+
"commit": "21155fb094f73d947066cedf7577d2483dfab473"
|
|
21
21
|
}
|
|
22
22
|
]
|
|
23
23
|
}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# Change Log - @fluentui/react-context-selector
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Mon, 06 Mar 2023 04:32:56 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-20230306-0424.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v0.0.0-nightly-20230306-0424.1)
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.10..@fluentui/react-context-selector_v0.0.0-nightly-
|
|
9
|
+
Mon, 06 Mar 2023 04:32:56 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.10..@fluentui/react-context-selector_v0.0.0-nightly-20230306-0424.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-20230306-0424.1 ([commit](https://github.com/microsoft/fluentui/commit/21155fb094f73d947066cedf7577d2483dfab473) by beachball)
|
|
16
16
|
|
|
17
17
|
## [9.1.10](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.1.10)
|
|
18
18
|
|
package/lib/createContext.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"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"],"sources":["../../../../../../../packages/react-components/react-context-selector/src/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
|
|
1
|
+
{"version":3,"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"],"sources":["../../../../../../../packages/react-components/react-context-selector/src/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"],"mappings":"AAAA,SAASA,yBAAyB,QAAQ,2BAA2B;AACrE,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,SAASC,uBAAuB,IAAIC,cAAc,EAAEC,wBAAwB,IAAIC,eAAe,QAAQ,WAAW;AAIlH,MAAMC,cAAc,GAAWC,QAA6C,IAAI;EAC9E,MAAMC,QAAQ,GAAyCC,KAAK,IAAG;IAC7D;IACA,MAAMC,QAAQ,GAAGT,KAAK,CAACU,MAAM,CAACF,KAAK,CAACG,KAAK,CAAC;IAC1C;IACA,MAAMC,UAAU,GAAGZ,KAAK,CAACU,MAAM,CAAC,CAAC,CAAC;IAElC;IACA,MAAMG,YAAY,GAAGb,KAAK,CAACU,MAAM,EAAuB;IAExD,IAAI,CAACG,YAAY,CAACC,OAAO,EAAE;MACzBD,YAAY,CAACC,OAAO,GAA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phicLayoutEffect","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"],"sources":["../../../../../../../packages/react-components/react-context-selector/src/useContextSelector.ts"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { Context, ContextSelector, ContextValue, ContextVersion } from './types';\n\n/**\n * Narrowing React.Reducer type to be more easily usable below.\n * No need to export this as it's for internal reducer usage.\n */\ntype ContextReducer<Value, SelectedValue> = React.Reducer<\n readonly [Value, SelectedValue],\n undefined | readonly [ContextVersion, Value]\n>;\n\n/**\n * @internal\n * This hook returns context selected value by selector.\n * It will only accept context created by `createContext`.\n * It will trigger re-render if only the selected value is referentially changed.\n */\nexport const useContextSelector = <Value, SelectedValue>(\n context: Context<Value>,\n selector: ContextSelector<Value, SelectedValue>,\n): SelectedValue => {\n const contextValue = React.useContext(
|
|
1
|
+
{"version":3,"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"],"sources":["../../../../../../../packages/react-components/react-context-selector/src/useContextSelector.ts"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { Context, ContextSelector, ContextValue, ContextVersion } from './types';\n\n/**\n * Narrowing React.Reducer type to be more easily usable below.\n * No need to export this as it's for internal reducer usage.\n */\ntype ContextReducer<Value, SelectedValue> = React.Reducer<\n readonly [Value, SelectedValue],\n undefined | readonly [ContextVersion, Value]\n>;\n\n/**\n * @internal\n * This hook returns context selected value by selector.\n * It will only accept context created by `createContext`.\n * It will trigger re-render if only the selected value is referentially changed.\n */\nexport const useContextSelector = <Value, SelectedValue>(\n context: Context<Value>,\n selector: ContextSelector<Value, SelectedValue>,\n): SelectedValue => {\n const contextValue = React.useContext(context as unknown as Context<ContextValue<Value>>);\n\n const {\n value: { current: value },\n version: { current: version },\n listeners,\n } = contextValue;\n const selected = selector(value);\n\n const [state, dispatch] = React.useReducer<ContextReducer<Value, SelectedValue>>(\n (\n prevState: readonly [Value /* contextValue */, SelectedValue /* selector(value) */],\n payload:\n | undefined // undefined from render below\n | readonly [ContextVersion, Value], // from provider effect\n ): readonly [Value, SelectedValue] => {\n if (!payload) {\n // early bail out when is dispatched during render\n return [value, selected] as const;\n }\n\n if (payload[0] <= version) {\n if (objectIs(prevState[1], selected)) {\n return prevState; // bail out\n }\n\n return [value, selected] as const;\n }\n\n try {\n if (objectIs(prevState[0], payload[1])) {\n return prevState; // do not update\n }\n\n const nextSelected = selector(payload[1]);\n\n if (objectIs(prevState[1], nextSelected)) {\n return prevState; // do not update\n }\n\n return [payload[1], nextSelected] as const;\n } catch (e) {\n // ignored (stale props or some other reason)\n }\n\n // explicitly spread to enforce typing\n return [prevState[0], prevState[1]] as const; // schedule update\n },\n [value, selected] as const,\n );\n\n if (!objectIs(state[1], selected)) {\n // schedule re-render\n // this is safe because it's self contained\n dispatch(undefined);\n }\n\n useIsomorphicLayoutEffect(() => {\n listeners.push(dispatch);\n\n return () => {\n const index = listeners.indexOf(dispatch);\n listeners.splice(index, 1);\n };\n }, [listeners]);\n\n return state[1] as SelectedValue;\n};\n\n/**\n * inlined Object.is polyfill to avoid requiring consumers ship their own\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction is(x: any, y: any) {\n return (\n (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst objectIs: (x: any, y: any) => boolean =\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore fallback to native if it exists (not in IE11)\n typeof Object.is === 'function' ? Object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KAC3C,CAAC,OAAOC,CAAC,EAAE;MACV;IAAA;IAGF;IACA,OAAO,CAACJ,SAAS,CAAC,CAAC,CAAC,EAAEA,SAAS,CAAC,CAAC,CAAC,CAAU,CAAC,CAAC;EAChD,CAAC,EACD,CAACR,KAAK,EAAEI,QAAQ,CAAU,CAC3B;EAED,IAAI,CAACM,QAAQ,CAACL,KAAK,CAAC,CAAC,CAAC,EAAED,QAAQ,CAAC,EAAE;IACjC;IACA;IACAE,QAAQ,CAACO,SAAS,CAAC;;EAGrBpB,yBAAyB,CAAC,MAAK;IAC7BU,SAAS,CAACW,IAAI,CAACR,QAAQ,CAAC;IAExB,OAAO,MAAK;MACV,MAAMS,KAAK,GAAGZ,SAAS,CAACa,OAAO,CAACV,QAAQ,CAAC;MACzCH,SAAS,CAACc,MAAM,CAACF,KAAK,EAAE,CAAC,CAAC;IAC5B,CAAC;EACH,CAAC,EAAE,CAACZ,SAAS,CAAC,CAAC;EAEf,OAAOE,KAAK,CAAC,CAAC,CAAkB;AAClC,CAAC;AAED;;;;AAIA;AACA,SAASa,EAAEA,CAACC,CAAM,EAAEC,CAAM;EACxB,OACGD,CAAC,KAAKC,CAAC,KAAKD,CAAC,KAAK,CAAC,IAAI,CAAC,GAAGA,CAAC,KAAK,CAAC,GAAGC,CAAC,CAAC,IAAMD,CAAC,KAAKA,CAAC,IAAIC,CAAC,KAAKA,CAAE,CAAC;EAAA;AAEtE;AAEA;AACA,MAAMV,QAAQ;AACZ;AACA;AACA,OAAOW,MAAM,CAACH,EAAE,KAAK,UAAU,GAAGG,MAAM,CAACH,EAAE,GAAGA,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useHasParentContext","context","contextValue","useContext","version","current"],"sources":["../../../../../../../packages/react-components/react-context-selector/src/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(
|
|
1
|
+
{"version":3,"names":["React","useHasParentContext","context","contextValue","useContext","version","current"],"sources":["../../../../../../../packages/react-components/react-context-selector/src/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"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAG9B;;;;;;;;AAQA,OAAM,SAAUC,mBAAmBA,CAAQC,OAAuB;EAChE,MAAMC,YAAY,GAAGH,KAAK,CAACI,UAAU,CAACF,OAAkD,CAAC;EAEzF,IAAIC,YAAY,CAACE,OAAO,EAAE;IACxB,OAAOF,YAAY,CAACE,OAAO,CAACC,OAAO,KAAK,CAAC,CAAC;;EAG5C,OAAO,KAAK;AACd"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["react_utilities_1","require","React","scheduler_1","createProvider","Original","Provider","props","valueRef","useRef","value","versionRef","contextValue","current","version","listeners","useIsomorphicLayoutEffect","unstable_runWithPriority","unstable_NormalPriority","forEach","listener","createElement","children","process","env","NODE_ENV","displayName","createContext","defaultValue","context","Consumer","exports"],"sources":["../../../../../../../packages/react-components/react-context-selector/src/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
|
|
1
|
+
{"version":3,"names":["react_utilities_1","require","React","scheduler_1","createProvider","Original","Provider","props","valueRef","useRef","value","versionRef","contextValue","current","version","listeners","useIsomorphicLayoutEffect","unstable_runWithPriority","unstable_NormalPriority","forEach","listener","createElement","children","process","env","NODE_ENV","displayName","createContext","defaultValue","context","Consumer","exports"],"sources":["../../../../../../../packages/react-components/react-context-selector/src/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"],"mappings":";;;;;;AAAA,MAAAA,iBAAA,gBAAAC,OAAA;AACA,MAAAC,KAAA,gBAAAD,OAAA;AACA,MAAAE,WAAA,gBAAAF,OAAA;AAIA,MAAMG,cAAc,GAAWC,QAA6C,IAAI;EAC9E,MAAMC,QAAQ,GAAyCC,KAAK,IAAG;IAC7D;IACA,MAAMC,QAAQ,GAAGN,KAAK,CAACO,MAAM,CAACF,KAAK,CAACG,KAAK,CAAC;IAC1C;IACA,MAAMC,UAAU,GAAGT,KAAK,CAACO,MAAM,CAAC,CAAC,CAAC;IAElC;IACA,MAAMG,YAAY,GAAGV,KAAK,CAACO,MAAM,EAAuB;IAExD,IAAI,CAACG,YAAY,CAACC,OAAO,EAAE;MACzBD,YAAY,CAACC,OAAO,GAAG;QACrBH,KAAK,EAAEF,QAAQ;QACfM,OAAO,EAAEH,UAAU;QACnBI,SAAS,EAAE;OACZ;;IAGHf,iBAAA,CAAAgB,yBAAyB,CAAC,MAAK;MAC7BR,QAAQ,CAACK,OAAO,GAAGN,KAAK,CAACG,KAAK;MAC9BC,UAAU,CAACE,OAAO,IAAI,CAAC;MAEvBV,WAAA,CAAAc,wBAAe,CAACd,WAAA,CAAAe,uBAAc,EAAE,MAAK;QAClCN,YAAY,CAACC,OAA+B,CAACE,SAAS,CAACI,OAAO,CAACC,QAAQ,IAAG;UACzEA,QAAQ,CAAC,CAACT,UAAU,CAACE,OAAO,EAAEN,KAAK,CAACG,KAAK,CAAC,CAAC;QAC7C,CAAC,CAAC;MACJ,CAAC,CAAC;IACJ,CAAC,EAAE,CAACH,KAAK,CAACG,KAAK,CAAC,CAAC;IAEjB,OAAOR,KAAK,CAACmB,aAAa,CAAChB,QAAQ,EAAE;MAAEK,KAAK,EAAEE,YAAY,CAACC;IAAO,CAAE,EAAEN,KAAK,CAACe,QAAQ,CAAC;EACvF,CAAC;EAED;EACA,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;IACzCnB,QAAQ,CAACoB,WAAW,GAAG,0BAA0B;;EAGnD,OAAOpB,QAA0D;AACnE,CAAC;AAED;;;AAGO,MAAMqB,aAAa,GAAWC,YAAmB,IAAoB;EAC1E;EACA,MAAMC,OAAO,GAAG3B,KAAK,CAACyB,aAAa,CAAsB;IACvDjB,KAAK,EAAE;MAAEG,OAAO,EAAEe;IAAY,CAAE;IAChCd,OAAO,EAAE;MAAED,OAAO,EAAE,CAAC;IAAC,CAAE;IACxBE,SAAS,EAAE;GACZ,CAAC;EAEFc,OAAO,CAACvB,QAAQ,GAAGF,cAAc,CAAQyB,OAAO,CAACvB,QAAQ,CAAC;EAE1D;EACA,OAAQuB,OAAqC,CAACC,QAAQ;EAEtD,OAAOD,OAAoC;AAC7C,CAAC;AAdYE,OAAA,CAAAJ,aAAa,GAAAA,aAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["react_utilities_1","require","React","useContextSelector","context","selector","contextValue","useContext","value","current","version","listeners","selected","state","dispatch","useReducer","prevState","payload","objectIs","nextSelected","e","undefined","useIsomorphicLayoutEffect","push","index","indexOf","splice","exports","is","x","y","Object"],"sources":["../../../../../../../packages/react-components/react-context-selector/src/useContextSelector.ts"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { Context, ContextSelector, ContextValue, ContextVersion } from './types';\n\n/**\n * Narrowing React.Reducer type to be more easily usable below.\n * No need to export this as it's for internal reducer usage.\n */\ntype ContextReducer<Value, SelectedValue> = React.Reducer<\n readonly [Value, SelectedValue],\n undefined | readonly [ContextVersion, Value]\n>;\n\n/**\n * @internal\n * This hook returns context selected value by selector.\n * It will only accept context created by `createContext`.\n * It will trigger re-render if only the selected value is referentially changed.\n */\nexport const useContextSelector = <Value, SelectedValue>(\n context: Context<Value>,\n selector: ContextSelector<Value, SelectedValue>,\n): SelectedValue => {\n const contextValue = React.useContext(
|
|
1
|
+
{"version":3,"names":["react_utilities_1","require","React","useContextSelector","context","selector","contextValue","useContext","value","current","version","listeners","selected","state","dispatch","useReducer","prevState","payload","objectIs","nextSelected","e","undefined","useIsomorphicLayoutEffect","push","index","indexOf","splice","exports","is","x","y","Object"],"sources":["../../../../../../../packages/react-components/react-context-selector/src/useContextSelector.ts"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { Context, ContextSelector, ContextValue, ContextVersion } from './types';\n\n/**\n * Narrowing React.Reducer type to be more easily usable below.\n * No need to export this as it's for internal reducer usage.\n */\ntype ContextReducer<Value, SelectedValue> = React.Reducer<\n readonly [Value, SelectedValue],\n undefined | readonly [ContextVersion, Value]\n>;\n\n/**\n * @internal\n * This hook returns context selected value by selector.\n * It will only accept context created by `createContext`.\n * It will trigger re-render if only the selected value is referentially changed.\n */\nexport const useContextSelector = <Value, SelectedValue>(\n context: Context<Value>,\n selector: ContextSelector<Value, SelectedValue>,\n): SelectedValue => {\n const contextValue = React.useContext(context as unknown as Context<ContextValue<Value>>);\n\n const {\n value: { current: value },\n version: { current: version },\n listeners,\n } = contextValue;\n const selected = selector(value);\n\n const [state, dispatch] = React.useReducer<ContextReducer<Value, SelectedValue>>(\n (\n prevState: readonly [Value /* contextValue */, SelectedValue /* selector(value) */],\n payload:\n | undefined // undefined from render below\n | readonly [ContextVersion, Value], // from provider effect\n ): readonly [Value, SelectedValue] => {\n if (!payload) {\n // early bail out when is dispatched during render\n return [value, selected] as const;\n }\n\n if (payload[0] <= version) {\n if (objectIs(prevState[1], selected)) {\n return prevState; // bail out\n }\n\n return [value, selected] as const;\n }\n\n try {\n if (objectIs(prevState[0], payload[1])) {\n return prevState; // do not update\n }\n\n const nextSelected = selector(payload[1]);\n\n if (objectIs(prevState[1], nextSelected)) {\n return prevState; // do not update\n }\n\n return [payload[1], nextSelected] as const;\n } catch (e) {\n // ignored (stale props or some other reason)\n }\n\n // explicitly spread to enforce typing\n return [prevState[0], prevState[1]] as const; // schedule update\n },\n [value, selected] as const,\n );\n\n if (!objectIs(state[1], selected)) {\n // schedule re-render\n // this is safe because it's self contained\n dispatch(undefined);\n }\n\n useIsomorphicLayoutEffect(() => {\n listeners.push(dispatch);\n\n return () => {\n const index = listeners.indexOf(dispatch);\n listeners.splice(index, 1);\n };\n }, [listeners]);\n\n return state[1] as SelectedValue;\n};\n\n/**\n * inlined Object.is polyfill to avoid requiring consumers ship their own\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction is(x: any, y: any) {\n return (\n (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst objectIs: (x: any, y: any) => boolean =\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore fallback to native if it exists (not in IE11)\n typeof Object.is === 'function' ? Object.is : is;\n"],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,CAAC,EAAE;MACV;IAAA;IAGF;IACA,OAAO,CAACJ,SAAS,CAAC,CAAC,CAAC,EAAEA,SAAS,CAAC,CAAC,CAAC,CAAU,CAAC,CAAC;EAChD,CAAC,EACD,CAACR,KAAK,EAAEI,QAAQ,CAAU,CAC3B;EAED,IAAI,CAACM,QAAQ,CAACL,KAAK,CAAC,CAAC,CAAC,EAAED,QAAQ,CAAC,EAAE;IACjC;IACA;IACAE,QAAQ,CAACO,SAAS,CAAC;;EAGrBrB,iBAAA,CAAAsB,yBAAyB,CAAC,MAAK;IAC7BX,SAAS,CAACY,IAAI,CAACT,QAAQ,CAAC;IAExB,OAAO,MAAK;MACV,MAAMU,KAAK,GAAGb,SAAS,CAACc,OAAO,CAACX,QAAQ,CAAC;MACzCH,SAAS,CAACe,MAAM,CAACF,KAAK,EAAE,CAAC,CAAC;IAC5B,CAAC;EACH,CAAC,EAAE,CAACb,SAAS,CAAC,CAAC;EAEf,OAAOE,KAAK,CAAC,CAAC,CAAkB;AAClC,CAAC;AAvEYc,OAAA,CAAAxB,kBAAkB,GAAAA,kBAAA;AAyE/B;;;;AAIA;AACA,SAASyB,EAAEA,CAACC,CAAM,EAAEC,CAAM;EACxB,OACGD,CAAC,KAAKC,CAAC,KAAKD,CAAC,KAAK,CAAC,IAAI,CAAC,GAAGA,CAAC,KAAK,CAAC,GAAGC,CAAC,CAAC,IAAMD,CAAC,KAAKA,CAAC,IAAIC,CAAC,KAAKA,CAAE,CAAC;EAAA;AAEtE;AAEA;AACA,MAAMZ,QAAQ;AACZ;AACA;AACA,OAAOa,MAAM,CAACH,EAAE,KAAK,UAAU,GAAGG,MAAM,CAACH,EAAE,GAAGA,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","require","useHasParentContext","context","contextValue","useContext","version","current","exports"],"sources":["../../../../../../../packages/react-components/react-context-selector/src/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(
|
|
1
|
+
{"version":3,"names":["React","require","useHasParentContext","context","contextValue","useContext","version","current","exports"],"sources":["../../../../../../../packages/react-components/react-context-selector/src/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"],"mappings":";;;;;;AAAA,MAAAA,KAAA,gBAAAC,OAAA;AAGA;;;;;;;;AAQA,SAAgBC,mBAAmBA,CAAQC,OAAuB;EAChE,MAAMC,YAAY,GAAGJ,KAAK,CAACK,UAAU,CAACF,OAAkD,CAAC;EAEzF,IAAIC,YAAY,CAACE,OAAO,EAAE;IACxB,OAAOF,YAAY,CAACE,OAAO,CAACC,OAAO,KAAK,CAAC,CAAC;;EAG5C,OAAO,KAAK;AACd;AARAC,OAAA,CAAAN,mBAAA,GAAAA,mBAAA"}
|
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-20230306-0424.1",
|
|
4
4
|
"description": "React useContextSelector hook in userland",
|
|
5
5
|
"main": "lib-commonjs/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@fluentui/scripts-tasks": "*"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@fluentui/react-utilities": "0.0.0-nightly-
|
|
30
|
+
"@fluentui/react-utilities": "0.0.0-nightly-20230306-0424.1",
|
|
31
31
|
"tslib": "^2.1.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|