Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 对于配置config 类型的修复 #890

Merged
merged 6 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/.npmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ELECTRON_MIRROR="https://npm.taobao.org/mirrors/electron/"
electron_mirror=https://npmmirror.com/mirrors/electron/
18 changes: 13 additions & 5 deletions client/src/components/CherryMarkdown/cherry.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useStoreCherry } from "@/store/storeCherry";
import Cherry from "cherry-markdown";
import { CherryOptions } from "cherry-markdown/types/cherry";
import { CherryOptions } from "../../../../types/cherry";
import { ipcRenderer } from "electron";
import { onMounted, shallowReactive } from "vue";

Expand Down Expand Up @@ -60,14 +60,14 @@ const initCherryMarkdown = () => {
// 对复制内容进行额外处理
return code;
},
onExpandCode: (event, code) => {
onExpandCode: (event: any, code: string) => {
// 阻止默认的粘贴事件
// return false;
// 对复制内容进行额外处理
// console.log(event, code);
return code;
},
onUnExpandCode: (event, code) => {
onUnExpandCode: (event: any, code: string) => {
// 阻止默认的粘贴事件
// return false;
// 对复制内容进行额外处理
Expand All @@ -85,11 +85,19 @@ const initCherryMarkdown = () => {
},
};

type CustomConfig = {
CustomToolbar: {
CustomMenuType: {
customMenu_fileUpload: any
}
}
}

/**
* 默认配置
*/
const defaultConfig = {
// const defaultConfig: CherryOptions<CustomConfig> = {
const defaultConfig: CherryOptions = {
id: "cherry-markdown",
// 第三方包
externals: {
Expand Down Expand Up @@ -278,7 +286,7 @@ const initCherryMarkdown = () => {
};

onMounted(() => {
const cherryInstance = new Cherry(defaultConfig as Partial<CherryOptions>);
const cherryInstance = new Cherry(defaultConfig);
storeCherry.cherry = shallowReactive(cherryInstance)
})
}
Expand Down
23 changes: 9 additions & 14 deletions types/cherry.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import CodeMirror from 'codemirror';
import SyntaxBase from '../src/core/SyntaxBase';
import { FormulaMenu } from '@/toolbars/BubbleFormula';


export interface CherryExternalsOptions {
[key: string]: any;
[key: symbol]: any;
Saraph1nes marked this conversation as resolved.
Show resolved Hide resolved
}

type CherryToolbarsCustomType = {
Expand Down Expand Up @@ -69,7 +68,7 @@ export interface _CherryOptions<T extends CherryCustomOptions = CherryCustomOpti
themeNameSpace: string,
themeSettings: {
/** 主题列表,用于切换主题 */
themeList:{
themeList: {
/** 主题对应的class名 */
className: string,
/** 主题名称 */
Expand Down Expand Up @@ -118,11 +117,11 @@ export interface _CherryOptions<T extends CherryCustomOptions = CherryCustomOpti
/** 编辑器选区变化时触发 */
selectionChange?: ({ selections: [], lastSelections: [], info }) => void;
/** 变更语言时触发 */
afterChangeLocale?: ( locale: string ) => void;
afterChangeLocale?: (locale: string) => void;
/** 变更主题时触发 */
changeMainTheme?: ( theme: string ) => void;
changeMainTheme?: (theme: string) => void;
/** 变更代码块主题时触发 */
changeCodeBlockTheme?: ( theme: string ) => void;
changeCodeBlockTheme?: (theme: string) => void;
};
/** 预览区域配置 */
previewer: CherryPreviewerOptions;
Expand Down Expand Up @@ -271,10 +270,7 @@ export interface CherryPreviewerOptions {

export type CherryToolbarSeparator = '|';

export type CherryCustomToolbar = string;
RSS1102 marked this conversation as resolved.
Show resolved Hide resolved

export type CherryDefaultToolbar =
// | CherryToolbarSeparator
| 'audio'
| 'barTable'
| 'bold'
Expand Down Expand Up @@ -390,13 +386,12 @@ export interface CherryToolbarsOptions<F extends CherryToolbarsCustomType = Cher
*/
theme?: 'light' | 'dark';
toolbar?:
| (CherryCustomToolbar |
CherryDefaultBubbleToolbar |
| (CherryDefaultBubbleToolbar |
CherryDefaultToolbar |
{ [K in keyof Partial<F['CustomMenuType']> | CherryDefaultToolbar]?: (keyof F['CustomMenuType'] | CherryDefaultToolbar)[] })[]
{ [K in (keyof Partial<F['CustomMenuType']>) | CherryDefaultToolbar]?: (keyof F['CustomMenuType'] | CherryDefaultToolbar)[] })[]
RSS1102 marked this conversation as resolved.
Show resolved Hide resolved
| false;
toolbarRight?:
| (CherryCustomToolbar | CherryDefaultBubbleToolbar | CherryDefaultToolbar)[]
| (CherryDefaultBubbleToolbar | CherryDefaultToolbar)[]
| false;
/** 是否展示悬浮目录 */
toc?: false | {
Expand Down Expand Up @@ -433,7 +428,7 @@ export interface CherryToolbarsOptions<F extends CherryToolbarsCustomType = Cher
shortcutKeySettings?: {
/** 是否替换已有的快捷键, true: 替换默认快捷键; false: 会追加到默认快捷键里,相同的shortcutKey会覆盖默认的 */
isReplace?: boolean,
shortcutKeyMap?: { [shortcutKey:string]: ShortcutKeyMapStruct};
shortcutKeyMap?: { [shortcutKey: string]: ShortcutKeyMapStruct };
};
/** 一些按钮的配置信息 */
config?: CherryToolbarConfig;
Expand Down
Loading