@wordpress/components 21.1.0 → 21.1.2-next.4d3b314fd5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/build/draggable/index.js +3 -6
  3. package/build/draggable/index.js.map +1 -1
  4. package/build/index.js +6 -0
  5. package/build/index.js.map +1 -1
  6. package/build/menu-item/index.js +4 -3
  7. package/build/menu-item/index.js.map +1 -1
  8. package/build/mobile/bottom-sheet/bottom-sheet-navigation/navigation-container.native.js +10 -3
  9. package/build/mobile/bottom-sheet/bottom-sheet-navigation/navigation-container.native.js.map +1 -1
  10. package/build/mobile/bottom-sheet/bottom-sheet-navigation/navigation-screen.native.js +12 -3
  11. package/build/mobile/bottom-sheet/bottom-sheet-navigation/navigation-screen.native.js.map +1 -1
  12. package/build/mobile/bottom-sheet/sub-sheet/index.native.js +4 -1
  13. package/build/mobile/bottom-sheet/sub-sheet/index.native.js.map +1 -1
  14. package/build/mobile/color-settings/index.native.js +3 -1
  15. package/build/mobile/color-settings/index.native.js.map +1 -1
  16. package/build/mobile/color-settings/picker-screen.native.js +3 -1
  17. package/build/mobile/color-settings/picker-screen.native.js.map +1 -1
  18. package/build/mobile/image/index.native.js +3 -1
  19. package/build/mobile/image/index.native.js.map +1 -1
  20. package/build/mobile/keyboard-avoiding-view/index.ios.js +3 -1
  21. package/build/mobile/keyboard-avoiding-view/index.ios.js.map +1 -1
  22. package/build/mobile/link-picker/index.native.js +3 -1
  23. package/build/mobile/link-picker/index.native.js.map +1 -1
  24. package/build/mobile/link-picker/link-picker-results.native.js +3 -1
  25. package/build/mobile/link-picker/link-picker-results.native.js.map +1 -1
  26. package/build/mobile/link-picker/link-picker-screen.native.js +3 -1
  27. package/build/mobile/link-picker/link-picker-screen.native.js.map +1 -1
  28. package/build/mobile/link-settings/index.native.js +24 -6
  29. package/build/mobile/link-settings/index.native.js.map +1 -1
  30. package/build/mobile/link-settings/link-settings-screen.native.js +3 -1
  31. package/build/mobile/link-settings/link-settings-screen.native.js.map +1 -1
  32. package/build/mobile/segmented-control/index.native.js +6 -2
  33. package/build/mobile/segmented-control/index.native.js.map +1 -1
  34. package/build/mobile/utils/use-unit-converter-to-mobile.native.js +6 -2
  35. package/build/mobile/utils/use-unit-converter-to-mobile.native.js.map +1 -1
  36. package/build/notice/index.native.js +15 -19
  37. package/build/notice/index.native.js.map +1 -1
  38. package/build/notice/list.native.js +2 -3
  39. package/build/notice/list.native.js.map +1 -1
  40. package/build/palette-edit/index.js +1 -1
  41. package/build/palette-edit/index.js.map +1 -1
  42. package/build/popover/index.js +29 -32
  43. package/build/popover/index.js.map +1 -1
  44. package/build/popover/limit-shift.js +145 -0
  45. package/build/popover/limit-shift.js.map +1 -0
  46. package/build/popover/utils.js +55 -15
  47. package/build/popover/utils.js.map +1 -1
  48. package/build/tools-panel/styles.js +27 -12
  49. package/build/tools-panel/styles.js.map +1 -1
  50. package/build/tools-panel/tools-panel-header/component.js +19 -6
  51. package/build/tools-panel/tools-panel-header/component.js.map +1 -1
  52. package/build/tools-panel/tools-panel-header/hook.js +4 -0
  53. package/build/tools-panel/tools-panel-header/hook.js.map +1 -1
  54. package/build-module/draggable/index.js +2 -5
  55. package/build-module/draggable/index.js.map +1 -1
  56. package/build-module/index.js +1 -1
  57. package/build-module/index.js.map +1 -1
  58. package/build-module/menu-item/index.js +4 -3
  59. package/build-module/menu-item/index.js.map +1 -1
  60. package/build-module/mobile/bottom-sheet/bottom-sheet-navigation/navigation-container.native.js +10 -3
  61. package/build-module/mobile/bottom-sheet/bottom-sheet-navigation/navigation-container.native.js.map +1 -1
  62. package/build-module/mobile/bottom-sheet/bottom-sheet-navigation/navigation-screen.native.js +12 -3
  63. package/build-module/mobile/bottom-sheet/bottom-sheet-navigation/navigation-screen.native.js.map +1 -1
  64. package/build-module/mobile/bottom-sheet/sub-sheet/index.native.js +4 -1
  65. package/build-module/mobile/bottom-sheet/sub-sheet/index.native.js.map +1 -1
  66. package/build-module/mobile/color-settings/index.native.js +3 -1
  67. package/build-module/mobile/color-settings/index.native.js.map +1 -1
  68. package/build-module/mobile/color-settings/picker-screen.native.js +3 -1
  69. package/build-module/mobile/color-settings/picker-screen.native.js.map +1 -1
  70. package/build-module/mobile/image/index.native.js +3 -1
  71. package/build-module/mobile/image/index.native.js.map +1 -1
  72. package/build-module/mobile/keyboard-avoiding-view/index.ios.js +3 -1
  73. package/build-module/mobile/keyboard-avoiding-view/index.ios.js.map +1 -1
  74. package/build-module/mobile/link-picker/index.native.js +3 -1
  75. package/build-module/mobile/link-picker/index.native.js.map +1 -1
  76. package/build-module/mobile/link-picker/link-picker-results.native.js +3 -1
  77. package/build-module/mobile/link-picker/link-picker-results.native.js.map +1 -1
  78. package/build-module/mobile/link-picker/link-picker-screen.native.js +3 -1
  79. package/build-module/mobile/link-picker/link-picker-screen.native.js.map +1 -1
  80. package/build-module/mobile/link-settings/index.native.js +24 -6
  81. package/build-module/mobile/link-settings/index.native.js.map +1 -1
  82. package/build-module/mobile/link-settings/link-settings-screen.native.js +3 -1
  83. package/build-module/mobile/link-settings/link-settings-screen.native.js.map +1 -1
  84. package/build-module/mobile/segmented-control/index.native.js +6 -2
  85. package/build-module/mobile/segmented-control/index.native.js.map +1 -1
  86. package/build-module/mobile/utils/use-unit-converter-to-mobile.native.js +6 -2
  87. package/build-module/mobile/utils/use-unit-converter-to-mobile.native.js.map +1 -1
  88. package/build-module/notice/index.native.js +16 -21
  89. package/build-module/notice/index.native.js.map +1 -1
  90. package/build-module/notice/list.native.js +3 -3
  91. package/build-module/notice/list.native.js.map +1 -1
  92. package/build-module/palette-edit/index.js +1 -1
  93. package/build-module/palette-edit/index.js.map +1 -1
  94. package/build-module/popover/index.js +31 -35
  95. package/build-module/popover/index.js.map +1 -1
  96. package/build-module/popover/limit-shift.js +136 -0
  97. package/build-module/popover/limit-shift.js.map +1 -0
  98. package/build-module/popover/utils.js +55 -15
  99. package/build-module/popover/utils.js.map +1 -1
  100. package/build-module/tools-panel/styles.js +23 -12
  101. package/build-module/tools-panel/styles.js.map +1 -1
  102. package/build-module/tools-panel/tools-panel-header/component.js +19 -7
  103. package/build-module/tools-panel/tools-panel-header/component.js.map +1 -1
  104. package/build-module/tools-panel/tools-panel-header/hook.js +4 -0
  105. package/build-module/tools-panel/tools-panel-header/hook.js.map +1 -1
  106. package/build-style/style-rtl.css +13 -2
  107. package/build-style/style.css +13 -2
  108. package/build-types/draggable/index.d.ts.map +1 -1
  109. package/build-types/external-link/styles/external-link-styles.d.ts +1 -1
  110. package/build-types/focal-point-picker/styles/focal-point-style.d.ts +3 -3
  111. package/build-types/menu-item/index.d.ts.map +1 -1
  112. package/build-types/popover/index.d.ts.map +1 -1
  113. package/build-types/popover/limit-shift.d.ts +87 -0
  114. package/build-types/popover/limit-shift.d.ts.map +1 -0
  115. package/build-types/popover/test/index.d.ts +2 -0
  116. package/build-types/popover/test/index.d.ts.map +1 -0
  117. package/build-types/popover/types.d.ts +1 -1
  118. package/build-types/popover/types.d.ts.map +1 -1
  119. package/build-types/popover/utils.d.ts.map +1 -1
  120. package/build-types/range-control/types.d.ts +0 -32
  121. package/build-types/range-control/types.d.ts.map +1 -1
  122. package/build-types/spinner/index.d.ts +1 -1
  123. package/build-types/tools-panel/styles.d.ts +6 -0
  124. package/build-types/tools-panel/styles.d.ts.map +1 -1
  125. package/build-types/tools-panel/tools-panel-header/component.d.ts.map +1 -1
  126. package/build-types/tools-panel/tools-panel-header/hook.d.ts +1 -0
  127. package/build-types/tools-panel/tools-panel-header/hook.d.ts.map +1 -1
  128. package/build-types/tools-panel/types.d.ts +1 -0
  129. package/build-types/tools-panel/types.d.ts.map +1 -1
  130. package/package.json +17 -17
  131. package/src/draggable/index.js +2 -5
  132. package/src/index.js +1 -1
  133. package/src/menu-item/README.md +7 -0
  134. package/src/menu-item/index.js +11 -5
  135. package/src/menu-item/style.scss +1 -0
  136. package/src/menu-item/test/index.js +36 -0
  137. package/src/mobile/bottom-sheet/bottom-sheet-navigation/navigation-container.native.js +9 -0
  138. package/src/mobile/bottom-sheet/bottom-sheet-navigation/navigation-screen.native.js +11 -0
  139. package/src/mobile/bottom-sheet/sub-sheet/index.native.js +3 -0
  140. package/src/mobile/color-settings/index.native.js +3 -0
  141. package/src/mobile/color-settings/picker-screen.native.js +3 -0
  142. package/src/mobile/image/index.native.js +3 -0
  143. package/src/mobile/keyboard-avoiding-view/index.ios.js +3 -0
  144. package/src/mobile/link-picker/index.native.js +3 -0
  145. package/src/mobile/link-picker/link-picker-results.native.js +3 -0
  146. package/src/mobile/link-picker/link-picker-screen.native.js +3 -0
  147. package/src/mobile/link-settings/index.native.js +18 -0
  148. package/src/mobile/link-settings/link-settings-screen.native.js +3 -0
  149. package/src/mobile/segmented-control/index.native.js +6 -0
  150. package/src/mobile/utils/use-unit-converter-to-mobile.native.js +6 -0
  151. package/src/notice/index.native.js +17 -20
  152. package/src/notice/list.native.js +7 -3
  153. package/src/palette-edit/index.js +1 -1
  154. package/src/placeholder/style.scss +1 -1
  155. package/src/popover/index.tsx +26 -42
  156. package/src/popover/limit-shift.ts +205 -0
  157. package/src/popover/test/index.tsx +230 -0
  158. package/src/popover/types.ts +1 -0
  159. package/src/popover/utils.ts +58 -16
  160. package/src/range-control/types.ts +0 -33
  161. package/src/tools-panel/stories/index.js +27 -0
  162. package/src/tools-panel/styles.ts +28 -1
  163. package/src/tools-panel/tools-panel-header/component.tsx +12 -5
  164. package/src/tools-panel/tools-panel-header/hook.ts +5 -0
  165. package/src/tools-panel/types.ts +1 -0
  166. package/tsconfig.tsbuildinfo +1 -1
  167. package/src/popover/test/__snapshots__/index.js.snap +0 -34
  168. package/src/popover/test/index.js +0 -164
