2022-05-26 15:18:53 +08:00
|
|
|
|
import {Constants} from "../../constants";
|
|
|
|
|
|
import {merge} from "./merge";
|
|
|
|
|
|
import {hintEmbed, hintRef, hintSlash, hintTag} from "../hint/extend";
|
2024-11-08 01:17:38 +08:00
|
|
|
|
import {toolbarKeyToMenu} from "../toolbar/util";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
|
|
|
|
|
|
export class Options {
|
2024-10-22 18:13:21 +08:00
|
|
|
|
public options: IProtyleOptions;
|
|
|
|
|
|
private defaultOptions: IProtyleOptions = {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
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,
|
|
|
|
|
|
},
|
2022-09-29 23:08:37 +08:00
|
|
|
|
action: [],
|
2022-05-26 15:18:53 +08:00
|
|
|
|
after: undefined,
|
|
|
|
|
|
classes: {
|
|
|
|
|
|
preview: "",
|
|
|
|
|
|
},
|
2025-07-18 10:25:14 +08:00
|
|
|
|
click: {
|
|
|
|
|
|
preventInsetEmptyBlock: false
|
|
|
|
|
|
},
|
2022-05-26 15:18:53 +08:00
|
|
|
|
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,
|
2023-09-27 15:26:22 +08:00
|
|
|
|
}, {
|
|
|
|
|
|
key: "「『",
|
|
|
|
|
|
hint: hintEmbed,
|
|
|
|
|
|
}, {
|
|
|
|
|
|
key: "『「",
|
|
|
|
|
|
hint: hintEmbed,
|
|
|
|
|
|
}, {
|
|
|
|
|
|
key: "『『",
|
|
|
|
|
|
hint: hintEmbed,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}, {
|
|
|
|
|
|
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"],
|
2023-12-30 22:50:09 +08:00
|
|
|
|
delay: 0,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
markdown: {
|
|
|
|
|
|
paragraphBeginningSpace: window.siyuan.config.export.paragraphBeginningSpace,
|
|
|
|
|
|
listStyle: false,
|
|
|
|
|
|
sanitize: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
mode: "both",
|
|
|
|
|
|
},
|
2024-11-11 12:52:02 +08:00
|
|
|
|
toolbar: Constants.PROTYLE_TOOLBAR,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
typewriterMode: false,
|
|
|
|
|
|
upload: {
|
2025-02-24 11:18:36 +08:00
|
|
|
|
max: 1024 * 1024 * 1024 * 8,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
url: Constants.UPLOAD_ADDRESS,
|
|
|
|
|
|
extraData: {},
|
|
|
|
|
|
fieldName: "file[]",
|
2024-08-30 09:43:16 +08:00
|
|
|
|
filename: (name: string) => name.replace(/[\\/:*?"'<>|\[\]\(\)~!`&{}=#%$]/g, ""),
|
2022-05-26 15:18:53 +08:00
|
|
|
|
linkToImgUrl: "",
|
|
|
|
|
|
withCredentials: false,
|
2022-09-01 12:21:50 +08:00
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2024-10-22 18:13:21 +08:00
|
|
|
|
constructor(options: IProtyleOptions) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
this.options = options;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-22 18:13:21 +08:00
|
|
|
|
public merge(): IProtyleOptions {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
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>) {
|
2024-11-08 01:17:38 +08:00
|
|
|
|
return toolbarKeyToMenu(toolbar);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|