Browse Source

:art: preview

Van 6 years ago
parent
commit
2ab77e0bdb
5 changed files with 44 additions and 11 deletions
  1. 4 6
      demo/demo.js
  2. 4 2
      demo/index.html
  3. 8 1
      src/ts/markdown/index.ts
  4. 27 1
      webpack.config.js
  5. 1 1
      webpack.start.js

+ 4 - 6
demo/demo.js

@@ -1,7 +1,5 @@
-// webpack.demo.js
-import Vditor from '../src/index'
-// import Vditor from 'vditor'
-// import Vditor from '../dist/index.min'
+// import Vditor from '../src/index'
+import Vditor from '../dist/index.min'
 
 const vditor = new Vditor('vditor', {
   height: 200,
@@ -62,8 +60,8 @@ const vditor = new Vditor('vditor', {
       name: 'preview',
       tipPosition: 'ne',
     },
-    'br'
-    , {
+    'br',
+    {
       name: 'emoji',
       tail: '<a href="https://hacpai.com/settings/function" target="_blank">设置常用表情</a>',
     },

+ 4 - 2
demo/index.html

@@ -40,13 +40,15 @@
     <script src="dist/demo.js" defer></script>
     <!-- 静态文件引入文件 -->
     <!--<link href="../dist/index.classic.css" rel="stylesheet">-->
-    <!--<script src="../dist/index.min.js"></script>-->
-    <!--<script src="demo.js"></script>-->
+
 </head>
 <body>
 <h2>默认编辑器</h2>
 <div id="vditor2"></div>
 <h2>自定义编辑器</h2>
 <div id="vditor"></div>
+<!-- 静态文件引入文件 -->
+<!--<script src="../dist/index.min.js"></script>-->
+<!--<script src="demo.js"></script>-->
 </body>
 </html>

+ 8 - 1
src/ts/markdown/index.ts

@@ -18,7 +18,14 @@ export class Markdown {
 
         if (value) {
             this.element.innerHTML = value
-        } else if (vditor.options.preview.url) {
+            return
+        }
+
+        if (vditor.editor.element.value.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '') === '') {
+            return
+        }
+
+        if (vditor.options.preview.url) {
             clearTimeout(vditor.mdTimeoutId)
             vditor.mdTimeoutId = setTimeout(() => {
                 const xhr = new XMLHttpRequest()

+ 27 - 1
webpack.config.js

@@ -59,7 +59,7 @@ const baseConfig = [
       'index.min': './src/index.ts',
     },
     resolve: {
-      extensions: ['.ts', '.svg', 'png'],
+      extensions: ['.js', '.ts', '.svg', 'png'],
     },
     module: {
       rules: [
@@ -70,6 +70,32 @@ const baseConfig = [
             'file-loader',
           ],
         },
+        {
+          test: /\.js$/,
+          exclude: '/node_modules/',
+          use: {
+            loader: 'babel-loader',
+            options: {
+              presets: [
+                [
+                  '@babel/env',
+                  {
+                    targets: {
+                      browsers: [
+                        'last 2 Chrome major versions',
+                        'last 2 Firefox major versions',
+                        'last 2 Safari major versions',
+                        'last 2 Edge major versions',
+                        'last 2 iOS major versions',
+                        'last 2 ChromeAndroid major versions',
+                      ],
+                    },
+                  },
+                ],
+              ],
+            },
+          },
+        },
         {
           test: /\.ts$/,
           use: 'ts-loader',

+ 1 - 1
webpack.start.js

@@ -10,7 +10,7 @@ const path = require('path')
 module.exports = {
   mode: 'development',
   devServer: {
-    contentBase: path.join(__dirname, 'demo'),
+    contentBase: path.join(__dirname, '.'),
     port: 9000,
     proxy: {
       '/api': {