@fluentui/react-context-selector 0.0.0-nightly-20230317-1454.1 → 0.0.0-nightly-20230321-0440.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.json CHANGED
@@ -2,9 +2,9 @@
2
2
  "name": "@fluentui/react-context-selector",
3
3
  "entries": [
4
4
  {
5
- "date": "Fri, 17 Mar 2023 15:00:14 GMT",
6
- "tag": "@fluentui/react-context-selector_v0.0.0-nightly-20230317-1454.1",
7
- "version": "0.0.0-nightly-20230317-1454.1",
5
+ "date": "Tue, 21 Mar 2023 04:49:55 GMT",
6
+ "tag": "@fluentui/react-context-selector_v0.0.0-nightly-20230321-0440.1",
7
+ "version": "0.0.0-nightly-20230321-0440.1",
8
8
  "comments": {
9
9
  "prerelease": [
10
10
  {
@@ -16,8 +16,8 @@
16
16
  {
17
17
  "author": "beachball",
18
18
  "package": "@fluentui/react-context-selector",
19
- "comment": "Bump @fluentui/react-utilities to v0.0.0-nightly-20230317-1454.1",
20
- "commit": "636275472966fa37b1efc14ac2e70ad32bd39b86"
19
+ "comment": "Bump @fluentui/react-utilities to v0.0.0-nightly-20230321-0440.1",
20
+ "commit": "e913db5700c77cb74564f4422c775d52ef302e91"
21
21
  }
22
22
  ]
23
23
  }
package/CHANGELOG.md CHANGED
@@ -1,18 +1,18 @@
1
1
  # Change Log - @fluentui/react-context-selector
2
2
 
3
- This log was last generated on Fri, 17 Mar 2023 15:00:14 GMT and should not be manually modified.
3
+ This log was last generated on Tue, 21 Mar 2023 04:49:55 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## [0.0.0-nightly-20230317-1454.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v0.0.0-nightly-20230317-1454.1)
7
+ ## [0.0.0-nightly-20230321-0440.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v0.0.0-nightly-20230321-0440.1)
8
8
 
9
- Fri, 17 Mar 2023 15:00:14 GMT
10
- [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.14..@fluentui/react-context-selector_v0.0.0-nightly-20230317-1454.1)
9
+ Tue, 21 Mar 2023 04:49:55 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-context-selector_v9.1.14..@fluentui/react-context-selector_v0.0.0-nightly-20230321-0440.1)
11
11
 
12
12
  ### Changes
13
13
 
14
14
  - Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/not available) by fluentui-internal@service.microsoft.com)
