@powerduck/md-editor 0.7.1 → 0.8.2

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,98 @@
1
+ import type { MarkdownIt } from "markdown-it";
2
+ import type { EditorView } from "@codemirror/view";
3
+ /**
4
+ * A document / article item returned by the search hook.
5
+ */
6
+ export interface DocItem {
7
+ /** Unique identifier */
8
+ id: string;
9
+ /** Document title */
10
+ title: string;
11
+ /** Document URL */
12
+ url: string;
13
+ /** Optional thumbnail URL (if known upfront) */
14
+ thumbnail?: string;
15
+ /** Optional description / excerpt (if known upfront) */
16
+ description?: string;
17
+ /** Allow arbitrary extra fields for consumer use */
18
+ [key: string]: unknown;
19
+ }
20
+ /**
21
+ * Fetched metadata for a document URL.
22
+ */
23
+ export interface DocMeta {
24
+ title?: string;
25
+ thumbnail?: string;
26
+ description?: string;
27
+ }
28
+ /**
29
+ * Options for the document-link inserter.
30
+ */
31
+ export interface DocLinkOptions {
32
+ /**
33
+ * Hook to search documents by query. Return a list of items (or a Promise).
34
+ * If not provided, the slash-triggered dropdown is disabled.
35
+ */
36
+ onDocSearch?: (query: string) => DocItem[] | Promise<DocItem[]>;
37
+ /**
38
+ * Hook to fetch metadata for a URL. Override this to use a backend proxy
39
+ * and avoid browser CORS restrictions. If not provided, a default fetch +
40
+ * DOMParser implementation is used (may fail on cross-origin URLs).
41
+ */
42
+ onFetchDocMeta?: (url: string) => Promise<DocMeta>;
43
+ /**
44
+ * Insert style when a document is selected.
45
+ * - 'card': always insert a :::doc-link preview card (falls back to link if no meta)
46
+ * - 'link': always insert a plain markdown link
47
+ * - 'auto' (default): insert card if metadata is available, link otherwise
48
+ */
49
+ insertStyle?: "card" | "link" | "auto";
50
+ /** Character that triggers the document search dropdown. Default: '/' */
51
+ triggerChar?: string;
52
+ /** Minimum query length before searching. Default: 0 */
53
+ minChars?: number;
54
+ /** Maximum items shown in dropdown. Default: 8 */
55
+ maxItems?: number;
56
+ }
57
+ /**
58
+ * Default implementation: fetch the URL and parse Open Graph / meta tags.
59
+ * This will fail on cross-origin URLs due to CORS; consumers should override
60
+ * with onFetchDocMeta using a backend proxy in production.
61
+ */
62
+ export declare function defaultFetchDocMeta(url: string): Promise<DocMeta>;
63
+ /** Parse OG / meta tags from an HTML string. */
64
+ export declare function parseDocMeta(html: string, baseUrl: string): DocMeta;
65
+ /**
66
+ * Detects the trigger character (default '/') in the editor and shows a
67
+ * floating document search dropdown. Handles keyboard navigation and inserts
68
+ * either a plain link or a :::doc-link preview card on selection.
69
+ */
70
+ export declare class DocLinkController {
71
+ private view;
72
+ private options;
73
+ private dropdown;
74
+ private items;
75
+ private selectedIndex;
76
+ private trigger;
77
+ private searchAbort;
78
+ private destroyed;
79
+ constructor(view: EditorView, options?: DocLinkOptions);
80
+ /** Called on every CodeMirror update. */
81
+ update(): void;
82
+ /** Handle keyboard events for dropdown navigation. */
83
+ handleKey(event: KeyboardEvent): boolean;
84
+ private findTrigger;
85
+ private runSearch;
86
+ private show;
87
+ private renderDropdown;
88
+ private positionDropdown;
89
+ private selectItem;
90
+ /**
91
+ * Build the markdown insertion string for a selected document.
92
+ * Fetches metadata if needed and falls back to a plain link.
93
+ */
94
+ private buildInsertion;
95
+ hide(): void;
96
+ destroy(): void;
97
+ }
98
+ export declare function useDocLinkBlock(md: MarkdownIt): void;
@@ -0,0 +1,69 @@
1
+ import type { EditorView } from "@codemirror/view";
2
+ /**
3
+ * A single item in the @mention dropdown.
4
+ */
5
+ export interface MentionItem {
6
+ /** Unique identifier */
7
+ id: string;
8
+ /** Display label shown in the dropdown */
9
+ label: string;
10
+ /** Optional avatar URL */
11
+ avatar?: string;
12
+ /** Optional secondary text (e.g. email, role) */
13
+ description?: string;
14
+ /** Allow arbitrary extra fields for consumer use */
15
+ [key: string]: unknown;
16
+ }
17
+ /**
18
+ * Options for the mention controller.
19
+ */
20
+ export interface MentionOptions {
21
+ /**
22
+ * Hook to search for mention items based on the query text after @.
23
+ * Return a list of items (or a Promise that resolves to one).
24
+ * If not provided, no dropdown is shown.
25
+ */
26
+ onMentionSearch?: (query: string) => MentionItem[] | Promise<MentionItem[]>;
27
+ /**
28
+ * Hook called when an item is selected. Return the text to insert at the
29
+ * cursor (replacing the @query). If not provided, defaults to `@${item.label}`.
30
+ */
31
+ onMentionSelect?: (item: MentionItem) => string;
32
+ /** Minimum query length before showing dropdown. Default: 0 (show on @). */
33
+ minChars?: number;
34
+ /** Maximum items shown in dropdown. Default: 8. */
35
+ maxItems?: number;
36
+ }
37
+ /**
38
+ * Detects @mention triggers in the editor and shows a floating dropdown.
39
+ * Handles keyboard navigation (ArrowUp/Down, Enter, Escape) and mouse click.
40
+ */
41
+ export declare class MentionController {
42
+ private view;
43
+ private options;
44
+ private dropdown;
45
+ private items;
46
+ private selectedIndex;
47
+ private trigger;
48
+ private searchAbort;
49
+ private destroyed;
50
+ constructor(view: EditorView, options?: MentionOptions);
51
+ /**
52
+ * Called on every CodeMirror update. Detects @ triggers and manages
53
+ * the dropdown visibility.
54
+ */
55
+ update(): void;
56
+ /**
57
+ * Handle keyboard events for dropdown navigation.
58
+ * Returns true if the event was handled (and should not propagate).
59
+ */
60
+ handleKey(event: KeyboardEvent): boolean;
61
+ private findTrigger;
62
+ private runSearch;
63
+ private show;
64
+ private renderDropdown;
65
+ private positionDropdown;
66
+ private selectItem;
67
+ hide(): void;
68
+ destroy(): void;
69
+ }
@@ -5,6 +5,13 @@ import type { MarkdownIt } from "markdown-it";
5
5
  * asynchronously in hydrateMindmaps() because markdown-it renders strings
