UNPKG

@opentiny/fluent-editor

Version:

A rich text editor based on Quill 2.0, which extends rich modules and formats on the basis of Quill. It's powerful and out-of-the-box.

61 lines (60 loc) 2.23 kB
import { namespace } from "../config/index.es.js"; import { ICONS_CONFIG } from "../ui/icons.es.js"; import { lockScroll } from "../utils/scroll-lock.es.js"; let exitEscHandlerBindToolbar; let resizeHandlerBindToolbar; let cleanLock; let originScrollTop = 0; function exitEscHandler(toolbar, e) { if (e.code === "Escape") { exitFullscreen(toolbar); } } function updateToolbarHeight(toolbar) { const toolbarRect = toolbar.container.getBoundingClientRect(); toolbar.quill.container.style.setProperty(`--${namespace}-top`, `${toolbarRect.height}px`); } function intoFullscreen(toolbar) { toolbar.quill.isFullscreen = true; originScrollTop = document.documentElement.scrollTop; toolbar.container.classList.add("fullscreen"); toolbar.quill.container.classList.add("fullscreen"); cleanLock = lockScroll(); resizeHandlerBindToolbar(); const [, btn] = toolbar.controls.find((item) => item[0] === "fullscreen"); btn.innerHTML = ICONS_CONFIG["fullscreen-exit"]; window.addEventListener("resize", resizeHandlerBindToolbar); document.addEventListener("keydown", exitEscHandlerBindToolbar); const toolbarTipModule = toolbar.quill.getModule("toolbar-tip"); if (toolbarTipModule) { toolbarTipModule.hideAllTips(); } } function exitFullscreen(toolbar) { toolbar.quill.isFullscreen = false; toolbar.container.classList.remove("fullscreen"); toolbar.quill.container.classList.remove("fullscreen"); cleanLock(); document.documentElement.scrollTop = originScrollTop; const [, btn] = toolbar.controls.find((item) => item[0] === "fullscreen"); btn.innerHTML = ICONS_CONFIG.fullscreen; window.removeEventListener("resize", resizeHandlerBindToolbar); document.removeEventListener("keydown", exitEscHandlerBindToolbar); const toolbarTipModule = toolbar.quill.getModule("toolbar-tip"); if (toolbarTipModule) { toolbarTipModule.hideAllTips(); } } function fullscreenHandler() { if (this.quill.isFullscreen) { exitFullscreen(this); } else { exitEscHandlerBindToolbar = exitEscHandler.bind(void 0, this); resizeHandlerBindToolbar = updateToolbarHeight.bind(void 0, this); intoFullscreen(this); } } export { fullscreenHandler }; //# sourceMappingURL=fullscreen.es.js.map