@fluentui/react-context-selector 9.1.31 → 9.1.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.json CHANGED
@@ -2,7 +2,49 @@
2
2
  "name": "@fluentui/react-context-selector",
3
3
  "entries": [
4
4
  {
5
- "date": "Tue, 29 Aug 2023 12:53:36 GMT",
5
+ "date": "Tue, 05 Sep 2023 15:35:07 GMT",
6
+ "tag": "@fluentui/react-context-selector_v9.1.33",
7
+ "version": "9.1.33",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "beachball",
12
+ "package": "@fluentui/react-context-selector",
13
+ "comment": "Bump @fluentui/react-utilities to v9.13.2",
14
+ "commit": "94019033dfe3fd39ec0cde7dfb3b57c22805aa91"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Tue, 05 Sep 2023 13:29:20 GMT",
21
+ "tag": "@fluentui/react-context-selector_v9.1.32",
22
+ "version": "9.1.32",
23
+ "comments": {
24
+ "patch": [
25
+ {
26
+ "author": "bernardo.sunderhus@gmail.com",
27
+ "package": "@fluentui/react-context-selector",
28
+ "commit": "b93c2ac22355b6cb6f33dd509c6cd9c21f4fffc8",
29
+ "comment": "bumps @swc/helpers version to 0.5.1"
30
+ },
31
+ {
32
+ "author": "bernardo.sunderhus@gmail.com",
33
+ "package": "@fluentui/react-context-selector",
34
+ "commit": "eea6d93a62249ba4fba3347fb291c67ee1a3fb24",
35
+ "comment": "bumps react peer dependencies to v16.14.0"
36
+ },
37
+ {
38
+ "author": "beachball",
39
+ "package": "@fluentui/react-context-selector",
40
+ "comment": "Bump @fluentui/react-utilities to v9.13.1",
41
+ "commit": "da959e66f36b429e40ae61810d08dc71c16e154a"
42
+ }
43
+ ]
44
+ }
45
+ },
46
+ {
47
+ "date": "Tue, 29 Aug 2023 12:57:36 GMT",
6
48
  "tag": "@fluentui/react-context-selector_v9.1.31",
7
49
  "version": "9.1.31",
8
50
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,32 @@
1
1
  # Change Log - @fluentui/react-context-selector
2
2
 
3
- This log was last generated on Tue, 29 Aug 2023 12:53:36 GMT and should not be manually modified.
3
+ This log was last generated on Tue, 05 Sep 2023 15:35:07 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.1.33](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.1.33)
8
+
9
+ Tue, 05 Sep 2023 15:35:07 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.32..@fluentui/react-context-selector_v9.1.33)
11
+
12
+ ### Patches
13
+
14
+ - Bump @fluentui/react-utilities to v9.13.2 ([PR #29055](https://github.com/microsoft/fluentui/pull/29055) by beachball)
15
+
16
+ ## [9.1.32](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.1.32)
17
+
18
+ Tue, 05 Sep 2023 13:29:20 GMT
19
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.31..@fluentui/react-context-selector_v9.1.32)
20
+
21
+ ### Patches
22
+
23
+ - bumps @swc/helpers version to 0.5.1 ([PR #28989](https://github.com/microsoft/fluentui/pull/28989) by bernardo.sunderhus@gmail.com)
24
+ - bumps react peer dependencies to v16.14.0 ([PR #28959](https://github.com/microsoft/fluentui/pull/28959) by bernardo.sunderhus@gmail.com)
25
+ - Bump @fluentui/react-utilities to v9.13.1 ([PR #29056](https://github.com/microsoft/fluentui/pull/29056) by beachball)
26
+
7
27
  ## [9.1.31](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.1.31)
8
28
 
9
- Tue, 29 Aug 2023 12:53:36 GMT
29
+ Tue, 29 Aug 2023 12:57:36 GMT
10
30
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.30..@fluentui/react-context-selector_v9.1.31)
11
31
 
12
32
  ### Patches
@@ -1 +1 @@
1
- {"version":3,"sources":["createContext.ts"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { unstable_NormalPriority as NormalPriority, unstable_runWithPriority as runWithPriority } from 'scheduler';\n\nimport { Context, ContextValue } from './types';\n\nconst createProvider = <Value>(Original: React.Provider<ContextValue<Value>>) => {\n const Provider: React.FC<React.ProviderProps<Value>> = props => {\n // Holds an actual \"props.value\"\n const valueRef = React.useRef(props.value);\n // Used to sync context updates and avoid stale values, can be considered as render/effect counter of Provider.\n const versionRef = React.useRef(0);\n\n // A stable object, is used to avoid context updates via mutation of its values.\n const contextValue = React.useRef<ContextValue<Value>>();\n\n if (!contextValue.current) {\n contextValue.current = {\n value: valueRef,\n version: versionRef,\n listeners: [],\n };\n }\n\n useIsomorphicLayoutEffect(() => {\n valueRef.current = props.value;\n versionRef.current += 1;\n\n runWithPriority(NormalPriority, () => {\n (contextValue.current as ContextValue<Value>).listeners.forEach(listener => {\n listener([versionRef.current, props.value]);\n });\n });\n }, [props.value]);\n\n return React.createElement(Original, { value: contextValue.current }, props.children);\n };\n\n /* istanbul ignore else */\n if (process.env.NODE_ENV !== 'production') {\n Provider.displayName = 'ContextSelector.Provider';\n }\n\n return Provider as unknown as React.Provider<ContextValue<Value>>;\n};\n\n/**\n * @internal\n */\nexport const createContext = <Value>(defaultValue: Value): Context<Value> => {\n // eslint-disable-next-line @fluentui/no-context-default-value\n const context = React.createContext<ContextValue<Value>>({\n value: { current: defaultValue },\n version: { current: -1 },\n listeners: [],\n });\n\n context.Provider = createProvider<Value>(context.Provider);\n\n // We don't support Consumer API\n delete (context as unknown as Context<Value>).Consumer;\n\n return context as unknown as Context<Value>;\n};\n"],"names":["useIsomorphicLayoutEffect","React","unstable_NormalPriority","NormalPriority","unstable_runWithPriority","runWithPriority","createProvider","Original","Provider","props","valueRef","useRef","value","versionRef","contextValue","current","version","listeners","forEach","listener","createElement","children","process","env","NODE_ENV","displayName","createContext","defaultValue","context","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;QACvBE,WAAW,EAAE;IACf;IAEAW,QAAQpB,QAAQ,GAAGF,eAAsBsB,QAAQpB,QAAQ;IAEzD,gCAAgC;IAChC,OAAO,AAACoB,QAAsCC,QAAQ;IAEtD,OAAOD;AACT,EAAE"}
1
+ {"version":3,"sources":["createContext.ts"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { unstable_NormalPriority as NormalPriority, unstable_runWithPriority as runWithPriority } from 'scheduler';\n\nimport { Context, ContextValue } from './types';\n\nconst createProvider = <Value>(Original: React.Provider<ContextValue<Value>>) => {\n const Provider: React.FC<React.ProviderProps<Value>> = props => {\n // Holds an actual \"props.value\"\n const valueRef = React.useRef(props.value);\n // Used to sync context updates and avoid stale values, can be considered as render/effect counter of Provider.\n const versionRef = React.useRef(0);\n\n // A stable object, is used to avoid context updates via mutation of its values.\n const contextValue = React.useRef<ContextValue<Value>>();\n\n if (!contextValue.current) {\n contextValue.current = {\n value: valueRef,\n version: versionRef,\n listeners: [],\n };\n }\n\n useIsomorphicLayoutEffect(() => {\n valueRef.current = props.value;\n versionRef.current += 1;\n\n runWithPriority(NormalPriority, () => {\n (contextValue.current as ContextValue<Value>).listeners.forEach(listener => {\n listener([versionRef.current, props.value]);\n });\n });\n }, [props.value]);\n\n return React.createElement(Original, { value: contextValue.current }, props.children);\n };\n\n /* istanbul ignore else */\n if (process.env.NODE_ENV !== 'production') {\n Provider.displayName = 'ContextSelector.Provider';\n }\n\n return Provider as unknown as React.Provider<ContextValue<Value>>;\n};\n\n/**\n * @internal\n */\nexport const createContext = <Value>(defaultValue: Value): Context<Value> => {\n // eslint-disable-next-line @fluentui/no-context-default-value\n const context = React.createContext<ContextValue<Value>>({\n value: { current: defaultValue },\n version: { current: -1 },\n listeners: [],\n });\n\n context.Provider = createProvider<Value>(context.Provider);\n\n // We don't support Consumer API\n delete (context as unknown as Context<Value>).Consumer;\n\n return context as unknown as Context<Value>;\n};\n"],"names":["useIsomorphicLayoutEffect","React","unstable_NormalPriority","NormalPriority","unstable_runWithPriority","runWithPriority","createProvider","Original","Provider","props","valueRef","useRef","value","versionRef","contextValue","current","version","listeners","forEach","listener","createElement","children","process","env","NODE_ENV","displayName","createContext","defaultValue","context","Consumer"],"mappings":"AAAA,SAASA,yBAAyB,QAAQ,4BAA4B;AACtE,YAAYC,WAAW,QAAQ;AAC/B,SAASC,2BAA2BC,cAAc,EAAEC,4BAA4BC,eAAe,QAAQ,YAAY;AAInH,MAAMC,iBAAiB,CAAQC;IAC7B,MAAMC,WAAiDC,CAAAA;QACrD,gCAAgC;QAChC,MAAMC,WAAWT,MAAMU,MAAM,CAACF,MAAMG,KAAK;QACzC,+GAA+G;QAC/G,MAAMC,aAAaZ,MAAMU,MAAM,CAAC;QAEhC,gFAAgF;QAChF,MAAMG,eAAeb,MAAMU,MAAM;QAEjC,IAAI,CAACG,aAAaC,OAAO,EAAE;YACzBD,aAAaC,OAAO,GAAG;gBACrBH,OAAOF;gBACPM,SAASH;gBACTI,WAAW,EAAE;YACf;QACF;QAEAjB,0BAA0B;YACxBU,SAASK,OAAO,GAAGN,MAAMG,KAAK;YAC9BC,WAAWE,OAAO,IAAI;YAEtBV,gBAAgBF,gBAAgB;gBAC7BW,aAAaC,OAAO,CAAyBE,SAAS,CAACC,OAAO,CAACC,CAAAA;oBAC9DA,SAAS;wBAACN,WAAWE,OAAO;wBAAEN,MAAMG,KAAK;qBAAC;gBAC5C;YACF;QACF,GAAG;YAACH,MAAMG,KAAK;SAAC;QAEhB,OAAOX,MAAMmB,aAAa,CAACb,UAAU;YAAEK,OAAOE,aAAaC,OAAO;QAAC,GAAGN,MAAMY,QAAQ;IACtF;IAEA,wBAAwB,GACxB,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzChB,SAASiB,WAAW,GAAG;IACzB;IAEA,OAAOjB;AACT;AAEA;;CAEC,GACD,OAAO,MAAMkB,gBAAgB,CAAQC;IACnC,8DAA8D;IAC9D,MAAMC,UAAU3B,MAAMyB,aAAa,CAAsB;QACvDd,OAAO;YAAEG,SAASY;QAAa;QAC/BX,SAAS;YAAED,SAAS,CAAC;QAAE;QACvBE,WAAW,EAAE;IACf;IAEAW,QAAQpB,QAAQ,GAAGF,eAAsBsB,QAAQpB,QAAQ;IAEzD,gCAAgC;IAChC,OAAO,AAACoB,QAAsCC,QAAQ;IAEtD,OAAOD;AACT,EAAE"}
@@ -7,7 +7,7 @@ import * as React from 'react';
7
7
  * It will trigger re-render if only the selected value is referentially changed.
8
8
  */ export const useContextSelector = (context, selector)=>{
9
9
  const contextValue = React.useContext(context);
10
- const { value: { current: value } , version: { current: version } , listeners } = contextValue;
10
+ const { value: { current: value }, version: { current: version }, listeners } = contextValue;
11
11
  const selected = selector(value);
12
12
  const [state, dispatch] = React.useReducer((prevState, payload)=>{
13
13
  if (!payload) {
@@ -1 +1 @@
1
- {"version":3,"sources":["useContextSelector.ts"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { Context, ContextSelector, ContextValue, ContextVersion } from './types';\n\n/**\n * Narrowing React.Reducer type to be more easily usable below.\n * No need to export this as it's for internal reducer usage.\n */\ntype ContextReducer<Value, SelectedValue> = React.Reducer<\n readonly [Value, SelectedValue],\n undefined | readonly [ContextVersion, Value]\n>;\n\n/**\n * @internal\n * This hook returns context selected value by selector.\n * It will only accept context created by `createContext`.\n * It will trigger re-render if only the selected value is referentially changed.\n */\nexport const useContextSelector = <Value, SelectedValue>(\n context: Context<Value>,\n selector: ContextSelector<Value, SelectedValue>,\n): SelectedValue => {\n const contextValue = React.useContext(context as unknown as Context<ContextValue<Value>>);\n\n const {\n value: { current: value },\n version: { current: version },\n listeners,\n } = contextValue;\n const selected = selector(value);\n\n const [state, dispatch] = React.useReducer<ContextReducer<Value, SelectedValue>>(\n (\n prevState: readonly [Value /* contextValue */, SelectedValue /* selector(value) */],\n payload:\n | undefined // undefined from render below\n | readonly [ContextVersion, Value], // from provider effect\n ): readonly [Value, SelectedValue] => {\n if (!payload) {\n // early bail out when is dispatched during render\n return [value, selected] as const;\n }\n\n if (payload[0] <= version) {\n if (objectIs(prevState[1], selected)) {\n return prevState; // bail out\n }\n\n return [value, selected] as const;\n }\n\n try {\n if (objectIs(prevState[0], payload[1])) {\n return prevState; // do not update\n }\n\n const nextSelected = selector(payload[1]);\n\n if (objectIs(prevState[1], nextSelected)) {\n return prevState; // do not update\n }\n\n return [payload[1], nextSelected] as const;\n } catch (e) {\n // ignored (stale props or some other reason)\n }\n\n // explicitly spread to enforce typing\n return [prevState[0], prevState[1]] as const; // schedule update\n },\n [value, selected] as const,\n );\n\n if (!objectIs(state[1], selected)) {\n // schedule re-render\n // this is safe because it's self contained\n dispatch(undefined);\n }\n\n useIsomorphicLayoutEffect(() => {\n listeners.push(dispatch);\n\n return () => {\n const index = listeners.indexOf(dispatch);\n listeners.splice(index, 1);\n };\n }, [listeners]);\n\n return state[1] as SelectedValue;\n};\n\n/**\n * inlined Object.is polyfill to avoid requiring consumers ship their own\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction is(x: any, y: any) {\n return (\n (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst objectIs: (x: any, y: any) => boolean =\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore fallback to native if it exists (not in IE11)\n typeof Object.is === 'function' ? Object.is : is;\n"],"names":["useIsomorphicLayoutEffect","React","useContextSelector","context","selector","contextValue","useContext","value","current","version","listeners","selected","state","dispatch","useReducer","prevState","payload","objectIs","nextSelected","e","undefined","push","index","indexOf","splice","is","x","y","Object"],"mappings":"AAAA,SAASA,yBAAyB,QAAQ,4BAA4B;AACtE,YAAYC,WAAW,QAAQ;AAa/B;;;;;C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,OAAO,IAAM;YACX,MAAMS,QAAQZ,UAAUa,OAAO,CAACV;YAChCH,UAAUc,MAAM,CAACF,OAAO;QAC1B;IACF,GAAG;QAACZ;KAAU;IAEd,OAAOE,KAAK,CAAC,EAAE;AACjB,EAAE;AAEF;;;CAGC,GACD,8DAA8D;AAC9D,SAASa,GAAGC,CAAM,EAAEC,CAAM,EAAE;IAC1B,OACE,AAACD,MAAMC,KAAMD,CAAAA,MAAM,KAAK,IAAIA,MAAM,IAAIC,CAAAA,KAAQD,MAAMA,KAAKC,MAAMA,EAAG,sCAAsC;;AAE5G;AAEA,8DAA8D;AAC9D,MAAMV,WACJ,6DAA6D;AAC7D,2DAA2D;AAC3D,OAAOW,OAAOH,EAAE,KAAK,aAAaG,OAAOH,EAAE,GAAGA,EAAE"}
1
+ {"version":3,"sources":["useContextSelector.ts"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { Context, ContextSelector, ContextValue, ContextVersion } from './types';\n\n/**\n * Narrowing React.Reducer type to be more easily usable below.\n * No need to export this as it's for internal reducer usage.\n */\ntype ContextReducer<Value, SelectedValue> = React.Reducer<\n readonly [Value, SelectedValue],\n undefined | readonly [ContextVersion, Value]\n>;\n\n/**\n * @internal\n * This hook returns context selected value by selector.\n * It will only accept context created by `createContext`.\n * It will trigger re-render if only the selected value is referentially changed.\n */\nexport const useContextSelector = <Value, SelectedValue>(\n context: Context<Value>,\n selector: ContextSelector<Value, SelectedValue>,\n): SelectedValue => {\n const contextValue = React.useContext(context as unknown as Context<ContextValue<Value>>);\n\n const {\n value: { current: value },\n version: { current: version },\n listeners,\n } = contextValue;\n const selected = selector(value);\n\n const [state, dispatch] = React.useReducer<ContextReducer<Value, SelectedValue>>(\n (\n prevState: readonly [Value /* contextValue */, SelectedValue /* selector(value) */],\n payload:\n | undefined // undefined from render below\n | readonly [ContextVersion, Value], // from provider effect\n ): readonly [Value, SelectedValue] => {\n if (!payload) {\n // early bail out when is dispatched during render\n return [value, selected] as const;\n }\n\n if (payload[0] <= version) {\n if (objectIs(prevState[1], selected)) {\n return prevState; // bail out\n }\n\n return [value, selected] as const;\n }\n\n try {\n if (objectIs(prevState[0], payload[1])) {\n return prevState; // do not update\n }\n\n const nextSelected = selector(payload[1]);\n\n if (objectIs(prevState[1], nextSelected)) {\n return prevState; // do not update\n }\n\n return [payload[1], nextSelected] as const;\n } catch (e) {\n // ignored (stale props or some other reason)\n }\n\n // explicitly spread to enforce typing\n return [prevState[0], prevState[1]] as const; // schedule update\n },\n [value, selected] as const,\n );\n\n if (!objectIs(state[1], selected)) {\n // schedule re-render\n // this is safe because it's self contained\n dispatch(undefined);\n }\n\n useIsomorphicLayoutEffect(() => {\n listeners.push(dispatch);\n\n return () => {\n const index = listeners.indexOf(dispatch);\n listeners.splice(index, 1);\n };\n }, [listeners]);\n\n return state[1] as SelectedValue;\n};\n\n/**\n * inlined Object.is polyfill to avoid requiring consumers ship their own\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction is(x: any, y: any) {\n return (\n (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst objectIs: (x: any, y: any) => boolean =\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore fallback to native if it exists (not in IE11)\n typeof Object.is === 'function' ? Object.is : is;\n"],"names":["useIsomorphicLayoutEffect","React","useContextSelector","context","selector","contextValue","useContext","value","current","version","listeners","selected","state","dispatch","useReducer","prevState","payload","objectIs","nextSelected","e","undefined","push","index","indexOf","splice","is","x","y","Object"],"mappings":"AAAA,SAASA,yBAAyB,QAAQ,4BAA4B;AACtE,YAAYC,WAAW,QAAQ;AAa/B;;;;;CAKC,GACD,OAAO,MAAMC,qBAAqB,CAChCC,SACAC;IAEA,MAAMC,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E,KAAK,CAAC,EAAE;AACjB,EAAE;AAEF;;;CAGC,GACD,8DAA8D;AAC9D,SAASa,GAAGC,CAAM,EAAEC,CAAM;IACxB,OACE,AAACD,MAAMC,KAAMD,CAAAA,MAAM,KAAK,IAAIA,MAAM,IAAIC,CAAAA,KAAQD,MAAMA,KAAKC,MAAMA,EAAG,sCAAsC;;AAE5G;AAEA,8DAA8D;AAC9D,MAAMV,WACJ,6DAA6D;AAC7D,2DAA2D;AAC3D,OAAOW,OAAOH,EAAE,KAAK,aAAaG,OAAOH,EAAE,GAAGA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["useHasParentContext.ts"],"sourcesContent":["import * as React from 'react';\nimport { Context, ContextValue } from './types';\n\n/**\n * @internal\n * Utility hook for contexts created by react-context-selector to determine if a parent context exists\n * WARNING: This hook will not work for native React contexts\n *\n * @param context - context created by react-context-selector\n * @returns whether the hook is wrapped by a parent context\n */\nexport function useHasParentContext<Value>(context: Context<Value>) {\n const contextValue = React.useContext(context as unknown as Context<ContextValue<Value>>);\n\n if (contextValue.version) {\n return contextValue.version.current !== -1;\n }\n\n return false;\n}\n"],"names":["React","useHasParentContext","context","contextValue","useContext","version","current"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAG/B;;;;;;;CAOC,GACD,OAAO,SAASC,oBAA2BC,OAAuB,EAAE;IAClE,MAAMC,eAAeH,MAAMI,UAAU,CAACF;IAEtC,IAAIC,aAAaE,OAAO,EAAE;QACxB,OAAOF,aAAaE,OAAO,CAACC,OAAO,KAAK,CAAC;IAC3C,CAAC;IAED,OAAO,KAAK;AACd,CAAC"}
1
+ {"version":3,"sources":["useHasParentContext.ts"],"sourcesContent":["import * as React from 'react';\nimport { Context, ContextValue } from './types';\n\n/**\n * @internal\n * Utility hook for contexts created by react-context-selector to determine if a parent context exists\n * WARNING: This hook will not work for native React contexts\n *\n * @param context - context created by react-context-selector\n * @returns whether the hook is wrapped by a parent context\n */\nexport function useHasParentContext<Value>(context: Context<Value>) {\n const contextValue = React.useContext(context as unknown as Context<ContextValue<Value>>);\n\n if (contextValue.version) {\n return contextValue.version.current !== -1;\n }\n\n return false;\n}\n"],"names":["React","useHasParentContext","context","contextValue","useContext","version","current"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAG/B;;;;;;;CAOC,GACD,OAAO,SAASC,oBAA2BC,OAAuB;IAChE,MAAMC,eAAeH,MAAMI,UAAU,CAACF;IAEtC,IAAIC,aAAaE,OAAO,EAAE;QACxB,OAAOF,aAAaE,OAAO,CAACC,OAAO,KAAK,CAAC;IAC3C;IAEA,OAAO;AACT"}
@@ -4,11 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "createContext", {
6
6
  enumerable: true,
7
- get: ()=>createContext
7
+ get: function() {
8
+ return createContext;
9
+ }
8
10
  });
9
- const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
10
- const _reactUtilities = require("@fluentui/react-utilities");
11
- const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
11
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
+ const _reactutilities = require("@fluentui/react-utilities");
13
+ const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
12
14
  const _scheduler = require("scheduler");
13
15
  const createProvider = (Original)=>{
14
16
  const Provider = (props)=>{
@@ -25,7 +27,7 @@ const createProvider = (Original)=>{
25
27
  listeners: []
26
28
  };
27
29
  }
28
- (0, _reactUtilities.useIsomorphicLayoutEffect)(()=>{
30
+ (0, _reactutilities.useIsomorphicLayoutEffect)(()=>{
29
31
  valueRef.current = props.value;
30
32
  versionRef.current += 1;
31
33
  (0, _scheduler.unstable_runWithPriority)(_scheduler.unstable_NormalPriority, ()=>{
@@ -1 +1 @@
1
- {"version":3,"sources":["createContext.js"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { unstable_NormalPriority as NormalPriority, unstable_runWithPriority as runWithPriority } from 'scheduler';\nconst createProvider = (Original)=>{\n const Provider = (props)=>{\n // Holds an actual \"props.value\"\n const valueRef = React.useRef(props.value);\n // Used to sync context updates and avoid stale values, can be considered as render/effect counter of Provider.\n const versionRef = React.useRef(0);\n // A stable object, is used to avoid context updates via mutation of its values.\n const contextValue = React.useRef();\n if (!contextValue.current) {\n contextValue.current = {\n value: valueRef,\n version: versionRef,\n listeners: []\n };\n }\n useIsomorphicLayoutEffect(()=>{\n valueRef.current = props.value;\n versionRef.current += 1;\n runWithPriority(NormalPriority, ()=>{\n contextValue.current.listeners.forEach((listener)=>{\n listener([\n versionRef.current,\n props.value\n ]);\n });\n });\n }, [\n props.value\n ]);\n return React.createElement(Original, {\n value: contextValue.current\n }, props.children);\n };\n /* istanbul ignore else */ if (process.env.NODE_ENV !== 'production') {\n Provider.displayName = 'ContextSelector.Provider';\n }\n return Provider;\n};\n/**\n * @internal\n */ export const createContext = (defaultValue)=>{\n // eslint-disable-next-line @fluentui/no-context-default-value\n const context = React.createContext({\n value: {\n current: defaultValue\n },\n version: {\n current: -1\n },\n listeners: []\n });\n context.Provider = createProvider(context.Provider);\n // We don't support Consumer API\n delete context.Consumer;\n return context;\n};\n"],"names":["createContext","createProvider","Original","Provider","props","valueRef","React","useRef","value","versionRef","contextValue","current","version","listeners","useIsomorphicLayoutEffect","runWithPriority","NormalPriority","forEach","listener","createElement","children","process","env","NODE_ENV","displayName","defaultValue","context","Consumer"],"mappings":";;;;+BA2CiBA;;aAAAA;;;gCA3CyB;6DACnB;2BACgF;AACvG,MAAMC,iBAAiB,CAACC,WAAW;IAC/B,MAAMC,WAAW,CAACC,QAAQ;QACtB,gCAAgC;QAChC,MAAMC,WAAWC,OAAMC,MAAM,CAACH,MAAMI,KAAK;QACzC,+GAA+G;QAC/G,MAAMC,aAAaH,OAAMC,MAAM,CAAC;QAChC,gFAAgF;QAChF,MAAMG,eAAeJ,OAAMC,MAAM;QACjC,IAAI,CAACG,aAAaC,OAAO,EAAE;YACvBD,aAAaC,OAAO,GAAG;gBACnBH,OAAOH;gBACPO,SAASH;gBACTI,WAAW,EAAE;YACjB;QACJ,CAAC;QACDC,IAAAA,yCAAyB,EAAC,IAAI;YAC1BT,SAASM,OAAO,GAAGP,MAAMI,KAAK;YAC9BC,WAAWE,OAAO,IAAI;YACtBI,IAAAA,mCAAe,EAACC,kCAAc,EAAE,IAAI;gBAChCN,aAAaC,OAAO,CAACE,SAAS,CAACI,OAAO,CAAC,CAACC,WAAW;oBAC/CA,SAAS;wBACLT,WAAWE,OAAO;wBAClBP,MAAMI,KAAK;qBACd;gBACL;YACJ;QACJ,GAAG;YACCJ,MAAMI,KAAK;SACd;QACD,qBAAOF,OAAMa,aAAa,CAACjB,UAAU;YACjCM,OAAOE,aAAaC,OAAO;QAC/B,GAAGP,MAAMgB,QAAQ;IACrB;IACA,wBAAwB,GAAG,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QAClEpB,SAASqB,WAAW,GAAG;IAC3B,CAAC;IACD,OAAOrB;AACX;AAGW,MAAMH,gBAAgB,CAACyB,eAAe;IAC7C,8DAA8D;IAC9D,MAAMC,wBAAUpB,OAAMN,aAAa,CAAC;QAChCQ,OAAO;YACHG,SAASc;QACb;QACAb,SAAS;YACLD,SAAS,CAAC;QACd;QACAE,WAAW,EAAE;IACjB;IACAa,QAAQvB,QAAQ,GAAGF,eAAeyB,QAAQvB,QAAQ;IAClD,gCAAgC;IAChC,OAAOuB,QAAQC,QAAQ;IACvB,OAAOD;AACX"}
1
+ {"version":3,"sources":["createContext.js"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { unstable_NormalPriority as NormalPriority, unstable_runWithPriority as runWithPriority } from 'scheduler';\nconst createProvider = (Original)=>{\n const Provider = (props)=>{\n // Holds an actual \"props.value\"\n const valueRef = React.useRef(props.value);\n // Used to sync context updates and avoid stale values, can be considered as render/effect counter of Provider.\n const versionRef = React.useRef(0);\n // A stable object, is used to avoid context updates via mutation of its values.\n const contextValue = React.useRef();\n if (!contextValue.current) {\n contextValue.current = {\n value: valueRef,\n version: versionRef,\n listeners: []\n };\n }\n useIsomorphicLayoutEffect(()=>{\n valueRef.current = props.value;\n versionRef.current += 1;\n runWithPriority(NormalPriority, ()=>{\n contextValue.current.listeners.forEach((listener)=>{\n listener([\n versionRef.current,\n props.value\n ]);\n });\n });\n }, [\n props.value\n ]);\n return React.createElement(Original, {\n value: contextValue.current\n }, props.children);\n };\n /* istanbul ignore else */ if (process.env.NODE_ENV !== 'production') {\n Provider.displayName = 'ContextSelector.Provider';\n }\n return Provider;\n};\n/**\n * @internal\n */ export const createContext = (defaultValue)=>{\n // eslint-disable-next-line @fluentui/no-context-default-value\n const context = React.createContext({\n value: {\n current: defaultValue\n },\n version: {\n current: -1\n },\n listeners: []\n });\n context.Provider = createProvider(context.Provider);\n // We don't support Consumer API\n delete context.Consumer;\n return context;\n};\n"],"names":["createContext","createProvider","Original","Provider","props","valueRef","React","useRef","value","versionRef","contextValue","current","version","listeners","useIsomorphicLayoutEffect","runWithPriority","NormalPriority","forEach","listener","createElement","children","process","env","NODE_ENV","displayName","defaultValue","context","Consumer"],"mappings":";;;;+BA2CiBA;;;eAAAA;;;;gCA3CyB;iEACnB;2BACgF;AACvG,MAAMC,iBAAiB,CAACC;IACpB,MAAMC,WAAW,CAACC;QACd,gCAAgC;QAChC,MAAMC,WAAWC,OAAMC,MAAM,CAACH,MAAMI,KAAK;QACzC,+GAA+G;QAC/G,MAAMC,aAAaH,OAAMC,MAAM,CAAC;QAChC,gFAAgF;QAChF,MAAMG,eAAeJ,OAAMC,MAAM;QACjC,IAAI,CAACG,aAAaC,OAAO,EAAE;YACvBD,aAAaC,OAAO,GAAG;gBACnBH,OAAOH;gBACPO,SAASH;gBACTI,WAAW,EAAE;YACjB;QACJ;QACAC,IAAAA,yCAAyB,EAAC;YACtBT,SAASM,OAAO,GAAGP,MAAMI,KAAK;YAC9BC,WAAWE,OAAO,IAAI;YACtBI,IAAAA,mCAAe,EAACC,kCAAc,EAAE;gBAC5BN,aAAaC,OAAO,CAACE,SAAS,CAACI,OAAO,CAAC,CAACC;oBACpCA,SAAS;wBACLT,WAAWE,OAAO;wBAClBP,MAAMI,KAAK;qBACd;gBACL;YACJ;QACJ,GAAG;YACCJ,MAAMI,KAAK;SACd;QACD,qBAAOF,OAAMa,aAAa,CAACjB,UAAU;YACjCM,OAAOE,aAAaC,OAAO;QAC/B,GAAGP,MAAMgB,QAAQ;IACrB;IACA,wBAAwB,GAAG,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QAClEpB,SAASqB,WAAW,GAAG;IAC3B;IACA,OAAOrB;AACX;AAGW,MAAMH,gBAAgB,CAACyB;IAC9B,8DAA8D;IAC9D,MAAMC,wBAAUpB,OAAMN,aAAa,CAAC;QAChCQ,OAAO;YACHG,SAASc;QACb;QACAb,SAAS;YACLD,SAAS,CAAC;QACd;QACAE,WAAW,EAAE;IACjB;IACAa,QAAQvB,QAAQ,GAAGF,eAAeyB,QAAQvB,QAAQ;IAClD,gCAAgC;IAChC,OAAOuB,QAAQC,QAAQ;IACvB,OAAOD;AACX"}
@@ -9,9 +9,15 @@ function _export(target, all) {
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
- createContext: ()=>_createContext.createContext,
13
- useContextSelector: ()=>_useContextSelector.useContextSelector,
14
- useHasParentContext: ()=>_useHasParentContext.useHasParentContext
12
+ createContext: function() {
13
+ return _createContext.createContext;
14
+ },
15
+ useContextSelector: function() {
16
+ return _useContextSelector.useContextSelector;
17
+ },
18
+ useHasParentContext: function() {
19
+ return _useHasParentContext.useHasParentContext;
20
+ }
15
21
  });
16
22
  const _createContext = require("./createContext");
17
23
  const _useContextSelector = require("./useContextSelector");
@@ -1 +1 @@
1
- {"version":3,"sources":["index.js"],"sourcesContent":["export { createContext } from './createContext';\nexport { useContextSelector } from './useContextSelector';\nexport { useHasParentContext } from './useHasParentContext';\n"],"names":["createContext","useContextSelector","useHasParentContext"],"mappings":";;;;;;;;;;;IAASA,aAAa,MAAbA,4BAAa;IACbC,kBAAkB,MAAlBA,sCAAkB;IAClBC,mBAAmB,MAAnBA,wCAAmB;;+BAFE;oCACK;qCACC"}
1
+ {"version":3,"sources":["index.js"],"sourcesContent":["export { createContext } from './createContext';\nexport { useContextSelector } from './useContextSelector';\nexport { useHasParentContext } from './useHasParentContext';\n"],"names":["createContext","useContextSelector","useHasParentContext"],"mappings":";;;;;;;;;;;IAASA,aAAa;eAAbA,4BAAa;;IACbC,kBAAkB;eAAlBA,sCAAkB;;IAClBC,mBAAmB;eAAnBA,wCAAmB;;;+BAFE;oCACK;qCACC"}
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
6
- const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
5
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
6
+ const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
@@ -1 +1 @@
1
- {"version":3,"sources":["types.js"],"sourcesContent":["import * as React from 'react';\n"],"names":[],"mappings":";;;;;6DAAuB"}
1
+ {"version":3,"sources":["types.js"],"sourcesContent":["import * as React from 'react';\n"],"names":[],"mappings":";;;;;iEAAuB"}
@@ -4,14 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "useContextSelector", {
6
6
  enumerable: true,
7
- get: ()=>useContextSelector
7
+ get: function() {
8
+ return useContextSelector;
9
+ }
8
10
  });
9
- const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
10
- const _reactUtilities = require("@fluentui/react-utilities");
11
- const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
11
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
+ const _reactutilities = require("@fluentui/react-utilities");
13
+ const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
12
14
  const useContextSelector = (context, selector)=>{
13
15
  const contextValue = _react.useContext(context);
14
- const { value: { current: value } , version: { current: version } , listeners } = contextValue;
16
+ const { value: { current: value }, version: { current: version }, listeners } = contextValue;
15
17
  const selected = selector(value);
16
18
  const [state, dispatch] = _react.useReducer((prevState, payload)=>{
17
19
  if (!payload) {
@@ -59,7 +61,7 @@ const useContextSelector = (context, selector)=>{
59
61
  // this is safe because it's self contained
60
62
  dispatch(undefined);
61
63
  }
62
- (0, _reactUtilities.useIsomorphicLayoutEffect)(()=>{
64
+ (0, _reactutilities.useIsomorphicLayoutEffect)(()=>{
63
65
  listeners.push(dispatch);
64
66
  return ()=>{
65
67
  const index = listeners.indexOf(dispatch);
@@ -1 +1 @@
1
- {"version":3,"sources":["useContextSelector.js"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n/**\n * @internal\n * This hook returns context selected value by selector.\n * It will only accept context created by `createContext`.\n * It will trigger re-render if only the selected value is referentially changed.\n */ export const useContextSelector = (context, selector)=>{\n const contextValue = React.useContext(context);\n const { value: { current: value } , version: { current: version } , listeners } = contextValue;\n const selected = selector(value);\n const [state, dispatch] = React.useReducer((prevState, payload)=>{\n if (!payload) {\n // early bail out when is dispatched during render\n return [\n value,\n selected\n ];\n }\n if (payload[0] <= version) {\n if (objectIs(prevState[1], selected)) {\n return prevState; // bail out\n }\n return [\n value,\n selected\n ];\n }\n try {\n if (objectIs(prevState[0], payload[1])) {\n return prevState; // do not update\n }\n const nextSelected = selector(payload[1]);\n if (objectIs(prevState[1], nextSelected)) {\n return prevState; // do not update\n }\n return [\n payload[1],\n nextSelected\n ];\n } catch (e) {\n // ignored (stale props or some other reason)\n }\n // explicitly spread to enforce typing\n return [\n prevState[0],\n prevState[1]\n ]; // schedule update\n }, [\n value,\n selected\n ]);\n if (!objectIs(state[1], selected)) {\n // schedule re-render\n // this is safe because it's self contained\n dispatch(undefined);\n }\n useIsomorphicLayoutEffect(()=>{\n listeners.push(dispatch);\n return ()=>{\n const index = listeners.indexOf(dispatch);\n listeners.splice(index, 1);\n };\n }, [\n listeners\n ]);\n return state[1];\n};\n/**\n * inlined Object.is polyfill to avoid requiring consumers ship their own\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n */ // eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction is(x, y) {\n return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare\n ;\n}\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst objectIs = // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore fallback to native if it exists (not in IE11)\ntypeof Object.is === 'function' ? Object.is : is;\n"],"names":["useContextSelector","context","selector","contextValue","React","useContext","value","current","version","listeners","selected","state","dispatch","useReducer","prevState","payload","objectIs","nextSelected","e","undefined","useIsomorphicLayoutEffect","push","index","indexOf","splice","is","x","y","Object"],"mappings":";;;;+BAOiBA;;aAAAA;;;gCAPyB;6DACnB;AAMZ,MAAMA,qBAAqB,CAACC,SAASC,WAAW;IACvD,MAAMC,eAAeC,OAAMC,UAAU,CAACJ;IACtC,MAAM,EAAEK,OAAO,EAAEC,SAASD,MAAK,EAAG,CAAA,EAAGE,SAAS,EAAED,SAASC,QAAO,EAAG,CAAA,EAAGC,UAAS,EAAG,GAAGN;IACrF,MAAMO,WAAWR,SAASI;IAC1B,MAAM,CAACK,OAAOC,SAAS,GAAGR,OAAMS,UAAU,CAAC,CAACC,WAAWC,UAAU;QAC7D,IAAI,CAACA,SAAS;YACV,kDAAkD;YAClD,OAAO;gBACHT;gBACAI;aACH;QACL,CAAC;QACD,IAAIK,OAAO,CAAC,EAAE,IAAIP,SAAS;YACvB,IAAIQ,SAASF,SAAS,CAAC,EAAE,EAAEJ,WAAW;gBAClC,OAAOI,WAAW,WAAW;YACjC,CAAC;YACD,OAAO;gBACHR;gBACAI;aACH;QACL,CAAC;QACD,IAAI;YACA,IAAIM,SAASF,SAAS,CAAC,EAAE,EAAEC,OAAO,CAAC,EAAE,GAAG;gBACpC,OAAOD,WAAW,gBAAgB;YACtC,CAAC;YACD,MAAMG,eAAef,SAASa,OAAO,CAAC,EAAE;YACxC,IAAIC,SAASF,SAAS,CAAC,EAAE,EAAEG,eAAe;gBACtC,OAAOH,WAAW,gBAAgB;YACtC,CAAC;YACD,OAAO;gBACHC,OAAO,CAAC,EAAE;gBACVE;aACH;QACL,EAAE,OAAOC,GAAG;QACZ,6CAA6C;QAC7C;QACA,sCAAsC;QACtC,OAAO;YACHJ,SAAS,CAAC,EAAE;YACZA,SAAS,CAAC,EAAE;SACf,EAAE,kBAAkB;IACzB,GAAG;QACCR;QACAI;KACH;IACD,IAAI,CAACM,SAASL,KAAK,CAAC,EAAE,EAAED,WAAW;QAC/B,qBAAqB;QACrB,2CAA2C;QAC3CE,SAASO;IACb,CAAC;IACDC,IAAAA,yCAAyB,EAAC,IAAI;QAC1BX,UAAUY,IAAI,CAACT;QACf,OAAO,IAAI;YACP,MAAMU,QAAQb,UAAUc,OAAO,CAACX;YAChCH,UAAUe,MAAM,CAACF,OAAO;QAC5B;IACJ,GAAG;QACCb;KACH;IACD,OAAOE,KAAK,CAAC,EAAE;AACnB;AACA;;;CAGC,GAAG,8DAA8D;AAClE,SAASc,GAAGC,CAAC,EAAEC,CAAC,EAAE;IACd,OAAOD,MAAMC,KAAMD,CAAAA,MAAM,KAAK,IAAIA,MAAM,IAAIC,CAAAA,KAAMD,MAAMA,KAAKC,MAAMA,EAAE,sCAAsC;;AAE/G;AACA,8DAA8D;AAC9D,MAAMX,WACN,2DAA2D;AAC3D,OAAOY,OAAOH,EAAE,KAAK,aAAaG,OAAOH,EAAE,GAAGA,EAAE"}
1
+ {"version":3,"sources":["useContextSelector.js"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n/**\n * @internal\n * This hook returns context selected value by selector.\n * It will only accept context created by `createContext`.\n * It will trigger re-render if only the selected value is referentially changed.\n */ export const useContextSelector = (context, selector)=>{\n const contextValue = React.useContext(context);\n const { value: { current: value }, version: { current: version }, listeners } = contextValue;\n const selected = selector(value);\n const [state, dispatch] = React.useReducer((prevState, payload)=>{\n if (!payload) {\n // early bail out when is dispatched during render\n return [\n value,\n selected\n ];\n }\n if (payload[0] <= version) {\n if (objectIs(prevState[1], selected)) {\n return prevState; // bail out\n }\n return [\n value,\n selected\n ];\n }\n try {\n if (objectIs(prevState[0], payload[1])) {\n return prevState; // do not update\n }\n const nextSelected = selector(payload[1]);\n if (objectIs(prevState[1], nextSelected)) {\n return prevState; // do not update\n }\n return [\n payload[1],\n nextSelected\n ];\n } catch (e) {\n // ignored (stale props or some other reason)\n }\n // explicitly spread to enforce typing\n return [\n prevState[0],\n prevState[1]\n ]; // schedule update\n }, [\n value,\n selected\n ]);\n if (!objectIs(state[1], selected)) {\n // schedule re-render\n // this is safe because it's self contained\n dispatch(undefined);\n }\n useIsomorphicLayoutEffect(()=>{\n listeners.push(dispatch);\n return ()=>{\n const index = listeners.indexOf(dispatch);\n listeners.splice(index, 1);\n };\n }, [\n listeners\n ]);\n return state[1];\n};\n/**\n * inlined Object.is polyfill to avoid requiring consumers ship their own\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n */ // eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction is(x, y) {\n return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare\n ;\n}\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst objectIs = // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore fallback to native if it exists (not in IE11)\ntypeof Object.is === 'function' ? Object.is : is;\n"],"names":["useContextSelector","context","selector","contextValue","React","useContext","value","current","version","listeners","selected","state","dispatch","useReducer","prevState","payload","objectIs","nextSelected","e","undefined","useIsomorphicLayoutEffect","push","index","indexOf","splice","is","x","y","Object"],"mappings":";;;;+BAOiBA;;;eAAAA;;;;gCAPyB;iEACnB;AAMZ,MAAMA,qBAAqB,CAACC,SAASC;IAC5C,MAAMC,eAAeC,OAAMC,UAAU,CAACJ;IACtC,MAAM,EAAEK,OAAO,EAAEC,SAASD,KAAK,EAAE,EAAEE,SAAS,EAAED,SAASC,OAAO,EAAE,EAAEC,SAAS,EAAE,GAAGN;IAChF,MAAMO,WAAWR,SAASI;IAC1B,MAAM,CAACK,OAAOC,SAAS,GAAGR,OAAMS,UAAU,CAAC,CAACC,WAAWC;QACnD,IAAI,CAACA,SAAS;YACV,kDAAkD;YAClD,OAAO;gBACHT;gBACAI;aACH;QACL;QACA,IAAIK,OAAO,CAAC,EAAE,IAAIP,SAAS;YACvB,IAAIQ,SAASF,SAAS,CAAC,EAAE,EAAEJ,WAAW;gBAClC,OAAOI,WAAW,WAAW;YACjC;YACA,OAAO;gBACHR;gBACAI;aACH;QACL;QACA,IAAI;YACA,IAAIM,SAASF,SAAS,CAAC,EAAE,EAAEC,OAAO,CAAC,EAAE,GAAG;gBACpC,OAAOD,WAAW,gBAAgB;YACtC;YACA,MAAMG,eAAef,SAASa,OAAO,CAAC,EAAE;YACxC,IAAIC,SAASF,SAAS,CAAC,EAAE,EAAEG,eAAe;gBACtC,OAAOH,WAAW,gBAAgB;YACtC;YACA,OAAO;gBACHC,OAAO,CAAC,EAAE;gBACVE;aACH;QACL,EAAE,OAAOC,GAAG;QACZ,6CAA6C;QAC7C;QACA,sCAAsC;QACtC,OAAO;YACHJ,SAAS,CAAC,EAAE;YACZA,SAAS,CAAC,EAAE;SACf,EAAE,kBAAkB;IACzB,GAAG;QACCR;QACAI;KACH;IACD,IAAI,CAACM,SAASL,KAAK,CAAC,EAAE,EAAED,WAAW;QAC/B,qBAAqB;QACrB,2CAA2C;QAC3CE,SAASO;IACb;IACAC,IAAAA,yCAAyB,EAAC;QACtBX,UAAUY,IAAI,CAACT;QACf,OAAO;YACH,MAAMU,QAAQb,UAAUc,OAAO,CAACX;YAChCH,UAAUe,MAAM,CAACF,OAAO;QAC5B;IACJ,GAAG;QACCb;KACH;IACD,OAAOE,KAAK,CAAC,EAAE;AACnB;AACA;;;CAGC,GAAG,8DAA8D;AAClE,SAASc,GAAGC,CAAC,EAAEC,CAAC;IACZ,OAAOD,MAAMC,KAAMD,CAAAA,MAAM,KAAK,IAAIA,MAAM,IAAIC,CAAAA,KAAMD,MAAMA,KAAKC,MAAMA,EAAE,sCAAsC;;AAE/G;AACA,8DAA8D;AAC9D,MAAMX,WACN,2DAA2D;AAC3D,OAAOY,OAAOH,EAAE,KAAK,aAAaG,OAAOH,EAAE,GAAGA"}
@@ -4,10 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "useHasParentContext", {
6
6
  enumerable: true,
7
- get: ()=>useHasParentContext
7
+ get: function() {
8
+ return useHasParentContext;
9
+ }
8
10
  });
9
- const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
10
- const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
11
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
+ const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
11
13
  function useHasParentContext(context) {
12
14
  const contextValue = _react.useContext(context);
13
15
  if (contextValue.version) {
@@ -1 +1 @@
1
- {"version":3,"sources":["useHasParentContext.js"],"sourcesContent":["import * as React from 'react';\n/**\n * @internal\n * Utility hook for contexts created by react-context-selector to determine if a parent context exists\n * WARNING: This hook will not work for native React contexts\n *\n * @param context - context created by react-context-selector\n * @returns whether the hook is wrapped by a parent context\n */ export function useHasParentContext(context) {\n const contextValue = React.useContext(context);\n if (contextValue.version) {\n return contextValue.version.current !== -1;\n }\n return false;\n}\n"],"names":["useHasParentContext","context","contextValue","React","useContext","version","current"],"mappings":";;;;+BAQoBA;;aAAAA;;;6DARG;AAQZ,SAASA,oBAAoBC,OAAO,EAAE;IAC7C,MAAMC,eAAeC,OAAMC,UAAU,CAACH;IACtC,IAAIC,aAAaG,OAAO,EAAE;QACtB,OAAOH,aAAaG,OAAO,CAACC,OAAO,KAAK,CAAC;IAC7C,CAAC;IACD,OAAO,KAAK;AAChB"}
1
+ {"version":3,"sources":["useHasParentContext.js"],"sourcesContent":["import * as React from 'react';\n/**\n * @internal\n * Utility hook for contexts created by react-context-selector to determine if a parent context exists\n * WARNING: This hook will not work for native React contexts\n *\n * @param context - context created by react-context-selector\n * @returns whether the hook is wrapped by a parent context\n */ export function useHasParentContext(context) {\n const contextValue = React.useContext(context);\n if (contextValue.version) {\n return contextValue.version.current !== -1;\n }\n return false;\n}\n"],"names":["useHasParentContext","context","contextValue","React","useContext","version","current"],"mappings":";;;;+BAQoBA;;;eAAAA;;;;iEARG;AAQZ,SAASA,oBAAoBC,OAAO;IAC3C,MAAMC,eAAeC,OAAMC,UAAU,CAACH;IACtC,IAAIC,aAAaG,OAAO,EAAE;QACtB,OAAOH,aAAaG,OAAO,CAACC,OAAO,KAAK,CAAC;IAC7C;IACA,OAAO;AACX"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-context-selector",
3
- "version": "9.1.31",
3
+ "version": "9.1.33",
4
4
  "description": "React useContextSelector hook in userland",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",
@@ -28,14 +28,14 @@
28
28
  "@fluentui/scripts-tasks": "*"
29
29
  },
30
30
  "dependencies": {
31
- "@fluentui/react-utilities": "^9.13.0",
32
- "@swc/helpers": "^0.4.14"
31
+ "@fluentui/react-utilities": "^9.13.2",
32
+ "@swc/helpers": "^0.5.1"
33
33
  },
34
34
  "peerDependencies": {
35
- "@types/react": ">=16.8.0 <19.0.0",
36
- "@types/react-dom": ">=16.8.0 <19.0.0",
37
- "react": ">=16.8.0 <19.0.0",
38
- "react-dom": ">=16.8.0 <19.0.0",
35
+ "@types/react": ">=16.14.0 <19.0.0",
36
+ "@types/react-dom": ">=16.14.0 <19.0.0",
37
+ "react": ">=16.14.0 <19.0.0",
38
+ "react-dom": ">=16.14.0 <19.0.0",
39
39
  "scheduler": "^0.19.0 || ^0.20.0"
40
40
  },
41
41
  "beachball": {