autumnnote 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.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +874 -0
  3. package/dist/autumnnote.css +1 -0
  4. package/dist/autumnnote.es.js +5888 -0
  5. package/dist/autumnnote.es.js.map +1 -0
  6. package/dist/autumnnote.umd.js +74 -0
  7. package/dist/autumnnote.umd.js.map +1 -0
  8. package/package.json +55 -0
  9. package/src/js/Context.js +497 -0
  10. package/src/js/core/dom.js +315 -0
  11. package/src/js/core/env.js +25 -0
  12. package/src/js/core/func.js +153 -0
  13. package/src/js/core/key.js +66 -0
  14. package/src/js/core/lists.js +121 -0
  15. package/src/js/core/markdown.js +294 -0
  16. package/src/js/core/range.js +194 -0
  17. package/src/js/core/sanitise.js +78 -0
  18. package/src/js/editing/History.js +205 -0
  19. package/src/js/editing/Style.js +329 -0
  20. package/src/js/editing/Table.js +59 -0
  21. package/src/js/editing/Typing.js +142 -0
  22. package/src/js/index.js +126 -0
  23. package/src/js/module/Buttons.js +300 -0
  24. package/src/js/module/Clipboard.js +460 -0
  25. package/src/js/module/CodeTooltip.js +428 -0
  26. package/src/js/module/Codeview.js +122 -0
  27. package/src/js/module/ContextMenu.js +470 -0
  28. package/src/js/module/Editor.js +528 -0
  29. package/src/js/module/EmojiDialog.js +726 -0
  30. package/src/js/module/FindReplace.js +440 -0
  31. package/src/js/module/Fullscreen.js +80 -0
  32. package/src/js/module/IconDialog.js +620 -0
  33. package/src/js/module/ImageDialog.js +208 -0
  34. package/src/js/module/ImageResizer.js +216 -0
  35. package/src/js/module/ImageTooltip.js +286 -0
  36. package/src/js/module/LinkDialog.js +204 -0
  37. package/src/js/module/LinkTooltip.js +242 -0
  38. package/src/js/module/Placeholder.js +44 -0
  39. package/src/js/module/ShortcutsDialog.js +141 -0
  40. package/src/js/module/Statusbar.js +238 -0
  41. package/src/js/module/TableTooltip.js +568 -0
  42. package/src/js/module/Toolbar.js +562 -0
  43. package/src/js/module/VideoDialog.js +263 -0
  44. package/src/js/module/VideoResizer.js +227 -0
  45. package/src/js/module/VideoTooltip.js +252 -0
  46. package/src/js/renderer.js +107 -0
  47. package/src/js/settings.js +134 -0
  48. package/src/styles/_variables.scss +48 -0
  49. package/src/styles/autumnnote.scss +1740 -0
  50. package/types/index.d.ts +324 -0