@@ -0,0 +1,136 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+
5
+ /**
6
+ * Parts of this source were derived and modified from `floating-ui`,
7
+ * released under the MIT license.
8
+ *
9
+ * https://github.com/floating-ui/floating-ui
10
+ *
11
+ * Copyright (c) 2021 Floating UI contributors
12
+ *
13
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ * of this software and associated documentation files (the "Software"), to deal
15
+ * in the Software without restriction, including without limitation the rights
16
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ * copies of the Software, and to permit persons to whom the Software is
18
+ * furnished to do so, subject to the following conditions:
19
+ *
20
+ * The above copyright notice and this permission notice shall be included in all
21
+ * copies or substantial portions of the Software.
22
+ *
23
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ * SOFTWARE.
30
+ */
31
+
32
+ /**
33
+ * Custom limiter function for the `shift` middleware.
34
+ * This function is mostly identical default `limitShift` from ``@floating-ui`;
35
+ * the only difference is that, when computing the min/max shift limits, it
36
+ * also takes into account the iframe offset that is added by the
37
+ * custom "frameOffset" middleware.
38
+ *
39
+ * All unexported types and functions are also from the `@floating-ui` library,
40
+ * and have been copied to this file for convenience.
41
+ */
42
+ function getSide(placement) {
43
+ return placement.split('-')[0];
44
+ }
45
+
46
+ function getMainAxisFromPlacement(placement) {
47
+ return ['top', 'bottom'].includes(getSide(placement)) ? 'x' : 'y';
48
+ }
49
+
50
+ function getCrossAxis(axis) {
51
+ return axis === 'x' ? 'y' : 'x';
52
+ }
53
+
54
+ export const limitShift = function () {
55
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
56
+ return {
57
+ options,
58
+
59
+ fn(middlewareArguments) {
60
+ var _middlewareData$frame;
61
+
62
+ const {
63
+ x,
64
+ y,
65
+ placement,
66
+ rects,
67
+ middlewareData
68
+ } = middlewareArguments;
69
+ const {
70
+ offset = 0,
71
+ mainAxis: checkMainAxis = true,
72
+ crossAxis: checkCrossAxis = true
73
+ } = options;
74
+ const coords = {
75
+ x,
76
+ y
77
+ };
78
+ const mainAxis = getMainAxisFromPlacement(placement);
79
+ const crossAxis = getCrossAxis(mainAxis);
80
+ let mainAxisCoord = coords[mainAxis];
81
+ let crossAxisCoord = coords[crossAxis];
82
+ const rawOffset = typeof offset === 'function' ? offset(middlewareArguments) : offset;
83
+ const computedOffset = typeof rawOffset === 'number' ? {
84
+ mainAxis: rawOffset,
85
+ crossAxis: 0
86
+ } : {
87
+ mainAxis: 0,
88
+ crossAxis: 0,
89
+ ...rawOffset
90
+ }; // At the moment of writing, this is the only difference
91
+ // with the `limitShift` function from `@floating-ui`.
92
+ // This offset needs to be added to all min/max limits
93
+ // in order to make the shift-limiting work as expected.
94
+
95
+ const additionalFrameOffset = {
96
+ x: 0,
97
+ y: 0,
98
+ ...((_middlewareData$frame = middlewareData.frameOffset) === null || _middlewareData$frame === void 0 ? void 0 : _middlewareData$frame.amount)
99
+ };
100
+
101
+ if (checkMainAxis) {
102
+ const len = mainAxis === 'y' ? 'height' : 'width';
103
+ const limitMin = rects.reference[mainAxis] - rects.floating[len] + computedOffset.mainAxis + additionalFrameOffset[mainAxis];
104
+ const limitMax = rects.reference[mainAxis] + rects.reference[len] - computedOffset.mainAxis + additionalFrameOffset[mainAxis];
105
+
106
+ if (mainAxisCoord < limitMin) {
107
+ mainAxisCoord = limitMin;
108
+ } else if (mainAxisCoord > limitMax) {
109
+ mainAxisCoord = limitMax;
110
+ }
111
+ }
112
+
113
+ if (checkCrossAxis) {
114
+ var _middlewareData$offse, _middlewareData$offse2, _middlewareData$offse3, _middlewareData$offse4;
115
+
116
+ const len = mainAxis === 'y' ? 'width' : 'height';
117
+ const isOriginSide = ['top', 'left'].includes(getSide(placement));
118
+ const limitMin = rects.reference[crossAxis] - rects.floating[len] + (isOriginSide ? (_middlewareData$offse = (_middlewareData$offse2 = middlewareData.offset) === null || _middlewareData$offse2 === void 0 ? void 0 : _middlewareData$offse2[crossAxis]) !== null && _middlewareData$offse !== void 0 ? _middlewareData$offse : 0 : 0) + (isOriginSide ? 0 : computedOffset.crossAxis) + additionalFrameOffset[crossAxis];
119
+ const limitMax = rects.reference[crossAxis] + rects.reference[len] + (isOriginSide ? 0 : (_middlewareData$offse3 = (_middlewareData$offse4 = middlewareData.offset) === null || _middlewareData$offse4 === void 0 ? void 0 : _middlewareData$offse4[crossAxis]) !== null && _middlewareData$offse3 !== void 0 ? _middlewareData$offse3 : 0) - (isOriginSide ? computedOffset.crossAxis : 0) + additionalFrameOffset[crossAxis];
120
+
121
+ if (crossAxisCoord < limitMin) {
122
+ crossAxisCoord = limitMin;
123
+ } else if (crossAxisCoord > limitMax) {
124
+ crossAxisCoord = limitMax;
125
+ }
126
+ }
127
+
128
+ return {
129
+ [mainAxis]: mainAxisCoord,
130
+ [crossAxis]: crossAxisCoord
131
+ };
132
+ }
133
+
134
+ };
135
+ };
136
+ //# sourceMappingURL=limit-shift.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/components/src/popover/limit-shift.ts"],"names":["getSide","placement","split","getMainAxisFromPlacement","includes","getCrossAxis","axis","limitShift","options","fn","middlewareArguments","x","y","rects","middlewareData","offset","mainAxis","checkMainAxis","crossAxis","checkCrossAxis","coords","mainAxisCoord","crossAxisCoord","rawOffset","computedOffset","additionalFrameOffset","frameOffset","amount","len","limitMin","reference","floating","limitMax","isOriginSide"],"mappings":"AAAA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;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AF,CADa,CAArB;AAGA,cAAM4B,QAAQ,GACbhB,KAAK,CAACiB,SAAN,CAAiBZ,SAAjB,IACAL,KAAK,CAACkB,QAAN,CAAgBH,GAAhB,CADA,IAEEK,YAAY,sDACXnB,cAAc,CAACC,MADJ,2DACX,uBAAyBG,SAAzB,CADW,yEAC6B,CAD7B,GAEX,CAJH,KAKEe,YAAY,GAAG,CAAH,GAAOT,cAAc,CAACN,SALpC,IAMAO,qBAAqB,CAAEP,SAAF,CAPtB;AAQA,cAAMc,QAAQ,GACbnB,KAAK,CAACiB,SAAN,CAAiBZ,SAAjB,IACAL,KAAK,CAACiB,SAAN,CAAiBF,GAAjB,CADA,IAEEK,YAAY,GACX,CADW,uDAEXnB,cAAc,CAACC,MAFJ,2DAEX,uBAAyBG,SAAzB,CAFW,2EAE6B,CAJ3C,KAKEe,YAAY,GAAGT,cAAc,CAACN,SAAlB,GAA8B,CAL5C,IAMAO,qBAAqB,CAAEP,SAAF,CAPtB;;AASA,YAAKI,cAAc,GAAGO,QAAtB,EAAiC;AAChCP,UAAAA,cAAc,GAAGO,QAAjB;AACA,SAFD,MAEO,IAAKP,cAAc,GAAGU,QAAtB,EAAiC;AACvCV,UAAAA,cAAc,GAAGU,QAAjB;AACA;AACD;;AAED,aAAO;AACN,SAAEhB,QAAF,GAAcK,aADR;AAEN,SAAEH,SAAF,GAAeI;AAFT,OAAP;AAIA;;AAzFK,GALmB;AAAA,CAAnB","sourcesContent":["/**\n * External dependencies\n */\nimport type {\n\tAxis,\n\tCoords,\n\tPlacement,\n\tSide,\n\tMiddlewareArguments,\n} from '@floating-ui/react-dom';\n\n/**\n * Parts of this source were derived and modified from `floating-ui`,\n * released under the MIT license.\n *\n * https://github.com/floating-ui/floating-ui\n *\n * Copyright (c) 2021 Floating UI contributors\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * Custom limiter function for the `shift` middleware.\n * This function is mostly identical default `limitShift` from ``@floating-ui`;\n * the only difference is that, when computing the min/max shift limits, it\n * also takes into account the iframe offset that is added by the\n * custom \"frameOffset\" middleware.\n *\n * All unexported types and functions are also from the `@floating-ui` library,\n * and have been copied to this file for convenience.\n */\n\ntype LimitShiftOffset =\n\t| ( ( args: MiddlewareArguments ) =>\n\t\t\t| number\n\t\t\t| {\n\t\t\t\t\t/**\n\t\t\t\t\t * Offset the limiting of the axis that runs along the alignment of the\n\t\t\t\t\t * floating element.\n\t\t\t\t\t */\n\t\t\t\t\tmainAxis?: number;\n\t\t\t\t\t/**\n\t\t\t\t\t * Offset the limiting of the axis that runs along the side of the\n\t\t\t\t\t * floating element.\n\t\t\t\t\t */\n\t\t\t\t\tcrossAxis?: number;\n\t\t\t } )\n\t| number\n\t| {\n\t\t\t/**\n\t\t\t * Offset the limiting of the axis that runs along the alignment of the\n\t\t\t * floating element.\n\t\t\t */\n\t\t\tmainAxis?: number;\n\t\t\t/**\n\t\t\t * Offset the limiting of the axis that runs along the side of the\n\t\t\t * floating element.\n\t\t\t */\n\t\t\tcrossAxis?: number;\n\t };\n\ntype LimitShiftOptions = {\n\t/**\n\t * Offset when limiting starts. `0` will limit when the opposite edges of the\n\t * reference and floating elements are aligned.\n\t * - positive = start limiting earlier\n\t * - negative = start limiting later\n\t */\n\toffset: LimitShiftOffset;\n\t/**\n\t * Whether to limit the axis that runs along the alignment of the floating\n\t * element.\n\t */\n\tmainAxis: boolean;\n\t/**\n\t * Whether to limit the axis that runs along the side of the floating element.\n\t */\n\tcrossAxis: boolean;\n};\n\nfunction getSide( placement: Placement ): Side {\n\treturn placement.split( '-' )[ 0 ] as Side;\n}\n\nfunction getMainAxisFromPlacement( placement: Placement ): Axis {\n\treturn [ 'top', 'bottom' ].includes( getSide( placement ) ) ? 'x' : 'y';\n}\n\nfunction getCrossAxis( axis: Axis ): Axis {\n\treturn axis === 'x' ? 'y' : 'x';\n}\n\nexport const limitShift = (\n\toptions: Partial< LimitShiftOptions > = {}\n): {\n\toptions: Partial< LimitShiftOffset >;\n\tfn: ( middlewareArguments: MiddlewareArguments ) => Coords;\n} => ( {\n\toptions,\n\tfn( middlewareArguments ) {\n\t\tconst { x, y, placement, rects, middlewareData } = middlewareArguments;\n\t\tconst {\n\t\t\toffset = 0,\n\t\t\tmainAxis: checkMainAxis = true,\n\t\t\tcrossAxis: checkCrossAxis = true,\n\t\t} = options;\n\n\t\tconst coords = { x, y };\n\t\tconst mainAxis = getMainAxisFromPlacement( placement );\n\t\tconst crossAxis = getCrossAxis( mainAxis );\n\n\t\tlet mainAxisCoord = coords[ mainAxis ];\n\t\tlet crossAxisCoord = coords[ crossAxis ];\n\n\t\tconst rawOffset =\n\t\t\ttypeof offset === 'function'\n\t\t\t\t? offset( middlewareArguments )\n\t\t\t\t: offset;\n\t\tconst computedOffset =\n\t\t\ttypeof rawOffset === 'number'\n\t\t\t\t? { mainAxis: rawOffset, crossAxis: 0 }\n\t\t\t\t: { mainAxis: 0, crossAxis: 0, ...rawOffset };\n\n\t\t// At the moment of writing, this is the only difference\n\t\t// with the `limitShift` function from `@floating-ui`.\n\t\t// This offset needs to be added to all min/max limits\n\t\t// in order to make the shift-limiting work as expected.\n\t\tconst additionalFrameOffset = {\n\t\t\tx: 0,\n\t\t\ty: 0,\n\t\t\t...middlewareData.frameOffset?.amount,\n\t\t};\n\n\t\tif ( checkMainAxis ) {\n\t\t\tconst len = mainAxis === 'y' ? 'height' : 'width';\n\t\t\tconst limitMin =\n\t\t\t\trects.reference[ mainAxis ] -\n\t\t\t\trects.floating[ len ] +\n\t\t\t\tcomputedOffset.mainAxis +\n\t\t\t\tadditionalFrameOffset[ mainAxis ];\n\t\t\tconst limitMax =\n\t\t\t\trects.reference[ mainAxis ] +\n\t\t\t\trects.reference[ len ] -\n\t\t\t\tcomputedOffset.mainAxis +\n\t\t\t\tadditionalFrameOffset[ mainAxis ];\n\n\t\t\tif ( mainAxisCoord < limitMin ) {\n\t\t\t\tmainAxisCoord = limitMin;\n\t\t\t} else if ( mainAxisCoord > limitMax ) {\n\t\t\t\tmainAxisCoord = limitMax;\n\t\t\t}\n\t\t}\n\n\t\tif ( checkCrossAxis ) {\n\t\t\tconst len = mainAxis === 'y' ? 'width' : 'height';\n\t\t\tconst isOriginSide = [ 'top', 'left' ].includes(\n\t\t\t\tgetSide( placement )\n\t\t\t);\n\t\t\tconst limitMin =\n\t\t\t\trects.reference[ crossAxis ] -\n\t\t\t\trects.floating[ len ] +\n\t\t\t\t( isOriginSide\n\t\t\t\t\t? middlewareData.offset?.[ crossAxis ] ?? 0\n\t\t\t\t\t: 0 ) +\n\t\t\t\t( isOriginSide ? 0 : computedOffset.crossAxis ) +\n\t\t\t\tadditionalFrameOffset[ crossAxis ];\n\t\t\tconst limitMax =\n\t\t\t\trects.reference[ crossAxis ] +\n\t\t\t\trects.reference[ len ] +\n\t\t\t\t( isOriginSide\n\t\t\t\t\t? 0\n\t\t\t\t\t: middlewareData.offset?.[ crossAxis ] ?? 0 ) -\n\t\t\t\t( isOriginSide ? computedOffset.crossAxis : 0 ) +\n\t\t\t\tadditionalFrameOffset[ crossAxis ];\n\n\t\t\tif ( crossAxisCoord < limitMin ) {\n\t\t\t\tcrossAxisCoord = limitMin;\n\t\t\t} else if ( crossAxisCoord > limitMax ) {\n\t\t\t\tcrossAxisCoord = limitMax;\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\t[ mainAxis ]: mainAxisCoord,\n\t\t\t[ crossAxis ]: crossAxisCoord,\n\t\t} as Coords;\n\t},\n} );\n"]}
@@ -6,7 +6,58 @@
6
6
  /**
7
7
  * Internal dependencies
8
8
  */
