@usememos/editor 26.10.14 → 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
@@ -90,7 +90,8 @@ function listItem(listType, content = [], opts = {}) {
90
90
  checked: listType === "task" ? opts.checked ?? false : false,
91
91
  content: normalizeInline(content)
92
92
  };
93
- 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;
94
95
  }
95
96
  function quote(content = [], id = createId(), callout) {
96
97
  const block3 = { id, type: "quote", content: normalizeInline(content) };
@@ -132,6 +133,23 @@ function detailsEnd(id = createId()) {
132
133
  function plain(text) {
133
134
  return text ? [{ text, marks: [] }] : [];
134
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
+ }
135
153
  function isTextBlock(block3) {
136
154
  return block3.type !== "table" && block3.type !== "divider" && block3.type !== "detailsEnd";
137
155
  }
@@ -532,7 +550,7 @@ function contentOf(block3, cell) {
532
550
  function emptyLike(block3) {
533
551
  switch (block3.type) {
534
552
  case "listItem":
535
- return listItem(block3.listType, [], { indent: block3.indent });
553
+ return listItem(block3.listType, [], { indent: block3.indent, quote: quoteKind(block3) });
536
554
  case "quote":
537
555
  return quote([], void 0, block3.callout);
538
556
  default:
@@ -627,6 +645,7 @@ function deleteBackward(state) {
627
645
  return { ...state, selection: caret(block3.id, inlineLength(contentOf(block3, prevCell)), prevCell) };
628
646
  }
629
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));
630
649
  if (block3.type !== "paragraph") return replaceBlock(state, paragraph(block3.content, block3.id));
631
650
  const prev = state.doc.blocks[index - 1];
632
651
  if (!prev) return state;
@@ -760,7 +779,7 @@ function splitBlock(state) {
760
779
  return replaceBlock(s, code, caret(code.id, 0));
761
780
  }
762
781
  if (length === 0 && block3.type === "listItem") {
763
- 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);
764
783
  return replaceBlock(s, next);
765
784
  }
766
785
  if (length === 0 && block3.type === "quote") return replaceBlock(s, paragraph([], block3.id));
@@ -1010,9 +1029,12 @@ function convert(block3, spec) {
1010
1029
  return listItem(spec.listType, content, {
1011
1030
  id: block3.id,
1012
1031
  indent: block3.type === "listItem" ? block3.indent : 0,
1013
- 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)
1014
1035
  });
1015
1036
  case "quote":
1037
+ if (block3.type === "listItem") return withQuote(block3, spec.callout ?? (block3.quote ? block3.callout ?? "quote" : "quote"));
1016
1038
  return quote(content, block3.id, spec.callout);
1017
1039
  case "code":
1018
1040
  return codeBlock(spec.language ?? (block3.type === "code" ? block3.language : ""), inlineText(toPlain(content)), block3.id);
@@ -1025,12 +1047,15 @@ function isConvertible(block3) {
1025
1047
  }
1026
1048
  function setBlockType(state, spec) {
1027
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) {
1028
1053
  const { from, to } = orderedRange(state.doc, state.selection);
1029
1054
  const start = blockIndex(state.doc, from.blockId);
1030
1055
  const end = blockIndex(state.doc, to.blockId);
1031
1056
  const range = state.doc.blocks.slice(start, end + 1);
1032
1057
  if (spec.type === "code" && range.filter(isConvertible).length > 1) return mergeIntoCode(state, start, range, spec.language);
1033
- const updated = range.map((b) => isConvertible(b) ? convert(b, spec) : b);
1058
+ const updated = range.map((b) => isConvertible(b) ? convertBlock(b) : b);
1034
1059
  const doc = { blocks: splice(state, start, updated.length, ...updated) };
1035
1060
  return { doc, selection: clampSelection(doc, state.selection), storedMarks: null };
1036
1061
  }
@@ -1062,20 +1087,21 @@ function quoteRun(state, blockId) {
1062
1087
  const blocks = state.doc.blocks;
1063
1088
  const index = blockIndex(state.doc, blockId);
1064
1089
  const block3 = blocks[index];
1065
- if (block3?.type !== "quote") return null;
1066
- const same = (b) => b?.type === "quote" && b.callout === block3.callout;
1090
+ if (quoteKind(block3) === null) return null;
1067
1091
  let start = index;
1068
1092
  let end = index;
1069
- while (same(blocks[start - 1])) start--;
1070
- while (same(blocks[end + 1])) end++;
1093
+ while (sameQuote(block3, blocks[start - 1])) start--;
1094
+ while (sameQuote(block3, blocks[end + 1])) end++;
1071
1095
  return { start, end };
1072
1096
  }
1073
1097
  function setCallout(state, blockId, callout) {
1074
1098
  const run = quoteRun(state, blockId);
1075
1099
  if (!run) return state;
1076
1100
  const blocks = state.doc.blocks.slice(run.start, run.end + 1);
1077
- if (blocks.every((b) => (b.callout ?? null) === callout)) return state;
1078
- const updated = blocks.map((b) => quote(b.content, b.id, callout ?? void 0));
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
+ );
1079
1105
  const doc = { blocks: splice(state, run.start, updated.length, ...updated) };
1080
1106
  return { doc, selection: state.selection, storedMarks: state.storedMarks };
1081
1107
  }
@@ -1091,8 +1117,10 @@ function hasType(block3, spec) {
1091
1117
  return block3.type === "listItem" && block3.listType === spec.listType;
1092
1118
  case "code":
1093
1119
  return block3.type === "code";
1094
- case "quote":
1095
- return block3.type === "quote" && (!spec.callout || block3.callout === spec.callout);
1120
+ case "quote": {
1121
+ const kind = quoteKind(block3);
1122
+ return kind !== null && (!spec.callout || kind === spec.callout);
1123
+ }
1096
1124
  default:
1097
1125
  return block3.type === spec.type;
1098
1126
  }
@@ -1101,7 +1129,13 @@ function toggleBlockType(state, spec) {
1101
1129
  const text = convertibleBlocks(state);
1102
1130
  if (text.length === 0) return state;
1103
1131
  const on = text.every((b) => hasType(b, spec));
1104
- 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
+ });
1105
1139
  }
