This is an automated email from the ASF dual-hosted git repository.

wangzx pushed a commit to branch gh-pages
in repository https://gitbox.apache.org/repos/asf/echarts-examples.git


The following commit(s) were added to refs/heads/gh-pages by this push:
     new e781c8ac fix(editor): fix prettier can't be loaded beacause of the TS 
editor.
e781c8ac is described below

commit e781c8ac8a25ba03213d5d4631ca8fe00cb6b318
Author: plainheart <y...@all-my-life.cn>
AuthorDate: Thu Oct 20 12:49:22 2022 +0800

    fix(editor): fix prettier can't be loaded beacause of the TS editor.
---
 src/editor/CodeMonaco.vue |  1 +
 src/editor/Editor.vue     | 28 +++++++++++++++++++---------
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/src/editor/CodeMonaco.vue b/src/editor/CodeMonaco.vue
index 073eb642..66408cf7 100644
--- a/src/editor/CodeMonaco.vue
+++ b/src/editor/CodeMonaco.vue
@@ -155,6 +155,7 @@ export default {
       });
 
       this.loading = false;
+      this.$emit('ready');
     });
   },
 
diff --git a/src/editor/Editor.vue b/src/editor/Editor.vue
index f6bcba07..3e2135b5 100644
--- a/src/editor/Editor.vue
+++ b/src/editor/Editor.vue
@@ -76,8 +76,10 @@
                 </a>
                 <a
                   class="btn btn-sm format"
-                  @click="format"
                   :title="$t('editor.format')"
+                  :disabled="!formatterReady"
+                  :style="{ cursor: formatterReady ? '' : 'progress' }"
+                  @click="format"
                 >
                   <svg
                     xmlns="http://www.w3.org/2000/svg";
@@ -122,12 +124,9 @@
                 v-if="shared.typeCheck"
                 id="code-panel"
                 :initialCode="initialCode"
-              ></CodeMonaco>
-              <CodeAce
-                v-else
-                id="code-panel"
-                :initialCode="initialCode"
-              ></CodeAce>
+                @ready="prepareFormatter"
+              />
+              <CodeAce v-else id="code-panel" :initialCode="initialCode" />
             </el-main>
           </el-container>
         </el-tab-pane>
@@ -233,7 +232,9 @@ export default {
         minimal: false,
         esm: true,
         node: false // If is in node
-      }
+      },
+
+      formatterReady: false
     };
   },
 
@@ -281,7 +282,7 @@ export default {
       });
 
       // ensure prettier
-      formatCode(' ');
+      store.typeCheck || this.prepareFormatter();
     }
   },
 
@@ -416,6 +417,10 @@ export default {
       }
     },
     format() {
+      if (!this.formatterReady) {
+        console.warn('formatter is not ready yet!');
+        return;
+      }
       formatCode(store.sourceCode).then((code) => {
         if (
           code === this.initialCode &&
@@ -430,6 +435,11 @@ export default {
         });
       });
     },
+    prepareFormatter() {
+      return formatCode(' ').then(() => {
+        this.formatterReady = true;
+      });
+    },
     onPreviewReady() {
       this.updateTabContent(this.currentTab);
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org
For additional commands, e-mail: commits-h...@echarts.apache.org

Reply via email to