Vanessa 2023-06-01 14:56:21 +08:00
parent 8c35440a77
commit 74b4a00a2f
42 changed files with 426 additions and 270 deletions

View file

@ -810,7 +810,7 @@ export const globalShortcut = (app: App) => {
app.plugins.find(item => { app.plugins.find(item => {
item.commands.find(command => { item.commands.find(command => {
if (command.callback && if (command.callback &&
!command.fileTreeCallback && !command.editorCallback&& !command.dockCallback !command.fileTreeCallback && !command.editorCallback && !command.dockCallback
&& matchHotKey(command.customHotkey, event)) { && matchHotKey(command.customHotkey, event)) {
matchCommand = true; matchCommand = true;
command.callback(); command.callback();
@ -1071,7 +1071,7 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
selectElements = [nodeElement]; selectElements = [nodeElement];
} }
movePathTo((toPath) => { movePathTo((toPath) => {
hintMoveBlock(toPath[0], selectElements, protyle); hintMoveBlock(toPath[0], selectElements, protyle, app);
}); });
} }
event.preventDefault(); event.preventDefault();
@ -1084,7 +1084,7 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
return false; return false;
} }
if (matchHotKey(window.siyuan.config.keymap.editor.general.refresh.custom, event)) { if (matchHotKey(window.siyuan.config.keymap.editor.general.refresh.custom, event)) {
reloadProtyle(protyle, true); reloadProtyle(protyle, app, true);
event.preventDefault(); event.preventDefault();
return true; return true;
} }
@ -1106,19 +1106,19 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
id: protyle.block.parentID, id: protyle.block.parentID,
size: window.siyuan.config.editor.dynamicLoadBlocks, size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => { }, getResponse => {
onGet(getResponse, protyle); onGet({data: getResponse, protyle, app});
}); });
event.preventDefault(); event.preventDefault();
return true; return true;
} }
// 没有光标时,无法撤销 https://ld246.com/article/1624021111567 // 没有光标时,无法撤销 https://ld246.com/article/1624021111567
if (matchHotKey(window.siyuan.config.keymap.editor.general.undo.custom, event)) { if (matchHotKey(window.siyuan.config.keymap.editor.general.undo.custom, event)) {
protyle.undo.undo(protyle); protyle.undo.undo(app, protyle);
event.preventDefault(); event.preventDefault();
return true; return true;
} }
if (matchHotKey(window.siyuan.config.keymap.editor.general.redo.custom, event)) { if (matchHotKey(window.siyuan.config.keymap.editor.general.redo.custom, event)) {
protyle.undo.redo(protyle); protyle.undo.redo(app, protyle);
event.preventDefault(); event.preventDefault();
return true; return true;
} }

View file

@ -143,7 +143,12 @@ export const bindCardEvent = (options: {
mode: 0, mode: 0,
size: Constants.SIZE_GET_MAX size: Constants.SIZE_GET_MAX
}, (response) => { }, (response) => {
onGet(response, editor.protyle, [Constants.CB_GET_ALL, Constants.CB_GET_HTML]); onGet({
data: response,
protyle: editor.protyle,
action: [Constants.CB_GET_ALL, Constants.CB_GET_HTML],
app: options.app
});
}); });
} }
(options.element.firstElementChild as HTMLElement).style.zIndex = "200"; (options.element.firstElementChild as HTMLElement).style.zIndex = "200";
@ -163,6 +168,7 @@ export const bindCardEvent = (options: {
options.blocks = treeCards.data.cards; options.blocks = treeCards.data.cards;
if (options.blocks.length > 0) { if (options.blocks.length > 0) {
nextCard({ nextCard({
app: options.app,
countElement, countElement,
editor, editor,
actionElements, actionElements,
@ -336,6 +342,7 @@ export const bindCardEvent = (options: {
if (index > 0) { if (index > 0) {
index--; index--;
nextCard({ nextCard({
app: options.app,
countElement, countElement,
editor, editor,
actionElements, actionElements,
@ -379,6 +386,7 @@ export const bindCardEvent = (options: {
} }
} else { } else {
nextCard({ nextCard({
app: options.app,
countElement, countElement,
editor, editor,
actionElements, actionElements,
@ -390,6 +398,7 @@ export const bindCardEvent = (options: {
return; return;
} }
nextCard({ nextCard({
app: options.app,
countElement, countElement,
editor, editor,
actionElements, actionElements,
@ -449,6 +458,7 @@ export const openCardByData = (app: App, cardsData: {
}; };
const nextCard = (options: { const nextCard = (options: {
app: App,
countElement: Element, editor: Protyle, actionElements: NodeListOf<Element>, index: number, blocks: ICard[] countElement: Element, editor: Protyle, actionElements: NodeListOf<Element>, index: number, blocks: ICard[]
}) => { }) => {
options.editor.protyle.element.classList.add("card__block--hide"); options.editor.protyle.element.classList.add("card__block--hide");
@ -477,7 +487,12 @@ const nextCard = (options: {
mode: 0, mode: 0,
size: Constants.SIZE_GET_MAX size: Constants.SIZE_GET_MAX
}, (response) => { }, (response) => {
onGet(response, options.editor.protyle, [Constants.CB_GET_ALL, Constants.CB_GET_HTML]); onGet({
data: response,
protyle: options.editor.protyle,
action: [Constants.CB_GET_ALL, Constants.CB_GET_HTML],
app: options.app
});
}); });
}; };

View file

@ -68,7 +68,7 @@ export const viewCards = (app: App, deckID: string, title: string, deckType: "Tr
if (window.siyuan.config.editor.readOnly) { if (window.siyuan.config.editor.readOnly) {
disabledProtyle(edit.protyle); disabledProtyle(edit.protyle);
} }
getArticle(edit, dialog.element.querySelector(".b3-list-item--focus")?.getAttribute("data-id")); getArticle(app, edit, dialog.element.querySelector(".b3-list-item--focus")?.getAttribute("data-id"));
} }
const previousElement = dialog.element.querySelector('[data-type="previous"]'); const previousElement = dialog.element.querySelector('[data-type="previous"]');
const nextElement = dialog.element.querySelector('[data-type="next"]'); const nextElement = dialog.element.querySelector('[data-type="next"]');
@ -93,7 +93,7 @@ export const viewCards = (app: App, deckID: string, title: string, deckType: "Tr
if (currentRect.top < parentRect.top || currentRect.bottom > parentRect.bottom) { if (currentRect.top < parentRect.top || currentRect.bottom > parentRect.bottom) {
currentElement.scrollIntoView(currentRect.top < parentRect.top); currentElement.scrollIntoView(currentRect.top < parentRect.top);
} }
getArticle(edit, currentElement.getAttribute("data-id")); getArticle(app, edit, currentElement.getAttribute("data-id"));
currentElement.classList.add("b3-list-item--focus"); currentElement.classList.add("b3-list-item--focus");
} }
event.stopPropagation(); event.stopPropagation();
@ -125,7 +125,7 @@ export const viewCards = (app: App, deckID: string, title: string, deckType: "Tr
nextElement.nextElementSibling.nextElementSibling.textContent = `${pageIndex}/${cardsResponse.data.pageCount || 1}`; nextElement.nextElementSibling.nextElementSibling.textContent = `${pageIndex}/${cardsResponse.data.pageCount || 1}`;
listElement.innerHTML = renderViewItem(cardsResponse.data.blocks, title, deckType); listElement.innerHTML = renderViewItem(cardsResponse.data.blocks, title, deckType);
listElement.scrollTop = 0; listElement.scrollTop = 0;
getArticle(edit, dialog.element.querySelector(".b3-list-item--focus")?.getAttribute("data-id")); getArticle(app, edit, dialog.element.querySelector(".b3-list-item--focus")?.getAttribute("data-id"));
}); });
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
@ -145,13 +145,13 @@ export const viewCards = (app: App, deckID: string, title: string, deckType: "Tr
nextElement.nextElementSibling.nextElementSibling.textContent = `${pageIndex}/${cardsResponse.data.pageCount || 1}`; nextElement.nextElementSibling.nextElementSibling.textContent = `${pageIndex}/${cardsResponse.data.pageCount || 1}`;
listElement.innerHTML = renderViewItem(cardsResponse.data.blocks, title, deckType); listElement.innerHTML = renderViewItem(cardsResponse.data.blocks, title, deckType);
listElement.scrollTop = 0; listElement.scrollTop = 0;
getArticle(edit, dialog.element.querySelector(".b3-list-item--focus")?.getAttribute("data-id")); getArticle(app, edit, dialog.element.querySelector(".b3-list-item--focus")?.getAttribute("data-id"));
}); });
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
break; break;
} else if (type === "card-item") { } else if (type === "card-item") {
getArticle(edit, target.getAttribute("data-id")); getArticle(app, edit, target.getAttribute("data-id"));
listElement.querySelector(".b3-list-item--focus")?.classList.remove("b3-list-item--focus"); listElement.querySelector(".b3-list-item--focus")?.classList.remove("b3-list-item--focus");
target.classList.add("b3-list-item--focus"); target.classList.add("b3-list-item--focus");
event.stopPropagation(); event.stopPropagation();
@ -171,10 +171,10 @@ export const viewCards = (app: App, deckID: string, title: string, deckType: "Tr
} }
if (!nextElment) { if (!nextElment) {
getArticle(edit, ""); getArticle(app, edit, "");
listElement.innerHTML = `<div class="b3-list--empty">${window.siyuan.languages.emptyContent}</div>`; listElement.innerHTML = `<div class="b3-list--empty">${window.siyuan.languages.emptyContent}</div>`;
} else { } else {
getArticle(edit, nextElment.getAttribute("data-id")); getArticle(app, edit, nextElment.getAttribute("data-id"));
listElement.querySelector(".b3-list-item--focus")?.classList.remove("b3-list-item--focus"); listElement.querySelector(".b3-list-item--focus")?.classList.remove("b3-list-item--focus");
nextElment.classList.add("b3-list-item--focus"); nextElment.classList.add("b3-list-item--focus");
target.parentElement.remove(); target.parentElement.remove();
@ -240,7 +240,7 @@ ${unicode2Emoji(item.ial.icon, false, "b3-list-item__graphic", true)}
}; };
const getArticle = (edit: Protyle, id: string) => { const getArticle = (app: App, edit: Protyle, id: string) => {
if (!id) { if (!id) {
edit.protyle.element.classList.add("fn__none"); edit.protyle.element.classList.add("fn__none");
edit.protyle.element.nextElementSibling.classList.remove("fn__none"); edit.protyle.element.nextElementSibling.classList.remove("fn__none");
@ -255,6 +255,8 @@ const getArticle = (edit: Protyle, id: string) => {
mode: 0, mode: 0,
size: Constants.SIZE_GET_MAX, size: Constants.SIZE_GET_MAX,
}, getResponse => { }, getResponse => {
onGet(getResponse, edit.protyle, [Constants.CB_GET_ALL, Constants.CB_GET_HTML]); onGet({
data: getResponse, protyle: edit.protyle, action: [Constants.CB_GET_ALL, Constants.CB_GET_HTML], app
});
}); });
}; };

View file

@ -5,6 +5,7 @@ import {confirmDialog} from "../dialog/confirmDialog";
import {setPadding} from "../protyle/ui/initUI"; import {setPadding} from "../protyle/ui/initUI";
import {reloadProtyle} from "../protyle/util/reload"; import {reloadProtyle} from "../protyle/util/reload";
import {updateHotkeyTip} from "../protyle/util/compatibility"; import {updateHotkeyTip} from "../protyle/util/compatibility";
import {App} from "../index";
export const editor = { export const editor = {
element: undefined as Element, element: undefined as Element,
@ -257,7 +258,7 @@ export const editor = {
</div> </div>
</label>`; </label>`;
}, },
bindEvent: () => { bindEvent: (app: App) => {
const fontFamilyElement = editor.element.querySelector("#fontFamily") as HTMLSelectElement; const fontFamilyElement = editor.element.querySelector("#fontFamily") as HTMLSelectElement;
if (fontFamilyElement.tagName === "SELECT") { if (fontFamilyElement.tagName === "SELECT") {
let fontFamilyHTML = `<option value="">${window.siyuan.languages.default}</option>`; let fontFamilyHTML = `<option value="">${window.siyuan.languages.default}</option>`;
@ -317,7 +318,7 @@ export const editor = {
fontFamily: fontFamilyElement.value, fontFamily: fontFamilyElement.value,
emoji: window.siyuan.config.editor.emoji emoji: window.siyuan.config.editor.emoji
}, response => { }, response => {
editor.onSetEditor(response.data); editor.onSetEditor(response.data, app);
}); });
}; };
editor.element.querySelectorAll("input.b3-switch, select.b3-select, input.b3-slider").forEach((item) => { editor.element.querySelectorAll("input.b3-switch, select.b3-select, input.b3-slider").forEach((item) => {
@ -337,13 +338,13 @@ export const editor = {
}); });
}); });
}, },
onSetEditor: (editorData: IEditor) => { onSetEditor: (editorData: IEditor, app: App) => {
if (editorData.readOnly !== window.siyuan.config.editor.readOnly) { if (editorData.readOnly !== window.siyuan.config.editor.readOnly) {
editor.setReadonly(editorData.readOnly); editor.setReadonly(editorData.readOnly);
} }
window.siyuan.config.editor = editorData; window.siyuan.config.editor = editorData;
getAllModels().editor.forEach((item) => { getAllModels().editor.forEach((item) => {
reloadProtyle(item.editor.protyle, false); reloadProtyle(item.editor.protyle, app, false);
setPadding(item.editor.protyle); setPadding(item.editor.protyle);
if (window.siyuan.config.editor.fullWidth) { if (window.siyuan.config.editor.fullWidth) {
item.editor.protyle.contentElement.setAttribute("data-fullwidth", "true"); item.editor.protyle.contentElement.setAttribute("data-fullwidth", "true");

View file

@ -146,6 +146,6 @@ export const openSetting = (app: App) => {
}); });
}); });
editor.element = dialog.element.querySelector('.config__tab-container[data-name="editor"]'); editor.element = dialog.element.querySelector('.config__tab-container[data-name="editor"]');
editor.bindEvent(); editor.bindEvent(app);
return dialog; return dialog;
}; };

View file

@ -37,7 +37,7 @@ export const reloadSync = (app: App, data: { upsertRootIDs: string[], removeRoot
if (data.removeRootIDs.includes(window.siyuan.mobile.popEditor.protyle.block.rootID)) { if (data.removeRootIDs.includes(window.siyuan.mobile.popEditor.protyle.block.rootID)) {
hideElements(["dialog"]); hideElements(["dialog"]);
} else { } else {
reloadProtyle(window.siyuan.mobile.popEditor.protyle, false); reloadProtyle(window.siyuan.mobile.popEditor.protyle, app, false);
window.siyuan.mobile.popEditor.protyle.breadcrumb.render(window.siyuan.mobile.popEditor.protyle, true); window.siyuan.mobile.popEditor.protyle.breadcrumb.render(window.siyuan.mobile.popEditor.protyle, true);
} }
} }
@ -45,7 +45,7 @@ export const reloadSync = (app: App, data: { upsertRootIDs: string[], removeRoot
if (data.removeRootIDs.includes(window.siyuan.mobile.editor.protyle.block.rootID)) { if (data.removeRootIDs.includes(window.siyuan.mobile.editor.protyle.block.rootID)) {
setEmpty(app); setEmpty(app);
} else { } else {
reloadProtyle(window.siyuan.mobile.editor.protyle, false); reloadProtyle(window.siyuan.mobile.editor.protyle, app, false);
fetchPost("/api/block/getDocInfo", { fetchPost("/api/block/getDocInfo", {
id: window.siyuan.mobile.editor.protyle.block.rootID id: window.siyuan.mobile.editor.protyle.block.rootID
}, (response) => { }, (response) => {
@ -60,7 +60,7 @@ export const reloadSync = (app: App, data: { upsertRootIDs: string[], removeRoot
const allModels = getAllModels(); const allModels = getAllModels();
allModels.editor.forEach(item => { allModels.editor.forEach(item => {
if (data.upsertRootIDs.includes(item.editor.protyle.block.rootID)) { if (data.upsertRootIDs.includes(item.editor.protyle.block.rootID)) {
reloadProtyle(item.editor.protyle, false); reloadProtyle(item.editor.protyle, app, false);
updateTitle(item.editor.protyle.block.rootID, item.parent); updateTitle(item.editor.protyle.block.rootID, item.parent);
} else if (data.removeRootIDs.includes(item.editor.protyle.block.rootID)) { } else if (data.removeRootIDs.includes(item.editor.protyle.block.rootID)) {
item.parent.parent.removeTab(item.parent.id, false, false, false); item.parent.parent.removeTab(item.parent.id, false, false, false);

View file

@ -343,7 +343,7 @@ const switchEditor = (editor: Editor, options: IOpenFileOptions, allModels: IMod
return true; return true;
} }
if (options.zoomIn) { if (options.zoomIn) {
zoomOut(editor.editor.protyle, options.id); zoomOut({app: options.app, protyle: editor.editor.protyle, id: options.id});
return true; return true;
} }
let nodeElement = editor.editor.protyle.wysiwyg.element.querySelector(`[data-node-id="${options.id}"]`); let nodeElement = editor.editor.protyle.wysiwyg.element.querySelector(`[data-node-id="${options.id}"]`);
@ -353,7 +353,7 @@ const switchEditor = (editor: Editor, options: IOpenFileOptions, allModels: IMod
mode: (options.action && options.action.includes(Constants.CB_GET_CONTEXT)) ? 3 : 0, mode: (options.action && options.action.includes(Constants.CB_GET_CONTEXT)) ? 3 : 0,
size: window.siyuan.config.editor.dynamicLoadBlocks, size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => { }, getResponse => {
onGet(getResponse, editor.editor.protyle, options.action); onGet({data: getResponse, protyle: editor.editor.protyle, action: options.action, app: options.app});
// 大纲点击折叠标题下的内容时,需更新反链面板 // 大纲点击折叠标题下的内容时,需更新反链面板
updateBacklinkGraph(allModels, editor.editor.protyle); updateBacklinkGraph(allModels, editor.editor.protyle);
}); });

View file

@ -74,7 +74,12 @@ const renderCompare = (app: App, element: HTMLElement) => {
} else { } else {
textElement.classList.add("fn__none"); textElement.classList.add("fn__none");
leftElement.lastElementChild.classList.remove("fn__none"); leftElement.lastElementChild.classList.remove("fn__none");
onGet(response, leftEditor.protyle, [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML]); onGet({
data: response,
protyle: leftEditor.protyle,
action: [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML],
app
});
} }
textElement.previousElementSibling.textContent = dayjs(response.data.updated).format("YYYY-MM-DD HH:mm"); textElement.previousElementSibling.textContent = dayjs(response.data.updated).format("YYYY-MM-DD HH:mm");
}); });
@ -90,7 +95,12 @@ const renderCompare = (app: App, element: HTMLElement) => {
} else { } else {
textElement.classList.add("fn__none"); textElement.classList.add("fn__none");
rightElement.lastElementChild.classList.remove("fn__none"); rightElement.lastElementChild.classList.remove("fn__none");
onGet(response, rightEditor.protyle, [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML]); onGet({
data: response,
protyle: rightEditor.protyle,
action: [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML],
app
});
} }
textElement.previousElementSibling.textContent = dayjs(response.data.updated).format("YYYY-MM-DD HH:mm"); textElement.previousElementSibling.textContent = dayjs(response.data.updated).format("YYYY-MM-DD HH:mm");
}); });

View file

@ -611,7 +611,12 @@ const bindEvent = (app: App, element: Element, dialog?: Dialog) => {
} else { } else {
mdElement.classList.add("fn__none"); mdElement.classList.add("fn__none");
docElement.classList.remove("fn__none"); docElement.classList.remove("fn__none");
onGet(response, historyEditor.protyle, [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML]); onGet({
data: response,
protyle: historyEditor.protyle,
action: [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML],
app
});
} }
}); });
} }

View file

@ -181,7 +181,7 @@ export class App {
}); });
setNoteBook(); setNoteBook();
initBlockPopover(this); initBlockPopover(this);
promiseTransactions(); promiseTransactions(this);
} }
} }

