@chenyomi/leafer-htmltext-edit 2.2.2 → 2.2.4

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.
Files changed (3) hide show
  1. package/README.md +4 -0
  2. package/README_EN.md +618 -0
  3. package/package.json +2 -1
package/README.md CHANGED
@@ -9,6 +9,8 @@
9
9
 
10
10
  一个强大的 Leafer UI 富文本编辑器插件,集成 Quill 2.0,支持 HTML 文本编辑和丰富的文本样式控制。
11
11
 
12
+ [English Document](./README_EN.md)
13
+
12
14
  ## ✨ 特性
13
15
 
14
16
  - 🎨 **富文本编辑** - 基于 Quill 2.0,支持完整的富文本编辑功能
@@ -529,6 +531,7 @@ A: 支持所有现代浏览器:
529
531
  A: 请联系开发者获取商业授权密钥:
530
532
 
531
533
  - Email: 408550179@qq.com
534
+ - TG: [https://t.me/Ccymmm](https://t.me/Ccymmm)
532
535
 
533
536
  1. 使用 `build:watch` 模式开发,避免频繁重新构建
534
537
  2. 大型文档建议分段加载
@@ -585,6 +588,7 @@ quill.keyboard.addBinding({
585
588
 
586
589
  - npm: [@chenyomi](https://www.npmjs.com/~chenyomi)
587
590
  - Email: 408550179@qq.com
591
+ - TG: [https://t.me/Ccymmm](https://t.me/Ccymmm)
588
592
 
589
593
  ## 🙏 致谢
590
594
 
package/README_EN.md ADDED
@@ -0,0 +1,618 @@
1
+ # Leafer HTMLText Editor
2
+
3
+ <p align="center">
4
+ <img src="https://img.shields.io/npm/v/@chenyomi/leafer-htmltext-edit.svg" alt="npm version">
5
+ <img src="https://img.shields.io/npm/dm/@chenyomi/leafer-htmltext-edit.svg" alt="npm downloads">
6
+ <img src="https://img.shields.io/npm/l/@chenyomi/leafer-htmltext-edit.svg" alt="license">
7
+ <img src="https://img.shields.io/badge/TypeScript-Ready-blue.svg" alt="TypeScript">
8
+ </p>
9
+
10
+ A powerful rich text editor plugin for Leafer UI, integrated with Quill 2.0, supporting HTML text editing and comprehensive text styling controls.
11
+
12
+ [中文文档](./README.md)
13
+
14
+ ## ✨ Features
15
+
16
+ - 🎨 **Rich Text Editing** - Based on Quill 2.0, supports full rich text editing capabilities
17
+ - 🔤 **Multi-language Fonts** - Supports custom fonts
18
+ - 📐 **Text Styling** - Comprehensive control over font, size, color, alignment, line height, letter spacing, and more
19
+ - 📝 **Formatting Tools** - Bold, italic, underline, strikethrough, superscript, subscript
20
+ - 📋 **List Support** - Ordered and unordered lists
21
+ - 🎯 **Perfect Integration** - Seamlessly integrates into the Leafer UI ecosystem
22
+ - 🔐 **License Management** - Built-in licensing system, no restrictions for local development, requires license for production
23
+ - 📦 **Lightweight** - Minified and obfuscated code, small size, fast loading
24
+ - 🔧 **TypeScript** - Full type definition support
25
+ - 🚀 **Modern Build** - ESM + CJS dual format, supports Tree Shaking
26
+
27
+ - [Official Website](https://chenyomi.github.io/leafer-htmltext-edit-website/)
28
+ - [Live Demo](https://chenyomi.github.io/leafer-htmltext-edit-view/)
29
+ - [Issue Tracker](https://github.com/chenyomi/leafer-htmltext-edit-view/issues)
30
+
31
+ ## 📦 Installation
32
+
33
+ ```bash
34
+ npm install @chenyomi/leafer-htmltext-edit
35
+ ```
36
+
37
+ Or using other package managers:
38
+
39
+ ```bash
40
+ # pnpm
41
+ pnpm add @chenyomi/leafer-htmltext-edit
42
+
43
+ # yarn
44
+ yarn add @chenyomi/leafer-htmltext-edit
45
+ ```
46
+
47
+ ### Peer Dependencies
48
+
49
+ This plugin requires the following dependencies (please ensure they are installed):
50
+
51
+ ```bash
52
+ npm install leafer-ui @leafer-ui/core @leafer-in/editor @leafer-in/html quill
53
+ ```
54
+
55
+ ## 🚀 Quick Start
56
+
57
+ ### Vite Project Configuration
58
+
59
+ To ensure the plugin works properly, it's recommended to add the following settings to your Vite configuration:
60
+
61
+ ```typescript
62
+ // vite.config.ts
63
+ import { defineConfig } from "vite";
64
+
65
+ export default defineConfig({
66
+ resolve: {
67
+ // Ensure using project's dependency instances
68
+ dedupe: [
69
+ "@leafer-ui/core",
70
+ "@leafer-in/editor",
71
+ "@leafer-in/html",
72
+ "leafer-ui",
73
+ "quill",
74
+ ],
75
+ },
76
+ optimizeDeps: {
77
+ // Exclude plugin from pre-bundling
78
+ exclude: ["@chenyomi/leafer-htmltext-edit"],
79
+ },
80
+ });
81
+ ```
82
+
83
+ ### Webpack Project Configuration
84
+
85
+ ```javascript
86
+ // webpack.config.js
87
+ module.exports = {
88
+ resolve: {
89
+ // Ensure single instance usage
90
+ alias: {
91
+ quill: require.resolve("quill"),
92
+ "@leafer-ui/core": require.resolve("@leafer-ui/core"),
93
+ "@leafer-in/editor": require.resolve("@leafer-in/editor"),
94
+ "@leafer-in/html": require.resolve("@leafer-in/html"),
95
+ "leafer-ui": require.resolve("leafer-ui"),
96
+ },
97
+ },
98
+ };
99
+ ```
100
+
101
+ ### Using in Vue 3
102
+
103
+ ```vue
104
+ <template>
105
+ <div id="leafer-view" style="width: 100vw; height: 100vh;"></div>
106
+ </template>
107
+
108
+ <script setup lang="ts">
109
+ import { onMounted } from "vue";
110
+ import { App } from "leafer-ui";
111
+ import "leafer-editor";
112
+ import {
113
+ htmlTextManage,
114
+ setLicense,
115
+ setHTMLText,
116
+ HtmlText,
117
+ } from "@chenyomi/leafer-htmltext-edit";
118
+
119
+ onMounted(async () => {
120
+ // 1. Set License (must be done before init)
121
+ const licenseKey = "Contact author for license";
122
+ const success = await setLicense(licenseKey);
123
+
124
+ if (!success) {
125
+ console.error("License validation failed");
126
+ // You can display an error message to the user
127
+ }
128
+
129
+ const leafer = new App({
130
+ view: "leafer-view",
131
+ fill: "#ffffff",
132
+ editor: {},
133
+ });
134
+
135
+ htmlTextManage.init(leafer);
136
+
137
+ let { width = 1200, height = 960 } = leafer;
138
+ const text_ = new HtmlText({
139
+ editOuter: "TextEditTool",
140
+ name: "Text",
141
+ x: width / 2 - 100,
142
+ y: height * 0.4,
143
+ editable: true,
144
+ draggable: true,
145
+ fontFamily: undefined,
146
+ fontSize: 30,
147
+ lineHeight: 1.5,
148
+ letterSpacing: 0,
149
+ textShadow: undefined,
150
+ alignContent: "start",
151
+ });
152
+
153
+ leafer.tree.add([text_]);
154
+ });
155
+ </script>
156
+ ```
157
+
158
+ ### Using in React
159
+
160
+ ```tsx
161
+ // Refer to Vue 3 example - similar implementation
162
+ ```
163
+
164
+ ### Using in Angular
165
+
166
+ ```typescript
167
+ // Refer to Vue 3 example - similar implementation
168
+ ```
169
+
170
+ ## 📚 API Documentation
171
+
172
+ ### HtmlTextManage
173
+
174
+ Singleton editor manager responsible for managing Quill instances and text editing.
175
+
176
+ #### Static Methods
177
+
178
+ ##### `init(app: any): Promise<Quill>`
179
+
180
+ Initialize Quill editor and bind to Leafer application.
181
+
182
+ ```typescript
183
+ const quill = await HtmlTextManage.init(app);
184
+ ```
185
+
186
+ **Parameters:**
187
+
188
+ - `app` - Leafer App instance
189
+
190
+ **Returns:** Promise<Quill> - Quill editor instance
191
+
192
+ ##### `getQuill(): Quill`
193
+
194
+ Get the Quill instance.
195
+
196
+ ```typescript
197
+ const quill = HtmlTextManage.getQuill();
198
+ ```
199
+
200
+ **Returns:** Quill - Quill editor instance
201
+
202
+ ##### `getCanvas(): any`
203
+
204
+ Get the Leafer App instance.
205
+
206
+ ```typescript
207
+ const app = HtmlTextManage.getCanvas();
208
+ ```
209
+
210
+ **Returns:** App - Leafer application instance
211
+
212
+ ##### `isMultiSelect(): boolean`
213
+
214
+ Check if multiple objects are selected.
215
+
216
+ ```typescript
217
+ if (HtmlTextManage.isMultiSelect()) {
218
+ console.log("Multiple objects selected");
219
+ }
220
+ ```
221
+
222
+ **Returns:** boolean - Whether multiple objects are selected
223
+
224
+ ##### `dateEdit(callback: (leaf: any) => void, level?: number, listNew?: any): void`
225
+
226
+ Batch edit selected objects.
227
+
228
+ ```typescript
229
+ HtmlTextManage.dateEdit((leaf) => {
230
+ leaf.fontSize = 20;
231
+ leaf.fill = "#ff0000";
232
+ });
233
+ ```
234
+
235
+ **Parameters:**
236
+
237
+ - `callback` - Edit callback function, receives each selected object
238
+ - `level?` - Optional, edit level
239
+ - `listNew?` - Optional, new object list
240
+
241
+ ### License Management
242
+
243
+ The plugin has a built-in licensing system for commercial use.
244
+
245
+ #### `setLicense(licenseKey: string): boolean`
246
+
247
+ Set the license key.
248
+
249
+ ```typescript
250
+ import { setLicense } from "@chenyomi/leafer-htmltext-edit";
251
+
252
+ const success = setLicense("your-license-key");
253
+ if (success) {
254
+ console.log("License activated successfully");
255
+ }
256
+ ```
257
+
258
+ **Parameters:**
259
+
260
+ - `licenseKey` - License key string
261
+
262
+ **Returns:** boolean - Whether activation was successful
263
+
264
+ #### `checkLicense(): boolean`
265
+
266
+ Check license status.
267
+
268
+ ```typescript
269
+ import { checkLicense } from "@chenyomi/leafer-htmltext-edit";
270
+
271
+ if (checkLicense()) {
272
+ console.log("License is valid");
273
+ } else {
274
+ console.log("License is invalid or expired");
275
+ }
276
+ ```
277
+
278
+ ### HtmlText
279
+
280
+ Custom HTML text class, extends Leafer's text object.
281
+
282
+ ```typescript
283
+ import { HtmlText } from "@chenyomi/leafer-htmltext-edit";
284
+
285
+ // HtmlText is automatically registered in Leafer
286
+ // Can be used directly in Leafer
287
+ ```
288
+
289
+ ### Utility Functions
290
+
291
+ #### `updataHtmlText(obj: any): void`
292
+
293
+ Update HTML text object.
294
+
295
+ ```typescript
296
+ import { updataHtmlText } from "@chenyomi/leafer-htmltext-edit";
297
+
298
+ updataHtmlText(textObject);
299
+ ```
300
+
301
+ #### `setHTMLText(type: string, value: any, inner: any, editor: any, multi: boolean): void`
302
+
303
+ Set HTML text properties.
304
+
305
+ ```typescript
306
+ import { setHTMLText } from "@chenyomi/leafer-htmltext-edit";
307
+
308
+ // Set font size
309
+ setHTMLText("fontSize", 24, null, editor, false);
310
+ ```
311
+
312
+ ## 🎨 Usage Examples
313
+
314
+ ### Setting Text Styles
315
+
316
+ ```typescript
317
+ import { setHTMLText } from "@chenyomi/leafer-htmltext-edit";
318
+ ```
319
+
320
+ ```html
321
+ <button @click="setHTMLText('bold')">Bold</button>
322
+ <button @click="setHTMLText('italic')">Italic</button>
323
+ <button @click="setHTMLText('underline')">Underline</button>
324
+ <button @click="setHTMLText('strike')">Strikethrough</button>
325
+ <button @click="setHTMLText('textCase')">Text Case</button>
326
+ <button @click="setHTMLText('script', 'super')">Superscript</button>
327
+ <button @click="setHTMLText('script', 'sub')">Subscript</button>
328
+ <button @click="setHTMLText('align', false)">Align Left</button>
329
+ <button @click="setHTMLText('align', 'center')">Align Center</button>
330
+ <button @click="setHTMLText('align', 'right')">Align Right</button>
331
+ <button @click="setHTMLText('alignContent', 'start')">Align Top</button>
332
+ <button @click="setHTMLText('alignContent', 'center')">Align Middle</button>
333
+ <button @click="setHTMLText('alignContent', 'end')">Align Bottom</button>
334
+ <button @click="setHTMLText('list', 'ordered')">Ordered List</button>
335
+ <button @click="setHTMLText('list', 'bullet')">Bullet List</button>
336
+ <button @click="setHTMLText('color', '#3CB72C')">#3CB72C</button>
337
+ <button @click="setHTMLText('color', '#000000')">#000000</button>
338
+ <button @click="setHTMLText('lineHeight', 1.5)">Line Height 1.5</button>
339
+ <button @click="setHTMLText('lineHeight', 3)">Line Height 3.0</button>
340
+ <button @click="setHTMLText('letterSpacing', 0)">Letter Spacing 0</button>
341
+ <button @click="setHTMLText('letterSpacing', 3)">Letter Spacing 3</button>
342
+ <button @click="setHTMLText('textShadow', '3px 3px 3px rgba(0, 0, 0, 0.5)')">
343
+ Shadow
344
+ </button>
345
+ <button @click="setHTMLText('textShadow', undefined)">No Shadow</button>
346
+ <button @click="changeFontFamily">Font Family</button>
347
+ <button @click="setHTMLText('fontSize', 100)">Large Font</button>
348
+ <button @click="reload">Reset</button>
349
+ ```
350
+
351
+ ### Batch Editing Multiple Objects
352
+
353
+ ```typescript
354
+ // When multiple text objects are selected
355
+ if (HtmlTextManage.isMultiSelect()) {
356
+ HtmlTextManage.dateEdit((leaf) => {
357
+ leaf.fontSize = 18;
358
+ leaf.fontFamily = "Inter";
359
+ leaf.fill = "#333333";
360
+ leaf.textAlign = "center";
361
+ });
362
+ }
363
+ ```
364
+
365
+ ### Listening to Text Changes
366
+
367
+ ```typescript
368
+ const quill = HtmlTextManage.getQuill();
369
+
370
+ // Listen to text content changes
371
+ quill.on("text-change", (delta, oldDelta, source) => {
372
+ console.log("Text changed:", delta);
373
+ console.log("Source:", source); // 'user' or 'api'
374
+ });
375
+
376
+ // Listen to selection changes
377
+ quill.on("selection-change", (range, oldRange, source) => {
378
+ if (range) {
379
+ console.log("Selection:", range.index, range.length);
380
+ } else {
381
+ console.log("Editor lost focus");
382
+ }
383
+ });
384
+
385
+ // Listen to editor changes
386
+ quill.on("editor-change", (eventName, ...args) => {
387
+ console.log("Editor event:", eventName);
388
+ });
389
+ ```
390
+
391
+ ### Formatting Text
392
+
393
+ ```typescript
394
+ const quill = HtmlTextManage.getQuill();
395
+
396
+ // Bold
397
+ quill.format("bold", true);
398
+
399
+ // Italic
400
+ quill.format("italic", true);
401
+
402
+ // Underline
403
+ quill.format("underline", true);
404
+
405
+ // Strikethrough
406
+ quill.format("strike", true);
407
+
408
+ // Superscript
409
+ quill.format("script", "super");
410
+
411
+ // Subscript
412
+ quill.format("script", "sub");
413
+
414
+ // Lists
415
+ quill.format("list", "ordered"); // Ordered list
416
+ quill.format("list", "bullet"); // Bullet list
417
+ ```
418
+
419
+ ### Inserting Content
420
+
421
+ ```typescript
422
+ const quill = HtmlTextManage.getQuill();
423
+
424
+ // Insert text
425
+ quill.insertText(0, "Hello World!");
426
+
427
+ // Insert formatted text
428
+ quill.insertText(0, "Hello", { bold: true, color: "red" });
429
+
430
+ // Get text content
431
+ const text = quill.getText();
432
+
433
+ // Get HTML content
434
+ const html = quill.root.innerHTML;
435
+
436
+ // Set content
437
+ quill.setContents([
438
+ { insert: "Hello " },
439
+ { insert: "World", attributes: { bold: true } },
440
+ { insert: "\n" },
441
+ ]);
442
+ ```
443
+
444
+ ## 🔤 Supported Fonts
445
+
446
+ ### Custom Fonts (IMPORTANT‼️)
447
+
448
+ ### The editor consists of internal and external editors
449
+
450
+ ### Internal editor fonts must be loaded in the current project
451
+
452
+ ### External editor fonts must be passed as base64 for displaying HTML converted to SVG with embedded fonts
453
+
454
+ ```typescript
455
+ import { HtmlTextManage } from "@chenyomi/leafer-htmltext-edit";
456
+
457
+ // Get Quill instance
458
+ const quill = HtmlTextManage.getQuill();
459
+
460
+ const fontFamily = '"Dancing Script", cursive';
461
+ const fontBase64 = "base64-encoded font data";
462
+ setHTMLText("font", fontFamily, fontBase64);
463
+ ```
464
+
465
+ ### TypeScript Configuration
466
+
467
+ Ensure your `tsconfig.json` includes the correct type definitions:
468
+
469
+ ```json
470
+ {
471
+ "compilerOptions": {
472
+ "moduleResolution": "node",
473
+ "esModuleInterop": true,
474
+ "skipLibCheck": true,
475
+ "types": ["node"]
476
+ }
477
+ }
478
+ ```
479
+
480
+ ## 🔧 Development
481
+
482
+ ### Clone Repository
483
+
484
+ ```bash
485
+ git clone https://github.com/chenyomi/leafer-htmltext-edit.git
486
+ cd leafer-htmltext-edit
487
+ ```
488
+
489
+ ### Install Dependencies
490
+
491
+ ```bash
492
+ npm install
493
+ ```
494
+
495
+ ### Build
496
+
497
+ ```bash
498
+ # Production build (minified and obfuscated)
499
+ npm run build
500
+ ```
501
+
502
+ ## 📝 FAQ
503
+
504
+ ### Q: How to import CSS styles?
505
+
506
+ A: The plugin's CSS is automatically injected, no manual import needed. If you encounter style issues, you can manually import Quill CSS:
507
+
508
+ ```typescript
509
+ import "quill/dist/quill.core.css";
510
+ ```
511
+
512
+ ### Q: Why isn't the editor showing?
513
+
514
+ A: Please ensure:
515
+
516
+ 1. All peer dependencies are correctly installed
517
+ 2. Called `HtmlTextManage.init(app)` and waited for Promise completion
518
+ 3. Created an `Editor` instance
519
+ 4. Added `dedupe` or `alias` settings in Vite/Webpack configuration
520
+ 5. Check browser console for error messages
521
+
522
+ ### Q: Which browsers are supported?
523
+
524
+ A: Supports all modern browsers:
525
+
526
+ - Chrome 90+
527
+ - Firefox 88+
528
+ - Safari 14+
529
+ - Edge 90+
530
+
531
+ IE11 and earlier versions are not supported.
532
+
533
+ ### Q: How to obtain a license?
534
+
535
+ A: Please contact the developer for a commercial license key:
536
+
537
+ - Email: 408550179@qq.com
538
+ - TG: [https://t.me/Ccymmm](https://t.me/Ccymmm)
539
+
540
+ ### Q: How to optimize performance?
541
+
542
+ A: Best practices:
543
+
544
+ 1. Use `build:watch` mode for development to avoid frequent rebuilds
545
+ 2. Load large documents in segments
546
+ 3. Avoid frequent calls to `dateEdit` in short periods
547
+ 4. Use debounce for high-frequency events
548
+
549
+ ### Q: How to handle Chinese input method issues?
550
+
551
+ A: Quill 2.0 has built-in support for Chinese input methods. If you encounter issues:
552
+
553
+ ```typescript
554
+ const quill = HtmlTextManage.getQuill();
555
+
556
+ // Listen to composition events
557
+ quill.keyboard.addBinding({
558
+ key: "Enter",
559
+ handler: function (range, context) {
560
+ // Custom handling logic
561
+ },
562
+ });
563
+ ```
564
+
565
+ ## 🤝 Contributing
566
+
567
+ Issues and Pull Requests are welcome!
568
+
569
+ ### Contribution Guidelines
570
+
571
+ 1. Fork this repository
572
+ 2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
573
+ 3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
574
+ 4. Push to the branch (`git push origin feature/AmazingFeature`)
575
+ 5. Open a Pull Request
576
+
577
+ ### Development Standards
578
+
579
+ - Follow TypeScript best practices
580
+ - Add necessary type definitions
581
+ - Write clear comments
582
+ - Update relevant documentation
583
+ - Ensure all tests pass
584
+
585
+ ## 📄 License
586
+
587
+ This project is licensed under the [MIT](./LICENSE) License.
588
+
589
+ ### Commercial Use
590
+
591
+ This plugin supports commercial use but requires a license key. Please contact the developer for authorization.
592
+
593
+ ## 👤 Author
594
+
595
+ **chenyomi**
596
+
597
+ - npm: [@chenyomi](https://www.npmjs.com/~chenyomi)
598
+ - Email: 408550179@qq.com
599
+ - TG: [https://t.me/Ccymmm](https://t.me/Ccymmm)
600
+
601
+ ## 🙏 Acknowledgments
602
+
603
+ - [Leafer UI](https://www.leaferjs.com/) - Powerful Canvas rendering engine
604
+ - [Quill](https://quilljs.com/) - Modern rich text editor
605
+ - [TypeScript](https://www.typescriptlang.org/) - JavaScript superset
606
+ - [Google Fonts](https://fonts.google.com/) - Quality open-source fonts
607
+
608
+ ## 📊 Stats
609
+
610
+ ![npm version](https://img.shields.io/npm/v/@chenyomi/leafer-htmltext-edit)
611
+ ![npm downloads](https://img.shields.io/npm/dt/@chenyomi/leafer-htmltext-edit)
612
+ ![bundle size](https://img.shields.io/bundlephobia/minzip/@chenyomi/leafer-htmltext-edit)
613
+ ![license](https://img.shields.io/npm/l/@chenyomi/leafer-htmltext-edit)
614
+ ![stars](https://img.shields.io/github/stars/chenyomi/leafer-htmltext-edit)
615
+
616
+ ---
617
+
618
+ If this project helps you, please give it a ⭐️ Star! Your support is our greatest motivation!
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chenyomi/leafer-htmltext-edit",
3
- "version": "2.2.2",
3
+ "version": "2.2.4",
4
4
  "description": "A text editor plugin for Leafer UI with HTML text support",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -57,6 +57,7 @@
57
57
  "files": [
58
58
  "dist",
59
59
  "README.md",
60
+ "README_EN.md",
60
61
  "LICENSE"
61
62
  ],
62
63
  "publishConfig": {