mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 08:30:12 +01:00
♻️
This commit is contained in:
parent
fd0893d8d8
commit
6806392b41
57 changed files with 271 additions and 360 deletions
|
|
@ -1071,7 +1071,7 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
|
||||||
selectElements = [nodeElement];
|
selectElements = [nodeElement];
|
||||||
}
|
}
|
||||||
movePathTo((toPath) => {
|
movePathTo((toPath) => {
|
||||||
hintMoveBlock(toPath[0], selectElements, protyle, app);
|
hintMoveBlock(toPath[0], selectElements, protyle);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
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, app, true);
|
reloadProtyle(protyle, 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({data: getResponse, protyle, app});
|
onGet({data: getResponse, protyle});
|
||||||
});
|
});
|
||||||
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(app, protyle);
|
protyle.undo.undo(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(app, protyle);
|
protyle.undo.redo(protyle);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,6 @@ export const bindCardEvent = (options: {
|
||||||
data: response,
|
data: response,
|
||||||
protyle: editor.protyle,
|
protyle: editor.protyle,
|
||||||
action: [Constants.CB_GET_ALL, Constants.CB_GET_HTML],
|
action: [Constants.CB_GET_ALL, Constants.CB_GET_HTML],
|
||||||
app: options.app
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -168,7 +167,6 @@ 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,
|
||||||
|
|
@ -342,7 +340,6 @@ export const bindCardEvent = (options: {
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
index--;
|
index--;
|
||||||
nextCard({
|
nextCard({
|
||||||
app: options.app,
|
|
||||||
countElement,
|
countElement,
|
||||||
editor,
|
editor,
|
||||||
actionElements,
|
actionElements,
|
||||||
|
|
@ -386,7 +383,6 @@ export const bindCardEvent = (options: {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nextCard({
|
nextCard({
|
||||||
app: options.app,
|
|
||||||
countElement,
|
countElement,
|
||||||
editor,
|
editor,
|
||||||
actionElements,
|
actionElements,
|
||||||
|
|
@ -398,7 +394,6 @@ export const bindCardEvent = (options: {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
nextCard({
|
nextCard({
|
||||||
app: options.app,
|
|
||||||
countElement,
|
countElement,
|
||||||
editor,
|
editor,
|
||||||
actionElements,
|
actionElements,
|
||||||
|
|
@ -458,8 +453,11 @@ export const openCardByData = (app: App, cardsData: {
|
||||||
};
|
};
|
||||||
|
|
||||||
const nextCard = (options: {
|
const nextCard = (options: {
|
||||||
app: App,
|
countElement: Element,
|
||||||
countElement: Element, editor: Protyle, actionElements: NodeListOf<Element>, index: number, blocks: ICard[]
|
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");
|
||||||
if (window.siyuan.config.flashcard.superBlock) {
|
if (window.siyuan.config.flashcard.superBlock) {
|
||||||
|
|
@ -491,7 +489,6 @@ const nextCard = (options: {
|
||||||
data: response,
|
data: response,
|
||||||
protyle: options.editor.protyle,
|
protyle: options.editor.protyle,
|
||||||
action: [Constants.CB_GET_ALL, Constants.CB_GET_HTML],
|
action: [Constants.CB_GET_ALL, Constants.CB_GET_HTML],
|
||||||
app: options.app
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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(app, edit, dialog.element.querySelector(".b3-list-item--focus")?.getAttribute("data-id"));
|
getArticle(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(app, edit, currentElement.getAttribute("data-id"));
|
getArticle(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(app, edit, dialog.element.querySelector(".b3-list-item--focus")?.getAttribute("data-id"));
|
getArticle(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(app, edit, dialog.element.querySelector(".b3-list-item--focus")?.getAttribute("data-id"));
|
getArticle(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(app, edit, target.getAttribute("data-id"));
|
getArticle(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(app, edit, "");
|
getArticle(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(app, edit, nextElment.getAttribute("data-id"));
|
getArticle(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 = (app: App, edit: Protyle, id: string) => {
|
const getArticle = (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");
|
||||||
|
|
@ -256,7 +256,7 @@ const getArticle = (app: App, edit: Protyle, id: string) => {
|
||||||
size: Constants.SIZE_GET_MAX,
|
size: Constants.SIZE_GET_MAX,
|
||||||
}, getResponse => {
|
}, getResponse => {
|
||||||
onGet({
|
onGet({
|
||||||
data: getResponse, protyle: edit.protyle, action: [Constants.CB_GET_ALL, Constants.CB_GET_HTML], app
|
data: getResponse, protyle: edit.protyle, action: [Constants.CB_GET_ALL, Constants.CB_GET_HTML]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ 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,
|
||||||
|
|
@ -258,7 +257,7 @@ export const editor = {
|
||||||
</div>
|
</div>
|
||||||
</label>`;
|
</label>`;
|
||||||
},
|
},
|
||||||
bindEvent: (app: App) => {
|
bindEvent: () => {
|
||||||
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>`;
|
||||||
|
|
@ -318,7 +317,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, app);
|
editor.onSetEditor(response.data);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
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) => {
|
||||||
|
|
@ -338,13 +337,13 @@ export const editor = {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onSetEditor: (editorData: IEditor, app: App) => {
|
onSetEditor: (editorData: IEditor) => {
|
||||||
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, app, false);
|
reloadProtyle(item.editor.protyle, 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");
|
||||||
|
|
|
||||||
|
|
@ -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(app);
|
editor.bindEvent();
|
||||||
return dialog;
|
return dialog;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -169,7 +169,7 @@ export const keymap = {
|
||||||
const data: IKeymap = JSON.parse(JSON.stringify(Constants.SIYUAN_KEYMAP));
|
const data: IKeymap = JSON.parse(JSON.stringify(Constants.SIYUAN_KEYMAP));
|
||||||
keymap.element.querySelectorAll("label.b3-list-item input").forEach((item) => {
|
keymap.element.querySelectorAll("label.b3-list-item input").forEach((item) => {
|
||||||
const keys = item.getAttribute("data-key").split(Constants.ZWSP);
|
const keys = item.getAttribute("data-key").split(Constants.ZWSP);
|
||||||
const newHotkey = item.getAttribute("data-value")
|
const newHotkey = item.getAttribute("data-value");
|
||||||
if (keys[0] === "plugin") {
|
if (keys[0] === "plugin") {
|
||||||
window.siyuan.config.keymap.plugin[keys[1]][keys[2]].custom = newHotkey;
|
window.siyuan.config.keymap.plugin[keys[1]][keys[2]].custom = newHotkey;
|
||||||
data.plugin = window.siyuan.config.keymap.plugin;
|
data.plugin = window.siyuan.config.keymap.plugin;
|
||||||
|
|
@ -179,9 +179,9 @@ export const keymap = {
|
||||||
if (command.langKey === keys[2]) {
|
if (command.langKey === keys[2]) {
|
||||||
command.customHotkey = newHotkey;
|
command.customHotkey = newHotkey;
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
} else if (keys[0] === "general") {
|
} else if (keys[0] === "general") {
|
||||||
data[keys[0]][keys[1]].custom = newHotkey;
|
data[keys[0]][keys[1]].custom = newHotkey;
|
||||||
} else if (keys[0] === "editor" && (keys[1] === "general" || keys[1] === "insert" || keys[1] === "heading" || keys[1] === "list" || keys[1] === "table")) {
|
} else if (keys[0] === "editor" && (keys[1] === "general" || keys[1] === "insert" || keys[1] === "heading" || keys[1] === "list" || keys[1] === "table")) {
|
||||||
|
|
|
||||||
|
|
@ -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, app, false);
|
reloadProtyle(window.siyuan.mobile.popEditor.protyle, 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, app, false);
|
reloadProtyle(window.siyuan.mobile.editor.protyle, 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, app, false);
|
reloadProtyle(item.editor.protyle, 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);
|
||||||
|
|
|
||||||
|
|
@ -277,13 +277,13 @@ export const openFile = (options: IOpenFileOptions) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
createdTab = newTab(options)
|
createdTab = newTab(options);
|
||||||
wnd.addTab(createdTab);
|
wnd.addTab(createdTab);
|
||||||
if (unUpdateTab && options.removeCurrentTab) {
|
if (unUpdateTab && options.removeCurrentTab) {
|
||||||
wnd.removeTab(unUpdateTab.id, false, true, false);
|
wnd.removeTab(unUpdateTab.id, false, true, false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
createdTab = newTab(options)
|
createdTab = newTab(options);
|
||||||
wnd.addTab(createdTab);
|
wnd.addTab(createdTab);
|
||||||
}
|
}
|
||||||
wnd.showHeading();
|
wnd.showHeading();
|
||||||
|
|
@ -343,7 +343,7 @@ const switchEditor = (editor: Editor, options: IOpenFileOptions, allModels: IMod
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (options.zoomIn) {
|
if (options.zoomIn) {
|
||||||
zoomOut({app: options.app, protyle: editor.editor.protyle, id: options.id});
|
zoomOut({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({data: getResponse, protyle: editor.editor.protyle, action: options.action, app: options.app});
|
onGet({data: getResponse, protyle: editor.editor.protyle, action: options.action});
|
||||||
// 大纲点击折叠标题下的内容时,需更新反链面板
|
// 大纲点击折叠标题下的内容时,需更新反链面板
|
||||||
updateBacklinkGraph(allModels, editor.editor.protyle);
|
updateBacklinkGraph(allModels, editor.editor.protyle);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,6 @@ const renderCompare = (app: App, element: HTMLElement) => {
|
||||||
data: response,
|
data: response,
|
||||||
protyle: leftEditor.protyle,
|
protyle: leftEditor.protyle,
|
||||||
action: [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML],
|
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");
|
||||||
|
|
@ -99,7 +98,6 @@ const renderCompare = (app: App, element: HTMLElement) => {
|
||||||
data: response,
|
data: response,
|
||||||
protyle: rightEditor.protyle,
|
protyle: rightEditor.protyle,
|
||||||
action: [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML],
|
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");
|
||||||
|
|
|
||||||
|
|
@ -615,7 +615,6 @@ const bindEvent = (app: App, element: Element, dialog?: Dialog) => {
|
||||||
data: response,
|
data: response,
|
||||||
protyle: historyEditor.protyle,
|
protyle: historyEditor.protyle,
|
||||||
action: [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML],
|
action: [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML],
|
||||||
app
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -181,7 +181,7 @@ export class App {
|
||||||
});
|
});
|
||||||
setNoteBook();
|
setNoteBook();
|
||||||
initBlockPopover(this);
|
initBlockPopover(this);
|
||||||
promiseTransactions(this);
|
promiseTransactions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -160,7 +160,6 @@ export class Outline extends Model {
|
||||||
data: getResponse,
|
data: getResponse,
|
||||||
protyle: item.editor.protyle,
|
protyle: item.editor.protyle,
|
||||||
action: [Constants.CB_GET_FOCUS],
|
action: [Constants.CB_GET_FOCUS],
|
||||||
app: options.app
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,8 @@ import {Graph} from "./Graph";
|
||||||
import {Outline} from "./Outline";
|
import {Outline} from "./Outline";
|
||||||
import {switchWnd} from "../util";
|
import {switchWnd} from "../util";
|
||||||
import {Backlink} from "./Backlink";
|
import {Backlink} from "./Backlink";
|
||||||
import {App} from "../../index";
|
|
||||||
|
|
||||||
export const openBacklink = (app: App, protyle: IProtyle) => {
|
export const openBacklink = (protyle: IProtyle) => {
|
||||||
const backlink = getAllModels().backlink.find(item => {
|
const backlink = getAllModels().backlink.find(item => {
|
||||||
if (item.blockId === protyle.block.id && item.type === "local") {
|
if (item.blockId === protyle.block.id && item.type === "local") {
|
||||||
item.parent.parent.removeTab(item.parent.id);
|
item.parent.parent.removeTab(item.parent.id);
|
||||||
|
|
@ -22,7 +21,7 @@ export const openBacklink = (app: App, protyle: IProtyle) => {
|
||||||
title: protyle.title.editElement.textContent || "Untitled",
|
title: protyle.title.editElement.textContent || "Untitled",
|
||||||
callback(tab: Tab) {
|
callback(tab: Tab) {
|
||||||
tab.addModel(new Backlink({
|
tab.addModel(new Backlink({
|
||||||
app,
|
app: protyle.app,
|
||||||
type: "local",
|
type: "local",
|
||||||
tab,
|
tab,
|
||||||
// 通过搜索打开的包含上下文,但不是缩放,因此需要传 rootID https://ld246.com/article/1666786639708
|
// 通过搜索打开的包含上下文,但不是缩放,因此需要传 rootID https://ld246.com/article/1666786639708
|
||||||
|
|
@ -34,7 +33,7 @@ export const openBacklink = (app: App, protyle: IProtyle) => {
|
||||||
newWnd.addTab(tab);
|
newWnd.addTab(tab);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const openGraph = (app: App, protyle: IProtyle) => {
|
export const openGraph = (protyle: IProtyle) => {
|
||||||
const graph = getAllModels().graph.find(item => {
|
const graph = getAllModels().graph.find(item => {
|
||||||
if (item.blockId === protyle.block.id && item.type === "local") {
|
if (item.blockId === protyle.block.id && item.type === "local") {
|
||||||
item.parent.parent.removeTab(item.parent.id);
|
item.parent.parent.removeTab(item.parent.id);
|
||||||
|
|
@ -50,7 +49,7 @@ export const openGraph = (app: App, protyle: IProtyle) => {
|
||||||
title: protyle.title.editElement.textContent || "Untitled",
|
title: protyle.title.editElement.textContent || "Untitled",
|
||||||
callback(tab: Tab) {
|
callback(tab: Tab) {
|
||||||
tab.addModel(new Graph({
|
tab.addModel(new Graph({
|
||||||
app,
|
app: protyle.app,
|
||||||
type: "local",
|
type: "local",
|
||||||
tab,
|
tab,
|
||||||
blockId: protyle.block.id,
|
blockId: protyle.block.id,
|
||||||
|
|
@ -61,7 +60,7 @@ export const openGraph = (app: App, protyle: IProtyle) => {
|
||||||
wnd.addTab(tab);
|
wnd.addTab(tab);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const openOutline = (app: App,protyle: IProtyle) => {
|
export const openOutline = (protyle: IProtyle) => {
|
||||||
const outlinePanel = getAllModels().outline.find(item => {
|
const outlinePanel = getAllModels().outline.find(item => {
|
||||||
if (item.blockId === protyle.block.rootID && item.type === "local") {
|
if (item.blockId === protyle.block.rootID && item.type === "local") {
|
||||||
item.parent.parent.removeTab(item.parent.id);
|
item.parent.parent.removeTab(item.parent.id);
|
||||||
|
|
@ -77,7 +76,7 @@ export const openOutline = (app: App,protyle: IProtyle) => {
|
||||||
title: protyle.title.editElement.textContent || "Untitled",
|
title: protyle.title.editElement.textContent || "Untitled",
|
||||||
callback(tab: Tab) {
|
callback(tab: Tab) {
|
||||||
tab.addModel(new Outline({
|
tab.addModel(new Outline({
|
||||||
app,
|
app: protyle.app,
|
||||||
type: "local",
|
type: "local",
|
||||||
tab,
|
tab,
|
||||||
blockId: protyle.block.rootID,
|
blockId: protyle.block.rootID,
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ export const initBar = (app: App) => {
|
||||||
window.siyuan.menus.menu.element.setAttribute("data-name", "barmore");
|
window.siyuan.menus.menu.element.setAttribute("data-name", "barmore");
|
||||||
(target.getAttribute("data-hideids") || "").split(",").forEach((itemId) => {
|
(target.getAttribute("data-hideids") || "").split(",").forEach((itemId) => {
|
||||||
const hideElement = toolbarElement.querySelector("#" + itemId);
|
const hideElement = toolbarElement.querySelector("#" + itemId);
|
||||||
const useElement = hideElement.querySelector("use")
|
const useElement = hideElement.querySelector("use");
|
||||||
const menuOptions: IMenu = {
|
const menuOptions: IMenu = {
|
||||||
label: itemId === "toolbarVIP" ? window.siyuan.languages.account : hideElement.getAttribute("aria-label"),
|
label: itemId === "toolbarVIP" ? window.siyuan.languages.account : hideElement.getAttribute("aria-label"),
|
||||||
icon: itemId === "toolbarVIP" ? "iconAccount" : (useElement ? useElement.getAttribute("xlink:href").substring(1) : undefined),
|
icon: itemId === "toolbarVIP" ? "iconAccount" : (useElement ? useElement.getAttribute("xlink:href").substring(1) : undefined),
|
||||||
|
|
@ -98,7 +98,7 @@ export const initBar = (app: App) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (!useElement) {
|
if (!useElement) {
|
||||||
const svgElement = hideElement.querySelector("svg")
|
const svgElement = hideElement.querySelector("svg");
|
||||||
svgElement.classList.add("b3-menu__icon");
|
svgElement.classList.add("b3-menu__icon");
|
||||||
menuOptions.iconHTML = svgElement.outerHTML;
|
menuOptions.iconHTML = svgElement.outerHTML;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,9 +42,8 @@ import {removeLink} from "../protyle/toolbar/Link";
|
||||||
import {alignImgCenter, alignImgLeft} from "../protyle/wysiwyg/commonHotkey";
|
import {alignImgCenter, alignImgLeft} from "../protyle/wysiwyg/commonHotkey";
|
||||||
import {renameTag} from "../util/noRelyPCFunction";
|
import {renameTag} from "../util/noRelyPCFunction";
|
||||||
import {hideElements} from "../protyle/ui/hideElements";
|
import {hideElements} from "../protyle/ui/hideElements";
|
||||||
import {App} from "../index";
|
|
||||||
|
|
||||||
export const refMenu = (app: App, protyle: IProtyle, element: HTMLElement) => {
|
export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
|
||||||
const nodeElement = hasClosestBlock(element);
|
const nodeElement = hasClosestBlock(element);
|
||||||
if (!nodeElement) {
|
if (!nodeElement) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -89,7 +88,7 @@ export const refMenu = (app: App, protyle: IProtyle, element: HTMLElement) => {
|
||||||
click() {
|
click() {
|
||||||
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
app,
|
app: protyle.app,
|
||||||
id: refBlockId,
|
id: refBlockId,
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
zoomIn: foldResponse.data
|
zoomIn: foldResponse.data
|
||||||
|
|
@ -103,7 +102,7 @@ export const refMenu = (app: App, protyle: IProtyle, element: HTMLElement) => {
|
||||||
click() {
|
click() {
|
||||||
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
app,
|
app: protyle.app,
|
||||||
id: refBlockId,
|
id: refBlockId,
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
|
||||||
keepCursor: true,
|
keepCursor: true,
|
||||||
|
|
@ -119,7 +118,7 @@ export const refMenu = (app: App, protyle: IProtyle, element: HTMLElement) => {
|
||||||
click() {
|
click() {
|
||||||
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
app,
|
app: protyle.app,
|
||||||
id: refBlockId,
|
id: refBlockId,
|
||||||
position: "right",
|
position: "right",
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
|
|
@ -135,7 +134,7 @@ export const refMenu = (app: App, protyle: IProtyle, element: HTMLElement) => {
|
||||||
click() {
|
click() {
|
||||||
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
app,
|
app: protyle.app,
|
||||||
id: refBlockId,
|
id: refBlockId,
|
||||||
position: "bottom",
|
position: "bottom",
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
|
|
@ -435,7 +434,6 @@ export const contentMenu = (protyle: IProtyle, nodeElement: Element) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const zoomOut = (options: {
|
export const zoomOut = (options: {
|
||||||
app: App,
|
|
||||||
protyle: IProtyle,
|
protyle: IProtyle,
|
||||||
id: string,
|
id: string,
|
||||||
focusId?: string,
|
focusId?: string,
|
||||||
|
|
@ -488,14 +486,12 @@ export const zoomOut = (options: {
|
||||||
data: getResponse,
|
data: getResponse,
|
||||||
protyle: options.protyle,
|
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],
|
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({
|
onGet({
|
||||||
data: getResponse,
|
data: getResponse,
|
||||||
protyle: options.protyle,
|
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],
|
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
|
||||||
|
|
@ -514,7 +510,6 @@ export const zoomOut = (options: {
|
||||||
data: getFocusResponse,
|
data: getFocusResponse,
|
||||||
protyle: options.protyle,
|
protyle: options.protyle,
|
||||||
action: options.isPushBack ? [Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_UNUNDO],
|
action: options.isPushBack ? [Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_UNUNDO],
|
||||||
app: options.app
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
|
|
@ -537,7 +532,7 @@ export const zoomOut = (options: {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const imgMenu = (app: App, protyle: IProtyle, range: Range, assetElement: HTMLElement, position: {
|
export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLElement, position: {
|
||||||
clientX: number,
|
clientX: number,
|
||||||
clientY: number
|
clientY: number
|
||||||
}) => {
|
}) => {
|
||||||
|
|
@ -739,7 +734,7 @@ export const imgMenu = (app: App, protyle: IProtyle, range: Range, assetElement:
|
||||||
const imgSrc = imgElement.getAttribute("src");
|
const imgSrc = imgElement.getAttribute("src");
|
||||||
if (imgSrc) {
|
if (imgSrc) {
|
||||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||||
openMenu(app, imgSrc, false, false);
|
openMenu(protyle.app, imgSrc, false, false);
|
||||||
}
|
}
|
||||||
window.siyuan.menus.menu.popup({x: position.clientX, y: position.clientY});
|
window.siyuan.menus.menu.popup({x: position.clientX, y: position.clientY});
|
||||||
const textElements = window.siyuan.menus.menu.element.querySelectorAll("textarea");
|
const textElements = window.siyuan.menus.menu.element.querySelectorAll("textarea");
|
||||||
|
|
@ -758,7 +753,7 @@ export const imgMenu = (app: App, protyle: IProtyle, range: Range, assetElement:
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const linkMenu = (app: App, protyle: IProtyle, linkElement: HTMLElement, focusText = false) => {
|
export const linkMenu = (protyle: IProtyle, linkElement: HTMLElement, focusText = false) => {
|
||||||
window.siyuan.menus.menu.remove();
|
window.siyuan.menus.menu.remove();
|
||||||
const nodeElement = hasClosestBlock(linkElement);
|
const nodeElement = hasClosestBlock(linkElement);
|
||||||
if (!nodeElement) {
|
if (!nodeElement) {
|
||||||
|
|
@ -851,7 +846,7 @@ export const linkMenu = (app: App, protyle: IProtyle, linkElement: HTMLElement,
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
if (linkAddress) {
|
if (linkAddress) {
|
||||||
openMenu(app, linkAddress, false, true);
|
openMenu(protyle.app, linkAddress, false, true);
|
||||||
}
|
}
|
||||||
if (linkAddress?.startsWith("siyuan://blocks/")) {
|
if (linkAddress?.startsWith("siyuan://blocks/")) {
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
|
|
@ -934,7 +929,7 @@ export const linkMenu = (app: App, protyle: IProtyle, linkElement: HTMLElement,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const tagMenu = (app: App, protyle: IProtyle, tagElement: HTMLElement) => {
|
export const tagMenu = (protyle: IProtyle, tagElement: HTMLElement) => {
|
||||||
window.siyuan.menus.menu.remove();
|
window.siyuan.menus.menu.remove();
|
||||||
const nodeElement = hasClosestBlock(tagElement);
|
const nodeElement = hasClosestBlock(tagElement);
|
||||||
if (!nodeElement) {
|
if (!nodeElement) {
|
||||||
|
|
@ -990,7 +985,7 @@ export const tagMenu = (app: App, protyle: IProtyle, tagElement: HTMLElement) =>
|
||||||
accelerator: "Click",
|
accelerator: "Click",
|
||||||
icon: "iconSearch",
|
icon: "iconSearch",
|
||||||
click() {
|
click() {
|
||||||
openGlobalSearch(app, `#${tagElement.textContent}#`, false);
|
openGlobalSearch(protyle.app, `#${tagElement.textContent}#`, false);
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
/// #endif
|
/// #endif
|
||||||
|
|
@ -1054,7 +1049,7 @@ const genImageWidthMenu = (label: string, assetElement: HTMLElement, imgElement:
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const iframeMenu = (app: App, protyle: IProtyle, nodeElement: Element) => {
|
export const iframeMenu = (protyle: IProtyle, nodeElement: Element) => {
|
||||||
const id = nodeElement.getAttribute("data-node-id");
|
const id = nodeElement.getAttribute("data-node-id");
|
||||||
const iframeElement = nodeElement.querySelector("iframe");
|
const iframeElement = nodeElement.querySelector("iframe");
|
||||||
let html = nodeElement.outerHTML;
|
let html = nodeElement.outerHTML;
|
||||||
|
|
@ -1113,12 +1108,12 @@ export const iframeMenu = (app: App, protyle: IProtyle, nodeElement: Element) =>
|
||||||
subMenus.push({
|
subMenus.push({
|
||||||
type: "separator"
|
type: "separator"
|
||||||
});
|
});
|
||||||
return subMenus.concat(openMenu(app, iframeSrc, true, false) as IMenu[]);
|
return subMenus.concat(openMenu(protyle.app, iframeSrc, true, false) as IMenu[]);
|
||||||
}
|
}
|
||||||
return subMenus;
|
return subMenus;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const videoMenu = (app: App, protyle: IProtyle, nodeElement: Element, type: string) => {
|
export const videoMenu = (protyle: IProtyle, nodeElement: Element, type: string) => {
|
||||||
const id = nodeElement.getAttribute("data-node-id");
|
const id = nodeElement.getAttribute("data-node-id");
|
||||||
const videoElement = nodeElement.querySelector(type === "NodeVideo" ? "video" : "audio");
|
const videoElement = nodeElement.querySelector(type === "NodeVideo" ? "video" : "audio");
|
||||||
let html = nodeElement.outerHTML;
|
let html = nodeElement.outerHTML;
|
||||||
|
|
@ -1150,7 +1145,7 @@ export const videoMenu = (app: App, protyle: IProtyle, nodeElement: Element, typ
|
||||||
/// #endif
|
/// #endif
|
||||||
const VideoSrc = videoElement.getAttribute("src");
|
const VideoSrc = videoElement.getAttribute("src");
|
||||||
if (VideoSrc) {
|
if (VideoSrc) {
|
||||||
return subMenus.concat(openMenu(app, VideoSrc, true, false) as IMenu[]);
|
return subMenus.concat(openMenu(protyle.app, VideoSrc, true, false) as IMenu[]);
|
||||||
}
|
}
|
||||||
return subMenus;
|
return subMenus;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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({data: getResponse, protyle: window.siyuan.mobile.editor.protyle, action, app});
|
onGet({data: getResponse, protyle: window.siyuan.mobile.editor.protyle, action});
|
||||||
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();
|
||||||
|
|
|
||||||
|
|
@ -93,16 +93,16 @@ class App {
|
||||||
document.addEventListener("touchstart", handleTouchStart, false);
|
document.addEventListener("touchstart", handleTouchStart, false);
|
||||||
document.addEventListener("touchmove", handleTouchMove, false);
|
document.addEventListener("touchmove", handleTouchMove, false);
|
||||||
document.addEventListener("touchend", (event) => {
|
document.addEventListener("touchend", (event) => {
|
||||||
handleTouchEnd(this, event);
|
handleTouchEnd(event);
|
||||||
}, false);
|
}, false);
|
||||||
});
|
});
|
||||||
promiseTransactions(this);
|
promiseTransactions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const siyuanApp = new App();
|
const siyuanApp = new App();
|
||||||
|
|
||||||
window.goBack = goBack.apply(siyuanApp);
|
window.goBack = goBack;
|
||||||
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();
|
||||||
|
|
|
||||||
|
|
@ -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(app);
|
initEditor();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -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 = (app: App,element: Element, config: ISearchOption, isAll: boolean) => {
|
const replace = (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 = (app: App,element: Element, config: ISearchOption, isAll: boolea
|
||||||
if (ids.length > 1) {
|
if (ids.length > 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
reloadProtyle(window.siyuan.mobile.editor.protyle, app, false);
|
reloadProtyle(window.siyuan.mobile.editor.protyle, 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(app, element, config, true);
|
replace(element, config, true);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
} else if (type === "replace") {
|
} else if (type === "replace") {
|
||||||
replace(app, element, config, false);
|
replace(element, config, false);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,8 @@ 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 = (app: App, modelMainElement: Element) => {
|
const setEditor = (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;
|
||||||
|
|
@ -41,12 +40,12 @@ const setEditor = (app: App, 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, app, false);
|
reloadProtyle(window.siyuan.mobile.editor.protyle, false);
|
||||||
setInlineStyle();
|
setInlineStyle();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initEditor = (app: App) => {
|
export const initEditor = () => {
|
||||||
openModel({
|
openModel({
|
||||||
title: window.siyuan.languages.editor,
|
title: window.siyuan.languages.editor,
|
||||||
icon: "iconEdit",
|
icon: "iconEdit",
|
||||||
|
|
@ -231,12 +230,12 @@ export const initEditor = (app: App) => {
|
||||||
|
|
||||||
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(app, modelMainElement);
|
setEditor(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(app, modelMainElement);
|
setEditor(modelMainElement);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
modelMainElement.querySelectorAll("input.b3-slider").forEach((item) => {
|
modelMainElement.querySelectorAll("input.b3-slider").forEach((item) => {
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,10 @@ 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, app: App) => {
|
const focusStack = (backStack: IBackStack) => {
|
||||||
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,
|
||||||
|
|
@ -52,7 +51,6 @@ const focusStack = (backStack: IBackStack, app: App) => {
|
||||||
fetchPost("/api/block/checkBlockExist", {id: backStack.id}, existResponse => {
|
fetchPost("/api/block/checkBlockExist", {id: backStack.id}, existResponse => {
|
||||||
if (existResponse.data) {
|
if (existResponse.data) {
|
||||||
zoomOut({
|
zoomOut({
|
||||||
app,
|
|
||||||
protyle,
|
protyle,
|
||||||
id: backStack.id,
|
id: backStack.id,
|
||||||
isPushBack: false,
|
isPushBack: false,
|
||||||
|
|
@ -111,29 +109,7 @@ export const pushBack = () => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const goForward = (app: App) => {
|
export const goBack = () => {
|
||||||
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.dispatchEvent(new CustomEvent("click", {detail: "back"}));
|
|
||||||
return;
|
|
||||||
} else if (document.getElementById("model").style.transform === "translateY(0px)" ||
|
|
||||||
document.getElementById("menu").style.transform === "translateX(0px)" ||
|
|
||||||
document.getElementById("sidebar").style.transform === "translateX(0px)") {
|
|
||||||
closePanel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (window.JSAndroid && forwardStack.length < 2) {
|
|
||||||
window.JSAndroid.returnDesktop();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (forwardStack.length < 2) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
window.siyuan.backStack.push(forwardStack.pop());
|
|
||||||
focusStack(forwardStack[forwardStack.length - 1], app);
|
|
||||||
};
|
|
||||||
|
|
||||||
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")) {
|
||||||
|
|
@ -181,5 +157,5 @@ export const goBack = (app: App) => {
|
||||||
}
|
}
|
||||||
const item = window.siyuan.backStack.pop();
|
const item = window.siyuan.backStack.pop();
|
||||||
forwardStack.push(item);
|
forwardStack.push(item);
|
||||||
focusStack(item, app);
|
focusStack(item);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import {App} from "../../index";
|
||||||
export const initFramework = (app: App) => {
|
export const initFramework = (app: App) => {
|
||||||
setInlineStyle();
|
setInlineStyle();
|
||||||
renderSnippet();
|
renderSnippet();
|
||||||
initKeyboardToolbar(app);
|
initKeyboardToolbar();
|
||||||
const sidebarElement = document.getElementById("sidebar");
|
const sidebarElement = document.getElementById("sidebar");
|
||||||
let outline: MobileOutline;
|
let outline: MobileOutline;
|
||||||
let backlink: MobileBacklinks;
|
let backlink: MobileBacklinks;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ 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;
|
||||||
|
|
@ -328,7 +327,7 @@ export const activeBlur = () => {
|
||||||
(document.activeElement as HTMLElement).blur();
|
(document.activeElement as HTMLElement).blur();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initKeyboardToolbar = (app: App) => {
|
export const initKeyboardToolbar = () => {
|
||||||
let preventRender = false;
|
let preventRender = false;
|
||||||
document.addEventListener("selectionchange", () => {
|
document.addEventListener("selectionchange", () => {
|
||||||
if (!preventRender) {
|
if (!preventRender) {
|
||||||
|
|
@ -417,10 +416,10 @@ export const initKeyboardToolbar = (app: App) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (type === "undo") {
|
if (type === "undo") {
|
||||||
protyle.undo.undo(app, protyle);
|
protyle.undo.undo(protyle);
|
||||||
return;
|
return;
|
||||||
} else if (type === "redo") {
|
} else if (type === "redo") {
|
||||||
protyle.undo.redo(app, protyle);
|
protyle.undo.redo(protyle);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (getSelection().rangeCount === 0) {
|
if (getSelection().rangeCount === 0) {
|
||||||
|
|
@ -476,7 +475,7 @@ export const initKeyboardToolbar = (app: App) => {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else if (type === "more") {
|
} else if (type === "more") {
|
||||||
protyle.breadcrumb.showMenu(app, protyle, {
|
protyle.breadcrumb.showMenu(protyle, {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0
|
y: 0
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import {popMenu} from "../menu";
|
||||||
import {activeBlur, hideKeyboardToolbar} from "./keyboardToolbar";
|
import {activeBlur, hideKeyboardToolbar} from "./keyboardToolbar";
|
||||||
import {getCurrentEditor} from "../editor";
|
import {getCurrentEditor} from "../editor";
|
||||||
import {linkMenu, refMenu, tagMenu} from "../../menus/protyle";
|
import {linkMenu, refMenu, tagMenu} from "../../menus/protyle";
|
||||||
import {App} from "../../index";
|
|
||||||
|
|
||||||
let clientX: number;
|
let clientX: number;
|
||||||
let clientY: number;
|
let clientY: number;
|
||||||
|
|
@ -24,7 +23,7 @@ const popSide = (render = true) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const handleTouchEnd = (app: App, event: TouchEvent) => {
|
export const handleTouchEnd = (event: TouchEvent) => {
|
||||||
const editor = getCurrentEditor();
|
const editor = getCurrentEditor();
|
||||||
if (editor) {
|
if (editor) {
|
||||||
document.querySelectorAll(".protyle-breadcrumb__bar--hide").forEach(item => {
|
document.querySelectorAll(".protyle-breadcrumb__bar--hide").forEach(item => {
|
||||||
|
|
@ -45,13 +44,13 @@ export const handleTouchEnd = (app: App, event: TouchEvent) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (types.includes("block-ref")) {
|
if (types.includes("block-ref")) {
|
||||||
refMenu(app, editor.protyle, target);
|
refMenu(editor.protyle, target);
|
||||||
} else if (types.includes("file-annotation-ref")) {
|
} else if (types.includes("file-annotation-ref")) {
|
||||||
editor.protyle.toolbar.showFileAnnotationRef(editor.protyle, target);
|
editor.protyle.toolbar.showFileAnnotationRef(editor.protyle, target);
|
||||||
} else if (types.includes("tag")) {
|
} else if (types.includes("tag")) {
|
||||||
tagMenu(app, editor.protyle, target);
|
tagMenu(editor.protyle, target);
|
||||||
} else if (types.includes("a")) {
|
} else if (types.includes("a")) {
|
||||||
linkMenu(app, editor.protyle, target);
|
linkMenu(editor.protyle, target);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,7 @@ openTab = (options: {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!options.doc.action) {
|
if (!options.doc.action) {
|
||||||
options.doc.action = []
|
options.doc.action = [];
|
||||||
}
|
}
|
||||||
return openFileById({
|
return openFileById({
|
||||||
app: options.app,
|
app: options.app,
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,7 @@ export const afterLoadPlugin = (plugin: Plugin) => {
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
mergePluginHotkey(plugin);
|
mergePluginHotkey(plugin);
|
||||||
plugin.statusBarIcons.forEach(element => {
|
plugin.statusBarIcons.forEach(element => {
|
||||||
const statusElement = document.getElementById("status")
|
const statusElement = document.getElementById("status");
|
||||||
if (element.getAttribute("data-position") === "right") {
|
if (element.getAttribute("data-position") === "right") {
|
||||||
statusElement.insertAdjacentElement("beforeend", element);
|
statusElement.insertAdjacentElement("beforeend", element);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,8 @@ 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, app: App) => {
|
export const netImg2LocalAssets = (protyle: IProtyle) => {
|
||||||
if (protyle.element.querySelector(".wysiwygLoading")) {
|
if (protyle.element.querySelector(".wysiwygLoading")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -19,11 +18,11 @@ export const netImg2LocalAssets = (protyle: IProtyle, app: App) => {
|
||||||
id: protyle.block.rootID
|
id: protyle.block.rootID
|
||||||
}, () => {
|
}, () => {
|
||||||
/// #if MOBILE
|
/// #if MOBILE
|
||||||
reloadProtyle(protyle, app, false);
|
reloadProtyle(protyle, 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, app, item.editor.protyle.element.isSameNode(protyle.element));
|
reloadProtyle(item.editor.protyle, item.editor.protyle.element.isSameNode(protyle.element));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/// #endif
|
/// #endif
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ import {hideElements} from "../ui/hideElements";
|
||||||
import {confirmDialog} from "../../dialog/confirmDialog";
|
import {confirmDialog} from "../../dialog/confirmDialog";
|
||||||
import {reloadProtyle} from "../util/reload";
|
import {reloadProtyle} from "../util/reload";
|
||||||
import {deleteFile} from "../../editor/deleteFile";
|
import {deleteFile} from "../../editor/deleteFile";
|
||||||
import {App} from "../../index";
|
|
||||||
|
|
||||||
export class Breadcrumb {
|
export class Breadcrumb {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
|
|
@ -33,7 +32,7 @@ export class Breadcrumb {
|
||||||
private id: string;
|
private id: string;
|
||||||
private messageId: string;
|
private messageId: string;
|
||||||
|
|
||||||
constructor(app: App, protyle: IProtyle) {
|
constructor(protyle: IProtyle) {
|
||||||
const element = document.createElement("div");
|
const element = document.createElement("div");
|
||||||
element.className = "protyle-breadcrumb";
|
element.className = "protyle-breadcrumb";
|
||||||
const isFocus = protyle.options.action.includes(Constants.CB_GET_ALL) && !isMobile();
|
const isFocus = protyle.options.action.includes(Constants.CB_GET_ALL) && !isMobile();
|
||||||
|
|
@ -51,31 +50,31 @@ export class Breadcrumb {
|
||||||
if (protyle.options.render.breadcrumbDocName && window.siyuan.ctrlIsPressed) {
|
if (protyle.options.render.breadcrumbDocName && window.siyuan.ctrlIsPressed) {
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
openFileById({
|
openFileById({
|
||||||
app,
|
app:protyle.app,
|
||||||
id,
|
id,
|
||||||
action: id === protyle.block.rootID ? [Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL]
|
action: id === protyle.block.rootID ? [Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL]
|
||||||
});
|
});
|
||||||
/// #endif
|
/// #endif
|
||||||
} else {
|
} else {
|
||||||
zoomOut({protyle, id, app});
|
zoomOut({protyle, id});
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
} else if (target.getAttribute("data-menu") === "true") {
|
} else if (target.getAttribute("data-menu") === "true") {
|
||||||
this.showMenu(app, protyle, {
|
this.showMenu(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, id: protyle.block.rootID, focusId: protyle.block.id, app});
|
zoomOut({protyle, id: protyle.block.rootID, focusId: protyle.block.id});
|
||||||
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, id: protyle.options.blockId, app});
|
zoomOut({protyle, id: protyle.options.blockId});
|
||||||
target.classList.remove("block__icon--active");
|
target.classList.remove("block__icon--active");
|
||||||
} else {
|
} else {
|
||||||
fetchPost("/api/filetree/getDoc", {
|
fetchPost("/api/filetree/getDoc", {
|
||||||
|
|
@ -83,7 +82,7 @@ export class Breadcrumb {
|
||||||
mode: 3,
|
mode: 3,
|
||||||
size: window.siyuan.config.editor.dynamicLoadBlocks,
|
size: window.siyuan.config.editor.dynamicLoadBlocks,
|
||||||
}, getResponse => {
|
}, getResponse => {
|
||||||
onGet({data: getResponse, protyle, action: [Constants.CB_GET_HL], app});
|
onGet({data: getResponse, protyle, action: [Constants.CB_GET_HL]});
|
||||||
this.toggleExit(true);
|
this.toggleExit(true);
|
||||||
});
|
});
|
||||||
target.classList.add("block__icon--active");
|
target.classList.add("block__icon--active");
|
||||||
|
|
@ -158,7 +157,7 @@ export class Breadcrumb {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public showMenu(app: App, protyle: IProtyle, position: { x: number, y: number }) {
|
public showMenu(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 +259,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, app);
|
netImg2LocalAssets(protyle);
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
|
|
@ -303,7 +302,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, app, !isMobile());
|
reloadProtyle(protyle, !isMobile());
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
|
|
|
||||||
|
|
@ -38,16 +38,13 @@ import {isMobile} from "../../util/functions";
|
||||||
import {AIActions} from "../../ai/actions";
|
import {AIActions} from "../../ai/actions";
|
||||||
import {activeBlur} from "../../mobile/util/keyboardToolbar";
|
import {activeBlur} from "../../mobile/util/keyboardToolbar";
|
||||||
import {hideTooltip} from "../../dialog/tooltip";
|
import {hideTooltip} from "../../dialog/tooltip";
|
||||||
import {App} from "../../index";
|
|
||||||
import {appearanceMenu} from "../toolbar/Font";
|
import {appearanceMenu} from "../toolbar/Font";
|
||||||
import {setPosition} from "../../util/setPosition";
|
import {setPosition} from "../../util/setPosition";
|
||||||
|
|
||||||
export class Gutter {
|
export class Gutter {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
private app: App;
|
|
||||||
|
|
||||||
constructor(app: App, protyle: IProtyle) {
|
constructor(protyle: IProtyle) {
|
||||||
this.app = app;
|
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
this.element.className = "protyle-gutters";
|
this.element.className = "protyle-gutters";
|
||||||
if (/Mac/.test(navigator.platform) || navigator.platform === "iPhone") {
|
if (/Mac/.test(navigator.platform) || navigator.platform === "iPhone") {
|
||||||
|
|
@ -164,7 +161,7 @@ export class Gutter {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event.ctrlKey || event.metaKey) {
|
if (event.ctrlKey || event.metaKey) {
|
||||||
zoomOut({protyle, id, app});
|
zoomOut({protyle, id});
|
||||||
} 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 +645,7 @@ export class Gutter {
|
||||||
});
|
});
|
||||||
writeText(protyle.lute.BlockDOM2StdMd(html).trimEnd());
|
writeText(protyle.lute.BlockDOM2StdMd(html).trimEnd());
|
||||||
protyle.breadcrumb?.hide();
|
protyle.breadcrumb?.hide();
|
||||||
removeBlock(this.app, protyle, selectsElement[0], getEditorRange(selectsElement[0]));
|
removeBlock(protyle, selectsElement[0], getEditorRange(selectsElement[0]));
|
||||||
} else {
|
} else {
|
||||||
focusByRange(getEditorRange(selectsElement[0]));
|
focusByRange(getEditorRange(selectsElement[0]));
|
||||||
document.execCommand("cut");
|
document.execCommand("cut");
|
||||||
|
|
@ -661,7 +658,7 @@ export class Gutter {
|
||||||
icon: "iconMove",
|
icon: "iconMove",
|
||||||
click: () => {
|
click: () => {
|
||||||
movePathTo((toPath) => {
|
movePathTo((toPath) => {
|
||||||
hintMoveBlock(toPath[0], selectsElement, protyle, this.app);
|
hintMoveBlock(toPath[0], selectsElement, protyle);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
|
|
@ -671,7 +668,7 @@ export class Gutter {
|
||||||
accelerator: "⌫",
|
accelerator: "⌫",
|
||||||
click: () => {
|
click: () => {
|
||||||
protyle.breadcrumb?.hide();
|
protyle.breadcrumb?.hide();
|
||||||
removeBlock(this.app, protyle, selectsElement[0], getEditorRange(selectsElement[0]));
|
removeBlock(protyle, selectsElement[0], getEditorRange(selectsElement[0]));
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
|
|
||||||
|
|
@ -722,12 +719,12 @@ export class Gutter {
|
||||||
}
|
}
|
||||||
ids.push(item.getAttribute("data-node-id"));
|
ids.push(item.getAttribute("data-node-id"));
|
||||||
});
|
});
|
||||||
makeCard(this.app, ids);
|
makeCard(protyle.app, ids);
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
}
|
}
|
||||||
const pluginSubMenu = new subMenu();
|
const pluginSubMenu = new subMenu();
|
||||||
this.app?.plugins?.forEach((plugin) => {
|
protyle.app?.plugins?.forEach((plugin) => {
|
||||||
plugin.eventBus.emit("click-blockicon", {
|
plugin.eventBus.emit("click-blockicon", {
|
||||||
protyle,
|
protyle,
|
||||||
menu: pluginSubMenu,
|
menu: pluginSubMenu,
|
||||||
|
|
@ -1078,7 +1075,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(this.app, protyle, nodeElement, getEditorRange(nodeElement));
|
removeBlock(protyle, nodeElement, getEditorRange(nodeElement));
|
||||||
protyle.breadcrumb?.hide();
|
protyle.breadcrumb?.hide();
|
||||||
} else {
|
} else {
|
||||||
focusByRange(getEditorRange(nodeElement));
|
focusByRange(getEditorRange(nodeElement));
|
||||||
|
|
@ -1092,7 +1089,7 @@ export class Gutter {
|
||||||
icon: "iconMove",
|
icon: "iconMove",
|
||||||
click: () => {
|
click: () => {
|
||||||
movePathTo((toPath) => {
|
movePathTo((toPath) => {
|
||||||
hintMoveBlock(toPath[0], [nodeElement], protyle, this.app);
|
hintMoveBlock(toPath[0], [nodeElement], protyle);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
|
|
@ -1102,7 +1099,7 @@ export class Gutter {
|
||||||
accelerator: "⌫",
|
accelerator: "⌫",
|
||||||
click: () => {
|
click: () => {
|
||||||
protyle.breadcrumb?.hide();
|
protyle.breadcrumb?.hide();
|
||||||
removeBlock(this.app, protyle, nodeElement, getEditorRange(nodeElement));
|
removeBlock(protyle, nodeElement, getEditorRange(nodeElement));
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
}
|
}
|
||||||
|
|
@ -1241,7 +1238,7 @@ export class Gutter {
|
||||||
type: "submenu",
|
type: "submenu",
|
||||||
icon: type === "NodeVideo" ? "iconVideo" : "iconRecord",
|
icon: type === "NodeVideo" ? "iconVideo" : "iconRecord",
|
||||||
label: window.siyuan.languages.assets,
|
label: window.siyuan.languages.assets,
|
||||||
submenu: videoMenu(this.app, protyle, nodeElement, type)
|
submenu: videoMenu(protyle, nodeElement, type)
|
||||||
}).element);
|
}).element);
|
||||||
} else if (type === "NodeIFrame" && !protyle.disabled) {
|
} else if (type === "NodeIFrame" && !protyle.disabled) {
|
||||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||||
|
|
@ -1250,7 +1247,7 @@ export class Gutter {
|
||||||
type: "submenu",
|
type: "submenu",
|
||||||
icon: "iconLanguage",
|
icon: "iconLanguage",
|
||||||
label: window.siyuan.languages.assets,
|
label: window.siyuan.languages.assets,
|
||||||
submenu: iframeMenu(this.app, protyle, nodeElement)
|
submenu: iframeMenu(protyle, nodeElement)
|
||||||
}).element);
|
}).element);
|
||||||
} else if (type === "NodeHTMLBlock" && !protyle.disabled) {
|
} else if (type === "NodeHTMLBlock" && !protyle.disabled) {
|
||||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||||
|
|
@ -1402,7 +1399,7 @@ export class Gutter {
|
||||||
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, app: this.app});
|
zoomOut({protyle, id});
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
|
|
@ -1413,17 +1410,17 @@ export class Gutter {
|
||||||
const ids = protyle.path.split("/");
|
const ids = protyle.path.split("/");
|
||||||
if (ids.length > 2) {
|
if (ids.length > 2) {
|
||||||
/// #if MOBILE
|
/// #if MOBILE
|
||||||
openMobileFileById(this.app, ids[ids.length - 2], [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]);
|
openMobileFileById(protyle.app, ids[ids.length - 2], [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]);
|
||||||
/// #else
|
/// #else
|
||||||
openFileById({
|
openFileById({
|
||||||
app: this.app,
|
app: protyle.app,
|
||||||
id: ids[ids.length - 2],
|
id: ids[ids.length - 2],
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
|
||||||
});
|
});
|
||||||
/// #endif
|
/// #endif
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
zoomOut({protyle, id:protyle.block.parent2ID, focusId:id, app: this.app});
|
zoomOut({protyle, id:protyle.block.parent2ID, focusId:id});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
|
|
@ -1536,14 +1533,14 @@ export class Gutter {
|
||||||
label: window.siyuan.languages.addToDeck,
|
label: window.siyuan.languages.addToDeck,
|
||||||
icon: "iconRiffCard",
|
icon: "iconRiffCard",
|
||||||
click() {
|
click() {
|
||||||
makeCard(this.app, [nodeElement.getAttribute("data-node-id")]);
|
makeCard(protyle.app, [nodeElement.getAttribute("data-node-id")]);
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
}
|
}
|
||||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||||
}
|
}
|
||||||
const pluginSubMenu = new subMenu();
|
const pluginSubMenu = new subMenu();
|
||||||
this.app?.plugins?.forEach((plugin) => {
|
protyle.app?.plugins?.forEach((plugin) => {
|
||||||
plugin.eventBus.emit("click-blockicon", {
|
plugin.eventBus.emit("click-blockicon", {
|
||||||
protyle,
|
protyle,
|
||||||
menu: pluginSubMenu,
|
menu: pluginSubMenu,
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ import {popSearch} from "../../mobile/menu/search";
|
||||||
import {getEventName} from "../util/compatibility";
|
import {getEventName} from "../util/compatibility";
|
||||||
import {Dialog} from "../../dialog";
|
import {Dialog} from "../../dialog";
|
||||||
import {Constants} from "../../constants";
|
import {Constants} from "../../constants";
|
||||||
import {App} from "../../index";
|
|
||||||
|
|
||||||
export class Background {
|
export class Background {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
|
|
@ -23,7 +22,7 @@ export class Background {
|
||||||
private tagsElement: HTMLElement;
|
private tagsElement: HTMLElement;
|
||||||
private transparentData = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";
|
private transparentData = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";
|
||||||
|
|
||||||
constructor(app: App, protyle: IProtyle) {
|
constructor(protyle: IProtyle) {
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
this.element.className = "protyle-background";
|
this.element.className = "protyle-background";
|
||||||
this.element.innerHTML = `<div class="protyle-background__img">
|
this.element.innerHTML = `<div class="protyle-background__img">
|
||||||
|
|
@ -332,10 +331,10 @@ export class Background {
|
||||||
break;
|
break;
|
||||||
} else if (type === "open-search") {
|
} else if (type === "open-search") {
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
openGlobalSearch(app, `#${target.textContent}#`, !window.siyuan.ctrlIsPressed);
|
openGlobalSearch(protyle.app, `#${target.textContent}#`, !window.siyuan.ctrlIsPressed);
|
||||||
/// #else
|
/// #else
|
||||||
const searchOption = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
|
const searchOption = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
|
||||||
popSearch(app, {
|
popSearch(protyle.app, {
|
||||||
removed: searchOption.removed,
|
removed: searchOption.removed,
|
||||||
sort: searchOption.sort,
|
sort: searchOption.sort,
|
||||||
group: searchOption.group,
|
group: searchOption.group,
|
||||||
|
|
|
||||||
|
|
@ -36,16 +36,13 @@ import {makeCard, quickMakeCard} from "../../card/makeCard";
|
||||||
import {viewCards} from "../../card/viewCards";
|
import {viewCards} from "../../card/viewCards";
|
||||||
import {getNotebookName, pathPosix} from "../../util/pathName";
|
import {getNotebookName, pathPosix} from "../../util/pathName";
|
||||||
import {commonClick} from "../wysiwyg/commonClick";
|
import {commonClick} from "../wysiwyg/commonClick";
|
||||||
import {App} from "../../index";
|
|
||||||
|
|
||||||
export class Title {
|
export class Title {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
public editElement: HTMLElement;
|
public editElement: HTMLElement;
|
||||||
private timeout: number;
|
private timeout: number;
|
||||||
private app: App;
|
|
||||||
|
|
||||||
constructor(app: App, protyle: IProtyle) {
|
constructor(protyle: IProtyle) {
|
||||||
this.app = app;
|
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
this.element.className = "protyle-title";
|
this.element.className = "protyle-title";
|
||||||
if (window.siyuan.config.editor.displayBookmarkIcon) {
|
if (window.siyuan.config.editor.displayBookmarkIcon) {
|
||||||
|
|
@ -93,14 +90,14 @@ export class Title {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commonHotkey(app, protyle, event)) {
|
if (commonHotkey(protyle, event)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (matchHotKey(window.siyuan.config.keymap.general.enterBack.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.general.enterBack.custom, event)) {
|
||||||
const ids = protyle.path.split("/");
|
const ids = protyle.path.split("/");
|
||||||
if (ids.length > 2) {
|
if (ids.length > 2) {
|
||||||
openFileById({
|
openFileById({
|
||||||
app,
|
app: protyle.app,
|
||||||
id: ids[ids.length - 2],
|
id: ids[ids.length - 2],
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
|
||||||
});
|
});
|
||||||
|
|
@ -268,7 +265,7 @@ export class Title {
|
||||||
fetchPost("/api/block/getDocInfo", {
|
fetchPost("/api/block/getDocInfo", {
|
||||||
id: protyle.block.rootID
|
id: protyle.block.rootID
|
||||||
}, (response) => {
|
}, (response) => {
|
||||||
commonClick(app, event, protyle, response.data.ial);
|
commonClick(event, protyle, response.data.ial);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -334,7 +331,7 @@ export class Title {
|
||||||
label: window.siyuan.languages.outline,
|
label: window.siyuan.languages.outline,
|
||||||
accelerator: window.siyuan.config.keymap.editor.general.outline.custom,
|
accelerator: window.siyuan.config.keymap.editor.general.outline.custom,
|
||||||
click: () => {
|
click: () => {
|
||||||
openOutline(this.app, protyle);
|
openOutline(protyle);
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
|
|
@ -342,7 +339,7 @@ export class Title {
|
||||||
label: window.siyuan.languages.backlinks,
|
label: window.siyuan.languages.backlinks,
|
||||||
accelerator: window.siyuan.config.keymap.editor.general.backlinks.custom,
|
accelerator: window.siyuan.config.keymap.editor.general.backlinks.custom,
|
||||||
click: () => {
|
click: () => {
|
||||||
openBacklink(this.app, protyle);
|
openBacklink(protyle);
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
|
|
@ -350,7 +347,7 @@ export class Title {
|
||||||
label: window.siyuan.languages.graphView,
|
label: window.siyuan.languages.graphView,
|
||||||
accelerator: window.siyuan.config.keymap.editor.general.graphView.custom,
|
accelerator: window.siyuan.config.keymap.editor.general.graphView.custom,
|
||||||
click: () => {
|
click: () => {
|
||||||
openGraph(this.app, protyle);
|
openGraph(protyle);
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||||
|
|
@ -367,7 +364,7 @@ export class Title {
|
||||||
accelerator: window.siyuan.config.keymap.editor.general.spaceRepetition.custom,
|
accelerator: window.siyuan.config.keymap.editor.general.spaceRepetition.custom,
|
||||||
click: () => {
|
click: () => {
|
||||||
fetchPost("/api/riff/getTreeRiffDueCards", {rootID: protyle.block.rootID}, (response) => {
|
fetchPost("/api/riff/getTreeRiffDueCards", {rootID: protyle.block.rootID}, (response) => {
|
||||||
openCardByData(this.app, response.data, "doc", protyle.block.rootID, this.editElement.textContent || "Untitled");
|
openCardByData(protyle.app, response.data, "doc", protyle.block.rootID, this.editElement.textContent || "Untitled");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
|
|
@ -377,7 +374,7 @@ export class Title {
|
||||||
fetchPost("/api/filetree/getHPathByID", {
|
fetchPost("/api/filetree/getHPathByID", {
|
||||||
id: protyle.block.rootID
|
id: protyle.block.rootID
|
||||||
}, (response) => {
|
}, (response) => {
|
||||||
viewCards(this.app, protyle.block.rootID, pathPosix().join(getNotebookName(protyle.notebookId), (response.data)), "Tree");
|
viewCards(protyle.app, protyle.block.rootID, pathPosix().join(getNotebookName(protyle.notebookId), (response.data)), "Tree");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
|
|
@ -393,7 +390,7 @@ export class Title {
|
||||||
iconHTML: Constants.ZWSP,
|
iconHTML: Constants.ZWSP,
|
||||||
label: window.siyuan.languages.addToDeck,
|
label: window.siyuan.languages.addToDeck,
|
||||||
click: () => {
|
click: () => {
|
||||||
makeCard(this.app, [protyle.block.rootID]);
|
makeCard(protyle.app, [protyle.block.rootID]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -411,7 +408,7 @@ export class Title {
|
||||||
${window.siyuan.languages.createdAt} ${dayjs(response.data.ial.id.substr(0, 14)).format("YYYY-MM-DD HH:mm:ss")}`
|
${window.siyuan.languages.createdAt} ${dayjs(response.data.ial.id.substr(0, 14)).format("YYYY-MM-DD HH:mm:ss")}`
|
||||||
}).element);
|
}).element);
|
||||||
window.siyuan.menus.menu.popup(position);
|
window.siyuan.menus.menu.popup(position);
|
||||||
this.app?.plugins?.forEach((plugin) => {
|
protyle.app?.plugins?.forEach((plugin) => {
|
||||||
plugin.eventBus.emit("click-editortitleicon", {
|
plugin.eventBus.emit("click-editortitleicon", {
|
||||||
protyle,
|
protyle,
|
||||||
menu: window.siyuan.menus.menu,
|
menu: window.siyuan.menus.menu,
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ 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[] = [{
|
||||||
|
|
@ -462,7 +461,7 @@ export const hintRenderAssets = (value: string, protyle: IProtyle) => {
|
||||||
hideElements(["util"], protyle);
|
hideElements(["util"], protyle);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const hintMoveBlock = (pathString: string, sourceElements: Element[], protyle: IProtyle, app: App) => {
|
export const hintMoveBlock = (pathString: string, sourceElements: Element[], protyle: IProtyle) => {
|
||||||
if (pathString === "/") {
|
if (pathString === "/") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -513,7 +512,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({app, protyle, id: protyle.block.parent2ID, focusId:protyle.block.parent2ID});
|
zoomOut({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) &&
|
||||||
|
|
|
||||||
|
|
@ -32,20 +32,17 @@ import {processRender} from "../util/processCode";
|
||||||
import {AIChat} from "../../ai/chat";
|
import {AIChat} from "../../ai/chat";
|
||||||
import {isMobile} from "../../util/functions";
|
import {isMobile} from "../../util/functions";
|
||||||
import {isCtrl} from "../util/compatibility";
|
import {isCtrl} from "../util/compatibility";
|
||||||
import {App} from "../../index";
|
|
||||||
|
|
||||||
export class Hint {
|
export class Hint {
|
||||||
public timeId: number;
|
public timeId: number;
|
||||||
public element: HTMLDivElement;
|
public element: HTMLDivElement;
|
||||||
public enableSlash = true;
|
public enableSlash = true;
|
||||||
private enableEmoji = true;
|
private enableEmoji = true;
|
||||||
private app: App;
|
|
||||||
public enableExtend = false;
|
public enableExtend = false;
|
||||||
public splitChar = "";
|
public splitChar = "";
|
||||||
public lastIndex = -1;
|
public lastIndex = -1;
|
||||||
|
|
||||||
constructor(app: App, protyle: IProtyle) {
|
constructor(protyle: IProtyle) {
|
||||||
this.app = app;
|
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
this.element.setAttribute("data-close", "false");
|
this.element.setAttribute("data-close", "false");
|
||||||
// height 402 根据 .emojis max-height+8 得来
|
// height 402 根据 .emojis max-height+8 得来
|
||||||
|
|
@ -580,10 +577,10 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
|
||||||
}, () => {
|
}, () => {
|
||||||
insertHTML(`<span data-type="block-ref" data-id="${newSubDocId}" data-subtype="d">Untitled</span>`, protyle);
|
insertHTML(`<span data-type="block-ref" data-id="${newSubDocId}" data-subtype="d">Untitled</span>`, protyle);
|
||||||
/// #if MOBILE
|
/// #if MOBILE
|
||||||
openMobileFileById(this.app, newSubDocId, [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
|
openMobileFileById(protyle.app, newSubDocId, [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
|
||||||
/// #else
|
/// #else
|
||||||
openFileById({
|
openFileById({
|
||||||
app: this.app,
|
app: protyle.app,
|
||||||
id: newSubDocId,
|
id: newSubDocId,
|
||||||
action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]
|
action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]
|
||||||
});
|
});
|
||||||
|
|
@ -649,7 +646,7 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const rect = imgElement.getBoundingClientRect();
|
const rect = imgElement.getBoundingClientRect();
|
||||||
imgMenu(this.app, protyle, range, imgElement, {
|
imgMenu(protyle, range, imgElement, {
|
||||||
clientX: rect.left,
|
clientX: rect.left,
|
||||||
clientY: rect.top
|
clientY: rect.top
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -34,19 +34,18 @@ export class Protyle {
|
||||||
|
|
||||||
public readonly version: string;
|
public readonly version: string;
|
||||||
public protyle: IProtyle;
|
public protyle: IProtyle;
|
||||||
private app: App;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param id 要挂载 Protyle 的元素或者元素 ID。
|
* @param id 要挂载 Protyle 的元素或者元素 ID。
|
||||||
* @param options Protyle 参数
|
* @param options Protyle 参数
|
||||||
*/
|
*/
|
||||||
constructor(app: App, id: HTMLElement, options?: IOptions) {
|
constructor(app: App, id: HTMLElement, options?: IOptions) {
|
||||||
this.app = app;
|
|
||||||
this.version = Constants.SIYUAN_VERSION;
|
this.version = Constants.SIYUAN_VERSION;
|
||||||
const getOptions = new Options(options);
|
const getOptions = new Options(options);
|
||||||
const mergedOptions = getOptions.merge();
|
const mergedOptions = getOptions.merge();
|
||||||
|
|
||||||
this.protyle = {
|
this.protyle = {
|
||||||
|
app,
|
||||||
transactionTime: new Date().getTime(),
|
transactionTime: new Date().getTime(),
|
||||||
id: genUUID(),
|
id: genUUID(),
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
|
@ -56,17 +55,17 @@ export class Protyle {
|
||||||
block: {},
|
block: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
this.protyle.hint = new Hint(app, this.protyle);
|
this.protyle.hint = new Hint(this.protyle);
|
||||||
if (mergedOptions.render.breadcrumb) {
|
if (mergedOptions.render.breadcrumb) {
|
||||||
this.protyle.breadcrumb = new Breadcrumb(app, this.protyle);
|
this.protyle.breadcrumb = new Breadcrumb(this.protyle);
|
||||||
}
|
}
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
if (mergedOptions.render.title) {
|
if (mergedOptions.render.title) {
|
||||||
this.protyle.title = new Title(app, this.protyle);
|
this.protyle.title = new Title(this.protyle);
|
||||||
}
|
}
|
||||||
/// #endif
|
/// #endif
|
||||||
if (mergedOptions.render.background) {
|
if (mergedOptions.render.background) {
|
||||||
this.protyle.background = new Background(app, this.protyle);
|
this.protyle.background = new Background(this.protyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.protyle.element.innerHTML = "";
|
this.protyle.element.innerHTML = "";
|
||||||
|
|
@ -75,11 +74,11 @@ export class Protyle {
|
||||||
this.protyle.element.appendChild(this.protyle.breadcrumb.element.parentElement);
|
this.protyle.element.appendChild(this.protyle.breadcrumb.element.parentElement);
|
||||||
}
|
}
|
||||||
this.protyle.undo = new Undo();
|
this.protyle.undo = new Undo();
|
||||||
this.protyle.wysiwyg = new WYSIWYG(app, this.protyle);
|
this.protyle.wysiwyg = new WYSIWYG(this.protyle);
|
||||||
this.protyle.toolbar = new Toolbar(app, this.protyle);
|
this.protyle.toolbar = new Toolbar(this.protyle);
|
||||||
this.protyle.scroll = new Scroll(this.protyle, this.app); // 不能使用 render.scroll 来判读是否初始化,除非重构后面用到的相关变量
|
this.protyle.scroll = new Scroll(this.protyle); // 不能使用 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(this.protyle);
|
||||||
}
|
}
|
||||||
if (mergedOptions.upload.url || mergedOptions.upload.handler) {
|
if (mergedOptions.upload.url || mergedOptions.upload.handler) {
|
||||||
this.protyle.upload = new Upload();
|
this.protyle.upload = new Upload();
|
||||||
|
|
@ -95,7 +94,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, app, false);
|
reloadProtyle(this.protyle, false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "addLoading":
|
case "addLoading":
|
||||||
|
|
@ -105,7 +104,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(app, this.protyle, item, false);
|
onTransaction(this.protyle, item, false);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "readonly":
|
case "readonly":
|
||||||
|
|
@ -123,10 +122,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({data: getResponse, protyle: this.protyle, app: this.app});
|
onGet({data: getResponse, protyle: this.protyle});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
reloadProtyle(this.protyle, app, false);
|
reloadProtyle(this.protyle, false);
|
||||||
}
|
}
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
if (data.cmd === "heading2doc") {
|
if (data.cmd === "heading2doc") {
|
||||||
|
|
@ -224,7 +223,6 @@ 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,
|
||||||
|
|
@ -238,7 +236,6 @@ export class Protyle {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
getDocByScroll({
|
getDocByScroll({
|
||||||
app: this.app,
|
|
||||||
protyle: this.protyle,
|
protyle: this.protyle,
|
||||||
scrollAttr: options.scrollAttr,
|
scrollAttr: options.scrollAttr,
|
||||||
mergedOptions,
|
mergedOptions,
|
||||||
|
|
@ -262,7 +259,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({data: getResponse, protyle: this.protyle, app: this.app, action: mergedOptions.action});
|
onGet({data: getResponse, protyle: this.protyle, action: mergedOptions.action});
|
||||||
this.afterOnGet(mergedOptions);
|
this.afterOnGet(mergedOptions);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -330,9 +327,9 @@ export class Protyle {
|
||||||
sanitize: this.protyle.options.preview.markdown.sanitize,
|
sanitize: this.protyle.options.preview.markdown.sanitize,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.protyle.preview = new Preview(this.app, this.protyle);
|
this.protyle.preview = new Preview(this.protyle);
|
||||||
|
|
||||||
initUI(this.protyle, this.app);
|
initUI(this.protyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 聚焦到编辑器 */
|
/** 聚焦到编辑器 */
|
||||||
|
|
|
||||||
|
|
@ -17,14 +17,13 @@ import {fetchPost} from "../../util/fetch";
|
||||||
import {processRender} from "../util/processCode";
|
import {processRender} from "../util/processCode";
|
||||||
import {highlightRender} from "../markdown/highlightRender";
|
import {highlightRender} from "../markdown/highlightRender";
|
||||||
import {speechRender} from "../markdown/speechRender";
|
import {speechRender} from "../markdown/speechRender";
|
||||||
import {App} from "../../index";
|
|
||||||
|
|
||||||
export class Preview {
|
export class Preview {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
public previewElement: HTMLElement;
|
public previewElement: HTMLElement;
|
||||||
private mdTimeoutId: number;
|
private mdTimeoutId: number;
|
||||||
|
|
||||||
constructor(app: App, protyle: IProtyle) {
|
constructor(protyle: IProtyle) {
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
this.element.className = "protyle-preview fn__none";
|
this.element.className = "protyle-preview fn__none";
|
||||||
|
|
||||||
|
|
@ -56,7 +55,7 @@ export class Preview {
|
||||||
if (isLocalPath(linkAddress)) {
|
if (isLocalPath(linkAddress)) {
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
if (Constants.SIYUAN_ASSETS_EXTS.includes(pathPosix().extname((linkAddress.split("?page")[0])))) {
|
if (Constants.SIYUAN_ASSETS_EXTS.includes(pathPosix().extname((linkAddress.split("?page")[0])))) {
|
||||||
openAsset(app, linkAddress.split("?page")[0], parseInt(getSearch("page", linkAddress)));
|
openAsset(protyle.app, linkAddress.split("?page")[0], parseInt(getSearch("page", linkAddress)));
|
||||||
} else {
|
} else {
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
openBy(linkAddress, "folder");
|
openBy(linkAddress, "folder");
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,9 @@ 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 = (app: App, protyle: IProtyle, element: HTMLElement) => {
|
export const scrollEvent = (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")) {
|
||||||
|
|
@ -75,7 +74,6 @@ export const scrollEvent = (app: App, protyle: IProtyle, element: HTMLElement) =
|
||||||
data: getResponse,
|
data: getResponse,
|
||||||
protyle,
|
protyle,
|
||||||
action: [Constants.CB_GET_BEFORE, Constants.CB_GET_UNCHANGEID],
|
action: [Constants.CB_GET_BEFORE, Constants.CB_GET_UNCHANGEID],
|
||||||
app
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -92,7 +90,6 @@ export const scrollEvent = (app: App, protyle: IProtyle, element: HTMLElement) =
|
||||||
data: getResponse,
|
data: getResponse,
|
||||||
protyle,
|
protyle,
|
||||||
action: [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID],
|
action: [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID],
|
||||||
app
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ 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;
|
||||||
|
|
@ -14,7 +13,7 @@ export class Scroll {
|
||||||
public lastScrollTop: number;
|
public lastScrollTop: number;
|
||||||
public keepLazyLoad: boolean; // 保持加载内容
|
public keepLazyLoad: boolean; // 保持加载内容
|
||||||
|
|
||||||
constructor(protyle: IProtyle, app: App) {
|
constructor(protyle: IProtyle) {
|
||||||
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()) {
|
||||||
|
|
@ -42,25 +41,25 @@ export class Scroll {
|
||||||
});
|
});
|
||||||
/// #if BROWSER
|
/// #if BROWSER
|
||||||
this.inputElement.addEventListener("change", () => {
|
this.inputElement.addEventListener("change", () => {
|
||||||
this.setIndex(protyle, app);
|
this.setIndex(protyle);
|
||||||
});
|
});
|
||||||
this.inputElement.addEventListener("touchend", () => {
|
this.inputElement.addEventListener("touchend", () => {
|
||||||
this.setIndex(protyle, app);
|
this.setIndex(protyle);
|
||||||
});
|
});
|
||||||
/// #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, app);
|
goHome(protyle);
|
||||||
} else if (hasClosestByClassName(target, "protyle-scroll__down")) {
|
} else if (hasClosestByClassName(target, "protyle-scroll__down")) {
|
||||||
goEnd(protyle, app);
|
goEnd(protyle);
|
||||||
} else if (target.classList.contains("b3-slider")) {
|
} else if (target.classList.contains("b3-slider")) {
|
||||||
this.setIndex(protyle, app);
|
this.setIndex(protyle);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private setIndex(protyle: IProtyle, app: App) {
|
private setIndex(protyle: IProtyle) {
|
||||||
if (protyle.wysiwyg.element.getAttribute("data-top")) {
|
if (protyle.wysiwyg.element.getAttribute("data-top")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -75,7 +74,6 @@ export class Scroll {
|
||||||
data: getResponse,
|
data: getResponse,
|
||||||
protyle,
|
protyle,
|
||||||
action: [Constants.CB_GET_FOCUSFIRST, Constants.CB_GET_UNCHANGEID],
|
action: [Constants.CB_GET_FOCUSFIRST, Constants.CB_GET_UNCHANGEID],
|
||||||
app
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ 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) {
|
||||||
|
|
@ -46,7 +45,6 @@ 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,
|
||||||
|
|
@ -75,7 +73,6 @@ export const getDocByScroll = (options: {
|
||||||
protyle: options.protyle,
|
protyle: options.protyle,
|
||||||
action: actions,
|
action: actions,
|
||||||
scrollAttr: options.scrollAttr,
|
scrollAttr: options.scrollAttr,
|
||||||
app: options.app
|
|
||||||
});
|
});
|
||||||
if (options.cb) {
|
if (options.cb) {
|
||||||
options.cb();
|
options.cb();
|
||||||
|
|
@ -94,7 +91,6 @@ export const getDocByScroll = (options: {
|
||||||
protyle: options.protyle,
|
protyle: options.protyle,
|
||||||
action: actions,
|
action: actions,
|
||||||
scrollAttr: options.scrollAttr,
|
scrollAttr: options.scrollAttr,
|
||||||
app: options.app
|
|
||||||
});
|
});
|
||||||
if (options.cb) {
|
if (options.cb) {
|
||||||
options.cb();
|
options.cb();
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,11 @@ import {hasClosestBlock, hasClosestByAttribute} from "../util/hasClosest";
|
||||||
import {focusByRange, focusByWbr} from "../util/selection";
|
import {focusByRange, focusByWbr} from "../util/selection";
|
||||||
import {readText} from "../util/compatibility";
|
import {readText} from "../util/compatibility";
|
||||||
import {Constants} from "../../constants";
|
import {Constants} from "../../constants";
|
||||||
import {App} from "../../index";
|
|
||||||
|
|
||||||
export class Link extends ToolbarItem {
|
export class Link extends ToolbarItem {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
|
|
||||||
constructor(app: App, protyle: IProtyle, menuItem: IMenuItem) {
|
constructor(protyle: IProtyle, menuItem: IMenuItem) {
|
||||||
super(protyle, menuItem);
|
super(protyle, menuItem);
|
||||||
// 不能用 getEventName,否则会导致光标位置变动到点击的文档中
|
// 不能用 getEventName,否则会导致光标位置变动到点击的文档中
|
||||||
this.element.addEventListener("click", async (event: MouseEvent & { changedTouches: MouseEvent[] }) => {
|
this.element.addEventListener("click", async (event: MouseEvent & { changedTouches: MouseEvent[] }) => {
|
||||||
|
|
@ -23,7 +22,7 @@ export class Link extends ToolbarItem {
|
||||||
}
|
}
|
||||||
const aElement = hasClosestByAttribute(range.startContainer, "data-type", "a");
|
const aElement = hasClosestByAttribute(range.startContainer, "data-type", "a");
|
||||||
if (aElement) {
|
if (aElement) {
|
||||||
linkMenu(app, protyle, aElement);
|
linkMenu(protyle, aElement);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,6 @@ import {mathRender} from "../markdown/mathRender";
|
||||||
import {linkMenu} from "../../menus/protyle";
|
import {linkMenu} from "../../menus/protyle";
|
||||||
import {addScript} from "../util/addScript";
|
import {addScript} from "../util/addScript";
|
||||||
import {confirmDialog} from "../../dialog/confirmDialog";
|
import {confirmDialog} from "../../dialog/confirmDialog";
|
||||||
import {App} from "../../index";
|
|
||||||
|
|
||||||
export class Toolbar {
|
export class Toolbar {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
|
|
@ -53,11 +52,9 @@ export class Toolbar {
|
||||||
public subElementCloseCB: () => void;
|
public subElementCloseCB: () => void;
|
||||||
public range: Range;
|
public range: Range;
|
||||||
private toolbarHeight: number;
|
private toolbarHeight: number;
|
||||||
private app: App;
|
|
||||||
|
|
||||||
constructor(app: App, protyle: IProtyle) {
|
constructor(protyle: IProtyle) {
|
||||||
const options = protyle.options;
|
const options = protyle.options;
|
||||||
this.app = app;
|
|
||||||
const element = document.createElement("div");
|
const element = document.createElement("div");
|
||||||
element.className = "protyle-toolbar fn__none";
|
element.className = "protyle-toolbar fn__none";
|
||||||
this.element = element;
|
this.element = element;
|
||||||
|
|
@ -229,7 +226,7 @@ export class Toolbar {
|
||||||
menuItemObj = new Font(protyle, menuItem);
|
menuItemObj = new Font(protyle, menuItem);
|
||||||
break;
|
break;
|
||||||
case "a":
|
case "a":
|
||||||
menuItemObj = new Link(this.app, protyle, menuItem);
|
menuItemObj = new Link(protyle, menuItem);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!menuItemObj) {
|
if (!menuItemObj) {
|
||||||
|
|
@ -733,7 +730,7 @@ export class Toolbar {
|
||||||
const aElement = newNodes[0] as HTMLElement;
|
const aElement = newNodes[0] as HTMLElement;
|
||||||
if (aElement.textContent.replace(Constants.ZWSP, "") === "" || !aElement.getAttribute("data-href")) {
|
if (aElement.textContent.replace(Constants.ZWSP, "") === "" || !aElement.getAttribute("data-href")) {
|
||||||
needFocus = false;
|
needFocus = false;
|
||||||
linkMenu(this.app, protyle, aElement, aElement.getAttribute("data-href") ? true : false);
|
linkMenu(protyle, aElement, aElement.getAttribute("data-href") ? true : false);
|
||||||
} else {
|
} else {
|
||||||
this.range.collapse(false);
|
this.range.collapse(false);
|
||||||
}
|
}
|
||||||
|
|
@ -1199,7 +1196,7 @@ export class Toolbar {
|
||||||
if (!protyle.disabled) {
|
if (!protyle.disabled) {
|
||||||
textElement.select();
|
textElement.select();
|
||||||
}
|
}
|
||||||
this.app.plugins.forEach(item => {
|
protyle.app.plugins.forEach(item => {
|
||||||
item.eventBus.emit("open-noneditableblock", {
|
item.eventBus.emit("open-noneditableblock", {
|
||||||
protyle,
|
protyle,
|
||||||
toolbar: this
|
toolbar: this
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,8 @@ 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, app: App) => {
|
export const initUI = (protyle: IProtyle) => {
|
||||||
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) {
|
||||||
|
|
@ -25,7 +24,7 @@ export const initUI = (protyle: IProtyle, app: App) => {
|
||||||
}
|
}
|
||||||
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(app, protyle, protyle.contentElement);
|
scrollEvent(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);
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ 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[],
|
||||||
|
|
@ -24,7 +23,7 @@ export class Undo {
|
||||||
this.undoStack = [];
|
this.undoStack = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public undo(app: App, protyle: IProtyle) {
|
public undo(protyle: IProtyle) {
|
||||||
if (protyle.disabled) {
|
if (protyle.disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -32,13 +31,13 @@ export class Undo {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const state = this.undoStack.pop();
|
const state = this.undoStack.pop();
|
||||||
this.render(app, protyle, state, false);
|
this.render(protyle, state, false);
|
||||||
this.hasUndo = true;
|
this.hasUndo = true;
|
||||||
this.redoStack.push(state);
|
this.redoStack.push(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public redo(app: App, protyle: IProtyle) {
|
public redo(protyle: IProtyle) {
|
||||||
if (protyle.disabled) {
|
if (protyle.disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -46,21 +45,21 @@ export class Undo {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const state = this.redoStack.pop();
|
const state = this.redoStack.pop();
|
||||||
this.render(app, protyle, state, true);
|
this.render(protyle, state, true);
|
||||||
this.undoStack.push(state);
|
this.undoStack.push(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
private render(app: App, protyle: IProtyle, state: IOperations, redo: boolean) {
|
private render(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(app, protyle, item, true);
|
onTransaction(protyle, item, true);
|
||||||
});
|
});
|
||||||
transaction(protyle, state.undoOperations);
|
transaction(protyle, state.undoOperations);
|
||||||
} else {
|
} else {
|
||||||
state.doOperations.forEach(item => {
|
state.doOperations.forEach(item => {
|
||||||
onTransaction(app, protyle, item, true);
|
onTransaction(protyle, item, true);
|
||||||
});
|
});
|
||||||
transaction(protyle, state.doOperations);
|
transaction(protyle, state.doOperations);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ 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) => {
|
||||||
|
|
@ -696,7 +695,7 @@ const dragSame = async (protyle: IProtyle, sourceElements: Element[], targetElem
|
||||||
focusBlock(sourceElements[0]);
|
focusBlock(sourceElements[0]);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const dropEvent = (app: App, protyle: IProtyle, editorElement: HTMLElement) => {
|
export const dropEvent = (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") {
|
||||||
|
|
@ -853,7 +852,7 @@ export const dropEvent = (app: App, protyle: IProtyle, editorElement: HTMLElemen
|
||||||
id: protyle.block.id,
|
id: protyle.block.id,
|
||||||
size: window.siyuan.config.editor.dynamicLoadBlocks,
|
size: window.siyuan.config.editor.dynamicLoadBlocks,
|
||||||
}, getResponse => {
|
}, getResponse => {
|
||||||
onGet({data: getResponse, protyle, app});
|
onGet({data: getResponse, protyle});
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
// 文档标题互转后,需更新大纲
|
// 文档标题互转后,需更新大纲
|
||||||
updatePanelByEditor({
|
updatePanelByEditor({
|
||||||
|
|
|
||||||
|
|
@ -16,14 +16,12 @@ 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 = (options: {
|
export const onGet = (options: {
|
||||||
data: IWebSocketData,
|
data: IWebSocketData,
|
||||||
protyle: IProtyle,
|
protyle: IProtyle,
|
||||||
action?: string[],
|
action?: string[],
|
||||||
scrollAttr?: IScrollAttr
|
scrollAttr?: IScrollAttr
|
||||||
app: App
|
|
||||||
}) => {
|
}) => {
|
||||||
if (!options.action) {
|
if (!options.action) {
|
||||||
options.action = [];
|
options.action = [];
|
||||||
|
|
@ -79,7 +77,7 @@ export const onGet = (options: {
|
||||||
action: options.action,
|
action: options.action,
|
||||||
scrollAttr: options.scrollAttr,
|
scrollAttr: options.scrollAttr,
|
||||||
isSyncing: options.data.data.isSyncing,
|
isSyncing: options.data.data.isSyncing,
|
||||||
}, options.protyle, options.app);
|
}, options.protyle);
|
||||||
removeLoading(options.protyle);
|
removeLoading(options.protyle);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -101,7 +99,7 @@ export const onGet = (options: {
|
||||||
action: options.action,
|
action: options.action,
|
||||||
scrollAttr: options.scrollAttr,
|
scrollAttr: options.scrollAttr,
|
||||||
isSyncing: options.data.data.isSyncing,
|
isSyncing: options.data.data.isSyncing,
|
||||||
}, options.protyle, options.app);
|
}, options.protyle);
|
||||||
setTitle(response.data.ial.title);
|
setTitle(response.data.ial.title);
|
||||||
removeLoading(options.protyle);
|
removeLoading(options.protyle);
|
||||||
});
|
});
|
||||||
|
|
@ -113,7 +111,7 @@ const setHTML = (options: {
|
||||||
isSyncing: boolean,
|
isSyncing: boolean,
|
||||||
expand: boolean,
|
expand: boolean,
|
||||||
scrollAttr?: IScrollAttr
|
scrollAttr?: IScrollAttr
|
||||||
}, protyle: IProtyle, app: App) => {
|
}, protyle: IProtyle) => {
|
||||||
if (protyle.contentElement.classList.contains("fn__none")) {
|
if (protyle.contentElement.classList.contains("fn__none")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -261,7 +259,7 @@ const setHTML = (options: {
|
||||||
mode: 2,
|
mode: 2,
|
||||||
size: window.siyuan.config.editor.dynamicLoadBlocks,
|
size: window.siyuan.config.editor.dynamicLoadBlocks,
|
||||||
}, getResponse => {
|
}, getResponse => {
|
||||||
onGet({data: getResponse, protyle, action: [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID], app});
|
onGet({data: getResponse, protyle, action: [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID]});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
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)) {
|
||||||
|
|
@ -270,7 +268,7 @@ const setHTML = (options: {
|
||||||
if (protyle.options.render.breadcrumb) {
|
if (protyle.options.render.breadcrumb) {
|
||||||
protyle.breadcrumb.render(protyle);
|
protyle.breadcrumb.render(protyle);
|
||||||
}
|
}
|
||||||
app.plugins.forEach(item => {
|
protyle.app.plugins.forEach(item => {
|
||||||
item.eventBus.emit("loaded-protyle", protyle);
|
item.eventBus.emit("loaded-protyle", protyle);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,8 @@ 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, app: App, focus: boolean) => {
|
export const reloadProtyle = (protyle: IProtyle, 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 {
|
||||||
|
|
@ -40,7 +39,6 @@ export const reloadProtyle = (protyle: IProtyle, app: App, focus: boolean) => {
|
||||||
} else {
|
} else {
|
||||||
preventScroll(protyle);
|
preventScroll(protyle);
|
||||||
getDocByScroll({
|
getDocByScroll({
|
||||||
app,
|
|
||||||
protyle,
|
protyle,
|
||||||
focus,
|
focus,
|
||||||
scrollAttr: saveScroll(protyle, true)
|
scrollAttr: saveScroll(protyle, true)
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,16 @@ import {openAttr, openFileAttr} from "../../menus/commonMenuItem";
|
||||||
import {openGlobalSearch} from "../../search/util";
|
import {openGlobalSearch} from "../../search/util";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {isMobile} from "../../util/functions";
|
import {isMobile} from "../../util/functions";
|
||||||
import {App} from "../../index";
|
|
||||||
|
|
||||||
export const commonClick = (app: App, event: MouseEvent & {
|
export const commonClick = (event: MouseEvent & {
|
||||||
target: HTMLElement
|
target: HTMLElement
|
||||||
}, protyle: IProtyle, data?:IObject) => {
|
}, protyle: IProtyle, data?: IObject) => {
|
||||||
const isM = isMobile();
|
const isM = isMobile();
|
||||||
const attrBookmarkElement = hasClosestByClassName(event.target, "protyle-attr--bookmark");
|
const attrBookmarkElement = hasClosestByClassName(event.target, "protyle-attr--bookmark");
|
||||||
if (attrBookmarkElement) {
|
if (attrBookmarkElement) {
|
||||||
if (!isM && (event.ctrlKey || event.metaKey)) {
|
if (!isM && (event.ctrlKey || event.metaKey)) {
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
openGlobalSearch(app, attrBookmarkElement.textContent.trim(), true);
|
openGlobalSearch(protyle.app, attrBookmarkElement.textContent.trim(), true);
|
||||||
/// #endif
|
/// #endif
|
||||||
} else {
|
} else {
|
||||||
if (data) {
|
if (data) {
|
||||||
|
|
@ -31,10 +30,10 @@ export const commonClick = (app: App, event: MouseEvent & {
|
||||||
if (attrNameElement) {
|
if (attrNameElement) {
|
||||||
if (!isM && (event.ctrlKey || event.metaKey)) {
|
if (!isM && (event.ctrlKey || event.metaKey)) {
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
openGlobalSearch(app, attrNameElement.textContent.trim(), true);
|
openGlobalSearch(protyle.app, attrNameElement.textContent.trim(), true);
|
||||||
/// #endif
|
/// #endif
|
||||||
} else {
|
} else {
|
||||||
if (data ) {
|
if (data) {
|
||||||
openFileAttr(data, protyle.block.rootID, "name");
|
openFileAttr(data, protyle.block.rootID, "name");
|
||||||
} else {
|
} else {
|
||||||
openAttr(attrNameElement.parentElement.parentElement, protyle, "name");
|
openAttr(attrNameElement.parentElement.parentElement, protyle, "name");
|
||||||
|
|
@ -48,7 +47,7 @@ export const commonClick = (app: App, event: MouseEvent & {
|
||||||
if (attrAliasElement) {
|
if (attrAliasElement) {
|
||||||
if (!isM && (event.ctrlKey || event.metaKey)) {
|
if (!isM && (event.ctrlKey || event.metaKey)) {
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
openGlobalSearch(app, attrAliasElement.textContent.trim(), true);
|
openGlobalSearch(protyle.app, attrAliasElement.textContent.trim(), true);
|
||||||
/// #endif
|
/// #endif
|
||||||
} else {
|
} else {
|
||||||
if (data) {
|
if (data) {
|
||||||
|
|
@ -65,7 +64,7 @@ export const commonClick = (app: App, event: MouseEvent & {
|
||||||
if (attrMemoElement) {
|
if (attrMemoElement) {
|
||||||
if (!isM && (event.ctrlKey || event.metaKey)) {
|
if (!isM && (event.ctrlKey || event.metaKey)) {
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
openGlobalSearch(app, attrMemoElement.getAttribute("aria-label").trim(), true);
|
openGlobalSearch(protyle.app, attrMemoElement.getAttribute("aria-label").trim(), true);
|
||||||
/// #endif
|
/// #endif
|
||||||
} else {
|
} else {
|
||||||
if (data) {
|
if (data) {
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,8 @@ import {transaction, updateTransaction} from "./transaction";
|
||||||
import {onGet} from "../util/onGet";
|
import {onGet} from "../util/onGet";
|
||||||
import {Constants} from "../../constants";
|
import {Constants} from "../../constants";
|
||||||
import * as dayjs from "dayjs";
|
import * as dayjs from "dayjs";
|
||||||
import {App} from "../../index";
|
|
||||||
|
|
||||||
export const commonHotkey = (app: App, protyle: IProtyle, event: KeyboardEvent) => {
|
export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent) => {
|
||||||
const target = event.target as HTMLElement;
|
const target = event.target as HTMLElement;
|
||||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.copyHPath.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.copyHPath.custom, event)) {
|
||||||
fetchPost("/api/filetree/getHPathByID", {
|
fetchPost("/api/filetree/getHPathByID", {
|
||||||
|
|
@ -36,7 +35,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, app);
|
netImg2LocalAssets(protyle);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -53,20 +52,20 @@ export const commonHotkey = (app: App, protyle: IProtyle, event: KeyboardEvent)
|
||||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.backlinks.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.backlinks.custom, event)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
openBacklink(app, protyle);
|
openBacklink(protyle);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.graphView.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.graphView.custom, event)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
openGraph(app, protyle);
|
openGraph(protyle);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.outline.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.outline.custom, event)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
const offset = getSelectionOffset(target);
|
const offset = getSelectionOffset(target);
|
||||||
openOutline(app, protyle);
|
openOutline(protyle);
|
||||||
// switchWnd 后,range会被清空,需要重新设置
|
// switchWnd 后,range会被清空,需要重新设置
|
||||||
focusByOffset(target, offset.start, offset.end);
|
focusByOffset(target, offset.start, offset.end);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -74,7 +73,7 @@ export const commonHotkey = (app: App, protyle: IProtyle, event: KeyboardEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
let matchCommand = false;
|
let matchCommand = false;
|
||||||
app.plugins.find(item => {
|
protyle.app.plugins.find(item => {
|
||||||
item.commands.find(command => {
|
item.commands.find(command => {
|
||||||
if (command.editorCallback && matchHotKey(command.customHotkey, event)) {
|
if (command.editorCallback && matchHotKey(command.customHotkey, event)) {
|
||||||
matchCommand = true;
|
matchCommand = true;
|
||||||
|
|
@ -228,7 +227,7 @@ export const duplicateBlock = (nodeElements: Element[], protyle: IProtyle) => {
|
||||||
scrollCenter(protyle);
|
scrollCenter(protyle);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const goHome = (protyle: IProtyle, app: App) => {
|
export const goHome = (protyle: IProtyle) => {
|
||||||
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 +240,12 @@ export const goHome = (protyle: IProtyle, app: App) => {
|
||||||
mode: 0,
|
mode: 0,
|
||||||
size: window.siyuan.config.editor.dynamicLoadBlocks,
|
size: window.siyuan.config.editor.dynamicLoadBlocks,
|
||||||
}, getResponse => {
|
}, getResponse => {
|
||||||
onGet({data: getResponse, protyle, action: [Constants.CB_GET_FOCUS], app});
|
onGet({data: getResponse, protyle, action: [Constants.CB_GET_FOCUS]});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const goEnd = (protyle: IProtyle, app: App) => {
|
export const goEnd = (protyle: IProtyle) => {
|
||||||
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 +253,7 @@ export const goEnd = (protyle: IProtyle, app: App) => {
|
||||||
mode: 4,
|
mode: 4,
|
||||||
size: window.siyuan.config.editor.dynamicLoadBlocks,
|
size: window.siyuan.config.editor.dynamicLoadBlocks,
|
||||||
}, getResponse => {
|
}, getResponse => {
|
||||||
onGet({data: getResponse, protyle, action: [Constants.CB_GET_FOCUS], app});
|
onGet({data: getResponse, protyle, action: [Constants.CB_GET_FOCUS]});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
protyle.contentElement.scrollTop = protyle.contentElement.scrollHeight;
|
protyle.contentElement.scrollTop = protyle.contentElement.scrollHeight;
|
||||||
|
|
|
||||||
|
|
@ -66,17 +66,14 @@ import {getBacklinkHeadingMore, loadBreadcrumb} from "./renderBacklink";
|
||||||
import {removeSearchMark} from "../toolbar/util";
|
import {removeSearchMark} from "../toolbar/util";
|
||||||
import {activeBlur, hideKeyboardToolbar} from "../../mobile/util/keyboardToolbar";
|
import {activeBlur, hideKeyboardToolbar} from "../../mobile/util/keyboardToolbar";
|
||||||
import {commonClick} from "./commonClick";
|
import {commonClick} from "./commonClick";
|
||||||
import {App} from "../../index";
|
|
||||||
|
|
||||||
export class WYSIWYG {
|
export class WYSIWYG {
|
||||||
public lastHTMLs: { [key: string]: string } = {};
|
public lastHTMLs: { [key: string]: string } = {};
|
||||||
|
|
||||||
public element: HTMLDivElement;
|
public element: HTMLDivElement;
|
||||||
public preventKeyup: boolean;
|
public preventKeyup: boolean;
|
||||||
private app: App;
|
|
||||||
|
|
||||||
constructor(app: App, protyle: IProtyle) {
|
constructor(protyle: IProtyle) {
|
||||||
this.app = app;
|
|
||||||
this.element = document.createElement("div");
|
this.element = document.createElement("div");
|
||||||
this.element.className = "protyle-wysiwyg";
|
this.element.className = "protyle-wysiwyg";
|
||||||
this.element.setAttribute("spellcheck", "false");
|
this.element.setAttribute("spellcheck", "false");
|
||||||
|
|
@ -94,8 +91,8 @@ export class WYSIWYG {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.bindEvent(protyle);
|
this.bindEvent(protyle);
|
||||||
keydown(app, protyle, this.element);
|
keydown(protyle, this.element);
|
||||||
dropEvent(app, protyle, this.element);
|
dropEvent(protyle, this.element);
|
||||||
}
|
}
|
||||||
|
|
||||||
public renderCustom(ial: IObject) {
|
public renderCustom(ial: IObject) {
|
||||||
|
|
@ -1025,7 +1022,7 @@ export class WYSIWYG {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const nextElement = getNextBlock(selectElements[selectElements.length - 1]);
|
const nextElement = getNextBlock(selectElements[selectElements.length - 1]);
|
||||||
removeBlock(this.app, protyle, nodeElement, range);
|
removeBlock(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);
|
||||||
|
|
@ -1212,7 +1209,7 @@ export class WYSIWYG {
|
||||||
removeSearchMark(target);
|
removeSearchMark(target);
|
||||||
}
|
}
|
||||||
if (types.includes("block-ref") && !protyle.disabled) {
|
if (types.includes("block-ref") && !protyle.disabled) {
|
||||||
refMenu(this.app, protyle, target);
|
refMenu(protyle, target);
|
||||||
// 阻止 popover
|
// 阻止 popover
|
||||||
target.setAttribute("prevent-popover", "true");
|
target.setAttribute("prevent-popover", "true");
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
@ -1223,13 +1220,13 @@ export class WYSIWYG {
|
||||||
protyle.toolbar.showFileAnnotationRef(protyle, target);
|
protyle.toolbar.showFileAnnotationRef(protyle, target);
|
||||||
return false;
|
return false;
|
||||||
} else if (types.includes("tag") && !protyle.disabled) {
|
} else if (types.includes("tag") && !protyle.disabled) {
|
||||||
tagMenu(this.app, protyle, target);
|
tagMenu(protyle, target);
|
||||||
return false;
|
return false;
|
||||||
} else if (types.includes("inline-memo")) {
|
} else if (types.includes("inline-memo")) {
|
||||||
protyle.toolbar.showRender(protyle, target);
|
protyle.toolbar.showRender(protyle, target);
|
||||||
return false;
|
return false;
|
||||||
} else if (types.includes("a") && !protyle.disabled) {
|
} else if (types.includes("a") && !protyle.disabled) {
|
||||||
linkMenu(this.app, protyle, target);
|
linkMenu(protyle, target);
|
||||||
if (window.siyuan.config.editor.floatWindowMode === 0 &&
|
if (window.siyuan.config.editor.floatWindowMode === 0 &&
|
||||||
target.getAttribute("data-href")?.startsWith("siyuan://blocks")) {
|
target.getAttribute("data-href")?.startsWith("siyuan://blocks")) {
|
||||||
// 阻止 popover
|
// 阻止 popover
|
||||||
|
|
@ -1242,7 +1239,7 @@ export class WYSIWYG {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!protyle.disabled && target.tagName === "IMG" && hasClosestByClassName(target, "img")) {
|
if (!protyle.disabled && target.tagName === "IMG" && hasClosestByClassName(target, "img")) {
|
||||||
imgMenu(this.app, protyle, protyle.toolbar.range, target.parentElement.parentElement, {
|
imgMenu(protyle, protyle.toolbar.range, target.parentElement.parentElement, {
|
||||||
clientX: x + 4,
|
clientX: x + 4,
|
||||||
clientY: y
|
clientY: y
|
||||||
});
|
});
|
||||||
|
|
@ -1303,7 +1300,6 @@ export class WYSIWYG {
|
||||||
data: getResponse,
|
data: getResponse,
|
||||||
protyle,
|
protyle,
|
||||||
action: [Constants.CB_GET_BEFORE, Constants.CB_GET_UNCHANGEID],
|
action: [Constants.CB_GET_BEFORE, Constants.CB_GET_UNCHANGEID],
|
||||||
app: this.app
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
preventGetTopHTML = true;
|
preventGetTopHTML = true;
|
||||||
|
|
@ -1498,7 +1494,7 @@ export class WYSIWYG {
|
||||||
|
|
||||||
let shiftStartElement: HTMLElement;
|
let shiftStartElement: HTMLElement;
|
||||||
this.element.addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => {
|
this.element.addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => {
|
||||||
this.app.plugins.forEach(item => {
|
protyle.app.plugins.forEach(item => {
|
||||||
item.eventBus.emit("click-editorcontent", {
|
item.eventBus.emit("click-editorcontent", {
|
||||||
protyle,
|
protyle,
|
||||||
event
|
event
|
||||||
|
|
@ -1514,7 +1510,7 @@ export class WYSIWYG {
|
||||||
if (ctrlIsPressed) {
|
if (ctrlIsPressed) {
|
||||||
fetchPost("/api/block/checkBlockFold", {id: breadcrumbId}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id: breadcrumbId}, (foldResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
app: this.app,
|
app: protyle.app,
|
||||||
id: breadcrumbId,
|
id: breadcrumbId,
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
zoomIn: foldResponse.data
|
zoomIn: foldResponse.data
|
||||||
|
|
@ -1572,7 +1568,7 @@ export class WYSIWYG {
|
||||||
|
|
||||||
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
|
||||||
/// #if MOBILE
|
/// #if MOBILE
|
||||||
openMobileFileById(this.app, refBlockId, foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
|
openMobileFileById(protyle.app, refBlockId, foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]);
|
||||||
activeBlur();
|
activeBlur();
|
||||||
hideKeyboardToolbar();
|
hideKeyboardToolbar();
|
||||||
/// #else
|
/// #else
|
||||||
|
|
@ -1582,7 +1578,7 @@ export class WYSIWYG {
|
||||||
}
|
}
|
||||||
if (event.shiftKey) {
|
if (event.shiftKey) {
|
||||||
openFileById({
|
openFileById({
|
||||||
app: this.app,
|
app: protyle.app,
|
||||||
id: refBlockId,
|
id: refBlockId,
|
||||||
position: "bottom",
|
position: "bottom",
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
|
|
@ -1590,7 +1586,7 @@ export class WYSIWYG {
|
||||||
});
|
});
|
||||||
} else if (event.altKey) {
|
} else if (event.altKey) {
|
||||||
openFileById({
|
openFileById({
|
||||||
app: this.app,
|
app: protyle.app,
|
||||||
id: refBlockId,
|
id: refBlockId,
|
||||||
position: "right",
|
position: "right",
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
|
|
@ -1598,7 +1594,7 @@ export class WYSIWYG {
|
||||||
});
|
});
|
||||||
} else if (ctrlIsPressed) {
|
} else if (ctrlIsPressed) {
|
||||||
openFileById({
|
openFileById({
|
||||||
app: this.app,
|
app: protyle.app,
|
||||||
id: refBlockId,
|
id: refBlockId,
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
|
||||||
keepCursor: true,
|
keepCursor: true,
|
||||||
|
|
@ -1606,7 +1602,7 @@ export class WYSIWYG {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
openFileById({
|
openFileById({
|
||||||
app: this.app,
|
app: protyle.app,
|
||||||
id: refBlockId,
|
id: refBlockId,
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
zoomIn: foldResponse.data
|
zoomIn: foldResponse.data
|
||||||
|
|
@ -1645,7 +1641,7 @@ export class WYSIWYG {
|
||||||
} else if (event.shiftKey) {
|
} else if (event.shiftKey) {
|
||||||
openBy(linkAddress, "app");
|
openBy(linkAddress, "app");
|
||||||
} else {
|
} else {
|
||||||
openAsset(this.app, linkAddress, fileIds[2], "right");
|
openAsset(protyle.app, linkAddress, fileIds[2], "right");
|
||||||
}
|
}
|
||||||
/// #endif
|
/// #endif
|
||||||
return;
|
return;
|
||||||
|
|
@ -1669,7 +1665,7 @@ export class WYSIWYG {
|
||||||
} else if (event.shiftKey) {
|
} else if (event.shiftKey) {
|
||||||
openBy(linkAddress, "app");
|
openBy(linkAddress, "app");
|
||||||
} else {
|
} else {
|
||||||
openAsset(this.app, linkPathname, parseInt(getSearch("page", linkAddress)), "right");
|
openAsset(protyle.app, linkPathname, parseInt(getSearch("page", linkAddress)), "right");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
|
|
@ -1698,11 +1694,11 @@ export class WYSIWYG {
|
||||||
const tagElement = hasClosestByAttribute(event.target, "data-type", "tag");
|
const tagElement = hasClosestByAttribute(event.target, "data-type", "tag");
|
||||||
if (tagElement && !event.altKey) {
|
if (tagElement && !event.altKey) {
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
openGlobalSearch(this.app, `#${tagElement.textContent}#`, !ctrlIsPressed);
|
openGlobalSearch(protyle.app, `#${tagElement.textContent}#`, !ctrlIsPressed);
|
||||||
hideElements(["dialog"]);
|
hideElements(["dialog"]);
|
||||||
/// #else
|
/// #else
|
||||||
const searchOption = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
|
const searchOption = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
|
||||||
popSearch(this.app, {
|
popSearch(protyle.app, {
|
||||||
removed: searchOption.removed,
|
removed: searchOption.removed,
|
||||||
sort: searchOption.sort,
|
sort: searchOption.sort,
|
||||||
group: searchOption.group,
|
group: searchOption.group,
|
||||||
|
|
@ -1723,13 +1719,13 @@ export class WYSIWYG {
|
||||||
if (embedItemElement) {
|
if (embedItemElement) {
|
||||||
const embedId = embedItemElement.getAttribute("data-id");
|
const embedId = embedItemElement.getAttribute("data-id");
|
||||||
/// #if MOBILE
|
/// #if MOBILE
|
||||||
openMobileFileById(this.app, embedId, [Constants.CB_GET_ALL]);
|
openMobileFileById(protyle.app, embedId, [Constants.CB_GET_ALL]);
|
||||||
activeBlur();
|
activeBlur();
|
||||||
hideKeyboardToolbar();
|
hideKeyboardToolbar();
|
||||||
/// #else
|
/// #else
|
||||||
if (event.shiftKey) {
|
if (event.shiftKey) {
|
||||||
openFileById({
|
openFileById({
|
||||||
app: this.app,
|
app: protyle.app,
|
||||||
id: embedId,
|
id: embedId,
|
||||||
position: "bottom",
|
position: "bottom",
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL],
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL],
|
||||||
|
|
@ -1737,7 +1733,7 @@ export class WYSIWYG {
|
||||||
});
|
});
|
||||||
} else if (event.altKey) {
|
} else if (event.altKey) {
|
||||||
openFileById({
|
openFileById({
|
||||||
app: this.app,
|
app: protyle.app,
|
||||||
id: embedId,
|
id: embedId,
|
||||||
position: "right",
|
position: "right",
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL],
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL],
|
||||||
|
|
@ -1745,7 +1741,7 @@ export class WYSIWYG {
|
||||||
});
|
});
|
||||||
} else if (ctrlIsPressed) {
|
} else if (ctrlIsPressed) {
|
||||||
openFileById({
|
openFileById({
|
||||||
app: this.app,
|
app: protyle.app,
|
||||||
id: embedId,
|
id: embedId,
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL],
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL],
|
||||||
keepCursor: true,
|
keepCursor: true,
|
||||||
|
|
@ -1753,7 +1749,7 @@ export class WYSIWYG {
|
||||||
});
|
});
|
||||||
} else if (!protyle.disabled) {
|
} else if (!protyle.disabled) {
|
||||||
window.siyuan.blockPanels.push(new BlockPanel({
|
window.siyuan.blockPanels.push(new BlockPanel({
|
||||||
app: this.app,
|
app: protyle.app,
|
||||||
targetElement: embedItemElement,
|
targetElement: embedItemElement,
|
||||||
isBacklink: false,
|
isBacklink: false,
|
||||||
nodeIds: [embedId],
|
nodeIds: [embedId],
|
||||||
|
|
@ -1764,7 +1760,7 @@ export class WYSIWYG {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commonClick(this.app, event, protyle)) {
|
if (commonClick(event, protyle)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1829,7 +1825,7 @@ export class WYSIWYG {
|
||||||
if (actionElement) {
|
if (actionElement) {
|
||||||
const type = actionElement.parentElement.parentElement.getAttribute("data-type");
|
const type = actionElement.parentElement.parentElement.getAttribute("data-type");
|
||||||
if (type === "img" && !protyle.disabled) {
|
if (type === "img" && !protyle.disabled) {
|
||||||
imgMenu(this.app, protyle, range, actionElement.parentElement.parentElement, {
|
imgMenu(protyle, range, actionElement.parentElement.parentElement, {
|
||||||
clientX: event.clientX + 4,
|
clientX: event.clientX + 4,
|
||||||
clientY: event.clientY
|
clientY: event.clientY
|
||||||
});
|
});
|
||||||
|
|
@ -1865,7 +1861,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, id: actionElement.parentElement.getAttribute("data-node-id"), app: this.app});
|
zoomOut({protyle, id: actionElement.parentElement.getAttribute("data-node-id")});
|
||||||
} 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;
|
||||||
|
|
|
||||||
|
|
@ -71,9 +71,8 @@ import {escapeHtml} from "../../util/escape";
|
||||||
import {insertHTML} from "../util/insertHTML";
|
import {insertHTML} from "../util/insertHTML";
|
||||||
import {quickMakeCard} from "../../card/makeCard";
|
import {quickMakeCard} from "../../card/makeCard";
|
||||||
import {removeSearchMark} from "../toolbar/util";
|
import {removeSearchMark} from "../toolbar/util";
|
||||||
import {App} from "../../index";
|
|
||||||
|
|
||||||
export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement) => {
|
export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
editorElement.addEventListener("keydown", (event: KeyboardEvent & { target: HTMLElement }) => {
|
editorElement.addEventListener("keydown", (event: KeyboardEvent & { target: HTMLElement }) => {
|
||||||
if (event.target.localName === "protyle-html") {
|
if (event.target.localName === "protyle-html") {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
@ -431,7 +430,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, id:topNodeElement.getAttribute("data-node-id"), app});
|
zoomOut({protyle, id: topNodeElement.getAttribute("data-node-id")});
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
return;
|
return;
|
||||||
|
|
@ -442,13 +441,13 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
|
||||||
const ids = protyle.path.split("/");
|
const ids = protyle.path.split("/");
|
||||||
if (ids.length > 2) {
|
if (ids.length > 2) {
|
||||||
openFileById({
|
openFileById({
|
||||||
app,
|
app: protyle.app,
|
||||||
id: ids[ids.length - 2],
|
id: ids[ids.length - 2],
|
||||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
|
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
zoomOut({protyle, id:protyle.block.parent2ID, focusId:nodeElement.getAttribute("data-node-id"), app});
|
zoomOut({protyle, id: protyle.block.parent2ID, focusId: nodeElement.getAttribute("data-node-id")});
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
@ -477,14 +476,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, app);
|
goHome(protyle);
|
||||||
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, app);
|
goEnd(protyle);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
|
|
@ -532,7 +531,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
|
||||||
removeSearchMark(inlineElement);
|
removeSearchMark(inlineElement);
|
||||||
}
|
}
|
||||||
if (types.includes("block-ref")) {
|
if (types.includes("block-ref")) {
|
||||||
refMenu(app, protyle, inlineElement);
|
refMenu(protyle, inlineElement);
|
||||||
return;
|
return;
|
||||||
} else if (types.includes("inline-memo")) {
|
} else if (types.includes("inline-memo")) {
|
||||||
protyle.toolbar.showRender(protyle, inlineElement);
|
protyle.toolbar.showRender(protyle, inlineElement);
|
||||||
|
|
@ -541,10 +540,10 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
|
||||||
protyle.toolbar.showFileAnnotationRef(protyle, inlineElement);
|
protyle.toolbar.showFileAnnotationRef(protyle, inlineElement);
|
||||||
return;
|
return;
|
||||||
} else if (types.includes("a")) {
|
} else if (types.includes("a")) {
|
||||||
linkMenu(app, protyle, inlineElement);
|
linkMenu(protyle, inlineElement);
|
||||||
return;
|
return;
|
||||||
} else if (types.includes("tag")) {
|
} else if (types.includes("tag")) {
|
||||||
tagMenu(app, protyle, inlineElement);
|
tagMenu(protyle, inlineElement);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -694,7 +693,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(app, protyle, nodeElement, range);
|
removeBlock(protyle, nodeElement, range);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
|
|
@ -736,7 +735,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(app, protyle, nodeElement, range);
|
removeBlock(protyle, nodeElement, range);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
|
|
@ -746,7 +745,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(app, protyle, nodeElement, range);
|
removeBlock(protyle, nodeElement, range);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
|
|
@ -768,7 +767,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(app, protyle, nodeElement, range);
|
removeBlock(protyle, nodeElement, range);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
|
|
@ -783,7 +782,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(app, protyle, nextBlockElement, nextRange);
|
removeBlock(protyle, nextBlockElement, nextRange);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
@ -801,7 +800,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(app, protyle, nodeElement, range);
|
removeBlock(protyle, nodeElement, range);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
|
|
@ -810,7 +809,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(app, protyle, nodeElement, range);
|
removeBlock(protyle, nodeElement, range);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
|
|
@ -927,14 +926,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(app, protyle);
|
protyle.undo.undo(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(app, protyle);
|
protyle.undo.redo(protyle);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
return;
|
return;
|
||||||
|
|
@ -954,7 +953,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
if (commonHotkey(app, protyle, event)) {
|
if (commonHotkey(protyle, event)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/// #endif
|
/// #endif
|
||||||
|
|
@ -1446,7 +1445,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(app, protyle, nodeElement, range);
|
removeBlock(protyle, nodeElement, range);
|
||||||
if (nextElement) {
|
if (nextElement) {
|
||||||
focusBlock(nextElement);
|
focusBlock(nextElement);
|
||||||
}
|
}
|
||||||
|
|
@ -1597,7 +1596,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
|
||||||
if (matchHotKey(window.siyuan.config.keymap.editor.general.openBy.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.editor.general.openBy.custom, event)) {
|
||||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
app,
|
app: protyle.app,
|
||||||
id,
|
id,
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
zoomIn: foldResponse.data
|
zoomIn: foldResponse.data
|
||||||
|
|
@ -1610,7 +1609,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
|
||||||
// 打开块引和编辑器中引用、反链、书签中点击事件需保持一致,都加载上下文
|
// 打开块引和编辑器中引用、反链、书签中点击事件需保持一致,都加载上下文
|
||||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
app,
|
app: protyle.app,
|
||||||
id,
|
id,
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
|
||||||
keepCursor: true,
|
keepCursor: true,
|
||||||
|
|
@ -1623,7 +1622,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
|
||||||
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.insertRight.custom, event)) {
|
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.insertRight.custom, event)) {
|
||||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
app,
|
app: protyle.app,
|
||||||
id,
|
id,
|
||||||
position: "right",
|
position: "right",
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
|
|
@ -1636,7 +1635,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
|
||||||
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.insertBottom.custom, event)) {
|
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.insertBottom.custom, event)) {
|
||||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
||||||
openFileById({
|
openFileById({
|
||||||
app,
|
app: protyle.app,
|
||||||
id,
|
id,
|
||||||
position: "bottom",
|
position: "bottom",
|
||||||
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||||
|
|
@ -1649,7 +1648,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
|
||||||
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.refPopover.custom, event)) {
|
} else if (matchHotKey(window.siyuan.config.keymap.editor.general.refPopover.custom, event)) {
|
||||||
// open popover
|
// open popover
|
||||||
window.siyuan.blockPanels.push(new BlockPanel({
|
window.siyuan.blockPanels.push(new BlockPanel({
|
||||||
app,
|
app: protyle.app,
|
||||||
isBacklink: false,
|
isBacklink: false,
|
||||||
targetElement: refElement,
|
targetElement: refElement,
|
||||||
nodeIds: [id],
|
nodeIds: [id],
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ 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")) {
|
||||||
|
|
@ -178,7 +177,7 @@ const removeLi = (protyle: IProtyle, blockElement: Element, range: Range) => {
|
||||||
focusByWbr(previousLastElement.parentElement, range);
|
focusByWbr(previousLastElement.parentElement, range);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const removeBlock = (app: App, protyle: IProtyle, blockElement: Element, range: Range) => {
|
export const removeBlock = (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"));
|
||||||
|
|
@ -242,7 +241,7 @@ export const removeBlock = (app: App, protyle: IProtyle, blockElement: Element,
|
||||||
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({app, protyle, id:protyle.block.parent2ID, focusId:protyle.block.parent2ID});
|
zoomOut({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)) {
|
||||||
|
|
@ -295,7 +294,7 @@ export const removeBlock = (app: App, protyle: IProtyle, blockElement: Element,
|
||||||
// 空代码块直接删除
|
// 空代码块直接删除
|
||||||
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(app, protyle, blockElement, range);
|
removeBlock(protyle, blockElement, range);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 设置 bq 和代码块光标
|
// 设置 bq 和代码块光标
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ 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) => {
|
||||||
// 移动到其他文档中,该块需移除
|
// 移动到其他文档中,该块需移除
|
||||||
|
|
@ -49,7 +48,7 @@ const removeTopElement = (updateElement: Element, protyle: IProtyle) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// 用于执行操作,外加处理当前编辑器中引用块、嵌入块的更新
|
// 用于执行操作,外加处理当前编辑器中引用块、嵌入块的更新
|
||||||
const promiseTransaction = (app: App) => {
|
const promiseTransaction = () => {
|
||||||
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;
|
||||||
|
|
@ -65,9 +64,9 @@ const promiseTransaction = (app: App) => {
|
||||||
}]
|
}]
|
||||||
}, (response) => {
|
}, (response) => {
|
||||||
if (window.siyuan.transactions.length === 0) {
|
if (window.siyuan.transactions.length === 0) {
|
||||||
promiseTransactions(app);
|
promiseTransactions();
|
||||||
} else {
|
} else {
|
||||||
promiseTransaction(app);
|
promiseTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
countBlockWord([], protyle.block.rootID, true);
|
countBlockWord([], protyle.block.rootID, true);
|
||||||
|
|
@ -140,7 +139,6 @@ const promiseTransaction = (app: App) => {
|
||||||
data: getResponse,
|
data: getResponse,
|
||||||
protyle,
|
protyle,
|
||||||
action: [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID],
|
action: [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID],
|
||||||
app
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -312,18 +310,18 @@ const updateEmbed = (protyle: IProtyle, operation: IOperation) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const promiseTransactions = (app: App) => {
|
export const promiseTransactions = () => {
|
||||||
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(app);
|
promiseTransaction();
|
||||||
}, Constants.TIMEOUT_INPUT * 2);
|
}, Constants.TIMEOUT_INPUT * 2);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 用于推送和撤销
|
// 用于推送和撤销
|
||||||
export const onTransaction = (app: App, protyle: IProtyle, operation: IOperation, focus: boolean) => {
|
export const onTransaction = (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")) {
|
||||||
|
|
@ -655,7 +653,7 @@ export const onTransaction = (app: App, protyle: IProtyle, operation: IOperation
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (operation.action === "append") {
|
if (operation.action === "append") {
|
||||||
reloadProtyle(protyle, app, false);
|
reloadProtyle(protyle, false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -915,7 +915,6 @@ const getArticle = (options: {
|
||||||
data: getResponse,
|
data: getResponse,
|
||||||
protyle: options.edit.protyle,
|
protyle: options.edit.protyle,
|
||||||
action: foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_HL, Constants.CB_GET_HTML],
|
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) {
|
||||||
|
|
@ -975,7 +974,7 @@ const replace = (element: Element, config: ISearchOption, edit: Protyle, app: Ap
|
||||||
}
|
}
|
||||||
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, app, false);
|
reloadProtyle(item.editor.protyle, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (currentList.nextElementSibling) {
|
if (currentList.nextElementSibling) {
|
||||||
|
|
|
||||||
2
app/src/types/index.d.ts
vendored
2
app/src/types/index.d.ts
vendored
|
|
@ -49,7 +49,7 @@ interface Window {
|
||||||
|
|
||||||
Protyle: import("../protyle/method").default
|
Protyle: import("../protyle/method").default
|
||||||
|
|
||||||
goBack(app: import("../index").App): void
|
goBack(): void
|
||||||
|
|
||||||
showKeyboardToolbar(height: number): void
|
showKeyboardToolbar(height: number): void
|
||||||
|
|
||||||
|
|
|
||||||
1
app/src/types/protyle.d.ts
vendored
1
app/src/types/protyle.d.ts
vendored
|
|
@ -407,6 +407,7 @@ interface IOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IProtyle {
|
interface IProtyle {
|
||||||
|
app: import("../index").App,
|
||||||
transactionTime: number,
|
transactionTime: number,
|
||||||
id: string,
|
id: string,
|
||||||
block: {
|
block: {
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,6 @@ const focusStack = async (app: App, stack: IBackStack) => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
zoomOut({
|
zoomOut({
|
||||||
app,
|
|
||||||
protyle: stack.protyle,
|
protyle: stack.protyle,
|
||||||
id: stack.zoomId || stack.protyle.block.rootID,
|
id: stack.zoomId || stack.protyle.block.rootID,
|
||||||
isPushBack: false,
|
isPushBack: false,
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ export const isMobile = () => {
|
||||||
// "windows" | "linux" | "darwin" | "docker" | "android" | "ios"
|
// "windows" | "linux" | "darwin" | "docker" | "android" | "ios"
|
||||||
export const getBackend = () => {
|
export const getBackend = () => {
|
||||||
if (["docker", "ios", "android"].includes(window.siyuan.config.system.container)) {
|
if (["docker", "ios", "android"].includes(window.siyuan.config.system.container)) {
|
||||||
return window.siyuan.config.system.container
|
return window.siyuan.config.system.container;
|
||||||
} else {
|
} else {
|
||||||
return window.siyuan.config.system.os
|
return window.siyuan.config.system.os;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -145,7 +145,7 @@ class App {
|
||||||
});
|
});
|
||||||
setNoteBook();
|
setNoteBook();
|
||||||
initBlockPopover(this);
|
initBlockPopover(this);
|
||||||
promiseTransactions(this);
|
promiseTransactions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue