@lambo-design/wang-editor 2.0.0-beta.4 → 2.0.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -4
- package/src/index.vue +15 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lambo-design/wang-editor",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "lambo",
|
|
@@ -10,12 +10,13 @@
|
|
|
10
10
|
"registry": "https://registry.npmjs.org/"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
|
-
"@lambo-design/core": "^4.7.1-beta.
|
|
14
|
-
"@lambo-design/shared": "^1.0.0-beta.
|
|
13
|
+
"@lambo-design/core": "^4.7.1-beta.183",
|
|
14
|
+
"@lambo-design/shared": "^1.0.0-beta.379"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@wangeditor/editor": "5.1.23",
|
|
18
|
-
"@wangeditor/editor-for-vue": "^1.0.2"
|
|
18
|
+
"@wangeditor/editor-for-vue": "^1.0.2",
|
|
19
|
+
"xss": "^1.0.15"
|
|
19
20
|
},
|
|
20
21
|
"scripts": {
|
|
21
22
|
"release": "pnpm release-beta && git push --follow-tags && pnpm re-publish",
|
package/src/index.vue
CHANGED
|
@@ -24,6 +24,7 @@ import {oneOf} from '@lambo-design/shared/utils/platform';
|
|
|
24
24
|
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
|
|
25
25
|
import '@wangeditor/editor/dist/css/style.css'
|
|
26
26
|
|
|
27
|
+
import xss from 'xss';
|
|
27
28
|
export default {
|
|
28
29
|
name: 'LamboWangEditor',
|
|
29
30
|
components: { Editor, Toolbar },
|
|
@@ -153,23 +154,32 @@ export default {
|
|
|
153
154
|
},
|
|
154
155
|
methods: {
|
|
155
156
|
setHtml(val) {
|
|
157
|
+
let htmlVal = xss(val)
|
|
156
158
|
if (this.editor) {
|
|
157
|
-
this.editor.setHtml(
|
|
159
|
+
this.editor.setHtml(htmlVal)
|
|
158
160
|
} else {
|
|
159
161
|
// 编辑器尚未初始化时的处理
|
|
160
162
|
console.warn('Editor not initialized yet, queuing the content update...');
|
|
161
163
|
// 可以考虑缓存内容,等待编辑器初始化后设置
|
|
162
|
-
this.pendingContent =
|
|
164
|
+
this.pendingContent = htmlVal;
|
|
163
165
|
}
|
|
164
166
|
},
|
|
165
167
|
handleChange(editor) {
|
|
166
168
|
const html = editor.getHtml();
|
|
167
169
|
const text = editor.getText();
|
|
170
|
+
|
|
171
|
+
// 判断是否为空内容
|
|
172
|
+
const isEmpty = html === '<p><br></p>' || html.trim() === '';
|
|
173
|
+
|
|
174
|
+
// 如果为空,返回空字符串;否则返回原始 HTML 或文本
|
|
175
|
+
const finalValue = isEmpty ? '' : (this.valueType === 'html' ? html : text);
|
|
176
|
+
|
|
168
177
|
if (this.cache) {
|
|
169
|
-
localStorage.editorCache =
|
|
178
|
+
localStorage.editorCache = finalValue;
|
|
170
179
|
}
|
|
171
|
-
|
|
172
|
-
this.$emit('
|
|
180
|
+
|
|
181
|
+
this.$emit('input', finalValue);
|
|
182
|
+
this.$emit('on-change', finalValue, text);
|
|
173
183
|
},
|
|
174
184
|
onCreated(editor) {
|
|
175
185
|
this.editor = Object.seal(editor) // 一定要用 Object.seal() ,否则会报错
|