mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 01:31:35 +08:00
This reverts commits 0623ac684a65f95ce4f5438ff47944b1dc2119f4 408e71e437ef8abf98f93e3449898bf906766b0e a32fa3b9470dde0543fcee809f2abd1f219f7336 User tips were running into some issues.
This commit is contained in:
@ -1,93 +0,0 @@
|
||||
import {
|
||||
arrow,
|
||||
computePosition,
|
||||
flip,
|
||||
inline,
|
||||
offset,
|
||||
shift,
|
||||
} from "@floating-ui/dom";
|
||||
import { FLOAT_UI_PLACEMENTS } from "float-kit/lib/constants";
|
||||
import { isTesting } from "discourse-common/config/environment";
|
||||
import { headerOffset } from "discourse/lib/offset-calculator";
|
||||
import { iconHTML } from "discourse-common/lib/icon-library";
|
||||
import domFromString from "discourse-common/lib/dom-from-string";
|
||||
|
||||
export async function updatePosition(trigger, content, options) {
|
||||
let padding = 0;
|
||||
if (!isTesting()) {
|
||||
padding = options.padding || {
|
||||
top: headerOffset(),
|
||||
left: 10,
|
||||
right: 10,
|
||||
bottom: 10,
|
||||
};
|
||||
}
|
||||
|
||||
const flipOptions = {
|
||||
fallbackPlacements: options.fallbackPlacements ?? FLOAT_UI_PLACEMENTS,
|
||||
padding,
|
||||
};
|
||||
|
||||
const middleware = [
|
||||
offset(options.offset ? parseInt(options.offset, 10) : 10),
|
||||
];
|
||||
|
||||
if (options.inline) {
|
||||
middleware.push(inline());
|
||||
}
|
||||
|
||||
middleware.push(flip(flipOptions));
|
||||
middleware.push(shift({ padding }));
|
||||
|
||||
let arrowElement;
|
||||
if (options.arrow) {
|
||||
arrowElement = content.querySelector(".arrow");
|
||||
|
||||
if (!arrowElement) {
|
||||
arrowElement = domFromString(
|
||||
iconHTML("tippy-rounded-arrow", { class: "arrow" })
|
||||
)[0];
|
||||
content.appendChild(arrowElement);
|
||||
}
|
||||
|
||||
middleware.push(arrow({ element: arrowElement }));
|
||||
}
|
||||
|
||||
content.dataset.strategy = options.strategy || "absolute";
|
||||
|
||||
const { x, y, placement, middlewareData } = await computePosition(
|
||||
trigger,
|
||||
content,
|
||||
{
|
||||
placement: options.placement,
|
||||
strategy: options.strategy || "absolute",
|
||||
middleware,
|
||||
}
|
||||
);
|
||||
|
||||
if (options.computePosition) {
|
||||
options.computePosition(content, {
|
||||
x,
|
||||
y,
|
||||
placement,
|
||||
middlewareData,
|
||||
arrowElement,
|
||||
});
|
||||
} else {
|
||||
content.dataset.placement = placement;
|
||||
Object.assign(content.style, {
|
||||
left: `${x}px`,
|
||||
top: `${y}px`,
|
||||
});
|
||||
|
||||
if (middlewareData.arrow && arrowElement) {
|
||||
const arrowX = middlewareData.arrow.x;
|
||||
const arrowY = middlewareData.arrow.y;
|
||||
|
||||
Object.assign(arrowElement.style, {
|
||||
left: arrowX != null ? `${arrowX}px` : "",
|
||||
top: arrowY != null ? `${arrowY}px` : "",
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user