浏览代码

:art: fix https://github.com/Vanessa219/vditor/issues/1627

Vanessa 1 年之前
父节点
当前提交
ba20e38fda
共有 6 个文件被更改,包括 27 次插入0 次删除
  1. 3 0
      CHANGELOG.md
  2. 1 0
      README.md
  3. 1 0
      README_en_US.md
  4. 4 0
      src/index.ts
  5. 17 0
      src/ts/toolbar/index.ts
  6. 1 0
      types/index.d.ts

+ 3 - 0
CHANGELOG.md

@@ -9,6 +9,7 @@
   * 添加 hljs.defaultLang
   * 添加 hljs.renderMenu
   * 添加 preview.render.media.enable
+  * 添加 updateToolbarConfig
 
 ### TODO
 
@@ -16,6 +17,8 @@
 
 ### v3.10.5 / 2024-05
 
+* [添加 `updateToolbarConfig` 方法](https://github.com/Vanessa219/vditor/issues/1627) `引入特性`
+
 ### v3.10.4 / 2024-04-16
 
 * [移动端支持划选阅读](https://github.com/Vanessa219/vditor/issues/1611) `改进功能`

+ 1 - 0
README.md

@@ -545,6 +545,7 @@ if (xhr.status === 200) {
 | hlCommentIds(ids: string[]) | 高亮评论 |
 | unHlCommentIds(ids: string[]) | 取消评论高亮 |
 | removeCommentIds(removeIds: string[]) | 删除评论 |
+| updateToolbarConfig(config: {hide?: boolean, pin?: boolean}) | 更新工具栏配置 |
 
 #### static methods
 

+ 1 - 0
README_en_US.md

@@ -498,6 +498,7 @@ xhr.send(JSON.stringify({url: src})); // src is the address of the image outside
 | hlCommentIds(ids: string[]) | Highlight comment by Ids |
 | unHlCommentIds(ids: string[]) | Cancel highlight comment by Ids |
 | removeCommentIds(removeIds: string[]) | Remove comment by Ids |
+| updateToolbarConfig(config: {hide?: boolean, pin?: boolean}) | Update toolbar config |
 
 #### static methods
 

+ 4 - 0
src/index.ts

@@ -102,6 +102,10 @@ class Vditor extends VditorMethod {
         tip.show(error, 0)
     }
 
+    public updateToolbarConfig(options: IToolbarConfig) {
+        this.vditor.toolbar.updateConfig(this.vditor, options);
+    }
+
     /** 设置主题 */
     public setTheme(
         theme: "dark" | "classic",

+ 17 - 0
src/ts/toolbar/index.ts

@@ -69,6 +69,23 @@ export class Toolbar {
         }
     }
 
+    public updateConfig(vditor: IVditor, options: IToolbarConfig) {
+        vditor.options.toolbarConfig = Object.assign({
+            hide: false,
+            pin: false,
+        }, options);
+        if (vditor.options.toolbarConfig.hide) {
+            this.element.classList.add("vditor-toolbar--hide");
+        } else {
+            this.element.classList.remove("vditor-toolbar--hide");
+        }
+        if (vditor.options.toolbarConfig.pin) {
+            this.element.classList.add("vditor-toolbar--pin");
+        } else {
+            this.element.classList.remove("vditor-toolbar--pin");
+        }
+    }
+
     private genItem(vditor: IVditor, menuItem: IMenuItem, index: number) {
         let menuItemObj;
         switch (menuItem.name) {

+ 1 - 0
types/index.d.ts

@@ -786,6 +786,7 @@ interface IVditor {
     toolbar?: {
         elements?: { [key: string]: HTMLElement },
         element?: HTMLElement,
+        updateConfig(vditor: IVditor, options: IToolbarConfig): void,
     };
     preview?: {
         element: HTMLElement,