├── .github └── workflows │ ├── build.yml │ └── npm-publish.yml ├── .gitignore ├── .npmignore ├── .release-it.js ├── .vscode └── settings.json ├── DEV.md ├── README-en.md ├── README.md ├── babel.config.json ├── build ├── config │ ├── common.js │ ├── dev.js │ └── prd.js └── create-rollup-config.js ├── example ├── App.vue ├── index.html ├── index.ts └── pages │ ├── Basic.vue │ ├── Simple.vue │ └── VModelHTML.vue ├── package.json ├── rollup.config.js ├── rollup.example.config.js ├── shims-vue.d.ts ├── src ├── components │ ├── Editor.vue │ └── Toolbar.vue └── index.ts ├── tsconfig.json └── yarn.lock /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build project 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'main' 7 | - 'master' 8 | - 'dev' 9 | - 'feature-*' 10 | - 'fix-*' 11 | - 'hotfix-*' 12 | - 'refactor-*' 13 | 14 | jobs: 15 | build: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - uses: actions/checkout@v2 19 | - uses: actions/setup-node@v1 20 | with: 21 | node-version: 14 22 | registry-url: https://registry.npmjs.org/ 23 | - run: yarn 24 | - run: yarn --version 25 | - run: node --version 26 | # - run: yarn test 27 | - run: yarn build 28 | -------------------------------------------------------------------------------- /.github/workflows/npm-publish.yml: -------------------------------------------------------------------------------- 1 | name: publish npm Package 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*.*.*' 7 | 8 | jobs: 9 | publish-npm: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v2 13 | - uses: actions/setup-node@v1 14 | with: 15 | node-version: 12 16 | registry-url: https://registry.npmjs.org/ 17 | - run: yarn 18 | # - run: yarn test 19 | - run: yarn build 20 | - run: npm publish --access=public 21 | env: 22 | NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | node_modules/ 3 | dist-example/ 4 | stats.html -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .github/ 2 | .vscode 3 | build/ 4 | doc/ 5 | docs/ 6 | example/ 7 | __tests__/ 8 | .release-it.js 9 | index.html 10 | tsconfig.json 11 | src/ -------------------------------------------------------------------------------- /.release-it.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | git: { 3 | tagName: 'v${version}', 4 | commitMessage: 'release: v${version}', 5 | requireCleanWorkingDir: false, 6 | requireBranch: 'main', 7 | }, 8 | hooks: { 9 | 'before:init': ['git pull origin main'], 10 | }, 11 | npm: { 12 | publish: false, 13 | }, 14 | prompt: { 15 | ghRelease: false, 16 | glRelease: false, 17 | publish: false, 18 | }, 19 | }; 20 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cSpell.words": [ 3 | "rollup", 4 | "wangeditor", 5 | "wangfupeng" 6 | ] 7 | } -------------------------------------------------------------------------------- /DEV.md: -------------------------------------------------------------------------------- 1 | # 开发文档 2 | 3 | ## 目录结构 4 | 5 | ```bash 6 | ├── __test__ # 测试文件 7 | ├── build # 构建工具配置文件 8 | ├── example # dev环境下的example 9 | ├── rollup.config.js # rollup打包主入口文件 10 | ├── rollup.example.config.js # example运行配置文件 11 | └── src 12 | ├── components 13 | │ ├── Editor.vue 14 | │ └── Toolbar.vue 15 | ├── utils 16 | └── index.ts 17 | ``` 18 | 19 | ## dev 本地开发 20 | 21 | `yarn dev` 启动本地服务,使用 src/App.vue 文件 22 | 23 | `yarn test` 单元测试,使用 test 目录 24 | 25 | ## build 构建 26 | 27 | `yarn build` 构建代码,使用 src 目录。 28 | 29 | ## release 发布 30 | 31 | `yarn release` 可触发 github actions 并发布 npm 32 | -------------------------------------------------------------------------------- /README-en.md: -------------------------------------------------------------------------------- 1 | # wangEditor for Vue 2 | 3 | [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/facebook/react/blob/main/LICENSE) [![npm](https://img.shields.io/npm/v/@wangeditor/editor-for-vue.svg)](https://www.npmjs.com/package/@wangeditor/editor-for-vue/v/next) [![build status](https://github.com/wangeditor-team/wangEditor-for-vue/actions/workflows/npm-publish.yml/badge.svg?branch=main)](https://github.com/wangeditor-team/wangEditor-for-vue/actions) 4 | 5 | [中文文档](./README.md) 6 | 7 | ## Introduction 8 | 9 | An out-of-the-box [Vue2 component](https://www.wangeditor.com/v5/for-frame.html#vue2) 10 | based on the [wangEditor 5](https://www.wangeditor.com/v5/for-frame.html#vue2) 11 | 12 | ## Installation 13 | 14 | ```shell 15 | yarn add @wangeditor/editor 16 | yarn add @wangeditor/editor-for-vue 17 | ``` 18 | 19 | ## Usage 20 | 21 | [Usage doc](https://www.wangeditor.com/en/v5/for-frame.html#vue2) 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # wangEditor for Vue 2 | 3 | [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/facebook/react/blob/main/LICENSE) [![npm](https://img.shields.io/npm/v/@wangeditor/editor-for-vue.svg)](https://www.npmjs.com/package/@wangeditor/editor-for-vue/v/next) [![build status](https://github.com/wangeditor-team/wangEditor-for-vue/actions/workflows/npm-publish.yml/badge.svg?branch=main)](https://github.com/wangeditor-team/wangEditor-for-vue/actions) 4 | 5 | [English documentation](./README-en.md) 6 | 7 | ## 介绍 8 | 9 | 基于 [wangEditor](https://www.wangeditor.com/) 封装的开箱即用的 [Vue2 组件](https://www.wangeditor.com/v5/for-frame.html#vue2) 10 | 11 | ## 安装 12 | 13 | ```shell 14 | yarn add @wangeditor/editor 15 | yarn add @wangeditor/editor-for-vue 16 | ``` 17 | 18 | ## 使用 19 | 20 | 参考[文档](https://www.wangeditor.com/v5/for-frame.html#vue2) 21 | -------------------------------------------------------------------------------- /babel.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | [ 4 | "@babel/preset-env", 5 | { 6 | "modules": false, 7 | "useBuiltIns": "usage", 8 | "corejs": 3, 9 | "targets": "ie 11" 10 | } 11 | ] 12 | ], 13 | "plugins": [ 14 | [ 15 | "@babel/plugin-transform-runtime", 16 | { 17 | "absoluteRuntime": false, 18 | "corejs": 3, 19 | "helpers": true, 20 | "regenerator": true, 21 | "useESModules": false 22 | } 23 | ] 24 | ] 25 | } -------------------------------------------------------------------------------- /build/config/common.js: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import commonjs from '@rollup/plugin-commonjs'; 3 | import json from '@rollup/plugin-json'; 4 | import nodeResolve from '@rollup/plugin-node-resolve'; 5 | import typescript from 'rollup-plugin-typescript2'; 6 | import replace from '@rollup/plugin-replace'; 7 | import peerDepsExternal from 'rollup-plugin-peer-deps-external'; 8 | import vuePlugin from 'rollup-plugin-vue'; 9 | 10 | export const extensions = ['.js', '.jsx', '.ts', '.tsx', '.vue']; 11 | 12 | export default { 13 | input: path.resolve(__dirname, './src/index.ts'), 14 | output: { 15 | globals: { 16 | vue: 'Vue', 17 | }, 18 | }, 19 | plugins: [ 20 | peerDepsExternal(), // 打包结果不包含 package.json 的 peerDependencies 21 | json({ 22 | compact: true, 23 | indent: ' ', 24 | preferConst: true, 25 | }), 26 | typescript({ 27 | clean: true, 28 | tsconfig: path.resolve(__dirname, './tsconfig.json'), 29 | }), 30 | nodeResolve({ 31 | browser: true, // 重要 32 | extensions, 33 | }), 34 | vuePlugin({ 35 | target: 'browser', 36 | }), 37 | commonjs(), 38 | replace({ 39 | 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV), 40 | preventAssignment: true, 41 | }), 42 | // del({ targets: 'dist/*' }), 43 | ], 44 | }; 45 | -------------------------------------------------------------------------------- /build/config/dev.js: -------------------------------------------------------------------------------- 1 | import postcss from 'rollup-plugin-postcss' 2 | import autoprefixer from 'autoprefixer' 3 | import commonConfig from './common' 4 | 5 | const { output, input, plugins = [], external } = commonConfig 6 | 7 | export default { 8 | input, 9 | output, 10 | external, 11 | plugins: [ 12 | ...plugins, 13 | postcss({ 14 | plugins: [autoprefixer()], 15 | extract: 'css/style.css', 16 | }), 17 | ], 18 | } 19 | -------------------------------------------------------------------------------- /build/config/prd.js: -------------------------------------------------------------------------------- 1 | import babel from '@rollup/plugin-babel'; 2 | import postcss from 'rollup-plugin-postcss'; 3 | import autoprefixer from 'autoprefixer'; 4 | import cssnano from 'cssnano'; 5 | import { terser } from 'rollup-plugin-terser'; 6 | import cleanup from 'rollup-plugin-cleanup'; 7 | import commonConfig from './common'; 8 | import { extensions } from './common'; 9 | 10 | const { input, output = {}, plugins = [] } = commonConfig; 11 | 12 | const finalPlugins = [ 13 | ...plugins, 14 | // babel({ 15 | // babelHelpers: 'runtime', 16 | // exclude: 'node_modules/**', 17 | // include: 'src/**', 18 | // extensions, 19 | // }), 20 | postcss({ 21 | plugins: [ 22 | autoprefixer(), 23 | cssnano(), // 压缩 css 24 | ], 25 | extract: 'css/style.css', 26 | }), 27 | cleanup({ 28 | comments: 'none', 29 | extensions: ['.ts', '.tsx'], 30 | }), 31 | terser(), // 压缩 js 32 | ]; 33 | 34 | export default { 35 | input, 36 | output: { 37 | sourcemap: true, 38 | 39 | ...output, 40 | }, 41 | external: ['vue', '@wangeditor/editor'], 42 | plugins: finalPlugins, 43 | }; 44 | -------------------------------------------------------------------------------- /build/create-rollup-config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @description 创建 rollup 配置 3 | * @author wangfupeng 4 | */ 5 | 6 | import { merge } from 'lodash' 7 | import { visualizer } from 'rollup-plugin-visualizer' 8 | import devConf from './config/dev' 9 | import prdConf from './config/prd' 10 | 11 | // 环境变量 12 | const ENV = process.env.NODE_ENV || 'production' 13 | const IS_SIZE_STATS = ENV.indexOf('size_stats') >= 0 // 分析包体积 14 | export const IS_DEV = ENV.indexOf('development') >= 0 15 | export const IS_PRD = ENV.indexOf('production') >= 0 16 | 17 | /** 18 | * 生成单个 rollup 配置 19 | * @param {object} customConfig { input, output, plugins ... } 20 | */ 21 | export function createRollupConfig(customConfig = {}) { 22 | const { input, output = {}, plugins = [] } = customConfig 23 | 24 | let baseConfig 25 | if (IS_PRD) { 26 | baseConfig = prdConf 27 | } else { 28 | baseConfig = devConf 29 | } 30 | 31 | if (IS_SIZE_STATS) { 32 | // 分析包体积。运行之后可查看 package 下的 `stats.html` 33 | plugins.push(visualizer()) 34 | } 35 | 36 | const config = { 37 | input: input ? input : baseConfig.input, 38 | output, 39 | plugins, 40 | } 41 | 42 | const res = merge({}, baseConfig, config) 43 | return res 44 | } 45 | -------------------------------------------------------------------------------- /example/App.vue: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | wangEditor vue demo 8 | 12 | 13 | 14 | 15 | 16 | 17 | 21 | 22 | 26 | 27 | 28 |
29 | 30 | 31 | -------------------------------------------------------------------------------- /example/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @description editor-for-vue example entry 3 | * @author wangfupeng 4 | */ 5 | 6 | import Vue from 'vue' 7 | import App from './App.vue' 8 | 9 | new Vue({ 10 | render: h => h(App), 11 | }).$mount('#App') 12 | -------------------------------------------------------------------------------- /example/pages/Basic.vue: -------------------------------------------------------------------------------- 1 | 142 | -------------------------------------------------------------------------------- /example/pages/Simple.vue: -------------------------------------------------------------------------------- 1 | 72 | -------------------------------------------------------------------------------- /example/pages/VModelHTML.vue: -------------------------------------------------------------------------------- 1 | 68 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@wangeditor/editor-for-vue", 3 | "version": "1.0.2", 4 | "description": "wangEditor component for vue2.x", 5 | "author": "wangfupeng1988 ", 6 | "contributors": [], 7 | "homepage": "https://github.com/wangeditor-team/we-2021#readme", 8 | "license": "MIT", 9 | "types": "dist/index.d.ts", 10 | "main": "dist/index.js", 11 | "module": "dist/index.esm.js", 12 | "browser": { 13 | "./dist/index.js": "./dist/index.js", 14 | "./dist/index.esm.js": "./dist/index.esm.js" 15 | }, 16 | "directories": { 17 | "lib": "dist", 18 | "test": "__tests__" 19 | }, 20 | "files": [ 21 | "dist" 22 | ], 23 | "keywords": [ 24 | "wangEditor", 25 | "富文本编辑器", 26 | "富文本", 27 | "vue2" 28 | ], 29 | "repository": { 30 | "type": "git", 31 | "url": "git+https://github.com/wangeditor-team/we-2021.git" 32 | }, 33 | "scripts": { 34 | "test": "jest", 35 | "test-c": "jest --coverage", 36 | "release": "release-it", 37 | "example": "cross-env NODE_ENV=development:example rollup -c rollup.example.config.js -w", 38 | "dev": "cross-env NODE_ENV=development rollup -c rollup.config.js", 39 | "dev-watch": "cross-env NODE_ENV=development rollup -c rollup.config.js -w", 40 | "build": "cross-env NODE_ENV=production rollup -c rollup.config.js", 41 | "dev-size-stats": "cross-env NODE_ENV=development:size_stats rollup -c rollup.config.js", 42 | "size-stats": "cross-env NODE_ENV=production:size_stats rollup -c rollup.config.js" 43 | }, 44 | "bugs": { 45 | "url": "https://github.com/wangeditor-team/we-2021/issues" 46 | }, 47 | "peerDependencies": { 48 | "@wangeditor/editor": ">=5.1.0", 49 | "vue": "^2.6.14" 50 | }, 51 | "devDependencies": { 52 | "@babel/core": "^7.16.0", 53 | "@babel/plugin-transform-runtime": "^7.16.0", 54 | "@babel/preset-env": "^7.16.0", 55 | "@rollup/plugin-babel": "^5.3.0", 56 | "@rollup/plugin-commonjs": "^21.0.1", 57 | "@rollup/plugin-json": "^4.1.0", 58 | "@rollup/plugin-node-resolve": "^13.0.6", 59 | "@rollup/plugin-replace": "^3.0.0", 60 | "@types/vue": "^2.0.0", 61 | "@vue/compiler-sfc": "^3.2.21", 62 | "@wangeditor/editor": "^5.1.1", 63 | "autoprefixer": "^10.4.0", 64 | "cross-env": "^7.0.3", 65 | "cssnano": "^5.0.10", 66 | "jest": "^27.3.1", 67 | "lodash": "^4.17.21", 68 | "postcss": "^8.3.11", 69 | "release-it": "^14.11.6", 70 | "rollup": "^2.59.0", 71 | "rollup-plugin-cleanup": "^3.2.1", 72 | "rollup-plugin-copy": "^3.4.0", 73 | "rollup-plugin-delete": "^2.0.0", 74 | "rollup-plugin-generate-html-template": "^1.7.0", 75 | "rollup-plugin-peer-deps-external": "^2.2.4", 76 | "rollup-plugin-postcss": "^4.0.1", 77 | "rollup-plugin-serve": "^1.1.0", 78 | "rollup-plugin-terser": "^7.0.2", 79 | "rollup-plugin-typescript2": "^0.30.0", 80 | "rollup-plugin-visualizer": "^5.5.0", 81 | "rollup-plugin-vue": "^6.0.0", 82 | "ts-jest": "^27.0.4", 83 | "tslib": "^2.3.0", 84 | "typescript": "^4.4.4", 85 | "vue-template-compiler": "^2.6.14" 86 | }, 87 | "dependencies": {} 88 | } 89 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import path from 'path' 2 | import { createRollupConfig, IS_PRD } from './build/create-rollup-config' 3 | import pkg from './package.json' 4 | 5 | const name = 'WangEditorForVue' 6 | const input = path.resolve(__dirname, './src', 'index.ts') 7 | 8 | const configList = [] 9 | 10 | // umd - 开发环境需要 CDN 引入方式来测试,所以优先输出 umd 11 | const umdConf = createRollupConfig({ 12 | input, 13 | output: { 14 | file: pkg.main, 15 | format: 'umd', 16 | name, 17 | }, 18 | }) 19 | configList.push(umdConf) 20 | 21 | if (IS_PRD) { 22 | // esm 23 | const esmConf = createRollupConfig({ 24 | input, 25 | output: { 26 | file: pkg.module, 27 | format: 'esm', 28 | name, 29 | }, 30 | }) 31 | configList.push(esmConf) 32 | } 33 | 34 | export default configList 35 | -------------------------------------------------------------------------------- /rollup.example.config.js: -------------------------------------------------------------------------------- 1 | import path from 'path' 2 | import htmlTemplate from 'rollup-plugin-generate-html-template' 3 | import serve from 'rollup-plugin-serve' 4 | import copy from 'rollup-plugin-copy' 5 | import del from 'rollup-plugin-delete' 6 | import devConfig from './build/config/dev' 7 | import { merge } from 'lodash' 8 | 9 | // 继续生成 rollup config 10 | const name = 'WangEditorForVue' 11 | const input = path.resolve(__dirname, './example', 'index.ts') 12 | const file = 'dist-example/index.js' 13 | const port = 8883 14 | 15 | const config = { 16 | input, 17 | output: { 18 | file, 19 | format: 'umd', 20 | name, 21 | }, 22 | plugins: [ 23 | serve({ 24 | // open: true, 25 | contentBase: ['dist-example'], 26 | port, 27 | onListening: function () { 28 | console.log(`\nExample is running on http://localhost:${port}/\n`) 29 | }, 30 | }), 31 | htmlTemplate({ 32 | template: 'example/index.html', 33 | target: 'dist-example/index.html', 34 | }), 35 | del({ targets: 'dist-example/*' }), 36 | ], 37 | } 38 | 39 | export default merge(devConfig, config) 40 | -------------------------------------------------------------------------------- /shims-vue.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*.vue' { 2 | import Vue from 'vue' 3 | export default Vue 4 | } 5 | -------------------------------------------------------------------------------- /src/components/Editor.vue: -------------------------------------------------------------------------------- 1 | 134 | -------------------------------------------------------------------------------- /src/components/Toolbar.vue: -------------------------------------------------------------------------------- 1 | 37 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @description editor-for-vue entry 3 | * @author wangfupeng 4 | */ 5 | 6 | import Editor from './components/Editor.vue' 7 | import Toolbar from './components/Toolbar.vue' 8 | 9 | export { Editor, Toolbar } 10 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES5", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "declaration": true, 7 | "strict": true, 8 | "jsx": "preserve", 9 | "sourceMap": true, 10 | "resolveJsonModule": true, 11 | "esModuleInterop": true, 12 | "lib": ["esnext", "dom"] 13 | }, 14 | "exclude": ["node_modules", "build", "__tests__", "dist", "dist-example", "example", "rollup.*"] 15 | } 16 | --------------------------------------------------------------------------------