@oix1987/yjd 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 +91 -0
- package/index.d.ts +103 -0
- package/index.js +221 -0
- package/lib/core/editor.js +1175 -0
- package/lib/core/format.js +542 -0
- package/lib/core/module.js +81 -0
- package/lib/core/registry.js +152 -0
- package/lib/formats/background.js +212 -0
- package/lib/formats/bold.js +67 -0
- package/lib/formats/capitalization.js +563 -0
- package/lib/formats/color.js +165 -0
- package/lib/formats/emoji.js +282 -0
- package/lib/formats/font-family.js +547 -0
- package/lib/formats/heading.js +502 -0
- package/lib/formats/image.js +344 -0
- package/lib/formats/import.js +385 -0
- package/lib/formats/indent.js +297 -0
- package/lib/formats/italic.js +27 -0
- package/lib/formats/line-height.js +558 -0
- package/lib/formats/link.js +251 -0
- package/lib/formats/list.js +635 -0
- package/lib/formats/strike.js +31 -0
- package/lib/formats/subscript.js +36 -0
- package/lib/formats/superscript.js +35 -0
- package/lib/formats/table.js +288 -0
- package/lib/formats/tag.js +304 -0
- package/lib/formats/text-align.js +421 -0
- package/lib/formats/text-size.js +497 -0
- package/lib/formats/underline.js +30 -0
- package/lib/formats/video.js +372 -0
- package/lib/modules/block-toolbar.js +628 -0
- package/lib/modules/code-view.js +434 -0
- package/lib/modules/history.js +410 -0
- package/lib/modules/resize-handles.js +677 -0
- package/lib/modules/table-toolbar.js +618 -0
- package/lib/modules/toolbar.js +424 -0
- package/lib/styles-loader.js +144 -0
- package/lib/styles.css +2123 -0
- package/lib/ui/color-picker.js +296 -0
- package/lib/ui/customselect.js +319 -0
- package/lib/ui/emoji-picker.js +196 -0
- package/lib/ui/icons.js +413 -0
- package/lib/ui/image-popup.js +444 -0
- package/lib/ui/import-popup.js +288 -0
- package/lib/ui/link-popup.js +191 -0
- package/lib/ui/list-picker.js +307 -0
- package/lib/ui/select-button.js +61 -0
- package/lib/ui/table-popup.js +171 -0
- package/lib/ui/tag-popup.js +249 -0
- package/lib/ui/text-align-picker.js +281 -0
- package/lib/ui/video-popup.js +422 -0
- package/lib/utils/history-helper.js +50 -0
- package/lib/utils/popup-helper.js +219 -0
- package/lib/utils/popup-positioning.js +231 -0
- package/package.json +26 -0
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Rich Text Editor
|
|
2
|
+
|
|
3
|
+
A powerful rich text editor with real-time content change tracking.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Rich text formatting (Bold, Italic, Underline, Strikethrough, etc.)
|
|
8
|
+
- Real-time content change tracking with `onChange` callback
|
|
9
|
+
- Modern UI with customizable toolbar
|
|
10
|
+
- Support for images, tables, links, and more
|
|
11
|
+
- TypeScript support
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Basic Usage
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
import RichEditor from "./index.js";
|
|
19
|
+
|
|
20
|
+
const editor = new RichEditor("#editor-container", {
|
|
21
|
+
content: "<p>Initial content</p>",
|
|
22
|
+
height: 400,
|
|
23
|
+
width: 800,
|
|
24
|
+
theme: "light",
|
|
25
|
+
placeholder: "Start typing...",
|
|
26
|
+
onChange: (content) => {
|
|
27
|
+
// Handle content changes here
|
|
28
|
+
console.log("Content changed:", content);
|
|
29
|
+
// Update your output container
|
|
30
|
+
document.getElementById("output").innerHTML = content;
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Options
|
|
36
|
+
|
|
37
|
+
| Option | Type | Default | Description |
|
|
38
|
+
| ------------- | -------- | -------------- | --------------------------------------------- |
|
|
39
|
+
| `content` | string | null | Initial content for the editor |
|
|
40
|
+
| `height` | number | 400 | Editor height in pixels |
|
|
41
|
+
| `width` | number | 800 | Editor width in pixels |
|
|
42
|
+
| `theme` | string | 'light' | Editor theme |
|
|
43
|
+
| `placeholder` | string | 'Type here...' | Placeholder text |
|
|
44
|
+
| `onChange` | function | undefined | Callback function called when content changes |
|
|
45
|
+
|
|
46
|
+
### onChange Callback
|
|
47
|
+
|
|
48
|
+
The `onChange` callback receives the current HTML content as a parameter:
|
|
49
|
+
|
|
50
|
+
```javascript
|
|
51
|
+
onChange: (content) => {
|
|
52
|
+
// content is the HTML string of the editor content
|
|
53
|
+
console.log("New content:", content);
|
|
54
|
+
|
|
55
|
+
// Example: Update an output container
|
|
56
|
+
document.getElementById("output").innerHTML = content;
|
|
57
|
+
|
|
58
|
+
// Example: Send to server
|
|
59
|
+
fetch("/api/save-content", {
|
|
60
|
+
method: "POST",
|
|
61
|
+
body: JSON.stringify({ content }),
|
|
62
|
+
headers: { "Content-Type": "application/json" },
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Events
|
|
68
|
+
|
|
69
|
+
The editor also supports event listeners:
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
// Listen for text changes
|
|
73
|
+
editor.on("text-change", (content) => {
|
|
74
|
+
console.log("Text changed:", content);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Remove event listener
|
|
78
|
+
editor.off("text-change", handler);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Methods
|
|
82
|
+
|
|
83
|
+
- `getContent()` - Get current HTML content
|
|
84
|
+
- `setContent(content)` - Set editor content
|
|
85
|
+
- `focus()` - Focus the editor
|
|
86
|
+
- `on(event, handler)` - Add event listener
|
|
87
|
+
- `off(event, handler)` - Remove event listener
|
|
88
|
+
|
|
89
|
+
## Example
|
|
90
|
+
|
|
91
|
+
See `index.html` and `main.js` for a complete working example that demonstrates the `onChange` functionality with real-time output display.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
declare module 'yjdtest' {
|
|
2
|
+
// Editor options interface
|
|
3
|
+
interface EditorOptions {
|
|
4
|
+
placeholder?: string;
|
|
5
|
+
theme?: string;
|
|
6
|
+
height?: number;
|
|
7
|
+
width?: number;
|
|
8
|
+
maxWidth?: number;
|
|
9
|
+
maxHeight?: number;
|
|
10
|
+
content?: string | null;
|
|
11
|
+
onChange?: (content: string) => void;
|
|
12
|
+
features?: {
|
|
13
|
+
emoji?: boolean;
|
|
14
|
+
image?: boolean;
|
|
15
|
+
table?: boolean;
|
|
16
|
+
wordCount?: boolean;
|
|
17
|
+
breadcrumb?: boolean;
|
|
18
|
+
};
|
|
19
|
+
toolbar1?: Array<{
|
|
20
|
+
group: string;
|
|
21
|
+
items: string[];
|
|
22
|
+
}>;
|
|
23
|
+
toolbar2?: Array<{
|
|
24
|
+
group: string;
|
|
25
|
+
items: string[];
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class Editor {
|
|
30
|
+
constructor(selector: string | Element, options?: EditorOptions);
|
|
31
|
+
on(event: string, handler: (data: any) => void): void;
|
|
32
|
+
off(event: string, handler: (data: any) => void): void;
|
|
33
|
+
emit(event: string, data: any): void;
|
|
34
|
+
getContent(): string;
|
|
35
|
+
setContent(content: string): void;
|
|
36
|
+
focus(): void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class Module {}
|
|
40
|
+
export class Format {}
|
|
41
|
+
export class InlineFormat extends Format {}
|
|
42
|
+
export class BlockFormat extends Format {}
|
|
43
|
+
export const registry: any;
|
|
44
|
+
|
|
45
|
+
export class RichEditor extends Editor {
|
|
46
|
+
static register(path: string, definition: any, suppressWarning?: boolean): void;
|
|
47
|
+
static get(path: string): any;
|
|
48
|
+
static create(selector: string | Element, options?: EditorOptions): RichEditor;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function createEditor(selector: string | Element, options?: EditorOptions): RichEditor;
|
|
52
|
+
|
|
53
|
+
// Formats
|
|
54
|
+
export const Bold: any;
|
|
55
|
+
export const Italic: any;
|
|
56
|
+
export const Underline: any;
|
|
57
|
+
export const Strike: any;
|
|
58
|
+
export const Subscript: any;
|
|
59
|
+
export const Superscript: any;
|
|
60
|
+
export const Color: any;
|
|
61
|
+
export const Background: any;
|
|
62
|
+
export const Link: any;
|
|
63
|
+
export const Table: any;
|
|
64
|
+
export const Heading: any;
|
|
65
|
+
export const FontFamily: any;
|
|
66
|
+
export const LineHeight: any;
|
|
67
|
+
export const Capitalization: any;
|
|
68
|
+
export const TextAlign: any;
|
|
69
|
+
export const List: any;
|
|
70
|
+
export const Indent: any;
|
|
71
|
+
export const IndentIncrease: any;
|
|
72
|
+
export const IndentDecrease: any;
|
|
73
|
+
export const Emoji: any;
|
|
74
|
+
export const Image: any;
|
|
75
|
+
export const Video: any;
|
|
76
|
+
export const Tag: any;
|
|
77
|
+
export const TextSize: any;
|
|
78
|
+
export const Import: any;
|
|
79
|
+
|
|
80
|
+
// Modules
|
|
81
|
+
export const Toolbar: any;
|
|
82
|
+
export const History: any;
|
|
83
|
+
export const BlockToolbar: any;
|
|
84
|
+
export const TableToolbar: any;
|
|
85
|
+
export const CodeView: any;
|
|
86
|
+
export const ResizeHandles: any;
|
|
87
|
+
|
|
88
|
+
// UI components
|
|
89
|
+
export const ColorPicker: any;
|
|
90
|
+
export const IconUtils: any;
|
|
91
|
+
export const LinkPopup: any;
|
|
92
|
+
export const TablePopup: any;
|
|
93
|
+
export const TextAlignPicker: any;
|
|
94
|
+
export const ListPicker: any;
|
|
95
|
+
export const EmojiPicker: any;
|
|
96
|
+
export const ImagePopup: any;
|
|
97
|
+
export const VideoPopup: any;
|
|
98
|
+
export const TagPopup: any;
|
|
99
|
+
|
|
100
|
+
export const createCustomButton: any;
|
|
101
|
+
|
|
102
|
+
export default RichEditor;
|
|
103
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import Editor from './lib/core/editor.js';
|
|
2
|
+
import registry from './lib/core/registry.js';
|
|
3
|
+
import Module from './lib/core/module.js';
|
|
4
|
+
import { Format, InlineFormat, BlockFormat } from './lib/core/format.js';
|
|
5
|
+
import StylesLoader from './lib/styles-loader.js';
|
|
6
|
+
|
|
7
|
+
// Import formats
|
|
8
|
+
import Bold from './lib/formats/bold.js';
|
|
9
|
+
import Italic from './lib/formats/italic.js';
|
|
10
|
+
import Underline from './lib/formats/underline.js';
|
|
11
|
+
import Strike from './lib/formats/strike.js';
|
|
12
|
+
import Subscript from './lib/formats/subscript.js';
|
|
13
|
+
import Superscript from './lib/formats/superscript.js';
|
|
14
|
+
import Color from './lib/formats/color.js';
|
|
15
|
+
import Background from './lib/formats/background.js';
|
|
16
|
+
import Link from './lib/formats/link.js';
|
|
17
|
+
import Table from './lib/formats/table.js';
|
|
18
|
+
import Heading from './lib/formats/heading.js';
|
|
19
|
+
import FontFamily from './lib/formats/font-family.js';
|
|
20
|
+
import LineHeight from './lib/formats/line-height.js';
|
|
21
|
+
import Capitalization from './lib/formats/capitalization.js';
|
|
22
|
+
import TextAlign from './lib/formats/text-align.js';
|
|
23
|
+
import List from './lib/formats/list.js';
|
|
24
|
+
import Indent, { IndentIncrease, IndentDecrease } from './lib/formats/indent.js';
|
|
25
|
+
import Emoji from './lib/formats/emoji.js';
|
|
26
|
+
import Image from './lib/formats/image.js';
|
|
27
|
+
import Video from './lib/formats/video.js';
|
|
28
|
+
import Tag from './lib/formats/tag.js';
|
|
29
|
+
import TextSize from './lib/formats/text-size.js';
|
|
30
|
+
|
|
31
|
+
import Import from './lib/formats/import.js';
|
|
32
|
+
|
|
33
|
+
// Import modules
|
|
34
|
+
import Toolbar from './lib/modules/toolbar.js';
|
|
35
|
+
import History from './lib/modules/history.js';
|
|
36
|
+
import BlockToolbar from './lib/modules/block-toolbar.js';
|
|
37
|
+
import TableToolbar from './lib/modules/table-toolbar.js';
|
|
38
|
+
import CodeView from './lib/modules/code-view.js';
|
|
39
|
+
|
|
40
|
+
import ResizeHandles from './lib/modules/resize-handles.js';
|
|
41
|
+
|
|
42
|
+
// Import UI components
|
|
43
|
+
import ColorPicker from './lib/ui/color-picker.js';
|
|
44
|
+
import IconUtils from './lib/ui/icons.js';
|
|
45
|
+
import LinkPopup from './lib/ui/link-popup.js';
|
|
46
|
+
import TablePopup from './lib/ui/table-popup.js';
|
|
47
|
+
import TextAlignPicker from './lib/ui/text-align-picker.js';
|
|
48
|
+
import ListPicker from './lib/ui/list-picker.js';
|
|
49
|
+
import EmojiPicker from './lib/ui/emoji-picker.js';
|
|
50
|
+
import ImagePopup from './lib/ui/image-popup.js';
|
|
51
|
+
import VideoPopup from './lib/ui/video-popup.js';
|
|
52
|
+
import TagPopup from './lib/ui/tag-popup.js';
|
|
53
|
+
|
|
54
|
+
import createCustomButton from './lib/ui/select-button.js';
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
// Register default formats
|
|
59
|
+
registry.register('formats/bold', Bold, true);
|
|
60
|
+
registry.register('formats/italic', Italic, true);
|
|
61
|
+
registry.register('formats/underline', Underline, true);
|
|
62
|
+
registry.register('formats/strike', Strike, true);
|
|
63
|
+
registry.register('formats/subscript', Subscript, true);
|
|
64
|
+
registry.register('formats/superscript', Superscript, true);
|
|
65
|
+
registry.register('formats/color', Color, true);
|
|
66
|
+
registry.register('formats/background', Background, true);
|
|
67
|
+
registry.register('formats/link', Link, true);
|
|
68
|
+
registry.register('formats/table', Table, true);
|
|
69
|
+
registry.register('formats/heading', Heading, true);
|
|
70
|
+
registry.register('formats/font-family', FontFamily, true);
|
|
71
|
+
registry.register('formats/line-height', LineHeight, true);
|
|
72
|
+
registry.register('formats/capitalization', Capitalization, true);
|
|
73
|
+
registry.register('formats/text-align', TextAlign, true);
|
|
74
|
+
registry.register('formats/list', List, true);
|
|
75
|
+
registry.register('formats/indent', Indent, true);
|
|
76
|
+
registry.register('formats/indent-increase', IndentIncrease, true);
|
|
77
|
+
registry.register('formats/indent-decrease', IndentDecrease, true);
|
|
78
|
+
registry.register('formats/emoji', Emoji, true);
|
|
79
|
+
registry.register('formats/image', Image, true);
|
|
80
|
+
registry.register('formats/video', Video, true);
|
|
81
|
+
registry.register('formats/tag', Tag, true);
|
|
82
|
+
registry.register('formats/text-size', TextSize, true);
|
|
83
|
+
|
|
84
|
+
registry.register('formats/import', Import, true);
|
|
85
|
+
|
|
86
|
+
// Register default modules
|
|
87
|
+
registry.register('modules/toolbar', Toolbar, true);
|
|
88
|
+
registry.register('modules/history', History, true);
|
|
89
|
+
registry.register('modules/block-toolbar', BlockToolbar, true);
|
|
90
|
+
registry.register('modules/table-toolbar', TableToolbar, true);
|
|
91
|
+
registry.register('modules/code-view', CodeView, true);
|
|
92
|
+
|
|
93
|
+
registry.register('modules/resize-handles', ResizeHandles, true);
|
|
94
|
+
|
|
95
|
+
// Register UI components
|
|
96
|
+
registry.register('ui/color-picker', ColorPicker, true);
|
|
97
|
+
registry.register('ui/text-align-picker', TextAlignPicker, true);
|
|
98
|
+
registry.register('ui/list-picker', ListPicker, true);
|
|
99
|
+
registry.register('ui/emoji-picker', EmojiPicker, true);
|
|
100
|
+
registry.register('ui/image-popup', ImagePopup, true);
|
|
101
|
+
registry.register('ui/video-popup', VideoPopup, true);
|
|
102
|
+
registry.register('ui/tag-popup', TagPopup, true);
|
|
103
|
+
|
|
104
|
+
registry.register('ui/custom-button', createCustomButton, true);
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
// Load CSS styles
|
|
109
|
+
StylesLoader.loadStyles().catch(error => {
|
|
110
|
+
console.warn('Could not load Rich Editor styles:', error);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// Main Editor class with registration system
|
|
114
|
+
class RichEditor extends Editor {
|
|
115
|
+
/**
|
|
116
|
+
* Register a module, format, or theme
|
|
117
|
+
* @param {string|object} path - Registration path
|
|
118
|
+
* @param {*} definition - Class definition
|
|
119
|
+
* @param {boolean} suppressWarning - Suppress overwrite warnings
|
|
120
|
+
*/
|
|
121
|
+
static register(path, definition, suppressWarning = false) {
|
|
122
|
+
registry.register(path, definition, suppressWarning);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Get registered item
|
|
127
|
+
* @param {string} path - Registration path
|
|
128
|
+
*/
|
|
129
|
+
static get(path) {
|
|
130
|
+
return registry.get(path);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Create new editor instance
|
|
135
|
+
* @param {string|Element} selector - DOM selector or element
|
|
136
|
+
* @param {object} options - Editor options
|
|
137
|
+
*/
|
|
138
|
+
static create(selector, options = {}) {
|
|
139
|
+
return new RichEditor(selector, options);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Export classes for extension
|
|
144
|
+
export {
|
|
145
|
+
RichEditor as default,
|
|
146
|
+
Editor,
|
|
147
|
+
Module,
|
|
148
|
+
Format,
|
|
149
|
+
InlineFormat,
|
|
150
|
+
BlockFormat,
|
|
151
|
+
registry
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// Export formats
|
|
155
|
+
export {
|
|
156
|
+
Bold,
|
|
157
|
+
Italic,
|
|
158
|
+
Underline,
|
|
159
|
+
Strike,
|
|
160
|
+
Subscript,
|
|
161
|
+
Superscript,
|
|
162
|
+
Color,
|
|
163
|
+
Background,
|
|
164
|
+
Link,
|
|
165
|
+
Table,
|
|
166
|
+
Heading,
|
|
167
|
+
FontFamily,
|
|
168
|
+
LineHeight,
|
|
169
|
+
Capitalization,
|
|
170
|
+
TextAlign,
|
|
171
|
+
List,
|
|
172
|
+
Indent,
|
|
173
|
+
IndentIncrease,
|
|
174
|
+
IndentDecrease,
|
|
175
|
+
Emoji,
|
|
176
|
+
Image,
|
|
177
|
+
Video,
|
|
178
|
+
Tag,
|
|
179
|
+
TextSize,
|
|
180
|
+
|
|
181
|
+
Import
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// Export modules
|
|
185
|
+
export {
|
|
186
|
+
Toolbar,
|
|
187
|
+
History,
|
|
188
|
+
BlockToolbar,
|
|
189
|
+
TableToolbar,
|
|
190
|
+
CodeView,
|
|
191
|
+
|
|
192
|
+
ResizeHandles
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// Export UI components
|
|
196
|
+
export {
|
|
197
|
+
ColorPicker,
|
|
198
|
+
IconUtils,
|
|
199
|
+
LinkPopup,
|
|
200
|
+
TablePopup,
|
|
201
|
+
TextAlignPicker,
|
|
202
|
+
ListPicker,
|
|
203
|
+
EmojiPicker,
|
|
204
|
+
ImagePopup,
|
|
205
|
+
VideoPopup,
|
|
206
|
+
TagPopup,
|
|
207
|
+
|
|
208
|
+
createCustomButton
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Utility function to create editor instance
|
|
216
|
+
* @param {string|Element} selector - DOM selector or element
|
|
217
|
+
* @param {object} options - Editor options
|
|
218
|
+
*/
|
|
219
|
+
export function createEditor(selector, options = {}) {
|
|
220
|
+
return new RichEditor(selector, options);
|
|
221
|
+
}
|