@oix1987/yjd 1.0.2 → 2.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.
Files changed (70) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +146 -142
  3. package/core.js +77 -0
  4. package/dist/core.esm.js +2 -0
  5. package/dist/core.esm.js.map +1 -0
  6. package/dist/rich-editor.esm.js +1 -1
  7. package/dist/rich-editor.esm.js.map +1 -1
  8. package/dist/rich-editor.min.js +1 -1
  9. package/dist/rich-editor.min.js.map +1 -1
  10. package/index.d.ts +134 -103
  11. package/index.js +227 -0
  12. package/lib/core/editor.js +1806 -0
  13. package/lib/core/format.js +540 -0
  14. package/lib/core/module.js +81 -0
  15. package/lib/core/registry.js +158 -0
  16. package/lib/formats/background.js +213 -0
  17. package/lib/formats/bold.js +49 -0
  18. package/lib/formats/capitalization.js +579 -0
  19. package/lib/formats/color.js +183 -0
  20. package/lib/formats/emoji.js +282 -0
  21. package/lib/formats/font-family.js +548 -0
  22. package/lib/formats/heading.js +502 -0
  23. package/lib/formats/image.js +347 -0
  24. package/lib/formats/import.js +385 -0
  25. package/lib/formats/indent.js +297 -0
  26. package/lib/formats/italic.js +27 -0
  27. package/lib/formats/line-height.js +562 -0
  28. package/lib/formats/link.js +251 -0
  29. package/lib/formats/list.js +635 -0
  30. package/lib/formats/strike.js +31 -0
  31. package/lib/formats/subscript.js +40 -0
  32. package/lib/formats/superscript.js +39 -0
  33. package/lib/formats/table.js +293 -0
  34. package/lib/formats/tag.js +304 -0
  35. package/lib/formats/text-align.js +422 -0
  36. package/lib/formats/text-size.js +498 -0
  37. package/lib/formats/underline.js +30 -0
  38. package/lib/formats/video.js +381 -0
  39. package/lib/modules/block-toolbar.js +639 -0
  40. package/lib/modules/code-view.js +447 -0
  41. package/lib/modules/find-replace.js +273 -0
  42. package/lib/modules/history.js +425 -0
  43. package/lib/modules/resize-handles.js +701 -0
  44. package/lib/modules/slash-menu.js +183 -0
  45. package/lib/modules/table-toolbar.js +635 -0
  46. package/lib/modules/toolbar.js +607 -0
  47. package/lib/styles-loader.js +142 -0
  48. package/lib/styles.css +3373 -0
  49. package/lib/styles.css.js +2 -0
  50. package/lib/styles.min.css +1 -0
  51. package/lib/ui/color-picker.js +296 -0
  52. package/lib/ui/customselect.js +351 -0
  53. package/lib/ui/emoji-picker.js +196 -0
  54. package/lib/ui/icons.js +145 -0
  55. package/lib/ui/image-popup.js +435 -0
  56. package/lib/ui/import-popup.js +288 -0
  57. package/lib/ui/link-popup.js +139 -0
  58. package/lib/ui/list-picker.js +307 -0
  59. package/lib/ui/select-button.js +68 -0
  60. package/lib/ui/table-popup.js +171 -0
  61. package/lib/ui/tag-popup.js +249 -0
  62. package/lib/ui/text-align-picker.js +278 -0
  63. package/lib/ui/video-popup.js +413 -0
  64. package/lib/utils/exec-command.js +72 -0
  65. package/lib/utils/history-helper.js +50 -0
  66. package/lib/utils/popup-helper.js +219 -0
  67. package/lib/utils/popup-positioning.js +234 -0
  68. package/lib/utils/sanitize.js +164 -0
  69. package/package.json +51 -31
  70. package/umd-entry.js +18 -0
