From ef7a946fd70058fcd4007d6b96b79f71af340970 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=98=BF=E8=8F=9C=20Cai?= <jimmyrss1102@gmail.com>
Date: Wed, 23 Oct 2024 14:36:26 +0800
Subject: [PATCH] fix(type): add key name declaration for custom toolbar (#932)

* fix(type): add key name declaration for custom toolbar

Added some usage notes

* chore: add custom toolbar type example
---
 types/cherry.d.ts | 49 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 47 insertions(+), 2 deletions(-)

diff --git a/types/cherry.d.ts b/types/cherry.d.ts
index ccfecb65..5e80acdb 100644
--- a/types/cherry.d.ts
+++ b/types/cherry.d.ts
@@ -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>;
 }
@@ -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?: