From 683fe00d86c8ba4020ebd35cd358960bc49dc6c2 Mon Sep 17 00:00:00 2001
From: clinfc <1962109568@qq.com>
Date: Tue, 3 Nov 2020 19:48:36 +0800
Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E5=A4=9A=E5=AE=9E=E4=BE=8B=20disabl?=
=?UTF-8?q?e=20=E5=BC=82=E5=B8=B8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/editor/disable/index.ts | 70 ++++++++++++++++++++-----------------
src/editor/index.ts | 26 ++++++--------
2 files changed, 49 insertions(+), 47 deletions(-)
diff --git a/src/editor/disable/index.ts b/src/editor/disable/index.ts
index d15af1f..7bffedc 100644
--- a/src/editor/disable/index.ts
+++ b/src/editor/disable/index.ts
@@ -6,41 +6,47 @@ import Editor from '../index'
import $, { DomElement } from '../../utils/dom-core'
import '../../assets/style/disable.less'
-let isCurtain: Boolean = false // 避免重复生成幕布
-let $contentDom: DomElement
-let $menuDom: DomElement
+export default function disableInit(editor: Editor) {
+ let isCurtain: Boolean = false // 避免重复生成幕布
+ let $contentDom: DomElement
+ let $menuDom: DomElement
-// 创建幕布
-function disable(editor: Editor) {
- if (isCurtain) return
- // 隐藏编辑区域
- editor.$textElem.hide()
- // 生成div 渲染编辑内容
- let textContainerZindexValue = editor.zIndex.get('textContainer')
- const content = editor.txt.html()
- $contentDom = $(
- `
+ // 禁用期间,通过 js 修改内容后,刷新内容
+ editor.txt.eventHooks.changeEvents.push(function () {
+ if (isCurtain) {
+ $contentDom.find('.w-e-content-preview').html(editor.$textElem.html())
+ }
+ })
+
+ // 创建幕布
+ function disable() {
+ if (isCurtain) return
+ // 隐藏编辑区域
+ editor.$textElem.hide()
+ // 生成div 渲染编辑内容
+ let textContainerZindexValue = editor.zIndex.get('textContainer')
+ const content = editor.txt.html()
+ $contentDom = $(
+ `
`
- )
- editor.$textContainerElem.append($contentDom)
- // 生成div 菜单膜布
- let menuZindexValue = editor.zIndex.get('menu')
- $menuDom = $(``)
- editor.$toolbarElem.append($menuDom)
- isCurtain = true
-}
+ )
+ editor.$textContainerElem.append($contentDom)
+ // 生成div 菜单膜布
+ let menuZindexValue = editor.zIndex.get('menu')
+ $menuDom = $(``)
+ editor.$toolbarElem.append($menuDom)
+ isCurtain = true
+ }
-// 销毁幕布并显示可编辑区域
-function enable(editor: Editor) {
- if (!isCurtain) return
- $contentDom.remove()
- $menuDom.remove()
- editor.$textElem.show()
- isCurtain = false
-}
+ // 销毁幕布并显示可编辑区域
+ function enable() {
+ if (!isCurtain) return
+ $contentDom.remove()
+ $menuDom.remove()
+ editor.$textElem.show()
+ isCurtain = false
+ }
-export default {
- disable,
- enable,
+ return { disable, enable }
}
diff --git a/src/editor/index.ts b/src/editor/index.ts
index 605029e..ce5ee58 100644
--- a/src/editor/index.ts
+++ b/src/editor/index.ts
@@ -18,7 +18,7 @@ import initFullScreen, { setUnFullScreen, setFullScreen } from './init-fns/set-f
import ZIndex from './z-index'
import Change from './change/index'
import History from './history/index'
-import disable from './disable'
+import disableInit from './disable'
// 创建菜单的 class
import BtnMenu from '../menus/menu-constructors/BtnMenu'
@@ -66,6 +66,12 @@ class Editor {
// 实例销毁前需要执行的钩子集合
private beforeDestroyHooks: Function[] = []
+ /** 禁用api */
+ public disable: Function
+
+ /** 启用api */
+ public enable: Function
+
/**
* 构造函数
* @param toolbarSelector 工具栏 DOM selector
@@ -101,6 +107,10 @@ class Editor {
this.zIndex = new ZIndex()
this.change = new Change(this)
this.history = new History(this)
+
+ const { disable, enable } = disableInit(this)
+ this.disable = disable
+ this.enable = enable
}
/**
@@ -187,20 +197,6 @@ class Editor {
public unFullScreen(): void {
setUnFullScreen(this)
}
-
- /**
- * 禁用api
- */
- public disable(): void {
- disable.disable(this)
- }
-
- /**
- * 启用api
- */
- public enable(): void {
- disable.enable(this)
- }
}
export default Editor
From 298230449f15276975506fe1b54ee1abdad78e3d Mon Sep 17 00:00:00 2001
From: xiaokyo <904656778@qq.com>
Date: Thu, 5 Nov 2020 17:01:19 +0800
Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90setJSON?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
examples/getJSON.html | 13 +++++++++--
src/text/getHtmlByNodeList.ts | 41 +++++++++++++++++++++++++++++++++++
src/text/index.ts | 15 +++++++++++++
src/utils/dom-core.ts | 13 +++++++++++
4 files changed, 80 insertions(+), 2 deletions(-)
create mode 100644 src/text/getHtmlByNodeList.ts
diff --git a/examples/getJSON.html b/examples/getJSON.html
index 2b099c6..04e4926 100644
--- a/examples/getJSON.html
+++ b/examples/getJSON.html
@@ -1,5 +1,6 @@
+
@@ -7,6 +8,7 @@
+
wangEditor getJSON
@@ -15,16 +17,23 @@
我是一行文字
我是一行这里加粗文字
我是一行链接文字
-
+
+