A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
at lambda-fork/main 128 lines 3.8 kB view raw
1import {Constants} from "../../constants"; 2import {merge} from "./merge"; 3import {hintEmbed, hintRef, hintSlash, hintTag} from "../hint/extend"; 4import {toolbarKeyToMenu} from "../toolbar/util"; 5 6export class Options { 7 public options: IProtyleOptions; 8 private defaultOptions: IProtyleOptions = { 9 mode: "wysiwyg", 10 blockId: "", 11 render: { 12 background: false, 13 title: false, 14 titleShowTop: false, 15 hideTitleOnZoom: false, 16 gutter: true, 17 scroll: false, 18 breadcrumb: true, 19 breadcrumbDocName: false, 20 }, 21 action: [], 22 after: undefined, 23 classes: { 24 preview: "", 25 }, 26 click: { 27 preventInsetEmptyBlock: false 28 }, 29 hint: { 30 delay: 200, 31 emoji: { 32 "+1": "👍", 33 "-1": "👎", 34 "confused": "😕", 35 "eyes": "👀️", 36 "heart": "❤️", 37 "rocket": "🚀️", 38 "smile": "😄", 39 "tada": "🎉️", 40 }, 41 emojiPath: "/emojis", 42 extend: [{ 43 key: "((", 44 hint: hintRef, 45 }, { 46 key: "【【", 47 hint: hintRef, 48 }, { 49 key: "((", 50 hint: hintRef, 51 }, { 52 key: "[[", 53 hint: hintRef, 54 }, { 55 key: "{{", 56 hint: hintEmbed, 57 }, { 58 key: "「「", 59 hint: hintEmbed, 60 }, { 61 key: "「『", 62 hint: hintEmbed, 63 }, { 64 key: "『「", 65 hint: hintEmbed, 66 }, { 67 key: "『『", 68 hint: hintEmbed, 69 }, { 70 key: "#", // 需在 / 之前,否则 #abc/ 会显示菜单 71 hint: hintTag, 72 }, { 73 key: "/", 74 hint: hintSlash, 75 }, { 76 key: "、", 77 hint: hintSlash, 78 }, { 79 key: ":" // 必须在最后一个,否则块引用后的 : 不能被解析 80 }], 81 }, 82 lang: window.siyuan.config.appearance.lang, 83 preview: { 84 actions: ["desktop", "tablet", "mobile", "mp-wechat", "zhihu", "yuque"], 85 delay: 0, 86 markdown: { 87 paragraphBeginningSpace: window.siyuan.config.export.paragraphBeginningSpace, 88 listStyle: false, 89 sanitize: true, 90 }, 91 mode: "both", 92 }, 93 toolbar: Constants.PROTYLE_TOOLBAR, 94 typewriterMode: false, 95 upload: { 96 max: 1024 * 1024 * 1024 * 8, 97 url: Constants.UPLOAD_ADDRESS, 98 extraData: {}, 99 fieldName: "file[]", 100 filename: (name: string) => name.replace(/[\\/:*?"'<>|\[\]\(\)~!`&{}=#%$]/g, ""), 101 linkToImgUrl: "", 102 withCredentials: false, 103 } 104 }; 105 106 constructor(options: IProtyleOptions) { 107 this.options = options; 108 } 109 110 public merge(): IProtyleOptions { 111 if (this.options) { 112 if (this.options.toolbar) { 113 this.options.toolbar = this.mergeToolbar(this.options.toolbar); 114 } else { 115 this.options.toolbar = this.mergeToolbar(this.defaultOptions.toolbar); 116 } 117 if (this.options.hint?.emoji) { 118 this.defaultOptions.hint.emoji = this.options.hint.emoji; 119 } 120 } 121 122 return merge(this.defaultOptions, this.options); 123 } 124 125 private mergeToolbar(toolbar: Array<string | IMenuItem>) { 126 return toolbarKeyToMenu(toolbar); 127 } 128}