@chenyomi/leafer-htmltext-edit 2.0.3 → 2.1.3
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 +380 -210
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.mjs +4 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,19 +7,25 @@
|
|
|
7
7
|
<img src="https://img.shields.io/badge/TypeScript-Ready-blue.svg" alt="TypeScript">
|
|
8
8
|
</p>
|
|
9
9
|
|
|
10
|
-
一个强大的 Leafer UI
|
|
10
|
+
一个强大的 Leafer UI 富文本编辑器插件,集成 Quill 2.0,支持 HTML 文本编辑和丰富的文本样式控制。
|
|
11
11
|
|
|
12
12
|
## ✨ 特性
|
|
13
13
|
|
|
14
|
+
- 🎨 **富文本编辑** - 基于 Quill 2.0,支持完整的富文本编辑功能
|
|
14
15
|
- 🔤 **多语言字体** - 支持自定义字体
|
|
15
16
|
- 📐 **文本样式** - 字体、大小、颜色、对齐、行高、字间距等全面控制
|
|
16
17
|
- 📝 **格式化工具** - 加粗、斜体、下划线、删除线、上下标
|
|
17
18
|
- 📋 **列表支持** - 有序列表、无序列表
|
|
18
19
|
- 🎯 **完美集成** - 无缝集成到 Leafer UI 生态系统
|
|
20
|
+
- 🔐 **授权管理** - 内置授权系统,本地开发不限制,上线有授权检测,需要联系作者
|
|
19
21
|
- 📦 **轻量级** - 代码混淆压缩,体积小,加载快
|
|
20
22
|
- 🔧 **TypeScript** - 完整的类型定义支持
|
|
21
23
|
- 🚀 **现代化构建** - ESM + CJS 双格式,支持 Tree Shaking
|
|
22
24
|
|
|
25
|
+
- [插件官网](https://chenyomi.github.io/leafer-htmltext-edit-website/)
|
|
26
|
+
- [在线演示](https://chenyomi.github.io/leafer-htmltext-edit-view/)
|
|
27
|
+
- [问题反馈](https://github.com/chenyomi/npm-chenyomi-leafer-htmltext-edit/issues)
|
|
28
|
+
|
|
23
29
|
## 📦 安装
|
|
24
30
|
|
|
25
31
|
```bash
|
|
@@ -41,195 +47,316 @@ yarn add @chenyomi/leafer-htmltext-edit
|
|
|
41
47
|
本插件需要以下依赖(请确保已安装):
|
|
42
48
|
|
|
43
49
|
```bash
|
|
44
|
-
npm install leafer-ui @leafer-ui/core @leafer-in/editor @leafer-in/html
|
|
50
|
+
npm install leafer-ui @leafer-ui/core @leafer-in/editor @leafer-in/html quill
|
|
45
51
|
```
|
|
46
52
|
|
|
47
53
|
## 🚀 快速开始
|
|
48
54
|
|
|
49
|
-
###
|
|
55
|
+
### Vite 项目配置
|
|
50
56
|
|
|
51
|
-
|
|
52
|
-
import { App } from 'leafer-ui'
|
|
53
|
-
import { Editor } from '@leafer-in/editor'
|
|
54
|
-
import { HtmlTextManage } from '@chenyomi/leafer-htmltext-edit'
|
|
57
|
+
为了确保插件正常工作,建议在 Vite 配置中添加以下设置:
|
|
55
58
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
tree: {},
|
|
60
|
-
editor: {}
|
|
61
|
-
})
|
|
59
|
+
```typescript
|
|
60
|
+
// vite.config.ts
|
|
61
|
+
import { defineConfig } from "vite";
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
export default defineConfig({
|
|
64
|
+
resolve: {
|
|
65
|
+
// 确保使用项目的依赖实例
|
|
66
|
+
dedupe: [
|
|
67
|
+
"@leafer-ui/core",
|
|
68
|
+
"@leafer-in/editor",
|
|
69
|
+
"@leafer-in/html",
|
|
70
|
+
"leafer-ui",
|
|
71
|
+
"quill",
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
optimizeDeps: {
|
|
75
|
+
// 排除插件的预构建
|
|
76
|
+
exclude: ["@chenyomi/leafer-htmltext-edit"],
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
```
|
|
65
80
|
|
|
66
|
-
|
|
67
|
-
const editor = new Editor({ app })
|
|
81
|
+
### Webpack 项目配置
|
|
68
82
|
|
|
69
|
-
|
|
83
|
+
```javascript
|
|
84
|
+
// webpack.config.js
|
|
85
|
+
module.exports = {
|
|
86
|
+
resolve: {
|
|
87
|
+
// 确保使用单一实例
|
|
88
|
+
alias: {
|
|
89
|
+
quill: require.resolve("quill"),
|
|
90
|
+
"@leafer-ui/core": require.resolve("@leafer-ui/core"),
|
|
91
|
+
"@leafer-in/editor": require.resolve("@leafer-in/editor"),
|
|
92
|
+
"@leafer-in/html": require.resolve("@leafer-in/html"),
|
|
93
|
+
"leafer-ui": require.resolve("leafer-ui"),
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
};
|
|
70
97
|
```
|
|
71
98
|
|
|
99
|
+
|
|
72
100
|
### 在 Vue 3 中使用
|
|
73
101
|
|
|
74
102
|
```vue
|
|
75
103
|
<template>
|
|
76
|
-
<div
|
|
104
|
+
<div id="leafer-view" style="width: 100vw; height: 100vh;"></div>
|
|
77
105
|
</template>
|
|
78
106
|
|
|
79
107
|
<script setup lang="ts">
|
|
80
|
-
import {
|
|
81
|
-
import { App } from
|
|
82
|
-
import
|
|
83
|
-
import {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
108
|
+
import { onMounted } from "vue";
|
|
109
|
+
import { App } from "leafer-ui";
|
|
110
|
+
import "leafer-editor";
|
|
111
|
+
import {
|
|
112
|
+
htmlTextManage,
|
|
113
|
+
setLicense,
|
|
114
|
+
setHTMLText,
|
|
115
|
+
HtmlText,
|
|
116
|
+
} from "@chenyomi/leafer-htmltext-edit";
|
|
117
|
+
// 1. 设置 License(必须在 init 之前)
|
|
118
|
+
const licenseKey = "授权请联系作者";
|
|
119
|
+
const success = setLicense(licenseKey);
|
|
120
|
+
|
|
121
|
+
if (!success) {
|
|
122
|
+
console.error("License validation failed");
|
|
123
|
+
// 可以显示错误提示给用户
|
|
124
|
+
}
|
|
125
|
+
onMounted(() => {
|
|
126
|
+
const leafer = new App({
|
|
127
|
+
view: "leafer-view",
|
|
128
|
+
fill: "#ffffff",
|
|
129
|
+
editor: {},
|
|
130
|
+
});
|
|
131
|
+
htmlTextManage.init(leafer);
|
|
132
|
+
let { width = 1200, height = 960 } = leafer;
|
|
133
|
+
const text_ = new HtmlText({
|
|
134
|
+
editOuter: "TextEditTool",
|
|
135
|
+
name: "Text",
|
|
136
|
+
x: width / 2 - 100,
|
|
137
|
+
y: height * 0.4,
|
|
138
|
+
editable: true,
|
|
139
|
+
draggable: true,
|
|
140
|
+
fontFamily: undefined,
|
|
141
|
+
fontSize: 30,
|
|
142
|
+
lineHeight: 1.5,
|
|
143
|
+
letterSpacing: 0,
|
|
144
|
+
textShadow: undefined,
|
|
145
|
+
alignContent: "start",
|
|
146
|
+
});
|
|
147
|
+
leafer.tree.add([text_]);
|
|
148
|
+
});
|
|
97
149
|
</script>
|
|
98
150
|
```
|
|
99
151
|
|
|
100
152
|
### 在 React 中使用
|
|
101
153
|
|
|
102
154
|
```tsx
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
import { Editor } from '@leafer-in/editor'
|
|
106
|
-
import { HtmlTextManage } from '@chenyomi/leafer-htmltext-edit'
|
|
107
|
-
|
|
108
|
-
function TextEditor() {
|
|
109
|
-
const canvasRef = useRef<HTMLDivElement>(null)
|
|
110
|
-
|
|
111
|
-
useEffect(() => {
|
|
112
|
-
if (!canvasRef.current) return
|
|
113
|
-
|
|
114
|
-
const app = new App({
|
|
115
|
-
view: canvasRef.current,
|
|
116
|
-
tree: {},
|
|
117
|
-
editor: {}
|
|
118
|
-
})
|
|
155
|
+
// 参考vue3 示例 懒得写demo了
|
|
156
|
+
```
|
|
119
157
|
|
|
120
|
-
|
|
121
|
-
new Editor({ app })
|
|
122
|
-
})
|
|
123
|
-
}, [])
|
|
158
|
+
### 在 Angular 中使用
|
|
124
159
|
|
|
125
|
-
|
|
126
|
-
|
|
160
|
+
```typescript
|
|
161
|
+
// 参考vue3 示例 懒得写demo了
|
|
127
162
|
```
|
|
128
163
|
|
|
129
164
|
## 📚 API 文档
|
|
130
165
|
|
|
131
166
|
### HtmlTextManage
|
|
132
167
|
|
|
133
|
-
|
|
168
|
+
单例模式的编辑器管理器,负责管理 Quill 实例和文本编辑。
|
|
134
169
|
|
|
135
|
-
####
|
|
170
|
+
#### 静态方法
|
|
136
171
|
|
|
137
172
|
##### `init(app: any): Promise<Quill>`
|
|
138
173
|
|
|
139
|
-
初始化 Quill
|
|
174
|
+
初始化 Quill 编辑器并绑定到 Leafer 应用。
|
|
140
175
|
|
|
141
176
|
```typescript
|
|
142
|
-
const quill = await HtmlTextManage.init(app)
|
|
177
|
+
const quill = await HtmlTextManage.init(app);
|
|
143
178
|
```
|
|
144
179
|
|
|
180
|
+
**参数:**
|
|
181
|
+
|
|
182
|
+
- `app` - Leafer App 实例
|
|
183
|
+
|
|
184
|
+
**返回:** Promise<Quill> - Quill 编辑器实例
|
|
185
|
+
|
|
145
186
|
##### `getQuill(): Quill`
|
|
146
187
|
|
|
147
188
|
获取 Quill 实例。
|
|
148
189
|
|
|
149
190
|
```typescript
|
|
150
|
-
const quill = HtmlTextManage.getQuill()
|
|
191
|
+
const quill = HtmlTextManage.getQuill();
|
|
151
192
|
```
|
|
152
193
|
|
|
194
|
+
**返回:** Quill - Quill 编辑器实例
|
|
195
|
+
|
|
153
196
|
##### `getCanvas(): any`
|
|
154
197
|
|
|
155
198
|
获取 Leafer App 实例。
|
|
156
199
|
|
|
157
200
|
```typescript
|
|
158
|
-
const app = HtmlTextManage.getCanvas()
|
|
201
|
+
const app = HtmlTextManage.getCanvas();
|
|
159
202
|
```
|
|
160
203
|
|
|
204
|
+
**返回:** App - Leafer 应用实例
|
|
205
|
+
|
|
161
206
|
##### `isMultiSelect(): boolean`
|
|
162
207
|
|
|
163
|
-
|
|
208
|
+
判断是否为多选状态(选中了多个对象)。
|
|
164
209
|
|
|
165
210
|
```typescript
|
|
166
211
|
if (HtmlTextManage.isMultiSelect()) {
|
|
167
|
-
console.log(
|
|
212
|
+
console.log("Multiple objects selected");
|
|
168
213
|
}
|
|
169
214
|
```
|
|
170
215
|
|
|
216
|
+
**返回:** boolean - 是否多选
|
|
217
|
+
|
|
171
218
|
##### `dateEdit(callback: (leaf: any) => void, level?: number, listNew?: any): void`
|
|
172
219
|
|
|
173
220
|
批量编辑选中的对象。
|
|
174
221
|
|
|
175
222
|
```typescript
|
|
176
223
|
HtmlTextManage.dateEdit((leaf) => {
|
|
177
|
-
leaf.fontSize = 20
|
|
178
|
-
leaf.fill =
|
|
179
|
-
})
|
|
224
|
+
leaf.fontSize = 20;
|
|
225
|
+
leaf.fill = "#ff0000";
|
|
226
|
+
});
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
**参数:**
|
|
230
|
+
|
|
231
|
+
- `callback` - 编辑回调函数,接收每个选中的对象
|
|
232
|
+
- `level?` - 可选,编辑层级
|
|
233
|
+
- `listNew?` - 可选,新对象列表
|
|
234
|
+
|
|
235
|
+
### 授权管理
|
|
236
|
+
|
|
237
|
+
插件内置授权系统,支持商业使用。
|
|
238
|
+
|
|
239
|
+
#### `setLicense(licenseKey: string): boolean`
|
|
240
|
+
|
|
241
|
+
设置授权密钥。
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
import { setLicense } from "@chenyomi/leafer-htmltext-edit";
|
|
245
|
+
|
|
246
|
+
const success = setLicense("your-license-key");
|
|
247
|
+
if (success) {
|
|
248
|
+
console.log("License activated successfully");
|
|
249
|
+
}
|
|
180
250
|
```
|
|
181
251
|
|
|
182
|
-
|
|
252
|
+
**参数:**
|
|
183
253
|
|
|
184
|
-
|
|
254
|
+
- `licenseKey` - 授权密钥字符串
|
|
255
|
+
|
|
256
|
+
**返回:** boolean - 是否成功激活
|
|
257
|
+
|
|
258
|
+
#### `checkLicense(): boolean`
|
|
259
|
+
|
|
260
|
+
检查授权状态。
|
|
185
261
|
|
|
186
262
|
```typescript
|
|
187
|
-
import {
|
|
263
|
+
import { checkLicense } from "@chenyomi/leafer-htmltext-edit";
|
|
188
264
|
|
|
189
|
-
|
|
190
|
-
|
|
265
|
+
if (checkLicense()) {
|
|
266
|
+
console.log("License is valid");
|
|
267
|
+
} else {
|
|
268
|
+
console.log("License is invalid or expired");
|
|
269
|
+
}
|
|
191
270
|
```
|
|
192
271
|
|
|
193
|
-
|
|
272
|
+
**返回:** boolean - 授权是否有效
|
|
194
273
|
|
|
195
|
-
|
|
274
|
+
#### `getLicenseInfo(): LicenseData | null`
|
|
275
|
+
|
|
276
|
+
获取授权信息。
|
|
196
277
|
|
|
197
278
|
```typescript
|
|
198
|
-
import {
|
|
279
|
+
import { getLicenseInfo } from "@chenyomi/leafer-htmltext-edit";
|
|
199
280
|
|
|
200
|
-
|
|
201
|
-
|
|
281
|
+
const info = getLicenseInfo();
|
|
282
|
+
if (info) {
|
|
283
|
+
console.log("License holder:", info.name);
|
|
284
|
+
console.log("Expires at:", info.expirationDate);
|
|
285
|
+
}
|
|
202
286
|
```
|
|
203
287
|
|
|
204
|
-
|
|
288
|
+
**返回:** LicenseData | null - 授权信息对象或 null
|
|
205
289
|
|
|
206
|
-
###
|
|
290
|
+
### HtmlText
|
|
291
|
+
|
|
292
|
+
自定义的 HTML 文本类,扩展自 Leafer 的文本对象。
|
|
207
293
|
|
|
208
294
|
```typescript
|
|
209
|
-
import {
|
|
295
|
+
import { HtmlText } from "@chenyomi/leafer-htmltext-edit";
|
|
210
296
|
|
|
211
|
-
//
|
|
212
|
-
|
|
297
|
+
// HtmlText 会自动注册到 Leafer 中
|
|
298
|
+
// 可以直接在 Leafer 中使用
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### 工具函数
|
|
302
|
+
|
|
303
|
+
#### `updataHtmlText(obj: any): void`
|
|
304
|
+
|
|
305
|
+
更新 HTML 文本对象。
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
import { updataHtmlText } from "@chenyomi/leafer-htmltext-edit";
|
|
309
|
+
|
|
310
|
+
updataHtmlText(textObject);
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
#### `setHTMLText(type: string, value: any, inner: any, editor: any, multi: boolean): void`
|
|
314
|
+
|
|
315
|
+
设置 HTML 文本属性。
|
|
316
|
+
|
|
317
|
+
```typescript
|
|
318
|
+
import { setHTMLText } from "@chenyomi/leafer-htmltext-edit";
|
|
213
319
|
|
|
214
320
|
// 设置字体大小
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
})
|
|
321
|
+
setHTMLText("fontSize", 24, null, editor, false);
|
|
322
|
+
```
|
|
218
323
|
|
|
219
|
-
|
|
220
|
-
HtmlTextManage.dateEdit((leaf) => {
|
|
221
|
-
leaf.fontFamily = 'Roboto'
|
|
222
|
-
})
|
|
324
|
+
## 🎨 使用示例
|
|
223
325
|
|
|
224
|
-
|
|
225
|
-
HtmlTextManage.dateEdit((leaf) => {
|
|
226
|
-
leaf.fill = '#ff0000'
|
|
227
|
-
})
|
|
326
|
+
### 设置文本样式
|
|
228
327
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
328
|
+
```typescript
|
|
329
|
+
import { setHTMLText } from "@chenyomi/leafer-htmltext-edit";
|
|
330
|
+
```
|
|
331
|
+
```html
|
|
332
|
+
<button @click="setHTMLText('bold')">加粗</button>
|
|
333
|
+
<button @click="setHTMLText('italic')">斜体</button>
|
|
334
|
+
<button @click="setHTMLText('underline')">下划线</button>
|
|
335
|
+
<button @click="setHTMLText('strike')">删除线</button>
|
|
336
|
+
<button @click="setHTMLText('textCase')">大小写</button>
|
|
337
|
+
<button @click="setHTMLText('script', 'super')">上标</button>
|
|
338
|
+
<button @click="setHTMLText('script', 'sub')">下标</button>
|
|
339
|
+
<button @click="setHTMLText('align', false)">左对齐</button>
|
|
340
|
+
<button @click="setHTMLText('align', 'center')">居中对齐</button>
|
|
341
|
+
<button @click="setHTMLText('align', 'right')">右对齐</button>
|
|
342
|
+
<button @click="setHTMLText('alignContent', 'start')">顶部对齐</button>
|
|
343
|
+
<button @click="setHTMLText('alignContent', 'center')">垂直居中</button>
|
|
344
|
+
<button @click="setHTMLText('alignContent', 'end')">底部对齐</button>
|
|
345
|
+
<button @click="setHTMLText('list', 'ordered')">有序列表</button>
|
|
346
|
+
<button @click="setHTMLText('list', 'bullet')">无序列表</button>
|
|
347
|
+
<button @click="setHTMLText('color', '#3CB72C')">#3CB72C</button>
|
|
348
|
+
<button @click="setHTMLText('color', '#000000')">#000000</button>
|
|
349
|
+
<button @click="setHTMLText('lineHeight', 1.5)">行高1.5</button>
|
|
350
|
+
<button @click="setHTMLText('lineHeight', 3)">行高3.0</button>
|
|
351
|
+
<button @click="setHTMLText('letterSpacing', 0)">字间距0</button>
|
|
352
|
+
<button @click="setHTMLText('letterSpacing', 3)">字间距3</button>
|
|
353
|
+
<button @click="setHTMLText('textShadow', '3px 3px 3px rgba(0, 0, 0, 0.5)')">
|
|
354
|
+
Shadow
|
|
355
|
+
</button>
|
|
356
|
+
<button @click="setHTMLText('textShadow', undefined)">无Shadow</button>
|
|
357
|
+
<button @click="changeFontFamily">字体</button>
|
|
358
|
+
<button @click="setHTMLText('fontSize', 100)">大字号</button>
|
|
359
|
+
<button @click="reload">重置</button>
|
|
233
360
|
```
|
|
234
361
|
|
|
235
362
|
### 批量编辑多个对象
|
|
@@ -238,103 +365,124 @@ HtmlTextManage.dateEdit((leaf) => {
|
|
|
238
365
|
// 当选中多个文本对象时
|
|
239
366
|
if (HtmlTextManage.isMultiSelect()) {
|
|
240
367
|
HtmlTextManage.dateEdit((leaf) => {
|
|
241
|
-
leaf.fontSize = 18
|
|
242
|
-
leaf.fontFamily =
|
|
243
|
-
leaf.fill =
|
|
244
|
-
|
|
368
|
+
leaf.fontSize = 18;
|
|
369
|
+
leaf.fontFamily = "Inter";
|
|
370
|
+
leaf.fill = "#333333";
|
|
371
|
+
leaf.textAlign = "center";
|
|
372
|
+
});
|
|
245
373
|
}
|
|
246
374
|
```
|
|
247
375
|
|
|
248
376
|
### 监听文本变化
|
|
249
377
|
|
|
250
378
|
```typescript
|
|
251
|
-
const quill = HtmlTextManage.getQuill()
|
|
379
|
+
const quill = HtmlTextManage.getQuill();
|
|
252
380
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
381
|
+
// 监听文本内容变化
|
|
382
|
+
quill.on("text-change", (delta, oldDelta, source) => {
|
|
383
|
+
console.log("Text changed:", delta);
|
|
384
|
+
console.log("Source:", source); // 'user' 或 'api'
|
|
385
|
+
});
|
|
256
386
|
|
|
257
|
-
|
|
387
|
+
// 监听选区变化
|
|
388
|
+
quill.on("selection-change", (range, oldRange, source) => {
|
|
258
389
|
if (range) {
|
|
259
|
-
console.log(
|
|
390
|
+
console.log("Selection:", range.index, range.length);
|
|
391
|
+
} else {
|
|
392
|
+
console.log("Editor lost focus");
|
|
260
393
|
}
|
|
261
|
-
})
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
// 监听编辑器变化
|
|
397
|
+
quill.on("editor-change", (eventName, ...args) => {
|
|
398
|
+
console.log("Editor event:", eventName);
|
|
399
|
+
});
|
|
262
400
|
```
|
|
263
401
|
|
|
264
|
-
|
|
402
|
+
### 格式化文本
|
|
265
403
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
### 西文字体
|
|
269
|
-
- **Roboto** - Google 设计的现代无衬线字体
|
|
270
|
-
- **Roboto Mono** - 等宽字体
|
|
271
|
-
- **Inter** - 现代 UI 字体
|
|
272
|
-
- **Open Sans** - 清晰易读
|
|
273
|
-
- **Montserrat** - 几何无衬线
|
|
274
|
-
- **Lato** - 人文主义无衬线
|
|
275
|
-
- **Poppins** - 几何无衬线
|
|
276
|
-
- **Arimo** - 无衬线字体
|
|
277
|
-
|
|
278
|
-
### 衬线字体
|
|
279
|
-
- **Merriweather** - 可读性强的衬线字体
|
|
280
|
-
- **Playfair Display** - 优雅的显示字体
|
|
281
|
-
- **Noto Serif** - Google Noto 衬线
|
|
282
|
-
- **Spectral** - 现代衬线字体
|
|
283
|
-
|
|
284
|
-
### 手写字体
|
|
285
|
-
- **Dancing Script** - 手写风格
|
|
286
|
-
|
|
287
|
-
### 中日韩字体
|
|
288
|
-
- **Noto Sans Simplified Chinese** - 思源黑体简体
|
|
289
|
-
- **Noto Serif Simplified Chinese** - 思源宋体简体
|
|
290
|
-
- **Noto Sans Traditional Chinese** - 思源黑体繁体
|
|
291
|
-
- **Noto Sans Hong Kong** - 思源黑体香港
|
|
292
|
-
- **Noto Serif Traditional Chinese** - 思源宋体繁体
|
|
293
|
-
- **Noto Serif Hong Kong** - 思源宋体香港
|
|
294
|
-
- **Noto Sans Japanese** - 思源黑体日文
|
|
295
|
-
- **Noto Sans Korean** - 思源黑体韩文
|
|
296
|
-
|
|
297
|
-
## ⚙️ 高级配置
|
|
404
|
+
```typescript
|
|
405
|
+
const quill = HtmlTextManage.getQuill();
|
|
298
406
|
|
|
299
|
-
|
|
407
|
+
// 加粗
|
|
408
|
+
quill.format("bold", true);
|
|
300
409
|
|
|
301
|
-
|
|
410
|
+
// 斜体
|
|
411
|
+
quill.format("italic", true);
|
|
412
|
+
|
|
413
|
+
// 下划线
|
|
414
|
+
quill.format("underline", true);
|
|
415
|
+
|
|
416
|
+
// 删除线
|
|
417
|
+
quill.format("strike", true);
|
|
418
|
+
|
|
419
|
+
// 上标
|
|
420
|
+
quill.format("script", "super");
|
|
421
|
+
|
|
422
|
+
// 下标
|
|
423
|
+
quill.format("script", "sub");
|
|
424
|
+
|
|
425
|
+
// 列表
|
|
426
|
+
quill.format("list", "ordered"); // 有序列表
|
|
427
|
+
quill.format("list", "bullet"); // 无序列表
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
### 插入内容
|
|
302
431
|
|
|
303
432
|
```typescript
|
|
304
|
-
|
|
305
|
-
|
|
433
|
+
const quill = HtmlTextManage.getQuill();
|
|
434
|
+
|
|
435
|
+
// 插入文本
|
|
436
|
+
quill.insertText(0, "Hello World!");
|
|
437
|
+
|
|
438
|
+
// 插入带格式的文本
|
|
439
|
+
quill.insertText(0, "Hello", { bold: true, color: "red" });
|
|
440
|
+
|
|
441
|
+
// 获取文本内容
|
|
442
|
+
const text = quill.getText();
|
|
443
|
+
|
|
444
|
+
// 获取 HTML 内容
|
|
445
|
+
const html = quill.root.innerHTML;
|
|
446
|
+
|
|
447
|
+
// 设置内容
|
|
448
|
+
quill.setContents([
|
|
449
|
+
{ insert: "Hello " },
|
|
450
|
+
{ insert: "World", attributes: { bold: true } },
|
|
451
|
+
{ insert: "\n" },
|
|
452
|
+
]);
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
## 🔤 支持的字体
|
|
456
|
+
|
|
457
|
+
### 自定义字体(重要‼️)
|
|
458
|
+
### 编辑器分为内部编辑器和外部编辑器
|
|
459
|
+
### 内部编辑器的字体要在当前项目加载好
|
|
460
|
+
### 外部编辑器的字体要在下面的方式传入base64用于显示Html转成Svg内嵌的字体
|
|
461
|
+
```typescript
|
|
462
|
+
import { HtmlTextManage } from "@chenyomi/leafer-htmltext-edit";
|
|
463
|
+
|
|
464
|
+
// 获取 Quill 实例
|
|
465
|
+
const quill = HtmlTextManage.getQuill();
|
|
466
|
+
|
|
467
|
+
const fontFamily = '"Dancing Script", cursive';
|
|
468
|
+
const fontBase64 = "字体的base64编码"
|
|
469
|
+
setHTMLText("font", fontFamily, fontBase64);
|
|
306
470
|
|
|
307
|
-
export default defineConfig({
|
|
308
|
-
resolve: {
|
|
309
|
-
// 确保使用项目的依赖实例
|
|
310
|
-
dedupe: [
|
|
311
|
-
'@leafer-ui/core',
|
|
312
|
-
'@leafer-in/editor',
|
|
313
|
-
'@leafer-in/html',
|
|
314
|
-
'leafer-ui',
|
|
315
|
-
'quill'
|
|
316
|
-
]
|
|
317
|
-
},
|
|
318
|
-
optimizeDeps: {
|
|
319
|
-
// 排除插件的预构建
|
|
320
|
-
exclude: ['@chenyomi/leafer-htmltext-edit']
|
|
321
|
-
}
|
|
322
|
-
})
|
|
323
471
|
```
|
|
324
472
|
|
|
325
|
-
### 自定义样式
|
|
326
473
|
|
|
327
|
-
|
|
474
|
+
### TypeScript 配置
|
|
328
475
|
|
|
329
|
-
|
|
330
|
-
/* 覆盖编辑器样式 */
|
|
331
|
-
#textInnerEditor {
|
|
332
|
-
/* 自定义样式 */
|
|
333
|
-
}
|
|
476
|
+
确保 `tsconfig.json` 包含正确的类型定义:
|
|
334
477
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
478
|
+
```json
|
|
479
|
+
{
|
|
480
|
+
"compilerOptions": {
|
|
481
|
+
"moduleResolution": "node",
|
|
482
|
+
"esModuleInterop": true,
|
|
483
|
+
"skipLibCheck": true,
|
|
484
|
+
"types": ["node"]
|
|
485
|
+
}
|
|
338
486
|
}
|
|
339
487
|
```
|
|
340
488
|
|
|
@@ -343,8 +491,8 @@ export default defineConfig({
|
|
|
343
491
|
### 克隆仓库
|
|
344
492
|
|
|
345
493
|
```bash
|
|
346
|
-
git clone https://github.com/
|
|
347
|
-
cd leafer-htmltext-
|
|
494
|
+
git clone https://github.com/chenyomi/leafer-htmltext-edit.git
|
|
495
|
+
cd leafer-htmltext-edit
|
|
348
496
|
```
|
|
349
497
|
|
|
350
498
|
### 安装依赖
|
|
@@ -359,22 +507,6 @@ npm install
|
|
|
359
507
|
# 生产构建(混淆压缩)
|
|
360
508
|
npm run build
|
|
361
509
|
|
|
362
|
-
# 开发构建(不混淆)
|
|
363
|
-
npm run build:dev
|
|
364
|
-
|
|
365
|
-
# 监听模式
|
|
366
|
-
npm run build:watch
|
|
367
|
-
```
|
|
368
|
-
|
|
369
|
-
### 本地测试
|
|
370
|
-
|
|
371
|
-
```bash
|
|
372
|
-
# 在插件目录
|
|
373
|
-
npm link
|
|
374
|
-
|
|
375
|
-
# 在你的项目目录
|
|
376
|
-
npm link @chenyomi/leafer-htmltext-edit
|
|
377
|
-
```
|
|
378
510
|
|
|
379
511
|
## 📝 常见问题
|
|
380
512
|
|
|
@@ -383,69 +515,107 @@ npm link @chenyomi/leafer-htmltext-edit
|
|
|
383
515
|
A: 插件的 CSS 会自动注入,无需手动导入。如果遇到样式问题,可以手动导入 Quill CSS:
|
|
384
516
|
|
|
385
517
|
```typescript
|
|
386
|
-
import
|
|
518
|
+
import "quill/dist/quill.core.css";
|
|
387
519
|
```
|
|
388
520
|
|
|
389
521
|
### Q: 为什么编辑器不显示?
|
|
390
522
|
|
|
391
523
|
A: 请确保:
|
|
524
|
+
|
|
392
525
|
1. 已正确安装所有 peer dependencies
|
|
393
|
-
2. 调用了 `HtmlTextManage.init(app)`
|
|
526
|
+
2. 调用了 `HtmlTextManage.init(app)` 并等待 Promise 完成
|
|
394
527
|
3. 创建了 `Editor` 实例
|
|
395
|
-
4. Vite 配置中添加了 `dedupe` 设置
|
|
528
|
+
4. Vite/Webpack 配置中添加了 `dedupe` 或 `alias` 设置
|
|
529
|
+
5. 检查浏览器控制台是否有错误信息
|
|
396
530
|
|
|
397
531
|
### Q: 支持哪些浏览器?
|
|
398
532
|
|
|
399
|
-
A:
|
|
533
|
+
A: 支持所有现代浏览器:
|
|
400
534
|
|
|
401
|
-
|
|
535
|
+
- Chrome 90+
|
|
536
|
+
- Firefox 88+
|
|
537
|
+
- Safari 14+
|
|
538
|
+
- Edge 90+
|
|
402
539
|
|
|
403
|
-
|
|
540
|
+
不支持 IE11 及更早版本。
|
|
404
541
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
542
|
+
### Q: 如何获取授权?
|
|
543
|
+
|
|
544
|
+
A: 请联系开发者获取商业授权密钥:
|
|
545
|
+
|
|
546
|
+
- Email: 408550179@qq.com
|
|
547
|
+
|
|
548
|
+
1. 使用 `build:watch` 模式开发,避免频繁重新构建
|
|
549
|
+
2. 大型文档建议分段加载
|
|
550
|
+
3. 避免在短时间内频繁调用 `dateEdit`
|
|
551
|
+
4. 使用防抖(debounce)处理高频事件
|
|
552
|
+
|
|
553
|
+
### Q: 如何处理中文输入法问题?
|
|
554
|
+
|
|
555
|
+
A: Quill 2.0 已经内置了对中文输入法的支持。如果遇到问题:
|
|
411
556
|
|
|
412
|
-
|
|
557
|
+
```typescript
|
|
558
|
+
const quill = HtmlTextManage.getQuill();
|
|
413
559
|
|
|
414
|
-
|
|
560
|
+
// 监听输入法组合
|
|
561
|
+
quill.keyboard.addBinding({
|
|
562
|
+
key: "Enter",
|
|
563
|
+
handler: function (range, context) {
|
|
564
|
+
// 自定义处理逻辑
|
|
565
|
+
},
|
|
566
|
+
});
|
|
567
|
+
```
|
|
415
568
|
|
|
416
569
|
## 🤝 贡献
|
|
417
570
|
|
|
418
571
|
欢迎提交 Issue 和 Pull Request!
|
|
419
572
|
|
|
573
|
+
### 贡献指南
|
|
574
|
+
|
|
420
575
|
1. Fork 本仓库
|
|
421
576
|
2. 创建你的特性分支 (`git checkout -b feature/AmazingFeature`)
|
|
422
577
|
3. 提交你的改动 (`git commit -m 'Add some AmazingFeature'`)
|
|
423
578
|
4. 推送到分支 (`git push origin feature/AmazingFeature`)
|
|
424
579
|
5. 开启一个 Pull Request
|
|
425
580
|
|
|
581
|
+
### 开发规范
|
|
582
|
+
|
|
583
|
+
- 遵循 TypeScript 最佳实践
|
|
584
|
+
- 添加必要的类型定义
|
|
585
|
+
- 编写清晰的注释
|
|
586
|
+
- 更新相关文档
|
|
587
|
+
- 确保所有测试通过
|
|
588
|
+
|
|
426
589
|
## 📄 许可证
|
|
427
590
|
|
|
428
591
|
本项目采用 [MIT](./LICENSE) 许可证。
|
|
429
592
|
|
|
593
|
+
### 商业使用
|
|
594
|
+
|
|
595
|
+
本插件支持商业使用,但需要获取授权密钥。请联系开发者获取授权。
|
|
596
|
+
|
|
430
597
|
## 👤 作者
|
|
431
598
|
|
|
432
599
|
**chenyomi**
|
|
433
600
|
|
|
434
|
-
- GitHub: [@chenyomi](https://github.com/yourusername)
|
|
435
601
|
- npm: [@chenyomi](https://www.npmjs.com/~chenyomi)
|
|
602
|
+
- Email: 408550179@qq.com
|
|
436
603
|
|
|
437
604
|
## 🙏 致谢
|
|
438
605
|
|
|
439
606
|
- [Leafer UI](https://www.leaferjs.com/) - 强大的 Canvas 渲染引擎
|
|
440
607
|
- [Quill](https://quilljs.com/) - 现代化的富文本编辑器
|
|
441
608
|
- [TypeScript](https://www.typescriptlang.org/) - JavaScript 的超集
|
|
609
|
+
- [Google Fonts](https://fonts.google.com/) - 优质的开源字体
|
|
442
610
|
|
|
443
611
|
## 📊 统计
|
|
444
612
|
|
|
445
|
-

|
|
446
|
-

|
|
614
|
+

|
|
615
|
+

|
|
616
|
+

|
|
617
|
+

|
|
448
618
|
|
|
449
619
|
---
|
|
450
620
|
|
|
451
|
-
如果这个项目对你有帮助,请给个 ⭐️ Star
|
|
621
|
+
如果这个项目对你有帮助,请给个 ⭐️ Star!你的支持是我们最大的动力!
|