@fluentui/react-positioning 9.75.0-experimental.css-modules.20261031-810ab07afb.0 → 9.75.1-experimental.positioning-engine.20261103-19efe125d1.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 (111) hide show
  1. package/CHANGELOG.md +7 -7
  2. package/README.md +130 -7
  3. package/lib/PositioningConfigurationContext.js +1 -2
  4. package/lib/PositioningConfigurationContext.js.map +1 -1
  5. package/lib/createPositionManager.js +74 -82
  6. package/lib/createPositionManager.js.map +1 -1
  7. package/lib/engine/computePosition.js +258 -0
  8. package/lib/engine/computePosition.js.map +1 -0
  9. package/lib/engine/index.js +260 -0
  10. package/lib/engine/index.js.map +1 -0
  11. package/lib/engine/platform.js +209 -0
  12. package/lib/engine/platform.js.map +1 -0
  13. package/lib/middleware/flip.js +1 -1
  14. package/lib/middleware/flip.js.map +1 -1
  15. package/lib/middleware/intersecting.js +1 -1
  16. package/lib/middleware/intersecting.js.map +1 -1
  17. package/lib/middleware/maxSize.js +1 -1
  18. package/lib/middleware/maxSize.js.map +1 -1
  19. package/lib/middleware/offset.js +1 -1
  20. package/lib/middleware/offset.js.map +1 -1
  21. package/lib/middleware/shift.js +1 -1
  22. package/lib/middleware/shift.js.map +1 -1
  23. package/lib/usePositioning.js +38 -48
  24. package/lib/usePositioning.js.map +1 -1
  25. package/lib/usePositioning.raster.js +45 -0
  26. package/lib/usePositioning.raster.js.map +1 -0
  27. package/lib/usePositioningOptions.js +25 -117
  28. package/lib/usePositioningOptions.js.map +1 -1
  29. package/lib/utils/createResizeObserver.js +2 -2
  30. package/lib/utils/createResizeObserver.js.map +1 -1
  31. package/lib/utils/debounce.js +6 -13
  32. package/lib/utils/debounce.js.map +1 -1
  33. package/lib/utils/fromFloatingUIPlacement.js +10 -29
  34. package/lib/utils/fromFloatingUIPlacement.js.map +1 -1
  35. package/lib/utils/getBoundary.js +8 -17
  36. package/lib/utils/getBoundary.js.map +1 -1
  37. package/lib/utils/index.js +0 -2
  38. package/lib/utils/index.js.map +1 -1
  39. package/lib/utils/listScrollParents.js +12 -20
  40. package/lib/utils/listScrollParents.js.map +1 -1
  41. package/lib/utils/normalizeAutoSize.js +15 -22
  42. package/lib/utils/normalizeAutoSize.js.map +1 -1
  43. package/lib/utils/toFloatingUIPlacement.js +9 -26
  44. package/lib/utils/toFloatingUIPlacement.js.map +1 -1
  45. package/lib/utils/useCallbackRef.js +1 -10
  46. package/lib/utils/useCallbackRef.js.map +1 -1
  47. package/lib-commonjs/PositioningConfigurationContext.cjs +1 -2
  48. package/lib-commonjs/PositioningConfigurationContext.cjs.map +1 -1
  49. package/lib-commonjs/createPositionManager.cjs +72 -80
  50. package/lib-commonjs/createPositionManager.cjs.map +1 -1
  51. package/lib-commonjs/engine/computePosition.cjs +265 -0
  52. package/lib-commonjs/engine/computePosition.cjs.map +1 -0
  53. package/lib-commonjs/engine/index.cjs +290 -0
  54. package/lib-commonjs/engine/index.cjs.map +1 -0
  55. package/lib-commonjs/engine/platform.cjs +264 -0
  56. package/lib-commonjs/engine/platform.cjs.map +1 -0
  57. package/lib-commonjs/middleware/flip.cjs +6 -6
  58. package/lib-commonjs/middleware/flip.cjs.map +1 -1
  59. package/lib-commonjs/middleware/intersecting.cjs +2 -2
  60. package/lib-commonjs/middleware/intersecting.cjs.map +1 -1
  61. package/lib-commonjs/middleware/maxSize.cjs +4 -4
  62. package/lib-commonjs/middleware/maxSize.cjs.map +1 -1
  63. package/lib-commonjs/middleware/offset.cjs +2 -2
  64. package/lib-commonjs/middleware/offset.cjs.map +1 -1
  65. package/lib-commonjs/middleware/shift.cjs +7 -7
  66. package/lib-commonjs/middleware/shift.cjs.map +1 -1
  67. package/lib-commonjs/usePositioning.cjs +37 -46
  68. package/lib-commonjs/usePositioning.cjs.map +1 -1
  69. package/lib-commonjs/usePositioning.raster.cjs +49 -0
  70. package/lib-commonjs/usePositioning.raster.cjs.map +1 -0
  71. package/lib-commonjs/usePositioningOptions.cjs +24 -112
  72. package/lib-commonjs/usePositioningOptions.cjs.map +1 -1
  73. package/lib-commonjs/utils/createResizeObserver.cjs +2 -2
  74. package/lib-commonjs/utils/createResizeObserver.cjs.map +1 -1
  75. package/lib-commonjs/utils/debounce.cjs +6 -13
  76. package/lib-commonjs/utils/debounce.cjs.map +1 -1
  77. package/lib-commonjs/utils/fromFloatingUIPlacement.cjs +21 -32
  78. package/lib-commonjs/utils/fromFloatingUIPlacement.cjs.map +1 -1
  79. package/lib-commonjs/utils/getBoundary.cjs +8 -17
  80. package/lib-commonjs/utils/getBoundary.cjs.map +1 -1
  81. package/lib-commonjs/utils/index.cjs +0 -8
  82. package/lib-commonjs/utils/index.cjs.map +1 -1
  83. package/lib-commonjs/utils/listScrollParents.cjs +12 -20
  84. package/lib-commonjs/utils/listScrollParents.cjs.map +1 -1
  85. package/lib-commonjs/utils/normalizeAutoSize.cjs +26 -25
  86. package/lib-commonjs/utils/normalizeAutoSize.cjs.map +1 -1
  87. package/lib-commonjs/utils/toFloatingUIPlacement.cjs +13 -27
  88. package/lib-commonjs/utils/toFloatingUIPlacement.cjs.map +1 -1
  89. package/lib-commonjs/utils/useCallbackRef.cjs +1 -9
  90. package/lib-commonjs/utils/useCallbackRef.cjs.map +1 -1
  91. package/package.json +5 -9
  92. package/lib/Arrow.module.css +0 -45
  93. package/lib/hooks/useSafeZoneArea/SafeZoneArea.module.css +0 -28
  94. package/lib/hooks/useSafeZoneArea/SafeZoneArea.styles.css.js +0 -9
  95. package/lib/hooks/useSafeZoneArea/SafeZoneArea.styles.css.js.map +0 -1
  96. package/lib/hooks/useSafeZoneArea/SafeZoneArea.styles.raw.css.js +0 -9
  97. package/lib/hooks/useSafeZoneArea/SafeZoneArea.styles.raw.css.js.map +0 -1
  98. package/lib/utils/writeArrowUpdates.js +0 -13
  99. package/lib/utils/writeArrowUpdates.js.map +0 -1
  100. package/lib/utils/writeContainerupdates.js +0 -43
  101. package/lib/utils/writeContainerupdates.js.map +0 -1
  102. package/lib-commonjs/Arrow.module.css +0 -45
  103. package/lib-commonjs/hooks/useSafeZoneArea/SafeZoneArea.module.css +0 -28
  104. package/lib-commonjs/hooks/useSafeZoneArea/SafeZoneArea.styles.css.cjs +0 -20
  105. package/lib-commonjs/hooks/useSafeZoneArea/SafeZoneArea.styles.css.cjs.map +0 -1
  106. package/lib-commonjs/hooks/useSafeZoneArea/SafeZoneArea.styles.raw.css.cjs +0 -20
  107. package/lib-commonjs/hooks/useSafeZoneArea/SafeZoneArea.styles.raw.css.cjs.map +0 -1
  108. package/lib-commonjs/utils/writeArrowUpdates.cjs +0 -23
  109. package/lib-commonjs/utils/writeArrowUpdates.cjs.map +0 -1
  110. package/lib-commonjs/utils/writeContainerupdates.cjs +0 -51
  111. package/lib-commonjs/utils/writeContainerupdates.cjs.map +0 -1
