Fix Floating Ui error causing freezes on image resize (#2206)
* Replace autoPlacement with flip * Remove logic made redundant by use of flip() * Edit preferred placement on components using WithFloating * Rename placement to preferredPlacement * Set "bottom" as default placement and remove redundant declarations
This commit is contained in:
parent
ade2738458
commit
fba46e9815
@ -26,7 +26,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
|
|
||||||
<WithFloating
|
<WithFloating
|
||||||
show={showFloating}
|
show={showFloating}
|
||||||
placement="bottom"
|
|
||||||
offset={0}
|
offset={0}
|
||||||
shift={0}
|
shift={0}
|
||||||
hideArrow
|
hideArrow
|
||||||
|
@ -27,7 +27,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
|
|
||||||
export let portalTarget: HTMLElement | null = null;
|
export let portalTarget: HTMLElement | null = null;
|
||||||
|
|
||||||
export let placement: Placement | Placement[] | "auto" = "bottom";
|
let placement: Placement = "bottom";
|
||||||
|
export { placement as preferredPlacement };
|
||||||
export let offset = 5;
|
export let offset = 5;
|
||||||
/* 30px box shadow from elevation(8) */
|
/* 30px box shadow from elevation(8) */
|
||||||
export let shift = 30;
|
export let shift = 30;
|
||||||
|
@ -101,7 +101,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
<ButtonGroupItem>
|
<ButtonGroupItem>
|
||||||
<WithFloating
|
<WithFloating
|
||||||
show={showFloating && !disabled}
|
show={showFloating && !disabled}
|
||||||
placement="bottom"
|
|
||||||
inline
|
inline
|
||||||
on:close={() => (showFloating = false)}
|
on:close={() => (showFloating = false)}
|
||||||
let:asReference
|
let:asReference
|
||||||
|
@ -35,12 +35,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<WithFloating
|
<WithFloating show={showFloating} inline on:close={() => (showFloating = false)}>
|
||||||
show={showFloating}
|
|
||||||
placement="bottom"
|
|
||||||
inline
|
|
||||||
on:close={() => (showFloating = false)}
|
|
||||||
>
|
|
||||||
<IconButton
|
<IconButton
|
||||||
slot="reference"
|
slot="reference"
|
||||||
tooltip={tr.actionsOptions()}
|
tooltip={tr.actionsOptions()}
|
||||||
|
@ -116,7 +116,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
|
|
||||||
<WithFloating
|
<WithFloating
|
||||||
show={showFloating && !disabled}
|
show={showFloating && !disabled}
|
||||||
placement="bottom"
|
|
||||||
inline
|
inline
|
||||||
on:close={() => (showFloating = false)}
|
on:close={() => (showFloating = false)}
|
||||||
>
|
>
|
||||||
|
@ -266,7 +266,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
<WithOverlay reference={activeImage} inline let:position={positionOverlay}>
|
<WithOverlay reference={activeImage} inline let:position={positionOverlay}>
|
||||||
<WithFloating
|
<WithFloating
|
||||||
reference={activeImage}
|
reference={activeImage}
|
||||||
placement="auto"
|
|
||||||
offset={20}
|
offset={20}
|
||||||
inline
|
inline
|
||||||
hideIfReferenceHidden
|
hideIfReferenceHidden
|
||||||
|
@ -202,7 +202,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
>
|
>
|
||||||
<WithFloating
|
<WithFloating
|
||||||
reference={activeImage}
|
reference={activeImage}
|
||||||
placement="auto"
|
|
||||||
offset={20}
|
offset={20}
|
||||||
keepOnKeyup
|
keepOnKeyup
|
||||||
let:position={positionFloating}
|
let:position={positionFloating}
|
||||||
|
@ -380,11 +380,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
|
|
||||||
<div class="symbols-overlay">
|
<div class="symbols-overlay">
|
||||||
{#if referenceRange}
|
{#if referenceRange}
|
||||||
<WithFloating
|
<WithFloating reference={referenceRange} preferredPlacement="top" offset={10}>
|
||||||
reference={referenceRange}
|
|
||||||
placement={["top", "bottom"]}
|
|
||||||
offset={10}
|
|
||||||
>
|
|
||||||
<Popover slot="floating" --popover-padding-inline="0">
|
<Popover slot="floating" --popover-padding-inline="0">
|
||||||
<div class="symbols-menu">
|
<div class="symbols-menu">
|
||||||
{#each foundSymbols as found, index (found.symbol)}
|
{#each foundSymbols as found, index (found.symbol)}
|
||||||
|
@ -10,7 +10,6 @@ import type {
|
|||||||
} from "@floating-ui/dom";
|
} from "@floating-ui/dom";
|
||||||
import {
|
import {
|
||||||
arrow,
|
arrow,
|
||||||
autoPlacement,
|
|
||||||
computePosition,
|
computePosition,
|
||||||
flip,
|
flip,
|
||||||
hide,
|
hide,
|
||||||
@ -22,7 +21,7 @@ import {
|
|||||||
import type { PositionAlgorithm } from "./position-algorithm";
|
import type { PositionAlgorithm } from "./position-algorithm";
|
||||||
|
|
||||||
export interface PositionFloatingArgs {
|
export interface PositionFloatingArgs {
|
||||||
placement: Placement | Placement[] | "auto";
|
placement: Placement;
|
||||||
arrow: HTMLElement;
|
arrow: HTMLElement;
|
||||||
shift: number;
|
shift: number;
|
||||||
offset: number;
|
offset: number;
|
||||||
@ -47,7 +46,6 @@ function positionFloating({
|
|||||||
floating: FloatingElement,
|
floating: FloatingElement,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const middleware: Middleware[] = [
|
const middleware: Middleware[] = [
|
||||||
// the .shift() lines below expect flip() to be first
|
|
||||||
flip(),
|
flip(),
|
||||||
offset(offsetArg),
|
offset(offsetArg),
|
||||||
shift({ padding: shiftArg }),
|
shift({ padding: shiftArg }),
|
||||||
@ -60,20 +58,9 @@ function positionFloating({
|
|||||||
|
|
||||||
const computeArgs: Partial<ComputePositionConfig> = {
|
const computeArgs: Partial<ComputePositionConfig> = {
|
||||||
middleware,
|
middleware,
|
||||||
|
placement,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Array.isArray(placement)) {
|
|
||||||
const allowedPlacements = placement;
|
|
||||||
// flip() is incompatible with autoPlacement
|
|
||||||
middleware.shift();
|
|
||||||
middleware.push(autoPlacement({ allowedPlacements }));
|
|
||||||
} else if (placement === "auto") {
|
|
||||||
middleware.shift();
|
|
||||||
middleware.push(autoPlacement());
|
|
||||||
} else {
|
|
||||||
computeArgs.placement = placement;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hideIfEscaped) {
|
if (hideIfEscaped) {
|
||||||
middleware.push(hide({ strategy: "escaped" }));
|
middleware.push(hide({ strategy: "escaped" }));
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
<slot {selectMode} {hoverClass} />
|
<slot {selectMode} {hoverClass} />
|
||||||
</Tag>
|
</Tag>
|
||||||
{:else if shorten && hasMultipleParts(name)}
|
{:else if shorten && hasMultipleParts(name)}
|
||||||
<WithTooltip {tooltip} trigger="hover" placement="auto" let:createTooltip>
|
<WithTooltip {tooltip} trigger="hover" placement="top" let:createTooltip>
|
||||||
<Tag
|
<Tag
|
||||||
class={className}
|
class={className}
|
||||||
bind:flash
|
bind:flash
|
||||||
|
@ -127,7 +127,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
<WithFloating
|
<WithFloating
|
||||||
keepOnKeyup
|
keepOnKeyup
|
||||||
show={$show}
|
show={$show}
|
||||||
placement="top-start"
|
preferredPlacement="top-start"
|
||||||
portalTarget={document.body}
|
portalTarget={document.body}
|
||||||
let:asReference
|
let:asReference
|
||||||
on:close={() => show.set(false)}
|
on:close={() => show.set(false)}
|
||||||
|
@ -25,7 +25,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
|
|
||||||
<WithFloating
|
<WithFloating
|
||||||
{show}
|
{show}
|
||||||
placement="top"
|
preferredPlacement="top"
|
||||||
portalTarget={document.body}
|
portalTarget={document.body}
|
||||||
shift={0}
|
shift={0}
|
||||||
let:asReference
|
let:asReference
|
||||||
|
Loading…
Reference in New Issue
Block a user