@lexical/mdast 0.47.0 → 0.47.1-nightly.20260713.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/LexicalMdast.dev.js +128 -20
- package/dist/LexicalMdast.dev.mjs +128 -20
- package/dist/LexicalMdast.prod.js +2 -2
- package/dist/LexicalMdast.prod.mjs +2 -2
- package/dist/handlers.d.ts +21 -0
- package/package.json +10 -10
- package/src/MdastExport.ts +21 -21
- package/src/handlers.ts +116 -0
package/dist/LexicalMdast.dev.js
CHANGED
|
@@ -631,6 +631,112 @@ function phrasingFromFormattedText(value, format) {
|
|
|
631
631
|
}
|
|
632
632
|
return content;
|
|
633
633
|
}
|
|
634
|
+
|
|
635
|
+
/** A contiguous stretch of plain text sharing one Lexical format bitmask. */
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Emphasis-family format bits eligible for cross-run grouping, in tie-break
|
|
639
|
+
* order matching the single-run nesting of {@link phrasingFromFormattedText}
|
|
640
|
+
* (strong outside emphasis).
|
|
641
|
+
*/
|
|
642
|
+
const EMPHASIS_FORMATS = [[FORMAT_BOLD, 'strong'], [FORMAT_ITALIC, 'emphasis']];
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Converts a segment of strikethrough-free (or strikethrough-stripped) runs
|
|
646
|
+
* into nested emphasis/strong phrasing. At each position the wrapper is
|
|
647
|
+
* chosen greedily: the format bit shared by the longest stretch of upcoming
|
|
648
|
+
* runs becomes the outer container (ties fall back to strong-outside-emphasis,
|
|
649
|
+
* matching the single-run nesting), and the covered runs recurse with that
|
|
650
|
+
* bit cleared. Overlap is not always fully expressible as nesting — the
|
|
651
|
+
* format that extends furthest keeps a single pair of delimiters and the
|
|
652
|
+
* other side splits.
|
|
653
|
+
*/
|
|
654
|
+
function phrasingFromEmphasisRuns(runs) {
|
|
655
|
+
const out = [];
|
|
656
|
+
for (let i = 0; i < runs.length;) {
|
|
657
|
+
const {
|
|
658
|
+
format,
|
|
659
|
+
value
|
|
660
|
+
} = runs[i];
|
|
661
|
+
let wrapper = null;
|
|
662
|
+
let wrapperBit = 0;
|
|
663
|
+
let end = i + 1;
|
|
664
|
+
for (const [bit, type] of EMPHASIS_FORMATS) {
|
|
665
|
+
if ((format & bit) === 0) {
|
|
666
|
+
continue;
|
|
667
|
+
}
|
|
668
|
+
let bitEnd = i + 1;
|
|
669
|
+
while (bitEnd < runs.length && runs[bitEnd].format & bit) {
|
|
670
|
+
bitEnd++;
|
|
671
|
+
}
|
|
672
|
+
if (wrapper === null || bitEnd > end) {
|
|
673
|
+
wrapper = type;
|
|
674
|
+
wrapperBit = bit;
|
|
675
|
+
end = bitEnd;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
if (wrapper === null) {
|
|
679
|
+
out.push(format & FORMAT_CODE ? {
|
|
680
|
+
type: 'inlineCode',
|
|
681
|
+
value
|
|
682
|
+
} : {
|
|
683
|
+
type: 'text',
|
|
684
|
+
value
|
|
685
|
+
});
|
|
686
|
+
i++;
|
|
687
|
+
} else {
|
|
688
|
+
out.push({
|
|
689
|
+
children: phrasingFromEmphasisRuns(runs.slice(i, end).map(run => ({
|
|
690
|
+
format: run.format & ~wrapperBit,
|
|
691
|
+
value: run.value
|
|
692
|
+
}))),
|
|
693
|
+
type: wrapper
|
|
694
|
+
});
|
|
695
|
+
i = end;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
return out;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Converts a sequence of text runs into properly *nested* mdast phrasing.
|
|
703
|
+
* Runs whose formats overlap (e.g. `llo` bold, `wor` bold+italic, `ld`
|
|
704
|
+
* italic) must share a container wherever they share a format bit — emitting
|
|
705
|
+
* each run as its own fully-wrapped sibling produces adjacent delimiter runs
|
|
706
|
+
* (`**llo*****wor****ld*`) that CommonMark resolves differently, so the
|
|
707
|
+
* output would not re-parse to the same formatting (issue #4895).
|
|
708
|
+
*
|
|
709
|
+
* Strikethrough segments the sequence first and always wraps outermost (the
|
|
710
|
+
* single-run nesting order): a `~~` delimiter is only reliably flanking next
|
|
711
|
+
* to text, so `delete` must never land *inside* an emphasis/strong group
|
|
712
|
+
* where a `*` marker would abut it (`*ld~~**llo**~~*` does not re-parse).
|
|
713
|
+
* Bold/italic overlap is then grouped greedily within each segment by
|
|
714
|
+
* {@link phrasingFromEmphasisRuns}.
|
|
715
|
+
*/
|
|
716
|
+
function phrasingFromTextRuns(runs) {
|
|
717
|
+
const out = [];
|
|
718
|
+
for (let i = 0; i < runs.length;) {
|
|
719
|
+
const strike = (runs[i].format & FORMAT_STRIKETHROUGH) !== 0;
|
|
720
|
+
let end = i + 1;
|
|
721
|
+
while (end < runs.length && (runs[end].format & FORMAT_STRIKETHROUGH) !== 0 === strike) {
|
|
722
|
+
end++;
|
|
723
|
+
}
|
|
724
|
+
const segment = runs.slice(i, end);
|
|
725
|
+
if (strike) {
|
|
726
|
+
out.push({
|
|
727
|
+
children: phrasingFromEmphasisRuns(segment.map(run => ({
|
|
728
|
+
format: run.format & ~FORMAT_STRIKETHROUGH,
|
|
729
|
+
value: run.value
|
|
730
|
+
}))),
|
|
731
|
+
type: 'delete'
|
|
732
|
+
});
|
|
733
|
+
} else {
|
|
734
|
+
out.push(...phrasingFromEmphasisRuns(segment));
|
|
735
|
+
}
|
|
736
|
+
i = end;
|
|
737
|
+
}
|
|
738
|
+
return out;
|
|
739
|
+
}
|
|
634
740
|
const exportText = node => {
|
|
635
741
|
if (!lexical.$isTextNode(node)) {
|
|
636
742
|
return null;
|
|
@@ -780,40 +886,42 @@ const SYNTAX_TO_MARKDOWN = {
|
|
|
780
886
|
};
|
|
781
887
|
|
|
782
888
|
/**
|
|
783
|
-
* Accumulates adjacent plain text nodes
|
|
784
|
-
*
|
|
785
|
-
*
|
|
889
|
+
* Accumulates adjacent plain text nodes so a whole stretch of formatted text
|
|
890
|
+
* serializes together: nodes sharing a format merge into a single delimiter
|
|
891
|
+
* pair (`**ab**` rather than `**a****b**`), and nodes whose formats *overlap*
|
|
892
|
+
* (bold, bold+italic, italic) nest inside shared containers so the emitted
|
|
893
|
+
* delimiters re-parse to the same formatting. Shared by the inline and block
|
|
894
|
+
* export walks.
|
|
786
895
|
*/
|
|
787
896
|
class TextRunAccumulator {
|
|
788
|
-
|
|
789
|
-
value = '';
|
|
897
|
+
runs = [];
|
|
790
898
|
|
|
791
899
|
/**
|
|
792
|
-
* Returns `true` when `child` was absorbed.
|
|
793
|
-
*
|
|
794
|
-
* are eligible (plain text with no export rule of its own); this only
|
|
900
|
+
* Returns `true` when `child` was absorbed. The caller decides *which* text
|
|
901
|
+
* nodes are eligible (plain text with no export rule of its own); this only
|
|
795
902
|
* guards the node kind.
|
|
796
903
|
*/
|
|
797
|
-
push(child
|
|
904
|
+
push(child) {
|
|
798
905
|
if (!lexical.$isTextNode(child)) {
|
|
799
906
|
return false;
|
|
800
907
|
}
|
|
801
908
|
const format = child.getFormat() & TEXT_FORMAT_MASK;
|
|
802
|
-
|
|
803
|
-
|
|
909
|
+
const last = this.runs[this.runs.length - 1];
|
|
910
|
+
if (last !== undefined && last.format === format) {
|
|
911
|
+
last.value += child.getTextContent();
|
|
804
912
|
} else {
|
|
805
|
-
this.
|
|
806
|
-
|
|
807
|
-
|
|
913
|
+
this.runs.push({
|
|
914
|
+
format,
|
|
915
|
+
value: child.getTextContent()
|
|
916
|
+
});
|
|
808
917
|
}
|
|
809
918
|
return true;
|
|
810
919
|
}
|
|
811
920
|
flushInto(out) {
|
|
812
|
-
if (this.
|
|
813
|
-
out.push(
|
|
921
|
+
if (this.runs.length > 0) {
|
|
922
|
+
out.push(...phrasingFromTextRuns(this.runs));
|
|
923
|
+
this.runs = [];
|
|
814
924
|
}
|
|
815
|
-
this.format = -1;
|
|
816
|
-
this.value = '';
|
|
817
925
|
}
|
|
818
926
|
}
|
|
819
927
|
function createNodeExporter(compiled, selection$1 = null) {
|
|
@@ -948,7 +1056,7 @@ function createNodeExporter(compiled, selection$1 = null) {
|
|
|
948
1056
|
if (target === null) {
|
|
949
1057
|
continue;
|
|
950
1058
|
}
|
|
951
|
-
if (!(mayAccumulate(target) && runs.push(target
|
|
1059
|
+
if (!(mayAccumulate(target) && runs.push(target))) {
|
|
952
1060
|
runs.flushInto(result);
|
|
953
1061
|
if (lexical.$isElementNode(target)) {
|
|
954
1062
|
// The registry erases types; phrasing output is the dispatch
|
|
@@ -998,7 +1106,7 @@ function createNodeExporter(compiled, selection$1 = null) {
|
|
|
998
1106
|
runs.flushInto(inline);
|
|
999
1107
|
inline.push(asBreak);
|
|
1000
1108
|
}
|
|
1001
|
-
} else if (mayAccumulate(target) && runs.push(target
|
|
1109
|
+
} else if (mayAccumulate(target) && runs.push(target)) {
|
|
1002
1110
|
continue;
|
|
1003
1111
|
} else if ($isBlockLevelNode(target)) {
|
|
1004
1112
|
flushParagraph();
|
|
@@ -629,6 +629,112 @@ function phrasingFromFormattedText(value, format) {
|
|
|
629
629
|
}
|
|
630
630
|
return content;
|
|
631
631
|
}
|
|
632
|
+
|
|
633
|
+
/** A contiguous stretch of plain text sharing one Lexical format bitmask. */
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Emphasis-family format bits eligible for cross-run grouping, in tie-break
|
|
637
|
+
* order matching the single-run nesting of {@link phrasingFromFormattedText}
|
|
638
|
+
* (strong outside emphasis).
|
|
639
|
+
*/
|
|
640
|
+
const EMPHASIS_FORMATS = [[FORMAT_BOLD, 'strong'], [FORMAT_ITALIC, 'emphasis']];
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Converts a segment of strikethrough-free (or strikethrough-stripped) runs
|
|
644
|
+
* into nested emphasis/strong phrasing. At each position the wrapper is
|
|
645
|
+
* chosen greedily: the format bit shared by the longest stretch of upcoming
|
|
646
|
+
* runs becomes the outer container (ties fall back to strong-outside-emphasis,
|
|
647
|
+
* matching the single-run nesting), and the covered runs recurse with that
|
|
648
|
+
* bit cleared. Overlap is not always fully expressible as nesting — the
|
|
649
|
+
* format that extends furthest keeps a single pair of delimiters and the
|
|
650
|
+
* other side splits.
|
|
651
|
+
*/
|
|
652
|
+
function phrasingFromEmphasisRuns(runs) {
|
|
653
|
+
const out = [];
|
|
654
|
+
for (let i = 0; i < runs.length;) {
|
|
655
|
+
const {
|
|
656
|
+
format,
|
|
657
|
+
value
|
|
658
|
+
} = runs[i];
|
|
659
|
+
let wrapper = null;
|
|
660
|
+
let wrapperBit = 0;
|
|
661
|
+
let end = i + 1;
|
|
662
|
+
for (const [bit, type] of EMPHASIS_FORMATS) {
|
|
663
|
+
if ((format & bit) === 0) {
|
|
664
|
+
continue;
|
|
665
|
+
}
|
|
666
|
+
let bitEnd = i + 1;
|
|
667
|
+
while (bitEnd < runs.length && runs[bitEnd].format & bit) {
|
|
668
|
+
bitEnd++;
|
|
669
|
+
}
|
|
670
|
+
if (wrapper === null || bitEnd > end) {
|
|
671
|
+
wrapper = type;
|
|
672
|
+
wrapperBit = bit;
|
|
673
|
+
end = bitEnd;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
if (wrapper === null) {
|
|
677
|
+
out.push(format & FORMAT_CODE ? {
|
|
678
|
+
type: 'inlineCode',
|
|
679
|
+
value
|
|
680
|
+
} : {
|
|
681
|
+
type: 'text',
|
|
682
|
+
value
|
|
683
|
+
});
|
|
684
|
+
i++;
|
|
685
|
+
} else {
|
|
686
|
+
out.push({
|
|
687
|
+
children: phrasingFromEmphasisRuns(runs.slice(i, end).map(run => ({
|
|
688
|
+
format: run.format & ~wrapperBit,
|
|
689
|
+
value: run.value
|
|
690
|
+
}))),
|
|
691
|
+
type: wrapper
|
|
692
|
+
});
|
|
693
|
+
i = end;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
return out;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* Converts a sequence of text runs into properly *nested* mdast phrasing.
|
|
701
|
+
* Runs whose formats overlap (e.g. `llo` bold, `wor` bold+italic, `ld`
|
|
702
|
+
* italic) must share a container wherever they share a format bit — emitting
|
|
703
|
+
* each run as its own fully-wrapped sibling produces adjacent delimiter runs
|
|
704
|
+
* (`**llo*****wor****ld*`) that CommonMark resolves differently, so the
|
|
705
|
+
* output would not re-parse to the same formatting (issue #4895).
|
|
706
|
+
*
|
|
707
|
+
* Strikethrough segments the sequence first and always wraps outermost (the
|
|
708
|
+
* single-run nesting order): a `~~` delimiter is only reliably flanking next
|
|
709
|
+
* to text, so `delete` must never land *inside* an emphasis/strong group
|
|
710
|
+
* where a `*` marker would abut it (`*ld~~**llo**~~*` does not re-parse).
|
|
711
|
+
* Bold/italic overlap is then grouped greedily within each segment by
|
|
712
|
+
* {@link phrasingFromEmphasisRuns}.
|
|
713
|
+
*/
|
|
714
|
+
function phrasingFromTextRuns(runs) {
|
|
715
|
+
const out = [];
|
|
716
|
+
for (let i = 0; i < runs.length;) {
|
|
717
|
+
const strike = (runs[i].format & FORMAT_STRIKETHROUGH) !== 0;
|
|
718
|
+
let end = i + 1;
|
|
719
|
+
while (end < runs.length && (runs[end].format & FORMAT_STRIKETHROUGH) !== 0 === strike) {
|
|
720
|
+
end++;
|
|
721
|
+
}
|
|
722
|
+
const segment = runs.slice(i, end);
|
|
723
|
+
if (strike) {
|
|
724
|
+
out.push({
|
|
725
|
+
children: phrasingFromEmphasisRuns(segment.map(run => ({
|
|
726
|
+
format: run.format & ~FORMAT_STRIKETHROUGH,
|
|
727
|
+
value: run.value
|
|
728
|
+
}))),
|
|
729
|
+
type: 'delete'
|
|
730
|
+
});
|
|
731
|
+
} else {
|
|
732
|
+
out.push(...phrasingFromEmphasisRuns(segment));
|
|
733
|
+
}
|
|
734
|
+
i = end;
|
|
735
|
+
}
|
|
736
|
+
return out;
|
|
737
|
+
}
|
|
632
738
|
const exportText = node => {
|
|
633
739
|
if (!$isTextNode(node)) {
|
|
634
740
|
return null;
|
|
@@ -778,40 +884,42 @@ const SYNTAX_TO_MARKDOWN = {
|
|
|
778
884
|
};
|
|
779
885
|
|
|
780
886
|
/**
|
|
781
|
-
* Accumulates adjacent plain text nodes
|
|
782
|
-
*
|
|
783
|
-
*
|
|
887
|
+
* Accumulates adjacent plain text nodes so a whole stretch of formatted text
|
|
888
|
+
* serializes together: nodes sharing a format merge into a single delimiter
|
|
889
|
+
* pair (`**ab**` rather than `**a****b**`), and nodes whose formats *overlap*
|
|
890
|
+
* (bold, bold+italic, italic) nest inside shared containers so the emitted
|
|
891
|
+
* delimiters re-parse to the same formatting. Shared by the inline and block
|
|
892
|
+
* export walks.
|
|
784
893
|
*/
|
|
785
894
|
class TextRunAccumulator {
|
|
786
|
-
|
|
787
|
-
value = '';
|
|
895
|
+
runs = [];
|
|
788
896
|
|
|
789
897
|
/**
|
|
790
|
-
* Returns `true` when `child` was absorbed.
|
|
791
|
-
*
|
|
792
|
-
* are eligible (plain text with no export rule of its own); this only
|
|
898
|
+
* Returns `true` when `child` was absorbed. The caller decides *which* text
|
|
899
|
+
* nodes are eligible (plain text with no export rule of its own); this only
|
|
793
900
|
* guards the node kind.
|
|
794
901
|
*/
|
|
795
|
-
push(child
|
|
902
|
+
push(child) {
|
|
796
903
|
if (!$isTextNode(child)) {
|
|
797
904
|
return false;
|
|
798
905
|
}
|
|
799
906
|
const format = child.getFormat() & TEXT_FORMAT_MASK;
|
|
800
|
-
|
|
801
|
-
|
|
907
|
+
const last = this.runs[this.runs.length - 1];
|
|
908
|
+
if (last !== undefined && last.format === format) {
|
|
909
|
+
last.value += child.getTextContent();
|
|
802
910
|
} else {
|
|
803
|
-
this.
|
|
804
|
-
|
|
805
|
-
|
|
911
|
+
this.runs.push({
|
|
912
|
+
format,
|
|
913
|
+
value: child.getTextContent()
|
|
914
|
+
});
|
|
806
915
|
}
|
|
807
916
|
return true;
|
|
808
917
|
}
|
|
809
918
|
flushInto(out) {
|
|
810
|
-
if (this.
|
|
811
|
-
out.push(
|
|
919
|
+
if (this.runs.length > 0) {
|
|
920
|
+
out.push(...phrasingFromTextRuns(this.runs));
|
|
921
|
+
this.runs = [];
|
|
812
922
|
}
|
|
813
|
-
this.format = -1;
|
|
814
|
-
this.value = '';
|
|
815
923
|
}
|
|
816
924
|
}
|
|
817
925
|
function createNodeExporter(compiled, selection = null) {
|
|
@@ -946,7 +1054,7 @@ function createNodeExporter(compiled, selection = null) {
|
|
|
946
1054
|
if (target === null) {
|
|
947
1055
|
continue;
|
|
948
1056
|
}
|
|
949
|
-
if (!(mayAccumulate(target) && runs.push(target
|
|
1057
|
+
if (!(mayAccumulate(target) && runs.push(target))) {
|
|
950
1058
|
runs.flushInto(result);
|
|
951
1059
|
if ($isElementNode(target)) {
|
|
952
1060
|
// The registry erases types; phrasing output is the dispatch
|
|
@@ -996,7 +1104,7 @@ function createNodeExporter(compiled, selection = null) {
|
|
|
996
1104
|
runs.flushInto(inline);
|
|
997
1105
|
inline.push(asBreak);
|
|
998
1106
|
}
|
|
999
|
-
} else if (mayAccumulate(target) && runs.push(target
|
|
1107
|
+
} else if (mayAccumulate(target) && runs.push(target)) {
|
|
1000
1108
|
continue;
|
|
1001
1109
|
} else if ($isBlockLevelNode(target)) {
|
|
1002
1110
|
flushParagraph();
|
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/extension"),t=require("lexical"),n=require("@lexical/selection"),o=require("mdast-util-to-markdown"),r=require("mdast-util-to-string"),i=require("@lexical/code-core"),s=require("@lexical/link"),a=require("@lexical/list"),l=require("@lexical/rich-text"),d=require("mdast-util-gfm-autolink-literal"),c=require("mdast-util-gfm-strikethrough"),u=require("mdast-util-gfm-task-list-item"),p=require("micromark-extension-gfm-autolink-literal"),f=require("micromark-extension-gfm-strikethrough"),m=require("micromark-extension-gfm-task-list-item"),h=require("mdast-util-from-markdown"),g=require("@lexical/table"),x=require("mdast-util-gfm-table"),$=require("micromark-extension-gfm-table");const k=/* @__PURE__ */t.createState("mdastListMarker",{parse:e=>"-"===e||"*"===e||"+"===e?e:"",resetOnCopyNode:!0}),T=/* @__PURE__ */t.createState("mdastOrderedMarker",{parse:e=>"."===e||")"===e?e:"",resetOnCopyNode:!0}),S=/* @__PURE__ */t.createState("mdastEmphasisMarker",{parse:e=>"_"===e?"_":"",resetOnCopyNode:!0}),y=/* @__PURE__ */t.createState("mdastStrongMarker",{parse:e=>"_"===e?"_":"",resetOnCopyNode:!0}),N=/* @__PURE__ */t.createState("mdastSetext",{parse:e=>!0===e,resetOnCopyNode:!0}),E=/* @__PURE__ */t.createState("mdastCodeFence",{parse:e=>"string"==typeof e&&/^(`{3,}|~{3,})$/.test(e)?e:"",resetOnCopyNode:!0}),C=/* @__PURE__ */t.createState("mdastCodeMeta",{parse:e=>"string"==typeof e?e:"",resetOnCopyNode:!0}),M=/* @__PURE__ */t.createState("mdastHardLineBreak",{parse:e=>"string"==typeof e&&/^(\\| {2,})$/.test(e)?e:"",resetOnCopyNode:!0}),R=/* @__PURE__ */t.createState("mdastParagraphBreak",{parse:e=>!0===e,resetOnCopyNode:!0}),w=/* @__PURE__ */t.createState("mdastHrMarker",{parse:e=>"-"===e||"*"===e||"_"===e?e:"",resetOnCopyNode:!0}),b=/* @__PURE__ */t.createState("mdastLinkStyle",{parse:e=>"inline"===e||"autolink"===e||"literal"===e?e:"",resetOnCopyNode:!0});function L(e,t){return e.splice(e.getChildrenSize(),0,t)}function v(e){return(t.$isElementNode(e)||t.$isDecoratorNode(e))&&!e.isInline()}function O(){return t.$setState(t.$createLineBreakNode(),R,!0)}const I=t.TEXT_TYPE_TO_FORMAT.bold,F=t.TEXT_TYPE_TO_FORMAT.italic,_=t.TEXT_TYPE_TO_FORMAT.strikethrough,H=t.TEXT_TYPE_TO_FORMAT.code,B=I|F|_|H;function q(e){if(e.ordered)return"number";for(const t of e.children)if("listItem"===t.type&&null!=t.checked)return"check";return"bullet"}function A(e,n){return(o,r)=>{const i=r.importChildren(o,e);if("_"===function(e,t){if(e.source&&t.position&&null!=t.position.start.offset)return e.source[t.position.start.offset]}(r,o))for(const e of i)t.$isTextNode(e)&&t.$setState(e,n,"_");return i}}const P=/* @__PURE__ */A(F,S),z=/* @__PURE__ */A(I,y),D={h1:1,h2:2,h3:3,h4:4,h5:5,h6:6};function Q(e,n){const o=e.getListType(),r={children:[],ordered:"number"===o,spread:!1,start:"number"===o?e.getStart():void 0,type:"list"};if("number"===o){const n=t.$getState(e,T);n&&(r.data={mdastBulletOrdered:n})}else{const n=t.$getState(e,k);n&&(r.data={mdastBullet:n})}let i=null;for(const t of e.getChildren()){if(!a.$isListItemNode(t)||!n.isIncluded(t))continue;const e=t.getFirstChild();if(1===t.getChildrenSize()&&a.$isListNode(e)){const t=Q(e,n);i?i.children.push(t):r.children.push({children:[t],spread:!1,type:"listItem"});continue}const s={checked:"check"===o?t.getChecked()??!1:null,children:n.exportBlocks(t),spread:!1,type:"listItem"};r.children.push(s),i=s}return r}function Y(e,t){let n=t&H?{type:"inlineCode",value:e}:{type:"text",value:e};return t&F&&(n={children:[n],type:"emphasis"}),t&I&&(n={children:[n],type:"strong"}),t&_&&(n={children:[n],type:"delete"}),n}const G=e=>t.$isTextNode(e)?Y(e.getTextContent(),e.getFormat()&B):null,U=e=>t.$isLineBreakNode(e)?{data:{mdastBreak:t.$getState(e,M)},type:"break"}:null;function X(e,t,n){const{options:o}=e,r={};for(const e of Object.keys(t))r[e]=o[e],o[e]=t[e];try{return n()}finally{for(const e of Object.keys(r))o[e]=r[e]}}const K={handlers:{break(e,t,n,r){const i=o.defaultHandlers.break(e,t,n,r);if("\\\n"!==i)return i;const s=e.data&&e.data.mdastBreak;return s?/^ {2,}$/.test(s)?`${s}\n`:i:"\n"},code(e,t,n,r){const i=e.data&&e.data.mdastFence;return i?X(n,{fence:"~"===i[0]?"~":"`",fences:!0},()=>o.defaultHandlers.code(e,t,n,r)):o.defaultHandlers.code(e,t,n,r)},heading:(e,t,n,r)=>e.data&&!0===e.data.mdastSetext?X(n,{setext:!0},()=>o.defaultHandlers.heading(e,t,n,r)):o.defaultHandlers.heading(e,t,n,r),link(e,t,n,i){const s=e.data&&e.data.mdastLinkStyle;return"literal"===s&&null==e.title?r.toString(e):"inline"===s?X(n,{resourceLink:!0},()=>o.defaultHandlers.link(e,t,n,i)):o.defaultHandlers.link(e,t,n,i)},list(e,t,n,r){if(e.ordered){const i=e.data&&e.data.mdastBulletOrdered;return null==i?o.defaultHandlers.list(e,t,n,r):X(n,{bulletOrdered:i},()=>o.defaultHandlers.list(e,t,n,r))}const i=e.data&&e.data.mdastBullet;return null==i?o.defaultHandlers.list(e,t,n,r):X(n,{bullet:i,bulletOther:"-"===i?"*":"-"},()=>o.defaultHandlers.list(e,t,n,r))},thematicBreak(e,t,n){const r=e.data&&e.data.mdastRule;return"-"!==r&&"*"!==r&&"_"!==r?o.defaultHandlers.thematicBreak(e,t,n):X(n,{rule:r},()=>o.defaultHandlers.thematicBreak(e,t,n))}}};class j{format=-1;value="";push(e,n){if(!t.$isTextNode(e))return!1;const o=e.getFormat()&B;return o===this.format?this.value+=e.getTextContent():(this.flushInto(n),this.format=o,this.value=e.getTextContent()),!0}flushInto(e){this.format>=0&&e.push(Y(this.value,this.format)),this.format=-1,this.value=""}}function W(e,o=null){const{exportHandlers:r}=e;let i=0;function s(e){const t=r.get(e.getType());return void 0===t||t===G}function a(e){return null===o||t.$isElementNode(e)?e:e.isSelected(o)?(i++,t.$isTextNode(e)?n.$sliceSelectedTextNodeContent(o,e,"clone"):e):null}function l(e,t){const n=null!==o&&e.isSelected(o);n&&i++;const r=i,s=c(e);(null===o||n||i>r)&&t.push(...s)}const d={exportBlocks:e=>function(e){const n=[];let o=[];const r=new j,i=()=>{r.flushInto(o),o.length>0&&(n.push({children:o,type:"paragraph"}),o=[])};for(const d of e.getChildren()){const e=a(d);if(null!==e)if(t.$isLineBreakNode(e)){const n=U(e);t.$getState(e,R)||null===n?i():(r.flushInto(o),o.push(n))}else{if(s(e)&&r.push(e,o))continue;v(e)?(i(),t.$isElementNode(e)?l(e,n):n.push(...c(e))):t.$isElementNode(e)?(r.flushInto(o),l(e,o)):(r.flushInto(o),o.push(...c(e)))}}i(),0===n.length&&n.push({children:[],type:"paragraph"});return n}(e),exportChildren:e=>{const n=[];for(const o of e.getChildren()){const e=a(o);null!==e&&(t.$isElementNode(e)?l(e,n):n.push(...c(e)))}return n},exportInline:e=>function(e){const n=[],o=new j;for(const r of e.getChildren()){const e=a(r);null!==e&&(s(e)&&o.push(e,n)||(o.flushInto(n),t.$isElementNode(e)?l(e,n):n.push(...c(e))))}return o.flushInto(n),n}(e),isIncluded:function e(n){if(null===o||n.isSelected(o))return!0;if(t.$isElementNode(n))for(const t of n.getChildren())if(e(t))return!0;return!1}};function c(e){const n=r.get(e.getType());if(n){const t=n(e,d);if(null!=t)return Array.isArray(t)?t:[t]}const o=G(e);if(null!==o)return[o];const i=U(e);if(null!==i)return[i];if(t.$isElementNode(e))return d.exportChildren(e);const s=e.getTextContent();return s?[{type:"text",value:s}]:[]}return{exportChildren:d.exportChildren}}function J(e){const n=W(e),r=(e,t)=>({children:t.exportChildren(e),type:"root"}),i=(n,r)=>{const{emphasis:i,strong:s}=function(e){let n,o;const r=e=>{for(const i of e.getChildren())if(t.$isTextNode(i)?(void 0===n&&i.hasFormat("italic")&&"_"===t.$getState(i,S)&&(n="_"),void 0===o&&i.hasFormat("bold")&&"_"===t.$getState(i,y)&&(o="_")):t.$isElementNode(i)&&r(i),void 0!==n&&void 0!==o)return};return r(e),{emphasis:n,strong:o}}(r),a={bullet:"-"};i&&(a.emphasis=i),s&&(a.strong=s);return o.toMarkdown(n,{extensions:[a,...e.toMarkdownExtensions,K]}).replace(/\n$/,"")};return{$exportSelectionToMarkdown:(n=t.$getSelection())=>{if(null===n||t.$isRangeSelection(n)&&n.isCollapsed())return"";const o=t.$getRoot();return i(r(o,W(e,n)),o)},$exportToMarkdown:e=>{const o=e||t.$getRoot();return i(r(o,n),o)},$exportToMdast:e=>r(e||t.$getRoot(),n)}}function V(e,n){const o=[];return t.tokenizeRawText(e,{linebreak:()=>o.push(t.$createLineBreakNode()),tab:()=>o.push(t.$createTabNode()),text:e=>{const r=t.$createTextNode(e);n&&r.setFormat(n),o.push(r)}}),o}const Z=new Map;function ee(e,t="",n=Z){const{importHandlers:o}=e,r=new Map;function i(e,a){const l=o.get(e.type);if(l){const o=l(e,function(e){let o=r.get(e);return void 0===o&&(o={createText:(t,n)=>V(t,null==n?e:n),format:e,getDefinition:e=>n.get(e),importChildren:(t,n)=>s(t,e|(n||0)),importNode:(t,n)=>i(t,e|(n||0)),source:t},r.set(e,o)),o}(a));return null==o?[]:Array.isArray(o)?o:[o]}return"children"in e?s(e,a):"value"in e&&"string"==typeof e.value?V(e.value,a):[]}function s(e,t){const n=[];for(const o of e.children)n.push(...i(o,t));return n}return{$importChildren:s,$importNode:i}}function te(e){const n=(n,o)=>{const{$importNode:r}=ee(e,o,function(e){const t=new Map,n=e=>{if("definition"===e.type&&(t.has(e.identifier)||t.set(e.identifier,{title:e.title,url:e.url})),"children"in e)for(const t of e.children)n(t)};return n(e),t}(n)),i=[];let s=null;const a=()=>{s&&(i.push(s),s=null)};for(const e of n.children)for(const n of r(e,0))v(n)?(a(),i.push(n)):(s||(s=t.$createParagraphNode()),L(s,[n]));return a(),i},o=t=>n(h.fromMarkdown(t,{extensions:e.micromarkExtensions,mdastExtensions:e.mdastExtensions}),t),r=e=>n(e,""),i=(e,n)=>{const o=n||t.$getRoot();var r,i;o.clear(),r=o,i=e.length>0?e:[t.$createParagraphNode()],r.splice(0,0,i),null!==t.$getSelection()&&o.selectStart()};return{$generateNodesFromMarkdown:o,$generateNodesFromMdast:r,$importMarkdown:(e,t)=>i(o(e),t),$importMdast:(e,t)=>i(r(e),t)}}function ne(e,t){let n=e;for(;;){if("heading"===n.type||"paragraph"===n.type){const e=n.children[0];return e&&e.position&&null!=e.position.start.offset?e.position.start.offset:t.length}if(!("children"in n)||0===n.children.length)return t.length;n=n.children[0]}}class oe{compiled;importNode;supportsTaskListItems;constructor(e){this.compiled=e,this.importNode=ee(e,"").$importNode;const t=this.parse("- [x] a").children[0];this.supportsTaskListItems=null!=t&&"list"===t.type&&!0===t.children[0].checked}get inlineTriggers(){return this.compiled.inlineShortcutTriggers}parse(e){return h.fromMarkdown(e,{extensions:this.compiled.micromarkExtensions,mdastExtensions:this.compiled.mdastExtensions})}importInline(e){return this.importNode(e,0)}scanBlock(e){if(""===e.trim())return null;const t=this.parse(e).children[0];if(!t||!this.compiled.importHandlers.has(t.type))return null;switch(t.type){case"heading":return{kind:"heading",markerLength:ne(t,e),node:t};case"blockquote":return{kind:"blockquote",markerLength:ne(t,e),node:t};case"list":return{kind:"list",markerLength:ne(t,e),node:t};case"code":return{kind:"code",markerLength:e.length,node:t};default:return null}}scanInline(e){if(0===e.length)return null;const t=this.parse(e),n=t.children[t.children.length-1];if(!n||"paragraph"!==n.type)return null;const o=n.children[n.children.length-1];if(!o||!o.position||o.position.end.offset!==e.length||!this.compiled.inlineShortcutTypes.has(o.type))return null;const r=o.position.start.offset??0,i=e[r];return r>0&&e[r-1]===i&&this.compiled.inlineShortcutTriggers.has(i)?null:o}}function re(e,n){let o=n,r=e.getFirstChild();for(;o>0&&r&&t.$isTextNode(r);){const e=r.getTextContent();if(e.length<=o){const t=r.getNextSibling();o-=e.length,r.remove(),r=t}else r.setTextContent(e.slice(o)),o=0}}function ie(e,n){const o="code"===n.kind?e.getTextContent().match(/^[ \t]*(`{3,}|~{3,})/):null;re(e,n.markerLength);const r=e.getChildren();if("code"===n.kind){const s=i.$createCodeNode(n.node.lang||void 0);return o&&t.$setState(s,E,o[1]),n.node.meta&&t.$setState(s,C,n.node.meta),L(s,r),e.replace(s),s.selectStart(),!0}let s,d;if("heading"===n.kind){const e=L(l.$createHeadingNode(`h${n.node.depth}`),r);s=e,d=e}else if("blockquote"===n.kind){const e=L(l.$createQuoteNode(),r);s=e,d=e}else{const e=n.node,t=q(e),o=e.ordered&&null!=e.start?e.start:1,i=a.$createListNode(t,o),l=e.children[0],c=l&&"listItem"===l.type&&"boolean"==typeof l.checked?l.checked:void 0,u=L(a.$createListItemNode(c),r);L(i,[u]),s=i,d=u}return e.replace(s),d.selectStart(),!0}const se=/^\[([ xX])\]\s$/;function ae(e,n){return t.$isParagraphNode(e)&&t.$isRootOrShadowRoot(e.getParent())&&e.getFirstChild()===n}function le(e,n){const o=new oe(n),r=o.inlineTriggers,s=new Set([" ",...r]);return t.mergeRegister(e.registerUpdateListener(({tags:n,dirtyLeaves:l,editorState:d,prevEditorState:c})=>{if(0===l.size||n.has(t.COLLABORATION_TAG)||n.has(t.HISTORIC_TAG))return;if(e.isComposing())return;const u=n.has(t.COMPOSITION_END_TAG),p=d.read(t.$getSelection),f=c.read(t.$getSelection);if(!t.$isRangeSelection(p)||!t.$isRangeSelection(f)||!p.isCollapsed()||p.is(f)&&!u)return;const m=p.anchor.key,h=p.anchor.offset,g=d._nodeMap.get(m);if(!t.$isTextNode(g)||!l.has(m))return;if(!u&&1!==h&&(f.anchor.key!==m||h!==f.anchor.offset+1))return;const x=d.read(()=>g.getTextContent()),$=x[h-1];var k,T;u&&!s.has($)||(" "===$||r.has($))&&(" "===$||(k=x.slice(0,h),")"===(T=$)?k.lastIndexOf("](")>0:-1!==k.lastIndexOf(T,k.length-2)))&&e.update(()=>{const e=t.$getNodeByKey(m);if(!t.$isTextNode(e)||e.hasFormat("code"))return;const n=e.getParent();if(null===n||i.$isCodeNode(n))return;let r=!1;if(" "===$){if(o.supportsTaskListItems&&function(e,t,n){if(t.getFirstChild()!==e)return!1;const o=t.getTextContent().slice(0,n).match(se);if(!o)return!1;const r="x"===o[1].toLowerCase();if(a.$isListItemNode(t)){const e=t.getParent();return!(!a.$isListNode(e)||"number"===e.getListType()||(re(t,o[0].length),e.setListType("check"),t.setChecked(r),0))}if(ae(t,e)){re(t,o[0].length);const e=t.getChildren(),n=a.$createListNode("check"),i=L(a.$createListItemNode(r),e);return L(n,[i]),t.replace(n),i.selectStart(),!0}return!1}(e,n,h))r=!0;else if(h<=24&&ae(n,e)){const t=o.scanBlock(e.getTextContent().slice(0,h));t&&"code"!==t.kind&&t.markerLength===h&&(r=ie(n,t))}}else r=function(e,n,o){const r=e.getTextContent().slice(0,n),i=o.scanInline(r);if(!i||!i.position)return!1;const s=i.position.start.offset??0,a=n;let l;if(s<=0)[l]=e.splitText(a);else{const t=e.splitText(s,a);l=3===t.length?t[1]:t[t.length-1]}const d=o.importInline(i);if(0===d.length)return!1;let c=d[0];l.replace(c);for(let e=1;e<d.length;e++)c.insertAfter(d[e]),c=d[e];if(t.$isTextNode(c)){const e=c.getTextContentSize();c.select(e,e)}else c.selectNext(0,0);return!0}(e,h,o);r&&t.$addUpdateTag(t.HISTORY_PUSH_TAG)})}),e.registerCommand(t.KEY_ENTER_COMMAND,e=>{if(null!==e&&e.shiftKey)return!1;const n=t.$getSelection();if(!t.$isRangeSelection(n)||!n.isCollapsed())return!1;const r=n.anchor.getNode();if(!t.$isTextNode(r)||r.hasFormat("code"))return!1;const s=r.getParent(),a=n.anchor.offset;if(null===s||i.$isCodeNode(s)||!ae(s,r)||a!==r.getTextContentSize())return!1;const l=o.scanBlock(s.getTextContent());return!(!l||l.markerLength!==a||!ie(s,l))&&(null!==e&&e.preventDefault(),!0)},t.COMMAND_PRIORITY_BEFORE_EDITOR))}const de=[{$import:(e,n)=>L(t.$createParagraphNode(),n.importChildren(e)),type:"paragraph"},{$import:(e,t)=>t.createText(e.value),type:"text"},{$import:(e,t)=>t.createText(e.value),type:"html"},{$import:(e,t)=>t.createText(e.value,t.format|H),type:"inlineCode"},{$import:P,type:"emphasis"},{$import:z,type:"strong"},{$import:(e,n)=>{let o="\\";if(n.source&&e.position){const{start:t,end:r}=e.position;if(null!=t.offset&&null!=r.offset){const e=n.source.slice(t.offset,r.offset).replace(/\n$/,"");/^ {2,}$/.test(e)&&(o=e)}}return[t.$setState(t.$createLineBreakNode(),M,o)]},type:"break"}],ce=[{$export:(e,n)=>t.$isParagraphNode(e)?{children:n.exportInline(e),type:"paragraph"}:null,type:"paragraph"},{$export:G,type:"text"},{$export:U,type:"linebreak"},{$export:e=>t.$isTabNode(e)?{type:"text",value:"\t"}:null,type:"tab"}],ue=/* @__PURE__ */t.defineExtension({build(e,t){const n=function(e){const t=new Map,n=new Map;for(const n of e.importRules)t.has(n.type)||t.set(n.type,n.$import);for(const t of e.exportRules)n.has(t.type)||n.set(t.type,t.$export);return{exportHandlers:n,importHandlers:t,inlineShortcutTriggers:new Set(e.inlineShortcutTriggers),inlineShortcutTypes:new Set(e.inlineShortcutTypes),mdastExtensions:[...e.mdastExtensions],micromarkExtensions:[...e.micromarkExtensions],toMarkdownExtensions:[...e.toMarkdownExtensions]}}(t),{$generateNodesFromMarkdown:o,$generateNodesFromMdast:r,$importMarkdown:i,$importMdast:s}=te(n);return{$convertFromMarkdownString:i,$convertFromMdast:s,$generateNodesFromMarkdownString:o,$generateNodesFromMdast:r,registry:n}},config:/* @__PURE__ */t.safeCast({exportRules:ce,importRules:de,inlineShortcutTriggers:["*","_","`"],inlineShortcutTypes:["emphasis","inlineCode","strong"],mdastExtensions:[],micromarkExtensions:[],toMarkdownExtensions:[]}),mergeConfig(e,n){function o(e,t){return e?[...e,...t]:t}return t.shallowMergeConfig(e,{exportRules:o(n.exportRules,e.exportRules),importRules:o(n.importRules,e.importRules),inlineShortcutTriggers:o(n.inlineShortcutTriggers,e.inlineShortcutTriggers),inlineShortcutTypes:o(n.inlineShortcutTypes,e.inlineShortcutTypes),mdastExtensions:o(n.mdastExtensions,e.mdastExtensions),micromarkExtensions:o(n.micromarkExtensions,e.micromarkExtensions),toMarkdownExtensions:o(n.toMarkdownExtensions,e.toMarkdownExtensions)})},name:"@lexical/mdast/Import"}),pe=/* @__PURE__ */t.defineExtension({dependencies:[/* @__PURE__ */t.configExtension(ue,{exportRules:[{$export:(e,n)=>{if(!l.$isHeadingNode(e))return null;const o={children:n.exportInline(e),depth:D[e.getTag()],type:"heading"};return t.$getState(e,N)&&(o.data={mdastSetext:!0}),o},type:"heading"}],importRules:[{$import:(e,n)=>{const o=l.$createHeadingNode(`h${e.depth}`);if(n.source&&e.position&&(1===e.depth||2===e.depth)){const r=e.position.start.offset;null==r||/^ {0,3}#{1,6}([ \t\r\n]|$)/.test(n.source.slice(r,r+10))||t.$setState(o,N,!0)}return L(o,n.importChildren(e))},type:"heading"}]})],name:"@lexical/mdast/Heading",nodes:[l.HeadingNode]}),fe=/* @__PURE__ */t.defineExtension({dependencies:[/* @__PURE__ */t.configExtension(ue,{exportRules:[{$export:(e,t)=>l.$isQuoteNode(e)?{children:e.isShadowRoot()?t.exportChildren(e):t.exportBlocks(e),type:"blockquote"}:null,type:"quote"}],importRules:[{$import:(e,t)=>{const n=l.$createQuoteNode(),o=[];for(const n of e.children)"paragraph"===n.type?(o.length>0&&o.push(O()),o.push(...t.importChildren(n))):o.push(...t.importNode(n));return L(n,o)},type:"blockquote"}]})],name:"@lexical/mdast/Blockquote",nodes:[l.QuoteNode]}),me=/* @__PURE__ */t.defineExtension({dependencies:[pe,fe],name:"@lexical/mdast/RichText"}),he=/* @__PURE__ */t.defineExtension({dependencies:[/* @__PURE__ */t.configExtension(ue,{exportRules:[{$export:(e,t)=>a.$isListNode(e)?Q(e,t):null,type:"list"}],importRules:[{$import:(e,n)=>{const o=q(e),r=e.ordered&&null!=e.start?e.start:1,i=a.$createListNode(o,r),s=e.children[0],l=n.source&&s&&s.position?s.position.start.offset:void 0;if(null!=l){const e=n.source.slice(l,l+16);if("number"===o){const n=e.match(/^\s*\d+([.)])/),o=n&&n[1];"."!==o&&")"!==o||t.$setState(i,T,o)}else{const n=e.match(/^\s*([-*+])/),o=n&&n[1];"-"!==o&&"*"!==o&&"+"!==o||t.$setState(i,k,o)}}return L(i,e.children.flatMap(e=>n.importNode(e)))},type:"list"},{$import:(e,t)=>{const n=a.$createListItemNode("boolean"==typeof e.checked?e.checked:void 0),o=[];for(const r of e.children)"list"===r.type?o.push(L(a.$createListItemNode(),t.importNode(r))):"paragraph"===r.type?(n.getChildrenSize()>0&&L(n,[O()]),L(n,t.importChildren(r))):L(n,t.importNode(r));return[n,...o]},type:"listItem"}]})],name:"@lexical/mdast/List",nodes:[a.ListNode,a.ListItemNode]}),ge=/* @__PURE__ */t.defineExtension({dependencies:[he,/* @__PURE__ */t.configExtension(ue,{mdastExtensions:[/* @__PURE__ */u.gfmTaskListItemFromMarkdown()],micromarkExtensions:[/* @__PURE__ */m.gfmTaskListItem()],toMarkdownExtensions:[/* @__PURE__ */u.gfmTaskListItemToMarkdown()]})],name:"@lexical/mdast/TaskList"}),xe=/* @__PURE__ */t.defineExtension({dependencies:[/* @__PURE__ */t.configExtension(ue,{exportRules:[{$export:e=>{if(!i.$isCodeNode(e))return null;const n={lang:e.getLanguage()||null,type:"code",value:e.getTextContent()},o=t.$getState(e,C);o&&(n.meta=o);const r=t.$getState(e,E);return r&&(n.data={mdastFence:r}),n},type:"code"}],importRules:[{$import:(e,n)=>{const o=i.$createCodeNode(e.lang||void 0);if(n.source&&e.position&&null!=e.position.start.offset){const r=e.position.start.offset,i=n.source.indexOf("\n",r),s=n.source.slice(r,-1===i?void 0:i).match(/^[ \t]*(`{3,}|~{3,})/);s&&t.$setState(o,E,s[1])}return e.meta&&t.$setState(o,C,e.meta),e.value&&L(o,[t.$createTextNode(e.value)]),o},type:"code"}]})],name:"@lexical/mdast/Code",nodes:[i.CodeNode]}),$e=/* @__PURE__ */t.defineExtension({dependencies:[/* @__PURE__ */t.configExtension(ue,{exportRules:[{$export:(e,n)=>{if(!s.$isLinkNode(e)||s.$isAutoLinkNode(e))return null;const o={children:n.exportInline(e),title:e.getTitle()??null,type:"link",url:e.getURL()},r=t.$getState(e,b);return r&&(o.data={mdastLinkStyle:r}),o},type:"link"}],importRules:[{$import:(e,n)=>{const o=L(s.$createLinkNode(e.url,{title:null==e.title?void 0:e.title}),n.importChildren(e));if(n.source&&e.position&&null!=e.position.start.offset){const r=n.source[e.position.start.offset];t.$setState(o,b,"["===r?"inline":"<"===r?"autolink":"literal")}return o},type:"link"},{$import:(e,t)=>{const n=t.getDefinition(e.identifier);if(n)return L(s.$createLinkNode(n.url,{title:null==n.title?void 0:n.title}),t.importChildren(e));const{position:o}=e;return t.source&&o&&null!=o.start.offset?t.createText(t.source.slice(o.start.offset,o.end.offset)):[...t.createText("["),...t.importChildren(e),...t.createText("]")]},type:"linkReference"},{$import:()=>[],type:"definition"}],inlineShortcutTriggers:[")"],inlineShortcutTypes:["link"]})],name:"@lexical/mdast/Link",nodes:[s.LinkNode]}),ke=/* @__PURE__ */t.defineExtension({dependencies:[$e,/* @__PURE__ */t.configExtension(ue,{mdastExtensions:[/* @__PURE__ */d.gfmAutolinkLiteralFromMarkdown()],micromarkExtensions:[/* @__PURE__ */p.gfmAutolinkLiteral()],toMarkdownExtensions:[/* @__PURE__ */d.gfmAutolinkLiteralToMarkdown()]})],name:"@lexical/mdast/AutolinkLiteral"}),Te=/* @__PURE__ */t.defineExtension({dependencies:[fe,
|
|
9
|
+
"use strict";var e=require("@lexical/extension"),t=require("lexical"),n=require("@lexical/selection"),o=require("mdast-util-to-markdown"),r=require("mdast-util-to-string"),i=require("@lexical/code-core"),s=require("@lexical/link"),a=require("@lexical/list"),l=require("@lexical/rich-text"),d=require("mdast-util-gfm-autolink-literal"),c=require("mdast-util-gfm-strikethrough"),u=require("mdast-util-gfm-task-list-item"),p=require("micromark-extension-gfm-autolink-literal"),f=require("micromark-extension-gfm-strikethrough"),m=require("micromark-extension-gfm-task-list-item"),h=require("mdast-util-from-markdown"),g=require("@lexical/table"),x=require("mdast-util-gfm-table"),$=require("micromark-extension-gfm-table");const k=/* @__PURE__ */t.createState("mdastListMarker",{parse:e=>"-"===e||"*"===e||"+"===e?e:"",resetOnCopyNode:!0}),T=/* @__PURE__ */t.createState("mdastOrderedMarker",{parse:e=>"."===e||")"===e?e:"",resetOnCopyNode:!0}),y=/* @__PURE__ */t.createState("mdastEmphasisMarker",{parse:e=>"_"===e?"_":"",resetOnCopyNode:!0}),S=/* @__PURE__ */t.createState("mdastStrongMarker",{parse:e=>"_"===e?"_":"",resetOnCopyNode:!0}),N=/* @__PURE__ */t.createState("mdastSetext",{parse:e=>!0===e,resetOnCopyNode:!0}),E=/* @__PURE__ */t.createState("mdastCodeFence",{parse:e=>"string"==typeof e&&/^(`{3,}|~{3,})$/.test(e)?e:"",resetOnCopyNode:!0}),C=/* @__PURE__ */t.createState("mdastCodeMeta",{parse:e=>"string"==typeof e?e:"",resetOnCopyNode:!0}),M=/* @__PURE__ */t.createState("mdastHardLineBreak",{parse:e=>"string"==typeof e&&/^(\\| {2,})$/.test(e)?e:"",resetOnCopyNode:!0}),R=/* @__PURE__ */t.createState("mdastParagraphBreak",{parse:e=>!0===e,resetOnCopyNode:!0}),w=/* @__PURE__ */t.createState("mdastHrMarker",{parse:e=>"-"===e||"*"===e||"_"===e?e:"",resetOnCopyNode:!0}),b=/* @__PURE__ */t.createState("mdastLinkStyle",{parse:e=>"inline"===e||"autolink"===e||"literal"===e?e:"",resetOnCopyNode:!0});function L(e,t){return e.splice(e.getChildrenSize(),0,t)}function v(e){return(t.$isElementNode(e)||t.$isDecoratorNode(e))&&!e.isInline()}function O(){return t.$setState(t.$createLineBreakNode(),R,!0)}const I=t.TEXT_TYPE_TO_FORMAT.bold,F=t.TEXT_TYPE_TO_FORMAT.italic,_=t.TEXT_TYPE_TO_FORMAT.strikethrough,H=t.TEXT_TYPE_TO_FORMAT.code,B=I|F|_|H;function q(e){if(e.ordered)return"number";for(const t of e.children)if("listItem"===t.type&&null!=t.checked)return"check";return"bullet"}function A(e,n){return(o,r)=>{const i=r.importChildren(o,e);if("_"===function(e,t){if(e.source&&t.position&&null!=t.position.start.offset)return e.source[t.position.start.offset]}(r,o))for(const e of i)t.$isTextNode(e)&&t.$setState(e,n,"_");return i}}const P=/* @__PURE__ */A(F,y),z=/* @__PURE__ */A(I,S),D={h1:1,h2:2,h3:3,h4:4,h5:5,h6:6};function Q(e,n){const o=e.getListType(),r={children:[],ordered:"number"===o,spread:!1,start:"number"===o?e.getStart():void 0,type:"list"};if("number"===o){const n=t.$getState(e,T);n&&(r.data={mdastBulletOrdered:n})}else{const n=t.$getState(e,k);n&&(r.data={mdastBullet:n})}let i=null;for(const t of e.getChildren()){if(!a.$isListItemNode(t)||!n.isIncluded(t))continue;const e=t.getFirstChild();if(1===t.getChildrenSize()&&a.$isListNode(e)){const t=Q(e,n);i?i.children.push(t):r.children.push({children:[t],spread:!1,type:"listItem"});continue}const s={checked:"check"===o?t.getChecked()??!1:null,children:n.exportBlocks(t),spread:!1,type:"listItem"};r.children.push(s),i=s}return r}const Y=[[I,"strong"],[F,"emphasis"]];function G(e){const t=[];for(let n=0;n<e.length;){const{format:o,value:r}=e[n];let i=null,s=0,a=n+1;for(const[t,r]of Y){if(0===(o&t))continue;let l=n+1;for(;l<e.length&&e[l].format&t;)l++;(null===i||l>a)&&(i=r,s=t,a=l)}null===i?(t.push(o&H?{type:"inlineCode",value:r}:{type:"text",value:r}),n++):(t.push({children:G(e.slice(n,a).map(e=>({format:e.format&~s,value:e.value}))),type:i}),n=a)}return t}const U=e=>t.$isTextNode(e)?function(e,t){let n=t&H?{type:"inlineCode",value:e}:{type:"text",value:e};return t&F&&(n={children:[n],type:"emphasis"}),t&I&&(n={children:[n],type:"strong"}),t&_&&(n={children:[n],type:"delete"}),n}(e.getTextContent(),e.getFormat()&B):null,X=e=>t.$isLineBreakNode(e)?{data:{mdastBreak:t.$getState(e,M)},type:"break"}:null;function K(e,t,n){const{options:o}=e,r={};for(const e of Object.keys(t))r[e]=o[e],o[e]=t[e];try{return n()}finally{for(const e of Object.keys(r))o[e]=r[e]}}const j={handlers:{break(e,t,n,r){const i=o.defaultHandlers.break(e,t,n,r);if("\\\n"!==i)return i;const s=e.data&&e.data.mdastBreak;return s?/^ {2,}$/.test(s)?`${s}\n`:i:"\n"},code(e,t,n,r){const i=e.data&&e.data.mdastFence;return i?K(n,{fence:"~"===i[0]?"~":"`",fences:!0},()=>o.defaultHandlers.code(e,t,n,r)):o.defaultHandlers.code(e,t,n,r)},heading:(e,t,n,r)=>e.data&&!0===e.data.mdastSetext?K(n,{setext:!0},()=>o.defaultHandlers.heading(e,t,n,r)):o.defaultHandlers.heading(e,t,n,r),link(e,t,n,i){const s=e.data&&e.data.mdastLinkStyle;return"literal"===s&&null==e.title?r.toString(e):"inline"===s?K(n,{resourceLink:!0},()=>o.defaultHandlers.link(e,t,n,i)):o.defaultHandlers.link(e,t,n,i)},list(e,t,n,r){if(e.ordered){const i=e.data&&e.data.mdastBulletOrdered;return null==i?o.defaultHandlers.list(e,t,n,r):K(n,{bulletOrdered:i},()=>o.defaultHandlers.list(e,t,n,r))}const i=e.data&&e.data.mdastBullet;return null==i?o.defaultHandlers.list(e,t,n,r):K(n,{bullet:i,bulletOther:"-"===i?"*":"-"},()=>o.defaultHandlers.list(e,t,n,r))},thematicBreak(e,t,n){const r=e.data&&e.data.mdastRule;return"-"!==r&&"*"!==r&&"_"!==r?o.defaultHandlers.thematicBreak(e,t,n):K(n,{rule:r},()=>o.defaultHandlers.thematicBreak(e,t,n))}}};class W{runs=[];push(e){if(!t.$isTextNode(e))return!1;const n=e.getFormat()&B,o=this.runs[this.runs.length-1];return void 0!==o&&o.format===n?o.value+=e.getTextContent():this.runs.push({format:n,value:e.getTextContent()}),!0}flushInto(e){this.runs.length>0&&(e.push(...function(e){const t=[];for(let n=0;n<e.length;){const o=0!==(e[n].format&_);let r=n+1;for(;r<e.length&&0!==(e[r].format&_)===o;)r++;const i=e.slice(n,r);o?t.push({children:G(i.map(e=>({format:e.format&~_,value:e.value}))),type:"delete"}):t.push(...G(i)),n=r}return t}(this.runs)),this.runs=[])}}function J(e,o=null){const{exportHandlers:r}=e;let i=0;function s(e){const t=r.get(e.getType());return void 0===t||t===U}function a(e){return null===o||t.$isElementNode(e)?e:e.isSelected(o)?(i++,t.$isTextNode(e)?n.$sliceSelectedTextNodeContent(o,e,"clone"):e):null}function l(e,t){const n=null!==o&&e.isSelected(o);n&&i++;const r=i,s=c(e);(null===o||n||i>r)&&t.push(...s)}const d={exportBlocks:e=>function(e){const n=[];let o=[];const r=new W,i=()=>{r.flushInto(o),o.length>0&&(n.push({children:o,type:"paragraph"}),o=[])};for(const d of e.getChildren()){const e=a(d);if(null!==e)if(t.$isLineBreakNode(e)){const n=X(e);t.$getState(e,R)||null===n?i():(r.flushInto(o),o.push(n))}else{if(s(e)&&r.push(e))continue;v(e)?(i(),t.$isElementNode(e)?l(e,n):n.push(...c(e))):t.$isElementNode(e)?(r.flushInto(o),l(e,o)):(r.flushInto(o),o.push(...c(e)))}}i(),0===n.length&&n.push({children:[],type:"paragraph"});return n}(e),exportChildren:e=>{const n=[];for(const o of e.getChildren()){const e=a(o);null!==e&&(t.$isElementNode(e)?l(e,n):n.push(...c(e)))}return n},exportInline:e=>function(e){const n=[],o=new W;for(const r of e.getChildren()){const e=a(r);null!==e&&(s(e)&&o.push(e)||(o.flushInto(n),t.$isElementNode(e)?l(e,n):n.push(...c(e))))}return o.flushInto(n),n}(e),isIncluded:function e(n){if(null===o||n.isSelected(o))return!0;if(t.$isElementNode(n))for(const t of n.getChildren())if(e(t))return!0;return!1}};function c(e){const n=r.get(e.getType());if(n){const t=n(e,d);if(null!=t)return Array.isArray(t)?t:[t]}const o=U(e);if(null!==o)return[o];const i=X(e);if(null!==i)return[i];if(t.$isElementNode(e))return d.exportChildren(e);const s=e.getTextContent();return s?[{type:"text",value:s}]:[]}return{exportChildren:d.exportChildren}}function V(e){const n=J(e),r=(e,t)=>({children:t.exportChildren(e),type:"root"}),i=(n,r)=>{const{emphasis:i,strong:s}=function(e){let n,o;const r=e=>{for(const i of e.getChildren())if(t.$isTextNode(i)?(void 0===n&&i.hasFormat("italic")&&"_"===t.$getState(i,y)&&(n="_"),void 0===o&&i.hasFormat("bold")&&"_"===t.$getState(i,S)&&(o="_")):t.$isElementNode(i)&&r(i),void 0!==n&&void 0!==o)return};return r(e),{emphasis:n,strong:o}}(r),a={bullet:"-"};i&&(a.emphasis=i),s&&(a.strong=s);return o.toMarkdown(n,{extensions:[a,...e.toMarkdownExtensions,j]}).replace(/\n$/,"")};return{$exportSelectionToMarkdown:(n=t.$getSelection())=>{if(null===n||t.$isRangeSelection(n)&&n.isCollapsed())return"";const o=t.$getRoot();return i(r(o,J(e,n)),o)},$exportToMarkdown:e=>{const o=e||t.$getRoot();return i(r(o,n),o)},$exportToMdast:e=>r(e||t.$getRoot(),n)}}function Z(e,n){const o=[];return t.tokenizeRawText(e,{linebreak:()=>o.push(t.$createLineBreakNode()),tab:()=>o.push(t.$createTabNode()),text:e=>{const r=t.$createTextNode(e);n&&r.setFormat(n),o.push(r)}}),o}const ee=new Map;function te(e,t="",n=ee){const{importHandlers:o}=e,r=new Map;function i(e,a){const l=o.get(e.type);if(l){const o=l(e,function(e){let o=r.get(e);return void 0===o&&(o={createText:(t,n)=>Z(t,null==n?e:n),format:e,getDefinition:e=>n.get(e),importChildren:(t,n)=>s(t,e|(n||0)),importNode:(t,n)=>i(t,e|(n||0)),source:t},r.set(e,o)),o}(a));return null==o?[]:Array.isArray(o)?o:[o]}return"children"in e?s(e,a):"value"in e&&"string"==typeof e.value?Z(e.value,a):[]}function s(e,t){const n=[];for(const o of e.children)n.push(...i(o,t));return n}return{$importChildren:s,$importNode:i}}function ne(e){const n=(n,o)=>{const{$importNode:r}=te(e,o,function(e){const t=new Map,n=e=>{if("definition"===e.type&&(t.has(e.identifier)||t.set(e.identifier,{title:e.title,url:e.url})),"children"in e)for(const t of e.children)n(t)};return n(e),t}(n)),i=[];let s=null;const a=()=>{s&&(i.push(s),s=null)};for(const e of n.children)for(const n of r(e,0))v(n)?(a(),i.push(n)):(s||(s=t.$createParagraphNode()),L(s,[n]));return a(),i},o=t=>n(h.fromMarkdown(t,{extensions:e.micromarkExtensions,mdastExtensions:e.mdastExtensions}),t),r=e=>n(e,""),i=(e,n)=>{const o=n||t.$getRoot();var r,i;o.clear(),r=o,i=e.length>0?e:[t.$createParagraphNode()],r.splice(0,0,i),null!==t.$getSelection()&&o.selectStart()};return{$generateNodesFromMarkdown:o,$generateNodesFromMdast:r,$importMarkdown:(e,t)=>i(o(e),t),$importMdast:(e,t)=>i(r(e),t)}}function oe(e,t){let n=e;for(;;){if("heading"===n.type||"paragraph"===n.type){const e=n.children[0];return e&&e.position&&null!=e.position.start.offset?e.position.start.offset:t.length}if(!("children"in n)||0===n.children.length)return t.length;n=n.children[0]}}class re{compiled;importNode;supportsTaskListItems;constructor(e){this.compiled=e,this.importNode=te(e,"").$importNode;const t=this.parse("- [x] a").children[0];this.supportsTaskListItems=null!=t&&"list"===t.type&&!0===t.children[0].checked}get inlineTriggers(){return this.compiled.inlineShortcutTriggers}parse(e){return h.fromMarkdown(e,{extensions:this.compiled.micromarkExtensions,mdastExtensions:this.compiled.mdastExtensions})}importInline(e){return this.importNode(e,0)}scanBlock(e){if(""===e.trim())return null;const t=this.parse(e).children[0];if(!t||!this.compiled.importHandlers.has(t.type))return null;switch(t.type){case"heading":return{kind:"heading",markerLength:oe(t,e),node:t};case"blockquote":return{kind:"blockquote",markerLength:oe(t,e),node:t};case"list":return{kind:"list",markerLength:oe(t,e),node:t};case"code":return{kind:"code",markerLength:e.length,node:t};default:return null}}scanInline(e){if(0===e.length)return null;const t=this.parse(e),n=t.children[t.children.length-1];if(!n||"paragraph"!==n.type)return null;const o=n.children[n.children.length-1];if(!o||!o.position||o.position.end.offset!==e.length||!this.compiled.inlineShortcutTypes.has(o.type))return null;const r=o.position.start.offset??0,i=e[r];return r>0&&e[r-1]===i&&this.compiled.inlineShortcutTriggers.has(i)?null:o}}function ie(e,n){let o=n,r=e.getFirstChild();for(;o>0&&r&&t.$isTextNode(r);){const e=r.getTextContent();if(e.length<=o){const t=r.getNextSibling();o-=e.length,r.remove(),r=t}else r.setTextContent(e.slice(o)),o=0}}function se(e,n){const o="code"===n.kind?e.getTextContent().match(/^[ \t]*(`{3,}|~{3,})/):null;ie(e,n.markerLength);const r=e.getChildren();if("code"===n.kind){const s=i.$createCodeNode(n.node.lang||void 0);return o&&t.$setState(s,E,o[1]),n.node.meta&&t.$setState(s,C,n.node.meta),L(s,r),e.replace(s),s.selectStart(),!0}let s,d;if("heading"===n.kind){const e=L(l.$createHeadingNode(`h${n.node.depth}`),r);s=e,d=e}else if("blockquote"===n.kind){const e=L(l.$createQuoteNode(),r);s=e,d=e}else{const e=n.node,t=q(e),o=e.ordered&&null!=e.start?e.start:1,i=a.$createListNode(t,o),l=e.children[0],c=l&&"listItem"===l.type&&"boolean"==typeof l.checked?l.checked:void 0,u=L(a.$createListItemNode(c),r);L(i,[u]),s=i,d=u}return e.replace(s),d.selectStart(),!0}const ae=/^\[([ xX])\]\s$/;function le(e,n){return t.$isParagraphNode(e)&&t.$isRootOrShadowRoot(e.getParent())&&e.getFirstChild()===n}function de(e,n){const o=new re(n),r=o.inlineTriggers,s=new Set([" ",...r]);return t.mergeRegister(e.registerUpdateListener(({tags:n,dirtyLeaves:l,editorState:d,prevEditorState:c})=>{if(0===l.size||n.has(t.COLLABORATION_TAG)||n.has(t.HISTORIC_TAG))return;if(e.isComposing())return;const u=n.has(t.COMPOSITION_END_TAG),p=d.read(t.$getSelection),f=c.read(t.$getSelection);if(!t.$isRangeSelection(p)||!t.$isRangeSelection(f)||!p.isCollapsed()||p.is(f)&&!u)return;const m=p.anchor.key,h=p.anchor.offset,g=d._nodeMap.get(m);if(!t.$isTextNode(g)||!l.has(m))return;if(!u&&1!==h&&(f.anchor.key!==m||h!==f.anchor.offset+1))return;const x=d.read(()=>g.getTextContent()),$=x[h-1];var k,T;u&&!s.has($)||(" "===$||r.has($))&&(" "===$||(k=x.slice(0,h),")"===(T=$)?k.lastIndexOf("](")>0:-1!==k.lastIndexOf(T,k.length-2)))&&e.update(()=>{const e=t.$getNodeByKey(m);if(!t.$isTextNode(e)||e.hasFormat("code"))return;const n=e.getParent();if(null===n||i.$isCodeNode(n))return;let r=!1;if(" "===$){if(o.supportsTaskListItems&&function(e,t,n){if(t.getFirstChild()!==e)return!1;const o=t.getTextContent().slice(0,n).match(ae);if(!o)return!1;const r="x"===o[1].toLowerCase();if(a.$isListItemNode(t)){const e=t.getParent();return!(!a.$isListNode(e)||"number"===e.getListType()||(ie(t,o[0].length),e.setListType("check"),t.setChecked(r),0))}if(le(t,e)){ie(t,o[0].length);const e=t.getChildren(),n=a.$createListNode("check"),i=L(a.$createListItemNode(r),e);return L(n,[i]),t.replace(n),i.selectStart(),!0}return!1}(e,n,h))r=!0;else if(h<=24&&le(n,e)){const t=o.scanBlock(e.getTextContent().slice(0,h));t&&"code"!==t.kind&&t.markerLength===h&&(r=se(n,t))}}else r=function(e,n,o){const r=e.getTextContent().slice(0,n),i=o.scanInline(r);if(!i||!i.position)return!1;const s=i.position.start.offset??0,a=n;let l;if(s<=0)[l]=e.splitText(a);else{const t=e.splitText(s,a);l=3===t.length?t[1]:t[t.length-1]}const d=o.importInline(i);if(0===d.length)return!1;let c=d[0];l.replace(c);for(let e=1;e<d.length;e++)c.insertAfter(d[e]),c=d[e];if(t.$isTextNode(c)){const e=c.getTextContentSize();c.select(e,e)}else c.selectNext(0,0);return!0}(e,h,o);r&&t.$addUpdateTag(t.HISTORY_PUSH_TAG)})}),e.registerCommand(t.KEY_ENTER_COMMAND,e=>{if(null!==e&&e.shiftKey)return!1;const n=t.$getSelection();if(!t.$isRangeSelection(n)||!n.isCollapsed())return!1;const r=n.anchor.getNode();if(!t.$isTextNode(r)||r.hasFormat("code"))return!1;const s=r.getParent(),a=n.anchor.offset;if(null===s||i.$isCodeNode(s)||!le(s,r)||a!==r.getTextContentSize())return!1;const l=o.scanBlock(s.getTextContent());return!(!l||l.markerLength!==a||!se(s,l))&&(null!==e&&e.preventDefault(),!0)},t.COMMAND_PRIORITY_BEFORE_EDITOR))}const ce=[{$import:(e,n)=>L(t.$createParagraphNode(),n.importChildren(e)),type:"paragraph"},{$import:(e,t)=>t.createText(e.value),type:"text"},{$import:(e,t)=>t.createText(e.value),type:"html"},{$import:(e,t)=>t.createText(e.value,t.format|H),type:"inlineCode"},{$import:P,type:"emphasis"},{$import:z,type:"strong"},{$import:(e,n)=>{let o="\\";if(n.source&&e.position){const{start:t,end:r}=e.position;if(null!=t.offset&&null!=r.offset){const e=n.source.slice(t.offset,r.offset).replace(/\n$/,"");/^ {2,}$/.test(e)&&(o=e)}}return[t.$setState(t.$createLineBreakNode(),M,o)]},type:"break"}],ue=[{$export:(e,n)=>t.$isParagraphNode(e)?{children:n.exportInline(e),type:"paragraph"}:null,type:"paragraph"},{$export:U,type:"text"},{$export:X,type:"linebreak"},{$export:e=>t.$isTabNode(e)?{type:"text",value:"\t"}:null,type:"tab"}],pe=/* @__PURE__ */t.defineExtension({build(e,t){const n=function(e){const t=new Map,n=new Map;for(const n of e.importRules)t.has(n.type)||t.set(n.type,n.$import);for(const t of e.exportRules)n.has(t.type)||n.set(t.type,t.$export);return{exportHandlers:n,importHandlers:t,inlineShortcutTriggers:new Set(e.inlineShortcutTriggers),inlineShortcutTypes:new Set(e.inlineShortcutTypes),mdastExtensions:[...e.mdastExtensions],micromarkExtensions:[...e.micromarkExtensions],toMarkdownExtensions:[...e.toMarkdownExtensions]}}(t),{$generateNodesFromMarkdown:o,$generateNodesFromMdast:r,$importMarkdown:i,$importMdast:s}=ne(n);return{$convertFromMarkdownString:i,$convertFromMdast:s,$generateNodesFromMarkdownString:o,$generateNodesFromMdast:r,registry:n}},config:/* @__PURE__ */t.safeCast({exportRules:ue,importRules:ce,inlineShortcutTriggers:["*","_","`"],inlineShortcutTypes:["emphasis","inlineCode","strong"],mdastExtensions:[],micromarkExtensions:[],toMarkdownExtensions:[]}),mergeConfig(e,n){function o(e,t){return e?[...e,...t]:t}return t.shallowMergeConfig(e,{exportRules:o(n.exportRules,e.exportRules),importRules:o(n.importRules,e.importRules),inlineShortcutTriggers:o(n.inlineShortcutTriggers,e.inlineShortcutTriggers),inlineShortcutTypes:o(n.inlineShortcutTypes,e.inlineShortcutTypes),mdastExtensions:o(n.mdastExtensions,e.mdastExtensions),micromarkExtensions:o(n.micromarkExtensions,e.micromarkExtensions),toMarkdownExtensions:o(n.toMarkdownExtensions,e.toMarkdownExtensions)})},name:"@lexical/mdast/Import"}),fe=/* @__PURE__ */t.defineExtension({dependencies:[/* @__PURE__ */t.configExtension(pe,{exportRules:[{$export:(e,n)=>{if(!l.$isHeadingNode(e))return null;const o={children:n.exportInline(e),depth:D[e.getTag()],type:"heading"};return t.$getState(e,N)&&(o.data={mdastSetext:!0}),o},type:"heading"}],importRules:[{$import:(e,n)=>{const o=l.$createHeadingNode(`h${e.depth}`);if(n.source&&e.position&&(1===e.depth||2===e.depth)){const r=e.position.start.offset;null==r||/^ {0,3}#{1,6}([ \t\r\n]|$)/.test(n.source.slice(r,r+10))||t.$setState(o,N,!0)}return L(o,n.importChildren(e))},type:"heading"}]})],name:"@lexical/mdast/Heading",nodes:[l.HeadingNode]}),me=/* @__PURE__ */t.defineExtension({dependencies:[/* @__PURE__ */t.configExtension(pe,{exportRules:[{$export:(e,t)=>l.$isQuoteNode(e)?{children:e.isShadowRoot()?t.exportChildren(e):t.exportBlocks(e),type:"blockquote"}:null,type:"quote"}],importRules:[{$import:(e,t)=>{const n=l.$createQuoteNode(),o=[];for(const n of e.children)"paragraph"===n.type?(o.length>0&&o.push(O()),o.push(...t.importChildren(n))):o.push(...t.importNode(n));return L(n,o)},type:"blockquote"}]})],name:"@lexical/mdast/Blockquote",nodes:[l.QuoteNode]}),he=/* @__PURE__ */t.defineExtension({dependencies:[fe,me],name:"@lexical/mdast/RichText"}),ge=/* @__PURE__ */t.defineExtension({dependencies:[/* @__PURE__ */t.configExtension(pe,{exportRules:[{$export:(e,t)=>a.$isListNode(e)?Q(e,t):null,type:"list"}],importRules:[{$import:(e,n)=>{const o=q(e),r=e.ordered&&null!=e.start?e.start:1,i=a.$createListNode(o,r),s=e.children[0],l=n.source&&s&&s.position?s.position.start.offset:void 0;if(null!=l){const e=n.source.slice(l,l+16);if("number"===o){const n=e.match(/^\s*\d+([.)])/),o=n&&n[1];"."!==o&&")"!==o||t.$setState(i,T,o)}else{const n=e.match(/^\s*([-*+])/),o=n&&n[1];"-"!==o&&"*"!==o&&"+"!==o||t.$setState(i,k,o)}}return L(i,e.children.flatMap(e=>n.importNode(e)))},type:"list"},{$import:(e,t)=>{const n=a.$createListItemNode("boolean"==typeof e.checked?e.checked:void 0),o=[];for(const r of e.children)"list"===r.type?o.push(L(a.$createListItemNode(),t.importNode(r))):"paragraph"===r.type?(n.getChildrenSize()>0&&L(n,[O()]),L(n,t.importChildren(r))):L(n,t.importNode(r));return[n,...o]},type:"listItem"}]})],name:"@lexical/mdast/List",nodes:[a.ListNode,a.ListItemNode]}),xe=/* @__PURE__ */t.defineExtension({dependencies:[ge,/* @__PURE__ */t.configExtension(pe,{mdastExtensions:[/* @__PURE__ */u.gfmTaskListItemFromMarkdown()],micromarkExtensions:[/* @__PURE__ */m.gfmTaskListItem()],toMarkdownExtensions:[/* @__PURE__ */u.gfmTaskListItemToMarkdown()]})],name:"@lexical/mdast/TaskList"}),$e=/* @__PURE__ */t.defineExtension({dependencies:[/* @__PURE__ */t.configExtension(pe,{exportRules:[{$export:e=>{if(!i.$isCodeNode(e))return null;const n={lang:e.getLanguage()||null,type:"code",value:e.getTextContent()},o=t.$getState(e,C);o&&(n.meta=o);const r=t.$getState(e,E);return r&&(n.data={mdastFence:r}),n},type:"code"}],importRules:[{$import:(e,n)=>{const o=i.$createCodeNode(e.lang||void 0);if(n.source&&e.position&&null!=e.position.start.offset){const r=e.position.start.offset,i=n.source.indexOf("\n",r),s=n.source.slice(r,-1===i?void 0:i).match(/^[ \t]*(`{3,}|~{3,})/);s&&t.$setState(o,E,s[1])}return e.meta&&t.$setState(o,C,e.meta),e.value&&L(o,[t.$createTextNode(e.value)]),o},type:"code"}]})],name:"@lexical/mdast/Code",nodes:[i.CodeNode]}),ke=/* @__PURE__ */t.defineExtension({dependencies:[/* @__PURE__ */t.configExtension(pe,{exportRules:[{$export:(e,n)=>{if(!s.$isLinkNode(e)||s.$isAutoLinkNode(e))return null;const o={children:n.exportInline(e),title:e.getTitle()??null,type:"link",url:e.getURL()},r=t.$getState(e,b);return r&&(o.data={mdastLinkStyle:r}),o},type:"link"}],importRules:[{$import:(e,n)=>{const o=L(s.$createLinkNode(e.url,{title:null==e.title?void 0:e.title}),n.importChildren(e));if(n.source&&e.position&&null!=e.position.start.offset){const r=n.source[e.position.start.offset];t.$setState(o,b,"["===r?"inline":"<"===r?"autolink":"literal")}return o},type:"link"},{$import:(e,t)=>{const n=t.getDefinition(e.identifier);if(n)return L(s.$createLinkNode(n.url,{title:null==n.title?void 0:n.title}),t.importChildren(e));const{position:o}=e;return t.source&&o&&null!=o.start.offset?t.createText(t.source.slice(o.start.offset,o.end.offset)):[...t.createText("["),...t.importChildren(e),...t.createText("]")]},type:"linkReference"},{$import:()=>[],type:"definition"}],inlineShortcutTriggers:[")"],inlineShortcutTypes:["link"]})],name:"@lexical/mdast/Link",nodes:[s.LinkNode]}),Te=/* @__PURE__ */t.defineExtension({dependencies:[ke,/* @__PURE__ */t.configExtension(pe,{mdastExtensions:[/* @__PURE__ */d.gfmAutolinkLiteralFromMarkdown()],micromarkExtensions:[/* @__PURE__ */p.gfmAutolinkLiteral()],toMarkdownExtensions:[/* @__PURE__ */d.gfmAutolinkLiteralToMarkdown()]})],name:"@lexical/mdast/AutolinkLiteral"}),ye=/* @__PURE__ */t.defineExtension({dependencies:[me,
|
|
10
10
|
/* @__PURE__ */
|
|
11
|
-
t.configExtension(
|
|
11
|
+
t.configExtension(pe,{importRules:[{$import:(e,n)=>L(l.$createQuoteNode({shadowRoot:!0}),function(e,n){const o=[];let r=null;const i=()=>{r&&(o.push(r),r=null)};for(const s of e.children)for(const e of n.importNode(s))v(e)?(i(),o.push(e)):(r||(r=t.$createParagraphNode()),L(r,[e]));return i(),o}(e,n)),type:"blockquote"}]})],name:"@lexical/mdast/ShadowRootQuote"}),Se=/* @__PURE__ */t.defineExtension({dependencies:[e.HorizontalRuleExtension,/* @__PURE__ */t.configExtension(pe,{exportRules:[{$export:n=>{if(!e.$isHorizontalRuleNode(n))return null;const o={type:"thematicBreak"},r=t.$getState(n,w);return r&&(o.data={mdastRule:r}),o},type:"horizontalrule"}],importRules:[{$import:(n,o)=>{const r=e.$createHorizontalRuleNode();if(o.source&&n.position&&null!=n.position.start.offset){const e=o.source.slice(n.position.start.offset,n.position.start.offset+4).trimStart()[0];"-"!==e&&"*"!==e&&"_"!==e||t.$setState(r,w,e)}return r},type:"thematicBreak"}]})],name:"@lexical/mdast/HorizontalRule"}),Ne=/* @__PURE__ */t.defineExtension({dependencies:[/* @__PURE__ */t.configExtension(pe,{importRules:[{$import:(e,t)=>t.importChildren(e,_),type:"delete"}],inlineShortcutTriggers:["~"],inlineShortcutTypes:["delete"],mdastExtensions:[/* @__PURE__ */c.gfmStrikethroughFromMarkdown()],micromarkExtensions:[/* @__PURE__ */f.gfmStrikethrough()],toMarkdownExtensions:[/* @__PURE__ */c.gfmStrikethroughToMarkdown()]})],name:"@lexical/mdast/Strikethrough"}),Ee=/* @__PURE__ */t.defineExtension({dependencies:[he,ge,$e,ke,Se],name:"@lexical/mdast/CommonMark"}),Ce=/* @__PURE__ */t.defineExtension({build:(t,n)=>e.namedSignals(n),config:/* @__PURE__ */t.safeCast({disabled:!1}),dependencies:[pe],name:"@lexical/mdast/Shortcuts",register:(t,n,o)=>{const{disabled:r}=o.getOutput();return e.effect(()=>{if(r.value)return;const{registry:n}=e.getExtensionDependencyFromEditor(t,pe).output;return de(t,n)})}});const Me=/* @__PURE__ */t.defineExtension({build(e,t,n){const{registry:o}=n.getDependency(pe).output,{$exportSelectionToMarkdown:r,$exportToMdast:i,$exportToMarkdown:s}=V(o);return{$convertSelectionToMarkdownString:r,$convertToMarkdownString:s,$convertToMdast:i}},dependencies:[pe],name:"@lexical/mdast/Export"});const Re=/* @__PURE__ */t.defineExtension({dependencies:[pe,Me],name:"@lexical/mdast/Mdast"}),we=/* @__PURE__ */t.createState("mdastTableAlign",{parse:e=>Array.isArray(e)?e.map(e=>"center"===e||"left"===e||"right"===e?e:null):[],resetOnCopyNode:!0}),be=/* @__PURE__ */t.defineExtension({dependencies:[/* @__PURE__ */e.configExtension(pe,{exportRules:[{$export:(e,n)=>{if(!g.$isTableNode(e))return null;const o=[];for(const r of e.getChildren()){if(!g.$isTableRowNode(r)||!n.isIncluded(r))continue;const e=[];for(const o of r.getChildren()){if(!g.$isTableCellNode(o))continue;const r=[];for(const e of o.getChildren())t.$isElementNode(e)&&(r.length>0&&r.push({type:"break"}),r.push(...n.exportInline(e)));e.push({children:r,type:"tableCell"})}o.push({children:e,type:"tableRow"})}return{align:t.$getState(e,we),children:o,type:"table"}},type:"table"}],importRules:[{$import:(e,n)=>{const o=g.$createTableNode();return e.align&&e.align.some(e=>null!=e)&&t.$setState(o,we,e.align),e.children.forEach((e,r)=>{const i=g.$createTableRowNode();for(const o of e.children){const e=g.$createTableCellNode(0===r?g.TableCellHeaderStates.ROW:g.TableCellHeaderStates.NO_STATUS),s=t.$createParagraphNode();L(s,n.importChildren(o)),L(e,[s]),L(i,[e])}L(o,[i])}),o},type:"table"}],mdastExtensions:[/* @__PURE__ */x.gfmTableFromMarkdown()],micromarkExtensions:[/* @__PURE__ */$.gfmTable()],toMarkdownExtensions:[/* @__PURE__ */x.gfmTableToMarkdown()]})],name:"@lexical/mdast/Table",nodes:[g.TableNode,g.TableRowNode,g.TableCellNode]}),Le=/* @__PURE__ */t.defineExtension({dependencies:[Ne,xe,Te,be],name:"@lexical/mdast/Gfm"});exports.$convertFromMarkdownString=function(t,n){e.$getExtensionOutput(pe).$convertFromMarkdownString(t,n)},exports.$convertFromMdast=function(t,n){e.$getExtensionOutput(pe).$convertFromMdast(t,n)},exports.$convertSelectionToMarkdownString=function(t){return e.$getExtensionOutput(Me).$convertSelectionToMarkdownString(t)},exports.$convertToMarkdownString=function(t){return e.$getExtensionOutput(Me).$convertToMarkdownString(t)},exports.$convertToMdast=function(t){return e.$getExtensionOutput(Me).$convertToMdast(t)},exports.$generateNodesFromMarkdownString=function(t){return e.$getExtensionOutput(pe).$generateNodesFromMarkdownString(t)},exports.$generateNodesFromMdast=function(t){return e.$getExtensionOutput(pe).$generateNodesFromMdast(t)},exports.MdastAutolinkLiteralExtension=Te,exports.MdastBlockquoteExtension=me,exports.MdastCodeExtension=$e,exports.MdastCommonMarkExtension=Ee,exports.MdastExportExtension=Me,exports.MdastExtension=Re,exports.MdastGfmExtension=Le,exports.MdastHeadingExtension=fe,exports.MdastHorizontalRuleExtension=Se,exports.MdastImportExtension=pe,exports.MdastLinkExtension=ke,exports.MdastListExtension=ge,exports.MdastRichTextExtension=he,exports.MdastShadowRootQuoteExtension=ye,exports.MdastShortcutsExtension=Ce,exports.MdastStrikethroughExtension=Ne,exports.MdastTableExtension=be,exports.MdastTaskListExtension=xe;
|
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{HorizontalRuleExtension as t,effect as e,getExtensionDependencyFromEditor as n,namedSignals as r,$getExtensionOutput as o,$createHorizontalRuleNode as i,$isHorizontalRuleNode as s,configExtension as l}from"@lexical/extension";import{createState as a,$createParagraphNode as c,$setState as d,$createLineBreakNode as u,$isParagraphNode as p,$isTextNode as m,$isLineBreakNode as f,$getState as h,$isTabNode as g,$createTextNode as x,TEXT_TYPE_TO_FORMAT as k,$isElementNode as y,$isDecoratorNode as C,$getRoot as $,$isRangeSelection as T,$getSelection as S,tokenizeRawText as M,$createTabNode as v,mergeRegister as b,COLLABORATION_TAG as w,HISTORIC_TAG as E,COMPOSITION_END_TAG as R,$getNodeByKey as N,$addUpdateTag as I,HISTORY_PUSH_TAG as L,KEY_ENTER_COMMAND as F,COMMAND_PRIORITY_BEFORE_EDITOR as O,$isRootOrShadowRoot as B,defineExtension as _,shallowMergeConfig as A,safeCast as H,configExtension as q}from"lexical";import{$sliceSelectedTextNodeContent as z}from"@lexical/selection";import{toMarkdown as P,defaultHandlers as D}from"mdast-util-to-markdown";import{toString as U}from"mdast-util-to-string";import{$createCodeNode as j,$isCodeNode as G,CodeNode as K}from"@lexical/code-core";import{$createLinkNode as Q,$isLinkNode as W,$isAutoLinkNode as X,LinkNode as J}from"@lexical/link";import{$createListNode as V,$createListItemNode as Y,$isListNode as Z,$isListItemNode as tt,ListNode as et,ListItemNode as nt}from"@lexical/list";import{$createHeadingNode as rt,$isHeadingNode as ot,$createQuoteNode as it,$isQuoteNode as st,HeadingNode as lt,QuoteNode as at}from"@lexical/rich-text";import{gfmAutolinkLiteralToMarkdown as ct,gfmAutolinkLiteralFromMarkdown as dt}from"mdast-util-gfm-autolink-literal";import{gfmStrikethroughToMarkdown as ut,gfmStrikethroughFromMarkdown as pt}from"mdast-util-gfm-strikethrough";import{gfmTaskListItemToMarkdown as mt,gfmTaskListItemFromMarkdown as ft}from"mdast-util-gfm-task-list-item";import{gfmAutolinkLiteral as ht}from"micromark-extension-gfm-autolink-literal";import{gfmStrikethrough as gt}from"micromark-extension-gfm-strikethrough";import{gfmTaskListItem as xt}from"micromark-extension-gfm-task-list-item";import{fromMarkdown as kt}from"mdast-util-from-markdown";import{TableNode as yt,TableRowNode as Ct,TableCellNode as $t,$createTableNode as Tt,$createTableRowNode as St,$createTableCellNode as Mt,TableCellHeaderStates as vt,$isTableNode as bt,$isTableRowNode as wt,$isTableCellNode as Et}from"@lexical/table";import{gfmTableToMarkdown as Rt,gfmTableFromMarkdown as Nt}from"mdast-util-gfm-table";import{gfmTable as It}from"micromark-extension-gfm-table";const Lt=/* @__PURE__ */a("mdastListMarker",{parse:t=>"-"===t||"*"===t||"+"===t?t:"",resetOnCopyNode:!0}),Ft=/* @__PURE__ */a("mdastOrderedMarker",{parse:t=>"."===t||")"===t?t:"",resetOnCopyNode:!0}),Ot=/* @__PURE__ */a("mdastEmphasisMarker",{parse:t=>"_"===t?"_":"",resetOnCopyNode:!0}),Bt=/* @__PURE__ */a("mdastStrongMarker",{parse:t=>"_"===t?"_":"",resetOnCopyNode:!0}),_t=/* @__PURE__ */a("mdastSetext",{parse:t=>!0===t,resetOnCopyNode:!0}),At=/* @__PURE__ */a("mdastCodeFence",{parse:t=>"string"==typeof t&&/^(`{3,}|~{3,})$/.test(t)?t:"",resetOnCopyNode:!0}),Ht=/* @__PURE__ */a("mdastCodeMeta",{parse:t=>"string"==typeof t?t:"",resetOnCopyNode:!0}),qt=/* @__PURE__ */a("mdastHardLineBreak",{parse:t=>"string"==typeof t&&/^(\\| {2,})$/.test(t)?t:"",resetOnCopyNode:!0}),zt=/* @__PURE__ */a("mdastParagraphBreak",{parse:t=>!0===t,resetOnCopyNode:!0}),Pt=/* @__PURE__ */a("mdastHrMarker",{parse:t=>"-"===t||"*"===t||"_"===t?t:"",resetOnCopyNode:!0}),Dt=/* @__PURE__ */a("mdastLinkStyle",{parse:t=>"inline"===t||"autolink"===t||"literal"===t?t:"",resetOnCopyNode:!0});function Ut(t,e){return t.splice(t.getChildrenSize(),0,e)}function jt(t){return(y(t)||C(t))&&!t.isInline()}function Gt(){return d(u(),zt,!0)}const Kt=k.bold,Qt=k.italic,Wt=k.strikethrough,Xt=k.code,Jt=Kt|Qt|Wt|Xt;function Vt(t){if(t.ordered)return"number";for(const e of t.children)if("listItem"===e.type&&null!=e.checked)return"check";return"bullet"}function Yt(t,e){return(n,r)=>{const o=r.importChildren(n,t);if("_"===function(t,e){if(t.source&&e.position&&null!=e.position.start.offset)return t.source[e.position.start.offset]}(r,n))for(const t of o)m(t)&&d(t,e,"_");return o}}const Zt=/* @__PURE__ */Yt(Qt,Ot),te=/* @__PURE__ */Yt(Kt,Bt),ee={h1:1,h2:2,h3:3,h4:4,h5:5,h6:6};function ne(t,e){const n=t.getListType(),r={children:[],ordered:"number"===n,spread:!1,start:"number"===n?t.getStart():void 0,type:"list"};if("number"===n){const e=h(t,Ft);e&&(r.data={mdastBulletOrdered:e})}else{const e=h(t,Lt);e&&(r.data={mdastBullet:e})}let o=null;for(const i of t.getChildren()){if(!tt(i)||!e.isIncluded(i))continue;const t=i.getFirstChild();if(1===i.getChildrenSize()&&Z(t)){const n=ne(t,e);o?o.children.push(n):r.children.push({children:[n],spread:!1,type:"listItem"});continue}const s={checked:"check"===n?i.getChecked()??!1:null,children:e.exportBlocks(i),spread:!1,type:"listItem"};r.children.push(s),o=s}return r}function re(t,e){let n=e&Xt?{type:"inlineCode",value:t}:{type:"text",value:t};return e&Qt&&(n={children:[n],type:"emphasis"}),e&Kt&&(n={children:[n],type:"strong"}),e&Wt&&(n={children:[n],type:"delete"}),n}const oe=t=>m(t)?re(t.getTextContent(),t.getFormat()&Jt):null,ie=t=>f(t)?{data:{mdastBreak:h(t,qt)},type:"break"}:null;function se(t,e,n){const{options:r}=t,o={};for(const t of Object.keys(e))o[t]=r[t],r[t]=e[t];try{return n()}finally{for(const t of Object.keys(o))r[t]=o[t]}}const le={handlers:{break(t,e,n,r){const o=D.break(t,e,n,r);if("\\\n"!==o)return o;const i=t.data&&t.data.mdastBreak;return i?/^ {2,}$/.test(i)?`${i}\n`:o:"\n"},code(t,e,n,r){const o=t.data&&t.data.mdastFence;return o?se(n,{fence:"~"===o[0]?"~":"`",fences:!0},()=>D.code(t,e,n,r)):D.code(t,e,n,r)},heading:(t,e,n,r)=>t.data&&!0===t.data.mdastSetext?se(n,{setext:!0},()=>D.heading(t,e,n,r)):D.heading(t,e,n,r),link(t,e,n,r){const o=t.data&&t.data.mdastLinkStyle;return"literal"===o&&null==t.title?U(t):"inline"===o?se(n,{resourceLink:!0},()=>D.link(t,e,n,r)):D.link(t,e,n,r)},list(t,e,n,r){if(t.ordered){const o=t.data&&t.data.mdastBulletOrdered;return null==o?D.list(t,e,n,r):se(n,{bulletOrdered:o},()=>D.list(t,e,n,r))}const o=t.data&&t.data.mdastBullet;return null==o?D.list(t,e,n,r):se(n,{bullet:o,bulletOther:"-"===o?"*":"-"},()=>D.list(t,e,n,r))},thematicBreak(t,e,n){const r=t.data&&t.data.mdastRule;return"-"!==r&&"*"!==r&&"_"!==r?D.thematicBreak(t,e,n):se(n,{rule:r},()=>D.thematicBreak(t,e,n))}}};class ae{format=-1;value="";push(t,e){if(!m(t))return!1;const n=t.getFormat()&Jt;return n===this.format?this.value+=t.getTextContent():(this.flushInto(e),this.format=n,this.value=t.getTextContent()),!0}flushInto(t){this.format>=0&&t.push(re(this.value,this.format)),this.format=-1,this.value=""}}function ce(t,e=null){const{exportHandlers:n}=t;let r=0;function o(t){const e=n.get(t.getType());return void 0===e||e===oe}function i(t){return null===e||y(t)?t:t.isSelected(e)?(r++,m(t)?z(e,t,"clone"):t):null}function s(t,n){const o=null!==e&&t.isSelected(e);o&&r++;const i=r,s=a(t);(null===e||o||r>i)&&n.push(...s)}const l={exportBlocks:t=>function(t){const e=[];let n=[];const r=new ae,l=()=>{r.flushInto(n),n.length>0&&(e.push({children:n,type:"paragraph"}),n=[])};for(const c of t.getChildren()){const t=i(c);if(null!==t)if(f(t)){const e=ie(t);h(t,zt)||null===e?l():(r.flushInto(n),n.push(e))}else{if(o(t)&&r.push(t,n))continue;jt(t)?(l(),y(t)?s(t,e):e.push(...a(t))):y(t)?(r.flushInto(n),s(t,n)):(r.flushInto(n),n.push(...a(t)))}}l(),0===e.length&&e.push({children:[],type:"paragraph"});return e}(t),exportChildren:t=>{const e=[];for(const n of t.getChildren()){const t=i(n);null!==t&&(y(t)?s(t,e):e.push(...a(t)))}return e},exportInline:t=>function(t){const e=[],n=new ae;for(const r of t.getChildren()){const t=i(r);null!==t&&(o(t)&&n.push(t,e)||(n.flushInto(e),y(t)?s(t,e):e.push(...a(t))))}return n.flushInto(e),e}(t),isIncluded:function t(n){if(null===e||n.isSelected(e))return!0;if(y(n))for(const e of n.getChildren())if(t(e))return!0;return!1}};function a(t){const e=n.get(t.getType());if(e){const n=e(t,l);if(null!=n)return Array.isArray(n)?n:[n]}const r=oe(t);if(null!==r)return[r];const o=ie(t);if(null!==o)return[o];if(y(t))return l.exportChildren(t);const i=t.getTextContent();return i?[{type:"text",value:i}]:[]}return{exportChildren:l.exportChildren}}function de(t){const e=ce(t),n=(t,e)=>({children:e.exportChildren(t),type:"root"}),r=(e,n)=>{const{emphasis:r,strong:o}=function(t){let e,n;const r=t=>{for(const o of t.getChildren())if(m(o)?(void 0===e&&o.hasFormat("italic")&&"_"===h(o,Ot)&&(e="_"),void 0===n&&o.hasFormat("bold")&&"_"===h(o,Bt)&&(n="_")):y(o)&&r(o),void 0!==e&&void 0!==n)return};return r(t),{emphasis:e,strong:n}}(n),i={bullet:"-"};r&&(i.emphasis=r),o&&(i.strong=o);return P(e,{extensions:[i,...t.toMarkdownExtensions,le]}).replace(/\n$/,"")};return{$exportSelectionToMarkdown:(e=S())=>{if(null===e||T(e)&&e.isCollapsed())return"";const o=$();return r(n(o,ce(t,e)),o)},$exportToMarkdown:t=>{const o=t||$();return r(n(o,e),o)},$exportToMdast:t=>n(t||$(),e)}}function ue(t,e){const n=[];return M(t,{linebreak:()=>n.push(u()),tab:()=>n.push(v()),text:t=>{const r=x(t);e&&r.setFormat(e),n.push(r)}}),n}const pe=new Map;function me(t,e="",n=pe){const{importHandlers:r}=t,o=new Map;function i(t,l){const a=r.get(t.type);if(a){const r=a(t,function(t){let r=o.get(t);return void 0===r&&(r={createText:(e,n)=>ue(e,null==n?t:n),format:t,getDefinition:t=>n.get(t),importChildren:(e,n)=>s(e,t|(n||0)),importNode:(e,n)=>i(e,t|(n||0)),source:e},o.set(t,r)),r}(l));return null==r?[]:Array.isArray(r)?r:[r]}return"children"in t?s(t,l):"value"in t&&"string"==typeof t.value?ue(t.value,l):[]}function s(t,e){const n=[];for(const r of t.children)n.push(...i(r,e));return n}return{$importChildren:s,$importNode:i}}function fe(t){const e=(e,n)=>{const{$importNode:r}=me(t,n,function(t){const e=new Map,n=t=>{if("definition"===t.type&&(e.has(t.identifier)||e.set(t.identifier,{title:t.title,url:t.url})),"children"in t)for(const e of t.children)n(e)};return n(t),e}(e)),o=[];let i=null;const s=()=>{i&&(o.push(i),i=null)};for(const t of e.children)for(const e of r(t,0))jt(e)?(s(),o.push(e)):(i||(i=c()),Ut(i,[e]));return s(),o},n=n=>e(kt(n,{extensions:t.micromarkExtensions,mdastExtensions:t.mdastExtensions}),n),r=t=>e(t,""),o=(t,e)=>{const n=e||$();var r,o;n.clear(),r=n,o=t.length>0?t:[c()],r.splice(0,0,o),null!==S()&&n.selectStart()};return{$generateNodesFromMarkdown:n,$generateNodesFromMdast:r,$importMarkdown:(t,e)=>o(n(t),e),$importMdast:(t,e)=>o(r(t),e)}}function he(t,e){let n=t;for(;;){if("heading"===n.type||"paragraph"===n.type){const t=n.children[0];return t&&t.position&&null!=t.position.start.offset?t.position.start.offset:e.length}if(!("children"in n)||0===n.children.length)return e.length;n=n.children[0]}}class ge{compiled;importNode;supportsTaskListItems;constructor(t){this.compiled=t,this.importNode=me(t,"").$importNode;const e=this.parse("- [x] a").children[0];this.supportsTaskListItems=null!=e&&"list"===e.type&&!0===e.children[0].checked}get inlineTriggers(){return this.compiled.inlineShortcutTriggers}parse(t){return kt(t,{extensions:this.compiled.micromarkExtensions,mdastExtensions:this.compiled.mdastExtensions})}importInline(t){return this.importNode(t,0)}scanBlock(t){if(""===t.trim())return null;const e=this.parse(t).children[0];if(!e||!this.compiled.importHandlers.has(e.type))return null;switch(e.type){case"heading":return{kind:"heading",markerLength:he(e,t),node:e};case"blockquote":return{kind:"blockquote",markerLength:he(e,t),node:e};case"list":return{kind:"list",markerLength:he(e,t),node:e};case"code":return{kind:"code",markerLength:t.length,node:e};default:return null}}scanInline(t){if(0===t.length)return null;const e=this.parse(t),n=e.children[e.children.length-1];if(!n||"paragraph"!==n.type)return null;const r=n.children[n.children.length-1];if(!r||!r.position||r.position.end.offset!==t.length||!this.compiled.inlineShortcutTypes.has(r.type))return null;const o=r.position.start.offset??0,i=t[o];return o>0&&t[o-1]===i&&this.compiled.inlineShortcutTriggers.has(i)?null:r}}function xe(t,e){let n=e,r=t.getFirstChild();for(;n>0&&r&&m(r);){const t=r.getTextContent();if(t.length<=n){const e=r.getNextSibling();n-=t.length,r.remove(),r=e}else r.setTextContent(t.slice(n)),n=0}}function ke(t,e){const n="code"===e.kind?t.getTextContent().match(/^[ \t]*(`{3,}|~{3,})/):null;xe(t,e.markerLength);const r=t.getChildren();if("code"===e.kind){const o=j(e.node.lang||void 0);return n&&d(o,At,n[1]),e.node.meta&&d(o,Ht,e.node.meta),Ut(o,r),t.replace(o),o.selectStart(),!0}let o,i;if("heading"===e.kind){const t=Ut(rt(`h${e.node.depth}`),r);o=t,i=t}else if("blockquote"===e.kind){const t=Ut(it(),r);o=t,i=t}else{const t=e.node,n=Vt(t),s=t.ordered&&null!=t.start?t.start:1,l=V(n,s),a=t.children[0],c=a&&"listItem"===a.type&&"boolean"==typeof a.checked?a.checked:void 0,d=Ut(Y(c),r);Ut(l,[d]),o=l,i=d}return t.replace(o),i.selectStart(),!0}const ye=/^\[([ xX])\]\s$/;function Ce(t,e){return p(t)&&B(t.getParent())&&t.getFirstChild()===e}function $e(t,e){const n=new ge(e),r=n.inlineTriggers,o=new Set([" ",...r]);return b(t.registerUpdateListener(({tags:e,dirtyLeaves:i,editorState:s,prevEditorState:l})=>{if(0===i.size||e.has(w)||e.has(E))return;if(t.isComposing())return;const a=e.has(R),c=s.read(S),d=l.read(S);if(!T(c)||!T(d)||!c.isCollapsed()||c.is(d)&&!a)return;const u=c.anchor.key,p=c.anchor.offset,f=s._nodeMap.get(u);if(!m(f)||!i.has(u))return;if(!a&&1!==p&&(d.anchor.key!==u||p!==d.anchor.offset+1))return;const h=s.read(()=>f.getTextContent()),g=h[p-1];var x,k;a&&!o.has(g)||(" "===g||r.has(g))&&(" "===g||(x=h.slice(0,p),")"===(k=g)?x.lastIndexOf("](")>0:-1!==x.lastIndexOf(k,x.length-2)))&&t.update(()=>{const t=N(u);if(!m(t)||t.hasFormat("code"))return;const e=t.getParent();if(null===e||G(e))return;let r=!1;if(" "===g){if(n.supportsTaskListItems&&function(t,e,n){if(e.getFirstChild()!==t)return!1;const r=e.getTextContent().slice(0,n).match(ye);if(!r)return!1;const o="x"===r[1].toLowerCase();if(tt(e)){const t=e.getParent();return!(!Z(t)||"number"===t.getListType()||(xe(e,r[0].length),t.setListType("check"),e.setChecked(o),0))}if(Ce(e,t)){xe(e,r[0].length);const t=e.getChildren(),n=V("check"),i=Ut(Y(o),t);return Ut(n,[i]),e.replace(n),i.selectStart(),!0}return!1}(t,e,p))r=!0;else if(p<=24&&Ce(e,t)){const o=n.scanBlock(t.getTextContent().slice(0,p));o&&"code"!==o.kind&&o.markerLength===p&&(r=ke(e,o))}}else r=function(t,e,n){const r=t.getTextContent().slice(0,e),o=n.scanInline(r);if(!o||!o.position)return!1;const i=o.position.start.offset??0,s=e;let l;if(i<=0)[l]=t.splitText(s);else{const e=t.splitText(i,s);l=3===e.length?e[1]:e[e.length-1]}const a=n.importInline(o);if(0===a.length)return!1;let c=a[0];l.replace(c);for(let t=1;t<a.length;t++)c.insertAfter(a[t]),c=a[t];if(m(c)){const t=c.getTextContentSize();c.select(t,t)}else c.selectNext(0,0);return!0}(t,p,n);r&&I(L)})}),t.registerCommand(F,t=>{if(null!==t&&t.shiftKey)return!1;const e=S();if(!T(e)||!e.isCollapsed())return!1;const r=e.anchor.getNode();if(!m(r)||r.hasFormat("code"))return!1;const o=r.getParent(),i=e.anchor.offset;if(null===o||G(o)||!Ce(o,r)||i!==r.getTextContentSize())return!1;const s=n.scanBlock(o.getTextContent());return!(!s||s.markerLength!==i||!ke(o,s))&&(null!==t&&t.preventDefault(),!0)},O))}const Te=[{$import:(t,e)=>Ut(c(),e.importChildren(t)),type:"paragraph"},{$import:(t,e)=>e.createText(t.value),type:"text"},{$import:(t,e)=>e.createText(t.value),type:"html"},{$import:(t,e)=>e.createText(t.value,e.format|Xt),type:"inlineCode"},{$import:Zt,type:"emphasis"},{$import:te,type:"strong"},{$import:(t,e)=>{let n="\\";if(e.source&&t.position){const{start:r,end:o}=t.position;if(null!=r.offset&&null!=o.offset){const t=e.source.slice(r.offset,o.offset).replace(/\n$/,"");/^ {2,}$/.test(t)&&(n=t)}}return[d(u(),qt,n)]},type:"break"}],Se=[{$export:(t,e)=>p(t)?{children:e.exportInline(t),type:"paragraph"}:null,type:"paragraph"},{$export:oe,type:"text"},{$export:ie,type:"linebreak"},{$export:t=>g(t)?{type:"text",value:"\t"}:null,type:"tab"}],Me=/* @__PURE__ */_({build(t,e){const n=function(t){const e=new Map,n=new Map;for(const n of t.importRules)e.has(n.type)||e.set(n.type,n.$import);for(const e of t.exportRules)n.has(e.type)||n.set(e.type,e.$export);return{exportHandlers:n,importHandlers:e,inlineShortcutTriggers:new Set(t.inlineShortcutTriggers),inlineShortcutTypes:new Set(t.inlineShortcutTypes),mdastExtensions:[...t.mdastExtensions],micromarkExtensions:[...t.micromarkExtensions],toMarkdownExtensions:[...t.toMarkdownExtensions]}}(e),{$generateNodesFromMarkdown:r,$generateNodesFromMdast:o,$importMarkdown:i,$importMdast:s}=fe(n);return{$convertFromMarkdownString:i,$convertFromMdast:s,$generateNodesFromMarkdownString:r,$generateNodesFromMdast:o,registry:n}},config:/* @__PURE__ */H({exportRules:Se,importRules:Te,inlineShortcutTriggers:["*","_","`"],inlineShortcutTypes:["emphasis","inlineCode","strong"],mdastExtensions:[],micromarkExtensions:[],toMarkdownExtensions:[]}),mergeConfig(t,e){function n(t,e){return t?[...t,...e]:e}return A(t,{exportRules:n(e.exportRules,t.exportRules),importRules:n(e.importRules,t.importRules),inlineShortcutTriggers:n(e.inlineShortcutTriggers,t.inlineShortcutTriggers),inlineShortcutTypes:n(e.inlineShortcutTypes,t.inlineShortcutTypes),mdastExtensions:n(e.mdastExtensions,t.mdastExtensions),micromarkExtensions:n(e.micromarkExtensions,t.micromarkExtensions),toMarkdownExtensions:n(e.toMarkdownExtensions,t.toMarkdownExtensions)})},name:"@lexical/mdast/Import"}),ve=/* @__PURE__ */_({dependencies:[/* @__PURE__ */q(Me,{exportRules:[{$export:(t,e)=>{if(!ot(t))return null;const n={children:e.exportInline(t),depth:ee[t.getTag()],type:"heading"};return h(t,_t)&&(n.data={mdastSetext:!0}),n},type:"heading"}],importRules:[{$import:(t,e)=>{const n=rt(`h${t.depth}`);if(e.source&&t.position&&(1===t.depth||2===t.depth)){const r=t.position.start.offset;null==r||/^ {0,3}#{1,6}([ \t\r\n]|$)/.test(e.source.slice(r,r+10))||d(n,_t,!0)}return Ut(n,e.importChildren(t))},type:"heading"}]})],name:"@lexical/mdast/Heading",nodes:[lt]}),be=/* @__PURE__ */_({dependencies:[/* @__PURE__ */q(Me,{exportRules:[{$export:(t,e)=>st(t)?{children:t.isShadowRoot()?e.exportChildren(t):e.exportBlocks(t),type:"blockquote"}:null,type:"quote"}],importRules:[{$import:(t,e)=>{const n=it(),r=[];for(const n of t.children)"paragraph"===n.type?(r.length>0&&r.push(Gt()),r.push(...e.importChildren(n))):r.push(...e.importNode(n));return Ut(n,r)},type:"blockquote"}]})],name:"@lexical/mdast/Blockquote",nodes:[at]}),we=/* @__PURE__ */_({dependencies:[ve,be],name:"@lexical/mdast/RichText"}),Ee=/* @__PURE__ */_({dependencies:[/* @__PURE__ */q(Me,{exportRules:[{$export:(t,e)=>Z(t)?ne(t,e):null,type:"list"}],importRules:[{$import:(t,e)=>{const n=Vt(t),r=t.ordered&&null!=t.start?t.start:1,o=V(n,r),i=t.children[0],s=e.source&&i&&i.position?i.position.start.offset:void 0;if(null!=s){const t=e.source.slice(s,s+16);if("number"===n){const e=t.match(/^\s*\d+([.)])/),n=e&&e[1];"."!==n&&")"!==n||d(o,Ft,n)}else{const e=t.match(/^\s*([-*+])/),n=e&&e[1];"-"!==n&&"*"!==n&&"+"!==n||d(o,Lt,n)}}return Ut(o,t.children.flatMap(t=>e.importNode(t)))},type:"list"},{$import:(t,e)=>{const n=Y("boolean"==typeof t.checked?t.checked:void 0),r=[];for(const o of t.children)"list"===o.type?r.push(Ut(Y(),e.importNode(o))):"paragraph"===o.type?(n.getChildrenSize()>0&&Ut(n,[Gt()]),Ut(n,e.importChildren(o))):Ut(n,e.importNode(o));return[n,...r]},type:"listItem"}]})],name:"@lexical/mdast/List",nodes:[et,nt]}),Re=/* @__PURE__ */_({dependencies:[Ee,/* @__PURE__ */q(Me,{mdastExtensions:[/* @__PURE__ */ft()],micromarkExtensions:[/* @__PURE__ */xt()],toMarkdownExtensions:[/* @__PURE__ */mt()]})],name:"@lexical/mdast/TaskList"}),Ne=/* @__PURE__ */_({dependencies:[/* @__PURE__ */q(Me,{exportRules:[{$export:t=>{if(!G(t))return null;const e={lang:t.getLanguage()||null,type:"code",value:t.getTextContent()},n=h(t,Ht);n&&(e.meta=n);const r=h(t,At);return r&&(e.data={mdastFence:r}),e},type:"code"}],importRules:[{$import:(t,e)=>{const n=j(t.lang||void 0);if(e.source&&t.position&&null!=t.position.start.offset){const r=t.position.start.offset,o=e.source.indexOf("\n",r),i=e.source.slice(r,-1===o?void 0:o).match(/^[ \t]*(`{3,}|~{3,})/);i&&d(n,At,i[1])}return t.meta&&d(n,Ht,t.meta),t.value&&Ut(n,[x(t.value)]),n},type:"code"}]})],name:"@lexical/mdast/Code",nodes:[K]}),Ie=/* @__PURE__ */_({dependencies:[/* @__PURE__ */q(Me,{exportRules:[{$export:(t,e)=>{if(!W(t)||X(t))return null;const n={children:e.exportInline(t),title:t.getTitle()??null,type:"link",url:t.getURL()},r=h(t,Dt);return r&&(n.data={mdastLinkStyle:r}),n},type:"link"}],importRules:[{$import:(t,e)=>{const n=Ut(Q(t.url,{title:null==t.title?void 0:t.title}),e.importChildren(t));if(e.source&&t.position&&null!=t.position.start.offset){const r=e.source[t.position.start.offset];d(n,Dt,"["===r?"inline":"<"===r?"autolink":"literal")}return n},type:"link"},{$import:(t,e)=>{const n=e.getDefinition(t.identifier);if(n)return Ut(Q(n.url,{title:null==n.title?void 0:n.title}),e.importChildren(t));const{position:r}=t;return e.source&&r&&null!=r.start.offset?e.createText(e.source.slice(r.start.offset,r.end.offset)):[...e.createText("["),...e.importChildren(t),...e.createText("]")]},type:"linkReference"},{$import:()=>[],type:"definition"}],inlineShortcutTriggers:[")"],inlineShortcutTypes:["link"]})],name:"@lexical/mdast/Link",nodes:[J]}),Le=/* @__PURE__ */_({dependencies:[Ie,/* @__PURE__ */q(Me,{mdastExtensions:[/* @__PURE__ */dt()],micromarkExtensions:[/* @__PURE__ */ht()],toMarkdownExtensions:[/* @__PURE__ */ct()]})],name:"@lexical/mdast/AutolinkLiteral"}),Fe=/* @__PURE__ */_({dependencies:[be,
|
|
9
|
+
import{HorizontalRuleExtension as t,effect as e,getExtensionDependencyFromEditor as n,namedSignals as r,$getExtensionOutput as o,$createHorizontalRuleNode as i,$isHorizontalRuleNode as s,configExtension as l}from"@lexical/extension";import{createState as a,$createParagraphNode as c,$setState as u,$createLineBreakNode as d,$isParagraphNode as p,$isTextNode as m,$isLineBreakNode as f,$getState as h,$isTabNode as g,$createTextNode as x,TEXT_TYPE_TO_FORMAT as k,$isElementNode as y,$isDecoratorNode as C,$getRoot as $,$isRangeSelection as T,$getSelection as S,tokenizeRawText as v,$createTabNode as M,mergeRegister as b,COLLABORATION_TAG as w,HISTORIC_TAG as E,COMPOSITION_END_TAG as R,$getNodeByKey as N,$addUpdateTag as I,HISTORY_PUSH_TAG as L,KEY_ENTER_COMMAND as F,COMMAND_PRIORITY_BEFORE_EDITOR as O,$isRootOrShadowRoot as B,defineExtension as _,shallowMergeConfig as A,safeCast as H,configExtension as q}from"lexical";import{$sliceSelectedTextNodeContent as z}from"@lexical/selection";import{toMarkdown as P,defaultHandlers as D}from"mdast-util-to-markdown";import{toString as U}from"mdast-util-to-string";import{$createCodeNode as j,$isCodeNode as G,CodeNode as K}from"@lexical/code-core";import{$createLinkNode as Q,$isLinkNode as W,$isAutoLinkNode as X,LinkNode as J}from"@lexical/link";import{$createListNode as V,$createListItemNode as Y,$isListNode as Z,$isListItemNode as tt,ListNode as et,ListItemNode as nt}from"@lexical/list";import{$createHeadingNode as rt,$isHeadingNode as ot,$createQuoteNode as it,$isQuoteNode as st,HeadingNode as lt,QuoteNode as at}from"@lexical/rich-text";import{gfmAutolinkLiteralToMarkdown as ct,gfmAutolinkLiteralFromMarkdown as ut}from"mdast-util-gfm-autolink-literal";import{gfmStrikethroughToMarkdown as dt,gfmStrikethroughFromMarkdown as pt}from"mdast-util-gfm-strikethrough";import{gfmTaskListItemToMarkdown as mt,gfmTaskListItemFromMarkdown as ft}from"mdast-util-gfm-task-list-item";import{gfmAutolinkLiteral as ht}from"micromark-extension-gfm-autolink-literal";import{gfmStrikethrough as gt}from"micromark-extension-gfm-strikethrough";import{gfmTaskListItem as xt}from"micromark-extension-gfm-task-list-item";import{fromMarkdown as kt}from"mdast-util-from-markdown";import{TableNode as yt,TableRowNode as Ct,TableCellNode as $t,$createTableNode as Tt,$createTableRowNode as St,$createTableCellNode as vt,TableCellHeaderStates as Mt,$isTableNode as bt,$isTableRowNode as wt,$isTableCellNode as Et}from"@lexical/table";import{gfmTableToMarkdown as Rt,gfmTableFromMarkdown as Nt}from"mdast-util-gfm-table";import{gfmTable as It}from"micromark-extension-gfm-table";const Lt=/* @__PURE__ */a("mdastListMarker",{parse:t=>"-"===t||"*"===t||"+"===t?t:"",resetOnCopyNode:!0}),Ft=/* @__PURE__ */a("mdastOrderedMarker",{parse:t=>"."===t||")"===t?t:"",resetOnCopyNode:!0}),Ot=/* @__PURE__ */a("mdastEmphasisMarker",{parse:t=>"_"===t?"_":"",resetOnCopyNode:!0}),Bt=/* @__PURE__ */a("mdastStrongMarker",{parse:t=>"_"===t?"_":"",resetOnCopyNode:!0}),_t=/* @__PURE__ */a("mdastSetext",{parse:t=>!0===t,resetOnCopyNode:!0}),At=/* @__PURE__ */a("mdastCodeFence",{parse:t=>"string"==typeof t&&/^(`{3,}|~{3,})$/.test(t)?t:"",resetOnCopyNode:!0}),Ht=/* @__PURE__ */a("mdastCodeMeta",{parse:t=>"string"==typeof t?t:"",resetOnCopyNode:!0}),qt=/* @__PURE__ */a("mdastHardLineBreak",{parse:t=>"string"==typeof t&&/^(\\| {2,})$/.test(t)?t:"",resetOnCopyNode:!0}),zt=/* @__PURE__ */a("mdastParagraphBreak",{parse:t=>!0===t,resetOnCopyNode:!0}),Pt=/* @__PURE__ */a("mdastHrMarker",{parse:t=>"-"===t||"*"===t||"_"===t?t:"",resetOnCopyNode:!0}),Dt=/* @__PURE__ */a("mdastLinkStyle",{parse:t=>"inline"===t||"autolink"===t||"literal"===t?t:"",resetOnCopyNode:!0});function Ut(t,e){return t.splice(t.getChildrenSize(),0,e)}function jt(t){return(y(t)||C(t))&&!t.isInline()}function Gt(){return u(d(),zt,!0)}const Kt=k.bold,Qt=k.italic,Wt=k.strikethrough,Xt=k.code,Jt=Kt|Qt|Wt|Xt;function Vt(t){if(t.ordered)return"number";for(const e of t.children)if("listItem"===e.type&&null!=e.checked)return"check";return"bullet"}function Yt(t,e){return(n,r)=>{const o=r.importChildren(n,t);if("_"===function(t,e){if(t.source&&e.position&&null!=e.position.start.offset)return t.source[e.position.start.offset]}(r,n))for(const t of o)m(t)&&u(t,e,"_");return o}}const Zt=/* @__PURE__ */Yt(Qt,Ot),te=/* @__PURE__ */Yt(Kt,Bt),ee={h1:1,h2:2,h3:3,h4:4,h5:5,h6:6};function ne(t,e){const n=t.getListType(),r={children:[],ordered:"number"===n,spread:!1,start:"number"===n?t.getStart():void 0,type:"list"};if("number"===n){const e=h(t,Ft);e&&(r.data={mdastBulletOrdered:e})}else{const e=h(t,Lt);e&&(r.data={mdastBullet:e})}let o=null;for(const i of t.getChildren()){if(!tt(i)||!e.isIncluded(i))continue;const t=i.getFirstChild();if(1===i.getChildrenSize()&&Z(t)){const n=ne(t,e);o?o.children.push(n):r.children.push({children:[n],spread:!1,type:"listItem"});continue}const s={checked:"check"===n?i.getChecked()??!1:null,children:e.exportBlocks(i),spread:!1,type:"listItem"};r.children.push(s),o=s}return r}const re=[[Kt,"strong"],[Qt,"emphasis"]];function oe(t){const e=[];for(let n=0;n<t.length;){const{format:r,value:o}=t[n];let i=null,s=0,l=n+1;for(const[e,o]of re){if(0===(r&e))continue;let a=n+1;for(;a<t.length&&t[a].format&e;)a++;(null===i||a>l)&&(i=o,s=e,l=a)}null===i?(e.push(r&Xt?{type:"inlineCode",value:o}:{type:"text",value:o}),n++):(e.push({children:oe(t.slice(n,l).map(t=>({format:t.format&~s,value:t.value}))),type:i}),n=l)}return e}const ie=t=>m(t)?function(t,e){let n=e&Xt?{type:"inlineCode",value:t}:{type:"text",value:t};return e&Qt&&(n={children:[n],type:"emphasis"}),e&Kt&&(n={children:[n],type:"strong"}),e&Wt&&(n={children:[n],type:"delete"}),n}(t.getTextContent(),t.getFormat()&Jt):null,se=t=>f(t)?{data:{mdastBreak:h(t,qt)},type:"break"}:null;function le(t,e,n){const{options:r}=t,o={};for(const t of Object.keys(e))o[t]=r[t],r[t]=e[t];try{return n()}finally{for(const t of Object.keys(o))r[t]=o[t]}}const ae={handlers:{break(t,e,n,r){const o=D.break(t,e,n,r);if("\\\n"!==o)return o;const i=t.data&&t.data.mdastBreak;return i?/^ {2,}$/.test(i)?`${i}\n`:o:"\n"},code(t,e,n,r){const o=t.data&&t.data.mdastFence;return o?le(n,{fence:"~"===o[0]?"~":"`",fences:!0},()=>D.code(t,e,n,r)):D.code(t,e,n,r)},heading:(t,e,n,r)=>t.data&&!0===t.data.mdastSetext?le(n,{setext:!0},()=>D.heading(t,e,n,r)):D.heading(t,e,n,r),link(t,e,n,r){const o=t.data&&t.data.mdastLinkStyle;return"literal"===o&&null==t.title?U(t):"inline"===o?le(n,{resourceLink:!0},()=>D.link(t,e,n,r)):D.link(t,e,n,r)},list(t,e,n,r){if(t.ordered){const o=t.data&&t.data.mdastBulletOrdered;return null==o?D.list(t,e,n,r):le(n,{bulletOrdered:o},()=>D.list(t,e,n,r))}const o=t.data&&t.data.mdastBullet;return null==o?D.list(t,e,n,r):le(n,{bullet:o,bulletOther:"-"===o?"*":"-"},()=>D.list(t,e,n,r))},thematicBreak(t,e,n){const r=t.data&&t.data.mdastRule;return"-"!==r&&"*"!==r&&"_"!==r?D.thematicBreak(t,e,n):le(n,{rule:r},()=>D.thematicBreak(t,e,n))}}};class ce{runs=[];push(t){if(!m(t))return!1;const e=t.getFormat()&Jt,n=this.runs[this.runs.length-1];return void 0!==n&&n.format===e?n.value+=t.getTextContent():this.runs.push({format:e,value:t.getTextContent()}),!0}flushInto(t){this.runs.length>0&&(t.push(...function(t){const e=[];for(let n=0;n<t.length;){const r=0!==(t[n].format&Wt);let o=n+1;for(;o<t.length&&0!==(t[o].format&Wt)===r;)o++;const i=t.slice(n,o);r?e.push({children:oe(i.map(t=>({format:t.format&~Wt,value:t.value}))),type:"delete"}):e.push(...oe(i)),n=o}return e}(this.runs)),this.runs=[])}}function ue(t,e=null){const{exportHandlers:n}=t;let r=0;function o(t){const e=n.get(t.getType());return void 0===e||e===ie}function i(t){return null===e||y(t)?t:t.isSelected(e)?(r++,m(t)?z(e,t,"clone"):t):null}function s(t,n){const o=null!==e&&t.isSelected(e);o&&r++;const i=r,s=a(t);(null===e||o||r>i)&&n.push(...s)}const l={exportBlocks:t=>function(t){const e=[];let n=[];const r=new ce,l=()=>{r.flushInto(n),n.length>0&&(e.push({children:n,type:"paragraph"}),n=[])};for(const c of t.getChildren()){const t=i(c);if(null!==t)if(f(t)){const e=se(t);h(t,zt)||null===e?l():(r.flushInto(n),n.push(e))}else{if(o(t)&&r.push(t))continue;jt(t)?(l(),y(t)?s(t,e):e.push(...a(t))):y(t)?(r.flushInto(n),s(t,n)):(r.flushInto(n),n.push(...a(t)))}}l(),0===e.length&&e.push({children:[],type:"paragraph"});return e}(t),exportChildren:t=>{const e=[];for(const n of t.getChildren()){const t=i(n);null!==t&&(y(t)?s(t,e):e.push(...a(t)))}return e},exportInline:t=>function(t){const e=[],n=new ce;for(const r of t.getChildren()){const t=i(r);null!==t&&(o(t)&&n.push(t)||(n.flushInto(e),y(t)?s(t,e):e.push(...a(t))))}return n.flushInto(e),e}(t),isIncluded:function t(n){if(null===e||n.isSelected(e))return!0;if(y(n))for(const e of n.getChildren())if(t(e))return!0;return!1}};function a(t){const e=n.get(t.getType());if(e){const n=e(t,l);if(null!=n)return Array.isArray(n)?n:[n]}const r=ie(t);if(null!==r)return[r];const o=se(t);if(null!==o)return[o];if(y(t))return l.exportChildren(t);const i=t.getTextContent();return i?[{type:"text",value:i}]:[]}return{exportChildren:l.exportChildren}}function de(t){const e=ue(t),n=(t,e)=>({children:e.exportChildren(t),type:"root"}),r=(e,n)=>{const{emphasis:r,strong:o}=function(t){let e,n;const r=t=>{for(const o of t.getChildren())if(m(o)?(void 0===e&&o.hasFormat("italic")&&"_"===h(o,Ot)&&(e="_"),void 0===n&&o.hasFormat("bold")&&"_"===h(o,Bt)&&(n="_")):y(o)&&r(o),void 0!==e&&void 0!==n)return};return r(t),{emphasis:e,strong:n}}(n),i={bullet:"-"};r&&(i.emphasis=r),o&&(i.strong=o);return P(e,{extensions:[i,...t.toMarkdownExtensions,ae]}).replace(/\n$/,"")};return{$exportSelectionToMarkdown:(e=S())=>{if(null===e||T(e)&&e.isCollapsed())return"";const o=$();return r(n(o,ue(t,e)),o)},$exportToMarkdown:t=>{const o=t||$();return r(n(o,e),o)},$exportToMdast:t=>n(t||$(),e)}}function pe(t,e){const n=[];return v(t,{linebreak:()=>n.push(d()),tab:()=>n.push(M()),text:t=>{const r=x(t);e&&r.setFormat(e),n.push(r)}}),n}const me=new Map;function fe(t,e="",n=me){const{importHandlers:r}=t,o=new Map;function i(t,l){const a=r.get(t.type);if(a){const r=a(t,function(t){let r=o.get(t);return void 0===r&&(r={createText:(e,n)=>pe(e,null==n?t:n),format:t,getDefinition:t=>n.get(t),importChildren:(e,n)=>s(e,t|(n||0)),importNode:(e,n)=>i(e,t|(n||0)),source:e},o.set(t,r)),r}(l));return null==r?[]:Array.isArray(r)?r:[r]}return"children"in t?s(t,l):"value"in t&&"string"==typeof t.value?pe(t.value,l):[]}function s(t,e){const n=[];for(const r of t.children)n.push(...i(r,e));return n}return{$importChildren:s,$importNode:i}}function he(t){const e=(e,n)=>{const{$importNode:r}=fe(t,n,function(t){const e=new Map,n=t=>{if("definition"===t.type&&(e.has(t.identifier)||e.set(t.identifier,{title:t.title,url:t.url})),"children"in t)for(const e of t.children)n(e)};return n(t),e}(e)),o=[];let i=null;const s=()=>{i&&(o.push(i),i=null)};for(const t of e.children)for(const e of r(t,0))jt(e)?(s(),o.push(e)):(i||(i=c()),Ut(i,[e]));return s(),o},n=n=>e(kt(n,{extensions:t.micromarkExtensions,mdastExtensions:t.mdastExtensions}),n),r=t=>e(t,""),o=(t,e)=>{const n=e||$();var r,o;n.clear(),r=n,o=t.length>0?t:[c()],r.splice(0,0,o),null!==S()&&n.selectStart()};return{$generateNodesFromMarkdown:n,$generateNodesFromMdast:r,$importMarkdown:(t,e)=>o(n(t),e),$importMdast:(t,e)=>o(r(t),e)}}function ge(t,e){let n=t;for(;;){if("heading"===n.type||"paragraph"===n.type){const t=n.children[0];return t&&t.position&&null!=t.position.start.offset?t.position.start.offset:e.length}if(!("children"in n)||0===n.children.length)return e.length;n=n.children[0]}}class xe{compiled;importNode;supportsTaskListItems;constructor(t){this.compiled=t,this.importNode=fe(t,"").$importNode;const e=this.parse("- [x] a").children[0];this.supportsTaskListItems=null!=e&&"list"===e.type&&!0===e.children[0].checked}get inlineTriggers(){return this.compiled.inlineShortcutTriggers}parse(t){return kt(t,{extensions:this.compiled.micromarkExtensions,mdastExtensions:this.compiled.mdastExtensions})}importInline(t){return this.importNode(t,0)}scanBlock(t){if(""===t.trim())return null;const e=this.parse(t).children[0];if(!e||!this.compiled.importHandlers.has(e.type))return null;switch(e.type){case"heading":return{kind:"heading",markerLength:ge(e,t),node:e};case"blockquote":return{kind:"blockquote",markerLength:ge(e,t),node:e};case"list":return{kind:"list",markerLength:ge(e,t),node:e};case"code":return{kind:"code",markerLength:t.length,node:e};default:return null}}scanInline(t){if(0===t.length)return null;const e=this.parse(t),n=e.children[e.children.length-1];if(!n||"paragraph"!==n.type)return null;const r=n.children[n.children.length-1];if(!r||!r.position||r.position.end.offset!==t.length||!this.compiled.inlineShortcutTypes.has(r.type))return null;const o=r.position.start.offset??0,i=t[o];return o>0&&t[o-1]===i&&this.compiled.inlineShortcutTriggers.has(i)?null:r}}function ke(t,e){let n=e,r=t.getFirstChild();for(;n>0&&r&&m(r);){const t=r.getTextContent();if(t.length<=n){const e=r.getNextSibling();n-=t.length,r.remove(),r=e}else r.setTextContent(t.slice(n)),n=0}}function ye(t,e){const n="code"===e.kind?t.getTextContent().match(/^[ \t]*(`{3,}|~{3,})/):null;ke(t,e.markerLength);const r=t.getChildren();if("code"===e.kind){const o=j(e.node.lang||void 0);return n&&u(o,At,n[1]),e.node.meta&&u(o,Ht,e.node.meta),Ut(o,r),t.replace(o),o.selectStart(),!0}let o,i;if("heading"===e.kind){const t=Ut(rt(`h${e.node.depth}`),r);o=t,i=t}else if("blockquote"===e.kind){const t=Ut(it(),r);o=t,i=t}else{const t=e.node,n=Vt(t),s=t.ordered&&null!=t.start?t.start:1,l=V(n,s),a=t.children[0],c=a&&"listItem"===a.type&&"boolean"==typeof a.checked?a.checked:void 0,u=Ut(Y(c),r);Ut(l,[u]),o=l,i=u}return t.replace(o),i.selectStart(),!0}const Ce=/^\[([ xX])\]\s$/;function $e(t,e){return p(t)&&B(t.getParent())&&t.getFirstChild()===e}function Te(t,e){const n=new xe(e),r=n.inlineTriggers,o=new Set([" ",...r]);return b(t.registerUpdateListener(({tags:e,dirtyLeaves:i,editorState:s,prevEditorState:l})=>{if(0===i.size||e.has(w)||e.has(E))return;if(t.isComposing())return;const a=e.has(R),c=s.read(S),u=l.read(S);if(!T(c)||!T(u)||!c.isCollapsed()||c.is(u)&&!a)return;const d=c.anchor.key,p=c.anchor.offset,f=s._nodeMap.get(d);if(!m(f)||!i.has(d))return;if(!a&&1!==p&&(u.anchor.key!==d||p!==u.anchor.offset+1))return;const h=s.read(()=>f.getTextContent()),g=h[p-1];var x,k;a&&!o.has(g)||(" "===g||r.has(g))&&(" "===g||(x=h.slice(0,p),")"===(k=g)?x.lastIndexOf("](")>0:-1!==x.lastIndexOf(k,x.length-2)))&&t.update(()=>{const t=N(d);if(!m(t)||t.hasFormat("code"))return;const e=t.getParent();if(null===e||G(e))return;let r=!1;if(" "===g){if(n.supportsTaskListItems&&function(t,e,n){if(e.getFirstChild()!==t)return!1;const r=e.getTextContent().slice(0,n).match(Ce);if(!r)return!1;const o="x"===r[1].toLowerCase();if(tt(e)){const t=e.getParent();return!(!Z(t)||"number"===t.getListType()||(ke(e,r[0].length),t.setListType("check"),e.setChecked(o),0))}if($e(e,t)){ke(e,r[0].length);const t=e.getChildren(),n=V("check"),i=Ut(Y(o),t);return Ut(n,[i]),e.replace(n),i.selectStart(),!0}return!1}(t,e,p))r=!0;else if(p<=24&&$e(e,t)){const o=n.scanBlock(t.getTextContent().slice(0,p));o&&"code"!==o.kind&&o.markerLength===p&&(r=ye(e,o))}}else r=function(t,e,n){const r=t.getTextContent().slice(0,e),o=n.scanInline(r);if(!o||!o.position)return!1;const i=o.position.start.offset??0,s=e;let l;if(i<=0)[l]=t.splitText(s);else{const e=t.splitText(i,s);l=3===e.length?e[1]:e[e.length-1]}const a=n.importInline(o);if(0===a.length)return!1;let c=a[0];l.replace(c);for(let t=1;t<a.length;t++)c.insertAfter(a[t]),c=a[t];if(m(c)){const t=c.getTextContentSize();c.select(t,t)}else c.selectNext(0,0);return!0}(t,p,n);r&&I(L)})}),t.registerCommand(F,t=>{if(null!==t&&t.shiftKey)return!1;const e=S();if(!T(e)||!e.isCollapsed())return!1;const r=e.anchor.getNode();if(!m(r)||r.hasFormat("code"))return!1;const o=r.getParent(),i=e.anchor.offset;if(null===o||G(o)||!$e(o,r)||i!==r.getTextContentSize())return!1;const s=n.scanBlock(o.getTextContent());return!(!s||s.markerLength!==i||!ye(o,s))&&(null!==t&&t.preventDefault(),!0)},O))}const Se=[{$import:(t,e)=>Ut(c(),e.importChildren(t)),type:"paragraph"},{$import:(t,e)=>e.createText(t.value),type:"text"},{$import:(t,e)=>e.createText(t.value),type:"html"},{$import:(t,e)=>e.createText(t.value,e.format|Xt),type:"inlineCode"},{$import:Zt,type:"emphasis"},{$import:te,type:"strong"},{$import:(t,e)=>{let n="\\";if(e.source&&t.position){const{start:r,end:o}=t.position;if(null!=r.offset&&null!=o.offset){const t=e.source.slice(r.offset,o.offset).replace(/\n$/,"");/^ {2,}$/.test(t)&&(n=t)}}return[u(d(),qt,n)]},type:"break"}],ve=[{$export:(t,e)=>p(t)?{children:e.exportInline(t),type:"paragraph"}:null,type:"paragraph"},{$export:ie,type:"text"},{$export:se,type:"linebreak"},{$export:t=>g(t)?{type:"text",value:"\t"}:null,type:"tab"}],Me=/* @__PURE__ */_({build(t,e){const n=function(t){const e=new Map,n=new Map;for(const n of t.importRules)e.has(n.type)||e.set(n.type,n.$import);for(const e of t.exportRules)n.has(e.type)||n.set(e.type,e.$export);return{exportHandlers:n,importHandlers:e,inlineShortcutTriggers:new Set(t.inlineShortcutTriggers),inlineShortcutTypes:new Set(t.inlineShortcutTypes),mdastExtensions:[...t.mdastExtensions],micromarkExtensions:[...t.micromarkExtensions],toMarkdownExtensions:[...t.toMarkdownExtensions]}}(e),{$generateNodesFromMarkdown:r,$generateNodesFromMdast:o,$importMarkdown:i,$importMdast:s}=he(n);return{$convertFromMarkdownString:i,$convertFromMdast:s,$generateNodesFromMarkdownString:r,$generateNodesFromMdast:o,registry:n}},config:/* @__PURE__ */H({exportRules:ve,importRules:Se,inlineShortcutTriggers:["*","_","`"],inlineShortcutTypes:["emphasis","inlineCode","strong"],mdastExtensions:[],micromarkExtensions:[],toMarkdownExtensions:[]}),mergeConfig(t,e){function n(t,e){return t?[...t,...e]:e}return A(t,{exportRules:n(e.exportRules,t.exportRules),importRules:n(e.importRules,t.importRules),inlineShortcutTriggers:n(e.inlineShortcutTriggers,t.inlineShortcutTriggers),inlineShortcutTypes:n(e.inlineShortcutTypes,t.inlineShortcutTypes),mdastExtensions:n(e.mdastExtensions,t.mdastExtensions),micromarkExtensions:n(e.micromarkExtensions,t.micromarkExtensions),toMarkdownExtensions:n(e.toMarkdownExtensions,t.toMarkdownExtensions)})},name:"@lexical/mdast/Import"}),be=/* @__PURE__ */_({dependencies:[/* @__PURE__ */q(Me,{exportRules:[{$export:(t,e)=>{if(!ot(t))return null;const n={children:e.exportInline(t),depth:ee[t.getTag()],type:"heading"};return h(t,_t)&&(n.data={mdastSetext:!0}),n},type:"heading"}],importRules:[{$import:(t,e)=>{const n=rt(`h${t.depth}`);if(e.source&&t.position&&(1===t.depth||2===t.depth)){const r=t.position.start.offset;null==r||/^ {0,3}#{1,6}([ \t\r\n]|$)/.test(e.source.slice(r,r+10))||u(n,_t,!0)}return Ut(n,e.importChildren(t))},type:"heading"}]})],name:"@lexical/mdast/Heading",nodes:[lt]}),we=/* @__PURE__ */_({dependencies:[/* @__PURE__ */q(Me,{exportRules:[{$export:(t,e)=>st(t)?{children:t.isShadowRoot()?e.exportChildren(t):e.exportBlocks(t),type:"blockquote"}:null,type:"quote"}],importRules:[{$import:(t,e)=>{const n=it(),r=[];for(const n of t.children)"paragraph"===n.type?(r.length>0&&r.push(Gt()),r.push(...e.importChildren(n))):r.push(...e.importNode(n));return Ut(n,r)},type:"blockquote"}]})],name:"@lexical/mdast/Blockquote",nodes:[at]}),Ee=/* @__PURE__ */_({dependencies:[be,we],name:"@lexical/mdast/RichText"}),Re=/* @__PURE__ */_({dependencies:[/* @__PURE__ */q(Me,{exportRules:[{$export:(t,e)=>Z(t)?ne(t,e):null,type:"list"}],importRules:[{$import:(t,e)=>{const n=Vt(t),r=t.ordered&&null!=t.start?t.start:1,o=V(n,r),i=t.children[0],s=e.source&&i&&i.position?i.position.start.offset:void 0;if(null!=s){const t=e.source.slice(s,s+16);if("number"===n){const e=t.match(/^\s*\d+([.)])/),n=e&&e[1];"."!==n&&")"!==n||u(o,Ft,n)}else{const e=t.match(/^\s*([-*+])/),n=e&&e[1];"-"!==n&&"*"!==n&&"+"!==n||u(o,Lt,n)}}return Ut(o,t.children.flatMap(t=>e.importNode(t)))},type:"list"},{$import:(t,e)=>{const n=Y("boolean"==typeof t.checked?t.checked:void 0),r=[];for(const o of t.children)"list"===o.type?r.push(Ut(Y(),e.importNode(o))):"paragraph"===o.type?(n.getChildrenSize()>0&&Ut(n,[Gt()]),Ut(n,e.importChildren(o))):Ut(n,e.importNode(o));return[n,...r]},type:"listItem"}]})],name:"@lexical/mdast/List",nodes:[et,nt]}),Ne=/* @__PURE__ */_({dependencies:[Re,/* @__PURE__ */q(Me,{mdastExtensions:[/* @__PURE__ */ft()],micromarkExtensions:[/* @__PURE__ */xt()],toMarkdownExtensions:[/* @__PURE__ */mt()]})],name:"@lexical/mdast/TaskList"}),Ie=/* @__PURE__ */_({dependencies:[/* @__PURE__ */q(Me,{exportRules:[{$export:t=>{if(!G(t))return null;const e={lang:t.getLanguage()||null,type:"code",value:t.getTextContent()},n=h(t,Ht);n&&(e.meta=n);const r=h(t,At);return r&&(e.data={mdastFence:r}),e},type:"code"}],importRules:[{$import:(t,e)=>{const n=j(t.lang||void 0);if(e.source&&t.position&&null!=t.position.start.offset){const r=t.position.start.offset,o=e.source.indexOf("\n",r),i=e.source.slice(r,-1===o?void 0:o).match(/^[ \t]*(`{3,}|~{3,})/);i&&u(n,At,i[1])}return t.meta&&u(n,Ht,t.meta),t.value&&Ut(n,[x(t.value)]),n},type:"code"}]})],name:"@lexical/mdast/Code",nodes:[K]}),Le=/* @__PURE__ */_({dependencies:[/* @__PURE__ */q(Me,{exportRules:[{$export:(t,e)=>{if(!W(t)||X(t))return null;const n={children:e.exportInline(t),title:t.getTitle()??null,type:"link",url:t.getURL()},r=h(t,Dt);return r&&(n.data={mdastLinkStyle:r}),n},type:"link"}],importRules:[{$import:(t,e)=>{const n=Ut(Q(t.url,{title:null==t.title?void 0:t.title}),e.importChildren(t));if(e.source&&t.position&&null!=t.position.start.offset){const r=e.source[t.position.start.offset];u(n,Dt,"["===r?"inline":"<"===r?"autolink":"literal")}return n},type:"link"},{$import:(t,e)=>{const n=e.getDefinition(t.identifier);if(n)return Ut(Q(n.url,{title:null==n.title?void 0:n.title}),e.importChildren(t));const{position:r}=t;return e.source&&r&&null!=r.start.offset?e.createText(e.source.slice(r.start.offset,r.end.offset)):[...e.createText("["),...e.importChildren(t),...e.createText("]")]},type:"linkReference"},{$import:()=>[],type:"definition"}],inlineShortcutTriggers:[")"],inlineShortcutTypes:["link"]})],name:"@lexical/mdast/Link",nodes:[J]}),Fe=/* @__PURE__ */_({dependencies:[Le,/* @__PURE__ */q(Me,{mdastExtensions:[/* @__PURE__ */ut()],micromarkExtensions:[/* @__PURE__ */ht()],toMarkdownExtensions:[/* @__PURE__ */ct()]})],name:"@lexical/mdast/AutolinkLiteral"}),Oe=/* @__PURE__ */_({dependencies:[we,
|
|
10
10
|
/* @__PURE__ */
|
|
11
|
-
q(Me,{importRules:[{$import:(t,e)=>Ut(it({shadowRoot:!0}),function(t,e){const n=[];let r=null;const o=()=>{r&&(n.push(r),r=null)};for(const i of t.children)for(const t of e.importNode(i))jt(t)?(o(),n.push(t)):(r||(r=c()),Ut(r,[t]));return o(),n}(t,e)),type:"blockquote"}]})],name:"@lexical/mdast/ShadowRootQuote"}),
|
|
11
|
+
q(Me,{importRules:[{$import:(t,e)=>Ut(it({shadowRoot:!0}),function(t,e){const n=[];let r=null;const o=()=>{r&&(n.push(r),r=null)};for(const i of t.children)for(const t of e.importNode(i))jt(t)?(o(),n.push(t)):(r||(r=c()),Ut(r,[t]));return o(),n}(t,e)),type:"blockquote"}]})],name:"@lexical/mdast/ShadowRootQuote"}),Be=/* @__PURE__ */_({dependencies:[t,/* @__PURE__ */q(Me,{exportRules:[{$export:t=>{if(!s(t))return null;const e={type:"thematicBreak"},n=h(t,Pt);return n&&(e.data={mdastRule:n}),e},type:"horizontalrule"}],importRules:[{$import:(t,e)=>{const n=i();if(e.source&&t.position&&null!=t.position.start.offset){const r=e.source.slice(t.position.start.offset,t.position.start.offset+4).trimStart()[0];"-"!==r&&"*"!==r&&"_"!==r||u(n,Pt,r)}return n},type:"thematicBreak"}]})],name:"@lexical/mdast/HorizontalRule"}),_e=/* @__PURE__ */_({dependencies:[/* @__PURE__ */q(Me,{importRules:[{$import:(t,e)=>e.importChildren(t,Wt),type:"delete"}],inlineShortcutTriggers:["~"],inlineShortcutTypes:["delete"],mdastExtensions:[/* @__PURE__ */pt()],micromarkExtensions:[/* @__PURE__ */gt()],toMarkdownExtensions:[/* @__PURE__ */dt()]})],name:"@lexical/mdast/Strikethrough"}),Ae=/* @__PURE__ */_({dependencies:[Ee,Re,Ie,Le,Be],name:"@lexical/mdast/CommonMark"}),He=/* @__PURE__ */_({build:(t,e)=>r(e),config:/* @__PURE__ */H({disabled:!1}),dependencies:[Me],name:"@lexical/mdast/Shortcuts",register:(t,r,o)=>{const{disabled:i}=o.getOutput();return e(()=>{if(i.value)return;const{registry:e}=n(t,Me).output;return Te(t,e)})}});function qe(t,e){o(Me).$convertFromMarkdownString(t,e)}function ze(t,e){o(Me).$convertFromMdast(t,e)}function Pe(t){return o(Me).$generateNodesFromMarkdownString(t)}function De(t){return o(Me).$generateNodesFromMdast(t)}const Ue=/* @__PURE__ */_({build(t,e,n){const{registry:r}=n.getDependency(Me).output,{$exportSelectionToMarkdown:o,$exportToMdast:i,$exportToMarkdown:s}=de(r);return{$convertSelectionToMarkdownString:o,$convertToMarkdownString:s,$convertToMdast:i}},dependencies:[Me],name:"@lexical/mdast/Export"});function je(t){return o(Ue).$convertToMarkdownString(t)}function Ge(t){return o(Ue).$convertToMdast(t)}function Ke(t){return o(Ue).$convertSelectionToMarkdownString(t)}const Qe=/* @__PURE__ */_({dependencies:[Me,Ue],name:"@lexical/mdast/Mdast"}),We=/* @__PURE__ */a("mdastTableAlign",{parse:t=>Array.isArray(t)?t.map(t=>"center"===t||"left"===t||"right"===t?t:null):[],resetOnCopyNode:!0}),Xe=/* @__PURE__ */_({dependencies:[/* @__PURE__ */l(Me,{exportRules:[{$export:(t,e)=>{if(!bt(t))return null;const n=[];for(const r of t.getChildren()){if(!wt(r)||!e.isIncluded(r))continue;const t=[];for(const n of r.getChildren()){if(!Et(n))continue;const r=[];for(const t of n.getChildren())y(t)&&(r.length>0&&r.push({type:"break"}),r.push(...e.exportInline(t)));t.push({children:r,type:"tableCell"})}n.push({children:t,type:"tableRow"})}return{align:h(t,We),children:n,type:"table"}},type:"table"}],importRules:[{$import:(t,e)=>{const n=Tt();return t.align&&t.align.some(t=>null!=t)&&u(n,We,t.align),t.children.forEach((t,r)=>{const o=St();for(const n of t.children){const t=vt(0===r?Mt.ROW:Mt.NO_STATUS),i=c();Ut(i,e.importChildren(n)),Ut(t,[i]),Ut(o,[t])}Ut(n,[o])}),n},type:"table"}],mdastExtensions:[/* @__PURE__ */Nt()],micromarkExtensions:[/* @__PURE__ */It()],toMarkdownExtensions:[/* @__PURE__ */Rt()]})],name:"@lexical/mdast/Table",nodes:[yt,Ct,$t]}),Je=/* @__PURE__ */_({dependencies:[_e,Ne,Fe,Xe],name:"@lexical/mdast/Gfm"});export{qe as $convertFromMarkdownString,ze as $convertFromMdast,Ke as $convertSelectionToMarkdownString,je as $convertToMarkdownString,Ge as $convertToMdast,Pe as $generateNodesFromMarkdownString,De as $generateNodesFromMdast,Fe as MdastAutolinkLiteralExtension,we as MdastBlockquoteExtension,Ie as MdastCodeExtension,Ae as MdastCommonMarkExtension,Ue as MdastExportExtension,Qe as MdastExtension,Je as MdastGfmExtension,be as MdastHeadingExtension,Be as MdastHorizontalRuleExtension,Me as MdastImportExtension,Le as MdastLinkExtension,Re as MdastListExtension,Ee as MdastRichTextExtension,Oe as MdastShadowRootQuoteExtension,He as MdastShortcutsExtension,_e as MdastStrikethroughExtension,Xe as MdastTableExtension,Ne as MdastTaskListExtension};
|
package/dist/handlers.d.ts
CHANGED
|
@@ -79,6 +79,27 @@ export declare const $exportList: MdastExportHandler;
|
|
|
79
79
|
* one document desyncs to-markdown's character escaping.
|
|
80
80
|
*/
|
|
81
81
|
export declare function phrasingFromFormattedText(value: string, format: number): PhrasingContent;
|
|
82
|
+
/** A contiguous stretch of plain text sharing one Lexical format bitmask. */
|
|
83
|
+
export interface TextRun {
|
|
84
|
+
format: number;
|
|
85
|
+
value: string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Converts a sequence of text runs into properly *nested* mdast phrasing.
|
|
89
|
+
* Runs whose formats overlap (e.g. `llo` bold, `wor` bold+italic, `ld`
|
|
90
|
+
* italic) must share a container wherever they share a format bit — emitting
|
|
91
|
+
* each run as its own fully-wrapped sibling produces adjacent delimiter runs
|
|
92
|
+
* (`**llo*****wor****ld*`) that CommonMark resolves differently, so the
|
|
93
|
+
* output would not re-parse to the same formatting (issue #4895).
|
|
94
|
+
*
|
|
95
|
+
* Strikethrough segments the sequence first and always wraps outermost (the
|
|
96
|
+
* single-run nesting order): a `~~` delimiter is only reliably flanking next
|
|
97
|
+
* to text, so `delete` must never land *inside* an emphasis/strong group
|
|
98
|
+
* where a `*` marker would abut it (`*ld~~**llo**~~*` does not re-parse).
|
|
99
|
+
* Bold/italic overlap is then grouped greedily within each segment by
|
|
100
|
+
* {@link phrasingFromEmphasisRuns}.
|
|
101
|
+
*/
|
|
102
|
+
export declare function phrasingFromTextRuns(runs: readonly TextRun[]): PhrasingContent[];
|
|
82
103
|
export declare const exportText: (node: LexicalNode) => PhrasingContent | null;
|
|
83
104
|
export declare const $exportLineBreak: (node: LexicalNode) => Break | null;
|
|
84
105
|
export declare const exportTab: (node: LexicalNode) => MdastText | null;
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"micromark"
|
|
11
11
|
],
|
|
12
12
|
"license": "MIT",
|
|
13
|
-
"version": "0.47.0",
|
|
13
|
+
"version": "0.47.1-nightly.20260713.0",
|
|
14
14
|
"main": "./dist/LexicalMdast.js",
|
|
15
15
|
"types": "./dist/typescript-too-old.d.ts",
|
|
16
16
|
"dependencies": {
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
"micromark-extension-gfm-table": "^2.1.1",
|
|
28
28
|
"micromark-extension-gfm-task-list-item": "^2.1.0",
|
|
29
29
|
"micromark-util-types": "^2.0.2",
|
|
30
|
-
"@lexical/
|
|
31
|
-
"@lexical/
|
|
32
|
-
"@lexical/
|
|
33
|
-
"@lexical/
|
|
34
|
-
"@lexical/link": "0.47.0",
|
|
35
|
-
"@lexical/
|
|
36
|
-
"@lexical/
|
|
37
|
-
"
|
|
38
|
-
"lexical": "0.47.0"
|
|
30
|
+
"@lexical/extension": "0.47.1-nightly.20260713.0",
|
|
31
|
+
"@lexical/rich-text": "0.47.1-nightly.20260713.0",
|
|
32
|
+
"@lexical/selection": "0.47.1-nightly.20260713.0",
|
|
33
|
+
"@lexical/list": "0.47.1-nightly.20260713.0",
|
|
34
|
+
"@lexical/link": "0.47.1-nightly.20260713.0",
|
|
35
|
+
"@lexical/table": "0.47.1-nightly.20260713.0",
|
|
36
|
+
"@lexical/utils": "0.47.1-nightly.20260713.0",
|
|
37
|
+
"lexical": "0.47.1-nightly.20260713.0",
|
|
38
|
+
"@lexical/code-core": "0.47.1-nightly.20260713.0"
|
|
39
39
|
},
|
|
40
40
|
"repository": {
|
|
41
41
|
"type": "git",
|
package/src/MdastExport.ts
CHANGED
|
@@ -42,8 +42,9 @@ import {
|
|
|
42
42
|
$exportLineBreak,
|
|
43
43
|
$isBlockLevelNode,
|
|
44
44
|
exportText,
|
|
45
|
-
|
|
45
|
+
phrasingFromTextRuns,
|
|
46
46
|
TEXT_FORMAT_MASK,
|
|
47
|
+
type TextRun,
|
|
47
48
|
} from './handlers';
|
|
48
49
|
import {
|
|
49
50
|
emphasisMarkerState,
|
|
@@ -178,41 +179,40 @@ const SYNTAX_TO_MARKDOWN: ToMarkdownExtension = {
|
|
|
178
179
|
};
|
|
179
180
|
|
|
180
181
|
/**
|
|
181
|
-
* Accumulates adjacent plain text nodes
|
|
182
|
-
*
|
|
183
|
-
*
|
|
182
|
+
* Accumulates adjacent plain text nodes so a whole stretch of formatted text
|
|
183
|
+
* serializes together: nodes sharing a format merge into a single delimiter
|
|
184
|
+
* pair (`**ab**` rather than `**a****b**`), and nodes whose formats *overlap*
|
|
185
|
+
* (bold, bold+italic, italic) nest inside shared containers so the emitted
|
|
186
|
+
* delimiters re-parse to the same formatting. Shared by the inline and block
|
|
187
|
+
* export walks.
|
|
184
188
|
*/
|
|
185
189
|
class TextRunAccumulator {
|
|
186
|
-
private
|
|
187
|
-
private value = '';
|
|
190
|
+
private runs: TextRun[] = [];
|
|
188
191
|
|
|
189
192
|
/**
|
|
190
|
-
* Returns `true` when `child` was absorbed.
|
|
191
|
-
*
|
|
192
|
-
* are eligible (plain text with no export rule of its own); this only
|
|
193
|
+
* Returns `true` when `child` was absorbed. The caller decides *which* text
|
|
194
|
+
* nodes are eligible (plain text with no export rule of its own); this only
|
|
193
195
|
* guards the node kind.
|
|
194
196
|
*/
|
|
195
|
-
push(child: LexicalNode
|
|
197
|
+
push(child: LexicalNode): boolean {
|
|
196
198
|
if (!$isTextNode(child)) {
|
|
197
199
|
return false;
|
|
198
200
|
}
|
|
199
201
|
const format = child.getFormat() & TEXT_FORMAT_MASK;
|
|
200
|
-
|
|
201
|
-
|
|
202
|
+
const last = this.runs[this.runs.length - 1];
|
|
203
|
+
if (last !== undefined && last.format === format) {
|
|
204
|
+
last.value += child.getTextContent();
|
|
202
205
|
} else {
|
|
203
|
-
this.
|
|
204
|
-
this.format = format;
|
|
205
|
-
this.value = child.getTextContent();
|
|
206
|
+
this.runs.push({format, value: child.getTextContent()});
|
|
206
207
|
}
|
|
207
208
|
return true;
|
|
208
209
|
}
|
|
209
210
|
|
|
210
211
|
flushInto(out: PhrasingContent[]): void {
|
|
211
|
-
if (this.
|
|
212
|
-
out.push(
|
|
212
|
+
if (this.runs.length > 0) {
|
|
213
|
+
out.push(...phrasingFromTextRuns(this.runs));
|
|
214
|
+
this.runs = [];
|
|
213
215
|
}
|
|
214
|
-
this.format = -1;
|
|
215
|
-
this.value = '';
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
|
|
@@ -350,7 +350,7 @@ function createNodeExporter(
|
|
|
350
350
|
if (target === null) {
|
|
351
351
|
continue;
|
|
352
352
|
}
|
|
353
|
-
if (!(mayAccumulate(target) && runs.push(target
|
|
353
|
+
if (!(mayAccumulate(target) && runs.push(target))) {
|
|
354
354
|
runs.flushInto(result);
|
|
355
355
|
if ($isElementNode(target)) {
|
|
356
356
|
// The registry erases types; phrasing output is the dispatch
|
|
@@ -397,7 +397,7 @@ function createNodeExporter(
|
|
|
397
397
|
runs.flushInto(inline);
|
|
398
398
|
inline.push(asBreak);
|
|
399
399
|
}
|
|
400
|
-
} else if (mayAccumulate(target) && runs.push(target
|
|
400
|
+
} else if (mayAccumulate(target) && runs.push(target)) {
|
|
401
401
|
continue;
|
|
402
402
|
} else if ($isBlockLevelNode(target)) {
|
|
403
403
|
flushParagraph();
|
package/src/handlers.ts
CHANGED
|
@@ -626,6 +626,122 @@ export function phrasingFromFormattedText(
|
|
|
626
626
|
return content;
|
|
627
627
|
}
|
|
628
628
|
|
|
629
|
+
/** A contiguous stretch of plain text sharing one Lexical format bitmask. */
|
|
630
|
+
export interface TextRun {
|
|
631
|
+
format: number;
|
|
632
|
+
value: string;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Emphasis-family format bits eligible for cross-run grouping, in tie-break
|
|
637
|
+
* order matching the single-run nesting of {@link phrasingFromFormattedText}
|
|
638
|
+
* (strong outside emphasis).
|
|
639
|
+
*/
|
|
640
|
+
const EMPHASIS_FORMATS: readonly [number, 'strong' | 'emphasis'][] = [
|
|
641
|
+
[FORMAT_BOLD, 'strong'],
|
|
642
|
+
[FORMAT_ITALIC, 'emphasis'],
|
|
643
|
+
];
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* Converts a segment of strikethrough-free (or strikethrough-stripped) runs
|
|
647
|
+
* into nested emphasis/strong phrasing. At each position the wrapper is
|
|
648
|
+
* chosen greedily: the format bit shared by the longest stretch of upcoming
|
|
649
|
+
* runs becomes the outer container (ties fall back to strong-outside-emphasis,
|
|
650
|
+
* matching the single-run nesting), and the covered runs recurse with that
|
|
651
|
+
* bit cleared. Overlap is not always fully expressible as nesting — the
|
|
652
|
+
* format that extends furthest keeps a single pair of delimiters and the
|
|
653
|
+
* other side splits.
|
|
654
|
+
*/
|
|
655
|
+
function phrasingFromEmphasisRuns(runs: readonly TextRun[]): PhrasingContent[] {
|
|
656
|
+
const out: PhrasingContent[] = [];
|
|
657
|
+
for (let i = 0; i < runs.length; ) {
|
|
658
|
+
const {format, value} = runs[i];
|
|
659
|
+
let wrapper: 'strong' | 'emphasis' | null = null;
|
|
660
|
+
let wrapperBit = 0;
|
|
661
|
+
let end = i + 1;
|
|
662
|
+
for (const [bit, type] of EMPHASIS_FORMATS) {
|
|
663
|
+
if ((format & bit) === 0) {
|
|
664
|
+
continue;
|
|
665
|
+
}
|
|
666
|
+
let bitEnd = i + 1;
|
|
667
|
+
while (bitEnd < runs.length && runs[bitEnd].format & bit) {
|
|
668
|
+
bitEnd++;
|
|
669
|
+
}
|
|
670
|
+
if (wrapper === null || bitEnd > end) {
|
|
671
|
+
wrapper = type;
|
|
672
|
+
wrapperBit = bit;
|
|
673
|
+
end = bitEnd;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
if (wrapper === null) {
|
|
677
|
+
out.push(
|
|
678
|
+
format & FORMAT_CODE
|
|
679
|
+
? {type: 'inlineCode', value}
|
|
680
|
+
: {type: 'text', value},
|
|
681
|
+
);
|
|
682
|
+
i++;
|
|
683
|
+
} else {
|
|
684
|
+
out.push({
|
|
685
|
+
children: phrasingFromEmphasisRuns(
|
|
686
|
+
runs
|
|
687
|
+
.slice(i, end)
|
|
688
|
+
.map(run => ({format: run.format & ~wrapperBit, value: run.value})),
|
|
689
|
+
),
|
|
690
|
+
type: wrapper,
|
|
691
|
+
});
|
|
692
|
+
i = end;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
return out;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* Converts a sequence of text runs into properly *nested* mdast phrasing.
|
|
700
|
+
* Runs whose formats overlap (e.g. `llo` bold, `wor` bold+italic, `ld`
|
|
701
|
+
* italic) must share a container wherever they share a format bit — emitting
|
|
702
|
+
* each run as its own fully-wrapped sibling produces adjacent delimiter runs
|
|
703
|
+
* (`**llo*****wor****ld*`) that CommonMark resolves differently, so the
|
|
704
|
+
* output would not re-parse to the same formatting (issue #4895).
|
|
705
|
+
*
|
|
706
|
+
* Strikethrough segments the sequence first and always wraps outermost (the
|
|
707
|
+
* single-run nesting order): a `~~` delimiter is only reliably flanking next
|
|
708
|
+
* to text, so `delete` must never land *inside* an emphasis/strong group
|
|
709
|
+
* where a `*` marker would abut it (`*ld~~**llo**~~*` does not re-parse).
|
|
710
|
+
* Bold/italic overlap is then grouped greedily within each segment by
|
|
711
|
+
* {@link phrasingFromEmphasisRuns}.
|
|
712
|
+
*/
|
|
713
|
+
export function phrasingFromTextRuns(
|
|
714
|
+
runs: readonly TextRun[],
|
|
715
|
+
): PhrasingContent[] {
|
|
716
|
+
const out: PhrasingContent[] = [];
|
|
717
|
+
for (let i = 0; i < runs.length; ) {
|
|
718
|
+
const strike = (runs[i].format & FORMAT_STRIKETHROUGH) !== 0;
|
|
719
|
+
let end = i + 1;
|
|
720
|
+
while (
|
|
721
|
+
end < runs.length &&
|
|
722
|
+
((runs[end].format & FORMAT_STRIKETHROUGH) !== 0) === strike
|
|
723
|
+
) {
|
|
724
|
+
end++;
|
|
725
|
+
}
|
|
726
|
+
const segment = runs.slice(i, end);
|
|
727
|
+
if (strike) {
|
|
728
|
+
out.push({
|
|
729
|
+
children: phrasingFromEmphasisRuns(
|
|
730
|
+
segment.map(run => ({
|
|
731
|
+
format: run.format & ~FORMAT_STRIKETHROUGH,
|
|
732
|
+
value: run.value,
|
|
733
|
+
})),
|
|
734
|
+
),
|
|
735
|
+
type: 'delete',
|
|
736
|
+
});
|
|
737
|
+
} else {
|
|
738
|
+
out.push(...phrasingFromEmphasisRuns(segment));
|
|
739
|
+
}
|
|
740
|
+
i = end;
|
|
741
|
+
}
|
|
742
|
+
return out;
|
|
743
|
+
}
|
|
744
|
+
|
|
629
745
|
export const exportText = (node: LexicalNode): PhrasingContent | null => {
|
|
630
746
|
if (!$isTextNode(node)) {
|
|
631
747
|
return null;
|