package/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2024 Oix1987
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -1,142 +1,146 @@
1
- # @oix1987/yjd - Professional Rich Text Editor
2
-
3
- A powerful, commercial-grade rich text editor with real-time content change tracking for web applications. Built with vanilla JavaScript for maximum performance and compatibility.
4
-
5
- ## 🚀 Features
6
-
7
- - **Rich Text Formatting**: Bold, Italic, Underline, Strikethrough, Subscript, Superscript
8
- - **Advanced Formatting**: Text alignment, line height, font family, text size, background colors
9
- - **Content Management**: Images, tables, links, lists, emojis, videos
10
- - **Real-time Tracking**: `onChange` callback for live content monitoring
11
- - **Modern UI**: Customizable toolbar with intuitive controls
12
- - **TypeScript Support**: Full type definitions included
13
- - **Lightweight**: Pure JavaScript implementation, no heavy dependencies
14
- - **Cross-browser**: Compatible with all modern browsers
15
-
16
- ## 📦 Installation
17
-
18
- ```bash
19
- npm install @oix1987/yjd
20
- ```
21
-
22
- ## 💻 Usage
23
-
24
- ### Basic Implementation
25
-
26
- ```javascript
27
- import RichEditor from "@oix1987/yjd";
28
-
29
- const editor = new RichEditor("#editor-container", {
30
- content: "<p>Initial content</p>",
31
- height: 400,
32
- width: 800,
33
- theme: "light",
34
- placeholder: "Start typing...",
35
- onChange: (content) => {
36
- // Handle content changes here
37
- console.log("Content changed:", content);
38
- // Update your output container
39
- document.getElementById("output").innerHTML = content;
40
- },
41
- });
42
- ```
43
-
44
- ### CDN Usage
45
-
46
- ```html
47
- <!-- Using jsDelivr CDN -->
48
- <script src="https://cdn.jsdelivr.net/npm/@oix1987/yjd@1.0.2/dist/rich-editor.min.js"></script>
49
- <script>
50
- const editor = new RichEditor("#editor-container", {
51
- // configuration options
52
- });
53
- </script>
54
- ```
55
-
56
- ### Alternative CDN
57
-
58
- ```html
59
- <!-- Using unpkg CDN -->
60
- <script src="https://unpkg.com/@oix1987/yjd@1.0.2/dist/rich-editor.min.js"></script>
61
- ```
62
-
63
- ## ⚙️ Configuration Options
64
-
65
- | Option | Type | Default | Description |
66
- | ------------- | -------- | -------------- | --------------------------------------------- |
67
- | `content` | string | null | Initial content for the editor |
68
- | `height` | number | 400 | Editor height in pixels |
69
- | `width` | number | 800 | Editor width in pixels |
70
- | `theme` | string | 'light' | Editor theme (light/dark) |
71
- | `placeholder` | string | 'Type here...' | Placeholder text |
72
- | `onChange` | function | undefined | Callback function called when content changes |
73
-
74
- ### onChange Callback
75
-
76
- The `onChange` callback receives the current HTML content as a parameter:
77
-
78
- ```javascript
79
- onChange: (content) => {
80
- // content is the HTML string of the editor content
81
- console.log("New content:", content);
82
-
83
- // Example: Update an output container
84
- document.getElementById("output").innerHTML = content;
85
-
86
- // Example: Send to server
87
- fetch("/api/save-content", {
88
- method: "POST",
89
- body: JSON.stringify({ content }),
90
- headers: { "Content-Type": "application/json" },
91
- });
92
- };
93
- ```
94
-
95
- ## 🎯 Events
96
-
97
- The editor supports comprehensive event handling:
98
-
99
- ```javascript
100
- // Listen for text changes
101
- editor.on("text-change", (content) => {
102
- console.log("Text changed:", content);
103
- });
104
-
105
- // Listen for focus events
106
- editor.on("focus", () => {
107
- console.log("Editor focused");
108
- });
109
-
110
- // Remove event listener
111
- editor.off("text-change", handler);
112
- ```
113
-
114
- ## 🔧 API Methods
115
-
116
- | Method | Description | Parameters | Returns |
117
- | --------------------- | ------------------------ | ---------------------------------- | -------- |
118
- | `getContent()` | Get current HTML content | - | `string` |
119
- | `setContent(content)` | Set editor content | `content: string` | `void` |
120
- | `focus()` | Focus the editor | - | `void` |
121
- | `on(event, handler)` | Add event listener | `event: string, handler: function` | `void` |
122
- | `off(event, handler)` | Remove event listener | `event: string, handler: function` | `void` |
123
-
124
- ## 💼 Commercial License
125
-
126
- This is a commercial product. For licensing information and pricing, please contact:
127
-
128
- - **Author**: Oix1987
129
- - **License**: ISC (Commercial)
130
- - **Version**: 1.0.1
131
-
132
- ## 📄 License
133
-
134
- Copyright (c) 2024 Oix1987. All rights reserved.
135
-
136
- This software is licensed under the ISC License. Commercial use requires a valid license.
137
-
138
- ## 🆘 Support
139
-
140
- For technical support, feature requests, or licensing inquiries, please contact the author.
141
-
142
- See `index.html` and `main.js` for a complete working example that demonstrates the `onChange` functionality with real-time output display.
1
+ # yjd
2
+
3
+ **Rich text, without the weight.** A dependency-free, tree-shakeable rich text editor for the web. Compose it from a `/core` entry and ship **16 KB**, not the whole library.
4
+
5
+ 🔗 **[yjd.io](https://yjd.io)** · [Live playground](https://yjd.io/demos/) · [Docs](https://yjd.io/site/docs.html)
6
+
7
+ ```js
8
+ import RichEditor from '@oix1987/yjd';
9
+ new RichEditor('#editor', { placeholder: 'Start writing…' });
10
+ ```
11
+
12
+ ---
13
+
14
+ ## Why yjd
15
+
16
+ - **Tree-shakeable core** — register only the formats/modules you use; the rest is dropped.
17
+ - **Zero runtime dependencies** — plain DOM, ESM + UMD builds.
18
+ - **Framework-agnostic** — drop it into React, Vue, Svelte, or a static page.
19
+ - **Responsive** — toolbar fills the width on desktop, a single swipe-row on mobile.
20
+ - **XSS-safe paste** — sanitises pasted HTML (scripts/handlers/unsafe URLs stripped; only trusted embeds survive).
21
+ - **Accessible** — keyboard navigable, WCAG-AA contrast (Lighthouse a11y 100).
22
+
23
+ ## Bundle size (gzipped JS)
24
+
25
+ Every preset is built from the same `/core` entry — pick a profile, tree-shake the rest.
26
+
27
+ | Preset | Includes | Size |
28
+ |---|---|---|
29
+ | Minimal | bold · italic · underline · link | **~16 KB** |
30
+ | Bubble | floating bar, no toolbar + slash menu | **~21 KB** |
31
+ | Basic | + strike · headings · lists · align | **~25 KB** |
32
+ | Standard | + colour · image · table · find · code view | **~38 KB** |
33
+ | Full | everything (CSS inlined) | **~54 KB** |
34
+
35
+ > For comparison, Quill 2 is ~60 KB. The stylesheet (~8 KB gzip) ships once and is cached, kept out of the JS.
36
+
37
+ ## Install
38
+
39
+ ```bash
40
+ npm i @oix1987/yjd
41
+ ```
42
+
43
+ Or via CDN (all-in-one UMD):
44
+
45
+ ```html
46
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@oix1987/yjd/lib/styles.min.css">
47
+ <script src="https://cdn.jsdelivr.net/npm/@oix1987/yjd"></script>
48
+ <script> new RichEditor('#editor'); </script>
49
+ ```
50
+
51
+ ## Quick start (all-in-one)
52
+
53
+ The default build registers everything and injects its CSS:
54
+
55
+ ```js
56
+ import RichEditor from '@oix1987/yjd';
57
+
58
+ const editor = new RichEditor('#editor', {
59
+ placeholder: 'Start writing…',
60
+ onChange: (html) => console.log(html),
61
+ });
62
+ ```
63
+
64
+ ## Tree-shakeable core
65
+
66
+ For the smallest bundle, import from `@oix1987/yjd/core` (side-effect-free) and register only what you need. Link the stylesheet once.
67
+
68
+ ```js
69
+ import { Editor, registry, Bold, Italic, Underline, Link, Toolbar, History }
70
+ from '@oix1987/yjd/core';
71
+
72
+ registry.register('formats/bold', Bold);
73
+ registry.register('formats/italic', Italic);
74
+ registry.register('formats/underline', Underline);
75
+ registry.register('formats/link', Link);
76
+ registry.register('modules/toolbar', Toolbar);
77
+ registry.register('modules/history', History);
78
+
79
+ new Editor('#editor', {
80
+ formats: ['bold', 'italic', 'underline', 'link'],
81
+ modules: ['toolbar', 'history'],
82
+ });
83
+ ```
84
+
85
+ ```html
86
+ <link rel="stylesheet" href="@oix1987/yjd/lib/styles.min.css">
87
+ ```
88
+
89
+ ## Options
90
+
91
+ | Option | Type | Description |
92
+ |---|---|---|
93
+ | `placeholder` | string | Empty-state text. |
94
+ | `content` | string | Initial HTML. |
95
+ | `width` / `maxWidth` | number|string | Number = px; string (e.g. `'100%'`) = responsive. |
96
+ | `height` / `maxHeight` | number | Editor body height in px. |
97
+ | `onChange` | fn(html) | Called on every content change. |
98
+ | `toolbar1` / `toolbar2` | array | Toolbar groups: `{ group, items: [] }`. |
99
+ | `formats` / `modules` | string[] | Which registered features to activate. |
100
+ | `features` | object | `{ wordCount, breadcrumb, … }` — toggle the status bar. |
101
+ | `maxLength` | number | Hard character limit. |
102
+
103
+ ## Formats & modules
104
+
105
+ **Formats** `bold` · `italic` · `underline` · `strike` · `subscript` · `superscript` · `color` · `background` · `link` · `heading` · `font-family` · `text-size` · `line-height` · `capitalization` · `text-align` · `list` · `indent-increase` · `indent-decrease` · `image` · `video` · `table` · `emoji` · `tag`
106
+
107
+ **Modules** — `toolbar` · `history` · `slash-menu` · `block-toolbar` (bubble bar) · `table-toolbar` · `find-replace` · `code-view` · `resize-handles`
108
+
109
+ ## Methods
110
+
111
+ `getHTML()` · `getText()` · `insertHTML(html)` · `insertText(t)` · `clear()` · `isEmpty()` · `focus()` · `setReadOnly(bool)` · `undo()` · `redo()`
112
+
113
+ ## Styling
114
+
115
+ Theme via CSS custom properties:
116
+
117
+ ```css
118
+ .yjd-rich-editor {
119
+ --rte-accent: #6d5efc; /* primary */
120
+ --rte-ink: #20242f; /* text */
121
+ --rte-radius: 14px;
122
+ --rte-border: #e9e9f1;
123
+ }
124
+ ```
125
+
126
+ ## Development
127
+
128
+ ```bash
129
+ npm install
130
+ npm run build # dist/ (UMD + ESM) + bundled /core; regenerates CSS
131
+ npm test # unit tests (sanitize, exec-command)
132
+ npm run build:demos # preset demo bundles
133
+
134
+ # Static site (landing + docs + playground) for Cloudflare Pages
135
+ npm run build:pages # build + assemble ./public
136
+ ```
137
+
138
+ ### Deploy to Cloudflare Pages (yjd.io)
139
+
140
+ - **Build command:** `npm run build:pages`
141
+ - **Output directory:** `public`
142
+ - Add `yjd.io` as a custom domain in the Pages project.
143
+
144
+ ## License
145
+
146
+ ISC
package/core.js ADDED
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Tree-shakeable entry point.
3
+ *
4
+ * Unlike the default entry (./index.js) — which registers every format/module
5
+ * and injects the stylesheet on import (convenient, but pulls the whole editor)
6
+ * — this entry only RE-EXPORTS classes with no side effects. A bundler can drop
7
+ * anything you don't import.
8
+ *
9
+ * Usage (only what you need ends up in your bundle):
10
+ *
11
+ * import { Editor, registry, StylesLoader, Bold, Italic, Toolbar, History }
12
+ * from '@oix1987/yjd/core';
13
+ * StylesLoader.loadStyles();
14
+ * registry.register('formats/bold', Bold);
15
+ * registry.register('formats/italic', Italic);
16
+ * registry.register('modules/toolbar', Toolbar);
17
+ * registry.register('modules/history', History);
18
+ * const editor = new Editor('#app', {
19
+ * formats: ['bold', 'italic'],
20
+ * modules: ['toolbar', 'history'],
21
+ * });
22
+ */
23
+
24
+ // Core
25
+ export { default as Editor } from './lib/core/editor.js';
26
+ export { default as Module } from './lib/core/module.js';
27
+ export { Format, InlineFormat, BlockFormat } from './lib/core/format.js';
28
+ export { default as registry } from './lib/core/registry.js';
29
+ export { default as StylesLoader } from './lib/styles-loader.js';
30
+
31
+ // Formats
32
+ export { default as Bold } from './lib/formats/bold.js';
33
+ export { default as Italic } from './lib/formats/italic.js';
34
+ export { default as Underline } from './lib/formats/underline.js';
35
+ export { default as Strike } from './lib/formats/strike.js';
36
+ export { default as Subscript } from './lib/formats/subscript.js';
37
+ export { default as Superscript } from './lib/formats/superscript.js';
38
+ export { default as Color } from './lib/formats/color.js';
39
+ export { default as Background } from './lib/formats/background.js';
40
+ export { default as Link } from './lib/formats/link.js';
41
+ export { default as Table } from './lib/formats/table.js';
42
+ export { default as Heading } from './lib/formats/heading.js';
43
+ export { default as FontFamily } from './lib/formats/font-family.js';
44
+ export { default as LineHeight } from './lib/formats/line-height.js';
45
+ export { default as Capitalization } from './lib/formats/capitalization.js';
46
+ export { default as TextAlign } from './lib/formats/text-align.js';
47
+ export { default as List } from './lib/formats/list.js';
48
+ export { default as Indent, IndentIncrease, IndentDecrease } from './lib/formats/indent.js';
49
+ export { default as Emoji } from './lib/formats/emoji.js';
50
+ export { default as Image } from './lib/formats/image.js';
51
+ export { default as Video } from './lib/formats/video.js';
52
+ export { default as Tag } from './lib/formats/tag.js';
53
+ export { default as TextSize } from './lib/formats/text-size.js';
54
+ export { default as Import } from './lib/formats/import.js';
55
+
56
+ // Modules
57
+ export { default as Toolbar } from './lib/modules/toolbar.js';
58
+ export { default as History } from './lib/modules/history.js';
59
+ export { default as BlockToolbar } from './lib/modules/block-toolbar.js';
60
+ export { default as TableToolbar } from './lib/modules/table-toolbar.js';
61
+ export { default as CodeView } from './lib/modules/code-view.js';
62
+ export { default as FindReplace } from './lib/modules/find-replace.js';
63
+ export { default as SlashMenu } from './lib/modules/slash-menu.js';
64
+ export { default as ResizeHandles } from './lib/modules/resize-handles.js';
65
+
66
+ // UI
67
+ export { default as IconUtils } from './lib/ui/icons.js';
68
+ export { default as ColorPicker } from './lib/ui/color-picker.js';
69
+ export { default as LinkPopup } from './lib/ui/link-popup.js';
70
+ export { default as TablePopup } from './lib/ui/table-popup.js';
71
+ export { default as TextAlignPicker } from './lib/ui/text-align-picker.js';
72
+ export { default as ListPicker } from './lib/ui/list-picker.js';
73
+ export { default as EmojiPicker } from './lib/ui/emoji-picker.js';
74
+ export { default as ImagePopup } from './lib/ui/image-popup.js';
75
+ export { default as VideoPopup } from './lib/ui/video-popup.js';
76
+ export { default as TagPopup } from './lib/ui/tag-popup.js';
77
+ export { default as createCustomButton } from './lib/ui/select-button.js';