@mdxeditor/editor 0.4.1 → 0.5.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.
@@ -0,0 +1,3884 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import { LexicalComposer } from "@lexical/react/LexicalComposer";
8
+ import { ContentEditable } from "@lexical/react/LexicalContentEditable";
9
+ import LexicalErrorBoundary from "@lexical/react/LexicalErrorBoundary";
10
+ import { HorizontalRulePlugin } from "@lexical/react/LexicalHorizontalRulePlugin";
11
+ import { LinkPlugin } from "@lexical/react/LexicalLinkPlugin";
12
+ import { ListPlugin } from "@lexical/react/LexicalListPlugin";
13
+ import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
14
+ import { TabIndentationPlugin } from "@lexical/react/LexicalTabIndentationPlugin";
15
+ import classNames from "classnames";
16
+ import { ElementNode, $createParagraphNode, $applyNodeReplacement, DecoratorNode, createEditor, $getRoot, $isRootNode, $isParagraphNode, $isLineBreakNode, $isTextNode, $isElementNode, ParagraphNode, $createTextNode, $getSelection, $isRangeSelection, DEPRECATED_$isGridSelection, FORMAT_TEXT_COMMAND, $isRootOrShadowRoot, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_CRITICAL, BLUR_COMMAND, COMMAND_PRIORITY_LOW, FOCUS_COMMAND, KEY_ESCAPE_COMMAND, KEY_MODIFIER_COMMAND, COMMAND_PRIORITY_HIGH, createCommand, INDENT_CONTENT_COMMAND, $getNodeByKey } from "lexical";
17
+ import * as React from "react";
18
+ import React__default, { createContext, forwardRef, useMemo, useImperativeHandle, createElement, useCallback, useContext, useState, useEffect } from "react";
19
+ import { CodeNode } from "@lexical/code";
20
+ import { $isLinkNode, LinkNode, $createLinkNode, TOGGLE_LINK_COMMAND } from "@lexical/link";
21
+ import { $isListNode, $isListItemNode, ListNode, ListItemNode, $createListNode, $createListItemNode, INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND, REMOVE_LIST_COMMAND, $getListDepth } from "@lexical/list";
22
+ import { $isHorizontalRuleNode, HorizontalRuleNode, $createHorizontalRuleNode, INSERT_HORIZONTAL_RULE_COMMAND } from "@lexical/react/LexicalHorizontalRuleNode";
23
+ import { $isHeadingNode, $isQuoteNode, HeadingNode, QuoteNode, $createHeadingNode, $createQuoteNode } from "@lexical/rich-text";
24
+ import { directiveToMarkdown, directiveFromMarkdown } from "mdast-util-directive";
25
+ import { fromMarkdown } from "mdast-util-from-markdown";
26
+ import { frontmatterToMarkdown, frontmatterFromMarkdown } from "mdast-util-frontmatter";
27
+ import { gfmTableToMarkdown, gfmTableFromMarkdown } from "mdast-util-gfm-table";
28
+ import { mdxToMarkdown, mdxFromMarkdown } from "mdast-util-mdx";
29
+ import { directive } from "micromark-extension-directive";
30
+ import { frontmatter } from "micromark-extension-frontmatter";
31
+ import { gfmTable } from "micromark-extension-gfm-table";
32
+ import { mdxjs } from "micromark-extension-mdxjs";
33
+ import { addClassNamesToElement, $insertNodeToNearestRoot, $findMatchingParent, $getNearestNodeOfType } from "@lexical/utils";
34
+ import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
35
+ import { $setBlocksType, $isAtNodeEnd } from "@lexical/selection";
36
+ import { createEmptyHistoryState, HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
37
+ import { toMarkdown } from "mdast-util-to-markdown";
38
+ import * as RadixPopover from "@radix-ui/react-popover";
39
+ import * as Tooltip from "@radix-ui/react-tooltip";
40
+ import { useCombobox } from "downshift";
41
+ import { CODE, TRANSFORMERS } from "@lexical/markdown";
42
+ import { MarkdownShortcutPlugin } from "@lexical/react/LexicalMarkdownShortcutPlugin";
43
+ import { markdown } from "@codemirror/lang-markdown";
44
+ import { SandpackProvider, CodeEditor } from "@codesandbox/sandpack-react";
45
+ import { parseDiff, Diff, Hunk } from "react-diff-view";
46
+ import { formatLines, diffLines } from "unidiff";
47
+ import * as RadixToolbar from "@radix-ui/react-toolbar";
48
+ import * as Select from "@radix-ui/react-select";
49
+ import * as Dialog from "@radix-ui/react-dialog";
50
+ class AdmonitionNode extends ElementNode {
51
+ constructor(kind, key) {
52
+ super(key);
53
+ __publicField(this, "__kind");
54
+ this.__kind = kind || "note";
55
+ }
56
+ static getType() {
57
+ return "admonition";
58
+ }
59
+ getKind() {
60
+ return this.getLatest().__kind;
61
+ }
62
+ setKind(kind) {
63
+ if (kind !== this.getKind()) {
64
+ this.getWritable().__kind = kind;
65
+ }
66
+ }
67
+ static clone(node) {
68
+ return new AdmonitionNode(node.__kind, node.__key);
69
+ }
70
+ // View
71
+ createDOM(config) {
72
+ const element = document.createElement("div");
73
+ addClassNamesToElement(element, config.theme.admonition[this.__kind]);
74
+ return element;
75
+ }
76
+ updateDOM(_prevNode, _dom) {
77
+ return false;
78
+ }
79
+ // TODO:
80
+ // static importDOM(): DOMConversionMap | null {
81
+ // return {
82
+ // blockquote: (node: Node) => ({
83
+ // conversion: convertBlockquoteElement,
84
+ // priority: 0,
85
+ // }),
86
+ // }
87
+ // }
88
+ static importJSON(serializedNode) {
89
+ const node = $createAdmonitionNode(serializedNode.kind);
90
+ return node;
91
+ }
92
+ exportJSON() {
93
+ return {
94
+ ...super.exportJSON(),
95
+ type: "admonition"
96
+ };
97
+ }
98
+ // Mutation
99
+ insertNewAfter(_, restoreSelection) {
100
+ const newBlock = $createAdmonitionNode();
101
+ this.insertAfter(newBlock, restoreSelection);
102
+ return newBlock;
103
+ }
104
+ collapseAtStart() {
105
+ const paragraph = $createParagraphNode();
106
+ const children = this.getChildren();
107
+ children.forEach((child) => paragraph.append(child));
108
+ this.replace(paragraph);
109
+ return true;
110
+ }
111
+ }
112
+ function $createAdmonitionNode(kind) {
113
+ return $applyNodeReplacement(new AdmonitionNode(kind));
114
+ }
115
+ function $isAdmonitionNode(node) {
116
+ return node instanceof AdmonitionNode;
117
+ }
118
+ function tap(arg, proc) {
119
+ proc(arg);
120
+ return arg;
121
+ }
122
+ function always(value) {
123
+ return () => value;
124
+ }
125
+ function noop() {
126
+ }
127
+ function voidEmitter$1() {
128
+ let subscription = noop;
129
+ return {
130
+ publish: () => {
131
+ subscription();
132
+ },
133
+ subscribe: (cb) => {
134
+ subscription = cb;
135
+ }
136
+ };
137
+ }
138
+ class CodeBlockNode extends DecoratorNode {
139
+ constructor(code2, language, meta, key) {
140
+ super(key);
141
+ __publicField(this, "__code");
142
+ __publicField(this, "__meta");
143
+ __publicField(this, "__language");
144
+ __publicField(this, "__focusEmitter", voidEmitter$1());
145
+ this.__code = code2;
146
+ this.__meta = meta;
147
+ this.__language = language;
148
+ }
149
+ static getType() {
150
+ return "codeblock";
151
+ }
152
+ static clone(node) {
153
+ return new CodeBlockNode(node.__code, node.__language, node.__meta, node.__key);
154
+ }
155
+ static importJSON(serializedNode) {
156
+ const { code: code2, meta, language } = serializedNode;
157
+ return $createCodeBlockNode({
158
+ code: code2,
159
+ language,
160
+ meta
161
+ });
162
+ }
163
+ exportJSON() {
164
+ return {
165
+ code: this.getCode(),
166
+ language: this.getLanguage(),
167
+ meta: this.getMeta(),
168
+ type: "codeblock",
169
+ version: 1
170
+ };
171
+ }
172
+ // View
173
+ createDOM(_config) {
174
+ return document.createElement("div");
175
+ }
176
+ updateDOM() {
177
+ return false;
178
+ }
179
+ getCode() {
180
+ return this.getLatest().__code;
181
+ }
182
+ getMeta() {
183
+ return this.getLatest().__meta;
184
+ }
185
+ getLanguage() {
186
+ return this.getLatest().__language;
187
+ }
188
+ setCode(code2) {
189
+ if (code2 !== this.__code) {
190
+ this.getWritable().__code = code2;
191
+ }
192
+ }
193
+ setMeta(meta) {
194
+ if (meta !== this.__meta) {
195
+ this.getWritable().__meta = meta;
196
+ }
197
+ }
198
+ setLanguage(language) {
199
+ if (language !== this.__language) {
200
+ this.getWritable().__language = language;
201
+ }
202
+ }
203
+ select() {
204
+ this.__focusEmitter.publish();
205
+ }
206
+ decorate(_editor, {
207
+ theme: {
208
+ nodeDecoratorComponents: { CodeBlockEditor }
209
+ }
210
+ }) {
211
+ return /* @__PURE__ */ React__default.createElement(
212
+ CodeBlockEditor,
213
+ {
214
+ nodeKey: this.getKey(),
215
+ code: this.getCode(),
216
+ meta: this.getMeta(),
217
+ language: this.getLanguage(),
218
+ onChange: (code2) => this.setCode(code2),
219
+ focusEmitter: this.__focusEmitter
220
+ }
221
+ );
222
+ }
223
+ }
224
+ function $createCodeBlockNode(options) {
225
+ const { code: code2, language, meta } = options;
226
+ return new CodeBlockNode(code2, language, meta);
227
+ }
228
+ function $isCodeBlockNode(node) {
229
+ return node instanceof CodeBlockNode;
230
+ }
231
+ class FrontmatterNode extends DecoratorNode {
232
+ constructor(code2, key) {
233
+ super(key);
234
+ __publicField(this, "__yaml");
235
+ this.__yaml = code2;
236
+ }
237
+ static getType() {
238
+ return "frontmatter";
239
+ }
240
+ static clone(node) {
241
+ return new FrontmatterNode(node.__yaml, node.__key);
242
+ }
243
+ static importJSON(serializedNode) {
244
+ const { yaml } = serializedNode;
245
+ const node = $createFrontmatterNode(yaml);
246
+ return node;
247
+ }
248
+ exportJSON() {
249
+ return {
250
+ yaml: this.getYaml(),
251
+ type: "frontmatter",
252
+ version: 1
253
+ };
254
+ }
255
+ // View
256
+ createDOM(_config) {
257
+ return document.createElement("div");
258
+ }
259
+ updateDOM() {
260
+ return false;
261
+ }
262
+ getYaml() {
263
+ return this.getLatest().__yaml;
264
+ }
265
+ setYaml(yaml) {
266
+ if (yaml !== this.__yaml) {
267
+ this.getWritable().__yaml = yaml;
268
+ }
269
+ }
270
+ decorate(editor, {
271
+ theme: {
272
+ nodeDecoratorComponents: { FrontmatterEditor }
273
+ }
274
+ }) {
275
+ return /* @__PURE__ */ React__default.createElement(
276
+ FrontmatterEditor,
277
+ {
278
+ yaml: this.getYaml(),
279
+ onChange: (yaml) => editor == null ? void 0 : editor.update(() => {
280
+ this.setYaml(yaml);
281
+ })
282
+ }
283
+ );
284
+ }
285
+ }
286
+ function $createFrontmatterNode(yaml) {
287
+ return new FrontmatterNode(yaml);
288
+ }
289
+ function $isFrontmatterNode(node) {
290
+ return node instanceof FrontmatterNode;
291
+ }
292
+ function convertImageElement(domNode) {
293
+ if (domNode instanceof HTMLImageElement) {
294
+ const { alt: altText, src, title } = domNode;
295
+ const node = $createImageNode({ altText, src, title });
296
+ return { node };
297
+ }
298
+ return null;
299
+ }
300
+ class ImageNode extends DecoratorNode {
301
+ constructor(src, altText, title, key) {
302
+ super(key);
303
+ __publicField(this, "__src");
304
+ __publicField(this, "__altText");
305
+ __publicField(this, "__title");
306
+ this.__src = src;
307
+ this.__title = title;
308
+ this.__altText = altText;
309
+ }
310
+ static getType() {
311
+ return "image";
312
+ }
313
+ static clone(node) {
314
+ return new ImageNode(node.__src, node.__altText, node.__title, node.__key);
315
+ }
316
+ static importJSON(serializedNode) {
317
+ const { altText, title, src } = serializedNode;
318
+ const node = $createImageNode({
319
+ altText,
320
+ title,
321
+ src
322
+ });
323
+ return node;
324
+ }
325
+ exportDOM() {
326
+ const element = document.createElement("img");
327
+ element.setAttribute("src", this.__src);
328
+ element.setAttribute("alt", this.__altText);
329
+ if (this.__title) {
330
+ element.setAttribute("title", this.__title);
331
+ }
332
+ return { element };
333
+ }
334
+ static importDOM() {
335
+ return {
336
+ img: () => ({
337
+ conversion: convertImageElement,
338
+ priority: 0
339
+ })
340
+ };
341
+ }
342
+ exportJSON() {
343
+ return {
344
+ altText: this.getAltText(),
345
+ title: this.getTitle(),
346
+ src: this.getSrc(),
347
+ type: "image",
348
+ version: 1
349
+ };
350
+ }
351
+ createDOM(config) {
352
+ const span = document.createElement("span");
353
+ const theme2 = config.theme;
354
+ const className = theme2.image;
355
+ if (className !== void 0) {
356
+ span.className = className;
357
+ }
358
+ return span;
359
+ }
360
+ updateDOM() {
361
+ return false;
362
+ }
363
+ getSrc() {
364
+ return this.__src;
365
+ }
366
+ getAltText() {
367
+ return this.__altText;
368
+ }
369
+ getTitle() {
370
+ return this.__title;
371
+ }
372
+ setTitle(title) {
373
+ this.getWritable().__title = title;
374
+ }
375
+ decorate() {
376
+ return /* @__PURE__ */ React__default.createElement("img", { title: this.__title, src: this.__src, alt: this.__altText });
377
+ }
378
+ }
379
+ function $createImageNode(options) {
380
+ const { altText, title, src, key } = options;
381
+ return new ImageNode(src, altText, title, key);
382
+ }
383
+ function $isImageNode(node) {
384
+ return node instanceof ImageNode;
385
+ }
386
+ const darkTheme = "_dark-theme_13nbk_1";
387
+ const bold = "_bold_13nbk_10";
388
+ const italic = "_italic_13nbk_14";
389
+ const underline = "_underline_13nbk_18";
390
+ const strikethrough = "_strikethrough_13nbk_34";
391
+ const underlineStrikethrough = "_underlineStrikethrough_13nbk_38";
392
+ const subscript = "_subscript_13nbk_42";
393
+ const superscript = "_superscript_13nbk_47";
394
+ const code = "_code_13nbk_52";
395
+ const nestedListItem$1 = "_nestedListItem_13nbk_59";
396
+ const admonitionDanger = "_admonitionDanger_13nbk_63";
397
+ const admonitionInfo = "_admonitionInfo_13nbk_63";
398
+ const admonitionNote = "_admonitionNote_13nbk_63";
399
+ const admonitionTip = "_admonitionTip_13nbk_63";
400
+ const admonitionCaution = "_admonitionCaution_13nbk_63";
401
+ const styles$1 = {
402
+ darkTheme,
403
+ bold,
404
+ italic,
405
+ underline,
406
+ strikethrough,
407
+ underlineStrikethrough,
408
+ subscript,
409
+ superscript,
410
+ code,
411
+ nestedListItem: nestedListItem$1,
412
+ admonitionDanger,
413
+ admonitionInfo,
414
+ admonitionNote,
415
+ admonitionTip,
416
+ admonitionCaution
417
+ };
418
+ const theme = {
419
+ text: {
420
+ bold: styles$1.bold,
421
+ italic: styles$1.italic,
422
+ underline: styles$1.underline,
423
+ code: styles$1.code,
424
+ strikethrough: styles$1.strikethrough,
425
+ subscript: styles$1.subscript,
426
+ superscript: styles$1.superscript,
427
+ underlineStrikethrough: styles$1.underlineStrikethrough
428
+ },
429
+ list: {
430
+ nested: {
431
+ listitem: styles$1.nestedListItem
432
+ }
433
+ },
434
+ admonition: {
435
+ danger: styles$1.admonitionDanger,
436
+ info: styles$1.admonitionInfo,
437
+ note: styles$1.admonitionNote,
438
+ tip: styles$1.admonitionTip,
439
+ caution: styles$1.admonitionCaution
440
+ }
441
+ };
442
+ const EmptySerializedTextEditorState = {
443
+ type: "root",
444
+ format: "left",
445
+ indent: 0,
446
+ direction: "ltr",
447
+ version: 1,
448
+ children: [
449
+ {
450
+ type: "paragraph",
451
+ version: 1,
452
+ direction: "ltr",
453
+ format: "left",
454
+ indent: 0,
455
+ children: []
456
+ }
457
+ ]
458
+ };
459
+ const EmptySerializedFlowEditorState = {
460
+ type: "root",
461
+ format: "left",
462
+ indent: 0,
463
+ direction: "ltr",
464
+ version: 1,
465
+ children: []
466
+ };
467
+ class JsxNode extends DecoratorNode {
468
+ constructor({ name, kind, attributes, state, updateFn, key }) {
469
+ super(key);
470
+ __publicField(this, "__kind");
471
+ __publicField(this, "__name");
472
+ __publicField(this, "__attributes");
473
+ __publicField(this, "__editor");
474
+ if (!attributes) {
475
+ debugger;
476
+ }
477
+ this.__name = name;
478
+ this.__kind = kind;
479
+ this.__attributes = attributes;
480
+ this.__editor = createEditor();
481
+ if (state) {
482
+ const parsedState = this.__editor.parseEditorState(state);
483
+ if (!parsedState.isEmpty()) {
484
+ this.__editor.setEditorState(parsedState);
485
+ }
486
+ } else if (updateFn) {
487
+ const parsedState = this.__editor.parseEditorState(
488
+ { root: this.getKind() === "text" ? EmptySerializedTextEditorState : EmptySerializedFlowEditorState },
489
+ () => {
490
+ if (this.getKind() === "text") {
491
+ const rootParagraph = $getRoot().getFirstChildOrThrow();
492
+ updateFn(rootParagraph);
493
+ } else {
494
+ updateFn($getRoot());
495
+ }
496
+ }
497
+ );
498
+ if (!parsedState.isEmpty()) {
499
+ this.__editor.setEditorState(parsedState);
500
+ }
501
+ }
502
+ }
503
+ static getType() {
504
+ return "jsx";
505
+ }
506
+ static clone(node) {
507
+ return new JsxNode({
508
+ name: node.__name,
509
+ kind: node.__kind,
510
+ attributes: node.__attributes,
511
+ state: node.__editor.getEditorState().toJSON()
512
+ });
513
+ }
514
+ static importJSON(serializedNode) {
515
+ const { name, kind, attributes, state } = serializedNode;
516
+ return $createJsxNode({
517
+ kind,
518
+ name,
519
+ attributes,
520
+ state
521
+ });
522
+ }
523
+ exportJSON() {
524
+ return {
525
+ name: this.getName(),
526
+ kind: this.getKind(),
527
+ attributes: this.getAttributes(),
528
+ state: this.__editor.getEditorState().toJSON(),
529
+ type: "jsx",
530
+ version: 1
531
+ };
532
+ }
533
+ inNestedEditor(callback) {
534
+ this.__editor.getEditorState().read(callback);
535
+ }
536
+ getChildren() {
537
+ if (this.getKey() === "flow") {
538
+ return $getRoot().getChildren() || [];
539
+ } else {
540
+ const firstChild = $getRoot().getFirstChild();
541
+ if (!firstChild) {
542
+ return [];
543
+ }
544
+ return firstChild.getChildren() || [];
545
+ }
546
+ }
547
+ createDOM() {
548
+ if (this.getKey() === "flow") {
549
+ return document.createElement("div");
550
+ } else {
551
+ return document.createElement("span");
552
+ }
553
+ }
554
+ updateDOM() {
555
+ return false;
556
+ }
557
+ getName() {
558
+ return this.__name;
559
+ }
560
+ getKind() {
561
+ return this.__kind;
562
+ }
563
+ getAttributes() {
564
+ return this.__attributes;
565
+ }
566
+ updateAttributes(attributeValues) {
567
+ this.getWritable().__attributes = Object.entries(attributeValues).map(([name, value]) => {
568
+ return { name, value };
569
+ });
570
+ }
571
+ decorate(_parentEditor, {
572
+ theme: {
573
+ nodeDecoratorComponents: { JsxEditor }
574
+ }
575
+ }) {
576
+ return /* @__PURE__ */ React__default.createElement(
577
+ JsxEditor,
578
+ {
579
+ attributes: this.getAttributes(),
580
+ componentName: this.getName(),
581
+ kind: this.getKind(),
582
+ editor: this.__editor,
583
+ onSubmit: (attributeValues) => this.updateAttributes(attributeValues),
584
+ theme
585
+ }
586
+ );
587
+ }
588
+ }
589
+ function $createJsxNode(options) {
590
+ return new JsxNode(options);
591
+ }
592
+ function $isJsxNode(node) {
593
+ return node instanceof JsxNode;
594
+ }
595
+ function voidEmitter() {
596
+ let subscription = noop;
597
+ return {
598
+ publish: () => {
599
+ subscription();
600
+ },
601
+ subscribe: (cb) => {
602
+ subscription = cb;
603
+ }
604
+ };
605
+ }
606
+ class SandpackNode extends DecoratorNode {
607
+ constructor(code2, language, meta, key) {
608
+ super(key);
609
+ __publicField(this, "__code");
610
+ __publicField(this, "__meta");
611
+ __publicField(this, "__language");
612
+ __publicField(this, "__focusEmitter", voidEmitter());
613
+ this.__code = code2;
614
+ this.__meta = meta;
615
+ this.__language = language;
616
+ }
617
+ static getType() {
618
+ return "sandpack";
619
+ }
620
+ static clone(node) {
621
+ return new SandpackNode(node.__code, node.__language, node.__meta, node.__key);
622
+ }
623
+ static importJSON(serializedNode) {
624
+ const { code: code2, meta, language } = serializedNode;
625
+ return $createSandpackNode({
626
+ code: code2,
627
+ language,
628
+ meta
629
+ });
630
+ }
631
+ exportJSON() {
632
+ return {
633
+ code: this.getCode(),
634
+ language: this.getLanguage(),
635
+ meta: this.getMeta(),
636
+ type: "sandpack",
637
+ version: 1
638
+ };
639
+ }
640
+ // View
641
+ createDOM(_config) {
642
+ return document.createElement("div");
643
+ }
644
+ updateDOM() {
645
+ return false;
646
+ }
647
+ getCode() {
648
+ return this.getLatest().__code;
649
+ }
650
+ getMeta() {
651
+ return this.getLatest().__meta;
652
+ }
653
+ getLanguage() {
654
+ return this.getLatest().__language;
655
+ }
656
+ setCode(code2) {
657
+ if (code2 !== this.__code) {
658
+ this.getWritable().__code = code2;
659
+ }
660
+ }
661
+ setMeta(meta) {
662
+ if (meta !== this.__meta) {
663
+ this.getWritable().__meta = meta;
664
+ }
665
+ }
666
+ setLanguage(language) {
667
+ if (language !== this.__language) {
668
+ this.getWritable().__language = language;
669
+ }
670
+ }
671
+ select() {
672
+ this.__focusEmitter.publish();
673
+ }
674
+ decorate(_parentEditor, {
675
+ theme: {
676
+ nodeDecoratorComponents: { SandpackEditor }
677
+ }
678
+ }) {
679
+ return /* @__PURE__ */ React__default.createElement(
680
+ SandpackEditor,
681
+ {
682
+ nodeKey: this.getKey(),
683
+ code: this.getCode(),
684
+ meta: this.getMeta(),
685
+ onChange: (code2) => this.setCode(code2),
686
+ focusEmitter: this.__focusEmitter
687
+ }
688
+ );
689
+ }
690
+ }
691
+ function $createSandpackNode(options) {
692
+ const { code: code2, language, meta } = options;
693
+ return new SandpackNode(code2, language, meta);
694
+ }
695
+ function $isSandpackNode(node) {
696
+ return node instanceof SandpackNode;
697
+ }
698
+ const EMPTY_CELL = { type: "tableCell", children: [] };
699
+ function coordinatesEmitter() {
700
+ let subscription = noop;
701
+ return {
702
+ publish: (coords) => {
703
+ subscription(coords);
704
+ },
705
+ subscribe: (cb) => {
706
+ subscription = cb;
707
+ }
708
+ };
709
+ }
710
+ class TableNode extends DecoratorNode {
711
+ constructor(mdastNode, key) {
712
+ super(key);
713
+ __publicField(this, "__mdastNode");
714
+ __publicField(this, "focusEmitter", coordinatesEmitter());
715
+ this.__mdastNode = mdastNode || { type: "table", children: [] };
716
+ }
717
+ static getType() {
718
+ return "table";
719
+ }
720
+ static clone(node) {
721
+ return new TableNode(structuredClone(node.__mdastNode), node.__key);
722
+ }
723
+ static importJSON(serializedNode) {
724
+ return $createTableNode(serializedNode.mdastNode);
725
+ }
726
+ exportJSON() {
727
+ return {
728
+ mdastNode: structuredClone(this.__mdastNode),
729
+ type: "table",
730
+ version: 1
731
+ };
732
+ }
733
+ getMdastNode() {
734
+ return this.__mdastNode;
735
+ }
736
+ getRowCount() {
737
+ return this.__mdastNode.children.length;
738
+ }
739
+ getColCount() {
740
+ var _a;
741
+ return ((_a = this.__mdastNode.children[0]) == null ? void 0 : _a.children.length) || 0;
742
+ }
743
+ createDOM() {
744
+ return document.createElement("div");
745
+ }
746
+ updateDOM() {
747
+ return false;
748
+ }
749
+ updateCellContents(colIndex, rowIndex, children) {
750
+ const self = this.getWritable();
751
+ const table = self.__mdastNode;
752
+ const row = table.children[rowIndex];
753
+ const cells = row.children;
754
+ const cell = cells[colIndex];
755
+ const cellsClone = Array.from(cells);
756
+ const cellClone = { ...cell, children };
757
+ const rowClone = { ...row, children: cellsClone };
758
+ cellsClone[colIndex] = cellClone;
759
+ table.children[rowIndex] = rowClone;
760
+ }
761
+ insertColumnAt(colIndex) {
762
+ const self = this.getWritable();
763
+ const table = self.__mdastNode;
764
+ for (let rowIndex = 0; rowIndex < table.children.length; rowIndex++) {
765
+ const row = table.children[rowIndex];
766
+ const cells = row.children;
767
+ const cellsClone = Array.from(cells);
768
+ const rowClone = { ...row, children: cellsClone };
769
+ cellsClone.splice(colIndex, 0, structuredClone(EMPTY_CELL));
770
+ table.children[rowIndex] = rowClone;
771
+ }
772
+ if (table.align && table.align.length > 0) {
773
+ table.align.splice(colIndex, 0, "left");
774
+ }
775
+ }
776
+ deleteColumnAt(colIndex) {
777
+ const self = this.getWritable();
778
+ const table = self.__mdastNode;
779
+ for (let rowIndex = 0; rowIndex < table.children.length; rowIndex++) {
780
+ const row = table.children[rowIndex];
781
+ const cells = row.children;
782
+ const cellsClone = Array.from(cells);
783
+ const rowClone = { ...row, children: cellsClone };
784
+ cellsClone.splice(colIndex, 1);
785
+ table.children[rowIndex] = rowClone;
786
+ }
787
+ }
788
+ insertRowAt(y) {
789
+ const self = this.getWritable();
790
+ const table = self.__mdastNode;
791
+ const newRow = {
792
+ type: "tableRow",
793
+ children: Array.from({ length: this.getColCount() }, () => structuredClone(EMPTY_CELL))
794
+ };
795
+ table.children.splice(y, 0, newRow);
796
+ }
797
+ deleteRowAt(rowIndex) {
798
+ this.getWritable().__mdastNode.children.splice(rowIndex, 1);
799
+ }
800
+ addRowToBottom() {
801
+ this.insertRowAt(this.getRowCount());
802
+ }
803
+ addColumnToRight() {
804
+ this.insertColumnAt(this.getColCount());
805
+ }
806
+ setColumnAlign(colIndex, align) {
807
+ const self = this.getWritable();
808
+ const table = self.__mdastNode;
809
+ if (table.align == null) {
810
+ table.align = [];
811
+ }
812
+ table.align[colIndex] = align;
813
+ }
814
+ decorate(parentEditor, {
815
+ theme: {
816
+ nodeDecoratorComponents: { TableEditor }
817
+ }
818
+ }) {
819
+ return /* @__PURE__ */ React__default.createElement(TableEditor, { lexicalTable: this, mdastNode: this.__mdastNode, parentEditor });
820
+ }
821
+ select(coords) {
822
+ this.focusEmitter.publish(coords);
823
+ }
824
+ isInline() {
825
+ return false;
826
+ }
827
+ }
828
+ function $isTableNode(node) {
829
+ return node instanceof TableNode;
830
+ }
831
+ function $createTableNode(mdastNode) {
832
+ return new TableNode(mdastNode);
833
+ }
834
+ const IS_BOLD = 1;
835
+ const IS_ITALIC = 2;
836
+ const IS_UNDERLINE = 8;
837
+ const IS_CODE = 16;
838
+ const LexicalRootVisitor = {
839
+ testLexicalNode: $isRootNode,
840
+ visitLexicalNode: ({ actions }) => {
841
+ actions.addAndStepInto("root");
842
+ }
843
+ };
844
+ const LexicalParagraphVisitor = {
845
+ testLexicalNode: $isParagraphNode,
846
+ visitLexicalNode: ({ actions }) => {
847
+ actions.addAndStepInto("paragraph");
848
+ }
849
+ };
850
+ const LexicalFrontmatterVisitor = {
851
+ testLexicalNode: $isFrontmatterNode,
852
+ visitLexicalNode: ({ actions, lexicalNode }) => {
853
+ actions.addAndStepInto("yaml", { value: lexicalNode.getYaml() });
854
+ }
855
+ };
856
+ const LexicalLinkVisitor = {
857
+ testLexicalNode: $isLinkNode,
858
+ visitLexicalNode: ({ lexicalNode, actions }) => {
859
+ actions.addAndStepInto("link", { url: lexicalNode.getURL(), title: lexicalNode.getTitle() });
860
+ }
861
+ };
862
+ const LexicalHeadingVisitor = {
863
+ testLexicalNode: $isHeadingNode,
864
+ visitLexicalNode: ({ lexicalNode, actions }) => {
865
+ const depth = parseInt(lexicalNode.getTag()[1], 10);
866
+ actions.addAndStepInto("heading", { depth });
867
+ }
868
+ };
869
+ const LexicalListVisitor = {
870
+ testLexicalNode: $isListNode,
871
+ visitLexicalNode: ({ lexicalNode, actions }) => {
872
+ actions.addAndStepInto("list", {
873
+ ordered: lexicalNode.getListType() === "number",
874
+ //TODO: figure out when spread can be true
875
+ spread: false
876
+ });
877
+ }
878
+ };
879
+ const LexicalListItemVisitor = {
880
+ testLexicalNode: $isListItemNode,
881
+ visitLexicalNode: ({ lexicalNode, mdastParent, actions }) => {
882
+ const children = lexicalNode.getChildren();
883
+ const firstChild = children[0];
884
+ if (children.length === 1 && $isListNode(firstChild)) {
885
+ const prevListItemNode = mdastParent.children.at(-1);
886
+ actions.visitChildren(lexicalNode, prevListItemNode);
887
+ } else {
888
+ const listItem = actions.appendToParent(mdastParent, {
889
+ type: "listItem",
890
+ spread: false,
891
+ children: [{ type: "paragraph", children: [] }]
892
+ });
893
+ actions.visitChildren(lexicalNode, listItem.children[0]);
894
+ }
895
+ }
896
+ };
897
+ const LexicalQuoteVisitor = {
898
+ testLexicalNode: $isQuoteNode,
899
+ visitLexicalNode: ({ lexicalNode, mdastParent, actions }) => {
900
+ const blockquote = actions.appendToParent(mdastParent, {
901
+ type: "blockquote",
902
+ children: [{ type: "paragraph", children: [] }]
903
+ });
904
+ actions.visitChildren(lexicalNode, blockquote.children[0]);
905
+ }
906
+ };
907
+ const AdmonitionVisitor = {
908
+ testLexicalNode: $isAdmonitionNode,
909
+ visitLexicalNode: ({ mdastParent, lexicalNode, actions }) => {
910
+ const admonition = actions.appendToParent(mdastParent, {
911
+ type: "containerDirective",
912
+ name: lexicalNode.getKind(),
913
+ children: [{ type: "paragraph", children: [] }]
914
+ });
915
+ actions.visitChildren(lexicalNode, admonition.children[0]);
916
+ }
917
+ };
918
+ const SandpackNodeVisitor = {
919
+ testLexicalNode: $isSandpackNode,
920
+ visitLexicalNode: ({ lexicalNode, actions }) => {
921
+ actions.addAndStepInto("code", {
922
+ value: lexicalNode.getCode(),
923
+ lang: lexicalNode.getLanguage(),
924
+ meta: lexicalNode.getMeta()
925
+ });
926
+ }
927
+ };
928
+ const CodeBlockVisitor = {
929
+ testLexicalNode: $isCodeBlockNode,
930
+ visitLexicalNode: ({ lexicalNode, actions }) => {
931
+ actions.addAndStepInto("code", {
932
+ value: lexicalNode.getCode(),
933
+ lang: lexicalNode.getLanguage(),
934
+ meta: lexicalNode.getMeta()
935
+ });
936
+ }
937
+ };
938
+ function isMdastText(mdastNode) {
939
+ return mdastNode.type === "text";
940
+ }
941
+ const LexicalLinebreakVisitor = {
942
+ testLexicalNode: $isLineBreakNode,
943
+ visitLexicalNode: ({ mdastParent, actions }) => {
944
+ actions.appendToParent(mdastParent, { type: "text", value: "\n" });
945
+ }
946
+ };
947
+ const LexicalTextVisitor = {
948
+ shouldJoin: (prevNode, currentNode) => {
949
+ return ["text", "emphasis", "strong", "mdxJsxTextElement"].includes(prevNode.type) && prevNode.type === currentNode.type;
950
+ },
951
+ join(prevNode, currentNode) {
952
+ if (isMdastText(prevNode) && isMdastText(currentNode)) {
953
+ return {
954
+ type: "text",
955
+ value: prevNode.value + currentNode.value
956
+ };
957
+ } else {
958
+ return {
959
+ ...prevNode,
960
+ children: [...prevNode.children, ...currentNode.children]
961
+ };
962
+ }
963
+ },
964
+ testLexicalNode: $isTextNode,
965
+ visitLexicalNode: ({ lexicalNode, mdastParent, actions }) => {
966
+ const previousSibling = lexicalNode.getPreviousSibling();
967
+ const prevFormat = $isTextNode(previousSibling) ? previousSibling.getFormat() : 0;
968
+ const textContent = lexicalNode.getTextContent();
969
+ const format = lexicalNode.getFormat() ?? 0;
970
+ if (format & IS_CODE) {
971
+ actions.addAndStepInto("inlineCode", {
972
+ value: textContent
973
+ });
974
+ return;
975
+ }
976
+ let localParentNode = mdastParent;
977
+ if (prevFormat & format & IS_ITALIC) {
978
+ localParentNode = actions.appendToParent(localParentNode, {
979
+ type: "emphasis",
980
+ children: []
981
+ });
982
+ }
983
+ if (prevFormat & format & IS_BOLD) {
984
+ localParentNode = actions.appendToParent(localParentNode, {
985
+ type: "strong",
986
+ children: []
987
+ });
988
+ }
989
+ if (prevFormat & format & IS_UNDERLINE) {
990
+ localParentNode = actions.appendToParent(localParentNode, {
991
+ type: "mdxJsxTextElement",
992
+ name: "u",
993
+ children: [],
994
+ attributes: []
995
+ });
996
+ }
997
+ if (format & IS_ITALIC && !(prevFormat & IS_ITALIC)) {
998
+ localParentNode = actions.appendToParent(localParentNode, {
999
+ type: "emphasis",
1000
+ children: []
1001
+ });
1002
+ }
1003
+ if (format & IS_BOLD && !(prevFormat & IS_BOLD)) {
1004
+ localParentNode = actions.appendToParent(localParentNode, {
1005
+ type: "strong",
1006
+ children: []
1007
+ });
1008
+ }
1009
+ if (format & IS_UNDERLINE && !(prevFormat & IS_UNDERLINE)) {
1010
+ localParentNode = actions.appendToParent(localParentNode, {
1011
+ type: "mdxJsxTextElement",
1012
+ name: "u",
1013
+ children: [],
1014
+ attributes: []
1015
+ });
1016
+ }
1017
+ actions.appendToParent(localParentNode, {
1018
+ type: "text",
1019
+ value: textContent
1020
+ });
1021
+ }
1022
+ };
1023
+ const LexicalThematicBreakVisitor = {
1024
+ testLexicalNode: $isHorizontalRuleNode,
1025
+ visitLexicalNode({ actions }) {
1026
+ actions.addAndStepInto("thematicBreak");
1027
+ }
1028
+ };
1029
+ const LexicalImageVisitor = {
1030
+ testLexicalNode: $isImageNode,
1031
+ visitLexicalNode({ lexicalNode, actions }) {
1032
+ actions.addAndStepInto("image", {
1033
+ url: lexicalNode.getSrc(),
1034
+ alt: lexicalNode.getAltText(),
1035
+ title: lexicalNode.getTitle()
1036
+ });
1037
+ }
1038
+ };
1039
+ const LexicalTableVisitor = {
1040
+ testLexicalNode: $isTableNode,
1041
+ visitLexicalNode({ actions, mdastParent, lexicalNode }) {
1042
+ actions.appendToParent(mdastParent, lexicalNode.getMdastNode());
1043
+ }
1044
+ };
1045
+ const JsxVisitor = {
1046
+ testLexicalNode: $isJsxNode,
1047
+ visitLexicalNode({ mdastParent, lexicalNode, actions }) {
1048
+ const nodeType = lexicalNode.getKind() === "text" ? "mdxJsxTextElement" : "mdxJsxFlowElement";
1049
+ actions.registerReferredComponent(lexicalNode.getName());
1050
+ const node = {
1051
+ type: nodeType,
1052
+ name: lexicalNode.getName(),
1053
+ attributes: lexicalNode.getAttributes(),
1054
+ children: []
1055
+ };
1056
+ actions.appendToParent(mdastParent, node);
1057
+ lexicalNode.inNestedEditor(() => {
1058
+ actions.visitChildren(lexicalNode, node);
1059
+ });
1060
+ }
1061
+ };
1062
+ const defaultLexicalVisitors = {
1063
+ LexicalRootVisitor,
1064
+ LexicalParagraphVisitor,
1065
+ LexicalFrontmatterVisitor,
1066
+ LexicalTextVisitor,
1067
+ LexicalLinebreakVisitor,
1068
+ LexicalLinkVisitor,
1069
+ LexicalHeadingVisitor,
1070
+ LexicalListVisitor,
1071
+ LexicalListItemVisitor,
1072
+ LexicalQuoteVisitor,
1073
+ SandpackNodeVisitor,
1074
+ CodeBlockVisitor,
1075
+ LexicalThematicBreakVisitor,
1076
+ AdmonitionVisitor,
1077
+ LexicalImageVisitor,
1078
+ JsxVisitor,
1079
+ LexicalTableVisitor
1080
+ };
1081
+ function isParent$1(node) {
1082
+ return node.children instanceof Array;
1083
+ }
1084
+ function exportLexicalTreeToMdast({ root, visitors, jsxComponentDescriptors }) {
1085
+ let unistRoot = null;
1086
+ const referredComponents = /* @__PURE__ */ new Set();
1087
+ visit(root, null);
1088
+ function registerReferredComponent(componentName) {
1089
+ referredComponents.add(componentName);
1090
+ }
1091
+ function appendToParent(parentNode, node) {
1092
+ if (unistRoot === null) {
1093
+ unistRoot = node;
1094
+ return unistRoot;
1095
+ }
1096
+ if (!isParent$1(parentNode)) {
1097
+ throw new Error("Attempting to append children to a non-parent");
1098
+ }
1099
+ const siblings = parentNode.children;
1100
+ const prevSibling = siblings.at(-1);
1101
+ if (prevSibling) {
1102
+ const joinVisitor = visitors.find((visitor) => {
1103
+ var _a;
1104
+ return (_a = visitor.shouldJoin) == null ? void 0 : _a.call(visitor, prevSibling, node);
1105
+ });
1106
+ if (joinVisitor) {
1107
+ const joinedNode = joinVisitor.join(prevSibling, node);
1108
+ siblings.splice(siblings.length - 1, 1, joinedNode);
1109
+ return joinedNode;
1110
+ }
1111
+ }
1112
+ siblings.push(node);
1113
+ return node;
1114
+ }
1115
+ function visitChildren(lexicalNode, parentNode) {
1116
+ lexicalNode.getChildren().forEach((lexicalChild) => {
1117
+ visit(lexicalChild, parentNode);
1118
+ });
1119
+ }
1120
+ function visit(lexicalNode, mdastParent) {
1121
+ var _a;
1122
+ const visitor = visitors.find((visitor2) => {
1123
+ var _a2;
1124
+ return (_a2 = visitor2.testLexicalNode) == null ? void 0 : _a2.call(visitor2, lexicalNode);
1125
+ });
1126
+ if (!visitor) {
1127
+ throw new Error(`no lexical visitor found for ${lexicalNode.getType()}`, {
1128
+ cause: lexicalNode
1129
+ });
1130
+ }
1131
+ (_a = visitor.visitLexicalNode) == null ? void 0 : _a.call(visitor, {
1132
+ lexicalNode,
1133
+ mdastParent,
1134
+ actions: {
1135
+ addAndStepInto(type, props = {}, hasChildren = true) {
1136
+ const newNode = {
1137
+ type,
1138
+ ...props,
1139
+ ...hasChildren ? { children: [] } : {}
1140
+ };
1141
+ appendToParent(mdastParent, newNode);
1142
+ if ($isElementNode(lexicalNode) && hasChildren) {
1143
+ visitChildren(lexicalNode, newNode);
1144
+ }
1145
+ },
1146
+ appendToParent,
1147
+ visitChildren,
1148
+ registerReferredComponent
1149
+ }
1150
+ });
1151
+ }
1152
+ if (unistRoot === null) {
1153
+ throw new Error("traversal ended with no root element");
1154
+ }
1155
+ const importsMap = /* @__PURE__ */ new Map();
1156
+ const defaultImportsMap = /* @__PURE__ */ new Map();
1157
+ for (const componentName of referredComponents) {
1158
+ const descriptor = jsxComponentDescriptors.find((descriptor2) => descriptor2.name === componentName);
1159
+ if (!descriptor) {
1160
+ throw new Error(`Component ${componentName} is used but not imported`);
1161
+ }
1162
+ if (descriptor.defaultExport) {
1163
+ defaultImportsMap.set(componentName, descriptor.source);
1164
+ } else {
1165
+ const { source } = descriptor;
1166
+ const existing = importsMap.get(source);
1167
+ if (existing) {
1168
+ existing.push(componentName);
1169
+ } else {
1170
+ importsMap.set(source, [componentName]);
1171
+ }
1172
+ }
1173
+ }
1174
+ const imports = Array.from(importsMap).map(([source, componentNames]) => {
1175
+ return {
1176
+ type: "mdxjsEsm",
1177
+ value: `import { ${componentNames.join(", ")} } from '${source}'`
1178
+ };
1179
+ });
1180
+ imports.push(
1181
+ ...Array.from(defaultImportsMap).map(([componentName, source]) => {
1182
+ return {
1183
+ type: "mdxjsEsm",
1184
+ value: `import ${componentName} from '${source}'`
1185
+ };
1186
+ })
1187
+ );
1188
+ const typedRoot = unistRoot;
1189
+ const frontmatter2 = typedRoot.children.find((child) => child.type === "yaml");
1190
+ if (frontmatter2) {
1191
+ typedRoot.children.splice(typedRoot.children.indexOf(frontmatter2) + 1, 0, ...imports);
1192
+ } else {
1193
+ typedRoot.children.unshift(...imports);
1194
+ }
1195
+ fixWrappingWhitespace(typedRoot, []);
1196
+ return typedRoot;
1197
+ }
1198
+ const TRAILING_WHITESPACE_REGEXP = /\s+$/;
1199
+ const LEADING_WHITESPACE_REGEXP = /^\s+/;
1200
+ function fixWrappingWhitespace(node, parentChain) {
1201
+ if (node.type === "strong" || node.type === "emphasis") {
1202
+ const lastChild = node.children.at(-1);
1203
+ if ((lastChild == null ? void 0 : lastChild.type) === "text") {
1204
+ const trailingWhitespace = lastChild.value.match(TRAILING_WHITESPACE_REGEXP);
1205
+ if (trailingWhitespace) {
1206
+ lastChild.value = lastChild.value.replace(TRAILING_WHITESPACE_REGEXP, "");
1207
+ const parent = parentChain.at(-1);
1208
+ if (parent) {
1209
+ parent.children.splice(parent.children.indexOf(node) + 1, 0, {
1210
+ type: "text",
1211
+ value: trailingWhitespace[0]
1212
+ });
1213
+ fixWrappingWhitespace(parent, parentChain.slice(0, -1));
1214
+ }
1215
+ }
1216
+ }
1217
+ const firstChild = node.children.at(0);
1218
+ if ((firstChild == null ? void 0 : firstChild.type) === "text") {
1219
+ const leadingWhitespace = firstChild.value.match(LEADING_WHITESPACE_REGEXP);
1220
+ if (leadingWhitespace) {
1221
+ firstChild.value = firstChild.value.replace(LEADING_WHITESPACE_REGEXP, "");
1222
+ const parent = parentChain.at(-1);
1223
+ if (parent) {
1224
+ parent.children.splice(parent.children.indexOf(node), 0, {
1225
+ type: "text",
1226
+ value: leadingWhitespace[0]
1227
+ });
1228
+ fixWrappingWhitespace(parent, parentChain.slice(0, -1));
1229
+ }
1230
+ }
1231
+ }
1232
+ }
1233
+ if (Object.hasOwn(node, "children")) {
1234
+ const nodeAsParent = node;
1235
+ nodeAsParent.children.forEach((child) => fixWrappingWhitespace(child, [...parentChain, nodeAsParent]));
1236
+ }
1237
+ }
1238
+ const defaultExtensions = {
1239
+ mdxToMarkdown: mdxToMarkdown(),
1240
+ frontmatterToMarkdown: frontmatterToMarkdown("yaml"),
1241
+ directiveToMarkdown,
1242
+ gfmTableToMarkdown: gfmTableToMarkdown({ tableCellPadding: true, tablePipeAlign: true })
1243
+ };
1244
+ const defaultToMarkdownOptions = {
1245
+ listItemIndent: "one"
1246
+ };
1247
+ function exportMarkdownFromLexical({
1248
+ root,
1249
+ toMarkdownOptions,
1250
+ toMarkdownExtensions,
1251
+ visitors,
1252
+ jsxComponentDescriptors
1253
+ }) {
1254
+ return toMarkdown(exportLexicalTreeToMdast({ root, visitors, jsxComponentDescriptors }), {
1255
+ extensions: toMarkdownExtensions,
1256
+ ...toMarkdownOptions
1257
+ });
1258
+ }
1259
+ const MdastRootVisitor = {
1260
+ testNode: "root",
1261
+ visitNode({ actions, mdastNode, lexicalParent }) {
1262
+ actions.visitChildren(mdastNode, lexicalParent);
1263
+ }
1264
+ };
1265
+ const MdastParagraphVisitor = {
1266
+ testNode: "paragraph",
1267
+ visitNode: function({ mdastNode, lexicalParent, actions }) {
1268
+ if ($isListItemNode(lexicalParent) || $isQuoteNode(lexicalParent) || $isAdmonitionNode(lexicalParent)) {
1269
+ actions.visitChildren(mdastNode, lexicalParent);
1270
+ } else {
1271
+ actions.addAndStepInto($createParagraphNode());
1272
+ }
1273
+ }
1274
+ };
1275
+ const MdastLinkVisitor = {
1276
+ testNode: "link",
1277
+ visitNode({ mdastNode, actions }) {
1278
+ actions.addAndStepInto(
1279
+ $createLinkNode(mdastNode.url, {
1280
+ title: mdastNode.title
1281
+ })
1282
+ );
1283
+ }
1284
+ };
1285
+ const MdastAdmonitionVisitor = {
1286
+ testNode: "containerDirective",
1287
+ visitNode({ mdastNode, actions }) {
1288
+ actions.addAndStepInto($createAdmonitionNode(mdastNode.name));
1289
+ }
1290
+ };
1291
+ const MdastHeadingVisitor = {
1292
+ testNode: "heading",
1293
+ visitNode: function({ mdastNode, actions }) {
1294
+ actions.addAndStepInto($createHeadingNode(`h${mdastNode.depth}`));
1295
+ }
1296
+ };
1297
+ const MdastListVisitor = {
1298
+ testNode: "list",
1299
+ visitNode: function({ mdastNode, lexicalParent, actions }) {
1300
+ const lexicalNode = $createListNode(mdastNode.ordered ? "number" : "bullet");
1301
+ if ($isListItemNode(lexicalParent)) {
1302
+ const dedicatedParent = $createListItemNode();
1303
+ dedicatedParent.append(lexicalNode);
1304
+ lexicalParent.insertAfter(dedicatedParent);
1305
+ } else {
1306
+ lexicalParent.append(lexicalNode);
1307
+ }
1308
+ actions.visitChildren(mdastNode, lexicalNode);
1309
+ }
1310
+ };
1311
+ const MdastListItemVisitor = {
1312
+ testNode: "listItem",
1313
+ visitNode({ actions }) {
1314
+ actions.addAndStepInto($createListItemNode());
1315
+ }
1316
+ };
1317
+ const MdastBlockQuoteVisitor = {
1318
+ testNode: "blockquote",
1319
+ visitNode({ actions }) {
1320
+ actions.addAndStepInto($createQuoteNode());
1321
+ }
1322
+ };
1323
+ const MdastTableVisitor = {
1324
+ testNode: "table",
1325
+ visitNode({ mdastNode, lexicalParent }) {
1326
+ lexicalParent.append($createTableNode(mdastNode));
1327
+ }
1328
+ };
1329
+ const MdastFormattingVisitor = {
1330
+ testNode(mdastNode) {
1331
+ return mdastNode.type === "emphasis" || mdastNode.type === "strong" || mdastNode.type === "mdxJsxTextElement" && (mdastNode == null ? void 0 : mdastNode.name) === "u";
1332
+ },
1333
+ visitNode({ mdastNode, lexicalParent, actions }) {
1334
+ if (mdastNode.type === "emphasis") {
1335
+ actions.addFormatting(IS_ITALIC);
1336
+ } else if (mdastNode.type === "strong") {
1337
+ actions.addFormatting(IS_BOLD);
1338
+ } else if (mdastNode.type === "mdxJsxTextElement" && mdastNode.name === "u") {
1339
+ actions.addFormatting(IS_UNDERLINE);
1340
+ }
1341
+ actions.visitChildren(mdastNode, lexicalParent);
1342
+ }
1343
+ };
1344
+ const MdastInlineCodeVisitor = {
1345
+ testNode: "inlineCode",
1346
+ visitNode({ mdastNode, actions }) {
1347
+ actions.addAndStepInto($createTextNode(mdastNode.value).setFormat(IS_CODE));
1348
+ }
1349
+ };
1350
+ const MdastCodeVisitor = {
1351
+ testNode: "code",
1352
+ visitNode({ mdastNode, actions }) {
1353
+ var _a;
1354
+ const constructor = ((_a = mdastNode.meta) == null ? void 0 : _a.startsWith("live")) ? $createSandpackNode : $createCodeBlockNode;
1355
+ actions.addAndStepInto(
1356
+ constructor({
1357
+ code: mdastNode.value,
1358
+ language: mdastNode.lang,
1359
+ meta: mdastNode.meta
1360
+ })
1361
+ );
1362
+ }
1363
+ };
1364
+ const MdastTextVisitor = {
1365
+ testNode: "text",
1366
+ visitNode({ mdastNode, actions }) {
1367
+ actions.addAndStepInto($createTextNode(mdastNode.value).setFormat(actions.getParentFormatting()));
1368
+ }
1369
+ };
1370
+ const MdastThematicBreakVisitor = {
1371
+ testNode: "thematicBreak",
1372
+ visitNode({ actions }) {
1373
+ actions.addAndStepInto($createHorizontalRuleNode());
1374
+ }
1375
+ };
1376
+ const MdastImageVisitor = {
1377
+ testNode: "image",
1378
+ visitNode({ mdastNode, actions }) {
1379
+ actions.addAndStepInto(
1380
+ $createImageNode({
1381
+ src: mdastNode.url,
1382
+ altText: mdastNode.alt || "",
1383
+ title: mdastNode.title || ""
1384
+ })
1385
+ );
1386
+ }
1387
+ };
1388
+ const MdastFrontmatterVisitor = {
1389
+ testNode: "yaml",
1390
+ visitNode({ mdastNode, actions }) {
1391
+ actions.addAndStepInto($createFrontmatterNode(mdastNode.value));
1392
+ }
1393
+ };
1394
+ const MdastMdxJsEsmVisitor = {
1395
+ testNode: "mdxjsEsm",
1396
+ visitNode() {
1397
+ }
1398
+ };
1399
+ const MdastMdxJsxElementVisitor = {
1400
+ testNode: (node) => {
1401
+ return node.type === "mdxJsxTextElement" || node.type === "mdxJsxFlowElement";
1402
+ },
1403
+ visitNode({ lexicalParent, mdastNode, actions }) {
1404
+ lexicalParent.append(
1405
+ $createJsxNode({
1406
+ name: mdastNode.name,
1407
+ kind: mdastNode.type === "mdxJsxTextElement" ? "text" : "flow",
1408
+ //TODO: expressions are not supported yet
1409
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
1410
+ attributes: mdastNode.attributes,
1411
+ updateFn: (lexicalParent2) => {
1412
+ actions.visitChildren(mdastNode, lexicalParent2);
1413
+ }
1414
+ })
1415
+ );
1416
+ }
1417
+ };
1418
+ const defaultMdastVisitors = {
1419
+ MdastRootVisitor,
1420
+ MdastParagraphVisitor,
1421
+ MdastTextVisitor,
1422
+ MdastFormattingVisitor,
1423
+ MdastInlineCodeVisitor,
1424
+ MdastLinkVisitor,
1425
+ MdastHeadingVisitor,
1426
+ MdastListVisitor,
1427
+ MdastListItemVisitor,
1428
+ MdastBlockQuoteVisitor,
1429
+ MdastCodeVisitor,
1430
+ MdastThematicBreakVisitor,
1431
+ MdastImageVisitor,
1432
+ MdastFrontmatterVisitor,
1433
+ MdastAdmonitionVisitor,
1434
+ MdastMdxJsEsmVisitor,
1435
+ MdastMdxJsxElementVisitor,
1436
+ MdastTableVisitor
1437
+ };
1438
+ function isParent(node) {
1439
+ return node.children instanceof Array;
1440
+ }
1441
+ const defaultMdastExtensions = {
1442
+ mdxFromMarkdown: mdxFromMarkdown(),
1443
+ frontmatterFromMarkdown: frontmatterFromMarkdown("yaml"),
1444
+ directiveFromMarkdown,
1445
+ gfmTableFromMarkdown
1446
+ };
1447
+ const defaultSyntaxExtensions = {
1448
+ mdxjs: mdxjs(),
1449
+ frontmatter: frontmatter(),
1450
+ directive: directive(),
1451
+ gfmTable
1452
+ };
1453
+ function importMarkdownToLexical({ root, markdown: markdown2, visitors, syntaxExtensions, mdastExtensions }) {
1454
+ const mdastRoot = fromMarkdown(markdown2, {
1455
+ extensions: syntaxExtensions,
1456
+ mdastExtensions
1457
+ });
1458
+ if (mdastRoot.children.length === 0) {
1459
+ mdastRoot.children.push({ type: "paragraph", children: [] });
1460
+ }
1461
+ importMdastTreeToLexical({ root, mdastRoot, visitors });
1462
+ }
1463
+ function importMdastTreeToLexical({ root, mdastRoot, visitors }) {
1464
+ const formattingMap = /* @__PURE__ */ new WeakMap();
1465
+ function visitChildren(mdastNode, lexicalParent) {
1466
+ if (!isParent(mdastNode)) {
1467
+ throw new Error("Attempting to visit children of a non-parent");
1468
+ }
1469
+ mdastNode.children.forEach((child) => visit(child, lexicalParent, mdastNode));
1470
+ }
1471
+ function visit(mdastNode, lexicalParent, mdastParent) {
1472
+ const visitor = visitors.find((visitor2) => {
1473
+ if (typeof visitor2.testNode === "string") {
1474
+ return visitor2.testNode === mdastNode.type;
1475
+ }
1476
+ return visitor2.testNode(mdastNode);
1477
+ });
1478
+ if (!visitor) {
1479
+ throw new Error(`no unist visitor found for ${mdastNode.type}`, {
1480
+ cause: mdastNode
1481
+ });
1482
+ }
1483
+ visitor.visitNode({
1484
+ //@ts-expect-error root type is glitching
1485
+ mdastNode,
1486
+ lexicalParent,
1487
+ actions: {
1488
+ visitChildren,
1489
+ addAndStepInto(lexicalNode) {
1490
+ lexicalParent.append(lexicalNode);
1491
+ if (isParent(mdastNode)) {
1492
+ visitChildren(mdastNode, lexicalNode);
1493
+ }
1494
+ },
1495
+ addFormatting(format) {
1496
+ formattingMap.set(mdastNode, format | (formattingMap.get(mdastParent) ?? 0));
1497
+ },
1498
+ getParentFormatting() {
1499
+ return formattingMap.get(mdastParent) ?? 0;
1500
+ }
1501
+ }
1502
+ });
1503
+ }
1504
+ visit(mdastRoot, root, null);
1505
+ }
1506
+ const defaultLexicalNodes = {
1507
+ ParagraphNode,
1508
+ LinkNode,
1509
+ HeadingNode,
1510
+ QuoteNode,
1511
+ ListNode,
1512
+ ListItemNode,
1513
+ HorizontalRuleNode,
1514
+ ImageNode,
1515
+ SandpackNode,
1516
+ CodeBlockNode,
1517
+ FrontmatterNode,
1518
+ AdmonitionNode,
1519
+ JsxNode,
1520
+ CodeNode,
1521
+ // this one should not be used, but markdown shortcuts complain about it
1522
+ TableNode
1523
+ };
1524
+ function uuidv4() {
1525
+ const hex = [...Array(256).keys()].map((index2) => index2.toString(16).padStart(2, "0"));
1526
+ const r = crypto.getRandomValues(new Uint8Array(16));
1527
+ r[6] = r[6] & 15 | 64;
1528
+ r[8] = r[8] & 63 | 128;
1529
+ return [...r.entries()].map(([index2, int]) => [4, 6, 8, 10].includes(index2) ? `-${hex[int]}` : hex[int]).join("");
1530
+ }
1531
+ function defaultComparator(current, next) {
1532
+ return current === next;
1533
+ }
1534
+ class SetMap {
1535
+ constructor() {
1536
+ __publicField(this, "map", /* @__PURE__ */ new Map());
1537
+ }
1538
+ getOrCreate(key) {
1539
+ let record = this.map.get(key);
1540
+ if (!record) {
1541
+ record = /* @__PURE__ */ new Set();
1542
+ this.map.set(key, record);
1543
+ }
1544
+ return record;
1545
+ }
1546
+ get(key) {
1547
+ return this.map.get(key);
1548
+ }
1549
+ use(key, cb) {
1550
+ const set = this.get(key);
1551
+ if (set !== void 0) {
1552
+ cb(set);
1553
+ }
1554
+ }
1555
+ delete(key) {
1556
+ return this.map.delete(key);
1557
+ }
1558
+ }
1559
+ class RefCount {
1560
+ constructor(map = /* @__PURE__ */ new Map()) {
1561
+ __publicField(this, "map");
1562
+ this.map = map;
1563
+ }
1564
+ clone() {
1565
+ return new RefCount(new Map(this.map));
1566
+ }
1567
+ increment(key) {
1568
+ const counter = this.map.get(key) ?? 0;
1569
+ this.map.set(key, counter + 1);
1570
+ }
1571
+ decrement(key, ifZero) {
1572
+ let counter = this.map.get(key);
1573
+ if (counter !== void 0) {
1574
+ counter -= 1;
1575
+ this.map.set(key, counter);
1576
+ if (counter === 0) {
1577
+ ifZero();
1578
+ }
1579
+ }
1580
+ }
1581
+ }
1582
+ const NO_VALUE = Symbol("NO_VALUE");
1583
+ function realm() {
1584
+ const subscriptions = new SetMap();
1585
+ const singletonSubscriptions = /* @__PURE__ */ new Map();
1586
+ const graph = new SetMap();
1587
+ const state = /* @__PURE__ */ new Map();
1588
+ const distinctNodes = /* @__PURE__ */ new Map();
1589
+ const labels = {};
1590
+ function node(value = NO_VALUE, distinct = false) {
1591
+ const key = uuidv4();
1592
+ if (value !== NO_VALUE) {
1593
+ state.set(key, value);
1594
+ }
1595
+ if (distinct !== false) {
1596
+ distinctNodes.set(key, distinct === true ? defaultComparator : distinct);
1597
+ }
1598
+ return { key, toString: () => key };
1599
+ }
1600
+ function subSingle({ key }, subscription) {
1601
+ const nodeSubscriptions = subscriptions.getOrCreate(key);
1602
+ nodeSubscriptions.add(subscription);
1603
+ return () => nodeSubscriptions.delete(subscription);
1604
+ }
1605
+ function singletonSub({ key }, subscription) {
1606
+ singletonSubscriptions.set(key, subscription);
1607
+ return () => singletonSubscriptions.delete(key);
1608
+ }
1609
+ function singletonSubKey(key, subscription) {
1610
+ return singletonSub(labels[key], subscription);
1611
+ }
1612
+ function resetSingletonSubs() {
1613
+ singletonSubscriptions.clear();
1614
+ }
1615
+ function subMultiple(sources, cb) {
1616
+ const sink = node();
1617
+ connect({
1618
+ map: (done) => (...args) => {
1619
+ done(args);
1620
+ },
1621
+ sink,
1622
+ sources
1623
+ });
1624
+ return subSingle(sink, cb);
1625
+ }
1626
+ function sub(...args) {
1627
+ const [subscription] = args.slice(-1);
1628
+ const nodes = args.slice(0, -1);
1629
+ if (nodes.length === 1) {
1630
+ return subSingle(nodes[0], subscription);
1631
+ } else {
1632
+ return subMultiple(nodes, subscription);
1633
+ }
1634
+ }
1635
+ function calculateExecutionMap(keys) {
1636
+ const participatingNodeKeys = [];
1637
+ const visitedNodes = /* @__PURE__ */ new Set();
1638
+ const pendingPulls = new SetMap();
1639
+ const refCount = new RefCount();
1640
+ const projections = new SetMap();
1641
+ function visit(key, insertIndex = 0) {
1642
+ refCount.increment(key);
1643
+ if (visitedNodes.has(key)) {
1644
+ return;
1645
+ }
1646
+ pendingPulls.use(key, (pulls) => {
1647
+ insertIndex = Math.max(...Array.from(pulls).map((key2) => participatingNodeKeys.indexOf(key2))) + 1;
1648
+ });
1649
+ graph.use(key, (sinkProjections) => {
1650
+ sinkProjections.forEach((projection) => {
1651
+ if (projection.sources.has(key)) {
1652
+ projections.getOrCreate(projection.sink).add(projection);
1653
+ visit(projection.sink, insertIndex);
1654
+ } else {
1655
+ pendingPulls.getOrCreate(projection.sink).add(key);
1656
+ }
1657
+ });
1658
+ });
1659
+ visitedNodes.add(key);
1660
+ participatingNodeKeys.splice(insertIndex, 0, key);
1661
+ }
1662
+ keys.forEach((key) => visit(key));
1663
+ return { participatingNodeKeys, pendingPulls, projections, refCount };
1664
+ }
1665
+ const executionMaps = /* @__PURE__ */ new Map();
1666
+ function pubIn(values) {
1667
+ var _a;
1668
+ const keys = Object.keys(values);
1669
+ const executionMapKey = keys.join(",");
1670
+ if (!executionMaps.has(executionMapKey)) {
1671
+ executionMaps.set(executionMapKey, calculateExecutionMap(keys));
1672
+ }
1673
+ const map2 = executionMaps.get(executionMapKey);
1674
+ const refCount = map2.refCount.clone();
1675
+ const participatingNodeKeys = map2.participatingNodeKeys.slice();
1676
+ const transientState = new Map(state);
1677
+ function nodeWillNotEmit(key) {
1678
+ graph.use(key, (projections) => {
1679
+ projections.forEach(({ sources, sink }) => {
1680
+ if (sources.has(key)) {
1681
+ refCount.decrement(sink, () => {
1682
+ participatingNodeKeys.splice(participatingNodeKeys.indexOf(sink), 1);
1683
+ nodeWillNotEmit(sink);
1684
+ });
1685
+ }
1686
+ });
1687
+ });
1688
+ }
1689
+ let nodeKey;
1690
+ while (nodeKey = participatingNodeKeys.shift()) {
1691
+ let resolved = false;
1692
+ const done = (value) => {
1693
+ if (distinctNodes.has(nodeKey) && distinctNodes.get(nodeKey)(state.get(nodeKey), value)) {
1694
+ resolved = false;
1695
+ return;
1696
+ }
1697
+ resolved = true;
1698
+ transientState.set(nodeKey, value);
1699
+ if (state.has(nodeKey)) {
1700
+ state.set(nodeKey, value);
1701
+ }
1702
+ };
1703
+ if (Object.prototype.hasOwnProperty.call(values, nodeKey)) {
1704
+ done(values[nodeKey]);
1705
+ } else {
1706
+ map2.projections.use(nodeKey, (nodeProjections) => {
1707
+ nodeProjections.forEach((projection) => {
1708
+ const args = [...Array.from(projection.sources), ...Array.from(projection.pulls)].map((id) => transientState.get(id));
1709
+ projection.map(done)(...args);
1710
+ });
1711
+ });
1712
+ }
1713
+ if (resolved) {
1714
+ const value = transientState.get(nodeKey);
1715
+ subscriptions.use(nodeKey, (nodeSubscriptions) => {
1716
+ nodeSubscriptions.forEach((subscription) => subscription(value));
1717
+ });
1718
+ (_a = singletonSubscriptions.get(nodeKey)) == null ? void 0 : _a(value);
1719
+ } else {
1720
+ nodeWillNotEmit(nodeKey);
1721
+ }
1722
+ }
1723
+ }
1724
+ function nodesToKeySet(nodes) {
1725
+ return new Set(nodes.map((s) => s.key));
1726
+ }
1727
+ function connect({ sources, pulls = [], map: map2, sink: { key: sink } }) {
1728
+ const dependency = {
1729
+ map: map2,
1730
+ pulls: nodesToKeySet(pulls),
1731
+ sink,
1732
+ sources: nodesToKeySet(sources)
1733
+ };
1734
+ [...sources, ...pulls].forEach(({ key: sourceKey }) => {
1735
+ graph.getOrCreate(sourceKey).add(dependency);
1736
+ });
1737
+ executionMaps.clear();
1738
+ }
1739
+ function debug() {
1740
+ Object.entries(labels).forEach(([name, value]) => {
1741
+ state.get(value.key);
1742
+ });
1743
+ }
1744
+ function pub(...args) {
1745
+ const map2 = {};
1746
+ for (let index2 = 0; index2 < args.length; index2 += 2) {
1747
+ const node2 = args[index2];
1748
+ map2[node2.key] = args[index2 + 1];
1749
+ }
1750
+ pubIn(map2);
1751
+ }
1752
+ function label(newLabels) {
1753
+ Object.assign(labels, newLabels);
1754
+ }
1755
+ function pipe(source, ...operators) {
1756
+ for (const operator of operators) {
1757
+ source = operator(source);
1758
+ }
1759
+ return source;
1760
+ }
1761
+ function spread(source, initialValues) {
1762
+ return initialValues.map((initialValue, index2) => {
1763
+ return tap(node(initialValue, true), (sink) => {
1764
+ connect({
1765
+ map: (done) => (sourceValue) => {
1766
+ done(sourceValue[index2]);
1767
+ },
1768
+ sink,
1769
+ sources: [source]
1770
+ });
1771
+ });
1772
+ });
1773
+ }
1774
+ function link(source, sink) {
1775
+ connect({ map: (done) => (value) => done(value), sink, sources: [source] });
1776
+ }
1777
+ function derive(source, initial) {
1778
+ return tap(node(initial, true), (sink) => {
1779
+ connect({ map: (done) => (value) => done(value), sink, sources: [source] });
1780
+ });
1781
+ }
1782
+ function map(mapFunction) {
1783
+ return (source) => {
1784
+ const sink = node();
1785
+ connect({
1786
+ map: (done) => (value) => {
1787
+ done(mapFunction(value));
1788
+ },
1789
+ sink,
1790
+ sources: [source]
1791
+ });
1792
+ return sink;
1793
+ };
1794
+ }
1795
+ function mapTo(value) {
1796
+ return (source) => {
1797
+ const sink = node();
1798
+ connect({ map: (done) => () => done(value), sink, sources: [source] });
1799
+ return sink;
1800
+ };
1801
+ }
1802
+ function filter(predicate) {
1803
+ return (source) => {
1804
+ const sink = node();
1805
+ connect({ map: (done) => (value) => predicate(value) && done(value), sink, sources: [source] });
1806
+ return sink;
1807
+ };
1808
+ }
1809
+ function once() {
1810
+ return (source) => {
1811
+ const sink = node();
1812
+ let passed = false;
1813
+ connect({
1814
+ map: (done) => (value) => {
1815
+ if (!passed) {
1816
+ passed = true;
1817
+ done(value);
1818
+ }
1819
+ },
1820
+ sink,
1821
+ sources: [source]
1822
+ });
1823
+ return sink;
1824
+ };
1825
+ }
1826
+ function scan(accumulator, seed) {
1827
+ return (source) => {
1828
+ const sink = node();
1829
+ connect({ map: (done) => (value) => done(seed = accumulator(seed, value)), sink, sources: [source] });
1830
+ return sink;
1831
+ };
1832
+ }
1833
+ function throttleTime(delay) {
1834
+ return (source) => {
1835
+ const sink = node();
1836
+ let currentValue;
1837
+ let timeout;
1838
+ sub(source, (value) => {
1839
+ currentValue = value;
1840
+ if (timeout) {
1841
+ return;
1842
+ }
1843
+ timeout = setTimeout(() => {
1844
+ timeout = void 0;
1845
+ pub(sink, currentValue);
1846
+ }, delay);
1847
+ });
1848
+ return sink;
1849
+ };
1850
+ }
1851
+ function delayWithMicrotask() {
1852
+ return (source) => {
1853
+ const sink = node();
1854
+ sub(source, (value) => queueMicrotask(() => pub(sink, value)));
1855
+ return sink;
1856
+ };
1857
+ }
1858
+ function debounceTime(delay) {
1859
+ return (source) => {
1860
+ const sink = node();
1861
+ let currentValue;
1862
+ let timeout;
1863
+ sub(source, (value) => {
1864
+ currentValue = value;
1865
+ if (timeout) {
1866
+ clearTimeout(timeout);
1867
+ }
1868
+ timeout = setTimeout(() => {
1869
+ pub(sink, currentValue);
1870
+ }, delay);
1871
+ });
1872
+ return sink;
1873
+ };
1874
+ }
1875
+ function onNext(bufNode) {
1876
+ return (source) => {
1877
+ const sink = node();
1878
+ let pendingValue = NO_VALUE;
1879
+ sub(source, (value) => pendingValue = value);
1880
+ connect({
1881
+ map: (done) => (value) => {
1882
+ if (pendingValue !== NO_VALUE) {
1883
+ done([pendingValue, value]);
1884
+ pendingValue = NO_VALUE;
1885
+ }
1886
+ },
1887
+ sink,
1888
+ sources: [bufNode]
1889
+ });
1890
+ return sink;
1891
+ };
1892
+ }
1893
+ function passOnlyAfterNodeHasEmittedBefore(starterNode, durationNode) {
1894
+ return (source) => {
1895
+ const sink = node();
1896
+ let startTime = 0;
1897
+ sub(starterNode, () => startTime = Date.now());
1898
+ connect({
1899
+ map: (done) => (value) => {
1900
+ if (Date.now() < startTime + state.get(durationNode.key)) {
1901
+ done(value);
1902
+ }
1903
+ },
1904
+ sink,
1905
+ sources: [source]
1906
+ });
1907
+ return sink;
1908
+ };
1909
+ }
1910
+ function withLatestFrom(...nodes) {
1911
+ return (source) => {
1912
+ const sink = node();
1913
+ connect({
1914
+ map: (done) => (...args) => done(args),
1915
+ pulls: nodes,
1916
+ sink,
1917
+ sources: [source]
1918
+ });
1919
+ return sink;
1920
+ };
1921
+ }
1922
+ function combine(...nodes) {
1923
+ const sink = node();
1924
+ connect({
1925
+ map: (done) => (...args) => done(args),
1926
+ sink,
1927
+ sources: nodes
1928
+ });
1929
+ return sink;
1930
+ }
1931
+ function subKey(key, subscription) {
1932
+ return sub(labels[key], subscription);
1933
+ }
1934
+ function subKeys(keys, subscription) {
1935
+ const nodes = keys.map((key) => labels[key]);
1936
+ return sub(...nodes.concat(subscription));
1937
+ }
1938
+ function pubKey(key, value) {
1939
+ pubKeys({ [key]: value });
1940
+ }
1941
+ function pubKeys(values) {
1942
+ const valuesWithInternalKeys = Object.entries(values).reduce(
1943
+ (acc, [key, value]) => tap(acc, (acc2) => acc2[labels[key].key] = value),
1944
+ {}
1945
+ );
1946
+ pubIn(valuesWithInternalKeys);
1947
+ }
1948
+ function getKeyValue(key) {
1949
+ return state.get(labels[key].key);
1950
+ }
1951
+ function getValue(node2) {
1952
+ return state.get(node2.key);
1953
+ }
1954
+ function getKeyValues(keys) {
1955
+ return keys.map((key) => state.get(labels[key].key));
1956
+ }
1957
+ return {
1958
+ combine,
1959
+ connect,
1960
+ debug,
1961
+ derive,
1962
+ getKeyValue,
1963
+ getValue,
1964
+ getKeyValues,
1965
+ label,
1966
+ labels,
1967
+ link,
1968
+ node,
1969
+ o: {
1970
+ delayWithMicrotask,
1971
+ debounceTime,
1972
+ filter,
1973
+ map,
1974
+ mapTo,
1975
+ onNext,
1976
+ scan,
1977
+ throttleTime,
1978
+ withLatestFrom,
1979
+ once,
1980
+ passOnlyAfterNodeHasEmittedBefore
1981
+ },
1982
+ pipe,
1983
+ pub,
1984
+ pubIn,
1985
+ pubKey,
1986
+ pubKeys,
1987
+ resetSingletonSubs,
1988
+ singletonSub,
1989
+ singletonSubKey,
1990
+ spread,
1991
+ sub,
1992
+ subKey,
1993
+ subKeys
1994
+ };
1995
+ }
1996
+ function omit(keys, obj) {
1997
+ const result = {};
1998
+ const index2 = {};
1999
+ let idx = 0;
2000
+ const len = keys.length;
2001
+ while (idx < len) {
2002
+ index2[keys[idx]] = 1;
2003
+ idx += 1;
2004
+ }
2005
+ for (const prop in obj) {
2006
+ if (!Object.prototype.hasOwnProperty.call(index2, prop)) {
2007
+ result[prop] = obj[prop];
2008
+ }
2009
+ }
2010
+ return result;
2011
+ }
2012
+ const useIsomorphicLayoutEffect = typeof document !== "undefined" ? React.useLayoutEffect : React.useEffect;
2013
+ const GurxContext = createContext(void 0);
2014
+ function realmFactoryToComponent(realmFactory2, map, Root) {
2015
+ const requiredPropNames = Object.keys(map.required || {});
2016
+ const optionalPropNames = Object.keys(map.optional || {});
2017
+ const methodNames = Object.keys(map.methods || {});
2018
+ const eventNames = Object.keys(map.events || {});
2019
+ const Context = GurxContext;
2020
+ function applyPropsToRealm(realm2, props) {
2021
+ const toBePublished = {};
2022
+ for (const requiredPropName of requiredPropNames) {
2023
+ const nodeName = map.required[requiredPropName];
2024
+ toBePublished[nodeName] = props[requiredPropName];
2025
+ }
2026
+ for (const optionalPropName of optionalPropNames) {
2027
+ const value = props[optionalPropName];
2028
+ if (value !== void 0) {
2029
+ const nodeName = map.optional[optionalPropName];
2030
+ toBePublished[nodeName] = value;
2031
+ }
2032
+ }
2033
+ realm2.suppressFlushSync = true;
2034
+ realm2.pubKeys(toBePublished);
2035
+ realm2.suppressFlushSync = false;
2036
+ }
2037
+ function buildMethods(realm2) {
2038
+ return methodNames.reduce((acc, methodName) => {
2039
+ const nodeName = map.methods[methodName];
2040
+ acc[methodName] = (value) => {
2041
+ realm2.pubKey(nodeName, value);
2042
+ };
2043
+ return acc;
2044
+ }, {});
2045
+ }
2046
+ const Component = forwardRef((props, ref) => {
2047
+ const realm2 = useMemo(() => {
2048
+ return tap(realmFactory2(), (realm22) => applyPropsToRealm(realm22, props));
2049
+ }, []);
2050
+ useIsomorphicLayoutEffect(() => {
2051
+ applyPropsToRealm(realm2, props);
2052
+ realm2.resetSingletonSubs();
2053
+ for (const eventName of eventNames) {
2054
+ if (eventName in props) {
2055
+ realm2.singletonSubKey(map.events[eventName], props[eventName]);
2056
+ }
2057
+ }
2058
+ return () => {
2059
+ realm2.resetSingletonSubs();
2060
+ };
2061
+ }, [props]);
2062
+ useImperativeHandle(ref, always(buildMethods(realm2)));
2063
+ const children = props.children;
2064
+ return createElement(
2065
+ Context.Provider,
2066
+ { value: realm2 },
2067
+ Root ? createElement(
2068
+ Root,
2069
+ omit([...requiredPropNames, ...optionalPropNames, ...eventNames], props),
2070
+ children
2071
+ ) : children
2072
+ );
2073
+ });
2074
+ Component.displayName = "Gurx Component";
2075
+ const usePublisher2 = (key) => {
2076
+ const realm2 = React.useContext(Context);
2077
+ return useCallback(
2078
+ (value) => {
2079
+ realm2.pubKey(key, value);
2080
+ },
2081
+ // eslint-disable-next-line react-hooks/exhaustive-deps
2082
+ [key, realm2]
2083
+ );
2084
+ };
2085
+ const useEmitterValues2 = (...keys) => {
2086
+ const realm2 = useContext(Context);
2087
+ const [values, setValues] = useState(() => realm2.getKeyValues(keys));
2088
+ useIsomorphicLayoutEffect(
2089
+ () => realm2 == null ? void 0 : realm2.subKeys(keys, (newValues) => {
2090
+ const setter = () => {
2091
+ setValues(keys.length === 1 ? [newValues] : newValues);
2092
+ };
2093
+ if (realm2.suppressFlushSync) {
2094
+ setter();
2095
+ } else {
2096
+ setter();
2097
+ }
2098
+ }),
2099
+ [keys]
2100
+ );
2101
+ return values;
2102
+ };
2103
+ const usePubKeys = () => {
2104
+ return useContext(Context).pubKeys;
2105
+ };
2106
+ const useEmitter = (key, callback) => {
2107
+ const realm2 = useContext(Context);
2108
+ useIsomorphicLayoutEffect(() => realm2.subKey(key, callback), [callback]);
2109
+ };
2110
+ return {
2111
+ Component,
2112
+ useEmitter,
2113
+ useEmitterValues: useEmitterValues2,
2114
+ usePubKeys,
2115
+ usePublisher: usePublisher2
2116
+ };
2117
+ }
2118
+ function system(constructor, dependencies = [], id = uuidv4()) {
2119
+ return [
2120
+ {
2121
+ constructor,
2122
+ dependencies,
2123
+ id
2124
+ },
2125
+ { id }
2126
+ ];
2127
+ }
2128
+ function realmFactory(...specs) {
2129
+ const singletons = /* @__PURE__ */ new Map();
2130
+ const r = realm();
2131
+ const _init = ({ id, constructor, dependencies }) => {
2132
+ if (singletons.has(id)) {
2133
+ return singletons.get(id);
2134
+ }
2135
+ const system2 = constructor(
2136
+ r,
2137
+ dependencies.map((t) => _init(specs.find((spec) => spec.id === t.id)))
2138
+ );
2139
+ r.label(system2);
2140
+ singletons.set(id, system2);
2141
+ return system2;
2142
+ };
2143
+ specs.forEach(_init);
2144
+ return r;
2145
+ }
2146
+ function getRealmFactory(...specs) {
2147
+ return () => realmFactory(...specs);
2148
+ }
2149
+ const formatParagraph = (editor) => {
2150
+ editor.update(() => {
2151
+ const selection = $getSelection();
2152
+ if ($isRangeSelection(selection) || DEPRECATED_$isGridSelection(selection))
2153
+ $setBlocksType(selection, () => $createParagraphNode());
2154
+ });
2155
+ };
2156
+ const formatHeading = (editor, headingType) => {
2157
+ editor.update(() => {
2158
+ const selection = $getSelection();
2159
+ if ($isRangeSelection(selection) || DEPRECATED_$isGridSelection(selection)) {
2160
+ $setBlocksType(selection, () => $createHeadingNode(headingType));
2161
+ }
2162
+ });
2163
+ };
2164
+ const formatQuote = (editor) => {
2165
+ editor.update(() => {
2166
+ const selection = $getSelection();
2167
+ if ($isRangeSelection(selection) || DEPRECATED_$isGridSelection(selection)) {
2168
+ $setBlocksType(selection, () => $createQuoteNode());
2169
+ }
2170
+ });
2171
+ };
2172
+ const formatAdmonition = (editor, kind) => {
2173
+ editor.update(() => {
2174
+ const selection = $getSelection();
2175
+ if ($isRangeSelection(selection) || DEPRECATED_$isGridSelection(selection)) {
2176
+ $setBlocksType(selection, () => {
2177
+ return $createAdmonitionNode(kind);
2178
+ });
2179
+ }
2180
+ });
2181
+ };
2182
+ const ListTypeCommandMap = /* @__PURE__ */ new Map([
2183
+ ["number", INSERT_ORDERED_LIST_COMMAND],
2184
+ ["bullet", INSERT_UNORDERED_LIST_COMMAND],
2185
+ ["", REMOVE_LIST_COMMAND]
2186
+ ]);
2187
+ function seedTable() {
2188
+ return {
2189
+ type: "table",
2190
+ children: [
2191
+ {
2192
+ type: "tableRow",
2193
+ children: [{ type: "tableCell", children: [] }]
2194
+ }
2195
+ ]
2196
+ };
2197
+ }
2198
+ const [EditorSystem, EditorSystemType] = system((r) => {
2199
+ const editor = r.node(null, true);
2200
+ const markdownSource = r.node("");
2201
+ const historyState = r.node(createEmptyHistoryState());
2202
+ const activeEditor = r.derive(editor, null);
2203
+ const currentFormat = r.node(0, true);
2204
+ const currentSelection = r.node(null);
2205
+ const currentListType = r.node(null);
2206
+ const currentBlockType = r.node(null);
2207
+ const applyFormat = r.node();
2208
+ const applyListType = r.node();
2209
+ const applyBlockType = r.node();
2210
+ const insertHorizontalRule = r.node();
2211
+ const insertTable = r.node();
2212
+ const insertFrontmatter = r.node();
2213
+ const insertImage = r.node();
2214
+ const createEditorSubscription = r.node();
2215
+ const editorSubscriptions = r.node([]);
2216
+ const inFocus = r.node(false, true);
2217
+ const activeEditorType = r.node({ type: "lexical" });
2218
+ const editorRootElementRef = r.node(null);
2219
+ const markdownParseOptions = r.node(null);
2220
+ const lexicalConvertOptions = r.node(null);
2221
+ const lexicalNodes = r.node([]);
2222
+ const imageAutocompleteSuggestions = r.node([]);
2223
+ r.link(
2224
+ r.pipe(
2225
+ createEditorSubscription,
2226
+ r.o.withLatestFrom(editorSubscriptions),
2227
+ r.o.map(([createSubscription, subscriptions]) => {
2228
+ return [...subscriptions, createSubscription];
2229
+ })
2230
+ ),
2231
+ editorSubscriptions
2232
+ );
2233
+ r.sub(r.pipe(applyListType, r.o.withLatestFrom(activeEditor)), ([listType, theEditor]) => {
2234
+ theEditor == null ? void 0 : theEditor.dispatchCommand(ListTypeCommandMap.get(listType), void 0);
2235
+ });
2236
+ r.sub(r.pipe(applyFormat, r.o.withLatestFrom(activeEditor)), ([format, theEditor]) => {
2237
+ theEditor == null ? void 0 : theEditor.dispatchCommand(FORMAT_TEXT_COMMAND, format);
2238
+ });
2239
+ r.sub(r.pipe(insertHorizontalRule, r.o.withLatestFrom(activeEditor)), ([, theEditor]) => {
2240
+ theEditor == null ? void 0 : theEditor.dispatchCommand(INSERT_HORIZONTAL_RULE_COMMAND, void 0);
2241
+ });
2242
+ r.sub(r.pipe(insertImage, r.o.withLatestFrom(activeEditor)), ([src, theEditor]) => {
2243
+ theEditor == null ? void 0 : theEditor.getEditorState().read(() => {
2244
+ const selection = $getSelection();
2245
+ if ($isRangeSelection(selection)) {
2246
+ const focusNode = selection.focus.getNode();
2247
+ if (focusNode !== null) {
2248
+ theEditor.update(() => {
2249
+ const imageNode = $createImageNode({ altText: "", src, title: "" });
2250
+ $insertNodeToNearestRoot(imageNode);
2251
+ });
2252
+ }
2253
+ }
2254
+ });
2255
+ });
2256
+ r.sub(r.pipe(insertFrontmatter, r.o.withLatestFrom(activeEditor)), ([, theEditor]) => {
2257
+ theEditor == null ? void 0 : theEditor.update(() => {
2258
+ const firstItem = $getRoot().getFirstChild();
2259
+ if (!$isFrontmatterNode(firstItem)) {
2260
+ const fmNode = $createFrontmatterNode('"": ""');
2261
+ if (firstItem) {
2262
+ firstItem.insertBefore(fmNode);
2263
+ } else {
2264
+ $getRoot().append(fmNode);
2265
+ }
2266
+ }
2267
+ });
2268
+ });
2269
+ r.sub(r.pipe(insertTable, r.o.withLatestFrom(activeEditor)), ([, theEditor]) => {
2270
+ theEditor == null ? void 0 : theEditor.getEditorState().read(() => {
2271
+ const selection = $getSelection();
2272
+ if ($isRangeSelection(selection)) {
2273
+ const focusNode = selection.focus.getNode();
2274
+ if (focusNode !== null) {
2275
+ theEditor.update(() => {
2276
+ const tableNode = $createTableNode(seedTable());
2277
+ $insertNodeToNearestRoot(tableNode);
2278
+ setTimeout(() => {
2279
+ tableNode.select([0, 0]);
2280
+ }, 50);
2281
+ });
2282
+ }
2283
+ }
2284
+ });
2285
+ });
2286
+ r.sub(r.pipe(applyBlockType, r.o.withLatestFrom(activeEditor)), ([type, theEditor]) => {
2287
+ if (theEditor) {
2288
+ switch (type) {
2289
+ case "paragraph": {
2290
+ formatParagraph(theEditor);
2291
+ break;
2292
+ }
2293
+ case "quote": {
2294
+ formatQuote(theEditor);
2295
+ break;
2296
+ }
2297
+ case "note":
2298
+ case "tip":
2299
+ case "danger":
2300
+ case "caution":
2301
+ case "info": {
2302
+ formatAdmonition(theEditor, type);
2303
+ break;
2304
+ }
2305
+ default: {
2306
+ formatHeading(theEditor, type);
2307
+ }
2308
+ }
2309
+ }
2310
+ });
2311
+ r.sub(r.pipe(currentSelection, r.o.withLatestFrom(activeEditor)), ([selection, theEditor]) => {
2312
+ if (!selection || !theEditor) {
2313
+ return;
2314
+ }
2315
+ const anchorNode = selection.anchor.getNode();
2316
+ let element = anchorNode.getKey() === "root" ? anchorNode : $findMatchingParent(anchorNode, (e) => {
2317
+ const parent = e.getParent();
2318
+ return parent !== null && $isRootOrShadowRoot(parent);
2319
+ });
2320
+ if (element === null) {
2321
+ element = anchorNode.getTopLevelElementOrThrow();
2322
+ }
2323
+ const elementKey = element.getKey();
2324
+ const elementDOM = theEditor.getElementByKey(elementKey);
2325
+ if (elementDOM !== null) {
2326
+ if ($isListNode(element)) {
2327
+ const parentList = $getNearestNodeOfType(anchorNode, ListNode);
2328
+ const type = parentList ? parentList.getListType() : element.getListType();
2329
+ r.pubIn({
2330
+ [currentListType.key]: type,
2331
+ [currentBlockType.key]: ""
2332
+ });
2333
+ } else {
2334
+ r.pub(currentListType, null);
2335
+ const blockType = $isHeadingNode(element) ? element.getTag() : $isAdmonitionNode(element) ? element.getKind() : element.getType();
2336
+ r.pubIn({
2337
+ [currentListType.key]: null,
2338
+ [currentBlockType.key]: blockType
2339
+ });
2340
+ }
2341
+ }
2342
+ });
2343
+ function handleSelectionChange() {
2344
+ const selection = $getSelection();
2345
+ if ($isRangeSelection(selection)) {
2346
+ r.pubKeys({
2347
+ currentSelection: selection,
2348
+ currentFormat: selection.format
2349
+ });
2350
+ }
2351
+ }
2352
+ r.sub(editor, (theEditor) => {
2353
+ if (theEditor) {
2354
+ theEditor.registerCommand(
2355
+ SELECTION_CHANGE_COMMAND,
2356
+ (_, editor2) => {
2357
+ r.pubIn({
2358
+ [activeEditor.key]: editor2,
2359
+ [inFocus.key]: true
2360
+ });
2361
+ handleSelectionChange();
2362
+ return false;
2363
+ },
2364
+ COMMAND_PRIORITY_CRITICAL
2365
+ );
2366
+ }
2367
+ });
2368
+ r.pipe(
2369
+ r.combine(editorSubscriptions, activeEditor),
2370
+ r.o.scan((teardowns, [editorSubscriptions2, activeEditorValue]) => {
2371
+ teardowns.forEach((u) => u());
2372
+ return activeEditorValue ? editorSubscriptions2.map((s) => s(activeEditorValue, r.getValue(editor))) : [];
2373
+ }, [])
2374
+ );
2375
+ r.pub(createEditorSubscription, (editor2) => {
2376
+ return editor2.registerUpdateListener(({ editorState }) => {
2377
+ editorState.read(() => {
2378
+ handleSelectionChange();
2379
+ });
2380
+ });
2381
+ });
2382
+ r.pub(createEditorSubscription, (theEditor) => {
2383
+ return theEditor.registerCommand(
2384
+ BLUR_COMMAND,
2385
+ (payload) => {
2386
+ var _a;
2387
+ const rootEditor = r.getValue(editor);
2388
+ const movingOutside = !((_a = rootEditor.getRootElement()) == null ? void 0 : _a.contains(payload.relatedTarget));
2389
+ if (movingOutside) {
2390
+ r.pub(inFocus, false);
2391
+ }
2392
+ return false;
2393
+ },
2394
+ COMMAND_PRIORITY_LOW
2395
+ );
2396
+ });
2397
+ return {
2398
+ editor,
2399
+ activeEditor,
2400
+ currentFormat,
2401
+ currentSelection,
2402
+ currentListType,
2403
+ currentBlockType,
2404
+ applyFormat,
2405
+ applyListType,
2406
+ applyBlockType,
2407
+ insertHorizontalRule,
2408
+ insertFrontmatter,
2409
+ insertImage,
2410
+ insertTable,
2411
+ createEditorSubscription,
2412
+ editorSubscriptions,
2413
+ activeEditorType,
2414
+ inFocus,
2415
+ historyState,
2416
+ editorRootElementRef,
2417
+ markdownParseOptions,
2418
+ lexicalConvertOptions,
2419
+ lexicalNodes,
2420
+ imageAutocompleteSuggestions,
2421
+ markdownSource
2422
+ };
2423
+ }, []);
2424
+ const [JsxSystem, JsxSystemType] = system((r) => {
2425
+ const jsxComponentDescriptors = r.node([]);
2426
+ return {
2427
+ jsxComponentDescriptors
2428
+ };
2429
+ }, []);
2430
+ const [ViewModeSystem] = system(
2431
+ (r, [{ editor, markdownParseOptions, markdownSource }, {}]) => {
2432
+ const viewMode = r.node("editor");
2433
+ const headMarkdown = r.node("");
2434
+ r.sub(
2435
+ r.pipe(
2436
+ viewMode,
2437
+ r.o.scan(
2438
+ (prev, next) => {
2439
+ return {
2440
+ current: prev.next,
2441
+ next
2442
+ };
2443
+ },
2444
+ { current: "editor", next: "editor" }
2445
+ ),
2446
+ r.o.withLatestFrom(editor, markdownSource, markdownParseOptions)
2447
+ ),
2448
+ ([{ current }, editor2, markdownSource2, markdownParseOptions2]) => {
2449
+ if (current === "markdown") {
2450
+ editor2 == null ? void 0 : editor2.update(() => {
2451
+ $getRoot().clear();
2452
+ importMarkdownToLexical({
2453
+ root: $getRoot(),
2454
+ markdown: markdownSource2,
2455
+ ...markdownParseOptions2
2456
+ });
2457
+ });
2458
+ }
2459
+ }
2460
+ );
2461
+ return {
2462
+ viewMode,
2463
+ headMarkdown
2464
+ };
2465
+ },
2466
+ [EditorSystemType, JsxSystemType]
2467
+ );
2468
+ const defaultSnippetContent = `
2469
+ export default function App() {
2470
+ return (
2471
+ <div className="App">
2472
+ <h1>Hello CodeSandbox</h1>
2473
+ <h2>Start editing to see some magic happen!</h2>
2474
+ </div>
2475
+ );
2476
+ }
2477
+ `;
2478
+ const defaultSandpackConfig$1 = {
2479
+ defaultPreset: "react",
2480
+ presets: [
2481
+ {
2482
+ name: "react",
2483
+ meta: "live react",
2484
+ label: "React",
2485
+ sandpackTemplate: "react",
2486
+ sandpackTheme: "light",
2487
+ snippetFileName: "/App.js",
2488
+ snippetLanguage: "jsx",
2489
+ initialSnippetContent: defaultSnippetContent
2490
+ }
2491
+ ]
2492
+ };
2493
+ const defaultCodeBlockLanguages = {
2494
+ js: "JavaScript",
2495
+ ts: "TypeScript",
2496
+ tsx: "TypeScript (React)",
2497
+ jsx: "JavaScript (React)",
2498
+ css: "CSS"
2499
+ };
2500
+ const [SandpackSystem] = system(
2501
+ (r, [{ activeEditor, activeEditorType, createEditorSubscription }]) => {
2502
+ const sandpackConfig = r.node(defaultSandpackConfig$1);
2503
+ const codeBlockLanguages = r.node(defaultCodeBlockLanguages);
2504
+ const insertSandpack = r.node();
2505
+ const insertCodeBlock = r.node();
2506
+ r.pub(createEditorSubscription, (editor) => {
2507
+ return editor.registerCommand(
2508
+ FOCUS_COMMAND,
2509
+ () => {
2510
+ r.pub(activeEditorType, { type: "lexical" });
2511
+ return false;
2512
+ },
2513
+ COMMAND_PRIORITY_LOW
2514
+ );
2515
+ });
2516
+ r.sub(r.pipe(insertSandpack, r.o.withLatestFrom(activeEditor, sandpackConfig)), ([meta, theEditor, sandpackConfig2]) => {
2517
+ theEditor == null ? void 0 : theEditor.getEditorState().read(() => {
2518
+ const selection = $getSelection();
2519
+ if ($isRangeSelection(selection)) {
2520
+ const focusNode = selection.focus.getNode();
2521
+ const preset = meta ? sandpackConfig2.presets.find((preset2) => preset2.meta === meta) : sandpackConfig2.presets.find((preset2) => preset2.name == sandpackConfig2.defaultPreset);
2522
+ if (!preset) {
2523
+ throw new Error(`No sandpack preset found with ${meta}`);
2524
+ }
2525
+ if (focusNode !== null) {
2526
+ theEditor.update(() => {
2527
+ const sandpackNode = $createSandpackNode({
2528
+ code: preset.initialSnippetContent || "",
2529
+ language: preset.snippetLanguage || "jsx",
2530
+ meta: preset.meta
2531
+ });
2532
+ $insertNodeToNearestRoot(sandpackNode);
2533
+ setTimeout(() => sandpackNode.select(), 80);
2534
+ });
2535
+ }
2536
+ }
2537
+ });
2538
+ });
2539
+ r.sub(r.pipe(insertCodeBlock, r.o.withLatestFrom(activeEditor)), ([, theEditor]) => {
2540
+ theEditor == null ? void 0 : theEditor.getEditorState().read(() => {
2541
+ const selection = $getSelection();
2542
+ if ($isRangeSelection(selection)) {
2543
+ const focusNode = selection.focus.getNode();
2544
+ if (focusNode !== null) {
2545
+ theEditor.update(() => {
2546
+ const codeBlockNode = $createCodeBlockNode({
2547
+ code: "",
2548
+ language: "jsx",
2549
+ meta: ""
2550
+ });
2551
+ $insertNodeToNearestRoot(codeBlockNode);
2552
+ setTimeout(() => codeBlockNode.select(), 80);
2553
+ });
2554
+ }
2555
+ }
2556
+ });
2557
+ });
2558
+ return {
2559
+ codeBlockLanguages,
2560
+ insertSandpack,
2561
+ insertCodeBlock,
2562
+ sandpackConfig
2563
+ };
2564
+ },
2565
+ [EditorSystemType]
2566
+ );
2567
+ function getSelectedNode(selection) {
2568
+ const anchor = selection.anchor;
2569
+ const focus = selection.focus;
2570
+ const anchorNode = selection.anchor.getNode();
2571
+ const focusNode = selection.focus.getNode();
2572
+ if (anchorNode === focusNode) {
2573
+ return anchorNode;
2574
+ }
2575
+ const isBackward = selection.isBackward();
2576
+ if (isBackward) {
2577
+ return $isAtNodeEnd(focus) ? anchorNode : focusNode;
2578
+ } else {
2579
+ return $isAtNodeEnd(anchor) ? anchorNode : focusNode;
2580
+ }
2581
+ }
2582
+ function getSelectionRectangle(editor) {
2583
+ const selection = $getSelection();
2584
+ const nativeSelection = window.getSelection();
2585
+ const activeElement = document.activeElement;
2586
+ const rootElement = editor.getRootElement();
2587
+ if (selection !== null && nativeSelection !== null && rootElement !== null && rootElement.contains(nativeSelection.anchorNode) && editor.isEditable()) {
2588
+ const domRange = nativeSelection.getRangeAt(0);
2589
+ let rect;
2590
+ if (nativeSelection.anchorNode === rootElement) {
2591
+ let inner = rootElement;
2592
+ while (inner.firstElementChild != null) {
2593
+ inner = inner.firstElementChild;
2594
+ }
2595
+ rect = inner.getBoundingClientRect();
2596
+ } else {
2597
+ rect = domRange.getBoundingClientRect();
2598
+ }
2599
+ return {
2600
+ top: rect.top + window.scrollY,
2601
+ left: rect.left + window.scrollX,
2602
+ width: rect.width,
2603
+ height: rect.height
2604
+ };
2605
+ } else if (!activeElement || activeElement.className !== "link-input") {
2606
+ return null;
2607
+ }
2608
+ return null;
2609
+ }
2610
+ function getStateAsMarkdown(editor, exportParams) {
2611
+ return tap({ markdown: "" }, (result) => {
2612
+ editor.getEditorState().read(() => {
2613
+ result.markdown = exportMarkdownFromLexical({ root: $getRoot(), ...exportParams });
2614
+ });
2615
+ }).markdown;
2616
+ }
2617
+ const CAN_USE_DOM = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
2618
+ const IS_APPLE = CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
2619
+ function getLinkNodeInSelection(selection) {
2620
+ const node = getSelectedNode(selection);
2621
+ const parent = node.getParent();
2622
+ if ($isLinkNode(parent)) {
2623
+ return parent;
2624
+ } else if ($isLinkNode(node)) {
2625
+ return node;
2626
+ }
2627
+ return null;
2628
+ }
2629
+ const [LinkDialogSystem, LinkDialogSystemType] = system(
2630
+ (r, [{ activeEditor, currentSelection, createEditorSubscription }]) => {
2631
+ const dialogState = r.node(false);
2632
+ const onWindowChange = r.node();
2633
+ const linkDialogState = r.node({ type: "inactive" }, true);
2634
+ const updateLinkUrl = r.node();
2635
+ const cancelLinkEdit = r.node();
2636
+ const applyLinkChanges = r.node();
2637
+ const switchFromPreviewToLinkEdit = r.node();
2638
+ const removeLink = r.node();
2639
+ const openLinkEditDialog = r.node();
2640
+ const linkAutocompleteSuggestions = r.node([]);
2641
+ r.sub(
2642
+ r.pipe(
2643
+ openLinkEditDialog,
2644
+ r.o.withLatestFrom(currentSelection, activeEditor),
2645
+ r.o.filter(([, selection]) => $isRangeSelection(selection))
2646
+ ),
2647
+ ([, selection, editor]) => {
2648
+ editor == null ? void 0 : editor.getEditorState().read(() => {
2649
+ const node = getLinkNodeInSelection(selection);
2650
+ const rectangle = getSelectionRectangle(editor);
2651
+ if (node) {
2652
+ r.pub(linkDialogState, {
2653
+ type: "edit",
2654
+ initialUrl: node.getURL(),
2655
+ url: node.getURL(),
2656
+ linkNodeKey: node.getKey(),
2657
+ rectangle
2658
+ });
2659
+ } else {
2660
+ r.pub(linkDialogState, {
2661
+ type: "edit",
2662
+ initialUrl: "",
2663
+ url: "",
2664
+ linkNodeKey: "",
2665
+ rectangle
2666
+ });
2667
+ }
2668
+ });
2669
+ }
2670
+ );
2671
+ r.sub(r.pipe(removeLink, r.o.withLatestFrom(activeEditor)), ([, editor]) => {
2672
+ editor == null ? void 0 : editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
2673
+ });
2674
+ r.pub(createEditorSubscription, (editor) => {
2675
+ return editor.registerCommand(
2676
+ KEY_ESCAPE_COMMAND,
2677
+ () => {
2678
+ const state = r.getValue(linkDialogState);
2679
+ if (state.type === "preview") {
2680
+ r.pub(linkDialogState, { type: "inactive" });
2681
+ return true;
2682
+ }
2683
+ return false;
2684
+ },
2685
+ COMMAND_PRIORITY_LOW
2686
+ );
2687
+ });
2688
+ r.pub(createEditorSubscription, (editor) => {
2689
+ return editor.registerCommand(
2690
+ KEY_MODIFIER_COMMAND,
2691
+ (event) => {
2692
+ if (event.key === "k" && IS_APPLE ? event.metaKey : event.ctrlKey) {
2693
+ r.pub(openLinkEditDialog, true);
2694
+ return true;
2695
+ }
2696
+ return false;
2697
+ },
2698
+ COMMAND_PRIORITY_HIGH
2699
+ );
2700
+ });
2701
+ r.link(
2702
+ r.pipe(
2703
+ switchFromPreviewToLinkEdit,
2704
+ r.o.withLatestFrom(linkDialogState),
2705
+ r.o.map(([, state]) => {
2706
+ if (state.type === "preview") {
2707
+ return {
2708
+ type: "edit",
2709
+ initialUrl: state.url,
2710
+ url: state.url,
2711
+ linkNodeKey: state.linkNodeKey,
2712
+ rectangle: state.rectangle
2713
+ };
2714
+ } else {
2715
+ throw new Error("Cannot switch to edit mode when not in preview mode");
2716
+ }
2717
+ })
2718
+ ),
2719
+ linkDialogState
2720
+ );
2721
+ r.sub(r.pipe(applyLinkChanges, r.o.withLatestFrom(linkDialogState, activeEditor)), ([, state, editor]) => {
2722
+ if (state.type === "edit") {
2723
+ const url = state.url.trim();
2724
+ if (url.trim() !== "") {
2725
+ editor == null ? void 0 : editor.dispatchCommand(TOGGLE_LINK_COMMAND, url);
2726
+ r.pub(linkDialogState, {
2727
+ type: "preview",
2728
+ linkNodeKey: state.linkNodeKey,
2729
+ rectangle: state.rectangle,
2730
+ url
2731
+ });
2732
+ } else {
2733
+ if (state.initialUrl !== "") {
2734
+ editor == null ? void 0 : editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
2735
+ }
2736
+ r.pub(linkDialogState, {
2737
+ type: "inactive"
2738
+ });
2739
+ }
2740
+ } else {
2741
+ throw new Error("Cannot apply link edit when not in edit mode");
2742
+ }
2743
+ });
2744
+ r.link(
2745
+ r.pipe(
2746
+ updateLinkUrl,
2747
+ r.o.withLatestFrom(linkDialogState),
2748
+ r.o.map(([url, state]) => {
2749
+ if (state.type === "edit") {
2750
+ return {
2751
+ ...state,
2752
+ url
2753
+ };
2754
+ } else {
2755
+ throw new Error("Cannot update link url when not in edit mode");
2756
+ }
2757
+ })
2758
+ ),
2759
+ linkDialogState
2760
+ );
2761
+ r.link(
2762
+ r.pipe(
2763
+ cancelLinkEdit,
2764
+ r.o.withLatestFrom(linkDialogState, activeEditor),
2765
+ r.o.map(([, state, editor]) => {
2766
+ if (state.type === "edit") {
2767
+ editor == null ? void 0 : editor.focus();
2768
+ if (state.initialUrl === "") {
2769
+ return {
2770
+ type: "inactive"
2771
+ };
2772
+ } else {
2773
+ return {
2774
+ type: "preview",
2775
+ url: state.initialUrl,
2776
+ linkNodeKey: state.linkNodeKey,
2777
+ rectangle: state.rectangle
2778
+ };
2779
+ }
2780
+ } else {
2781
+ throw new Error("Cannot cancel edit when not in edit mode");
2782
+ }
2783
+ })
2784
+ ),
2785
+ linkDialogState
2786
+ );
2787
+ r.link(
2788
+ r.pipe(
2789
+ r.combine(currentSelection, onWindowChange),
2790
+ r.o.withLatestFrom(activeEditor, linkDialogState),
2791
+ r.o.map(([[selection], activeEditor2]) => {
2792
+ if ($isRangeSelection(selection) && activeEditor2) {
2793
+ const node = getLinkNodeInSelection(selection);
2794
+ if (node) {
2795
+ return {
2796
+ type: "preview",
2797
+ url: node.getURL(),
2798
+ linkNodeKey: node.getKey(),
2799
+ rectangle: getSelectionRectangle(activeEditor2)
2800
+ };
2801
+ } else {
2802
+ return {
2803
+ type: "inactive"
2804
+ };
2805
+ }
2806
+ } else {
2807
+ return {
2808
+ type: "inactive"
2809
+ };
2810
+ }
2811
+ })
2812
+ ),
2813
+ linkDialogState
2814
+ );
2815
+ return {
2816
+ dialogState,
2817
+ onWindowChange,
2818
+ linkDialogState,
2819
+ updateLinkUrl,
2820
+ switchFromPreviewToLinkEdit,
2821
+ cancelLinkEdit,
2822
+ removeLink,
2823
+ openLinkEditDialog,
2824
+ applyLinkChanges,
2825
+ linkAutocompleteSuggestions
2826
+ };
2827
+ },
2828
+ [EditorSystemType]
2829
+ );
2830
+ const [OnChangeSystem, OnChangeSystemType] = system(
2831
+ (r, [{ createEditorSubscription, lexicalConvertOptions, markdownSource }, { jsxComponentDescriptors }]) => {
2832
+ const onChange = r.node();
2833
+ r.pub(createEditorSubscription, (activeEditor, rootEditor) => {
2834
+ function updateMarkdown() {
2835
+ const descriptors = r.getValue(jsxComponentDescriptors);
2836
+ const options = r.getValue(lexicalConvertOptions);
2837
+ const markdown2 = getStateAsMarkdown(rootEditor, { jsxComponentDescriptors: descriptors, ...options });
2838
+ r.pub(onChange, markdown2);
2839
+ r.pub(markdownSource, markdown2);
2840
+ }
2841
+ updateMarkdown();
2842
+ return activeEditor.registerUpdateListener(({ dirtyElements, dirtyLeaves, prevEditorState, tags }) => {
2843
+ if (dirtyElements.size === 0 && dirtyLeaves.size === 0 || tags.has("history-merge") || prevEditorState.isEmpty()) {
2844
+ return;
2845
+ }
2846
+ updateMarkdown();
2847
+ });
2848
+ });
2849
+ return {
2850
+ onChange
2851
+ };
2852
+ },
2853
+ [EditorSystemType, JsxSystemType]
2854
+ );
2855
+ const [ToolbarSystem, ToolbarSystemType] = system((r) => {
2856
+ const toolbarComponents = r.node([]);
2857
+ return {
2858
+ toolbarComponents
2859
+ };
2860
+ }, []);
2861
+ const {
2862
+ Component: EditorSystemComponent,
2863
+ usePublisher,
2864
+ useEmitterValues
2865
+ } = realmFactoryToComponent(
2866
+ getRealmFactory(EditorSystem, ViewModeSystem, SandpackSystem, LinkDialogSystem, JsxSystem, OnChangeSystem, ToolbarSystem),
2867
+ {
2868
+ required: {
2869
+ markdownSource: "markdownSource",
2870
+ headMarkdown: "headMarkdown",
2871
+ jsxComponentDescriptors: "jsxComponentDescriptors",
2872
+ sandpackConfig: "sandpackConfig",
2873
+ toolbarComponents: "toolbarComponents",
2874
+ markdownParseOptions: "markdownParseOptions",
2875
+ lexicalConvertOptions: "lexicalConvertOptions",
2876
+ lexicalNodes: "lexicalNodes"
2877
+ },
2878
+ optional: {
2879
+ editorRootElementRef: "editorRootElementRef",
2880
+ viewMode: "viewMode",
2881
+ linkAutocompleteSuggestions: "linkAutocompleteSuggestions",
2882
+ imageAutocompleteSuggestions: "imageAutocompleteSuggestions",
2883
+ codeBlockLanguages: "codeBlockLanguages"
2884
+ },
2885
+ events: {
2886
+ onChange: "onChange"
2887
+ }
2888
+ },
2889
+ ({ children }) => {
2890
+ return /* @__PURE__ */ React__default.createElement("div", null, /* @__PURE__ */ React__default.createElement(CaptureLexicalEditor, null), children);
2891
+ }
2892
+ );
2893
+ const CaptureLexicalEditor = () => {
2894
+ const setEditor = usePublisher("editor");
2895
+ const [lexicalEditor] = useLexicalComposerContext();
2896
+ React__default.useEffect(() => setEditor(lexicalEditor), [lexicalEditor, setEditor]);
2897
+ return null;
2898
+ };
2899
+ const SvgCheck = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
2900
+ maskType: "alpha"
2901
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "m9.55 18-5.7-5.7 1.425-1.425L9.55 15.15l9.175-9.175L20.15 7.4 9.55 18Z" })));
2902
+ const CheckIcon = SvgCheck;
2903
+ const SvgClose = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
2904
+ maskType: "alpha"
2905
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M6.4 19 5 17.6l5.6-5.6L5 6.4 6.4 5l5.6 5.6L17.6 5 19 6.4 13.4 12l5.6 5.6-1.4 1.4-5.6-5.6L6.4 19Z" })));
2906
+ const CloseIcon = SvgClose;
2907
+ const SvgContentCopy = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
2908
+ maskType: "alpha"
2909
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M7 18V2h13v16H7Zm2-2h9V4H9v12Zm-6 6V6h2v14h11v2H3Z" })));
2910
+ const CopyIcon = SvgContentCopy;
2911
+ const SvgEdit = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
2912
+ maskType: "alpha"
2913
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M5 19h1.4l8.625-8.625-1.4-1.4L5 17.6V19ZM19.3 8.925l-4.25-4.2L17.875 1.9 22.1 6.125l-2.8 2.8ZM3 21v-4.25l10.6-10.6 4.25 4.25L7.25 21H3Z" })));
2914
+ const EditIcon = SvgEdit;
2915
+ const SvgLinkOff = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
2916
+ maskType: "alpha"
2917
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "m19.25 16.45-1.5-1.55a3.05 3.05 0 0 0 1.625-1.063A2.867 2.867 0 0 0 20 12c0-.833-.292-1.542-.875-2.125A2.893 2.893 0 0 0 17 9h-4V7h4c1.383 0 2.563.487 3.538 1.462C21.513 9.437 22 10.617 22 12c0 .95-.246 1.825-.737 2.625a4.79 4.79 0 0 1-2.013 1.825ZM15.85 13l-2-2H16v2h-.15Zm3.95 9.6L1.4 4.2l1.4-1.4 18.4 18.4-1.4 1.4ZM11 17H7c-1.383 0-2.562-.488-3.537-1.463C2.488 14.562 2 13.383 2 12c0-1.15.35-2.175 1.05-3.075.7-.9 1.6-1.492 2.7-1.775L7.6 9H7c-.833 0-1.542.292-2.125.875A2.893 2.893 0 0 0 4 12c0 .833.292 1.542.875 2.125A2.893 2.893 0 0 0 7 15h4v2Zm-3-4v-2h1.625l1.975 2H8Z" })));
2918
+ const LinkOffIcon = SvgLinkOff;
2919
+ const SvgOpenInNew = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
2920
+ maskType: "alpha"
2921
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M3 21V3h9v2H5v14h14v-7h2v9H3Zm6.7-5.3-1.4-1.4L17.6 5H14V3h7v7h-2V6.4l-9.3 9.3Z" })));
2922
+ const OpenInNewIcon = SvgOpenInNew;
2923
+ const SvgArrowDropDown = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
2924
+ maskType: "alpha"
2925
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "m12 15-5-5h10l-5 5Z" })));
2926
+ const DropDownIcon = SvgArrowDropDown;
2927
+ const editorRoot = "_editorRoot_gm91f_47";
2928
+ const editorWrapper = "_editorWrapper_gm91f_141";
2929
+ const nestedListItem = "_nestedListItem_gm91f_145";
2930
+ const toolbarRoot = "_toolbarRoot_gm91f_149";
2931
+ const toolbarModeSwitch = "_toolbarModeSwitch_gm91f_170";
2932
+ const toolbarToggleItem = "_toolbarToggleItem_gm91f_179";
2933
+ const toolbarGroupOfGroups = "_toolbarGroupOfGroups_gm91f_189";
2934
+ const toolbarToggleSingleGroup = "_toolbarToggleSingleGroup_gm91f_193";
2935
+ const toolbarButton = "_toolbarButton_gm91f_207";
2936
+ const toolbarNodeKindSelectContainer = "_toolbarNodeKindSelectContainer_gm91f_236";
2937
+ const toolbarButtonDropdownContainer = "_toolbarButtonDropdownContainer_gm91f_237";
2938
+ const toolbarCodeBlockLanguageSelectContent = "_toolbarCodeBlockLanguageSelectContent_gm91f_238";
2939
+ const toolbarNodeKindSelectTrigger = "_toolbarNodeKindSelectTrigger_gm91f_252";
2940
+ const toolbarButtonSelectTrigger = "_toolbarButtonSelectTrigger_gm91f_253";
2941
+ const toolbarCodeBlockLanguageSelectTrigger = "_toolbarCodeBlockLanguageSelectTrigger_gm91f_286";
2942
+ const toolbarNodeKindSelectItem = "_toolbarNodeKindSelectItem_gm91f_292";
2943
+ const toolbarNodeKindSelectDropdownArrow = "_toolbarNodeKindSelectDropdownArrow_gm91f_315";
2944
+ const contentEditable = "_contentEditable_gm91f_319";
2945
+ const sandpackWrapper = "_sandpackWrapper_gm91f_327";
2946
+ const frontmatterWrapper = "_frontmatterWrapper_gm91f_331";
2947
+ const frontmatterToggleButton = "_frontmatterToggleButton_gm91f_341";
2948
+ const frontmatterEditorTable = "_frontmatterEditorTable_gm91f_349";
2949
+ const iconButton = "_iconButton_gm91f_367";
2950
+ const frontmatterInput = "_frontmatterInput_gm91f_373";
2951
+ const primaryButton = "_primaryButton_gm91f_388";
2952
+ const linkDialogEditForm = "_linkDialogEditForm_gm91f_398";
2953
+ const linkDialogInputContainer = "_linkDialogInputContainer_gm91f_404";
2954
+ const linkDialogInputWrapper = "_linkDialogInputWrapper_gm91f_410";
2955
+ const linkDialogInput = "_linkDialogInput_gm91f_404";
2956
+ const linkDialogAutocompleteContainer = "_linkDialogAutocompleteContainer_gm91f_440";
2957
+ const linkDialogAnchor = "_linkDialogAnchor_gm91f_485";
2958
+ const linkDialogPopoverContent = "_linkDialogPopoverContent_gm91f_499";
2959
+ const tableColumnEditorPopoverContent = "_tableColumnEditorPopoverContent_gm91f_499";
2960
+ const dialogContent = "_dialogContent_gm91f_499";
2961
+ const linkDialogPreviewAnchor = "_linkDialogPreviewAnchor_gm91f_513";
2962
+ const tooltipContent = "_tooltipContent_gm91f_535";
2963
+ const actionButton = "_actionButton_gm91f_549";
2964
+ const primaryActionButton = "_primaryActionButton_gm91f_555";
2965
+ const tableEditor = "_tableEditor_gm91f_564";
2966
+ const toolCell = "_toolCell_gm91f_575";
2967
+ const tableColumnEditorTrigger = "_tableColumnEditorTrigger_gm91f_592";
2968
+ const tableRowEditorTrigger = "_tableRowEditorTrigger_gm91f_592";
2969
+ const addRowButton = "_addRowButton_gm91f_592";
2970
+ const addColumnButton = "_addColumnButton_gm91f_592";
2971
+ const tableColumnEditorToolbar = "_tableColumnEditorToolbar_gm91f_626";
2972
+ const toggleGroupRoot = "_toggleGroupRoot_gm91f_638";
2973
+ const tableToolsColumn = "_tableToolsColumn_gm91f_655";
2974
+ const leftAlignedCell = "_leftAlignedCell_gm91f_663";
2975
+ const rightAlignedCell = "_rightAlignedCell_gm91f_667";
2976
+ const centeredCell = "_centeredCell_gm91f_671";
2977
+ const dialogOverlay = "_dialogOverlay_gm91f_699";
2978
+ const overlayShow = "_overlayShow_gm91f_1";
2979
+ const contentShow = "_contentShow_gm91f_1";
2980
+ const styles = {
2981
+ editorRoot,
2982
+ editorWrapper,
2983
+ nestedListItem,
2984
+ toolbarRoot,
2985
+ toolbarModeSwitch,
2986
+ toolbarToggleItem,
2987
+ toolbarGroupOfGroups,
2988
+ toolbarToggleSingleGroup,
2989
+ toolbarButton,
2990
+ toolbarNodeKindSelectContainer,
2991
+ toolbarButtonDropdownContainer,
2992
+ toolbarCodeBlockLanguageSelectContent,
2993
+ toolbarNodeKindSelectTrigger,
2994
+ toolbarButtonSelectTrigger,
2995
+ toolbarCodeBlockLanguageSelectTrigger,
2996
+ toolbarNodeKindSelectItem,
2997
+ toolbarNodeKindSelectDropdownArrow,
2998
+ contentEditable,
2999
+ sandpackWrapper,
3000
+ frontmatterWrapper,
3001
+ frontmatterToggleButton,
3002
+ frontmatterEditorTable,
3003
+ iconButton,
3004
+ frontmatterInput,
3005
+ primaryButton,
3006
+ linkDialogEditForm,
3007
+ linkDialogInputContainer,
3008
+ linkDialogInputWrapper,
3009
+ linkDialogInput,
3010
+ linkDialogAutocompleteContainer,
3011
+ linkDialogAnchor,
3012
+ linkDialogPopoverContent,
3013
+ tableColumnEditorPopoverContent,
3014
+ dialogContent,
3015
+ linkDialogPreviewAnchor,
3016
+ tooltipContent,
3017
+ actionButton,
3018
+ primaryActionButton,
3019
+ tableEditor,
3020
+ toolCell,
3021
+ tableColumnEditorTrigger,
3022
+ tableRowEditorTrigger,
3023
+ addRowButton,
3024
+ addColumnButton,
3025
+ tableColumnEditorToolbar,
3026
+ toggleGroupRoot,
3027
+ tableToolsColumn,
3028
+ leftAlignedCell,
3029
+ rightAlignedCell,
3030
+ centeredCell,
3031
+ dialogOverlay,
3032
+ overlayShow,
3033
+ contentShow
3034
+ };
3035
+ createCommand();
3036
+ const MAX_SUGGESTIONS$1 = 20;
3037
+ function LinkEditForm({ initialUrl, onSubmit, onCancel, linkAutocompleteSuggestions }) {
3038
+ const [items, setItems] = React__default.useState(linkAutocompleteSuggestions.slice(0, MAX_SUGGESTIONS$1));
3039
+ const { isOpen, getToggleButtonProps, getMenuProps, getInputProps, highlightedIndex, getItemProps, selectedItem } = useCombobox({
3040
+ initialInputValue: initialUrl,
3041
+ onInputValueChange({ inputValue }) {
3042
+ inputValue = (inputValue == null ? void 0 : inputValue.toLowerCase()) || "";
3043
+ const matchingItems = [];
3044
+ for (const url of linkAutocompleteSuggestions) {
3045
+ if (url.toLowerCase().includes(inputValue)) {
3046
+ matchingItems.push(url);
3047
+ if (matchingItems.length >= MAX_SUGGESTIONS$1) {
3048
+ break;
3049
+ }
3050
+ }
3051
+ }
3052
+ setItems(matchingItems);
3053
+ },
3054
+ items,
3055
+ itemToString(item) {
3056
+ return item ?? "";
3057
+ }
3058
+ });
3059
+ const onSubmitEH = (e) => {
3060
+ e.preventDefault();
3061
+ onSubmit(selectedItem || "");
3062
+ };
3063
+ const onKeyDownEH = React__default.useCallback(
3064
+ (e) => {
3065
+ var _a;
3066
+ if (e.key === "Escape") {
3067
+ (_a = e.target.form) == null ? void 0 : _a.reset();
3068
+ } else if (e.key === "Enter" && (!isOpen || items.length === 0)) {
3069
+ e.preventDefault();
3070
+ onSubmit(e.target.value);
3071
+ }
3072
+ },
3073
+ [isOpen, items, onSubmit]
3074
+ );
3075
+ const downshiftInputProps = getInputProps();
3076
+ const inputProps = {
3077
+ ...downshiftInputProps,
3078
+ onKeyDown: (e) => {
3079
+ onKeyDownEH(e);
3080
+ downshiftInputProps.onKeyDown(e);
3081
+ }
3082
+ };
3083
+ const dropdownIsVisible = isOpen && items.length > 0;
3084
+ return /* @__PURE__ */ React__default.createElement("form", { onSubmit: onSubmitEH, onReset: onCancel, className: classNames(styles.linkDialogEditForm) }, /* @__PURE__ */ React__default.createElement("div", { className: styles.linkDialogInputContainer }, /* @__PURE__ */ React__default.createElement("div", { "data-visible-dropdown": dropdownIsVisible, className: styles.linkDialogInputWrapper }, /* @__PURE__ */ React__default.createElement("input", { className: styles.linkDialogInput, ...inputProps, autoFocus: true, size: 30, "data-editor-dialog": true }), /* @__PURE__ */ React__default.createElement("button", { "aria-label": "toggle menu", type: "button", ...getToggleButtonProps() }, /* @__PURE__ */ React__default.createElement(DropDownIcon, null))), /* @__PURE__ */ React__default.createElement("div", { className: styles.linkDialogAutocompleteContainer }, /* @__PURE__ */ React__default.createElement("ul", { ...getMenuProps(), "data-visible": dropdownIsVisible }, items.map((item, index2) => /* @__PURE__ */ React__default.createElement(
3085
+ "li",
3086
+ {
3087
+ "data-selected": selectedItem === item,
3088
+ "data-highlighted": highlightedIndex === index2,
3089
+ key: `${item}${index2}`,
3090
+ ...getItemProps({ item, index: index2 })
3091
+ },
3092
+ item
3093
+ ))))), /* @__PURE__ */ React__default.createElement(ActionButton$1, { type: "submit", title: "Set URL", "aria-label": "Set URL" }, /* @__PURE__ */ React__default.createElement(CheckIcon, null)), /* @__PURE__ */ React__default.createElement(ActionButton$1, { type: "reset", title: "Cancel change", "aria-label": "Cancel change" }, /* @__PURE__ */ React__default.createElement(CloseIcon, null)));
3094
+ }
3095
+ function LinkDialogPlugin() {
3096
+ const [editorRootElementRef] = useEmitterValues("editorRootElementRef");
3097
+ const publishWindowChange = usePublisher("onWindowChange");
3098
+ const [linkDialogState, linkAutocompleteSuggestions, activeEditor] = useEmitterValues(
3099
+ "linkDialogState",
3100
+ "linkAutocompleteSuggestions",
3101
+ "activeEditor"
3102
+ );
3103
+ const updateLinkUrl = usePublisher("updateLinkUrl");
3104
+ const cancelLinkEdit = usePublisher("cancelLinkEdit");
3105
+ const switchFromPreviewToLinkEdit = usePublisher("switchFromPreviewToLinkEdit");
3106
+ const removeLink = usePublisher("removeLink");
3107
+ const applyLinkChanges = usePublisher("applyLinkChanges");
3108
+ React__default.useEffect(() => {
3109
+ const update = () => {
3110
+ activeEditor == null ? void 0 : activeEditor.getEditorState().read(() => {
3111
+ publishWindowChange(true);
3112
+ });
3113
+ };
3114
+ window.addEventListener("resize", update);
3115
+ window.addEventListener("scroll", update);
3116
+ return () => {
3117
+ window.removeEventListener("resize", update);
3118
+ window.removeEventListener("scroll", update);
3119
+ };
3120
+ }, [activeEditor, publishWindowChange]);
3121
+ const [copyUrlTooltipOpen, setCopyUrlTooltipOpen] = React__default.useState(false);
3122
+ const theRect = linkDialogState == null ? void 0 : linkDialogState.rectangle;
3123
+ const onSubmitEH = React__default.useCallback(
3124
+ (url) => {
3125
+ updateLinkUrl(url);
3126
+ applyLinkChanges(true);
3127
+ },
3128
+ [applyLinkChanges, updateLinkUrl]
3129
+ );
3130
+ const urlIsExternal = linkDialogState.type === "preview" && linkDialogState.url.startsWith("http");
3131
+ return /* @__PURE__ */ React__default.createElement(RadixPopover.Root, { open: linkDialogState.type !== "inactive" }, /* @__PURE__ */ React__default.createElement(
3132
+ RadixPopover.Anchor,
3133
+ {
3134
+ "data-visible": linkDialogState.type === "edit",
3135
+ className: styles.linkDialogAnchor,
3136
+ style: {
3137
+ top: theRect == null ? void 0 : theRect.top,
3138
+ left: theRect == null ? void 0 : theRect.left,
3139
+ width: theRect == null ? void 0 : theRect.width,
3140
+ height: theRect == null ? void 0 : theRect.height
3141
+ }
3142
+ }
3143
+ ), /* @__PURE__ */ React__default.createElement(RadixPopover.Portal, { container: editorRootElementRef == null ? void 0 : editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(
3144
+ RadixPopover.Content,
3145
+ {
3146
+ className: classNames(styles.linkDialogPopoverContent),
3147
+ sideOffset: 5,
3148
+ onOpenAutoFocus: (e) => e.preventDefault(),
3149
+ key: linkDialogState.linkNodeKey
3150
+ },
3151
+ linkDialogState.type === "edit" && /* @__PURE__ */ React__default.createElement(
3152
+ LinkEditForm,
3153
+ {
3154
+ initialUrl: linkDialogState.url,
3155
+ onSubmit: onSubmitEH,
3156
+ onCancel: cancelLinkEdit.bind(null, true),
3157
+ linkAutocompleteSuggestions
3158
+ }
3159
+ ),
3160
+ linkDialogState.type === "preview" && /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(
3161
+ "a",
3162
+ {
3163
+ className: styles.linkDialogPreviewAnchor,
3164
+ href: linkDialogState.url,
3165
+ ...urlIsExternal ? { target: "_blank", rel: "noreferrer" } : {},
3166
+ title: urlIsExternal ? `Open ${linkDialogState.url} in new window` : linkDialogState.url
3167
+ },
3168
+ /* @__PURE__ */ React__default.createElement("span", null, linkDialogState.url),
3169
+ urlIsExternal && /* @__PURE__ */ React__default.createElement(OpenInNewIcon, null)
3170
+ ), /* @__PURE__ */ React__default.createElement(ActionButton$1, { onClick: () => switchFromPreviewToLinkEdit(true), title: "Edit link URL", "aria-label": "Edit link URL" }, /* @__PURE__ */ React__default.createElement(EditIcon, null)), /* @__PURE__ */ React__default.createElement(Tooltip.Provider, null, /* @__PURE__ */ React__default.createElement(Tooltip.Root, { open: copyUrlTooltipOpen }, /* @__PURE__ */ React__default.createElement(Tooltip.Trigger, { asChild: true }, /* @__PURE__ */ React__default.createElement(
3171
+ ActionButton$1,
3172
+ {
3173
+ title: "Copy to clipboard",
3174
+ "aria-label": "Copy link URL",
3175
+ onClick: () => {
3176
+ void window.navigator.clipboard.writeText(linkDialogState.url).then(() => {
3177
+ setCopyUrlTooltipOpen(true);
3178
+ setTimeout(() => setCopyUrlTooltipOpen(false), 1e3);
3179
+ });
3180
+ }
3181
+ },
3182
+ copyUrlTooltipOpen ? /* @__PURE__ */ React__default.createElement(CheckIcon, null) : /* @__PURE__ */ React__default.createElement(CopyIcon, null)
3183
+ )), /* @__PURE__ */ React__default.createElement(Tooltip.Portal, { container: editorRootElementRef == null ? void 0 : editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(Tooltip.Content, { className: classNames(styles.tooltipContent), sideOffset: 5 }, "Copied!", /* @__PURE__ */ React__default.createElement(Tooltip.Arrow, null))))), /* @__PURE__ */ React__default.createElement(ActionButton$1, { title: "Remove link", "aria-label": "Remove link", onClick: () => removeLink(true) }, /* @__PURE__ */ React__default.createElement(LinkOffIcon, null)))
3184
+ )));
3185
+ }
3186
+ const ActionButton$1 = React__default.forwardRef(({ className, ...props }, ref) => {
3187
+ return /* @__PURE__ */ React__default.createElement("button", { className: classNames(styles.actionButton, className), ref, ...props });
3188
+ });
3189
+ function getElementNodesInSelection(selection) {
3190
+ const nodesInSelection = selection.getNodes();
3191
+ if (nodesInSelection.length === 0) {
3192
+ return /* @__PURE__ */ new Set([selection.anchor.getNode().getParentOrThrow(), selection.focus.getNode().getParentOrThrow()]);
3193
+ }
3194
+ return new Set(nodesInSelection.map((n) => $isElementNode(n) ? n : n.getParentOrThrow()));
3195
+ }
3196
+ function isIndentPermitted(maxDepth) {
3197
+ const selection = $getSelection();
3198
+ if (!$isRangeSelection(selection)) {
3199
+ return false;
3200
+ }
3201
+ const elementNodesInSelection = getElementNodesInSelection(selection);
3202
+ let totalDepth = 0;
3203
+ for (const elementNode of elementNodesInSelection) {
3204
+ if ($isListNode(elementNode)) {
3205
+ totalDepth = Math.max($getListDepth(elementNode) + 1, totalDepth);
3206
+ } else if ($isListItemNode(elementNode)) {
3207
+ const parent = elementNode.getParent();
3208
+ if ((parent == null ? void 0 : parent.getChildren().length) === 1) {
3209
+ const grandParentListItem = parent == null ? void 0 : parent.getParent();
3210
+ if ($isListItemNode(grandParentListItem) && grandParentListItem.getChildren().length === 1) {
3211
+ return false;
3212
+ }
3213
+ }
3214
+ if (!$isListNode(parent)) {
3215
+ throw new Error("ListMaxIndentLevelPlugin: A ListItemNode must have a ListNode for a parent.");
3216
+ }
3217
+ totalDepth = Math.max($getListDepth(parent) + 1, totalDepth);
3218
+ }
3219
+ }
3220
+ return totalDepth <= maxDepth;
3221
+ }
3222
+ function ListMaxIndentLevelPlugin({ maxDepth }) {
3223
+ const [editor] = useLexicalComposerContext();
3224
+ useEffect(() => {
3225
+ return editor.registerCommand(INDENT_CONTENT_COMMAND, () => !isIndentPermitted(maxDepth ?? 7), COMMAND_PRIORITY_CRITICAL);
3226
+ }, [editor, maxDepth]);
3227
+ return null;
3228
+ }
3229
+ function patchMarkdownTransformers(transformers) {
3230
+ const codeTransformer = transformers.find((t) => t === CODE);
3231
+ codeTransformer.replace = (parentNode, _children, match) => {
3232
+ const codeBlockNode = $createCodeBlockNode({ code: "", language: match ? match[1] : "", meta: "" });
3233
+ parentNode.replace(codeBlockNode);
3234
+ setTimeout(() => codeBlockNode.select(), 80);
3235
+ };
3236
+ return transformers;
3237
+ }
3238
+ const PatchedMarkdownShortcutPlugin = () => {
3239
+ return /* @__PURE__ */ React__default.createElement(MarkdownShortcutPlugin, { transformers: patchMarkdownTransformers(TRANSFORMERS) });
3240
+ };
3241
+ const SharedHistoryPlugin = () => {
3242
+ const [historyState] = useEmitterValues("historyState");
3243
+ return /* @__PURE__ */ React__default.createElement(HistoryPlugin, { externalHistoryState: historyState });
3244
+ };
3245
+ const index = "";
3246
+ function DiffViewer({ oldText, newText }) {
3247
+ const diffText = formatLines(diffLines(oldText, newText), { context: 3 });
3248
+ if (diffText.trim() === "")
3249
+ return /* @__PURE__ */ React__default.createElement("div", null, "No changes");
3250
+ const [diff] = parseDiff(diffText, { nearbySequences: "zip" });
3251
+ return /* @__PURE__ */ React__default.createElement(Diff, { viewType: "split", diffType: "modify", hunks: diff.hunks || [] }, (hunks) => hunks.map((hunk) => /* @__PURE__ */ React__default.createElement(Hunk, { key: hunk.content, hunk })));
3252
+ }
3253
+ function MarkdownDiffView() {
3254
+ const [markdown2, headMarkdown] = useEmitterValues("markdownSource", "headMarkdown");
3255
+ return /* @__PURE__ */ React__default.createElement(DiffViewer, { oldText: headMarkdown, newText: markdown2 });
3256
+ }
3257
+ const ViewModeToggler = ({ children }) => {
3258
+ const [viewMode] = useEmitterValues("viewMode");
3259
+ return /* @__PURE__ */ React__default.createElement("div", null, /* @__PURE__ */ React__default.createElement("div", { style: { display: viewMode === "editor" ? "block" : "none" } }, children), viewMode === "diff" ? /* @__PURE__ */ React__default.createElement(MarkdownDiffView, null) : null, viewMode === "markdown" ? /* @__PURE__ */ React__default.createElement(SourceEditor, null) : null);
3260
+ };
3261
+ const SourceEditor = () => {
3262
+ const [markdown$1] = useEmitterValues("markdownSource");
3263
+ const updateMarkdown = usePublisher("markdownSource");
3264
+ const codeMirrorRef = React__default.useRef(null);
3265
+ return /* @__PURE__ */ React__default.createElement("div", null, /* @__PURE__ */ React__default.createElement(SandpackProvider, null, /* @__PURE__ */ React__default.createElement(
3266
+ CodeEditor,
3267
+ {
3268
+ showLineNumbers: true,
3269
+ additionalLanguages: [{ name: "markdown", extensions: ["md"], language: markdown() }],
3270
+ initMode: "lazy",
3271
+ filePath: `file.md`,
3272
+ code: markdown$1,
3273
+ onCodeUpdate: updateMarkdown,
3274
+ ref: codeMirrorRef
3275
+ }
3276
+ )));
3277
+ };
3278
+ const InstantTooltip = React__default.forwardRef(({ title, children }, ref) => {
3279
+ const [editorRootElementRef] = useEmitterValues("editorRootElementRef");
3280
+ return /* @__PURE__ */ React__default.createElement(Tooltip.Provider, { delayDuration: 100 }, /* @__PURE__ */ React__default.createElement(Tooltip.Root, null, /* @__PURE__ */ React__default.createElement(Tooltip.Trigger, { ref, asChild: true }, /* @__PURE__ */ React__default.createElement("span", null, children)), /* @__PURE__ */ React__default.createElement(Tooltip.Portal, { container: editorRootElementRef == null ? void 0 : editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(Tooltip.Content, { className: classNames(styles.tooltipContent), sideOffset: 10 }, title))));
3281
+ });
3282
+ const SelectItem = React__default.forwardRef(
3283
+ ({ children, className, ...props }, forwardedRef) => {
3284
+ return /* @__PURE__ */ React__default.createElement(Select.Item, { ...props, ref: forwardedRef, className: classNames(className, styles.toolbarNodeKindSelectItem) }, /* @__PURE__ */ React__default.createElement(Select.ItemText, null, children));
3285
+ }
3286
+ );
3287
+ const SelectTrigger = ({ title, placeholder, className }) => {
3288
+ return /* @__PURE__ */ React__default.createElement(InstantTooltip, { title }, /* @__PURE__ */ React__default.createElement(Select.Trigger, { "aria-label": placeholder, className: classNames(styles.toolbarNodeKindSelectTrigger, className) }, /* @__PURE__ */ React__default.createElement(Select.Value, { placeholder }), /* @__PURE__ */ React__default.createElement(Select.Icon, { className: styles.toolbarNodeKindSelectDropdownArrow }, /* @__PURE__ */ React__default.createElement(DropDownIcon, null))));
3289
+ };
3290
+ const SelectContent = ({
3291
+ children,
3292
+ className = styles.toolbarNodeKindSelectContainer
3293
+ }) => {
3294
+ const [editorRootElementRef] = useEmitterValues("editorRootElementRef");
3295
+ return /* @__PURE__ */ React__default.createElement(Select.Portal, { container: editorRootElementRef == null ? void 0 : editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(Select.Content, { className, onCloseAutoFocus: (e) => e.preventDefault(), position: "popper" }, /* @__PURE__ */ React__default.createElement(Select.Viewport, null, children)));
3296
+ };
3297
+ const SelectButtonTrigger = ({
3298
+ children,
3299
+ title,
3300
+ className
3301
+ }) => {
3302
+ return /* @__PURE__ */ React__default.createElement(InstantTooltip, { title }, /* @__PURE__ */ React__default.createElement(Select.Trigger, { className: classNames(styles.toolbarButtonSelectTrigger, className) }, children, /* @__PURE__ */ React__default.createElement(Select.Icon, { className: styles.toolbarNodeKindSelectDropdownArrow }, /* @__PURE__ */ React__default.createElement(DropDownIcon, null))));
3303
+ };
3304
+ function CodeBlockLanguageSelect() {
3305
+ const [activeEditorType, activeEditor, codeBlockLanguages] = useEmitterValues("activeEditorType", "activeEditor", "codeBlockLanguages");
3306
+ const nodeLanguage = React__default.useMemo(() => {
3307
+ let language;
3308
+ activeEditor.getEditorState().read(() => {
3309
+ const node = $getNodeByKey(activeEditorType.nodeKey);
3310
+ language = node.getLanguage();
3311
+ });
3312
+ return language;
3313
+ }, [activeEditor, activeEditorType]);
3314
+ return /* @__PURE__ */ React__default.createElement(
3315
+ Select.Root,
3316
+ {
3317
+ value: nodeLanguage,
3318
+ onValueChange: (language) => {
3319
+ activeEditor.update(() => {
3320
+ const node = $getNodeByKey(activeEditorType.nodeKey);
3321
+ node.setLanguage(language);
3322
+ setTimeout(() => {
3323
+ node.select();
3324
+ }, 80);
3325
+ });
3326
+ }
3327
+ },
3328
+ /* @__PURE__ */ React__default.createElement(SelectTrigger, { title: "Change code block language", placeholder: "Language", className: styles.toolbarCodeBlockLanguageSelectTrigger }),
3329
+ /* @__PURE__ */ React__default.createElement(SelectContent, { className: styles.toolbarCodeBlockLanguageSelectContent }, Object.entries(codeBlockLanguages).map(([value, label]) => /* @__PURE__ */ React__default.createElement(SelectItem, { key: value, value }, label)))
3330
+ );
3331
+ }
3332
+ const SvgDelete = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
3333
+ maskType: "alpha"
3334
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M5 21V6H4V4h5V3h6v1h5v2h-1v15H5Zm2-2h10V6H7v13Zm2-2h2V8H9v9Zm4 0h2V8h-2v9Z" })));
3335
+ const DeleteIcon = SvgDelete;
3336
+ const SvgCode = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
3337
+ maskType: "alpha"
3338
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "m8 18-6-6 6-6 1.425 1.425-4.6 4.6L9.4 16.6 8 18Zm8 0-1.425-1.425 4.6-4.6L14.6 7.4 16 6l6 6-6 6Z" })));
3339
+ const CodeIcon = SvgCode;
3340
+ const SvgDeployedCode = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
3341
+ maskType: "alpha"
3342
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "m5 15.95 6 3.475v-6.85L5 9.1v6.85Zm8 3.475 6-3.475V9.1l-6 3.475v6.85Zm-6.925-12L12 10.85l5.925-3.425L12 4 6.075 7.425ZM3 17.125V6.875L12 1.7l9 5.175v10.25L12 22.3l-9-5.175Z" })));
3343
+ const LiveCodeIcon = SvgDeployedCode;
3344
+ const SvgDifference = (props) => /* @__PURE__ */ React.createElement("svg", { width: 25, height: 24, viewBox: "0 0 25 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "mask0_318_257", style: {
3345
+ maskType: "alpha"
3346
+ }, maskUnits: "userSpaceOnUse", x: 0, y: 0, width: 25, height: 24 }, /* @__PURE__ */ React.createElement("rect", { x: 0.929688, width: 24, height: 24, fill: "#D9D9D9" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#mask0_318_257)" }, /* @__PURE__ */ React.createElement("path", { d: "M12.4297 12H14.4297V10H16.4297V8H14.4297V6H12.4297V8H10.4297V10H12.4297V12ZM10.4297 16H16.4297V14H10.4297V16ZM5.92969 20V2H14.9297L20.9297 8V20H5.92969ZM7.92969 18H18.9297V9L13.9297 4H7.92969V18Z", fill: "currentColor" })));
3347
+ const DifferenceIcon = SvgDifference;
3348
+ const SvgFormatBold = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
3349
+ maskType: "alpha"
3350
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M6.8 19V5h5.525c1.083 0 2.083.333 3 1 .917.667 1.375 1.592 1.375 2.775 0 .85-.192 1.504-.575 1.962-.383.459-.742.788-1.075.988.417.183.88.525 1.388 1.025.508.5.762 1.25.762 2.25 0 1.483-.542 2.521-1.625 3.113-1.083.591-2.1.887-3.05.887H6.8Zm3.025-2.8h2.6c.8 0 1.287-.204 1.462-.613.175-.408.263-.704.263-.887 0-.183-.088-.48-.263-.888-.175-.408-.687-.612-1.537-.612H9.825v3Zm0-5.7h2.325c.55 0 .95-.142 1.2-.425a1.4 1.4 0 0 0 .375-.95c0-.4-.142-.725-.425-.975-.283-.25-.65-.375-1.1-.375H9.825V10.5Z" })));
3351
+ const BoldIcon = SvgFormatBold;
3352
+ const SvgFormatItalic = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
3353
+ maskType: "alpha"
3354
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M5 19v-2.5h4l3-9H8V5h10v2.5h-3.5l-3 9H15V19H5Z" })));
3355
+ const ItalicIcon = SvgFormatItalic;
3356
+ const SvgFormatListBulleted = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
3357
+ maskType: "alpha"
3358
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M9 19v-2h12v2H9Zm0-6v-2h12v2H9Zm0-6V5h12v2H9ZM5 20a1.93 1.93 0 0 1-1.413-.587A1.928 1.928 0 0 1 3 18c0-.55.196-1.021.587-1.413A1.928 1.928 0 0 1 5 16c.55 0 1.02.196 1.412.587.392.392.588.863.588 1.413s-.196 1.021-.588 1.413A1.925 1.925 0 0 1 5 20Zm0-6c-.55 0-1.021-.196-1.413-.588A1.925 1.925 0 0 1 3 12c0-.55.196-1.021.587-1.413A1.928 1.928 0 0 1 5 10c.55 0 1.02.196 1.412.587.392.392.588.863.588 1.413s-.196 1.02-.588 1.412A1.923 1.923 0 0 1 5 14Zm0-6c-.55 0-1.021-.196-1.413-.588A1.925 1.925 0 0 1 3 6c0-.55.196-1.02.587-1.412A1.927 1.927 0 0 1 5 4c.55 0 1.02.196 1.412.588C6.804 4.979 7 5.45 7 6c0 .55-.196 1.02-.588 1.412A1.923 1.923 0 0 1 5 8Z" })));
3359
+ const BulletedListIcon = SvgFormatListBulleted;
3360
+ const SvgFormatListNumbered = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
3361
+ maskType: "alpha"
3362
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M3 22v-1.5h2.5v-.75H4v-1.5h1.5v-.75H3V16h4v2.25L6 19l1 .75V22H3Zm0-7v-3.75h2.5v-.75H3V9h4v3.75H4.5v.75H7V15H3Zm1.5-7V3.5H3V2h3v6H4.5ZM9 19v-2h12v2H9Zm0-6v-2h12v2H9Zm0-6V5h12v2H9Z" })));
3363
+ const NumberedListIcon = SvgFormatListNumbered;
3364
+ const SvgFormatUnderlined = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
3365
+ maskType: "alpha"
3366
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M5 21v-2h14v2H5Zm7-4c-1.683 0-2.992-.525-3.925-1.575-.933-1.05-1.4-2.442-1.4-4.175V3H9.25v8.4c0 .933.233 1.692.7 2.275.467.583 1.15.875 2.05.875.9 0 1.583-.292 2.05-.875.467-.583.7-1.342.7-2.275V3h2.575v8.25c0 1.733-.467 3.125-1.4 4.175C14.992 16.475 13.683 17 12 17Z" })));
3367
+ const UnderlinedIcon = SvgFormatUnderlined;
3368
+ const SvgFrameSource = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
3369
+ maskType: "alpha"
3370
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M3 21v-6h2v4h4v2H3Zm12 0v-2h4v-4h2v6h-6Zm-6.4-5.4L5 12l3.6-3.6L10 9.825 7.825 12 10 14.175 8.6 15.6Zm6.8 0L14 14.175 16.175 12 14 9.825 15.4 8.4 19 12l-3.6 3.6ZM3 9V3h6v2H5v4H3Zm16 0V5h-4V3h6v6h-2Z" })));
3371
+ const FrameSourceIcon = SvgFrameSource;
3372
+ const SvgFrontmatter = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
3373
+ maskType: "alpha"
3374
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M5 7h4v2H5z" }), /* @__PURE__ */ React.createElement("path", { d: "M5 7h4v2H5zm0 7h4v2H5z" }), /* @__PURE__ */ React.createElement("path", { d: "M5 14h4v2H5zm5-7h4v2h-4z" }), /* @__PURE__ */ React.createElement("path", { d: "M10 7h4v2h-4zm0 7h4v2h-4z" }), /* @__PURE__ */ React.createElement("path", { d: "M10 14h4v2h-4zm5-7h4v2h-4z" }), /* @__PURE__ */ React.createElement("path", { d: "M15 7h4v2h-4zm0 7h4v2h-4z" }), /* @__PURE__ */ React.createElement("path", { d: "M15 14h4v2h-4z" })));
3375
+ const FrontmatterIcon = SvgFrontmatter;
3376
+ const SvgHorizontalRule = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
3377
+ maskType: "alpha"
3378
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M4 13v-2h16v2H4Z" })));
3379
+ const HorizontalRuleIcon = SvgHorizontalRule;
3380
+ const SvgLink = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
3381
+ maskType: "alpha"
3382
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M11 17H7c-1.383 0-2.562-.488-3.537-1.463C2.488 14.562 2 13.383 2 12s.488-2.563 1.463-3.538C4.438 7.487 5.617 7 7 7h4v2H7c-.833 0-1.542.292-2.125.875A2.893 2.893 0 0 0 4 12c0 .833.292 1.542.875 2.125A2.893 2.893 0 0 0 7 15h4v2Zm-3-4v-2h8v2H8Zm5 4v-2h4c.833 0 1.542-.292 2.125-.875A2.893 2.893 0 0 0 20 12c0-.833-.292-1.542-.875-2.125A2.893 2.893 0 0 0 17 9h-4V7h4c1.383 0 2.563.487 3.538 1.462C21.513 9.437 22 10.617 22 12s-.487 2.562-1.462 3.537C19.563 16.512 18.383 17 17 17h-4Z" })));
3383
+ const LinkIcon = SvgLink;
3384
+ const SvgMarkdown = (props) => /* @__PURE__ */ React.createElement("svg", { width: 24, height: 24, viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "mask0_46_56", style: {
3385
+ maskType: "alpha"
3386
+ }, maskUnits: "userSpaceOnUse", x: 0, y: 0, width: 24, height: 24 }, /* @__PURE__ */ React.createElement("rect", { width: 24, height: 24, fill: "#D9D9D9" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#mask0_46_56)" }, /* @__PURE__ */ React.createElement("path", { d: "M19 19L14 14L15.4 12.575L18 15.175V5H20V15.175L22.6 12.575L24 14L19 19Z", fill: "currentColor" }), /* @__PURE__ */ React.createElement("path", { d: "M13 19H10.5V9L6.5 15L2.5 9V19H0V5H2.5L6.5 11L10.5 5H13V19Z", fill: "currentColor" })));
3387
+ const MarkdownIcon = SvgMarkdown;
3388
+ const SvgRichText = (props) => /* @__PURE__ */ React.createElement("svg", { width: 24, height: 24, viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "mask0_318_249", style: {
3389
+ maskType: "alpha"
3390
+ }, maskUnits: "userSpaceOnUse", x: 0, y: 0, width: 24, height: 24 }, /* @__PURE__ */ React.createElement("rect", { width: 24, height: 24, fill: "#D9D9D9" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#mask0_318_249)" }, /* @__PURE__ */ React.createElement("path", { d: "M5 21V19H19V21H5Z", fill: "currentColor" }), /* @__PURE__ */ React.createElement("path", { d: "M6.80005 17V3H12.325C13.4084 3 14.4084 3.33333 15.325 4C16.2417 4.66667 16.7001 5.59167 16.7001 6.775C16.7001 7.625 16.5084 8.279 16.125 8.737C15.7417 9.19567 15.3834 9.525 15.05 9.725C15.4667 9.90833 15.9294 10.25 16.438 10.75C16.946 11.25 17.2001 12 17.2001 13C17.2001 14.4833 16.6584 15.521 15.575 16.113C14.4917 16.7043 13.475 17 12.525 17H6.80005ZM9.82505 14.2H12.425C13.225 14.2 13.7124 13.9957 13.887 13.587C14.0624 13.179 14.15 12.8833 14.15 12.7C14.15 12.5167 14.0624 12.2207 13.887 11.812C13.7124 11.404 13.2 11.2 12.35 11.2H9.82505V14.2ZM9.82505 8.5H12.15C12.7 8.5 13.1 8.35833 13.35 8.075C13.6 7.79167 13.725 7.475 13.725 7.125C13.725 6.725 13.5834 6.4 13.3 6.15C13.0167 5.9 12.65 5.775 12.2 5.775H9.82505V8.5Z", fill: "currentColor" })));
3391
+ const RichTextIcon = SvgRichText;
3392
+ const SvgTable = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: 24, height: 24, fill: "currentColor", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "a", width: 24, height: 24, x: 0, y: 0, maskUnits: "userSpaceOnUse", style: {
3393
+ maskType: "alpha"
3394
+ } }, /* @__PURE__ */ React.createElement("path", { d: "M0 0h24v24H0z" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#a)" }, /* @__PURE__ */ React.createElement("path", { d: "M3 21V3h18v18H3ZM5 9h14V5H5v4Zm5.325 5h3.35v-3h-3.35v3Zm0 5h3.35v-3h-3.35v3ZM5 14h3.325v-3H5v3Zm10.675 0H19v-3h-3.325v3ZM5 19h3.325v-3H5v3Zm10.675 0H19v-3h-3.325v3Z" }), /* @__PURE__ */ React.createElement("path", { d: "M8.325 9h2V5h-2v4Zm5.35 0h2V5h-2v4Z" })));
3395
+ const TableIcon = SvgTable;
3396
+ const BlockTypeSelect = () => {
3397
+ const [currentBlockType] = useEmitterValues("currentBlockType");
3398
+ const applyBlockType = usePublisher("applyBlockType");
3399
+ return /* @__PURE__ */ React__default.createElement(Select.Root, { value: currentBlockType || "", onValueChange: applyBlockType }, /* @__PURE__ */ React__default.createElement(SelectTrigger, { title: "Select block type", placeholder: "Block type" }), /* @__PURE__ */ React__default.createElement(SelectContent, null, /* @__PURE__ */ React__default.createElement(SelectItem, { value: "paragraph" }, "Paragraph"), /* @__PURE__ */ React__default.createElement(SelectItem, { value: "quote" }, "Quote"), /* @__PURE__ */ React__default.createElement(Select.Separator, null), /* @__PURE__ */ React__default.createElement(SelectItem, { value: "h1" }, "Heading 1"), /* @__PURE__ */ React__default.createElement(SelectItem, { value: "h2" }, "Heading 2"), /* @__PURE__ */ React__default.createElement(SelectItem, { value: "h3" }, "Heading 3"), /* @__PURE__ */ React__default.createElement(SelectItem, { value: "h4" }, "Heading 4"), /* @__PURE__ */ React__default.createElement(SelectItem, { value: "h5" }, "Heading 5"), /* @__PURE__ */ React__default.createElement(SelectItem, { value: "h6" }, "Heading 6"), /* @__PURE__ */ React__default.createElement(Select.Separator, null), /* @__PURE__ */ React__default.createElement(SelectItem, { value: "note" }, "Note"), /* @__PURE__ */ React__default.createElement(SelectItem, { value: "tip" }, "Tip"), /* @__PURE__ */ React__default.createElement(SelectItem, { value: "info" }, "Info"), /* @__PURE__ */ React__default.createElement(SelectItem, { value: "caution" }, "Caution"), /* @__PURE__ */ React__default.createElement(SelectItem, { value: "danger" }, "Danger")));
3400
+ };
3401
+ const SvgAddPhoto = (props) => /* @__PURE__ */ React.createElement("svg", { width: 24, height: 24, viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", ...props }, /* @__PURE__ */ React.createElement("mask", { id: "mask0_343_38", style: {
3402
+ maskType: "alpha"
3403
+ }, maskUnits: "userSpaceOnUse", x: 0, y: 0, width: 24, height: 24 }, /* @__PURE__ */ React.createElement("rect", { width: 24, height: 24, fill: "#D9D9D9" })), /* @__PURE__ */ React.createElement("g", { mask: "url(#mask0_343_38)" }, /* @__PURE__ */ React.createElement("path", { d: "M3 21V3H14V5H5V19H19V10H21V21H3ZM17 9V7H15V5H17V3H19V5H21V7H19V9H17ZM6 17H18L14.25 12L11.25 16L9 13L6 17Z", fill: "currentColor" })));
3404
+ const AddPhotoIcon = SvgAddPhoto;
3405
+ const ImageButton = React__default.forwardRef((props, forwardedRef) => {
3406
+ const [editorRootElementRef, imageAutocompleteSuggestions] = useEmitterValues("editorRootElementRef", "imageAutocompleteSuggestions");
3407
+ const [open, setOpen] = React__default.useState(false);
3408
+ const insertImage = usePublisher("insertImage");
3409
+ const onSubmit = React__default.useCallback(
3410
+ (url) => {
3411
+ insertImage(url);
3412
+ setOpen(false);
3413
+ },
3414
+ [insertImage]
3415
+ );
3416
+ return /* @__PURE__ */ React__default.createElement(Dialog.Root, { open, onOpenChange: setOpen }, /* @__PURE__ */ React__default.createElement(Dialog.Trigger, { asChild: true }, /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { className: styles.toolbarButton, ...props, ref: forwardedRef }, /* @__PURE__ */ React__default.createElement(InstantTooltip, { title: "Insert image" }, /* @__PURE__ */ React__default.createElement(AddPhotoIcon, null)))), /* @__PURE__ */ React__default.createElement(Dialog.Portal, { container: editorRootElementRef.current }, /* @__PURE__ */ React__default.createElement(Dialog.Overlay, { className: styles.dialogOverlay }), /* @__PURE__ */ React__default.createElement(Dialog.Content, { className: styles.dialogContent }, /* @__PURE__ */ React__default.createElement(ImageForm, { initialUrl: "", onSubmit, imageAutocompleteSuggestions }))));
3417
+ });
3418
+ createCommand();
3419
+ const MAX_SUGGESTIONS = 20;
3420
+ const ImageForm = ({ initialUrl, onSubmit, imageAutocompleteSuggestions }) => {
3421
+ const [items, setItems] = React__default.useState(imageAutocompleteSuggestions.slice(0, MAX_SUGGESTIONS));
3422
+ const { isOpen, getToggleButtonProps, getMenuProps, getInputProps, highlightedIndex, getItemProps, selectedItem } = useCombobox({
3423
+ initialInputValue: initialUrl,
3424
+ onInputValueChange({ inputValue }) {
3425
+ inputValue = (inputValue == null ? void 0 : inputValue.toLowerCase()) || "";
3426
+ const matchingItems = [];
3427
+ for (const url of imageAutocompleteSuggestions) {
3428
+ if (url.toLowerCase().includes(inputValue)) {
3429
+ matchingItems.push(url);
3430
+ if (matchingItems.length >= MAX_SUGGESTIONS) {
3431
+ break;
3432
+ }
3433
+ }
3434
+ }
3435
+ setItems(matchingItems);
3436
+ },
3437
+ items,
3438
+ itemToString(item) {
3439
+ return item ?? "";
3440
+ }
3441
+ });
3442
+ const onSubmitEH = (e) => {
3443
+ e.preventDefault();
3444
+ onSubmit(selectedItem || "");
3445
+ };
3446
+ const onKeyDownEH = React__default.useCallback(
3447
+ (e) => {
3448
+ var _a;
3449
+ if (e.key === "Escape") {
3450
+ (_a = e.target.form) == null ? void 0 : _a.reset();
3451
+ } else if (e.key === "Enter" && (!isOpen || items.length === 0)) {
3452
+ e.preventDefault();
3453
+ onSubmit(e.target.value);
3454
+ }
3455
+ },
3456
+ [isOpen, items, onSubmit]
3457
+ );
3458
+ const downshiftInputProps = getInputProps();
3459
+ const inputProps = {
3460
+ ...downshiftInputProps,
3461
+ onKeyDown: (e) => {
3462
+ onKeyDownEH(e);
3463
+ downshiftInputProps.onKeyDown(e);
3464
+ }
3465
+ };
3466
+ const dropdownIsVisible = isOpen && items.length > 0;
3467
+ return /* @__PURE__ */ React__default.createElement("form", { onSubmit: onSubmitEH, className: classNames(styles.linkDialogEditForm) }, /* @__PURE__ */ React__default.createElement("div", { className: styles.linkDialogInputContainer }, /* @__PURE__ */ React__default.createElement("div", { "data-visible-dropdown": dropdownIsVisible, className: styles.linkDialogInputWrapper }, /* @__PURE__ */ React__default.createElement(
3468
+ "input",
3469
+ {
3470
+ placeholder: "Paste or select an image url",
3471
+ className: styles.linkDialogInput,
3472
+ ...inputProps,
3473
+ autoFocus: true,
3474
+ size: 30,
3475
+ "data-editor-dialog": true
3476
+ }
3477
+ ), /* @__PURE__ */ React__default.createElement("button", { "aria-label": "toggle menu", type: "button", ...getToggleButtonProps() }, /* @__PURE__ */ React__default.createElement(DropDownIcon, null))), /* @__PURE__ */ React__default.createElement("div", { className: styles.linkDialogAutocompleteContainer }, /* @__PURE__ */ React__default.createElement("ul", { ...getMenuProps(), "data-visible": dropdownIsVisible }, items.map((item, index2) => /* @__PURE__ */ React__default.createElement(
3478
+ "li",
3479
+ {
3480
+ "data-selected": selectedItem === item,
3481
+ "data-highlighted": highlightedIndex === index2,
3482
+ key: `${item}${index2}`,
3483
+ ...getItemProps({ item, index: index2 })
3484
+ },
3485
+ item
3486
+ ))))), /* @__PURE__ */ React__default.createElement(ActionButton, { type: "submit", title: "Insert image", "aria-label": "Insert image", className: styles.primaryActionButton }, /* @__PURE__ */ React__default.createElement(CheckIcon, null)), /* @__PURE__ */ React__default.createElement(Dialog.Close, { className: styles.actionButton }, /* @__PURE__ */ React__default.createElement(CloseIcon, null)));
3487
+ };
3488
+ const ActionButton = React__default.forwardRef(({ className, ...props }, ref) => {
3489
+ return /* @__PURE__ */ React__default.createElement("button", { className: classNames(styles.actionButton, className), ref, ...props });
3490
+ });
3491
+ const ToggleItem = React__default.forwardRef(
3492
+ ({ title, children, className: passedClassName, ...props }, forwardedRef) => {
3493
+ return /* @__PURE__ */ React__default.createElement(RadixToolbar.ToggleItem, { className: classNames(passedClassName, styles.toolbarToggleItem), ...props, ref: forwardedRef }, /* @__PURE__ */ React__default.createElement(InstantTooltip, { title }, children));
3494
+ }
3495
+ );
3496
+ const ToolbarButton = React__default.forwardRef(
3497
+ ({ title, children, ...props }, forwardedRef) => {
3498
+ return /* @__PURE__ */ React__default.createElement(RadixToolbar.Button, { className: styles.toolbarButton, ...props, ref: forwardedRef }, /* @__PURE__ */ React__default.createElement(InstantTooltip, { title }, children));
3499
+ }
3500
+ );
3501
+ const ToggleSingleGroup = React__default.forwardRef(
3502
+ ({ children, className, ...props }, forwardedRef) => {
3503
+ return /* @__PURE__ */ React__default.createElement(
3504
+ RadixToolbar.ToggleGroup,
3505
+ {
3506
+ ...props,
3507
+ type: "single",
3508
+ ref: forwardedRef,
3509
+ className: classNames(styles.toolbarToggleSingleGroup, className)
3510
+ },
3511
+ children
3512
+ );
3513
+ }
3514
+ );
3515
+ const ToggleSingleGroupWithItem = React__default.forwardRef(({ on, title, children, ...props }, forwardedRef) => {
3516
+ return /* @__PURE__ */ React__default.createElement(ToggleSingleGroup, { ...props, value: on ? "on" : "off", ref: forwardedRef }, /* @__PURE__ */ React__default.createElement(ToggleItem, { title, value: "on" }, children));
3517
+ });
3518
+ const GroupGroup = ({ children }) => {
3519
+ return /* @__PURE__ */ React__default.createElement("div", { className: styles.toolbarGroupOfGroups }, children);
3520
+ };
3521
+ const ToolbarSeparator = RadixToolbar.ToolbarSeparator;
3522
+ const BoldItalicUnderlineButtons = () => {
3523
+ const [currentFormat] = useEmitterValues("currentFormat", "currentListType");
3524
+ const applyFormat = usePublisher("applyFormat");
3525
+ const boldIsOn = (currentFormat & IS_BOLD) !== 0;
3526
+ const italicIsOn = (currentFormat & IS_ITALIC) !== 0;
3527
+ const underlineIsOn = (currentFormat & IS_UNDERLINE) !== 0;
3528
+ const boldTitle = boldIsOn ? "Remove bold" : "Bold";
3529
+ const italicTitle = italicIsOn ? "Remove italic" : "Italic";
3530
+ const underlineTitle = underlineIsOn ? "Remove underline" : "Underline";
3531
+ return /* @__PURE__ */ React__default.createElement(GroupGroup, null, /* @__PURE__ */ React__default.createElement(ToggleSingleGroupWithItem, { title: boldTitle, "aria-label": "Bold", on: boldIsOn, onValueChange: applyFormat.bind(null, "bold") }, /* @__PURE__ */ React__default.createElement(BoldIcon, null)), /* @__PURE__ */ React__default.createElement(ToggleSingleGroupWithItem, { title: italicTitle, "aria-label": "Italic", on: italicIsOn, onValueChange: applyFormat.bind(null, "italic") }, /* @__PURE__ */ React__default.createElement(ItalicIcon, null)), /* @__PURE__ */ React__default.createElement(
3532
+ ToggleSingleGroupWithItem,
3533
+ {
3534
+ "aria-label": "Underline",
3535
+ title: underlineTitle,
3536
+ on: underlineIsOn,
3537
+ onValueChange: applyFormat.bind(null, "underline")
3538
+ },
3539
+ /* @__PURE__ */ React__default.createElement(UnderlinedIcon, { style: { transform: "translateY(2px)" } })
3540
+ ));
3541
+ };
3542
+ const CodeFormattingButton = () => {
3543
+ const [currentFormat] = useEmitterValues("currentFormat", "currentListType");
3544
+ const applyFormat = usePublisher("applyFormat");
3545
+ const codeIsOn = (currentFormat & IS_CODE) !== 0;
3546
+ const codeTitle = codeIsOn ? "Remove inline code" : "Inline code";
3547
+ return /* @__PURE__ */ React__default.createElement(GroupGroup, null, /* @__PURE__ */ React__default.createElement(ToggleSingleGroupWithItem, { title: codeTitle, "aria-label": "Inline code", on: codeIsOn, onValueChange: applyFormat.bind(null, "code") }, /* @__PURE__ */ React__default.createElement(CodeIcon, null)));
3548
+ };
3549
+ const ListButtons = () => {
3550
+ const [currentListType] = useEmitterValues("currentListType");
3551
+ const applyListType = usePublisher("applyListType");
3552
+ return /* @__PURE__ */ React__default.createElement(GroupGroup, null, /* @__PURE__ */ React__default.createElement(
3553
+ ToggleSingleGroup,
3554
+ {
3555
+ "aria-label": "List type",
3556
+ onValueChange: applyListType,
3557
+ value: currentListType || "",
3558
+ onFocus: (e) => e.preventDefault()
3559
+ },
3560
+ /* @__PURE__ */ React__default.createElement(ToggleItem, { title: "Bulleted list", value: "bullet", "aria-label": "Bulleted list" }, /* @__PURE__ */ React__default.createElement(BulletedListIcon, null)),
3561
+ /* @__PURE__ */ React__default.createElement(ToggleItem, { title: "Numbered list", value: "number", "aria-label": "Numbered list" }, /* @__PURE__ */ React__default.createElement(NumberedListIcon, null))
3562
+ ));
3563
+ };
3564
+ const LinkButton = () => {
3565
+ const openLinkEditDialog = usePublisher("openLinkEditDialog");
3566
+ return /* @__PURE__ */ React__default.createElement(ToolbarButton, { title: "Create link", onClick: openLinkEditDialog.bind(null, true) }, /* @__PURE__ */ React__default.createElement(LinkIcon, null));
3567
+ };
3568
+ const TableButton = () => {
3569
+ const insertTable = usePublisher("insertTable");
3570
+ return /* @__PURE__ */ React__default.createElement(ToolbarButton, { title: "Insert table", onClick: insertTable.bind(null, true) }, /* @__PURE__ */ React__default.createElement(TableIcon, null));
3571
+ };
3572
+ const CodeBlockButton = () => {
3573
+ const insertCodeBlock = usePublisher("insertCodeBlock");
3574
+ return /* @__PURE__ */ React__default.createElement(ToolbarButton, { title: "Insert code block", onClick: insertCodeBlock.bind(null, true) }, /* @__PURE__ */ React__default.createElement(FrameSourceIcon, null));
3575
+ };
3576
+ const HorizontalRuleButton = () => {
3577
+ const insertHorizontalRule = usePublisher("insertHorizontalRule");
3578
+ return /* @__PURE__ */ React__default.createElement(ToolbarButton, { title: "Insert horizontal rule", onClick: insertHorizontalRule.bind(null, true) }, /* @__PURE__ */ React__default.createElement(HorizontalRuleIcon, null));
3579
+ };
3580
+ const SandpackButton = () => {
3581
+ const insertSandpack = usePublisher("insertSandpack");
3582
+ const [sandpackConfig] = useEmitterValues("sandpackConfig");
3583
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, sandpackConfig.presets.length === 1 ? /* @__PURE__ */ React__default.createElement(ToolbarButton, { title: "Insert live code block", onClick: insertSandpack.bind(null, "") }, /* @__PURE__ */ React__default.createElement(LiveCodeIcon, null)) : /* @__PURE__ */ React__default.createElement(Select.Root, { value: "", onValueChange: insertSandpack }, /* @__PURE__ */ React__default.createElement(SelectButtonTrigger, { title: "Insert live code snippet" }, /* @__PURE__ */ React__default.createElement(LiveCodeIcon, null)), /* @__PURE__ */ React__default.createElement(SelectContent, { className: styles.toolbarButtonDropdownContainer }, sandpackConfig.presets.map((preset) => /* @__PURE__ */ React__default.createElement(SelectItem, { key: preset.name, value: preset.meta }, preset.label)))));
3584
+ };
3585
+ const FrontmatterButton = () => {
3586
+ const insertFrontmatter = usePublisher("insertFrontmatter");
3587
+ return /* @__PURE__ */ React__default.createElement(ToolbarButton, { title: "Insert frontmatter editor", onClick: insertFrontmatter.bind(null, true) }, /* @__PURE__ */ React__default.createElement(FrontmatterIcon, null));
3588
+ };
3589
+ const ViewModeSwitch = () => {
3590
+ const [viewMode] = useEmitterValues("viewMode", "activeEditorType");
3591
+ const setViewMode = usePublisher("viewMode");
3592
+ return /* @__PURE__ */ React__default.createElement(
3593
+ ToggleSingleGroup,
3594
+ {
3595
+ "aria-label": "View Mode",
3596
+ onValueChange: (v) => {
3597
+ if (v !== "") {
3598
+ setViewMode(v);
3599
+ }
3600
+ },
3601
+ value: viewMode,
3602
+ className: styles.toolbarModeSwitch
3603
+ },
3604
+ /* @__PURE__ */ React__default.createElement(ToggleItem, { value: "editor", "aria-label": "Rich text", title: "Rich text mode" }, /* @__PURE__ */ React__default.createElement(RichTextIcon, null)),
3605
+ /* @__PURE__ */ React__default.createElement(ToggleItem, { value: "diff", "aria-label": "View diff", title: "Diff mode" }, /* @__PURE__ */ React__default.createElement(DifferenceIcon, null)),
3606
+ /* @__PURE__ */ React__default.createElement(ToggleItem, { value: "markdown", "aria-label": "View Markdown", title: "Markdown source mode" }, /* @__PURE__ */ React__default.createElement(MarkdownIcon, null))
3607
+ );
3608
+ };
3609
+ const ToolbarComponents = {
3610
+ BlockTypeSelect,
3611
+ BoldItalicUnderlineButtons,
3612
+ CodeBlockButton,
3613
+ FrontmatterButton,
3614
+ GroupGroup,
3615
+ HorizontalRuleIcon,
3616
+ LinkButton,
3617
+ ListButtons,
3618
+ SandpackButton,
3619
+ TableButton,
3620
+ ToggleItem,
3621
+ ToggleSingleGroup,
3622
+ ToggleSingleGroupWithItem,
3623
+ ToolbarButton,
3624
+ ToolbarSeparator,
3625
+ ImageButton
3626
+ };
3627
+ const ToolbarPlugin = () => {
3628
+ const [activeEditorType, viewMode] = useEmitterValues("activeEditorType", "viewMode");
3629
+ return /* @__PURE__ */ React__default.createElement(RadixToolbar.Root, { className: styles.toolbarRoot, "aria-label": "Formatting options" }, viewMode === "editor" && (activeEditorType.type === "lexical" ? /* @__PURE__ */ React__default.createElement(RichTextButtonSet, null) : activeEditorType.type === "codeblock" ? /* @__PURE__ */ React__default.createElement(CodeBlockButtonSet, null) : /* @__PURE__ */ React__default.createElement(SandpackButtonSet, null)), /* @__PURE__ */ React__default.createElement(ToolbarSeparator, null), /* @__PURE__ */ React__default.createElement(ViewModeSwitch, null));
3630
+ };
3631
+ const CodeBlockButtonSet = () => {
3632
+ const [activeEditor, activeEditorType] = useEmitterValues("activeEditor", "activeEditorType");
3633
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(CodeBlockLanguageSelect, null), /* @__PURE__ */ React__default.createElement(
3634
+ ToolbarButton,
3635
+ {
3636
+ title: "Remove code block",
3637
+ onClick: () => {
3638
+ activeEditor.update(() => {
3639
+ const node = $getNodeByKey(activeEditorType.nodeKey);
3640
+ node.selectNext();
3641
+ node.remove();
3642
+ });
3643
+ }
3644
+ },
3645
+ /* @__PURE__ */ React__default.createElement(DeleteIcon, null)
3646
+ ));
3647
+ };
3648
+ const SandpackButtonSet = () => {
3649
+ const [activeEditor, activeEditorType] = useEmitterValues("activeEditor", "activeEditorType");
3650
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(
3651
+ ToolbarButton,
3652
+ {
3653
+ title: "Remove live code block",
3654
+ onClick: () => {
3655
+ activeEditor.update(() => {
3656
+ const node = $getNodeByKey(activeEditorType.nodeKey);
3657
+ node.selectNext();
3658
+ node.remove();
3659
+ });
3660
+ }
3661
+ },
3662
+ /* @__PURE__ */ React__default.createElement(DeleteIcon, null)
3663
+ ));
3664
+ };
3665
+ const RichTextButtonSet = () => {
3666
+ const [toolbarComponents] = useEmitterValues("toolbarComponents");
3667
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, toolbarComponents.map((Component, index2) => /* @__PURE__ */ React__default.createElement(Component, { key: index2 })));
3668
+ };
3669
+ const LazyFrontmatterEditor = React__default.lazy(
3670
+ () => import("./FrontmatterEditor-a8263f5d.js").then((module) => ({ default: module.FrontmatterEditor }))
3671
+ );
3672
+ const LazyJsxEditor = React__default.lazy(() => import("./JsxEditor-4511b188.js").then((module) => ({ default: module.JsxEditor })));
3673
+ const LazySandpackEditor = React__default.lazy(
3674
+ () => import("./SandpackEditor-0a3bfaf0.js").then((module) => ({ default: module.SandpackEditor }))
3675
+ );
3676
+ const LazyCodeBlockEditor = React__default.lazy(
3677
+ () => import("./CodeBlockEditor-85a8b6b0.js").then((module) => ({ default: module.CodeBlockEditor }))
3678
+ );
3679
+ const LazyTableEditor = React__default.lazy(() => import("./TableEditor-0aedb943.js").then((module) => ({ default: module.TableEditor })));
3680
+ const defaultNodeDecorators = {
3681
+ FrontmatterEditor: LazyFrontmatterEditor,
3682
+ JsxEditor: LazyJsxEditor,
3683
+ SandpackEditor: LazySandpackEditor,
3684
+ CodeBlockEditor: LazyCodeBlockEditor,
3685
+ TableEditor: LazyTableEditor
3686
+ };
3687
+ const defaultToolbarComponents = [
3688
+ BoldItalicUnderlineButtons,
3689
+ ToolbarSeparator,
3690
+ CodeFormattingButton,
3691
+ ToolbarSeparator,
3692
+ ListButtons,
3693
+ ToolbarSeparator,
3694
+ BlockTypeSelect,
3695
+ ToolbarSeparator,
3696
+ LinkButton,
3697
+ ImageButton,
3698
+ TableButton,
3699
+ HorizontalRuleButton,
3700
+ FrontmatterButton,
3701
+ ToolbarSeparator,
3702
+ CodeBlockButton,
3703
+ SandpackButton
3704
+ ];
3705
+ const defaultSandpackConfig = {
3706
+ defaultPreset: "react",
3707
+ presets: [
3708
+ {
3709
+ name: "react",
3710
+ meta: "live react",
3711
+ label: "React",
3712
+ sandpackTemplate: "react",
3713
+ sandpackTheme: "light",
3714
+ snippetFileName: "/App.js",
3715
+ snippetLanguage: "jsx",
3716
+ initialSnippetContent: `
3717
+ export default function App() {
3718
+ return (
3719
+ <div className="App">
3720
+ <h1>Hello CodeSandbox</h1>
3721
+ <h2>Start editing to see some magic happen!</h2>
3722
+ </div>
3723
+ );
3724
+ }
3725
+ `.trim()
3726
+ }
3727
+ ]
3728
+ };
3729
+ const defaultMdxOptionValues = {
3730
+ markdownParse: {
3731
+ defaultVisitors: defaultMdastVisitors,
3732
+ defaultSyntaxExtensions,
3733
+ defaultMdastExtensions
3734
+ },
3735
+ lexicalConvert: {
3736
+ defaultVisitors: defaultLexicalVisitors,
3737
+ defaultExtensions,
3738
+ defaultMarkdownOptions: defaultToMarkdownOptions
3739
+ },
3740
+ defaultLexicalNodes
3741
+ };
3742
+ const MDXEditor = React__default.forwardRef(
3743
+ ({
3744
+ markdown: markdown2,
3745
+ headMarkdown,
3746
+ jsxComponentDescriptors = [],
3747
+ sandpackConfig = defaultSandpackConfig,
3748
+ onChange,
3749
+ viewMode,
3750
+ linkAutocompleteSuggestions,
3751
+ imageAutoCompleteSuggestions,
3752
+ className,
3753
+ contentEditableClassName,
3754
+ toolbarComponents = defaultToolbarComponents,
3755
+ markdownParseOptions: {
3756
+ syntaxExtensions = Object.values(defaultSyntaxExtensions),
3757
+ mdastExtensions = Object.values(defaultMdastExtensions),
3758
+ visitors: importVisitors = Object.values(defaultMdastVisitors)
3759
+ } = {},
3760
+ lexicalConvertOptions: {
3761
+ toMarkdownExtensions = Object.values(defaultExtensions),
3762
+ toMarkdownOptions = defaultToMarkdownOptions,
3763
+ visitors: exportVisitors = Object.values(defaultLexicalVisitors)
3764
+ } = {},
3765
+ lexicalNodes = Object.values(defaultLexicalNodes)
3766
+ }, ref) => {
3767
+ const editorRootElementRef = React__default.useRef(null);
3768
+ return /* @__PURE__ */ React__default.createElement("div", { className: classNames(styles.editorRoot, styles.editorWrapper, className), ref: editorRootElementRef }, /* @__PURE__ */ React__default.createElement(
3769
+ LexicalComposer,
3770
+ {
3771
+ initialConfig: {
3772
+ editorState: () => {
3773
+ importMarkdownToLexical({
3774
+ root: $getRoot(),
3775
+ visitors: importVisitors,
3776
+ mdastExtensions,
3777
+ markdown: markdown2,
3778
+ syntaxExtensions
3779
+ });
3780
+ },
3781
+ namespace: "MDXEditor",
3782
+ theme: {
3783
+ ...theme,
3784
+ nodeDecoratorComponents: defaultNodeDecorators
3785
+ },
3786
+ nodes: lexicalNodes,
3787
+ onError: (error) => console.error(error)
3788
+ }
3789
+ },
3790
+ /* @__PURE__ */ React__default.createElement(
3791
+ EditorSystemComponent,
3792
+ {
3793
+ markdownSource: markdown2,
3794
+ headMarkdown: headMarkdown || markdown2,
3795
+ jsxComponentDescriptors,
3796
+ sandpackConfig,
3797
+ onChange,
3798
+ viewMode,
3799
+ linkAutocompleteSuggestions,
3800
+ imageAutocompleteSuggestions: imageAutoCompleteSuggestions,
3801
+ editorRootElementRef,
3802
+ toolbarComponents,
3803
+ markdownParseOptions: {
3804
+ visitors: importVisitors,
3805
+ mdastExtensions,
3806
+ syntaxExtensions
3807
+ },
3808
+ lexicalConvertOptions: {
3809
+ visitors: exportVisitors,
3810
+ toMarkdownOptions,
3811
+ toMarkdownExtensions
3812
+ },
3813
+ lexicalNodes
3814
+ },
3815
+ /* @__PURE__ */ React__default.createElement(ToolbarPlugin, null),
3816
+ /* @__PURE__ */ React__default.createElement(ViewModeToggler, null, /* @__PURE__ */ React__default.createElement(
3817
+ RichTextPlugin,
3818
+ {
3819
+ contentEditable: /* @__PURE__ */ React__default.createElement(ContentEditable, { className: classNames(styles.contentEditable, contentEditableClassName) }),
3820
+ placeholder: /* @__PURE__ */ React__default.createElement("div", null),
3821
+ ErrorBoundary: LexicalErrorBoundary
3822
+ }
3823
+ )),
3824
+ /* @__PURE__ */ React__default.createElement(LinkPlugin, null),
3825
+ /* @__PURE__ */ React__default.createElement(HorizontalRulePlugin, null),
3826
+ /* @__PURE__ */ React__default.createElement(ListPlugin, null),
3827
+ /* @__PURE__ */ React__default.createElement(ListMaxIndentLevelPlugin, { maxDepth: 7 }),
3828
+ /* @__PURE__ */ React__default.createElement(TabIndentationPlugin, null),
3829
+ /* @__PURE__ */ React__default.createElement(LinkDialogPlugin, null),
3830
+ /* @__PURE__ */ React__default.createElement(SharedHistoryPlugin, null),
3831
+ /* @__PURE__ */ React__default.createElement(PatchedMarkdownShortcutPlugin, null),
3832
+ /* @__PURE__ */ React__default.createElement(MDXMethods, { mdxRef: ref })
3833
+ )
3834
+ ));
3835
+ }
3836
+ );
3837
+ const MDXMethods = ({ mdxRef }) => {
3838
+ const [markdownSource] = useEmitterValues("markdownSource");
3839
+ React__default.useImperativeHandle(
3840
+ mdxRef,
3841
+ () => {
3842
+ return {
3843
+ getMarkdown: () => {
3844
+ return markdownSource;
3845
+ }
3846
+ };
3847
+ },
3848
+ [markdownSource]
3849
+ );
3850
+ return null;
3851
+ };
3852
+ export {
3853
+ $createAdmonitionNode as $,
3854
+ AdmonitionNode as A,
3855
+ CodeBlockNode as C,
3856
+ FrontmatterNode as F,
3857
+ ImageNode as I,
3858
+ JsxNode as J,
3859
+ MDXEditor as M,
3860
+ SharedHistoryPlugin as S,
3861
+ ToolbarComponents as T,
3862
+ usePublisher as a,
3863
+ $isAdmonitionNode as b,
3864
+ $createCodeBlockNode as c,
3865
+ $isCodeBlockNode as d,
3866
+ exportLexicalTreeToMdast as e,
3867
+ $createFrontmatterNode as f,
3868
+ $isFrontmatterNode as g,
3869
+ $createImageNode as h,
3870
+ importMdastTreeToLexical as i,
3871
+ $isImageNode as j,
3872
+ $createJsxNode as k,
3873
+ $isJsxNode as l,
3874
+ SandpackNode as m,
3875
+ $createSandpackNode as n,
3876
+ $isSandpackNode as o,
3877
+ TableNode as p,
3878
+ $isTableNode as q,
3879
+ $createTableNode as r,
3880
+ styles as s,
3881
+ theme as t,
3882
+ useEmitterValues as u,
3883
+ defaultMdxOptionValues as v
3884
+ };