draftly 0.1.0-alpha.1 → 1.0.7

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 (68) hide show
  1. package/dist/chunk-2B3A3VSQ.cjs +3382 -0
  2. package/dist/chunk-2B3A3VSQ.cjs.map +1 -0
  3. package/dist/{chunk-ZDSZRRUY.cjs → chunk-72ZYRGRT.cjs} +48 -104
  4. package/dist/chunk-72ZYRGRT.cjs.map +1 -0
  5. package/dist/{chunk-MOG6E2LY.js → chunk-CG4M4TC7.js} +46 -103
  6. package/dist/chunk-CG4M4TC7.js.map +1 -0
  7. package/dist/{chunk-LCQALOEI.js → chunk-DFQYXFOP.js} +36 -3
  8. package/dist/chunk-DFQYXFOP.js.map +1 -0
  9. package/dist/{chunk-6LQ2VR4I.js → chunk-HPSMS2WB.js} +38 -22
  10. package/dist/chunk-HPSMS2WB.js.map +1 -0
  11. package/dist/{chunk-7Z3SRTPZ.cjs → chunk-KBQDZ5IW.cjs} +38 -22
  12. package/dist/chunk-KBQDZ5IW.cjs.map +1 -0
  13. package/dist/{chunk-RV2SYFA6.cjs → chunk-KDEDLC3D.cjs} +36 -2
  14. package/dist/chunk-KDEDLC3D.cjs.map +1 -0
  15. package/dist/chunk-N3WL3XPB.js +3360 -0
  16. package/dist/chunk-N3WL3XPB.js.map +1 -0
  17. package/dist/{draftly-Bxu_H4nw.d.ts → draftly-BLnx3uGX.d.cts} +12 -6
  18. package/dist/{draftly-Bxu_H4nw.d.cts → draftly-BLnx3uGX.d.ts} +12 -6
  19. package/dist/editor/index.cjs +20 -12
  20. package/dist/editor/index.d.cts +3 -2
  21. package/dist/editor/index.d.ts +3 -2
  22. package/dist/editor/index.js +2 -2
  23. package/dist/index.cjs +59 -27
  24. package/dist/index.d.cts +3 -3
  25. package/dist/index.d.ts +3 -3
  26. package/dist/index.js +4 -4
  27. package/dist/plugins/index.cjs +35 -11
  28. package/dist/plugins/index.d.cts +321 -3
  29. package/dist/plugins/index.d.ts +321 -3
  30. package/dist/plugins/index.js +3 -3
  31. package/dist/preview/index.cjs +7 -7
  32. package/dist/preview/index.d.cts +9 -4
  33. package/dist/preview/index.d.ts +9 -4
  34. package/dist/preview/index.js +2 -2
  35. package/package.json +2 -1
  36. package/src/editor/draftly.ts +9 -13
  37. package/src/editor/plugin.ts +4 -1
  38. package/src/editor/theme.ts +34 -1
  39. package/src/editor/utils.ts +49 -0
  40. package/src/editor/view-plugin.ts +6 -131
  41. package/src/plugins/code-plugin.ts +1119 -0
  42. package/src/plugins/heading-plugin.ts +23 -11
  43. package/src/plugins/hr-plugin.ts +102 -0
  44. package/src/plugins/image-plugin.ts +96 -2
  45. package/src/plugins/index.ts +57 -39
  46. package/src/plugins/inline-plugin.ts +125 -6
  47. package/src/plugins/link-plugin.ts +509 -0
  48. package/src/plugins/list-plugin.ts +116 -2
  49. package/src/plugins/math-plugin.ts +5 -1
  50. package/src/plugins/mermaid-plugin.ts +500 -0
  51. package/src/plugins/paragraph-plugin.ts +38 -0
  52. package/src/plugins/quote-plugin.ts +146 -0
  53. package/src/preview/context.ts +1 -1
  54. package/src/preview/css-generator.ts +3 -1
  55. package/src/preview/default-renderers.ts +0 -5
  56. package/src/preview/preview.ts +2 -2
  57. package/src/preview/renderer.ts +34 -12
  58. package/src/preview/types.ts +1 -1
  59. package/dist/chunk-6LQ2VR4I.js.map +0 -1
  60. package/dist/chunk-7Z3SRTPZ.cjs.map +0 -1
  61. package/dist/chunk-GA6NYY77.cjs +0 -1400
  62. package/dist/chunk-GA6NYY77.cjs.map +0 -1
  63. package/dist/chunk-LCQALOEI.js.map +0 -1
  64. package/dist/chunk-MOG6E2LY.js.map +0 -1
  65. package/dist/chunk-RV2SYFA6.cjs.map +0 -1
  66. package/dist/chunk-TKZNKWGF.js +0 -1385
  67. package/dist/chunk-TKZNKWGF.js.map +0 -1
  68. package/dist/chunk-ZDSZRRUY.cjs.map +0 -1
@@ -1,10 +1,26 @@
1
- import { a as DecorationPlugin, T as ThemeEnum, f as ThemeStyle, D as DecorationContext, d as DraftlyPlugin } from '../draftly-Bxu_H4nw.js';
1
+ import { d as DraftlyPlugin, T as ThemeEnum, f as ThemeStyle, a as DecorationPlugin, D as DecorationContext } from '../draftly-BLnx3uGX.js';
2
2
  import { SyntaxNode } from '@lezer/common';
3
+ import { KeyBinding } from '@codemirror/view';
3
4
  import { MarkdownConfig } from '@lezer/markdown';
4
5
  import '@codemirror/state';
5
- import '@codemirror/view';
6
6
  import 'style-mod';
7
7
 
8
+ /**
9
+ * ParagraphPlugin - Adds top and bottom padding to paragraphs in preview
10
+ *
11
+ * Applies visual spacing to markdown paragraphs for better readability
12
+ */
13
+ declare class ParagraphPlugin extends DraftlyPlugin {
14
+ readonly name = "paragraph";
15
+ readonly version = "1.0.0";
16
+ readonly requiredNodes: readonly ["Paragraph"];
17
+ /**
18
+ * Plugin theme for preview styling
19
+ */
20
+ get theme(): (theme: ThemeEnum) => ThemeStyle;
21
+ renderToHTML(node: SyntaxNode, children: string): string | null;
22
+ }
23
+
8
24
  /**
9
25
  * HeadingPlugin - Decorates markdown headings
10
26
  *
@@ -17,6 +33,7 @@ declare class HeadingPlugin extends DecorationPlugin {
17
33
  readonly name = "heading";
18
34
  readonly version = "1.0.0";
19
35
  decorationPriority: number;
36
+ readonly requiredNodes: readonly ["ATXHeading1", "ATXHeading2", "ATXHeading3", "ATXHeading4", "ATXHeading5", "ATXHeading6", "HeaderMark"];
20
37
  /**
21
38
  * Constructor - calls super constructor
22
39
  */
