2022-05-26 15:18:53 +08:00
|
|
|
|
import {Constants} from "../../constants";
|
|
|
|
|
|
import {merge} from "./merge";
|
|
|
|
|
|
import {hintEmbed, hintRef, hintSlash, hintTag} from "../hint/extend";
|
|
|
|
|
|
import {isMobile} from "../../util/functions";
|
|
|
|
|
|
|
|
|
|
|
|
export class Options {
|
|
|
|
|
|
public options: IOptions;
|
|
|
|
|
|
private defaultOptions: IOptions = {
|
|
|
|
|
|
mode: "wysiwyg",
|
|
|
|
|
|
blockId: "",
|
|
|
|
|
|
render: {
|
|
|
|
|
|
background: false,
|
|
|
|
|
|
title: false,
|
|
|
|
|
|
gutter: true,
|
|
|
|
|
|
scroll: false,
|
2022-08-31 01:14:45 +08:00
|
|
|
|
breadcrumb: true,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
breadcrumbDocName: false,
|
|
|
|
|
|
breadcrumbContext: false
|
|
|
|
|
|
},
|
|
|
|
|
|
after: undefined,
|
|
|
|
|
|
classes: {
|
|
|
|
|
|
preview: "",
|
|
|
|
|
|
},
|
|
|
|
|
|
debugger: Constants.NODE_ENV === "development",
|
|
|
|
|
|
hint: {
|
|
|
|
|
|
delay: 200,
|
|
|
|
|
|
emoji: {
|
|
|
|
|
|
"+1": "👍",
|
|
|
|
|
|
"-1": "👎",
|
|
|
|
|
|
"confused": "😕",
|
|
|
|
|
|
"eyes": "👀️",
|
|
|
|
|
|
"heart": "❤️",
|
|
|
|
|
|
"rocket": "🚀️",
|
|
|
|
|
|
"smile": "😄",
|
|
|
|
|
|
"tada": "🎉️",
|
|
|
|
|
|
},
|
|
|
|
|
|
emojiPath: "/emojis",
|
|
|
|
|
|
extend: [{
|
|
|
|
|
|
key: "((",
|
|
|
|
|
|
hint: hintRef,
|
|
|
|
|
|
}, {
|
|
|
|
|
|
key: "【【",
|
|
|
|
|
|
hint: hintRef,
|
|
|
|
|
|
}, {
|
|
|
|
|
|
key: "((",
|
|
|
|
|
|
hint: hintRef,
|
|
|
|
|
|
}, {
|
|
|
|
|
|
key: "[[",
|
|
|
|
|
|
hint: hintRef,
|
|
|
|
|
|
}, {
|
|
|
|
|
|
key: "{{",
|
|
|
|
|
|
hint: hintEmbed,
|
|
|
|
|
|
}, {
|
|
|
|
|
|
key: "「「",
|
|
|
|
|
|
hint: hintEmbed,
|
|
|
|
|
|
}, {
|
|
|
|
|
|
key: "#", // 需在 / 之前,否则 #abc/ 会显示菜单
|
|
|
|
|
|
hint: hintTag,
|
|
|
|
|
|
}, {
|
|
|
|
|
|
key: "/",
|
|
|
|
|
|
hint: hintSlash,
|
|
|
|
|
|
}, {
|
|
|
|
|
|
key: "、",
|
|
|
|
|
|
hint: hintSlash,
|
|
|
|
|
|
}, {
|
|
|
|
|
|
key: ":" // 必须在最后一个,否则块引用后的 : 不能被解析
|
|
|
|
|
|
}],
|
|
|
|
|
|
},
|
|
|
|
|
|
lang: window.siyuan.config.appearance.lang,
|
|
|
|
|
|
preview: {
|
|
|
|
|
|
actions: ["desktop", "tablet", "mobile", "mp-wechat", "zhihu", "yuque"],
|
|
|
|
|
|
delay: 1000,
|
|
|
|
|
|
markdown: {
|
|
|
|
|
|
paragraphBeginningSpace: window.siyuan.config.export.paragraphBeginningSpace,
|
|
|
|
|
|
listStyle: false,
|
|
|
|
|
|
sanitize: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
mode: "both",
|
|
|
|
|
|
},
|
|
|
|
|
|
toolbar: isMobile() ? [
|
2022-09-13 10:19:13 +08:00
|
|
|
|
"block-ref",
|
|
|
|
|
|
"a",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
"|",
|
2022-09-22 10:02:13 +08:00
|
|
|
|
"text",
|
2022-09-13 10:19:13 +08:00
|
|
|
|
"strong",
|
|
|
|
|
|
"em",
|
|
|
|
|
|
"u",
|
2022-09-22 10:02:13 +08:00
|
|
|
|
"clear",
|
|
|
|
|
|
"|",
|
2022-09-13 10:19:13 +08:00
|
|
|
|
"code",
|
2022-09-21 11:03:32 +08:00
|
|
|
|
"tag",
|
|
|
|
|
|
"inline-memo",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
"inline-math",
|
|
|
|
|
|
] : [
|
2022-09-13 10:19:13 +08:00
|
|
|
|
"block-ref",
|
|
|
|
|
|
"a",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
"|",
|
2022-09-22 10:02:13 +08:00
|
|
|
|
"text",
|
2022-09-13 10:19:13 +08:00
|
|
|
|
"strong",
|
|
|
|
|
|
"em",
|
|
|
|
|
|
"u",
|
|
|
|
|
|
"s",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
"mark",
|
|
|
|
|
|
"sup",
|
|
|
|
|
|
"sub",
|
2022-09-22 10:02:13 +08:00
|
|
|
|
"clear",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
"|",
|
2022-09-13 10:19:13 +08:00
|
|
|
|
"code",
|
2022-09-21 11:03:32 +08:00
|
|
|
|
"kbd",
|
|
|
|
|
|
"tag",
|
|
|
|
|
|
"inline-memo",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
"inline-math",
|
|
|
|
|
|
],
|
|
|
|
|
|
typewriterMode: false,
|
|
|
|
|
|
upload: {
|
|
|
|
|
|
max: 1024 * 1024 * 1024 * 4,
|
|
|
|
|
|
url: Constants.UPLOAD_ADDRESS,
|
|
|
|
|
|
extraData: {},
|
|
|
|
|
|
fieldName: "file[]",
|
|
|
|
|
|
filename: (name: string) => name.replace(/[\\/:*?"'<>|]/g, ""),
|
|
|
|
|
|
linkToImgUrl: "",
|
|
|
|
|
|
withCredentials: false,
|
2022-09-01 12:21:50 +08:00
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
constructor(options: IOptions) {
|
|
|
|
|
|
this.options = options;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public merge(): IOptions {
|
|
|
|
|
|
if (this.options) {
|
|
|
|
|
|
if (this.options.toolbar) {
|
|
|
|
|
|
this.options.toolbar = this.mergeToolbar(this.options.toolbar);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.options.toolbar = this.mergeToolbar(this.defaultOptions.toolbar);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (this.options.hint?.emoji) {
|
|
|
|
|
|
this.defaultOptions.hint.emoji = this.options.hint.emoji;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return merge(this.defaultOptions, this.options);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private mergeToolbar(toolbar: Array<string | IMenuItem>) {
|
|
|
|
|
|
const toolbarItem: IMenuItem [] = [{
|
2022-09-13 10:19:13 +08:00
|
|
|
|
name: "block-ref",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
hotkey: window.siyuan.config.keymap.editor.insert.blockRef.custom,
|
2022-09-13 10:19:13 +08:00
|
|
|
|
lang: "blockRef",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconGraph",
|
|
|
|
|
|
tipPosition: "ne",
|
|
|
|
|
|
}, {
|
2022-09-13 10:19:13 +08:00
|
|
|
|
name: "a",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
hotkey: window.siyuan.config.keymap.editor.insert.link.custom,
|
2022-09-13 10:19:13 +08:00
|
|
|
|
lang: "link",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
icon: "iconLink",
|
|
|
|
|
|
tipPosition: "n",
|
|
|
|
|
|
}, {
|
2022-09-13 10:19:13 +08:00
|
|
|
|
name: "strong",
|
|
|
|
|
|
lang: "bold",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
hotkey: window.siyuan.config.keymap.editor.insert.bold.custom,
|
|
|
|
|
|
icon: "iconBold",
|
|
|
|
|
|
tipPosition: "n",
|
|
|
|
|
|
}, {
|
2022-09-13 10:19:13 +08:00
|
|
|
|
name: "em",
|
|
|
|
|
|
lang: "italic",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
hotkey: window.siyuan.config.keymap.editor.insert.italic.custom,
|
|
|
|
|
|
icon: "iconItalic",
|
|
|
|
|
|
tipPosition: "n",
|
|
|
|
|
|
}, {
|
2022-09-13 10:19:13 +08:00
|
|
|
|
name: "u",
|
|
|
|
|
|
lang: "underline",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
hotkey: window.siyuan.config.keymap.editor.insert.underline.custom,
|
|
|
|
|
|
icon: "iconUnderline",
|
|
|
|
|
|
tipPosition: "n",
|
|
|
|
|
|
}, {
|
2022-09-13 10:19:13 +08:00
|
|
|
|
name: "s",
|
|
|
|
|
|
lang: "strike",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
hotkey: window.siyuan.config.keymap.editor.insert.strike.custom,
|
|
|
|
|
|
icon: "iconStrike",
|
|
|
|
|
|
tipPosition: "n",
|
|
|
|
|
|
}, {
|
|
|
|
|
|
name: "mark",
|
2022-09-13 10:19:13 +08:00
|
|
|
|
lang: "mark",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
hotkey: window.siyuan.config.keymap.editor.insert.mark.custom,
|
|
|
|
|
|
icon: "iconMark",
|
|
|
|
|
|
tipPosition: "n",
|
|
|
|
|
|
}, {
|
|
|
|
|
|
name: "sup",
|
2022-09-13 10:19:13 +08:00
|
|
|
|
lang: "sup",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
hotkey: window.siyuan.config.keymap.editor.insert.sup.custom,
|
|
|
|
|
|
icon: "iconSup",
|
|
|
|
|
|
tipPosition: "n",
|
|
|
|
|
|
}, {
|
|
|
|
|
|
name: "sub",
|
2022-09-13 10:19:13 +08:00
|
|
|
|
lang: "sub",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
hotkey: window.siyuan.config.keymap.editor.insert.sub.custom,
|
|
|
|
|
|
icon: "iconSub",
|
|
|
|
|
|
tipPosition: "n",
|
|
|
|
|
|
}, {
|
|
|
|
|
|
name: "kbd",
|
2022-09-13 10:19:13 +08:00
|
|
|
|
lang: "kbd",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
hotkey: window.siyuan.config.keymap.editor.insert.kbd.custom,
|
|
|
|
|
|
icon: "iconKeymap",
|
|
|
|
|
|
tipPosition: "n",
|
|
|
|
|
|
}, {
|
|
|
|
|
|
name: "tag",
|
2022-09-13 10:19:13 +08:00
|
|
|
|
lang: "tag",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
hotkey: window.siyuan.config.keymap.editor.insert.tag.custom,
|
|
|
|
|
|
icon: "iconTags",
|
|
|
|
|
|
tipPosition: "n",
|
|
|
|
|
|
}, {
|
2022-09-13 10:19:13 +08:00
|
|
|
|
name: "code",
|
|
|
|
|
|
lang: "inline-code",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
hotkey: window.siyuan.config.keymap.editor.insert["inline-code"].custom,
|
|
|
|
|
|
icon: "iconInlineCode",
|
|
|
|
|
|
tipPosition: "n",
|
|
|
|
|
|
}, {
|
|
|
|
|
|
name: "inline-math",
|
2022-09-13 10:19:13 +08:00
|
|
|
|
lang: "inline-math",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
hotkey: window.siyuan.config.keymap.editor.insert["inline-math"].custom,
|
|
|
|
|
|
icon: "iconMath",
|
2022-09-17 23:14:02 +08:00
|
|
|
|
tipPosition: "n",
|
|
|
|
|
|
}, {
|
|
|
|
|
|
name: "inline-memo",
|
|
|
|
|
|
lang: "memo",
|
|
|
|
|
|
hotkey: window.siyuan.config.keymap.editor.insert.memo.custom,
|
|
|
|
|
|
icon: "iconM",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
tipPosition: "n",
|
|
|
|
|
|
}, {
|
2022-09-13 10:19:13 +08:00
|
|
|
|
name: "text",
|
|
|
|
|
|
lang: "font",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
hotkey: window.siyuan.config.keymap.editor.insert.font.custom,
|
|
|
|
|
|
icon: "iconFont",
|
|
|
|
|
|
tipPosition: "n",
|
2022-09-21 11:03:32 +08:00
|
|
|
|
}, {
|
|
|
|
|
|
name: "clear",
|
|
|
|
|
|
lang: "clearFontStyle",
|
|
|
|
|
|
hotkey: window.siyuan.config.keymap.editor.insert.clearFontStyle.custom,
|
|
|
|
|
|
icon: "iconClear",
|
|
|
|
|
|
tipPosition: "n",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}, {
|
|
|
|
|
|
name: "|",
|
2022-09-13 10:19:13 +08:00
|
|
|
|
}];
|
2022-05-26 15:18:53 +08:00
|
|
|
|
const toolbarResult: IMenuItem[] = [];
|
|
|
|
|
|
toolbar.forEach((menuItem: IMenuItem) => {
|
|
|
|
|
|
let currentMenuItem = menuItem;
|
|
|
|
|
|
toolbarItem.find((defaultMenuItem: IMenuItem) => {
|
|
|
|
|
|
if (typeof menuItem === "string" && defaultMenuItem.name === menuItem) {
|
|
|
|
|
|
currentMenuItem = defaultMenuItem;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (typeof menuItem === "object" && defaultMenuItem.name === menuItem.name) {
|
|
|
|
|
|
currentMenuItem = Object.assign({}, defaultMenuItem, menuItem);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
toolbarResult.push(currentMenuItem);
|
|
|
|
|
|
});
|
|
|
|
|
|
return toolbarResult;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|