@@ -0,0 +1,324 @@
1
+ /**
2
+ * AutumnNote – TypeScript declarations
3
+ * @version 1.0.0
4
+ */
5
+
6
+ // ---------------------------------------------------------------------------
7
+ // Options
8
+ // ---------------------------------------------------------------------------
9
+
10
+ export interface AsnOptions {
11
+ /** Placeholder text when the editor is empty. */
12
+ placeholder?: string;
13
+ /** Editor height in px (sets the min-height of the editable area). */
14
+ height?: number;
15
+ /** Minimum height in px for the editable area. */
16
+ minHeight?: number;
17
+ /** Maximum height in px (0 = unlimited). */
18
+ maxHeight?: number;
19
+ /** Auto-focus the editor on init. */
20
+ focus?: boolean;
21
+ /** Show the resize handle in the statusbar. */
22
+ resizable?: boolean;
23
+ /** Toolbar button group configuration. */
24
+ toolbar?: Array<Array<ButtonDef | DropdownDef>>;
25
+ /** Use Bootstrap button classes on toolbar buttons. */
26
+ useBootstrap?: boolean;
27
+ /** CSS class(es) applied to Bootstrap toolbar buttons. */
28
+ toolbarButtonClass?: string;
29
+ /** Use Font Awesome icons (default: true). */
30
+ useFontAwesome?: boolean;
31
+ /** Font Awesome prefix class, e.g. 'fas' (FA5) or 'fa-solid' (FA6). */
32
+ fontAwesomeClass?: string;
33
+ /** Force plain-text paste — strips all HTML on paste. */
34
+ pasteAsPlainText?: boolean;
35
+ /** Sanitise HTML on paste. */
36
+ pasteCleanHTML?: boolean;
37
+ /** Strip class/style/data-* attributes from pasted HTML (default: false). */
38
+ pasteStripAttributes?: boolean;
39
+ /** Allow file upload in the image dialog. */
40
+ allowImageUpload?: boolean;
41
+ /** Maximum image upload size in MB. */
42
+ maxImageSize?: number;
43
+ /** Number of spaces inserted when Tab is pressed (outside a list). */
44
+ tabSize?: number;
45
+ /** Callback on content change. */
46
+ onChange?: (context: Context) => void;
47
+ /** Callback on editor focus. */
48
+ onFocus?: (context: Context) => void;
49
+ /** Callback fired on editor blur. */
50
+ onBlur?: (context: Context) => void;
51
+ /** Callback after the editor has initialised. */
52
+ onInit?: (context: Context) => void;
53
+ /** Callback fired just before the editor instance is destroyed. */
54
+ onDestroy?: (context: Context) => void;
55
+ /** Callback fired whenever the selection changes inside the editor. */
56
+ onSelectionChange?: (context: Context) => void;
57
+ /** Callback fired when the character limit is reached. */
58
+ onCharLimitReached?: (context: Context) => void;
59
+ /** Callback fired when the word limit is reached. */
60
+ onWordLimitReached?: (context: Context) => void;
61
+ /** Custom image upload handler. */
62
+ onImageUpload?: (files: FileList) => void;
63
+ /** Callback when an image upload error occurs. */
64
+ onImageError?: (error: Error) => void;
65
+ /** Stick the toolbar to the viewport top when scrolling. */
66
+ stickyToolbar?: boolean;
67
+ /** Top offset in px for sticky toolbar (e.g. height of a fixed nav bar). */
68
+ stickyToolbarOffset?: number;
69
+ /** Colour theme: 'light' (default) | 'dark'. */
70
+ theme?: 'light' | 'dark';
71
+ /** Auto-load Prism.js for syntax highlighting inside code blocks. */
72
+ codeHighlight?: boolean;
73
+ /** CDN base URL for Prism assets. */
74
+ codeHighlightCDN?: string;
75
+ /** Convert pasted Markdown text to HTML. */
76
+ markdownPaste?: boolean;
77
+ /** Maximum undo/redo history steps. */
78
+ historyLimit?: number;
79
+ /** Default font family applied to the editable area on init. */
80
+ defaultFontFamily?: string;
81
+ /** Default font size applied to the editable area on init (e.g. '14px'). */
82
+ defaultFontSize?: string;
83
+ /** Font families shown in the font-family toolbar dropdown. */
84
+ fontFamilies?: string[];
85
+ /** Start the editor in read-only (non-editable) mode. */
86
+ readOnly?: boolean;
87
+ /** Enable browser spellcheck in the editable area (default: true). */
88
+ spellcheck?: boolean;
89
+ /** Text direction for the editable area: 'ltr' (default) | 'rtl'. */
90
+ direction?: 'ltr' | 'rtl';
91
+ /** How the toolbar handles overflow: 'wrap' (default) | 'scroll'. */
92
+ toolbarOverflow?: 'wrap' | 'scroll';
93
+ /** Auto-save content to localStorage on every change. */
94
+ autoSave?: boolean;
95
+ /** localStorage key used for auto-save. */
96
+ autoSaveKey?: string;
97
+ /** Maximum character count for the statusbar warning (0 = unlimited). */
98
+ maxChars?: number;
99
+ /** Maximum word count for the statusbar warning (0 = unlimited). */
100
+ maxWords?: number;
101
+ /** Insert a header row (<thead>) when creating new tables. */
102
+ tableHeaderRow?: boolean;
103
+ /** Callback fired after every paste event. */
104
+ onPaste?: (data: { text: string; html: string }) => void;
105
+ /** Additional color swatches shown at the top of the color picker. */
106
+ colorSwatches?: string[];
107
+ }
108
+
109
+ // ---------------------------------------------------------------------------
110
+ // Button / toolbar definitions
111
+ // ---------------------------------------------------------------------------
112
+
113
+ export interface ButtonDef {
114
+ /** Unique identifier used in toolbar config arrays. */
115
+ name: string;
116
+ /** Icon identifier (maps to SVG or Font Awesome class). */
117
+ icon: string;
118
+ /** Tooltip text. */
119
+ tooltip: string;
120
+ /** Action executed when the button is clicked. */
121
+ action: (context: Context) => void;
122
+ /** Returns true when the button should appear "active" (pressed). */
123
+ isActive?: (context: Context) => boolean;
124
+ /** Returns true when the button should be disabled. */
125
+ isDisabled?: (context: Context) => boolean;
126
+ /** Additional CSS class(es) added to the button element. */
127
+ className?: string;
128
+ }
129
+
130
+ export interface DropdownDef {
131
+ /** Unique identifier. */
132
+ name: string;
133
+ /** Must be 'select' to identify as a dropdown. */
134
+ type: 'select';
135
+ /** Tooltip text. */
136
+ tooltip: string;
137
+ /** Static item list (may be overridden at render time from options). */
138
+ items?: string[];
139
+ /** Action executed when a value is selected. */
140
+ action: (context: Context, value: string) => void;
141
+ /** Returns the current value to show as selected. */
142
+ getValue?: (context: Context) => string;
143
+ }
144
+
145
+ // ---------------------------------------------------------------------------
146
+ // Context — per-instance editor hub
147
+ // ---------------------------------------------------------------------------
148
+
149
+ export declare class Context {
150
+ readonly targetEl: HTMLElement;
151
+ readonly options: Required<AsnOptions>;
152
+ readonly layoutInfo: {
153
+ container: HTMLElement;
154
+ editable: HTMLElement;
155
+ toolbar?: HTMLElement;
156
+ statusbar?: HTMLElement;
157
+ };
158
+
159
+ constructor(targetEl: HTMLElement, userOptions?: AsnOptions);
160
+
161
+ /** Initialises the editor (called automatically by AutumnNote.create). */
162
+ initialize(): this;
163
+
164
+ /** Invokes a method on a registered module (e.g. 'editor.bold'). */
165
+ invoke(path: string, ...args: unknown[]): unknown;
166
+
167
+ /** Subscribes to an editor event. Returns an unsubscribe function. */
168
+ on(eventName: string, handler: (...args: unknown[]) => void): () => void;
169
+
170
+ /** Unsubscribes from an editor event. */
171
+ off(eventName: string, handler: (...args: unknown[]) => void): void;
172
+
173
+ /** Triggers an editor event. */
174
+ triggerEvent(eventName: string, ...args: unknown[]): void;
175
+
176
+ /** Returns the current HTML content of the editor. */
177
+ getHTML(): string;
178
+
179
+ /** Sets the HTML content of the editor. */
180
+ setHTML(html: string): void;
181
+
182
+ /** Returns the plain-text content of the editor. */
183
+ getText(): string;
184
+
185
+ /** Sets the editor content from a plain-text string (HTML-escaped). */
186
+ setText(text: string): void;
187
+
188
+ /** Clears the editor content. */
189
+ clear(): void;
190
+
191
+ /**
192
+ * Resets the undo/redo history stack.
193
+ * Useful after programmatically loading content via setHTML() / setMarkdown()
194
+ * so that Ctrl+Z cannot undo back to the previous document.
195
+ */
196
+ clearHistory(): void;
197
+
198
+ /** Returns true when the editor has no meaningful content. */
199
+ isEmpty(): boolean;
200
+
201
+ /** Inserts HTML at the current cursor position. */
202
+ insertHTML(html: string): void;
203
+
204
+ /** Inserts plain text at the current cursor position. */
205
+ insertText(text: string): void;
206
+
207
+ /** Sets editor content from a Markdown string. */
208
+ setMarkdown(md: string): void;
209
+
210
+ /** Returns the editor content as a Markdown string. */
211
+ getMarkdown(): string;
212
+
213
+ /** Returns the current word count of the editor content. */
214
+ getWordCount(): number;
215
+
216
+ /** Returns the current character count (excluding newlines) of the editor content. */
217
+ getCharCount(): number;
218
+
219
+ /** Downloads the editor content as an HTML file. */
220
+ downloadHTML(filename?: string): void;
221
+
222
+ /** Downloads the editor content as a plain-text file. */
223
+ downloadText(filename?: string): void;
224
+
225
+ /** Downloads the editor content as a Markdown file. */
226
+ downloadMarkdown(filename?: string): void;
227
+
228
+ /** Enables or disables (read-only) mode on this instance. */
229
+ setDisabled(disabled: boolean): void;
230
+
231
+ /**
232
+ * Registers and initialises a custom module on this instance.
233
+ * @param name - Key used for ctx.invoke() calls (e.g. 'myModule')
234
+ * @param ModuleClass - Class with `initialize()` and optional `destroy()`
235
+ */
236
+ registerModule(name: string, ModuleClass: new (ctx: Context) => object): this;
237
+
238
+ /** Completely removes the editor and restores the original element. */
239
+ destroy(): void;
240
+ }
241
+
242
+ // ---------------------------------------------------------------------------
243
+ // Pre-built toolbar buttons (re-exported for custom toolbar config)
244
+ // ---------------------------------------------------------------------------
245
+
246
+ export declare const boldBtn: ButtonDef;
247
+ export declare const italicBtn: ButtonDef;
248
+ export declare const underlineBtn: ButtonDef;
249
+ export declare const strikeBtn: ButtonDef;
250
+ export declare const superscriptBtn: ButtonDef;
251
+ export declare const subscriptBtn: ButtonDef;
252
+ export declare const alignLeftBtn: ButtonDef;
253
+ export declare const alignCenterBtn: ButtonDef;
254
+ export declare const alignRightBtn: ButtonDef;
255
+ export declare const alignJustifyBtn: ButtonDef;
256
+ export declare const ulBtn: ButtonDef;
257
+ export declare const olBtn: ButtonDef;
258
+ export declare const indentBtn: ButtonDef;
259
+ export declare const outdentBtn: ButtonDef;
260
+ export declare const undoBtn: ButtonDef;
261
+ export declare const redoBtn: ButtonDef;
262
+ export declare const hrBtn: ButtonDef;
263
+ export declare const linkBtn: ButtonDef;
264
+ export declare const imageBtn: ButtonDef;
265
+ export declare const videoBtn: ButtonDef;
266
+ export declare const tableBtn: ButtonDef;
267
+ export declare const codeBlockBtn: ButtonDef;
268
+ export declare const codeviewBtn: ButtonDef;
269
+ export declare const fullscreenBtn: ButtonDef;
270
+ export declare const emojiBtn: ButtonDef;
271
+ export declare const iconBtn: ButtonDef;
272
+ export declare const shortcutsBtn: ButtonDef;
273
+ export declare const findBtn: ButtonDef;
274
+ export declare const findReplaceBtn: ButtonDef;
275
+ export declare const removeFormatBtn: ButtonDef;
276
+ export declare const directionBtn: ButtonDef;
277
+ export declare const fontFamilyBtn: DropdownDef;
278
+ export declare const fontSizeBtn: DropdownDef;
279
+ export declare const headingBtn: DropdownDef;
280
+ export declare const lineHeightBtn: DropdownDef;
281
+ export declare const paragraphStyleBtn: DropdownDef;
282
+ export declare const foreColorBtn: DropdownDef;
283
+ export declare const backColorBtn: DropdownDef;
284
+ export declare const defaultToolbar: Array<Array<ButtonDef | DropdownDef>>;
285
+
286
+ // ---------------------------------------------------------------------------
287
+ // Main AutumnNote API
288
+ // ---------------------------------------------------------------------------
289
+
290
+ export interface AutumnNoteStatic {
291
+ /**
292
+ * Creates (or returns existing) editor instance(s) on one or more elements.
293
+ * Returns a single Context when one element is matched, or an array otherwise.
294
+ */
295
+ create(selector: string | Element | NodeList | Element[], options?: AsnOptions): Context | Context[];
296
+
297
+ /** Destroys the editor(s) on the given selector. */
298
+ destroy(selector: string | Element | NodeList | Element[]): void;
299
+
300
+ /** Returns the Context for a given element, or null if not initialised. */
301
+ getInstance(selector: string | Element): Context | null;
302
+
303
+ /** Read-only snapshot of the current global defaults. */
304
+ readonly defaults: Readonly<AsnOptions>;
305
+
306
+ /** Merges options into the global defaults (applies to all future instances). */
307
+ setDefaults(overrides: Partial<AsnOptions>): void;
308
+
309
+ /** Restores global defaults back to their original factory values. */
310
+ resetDefaults(): void;
311
+
312
+ /**
313
+ * Registers a custom module to be included in every new editor instance.
314
+ * @param name - Key for `ctx.invoke()` (e.g. 'myPlugin')
315
+ * @param ModuleClass - Class with `initialize()` and optional `destroy()`
316
+ */
317
+ registerModule(name: string, ModuleClass: new (ctx: Context) => object): void;
318
+
319
+ /** Library version string. */
320
+ readonly version: string;
321
+ }
322
+
323
+ declare const AutumnNote: AutumnNoteStatic;
324
+ export default AutumnNote;