@fluentui/react-positioning 9.0.0-alpha.6 → 9.0.0-alpha.60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. package/CHANGELOG.json +1116 -1
  2. package/CHANGELOG.md +520 -2
  3. package/dist/react-positioning.d.ts +72 -27
  4. package/lib/createVirtualElementFromClick.d.ts +6 -0
  5. package/lib/createVirtualElementFromClick.js +24 -0
  6. package/lib/createVirtualElementFromClick.js.map +1 -0
  7. package/lib/index.d.ts +3 -0
  8. package/lib/index.js +4 -0
  9. package/lib/index.js.map +1 -1
  10. package/lib/tsdoc-metadata.json +1 -1
  11. package/lib/types.d.ts +22 -27
  12. package/lib/types.js +1 -0
  13. package/lib/types.js.map +1 -1
  14. package/lib/usePopper.d.ts +21 -1
  15. package/lib/usePopper.js +67 -29
  16. package/lib/usePopper.js.map +1 -1
  17. package/lib/usePopperMouseTarget.d.ts +11 -0
  18. package/lib/usePopperMouseTarget.js +34 -0
  19. package/lib/usePopperMouseTarget.js.map +1 -0
  20. package/lib/utils/getBasePlacement.d.ts +8 -0
  21. package/lib/utils/getBasePlacement.js +10 -0
  22. package/lib/utils/getBasePlacement.js.map +1 -0
  23. package/lib/utils/getBoundary.d.ts +1 -1
  24. package/lib/utils/getBoundary.js +2 -3
  25. package/lib/utils/getBoundary.js.map +1 -1
  26. package/lib/utils/getReactFiberFromNode.js.map +1 -1
  27. package/lib/utils/getScrollParent.js.map +1 -1
  28. package/lib/utils/index.d.ts +5 -3
  29. package/lib/utils/index.js +5 -3
  30. package/lib/utils/index.js.map +1 -1
  31. package/lib/utils/mergeArrowOffset.d.ts +10 -0
  32. package/lib/utils/mergeArrowOffset.js +37 -0
  33. package/lib/utils/mergeArrowOffset.js.map +1 -0
  34. package/lib/utils/positioningHelper.d.ts +2 -2
  35. package/lib/utils/positioningHelper.js.map +1 -1
  36. package/lib/utils/resolvePositioningShorthand.d.ts +2 -0
  37. package/lib/utils/resolvePositioningShorthand.js +25 -0
  38. package/lib/utils/resolvePositioningShorthand.js.map +1 -0
  39. package/lib/utils/useCallbackRef.js.map +1 -1
  40. package/lib-commonjs/createVirtualElementFromClick.d.ts +6 -0
  41. package/lib-commonjs/createVirtualElementFromClick.js +28 -0
  42. package/lib-commonjs/createVirtualElementFromClick.js.map +1 -0
  43. package/lib-commonjs/index.d.ts +3 -0
  44. package/lib-commonjs/index.js +7 -0
  45. package/lib-commonjs/index.js.map +1 -1
  46. package/lib-commonjs/types.d.ts +22 -27
  47. package/lib-commonjs/types.js.map +1 -1
  48. package/lib-commonjs/usePopper.d.ts +21 -1
  49. package/lib-commonjs/usePopper.js +67 -28
  50. package/lib-commonjs/usePopper.js.map +1 -1
  51. package/lib-commonjs/usePopperMouseTarget.d.ts +11 -0
  52. package/lib-commonjs/usePopperMouseTarget.js +38 -0
  53. package/lib-commonjs/usePopperMouseTarget.js.map +1 -0
  54. package/lib-commonjs/utils/getBasePlacement.d.ts +8 -0
  55. package/lib-commonjs/utils/getBasePlacement.js +14 -0
  56. package/lib-commonjs/utils/getBasePlacement.js.map +1 -0
  57. package/lib-commonjs/utils/getBoundary.d.ts +1 -1
  58. package/lib-commonjs/utils/getBoundary.js +3 -3
  59. package/lib-commonjs/utils/getBoundary.js.map +1 -1
  60. package/lib-commonjs/utils/getReactFiberFromNode.js +1 -0
  61. package/lib-commonjs/utils/getReactFiberFromNode.js.map +1 -1
  62. package/lib-commonjs/utils/getScrollParent.js +5 -2
  63. package/lib-commonjs/utils/getScrollParent.js.map +1 -1
  64. package/lib-commonjs/utils/index.d.ts +5 -3
  65. package/lib-commonjs/utils/index.js +5 -3
  66. package/lib-commonjs/utils/index.js.map +1 -1
  67. package/lib-commonjs/utils/mergeArrowOffset.d.ts +10 -0
  68. package/lib-commonjs/utils/mergeArrowOffset.js +41 -0
  69. package/lib-commonjs/utils/mergeArrowOffset.js.map +1 -0
  70. package/lib-commonjs/utils/positioningHelper.d.ts +2 -2
  71. package/lib-commonjs/utils/positioningHelper.js +5 -2
  72. package/lib-commonjs/utils/positioningHelper.js.map +1 -1
  73. package/lib-commonjs/utils/resolvePositioningShorthand.d.ts +2 -0
  74. package/lib-commonjs/utils/resolvePositioningShorthand.js +29 -0
  75. package/lib-commonjs/utils/resolvePositioningShorthand.js.map +1 -0
  76. package/lib-commonjs/utils/useCallbackRef.js +1 -0
  77. package/lib-commonjs/utils/useCallbackRef.js.map +1 -1
  78. package/package.json +11 -8
  79. package/NOTICE.txt +0 -0
  80. package/config/api-extractor.json +0 -3
  81. package/etc/react-positioning.api.md +0 -69
  82. package/just.config.ts +0 -3
  83. package/lib/utils/isBrowser.d.ts +0 -1
  84. package/lib/utils/isBrowser.js +0 -4
  85. package/lib/utils/isBrowser.js.map +0 -1
  86. package/lib-amd/index.d.ts +0 -2
  87. package/lib-amd/index.js +0 -6
  88. package/lib-amd/index.js.map +0 -1
  89. package/lib-amd/types.d.ts +0 -73
  90. package/lib-amd/types.js +0 -5
  91. package/lib-amd/types.js.map +0 -1
  92. package/lib-amd/usePopper.d.ts +0 -15
  93. package/lib-amd/usePopper.js +0 -280
  94. package/lib-amd/usePopper.js.map +0 -1
  95. package/lib-amd/utils/getBoundary.d.ts +0 -6
  96. package/lib-amd/utils/getBoundary.js +0 -23
  97. package/lib-amd/utils/getBoundary.js.map +0 -1
  98. package/lib-amd/utils/getReactFiberFromNode.d.ts +0 -109
  99. package/lib-amd/utils/getReactFiberFromNode.js +0 -47
  100. package/lib-amd/utils/getReactFiberFromNode.js.map +0 -1
  101. package/lib-amd/utils/getScrollParent.d.ts +0 -12
  102. package/lib-amd/utils/getScrollParent.js +0 -55
  103. package/lib-amd/utils/getScrollParent.js.map +0 -1
  104. package/lib-amd/utils/index.d.ts +0 -6
  105. package/lib-amd/utils/index.js +0 -11
  106. package/lib-amd/utils/index.js.map +0 -1
  107. package/lib-amd/utils/isBrowser.d.ts +0 -1
  108. package/lib-amd/utils/isBrowser.js +0 -8
  109. package/lib-amd/utils/isBrowser.js.map +0 -1
  110. package/lib-amd/utils/positioningHelper.d.ts +0 -7
  111. package/lib-amd/utils/positioningHelper.js +0 -45
  112. package/lib-amd/utils/positioningHelper.js.map +0 -1
  113. package/lib-amd/utils/useCallbackRef.d.ts +0 -19
  114. package/lib-amd/utils/useCallbackRef.js +0 -54
  115. package/lib-amd/utils/useCallbackRef.js.map +0 -1
  116. package/lib-commonjs/utils/isBrowser.d.ts +0 -1
  117. package/lib-commonjs/utils/isBrowser.js +0 -6
  118. package/lib-commonjs/utils/isBrowser.js.map +0 -1