@@ -0,0 +1,209 @@
1
+ import { isHTMLElement } from "@fluentui/react-utilities";
2
+ // Expression-bodied helpers and plain property access keep the ES2019 output compact.
3
+ export const getWindow = (node)=>node.ownerDocument.defaultView;
4
+ export const getRoot = (node)=>node.ownerDocument.documentElement;
5
+ export const getStyle = (element)=>getWindow(element).getComputedStyle(element);
6
+ /** A CSS pixel value, an empty string removes the inline style */ export const px = (value)=>value === undefined ? '' : `${value}px`;
7
+ // Properties that are not supported are empty strings (i.e. in jsdom)
8
+ const isSet = (value)=>!!value && value !== 'none';
9
+ /** Uses `CSS.supports()` of the element's window, which is unavailable in some environments (e.g. jsdom) */ const isWebKit = (element)=>{
10
+ const css = getWindow(element).CSS;
11
+ return !!css && !!css.supports && css.supports('-webkit-backdrop-filter', 'none');
12
+ };
13
+ /** Shared and never mutated */ export const NO_OFFSET = {
14
+ x: 0,
15
+ y: 0
16
+ };
17
+ const getVisualOffsets = (element)=>{
18
+ const viewport = getWindow(element).visualViewport;
19
+ return isWebKit(element) && viewport ? {
20
+ x: viewport.offsetLeft,
21
+ y: viewport.offsetTop
22
+ } : NO_OFFSET;
23
+ };
24
+ const getBounds = (target)=>target.getBoundingClientRect();
25
+ export const rect = (x, y, width, height)=>({
26
+ x,
27
+ y,
28
+ width,
29
+ height
30
+ });
31
+ export const intersect = (a, b)=>{
32
+ const x = Math.max(a.x, b.x);
33
+ const y = Math.max(a.y, b.y);
34
+ return rect(x, y, Math.min(a.x + a.width, b.x + b.width) - x, Math.min(a.y + a.height, b.y + b.height) - y);
35
+ };
36
+ export const isContainingBlock = (element, style, strategy)=>// Boxless elements can't form containing blocks, and WebKit ignores filters
37
+ style.display !== 'contents' && (strategy === 'absolute' && !/^(static)?$/.test(style.position) || 'transform translate scale rotate perspective'.split(' ').some((property)=>isSet(style[property])) || (isSet(style.filter) || isSet(style.backdropFilter)) && !isWebKit(element) || /auto|hidden/.test(style.contentVisibility) || !!style.containerType && style.containerType !== 'normal' || /transform|perspective|filter/.test(style.willChange) || /paint|layout|strict|content/.test(style.contain));
38
+ /** The parent element, through slot assignments and shadow roots but not virtual parents */ export const getPhysicalParent = (element)=>{
39
+ if (isTopLayer(element)) {
40
+ return null;
41
+ }
42
+ let parent = element.assignedSlot || element.parentNode;
43
+ if (parent && parent.nodeType === 11) {
44
+ parent = parent.host;
45
+ }
46
+ return parent && parent.nodeType === 1 ? parent : null;
47
+ };
48
+ /** Open popovers and modal dialogs escape the clipping and containing blocks of their ancestors */ const isTopLayer = (element)=>{
49
+ try {
50
+ // A single forgiving `:is()` match per ancestor: unsupported pseudo-classes never match, and environments
51
+ // without `:is()` (e.g. jsdom) throw
52
+ return element.matches(':is(:popover-open, :modal)');
53
+ } catch {
54
+ return false;
55
+ }
56
+ };
57
+ /**
58
+ * Walks the physical ancestors (including SVG elements) of an element up to (excluding) the root element,
59
+ * stops when the callback returns true and returns that ancestor.
60
+ */ export const findAncestor = (element, callback)=>{
61
+ const root = getRoot(element);
62
+ for(let node = getPhysicalParent(element); node && node !== root; node = getPhysicalParent(node)){
63
+ if (callback(node, getStyle(node))) {
64
+ return node;
65
+ }
66
+ }
67
+ return null;
68
+ };
69
+ /** The ancestors that can clip the element, the closest first */ export const getScrollAncestors = (element)=>{
70
+ const ancestors = [];
71
+ const isPositioned = (position)=>position === 'fixed' || position === 'absolute';
72
+ const { position } = getStyle(element);
73
+ let strategy = isPositioned(position) ? position : '';
74
+ findAncestor(element, (node, style)=>{
75
+ // Positioned descendants escape overflow between themselves and their containing block.
76
+ if (strategy && isContainingBlock(node, style, strategy)) {
77
+ strategy = '';
78
+ }
79
+ // The overflow of the body propagates to the viewport, which is always part of the clipping rect
80
+ if (!strategy && node !== element.ownerDocument.body && isHTMLElement(node) && !/^(inline|contents)$/.test(style.display) && /auto|scroll|overlay|hidden|clip/.test(style.overflow + style.overflowX + style.overflowY)) {
81
+ ancestors.push(node);
82
+ }
83
+ if (!strategy && isPositioned(style.position)) {
84
+ strategy = style.position;
85
+ }
86
+ });
87
+ return ancestors;
88
+ };
89
+ /** CSS dimensions, or the rounded layout dimensions when they differ after rounding */ export const getDimensions = (element)=>{
90
+ const css = getStyle(element);
91
+ const width = parseFloat(css.width) || 0;
92
+ const height = parseFloat(css.height) || 0;
93
+ const rounded = isHTMLElement(element) && (Math.round(width) !== element.offsetWidth || Math.round(height) !== element.offsetHeight);
94
+ return {
95
+ width: rounded ? element.offsetWidth : width,
96
+ height: rounded ? element.offsetHeight : height,
97
+ rounded
98
+ };
99
+ };
100
+ export const getScale = (element)=>{
101
+ const bounds = getBounds(element);
102
+ const { width, height, rounded } = getDimensions(element);
103
+ // Zero, infinite and NaN scales (e.g. of hidden elements) fall back to 1
104
+ const finite = (value)=>value && Number.isFinite(value) ? value : 1;
105
+ return {
106
+ x: finite((rounded ? Math.round(bounds.width) : bounds.width) / width),
107
+ y: finite((rounded ? Math.round(bounds.height) : bounds.height) / height)
108
+ };
109
+ };
110
+ /** The viewport rect of the element's padding box, in CSS pixels of its own window */ const getClientRect = (element)=>{
111
+ const bounds = getBounds(element);
112
+ const scale = getScale(element);
113
+ return {
114
+ ...rect(bounds.left + element.clientLeft * scale.x, bounds.top + element.clientTop * scale.y, element.clientWidth * scale.x, element.clientHeight * scale.y),
115
+ scale
116
+ };
117
+ };
118
+ /** The offset and scale of a window's viewport within the top-most same-origin window */ const getWindowSpace = (win)=>{
119
+ const space = {
120
+ x: 0,
121
+ y: 0,
122
+ scale: {
123
+ x: 1,
124
+ y: 1
125
+ }
126
+ };
127
+ for(let frame = win.frameElement; isHTMLElement(frame); frame = getWindow(frame).frameElement){
128
+ const bounds = getBounds(frame);
129
+ const scale = getScale(frame);
130
+ const css = getStyle(frame);
131
+ space.x = bounds.left + (frame.clientLeft + (parseFloat(css.paddingLeft) || 0) + space.x) * scale.x;
132
+ space.y = bounds.top + (frame.clientTop + (parseFloat(css.paddingTop) || 0) + space.y) * scale.y;
133
+ space.scale.x *= scale.x;
134
+ space.scale.y *= scale.y;
135
+ }
136
+ return space;
137
+ };
138
+ /** Converts a viewport rect of one window to a viewport rect of another (same-origin) window */ const convertWindowRect = (value, from, to)=>{
139
+ if (from === to) {
140
+ return value;
141
+ }
142
+ const { x, y, scale } = getWindowSpace(from);
143
+ const target = getWindowSpace(to);
144
+ const targetScale = target.scale;
145
+ return rect((x + value.x * scale.x - target.x) / targetScale.x, (y + value.y * scale.y - target.y) / targetScale.y, value.width * scale.x / targetScale.x, value.height * scale.y / targetScale.y);
146
+ };
147
+ const isStatic = (element)=>getStyle(element).position === 'static';
148
+ export const getOffsetParent = (element)=>{
149
+ if (isTopLayer(element)) {
150
+ return null;
151
+ }
152
+ const strategy = getStyle(element).position === 'fixed' ? 'fixed' : 'absolute';
153
+ let parent = strategy === 'fixed' ? null : element.offsetParent;
154
+ while(isHTMLElement(parent) && /^(TABLE|TD|TH)$/.test(parent.tagName) && isStatic(parent)){
155
+ parent = parent.offsetParent;
156
+ }
157
+ return isHTMLElement(parent) && (!/^(HTML|BODY)$/.test(parent.tagName) || !isStatic(parent)) ? parent : findAncestor(element, (node, style)=>isHTMLElement(node) && isContainingBlock(node, style, strategy));
158
+ };
159
+ /** The viewport offset and scale of the coordinate space used to position the element */ export const getCoordinateSpace = (element, strategy)=>{
160
+ const parent = getOffsetParent(element);
161
+ if (parent) {
162
+ const { x, y, scale } = getClientRect(parent);
163
+ return {
164
+ parent,
165
+ scale,
166
+ x: x - parent.scrollLeft * scale.x,
167
+ y: y - parent.scrollTop * scale.y
168
+ };
169
+ }
170
+ const bounds = getBounds(getRoot(element));
171
+ return {
172
+ scale: {
173
+ x: 1,
174
+ y: 1
175
+ },
176
+ x: strategy === 'fixed' ? 0 : bounds.left,
177
+ y: strategy === 'fixed' ? 0 : bounds.top
178
+ };
179
+ };
180
+ /**
181
+ * The reference rect in the floating element's coordinate space, `context` is the reference element or the element
182
+ * that a virtual reference is relative to (the floating element's root element by default).
183
+ */ export const getReferenceRect = (reference, context, floating, space, strategy)=>{
184
+ const floatingWindow = getWindow(floating);
185
+ const referenceWindow = getWindow(context);
186
+ const bounds = convertWindowRect(getBounds(reference), referenceWindow, floatingWindow);
187
+ const visual = strategy === 'fixed' && referenceWindow === floatingWindow && !space.parent ? getVisualOffsets(floating) : NO_OFFSET;
188
+ const { x, y, scale } = space;
189
+ return rect((bounds.x + visual.x - x) / scale.x, (bounds.y + visual.y - y) / scale.y, bounds.width / scale.x, bounds.height / scale.y);
190
+ };
191
+ /** The visible area of the element within the boundary, in viewport pixels of `floatingWindow` */ export const getClippingRect = (element, boundary, floatingWindow = getWindow(element), strategy = 'absolute')=>{
192
+ const win = getWindow(element);
193
+ const root = getRoot(element);
194
+ const viewport = win.visualViewport;
195
+ // WebKit lays out absolute elements relative to the layout viewport, rect boundaries are in its coordinates too
196
+ const visual = getVisualOffsets(element);
197
+ const layout = strategy === 'fixed' ? NO_OFFSET : visual;
198
+ const clippingAncestors = boundary === 'clippingAncestors';
199
+ let clip = viewport ? rect(viewport.offsetLeft - layout.x, viewport.offsetTop - layout.y, viewport.width, viewport.height) : rect(0, 0, root.clientWidth, root.clientHeight);
200
+ for (const item of clippingAncestors ? getScrollAncestors(element) : [].concat(boundary)){
201
+ if (item && typeof item === 'object') {
202
+ const { x, y, width, height } = item;
203
+ clip = intersect(clip, 'nodeType' in item ? convertWindowRect(getClientRect(item), getWindow(item), win) : rect(x - visual.x, y - visual.y, width, height));
204
+ }
205
+ }
206
+ const result = convertWindowRect(clip, win, floatingWindow);
207
+ const frame = win.frameElement;
208
+ return clippingAncestors && win !== floatingWindow && isHTMLElement(frame) ? intersect(result, getClippingRect(frame, boundary, floatingWindow, strategy)) : result;
209
+ };
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/engine/platform.ts"],"sourcesContent":["import { isHTMLElement } from '@fluentui/react-utilities';\nimport type { Boundary, Rect, Strategy } from '@floating-ui/dom';\n\ntype Scale = { x: number; y: number };\ntype CoordinateSpace = Scale & { scale: Scale; parent?: HTMLElement | null };\n\n// Expression-bodied helpers and plain property access keep the ES2019 output compact.\n\nexport const getWindow = (node: Node): Window => node.ownerDocument!.defaultView!;\nexport const getRoot = (node: Node): HTMLElement => node.ownerDocument!.documentElement;\nexport const getStyle = (element: Element): CSSStyleDeclaration => getWindow(element).getComputedStyle(element);\n\n/** A CSS pixel value, an empty string removes the inline style */\nexport const px = (value: number | undefined): string => (value === undefined ? '' : `${value}px`);\n\n// Properties that are not supported are empty strings (i.e. in jsdom)\nconst isSet = (value: string | undefined): boolean => !!value && value !== 'none';\n\n/** Uses `CSS.supports()` of the element's window, which is unavailable in some environments (e.g. jsdom) */\nconst isWebKit = (element: Element): boolean => {\n const css = (getWindow(element) as Window & typeof globalThis).CSS;\n return !!css && !!css.supports && css.supports('-webkit-backdrop-filter', 'none');\n};\n\n/** Shared and never mutated */\nexport const NO_OFFSET: Scale = { x: 0, y: 0 };\n\nconst getVisualOffsets = (element: Element): Scale => {\n const viewport = getWindow(element).visualViewport;\n return isWebKit(element) && viewport ? { x: viewport.offsetLeft, y: viewport.offsetTop } : NO_OFFSET;\n};\n\nconst getBounds = (target: { getBoundingClientRect(): DOMRect | Rect }) => target.getBoundingClientRect() as DOMRect;\n\nexport const rect = (x: number, y: number, width: number, height: number): Rect => ({ x, y, width, height });\n\nexport const intersect = (a: Rect, b: Rect): Rect => {\n const x = Math.max(a.x, b.x);\n const y = Math.max(a.y, b.y);\n\n return rect(x, y, Math.min(a.x + a.width, b.x + b.width) - x, Math.min(a.y + a.height, b.y + b.height) - y);\n};\n\nexport const isContainingBlock = (\n element: Element,\n style: CSSStyleDeclaration,\n strategy: 'absolute' | 'fixed',\n): boolean =>\n // Boxless elements can't form containing blocks, and WebKit ignores filters\n style.display !== 'contents' &&\n ((strategy === 'absolute' && !/^(static)?$/.test(style.position)) ||\n ('transform translate scale rotate perspective'.split(' ') as 'scale'[]).some(property => isSet(style[property])) ||\n ((isSet(style.filter) || isSet(style.backdropFilter)) && !isWebKit(element)) ||\n /auto|hidden/.test(style.contentVisibility) ||\n (!!style.containerType && style.containerType !== 'normal') ||\n /transform|perspective|filter/.test(style.willChange) ||\n /paint|layout|strict|content/.test(style.contain));\n\n/** The parent element, through slot assignments and shadow roots but not virtual parents */\nexport const getPhysicalParent = (element: Element): Element | null => {\n if (isTopLayer(element)) {\n return null;\n }\n let parent: Node | null = element.assignedSlot || element.parentNode;\n if (parent && parent.nodeType === 11) {\n parent = (parent as ShadowRoot).host;\n }\n return parent && parent.nodeType === 1 ? (parent as Element) : null;\n};\n\n/** Open popovers and modal dialogs escape the clipping and containing blocks of their ancestors */\nconst isTopLayer = (element: Element): boolean => {\n try {\n // A single forgiving `:is()` match per ancestor: unsupported pseudo-classes never match, and environments\n // without `:is()` (e.g. jsdom) throw\n return element.matches(':is(:popover-open, :modal)');\n } catch {\n return false;\n }\n};\n\n/**\n * Walks the physical ancestors (including SVG elements) of an element up to (excluding) the root element,\n * stops when the callback returns true and returns that ancestor.\n */\nexport const findAncestor = (\n element: Element,\n callback: (node: Element, style: CSSStyleDeclaration) => unknown,\n): Element | null => {\n const root = getRoot(element);\n for (let node = getPhysicalParent(element); node && node !== root; node = getPhysicalParent(node)) {\n if (callback(node, getStyle(node))) {\n return node;\n }\n }\n return null;\n};\n\n/** The ancestors that can clip the element, the closest first */\nexport const getScrollAncestors = (element: Element): HTMLElement[] => {\n const ancestors: HTMLElement[] = [];\n const isPositioned = (position: string) => position === 'fixed' || position === 'absolute';\n const { position } = getStyle(element);\n let strategy = isPositioned(position) ? position : '';\n\n findAncestor(element, (node, style) => {\n // Positioned descendants escape overflow between themselves and their containing block.\n if (strategy && isContainingBlock(node, style, strategy as 'absolute' | 'fixed')) {\n strategy = '';\n }\n // The overflow of the body propagates to the viewport, which is always part of the clipping rect\n if (\n !strategy &&\n node !== element.ownerDocument.body &&\n isHTMLElement(node) &&\n !/^(inline|contents)$/.test(style.display) &&\n /auto|scroll|overlay|hidden|clip/.test(style.overflow + style.overflowX + style.overflowY)\n ) {\n ancestors.push(node);\n }\n if (!strategy && isPositioned(style.position)) {\n strategy = style.position;\n }\n });\n\n return ancestors;\n};\n\n/** CSS dimensions, or the rounded layout dimensions when they differ after rounding */\nexport const getDimensions = (element: Element): { width: number; height: number; rounded: boolean } => {\n const css = getStyle(element);\n const width = parseFloat(css.width) || 0;\n const height = parseFloat(css.height) || 0;\n const rounded =\n isHTMLElement(element) &&\n (Math.round(width) !== element.offsetWidth || Math.round(height) !== element.offsetHeight);\n return {\n width: rounded ? (element as HTMLElement).offsetWidth : width,\n height: rounded ? (element as HTMLElement).offsetHeight : height,\n rounded,\n };\n};\n\nexport const getScale = (element: HTMLElement): Scale => {\n const bounds = getBounds(element);\n const { width, height, rounded } = getDimensions(element);\n // Zero, infinite and NaN scales (e.g. of hidden elements) fall back to 1\n const finite = (value: number) => (value && Number.isFinite(value) ? value : 1);\n return {\n x: finite((rounded ? Math.round(bounds.width) : bounds.width) / width),\n y: finite((rounded ? Math.round(bounds.height) : bounds.height) / height),\n };\n};\n\n/** The viewport rect of the element's padding box, in CSS pixels of its own window */\nconst getClientRect = (element: HTMLElement): Rect & { scale: Scale } => {\n const bounds = getBounds(element);\n const scale = getScale(element);\n return {\n ...rect(\n bounds.left + element.clientLeft * scale.x,\n bounds.top + element.clientTop * scale.y,\n element.clientWidth * scale.x,\n element.clientHeight * scale.y,\n ),\n scale,\n };\n};\n\n/** The offset and scale of a window's viewport within the top-most same-origin window */\nconst getWindowSpace = (win: Window): CoordinateSpace => {\n const space = { x: 0, y: 0, scale: { x: 1, y: 1 } };\n for (let frame = win.frameElement; isHTMLElement(frame); frame = getWindow(frame).frameElement) {\n const bounds = getBounds(frame);\n const scale = getScale(frame);\n const css = getStyle(frame);\n space.x = bounds.left + (frame.clientLeft + (parseFloat(css.paddingLeft) || 0) + space.x) * scale.x;\n space.y = bounds.top + (frame.clientTop + (parseFloat(css.paddingTop) || 0) + space.y) * scale.y;\n space.scale.x *= scale.x;\n space.scale.y *= scale.y;\n }\n return space;\n};\n\n/** Converts a viewport rect of one window to a viewport rect of another (same-origin) window */\nconst convertWindowRect = (value: Rect, from: Window, to: Window): Rect => {\n if (from === to) {\n return value;\n }\n const { x, y, scale } = getWindowSpace(from);\n const target = getWindowSpace(to);\n const targetScale = target.scale;\n return rect(\n (x + value.x * scale.x - target.x) / targetScale.x,\n (y + value.y * scale.y - target.y) / targetScale.y,\n (value.width * scale.x) / targetScale.x,\n (value.height * scale.y) / targetScale.y,\n );\n};\n\nconst isStatic = (element: Element) => getStyle(element).position === 'static';\n\nexport const getOffsetParent = (element: HTMLElement): HTMLElement | null => {\n if (isTopLayer(element)) {\n return null;\n }\n const strategy = getStyle(element).position === 'fixed' ? 'fixed' : 'absolute';\n let parent = strategy === 'fixed' ? null : element.offsetParent;\n while (isHTMLElement(parent) && /^(TABLE|TD|TH)$/.test(parent.tagName) && isStatic(parent)) {\n parent = parent.offsetParent;\n }\n return isHTMLElement(parent) && (!/^(HTML|BODY)$/.test(parent.tagName) || !isStatic(parent))\n ? parent\n : // The element that forms the containing block, `null` is the viewport or the initial containing block\n (findAncestor(\n element,\n (node, style) => isHTMLElement(node) && isContainingBlock(node, style, strategy),\n ) as HTMLElement | null);\n};\n\n/** The viewport offset and scale of the coordinate space used to position the element */\nexport const getCoordinateSpace = (element: HTMLElement, strategy: Strategy): CoordinateSpace => {\n const parent = getOffsetParent(element);\n if (parent) {\n const { x, y, scale } = getClientRect(parent);\n return { parent, scale, x: x - parent.scrollLeft * scale.x, y: y - parent.scrollTop * scale.y };\n }\n const bounds = getBounds(getRoot(element));\n return {\n scale: { x: 1, y: 1 },\n x: strategy === 'fixed' ? 0 : bounds.left,\n y: strategy === 'fixed' ? 0 : bounds.top,\n };\n};\n\n/**\n * The reference rect in the floating element's coordinate space, `context` is the reference element or the element\n * that a virtual reference is relative to (the floating element's root element by default).\n */\nexport const getReferenceRect = (\n reference: { getBoundingClientRect(): DOMRect | Rect },\n context: Element,\n floating: HTMLElement,\n space: CoordinateSpace,\n strategy: Strategy,\n): Rect => {\n const floatingWindow = getWindow(floating);\n const referenceWindow = getWindow(context);\n const bounds = convertWindowRect(getBounds(reference), referenceWindow, floatingWindow);\n const visual =\n strategy === 'fixed' && referenceWindow === floatingWindow && !space.parent\n ? getVisualOffsets(floating)\n : NO_OFFSET;\n const { x, y, scale } = space;\n return rect(\n (bounds.x + visual.x - x) / scale.x,\n (bounds.y + visual.y - y) / scale.y,\n bounds.width / scale.x,\n bounds.height / scale.y,\n );\n};\n\n/** The visible area of the element within the boundary, in viewport pixels of `floatingWindow` */\nexport const getClippingRect = (\n element: Element,\n boundary: Boundary,\n floatingWindow = getWindow(element),\n strategy: Strategy = 'absolute',\n): Rect => {\n const win = getWindow(element);\n const root = getRoot(element);\n const viewport = win.visualViewport;\n // WebKit lays out absolute elements relative to the layout viewport, rect boundaries are in its coordinates too\n const visual = getVisualOffsets(element);\n const layout = strategy === 'fixed' ? NO_OFFSET : visual;\n const clippingAncestors = boundary === 'clippingAncestors';\n let clip = viewport\n ? rect(viewport.offsetLeft - layout.x, viewport.offsetTop - layout.y, viewport.width, viewport.height)\n : rect(0, 0, root.clientWidth, root.clientHeight);\n for (const item of clippingAncestors ? getScrollAncestors(element) : ([] as unknown[]).concat(boundary)) {\n if (item && typeof item === 'object') {\n const { x, y, width, height } = item as Rect;\n clip = intersect(\n clip,\n 'nodeType' in item\n ? convertWindowRect(getClientRect(item as HTMLElement), getWindow(item as Node), win)\n : rect(x - visual.x, y - visual.y, width, height),\n );\n }\n }\n const result = convertWindowRect(clip, win, floatingWindow);\n const frame = win.frameElement;\n return clippingAncestors && win !== floatingWindow && isHTMLElement(frame)\n ? intersect(result, getClippingRect(frame, boundary, floatingWindow, strategy))\n : result;\n};\n"],"names":["isHTMLElement","getWindow","node","ownerDocument","defaultView","getRoot","documentElement","getStyle","element","getComputedStyle","px","value","undefined","isSet","isWebKit","css","CSS","supports","NO_OFFSET","x","y","getVisualOffsets","viewport","visualViewport","offsetLeft","offsetTop","getBounds","target","getBoundingClientRect","rect","width","height","intersect","a","b","Math","max","min","isContainingBlock","style","strategy","display","test","position","split","some","property","filter","backdropFilter","contentVisibility","containerType","willChange","contain","getPhysicalParent","isTopLayer","parent","assignedSlot","parentNode","nodeType","host","matches","findAncestor","callback","root","getScrollAncestors","ancestors","isPositioned","body","overflow","overflowX","overflowY","push","getDimensions","parseFloat","rounded","round","offsetWidth","offsetHeight","getScale","bounds","finite","Number","isFinite","getClientRect","scale","left","clientLeft","top","clientTop","clientWidth","clientHeight","getWindowSpace","win","space","frame","frameElement","paddingLeft","paddingTop","convertWindowRect","from","to","targetScale","isStatic","getOffsetParent","offsetParent","tagName","getCoordinateSpace","scrollLeft","scrollTop","getReferenceRect","reference","context","floating","floatingWindow","referenceWindow","visual","getClippingRect","boundary","layout","clippingAncestors","clip","item","concat","result"],"mappings":"AAAA,SAASA,aAAa,QAAQ,4BAA4B;AAM1D,sFAAsF;AAEtF,OAAO,MAAMC,YAAY,CAACC,OAAuBA,KAAKC,aAAa,CAAEC,WAAW,CAAE;AAClF,OAAO,MAAMC,UAAU,CAACH,OAA4BA,KAAKC,aAAa,CAAEG,eAAe,CAAC;AACxF,OAAO,MAAMC,WAAW,CAACC,UAA0CP,UAAUO,SAASC,gBAAgB,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AAC,EAAEU,KAAK,EAAEC,MAAM,EAAE,GAAG0F;YAChCD,OAAOxF,UACLwF,MACA,cAAcC,OACVvB,kBAAkBf,cAAcsC,OAAsBxH,UAAUwH,OAAe7B,OAC/E/D,KAAKV,IAAIgG,OAAOhG,CAAC,EAAEC,IAAI+F,OAAO/F,CAAC,EAAEU,OAAOC;QAEhD;IACF;IACA,MAAM4F,SAASzB,kBAAkBsB,MAAM5B,KAAKqB;IAC5C,MAAMnB,QAAQF,IAAIG,YAAY;IAC9B,OAAOwB,qBAAqB3B,QAAQqB,kBAAkBjH,cAAc8F,SAChE9D,UAAU2F,QAAQP,gBAAgBtB,OAAOuB,UAAUJ,gBAAgBzE,aACnEmF;AACN,EAAE"}
@@ -1,4 +1,4 @@
1
- import { flip as baseFlip } from "@floating-ui/dom";
1
+ import { flip as baseFlip } from "../engine/index.js";
2
2
  import { getBoundary, resolvePositioningShorthand, toFloatingUIPlacement } from "../utils/index.js";
