@usememos/editor 26.10.13 → 26.10.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -10,12 +10,15 @@ __export(commands_exports, {
10
10
  activeLink: () => activeLink,
11
11
  addColumn: () => addColumn,
12
12
  addRow: () => addRow,
13
+ appendParagraph: () => appendParagraph,
13
14
  applyAutolinkInputRule: () => applyAutolinkInputRule,
14
15
  applyBlockInputRules: () => applyBlockInputRules,
15
16
  applyInlineInputRules: () => applyInlineInputRules,
16
17
  applyTokenInputRules: () => applyTokenInputRules,
18
+ balanceSections: () => balanceSections,
17
19
  clampListIndents: () => clampListIndents,
18
20
  cloneBlock: () => cloneBlock,
21
+ closeSections: () => closeSections,
19
22
  convertibleBlocks: () => convertibleBlocks,
20
23
  deleteBackward: () => deleteBackward,
21
24
  deleteBlock: () => deleteBlock,
@@ -38,17 +41,22 @@ __export(commands_exports, {
38
41
  moveCell: () => moveCell,
39
42
  nextGrapheme: () => nextGrapheme,
40
43
  previousGrapheme: () => previousGrapheme,
44
+ quoteRun: () => quoteRun,
41
45
  replaceBlocks: () => replaceBlocks,
46
+ sectionEnd: () => sectionEnd,
47
+ sectionTitle: () => sectionTitle,
42
48
  selectAll: () => selectAll,
43
49
  selectImage: () => selectImage,
44
50
  selectedBlocks: () => selectedBlocks,
45
51
  selectedImage: () => selectedImage,
46
52
  selectedImageBlock: () => selectedImageBlock,
47
53
  setBlockType: () => setBlockType,
54
+ setCallout: () => setCallout,
48
55
  setCodeLanguage: () => setCodeLanguage,
49
56
  setLink: () => setLink,
50
57
  spanBlocks: () => spanBlocks,
51
58
  splitBlock: () => splitBlock,
59
+ splitCollapsedTitle: () => splitCollapsedTitle,
52
60
  tableAction: () => tableAction,
53
61
  toggleBlockType: () => toggleBlockType,
54
62
  toggleMark: () => toggleMark,
@@ -60,6 +68,7 @@ __export(commands_exports, {
60
68
  var MARK_ORDER = ["bold", "italic", "strike", "code", "html"];
61
69
  var ATOM_CHAR = "\uFFFC";
62
70
  var MAX_INDENT = 5;
71
+ var CALLOUT_TYPES = ["note", "tip", "important", "warning", "caution"];
63
72
  var idCounter = 0;
64
73
  var idPrefix = Math.random().toString(36).slice(2, 7);
65
74
  function createId() {
@@ -81,10 +90,12 @@ function listItem(listType, content = [], opts = {}) {
81
90
  checked: listType === "task" ? opts.checked ?? false : false,
82
91
  content: normalizeInline(content)
83
92
  };
84
- return listType === "ordered" && opts.start !== void 0 && opts.start !== 1 ? { ...block3, start: opts.start } : block3;
93
+ const numbered = listType === "ordered" && opts.start !== void 0 && opts.start !== 1 ? { ...block3, start: opts.start } : block3;
94
+ return opts.quote ? withQuote(numbered, opts.quote) : numbered;
85
95
  }
86
- function quote(content = [], id = createId()) {
87
- return { id, type: "quote", content: normalizeInline(content) };
96
+ function quote(content = [], id = createId(), callout) {
97
+ const block3 = { id, type: "quote", content: normalizeInline(content) };
98
+ return callout ? { ...block3, callout } : block3;
88
99
  }
89
100
  function codeBlock(language = "", text = "", id = createId()) {
90
101
  return { id, type: "code", language, content: plain(text) };
@@ -113,14 +124,40 @@ function emptyTable(rows = 3, cols = 3, id = createId()) {
113
124
  function divider(id = createId()) {
114
125
  return { id, type: "divider" };
115
126
  }
127
+ function details(content = [], opts = {}) {
128
+ return { id: opts.id ?? createId(), type: "details", open: opts.open ?? false, content: toPlain(content) };
129
+ }
130
+ function detailsEnd(id = createId()) {
131
+ return { id, type: "detailsEnd" };
132
+ }
116
133
  function plain(text) {
117
134
  return text ? [{ text, marks: [] }] : [];
118
135
  }
136
+ function quoteKind(block3) {
137
+ if (block3?.type === "quote" || block3?.type === "listItem" && block3.quote) return block3.callout ?? "quote";
138
+ return null;
139
+ }
140
+ function sameQuote(a, b) {
141
+ const kind = quoteKind(a);
142
+ return kind !== null && kind === quoteKind(b);
143
+ }
144
+ function withQuote(item, kind) {
145
+ const { quote: _quote, callout: _callout, ...rest } = item;
146
+ if (!kind) return rest;
147
+ return kind === "quote" ? { ...rest, quote: true } : { ...rest, quote: true, callout: kind };
148
+ }
149
+ function unquote(block3) {
150
+ if (block3.type === "quote") return paragraph(block3.content, block3.id);
151
+ return block3.type === "listItem" && block3.quote ? withQuote(block3, null) : block3;
152
+ }
119
153
  function isTextBlock(block3) {
120
- return block3.type !== "table" && block3.type !== "divider";
154
+ return block3.type !== "table" && block3.type !== "divider" && block3.type !== "detailsEnd";
155
+ }
156
+ function isTextless(block3) {
157
+ return block3.type === "divider" || block3.type === "detailsEnd";
121
158
  }
122
159
  function isPlainTextBlock(block3) {
123
- return block3.type === "code" || block3.type === "raw";
160
+ return block3.type === "code" || block3.type === "raw" || block3.type === "details";
124
161
  }
125
162
  function imageBlockOffset(block3) {
126
163
  if (block3.type !== "paragraph") return null;
@@ -145,7 +182,7 @@ function containerContent(block3, cell) {
145
182
  if (!cell) return null;
146
183
  return block3.rows[cell.row]?.[cell.col] ?? null;
147
184
  }
148
- if (block3.type === "divider") return null;
185
+ if (isTextless(block3)) return null;
149
186
  return block3.content;
150
187
  }
151
188
  function withContainerContent(block3, cell, content) {
@@ -156,7 +193,7 @@ function withContainerContent(block3, cell, content) {
156
193
  );
157
194
  return { ...block3, rows };
158
195
  }
159
- if (block3.type === "divider") return block3;
196
+ if (isTextless(block3)) return block3;
160
197
  return withContent(block3, content);
161
198
  }
162
199
  function withContent(block3, content) {
@@ -333,7 +370,7 @@ function endOf(block3) {
333
370
  const col = block3.align.length - 1;
334
371
  return { blockId: block3.id, offset: inlineLength(block3.rows[row][col]), cell: { row, col } };
335
372
  }
336
- if (block3.type === "divider") return { blockId: block3.id, offset: 0 };
373
+ if (isTextless(block3)) return { blockId: block3.id, offset: 0 };
337
374
  return { blockId: block3.id, offset: inlineLength(block3.content) };
338
375
  }
339
376
  function clampSelection(doc, sel) {
@@ -513,9 +550,9 @@ function contentOf(block3, cell) {
513
550
  function emptyLike(block3) {
514
551
  switch (block3.type) {
515
552
  case "listItem":
516
- return listItem(block3.listType, [], { indent: block3.indent });
553
+ return listItem(block3.listType, [], { indent: block3.indent, quote: quoteKind(block3) });
517
554
  case "quote":
518
- return quote();
555
+ return quote([], void 0, block3.callout);
519
556
  default:
520
557
  return paragraph();
521
558
  }
@@ -526,7 +563,7 @@ function deleteRange(state, from, to) {
526
563
  const fromBlock = state.doc.blocks[fromIndex];
527
564
  const toBlock = state.doc.blocks[toIndex];
528
565
  if (fromIndex === toIndex) {
529
- if (fromBlock.type === "divider") return state;
566
+ if (isTextless(fromBlock)) return state;
530
567
  if (fromBlock.type === "table") return deleteInTable(state, fromBlock, from, to);
531
568
  const content = deleteInline(fromBlock.content, from.offset, to.offset);
532
569
  return replaceBlock(state, withContent(fromBlock, content), caret(from.blockId, from.offset));
@@ -595,7 +632,7 @@ function deleteBackward(state) {
595
632
  const pos = state.selection.focus;
596
633
  const index = blockIndex(state.doc, pos.blockId);
597
634
  const block3 = state.doc.blocks[index];
598
- if (block3.type === "divider") return removeBlockAt(state, index, -1);
635
+ if (isTextless(block3)) return removeBlockAt(state, index, -1);
599
636
  if (pos.offset > 0) {
600
637
  const text = inlineText(contentOf(block3, pos.cell));
601
638
  const from = previousGrapheme(text, pos.offset);
@@ -608,9 +645,16 @@ function deleteBackward(state) {
608
645
  return { ...state, selection: caret(block3.id, inlineLength(contentOf(block3, prevCell)), prevCell) };
609
646
  }
610
647
  if (block3.type === "listItem" && block3.indent > 0) return replaceBlock(state, { ...block3, indent: block3.indent - 1 });
648
+ if (block3.type === "listItem" && block3.quote) return replaceBlock(state, quote(block3.content, block3.id, block3.callout));
611
649
  if (block3.type !== "paragraph") return replaceBlock(state, paragraph(block3.content, block3.id));
612
650
  const prev = state.doc.blocks[index - 1];
613
651
  if (!prev) return state;
652
+ if (prev.type === "detailsEnd") {
653
+ const end = lastTextBefore(state.doc.blocks, index);
654
+ if (!end) return state;
655
+ const selection = { anchor: end, focus: end };
656
+ return inlineLength(block3.content) === 0 ? withBlocks(state, splice(state, index, 1), selection) : { ...state, selection, storedMarks: null };
657
+ }
614
658
  if (prev.type === "divider") return withBlocks(state, splice(state, index - 1, 1));
615
659
  const prevImage = imageBlockOffset(prev);
616
660
  if (prevImage !== null) {
@@ -632,14 +676,17 @@ function deleteForward(state) {
632
676
  const pos = state.selection.focus;
633
677
  const index = blockIndex(state.doc, pos.blockId);
634
678
  const block3 = state.doc.blocks[index];
635
- if (block3.type === "divider") return removeBlockAt(state, index, 1);
679
+ if (isTextless(block3)) return removeBlockAt(state, index, 1);
636
680
  const text = inlineText(contentOf(block3, pos.cell));
637
681
  if (pos.offset < text.length) {
638
682
  return deleteRange(state, pos, { ...pos, offset: nextGrapheme(text, pos.offset) });
639
683
  }
640
684
  if (block3.type === "table") return state;
641
685
  const next = state.doc.blocks[index + 1];
642
- if (!next || next.type === "table") return state;
686
+ if (!next || next.type === "table" || next.type === "detailsEnd") return state;
687
+ if (next.type === "details") {
688
+ return inlineLength(contentOf(block3)) === 0 ? removeBlockAt(state, index, 1) : state;
689
+ }
643
690
  if (next.type === "divider") return withBlocks(state, splice(state, index + 1, 1));
644
691
  const nextImage = imageBlockOffset(next);
645
692
  if (nextImage !== null) {
@@ -648,6 +695,10 @@ function deleteForward(state) {
648
695
  }
649
696
  return deleteRange(state, pos, { blockId: next.id, offset: 0 });
650
697
  }
698
+ function lastTextBefore(blocks, index) {
699
+ for (let i = index - 1; i >= 0; i--) if (!isTextless(blocks[i])) return endOf(blocks[i]);
700
+ return null;
701
+ }
651
702
  function removeBlockAt(state, index, prefer) {
652
703
  const blocks = splice(state, index, 1);
653
704
  if (blocks.length === 0) {
@@ -668,7 +719,7 @@ function insertText(state, text) {
668
719
  const content = containerContent(block3, pos.cell);
669
720
  if (content === null) return state;
670
721
  let value = text;
671
- if (block3.type === "table") value = value.replace(/\r?\n/g, " ");
722
+ if (block3.type === "table" || block3.type === "details") value = value.replace(/\r?\n/g, " ");
672
723
  const format = isPlainTextBlock(block3) ? { marks: [] } : stored ? { marks: stored } : formatAt(content, pos.offset);
673
724
  const next = insertInline(content, pos.offset, value, format);
674
725
  return replaceBlock(s, withContainerContent(block3, pos.cell, next), caret(block3.id, pos.offset + value.length, pos.cell));
@@ -692,9 +743,13 @@ function exitBlock(state, dir) {
692
743
  const p = paragraph();
693
744
  return withBlocks(state, splice(state, dir === 1 ? index + 1 : 0, 0, p), caret(p.id, 0));
694
745
  }
746
+ function appendParagraph(state) {
747
+ const p = paragraph();
748
+ return withBlocks(state, [...state.doc.blocks, p], caret(p.id, 0));
749
+ }
695
750
  function insertLineBreak(state) {
696
751
  const block3 = getBlock(state.doc, state.selection.focus.blockId);
697
- if (block3.type === "table" || block3.type === "divider") return state;
752
+ if (block3.type === "table" || isTextless(block3) || block3.type === "details") return state;
698
753
  return insertText(state, "\n");
699
754
  }
700
755
  function splitBlock(state) {
@@ -702,11 +757,12 @@ function splitBlock(state) {
702
757
  const pos = s.selection.focus;
703
758
  const index = blockIndex(s.doc, pos.blockId);
704
759
  const block3 = s.doc.blocks[index];
705
- if (block3.type === "divider") {
760
+ if (isTextless(block3)) {
706
761
  const p = paragraph();
707
762
  return withBlocks(s, splice(s, index + 1, 0, p), caret(p.id, 0));
708
763
  }
709
764
  if (block3.type === "table") return tableEnter(s, block3, pos);
765
+ if (block3.type === "details") return detailsEnter(s, block3, index, pos.offset);
710
766
  const text = inlineText(block3.content);
711
767
  const length = text.length;
712
768
  if (isPlainTextBlock(block3)) {
@@ -723,10 +779,16 @@ function splitBlock(state) {
723
779
  return replaceBlock(s, code, caret(code.id, 0));
724
780
  }
725
781
  if (length === 0 && block3.type === "listItem") {
726
- const next = block3.indent > 0 ? { ...block3, indent: block3.indent - 1 } : paragraph([], block3.id);
782
+ const next = block3.indent > 0 ? { ...block3, indent: block3.indent - 1 } : block3.quote ? quote([], block3.id, block3.callout) : paragraph([], block3.id);
727
783
  return replaceBlock(s, next);
728
784
  }
729
785
  if (length === 0 && block3.type === "quote") return replaceBlock(s, paragraph([], block3.id));
786
+ if (length === 0 && block3.type === "paragraph" && s.doc.blocks[index + 1]?.type === "detailsEnd") {
787
+ const blocks = s.doc.blocks.slice();
788
+ blocks.splice(index, 1);
789
+ blocks.splice(index + 1, 0, block3);
790
+ return withBlocks(s, blocks, s.selection);
791
+ }
730
792
  if (pos.offset === 0 && length > 0) {
731
793
  return withBlocks(s, splice(s, index, 0, emptyLike(block3)), s.selection);
732
794
  }
@@ -740,6 +802,76 @@ function splitBlock(state) {
740
802
  }
741
803
  return withBlocks(s, splice(s, index, 1, left, right), caret(right.id, 0));
742
804
  }
805
+ function detailsEnter(state, block3, index, offset, collapsed = false) {
806
+ const length = inlineLength(block3.content);
807
+ if (offset === 0 && length > 0) return withBlocks(state, splice(state, index, 0, paragraph()), state.selection);
808
+ const first = state.doc.blocks[index + 1];
809
+ if (!collapsed && offset === length && first?.type === "paragraph" && inlineLength(first.content) === 0) {
810
+ return { ...state, selection: caret(first.id, 0), storedMarks: null };
811
+ }
812
+ const left = withContent(block3, sliceInline(block3.content, 0, offset));
813
+ const right = paragraph(sliceInline(block3.content, offset));
814
+ const blocks = state.doc.blocks.slice();
815
+ blocks[index] = left;
816
+ blocks.splice(collapsed ? (sectionEnd(blocks, index) ?? index) + 1 : index + 1, 0, right);
817
+ return withBlocks(state, blocks, caret(right.id, 0));
818
+ }
819
+ function splitCollapsedTitle(state) {
820
+ const s = deleteSelection(state);
821
+ const pos = s.selection.focus;
822
+ const index = blockIndex(s.doc, pos.blockId);
823
+ const block3 = s.doc.blocks[index];
824
+ return block3.type === "details" ? detailsEnter(s, block3, index, pos.offset, true) : splitBlock(state);
825
+ }
826
+ function sectionEnd(blocks, index) {
827
+ let depth = 0;
828
+ for (let i = index; i < blocks.length; i++) {
829
+ const type = blocks[i].type;
830
+ if (type === "details") depth++;
831
+ else if (type === "detailsEnd" && --depth === 0) return i;
832
+ }
833
+ return null;
834
+ }
835
+ function sectionTitle(blocks, index) {
836
+ let depth = 0;
837
+ for (let i = index; i >= 0; i--) {
838
+ const type = blocks[i].type;
839
+ if (type === "detailsEnd") depth++;
840
+ else if (type === "details" && --depth === 0) return i;
841
+ }
842
+ return null;
843
+ }
844
+ function closeSections(blocks) {
845
+ if (!blocks.some((b) => b.type === "details" || b.type === "detailsEnd")) return blocks;
846
+ const open = [];
847
+ const drop = /* @__PURE__ */ new Set();
848
+ blocks.forEach((b, i) => {
849
+ if (b.type === "details") open.push(i);
850
+ else if (b.type === "detailsEnd" && open.pop() === void 0) drop.add(i);
851
+ });
852
+ if (drop.size === 0 && open.length === 0) return blocks;
853
+ const unclosed = new Set(open);
854
+ const out = [];
855
+ blocks.forEach((b, i) => {
856
+ if (drop.has(i)) return;
857
+ out.push(unclosed.has(i) && b.type === "details" ? paragraph(b.content, b.id) : b);
858
+ });
859
+ return out.length > 0 ? out : [paragraph()];
860
+ }
861
+ function balanceSections(state) {
862
+ if (!state.doc.blocks.some((b) => b.type === "details" || b.type === "detailsEnd")) return state;
863
+ const blocks = closeSections(state.doc.blocks);
864
+ let next = state;
865
+ if (blocks !== state.doc.blocks) {
866
+ const doc = { blocks };
867
+ next = { ...state, doc, selection: clampSelection(doc, state.selection) };
868
+ }
869
+ const onEnd = (p) => next.doc.blocks.find((b) => b.id === p.blockId)?.type === "detailsEnd";
870
+ const { anchor, focus } = next.selection;
871
+ if (!onEnd(anchor) && !onEnd(focus)) return next;
872
+ const move = (p) => onEnd(p) ? lastTextBefore(next.doc.blocks, blockIndex(next.doc, p.blockId)) ?? p : p;
873
+ return { ...next, selection: { anchor: move(anchor), focus: move(focus) } };
874
+ }
743
875
  function tableEnter(state, block3, pos) {
744
876
  const cell = pos.cell;
745
877
  let table2 = block3;
@@ -751,7 +883,7 @@ function mapTextInRange(state, from, to, fn) {
751
883
  const start = blockIndex(state.doc, from.blockId);
752
884
  const end = blockIndex(state.doc, to.blockId);
753
885
  const updated = state.doc.blocks.slice(start, end + 1).map((block3) => {
754
- if (block3.type === "divider" || isPlainTextBlock(block3)) return block3;
886
+ if (isTextless(block3) || isPlainTextBlock(block3)) return block3;
755
887
  if (block3.type === "table") {
756
888
  const cols = block3.align.length;
757
889
  const fromIdx = block3.id === from.blockId && from.cell ? from.cell.row * cols + from.cell.col : 0;
@@ -897,10 +1029,13 @@ function convert(block3, spec) {
897
1029
  return listItem(spec.listType, content, {
898
1030
  id: block3.id,
899
1031
  indent: block3.type === "listItem" ? block3.indent : 0,
900
- checked: block3.type === "listItem" ? block3.checked : false
1032
+ checked: block3.type === "listItem" ? block3.checked : false,
1033
+ start: block3.type === "listItem" && block3.listType === spec.listType ? block3.start : void 0,
1034
+ quote: quoteKind(block3)
901
1035
  });
902
1036
  case "quote":
903
- return quote(content, block3.id);
1037
+ if (block3.type === "listItem") return withQuote(block3, spec.callout ?? (block3.quote ? block3.callout ?? "quote" : "quote"));
1038
+ return quote(content, block3.id, spec.callout);
904
1039
  case "code":
905
1040
  return codeBlock(spec.language ?? (block3.type === "code" ? block3.language : ""), inlineText(toPlain(content)), block3.id);
906
1041
  default:
@@ -911,13 +1046,16 @@ function isConvertible(block3) {
911
1046
  return isTextBlock(block3) && block3.type !== "raw";
912
1047
  }
913
1048
  function setBlockType(state, spec) {
914
- if (spec.type === "table" || spec.type === "divider") return insertBlock(state, spec);
1049
+ if (spec.type === "table" || spec.type === "divider" || spec.type === "details") return insertBlock(state, spec);
1050
+ return convertSelected(state, spec, (b) => convert(b, spec));
1051
+ }
1052
+ function convertSelected(state, spec, convertBlock) {
915
1053
  const { from, to } = orderedRange(state.doc, state.selection);
916
1054
  const start = blockIndex(state.doc, from.blockId);
917
1055
  const end = blockIndex(state.doc, to.blockId);
918
1056
  const range = state.doc.blocks.slice(start, end + 1);
919
1057
  if (spec.type === "code" && range.filter(isConvertible).length > 1) return mergeIntoCode(state, start, range, spec.language);
920
- const updated = range.map((b) => isConvertible(b) ? convert(b, spec) : b);
1058
+ const updated = range.map((b) => isConvertible(b) ? convertBlock(b) : b);
921
1059
  const doc = { blocks: splice(state, start, updated.length, ...updated) };
922
1060
  return { doc, selection: clampSelection(doc, state.selection), storedMarks: null };
923
1061
  }
@@ -945,6 +1083,28 @@ function mergeIntoCode(state, start, range, language) {
945
1083
  const selection = { anchor: startOf(merged[0]), focus: endOf(merged[merged.length - 1]) };
946
1084
  return { doc: { blocks: splice(state, start, range.length, ...out) }, selection, storedMarks: null };
947
1085
  }
1086
+ function quoteRun(state, blockId) {
1087
+ const blocks = state.doc.blocks;
1088
+ const index = blockIndex(state.doc, blockId);
1089
+ const block3 = blocks[index];
1090
+ if (quoteKind(block3) === null) return null;
1091
+ let start = index;
1092
+ let end = index;
1093
+ while (sameQuote(block3, blocks[start - 1])) start--;
1094
+ while (sameQuote(block3, blocks[end + 1])) end++;
1095
+ return { start, end };
1096
+ }
1097
+ function setCallout(state, blockId, callout) {
1098
+ const run = quoteRun(state, blockId);
1099
+ if (!run) return state;
1100
+ const blocks = state.doc.blocks.slice(run.start, run.end + 1);
1101
+ if (blocks.every((b) => quoteKind(b) === (callout ?? "quote"))) return state;
1102
+ const updated = blocks.map(
1103
+ (b) => b.type === "listItem" ? withQuote(b, callout ?? "quote") : b.type === "quote" ? quote(b.content, b.id, callout ?? void 0) : b
1104
+ );
1105
+ const doc = { blocks: splice(state, run.start, updated.length, ...updated) };
1106
+ return { doc, selection: state.selection, storedMarks: state.storedMarks };
1107
+ }
948
1108
  function convertibleBlocks(state) {
949
1109
  const { from, to } = orderedRange(state.doc, state.selection);
950
1110
  return state.doc.blocks.slice(blockIndex(state.doc, from.blockId), blockIndex(state.doc, to.blockId) + 1).filter(isConvertible);
@@ -957,6 +1117,10 @@ function hasType(block3, spec) {
957
1117
  return block3.type === "listItem" && block3.listType === spec.listType;
958
1118
  case "code":
959
1119
  return block3.type === "code";
1120
+ case "quote": {
1121
+ const kind = quoteKind(block3);
1122
+ return kind !== null && (!spec.callout || kind === spec.callout);
1123
+ }
960
1124
  default:
961
1125
  return block3.type === spec.type;
962
1126
  }
@@ -965,12 +1129,19 @@ function toggleBlockType(state, spec) {
965
1129
  const text = convertibleBlocks(state);
966
1130
  if (text.length === 0) return state;
967
1131
  const on = text.every((b) => hasType(b, spec));
968
- return setBlockType(state, on ? { type: "paragraph" } : spec);
1132
+ if (!on) return setBlockType(state, spec);
1133
+ const off = { type: "paragraph" };
1134
+ return convertSelected(state, off, (b) => {
1135
+ if (b.type === "listItem" && spec.type === "quote") return withQuote(b, null);
1136
+ if (b.type === "listItem" && b.quote && spec.type === "listItem") return quote(b.content, b.id, b.callout);
1137
+ return convert(b, off);
1138
+ });
969
1139
  }
970
1140
  function insertBlock(state, spec) {
971
1141
  const pos = state.selection.focus;
972
1142
  const index = blockIndex(state.doc, pos.blockId);
973
1143
  const current = state.doc.blocks[index];
1144
+ if (spec.type === "details") return insertSection(state, index);
974
1145
  if (spec.type !== "table" && spec.type !== "divider") return setBlockType(state, spec);
975
1146
  const isEmpty = isTextBlock(current) && inlineLength(current.content) === 0;
976
1147
  const created = spec.type === "table" ? emptyTable(spec.rows ?? 3, spec.cols ?? 3) : divider();
@@ -988,6 +1159,16 @@ function insertBlock(state, spec) {
988
1159
  const at = isEmpty ? index : index + 1;
989
1160
  return withBlocks(state, splice(state, at, isEmpty ? 1 : 0, ...blocks), { anchor: start, focus: start });
990
1161
  }
1162
+ function insertSection(state, index) {
1163
+ const current = state.doc.blocks[index];
1164
+ const convert2 = isConvertible(current) && current.type !== "details";
1165
+ const title = details(convert2 ? current.content : [], convert2 ? { id: current.id } : {});
1166
+ const body = paragraph();
1167
+ const at = convert2 ? index : index + 1;
1168
+ const blocks = splice(state, at, convert2 ? 1 : 0, title, body, detailsEnd());
1169
+ const target = inlineLength(title.content) === 0 ? caret(title.id, 0) : caret(body.id, 0);
1170
+ return withBlocks(state, blocks, target);
1171
+ }
991
1172
  function indentListItems(state, delta2) {
992
1173
  const { from, to } = orderedRange(state.doc, state.selection);
993
1174
  const start = blockIndex(state.doc, from.blockId);
@@ -997,8 +1178,7 @@ function indentListItems(state, delta2) {
997
1178
  for (let i = start; i <= end; i++) {
998
1179
  const b = blocks[i];
999
1180
  if (b.type !== "listItem") continue;
1000
- const prev = blocks[i - 1];
1001
- const max = prev?.type === "listItem" ? Math.min(MAX_INDENT, prev.indent + 1) : 0;
1181
+ const max = maxIndent(blocks[i - 1], b);
1002
1182
  const indent = Math.max(0, Math.min(max, b.indent + delta2));
1003
1183
  if (indent !== b.indent) {
1004
1184
  blocks[i] = { ...b, indent };
@@ -1070,12 +1250,14 @@ function deleteBlock(state, blockId) {
1070
1250
  function spanBlocks(blocks, range) {
1071
1251
  return { anchor: startOf(blocks[range.from]), focus: endOf(blocks[range.to]) };
1072
1252
  }
1253
+ function maxIndent(prev, item) {
1254
+ return prev?.type === "listItem" && quoteKind(prev) === quoteKind(item) ? Math.min(MAX_INDENT, prev.indent + 1) : 0;
1255
+ }
1073
1256
  function fitIndents(blocks, index) {
1074
1257
  for (let i = Math.max(0, index); i < blocks.length; i++) {
1075
1258
  const block3 = blocks[i];
1076
1259
  if (block3.type !== "listItem") return;
1077
- const prev = blocks[i - 1];
1078
- const max = prev?.type === "listItem" ? Math.min(MAX_INDENT, prev.indent + 1) : 0;
1260
+ const max = maxIndent(blocks[i - 1], block3);
1079
1261
  if (block3.indent <= max) return;
1080
1262
  blocks[i] = { ...block3, indent: max };
1081
1263
  }
@@ -1187,9 +1369,11 @@ var BLOCK_RULES = [
1187
1369
  [/^\d{1,9}[.)] $/, () => ({ type: "listItem", listType: "ordered" })],
1188
1370
  [/^\[[ xX]?\] $/, () => ({ type: "listItem", listType: "task" })],
1189
1371
  [/^> $/, () => ({ type: "quote" })],
1190
- [/^```([^`\s]*) $/, (m) => ({ type: "code", language: m[1] })]
1372
+ [new RegExp(`^\\[!(${CALLOUT_TYPES.join("|")})\\] $`, "i"), (m) => ({ type: "quote", callout: m[1].toLowerCase() })],
1373
+ [/^```([^`\s]*) $/, (m) => ({ type: "code", language: m[1] })],
1374
+ [/^>>> $/, () => ({ type: "details" })]
1191
1375
  ];
1192
- function applyBlockInputRules(state) {
1376
+ function applyBlockInputRules(state, dialect = {}) {
1193
1377
  if (!isCollapsed(state.selection)) return null;
1194
1378
  const pos = state.selection.focus;
1195
1379
  const block3 = getBlock(state.doc, pos.blockId);
@@ -1200,13 +1384,18 @@ function applyBlockInputRules(state) {
1200
1384
  const rest = withContent(block3, sliceInline(block3.content, pos.offset));
1201
1385
  return withBlocks(state, splice(state, index, 1, divider(), rest), caret(rest.id, 0));
1202
1386
  }
1203
- const allowed = block3.type === "paragraph" || block3.type === "listItem" && block3.listType === "bullet";
1387
+ const allowed = block3.type === "paragraph" || block3.type === "quote" || block3.type === "listItem" && block3.listType === "bullet";
1204
1388
  if (!allowed) return null;
1205
1389
  for (const [re, toSpec] of BLOCK_RULES) {
1206
1390
  const m = re.exec(before);
1207
1391
  if (!m) continue;
1208
1392
  const spec = toSpec(m);
1393
+ if (spec.type === "quote" && spec.callout && dialect.callouts === false || spec.type === "details" && dialect.details === false) continue;
1209
1394
  if (block3.type === "listItem" && !(spec.type === "listItem" && spec.listType === "task")) continue;
1395
+ if (block3.type === "quote" && spec.type !== "listItem") {
1396
+ if (spec.type !== "quote" || !spec.callout) continue;
1397
+ return setCallout(deleteRange(state, { blockId: block3.id, offset: 0 }, pos), block3.id, spec.callout);
1398
+ }
1210
1399
  const stripped = deleteRange(state, { blockId: block3.id, offset: 0 }, pos);
1211
1400
  let next = setBlockType(stripped, spec);
1212
1401
  const converted = getBlock(next.doc, block3.id);
@@ -1217,7 +1406,8 @@ function applyBlockInputRules(state) {
1217
1406
  id: converted.id,
1218
1407
  indent: converted.indent,
1219
1408
  checked,
1220
- start: converted.listType === "ordered" && start ? Number(start[1]) : void 0
1409
+ start: converted.listType === "ordered" && start ? Number(start[1]) : void 0,
1410
+ quote: quoteKind(converted)
1221
1411
  });
1222
1412
  next = replaceBlock(next, updated, next.selection);
1223
1413
  }
@@ -1315,10 +1505,8 @@ function clampListIndents(state, before) {
1315
1505
  let blocks = null;
1316
1506
  let max = 0;
1317
1507
  state.doc.blocks.forEach((block3, i) => {
1318
- if (block3.type !== "listItem") {
1319
- max = 0;
1320
- return;
1321
- }
1508
+ if (block3.type !== "listItem" || quoteKind(block3) !== quoteKind(state.doc.blocks[i - 1])) max = 0;
1509
+ if (block3.type !== "listItem") return;
1322
1510
  if (block3.indent > max) (blocks ??= [...state.doc.blocks])[i] = { ...block3, indent: max };
1323
1511
  max = Math.min(block3.indent, max) + 1;
1324
1512
  });
@@ -1501,20 +1689,16 @@ function docToHtml(doc) {
1501
1689
  let i = 0;
1502
1690
  while (i < blocks.length) {
1503
1691
  const block3 = blocks[i];
1504
- if (block3.type === "listItem") {
1505
- let j = i;
1506
- while (j < blocks.length && blocks[j].type === "listItem") j++;
1507
- out += listHtml(blocks.slice(i, j));
1692
+ const kind = quoteKind(block3);
1693
+ if (kind) {
1694
+ let j = i + 1;
1695
+ while (j < blocks.length && sameQuote(block3, blocks[j])) j++;
1696
+ out += quoteHtml(kind === "quote" ? void 0 : kind, docToHtml({ blocks: blocks.slice(i, j).map(unquote) }));
1508
1697
  i = j;
1509
- } else if (block3.type === "quote") {
1698
+ } else if (block3.type === "listItem") {
1510
1699
  let j = i;
1511
- let inner = "";
1512
- while (j < blocks.length && blocks[j].type === "quote") {
1513
- const quote2 = blocks[j];
1514
- if (quote2.type === "quote") inner += `<p>${inlineHtml(quote2.content)}</p>`;
1515
- j++;
1516
- }
1517
- out += `<blockquote>${inner}</blockquote>`;
1700
+ while (j < blocks.length && blocks[j].type === "listItem" && quoteKind(blocks[j]) === null) j++;
1701
+ out += listHtml(blocks.slice(i, j));
1518
1702
  i = j;
1519
1703
  } else {
1520
1704
  out += blockHtml(block3);
@@ -1540,6 +1724,11 @@ function blockHtml(block3) {
1540
1724
  return block3.syntax === "html" ? inlineText(block3.content) : `<pre>${escapeHtml(inlineText(block3.content))}</pre>`;
1541
1725
  case "divider":
1542
1726
  return "<hr>";
1727
+ // The body's blocks come between, so the two parts make one element.
1728
+ case "details":
1729
+ return `<details${block3.open ? " open" : ""}><summary>${escapeHtml(inlineText(block3.content))}</summary>`;
1730
+ case "detailsEnd":
1731
+ return "</details>";
1543
1732
  case "table": {
1544
1733
  const cell = (tag, content, c) => {
1545
1734
  const align = block3.align[c];
@@ -1552,11 +1741,15 @@ function blockHtml(block3) {
1552
1741
  return html + "</table>";
1553
1742
  }
1554
1743
  case "listItem":
1555
- return listHtml([block3]);
1556
1744
  case "quote":
1557
- return `<blockquote><p>${inlineHtml(block3.content)}</p></blockquote>`;
1745
+ return docToHtml({ blocks: [block3] });
1558
1746
  }
1559
1747
  }
1748
+ function quoteHtml(callout, inner) {
1749
+ if (!callout) return `<blockquote>${inner}</blockquote>`;
1750
+ const title = callout[0].toUpperCase() + callout.slice(1);
1751
+ return `<blockquote class="markdown-alert markdown-alert-${callout}"><p class="markdown-alert-title"><strong>${title}</strong></p>${inner}</blockquote>`;
1752
+ }
1560
1753
  function listHtml(items) {
1561
1754
  let out = "";
1562
1755
  const open = [];
@@ -1758,6 +1951,14 @@ function formatOf(el, parent) {
1758
1951
  const sorted = sortMarks(marks);
1759
1952
  return link === void 0 ? { marks: sorted, whiteSpace } : { marks: sorted, link, whiteSpace };
1760
1953
  }
1954
+ function calloutOf(el) {
1955
+ const m = /(?:^|\s)markdown-alert-([a-z]+)(?:\s|$)/.exec(el.getAttribute("class") ?? "");
1956
+ const type = m?.[1];
1957
+ return type && CALLOUT_TYPES.includes(type) ? type : void 0;
1958
+ }
1959
+ function hasClass(el, name) {
1960
+ return (el.getAttribute("class") ?? "").split(/\s+/).includes(name);
1961
+ }
1761
1962
  var Converter = class _Converter {
1762
1963
  out = [];
1763
1964
  spans = [];
@@ -1765,12 +1966,12 @@ var Converter = class _Converter {
1765
1966
  this.flush();
1766
1967
  return this.out;
1767
1968
  }
1768
- /** Converts the children of a block-level element. */
1769
- blocks(parent, format) {
1969
+ /** Converts the children of a block-level element, except those `skip` names. */
1970
+ blocks(parent, format, skip) {
1770
1971
  for (const node of Array.from(parent.childNodes)) {
1771
1972
  if (node.nodeType === TEXT_NODE) {
1772
1973
  this.text(node.nodeValue ?? "", format);
1773
- } else if (node.nodeType === ELEMENT_NODE) {
1974
+ } else if (node.nodeType === ELEMENT_NODE && !skip?.(node)) {
1774
1975
  this.element(node, format);
1775
1976
  }
1776
1977
  }
@@ -1789,7 +1990,15 @@ var Converter = class _Converter {
1789
1990
  } else if (tag === "li") {
1790
1991
  this.flush();
1791
1992
  this.listItem(el, "bullet", 0, void 0, format);
1792
- } else if (tag === "blockquote") {
1993
+ } else if (tag === "details") {
1994
+ this.flush();
1995
+ const summary = Array.from(el.children).find((c) => tagOf(c) === "summary");
1996
+ const title = (summary?.textContent ?? "").replace(/\s+/g, " ").trim();
1997
+ this.out.push(details(plain(title), { open: el.hasAttribute("open") }));
1998
+ this.blocks(el, format, (child) => child === summary);
1999
+ this.flush();
2000
+ this.out.push(detailsEnd());
2001
+ } else if (tag === "blockquote" || calloutOf(el)) {
1793
2002
  this.flush();
1794
2003
  this.blockquote(el, format);
1795
2004
  } else if (tag === "pre") {
@@ -1974,23 +2183,24 @@ var Converter = class _Converter {
1974
2183
  this.spans = saved;
1975
2184
  }
1976
2185
  // -- Quotes and tables ----------------------------------------------------
2186
+ /** A blockquote, or a callout as GitHub renders an alert (its title is dropped). */
1977
2187
  blockquote(el, format) {
2188
+ const callout = calloutOf(el);
1978
2189
  const inner = new _Converter();
1979
- inner.blocks(el, format);
1980
- for (const block3 of inner.finish()) {
2190
+ inner.blocks(el, format, callout ? (child) => hasClass(child, "markdown-alert-title") : void 0);
2191
+ const blocks = inner.finish();
2192
+ for (const block3 of blocks) {
1981
2193
  switch (block3.type) {
1982
2194
  case "paragraph":
1983
2195
  case "heading":
1984
2196
  case "quote":
1985
2197
  case "code":
1986
2198
  case "raw":
1987
- this.out.push(quote(block3.content));
2199
+ this.out.push(quote(block3.content, void 0, callout));
1988
2200
  break;
1989
- case "listItem": {
1990
- const marker = block3.listType === "ordered" ? "1. " : block3.listType === "task" ? block3.checked ? "- [x] " : "- [ ] " : "- ";
1991
- this.out.push(quote([...plain(marker), ...block3.content]));
2201
+ case "listItem":
2202
+ this.out.push(withQuote(block3, callout ?? "quote"));
1992
2203
  break;
1993
- }
1994
2204
  default:
1995
2205
  this.out.push(block3);
1996
2206
  }
@@ -2113,13 +2323,29 @@ var DEFAULT_LABELS = {
2113
2323
  heading1: "Heading 1",
2114
2324
  heading2: "Heading 2",
2115
2325
  heading3: "Heading 3",
2326
+ heading4: "Heading 4",
2116
2327
  bulletList: "Bulleted list",
2117
2328
  numberedList: "Numbered list",
2118
2329
  todoList: "To-do list",
2119
2330
  /** Accessible name of a task checkbox whose item has no text. */
2120
2331
  task: "Task",
2121
2332
  quote: "Quote",
2333
+ /** The slash menu item, and the title of a callout's block menu section. */
2334
+ callout: "Callout",
2335
+ /** Callout types: each callout's title, and its block menu items. */
2336
+ calloutNote: "Note",
2337
+ calloutTip: "Tip",
2338
+ calloutImportant: "Important",
2339
+ calloutWarning: "Warning",
2340
+ calloutCaution: "Caution",
2122
2341
  code: "Code block",
2342
+ /** The slash menu item that makes a collapsible section. */
2343
+ details: "Collapsible section",
2344
+ /** Shown in an empty section title. */
2345
+ detailsHint: "Title",
2346
+ /** The toggle of a collapsible section. */
2347
+ expandSection: "Expand",
2348
+ collapseSection: "Collapse",
2123
2349
  table: "Table",
2124
2350
  divider: "Divider",
2125
2351
  noResults: "No results",
@@ -2142,6 +2368,10 @@ var DEFAULT_LABELS = {
2142
2368
  list: "List",
2143
2369
  linkPlaceholder: "Paste or type a link\u2026",
2144
2370
  removeLink: "Remove link",
2371
+ /** The link card's buttons. */
2372
+ openLink: "Open link",
2373
+ copyLink: "Copy link",
2374
+ editLink: "Edit link",
2145
2375
  /** Shown in the empty paragraph that has the caret, with the `slashHint` option. */
2146
2376
  slashHint: "Type '/' for commands",
2147
2377
  blockHandle: "Open block menu",
@@ -2190,6 +2420,8 @@ var ICONS = {
2190
2420
  heading2: ["M4 12h8", "M4 18V6", "M12 18V6", "M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1"],
2191
2421
  /** `heading-3` */
2192
2422
  heading3: ["M4 12h8", "M4 18V6", "M12 18V6", "M17.5 10.5c1.7-1 3.5 0 3.5 1.5a2 2 0 0 1-2 2", "M17 17.5c2 1.5 4 .3 4-1.5a2 2 0 0 0-2-2"],
2423
+ /** `heading-4` */
2424
+ heading4: ["M12 18V6", "M17 10v3a1 1 0 0 0 1 1h3", "M21 10v8", "M4 12h8", "M4 18V6"],
2193
2425
  /** `list` */
2194
2426
  bulletList: ["M3 5h.01", "M3 12h.01", "M3 19h.01", "M8 5h13", "M8 12h13", "M8 19h13"],
2195
2427
  /** `list-ordered` */
@@ -2198,6 +2430,24 @@ var ICONS = {
2198
2430
  todoList: ["M13 5h8", "M13 12h8", "M13 19h8", "m3 17 2 2 4-4", ["rect", { x: "3", y: "4", width: "6", height: "6", rx: "1" }]],
2199
2431
  /** `text-quote` */
2200
2432
  quote: ["M17 5H3", "M21 12H8", "M21 19H8", "M3 12v7"],
2433
+ /** `info`, as a Note callout */
2434
+ callout: [["circle", { cx: "12", cy: "12", r: "10" }], "M12 16v-4", "M12 8h.01"],
2435
+ /** `info` */
2436
+ calloutNote: [["circle", { cx: "12", cy: "12", r: "10" }], "M12 16v-4", "M12 8h.01"],
2437
+ /** `lightbulb` */
2438
+ calloutTip: ["M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5", "M9 18h6", "M10 22h4"],
2439
+ /** `message-square-warning` */
2440
+ calloutImportant: ["M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z", "M12 15h.01", "M12 7v4"],
2441
+ /** `triangle-alert` */
2442
+ calloutWarning: ["m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3", "M12 9v4", "M12 17h.01"],
2443
+ /** `octagon-alert` */
2444
+ calloutCaution: [
2445
+ "M12 16h.01",
2446
+ "M12 8v4",
2447
+ "M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z"
2448
+ ],
2449
+ /** `list-collapse` */
2450
+ details: ["M10 5h11", "M10 12h11", "M10 19h11", "m3 10 3-3-3-3", "m3 20 3-3-3-3"],
2201
2451
  /** `square-code` */
2202
2452
  code: ["m10 9-3 3 3 3", "m14 15 3-3-3-3", ["rect", { x: "3", y: "3", width: "18", height: "18", rx: "2" }]],
2203
2453
  /** `table` */
@@ -2262,6 +2512,14 @@ var ICONS = {
2262
2512
  strike: ["M16 4H9a3 3 0 0 0-2.83 4", "M14 12a4 4 0 0 1 0 8H6", ["line", { x1: "4", x2: "20", y1: "12", y2: "12" }]],
2263
2513
  /** `code` */
2264
2514
  inlineCode: ["m16 18 6-6-6-6", "m8 6-6 6 6 6"],
2515
+ /** `external-link` */
2516
+ openLink: ["M15 3h6v6", "M10 14 21 3", "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"],
2517
+ /** `copy` */
2518
+ copyLink: [["rect", { width: "14", height: "14", x: "8", y: "8", rx: "2", ry: "2" }], "M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"],
2519
+ /** `pencil` */
2520
+ editLink: ["M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z", "m15 5 4 4"],
2521
+ /** `unlink` */
2522
+ removeLink: ["m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71", "m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71", "M8 2v3", "M2 8h3", "M16 19v3", "M19 16h3"],
2265
2523
  /** `link` */
2266
2524
  link: ["M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71", "M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"],
2267
2525
  /** `image-off` */
@@ -2361,7 +2619,7 @@ function inlineNodesText(nodes, soft) {
2361
2619
  import { lookupEntity } from "#entities";
2362
2620
 
2363
2621
  // src/markdown/options.ts
2364
- var DEFAULT_MARKDOWN = { breaks: false, setext: true, autolinks: true, syntax: [], inline: [], block: [], escape: "" };
2622
+ var DEFAULT_MARKDOWN = { breaks: false, setext: true, autolinks: true, callouts: true, details: true, syntax: [], inline: [], block: [], escape: "" };
2365
2623
  var resolved = /* @__PURE__ */ new WeakMap();
2366
2624
  function resolveMarkdown(options) {
2367
2625
  if (!options) return DEFAULT_MARKDOWN;
@@ -2372,6 +2630,8 @@ function resolveMarkdown(options) {
2372
2630
  breaks: options.breaks ?? false,
2373
2631
  setext: options.setext ?? true,
2374
2632
  autolinks: options.autolinks ?? true,
2633
+ callouts: options.callouts ?? true,
2634
+ details: options.details ?? true,
2375
2635
  syntax,
2376
2636
  inline: syntax.flatMap((s) => s.inline ?? []),
2377
2637
  block: syntax.flatMap((s) => s.block ?? []),
@@ -2384,7 +2644,10 @@ function resolveMarkdown(options) {
2384
2644
 
2385
2645
  // src/markdown/lower.ts
2386
2646
  function lowerTopLevel(node, options, source) {
2387
- if (!fitsModel(node, 0)) return [rawBlock("markdown", source)];
2647
+ return lowerIfFits(node, options) ?? [rawBlock("markdown", source)];
2648
+ }
2649
+ function lowerIfFits(node, options) {
2650
+ if (!fitsModel(node, 0)) return null;
2388
2651
  const blocks = [];
2389
2652
  lowerBlock(node, blocks, options);
2390
2653
  return blocks;
@@ -2392,7 +2655,7 @@ function lowerTopLevel(node, options, source) {
2392
2655
  function fitsModel(node, depth) {
2393
2656
  switch (node.type) {
2394
2657
  case "blockQuote":
2395
- return node.children.every((child) => child.type === "paragraph");
2658
+ return node.children.every((child) => child.type === "paragraph" || child.type === "list" && fitsModel(child, 0));
2396
2659
  case "list":
2397
2660
  return depth <= MAX_INDENT && node.items.every(
2398
2661
  (item) => item.children.every(
@@ -2504,7 +2767,7 @@ function listTypeOf(list, item) {
2504
2767
  if (item.task) return "task";
2505
2768
  return list.ordered ? "ordered" : "bullet";
2506
2769
  }
2507
- function lowerList(list, depth, out, o) {
2770
+ function lowerList(list, depth, out, o, quoted) {
2508
2771
  list.items.forEach((item, index) => {
2509
2772
  const first = item.children[0];
2510
2773
  const listType = listTypeOf(list, item);
@@ -2512,19 +2775,35 @@ function lowerList(list, depth, out, o) {
2512
2775
  listItem(listType, first?.type === "paragraph" ? lowerInlines(first.children, o) : [], {
2513
2776
  indent: Math.min(depth, MAX_INDENT),
2514
2777
  checked: item.checked,
2515
- start: index === 0 && listType === "ordered" ? list.start : void 0
2778
+ start: index === 0 && listType === "ordered" ? list.start : void 0,
2779
+ quote: quoted
2516
2780
  })
2517
2781
  );
2518
- for (const child of item.children) if (child.type === "list") lowerList(child, depth + 1, out, o);
2782
+ for (const child of item.children) if (child.type === "list") lowerList(child, depth + 1, out, o, quoted);
2519
2783
  });
2520
2784
  }
2521
2785
  function lowerQuote(children, out, o) {
2522
- for (const child of children) {
2523
- if (child.type !== "paragraph") continue;
2524
- const content = lowerInlines(child.children, o);
2525
- if (isEmptyLine(content)) out.push(quote([]));
2526
- else if (content.length > 0) out.push(quote(content));
2527
- }
2786
+ const alert = o.callouts === false ? null : calloutOf2(children);
2787
+ const callout = alert?.type;
2788
+ const start = out.length;
2789
+ children.forEach((child, i) => {
2790
+ if (child.type === "list") lowerList(child, 0, out, o, callout ?? "quote");
2791
+ if (child.type !== "paragraph") return;
2792
+ const content = lowerInlines(i === 0 && alert ? alert.rest : child.children, o);
2793
+ if (isEmptyLine(content)) out.push(quote([], void 0, callout));
2794
+ else if (content.length > 0) out.push(quote(content, void 0, callout));
2795
+ });
2796
+ if (callout && out.length === start) out.push(quote([], void 0, callout));
2797
+ }
2798
+ var ALERT_MARKER = new RegExp(`^\\[!(${CALLOUT_TYPES.join("|")})\\]$`, "i");
2799
+ function calloutOf2(children) {
2800
+ const first = children[0];
2801
+ if (first?.type !== "paragraph") return null;
2802
+ const [marker, after] = first.children;
2803
+ const m = marker?.type === "text" ? ALERT_MARKER.exec(marker.value) : null;
2804
+ if (!m) return null;
2805
+ if (after && after.type !== "softBreak" && after.type !== "hardBreak") return null;
2806
+ return { type: m[1].toLowerCase(), rest: first.children.slice(2) };
2528
2807
  }
2529
2808
 
2530
2809
  // src/markdown/inline.ts
@@ -2637,6 +2916,10 @@ function decodeEntity(entity2) {
2637
2916
  }
2638
2917
  return lookupEntity(entity2.slice(1, -1)) ?? null;
2639
2918
  }
2919
+ var reEntity = new RegExp(ENTITY, "g");
2920
+ function decodeEntities(s) {
2921
+ return s.includes("&") ? s.replace(reEntity, (m) => decodeEntity(m) ?? m) : s;
2922
+ }
2640
2923
  function unescapeString(s) {
2641
2924
  if (!s.includes("\\") && !s.includes("&")) return s;
2642
2925
  return s.replace(reEntityOrEscapedChar, (m) => m[0] === "\\" ? m[1] : decodeEntity(m) ?? m);
@@ -3356,6 +3639,10 @@ var reHtmlBlockOpen = [
3356
3639
  /^<[/]?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[123456]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:[ \t]|[/]?>|$)/i,
3357
3640
  new RegExp(`^(?:${OPENTAG}|${CLOSETAG})[ \\t]*$`, "i")
3358
3641
  ];
3642
+ function interruptsParagraph(text) {
3643
+ for (let type = 1; type <= 6; type++) if (reHtmlBlockOpen[type].test(text)) return true;
3644
+ return false;
3645
+ }
3359
3646
  var reHtmlBlockClose = [
3360
3647
  /^$/,
3361
3648
  /<\/(?:script|pre|textarea|style)>/i,
@@ -4118,6 +4405,29 @@ function htmlSectionEnd(nodes, i) {
4118
4405
  }
4119
4406
  return i;
4120
4407
  }
4408
+ var reDetailsOpen = /^<details(\s+open(?:\s*=\s*(?:""|''|"open"|'open'|open))?)?\s*>\s*<summary>([^<]*)<\/summary>\s*$/i;
4409
+ var reDetailsClose = /^<\/details>\s*$/i;
4410
+ function detailsSections(nodes) {
4411
+ const out = /* @__PURE__ */ new Map();
4412
+ const open = [];
4413
+ nodes.forEach((node, i) => {
4414
+ if (node.type !== "htmlBlock") return;
4415
+ const start = reDetailsOpen.exec(node.value);
4416
+ if (start) {
4417
+ open.push({ index: i, block: details(plain(decodeEntities(start[2].trim())), { open: !!start[1] }) });
4418
+ } else if (reDetailsClose.test(node.value)) {
4419
+ const section = open.pop();
4420
+ if (!section) return;
4421
+ out.set(section.index, section.block);
4422
+ out.set(i, detailsEnd());
4423
+ } else {
4424
+ const tags2 = [];
4425
+ applyTags(node.value, tags2);
4426
+ if (tags2.length > 0) open.length = 0;
4427
+ }
4428
+ });
4429
+ return out;
4430
+ }
4121
4431
  var slotMarker = (index) => `\uE000${index}\uE001`;
4122
4432
  var SLOT_MARKER = /(\d+)/g;
4123
4433
  function splitHtmlSection(source, options = DEFAULT_MARKDOWN) {
@@ -4171,26 +4481,38 @@ function serializeBlocks(blocks, options) {
4171
4481
  let out = "";
4172
4482
  let prev = null;
4173
4483
  const lists = new ListState(ctx.paragraph);
4174
- for (const block3 of blocks) {
4484
+ for (let i = 0; i < blocks.length; i++) {
4485
+ const block3 = blocks[i];
4175
4486
  let text;
4176
4487
  let separator = "\n\n";
4488
+ const kind = quoteKind(block3);
4489
+ if (kind) {
4490
+ let end = i + 1;
4491
+ while (end < blocks.length && sameQuote(block3, blocks[end])) end++;
4492
+ const inner = blocks.slice(i, end).map(unquote);
4493
+ let body = serializeBlocks(inner, options);
4494
+ if (kind !== "quote") body = `[!${kind.toUpperCase()}]
4495
+ ${interrupts(inner[0]) ? "" : "\n"}${body}`;
4496
+ if (out) out += separator;
4497
+ out += prefixLines(body, "> ", ">");
4498
+ prev = blocks[end - 1];
4499
+ i = end - 1;
4500
+ continue;
4501
+ }
4177
4502
  switch (block3.type) {
4178
4503
  case "paragraph":
4179
4504
  text = block3.content.length === 0 ? "&nbsp;" : inlineToMarkdown(block3.content, ctx.paragraph);
4180
4505
  break;
4181
- case "quote": {
4182
- const body = block3.content.length === 0 ? "&nbsp;" : inlineToMarkdown(block3.content, ctx.paragraph);
4183
- text = prefixLines(body, "> ", ">");
4184
- if (prev?.type === "quote") separator = "\n>\n";
4185
- break;
4186
- }
4506
+ case "quote":
4507
+ continue;
4187
4508
  case "heading":
4188
4509
  text = serializeHeading(block3.level, block3.content, ctx.heading);
4189
4510
  break;
4190
4511
  case "listItem": {
4191
- const item = lists.next(block3, prev?.type === "listItem" ? prev : null);
4512
+ const before = prev?.type === "listItem" && !prev.quote ? prev : null;
4513
+ const item = lists.next(block3, before);
4192
4514
  text = item.text;
4193
- if (prev?.type === "listItem" && !item.blankLineBefore) separator = "\n";
4515
+ if (before && !item.blankLineBefore) separator = "\n";
4194
4516
  break;
4195
4517
  }
4196
4518
  case "code":
@@ -4205,6 +4527,15 @@ function serializeBlocks(blocks, options) {
4205
4527
  case "divider":
4206
4528
  text = "---";
4207
4529
  break;
4530
+ case "details": {
4531
+ const title = inlineText(block3.content).replace(/[&<>]/g, (c) => c === "&" ? "&amp;" : c === "<" ? "&lt;" : "&gt;");
4532
+ text = `<details${block3.open ? " open" : ""}>
4533
+ <summary>${title}</summary>`;
4534
+ break;
4535
+ }
4536
+ case "detailsEnd":
4537
+ text = "</details>";
4538
+ break;
4208
4539
  }
4209
4540
  if (out) out += separator;
4210
4541
  out += text;
@@ -4212,6 +4543,11 @@ function serializeBlocks(blocks, options) {
4212
4543
  }
4213
4544
  return out;
4214
4545
  }
4546
+ function interrupts(block3) {
4547
+ if (block3.type !== "listItem") return true;
4548
+ if (block3.listType === "task") return true;
4549
+ return block3.content.length > 0 && (block3.start ?? 1) === 1;
4550
+ }
4215
4551
  function isEmptyParagraph(block3) {
4216
4552
  return block3.type === "paragraph" && block3.content.length === 0;
4217
4553
  }
@@ -4240,7 +4576,7 @@ function serializeCode(language, text) {
4240
4576
  ${text ? text + "\n" : ""}${fence}`;
4241
4577
  }
4242
4578
  function serializeTable(align, rows, ctx) {
4243
- const row = (cells) => "| " + cells.map((cell) => inlineToMarkdown(cell, ctx).replace(/\|/g, "\\|")).join(" | ") + " |";
4579
+ const row = (cells) => "| " + cells.map((cell) => inlineToMarkdown(representableCell(cell), ctx).replace(/\|/g, "\\|")).join(" | ") + " |";
4244
4580
  const delimiter = "| " + align.map((a) => a === "left" ? ":--" : a === "center" ? ":-:" : a === "right" ? "--:" : "---").join(" | ") + " |";
4245
4581
  const [header, ...body] = rows;
4246
4582
  return [row(header ?? align.map(() => [])), delimiter, ...body.map(row)].join("\n");
@@ -4321,6 +4657,25 @@ function sameInline(a, b) {
4321
4657
  });
4322
4658
  }
4323
4659
  var reSpecWhitespace = /^[\t\n\f\r\p{Zs}]+|[\t\n\f\r\p{Zs}]+$/gu;
4660
+ var ODD_BACKSLASH_PIPE = /(?<!\\)(?:\\\\)*\\\|/;
4661
+ function representableCell(inline3) {
4662
+ if (!inline3.some((s) => s.marks.includes("code") && ODD_BACKSLASH_PIPE.test(s.text))) return inline3;
4663
+ return normalizeInline(
4664
+ inline3.flatMap((s) => {
4665
+ if (!s.marks.includes("code")) return [s];
4666
+ const marks = s.marks.filter((m) => m !== "code");
4667
+ const out = [];
4668
+ let from = 0;
4669
+ for (const m of s.text.matchAll(new RegExp(ODD_BACKSLASH_PIPE, "g"))) {
4670
+ const pipe = m.index + m[0].length - 1;
4671
+ out.push({ ...s, text: s.text.slice(from, pipe) }, { ...s, text: "|", marks });
4672
+ from = pipe + 1;
4673
+ }
4674
+ out.push({ ...s, text: s.text.slice(from) });
4675
+ return out.filter((span) => span.text !== "");
4676
+ })
4677
+ );
4678
+ }
4324
4679
  function representableInline(inline3) {
4325
4680
  let spans = normalizeInline(
4326
4681
  inline3.flatMap((s) => {
@@ -4526,8 +4881,10 @@ function render(spans, ctx, strategy, bare = false) {
4526
4881
  let out = "";
4527
4882
  tokens.forEach((tok, i) => {
4528
4883
  if (tok.kind === "delim") out += tok.ch.repeat(tok.count);
4529
- else if (tok.kind === "raw") out += tok.text;
4530
- else {
4884
+ else if (tok.kind === "raw") {
4885
+ if (ctx.lineStart && out.endsWith("\n") && interruptsParagraph(tok.text)) out += " ";
4886
+ out += tok.text;
4887
+ } else {
4531
4888
  out += escapeText(tok, ctx, {
4532
4889
  before: out ? out[out.length - 1] : void 0,
4533
4890
  after: edgeChar(tokens[i + 1], "first"),
@@ -4720,14 +5077,16 @@ function loadMarkdown(text, options) {
4720
5077
  const groups = [];
4721
5078
  const groupOf = /* @__PURE__ */ new WeakMap();
4722
5079
  let lastEnd = 0;
5080
+ const sections2 = (options ?? DEFAULT_MARKDOWN).details === false ? null : detailsSections(root.children);
4723
5081
  for (let i = 0; i < root.children.length; i++) {
4724
5082
  const node = root.children[i];
4725
- const last = htmlSectionEnd(root.children, i);
5083
+ const section = sections2?.get(i);
5084
+ const last = section ? i : htmlSectionEnd(root.children, i);
4726
5085
  const from = lineStarts[root.lines[i].start - 1] ?? text.length;
4727
5086
  const lines = root.lines[last];
4728
5087
  const to = lineEnds[Math.max(lines.start, lines.end) - 1] ?? text.length;
4729
5088
  const source = text.slice(from, to);
4730
- const lowered = last > i ? [htmlBlock(source)] : lowerTopLevel(node, options ?? DEFAULT_MARKDOWN, source);
5089
+ const lowered = section ? [section] : last > i ? [htmlBlock(source)] : lowerTopLevel(node, options ?? DEFAULT_MARKDOWN, source);
4731
5090
  i = last;
4732
5091
  blocks.push(...lowered);
4733
5092
  if (lowered.length === 0 || from < lastEnd || to < from) continue;
@@ -4743,7 +5102,8 @@ function isOpen(source, options) {
4743
5102
  return parseAst(source + "\n\nx", options).children.length < 2;
4744
5103
  }
4745
5104
  function joins(a, b) {
4746
- return !!a && !!b && a.type === b.type && (a.type === "listItem" || a.type === "quote");
5105
+ if (quoteKind(a) !== null || quoteKind(b) !== null) return sameQuote(a, b);
5106
+ return a?.type === "listItem" && b?.type === "listItem";
4747
5107
  }
4748
5108
  function saveWithSource(blocks, source, options) {
4749
5109
  const text = source.text;
@@ -4839,7 +5199,7 @@ function saveWithSource(blocks, source, options) {
4839
5199
  }
4840
5200
  return out + ending;
4841
5201
  }
4842
- var reTaskLine = /^([ \t]*(?:[-+*]|\d{1,9}[.)])[ \t]+\[)([ xX])(?=\][ \t]|\]$)/gm;
5202
+ var reTaskLine = /^((?:[ \t]*>)*[ \t]*(?:[-+*]|\d{1,9}[.)])[ \t]+\[)([ xX])(?=\][ \t]|\]$)/gm;
4843
5203
  function tickedGroup(blocks, i, firstBlocks, source, options) {
4844
5204
  const loaded = firstBlocks.get(blocks[i].id);
4845
5205
  if (!loaded || loaded.open) return null;
@@ -5274,10 +5634,12 @@ function defaultKeymap() {
5274
5634
  "Mod-Alt-1": ({ editor }) => editor.commands.toggleHeading({ level: 1 }) || true,
5275
5635
  "Mod-Alt-2": ({ editor }) => editor.commands.toggleHeading({ level: 2 }) || true,
5276
5636
  "Mod-Alt-3": ({ editor }) => editor.commands.toggleHeading({ level: 3 }) || true,
5637
+ "Mod-Alt-4": ({ editor }) => editor.commands.toggleHeading({ level: 4 }) || true,
5277
5638
  "Mod-Alt-c": ({ editor }) => editor.commands.toggleCodeBlock() || true,
5278
5639
  "Mod-Shift-7": ({ editor }) => editor.commands.toggleOrderedList() || true,
5279
5640
  "Mod-Shift-8": ({ editor }) => editor.commands.toggleBulletList() || true,
5280
5641
  "Mod-Shift-9": ({ editor }) => editor.commands.toggleTaskList() || true,
5642
+ "Mod-Shift-6": ({ editor }) => editor.commands.toggleDetails() || true,
5281
5643
  "Mod-a": ({ editor }) => selectAll2(editor),
5282
5644
  "Mod-z": ({ editor }) => editor.commands.undo() || true,
5283
5645
  "Mod-Shift-z": ({ editor }) => editor.commands.redo() || true,
@@ -5989,7 +6351,8 @@ var TEXT_STYLES = [
5989
6351
  { id: "text", spec: { type: "paragraph" }, keys: mod("Alt+0") },
5990
6352
  { id: "heading1", spec: { type: "heading", level: 1 }, keys: mod("Alt+1") },
5991
6353
  { id: "heading2", spec: { type: "heading", level: 2 }, keys: mod("Alt+2") },
5992
- { id: "heading3", spec: { type: "heading", level: 3 }, keys: mod("Alt+3") }
6354
+ { id: "heading3", spec: { type: "heading", level: 3 }, keys: mod("Alt+3") },
6355
+ { id: "heading4", spec: { type: "heading", level: 4 }, keys: mod("Alt+4") }
5993
6356
  ];
5994
6357
  var LIST_TYPES = [
5995
6358
  { id: "bulletList", listType: "bullet", keys: mod("Shift+8") },
@@ -6000,7 +6363,7 @@ var TOOLTIP_DELAY = 500;
6000
6363
  var TOOLTIP_GRACE = 300;
6001
6364
  function blockState(editor) {
6002
6365
  const blocks = convertibleBlocks(editor.state);
6003
- const styleOf2 = (b) => b.type === "paragraph" ? "text" : b.type === "heading" && b.level <= 3 ? `heading${b.level}` : null;
6366
+ const styleOf2 = (b) => b.type === "paragraph" ? "text" : b.type === "heading" && b.level <= 4 ? `heading${b.level}` : null;
6004
6367
  const every = (f) => {
6005
6368
  const first = blocks[0] ? f(blocks[0]) : null;
6006
6369
  return blocks.every((b) => f(b) === first) ? first : null;
@@ -6011,7 +6374,7 @@ function blockState(editor) {
6011
6374
  allHeadings: some && blocks.every((b) => b.type === "heading"),
6012
6375
  listType: every((b) => b.type === "listItem" ? b.listType : null),
6013
6376
  allListItems: some && blocks.every((b) => b.type === "listItem"),
6014
- allQuotes: some && blocks.every((b) => b.type === "quote")
6377
+ allQuotes: some && blocks.every((b) => quoteKind(b) !== null)
6015
6378
  };
6016
6379
  }
6017
6380
  var FormatToolbar = class {
@@ -6340,6 +6703,10 @@ var FILL_ATTR = "data-mbe-fill";
6340
6703
  var ATOM_ATTR = "data-atom";
6341
6704
  var LIST_START_ATTR = "data-list-start";
6342
6705
  var QUOTE_JOINED_ATTR = "data-quote-joined";
6706
+ var QUOTE_CONTINUED_ATTR = "data-quote-continued";
6707
+ var SECTION_HIDDEN_ATTR = "data-section-hidden";
6708
+ var SECTION_COLLAPSED_ATTR = "data-collapsed";
6709
+ var SECTION_INSIDE_ATTR = "data-in-section";
6343
6710
  var MARK_TAGS = {
6344
6711
  bold: ["strong"],
6345
6712
  italic: ["em"],
@@ -6360,7 +6727,7 @@ function blockClasses(block3, theme) {
6360
6727
  case "quote":
6361
6728
  return theme.blockquote;
6362
6729
  case "listItem":
6363
- return theme[`${block3.listType}List`];
6730
+ return block3.quote ? classes(theme[`${block3.listType}List`], theme.blockquote) || void 0 : theme[`${block3.listType}List`];
6364
6731
  case "code":
6365
6732
  return theme.codeBlock;
6366
6733
  case "table":
@@ -6369,6 +6736,11 @@ function blockClasses(block3, theme) {
6369
6736
  return theme.raw;
6370
6737
  case "divider":
6371
6738
  return void 0;
6739
+ // on the <hr>
6740
+ case "details":
6741
+ return theme.details;
6742
+ case "detailsEnd":
6743
+ return void 0;
6372
6744
  }
6373
6745
  }
6374
6746
  var defaultResolveUrl = (url) => {
@@ -6387,6 +6759,9 @@ function sameReveal(a, b) {
6387
6759
  for (const key of a) if (!b.has(key)) return false;
6388
6760
  return true;
6389
6761
  }
6762
+ function calloutName(type) {
6763
+ return `callout${type[0].toUpperCase()}${type.slice(1)}`;
6764
+ }
6390
6765
  function markImageBlock(el, block3) {
6391
6766
  const offset = imageBlockOffset(block3);
6392
6767
  if (offset === null) return;
@@ -6394,6 +6769,28 @@ function markImageBlock(el, block3) {
6394
6769
  const align = sliceInline(block3.content, offset, offset + 1)[0]?.image?.align;
6395
6770
  if (align) el.dataset.align = align;
6396
6771
  }
6772
+ function renderCallout(block3, type, ctx, reveal) {
6773
+ const doc = ctx.doc;
6774
+ const root = doc.createElement("blockquote");
6775
+ root.dir = "auto";
6776
+ root.dataset.callout = type;
6777
+ const content = doc.createElement("div");
6778
+ content.className = "mbe-content";
6779
+ fillContent(content, block3.content, ctx, block3, reveal);
6780
+ root.append(calloutIcon(type, ctx), content);
6781
+ return root;
6782
+ }
6783
+ function calloutIcon(type, ctx) {
6784
+ const name = calloutName(type);
6785
+ const icon = ctx.doc.createElement("div");
6786
+ icon.className = "mbe-callout-icon";
6787
+ icon.contentEditable = "false";
6788
+ icon.setAttribute("role", "img");
6789
+ icon.setAttribute("aria-label", ctx.labels[name]);
6790
+ const glyph = ctx.icon?.(name);
6791
+ if (glyph) icon.appendChild(glyph);
6792
+ return icon;
6793
+ }
6397
6794
  function renderBlock(block3, ctx, reveal) {
6398
6795
  const { doc, labels } = ctx;
6399
6796
  const el = (tag, className2) => {
@@ -6406,13 +6803,21 @@ function renderBlock(block3, ctx, reveal) {
6406
6803
  case "paragraph":
6407
6804
  case "heading":
6408
6805
  case "quote":
6806
+ if (block3.type === "quote" && block3.callout) {
6807
+ root = renderCallout(block3, block3.callout, ctx, reveal);
6808
+ break;
6809
+ }
6409
6810
  root = el(block3.type === "paragraph" ? "p" : block3.type === "quote" ? "blockquote" : `h${block3.level}`);
6410
6811
  root.dir = "auto";
6411
6812
  fillContent(root, block3.content, ctx, block3, reveal);
6412
6813
  if (block3.type === "paragraph") markImageBlock(root, block3);
6413
6814
  break;
6414
6815
  case "listItem": {
6415
- root = el("div");
6816
+ root = el(block3.quote ? "blockquote" : "div");
6817
+ if (block3.callout) {
6818
+ root.dataset.callout = block3.callout;
6819
+ root.appendChild(calloutIcon(block3.callout, ctx));
6820
+ }
6416
6821
  root.dir = "auto";
6417
6822
  root.dataset.listType = block3.listType;
6418
6823
  root.dataset.indent = String(block3.indent);
@@ -6461,7 +6866,8 @@ function renderBlock(block3, ctx, reveal) {
6461
6866
  case "raw": {
6462
6867
  const source = inlineText(block3.content);
6463
6868
  const section = block3.syntax === "html" && !reveal?.has(REVEAL_BLOCK) && ctx.views?.has("html") ? splitHtmlSection(source, ctx.markdown) : null;
6464
- const view = reveal?.has(REVEAL_BLOCK) ? null : ctx.view?.(block3.syntax, section ? section.html : source, "block");
6869
+ const nested = block3.syntax === "markdown" && !reveal?.has(REVEAL_BLOCK) && ctx.views?.get("markdown") === MARKDOWN_VIEW;
6870
+ const view = reveal?.has(REVEAL_BLOCK) ? null : nested ? renderMarkdown(source, ctx) : ctx.view?.(block3.syntax, section ? section.html : source, "block");
6465
6871
  if (view) {
6466
6872
  root = view;
6467
6873
  root.classList.add("mbe-view-block");
@@ -6481,6 +6887,26 @@ function renderBlock(block3, ctx, reveal) {
6481
6887
  root.contentEditable = "false";
6482
6888
  root.appendChild(el("hr", ctx.classes.divider));
6483
6889
  break;
6890
+ case "details": {
6891
+ root = el("div");
6892
+ root.dir = "auto";
6893
+ const marker = el("span", "mbe-details-marker");
6894
+ marker.contentEditable = "false";
6895
+ const toggle = el("button", "mbe-details-toggle");
6896
+ toggle.type = "button";
6897
+ toggle.tabIndex = -1;
6898
+ const icon = ctx.icon?.("chevronRight");
6899
+ if (icon) toggle.appendChild(icon);
6900
+ marker.appendChild(toggle);
6901
+ const content = el("div", "mbe-content");
6902
+ fillContent(content, block3.content, ctx, block3, void 0, void 0, false);
6903
+ root.append(marker, content);
6904
+ break;
6905
+ }
6906
+ case "detailsEnd":
6907
+ root = el("div");
6908
+ root.contentEditable = "false";
6909
+ break;
6484
6910
  case "table": {
6485
6911
  root = el("div");
6486
6912
  root.contentEditable = "false";
@@ -6507,7 +6933,8 @@ function renderBlock(block3, ctx, reveal) {
6507
6933
  }
6508
6934
  }
6509
6935
  root.setAttribute(BLOCK_ATTR, block3.id);
6510
- let className = `${root.className ? root.className + " " : ""}mbe-block mbe-${block3.type === "listItem" ? "list-item" : block3.type}`;
6936
+ const name = block3.type === "listItem" ? "list-item" : block3.type === "detailsEnd" ? "details-end" : block3.type;
6937
+ let className = `${root.className ? root.className + " " : ""}mbe-block mbe-${name}`;
6511
6938
  if (block3.type === "listItem" && block3.checked) className += " mbe-checked";
6512
6939
  if ("content" in block3 && inlineLength(block3.content) === 0) className += " mbe-empty";
6513
6940
  const themed = blockClasses(block3, ctx.classes);
@@ -6578,13 +7005,85 @@ function fillSlots(root, count, content, doc) {
6578
7005
  function renderFlow(blocks, ctx) {
6579
7006
  const flow = ctx.doc.createElement("div");
6580
7007
  flow.className = "mbe-flow";
7008
+ appendBlocks(flow, blocks, ctx);
7009
+ makeInert(flow);
7010
+ return flow;
7011
+ }
7012
+ function appendBlocks(flow, blocks, ctx) {
6581
7013
  const elements = /* @__PURE__ */ new Map();
6582
7014
  for (const block3 of blocks) {
6583
7015
  const el = renderBlock(block3, ctx);
6584
7016
  elements.set(block3.id, el);
6585
7017
  flow.appendChild(el);
6586
7018
  }
6587
- updateNeighborMarks({ blocks }, (id) => elements.get(id), /* @__PURE__ */ new WeakMap());
7019
+ updateNeighborMarks({ blocks }, (id) => elements.get(id), /* @__PURE__ */ new WeakMap(), /* @__PURE__ */ new Set(), ctx.labels);
7020
+ }
7021
+ var MARKDOWN_VIEW = () => false;
7022
+ function renderMarkdown(source, ctx) {
7023
+ const root = ctx.doc.createElement("div");
7024
+ root.classList.add("mbe-view-markdown");
7025
+ root.appendChild(renderNodes(parseAst(source, ctx.markdown).children, ctx));
7026
+ makeInert(root);
7027
+ return root;
7028
+ }
7029
+ function renderNodes(nodes, ctx) {
7030
+ const options = ctx.markdown ?? DEFAULT_MARKDOWN;
7031
+ const flow = ctx.doc.createElement("div");
7032
+ flow.className = "mbe-flow";
7033
+ let run = [];
7034
+ for (const node of nodes) {
7035
+ const blocks = lowerIfFits(node, options);
7036
+ if (blocks) {
7037
+ run.push(...blocks);
7038
+ continue;
7039
+ }
7040
+ appendBlocks(flow, run, ctx);
7041
+ run = [];
7042
+ if (node.type === "blockQuote") flow.appendChild(renderQuoteNode(node, ctx));
7043
+ else if (node.type === "list") node.items.forEach((item, i) => flow.appendChild(renderItemNode(node, item, i, ctx)));
7044
+ }
7045
+ appendBlocks(flow, run, ctx);
7046
+ return flow;
7047
+ }
7048
+ function renderQuoteNode(node, ctx) {
7049
+ const alert = ctx.markdown?.callouts === false ? null : calloutOf2(node.children);
7050
+ const children = alert ? [...alert.rest.length > 0 ? [{ type: "paragraph", children: [...alert.rest] }] : [], ...node.children.slice(1)] : node.children;
7051
+ const el = ctx.doc.createElement("blockquote");
7052
+ el.dir = "auto";
7053
+ el.className = classes("mbe-block mbe-quote", ctx.classes.blockquote);
7054
+ if (alert) {
7055
+ el.dataset.callout = alert.type;
7056
+ el.appendChild(calloutIcon(alert.type, ctx));
7057
+ }
7058
+ el.appendChild(renderNodes(children, ctx));
7059
+ return el;
7060
+ }
7061
+ function renderItemNode(list, node, index, ctx) {
7062
+ const listType = node.task ? "task" : list.ordered ? "ordered" : "bullet";
7063
+ const el = ctx.doc.createElement("div");
7064
+ el.dir = "auto";
7065
+ el.className = classes("mbe-block mbe-list-item", ctx.classes[`${listType}List`]);
7066
+ el.dataset.listType = listType;
7067
+ el.dataset.indent = "0";
7068
+ if (index === 0) el.setAttribute(LIST_START_ATTR, "");
7069
+ const marker = ctx.doc.createElement("span");
7070
+ marker.className = "mbe-marker";
7071
+ if (node.task) {
7072
+ const box = ctx.doc.createElement("input");
7073
+ box.className = "mbe-checkbox";
7074
+ box.type = "checkbox";
7075
+ box.checked = node.checked;
7076
+ marker.appendChild(box);
7077
+ } else if (list.ordered) {
7078
+ marker.textContent = `${list.start + index}.`;
7079
+ }
7080
+ const content = ctx.doc.createElement("div");
7081
+ content.className = "mbe-content";
7082
+ content.appendChild(renderNodes(node.children, ctx));
7083
+ el.append(marker, content);
7084
+ return el;
7085
+ }
7086
+ function makeInert(flow) {
6588
7087
  for (const el of Array.from(flow.querySelectorAll(`[${BLOCK_ATTR}], [${CONTENT_ATTR}], [contenteditable], [data-row]`))) {
6589
7088
  el.removeAttribute(BLOCK_ATTR);
6590
7089
  el.removeAttribute(CONTENT_ATTR);
@@ -6597,7 +7096,6 @@ function renderFlow(blocks, ctx) {
6597
7096
  else input.readOnly = true;
6598
7097
  input.tabIndex = -1;
6599
7098
  }
6600
- return flow;
6601
7099
  }
6602
7100
  function fill(doc) {
6603
7101
  const br = doc.createElement("br");
@@ -6835,6 +7333,8 @@ var BlockRenderer = class {
6835
7333
  codeCopy = false;
6836
7334
  /** An image failed to load and now shows as unavailable. */
6837
7335
  onImageError;
7336
+ /** Collapsible sections shown collapsed, by the ID of their title block. */
7337
+ collapsed = /* @__PURE__ */ new Set();
6838
7338
  /** Per block, the views that show their source. A block re-renders when its entry changes. */
6839
7339
  revealed = /* @__PURE__ */ new Map();
6840
7340
  /**
@@ -6980,7 +7480,11 @@ var BlockRenderer = class {
6980
7480
  }
6981
7481
  }
6982
7482
  this.rendered = next;
6983
- updateNeighborMarks(doc, (id) => next.get(id)?.el, this.numbers);
7483
+ updateNeighborMarks(doc, (id) => next.get(id)?.el, this.numbers, this.collapsed, this.labels);
7484
+ }
7485
+ /** Marks blocks again after `collapsed` changed, without rendering any. */
7486
+ updateSections(doc) {
7487
+ updateNeighborMarks(doc, (id) => this.rendered.get(id)?.el, this.numbers, this.collapsed, this.labels);
6984
7488
  }
6985
7489
  elementFor(id) {
6986
7490
  return this.rendered.get(id)?.el;
@@ -7001,18 +7505,44 @@ var BlockRenderer = class {
7001
7505
  this.rendered.delete(id);
7002
7506
  }
7003
7507
  };
7004
- function updateNeighborMarks(doc, elementFor, written) {
7508
+ function markSection(el, depth, hidden, collapsed, labels) {
7509
+ const value = depth > 0 ? String(depth) : "";
7510
+ if (el.style.getPropertyValue("--mbe-section-depth") !== value) {
7511
+ if (value) el.style.setProperty("--mbe-section-depth", value);
7512
+ else el.style.removeProperty("--mbe-section-depth");
7513
+ }
7514
+ setFlag(el, SECTION_INSIDE_ATTR, depth > 0);
7515
+ setFlag(el, SECTION_HIDDEN_ATTR, hidden);
7516
+ if (collapsed === null) return;
7517
+ setFlag(el, SECTION_COLLAPSED_ATTR, collapsed);
7518
+ const toggle = el.querySelector(".mbe-details-toggle");
7519
+ const expanded = String(!collapsed);
7520
+ if (toggle && toggle.getAttribute("aria-expanded") !== expanded) {
7521
+ toggle.setAttribute("aria-expanded", expanded);
7522
+ toggle.setAttribute("aria-label", collapsed ? labels.expandSection : labels.collapseSection);
7523
+ }
7524
+ }
7525
+ function updateNeighborMarks(doc, elementFor, written, collapsed, labels) {
7005
7526
  const counters = [];
7527
+ const sections2 = [];
7006
7528
  doc.blocks.forEach((block3, i) => {
7007
7529
  const before = doc.blocks[i - 1];
7008
7530
  const el = elementFor(block3.id);
7009
- if (block3.type === "quote") setFlag(el, QUOTE_JOINED_ATTR, before?.type === "quote");
7010
- if (block3.type !== "listItem") {
7011
- counters.length = 0;
7012
- return;
7013
- }
7531
+ if (block3.type === "detailsEnd") sections2.pop();
7532
+ if (el) markSection(el, sections2.length, sections2.includes(true), block3.type === "details" ? collapsed.has(block3.id) : null, labels);
7533
+ if (block3.type === "details") sections2.push(collapsed.has(block3.id));
7534
+ if (quoteKind(block3) !== null) {
7535
+ setFlag(el, QUOTE_JOINED_ATTR, sameQuote(before, block3));
7536
+ setFlag(el, QUOTE_CONTINUED_ATTR, sameQuote(block3, doc.blocks[i + 1]));
7537
+ }
7538
+ if (block3.type !== "listItem" || before?.type !== "listItem" || quoteKind(before) !== quoteKind(block3)) counters.length = 0;
7539
+ if (block3.type !== "listItem") return;
7014
7540
  const ordered = block3.listType === "ordered";
7015
- setFlag(el, LIST_START_ATTR, before?.type !== "listItem" || block3.indent === 0 && ordered !== (before.listType === "ordered"));
7541
+ setFlag(
7542
+ el,
7543
+ LIST_START_ATTR,
7544
+ counters.length === 0 || block3.indent === 0 && before?.type === "listItem" && ordered !== (before.listType === "ordered")
7545
+ );
7016
7546
  counters.length = block3.indent + 1;
7017
7547
  if (!ordered) {
7018
7548
  counters[block3.indent] = void 0;
@@ -7031,8 +7561,8 @@ function keepDetailsOpen(from, to) {
7031
7561
  if (before.length === 0) return;
7032
7562
  const after = to.querySelectorAll("details");
7033
7563
  if (after.length !== before.length) return;
7034
- before.forEach((details, i) => {
7035
- after[i].open = details.open;
7564
+ before.forEach((details2, i) => {
7565
+ after[i].open = details2.open;
7036
7566
  });
7037
7567
  }
7038
7568
  function setFlag(el, attr, on) {
@@ -7203,8 +7733,8 @@ var BlockHandle = class {
7203
7733
  let node = target;
7204
7734
  while (node && node.parentElement !== this.editor.root) node = node.parentElement;
7205
7735
  if (!node || !node.hasAttribute(BLOCK_ATTR)) return;
7206
- const blockId = node.getAttribute(BLOCK_ATTR);
7207
- if (this.editor.hasBlockMenu(blockId)) this.showFor(blockId);
7736
+ const owner = this.editor.blockMenuOwner(node.getAttribute(BLOCK_ATTR));
7737
+ if (owner) this.showFor(owner);
7208
7738
  else if (this.blockId !== null) this.scheduleHide();
7209
7739
  }
7210
7740
  /** Shows the block handle next to a block. */
@@ -7217,11 +7747,13 @@ var BlockHandle = class {
7217
7747
  this.el.hidden = false;
7218
7748
  const offset = attach(this.el, this.editor.root);
7219
7749
  const rect = blockEl.getBoundingClientRect();
7750
+ const icon = blockEl.querySelector(":scope > .mbe-callout-icon");
7751
+ const iconRect = icon?.getBoundingClientRect();
7220
7752
  const lineHeight = parseFloat(doc.defaultView.getComputedStyle(blockEl).lineHeight) || 24;
7221
- const firstLine = Math.min(rect.height, lineHeight);
7753
+ const middle = iconRect?.height ? iconRect.top + iconRect.height / 2 : rect.top + Math.min(rect.height, lineHeight) / 2;
7222
7754
  const size = this.el.offsetHeight || 22;
7223
7755
  this.el.style.left = `${Math.round(rect.left - (this.el.offsetWidth || 20) - 6 - offset.x)}px`;
7224
- this.el.style.top = `${Math.round(rect.top + firstLine / 2 - size / 2 - offset.y)}px`;
7756
+ this.el.style.top = `${Math.round(middle - size / 2 - offset.y)}px`;
7225
7757
  }
7226
7758
  /** True when `node` is the block handle or inside it. */
7227
7759
  contains(node) {
@@ -7247,6 +7779,199 @@ var BlockHandle = class {
7247
7779
  }
7248
7780
  };
7249
7781
 
7782
+ // src/ui/linkCard.ts
7783
+ var HOVER_DELAY = 300;
7784
+ var LEAVE_DELAY = 250;
7785
+ var LinkCard = class {
7786
+ constructor(editor, actions) {
7787
+ this.editor = editor;
7788
+ this.actions = actions;
7789
+ const doc = editor.root.ownerDocument;
7790
+ const labels = editor.labels;
7791
+ this.popup = new Popup(editor.root, "mbe-link-card");
7792
+ const el = this.popup.el;
7793
+ el.setAttribute("role", "toolbar");
7794
+ el.setAttribute("aria-label", labels.link);
7795
+ this.url = doc.createElement("a");
7796
+ this.url.className = "mbe-link-card-url";
7797
+ this.url.target = "_blank";
7798
+ this.url.rel = "noopener noreferrer";
7799
+ this.url.addEventListener("click", (e) => {
7800
+ e.preventDefault();
7801
+ if (this.target) actions.open(this.target, e);
7802
+ });
7803
+ const button = (name, onClick) => {
7804
+ const b = doc.createElement("button");
7805
+ b.type = "button";
7806
+ b.className = `mbe-tool mbe-link-card-${name}`;
7807
+ setIcon(b, editor, name);
7808
+ b.setAttribute("aria-label", labels[name]);
7809
+ b.title = labels[name];
7810
+ b.addEventListener("click", (e) => {
7811
+ if (this.target) onClick(e);
7812
+ });
7813
+ return b;
7814
+ };
7815
+ const open = button("openLink", (e) => actions.open(this.target, e));
7816
+ this.copyButton = button("copyLink", () => this.copy());
7817
+ const edit = button("editLink", () => {
7818
+ const target = this.target;
7819
+ this.hide();
7820
+ actions.edit(target);
7821
+ });
7822
+ const remove = button("removeLink", () => {
7823
+ const target = this.target;
7824
+ this.hide();
7825
+ actions.remove(target);
7826
+ });
7827
+ const sep = doc.createElement("span");
7828
+ sep.className = "mbe-tool-sep";
7829
+ el.append(this.url, sep, open, this.copyButton, edit, remove);
7830
+ const root = editor.root;
7831
+ const on = (target, type, fn) => {
7832
+ target.addEventListener(type, fn);
7833
+ this.cleanup.push(() => target.removeEventListener(type, fn));
7834
+ };
7835
+ on(root, "mouseover", (e) => this.onOver(e));
7836
+ on(root, "mouseout", (e) => this.onOut(e));
7837
+ on(el, "mouseenter", () => this.cancelHide());
7838
+ on(el, "mouseleave", () => {
7839
+ if (this.hovered) this.scheduleHide();
7840
+ });
7841
+ }
7842
+ popup;
7843
+ url;
7844
+ copyButton;
7845
+ target = null;
7846
+ /** What shows the card: the pointer on a link, or the caret in one. The pointer wins. */
7847
+ hovered = null;
7848
+ caret = null;
7849
+ showTimer = null;
7850
+ hideTimer = null;
7851
+ copiedTimer = null;
7852
+ cleanup = [];
7853
+ get isOpen() {
7854
+ return this.popup.isOpen;
7855
+ }
7856
+ contains(node) {
7857
+ return this.popup.el.contains(node);
7858
+ }
7859
+ /** Sets the link with the caret (null for none) and shows or hides the card to match. */
7860
+ setCaret(target) {
7861
+ this.caret = target;
7862
+ if (this.hovered && !this.hovered.el.isConnected) this.hovered = null;
7863
+ this.render();
7864
+ }
7865
+ /** Places the card under its link again, after scrolling or a layout change. */
7866
+ reposition() {
7867
+ if (!this.target) return;
7868
+ if (!this.target.el.isConnected) return this.hide();
7869
+ this.place(this.target);
7870
+ }
7871
+ hide() {
7872
+ this.clearTimers();
7873
+ this.hovered = null;
7874
+ this.caret = null;
7875
+ this.target = null;
7876
+ this.popup.hide();
7877
+ }
7878
+ destroy() {
7879
+ this.clearTimers();
7880
+ if (this.copiedTimer !== null) clearTimeout(this.copiedTimer);
7881
+ for (const fn of this.cleanup) fn();
7882
+ this.popup.destroy();
7883
+ }
7884
+ onOver(e) {
7885
+ if (!this.editor.isEditable || e.buttons !== 0) return;
7886
+ const el = e.target?.closest?.("a.mbe-link");
7887
+ if (!el || !this.editor.root.contains(el)) return;
7888
+ this.cancelHide();
7889
+ if (this.hovered?.el === el) return;
7890
+ if (this.showTimer !== null) clearTimeout(this.showTimer);
7891
+ this.showTimer = setTimeout(() => {
7892
+ this.showTimer = null;
7893
+ const target = this.actions.targetOf(el);
7894
+ if (!target || !this.editor.isEditable) return;
7895
+ this.hovered = target;
7896
+ this.render();
7897
+ }, this.popup.isOpen ? 0 : HOVER_DELAY);
7898
+ }
7899
+ onOut(e) {
7900
+ const el = e.target?.closest?.("a.mbe-link");
7901
+ if (!el) return;
7902
+ const next = e.relatedTarget;
7903
+ if (next && (el.contains(next) || this.popup.el.contains(next))) return;
7904
+ if (this.showTimer !== null) {
7905
+ clearTimeout(this.showTimer);
7906
+ this.showTimer = null;
7907
+ }
7908
+ if (this.hovered) this.scheduleHide();
7909
+ }
7910
+ render() {
7911
+ const target = this.hovered ?? this.caret;
7912
+ if (!target) {
7913
+ this.target = null;
7914
+ this.popup.hide();
7915
+ return;
7916
+ }
7917
+ if (this.target?.el !== target.el || this.target.href !== target.href) {
7918
+ this.target = target;
7919
+ this.url.textContent = target.href;
7920
+ this.url.title = target.href;
7921
+ const resolved2 = target.el.getAttribute("href");
7922
+ if (resolved2) this.url.href = resolved2;
7923
+ else this.url.removeAttribute("href");
7924
+ const open = this.popup.el.querySelector(".mbe-link-card-openLink");
7925
+ if (open) open.disabled = !resolved2;
7926
+ this.showCopied(false);
7927
+ }
7928
+ this.place(target);
7929
+ }
7930
+ place(target) {
7931
+ const rects = target.el.getClientRects();
7932
+ const rect = rects.length > 0 ? rects[rects.length - 1] : target.el.getBoundingClientRect();
7933
+ this.popup.show(rect, "below", 4);
7934
+ }
7935
+ copy() {
7936
+ const href = this.target.href;
7937
+ const done = () => this.showCopied(true);
7938
+ const clipboard = this.editor.root.ownerDocument.defaultView?.navigator.clipboard;
7939
+ if (clipboard) clipboard.writeText(href).then(done, () => {
7940
+ });
7941
+ }
7942
+ showCopied(copied) {
7943
+ if (this.copiedTimer !== null) clearTimeout(this.copiedTimer);
7944
+ this.copiedTimer = null;
7945
+ const b = this.copyButton;
7946
+ const name = copied ? "copied" : "copyLink";
7947
+ setIcon(b, this.editor, name);
7948
+ b.setAttribute("aria-label", this.editor.labels[name]);
7949
+ b.title = this.editor.labels[name];
7950
+ if (copied) this.copiedTimer = setTimeout(() => this.showCopied(false), 1500);
7951
+ }
7952
+ scheduleHide() {
7953
+ this.cancelHide();
7954
+ this.hideTimer = setTimeout(() => {
7955
+ this.hideTimer = null;
7956
+ this.hovered = null;
7957
+ this.render();
7958
+ }, LEAVE_DELAY);
7959
+ }
7960
+ cancelHide() {
7961
+ if (this.hideTimer !== null) clearTimeout(this.hideTimer);
7962
+ this.hideTimer = null;
7963
+ }
7964
+ clearTimers() {
7965
+ this.cancelHide();
7966
+ if (this.showTimer !== null) clearTimeout(this.showTimer);
7967
+ this.showTimer = null;
7968
+ }
7969
+ };
7970
+ function setIcon(button, editor, name) {
7971
+ const icon = iconNode(button.ownerDocument, editor.icon(name));
7972
+ button.replaceChildren(...icon ? [icon] : []);
7973
+ }
7974
+
7250
7975
  // src/ui/resizeHandles.ts
7251
7976
  var MIN_WIDTH = 24;
7252
7977
  var SNAP = 8;
@@ -7461,7 +8186,7 @@ function sameRevealed(a, b) {
7461
8186
  }
7462
8187
  function viewEntry(block3, forward) {
7463
8188
  const text = inlineText(block3.content);
7464
- if (block3.type === "code") return { blockId: block3.id, offset: forward ? 0 : text.length };
8189
+ if (block3.type === "code" || block3.syntax === "markdown") return { blockId: block3.id, offset: forward ? 0 : text.length };
7465
8190
  if (forward) {
7466
8191
  const firstBreak = text.indexOf("\n");
7467
8192
  return { blockId: block3.id, offset: firstBreak >= 0 && firstBreak < text.length - 1 ? firstBreak + 1 : 0 };
@@ -7533,7 +8258,12 @@ var COLOR_VARS = {
7533
8258
  popupBackground: "--mbe-popup-bg",
7534
8259
  popupBorder: "--mbe-popup-border",
7535
8260
  hover: "--mbe-hover",
7536
- danger: "--mbe-danger"
8261
+ danger: "--mbe-danger",
8262
+ calloutNote: "--mbe-callout-note",
8263
+ calloutTip: "--mbe-callout-tip",
8264
+ calloutImportant: "--mbe-callout-important",
8265
+ calloutWarning: "--mbe-callout-warning",
8266
+ calloutCaution: "--mbe-callout-caution"
7537
8267
  };
7538
8268
  var SIZE_VARS = {
7539
8269
  font: "--mbe-font",
@@ -7565,10 +8295,13 @@ var SLASH_ITEM_IDS = [
7565
8295
  "heading1",
7566
8296
  "heading2",
7567
8297
  "heading3",
8298
+ "heading4",
7568
8299
  "bulletList",
7569
8300
  "numberedList",
7570
8301
  "todoList",
7571
8302
  "quote",
8303
+ "callout",
8304
+ "details",
7572
8305
  "code",
7573
8306
  "table",
7574
8307
  "divider"
@@ -7578,10 +8311,13 @@ var BLOCK_ITEMS2 = [
7578
8311
  { id: "heading1", aliases: ["h1", "title"], spec: { type: "heading", level: 1 } },
7579
8312
  { id: "heading2", aliases: ["h2", "subtitle"], spec: { type: "heading", level: 2 } },
7580
8313
  { id: "heading3", aliases: ["h3"], spec: { type: "heading", level: 3 } },
8314
+ { id: "heading4", aliases: ["h4"], spec: { type: "heading", level: 4 } },
7581
8315
  { id: "bulletList", aliases: ["ul", "unordered", "bullet"], spec: { type: "listItem", listType: "bullet" } },
7582
8316
  { id: "numberedList", aliases: ["ol", "ordered"], spec: { type: "listItem", listType: "ordered" } },
7583
8317
  { id: "todoList", aliases: ["task", "checkbox", "checklist"], spec: { type: "listItem", listType: "task" } },
7584
8318
  { id: "quote", aliases: ["blockquote", "citation"], spec: { type: "quote" } },
8319
+ { id: "callout", aliases: ["alert", "admonition", "note", "tip", "important", "warning", "caution"], spec: { type: "quote", callout: "note" } },
8320
+ { id: "details", aliases: ["toggle", "collapse", "collapsible", "summary", "spoiler", "fold"], spec: { type: "details" } },
7585
8321
  { id: "code", aliases: ["pre", "snippet", "fence"], spec: { type: "code" } },
7586
8322
  { id: "table", aliases: ["grid"], spec: { type: "table" } },
7587
8323
  { id: "divider", aliases: ["hr", "separator", "line", "rule"], spec: { type: "divider" } }
@@ -7673,6 +8409,9 @@ var Editor = class {
7673
8409
  /** The link popover, and the field for an image's alt text. */
7674
8410
  inputPopover;
7675
8411
  blockHandle;
8412
+ /** Collapsible sections shown collapsed, by the ID of their title. View state: not saved, not undone. */
8413
+ collapsed = /* @__PURE__ */ new Set();
8414
+ linkCard;
7676
8415
  resizeHandles;
7677
8416
  /** The selected image's element, which carries the selected class. */
7678
8417
  selectedImageEl = null;
@@ -7711,13 +8450,14 @@ var Editor = class {
7711
8450
  this.source = loaded.source;
7712
8451
  this.current = createState(loaded.doc);
7713
8452
  this.renderer = new BlockRenderer(root, this.labels);
8453
+ this.renderer.collapsed = this.collapsed;
8454
+ this.collapseClosedSections(this.current.doc);
7714
8455
  this.renderer.widgetsAfter = (blockId) => {
7715
8456
  if (this.widgets.length === 0) return void 0;
7716
8457
  const els = this.widgets.filter((w) => w.blockId === blockId).map((w) => w.element);
7717
8458
  return els.length ? els : void 0;
7718
8459
  };
7719
- const views = new Map(this.extensions.flatMap((e) => Object.entries(e.views ?? {})));
7720
- if (views.size > 0) this.renderer.views = views;
8460
+ this.renderer.views = new Map([["markdown", MARKDOWN_VIEW], ...this.extensions.flatMap((e) => Object.entries(e.views ?? {}))]);
7721
8461
  this.renderer.markdown = this.markdown;
7722
8462
  this.renderer.onViewSettled = (ids) => this.viewsSettled(ids);
7723
8463
  const codeDecorators = this.extensions.flatMap((e) => e.codeDecorations ? [e.codeDecorations] : []);
@@ -7781,6 +8521,12 @@ var Editor = class {
7781
8521
  this.toolbar = options.toolbar === false ? null : new FormatToolbar(this, typeof options.toolbar === "object" ? options.toolbar.items : void 0);
7782
8522
  if (this.toolbar) this.toolbar.onMenuChange = () => this.syncActiveDescendant();
7783
8523
  this.blockHandle = new BlockHandle(this);
8524
+ this.linkCard = options.linkCard === false ? null : new LinkCard(this, {
8525
+ open: (target, event) => this.openHref(target.el.getAttribute("href"), event),
8526
+ edit: (target) => this.editLink(target),
8527
+ remove: (target) => this.removeLink(target),
8528
+ targetOf: (el) => this.linkTargetOf(el)
8529
+ });
7784
8530
  this.resizeHandles = new ResizeHandles(this);
7785
8531
  this.renderer.onImageError = () => {
7786
8532
  if (this.destroyed) return;
@@ -7836,6 +8582,8 @@ var Editor = class {
7836
8582
  this.blockSel = null;
7837
8583
  this.suggestions.reset();
7838
8584
  const next = createState(loaded.doc);
8585
+ this.collapsed.clear();
8586
+ this.collapseClosedSections(next.doc);
7839
8587
  this.relocateWidgets(this.current.doc, next.doc, true);
7840
8588
  this.current = next;
7841
8589
  this.paint(true, true);
@@ -7882,12 +8630,12 @@ var Editor = class {
7882
8630
  }
7883
8631
  }
7884
8632
  const block3 = getBlock(s.doc, s.selection.focus.blockId);
7885
- if (blockName(block3) !== name) return false;
8633
+ if (blockName(block3) !== name && !(name === "blockquote" && quoteKind(block3))) return false;
7886
8634
  if (!attrs) return true;
7887
8635
  const actual = this.getAttributes(name);
7888
8636
  return Object.entries(attrs).every(([k, v]) => actual[k] === v);
7889
8637
  }
7890
- /** Attributes of `name` at the selection: `src`, `alt`, `title`, `align`, `width`, `height` and `block` (true for an image block) for a selected image, `href` for a link, `level` for a heading, `language` for a code block, `checked` for a task, `syntax` for a raw block. */
8638
+ /** Attributes of `name` at the selection: `src`, `alt`, `title`, `align`, `width`, `height` and `block` (true for an image block) for a selected image, `href` for a link, `level` for a heading, `language` for a code block, `checked` for a task, `syntax` for a raw block, `callout` for a callout, `open` (saved as `<details open>`) and `collapsed` (shown collapsed now) for a section title. */
7891
8639
  getAttributes(name) {
7892
8640
  const s = this.current;
7893
8641
  if (name === "link") {
@@ -7899,6 +8647,8 @@ var Editor = class {
7899
8647
  return selected ? { ...selected.image, block: selectedImageBlock(s) !== null } : {};
7900
8648
  }
7901
8649
  const block3 = getBlock(s.doc, s.selection.focus.blockId);
8650
+ const kind = quoteKind(block3);
8651
+ if (name === "blockquote" && kind) return kind === "quote" ? {} : { callout: kind };
7902
8652
  if (blockName(block3) !== name) return {};
7903
8653
  switch (block3.type) {
7904
8654
  case "heading":
@@ -7909,6 +8659,10 @@ var Editor = class {
7909
8659
  return block3.listType === "task" ? { checked: block3.checked, indent: block3.indent } : { indent: block3.indent };
7910
8660
  case "raw":
7911
8661
  return { syntax: block3.syntax };
8662
+ case "quote":
8663
+ return block3.callout ? { callout: block3.callout } : {};
8664
+ case "details":
8665
+ return { open: block3.open, collapsed: this.collapsed.has(block3.id) };
7912
8666
  default:
7913
8667
  return {};
7914
8668
  }
@@ -8093,6 +8847,7 @@ var Editor = class {
8093
8847
  if (!next || next === this.current) return false;
8094
8848
  next = dropBrokenTokens(next, this.current, this.markdown.inline);
8095
8849
  next = clampListIndents(next, this.current);
8850
+ next = balanceSections(next);
8096
8851
  if (next.doc !== this.current.doc && sameBlocks(next.doc, this.current.doc)) next = { ...next, doc: this.current.doc };
8097
8852
  if (next.doc === this.current.doc && next.selection === this.current.selection && next.storedMarks === this.current.storedMarks) {
8098
8853
  return false;
@@ -8114,6 +8869,10 @@ var Editor = class {
8114
8869
  toggleOrderedList: () => block3({ type: "listItem", listType: "ordered" }),
8115
8870
  toggleTaskList: () => block3({ type: "listItem", listType: "task" }),
8116
8871
  toggleBlockquote: () => block3({ type: "quote" }),
8872
+ // Without callouts or sections in the Markdown dialect, they would not read back as such.
8873
+ toggleCallout: (attrs = {}) => this.markdown.callouts && block3({ type: "quote", callout: attrs.type ?? "note" }),
8874
+ toggleDetails: () => this.markdown.details && block3({ type: "details" }),
8875
+ setCallout: ({ type }) => (this.markdown.callouts || type === null) && run((s) => setCallout(s, s.selection.focus.blockId, type)),
8117
8876
  toggleCodeBlock: (attrs = {}) => block3({ type: "code", language: attrs.language }),
8118
8877
  setLink: ({ href }) => run((s) => setLink(s, href)),
8119
8878
  unsetLink: () => run((s) => setLink(s, null)),
@@ -8262,6 +9021,7 @@ var Editor = class {
8262
9021
  this.toolbar?.destroy();
8263
9022
  this.inputPopover.destroy();
8264
9023
  this.blockHandle.destroy();
9024
+ this.linkCard?.destroy();
8265
9025
  this.resizeHandles.destroy();
8266
9026
  setPopupContainer(this.root, void 0);
8267
9027
  for (const name of Object.keys(this.runtime.attributes ?? {})) this.root.removeAttribute(name);
@@ -8375,9 +9135,10 @@ var Editor = class {
8375
9135
  const el = this.renderer.elementFor(block3.id);
8376
9136
  if (!el || !el.classList.contains("mbe-empty")) continue;
8377
9137
  let hint = "";
8378
- if (block3.type === "heading") hint = this.labels[`heading${Math.min(block3.level, 3)}`];
9138
+ if (block3.type === "heading") hint = this.labels[`heading${Math.min(block3.level, 4)}`];
8379
9139
  else if (block3.type === "listItem") hint = this.labels.listHint;
8380
- else if (block3.type === "quote") hint = this.labels.quoteHint;
9140
+ else if (block3.type === "quote" && !block3.callout) hint = this.labels.quoteHint;
9141
+ else if (block3.type === "details") hint = this.labels.detailsHint;
8381
9142
  if (hint && el.dataset.hint !== hint) el.dataset.hint = hint;
8382
9143
  }
8383
9144
  this.updateUi();
@@ -8469,7 +9230,7 @@ var Editor = class {
8469
9230
  const end = blockIndex(this.state.doc, to.blockId);
8470
9231
  for (let i = from + dir; (end - i) * dir > 0; i += dir) {
8471
9232
  const block3 = blocks[i];
8472
- if (block3.type !== "divider") return this.blockEntry(block3, dir === 1, x);
9233
+ if (!this.skipsCaret(block3)) return this.blockEntry(block3, dir === 1, x);
8473
9234
  }
8474
9235
  return null;
8475
9236
  }
@@ -8624,7 +9385,7 @@ var Editor = class {
8624
9385
  const index2 = blockIndex(this.state.doc, selected.pos.blockId);
8625
9386
  for (let i = index2 + (forward ? 1 : -1); i >= 0 && i < blocks.length; i += forward ? 1 : -1) {
8626
9387
  const block3 = blocks[i];
8627
- if (block3.type === "divider") continue;
9388
+ if (this.skipsCaret(block3)) continue;
8628
9389
  const offset2 = imageBlockOffset(block3);
8629
9390
  if (offset2 !== null) return { anchor: { blockId: block3.id, offset: offset2 }, focus: { blockId: block3.id, offset: offset2 + 1 } };
8630
9391
  const vertical = key === "ArrowDown" || key === "ArrowUp";
@@ -8672,7 +9433,7 @@ var Editor = class {
8672
9433
  }
8673
9434
  for (let i = index + dir; i >= 0 && i < blocks.length; i += dir) {
8674
9435
  const next = blocks[i];
8675
- if (next.type === "divider") continue;
9436
+ if (this.skipsCaret(next)) continue;
8676
9437
  if (next.type === "table") {
8677
9438
  const r = dir === 1 ? 0 : next.rows.length - 1;
8678
9439
  const c = Math.min(col, next.align.length - 1);
@@ -8760,7 +9521,7 @@ var Editor = class {
8760
9521
  }
8761
9522
  case "insertParagraph": {
8762
9523
  if (this.suggestions.isOpen && this.suggestions.accept()) return;
8763
- this.run(splitBlock);
9524
+ this.run((s) => this.collapsed.has(s.selection.focus.blockId) ? splitCollapsedTitle(s) : splitBlock(s));
8764
9525
  return;
8765
9526
  }
8766
9527
  case "insertLineBreak":
@@ -8829,7 +9590,7 @@ var Editor = class {
8829
9590
  /** Markdown shortcuts and suggestion menus that typing `text` triggers. */
8830
9591
  afterTyping(text) {
8831
9592
  const typed = this.state;
8832
- if (text === " " || text === "-") this.run((s) => applyBlockInputRules(s));
9593
+ if (text === " " || text === "-") this.run((s) => applyBlockInputRules(s, this.markdown));
8833
9594
  if (text.length === 1 && "*_`~".includes(text)) this.run((s) => applyInlineInputRules(s));
8834
9595
  if (this.markdown.inline.length > 0) this.run((s) => applyTokenInputRules(s, this.markdown.inline) ?? s);
8835
9596
  if (text === " " && this.markdown.autolinks) this.run((s) => applyAutolinkInputRule(s) ?? s);
@@ -8970,7 +9731,7 @@ var Editor = class {
8970
9731
  if (blockId !== void 0 && block3.id !== blockId) continue;
8971
9732
  const el = this.renderer.elementFor(block3.id);
8972
9733
  if (!el || !el.isConnected) continue;
8973
- const containers2 = block3.type === "table" ? block3.rows.flatMap((row, r) => row.map((_, c) => ({ cell: { row: r, col: c } }))) : block3.type === "divider" ? [] : [{}];
9734
+ const containers2 = block3.type === "table" ? block3.rows.flatMap((row, r) => row.map((_, c) => ({ cell: { row: r, col: c } }))) : isTextless(block3) ? [] : [{}];
8974
9735
  for (const { cell } of containers2) {
8975
9736
  const contentEl = contentElement(el, cell);
8976
9737
  const content = containerContent(getBlock(state.doc, block3.id), cell);
@@ -9074,6 +9835,7 @@ var Editor = class {
9074
9835
  }
9075
9836
  }
9076
9837
  if (mod2 && !e.altKey) {
9838
+ if (e.key === "/" && !e.shiftKey) this.refreshSelection();
9077
9839
  if (e.key === "/" && !e.shiftKey && this.hasBlockMenu(this.state.selection.focus.blockId)) {
9078
9840
  return handled(() => this.openBlockMenu(this.state.selection.focus.blockId));
9079
9841
  }
@@ -9139,7 +9901,7 @@ var Editor = class {
9139
9901
  const blocks = this.state.doc.blocks;
9140
9902
  for (let i = key.from + key.vertical; i >= 0 && i < blocks.length; i += key.vertical) {
9141
9903
  const block3 = blocks[i];
9142
- if (block3.type === "divider") continue;
9904
+ if (this.skipsCaret(block3)) continue;
9143
9905
  this.caretKey = null;
9144
9906
  const row = key.vertical === 1 ? 0 : block3.type === "table" ? block3.rows.length - 1 : 0;
9145
9907
  const pos = block3.type === "table" ? { blockId: block3.id, offset: key.vertical === 1 ? 0 : inlineLength(block3.rows[row][0]), cell: { row, col: 0 } } : this.blockEntry(block3, key.vertical === 1, key.x);
@@ -9147,6 +9909,10 @@ var Editor = class {
9147
9909
  this.scrollCaretIntoView();
9148
9910
  return;
9149
9911
  }
9912
+ if (key.vertical === 1 && blocks[blocks.length - 1].type === "detailsEnd") {
9913
+ this.caretKey = null;
9914
+ this.run((s) => appendParagraph(s));
9915
+ }
9150
9916
  });
9151
9917
  }
9152
9918
  /** Selects all the text of the block (or table cell) holding `target`. False if it holds none. */
@@ -9173,6 +9939,13 @@ var Editor = class {
9173
9939
  e.preventDefault();
9174
9940
  return;
9175
9941
  }
9942
+ const toggle = e.button === 0 ? target.closest?.(".mbe-details-toggle") : null;
9943
+ const toggleBlock = toggle?.closest(`[${BLOCK_ATTR}]`)?.getAttribute(BLOCK_ATTR);
9944
+ if (toggleBlock && this.root.contains(toggle)) {
9945
+ e.preventDefault();
9946
+ this.setSectionCollapsed(toggleBlock, !this.collapsed.has(toggleBlock));
9947
+ return;
9948
+ }
9176
9949
  this.dropBlockSelection();
9177
9950
  if (target === this.root && e.button === 0 && !this.readOnly && this.clickBelowLastBlock(e)) return;
9178
9951
  const imageEl = e.button === 0 && !e.shiftKey && !this.readOnly ? target.closest?.(".mbe-image") : null;
@@ -9192,6 +9965,13 @@ var Editor = class {
9192
9965
  e.preventDefault();
9193
9966
  return;
9194
9967
  }
9968
+ const icon = e.button === 0 && !this.readOnly ? target.closest?.(".mbe-callout-icon") : null;
9969
+ const iconBlock = icon?.parentElement?.getAttribute(BLOCK_ATTR);
9970
+ if (icon && iconBlock && icon.parentElement.parentElement === this.root) {
9971
+ e.preventDefault();
9972
+ this.openBlockMenu(iconBlock, icon.getBoundingClientRect());
9973
+ return;
9974
+ }
9195
9975
  if (e.button === 0) this.pointerDown = true;
9196
9976
  if (target.classList?.contains("mbe-checkbox")) {
9197
9977
  e.preventDefault();
@@ -9207,7 +9987,7 @@ var Editor = class {
9207
9987
  const blocks = this.state.doc.blocks;
9208
9988
  const last = blocks[blocks.length - 1];
9209
9989
  const image = last ? imageBlockOffset(last) : null;
9210
- if (!last || last.type !== "code" && last.type !== "table" && last.type !== "divider" && image === null) return false;
9990
+ if (!last || last.type !== "code" && last.type !== "table" && !isTextless(last) && image === null) return false;
9211
9991
  const el = this.root.querySelector(`:scope > [data-block-id="${last.id}"]`);
9212
9992
  if (!el || e.clientY <= el.getBoundingClientRect().bottom) return false;
9213
9993
  e.preventDefault();
@@ -9233,11 +10013,12 @@ var Editor = class {
9233
10013
  const link = target.closest?.("a.mbe-link");
9234
10014
  if (!link) return;
9235
10015
  e.preventDefault();
9236
- if (this.readOnly || (isMac ? e.metaKey : e.ctrlKey)) {
9237
- const href = link.getAttribute("href");
9238
- if (!href || this.runtime.onLinkClick?.({ editor: this, href, event: e })) return;
9239
- this.root.ownerDocument.defaultView?.open(href, "_blank", "noopener,noreferrer");
9240
- }
10016
+ if (this.readOnly || (isMac ? e.metaKey : e.ctrlKey)) this.openHref(link.getAttribute("href"), e);
10017
+ }
10018
+ /** Opens a resolved link URL, as a click on a link does: through `onLinkClick`, else in a new tab. */
10019
+ openHref(href, event) {
10020
+ if (!href || this.runtime.onLinkClick?.({ editor: this, href, event })) return;
10021
+ this.root.ownerDocument.defaultView?.open(href, "_blank", "noopener,noreferrer");
9241
10022
  }
9242
10023
  /** Copies the code of the code block holding `button`, and shows that it did for a moment. */
9243
10024
  copyCode(button) {
@@ -9305,6 +10086,7 @@ var Editor = class {
9305
10086
  }
9306
10087
  onScroll() {
9307
10088
  this.blockHandle.hide();
10089
+ this.linkCard?.reposition();
9308
10090
  this.resizeHandles.reposition();
9309
10091
  if (this.suggestions.isActive || this.toolbar?.isOpen || this.blockMenu.isOpen) this.updateUi();
9310
10092
  }
@@ -9316,7 +10098,7 @@ var Editor = class {
9316
10098
  if (range) {
9317
10099
  if (!e.clipboardData) return;
9318
10100
  e.preventDefault();
9319
- const doc2 = { blocks: this.state.doc.blocks.slice(range.from, range.to + 1).map(cloneBlock) };
10101
+ const doc2 = { blocks: closeSections(this.state.doc.blocks.slice(range.from, range.to + 1).map(cloneBlock)) };
9320
10102
  writeClipboard(e.clipboardData, doc2, serializeBlocks(doc2.blocks, this.markdown));
9321
10103
  if (cut && !this.readOnly) this.deleteSelectedBlocks();
9322
10104
  return;
@@ -9324,7 +10106,7 @@ var Editor = class {
9324
10106
  this.refreshSelection();
9325
10107
  if (isCollapsed(this.state.selection) || !e.clipboardData) return;
9326
10108
  e.preventDefault();
9327
- const doc = { blocks: selectedBlocks(this.state) };
10109
+ const doc = { blocks: closeSections(selectedBlocks(this.state)) };
9328
10110
  writeClipboard(e.clipboardData, doc, serializeMarkdown(doc, this.markdown).replace(/\n$/, ""));
9329
10111
  if (cut && !this.readOnly) this.run(deleteSelection);
9330
10112
  }
@@ -9410,7 +10192,7 @@ var Editor = class {
9410
10192
  /** The slash menu, as a suggestion. */
9411
10193
  slashSuggestion() {
9412
10194
  const ids = this.options.slashMenu || SLASH_ITEM_IDS;
9413
- const items = ids.map((id) => BLOCK_ITEMS2.find((b) => b.id === id)).filter((b) => !!b).map((b) => ({ id: b.id, label: this.labels[b.id], icon: this.icon(b.id), aliases: b.aliases, spec: b.spec }));
10195
+ const items = ids.map((id) => BLOCK_ITEMS2.find((b) => b.id === id)).filter((b) => !!b && (b.id !== "callout" || this.markdown.callouts) && (b.id !== "details" || this.markdown.details)).map((b) => ({ id: b.id, label: this.labels[b.id], icon: this.icon(b.id), aliases: b.aliases, spec: b.spec }));
9414
10196
  return {
9415
10197
  name: "slash",
9416
10198
  trigger: SLASH_CHARS,
@@ -9444,7 +10226,37 @@ var Editor = class {
9444
10226
  const doc = this.current.doc;
9445
10227
  const a = blockIndex(doc, this.blockSel.anchor);
9446
10228
  const h = blockIndex(doc, this.blockSel.head);
9447
- return a < 0 || h < 0 ? null : { from: Math.min(a, h), to: Math.max(a, h) };
10229
+ if (a < 0 || h < 0) return null;
10230
+ return this.wholeSections({ from: Math.min(a, h), to: Math.max(a, h) });
10231
+ }
10232
+ /** `range` grown so that a collapsible section with its title or its end in it is in it whole. */
10233
+ wholeSections(range) {
10234
+ const blocks = this.current.doc.blocks;
10235
+ let { from, to } = range;
10236
+ if (!blocks.some((b) => b.type === "details")) return range;
10237
+ for (let changed = true; changed; ) {
10238
+ changed = false;
10239
+ for (let i = from; i <= to; i++) {
10240
+ const block3 = blocks[i];
10241
+ if (block3.type === "details") {
10242
+ const end = sectionEnd(blocks, i) ?? i;
10243
+ if (end > to) to = end, changed = true;
10244
+ } else if (block3.type === "detailsEnd") {
10245
+ const title = sectionTitle(blocks, i);
10246
+ if (title !== null && title < from) from = title, changed = true;
10247
+ }
10248
+ }
10249
+ }
10250
+ return { from, to };
10251
+ }
10252
+ /** The next block a block selection moves to from `index`: blocks shown on screen, not section ends. */
10253
+ nextSelectable(index, dir) {
10254
+ const blocks = this.current.doc.blocks;
10255
+ for (let i = index + dir; i >= 0 && i < blocks.length; i += dir) {
10256
+ const block3 = blocks[i];
10257
+ if (block3.type !== "detailsEnd" && !this.renderer.elementFor(block3.id)?.hasAttribute("data-section-hidden")) return block3.id;
10258
+ }
10259
+ return blocks[index].id;
9448
10260
  }
9449
10261
  /** Selects whole blocks, from the block `anchor` to the block `head`. */
9450
10262
  selectBlockRange(anchor, head) {
@@ -9513,7 +10325,6 @@ var Editor = class {
9513
10325
  const blocks = this.state.doc.blocks;
9514
10326
  const plain2 = !e.metaKey && !e.ctrlKey && !e.altKey;
9515
10327
  const mod2 = isMac ? e.metaKey : e.ctrlKey;
9516
- const clamp = (i) => blocks[Math.max(0, Math.min(blocks.length - 1, i))].id;
9517
10328
  switch (e.key) {
9518
10329
  case "Escape":
9519
10330
  if (!plain2 || e.shiftKey) return false;
@@ -9525,9 +10336,11 @@ var Editor = class {
9525
10336
  if (!plain2) return false;
9526
10337
  const up = e.key === "ArrowUp";
9527
10338
  if (e.shiftKey) {
9528
- this.selectBlockRange(this.blockSel.anchor, clamp(blockIndex(this.current.doc, this.blockSel.head) + (up ? -1 : 1)));
10339
+ let head = blockIndex(this.current.doc, this.blockSel.head);
10340
+ if (!up && blocks[head]?.type === "details") head = sectionEnd(blocks, head) ?? head;
10341
+ this.selectBlockRange(this.blockSel.anchor, this.nextSelectable(head, up ? -1 : 1));
9529
10342
  } else {
9530
- const id = clamp(up ? range.from - 1 : range.to + 1);
10343
+ const id = this.nextSelectable(up ? range.from : range.to, up ? -1 : 1);
9531
10344
  this.selectBlockRange(id, id);
9532
10345
  }
9533
10346
  return true;
@@ -9588,6 +10401,36 @@ var Editor = class {
9588
10401
  })));
9589
10402
  sections2.push({ title: this.labels.tableSection, items });
9590
10403
  }
10404
+ const kind = quoteKind(block3);
10405
+ if (kind && kind !== "quote") {
10406
+ const current = kind;
10407
+ const items = CALLOUT_TYPES.map((type) => {
10408
+ const name = calloutName(type);
10409
+ return {
10410
+ id: name,
10411
+ label: this.labels[name],
10412
+ icon: this.icon(name),
10413
+ checked: type === current,
10414
+ run: () => this.run((s) => setCallout(s, blockId, type))
10415
+ };
10416
+ });
10417
+ sections2.push({ title: this.labels.callout, items });
10418
+ sections2.push({
10419
+ items: [
10420
+ {
10421
+ id: "delete",
10422
+ label: this.labels.delete,
10423
+ icon: this.icon("delete"),
10424
+ danger: true,
10425
+ run: () => this.run((s) => {
10426
+ const run = quoteRun(s, blockId);
10427
+ return run ? deleteBlocks(s, { from: run.start, to: run.end }) : null;
10428
+ })
10429
+ }
10430
+ ]
10431
+ });
10432
+ return sections2;
10433
+ }
9591
10434
  const imageOffset = imageBlockOffset(block3);
9592
10435
  if (imageOffset !== null) {
9593
10436
  const pos = { blockId, offset: imageOffset };
@@ -9634,15 +10477,26 @@ var Editor = class {
9634
10477
  }
9635
10478
  /**
9636
10479
  * @internal
9637
- * Only large blocks get the block handle and block menu: tables, code blocks and
9638
- * image blocks. Other blocks change type through the slash menu or Markdown
9639
- * shortcuts.
10480
+ * Only large blocks get the block handle and block menu: tables, code blocks,
10481
+ * image blocks and callouts. Other blocks change type through the slash menu
10482
+ * or Markdown shortcuts.
9640
10483
  */
9641
10484
  hasBlockMenu(blockId) {
9642
10485
  const block3 = this.state.doc.blocks.find((b) => b.id === blockId);
9643
- return block3?.type === "table" || block3?.type === "code" || !!block3 && isImageBlock(block3);
10486
+ return block3?.type === "table" || block3?.type === "code" || isCallout(block3) || !!block3 && isImageBlock(block3);
9644
10487
  }
9645
- /** @internal Opens the block menu of a table, code block or image block, as the block handle and Mod+/ do. */
10488
+ /**
10489
+ * @internal
10490
+ * The block whose block menu `blockId` belongs to, or null when it has none:
10491
+ * the first block of a callout, so the handle sits by its icon; otherwise
10492
+ * the block itself.
10493
+ */
10494
+ blockMenuOwner(blockId) {
10495
+ if (!this.hasBlockMenu(blockId)) return null;
10496
+ const run = quoteRun(this.state, blockId);
10497
+ return run ? this.state.doc.blocks[run.start].id : blockId;
10498
+ }
10499
+ /** @internal Opens the block menu of a table, code block, image block or callout, as the block handle and Mod+/ do. */
9646
10500
  openBlockMenu(blockId, anchor) {
9647
10501
  if (this.readOnly || !this.hasBlockMenu(blockId)) return;
9648
10502
  this.dropBlockSelection();
@@ -9652,7 +10506,7 @@ var Editor = class {
9652
10506
  if (imageOffset !== null) {
9653
10507
  this.current = selectImage(this.state, { blockId, offset: imageOffset });
9654
10508
  if (!this.hasFocus()) this.focus();
9655
- } else if (this.state.selection.focus.blockId !== blockId) {
10509
+ } else if (this.state.selection.focus.blockId !== blockId && !this.inSameCallout(this.state.selection.focus.blockId, blockId)) {
9656
10510
  const block3 = getBlock(this.state.doc, blockId);
9657
10511
  const start = startOf(block3);
9658
10512
  this.current = { ...this.state, selection: { anchor: start, focus: start } };
@@ -9665,6 +10519,14 @@ var Editor = class {
9665
10519
  if (rect) this.blockMenu.popup.show(rect, "below");
9666
10520
  this.syncActiveDescendant();
9667
10521
  }
10522
+ /** True if the blocks `a` and `b` are in the same callout. */
10523
+ inSameCallout(a, b) {
10524
+ const block3 = getBlock(this.state.doc, b);
10525
+ const run = isCallout(block3) ? quoteRun(this.state, b) : null;
10526
+ if (!run) return false;
10527
+ const i = blockIndex(this.state.doc, a);
10528
+ return i >= run.start && i <= run.end;
10529
+ }
9668
10530
  closeBlockMenu() {
9669
10531
  this.blockMenu.hide();
9670
10532
  this.syncActiveDescendant();
@@ -9709,6 +10571,7 @@ var Editor = class {
9709
10571
  // UI that follows the selection
9710
10572
  updateUi() {
9711
10573
  if (this.destroyed) return;
10574
+ this.expandAroundSelection();
9712
10575
  const focused = this.hasFocus();
9713
10576
  const pos = this.state.selection.focus;
9714
10577
  const el = focused && !this.blockSel && isCollapsed(this.state.selection) ? this.renderer.elementFor(pos.blockId) : void 0;
@@ -9734,12 +10597,130 @@ var Editor = class {
9734
10597
  else this.toolbar.hide();
9735
10598
  }
9736
10599
  if (focused && !this.readOnly && isTouch()) {
9737
- if (this.hasBlockMenu(pos.blockId)) this.blockHandle.showFor(pos.blockId);
10600
+ const owner = this.blockMenuOwner(pos.blockId);
10601
+ if (owner) this.blockHandle.showFor(owner);
9738
10602
  else this.blockHandle.hide();
9739
10603
  }
9740
10604
  if (!focused && this.blockMenu.isOpen && !this.root.ownerDocument.activeElement?.closest?.(".mbe-ui")) this.blockMenu.hide();
10605
+ if (this.linkCard) {
10606
+ if (this.readOnly) this.linkCard.hide();
10607
+ else this.linkCard.setCaret(focused && !this.composing && !this.blockSel && !this.suggestions.isActive && !this.blockMenu.isOpen && !this.inputPopover.isOpen ? this.caretLink() : null);
10608
+ }
9741
10609
  this.syncActiveDescendant();
9742
10610
  }
10611
+ // -------------------------------------------------------------------------
10612
+ // Collapsible sections
10613
+ /**
10614
+ * Collapses or expands the collapsible section titled by the block
10615
+ * `blockId`. This changes the view only: the Markdown, history and events
10616
+ * stay as they are. A caret inside a section that collapses moves to the
10617
+ * end of its title. Returns false when the block is not a section title.
10618
+ */
10619
+ setSectionCollapsed(blockId, collapsed) {
10620
+ if (this.destroyed) return false;
10621
+ const doc = this.state.doc;
10622
+ const index = blockIndex(doc, blockId);
10623
+ if (doc.blocks[index]?.type !== "details") return false;
10624
+ if (this.collapsed.has(blockId) === collapsed) return true;
10625
+ if (collapsed) this.collapsed.add(blockId);
10626
+ else this.collapsed.delete(blockId);
10627
+ if (collapsed) {
10628
+ const end = sectionEnd(doc.blocks, index) ?? index;
10629
+ const inside = (p) => {
10630
+ const i = blockIndex(doc, p.blockId);
10631
+ return i > index && i <= end;
10632
+ };
10633
+ const { anchor, focus } = this.state.selection;
10634
+ if (inside(anchor) || inside(focus)) {
10635
+ const title = endOf(doc.blocks[index]);
10636
+ this.dropBlockSelection();
10637
+ this.current = { ...this.current, selection: { anchor: title, focus: title }, storedMarks: null };
10638
+ this.syncDomSelection();
10639
+ }
10640
+ }
10641
+ this.renderer.updateSections(doc);
10642
+ this.updateUi();
10643
+ return true;
10644
+ }
10645
+ /** True when the section titled by `blockId` is shown collapsed. */
10646
+ isSectionCollapsed(blockId) {
10647
+ return this.collapsed.has(blockId);
10648
+ }
10649
+ /** Sections that are not saved open start collapsed, as a Markdown renderer shows them. */
10650
+ collapseClosedSections(doc) {
10651
+ for (const block3 of doc.blocks) if (block3.type === "details" && !block3.open) this.collapsed.add(block3.id);
10652
+ }
10653
+ /** Expands the collapsed sections around the selection's focus, so the caret is never hidden. */
10654
+ expandAroundSelection() {
10655
+ if (this.collapsed.size === 0) return;
10656
+ const focusId = this.state.selection.focus.blockId;
10657
+ if (!this.renderer.elementFor(focusId)?.hasAttribute("data-section-hidden")) return;
10658
+ const titles = [];
10659
+ for (const block3 of this.state.doc.blocks) {
10660
+ if (block3.id === focusId) break;
10661
+ if (block3.type === "details") titles.push(block3.id);
10662
+ else if (block3.type === "detailsEnd") titles.pop();
10663
+ }
10664
+ for (const id of titles) this.collapsed.delete(id);
10665
+ this.renderer.updateSections(this.state.doc);
10666
+ }
10667
+ /** Blocks the caret passes over: dividers, section ends, and blocks inside a collapsed section. */
10668
+ skipsCaret(block3) {
10669
+ return isTextless(block3) || !!this.renderer.elementFor(block3.id)?.hasAttribute("data-section-hidden");
10670
+ }
10671
+ // -------------------------------------------------------------------------
10672
+ // Links (see ui/linkCard.ts)
10673
+ /** The link the caret is inside, not at its edge, with its element. */
10674
+ caretLink() {
10675
+ if (!isCollapsed(this.state.selection)) return null;
10676
+ const link = activeLink(this.state);
10677
+ if (!link || link.pos.offset <= link.from || link.pos.offset >= link.to) return null;
10678
+ const blockEl = this.renderer.elementFor(link.pos.blockId);
10679
+ if (!blockEl) return null;
10680
+ const start = { ...link.pos, offset: link.from };
10681
+ for (const el of blockEl.querySelectorAll("a.mbe-link")) {
10682
+ const pos = this.linkStart(el);
10683
+ if (pos && samePosition(pos, start)) return this.linkTargetOf(el);
10684
+ }
10685
+ return null;
10686
+ }
10687
+ /** The document position where a rendered link starts. */
10688
+ linkStart(el) {
10689
+ return domToPosition(this.root, el, 0);
10690
+ }
10691
+ /** The link a rendered link element shows, or null for one outside the document's blocks. */
10692
+ linkTargetOf(el) {
10693
+ if (el.closest(".mbe-flow")) return null;
10694
+ const pos = this.linkStart(el);
10695
+ if (!pos) return null;
10696
+ const block3 = this.state.doc.blocks.find((b) => b.id === pos.blockId);
10697
+ const content = block3 && containerContent(block3, pos.cell);
10698
+ const link = content && linkAt(content, pos.offset);
10699
+ return link && link.from === pos.offset ? { el, href: link.href } : null;
10700
+ }
10701
+ /** The selection of a link's whole text, from a rendered link element. */
10702
+ linkSelection(target) {
10703
+ const from = this.linkStart(target.el);
10704
+ if (!from) return null;
10705
+ const block3 = getBlock(this.state.doc, from.blockId);
10706
+ const content = containerContent(block3, from.cell);
10707
+ const link = content && linkAt(content, from.offset);
10708
+ return link ? { anchor: from, focus: { ...from, offset: link.to } } : null;
10709
+ }
10710
+ /** Opens the link popover for a link, as Mod+K does with the caret in it. */
10711
+ editLink(target) {
10712
+ const range = this.linkSelection(target);
10713
+ if (!range || this.readOnly) return;
10714
+ this.focus();
10715
+ this.setSelection(range);
10716
+ this.openLinkPopover();
10717
+ }
10718
+ /** Removes a link and keeps its text, as one undo step. */
10719
+ removeLink(target) {
10720
+ const range = this.linkSelection(target);
10721
+ if (!range || this.readOnly) return;
10722
+ this.run((s) => ({ ...setLink({ ...s, selection: range }, null), selection: s.selection }));
10723
+ }
9743
10724
  /** Marks the selected image's element, and hides the browser's selection highlight over it. */
9744
10725
  paintSelectedImage(el) {
9745
10726
  if (this.selectedImageEl !== el) {
@@ -9812,6 +10793,7 @@ var Editor = class {
9812
10793
  this.blockMenu.hide();
9813
10794
  this.toolbar?.hide();
9814
10795
  this.blockHandle.hide();
10796
+ this.linkCard?.setCaret(null);
9815
10797
  this.resizeHandles.hide();
9816
10798
  this.paintSelectedImage(null);
9817
10799
  this.hintEl?.classList.remove("mbe-show-hint");
@@ -9833,6 +10815,10 @@ var Editor = class {
9833
10815
  this.cleanup.push(() => target.removeEventListener(type, fn, capture));
9834
10816
  }
9835
10817
  };
10818
+ function isCallout(block3) {
10819
+ const kind = quoteKind(block3);
10820
+ return kind !== null && kind !== "quote";
10821
+ }
9836
10822
  function blockName(block3) {
9837
10823
  switch (block3.type) {
9838
10824
  case "listItem":
@@ -9841,6 +10827,8 @@ function blockName(block3) {
9841
10827
  return "blockquote";
9842
10828
  case "code":
9843
10829
  return "codeBlock";
10830
+ case "detailsEnd":
10831
+ return "details";
9844
10832
  default:
9845
10833
  return block3.type;
9846
10834
  }
@@ -10178,6 +11166,7 @@ function fileHandler(options) {
10178
11166
  }
10179
11167
  export {
10180
11168
  ATOM_CHAR,
11169
+ CALLOUT_TYPES,
10181
11170
  DEFAULT_LABELS,
10182
11171
  Editor,
10183
11172
  MARK_ORDER,
@@ -10197,6 +11186,8 @@ export {
10197
11186
  defaultKeymap,
10198
11187
  defaultResolveUrl,
10199
11188
  deleteInline,
11189
+ details,
11190
+ detailsEnd,
10200
11191
  divider,
10201
11192
  docToHtml,
10202
11193
  emptyTable,
@@ -10216,6 +11207,7 @@ export {
10216
11207
  isImageBlock,
10217
11208
  isPlainTextBlock,
10218
11209
  isTextBlock,
11210
+ isTextless,
10219
11211
  linkAt,
10220
11212
  listItem,
10221
11213
  loadMarkdown,
@@ -10230,11 +11222,13 @@ export {
10230
11222
  parseMarkdown,
10231
11223
  plain,
10232
11224
  quote,
11225
+ quoteKind,
10233
11226
  rangeHasMark,
10234
11227
  rawBlock,
10235
11228
  sameCell,
10236
11229
  sameMarks,
10237
11230
  samePosition,
11231
+ sameQuote,
10238
11232
  scanMentions,
10239
11233
  scanTags,
10240
11234
  serializeInline,
@@ -10251,8 +11245,10 @@ export {
10251
11245
  textDecorator,
10252
11246
  toPlain,
10253
11247
  tokensAt,
11248
+ unquote,
10254
11249
  withContainerContent,
10255
- withContent
11250
+ withContent,
11251
+ withQuote
10256
11252
  };
10257
11253
  /*! Icons from Lucide (lucide-static 1.55.0), https://lucide.dev
10258
11254
  * ISC License. Copyright (c) 2026 Lucide Icons and Contributors.