浏览代码

:label: fix #60

Van 6 年之前
父节点
当前提交
3f3d0470ae
共有 8 个文件被更改,包括 411 次插入321 次删除
  1. 2 1
      CHANGELOG.md
  2. 357 255
      package-lock.json
  3. 10 10
      package.json
  4. 3 3
      src/ts/markdown/markdown-it-task.ts
  5. 2 2
      src/ts/markdown/render.ts
  6. 34 48
      src/ts/types/index.d.ts
  7. 1 0
      tsconfig.json
  8. 2 2
      webpack.config.js

+ 2 - 1
CHANGELOG.md

@@ -1,8 +1,9 @@
 ## Vditor change log
 
 
-### v1.4.5 / 2019-05-28
+### v1.4.6 / 2019-05-28
 
+* [60](https://github.com/b3log/vditor/issues/60) type 完善 `development`
 * [56](https://github.com/b3log/vditor/issues/56) 展现样式完善 `enhancement`
 * [55](https://github.com/b3log/vditor/issues/55) 如何设置图片上传的路径 `question`
 * [54](https://github.com/b3log/vditor/issues/54) 在使用Vditor时,如何做到支持粘贴图片的? `question`

文件差异内容过多而无法显示
+ 357 - 255
package-lock.json


+ 10 - 10
package.json

@@ -1,6 +1,6 @@
 {
   "name": "vditor",
-  "version": "1.4.5",
+  "version": "1.4.6",
   "cdn": "https://cdn.jsdelivr.net/npm",
   "description": "A markdown editor written in TypeScript",
   "author": " Vanessa <[email protected]> (http://vanessa.b3log.org)",
@@ -22,35 +22,35 @@
   },
   "devDependencies": {
     "@babel/core": "^7.4.4",
-    "@babel/preset-env": "^7.4.4",
+    "@babel/preset-env": "^7.4.5",
     "@types/jest": "^24.0.13",
     "@types/markdown-it": "0.0.7",
     "@types/puppeteer": "^1.12.4",
     "autoprefixer": "^9.5.1",
     "babel-loader": "^8.0.6",
-    "clean-webpack-plugin": "^2.0.2",
+    "clean-webpack-plugin": "^3.0.0",
     "copy-webpack-plugin": "^5.0.3",
     "css-loader": "^2.1.1",
     "file-loader": "^3.0.1",
     "html-loader": "^0.5.5",
     "html-webpack-plugin": "^3.2.0",
     "jest": "^24.8.0",
-    "mini-css-extract-plugin": "^0.6.0",
+    "mini-css-extract-plugin": "^0.7.0",
     "node-sass": "^4.12.0",
     "on-build-webpack": "^0.1.0",
     "optimize-css-assets-webpack-plugin": "^5.0.1",
     "postcss-loader": "^3.0.0",
-    "puppeteer": "^1.16.0",
+    "puppeteer": "^1.17.0",
     "sass-loader": "^7.1.0",
     "style-loader": "^0.23.1",
     "ts-jest": "^24.0.2",
-    "ts-loader": "^6.0.0",
-    "tslint": "^5.16.0",
-    "typescript": "^3.4.5",
-    "webpack": "^4.31.0",
+    "ts-loader": "^6.0.2",
+    "tslint": "^5.17.0",
+    "typescript": "^3.5.1",
+    "webpack": "^4.32.2",
     "webpack-bundle-analyzer": "^3.3.2",
     "webpack-cli": "^3.3.2",
-    "webpack-dev-server": "^3.3.1"
+    "webpack-dev-server": "^3.5.1"
   },
   "license": "MIT",
   "repository": {

+ 3 - 3
src/ts/markdown/markdown-it-task.ts

@@ -1,6 +1,6 @@
-export const task = (md: IMarkdownIt) => {
-    md.core.ruler.after("inline", "github-task-lists", (state: IMarkdownItState) => {
-        state.tokens.forEach((token: IMarkdownItToken, index: number) => {
+export const task = (md: markdownit) => {
+    md.core.ruler.after("inline", "github-task-lists", (state) => {
+        state.tokens.forEach((token, index: number) => {
             if (token.type === "inline" &&
                 (token.content.indexOf("[ ] ") === 0 || token.content.toLocaleLowerCase().indexOf("[x] ") === 0) &&
                 state.tokens[index - 1].type === "paragraph_open" &&

+ 2 - 2
src/ts/markdown/render.ts

@@ -9,7 +9,7 @@ export const markdownItRender = async (mdText: string, hljsStyle: string) => {
 
     const {default: MarkdownIt} = await import(/* webpackChunkName: "markdown-it" */ "markdown-it");
 
-    const options: IMarkdownItOptions = {
+    const options: markdownit.Options = {
         breaks: true,
         html: true,
         linkify: true,
@@ -38,7 +38,7 @@ const initMarkdownIt = async (vditor: IVditor, includeHljs: boolean) => {
 
     const {default: MarkdownIt} = await import(/* webpackChunkName: "markdown-it" */ "markdown-it");
 
-    const options: IMarkdownItOptions = {
+    const options: markdownit.Options = {
         breaks: true,
         html: true,
         linkify: true,

+ 34 - 48
src/ts/types/index.d.ts

@@ -1,7 +1,4 @@
-declare module "*.svg" {
-    const content: string;
-    export default content;
-}
+declare module "*.svg";
 
 declare module "*.png";
 
@@ -20,49 +17,6 @@ declare var webkitAudioContext: {
     new(contextOptions?: AudioContextOptions): AudioContext,
 };
 
-declare interface IMarkdownItOptions {
-    html: boolean;
-    linkify: boolean;
-    breaks: boolean;
-
-    highlight?(str: string, lang: string): string;
-}
-
-declare interface ITurndown {
-    prototype: {
-        escape(name: string): string,
-    };
-
-    new(): {
-        addRule(name: string, options: {}): void
-        use(plugin: ITurndown): void
-        turndown(text: string): string,
-    };
-}
-
-interface IMarkdownIt {
-    render?: (md: string) => string | undefined;
-    core?: {
-        ruler: {
-            after: (type: string, name: string, process: (state: IMarkdownItState) => void) => void,
-        },
-    };
-}
-
-interface IMarkdownItState {
-    tokens: IMarkdownItToken[];
-    Token: any;
-}
-
-interface IMarkdownItToken {
-    type: string;
-    attrIndex: (name: string) => number;
-    attrPush: (name: string[]) => void;
-    attrs: string[][];
-    content: string;
-    children: IMarkdownItToken[];
-}
-
 interface IHTMLInputEvent extends Event {
     target: HTMLInputElement & EventTarget;
 }
@@ -162,7 +116,7 @@ interface IVditor {
     mdTimeoutId: number;
     options: IOptions;
     originalInnerHTML: string;
-    markdownIt?: IMarkdownIt;
+    markdownIt?: markdownit;
     toolbar?: {
         elements?: { [key: string]: HTMLElement },
     };
@@ -192,3 +146,35 @@ interface IVditor {
         isUploading: boolean,
     };
 }
+declare class IVditorConstructor {
+
+    public static mathRender: (element: HTMLElement) => void;
+    public static mermaidRender: (element: HTMLElement) => void;
+    public static codeRender: (element: HTMLElement, lang: (keyof II18nLang)) => void;
+    public static md2html: (mdText: string, hljsStyle: string) => string;
+    public readonly version: string;
+    public vditor: IVditor;
+
+    public getValue: () => string;
+    public insertValue: (value: string) => void;
+    public focus: () => void;
+    public blur: () => void;
+    public enable: () => void;
+    public setSelection: (start: number, end: number) => void;
+    public getSelection: () => string;
+    public setValue: (text: string) => void;
+    public renderPreview: (value?: string) => void;
+    public getCursorPosition: () => {
+        left: number,
+        top: number,
+    };
+    public deleteValue: () => void;
+    public updateValue: () => string;
+    public isUploading: () => boolean;
+    public clearCache: () => void;
+    public disabledCache: () => void;
+    public enableCache: () => void;
+    public html2md: (value: string) => string;
+    public getHTML: (includeHljs?: boolean) => string;
+    constructor(options: IOptions)
+}

+ 1 - 0
tsconfig.json

@@ -8,6 +8,7 @@
       "dom",
       "es2015"
     ],
+    "moduleResolution": "node",
     "esModuleInterop": true,
     "typeRoots": [
       "./node_modules/@types"

+ 2 - 2
webpack.config.js

@@ -2,13 +2,13 @@
  * @fileoverview webpack.
  *
  * @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
- * @version 0.1.0.0, Jan 23, 2019
+ * @version 0.1.0.1, Jun 3, 2019
  */
 
 const path = require('path')
 const fs = require('fs')
 const webpack = require('webpack')
-const CleanWebpackPlugin = require('clean-webpack-plugin')
+const {CleanWebpackPlugin} = require('clean-webpack-plugin')
 const MiniCssExtractPlugin = require('mini-css-extract-plugin')
 const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
 const WebpackOnBuildPlugin = require('on-build-webpack')

部分文件因为文件数量过多而无法显示