merge master

This commit is contained in:
wangfupeng 2020-06-28 15:11:25 +08:00
commit d45cf4ae67
8 changed files with 100 additions and 13 deletions

View File

@ -9,18 +9,18 @@ on:
- 'v*.*.*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
- run: npm ci
- run: npm test
# build:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - uses: actions/setup-node@v1
# with:
# node-version: 12
# - run: npm ci
# - run: npm test
publish-npm:
needs: build
# needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
@ -29,6 +29,8 @@ jobs:
node-version: 12
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm test
- run: npm run build --if-present
- run: npm publish --access=public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

View File

@ -5,4 +5,6 @@ doc/
docs/
examples/
test/
attachment/
TODO.md
ISSUE.md

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@wangeditor-team/we-next",
"version": "0.0.7",
"version": "0.0.9",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "@wangeditor-team/we-next",
"version": "0.0.7",
"version": "0.0.9",
"description": "wangEditor next",
"main": "dist/wangEditor.min.js",
"types": "dist/wangEditor.d.ts",

View File

@ -4,7 +4,7 @@
*/
export default {
menus: ['bold', 'head', 'link', 'underline', 'strikeThrough', 'fontStyle'],
menus: ['bold', 'head', 'link', 'italic', 'underline', 'strikeThrough', 'fontStyle'],
fontNames: ['宋体', '微软雅黑', 'Arial', 'Tahoma', 'Verdana'],

56
src/menus/italic/index.ts Normal file
View File

@ -0,0 +1,56 @@
/**
* @description
* @author liuwei
*/
import BtnMenu from '../menu-constructors/BtnMenu'
import $ from '../../utils/dom-core'
import Editor from '../../editor/index'
import { MenuActive } from '../menu-constructors/Menu'
class Italic extends BtnMenu implements MenuActive {
constructor(editor: Editor) {
const $elem = $(
`<div class="w-e-menu">
<i class="w-e-icon-italic"></i>
</div>`
)
super($elem, editor)
}
/**
*
*/
public clickHandler(): void {
const editor = this.editor
const isSelectEmpty = editor.selection.isSelectionEmpty()
if (isSelectEmpty) {
// 选区范围是空的,插入并选中一个“空白”
editor.selection.createEmptyRange()
}
// 执行 italic 命令
editor.cmd.do('italic')
if (isSelectEmpty) {
// 需要将选区范围折叠起来
editor.selection.collapseRange()
editor.selection.restoreSelection()
}
}
/**
*
*/
public tryChangeActive(): void {
const editor = this.editor
if (editor.cmd.queryCommandState('italic')) {
this.active()
} else {
this.unActive()
}
}
}
export default Italic

View File

@ -6,6 +6,7 @@
import Bold from './bold/index'
import Head from './head/index'
import Link from './link/index'
import Italic from './italic/index'
import Underline from './underline/index'
import StrikeThrough from './strike-through/index'
import FontStyle from './font-style/index'
@ -13,6 +14,7 @@ import FontStyle from './font-style/index'
export default {
bold: Bold,
head: Head,
italic: Italic,
link: Link,
underline: Underline,
strikeThrough: StrikeThrough,

25
test/menus/italic.test.ts Normal file
View File

@ -0,0 +1,25 @@
/**
* @description Italic test
* @author liuwei
*/
import createEditor from '../fns/create-editor'
import Editor from '../../src/editor'
import Italic from '../../src/menus/italic/index'
import mockCmdFn from '../fns/command-mock'
import { getMenuInstance } from '../fns/menus'
let editor: Editor
let italicMenu: Italic
test('斜体', () => {
editor = createEditor(document, 'div1') // 赋值给全局变量
// 找到 Italiic 菜单
italicMenu = getMenuInstance(editor, Italic) as Italic
// 执行点击事件,模拟斜体
mockCmdFn(document)
;(italicMenu as Italic).clickHandler()
expect(document.execCommand).toBeCalledWith('italic', false, undefined) // mock fn 被调用
})