import {tPopperHook} from "./createPopperHooks"; import {iAllRefs, iPlainPopperConfig, iShowHandler, iToggleHandler, iTriggerUser, plainAttrs} from "../utils/type.base"; import {DefaultTriggers} from "../triggers"; /** * 默认的初始化动作 * @author 韦胜健 * @date 2022/4/5 21:29 */ export function processInitialize({ hooks, config, refs, show, toggle }: { hooks: tPopperHook, config: iPlainPopperConfig, refs: iAllRefs, show: iShowHandler, toggle: iToggleHandler }) { hooks.onInitialize.use(({ refresh, refs, config }) => { Object.assign(refs.content.style, { backgroundColor: config.backgroundColor, color: config.color }); config.animation && refs.popper.setAttribute(plainAttrs.animation, config.animation); /*刷新位置,不启用transform优化定位*/ refresh(false); }); hooks.onDestroy.use(({ refs, config }) => { config.animation && refs.popper.removeAttribute(plainAttrs.animation); }); if (!!config.trigger) { const trigger: iTriggerUser = typeof config.trigger === "string" ? DefaultTriggers[config.trigger] : config.trigger; trigger({ refs, hooks, show, config, toggle }); } }