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) { return toolbarKeyToMenu(toolbar); } }