@fluentui/react-positioning 0.0.0-nightlya372ad979820211103.1 → 0.0.0-nightlya54302c0b220211124.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. package/CHANGELOG.json +45 -10
  2. package/CHANGELOG.md +18 -7
  3. package/dist/react-positioning.d.ts +28 -0
  4. package/lib/createArrowStyles.d.ts +27 -0
  5. package/lib/createArrowStyles.js +75 -0
  6. package/lib/createArrowStyles.js.map +1 -0
  7. package/lib/createVirtualElementFromClick.js +9 -9
  8. package/lib/createVirtualElementFromClick.js.map +1 -1
  9. package/lib/index.d.ts +2 -1
  10. package/lib/index.js +2 -1
  11. package/lib/index.js.map +1 -1
  12. package/lib/usePopper.js +64 -71
  13. package/lib/usePopper.js.map +1 -1
  14. package/lib/usePopperMouseTarget.js +5 -5
  15. package/lib/usePopperMouseTarget.js.map +1 -1
  16. package/lib/utils/getBoundary.js +1 -1
  17. package/lib/utils/getReactFiberFromNode.d.ts +0 -1
  18. package/lib/utils/getReactFiberFromNode.js +1 -1
  19. package/lib/utils/getReactFiberFromNode.js.map +1 -1
  20. package/lib/utils/getScrollParent.js +6 -6
  21. package/lib/utils/getScrollParent.js.map +1 -1
  22. package/lib/utils/mergeArrowOffset.js +5 -5
  23. package/lib/utils/mergeArrowOffset.js.map +1 -1
  24. package/lib/utils/positioningHelper.d.ts +1 -1
  25. package/lib/utils/positioningHelper.js +14 -14
  26. package/lib/utils/positioningHelper.js.map +1 -1
  27. package/lib/utils/resolvePositioningShorthand.js +1 -1
  28. package/lib/utils/resolvePositioningShorthand.js.map +1 -1
  29. package/lib/utils/useCallbackRef.js +6 -6
  30. package/lib/utils/useCallbackRef.js.map +1 -1
  31. package/lib-commonjs/createArrowStyles.d.ts +27 -0
  32. package/lib-commonjs/createArrowStyles.js +79 -0
  33. package/lib-commonjs/createArrowStyles.js.map +1 -0
  34. package/lib-commonjs/createVirtualElementFromClick.js +9 -9
  35. package/lib-commonjs/createVirtualElementFromClick.js.map +1 -1
  36. package/lib-commonjs/index.d.ts +2 -1
  37. package/lib-commonjs/index.js +3 -2
  38. package/lib-commonjs/index.js.map +1 -1
  39. package/lib-commonjs/usePopper.js +69 -76
  40. package/lib-commonjs/usePopper.js.map +1 -1
  41. package/lib-commonjs/usePopperMouseTarget.js +7 -7
  42. package/lib-commonjs/usePopperMouseTarget.js.map +1 -1
  43. package/lib-commonjs/utils/getBoundary.js +2 -2
  44. package/lib-commonjs/utils/getBoundary.js.map +1 -1
  45. package/lib-commonjs/utils/getReactFiberFromNode.d.ts +0 -1
  46. package/lib-commonjs/utils/getReactFiberFromNode.js +1 -1
  47. package/lib-commonjs/utils/getReactFiberFromNode.js.map +1 -1
  48. package/lib-commonjs/utils/getScrollParent.js +6 -6
  49. package/lib-commonjs/utils/getScrollParent.js.map +1 -1
  50. package/lib-commonjs/utils/index.js +1 -1
  51. package/lib-commonjs/utils/mergeArrowOffset.js +5 -5
  52. package/lib-commonjs/utils/mergeArrowOffset.js.map +1 -1
  53. package/lib-commonjs/utils/positioningHelper.d.ts +1 -1
  54. package/lib-commonjs/utils/positioningHelper.js +14 -14
  55. package/lib-commonjs/utils/positioningHelper.js.map +1 -1
  56. package/lib-commonjs/utils/resolvePositioningShorthand.js +1 -1
  57. package/lib-commonjs/utils/resolvePositioningShorthand.js.map +1 -1
  58. package/lib-commonjs/utils/useCallbackRef.js +8 -8
  59. package/lib-commonjs/utils/useCallbackRef.js.map +1 -1
  60. package/package.json +4 -4
package/CHANGELOG.json CHANGED
@@ -2,28 +2,63 @@
2
2
  "name": "@fluentui/react-positioning",
