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(type): add key name declaration for custom toolbar #932

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Changes from all commits
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
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
Loading