@fluentui/react-context-selector 9.1.14 → 9.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.swcrc ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/swcrc",
3
+ "exclude": [
4
+ "/testing",
5
+ "/**/*.cy.ts",
6
+ "/**/*.cy.tsx",
7
+ "/**/*.spec.ts",
8
+ "/**/*.spec.tsx",
9
+ "/**/*.test.ts",
10
+ "/**/*.test.tsx"
11
+ ],
12
+ "jsc": {
13
+ "parser": {
14
+ "syntax": "typescript",
15
+ "tsx": true,
16
+ "decorators": false,
17
+ "dynamicImport": false
18
+ },
19
+ "externalHelpers": true,
20
+ "transform": {
21
+ "react": {
22
+ "runtime": "classic",
23
+ "useSpread": true
24
+ }
25
+ },
26
+ "target": "es2019"
27
+ },
28
+ "minify": false,
29
+ "sourceMaps": true
30
+ }
package/CHANGELOG.json CHANGED
@@ -2,7 +2,49 @@
2
2
  "name": "@fluentui/react-context-selector",
3
3
  "entries": [
4
4
  {
5
- "date": "Thu, 16 Mar 2023 14:33:33 GMT",
5
+ "date": "Tue, 04 Apr 2023 18:42:19 GMT",
6
+ "tag": "@fluentui/react-context-selector_v9.1.16",
7
+ "version": "9.1.16",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "beachball",
12
+ "package": "@fluentui/react-context-selector",
13
+ "comment": "Bump @fluentui/react-utilities to v9.7.3",
14
+ "commit": "37a3a6eda1fd41086edd99a0b1560a8740f8c6c5"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Tue, 21 Mar 2023 21:23:30 GMT",
21
+ "tag": "@fluentui/react-context-selector_v9.1.15",
22
+ "version": "9.1.15",
23
+ "comments": {
24
+ "patch": [
25
+ {
26
+ "author": "tristan.watanabe@gmail.com",
27
+ "package": "@fluentui/react-context-selector",
28
+ "commit": "ead1c6d4c2ac3f3596b62b8cbc07b0a03041f11f",
29
+ "comment": "fix: add node field to package.json exports map."
30
+ },
31
+ {
32
+ "author": "tristan.watanabe@gmail.com",
33
+ "package": "@fluentui/react-context-selector",
34
+ "commit": "2fac1a139149bd13b76b1306207bc988dca9c72c",
35
+ "comment": "chore: migrate to swc transpilation approach."
36
+ },
37
+ {
38
+ "author": "beachball",
39
+ "package": "@fluentui/react-context-selector",
40
+ "comment": "Bump @fluentui/react-utilities to v9.7.2",
41
+ "commit": "b7a26f6263c80e3253c6b8338c33b73bae33e2b5"
42
+ }
43
+ ]
44
+ }
45
+ },
46
+ {
47
+ "date": "Thu, 16 Mar 2023 14:36:59 GMT",
6
48
  "tag": "@fluentui/react-context-selector_v9.1.14",
7
49
  "version": "9.1.14",
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 Thu, 16 Mar 2023 14:33:33 GMT and should not be manually modified.
3
+ This log was last generated on Tue, 04 Apr 2023 18:42:19 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.1.16](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.1.16)
8
+
9
+ Tue, 04 Apr 2023 18:42:19 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.15..@fluentui/react-context-selector_v9.1.16)
11
+
12
+ ### Patches
13
+
14
+ - Bump @fluentui/react-utilities to v9.7.3 ([PR #27430](https://github.com/microsoft/fluentui/pull/27430) by beachball)
15
+
16
+ ## [9.1.15](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.1.15)
17
+
18
+ Tue, 21 Mar 2023 21:23:30 GMT
19
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.14..@fluentui/react-context-selector_v9.1.15)
20
+
21
+ ### Patches
22
+
23
+ - fix: add node field to package.json exports map. ([PR #27154](https://github.com/microsoft/fluentui/pull/27154) by tristan.watanabe@gmail.com)
24
+ - chore: migrate to swc transpilation approach. ([PR #27250](https://github.com/microsoft/fluentui/pull/27250) by tristan.watanabe@gmail.com)
25
+ - Bump @fluentui/react-utilities to v9.7.2 ([PR #27271](https://github.com/microsoft/fluentui/pull/27271) by beachball)
26
+
7
27
  ## [9.1.14](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.1.14)
8
28
 
9
- Thu, 16 Mar 2023 14:33:33 GMT
29
+ Thu, 16 Mar 2023 14:36:59 GMT
10
30
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.13..@fluentui/react-context-selector_v9.1.14)
11
31
 
12
32
  ### Patches
@@ -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":["../src/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,GAAG;QACrBH,KAAK,EAAEF,QAAQ;QACfM,OAAO,EAAEH,UAAU;QACnBI,SAAS,EAAE;OACZ;;IAGHjB,yBAAyB,CAAC,MAAK;MAC7BU,QAAQ,CAACK,OAAO,GAAGN,KAAK,CAACG,KAAK;MAC9BC,UAAU,CAACE,OAAO,IAAI,CAAC;MAEvBV,eAAe,CAACF,cAAc,EAAE,MAAK;QAClCW,YAAY,CAACC,OAA+B,CAACE,SAAS,CAACC,OAAO,CAACC,QAAQ,IAAG;UACzEA,QAAQ,CAAC,CAACN,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,oBAAOX,KAAK,CAACmB,aAAa,CAACb,QAAQ,EAAE;MAAEK,KAAK,EAAEE,YAAY,CAACC;IAAO,CAAE,EAAEN,KAAK,CAACY,QAAQ,CAAC;EACvF,CAAC;EAED;EACA,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;IACzChB,QAAQ,CAACiB,WAAW,GAAG,0BAA0B;;EAGnD,OAAOjB,QAA0D;AACnE,CAAC;AAED;;;AAGA,OAAO,MAAMkB,aAAa,GAAWC,YAAmB,IAAoB;EAC1E;EACA,MAAMC,OAAO,gBAAG3B,KAAK,CAACyB,aAAa,CAAsB;IACvDd,KAAK,EAAE;MAAEG,OAAO,EAAEY;IAAY,CAAE;IAChCX,OAAO,EAAE;MAAED,OAAO,EAAE,CAAC;IAAC,CAAE;IACxBE,SAAS,EAAE;GACZ,CAAC;EAEFW,OAAO,CAACpB,QAAQ,GAAGF,cAAc,CAAQsB,OAAO,CAACpB,QAAQ,CAAC;EAE1D;EACA,OAAQoB,OAAqC,CAACC,QAAQ;EAEtD,OAAOD,OAAoC;AAC7C,CAAC"}
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":["../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;AAC1C,YAAYC,KAAA,MAAW;AACvB,SAASC,uBAAA,IAA2BC,cAAc,EAAEC,wBAAA,IAA4BC,eAAe,QAAQ;AAIvG,MAAMC,cAAA,GAAyBC,QAAA,IAAkD;EAC/E,MAAMC,QAAA,GAAiDC,KAAA,IAAS;IAC9D;IACA,MAAMC,QAAA,GAAWT,KAAA,CAAMU,MAAM,CAACF,KAA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C,CAAsCC,QAAQ;EAEtD,OAAOD,OAAA;AACT"}
package/lib/index.js.map CHANGED
@@ -1 +1 @@
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"]}
1
+ {"version":3,"names":["createContext","useContextSelector","useHasParentContext"],"sources":["../src/index.ts"],"sourcesContent":["export { createContext } from './createContext';\nexport { useContextSelector } from './useContextSelector';\nexport { useHasParentContext } from './useHasParentContext';\n// eslint-disable-next-line @fluentui/ban-context-export\nexport type { Context, ContextSelector, ContextValue, ContextValues, ContextVersion } from './types';\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ;AAC9B,SAASC,kBAAkB,QAAQ;AACnC,SAASC,mBAAmB,QAAQ"}
package/lib/types.js CHANGED
@@ -1,2 +1,2 @@
1
- export {};
1
+ import * as React from 'react';
2
2
  //# sourceMappingURL=types.js.map
package/lib/types.js.map CHANGED
@@ -1 +1 @@
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
+ {"version":3,"names":["React"],"sources":["../src/types.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n */\nexport type Context<Value> = React.Context<Value> & {\n Provider: React.FC<React.ProviderProps<Value>>;\n Consumer: never;\n};\n\nexport type ContextSelector<Value, SelectedValue> = (value: Value) => SelectedValue;\n\n/**\n * @internal\n */\nexport type ContextVersion = number;\n\n/**\n * @internal\n */\nexport type ContextValue<Value> = {\n /** Holds a set of subscribers from components. */\n listeners: ((payload: readonly [ContextVersion, Value]) => void)[];\n\n /** Holds an actual value of React's context that will be propagated down for computations. */\n value: React.MutableRefObject<Value>;\n\n /** A version field is used to sync a context value and consumers. */\n version: React.MutableRefObject<ContextVersion>;\n};\n\n/**\n * @internal\n */\nexport type ContextValues<Value> = ContextValue<Value> & {\n /** List of listners to publish changes */\n listeners: ((payload: readonly [ContextVersion, Record<string, Value>]) => void)[];\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW"}
@@ -64,8 +64,7 @@ export const useContextSelector = (context, selector) => {
64
64
  /**
65
65
  * inlined Object.is polyfill to avoid requiring consumers ship their own
66
66
  * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
67
- */
68
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
+ */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
68
  function is(x, y) {
70
69
  return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
71
70
  ;
@@ -1 +1 @@
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":["../src/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"],"mappings":"AAAA,SAASA,yBAAyB,QAAQ,2BAA2B;AACrE,OAAO,KAAKC,KAAK,MAAM,OAAO;AAa9B;;;;;;AAMA,OAAO,MAAMC,kBAAkB,GAAGA,CAChCC,OAAuB,EACvBC,QAA+C,KAC9B;EACjB,MAAMC,YAAY,GAAGJ,KAAK,CAACK,UAAU,CAACH,OAAkD,CAAC;EAEzF,MAAM;IACJI,KAAK,EAAE;MAAEC,OAAO,EAAED;IAAK,CAAE;IACzBE,OAAO,EAAE;MAAED,OAAO,EAAEC;IAAO,CAAE;IAC7BC;EAAS,CACV,GAAGL,YAAY;EAChB,MAAMM,QAAQ,GAAGP,QAAQ,CAACG,KAAK,CAAC;EAEhC,MAAM,CAACK,KAAK,EAAEC,QAAQ,CAAC,GAAGZ,KAAK,CAACa,UAAU,CACxC,CACEC,SAAmF,EACnFC,OAEoC,KACD;IACnC,IAAI,CAACA,OAAO,EAAE;MACZ;MACA,OAAO,CAACT,KAAK,EAAEI,QAAQ,CAAU;;IAGnC,I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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
+ {"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":["../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"],"mappings":"AAAA,SAASA,yBAAyB,QAAQ;AAC1C,YAAYC,KAAA,MAAW;AAavB;;;;;;AAMA,OAAO,MAAMC,kBAAA,GAAqBA,CAChCC,OAAA,EACAC,QAAA,KACkB;EAClB,MAAMC,YAAA,GAAeJ,KAAA,CAAMK,UAAU,CAACH,OAAA;EAEtC,MAAM;IACJI,KAAA,EAAO;MAAEC,OAAA,EAASD;IAAK,CAAE;IACzBE,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OAAO,CAACV,QAAA;MAChCH,SAAA,CAAUc,MAAM,CAACF,KAAA,EAAO;IAC1B;EACF,GAAG,CAACZ,SAAA,CAAU;EAEd,OAAOE,KAAK,CAAC,EAAE;AACjB;AAEA;;;GAAA,CAIA;AACA,SAASa,GAAGC,CAAM,EAAEC,CAAM,EAAE;EAC1B,OACED,CAAC,KAAMC,CAAA,KAAMD,CAAA,KAAM,KAAK,IAAIA,CAAA,KAAM,IAAIC,CAAA,KAAQD,CAAA,KAAMA,CAAA,IAAKC,CAAA,KAAMA,CAAA,CAAG;EAAA;AAEtE;AAEA;AACA,MAAMV,QAAA;AACJ;AACA;AACA,OAAOW,MAAA,CAAOH,EAAE,KAAK,aAAaG,MAAA,CAAOH,EAAE,GAAGA,EAAE"}
@@ -1 +1 @@
1
- {"version":3,"names":["React","useHasParentContext","context","contextValue","useContext","version","current"],"sources":["../src/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
+ {"version":3,"names":["React","useHasParentContext","context","contextValue","useContext","version","current"],"sources":["../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,YAAYA,KAAA,MAAW;AAGvB;;;;;;;;AAQA,OAAO,SAASC,oBAA2BC,OAAuB,EAAE;EAClE,MAAMC,YAAA,GAAeH,KAAA,CAAMI,UAAU,CAACF,OAAA;EAEtC,IAAIC,YAAA,CAAaE,OAAO,EAAE;IACxB,OAAOF,YAAA,CAAaE,OAAO,CAACC,OAAO,KAAK,CAAC;EAC3C;EAEA,OAAO,KAAK;AACd"}
@@ -1,64 +1,68 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.createContext = void 0;
7
- const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
8
- const React = /*#__PURE__*/require("react");
9
- const scheduler_1 = /*#__PURE__*/require("scheduler");
10
- const createProvider = Original => {
11
- const Provider = props => {
12
- // Holds an actual "props.value"
13
- const valueRef = React.useRef(props.value);
14
- // Used to sync context updates and avoid stale values, can be considered as render/effect counter of Provider.
15
- const versionRef = React.useRef(0);
16
- // A stable object, is used to avoid context updates via mutation of its values.
17
- const contextValue = React.useRef();
18
- if (!contextValue.current) {
19
- contextValue.current = {
20
- value: valueRef,
21
- version: versionRef,
22
- listeners: []
23
- };
5
+ Object.defineProperty(exports, "createContext", {
6
+ enumerable: true,
7
+ get: ()=>createContext
8
+ });
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"));
12
+ const _scheduler = require("scheduler");
13
+ const createProvider = (Original)=>{
14
+ const Provider = (props)=>{
15
+ // Holds an actual "props.value"
16
+ const valueRef = _react.useRef(props.value);
17
+ // Used to sync context updates and avoid stale values, can be considered as render/effect counter of Provider.
18
+ const versionRef = _react.useRef(0);
19
+ // A stable object, is used to avoid context updates via mutation of its values.
20
+ const contextValue = _react.useRef();
21
+ if (!contextValue.current) {
22
+ contextValue.current = {
23
+ value: valueRef,
24
+ version: versionRef,
25
+ listeners: []
26
+ };
27
+ }
28
+ (0, _reactUtilities.useIsomorphicLayoutEffect)(()=>{
29
+ valueRef.current = props.value;
30
+ versionRef.current += 1;
31
+ (0, _scheduler.unstable_runWithPriority)(_scheduler.unstable_NormalPriority, ()=>{
32
+ contextValue.current.listeners.forEach((listener)=>{
33
+ listener([
34
+ versionRef.current,
35
+ props.value
36
+ ]);
37
+ });
38
+ });
39
+ }, [
40
+ props.value
41
+ ]);
42
+ return /*#__PURE__*/ _react.createElement(Original, {
43
+ value: contextValue.current
44
+ }, props.children);
45
+ };
46
+ /* istanbul ignore else */ if (process.env.NODE_ENV !== 'production') {
47
+ Provider.displayName = 'ContextSelector.Provider';
24
48
  }
25
- react_utilities_1.useIsomorphicLayoutEffect(() => {
26
- valueRef.current = props.value;
27
- versionRef.current += 1;
28
- scheduler_1.unstable_runWithPriority(scheduler_1.unstable_NormalPriority, () => {
29
- contextValue.current.listeners.forEach(listener => {
30
- listener([versionRef.current, props.value]);
31
- });
32
- });
33
- }, [props.value]);
34
- return React.createElement(Original, {
35
- value: contextValue.current
36
- }, props.children);
37
- };
38
- /* istanbul ignore else */
39
- if (process.env.NODE_ENV !== 'production') {
40
- Provider.displayName = 'ContextSelector.Provider';
41
- }
42
- return Provider;
49
+ return Provider;
43
50
  };
44
- /**
45
- * @internal
46
- */
47
- const createContext = defaultValue => {
48
- // eslint-disable-next-line @fluentui/no-context-default-value
49
- const context = React.createContext({
50
- value: {
51
- current: defaultValue
52
- },
53
- version: {
54
- current: -1
55
- },
56
- listeners: []
57
- });
58
- context.Provider = createProvider(context.Provider);
59
- // We don't support Consumer API
60
- delete context.Consumer;
61
- return context;
62
- };
63
- exports.createContext = createContext;
51
+ const createContext = (defaultValue)=>{
52
+ // eslint-disable-next-line @fluentui/no-context-default-value
53
+ const context = /*#__PURE__*/ _react.createContext({
54
+ value: {
55
+ current: defaultValue
56
+ },
57
+ version: {
58
+ current: -1
59
+ },
60
+ listeners: []
61
+ });
62
+ context.Provider = createProvider(context.Provider);
63
+ // We don't support Consumer API
64
+ delete context.Consumer;
65
+ return context;
66
+ }; //# sourceMappingURL=createContext.js.map
67
+
64
68
  //# sourceMappingURL=createContext.js.map
@@ -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":["../src/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
+ {"version":3,"sources":["../lib/createContext.js"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { unstable_NormalPriority as NormalPriority, unstable_runWithPriority as runWithPriority } from 'scheduler';\nconst createProvider = Original => {\n const Provider = props => {\n // Holds an actual \"props.value\"\n const valueRef = React.useRef(props.value);\n // Used to sync context updates and avoid stale values, can be considered as render/effect counter of Provider.\n const versionRef = React.useRef(0);\n // A stable object, is used to avoid context updates via mutation of its values.\n const contextValue = React.useRef();\n if (!contextValue.current) {\n contextValue.current = {\n value: valueRef,\n version: versionRef,\n listeners: []\n };\n }\n useIsomorphicLayoutEffect(() => {\n valueRef.current = props.value;\n versionRef.current += 1;\n runWithPriority(NormalPriority, () => {\n contextValue.current.listeners.forEach(listener => {\n listener([versionRef.current, props.value]);\n });\n });\n }, [props.value]);\n return /*#__PURE__*/React.createElement(Original, {\n value: contextValue.current\n }, props.children);\n };\n /* istanbul ignore else */\n if (process.env.NODE_ENV !== 'production') {\n Provider.displayName = 'ContextSelector.Provider';\n }\n return Provider;\n};\n/**\n * @internal\n */\nexport const createContext = defaultValue => {\n // eslint-disable-next-line @fluentui/no-context-default-value\n const context = /*#__PURE__*/React.createContext({\n value: {\n current: defaultValue\n },\n version: {\n current: -1\n },\n listeners: []\n });\n context.Provider = createProvider(context.Provider);\n // We don't support Consumer API\n delete context.Consumer;\n return context;\n};\n//# sourceMappingURL=createContext.js.map"],"names":["createContext","createProvider","Original","Provider","props","valueRef","React","useRef","value","versionRef","contextValue","current","version","listeners","useIsomorphicLayoutEffect","runWithPriority","NormalPriority","forEach","listener","createElement","children","process","env","NODE_ENV","displayName","defaultValue","context","Consumer"],"mappings":";;;;+BAwCaA;;aAAAA;;;gCAxC6B;6DACnB;2BACgF;AACvG,MAAMC,iBAAiBC,CAAAA,WAAY;IACjC,MAAMC,WAAWC,CAAAA,QAAS;QACxB,gCAAgC;QAChC,MAAMC,WAAWC,OAAMC,MAAM,CAACH,MAAMI,KAAK;QACzC,+GAA+G;QAC/G,MAAMC,aAAaH,OAAMC,MAAM,CAAC;QAChC,gFAAgF;QAChF,MAAMG,eAAeJ,OAAMC,MAAM;QACjC,IAAI,CAACG,aAAaC,OAAO,EAAE;YACzBD,aAAaC,OAAO,GAAG;gBACrBH,OAAOH;gBACPO,SAASH;gBACTI,WAAW,EAAE;YACf;QACF,CAAC;QACDC,IAAAA,yCAAyB,EAAC,IAAM;YAC9BT,SAASM,OAAO,GAAGP,MAAMI,KAAK;YAC9BC,WAAWE,OAAO,IAAI;YACtBI,IAAAA,mCAAe,EAACC,kCAAc,EAAE,IAAM;gBACpCN,aAAaC,OAAO,CAACE,SAAS,CAACI,OAAO,CAACC,CAAAA,WAAY;oBACjDA,SAAS;wBAACT,WAAWE,OAAO;wBAAEP,MAAMI,KAAK;qBAAC;gBAC5C;YACF;QACF,GAAG;YAACJ,MAAMI,KAAK;SAAC;QAChB,OAAO,WAAW,GAAEF,OAAMa,aAAa,CAACjB,UAAU;YAChDM,OAAOE,aAAaC,OAAO;QAC7B,GAAGP,MAAMgB,QAAQ;IACnB;IACA,wBAAwB,GACxB,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzCpB,SAASqB,WAAW,GAAG;IACzB,CAAC;IACD,OAAOrB;AACT;AAIO,MAAMH,gBAAgByB,CAAAA,eAAgB;IAC3C,8DAA8D;IAC9D,MAAMC,UAAU,WAAW,GAAEpB,OAAMN,aAAa,CAAC;QAC/CQ,OAAO;YACLG,SAASc;QACX;QACAb,SAAS;YACPD,SAAS,CAAC;QACZ;QACAE,WAAW,EAAE;IACf;IACAa,QAAQvB,QAAQ,GAAGF,eAAeyB,QAAQvB,QAAQ;IAClD,gCAAgC;IAChC,OAAOuB,QAAQC,QAAQ;IACvB,OAAOD;AACT,GACA,yCAAyC"}
@@ -1,28 +1,21 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useHasParentContext = exports.useContextSelector = exports.createContext = void 0;
7
- var createContext_1 = /*#__PURE__*/require("./createContext");
8
- Object.defineProperty(exports, "createContext", {
9
- enumerable: true,
10
- get: function () {
11
- return createContext_1.createContext;
12
- }
3
+ value: true
13
4
  });
14
- var useContextSelector_1 = /*#__PURE__*/require("./useContextSelector");
15
- Object.defineProperty(exports, "useContextSelector", {
16
- enumerable: true,
17
- get: function () {
18
- return useContextSelector_1.useContextSelector;
19
- }
20
- });
21
- var useHasParentContext_1 = /*#__PURE__*/require("./useHasParentContext");
22
- Object.defineProperty(exports, "useHasParentContext", {
23
- enumerable: true,
24
- get: function () {
25
- return useHasParentContext_1.useHasParentContext;
26
- }
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ createContext: ()=>_createContext.createContext,
13
+ useContextSelector: ()=>_useContextSelector.useContextSelector,
14
+ useHasParentContext: ()=>_useHasParentContext.useHasParentContext
27
15
  });
16
+ const _createContext = require("./createContext");
17
+ const _useContextSelector = require("./useContextSelector");
18
+ const _useHasParentContext = require("./useHasParentContext");
19
+ //# sourceMappingURL=index.js.map
20
+
28
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createContext_1","require","Object","defineProperty","exports","enumerable","get","createContext","useContextSelector_1","useContextSelector","useHasParentContext_1","useHasParentContext"],"sources":["../src/packages/react-components/react-context-selector/src/index.ts"],"sourcesContent":["export { createContext } from './createContext';\nexport { useContextSelector } from './useContextSelector';\nexport { useHasParentContext } from './useHasParentContext';\n// eslint-disable-next-line @fluentui/ban-context-export\nexport type { Context, ContextSelector, ContextValue, ContextValues, ContextVersion } from './types';\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,gBAAAC,OAAA;AAASC,MAAA,CAAAC,cAAA,CAAAC,OAAA;EAAAC,UAAA;EAAAC,GAAA,WAAAA,CAAA;IAAA,OAAAN,eAAA,CAAAO,aAAa;EAAA;AAAA;AACtB,IAAAC,oBAAA,gBAAAP,OAAA;AAASC,MAAA,CAAAC,cAAA,CAAAC,OAAA;EAAAC,UAAA;EAAAC,GAAA,WAAAA,CAAA;IAAA,OAAAE,oBAAA,CAAAC,kBAAkB;EAAA;AAAA;AAC3B,IAAAC,qBAAA,gBAAAT,OAAA;AAASC,MAAA,CAAAC,cAAA,CAAAC,OAAA;EAAAC,UAAA;EAAAC,GAAA,WAAAA,CAAA;IAAA,OAAAI,qBAAA,CAAAC,mBAAmB;EAAA;AAAA"}
1
+ {"version":3,"sources":["../lib/index.js"],"sourcesContent":["export { createContext } from './createContext';\nexport { useContextSelector } from './useContextSelector';\nexport { useHasParentContext } from './useHasParentContext';\n//# sourceMappingURL=index.js.map"],"names":["createContext","useContextSelector","useHasParentContext"],"mappings":";;;;;;;;;;;IAASA,aAAa,MAAbA,4BAAa;IACbC,kBAAkB,MAAlBA,sCAAkB;IAClBC,mBAAmB,MAAnBA,wCAAmB;;+BAFE;oCACK;qCACC;CACpC,iCAAiC"}
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
5
+ const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
6
+ const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
7
+ //# sourceMappingURL=types.js.map
8
+
6
9
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["../src/packages/react-components/react-context-selector/src/types.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n */\nexport type Context<Value> = React.Context<Value> & {\n Provider: React.FC<React.ProviderProps<Value>>;\n Consumer: never;\n};\n\nexport type ContextSelector<Value, SelectedValue> = (value: Value) => SelectedValue;\n\n/**\n * @internal\n */\nexport type ContextVersion = number;\n\n/**\n * @internal\n */\nexport type ContextValue<Value> = {\n /** Holds a set of subscribers from components. */\n listeners: ((payload: readonly [ContextVersion, Value]) => void)[];\n\n /** Holds an actual value of React's context that will be propagated down for computations. */\n value: React.MutableRefObject<Value>;\n\n /** A version field is used to sync a context value and consumers. */\n version: React.MutableRefObject<ContextVersion>;\n};\n\n/**\n * @internal\n */\nexport type ContextValues<Value> = ContextValue<Value> & {\n /** List of listners to publish changes */\n listeners: ((payload: readonly [ContextVersion, Record<string, Value>]) => void)[];\n};\n"],"mappings":""}
1
+ {"version":3,"sources":["../lib/types.js"],"sourcesContent":["import * as React from 'react';\n//# sourceMappingURL=types.js.map"],"names":[],"mappings":";;;;;6DAAuB;CACvB,iCAAiC"}
@@ -1,85 +1,86 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.useContextSelector = void 0;
7
- const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
8
- const React = /*#__PURE__*/require("react");
9
- /**
10
- * @internal
11
- * This hook returns context selected value by selector.
12
- * It will only accept context created by `createContext`.
13
- * It will trigger re-render if only the selected value is referentially changed.
14
- */
15
- const useContextSelector = (context, selector) => {
16
- const contextValue = React.useContext(context);
17
- const {
18
- value: {
19
- current: value
20
- },
21
- version: {
22
- current: version
23
- },
24
- listeners
25
- } = contextValue;
26
- const selected = selector(value);
27
- const [state, dispatch] = React.useReducer((prevState, payload) => {
28
- if (!payload) {
29
- // early bail out when is dispatched during render
30
- return [value, selected];
31
- }
32
- if (payload[0] <= version) {
33
- if (objectIs(prevState[1], selected)) {
34
- return prevState; // bail out
35
- }
36
-
37
- return [value, selected];
38
- }
39
- try {
40
- if (objectIs(prevState[0], payload[1])) {
41
- return prevState; // do not update
42
- }
43
-
44
- const nextSelected = selector(payload[1]);
45
- if (objectIs(prevState[1], nextSelected)) {
46
- return prevState; // do not update
47
- }
48
-
49
- return [payload[1], nextSelected];
50
- } catch (e) {
51
- // ignored (stale props or some other reason)
5
+ Object.defineProperty(exports, "useContextSelector", {
6
+ enumerable: true,
7
+ get: ()=>useContextSelector
8
+ });
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"));
12
+ const useContextSelector = (context, selector)=>{
13
+ const contextValue = _react.useContext(context);
14
+ const { value: { current: value } , version: { current: version } , listeners } = contextValue;
15
+ const selected = selector(value);
16
+ const [state, dispatch] = _react.useReducer((prevState, payload)=>{
17
+ if (!payload) {
18
+ // early bail out when is dispatched during render
19
+ return [
20
+ value,
21
+ selected
22
+ ];
23
+ }
24
+ if (payload[0] <= version) {
25
+ if (objectIs(prevState[1], selected)) {
26
+ return prevState; // bail out
27
+ }
28
+ return [
29
+ value,
30
+ selected
31
+ ];
32
+ }
33
+ try {
34
+ if (objectIs(prevState[0], payload[1])) {
35
+ return prevState; // do not update
36
+ }
37
+ const nextSelected = selector(payload[1]);
38
+ if (objectIs(prevState[1], nextSelected)) {
39
+ return prevState; // do not update
40
+ }
41
+ return [
42
+ payload[1],
43
+ nextSelected
44
+ ];
45
+ } catch (e) {
46
+ // ignored (stale props or some other reason)
47
+ }
48
+ // explicitly spread to enforce typing
49
+ return [
50
+ prevState[0],
51
+ prevState[1]
52
+ ]; // schedule update
53
+ }, [
54
+ value,
55
+ selected
56
+ ]);
57
+ if (!objectIs(state[1], selected)) {
58
+ // schedule re-render
59
+ // this is safe because it's self contained
60
+ dispatch(undefined);
52
61
  }
53
- // explicitly spread to enforce typing
54
- return [prevState[0], prevState[1]]; // schedule update
55
- }, [value, selected]);
56
- if (!objectIs(state[1], selected)) {
57
- // schedule re-render
58
- // this is safe because it's self contained
59
- dispatch(undefined);
60
- }
61
- react_utilities_1.useIsomorphicLayoutEffect(() => {
62
- listeners.push(dispatch);
63
- return () => {
64
- const index = listeners.indexOf(dispatch);
65
- listeners.splice(index, 1);
66
- };
67
- }, [listeners]);
68
- return state[1];
62
+ (0, _reactUtilities.useIsomorphicLayoutEffect)(()=>{
63
+ listeners.push(dispatch);
64
+ return ()=>{
65
+ const index = listeners.indexOf(dispatch);
66
+ listeners.splice(index, 1);
67
+ };
68
+ }, [
69
+ listeners
70
+ ]);
71
+ return state[1];
69
72
  };
70
- exports.useContextSelector = useContextSelector;
71
73
  /**
72
74
  * inlined Object.is polyfill to avoid requiring consumers ship their own
73
75
  * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
74
- */
75
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
+ */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
77
  function is(x, y) {
77
- return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
78
- ;
78
+ return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
79
+ ;
79
80
  }
80
81
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
- const objectIs =
82
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
82
+ const objectIs = // eslint-disable-next-line @typescript-eslint/ban-ts-comment
83
83
  // @ts-ignore fallback to native if it exists (not in IE11)
84
- typeof Object.is === 'function' ? Object.is : is;
84
+ typeof Object.is === 'function' ? Object.is : is; //# sourceMappingURL=useContextSelector.js.map
85
+
85
86
  //# sourceMappingURL=useContextSelector.js.map
@@ -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":["../src/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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AAC,EAAEE,YAAY,CAAU;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;;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
+ {"version":3,"sources":["../lib/useContextSelector.js"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n/**\n * @internal\n * This hook returns context selected value by selector.\n * It will only accept context created by `createContext`.\n * It will trigger re-render if only the selected value is referentially changed.\n */\nexport const useContextSelector = (context, selector) => {\n const contextValue = React.useContext(context);\n const {\n value: {\n current: value\n },\n version: {\n current: version\n },\n listeners\n } = contextValue;\n const selected = selector(value);\n const [state, dispatch] = React.useReducer((prevState, payload) => {\n if (!payload) {\n // early bail out when is dispatched during render\n return [value, selected];\n }\n if (payload[0] <= version) {\n if (objectIs(prevState[1], selected)) {\n return prevState; // bail out\n }\n\n return [value, selected];\n }\n try {\n if (objectIs(prevState[0], payload[1])) {\n return prevState; // do not update\n }\n\n const nextSelected = selector(payload[1]);\n if (objectIs(prevState[1], nextSelected)) {\n return prevState; // do not update\n }\n\n return [payload[1], nextSelected];\n } catch (e) {\n // ignored (stale props or some other reason)\n }\n // explicitly spread to enforce typing\n return [prevState[0], prevState[1]]; // schedule update\n }, [value, selected]);\n if (!objectIs(state[1], selected)) {\n // schedule re-render\n // this is safe because it's self contained\n dispatch(undefined);\n }\n useIsomorphicLayoutEffect(() => {\n listeners.push(dispatch);\n return () => {\n const index = listeners.indexOf(dispatch);\n listeners.splice(index, 1);\n };\n }, [listeners]);\n return state[1];\n};\n/**\n * inlined Object.is polyfill to avoid requiring consumers ship their own\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n */ // eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction is(x, y) {\n return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare\n ;\n}\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst objectIs =\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore fallback to native if it exists (not in IE11)\ntypeof Object.is === 'function' ? Object.is : is;\n//# sourceMappingURL=useContextSelector.js.map"],"names":["useContextSelector","context","selector","contextValue","React","useContext","value","current","version","listeners","selected","state","dispatch","useReducer","prevState","payload","objectIs","nextSelected","e","undefined","useIsomorphicLayoutEffect","push","index","indexOf","splice","is","x","y","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C,IAAM;QAC9BX,UAAUY,IAAI,CAACT;QACf,OAAO,IAAM;YACX,MAAMU,QAAQb,UAAUc,OAAO,CAACX;YAChCH,UAAUe,MAAM,CAACF,OAAO;QAC1B;IACF,GAAG;QAACb;KAAU;IACd,OAAOE,KAAK,CAAC,EAAE;AACjB;AACA;;;CAGC,GAAG,8DAA8D;AAClE,SAASc,GAAGC,CAAC,EAAEC,CAAC,EAAE;IAChB,OAAOD,MAAMC,KAAMD,CAAAA,MAAM,KAAK,IAAIA,MAAM,IAAIC,CAAAA,KAAMD,MAAMA,KAAKC,MAAMA,EAAE,sCAAsC;;AAE7G;AACA,8DAA8D;AAC9D,MAAMX,WACN,6DAA6D;AAC7D,2DAA2D;AAC3D,OAAOY,OAAOH,EAAE,KAAK,aAAaG,OAAOH,EAAE,GAAGA,EAAE,EAChD,8CAA8C"}
@@ -1,24 +1,19 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useHasParentContext", {
6
+ enumerable: true,
7
+ get: ()=>useHasParentContext
5
8
  });
6
- exports.useHasParentContext = void 0;
7
- const React = /*#__PURE__*/require("react");
8
- /**
9
- * @internal
10
- * Utility hook for contexts created by react-context-selector to determine if a parent context exists
11
- * WARNING: This hook will not work for native React contexts
12
- *
13
- * @param context - context created by react-context-selector
14
- * @returns whether the hook is wrapped by a parent context
15
- */
9
+ const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
10
+ const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
16
11
  function useHasParentContext(context) {
17
- const contextValue = React.useContext(context);
18
- if (contextValue.version) {
19
- return contextValue.version.current !== -1;
20
- }
21
- return false;
22
- }
23
- exports.useHasParentContext = useHasParentContext;
12
+ const contextValue = _react.useContext(context);
13
+ if (contextValue.version) {
14
+ return contextValue.version.current !== -1;
15
+ }
16
+ return false;
17
+ } //# sourceMappingURL=useHasParentContext.js.map
18
+
24
19
  //# sourceMappingURL=useHasParentContext.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","require","useHasParentContext","context","contextValue","useContext","version","current","exports"],"sources":["../src/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"}
1
+ {"version":3,"sources":["../lib/useHasParentContext.js"],"sourcesContent":["import * as React from 'react';\n/**\n * @internal\n * Utility hook for contexts created by react-context-selector to determine if a parent context exists\n * WARNING: This hook will not work for native React contexts\n *\n * @param context - context created by react-context-selector\n * @returns whether the hook is wrapped by a parent context\n */\nexport function useHasParentContext(context) {\n const contextValue = React.useContext(context);\n if (contextValue.version) {\n return contextValue.version.current !== -1;\n }\n return false;\n}\n//# sourceMappingURL=useHasParentContext.js.map"],"names":["useHasParentContext","context","contextValue","React","useContext","version","current"],"mappings":";;;;+BASgBA;;aAAAA;;;6DATO;AAShB,SAASA,oBAAoBC,OAAO,EAAE;IAC3C,MAAMC,eAAeC,OAAMC,UAAU,CAACH;IACtC,IAAIC,aAAaG,OAAO,EAAE;QACxB,OAAOH,aAAaG,OAAO,CAACC,OAAO,KAAK,CAAC;IAC3C,CAAC;IACD,OAAO,KAAK;AACd,EACA,+CAA+C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-context-selector",
3
- "version": "9.1.14",
3
+ "version": "9.1.16",
4
4
  "description": "React useContextSelector hook in userland",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",
@@ -19,7 +19,7 @@
19
19
  "lint": "just-scripts lint",
20
20
  "test": "jest --passWithNoTests",
21
21
  "type-check": "tsc -b tsconfig.json",
22
- "generate-api": "tsc -p ./tsconfig.lib.json --emitDeclarationOnly && just-scripts api-extractor"
22
+ "generate-api": "just-scripts generate-api"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@fluentui/eslint-plugin": "*",
@@ -27,8 +27,8 @@
27
27
  "@fluentui/scripts-tasks": "*"
28
28
  },
29
29
  "dependencies": {
30
- "@fluentui/react-utilities": "^9.7.1",
31
- "tslib": "^2.1.0"
30
+ "@fluentui/react-utilities": "^9.7.3",
31
+ "@swc/helpers": "^0.4.14"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "@types/react": ">=16.8.0 <19.0.0",
@@ -46,6 +46,7 @@
46
46
  "exports": {
47
47
  ".": {
48
48
  "types": "./dist/index.d.ts",
49
+ "node": "./lib-commonjs/index.js",
49
50
  "import": "./lib/index.js",
50
51
  "require": "./lib-commonjs/index.js"
51
52
  },
@@ -1,54 +0,0 @@
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
@@ -1 +0,0 @@
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,EA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AqC,CAAC,QAAQ,CAAC;QAEvD,OAAO,OAAoC,CAAC;IAC9C,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 DELETED
@@ -1,9 +0,0 @@
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
@@ -1 +0,0 @@
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 DELETED
@@ -1,5 +0,0 @@
1
- define(["require", "exports"], function (require, exports) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- });
5
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
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"]}
@@ -1,72 +0,0 @@
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 referentially 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
@@ -1 +0,0 @@
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,CAAC,OAAkD,CAAC,CAAC;QAG/E,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,CAAC,EAAE;oBACpC,OAAO,SAAS,CAAC,CAAC,WAAW;iBAC9B;gBAED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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 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"]}
@@ -1,22 +0,0 @@
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
@@ -1 +0,0 @@
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,CAAC,OAAkD,CAAC,CAAC;QAE1F,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"]}