View file

@ -156,7 +156,12 @@ export class Outline extends Model {
mode: 0, mode: 0,
size: window.siyuan.config.editor.dynamicLoadBlocks, size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => { }, getResponse => {
onGet(getResponse, item.editor.protyle, [Constants.CB_GET_FOCUS]); onGet({
data: getResponse,
protyle: item.editor.protyle,
action: [Constants.CB_GET_FOCUS],
app: options.app
});
}); });
} }
return true; return true;

View file

@ -434,16 +434,30 @@ export const contentMenu = (protyle: IProtyle, nodeElement: Element) => {
} }
}; };
export const zoomOut = (protyle: IProtyle, id: string, focusId?: string, isPushBack = true, callback?: () => void, reload = false) => { export const zoomOut = (options: {
if (protyle.options.backlinkData) { app: App,
protyle: IProtyle,
id: string,
focusId?: string,
isPushBack?: boolean,
callback?: () => void,
reload?: boolean
}) => {
if (options.protyle.options.backlinkData) {
return; return;
} }
const breadcrumbHLElement = protyle.breadcrumb?.element.querySelector(".protyle-breadcrumb__item--active"); if (typeof options.isPushBack === "undefined") {
if (!reload && breadcrumbHLElement && breadcrumbHLElement.getAttribute("data-node-id") === id) { options.isPushBack = true;
if (id === protyle.block.rootID) { }
if (typeof options.reload === "undefined") {
options.reload = false;
}
const breadcrumbHLElement = options.protyle.breadcrumb?.element.querySelector(".protyle-breadcrumb__item--active");
if (!options.reload && breadcrumbHLElement && breadcrumbHLElement.getAttribute("data-node-id") === options.id) {
if (options.id === options.protyle.block.rootID) {
return; return;
} }
const focusElement = protyle.wysiwyg.element.querySelector(`[data-node-id="${focusId || id}"]`); const focusElement = options.protyle.wysiwyg.element.querySelector(`[data-node-id="${options.focusId || options.id}"]`);
if (focusElement) { if (focusElement) {
focusBlock(focusElement); focusBlock(focusElement);
focusElement.scrollIntoView(); focusElement.scrollIntoView();
@ -452,58 +466,73 @@ export const zoomOut = (protyle: IProtyle, id: string, focusId?: string, isPushB
} }
if (window.siyuan.mobile?.editor) { if (window.siyuan.mobile?.editor) {
window.siyuan.storage[Constants.LOCAL_DOCINFO] = { window.siyuan.storage[Constants.LOCAL_DOCINFO] = {
id, id: options.id,
action: id === protyle.block.rootID ? [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT] : [Constants.CB_GET_ALL] action: options.id === options.protyle.block.rootID ? [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT] : [Constants.CB_GET_ALL]
}; };
setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]); setStorageVal(Constants.LOCAL_DOCINFO, window.siyuan.storage[Constants.LOCAL_DOCINFO]);
if (isPushBack) { if (options.isPushBack) {
pushBack(); pushBack();
} }
} }
/// #if !MOBILE /// #if !MOBILE
if (protyle.breadcrumb) { if (options.protyle.breadcrumb) {
protyle.breadcrumb.toggleExit(id === protyle.block.rootID); options.protyle.breadcrumb.toggleExit(options.id === options.protyle.block.rootID);
} }
/// #endif /// #endif
fetchPost("/api/filetree/getDoc", { fetchPost("/api/filetree/getDoc", {
id, id: options.id,
size: id === protyle.block.rootID ? window.siyuan.config.editor.dynamicLoadBlocks : Constants.SIZE_GET_MAX, size: options.id === options.protyle.block.rootID ? window.siyuan.config.editor.dynamicLoadBlocks : Constants.SIZE_GET_MAX,
}, getResponse => { }, getResponse => {
if (isPushBack) { if (options.isPushBack) {
onGet(getResponse, protyle, id === protyle.block.rootID ? [Constants.CB_GET_FOCUS, Constants.CB_GET_HTML] : [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS, Constants.CB_GET_HTML]); onGet({
data: getResponse,
protyle: options.protyle,
action: options.id === options.protyle.block.rootID ? [Constants.CB_GET_FOCUS, Constants.CB_GET_HTML] : [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS, Constants.CB_GET_HTML],
app: options.app
});
} else { } else {
onGet(getResponse, protyle, id === protyle.block.rootID ? [Constants.CB_GET_FOCUS, Constants.CB_GET_HTML, Constants.CB_GET_UNUNDO] : [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS, Constants.CB_GET_UNUNDO, Constants.CB_GET_HTML]); onGet({
data: getResponse,
protyle: options.protyle,
action: options.id === options.protyle.block.rootID ? [Constants.CB_GET_FOCUS, Constants.CB_GET_HTML, Constants.CB_GET_UNUNDO] : [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS, Constants.CB_GET_UNUNDO, Constants.CB_GET_HTML],
app: options.app
});
} }
// https://github.com/siyuan-note/siyuan/issues/4874 // https://github.com/siyuan-note/siyuan/issues/4874
if (focusId) { if (options.focusId) {
const focusElement = protyle.wysiwyg.element.querySelector(`[data-node-id="${focusId}"]`); const focusElement = options.protyle.wysiwyg.element.querySelector(`[data-node-id="${options.focusId}"]`);
if (focusElement) { if (focusElement) {
focusBlock(focusElement); focusBlock(focusElement);
focusElement.scrollIntoView(); focusElement.scrollIntoView();
} else if (id === protyle.block.rootID) { // 聚焦返回后,该块是动态加载的,但是没加载出来 } else if (options.id === options.protyle.block.rootID) { // 聚焦返回后,该块是动态加载的,但是没加载出来
fetchPost("/api/filetree/getDoc", { fetchPost("/api/filetree/getDoc", {
id: focusId, id: options.focusId,
mode: 3, mode: 3,
size: window.siyuan.config.editor.dynamicLoadBlocks, size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getFocusResponse => { }, getFocusResponse => {
onGet(getFocusResponse, protyle, isPushBack ? [Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_UNUNDO]); onGet({
data: getFocusResponse,
protyle: options.protyle,
action: options.isPushBack ? [Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_UNUNDO],
app: options.app
});
}); });
return; return;
} }
} }
/// #if !MOBILE /// #if !MOBILE
if (protyle.model) { if (options.protyle.model) {
const allModels = getAllModels(); const allModels = getAllModels();
allModels.outline.forEach(item => { allModels.outline.forEach(item => {
if (item.blockId === protyle.block.rootID) { if (item.blockId === options.protyle.block.rootID) {
item.setCurrent(protyle.wysiwyg.element.querySelector(`[data-node-id="${focusId || id}"]`)); item.setCurrent(options.protyle.wysiwyg.element.querySelector(`[data-node-id="${options.focusId || options.id}"]`));
} }
}); });
updateBacklinkGraph(allModels, protyle); updateBacklinkGraph(allModels, options.protyle);
} }
/// #endif /// #endif
if (callback) { if (options.callback) {
callback(); options.callback();
} }
}); });
}; };

View file

@ -58,7 +58,7 @@ export const openMobileFileById = (app: App, id: string, action = [Constants.CB_
size: action.includes(Constants.CB_GET_ALL) ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks, size: action.includes(Constants.CB_GET_ALL) ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks,
mode: action.includes(Constants.CB_GET_CONTEXT) ? 3 : 0, mode: action.includes(Constants.CB_GET_CONTEXT) ? 3 : 0,
}, getResponse => { }, getResponse => {
onGet(getResponse, window.siyuan.mobile.editor.protyle, action); onGet({data: getResponse, protyle: window.siyuan.mobile.editor.protyle, action, app});
window.siyuan.mobile.editor.protyle.breadcrumb?.render(window.siyuan.mobile.editor.protyle); window.siyuan.mobile.editor.protyle.breadcrumb?.render(window.siyuan.mobile.editor.protyle);
}); });
window.siyuan.mobile.editor.protyle.undo.clear(); window.siyuan.mobile.editor.protyle.undo.clear();

View file

