@fluentui/react-utilities 9.18.16 → 9.18.18
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.md +23 -2
- package/dist/index.d.ts +1 -2
- package/lib/compose/assertSlots.js.map +1 -1
- package/lib/compose/constants.js.map +1 -1
- package/lib/compose/deprecated/getSlots.js.map +1 -1
- package/lib/compose/deprecated/getSlotsNext.js.map +1 -1
- package/lib/compose/deprecated/resolveShorthand.js.map +1 -1
- package/lib/compose/getIntrinsicElementProps.js.map +1 -1
- package/lib/compose/index.js +11 -9
- package/lib/compose/index.js.map +1 -1
- package/lib/compose/isResolvedShorthand.js +2 -2
- package/lib/compose/isResolvedShorthand.js.map +1 -1
- package/lib/compose/isSlot.js.map +1 -1
- package/lib/compose/slot.js.map +1 -1
- package/lib/compose/types.js.map +1 -1
- package/lib/events/index.js +1 -1
- package/lib/events/index.js.map +1 -1
- package/lib/events/mouseTouchHelpers.js.map +1 -1
- package/lib/hooks/index.js +13 -13
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useAnimationFrame.js.map +1 -1
- package/lib/hooks/useBrowserTimer.js.map +1 -1
- package/lib/hooks/useControllableState.js.map +1 -1
- package/lib/hooks/useEventCallback.js.map +1 -1
- package/lib/hooks/useFirstMount.js.map +1 -1
- package/lib/hooks/useForceUpdate.js +2 -2
- package/lib/hooks/useForceUpdate.js.map +1 -1
- package/lib/hooks/useId.js.map +1 -1
- package/lib/hooks/useIsomorphicLayoutEffect.js.map +1 -1
- package/lib/hooks/useMergedRefs.js.map +1 -1
- package/lib/hooks/useOnClickOutside.js.map +1 -1
- package/lib/hooks/useOnScrollOutside.js.map +1 -1
- package/lib/hooks/usePrevious.js.map +1 -1
- package/lib/hooks/useScrollbarWidth.js.map +1 -1
- package/lib/hooks/useTimeout.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/selection/index.js +1 -2
- package/lib/selection/index.js.map +1 -1
- package/lib/selection/types.js.map +1 -1
- package/lib/selection/useSelection.js.map +1 -1
- package/lib/ssr/SSRContext.js.map +1 -1
- package/lib/ssr/canUseDOM.js.map +1 -1
- package/lib/ssr/index.js +2 -2
- package/lib/ssr/index.js.map +1 -1
- package/lib/trigger/applyTriggerPropsToChildren.js.map +1 -1
- package/lib/trigger/getTriggerChild.js.map +1 -1
- package/lib/trigger/index.js +3 -4
- package/lib/trigger/index.js.map +1 -1
- package/lib/trigger/isFluentTrigger.js.map +1 -1
- package/lib/trigger/types.js.map +1 -1
- package/lib/utils/clamp.js.map +1 -1
- package/lib/utils/createSetFromIterable.js.map +1 -1
- package/lib/utils/getNativeElementProps.js.map +1 -1
- package/lib/utils/getRTLSafeKey.js.map +1 -1
- package/lib/utils/getReactCallbackName.js.map +1 -1
- package/lib/utils/index.js +10 -9
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/isHTMLElement.js.map +1 -1
- package/lib/utils/isInteractiveHTMLElement.js.map +1 -1
- package/lib/utils/mergeCallbacks.js.map +1 -1
- package/lib/utils/omit.js.map +1 -1
- package/lib/utils/priorityQueue.js.map +1 -1
- package/lib/utils/properties.js.map +1 -1
- package/lib/utils/types.js.map +1 -1
- package/lib/virtualParent/elementContains.js.map +1 -1
- package/lib/virtualParent/getParent.js.map +1 -1
- package/lib/virtualParent/index.js +3 -3
- package/lib/virtualParent/index.js.map +1 -1
- package/lib/virtualParent/isVirtualElement.js.map +1 -1
- package/lib/virtualParent/setVirtualParent.js.map +1 -1
- package/lib/virtualParent/types.js.map +1 -1
- package/lib-commonjs/compose/assertSlots.js.map +1 -1
- package/lib-commonjs/compose/constants.js.map +1 -1
- package/lib-commonjs/compose/deprecated/getSlots.js.map +1 -1
- package/lib-commonjs/compose/deprecated/getSlotsNext.js.map +1 -1
- package/lib-commonjs/compose/deprecated/resolveShorthand.js.map +1 -1
- package/lib-commonjs/compose/getIntrinsicElementProps.js.map +1 -1
- package/lib-commonjs/compose/index.js +43 -13
- package/lib-commonjs/compose/index.js.map +1 -1
- package/lib-commonjs/compose/isResolvedShorthand.js +3 -2
- package/lib-commonjs/compose/isResolvedShorthand.js.map +1 -1
- package/lib-commonjs/compose/isSlot.js.map +1 -1
- package/lib-commonjs/compose/slot.js +1 -1
- package/lib-commonjs/compose/slot.js.map +1 -1
- package/lib-commonjs/compose/types.js.map +1 -1
- package/lib-commonjs/events/index.js +18 -2
- package/lib-commonjs/events/index.js.map +1 -1
- package/lib-commonjs/events/mouseTouchHelpers.js.map +1 -1
- package/lib-commonjs/hooks/index.js +66 -14
- package/lib-commonjs/hooks/index.js.map +1 -1
- package/lib-commonjs/hooks/useAnimationFrame.js.map +1 -1
- package/lib-commonjs/hooks/useBrowserTimer.js.map +1 -1
- package/lib-commonjs/hooks/useControllableState.js.map +1 -1
- package/lib-commonjs/hooks/useEventCallback.js.map +1 -1
- package/lib-commonjs/hooks/useFirstMount.js.map +1 -1
- package/lib-commonjs/hooks/useForceUpdate.js +3 -2
- package/lib-commonjs/hooks/useForceUpdate.js.map +1 -1
- package/lib-commonjs/hooks/useId.js +1 -1
- package/lib-commonjs/hooks/useId.js.map +1 -1
- package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js.map +1 -1
- package/lib-commonjs/hooks/useMergedRefs.js +2 -1
- package/lib-commonjs/hooks/useMergedRefs.js.map +1 -1
- package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -1
- package/lib-commonjs/hooks/useOnScrollOutside.js.map +1 -1
- package/lib-commonjs/hooks/usePrevious.js.map +1 -1
- package/lib-commonjs/hooks/useScrollbarWidth.js.map +1 -1
- package/lib-commonjs/hooks/useTimeout.js.map +1 -1
- package/lib-commonjs/index.js +4 -0
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/selection/index.js +7 -3
- package/lib-commonjs/selection/index.js.map +1 -1
- package/lib-commonjs/selection/types.js.map +1 -1
- package/lib-commonjs/selection/useSelection.js.map +1 -1
- package/lib-commonjs/ssr/SSRContext.js.map +1 -1
- package/lib-commonjs/ssr/canUseDOM.js.map +1 -1
- package/lib-commonjs/ssr/index.js +28 -3
- package/lib-commonjs/ssr/index.js.map +1 -1
- package/lib-commonjs/trigger/applyTriggerPropsToChildren.js +3 -3
- package/lib-commonjs/trigger/applyTriggerPropsToChildren.js.map +1 -1
- package/lib-commonjs/trigger/getTriggerChild.js +3 -2
- package/lib-commonjs/trigger/getTriggerChild.js.map +1 -1
- package/lib-commonjs/trigger/index.js +20 -5
- package/lib-commonjs/trigger/index.js.map +1 -1
- package/lib-commonjs/trigger/isFluentTrigger.js.map +1 -1
- package/lib-commonjs/trigger/types.js.map +1 -1
- package/lib-commonjs/utils/clamp.js.map +1 -1
- package/lib-commonjs/utils/createSetFromIterable.js.map +1 -1
- package/lib-commonjs/utils/getNativeElementProps.js.map +1 -1
- package/lib-commonjs/utils/getRTLSafeKey.js.map +1 -1
- package/lib-commonjs/utils/getReactCallbackName.js.map +1 -1
- package/lib-commonjs/utils/index.js +132 -10
- package/lib-commonjs/utils/index.js.map +1 -1
- package/lib-commonjs/utils/isHTMLElement.js.map +1 -1
- package/lib-commonjs/utils/isInteractiveHTMLElement.js.map +1 -1
- package/lib-commonjs/utils/mergeCallbacks.js.map +1 -1
- package/lib-commonjs/utils/omit.js.map +1 -1
- package/lib-commonjs/utils/priorityQueue.js +0 -4
- package/lib-commonjs/utils/priorityQueue.js.map +1 -1
- package/lib-commonjs/utils/properties.js +2 -1
- package/lib-commonjs/utils/properties.js.map +1 -1
- package/lib-commonjs/utils/types.js +1 -4
- package/lib-commonjs/utils/types.js.map +1 -1
- package/lib-commonjs/virtualParent/elementContains.js.map +1 -1
- package/lib-commonjs/virtualParent/getParent.js.map +1 -1
- package/lib-commonjs/virtualParent/index.js +20 -4
- package/lib-commonjs/virtualParent/index.js.map +1 -1
- package/lib-commonjs/virtualParent/isVirtualElement.js +1 -4
- package/lib-commonjs/virtualParent/isVirtualElement.js.map +1 -1
- package/lib-commonjs/virtualParent/setVirtualParent.js +1 -7
- package/lib-commonjs/virtualParent/setVirtualParent.js.map +1 -1
- package/lib-commonjs/virtualParent/types.js.map +1 -1
- package/package.json +3 -18
@@ -2,17 +2,69 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
3
3
|
value: true
|
4
4
|
});
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
+
IdPrefixProvider: function() {
|
13
|
+
return _useId.IdPrefixProvider;
|
14
|
+
},
|
15
|
+
resetIdsForTests: function() {
|
16
|
+
return _useId.resetIdsForTests;
|
17
|
+
},
|
18
|
+
useAnimationFrame: function() {
|
19
|
+
return _useAnimationFrame.useAnimationFrame;
|
20
|
+
},
|
21
|
+
useControllableState: function() {
|
22
|
+
return _useControllableState.useControllableState;
|
23
|
+
},
|
24
|
+
useEventCallback: function() {
|
25
|
+
return _useEventCallback.useEventCallback;
|
26
|
+
},
|
27
|
+
useFirstMount: function() {
|
28
|
+
return _useFirstMount.useFirstMount;
|
29
|
+
},
|
30
|
+
useForceUpdate: function() {
|
31
|
+
return _useForceUpdate.useForceUpdate;
|
32
|
+
},
|
33
|
+
useId: function() {
|
34
|
+
return _useId.useId;
|
35
|
+
},
|
36
|
+
useIsomorphicLayoutEffect: function() {
|
37
|
+
return _useIsomorphicLayoutEffect.useIsomorphicLayoutEffect;
|
38
|
+
},
|
39
|
+
useMergedRefs: function() {
|
40
|
+
return _useMergedRefs.useMergedRefs;
|
41
|
+
},
|
42
|
+
useOnClickOutside: function() {
|
43
|
+
return _useOnClickOutside.useOnClickOutside;
|
44
|
+
},
|
45
|
+
useOnScrollOutside: function() {
|
46
|
+
return _useOnScrollOutside.useOnScrollOutside;
|
47
|
+
},
|
48
|
+
usePrevious: function() {
|
49
|
+
return _usePrevious.usePrevious;
|
50
|
+
},
|
51
|
+
useScrollbarWidth: function() {
|
52
|
+
return _useScrollbarWidth.useScrollbarWidth;
|
53
|
+
},
|
54
|
+
useTimeout: function() {
|
55
|
+
return _useTimeout.useTimeout;
|
56
|
+
}
|
57
|
+
});
|
58
|
+
const _useAnimationFrame = require("./useAnimationFrame");
|
59
|
+
const _useControllableState = require("./useControllableState");
|
60
|
+
const _useEventCallback = require("./useEventCallback");
|
61
|
+
const _useFirstMount = require("./useFirstMount");
|
62
|
+
const _useForceUpdate = require("./useForceUpdate");
|
63
|
+
const _useId = require("./useId");
|
64
|
+
const _useIsomorphicLayoutEffect = require("./useIsomorphicLayoutEffect");
|
65
|
+
const _useMergedRefs = require("./useMergedRefs");
|
66
|
+
const _useOnClickOutside = require("./useOnClickOutside");
|
67
|
+
const _useOnScrollOutside = require("./useOnScrollOutside");
|
68
|
+
const _usePrevious = require("./usePrevious");
|
69
|
+
const _useScrollbarWidth = require("./useScrollbarWidth");
|
70
|
+
const _useTimeout = require("./useTimeout");
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["index.ts"],"sourcesContent":["export
|
1
|
+
{"version":3,"sources":["../src/hooks/index.ts"],"sourcesContent":["export { useAnimationFrame } from './useAnimationFrame';\nexport type { UseControllableStateOptions } from './useControllableState';\nexport { useControllableState } from './useControllableState';\nexport { useEventCallback } from './useEventCallback';\nexport { useFirstMount } from './useFirstMount';\nexport { useForceUpdate } from './useForceUpdate';\nexport { IdPrefixProvider, resetIdsForTests, useId } from './useId';\nexport { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';\nexport type { RefObjectFunction } from './useMergedRefs';\nexport { useMergedRefs } from './useMergedRefs';\nexport type { UseOnClickOrScrollOutsideOptions } from './useOnClickOutside';\nexport { useOnClickOutside } from './useOnClickOutside';\nexport { useOnScrollOutside } from './useOnScrollOutside';\nexport { usePrevious } from './usePrevious';\nexport { useScrollbarWidth } from './useScrollbarWidth';\nexport { useTimeout } from './useTimeout';\n"],"names":["IdPrefixProvider","resetIdsForTests","useAnimationFrame","useControllableState","useEventCallback","useFirstMount","useForceUpdate","useId","useIsomorphicLayoutEffect","useMergedRefs","useOnClickOutside","useOnScrollOutside","usePrevious","useScrollbarWidth","useTimeout"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAMSA,gBAAgB;eAAhBA,uBAAgB;;IAAEC,gBAAgB;eAAhBA,uBAAgB;;IANlCC,iBAAiB;eAAjBA,oCAAiB;;IAEjBC,oBAAoB;eAApBA,0CAAoB;;IACpBC,gBAAgB;eAAhBA,kCAAgB;;IAChBC,aAAa;eAAbA,4BAAa;;IACbC,cAAc;eAAdA,8BAAc;;IACsBC,KAAK;eAALA,YAAK;;IACzCC,yBAAyB;eAAzBA,oDAAyB;;IAEzBC,aAAa;eAAbA,4BAAa;;IAEbC,iBAAiB;eAAjBA,oCAAiB;;IACjBC,kBAAkB;eAAlBA,sCAAkB;;IAClBC,WAAW;eAAXA,wBAAW;;IACXC,iBAAiB;eAAjBA,oCAAiB;;IACjBC,UAAU;eAAVA,sBAAU;;;mCAfe;sCAEG;kCACJ;+BACH;gCACC;uBAC2B;2CAChB;+BAEZ;mCAEI;oCACC;6BACP;mCACM;4BACP"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useAnimationFrame.ts"],"sourcesContent":["import { useBrowserTimer } from './useBrowserTimer';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nconst setAnimationFrameNoop = (callback: FrameRequestCallback) => {\n callback(0);\n return 0;\n};\nconst cancelAnimationFrameNoop = (handle: number) => handle;\n\n/**\n * @internal\n * Helper to manage a browser requestAnimationFrame.\n * Ensures that the requestAnimationFrame isn't set multiple times at once and is cleaned up\n * when the component is unloaded.\n *\n * @returns A pair of [requestAnimationFrame, cancelAnimationFrame] that are stable between renders.\n */\nexport function useAnimationFrame() {\n const { targetDocument } = useFluent();\n const win = targetDocument?.defaultView;\n\n const setAnimationFrame = win ? win.requestAnimationFrame : setAnimationFrameNoop;\n const clearAnimationFrame = win ? win.cancelAnimationFrame : cancelAnimationFrameNoop;\n\n return useBrowserTimer(setAnimationFrame, clearAnimationFrame);\n}\n"],"names":["useAnimationFrame","setAnimationFrameNoop","callback","cancelAnimationFrameNoop","handle","targetDocument","useFluent","win","defaultView","setAnimationFrame","requestAnimationFrame","clearAnimationFrame","cancelAnimationFrame","useBrowserTimer"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAiBgBA;;;eAAAA;;;iCAjBgB;qCACgB;AAEhD,MAAMC,wBAAwB,CAACC;IAC7BA,SAAS;IACT,OAAO;AACT;AACA,MAAMC,2BAA2B,CAACC,SAAmBA;AAU9C,SAASJ;IACd,MAAM,EAAEK,cAAc,EAAE,GAAGC,IAAAA,
|
1
|
+
{"version":3,"sources":["../src/hooks/useAnimationFrame.ts"],"sourcesContent":["import { useBrowserTimer } from './useBrowserTimer';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nconst setAnimationFrameNoop = (callback: FrameRequestCallback) => {\n callback(0);\n return 0;\n};\nconst cancelAnimationFrameNoop = (handle: number) => handle;\n\n/**\n * @internal\n * Helper to manage a browser requestAnimationFrame.\n * Ensures that the requestAnimationFrame isn't set multiple times at once and is cleaned up\n * when the component is unloaded.\n *\n * @returns A pair of [requestAnimationFrame, cancelAnimationFrame] that are stable between renders.\n */\nexport function useAnimationFrame() {\n const { targetDocument } = useFluent();\n const win = targetDocument?.defaultView;\n\n const setAnimationFrame = win ? win.requestAnimationFrame : setAnimationFrameNoop;\n const clearAnimationFrame = win ? win.cancelAnimationFrame : cancelAnimationFrameNoop;\n\n return useBrowserTimer(setAnimationFrame, clearAnimationFrame);\n}\n"],"names":["useAnimationFrame","setAnimationFrameNoop","callback","cancelAnimationFrameNoop","handle","targetDocument","useFluent","win","defaultView","setAnimationFrame","requestAnimationFrame","clearAnimationFrame","cancelAnimationFrame","useBrowserTimer"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAiBgBA;;;eAAAA;;;iCAjBgB;qCACgB;AAEhD,MAAMC,wBAAwB,CAACC;IAC7BA,SAAS;IACT,OAAO;AACT;AACA,MAAMC,2BAA2B,CAACC,SAAmBA;AAU9C,SAASJ;IACd,MAAM,EAAEK,cAAc,EAAE,GAAGC,IAAAA,uCAAS;IACpC,MAAMC,MAAMF,2BAAAA,qCAAAA,eAAgBG,WAAW;IAEvC,MAAMC,oBAAoBF,MAAMA,IAAIG,qBAAqB,GAAGT;IAC5D,MAAMU,sBAAsBJ,MAAMA,IAAIK,oBAAoB,GAAGT;IAE7D,OAAOU,IAAAA,gCAAe,EAACJ,mBAAmBE;AAC5C"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useBrowserTimer.ts"],"sourcesContent":["import * as React from 'react';\n\ntype BrowserTimerSetter =\n | ((fn: () => void, duration?: number, ...args: Record<string, unknown>[]) => number)\n | ((fn: () => void) => number);\n\n/**\n * @internal\n * Helper to manage a browser timer.\n * Ensures that the timer isn't set multiple times at once,\n * and is cleaned up when the component is unloaded.\n *\n * @param setTimer - The timer setter function\n * @param cancelTimer - The timer cancel function\n * @returns A pair of [setTimer, cancelTimer] that are stable between renders.\n *\n * @example\n * const [setTimer, cancelTimer] = useBrowserTimer(setTimeout, cancelTimeout);\n *\n * setTimer(() => console.log('Hello world!'), 1000);\n * cancelTimer();\n */\nexport function useBrowserTimer(setTimer: BrowserTimerSetter, cancelTimer: (id: number) => void) {\n const id = React.useRef<number | undefined>(undefined);\n\n const set = React.useCallback(\n (fn: () => void, delay?: number) => {\n if (id.current !== undefined) {\n cancelTimer(id.current);\n }\n\n id.current = setTimer(fn, delay);\n return id.current;\n },\n [cancelTimer, setTimer],\n );\n\n const cancel = React.useCallback(() => {\n if (id.current !== undefined) {\n cancelTimer(id.current);\n id.current = undefined;\n }\n }, [cancelTimer]);\n\n // Clean up the timeout when the component is unloaded\n React.useEffect(() => cancel, [cancel]);\n\n return [set, cancel] as const;\n}\n"],"names":["useBrowserTimer","setTimer","cancelTimer","id","React","useRef","undefined","set","useCallback","fn","delay","current","cancel","useEffect"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAsBgBA;;;eAAAA;;;;iEAtBO;AAsBhB,SAASA,gBAAgBC,QAA4B,EAAEC,WAAiC;IAC7F,MAAMC,KAAKC,OAAMC,MAAM,CAAqBC;IAE5C,MAAMC,MAAMH,OAAMI,WAAW,CAC3B,CAACC,IAAgBC;QACf,IAAIP,GAAGQ,OAAO,KAAKL,WAAW;YAC5BJ,YAAYC,GAAGQ,OAAO;QACxB;QAEAR,GAAGQ,OAAO,GAAGV,SAASQ,IAAIC;QAC1B,OAAOP,GAAGQ,OAAO;IACnB,GACA;QAACT;QAAaD;KAAS;IAGzB,MAAMW,SAASR,OAAMI,WAAW,CAAC;QAC/B,IAAIL,GAAGQ,OAAO,KAAKL,WAAW;YAC5BJ,YAAYC,GAAGQ,OAAO;YACtBR,GAAGQ,OAAO,GAAGL;QACf;IACF,GAAG;QAACJ;KAAY;IAEhB,sDAAsD;IACtDE,OAAMS,SAAS,CAAC,IAAMD,QAAQ;QAACA;KAAO;IAEtC,OAAO;QAACL;QAAKK;KAAO;AACtB"}
|
1
|
+
{"version":3,"sources":["../src/hooks/useBrowserTimer.ts"],"sourcesContent":["import * as React from 'react';\n\ntype BrowserTimerSetter =\n | ((fn: () => void, duration?: number, ...args: Record<string, unknown>[]) => number)\n | ((fn: () => void) => number);\n\n/**\n * @internal\n * Helper to manage a browser timer.\n * Ensures that the timer isn't set multiple times at once,\n * and is cleaned up when the component is unloaded.\n *\n * @param setTimer - The timer setter function\n * @param cancelTimer - The timer cancel function\n * @returns A pair of [setTimer, cancelTimer] that are stable between renders.\n *\n * @example\n * const [setTimer, cancelTimer] = useBrowserTimer(setTimeout, cancelTimeout);\n *\n * setTimer(() => console.log('Hello world!'), 1000);\n * cancelTimer();\n */\nexport function useBrowserTimer(setTimer: BrowserTimerSetter, cancelTimer: (id: number) => void) {\n const id = React.useRef<number | undefined>(undefined);\n\n const set = React.useCallback(\n (fn: () => void, delay?: number) => {\n if (id.current !== undefined) {\n cancelTimer(id.current);\n }\n\n id.current = setTimer(fn, delay);\n return id.current;\n },\n [cancelTimer, setTimer],\n );\n\n const cancel = React.useCallback(() => {\n if (id.current !== undefined) {\n cancelTimer(id.current);\n id.current = undefined;\n }\n }, [cancelTimer]);\n\n // Clean up the timeout when the component is unloaded\n React.useEffect(() => cancel, [cancel]);\n\n return [set, cancel] as const;\n}\n"],"names":["useBrowserTimer","setTimer","cancelTimer","id","React","useRef","undefined","set","useCallback","fn","delay","current","cancel","useEffect"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAsBgBA;;;eAAAA;;;;iEAtBO;AAsBhB,SAASA,gBAAgBC,QAA4B,EAAEC,WAAiC;IAC7F,MAAMC,KAAKC,OAAMC,MAAM,CAAqBC;IAE5C,MAAMC,MAAMH,OAAMI,WAAW,CAC3B,CAACC,IAAgBC;QACf,IAAIP,GAAGQ,OAAO,KAAKL,WAAW;YAC5BJ,YAAYC,GAAGQ,OAAO;QACxB;QAEAR,GAAGQ,OAAO,GAAGV,SAASQ,IAAIC;QAC1B,OAAOP,GAAGQ,OAAO;IACnB,GACA;QAACT;QAAaD;KAAS;IAGzB,MAAMW,SAASR,OAAMI,WAAW,CAAC;QAC/B,IAAIL,GAAGQ,OAAO,KAAKL,WAAW;YAC5BJ,YAAYC,GAAGQ,OAAO;YACtBR,GAAGQ,OAAO,GAAGL;QACf;IACF,GAAG;QAACJ;KAAY;IAEhB,sDAAsD;IACtDE,OAAMS,SAAS,CAAC,IAAMD,QAAQ;QAACA;KAAO;IAEtC,OAAO;QAACL;QAAKK;KAAO;AACtB"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useControllableState.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n */\nexport type UseControllableStateOptions<State> = {\n /**\n * User-provided default state or initializer, for uncontrolled usage.\n */\n defaultState?: State | (() => State);\n /**\n * User-provided controlled state. `undefined` means internal state will be used.\n */\n state: State | undefined;\n /**\n * Used as the initial state if `state` and `defaultState` are both `undefined`.\n * If `undefined` is the correct initial state, pass that here.\n */\n initialState: State;\n};\n\nfunction isFactoryDispatch<State>(newState: React.SetStateAction<State>): newState is (prevState: State) => State {\n return typeof newState === 'function';\n}\n\n/**\n * @internal\n *\n * A [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate)-like hook\n * to manage a value that could be either `controlled` or `uncontrolled`,\n * such as a checked state or text input string.\n *\n * @see https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components for more details on `controlled`/`uncontrolled`\n *\n * @returns an array of the current value and an updater (dispatcher) function.\n * The updater function is referentially stable (won't change during the component's lifecycle).\n * It can take either a new value, or a function which is passed the previous value and returns the new value.\n *\n * ❗️❗️ Calls to the dispatcher will only modify the state if the state is `uncontrolled`.\n * Meaning that if a state is `controlled`, calls to the dispatcher do not modify the state.\n *\n */\nexport const useControllableState = <State>(\n options: UseControllableStateOptions<State>,\n): [State, React.Dispatch<React.SetStateAction<State>>] => {\n 'use no memo';\n\n if (process.env.NODE_ENV !== 'production') {\n if (options.state !== undefined && options.defaultState !== undefined) {\n // eslint-disable-next-line no-console\n console.error(/** #__DE-INDENT__ */ `\n @fluentui/react-utilities [useControllableState]:\n A component must be either controlled or uncontrolled (specify either the state or the defaultState, but not both).\n Decide between using a controlled or uncontrolled component and remove one of this props.\n More info: https://reactjs.org/link/controlled-components\n ${new Error().stack}\n `);\n }\n }\n const [internalState, setInternalState] = React.useState<State>(() => {\n if (options.defaultState === undefined) {\n return options.initialState;\n }\n return isInitializer(options.defaultState) ? options.defaultState() : options.defaultState;\n });\n\n // Heads up!\n // This part is specific for controlled mode and mocks behavior of React dispatcher function.\n\n const stateValueRef = React.useRef<State | undefined>(options.state);\n\n React.useEffect(() => {\n stateValueRef.current = options.state;\n }, [options.state]);\n\n const setControlledState = React.useCallback((newState: React.SetStateAction<State>) => {\n if (isFactoryDispatch(newState)) {\n newState(stateValueRef.current as State);\n }\n }, []);\n\n return useIsControlled(options.state) ? [options.state, setControlledState] : [internalState, setInternalState];\n};\n\nfunction isInitializer<State>(value: State | (() => State)): value is () => State {\n return typeof value === 'function';\n}\n\n/**\n * Helper hook to handle previous comparison of controlled/uncontrolled\n * Prints an error when isControlled value switches between subsequent renders\n * @returns - whether the value is controlled\n */\nconst useIsControlled = <V>(controlledValue: V | undefined): controlledValue is V => {\n 'use no memo';\n\n const [isControlled] = React.useState<boolean>(() => controlledValue !== undefined);\n\n if (process.env.NODE_ENV !== 'production') {\n // We don't want these warnings in production even though it is against native behaviour\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (isControlled !== (controlledValue !== undefined)) {\n const error = new Error();\n\n const controlWarning = isControlled\n ? 'a controlled value to be uncontrolled'\n : 'an uncontrolled value to be controlled';\n\n const undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined';\n\n // eslint-disable-next-line no-console\n console.error(/** #__DE-INDENT__ */ `\n @fluentui/react-utilities [useControllableState]:\n A component is changing ${controlWarning}. This is likely caused by the value changing from ${undefinedWarning} value, which should not happen.\n Decide between using a controlled or uncontrolled input element for the lifetime of the component.\n More info: https://reactjs.org/link/controlled-components\n ${error.stack}\n `);\n }\n }, [isControlled, controlledValue]);\n }\n\n return isControlled;\n};\n"],"names":["useControllableState","isFactoryDispatch","newState","options","process","env","NODE_ENV","state","undefined","defaultState","console","error","Error","stack","internalState","setInternalState","React","useState","initialState","isInitializer","stateValueRef","useRef","useEffect","current","setControlledState","useCallback","useIsControlled","value","controlledValue","isControlled","controlWarning","undefinedWarning"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BA0CaA;;;eAAAA;;;;iEA1CU;AAqBvB,SAASC,kBAAyBC,QAAqC;IACrE,OAAO,OAAOA,aAAa;AAC7B;AAmBO,MAAMF,uBAAuB,CAClCG;IAEA;IAEA,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,IAAIH,QAAQI,KAAK,KAAKC,aAAaL,QAAQM,YAAY,KAAKD,WAAW;YACrE,sCAAsC;YACtCE,QAAQC,KAAK,CAAuB,CAAC;;;;AAKrC,EAAE,IAAIC,QAAQC,KAAK,CAAC,
|
1
|
+
{"version":3,"sources":["../src/hooks/useControllableState.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n */\nexport type UseControllableStateOptions<State> = {\n /**\n * User-provided default state or initializer, for uncontrolled usage.\n */\n defaultState?: State | (() => State);\n /**\n * User-provided controlled state. `undefined` means internal state will be used.\n */\n state: State | undefined;\n /**\n * Used as the initial state if `state` and `defaultState` are both `undefined`.\n * If `undefined` is the correct initial state, pass that here.\n */\n initialState: State;\n};\n\nfunction isFactoryDispatch<State>(newState: React.SetStateAction<State>): newState is (prevState: State) => State {\n return typeof newState === 'function';\n}\n\n/**\n * @internal\n *\n * A [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate)-like hook\n * to manage a value that could be either `controlled` or `uncontrolled`,\n * such as a checked state or text input string.\n *\n * @see https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components for more details on `controlled`/`uncontrolled`\n *\n * @returns an array of the current value and an updater (dispatcher) function.\n * The updater function is referentially stable (won't change during the component's lifecycle).\n * It can take either a new value, or a function which is passed the previous value and returns the new value.\n *\n * ❗️❗️ Calls to the dispatcher will only modify the state if the state is `uncontrolled`.\n * Meaning that if a state is `controlled`, calls to the dispatcher do not modify the state.\n *\n */\nexport const useControllableState = <State>(\n options: UseControllableStateOptions<State>,\n): [State, React.Dispatch<React.SetStateAction<State>>] => {\n 'use no memo';\n\n if (process.env.NODE_ENV !== 'production') {\n if (options.state !== undefined && options.defaultState !== undefined) {\n // eslint-disable-next-line no-console\n console.error(/** #__DE-INDENT__ */ `\n @fluentui/react-utilities [useControllableState]:\n A component must be either controlled or uncontrolled (specify either the state or the defaultState, but not both).\n Decide between using a controlled or uncontrolled component and remove one of this props.\n More info: https://reactjs.org/link/controlled-components\n ${new Error().stack}\n `);\n }\n }\n const [internalState, setInternalState] = React.useState<State>(() => {\n if (options.defaultState === undefined) {\n return options.initialState;\n }\n return isInitializer(options.defaultState) ? options.defaultState() : options.defaultState;\n });\n\n // Heads up!\n // This part is specific for controlled mode and mocks behavior of React dispatcher function.\n\n const stateValueRef = React.useRef<State | undefined>(options.state);\n\n React.useEffect(() => {\n stateValueRef.current = options.state;\n }, [options.state]);\n\n const setControlledState = React.useCallback((newState: React.SetStateAction<State>) => {\n if (isFactoryDispatch(newState)) {\n newState(stateValueRef.current as State);\n }\n }, []);\n\n return useIsControlled(options.state) ? [options.state, setControlledState] : [internalState, setInternalState];\n};\n\nfunction isInitializer<State>(value: State | (() => State)): value is () => State {\n return typeof value === 'function';\n}\n\n/**\n * Helper hook to handle previous comparison of controlled/uncontrolled\n * Prints an error when isControlled value switches between subsequent renders\n * @returns - whether the value is controlled\n */\nconst useIsControlled = <V>(controlledValue: V | undefined): controlledValue is V => {\n 'use no memo';\n\n const [isControlled] = React.useState<boolean>(() => controlledValue !== undefined);\n\n if (process.env.NODE_ENV !== 'production') {\n // We don't want these warnings in production even though it is against native behaviour\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (isControlled !== (controlledValue !== undefined)) {\n const error = new Error();\n\n const controlWarning = isControlled\n ? 'a controlled value to be uncontrolled'\n : 'an uncontrolled value to be controlled';\n\n const undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined';\n\n // eslint-disable-next-line no-console\n console.error(/** #__DE-INDENT__ */ `\n @fluentui/react-utilities [useControllableState]:\n A component is changing ${controlWarning}. This is likely caused by the value changing from ${undefinedWarning} value, which should not happen.\n Decide between using a controlled or uncontrolled input element for the lifetime of the component.\n More info: https://reactjs.org/link/controlled-components\n ${error.stack}\n `);\n }\n }, [isControlled, controlledValue]);\n }\n\n return isControlled;\n};\n"],"names":["useControllableState","isFactoryDispatch","newState","options","process","env","NODE_ENV","state","undefined","defaultState","console","error","Error","stack","internalState","setInternalState","React","useState","initialState","isInitializer","stateValueRef","useRef","useEffect","current","setControlledState","useCallback","useIsControlled","value","controlledValue","isControlled","controlWarning","undefinedWarning"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BA0CaA;;;eAAAA;;;;iEA1CU;AAqBvB,SAASC,kBAAyBC,QAAqC;IACrE,OAAO,OAAOA,aAAa;AAC7B;AAmBO,MAAMF,uBAAuB,CAClCG;IAEA;IAEA,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,IAAIH,QAAQI,KAAK,KAAKC,aAAaL,QAAQM,YAAY,KAAKD,WAAW;YACrE,sCAAsC;YACtCE,QAAQC,KAAK,CAAuB,CAAC;;;;AAKrC,EAAE,IAAIC,QAAQC,KAAK,CAAC,AACtB,CAAC;QACD;IACF;IACA,MAAM,CAACC,eAAeC,iBAAiB,GAAGC,OAAMC,QAAQ,CAAQ;QAC9D,IAAId,QAAQM,YAAY,KAAKD,WAAW;YACtC,OAAOL,QAAQe,YAAY;QAC7B;QACA,OAAOC,cAAchB,QAAQM,YAAY,IAAIN,QAAQM,YAAY,KAAKN,QAAQM,YAAY;IAC5F;IAEA,YAAY;IACZ,6FAA6F;IAE7F,MAAMW,gBAAgBJ,OAAMK,MAAM,CAAoBlB,QAAQI,KAAK;IAEnES,OAAMM,SAAS,CAAC;QACdF,cAAcG,OAAO,GAAGpB,QAAQI,KAAK;IACvC,GAAG;QAACJ,QAAQI,KAAK;KAAC;IAElB,MAAMiB,qBAAqBR,OAAMS,WAAW,CAAC,CAACvB;QAC5C,IAAID,kBAAkBC,WAAW;YAC/BA,SAASkB,cAAcG,OAAO;QAChC;IACF,GAAG,EAAE;IAEL,OAAOG,gBAAgBvB,QAAQI,KAAK,IAAI;QAACJ,QAAQI,KAAK;QAAEiB;KAAmB,GAAG;QAACV;QAAeC;KAAiB;AACjH;AAEA,SAASI,cAAqBQ,KAA4B;IACxD,OAAO,OAAOA,UAAU;AAC1B;AAEA;;;;CAIC,GACD,MAAMD,kBAAkB,CAAIE;IAC1B;IAEA,MAAM,CAACC,aAAa,GAAGb,OAAMC,QAAQ,CAAU,IAAMW,oBAAoBpB;IAEzE,IAAIJ,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,wFAAwF;QACxF,sDAAsD;QACtDU,OAAMM,SAAS,CAAC;YACd,IAAIO,iBAAkBD,CAAAA,oBAAoBpB,SAAQ,GAAI;gBACpD,MAAMG,QAAQ,IAAIC;gBAElB,MAAMkB,iBAAiBD,eACnB,0CACA;gBAEJ,MAAME,mBAAmBF,eAAe,4BAA4B;gBAEpE,sCAAsC;gBACtCnB,QAAQC,KAAK,CAAuB,CAAC;wBAEX,EAAEmB,eAAe,mDAAmD,EAAEC,iBAAiB;;;AAG/G,EAAEpB,MAAME,KAAK,CAAC,AAChB,CAAC;YACH;QACF,GAAG;YAACgB;YAAcD;SAAgB;IACpC;IAEA,OAAOC;AACT"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useEventCallback.ts"],"sourcesContent":["import * as React from 'react';\nimport { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';\n\n/**\n * @internal\n * https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback\n *\n * Modified `useCallback` that can be used when dependencies change too frequently. Can occur when\n * e.g. user props are dependencies which could change on every render\n * e.g. volatile values (i.e. useState/useDispatch) are dependencies which could change frequently\n *\n * This should not be used often, but can be a useful re-render optimization since the callback is a ref and\n * will not be invalidated between re-renders\n *\n * @param fn - The callback function that will be used\n */\nexport const useEventCallback = <Args extends unknown[], Return>(fn: (...args: Args) => Return) => {\n const callbackRef = React.useRef<typeof fn>(() => {\n throw new Error('Cannot call an event handler while rendering');\n });\n\n useIsomorphicLayoutEffect(() => {\n callbackRef.current = fn;\n }, [fn]);\n\n return React.useCallback(\n (...args: Args) => {\n const callback = callbackRef.current;\n return callback(...args);\n },\n [callbackRef],\n );\n};\n"],"names":["useEventCallback","fn","callbackRef","React","useRef","Error","useIsomorphicLayoutEffect","current","useCallback","args","callback"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAgBaA;;;eAAAA;;;;iEAhBU;2CACmB;AAenC,MAAMA,mBAAmB,CAAiCC;IAC/D,MAAMC,cAAcC,OAAMC,MAAM,CAAY;QAC1C,MAAM,IAAIC,MAAM;IAClB;IAEAC,IAAAA,
|
1
|
+
{"version":3,"sources":["../src/hooks/useEventCallback.ts"],"sourcesContent":["import * as React from 'react';\nimport { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';\n\n/**\n * @internal\n * https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback\n *\n * Modified `useCallback` that can be used when dependencies change too frequently. Can occur when\n * e.g. user props are dependencies which could change on every render\n * e.g. volatile values (i.e. useState/useDispatch) are dependencies which could change frequently\n *\n * This should not be used often, but can be a useful re-render optimization since the callback is a ref and\n * will not be invalidated between re-renders\n *\n * @param fn - The callback function that will be used\n */\nexport const useEventCallback = <Args extends unknown[], Return>(fn: (...args: Args) => Return) => {\n const callbackRef = React.useRef<typeof fn>(() => {\n throw new Error('Cannot call an event handler while rendering');\n });\n\n useIsomorphicLayoutEffect(() => {\n callbackRef.current = fn;\n }, [fn]);\n\n return React.useCallback(\n (...args: Args) => {\n const callback = callbackRef.current;\n return callback(...args);\n },\n [callbackRef],\n );\n};\n"],"names":["useEventCallback","fn","callbackRef","React","useRef","Error","useIsomorphicLayoutEffect","current","useCallback","args","callback"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAgBaA;;;eAAAA;;;;iEAhBU;2CACmB;AAenC,MAAMA,mBAAmB,CAAiCC;IAC/D,MAAMC,cAAcC,OAAMC,MAAM,CAAY;QAC1C,MAAM,IAAIC,MAAM;IAClB;IAEAC,IAAAA,oDAAyB,EAAC;QACxBJ,YAAYK,OAAO,GAAGN;IACxB,GAAG;QAACA;KAAG;IAEP,OAAOE,OAAMK,WAAW,CACtB,CAAC,GAAGC;QACF,MAAMC,WAAWR,YAAYK,OAAO;QACpC,OAAOG,YAAYD;IACrB,GACA;QAACP;KAAY;AAEjB"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useFirstMount.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n * Checks if components was mounted the first time.\n * Since concurrent mode will be released in the future this needs to be verified\n * Currently (React 17) will always render the initial mount once\n * https://codesandbox.io/s/heuristic-brook-s4w0q?file=/src/App.jsx\n * https://codesandbox.io/s/holy-grass-8nieu?file=/src/App.jsx\n *\n * @example\n * const isFirstMount = useFirstMount();\n */\nexport function useFirstMount(): boolean {\n const isFirst = React.useRef(true);\n\n if (isFirst.current) {\n isFirst.current = false;\n return true;\n }\n\n return isFirst.current;\n}\n"],"names":["useFirstMount","isFirst","React","useRef","current"],"rangeMappings":";;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAagBA;;;eAAAA;;;;iEAbO;AAahB,SAASA;IACd,MAAMC,UAAUC,OAAMC,MAAM,CAAC;IAE7B,IAAIF,QAAQG,OAAO,EAAE;QACnBH,QAAQG,OAAO,GAAG;QAClB,OAAO;IACT;IAEA,OAAOH,QAAQG,OAAO;AACxB"}
|
1
|
+
{"version":3,"sources":["../src/hooks/useFirstMount.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n * Checks if components was mounted the first time.\n * Since concurrent mode will be released in the future this needs to be verified\n * Currently (React 17) will always render the initial mount once\n * https://codesandbox.io/s/heuristic-brook-s4w0q?file=/src/App.jsx\n * https://codesandbox.io/s/holy-grass-8nieu?file=/src/App.jsx\n *\n * @example\n * const isFirstMount = useFirstMount();\n */\nexport function useFirstMount(): boolean {\n const isFirst = React.useRef(true);\n\n if (isFirst.current) {\n isFirst.current = false;\n return true;\n }\n\n return isFirst.current;\n}\n"],"names":["useFirstMount","isFirst","React","useRef","current"],"rangeMappings":";;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAagBA;;;eAAAA;;;;iEAbO;AAahB,SAASA;IACd,MAAMC,UAAUC,OAAMC,MAAM,CAAC;IAE7B,IAAIF,QAAQG,OAAO,EAAE;QACnBH,QAAQG,OAAO,GAAG;QAClB,OAAO;IACT;IAEA,OAAOH,QAAQG,OAAO;AACxB"}
|
@@ -8,7 +8,8 @@ Object.defineProperty(exports, "useForceUpdate", {
|
|
8
8
|
return useForceUpdate;
|
9
9
|
}
|
10
10
|
});
|
11
|
-
const
|
11
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
12
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
12
13
|
function useForceUpdate() {
|
13
|
-
return
|
14
|
+
return _react.useReducer((x)=>x + 1, 0)[1];
|
14
15
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useForceUpdate.ts"],"sourcesContent":["import
|
1
|
+
{"version":3,"sources":["../src/hooks/useForceUpdate.ts"],"sourcesContent":["import * as React from 'react';\n/**\n * @internal\n * Forces a re-render, similar to `forceUpdate` in class components.\n */\nexport function useForceUpdate() {\n return React.useReducer(x => x + 1, 0)[1];\n}\n"],"names":["useForceUpdate","React","useReducer","x"],"rangeMappings":";;;;;;;;;;;;;;","mappings":";;;;+BAKgBA;;;eAAAA;;;;iEALO;AAKhB,SAASA;IACd,OAAOC,OAAMC,UAAU,CAACC,CAAAA,IAAKA,IAAI,GAAG,EAAE,CAAC,EAAE;AAC3C"}
|
@@ -22,7 +22,7 @@ _export(exports, {
|
|
22
22
|
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
23
23
|
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
24
24
|
const _index = require("../ssr/index");
|
25
|
-
const IdPrefixContext =
|
25
|
+
const IdPrefixContext = _react.createContext(undefined);
|
26
26
|
const IdPrefixProvider = IdPrefixContext.Provider;
|
27
27
|
function useIdPrefix() {
|
28
28
|
return _react.useContext(IdPrefixContext) || '';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useId.ts"],"sourcesContent":["import * as React from 'react';\nimport { defaultSSRContextValue, useSSRContext } from '../ssr/index';\n\nconst IdPrefixContext = React.createContext<string | undefined>(undefined);\n\n/**\n * Allows to define a prefix that will be used for all IDs generated by useId() hook. It's useful to avoid collisions\n * between different bundles.\n */\nexport const IdPrefixProvider = IdPrefixContext.Provider;\n\nfunction useIdPrefix(): string {\n return React.useContext(IdPrefixContext) || '';\n}\n\n/**\n * Resets generated IDs, should be used only in tests.\n */\nexport function resetIdsForTests(): void {\n defaultSSRContextValue.current = 0;\n}\n\n/**\n * Hook to generate a unique ID.\n *\n * @param prefix - Optional prefix for the ID. Defaults to 'fui-'.\n * @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,\n * without conditioning the hook call\n * @returns The ID\n */\nexport function useId(prefix: string = 'fui-', providedId?: string): string {\n 'use no memo';\n\n const contextValue = useSSRContext();\n const idPrefix = useIdPrefix();\n\n // Checking if useId is available on React, if it is, we use it to generate the id. String concatenation is used to\n // prevent bundlers from complaining with older versions of React.\n const _useId = (React as never)['use' + 'Id'] as (() => string) | undefined;\n\n if (_useId) {\n const generatedId = _useId();\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const escapedId = React.useMemo(() => generatedId.replace(/:/g, ''), [generatedId]);\n\n return providedId || `${idPrefix}${prefix}${escapedId}`;\n }\n\n // Hooks appear to be running conditionally, but they will always run in the same order since it's based on\n // the version of React being used. This is safe to ignore.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return React.useMemo(() => {\n if (providedId) {\n return providedId;\n }\n\n return `${idPrefix}${prefix}${++contextValue.current}`;\n }, [idPrefix, prefix, providedId, contextValue]);\n}\n"],"names":["IdPrefixProvider","resetIdsForTests","useId","IdPrefixContext","React","createContext","undefined","Provider","useIdPrefix","useContext","defaultSSRContextValue","current","prefix","providedId","contextValue","useSSRContext","idPrefix","_useId","generatedId","escapedId","useMemo","replace"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IASaA,
|
1
|
+
{"version":3,"sources":["../src/hooks/useId.ts"],"sourcesContent":["import * as React from 'react';\nimport { defaultSSRContextValue, useSSRContext } from '../ssr/index';\n\nconst IdPrefixContext = React.createContext<string | undefined>(undefined);\n\n/**\n * Allows to define a prefix that will be used for all IDs generated by useId() hook. It's useful to avoid collisions\n * between different bundles.\n */\nexport const IdPrefixProvider = IdPrefixContext.Provider;\n\nfunction useIdPrefix(): string {\n return React.useContext(IdPrefixContext) || '';\n}\n\n/**\n * Resets generated IDs, should be used only in tests.\n */\nexport function resetIdsForTests(): void {\n defaultSSRContextValue.current = 0;\n}\n\n/**\n * Hook to generate a unique ID.\n *\n * @param prefix - Optional prefix for the ID. Defaults to 'fui-'.\n * @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,\n * without conditioning the hook call\n * @returns The ID\n */\nexport function useId(prefix: string = 'fui-', providedId?: string): string {\n 'use no memo';\n\n const contextValue = useSSRContext();\n const idPrefix = useIdPrefix();\n\n // Checking if useId is available on React, if it is, we use it to generate the id. String concatenation is used to\n // prevent bundlers from complaining with older versions of React.\n const _useId = (React as never)['use' + 'Id'] as (() => string) | undefined;\n\n if (_useId) {\n const generatedId = _useId();\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const escapedId = React.useMemo(() => generatedId.replace(/:/g, ''), [generatedId]);\n\n return providedId || `${idPrefix}${prefix}${escapedId}`;\n }\n\n // Hooks appear to be running conditionally, but they will always run in the same order since it's based on\n // the version of React being used. This is safe to ignore.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return React.useMemo(() => {\n if (providedId) {\n return providedId;\n }\n\n return `${idPrefix}${prefix}${++contextValue.current}`;\n }, [idPrefix, prefix, providedId, contextValue]);\n}\n"],"names":["IdPrefixProvider","resetIdsForTests","useId","IdPrefixContext","React","createContext","undefined","Provider","useIdPrefix","useContext","defaultSSRContextValue","current","prefix","providedId","contextValue","useSSRContext","idPrefix","_useId","generatedId","escapedId","useMemo","replace"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IASaA,gBAAgB;eAAhBA;;IASGC,gBAAgB;eAAhBA;;IAYAC,KAAK;eAALA;;;;iEA9BO;uBAC+B;AAEtD,MAAMC,kBAAkBC,OAAMC,aAAa,CAAqBC;AAMzD,MAAMN,mBAAmBG,gBAAgBI,QAAQ;AAExD,SAASC;IACP,OAAOJ,OAAMK,UAAU,CAACN,oBAAoB;AAC9C;AAKO,SAASF;IACdS,6BAAsB,CAACC,OAAO,GAAG;AACnC;AAUO,SAAST,MAAMU,SAAiB,MAAM,EAAEC,UAAmB;IAChE;IAEA,MAAMC,eAAeC,IAAAA,oBAAa;IAClC,MAAMC,WAAWR;IAEjB,mHAAmH;IACnH,kEAAkE;IAClE,MAAMS,SAAS,AAACb,MAAe,CAAC,QAAQ,KAAK;IAE7C,IAAIa,QAAQ;QACV,MAAMC,cAAcD;QAEpB,sDAAsD;QACtD,MAAME,YAAYf,OAAMgB,OAAO,CAAC,IAAMF,YAAYG,OAAO,CAAC,MAAM,KAAK;YAACH;SAAY;QAElF,OAAOL,cAAc,CAAC,EAAEG,SAAS,EAAEJ,OAAO,EAAEO,UAAU,CAAC;IACzD;IAEA,2GAA2G;IAC3G,2DAA2D;IAC3D,sDAAsD;IACtD,OAAOf,OAAMgB,OAAO,CAAC;QACnB,IAAIP,YAAY;YACd,OAAOA;QACT;QAEA,OAAO,CAAC,EAAEG,SAAS,EAAEJ,OAAO,EAAE,EAAEE,aAAaH,OAAO,CAAC,CAAC;IACxD,GAAG;QAACK;QAAUJ;QAAQC;QAAYC;KAAa;AACjD"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useIsomorphicLayoutEffect.ts"],"sourcesContent":["import * as React from 'react';\nimport { canUseDOM } from '../ssr/index';\n\n/**\n * React currently throws a warning when using useLayoutEffect on the server. To get around it, we can conditionally\n * useEffect on the server (no-op) and useLayoutEffect in the browser. We occasionally need useLayoutEffect to\n * ensure we don't get a render flash for certain operations, but we may also need affected components to render on\n * the server.\n *\n * https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85\n * https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.js\n */\n// eslint-disable-next-line no-restricted-properties\nexport const useIsomorphicLayoutEffect: typeof React.useEffect = canUseDOM() ? React.useLayoutEffect : React.useEffect;\n"],"names":["useIsomorphicLayoutEffect","canUseDOM","React","useLayoutEffect","useEffect"],"rangeMappings":";;;;;;;;;;;;;","mappings":";;;;+BAaaA;;;eAAAA;;;;iEAbU;uBACG;AAYnB,MAAMA,4BAAoDC,IAAAA,
|
1
|
+
{"version":3,"sources":["../src/hooks/useIsomorphicLayoutEffect.ts"],"sourcesContent":["import * as React from 'react';\nimport { canUseDOM } from '../ssr/index';\n\n/**\n * React currently throws a warning when using useLayoutEffect on the server. To get around it, we can conditionally\n * useEffect on the server (no-op) and useLayoutEffect in the browser. We occasionally need useLayoutEffect to\n * ensure we don't get a render flash for certain operations, but we may also need affected components to render on\n * the server.\n *\n * https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85\n * https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.js\n */\n// eslint-disable-next-line no-restricted-properties\nexport const useIsomorphicLayoutEffect: typeof React.useEffect = canUseDOM() ? React.useLayoutEffect : React.useEffect;\n"],"names":["useIsomorphicLayoutEffect","canUseDOM","React","useLayoutEffect","useEffect"],"rangeMappings":";;;;;;;;;;;;;","mappings":";;;;+BAaaA;;;eAAAA;;;;iEAbU;uBACG;AAYnB,MAAMA,4BAAoDC,IAAAA,gBAAS,MAAKC,OAAMC,eAAe,GAAGD,OAAME,SAAS"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useMergedRefs.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * A Ref function which can be treated like a ref object in that it has an attached\n * current property, which will be updated as the ref is evaluated.\n */\nexport type RefObjectFunction<T> = React.RefObject<T> & ((value: T | null) => void);\n\n/**\n * React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that\n * updates all provided refs\n * @param refs - Refs to collectively update with one ref value.\n * @returns A function with an attached \"current\" prop, so that it can be treated like a RefObject.\n */\nexport function useMergedRefs<T>(...refs: (React.Ref<T> | undefined)[]): RefObjectFunction<T> {\n 'use no memo';\n\n const mergedCallback: RefObjectFunction<T> = React.useCallback(\n (value: T | null) => {\n // Update the \"current\" prop hanging on the function.\n (mergedCallback as React.MutableRefObject<T | null>).current = value;\n\n for (const ref of refs) {\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref) {\n // work around the immutability of the React.Ref type\n (ref as React.MutableRefObject<T | null>).current = value;\n }\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps -- already exhaustive\n [...refs],\n ) as RefObjectFunction<T>;\n\n return mergedCallback;\n}\n"],"names":["useMergedRefs","refs","mergedCallback","React","useCallback","value","current","ref"],"rangeMappings":"
|
1
|
+
{"version":3,"sources":["../src/hooks/useMergedRefs.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * A Ref function which can be treated like a ref object in that it has an attached\n * current property, which will be updated as the ref is evaluated.\n */\nexport type RefObjectFunction<T> = React.RefObject<T> & ((value: T | null) => void);\n\n/**\n * React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that\n * updates all provided refs\n * @param refs - Refs to collectively update with one ref value.\n * @returns A function with an attached \"current\" prop, so that it can be treated like a RefObject.\n */\nexport function useMergedRefs<T>(...refs: (React.Ref<T> | undefined)[]): RefObjectFunction<T> {\n 'use no memo';\n\n const mergedCallback: RefObjectFunction<T> = React.useCallback(\n (value: T | null) => {\n // Update the \"current\" prop hanging on the function.\n (mergedCallback as React.MutableRefObject<T | null>).current = value;\n\n for (const ref of refs) {\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref) {\n // work around the immutability of the React.Ref type\n (ref as React.MutableRefObject<T | null>).current = value;\n }\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps -- already exhaustive\n [...refs],\n ) as RefObjectFunction<T>;\n\n return mergedCallback;\n}\n"],"names":["useMergedRefs","refs","mergedCallback","React","useCallback","value","current","ref"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAcgBA;;;eAAAA;;;;iEAdO;AAchB,SAASA,cAAiB,GAAGC,IAAkC;IACpE;IAEA,MAAMC,iBAAuCC,OAAMC,WAAW,CAC5D,CAACC;QACC,qDAAqD;QACpDH,eAAoDI,OAAO,GAAGD;QAE/D,KAAK,MAAME,OAAON,KAAM;YACtB,IAAI,OAAOM,QAAQ,YAAY;gBAC7BA,IAAIF;YACN,OAAO,IAAIE,KAAK;gBACd,qDAAqD;gBACpDA,IAAyCD,OAAO,GAAGD;YACtD;QACF;IACF,GACA,6EAA6E;IAC7E;WAAIJ;KAAK;IAGX,OAAOC;AACT"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useOnClickOutside.ts"],"sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from './useEventCallback';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\n/**\n * @internal\n */\nexport type UseOnClickOrScrollOutsideOptions = {\n /**\n * The element to listen for the click event\n */\n element: Document | undefined;\n /**\n * Refs to elements that check if the click is outside\n */\n refs: React.MutableRefObject<HTMLElement | undefined | null>[];\n\n /**\n * By default uses element.contains, but custom contain function can be provided\n *\n * @param parent - provided parent element\n * @param child - event target element\n */\n contains?(parent: HTMLElement | null, child: HTMLElement): boolean;\n\n /**\n * Disables event listeners\n */\n disabled?: boolean;\n\n /**\n * Disables custom focus event listeners for iframes\n */\n disabledFocusOnIframe?: boolean;\n\n /**\n * Called if the click is outside the element refs\n */\n callback: (ev: MouseEvent | TouchEvent) => void;\n};\n\nconst DEFAULT_CONTAINS: UseOnClickOrScrollOutsideOptions['contains'] = (parent, child) => !!parent?.contains(child);\n\n/**\n * @internal\n * Utility to perform checks where a click/touch event was made outside a component\n */\nexport const useOnClickOutside = (options: UseOnClickOrScrollOutsideOptions) => {\n const { targetDocument } = useFluent();\n const win = targetDocument?.defaultView;\n const { refs, callback, element, disabled, disabledFocusOnIframe, contains = DEFAULT_CONTAINS } = options;\n const timeoutId = React.useRef<number | undefined>(undefined);\n\n useIFrameFocus({ element, disabled: disabledFocusOnIframe || disabled, callback, refs, contains });\n\n const isMouseDownInsideRef = React.useRef(false);\n const listener = useEventCallback((ev: MouseEvent | TouchEvent) => {\n if (isMouseDownInsideRef.current) {\n isMouseDownInsideRef.current = false;\n return;\n }\n\n const target = ev.composedPath()[0] as HTMLElement;\n const isOutside = refs.every(ref => !contains(ref.current || null, target));\n\n if (isOutside && !disabled) {\n callback(ev);\n }\n });\n\n const handleMouseDown = useEventCallback((ev: MouseEvent) => {\n // Selecting text from inside to outside will rigger click event.\n // In this case click event target is outside but mouse down event target is inside.\n // And this click event should be considered as inside click.\n isMouseDownInsideRef.current = refs.some(ref => contains(ref.current || null, ev.target as HTMLElement));\n });\n\n React.useEffect(() => {\n if (disabled) {\n return;\n }\n\n // Store the current event to avoid triggering handlers immediately\n // Note this depends on a deprecated but extremely well supported quirk of the web platform\n // https://github.com/facebook/react/issues/20074\n let currentEvent = getWindowEvent(win);\n\n const conditionalHandler = (event: MouseEvent | TouchEvent) => {\n // Skip if this event is the same as the one running when we added the handlers\n if (event === currentEvent) {\n currentEvent = undefined;\n return;\n }\n\n listener(event);\n };\n\n // use capture phase because React can update DOM before the event bubbles to the document\n element?.addEventListener('click', conditionalHandler, true);\n element?.addEventListener('touchstart', conditionalHandler, true);\n element?.addEventListener('contextmenu', conditionalHandler, true);\n element?.addEventListener('mousedown', handleMouseDown, true);\n\n // Garbage collect this event after it's no longer useful to avoid memory leaks\n timeoutId.current = win?.setTimeout(() => {\n currentEvent = undefined;\n }, 1);\n\n return () => {\n element?.removeEventListener('click', conditionalHandler, true);\n element?.removeEventListener('touchstart', conditionalHandler, true);\n element?.removeEventListener('contextmenu', conditionalHandler, true);\n element?.removeEventListener('mousedown', handleMouseDown, true);\n\n win?.clearTimeout(timeoutId.current);\n currentEvent = undefined;\n };\n }, [listener, element, disabled, handleMouseDown, win]);\n};\n\nconst getWindowEvent = (target: Node | Window | null | undefined): Event | undefined => {\n if (target) {\n if (typeof (target as Window).window === 'object' && (target as Window).window === target) {\n // eslint-disable-next-line deprecation/deprecation\n return target.event;\n }\n\n // eslint-disable-next-line deprecation/deprecation\n return (target as Node).ownerDocument?.defaultView?.event ?? undefined;\n }\n\n return undefined;\n};\n\nconst FUI_FRAME_EVENT = 'fuiframefocus';\n\ninterface UseIFrameFocusOptions\n extends Pick<UseOnClickOrScrollOutsideOptions, 'disabled' | 'element' | 'callback' | 'contains' | 'refs'> {\n /**\n * Millisecond duration to poll\n */\n pollDuration?: number;\n}\n\n/**\n * Since click events do not propagate past iframes, we use focus to detect if a\n * click has happened inside an iframe, since the only ways of focusing inside an\n * iframe are:\n * - clicking inside\n * - tabbing inside\n *\n * Polls the value of `document.activeElement`. If it is an iframe, then dispatch\n * a custom DOM event. When the custom event is received call the provided callback\n */\nconst useIFrameFocus = (options: UseIFrameFocusOptions) => {\n const {\n disabled,\n element: targetDocument,\n callback,\n contains = DEFAULT_CONTAINS,\n pollDuration = 1000,\n refs,\n } = options;\n const timeoutRef = React.useRef<number>();\n\n const listener = useEventCallback((e: Event) => {\n const isOutside = refs.every(ref => !contains(ref.current || null, e.target as HTMLElement));\n\n if (isOutside && !disabled) {\n callback(e as MouseEvent);\n }\n });\n\n // Adds listener to the custom iframe focus event\n React.useEffect(() => {\n if (disabled) {\n return;\n }\n\n targetDocument?.addEventListener(FUI_FRAME_EVENT, listener, true);\n\n return () => {\n targetDocument?.removeEventListener(FUI_FRAME_EVENT, listener, true);\n };\n }, [targetDocument, disabled, listener]);\n\n // Starts polling for the active element\n React.useEffect(() => {\n if (disabled) {\n return;\n }\n\n timeoutRef.current = targetDocument?.defaultView?.setInterval(() => {\n const activeElement = targetDocument?.activeElement;\n\n if (activeElement?.tagName === 'IFRAME' || activeElement?.tagName === 'WEBVIEW') {\n const event = new CustomEvent(FUI_FRAME_EVENT, { bubbles: true });\n activeElement.dispatchEvent(event);\n }\n }, pollDuration);\n\n return () => {\n targetDocument?.defaultView?.clearTimeout(timeoutRef.current);\n };\n }, [targetDocument, disabled, pollDuration]);\n};\n"],"names":["useOnClickOutside","DEFAULT_CONTAINS","parent","child","contains","options","targetDocument","useFluent","win","defaultView","refs","callback","element","disabled","disabledFocusOnIframe","timeoutId","React","useRef","undefined","useIFrameFocus","isMouseDownInsideRef","listener","useEventCallback","ev","current","target","composedPath","isOutside","every","ref","handleMouseDown","some","useEffect","currentEvent","getWindowEvent","conditionalHandler","event","addEventListener","setTimeout","removeEventListener","clearTimeout","_target_ownerDocument_defaultView","_target_ownerDocument","window","_target_ownerDocument_defaultView_event","ownerDocument","FUI_FRAME_EVENT","pollDuration","timeoutRef","e","setInterval","activeElement","tagName","CustomEvent","bubbles","dispatchEvent"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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B,OAAO;QAC9D;IACF,GAAG;QAAClB;QAAgBO;QAAUkC;KAAa;AAC7C"}
|
1
|
+
{"version":3,"sources":["../src/hooks/useOnClickOutside.ts"],"sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from './useEventCallback';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\n/**\n * @internal\n */\nexport type UseOnClickOrScrollOutsideOptions = {\n /**\n * The element to listen for the click event\n */\n element: Document | undefined;\n /**\n * Refs to elements that check if the click is outside\n */\n refs: React.MutableRefObject<HTMLElement | undefined | null>[];\n\n /**\n * By default uses element.contains, but custom contain function can be provided\n *\n * @param parent - provided parent element\n * @param child - event target element\n */\n contains?(parent: HTMLElement | null, child: HTMLElement): boolean;\n\n /**\n * Disables event listeners\n */\n disabled?: boolean;\n\n /**\n * Disables custom focus event listeners for iframes\n */\n disabledFocusOnIframe?: boolean;\n\n /**\n * Called if the click is outside the element refs\n */\n callback: (ev: MouseEvent | TouchEvent) => void;\n};\n\nconst DEFAULT_CONTAINS: UseOnClickOrScrollOutsideOptions['contains'] = (parent, child) => !!parent?.contains(child);\n\n/**\n * @internal\n * Utility to perform checks where a click/touch event was made outside a component\n */\nexport const useOnClickOutside = (options: UseOnClickOrScrollOutsideOptions) => {\n const { targetDocument } = useFluent();\n const win = targetDocument?.defaultView;\n const { refs, callback, element, disabled, disabledFocusOnIframe, contains = DEFAULT_CONTAINS } = options;\n const timeoutId = React.useRef<number | undefined>(undefined);\n\n useIFrameFocus({ element, disabled: disabledFocusOnIframe || disabled, callback, refs, contains });\n\n const isMouseDownInsideRef = React.useRef(false);\n const listener = useEventCallback((ev: MouseEvent | TouchEvent) => {\n if (isMouseDownInsideRef.current) {\n isMouseDownInsideRef.current = false;\n return;\n }\n\n const target = ev.composedPath()[0] as HTMLElement;\n const isOutside = refs.every(ref => !contains(ref.current || null, target));\n\n if (isOutside && !disabled) {\n callback(ev);\n }\n });\n\n const handleMouseDown = useEventCallback((ev: MouseEvent) => {\n // Selecting text from inside to outside will rigger click event.\n // In this case click event target is outside but mouse down event target is inside.\n // And this click event should be considered as inside click.\n isMouseDownInsideRef.current = refs.some(ref => contains(ref.current || null, ev.target as HTMLElement));\n });\n\n React.useEffect(() => {\n if (disabled) {\n return;\n }\n\n // Store the current event to avoid triggering handlers immediately\n // Note this depends on a deprecated but extremely well supported quirk of the web platform\n // https://github.com/facebook/react/issues/20074\n let currentEvent = getWindowEvent(win);\n\n const conditionalHandler = (event: MouseEvent | TouchEvent) => {\n // Skip if this event is the same as the one running when we added the handlers\n if (event === currentEvent) {\n currentEvent = undefined;\n return;\n }\n\n listener(event);\n };\n\n // use capture phase because React can update DOM before the event bubbles to the document\n element?.addEventListener('click', conditionalHandler, true);\n element?.addEventListener('touchstart', conditionalHandler, true);\n element?.addEventListener('contextmenu', conditionalHandler, true);\n element?.addEventListener('mousedown', handleMouseDown, true);\n\n // Garbage collect this event after it's no longer useful to avoid memory leaks\n timeoutId.current = win?.setTimeout(() => {\n currentEvent = undefined;\n }, 1);\n\n return () => {\n element?.removeEventListener('click', conditionalHandler, true);\n element?.removeEventListener('touchstart', conditionalHandler, true);\n element?.removeEventListener('contextmenu', conditionalHandler, true);\n element?.removeEventListener('mousedown', handleMouseDown, true);\n\n win?.clearTimeout(timeoutId.current);\n currentEvent = undefined;\n };\n }, [listener, element, disabled, handleMouseDown, win]);\n};\n\nconst getWindowEvent = (target: Node | Window | null | undefined): Event | undefined => {\n if (target) {\n if (typeof (target as Window).window === 'object' && (target as Window).window === target) {\n // eslint-disable-next-line deprecation/deprecation\n return target.event;\n }\n\n // eslint-disable-next-line deprecation/deprecation\n return (target as Node).ownerDocument?.defaultView?.event ?? undefined;\n }\n\n return undefined;\n};\n\nconst FUI_FRAME_EVENT = 'fuiframefocus';\n\ninterface UseIFrameFocusOptions\n extends Pick<UseOnClickOrScrollOutsideOptions, 'disabled' | 'element' | 'callback' | 'contains' | 'refs'> {\n /**\n * Millisecond duration to poll\n */\n pollDuration?: number;\n}\n\n/**\n * Since click events do not propagate past iframes, we use focus to detect if a\n * click has happened inside an iframe, since the only ways of focusing inside an\n * iframe are:\n * - clicking inside\n * - tabbing inside\n *\n * Polls the value of `document.activeElement`. If it is an iframe, then dispatch\n * a custom DOM event. When the custom event is received call the provided callback\n */\nconst useIFrameFocus = (options: UseIFrameFocusOptions) => {\n const {\n disabled,\n element: targetDocument,\n callback,\n contains = DEFAULT_CONTAINS,\n pollDuration = 1000,\n refs,\n } = options;\n const timeoutRef = React.useRef<number>();\n\n const listener = useEventCallback((e: Event) => {\n const isOutside = refs.every(ref => !contains(ref.current || null, e.target as HTMLElement));\n\n if (isOutside && !disabled) {\n callback(e as MouseEvent);\n }\n });\n\n // Adds listener to the custom iframe focus event\n React.useEffect(() => {\n if (disabled) {\n return;\n }\n\n targetDocument?.addEventListener(FUI_FRAME_EVENT, listener, true);\n\n return () => {\n targetDocument?.removeEventListener(FUI_FRAME_EVENT, listener, true);\n };\n }, [targetDocument, disabled, listener]);\n\n // Starts polling for the active element\n React.useEffect(() => {\n if (disabled) {\n return;\n }\n\n timeoutRef.current = targetDocument?.defaultView?.setInterval(() => {\n const activeElement = targetDocument?.activeElement;\n\n if (activeElement?.tagName === 'IFRAME' || activeElement?.tagName === 'WEBVIEW') {\n const event = new CustomEvent(FUI_FRAME_EVENT, { bubbles: true });\n activeElement.dispatchEvent(event);\n }\n }, pollDuration);\n\n return () => {\n targetDocument?.defaultView?.clearTimeout(timeoutRef.current);\n };\n }, [targetDocument, disabled, pollDuration]);\n};\n"],"names":["useOnClickOutside","DEFAULT_CONTAINS","parent","child","contains","options","targetDocument","useFluent","win","defaultView","refs","callback","element","disabled","disabledFocusOnIframe","timeoutId","React","useRef","undefined","useIFrameFocus","isMouseDownInsideRef","listener","useEventCallback","ev","current","target","composedPath","isOutside","every","ref","handleMouseDown","some","useEffect","currentEvent","getWindowEvent","conditionalHandler","event","addEventListener","setTimeout","removeEventListener","clearTimeout","window","ownerDocument","FUI_FRAME_EVENT","pollD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5D,MAAMC,gBAAgB1C,2BAAAA,qCAAAA,eAAgB0C,aAAa;YAEnD,IAAIA,CAAAA,0BAAAA,oCAAAA,cAAeC,OAAO,MAAK,YAAYD,CAAAA,0BAAAA,oCAAAA,cAAeC,OAAO,MAAK,WAAW;gBAC/E,MAAMb,QAAQ,IAAIc,YAAYP,iBAAiB;oBAAEQ,SAAS;gBAAK;gBAC/DH,cAAcI,aAAa,CAAChB;YAC9B;QACF,GAAGQ;QAEH,OAAO;gBACLtC;YAAAA,2BAAAA,sCAAAA,8BAAAA,eAAgBG,WAAW,cAA3BH,kDAAAA,4BAA6BkC,YAAY,CAACK,WAAWrB,OAAO;QAC9D;IACF,GAAG;QAAClB;QAAgBO;QAAU+B;KAAa;AAC7C"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useOnScrollOutside.ts"],"sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from './useEventCallback';\nimport type { UseOnClickOrScrollOutsideOptions } from './useOnClickOutside';\n\n/**\n * @internal\n * Utility to perform checks where a click/touch event was made outside a component\n */\nexport const useOnScrollOutside = (options: UseOnClickOrScrollOutsideOptions) => {\n const { refs, callback, element, disabled, contains: containsProp } = options;\n\n const listener = useEventCallback((ev: MouseEvent | TouchEvent) => {\n const contains: UseOnClickOrScrollOutsideOptions['contains'] =\n containsProp || ((parent, child) => !!parent?.contains(child));\n\n const target = ev.composedPath()[0] as HTMLElement;\n const isOutside = refs.every(ref => !contains(ref.current || null, target));\n\n if (isOutside && !disabled) {\n callback(ev);\n }\n });\n\n React.useEffect(() => {\n if (disabled) {\n return;\n }\n\n element?.addEventListener('wheel', listener);\n element?.addEventListener('touchmove', listener);\n\n return () => {\n element?.removeEventListener('wheel', listener);\n element?.removeEventListener('touchmove', listener);\n };\n }, [listener, element, disabled]);\n};\n"],"names":["useOnScrollOutside","options","refs","callback","element","disabled","contains","containsProp","listener","useEventCallback","ev","parent","child","target","composedPath","isOutside","every","ref","current","React","useEffect","addEventListener","removeEventListener"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAQaA;;;eAAAA;;;;iEARU;kCACU;AAO1B,MAAMA,qBAAqB,CAACC;IACjC,MAAM,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,UAAUC,YAAY,EAAE,GAAGN;IAEtE,MAAMO,WAAWC,IAAAA,
|
1
|
+
{"version":3,"sources":["../src/hooks/useOnScrollOutside.ts"],"sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from './useEventCallback';\nimport type { UseOnClickOrScrollOutsideOptions } from './useOnClickOutside';\n\n/**\n * @internal\n * Utility to perform checks where a click/touch event was made outside a component\n */\nexport const useOnScrollOutside = (options: UseOnClickOrScrollOutsideOptions) => {\n const { refs, callback, element, disabled, contains: containsProp } = options;\n\n const listener = useEventCallback((ev: MouseEvent | TouchEvent) => {\n const contains: UseOnClickOrScrollOutsideOptions['contains'] =\n containsProp || ((parent, child) => !!parent?.contains(child));\n\n const target = ev.composedPath()[0] as HTMLElement;\n const isOutside = refs.every(ref => !contains(ref.current || null, target));\n\n if (isOutside && !disabled) {\n callback(ev);\n }\n });\n\n React.useEffect(() => {\n if (disabled) {\n return;\n }\n\n element?.addEventListener('wheel', listener);\n element?.addEventListener('touchmove', listener);\n\n return () => {\n element?.removeEventListener('wheel', listener);\n element?.removeEventListener('touchmove', listener);\n };\n }, [listener, element, disabled]);\n};\n"],"names":["useOnScrollOutside","options","refs","callback","element","disabled","contains","containsProp","listener","useEventCallback","ev","parent","child","target","composedPath","isOutside","every","ref","current","React","useEffect","addEventListener","removeEventListener"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAQaA;;;eAAAA;;;;iEARU;kCACU;AAO1B,MAAMA,qBAAqB,CAACC;IACjC,MAAM,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,UAAUC,YAAY,EAAE,GAAGN;IAEtE,MAAMO,WAAWC,IAAAA,kCAAgB,EAAC,CAACC;QACjC,MAAMJ,WACJC,gBAAiB,CAAA,CAACI,QAAQC,QAAU,CAAC,EAACD,mBAAAA,6BAAAA,OAAQL,QAAQ,CAACM,OAAK;QAE9D,MAAMC,SAASH,GAAGI,YAAY,EAAE,CAAC,EAAE;QACnC,MAAMC,YAAYb,KAAKc,KAAK,CAACC,CAAAA,MAAO,CAACX,SAASW,IAAIC,OAAO,IAAI,MAAML;QAEnE,IAAIE,aAAa,CAACV,UAAU;YAC1BF,SAASO;QACX;IACF;IAEAS,OAAMC,SAAS,CAAC;QACd,IAAIf,UAAU;YACZ;QACF;QAEAD,oBAAAA,8BAAAA,QAASiB,gBAAgB,CAAC,SAASb;QACnCJ,oBAAAA,8BAAAA,QAASiB,gBAAgB,CAAC,aAAab;QAEvC,OAAO;YACLJ,oBAAAA,8BAAAA,QAASkB,mBAAmB,CAAC,SAASd;YACtCJ,oBAAAA,8BAAAA,QAASkB,mBAAmB,CAAC,aAAad;QAC5C;IACF,GAAG;QAACA;QAAUJ;QAASC;KAAS;AAClC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["usePrevious.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n */\nexport const usePrevious = <ValueType = unknown>(value: ValueType) => {\n const ref = React.useRef<ValueType | null>(null);\n React.useEffect(() => {\n ref.current = value;\n }, [value]);\n return ref.current;\n};\n"],"names":["usePrevious","value","ref","React","useRef","useEffect","current"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAKaA;;;eAAAA;;;;iEALU;AAKhB,MAAMA,cAAc,CAAsBC;IAC/C,MAAMC,MAAMC,OAAMC,MAAM,CAAmB;IAC3CD,OAAME,SAAS,CAAC;QACdH,IAAII,OAAO,GAAGL;IAChB,GAAG;QAACA;KAAM;IACV,OAAOC,IAAII,OAAO;AACpB"}
|
1
|
+
{"version":3,"sources":["../src/hooks/usePrevious.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n */\nexport const usePrevious = <ValueType = unknown>(value: ValueType) => {\n const ref = React.useRef<ValueType | null>(null);\n React.useEffect(() => {\n ref.current = value;\n }, [value]);\n return ref.current;\n};\n"],"names":["usePrevious","value","ref","React","useRef","useEffect","current"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAKaA;;;eAAAA;;;;iEALU;AAKhB,MAAMA,cAAc,CAAsBC;IAC/C,MAAMC,MAAMC,OAAMC,MAAM,CAAmB;IAC3CD,OAAME,SAAS,CAAC;QACdH,IAAII,OAAO,GAAGL;IAChB,GAAG;QAACA;KAAM;IACV,OAAOC,IAAII,OAAO;AACpB"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useScrollbarWidth.ts"],"sourcesContent":["import * as React from 'react';\n\nconst cache = new WeakMap<Document, number>();\n\ninterface UseScrollbarWidthOptions {\n /**\n * Reference document to measure the scrollbar width\n */\n targetDocument: Document | null | undefined;\n\n /**\n * Does not use the cache and recalculates the scrollbar width\n */\n force?: boolean;\n}\n\n/**\n * @returns The width in pixels of the scrollbar in the user agent\n */\nexport function useScrollbarWidth(options: UseScrollbarWidthOptions) {\n const { targetDocument, force } = options;\n return React.useMemo(() => {\n if (!targetDocument) {\n return 0;\n }\n\n if (!force && cache.has(targetDocument)) {\n return cache.get(targetDocument);\n }\n\n const outer = targetDocument.createElement('div');\n outer.style.visibility = 'hidden';\n outer.style.overflow = 'scroll';\n\n const inner = targetDocument.createElement('div');\n outer.appendChild(inner);\n\n targetDocument.body.appendChild(outer);\n const scrollbarWidth = outer.offsetWidth - inner.offsetWidth;\n outer.remove();\n cache.set(targetDocument, scrollbarWidth);\n return scrollbarWidth;\n }, [targetDocument, force]);\n}\n"],"names":["useScrollbarWidth","cache","WeakMap","options","targetDocument","force","React","useMemo","has","get","outer","createElement","style","visibility","overflow","inner","appendChild","body","scrollbarWidth","offsetWidth","remove","set"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAmBgBA;;;eAAAA;;;;iEAnBO;AAEvB,MAAMC,QAAQ,IAAIC;AAiBX,SAASF,kBAAkBG,OAAiC;IACjE,MAAM,EAAEC,cAAc,EAAEC,KAAK,EAAE,GAAGF;IAClC,OAAOG,OAAMC,OAAO,CAAC;QACnB,IAAI,CAACH,gBAAgB;YACnB,OAAO;QACT;QAEA,IAAI,CAACC,SAASJ,MAAMO,GAAG,CAACJ,iBAAiB;YACvC,OAAOH,MAAMQ,GAAG,CAACL;QACnB;QAEA,MAAMM,QAAQN,eAAeO,aAAa,CAAC;QAC3CD,MAAME,KAAK,CAACC,UAAU,GAAG;QACzBH,MAAME,KAAK,CAACE,QAAQ,GAAG;QAEvB,MAAMC,QAAQX,eAAeO,aAAa,CAAC;QAC3CD,MAAMM,WAAW,CAACD;QAElBX,eAAea,IAAI,CAACD,WAAW,CAACN;QAChC,MAAMQ,iBAAiBR,MAAMS,WAAW,GAAGJ,MAAMI,WAAW;QAC5DT,MAAMU,MAAM;QACZnB,MAAMoB,GAAG,CAACjB,gBAAgBc;QAC1B,OAAOA;IACT,GAAG;QAACd;QAAgBC;KAAM;AAC5B"}
|
1
|
+
{"version":3,"sources":["../src/hooks/useScrollbarWidth.ts"],"sourcesContent":["import * as React from 'react';\n\nconst cache = new WeakMap<Document, number>();\n\ninterface UseScrollbarWidthOptions {\n /**\n * Reference document to measure the scrollbar width\n */\n targetDocument: Document | null | undefined;\n\n /**\n * Does not use the cache and recalculates the scrollbar width\n */\n force?: boolean;\n}\n\n/**\n * @returns The width in pixels of the scrollbar in the user agent\n */\nexport function useScrollbarWidth(options: UseScrollbarWidthOptions) {\n const { targetDocument, force } = options;\n return React.useMemo(() => {\n if (!targetDocument) {\n return 0;\n }\n\n if (!force && cache.has(targetDocument)) {\n return cache.get(targetDocument);\n }\n\n const outer = targetDocument.createElement('div');\n outer.style.visibility = 'hidden';\n outer.style.overflow = 'scroll';\n\n const inner = targetDocument.createElement('div');\n outer.appendChild(inner);\n\n targetDocument.body.appendChild(outer);\n const scrollbarWidth = outer.offsetWidth - inner.offsetWidth;\n outer.remove();\n cache.set(targetDocument, scrollbarWidth);\n return scrollbarWidth;\n }, [targetDocument, force]);\n}\n"],"names":["useScrollbarWidth","cache","WeakMap","options","targetDocument","force","React","useMemo","has","get","outer","createElement","style","visibility","overflow","inner","appendChild","body","scrollbarWidth","offsetWidth","remove","set"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAmBgBA;;;eAAAA;;;;iEAnBO;AAEvB,MAAMC,QAAQ,IAAIC;AAiBX,SAASF,kBAAkBG,OAAiC;IACjE,MAAM,EAAEC,cAAc,EAAEC,KAAK,EAAE,GAAGF;IAClC,OAAOG,OAAMC,OAAO,CAAC;QACnB,IAAI,CAACH,gBAAgB;YACnB,OAAO;QACT;QAEA,IAAI,CAACC,SAASJ,MAAMO,GAAG,CAACJ,iBAAiB;YACvC,OAAOH,MAAMQ,GAAG,CAACL;QACnB;QAEA,MAAMM,QAAQN,eAAeO,aAAa,CAAC;QAC3CD,MAAME,KAAK,CAACC,UAAU,GAAG;QACzBH,MAAME,KAAK,CAACE,QAAQ,GAAG;QAEvB,MAAMC,QAAQX,eAAeO,aAAa,CAAC;QAC3CD,MAAMM,WAAW,CAACD;QAElBX,eAAea,IAAI,CAACD,WAAW,CAACN;QAChC,MAAMQ,iBAAiBR,MAAMS,WAAW,GAAGJ,MAAMI,WAAW;QAC5DT,MAAMU,MAAM;QACZnB,MAAMoB,GAAG,CAACjB,gBAAgBc;QAC1B,OAAOA;IACT,GAAG;QAACd;QAAgBC;KAAM;AAC5B"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useTimeout.ts"],"sourcesContent":["import { useBrowserTimer } from './useBrowserTimer';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nconst setTimeoutNoop = (_callback: Function) => -1;\nconst clearTimeoutNoop = (_handle: number) => undefined;\n\n/**\n * @internal\n * Helper to manage a browser timeout.\n * Ensures that the timeout isn't set multiple times at once and is cleaned up\n * when the component is unloaded.\n *\n * @returns A pair of [setTimeout, clearTimeout] that are stable between renders.\n */\nexport function useTimeout() {\n const { targetDocument } = useFluent();\n const win = targetDocument?.defaultView;\n\n const setTimerFn = win ? win.setTimeout : setTimeoutNoop;\n const clearTimerFn = win ? win.clearTimeout : clearTimeoutNoop;\n\n return useBrowserTimer(setTimerFn, clearTimerFn);\n}\n"],"names":["useTimeout","setTimeoutNoop","_callback","clearTimeoutNoop","_handle","undefined","targetDocument","useFluent","win","defaultView","setTimerFn","setTimeout","clearTimerFn","clearTimeout","useBrowserTimer"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAcgBA;;;eAAAA;;;iCAdgB;qCACgB;AAEhD,MAAMC,iBAAiB,CAACC,YAAwB,CAAC;AACjD,MAAMC,mBAAmB,CAACC,UAAoBC;AAUvC,SAASL;IACd,MAAM,EAAEM,cAAc,EAAE,GAAGC,IAAAA,
|
1
|
+
{"version":3,"sources":["../src/hooks/useTimeout.ts"],"sourcesContent":["import { useBrowserTimer } from './useBrowserTimer';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nconst setTimeoutNoop = (_callback: Function) => -1;\nconst clearTimeoutNoop = (_handle: number) => undefined;\n\n/**\n * @internal\n * Helper to manage a browser timeout.\n * Ensures that the timeout isn't set multiple times at once and is cleaned up\n * when the component is unloaded.\n *\n * @returns A pair of [setTimeout, clearTimeout] that are stable between renders.\n */\nexport function useTimeout() {\n const { targetDocument } = useFluent();\n const win = targetDocument?.defaultView;\n\n const setTimerFn = win ? win.setTimeout : setTimeoutNoop;\n const clearTimerFn = win ? win.clearTimeout : clearTimeoutNoop;\n\n return useBrowserTimer(setTimerFn, clearTimerFn);\n}\n"],"names":["useTimeout","setTimeoutNoop","_callback","clearTimeoutNoop","_handle","undefined","targetDocument","useFluent","win","defaultView","setTimerFn","setTimeout","clearTimerFn","clearTimeout","useBrowserTimer"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAcgBA;;;eAAAA;;;iCAdgB;qCACgB;AAEhD,MAAMC,iBAAiB,CAACC,YAAwB,CAAC;AACjD,MAAMC,mBAAmB,CAACC,UAAoBC;AAUvC,SAASL;IACd,MAAM,EAAEM,cAAc,EAAE,GAAGC,IAAAA,uCAAS;IACpC,MAAMC,MAAMF,2BAAAA,qCAAAA,eAAgBG,WAAW;IAEvC,MAAMC,aAAaF,MAAMA,IAAIG,UAAU,GAAGV;IAC1C,MAAMW,eAAeJ,MAAMA,IAAIK,YAAY,GAAGV;IAE9C,OAAOW,IAAAA,gCAAe,EAACJ,YAAYE;AACrC"}
|
package/lib-commonjs/index.js
CHANGED
@@ -45,6 +45,7 @@ _export(exports, {
|
|
45
45
|
getIntrinsicElementProps: function() {
|
46
46
|
return _index.getIntrinsicElementProps;
|
47
47
|
},
|
48
|
+
// eslint-disable-next-line deprecation/deprecation
|
48
49
|
getNativeElementProps: function() {
|
49
50
|
return _index3.getNativeElementProps;
|
50
51
|
},
|
@@ -57,9 +58,11 @@ _export(exports, {
|
|
57
58
|
getRTLSafeKey: function() {
|
58
59
|
return _index3.getRTLSafeKey;
|
59
60
|
},
|
61
|
+
// eslint-disable-next-line deprecation/deprecation
|
60
62
|
getSlots: function() {
|
61
63
|
return _index.getSlots;
|
62
64
|
},
|
65
|
+
// eslint-disable-next-line deprecation/deprecation
|
63
66
|
getSlotsNext: function() {
|
64
67
|
return _index.getSlotsNext;
|
65
68
|
},
|
@@ -96,6 +99,7 @@ _export(exports, {
|
|
96
99
|
resetIdsForTests: function() {
|
97
100
|
return _index1.resetIdsForTests;
|
98
101
|
},
|
102
|
+
// eslint-disable-next-line deprecation/deprecation
|
99
103
|
resolveShorthand: function() {
|
100
104
|
return _index.resolveShorthand;
|
101
105
|
},
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["index.ts"],"sourcesContent":["export {\n slot,\n isSlot,\n // eslint-disable-next-line deprecation/deprecation\n getSlots,\n // eslint-disable-next-line deprecation/deprecation\n getSlotsNext,\n assertSlots,\n // eslint-disable-next-line deprecation/deprecation\n resolveShorthand,\n isResolvedShorthand,\n getIntrinsicElementProps,\n SLOT_ELEMENT_TYPE_SYMBOL,\n SLOT_RENDER_FUNCTION_SYMBOL,\n} from './compose/index';\nexport type {\n ExtractSlotProps,\n ComponentProps,\n ComponentState,\n ForwardRefComponent,\n // eslint-disable-next-line deprecation/deprecation\n ResolveShorthandFunction,\n // eslint-disable-next-line deprecation/deprecation\n ResolveShorthandOptions,\n Slot,\n // eslint-disable-next-line deprecation/deprecation\n Slots,\n SlotClassNames,\n SlotPropsRecord,\n SlotRenderFunction,\n SlotShorthandValue,\n UnknownSlotProps,\n SlotComponentType,\n SlotOptions,\n InferredElementRefType,\n EventData,\n EventHandler,\n} from './compose/index';\n\nexport {\n IdPrefixProvider,\n resetIdsForTests,\n useAnimationFrame,\n useControllableState,\n useEventCallback,\n useFirstMount,\n useForceUpdate,\n useId,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n useOnClickOutside,\n useOnScrollOutside,\n usePrevious,\n useScrollbarWidth,\n useTimeout,\n} from './hooks/index';\nexport type { RefObjectFunction, UseControllableStateOptions, UseOnClickOrScrollOutsideOptions } from './hooks/index';\n\nexport { canUseDOM, useIsSSR, SSRProvider } from './ssr/index';\n\nexport {\n clamp,\n // eslint-disable-next-line deprecation/deprecation\n getNativeElementProps,\n getPartitionedNativeProps,\n getRTLSafeKey,\n mergeCallbacks,\n isHTMLElement,\n isInteractiveHTMLElement,\n omit,\n createPriorityQueue,\n} from './utils/index';\n\nexport type { DistributiveOmit, UnionToIntersection } from './utils/types';\n\nexport type { PriorityQueue } from './utils/priorityQueue';\n\nexport { applyTriggerPropsToChildren, getTriggerChild, isFluentTrigger } from './trigger/index';\n\nexport type { FluentTriggerComponent, TriggerProps } from './trigger/index';\n\n/**\n * Event utils\n */\nexport type { NativeTouchOrMouseEvent, ReactTouchOrMouseEvent, TouchOrMouseEvent } from './events/index';\nexport { isTouchEvent, isMouseEvent, getEventClientCoords } from './events/index';\n\nexport type {\n SelectionMode,\n OnSelectionChangeCallback,\n OnSelectionChangeData,\n SelectionItemId,\n SelectionHookParams,\n SelectionMethods,\n} from './selection/index';\nexport { useSelection } from './selection/index';\n\nexport { elementContains, setVirtualParent, getParent } from './virtualParent/index';\n"],"names":["IdPrefixProvider","SLOT_ELEMENT_TYPE_SYMBOL","SLOT_RENDER_FUNCTION_SYMBOL","SSRProvider","applyTriggerPropsToChildren","assertSlots","canUseDOM","clamp","createPriorityQueue","elementContains","getEventClientCoords","getIntrinsicElementProps","getNativeElementProps","getParent","getPartitionedNativeProps","getRTLSafeKey","getSlots","getSlotsNext","getTriggerChild","isFluentTrigger","isHTMLElement","isInteractiveHTMLElement","isMouseEvent","isResolvedShorthand","isSlot","isTouchEvent","mergeCallbacks","omit","resetIdsForTests","resolveShorthand","setVirtualParent","slot","useAnimationFrame","useControllableState","useEventCallback","useFirstMount","useForceUpdate","useId","useIsSSR","useIsomorphicLayoutEffect","useMergedRefs","useOnClickOutside","useOnScrollOutside","usePrevious","useScrollbarWidth","useSelection","useTimeout"],"rangeMappings":"
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export {\n slot,\n isSlot,\n // eslint-disable-next-line deprecation/deprecation\n getSlots,\n // eslint-disable-next-line deprecation/deprecation\n getSlotsNext,\n assertSlots,\n // eslint-disable-next-line deprecation/deprecation\n resolveShorthand,\n isResolvedShorthand,\n getIntrinsicElementProps,\n SLOT_ELEMENT_TYPE_SYMBOL,\n SLOT_RENDER_FUNCTION_SYMBOL,\n} from './compose/index';\nexport type {\n ExtractSlotProps,\n ComponentProps,\n ComponentState,\n ForwardRefComponent,\n // eslint-disable-next-line deprecation/deprecation\n ResolveShorthandFunction,\n // eslint-disable-next-line deprecation/deprecation\n ResolveShorthandOptions,\n Slot,\n // eslint-disable-next-line deprecation/deprecation\n Slots,\n SlotClassNames,\n SlotPropsRecord,\n SlotRenderFunction,\n SlotShorthandValue,\n UnknownSlotProps,\n SlotComponentType,\n SlotOptions,\n InferredElementRefType,\n EventData,\n EventHandler,\n} from './compose/index';\n\nexport {\n IdPrefixProvider,\n resetIdsForTests,\n useAnimationFrame,\n useControllableState,\n useEventCallback,\n useFirstMount,\n useForceUpdate,\n useId,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n useOnClickOutside,\n useOnScrollOutside,\n usePrevious,\n useScrollbarWidth,\n useTimeout,\n} from './hooks/index';\nexport type { RefObjectFunction, UseControllableStateOptions, UseOnClickOrScrollOutsideOptions } from './hooks/index';\n\nexport { canUseDOM, useIsSSR, SSRProvider } from './ssr/index';\n\nexport {\n clamp,\n // eslint-disable-next-line deprecation/deprecation\n getNativeElementProps,\n getPartitionedNativeProps,\n getRTLSafeKey,\n mergeCallbacks,\n isHTMLElement,\n isInteractiveHTMLElement,\n omit,\n createPriorityQueue,\n} from './utils/index';\n\nexport type { DistributiveOmit, UnionToIntersection } from './utils/types';\n\nexport type { PriorityQueue } from './utils/priorityQueue';\n\nexport { applyTriggerPropsToChildren, getTriggerChild, isFluentTrigger } from './trigger/index';\n\nexport type { FluentTriggerComponent, TriggerProps } from './trigger/index';\n\n/**\n * Event utils\n */\nexport type { NativeTouchOrMouseEvent, ReactTouchOrMouseEvent, TouchOrMouseEvent } from './events/index';\nexport { isTouchEvent, isMouseEvent, getEventClientCoords } from './events/index';\n\nexport type {\n SelectionMode,\n OnSelectionChangeCallback,\n OnSelectionChangeData,\n SelectionItemId,\n SelectionHookParams,\n SelectionMethods,\n} from './selection/index';\nexport { useSelection } from './selection/index';\n\nexport { elementContains, setVirtualParent, getParent } from './virtualParent/index';\n"],"names":["IdPrefixProvider","SLOT_ELEMENT_TYPE_SYMBOL","SLOT_RENDER_FUNCTION_SYMBOL","SSRProvider","applyTriggerPropsToChildren","assertSlots","canUseDOM","clamp","createPriorityQueue","elementContains","getEventClientCoords","getIntrinsicElementProps","getNativeElementProps","getParent","getPartitionedNativeProps","getRTLSafeKey","getSlots","getSlotsNext","getTriggerChild","isFluentTrigger","isHTMLElement","isInteractiveHTMLElement","isMouseEvent","isResolvedShorthand","isSlot","isTouchEvent","mergeCallbacks","omit","resetIdsForTests","resolveShorthand","setVirtualParent","slot","useAnimationFrame","useControllableState","useEventCallback","useFirstMount","useForceUpdate","useId","useIsSSR","useIsomorphicLayoutEffect","useMergedRefs","useOnClickOutside","useOnScrollOutside","usePrevious","useScrollbarWidth","useSelection","useTimeout"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAwCEA,gBAAgB;eAAhBA,wBAAgB;;IA5BhBC,wBAAwB;eAAxBA,+BAAwB;;IACxBC,2BAA2B;eAA3BA,kCAA2B;;IA6CCC,WAAW;eAAXA,mBAAW;;IAmBhCC,2BAA2B;eAA3BA,mCAA2B;;IAtElCC,WAAW;eAAXA,kBAAW;;IAmDJC,SAAS;eAATA,iBAAS;;IAGhBC,KAAK;eAALA,aAAK;;IASLC,mBAAmB;eAAnBA,2BAAmB;;IA2BZC,eAAe;eAAfA,uBAAe;;IAZaC,oBAAoB;eAApBA,4BAAoB;;IA1EvDC,wBAAwB;eAAxBA,+BAAwB;;IAmDxB,mDAAmD;IACnDC,qBAAqB;eAArBA,6BAAqB;;IAkCqBC,SAAS;eAATA,iBAAS;;IAjCnDC,yBAAyB;eAAzBA,iCAAyB;;IACzBC,aAAa;eAAbA,qBAAa;;IA9Db,mDAAmD;IACnDC,QAAQ;eAARA,eAAQ;;IACR,mDAAmD;IACnDC,YAAY;eAAZA,mBAAY;;IAuEwBC,eAAe;eAAfA,uBAAe;;IAAEC,eAAe;eAAfA,uBAAe;;IAVpEC,aAAa;eAAbA,qBAAa;;IACbC,wBAAwB;eAAxBA,gCAAwB;;IAiBHC,YAAY;eAAZA,oBAAY;;IA3EjCC,mBAAmB;eAAnBA,0BAAmB;;IARnBC,MAAM;eAANA,aAAM;;IAmFCC,YAAY;eAAZA,oBAAY;;IAnBnBC,cAAc;eAAdA,sBAAc;;IAGdC,IAAI;eAAJA,YAAI;;IA5BJC,gBAAgB;eAAhBA,wBAAgB;;IAjChB,mDAAmD;IACnDC,gBAAgB;eAAhBA,uBAAgB;;IAwFQC,gBAAgB;eAAhBA,wBAAgB;;IAhGxCC,IAAI;eAAJA,WAAI;;IAyCJC,iBAAiB;eAAjBA,yBAAiB;;IACjBC,oBAAoB;eAApBA,4BAAoB;;IACpBC,gBAAgB;eAAhBA,wBAAgB;;IAChBC,aAAa;eAAbA,qBAAa;;IACbC,cAAc;eAAdA,sBAAc;;IACdC,KAAK;eAALA,aAAK;;IAWaC,QAAQ;eAARA,gBAAQ;;IAV1BC,yBAAyB;eAAzBA,iCAAyB;;IACzBC,aAAa;eAAbA,qBAAa;;IACbC,iBAAiB;eAAjBA,yBAAiB;;IACjBC,kBAAkB;eAAlBA,0BAAkB;;IAClBC,WAAW;eAAXA,mBAAW;;IACXC,iBAAiB;eAAjBA,yBAAiB;;IA0CVC,YAAY;eAAZA,oBAAY;;IAzCnBC,UAAU;eAAVA,kBAAU;;;uBAxCL;wBAyCA;wBAG0C;wBAa1C;wBAMuE;wBAQb;wBAUpC;wBAEgC"}
|
@@ -2,6 +2,10 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
3
3
|
value: true
|
4
4
|
});
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
Object.defineProperty(exports, "useSelection", {
|
6
|
+
enumerable: true,
|
7
|
+
get: function() {
|
8
|
+
return _useSelection.useSelection;
|
9
|
+
}
|
10
|
+
});
|
11
|
+
const _useSelection = require("./useSelection");
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["index.ts"],"sourcesContent":["export
|
1
|
+
{"version":3,"sources":["../src/selection/index.ts"],"sourcesContent":["export type {\n OnSelectionChangeCallback,\n OnSelectionChangeData,\n SelectionHookParams,\n SelectionItemId,\n SelectionMethods,\n SelectionMode,\n} from './types';\nexport { useSelection } from './useSelection';\n"],"names":["useSelection"],"rangeMappings":";;;;;;;;;;","mappings":";;;;+BAQSA;;;eAAAA,0BAAY;;;8BAAQ"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["types.ts"],"sourcesContent":["import * as React from 'react';\n\nexport type SelectionMode = 'single' | 'multiselect';\n\nexport interface SelectionMethods {\n toggleItem(event: React.SyntheticEvent, id: SelectionItemId): void;\n selectItem(event: React.SyntheticEvent, id: SelectionItemId): void;\n deselectItem(event: React.SyntheticEvent, id: SelectionItemId): void;\n clearItems(event: React.SyntheticEvent): void;\n isSelected(id: SelectionItemId): boolean;\n toggleAllItems(event: React.SyntheticEvent, itemIds: SelectionItemId[]): void;\n}\n\nexport type SelectionItemId = string | number;\n\nexport type OnSelectionChangeCallback = (event: React.SyntheticEvent, selectedItems: Set<SelectionItemId>) => void;\n\nexport type OnSelectionChangeData = {\n selectedItems: Set<SelectionItemId>;\n};\n\nexport type SelectionHookParams = {\n selectionMode: SelectionMode;\n /**\n * Used in uncontrolled mode to set initial selected items on mount\n */\n defaultSelectedItems?: Iterable<SelectionItemId>;\n /**\n * Used to control selected items\n */\n selectedItems?: Iterable<SelectionItemId>;\n /**\n * Called when selection changes\n */\n onSelectionChange?(event: React.SyntheticEvent, data: OnSelectionChangeData): void;\n};\n"],"names":[],"rangeMappings":";;;;;","mappings":";;;;;iEAAuB"}
|
1
|
+
{"version":3,"sources":["../src/selection/types.ts"],"sourcesContent":["import * as React from 'react';\n\nexport type SelectionMode = 'single' | 'multiselect';\n\nexport interface SelectionMethods {\n toggleItem(event: React.SyntheticEvent, id: SelectionItemId): void;\n selectItem(event: React.SyntheticEvent, id: SelectionItemId): void;\n deselectItem(event: React.SyntheticEvent, id: SelectionItemId): void;\n clearItems(event: React.SyntheticEvent): void;\n isSelected(id: SelectionItemId): boolean;\n toggleAllItems(event: React.SyntheticEvent, itemIds: SelectionItemId[]): void;\n}\n\nexport type SelectionItemId = string | number;\n\nexport type OnSelectionChangeCallback = (event: React.SyntheticEvent, selectedItems: Set<SelectionItemId>) => void;\n\nexport type OnSelectionChangeData = {\n selectedItems: Set<SelectionItemId>;\n};\n\nexport type SelectionHookParams = {\n selectionMode: SelectionMode;\n /**\n * Used in uncontrolled mode to set initial selected items on mount\n */\n defaultSelectedItems?: Iterable<SelectionItemId>;\n /**\n * Used to control selected items\n */\n selectedItems?: Iterable<SelectionItemId>;\n /**\n * Called when selection changes\n */\n onSelectionChange?(event: React.SyntheticEvent, data: OnSelectionChangeData): void;\n};\n"],"names":[],"rangeMappings":";;;;;","mappings":";;;;;iEAAuB"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useSelection.ts"],"sourcesContent":["import * as React from 'react';\nimport { SelectionHookParams, SelectionItemId, SelectionMethods } from './types';\nimport { useControllableState } from '../hooks/useControllableState';\nimport { createSetFromIterable } from '../utils/createSetFromIterable';\n\nfunction useSelectionState(params: Omit<SelectionHookParams, 'selectionMode'>) {\n const [selected, setSelected] = useControllableState<Set<SelectionItemId>>({\n initialState: new Set(),\n defaultState: React.useMemo(\n () => params.defaultSelectedItems && createSetFromIterable(params.defaultSelectedItems),\n [params.defaultSelectedItems],\n ),\n state: React.useMemo(\n () => params.selectedItems && createSetFromIterable(params.selectedItems),\n [params.selectedItems],\n ),\n });\n const changeSelection = (event: React.SyntheticEvent, nextSelectedItems: Set<SelectionItemId>) => {\n params.onSelectionChange?.(event, { selectedItems: nextSelectedItems });\n setSelected(nextSelectedItems);\n };\n return [selected, changeSelection] as const;\n}\n\nfunction useSingleSelection(params: Omit<SelectionHookParams, 'selectionMode'>) {\n const [selected, changeSelection] = useSelectionState(params);\n const methods: SelectionMethods = {\n deselectItem: event => changeSelection(event, new Set()),\n selectItem: (event, itemId) => changeSelection(event, new Set([itemId])),\n toggleAllItems: () => {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('[react-utilities]: `toggleAllItems` should not be used in single selection mode');\n }\n },\n toggleItem: (event, itemId) => changeSelection(event, new Set([itemId])),\n clearItems: event => changeSelection(event, new Set()),\n isSelected: itemId => selected.has(itemId) ?? false,\n };\n return [selected, methods] as const;\n}\n\nfunction useMultipleSelection(params: Omit<SelectionHookParams, 'selectionMode'>) {\n const [selected, changeSelection] = useSelectionState(params);\n const methods: SelectionMethods = {\n toggleItem: (event, itemId) => {\n const nextSelectedItems = new Set(selected);\n if (selected.has(itemId)) {\n nextSelectedItems.delete(itemId);\n } else {\n nextSelectedItems.add(itemId);\n }\n changeSelection(event, nextSelectedItems);\n },\n selectItem: (event, itemId) => {\n const nextSelectedItems = new Set(selected);\n nextSelectedItems.add(itemId);\n changeSelection(event, nextSelectedItems);\n },\n deselectItem: (event, itemId) => {\n const nextSelectedItems = new Set(selected);\n nextSelectedItems.delete(itemId);\n changeSelection(event, nextSelectedItems);\n },\n clearItems: event => {\n changeSelection(event, new Set());\n },\n isSelected: itemId => selected.has(itemId),\n toggleAllItems: (event, itemIds) => {\n const allItemsSelected = itemIds.every(itemId => selected.has(itemId));\n const nextSelectedItems = new Set(selected);\n if (allItemsSelected) {\n nextSelectedItems.clear();\n } else {\n itemIds.forEach(itemId => nextSelectedItems.add(itemId));\n }\n changeSelection(event, nextSelectedItems);\n },\n };\n return [selected, methods] as const;\n}\n\nexport function useSelection(params: SelectionHookParams) {\n 'use no memo';\n\n if (params.selectionMode === 'multiselect') {\n // selectionMode is a static value, so we can safely ignore rules-of-hooks\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useMultipleSelection(params);\n }\n // selectionMode is a static value, so we can safely ignore rules-of-hooks\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useSingleSelection(params);\n}\n"],"names":["useSelection","useSelectionState","params","selected","setSelected","useControllableState","initialState","Set","defaultState","React","useMemo","defaultSelectedItems","createSetFromIterable","state","selectedItems","changeSelection","event","nextSelectedItems","onSelectionChange","useSingleSelection","methods","deselectItem","selectItem","itemId","toggleAllItems","process","env","NODE_ENV","Error","toggleItem","clearItems","isSelected","has","useMultipleSelection","delete","add","itemIds","allItemsSelected","every","clear","forEach","selectionMode"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAiFgBA;;;eAAAA;;;;iEAjFO;sCAEc;uCACC;AAEtC,SAASC,kBAAkBC,MAAkD;IAC3E,MAAM,CAACC,UAAUC,YAAY,GAAGC,IAAAA,
|
1
|
+
{"version":3,"sources":["../src/selection/useSelection.ts"],"sourcesContent":["import * as React from 'react';\nimport { SelectionHookParams, SelectionItemId, SelectionMethods } from './types';\nimport { useControllableState } from '../hooks/useControllableState';\nimport { createSetFromIterable } from '../utils/createSetFromIterable';\n\nfunction useSelectionState(params: Omit<SelectionHookParams, 'selectionMode'>) {\n const [selected, setSelected] = useControllableState<Set<SelectionItemId>>({\n initialState: new Set(),\n defaultState: React.useMemo(\n () => params.defaultSelectedItems && createSetFromIterable(params.defaultSelectedItems),\n [params.defaultSelectedItems],\n ),\n state: React.useMemo(\n () => params.selectedItems && createSetFromIterable(params.selectedItems),\n [params.selectedItems],\n ),\n });\n const changeSelection = (event: React.SyntheticEvent, nextSelectedItems: Set<SelectionItemId>) => {\n params.onSelectionChange?.(event, { selectedItems: nextSelectedItems });\n setSelected(nextSelectedItems);\n };\n return [selected, changeSelection] as const;\n}\n\nfunction useSingleSelection(params: Omit<SelectionHookParams, 'selectionMode'>) {\n const [selected, changeSelection] = useSelectionState(params);\n const methods: SelectionMethods = {\n deselectItem: event => changeSelection(event, new Set()),\n selectItem: (event, itemId) => changeSelection(event, new Set([itemId])),\n toggleAllItems: () => {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('[react-utilities]: `toggleAllItems` should not be used in single selection mode');\n }\n },\n toggleItem: (event, itemId) => changeSelection(event, new Set([itemId])),\n clearItems: event => changeSelection(event, new Set()),\n isSelected: itemId => selected.has(itemId) ?? false,\n };\n return [selected, methods] as const;\n}\n\nfunction useMultipleSelection(params: Omit<SelectionHookParams, 'selectionMode'>) {\n const [selected, changeSelection] = useSelectionState(params);\n const methods: SelectionMethods = {\n toggleItem: (event, itemId) => {\n const nextSelectedItems = new Set(selected);\n if (selected.has(itemId)) {\n nextSelectedItems.delete(itemId);\n } else {\n nextSelectedItems.add(itemId);\n }\n changeSelection(event, nextSelectedItems);\n },\n selectItem: (event, itemId) => {\n const nextSelectedItems = new Set(selected);\n nextSelectedItems.add(itemId);\n changeSelection(event, nextSelectedItems);\n },\n deselectItem: (event, itemId) => {\n const nextSelectedItems = new Set(selected);\n nextSelectedItems.delete(itemId);\n changeSelection(event, nextSelectedItems);\n },\n clearItems: event => {\n changeSelection(event, new Set());\n },\n isSelected: itemId => selected.has(itemId),\n toggleAllItems: (event, itemIds) => {\n const allItemsSelected = itemIds.every(itemId => selected.has(itemId));\n const nextSelectedItems = new Set(selected);\n if (allItemsSelected) {\n nextSelectedItems.clear();\n } else {\n itemIds.forEach(itemId => nextSelectedItems.add(itemId));\n }\n changeSelection(event, nextSelectedItems);\n },\n };\n return [selected, methods] as const;\n}\n\nexport function useSelection(params: SelectionHookParams) {\n 'use no memo';\n\n if (params.selectionMode === 'multiselect') {\n // selectionMode is a static value, so we can safely ignore rules-of-hooks\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useMultipleSelection(params);\n }\n // selectionMode is a static value, so we can safely ignore rules-of-hooks\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useSingleSelection(params);\n}\n"],"names":["useSelection","useSelectionState","params","selected","setSelected","useControllableState","initialState","Set","defaultState","React","useMemo","defaultSelectedItems","createSetFromIterable","state","selectedItems","changeSelection","event","nextSelectedItems","onSelectionChange","useSingleSelection","methods","deselectItem","selectItem","itemId","toggleAllItems","process","env","NODE_ENV","Error","toggleItem","clearItems","isSelected","has","useMultipleSelection","delete","add","itemIds","allItemsSelected","every","clear","forEach","selectionMode"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAiFgBA;;;eAAAA;;;;iEAjFO;sCAEc;uCACC;AAEtC,SAASC,kBAAkBC,MAAkD;IAC3E,MAAM,CAACC,UAAUC,YAAY,GAAGC,IAAAA,0CAAoB,EAAuB;QACzEC,cAAc,IAAIC;QAClBC,cAAcC,OAAMC,OAAO,CACzB,IAAMR,OAAOS,oBAAoB,IAAIC,IAAAA,4CAAqB,EAACV,OAAOS,oBAAoB,GACtF;YAACT,OAAOS,oBAAoB;SAAC;QAE/BE,OAAOJ,OAAMC,OAAO,CAClB,IAAMR,OAAOY,aAAa,IAAIF,IAAAA,4CAAqB,EAACV,OAAOY,aAAa,GACxE;YAACZ,OAAOY,aAAa;SAAC;IAE1B;IACA,MAAMC,kBAAkB,CAACC,OAA6BC;YACpDf;SAAAA,4BAAAA,OAAOgB,iBAAiB,cAAxBhB,gDAAAA,+BAAAA,QAA2Bc,OAAO;YAAEF,eAAeG;QAAkB;QACrEb,YAAYa;IACd;IACA,OAAO;QAACd;QAAUY;KAAgB;AACpC;AAEA,SAASI,mBAAmBjB,MAAkD;IAC5E,MAAM,CAACC,UAAUY,gBAAgB,GAAGd,kBAAkBC;IACtD,MAAMkB,UAA4B;QAChCC,cAAcL,CAAAA,QAASD,gBAAgBC,OAAO,IAAIT;QAClDe,YAAY,CAACN,OAAOO,SAAWR,gBAAgBC,OAAO,IAAIT,IAAI;gBAACgB;aAA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pBpB,kBAAkBsB,KAAK;YACzB,OAAO;gBACLH,QAAQI,OAAO,CAACjB,CAAAA,SAAUN,kBAAkBkB,GAAG,CAACZ;YAClD;YACAR,gBAAgBC,OAAOC;QACzB;IACF;IACA,OAAO;QAACd;QAAUiB;KAAQ;AAC5B;AAEO,SAASpB,aAAaE,MAA2B;IACtD;IAEA,IAAIA,OAAOuC,aAAa,KAAK,eAAe;QAC1C,0EAA0E;QAC1E,sDAAsD;QACtD,OAAOR,qBAAqB/B;IAC9B;IACA,0EAA0E;IAC1E,sDAAsD;IACtD,OAAOiB,mBAAmBjB;AAC5B"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["SSRContext.tsx"],"sourcesContent":["import * as React from 'react';\nimport { canUseDOM } from './canUseDOM';\n\n/**\n * To support SSR, the auto incrementing id counter is stored in a context. This allows it to be reset on every request\n * to ensure the client and server are consistent.\n *\n * @internal\n */\nexport type SSRContextValue = {\n current: number;\n};\n\n/**\n * Default context value to use in case there is no SSRProvider. This is fine for client-only apps.\n *\n * @internal\n */\nexport const defaultSSRContextValue: SSRContextValue = {\n current: 0,\n};\n\nexport const SSRContext = React.createContext<SSRContextValue | undefined>(undefined) as React.Context<SSRContextValue>;\n\n/**\n * @internal\n */\nexport function useSSRContext(): SSRContextValue {\n return React.useContext(SSRContext) ?? defaultSSRContextValue;\n}\n\n/**\n * When using SSR with Fluent UI, applications must be wrapped in an SSRProvider. This ensures that auto generated ids\n * are consistent between the client and server.\n *\n * @public\n */\nexport const SSRProvider: React.FC<{ children: React.ReactNode }> = props => {\n const [value] = React.useState<SSRContextValue>(() => ({ current: 0 }));\n\n return <SSRContext.Provider value={value}>{props.children}</SSRContext.Provider>;\n};\n\n/**\n * Returns whether the component is currently being server side rendered or hydrated on the client. Can be used to delay\n * browser-specific rendering until after hydration. May cause re-renders on a client when is used within SSRProvider.\n */\nexport function useIsSSR(): boolean {\n const isInSSRContext = useSSRContext() !== defaultSSRContextValue;\n const [isSSR, setIsSSR] = React.useState(isInSSRContext);\n\n // If we are rendering in a non-DOM environment, and there's no SSRProvider, provide a warning to hint to the\n // developer to add one.\n if (process.env.NODE_ENV !== 'production') {\n if (!isInSSRContext && !canUseDOM()) {\n // eslint-disable-next-line no-console\n console.error(/** #__DE-INDENT__ */ `\n @fluentui/react-components [${useIsSSR.name}]:\n When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are generated between the client and server.\n\n\n Check documentation at https://aka.ms/fluentui-ssr.\n `);\n }\n }\n\n // If on the client, and the component was initially server rendered, then schedule a layout effect to update the\n // component after hydration.\n if (canUseDOM() && isInSSRContext) {\n // This if statement technically breaks the rules of hooks, but is safe because the condition never changes after\n // mounting.\n // eslint-disable-next-line\n React.useLayoutEffect(() => {\n setIsSSR(false);\n }, []);\n }\n\n return isSSR;\n}\n"],"names":["SSRContext","SSRProvider","defaultSSRContextValue","useIsSSR","useSSRContext","current","React","createContext","undefined","useContext","props","value","useState","
|
1
|
+
{"version":3,"sources":["../src/ssr/SSRContext.tsx"],"sourcesContent":["import * as React from 'react';\nimport { canUseDOM } from './canUseDOM';\n\n/**\n * To support SSR, the auto incrementing id counter is stored in a context. This allows it to be reset on every request\n * to ensure the client and server are consistent.\n *\n * @internal\n */\nexport type SSRContextValue = {\n current: number;\n};\n\n/**\n * Default context value to use in case there is no SSRProvider. This is fine for client-only apps.\n *\n * @internal\n */\nexport const defaultSSRContextValue: SSRContextValue = {\n current: 0,\n};\n\nexport const SSRContext = React.createContext<SSRContextValue | undefined>(undefined) as React.Context<SSRContextValue>;\n\n/**\n * @internal\n */\nexport function useSSRContext(): SSRContextValue {\n return React.useContext(SSRContext) ?? defaultSSRContextValue;\n}\n\n/**\n * When using SSR with Fluent UI, applications must be wrapped in an SSRProvider. This ensures that auto generated ids\n * are consistent between the client and server.\n *\n * @public\n */\nexport const SSRProvider: React.FC<{ children: React.ReactNode }> = props => {\n const [value] = React.useState<SSRContextValue>(() => ({ current: 0 }));\n\n return <SSRContext.Provider value={value}>{props.children}</SSRContext.Provider>;\n};\n\n/**\n * Returns whether the component is currently being server side rendered or hydrated on the client. Can be used to delay\n * browser-specific rendering until after hydration. May cause re-renders on a client when is used within SSRProvider.\n */\nexport function useIsSSR(): boolean {\n const isInSSRContext = useSSRContext() !== defaultSSRContextValue;\n const [isSSR, setIsSSR] = React.useState(isInSSRContext);\n\n // If we are rendering in a non-DOM environment, and there's no SSRProvider, provide a warning to hint to the\n // developer to add one.\n if (process.env.NODE_ENV !== 'production') {\n if (!isInSSRContext && !canUseDOM()) {\n // eslint-disable-next-line no-console\n console.error(/** #__DE-INDENT__ */ `\n @fluentui/react-components [${useIsSSR.name}]:\n When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are generated between the client and server.\n\n\n Check documentation at https://aka.ms/fluentui-ssr.\n `);\n }\n }\n\n // If on the client, and the component was initially server rendered, then schedule a layout effect to update the\n // component after hydration.\n if (canUseDOM() && isInSSRContext) {\n // This if statement technically breaks the rules of hooks, but is safe because the condition never changes after\n // mounting.\n // eslint-disable-next-line\n React.useLayoutEffect(() => {\n setIsSSR(false);\n }, []);\n }\n\n return isSSR;\n}\n"],"names":["SSRContext","SSRProvider","defaultSSRContextValue","useIsSSR","useSSRContext","current","React","createContext","undefined","useContext","props","value","useState","Provider","children","isInSSRContext","isSSR","setIsSSR","process","env","NODE_ENV","canUseDOM","console","error","name","useLayoutEffect"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAsBaA,UAAU;eAAVA;;IAeAC,WAAW;eAAXA;;IAnBAC,sBAAsB;eAAtBA;;IA6BGC,QAAQ;eAARA;;IApBAC,aAAa;eAAbA;;;;iEA3BO;2BACG;AAiBnB,MAAMF,yBAA0C;IACrDG,SAAS;AACX;AAEO,MAAML,2BAAaM,OAAMC,aAAa,CAA8BC;AAKpE,SAASJ;QACPE;IAAP,OAAOA,CAAAA,oBAAAA,OAAMG,UAAU,CAACT,yBAAjBM,+BAAAA,oBAAgCJ;AACzC;AAQO,MAAMD,cAAuDS,CAAAA;IAClE,MAAM,CAACC,MAAM,GAAGL,OAAMM,QAAQ,CAAkB,IAAO,CAAA;YAAEP,SAAS;QAAE,CAAA;IAEpE,qBAAO,qBAACL,WAAWa,QAAQ;QAACF,OAAOA;OAAQD,MAAMI,QAAQ;AAC3D;AAMO,SAASX;IACd,MAAMY,iBAAiBX,oBAAoBF;IAC3C,MAAM,CAACc,OAAOC,SAAS,GAAGX,OAAMM,QAAQ,CAACG;IAEzC,6GAA6G;IAC7G,wBAAwB;IACxB,IAAIG,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,IAAI,CAACL,kBAAkB,CAACM,IAAAA,oBAAS,KAAI;YACnC,sCAAsC;YACtCC,QAAQC,KAAK,CAAuB,CAAC,4BACP,EAAEpB,SAASqB,IAAI,CAAC;;;;mDAK9C,CAAC;QACH;IACF;IAEA,iHAAiH;IACjH,6BAA6B;IAC7B,IAAIH,IAAAA,oBAAS,OAAMN,gBAAgB;QACjC,iHAAiH;QACjH,YAAY;QACZ,2BAA2B;QAC3BT,OAAMmB,eAAe,CAAC;YACpBR,SAAS;QACX,GAAG,EAAE;IACP;IAEA,OAAOD;AACT"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["canUseDOM.ts"],"sourcesContent":["/**\n * Verifies if an application can use DOM.\n */\nexport function canUseDOM(): boolean {\n return (\n /* eslint-disable @nx/workspace-no-restricted-globals -- expected ignore ( SSR friendly acquisition of globals )*/\n typeof window !== 'undefined' &&\n !!(\n window.document &&\n // eslint-disable-next-line deprecation/deprecation\n window.document.createElement\n )\n /* eslint-enable @nx/workspace-no-restricted-globals */\n );\n}\n"],"names":["canUseDOM","window","document","createElement"],"rangeMappings":";;;;;;;;;;;;;;;","mappings":"AAAA;;CAEC;;;;+BACeA;;;eAAAA;;;AAAT,SAASA;IACd,OACE,gHAAgH,GAChH,OAAOC,WAAW,eAClB,CAAC,CACCA,CAAAA,OAAOC,QAAQ,IACf,mDAAmD;IACnDD,OAAOC,QAAQ,CAACC,aAAa,
|
1
|
+
{"version":3,"sources":["../src/ssr/canUseDOM.ts"],"sourcesContent":["/**\n * Verifies if an application can use DOM.\n */\nexport function canUseDOM(): boolean {\n return (\n /* eslint-disable @nx/workspace-no-restricted-globals -- expected ignore ( SSR friendly acquisition of globals )*/\n typeof window !== 'undefined' &&\n !!(\n window.document &&\n // eslint-disable-next-line deprecation/deprecation\n window.document.createElement\n )\n /* eslint-enable @nx/workspace-no-restricted-globals */\n );\n}\n"],"names":["canUseDOM","window","document","createElement"],"rangeMappings":";;;;;;;;;;;;;;;","mappings":"AAAA;;CAEC;;;;+BACeA;;;eAAAA;;;AAAT,SAASA;IACd,OACE,gHAAgH,GAChH,OAAOC,WAAW,eAClB,CAAC,CACCA,CAAAA,OAAOC,QAAQ,IACf,mDAAmD;IACnDD,OAAOC,QAAQ,CAACC,aAAa,AAAD;AAIlC"}
|
@@ -2,6 +2,31 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
3
3
|
value: true
|
4
4
|
});
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
+
SSRContext: function() {
|
13
|
+
return _SSRContext.SSRContext;
|
14
|
+
},
|
15
|
+
SSRProvider: function() {
|
16
|
+
return _SSRContext.SSRProvider;
|
17
|
+
},
|
18
|
+
canUseDOM: function() {
|
19
|
+
return _canUseDOM.canUseDOM;
|
20
|
+
},
|
21
|
+
defaultSSRContextValue: function() {
|
22
|
+
return _SSRContext.defaultSSRContextValue;
|
23
|
+
},
|
24
|
+
useIsSSR: function() {
|
25
|
+
return _SSRContext.useIsSSR;
|
26
|
+
},
|
27
|
+
useSSRContext: function() {
|
28
|
+
return _SSRContext.useSSRContext;
|
29
|
+
}
|
30
|
+
});
|
31
|
+
const _canUseDOM = require("./canUseDOM");
|
32
|
+
const _SSRContext = require("./SSRContext");
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["index.ts"],"sourcesContent":["export
|
1
|
+
{"version":3,"sources":["../src/ssr/index.ts"],"sourcesContent":["export { canUseDOM } from './canUseDOM';\nexport type { SSRContextValue } from './SSRContext';\nexport { SSRContext, SSRProvider, defaultSSRContextValue, useIsSSR, useSSRContext } from './SSRContext';\n"],"names":["SSRContext","SSRProvider","canUseDOM","defaultSSRContextValue","useIsSSR","useSSRContext"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAESA,UAAU;eAAVA,sBAAU;;IAAEC,WAAW;eAAXA,uBAAW;;IAFvBC,SAAS;eAATA,oBAAS;;IAEgBC,sBAAsB;eAAtBA,kCAAsB;;IAAEC,QAAQ;eAARA,oBAAQ;;IAAEC,aAAa;eAAbA,yBAAa;;;2BAFvD;4BAE+D"}
|