15
- - Bump @fluentui/react-utilities to v0.0.0-nightly-20230317-1454.1 ([commit](https://github.com/microsoft/fluentui/commit/636275472966fa37b1efc14ac2e70ad32bd39b86) by beachball)
15
+ - Bump @fluentui/react-utilities to v0.0.0-nightly-20230321-0440.1 ([commit](https://github.com/microsoft/fluentui/commit/e913db5700c77cb74564f4422c775d52ef302e91) by beachball)
16
16
 
17
17
  ## [9.1.14](https://github.com/microsoft/fluentui/tree/@fluentui/react-context-selector_v9.1.14)
18
18
 
@@ -1,6 +1,6 @@
1
- import { useIsomorphicLayoutEffect } from "@fluentui/react-utilities";
2
- import * as React from "react";
3
- import { unstable_NormalPriority as NormalPriority, unstable_runWithPriority as runWithPriority } from "scheduler";
1
+ import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';
2
+ import * as React from 'react';
3
+ import { unstable_NormalPriority as NormalPriority, unstable_runWithPriority as runWithPriority } from 'scheduler';
4
4
  const createProvider = Original => {
5
5
  const Provider = props => {
6
6
  // Holds an actual "props.value"
@@ -30,8 +30,8 @@ const createProvider = Original => {
30
30
  }, props.children);
31
31
  };
32
32
  /* istanbul ignore else */
33
- if (process.env.NODE_ENV !== "production") {
34
- Provider.displayName = "ContextSelector.Provider";
33
+ if (process.env.NODE_ENV !== 'production') {
34
+ Provider.displayName = 'ContextSelector.Provider';
35
35
  }
36
36
  return Provider;
37
37
  };
@@ -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/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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MC,OAAA,gBAAU3B,KAAA,CAAMyB,aAAa,CAAsB;IACvDd,KAAA,EAAO;MAAEG,OAAA,EAASY;IAAa;IAC/BX,OAAA,EAAS;MAAED,OAAA,EAAS,CAAC;IAAE;IACvBE,SAAA,EAAW;EACb;EAEAW,OAAA,CAAQpB,QAAQ,GAAGF,cAAA,CAAsBsB,OAAA,CAAQpB,QAAQ;EAEzD;EACA,OAAOoB,OAAC,CAAsCC,QAAQ;EAEtD,OAAOD,OAAA;AACT"}
1
+ {"version":3,"names":["useIsomorphicLayoutEffect","React","unstable_NormalPriority","NormalPriority","unstable_runWithPriority","runWithPriority","createProvider","Original","Provider","props","valueRef","useRef","value","versionRef","contextValue","current","version","listeners","forEach","listener","createElement","children","process","env","NODE_ENV","displayName","createContext","defaultValue","context","Consumer"],"sources":["../../../../../../../packages/react-components/react-context-selector/src/createContext.ts"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { unstable_NormalPriority as NormalPriority, unstable_runWithPriority as runWithPriority } from 'scheduler';\n\nimport { Context, ContextValue } from './types';\n\nconst createProvider = <Value>(Original: React.Provider<ContextValue<Value>>) => {\n const Provider: React.FC<React.ProviderProps<Value>> = props => {\n // Holds an actual \"props.value\"\n const valueRef = React.useRef(props.value);\n // Used to sync context updates and avoid stale values, can be considered as render/effect counter of Provider.\n const versionRef = React.useRef(0);\n\n // A stable object, is used to avoid context updates via mutation of its values.\n const contextValue = React.useRef<ContextValue<Value>>();\n\n if (!contextValue.current) {\n contextValue.current = {\n value: valueRef,\n version: versionRef,\n listeners: [],\n };\n }\n\n useIsomorphicLayoutEffect(() => {\n valueRef.current = props.value;\n versionRef.current += 1;\n\n runWithPriority(NormalPriority, () => {\n (contextValue.current as ContextValue<Value>).listeners.forEach(listener => {\n listener([versionRef.current, props.value]);\n });\n });\n }, [props.value]);\n\n return React.createElement(Original, { value: contextValue.current }, props.children);\n };\n\n /* istanbul ignore else */\n if (process.env.NODE_ENV !== 'production') {\n Provider.displayName = 'ContextSelector.Provider';\n }\n\n return Provider as unknown as React.Provider<ContextValue<Value>>;\n};\n\n/**\n * @internal\n */\nexport const createContext = <Value>(defaultValue: Value): Context<Value> => {\n // eslint-disable-next-line @fluentui/no-context-default-value\n const context = React.createContext<ContextValue<Value>>({\n value: { current: defaultValue },\n version: { current: -1 },\n listeners: [],\n });\n\n context.Provider = createProvider<Value>(context.Provider);\n\n // We don't support Consumer API\n delete (context as unknown as Context<Value>).Consumer;\n\n return context as unknown as Context<Value>;\n};\n"],"mappings":"AAAA,SAASA,yBAAyB,QAAQ,2BAA2B;AACrE,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,SAASC,uBAAuB,IAAIC,cAAc,EAAEC,wBAAwB,IAAIC,eAAe,QAAQ,WAAW;AAIlH,MAAMC,cAAc,GAAWC,QAA6C,IAAI;EAC9E,MAAMC,QAAQ,GAAyCC,KAAK,IAAG;IAC7D;IACA,MAAMC,QAAQ,GAAGT,KAAK,CAACU,MAAM,CAACF,KAAK,CAACG,KAAK,CAAC;IAC1C;IACA,MAAMC,UAAU,GAAGZ,KAAK,CAACU,MAAM,CAAC,CAAC,CAAC;IAElC;IACA,MAAMG,YAAY,GAAGb,KAAK,CAACU,MAAM,EAAuB;IAExD,IAAI,CAACG,YAAY,CAACC,OAAO,EAAE;MACzBD,YAAY,CAACC,OAAO,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"}
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { createContext } from "./createContext";
2
- export { useContextSelector } from "./useContextSelector";
3
- export { useHasParentContext } from "./useHasParentContext";
1
+ export { createContext } from './createContext';
2
+ export { useContextSelector } from './useContextSelector';
3
+ export { useHasParentContext } from './useHasParentContext';
4
4
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/react-context-selector/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["export { createContext } from './createContext';\nexport { useContextSelector } from './useContextSelector';\nexport { useHasParentContext } from './useHasParentContext';\n// eslint-disable-next-line @fluentui/ban-context-export\nexport type { Context, ContextSelector, ContextValue, ContextValues, ContextVersion } from './types';\n"]}
package/lib/types.js CHANGED
@@ -1,2 +1,2 @@
1
- import * as React from "react";
1
+ export {};
2
2
  //# sourceMappingURL=types.js.map
package/lib/types.js.map CHANGED
@@ -1 +1 @@
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"}
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,5 +1,5 @@
1
- import { useIsomorphicLayoutEffect } from "@fluentui/react-utilities";
2
- import * as React from "react";
1
+ import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';
2
+ import * as React from 'react';
3
3
  /**
4
4
  * @internal
5
5
  * This hook returns context selected value by selector.
@@ -64,7 +64,8 @@ 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
- */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
+ */
68
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
69
  function is(x, y) {
69
70
  return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
70
71
  ;
@@ -73,5 +74,5 @@ function is(x, y) {
73
74
  const objectIs =
74
75
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
75
76
  // @ts-ignore fallback to native if it exists (not in IE11)
76
- typeof Object.is === "function" ? Object.is : is;
77
+ typeof Object.is === 'function' ? Object.is : is;
77
78
  //# sourceMappingURL=useContextSelector.js.map
@@ -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/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,OAAA,EAAS;MAAED,OAAA,EAASC;IAAO,CAAE;IAC7BC;EAAS,CACV,GAAGL,YAAA;EACJ,MAAMM,QAAA,GAAWP,QAAA,CAASG,KAAA;EAE1B,MAAM,CAACK,KAAA,EAAOC,QAAA,CAAS,GAAGZ,KAAA,CAAMa,UAAU,CACxC,CACEC,SAAA,EACAC,OAAA,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AMC,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
+ {"version":3,"names":["useIsomorphicLayoutEffect","React","useContextSelector","context","selector","contextValue","useContext","value","current","version","listeners","selected","state","dispatch","useReducer","prevState","payload","objectIs","nextSelected","e","undefined","push","index","indexOf","splice","is","x","y","Object"],"sources":["../../../../../../../packages/react-components/react-context-selector/src/useContextSelector.ts"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { Context, ContextSelector, ContextValue, ContextVersion } from './types';\n\n/**\n * Narrowing React.Reducer type to be more easily usable below.\n * No need to export this as it's for internal reducer usage.\n */\ntype ContextReducer<Value, SelectedValue> = React.Reducer<\n readonly [Value, SelectedValue],\n undefined | readonly [ContextVersion, Value]\n>;\n\n/**\n * @internal\n * This hook returns context selected value by selector.\n * It will only accept context created by `createContext`.\n * It will trigger re-render if only the selected value is referentially changed.\n */\nexport const useContextSelector = <Value, SelectedValue>(\n context: Context<Value>,\n selector: ContextSelector<Value, SelectedValue>,\n): SelectedValue => {\n const contextValue = React.useContext(context as unknown as Context<ContextValue<Value>>);\n\n const {\n value: { current: value },\n version: { current: version },\n listeners,\n } = contextValue;\n const selected = selector(value);\n\n const [state, dispatch] = React.useReducer<ContextReducer<Value, SelectedValue>>(\n (\n prevState: readonly [Value /* contextValue */, SelectedValue /* selector(value) */],\n payload:\n | undefined // undefined from render below\n | readonly [ContextVersion, Value], // from provider effect\n ): readonly [Value, SelectedValue] => {\n if (!payload) {\n // early bail out when is dispatched during render\n return [value, selected] as const;\n }\n\n if (payload[0] <= version) {\n if (objectIs(prevState[1], selected)) {\n return prevState; // bail out\n }\n\n return [value, selected] as const;\n }\n\n try {\n if (objectIs(prevState[0], payload[1])) {\n return prevState; // do not update\n }\n\n const nextSelected = selector(payload[1]);\n\n if (objectIs(prevState[1], nextSelected)) {\n return prevState; // do not update\n }\n\n return [payload[1], nextSelected] as const;\n } catch (e) {\n // ignored (stale props or some other reason)\n }\n\n // explicitly spread to enforce typing\n return [prevState[0], prevState[1]] as const; // schedule update\n },\n [value, selected] as const,\n );\n\n if (!objectIs(state[1], selected)) {\n // schedule re-render\n // this is safe because it's self contained\n dispatch(undefined);\n }\n\n useIsomorphicLayoutEffect(() => {\n listeners.push(dispatch);\n\n return () => {\n const index = listeners.indexOf(dispatch);\n listeners.splice(index, 1);\n };\n }, [listeners]);\n\n return state[1] as SelectedValue;\n};\n\n/**\n * inlined Object.is polyfill to avoid requiring consumers ship their own\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction is(x: any, y: any) {\n return (\n (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst objectIs: (x: any, y: any) => boolean =\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore fallback to native if it exists (not in IE11)\n typeof Object.is === 'function' ? Object.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;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S,CAACW,IAAI,CAACR,QAAQ,CAAC;IAExB,OAAO,MAAK;MACV,MAAMS,KAAK,GAAGZ,SAAS,CAACa,OAAO,CAACV,QAAQ,CAAC;MACzCH,SAAS,CAACc,MAAM,CAACF,KAAK,EAAE,CAAC,CAAC;IAC5B,CAAC;EACH,CAAC,EAAE,CAACZ,SAAS,CAAC,CAAC;EAEf,OAAOE,KAAK,CAAC,CAAC,CAAkB;AAClC,CAAC;AAED;;;;AAIA;AACA,SAASa,EAAEA,CAACC,CAAM,EAAEC,CAAM;EACxB,OACGD,CAAC,KAAKC,CAAC,KAAKD,CAAC,KAAK,CAAC,IAAI,CAAC,GAAGA,CAAC,KAAK,CAAC,GAAGC,CAAC,CAAC,IAAMD,CAAC,KAAKA,CAAC,IAAIC,CAAC,KAAKA,CAAE,CAAC;EAAA;AAEtE;AAEA;AACA,MAAMV,QAAQ;AACZ;AACA;AACA,OAAOW,MAAM,CAACH,EAAE,KAAK,UAAU,GAAGG,MAAM,CAACH,EAAE,GAAGA,EAAE"}
@@ -1,4 +1,4 @@
1
- import * as React from "react";
1
+ import * as React from 'react';
2
2
  /**
3
3
  * @internal
4
4
  * Utility hook for contexts created by react-context-selector to determine if a parent context exists
@@ -1 +1 @@
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
+ {"version":3,"names":["React","useHasParentContext","context","contextValue","useContext","version","current"],"sources":["../../../../../../../packages/react-components/react-context-selector/src/useHasParentContext.ts"],"sourcesContent":["import * as React from 'react';\nimport { Context, ContextValue } from './types';\n\n/**\n * @internal\n * Utility hook for contexts created by react-context-selector to determine if a parent context exists\n * WARNING: This hook will not work for native React contexts\n *\n * @param context - context created by react-context-selector\n * @returns whether the hook is wrapped by a parent context\n */\nexport function useHasParentContext<Value>(context: Context<Value>) {\n const contextValue = React.useContext(context as unknown as Context<ContextValue<Value>>);\n\n if (contextValue.version) {\n return contextValue.version.current !== -1;\n }\n\n return false;\n}\n"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAG9B;;;;;;;;AAQA,OAAM,SAAUC,mBAAmBA,CAAQC,OAAuB;EAChE,MAAMC,YAAY,GAAGH,KAAK,CAACI,UAAU,CAACF,OAAkD,CAAC;EAEzF,IAAIC,YAAY,CAACE,OAAO,EAAE;IACxB,OAAOF,YAAY,CAACE,OAAO,CAACC,OAAO,KAAK,CAAC,CAAC;;EAG5C,OAAO,KAAK;AACd"}
@@ -1,68 +1,64 @@
1
1
  "use strict";
2
+
2
3
  Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "createContext", {
6
- enumerable: true,
7
- get: ()=>createContext
4
+ value: true
8
5
  });
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";
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
+ };
48
24
  }
49
- return Provider;
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;
50
43
  };
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
-
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;
68
64
  //# sourceMappingURL=createContext.js.map
@@ -1 +1 @@
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
+ {"version":3,"names":["react_utilities_1","require","React","scheduler_1","createProvider","Original","Provider","props","valueRef","useRef","value","versionRef","contextValue","current","version","listeners","useIsomorphicLayoutEffect","unstable_runWithPriority","unstable_NormalPriority","forEach","listener","createElement","children","process","env","NODE_ENV","displayName","createContext","defaultValue","context","Consumer","exports"],"sources":["../../../../../../../packages/react-components/react-context-selector/src/createContext.ts"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { unstable_NormalPriority as NormalPriority, unstable_runWithPriority as runWithPriority } from 'scheduler';\n\nimport { Context, ContextValue } from './types';\n\nconst createProvider = <Value>(Original: React.Provider<ContextValue<Value>>) => {\n const Provider: React.FC<React.ProviderProps<Value>> = props => {\n // Holds an actual \"props.value\"\n const valueRef = React.useRef(props.value);\n // Used to sync context updates and avoid stale values, can be considered as render/effect counter of Provider.\n const versionRef = React.useRef(0);\n\n // A stable object, is used to avoid context updates via mutation of its values.\n const contextValue = React.useRef<ContextValue<Value>>();\n\n if (!contextValue.current) {\n contextValue.current = {\n value: valueRef,\n version: versionRef,\n listeners: [],\n };\n }\n\n useIsomorphicLayoutEffect(() => {\n valueRef.current = props.value;\n versionRef.current += 1;\n\n runWithPriority(NormalPriority, () => {\n (contextValue.current as ContextValue<Value>).listeners.forEach(listener => {\n listener([versionRef.current, props.value]);\n });\n });\n }, [props.value]);\n\n return React.createElement(Original, { value: contextValue.current }, props.children);\n };\n\n /* istanbul ignore else */\n if (process.env.NODE_ENV !== 'production') {\n Provider.displayName = 'ContextSelector.Provider';\n }\n\n return Provider as unknown as React.Provider<ContextValue<Value>>;\n};\n\n/**\n * @internal\n */\nexport const createContext = <Value>(defaultValue: Value): Context<Value> => {\n // eslint-disable-next-line @fluentui/no-context-default-value\n const context = React.createContext<ContextValue<Value>>({\n value: { current: defaultValue },\n version: { current: -1 },\n listeners: [],\n });\n\n context.Provider = createProvider<Value>(context.Provider);\n\n // We don't support Consumer API\n delete (context as unknown as Context<Value>).Consumer;\n\n return context as unknown as Context<Value>;\n};\n"],"mappings":";;;;;;AAAA,MAAAA,iBAAA,gBAAAC,OAAA;AACA,MAAAC,KAAA,gBAAAD,OAAA;AACA,MAAAE,WAAA,gBAAAF,OAAA;AAIA,MAAMG,cAAc,GAAWC,QAA6C,IAAI;EAC9E,MAAMC,QAAQ,GAAyCC,KAAK,IAAG;IAC7D;IACA,MAAMC,QAAQ,GAAGN,KAAK,CAACO,MAAM,CAACF,KAAK,CAACG,KAAK,CAAC;IAC1C;IACA,MAAMC,UAAU,GAAGT,KAAK,CAACO,MAAM,CAAC,CAAC,CAAC;IAElC;IACA,MAAMG,YAAY,GAAGV,KAAK,CAACO,MAAM,EAAuB;IAExD,IAAI,CAACG,YAAY,CAACC,OAAO,EAAE;MACzBD,YAAY,CAACC,OAAO,GAAG;QACrBH,KAAK,EAAEF,QAAQ;QACfM,OAAO,EAAEH,U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
  "use strict";
2
+
2
3
  Object.defineProperty(exports, "__esModule", {
3
- value: true
4
+ value: true
4
5
  });
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
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
+ }
13
+ });
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
+ }
15
27
  });
16
- const _createContext = require("./createContext");
17
- const _useContextSelector = require("./useContextSelector");
18
- const _useHasParentContext = require("./useHasParentContext");
19
- //# sourceMappingURL=index.js.map
20
-
21
28
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
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
+ {"version":3,"names":["createContext_1","require","Object","defineProperty","exports","enumerable","get","createContext","useContextSelector_1","useContextSelector","useHasParentContext_1","useHasParentContext"],"sources":["../../../../../../../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,9 +1,6 @@
1
1
  "use strict";
2
+
2
3
  Object.defineProperty(exports, "__esModule", {
3
- value: true
4
+ value: true
4
5
  });
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
-
9
6
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../lib/types.js"],"sourcesContent":["import * as React from \"react\";\n//# sourceMappingURL=types.js.map"],"names":[],"mappings":";;;;;6DAAuB;CACvB,iCAAiC"}
1
+ {"version":3,"names":[],"sources":["../../../../../../../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,86 +1,85 @@
1
1
  "use strict";
2
+
2
3
  Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "useContextSelector", {
6
- enumerable: true,
7
- get: ()=>useContextSelector
4
+ value: true
8
5
  });
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);
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];
61
38
  }
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];
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)
52
+ }
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];
72
69
  };
70
+ exports.useContextSelector = useContextSelector;
73
71
  /**
74
72
  * inlined Object.is polyfill to avoid requiring consumers ship their own
75
73
  * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
76
- */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
74
+ */
75
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
77
76
  function is(x, y) {
78
- return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
79
- ;
77
+ return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
78
+ ;
80
79
  }
81
80
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
- const objectIs = // eslint-disable-next-line @typescript-eslint/ban-ts-comment
81
+ const objectIs =
82
+ // 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; //# sourceMappingURL=useContextSelector.js.map
85
-
84
+ typeof Object.is === 'function' ? Object.is : is;
86
85
  //# sourceMappingURL=useContextSelector.js.map
@@ -1 +1 @@
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","Object"],"mappings":";;;;+BAQaA;;aAAAA;;;gCAR6B;6DACnB;AAOhB,MAAMA,qBAAqB,CAACC,SAASC,WAAa;IACvD,MAAMC,eAAeC,OAAMC,UAAU,CAACJ;IACtC,MAA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;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
+ {"version":3,"names":["react_utilities_1","require","React","useContextSelector","context","selector","contextValue","useContext","value","current","version","listeners","selected","state","dispatch","useReducer","prevState","payload","objectIs","nextSelected","e","undefined","useIsomorphicLayoutEffect","push","index","indexOf","splice","exports","is","x","y","Object"],"sources":["../../../../../../../packages/react-components/react-context-selector/src/useContextSelector.ts"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { Context, ContextSelector, ContextValue, ContextVersion } from './types';\n\n/**\n * Narrowing React.Reducer type to be more easily usable below.\n * No need to export this as it's for internal reducer usage.\n */\ntype ContextReducer<Value, SelectedValue> = React.Reducer<\n readonly [Value, SelectedValue],\n undefined | readonly [ContextVersion, Value]\n>;\n\n/**\n * @internal\n * This hook returns context selected value by selector.\n * It will only accept context created by `createContext`.\n * It will trigger re-render if only the selected value is referentially changed.\n */\nexport const useContextSelector = <Value, SelectedValue>(\n context: Context<Value>,\n selector: ContextSelector<Value, SelectedValue>,\n): SelectedValue => {\n const contextValue = React.useContext(context as unknown as Context<ContextValue<Value>>);\n\n const {\n value: { current: value },\n version: { current: version },\n listeners,\n } = contextValue;\n const selected = selector(value);\n\n const [state, dispatch] = React.useReducer<ContextReducer<Value, SelectedValue>>(\n (\n prevState: readonly [Value /* contextValue */, SelectedValue /* selector(value) */],\n payload:\n | undefined // undefined from render below\n | readonly [ContextVersion, Value], // from provider effect\n ): readonly [Value, SelectedValue] => {\n if (!payload) {\n // early bail out when is dispatched during render\n return [value, selected] as const;\n }\n\n if (payload[0] <= version) {\n if (objectIs(prevState[1], selected)) {\n return prevState; // bail out\n }\n\n return [value, selected] as const;\n }\n\n try {\n if (objectIs(prevState[0], payload[1])) {\n return prevState; // do not update\n }\n\n const nextSelected = selector(payload[1]);\n\n if (objectIs(prevState[1], nextSelected)) {\n return prevState; // do not update\n }\n\n return [payload[1], nextSelected] as const;\n } catch (e) {\n // ignored (stale props or some other reason)\n }\n\n // explicitly spread to enforce typing\n return [prevState[0], prevState[1]] as const; // schedule update\n },\n [value, selected] as const,\n );\n\n if (!objectIs(state[1], selected)) {\n // schedule re-render\n // this is safe because it's self contained\n dispatch(undefined);\n }\n\n useIsomorphicLayoutEffect(() => {\n listeners.push(dispatch);\n\n return () => {\n const index = listeners.indexOf(dispatch);\n listeners.splice(index, 1);\n };\n }, [listeners]);\n\n return state[1] as SelectedValue;\n};\n\n/**\n * inlined Object.is polyfill to avoid requiring consumers ship their own\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction is(x: any, y: any) {\n return (\n (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y) // eslint-disable-line no-self-compare\n );\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst objectIs: (x: any, y: any) => boolean =\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore fallback to native if it exists (not in IE11)\n typeof Object.is === 'function' ? Object.is : is;\n"],"mappings":";;;;;;AAAA,MAAAA,iBAAA,gBAAAC,OAAA;AACA,MAAAC,KAAA,gBAAAD,OAAA;AAaA;;;;;;AAMO,MAAME,kBAAkB,GAAGA,CAChCC,OAAuB,EACvBC,QAA+C,KAC9B;EACjB,MAAMC,YAAY,GAAGJ,KAAK,CAACK,UAAU,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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,19 +1,24 @@
1
1
  "use strict";
2
+
2
3
  Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "useHasParentContext", {
6
- enumerable: true,
7
- get: ()=>useHasParentContext
4
+ value: true
8
5
  });
9
- const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
10
- const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
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
+ */
11
16
  function useHasParentContext(context) {
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
-
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;
19
24
  //# sourceMappingURL=useHasParentContext.js.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"names":["React","require","useHasParentContext","context","contextValue","useContext","version","current","exports"],"sources":["../../../../../../../packages/react-components/react-context-selector/src/useHasParentContext.ts"],"sourcesContent":["import * as React from 'react';\nimport { Context, ContextValue } from './types';\n\n/**\n * @internal\n * Utility hook for contexts created by react-context-selector to determine if a parent context exists\n * WARNING: This hook will not work for native React contexts\n *\n * @param context - context created by react-context-selector\n * @returns whether the hook is wrapped by a parent context\n */\nexport function useHasParentContext<Value>(context: Context<Value>) {\n const contextValue = React.useContext(context as unknown as Context<ContextValue<Value>>);\n\n if (contextValue.version) {\n return contextValue.version.current !== -1;\n }\n\n return false;\n}\n"],"mappings":";;;;;;AAAA,MAAAA,KAAA,gBAAAC,OAAA;AAGA;;;;;;;;AAQA,SAAgBC,mBAAmBA,CAAQC,OAAuB;EAChE,MAAMC,YAAY,GAAGJ,KAAK,CAACK,UAAU,CAACF,OAAkD,CAAC;EAEzF,IAAIC,YAAY,CAACE,OAAO,EAAE;IACxB,OAAOF,YAAY,CAACE,OAAO,CAACC,OAAO,KAAK,CAAC,CAAC;;EAG5C,OAAO,KAAK;AACd;AARAC,OAAA,CAAAN,mBAAA,GAAAA,mBAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-context-selector",
3
- "version": "0.0.0-nightly-20230317-1454.1",
3
+ "version": "0.0.0-nightly-20230321-0440.1",
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": "just-scripts generate-api"
22
+ "generate-api": "tsc -p ./tsconfig.lib.json --emitDeclarationOnly && just-scripts api-extractor"
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": "0.0.0-nightly-20230317-1454.1",
31
- "@swc/helpers": "^0.4.14"
30
+ "@fluentui/react-utilities": "0.0.0-nightly-20230321-0440.1",
31
+ "tslib": "^2.1.0"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "@types/react": ">=16.8.0 <19.0.0",
@@ -41,6 +41,7 @@
41
41
  "exports": {
42
42
  ".": {
43
43
  "types": "./dist/index.d.ts",
44
+ "node": "./lib-commonjs/index.js",
44
45
  "import": "./lib/index.js",
45
46
  "require": "./lib-commonjs/index.js"
46
47
  },
package/.swcrc DELETED
@@ -1,39 +0,0 @@
1
- {
2
- "$schema": "https://json.schemastore.org/swcrc",
3
- "env": {
4
- "targets": {
5
- "chrome": "84",
6
- "edge": "84",
7
- "firefox": "75",
8
- "opera": "73",
9
- "safari": "14.1"
10
- },
11
- "bugfixes": true
12
- },
13
- "exclude": [
14
- "/testing",
15
- "/**/*.cy.ts",
16
- "/**/*.cy.tsx",
17
- "/**/*.spec.ts",
18
- "/**/*.spec.tsx",
19
- "/**/*.test.ts",
20
- "/**/*.test.tsx"
21
- ],
22
- "jsc": {
23
- "parser": {
24
- "syntax": "typescript",
25
- "tsx": true,
26
- "decorators": false,
27
- "dynamicImport": false
28
- },
29
- "externalHelpers": true,
30
- "transform": {
31
- "react": {
32
- "runtime": "classic",
33
- "useSpread": true
34
- }
35
- }
36
- },
37
- "minify": false,
38
- "sourceMaps": true
39
- }