6
6
  * synchronously while markmap requires real DOM nodes.
7
7
  *
8
+ * NESTED FENCE SUPPORT: Unlike markdown-it's built-in fence rule (which
9
+ * closes a 3-backtick fence at the first 3-backtick line, losing nested
10
+ * code content), this custom block rule tracks nesting depth. A line with
11
+ * backticks + an info string (e.g. ```js) opens a nested fence; a line with
12
+ * only backticks closes one. The mindmap block only closes when depth
13
+ * returns to 0. This allows code examples inside mindmap outlines.
14
+ *
8
15
  * Usage (in the editor markdown source):
9
16
  *
10
17
  * ```mindmap
@@ -9,6 +9,7 @@ export interface PopupConfig {
9
9
  title: string;
10
10
  fields: readonly PopupField[];
11
11
  submitLabel?: string;
12
+ theme?: 'light' | 'dark';
12
13
  onSubmit: (values: Record<string, string>) => void;
13
14
  }
14
15
  /**
@@ -0,0 +1,7 @@
1
+ import type { MarkdownIt } from "markdown-it";
2
+ /**
3
+ * Lightweight task list (checkbox) support for markdown-it.
4
+ * Converts `- [ ]` and `- [x]` list items into checkboxes without
5
+ * requiring the full markdown-it-task-lists dependency.
6
+ */
7
+ export declare function useTaskList(md: MarkdownIt): void;