This commit is contained in:
Vanessa 2023-06-01 20:50:49 +08:00
parent fd0893d8d8
commit 6806392b41
57 changed files with 271 additions and 360 deletions

View file

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

View file

@ -25,7 +25,6 @@ import {hideElements} from "../ui/hideElements";
import {confirmDialog} from "../../dialog/confirmDialog";
import {reloadProtyle} from "../util/reload";
import {deleteFile} from "../../editor/deleteFile";
import {App} from "../../index";
export class Breadcrumb {
public element: HTMLElement;
@ -33,7 +32,7 @@ export class Breadcrumb {
private id: string;
private messageId: string;
constructor(app: App, protyle: IProtyle) {
constructor(protyle: IProtyle) {
const element = document.createElement("div");
element.className = "protyle-breadcrumb";
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 !MOBILE
openFileById({
app,
app:protyle.app,
id,
action: id === protyle.block.rootID ? [Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL]
});
/// #endif
} else {
zoomOut({protyle, id, app});
zoomOut({protyle, id});
}
event.preventDefault();
break;
} else if (target.getAttribute("data-menu") === "true") {
this.showMenu(app, protyle, {
this.showMenu(protyle, {
x: event.clientX,
y: event.clientY
});
event.preventDefault();
break;
} 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();
break;
} else if (target.getAttribute("data-type") === "context") {
event.preventDefault();
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");
} else {
fetchPost("/api/filetree/getDoc", {
@ -83,7 +82,7 @@ export class Breadcrumb {
mode: 3,
size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => {
onGet({data: getResponse, protyle, action: [Constants.CB_GET_HL], app});
onGet({data: getResponse, protyle, action: [Constants.CB_GET_HL]});
this.toggleExit(true);
});
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;
const cursorNodeElement = hasClosestBlock(getEditorRange(protyle.element).startContainer);
if (cursorNodeElement) {
@ -260,7 +259,7 @@ export class Breadcrumb {
icon: "iconTransform",
accelerator: window.siyuan.config.keymap.editor.general.netImg2LocalAsset.custom,
click() {
netImg2LocalAssets(protyle, app);
netImg2LocalAssets(protyle);
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({
@ -303,7 +302,7 @@ export class Breadcrumb {
accelerator: window.siyuan.config.keymap.editor.general.refresh.custom,
label: window.siyuan.languages.refresh,
click: () => {
reloadProtyle(protyle, app, !isMobile());
reloadProtyle(protyle, !isMobile());
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({

View file

@ -38,16 +38,13 @@ import {isMobile} from "../../util/functions";
import {AIActions} from "../../ai/actions";
import {activeBlur} from "../../mobile/util/keyboardToolbar";
import {hideTooltip} from "../../dialog/tooltip";
import {App} from "../../index";
import {appearanceMenu} from "../toolbar/Font";
import {setPosition} from "../../util/setPosition";
export class Gutter {
public element: HTMLElement;
private app: App;
constructor(app: App, protyle: IProtyle) {
this.app = app;
constructor(protyle: IProtyle) {
this.element = document.createElement("div");
this.element.className = "protyle-gutters";
if (/Mac/.test(navigator.platform) || navigator.platform === "iPhone") {
@ -164,7 +161,7 @@ export class Gutter {
return;
}
if (event.ctrlKey || event.metaKey) {
zoomOut({protyle, id, app});
zoomOut({protyle, id});
} else if (event.altKey) {
let foldElement: Element;
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());
protyle.breadcrumb?.hide();
removeBlock(this.app, protyle, selectsElement[0], getEditorRange(selectsElement[0]));
removeBlock(protyle, selectsElement[0], getEditorRange(selectsElement[0]));
} else {
focusByRange(getEditorRange(selectsElement[0]));
document.execCommand("cut");
@ -661,7 +658,7 @@ export class Gutter {
icon: "iconMove",
click: () => {
movePathTo((toPath) => {
hintMoveBlock(toPath[0], selectsElement, protyle, this.app);
hintMoveBlock(toPath[0], selectsElement, protyle);
});
}
}).element);
@ -671,7 +668,7 @@ export class Gutter {
accelerator: "⌫",
click: () => {
protyle.breadcrumb?.hide();
removeBlock(this.app, protyle, selectsElement[0], getEditorRange(selectsElement[0]));
removeBlock(protyle, selectsElement[0], getEditorRange(selectsElement[0]));
}
}).element);
@ -722,12 +719,12 @@ export class Gutter {
}
ids.push(item.getAttribute("data-node-id"));
});
makeCard(this.app, ids);
makeCard(protyle.app, ids);
}
}).element);
}
const pluginSubMenu = new subMenu();
this.app?.plugins?.forEach((plugin) => {
protyle.app?.plugins?.forEach((plugin) => {
plugin.eventBus.emit("click-blockicon", {
protyle,
menu: pluginSubMenu,
@ -1078,7 +1075,7 @@ export class Gutter {
click: () => {
if (isNotEditBlock(nodeElement)) {
writeText(protyle.lute.BlockDOM2StdMd(removeEmbed(nodeElement)).trimEnd());
removeBlock(this.app, protyle, nodeElement, getEditorRange(nodeElement));
removeBlock(protyle, nodeElement, getEditorRange(nodeElement));
protyle.breadcrumb?.hide();
} else {
focusByRange(getEditorRange(nodeElement));
@ -1092,7 +1089,7 @@ export class Gutter {
icon: "iconMove",
click: () => {
movePathTo((toPath) => {
hintMoveBlock(toPath[0], [nodeElement], protyle, this.app);
hintMoveBlock(toPath[0], [nodeElement], protyle);
});
}
}).element);
@ -1102,7 +1099,7 @@ export class Gutter {
accelerator: "⌫",
click: () => {
protyle.breadcrumb?.hide();
removeBlock(this.app, protyle, nodeElement, getEditorRange(nodeElement));
removeBlock(protyle, nodeElement, getEditorRange(nodeElement));
}
}).element);
}
@ -1241,7 +1238,7 @@ export class Gutter {
type: "submenu",
icon: type === "NodeVideo" ? "iconVideo" : "iconRecord",
label: window.siyuan.languages.assets,
submenu: videoMenu(this.app, protyle, nodeElement, type)
submenu: videoMenu(protyle, nodeElement, type)
}).element);
} else if (type === "NodeIFrame" && !protyle.disabled) {
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
@ -1250,7 +1247,7 @@ export class Gutter {
type: "submenu",
icon: "iconLanguage",
label: window.siyuan.languages.assets,
submenu: iframeMenu(this.app, protyle, nodeElement)
submenu: iframeMenu(protyle, nodeElement)
}).element);
} else if (type === "NodeHTMLBlock" && !protyle.disabled) {
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")}`,
label: window.siyuan.languages.enter,
click:()=> {
zoomOut({protyle, id, app: this.app});
zoomOut({protyle, id});
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({
@ -1413,17 +1410,17 @@ export class Gutter {
const ids = protyle.path.split("/");
if (ids.length > 2) {
/// #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
openFileById({
app: this.app,
app: protyle.app,
id: ids[ids.length - 2],
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
});
/// #endif
}
} else {
zoomOut({protyle, id:protyle.block.parent2ID, focusId:id, app: this.app});
zoomOut({protyle, id:protyle.block.parent2ID, focusId:id});
}
}
}).element);
@ -1536,14 +1533,14 @@ export class Gutter {
label: window.siyuan.languages.addToDeck,
icon: "iconRiffCard",
click() {
makeCard(this.app, [nodeElement.getAttribute("data-node-id")]);
makeCard(protyle.app, [nodeElement.getAttribute("data-node-id")]);
}
}).element);
}
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
}
const pluginSubMenu = new subMenu();
this.app?.plugins?.forEach((plugin) => {
protyle.app?.plugins?.forEach((plugin) => {
plugin.eventBus.emit("click-blockicon", {
protyle,
menu: pluginSubMenu,

View file

@ -13,7 +13,6 @@ import {popSearch} from "../../mobile/menu/search";
import {getEventName} from "../util/compatibility";
import {Dialog} from "../../dialog";
import {Constants} from "../../constants";
import {App} from "../../index";
export class Background {
public element: HTMLElement;
@ -23,7 +22,7 @@ export class Background {
private tagsElement: HTMLElement;
private transparentData = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";
constructor(app: App, protyle: IProtyle) {
constructor(protyle: IProtyle) {
this.element = document.createElement("div");
this.element.className = "protyle-background";
this.element.innerHTML = `<div class="protyle-background__img">
@ -332,10 +331,10 @@ export class Background {
break;
} else if (type === "open-search") {
/// #if !MOBILE
openGlobalSearch(app, `#${target.textContent}#`, !window.siyuan.ctrlIsPressed);
openGlobalSearch(protyle.app, `#${target.textContent}#`, !window.siyuan.ctrlIsPressed);
/// #else
const searchOption = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
popSearch(app, {
popSearch(protyle.app, {
removed: searchOption.removed,
sort: searchOption.sort,
group: searchOption.group,

View file

@ -36,16 +36,13 @@ import {makeCard, quickMakeCard} from "../../card/makeCard";
import {viewCards} from "../../card/viewCards";
import {getNotebookName, pathPosix} from "../../util/pathName";
import {commonClick} from "../wysiwyg/commonClick";
import {App} from "../../index";
export class Title {
public element: HTMLElement;
public editElement: HTMLElement;
private timeout: number;
private app: App;
constructor(app: App, protyle: IProtyle) {
this.app = app;
constructor(protyle: IProtyle) {
this.element = document.createElement("div");
this.element.className = "protyle-title";
if (window.siyuan.config.editor.displayBookmarkIcon) {
@ -93,14 +90,14 @@ export class Title {
return;
}
if (commonHotkey(app, protyle, event)) {
if (commonHotkey(protyle, event)) {
return true;
}
if (matchHotKey(window.siyuan.config.keymap.general.enterBack.custom, event)) {
const ids = protyle.path.split("/");
if (ids.length > 2) {
openFileById({
app,
app: protyle.app,
id: ids[ids.length - 2],
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
});
@ -268,7 +265,7 @@ export class Title {
fetchPost("/api/block/getDocInfo", {
id: protyle.block.rootID
}, (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,
accelerator: window.siyuan.config.keymap.editor.general.outline.custom,
click: () => {
openOutline(this.app, protyle);
openOutline(protyle);
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({
@ -342,7 +339,7 @@ export class Title {
label: window.siyuan.languages.backlinks,
accelerator: window.siyuan.config.keymap.editor.general.backlinks.custom,
click: () => {
openBacklink(this.app, protyle);
openBacklink(protyle);
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({
@ -350,7 +347,7 @@ export class Title {
label: window.siyuan.languages.graphView,
accelerator: window.siyuan.config.keymap.editor.general.graphView.custom,
click: () => {
openGraph(this.app, protyle);
openGraph(protyle);
}
}).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,
click: () => {
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", {
id: protyle.block.rootID
}, (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,
label: window.siyuan.languages.addToDeck,
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")}`
}).element);
window.siyuan.menus.menu.popup(position);
this.app?.plugins?.forEach((plugin) => {
protyle.app?.plugins?.forEach((plugin) => {
plugin.eventBus.emit("click-editortitleicon", {
protyle,
menu: window.siyuan.menus.menu,

View file

@ -19,7 +19,6 @@ import {zoomOut} from "../../menus/protyle";
import {hideElements} from "../ui/hideElements";
import {genAssetHTML} from "../../asset/renderAssets";
import {unicode2Emoji} from "../../emoji";
import {App} from "../../index";
export const hintSlash = (key: string, protyle: IProtyle) => {
const allList: IHintData[] = [{
@ -462,7 +461,7 @@ export const hintRenderAssets = (value: string, protyle: IProtyle) => {
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 === "/") {
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) {
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);
} else if (parentElement.classList.contains("protyle-wysiwyg") && parentElement.innerHTML === "" &&
!hasClosestByClassName(parentElement, "block__edit", true) &&

View file

@ -32,20 +32,17 @@ import {processRender} from "../util/processCode";
import {AIChat} from "../../ai/chat";
import {isMobile} from "../../util/functions";
import {isCtrl} from "../util/compatibility";
import {App} from "../../index";
export class Hint {
public timeId: number;
public element: HTMLDivElement;
public enableSlash = true;
private enableEmoji = true;
private app: App;
public enableExtend = false;
public splitChar = "";
public lastIndex = -1;
constructor(app: App, protyle: IProtyle) {
this.app = app;
constructor(protyle: IProtyle) {
this.element = document.createElement("div");
this.element.setAttribute("data-close", "false");
// 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);
/// #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
openFileById({
app: this.app,
app: protyle.app,
id: newSubDocId,
action: [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT]
});
@ -649,7 +646,7 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
});
}
const rect = imgElement.getBoundingClientRect();
imgMenu(this.app, protyle, range, imgElement, {
imgMenu(protyle, range, imgElement, {
clientX: rect.left,
clientY: rect.top
});

View file

@ -34,19 +34,18 @@ export class Protyle {
public readonly version: string;
public protyle: IProtyle;
private app: App;
/**
* @param id Protyle ID
* @param options Protyle
*/
constructor(app: App, id: HTMLElement, options?: IOptions) {
this.app = app;
this.version = Constants.SIYUAN_VERSION;
const getOptions = new Options(options);
const mergedOptions = getOptions.merge();
this.protyle = {
app,
transactionTime: new Date().getTime(),
id: genUUID(),
disabled: false,
@ -56,17 +55,17 @@ export class Protyle {
block: {},
};
this.protyle.hint = new Hint(app, this.protyle);
this.protyle.hint = new Hint(this.protyle);
if (mergedOptions.render.breadcrumb) {
this.protyle.breadcrumb = new Breadcrumb(app, this.protyle);
this.protyle.breadcrumb = new Breadcrumb(this.protyle);
}
/// #if !MOBILE
if (mergedOptions.render.title) {
this.protyle.title = new Title(app, this.protyle);
this.protyle.title = new Title(this.protyle);
}
/// #endif
if (mergedOptions.render.background) {
this.protyle.background = new Background(app, this.protyle);
this.protyle.background = new Background(this.protyle);
}
this.protyle.element.innerHTML = "";
@ -75,11 +74,11 @@ export class Protyle {
this.protyle.element.appendChild(this.protyle.breadcrumb.element.parentElement);
}
this.protyle.undo = new Undo();
this.protyle.wysiwyg = new WYSIWYG(app, this.protyle);
this.protyle.toolbar = new Toolbar(app, this.protyle);
this.protyle.scroll = new Scroll(this.protyle, this.app); // 不能使用 render.scroll 来判读是否初始化,除非重构后面用到的相关变量
this.protyle.wysiwyg = new WYSIWYG(this.protyle);
this.protyle.toolbar = new Toolbar(this.protyle);
this.protyle.scroll = new Scroll(this.protyle); // 不能使用 render.scroll 来判读是否初始化,除非重构后面用到的相关变量
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) {
this.protyle.upload = new Upload();
@ -95,7 +94,7 @@ export class Protyle {
switch (data.cmd) {
case "reload":
if (data.data === this.protyle.block.rootID) {
reloadProtyle(this.protyle, app, false);
reloadProtyle(this.protyle, false);
}
break;
case "addLoading":
@ -105,7 +104,7 @@ export class Protyle {
break;
case "transactions":
data.data[0].doOperations.forEach((item: IOperation) => {
onTransaction(app, this.protyle, item, false);
onTransaction(this.protyle, item, false);
});
break;
case "readonly":
@ -123,10 +122,10 @@ export class Protyle {
id: this.protyle.block.rootID,
size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => {
onGet({data: getResponse, protyle: this.protyle, app: this.app});
onGet({data: getResponse, protyle: this.protyle});
});
} else {
reloadProtyle(this.protyle, app, false);
reloadProtyle(this.protyle, false);
}
/// #if !MOBILE
if (data.cmd === "heading2doc") {
@ -224,7 +223,6 @@ export class Protyle {
if (scrollObj) {
scrollObj.rootId = response.data.rootID;
getDocByScroll({
app: this.app,
protyle: this.protyle,
scrollAttr: scrollObj,
mergedOptions,
@ -238,7 +236,6 @@ export class Protyle {
});
} else {
getDocByScroll({
app: this.app,
protyle: this.protyle,
scrollAttr: options.scrollAttr,
mergedOptions,
@ -262,7 +259,7 @@ export class Protyle {
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,
}, 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);
});
}
@ -330,9 +327,9 @@ export class Protyle {
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);
}
/** 聚焦到编辑器 */

View file

@ -17,14 +17,13 @@ import {fetchPost} from "../../util/fetch";
import {processRender} from "../util/processCode";
import {highlightRender} from "../markdown/highlightRender";
import {speechRender} from "../markdown/speechRender";
import {App} from "../../index";
export class Preview {
public element: HTMLElement;
public previewElement: HTMLElement;
private mdTimeoutId: number;
constructor(app: App, protyle: IProtyle) {
constructor(protyle: IProtyle) {
this.element = document.createElement("div");
this.element.className = "protyle-preview fn__none";
@ -56,7 +55,7 @@ export class Preview {
if (isLocalPath(linkAddress)) {
/// #if !MOBILE
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 {
/// #if !BROWSER
openBy(linkAddress, "folder");

View file

@ -4,10 +4,9 @@ import {fetchPost} from "../../util/fetch";
import {onGet} from "../util/onGet";
import {isMobile} from "../../util/functions";
import {hasClosestBlock, hasClosestByClassName} from "../util/hasClosest";
import {App} from "../../index";
let getIndexTimeout: number;
export const scrollEvent = (app: App, protyle: IProtyle, element: HTMLElement) => {
export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => {
let elementRect = element.getBoundingClientRect();
element.addEventListener("scroll", () => {
if (!protyle.toolbar.element.classList.contains("fn__none")) {
@ -75,7 +74,6 @@ export const scrollEvent = (app: App, protyle: IProtyle, element: HTMLElement) =
data: getResponse,
protyle,
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,
protyle,
action: [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID],
app
});
});
}

View file

@ -5,7 +5,6 @@ import {updateHotkeyTip} from "../util/compatibility";
import {hasClosestByClassName} from "../util/hasClosest";
import {goEnd, goHome} from "../wysiwyg/commonHotkey";
import {isMobile} from "../../util/functions";
import {App} from "../../index";
export class Scroll {
public element: HTMLElement;
@ -14,7 +13,7 @@ export class Scroll {
public lastScrollTop: number;
public keepLazyLoad: boolean; // 保持加载内容
constructor(protyle: IProtyle, app: App) {
constructor(protyle: IProtyle) {
this.parentElement = document.createElement("div");
this.parentElement.classList.add("protyle-scroll");
if (!isMobile()) {
@ -42,25 +41,25 @@ export class Scroll {
});
/// #if BROWSER
this.inputElement.addEventListener("change", () => {
this.setIndex(protyle, app);
this.setIndex(protyle);
});
this.inputElement.addEventListener("touchend", () => {
this.setIndex(protyle, app);
this.setIndex(protyle);
});
/// #endif
this.parentElement.addEventListener("click", (event) => {
const target = event.target as HTMLElement;
if (hasClosestByClassName(target, "protyle-scroll__up")) {
goHome(protyle, app);
goHome(protyle);
} else if (hasClosestByClassName(target, "protyle-scroll__down")) {
goEnd(protyle, app);
goEnd(protyle);
} 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")) {
return;
}
@ -75,7 +74,6 @@ export class Scroll {
data: getResponse,
protyle,
action: [Constants.CB_GET_FOCUSFIRST, Constants.CB_GET_UNCHANGEID],
app
});
});
}

View file

@ -3,7 +3,6 @@ import {getSelectionOffset} from "../util/selection";
import {fetchPost} from "../../util/fetch";
import {onGet} from "../util/onGet";
import {Constants} from "../../constants";
import {App} from "../../index";
export const saveScroll = (protyle: IProtyle, getObject = false) => {
if (!protyle.wysiwyg.element.firstElementChild || window.siyuan.config.readonly) {
@ -46,7 +45,6 @@ export const saveScroll = (protyle: IProtyle, getObject = false) => {
};
export const getDocByScroll = (options: {
app: App,
protyle: IProtyle,
scrollAttr: IScrollAttr,
mergedOptions?: IOptions,
@ -75,7 +73,6 @@ export const getDocByScroll = (options: {
protyle: options.protyle,
action: actions,
scrollAttr: options.scrollAttr,
app: options.app
});
if (options.cb) {
options.cb();
@ -94,7 +91,6 @@ export const getDocByScroll = (options: {
protyle: options.protyle,
action: actions,
scrollAttr: options.scrollAttr,
app: options.app
});
if (options.cb) {
options.cb();

View file

@ -4,12 +4,11 @@ import {hasClosestBlock, hasClosestByAttribute} from "../util/hasClosest";
import {focusByRange, focusByWbr} from "../util/selection";
import {readText} from "../util/compatibility";
import {Constants} from "../../constants";
import {App} from "../../index";
export class Link extends ToolbarItem {
public element: HTMLElement;
constructor(app: App, protyle: IProtyle, menuItem: IMenuItem) {
constructor(protyle: IProtyle, menuItem: IMenuItem) {
super(protyle, menuItem);
// 不能用 getEventName否则会导致光标位置变动到点击的文档中
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");
if (aElement) {
linkMenu(app, protyle, aElement);
linkMenu(protyle, aElement);
return;
}

View file

@ -45,7 +45,6 @@ import {mathRender} from "../markdown/mathRender";
import {linkMenu} from "../../menus/protyle";
import {addScript} from "../util/addScript";
import {confirmDialog} from "../../dialog/confirmDialog";
import {App} from "../../index";
export class Toolbar {
public element: HTMLElement;
@ -53,11 +52,9 @@ export class Toolbar {
public subElementCloseCB: () => void;
public range: Range;
private toolbarHeight: number;
private app: App;
constructor(app: App, protyle: IProtyle) {
constructor(protyle: IProtyle) {
const options = protyle.options;
this.app = app;
const element = document.createElement("div");
element.className = "protyle-toolbar fn__none";
this.element = element;
@ -229,7 +226,7 @@ export class Toolbar {
menuItemObj = new Font(protyle, menuItem);
break;
case "a":
menuItemObj = new Link(this.app, protyle, menuItem);
menuItemObj = new Link(protyle, menuItem);
break;
}
if (!menuItemObj) {
@ -733,7 +730,7 @@ export class Toolbar {
const aElement = newNodes[0] as HTMLElement;
if (aElement.textContent.replace(Constants.ZWSP, "") === "" || !aElement.getAttribute("data-href")) {
needFocus = false;
linkMenu(this.app, protyle, aElement, aElement.getAttribute("data-href") ? true : false);
linkMenu(protyle, aElement, aElement.getAttribute("data-href") ? true : false);
} else {
this.range.collapse(false);
}
@ -1199,7 +1196,7 @@ export class Toolbar {
if (!protyle.disabled) {
textElement.select();
}
this.app.plugins.forEach(item => {
protyle.app.plugins.forEach(item => {
item.eventBus.emit("open-noneditableblock", {
protyle,
toolbar: this

View file

@ -7,9 +7,8 @@ import {hasClosestByAttribute, hasClosestByClassName} from "../util/hasClosest";
import {isMac} from "../util/compatibility";
import {setInlineStyle} from "../../util/assets";
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.className = "protyle-content";
if (window.siyuan.config.editor.fullWidth) {
@ -25,7 +24,7 @@ export const initUI = (protyle: IProtyle, app: App) => {
}
protyle.contentElement.appendChild(protyle.wysiwyg.element);
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.appendChild(protyle.preview.element);

View file

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

View file

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

View file

@ -16,14 +16,12 @@ import {removeLoading} from "../ui/initUI";
import {isMobile} from "../../util/functions";
import {foldPassiveType} from "../wysiwyg/renderBacklink";
import {showMessage} from "../../dialog/message";
import {App} from "../../index";
export const onGet = (options: {
data: IWebSocketData,
protyle: IProtyle,
action?: string[],
scrollAttr?: IScrollAttr
app: App
}) => {
if (!options.action) {
options.action = [];
@ -79,7 +77,7 @@ export const onGet = (options: {
action: options.action,
scrollAttr: options.scrollAttr,
isSyncing: options.data.data.isSyncing,
}, options.protyle, options.app);
}, options.protyle);
removeLoading(options.protyle);
return;
}
@ -101,7 +99,7 @@ export const onGet = (options: {
action: options.action,
scrollAttr: options.scrollAttr,
isSyncing: options.data.data.isSyncing,
}, options.protyle, options.app);
}, options.protyle);
setTitle(response.data.ial.title);
removeLoading(options.protyle);
});
@ -113,7 +111,7 @@ const setHTML = (options: {
isSyncing: boolean,
expand: boolean,
scrollAttr?: IScrollAttr
}, protyle: IProtyle, app: App) => {
}, protyle: IProtyle) => {
if (protyle.contentElement.classList.contains("fn__none")) {
return;
}
@ -261,7 +259,7 @@ const setHTML = (options: {
mode: 2,
size: window.siyuan.config.editor.dynamicLoadBlocks,
}, 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)) {
@ -270,7 +268,7 @@ const setHTML = (options: {
if (protyle.options.render.breadcrumb) {
protyle.breadcrumb.render(protyle);
}
app.plugins.forEach(item => {
protyle.app.plugins.forEach(item => {
item.eventBus.emit("loaded-protyle", protyle);
});
};

View file

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

View file

@ -4,17 +4,16 @@ import {openAttr, openFileAttr} from "../../menus/commonMenuItem";
import {openGlobalSearch} from "../../search/util";
/// #endif
import {isMobile} from "../../util/functions";
import {App} from "../../index";
export const commonClick = (app: App, event: MouseEvent & {
export const commonClick = (event: MouseEvent & {
target: HTMLElement
}, protyle: IProtyle, data?:IObject) => {
}, protyle: IProtyle, data?: IObject) => {
const isM = isMobile();
const attrBookmarkElement = hasClosestByClassName(event.target, "protyle-attr--bookmark");
if (attrBookmarkElement) {
if (!isM && (event.ctrlKey || event.metaKey)) {
/// #if !MOBILE
openGlobalSearch(app, attrBookmarkElement.textContent.trim(), true);
openGlobalSearch(protyle.app, attrBookmarkElement.textContent.trim(), true);
/// #endif
} else {
if (data) {
@ -31,10 +30,10 @@ export const commonClick = (app: App, event: MouseEvent & {
if (attrNameElement) {
if (!isM && (event.ctrlKey || event.metaKey)) {
/// #if !MOBILE
openGlobalSearch(app, attrNameElement.textContent.trim(), true);
openGlobalSearch(protyle.app, attrNameElement.textContent.trim(), true);
/// #endif
} else {
if (data ) {
if (data) {
openFileAttr(data, protyle.block.rootID, "name");
} else {
openAttr(attrNameElement.parentElement.parentElement, protyle, "name");
@ -48,7 +47,7 @@ export const commonClick = (app: App, event: MouseEvent & {
if (attrAliasElement) {
if (!isM && (event.ctrlKey || event.metaKey)) {
/// #if !MOBILE
openGlobalSearch(app, attrAliasElement.textContent.trim(), true);
openGlobalSearch(protyle.app, attrAliasElement.textContent.trim(), true);
/// #endif
} else {
if (data) {
@ -65,7 +64,7 @@ export const commonClick = (app: App, event: MouseEvent & {
if (attrMemoElement) {
if (!isM && (event.ctrlKey || event.metaKey)) {
/// #if !MOBILE
openGlobalSearch(app, attrMemoElement.getAttribute("aria-label").trim(), true);
openGlobalSearch(protyle.app, attrMemoElement.getAttribute("aria-label").trim(), true);
/// #endif
} else {
if (data) {

View file

@ -20,9 +20,8 @@ import {transaction, updateTransaction} from "./transaction";
import {onGet} from "../util/onGet";
import {Constants} from "../../constants";
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;
if (matchHotKey(window.siyuan.config.keymap.editor.general.copyHPath.custom, event)) {
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)) {
netImg2LocalAssets(protyle, app);
netImg2LocalAssets(protyle);
event.preventDefault();
event.stopPropagation();
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)) {
event.preventDefault();
event.stopPropagation();
openBacklink(app, protyle);
openBacklink(protyle);
return true;
}
if (matchHotKey(window.siyuan.config.keymap.editor.general.graphView.custom, event)) {
event.preventDefault();
event.stopPropagation();
openGraph(app, protyle);
openGraph(protyle);
return true;
}
if (matchHotKey(window.siyuan.config.keymap.editor.general.outline.custom, event)) {
event.preventDefault();
event.stopPropagation();
const offset = getSelectionOffset(target);
openOutline(app, protyle);
openOutline(protyle);
// switchWnd 后range会被清空需要重新设置
focusByOffset(target, offset.start, offset.end);
return true;
@ -74,7 +73,7 @@ export const commonHotkey = (app: App, protyle: IProtyle, event: KeyboardEvent)
}
let matchCommand = false;
app.plugins.find(item => {
protyle.app.plugins.find(item => {
item.commands.find(command => {
if (command.editorCallback && matchHotKey(command.customHotkey, event)) {
matchCommand = true;
@ -228,7 +227,7 @@ export const duplicateBlock = (nodeElements: Element[], protyle: IProtyle) => {
scrollCenter(protyle);
};
export const goHome = (protyle: IProtyle, app: App) => {
export const goHome = (protyle: IProtyle) => {
if (protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-index") === "0" ||
protyle.wysiwyg.element.firstElementChild.getAttribute("data-eof") === "1" ||
protyle.options.backlinkData) {
@ -241,12 +240,12 @@ export const goHome = (protyle: IProtyle, app: App) => {
mode: 0,
size: window.siyuan.config.editor.dynamicLoadBlocks,
}, 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") &&
protyle.wysiwyg.element.lastElementChild.getAttribute("data-eof") !== "2") {
fetchPost("/api/filetree/getDoc", {
@ -254,7 +253,7 @@ export const goEnd = (protyle: IProtyle, app: App) => {
mode: 4,
size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => {
onGet({data: getResponse, protyle, action: [Constants.CB_GET_FOCUS], app});
onGet({data: getResponse, protyle, action: [Constants.CB_GET_FOCUS]});
});
} else {
protyle.contentElement.scrollTop = protyle.contentElement.scrollHeight;

View file

@ -66,17 +66,14 @@ import {getBacklinkHeadingMore, loadBreadcrumb} from "./renderBacklink";
import {removeSearchMark} from "../toolbar/util";
import {activeBlur, hideKeyboardToolbar} from "../../mobile/util/keyboardToolbar";
import {commonClick} from "./commonClick";
import {App} from "../../index";
export class WYSIWYG {
public lastHTMLs: { [key: string]: string } = {};
public element: HTMLDivElement;
public preventKeyup: boolean;
private app: App;
constructor(app: App, protyle: IProtyle) {
this.app = app;
constructor(protyle: IProtyle) {
this.element = document.createElement("div");
this.element.className = "protyle-wysiwyg";
this.element.setAttribute("spellcheck", "false");
@ -94,8 +91,8 @@ export class WYSIWYG {
return;
}
this.bindEvent(protyle);
keydown(app, protyle, this.element);
dropEvent(app, protyle, this.element);
keydown(protyle, this.element);
dropEvent(protyle, this.element);
}
public renderCustom(ial: IObject) {
@ -1025,7 +1022,7 @@ export class WYSIWYG {
}
}
const nextElement = getNextBlock(selectElements[selectElements.length - 1]);
removeBlock(this.app, protyle, nodeElement, range);
removeBlock(protyle, nodeElement, range);
if (nextElement) {
// Ctrl+X 剪切后光标应跳到下一行行首 https://github.com/siyuan-note/siyuan/issues/5485
focusBlock(nextElement);
@ -1212,7 +1209,7 @@ export class WYSIWYG {
removeSearchMark(target);
}
if (types.includes("block-ref") && !protyle.disabled) {
refMenu(this.app, protyle, target);
refMenu(protyle, target);
// 阻止 popover
target.setAttribute("prevent-popover", "true");
setTimeout(() => {
@ -1223,13 +1220,13 @@ export class WYSIWYG {
protyle.toolbar.showFileAnnotationRef(protyle, target);
return false;
} else if (types.includes("tag") && !protyle.disabled) {
tagMenu(this.app, protyle, target);
tagMenu(protyle, target);
return false;
} else if (types.includes("inline-memo")) {
protyle.toolbar.showRender(protyle, target);
return false;
} else if (types.includes("a") && !protyle.disabled) {
linkMenu(this.app, protyle, target);
linkMenu(protyle, target);
if (window.siyuan.config.editor.floatWindowMode === 0 &&
target.getAttribute("data-href")?.startsWith("siyuan://blocks")) {
// 阻止 popover
@ -1242,7 +1239,7 @@ export class WYSIWYG {
}
}
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,
clientY: y
});
@ -1303,7 +1300,6 @@ export class WYSIWYG {
data: getResponse,
protyle,
action: [Constants.CB_GET_BEFORE, Constants.CB_GET_UNCHANGEID],
app: this.app
});
});
preventGetTopHTML = true;
@ -1498,7 +1494,7 @@ export class WYSIWYG {
let shiftStartElement: HTMLElement;
this.element.addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => {
this.app.plugins.forEach(item => {
protyle.app.plugins.forEach(item => {
item.eventBus.emit("click-editorcontent", {
protyle,
event
@ -1514,7 +1510,7 @@ export class WYSIWYG {
if (ctrlIsPressed) {
fetchPost("/api/block/checkBlockFold", {id: breadcrumbId}, (foldResponse) => {
openFileById({
app: this.app,
app: protyle.app,
id: breadcrumbId,
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
zoomIn: foldResponse.data
@ -1572,7 +1568,7 @@ export class WYSIWYG {
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
/// #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();
hideKeyboardToolbar();
/// #else
@ -1582,7 +1578,7 @@ export class WYSIWYG {
}
if (event.shiftKey) {
openFileById({
app: this.app,
app: protyle.app,
id: refBlockId,
position: "bottom",
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) {
openFileById({
app: this.app,
app: protyle.app,
id: refBlockId,
position: "right",
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) {
openFileById({
app: this.app,
app: protyle.app,
id: refBlockId,
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
keepCursor: true,
@ -1606,7 +1602,7 @@ export class WYSIWYG {
});
} else {
openFileById({
app: this.app,
app: protyle.app,
id: refBlockId,
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
zoomIn: foldResponse.data
@ -1645,7 +1641,7 @@ export class WYSIWYG {
} else if (event.shiftKey) {
openBy(linkAddress, "app");
} else {
openAsset(this.app, linkAddress, fileIds[2], "right");
openAsset(protyle.app, linkAddress, fileIds[2], "right");
}
/// #endif
return;
@ -1669,7 +1665,7 @@ export class WYSIWYG {
} else if (event.shiftKey) {
openBy(linkAddress, "app");
} else {
openAsset(this.app, linkPathname, parseInt(getSearch("page", linkAddress)), "right");
openAsset(protyle.app, linkPathname, parseInt(getSearch("page", linkAddress)), "right");
}
} else {
/// #if !BROWSER
@ -1698,11 +1694,11 @@ export class WYSIWYG {
const tagElement = hasClosestByAttribute(event.target, "data-type", "tag");
if (tagElement && !event.altKey) {
/// #if !MOBILE
openGlobalSearch(this.app, `#${tagElement.textContent}#`, !ctrlIsPressed);
openGlobalSearch(protyle.app, `#${tagElement.textContent}#`, !ctrlIsPressed);
hideElements(["dialog"]);
/// #else
const searchOption = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
popSearch(this.app, {
popSearch(protyle.app, {
removed: searchOption.removed,
sort: searchOption.sort,
group: searchOption.group,
@ -1723,13 +1719,13 @@ export class WYSIWYG {
if (embedItemElement) {
const embedId = embedItemElement.getAttribute("data-id");
/// #if MOBILE
openMobileFileById(this.app, embedId, [Constants.CB_GET_ALL]);
openMobileFileById(protyle.app, embedId, [Constants.CB_GET_ALL]);
activeBlur();
hideKeyboardToolbar();
/// #else
if (event.shiftKey) {
openFileById({
app: this.app,
app: protyle.app,
id: embedId,
position: "bottom",
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL],
@ -1737,7 +1733,7 @@ export class WYSIWYG {
});
} else if (event.altKey) {
openFileById({
app: this.app,
app: protyle.app,
id: embedId,
position: "right",
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL],
@ -1745,7 +1741,7 @@ export class WYSIWYG {
});
} else if (ctrlIsPressed) {
openFileById({
app: this.app,
app: protyle.app,
id: embedId,
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL],
keepCursor: true,
@ -1753,7 +1749,7 @@ export class WYSIWYG {
});
} else if (!protyle.disabled) {
window.siyuan.blockPanels.push(new BlockPanel({
app: this.app,
app: protyle.app,
targetElement: embedItemElement,
isBacklink: false,
nodeIds: [embedId],
@ -1764,7 +1760,7 @@ export class WYSIWYG {
return;
}
if (commonClick(this.app, event, protyle)) {
if (commonClick(event, protyle)) {
return;
}
@ -1829,7 +1825,7 @@ export class WYSIWYG {
if (actionElement) {
const type = actionElement.parentElement.parentElement.getAttribute("data-type");
if (type === "img" && !protyle.disabled) {
imgMenu(this.app, protyle, range, actionElement.parentElement.parentElement, {
imgMenu(protyle, range, actionElement.parentElement.parentElement, {
clientX: event.clientX + 4,
clientY: event.clientY
});
@ -1865,7 +1861,7 @@ export class WYSIWYG {
} else if (event.shiftKey) {
openAttr(actionElement.parentElement, protyle);
} 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 {
if (actionElement.classList.contains("protyle-action--task")) {
const html = actionElement.parentElement.outerHTML;

View file

@ -71,9 +71,8 @@ import {escapeHtml} from "../../util/escape";
import {insertHTML} from "../util/insertHTML";
import {quickMakeCard} from "../../card/makeCard";
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 }) => {
if (event.target.localName === "protyle-html") {
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 = topNodeElement.parentElement;
}
zoomOut({protyle, id:topNodeElement.getAttribute("data-node-id"), app});
zoomOut({protyle, id: topNodeElement.getAttribute("data-node-id")});
event.preventDefault();
event.stopPropagation();
return;
@ -442,13 +441,13 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
const ids = protyle.path.split("/");
if (ids.length > 2) {
openFileById({
app,
app: protyle.app,
id: ids[ids.length - 2],
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_SCROLL]
});
}
} 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.stopPropagation();
@ -477,14 +476,14 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
}
// ctrl+home 光标移动到顶
if (!event.altKey && !event.shiftKey && isCtrl(event) && event.key === "Home") {
goHome(protyle, app);
goHome(protyle);
event.stopPropagation();
event.preventDefault();
return;
}
// ctrl+end 光标移动到尾
if (!event.altKey && !event.shiftKey && isCtrl(event) && event.key === "End") {
goEnd(protyle, app);
goEnd(protyle);
event.stopPropagation();
event.preventDefault();
return;
@ -532,7 +531,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
removeSearchMark(inlineElement);
}
if (types.includes("block-ref")) {
refMenu(app, protyle, inlineElement);
refMenu(protyle, inlineElement);
return;
} else if (types.includes("inline-memo")) {
protyle.toolbar.showRender(protyle, inlineElement);
@ -541,10 +540,10 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
protyle.toolbar.showFileAnnotationRef(protyle, inlineElement);
return;
} else if (types.includes("a")) {
linkMenu(app, protyle, inlineElement);
linkMenu(protyle, inlineElement);
return;
} else if (types.includes("tag")) {
tagMenu(app, protyle, inlineElement);
tagMenu(protyle, inlineElement);
return;
}
}
@ -694,7 +693,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
// 不可使用 !event.shiftKey否则 https://ld246.com/article/1666434796806
if (!event.altKey && (event.key === "Backspace" || event.key === "Delete")) {
if (protyle.wysiwyg.element.querySelector(".protyle-wysiwyg--select")) {
removeBlock(app, protyle, nodeElement, range);
removeBlock(protyle, nodeElement, range);
event.stopPropagation();
event.preventDefault();
return;
@ -736,7 +735,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
previousSibling.nodeType !== 3 && (previousSibling as HTMLElement).outerHTML === "<span>\\</span>" &&
!hasPreviousSibling(previousSibling.parentElement)) {
range.setStartBefore(previousSibling.parentElement);
removeBlock(app, protyle, nodeElement, range);
removeBlock(protyle, nodeElement, range);
event.stopPropagation();
event.preventDefault();
return;
@ -746,7 +745,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
range.startContainer.parentElement.getAttribute("data-type")?.indexOf("backslash") > -1 &&
!hasPreviousSibling(range.startContainer.parentElement)) {
range.setStartBefore(range.startContainer.parentElement);
removeBlock(app, protyle, nodeElement, range);
removeBlock(protyle, nodeElement, range);
event.stopPropagation();
event.preventDefault();
return;
@ -768,7 +767,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
const editElement = getContenteditableElement(nodeElement);
if (!editElement) {
nodeElement.classList.add("protyle-wysiwyg--select");
removeBlock(app, protyle, nodeElement, range);
removeBlock(protyle, nodeElement, range);
event.stopPropagation();
event.preventDefault();
return;
@ -783,7 +782,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
if (nextRange) {
const nextBlockElement = hasClosestBlock(nextRange.startContainer);
if (nextBlockElement) {
removeBlock(app, protyle, nextBlockElement, nextRange);
removeBlock(protyle, nextBlockElement, nextRange);
}
}
event.stopPropagation();
@ -801,7 +800,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
range.startOffset === 0 ||
(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.preventDefault();
return;
@ -810,7 +809,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
nodeElement.getAttribute("data-type") === "NodeTable" &&
(range.startContainer as HTMLElement).children[range.startOffset - 1]?.tagName === "TABLE") {
nodeElement.classList.add("protyle-wysiwyg--select");
removeBlock(app, protyle, nodeElement, range);
removeBlock(protyle, nodeElement, range);
event.stopPropagation();
event.preventDefault();
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)) {
protyle.undo.undo(app, protyle);
protyle.undo.undo(protyle);
event.preventDefault();
event.stopPropagation();
return;
}
if (matchHotKey(window.siyuan.config.keymap.editor.general.redo.custom, event)) {
protyle.undo.redo(app, protyle);
protyle.undo.redo(protyle);
event.preventDefault();
event.stopPropagation();
return;
@ -954,7 +953,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
return true;
}
/// #if !MOBILE
if (commonHotkey(app, protyle, event)) {
if (commonHotkey(protyle, event)) {
return true;
}
/// #endif
@ -1446,7 +1445,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
});
writeText(protyle.lute.BlockDOM2StdMd(html).trimEnd());
const nextElement = getNextBlock(selectElements[selectElements.length - 1]);
removeBlock(app, protyle, nodeElement, range);
removeBlock(protyle, nodeElement, range);
if (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)) {
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
openFileById({
app,
app: protyle.app,
id,
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
zoomIn: foldResponse.data
@ -1610,7 +1609,7 @@ export const keydown = (app: App, protyle: IProtyle, editorElement: HTMLElement)
// 打开块引和编辑器中引用、反链、书签中点击事件需保持一致,都加载上下文
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
openFileById({
app,
app: protyle.app,
id,
action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
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)) {
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
openFileById({
app,
app: protyle.app,
id,
position: "right",
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)) {
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
openFileById({
app,
app: protyle.app,
id,
position: "bottom",
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)) {
// open popover
window.siyuan.blockPanels.push(new BlockPanel({
app,
app: protyle.app,
isBacklink: false,
targetElement: refElement,
nodeIds: [id],

View file

@ -15,7 +15,6 @@ import {preventScroll} from "../scroll/preventScroll";
import {hideElements} from "../ui/hideElements";
import {Constants} from "../../constants";
import {scrollCenter} from "../../util/highlightById";
import {App} from "../../index";
const removeLi = (protyle: IProtyle, blockElement: Element, range: Range) => {
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);
};
export const removeBlock = (app: App, protyle: IProtyle, blockElement: Element, range: Range) => {
export const removeBlock = (protyle: IProtyle, blockElement: Element, range: Range) => {
// 删除后,防止滚动条滚动后调用 get 请求,因为返回的请求已查找不到内容块了
preventScroll(protyle);
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 (protyle.block.showAll && sideElement.classList.contains("protyle-wysiwyg") && protyle.wysiwyg.element.childElementCount === 0) {
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);
} else {
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() === "") {
blockElement.classList.add("protyle-wysiwyg--select");
removeBlock(app, protyle, blockElement, range);
removeBlock(protyle, blockElement, range);
return;
}
// 设置 bq 和代码块光标

View file

@ -17,7 +17,6 @@ import {hideElements} from "../ui/hideElements";
import {reloadProtyle} from "../util/reload";
import {countBlockWord} from "../../layout/status";
import {needSubscribe} from "../../util/needSubscribe";
import {App} from "../../index";
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 doOperations = window.siyuan.transactions[0].doOperations;
const undoOperations = window.siyuan.transactions[0].undoOperations;
@ -65,9 +64,9 @@ const promiseTransaction = (app: App) => {
}]
}, (response) => {
if (window.siyuan.transactions.length === 0) {
promiseTransactions(app);
promiseTransactions();
} else {
promiseTransaction(app);
promiseTransaction();
}
countBlockWord([], protyle.block.rootID, true);
@ -140,7 +139,6 @@ const promiseTransaction = (app: App) => {
data: getResponse,
protyle,
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(() => {
if (window.siyuan.transactions.length === 0) {
return;
}
window.clearInterval(window.siyuan.transactionsTimeout);
promiseTransaction(app);
promiseTransaction();
}, 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[] = [];
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`)).forEach(item => {
if (!hasClosestByAttribute(item.parentElement, "data-type", "NodeBlockQueryEmbed")) {
@ -655,7 +653,7 @@ export const onTransaction = (app: App, protyle: IProtyle, operation: IOperation
return;
}
if (operation.action === "append") {
reloadProtyle(protyle, app, false);
reloadProtyle(protyle, false);
}
};