mardora 1.2.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/LICENSE +21 -0
- package/README.md +113 -0
- package/dist/chunk-3OCUX4OO.js +7690 -0
- package/dist/chunk-3OCUX4OO.js.map +1 -0
- package/dist/chunk-3ZOCCFDL.cjs +74 -0
- package/dist/chunk-3ZOCCFDL.cjs.map +1 -0
- package/dist/chunk-7JOEPNEV.cjs +7740 -0
- package/dist/chunk-7JOEPNEV.cjs.map +1 -0
- package/dist/chunk-BIKZQZ6W.js +33 -0
- package/dist/chunk-BIKZQZ6W.js.map +1 -0
- package/dist/chunk-EQJESPP2.js +234 -0
- package/dist/chunk-EQJESPP2.js.map +1 -0
- package/dist/chunk-G4SE26YY.js +70 -0
- package/dist/chunk-G4SE26YY.js.map +1 -0
- package/dist/chunk-KNDWF2DP.cjs +35 -0
- package/dist/chunk-KNDWF2DP.cjs.map +1 -0
- package/dist/chunk-MLBEBFHB.cjs +2971 -0
- package/dist/chunk-MLBEBFHB.cjs.map +1 -0
- package/dist/chunk-P7JFCYU3.js +905 -0
- package/dist/chunk-P7JFCYU3.js.map +1 -0
- package/dist/chunk-SWFUKJDO.cjs +243 -0
- package/dist/chunk-SWFUKJDO.cjs.map +1 -0
- package/dist/chunk-WFVCG4LD.cjs +926 -0
- package/dist/chunk-WFVCG4LD.cjs.map +1 -0
- package/dist/chunk-XL6WFGJT.js +2901 -0
- package/dist/chunk-XL6WFGJT.js.map +1 -0
- package/dist/editor/index.cjs +277 -0
- package/dist/editor/index.cjs.map +1 -0
- package/dist/editor/index.d.cts +186 -0
- package/dist/editor/index.d.ts +186 -0
- package/dist/editor/index.js +4 -0
- package/dist/editor/index.js.map +1 -0
- package/dist/index.cjs +405 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/index.cjs +12 -0
- package/dist/lib/index.cjs.map +1 -0
- package/dist/lib/index.d.cts +16 -0
- package/dist/lib/index.d.ts +16 -0
- package/dist/lib/index.js +3 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/mardora-DCwjomil.d.cts +640 -0
- package/dist/mardora-DCwjomil.d.ts +640 -0
- package/dist/plugins/index.cjs +104 -0
- package/dist/plugins/index.cjs.map +1 -0
- package/dist/plugins/index.d.cts +740 -0
- package/dist/plugins/index.d.ts +740 -0
- package/dist/plugins/index.js +7 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/preview/index.cjs +38 -0
- package/dist/preview/index.cjs.map +1 -0
- package/dist/preview/index.d.cts +101 -0
- package/dist/preview/index.d.ts +101 -0
- package/dist/preview/index.js +5 -0
- package/dist/preview/index.js.map +1 -0
- package/dist/types-NBsaxl4d.d.cts +71 -0
- package/dist/types-Pw2SWWAR.d.ts +71 -0
- package/package.json +92 -0
- package/src/editor/attachments/extension.ts +181 -0
- package/src/editor/attachments/format.ts +63 -0
- package/src/editor/attachments/index.ts +3 -0
- package/src/editor/attachments/types.ts +37 -0
- package/src/editor/heading-fold/config.ts +25 -0
- package/src/editor/heading-fold/extension.ts +268 -0
- package/src/editor/heading-fold/extract.ts +88 -0
- package/src/editor/heading-fold/index.ts +5 -0
- package/src/editor/heading-fold/theme.ts +85 -0
- package/src/editor/heading-fold/types.ts +24 -0
- package/src/editor/i18n.ts +13 -0
- package/src/editor/icons/index.ts +367 -0
- package/src/editor/index.ts +16 -0
- package/src/editor/mardora.ts +257 -0
- package/src/editor/media-lightbox-theme.ts +146 -0
- package/src/editor/media-lightbox.ts +125 -0
- package/src/editor/plugin.ts +294 -0
- package/src/editor/selection-toolbar/activation.ts +123 -0
- package/src/editor/selection-toolbar/commands.ts +279 -0
- package/src/editor/selection-toolbar/extension.ts +564 -0
- package/src/editor/selection-toolbar/i18n.ts +164 -0
- package/src/editor/selection-toolbar/index.ts +7 -0
- package/src/editor/selection-toolbar/menu.ts +252 -0
- package/src/editor/selection-toolbar/position.ts +43 -0
- package/src/editor/selection-toolbar/theme.ts +195 -0
- package/src/editor/selection-toolbar/types.ts +155 -0
- package/src/editor/slash/default-commands.ts +190 -0
- package/src/editor/slash/extension.ts +319 -0
- package/src/editor/slash/index.ts +7 -0
- package/src/editor/slash/insertions.ts +26 -0
- package/src/editor/slash/menu.ts +123 -0
- package/src/editor/slash/position.ts +61 -0
- package/src/editor/slash/query.ts +33 -0
- package/src/editor/slash/theme.ts +113 -0
- package/src/editor/slash/types.ts +40 -0
- package/src/editor/table-of-contents/extension.ts +202 -0
- package/src/editor/table-of-contents/extract.ts +53 -0
- package/src/editor/table-of-contents/index.ts +7 -0
- package/src/editor/table-of-contents/panel.ts +83 -0
- package/src/editor/table-of-contents/slug.ts +50 -0
- package/src/editor/table-of-contents/storage.ts +35 -0
- package/src/editor/table-of-contents/theme.ts +153 -0
- package/src/editor/table-of-contents/types.ts +44 -0
- package/src/editor/theme.ts +72 -0
- package/src/editor/utils.ts +176 -0
- package/src/editor/view-plugin.ts +189 -0
- package/src/index.ts +5 -0
- package/src/lib/index.ts +2 -0
- package/src/lib/input-handler.ts +47 -0
- package/src/plugins/code-plugin.theme.ts +545 -0
- package/src/plugins/code-plugin.ts +1892 -0
- package/src/plugins/emoji-plugin.ts +140 -0
- package/src/plugins/heading-plugin.ts +194 -0
- package/src/plugins/hr-plugin.ts +102 -0
- package/src/plugins/html-plugin.ts +353 -0
- package/src/plugins/image-plugin.ts +806 -0
- package/src/plugins/index.ts +71 -0
- package/src/plugins/inline-plugin.ts +311 -0
- package/src/plugins/link-plugin.ts +509 -0
- package/src/plugins/list-plugin.ts +492 -0
- package/src/plugins/math-plugin.ts +526 -0
- package/src/plugins/mermaid-plugin.ts +513 -0
- package/src/plugins/paragraph-plugin.ts +38 -0
- package/src/plugins/quote-plugin.ts +733 -0
- package/src/plugins/table-controls-theme.ts +126 -0
- package/src/plugins/table-controls.ts +423 -0
- package/src/plugins/table-model.ts +661 -0
- package/src/plugins/table-plugin.ts +2111 -0
- package/src/preview/context.ts +45 -0
- package/src/preview/css-generator.ts +64 -0
- package/src/preview/default-renderers.ts +29 -0
- package/src/preview/index.ts +29 -0
- package/src/preview/preview.ts +41 -0
- package/src/preview/renderer.ts +184 -0
- package/src/preview/syntax-theme.ts +112 -0
- package/src/preview/toc.ts +23 -0
- package/src/preview/types.ts +89 -0
|
@@ -0,0 +1,640 @@
|
|
|
1
|
+
import * as _codemirror_state from '@codemirror/state';
|
|
2
|
+
import { Range, Extension } from '@codemirror/state';
|
|
3
|
+
import { EditorView, Decoration, KeyBinding, ViewUpdate } from '@codemirror/view';
|
|
4
|
+
import { MarkdownConfig } from '@lezer/markdown';
|
|
5
|
+
import * as _lezer_highlight from '@lezer/highlight';
|
|
6
|
+
import { SyntaxNode } from '@lezer/common';
|
|
7
|
+
import { StyleSpec } from 'style-mod';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Deep merge two objects
|
|
11
|
+
* @param a - First object
|
|
12
|
+
* @param b - Second object
|
|
13
|
+
* @returns Merged object
|
|
14
|
+
*/
|
|
15
|
+
declare function deepMerge<T>(a: T, b?: T): T;
|
|
16
|
+
/**
|
|
17
|
+
* Theme style
|
|
18
|
+
*/
|
|
19
|
+
type ThemeStyle = {
|
|
20
|
+
[selector: string]: StyleSpec;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Theme Enum
|
|
24
|
+
*/
|
|
25
|
+
declare enum ThemeEnum {
|
|
26
|
+
DARK = "dark",
|
|
27
|
+
LIGHT = "light",
|
|
28
|
+
AUTO = "auto"
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Function to create the themes
|
|
32
|
+
*
|
|
33
|
+
* @param defaultTheme - Default theme -- Always applied
|
|
34
|
+
* @param darkTheme - Dark theme -- Applied when theme is "dark" or "auto" and system is dark
|
|
35
|
+
* @param lightTheme - Light theme -- Applied when theme is "light" or "auto" and system is light
|
|
36
|
+
* @returns Theme function
|
|
37
|
+
*/
|
|
38
|
+
declare function createTheme({ default: defaultTheme, dark: darkTheme, light: lightTheme, }: {
|
|
39
|
+
default: ThemeStyle;
|
|
40
|
+
dark?: ThemeStyle;
|
|
41
|
+
light?: ThemeStyle;
|
|
42
|
+
}): (theme: ThemeEnum) => ThemeStyle;
|
|
43
|
+
declare function flattenThemeStyles(themeStyles: ThemeStyle, parentSelector?: string): ThemeStyle;
|
|
44
|
+
declare function fixSelector(selector: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* Check if cursor is within the given range
|
|
47
|
+
*/
|
|
48
|
+
declare function cursorInRange(view: EditorView, from: number, to: number): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Check if any selection overlaps with the given range
|
|
51
|
+
*/
|
|
52
|
+
declare function selectionOverlapsRange(view: EditorView, from: number, to: number): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Toggle markdown style on selection or insert markers at cursor
|
|
55
|
+
* @param marker - The markdown marker (e.g., "**" for bold, "*" for italic)
|
|
56
|
+
* @returns Command function for EditorView
|
|
57
|
+
*/
|
|
58
|
+
declare function toggleMarkdownStyle(marker: string): (view: EditorView) => boolean;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Context passed to plugin lifecycle methods
|
|
62
|
+
*/
|
|
63
|
+
interface PluginContext {
|
|
64
|
+
/** Current configuration */
|
|
65
|
+
readonly config: MardoraConfig;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Plugin configuration schema
|
|
69
|
+
*/
|
|
70
|
+
interface PluginConfig {
|
|
71
|
+
[key: string]: unknown;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Decoration context passed to plugin decoration builders
|
|
75
|
+
* Provides access to view state and decoration collection
|
|
76
|
+
*/
|
|
77
|
+
interface DecorationContext {
|
|
78
|
+
/** The EditorView instance (readonly) */
|
|
79
|
+
readonly view: EditorView;
|
|
80
|
+
/** Array to push decorations into (will be sorted automatically) */
|
|
81
|
+
readonly decorations: Range<Decoration>[];
|
|
82
|
+
/** Check if selection overlaps with a range (to show raw markdown) */
|
|
83
|
+
selectionOverlapsRange(from: number, to: number): boolean;
|
|
84
|
+
/** Check if cursor is within a range */
|
|
85
|
+
cursorInRange(from: number, to: number): boolean;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Abstract base class for all mardora plugins
|
|
89
|
+
*
|
|
90
|
+
* Implements OOP principles:
|
|
91
|
+
* - Abstraction: abstract name/version must be implemented by subclasses
|
|
92
|
+
* - Encapsulation: private _config, protected _context
|
|
93
|
+
* - Inheritance: specialized plugin classes can extend this
|
|
94
|
+
*/
|
|
95
|
+
declare abstract class MardoraPlugin {
|
|
96
|
+
/** Unique plugin identifier (abstract - must be implemented) */
|
|
97
|
+
abstract readonly name: string;
|
|
98
|
+
/** Plugin version (abstract - must be implemented) */
|
|
99
|
+
abstract readonly version: string;
|
|
100
|
+
/** Decoration priority (higher = applied later) */
|
|
101
|
+
readonly decorationPriority: number;
|
|
102
|
+
/** Plugin dependencies - names of required plugins */
|
|
103
|
+
readonly dependencies: string[];
|
|
104
|
+
/** Node types this plugin handles for decorations and preview rendering */
|
|
105
|
+
readonly requiredNodes: readonly string[];
|
|
106
|
+
/** Private configuration storage */
|
|
107
|
+
private _config;
|
|
108
|
+
/** Protected context - accessible to subclasses */
|
|
109
|
+
protected _context: PluginContext | null;
|
|
110
|
+
/** Get plugin configuration */
|
|
111
|
+
get config(): PluginConfig;
|
|
112
|
+
/** Set plugin configuration */
|
|
113
|
+
set config(value: PluginConfig);
|
|
114
|
+
/** Get plugin context */
|
|
115
|
+
get context(): PluginContext | null;
|
|
116
|
+
/** Plugin theme */
|
|
117
|
+
get theme(): (theme: ThemeEnum) => ThemeStyle;
|
|
118
|
+
/**
|
|
119
|
+
* Return CodeMirror extensions for this plugin
|
|
120
|
+
* Override to provide custom extensions
|
|
121
|
+
*/
|
|
122
|
+
getExtensions(): Extension[];
|
|
123
|
+
/**
|
|
124
|
+
* Return markdown parser extensions
|
|
125
|
+
* Override to extend markdown parsing
|
|
126
|
+
*/
|
|
127
|
+
getMarkdownConfig(): MarkdownConfig | null;
|
|
128
|
+
/**
|
|
129
|
+
* Return keybindings for this plugin
|
|
130
|
+
* Override to add custom keyboard shortcuts
|
|
131
|
+
*/
|
|
132
|
+
getKeymap(): KeyBinding[];
|
|
133
|
+
/**
|
|
134
|
+
* Build decorations for the current view state
|
|
135
|
+
* Override to contribute decorations to the editor
|
|
136
|
+
*
|
|
137
|
+
* @param ctx - Decoration context with view and decoration array
|
|
138
|
+
*/
|
|
139
|
+
buildDecorations(_ctx: DecorationContext): void;
|
|
140
|
+
/**
|
|
141
|
+
* Called when plugin is registered with mardora
|
|
142
|
+
* Override to perform initialization
|
|
143
|
+
*
|
|
144
|
+
* @param context - Plugin context with configuration
|
|
145
|
+
*/
|
|
146
|
+
onRegister(context: PluginContext): void | Promise<void>;
|
|
147
|
+
/**
|
|
148
|
+
* Called when plugin is unregistered
|
|
149
|
+
* Override to perform cleanup
|
|
150
|
+
*/
|
|
151
|
+
onUnregister(): void;
|
|
152
|
+
/**
|
|
153
|
+
* Called when EditorView is created and ready
|
|
154
|
+
* Override to perform view-specific initialization
|
|
155
|
+
*
|
|
156
|
+
* @param view - The EditorView instance
|
|
157
|
+
*/
|
|
158
|
+
onViewReady(_view: EditorView): void;
|
|
159
|
+
/**
|
|
160
|
+
* Called on view updates (document changes, selection changes, etc.)
|
|
161
|
+
* Override to react to editor changes
|
|
162
|
+
*
|
|
163
|
+
* @param update - The ViewUpdate with change information
|
|
164
|
+
*/
|
|
165
|
+
onViewUpdate(_update: ViewUpdate): void;
|
|
166
|
+
/**
|
|
167
|
+
* Helper to get current editor state
|
|
168
|
+
* @param view - The EditorView instance
|
|
169
|
+
*/
|
|
170
|
+
protected getState(view: EditorView): _codemirror_state.EditorState;
|
|
171
|
+
/**
|
|
172
|
+
* Helper to get current document
|
|
173
|
+
* @param view - The EditorView instance
|
|
174
|
+
*/
|
|
175
|
+
protected getDocument(view: EditorView): _codemirror_state.Text;
|
|
176
|
+
/**
|
|
177
|
+
* Render a syntax node to HTML for preview mode
|
|
178
|
+
* Override to provide custom HTML rendering for specific node types
|
|
179
|
+
*
|
|
180
|
+
* @param node - The syntax node to render
|
|
181
|
+
* @param children - Pre-rendered children HTML
|
|
182
|
+
* @param ctx - Preview context with document and utilities
|
|
183
|
+
* @returns HTML string to use, or null to use default rendering
|
|
184
|
+
*/
|
|
185
|
+
renderToHTML?(node: SyntaxNode, children: string, ctx: {
|
|
186
|
+
doc: string;
|
|
187
|
+
sliceDoc(from: number, to: number): string;
|
|
188
|
+
sanitize(html: string): string;
|
|
189
|
+
syntaxHighlighters?: readonly _lezer_highlight.Highlighter[];
|
|
190
|
+
}): string | null | Promise<string | null>;
|
|
191
|
+
/**
|
|
192
|
+
* Return the document position consumed by preview rendering.
|
|
193
|
+
* Plugins can use this when a rendered node owns trailing syntax that is
|
|
194
|
+
* outside the Lezer node range, such as image attributes.
|
|
195
|
+
*/
|
|
196
|
+
getPreviewConsumedTo?(node: SyntaxNode, ctx: {
|
|
197
|
+
doc: string;
|
|
198
|
+
sliceDoc(from: number, to: number): string;
|
|
199
|
+
}): number | null;
|
|
200
|
+
/**
|
|
201
|
+
* Get CSS styles for preview mode
|
|
202
|
+
* Override to provide custom CSS for preview rendering
|
|
203
|
+
*
|
|
204
|
+
* @param theme - Current theme enum
|
|
205
|
+
* @returns CSS string for preview styles
|
|
206
|
+
*/
|
|
207
|
+
getPreviewStyles(theme: ThemeEnum, wrapperClass: string): string;
|
|
208
|
+
/**
|
|
209
|
+
* Transform ThemeStyle object to CSS string for preview
|
|
210
|
+
* Uses cssClassMap to convert CM selectors to semantic selectors
|
|
211
|
+
*/
|
|
212
|
+
protected transformToCss(themeStyles: ThemeStyle, wrapperClass: string): string;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Base class for plugins that primarily contribute decorations
|
|
216
|
+
* Extends MardoraPlugin with decoration-focused defaults
|
|
217
|
+
*/
|
|
218
|
+
declare abstract class DecorationPlugin extends MardoraPlugin {
|
|
219
|
+
/**
|
|
220
|
+
* Decoration priority - lower than default for decoration plugins
|
|
221
|
+
* Override to customize
|
|
222
|
+
*/
|
|
223
|
+
decorationPriority: number;
|
|
224
|
+
/**
|
|
225
|
+
* Subclasses must implement this to provide decorations
|
|
226
|
+
* @param ctx - Decoration context
|
|
227
|
+
*/
|
|
228
|
+
abstract buildDecorations(ctx: DecorationContext): void;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Base class for plugins that add syntax/parser extensions
|
|
232
|
+
* Extends MardoraPlugin with syntax-focused requirements
|
|
233
|
+
*/
|
|
234
|
+
declare abstract class SyntaxPlugin extends MardoraPlugin {
|
|
235
|
+
/**
|
|
236
|
+
* Subclasses must implement this to provide markdown config
|
|
237
|
+
*/
|
|
238
|
+
abstract getMarkdownConfig(): MarkdownConfig;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
type MardoraAttachmentKind = "image" | "video" | "audio" | "file";
|
|
242
|
+
type MardoraAttachmentUploadSource = "slash" | "paste" | "drop" | "api";
|
|
243
|
+
type MardoraAttachmentUploadContext = {
|
|
244
|
+
kind: MardoraAttachmentKind;
|
|
245
|
+
source: MardoraAttachmentUploadSource;
|
|
246
|
+
documentText: string;
|
|
247
|
+
selection: {
|
|
248
|
+
from: number;
|
|
249
|
+
to: number;
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
type MardoraAttachmentUploadResult = {
|
|
253
|
+
url: string;
|
|
254
|
+
name?: string;
|
|
255
|
+
title?: string;
|
|
256
|
+
mimeType?: string;
|
|
257
|
+
};
|
|
258
|
+
type MardoraAttachmentUploader = (file: File, context: MardoraAttachmentUploadContext) => Promise<MardoraAttachmentUploadResult>;
|
|
259
|
+
type MardoraAttachmentAccept = Partial<Record<MardoraAttachmentKind, string[]>>;
|
|
260
|
+
type MardoraAttachmentsConfig = {
|
|
261
|
+
enabled?: boolean;
|
|
262
|
+
uploader?: MardoraAttachmentUploader;
|
|
263
|
+
accept?: MardoraAttachmentAccept;
|
|
264
|
+
enablePaste?: boolean;
|
|
265
|
+
enableDrop?: boolean;
|
|
266
|
+
};
|
|
267
|
+
type MardoraFileLike = {
|
|
268
|
+
name: string;
|
|
269
|
+
type: string;
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
type MardoraLocale = "zh-CN" | "en-US";
|
|
273
|
+
type MardoraI18nConfig = {
|
|
274
|
+
locale?: MardoraLocale;
|
|
275
|
+
};
|
|
276
|
+
declare const defaultMardoraLocale: MardoraLocale;
|
|
277
|
+
declare function resolveMardoraLocale(locale?: MardoraLocale): MardoraLocale;
|
|
278
|
+
|
|
279
|
+
type MardoraSlashCommandGroup = "basic" | "media";
|
|
280
|
+
type MardoraSlashMessages = {
|
|
281
|
+
groups: Record<MardoraSlashCommandGroup, string>;
|
|
282
|
+
empty: string;
|
|
283
|
+
close: string;
|
|
284
|
+
closeHint: string;
|
|
285
|
+
};
|
|
286
|
+
type MardoraSlashCommandContext = {
|
|
287
|
+
view: EditorView;
|
|
288
|
+
queryRange: {
|
|
289
|
+
from: number;
|
|
290
|
+
to: number;
|
|
291
|
+
};
|
|
292
|
+
requestAttachment?: (kind: MardoraAttachmentKind, context: MardoraSlashCommandContext) => boolean;
|
|
293
|
+
};
|
|
294
|
+
type MardoraSlashCommand = {
|
|
295
|
+
id: string;
|
|
296
|
+
group: MardoraSlashCommandGroup;
|
|
297
|
+
title: string;
|
|
298
|
+
aliases: string[];
|
|
299
|
+
icon: string;
|
|
300
|
+
hint: string;
|
|
301
|
+
run: (context: MardoraSlashCommandContext) => boolean;
|
|
302
|
+
};
|
|
303
|
+
type MardoraSlashQuery = {
|
|
304
|
+
from: number;
|
|
305
|
+
to: number;
|
|
306
|
+
query: string;
|
|
307
|
+
};
|
|
308
|
+
type MardoraSlashCommandsConfig = {
|
|
309
|
+
enabled?: boolean;
|
|
310
|
+
locale?: MardoraLocale;
|
|
311
|
+
commands?: MardoraSlashCommand[];
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
type MardoraIconName = "arrow-down" | "arrow-down-to-line" | "arrow-left" | "arrow-left-to-line" | "arrow-right" | "arrow-right-to-line" | "arrow-up" | "arrow-up-to-line" | "badge-alert" | "baseline" | "bold" | "code" | "code-xml" | "copy" | "external-link" | "file" | "heading-1" | "heading-2" | "heading-3" | "heading-4" | "heading-5" | "heading-6" | "highlighter" | "image" | "info" | "italic" | "link" | "lightbulb" | "list" | "list-ordered" | "list-todo" | "maximize-2" | "minus" | "music-2" | "octagon-alert" | "play" | "rotate-ccw" | "strikethrough" | "table" | "table-delete" | "table-of-contents" | "text-align-start" | "text-quote" | "trash-2" | "triangle-alert" | "underline" | "type" | "x";
|
|
315
|
+
declare function hasMardoraIcon(name: string): name is MardoraIconName;
|
|
316
|
+
declare function createMardoraIcon(name: string): SVGSVGElement | null;
|
|
317
|
+
|
|
318
|
+
type SelectionToolbarMessages = {
|
|
319
|
+
buttons: {
|
|
320
|
+
blockType: string;
|
|
321
|
+
bold: string;
|
|
322
|
+
italic: string;
|
|
323
|
+
strike: string;
|
|
324
|
+
underline: string;
|
|
325
|
+
code: string;
|
|
326
|
+
highlight: string;
|
|
327
|
+
color: string;
|
|
328
|
+
link: string;
|
|
329
|
+
orderedList: string;
|
|
330
|
+
unorderedList: string;
|
|
331
|
+
taskList: string;
|
|
332
|
+
};
|
|
333
|
+
panels: {
|
|
334
|
+
textColor: string;
|
|
335
|
+
highlightColor: string;
|
|
336
|
+
};
|
|
337
|
+
link: {
|
|
338
|
+
title: string;
|
|
339
|
+
url: string;
|
|
340
|
+
copy: string;
|
|
341
|
+
copied: string;
|
|
342
|
+
open: string;
|
|
343
|
+
remove: string;
|
|
344
|
+
invalid: string;
|
|
345
|
+
};
|
|
346
|
+
blockTypes: Record<SelectionToolbarBlockType, string>;
|
|
347
|
+
colors: {
|
|
348
|
+
defaultText: string;
|
|
349
|
+
gray: string;
|
|
350
|
+
red: string;
|
|
351
|
+
orange: string;
|
|
352
|
+
yellow: string;
|
|
353
|
+
green: string;
|
|
354
|
+
blue: string;
|
|
355
|
+
purple: string;
|
|
356
|
+
defaultHighlight: string;
|
|
357
|
+
yellowHighlight: string;
|
|
358
|
+
greenHighlight: string;
|
|
359
|
+
blueHighlight: string;
|
|
360
|
+
pinkHighlight: string;
|
|
361
|
+
purpleHighlight: string;
|
|
362
|
+
};
|
|
363
|
+
};
|
|
364
|
+
declare function getSelectionToolbarMessages(locale: MardoraLocale): SelectionToolbarMessages;
|
|
365
|
+
|
|
366
|
+
type MardoraSelectionToolbarConfig = {
|
|
367
|
+
enabled?: boolean;
|
|
368
|
+
locale?: MardoraLocale;
|
|
369
|
+
};
|
|
370
|
+
type SelectionToolbarPlacement = "top" | "bottom";
|
|
371
|
+
type SelectionToolbarAnchorRect = {
|
|
372
|
+
left: number;
|
|
373
|
+
right: number;
|
|
374
|
+
top: number;
|
|
375
|
+
bottom: number;
|
|
376
|
+
};
|
|
377
|
+
type SelectionToolbarViewport = {
|
|
378
|
+
width: number;
|
|
379
|
+
height: number;
|
|
380
|
+
};
|
|
381
|
+
type SelectionToolbarFloatingSize = {
|
|
382
|
+
width: number;
|
|
383
|
+
height: number;
|
|
384
|
+
};
|
|
385
|
+
type SelectionToolbarBoundary = {
|
|
386
|
+
left: number;
|
|
387
|
+
right: number;
|
|
388
|
+
top: number;
|
|
389
|
+
bottom: number;
|
|
390
|
+
};
|
|
391
|
+
type SelectionToolbarLayoutInput = {
|
|
392
|
+
anchor: SelectionToolbarAnchorRect;
|
|
393
|
+
viewport: SelectionToolbarViewport;
|
|
394
|
+
boundary?: SelectionToolbarBoundary;
|
|
395
|
+
floating: SelectionToolbarFloatingSize;
|
|
396
|
+
};
|
|
397
|
+
type SelectionToolbarLayout = {
|
|
398
|
+
placement: SelectionToolbarPlacement;
|
|
399
|
+
left: number;
|
|
400
|
+
top: number;
|
|
401
|
+
maxHeight: number;
|
|
402
|
+
};
|
|
403
|
+
type SelectionToolbarActionId = "block-type" | "bold" | "italic" | "strike" | "underline" | "code" | "highlight" | "color" | "link" | "ordered-list" | "unordered-list" | "task-list";
|
|
404
|
+
type SelectionToolbarButton = {
|
|
405
|
+
id: SelectionToolbarActionId;
|
|
406
|
+
label: string;
|
|
407
|
+
icon: MardoraIconName;
|
|
408
|
+
text?: string;
|
|
409
|
+
active?: boolean;
|
|
410
|
+
};
|
|
411
|
+
type TextChange = {
|
|
412
|
+
from: number;
|
|
413
|
+
to: number;
|
|
414
|
+
insert: string;
|
|
415
|
+
};
|
|
416
|
+
type TextSelection = {
|
|
417
|
+
anchor: number;
|
|
418
|
+
head?: number;
|
|
419
|
+
};
|
|
420
|
+
type TextCommandResult = {
|
|
421
|
+
changes: TextChange | TextChange[];
|
|
422
|
+
selection?: TextSelection;
|
|
423
|
+
};
|
|
424
|
+
type InlineFormatInput = {
|
|
425
|
+
doc: string;
|
|
426
|
+
from: number;
|
|
427
|
+
to: number;
|
|
428
|
+
marker?: string;
|
|
429
|
+
htmlTag?: "u";
|
|
430
|
+
spanStyle?: {
|
|
431
|
+
property: "color" | "background-color";
|
|
432
|
+
value: string;
|
|
433
|
+
};
|
|
434
|
+
clear?: boolean;
|
|
435
|
+
};
|
|
436
|
+
type ParsedSelectionLink = {
|
|
437
|
+
kind: "markdown-link";
|
|
438
|
+
title: string;
|
|
439
|
+
url: string;
|
|
440
|
+
} | {
|
|
441
|
+
kind: "url";
|
|
442
|
+
title: string;
|
|
443
|
+
url: string;
|
|
444
|
+
} | {
|
|
445
|
+
kind: "text";
|
|
446
|
+
title: string;
|
|
447
|
+
url: string;
|
|
448
|
+
};
|
|
449
|
+
type LinkChangeInput = {
|
|
450
|
+
from: number;
|
|
451
|
+
to: number;
|
|
452
|
+
title: string;
|
|
453
|
+
url: string;
|
|
454
|
+
remove?: boolean;
|
|
455
|
+
};
|
|
456
|
+
type SelectionToolbarListKind = "ordered" | "unordered" | "task";
|
|
457
|
+
type SelectionToolbarBlockType = "text" | "heading-1" | "heading-2" | "heading-3" | "heading-4" | "heading-5" | "heading-6";
|
|
458
|
+
type SelectionToolbarPanel = "toolbar" | "link" | "color" | "highlight" | "block-type";
|
|
459
|
+
type SelectionToolbarPaletteItem = {
|
|
460
|
+
id: string;
|
|
461
|
+
label: string;
|
|
462
|
+
value: string | null;
|
|
463
|
+
};
|
|
464
|
+
type SelectionToolbarLinkState = {
|
|
465
|
+
title: string;
|
|
466
|
+
url: string;
|
|
467
|
+
canRemove: boolean;
|
|
468
|
+
error?: string;
|
|
469
|
+
copied?: boolean;
|
|
470
|
+
};
|
|
471
|
+
type SelectionToolbarMenuState = {
|
|
472
|
+
panel: SelectionToolbarPanel;
|
|
473
|
+
buttons: SelectionToolbarButton[];
|
|
474
|
+
blockType: SelectionToolbarBlockType;
|
|
475
|
+
blockTypes: Array<{
|
|
476
|
+
type: SelectionToolbarBlockType;
|
|
477
|
+
label: string;
|
|
478
|
+
icon: MardoraIconName;
|
|
479
|
+
}>;
|
|
480
|
+
textColors: SelectionToolbarPaletteItem[];
|
|
481
|
+
highlightColors: SelectionToolbarPaletteItem[];
|
|
482
|
+
link: SelectionToolbarLinkState;
|
|
483
|
+
messages: SelectionToolbarMessages;
|
|
484
|
+
};
|
|
485
|
+
type SelectionToolbarMenuCallbacks = {
|
|
486
|
+
onAction: (id: SelectionToolbarActionId) => void;
|
|
487
|
+
onBlockType: (type: SelectionToolbarBlockType) => void;
|
|
488
|
+
onColor: (value: string | null) => void;
|
|
489
|
+
onHighlight: (value: string | null) => void;
|
|
490
|
+
onLinkInput: (field: "title" | "url", value: string) => void;
|
|
491
|
+
onLinkSubmit: () => void;
|
|
492
|
+
onLinkCopy: () => void;
|
|
493
|
+
onLinkOpen: () => void;
|
|
494
|
+
onLinkRemove: () => void;
|
|
495
|
+
onCancelPanel: () => void;
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
type MardoraTocLevel = 2 | 3 | 4 | 5 | 6;
|
|
499
|
+
interface MardoraTocItem {
|
|
500
|
+
id: string;
|
|
501
|
+
level: MardoraTocLevel;
|
|
502
|
+
text: string;
|
|
503
|
+
from?: number;
|
|
504
|
+
to?: number;
|
|
505
|
+
active: boolean;
|
|
506
|
+
}
|
|
507
|
+
interface MardoraTocConfig {
|
|
508
|
+
enabled?: boolean;
|
|
509
|
+
onTocChange?: (items: MardoraTocItem[]) => void;
|
|
510
|
+
minLevel?: MardoraTocLevel;
|
|
511
|
+
maxLevel?: MardoraTocLevel;
|
|
512
|
+
defaultExpanded?: boolean;
|
|
513
|
+
defaultWidth?: number;
|
|
514
|
+
minWidth?: number;
|
|
515
|
+
maxWidth?: number;
|
|
516
|
+
storageKey?: string;
|
|
517
|
+
}
|
|
518
|
+
interface ResolvedMardoraTocConfig {
|
|
519
|
+
enabled: boolean;
|
|
520
|
+
onTocChange?: (items: MardoraTocItem[]) => void;
|
|
521
|
+
minLevel: MardoraTocLevel;
|
|
522
|
+
maxLevel: MardoraTocLevel;
|
|
523
|
+
defaultExpanded: boolean;
|
|
524
|
+
defaultWidth: number;
|
|
525
|
+
minWidth: number;
|
|
526
|
+
maxWidth: number;
|
|
527
|
+
storageKey?: string;
|
|
528
|
+
}
|
|
529
|
+
interface TocPanelState {
|
|
530
|
+
expanded: boolean;
|
|
531
|
+
width: number;
|
|
532
|
+
}
|
|
533
|
+
interface TocStorageAdapter {
|
|
534
|
+
getItem(key: string): string | null;
|
|
535
|
+
setItem(key: string, value: string): unknown;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
type MardoraHeadingFoldLevel = 2 | 3 | 4 | 5;
|
|
539
|
+
interface MardoraHeadingFoldConfig {
|
|
540
|
+
enabled?: boolean;
|
|
541
|
+
minLevel?: MardoraHeadingFoldLevel;
|
|
542
|
+
maxLevel?: MardoraHeadingFoldLevel;
|
|
543
|
+
}
|
|
544
|
+
interface ResolvedMardoraHeadingFoldConfig {
|
|
545
|
+
enabled: boolean;
|
|
546
|
+
minLevel: MardoraHeadingFoldLevel;
|
|
547
|
+
maxLevel: MardoraHeadingFoldLevel;
|
|
548
|
+
}
|
|
549
|
+
interface MardoraHeadingFoldRange {
|
|
550
|
+
level: MardoraHeadingFoldLevel;
|
|
551
|
+
text: string;
|
|
552
|
+
headingFrom: number;
|
|
553
|
+
headingTo: number;
|
|
554
|
+
headingLineFrom: number;
|
|
555
|
+
headingLineTo: number;
|
|
556
|
+
foldFrom: number;
|
|
557
|
+
foldTo: number;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* MardoraNode: represents a node in the markdown tree
|
|
562
|
+
*
|
|
563
|
+
* Useful for debugging and development
|
|
564
|
+
*/
|
|
565
|
+
type MardoraNode = {
|
|
566
|
+
from: number;
|
|
567
|
+
to: number;
|
|
568
|
+
name: string;
|
|
569
|
+
children: MardoraNode[];
|
|
570
|
+
isSelected: boolean;
|
|
571
|
+
};
|
|
572
|
+
/**
|
|
573
|
+
* Configuration options for the mardora editor
|
|
574
|
+
*/
|
|
575
|
+
interface MardoraConfig {
|
|
576
|
+
/** Theme */
|
|
577
|
+
theme?: ThemeEnum;
|
|
578
|
+
/** Editor UI locale. Defaults to Simplified Chinese. */
|
|
579
|
+
locale?: MardoraLocale;
|
|
580
|
+
/** Internationalization configuration for editor-owned UI text */
|
|
581
|
+
i18n?: MardoraI18nConfig;
|
|
582
|
+
/** Weather to load base styles */
|
|
583
|
+
baseStyles?: boolean;
|
|
584
|
+
/** Plugins to load */
|
|
585
|
+
plugins?: MardoraPlugin[];
|
|
586
|
+
/** Additional markdown extensions for the parser */
|
|
587
|
+
markdown?: MarkdownConfig[];
|
|
588
|
+
/** Additional CodeMirror extensions */
|
|
589
|
+
extensions?: Extension[];
|
|
590
|
+
/** Additional keybindings */
|
|
591
|
+
keymap?: KeyBinding[];
|
|
592
|
+
/** Disable the built-in view plugin (for raw markdown mode) */
|
|
593
|
+
disableViewPlugin?: boolean;
|
|
594
|
+
/** Enable default keybindings */
|
|
595
|
+
defaultKeybindings?: boolean;
|
|
596
|
+
/** Enable history */
|
|
597
|
+
history?: boolean;
|
|
598
|
+
/** Enable indent with tab */
|
|
599
|
+
indentWithTab?: boolean;
|
|
600
|
+
/** Highlight active line */
|
|
601
|
+
highlightActiveLine?: boolean;
|
|
602
|
+
/** Line wrapping in raw markdown mode */
|
|
603
|
+
lineWrapping?: boolean;
|
|
604
|
+
/** Callback to receive the nodes on every update */
|
|
605
|
+
onNodesChange?: (nodes: MardoraNode[]) => void;
|
|
606
|
+
/** Slash command menu configuration */
|
|
607
|
+
slashCommands?: MardoraSlashCommandsConfig;
|
|
608
|
+
/** Browser attachment upload configuration */
|
|
609
|
+
attachments?: MardoraAttachmentsConfig;
|
|
610
|
+
/** Selected text floating toolbar configuration */
|
|
611
|
+
selectionToolbar?: MardoraSelectionToolbarConfig;
|
|
612
|
+
/** Table of contents configuration */
|
|
613
|
+
toc?: MardoraTocConfig;
|
|
614
|
+
/** Heading section folding configuration */
|
|
615
|
+
headingFold?: MardoraHeadingFoldConfig;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Creates a mardora editor extension bundle for CodeMirror 6
|
|
619
|
+
*
|
|
620
|
+
* @param config - Configuration options for the editor
|
|
621
|
+
* @returns CodeMirror Extension that can be added to EditorState
|
|
622
|
+
*
|
|
623
|
+
* @example
|
|
624
|
+
* ```ts
|
|
625
|
+
* import { EditorView } from '@codemirror/view';
|
|
626
|
+
* import { EditorState } from '@codemirror/state';
|
|
627
|
+
* import { mardora } from 'mardora';
|
|
628
|
+
*
|
|
629
|
+
* const view = new EditorView({
|
|
630
|
+
* state: EditorState.create({
|
|
631
|
+
* doc: '# Hello mardora',
|
|
632
|
+
* extensions: [mardora()]
|
|
633
|
+
* }),
|
|
634
|
+
* parent: document.getElementById('editor')
|
|
635
|
+
* });
|
|
636
|
+
* ```
|
|
637
|
+
*/
|
|
638
|
+
declare function mardora(config?: MardoraConfig): Extension[];
|
|
639
|
+
|
|
640
|
+
export { SyntaxPlugin as $, type MardoraTocLevel as A, type PluginConfig as B, type PluginContext as C, type DecorationContext as D, type ResolvedMardoraTocConfig as E, type SelectionToolbarAnchorRect as F, type SelectionToolbarBlockType as G, type SelectionToolbarBoundary as H, type InlineFormatInput as I, type SelectionToolbarButton as J, type SelectionToolbarFloatingSize as K, type LinkChangeInput as L, type MardoraAttachmentAccept as M, type SelectionToolbarLayout as N, type SelectionToolbarLayoutInput as O, type ParsedSelectionLink as P, type SelectionToolbarLinkState as Q, type ResolvedMardoraHeadingFoldConfig as R, type SelectionToolbarActionId as S, type SelectionToolbarListKind as T, type SelectionToolbarMenuCallbacks as U, type SelectionToolbarMenuState as V, type SelectionToolbarMessages as W, type SelectionToolbarPaletteItem as X, type SelectionToolbarPanel as Y, type SelectionToolbarPlacement as Z, type SelectionToolbarViewport as _, DecorationPlugin as a, type TextChange as a0, type TextCommandResult as a1, type TextSelection as a2, ThemeEnum as a3, type ThemeStyle as a4, type TocPanelState as a5, type TocStorageAdapter as a6, createMardoraIcon as a7, createTheme as a8, cursorInRange as a9, deepMerge as aa, defaultMardoraLocale as ab, fixSelector as ac, flattenThemeStyles as ad, getSelectionToolbarMessages as ae, hasMardoraIcon as af, mardora as ag, resolveMardoraLocale as ah, selectionOverlapsRange as ai, toggleMarkdownStyle as aj, type MardoraAttachmentKind as b, type MardoraAttachmentUploadContext as c, type MardoraAttachmentUploadResult as d, type MardoraAttachmentUploadSource as e, type MardoraAttachmentUploader as f, type MardoraAttachmentsConfig as g, type MardoraConfig as h, type MardoraFileLike as i, type MardoraHeadingFoldConfig as j, type MardoraHeadingFoldLevel as k, type MardoraHeadingFoldRange as l, type MardoraI18nConfig as m, type MardoraIconName as n, type MardoraLocale as o, type MardoraNode as p, MardoraPlugin as q, type MardoraSelectionToolbarConfig as r, type MardoraSlashCommand as s, type MardoraSlashCommandContext as t, type MardoraSlashCommandGroup as u, type MardoraSlashCommandsConfig as v, type MardoraSlashMessages as w, type MardoraSlashQuery as x, type MardoraTocConfig as y, type MardoraTocItem as z };
|