siyuan/app/src/protyle/util/Options.ts
Vanessa cb2560ffda 🚨
2024-11-14 23:21:55 +08:00

124 lines
3.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {Constants} from "../../constants";
import {merge} from "./merge";
import {hintEmbed, hintRef, hintSlash, hintTag} from "../hint/extend";
import {toolbarKeyToMenu} from "../toolbar/util";
export class Options {
public options: IProtyleOptions;
private defaultOptions: IProtyleOptions = {
mode: "wysiwyg",
blockId: "",
render: {
background: false,
title: false,
gutter: true,
scroll: false,
breadcrumb: true,
breadcrumbDocName: false,
},
action: [],
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: "「『",
hint: hintEmbed,
}, {
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: 0,
markdown: {
paragraphBeginningSpace: window.siyuan.config.export.paragraphBeginningSpace,
listStyle: false,
sanitize: true,
},
mode: "both",
},
toolbar: Constants.PROTYLE_TOOLBAR,
typewriterMode: false,
upload: {
max: 1024 * 1024 * 1024 * 4,
url: Constants.UPLOAD_ADDRESS,
extraData: {},
fieldName: "file[]",
filename: (name: string) => name.replace(/[\\/:*?"'<>|\[\]\(\)~!`&{}=#%$]/g, ""),
linkToImgUrl: "",
withCredentials: false,
}
};
constructor(options: IProtyleOptions) {
this.options = options;
}
public merge(): IProtyleOptions {
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>) {
return toolbarKeyToMenu(toolbar);
}
}