@cairn214/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.
62 lines (61 loc) • 2.45 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const index = require("../config/index.cjs.js");
require("../toolbar/index.cjs.js");
const scrollLock = require("../utils/scroll-lock.cjs.js");
const toolbarTip = require("../toolbar/toolbar-tip.cjs.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(`--${index.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 = scrollLock.lockScroll();
resizeHandlerBindToolbar();
const [, btn] = toolbar.controls.find((item) => item[0] === "fullscreen");
btn.innerHTML = index.ICONS_CONFIG["fullscreen-exit"];
window.addEventListener("resize", resizeHandlerBindToolbar);
document.addEventListener("keydown", exitEscHandlerBindToolbar);
const toolbarTipModule = toolbar.quill.getModule(toolbarTip.ToolbarTip.moduleName);
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 = index.ICONS_CONFIG.fullscreen;
window.removeEventListener("resize", resizeHandlerBindToolbar);
document.removeEventListener("keydown", exitEscHandlerBindToolbar);
const toolbarTipModule = toolbar.quill.getModule(toolbarTip.ToolbarTip.moduleName);
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);
}
}
exports.fullscreenHandler = fullscreenHandler;
//# sourceMappingURL=handler.cjs.js.map
;