3
3
  "entries": [
4
4
  {
5
- "date": "Wed, 03 Nov 2021 08:24:05 GMT",
6
- "tag": "@fluentui/react-positioning_v0.0.0-nightlya372ad979820211103.1",
7
- "version": "0.0.0-nightlya372ad979820211103.1",
5
+ "date": "Wed, 24 Nov 2021 04:12:45 GMT",
6
+ "tag": "@fluentui/react-positioning_v0.0.0-nightlya54302c0b220211124.1",
7
+ "version": "0.0.0-nightlya54302c0b220211124.1",
8
8
  "comments": {
9
9
  "prerelease": [
10
10
  {
11
- "author": "email not defined",
11
+ "author": "lingfangao@hotmail.com",
12
+ "package": "@fluentui/react-positioning",
13
+ "commit": "58db204f28af1d68df7260ff580cf91f0adcfb66",
14
+ "comment": "Add utility function to create styles for an arrow element"
15
+ },
16
+ {
17
+ "author": "beachball",
18
+ "package": "@fluentui/react-positioning",
19
+ "comment": "Bump @fluentui/react-make-styles to v0.0.0-nightlya54302c0b220211124.1",
20
+ "commit": "e3c1bd15060ac276670338660c7965b877e333f4"
21
+ },
22
+ {
23
+ "author": "beachball",
24
+ "package": "@fluentui/react-positioning",
25
+ "comment": "Bump @fluentui/react-shared-contexts to v0.0.0-nightlya54302c0b220211124.1",
26
+ "commit": "e3c1bd15060ac276670338660c7965b877e333f4"
27
+ }
28
+ ]
29
+ }
30
+ },
31
+ {
32
+ "date": "Fri, 12 Nov 2021 13:25:30 GMT",
33
+ "tag": "@fluentui/react-positioning_v9.0.0-beta.3",
34
+ "version": "9.0.0-beta.3",
35
+ "comments": {
36
+ "prerelease": [
37
+ {
38
+ "author": "gcox@microsoft.com",
12
39
  "package": "@fluentui/react-positioning",
13
- "commit": "ff9c0a60767a2dbd1afdc71659a5daee5f2068dd",
14
- "comment": "Release nightly v9"
40
+ "commit": "c9bd5b5a02ae94a8239ce1b56cac2f0d0dbd3586",
41
+ "comment": "Updated beta and RC components to ES2019"
15
42
  },
16
43
  {
17
44
  "author": "beachball",
18
45
  "package": "@fluentui/react-positioning",
19
- "comment": "Bump @fluentui/react-shared-contexts to v0.0.0-nightlya372ad979820211103.1",
20
- "commit": "ff9c0a60767a2dbd1afdc71659a5daee5f2068dd"
46
+ "comment": "Bump @fluentui/react-shared-contexts to v9.0.0-beta.3",
47
+ "commit": "742342e52c65066f779232e4e1302fedf0dd460d"
21
48
  },
22
49
  {
23
50
  "author": "beachball",
24
51
  "package": "@fluentui/react-positioning",
25
- "comment": "Bump @fluentui/react-utilities to v0.0.0-nightlya372ad979820211103.1",
26
- "commit": "ff9c0a60767a2dbd1afdc71659a5daee5f2068dd"
52
+ "comment": "Bump @fluentui/react-utilities to v9.0.0-beta.3",
53
+ "commit": "742342e52c65066f779232e4e1302fedf0dd460d"
54
+ }
55
+ ],
56
+ "none": [
57
+ {
58
+ "author": "lingfangao@hotmail.com",
59
+ "package": "@fluentui/react-positioning",
60
+ "commit": "00f70581480b536e723fb69edf0ae617beac4807",
61
+ "comment": "Remove beta release tag"
27
62
  }
28
63
  ]
29
64
  }
package/CHANGELOG.md CHANGED
@@ -1,19 +1,30 @@
1
1
  # Change Log - @fluentui/react-positioning
2
2
 
3
- This log was last generated on Wed, 03 Nov 2021 08:24:05 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 24 Nov 2021 04:12:45 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## [0.0.0-nightlya372ad979820211103.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-positioning_v0.0.0-nightlya372ad979820211103.1)
7
+ ## [0.0.0-nightlya54302c0b220211124.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-positioning_v0.0.0-nightlya54302c0b220211124.1)
8
8
 
9
- Wed, 03 Nov 2021 08:24:05 GMT
10
- [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-positioning_v9.0.0-beta.2..@fluentui/react-positioning_v0.0.0-nightlya372ad979820211103.1)
9
+ Wed, 24 Nov 2021 04:12:45 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-positioning_v9.0.0-beta.3..@fluentui/react-positioning_v0.0.0-nightlya54302c0b220211124.1)
11
11
 
12
12
  ### Changes
13
13
 
14
- - Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/ff9c0a60767a2dbd1afdc71659a5daee5f2068dd) by email not defined)
15
- - Bump @fluentui/react-shared-contexts to v0.0.0-nightlya372ad979820211103.1 ([commit](https://github.com/microsoft/fluentui/commit/ff9c0a60767a2dbd1afdc71659a5daee5f2068dd) by beachball)
16
- - Bump @fluentui/react-utilities to v0.0.0-nightlya372ad979820211103.1 ([commit](https://github.com/microsoft/fluentui/commit/ff9c0a60767a2dbd1afdc71659a5daee5f2068dd) by beachball)
14
+ - Add utility function to create styles for an arrow element ([PR #20541](https://github.com/microsoft/fluentui/pull/20541) by lingfangao@hotmail.com)
15
+ - Bump @fluentui/react-make-styles to v0.0.0-nightlya54302c0b220211124.1 ([commit](https://github.com/microsoft/fluentui/commit/e3c1bd15060ac276670338660c7965b877e333f4) by beachball)
16
+ - Bump @fluentui/react-shared-contexts to v0.0.0-nightlya54302c0b220211124.1 ([commit](https://github.com/microsoft/fluentui/commit/e3c1bd15060ac276670338660c7965b877e333f4) by beachball)
17
+
18
+ ## [9.0.0-beta.3](https://github.com/microsoft/fluentui/tree/@fluentui/react-positioning_v9.0.0-beta.3)
19
+
20
+ Fri, 12 Nov 2021 13:25:30 GMT
21
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-positioning_v9.0.0-beta.2..@fluentui/react-positioning_v9.0.0-beta.3)
22
+
23
+ ### Changes
24
+
25
+ - Updated beta and RC components to ES2019 ([PR #20405](https://github.com/microsoft/fluentui/pull/20405) by gcox@microsoft.com)
26
+ - Bump @fluentui/react-shared-contexts to v9.0.0-beta.3 ([PR #20583](https://github.com/microsoft/fluentui/pull/20583) by beachball)
27
+ - Bump @fluentui/react-utilities to v9.0.0-beta.3 ([PR #20583](https://github.com/microsoft/fluentui/pull/20583) by beachball)
17
28
 
18
29
  ## [9.0.0-beta.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-positioning_v9.0.0-beta.2)
19
30
 
@@ -1,5 +1,7 @@
1
+ import type { MakeStylesStyleRule } from '@fluentui/make-styles';
1
2
  import * as PopperJs from '@popperjs/core';
2
3
  import * as React_2 from 'react';
4
+ import type { Theme } from '@fluentui/react-theme';
3
5
 
4
6
  export declare type Alignment = 'top' | 'bottom' | 'start' | 'end' | 'center';
5
7
 
@@ -7,6 +9,32 @@ export declare type AutoSize = 'height' | 'height-always' | 'width' | 'width-alw
7
9
 
8
10
  export declare type Boundary = PopperJs.Boundary | 'scrollParent' | 'window';
9
11
 
12
+ /**
13
+ * Helper that creates a makeStyles rule for an arrow element.
14
+ * For runtime arrow size toggling simply create extra classnames to apply to the arrow element
15
+ *
16
+ * ```ts
17
+ * makeStyles({
18
+ * arrowWithSize: createArrowStyles(5),
19
+ *
20
+ * arrowWithoutSize: createArrowStyles(),
21
+ * mediumArrow: { aspectRatio: 1, width: '4px' }
22
+ * smallArrow: { aspectRatio: 1, width: '2px' }
23
+ * })
24
+ * ...
25
+ *
26
+ * state.arrowWithSize.clasName = styles.arrowWithSize
27
+ * state.arrowWithoutSize.className = mergeClases(
28
+ * styles.arrowWithoutSize,
29
+ * state.smallArrow && styles.smallArrow,
30
+ * state.mediumArrow && styles.mediumArrow,
31
+ * )
32
+ * ```
33
+ *
34
+ * @param size - dimensions of the square arrow element in pixels.
35
+ */
36
+ export declare function createArrowStyles(size?: number): MakeStylesStyleRule<Theme>;
37
+
10
38
  /**
11
39
  * Creates a virtual element based on the position of a click event
12
40
  * Can be used as a target for popper in scenarios such as context menus
@@ -0,0 +1,27 @@
1
+ import type { MakeStylesStyleRule } from '@fluentui/make-styles';
2
+ import type { Theme } from '@fluentui/react-theme';
3
+ /**
4
+ * Helper that creates a makeStyles rule for an arrow element.
5
+ * For runtime arrow size toggling simply create extra classnames to apply to the arrow element
6
+ *
7
+ * ```ts
8
+ * makeStyles({
9
+ * arrowWithSize: createArrowStyles(5),
10
+ *
11
+ * arrowWithoutSize: createArrowStyles(),
12
+ * mediumArrow: { aspectRatio: 1, width: '4px' }
13
+ * smallArrow: { aspectRatio: 1, width: '2px' }
14
+ * })
15
+ * ...
16
+ *
17
+ * state.arrowWithSize.clasName = styles.arrowWithSize
18
+ * state.arrowWithoutSize.className = mergeClases(
19
+ * styles.arrowWithoutSize,
20
+ * state.smallArrow && styles.smallArrow,
21
+ * state.mediumArrow && styles.mediumArrow,
22
+ * )
23
+ * ```
24
+ *
25
+ * @param size - dimensions of the square arrow element in pixels.
26
+ */
27
+ export declare function createArrowStyles(size?: number): MakeStylesStyleRule<Theme>;
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Helper that creates a makeStyles rule for an arrow element.
3
+ * For runtime arrow size toggling simply create extra classnames to apply to the arrow element
4
+ *
5
+ * ```ts
6
+ * makeStyles({
7
+ * arrowWithSize: createArrowStyles(5),
8
+ *
9
+ * arrowWithoutSize: createArrowStyles(),
10
+ * mediumArrow: { aspectRatio: 1, width: '4px' }
11
+ * smallArrow: { aspectRatio: 1, width: '2px' }
12
+ * })
13
+ * ...
14
+ *
15
+ * state.arrowWithSize.clasName = styles.arrowWithSize
16
+ * state.arrowWithoutSize.className = mergeClases(
17
+ * styles.arrowWithoutSize,
18
+ * state.smallArrow && styles.smallArrow,
19
+ * state.mediumArrow && styles.mediumArrow,
20
+ * )
21
+ * ```
22
+ *
23
+ * @param size - dimensions of the square arrow element in pixels.
24
+ */
25
+ export function createArrowStyles(size) {
26
+ return theme => {
27
+ const arrowHCBorderStyle = `1px solid transparent`;
28
+ const arrowHCBorder = {
29
+ borderRight: arrowHCBorderStyle,
30
+ borderBottom: arrowHCBorderStyle,
31
+ };
32
+ return {
33
+ position: 'absolute',
34
+ background: 'inherit',
35
+ visibility: 'hidden',
36
+ zIndex: -1,
37
+ ...(size && {
38
+ aspectRatio: 1,
39
+ width: `${size}px`,
40
+ }),
41
+ ':before': {
42
+ content: '""',
43
+ borderRadius: '4px',
44
+ position: 'absolute',
45
+ width: 'inherit',
46
+ height: 'inherit',
47
+ background: 'inherit',
48
+ visibility: 'visible',
49
+ borderBottomRightRadius: theme.borderRadiusSmall,
50
+ transform: 'rotate(var(--angle)) translate(0, 50%) rotate(45deg)',
51
+ },
52
+ ':global([data-popper-placement])': {
53
+ ':before': arrowHCBorder,
54
+ },
55
+ // Popper sets data-popper-placement on the root element, which is used to align the arrow
56
+ ':global([data-popper-placement^="top"])': {
57
+ bottom: 0,
58
+ '--angle': '0',
59
+ },
60
+ ':global([data-popper-placement^="right"])': {
61
+ left: 0,
62
+ '--angle': '90deg',
63
+ },
64
+ ':global([data-popper-placement^="bottom"])': {
65
+ top: 0,
66
+ '--angle': '180deg',
67
+ },
68
+ ':global([data-popper-placement^="left"])': {
69
+ right: 0,
70
+ '--angle': '270deg',
71
+ },
72
+ };
73
+ };
74
+ }
75
+ //# sourceMappingURL=createArrowStyles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createArrowStyles.js","sourceRoot":"","sources":["../src/createArrowStyles.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAa;IAC7C,OAAO,KAAK,CAAC,EAAE;QACb,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;QACnD,MAAM,aAAa,GAAG;YACpB,WAAW,EAAE,kBAAkB;YAC/B,YAAY,EAAE,kBAAkB;SACjC,CAAC;QAEF,OAAO;YACL,QAAQ,EAAE,UAAU;YACpB,UAAU,EAAE,SAAS;YACrB,UAAU,EAAE,QAAQ;YACpB,MAAM,EAAE,CAAC,CAAC;YAEV,GAAG,CAAC,IAAI,IAAI;gBACV,WAAW,EAAE,CAAC;gBACd,KAAK,EAAE,GAAG,IAAI,IAAI;aACnB,CAAC;YAEF,SAAS,EAAE;gBACT,OAAO,EAAE,IAAI;gBACb,YAAY,EAAE,KAAK;gBACnB,QAAQ,EAAE,UAAU;gBACpB,KAAK,EAAE,SAAS;gBAChB,MAAM,EAAE,SAAS;gBACjB,UAAU,EAAE,SAAS;gBACrB,UAAU,EAAE,SAAS;gBACrB,uBAAuB,EAAE,KAAK,CAAC,iBAAiB;gBAChD,SAAS,EAAE,sDAAsD;aAClE;YAED,kCAAkC,EAAE;gBAClC,SAAS,EAAE,aAAa;aACzB;YAED,0FAA0F;YAC1F,yCAAyC,EAAE;gBACzC,MAAM,EAAE,CAAC;gBACT,SAAS,EAAE,GAAG;aACf;YAED,2CAA2C,EAAE;gBAC3C,IAAI,EAAE,CAAC;gBACP,SAAS,EAAE,OAAO;aACnB;YACD,4CAA4C,EAAE;gBAC5C,GAAG,EAAE,CAAC;gBACN,SAAS,EAAE,QAAQ;aACpB;YACD,0CAA0C,EAAE;gBAC1C,KAAK,EAAE,CAAC;gBACR,SAAS,EAAE,QAAQ;aACpB;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -3,22 +3,22 @@
3
3
  * Can be used as a target for popper in scenarios such as context menus
4
4
  */
5
5
  export function createVirtualElementFromClick(nativeEvent) {
6
- var left = nativeEvent.clientX;
7
- var top = nativeEvent.clientY;
8
- var right = left + 1;
9
- var bottom = top + 1;
6
+ const left = nativeEvent.clientX;
7
+ const top = nativeEvent.clientY;
8
+ const right = left + 1;
9
+ const bottom = top + 1;
10
10
  function getBoundingClientRect() {
11
11
  return {
12
- left: left,
13
- top: top,
14
- right: right,
15
- bottom: bottom,
12
+ left,
13
+ top,
14
+ right,
15
+ bottom,
16
16
  height: 1,
17
17
  width: 1,
18
18
  };
19
19
  }
20
20
  return {
21
- getBoundingClientRect: getBoundingClientRect,
21
+ getBoundingClientRect,
22
22
  };
23
23
  }
24
24
  //# sourceMappingURL=createVirtualElementFromClick.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createVirtualElementFromClick.js","sourceRoot":"","sources":["../src/createVirtualElementFromClick.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,6BAA6B,CAAC,WAAuB;IACnE,IAAM,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC;IACjC,IAAM,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC;IAChC,IAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC;IACvB,IAAM,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC;IAEvB,SAAS,qBAAqB;QAC5B,OAAO;YACL,IAAI,MAAA;YACJ,GAAG,KAAA;YACH,KAAK,OAAA;YACL,MAAM,QAAA;YAEN,MAAM,EAAE,CAAC;YACT,KAAK,EAAE,CAAC;SACT,CAAC;IACJ,CAAC;IAED,OAAO;QACL,qBAAqB,uBAAA;KACtB,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"createVirtualElementFromClick.js","sourceRoot":"","sources":["../src/createVirtualElementFromClick.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,6BAA6B,CAAC,WAAuB;IACnE,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC;IACjC,MAAM,GAAG,GAAG,WAAW,CAAC,OAAO,CAAC;IAChC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC;IACvB,MAAM,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC;IAEvB,SAAS,qBAAqB;QAC5B,OAAO;YACL,IAAI;YACJ,GAAG;YACH,KAAK;YACL,MAAM;YAEN,MAAM,EAAE,CAAC;YACT,KAAK,EAAE,CAAC;SACT,CAAC;IACJ,CAAC;IAED,OAAO;QACL,qBAAqB;KACtB,CAAC;AACJ,CAAC"}
package/lib/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- export * from './usePopper';
2
1
  export * from './createVirtualElementFromClick';
2
+ export * from './createArrowStyles';
3
+ export * from './usePopper';
3
4
  export * from './usePopperMouseTarget';
4
5
  export { resolvePositioningShorthand, mergeArrowOffset } from './utils/index';
5
6
  export * from './types';
package/lib/index.js CHANGED
@@ -1,5 +1,6 @@
1
- export * from './usePopper';
2
1
  export * from './createVirtualElementFromClick';
2
+ export * from './createArrowStyles';
3
+ export * from './usePopper';
3
4
  export * from './usePopperMouseTarget';
4
5
  export { resolvePositioningShorthand, mergeArrowOffset } from './utils/index';
5
6
  export * from './types';
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,iCAAiC,CAAC;AAChD,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,2BAA2B,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC9E,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,2BAA2B,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC9E,cAAc,SAAS,CAAC"}
package/lib/usePopper.js CHANGED
@@ -13,7 +13,7 @@ import * as React from 'react';
13
13
  function hasAutofocusProp(node) {
14
14
  var _a;
15
15
  // https://github.com/facebook/react/blob/848bb2426e44606e0a55dfe44c7b3ece33772485/packages/react-dom/src/client/ReactDOMHostConfig.js#L157-L166
16
- var isAutoFocusableElement = node.nodeName === 'BUTTON' ||
16
+ const isAutoFocusableElement = node.nodeName === 'BUTTON' ||
17
17
  node.nodeName === 'INPUT' ||
18
18
  node.nodeName === 'SELECT' ||
19
19
  node.nodeName === 'TEXTAREA';
@@ -33,33 +33,30 @@ function hasAutofocusFilter(node) {
33
33
  * that can't be resolved properly during an initial rendering.
34
34
  */
35
35
  function usePopperOptions(options, popperOriginalPositionRef) {
36
- var arrowPadding = options.arrowPadding, autoSize = options.autoSize, coverTarget = options.coverTarget, flipBoundary = options.flipBoundary, offset = options.offset, onStateUpdate = options.onStateUpdate, overflowBoundary = options.overflowBoundary,
36
+ const { arrowPadding, autoSize, coverTarget, flipBoundary, offset, onStateUpdate, overflowBoundary,
37
37
  // eslint-disable-next-line @typescript-eslint/naming-convention
38
- unstable_disableTether = options.unstable_disableTether, pinned = options.pinned;
39
- var isRtl = useFluent().dir === 'rtl';
40
- var placement = getPlacement(options.align, options.position, isRtl);
41
- var strategy = options.positionFixed ? 'fixed' : 'absolute';
42
- var handleStateUpdate = useEventCallback(function (_a) {
43
- var state = _a.state;
38
+ unstable_disableTether, pinned, } = options;
39
+ const isRtl = useFluent().dir === 'rtl';
40
+ const placement = getPlacement(options.align, options.position, isRtl);
41
+ const strategy = options.positionFixed ? 'fixed' : 'absolute';
42
+ const handleStateUpdate = useEventCallback(({ state }) => {
44
43
  if (onStateUpdate) {
45
44
  onStateUpdate(state);
46
45
  }
47
46
  });
48
- var offsetModifier = React.useMemo(function () {
49
- return offset
50
- ? {
51
- name: 'offset',
52
- options: { offset: isRtl ? applyRtlToOffset(offset) : offset },
53
- }
54
- : null;
55
- }, [offset, isRtl]);
56
- return React.useCallback(function (target, container, arrow) {
47
+ const offsetModifier = React.useMemo(() => offset
48
+ ? {
49
+ name: 'offset',
50
+ options: { offset: isRtl ? applyRtlToOffset(offset) : offset },
51
+ }
52
+ : null, [offset, isRtl]);
53
+ return React.useCallback((target, container, arrow) => {
57
54
  var _a;
58
- var scrollParentElement = getScrollParent(container);
59
- var hasScrollableElement = scrollParentElement
55
+ const scrollParentElement = getScrollParent(container);
56
+ const hasScrollableElement = scrollParentElement
60
57
  ? scrollParentElement !== ((_a = scrollParentElement.ownerDocument) === null || _a === void 0 ? void 0 : _a.body)
61
58
  : false;
62
- var modifiers = [
59
+ const modifiers = [
63
60
  /**
64
61
  * We are setting the position to `fixed` in the first effect to prevent scroll jumps in case of the content
65
62
  * with managed focus. Modifier sets the position to `fixed` before all other modifier effects. Another part of
@@ -69,15 +66,14 @@ function usePopperOptions(options, popperOriginalPositionRef) {
69
66
  name: 'positionStyleFix',
70
67
  enabled: true,
71
68
  phase: 'afterWrite',
72
- effect: function (_a) {
73
- var state = _a.state, instance = _a.instance;
69
+ effect: ({ state, instance }) => {
74
70
  // ".isFirstRun" is a part of our patch, on a first evaluation it will "undefined"
75
71
  // should be disabled for subsequent runs as it breaks positioning for them
76
72
  if (instance.isFirstRun !== false) {
77
73
  popperOriginalPositionRef.current = state.elements.popper.style.position;
78
74
  state.elements.popper.style.position = 'fixed';
79
75
  }
80
- return function () { return undefined; };
76
+ return () => undefined;
81
77
  },
82
78
  requires: [],
83
79
  },
@@ -139,25 +135,24 @@ function usePopperOptions(options, popperOriginalPositionRef) {
139
135
  altBoundary: true,
140
136
  boundary: getBoundary(container, overflowBoundary),
141
137
  },
142
- fn: function (_a) {
143
- var state = _a.state, modifierOptions = _a.options;
144
- var overflow = PopperJs.detectOverflow(state, modifierOptions);
145
- var _b = state.modifiersData.preventOverflow || { x: 0, y: 0 }, x = _b.x, y = _b.y;
146
- var _c = state.rects.popper, width = _c.width, height = _c.height;
147
- var basePlacement = getBasePlacement(state.placement);
148
- var widthProp = basePlacement === 'left' ? 'left' : 'right';
149
- var heightProp = basePlacement === 'top' ? 'top' : 'bottom';
150
- var applyMaxWidth = autoSize === 'always' ||
138
+ fn({ state, options: modifierOptions }) {
139
+ const overflow = PopperJs.detectOverflow(state, modifierOptions);
140
+ const { x, y } = state.modifiersData.preventOverflow || { x: 0, y: 0 };
141
+ const { width, height } = state.rects.popper;
142
+ const basePlacement = getBasePlacement(state.placement);
143
+ const widthProp = basePlacement === 'left' ? 'left' : 'right';
144
+ const heightProp = basePlacement === 'top' ? 'top' : 'bottom';
145
+ const applyMaxWidth = autoSize === 'always' ||
151
146
  autoSize === 'width-always' ||
152
147
  (overflow[widthProp] > 0 && (autoSize === true || autoSize === 'width'));
153
- var applyMaxHeight = autoSize === 'always' ||
148
+ const applyMaxHeight = autoSize === 'always' ||
154
149
  autoSize === 'height-always' ||
155
150
  (overflow[heightProp] > 0 && (autoSize === true || autoSize === 'height'));
156
151
  if (applyMaxWidth) {
157
- state.styles.popper.maxWidth = width - overflow[widthProp] - x + "px";
152
+ state.styles.popper.maxWidth = `${width - overflow[widthProp] - x}px`;
158
153
  }
159
154
  if (applyMaxHeight) {
160
- state.styles.popper.maxHeight = height - overflow[heightProp] - y + "px";
155
+ state.styles.popper.maxHeight = `${height - overflow[heightProp] - y}px`;
161
156
  }
162
157
  },
163
158
  },
@@ -178,9 +173,8 @@ function usePopperOptions(options, popperOriginalPositionRef) {
178
173
  enabled: !!coverTarget,
179
174
  phase: 'main',
180
175
  requiresIfExists: ['offset', 'preventOverflow', 'flip'],
181
- fn: function (_a) {
182
- var state = _a.state;
183
- var basePlacement = getBasePlacement(state.placement);
176
+ fn({ state }) {
177
+ const basePlacement = getBasePlacement(state.placement);
184
178
  switch (basePlacement) {
185
179
  case 'bottom':
186
180
  state.modifiersData.popperOffsets.y -= state.rects.reference.height;
@@ -198,11 +192,11 @@ function usePopperOptions(options, popperOriginalPositionRef) {
198
192
  },
199
193
  },
200
194
  ].filter(Boolean); // filter boolean conditional spreading values
201
- var popperOptions = {
202
- modifiers: modifiers,
203
- placement: placement,
204
- strategy: strategy,
205
- onFirstUpdate: function (state) { return handleStateUpdate({ state: state }); },
195
+ const popperOptions = {
196
+ modifiers,
197
+ placement,
198
+ strategy,
199
+ onFirstUpdate: state => handleStateUpdate({ state }),
206
200
  };
207
201
  return popperOptions;
208
202
  }, [
@@ -229,19 +223,18 @@ function usePopperOptions(options, popperOriginalPositionRef) {
229
223
  * - contains a specific to React fix related to initial positioning when containers have components with managed focus
230
224
  * to avoid focus jumps
231
225
  */
232
- export function usePopper(options) {
233
- if (options === void 0) { options = {}; }
234
- var _a = options.enabled, enabled = _a === void 0 ? true : _a;
235
- var isFirstMount = useFirstMount();
236
- var popperOriginalPositionRef = React.useRef('absolute');
237
- var resolvePopperOptions = usePopperOptions(options, popperOriginalPositionRef);
238
- var popperInstanceRef = React.useRef(null);
239
- var handlePopperUpdate = useEventCallback(function () {
226
+ export function usePopper(options = {}) {
227
+ const { enabled = true } = options;
228
+ const isFirstMount = useFirstMount();
229
+ const popperOriginalPositionRef = React.useRef('absolute');
230
+ const resolvePopperOptions = usePopperOptions(options, popperOriginalPositionRef);
231
+ const popperInstanceRef = React.useRef(null);
232
+ const handlePopperUpdate = useEventCallback(() => {
240
233
  var _a;
241
234
  (_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.destroy();
242
235
  popperInstanceRef.current = null;
243
- var _b = options.target, target = _b === void 0 ? targetRef.current : _b;
244
- var popperInstance = null;
236
+ const { target = targetRef.current } = options;
237
+ let popperInstance = null;
245
238
  if (canUseDOM() && enabled) {
246
239
  if (target && containerRef.current) {
247
240
  popperInstance = PopperJs.createPopper(target, containerRef.current, resolvePopperOptions(target, containerRef.current, arrowRef.current));
@@ -252,14 +245,14 @@ export function usePopper(options) {
252
245
  * The patch updates `.forceUpdate()` Popper function which restores the original position before the first
253
246
  * forceUpdate() call. See also "positionStyleFix" modifier in usePopperOptions().
254
247
  */
255
- var originalForceUpdate_1 = popperInstance.forceUpdate;
248
+ const originalForceUpdate = popperInstance.forceUpdate;
256
249
  popperInstance.isFirstRun = true;
257
- popperInstance.forceUpdate = function () {
250
+ popperInstance.forceUpdate = () => {
258
251
  if (popperInstance === null || popperInstance === void 0 ? void 0 : popperInstance.isFirstRun) {
259
252
  popperInstance.state.elements.popper.style.position = popperOriginalPositionRef.current;
260
253
  popperInstance.isFirstRun = false;
261
254
  }
262
- originalForceUpdate_1();
255
+ originalForceUpdate();
263
256
  };
264
257
  }
265
258
  popperInstanceRef.current = popperInstance;
@@ -284,24 +277,24 @@ export function usePopper(options) {
284
277
  //
285
278
  // This again can be solved with callback refs. It's not a huge issue as with hooks we are moving popper's creation
286
279
  // to ChatMessage itself, however, without `useCallback()` refs it's still a Pandora box.
287
- var targetRef = useCallbackRef(null, handlePopperUpdate, true);
288
- var containerRef = useCallbackRef(null, handlePopperUpdate, true);
289
- var arrowRef = useCallbackRef(null, handlePopperUpdate, true);
290
- React.useImperativeHandle(options.popperRef, function () { return ({
291
- updatePosition: function () {
280
+ const targetRef = useCallbackRef(null, handlePopperUpdate, true);
281
+ const containerRef = useCallbackRef(null, handlePopperUpdate, true);
282
+ const arrowRef = useCallbackRef(null, handlePopperUpdate, true);
283
+ React.useImperativeHandle(options.popperRef, () => ({
284
+ updatePosition: () => {
292
285
  var _a;
293
286
  (_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.update();
294
287
  },
295
- }); }, []);
296
- useIsomorphicLayoutEffect(function () {
288
+ }), []);
289
+ useIsomorphicLayoutEffect(() => {
297
290
  handlePopperUpdate();
298
- return function () {
291
+ return () => {
299
292
  var _a;
300
293
  (_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.destroy();
301
294
  popperInstanceRef.current = null;
302
295
  };
303
296
  }, [handlePopperUpdate, options.enabled, options.target]);
304
- useIsomorphicLayoutEffect(function () {
297
+ useIsomorphicLayoutEffect(() => {
305
298
  var _a;
306
299
  if (!isFirstMount) {
307
300
  (_a = popperInstanceRef.current) === null || _a === void 0 ? void 0 : _a.setOptions(resolvePopperOptions(options.target || targetRef.current, containerRef.current, arrowRef.current));
@@ -316,15 +309,15 @@ export function usePopper(options) {
316
309
  if (process.env.NODE_ENV !== 'production') {
317
310
  // This checked should run only in development mode
318
311
  // eslint-disable-next-line react-hooks/rules-of-hooks
319
- React.useEffect(function () {
312
+ React.useEffect(() => {
320
313
  var _a;
321
314
  if (containerRef.current) {
322
- var contentNode = containerRef.current;
323
- var treeWalker = (_a = contentNode.ownerDocument) === null || _a === void 0 ? void 0 : _a.createTreeWalker(contentNode, NodeFilter.SHOW_ELEMENT, {
315
+ const contentNode = containerRef.current;
316
+ const treeWalker = (_a = contentNode.ownerDocument) === null || _a === void 0 ? void 0 : _a.createTreeWalker(contentNode, NodeFilter.SHOW_ELEMENT, {
324
317
  acceptNode: hasAutofocusFilter,
325
318
  });
326
319
  while (treeWalker === null || treeWalker === void 0 ? void 0 : treeWalker.nextNode()) {
327
- var node = treeWalker.currentNode;
320
+ const node = treeWalker.currentNode;
328
321
  // eslint-disable-next-line no-console
329
322
  console.warn('<Popper>:', node);
330
323
  // eslint-disable-next-line no-console
@@ -338,7 +331,7 @@ export function usePopper(options) {
338
331
  '(React.useEffect(), componentDidMount(), etc.) and we can not prevent this behavior. If you really',
339
332
  'want to use "autoFocus" please add "position: fixed" to styles of the element that is wrapped by',
340
333
  '"Popper".',
341
- "In general, it's not recommended to use \"autoFocus\" as it may break accessibility aspects:",
334
+ `In general, it's not recommended to use "autoFocus" as it may break accessibility aspects:`,
342
335
  'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-autofocus.md',
343
336
  '\n',
344
337
  'We suggest to use the "trapFocus" prop on Fluent components or a catch "ref" and then use',
@@ -352,6 +345,6 @@ export function usePopper(options) {
352
345
  // eslint-disable-next-line react-hooks/exhaustive-deps
353
346
  }, []);
354
347
  }
355
- return { targetRef: targetRef, containerRef: containerRef, arrowRef: arrowRef };
348
+ return { targetRef, containerRef, arrowRef };
356
349
  }
357
350
  //# sourceMappingURL=usePopper.js.map