refactor(editor): group and expose parameters of createButtonPopper (#10999)

This commit is contained in:
L-Sun
2025-03-20 08:37:59 +00:00
parent 6ff19ca307
commit da63d51b7e
8 changed files with 76 additions and 81 deletions

View File

@@ -32,6 +32,17 @@ export function listenClickAway(
type Display = 'show' | 'hidden';
const ATTR_SHOW = 'data-show';
export type ButtonPopperOptions = {
reference: HTMLElement;
popperElement: HTMLElement;
stateUpdated?: (state: { display: Display }) => void;
mainAxis?: number;
crossAxis?: number;
rootBoundary?: Rect | (() => Rect | undefined);
ignoreShift?: boolean;
offsetHeight?: number;
};
/**
* Using attribute 'data-show' to control popper visibility.
*
@@ -44,28 +55,19 @@ const ATTR_SHOW = 'data-show';
* }
* ```
*/
export function createButtonPopper(
reference: HTMLElement,
popperElement: HTMLElement,
stateUpdated: (state: { display: Display }) => void = () => {
/** DEFAULT EMPTY FUNCTION */
},
{
export function createButtonPopper(options: ButtonPopperOptions) {
let display: Display = 'hidden';
let cleanup: (() => void) | void;
const {
reference,
popperElement,
stateUpdated = () => {},
mainAxis,
crossAxis,
rootBoundary,
ignoreShift,
offsetHeight,
}: {
mainAxis?: number;
crossAxis?: number;
rootBoundary?: Rect | (() => Rect | undefined);
ignoreShift?: boolean;
offsetHeight?: number;
} = {}
) {
let display: Display = 'hidden';
let cleanup: (() => void) | void;
} = options;
const originMaxHeight = window.getComputedStyle(popperElement).maxHeight;