@@ -88,6 +88,64 @@ export default defineComponent({
88
88
});
89
89
</script>
90
90
```
91
+ :::
92
+
93
+ ### 自定义工具栏
94
+
95
+ :::demo 自定义编辑器的工具栏
96
+
97
+ ``` vue
98
+ <template>
99
+ <d-editor-md v-model="content" :toolbar-config="toolbarConfig" :custom-toolbars="customToolbars"></d-editor-md>
100
+ </template>
101
+
102
+ <script>
103
+ import { defineComponent, ref } from 'vue';
104
+
105
+ export default defineComponent({
106
+ setup() {
107
+ const content = ref('');
108
+ const toolbarConfig = ['add',
109
+ ['undo', 'redo'],
110
+ ['h1', 'h2', 'bold', 'italic', 'strike', 'underline', 'color', 'font'],
111
+ ['ul', 'ol', 'checklist', 'code', 'link', 'image', 'table'],
112
+ 'fullscreen',
113
+ ];
114
+ const customToolbars = {
115
+ add: {
116
+ id: 'add',
117
+ name: '新增',
118
+ exitName: '新增',
119
+ type: 'button',
120
+ icon: `<span>+</span>`,
121
+ shortKey: 'ALT+K',
122
+ handler: () => {
123
+ console.log('自定义工具点击事件');
124
+ },
125
+ },
126
+ undo: {
127
+ id: 'undo',
128
+ name: '撤销',
129
+ exitName: '撤销',
130
+ type: 'button',
131
+ icon: `<svg width="16px" height="14px" viewBox="0 0 16 14">
132
+ <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
133
+ <g fill="#293040">
134
+ <path d="M11,5 C13.7614237,5 16,7.23857625 16,10 C16,12.7614237 13.7614237,15 11,15 L7,15 L7,14 L11,14 C13.209139,14 15,12.209139 15,10 C15,7.790861 13.209139,6 11,6 L5,6 L5,10 L0,5.5 L5,1 L5,5 L11,5 Z" id="路径"></path>
135
+ </g>
136
+ </g>
137
+ </svg>`,
138
+ shortKey: 'Ctrl+M',
139
+ handler: () => {
140
+ console.log('覆盖原有工具栏功能事件');
141
+ },
142
+ }
143
+ };
144
+ return { content, toolbarConfig, customToolbars };
145
+ },
146
+ });
147
+ </script>
148
+ ```
91
149
92
150
:::
93
151
@@ -629,7 +687,9 @@ Bob-->>John: Jolly good!
629
687
| placeholder | `string` | '' | 编辑器无内容是的提示信息 |
630
688
| fullscreen-z-index | `number` | 10 | 编辑器全屏状态的 z-index |
631
689
| image-upload-to-server | `boolean` | false | 是否打开图片自定义上传开关(打开后将将监听图片的复制,toolbar 图片功能上传,传出事件回调) |
632
- |editor-container-height|`number`|--|可选,编辑器内容区高度||
690
+ | editor-container-height| `number`|--|可选,编辑器内容区高度 ||
691
+ | toolbar-config | `Array(string)` |`[['undo', 'redo'],['h1', 'h2', 'bold', 'italic', 'strike', 'underline', 'color', 'font'],['ul', 'ol', 'checklist', 'code', 'link', 'image', 'table'],'fullscreen']`|展示在toolbar工具栏处的按钮,用[]包起来的表示是同一组,不同组的会有线隔开。也可以自定义,自定义时需要配置参数custom-toolbars ||
692
+ | custom-toolbars | {[IToolbarItemConfig](#itoolbaritemconfig)} |--|配置toolbar-config中对应按钮的具体设置 [自定义工具栏](#自定义工具栏) | |
633
693
634
694
### EditorMd 事件
635
695
@@ -696,3 +756,22 @@ export interface HintConfig {
696
756
[key : string ]: HintConfigItem ; // key为触发提示前缀配置
697
757
}
698
758
```
759
+
760
+
761
+ ### IToolbarItemConfig
762
+ ``` ts
763
+ export interface IToolbarItemConfig {
764
+ id: string ;
765
+ name? : string ;
766
+ exitName? : string ;
767
+ type? : ' button' | ' dropDown' ;
768
+ icon? : string ;
769
+ exitIcon? : string ;
770
+ template? : any ;
771
+ component? : any ;
772
+ shortKey? : string ;
773
+ params? : { [key : string ]: any };
774
+ handler? (editor ? : any , params ? : any ): void ;
775
+ }
776
+ const toolbars = Record < string , IToolbarItemConfig>
777
+ ```
0 commit comments