@oix1987/yjd 1.0.3 → 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/{dist → lib}/styles.css +1285 -35
  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 -32
  70. package/umd-entry.js +18 -0
package/index.d.ts CHANGED
@@ -1,103 +1,134 @@
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
- }
1
+ // Type definitions for @oix1987/yjd
2
+ // These declarations are the package entry types (referenced via "types" in package.json),
3
+ // so they are declared at top level rather than wrapped in `declare module`.
4
+
5
+ // Editor options interface
6
+ export interface EditorOptions {
7
+ placeholder?: string;
8
+ theme?: string;
9
+ height?: number;
10
+ width?: number;
11
+ maxWidth?: number;
12
+ maxHeight?: number;
13
+ content?: string | null;
14
+ onChange?: (content: string) => void;
15
+ /** When true, paste always inserts plain text (default: false). */
16
+ pasteAsPlainText?: boolean;
17
+ /** Accessible label for the editable region (defaults to placeholder). */
18
+ ariaLabel?: string;
19
+ /** Maximum number of characters allowed. */
20
+ maxLength?: number;
21
+ /** Initial text direction. */
22
+ direction?: 'ltr' | 'rtl';
23
+ /** Enable markdown shortcuts (default: true). Set false to disable. */
24
+ markdown?: boolean;
25
+ /** Autosave drafts to localStorage. true, or { key, debounce(ms) }. */
26
+ autosave?: boolean | { key?: string; debounce?: number };
27
+ features?: {
28
+ emoji?: boolean;
29
+ image?: boolean;
30
+ table?: boolean;
31
+ wordCount?: boolean;
32
+ breadcrumb?: boolean;
33
+ };
34
+ toolbar1?: Array<{
35
+ group: string;
36
+ items: string[];
37
+ }>;
38
+ toolbar2?: Array<{
39
+ group: string;
40
+ items: string[];
41
+ }>;
42
+ }
43
+
44
+ export class Editor {
45
+ constructor(selector: string | Element, options?: EditorOptions);
46
+ on(event: string, handler: (data: any) => void): void;
47
+ off(event: string, handler: (data: any) => void): void;
48
+ emit(event: string, data: any): void;
49
+ getContent(): string;
50
+ setContent(content: string): void;
51
+ getText(): string;
52
+ isEmpty(): boolean;
53
+ clear(): void;
54
+ insertText(text: string): void;
55
+ insertHTML(html: string): void;
56
+ clearFormatting(): void;
57
+ insertHorizontalRule(): void;
58
+ insertImageFile(file: File): void;
59
+ setReadOnly(readOnly: boolean): void;
60
+ isReadOnly(): boolean;
61
+ setDirection(dir: 'ltr' | 'rtl'): void;
62
+ getDirection(): 'ltr' | 'rtl';
63
+ toggleDirection(): void;
64
+ clearAutosave(): void;
65
+ focus(): void;
66
+ destroy(): void;
67
+ }
68
+
69
+ export class Module {}
70
+ export class Format {}
71
+ export class InlineFormat extends Format {}
72
+ export class BlockFormat extends Format {}
73
+ export const registry: any;
74
+
75
+ export class RichEditor extends Editor {
76
+ static register(path: string, definition: any, suppressWarning?: boolean): void;
77
+ static get(path: string): any;
78
+ static create(selector: string | Element, options?: EditorOptions): RichEditor;
79
+ }
80
+
81
+ export function createEditor(selector: string | Element, options?: EditorOptions): RichEditor;
82
+
83
+ // Formats
84
+ export const Bold: any;
85
+ export const Italic: any;
86
+ export const Underline: any;
87
+ export const Strike: any;
88
+ export const Subscript: any;
89
+ export const Superscript: any;
90
+ export const Color: any;
91
+ export const Background: any;
92
+ export const Link: any;
93
+ export const Table: any;
94
+ export const Heading: any;
95
+ export const FontFamily: any;
96
+ export const LineHeight: any;
97
+ export const Capitalization: any;
98
+ export const TextAlign: any;
99
+ export const List: any;
100
+ export const Indent: any;
101
+ export const IndentIncrease: any;
102
+ export const IndentDecrease: any;
103
+ export const Emoji: any;
104
+ export const Image: any;
105
+ export const Video: any;
106
+ export const Tag: any;
107
+ export const TextSize: any;
108
+ export const Import: any;
109
+
110
+ // Modules
111
+ export const Toolbar: any;
112
+ export const History: any;
113
+ export const BlockToolbar: any;
114
+ export const TableToolbar: any;
115
+ export const CodeView: any;
116
+ export const FindReplace: any;
117
+ export const SlashMenu: any;
118
+ export const ResizeHandles: any;
119
+
120
+ // UI components
121
+ export const ColorPicker: any;
122
+ export const IconUtils: any;
123
+ export const LinkPopup: any;
124
+ export const TablePopup: any;
125
+ export const TextAlignPicker: any;
126
+ export const ListPicker: any;
127
+ export const EmojiPicker: any;
128
+ export const ImagePopup: any;
129
+ export const VideoPopup: any;
130
+ export const TagPopup: any;
131
+
132
+ export const createCustomButton: any;
133
+
134
+ export default RichEditor;
package/index.js ADDED
@@ -0,0 +1,227 @@
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
+ import FindReplace from './lib/modules/find-replace.js';
40
+ import SlashMenu from './lib/modules/slash-menu.js';
41
+
42
+ import ResizeHandles from './lib/modules/resize-handles.js';
43
+
44
+ // Import UI components
45
+ import ColorPicker from './lib/ui/color-picker.js';
46
+ import IconUtils from './lib/ui/icons.js';
47
+ import LinkPopup from './lib/ui/link-popup.js';
48
+ import TablePopup from './lib/ui/table-popup.js';
49
+ import TextAlignPicker from './lib/ui/text-align-picker.js';
50
+ import ListPicker from './lib/ui/list-picker.js';
51
+ import EmojiPicker from './lib/ui/emoji-picker.js';
52
+ import ImagePopup from './lib/ui/image-popup.js';
53
+ import VideoPopup from './lib/ui/video-popup.js';
54
+ import TagPopup from './lib/ui/tag-popup.js';
55
+
56
+ import createCustomButton from './lib/ui/select-button.js';
57
+
58
+
59
+
60
+ // Register default formats
61
+ registry.register('formats/bold', Bold, true);
62
+ registry.register('formats/italic', Italic, true);
63
+ registry.register('formats/underline', Underline, true);
64
+ registry.register('formats/strike', Strike, true);
65
+ registry.register('formats/subscript', Subscript, true);
66
+ registry.register('formats/superscript', Superscript, true);
67
+ registry.register('formats/color', Color, true);
68
+ registry.register('formats/background', Background, true);
69
+ registry.register('formats/link', Link, true);
70
+ registry.register('formats/table', Table, true);
71
+ registry.register('formats/heading', Heading, true);
72
+ registry.register('formats/font-family', FontFamily, true);
73
+ registry.register('formats/line-height', LineHeight, true);
74
+ registry.register('formats/capitalization', Capitalization, true);
75
+ registry.register('formats/text-align', TextAlign, true);
76
+ registry.register('formats/list', List, true);
77
+ registry.register('formats/indent', Indent, true);
78
+ registry.register('formats/indent-increase', IndentIncrease, true);
79
+ registry.register('formats/indent-decrease', IndentDecrease, true);
80
+ registry.register('formats/emoji', Emoji, true);
81
+ registry.register('formats/image', Image, true);
82
+ registry.register('formats/video', Video, true);
83
+ registry.register('formats/tag', Tag, true);
84
+ registry.register('formats/text-size', TextSize, true);
85
+
86
+ registry.register('formats/import', Import, true);
87
+
88
+ // Register default modules
89
+ registry.register('modules/toolbar', Toolbar, true);
90
+ registry.register('modules/history', History, true);
91
+ registry.register('modules/block-toolbar', BlockToolbar, true);
92
+ registry.register('modules/table-toolbar', TableToolbar, true);
93
+ registry.register('modules/code-view', CodeView, true);
94
+ registry.register('modules/find-replace', FindReplace, true);
95
+ registry.register('modules/slash-menu', SlashMenu, true);
96
+
97
+ registry.register('modules/resize-handles', ResizeHandles, true);
98
+
99
+ // Register UI components
100
+ registry.register('ui/color-picker', ColorPicker, true);
101
+ registry.register('ui/text-align-picker', TextAlignPicker, true);
102
+ registry.register('ui/list-picker', ListPicker, true);
103
+ registry.register('ui/emoji-picker', EmojiPicker, true);
104
+ registry.register('ui/image-popup', ImagePopup, true);
105
+ registry.register('ui/video-popup', VideoPopup, true);
106
+ registry.register('ui/tag-popup', TagPopup, true);
107
+
108
+ registry.register('ui/custom-button', createCustomButton, true);
109
+
110
+
111
+
112
+ // Load CSS styles
113
+ StylesLoader.loadStyles().catch(error => {
114
+ console.warn('Could not load Rich Editor styles:', error);
115
+ });
116
+
117
+ // Main Editor class with registration system
118
+ class RichEditor extends Editor {
119
+ /**
120
+ * Register a module, format, or theme
121
+ * @param {string|object} path - Registration path
122
+ * @param {*} definition - Class definition
123
+ * @param {boolean} suppressWarning - Suppress overwrite warnings
124
+ */
125
+ static register(path, definition, suppressWarning = false) {
126
+ registry.register(path, definition, suppressWarning);
127
+ }
128
+
129
+ /**
130
+ * Get registered item
131
+ * @param {string} path - Registration path
132
+ */
133
+ static get(path) {
134
+ return registry.get(path);
135
+ }
136
+
137
+ /**
138
+ * Create new editor instance
139
+ * @param {string|Element} selector - DOM selector or element
140
+ * @param {object} options - Editor options
141
+ */
142
+ static create(selector, options = {}) {
143
+ return new RichEditor(selector, options);
144
+ }
145
+ }
146
+
147
+ // Export classes for extension
148
+ export {
149
+ RichEditor as default,
150
+ Editor,
151
+ Module,
152
+ Format,
153
+ InlineFormat,
154
+ BlockFormat,
155
+ registry
156
+ };
157
+
158
+ // Export formats
159
+ export {
160
+ Bold,
161
+ Italic,
162
+ Underline,
163
+ Strike,
164
+ Subscript,
165
+ Superscript,
166
+ Color,
167
+ Background,
168
+ Link,
169
+ Table,
170
+ Heading,
171
+ FontFamily,
172
+ LineHeight,
173
+ Capitalization,
174
+ TextAlign,
175
+ List,
176
+ Indent,
177
+ IndentIncrease,
178
+ IndentDecrease,
179
+ Emoji,
180
+ Image,
181
+ Video,
182
+ Tag,
183
+ TextSize,
184
+
185
+ Import
186
+ };
187
+
188
+ // Export modules
189
+ export {
190
+ Toolbar,
191
+ History,
192
+ BlockToolbar,
193
+ TableToolbar,
194
+ CodeView,
195
+ FindReplace,
196
+ SlashMenu,
197
+
198
+ ResizeHandles
199
+ };
200
+
201
+ // Export UI components
202
+ export {
203
+ ColorPicker,
204
+ IconUtils,
205
+ LinkPopup,
206
+ TablePopup,
207
+ TextAlignPicker,
208
+ ListPicker,
209
+ EmojiPicker,
210
+ ImagePopup,
211
+ VideoPopup,
212
+ TagPopup,
213
+
214
+ createCustomButton
215
+ };
216
+
217
+
218
+
219
+
220
+ /**
221
+ * Utility function to create editor instance
222
+ * @param {string|Element} selector - DOM selector or element
223
+ * @param {object} options - Editor options
224
+ */
225
+ export function createEditor(selector, options = {}) {
226
+ return new RichEditor(selector, options);
227
+ }