@@ -1,11 +0,0 @@
1
- define(["require", "exports", "tslib", "./isBrowser", "./positioningHelper", "./getBoundary", "./getScrollParent", "./getReactFiberFromNode", "./useCallbackRef"], function (require, exports, tslib_1, isBrowser_1, positioningHelper_1, getBoundary_1, getScrollParent_1, getReactFiberFromNode_1, useCallbackRef_1) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- tslib_1.__exportStar(isBrowser_1, exports);
5
- tslib_1.__exportStar(positioningHelper_1, exports);
6
- tslib_1.__exportStar(getBoundary_1, exports);
7
- tslib_1.__exportStar(getScrollParent_1, exports);
8
- tslib_1.__exportStar(getReactFiberFromNode_1, exports);
9
- tslib_1.__exportStar(useCallbackRef_1, exports);
10
- });
11
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["utils/index.ts"],"names":[],"mappings":";;;IAAA,2CAA4B;IAC5B,mDAAoC;IACpC,6CAA8B;IAC9B,iDAAkC;IAClC,uDAAwC;IACxC,gDAAiC","sourcesContent":["export * from './isBrowser';\nexport * from './positioningHelper';\nexport * from './getBoundary';\nexport * from './getScrollParent';\nexport * from './getReactFiberFromNode';\nexport * from './useCallbackRef';\n"]}
@@ -1 +0,0 @@
1
- export declare const isBrowser: () => boolean;
@@ -1,8 +0,0 @@
1
- define(["require", "exports"], function (require, exports) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- var hasDocument = typeof document === 'object' && document !== null;
5
- var hasWindow = typeof window === 'object' && window !== null && window.self === window;
6
- exports.isBrowser = function () { return hasDocument && hasWindow; };
7
- });
8
- //# sourceMappingURL=isBrowser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isBrowser.js","sourceRoot":"../src/","sources":["utils/isBrowser.tsx"],"names":[],"mappings":";;;IAAA,IAAM,WAAW,GAAG,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,IAAI,CAAC;IACtE,IAAM,SAAS,GAAG,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC;IAE7E,QAAA,SAAS,GAAG,cAAM,OAAA,WAAW,IAAI,SAAS,EAAxB,CAAwB,CAAC","sourcesContent":["const hasDocument = typeof document === 'object' && document !== null;\nconst hasWindow = typeof window === 'object' && window !== null && window.self === window;\n\nexport const isBrowser = () => hasDocument && hasWindow;\n"]}
@@ -1,7 +0,0 @@
1
- import * as PopperJs from '@popperjs/core';
2
- import { OffsetFunction } from '../types';
3
- /**
4
- * @see positioninHelper.test.ts for expected placement values
5
- */
6
- export declare const getPlacement: (align?: "top" | "bottom" | "start" | "end" | "center" | undefined, position?: "above" | "below" | "before" | "after" | undefined, rtl?: boolean | undefined) => PopperJs.Placement;
7
- export declare const applyRtlToOffset: (offset: OffsetFunction | [number | null | undefined, number | null | undefined] | undefined) => OffsetFunction | [number | null | undefined, number | null | undefined] | undefined;
@@ -1,45 +0,0 @@
1
- define(["require", "exports"], function (require, exports) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- var getPositionMap = function (rtl) { return ({
5
- above: 'top',
6
- below: 'bottom',
7
- before: rtl ? 'right' : 'left',
8
- after: rtl ? 'left' : 'right',
9
- }); };
10
- var getAlignmentMap = function (rtl) { return ({
11
- start: rtl ? 'end' : 'start',
12
- end: rtl ? 'start' : 'end',
13
- top: 'start',
14
- bottom: 'end',
15
- center: '',
16
- }); };
17
- var shouldAlignToCenter = function (p, a) {
18
- var positionedVertically = p === 'above' || p === 'below';
19
- var alignedVertically = a === 'top' || a === 'bottom';
20
- return (positionedVertically && alignedVertically) || (!positionedVertically && !alignedVertically);
21
- };
22
- /**
23
- * @see positioninHelper.test.ts for expected placement values
24
- */
25
- exports.getPlacement = function (align, position, rtl) {
26
- var alignment = shouldAlignToCenter(position, align) ? 'center' : align;
27
- var computedPosition = position && getPositionMap(rtl)[position];
28
- var computedAlignmnent = alignment && getAlignmentMap(rtl)[alignment];
29
- if (computedPosition && computedAlignmnent) {
30
- return computedPosition + "-" + computedAlignmnent;
31
- }
32
- return computedPosition || 'auto';
33
- };
34
- exports.applyRtlToOffset = function (offset) {
35
- if (typeof offset === 'undefined') {
36
- return undefined;
37
- }
38
- if (Array.isArray(offset)) {
39
- offset[0] = offset[0] * -1;
40
- return offset;
41
- }
42
- return (function (param) { return exports.applyRtlToOffset(offset(param)); });
43
- };
44
- });
45
- //# sourceMappingURL=positioningHelper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"positioningHelper.js","sourceRoot":"../src/","sources":["utils/positioningHelper.ts"],"names":[],"mappings":";;;IAMA,IAAM,cAAc,GAAG,UAAC,GAAa,IAA0C,OAAA,CAAC;QAC9E,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,QAAQ;QACf,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM;QAC9B,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;KAC9B,CAAC,EAL6E,CAK7E,CAAC;IAEH,IAAM,eAAe,GAAG,UAAC,GAAa,IAAwC,OAAA,CAAC;QAC7E,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO;QAC5B,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK;QAC1B,GAAG,EAAE,OAAO;QACZ,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,EAAE;KACX,CAAC,EAN4E,CAM5E,CAAC;IAEH,IAAM,mBAAmB,GAAG,UAAC,CAAY,EAAE,CAAa;QACtD,IAAM,oBAAoB,GAAG,CAAC,KAAK,OAAO,IAAI,CAAC,KAAK,OAAO,CAAC;QAC5D,IAAM,iBAAiB,GAAG,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,QAAQ,CAAC;QAExD,OAAO,CAAC,oBAAoB,IAAI,iBAAiB,CAAC,IAAI,CAAC,CAAC,oBAAoB,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACtG,CAAC,CAAC;IAEF;;OAEG;IACU,QAAA,YAAY,GAAG,UAAC,KAAiB,EAAE,QAAmB,EAAE,GAAa;QAChF,IAAM,SAAS,GAAG,mBAAmB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;QAE1E,IAAM,gBAAgB,GAAG,QAAQ,IAAI,cAAc,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;QACnE,IAAM,kBAAkB,GAAG,SAAS,IAAI,eAAe,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC;QAExE,IAAI,gBAAgB,IAAI,kBAAkB,EAAE;YAC1C,OAAU,gBAAgB,SAAI,kBAA0C,CAAC;SAC1E;QAED,OAAO,gBAAgB,IAAK,MAA6B,CAAC;IAC5D,CAAC,CAAC;IAEW,QAAA,gBAAgB,GAAG,UAAC,MAA0B;QACzD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;YACjC,OAAO,SAAS,CAAC;SAClB;QAED,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YACzB,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,CAAC;YAE5B,OAAO,MAAM,CAAC;SACf;QAED,OAAO,CAAC,UAAC,KAA0B,IAAK,OAAA,wBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAA/B,CAA+B,CAAmB,CAAC;IAC7F,CAAC,CAAC","sourcesContent":["import * as PopperJs from '@popperjs/core';\nimport { Alignment, Offset, OffsetFunction, OffsetFunctionParam, Position } from '../types';\n\ntype PlacementPosition = 'top' | 'bottom' | 'left' | 'right';\ntype PlacementAlign = 'start' | 'end' | ''; // '' represents center\n\nconst getPositionMap = (rtl?: boolean): Record<Position, PlacementPosition> => ({\n above: 'top',\n below: 'bottom',\n before: rtl ? 'right' : 'left',\n after: rtl ? 'left' : 'right',\n});\n\nconst getAlignmentMap = (rtl?: boolean): Record<Alignment, PlacementAlign> => ({\n start: rtl ? 'end' : 'start',\n end: rtl ? 'start' : 'end',\n top: 'start',\n bottom: 'end',\n center: '',\n});\n\nconst shouldAlignToCenter = (p?: Position, a?: Alignment): boolean => {\n const positionedVertically = p === 'above' || p === 'below';\n const alignedVertically = a === 'top' || a === 'bottom';\n\n return (positionedVertically && alignedVertically) || (!positionedVertically && !alignedVertically);\n};\n\n/**\n * @see positioninHelper.test.ts for expected placement values\n */\nexport const getPlacement = (align?: Alignment, position?: Position, rtl?: boolean): PopperJs.Placement => {\n const alignment = shouldAlignToCenter(position, align) ? 'center' : align;\n\n const computedPosition = position && getPositionMap(rtl)[position];\n const computedAlignmnent = alignment && getAlignmentMap(rtl)[alignment];\n\n if (computedPosition && computedAlignmnent) {\n return `${computedPosition}-${computedAlignmnent}` as PopperJs.Placement;\n }\n\n return computedPosition || ('auto' as PopperJs.Placement);\n};\n\nexport const applyRtlToOffset = (offset: Offset | undefined): Offset | undefined => {\n if (typeof offset === 'undefined') {\n return undefined;\n }\n\n if (Array.isArray(offset)) {\n offset[0] = offset[0]! * -1;\n\n return offset;\n }\n\n return ((param: OffsetFunctionParam) => applyRtlToOffset(offset(param))) as OffsetFunction;\n};\n"]}
@@ -1,19 +0,0 @@
1
- import * as React from 'react';
2
- /**
3
- * Creates a MutableRef with ref change callback. Is useful as React.useRef() doesn't notify you when its content
4
- * changes and mutating the .current property doesn't cause a re-render. An opt-out will be use a callback ref via
5
- * React.useState(), but it will cause re-renders always.
6
- *
7
- * https://reactjs.org/docs/hooks-reference.html#useref
8
- * https://github.com/theKashey/use-callback-ref#usecallbackref---to-replace-reactuseref
9
- *
10
- * @param initialValue - initial ref value
11
- * @param callback - a callback to run when value changes
12
- * @param skipInitialResolve - a flag to skip an initial ref report
13
- *
14
- * @example
15
- * const ref = useCallbackRef(0, (newValue, oldValue) => console.log(oldValue, '->', newValue);
16
- * ref.current = 1;
17
- * // prints 0 -> 1
18
- */
19
- export declare function useCallbackRef<T>(initialValue: T | null, callback: (newValue: T | null, lastValue: T | null) => void, skipInitialResolve?: boolean): React.MutableRefObject<T | null>;
@@ -1,54 +0,0 @@
1
- define(["require", "exports", "react", "@fluentui/react-utilities"], function (require, exports, React, react_utilities_1) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- /**
5
- * Creates a MutableRef with ref change callback. Is useful as React.useRef() doesn't notify you when its content
6
- * changes and mutating the .current property doesn't cause a re-render. An opt-out will be use a callback ref via
7
- * React.useState(), but it will cause re-renders always.
8
- *
9
- * https://reactjs.org/docs/hooks-reference.html#useref
10
- * https://github.com/theKashey/use-callback-ref#usecallbackref---to-replace-reactuseref
11
- *
12
- * @param initialValue - initial ref value
13
- * @param callback - a callback to run when value changes
14
- * @param skipInitialResolve - a flag to skip an initial ref report
15
- *
16
- * @example
17
- * const ref = useCallbackRef(0, (newValue, oldValue) => console.log(oldValue, '->', newValue);
18
- * ref.current = 1;
19
- * // prints 0 -> 1
20
- */
21
- function useCallbackRef(initialValue, callback, skipInitialResolve) {
22
- var isFirst = React.useRef(true);
23
- var ref = React.useState(function () { return ({
24
- // value
25
- value: initialValue,
26
- // last callback
27
- callback: callback,
28
- // "memoized" public interface
29
- facade: {
30
- get current() {
31
- return ref.value;
32
- },
33
- set current(value) {
34
- var last = ref.value;
35
- if (last !== value) {
36
- ref.value = value;
37
- if (skipInitialResolve && isFirst.current) {
38
- return;
39
- }
40
- ref.callback(value, last);
41
- }
42
- },
43
- },
44
- }); })[0];
45
- react_utilities_1.useIsomorphicLayoutEffect(function () {
46
- isFirst.current = false;
47
- }, []);
48
- // update callback
49
- ref.callback = callback;
50
- return ref.facade;
51
- }
52
- exports.useCallbackRef = useCallbackRef;
53
- });
54
- //# sourceMappingURL=useCallbackRef.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useCallbackRef.js","sourceRoot":"../src/","sources":["utils/useCallbackRef.ts"],"names":[],"mappings":";;;IAGA;;;;;;;;;;;;;;;;OAgBG;IACH,SAAgB,cAAc,CAC5B,YAAsB,EACtB,QAA2D,EAC3D,kBAA4B;QAE5B,IAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC5B,IAAA;;;;;;;;;;;;;;;;;;;;;iBAAG,CAwBN;QAEJ,2CAAyB,CAAC;YACxB,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC;QAC1B,CAAC,EAAE,EAAE,CAAC,CAAC;QAEP,kBAAkB;QAClB,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAExB,OAAO,GAAG,CAAC,MAAM,CAAC;IACpB,CAAC;IAxCD,wCAwCC","sourcesContent":["import * as React from 'react';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\n\n/**\n * Creates a MutableRef with ref change callback. Is useful as React.useRef() doesn't notify you when its content\n * changes and mutating the .current property doesn't cause a re-render. An opt-out will be use a callback ref via\n * React.useState(), but it will cause re-renders always.\n *\n * https://reactjs.org/docs/hooks-reference.html#useref\n * https://github.com/theKashey/use-callback-ref#usecallbackref---to-replace-reactuseref\n *\n * @param initialValue - initial ref value\n * @param callback - a callback to run when value changes\n * @param skipInitialResolve - a flag to skip an initial ref report\n *\n * @example\n * const ref = useCallbackRef(0, (newValue, oldValue) => console.log(oldValue, '->', newValue);\n * ref.current = 1;\n * // prints 0 -> 1\n */\nexport function useCallbackRef<T>(\n initialValue: T | null,\n callback: (newValue: T | null, lastValue: T | null) => void,\n skipInitialResolve?: boolean,\n): React.MutableRefObject<T | null> {\n const isFirst = React.useRef(true);\n const [ref] = React.useState(() => ({\n // value\n value: initialValue,\n // last callback\n callback,\n // \"memoized\" public interface\n facade: {\n get current() {\n return ref.value;\n },\n set current(value) {\n const last = ref.value;\n\n if (last !== value) {\n ref.value = value;\n\n if (skipInitialResolve && isFirst.current) {\n return;\n }\n\n ref.callback(value, last);\n }\n },\n },\n }));\n\n useIsomorphicLayoutEffect(() => {\n isFirst.current = false;\n }, []);\n\n // update callback\n ref.callback = callback;\n\n return ref.facade;\n}\n"]}
@@ -1 +0,0 @@
1
- export declare const isBrowser: () => boolean;
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var hasDocument = typeof document === 'object' && document !== null;
4
- var hasWindow = typeof window === 'object' && window !== null && window.self === window;
5
- exports.isBrowser = function () { return hasDocument && hasWindow; };
6
- //# sourceMappingURL=isBrowser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isBrowser.js","sourceRoot":"../src/","sources":["utils/isBrowser.tsx"],"names":[],"mappings":";;AAAA,IAAM,WAAW,GAAG,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,IAAI,CAAC;AACtE,IAAM,SAAS,GAAG,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC;AAE7E,QAAA,SAAS,GAAG,cAAM,OAAA,WAAW,IAAI,SAAS,EAAxB,CAAwB,CAAC","sourcesContent":["const hasDocument = typeof document === 'object' && document !== null;\nconst hasWindow = typeof window === 'object' && window !== null && window.self === window;\n\nexport const isBrowser = () => hasDocument && hasWindow;\n"]}