mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-23 01:50:12 +01:00
This commit is contained in:
parent
877e28570e
commit
1ccebe7079
4 changed files with 56 additions and 55 deletions
|
|
@ -58,6 +58,6 @@
|
||||||
<div id="commonMenu" class="b3-menu fn__none"></div>
|
<div id="commonMenu" class="b3-menu fn__none"></div>
|
||||||
<div id="message" class="b3-snackbars"></div>
|
<div id="message" class="b3-snackbars"></div>
|
||||||
<div id="status" class="status status--hide"></div>
|
<div id="status" class="status status--hide"></div>
|
||||||
<div id="keyboardToolbar" class="keyboard"></div>
|
<div id="keyboardToolbar" class="keyboard fn__none"></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import {hasTopClosestByTag} from "../../protyle/util/hasClosest";
|
||||||
import {MobileBacklinks} from "./MobileBacklinks";
|
import {MobileBacklinks} from "./MobileBacklinks";
|
||||||
import {MobileBookmarks} from "./MobileBookmarks";
|
import {MobileBookmarks} from "./MobileBookmarks";
|
||||||
import {MobileTags} from "./MobileTags";
|
import {MobileTags} from "./MobileTags";
|
||||||
import {hideKeyboard, hideKeyboardToolbar, initKeyboardToolbar} from "./keyboardToolbar";
|
import {activeBlur, hideKeyboardToolbar, initKeyboardToolbar} from "./keyboardToolbar";
|
||||||
import {getSearch} from "../../util/functions";
|
import {getSearch} from "../../util/functions";
|
||||||
import {syncGuide} from "../../sync/syncGuide";
|
import {syncGuide} from "../../sync/syncGuide";
|
||||||
|
|
||||||
|
|
@ -77,7 +77,7 @@ export const initFramework = () => {
|
||||||
window.siyuan.mobile.files = new MobileFiles();
|
window.siyuan.mobile.files = new MobileFiles();
|
||||||
document.getElementById("toolbarFile").addEventListener("click", () => {
|
document.getElementById("toolbarFile").addEventListener("click", () => {
|
||||||
hideKeyboardToolbar();
|
hideKeyboardToolbar();
|
||||||
hideKeyboard();
|
activeBlur();
|
||||||
sidebarElement.style.left = "0";
|
sidebarElement.style.left = "0";
|
||||||
document.querySelector(".scrim").classList.remove("fn__none");
|
document.querySelector(".scrim").classList.remove("fn__none");
|
||||||
const type = sidebarElement.querySelector(".toolbar--border .toolbar__icon--active").getAttribute("data-type");
|
const type = sidebarElement.querySelector(".toolbar--border .toolbar__icon--active").getAttribute("data-type");
|
||||||
|
|
|
||||||
|
|
@ -6,39 +6,22 @@ import {focusByRange, getSelectionPosition} from "../../protyle/util/selection";
|
||||||
import {removeBlock} from "../../protyle/wysiwyg/remove";
|
import {removeBlock} from "../../protyle/wysiwyg/remove";
|
||||||
import {hintSlash} from "../../protyle/hint/extend";
|
import {hintSlash} from "../../protyle/hint/extend";
|
||||||
|
|
||||||
export const showKeyboardToolbar = (height: number) => {
|
|
||||||
if (getSelection().rangeCount === 0 || window.siyuan.config.editor.readOnly || window.siyuan.config.readonly) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const toolbarElement = document.getElementById("keyboardToolbar");
|
|
||||||
toolbarElement.setAttribute("data-keyboardheight", height.toString())
|
|
||||||
hideKeyboardToolbarUtil();
|
|
||||||
if (!toolbarElement.classList.contains("fn__none")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
toolbarElement.classList.remove("fn__none");
|
|
||||||
const range = getSelection().getRangeAt(0);
|
|
||||||
if (!window.siyuan.mobile.editor ||
|
|
||||||
!window.siyuan.mobile.editor.protyle.wysiwyg.element.contains(range.startContainer)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setTimeout(() => {
|
|
||||||
const contentElement = window.siyuan.mobile.editor.protyle.contentElement;
|
|
||||||
const cursorTop = getSelectionPosition(contentElement).top - contentElement.getBoundingClientRect().top;
|
|
||||||
if (cursorTop < window.innerHeight - 96) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
contentElement.scroll({
|
|
||||||
top: contentElement.scrollTop + cursorTop - ((window.outerHeight - 65) / 2 - 30),
|
|
||||||
left: contentElement.scrollLeft,
|
|
||||||
behavior: "smooth"
|
|
||||||
});
|
|
||||||
}, Constants.TIMEOUT_TRANSITION);
|
|
||||||
};
|
|
||||||
|
|
||||||
let renderKeyboardToolbarTimeout: number;
|
let renderKeyboardToolbarTimeout: number;
|
||||||
let showKeyboardToolbarUtil = false;
|
let showKeyboardToolbarUtil = false;
|
||||||
export const renderKeyboardToolbar = () => {
|
|
||||||
|
const renderKeyboardToolbarUtil = () => {
|
||||||
|
const toolbarElement = document.getElementById("keyboardToolbar");
|
||||||
|
const keyboardHeight = (parseInt(toolbarElement.getAttribute("data-keyboardheight")) + 42) + "px"
|
||||||
|
toolbarElement.style.height = keyboardHeight
|
||||||
|
window.siyuan.mobile.editor.protyle.element.style.marginBottom = keyboardHeight
|
||||||
|
window.siyuan.menus.menu.remove();
|
||||||
|
showKeyboardToolbarUtil = true;
|
||||||
|
setTimeout(() => {
|
||||||
|
showKeyboardToolbarUtil = false
|
||||||
|
}, 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
const renderKeyboardToolbar = () => {
|
||||||
clearTimeout(renderKeyboardToolbarTimeout);
|
clearTimeout(renderKeyboardToolbarTimeout);
|
||||||
renderKeyboardToolbarTimeout = window.setTimeout(() => {
|
renderKeyboardToolbarTimeout = window.setTimeout(() => {
|
||||||
if (getSelection().rangeCount === 0 || window.siyuan.config.editor.readOnly || window.siyuan.config.readonly) {
|
if (getSelection().rangeCount === 0 || window.siyuan.config.editor.readOnly || window.siyuan.config.readonly) {
|
||||||
|
|
@ -91,6 +74,41 @@ export const renderKeyboardToolbar = () => {
|
||||||
}, 620); // 需等待 range 更新
|
}, 620); // 需等待 range 更新
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const hideKeyboardToolbarUtil = () => {
|
||||||
|
document.getElementById("keyboardToolbar").style.height = ""
|
||||||
|
window.siyuan.mobile.editor.protyle.element.style.marginBottom = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
export const showKeyboardToolbar = (height: number) => {
|
||||||
|
if (getSelection().rangeCount === 0 || window.siyuan.config.editor.readOnly || window.siyuan.config.readonly) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const toolbarElement = document.getElementById("keyboardToolbar");
|
||||||
|
toolbarElement.setAttribute("data-keyboardheight", height.toString())
|
||||||
|
hideKeyboardToolbarUtil();
|
||||||
|
if (!toolbarElement.classList.contains("fn__none")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
toolbarElement.classList.remove("fn__none");
|
||||||
|
const range = getSelection().getRangeAt(0);
|
||||||
|
if (!window.siyuan.mobile.editor ||
|
||||||
|
!window.siyuan.mobile.editor.protyle.wysiwyg.element.contains(range.startContainer)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setTimeout(() => {
|
||||||
|
const contentElement = window.siyuan.mobile.editor.protyle.contentElement;
|
||||||
|
const cursorTop = getSelectionPosition(contentElement).top - contentElement.getBoundingClientRect().top;
|
||||||
|
if (cursorTop < window.innerHeight - 96) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
contentElement.scroll({
|
||||||
|
top: contentElement.scrollTop + cursorTop - ((window.outerHeight - 65) / 2 - 30),
|
||||||
|
left: contentElement.scrollLeft,
|
||||||
|
behavior: "smooth"
|
||||||
|
});
|
||||||
|
}, Constants.TIMEOUT_TRANSITION);
|
||||||
|
};
|
||||||
|
|
||||||
export const hideKeyboardToolbar = () => {
|
export const hideKeyboardToolbar = () => {
|
||||||
if (showKeyboardToolbarUtil) {
|
if (showKeyboardToolbarUtil) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -99,27 +117,10 @@ export const hideKeyboardToolbar = () => {
|
||||||
toolbarElement.classList.add("fn__none");
|
toolbarElement.classList.add("fn__none");
|
||||||
};
|
};
|
||||||
|
|
||||||
export const hideKeyboard = () => {
|
export const activeBlur = () => {
|
||||||
(document.activeElement as HTMLElement).blur();
|
(document.activeElement as HTMLElement).blur();
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderKeyboardToolbarUtil = () => {
|
|
||||||
const toolbarElement = document.getElementById("keyboardToolbar");
|
|
||||||
const keyboardHeight = (parseInt(toolbarElement.getAttribute("data-keyboardheight")) + 42) + "px"
|
|
||||||
toolbarElement.style.height = keyboardHeight
|
|
||||||
window.siyuan.mobile.editor.protyle.element.style.marginBottom = keyboardHeight
|
|
||||||
window.siyuan.menus.menu.remove();
|
|
||||||
showKeyboardToolbarUtil = true;
|
|
||||||
setTimeout(() => {
|
|
||||||
showKeyboardToolbarUtil = false
|
|
||||||
}, 1000)
|
|
||||||
}
|
|
||||||
|
|
||||||
const hideKeyboardToolbarUtil = () => {
|
|
||||||
document.getElementById("keyboardToolbar").style.height = ""
|
|
||||||
window.siyuan.mobile.editor.protyle.element.style.marginBottom = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
export const initKeyboardToolbar = () => {
|
export const initKeyboardToolbar = () => {
|
||||||
document.addEventListener("selectionchange", () => {
|
document.addEventListener("selectionchange", () => {
|
||||||
renderKeyboardToolbar();
|
renderKeyboardToolbar();
|
||||||
|
|
@ -179,7 +180,7 @@ export const initKeyboardToolbar = () => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
const type = buttonElement.getAttribute("data-type");
|
const type = buttonElement.getAttribute("data-type");
|
||||||
if (type === "done") {
|
if (type === "done") {
|
||||||
hideKeyboard();
|
activeBlur();
|
||||||
hideKeyboardToolbar();
|
hideKeyboardToolbar();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import {Dialog} from "../../dialog";
|
||||||
import {syncGuide} from "../../sync/syncGuide";
|
import {syncGuide} from "../../sync/syncGuide";
|
||||||
import {openCard} from "../../card/openCard";
|
import {openCard} from "../../card/openCard";
|
||||||
import {pathPosix} from "../../util/pathName";
|
import {pathPosix} from "../../util/pathName";
|
||||||
import {hideKeyboard, hideKeyboardToolbar} from "./keyboardToolbar";
|
import {activeBlur, hideKeyboardToolbar} from "./keyboardToolbar";
|
||||||
|
|
||||||
const showAccountInfo = (modelElement: HTMLElement, modelMainElement: Element) => {
|
const showAccountInfo = (modelElement: HTMLElement, modelMainElement: Element) => {
|
||||||
closePanel();
|
closePanel();
|
||||||
|
|
@ -115,7 +115,7 @@ const genWorkspace = (workspaceDirElement: Element) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
export const popMenu = () => {
|
export const popMenu = () => {
|
||||||
hideKeyboard();
|
activeBlur();
|
||||||
hideKeyboardToolbar();
|
hideKeyboardToolbar();
|
||||||
const modelElement = document.getElementById("model");
|
const modelElement = document.getElementById("model");
|
||||||
const modelMainElement = document.getElementById("modelMain");
|
const modelMainElement = document.getElementById("modelMain");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue