This commit is contained in:
parent
7a7af86b11
commit
334a2385b3
13 changed files with 37 additions and 35 deletions
|
@ -85,7 +85,7 @@ const focusStack = (backStack: IBackStack) => {
|
|||
protyle.wysiwyg.element.innerHTML = getResponse.data.content;
|
||||
processRender(protyle.wysiwyg.element);
|
||||
highlightRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element, protyle);
|
||||
blockRender(protyle, protyle.wysiwyg.element, backStack.scrollTop);
|
||||
if (getResponse.data.isSyncing) {
|
||||
disabledForeverProtyle(protyle);
|
||||
|
|
|
@ -378,7 +378,7 @@ export class Gutter {
|
|||
blockRender(options.protyle, options.protyle.wysiwyg.element);
|
||||
processRender(options.protyle.wysiwyg.element);
|
||||
highlightRender(options.protyle.wysiwyg.element);
|
||||
avRender(options.protyle.wysiwyg.element);
|
||||
avRender(options.protyle.wysiwyg.element, options.protyle);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -441,7 +441,7 @@ export const hintRenderTemplate = (value: string, protyle: IProtyle, nodeElement
|
|||
blockRender(protyle, protyle.wysiwyg.element);
|
||||
processRender(protyle.wysiwyg.element);
|
||||
highlightRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element, protyle);
|
||||
hideElements(["util"], protyle);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -768,7 +768,7 @@ ${genHintItemHTML(item)}
|
|||
} else if (value === "---") {
|
||||
focusBlock(nodeElement);
|
||||
} else if (nodeElement.classList.contains("av")) {
|
||||
avRender(nodeElement);
|
||||
avRender(nodeElement, protyle);
|
||||
} else {
|
||||
focusByWbr(nodeElement, range);
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ export class Protyle {
|
|||
case "refreshAttributeView":
|
||||
Array.from(this.protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${data.data.id}"]`)).forEach((item: HTMLElement) => {
|
||||
item.removeAttribute("data-render");
|
||||
avRender(item);
|
||||
avRender(item, this.protyle);
|
||||
});
|
||||
break;
|
||||
case "addLoading":
|
||||
|
|
|
@ -164,7 +164,7 @@ export class Preview {
|
|||
protyle.preview.previewElement.innerHTML = response.data.html;
|
||||
processRender(protyle.preview.previewElement);
|
||||
highlightRender(protyle.preview.previewElement);
|
||||
avRender(protyle.preview.previewElement);
|
||||
avRender(protyle.preview.previewElement, protyle);
|
||||
speechRender(protyle.preview.previewElement, protyle.options.lang);
|
||||
protyle.preview.previewElement.scrollTop = oldScrollTop;
|
||||
/// #if MOBILE
|
||||
|
|
|
@ -19,6 +19,17 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
|
|||
if (!blockElement) {
|
||||
return false;
|
||||
}
|
||||
const copyElement = hasClosestByAttribute(event.target, "data-type", "copy");
|
||||
if (copyElement) {
|
||||
writeText(copyElement.previousElementSibling.textContent.trim());
|
||||
showMessage(window.siyuan.languages.copied);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
}
|
||||
if (protyle.disabled) {
|
||||
return false;
|
||||
}
|
||||
const addElement = hasClosestByAttribute(event.target, "data-type", "av-header-add");
|
||||
if (addElement) {
|
||||
const addMenu = addCol(protyle, blockElement);
|
||||
|
@ -105,15 +116,6 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
|
|||
return true;
|
||||
}
|
||||
|
||||
const copyElement = hasClosestByAttribute(event.target, "data-type", "copy");
|
||||
if (copyElement) {
|
||||
writeText(copyElement.previousElementSibling.textContent.trim());
|
||||
showMessage(window.siyuan.languages.copied);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
}
|
||||
|
||||
const linkElement = hasClosestByClassName(event.target, "av__celltext--url");
|
||||
if (linkElement) {
|
||||
let prefix = "";
|
||||
|
|
|
@ -7,7 +7,7 @@ import {hasClosestByAttribute} from "../../util/hasClosest";
|
|||
import {Menu} from "../../../plugin/Menu";
|
||||
import {escapeAttr} from "../../../util/escape";
|
||||
|
||||
export const avRender = (element: Element, cb?: () => void) => {
|
||||
export const avRender = (element: Element, protyle: IProtyle, cb?: () => void) => {
|
||||
let avElements: Element[] = [];
|
||||
if (element.getAttribute("data-type") === "NodeAttributeView") {
|
||||
// 编辑器内代码块编辑渲染
|
||||
|
@ -138,7 +138,7 @@ ${cell.color ? `color:${cell.color};` : ""}">${text}</div>`;
|
|||
</span>
|
||||
<div class="fn__space"></div>
|
||||
</div>
|
||||
<div contenteditable="true" class="av__title" data-title="${data.name || ""}" data-tip="${window.siyuan.languages.title}">${response.data.name || ""}</div>
|
||||
<div contenteditable="${protyle.disabled ? "false" : "true"}" spellcheck="${window.siyuan.config.editor.spellcheck.toString()}" class="av__title" data-title="${data.name || ""}" data-tip="${window.siyuan.languages.title}">${response.data.name || ""}</div>
|
||||
<div class="av__counter fn__none"></div>
|
||||
</div>
|
||||
<div class="av__scroll">
|
||||
|
@ -174,7 +174,7 @@ export const refreshAV = (protyle: IProtyle, operation: IOperation) => {
|
|||
if (operation.action === "addAttrViewCol") {
|
||||
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${avId}"]`)).forEach((item: HTMLElement) => {
|
||||
item.removeAttribute("data-render");
|
||||
avRender(item, () => {
|
||||
avRender(item, protyle, () => {
|
||||
showColMenu(protyle, item, item.querySelector(`.av__row--header .av__cell[data-col-id="${operation.id}"]`));
|
||||
});
|
||||
});
|
||||
|
@ -200,7 +200,7 @@ export const refreshAV = (protyle: IProtyle, operation: IOperation) => {
|
|||
} else {
|
||||
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${avId}"]`)).forEach((item: HTMLElement) => {
|
||||
item.removeAttribute("data-render");
|
||||
avRender(item);
|
||||
avRender(item, protyle);
|
||||
});
|
||||
}
|
||||
setTimeout(() => {
|
||||
|
|
|
@ -71,7 +71,7 @@ export const blockRender = (protyle: IProtyle, element: Element, top?: number) =
|
|||
|
||||
processRender(item);
|
||||
highlightRender(item);
|
||||
avRender(item);
|
||||
avRender(item, protyle);
|
||||
if (top) {
|
||||
// 前进后退定位 https://ld246.com/article/1667652729995
|
||||
protyle.contentElement.scrollTop = top;
|
||||
|
|
|
@ -168,7 +168,7 @@ const setHTML = (options: {
|
|||
}
|
||||
processRender(protyle.wysiwyg.element);
|
||||
highlightRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element, protyle);
|
||||
blockRender(protyle, protyle.wysiwyg.element);
|
||||
if (options.action.includes(Constants.CB_GET_HISTORY)) {
|
||||
return;
|
||||
|
|
|
@ -117,7 +117,7 @@ export const pasteText = (protyle: IProtyle, textPlain: string, nodeElement: Ele
|
|||
blockRender(protyle, protyle.wysiwyg.element);
|
||||
processRender(protyle.wysiwyg.element);
|
||||
highlightRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element, protyle);
|
||||
filterClipboardHint(protyle, textPlain);
|
||||
scrollCenter(protyle, undefined, false, "smooth");
|
||||
};
|
||||
|
@ -242,7 +242,7 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
|
|||
blockRender(protyle, protyle.wysiwyg.element);
|
||||
processRender(protyle.wysiwyg.element);
|
||||
highlightRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element, protyle);
|
||||
} else if (code) {
|
||||
if (!code.startsWith('<div data-type="NodeCodeBlock" class="code-block" data-node-id="')) {
|
||||
// 原有代码在行内元素中粘贴会嵌套
|
||||
|
@ -292,7 +292,7 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
|
|||
blockRender(protyle, protyle.wysiwyg.element);
|
||||
processRender(protyle.wysiwyg.element);
|
||||
highlightRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element, protyle);
|
||||
filterClipboardHint(protyle, response.data);
|
||||
scrollCenter(protyle, undefined, false, "smooth");
|
||||
});
|
||||
|
@ -330,7 +330,7 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
|
|||
blockRender(protyle, protyle.wysiwyg.element);
|
||||
processRender(protyle.wysiwyg.element);
|
||||
highlightRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element, protyle);
|
||||
}
|
||||
scrollCenter(protyle, undefined, false, "smooth");
|
||||
};
|
||||
|
|
|
@ -21,7 +21,7 @@ export const renderBacklink = (protyle: IProtyle, backlinkData: {
|
|||
protyle.wysiwyg.element.innerHTML = html;
|
||||
processRender(protyle.wysiwyg.element);
|
||||
highlightRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element, protyle);
|
||||
blockRender(protyle, protyle.wysiwyg.element);
|
||||
removeLoading(protyle);
|
||||
if (window.siyuan.config.readonly || window.siyuan.config.editor.readOnly) {
|
||||
|
@ -75,7 +75,7 @@ export const loadBreadcrumb = (protyle: IProtyle, element: HTMLElement) => {
|
|||
}
|
||||
element.parentElement.insertAdjacentHTML("afterend", setBacklinkFold(getResponse.data.content, true));
|
||||
processRender(element.parentElement.parentElement);
|
||||
avRender(element.parentElement.parentElement);
|
||||
avRender(element.parentElement.parentElement, protyle);
|
||||
blockRender(protyle, element.parentElement.parentElement);
|
||||
if (getResponse.data.isSyncing) {
|
||||
disabledForeverProtyle(protyle);
|
||||
|
|
|
@ -124,7 +124,7 @@ const promiseTransaction = () => {
|
|||
});
|
||||
processRender(protyle.wysiwyg.element);
|
||||
highlightRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element, protyle);
|
||||
blockRender(protyle, protyle.wysiwyg.element);
|
||||
protyle.contentElement.scrollTop = scrollTop;
|
||||
protyle.scroll.lastScrollTop = scrollTop;
|
||||
|
@ -164,7 +164,7 @@ const promiseTransaction = () => {
|
|||
});
|
||||
processRender(protyle.wysiwyg.element);
|
||||
highlightRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element, protyle);
|
||||
blockRender(protyle, protyle.wysiwyg.element);
|
||||
}
|
||||
// 当前编辑器中更新嵌入块
|
||||
|
@ -274,7 +274,7 @@ const promiseTransaction = () => {
|
|||
cursorElements.forEach(item => {
|
||||
processRender(item);
|
||||
highlightRender(item);
|
||||
avRender(item);
|
||||
avRender(item, protyle);
|
||||
blockRender(protyle, item);
|
||||
const wbrElement = item.querySelector("wbr");
|
||||
if (wbrElement) {
|
||||
|
@ -314,7 +314,7 @@ const updateEmbed = (protyle: IProtyle, operation: IOperation) => {
|
|||
if (updatedEmbed) {
|
||||
processRender(protyle.wysiwyg.element);
|
||||
highlightRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element, protyle);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -358,7 +358,7 @@ const updateBlock = (updateElements: Element[], protyle: IProtyle, operation: IO
|
|||
}
|
||||
processRender(updateElements.length === 1 ? updateElements[0] : protyle.wysiwyg.element);
|
||||
highlightRender(updateElements.length === 1 ? updateElements[0] : protyle.wysiwyg.element);
|
||||
avRender(updateElements.length === 1 ? updateElements[0] : protyle.wysiwyg.element);
|
||||
avRender(updateElements.length === 1 ? updateElements[0] : protyle.wysiwyg.element, protyle);
|
||||
blockRender(protyle, updateElements.length === 1 ? updateElements[0] : protyle.wysiwyg.element);
|
||||
// 更新 ws 嵌入块
|
||||
updateEmbed(protyle, operation);
|
||||
|
@ -399,7 +399,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo:
|
|||
if (operation.retData) {
|
||||
processRender(protyle.wysiwyg.element);
|
||||
highlightRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element);
|
||||
avRender(protyle.wysiwyg.element, protyle);
|
||||
blockRender(protyle, protyle.wysiwyg.element);
|
||||
protyle.contentElement.scrollTop = scrollTop;
|
||||
protyle.scroll.lastScrollTop = scrollTop;
|
||||
|
@ -687,7 +687,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo:
|
|||
cursorElements.forEach(item => {
|
||||
processRender(item);
|
||||
highlightRender(item);
|
||||
avRender(item);
|
||||
avRender(item, protyle);
|
||||
blockRender(protyle, item);
|
||||
const wbrElement = item.querySelector("wbr");
|
||||
if (isUndo) {
|
||||
|
@ -916,7 +916,7 @@ export const turnsIntoTransaction = (options: {
|
|||
transaction(options.protyle, doOperations, undoOperations);
|
||||
processRender(options.protyle.wysiwyg.element);
|
||||
highlightRender(options.protyle.wysiwyg.element);
|
||||
avRender(options.protyle.wysiwyg.element);
|
||||
avRender(options.protyle.wysiwyg.element, options.protyle);
|
||||
blockRender(options.protyle, options.protyle.wysiwyg.element);
|
||||
if (range) {
|
||||
focusByWbr(options.protyle.wysiwyg.element, range);
|
||||
|
|
Loading…
Add table
Reference in a new issue