@ -96,13 +96,13 @@ class App {
handleTouchEnd(this, event); handleTouchEnd(this, event);
}, false); }, false);
}); });
promiseTransactions(); promiseTransactions(this);
} }
} }
const siyuanApp = new App(); const siyuanApp = new App();
window.goBack = goBack; window.goBack = goBack.apply(siyuanApp);
window.showKeyboardToolbar = (height) => { window.showKeyboardToolbar = (height) => {
document.getElementById("keyboardToolbar").setAttribute("data-keyboardheight", (height ? height : window.innerHeight / 2 - 42).toString()); document.getElementById("keyboardToolbar").setAttribute("data-keyboardheight", (height ? height : window.innerHeight / 2 - 42).toString());
showKeyboardToolbar(); showKeyboardToolbar();

View file

@ -144,7 +144,7 @@ export const initRightMenu = (app: App) => {
event.stopPropagation(); event.stopPropagation();
break; break;
} else if (target.id === "menuEditor") { } else if (target.id === "menuEditor") {
initEditor(); initEditor(app);
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
break; break;

View file

@ -16,7 +16,7 @@ import {reloadProtyle} from "../../protyle/util/reload";
import {activeBlur, hideKeyboardToolbar} from "../util/keyboardToolbar"; import {activeBlur, hideKeyboardToolbar} from "../util/keyboardToolbar";
import {App} from "../../index"; import {App} from "../../index";
const replace = (element: Element, config: ISearchOption, isAll: boolean) => { const replace = (app: App,element: Element, config: ISearchOption, isAll: boolean) => {
if (config.method === 1 || config.method === 2) { if (config.method === 1 || config.method === 2) {
showMessage(window.siyuan.languages._kernel[132]); showMessage(window.siyuan.languages._kernel[132]);
return; return;
@ -60,7 +60,7 @@ const replace = (element: Element, config: ISearchOption, isAll: boolean) => {
if (ids.length > 1) { if (ids.length > 1) {
return; return;
} }
reloadProtyle(window.siyuan.mobile.editor.protyle, false); reloadProtyle(window.siyuan.mobile.editor.protyle, app, false);
if (currentLiElement.nextElementSibling) { if (currentLiElement.nextElementSibling) {
currentLiElement.nextElementSibling.classList.add("b3-list-item--focus"); currentLiElement.nextElementSibling.classList.add("b3-list-item--focus");
@ -478,12 +478,12 @@ const initSearchEvent = (app: App, element: Element, config: ISearchOption) => {
event.preventDefault(); event.preventDefault();
break; break;
} else if (type === "replace-all") { } else if (type === "replace-all") {
replace(element, config, true); replace(app, element, config, true);
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
break; break;
} else if (type === "replace") { } else if (type === "replace") {
replace(element, config, false); replace(app, element, config, false);
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
break; break;

View file

@ -3,8 +3,9 @@ import {fetchPost} from "../../util/fetch";
import {reloadProtyle} from "../../protyle/util/reload"; import {reloadProtyle} from "../../protyle/util/reload";
import {setInlineStyle} from "../../util/assets"; import {setInlineStyle} from "../../util/assets";
import {confirmDialog} from "../../dialog/confirmDialog"; import {confirmDialog} from "../../dialog/confirmDialog";
import {App} from "../../index";
const setEditor = (modelMainElement: Element) => { const setEditor = (app: App, modelMainElement: Element) => {
let dynamicLoadBlocks = parseInt((modelMainElement.querySelector("#dynamicLoadBlocks") as HTMLInputElement).value); let dynamicLoadBlocks = parseInt((modelMainElement.querySelector("#dynamicLoadBlocks") as HTMLInputElement).value);
if (48 > dynamicLoadBlocks) { if (48 > dynamicLoadBlocks) {
dynamicLoadBlocks = 48; dynamicLoadBlocks = 48;
@ -40,12 +41,12 @@ const setEditor = (modelMainElement: Element) => {
window.siyuan.config.editor.historyRetentionDays = parseInt((modelMainElement.querySelector("#historyRetentionDays") as HTMLInputElement).value); window.siyuan.config.editor.historyRetentionDays = parseInt((modelMainElement.querySelector("#historyRetentionDays") as HTMLInputElement).value);
fetchPost("/api/setting/setEditor", window.siyuan.config.editor, response => { fetchPost("/api/setting/setEditor", window.siyuan.config.editor, response => {
window.siyuan.config.editor = response.data; window.siyuan.config.editor = response.data;
reloadProtyle(window.siyuan.mobile.editor.protyle, false); reloadProtyle(window.siyuan.mobile.editor.protyle, app, false);
setInlineStyle(); setInlineStyle();
}); });
}; };
export const initEditor = () => { export const initEditor = (app: App) => {
openModel({ openModel({
title: window.siyuan.languages.editor, title: window.siyuan.languages.editor,
icon: "iconEdit", icon: "iconEdit",
@ -230,12 +231,12 @@ export const initEditor = () => {
modelMainElement.querySelectorAll("input.b3-switch, select.b3-select, input.b3-slider").forEach((item) => { modelMainElement.querySelectorAll("input.b3-switch, select.b3-select, input.b3-slider").forEach((item) => {
item.addEventListener("change", () => { item.addEventListener("change", () => {
setEditor(modelMainElement); setEditor(app, modelMainElement);
}); });
}); });
modelMainElement.querySelectorAll("textarea.b3-text-field, input.b3-text-field, input.b3-slider").forEach((item) => { modelMainElement.querySelectorAll("textarea.b3-text-field, input.b3-text-field, input.b3-slider").forEach((item) => {
item.addEventListener("blur", () => { item.addEventListener("blur", () => {
setEditor(modelMainElement); setEditor(app, modelMainElement);
}); });
}); });
modelMainElement.querySelectorAll("input.b3-slider").forEach((item) => { modelMainElement.querySelectorAll("input.b3-slider").forEach((item) => {

View file

@ -11,10 +11,11 @@ import {setStorageVal} from "../../protyle/util/compatibility";
import {closePanel} from "./closePanel"; import {closePanel} from "./closePanel";
import {showMessage} from "../../dialog/message"; import {showMessage} from "../../dialog/message";
import {getCurrentEditor} from "../editor"; import {getCurrentEditor} from "../editor";
import {App} from "../../index";
const forwardStack: IBackStack[] = []; const forwardStack: IBackStack[] = [];
const focusStack = (backStack: IBackStack) => { const focusStack = (backStack: IBackStack, app: App) => {
const protyle = getCurrentEditor().protyle; const protyle = getCurrentEditor().protyle;
window.siyuan.storage[Constants.LOCAL_DOCINFO] = { window.siyuan.storage[Constants.LOCAL_DOCINFO] = {
id: backStack.id, id: backStack.id,
@ -50,8 +51,14 @@ const focusStack = (backStack: IBackStack) => {
if (backStack.zoomId !== protyle.block.id) { if (backStack.zoomId !== protyle.block.id) {
fetchPost("/api/block/checkBlockExist", {id: backStack.id}, existResponse => { fetchPost("/api/block/checkBlockExist", {id: backStack.id}, existResponse => {
if (existResponse.data) { if (existResponse.data) {
zoomOut(protyle, backStack.id, undefined, false, () => { zoomOut({
protyle.contentElement.scrollTop = backStack.scrollTop; app,
protyle,
id: backStack.id,
isPushBack: false,
callback: () => {
protyle.contentElement.scrollTop = backStack.scrollTop;
}
}); });
} }
}); });
@ -104,7 +111,7 @@ export const pushBack = () => {
}); });
}; };
export const goForward = () => { export const goForward = (app: App) => {
if (window.siyuan.menus.menu.element.classList.contains("b3-menu--fullscreen") && if (window.siyuan.menus.menu.element.classList.contains("b3-menu--fullscreen") &&
!window.siyuan.menus.menu.element.classList.contains("fn__none")) { !window.siyuan.menus.menu.element.classList.contains("fn__none")) {
window.siyuan.menus.menu.element.dispatchEvent(new CustomEvent("click", {detail: "back"})); window.siyuan.menus.menu.element.dispatchEvent(new CustomEvent("click", {detail: "back"}));
@ -123,10 +130,10 @@ export const goForward = () => {
return; return;
} }
window.siyuan.backStack.push(forwardStack.pop()); window.siyuan.backStack.push(forwardStack.pop());
focusStack(forwardStack[forwardStack.length - 1]); focusStack(forwardStack[forwardStack.length - 1], app);
}; };
export const goBack = () => { export const goBack = (app: App) => {
const editor = getCurrentEditor(); const editor = getCurrentEditor();
if (window.siyuan.menus.menu.element.classList.contains("b3-menu--fullscreen") && if (window.siyuan.menus.menu.element.classList.contains("b3-menu--fullscreen") &&
!window.siyuan.menus.menu.element.classList.contains("fn__none")) { !window.siyuan.menus.menu.element.classList.contains("fn__none")) {
@ -174,5 +181,5 @@ export const goBack = () => {
} }
const item = window.siyuan.backStack.pop(); const item = window.siyuan.backStack.pop();
forwardStack.push(item); forwardStack.push(item);
focusStack(item); focusStack(item, app);
}; };

View file

@ -23,7 +23,7 @@ import {App} from "../../index";
export const initFramework = (app: App) => { export const initFramework = (app: App) => {
setInlineStyle(); setInlineStyle();
renderSnippet(); renderSnippet();
initKeyboardToolbar(); initKeyboardToolbar(app);
const sidebarElement = document.getElementById("sidebar"); const sidebarElement = document.getElementById("sidebar");
let outline: MobileOutline; let outline: MobileOutline;
let backlink: MobileBacklinks; let backlink: MobileBacklinks;

View file

@ -4,6 +4,7 @@ import {moveToDown, moveToUp} from "../../protyle/wysiwyg/move";
import {Constants} from "../../constants"; import {Constants} from "../../constants";
import {focusByRange, getSelectionPosition} from "../../protyle/util/selection"; import {focusByRange, getSelectionPosition} from "../../protyle/util/selection";
import {getCurrentEditor} from "../editor"; import {getCurrentEditor} from "../editor";
import {App} from "../../index";
let renderKeyboardToolbarTimeout: number; let renderKeyboardToolbarTimeout: number;
let showUtil = false; let showUtil = false;
@ -327,7 +328,7 @@ export const activeBlur = () => {
(document.activeElement as HTMLElement).blur(); (document.activeElement as HTMLElement).blur();
}; };
export const initKeyboardToolbar = () => { export const initKeyboardToolbar = (app: App) => {
let preventRender = false; let preventRender = false;
document.addEventListener("selectionchange", () => { document.addEventListener("selectionchange", () => {
if (!preventRender) { if (!preventRender) {
@ -416,10 +417,10 @@ export const initKeyboardToolbar = () => {
return; return;
} }
if (type === "undo") { if (type === "undo") {
protyle.undo.undo(protyle); protyle.undo.undo(app, protyle);
return; return;
} else if (type === "redo") { } else if (type === "redo") {
protyle.undo.redo(protyle); protyle.undo.redo(app, protyle);
return; return;
} }
if (getSelection().rangeCount === 0) { if (getSelection().rangeCount === 0) {
@ -475,7 +476,7 @@ export const initKeyboardToolbar = () => {
} }
return; return;
} else if (type === "more") { } else if (type === "more") {
protyle.breadcrumb.showMenu(protyle, { protyle.breadcrumb.showMenu(app, protyle, {
x: 0, x: 0,
y: 0 y: 0
}); });

View file

@ -7,8 +7,9 @@ import {Constants} from "../../constants";
import {hideAllElements, hideElements} from "../ui/hideElements"; import {hideAllElements, hideElements} from "../ui/hideElements";
import {hasClosestByClassName} from "../util/hasClosest"; import {hasClosestByClassName} from "../util/hasClosest";
import {reloadProtyle} from "../util/reload"; import {reloadProtyle} from "../util/reload";
import {App} from "../../index";
export const netImg2LocalAssets = (protyle: IProtyle) => { export const netImg2LocalAssets = (protyle: IProtyle, app: App) => {
if (protyle.element.querySelector(".wysiwygLoading")) { if (protyle.element.querySelector(".wysiwygLoading")) {
return; return;
} }
@ -18,11 +19,11 @@ export const netImg2LocalAssets = (protyle: IProtyle) => {
id: protyle.block.rootID id: protyle.block.rootID
}, () => { }, () => {
/// #if MOBILE /// #if MOBILE
reloadProtyle(protyle, false); reloadProtyle(protyle, app, false);
/// #else /// #else
getAllModels().editor.forEach(item => { getAllModels().editor.forEach(item => {
if (item.editor.protyle.block.rootID === protyle.block.rootID) { if (item.editor.protyle.block.rootID === protyle.block.rootID) {
reloadProtyle(item.editor.protyle, item.editor.protyle.element.isSameNode(protyle.element)); reloadProtyle(item.editor.protyle, app, item.editor.protyle.element.isSameNode(protyle.element));
} }
}); });
/// #endif /// #endif

View file

@ -57,25 +57,25 @@ export class Breadcrumb {
}); });
/// #endif /// #endif
} else { } else {
zoomOut(protyle, id); zoomOut({protyle, id, app});
} }
event.preventDefault(); event.preventDefault();
break; break;
} else if (target.getAttribute("data-menu") === "true") { } else if (target.getAttribute("data-menu") === "true") {
this.showMenu(protyle, { this.showMenu(app, protyle, {
x: event.clientX, x: event.clientX,
y: event.clientY y: event.clientY
}); });
event.preventDefault(); event.preventDefault();
break; break;
} else if (target.getAttribute("data-type") === "exit-focus") { } else if (target.getAttribute("data-type") === "exit-focus") {
zoomOut(protyle, protyle.block.rootID, protyle.block.id); zoomOut({protyle, id: protyle.block.rootID, focusId: protyle.block.id, app});
event.preventDefault(); event.preventDefault();
break; break;
} else if (target.getAttribute("data-type") === "context") { } else if (target.getAttribute("data-type") === "context") {
event.preventDefault(); event.preventDefault();
if (target.classList.contains("block__icon--active")) { if (target.classList.contains("block__icon--active")) {
zoomOut(protyle, protyle.options.blockId); zoomOut({protyle, id: protyle.options.blockId, app});
target.classList.remove("block__icon--active"); target.classList.remove("block__icon--active");
} else { } else {
fetchPost("/api/filetree/getDoc", { fetchPost("/api/filetree/getDoc", {
@ -83,7 +83,7 @@ export class Breadcrumb {
mode: 3, mode: 3,
size: window.siyuan.config.editor.dynamicLoadBlocks, size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => { }, getResponse => {
onGet(getResponse, protyle, [Constants.CB_GET_HL]); onGet({data: getResponse, protyle, action: [Constants.CB_GET_HL], app});
this.toggleExit(true); this.toggleExit(true);
}); });
target.classList.add("block__icon--active"); target.classList.add("block__icon--active");
@ -158,7 +158,7 @@ export class Breadcrumb {
} }
} }
public showMenu(protyle: IProtyle, position: { x: number, y: number }) { public showMenu(app: App, protyle: IProtyle, position: { x: number, y: number }) {
let id; let id;
const cursorNodeElement = hasClosestBlock(getEditorRange(protyle.element).startContainer); const cursorNodeElement = hasClosestBlock(getEditorRange(protyle.element).startContainer);
if (cursorNodeElement) { if (cursorNodeElement) {
@ -260,7 +260,7 @@ export class Breadcrumb {
icon: "iconTransform", icon: "iconTransform",
accelerator: window.siyuan.config.keymap.editor.general.netImg2LocalAsset.custom, accelerator: window.siyuan.config.keymap.editor.general.netImg2LocalAsset.custom,
click() { click() {
netImg2LocalAssets(protyle); netImg2LocalAssets(protyle, app);
} }
}).element); }).element);
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
@ -303,7 +303,7 @@ export class Breadcrumb {
accelerator: window.siyuan.config.keymap.editor.general.refresh.custom, accelerator: window.siyuan.config.keymap.editor.general.refresh.custom,
label: window.siyuan.languages.refresh, label: window.siyuan.languages.refresh,
click: () => { click: () => {
reloadProtyle(protyle, !isMobile()); reloadProtyle(protyle, app, !isMobile());
} }
}).element); }).element);
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({

View file

@ -164,7 +164,7 @@ export class Gutter {
return; return;
} }
if (event.ctrlKey || event.metaKey) { if (event.ctrlKey || event.metaKey) {
zoomOut(protyle, id); zoomOut({protyle, id, app});
} else if (event.altKey) { } else if (event.altKey) {
let foldElement: Element; let foldElement: Element;
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${id}"]`)).find(item => { Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${id}"]`)).find(item => {
@ -648,7 +648,7 @@ export class Gutter {
}); });
writeText(protyle.lute.BlockDOM2StdMd(html).trimEnd()); writeText(protyle.lute.BlockDOM2StdMd(html).trimEnd());
protyle.breadcrumb?.hide(); protyle.breadcrumb?.hide();
removeBlock(protyle, selectsElement[0], getEditorRange(selectsElement[0])); removeBlock(this.app, protyle, selectsElement[0], getEditorRange(selectsElement[0]));
} else { } else {
focusByRange(getEditorRange(selectsElement[0])); focusByRange(getEditorRange(selectsElement[0]));
document.execCommand("cut"); document.execCommand("cut");
@ -661,7 +661,7 @@ export class Gutter {
icon: "iconMove", icon: "iconMove",
click: () => { click: () => {
movePathTo((toPath) => { movePathTo((toPath) => {
hintMoveBlock(toPath[0], selectsElement, protyle); hintMoveBlock(toPath[0], selectsElement, protyle, this.app);
}); });
} }
}).element); }).element);
@ -671,7 +671,7 @@ export class Gutter {
accelerator: "⌫", accelerator: "⌫",
click: () => { click: () => {
protyle.breadcrumb?.hide(); protyle.breadcrumb?.hide();
removeBlock(protyle, selectsElement[0], getEditorRange(selectsElement[0])); removeBlock(this.app, protyle, selectsElement[0], getEditorRange(selectsElement[0]));
} }
}).element); }).element);
@ -1078,7 +1078,7 @@ export class Gutter {
click: () => { click: () => {
if (isNotEditBlock(nodeElement)) { if (isNotEditBlock(nodeElement)) {
writeText(protyle.lute.BlockDOM2StdMd(removeEmbed(nodeElement)).trimEnd()); writeText(protyle.lute.BlockDOM2StdMd(removeEmbed(nodeElement)).trimEnd());
removeBlock(protyle, nodeElement, getEditorRange(nodeElement)); removeBlock(this.app, protyle, nodeElement, getEditorRange(nodeElement));
protyle.breadcrumb?.hide(); protyle.breadcrumb?.hide();
} else { } else {
focusByRange(getEditorRange(nodeElement)); focusByRange(getEditorRange(nodeElement));
@ -1092,7 +1092,7 @@ export class Gutter {
icon: "iconMove", icon: "iconMove",
click: () => { click: () => {
movePathTo((toPath) => { movePathTo((toPath) => {
hintMoveBlock(toPath[0], [nodeElement], protyle); hintMoveBlock(toPath[0], [nodeElement], protyle, this.app);
}); });
} }
}).element); }).element);
@ -1102,7 +1102,7 @@ export class Gutter {
accelerator: "⌫", accelerator: "⌫",
click: () => { click: () => {
protyle.breadcrumb?.hide(); protyle.breadcrumb?.hide();
removeBlock(protyle, nodeElement, getEditorRange(nodeElement)); removeBlock(this.app, protyle, nodeElement, getEditorRange(nodeElement));
} }
}).element); }).element);
} }
@ -1401,8 +1401,8 @@ export class Gutter {
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
accelerator: `${updateHotkeyTip(window.siyuan.config.keymap.general.enter.custom)}/${updateHotkeyTip("⌘Click")}`, accelerator: `${updateHotkeyTip(window.siyuan.config.keymap.general.enter.custom)}/${updateHotkeyTip("⌘Click")}`,
label: window.siyuan.languages.enter, label: window.siyuan.languages.enter,
click() { click:()=> {
zoomOut(protyle, id); zoomOut({protyle, id, app: this.app});
} }
}).element); }).element);
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
@ -1423,7 +1423,7 @@ export class Gutter {
/// #endif /// #endif
} }
} else { } else {
zoomOut(protyle, protyle.block.parent2ID, id); zoomOut({protyle, id:protyle.block.parent2ID, focusId:id, app: this.app});
} }
} }
}).element); }).element);

View file

@ -19,6 +19,7 @@ import {zoomOut} from "../../menus/protyle";
import {hideElements} from "../ui/hideElements"; import {hideElements} from "../ui/hideElements";
import {genAssetHTML} from "../../asset/renderAssets"; import {genAssetHTML} from "../../asset/renderAssets";
import {unicode2Emoji} from "../../emoji"; import {unicode2Emoji} from "../../emoji";
import {App} from "../../index";
export const hintSlash = (key: string, protyle: IProtyle) => { export const hintSlash = (key: string, protyle: IProtyle) => {
const allList: IHintData[] = [{ const allList: IHintData[] = [{
@ -461,7 +462,7 @@ export const hintRenderAssets = (value: string, protyle: IProtyle) => {
hideElements(["util"], protyle); hideElements(["util"], protyle);
}; };
export const hintMoveBlock = (pathString: string, sourceElements: Element[], protyle: IProtyle) => { export const hintMoveBlock = (pathString: string, sourceElements: Element[], protyle: IProtyle, app: App) => {
if (pathString === "/") { if (pathString === "/") {
return; return;
} }
@ -512,7 +513,7 @@ export const hintMoveBlock = (pathString: string, sourceElements: Element[], pro
}); });
} else if (protyle.block.showAll && parentElement.classList.contains("protyle-wysiwyg") && parentElement.childElementCount === 0) { } else if (protyle.block.showAll && parentElement.classList.contains("protyle-wysiwyg") && parentElement.childElementCount === 0) {
setTimeout(() => { setTimeout(() => {
zoomOut(protyle, protyle.block.parent2ID, protyle.block.parent2ID); zoomOut({app, protyle, id: protyle.block.parent2ID, focusId:protyle.block.parent2ID});
}, Constants.TIMEOUT_INPUT * 2 + 100); }, Constants.TIMEOUT_INPUT * 2 + 100);
} else if (parentElement.classList.contains("protyle-wysiwyg") && parentElement.innerHTML === "" && } else if (parentElement.classList.contains("protyle-wysiwyg") && parentElement.innerHTML === "" &&
!hasClosestByClassName(parentElement, "block__edit", true) && !hasClosestByClassName(parentElement, "block__edit", true) &&

View file

@ -77,7 +77,7 @@ export class Protyle {
this.protyle.undo = new Undo(); this.protyle.undo = new Undo();
this.protyle.wysiwyg = new WYSIWYG(app, this.protyle); this.protyle.wysiwyg = new WYSIWYG(app, this.protyle);
this.protyle.toolbar = new Toolbar(app, this.protyle); this.protyle.toolbar = new Toolbar(app, this.protyle);
this.protyle.scroll = new Scroll(this.protyle); // 不能使用 render.scroll 来判读是否初始化,除非重构后面用到的相关变量 this.protyle.scroll = new Scroll(this.protyle, this.app); // 不能使用 render.scroll 来判读是否初始化,除非重构后面用到的相关变量
if (this.protyle.options.render.gutter) { if (this.protyle.options.render.gutter) {
this.protyle.gutter = new Gutter(app, this.protyle); this.protyle.gutter = new Gutter(app, this.protyle);
} }
@ -95,7 +95,7 @@ export class Protyle {
switch (data.cmd) { switch (data.cmd) {
case "reload": case "reload":
if (data.data === this.protyle.block.rootID) { if (data.data === this.protyle.block.rootID) {
reloadProtyle(this.protyle, false); reloadProtyle(this.protyle, app, false);
} }
break; break;
case "addLoading": case "addLoading":
@ -105,7 +105,7 @@ export class Protyle {
break; break;
case "transactions": case "transactions":
data.data[0].doOperations.forEach((item: IOperation) => { data.data[0].doOperations.forEach((item: IOperation) => {
onTransaction(this.protyle, item, false); onTransaction(app, this.protyle, item, false);
}); });
break; break;
case "readonly": case "readonly":
@ -123,10 +123,10 @@ export class Protyle {
id: this.protyle.block.rootID, id: this.protyle.block.rootID,
size: window.siyuan.config.editor.dynamicLoadBlocks, size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => { }, getResponse => {
onGet(getResponse, this.protyle); onGet({data: getResponse, protyle: this.protyle, app: this.app});
}); });
} else { } else {
reloadProtyle(this.protyle, false); reloadProtyle(this.protyle, app, false);
} }
/// #if !MOBILE /// #if !MOBILE
if (data.cmd === "heading2doc") { if (data.cmd === "heading2doc") {
@ -224,6 +224,7 @@ export class Protyle {
if (scrollObj) { if (scrollObj) {
scrollObj.rootId = response.data.rootID; scrollObj.rootId = response.data.rootID;
getDocByScroll({ getDocByScroll({
app: this.app,
protyle: this.protyle, protyle: this.protyle,
scrollAttr: scrollObj, scrollAttr: scrollObj,
mergedOptions, mergedOptions,
@ -237,6 +238,7 @@ export class Protyle {
}); });
} else { } else {
getDocByScroll({ getDocByScroll({
app: this.app,
protyle: this.protyle, protyle: this.protyle,
scrollAttr: options.scrollAttr, scrollAttr: options.scrollAttr,
mergedOptions, mergedOptions,
@ -260,7 +262,7 @@ export class Protyle {
mode: (mergedOptions.action && mergedOptions.action.includes(Constants.CB_GET_CONTEXT)) ? 3 : 0, mode: (mergedOptions.action && mergedOptions.action.includes(Constants.CB_GET_CONTEXT)) ? 3 : 0,
size: mergedOptions.action?.includes(Constants.CB_GET_ALL) ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks, size: mergedOptions.action?.includes(Constants.CB_GET_ALL) ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => { }, getResponse => {
onGet(getResponse, this.protyle, mergedOptions.action); onGet({data: getResponse, protyle: this.protyle, app: this.app, action: mergedOptions.action});
this.afterOnGet(mergedOptions); this.afterOnGet(mergedOptions);
}); });
} }
@ -330,7 +332,7 @@ export class Protyle {
this.protyle.preview = new Preview(this.app, this.protyle); this.protyle.preview = new Preview(this.app, this.protyle);
initUI(this.protyle); initUI(this.protyle, this.app);
} }
/** 聚焦到编辑器 */ /** 聚焦到编辑器 */

View file

@ -4,9 +4,10 @@ import {fetchPost} from "../../util/fetch";
import {onGet} from "../util/onGet"; import {onGet} from "../util/onGet";
import {isMobile} from "../../util/functions"; import {isMobile} from "../../util/functions";
import {hasClosestBlock, hasClosestByClassName} from "../util/hasClosest"; import {hasClosestBlock, hasClosestByClassName} from "../util/hasClosest";
import {App} from "../../index";
let getIndexTimeout: number; let getIndexTimeout: number;
export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => { export const scrollEvent = (app: App, protyle: IProtyle, element: HTMLElement) => {
let elementRect = element.getBoundingClientRect(); let elementRect = element.getBoundingClientRect();
element.addEventListener("scroll", () => { element.addEventListener("scroll", () => {
if (!protyle.toolbar.element.classList.contains("fn__none")) { if (!protyle.toolbar.element.classList.contains("fn__none")) {
@ -70,7 +71,12 @@ export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => {
}, getResponse => { }, getResponse => {
protyle.contentElement.style.overflow = ""; protyle.contentElement.style.overflow = "";
protyle.contentElement.style.width = ""; protyle.contentElement.style.width = "";
onGet(getResponse, protyle, [Constants.CB_GET_BEFORE, Constants.CB_GET_UNCHANGEID]); onGet({
data: getResponse,
protyle,
action: [Constants.CB_GET_BEFORE, Constants.CB_GET_UNCHANGEID],
app
});
}); });
} }
} else if ((element.scrollTop > element.scrollHeight - element.clientHeight * 1.8) && } else if ((element.scrollTop > element.scrollHeight - element.clientHeight * 1.8) &&
@ -82,7 +88,12 @@ export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => {
mode: 2, mode: 2,
size: window.siyuan.config.editor.dynamicLoadBlocks, size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => { }, getResponse => {
onGet(getResponse, protyle, [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID]); onGet({
data: getResponse,
protyle,
action: [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID],
app
});
}); });
} }
protyle.scroll.lastScrollTop = Math.max(element.scrollTop, 0); protyle.scroll.lastScrollTop = Math.max(element.scrollTop, 0);

View file

@ -5,6 +5,7 @@ import {updateHotkeyTip} from "../util/compatibility";
import {hasClosestByClassName} from "../util/hasClosest"; import {hasClosestByClassName} from "../util/hasClosest";
import {goEnd, goHome} from "../wysiwyg/commonHotkey"; import {goEnd, goHome} from "../wysiwyg/commonHotkey";
import {isMobile} from "../../util/functions"; import {isMobile} from "../../util/functions";
import {App} from "../../index";
export class Scroll { export class Scroll {
public element: HTMLElement; public element: HTMLElement;
@ -13,7 +14,7 @@ export class Scroll {
public lastScrollTop: number; public lastScrollTop: number;
public keepLazyLoad: boolean; // 保持加载内容 public keepLazyLoad: boolean; // 保持加载内容
constructor(protyle: IProtyle) { constructor(protyle: IProtyle, app: App) {
this.parentElement = document.createElement("div"); this.parentElement = document.createElement("div");
this.parentElement.classList.add("protyle-scroll"); this.parentElement.classList.add("protyle-scroll");
if (!isMobile()) { if (!isMobile()) {
@ -41,25 +42,25 @@ export class Scroll {
}); });
/// #if BROWSER /// #if BROWSER
this.inputElement.addEventListener("change", () => { this.inputElement.addEventListener("change", () => {
this.setIndex(protyle); this.setIndex(protyle, app);
}); });
this.inputElement.addEventListener("touchend", () => { this.inputElement.addEventListener("touchend", () => {
this.setIndex(protyle); this.setIndex(protyle, app);
}); });
/// #endif /// #endif
this.parentElement.addEventListener("click", (event) => { this.parentElement.addEventListener("click", (event) => {
const target = event.target as HTMLElement; const target = event.target as HTMLElement;
if (hasClosestByClassName(target, "protyle-scroll__up")) { if (hasClosestByClassName(target, "protyle-scroll__up")) {
goHome(protyle); goHome(protyle, app);
} else if (hasClosestByClassName(target, "protyle-scroll__down")) { } else if (hasClosestByClassName(target, "protyle-scroll__down")) {
goEnd(protyle); goEnd(protyle, app);
} else if (target.classList.contains("b3-slider")) { } else if (target.classList.contains("b3-slider")) {
this.setIndex(protyle); this.setIndex(protyle, app);
} }
}); });
} }
private setIndex(protyle: IProtyle) { private setIndex(protyle: IProtyle, app: App) {
if (protyle.wysiwyg.element.getAttribute("data-top")) { if (protyle.wysiwyg.element.getAttribute("data-top")) {
return; return;
} }
@ -70,7 +71,12 @@ export class Scroll {
mode: 0, mode: 0,
size: window.siyuan.config.editor.dynamicLoadBlocks, size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => { }, getResponse => {
onGet(getResponse, protyle, [Constants.CB_GET_FOCUSFIRST, Constants.CB_GET_UNCHANGEID]); onGet({
data: getResponse,
protyle,
action: [Constants.CB_GET_FOCUSFIRST, Constants.CB_GET_UNCHANGEID],
app
});
}); });
} }

View file

@ -3,6 +3,7 @@ import {getSelectionOffset} from "../util/selection";
import {fetchPost} from "../../util/fetch"; import {fetchPost} from "../../util/fetch";
import {onGet} from "../util/onGet"; import {onGet} from "../util/onGet";
import {Constants} from "../../constants"; import {Constants} from "../../constants";
import {App} from "../../index";
export const saveScroll = (protyle: IProtyle, getObject = false) => { export const saveScroll = (protyle: IProtyle, getObject = false) => {
if (!protyle.wysiwyg.element.firstElementChild || window.siyuan.config.readonly) { if (!protyle.wysiwyg.element.firstElementChild || window.siyuan.config.readonly) {
@ -45,6 +46,7 @@ export const saveScroll = (protyle: IProtyle, getObject = false) => {
}; };
export const getDocByScroll = (options: { export const getDocByScroll = (options: {
app: App,
protyle: IProtyle, protyle: IProtyle,
scrollAttr: IScrollAttr, scrollAttr: IScrollAttr,
mergedOptions?: IOptions, mergedOptions?: IOptions,
@ -68,7 +70,13 @@ export const getDocByScroll = (options: {
}, response => { }, response => {
actions.push(Constants.CB_GET_ALL); actions.push(Constants.CB_GET_ALL);
options.protyle.breadcrumb?.toggleExit(false); options.protyle.breadcrumb?.toggleExit(false);
onGet(response, options.protyle, actions, options.scrollAttr); onGet({
data: response,
protyle: options.protyle,
action: actions,
scrollAttr: options.scrollAttr,
app: options.app
});
if (options.cb) { if (options.cb) {
options.cb(); options.cb();
} }
@ -81,7 +89,13 @@ export const getDocByScroll = (options: {
endID: options.scrollAttr.endId, endID: options.scrollAttr.endId,
}, response => { }, response => {
options.protyle.breadcrumb?.toggleExit(true); options.protyle.breadcrumb?.toggleExit(true);
onGet(response, options.protyle, actions, options.scrollAttr); onGet({
data: response,
protyle: options.protyle,
action: actions,
scrollAttr: options.scrollAttr,
app: options.app
});
if (options.cb) { if (options.cb) {
options.cb(); options.cb();
} }

View file

@ -7,8 +7,9 @@ import {hasClosestByAttribute, hasClosestByClassName} from "../util/hasClosest";
import {isMac} from "../util/compatibility"; import {isMac} from "../util/compatibility";
import {setInlineStyle} from "../../util/assets"; import {setInlineStyle} from "../../util/assets";
import {fetchPost} from "../../util/fetch"; import {fetchPost} from "../../util/fetch";
import {App} from "../../index";
export const initUI = (protyle: IProtyle) => { export const initUI = (protyle: IProtyle, app: App) => {
protyle.contentElement = document.createElement("div"); protyle.contentElement = document.createElement("div");
protyle.contentElement.className = "protyle-content"; protyle.contentElement.className = "protyle-content";
if (window.siyuan.config.editor.fullWidth) { if (window.siyuan.config.editor.fullWidth) {
@ -24,7 +25,7 @@ export const initUI = (protyle: IProtyle) => {
} }
protyle.contentElement.appendChild(protyle.wysiwyg.element); protyle.contentElement.appendChild(protyle.wysiwyg.element);
if (!protyle.options.action.includes(Constants.CB_GET_HISTORY)) { if (!protyle.options.action.includes(Constants.CB_GET_HISTORY)) {
scrollEvent(protyle, protyle.contentElement); scrollEvent(app, protyle, protyle.contentElement);
} }
protyle.element.append(protyle.contentElement); protyle.element.append(protyle.contentElement);
protyle.element.appendChild(protyle.preview.element); protyle.element.appendChild(protyle.preview.element);

View file

@ -7,6 +7,7 @@ import {scrollCenter} from "../../util/highlightById";
import {getCurrentWindow} from "@electron/remote"; import {getCurrentWindow} from "@electron/remote";
/// #endif /// #endif
import {matchHotKey} from "../util/hotKey"; import {matchHotKey} from "../util/hotKey";
import {App} from "../../index";
interface IOperations { interface IOperations {
doOperations: IOperation[], doOperations: IOperation[],
@ -23,7 +24,7 @@ export class Undo {
this.undoStack = []; this.undoStack = [];
} }
public undo(protyle: IProtyle) { public undo(app: App, protyle: IProtyle) {
if (protyle.disabled) { if (protyle.disabled) {
return; return;
} }
@ -31,13 +32,13 @@ export class Undo {
return; return;
} }
const state = this.undoStack.pop(); const state = this.undoStack.pop();
this.render(protyle, state, false); this.render(app, protyle, state, false);
this.hasUndo = true; this.hasUndo = true;
this.redoStack.push(state); this.redoStack.push(state);
} }
public redo(protyle: IProtyle) { public redo(app: App, protyle: IProtyle) {
if (protyle.disabled) { if (protyle.disabled) {
return; return;
} }
@ -45,21 +46,21 @@ export class Undo {
return; return;
} }
const state = this.redoStack.pop(); const state = this.redoStack.pop();
this.render(protyle, state, true); this.render(app, protyle, state, true);
this.undoStack.push(state); this.undoStack.push(state);
} }
private render(protyle: IProtyle, state: IOperations, redo: boolean) { private render(app: App, protyle: IProtyle, state: IOperations, redo: boolean) {
hideElements(["hint", "gutter"], protyle); hideElements(["hint", "gutter"], protyle);
protyle.wysiwyg.lastHTMLs = {}; protyle.wysiwyg.lastHTMLs = {};
if (!redo) { if (!redo) {
state.undoOperations.forEach(item => { state.undoOperations.forEach(item => {
onTransaction(protyle, item, true); onTransaction(app, protyle, item, true);
}); });
transaction(protyle, state.undoOperations); transaction(protyle, state.undoOperations);
} else { } else {
state.doOperations.forEach(item => { state.doOperations.forEach(item => {
onTransaction(protyle, item, true); onTransaction(app, protyle, item, true);
}); });
transaction(protyle, state.doOperations); transaction(protyle, state.doOperations);
} }

View file

@ -19,6 +19,7 @@ import {uploadLocalFiles} from "../upload";
import {insertHTML} from "./insertHTML"; import {insertHTML} from "./insertHTML";
import {isBrowser} from "../../util/functions"; import {isBrowser} from "../../util/functions";
import {hideElements} from "../ui/hideElements"; import {hideElements} from "../ui/hideElements";
import {App} from "../../index";
const moveToNew = (protyle: IProtyle, sourceElements: Element[], targetElement: Element, newSourceElement: Element, const moveToNew = (protyle: IProtyle, sourceElements: Element[], targetElement: Element, newSourceElement: Element,
isSameDoc: boolean, isBottom: boolean, isCopy: boolean) => { isSameDoc: boolean, isBottom: boolean, isCopy: boolean) => {
@ -695,7 +696,7 @@ const dragSame = async (protyle: IProtyle, sourceElements: Element[], targetElem
focusBlock(sourceElements[0]); focusBlock(sourceElements[0]);
}; };
export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => { export const dropEvent = (app: App, protyle: IProtyle, editorElement: HTMLElement) => {
editorElement.addEventListener("dragstart", (event) => { editorElement.addEventListener("dragstart", (event) => {
const target = event.target as HTMLElement; const target = event.target as HTMLElement;
if (target.tagName === "IMG") { if (target.tagName === "IMG") {
@ -852,7 +853,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
id: protyle.block.id, id: protyle.block.id,
size: window.siyuan.config.editor.dynamicLoadBlocks, size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => { }, getResponse => {
onGet(getResponse, protyle); onGet({data: getResponse, protyle, app});
/// #if !MOBILE /// #if !MOBILE
// 文档标题互转后,需更新大纲 // 文档标题互转后,需更新大纲
updatePanelByEditor({ updatePanelByEditor({

View file

@ -16,84 +16,94 @@ import {removeLoading} from "../ui/initUI";
import {isMobile} from "../../util/functions"; import {isMobile} from "../../util/functions";
import {foldPassiveType} from "../wysiwyg/renderBacklink"; import {foldPassiveType} from "../wysiwyg/renderBacklink";
import {showMessage} from "../../dialog/message"; import {showMessage} from "../../dialog/message";
import {App} from "../../index";
export const onGet = (data: IWebSocketData, protyle: IProtyle, action: string[] = [], scrollAttr?: IScrollAttr) => { export const onGet = (options: {
protyle.wysiwyg.element.removeAttribute("data-top"); data: IWebSocketData,
if (data.code === 1) { protyle: IProtyle,
action?: string[],
scrollAttr?: IScrollAttr
app: App
}) => {
if (!options.action) {
options.action = [];
}
options.protyle.wysiwyg.element.removeAttribute("data-top");
if (options.data.code === 1) {
// 其他报错 // 其他报错
if (protyle.model) { if (options.protyle.model) {
protyle.model.parent.parent.removeTab(protyle.model.parent.id, false, false); options.protyle.model.parent.parent.removeTab(options.protyle.model.parent.id, false, false);
} else { } else {
protyle.element.innerHTML = `<div class="ft__smaller ft__secondary b3-form__space--small" contenteditable="false">${window.siyuan.languages.refExpired}</div>`; options.protyle.element.innerHTML = `<div class="ft__smaller ft__secondary b3-form__space--small" contenteditable="false">${window.siyuan.languages.refExpired}</div>`;
} }
return; return;
} }
if (data.code === 3) { if (options.data.code === 3) {
// block not found // block not found
return; return;
} }
protyle.notebookId = data.data.box; options.protyle.notebookId = options.data.data.box;
protyle.path = data.data.path; options.protyle.path = options.data.data.path;
if (data.data.eof && !scrollAttr) { if (options.data.data.eof && !options.scrollAttr) {
if (action.includes(Constants.CB_GET_BEFORE)) { if (options.action.includes(Constants.CB_GET_BEFORE)) {
protyle.wysiwyg.element.firstElementChild.setAttribute("data-eof", "1"); options.protyle.wysiwyg.element.firstElementChild.setAttribute("data-eof", "1");
} else { } else {
protyle.wysiwyg.element.lastElementChild.setAttribute("data-eof", "2"); options.protyle.wysiwyg.element.lastElementChild.setAttribute("data-eof", "2");
} }
if (data.data.mode !== 4) { if (options.data.data.mode !== 4) {
return; return;
} }
} }
hideElements(["gutter"], protyle); hideElements(["gutter"], options.protyle);
protyle.block.parentID = data.data.parentID; options.protyle.block.parentID = options.data.data.parentID;
protyle.block.parent2ID = data.data.parent2ID; options.protyle.block.parent2ID = options.data.data.parent2ID;
protyle.block.rootID = data.data.rootID; options.protyle.block.rootID = options.data.data.rootID;
protyle.block.showAll = false; options.protyle.block.showAll = false;
protyle.block.mode = data.data.mode; options.protyle.block.mode = options.data.data.mode;
protyle.block.blockCount = data.data.blockCount; options.protyle.block.blockCount = options.data.data.blockCount;
protyle.block.scroll = data.data.scroll; options.protyle.block.scroll = options.data.data.scroll;
protyle.block.action = action; options.protyle.block.action = options.action;
if (!action.includes(Constants.CB_GET_UNCHANGEID)) { if (!options.action.includes(Constants.CB_GET_UNCHANGEID)) {
protyle.block.id = data.data.id; // 非缩放情况时不一定是 rootID搜索打开页签缩放时必为缩放 id否则需查看代码 options.protyle.block.id = options.data.data.id; // 非缩放情况时不一定是 rootID搜索打开页签缩放时必为缩放 id否则需查看代码
protyle.scroll.lastScrollTop = 0; options.protyle.scroll.lastScrollTop = 0;
protyle.contentElement.scrollTop = 0; options.protyle.contentElement.scrollTop = 0;
protyle.wysiwyg.element.setAttribute("data-doc-type", data.data.type); options.protyle.wysiwyg.element.setAttribute("data-doc-type", options.data.data.type);
} }
// 防止动态加载加载过多的内容 // 防止动态加载加载过多的内容
if (action.includes(Constants.CB_GET_APPEND) || action.includes(Constants.CB_GET_BEFORE) || action.includes(Constants.CB_GET_HTML)) { if (options.action.includes(Constants.CB_GET_APPEND) || options.action.includes(Constants.CB_GET_BEFORE) || options.action.includes(Constants.CB_GET_HTML)) {
setHTML({ setHTML({
content: data.data.content, content: options.data.data.content,
expand: data.data.isBacklinkExpand, expand: options.data.data.isBacklinkExpand,
action, action: options.action,
scrollAttr, scrollAttr: options.scrollAttr,
isSyncing: data.data.isSyncing, isSyncing: options.data.data.isSyncing,
}, protyle); }, options.protyle, options.app);
removeLoading(protyle); removeLoading(options.protyle);
return; return;
} }
fetchPost("/api/block/getDocInfo", { fetchPost("/api/block/getDocInfo", {
id: protyle.block.rootID id: options.protyle.block.rootID
}, (response) => { }, (response) => {
if (protyle.options.render.title) { if (options.protyle.options.render.title) {
// 页签没有打开 // 页签没有打开
protyle.title.render(protyle, response); options.protyle.title.render(options.protyle, response);
} else if (protyle.options.render.background) { } else if (options.protyle.options.render.background) {
protyle.background.render(response.data.ial, protyle.block.rootID); options.protyle.background.render(response.data.ial, options.protyle.block.rootID);
protyle.wysiwyg.renderCustom(response.data.ial); options.protyle.wysiwyg.renderCustom(response.data.ial);
} }
setHTML({ setHTML({
content: data.data.content, content: options.data.data.content,
expand: data.data.isBacklinkExpand, expand: options.data.data.isBacklinkExpand,
action, action: options.action,
scrollAttr, scrollAttr: options.scrollAttr,
isSyncing: data.data.isSyncing, isSyncing: options.data.data.isSyncing,
}, protyle); }, options.protyle, options.app);
setTitle(response.data.ial.title); setTitle(response.data.ial.title);
removeLoading(protyle); removeLoading(options.protyle);
}); });
}; };
@ -103,7 +113,7 @@ const setHTML = (options: {
isSyncing: boolean, isSyncing: boolean,
expand: boolean, expand: boolean,
scrollAttr?: IScrollAttr scrollAttr?: IScrollAttr
}, protyle: IProtyle) => { }, protyle: IProtyle, app: App) => {
if (protyle.contentElement.classList.contains("fn__none")) { if (protyle.contentElement.classList.contains("fn__none")) {
return; return;
} }
@ -251,7 +261,7 @@ const setHTML = (options: {
mode: 2, mode: 2,
size: window.siyuan.config.editor.dynamicLoadBlocks, size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => { }, getResponse => {
onGet(getResponse, protyle, [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID]); onGet({data: getResponse, protyle, action: [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID], app});
}); });
} }
if (options.action.includes(Constants.CB_GET_APPEND) || options.action.includes(Constants.CB_GET_BEFORE)) { if (options.action.includes(Constants.CB_GET_APPEND) || options.action.includes(Constants.CB_GET_BEFORE)) {

View file

@ -4,8 +4,9 @@ import {getDocByScroll, saveScroll} from "../scroll/saveScroll";
import {renderBacklink} from "../wysiwyg/renderBacklink"; import {renderBacklink} from "../wysiwyg/renderBacklink";
import {hasClosestByClassName} from "./hasClosest"; import {hasClosestByClassName} from "./hasClosest";
import {preventScroll} from "../scroll/preventScroll"; import {preventScroll} from "../scroll/preventScroll";
import {App} from "../../index";
export const reloadProtyle = (protyle: IProtyle, focus: boolean) => { export const reloadProtyle = (protyle: IProtyle, app: App, focus: boolean) => {
if (window.siyuan.config.editor.displayBookmarkIcon) { if (window.siyuan.config.editor.displayBookmarkIcon) {
protyle.wysiwyg.element.classList.add("protyle-wysiwyg--attr"); protyle.wysiwyg.element.classList.add("protyle-wysiwyg--attr");
} else { } else {
@ -39,6 +40,7 @@ export const reloadProtyle = (protyle: IProtyle, focus: boolean) => {
} else { } else {
preventScroll(protyle); preventScroll(protyle);
getDocByScroll({ getDocByScroll({
app,
protyle, protyle,
focus, focus,
scrollAttr: saveScroll(protyle, true) scrollAttr: saveScroll(protyle, true)

View file

@ -36,7 +36,7 @@ export const commonHotkey = (app: App, protyle: IProtyle, event: KeyboardEvent)
} }
if (matchHotKey(window.siyuan.config.keymap.editor.general.netImg2LocalAsset.custom, event)) { if (matchHotKey(window.siyuan.config.keymap.editor.general.netImg2LocalAsset.custom, event)) {
netImg2LocalAssets(protyle); netImg2LocalAssets(protyle, app);
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
return true; return true;
@ -228,7 +228,7 @@ export const duplicateBlock = (nodeElements: Element[], protyle: IProtyle) => {
scrollCenter(protyle); scrollCenter(protyle);
}; };
export const goHome = (protyle: IProtyle) => { export const goHome = (protyle: IProtyle, app: App) => {
if (protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-index") === "0" || if (protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-index") === "0" ||
protyle.wysiwyg.element.firstElementChild.getAttribute("data-eof") === "1" || protyle.wysiwyg.element.firstElementChild.getAttribute("data-eof") === "1" ||
protyle.options.backlinkData) { protyle.options.backlinkData) {
@ -241,12 +241,12 @@ export const goHome = (protyle: IProtyle) => {
mode: 0, mode: 0,
size: window.siyuan.config.editor.dynamicLoadBlocks, size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => { }, getResponse => {
onGet(getResponse, protyle, [Constants.CB_GET_FOCUS]); onGet({data: getResponse, protyle, action: [Constants.CB_GET_FOCUS], app});
}); });
} }
}; };
export const goEnd = (protyle: IProtyle) => { export const goEnd = (protyle: IProtyle, app: App) => {
if (!protyle.scroll.element.classList.contains("fn__none") && if (!protyle.scroll.element.classList.contains("fn__none") &&
protyle.wysiwyg.element.lastElementChild.getAttribute("data-eof") !== "2") { protyle.wysiwyg.element.lastElementChild.getAttribute("data-eof") !== "2") {
fetchPost("/api/filetree/getDoc", { fetchPost("/api/filetree/getDoc", {
@ -254,7 +254,7 @@ export const goEnd = (protyle: IProtyle) => {
mode: 4, mode: 4,
size: window.siyuan.config.editor.dynamicLoadBlocks, size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => { }, getResponse => {
onGet(getResponse, protyle, [Constants.CB_GET_FOCUS]); onGet({data: getResponse, protyle, action: [Constants.CB_GET_FOCUS], app});
}); });
} else { } else {
protyle.contentElement.scrollTop = protyle.contentElement.scrollHeight; protyle.contentElement.scrollTop = protyle.contentElement.scrollHeight;

View file

@ -95,7 +95,7 @@ export class WYSIWYG {
} }
this.bindEvent(protyle); this.bindEvent(protyle);
keydown(app, protyle, this.element); keydown(app, protyle, this.element);
dropEvent(protyle, this.element); dropEvent(app, protyle, this.element);
} }
public renderCustom(ial: IObject) { public renderCustom(ial: IObject) {
@ -1025,7 +1025,7 @@ export class WYSIWYG {
} }
} }
const nextElement = getNextBlock(selectElements[selectElements.length - 1]); const nextElement = getNextBlock(selectElements[selectElements.length - 1]);
removeBlock(protyle, nodeElement, range); removeBlock(this.app, protyle, nodeElement, range);
if (nextElement) { if (nextElement) {
// Ctrl+X 剪切后光标应跳到下一行行首 https://github.com/siyuan-note/siyuan/issues/5485 // Ctrl+X 剪切后光标应跳到下一行行首 https://github.com/siyuan-note/siyuan/issues/5485
focusBlock(nextElement); focusBlock(nextElement);
@ -1299,7 +1299,12 @@ export class WYSIWYG {
size: window.siyuan.config.editor.dynamicLoadBlocks, size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => { }, getResponse => {
preventGetTopHTML = false; preventGetTopHTML = false;
onGet(getResponse, protyle, [Constants.CB_GET_BEFORE, Constants.CB_GET_UNCHANGEID]); onGet({
data: getResponse,
protyle,
action: [Constants.CB_GET_BEFORE, Constants.CB_GET_UNCHANGEID],
app: this.app
});
}); });
preventGetTopHTML = true; preventGetTopHTML = true;
} }
@ -1860,7 +1865,7 @@ export class WYSIWYG {
} else if (event.shiftKey) { } else if (event.shiftKey) {
openAttr(actionElement.parentElement, protyle); openAttr(actionElement.parentElement, protyle);
} else if (ctrlIsPressed) { } else if (ctrlIsPressed) {
zoomOut(protyle, actionElement.parentElement.getAttribute("data-node-id")); zoomOut({protyle, id: actionElement.parentElement.getAttribute("data-node-id"), app: this.app});
} else { } else {
if (actionElement.classList.contains("protyle-action--task")) { if (actionElement.classList.contains("protyle-action--task")) {
const html = actionElement.parentElement.outerHTML; const html = actionElement.parentElement.outerHTML;

View file

@ -431,7 +431,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
topNodeElement.nextElementSibling?.classList.contains("list") && topNodeElement.previousElementSibling.classList.contains("protyle-action")) { topNodeElement.nextElementSibling?.classList.contains("list") && topNodeElement.previousElementSibling.classList.contains("protyle-action")) {
topNodeElement = topNodeElement.parentElement; topNodeElement = topNodeElement.parentElement;
} }
zoomOut(protyle, topNodeElement.getAttribute("data-node-id")); zoomOut({protyle, id:topNodeElement.getAttribute("data-node-id"), app});
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
return; return;
@ -448,7 +448,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
}); });
} }
} else { } else {
zoomOut(protyle, protyle.block.parent2ID, nodeElement.getAttribute("data-node-id")); zoomOut({protyle, id:protyle.block.parent2ID, focusId:nodeElement.getAttribute("data-node-id"), app});
} }
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
@ -477,14 +477,14 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
} }
// ctrl+home 光标移动到顶 // ctrl+home 光标移动到顶
if (!event.altKey && !event.shiftKey && isCtrl(event) && event.key === "Home") { if (!event.altKey && !event.shiftKey && isCtrl(event) && event.key === "Home") {
goHome(protyle); goHome(protyle, app);
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
return; return;
} }
// ctrl+end 光标移动到尾 // ctrl+end 光标移动到尾
if (!event.altKey && !event.shiftKey && isCtrl(event) && event.key === "End") { if (!event.altKey && !event.shiftKey && isCtrl(event) && event.key === "End") {
goEnd(protyle); goEnd(protyle, app);
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
return; return;
@ -694,7 +694,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
// 不可使用 !event.shiftKey否则 https://ld246.com/article/1666434796806 // 不可使用 !event.shiftKey否则 https://ld246.com/article/1666434796806
if (!event.altKey && (event.key === "Backspace" || event.key === "Delete")) { if (!event.altKey && (event.key === "Backspace" || event.key === "Delete")) {
if (protyle.wysiwyg.element.querySelector(".protyle-wysiwyg--select")) { if (protyle.wysiwyg.element.querySelector(".protyle-wysiwyg--select")) {
removeBlock(protyle, nodeElement, range); removeBlock(app, protyle, nodeElement, range);
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
return; return;
@ -736,7 +736,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
previousSibling.nodeType !== 3 && (previousSibling as HTMLElement).outerHTML === "<span>\\</span>" && previousSibling.nodeType !== 3 && (previousSibling as HTMLElement).outerHTML === "<span>\\</span>" &&
!hasPreviousSibling(previousSibling.parentElement)) { !hasPreviousSibling(previousSibling.parentElement)) {
range.setStartBefore(previousSibling.parentElement); range.setStartBefore(previousSibling.parentElement);
removeBlock(protyle, nodeElement, range); removeBlock(app, protyle, nodeElement, range);
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
return; return;
@ -746,7 +746,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
range.startContainer.parentElement.getAttribute("data-type")?.indexOf("backslash") > -1 && range.startContainer.parentElement.getAttribute("data-type")?.indexOf("backslash") > -1 &&
!hasPreviousSibling(range.startContainer.parentElement)) { !hasPreviousSibling(range.startContainer.parentElement)) {
range.setStartBefore(range.startContainer.parentElement); range.setStartBefore(range.startContainer.parentElement);
removeBlock(protyle, nodeElement, range); removeBlock(app, protyle, nodeElement, range);
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
return; return;
@ -768,7 +768,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
const editElement = getContenteditableElement(nodeElement); const editElement = getContenteditableElement(nodeElement);
if (!editElement) { if (!editElement) {
nodeElement.classList.add("protyle-wysiwyg--select"); nodeElement.classList.add("protyle-wysiwyg--select");
removeBlock(protyle, nodeElement, range); removeBlock(app, protyle, nodeElement, range);
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
return; return;
@ -783,7 +783,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
if (nextRange) { if (nextRange) {
const nextBlockElement = hasClosestBlock(nextRange.startContainer); const nextBlockElement = hasClosestBlock(nextRange.startContainer);
if (nextBlockElement) { if (nextBlockElement) {
removeBlock(protyle, nextBlockElement, nextRange); removeBlock(app, protyle, nextBlockElement, nextRange);
} }
} }
event.stopPropagation(); event.stopPropagation();
@ -801,7 +801,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
range.startOffset === 0 || range.startOffset === 0 ||
(currentNode && currentNode.nodeType === 3 && !hasPreviousSibling(currentNode) && currentNode.textContent === "") // https://ld246.com/article/1649251218696 (currentNode && currentNode.nodeType === 3 && !hasPreviousSibling(currentNode) && currentNode.textContent === "") // https://ld246.com/article/1649251218696
)) { )) {
removeBlock(protyle, nodeElement, range); removeBlock(app, protyle, nodeElement, range);
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
return; return;
@ -810,7 +810,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
nodeElement.getAttribute("data-type") === "NodeTable" && nodeElement.getAttribute("data-type") === "NodeTable" &&
(range.startContainer as HTMLElement).children[range.startOffset - 1]?.tagName === "TABLE") { (range.startContainer as HTMLElement).children[range.startOffset - 1]?.tagName === "TABLE") {
nodeElement.classList.add("protyle-wysiwyg--select"); nodeElement.classList.add("protyle-wysiwyg--select");
removeBlock(protyle, nodeElement, range); removeBlock(app, protyle, nodeElement, range);
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
return; return;
@ -927,14 +927,14 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
} }
if (matchHotKey(window.siyuan.config.keymap.editor.general.undo.custom, event)) { if (matchHotKey(window.siyuan.config.keymap.editor.general.undo.custom, event)) {
protyle.undo.undo(protyle); protyle.undo.undo(app, protyle);
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
return; return;
} }
if (matchHotKey(window.siyuan.config.keymap.editor.general.redo.custom, event)) { if (matchHotKey(window.siyuan.config.keymap.editor.general.redo.custom, event)) {
protyle.undo.redo(protyle); protyle.undo.redo(app, protyle);
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
return; return;
@ -1446,7 +1446,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
}); });
writeText(protyle.lute.BlockDOM2StdMd(html).trimEnd()); writeText(protyle.lute.BlockDOM2StdMd(html).trimEnd());
const nextElement = getNextBlock(selectElements[selectElements.length - 1]); const nextElement = getNextBlock(selectElements[selectElements.length - 1]);
removeBlock(protyle, nodeElement, range); removeBlock(app, protyle, nodeElement, range);
if (nextElement) { if (nextElement) {
focusBlock(nextElement); focusBlock(nextElement);
} }

View file

@ -15,6 +15,7 @@ import {preventScroll} from "../scroll/preventScroll";
import {hideElements} from "../ui/hideElements"; import {hideElements} from "../ui/hideElements";
import {Constants} from "../../constants"; import {Constants} from "../../constants";
import {scrollCenter} from "../../util/highlightById"; import {scrollCenter} from "../../util/highlightById";
import {App} from "../../index";
const removeLi = (protyle: IProtyle, blockElement: Element, range: Range) => { const removeLi = (protyle: IProtyle, blockElement: Element, range: Range) => {
if (!blockElement.parentElement.previousElementSibling && blockElement.parentElement.nextElementSibling && blockElement.parentElement.nextElementSibling.classList.contains("protyle-attr")) { if (!blockElement.parentElement.previousElementSibling && blockElement.parentElement.nextElementSibling && blockElement.parentElement.nextElementSibling.classList.contains("protyle-attr")) {
@ -177,7 +178,7 @@ const removeLi = (protyle: IProtyle, blockElement: Element, range: Range) => {
focusByWbr(previousLastElement.parentElement, range); focusByWbr(previousLastElement.parentElement, range);
}; };
export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Range) => { export const removeBlock = (app: App, protyle: IProtyle, blockElement: Element, range: Range) => {
// 删除后,防止滚动条滚动后调用 get 请求,因为返回的请求已查找不到内容块了 // 删除后,防止滚动条滚动后调用 get 请求,因为返回的请求已查找不到内容块了
preventScroll(protyle); preventScroll(protyle);
const selectElements = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select")); const selectElements = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
@ -241,7 +242,7 @@ export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Ran
if (sideElement) { if (sideElement) {
if (protyle.block.showAll && sideElement.classList.contains("protyle-wysiwyg") && protyle.wysiwyg.element.childElementCount === 0) { if (protyle.block.showAll && sideElement.classList.contains("protyle-wysiwyg") && protyle.wysiwyg.element.childElementCount === 0) {
setTimeout(() => { setTimeout(() => {
zoomOut(protyle, protyle.block.parent2ID, protyle.block.parent2ID); zoomOut({app, protyle, id:protyle.block.parent2ID, focusId:protyle.block.parent2ID});
}, Constants.TIMEOUT_INPUT * 2 + 100); }, Constants.TIMEOUT_INPUT * 2 + 100);
} else { } else {
if ((sideElement.classList.contains("protyle-wysiwyg") && protyle.wysiwyg.element.childElementCount === 0)) { if ((sideElement.classList.contains("protyle-wysiwyg") && protyle.wysiwyg.element.childElementCount === 0)) {
@ -294,7 +295,7 @@ export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Ran
// 空代码块直接删除 // 空代码块直接删除
if (blockElement.getAttribute("data-type") === "NodeCodeBlock" && getContenteditableElement(blockElement).textContent.trim() === "") { if (blockElement.getAttribute("data-type") === "NodeCodeBlock" && getContenteditableElement(blockElement).textContent.trim() === "") {
blockElement.classList.add("protyle-wysiwyg--select"); blockElement.classList.add("protyle-wysiwyg--select");
removeBlock(protyle, blockElement, range); removeBlock(app, protyle, blockElement, range);
return; return;
} }
// 设置 bq 和代码块光标 // 设置 bq 和代码块光标

View file

@ -17,6 +17,7 @@ import {hideElements} from "../ui/hideElements";
import {reloadProtyle} from "../util/reload"; import {reloadProtyle} from "../util/reload";
import {countBlockWord} from "../../layout/status"; import {countBlockWord} from "../../layout/status";
import {needSubscribe} from "../../util/needSubscribe"; import {needSubscribe} from "../../util/needSubscribe";
import {App} from "../../index";
const removeTopElement = (updateElement: Element, protyle: IProtyle) => { const removeTopElement = (updateElement: Element, protyle: IProtyle) => {
// 移动到其他文档中,该块需移除 // 移动到其他文档中,该块需移除
@ -48,7 +49,7 @@ const removeTopElement = (updateElement: Element, protyle: IProtyle) => {
}; };
// 用于执行操作,外加处理当前编辑器中引用块、嵌入块的更新 // 用于执行操作,外加处理当前编辑器中引用块、嵌入块的更新
const promiseTransaction = () => { const promiseTransaction = (app: App) => {
const protyle = window.siyuan.transactions[0].protyle; const protyle = window.siyuan.transactions[0].protyle;
const doOperations = window.siyuan.transactions[0].doOperations; const doOperations = window.siyuan.transactions[0].doOperations;
const undoOperations = window.siyuan.transactions[0].undoOperations; const undoOperations = window.siyuan.transactions[0].undoOperations;
@ -64,9 +65,9 @@ const promiseTransaction = () => {
}] }]
}, (response) => { }, (response) => {
if (window.siyuan.transactions.length === 0) { if (window.siyuan.transactions.length === 0) {
promiseTransactions(); promiseTransactions(app);
} else { } else {
promiseTransaction(); promiseTransaction(app);
} }
countBlockWord([], protyle.block.rootID, true); countBlockWord([], protyle.block.rootID, true);
@ -135,7 +136,12 @@ const promiseTransaction = () => {
mode: 2, mode: 2,
size: window.siyuan.config.editor.dynamicLoadBlocks, size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => { }, getResponse => {
onGet(getResponse, protyle, [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID]); onGet({
data: getResponse,
protyle,
action: [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID],
app
});
}); });
} }
return; return;
@ -306,18 +312,18 @@ const updateEmbed = (protyle: IProtyle, operation: IOperation) => {
} }
}; };
export const promiseTransactions = () => { export const promiseTransactions = (app: App) => {
window.siyuan.transactionsTimeout = window.setInterval(() => { window.siyuan.transactionsTimeout = window.setInterval(() => {
if (window.siyuan.transactions.length === 0) { if (window.siyuan.transactions.length === 0) {
return; return;
} }
window.clearInterval(window.siyuan.transactionsTimeout); window.clearInterval(window.siyuan.transactionsTimeout);
promiseTransaction(); promiseTransaction(app);
}, Constants.TIMEOUT_INPUT * 2); }, Constants.TIMEOUT_INPUT * 2);
}; };
// 用于推送和撤销 // 用于推送和撤销
export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: boolean) => { export const onTransaction = (app: App, protyle: IProtyle, operation: IOperation, focus: boolean) => {
const updateElements: Element[] = []; const updateElements: Element[] = [];
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`)).forEach(item => { Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`)).forEach(item => {
if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed")) { if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed")) {
@ -649,7 +655,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, focus: b
return; return;
} }
if (operation.action === "append") { if (operation.action === "append") {
reloadProtyle(protyle, false); reloadProtyle(protyle, app, false);
} }
}; };

View file

@ -271,7 +271,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
if (type === "next") { if (type === "next") {
if (!target.getAttribute("disabled")) { if (!target.getAttribute("disabled")) {
config.page++; config.page++;
inputTimeout = inputEvent(element, config, inputTimeout, edit); inputTimeout = inputEvent(element, config, inputTimeout, edit, app);
} }
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
@ -279,7 +279,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
} else if (type === "previous") { } else if (type === "previous") {
if (!target.getAttribute("disabled")) { if (!target.getAttribute("disabled")) {
config.page--; config.page--;
inputTimeout = inputEvent(element, config, inputTimeout, edit); inputTimeout = inputEvent(element, config, inputTimeout, edit, app);
} }
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
@ -288,7 +288,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
config.removed = false; config.removed = false;
criteriaData.find(item => { criteriaData.find(item => {
if (item.name === target.innerText.trim()) { if (item.name === target.innerText.trim()) {
updateConfig(element, item, config, edit); updateConfig(element, item, config, edit, app);
return true; return true;
} }
}); });
@ -319,7 +319,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
config.page = 1; config.page = 1;
searchPathInputElement.innerHTML = config.hPath; searchPathInputElement.innerHTML = config.hPath;
searchPathInputElement.setAttribute("title", ""); searchPathInputElement.setAttribute("title", "");
inputTimeout = inputEvent(element, config, inputTimeout, edit); inputTimeout = inputEvent(element, config, inputTimeout, edit, app);
const includeElement = element.querySelector("#searchInclude"); const includeElement = element.querySelector("#searchInclude");
includeElement.classList.remove("b3-button--cancel"); includeElement.classList.remove("b3-button--cancel");
includeElement.setAttribute("disabled", "disabled"); includeElement.setAttribute("disabled", "disabled");
@ -375,7 +375,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
} else { } else {
includeElement.setAttribute("disabled", "disabled"); includeElement.setAttribute("disabled", "disabled");
} }
inputTimeout = inputEvent(element, config, inputTimeout, edit); inputTimeout = inputEvent(element, config, inputTimeout, edit, app);
}); });
}, [], undefined, window.siyuan.languages.specifyPath); }, [], undefined, window.siyuan.languages.specifyPath);
event.stopPropagation(); event.stopPropagation();
@ -397,7 +397,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
}); });
} }
config.page = 1; config.page = 1;
inputTimeout = inputEvent(element, config, inputTimeout, edit); inputTimeout = inputEvent(element, config, inputTimeout, edit, app);
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
break; break;
@ -419,14 +419,14 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
event.preventDefault(); event.preventDefault();
break; break;
} else if (target.id === "searchRefresh") { } else if (target.id === "searchRefresh") {
inputTimeout = inputEvent(element, config, inputTimeout, edit); inputTimeout = inputEvent(element, config, inputTimeout, edit, app);
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
break; break;
} else if (target.id === "searchMore") { } else if (target.id === "searchMore") {
moreMenu(config, criteriaData, element, () => { moreMenu(config, criteriaData, element, () => {
config.page = 1; config.page = 1;
inputEvent(element, config, undefined, edit); inputEvent(element, config, undefined, edit, app);
}, () => { }, () => {
updateConfig(element, { updateConfig(element, {
removed: true, removed: true,
@ -453,7 +453,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
paragraph: window.siyuan.config.search.paragraph, paragraph: window.siyuan.config.search.paragraph,
embedBlock: window.siyuan.config.search.embedBlock, embedBlock: window.siyuan.config.search.embedBlock,
} }
}, config, edit); }, config, edit, app);
}, () => { }, () => {
const localData = window.siyuan.storage[Constants.LOCAL_SEARCHKEYS]; const localData = window.siyuan.storage[Constants.LOCAL_SEARCHKEYS];
const isPopover = hasClosestByClassName(element, "b3-dialog__container"); const isPopover = hasClosestByClassName(element, "b3-dialog__container");
@ -513,7 +513,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
} else if (target.id === "searchFilter") { } else if (target.id === "searchFilter") {
filterMenu(config, () => { filterMenu(config, () => {
config.page = 1; config.page = 1;
inputEvent(element, config, undefined, edit); inputEvent(element, config, undefined, edit, app);
}); });
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
@ -522,7 +522,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
queryMenu(config, () => { queryMenu(config, () => {
element.querySelector("#searchSyntaxCheck").setAttribute("aria-label", getQueryTip(config.method)); element.querySelector("#searchSyntaxCheck").setAttribute("aria-label", getQueryTip(config.method));
config.page = 1; config.page = 1;
inputEvent(element, config, undefined, edit); inputEvent(element, config, undefined, edit, app);
}); });
window.siyuan.menus.menu.popup({x: event.clientX - 16, y: event.clientY - 16}, true); window.siyuan.menus.menu.popup({x: event.clientX - 16, y: event.clientY - 16}, true);
event.stopPropagation(); event.stopPropagation();
@ -577,12 +577,12 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
event.preventDefault(); event.preventDefault();
return; return;
} else if (target.id === "replaceAllBtn") { } else if (target.id === "replaceAllBtn") {
replace(element, config, edit, true); replace(element, config, edit, app, true);
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
break; break;
} else if (target.id === "replaceBtn") { } else if (target.id === "replaceBtn") {
replace(element, config, edit, false); replace(element, config, edit, app, false);
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
break; break;
@ -596,7 +596,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
if (target.parentElement.id === "searchHistoryList") { if (target.parentElement.id === "searchHistoryList") {
searchInputElement.value = target.textContent; searchInputElement.value = target.textContent;
config.page = 1; config.page = 1;
inputTimeout = inputEvent(element, config, inputTimeout, edit); inputTimeout = inputEvent(element, config, inputTimeout, edit, app);
} else if (target.parentElement.id === "replaceHistoryList") { } else if (target.parentElement.id === "replaceHistoryList") {
replaceInputElement.value = target.textContent; replaceInputElement.value = target.textContent;
replaceHistoryElement.classList.add("fn__none"); replaceHistoryElement.classList.add("fn__none");
@ -627,6 +627,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
id: target.getAttribute("data-node-id"), id: target.getAttribute("data-node-id"),
config, config,
value: searchInputElement.value, value: searchInputElement.value,
app,
}); });
searchInputElement.focus(); searchInputElement.focus();
} else if (target.classList.contains("b3-list-item--focus")) { } else if (target.classList.contains("b3-list-item--focus")) {
@ -670,11 +671,11 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
searchInputElement.addEventListener("compositionend", (event: InputEvent) => { searchInputElement.addEventListener("compositionend", (event: InputEvent) => {
config.page = 1; config.page = 1;
inputTimeout = inputEvent(element, config, inputTimeout, edit, event); inputTimeout = inputEvent(element, config, inputTimeout, edit, app, event);
}); });
searchInputElement.addEventListener("input", (event: InputEvent) => { searchInputElement.addEventListener("input", (event: InputEvent) => {
config.page = 1; config.page = 1;
inputTimeout = inputEvent(element, config, inputTimeout, edit, event); inputTimeout = inputEvent(element, config, inputTimeout, edit, app, event);
}); });
searchInputElement.addEventListener("blur", () => { searchInputElement.addEventListener("blur", () => {
if (config.removed) { if (config.removed) {
@ -743,7 +744,8 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
id: currentList.getAttribute("data-node-id"), id: currentList.getAttribute("data-node-id"),
config, config,
value: searchInputElement.value, value: searchInputElement.value,
edit edit,
app
}); });
event.preventDefault(); event.preventDefault();
} else if (event.key === "ArrowUp") { } else if (event.key === "ArrowUp") {
@ -770,7 +772,8 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
id: currentList.getAttribute("data-node-id"), id: currentList.getAttribute("data-node-id"),
config, config,
value: searchInputElement.value, value: searchInputElement.value,
edit edit,
app
}); });
event.preventDefault(); event.preventDefault();
} }
@ -779,10 +782,10 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
if (event.isComposing || event.key !== "Enter") { if (event.isComposing || event.key !== "Enter") {
return; return;
} }
replace(element, config, edit, false); replace(element, config, edit, app, false);
event.preventDefault(); event.preventDefault();
}); });
inputTimeout = inputEvent(element, config, inputTimeout, edit); inputTimeout = inputEvent(element, config, inputTimeout, edit, app);
return edit; return edit;
}; };
@ -805,7 +808,7 @@ const getQueryTip = (method: number) => {
return methodTip; return methodTip;
}; };
const updateConfig = (element: Element, item: ISearchOption, config: ISearchOption, edit: Protyle) => { const updateConfig = (element: Element, item: ISearchOption, config: ISearchOption, edit: Protyle, app: App) => {
const dialogElement = hasClosestByClassName(element, "b3-dialog--open"); const dialogElement = hasClosestByClassName(element, "b3-dialog--open");
if (dialogElement && dialogElement.getAttribute("data-key") === window.siyuan.config.keymap.general.search.custom) { if (dialogElement && dialogElement.getAttribute("data-key") === window.siyuan.config.keymap.general.search.custom) {
// https://github.com/siyuan-note/siyuan/issues/6828 // https://github.com/siyuan-note/siyuan/issues/6828
@ -861,7 +864,7 @@ const updateConfig = (element: Element, item: ISearchOption, config: ISearchOpti
Object.assign(config, item); Object.assign(config, item);
window.siyuan.storage[Constants.LOCAL_SEARCHDATA] = Object.assign({}, config); window.siyuan.storage[Constants.LOCAL_SEARCHDATA] = Object.assign({}, config);
setStorageVal(Constants.LOCAL_SEARCHDATA, window.siyuan.storage[Constants.LOCAL_SEARCHDATA]); setStorageVal(Constants.LOCAL_SEARCHDATA, window.siyuan.storage[Constants.LOCAL_SEARCHDATA]);
inputEvent(element, config, undefined, edit); inputEvent(element, config, undefined, edit, app);
window.siyuan.menus.menu.remove(); window.siyuan.menus.menu.remove();
}; };
@ -894,6 +897,7 @@ const getArticle = (options: {
config: ISearchOption, config: ISearchOption,
edit: Protyle edit: Protyle
value: string, value: string,
app: App
}) => { }) => {
fetchPost("/api/block/checkBlockFold", {id: options.id}, (foldResponse) => { fetchPost("/api/block/checkBlockFold", {id: options.id}, (foldResponse) => {
options.edit.protyle.scroll.lastScrollTop = 0; options.edit.protyle.scroll.lastScrollTop = 0;
@ -907,7 +911,12 @@ const getArticle = (options: {
size: foldResponse.data ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks, size: foldResponse.data ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks,
zoom: foldResponse.data, zoom: foldResponse.data,
}, getResponse => { }, getResponse => {
onGet(getResponse, options.edit.protyle, foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_HL, Constants.CB_GET_HTML]); onGet({
data: getResponse,
protyle: options.edit.protyle,
action: foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_HL, Constants.CB_GET_HTML],
app: options.app
});
const matchElement = options.edit.protyle.wysiwyg.element.querySelector(`div[data-node-id="${options.id}"] span[data-type~="search-mark"]`); const matchElement = options.edit.protyle.wysiwyg.element.querySelector(`div[data-node-id="${options.id}"] span[data-type~="search-mark"]`);
if (matchElement) { if (matchElement) {
matchElement.classList.add("search-mark--hl"); matchElement.classList.add("search-mark--hl");
@ -919,7 +928,7 @@ const getArticle = (options: {
}); });
}; };
const replace = (element: Element, config: ISearchOption, edit: Protyle, isAll: boolean) => { const replace = (element: Element, config: ISearchOption, edit: Protyle, app: App, isAll: boolean) => {
if (config.method === 1 || config.method === 2) { if (config.method === 1 || config.method === 2) {
showMessage(window.siyuan.languages._kernel[132]); showMessage(window.siyuan.languages._kernel[132]);
return; return;
@ -966,7 +975,7 @@ const replace = (element: Element, config: ISearchOption, edit: Protyle, isAll:
} }
getAllModels().editor.forEach(item => { getAllModels().editor.forEach(item => {
if (rootIds[0] === item.editor.protyle.block.rootID) { if (rootIds[0] === item.editor.protyle.block.rootID) {
reloadProtyle(item.editor.protyle, false); reloadProtyle(item.editor.protyle, app, false);
} }
}); });
if (currentList.nextElementSibling) { if (currentList.nextElementSibling) {
@ -1006,11 +1015,12 @@ const replace = (element: Element, config: ISearchOption, edit: Protyle, isAll:
id: currentList.getAttribute("data-node-id"), id: currentList.getAttribute("data-node-id"),
config, config,
value: searchInputElement.value, value: searchInputElement.value,
app,
}); });
}); });
}; };
const inputEvent = (element: Element, config: ISearchOption, inputTimeout: number, edit: Protyle, event?: InputEvent) => { const inputEvent = (element: Element, config: ISearchOption, inputTimeout: number, edit: Protyle, app: App, event?: InputEvent) => {
if (event && event.isComposing) { if (event && event.isComposing) {
return; return;
} }
@ -1025,7 +1035,7 @@ const inputEvent = (element: Element, config: ISearchOption, inputTimeout: numbe
const nextElement = element.querySelector('[data-type="next"]'); const nextElement = element.querySelector('[data-type="next"]');
if (inputValue === "" && (!config.idPath || config.idPath.length === 0)) { if (inputValue === "" && (!config.idPath || config.idPath.length === 0)) {
fetchPost("/api/block/getRecentUpdatedBlocks", {}, (response) => { fetchPost("/api/block/getRecentUpdatedBlocks", {}, (response) => {
onSearch(response.data, edit, element, config); onSearch(response.data, edit, app, element, config);
loadingElement.classList.add("fn__none"); loadingElement.classList.add("fn__none");
element.querySelector("#searchResult").innerHTML = ""; element.querySelector("#searchResult").innerHTML = "";
previousElement.setAttribute("disabled", "true"); previousElement.setAttribute("disabled", "true");
@ -1054,7 +1064,7 @@ const inputEvent = (element: Element, config: ISearchOption, inputTimeout: numbe
} else { } else {
nextElement.setAttribute("disabled", "disabled"); nextElement.setAttribute("disabled", "disabled");
} }
onSearch(response.data.blocks, edit, element, config); onSearch(response.data.blocks, edit, app, element, config);
element.querySelector("#searchResult").innerHTML = `${config.page}/${response.data.pageCount || 1}<span class="fn__space"></span> element.querySelector("#searchResult").innerHTML = `${config.page}/${response.data.pageCount || 1}<span class="fn__space"></span>
<span class="ft__on-surface">${window.siyuan.languages.findInDoc.replace("${x}", response.data.matchedRootCount).replace("${y}", response.data.matchedBlockCount)}</span>`; <span class="ft__on-surface">${window.siyuan.languages.findInDoc.replace("${x}", response.data.matchedRootCount).replace("${y}", response.data.matchedBlockCount)}</span>`;
loadingElement.classList.add("fn__none"); loadingElement.classList.add("fn__none");
@ -1064,7 +1074,7 @@ const inputEvent = (element: Element, config: ISearchOption, inputTimeout: numbe
return inputTimeout; return inputTimeout;
}; };
const onSearch = (data: IBlock[], edit: Protyle, element: Element, config: ISearchOption) => { const onSearch = (data: IBlock[], edit: Protyle, app: App, element: Element, config: ISearchOption) => {
let resultHTML = ""; let resultHTML = "";
data.forEach((item, index) => { data.forEach((item, index) => {
const title = getNotebookName(item.box) + getDisplayName(item.hPath, false); const title = getNotebookName(item.box) + getDisplayName(item.hPath, false);
@ -1104,6 +1114,7 @@ ${unicode2Emoji(item.ial.icon, false, "b3-list-item__graphic", true)}
id: data[0].children[0].id, id: data[0].children[0].id,
config, config,
value: searchInputElement.value, value: searchInputElement.value,
app,
}); });
} else { } else {
getArticle({ getArticle({
@ -1111,6 +1122,7 @@ ${unicode2Emoji(item.ial.icon, false, "b3-list-item__graphic", true)}
id: data[0].id, id: data[0].id,
config, config,
value: searchInputElement.value, value: searchInputElement.value,
app
}); });
} }
} else { } else {

View file

@ -49,7 +49,7 @@ interface Window {
Protyle: import("../protyle/method").default Protyle: import("../protyle/method").default
goBack(): void goBack(app: import("../index").App): void
showKeyboardToolbar(height: number): void showKeyboardToolbar(height: number): void

View file

@ -152,23 +152,29 @@ const focusStack = async (app: App, stack: IBackStack) => {
} }
return false; return false;
} }
zoomOut(stack.protyle, stack.zoomId || stack.protyle.block.rootID, undefined, false, () => { zoomOut({
Array.from(stack.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${stack.id}"]`)).find((item: HTMLElement) => { app,
if (!hasClosestByAttribute(item, "data-type", "NodeBlockQueryEmbed")) { protyle: stack.protyle,
blockElement = item; id: stack.zoomId || stack.protyle.block.rootID,
return true; isPushBack: false,
callback: () => {
Array.from(stack.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${stack.id}"]`)).find((item: HTMLElement) => {
if (!hasClosestByAttribute(item, "data-type", "NodeBlockQueryEmbed")) {
blockElement = item;
return true;
}
});
if (!blockElement) {
return;
} }
}); getAllModels().outline.forEach(item => {
if (!blockElement) { if (item.blockId === stack.protyle.block.rootID) {
return; item.setCurrent(blockElement);
}
});
focusByOffset(getContenteditableElement(blockElement), stack.position.start, stack.position.end);
scrollCenter(stack.protyle, blockElement, true);
} }
getAllModels().outline.forEach(item => {
if (item.blockId === stack.protyle.block.rootID) {
item.setCurrent(blockElement);
}
});
focusByOffset(getContenteditableElement(blockElement), stack.position.start, stack.position.end);
scrollCenter(stack.protyle, blockElement, true);
}); });
return true; return true;
} }

View file

@ -145,7 +145,7 @@ class App {
}); });
setNoteBook(); setNoteBook();
initBlockPopover(this); initBlockPopover(this);
promiseTransactions(); promiseTransactions(this);
} }
} }