9
-
9
+ const POSITION_TO_PLACEMENT = {
10
+ bottom: 'bottom',
11
+ top: 'top',
12
+ 'middle left': 'left',
13
+ 'middle right': 'right',
14
+ 'bottom left': 'bottom-end',
15
+ 'bottom center': 'bottom',
16
+ 'bottom right': 'bottom-start',
17
+ 'top left': 'top-end',
18
+ 'top center': 'top',
19
+ 'top right': 'top-start',
20
+ 'middle left left': 'left',
21
+ 'middle left right': 'left',
22
+ 'middle left bottom': 'left-end',
23
+ 'middle left top': 'left-start',
24
+ 'middle right left': 'right',
25
+ 'middle right right': 'right',
26
+ 'middle right bottom': 'right-end',
27
+ 'middle right top': 'right-start',
28
+ 'bottom left left': 'bottom-end',
29
+ 'bottom left right': 'bottom-end',
30
+ 'bottom left bottom': 'bottom-end',
31
+ 'bottom left top': 'bottom-end',
32
+ 'bottom center left': 'bottom',
33
+ 'bottom center right': 'bottom',
34
+ 'bottom center bottom': 'bottom',
35
+ 'bottom center top': 'bottom',
36
+ 'bottom right left': 'bottom-start',
37
+ 'bottom right right': 'bottom-start',
38
+ 'bottom right bottom': 'bottom-start',
39
+ 'bottom right top': 'bottom-start',
40
+ 'top left left': 'top-end',
41
+ 'top left right': 'top-end',
42
+ 'top left bottom': 'top-end',
43
+ 'top left top': 'top-end',
44
+ 'top center left': 'top',
45
+ 'top center right': 'top',
46
+ 'top center bottom': 'top',
47
+ 'top center top': 'top',
48
+ 'top right left': 'top-start',
49
+ 'top right right': 'top-start',
50
+ 'top right bottom': 'top-start',
51
+ 'top right top': 'top-start',
52
+ // `middle`/`middle center [corner?]` positions are associated to a fallback
53
+ // `bottom` placement because there aren't any corresponding placement values.
54
+ middle: 'bottom',
55
+ 'middle center': 'bottom',
56
+ 'middle center bottom': 'bottom',
57
+ 'middle center left': 'bottom',
58
+ 'middle center right': 'bottom',
59
+ 'middle center top': 'bottom'
60
+ };
10
61
  /**
11
62
  * Converts the `Popover`'s legacy "position" prop to the new "placement" prop
12
63
  * (used by `floating-ui`).
@@ -14,22 +65,11 @@
14
65
  * @param position The legacy position
15
66
  * @return The corresponding placement
16
67
  */