3
3
  export function flip(options) {
4
4
  const { hasScrollableElement, flipBoundary, container, fallbackPositions = [], isRtl } = options;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/middleware/flip.ts"],"sourcesContent":["import type { Placement, Middleware } from '@floating-ui/dom';\nimport { flip as baseFlip } from '@floating-ui/dom';\nimport type { PositioningOptions } from '../types';\nimport { getBoundary, resolvePositioningShorthand, toFloatingUIPlacement } from '../utils/index';\n\nexport interface FlipMiddlewareOptions extends Pick<PositioningOptions, 'flipBoundary' | 'fallbackPositions'> {\n hasScrollableElement?: boolean;\n container: HTMLElement | null;\n isRtl?: boolean;\n}\n\nexport function flip(options: FlipMiddlewareOptions): Middleware {\n const { hasScrollableElement, flipBoundary, container, fallbackPositions = [], isRtl } = options;\n\n const fallbackPlacements = fallbackPositions.reduce<Placement[]>((acc, shorthand) => {\n const { position, align } = resolvePositioningShorthand(shorthand);\n const placement = toFloatingUIPlacement(align, position, isRtl);\n if (placement) {\n acc.push(placement);\n }\n return acc;\n }, []);\n\n return baseFlip({\n ...(hasScrollableElement && { boundary: 'clippingAncestors' }),\n ...(flipBoundary && { altBoundary: true, boundary: getBoundary(container, flipBoundary) }),\n fallbackStrategy: 'bestFit',\n ...(fallbackPlacements.length && { fallbackPlacements }),\n });\n}\n"],"names":["flip","baseFlip","getBoundary","resolvePositioningShorthand","toFloatingUIPlacement","options","hasScrollableElement","flipBoundary","container","fallbackPositions","isRtl","fallbackPlacements","reduce","acc","shorthand","position","align","placement","push","boundary","altBoundary","fallbackStrategy","length"],"mappings":"AACA,SAASA,QAAQC,QAAQ,QAAQ,mBAAmB;AAEpD,SAASC,WAAW,EAAEC,2BAA2B,EAAEC,qBAAqB,QAAQ,oBAAiB;AAQjG,OAAO,SAASJ,KAAKK,OAA8B;IACjD,MAAM,EAAEC,oBAAoB,EAAEC,YAAY,EAAEC,SAAS,EAAEC,oBAAoB,EAAE,EAAEC,KAAK,EAAE,GAAGL;IAEzF,MAAMM,qBAAqBF,kBAAkBG,MAAM,CAAc,CAACC,KAAKC;QACrE,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAE,GAAGb,4BAA4BW;QACxD,MAAMG,YAAYb,sBAAsBY,OAAOD,UAAUL;QACzD,IAAIO,WAAW;YACbJ,IAAIK,IAAI,CAACD;QACX;QACA,OAAOJ;IACT,GAAG,EAAE;IAEL,OAAOZ,SAAS;QACd,GAAIK,wBAAwB;YAAEa,UAAU;QAAoB,CAAC;QAC7D,GAAIZ,gBAAgB;YAAEa,aAAa;YAAMD,UAAUjB,YAAYM,WAAWD;QAAc,CAAC;QACzFc,kBAAkB;QAClB,GAAIV,mBAAmBW,MAAM,IAAI;YAAEX;QAAmB,CAAC;IACzD;AACF"}
1
+ {"version":3,"sources":["../../src/middleware/flip.ts"],"sourcesContent":["import type { Placement, Middleware } from '@floating-ui/dom';\nimport { flip as baseFlip } from '../engine';\nimport type { PositioningOptions } from '../types';\nimport { getBoundary, resolvePositioningShorthand, toFloatingUIPlacement } from '../utils/index';\n\nexport interface FlipMiddlewareOptions extends Pick<PositioningOptions, 'flipBoundary' | 'fallbackPositions'> {\n hasScrollableElement?: boolean;\n container: HTMLElement | null;\n isRtl?: boolean;\n}\n\nexport function flip(options: FlipMiddlewareOptions): Middleware {\n const { hasScrollableElement, flipBoundary, container, fallbackPositions = [], isRtl } = options;\n\n const fallbackPlacements = fallbackPositions.reduce<Placement[]>((acc, shorthand) => {\n const { position, align } = resolvePositioningShorthand(shorthand);\n const placement = toFloatingUIPlacement(align, position, isRtl);\n if (placement) {\n acc.push(placement);\n }\n return acc;\n }, []);\n\n return baseFlip({\n ...(hasScrollableElement && { boundary: 'clippingAncestors' }),\n ...(flipBoundary && { altBoundary: true, boundary: getBoundary(container, flipBoundary) }),\n fallbackStrategy: 'bestFit',\n ...(fallbackPlacements.length && { fallbackPlacements }),\n });\n}\n"],"names":["flip","baseFlip","getBoundary","resolvePositioningShorthand","toFloatingUIPlacement","options","hasScrollableElement","flipBoundary","container","fallbackPositions","isRtl","fallbackPlacements","reduce","acc","shorthand","position","align","placement","push","boundary","altBoundary","fallbackStrategy","length"],"mappings":"AACA,SAASA,QAAQC,QAAQ,QAAQ,qBAAY;AAE7C,SAASC,WAAW,EAAEC,2BAA2B,EAAEC,qBAAqB,QAAQ,oBAAiB;AAQjG,OAAO,SAASJ,KAAKK,OAA8B;IACjD,MAAM,EAAEC,oBAAoB,EAAEC,YAAY,EAAEC,SAAS,EAAEC,oBAAoB,EAAE,EAAEC,KAAK,EAAE,GAAGL;IAEzF,MAAMM,qBAAqBF,kBAAkBG,MAAM,CAAc,CAACC,KAAKC;QACrE,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAE,GAAGb,4BAA4BW;QACxD,MAAMG,YAAYb,sBAAsBY,OAAOD,UAAUL;QACzD,IAAIO,WAAW;YACbJ,IAAIK,IAAI,CAACD;QACX;QACA,OAAOJ;IACT,GAAG,EAAE;IAEL,OAAOZ,SAAS;QACd,GAAIK,wBAAwB;YAAEa,UAAU;QAAoB,CAAC;QAC7D,GAAIZ,gBAAgB;YAAEa,aAAa;YAAMD,UAAUjB,YAAYM,WAAWD;QAAc,CAAC;QACzFc,kBAAkB;QAClB,GAAIV,mBAAmBW,MAAM,IAAI;YAAEX;QAAmB,CAAC;IACzD;AACF"}
@@ -1,4 +1,4 @@
1
- import { detectOverflow } from "@floating-ui/dom";
1
+ import { detectOverflow } from "../engine/index.js";
2
2
  export function intersecting() {
3
3
  return {
4
4
  name: 'intersectionObserver',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/middleware/intersecting.ts"],"sourcesContent":["import type { Middleware } from '@floating-ui/dom';\nimport { detectOverflow } from '@floating-ui/dom';\n\nexport function intersecting(): Middleware {\n return {\n name: 'intersectionObserver',\n fn: async middlewareArguments => {\n const floatingRect = middlewareArguments.rects.floating;\n const altOverflow = await detectOverflow(middlewareArguments, { altBoundary: true });\n\n const isIntersectingTop = altOverflow.top < floatingRect.height && altOverflow.top > 0;\n const isIntersectingBottom = altOverflow.bottom < floatingRect.height && altOverflow.bottom > 0;\n\n const isIntersecting = isIntersectingTop || isIntersectingBottom;\n\n return {\n data: {\n intersecting: isIntersecting,\n },\n };\n },\n };\n}\n"],"names":["detectOverflow","intersecting","name","fn","middlewareArguments","floatingRect","rects","floating","altOverflow","altBoundary","isIntersectingTop","top","height","isIntersectingBottom","bottom","isIntersecting","data"],"mappings":"AACA,SAASA,cAAc,QAAQ,mBAAmB;AAElD,OAAO,SAASC;IACd,OAAO;QACLC,MAAM;QACNC,IAAI,OAAMC;YACR,MAAMC,eAAeD,oBAAoBE,KAAK,CAACC,QAAQ;YACvD,MAAMC,cAAc,MAAMR,eAAeI,qBAAqB;gBAAEK,aAAa;YAAK;YAElF,MAAMC,oBAAoBF,YAAYG,GAAG,GAAGN,aAAaO,MAAM,IAAIJ,YAAYG,GAAG,GAAG;YACrF,MAAME,uBAAuBL,YAAYM,MAAM,GAAGT,aAAaO,MAAM,IAAIJ,YAAYM,MAAM,GAAG;YAE9F,MAAMC,iBAAiBL,qBAAqBG;YAE5C,OAAO;gBACLG,MAAM;oBACJf,cAAcc;gBAChB;YACF;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/middleware/intersecting.ts"],"sourcesContent":["import type { Middleware } from '@floating-ui/dom';\nimport { detectOverflow } from '../engine';\n\nexport function intersecting(): Middleware {\n return {\n name: 'intersectionObserver',\n fn: async middlewareArguments => {\n const floatingRect = middlewareArguments.rects.floating;\n const altOverflow = await detectOverflow(middlewareArguments, { altBoundary: true });\n\n const isIntersectingTop = altOverflow.top < floatingRect.height && altOverflow.top > 0;\n const isIntersectingBottom = altOverflow.bottom < floatingRect.height && altOverflow.bottom > 0;\n\n const isIntersecting = isIntersectingTop || isIntersectingBottom;\n\n return {\n data: {\n intersecting: isIntersecting,\n },\n };\n },\n };\n}\n"],"names":["detectOverflow","intersecting","name","fn","middlewareArguments","floatingRect","rects","floating","altOverflow","altBoundary","isIntersectingTop","top","height","isIntersectingBottom","bottom","isIntersecting","data"],"mappings":"AACA,SAASA,cAAc,QAAQ,qBAAY;AAE3C,OAAO,SAASC;IACd,OAAO;QACLC,MAAM;QACNC,IAAI,OAAMC;YACR,MAAMC,eAAeD,oBAAoBE,KAAK,CAACC,QAAQ;YACvD,MAAMC,cAAc,MAAMR,eAAeI,qBAAqB;gBAAEK,aAAa;YAAK;YAElF,MAAMC,oBAAoBF,YAAYG,GAAG,GAAGN,aAAaO,MAAM,IAAIJ,YAAYG,GAAG,GAAG;YACrF,MAAME,uBAAuBL,YAAYM,MAAM,GAAGT,aAAaO,MAAM,IAAIJ,YAAYM,MAAM,GAAG;YAE9F,MAAMC,iBAAiBL,qBAAqBG;YAE5C,OAAO;gBACLG,MAAM;oBACJf,cAAcc;gBAChB;YACF;QACF;IACF;AACF"}
@@ -1,4 +1,4 @@
1
- import { size } from "@floating-ui/dom";
1
+ import { size } from "../engine/index.js";
2
2
  import { getBoundary } from "../utils/getBoundary.js";
3
3
  import { toFloatingUIPadding } from "../utils/index.js";
4
4
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/middleware/maxSize.ts"],"sourcesContent":["import { size } from '@floating-ui/dom';\nimport type { Middleware } from '@floating-ui/dom';\nimport type { NormalizedAutoSize, PositioningOptions } from '../types';\nimport { getBoundary } from '../utils/getBoundary';\nimport { toFloatingUIPadding } from '../utils';\nexport interface MaxSizeMiddlewareOptions\n extends Pick<PositioningOptions, 'overflowBoundary' | 'overflowBoundaryPadding'> {\n container: HTMLElement | null;\n isRtl: boolean;\n}\n\n/**\n * floating-ui `size` middleware uses floating element's height/width to calculate available height/width.\n * This middleware only runs once per lifecycle, resetting styles applied by maxSize from previous lifecycle.\n * Then floating element's original size is restored and `size` middleware can calculate available height/width correctly.\n */\nexport const resetMaxSize = (autoSize: NormalizedAutoSize): Middleware => ({\n name: 'resetMaxSize',\n fn({ middlewareData, elements }) {\n if (middlewareData.resetMaxSize?.maxSizeAlreadyReset) {\n return {};\n }\n\n const { applyMaxWidth, applyMaxHeight } = autoSize;\n if (applyMaxWidth) {\n elements.floating.style.removeProperty('box-sizing');\n elements.floating.style.removeProperty('max-width');\n elements.floating.style.removeProperty('width');\n }\n if (applyMaxHeight) {\n elements.floating.style.removeProperty('box-sizing');\n elements.floating.style.removeProperty('max-height');\n elements.floating.style.removeProperty('height');\n }\n\n return {\n data: { maxSizeAlreadyReset: true },\n reset: { rects: true },\n };\n },\n});\n\nexport function maxSize(autoSize: NormalizedAutoSize, options: MaxSizeMiddlewareOptions): Middleware {\n const { container, overflowBoundary, overflowBoundaryPadding, isRtl } = options;\n return size({\n ...(overflowBoundaryPadding && { padding: toFloatingUIPadding(overflowBoundaryPadding, isRtl) }),\n ...(overflowBoundary && { altBoundary: true, boundary: getBoundary(container, overflowBoundary) }),\n apply({ availableHeight, availableWidth, elements, rects }) {\n const applyMaxSizeStyles = (apply: boolean, dimension: 'width' | 'height', availableSize: number) => {\n if (!apply) {\n return;\n }\n\n elements.floating.style.setProperty('box-sizing', 'border-box');\n elements.floating.style.setProperty(`max-${dimension}`, `${availableSize}px`);\n\n if (rects.floating[dimension] > availableSize) {\n elements.floating.style.setProperty(dimension, `${availableSize}px`);\n\n const axis = dimension === 'width' ? 'x' : 'y';\n if (!elements.floating.style.getPropertyValue(`overflow-${axis}`)) {\n elements.floating.style.setProperty(`overflow-${axis}`, 'auto');\n }\n }\n };\n\n const { applyMaxWidth, applyMaxHeight } = autoSize;\n applyMaxSizeStyles(applyMaxWidth, 'width', availableWidth);\n applyMaxSizeStyles(applyMaxHeight, 'height', availableHeight);\n },\n });\n}\n"],"names":["size","getBoundary","toFloatingUIPadding","resetMaxSize","autoSize","name","fn","middlewareData","elements","maxSizeAlreadyReset","applyMaxWidth","applyMaxHeight","floating","style","removeProperty","data","reset","rects","maxSize","options","container","overflowBoundary","overflowBoundaryPadding","isRtl","padding","altBoundary","boundary","apply","availableHeight","availableWidth","applyMaxSizeStyles","dimension","availableSize","setProperty","axis","getPropertyValue"],"mappings":"AAAA,SAASA,IAAI,QAAQ,mBAAmB;AAGxC,SAASC,WAAW,QAAQ,0BAAuB;AACnD,SAASC,mBAAmB,QAAQ,oBAAW;AAO/C;;;;CAIC,GACD,OAAO,MAAMC,eAAe,CAACC,WAA8C,CAAA;QACzEC,MAAM;QACNC,IAAG,EAAEC,cAAc,EAAEC,QAAQ,EAAE;gBACzBD;YAAJ,KAAIA,+BAAAA,eAAeJ,YAAY,cAA3BI,mDAAAA,6BAA6BE,mBAAmB,EAAE;gBACpD,OAAO,CAAC;YACV;YAEA,MAAM,EAAEC,aAAa,EAAEC,cAAc,EAAE,GAAGP;YAC1C,IAAIM,eAAe;gBACjBF,SAASI,QAAQ,CAACC,KAAK,CAACC,cAAc,CAAC;gBACvCN,SAASI,QAAQ,CAACC,KAAK,CAACC,cAAc,CAAC;gBACvCN,SAASI,QAAQ,CAACC,KAAK,CAACC,cAAc,CAAC;YACzC;YACA,IAAIH,gBAAgB;gBAClBH,SAASI,QAAQ,CAACC,KAAK,CAACC,cAAc,CAAC;gBACvCN,S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AM,EAAExB,aAAa,EAAEC,cAAc,EAAE,GAAGP;YAC1C0B,mBAAmBpB,eAAe,SAASmB;YAC3CC,mBAAmBnB,gBAAgB,UAAUiB;QAC/C;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/middleware/maxSize.ts"],"sourcesContent":["import { size } from '../engine';\nimport type { Middleware } from '@floating-ui/dom';\nimport type { NormalizedAutoSize, PositioningOptions } from '../types';\nimport { getBoundary } from '../utils/getBoundary';\nimport { toFloatingUIPadding } from '../utils';\nexport interface MaxSizeMiddlewareOptions\n extends Pick<PositioningOptions, 'overflowBoundary' | 'overflowBoundaryPadding'> {\n container: HTMLElement | null;\n isRtl: boolean;\n}\n\n/**\n * floating-ui `size` middleware uses floating element's height/width to calculate available height/width.\n * This middleware only runs once per lifecycle, resetting styles applied by maxSize from previous lifecycle.\n * Then floating element's original size is restored and `size` middleware can calculate available height/width correctly.\n */\nexport const resetMaxSize = (autoSize: NormalizedAutoSize): Middleware => ({\n name: 'resetMaxSize',\n fn({ middlewareData, elements }) {\n if (middlewareData.resetMaxSize?.maxSizeAlreadyReset) {\n return {};\n }\n\n const { applyMaxWidth, applyMaxHeight } = autoSize;\n if (applyMaxWidth) {\n elements.floating.style.removeProperty('box-sizing');\n elements.floating.style.removeProperty('max-width');\n elements.floating.style.removeProperty('width');\n }\n if (applyMaxHeight) {\n elements.floating.style.removeProperty('box-sizing');\n elements.floating.style.removeProperty('max-height');\n elements.floating.style.removeProperty('height');\n }\n\n return {\n data: { maxSizeAlreadyReset: true },\n reset: { rects: true },\n };\n },\n});\n\nexport function maxSize(autoSize: NormalizedAutoSize, options: MaxSizeMiddlewareOptions): Middleware {\n const { container, overflowBoundary, overflowBoundaryPadding, isRtl } = options;\n return size({\n ...(overflowBoundaryPadding && { padding: toFloatingUIPadding(overflowBoundaryPadding, isRtl) }),\n ...(overflowBoundary && { altBoundary: true, boundary: getBoundary(container, overflowBoundary) }),\n apply({ availableHeight, availableWidth, elements, rects }) {\n const applyMaxSizeStyles = (apply: boolean, dimension: 'width' | 'height', availableSize: number) => {\n if (!apply) {\n return;\n }\n\n elements.floating.style.setProperty('box-sizing', 'border-box');\n elements.floating.style.setProperty(`max-${dimension}`, `${availableSize}px`);\n\n if (rects.floating[dimension] > availableSize) {\n elements.floating.style.setProperty(dimension, `${availableSize}px`);\n\n const axis = dimension === 'width' ? 'x' : 'y';\n if (!elements.floating.style.getPropertyValue(`overflow-${axis}`)) {\n elements.floating.style.setProperty(`overflow-${axis}`, 'auto');\n }\n }\n };\n\n const { applyMaxWidth, applyMaxHeight } = autoSize;\n applyMaxSizeStyles(applyMaxWidth, 'width', availableWidth);\n applyMaxSizeStyles(applyMaxHeight, 'height', availableHeight);\n },\n });\n}\n"],"names":["size","getBoundary","toFloatingUIPadding","resetMaxSize","autoSize","name","fn","middlewareData","elements","maxSizeAlreadyReset","applyMaxWidth","applyMaxHeight","floating","style","removeProperty","data","reset","rects","maxSize","options","container","overflowBoundary","overflowBoundaryPadding","isRtl","padding","altBoundary","boundary","apply","availableHeight","availableWidth","applyMaxSizeStyles","dimension","availableSize","setProperty","axis","getPropertyValue"],"mappings":"AAAA,SAASA,IAAI,QAAQ,qBAAY;AAGjC,SAASC,WAAW,QAAQ,0BAAuB;AACnD,SAASC,mBAAmB,QAAQ,oBAAW;AAO/C;;;;CAIC,GACD,OAAO,MAAMC,eAAe,CAACC,WAA8C,CAAA;QACzEC,MAAM;QACNC,IAAG,EAAEC,cAAc,EAAEC,QAAQ,EAAE;gBACzBD;YAAJ,KAAIA,+BAAAA,eAAeJ,YAAY,cAA3BI,mDAAAA,6BAA6BE,mBAAmB,EAAE;gBACpD,OAAO,CAAC;YACV;YAEA,MAAM,EAAEC,aAAa,EAAEC,cAAc,EAAE,GAAGP;YAC1C,IAAIM,eAAe;gBACjBF,SAASI,QAAQ,CAACC,KAAK,CAACC,cAAc,CAAC;gBACvCN,SAASI,QAAQ,CAACC,KAAK,CAACC,cAAc,CAAC;gBACvCN,SAASI,QAAQ,CA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G;wBACjE1B,SAASI,QAAQ,CAACC,KAAK,CAACoB,WAAW,CAAC,CAAC,SAAS,EAAEC,MAAM,EAAE;oBAC1D;gBACF;YACF;YAEA,MAAM,EAAExB,aAAa,EAAEC,cAAc,EAAE,GAAGP;YAC1C0B,mBAAmBpB,eAAe,SAASmB;YAC3CC,mBAAmBnB,gBAAgB,UAAUiB;QAC/C;IACF;AACF"}
@@ -1,4 +1,4 @@
1
- import { offset as baseOffset } from "@floating-ui/dom";
1
+ import { offset as baseOffset } from "../engine/index.js";
2
2
  import { getFloatingUIOffset } from "../utils/getFloatingUIOffset.js";
3
3
  /**
4
4
  * Wraps floating UI offset middleware to transform offset value.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/middleware/offset.ts"],"sourcesContent":["import type { Middleware } from '@floating-ui/dom';\nimport { offset as baseOffset } from '@floating-ui/dom';\nimport type { PositioningOptions } from '../types';\nimport { getFloatingUIOffset } from '../utils/getFloatingUIOffset';\n\n/**\n * Wraps floating UI offset middleware to transform offset value.\n */\nexport function offset(offsetValue: PositioningOptions['offset']): Middleware {\n const floatingUIOffset = getFloatingUIOffset(offsetValue);\n return baseOffset(floatingUIOffset);\n}\n"],"names":["offset","baseOffset","getFloatingUIOffset","offsetValue","floatingUIOffset"],"mappings":"AACA,SAASA,UAAUC,UAAU,QAAQ,mBAAmB;AAExD,SAASC,mBAAmB,QAAQ,kCAA+B;AAEnE;;CAEC,GACD,OAAO,SAASF,OAAOG,WAAyC;IAC9D,MAAMC,mBAAmBF,oBAAoBC;IAC7C,OAAOF,WAAWG;AACpB"}
1
+ {"version":3,"sources":["../../src/middleware/offset.ts"],"sourcesContent":["import type { Middleware } from '@floating-ui/dom';\nimport { offset as baseOffset } from '../engine';\nimport type { PositioningOptions } from '../types';\nimport { getFloatingUIOffset } from '../utils/getFloatingUIOffset';\n\n/**\n * Wraps floating UI offset middleware to transform offset value.\n */\nexport function offset(offsetValue: PositioningOptions['offset']): Middleware {\n const floatingUIOffset = getFloatingUIOffset(offsetValue);\n return baseOffset(floatingUIOffset);\n}\n"],"names":["offset","baseOffset","getFloatingUIOffset","offsetValue","floatingUIOffset"],"mappings":"AACA,SAASA,UAAUC,UAAU,QAAQ,qBAAY;AAEjD,SAASC,mBAAmB,QAAQ,kCAA+B;AAEnE;;CAEC,GACD,OAAO,SAASF,OAAOG,WAAyC;IAC9D,MAAMC,mBAAmBF,oBAAoBC;IAC7C,OAAOF,WAAWG;AACpB"}
@@ -1,4 +1,4 @@
1
- import { shift as baseShift, limitShift } from "@floating-ui/dom";
1
+ import { shift as baseShift, limitShift } from "../engine/index.js";
2
2
  import { getBoundary, toFloatingUIPadding } from "../utils/index.js";
3
3
  /**
4
4
  * Wraps the floating UI shift middleware for easier usage of our options
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/middleware/shift.ts"],"sourcesContent":["import type { Middleware } from '@floating-ui/dom';\nimport { shift as baseShift, limitShift } from '@floating-ui/dom';\nimport type { PositioningOptions } from '../types';\nimport { getBoundary, toFloatingUIPadding } from '../utils/index';\n\nexport interface ShiftMiddlewareOptions\n extends Pick<PositioningOptions, 'overflowBoundary' | 'overflowBoundaryPadding' | 'shiftToCoverTarget'> {\n hasScrollableElement?: boolean;\n disableTether?: PositioningOptions['unstable_disableTether'];\n container: HTMLElement | null;\n isRtl: boolean;\n}\n\n/**\n * Wraps the floating UI shift middleware for easier usage of our options\n */\nexport function shift(options: ShiftMiddlewareOptions): Middleware {\n const {\n hasScrollableElement,\n shiftToCoverTarget,\n disableTether,\n overflowBoundary,\n container,\n overflowBoundaryPadding,\n isRtl,\n } = options;\n\n return baseShift({\n ...(hasScrollableElement && { boundary: 'clippingAncestors' }),\n ...(shiftToCoverTarget && {\n crossAxis: true,\n limiter: limitShift({ crossAxis: true, mainAxis: false }),\n }),\n ...(disableTether && {\n crossAxis: disableTether === 'all',\n limiter: limitShift({ crossAxis: disableTether !== 'all', mainAxis: false }),\n }),\n ...(overflowBoundaryPadding && { padding: toFloatingUIPadding(overflowBoundaryPadding, isRtl) }),\n ...(overflowBoundary && { altBoundary: true, boundary: getBoundary(container, overflowBoundary) }),\n });\n}\n"],"names":["shift","baseShift","limitShift","getBoundary","toFloatingUIPadding","options","hasScrollableElement","shiftToCoverTarget","disableTether","overflowBoundary","container","overflowBoundaryPadding","isRtl","boundary","crossAxis","limiter","mainAxis","padding","altBoundary"],"mappings":"AACA,SAASA,SAASC,SAAS,EAAEC,UAAU,QAAQ,mBAAmB;AAElE,SAASC,WAAW,EAAEC,mBAAmB,QAAQ,oBAAiB;AAUlE;;CAEC,GACD,OAAO,SAASJ,MAAMK,OAA+B;IACnD,MAAM,EACJC,oBAAoB,EACpBC,kBAAkB,EAClBC,aAAa,EACbC,gBAAgB,EAChBC,SAAS,EACTC,uBAAuB,EACvBC,KAAK,EACN,GAAGP;IAEJ,OAAOJ,UAAU;QACf,GAAIK,wBAAwB;YAAEO,UAAU;QAAoB,CAAC;QAC7D,GAAIN,sBAAsB;YACxBO,WAAW;YACXC,SAASb,WAAW;gBAAEY,WAAW;gBAAME,UAAU;YAAM;QACzD,CAAC;QACD,GAAIR,iBAAiB;YACnBM,WAAWN,kBAAkB;YAC7BO,SAASb,WAAW;gBAAEY,WAAWN,kBAAkB;gBAAOQ,UAAU;YAAM;QAC5E,CAAC;QACD,GAAIL,2BAA2B;YAAEM,SAASb,oBAAoBO,yBAAyBC;QAAO,CAAC;QAC/F,GAAIH,oBAAoB;YAAES,aAAa;YAAML,UAAUV,YAAYO,WAAWD;QAAkB,CAAC;IACnG;AACF"}
1
+ {"version":3,"sources":["../../src/middleware/shift.ts"],"sourcesContent":["import type { Middleware } from '@floating-ui/dom';\nimport { shift as baseShift, limitShift } from '../engine';\nimport type { PositioningOptions } from '../types';\nimport { getBoundary, toFloatingUIPadding } from '../utils/index';\n\nexport interface ShiftMiddlewareOptions\n extends Pick<PositioningOptions, 'overflowBoundary' | 'overflowBoundaryPadding' | 'shiftToCoverTarget'> {\n hasScrollableElement?: boolean;\n disableTether?: PositioningOptions['unstable_disableTether'];\n container: HTMLElement | null;\n isRtl: boolean;\n}\n\n/**\n * Wraps the floating UI shift middleware for easier usage of our options\n */\nexport function shift(options: ShiftMiddlewareOptions): Middleware {\n const {\n hasScrollableElement,\n shiftToCoverTarget,\n disableTether,\n overflowBoundary,\n container,\n overflowBoundaryPadding,\n isRtl,\n } = options;\n\n return baseShift({\n ...(hasScrollableElement && { boundary: 'clippingAncestors' }),\n ...(shiftToCoverTarget && {\n crossAxis: true,\n limiter: limitShift({ crossAxis: true, mainAxis: false }),\n }),\n ...(disableTether && {\n crossAxis: disableTether === 'all',\n limiter: limitShift({ crossAxis: disableTether !== 'all', mainAxis: false }),\n }),\n ...(overflowBoundaryPadding && { padding: toFloatingUIPadding(overflowBoundaryPadding, isRtl) }),\n ...(overflowBoundary && { altBoundary: true, boundary: getBoundary(container, overflowBoundary) }),\n });\n}\n"],"names":["shift","baseShift","limitShift","getBoundary","toFloatingUIPadding","options","hasScrollableElement","shiftToCoverTarget","disableTether","overflowBoundary","container","overflowBoundaryPadding","isRtl","boundary","crossAxis","limiter","mainAxis","padding","altBoundary"],"mappings":"AACA,SAASA,SAASC,SAAS,EAAEC,UAAU,QAAQ,qBAAY;AAE3D,SAASC,WAAW,EAAEC,mBAAmB,QAAQ,oBAAiB;AAUlE;;CAEC,GACD,OAAO,SAASJ,MAAMK,OAA+B;IACnD,MAAM,EACJC,oBAAoB,EACpBC,kBAAkB,EAClBC,aAAa,EACbC,gBAAgB,EAChBC,SAAS,EACTC,uBAAuB,EACvBC,KAAK,EACN,GAAGP;IAEJ,OAAOJ,UAAU;QACf,GAAIK,wBAAwB;YAAEO,UAAU;QAAoB,CAAC;QAC7D,GAAIN,sBAAsB;YACxBO,WAAW;YACXC,SAASb,WAAW;gBAAEY,WAAW;gBAAME,UAAU;YAAM;QACzD,CAAC;QACD,GAAIR,iBAAiB;YACnBM,WAAWN,kBAAkB;YAC7BO,SAASb,WAAW;gBAAEY,WAAWN,kBAAkB;gBAAOQ,UAAU;YAAM;QAC5E,CAAC;QACD,GAAIL,2BAA2B;YAAEM,SAASb,oBAAoBO,yBAAyBC;QAAO,CAAC;QAC/F,GAAIH,oBAAoB;YAAES,aAAa;YAAML,UAAUV,YAAYO,WAAWD;QAAkB,CAAC;IACnG;AACF"}
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import { canUseDOM, useEventCallback, useIsomorphicLayoutEffect } from "@fluentui/react-utilities";
2
+ import { useEventCallback, useIsomorphicLayoutEffect } from "@fluentui/react-utilities";
3
3
  import * as React from "react";
4
4
  import { POSITIONING_END_EVENT } from "./constants.js";
5
5
  import { createPositionManager } from "./createPositionManager.js";
@@ -9,25 +9,24 @@ import { useCallbackRef, hasAutofocusFilter } from "./utils/index.js";
9
9
  * @internal
10
10
  */ export function usePositioning(options) {
11
11
  const managerRef = React.useRef(null);
12
- const targetRef = React.useRef(null);
13
- const overrideTargetRef = React.useRef(null);
14
- const containerRef = React.useRef(null);
15
- const arrowRef = React.useRef(null);
12
+ // The latest elements, an imperatively set target overrides the target ref
13
+ const elementsRef = React.useRef({});
16
14
  const { enabled = true } = options;
17
15
  const resolvePositioningOptions = usePositioningOptions(options);
18
16
  const updatePositionManager = React.useCallback(()=>{
19
- var _overrideTargetRef_current;
20
17
  if (managerRef.current) {
21
18
  managerRef.current.dispose();
22
19
  }
23
20
  managerRef.current = null;
24
- const target = (_overrideTargetRef_current = overrideTargetRef.current) !== null && _overrideTargetRef_current !== void 0 ? _overrideTargetRef_current : targetRef.current;
25
- if (enabled && canUseDOM() && target && containerRef.current) {
21
+ const { override, target, container, arrow = null } = elementsRef.current;
22
+ const positioningTarget = override || target;
23
+ // Elements only exist in the DOM, so this also guards server rendering
24
+ if (enabled && positioningTarget && container) {
26
25
  managerRef.current = createPositionManager({
27
- container: containerRef.current,
28
- target,
29
- arrow: arrowRef.current,
30
- ...resolvePositioningOptions(containerRef.current, arrowRef.current)
26
+ container,
27
+ target: positioningTarget,
28
+ arrow,
29
+ ...resolvePositioningOptions(container, arrow)
31
30
  });
32
31
  }
33
32
  }, [
@@ -35,16 +34,13 @@ import { useCallbackRef, hasAutofocusFilter } from "./utils/index.js";
35
34
  resolvePositioningOptions
36
35
  ]);
37
36
  const setOverrideTarget = useEventCallback((target)=>{
38
- overrideTargetRef.current = target;
37
+ elementsRef.current.override = target;
39
38
  updatePositionManager();
40
39
  });
41
40
  React.useImperativeHandle(options.positioningRef, ()=>({
42
- updatePosition: ()=>{
43
- var _managerRef_current;
44
- return (_managerRef_current = managerRef.current) === null || _managerRef_current === void 0 ? void 0 : _managerRef_current.updatePosition();
45
- },
46
- setTarget: (target)=>{
47
- if (options.target && process.env.NODE_ENV !== 'production') {
41
+ updatePosition: ()=>managerRef.current && managerRef.current.updatePosition(),
42
+ setTarget: process.env.NODE_ENV === 'production' ? setOverrideTarget : (target)=>{
43
+ if (options.target) {
48
44
  const err = new Error();
49
45
  // eslint-disable-next-line no-console
50
46
  console.warn('Imperative setTarget should not be used at the same time as target option');
@@ -58,8 +54,7 @@ import { useCallbackRef, hasAutofocusFilter } from "./utils/index.js";
58
54
  setOverrideTarget
59
55
  ]);
60
56
  useIsomorphicLayoutEffect(()=>{
61
- var _options_target;
62
- setOverrideTarget((_options_target = options.target) !== null && _options_target !== void 0 ? _options_target : null);
57
+ setOverrideTarget(options.target || null);
63
58
  }, [
64
59
  options.target,
65
60
  setOverrideTarget
@@ -73,9 +68,9 @@ import { useCallbackRef, hasAutofocusFilter } from "./utils/index.js";
73
68
  // This checked should run only in development mode
74
69
  // eslint-disable-next-line react-hooks/rules-of-hooks
75
70
  React.useEffect(()=>{
76
- if (containerRef.current) {
71
+ if (elementsRef.current.container) {
77
72
  var _contentNode_ownerDocument;
78
- const contentNode = containerRef.current;
73
+ const contentNode = elementsRef.current.container;
79
74
  const treeWalker = (_contentNode_ownerDocument = contentNode.ownerDocument) === null || _contentNode_ownerDocument === void 0 ? void 0 : _contentNode_ownerDocument.createTreeWalker(contentNode, NodeFilter.SHOW_ELEMENT, {
80
75
  acceptNode: hasAutofocusFilter
81
76
  });
@@ -107,36 +102,31 @@ import { useCallbackRef, hasAutofocusFilter } from "./utils/index.js";
107
102
  // TODO: Should be rework to handle options.enabled and contentRef updates
108
103
  }, []);
109
104
  }
110
- const setTarget = useCallbackRef(null, (target)=>{
111
- if (targetRef.current !== target) {
112
- targetRef.current = target;
113
- updatePositionManager();
114
- }
115
- });
116
- const onPositioningEnd = useEventCallback((e)=>{
117
- var _options_onPositioningEnd;
118
- return (_options_onPositioningEnd = options.onPositioningEnd) === null || _options_onPositioningEnd === void 0 ? void 0 : _options_onPositioningEnd.call(options, e);
105
+ // Callback refs only fire when their value changes
106
+ const targetRef = useCallbackRef(null, (target)=>{
107
+ elementsRef.current.target = target;
108
+ updatePositionManager();
119
109
  });
120
- const setContainer = useCallbackRef(null, (container)=>{
121
- if (containerRef.current !== container) {
122
- var // Cast because CustomEvent<OnPositioningEndEventDetail> is not assignable to EventListener
123
- _containerRef_current;
124
- (_containerRef_current = containerRef.current) === null || _containerRef_current === void 0 ? void 0 : _containerRef_current.removeEventListener(POSITIONING_END_EVENT, onPositioningEnd);
125
- container === null || container === void 0 ? void 0 : container.addEventListener(POSITIONING_END_EVENT, onPositioningEnd);
126
- containerRef.current = container;
127
- updatePositionManager();
110
+ const onPositioningEnd = useEventCallback((e)=>options.onPositioningEnd && options.onPositioningEnd(e));
111
+ const containerRef = useCallbackRef(null, (container, previousContainer)=>{
112
+ // Cast because CustomEvent<OnPositioningEndEventDetail> is not assignable to EventListener
113
+ if (previousContainer) {
114
+ previousContainer.removeEventListener(POSITIONING_END_EVENT, onPositioningEnd);
128
115
  }
129
- });
130
- const setArrow = useCallbackRef(null, (arrow)=>{
131
- if (arrowRef.current !== arrow) {
132
- arrowRef.current = arrow;
133
- updatePositionManager();
116
+ if (container) {
117
+ container.addEventListener(POSITIONING_END_EVENT, onPositioningEnd);
134
118
  }
119
+ elementsRef.current.container = container;
120
+ updatePositionManager();
121
+ });
122
+ const arrowRef = useCallbackRef(null, (arrow)=>{
123
+ elementsRef.current.arrow = arrow;
124
+ updatePositionManager();
135
125
  });
136
126
  // Let users use callback refs so they feel like 'normal' DOM refs
137
127
  return {
138
- targetRef: setTarget,
139
- containerRef: setContainer,
140
- arrowRef: setArrow
128
+ targetRef,
129
+ containerRef,
130
+ arrowRef
141
131
  };
142
132
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/usePositioning.ts"],"sourcesContent":["'use client';\n\nimport { canUseDOM, useEventCallback, useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { POSITIONING_END_EVENT } from './constants';\nimport { createPositionManager } from './createPositionManager';\nimport type {\n OnPositioningEndEvent,\n PositioningOptions,\n PositioningProps,\n PositionManager,\n TargetElement,\n UsePositioningReturn,\n} from './types';\nimport { usePositioningOptions } from './usePositioningOptions';\nimport { useCallbackRef, hasAutofocusFilter } from './utils';\n\n/**\n * @internal\n */\nexport function usePositioning(options: PositioningProps & PositioningOptions): UsePositioningReturn {\n const managerRef = React.useRef<PositionManager | null>(null);\n const targetRef = React.useRef<TargetElement | null>(null);\n const overrideTargetRef = React.useRef<TargetElement | null>(null);\n const containerRef = React.useRef<HTMLElement | null>(null);\n const arrowRef = React.useRef<HTMLElement | null>(null);\n\n const { enabled = true } = options;\n const resolvePositioningOptions = usePositioningOptions(options);\n const updatePositionManager = React.useCallback(() => {\n if (managerRef.current) {\n managerRef.current.dispose();\n }\n managerRef.current = null;\n\n const target = overrideTargetRef.current ?? targetRef.current;\n\n if (enabled && canUseDOM() && target && containerRef.current) {\n managerRef.current = createPositionManager({\n container: containerRef.current,\n target,\n arrow: arrowRef.current,\n ...resolvePositioningOptions(containerRef.current, arrowRef.current),\n });\n }\n }, [enabled, resolvePositioningOptions]);\n\n const setOverrideTarget = useEventCallback((target: TargetElement | null) => {\n overrideTargetRef.current = target;\n updatePositionManager();\n });\n\n React.useImperativeHandle(\n options.positioningRef,\n () => ({\n updatePosition: () => managerRef.current?.updatePosition(),\n setTarget: (target: TargetElement | null) => {\n if (options.target && process.env.NODE_ENV !== 'production') {\n const err = new Error();\n // eslint-disable-next-line no-console\n console.warn('Imperative setTarget should not be used at the same time as target option');\n // eslint-disable-next-line no-console\n console.warn(err.stack);\n }\n\n setOverrideTarget(target);\n },\n }),\n [options.target, setOverrideTarget],\n );\n\n useIsomorphicLayoutEffect(() => {\n setOverrideTarget(options.target ?? null);\n }, [options.target, setOverrideTarget]);\n\n useIsomorphicLayoutEffect(() => {\n updatePositionManager();\n }, [updatePositionManager]);\n\n if (process.env.NODE_ENV !== 'production') {\n // This checked should run only in development mode\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (containerRef.current) {\n const contentNode = containerRef.current;\n const treeWalker = contentNode.ownerDocument?.createTreeWalker(contentNode, NodeFilter.SHOW_ELEMENT, {\n acceptNode: hasAutofocusFilter,\n });\n\n while (treeWalker.nextNode()) {\n const node = treeWalker.currentNode;\n // eslint-disable-next-line no-console\n console.warn('usePositioning():', node);\n // eslint-disable-next-line no-console\n console.warn(\n [\n 'usePositioning(): ^ this node contains \"autoFocus\" prop on a React element. This can break the initial',\n 'positioning of an element and cause a window jump effect. This issue occurs because React polyfills',\n '\"autoFocus\" behavior to solve inconsistencies between different browsers:',\n 'https://github.com/facebook/react/issues/11851#issuecomment-351787078',\n '\\n',\n 'However, \".focus()\" in this case occurs before any other React effects will be executed',\n '(React.useEffect(), componentDidMount(), etc.) and we can not prevent this behavior. If you really',\n 'want to use \"autoFocus\" please add \"position: fixed\" to styles of the element that is wrapped by',\n '\"Popper\".',\n `In general, it's not recommended to use \"autoFocus\" as it may break accessibility aspects:`,\n 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-autofocus.md',\n '\\n',\n 'We suggest to use the \"trapFocus\" prop on Fluent components or a catch \"ref\" and then use',\n '\"ref.current.focus\" in React.useEffect():',\n 'https://reactjs.org/docs/refs-and-the-dom.html#adding-a-ref-to-a-dom-element',\n ].join(' '),\n );\n }\n }\n // We run this check once, no need to add deps here\n // TODO: Should be rework to handle options.enabled and contentRef updates\n }, []);\n }\n\n const setTarget = useCallbackRef<TargetElement>(null, target => {\n if (targetRef.current !== target) {\n targetRef.current = target;\n updatePositionManager();\n }\n });\n\n const onPositioningEnd = useEventCallback((e: OnPositioningEndEvent) => options.onPositioningEnd?.(e));\n const setContainer = useCallbackRef<HTMLElement | null>(null, container => {\n if (containerRef.current !== container) {\n // Cast because CustomEvent<OnPositioningEndEventDetail> is not assignable to EventListener\n containerRef.current?.removeEventListener(POSITIONING_END_EVENT, onPositioningEnd as EventListener);\n container?.addEventListener(POSITIONING_END_EVENT, onPositioningEnd as EventListener);\n containerRef.current = container;\n updatePositionManager();\n }\n });\n\n const setArrow = useCallbackRef<HTMLElement | null>(null, arrow => {\n if (arrowRef.current !== arrow) {\n arrowRef.current = arrow;\n updatePositionManager();\n }\n });\n\n // Let users use callback refs so they feel like 'normal' DOM refs\n return { targetRef: setTarget, containerRef: setContainer, arrowRef: setArrow };\n}\n"],"names":["canUseDOM","useEventCallback","useIsomorphicLayoutEffect","React","POSITIONING_END_EVENT","createPositionManager","usePositioningOptions","useCallbackRef","hasAutofocusFilter","usePositioning","options","managerRef","useRef","targetRef","overrideTargetRef","containerRef","arrowRef","enabled","resolvePositioningOptions","updatePositionManager","useCallback","current","dispose","target","container","arrow","setOverrideTarget","useImperativeHandle","positioningRef","updatePosition","setTarget","process","env","NODE_ENV","err","Error","console","warn","stack","useEffect","contentNode","treeWalker","ownerDocument","createTreeWalker","NodeFilter","SHOW_ELEMENT","acceptNode","nextNode","node","currentNode","join","onPositioningEnd","e","setContainer","removeEventListener","addEventListener","setArrow"],"mappings":"AAAA;AAEA,SAASA,SAAS,EAAEC,gBAAgB,EAAEC,yBAAyB,QAAQ,4BAA4B;AACnG,YAAYC,WAAW,QAAQ;AAE/B,SAASC,qBAAqB,QAAQ,iBAAc;AACpD,SAASC,qBAAqB,Q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AO,GAAGE;YACpBJ;QACF;IACF;IAEA,MAAMgC,mBAAmBlD,iBAAiB,CAACmD;YAA6B1C;gBAAAA,4BAAAA,QAAQyC,gBAAgB,cAAxBzC,gDAAAA,+BAAAA,SAA2B0C;;IACnG,MAAMC,eAAe9C,eAAmC,MAAMiB,CAAAA;QAC5D,IAAIT,aAAaM,OAAO,KAAKG,WAAW;gBACtC,2FAA2F;YAC3FT;aAAAA,wBAAAA,aAAaM,OAAO,cAApBN,4CAAAA,sBAAsBuC,mBAAmB,CAAClD,uBAAuB+C;YACjE3B,sBAAAA,gCAAAA,UAAW+B,gBAAgB,CAACnD,uBAAuB+C;YACnDpC,aAAaM,OAAO,GAAGG;YACvBL;QACF;IACF;IAEA,MAAMqC,WAAWjD,eAAmC,MAAMkB,CAAAA;QACxD,IAAIT,SAASK,OAAO,KAAKI,OAAO;YAC9BT,SAASK,OAAO,GAAGI;YACnBN;QACF;IACF;IAEA,kEAAkE;IAClE,OAAO;QAAEN,WAAWiB;QAAWf,cAAcsC;QAAcrC,UAAUwC;IAAS;AAChF"}
1
+ {"version":3,"sources":["../src/usePositioning.ts"],"sourcesContent":["'use client';\n\nimport { useEventCallback, useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { POSITIONING_END_EVENT } from './constants';\nimport { createPositionManager } from './createPositionManager';\nimport type {\n OnPositioningEndEvent,\n PositioningOptions,\n PositioningProps,\n PositionManager,\n TargetElement,\n UsePositioningReturn,\n} from './types';\nimport { usePositioningOptions } from './usePositioningOptions';\nimport { useCallbackRef, hasAutofocusFilter } from './utils';\n\n/**\n * @internal\n */\nexport function usePositioning(options: PositioningProps & PositioningOptions): UsePositioningReturn {\n const managerRef = React.useRef<PositionManager | null>(null);\n // The latest elements, an imperatively set target overrides the target ref\n const elementsRef = React.useRef<\n Partial<Record<'target' | 'override', TargetElement | null>> & {\n container?: HTMLElement | null;\n arrow?: HTMLElement | null;\n }\n >({});\n\n const { enabled = true } = options;\n const resolvePositioningOptions = usePositioningOptions(options);\n const updatePositionManager = React.useCallback(() => {\n if (managerRef.current) {\n managerRef.current.dispose();\n }\n managerRef.current = null;\n\n const { override, target, container, arrow = null } = elementsRef.current;\n const positioningTarget = override || target;\n\n // Elements only exist in the DOM, so this also guards server rendering\n if (enabled && positioningTarget && container) {\n managerRef.current = createPositionManager({\n container,\n target: positioningTarget,\n arrow,\n ...resolvePositioningOptions(container, arrow),\n });\n }\n }, [enabled, resolvePositioningOptions]);\n\n const setOverrideTarget = useEventCallback((target: TargetElement | null) => {\n elementsRef.current.override = target;\n updatePositionManager();\n });\n\n React.useImperativeHandle(\n options.positioningRef,\n () => ({\n updatePosition: () => managerRef.current && managerRef.current.updatePosition(),\n setTarget:\n process.env.NODE_ENV === 'production'\n ? setOverrideTarget\n : (target: TargetElement | null) => {\n if (options.target) {\n const err = new Error();\n // eslint-disable-next-line no-console\n console.warn('Imperative setTarget should not be used at the same time as target option');\n // eslint-disable-next-line no-console\n console.warn(err.stack);\n }\n\n setOverrideTarget(target);\n },\n }),\n [options.target, setOverrideTarget],\n );\n\n useIsomorphicLayoutEffect(() => {\n setOverrideTarget(options.target || null);\n }, [options.target, setOverrideTarget]);\n\n useIsomorphicLayoutEffect(() => {\n updatePositionManager();\n }, [updatePositionManager]);\n\n if (process.env.NODE_ENV !== 'production') {\n // This checked should run only in development mode\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (elementsRef.current.container) {\n const contentNode = elementsRef.current.container;\n const treeWalker = contentNode.ownerDocument?.createTreeWalker(contentNode, NodeFilter.SHOW_ELEMENT, {\n acceptNode: hasAutofocusFilter,\n });\n\n while (treeWalker.nextNode()) {\n const node = treeWalker.currentNode;\n // eslint-disable-next-line no-console\n console.warn('usePositioning():', node);\n // eslint-disable-next-line no-console\n console.warn(\n [\n 'usePositioning(): ^ this node contains \"autoFocus\" prop on a React element. This can break the initial',\n 'positioning of an element and cause a window jump effect. This issue occurs because React polyfills',\n '\"autoFocus\" behavior to solve inconsistencies between different browsers:',\n 'https://github.com/facebook/react/issues/11851#issuecomment-351787078',\n '\\n',\n 'However, \".focus()\" in this case occurs before any other React effects will be executed',\n '(React.useEffect(), componentDidMount(), etc.) and we can not prevent this behavior. If you really',\n 'want to use \"autoFocus\" please add \"position: fixed\" to styles of the element that is wrapped by',\n '\"Popper\".',\n `In general, it's not recommended to use \"autoFocus\" as it may break accessibility aspects:`,\n 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-autofocus.md',\n '\\n',\n 'We suggest to use the \"trapFocus\" prop on Fluent components or a catch \"ref\" and then use',\n '\"ref.current.focus\" in React.useEffect():',\n 'https://reactjs.org/docs/refs-and-the-dom.html#adding-a-ref-to-a-dom-element',\n ].join(' '),\n );\n }\n }\n // We run this check once, no need to add deps here\n // TODO: Should be rework to handle options.enabled and contentRef updates\n }, []);\n }\n\n // Callback refs only fire when their value changes\n const targetRef = useCallbackRef<TargetElement>(null, target => {\n elementsRef.current.target = target;\n updatePositionManager();\n });\n\n const onPositioningEnd = useEventCallback(\n (e: OnPositioningEndEvent) => options.onPositioningEnd && options.onPositioningEnd(e),\n );\n const containerRef = useCallbackRef<HTMLElement>(null, (container, previousContainer) => {\n // Cast because CustomEvent<OnPositioningEndEventDetail> is not assignable to EventListener\n if (previousContainer) {\n previousContainer.removeEventListener(POSITIONING_END_EVENT, onPositioningEnd as EventListener);\n }\n if (container) {\n container.addEventListener(POSITIONING_END_EVENT, onPositioningEnd as EventListener);\n }\n elementsRef.current.container = container;\n updatePositionManager();\n });\n\n const arrowRef = useCallbackRef<HTMLElement>(null, arrow => {\n elementsRef.current.arrow = arrow;\n updatePositionManager();\n });\n\n // Let users use callback refs so they feel like 'normal' DOM refs\n return { targetRef, containerRef, arrowRef };\n}\n"],"names":["useEventCallback","useIsomorphicLayoutEffect","React","POSITIONING_END_EVENT","createPositionManager","usePositioningOptions","useCallbackRef","hasAutofocusFilter","usePositioning","options","managerRef","useRef","elementsRef","enabled","resolvePositioningOptions","updatePositionManager","useCallback","current","dispose","override","target","container","arrow","positioningTarget","setOverrideTarget","useImperativeHandle","positioningRef","updatePosition","setTarget","process","env","NODE_ENV","err","Error","console","warn","stack","useEffect","contentNode","treeWalker","ownerDocument","createTreeWalker","NodeFilter","SHOW_ELEMENT","acceptNode","nextNode","node","currentNode","join","targetRef","onPositioningEnd","e","containerRef","previousContainer","removeEventListener","addEventListener","arrowRef"],"mappings":"AAAA;AAEA,SAASA,gBAAgB,EAAEC,yBAAyB,QAAQ,4BAA4B;AACxF,YAAYC,WAAW,QAAQ;AAE/B,SAASC,qBAAqB,QAAQ,iBAAc;AACpD,SAASC,qBAAqB,QAAQ,6BAA0B;AAShE,SAASC,qBAAqB,QAAQ,6BAA0B;AAChE,SAASC,cAAc,EAAEC,kBAAkB,QAAQ,mBAAU;AAE7D;;CAEC,GACD,OAAO,SAASC,eAAeC,OAA8C;IAC3E,MAAMC,aAAaR,MAAMS,MAAM,CAAyB;IACxD,2EAA2E;IAC3E,MAAMC,cAAcV,MAAMS,MAAM,CAK9B,CAAC;IAEH,MAAM,EAAEE,UAAU,IAAI,EAAE,GAAGJ;IAC3B,MAAMK,4BAA4BT,sBAAsBI;IACxD,MAAMM,wBAAwBb,MAAMc,WAAW,CAAC;QAC9C,IAAIN,WAAWO,OAAO,EAAE;YACtBP,WAAWO,OAAO,CAACC,OAAO;QAC5B;QACAR,WAAWO,OAAO,GAAG;QAErB,MAAM,EAAEE,QAAQ,EAAEC,MAAM,EAAEC,SAAS,EAAEC,QAAQ,IAAI,EAAE,GAAGV,YAAYK,OAAO;QACzE,MAAMM,oBAAoBJ,YAAYC;QAEtC,uEAAuE;QACvE,IAAIP,WAAWU,qBAAqBF,WAAW;YAC7CX,WAAWO,OAAO,GAAGb,sBAAsB;gBACzCiB;gBACAD,QAAQG;gBACRD;gBACA,GAAGR,0BAA0BO,WAAWC,MAAM;YAChD;QACF;IACF,GAAG;QAACT;QAASC;KAA0B;IAEv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