1106
1140
  function insertBlock(state, spec) {
1107
1141
  const pos = state.selection.focus;
@@ -1144,8 +1178,7 @@ function indentListItems(state, delta2) {
1144
1178
  for (let i = start; i <= end; i++) {
1145
1179
  const b = blocks[i];
1146
1180
  if (b.type !== "listItem") continue;
1147
- const prev = blocks[i - 1];
1148
- const max = prev?.type === "listItem" ? Math.min(MAX_INDENT, prev.indent + 1) : 0;
1181
+ const max = maxIndent(blocks[i - 1], b);
1149
1182
  const indent = Math.max(0, Math.min(max, b.indent + delta2));
1150
1183
  if (indent !== b.indent) {
1151
1184
  blocks[i] = { ...b, indent };
@@ -1217,12 +1250,14 @@ function deleteBlock(state, blockId) {
1217
1250
  function spanBlocks(blocks, range) {
1218
1251
  return { anchor: startOf(blocks[range.from]), focus: endOf(blocks[range.to]) };
1219
1252
  }
1253
+ function maxIndent(prev, item) {
1254
+ return prev?.type === "listItem" && quoteKind(prev) === quoteKind(item) ? Math.min(MAX_INDENT, prev.indent + 1) : 0;
1255
+ }
1220
1256
  function fitIndents(blocks, index) {
1221
1257
  for (let i = Math.max(0, index); i < blocks.length; i++) {
1222
1258
  const block3 = blocks[i];
1223
1259
  if (block3.type !== "listItem") return;
1224
- const prev = blocks[i - 1];
1225
- const max = prev?.type === "listItem" ? Math.min(MAX_INDENT, prev.indent + 1) : 0;
1260
+ const max = maxIndent(blocks[i - 1], block3);
1226
1261
  if (block3.indent <= max) return;
1227
1262
  blocks[i] = { ...block3, indent: max };
1228
1263
  }
@@ -1357,7 +1392,7 @@ function applyBlockInputRules(state, dialect = {}) {
1357
1392
  const spec = toSpec(m);
1358
1393
  if (spec.type === "quote" && spec.callout && dialect.callouts === false || spec.type === "details" && dialect.details === false) continue;
1359
1394
  if (block3.type === "listItem" && !(spec.type === "listItem" && spec.listType === "task")) continue;
1360
- if (block3.type === "quote") {
1395
+ if (block3.type === "quote" && spec.type !== "listItem") {
1361
1396
  if (spec.type !== "quote" || !spec.callout) continue;
1362
1397
  return setCallout(deleteRange(state, { blockId: block3.id, offset: 0 }, pos), block3.id, spec.callout);
1363
1398
  }
@@ -1371,7 +1406,8 @@ function applyBlockInputRules(state, dialect = {}) {
1371
1406
  id: converted.id,
1372
1407
  indent: converted.indent,
1373
1408
  checked,
1374
- 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)
1375
1411
  });
1376
1412
  next = replaceBlock(next, updated, next.selection);
1377
1413
  }
@@ -1469,10 +1505,8 @@ function clampListIndents(state, before) {
1469
1505
  let blocks = null;
1470
1506
  let max = 0;
1471
1507
  state.doc.blocks.forEach((block3, i) => {
1472
- if (block3.type !== "listItem") {
1473
- max = 0;
1474
- return;
1475
- }
1508
+ if (block3.type !== "listItem" || quoteKind(block3) !== quoteKind(state.doc.blocks[i - 1])) max = 0;
1509
+ if (block3.type !== "listItem") return;
1476
1510
  if (block3.indent > max) (blocks ??= [...state.doc.blocks])[i] = { ...block3, indent: max };
1477
1511
  max = Math.min(block3.indent, max) + 1;
1478
1512
  });
@@ -1655,18 +1689,16 @@ function docToHtml(doc) {
1655
1689
  let i = 0;
1656
1690
  while (i < blocks.length) {
1657
1691
  const block3 = blocks[i];
1658
- if (block3.type === "listItem") {
1659
- let j = i;
1660
- while (j < blocks.length && blocks[j].type === "listItem") j++;
1661
- 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) }));
1662
1697
  i = j;
1663
- } else if (block3.type === "quote") {
1698
+ } else if (block3.type === "listItem") {
1664
1699
  let j = i;
1665
- let inner = "";
1666
- for (let next = blocks[j]; next?.type === "quote" && next.callout === block3.callout; next = blocks[++j]) {
1667
- inner += `<p>${inlineHtml(next.content)}</p>`;
1668
- }
1669
- out += quoteHtml(block3.callout, inner);
1700
+ while (j < blocks.length && blocks[j].type === "listItem" && quoteKind(blocks[j]) === null) j++;
1701
+ out += listHtml(blocks.slice(i, j));
1670
1702
  i = j;
1671
1703
  } else {
1672
1704
  out += blockHtml(block3);
@@ -1709,9 +1741,8 @@ function blockHtml(block3) {
1709
1741
  return html + "</table>";
1710
1742
  }
1711
1743
  case "listItem":
1712
- return listHtml([block3]);
1713
1744
  case "quote":
1714
- return quoteHtml(block3.callout, `<p>${inlineHtml(block3.content)}</p>`);
1745
+ return docToHtml({ blocks: [block3] });
1715
1746
  }
1716
1747
  }
1717
1748
  function quoteHtml(callout, inner) {
@@ -2167,11 +2198,9 @@ var Converter = class _Converter {
2167
2198
  case "raw":
2168
2199
  this.out.push(quote(block3.content, void 0, callout));
2169
2200
  break;
2170
- case "listItem": {
2171
- const marker = block3.listType === "ordered" ? "1. " : block3.listType === "task" ? block3.checked ? "- [x] " : "- [ ] " : "- ";
2172
- this.out.push(quote([...plain(marker), ...block3.content], void 0, callout));
2201
+ case "listItem":
2202
+ this.out.push(withQuote(block3, callout ?? "quote"));
2173
2203
  break;
2174
- }
2175
2204
  default:
2176
2205
  this.out.push(block3);
2177
2206
  }
@@ -2615,7 +2644,10 @@ function resolveMarkdown(options) {
2615
2644
 
2616
2645
  // src/markdown/lower.ts
2617
2646
  function lowerTopLevel(node, options, source) {
2618
- 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;
2619
2651
  const blocks = [];
2620
2652
  lowerBlock(node, blocks, options);
2621
2653
  return blocks;
@@ -2623,7 +2655,7 @@ function lowerTopLevel(node, options, source) {
2623
2655
  function fitsModel(node, depth) {
2624
2656
  switch (node.type) {
2625
2657
  case "blockQuote":
2626
- return node.children.every((child) => child.type === "paragraph");
2658
+ return node.children.every((child) => child.type === "paragraph" || child.type === "list" && fitsModel(child, 0));
2627
2659
  case "list":
2628
2660
  return depth <= MAX_INDENT && node.items.every(
2629
2661
  (item) => item.children.every(
@@ -2735,7 +2767,7 @@ function listTypeOf(list, item) {
2735
2767
  if (item.task) return "task";
2736
2768
  return list.ordered ? "ordered" : "bullet";
2737
2769
  }
2738
- function lowerList(list, depth, out, o) {
2770
+ function lowerList(list, depth, out, o, quoted) {
2739
2771
  list.items.forEach((item, index) => {
2740
2772
  const first = item.children[0];
2741
2773
  const listType = listTypeOf(list, item);
@@ -2743,10 +2775,11 @@ function lowerList(list, depth, out, o) {
2743
2775
  listItem(listType, first?.type === "paragraph" ? lowerInlines(first.children, o) : [], {
2744
2776
  indent: Math.min(depth, MAX_INDENT),
2745
2777
  checked: item.checked,
2746
- start: index === 0 && listType === "ordered" ? list.start : void 0
2778
+ start: index === 0 && listType === "ordered" ? list.start : void 0,
2779
+ quote: quoted
2747
2780
  })
2748
2781
  );
2749
- 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);
2750
2783
  });
2751
2784
  }
2752
2785
  function lowerQuote(children, out, o) {
@@ -2754,6 +2787,7 @@ function lowerQuote(children, out, o) {
2754
2787
  const callout = alert?.type;
2755
2788
  const start = out.length;
2756
2789
  children.forEach((child, i) => {
2790
+ if (child.type === "list") lowerList(child, 0, out, o, callout ?? "quote");
2757
2791
  if (child.type !== "paragraph") return;
2758
2792
  const content = lowerInlines(i === 0 && alert ? alert.rest : child.children, o);
2759
2793
  if (isEmptyLine(content)) out.push(quote([], void 0, callout));
@@ -4447,29 +4481,38 @@ function serializeBlocks(blocks, options) {
4447
4481
  let out = "";
4448
4482
  let prev = null;
4449
4483
  const lists = new ListState(ctx.paragraph);
4450
- for (const block3 of blocks) {
4484
+ for (let i = 0; i < blocks.length; i++) {
4485
+ const block3 = blocks[i];
4451
4486
  let text;
4452
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
+ }
4453
4502
  switch (block3.type) {
4454
4503
  case "paragraph":
4455
4504
  text = block3.content.length === 0 ? "&nbsp;" : inlineToMarkdown(block3.content, ctx.paragraph);
4456
4505
  break;
4457
- case "quote": {
4458
- let body = block3.content.length === 0 ? "&nbsp;" : inlineToMarkdown(block3.content, ctx.paragraph);
4459
- const joined = prev?.type === "quote" && prev.callout === block3.callout;
4460
- if (block3.callout && !joined) body = `[!${block3.callout.toUpperCase()}]
4461
- ${body}`;
4462
- text = prefixLines(body, "> ", ">");
4463
- if (joined) separator = "\n>\n";
4464
- break;
4465
- }
4506
+ case "quote":
4507
+ continue;
4466
4508
  case "heading":
4467
4509
  text = serializeHeading(block3.level, block3.content, ctx.heading);
4468
4510
  break;
4469
4511
  case "listItem": {
4470
- 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);
4471
4514
  text = item.text;
4472
- if (prev?.type === "listItem" && !item.blankLineBefore) separator = "\n";
4515
+ if (before && !item.blankLineBefore) separator = "\n";
4473
4516
  break;
4474
4517
  }
4475
4518
  case "code":
@@ -4500,6 +4543,11 @@ ${body}`;
4500
4543
  }
4501
4544
  return out;
4502
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
+ }
4503
4551
  function isEmptyParagraph(block3) {
4504
4552
  return block3.type === "paragraph" && block3.content.length === 0;
4505
4553
  }
@@ -5054,7 +5102,7 @@ function isOpen(source, options) {
5054
5102
  return parseAst(source + "\n\nx", options).children.length < 2;
5055
5103
  }
5056
5104
  function joins(a, b) {
5057
- if (a?.type === "quote" && b?.type === "quote") return a.callout === b.callout;
5105
+ if (quoteKind(a) !== null || quoteKind(b) !== null) return sameQuote(a, b);
5058
5106
  return a?.type === "listItem" && b?.type === "listItem";
5059
5107
  }
5060
5108
  function saveWithSource(blocks, source, options) {
@@ -5151,7 +5199,7 @@ function saveWithSource(blocks, source, options) {
5151
5199
  }
5152
5200
  return out + ending;
5153
5201
  }
5154
- var reTaskLine = /^([ \t]*(?:[-+*]|\d{1,9}[.)])[ \t]+\[)([ xX])(?=\][ \t]|\]$)/gm;
5202
+ var reTaskLine = /^((?:[ \t]*>)*[ \t]*(?:[-+*]|\d{1,9}[.)])[ \t]+\[)([ xX])(?=\][ \t]|\]$)/gm;
5155
5203
  function tickedGroup(blocks, i, firstBlocks, source, options) {
5156
5204
  const loaded = firstBlocks.get(blocks[i].id);
5157
5205
  if (!loaded || loaded.open) return null;
@@ -6326,7 +6374,7 @@ function blockState(editor) {
6326
6374
  allHeadings: some && blocks.every((b) => b.type === "heading"),
6327
6375
  listType: every((b) => b.type === "listItem" ? b.listType : null),
6328
6376
  allListItems: some && blocks.every((b) => b.type === "listItem"),
6329
- allQuotes: some && blocks.every((b) => b.type === "quote")
6377
+ allQuotes: some && blocks.every((b) => quoteKind(b) !== null)
6330
6378
  };
6331
6379
  }
6332
6380
  var FormatToolbar = class {
@@ -6655,6 +6703,7 @@ var FILL_ATTR = "data-mbe-fill";
6655
6703
  var ATOM_ATTR = "data-atom";
6656
6704
  var LIST_START_ATTR = "data-list-start";
6657
6705
  var QUOTE_JOINED_ATTR = "data-quote-joined";
6706
+ var QUOTE_CONTINUED_ATTR = "data-quote-continued";
6658
6707
  var SECTION_HIDDEN_ATTR = "data-section-hidden";
6659
6708
  var SECTION_COLLAPSED_ATTR = "data-collapsed";
6660
6709
  var SECTION_INSIDE_ATTR = "data-in-section";
@@ -6678,7 +6727,7 @@ function blockClasses(block3, theme) {
6678
6727
  case "quote":
6679
6728
  return theme.blockquote;
6680
6729
  case "listItem":
6681
- return theme[`${block3.listType}List`];
6730
+ return block3.quote ? classes(theme[`${block3.listType}List`], theme.blockquote) || void 0 : theme[`${block3.listType}List`];
6682
6731
  case "code":
6683
6732
  return theme.codeBlock;
6684
6733
  case "table":
@@ -6725,19 +6774,23 @@ function renderCallout(block3, type, ctx, reveal) {
6725
6774
  const root = doc.createElement("blockquote");
6726
6775
  root.dir = "auto";
6727
6776
  root.dataset.callout = type;
6728
- const name = calloutName(type);
6729
- const title = doc.createElement("div");
6730
- title.className = "mbe-callout-title";
6731
- title.contentEditable = "false";
6732
- const icon = ctx.icon?.(name);
6733
- if (icon) title.appendChild(icon);
6734
- title.appendChild(doc.createTextNode(ctx.labels[name]));
6735
6777
  const content = doc.createElement("div");
6736
6778
  content.className = "mbe-content";
6737
6779
  fillContent(content, block3.content, ctx, block3, reveal);
6738
- root.append(title, content);
6780
+ root.append(calloutIcon(type, ctx), content);
6739
6781
  return root;
6740
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
+ }
6741
6794
  function renderBlock(block3, ctx, reveal) {
6742
6795
  const { doc, labels } = ctx;
6743
6796
  const el = (tag, className2) => {
@@ -6760,7 +6813,11 @@ function renderBlock(block3, ctx, reveal) {
6760
6813
  if (block3.type === "paragraph") markImageBlock(root, block3);
6761
6814
  break;
6762
6815
  case "listItem": {
6763
- 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
+ }
6764
6821
  root.dir = "auto";
6765
6822
  root.dataset.listType = block3.listType;
6766
6823
  root.dataset.indent = String(block3.indent);
@@ -6809,7 +6866,8 @@ function renderBlock(block3, ctx, reveal) {
6809
6866
  case "raw": {
6810
6867
  const source = inlineText(block3.content);
6811
6868
  const section = block3.syntax === "html" && !reveal?.has(REVEAL_BLOCK) && ctx.views?.has("html") ? splitHtmlSection(source, ctx.markdown) : null;
6812
- 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");
6813
6871
  if (view) {
6814
6872
  root = view;
6815
6873
  root.classList.add("mbe-view-block");
@@ -6947,6 +7005,11 @@ function fillSlots(root, count, content, doc) {
6947
7005
  function renderFlow(blocks, ctx) {
6948
7006
  const flow = ctx.doc.createElement("div");
6949
7007
  flow.className = "mbe-flow";
7008
+ appendBlocks(flow, blocks, ctx);
7009
+ makeInert(flow);
7010
+ return flow;
7011
+ }
7012
+ function appendBlocks(flow, blocks, ctx) {
6950
7013
  const elements = /* @__PURE__ */ new Map();
6951
7014
  for (const block3 of blocks) {
6952
7015
  const el = renderBlock(block3, ctx);
@@ -6954,6 +7017,73 @@ function renderFlow(blocks, ctx) {
6954
7017
  flow.appendChild(el);
6955
7018
  }
6956
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) {
6957
7087
  for (const el of Array.from(flow.querySelectorAll(`[${BLOCK_ATTR}], [${CONTENT_ATTR}], [contenteditable], [data-row]`))) {
6958
7088
  el.removeAttribute(BLOCK_ATTR);
6959
7089
  el.removeAttribute(CONTENT_ATTR);
@@ -6966,7 +7096,6 @@ function renderFlow(blocks, ctx) {
6966
7096
  else input.readOnly = true;
6967
7097
  input.tabIndex = -1;
6968
7098
  }
6969
- return flow;
6970
7099
  }
6971
7100
  function fill(doc) {
6972
7101
  const br = doc.createElement("br");
@@ -7402,13 +7531,18 @@ function updateNeighborMarks(doc, elementFor, written, collapsed, labels) {
7402
7531
  if (block3.type === "detailsEnd") sections2.pop();
7403
7532
  if (el) markSection(el, sections2.length, sections2.includes(true), block3.type === "details" ? collapsed.has(block3.id) : null, labels);
7404
7533
  if (block3.type === "details") sections2.push(collapsed.has(block3.id));
7405
- if (block3.type === "quote") setFlag(el, QUOTE_JOINED_ATTR, before?.type === "quote" && before.callout === block3.callout);
7406
- if (block3.type !== "listItem") {
7407
- counters.length = 0;
7408
- return;
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]));
7409
7537
  }
7538
+ if (block3.type !== "listItem" || before?.type !== "listItem" || quoteKind(before) !== quoteKind(block3)) counters.length = 0;
7539
+ if (block3.type !== "listItem") return;
7410
7540
  const ordered = block3.listType === "ordered";
7411
- 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
+ );
7412
7546
  counters.length = block3.indent + 1;
7413
7547
  if (!ordered) {
7414
7548
  counters[block3.indent] = void 0;
@@ -7613,11 +7747,13 @@ var BlockHandle = class {
7613
7747
  this.el.hidden = false;
7614
7748
  const offset = attach(this.el, this.editor.root);
7615
7749
  const rect = blockEl.getBoundingClientRect();
7750
+ const icon = blockEl.querySelector(":scope > .mbe-callout-icon");
7751
+ const iconRect = icon?.getBoundingClientRect();
7616
7752
  const lineHeight = parseFloat(doc.defaultView.getComputedStyle(blockEl).lineHeight) || 24;
7617
- 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;
7618
7754
  const size = this.el.offsetHeight || 22;
7619
7755
  this.el.style.left = `${Math.round(rect.left - (this.el.offsetWidth || 20) - 6 - offset.x)}px`;
7620
- 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`;
7621
7757
  }
7622
7758
  /** True when `node` is the block handle or inside it. */
7623
7759
  contains(node) {
@@ -8050,7 +8186,7 @@ function sameRevealed(a, b) {
8050
8186
  }
8051
8187
  function viewEntry(block3, forward) {
8052
8188
  const text = inlineText(block3.content);
8053
- 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 };
8054
8190
  if (forward) {
8055
8191
  const firstBreak = text.indexOf("\n");
8056
8192
  return { blockId: block3.id, offset: firstBreak >= 0 && firstBreak < text.length - 1 ? firstBreak + 1 : 0 };
@@ -8321,8 +8457,7 @@ var Editor = class {
8321
8457
  const els = this.widgets.filter((w) => w.blockId === blockId).map((w) => w.element);
8322
8458
  return els.length ? els : void 0;
8323
8459
  };
8324
- const views = new Map(this.extensions.flatMap((e) => Object.entries(e.views ?? {})));
8325
- 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 ?? {}))]);
8326
8461
  this.renderer.markdown = this.markdown;
8327
8462
  this.renderer.onViewSettled = (ids) => this.viewsSettled(ids);
8328
8463
  const codeDecorators = this.extensions.flatMap((e) => e.codeDecorations ? [e.codeDecorations] : []);
@@ -8495,7 +8630,7 @@ var Editor = class {
8495
8630
  }
8496
8631
  }
8497
8632
  const block3 = getBlock(s.doc, s.selection.focus.blockId);
8498
- if (blockName(block3) !== name) return false;
8633
+ if (blockName(block3) !== name && !(name === "blockquote" && quoteKind(block3))) return false;
8499
8634
  if (!attrs) return true;
8500
8635
  const actual = this.getAttributes(name);
8501
8636
  return Object.entries(attrs).every(([k, v]) => actual[k] === v);
@@ -8512,6 +8647,8 @@ var Editor = class {
8512
8647
  return selected ? { ...selected.image, block: selectedImageBlock(s) !== null } : {};
8513
8648
  }
8514
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 };
8515
8652
  if (blockName(block3) !== name) return {};
8516
8653
  switch (block3.type) {
8517
8654
  case "heading":
@@ -9828,11 +9965,11 @@ var Editor = class {
9828
9965
  e.preventDefault();
9829
9966
  return;
9830
9967
  }
9831
- const title = e.button === 0 && !this.readOnly ? target.closest?.(".mbe-callout-title") : null;
9832
- const titleBlock = title?.parentElement?.getAttribute(BLOCK_ATTR);
9833
- if (title && titleBlock && title.parentElement.parentElement === this.root) {
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) {
9834
9971
  e.preventDefault();
9835
- this.openBlockMenu(titleBlock, title.getBoundingClientRect());
9972
+ this.openBlockMenu(iconBlock, icon.getBoundingClientRect());
9836
9973
  return;
9837
9974
  }
9838
9975
  if (e.button === 0) this.pointerDown = true;
@@ -10264,8 +10401,9 @@ var Editor = class {
10264
10401
  })));
10265
10402
  sections2.push({ title: this.labels.tableSection, items });
10266
10403
  }
10267
- if (block3.type === "quote" && block3.callout) {
10268
- const current = block3.callout;
10404
+ const kind = quoteKind(block3);
10405
+ if (kind && kind !== "quote") {
10406
+ const current = kind;
10269
10407
  const items = CALLOUT_TYPES.map((type) => {
10270
10408
  const name = calloutName(type);
10271
10409
  return {
@@ -10345,12 +10483,12 @@ var Editor = class {
10345
10483
  */
10346
10484
  hasBlockMenu(blockId) {
10347
10485
  const block3 = this.state.doc.blocks.find((b) => b.id === blockId);
10348
- return block3?.type === "table" || block3?.type === "code" || block3?.type === "quote" && !!block3.callout || !!block3 && isImageBlock(block3);
10486
+ return block3?.type === "table" || block3?.type === "code" || isCallout(block3) || !!block3 && isImageBlock(block3);
10349
10487
  }
10350
10488
  /**
10351
10489
  * @internal
10352
10490
  * The block whose block menu `blockId` belongs to, or null when it has none:
10353
- * the first block of a callout, so the handle sits by its title; otherwise
10491
+ * the first block of a callout, so the handle sits by its icon; otherwise
10354
10492
  * the block itself.
10355
10493
  */
10356
10494
  blockMenuOwner(blockId) {
@@ -10384,7 +10522,7 @@ var Editor = class {
10384
10522
  /** True if the blocks `a` and `b` are in the same callout. */
10385
10523
  inSameCallout(a, b) {
10386
10524
  const block3 = getBlock(this.state.doc, b);
10387
- const run = block3.type === "quote" && block3.callout ? quoteRun(this.state, b) : null;
10525
+ const run = isCallout(block3) ? quoteRun(this.state, b) : null;
10388
10526
  if (!run) return false;
10389
10527
  const i = blockIndex(this.state.doc, a);
10390
10528
  return i >= run.start && i <= run.end;
@@ -10677,6 +10815,10 @@ var Editor = class {
10677
10815
  this.cleanup.push(() => target.removeEventListener(type, fn, capture));
10678
10816
  }
10679
10817
  };
10818
+ function isCallout(block3) {
10819
+ const kind = quoteKind(block3);
10820
+ return kind !== null && kind !== "quote";
10821
+ }
10680
10822
  function blockName(block3) {
10681
10823
  switch (block3.type) {
10682
10824
  case "listItem":
@@ -11080,11 +11222,13 @@ export {
11080
11222
  parseMarkdown,
11081
11223
  plain,
11082
11224
  quote,
11225
+ quoteKind,
11083
11226
  rangeHasMark,
11084
11227
  rawBlock,
11085
11228
  sameCell,
11086
11229
  sameMarks,
11087
11230
  samePosition,
11231
+ sameQuote,
11088
11232
  scanMentions,
11089
11233
  scanTags,
11090
11234
  serializeInline,
@@ -11101,8 +11245,10 @@ export {
11101
11245
  textDecorator,
11102
11246
  toPlain,
11103
11247
  tokensAt,
11248
+ unquote,
11104
11249
  withContainerContent,
11105
- withContent
11250
+ withContent,
11251
+ withQuote
11106
11252
  };
11107
11253
  /*! Icons from Lucide (lucide-static 1.55.0), https://lucide.dev
11108
11254
  * ISC License. Copyright (c) 2026 Lucide Icons and Contributors.