17
- export const positionToPlacement = position => {
18
- const [x, y, z] = position.split(' ');
19
-
20
- if (['top', 'bottom'].includes(x)) {
21
- let suffix = '';
22
68
 
23
- if (!!z && z === 'left' || y === 'right') {
24
- suffix = '-start';
25
- } else if (!!z && z === 'right' || y === 'left') {
26
- suffix = '-end';
27
- }
28
-
29
- return x + suffix;
30
- }
69
+ export const positionToPlacement = position => {
70
+ var _POSITION_TO_PLACEMEN;
31
71
 
32
- return y;
72
+ return (_POSITION_TO_PLACEMEN = POSITION_TO_PLACEMENT[position]) !== null && _POSITION_TO_PLACEMEN !== void 0 ? _POSITION_TO_PLACEMEN : 'bottom';
33
73
  };
34
74
  /**
35
75
  * @typedef AnimationOrigin
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/components/src/popover/utils.ts"],"names":["positionToPlacement","position","x","y","z","split","includes","suffix","PLACEMENT_TO_ANIMATION_ORIGIN","top","originX","originY","right","bottom","left","placementToMotionAnimationProps","placement","translateProp","startsWith","translateDirection","style","initial","opacity","scale","animate","transition","duration","ease","getFrameOffset","document","frameElement","defaultView","iframeRect","getBoundingClientRect","getReferenceOwnerDocument","anchor","anchorRef","anchorRect","getAnchorRect","fallbackReferenceElement","fallbackDocument","resultingReferenceOwnerDoc","ownerDocument","startContainer","current","getReferenceElement","referenceElement","topRect","bottomRect","window","DOMRect","width","rect","height","parentElement"],"mappings":"AAA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ACA,8BAAOR,gBAAP,iEAA2B,IAA3B;AACA,CA1EM","sourcesContent":["/**\n * External dependencies\n */\n// eslint-disable-next-line no-restricted-imports\nimport type { MotionProps } from 'framer-motion';\nimport type { ReferenceType } from '@floating-ui/react-dom';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tPopoverProps,\n\tPopoverAnchorRefReference,\n\tPopoverAnchorRefTopBottom,\n} from './types';\n\n/**\n * Converts the `Popover`'s legacy \"position\" prop to the new \"placement\" prop\n * (used by `floating-ui`).\n *\n * @param position The legacy position\n * @return The corresponding placement\n */\nexport const positionToPlacement = (\n\tposition: NonNullable< PopoverProps[ 'position' ] >\n): NonNullable< PopoverProps[ 'placement' ] > => {\n\tconst [ x, y, z ] = position.split( ' ' );\n\n\tif ( [ 'top', 'bottom' ].includes( x ) ) {\n\t\tlet suffix = '';\n\t\tif ( ( !! z && z === 'left' ) || y === 'right' ) {\n\t\t\tsuffix = '-start';\n\t\t} else if ( ( !! z && z === 'right' ) || y === 'left' ) {\n\t\t\tsuffix = '-end';\n\t\t}\n\n\t\treturn ( x + suffix ) as NonNullable< PopoverProps[ 'placement' ] >;\n\t}\n\n\treturn y as NonNullable< PopoverProps[ 'placement' ] >;\n};\n\n/**\n * @typedef AnimationOrigin\n * @type {Object}\n * @property {number} originX A number between 0 and 1 (in CSS logical properties jargon, 0 is \"start\", 0.5 is \"center\", and 1 is \"end\")\n * @property {number} originY A number between 0 and 1 (0 is top, 0.5 is center, and 1 is bottom)\n */\n\nconst PLACEMENT_TO_ANIMATION_ORIGIN: Record<\n\tNonNullable< PopoverProps[ 'placement' ] >,\n\t{ originX: number; originY: number }\n> = {\n\ttop: { originX: 0.5, originY: 1 }, // open from bottom, center\n\t'top-start': { originX: 0, originY: 1 }, // open from bottom, left\n\t'top-end': { originX: 1, originY: 1 }, // open from bottom, right\n\tright: { originX: 0, originY: 0.5 }, // open from middle, left\n\t'right-start': { originX: 0, originY: 0 }, // open from top, left\n\t'right-end': { originX: 0, originY: 1 }, // open from bottom, left\n\tbottom: { originX: 0.5, originY: 0 }, // open from top, center\n\t'bottom-start': { originX: 0, originY: 0 }, // open from top, left\n\t'bottom-end': { originX: 1, originY: 0 }, // open from top, right\n\tleft: { originX: 1, originY: 0.5 }, // open from middle, right\n\t'left-start': { originX: 1, originY: 0 }, // open from top, right\n\t'left-end': { originX: 1, originY: 1 }, // open from bottom, right\n};\n\n/**\n * Given the floating-ui `placement`, compute the framer-motion props for the\n * popover's entry animation.\n *\n * @param placement A placement string from floating ui\n * @return The object containing the motion props\n */\nexport const placementToMotionAnimationProps = (\n\tplacement: NonNullable< PopoverProps[ 'placement' ] >\n): MotionProps => {\n\tconst translateProp =\n\t\tplacement.startsWith( 'top' ) || placement.startsWith( 'bottom' )\n\t\t\t? 'translateY'\n\t\t\t: 'translateX';\n\tconst translateDirection =\n\t\tplacement.startsWith( 'top' ) || placement.startsWith( 'left' )\n\t\t\t? 1\n\t\t\t: -1;\n\n\treturn {\n\t\tstyle: PLACEMENT_TO_ANIMATION_ORIGIN[ placement ],\n\t\tinitial: {\n\t\t\topacity: 0,\n\t\t\tscale: 0,\n\t\t\t[ translateProp ]: `${ 2 * translateDirection }em`,\n\t\t},\n\t\tanimate: { opacity: 1, scale: 1, [ translateProp ]: 0 },\n\t\ttransition: { duration: 0.1, ease: [ 0, 0, 0.2, 1 ] },\n\t};\n};\n\n/**\n * Returns the offset of a document's frame element.\n *\n * @param document The iframe's owner document.\n *\n * @return The offset of the document's frame element, or undefined if the\n * document has no frame element.\n */\nexport const getFrameOffset = (\n\tdocument?: Document\n): { x: number; y: number } | undefined => {\n\tconst frameElement = document?.defaultView?.frameElement;\n\tif ( ! frameElement ) {\n\t\treturn;\n\t}\n\tconst iframeRect = frameElement.getBoundingClientRect();\n\treturn { x: iframeRect.left, y: iframeRect.top };\n};\n\nexport const getReferenceOwnerDocument = ( {\n\tanchor,\n\tanchorRef,\n\tanchorRect,\n\tgetAnchorRect,\n\tfallbackReferenceElement,\n\tfallbackDocument,\n}: Pick<\n\tPopoverProps,\n\t'anchorRef' | 'anchorRect' | 'getAnchorRect' | 'anchor'\n> & {\n\tfallbackReferenceElement: Element | null;\n\tfallbackDocument: Document;\n} ): Document => {\n\t// In floating-ui's terms:\n\t// - \"reference\" refers to the popover's anchor element.\n\t// - \"floating\" refers the floating popover's element.\n\t// A floating element can also be positioned relative to a virtual element,\n\t// instead of a real one. A virtual element is represented by an object\n\t// with the `getBoundingClientRect()` function (like real elements).\n\t// See https://floating-ui.com/docs/virtual-elements for more info.\n\tlet resultingReferenceOwnerDoc;\n\tif ( anchor ) {\n\t\tresultingReferenceOwnerDoc = anchor.ownerDocument;\n\t} else if ( ( anchorRef as PopoverAnchorRefTopBottom | undefined )?.top ) {\n\t\tresultingReferenceOwnerDoc = ( anchorRef as PopoverAnchorRefTopBottom )\n\t\t\t?.top.ownerDocument;\n\t} else if ( ( anchorRef as Range | undefined )?.startContainer ) {\n\t\tresultingReferenceOwnerDoc = ( anchorRef as Range ).startContainer\n\t\t\t.ownerDocument;\n\t} else if (\n\t\t( anchorRef as PopoverAnchorRefReference | undefined )?.current\n\t) {\n\t\tresultingReferenceOwnerDoc = (\n\t\t\t( anchorRef as PopoverAnchorRefReference ).current as Element\n\t\t ).ownerDocument;\n\t} else if ( anchorRef as Element | undefined ) {\n\t\t// This one should be deprecated.\n\t\tresultingReferenceOwnerDoc = ( anchorRef as Element ).ownerDocument;\n\t} else if ( anchorRect && anchorRect?.ownerDocument ) {\n\t\tresultingReferenceOwnerDoc = anchorRect.ownerDocument;\n\t} else if ( getAnchorRect ) {\n\t\tresultingReferenceOwnerDoc = getAnchorRect(\n\t\t\tfallbackReferenceElement\n\t\t)?.ownerDocument;\n\t}\n\n\treturn resultingReferenceOwnerDoc ?? fallbackDocument;\n};\n\nexport const getReferenceElement = ( {\n\tanchor,\n\tanchorRef,\n\tanchorRect,\n\tgetAnchorRect,\n\tfallbackReferenceElement,\n}: Pick<\n\tPopoverProps,\n\t'anchorRef' | 'anchorRect' | 'getAnchorRect' | 'anchor'\n> & {\n\tfallbackReferenceElement: Element | null;\n} ): ReferenceType | null => {\n\tlet referenceElement = null;\n\n\tif ( anchor ) {\n\t\treferenceElement = anchor;\n\t} else if ( ( anchorRef as PopoverAnchorRefTopBottom | undefined )?.top ) {\n\t\t// Create a virtual element for the ref. The expectation is that\n\t\t// if anchorRef.top is defined, then anchorRef.bottom is defined too.\n\t\t// Seems to be used by the block toolbar, when multiple blocks are selected\n\t\t// (top and bottom blocks are used to calculate the resulting rect).\n\t\treferenceElement = {\n\t\t\tgetBoundingClientRect() {\n\t\t\t\tconst topRect = (\n\t\t\t\t\tanchorRef as PopoverAnchorRefTopBottom\n\t\t\t\t ).top.getBoundingClientRect();\n\t\t\t\tconst bottomRect = (\n\t\t\t\t\tanchorRef as PopoverAnchorRefTopBottom\n\t\t\t\t ).bottom.getBoundingClientRect();\n\t\t\t\treturn new window.DOMRect(\n\t\t\t\t\ttopRect.x,\n\t\t\t\t\ttopRect.y,\n\t\t\t\t\ttopRect.width,\n\t\t\t\t\tbottomRect.bottom - topRect.top\n\t\t\t\t);\n\t\t\t},\n\t\t};\n\t} else if (\n\t\t( anchorRef as PopoverAnchorRefReference | undefined )?.current\n\t) {\n\t\t// Standard React ref.\n\t\treferenceElement = ( anchorRef as PopoverAnchorRefReference ).current;\n\t} else if ( anchorRef as Element | undefined ) {\n\t\t// If `anchorRef` holds directly the element's value (no `current` key)\n\t\t// This is a weird scenario and should be deprecated.\n\t\treferenceElement = anchorRef as Element;\n\t} else if ( anchorRect ) {\n\t\t// Create a virtual element for the ref.\n\t\treferenceElement = {\n\t\t\tgetBoundingClientRect() {\n\t\t\t\treturn anchorRect;\n\t\t\t},\n\t\t};\n\t} else if ( getAnchorRect ) {\n\t\t// Create a virtual element for the ref.\n\t\treferenceElement = {\n\t\t\tgetBoundingClientRect() {\n\t\t\t\tconst rect = getAnchorRect( fallbackReferenceElement );\n\t\t\t\treturn new window.DOMRect(\n\t\t\t\t\trect.x ?? rect.left,\n\t\t\t\t\trect.y ?? rect.top,\n\t\t\t\t\trect.width ?? rect.right - rect.left,\n\t\t\t\t\trect.height ?? rect.bottom - rect.top\n\t\t\t\t);\n\t\t\t},\n\t\t};\n\t} else if ( fallbackReferenceElement ) {\n\t\t// If no explicit ref is passed via props, fall back to\n\t\t// anchoring to the popover's parent node.\n\t\treferenceElement = fallbackReferenceElement.parentElement;\n\t}\n\n\t// Convert any `undefined` value to `null`.\n\treturn referenceElement ?? null;\n};\n"]}
1
+ {"version":3,"sources":["@wordpress/components/src/popover/utils.ts"],"names":["POSITION_TO_PLACEMENT","bottom","top","middle","positionToPlacement","position","PLACEMENT_TO_ANIMATION_ORIGIN","originX","originY","right","left","placementToMotionAnimationProps","placement","translateProp","startsWith","translateDirection","style","initial","opacity","scale","animate","transition","duration","ease","getFrameOffset","document","frameElement","defaultView","iframeRect","getBoundingClientRect","x","y","getReferenceOwnerDocument","anchor","anchorRef","anchorRect","getAnchorRect","fallbackReferenceElement","fallbackDocument","resultingReferenceOwnerDoc","ownerDocument","startContainer","current","getReferenceElement","referenceElement","topRect","bottomRect","window","DOMRect","width","rect","height","parentElement"],"mappings":"AAAA;AACA;AACA;AACA;;AAIA;AACA;AACA;AAOA,MAAMA,qBAGL,GAAG;AACHC,EAAAA,MAAM,EAAE,QADL;AAEHC,EAAAA,GAAG,EAAE,KAFF;AAGH,iBAAe,MAHZ;AAIH,kBAAgB,OAJb;AAKH,iBAAe,YALZ;AAMH,mBAAiB,QANd;AAOH,kBAAgB,cAPb;AAQH,cAAY,SART;AASH,gBAAc,KATX;AAUH,eAAa,WAVV;AAWH,sBAAoB,MAXjB;AAYH,uBAAqB,MAZlB;AAaH,wBAAsB,UAbnB;AAcH,qBAAmB,YAdhB;AAeH,uBAAqB,OAflB;AAgBH,wBAAsB,OAhBnB;AAiBH,yBAAuB,WAjBpB;AAkBH,sBAAoB,aAlBjB;AAmBH,sBAAoB,YAnBjB;AAoBH,uBAAqB,YApBlB;AA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,GAJ5B,CAAP;AAMA;;AATiB,KAAnB;AAWA,GAbM,MAaA,IAAKmC,wBAAL,EAAgC;AACtC;AACA;AACAO,IAAAA,gBAAgB,GAAGP,wBAAwB,CAACe,aAA5C;AACA,GA3D2B,CA6D5B;;;AACA,8BAAOR,gBAAP,iEAA2B,IAA3B;AACA,CA1EM","sourcesContent":["/**\n * External dependencies\n */\n// eslint-disable-next-line no-restricted-imports\nimport type { MotionProps } from 'framer-motion';\nimport type { ReferenceType } from '@floating-ui/react-dom';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tPopoverProps,\n\tPopoverAnchorRefReference,\n\tPopoverAnchorRefTopBottom,\n} from './types';\n\nconst POSITION_TO_PLACEMENT: Record<\n\tNonNullable< PopoverProps[ 'position' ] >,\n\tNonNullable< PopoverProps[ 'placement' ] >\n> = {\n\tbottom: 'bottom',\n\ttop: 'top',\n\t'middle left': 'left',\n\t'middle right': 'right',\n\t'bottom left': 'bottom-end',\n\t'bottom center': 'bottom',\n\t'bottom right': 'bottom-start',\n\t'top left': 'top-end',\n\t'top center': 'top',\n\t'top right': 'top-start',\n\t'middle left left': 'left',\n\t'middle left right': 'left',\n\t'middle left bottom': 'left-end',\n\t'middle left top': 'left-start',\n\t'middle right left': 'right',\n\t'middle right right': 'right',\n\t'middle right bottom': 'right-end',\n\t'middle right top': 'right-start',\n\t'bottom left left': 'bottom-end',\n\t'bottom left right': 'bottom-end',\n\t'bottom left bottom': 'bottom-end',\n\t'bottom left top': 'bottom-end',\n\t'bottom center left': 'bottom',\n\t'bottom center right': 'bottom',\n\t'bottom center bottom': 'bottom',\n\t'bottom center top': 'bottom',\n\t'bottom right left': 'bottom-start',\n\t'bottom right right': 'bottom-start',\n\t'bottom right bottom': 'bottom-start',\n\t'bottom right top': 'bottom-start',\n\t'top left left': 'top-end',\n\t'top left right': 'top-end',\n\t'top left bottom': 'top-end',\n\t'top left top': 'top-end',\n\t'top center left': 'top',\n\t'top center right': 'top',\n\t'top center bottom': 'top',\n\t'top center top': 'top',\n\t'top right left': 'top-start',\n\t'top right right': 'top-start',\n\t'top right bottom': 'top-start',\n\t'top right top': 'top-start',\n\t// `middle`/`middle center [corner?]` positions are associated to a fallback\n\t// `bottom` placement because there aren't any corresponding placement values.\n\tmiddle: 'bottom',\n\t'middle center': 'bottom',\n\t'middle center bottom': 'bottom',\n\t'middle center left': 'bottom',\n\t'middle center right': 'bottom',\n\t'middle center top': 'bottom',\n};\n\n/**\n * Converts the `Popover`'s legacy \"position\" prop to the new \"placement\" prop\n * (used by `floating-ui`).\n *\n * @param position The legacy position\n * @return The corresponding placement\n */\nexport const positionToPlacement = (\n\tposition: NonNullable< PopoverProps[ 'position' ] >\n): NonNullable< PopoverProps[ 'placement' ] > =>\n\tPOSITION_TO_PLACEMENT[ position ] ?? 'bottom';\n\n/**\n * @typedef AnimationOrigin\n * @type {Object}\n * @property {number} originX A number between 0 and 1 (in CSS logical properties jargon, 0 is \"start\", 0.5 is \"center\", and 1 is \"end\")\n * @property {number} originY A number between 0 and 1 (0 is top, 0.5 is center, and 1 is bottom)\n */\n\nconst PLACEMENT_TO_ANIMATION_ORIGIN: Record<\n\tNonNullable< PopoverProps[ 'placement' ] >,\n\t{ originX: number; originY: number }\n> = {\n\ttop: { originX: 0.5, originY: 1 }, // open from bottom, center\n\t'top-start': { originX: 0, originY: 1 }, // open from bottom, left\n\t'top-end': { originX: 1, originY: 1 }, // open from bottom, right\n\tright: { originX: 0, originY: 0.5 }, // open from middle, left\n\t'right-start': { originX: 0, originY: 0 }, // open from top, left\n\t'right-end': { originX: 0, originY: 1 }, // open from bottom, left\n\tbottom: { originX: 0.5, originY: 0 }, // open from top, center\n\t'bottom-start': { originX: 0, originY: 0 }, // open from top, left\n\t'bottom-end': { originX: 1, originY: 0 }, // open from top, right\n\tleft: { originX: 1, originY: 0.5 }, // open from middle, right\n\t'left-start': { originX: 1, originY: 0 }, // open from top, right\n\t'left-end': { originX: 1, originY: 1 }, // open from bottom, right\n};\n\n/**\n * Given the floating-ui `placement`, compute the framer-motion props for the\n * popover's entry animation.\n *\n * @param placement A placement string from floating ui\n * @return The object containing the motion props\n */\nexport const placementToMotionAnimationProps = (\n\tplacement: NonNullable< PopoverProps[ 'placement' ] >\n): MotionProps => {\n\tconst translateProp =\n\t\tplacement.startsWith( 'top' ) || placement.startsWith( 'bottom' )\n\t\t\t? 'translateY'\n\t\t\t: 'translateX';\n\tconst translateDirection =\n\t\tplacement.startsWith( 'top' ) || placement.startsWith( 'left' )\n\t\t\t? 1\n\t\t\t: -1;\n\n\treturn {\n\t\tstyle: PLACEMENT_TO_ANIMATION_ORIGIN[ placement ],\n\t\tinitial: {\n\t\t\topacity: 0,\n\t\t\tscale: 0,\n\t\t\t[ translateProp ]: `${ 2 * translateDirection }em`,\n\t\t},\n\t\tanimate: { opacity: 1, scale: 1, [ translateProp ]: 0 },\n\t\ttransition: { duration: 0.1, ease: [ 0, 0, 0.2, 1 ] },\n\t};\n};\n\n/**\n * Returns the offset of a document's frame element.\n *\n * @param document The iframe's owner document.\n *\n * @return The offset of the document's frame element, or undefined if the\n * document has no frame element.\n */\nexport const getFrameOffset = (\n\tdocument?: Document\n): { x: number; y: number } | undefined => {\n\tconst frameElement = document?.defaultView?.frameElement;\n\tif ( ! frameElement ) {\n\t\treturn;\n\t}\n\tconst iframeRect = frameElement.getBoundingClientRect();\n\treturn { x: iframeRect.left, y: iframeRect.top };\n};\n\nexport const getReferenceOwnerDocument = ( {\n\tanchor,\n\tanchorRef,\n\tanchorRect,\n\tgetAnchorRect,\n\tfallbackReferenceElement,\n\tfallbackDocument,\n}: Pick<\n\tPopoverProps,\n\t'anchorRef' | 'anchorRect' | 'getAnchorRect' | 'anchor'\n> & {\n\tfallbackReferenceElement: Element | null;\n\tfallbackDocument: Document;\n} ): Document => {\n\t// In floating-ui's terms:\n\t// - \"reference\" refers to the popover's anchor element.\n\t// - \"floating\" refers the floating popover's element.\n\t// A floating element can also be positioned relative to a virtual element,\n\t// instead of a real one. A virtual element is represented by an object\n\t// with the `getBoundingClientRect()` function (like real elements).\n\t// See https://floating-ui.com/docs/virtual-elements for more info.\n\tlet resultingReferenceOwnerDoc;\n\tif ( anchor ) {\n\t\tresultingReferenceOwnerDoc = anchor.ownerDocument;\n\t} else if ( ( anchorRef as PopoverAnchorRefTopBottom | undefined )?.top ) {\n\t\tresultingReferenceOwnerDoc = ( anchorRef as PopoverAnchorRefTopBottom )\n\t\t\t?.top.ownerDocument;\n\t} else if ( ( anchorRef as Range | undefined )?.startContainer ) {\n\t\tresultingReferenceOwnerDoc = ( anchorRef as Range ).startContainer\n\t\t\t.ownerDocument;\n\t} else if (\n\t\t( anchorRef as PopoverAnchorRefReference | undefined )?.current\n\t) {\n\t\tresultingReferenceOwnerDoc = (\n\t\t\t( anchorRef as PopoverAnchorRefReference ).current as Element\n\t\t ).ownerDocument;\n\t} else if ( anchorRef as Element | undefined ) {\n\t\t// This one should be deprecated.\n\t\tresultingReferenceOwnerDoc = ( anchorRef as Element ).ownerDocument;\n\t} else if ( anchorRect && anchorRect?.ownerDocument ) {\n\t\tresultingReferenceOwnerDoc = anchorRect.ownerDocument;\n\t} else if ( getAnchorRect ) {\n\t\tresultingReferenceOwnerDoc = getAnchorRect(\n\t\t\tfallbackReferenceElement\n\t\t)?.ownerDocument;\n\t}\n\n\treturn resultingReferenceOwnerDoc ?? fallbackDocument;\n};\n\nexport const getReferenceElement = ( {\n\tanchor,\n\tanchorRef,\n\tanchorRect,\n\tgetAnchorRect,\n\tfallbackReferenceElement,\n}: Pick<\n\tPopoverProps,\n\t'anchorRef' | 'anchorRect' | 'getAnchorRect' | 'anchor'\n> & {\n\tfallbackReferenceElement: Element | null;\n} ): ReferenceType | null => {\n\tlet referenceElement = null;\n\n\tif ( anchor ) {\n\t\treferenceElement = anchor;\n\t} else if ( ( anchorRef as PopoverAnchorRefTopBottom | undefined )?.top ) {\n\t\t// Create a virtual element for the ref. The expectation is that\n\t\t// if anchorRef.top is defined, then anchorRef.bottom is defined too.\n\t\t// Seems to be used by the block toolbar, when multiple blocks are selected\n\t\t// (top and bottom blocks are used to calculate the resulting rect).\n\t\treferenceElement = {\n\t\t\tgetBoundingClientRect() {\n\t\t\t\tconst topRect = (\n\t\t\t\t\tanchorRef as PopoverAnchorRefTopBottom\n\t\t\t\t ).top.getBoundingClientRect();\n\t\t\t\tconst bottomRect = (\n\t\t\t\t\tanchorRef as PopoverAnchorRefTopBottom\n\t\t\t\t ).bottom.getBoundingClientRect();\n\t\t\t\treturn new window.DOMRect(\n\t\t\t\t\ttopRect.x,\n\t\t\t\t\ttopRect.y,\n\t\t\t\t\ttopRect.width,\n\t\t\t\t\tbottomRect.bottom - topRect.top\n\t\t\t\t);\n\t\t\t},\n\t\t};\n\t} else if (\n\t\t( anchorRef as PopoverAnchorRefReference | undefined )?.current\n\t) {\n\t\t// Standard React ref.\n\t\treferenceElement = ( anchorRef as PopoverAnchorRefReference ).current;\n\t} else if ( anchorRef as Element | undefined ) {\n\t\t// If `anchorRef` holds directly the element's value (no `current` key)\n\t\t// This is a weird scenario and should be deprecated.\n\t\treferenceElement = anchorRef as Element;\n\t} else if ( anchorRect ) {\n\t\t// Create a virtual element for the ref.\n\t\treferenceElement = {\n\t\t\tgetBoundingClientRect() {\n\t\t\t\treturn anchorRect;\n\t\t\t},\n\t\t};\n\t} else if ( getAnchorRect ) {\n\t\t// Create a virtual element for the ref.\n\t\treferenceElement = {\n\t\t\tgetBoundingClientRect() {\n\t\t\t\tconst rect = getAnchorRect( fallbackReferenceElement );\n\t\t\t\treturn new window.DOMRect(\n\t\t\t\t\trect.x ?? rect.left,\n\t\t\t\t\trect.y ?? rect.top,\n\t\t\t\t\trect.width ?? rect.right - rect.left,\n\t\t\t\t\trect.height ?? rect.bottom - rect.top\n\t\t\t\t);\n\t\t\t},\n\t\t};\n\t} else if ( fallbackReferenceElement ) {\n\t\t// If no explicit ref is passed via props, fall back to\n\t\t// anchoring to the popover's parent node.\n\t\treferenceElement = fallbackReferenceElement.parentElement;\n\t}\n\n\t// Convert any `undefined` value to `null`.\n\treturn referenceElement ?? null;\n};\n"]}