@mdxeditor/editor 0.1.1 → 0.3.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/dist/index.d.ts CHANGED
@@ -9,7 +9,6 @@
9
9
 
10
10
  import { AdmonitionKind } from 'lexical';
11
11
  import type { ComponentType } from 'react';
12
- import { ContainerDirective } from 'mdast-util-directive';
13
12
  import { DecoratorNode } from 'lexical';
14
13
  import type { DOMConversionMap } from 'lexical';
15
14
  import type { DOMExportOutput } from 'lexical';
@@ -17,25 +16,13 @@ import { EditorConfig } from 'lexical';
17
16
  import { EditorThemeClasses } from 'lexical';
18
17
  import { ElementNode } from 'lexical';
19
18
  import { FromMarkdownOptions } from 'mdast-util-from-markdown/lib';
20
- import { HeadingNode } from '@lexical/rich-text';
21
- import { HorizontalRuleNode } from '@lexical/react/LexicalHorizontalRuleNode';
22
19
  import { Klass } from 'lexical';
23
20
  import { LexicalEditor } from 'lexical';
24
21
  import { LexicalNode } from 'lexical';
25
- import { LineBreakNode } from 'lexical';
26
- import { LinkNode } from '@lexical/link';
27
- import { ListItemNode } from '@lexical/list';
28
- import { ListNode } from '@lexical/list';
29
22
  import * as Mdast from 'mdast';
30
- import { MdxjsEsm } from 'mdast-util-mdx';
31
23
  import { MdxJsxAttribute } from 'mdast-util-mdx-jsx';
