@mdaemon/html-editor 1.0.1

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.
@@ -0,0 +1,489 @@
1
+ import { Editor } from '@tiptap/core';
2
+ import { Extension } from '@tiptap/core';
3
+
4
+ declare type BlurCallback = () => void;
5
+
6
+ declare type ChangeCallback = (content: string) => void;
7
+
8
+ export declare const CHAR_MAP: Array<{
9
+ category: string;
10
+ chars: Array<{
11
+ char: string;
12
+ name: string;
13
+ }>;
14
+ }>;
15
+
16
+ export declare class CharacterMap {
17
+ private options;
18
+ private overlay;
19
+ private dialog;
20
+ constructor(options: CharMapOptions);
21
+ open(): void;
22
+ close(): void;
23
+ private createDialog;
24
+ private renderChars;
25
+ destroy(): void;
26
+ }
27
+
28
+ /**
29
+ * Character map character
30
+ */
31
+ export declare interface CharMapChar {
32
+ char: string;
33
+ name: string;
34
+ category?: string;
35
+ }
36
+
37
+ /**
38
+ * CharacterMap
39
+ * Special character picker dialog
40
+ */
41
+ declare interface CharMapOptions {
42
+ onSelect: (char: string) => void;
43
+ trans: (key: string) => string;
44
+ }
45
+
46
+ /**
47
+ * Color picker color
48
+ */
49
+ export declare interface ColorOption {
50
+ value: string;
51
+ label?: string;
52
+ }
53
+
54
+ declare type DirtyCallback = (dirty: boolean) => void;
55
+
56
+ /**
57
+ * Dropbox choose options
58
+ */
59
+ export declare interface DropboxChooseOptions {
60
+ success: (files: DropboxFile[]) => void;
61
+ cancel?: () => void;
62
+ linkType?: 'preview' | 'direct';
63
+ multiselect?: boolean;
64
+ extensions?: string[];
65
+ }
66
+
67
+ /**
68
+ * Dropbox file
69
+ */
70
+ export declare interface DropboxFile {
71
+ name: string;
72
+ link: string;
73
+ bytes: number;
74
+ icon: string;
75
+ thumbnailLink?: string;
76
+ isDir: boolean;
77
+ }
78
+
79
+ /**
80
+ * Main editor configuration
81
+ * Compatible with TinyMCE configuration options
82
+ */
83
+ export declare interface EditorConfig {
84
+ basicEditor?: boolean;
85
+ includeTemplates?: boolean;
86
+ templates?: Template[];
87
+ dropbox?: boolean;
88
+ images_upload_url?: string;
89
+ images_upload_credentials?: boolean;
90
+ images_upload_base_path?: string;
91
+ font_family_formats?: string;
92
+ font_size_formats?: string;
93
+ fontName?: string;
94
+ fontSize?: string;
95
+ directionality?: 'ltr' | 'rtl';
96
+ language?: string;
97
+ height?: string | number;
98
+ auto_focus?: string;
99
+ setFocus?: string;
100
+ skin?: 'oxide' | 'oxide-dark';
101
+ content_css?: 'default' | 'dark';
102
+ content_style?: string;
103
+ toolbar?: string;
104
+ toolbar_mode?: 'sliding' | 'floating' | 'wrap';
105
+ toolbar_sticky?: boolean;
106
+ menubar?: boolean;
107
+ contextmenu?: boolean | string;
108
+ quickbars_selection_toolbar?: string;
109
+ quickbars_image_toolbar?: boolean;
110
+ quickbars_insert_toolbar?: boolean;
111
+ browser_spellcheck?: boolean;
112
+ elementpath?: boolean;
113
+ entity_encoding?: 'raw' | 'named' | 'numeric';
114
+ valid_children?: string;
115
+ convert_unsafe_embeds?: boolean;
116
+ format_empty_lines?: boolean;
117
+ plugins?: string;
118
+ setup?: (editor: MDHTMLEditor) => void;
119
+ }
120
+
121
+ export declare interface EditorEventMap {
122
+ init: InitCallback;
123
+ dirty: DirtyCallback;
124
+ change: ChangeCallback;
125
+ focus: FocusCallback;
126
+ blur: BlurCallback;
127
+ }
128
+
129
+ export declare interface EditorEvents {
130
+ init?: InitCallback;
131
+ dirty?: DirtyCallback;
132
+ change?: ChangeCallback;
133
+ focus?: FocusCallback;
134
+ blur?: BlurCallback;
135
+ }
136
+
137
+ export declare const EMOJI_CATEGORIES: Array<{
138
+ category: string;
139
+ icon: string;
140
+ emojis: string[];
141
+ }>;
142
+
143
+ export declare class EmojiPicker {
144
+ private options;
145
+ private overlay;
146
+ private dialog;
147
+ private searchInput;
148
+ constructor(options: EmojiPickerOptions);
149
+ open(): void;
150
+ close(): void;
151
+ private createDialog;
152
+ private renderEmojis;
153
+ destroy(): void;
154
+ }
155
+
156
+ /**
157
+ * EmojiPicker
158
+ * Emoji selection dialog
159
+ */
160
+ declare interface EmojiPickerOptions {
161
+ onSelect: (emoji: string) => void;
162
+ trans: (key: string) => string;
163
+ }
164
+
165
+ declare type FocusCallback = () => void;
166
+
167
+ export declare const fontNames = "Andale Mono=andale mono,times; Arial=arial,helvetica,sans-serif; Arial Black=arial black,avant garde; Book Antiqua=book antiqua,palatino; Comic Sans MS=comic sans ms,sans-serif; Courier New=courier new,courier; Georgia=georgia,palatino; Helvetica=helvetica; Impact=impact,chicago; Tahoma=tahoma,arial,helvetica,sans-serif; Terminal=terminal,monaco; Times New Roman=times new roman,times; Trebuchet MS=trebuchet ms,geneva; Verdana=verdana,geneva";
168
+
169
+ /**
170
+ * Font option
171
+ */
172
+ export declare interface FontOption {
173
+ label: string;
174
+ value: string;
175
+ }
176
+
177
+ export declare const FontSize: Extension<FontSizeOptions, any>;
178
+
179
+ declare interface FontSizeOptions {
180
+ types: string[];
181
+ }
182
+
183
+ /**
184
+ * Get global file source resolver
185
+ */
186
+ export declare function getGetFileSrc(): (path: string) => string;
187
+
188
+ /**
189
+ * Get global translation function
190
+ */
191
+ export declare function getTranslate(): TranslateFunction;
192
+
193
+ /**
194
+ * Global configuration
195
+ */
196
+ export declare interface GlobalConfig {
197
+ translate?: TranslateFunction;
198
+ getFileSrc?: (path: string) => string;
199
+ }
200
+
201
+ /**
202
+ * MDHTMLEditor - Main editor class
203
+ */
204
+ export declare class HTMLEditor implements MDHTMLEditor {
205
+ readonly id: string;
206
+ readonly ui: {
207
+ registry: UIRegistry;
208
+ };
209
+ private tiptap;
210
+ private container;
211
+ private editorWrapper;
212
+ private toolbar;
213
+ private config;
214
+ private dirty;
215
+ private customButtons;
216
+ private eventListeners;
217
+ private changeTimeout;
218
+ constructor(container: HTMLElement, config?: EditorConfig);
219
+ private normalizeConfig;
220
+ private createEditor;
221
+ private buildExtensions;
222
+ private handleChange;
223
+ getContent(): string;
224
+ setContent(html: string): void;
225
+ insertContent(html: string): void;
226
+ execCommand(command: string, _ui?: boolean, value?: unknown): boolean;
227
+ isDirty(): boolean;
228
+ setDirty(state: boolean): void;
229
+ focus(): void;
230
+ hasFocus(): boolean;
231
+ on<K extends keyof EditorEventMap>(event: K, callback: EditorEventMap[K]): void;
232
+ off<K extends keyof EditorEventMap>(event: K, callback: EditorEventMap[K]): void;
233
+ fire<K extends keyof EditorEventMap>(event: K, ...args: Parameters<EditorEventMap[K]>): void;
234
+ destroy(): void;
235
+ getTipTap(): Editor | null;
236
+ /**
237
+ * Get the editor config
238
+ */
239
+ getConfig(): EditorConfig;
240
+ /**
241
+ * Check if the editor is in basic mode
242
+ */
243
+ isBasicEditor(): boolean;
244
+ }
245
+
246
+ /**
247
+ * Image upload handler
248
+ */
249
+ export declare type ImageUploadHandler = (blobInfo: {
250
+ blob: () => Blob;
251
+ filename: () => string;
252
+ }, progress: (percent: number) => void) => Promise<ImageUploadResult>;
253
+
254
+ /**
255
+ * Image upload result
256
+ */
257
+ export declare interface ImageUploadResult {
258
+ location: string;
259
+ }
260
+
261
+ /**
262
+ * Event callback types
263
+ */
264
+ declare type InitCallback = (editor: MDHTMLEditor) => void;
265
+
266
+ export declare const LineHeight: Extension<LineHeightOptions, any>;
267
+
268
+ declare interface LineHeightOptions {
269
+ types: string[];
270
+ defaultLineHeight: string;
271
+ }
272
+
273
+ /**
274
+ * Main HTMLEditor class interface
275
+ */
276
+ export declare interface MDHTMLEditor {
277
+ readonly id: string;
278
+ readonly ui: {
279
+ registry: UIRegistry;
280
+ };
281
+ getContent(): string;
282
+ setContent(html: string): void;
283
+ insertContent(html: string): void;
284
+ execCommand(command: string, ui?: boolean, value?: unknown): boolean;
285
+ isDirty(): boolean;
286
+ setDirty(state: boolean): void;
287
+ focus(): void;
288
+ hasFocus(): boolean;
289
+ on<K extends keyof EditorEventMap>(event: K, callback: EditorEventMap[K]): void;
290
+ off<K extends keyof EditorEventMap>(event: K, callback: EditorEventMap[K]): void;
291
+ fire<K extends keyof EditorEventMap>(event: K, ...args: Parameters<EditorEventMap[K]>): void;
292
+ destroy(): void;
293
+ getTipTap(): Editor | null;
294
+ }
295
+
296
+ export declare class SearchReplace {
297
+ private options;
298
+ private overlay;
299
+ private dialog;
300
+ private searchInput;
301
+ private replaceInput;
302
+ private currentResults;
303
+ private currentIndex;
304
+ private caseSensitive;
305
+ private wholeWord;
306
+ constructor(options: SearchReplaceOptions_2);
307
+ private get tiptap();
308
+ open(): void;
309
+ close(): void;
310
+ private createDialog;
311
+ private doSearch;
312
+ private updateCount;
313
+ private highlightCurrent;
314
+ private clearHighlights;
315
+ findNext(): void;
316
+ findPrevious(): void;
317
+ replaceCurrent(): void;
318
+ replaceAll(): void;
319
+ destroy(): void;
320
+ }
321
+
322
+ /**
323
+ * Search/Replace options
324
+ */
325
+ export declare interface SearchReplaceOptions {
326
+ caseSensitive?: boolean;
327
+ wholeWord?: boolean;
328
+ }
329
+
330
+ declare interface SearchReplaceOptions_2 {
331
+ editor: HTMLEditor;
332
+ trans: (key: string) => string;
333
+ }
334
+
335
+ /**
336
+ * Set global file source resolver
337
+ */
338
+ export declare function setGetFileSrc(fn: (path: string) => string): void;
339
+
340
+ /**
341
+ * Set global translation function
342
+ */
343
+ export declare function setTranslate(fn: TranslateFunction): void;
344
+
345
+ /**
346
+ * Template object for email templates
347
+ */
348
+ export declare interface Template {
349
+ id?: number | string;
350
+ title: string;
351
+ description?: string;
352
+ content: string;
353
+ }
354
+
355
+ export declare const TextDirection: Extension<TextDirectionOptions, any>;
356
+
357
+ declare interface TextDirectionOptions {
358
+ types: string[];
359
+ defaultDirection: 'ltr' | 'rtl';
360
+ }
361
+
362
+ export declare class Toolbar {
363
+ private container;
364
+ private options;
365
+ private state;
366
+ private buttonElements;
367
+ private dropdowns;
368
+ private charMap;
369
+ private emojiPicker;
370
+ private searchReplace;
371
+ private updateInterval;
372
+ constructor(container: HTMLElement, options: ToolbarOptions);
373
+ private get tiptap();
374
+ private get trans();
375
+ private render;
376
+ private createButton;
377
+ private createActionButton;
378
+ private createCustomButton;
379
+ private createFontFamilyDropdown;
380
+ private createFontSizeDropdown;
381
+ private createLineHeightDropdown;
382
+ private createTemplateDropdown;
383
+ private createDropdown;
384
+ private createColorPicker;
385
+ private bindEvents;
386
+ private closeAllDropdowns;
387
+ private startStateUpdates;
388
+ private updateButtonStates;
389
+ private openImageDialog;
390
+ private openLinkDialog;
391
+ private openCharMap;
392
+ private openEmojiPicker;
393
+ private openSearchReplace;
394
+ private openSourceCode;
395
+ private openPreview;
396
+ private toggleFullscreen;
397
+ destroy(): void;
398
+ }
399
+
400
+ export declare interface ToolbarButtonAPI {
401
+ isEnabled: () => boolean;
402
+ setEnabled: (enabled: boolean) => void;
403
+ isActive: () => boolean;
404
+ setActive: (active: boolean) => void;
405
+ }
406
+
407
+ /**
408
+ * Custom toolbar button definition
409
+ */
410
+ export declare interface ToolbarButtonSpec {
411
+ tooltip?: string;
412
+ icon?: string;
413
+ text?: string;
414
+ onSetup?: (api: ToolbarButtonAPI) => void | (() => void);
415
+ onAction?: (api: ToolbarButtonAPI) => void;
416
+ disabled?: boolean;
417
+ }
418
+
419
+ declare interface ToolbarOptions {
420
+ editor: HTMLEditor;
421
+ buttons: string;
422
+ mode: 'sliding' | 'floating' | 'wrap';
423
+ sticky: boolean;
424
+ customButtons: Map<string, ToolbarButtonSpec>;
425
+ config: EditorConfig;
426
+ }
427
+
428
+ /**
429
+ * Translation function type
430
+ */
431
+ export declare type TranslateFunction = (key: string) => string;
432
+
433
+ /**
434
+ * UI Registry for custom buttons (TinyMCE-compatible)
435
+ */
436
+ export declare interface UIRegistry {
437
+ addButton: (name: string, spec: ToolbarButtonSpec) => void;
438
+ getButton: (name: string) => ToolbarButtonSpec | undefined;
439
+ }
440
+
441
+ export { }
442
+
443
+
444
+ declare module '@tiptap/core' {
445
+ interface Commands<ReturnType> {
446
+ fontSize: {
447
+ /**
448
+ * Set the font size
449
+ */
450
+ setFontSize: (size: string) => ReturnType;
451
+ /**
452
+ * Unset the font size
453
+ */
454
+ unsetFontSize: () => ReturnType;
455
+ };
456
+ }
457
+ }
458
+
459
+
460
+ declare module '@tiptap/core' {
461
+ interface Commands<ReturnType> {
462
+ lineHeight: {
463
+ /**
464
+ * Set the line height
465
+ */
466
+ setLineHeight: (lineHeight: string) => ReturnType;
467
+ /**
468
+ * Unset the line height
469
+ */
470
+ unsetLineHeight: () => ReturnType;
471
+ };
472
+ }
473
+ }
474
+
475
+
476
+ declare module '@tiptap/core' {
477
+ interface Commands<ReturnType> {
478
+ textDirection: {
479
+ /**
480
+ * Set the text direction
481
+ */
482
+ setTextDirection: (direction: 'ltr' | 'rtl' | 'auto') => ReturnType;
483
+ /**
484
+ * Unset the text direction
485
+ */
486
+ unsetTextDirection: () => ReturnType;
487
+ };
488
+ }
489
+ }