2022-10-06 21:07:47 +08:00
|
|
|
import {getEventName} from "../../protyle/util/compatibility";
|
|
|
|
|
import {listIndent, listOutdent} from "../../protyle/wysiwyg/list";
|
|
|
|
|
import {hasClosestBlock, hasClosestByMatchTag} from "../../protyle/util/hasClosest";
|
|
|
|
|
|
2022-10-06 17:14:04 +08:00
|
|
|
export const showKeyboardToolbar = (bottom = 0) => {
|
|
|
|
|
const toolbarElement = document.getElementById("keyboardToolbar");
|
|
|
|
|
toolbarElement.classList.remove("fn__none");
|
|
|
|
|
toolbarElement.style.bottom = bottom + "px";
|
2022-10-06 21:08:32 +08:00
|
|
|
};
|
2022-10-06 17:30:43 +08:00
|
|
|
|
|
|
|
|
export const hideKeyboardToolbar = () => {
|
|
|
|
|
const toolbarElement = document.getElementById("keyboardToolbar");
|
|
|
|
|
toolbarElement.classList.add("fn__none");
|
2022-10-06 21:08:32 +08:00
|
|
|
};
|
2022-10-06 17:30:43 +08:00
|
|
|
|
|
|
|
|
export const initKeyboardToolbar = () => {
|
|
|
|
|
const toolbarElement = document.getElementById("keyboardToolbar");
|
2022-10-06 21:07:47 +08:00
|
|
|
toolbarElement.addEventListener(getEventName(), (event) => {
|
2022-10-06 21:08:32 +08:00
|
|
|
const target = event.target as HTMLElement;
|
|
|
|
|
const buttonElement = hasClosestByMatchTag(target, "BUTTON");
|
2022-10-06 21:07:47 +08:00
|
|
|
if (!buttonElement || !window.siyuan.mobileEditor) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const type = buttonElement.getAttribute("data-type");
|
2022-10-06 21:08:32 +08:00
|
|
|
const protyle = window.siyuan.mobileEditor.protyle;
|
2022-10-06 21:07:47 +08:00
|
|
|
if (type === "undo") {
|
2022-10-06 21:08:32 +08:00
|
|
|
protyle.undo.undo(protyle);
|
2022-10-06 21:07:47 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (type === "redo") {
|
2022-10-06 21:08:32 +08:00
|
|
|
protyle.undo.redo(protyle);
|
2022-10-06 21:07:47 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2022-10-06 21:08:32 +08:00
|
|
|
let range: Range;
|
2022-10-06 21:07:47 +08:00
|
|
|
if (getSelection().rangeCount > 0) {
|
2022-10-06 21:08:32 +08:00
|
|
|
range = getSelection().getRangeAt(0);
|
2022-10-06 21:07:47 +08:00
|
|
|
}
|
|
|
|
|
if (!range) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const nodeElement = hasClosestBlock(range.startContainer);
|
|
|
|
|
if (!nodeElement) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!nodeElement.parentElement.classList.contains("li") || nodeElement.getAttribute("data-type") === "NodeCodeBlock") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (type === "outdent") {
|
|
|
|
|
listOutdent(protyle, [nodeElement.parentElement], range);
|
|
|
|
|
} else if (type === "indent") {
|
|
|
|
|
listIndent(protyle, [nodeElement.parentElement], range);
|
2022-10-06 20:39:43 +08:00
|
|
|
}
|
2022-10-06 21:08:32 +08:00
|
|
|
});
|
|
|
|
|
};
|