@@ -41,6 +58,7 @@ declare class HeadingPlugin extends DecorationPlugin {
41
58
  * - Strikethrough - ~~text~~
42
59
  * - Subscript - ~text~
43
60
  * - Superscript - ^text^
61
+ * - Highlight - ==text==
44
62
  *
45
63
  * Hides formatting markers when cursor is not in the element
46
64
  */
@@ -48,12 +66,21 @@ declare class InlinePlugin extends DecorationPlugin {
48
66
  readonly name = "inline";
49
67
  readonly version = "1.0.0";
50
68
  decorationPriority: number;
69
+ readonly requiredNodes: readonly ["Emphasis", "StrongEmphasis", "Strikethrough", "Subscript", "Superscript", "Highlight", "EmphasisMark", "StrikethroughMark", "SubscriptMark", "SuperscriptMark", "HighlightMark"];
51
70
  marks: string[];
52
71
  constructor();
53
72
  /**
54
73
  * Plugin theme
55
74
  */
56
75
  get theme(): (theme: ThemeEnum) => ThemeStyle;
76
+ /**
77
+ * Keyboard shortcuts for inline formatting
78
+ */
79
+ getKeymap(): KeyBinding[];
80
+ /**
81
+ * Return markdown parser extensions for highlight syntax (==text==)
82
+ */
83
+ getMarkdownConfig(): MarkdownConfig;
57
84
  /**
58
85
  * Build inline decorations by iterating the syntax tree
59
86
  */
@@ -65,6 +92,56 @@ declare class InlinePlugin extends DecorationPlugin {
65
92
  renderToHTML(node: SyntaxNode, children: string): string | null;
66
93
  }
67
94
 
95
+ /**
96
+ * LinkPlugin - Decorates and provides interactivity for markdown links
97
+ *
98
+ * Supports the full link syntax: [text](url) and [text](url "title")
99
+ * - Click: reveals raw markdown (selects/focuses the link syntax)
100
+ * - Ctrl+Click: opens the link URL in a new browser tab
101
+ * - Hover: shows tooltip with the link URL
102
+ * - Hides the markdown syntax when cursor is not in range
103
+ * - Shows raw markdown when cursor is within the link range
104
+ */
105
+ declare class LinkPlugin extends DecorationPlugin {
106
+ readonly name = "link";
107
+ readonly version = "1.0.0";
108
+ decorationPriority: number;
109
+ readonly requiredNodes: readonly ["Link"];
110
+ constructor();
111
+ /**
112
+ * Plugin theme
113
+ */
114
+ get theme(): (theme: ThemeEnum) => ThemeStyle;
115
+ /**
116
+ * Keyboard shortcuts for link formatting
117
+ */
118
+ getKeymap(): KeyBinding[];
119
+ /**
120
+ * URL regex pattern
121
+ */
122
+ private readonly urlPattern;
123
+ /**
124
+ * Toggle link on selection
125
+ * - If text is selected and is a URL: [](url) with cursor in brackets
126
+ * - If text is selected (not URL): [text]() with cursor in parentheses
127
+ * - If nothing selected: []() with cursor in brackets
128
+ * - If already a link: remove syntax, leave plain text
129
+ */
130
+ private toggleLink;
131
+ buildDecorations(ctx: DecorationContext): void;
132
+ /**
133
+ * Decorate raw link markdown when cursor is in range
134
+ */
135
+ private decorateRawLink;
136
+ /**
137
+ * Render link to HTML for preview mode
138
+ */
139
+ renderToHTML(node: SyntaxNode, _children: string, ctx: {
140
+ sliceDoc(from: number, to: number): string;
141
+ sanitize(html: string): string;
142
+ }): string | null;
143
+ }
144
+
68
145
  /**
69
146
  * Decorates markdown lists with custom styling.
70
147
  *
@@ -77,7 +154,16 @@ declare class ListPlugin extends DecorationPlugin {
77
154
  readonly name = "list";
78
155
  readonly version = "1.0.0";
79
156
  decorationPriority: number;
157
+ readonly requiredNodes: readonly ["BulletList", "OrderedList", "ListItem", "ListMark", "Task", "TaskMarker"];
80
158
  get theme(): (theme: ThemeEnum) => ThemeStyle;
159
+ /**
160
+ * Keyboard shortcuts for list formatting
161
+ */
162
+ getKeymap(): KeyBinding[];
163
+ /**
164
+ * Toggle list marker on current line or selected lines
165
+ */
166
+ private toggleListOnLines;
81
167
  buildDecorations(ctx: DecorationContext): void;
82
168
  /** Add line decoration for list items with nesting depth */
83
169
  private decorateListItem;
@@ -122,11 +208,28 @@ declare class ImagePlugin extends DecorationPlugin {
122
208
  readonly name = "image";
123
209
  readonly version = "1.0.0";
124
210
  decorationPriority: number;
211
+ readonly requiredNodes: readonly ["Image"];
125
212
  constructor();
126
213
  /**
127
214
  * Plugin theme
128
215
  */
129
216
  get theme(): (theme: ThemeEnum) => ThemeStyle;
217
+ /**
218
+ * Keyboard shortcuts for image formatting
219
+ */
220
+ getKeymap(): KeyBinding[];
221
+ /**
222
+ * URL regex pattern
223
+ */
224
+ private readonly urlPattern;
225
+ /**
226
+ * Toggle image on selection
227
+ * - If text selected and is a URL: ![Alt Text](url) with cursor in brackets
228
+ * - If text selected (not URL): ![text]() with cursor in parentheses
229
+ * - If nothing selected: ![Alt Text]() with cursor in parentheses
230
+ * - If already an image: remove syntax, leave just the URL
231
+ */
232
+ private toggleImage;
130
233
  buildDecorations(ctx: DecorationContext): void;
131
234
  /**
132
235
  * Decorate raw image markdown when cursor is in range
@@ -159,6 +262,7 @@ declare class MathPlugin extends DecorationPlugin {
159
262
  readonly name = "math";
160
263
  readonly version = "1.0.0";
161
264
  decorationPriority: number;
265
+ readonly requiredNodes: readonly ["InlineMath", "MathBlock", "InlineMathMark", "MathBlockMark"];
162
266
  constructor();
163
267
  /**
164
268
  * Plugin theme
@@ -181,6 +285,220 @@ declare class MathPlugin extends DecorationPlugin {
181
285
  }): string | null;
182
286
  }
183
287
 
288
+ /**
289
+ * MermaidPlugin - Renders mermaid diagrams in the editor
290
+ *
291
+ * Supports block mermaid syntax:
292
+ * ```mermaid
293
+ * graph TD
294
+ * A --> B
295
+ * ```
296
+ *
297
+ * Behavior:
298
+ * - Always show rendered diagram below the block
299
+ * - Hide raw definition when cursor is outside the block
300
+ * - Show raw definition with styled markers when cursor is inside
301
+ */
302
+ declare class MermaidPlugin extends DecorationPlugin {
303
+ readonly name = "mermaid";
304
+ readonly version = "1.0.0";
305
+ decorationPriority: number;
306
+ readonly requiredNodes: readonly ["MermaidBlock", "MermaidBlockMark"];
307
+ constructor();
308
+ /**
309
+ * Plugin theme
310
+ */
311
+ get theme(): (theme: ThemeEnum) => ThemeStyle;
312
+ /**
313
+ * Return markdown parser extensions for mermaid syntax
314
+ */
315
+ getMarkdownConfig(): MarkdownConfig;
316
+ /**
317
+ * Build decorations for mermaid blocks
318
+ */
319
+ buildDecorations(ctx: DecorationContext): void;
320
+ /**
321
+ * Render mermaid to HTML for preview mode
322
+ *
323
+ * Renders the actual mermaid diagram to SVG HTML
324
+ */
325
+ renderToHTML(node: SyntaxNode, _children: string, ctx: {
326
+ sliceDoc(from: number, to: number): string;
327
+ sanitize(html: string): string;
328
+ }): Promise<string | null>;
329
+ }
330
+
331
+ /**
332
+ * Text highlight definition
333
+ * Matches text or regex patterns with optional instance selection
334
+ */
335
+ interface TextHighlight {
336
+ /** The pattern to match (regex without slashes) */
337
+ pattern: string;
338
+ /** Specific instances to highlight (e.g., [3,5] or range [3,4,5]) */
339
+ instances?: number[];
340
+ }
341
+ /**
342
+ * Properties extracted from CodeInfo string
343
+ *
344
+ * Example: ```tsx line-numbers{5} title="hello.tsx" caption="Example" copy {2-4,5} /Hello/3-5
345
+ */
346
+ interface CodeBlockProperties {
347
+ /** Language identifier (first token) */
348
+ language: string;
349
+ /** Show line numbers, optionally starting from a specific number */
350
+ lineNumbers?: number | boolean;
351
+ /** Title to display */
352
+ title?: string;
353
+ /** Caption to display */
354
+ caption?: string;
355
+ /** Show copy button */
356
+ copy?: boolean;
357
+ /** Lines to highlight (e.g., [2,3,4,5,9]) */
358
+ highlightLines?: number[];
359
+ /** Text patterns to highlight with optional instance selection */
360
+ highlightText?: TextHighlight[];
361
+ }
362
+ /**
363
+ * CodePlugin - Handles inline code and fenced code blocks.
364
+ *
365
+ * **Inline code:** `code`
366
+ * Hides backticks when cursor is not in range.
367
+ *
368
+ * **Fenced code blocks:**
369
+ * Supports syntax highlighting, line numbers, line/text highlighting,
370
+ * title, caption, and copy button via CodeInfo properties.
371
+ *
372
+ * @example
373
+ * ```tsx line-numbers{5} title="example.tsx" {2-4} /pattern/
374
+ * const x = 1;
375
+ * ```
376
+ */
377
+ declare class CodePlugin extends DecorationPlugin {
378
+ readonly name = "code";
379
+ readonly version = "1.0.0";
380
+ decorationPriority: number;
381
+ readonly requiredNodes: readonly ["InlineCode", "FencedCode", "CodeMark", "CodeInfo", "CodeText"];
382
+ /**
383
+ * Plugin theme
384
+ */
385
+ get theme(): (theme: ThemeEnum) => ThemeStyle;
386
+ /**
387
+ * Keyboard shortcuts for code formatting
388
+ */
389
+ getKeymap(): KeyBinding[];
390
+ /**
391
+ * Toggle code block on current line or selected lines
392
+ */
393
+ private toggleCodeBlock;
394
+ /**
395
+ * Parse CodeInfo string into structured properties
396
+ *
397
+ * @param codeInfo - The raw CodeInfo string (e.g., "tsx line-numbers{5} title=\"hello.tsx\" copy {2-4,5} /Hello/3-5")
398
+ * @returns Parsed CodeBlockProperties object
399
+ *
400
+ * @example
401
+ * ```typescript
402
+ * parseCodeInfo("tsx line-numbers{5} title=\"hello.tsx\" copy {2-4,5} /Hello/3-5")
403
+ * ```
404
+ *
405
+ * Returns:
406
+ * ```json
407
+ * {
408
+ * language: "tsx",
409
+ * lineNumbers: 5,
410
+ * title: "hello.tsx",
411
+ * copy: true,
412
+ * highlightLines: [2,3,4,5],
413
+ * highlightText: [{ pattern: "Hello", instances: [3,4,5] }]
414
+ * }
415
+ * ```
416
+ */
417
+ parseCodeInfo(codeInfo: string): CodeBlockProperties;
418
+ /**
419
+ * Build decorations for inline code and fenced code blocks.
420
+ * Handles line numbers, highlights, header/caption widgets, and fence visibility.
421
+ */
422
+ buildDecorations(ctx: DecorationContext): void;
423
+ /**
424
+ * Render code elements to HTML for static preview.
425
+ * Applies syntax highlighting using @lezer/highlight.
426
+ */
427
+ renderToHTML(node: SyntaxNode, children: string, ctx: {
428
+ sliceDoc(from: number, to: number): string;
429
+ sanitize(html: string): string;
430
+ }): string | null;
431
+ /**
432
+ * Highlight a single line of code using the language's Lezer parser.
433
+ * Falls back to sanitized plain text if the language is not supported.
434
+ */
435
+ private highlightCodeLine;
436
+ /**
437
+ * Apply text highlights (regex patterns) to already syntax-highlighted HTML.
438
+ * Wraps matched patterns in `<mark>` elements.
439
+ */
440
+ private applyTextHighlights;
441
+ }
442
+
443
+ /**
444
+ * QuotePlugin - Decorates markdown blockquotes
445
+ *
446
+ * Adds visual styling to blockquotes (> prefixed lines)
447
+ * - Line decorations for indicating quote blocks with a left border
448
+ * - Mark decorations for quote content
449
+ * - Hides > markers when cursor is not in the blockquote
450
+ */
451
+ declare class QuotePlugin extends DecorationPlugin {
452
+ readonly name = "quote";
453
+ readonly version = "1.0.0";
454
+ decorationPriority: number;
455
+ readonly requiredNodes: readonly ["Blockquote", "QuoteMark"];
456
+ /**
457
+ * Constructor - calls super constructor
458
+ */
459
+ constructor();
460
+ /**
461
+ * Plugin theme
462
+ */
463
+ get theme(): (theme: ThemeEnum) => ThemeStyle;
464
+ /**
465
+ * Build blockquote decorations by iterating the syntax tree
466
+ */
467
+ buildDecorations(ctx: DecorationContext): void;
468
+ /**
469
+ * Recursively find and hide quote marks
470
+ */
471
+ private hideQuoteMarks;
472
+ renderToHTML(node: SyntaxNode, children: string): string | null;
473
+ }
474
+
475
+ /**
476
+ * HRPlugin - Decorates markdown horizontal rules
477
+ *
478
+ * Adds visual styling to thematic breaks (---, ***, ___)
479
+ * - Line decoration that renders a centered horizontal line
480
+ * - Hides raw marker characters when the cursor is not on the line
481
+ */
482
+ declare class HRPlugin extends DecorationPlugin {
483
+ readonly name = "hr";
484
+ readonly version = "1.0.0";
485
+ decorationPriority: number;
486
+ readonly requiredNodes: readonly ["HorizontalRule"];
487
+ /**
488
+ * Constructor - calls super constructor
489
+ */
490
+ constructor();
491
+ /**
492
+ * Plugin theme
493
+ */
494
+ get theme(): (theme: ThemeEnum) => ThemeStyle;
495
+ /**
496
+ * Build horizontal rule decorations by iterating the syntax tree
497
+ */
498
+ buildDecorations(ctx: DecorationContext): void;
499
+ renderToHTML(node: SyntaxNode, _children: string): string | null;
500
+ }
501
+
184
502
  /**
185
503
  * Default plugins
186
504
  *
@@ -194,4 +512,4 @@ declare const essentialPlugins: DraftlyPlugin[];
194
512
  */
195
513
  declare const allPlugins: DraftlyPlugin[];
196
514
 
197
- export { HTMLPlugin, HeadingPlugin, ImagePlugin, InlinePlugin, ListPlugin, MathPlugin, allPlugins, essentialPlugins };
515
+ export { CodePlugin, HRPlugin, HTMLPlugin, HeadingPlugin, ImagePlugin, InlinePlugin, LinkPlugin, ListPlugin, MathPlugin, MermaidPlugin, ParagraphPlugin, QuotePlugin, allPlugins, essentialPlugins };
@@ -1,5 +1,5 @@
1
- export { HTMLPlugin, HeadingPlugin, ImagePlugin, InlinePlugin, ListPlugin, MathPlugin, allPlugins, essentialPlugins } from '../chunk-TKZNKWGF.js';
2
- import '../chunk-MOG6E2LY.js';
3
- import '../chunk-LCQALOEI.js';
1
+ export { CodePlugin, HRPlugin, HTMLPlugin, HeadingPlugin, ImagePlugin, InlinePlugin, LinkPlugin, ListPlugin, MathPlugin, MermaidPlugin, ParagraphPlugin, QuotePlugin, allPlugins, essentialPlugins } from '../chunk-N3WL3XPB.js';
2
+ import '../chunk-CG4M4TC7.js';
3
+ import '../chunk-DFQYXFOP.js';
4
4
  //# sourceMappingURL=index.js.map
5
5
  //# sourceMappingURL=index.js.map
@@ -1,29 +1,29 @@
1
1
  'use strict';
2
2
 
3
- var chunk7Z3SRTPZ_cjs = require('../chunk-7Z3SRTPZ.cjs');
4
- require('../chunk-RV2SYFA6.cjs');
3
+ var chunkKBQDZ5IW_cjs = require('../chunk-KBQDZ5IW.cjs');
4
+ require('../chunk-KDEDLC3D.cjs');
5
5
 
6
6
 
7
7
 
8
8
  Object.defineProperty(exports, "PreviewRenderer", {
9
9
  enumerable: true,
10
- get: function () { return chunk7Z3SRTPZ_cjs.PreviewRenderer; }
10
+ get: function () { return chunkKBQDZ5IW_cjs.PreviewRenderer; }
11
11
  });
12
12
  Object.defineProperty(exports, "defaultRenderers", {
13
13
  enumerable: true,
14
- get: function () { return chunk7Z3SRTPZ_cjs.defaultRenderers; }
14
+ get: function () { return chunkKBQDZ5IW_cjs.defaultRenderers; }
15
15
  });
16
16
  Object.defineProperty(exports, "escapeHtml", {
17
17
  enumerable: true,
18
- get: function () { return chunk7Z3SRTPZ_cjs.escapeHtml; }
18
+ get: function () { return chunkKBQDZ5IW_cjs.escapeHtml; }
19
19
  });
20
20
  Object.defineProperty(exports, "generateCSS", {
21
21
  enumerable: true,
22
- get: function () { return chunk7Z3SRTPZ_cjs.generateCSS; }
22
+ get: function () { return chunkKBQDZ5IW_cjs.generateCSS; }
23
23
  });
24
24
  Object.defineProperty(exports, "preview", {
25
25
  enumerable: true,
26
- get: function () { return chunk7Z3SRTPZ_cjs.preview; }
26
+ get: function () { return chunkKBQDZ5IW_cjs.preview; }
27
27
  });
28
28
  //# sourceMappingURL=index.cjs.map
29
29
  //# sourceMappingURL=index.cjs.map
@@ -1,6 +1,6 @@
1
1
  import * as _lezer_markdown from '@lezer/markdown';
2
2
  import { MarkdownConfig } from '@lezer/markdown';
3
- import { d as DraftlyPlugin, T as ThemeEnum } from '../draftly-Bxu_H4nw.cjs';
3
+ import { d as DraftlyPlugin, T as ThemeEnum } from '../draftly-BLnx3uGX.cjs';
4
4
  import { SyntaxNode } from '@lezer/common';
5
5
  import '@codemirror/state';
6
6
  import '@codemirror/view';
@@ -19,7 +19,7 @@ interface PreviewContext {
19
19
  /** Sanitize HTML content (for HTMLBlock/HTMLTag) */
20
20
  sanitize(html: string): string;
21
21
  /** Render children of a node to HTML */
22
- renderChildren(node: SyntaxNode): string;
22
+ renderChildren(node: SyntaxNode): Promise<string>;
23
23
  }
24
24
  /**
25
25
  * Configuration for the preview renderer
@@ -78,7 +78,7 @@ type NodeRendererMap = Record<string, NodeRenderer>;
78
78
  * });
79
79
  * ```
80
80
  */
81
- declare function preview(markdown: string, config?: PreviewConfig): string;
81
+ declare function preview(markdown: string, config?: PreviewConfig): Promise<string>;
82
82
 
83
83
  /**
84
84
  * Generate CSS for preview rendering
@@ -120,11 +120,16 @@ declare class PreviewRenderer {
120
120
  private sanitizeHtml;
121
121
  private renderers;
122
122
  private ctx;
123
+ private nodeToPlugins;
123
124
  constructor(doc: string, plugins: DraftlyPlugin[] | undefined, markdown: MarkdownConfig[], theme?: ThemeEnum, sanitize?: boolean);
125
+ /**
126
+ * Build a map from node names to plugins that handle them
127
+ */
128
+ private buildNodePluginMap;
124
129
  /**
125
130
  * Render the document to HTML
126
131
  */
127
- render(): string;
132
+ render(): Promise<string>;
128
133
  /**
129
134
  * Render a single node to HTML
130
135
  */
@@ -1,6 +1,6 @@
1
1
  import * as _lezer_markdown from '@lezer/markdown';
2
2
  import { MarkdownConfig } from '@lezer/markdown';
3
- import { d as DraftlyPlugin, T as ThemeEnum } from '../draftly-Bxu_H4nw.js';
3
+ import { d as DraftlyPlugin, T as ThemeEnum } from '../draftly-BLnx3uGX.js';
4
4
  import { SyntaxNode } from '@lezer/common';
5
5
  import '@codemirror/state';
6
6
  import '@codemirror/view';
@@ -19,7 +19,7 @@ interface PreviewContext {
19
19
  /** Sanitize HTML content (for HTMLBlock/HTMLTag) */
20
20
  sanitize(html: string): string;
21
21
  /** Render children of a node to HTML */
22
- renderChildren(node: SyntaxNode): string;
22
+ renderChildren(node: SyntaxNode): Promise<string>;
23
23
  }
24
24
  /**
25
25
  * Configuration for the preview renderer
@@ -78,7 +78,7 @@ type NodeRendererMap = Record<string, NodeRenderer>;
78
78
  * });
79
79
  * ```
80
80
  */
81
- declare function preview(markdown: string, config?: PreviewConfig): string;
81
+ declare function preview(markdown: string, config?: PreviewConfig): Promise<string>;
82
82
 
83
83
  /**
84
84
  * Generate CSS for preview rendering
@@ -120,11 +120,16 @@ declare class PreviewRenderer {
120
120
  private sanitizeHtml;
121
121
  private renderers;
122
122
  private ctx;
123
+ private nodeToPlugins;
123
124
  constructor(doc: string, plugins: DraftlyPlugin[] | undefined, markdown: MarkdownConfig[], theme?: ThemeEnum, sanitize?: boolean);
125
+ /**
126
+ * Build a map from node names to plugins that handle them
127
+ */
128
+ private buildNodePluginMap;
124
129
  /**
125
130
  * Render the document to HTML
126
131
  */
127
- render(): string;
132
+ render(): Promise<string>;
128
133
  /**
129
134
  * Render a single node to HTML
130
135
  */
@@ -1,4 +1,4 @@
1
- export { PreviewRenderer, defaultRenderers, escapeHtml, generateCSS, preview } from '../chunk-6LQ2VR4I.js';
2
- import '../chunk-LCQALOEI.js';
1
+ export { PreviewRenderer, defaultRenderers, escapeHtml, generateCSS, preview } from '../chunk-HPSMS2WB.js';
2
+ import '../chunk-DFQYXFOP.js';
3
3
  //# sourceMappingURL=index.js.map
4
4
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "draftly",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "1.0.7",
4
4
  "description": "Core library for draftly",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -34,6 +34,7 @@
34
34
  "@lezer/markdown": "^1.6.3",
35
35
  "dompurify": "^3.3.1",
36
36
  "katex": "^0.16.28",
37
+ "mermaid": "^11.12.2",
37
38
  "style-mod": "^4.1.3",
38
39
  "zod": "^4.3.6"
39
40
  },
@@ -8,6 +8,7 @@ import { defaultKeymap, history, historyKeymap, indentWithTab } from "@codemirro
8
8
  import { indentOnInput } from "@codemirror/language";
9
9
  import { languages } from "@codemirror/language-data";
10
10
  import { ThemeEnum } from "./utils";
11
+ import { markdownResetExtension } from "./theme";
11
12
 
12
13
  /**
13
14
  * DraftlyNode: represents a node in the markdown tree
@@ -29,9 +30,6 @@ export interface DraftlyConfig {
29
30
  /** Theme */
30
31
  theme?: ThemeEnum;
31
32
 
32
- /** ThemeStlye */
33
- themeStyle?: Extension;
34
-
35
33
  /** Weather to load base styles */
36
34
  baseStyles?: boolean;
37
35
 
@@ -93,7 +91,6 @@ export interface DraftlyConfig {
93
91
  export function draftly(config: DraftlyConfig = {}): Extension[] {
94
92
  const {
95
93
  theme: configTheme = ThemeEnum.AUTO,
96
- themeStyle: configThemeStyle = undefined,
97
94
  baseStyles = true,
98
95
  plugins = [],
99
96
  extensions = [],
@@ -171,8 +168,10 @@ export function draftly(config: DraftlyConfig = {}): Extension[] {
171
168
 
172
169
  // draftly extensions (pass plugins for decoration support)
173
170
  const draftlyExtensions: Extension[] = [];
174
- if (!disableViewPlugin)
171
+ if (!disableViewPlugin) {
175
172
  draftlyExtensions.push(createDraftlyViewExtension(configTheme, baseStyles, allPlugins, configOnNodesChange));
173
+ draftlyExtensions.push(Prec.highest(markdownResetExtension));
174
+ }
176
175
  if (!disableViewPlugin || configLineWrapping) draftlyExtensions.push(EditorView.lineWrapping);
177
176
 
178
177
  // Compose all extensions together
@@ -181,22 +180,19 @@ export function draftly(config: DraftlyConfig = {}): Extension[] {
181
180
  Prec.high(markdownSupport),
182
181
  Prec.high(keymap.of(markdownKeymap)),
183
182
 
184
- // Theme styles
185
- ...(configThemeStyle ? [Prec.high(configThemeStyle)] : []),
183
+ // draftly view plugin for rich rendering
184
+ draftlyExtensions,
186
185
 
187
186
  // Core CodeMirror extensions
188
- ...baseExtensions,
189
-
190
- // draftly view plugin for rich rendering
191
- ...draftlyExtensions,
187
+ baseExtensions,
192
188
 
193
189
  // Plugin extensions & keymaps
194
- ...pluginExtensions,
190
+ pluginExtensions,
195
191
  pluginKeymaps.length > 0 ? keymap.of(pluginKeymaps) : [],
196
192
 
197
193
  // Config keymaps & extensions
198
194
  configKeymap.length > 0 ? keymap.of(configKeymap) : [],
199
- ...extensions,
195
+ extensions,
200
196
  ];
201
197
 
202
198
  return composedExtensions;
@@ -60,6 +60,9 @@ export abstract class DraftlyPlugin {
60
60
  /** Plugin dependencies - names of required plugins */
61
61
  readonly dependencies: string[] = [];
62
62
 
63
+ /** Node types this plugin handles for decorations and preview rendering */
64
+ readonly requiredNodes: readonly string[] = [];
65
+
63
66
  /** Private configuration storage */
64
67
  private _config: PluginConfig = {};
65
68
 
@@ -212,7 +215,7 @@ export abstract class DraftlyPlugin {
212
215
  node: SyntaxNode,
213
216
  children: string,
214
217
  ctx: { sliceDoc(from: number, to: number): string; sanitize(html: string): string }
215
- ): string | null;
218
+ ): string | null | Promise<string | null>;
216
219
 
217
220
  /**
218
221
  * Get CSS styles for preview mode