Skip to content

Commit

Permalink
fix(type): add key name declaration for custom toolbar (#932)
Browse files Browse the repository at this point in the history
* fix(type): add key name declaration for custom toolbar

Added some usage notes

* chore: add custom toolbar type example
  • Loading branch information
RSS1102 authored Oct 23, 2024
1 parent 58d5725 commit ef7a946
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions types/cherry.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,61 @@ import SyntaxBase from '../src/core/SyntaxBase';
import { FormulaMenu } from '@/toolbars/BubbleFormula';

export interface CherryExternalsOptions {
[key: symbol]: any;
[key: string]: any;
}

/**
* 自定义toolbar键名[key]
*/
export interface CustomMenuType {
[key: string]: any;
}

type CherryToolbarsCustomType = {
CustomMenuType: CherryExternalsOptions
CustomMenuType: CustomMenuType
}

type CherryCustomOptions = {
CustomToolbar: CherryToolbarsCustomType
}


/**
* @description By by default, the types declared by Cherry markdown are supported.
* @description If you want to force the **custom toolbar** key type, please refer to the following.
* @example
* ```
* type CustomConfig = {
* CustomToolbar: {
* CustomMenuType: {
* customMenu_fileUpload: string
* },
* },
* }
*
* const cherryConfig: CherryOptions<CustomConfig> = {
* ...
* toolbars: {
* toolbar: [
* 'bold',
* 'italic',
* "customMenu_fileUpload",
* {
* customMenu_fileUpload: [
* 'image',
* 'audio',
* ],
* },
* 'settings',
* ],
* customMenu: {
* customMenu_fileUpload: customMenu_fileUpload,
* },
* }
* ```
* Among them, `customMenu` is the fixed attribute of the custom menu, and `customMenu_fileUpload` is the key name of the custom button
*/

export interface Cherry<T extends CherryCustomOptions = CherryCustomOptions> {
options: CherryOptions<T>;
}
Expand Down Expand Up @@ -532,6 +576,7 @@ export interface CherryToolbarsOptions<F extends CherryToolbarsCustomType = Cher
toolbar?:
| (CherryDefaultBubbleToolbar |
CherryDefaultToolbar |
keyof Partial<F['CustomMenuType']> |
{ [K in (keyof Partial<F['CustomMenuType']>) | CherryDefaultToolbar]?: (keyof F['CustomMenuType'] | CherryDefaultToolbar)[] })[]
| false;
toolbarRight?:
Expand Down

0 comments on commit ef7a946

Please sign in to comment.