32
- import type { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';
33
- import type { MdxJsxTextElement } from 'mdast-util-mdx-jsx';
34
- import { MdxJsxTextElement as MdxJsxTextElement_2 } from 'mdast-util-mdx';
35
24
  import { NodeKey } from 'lexical';
36
- import { ParagraphNode } from 'lexical';
37
25
  import { ParseOptions } from 'mdast-util-from-markdown/lib';
38
- import { QuoteNode } from '@lexical/rich-text';
39
26
  import * as RadixToolbar from '@radix-ui/react-toolbar';
40
27
  import { RangeSelection } from 'lexical';
41
28
  import { default as React_2 } from 'react';
@@ -45,41 +32,103 @@ import { SerializedEditorState } from 'lexical';
45
32
  import { SerializedElementNode } from 'lexical';
46
33
  import { SerializedLexicalNode } from 'lexical';
47
34
  import { Spread } from 'lexical';
48
- import { TextNode } from 'lexical';
35
+ import { ToMarkdownExtension as ToMarkdownExtension_2 } from 'mdast-util-mdx';
49
36
  import { Options as ToMarkdownOptions } from 'mdast-util-to-markdown';
37
+ import { ToMarkdownOptions as ToMarkdownOptions_2 } from 'mdast-util-mdx';
50
38
 
39
+ /**
40
+ * Creates an {@link AdmonitionNode}.
41
+ * @param kind - The kind of admonition to create. Accepts `'note' | 'tip' | 'danger' | 'info' | 'caution'`
42
+ */
51
43
  export declare function $createAdmonitionNode(kind?: AdmonitionKind): AdmonitionNode;
52
44
 
53
- export declare function $createCodeBlockNode({ code, language, meta }: CodeBlockPayload): CodeBlockNode;
45
+ /**
46
+ * Creates a {@link CodeBlockNode}.
47
+ * @param options - The code contents, the language (i.e. js, jsx, etc.), and the additional meta data of the block.
48
+ */
49
+ export declare function $createCodeBlockNode(options: CreateCodeBlockNodeOptions): CodeBlockNode;
54
50
 
55
- export declare function $createFrontmatterNode({ yaml }: FrontmatterPayload): FrontmatterNode;
51
+ /**
52
+ * Creates a {@link FrontmatterNode}.
53
+ * @param yaml - The YAML string of the frontmatter.
54
+ */
55
+ export declare function $createFrontmatterNode(yaml: string): FrontmatterNode;
56
56
 
57
- export declare function $createImageNode({ altText, title, src, key }: ImagePayload): ImageNode;
57
+ /**
58
+ * Creates an {@link ImageNode}.
59
+ * @param options - The payload to create an image. The keys map to the img tag attributes.
60
+ */
61
+ export declare function $createImageNode(options: CreateImageNodeOptions): ImageNode;
58
62
 
59
- export declare function $createJsxNode(payload: JsxPayload): JsxNode;
63
+ /**
64
+ * Creates a {@link JsxNode}.
65
+ * @param options - The payload necessary for the creation of a {@link JsxNode}.
66
+ *
67
+ * @see {@link CreateJsxNodeOptions} for more details.
68
+ */
69
+ export declare function $createJsxNode(options: CreateJsxNodeOptions): JsxNode;
60
70
 
61
- export declare function $createSandpackNode({ code, language, meta }: SandpackPayload): SandpackNode;
71
+ /**
72
+ * Creates a {@link SandpackNode}.
73
+ */
74
+ export declare function $createSandpackNode(options: CreateSandpackNodeOptions): SandpackNode;
62
75
 
76
+ /**
77
+ * Creates a {@link TableNode}
78
+ * @param mdastNode - The mdast node to create the {@link TableNode} from.
79
+ */
63
80
  export declare function $createTableNode(mdastNode: Mdast.Table): TableNode;
64
81
 
82
+ /**
83
+ * Returns `true` if the given node is an {@link AdmonitionNode}.
84
+ */
65
85
  export declare function $isAdmonitionNode(node: LexicalNode | null | undefined): node is AdmonitionNode;
66
86
 
87
+ /**
88
+ * Returns true if the given node is a {@link CodeBlockNode}.
89
+ */
67
90
  export declare function $isCodeBlockNode(node: LexicalNode | null | undefined): node is CodeBlockNode;
68
91
 
92
+ /**
93
+ * Returns `true` if the given node is a {@link FrontmatterNode}.
94
+ */
69
95
  export declare function $isFrontmatterNode(node: LexicalNode | null | undefined): node is FrontmatterNode;
70
96
 
97
+ /**
98
+ * Retruns true if the node is an {@link ImageNode}.
99
+ */
71
100
  export declare function $isImageNode(node: LexicalNode | null | undefined): node is ImageNode;
72
101
 
102
+ /**
103
+ * Returns true if a node is a {@link JsxNode}.
104
+ */
73
105
  export declare function $isJsxNode(node: LexicalNode | null | undefined): node is JsxNode;
74
106
 
107
+ /**
108
+ * Returns true if the given node is a {@link SandpackNode}.
109
+ */
75
110
  export declare function $isSandpackNode(node: LexicalNode | null | undefined): node is SandpackNode;
76
111
 
112
+ /**
113
+ * Retruns true if the given node is a {@link TableNode}.
114
+ */
77
115
  export declare function $isTableNode(node: LexicalNode | null | undefined): node is TableNode;
78
116
 
79
- export declare type ActiveEditorType = LexicalEditorType | CodeBlockEditorType | SandpackEditorType;
80
-
81
117
  export { AdmonitionKind }
82
118
 
119
+ /**
120
+ * A lexical node that represents the markdown directives (better known as admonitions, thanks to Docusaurus). Use {@link "$createAdmonitionNode"} to construct one.
121
+ *
122
+ * @remarks
123
+ *
124
+ * An admonition in markdown looks like this:
125
+ *
126
+ * ```md
127
+ * :::tip
128
+ * Some **content** with _Markdown_ `syntax`. Check [this `api`](#).
129
+ * :::
130
+ * ```
131
+ */
83
132
  export declare class AdmonitionNode extends ElementNode {
84
133
  __kind: AdmonitionKind;
85
134
  static getType(): string;
@@ -95,15 +144,13 @@ export declare class AdmonitionNode extends ElementNode {
95
144
  collapseAtStart(): true;
96
145
  }
97
146
 
98
- export declare interface CodeBlockEditorProps extends SandpackEditorProps {
147
+ declare interface CodeBlockEditorProps extends SandpackEditorProps {
99
148
  language: string;
100
149
  }
101
150
 
102
- export declare type CodeBlockEditorType = {
103
- type: 'codeblock';
104
- nodeKey: string;
105
- };
106
-
151
+ /**
152
+ * A lexical node that represents a fenced code block. Use {@link "$createCodeBlockNode"} to construct one.
153
+ */
107
154
  export declare class CodeBlockNode extends DecoratorNode<JSX.Element> {
108
155
  __code: string;
109
156
  __meta: string;
@@ -129,93 +176,119 @@ export declare class CodeBlockNode extends DecoratorNode<JSX.Element> {
129
176
  decorate(_editor: LexicalEditor, { theme: { nodeDecoratorComponents: { CodeBlockEditor } } }: ExtendedEditorConfig): JSX.Element;
130
177
  }
131
178
 
132
- export declare interface CodeBlockPayload {
179
+ declare type CoordinatesSubscription = (coords: [colIndex: number, rowIndex: number]) => void;
180
+
181
+ /**
182
+ * The options necessary to construct a {@link CodeBlockNode}.
183
+ */
184
+ export declare interface CreateCodeBlockNodeOptions {
185
+ /**
186
+ * The code contents of the block.
187
+ */
133
188
  code: string;
189
+ /**
190
+ * The additional meta data of the block.
191
+ */
134
192
  meta: string;
193
+ /**
194
+ * The language of the code block (i.e. `js`, `jsx`, etc.). This is used for syntax highlighting.
195
+ */
135
196
  language: string;
136
197
  }
137
198
 
138
- export declare type CoordinatesSubscription = (coords: [colIndex: number, rowIndex: number]) => void;
139
-
140
- export declare const defaultExtensions: {
141
- mdxToMarkdown: ToMarkdownOptions;
142
- frontmatterToMarkdown: ToMarkdownOptions;
143
- directiveToMarkdown: ToMarkdownOptions;
144
- gfmTableToMarkdown: ToMarkdownOptions;
145
- };
199
+ /**
200
+ * The payload to create an {@link ImageNode}.
201
+ */
202
+ export declare interface CreateImageNodeOptions {
203
+ altText: string;
204
+ title?: string;
205
+ key?: NodeKey;
206
+ src: string;
207
+ }
146
208
 
147
- export declare const defaultLexicalNodes: Record<string, Klass<LexicalNode>>;
148
-
149
- export declare const defaultLexicalVisitors: {
150
- LexicalRootVisitor: LexicalExportVisitor<RootNode, Mdast.Content>;
151
- LexicalParagraphVisitor: LexicalExportVisitor<ParagraphNode, Mdast.Paragraph>;
152
- LexicalFrontmatterVisitor: LexicalExportVisitor<FrontmatterNode, Mdast.YAML>;
153
- LexicalTextVisitor: LexicalExportVisitor<TextNode, Mdast.Text>;
154
- LexicalLinebreakVisitor: LexicalExportVisitor<LineBreakNode, Mdast.Text>;
155
- LexicalLinkVisitor: LexicalExportVisitor<LinkNode, Mdast.Link>;
156
- LexicalHeadingVisitor: LexicalExportVisitor<HeadingNode, Mdast.Heading>;
157
- LexicalListVisitor: LexicalExportVisitor<ListNode, Mdast.List>;
158
- LexicalListItemVisitor: LexicalExportVisitor<ListItemNode, Mdast.ListItem>;
159
- LexicalQuoteVisitor: LexicalExportVisitor<QuoteNode, Mdast.Blockquote>;
160
- SandpackNodeVisitor: LexicalExportVisitor<SandpackNode, Mdast.Code>;
161
- CodeBlockVisitor: LexicalExportVisitor<CodeBlockNode, Mdast.Code>;
162
- LexicalThematicBreakVisitor: LexicalExportVisitor<HorizontalRuleNode, Mdast.ThematicBreak>;
163
- AdmonitionVisitor: LexicalExportVisitor<AdmonitionNode, ContainerDirective>;
164
- LexicalImageVisitor: LexicalExportVisitor<ImageNode, Mdast.Image>;
165
- JsxVisitor: LexicalExportVisitor<JsxNode, MdxJsxFlowElement | MdxJsxTextElement>;
166
- LexicalTableVisitor: LexicalExportVisitor<TableNode, Mdast.Table>;
167
- };
209
+ /**
210
+ * The payload to create a {@link JsxNode}.
211
+ */
212
+ export declare interface CreateJsxNodeOptions {
213
+ /**
214
+ * The name of the JSX element.
215
+ */
216
+ name: string;
217
+ /**
218
+ * The type of the element - markdown makes a distinction between text and flow elements.
219
+ */
220
+ kind: JsxKind;
221
+ /**
222
+ * The attributes of the JSX element.
223
+ */
224
+ attributes: Array<MdxJsxAttribute>;
225
+ /**
226
+ * The tree state of the children.
227
+ */
228
+ state?: SerializedEditorState;
229
+ /**
230
+ * If passed, this function will be called with the root paragraph node of the editor.
231
+ */
232
+ updateFn?: updateFn;
233
+ }
168
234
 
169
- export declare const defaultMdastExtensions: Record<string, MarkdownParseOptions['mdastExtensions'][number]>;
235
+ /**
236
+ * The options necessary to construct a {@link SandpackNode}.
237
+ */
238
+ export declare interface CreateSandpackNodeOptions {
239
+ code: string;
240
+ meta: string;
241
+ language: string;
242
+ }
170
243
 
171
- export declare const defaultMdastVisitors: Record<string, MdastImportVisitor<Mdast.Content>>;
244
+ /**
245
+ * The default set of lexical nodes used in the editor.
246
+ */
247
+ declare const defaultLexicalNodes: Record<string, Klass<LexicalNode>>;
172
248
 
173
- export declare interface DefaultMdxOptionValues {
249
+ /**
250
+ * A structure that holds the default values for the options used in the markdown import/export steps.
251
+ *
252
+ * Most options are exported as records, so that you can pick a specific value using its name rather than its index which can change.
253
+ * The actual MDXEditor props accept arrays, so you should use the `Object.values` function to convert the records to arrays.
254
+ */
255
+ export declare type DefaultMdxOptionValues = {
256
+ /** The default values for the options used in the import step */
174
257
  markdownParse: {
175
- defaultVisitors: typeof defaultMdastVisitors;
176
- defaultSyntaxExtensions: typeof defaultSyntaxExtensions;
177
- defaultMdastExtensions: typeof defaultMdastExtensions;
258
+ defaultVisitors: Record<string, MdastImportVisitor<Mdast.Content>>;
259
+ defaultSyntaxExtensions: Record<string, SyntaxExtension>;
260
+ defaultMdastExtensions: Record<string, MdastExtension>;
178
261
  };
262
+ /** The default values for the options used in the markdown export step */
179
263
  lexicalConvert: {
180
- defaultVisitors: typeof defaultLexicalVisitors;
181
- defaultExtensions: typeof defaultExtensions;
182
- defaultMarkdownOptions: typeof defaultToMarkdownOptions;
264
+ defaultVisitors: Record<string, LexicalExportVisitor<LexicalNode, Mdast.Content>>;
265
+ defaultExtensions: Record<string, ToMarkdownExtension_2>;
266
+ defaultMarkdownOptions: ToMarkdownOptions_2;
183
267
  };
268
+ /** The default lexical nodes used by the underlying Lexical framework */
184
269
  defaultLexicalNodes: typeof defaultLexicalNodes;
185
- }
270
+ };
186
271
 
272
+ /**
273
+ * Exports the default values for the options used in the markdown import/export steps.
274
+ */
187
275
  export declare const defaultMdxOptionValues: DefaultMdxOptionValues;
188
276
 
189
- export declare const defaultSyntaxExtensions: Record<string, MarkdownParseOptions['syntaxExtensions'][number]>;
190
-
191
- export declare const defaultToMarkdownOptions: ToMarkdownOptions;
192
-
193
- export declare interface ExportLexicalTreeOptions {
194
- root: RootNode;
195
- visitors: LexicalVisitor[];
196
- jsxComponentDescriptors: JsxComponentDescriptors;
197
- }
198
-
199
- export declare function exportLexicalTreeToMdast({ root, visitors, jsxComponentDescriptors }: ExportLexicalTreeOptions): Mdast.Root;
200
-
201
- export declare function exportMarkdownFromLexical({ root, toMarkdownOptions, toMarkdownExtensions, visitors, jsxComponentDescriptors }: ExportMarkdownFromLexicalOptions): string;
202
-
203
- export declare interface ExportMarkdownFromLexicalOptions extends ExportLexicalTreeOptions {
204
- toMarkdownExtensions: ToMarkdownOptions['extensions'];
205
- toMarkdownOptions: ToMarkdownOptions;
206
- }
207
-
208
277
  declare type ExtendedEditorConfig = EditorConfig & {
209
278
  theme: EditorConfig['theme'] & {
210
279
  nodeDecoratorComponents: NodeDecoratorComponents;
211
280
  };
212
281
  };
213
282
 
214
- export declare interface FrontmatterEditorProps {
283
+ declare interface FrontmatterEditorProps {
215
284
  yaml: string;
216
285
  onChange: (yaml: string) => void;
217
286
  }
218
287
 
288
+ /**
289
+ * Represents {@link https://daily-dev-tips.com/posts/what-exactly-is-frontmatter/ | the frontmatter} of the markdown document.
290
+ * Use {@link "$createFrontmatterNode"} to construct one.
291
+ */
219
292
  export declare class FrontmatterNode extends DecoratorNode<JSX.Element> {
220
293
  __yaml: string;
221
294
  static getType(): string;
@@ -230,10 +303,9 @@ export declare class FrontmatterNode extends DecoratorNode<JSX.Element> {
230
303
  decorate(editor: LexicalEditor, { theme: { nodeDecoratorComponents: { FrontmatterEditor } } }: ExtendedEditorConfig): JSX.Element;
231
304
  }
232
305
 
233
- export declare interface FrontmatterPayload {
234
- yaml: string;
235
- }
236
-
306
+ /**
307
+ * A lexical node that represents an image. Use {@link "$createImageNode"} to construct one.
308
+ */
237
309
  export declare class ImageNode extends DecoratorNode<JSX.Element> {
238
310
  __src: string;
239
311
  __altText: string;
@@ -254,36 +326,39 @@ export declare class ImageNode extends DecoratorNode<JSX.Element> {
254
326
  decorate(): JSX.Element;
255
327
  }
256
328
 
257
- export declare interface ImagePayload {
258
- altText: string;
259
- title?: string;
260
- key?: NodeKey;
261
- src: string;
262
- }
263
-
264
- export declare function importMarkdownToLexical({ root, markdown, visitors, syntaxExtensions, mdastExtensions }: MarkdownParseOptions): void;
265
-
266
- export declare function importMdastTreeToLexical({ root, mdastRoot, visitors }: MdastTreeImportOptions): void;
267
-
268
- export declare type ImportVisitors = Array<MdastImportVisitor<Mdast.Content>>;
269
-
270
329
  declare const IS_BOLD: 1;
271
330
 
272
331
  declare const IS_ITALIC: 2;
273
332
 
274
333
  declare const IS_UNDERLINE: 8;
275
334
 
335
+ /**
336
+ * Defines the structure of a JSX component that can be used within the markdown document.
337
+ */
276
338
  export declare interface JsxComponentDescriptor {
339
+ /**
340
+ * The tag name
341
+ */
277
342
  name: string;
343
+ /**
344
+ * Wether the component is a flow or text component (inline or block)
345
+ */
278
346
  kind: 'flow' | 'text';
347
+ /**
348
+ * The module path from which the component can be imported
349
+ */
279
350
  source: string;
351
+ /**
352
+ * Wether the component is the default export of the module
353
+ */
280
354
  defaultExport?: boolean;
355
+ /**
356
+ * The properties that can be applied to the component
357
+ */
281
358
  props: Array<JsxPropertyDescriptor>;
282
359
  }
283
360
 
284
- export declare type JsxComponentDescriptors = Array<JsxComponentDescriptor>;
285
-
286
- export declare interface JsxEditorProps {
361
+ declare interface JsxEditorProps {
287
362
  kind: JsxKind;
288
363
  attributes: MdxJsxAttribute[];
289
364
  componentName: string;
@@ -292,8 +367,11 @@ export declare interface JsxEditorProps {
292
367
  editor: LexicalEditor;
293
368
  }
294
369
 
295
- export declare type JsxKind = 'text' | 'flow';
370
+ declare type JsxKind = 'text' | 'flow';
296
371
 
372
+ /**
373
+ * A lexical node that represents a JSX element. Use {@link "$createJsxNode"} to construct one.
374
+ */
297
375
  export declare class JsxNode extends DecoratorNode<JSX.Element> {
298
376
  __kind: JsxKind;
299
377
  __name: string;
@@ -315,110 +393,195 @@ export declare class JsxNode extends DecoratorNode<JSX.Element> {
315
393
  decorate(_parentEditor: LexicalEditor, { theme: { nodeDecoratorComponents: { JsxEditor } } }: ExtendedEditorConfig): JSX.Element;
316
394
  }
317
395
 
318
- export declare interface JsxNodeConstructorParams extends JsxPayload {
396
+ /**
397
+ * The parameters of the {@link JsxNode} constructor.
398
+ */
399
+ export declare interface JsxNodeConstructorParams extends CreateJsxNodeOptions {
319
400
  key?: NodeKey;
320
401
  }
321
402
 
322
- export declare interface JsxPayload {
323
- name: string;
324
- kind: JsxKind;
325
- attributes: Array<MdxJsxAttribute>;
326
- state?: SerializedEditorState;
327
- updateFn?: updateFn;
328
- }
329
-
403
+ /**
404
+ * Defines the structure of a JSX component property.
405
+ */
330
406
  export declare interface JsxPropertyDescriptor {
407
+ /**
408
+ * The name of the property
409
+ */
331
410
  name: string;
411
+ /**
412
+ * The type of the property
413
+ */
332
414
  type: 'string' | 'number';
415
+ /**
416
+ * Wether the property is required
417
+ */
333
418
  required?: boolean;
334
419
  }
335
420
 
336
- export declare type LexicalEditorType = {
337
- type: 'lexical';
338
- };
421
+ /**
422
+ * Configures how the lexical tree is converted to a mdast tree and then to markdown.
423
+ */
424
+ export declare interface LexicalConvertOptions {
425
+ /**
426
+ * The visitors to use when processing the lexical tree
427
+ */
428
+ visitors?: LexicalVisitor[];
429
+ /**
430
+ * the markdown extensions to use
431
+ */
432
+ toMarkdownExtensions?: Array<ToMarkdownExtension>;
433
+ /**
434
+ * The options to pass to `toMarkdown`
435
+ */
436
+ toMarkdownOptions?: ToMarkdownOptions;
437
+ }
339
438
 
439
+ /**
440
+ * Implement this interface in order to process mdast node(s) into a lexical tree.
441
+ * This is part of the process that converts the editor contents to markdown.
442
+ */
340
443
  export declare interface LexicalExportVisitor<LN extends LexicalNode, UN extends Mdast.Content> {
444
+ /**
445
+ * Return true if the given node is of the type that this visitor can process.
446
+ * You can safely use the node type guard functions (as in $isParagraphNode, $isLinkNode, etc.) here.
447
+ */
341
448
  testLexicalNode?(lexicalNode: LexicalNode): lexicalNode is LN;
449
+ /**
450
+ * Process the given node and manipulate the mdast tree accordingly.
451
+ * @see {@link LexicalNodeVisitParams} and {@link LexicalVisitActions} for more information.
452
+ */
342
453
  visitLexicalNode?(params: LexicalNodeVisitParams<LN>): void;
454
+ /**
455
+ * Return true if the current node should be joined with the previous node.
456
+ * This is necessary due to some inconsistencies between the lexical tree and the mdast tree when it comes to formatting.
457
+ */
343
458
  shouldJoin?(prevNode: Mdast.Content, currentNode: UN): boolean;
459
+ /**
460
+ * Join the current node with the previous node, returning the resulting new node
461
+ * For this to be called by the tree walk, shouldJoin must return true.
462
+ */
344
463
  join?<T extends Mdast.Content>(prevNode: T, currentNode: T): T;
345
464
  }
346
465
 
466
+ /**
467
+ * The params passed to the {@link LexicalExportVisitor.visitLexicalNode} method.
468
+ */
347
469
  export declare interface LexicalNodeVisitParams<T extends LexicalNode> {
470
+ /**
471
+ * The lexical node that is being visited.
472
+ */
348
473
  lexicalNode: T;
474
+ /**
475
+ * The mdast parent node that the result of the lexical node conversion should be appended to.
476
+ */
349
477
  mdastParent: Mdast.Parent;
478
+ /**
479
+ * A set of actions that can be used to manipulate the mdast tree.
480
+ * These are "convenience" utilities that avoid the repetitive boilerplate of creating mdast nodes.
481
+ */
350
482
  actions: LexicalVisitActions<T>;
351
483
  }
352
484
 
485
+ /**
486
+ * A set of covenience utilities to manipulate the mdast tree when processing lexical nodes.
487
+ */
353
488
  export declare interface LexicalVisitActions<T extends LexicalNode> {
489
+ /**
490
+ * Iterate over the immediate children of a lexical node with the given mdast node as a parent.
491
+ */
354
492
  visitChildren(node: T, mdastParent: Mdast.Parent): void;
493
+ /**
494
+ * Create a new mdast node with the given type, and props.
495
+ * Iterate over the immediate children of the current lexical node with the new mdast node as a parent.
496
+ * @param hasChildren - true by default. Pass false to skip iterating over the lexical node children.
497
+ */
355
498
  addAndStepInto(type: string, props?: Record<string, unknown>, hasChildren?: boolean): void;
499
+ /**
500
+ * Append a new mdast node to a parent node.
501
+ * @param parentNode - the mdast parent node to append the new node to.
502
+ * @param node - the mdast node to append.
503
+ */
356
504
  appendToParent<T extends Mdast.Parent>(parentNode: T, node: T['children'][number]): T['children'][number] | Mdast.Root;
505
+ /**
506
+ * Used when processing JSX nodes so that later, the correct import statement can be added to the document.
507
+ * @param componentName - the name of the component that has to be imported.
508
+ * @see {@link JsxComponentDescriptor}
509
+ */
357
510
  registerReferredComponent(componentName: string): void;
358
511
  }
359
512
 
360
- export declare type LexicalVisitor = LexicalExportVisitor<LexicalNode, Mdast.Content>;
513
+ declare type LexicalVisitor = LexicalExportVisitor<LexicalNode, Mdast.Content>;
361
514
 
515
+ /**
516
+ * Options that control how the the markdown input string is parsed into a tree.
517
+ * @see {@link https://github.com/syntax-tree/mdast-util-from-markdown | fromMarkdown}
518
+ */
362
519
  export declare interface MarkdownParseOptions extends Omit<MdastTreeImportOptions, 'mdastRoot'> {
363
520
  markdown: string;
364
521
  syntaxExtensions: NonNullable<ParseOptions['extensions']>;
365
522
  mdastExtensions: NonNullable<FromMarkdownOptions['mdastExtensions']>;
366
523
  }
367
524
 
368
- export declare const MdastAdmonitionVisitor: MdastImportVisitor<ContainerDirective>;
369
-
370
- export declare const MdastBlockQuoteVisitor: MdastImportVisitor<Mdast.Blockquote>;
371
-
372
- export declare const MdastCodeVisitor: MdastImportVisitor<Mdast.Code>;
373
-
374
- export declare const MdastFormattingVisitor: MdastImportVisitor<Mdast.Emphasis | Mdast.Strong | MdxJsxTextElement_2>;
375
-
376
- export declare const MdastFrontmatterVisitor: MdastImportVisitor<Mdast.YAML>;
377
-
378
- export declare const MdastHeadingVisitor: MdastImportVisitor<Mdast.Heading>;
379
-
380
- export declare const MdastImageVisitor: MdastImportVisitor<Mdast.Image>;
525
+ /**
526
+ * An extension for the `fromMarkdown` utility tree construction.
527
+ */
528
+ declare type MdastExtension = MarkdownParseOptions['mdastExtensions'][number];
381
529
 
530
+ /**
531
+ * Implement this interface to convert certian mdast nodes into lexical nodes.
532
+ * @typeParam UN - The type of the mdast node that is being visited.
533
+ */
382
534
  export declare interface MdastImportVisitor<UN extends Mdast.Content> {
535
+ /**
536
+ * The test function that determines if this visitor should be used for the given node.
537
+ * As a convenience, you can also pass a string here, which will be compared to the node's type.
538
+ */
383
539
  testNode: ((mdastNode: Mdast.Content | Mdast.Root) => boolean) | string;
540
+ /**
541
+ * The function that is called when the node is visited. See {@link MdastVisitParams} for details.
542
+ */
384
543
  visitNode(params: MdastVisitParams<UN>): void;
385
544
  }
386
545
 
387
- export declare const MdastInlineCodeVisitor: MdastImportVisitor<Mdast.InlineCode>;
388
-
389
- export declare const MdastLinkVisitor: MdastImportVisitor<Mdast.Link>;
390
-
391
- export declare const MdastListItemVisitor: MdastImportVisitor<Mdast.ListItem>;
392
-
393
- export declare const MdastListVisitor: MdastImportVisitor<Mdast.List>;
394
-
395
- export declare const MdastMdxJsEsmVisitor: MdastImportVisitor<MdxjsEsm>;
396
-
397
- export declare const MdastMdxJsxElementVisitor: MdastImportVisitor<MdxJsxTextElement_2>;
398
-
399
- export declare const MdastParagraphVisitor: MdastImportVisitor<Mdast.Paragraph>;
400
-
401
- export declare const MdastRootVisitor: MdastImportVisitor<Mdast.Content>;
402
-
403
- export declare const MdastTableVisitor: MdastImportVisitor<Mdast.Table>;
404
-
405
- export declare const MdastTextVisitor: MdastImportVisitor<Mdast.Text>;
406
-
407
- export declare const MdastThematicBreakVisitor: MdastImportVisitor<Mdast.ThematicBreak>;
408
-
546
+ /**
547
+ * The options of the tree import utility. Not meant to be used directly.
548
+ */
409
549
  export declare interface MdastTreeImportOptions {
410
550
  root: RootNode;
411
551
  visitors: Array<MdastImportVisitor<Mdast.Content>>;
412
552
  mdastRoot: Mdast.Root;
413
553
  }
414
554
 
555
+ /**
556
+ * A set of actions that can be used to modify the lexical tree while visiting the mdast tree.
557
+ */
415
558
  export declare interface MdastVisitActions {
559
+ /**
560
+ * Iterate the children of the node with the lexical node as the parent.
561
+ */
416
562
  visitChildren(node: Mdast.Parent, lexicalParent: LexicalNode): void;
563
+ /**
564
+ * Add the given node to the lexical tree, and iterate the current mdast node's children with the newly created lexical node as a parent.
565
+ */
417
566
  addAndStepInto(lexicalNode: LexicalNode): void;
567
+ /**
568
+ * Adds formatting as a context for the current node and its children.
569
+ * This is necessary due to mdast treating formatting as a node, while lexical considering it an attribute of a node.
570
+ */
418
571
  addFormatting(format: typeof IS_BOLD | typeof IS_ITALIC | typeof IS_UNDERLINE): void;
572
+ /**
573
+ * Access the current formatting context.
574
+ */
419
575
  getParentFormatting(): number;
420
576
  }
421
577
 
578
+ /**
579
+ * Parameters passe to the {@link MdastImportVisitor.visitNode} function.
580
+ * @param mdastNode - The node that is currently being visited.
581
+ * @param lexicalParent - The parent lexical node to which the results of the processing should be added.
582
+ * @param actions - A set of convenience utilities that can be used to add nodes to the lexical tree.
583
+ * @typeParam T - The type of the mdast node that is being visited.
584
+ */
422
585
  export declare interface MdastVisitParams<T extends Mdast.Content> {
423
586
  mdastNode: T;
424
587
  lexicalParent: LexicalNode;
@@ -462,9 +625,9 @@ export declare interface MDXEditorProps {
462
625
  headMarkdown?: string;
463
626
  /**
464
627
  * The configuration for the JSX components used in the markdown content.
465
- * @see the {@link JsxComponentDescriptors} interface for more details.
628
+ * @see the {@link JsxComponentDescriptor} interface for more details.
466
629
  */
467
- jsxComponentDescriptors?: JsxComponentDescriptors;
630
+ jsxComponentDescriptors?: JsxComponentDescriptor[];
468
631
  /**
469
632
  * The list of suggestions to be shown in the link autocomplete dialog dropdown.
470
633
  */
@@ -481,12 +644,36 @@ export declare interface MDXEditorProps {
481
644
  * The initial view mode for the editor. Defaults to `ViewMode.editor`.
482
645
  */
483
646
  viewMode?: ViewMode;
647
+ /**
648
+ * Triggered when the markdown content changes.
649
+ */
484
650
  onChange?: (markdown: string) => void;
651
+ /**
652
+ * The CSS class name to be applied to the wrapper element of the component.
653
+ */
485
654
  className?: string;
655
+ /**
656
+ * The CSS class name to be applied to the content editable element.
657
+ */
486
658
  contentEditableClassName?: string;
659
+ /**
660
+ * The options to be used when parsing the markdown content.
661
+ * @see the {@link MarkdownParseOptions} interface for more details.
662
+ */
487
663
  markdownParseOptions?: Partial<MarkdownParseOptions>;
664
+ /**
665
+ * The {@link https://lexical.dev/ | Lexical nodes} used by the editor.
666
+ */
488
667
  lexicalNodes?: Klass<LexicalNode>[];
489
- lexicalConvertOptions?: Partial<ExportMarkdownFromLexicalOptions>;
668
+ /**
669
+ * The options used when converting the lexical tree to markdown.
670
+ * @see the {@link LexicalConvertOptions} interface for more details.
671
+ */
672
+ lexicalConvertOptions?: LexicalConvertOptions;
673
+ /**
674
+ * The supported code block languages.
675
+ */
676
+ codeBlockLanguages?: Record<string, string>;
490
677
  }
491
678
 
492
679
  declare interface NodeDecoratorComponents {
@@ -498,20 +685,20 @@ declare interface NodeDecoratorComponents {
498
685
  }
499
686
 
500
687
  /**
501
- * The configuration for the available sandpack presets
688
+ * The configuration for the available sandpack presets.
502
689
  */
503
690
  export declare interface SandpackConfig {
504
691
  /**
505
- * The name of the default preset that will be used if no meta (other than live) is set
692
+ * The name of the default preset that will be used if no meta (other than live) is set.
506
693
  */
507
694
  defaultPreset: string;
508
695
  /**
509
- * The list of sandpack presets that can be used
696
+ * The list of sandpack presets that can be used.
510
697
  */
511
698
  presets: Array<SandpackPreset>;
512
699
  }
513
700
 
514
- export declare interface SandpackEditorProps {
701
+ declare interface SandpackEditorProps {
515
702
  code: string;
516
703
  nodeKey: string;
517
704
  meta: string;
@@ -519,11 +706,9 @@ export declare interface SandpackEditorProps {
519
706
  focusEmitter: VoidEmitter;
520
707
  }
521
708
 
522
- export declare type SandpackEditorType = {
523
- type: 'sandpack';
524
- nodeKey: string;
525
- };
526
-
709
+ /**
710
+ * A lexical node that represents a live code block that gets a preview. Use {@link "$createSandpackNode"} to construct one.
711
+ */
527
712
  export declare class SandpackNode extends DecoratorNode<JSX.Element> {
528
713
  __code: string;
529
714
  __meta: string;
@@ -549,22 +734,16 @@ export declare class SandpackNode extends DecoratorNode<JSX.Element> {
549
734
  decorate(_parentEditor: LexicalEditor, { theme: { nodeDecoratorComponents: { SandpackEditor } } }: ExtendedEditorConfig): JSX.Element;
550
735
  }
551
736
 
552
- export declare interface SandpackPayload {
553
- code: string;
554
- meta: string;
555
- language: string;
556
- }
557
-
558
737
  /**
559
738
  * Defines a single preset that can be used to create a sandbox.
560
739
  */
561
740
  export declare interface SandpackPreset {
562
741
  /**
563
- * The name of the preset - use this to reference the preset from the defaultPreset field
742
+ * The name of the preset - use this to reference the preset from the defaultPreset field.
564
743
  */
565
744
  name: string;
566
745
  /**
567
- * The label of th preset, displayed in the sandpack button dropdown
746
+ * The label of the preset, displayed in the sandpack button dropdown.
568
747
  */
569
748
  label: string;
570
749
  /**
@@ -580,11 +759,11 @@ export declare interface SandpackPreset {
580
759
  */
581
760
  sandpackTheme: SandpackProviderProps['theme'];
582
761
  /**
583
- * The name of the file that will be created in the sandbox. e.g. "/App.js"
762
+ * The name of the file that will be created in the sandbox. e.g. "/App.js".
584
763
  */
585
764
  snippetFileName: string;
586
765
  /**
587
- * The dependencies that will be added to the sandbox, just like in package.json
766
+ * The dependencies that will be added to the sandbox, just like in package.json.
588
767
  */
589
768
  dependencies?: Record<string, string>;
590
769
  /**
@@ -593,7 +772,7 @@ export declare interface SandpackPreset {
593
772
  */
594
773
  files?: Record<string, string>;
595
774
  /**
596
- * The language used in the editable snippet. e.g. "jsx", "tsx", etc
775
+ * The language used in the editable snippet. e.g. "jsx", "tsx", etc.
597
776
  */
598
777
  snippetLanguage?: string;
599
778
  /**
@@ -604,22 +783,34 @@ export declare interface SandpackPreset {
604
783
 
605
784
  declare type SandpackProviderProps = React_2.ComponentProps<typeof SandpackProvider>;
606
785
 
786
+ /**
787
+ * A serialized representation of an {@link AdmonitionNode}.
788
+ */
607
789
  export declare type SerializedAdmonitionNode = Spread<{
608
790
  type: 'admonition';
609
791
  kind: AdmonitionKind;
610
792
  version: 1;
611
793
  }, SerializedElementNode>;
612
794
 
613
- export declare type SerializedCodeBlockNode = Spread<CodeBlockPayload & {
795
+ /**
796
+ * A serialized representation of an {@link CodeBlockNode}.
797
+ */
798
+ export declare type SerializedCodeBlockNode = Spread<CreateCodeBlockNodeOptions & {
614
799
  type: 'codeblock';
615
800
  version: 1;
616
801
  }, SerializedLexicalNode>;
617
802
 
803
+ /**
804
+ * A serialized representation of an {@link FrontmatterNode}.
805
+ */
618
806
  export declare type SerializedFrontmatterNode = Spread<{
619
807
  yaml: string;
620
808
  version: 1;
621
809
  }, SerializedLexicalNode>;
622
810
 
811
+ /**
812
+ * A serialized representation of an {@link ImageNode}.
813
+ */
623
814
  export declare type SerializedImageNode = Spread<{
624
815
  altText: string;
625
816
  title?: string;
@@ -628,26 +819,44 @@ export declare type SerializedImageNode = Spread<{
628
819
  version: 1;
629
820
  }, SerializedLexicalNode>;
630
821
 
631
- export declare type SerializedJsxNode = Spread<Omit<JsxPayload, 'updateFn'> & {
822
+ /**
823
+ * A serialized representation of a {@link JsxNode}.
824
+ */
825
+ export declare type SerializedJsxNode = Spread<Omit<CreateJsxNodeOptions, 'updateFn'> & {
632
826
  version: 1;
633
827
  type: 'jsx';
634
828
  }, SerializedLexicalNode>;
635
829
 
636
- export declare type SerializedSandpackNode = Spread<SandpackPayload & {
830
+ /**
831
+ * A serialized representation of an {@link SandpackNode}.
832
+ */
833
+ export declare type SerializedSandpackNode = Spread<CreateSandpackNodeOptions & {
637
834
  type: 'sandpack';
638
835
  version: 1;
639
836
  }, SerializedLexicalNode>;
640
837
 
838
+ /**
839
+ * A serialized representation of a {@link TableNode}.
840
+ */
641
841
  export declare type SerializedTableNode = Spread<{
642
842
  mdastNode: Mdast.Table;
643
843
  }, SerializedLexicalNode>;
644
844
 
645
- export declare interface TableEditorProps {
845
+ /**
846
+ * An extension for the `fromMarkdown` utility markdown parse.
847
+ */
848
+ declare type SyntaxExtension = MarkdownParseOptions['syntaxExtensions'][number];
849
+
850
+ declare interface TableEditorProps {
646
851
  parentEditor: LexicalEditor;
647
852
  lexicalTable: TableNode;
648
853
  mdastNode: Mdast.Table;
649
854
  }
650
855
 
856
+ /**
857
+ * A lexical node that represents a table, with features specific to the markdown tables.
858
+ * Use {@link "$createTableNode"} to construct one.
859
+ */
651
860
  export declare class TableNode extends DecoratorNode<JSX.Element> {
652
861
  __mdastNode: Mdast.Table;
653
862
  focusEmitter: {
@@ -677,8 +886,14 @@ export declare class TableNode extends DecoratorNode<JSX.Element> {
677
886
  isInline(): false;
678
887
  }
679
888
 
889
+ declare type ToMarkdownExtension = NonNullable<ToMarkdownOptions['extensions']>[number];
890
+
680
891
  export { ToMarkdownOptions }
681
892
 
893
+ /**
894
+ * A dictionary with all built-in Toolbar components that can be used within the toolbar.
895
+ * @see To customize the toolbar, pass an array of what you need to the {@link MDXEditorProps.toolbarComponents}.
896
+ */
682
897
  export declare const ToolbarComponents: {
683
898
  BlockTypeSelect: () => React_2.JSX.Element;
684
899
  BoldItalicUnderlineButtons: React_2.FC<{}>;
@@ -712,9 +927,9 @@ export declare type updateFn = (node: LexicalNode) => void;
712
927
  * markdown - plain text markdown edit mode.
713
928
  * diff - side by side comparison with the original markdown (passed as `headMarkdown`).
714
929
  */
715
- export declare type ViewMode = 'editor' | 'markdown' | 'diff';
930
+ declare type ViewMode = 'editor' | 'markdown' | 'diff';
716
931
 
717
- export declare interface VoidEmitter {
932
+ declare interface VoidEmitter {
718
933
  publish: () => void;
719
934
  subscribe: (callback: () => void) => void;
720
935
  }