2022-05-26 15:18:53 +08:00
|
|
|
|
import {lockFile} from "../../dialog/processSystem";
|
|
|
|
|
import {Constants} from "../../constants";
|
|
|
|
|
import {hideElements} from "../ui/hideElements";
|
|
|
|
|
import {genEmptyElement} from "../../block/util";
|
|
|
|
|
import {transaction} from "../wysiwyg/transaction";
|
|
|
|
|
import {fetchPost} from "../../util/fetch";
|
|
|
|
|
import {processRender} from "./processCode";
|
|
|
|
|
import {highlightRender} from "../markdown/highlightRender";
|
|
|
|
|
import {blockRender} from "../markdown/blockRender";
|
2022-06-07 15:01:40 +08:00
|
|
|
|
import {highlightById} from "../../util/highlightById";
|
2022-06-29 20:25:30 +08:00
|
|
|
|
/// #if !MOBILE
|
2022-05-26 15:18:53 +08:00
|
|
|
|
import {pushBack} from "../../util/backForward";
|
2022-06-29 20:25:30 +08:00
|
|
|
|
/// #endif
|
2022-05-26 15:18:53 +08:00
|
|
|
|
import {focusBlock} from "./selection";
|
|
|
|
|
import {hasClosestByAttribute, hasClosestByClassName} from "./hasClosest";
|
|
|
|
|
import {preventScroll} from "../scroll/preventScroll";
|
2022-08-07 17:56:07 +08:00
|
|
|
|
import {restoreScroll} from "../scroll/saveScroll";
|
2022-08-29 10:32:54 +08:00
|
|
|
|
import {removeLoading} from "../ui/initUI";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
|
2022-08-07 21:58:41 +08:00
|
|
|
|
export const onGet = (data: IWebSocketData, protyle: IProtyle, action: string[] = [], scrollAttr?: IScrollAttr, renderTitle = false) => {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle.wysiwyg.element.removeAttribute("data-top");
|
|
|
|
|
if (data.code === 1) {
|
|
|
|
|
// 其他报错
|
|
|
|
|
if (protyle.model) {
|
2022-08-10 11:24:12 +08:00
|
|
|
|
protyle.model.parent.parent.removeTab(protyle.model.parent.id, false, false);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
|
|
|
|
protyle.element.innerHTML = `<div class="ft__smaller ft__secondary b3-form__space--small" contenteditable="false">${window.siyuan.languages.refExpired}</div>`;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (data.code === 3) {
|
|
|
|
|
// block not found
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
protyle.notebookId = data.data.box;
|
|
|
|
|
protyle.path = data.data.path;
|
|
|
|
|
if (data.code === 2) {
|
|
|
|
|
// 文件被锁定
|
|
|
|
|
protyle.block.rootID = data.data;
|
|
|
|
|
lockFile(data.data);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data.data.eof) {
|
|
|
|
|
if (action.includes(Constants.CB_GET_BEFORE)) {
|
|
|
|
|
protyle.wysiwyg.element.firstElementChild.setAttribute("data-eof", "true");
|
|
|
|
|
} else {
|
|
|
|
|
protyle.wysiwyg.element.lastElementChild.setAttribute("data-eof", "true");
|
|
|
|
|
}
|
|
|
|
|
if (data.data.mode !== 4) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
hideElements(["gutter"], protyle);
|
|
|
|
|
let html = data.data.content;
|
|
|
|
|
if (html === "" && !action) {
|
|
|
|
|
const element = genEmptyElement(false, false);
|
|
|
|
|
html = element.outerHTML;
|
|
|
|
|
transaction(protyle, [{
|
|
|
|
|
action: "insert",
|
|
|
|
|
id: element.getAttribute("data-node-id"),
|
|
|
|
|
data: html,
|
|
|
|
|
parentID: data.data.parentID
|
|
|
|
|
}]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protyle.block.parentID = data.data.parentID;
|
|
|
|
|
protyle.block.parent2ID = data.data.parent2ID;
|
|
|
|
|
protyle.block.rootID = data.data.rootID;
|
|
|
|
|
protyle.block.showAll = false;
|
|
|
|
|
protyle.block.mode = data.data.mode;
|
|
|
|
|
protyle.block.blockCount = data.data.blockCount;
|
2022-09-03 12:53:41 +08:00
|
|
|
|
protyle.block.childBlockCount = data.data.childBlockCount;
|
2022-08-23 11:55:40 +08:00
|
|
|
|
protyle.block.action = action;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (!action.includes(Constants.CB_GET_UNCHANGEID)) {
|
|
|
|
|
protyle.block.id = data.data.id;
|
|
|
|
|
protyle.scroll.lastScrollTop = 0;
|
|
|
|
|
protyle.contentElement.scrollTop = 0;
|
|
|
|
|
protyle.wysiwyg.element.setAttribute("data-doc-type", data.data.type);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-08 17:57:52 +08:00
|
|
|
|
// 防止动态加载加载过多的内容
|
2022-08-12 19:25:07 +08:00
|
|
|
|
if (action.includes(Constants.CB_GET_APPEND) || action.includes(Constants.CB_GET_BEFORE) || action.includes(Constants.CB_GET_HTML)) {
|
2022-08-08 11:36:51 +08:00
|
|
|
|
setHTML({
|
|
|
|
|
content: html,
|
|
|
|
|
action,
|
|
|
|
|
unScroll: false,
|
2022-10-22 12:06:59 +08:00
|
|
|
|
isSyncing: data.data.isSyncing,
|
2022-08-08 11:36:51 +08:00
|
|
|
|
}, protyle);
|
2022-08-29 10:32:54 +08:00
|
|
|
|
removeLoading(protyle);
|
2022-08-08 11:36:51 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-07 21:58:41 +08:00
|
|
|
|
fetchPost("/api/block/getDocInfo", {
|
|
|
|
|
id: protyle.block.rootID
|
|
|
|
|
}, (response) => {
|
|
|
|
|
if (protyle.options.render.title) {
|
|
|
|
|
// 页签没有打开
|
|
|
|
|
protyle.title.render(protyle, response, renderTitle);
|
|
|
|
|
} else if (protyle.options.render.background) {
|
2022-09-01 22:20:43 +08:00
|
|
|
|
protyle.background.render(response.data.ial, protyle.block.rootID);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle.wysiwyg.renderCustom(response.data.ial);
|
2022-08-07 21:58:41 +08:00
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
|
2022-08-07 21:58:41 +08:00
|
|
|
|
let scrollObj = scrollAttr;
|
|
|
|
|
if (!scrollObj) {
|
|
|
|
|
if (action.includes(Constants.CB_GET_SCROLL) && response.data.ial.scroll) {
|
|
|
|
|
try {
|
2022-08-08 11:36:51 +08:00
|
|
|
|
scrollObj = JSON.parse(response.data.ial.scroll.replace(/"/g, '"'));
|
2022-08-07 21:58:41 +08:00
|
|
|
|
} catch (e) {
|
|
|
|
|
scrollObj = undefined;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-07 17:56:07 +08:00
|
|
|
|
|
2022-08-07 21:58:41 +08:00
|
|
|
|
setHTML({
|
|
|
|
|
content: html,
|
|
|
|
|
action,
|
|
|
|
|
unScroll: (scrollObj && scrollObj.focusId) ? true : false,
|
2022-10-22 12:06:59 +08:00
|
|
|
|
isSyncing: data.data.isSyncing,
|
2022-08-07 21:58:41 +08:00
|
|
|
|
}, protyle);
|
|
|
|
|
|
2022-08-26 22:12:45 +08:00
|
|
|
|
if (scrollObj && protyle.options.mode !== "preview") {
|
2022-08-07 21:58:41 +08:00
|
|
|
|
restoreScroll(protyle, scrollObj);
|
|
|
|
|
}
|
2022-08-29 21:20:28 +08:00
|
|
|
|
removeLoading(protyle);
|
2022-08-07 21:58:41 +08:00
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
|
};
|
|
|
|
|
|
2022-10-22 12:06:59 +08:00
|
|
|
|
const setHTML = (options: {
|
|
|
|
|
content: string,
|
|
|
|
|
action?: string[],
|
|
|
|
|
isSyncing: boolean,
|
2022-10-22 12:12:38 +08:00
|
|
|
|
unScroll?: boolean
|
|
|
|
|
}, protyle: IProtyle) => {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (protyle.contentElement.classList.contains("fn__none")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
protyle.block.showAll = options.action.includes(Constants.CB_GET_ALL);
|
2022-06-25 22:55:56 +08:00
|
|
|
|
const REMOVED_OVER_HEIGHT = protyle.contentElement.clientHeight * 8;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (options.action.includes(Constants.CB_GET_APPEND)) {
|
2022-06-24 10:59:23 +08:00
|
|
|
|
// 动态加载移除
|
2022-07-07 23:10:48 +08:00
|
|
|
|
if (!protyle.wysiwyg.element.querySelector(".protyle-wysiwyg--select") && !protyle.scroll.keepLazyLoad && protyle.contentElement.scrollHeight > REMOVED_OVER_HEIGHT) {
|
2022-06-24 10:59:23 +08:00
|
|
|
|
let removeElement = protyle.wysiwyg.element.firstElementChild as HTMLElement;
|
|
|
|
|
const removeElements = [];
|
2022-07-17 11:29:45 +08:00
|
|
|
|
while (protyle.wysiwyg.element.childElementCount > 2 && removeElements && !protyle.wysiwyg.element.lastElementChild.isSameNode(removeElement)) {
|
2022-06-24 10:59:23 +08:00
|
|
|
|
if (protyle.contentElement.scrollHeight - removeElement.offsetTop > REMOVED_OVER_HEIGHT) {
|
|
|
|
|
removeElements.push(removeElement);
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
removeElement = removeElement.nextElementSibling as HTMLElement;
|
|
|
|
|
}
|
|
|
|
|
const lastRemoveTop = removeElement.getBoundingClientRect().top;
|
|
|
|
|
removeElements.forEach(item => {
|
|
|
|
|
item.remove();
|
|
|
|
|
});
|
|
|
|
|
protyle.contentElement.scrollTop = protyle.contentElement.scrollTop + (removeElement.getBoundingClientRect().top - lastRemoveTop);
|
2022-07-12 16:35:46 +08:00
|
|
|
|
protyle.scroll.lastScrollTop = protyle.contentElement.scrollTop;
|
2022-08-03 18:08:28 +08:00
|
|
|
|
hideElements(["toolbar"], protyle);
|
2022-06-24 10:59:23 +08:00
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle.wysiwyg.element.insertAdjacentHTML("beforeend", options.content);
|
|
|
|
|
} else if (options.action.includes(Constants.CB_GET_BEFORE)) {
|
|
|
|
|
const lastElement = protyle.wysiwyg.element.firstElementChild as HTMLElement;
|
2022-06-24 10:59:23 +08:00
|
|
|
|
const lastTop = lastElement.getBoundingClientRect().top;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle.wysiwyg.element.insertAdjacentHTML("afterbegin", options.content);
|
2022-06-24 10:59:23 +08:00
|
|
|
|
protyle.contentElement.scrollTop = protyle.contentElement.scrollTop + (lastElement.getBoundingClientRect().top - lastTop);
|
2022-07-12 16:35:46 +08:00
|
|
|
|
protyle.scroll.lastScrollTop = protyle.contentElement.scrollTop;
|
2022-06-24 10:59:23 +08:00
|
|
|
|
// 动态加载移除
|
2022-07-07 23:10:48 +08:00
|
|
|
|
if (!protyle.wysiwyg.element.querySelector(".protyle-wysiwyg--select") && !protyle.scroll.keepLazyLoad) {
|
|
|
|
|
while (protyle.wysiwyg.element.childElementCount > 2 && protyle.contentElement.scrollHeight > REMOVED_OVER_HEIGHT &&
|
|
|
|
|
protyle.wysiwyg.element.lastElementChild.getBoundingClientRect().top > window.innerHeight) {
|
|
|
|
|
protyle.wysiwyg.element.lastElementChild.remove();
|
|
|
|
|
}
|
2022-08-03 18:08:28 +08:00
|
|
|
|
hideElements(["toolbar"], protyle);
|
2022-06-24 10:59:23 +08:00
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
|
|
|
|
protyle.wysiwyg.element.innerHTML = options.content;
|
|
|
|
|
}
|
|
|
|
|
processRender(protyle.wysiwyg.element);
|
|
|
|
|
highlightRender(protyle.wysiwyg.element);
|
|
|
|
|
blockRender(protyle, protyle.wysiwyg.element);
|
2022-08-31 01:14:45 +08:00
|
|
|
|
if (options.action.includes(Constants.CB_GET_HISTORY)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (protyle.options.render.scroll) {
|
2022-09-03 12:53:41 +08:00
|
|
|
|
protyle.scroll.update(protyle);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
2022-08-07 21:58:41 +08:00
|
|
|
|
if (options.action.includes(Constants.CB_GET_HL) && !options.unScroll) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
preventScroll(protyle); // 搜索页签滚动会导致再次请求
|
|
|
|
|
const hlElement = highlightById(protyle, protyle.block.id, true);
|
2022-06-29 20:25:30 +08:00
|
|
|
|
/// #if !MOBILE
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (hlElement && !options.action.includes(Constants.CB_GET_UNUNDO)) {
|
|
|
|
|
pushBack(protyle, undefined, hlElement);
|
|
|
|
|
}
|
2022-06-29 20:25:30 +08:00
|
|
|
|
/// #endif
|
2022-08-07 21:58:41 +08:00
|
|
|
|
} else if (options.action.includes(Constants.CB_GET_FOCUS) && !options.unScroll) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
let focusElement: Element;
|
|
|
|
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${protyle.block.id}"]`)).find((item: HTMLElement) => {
|
|
|
|
|
if (!hasClosestByAttribute(item, "data-type", "block-render", true)) {
|
|
|
|
|
focusElement = item;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (protyle.block.mode === 4) {
|
|
|
|
|
preventScroll(protyle);
|
|
|
|
|
focusElement = protyle.wysiwyg.element.lastElementChild;
|
|
|
|
|
}
|
|
|
|
|
if (focusElement && !protyle.wysiwyg.element.firstElementChild.isSameNode(focusElement)) {
|
|
|
|
|
focusBlock(focusElement);
|
2022-06-29 20:25:30 +08:00
|
|
|
|
/// #if !MOBILE
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (!options.action.includes(Constants.CB_GET_UNUNDO)) {
|
|
|
|
|
pushBack(protyle, undefined, focusElement);
|
|
|
|
|
}
|
2022-06-29 20:25:30 +08:00
|
|
|
|
/// #endif
|
2022-06-06 15:52:50 +08:00
|
|
|
|
focusElement.scrollIntoView();
|
|
|
|
|
// 减少抖动 https://ld246.com/article/1654263598088
|
2022-05-26 15:18:53 +08:00
|
|
|
|
setTimeout(() => {
|
2022-06-06 15:52:50 +08:00
|
|
|
|
focusElement.scrollIntoView();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}, Constants.TIMEOUT_BLOCKLOAD);
|
|
|
|
|
} else {
|
|
|
|
|
focusBlock(protyle.wysiwyg.element.firstElementChild);
|
2022-06-29 20:25:30 +08:00
|
|
|
|
/// #if !MOBILE
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (!options.action.includes(Constants.CB_GET_UNUNDO)) {
|
|
|
|
|
pushBack(protyle, undefined, protyle.wysiwyg.element.firstElementChild);
|
|
|
|
|
}
|
2022-06-29 20:25:30 +08:00
|
|
|
|
/// #endif
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
2022-08-07 21:58:41 +08:00
|
|
|
|
} else if (options.action.includes(Constants.CB_GET_FOCUSFIRST) && !options.unScroll) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
// settimeout 时间需短一点,否则定位后快速滚动无效
|
2022-08-08 18:16:18 +08:00
|
|
|
|
const headerHeight = protyle.wysiwyg.element.offsetTop - 16;
|
|
|
|
|
preventScroll(protyle, headerHeight, 256);
|
|
|
|
|
protyle.contentElement.scrollTop = headerHeight;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
focusBlock(protyle.wysiwyg.element.firstElementChild);
|
2022-06-29 20:25:30 +08:00
|
|
|
|
/// #if !MOBILE
|
2022-08-07 21:58:41 +08:00
|
|
|
|
if (!options.action.includes(Constants.CB_GET_UNUNDO)) {
|
|
|
|
|
pushBack(protyle, undefined, protyle.wysiwyg.element.firstElementChild);
|
|
|
|
|
}
|
2022-06-29 20:25:30 +08:00
|
|
|
|
/// #endif
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
2022-10-22 12:06:59 +08:00
|
|
|
|
if (options.isSyncing) {
|
2022-10-22 12:14:26 +08:00
|
|
|
|
disabledForeverProtyle(protyle);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
2022-10-22 12:06:59 +08:00
|
|
|
|
if (protyle.disabled) {
|
|
|
|
|
disabledProtyle(protyle);
|
|
|
|
|
} else {
|
|
|
|
|
enableProtyle(protyle);
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
if (options.action.includes(Constants.CB_GET_SETID)) {
|
|
|
|
|
// 点击大纲后,如果需要动态加载,在定位后,需要重置 block.id https://github.com/siyuan-note/siyuan/issues/4487
|
|
|
|
|
protyle.block.id = protyle.block.rootID;
|
|
|
|
|
protyle.wysiwyg.element.setAttribute("data-doc-type", "NodeDocument");
|
|
|
|
|
}
|
|
|
|
|
if (protyle.options.defId) {
|
|
|
|
|
protyle.wysiwyg.element.querySelectorAll(`[data-id="${protyle.options.defId}"]`).forEach(item => {
|
|
|
|
|
item.classList.add("def--mark");
|
|
|
|
|
});
|
|
|
|
|
protyle.options.defId = undefined;
|
|
|
|
|
}
|
2022-06-06 17:08:29 +08:00
|
|
|
|
// https://ld246.com/article/1653639418266
|
|
|
|
|
if (protyle.element.classList.contains("block__edit") && (protyle.element.nextElementSibling || protyle.element.previousElementSibling)) {
|
2022-06-12 21:18:43 +08:00
|
|
|
|
protyle.element.style.minHeight = Math.min(30 + protyle.wysiwyg.element.clientHeight, window.innerHeight / 3) + "px";
|
2022-06-06 17:08:29 +08:00
|
|
|
|
}
|
2022-06-21 09:05:18 +08:00
|
|
|
|
// 屏幕太高的页签 https://github.com/siyuan-note/siyuan/issues/5018
|
2022-06-07 19:59:57 +08:00
|
|
|
|
if (!protyle.scroll.element.classList.contains("fn__none") &&
|
|
|
|
|
protyle.wysiwyg.element.lastElementChild.getAttribute("data-eof") !== "true" &&
|
2022-06-21 09:05:18 +08:00
|
|
|
|
protyle.contentElement.scrollHeight > 0 && // 没有激活的页签 https://github.com/siyuan-note/siyuan/issues/5255
|
2022-06-27 22:20:39 +08:00
|
|
|
|
!options.action.includes(Constants.CB_GET_FOCUSFIRST) && // 防止 eof 为true https://github.com/siyuan-note/siyuan/issues/5291
|
2022-06-07 20:08:14 +08:00
|
|
|
|
protyle.contentElement.scrollHeight <= protyle.contentElement.clientHeight) {
|
2022-06-07 19:59:57 +08:00
|
|
|
|
fetchPost("/api/filetree/getDoc", {
|
|
|
|
|
id: protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"),
|
|
|
|
|
mode: 2,
|
|
|
|
|
k: protyle.options.key || "",
|
2022-10-30 23:13:41 +08:00
|
|
|
|
size: window.siyuan.config.editor.dynamicLoadBlocks,
|
2022-06-07 19:59:57 +08:00
|
|
|
|
}, getResponse => {
|
|
|
|
|
onGet(getResponse, protyle, [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID]);
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (options.action.includes(Constants.CB_GET_APPEND) || options.action.includes(Constants.CB_GET_BEFORE)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-08-31 01:14:45 +08:00
|
|
|
|
if (protyle.options.render.breadcrumb) {
|
|
|
|
|
protyle.breadcrumb.render(protyle);
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
};
|
|
|
|
|
|
2022-10-22 12:06:59 +08:00
|
|
|
|
export const disabledForeverProtyle = (protyle: IProtyle) => {
|
|
|
|
|
disabledProtyle(protyle);
|
2022-10-22 12:12:38 +08:00
|
|
|
|
if (protyle.breadcrumb) {
|
2022-10-22 16:56:30 +08:00
|
|
|
|
protyle.breadcrumb.element.nextElementSibling.textContent = window.siyuan.languages["_kernel"][81];
|
2022-10-22 12:12:38 +08:00
|
|
|
|
}
|
2022-10-22 12:06:59 +08:00
|
|
|
|
protyle.element.setAttribute("disabled-forever", "true");
|
2022-10-22 12:14:26 +08:00
|
|
|
|
};
|
2022-10-22 12:06:59 +08:00
|
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
|
/** 禁用编辑器 */
|
|
|
|
|
export const disabledProtyle = (protyle: IProtyle) => {
|
2022-10-17 11:43:33 +08:00
|
|
|
|
window.siyuan.menus.menu.remove();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
hideElements(["gutter", "toolbar", "select", "hint", "util"], protyle);
|
|
|
|
|
protyle.disabled = true;
|
2022-10-11 23:38:14 +08:00
|
|
|
|
if (protyle.title) {
|
2022-10-15 14:25:04 +08:00
|
|
|
|
const titleElement = protyle.title.element.querySelector(".protyle-title__input") as HTMLElement;
|
2022-10-13 16:03:02 +08:00
|
|
|
|
titleElement.setAttribute("contenteditable", "false");
|
|
|
|
|
titleElement.style.userSelect = "text";
|
2022-10-11 23:38:14 +08:00
|
|
|
|
}
|
2022-10-17 11:43:33 +08:00
|
|
|
|
if (protyle.background) {
|
|
|
|
|
protyle.background.element.classList.remove("protyle-background--enable");
|
2022-10-28 12:27:44 +08:00
|
|
|
|
protyle.background.element.classList.remove("protyle-background--mobileshow");
|
2022-10-17 11:43:33 +08:00
|
|
|
|
}
|
2022-10-28 12:27:44 +08:00
|
|
|
|
protyle.wysiwyg.element.querySelectorAll(".protyle-icons--show").forEach(item => {
|
|
|
|
|
item.classList.remove("protyle-icons--show");
|
2022-10-30 00:16:48 +08:00
|
|
|
|
});
|
2022-10-13 16:03:02 +08:00
|
|
|
|
protyle.wysiwyg.element.style.userSelect = "text";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle.wysiwyg.element.setAttribute("contenteditable", "false");
|
|
|
|
|
protyle.wysiwyg.element.querySelectorAll('[contenteditable="true"][spellcheck="false"]').forEach(item => {
|
|
|
|
|
item.setAttribute("contenteditable", "false");
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** 解除编辑器禁用 */
|
|
|
|
|
export const enableProtyle = (protyle: IProtyle) => {
|
2022-10-22 12:06:59 +08:00
|
|
|
|
if (protyle.element.getAttribute("disabled-forever") === "true") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle.disabled = false;
|
|
|
|
|
if (navigator && navigator.maxTouchPoints > 1 && ["MacIntel", "iPhone"].includes(navigator.platform)) {
|
2022-10-17 11:43:33 +08:00
|
|
|
|
// iPhone,iPad 端 protyle.wysiwyg.element contenteditable 为 true 时,输入会在块中间插入 span 导致保存失败 https://ld246.com/article/1643473862873/comment/1643813765839#comments
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
|
|
|
|
protyle.wysiwyg.element.setAttribute("contenteditable", "true");
|
2022-10-13 16:03:02 +08:00
|
|
|
|
protyle.wysiwyg.element.style.userSelect = "";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
2022-10-17 11:43:33 +08:00
|
|
|
|
if (protyle.title) {
|
|
|
|
|
const titleElement = protyle.title.element.querySelector(".protyle-title__input") as HTMLElement;
|
|
|
|
|
titleElement.setAttribute("contenteditable", "true");
|
|
|
|
|
titleElement.style.userSelect = "";
|
|
|
|
|
}
|
|
|
|
|
if (protyle.background) {
|
|
|
|
|
protyle.background.element.classList.add("protyle-background--enable");
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
protyle.wysiwyg.element.querySelectorAll('[contenteditable="false"][spellcheck="false"]').forEach(item => {
|
|
|
|
|
if (!hasClosestByClassName(item, "protyle-wysiwyg__embed")) {
|
|
|
|
|
item.setAttribute("contenteditable", "true");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|