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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. package/CHANGELOG.json +47 -2
  2. package/CHANGELOG.md +30 -3
  3. package/lib/createVirtualElementFromClick.js.map +1 -1
  4. package/lib/index.js.map +1 -1
  5. package/lib/types.js.map +1 -1
  6. package/lib/usePopper.js.map +1 -1
  7. package/lib/usePopperMouseTarget.js.map +1 -1
  8. package/lib/utils/getBasePlacement.js.map +1 -1
  9. package/lib/utils/getBoundary.js.map +1 -1
  10. package/lib/utils/getReactFiberFromNode.js.map +1 -1
  11. package/lib/utils/getScrollParent.js.map +1 -1
  12. package/lib/utils/index.js.map +1 -1
  13. package/lib/utils/mergeArrowOffset.js.map +1 -1
  14. package/lib/utils/positioningHelper.js.map +1 -1
  15. package/lib/utils/resolvePositioningShorthand.js.map +1 -1
  16. package/lib/utils/useCallbackRef.js.map +1 -1
  17. package/lib-commonjs/createVirtualElementFromClick.js.map +1 -1
  18. package/lib-commonjs/index.js.map +1 -1
  19. package/lib-commonjs/types.js.map +1 -1
  20. package/lib-commonjs/usePopper.js.map +1 -1
  21. package/lib-commonjs/usePopperMouseTarget.js.map +1 -1
  22. package/lib-commonjs/utils/getBasePlacement.js.map +1 -1
  23. package/lib-commonjs/utils/getBoundary.js.map +1 -1
  24. package/lib-commonjs/utils/getReactFiberFromNode.js.map +1 -1
  25. package/lib-commonjs/utils/getScrollParent.js.map +1 -1
  26. package/lib-commonjs/utils/index.js.map +1 -1
  27. package/lib-commonjs/utils/mergeArrowOffset.js.map +1 -1
  28. package/lib-commonjs/utils/positioningHelper.js.map +1 -1
  29. package/lib-commonjs/utils/resolvePositioningShorthand.js.map +1 -1
  30. package/lib-commonjs/utils/useCallbackRef.js.map +1 -1
  31. package/package.json +2 -2
  32. package/lib-amd/createVirtualElementFromClick.d.ts +0 -6
  33. package/lib-amd/createVirtualElementFromClick.js +0 -30
  34. package/lib-amd/createVirtualElementFromClick.js.map +0 -1
  35. package/lib-amd/index.d.ts +0 -5
  36. package/lib-amd/index.js +0 -12
  37. package/lib-amd/index.js.map +0 -1
  38. package/lib-amd/types.d.ts +0 -68
  39. package/lib-amd/types.js +0 -5
  40. package/lib-amd/types.js.map +0 -1
  41. package/lib-amd/usePopper.d.ts +0 -35
  42. package/lib-amd/usePopper.js +0 -320
  43. package/lib-amd/usePopper.js.map +0 -1
  44. package/lib-amd/usePopperMouseTarget.d.ts +0 -11
  45. package/lib-amd/usePopperMouseTarget.js +0 -35
  46. package/lib-amd/usePopperMouseTarget.js.map +0 -1
  47. package/lib-amd/utils/getBasePlacement.d.ts +0 -8
  48. package/lib-amd/utils/getBasePlacement.js +0 -16
  49. package/lib-amd/utils/getBasePlacement.js.map +0 -1
  50. package/lib-amd/utils/getBoundary.d.ts +0 -6
  51. package/lib-amd/utils/getBoundary.js +0 -23
  52. package/lib-amd/utils/getBoundary.js.map +0 -1
  53. package/lib-amd/utils/getReactFiberFromNode.d.ts +0 -109
  54. package/lib-amd/utils/getReactFiberFromNode.js +0 -48
  55. package/lib-amd/utils/getReactFiberFromNode.js.map +0 -1
  56. package/lib-amd/utils/getScrollParent.d.ts +0 -12
  57. package/lib-amd/utils/getScrollParent.js +0 -58
  58. package/lib-amd/utils/getScrollParent.js.map +0 -1
  59. package/lib-amd/utils/index.d.ts +0 -8
  60. package/lib-amd/utils/index.js +0 -13
  61. package/lib-amd/utils/index.js.map +0 -1
  62. package/lib-amd/utils/mergeArrowOffset.d.ts +0 -10
  63. package/lib-amd/utils/mergeArrowOffset.js +0 -43
  64. package/lib-amd/utils/mergeArrowOffset.js.map +0 -1
  65. package/lib-amd/utils/positioningHelper.d.ts +0 -7
  66. package/lib-amd/utils/positioningHelper.js +0 -48
  67. package/lib-amd/utils/positioningHelper.js.map +0 -1
  68. package/lib-amd/utils/resolvePositioningShorthand.d.ts +0 -2
  69. package/lib-amd/utils/resolvePositioningShorthand.js +0 -31
  70. package/lib-amd/utils/resolvePositioningShorthand.js.map +0 -1
  71. package/lib-amd/utils/useCallbackRef.d.ts +0 -19
  72. package/lib-amd/utils/useCallbackRef.js +0 -55
  73. package/lib-amd/utils/useCallbackRef.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"positioningHelper.js","sourceRoot":"../src/","sources":["utils/positioningHelper.ts"],"names":[],"mappings":";;;AAMA,IAAM,cAAc,GAAG,UAAC,GAAa,IAA0C,OAAA,CAAC;IAC9E,KAAK,EAAE,KAAK;IACZ,KAAK,EAAE,QAAQ;IACf,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM;IAC9B,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;CAC9B,CAAC,EAL6E,CAK7E,CAAC;AAEH,IAAM,eAAe,GAAG,UAAC,GAAa,IAAwC,OAAA,CAAC;IAC7E,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO;IAC5B,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK;IAC1B,GAAG,EAAE,OAAO;IACZ,MAAM,EAAE,KAAK;IACb,MAAM,EAAE,EAAE;CACX,CAAC,EAN4E,CAM5E,CAAC;AAEH,IAAM,mBAAmB,GAAG,UAAC,CAAY,EAAE,CAAa;IACtD,IAAM,oBAAoB,GAAG,CAAC,KAAK,OAAO,IAAI,CAAC,KAAK,OAAO,CAAC;IAC5D,IAAM,iBAAiB,GAAG,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,QAAQ,CAAC;IAExD,OAAO,CAAC,oBAAoB,IAAI,iBAAiB,CAAC,IAAI,CAAC,CAAC,oBAAoB,IAAI,CAAC,iBAAiB,CAAC,CAAC;AACtG,CAAC,CAAC;AAEF;;GAEG;AACI,IAAM,YAAY,GAAG,UAAC,KAAiB,EAAE,QAAmB,EAAE,GAAa;IAChF,IAAM,SAAS,GAAG,mBAAmB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;IAE1E,IAAM,gBAAgB,GAAG,QAAQ,IAAI,cAAc,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;IACnE,IAAM,kBAAkB,GAAG,SAAS,IAAI,eAAe,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC;IAExE,IAAI,gBAAgB,IAAI,kBAAkB,EAAE;QAC1C,OAAU,gBAAgB,SAAI,kBAA0C,CAAC;KAC1E;IAED,OAAO,gBAAgB,IAAK,MAA6B,CAAC;AAC5D,CAAC,CAAC;AAXW,QAAA,YAAY,gBAWvB;AAEK,IAAM,gBAAgB,GAAG,UAAC,MAA0B;IACzD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAO,SAAS,CAAC;KAClB;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACzB,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,CAAC;QAE5B,OAAO,MAAM,CAAC;KACf;IAED,OAAO,CAAC,UAAC,KAA0B,IAAK,OAAA,wBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAA/B,CAA+B,CAAmB,CAAC;AAC7F,CAAC,CAAC;AAZW,QAAA,gBAAgB,oBAY3B","sourcesContent":["import * as PopperJs from '@popperjs/core';\nimport type { 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
+ {"version":3,"file":"positioningHelper.js","sourceRoot":"","sources":["../../src/utils/positioningHelper.ts"],"names":[],"mappings":";;;AAMA,IAAM,cAAc,GAAG,UAAC,GAAa,IAA0C,OAAA,CAAC;IAC9E,KAAK,EAAE,KAAK;IACZ,KAAK,EAAE,QAAQ;IACf,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM;IAC9B,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;CAC9B,CAAC,EAL6E,CAK7E,CAAC;AAEH,IAAM,eAAe,GAAG,UAAC,GAAa,IAAwC,OAAA,CAAC;IAC7E,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO;IAC5B,GAAG,EAAE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QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE;CACvD,CAAC;AAEF,SAAgB,2BAA2B,CACzC,SAAkD;IAElD,IAAI,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,IAAI,EAAE;QACjD,OAAO,EAAE,CAAC;KACX;IAED,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;QACjC,OAAO,eAAe,CAAC,SAAS,CAAC,CAAC;KACnC;IAED,OAAO,SAAuC,CAAC;AACjD,CAAC;AAZD,kEAYC","sourcesContent":["import type { PositioningShorthand, PositioningShorthandValue, PositioningProps } from '../types';\n\n// Look up table for shorthand to avoid parsing strings\nconst shorthandLookup: Record<PositioningShorthandValue, Pick<PositioningProps, 'position' | 'align'>> = {\n above: { position: 'above', align: 'center' },\n 'above-start': { position: 'above', align: 'start' },\n 'above-end': { position: 'above', align: 'end' },\n below: { position: 'below', align: 'center' },\n 'below-start': { position: 'below', align: 'start' },\n 'below-end': { position: 'below', align: 'end' },\n before: { position: 'before', align: 'center' },\n 'before-top': { position: 'before', align: 'top' },\n 'before-bottom': { position: 'before', align: 'bottom' },\n after: { position: 'after', align: 'center' },\n 'after-top': { position: 'after', align: 'top' },\n 'after-bottom': { position: 'after', align: 'bottom' },\n};\n\nexport function resolvePositioningShorthand(\n shorthand: PositioningShorthand | undefined | null,\n): Readonly<PositioningProps> {\n if (shorthand === undefined || shorthand === null) {\n return {};\n }\n\n if (typeof shorthand === 'string') {\n return shorthandLookup[shorthand];\n }\n\n return shorthand as Readonly<PositioningProps>;\n}\n"]}
1
+ {"version":3,"file":"resolvePositioningShorthand.js","sourceRoot":"","sources":["../../src/utils/resolvePositioningShorthand.ts"],"names":[],"mappings":";;;AAEA,uDAAuD;AACvD,IAAM,eAAe,GAAoF;IACvG,KAAK,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE;IAC7C,aAAa,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAA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tB,QAA2D,EAC3D,kBAA4B;IAE5B,IAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAA,GAAG,GAAI,KAAK,CAAC,QAAQ,CAAC,cAAM,OAAA,CAAC;QAClC,QAAQ;QACR,KAAK,EAAE,YAAY;QACnB,gBAAgB;QAChB,QAAQ,UAAA;QACR,8BAA8B;QAC9B,MAAM,EAAE;YACN,IAAI,OAAO;gBACT,OAAO,GAAG,CAAC,KAAK,CAAC;YACnB,CAAC;YACD,IAAI,OAAO,CAAC,KAAK;gBACf,IAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC;gBAEvB,IAAI,IAAI,KAAK,KAAK,EAAE;oBAClB,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC;oBAElB,IAAI,kBAAkB,IAAI,OAAO,CAAC,OAAO,EAAE;wBACzC,OAAO;qBACR;oBAED,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;iBAC3B;YACH,CAAC;SACF;KACF,CAAC,EAxBiC,CAwBjC,CAAC,GAxBO,CAwBN;IAEJ,2CAAyB,CAAC;QACxB,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC;IAC1B,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,kBAAkB;IAClB,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAExB,OAAO,GAAG,CAAC,MAAM,CAAC;AACpB,CAAC;AAxCD,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
+ {"version":3,"file":"useCallbackRef.js","sourceRoot":"","sources":["../../src/utils/useCallbackRef.ts"],"names":[],"mappings":";;;AAAA,6BAA+B;AAC/B,6DAAsE;AAEtE;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,cAAc,CAC5B,YAAsB,EACtB,QAA2D,EAC3D,kBAA4B;IAE5B,IAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAA,GAAG,GAAI,KAAK,CAAC,QAAQ,CAAC,cAAM,OAAA,CAAC;QAClC,QAAQ;QACR,KAAK,EAAE,YAAY;QACnB,gBAAgB;QAChB,QAAQ,UAAA;QACR,8BAA8B;QAC9B,MAAM,EAAE;YACN,IAAI,OAAO;gBACT,OAAO,GAAG,CAAC,KAAK,CAAC;YACnB,CAAC;YACD,IAAI,OAAO,CAAC,KAAK;gBACf,IAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC;gBAEvB,IAAI,IAAI,KAAK,KAAK,EAAE;oBAClB,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC;oBAElB,IAAI,kBAAkB,IAAI,OAAO,CAAC,OAAO,EAAE;wBACzC,OAAO;qBACR;oBAED,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;iBAC3B;YACH,CAAC;SACF;KACF,CAAC,EAxBiC,CAwBjC,CAAC,GAxBO,CAwBN;IAEJ,2CAAyB,CAAC;QACxB,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC;IAC1B,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,kBAAkB;IAClB,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAExB,OAAO,GAAG,CAAC,MAAM,CAAC;AACpB,CAAC;AAxCD,wCAwCC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-positioning",
3
- "version": "9.0.0-alpha.57",
3
+ "version": "9.0.0-alpha.60",
4
4
  "description": "A react wrapper around Popper.js for Fluent UI",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@fluentui/react-shared-contexts": "9.0.0-alpha.25",
37
- "@fluentui/react-utilities": "9.0.0-alpha.49",
37
+ "@fluentui/react-utilities": "9.0.0-alpha.52",
38
38
  "@popperjs/core": "~2.4.3",
39
39
  "tslib": "^2.1.0"
40
40
  },
@@ -1,6 +0,0 @@
1
- import type { PopperVirtualElement } from './types';
2
- /**
3
- * Creates a virtual element based on the position of a click event
4
- * Can be used as a target for popper in scenarios such as context menus
5
- */
6
- export declare function createVirtualElementFromClick(nativeEvent: MouseEvent): PopperVirtualElement;
@@ -1,30 +0,0 @@
1
- define(["require", "exports"], function (require, exports) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.createVirtualElementFromClick = void 0;
5
- /**
6
- * Creates a virtual element based on the position of a click event
7
- * Can be used as a target for popper in scenarios such as context menus
8
- */
9
- function createVirtualElementFromClick(nativeEvent) {
10
- var left = nativeEvent.clientX;
11
- var top = nativeEvent.clientY;
12
- var right = left + 1;
13
- var bottom = top + 1;
14
- function getBoundingClientRect() {
15
- return {
16
- left: left,
17
- top: top,
18
- right: right,
19
- bottom: bottom,
20
- height: 1,
21
- width: 1,
22
- };
23
- }
24
- return {
25
- getBoundingClientRect: getBoundingClientRect,
26
- };
27
- }
28
- exports.createVirtualElementFromClick = createVirtualElementFromClick;
29
- });
30
- //# sourceMappingURL=createVirtualElementFromClick.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createVirtualElementFromClick.js","sourceRoot":"../src/","sources":["createVirtualElementFromClick.ts"],"names":[],"mappings":";;;;IAEA;;;OAGG;IACH,SAAgB,6BAA6B,CAAC,WAAuB;QACnE,IAAM,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC;QACjC,IAAM,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC;QAChC,IAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC;QACvB,IAAM,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC;QAEvB,SAAS,qBAAqB;YAC5B,OAAO;gBACL,IAAI,MAAA;gBACJ,GAAG,KAAA;gBACH,KAAK,OAAA;gBACL,MAAM,QAAA;gBAEN,MAAM,EAAE,CAAC;gBACT,KAAK,EAAE,CAAC;aACT,CAAC;QACJ,CAAC;QAED,OAAO;YACL,qBAAqB,uBAAA;SACtB,CAAC;IACJ,CAAC;IArBD,sEAqBC","sourcesContent":["import type { PopperVirtualElement } from './types';\n\n/**\n * Creates a virtual element based on the position of a click event\n * Can be used as a target for popper in scenarios such as context menus\n */\nexport function createVirtualElementFromClick(nativeEvent: MouseEvent): PopperVirtualElement {\n const left = nativeEvent.clientX;\n const top = nativeEvent.clientY;\n const right = left + 1;\n const bottom = top + 1;\n\n function getBoundingClientRect(): ClientRect {\n return {\n left,\n top,\n right,\n bottom,\n\n height: 1,\n width: 1,\n };\n }\n\n return {\n getBoundingClientRect,\n };\n}\n"]}
@@ -1,5 +0,0 @@
1
- export * from './usePopper';
2
- export * from './createVirtualElementFromClick';
3
- export * from './usePopperMouseTarget';
4
- export { resolvePositioningShorthand, mergeArrowOffset } from './utils/index';
5
- export * from './types';
package/lib-amd/index.js DELETED
@@ -1,12 +0,0 @@
1
- define(["require", "exports", "tslib", "./usePopper", "./createVirtualElementFromClick", "./usePopperMouseTarget", "./utils/index", "./types"], function (require, exports, tslib_1, usePopper_1, createVirtualElementFromClick_1, usePopperMouseTarget_1, index_1, types_1) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.mergeArrowOffset = exports.resolvePositioningShorthand = void 0;
5
- tslib_1.__exportStar(usePopper_1, exports);
6
- tslib_1.__exportStar(createVirtualElementFromClick_1, exports);
7
- tslib_1.__exportStar(usePopperMouseTarget_1, exports);
8
- Object.defineProperty(exports, "resolvePositioningShorthand", { enumerable: true, get: function () { return index_1.resolvePositioningShorthand; } });
9
- Object.defineProperty(exports, "mergeArrowOffset", { enumerable: true, get: function () { return index_1.mergeArrowOffset; } });
10
- tslib_1.__exportStar(types_1, exports);
11
- });
12
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["index.ts"],"names":[],"mappings":";;;;IAAA,2CAA4B;IAC5B,+DAAgD;IAChD,sDAAuC;IAC9B,oHAAA,2BAA2B,OAAA;IAAE,yGAAA,gBAAgB,OAAA;IACtD,uCAAwB","sourcesContent":["export * from './usePopper';\nexport * from './createVirtualElementFromClick';\nexport * from './usePopperMouseTarget';\nexport { resolvePositioningShorthand, mergeArrowOffset } from './utils/index';\nexport * from './types';\n"]}
@@ -1,68 +0,0 @@
1
- import * as PopperJs from '@popperjs/core';
2
- import * as React from 'react';
3
- export declare type OffsetFunctionParam = {
4
- popper: PopperJs.Rect;
5
- reference: PopperJs.Rect;
6
- placement: PopperJs.Placement;
7
- };
8
- export declare type OffsetFunction = (param: OffsetFunctionParam) => [number | null | undefined, number | null | undefined];
9
- export declare type Offset = OffsetFunction | [number | null | undefined, number | null | undefined];
10
- export declare type Position = 'above' | 'below' | 'before' | 'after';
11
- export declare type Alignment = 'top' | 'bottom' | 'start' | 'end' | 'center';
12
- export declare type AutoSize = 'height' | 'height-always' | 'width' | 'width-always' | 'always' | boolean;
13
- export declare type Boundary = PopperJs.Boundary | 'scrollParent' | 'window';
14
- export declare type PopperRefHandle = {
15
- updatePosition: () => void;
16
- };
17
- export declare type PopperVirtualElement = PopperJs.VirtualElement;
18
- export interface PositioningProps {
19
- /** Alignment for the component. Only has an effect if used with the @see position option */
20
- align?: Alignment;
21
- /** The element which will define the boundaries of the popper position for the flip behavior. */
22
- flipBoundary?: Boundary;
23
- /** The element which will define the boundaries of the popper position for the overflow behavior. */
24
- overflowBoundary?: Boundary;
25
- /** An imperative handle to Popper methods. */
26
- popperRef?: React.Ref<PopperRefHandle>;
27
- /**
28
- * Position for the component. Position has higher priority than align. If position is vertical ('above' | 'below')
29
- * and align is also vertical ('top' | 'bottom') or if both position and align are horizontal ('before' | 'after'
30
- * and 'start' | 'end' respectively),
31
- * then provided value for 'align' will be ignored and 'center' will be used instead.
32
- */
33
- position?: Position;
34
- /**
35
- * Lets you displace a popper element from its reference element.
36
- * This can be useful if you need to apply some margin between them or if you need to fine tune the
37
- * position according to some custom logic.
38
- */
39
- offset?: Offset;
40
- /**
41
- * Defines padding between the corner of the popup element and the arrow.
42
- * Use to prevent the arrow from overlapping a rounded corner, for example.
43
- */
44
- arrowPadding?: number;
45
- /**
46
- * Applies max-height and max-width on popper to fit it within the available space in viewport.
47
- * true enables this for both width and height when overflow happens.
48
- * 'always' applies `max-height`/`max-width` regardless of overflow.
49
- * 'height' applies `max-height` when overflow happens, and 'width' for `max-width`
50
- * `height-always` applies `max-height` regardless of overflow, and 'width-always' for always applying `max-width`
51
- */
52
- autoSize?: AutoSize;
53
- /**
54
- * Manual override for popper target. Useful for scenarios where a component accepts user prop to override target
55
- */
56
- target?: HTMLElement | PopperVirtualElement | null;
57
- /**
58
- * Modifies position and alignment to cover the target
59
- */
60
- coverTarget?: boolean;
61
- /**
62
- * Disables automatic repositioning of the component; it will always be placed according to the values of `align` and
63
- * `position` props, regardless of the size of the component, the reference element or the viewport.
64
- */
65
- pinned?: boolean;
66
- }
67
- export declare type PositioningShorthandValue = 'above' | 'above-start' | 'above-end' | 'below' | 'below-start' | 'below-end' | 'before' | 'before-top' | 'before-bottom' | 'after' | 'after-top' | 'after-bottom';
68
- export declare type PositioningShorthand = PositioningProps | PositioningShorthandValue;
package/lib-amd/types.js DELETED
@@ -1,5 +0,0 @@
1
- define(["require", "exports"], function (require, exports) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- });
5
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"../src/","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["import * as PopperJs from '@popperjs/core';\nimport * as React from 'react';\n\nexport type OffsetFunctionParam = {\n popper: PopperJs.Rect;\n reference: PopperJs.Rect;\n placement: PopperJs.Placement;\n};\n\nexport type OffsetFunction = (param: OffsetFunctionParam) => [number | null | undefined, number | null | undefined];\n\nexport type Offset = OffsetFunction | [number | null | undefined, number | null | undefined];\n\nexport type Position = 'above' | 'below' | 'before' | 'after';\nexport type Alignment = 'top' | 'bottom' | 'start' | 'end' | 'center';\n\nexport type AutoSize = 'height' | 'height-always' | 'width' | 'width-always' | 'always' | boolean;\n\nexport type Boundary = PopperJs.Boundary | 'scrollParent' | 'window';\n\nexport type PopperRefHandle = { updatePosition: () => void };\n\nexport type PopperVirtualElement = PopperJs.VirtualElement;\n\nexport interface PositioningProps {\n /** Alignment for the component. Only has an effect if used with the @see position option */\n align?: Alignment;\n\n /** The element which will define the boundaries of the popper position for the flip behavior. */\n flipBoundary?: Boundary;\n\n /** The element which will define the boundaries of the popper position for the overflow behavior. */\n overflowBoundary?: Boundary;\n\n /** An imperative handle to Popper methods. */\n popperRef?: React.Ref<PopperRefHandle>;\n\n /**\n * Position for the component. Position has higher priority than align. If position is vertical ('above' | 'below')\n * and align is also vertical ('top' | 'bottom') or if both position and align are horizontal ('before' | 'after'\n * and 'start' | 'end' respectively),\n * then provided value for 'align' will be ignored and 'center' will be used instead.\n */\n position?: Position;\n\n /**\n * Lets you displace a popper element from its reference element.\n * This can be useful if you need to apply some margin between them or if you need to fine tune the\n * position according to some custom logic.\n */\n offset?: Offset;\n\n /**\n * Defines padding between the corner of the popup element and the arrow.\n * Use to prevent the arrow from overlapping a rounded corner, for example.\n */\n arrowPadding?: number;\n\n /**\n * Applies max-height and max-width on popper to fit it within the available space in viewport.\n * true enables this for both width and height when overflow happens.\n * 'always' applies `max-height`/`max-width` regardless of overflow.\n * 'height' applies `max-height` when overflow happens, and 'width' for `max-width`\n * `height-always` applies `max-height` regardless of overflow, and 'width-always' for always applying `max-width`\n */\n autoSize?: AutoSize;\n\n /**\n * Manual override for popper target. Useful for scenarios where a component accepts user prop to override target\n */\n target?: HTMLElement | PopperVirtualElement | null;\n\n /**\n * Modifies position and alignment to cover the target\n */\n coverTarget?: boolean;\n\n /**\n * Disables automatic repositioning of the component; it will always be placed according to the values of `align` and\n * `position` props, regardless of the size of the component, the reference element or the viewport.\n */\n pinned?: boolean;\n}\n\nexport type PositioningShorthandValue =\n | 'above'\n | 'above-start'\n | 'above-end'\n | 'below'\n | 'below-start'\n | 'below-end'\n | 'before'\n | 'before-top'\n | 'before-bottom'\n | 'after'\n | 'after-top'\n | 'after-bottom';\n\nexport type PositioningShorthand = PositioningProps | PositioningShorthandValue;\n"]}
@@ -1,35 +0,0 @@
1
- import * as PopperJs from '@popperjs/core';
2
- import * as React from 'react';
3
- import type { PositioningProps } from './types';
4
- interface PopperOptions extends PositioningProps {
5
- /**
6
- * If false, delays Popper's creation.
7
- * @default true
8
- */
9
- enabled?: boolean;
10
- onStateUpdate?: (state: Partial<PopperJs.State>) => void;
11
- /**
12
- * Enables the Popper box to position itself in 'fixed' mode (default value is position: 'absolute')
13
- * @default false
14
- */
15
- positionFixed?: boolean;
16
- /**
17
- * When the reference element or the viewport is outside viewport allows a popper element to be fully in viewport.
18
- * "all" enables this behavior for all axis.
19
- */
20
- unstable_disableTether?: boolean | 'all';
21
- }
22
- /**
23
- * Exposes Popper positioning API via React hook. Contains few important differences between an official "react-popper"
24
- * package:
25
- * - style attributes are applied directly on DOM to avoid re-renders
26
- * - refs changes and resolution is handled properly without re-renders
27
- * - contains a specific to React fix related to initial positioning when containers have components with managed focus
28
- * to avoid focus jumps
29
- */
30
- export declare function usePopper(options?: PopperOptions): {
31
- targetRef: React.MutableRefObject<any>;
32
- containerRef: React.MutableRefObject<any>;
33
- arrowRef: React.MutableRefObject<any>;
34
- };
35
- export {};
@@ -1,320 +0,0 @@
1
- define(["require", "exports", "@fluentui/react-utilities", "@fluentui/react-shared-contexts", "./utils/index", "@popperjs/core", "react"], function (require, exports, react_utilities_1, react_shared_contexts_1, index_1, PopperJs, React) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.usePopper = void 0;
5
- //
6
- // Dev utils to detect if nodes have "autoFocus" props.
7
- //
8
- /**
9
- * Detects if a passed HTML node has "autoFocus" prop on a React's fiber. Is needed as React handles autofocus behavior
10
- * in React DOM and will not pass "autoFocus" to an actual HTML.
11
- */
12
- function hasAutofocusProp(node) {
13
- var _a;
14
- // https://github.com/facebook/react/blob/848bb2426e44606e0a55dfe44c7b3ece33772485/packages/react-dom/src/client/ReactDOMHostConfig.js#L157-L166
15
- var isAutoFocusableElement = node.nodeName === 'BUTTON' ||
16
- node.nodeName === 'INPUT' ||
17
- node.nodeName === 'SELECT' ||
18
- node.nodeName === 'TEXTAREA';
19
- if (isAutoFocusableElement) {
20
- return !!((_a = index_1.getReactFiberFromNode(node)) === null || _a === void 0 ? void 0 : _a.pendingProps.autoFocus);
21
- }
22
- return false;
23
- }
24
- function hasAutofocusFilter(node) {
25
- return hasAutofocusProp(node) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
26
- }
27
- /**
28
- * Provides a callback to resolve Popper options, it's stable and should be used as a dependency to trigger updates
29
- * of Popper options.
30
- *
31
- * A callback is used there intentionally as some of Popper.js modifiers require DOM nodes (targer, container, arrow)
32
- * that can't be resolved properly during an initial rendering.
33
- */
34
- function usePopperOptions(options, popperOriginalPositionRef) {
35
- var arrowPadding = options.arrowPadding, autoSize = options.autoSize, coverTarget = options.coverTarget, flipBoundary = options.flipBoundary, offset = options.offset, onStateUpdate = options.onStateUpdate, overflowBoundary = options.overflowBoundary,
36
- // eslint-disable-next-line @typescript-eslint/naming-convention
37
- unstable_disableTether = options.unstable_disableTether, pinned = options.pinned;
38
- var isRtl = react_shared_contexts_1.useFluent().dir === 'rtl';
39
- var placement = index_1.getPlacement(options.align, options.position, isRtl);
40
- var strategy = options.positionFixed ? 'fixed' : 'absolute';
41
- var handleStateUpdate = react_utilities_1.useEventCallback(function (_a) {
42
- var state = _a.state;
43
- if (onStateUpdate) {
44
- onStateUpdate(state);
45
- }
46
- });
47
- var offsetModifier = React.useMemo(function () {
48
- return offset
49
- ? {
50
- name: 'offset',
51
- options: { offset: isRtl ? index_1.applyRtlToOffset(offset) : offset },
52
- }
53
- : null;
54
- }, [offset, isRtl]);
55
- return React.useCallback(function (target, container, arrow) {
56
- var _a;
57
- var scrollParentElement = index_1.getScrollParent(container);
58
- var hasScrollableElement = scrollParentElement
59
- ? scrollParentElement !== ((_a = scrollParentElement.ownerDocument) === null || _a === void 0 ? void 0 : _a.body)
60
- : false;
61
- var modifiers = [
62
- /**
63
- * We are setting the position to `fixed` in the first effect to prevent scroll jumps in case of the content
64
- * with managed focus. Modifier sets the position to `fixed` before all other modifier effects. Another part of
65
- * a patch modifies ".forceUpdate()" directly after a Popper will be created.
66
- */
67
- {
68
- name: 'positionStyleFix',
69
- enabled: true,
70
- phase: 'afterWrite',
71
- effect: function (_a) {
72
- var state = _a.state, instance = _a.instance;
73
- // ".isFirstRun" is a part of our patch, on a first evaluation it will "undefined"
74
- // should be disabled for subsequent runs as it breaks positioning for them
75
- if (instance.isFirstRun !== false) {
76
- popperOriginalPositionRef.current = state.elements.popper.style.position;
77
- state.elements.popper.style.position = 'fixed';
78
- }
79
- return function () { return undefined; };
80
- },
81
- requires: [],
82
- },
83
- { name: 'flip', options: { flipVariations: true } },
84
- /**
85
- * pinned disables the flip modifier by setting flip.enabled to false; this
86
- * disables automatic repositioning of the popper box; it will always be placed according to
87
- * the values of `align` and `position` props, regardless of the size of the component, the
88
- * reference element or the viewport.
89
- */
90
- pinned && { name: 'flip', enabled: false },
91
- /**
92
- * When the popper box is placed in the context of a scrollable element, we need to set
93
- * preventOverflow.escapeWithReference to true and flip.boundariesElement to 'scrollParent'
94
- * (default is 'viewport') so that the popper box will stick with the targetRef when we
95
- * scroll targetRef out of the viewport.
96
- */
97
- hasScrollableElement && { name: 'flip', options: { boundary: 'clippingParents' } },
98
- hasScrollableElement && { name: 'preventOverflow', options: { boundary: 'clippingParents' } },
99
- offsetModifier,
100
- /**
101
- * This modifier is necessary to retain behaviour from popper v1 where untethered poppers are allowed by
102
- * default. i.e. popper is still rendered fully in the viewport even if anchor element is no longer in the
103
- * viewport.
104
- */
105
- unstable_disableTether && {
106
- name: 'preventOverflow',
107
- options: { altAxis: unstable_disableTether === 'all', tether: false },
108
- },
109
- flipBoundary && {
110
- name: 'flip',
111
- options: {
112
- altBoundary: true,
113
- boundary: index_1.getBoundary(container, flipBoundary),
114
- },
115
- },
116
- overflowBoundary && {
117
- name: 'preventOverflow',
118
- options: {
119
- altBoundary: true,
120
- boundary: index_1.getBoundary(container, overflowBoundary),
121
- },
122
- },
123
- {
124
- name: 'onUpdate',
125
- enabled: true,
126
- phase: 'afterWrite',
127
- fn: handleStateUpdate,
128
- },
129
- {
130
- // Similar code as popper-maxsize-modifier: https://github.com/atomiks/popper.js/blob/master/src/modifiers/maxSize.js
131
- // popper-maxsize-modifier only calculates the max sizes.
132
- // This modifier can apply max sizes always, or apply the max sizes only when overflow is detected
133
- name: 'applyMaxSize',
134
- enabled: !!autoSize,
135
- phase: 'beforeWrite',
136
- requiresIfExists: ['offset', 'preventOverflow', 'flip'],
137
- options: {
138
- altBoundary: true,
139
- boundary: index_1.getBoundary(container, overflowBoundary),
140
- },
141
- fn: function (_a) {
142
- var state = _a.state, modifierOptions = _a.options;
143
- var overflow = PopperJs.detectOverflow(state, modifierOptions);
144
- var _b = state.modifiersData.preventOverflow || { x: 0, y: 0 }, x = _b.x, y = _b.y;
145
- var _c = state.rects.popper, width = _c.width, height = _c.height;
146
- var basePlacement = index_1.getBasePlacement(state.placement);
147
- var widthProp = basePlacement === 'left' ? 'left' : 'right';
148
- var heightProp = basePlacement === 'top' ? 'top' : 'bottom';
149
- var applyMaxWidth = autoSize === 'always' ||
150
- autoSize === 'width-always' ||
151
- (overflow[widthProp] > 0 && (autoSize === true || autoSize === 'width'));
152
- var applyMaxHeight = autoSize === 'always' ||
153
- autoSize === 'height-always' ||
154
- (overflow[heightProp] > 0 && (autoSize === true || autoSize === 'height'));
155
- if (applyMaxWidth) {
156
- state.styles.popper.maxWidth = width - overflow[widthProp] - x + "px";
157
- }
158
- if (applyMaxHeight) {
159
- state.styles.popper.maxHeight = height - overflow[heightProp] - y + "px";
160
- }
161
- },
162
- },
163
- /**
164
- * This modifier is necessary in order to render the pointer. Refs are resolved in effects, so it can't be
165
- * placed under computed modifiers. Deep merge is not required as this modifier has only these properties.
166
- */
167
- {
168
- name: 'arrow',
169
- enabled: !!arrow,
170
- options: { element: arrow, padding: arrowPadding },
171
- },
172
- /**
173
- * Modifies popper offsets to cover the reference rect, but still keep edge alignment
174
- */
175
- {
176
- name: 'coverTarget',
177
- enabled: !!coverTarget,
178
- phase: 'main',
179
- requiresIfExists: ['offset', 'preventOverflow', 'flip'],
180
- fn: function (_a) {
181
- var state = _a.state;
182
- var basePlacement = index_1.getBasePlacement(state.placement);
183
- switch (basePlacement) {
184
- case 'bottom':
185
- state.modifiersData.popperOffsets.y -= state.rects.reference.height;
186
- break;
187
- case 'top':
188
- state.modifiersData.popperOffsets.y += state.rects.reference.height;
189
- break;
190
- case 'left':
191
- state.modifiersData.popperOffsets.x += state.rects.reference.width;
192
- break;
193
- case 'right':
194
- state.modifiersData.popperOffsets.x -= state.rects.reference.width;
195
- break;
196
- }
197
- },
198
- },
199
- ].filter(Boolean); // filter boolean conditional spreading values
200
- var popperOptions = {
201
- modifiers: modifiers,
202
- placement: placement,
203
- strategy: strategy,
204
- onFirstUpdate: function (state) { return handleStateUpdate({ state: state }); },
205
- };
206
- return popperOptions;
207
- }, [
208
- arrowPadding,
209
- autoSize,
210
- coverTarget,
211
- flipBoundary,
212
- offsetModifier,
213
- overflowBoundary,
214
- placement,
215
- strategy,
216
- unstable_disableTether,
217
- pinned,
218
- // These can be skipped from deps as they will not ever change
219
- handleStateUpdate,
220
- popperOriginalPositionRef,
221
- ]);
222
- }
223
- /**
224
- * Exposes Popper positioning API via React hook. Contains few important differences between an official "react-popper"
225
- * package:
226
- * - style attributes are applied directly on DOM to avoid re-renders
227
- * - refs changes and resolution is handled properly without re-renders
228
- * - contains a specific to React fix related to initial positioning when containers have components with managed focus
229
- * to avoid focus jumps
230
- */
231
- function usePopper(options) {
232
- if (options === void 0) { options = {}; }
233
- var _a = options.enabled, enabled = _a === void 0 ? true : _a;
234
- var isFirstMount = react_utilities_1.useFirstMount();
235
- var popperOriginalPositionRef = React.useRef('absolute');
236
- var resolvePopperOptions = usePopperOptions(options, popperOriginalPositionRef);
237
- var popperInstanceRef = React.useRef(null);
238
- var handlePopperUpdate = react_utilities_1.useEventCallback(function () {
239
- var _a;
240
- (_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.destroy();
241
- popperInstanceRef.current = null;
242
- var _b = options.target, target = _b === void 0 ? targetRef.current : _b;
243
- var popperInstance = null;
244
- if (react_utilities_1.canUseDOM() && enabled) {
245
- if (target && containerRef.current) {
246
- popperInstance = PopperJs.createPopper(target, containerRef.current, resolvePopperOptions(target, containerRef.current, arrowRef.current));
247
- }
248
- }
249
- if (popperInstance) {
250
- /**
251
- * The patch updates `.forceUpdate()` Popper function which restores the original position before the first
252
- * forceUpdate() call. See also "positionStyleFix" modifier in usePopperOptions().
253
- */
254
- var originalForceUpdate_1 = popperInstance.forceUpdate;
255
- popperInstance.isFirstRun = true;
256
- popperInstance.forceUpdate = function () {
257
- if (popperInstance === null || popperInstance === void 0 ? void 0 : popperInstance.isFirstRun) {
258
- popperInstance.state.elements.popper.style.position = popperOriginalPositionRef.current;
259
- popperInstance.isFirstRun = false;
260
- }
261
- originalForceUpdate_1();
262
- };
263
- }
264
- popperInstanceRef.current = popperInstance;
265
- });
266
- // Refs are managed by useCallbackRef() to handle ref updates scenarios.
267
- //
268
- // The first scenario are updates for a targetRef, we can handle it properly only via callback refs, but it causes
269
- // re-renders (we would like to avoid them).
270
- //
271
- // The second problem is related to refs resolution on React's layer: refs are resolved in the same order as effects
272
- // that causes an issue when you have a container inside a target, for example: a menu in ChatMessage.
273
- //
274
- // function ChatMessage(props) {
275
- // <div className="message" ref={targetRef}> // 3) ref will be resolved only now, but it's too late already
276
- // <Popper target={targetRef}> // 2) create a popper instance
277
- // <div className="menu" /> // 1) capture ref from this element
278
- // </Popper>
279
- // </div>
280
- // }
281
- //
282
- // Check a demo on CodeSandbox: https://codesandbox.io/s/popper-refs-emy60.
283
- //
284
- // This again can be solved with callback refs. It's not a huge issue as with hooks we are moving popper's creation
285
- // to ChatMessage itself, however, without `useCallback()` refs it's still a Pandora box.
286
- var targetRef = index_1.useCallbackRef(null, handlePopperUpdate, true);
287
- var containerRef = index_1.useCallbackRef(null, handlePopperUpdate, true);
288
- var arrowRef = index_1.useCallbackRef(null, handlePopperUpdate, true);
289
- React.useImperativeHandle(options.popperRef, function () { return ({
290
- updatePosition: function () {
291
- var _a;
292
- (_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.update();
293
- },
294
- }); }, []);
295
- react_utilities_1.useIsomorphicLayoutEffect(function () {
296
- handlePopperUpdate();
297
- return function () {
298
- var _a;
299
- (_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.destroy();
300
- popperInstanceRef.current = null;
301
- };
302
- }, [handlePopperUpdate, options.enabled, options.target]);
303
- react_utilities_1.useIsomorphicLayoutEffect(function () {
304
- var _a;
305
- if (!isFirstMount) {
306
- (_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.setOptions(resolvePopperOptions(options.target || targetRef.current, containerRef.current, arrowRef.current));
307
- }
308
- },
309
- // Missing deps:
310
- // options.target - The useIsomorphicLayoutEffect before this will create a new popper instance if target changes
311
- // isFirstMount - Should never change after mount
312
- // arrowRef, containerRef, targetRef - Stable between renders
313
- // eslint-disable-next-line react-hooks/exhaustive-deps
314
- [resolvePopperOptions]);
315
-
316
- return { targetRef: targetRef, containerRef: containerRef, arrowRef: arrowRef };
317
- }
318
- exports.usePopper = usePopper;
319
- });
320
- //# sourceMappingURL=usePopper.js.map