@itshixun/qckeditor-vue2 1.0.0
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/README.md +265 -0
- package/dist/index.css +4 -0
- package/dist/index.d.ts +369 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +509 -0
- package/dist/src/components/CKEditor.d.ts +74 -0
- package/dist/src/components/CKEditor.d.ts.map +1 -0
- package/dist/src/components/QCKClassic.d.ts +65 -0
- package/dist/src/components/QCKClassic.d.ts.map +1 -0
- package/dist/src/components/QCKContent.d.ts +54 -0
- package/dist/src/components/QCKContent.d.ts.map +1 -0
- package/dist/src/components/QCKEditorPro.d.ts +183 -0
- package/dist/src/components/QCKEditorPro.d.ts.map +1 -0
- package/dist/src/types.d.ts +21 -0
- package/dist/src/types.d.ts.map +1 -0
- package/package.json +54 -0
package/README.md
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
# @itshixun/qckeditor-vue2
|
|
2
|
+
|
|
3
|
+
Vue 2 组件库,用于 CKEditor 5 富文本编辑器。
|
|
4
|
+
|
|
5
|
+
**注意:这是 Vue 2 版本。如果你使用 Vue 3,请使用 `@itshixun/qckeditor-vue3`。**
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @itshixun/qckeditor-vue2
|
|
11
|
+
# 或
|
|
12
|
+
pnpm add @itshixun/qckeditor-vue2
|
|
13
|
+
# 或
|
|
14
|
+
yarn add @itshixun/qckeditor-vue2
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### 对等依赖
|
|
18
|
+
|
|
19
|
+
本库需要以下对等依赖:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install vue@^2.6.0 ckeditor5@>=42.0.0
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 使用
|
|
26
|
+
|
|
27
|
+
### 引入样式
|
|
28
|
+
|
|
29
|
+
在使用组件前,需要先引入 CKEditor 的样式文件:
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
import 'ckeditor5/ckeditor5.css';
|
|
33
|
+
import '@itshixun/qckeditor-vue2/dist/style.css';
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 基础编辑器(CKEditor)
|
|
37
|
+
|
|
38
|
+
底层 CKEditor 封装组件,支持任意 CKEditor 构建:
|
|
39
|
+
|
|
40
|
+
```vue
|
|
41
|
+
<template>
|
|
42
|
+
<CKEditor
|
|
43
|
+
v-model="content"
|
|
44
|
+
:editor="ClassicEditor"
|
|
45
|
+
:config="editorConfig"
|
|
46
|
+
@ready="onReady"
|
|
47
|
+
@input="onInput"
|
|
48
|
+
/>
|
|
49
|
+
</template>
|
|
50
|
+
|
|
51
|
+
<script>
|
|
52
|
+
import { ClassicEditor } from 'ckeditor5';
|
|
53
|
+
import { CKEditor } from '@itshixun/qckeditor-vue2';
|
|
54
|
+
import 'ckeditor5/ckeditor5.css';
|
|
55
|
+
|
|
56
|
+
export default {
|
|
57
|
+
components: {
|
|
58
|
+
CKEditor,
|
|
59
|
+
},
|
|
60
|
+
data() {
|
|
61
|
+
return {
|
|
62
|
+
content: '',
|
|
63
|
+
ClassicEditor,
|
|
64
|
+
editorConfig: {
|
|
65
|
+
toolbar: ['bold', 'italic', 'link', 'bulletedList', 'numberedList'],
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
methods: {
|
|
70
|
+
onReady(editor) {
|
|
71
|
+
console.log('Editor ready:', editor);
|
|
72
|
+
},
|
|
73
|
+
onInput(data, event, editor) {
|
|
74
|
+
console.log('Content changed:', data);
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
</script>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 经典编辑器(QCKClassic)
|
|
82
|
+
|
|
83
|
+
预配置的经典编辑器组件:
|
|
84
|
+
|
|
85
|
+
```vue
|
|
86
|
+
<template>
|
|
87
|
+
<QCKClassic v-model="content" :config="editorConfig" @ready="onReady" />
|
|
88
|
+
</template>
|
|
89
|
+
|
|
90
|
+
<script>
|
|
91
|
+
import { QCKClassic } from '@itshixun/qckeditor-vue2';
|
|
92
|
+
import 'ckeditor5/ckeditor5.css';
|
|
93
|
+
|
|
94
|
+
export default {
|
|
95
|
+
components: {
|
|
96
|
+
QCKClassic,
|
|
97
|
+
},
|
|
98
|
+
data() {
|
|
99
|
+
return {
|
|
100
|
+
content: '',
|
|
101
|
+
editorConfig: {
|
|
102
|
+
toolbar: ['bold', 'italic', 'link'],
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
},
|
|
106
|
+
methods: {
|
|
107
|
+
onReady(editor) {
|
|
108
|
+
console.log('Editor ready:', editor);
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
</script>
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### 专业版编辑器(QCKEditorPro)
|
|
116
|
+
|
|
117
|
+
点击激活的编辑器,提升页面性能:
|
|
118
|
+
|
|
119
|
+
```vue
|
|
120
|
+
<template>
|
|
121
|
+
<QCKEditorPro
|
|
122
|
+
v-model="content"
|
|
123
|
+
:config="editorConfig"
|
|
124
|
+
placeholder="点击编辑内容"
|
|
125
|
+
:min-height="100"
|
|
126
|
+
@ready="onReady"
|
|
127
|
+
/>
|
|
128
|
+
</template>
|
|
129
|
+
|
|
130
|
+
<script>
|
|
131
|
+
import { QCKEditorPro } from '@itshixun/qckeditor-vue2';
|
|
132
|
+
import 'ckeditor5/ckeditor5.css';
|
|
133
|
+
|
|
134
|
+
export default {
|
|
135
|
+
components: {
|
|
136
|
+
QCKEditorPro,
|
|
137
|
+
},
|
|
138
|
+
data() {
|
|
139
|
+
return {
|
|
140
|
+
content: '',
|
|
141
|
+
editorConfig: {
|
|
142
|
+
toolbar: ['bold', 'italic'],
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
},
|
|
146
|
+
methods: {
|
|
147
|
+
onReady(editor) {
|
|
148
|
+
console.log('Editor ready:', editor);
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
</script>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### 内容展示(QCKContent)
|
|
156
|
+
|
|
157
|
+
安全渲染编辑器内容:
|
|
158
|
+
|
|
159
|
+
```vue
|
|
160
|
+
<template>
|
|
161
|
+
<QCKContent :content="htmlContent" />
|
|
162
|
+
</template>
|
|
163
|
+
|
|
164
|
+
<script>
|
|
165
|
+
import { QCKContent } from '@itshixun/qckeditor-vue2';
|
|
166
|
+
import 'ckeditor5/ckeditor5.css';
|
|
167
|
+
|
|
168
|
+
export default {
|
|
169
|
+
components: {
|
|
170
|
+
QCKContent,
|
|
171
|
+
},
|
|
172
|
+
data() {
|
|
173
|
+
return {
|
|
174
|
+
htmlContent: '<p>Hello <strong>World</strong></p>',
|
|
175
|
+
};
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
</script>
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Props
|
|
182
|
+
|
|
183
|
+
### CKEditor
|
|
184
|
+
|
|
185
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
186
|
+
|------|------|--------|------|
|
|
187
|
+
| editor | Function | 必填 | CKEditor 构建类 |
|
|
188
|
+
| config | Object | {} | 编辑器配置 |
|
|
189
|
+
| tagName | String | 'div' | 渲染标签 |
|
|
190
|
+
| disabled | Boolean | false | 是否禁用 |
|
|
191
|
+
| disableTwoWayDataBinding | Boolean | false | 禁用双向绑定 |
|
|
192
|
+
| value / v-model | String | '' | 编辑器内容 |
|
|
193
|
+
|
|
194
|
+
### QCKClassic
|
|
195
|
+
|
|
196
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
197
|
+
|------|------|--------|------|
|
|
198
|
+
| config | Object | {} | 编辑器配置 |
|
|
199
|
+
| tagName | String | 'div' | 渲染标签 |
|
|
200
|
+
| disabled | Boolean | false | 是否禁用 |
|
|
201
|
+
| disableTwoWayDataBinding | Boolean | false | 禁用双向绑定 |
|
|
202
|
+
| value / v-model | String | '' | 编辑器内容 |
|
|
203
|
+
|
|
204
|
+
### QCKEditorPro
|
|
205
|
+
|
|
206
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
207
|
+
|------|------|--------|------|
|
|
208
|
+
| config | Object | {} | 编辑器配置 |
|
|
209
|
+
| content | String | - | 初始内容 |
|
|
210
|
+
| placeholder | String | '点击编辑内容' | 占位文本 |
|
|
211
|
+
| minHeight | Number | 95 | 最小高度(px) |
|
|
212
|
+
| height | Number | 0 | 固定高度(px) |
|
|
213
|
+
| fitHeight | Boolean | false | 适应父容器高度 |
|
|
214
|
+
| contentBgColor | String | 'rgb(0 0 0 / 2%)' | 背景色 |
|
|
215
|
+
| contentBgHoverColor | String | 'rgb(0 0 0 / 4%)' | 悬停背景色 |
|
|
216
|
+
| borderRadius | Number | 4 | 圆角大小 |
|
|
217
|
+
| sanitize | Boolean | true | 是否清洗 HTML |
|
|
218
|
+
| value / v-model | String | '' | 编辑器内容 |
|
|
219
|
+
|
|
220
|
+
### QCKContent
|
|
221
|
+
|
|
222
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
223
|
+
|------|------|--------|------|
|
|
224
|
+
| content | String | - | HTML 内容 |
|
|
225
|
+
| containerClass | String | '' | 容器类名 |
|
|
226
|
+
| sanitize | Boolean | true | 是否清洗 HTML |
|
|
227
|
+
| value / v-model | String | '' | 内容 |
|
|
228
|
+
|
|
229
|
+
## 事件
|
|
230
|
+
|
|
231
|
+
所有编辑器组件都支持以下事件:
|
|
232
|
+
|
|
233
|
+
| 事件 | 参数 | 说明 |
|
|
234
|
+
|------|------|------|
|
|
235
|
+
| ready | (editor) | 编辑器就绪 |
|
|
236
|
+
| destroy | - | 编辑器销毁 |
|
|
237
|
+
| blur | (event, editor) | 失去焦点 |
|
|
238
|
+
| focus | (event, editor) | 获得焦点 |
|
|
239
|
+
| input | (data, event, editor) | 内容变化 |
|
|
240
|
+
|
|
241
|
+
## 与 Vue 3 版本的区别
|
|
242
|
+
|
|
243
|
+
1. **组件注册**:Vue 2 需要手动在 `components` 选项中注册
|
|
244
|
+
2. **v-model**:Vue 2 使用 `value` prop 和 `input` 事件
|
|
245
|
+
3. **生命周期**:使用 `beforeDestroy` 替代 `beforeUnmount`
|
|
246
|
+
|
|
247
|
+
## 类型导出
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
import type { Props, ExtractEditorType } from '@itshixun/qckeditor-vue2';
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
## 注意事项
|
|
254
|
+
|
|
255
|
+
1. **CKEditor 授权**:本库使用 CKEditor 5 的 GPL 授权。如需商业使用,请购买 [CKEditor 商业授权](https://ckeditor.com/pricing/)。
|
|
256
|
+
|
|
257
|
+
2. **样式文件**:必须导入 `ckeditor5/ckeditor5.css` 以确保编辑器样式正确。
|
|
258
|
+
|
|
259
|
+
3. **HTML 清洗**:`QCKContent` 和 `QCKEditorPro` 默认开启 XSS 防护,会自动过滤危险标签和属性。
|
|
260
|
+
|
|
261
|
+
4. **Vue 版本**:本库支持 Vue 2.6+ 和 Vue 2.7。
|
|
262
|
+
|
|
263
|
+
## License
|
|
264
|
+
|
|
265
|
+
MIT
|