@usememos/editor 26.10.13 → 26.10.14
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/README.md +57 -12
- package/dist/base.css +54 -2
- package/dist/emoji-data-WTFGY3MU.js +6 -0
- package/dist/emoji-data-WTFGY3MU.js.map +7 -0
- package/dist/emoji.js +74 -0
- package/dist/emoji.js.map +7 -0
- package/dist/index.js +942 -92
- package/dist/index.js.map +4 -4
- package/dist/react.js.map +2 -2
- package/dist/style.css +147 -4
- package/dist/theme.css +26 -2
- package/dist/types/commands.d.ts +48 -3
- package/dist/types/editor.d.ts +59 -3
- package/dist/types/emoji/data.d.ts +1 -0
- package/dist/types/emoji/index.d.ts +21 -0
- package/dist/types/emoji/search.d.ts +17 -0
- package/dist/types/icons.d.ts +39 -0
- package/dist/types/labels.d.ts +20 -0
- package/dist/types/markdown/blocks.d.ts +2 -0
- package/dist/types/markdown/htmlSection.d.ts +10 -1
- package/dist/types/markdown/inline.d.ts +2 -0
- package/dist/types/markdown/options.d.ts +14 -0
- package/dist/types/markdown/serialize.d.ts +8 -0
- package/dist/types/model.d.ts +42 -5
- package/dist/types/react/index.d.ts +1 -1
- package/dist/types/theme.d.ts +8 -0
- package/dist/types/ui/linkCard.d.ts +46 -0
- package/dist/types/view/dom.d.ts +7 -1
- package/package.json +5 -1
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() {
|
|
@@ -83,8 +92,9 @@ function listItem(listType, content = [], opts = {}) {
|
|
|
83
92
|
};
|
|
84
93
|
return listType === "ordered" && opts.start !== void 0 && opts.start !== 1 ? { ...block3, start: opts.start } : block3;
|
|
85
94
|
}
|
|
86
|
-
function quote(content = [], id = createId()) {
|
|
87
|
-
|
|
95
|
+
function quote(content = [], id = createId(), callout) {
|
|
96
|
+
const block3 = { id, type: "quote", content: normalizeInline(content) };
|
|
97
|
+
return callout ? { ...block3, callout } : block3;
|
|
88
98
|
}
|
|
89
99
|
function codeBlock(language = "", text = "", id = createId()) {
|
|
90
100
|
return { id, type: "code", language, content: plain(text) };
|
|
@@ -113,14 +123,23 @@ function emptyTable(rows = 3, cols = 3, id = createId()) {
|
|
|
113
123
|
function divider(id = createId()) {
|
|
114
124
|
return { id, type: "divider" };
|
|
115
125
|
}
|
|
126
|
+
function details(content = [], opts = {}) {
|
|
127
|
+
return { id: opts.id ?? createId(), type: "details", open: opts.open ?? false, content: toPlain(content) };
|
|
128
|
+
}
|
|
129
|
+
function detailsEnd(id = createId()) {
|
|
130
|
+
return { id, type: "detailsEnd" };
|
|
131
|
+
}
|
|
116
132
|
function plain(text) {
|
|
117
133
|
return text ? [{ text, marks: [] }] : [];
|
|
118
134
|
}
|
|
119
135
|
function isTextBlock(block3) {
|
|
120
|
-
return block3.type !== "table" && block3.type !== "divider";
|
|
136
|
+
return block3.type !== "table" && block3.type !== "divider" && block3.type !== "detailsEnd";
|
|
137
|
+
}
|
|
138
|
+
function isTextless(block3) {
|
|
139
|
+
return block3.type === "divider" || block3.type === "detailsEnd";
|
|
121
140
|
}
|
|
122
141
|
function isPlainTextBlock(block3) {
|
|
123
|
-
return block3.type === "code" || block3.type === "raw";
|
|
142
|
+
return block3.type === "code" || block3.type === "raw" || block3.type === "details";
|
|
124
143
|
}
|
|
125
144
|
function imageBlockOffset(block3) {
|
|
126
145
|
if (block3.type !== "paragraph") return null;
|
|
@@ -145,7 +164,7 @@ function containerContent(block3, cell) {
|
|
|
145
164
|
if (!cell) return null;
|
|
146
165
|
return block3.rows[cell.row]?.[cell.col] ?? null;
|
|
147
166
|
}
|
|
148
|
-
if (block3
|
|
167
|
+
if (isTextless(block3)) return null;
|
|
149
168
|
return block3.content;
|
|
150
169
|
}
|
|
151
170
|
function withContainerContent(block3, cell, content) {
|
|
@@ -156,7 +175,7 @@ function withContainerContent(block3, cell, content) {
|
|
|
156
175
|
);
|
|
157
176
|
return { ...block3, rows };
|
|
158
177
|
}
|
|
159
|
-
if (block3
|
|
178
|
+
if (isTextless(block3)) return block3;
|
|
160
179
|
return withContent(block3, content);
|
|
161
180
|
}
|
|
162
181
|
function withContent(block3, content) {
|
|
@@ -333,7 +352,7 @@ function endOf(block3) {
|
|
|
333
352
|
const col = block3.align.length - 1;
|
|
334
353
|
return { blockId: block3.id, offset: inlineLength(block3.rows[row][col]), cell: { row, col } };
|
|
335
354
|
}
|
|
336
|
-
if (block3
|
|
355
|
+
if (isTextless(block3)) return { blockId: block3.id, offset: 0 };
|
|
337
356
|
return { blockId: block3.id, offset: inlineLength(block3.content) };
|
|
338
357
|
}
|
|
339
358
|
function clampSelection(doc, sel) {
|
|
@@ -515,7 +534,7 @@ function emptyLike(block3) {
|
|
|
515
534
|
case "listItem":
|
|
516
535
|
return listItem(block3.listType, [], { indent: block3.indent });
|
|
517
536
|
case "quote":
|
|
518
|
-
return quote();
|
|
537
|
+
return quote([], void 0, block3.callout);
|
|
519
538
|
default:
|
|
520
539
|
return paragraph();
|
|
521
540
|
}
|
|
@@ -526,7 +545,7 @@ function deleteRange(state, from, to) {
|
|
|
526
545
|
const fromBlock = state.doc.blocks[fromIndex];
|
|
527
546
|
const toBlock = state.doc.blocks[toIndex];
|
|
528
547
|
if (fromIndex === toIndex) {
|
|
529
|
-
if (fromBlock
|
|
548
|
+
if (isTextless(fromBlock)) return state;
|
|
530
549
|
if (fromBlock.type === "table") return deleteInTable(state, fromBlock, from, to);
|
|
531
550
|
const content = deleteInline(fromBlock.content, from.offset, to.offset);
|
|
532
551
|
return replaceBlock(state, withContent(fromBlock, content), caret(from.blockId, from.offset));
|
|
@@ -595,7 +614,7 @@ function deleteBackward(state) {
|
|
|
595
614
|
const pos = state.selection.focus;
|
|
596
615
|
const index = blockIndex(state.doc, pos.blockId);
|
|
597
616
|
const block3 = state.doc.blocks[index];
|
|
598
|
-
if (block3
|
|
617
|
+
if (isTextless(block3)) return removeBlockAt(state, index, -1);
|
|
599
618
|
if (pos.offset > 0) {
|
|
600
619
|
const text = inlineText(contentOf(block3, pos.cell));
|
|
601
620
|
const from = previousGrapheme(text, pos.offset);
|
|
@@ -611,6 +630,12 @@ function deleteBackward(state) {
|
|
|
611
630
|
if (block3.type !== "paragraph") return replaceBlock(state, paragraph(block3.content, block3.id));
|
|
612
631
|
const prev = state.doc.blocks[index - 1];
|
|
613
632
|
if (!prev) return state;
|
|
633
|
+
if (prev.type === "detailsEnd") {
|
|
634
|
+
const end = lastTextBefore(state.doc.blocks, index);
|
|
635
|
+
if (!end) return state;
|
|
636
|
+
const selection = { anchor: end, focus: end };
|
|
637
|
+
return inlineLength(block3.content) === 0 ? withBlocks(state, splice(state, index, 1), selection) : { ...state, selection, storedMarks: null };
|
|
638
|
+
}
|
|
614
639
|
if (prev.type === "divider") return withBlocks(state, splice(state, index - 1, 1));
|
|
615
640
|
const prevImage = imageBlockOffset(prev);
|
|
616
641
|
if (prevImage !== null) {
|
|
@@ -632,14 +657,17 @@ function deleteForward(state) {
|
|
|
632
657
|
const pos = state.selection.focus;
|
|
633
658
|
const index = blockIndex(state.doc, pos.blockId);
|
|
634
659
|
const block3 = state.doc.blocks[index];
|
|
635
|
-
if (block3
|
|
660
|
+
if (isTextless(block3)) return removeBlockAt(state, index, 1);
|
|
636
661
|
const text = inlineText(contentOf(block3, pos.cell));
|
|
637
662
|
if (pos.offset < text.length) {
|
|
638
663
|
return deleteRange(state, pos, { ...pos, offset: nextGrapheme(text, pos.offset) });
|
|
639
664
|
}
|
|
640
665
|
if (block3.type === "table") return state;
|
|
641
666
|
const next = state.doc.blocks[index + 1];
|
|
642
|
-
if (!next || next.type === "table") return state;
|
|
667
|
+
if (!next || next.type === "table" || next.type === "detailsEnd") return state;
|
|
668
|
+
if (next.type === "details") {
|
|
669
|
+
return inlineLength(contentOf(block3)) === 0 ? removeBlockAt(state, index, 1) : state;
|
|
670
|
+
}
|
|
643
671
|
if (next.type === "divider") return withBlocks(state, splice(state, index + 1, 1));
|
|
644
672
|
const nextImage = imageBlockOffset(next);
|
|
645
673
|
if (nextImage !== null) {
|
|
@@ -648,6 +676,10 @@ function deleteForward(state) {
|
|
|
648
676
|
}
|
|
649
677
|
return deleteRange(state, pos, { blockId: next.id, offset: 0 });
|
|
650
678
|
}
|
|
679
|
+
function lastTextBefore(blocks, index) {
|
|
680
|
+
for (let i = index - 1; i >= 0; i--) if (!isTextless(blocks[i])) return endOf(blocks[i]);
|
|
681
|
+
return null;
|
|
682
|
+
}
|
|
651
683
|
function removeBlockAt(state, index, prefer) {
|
|
652
684
|
const blocks = splice(state, index, 1);
|
|
653
685
|
if (blocks.length === 0) {
|
|
@@ -668,7 +700,7 @@ function insertText(state, text) {
|
|
|
668
700
|
const content = containerContent(block3, pos.cell);
|
|
669
701
|
if (content === null) return state;
|
|
670
702
|
let value = text;
|
|
671
|
-
if (block3.type === "table") value = value.replace(/\r?\n/g, " ");
|
|
703
|
+
if (block3.type === "table" || block3.type === "details") value = value.replace(/\r?\n/g, " ");
|
|
672
704
|
const format = isPlainTextBlock(block3) ? { marks: [] } : stored ? { marks: stored } : formatAt(content, pos.offset);
|
|
673
705
|
const next = insertInline(content, pos.offset, value, format);
|
|
674
706
|
return replaceBlock(s, withContainerContent(block3, pos.cell, next), caret(block3.id, pos.offset + value.length, pos.cell));
|
|
@@ -692,9 +724,13 @@ function exitBlock(state, dir) {
|
|
|
692
724
|
const p = paragraph();
|
|
693
725
|
return withBlocks(state, splice(state, dir === 1 ? index + 1 : 0, 0, p), caret(p.id, 0));
|
|
694
726
|
}
|
|
727
|
+
function appendParagraph(state) {
|
|
728
|
+
const p = paragraph();
|
|
729
|
+
return withBlocks(state, [...state.doc.blocks, p], caret(p.id, 0));
|
|
730
|
+
}
|
|
695
731
|
function insertLineBreak(state) {
|
|
696
732
|
const block3 = getBlock(state.doc, state.selection.focus.blockId);
|
|
697
|
-
if (block3.type === "table" || block3.type === "
|
|
733
|
+
if (block3.type === "table" || isTextless(block3) || block3.type === "details") return state;
|
|
698
734
|
return insertText(state, "\n");
|
|
699
735
|
}
|
|
700
736
|
function splitBlock(state) {
|
|
@@ -702,11 +738,12 @@ function splitBlock(state) {
|
|
|
702
738
|
const pos = s.selection.focus;
|
|
703
739
|
const index = blockIndex(s.doc, pos.blockId);
|
|
704
740
|
const block3 = s.doc.blocks[index];
|
|
705
|
-
if (block3
|
|
741
|
+
if (isTextless(block3)) {
|
|
706
742
|
const p = paragraph();
|
|
707
743
|
return withBlocks(s, splice(s, index + 1, 0, p), caret(p.id, 0));
|
|
708
744
|
}
|
|
709
745
|
if (block3.type === "table") return tableEnter(s, block3, pos);
|
|
746
|
+
if (block3.type === "details") return detailsEnter(s, block3, index, pos.offset);
|
|
710
747
|
const text = inlineText(block3.content);
|
|
711
748
|
const length = text.length;
|
|
712
749
|
if (isPlainTextBlock(block3)) {
|
|
@@ -727,6 +764,12 @@ function splitBlock(state) {
|
|
|
727
764
|
return replaceBlock(s, next);
|
|
728
765
|
}
|
|
729
766
|
if (length === 0 && block3.type === "quote") return replaceBlock(s, paragraph([], block3.id));
|
|
767
|
+
if (length === 0 && block3.type === "paragraph" && s.doc.blocks[index + 1]?.type === "detailsEnd") {
|
|
768
|
+
const blocks = s.doc.blocks.slice();
|
|
769
|
+
blocks.splice(index, 1);
|
|
770
|
+
blocks.splice(index + 1, 0, block3);
|
|
771
|
+
return withBlocks(s, blocks, s.selection);
|
|
772
|
+
}
|
|
730
773
|
if (pos.offset === 0 && length > 0) {
|
|
731
774
|
return withBlocks(s, splice(s, index, 0, emptyLike(block3)), s.selection);
|
|
732
775
|
}
|
|
@@ -740,6 +783,76 @@ function splitBlock(state) {
|
|
|
740
783
|
}
|
|
741
784
|
return withBlocks(s, splice(s, index, 1, left, right), caret(right.id, 0));
|
|
742
785
|
}
|
|
786
|
+
function detailsEnter(state, block3, index, offset, collapsed = false) {
|
|
787
|
+
const length = inlineLength(block3.content);
|
|
788
|
+
if (offset === 0 && length > 0) return withBlocks(state, splice(state, index, 0, paragraph()), state.selection);
|
|
789
|
+
const first = state.doc.blocks[index + 1];
|
|
790
|
+
if (!collapsed && offset === length && first?.type === "paragraph" && inlineLength(first.content) === 0) {
|
|
791
|
+
return { ...state, selection: caret(first.id, 0), storedMarks: null };
|
|
792
|
+
}
|
|
793
|
+
const left = withContent(block3, sliceInline(block3.content, 0, offset));
|
|
794
|
+
const right = paragraph(sliceInline(block3.content, offset));
|
|
795
|
+
const blocks = state.doc.blocks.slice();
|
|
796
|
+
blocks[index] = left;
|
|
797
|
+
blocks.splice(collapsed ? (sectionEnd(blocks, index) ?? index) + 1 : index + 1, 0, right);
|
|
798
|
+
return withBlocks(state, blocks, caret(right.id, 0));
|
|
799
|
+
}
|
|
800
|
+
function splitCollapsedTitle(state) {
|
|
801
|
+
const s = deleteSelection(state);
|
|
802
|
+
const pos = s.selection.focus;
|
|
803
|
+
const index = blockIndex(s.doc, pos.blockId);
|
|
804
|
+
const block3 = s.doc.blocks[index];
|
|
805
|
+
return block3.type === "details" ? detailsEnter(s, block3, index, pos.offset, true) : splitBlock(state);
|
|
806
|
+
}
|
|
807
|
+
function sectionEnd(blocks, index) {
|
|
808
|
+
let depth = 0;
|
|
809
|
+
for (let i = index; i < blocks.length; i++) {
|
|
810
|
+
const type = blocks[i].type;
|
|
811
|
+
if (type === "details") depth++;
|
|
812
|
+
else if (type === "detailsEnd" && --depth === 0) return i;
|
|
813
|
+
}
|
|
814
|
+
return null;
|
|
815
|
+
}
|
|
816
|
+
function sectionTitle(blocks, index) {
|
|
817
|
+
let depth = 0;
|
|
818
|
+
for (let i = index; i >= 0; i--) {
|
|
819
|
+
const type = blocks[i].type;
|
|
820
|
+
if (type === "detailsEnd") depth++;
|
|
821
|
+
else if (type === "details" && --depth === 0) return i;
|
|
822
|
+
}
|
|
823
|
+
return null;
|
|
824
|
+
}
|
|
825
|
+
function closeSections(blocks) {
|
|
826
|
+
if (!blocks.some((b) => b.type === "details" || b.type === "detailsEnd")) return blocks;
|
|
827
|
+
const open = [];
|
|
828
|
+
const drop = /* @__PURE__ */ new Set();
|
|
829
|
+
blocks.forEach((b, i) => {
|
|
830
|
+
if (b.type === "details") open.push(i);
|
|
831
|
+
else if (b.type === "detailsEnd" && open.pop() === void 0) drop.add(i);
|
|
832
|
+
});
|
|
833
|
+
if (drop.size === 0 && open.length === 0) return blocks;
|
|
834
|
+
const unclosed = new Set(open);
|
|
835
|
+
const out = [];
|
|
836
|
+
blocks.forEach((b, i) => {
|
|
837
|
+
if (drop.has(i)) return;
|
|
838
|
+
out.push(unclosed.has(i) && b.type === "details" ? paragraph(b.content, b.id) : b);
|
|
839
|
+
});
|
|
840
|
+
return out.length > 0 ? out : [paragraph()];
|
|
841
|
+
}
|
|
842
|
+
function balanceSections(state) {
|
|
843
|
+
if (!state.doc.blocks.some((b) => b.type === "details" || b.type === "detailsEnd")) return state;
|
|
844
|
+
const blocks = closeSections(state.doc.blocks);
|
|
845
|
+
let next = state;
|
|
846
|
+
if (blocks !== state.doc.blocks) {
|
|
847
|
+
const doc = { blocks };
|
|
848
|
+
next = { ...state, doc, selection: clampSelection(doc, state.selection) };
|
|
849
|
+
}
|
|
850
|
+
const onEnd = (p) => next.doc.blocks.find((b) => b.id === p.blockId)?.type === "detailsEnd";
|
|
851
|
+
const { anchor, focus } = next.selection;
|
|
852
|
+
if (!onEnd(anchor) && !onEnd(focus)) return next;
|
|
853
|
+
const move = (p) => onEnd(p) ? lastTextBefore(next.doc.blocks, blockIndex(next.doc, p.blockId)) ?? p : p;
|
|
854
|
+
return { ...next, selection: { anchor: move(anchor), focus: move(focus) } };
|
|
855
|
+
}
|
|
743
856
|
function tableEnter(state, block3, pos) {
|
|
744
857
|
const cell = pos.cell;
|
|
745
858
|
let table2 = block3;
|
|
@@ -751,7 +864,7 @@ function mapTextInRange(state, from, to, fn) {
|
|
|
751
864
|
const start = blockIndex(state.doc, from.blockId);
|
|
752
865
|
const end = blockIndex(state.doc, to.blockId);
|
|
753
866
|
const updated = state.doc.blocks.slice(start, end + 1).map((block3) => {
|
|
754
|
-
if (block3
|
|
867
|
+
if (isTextless(block3) || isPlainTextBlock(block3)) return block3;
|
|
755
868
|
if (block3.type === "table") {
|
|
756
869
|
const cols = block3.align.length;
|
|
757
870
|
const fromIdx = block3.id === from.blockId && from.cell ? from.cell.row * cols + from.cell.col : 0;
|
|
@@ -900,7 +1013,7 @@ function convert(block3, spec) {
|
|
|
900
1013
|
checked: block3.type === "listItem" ? block3.checked : false
|
|
901
1014
|
});
|
|
902
1015
|
case "quote":
|
|
903
|
-
return quote(content, block3.id);
|
|
1016
|
+
return quote(content, block3.id, spec.callout);
|
|
904
1017
|
case "code":
|
|
905
1018
|
return codeBlock(spec.language ?? (block3.type === "code" ? block3.language : ""), inlineText(toPlain(content)), block3.id);
|
|
906
1019
|
default:
|
|
@@ -911,7 +1024,7 @@ function isConvertible(block3) {
|
|
|
911
1024
|
return isTextBlock(block3) && block3.type !== "raw";
|
|
912
1025
|
}
|
|
913
1026
|
function setBlockType(state, spec) {
|
|
914
|
-
if (spec.type === "table" || spec.type === "divider") return insertBlock(state, spec);
|
|
1027
|
+
if (spec.type === "table" || spec.type === "divider" || spec.type === "details") return insertBlock(state, spec);
|
|
915
1028
|
const { from, to } = orderedRange(state.doc, state.selection);
|
|
916
1029
|
const start = blockIndex(state.doc, from.blockId);
|
|
917
1030
|
const end = blockIndex(state.doc, to.blockId);
|
|
@@ -945,6 +1058,27 @@ function mergeIntoCode(state, start, range, language) {
|
|
|
945
1058
|
const selection = { anchor: startOf(merged[0]), focus: endOf(merged[merged.length - 1]) };
|
|
946
1059
|
return { doc: { blocks: splice(state, start, range.length, ...out) }, selection, storedMarks: null };
|
|
947
1060
|
}
|
|
1061
|
+
function quoteRun(state, blockId) {
|
|
1062
|
+
const blocks = state.doc.blocks;
|
|
1063
|
+
const index = blockIndex(state.doc, blockId);
|
|
1064
|
+
const block3 = blocks[index];
|
|
1065
|
+
if (block3?.type !== "quote") return null;
|
|
1066
|
+
const same = (b) => b?.type === "quote" && b.callout === block3.callout;
|
|
1067
|
+
let start = index;
|
|
1068
|
+
let end = index;
|
|
1069
|
+
while (same(blocks[start - 1])) start--;
|
|
1070
|
+
while (same(blocks[end + 1])) end++;
|
|
1071
|
+
return { start, end };
|
|
1072
|
+
}
|
|
1073
|
+
function setCallout(state, blockId, callout) {
|
|
1074
|
+
const run = quoteRun(state, blockId);
|
|
1075
|
+
if (!run) return state;
|
|
1076
|
+
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));
|
|
1079
|
+
const doc = { blocks: splice(state, run.start, updated.length, ...updated) };
|
|
1080
|
+
return { doc, selection: state.selection, storedMarks: state.storedMarks };
|
|
1081
|
+
}
|
|
948
1082
|
function convertibleBlocks(state) {
|
|
949
1083
|
const { from, to } = orderedRange(state.doc, state.selection);
|
|
950
1084
|
return state.doc.blocks.slice(blockIndex(state.doc, from.blockId), blockIndex(state.doc, to.blockId) + 1).filter(isConvertible);
|
|
@@ -957,6 +1091,8 @@ function hasType(block3, spec) {
|
|
|
957
1091
|
return block3.type === "listItem" && block3.listType === spec.listType;
|
|
958
1092
|
case "code":
|
|
959
1093
|
return block3.type === "code";
|
|
1094
|
+
case "quote":
|
|
1095
|
+
return block3.type === "quote" && (!spec.callout || block3.callout === spec.callout);
|
|
960
1096
|
default:
|
|
961
1097
|
return block3.type === spec.type;
|
|
962
1098
|
}
|
|
@@ -971,6 +1107,7 @@ function insertBlock(state, spec) {
|
|
|
971
1107
|
const pos = state.selection.focus;
|
|
972
1108
|
const index = blockIndex(state.doc, pos.blockId);
|
|
973
1109
|
const current = state.doc.blocks[index];
|
|
1110
|
+
if (spec.type === "details") return insertSection(state, index);
|
|
974
1111
|
if (spec.type !== "table" && spec.type !== "divider") return setBlockType(state, spec);
|
|
975
1112
|
const isEmpty = isTextBlock(current) && inlineLength(current.content) === 0;
|
|
976
1113
|
const created = spec.type === "table" ? emptyTable(spec.rows ?? 3, spec.cols ?? 3) : divider();
|
|
@@ -988,6 +1125,16 @@ function insertBlock(state, spec) {
|
|
|
988
1125
|
const at = isEmpty ? index : index + 1;
|
|
989
1126
|
return withBlocks(state, splice(state, at, isEmpty ? 1 : 0, ...blocks), { anchor: start, focus: start });
|
|
990
1127
|
}
|
|
1128
|
+
function insertSection(state, index) {
|
|
1129
|
+
const current = state.doc.blocks[index];
|
|
1130
|
+
const convert2 = isConvertible(current) && current.type !== "details";
|
|
1131
|
+
const title = details(convert2 ? current.content : [], convert2 ? { id: current.id } : {});
|
|
1132
|
+
const body = paragraph();
|
|
1133
|
+
const at = convert2 ? index : index + 1;
|
|
1134
|
+
const blocks = splice(state, at, convert2 ? 1 : 0, title, body, detailsEnd());
|
|
1135
|
+
const target = inlineLength(title.content) === 0 ? caret(title.id, 0) : caret(body.id, 0);
|
|
1136
|
+
return withBlocks(state, blocks, target);
|
|
1137
|
+
}
|
|
991
1138
|
function indentListItems(state, delta2) {
|
|
992
1139
|
const { from, to } = orderedRange(state.doc, state.selection);
|
|
993
1140
|
const start = blockIndex(state.doc, from.blockId);
|
|
@@ -1187,9 +1334,11 @@ var BLOCK_RULES = [
|
|
|
1187
1334
|
[/^\d{1,9}[.)] $/, () => ({ type: "listItem", listType: "ordered" })],
|
|
1188
1335
|
[/^\[[ xX]?\] $/, () => ({ type: "listItem", listType: "task" })],
|
|
1189
1336
|
[/^> $/, () => ({ type: "quote" })],
|
|
1190
|
-
[
|
|
1337
|
+
[new RegExp(`^\\[!(${CALLOUT_TYPES.join("|")})\\] $`, "i"), (m) => ({ type: "quote", callout: m[1].toLowerCase() })],
|
|
1338
|
+
[/^```([^`\s]*) $/, (m) => ({ type: "code", language: m[1] })],
|
|
1339
|
+
[/^>>> $/, () => ({ type: "details" })]
|
|
1191
1340
|
];
|
|
1192
|
-
function applyBlockInputRules(state) {
|
|
1341
|
+
function applyBlockInputRules(state, dialect = {}) {
|
|
1193
1342
|
if (!isCollapsed(state.selection)) return null;
|
|
1194
1343
|
const pos = state.selection.focus;
|
|
1195
1344
|
const block3 = getBlock(state.doc, pos.blockId);
|
|
@@ -1200,13 +1349,18 @@ function applyBlockInputRules(state) {
|
|
|
1200
1349
|
const rest = withContent(block3, sliceInline(block3.content, pos.offset));
|
|
1201
1350
|
return withBlocks(state, splice(state, index, 1, divider(), rest), caret(rest.id, 0));
|
|
1202
1351
|
}
|
|
1203
|
-
const allowed = block3.type === "paragraph" || block3.type === "listItem" && block3.listType === "bullet";
|
|
1352
|
+
const allowed = block3.type === "paragraph" || block3.type === "quote" || block3.type === "listItem" && block3.listType === "bullet";
|
|
1204
1353
|
if (!allowed) return null;
|
|
1205
1354
|
for (const [re, toSpec] of BLOCK_RULES) {
|
|
1206
1355
|
const m = re.exec(before);
|
|
1207
1356
|
if (!m) continue;
|
|
1208
1357
|
const spec = toSpec(m);
|
|
1358
|
+
if (spec.type === "quote" && spec.callout && dialect.callouts === false || spec.type === "details" && dialect.details === false) continue;
|
|
1209
1359
|
if (block3.type === "listItem" && !(spec.type === "listItem" && spec.listType === "task")) continue;
|
|
1360
|
+
if (block3.type === "quote") {
|
|
1361
|
+
if (spec.type !== "quote" || !spec.callout) continue;
|
|
1362
|
+
return setCallout(deleteRange(state, { blockId: block3.id, offset: 0 }, pos), block3.id, spec.callout);
|
|
1363
|
+
}
|
|
1210
1364
|
const stripped = deleteRange(state, { blockId: block3.id, offset: 0 }, pos);
|
|
1211
1365
|
let next = setBlockType(stripped, spec);
|
|
1212
1366
|
const converted = getBlock(next.doc, block3.id);
|
|
@@ -1509,12 +1663,10 @@ function docToHtml(doc) {
|
|
|
1509
1663
|
} else if (block3.type === "quote") {
|
|
1510
1664
|
let j = i;
|
|
1511
1665
|
let inner = "";
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
if (quote2.type === "quote") inner += `<p>${inlineHtml(quote2.content)}</p>`;
|
|
1515
|
-
j++;
|
|
1666
|
+
for (let next = blocks[j]; next?.type === "quote" && next.callout === block3.callout; next = blocks[++j]) {
|
|
1667
|
+
inner += `<p>${inlineHtml(next.content)}</p>`;
|
|
1516
1668
|
}
|
|
1517
|
-
out +=
|
|
1669
|
+
out += quoteHtml(block3.callout, inner);
|
|
1518
1670
|
i = j;
|
|
1519
1671
|
} else {
|
|
1520
1672
|
out += blockHtml(block3);
|
|
@@ -1540,6 +1692,11 @@ function blockHtml(block3) {
|
|
|
1540
1692
|
return block3.syntax === "html" ? inlineText(block3.content) : `<pre>${escapeHtml(inlineText(block3.content))}</pre>`;
|
|
1541
1693
|
case "divider":
|
|
1542
1694
|
return "<hr>";
|
|
1695
|
+
// The body's blocks come between, so the two parts make one element.
|
|
1696
|
+
case "details":
|
|
1697
|
+
return `<details${block3.open ? " open" : ""}><summary>${escapeHtml(inlineText(block3.content))}</summary>`;
|
|
1698
|
+
case "detailsEnd":
|
|
1699
|
+
return "</details>";
|
|
1543
1700
|
case "table": {
|
|
1544
1701
|
const cell = (tag, content, c) => {
|
|
1545
1702
|
const align = block3.align[c];
|
|
@@ -1554,9 +1711,14 @@ function blockHtml(block3) {
|
|
|
1554
1711
|
case "listItem":
|
|
1555
1712
|
return listHtml([block3]);
|
|
1556
1713
|
case "quote":
|
|
1557
|
-
return `<
|
|
1714
|
+
return quoteHtml(block3.callout, `<p>${inlineHtml(block3.content)}</p>`);
|
|
1558
1715
|
}
|
|
1559
1716
|
}
|
|
1717
|
+
function quoteHtml(callout, inner) {
|
|
1718
|
+
if (!callout) return `<blockquote>${inner}</blockquote>`;
|
|
1719
|
+
const title = callout[0].toUpperCase() + callout.slice(1);
|
|
1720
|
+
return `<blockquote class="markdown-alert markdown-alert-${callout}"><p class="markdown-alert-title"><strong>${title}</strong></p>${inner}</blockquote>`;
|
|
1721
|
+
}
|
|
1560
1722
|
function listHtml(items) {
|
|
1561
1723
|
let out = "";
|
|
1562
1724
|
const open = [];
|
|
@@ -1758,6 +1920,14 @@ function formatOf(el, parent) {
|
|
|
1758
1920
|
const sorted = sortMarks(marks);
|
|
1759
1921
|
return link === void 0 ? { marks: sorted, whiteSpace } : { marks: sorted, link, whiteSpace };
|
|
1760
1922
|
}
|
|
1923
|
+
function calloutOf(el) {
|
|
1924
|
+
const m = /(?:^|\s)markdown-alert-([a-z]+)(?:\s|$)/.exec(el.getAttribute("class") ?? "");
|
|
1925
|
+
const type = m?.[1];
|
|
1926
|
+
return type && CALLOUT_TYPES.includes(type) ? type : void 0;
|
|
1927
|
+
}
|
|
1928
|
+
function hasClass(el, name) {
|
|
1929
|
+
return (el.getAttribute("class") ?? "").split(/\s+/).includes(name);
|
|
1930
|
+
}
|
|
1761
1931
|
var Converter = class _Converter {
|
|
1762
1932
|
out = [];
|
|
1763
1933
|
spans = [];
|
|
@@ -1765,12 +1935,12 @@ var Converter = class _Converter {
|
|
|
1765
1935
|
this.flush();
|
|
1766
1936
|
return this.out;
|
|
1767
1937
|
}
|
|
1768
|
-
/** Converts the children of a block-level element. */
|
|
1769
|
-
blocks(parent, format) {
|
|
1938
|
+
/** Converts the children of a block-level element, except those `skip` names. */
|
|
1939
|
+
blocks(parent, format, skip) {
|
|
1770
1940
|
for (const node of Array.from(parent.childNodes)) {
|
|
1771
1941
|
if (node.nodeType === TEXT_NODE) {
|
|
1772
1942
|
this.text(node.nodeValue ?? "", format);
|
|
1773
|
-
} else if (node.nodeType === ELEMENT_NODE) {
|
|
1943
|
+
} else if (node.nodeType === ELEMENT_NODE && !skip?.(node)) {
|
|
1774
1944
|
this.element(node, format);
|
|
1775
1945
|
}
|
|
1776
1946
|
}
|
|
@@ -1789,7 +1959,15 @@ var Converter = class _Converter {
|
|
|
1789
1959
|
} else if (tag === "li") {
|
|
1790
1960
|
this.flush();
|
|
1791
1961
|
this.listItem(el, "bullet", 0, void 0, format);
|
|
1792
|
-
} else if (tag === "
|
|
1962
|
+
} else if (tag === "details") {
|
|
1963
|
+
this.flush();
|
|
1964
|
+
const summary = Array.from(el.children).find((c) => tagOf(c) === "summary");
|
|
1965
|
+
const title = (summary?.textContent ?? "").replace(/\s+/g, " ").trim();
|
|
1966
|
+
this.out.push(details(plain(title), { open: el.hasAttribute("open") }));
|
|
1967
|
+
this.blocks(el, format, (child) => child === summary);
|
|
1968
|
+
this.flush();
|
|
1969
|
+
this.out.push(detailsEnd());
|
|
1970
|
+
} else if (tag === "blockquote" || calloutOf(el)) {
|
|
1793
1971
|
this.flush();
|
|
1794
1972
|
this.blockquote(el, format);
|
|
1795
1973
|
} else if (tag === "pre") {
|
|
@@ -1974,21 +2152,24 @@ var Converter = class _Converter {
|
|
|
1974
2152
|
this.spans = saved;
|
|
1975
2153
|
}
|
|
1976
2154
|
// -- Quotes and tables ----------------------------------------------------
|
|
2155
|
+
/** A blockquote, or a callout as GitHub renders an alert (its title is dropped). */
|
|
1977
2156
|
blockquote(el, format) {
|
|
2157
|
+
const callout = calloutOf(el);
|
|
1978
2158
|
const inner = new _Converter();
|
|
1979
|
-
inner.blocks(el, format);
|
|
1980
|
-
|
|
2159
|
+
inner.blocks(el, format, callout ? (child) => hasClass(child, "markdown-alert-title") : void 0);
|
|
2160
|
+
const blocks = inner.finish();
|
|
2161
|
+
for (const block3 of blocks) {
|
|
1981
2162
|
switch (block3.type) {
|
|
1982
2163
|
case "paragraph":
|
|
1983
2164
|
case "heading":
|
|
1984
2165
|
case "quote":
|
|
1985
2166
|
case "code":
|
|
1986
2167
|
case "raw":
|
|
1987
|
-
this.out.push(quote(block3.content));
|
|
2168
|
+
this.out.push(quote(block3.content, void 0, callout));
|
|
1988
2169
|
break;
|
|
1989
2170
|
case "listItem": {
|
|
1990
2171
|
const marker = block3.listType === "ordered" ? "1. " : block3.listType === "task" ? block3.checked ? "- [x] " : "- [ ] " : "- ";
|
|
1991
|
-
this.out.push(quote([...plain(marker), ...block3.content]));
|
|
2172
|
+
this.out.push(quote([...plain(marker), ...block3.content], void 0, callout));
|
|
1992
2173
|
break;
|
|
1993
2174
|
}
|
|
1994
2175
|
default:
|
|
@@ -2113,13 +2294,29 @@ var DEFAULT_LABELS = {
|
|
|
2113
2294
|
heading1: "Heading 1",
|
|
2114
2295
|
heading2: "Heading 2",
|
|
2115
2296
|
heading3: "Heading 3",
|
|
2297
|
+
heading4: "Heading 4",
|
|
2116
2298
|
bulletList: "Bulleted list",
|
|
2117
2299
|
numberedList: "Numbered list",
|
|
2118
2300
|
todoList: "To-do list",
|
|
2119
2301
|
/** Accessible name of a task checkbox whose item has no text. */
|
|
2120
2302
|
task: "Task",
|
|
2121
2303
|
quote: "Quote",
|
|
2304
|
+
/** The slash menu item, and the title of a callout's block menu section. */
|
|
2305
|
+
callout: "Callout",
|
|
2306
|
+
/** Callout types: each callout's title, and its block menu items. */
|
|
2307
|
+
calloutNote: "Note",
|
|
2308
|
+
calloutTip: "Tip",
|
|
2309
|
+
calloutImportant: "Important",
|
|
2310
|
+
calloutWarning: "Warning",
|
|
2311
|
+
calloutCaution: "Caution",
|
|
2122
2312
|
code: "Code block",
|
|
2313
|
+
/** The slash menu item that makes a collapsible section. */
|
|
2314
|
+
details: "Collapsible section",
|
|
2315
|
+
/** Shown in an empty section title. */
|
|
2316
|
+
detailsHint: "Title",
|
|
2317
|
+
/** The toggle of a collapsible section. */
|
|
2318
|
+
expandSection: "Expand",
|
|
2319
|
+
collapseSection: "Collapse",
|
|
2123
2320
|
table: "Table",
|
|
2124
2321
|
divider: "Divider",
|
|
2125
2322
|
noResults: "No results",
|
|
@@ -2142,6 +2339,10 @@ var DEFAULT_LABELS = {
|
|
|
2142
2339
|
list: "List",
|
|
2143
2340
|
linkPlaceholder: "Paste or type a link\u2026",
|
|
2144
2341
|
removeLink: "Remove link",
|
|
2342
|
+
/** The link card's buttons. */
|
|
2343
|
+
openLink: "Open link",
|
|
2344
|
+
copyLink: "Copy link",
|
|
2345
|
+
editLink: "Edit link",
|
|
2145
2346
|
/** Shown in the empty paragraph that has the caret, with the `slashHint` option. */
|
|
2146
2347
|
slashHint: "Type '/' for commands",
|
|
2147
2348
|
blockHandle: "Open block menu",
|
|
@@ -2190,6 +2391,8 @@ var ICONS = {
|
|
|
2190
2391
|
heading2: ["M4 12h8", "M4 18V6", "M12 18V6", "M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1"],
|
|
2191
2392
|
/** `heading-3` */
|
|
2192
2393
|
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"],
|
|
2394
|
+
/** `heading-4` */
|
|
2395
|
+
heading4: ["M12 18V6", "M17 10v3a1 1 0 0 0 1 1h3", "M21 10v8", "M4 12h8", "M4 18V6"],
|
|
2193
2396
|
/** `list` */
|
|
2194
2397
|
bulletList: ["M3 5h.01", "M3 12h.01", "M3 19h.01", "M8 5h13", "M8 12h13", "M8 19h13"],
|
|
2195
2398
|
/** `list-ordered` */
|
|
@@ -2198,6 +2401,24 @@ var ICONS = {
|
|
|
2198
2401
|
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
2402
|
/** `text-quote` */
|
|
2200
2403
|
quote: ["M17 5H3", "M21 12H8", "M21 19H8", "M3 12v7"],
|
|
2404
|
+
/** `info`, as a Note callout */
|
|
2405
|
+
callout: [["circle", { cx: "12", cy: "12", r: "10" }], "M12 16v-4", "M12 8h.01"],
|
|
2406
|
+
/** `info` */
|
|
2407
|
+
calloutNote: [["circle", { cx: "12", cy: "12", r: "10" }], "M12 16v-4", "M12 8h.01"],
|
|
2408
|
+
/** `lightbulb` */
|
|
2409
|
+
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"],
|
|
2410
|
+
/** `message-square-warning` */
|
|
2411
|
+
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"],
|
|
2412
|
+
/** `triangle-alert` */
|
|
2413
|
+
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"],
|
|
2414
|
+
/** `octagon-alert` */
|
|
2415
|
+
calloutCaution: [
|
|
2416
|
+
"M12 16h.01",
|
|
2417
|
+
"M12 8v4",
|
|
2418
|
+
"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"
|
|
2419
|
+
],
|
|
2420
|
+
/** `list-collapse` */
|
|
2421
|
+
details: ["M10 5h11", "M10 12h11", "M10 19h11", "m3 10 3-3-3-3", "m3 20 3-3-3-3"],
|
|
2201
2422
|
/** `square-code` */
|
|
2202
2423
|
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
2424
|
/** `table` */
|
|
@@ -2262,6 +2483,14 @@ var ICONS = {
|
|
|
2262
2483
|
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
2484
|
/** `code` */
|
|
2264
2485
|
inlineCode: ["m16 18 6-6-6-6", "m8 6-6 6 6 6"],
|
|
2486
|
+
/** `external-link` */
|
|
2487
|
+
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"],
|
|
2488
|
+
/** `copy` */
|
|
2489
|
+
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"],
|
|
2490
|
+
/** `pencil` */
|
|
2491
|
+
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"],
|
|
2492
|
+
/** `unlink` */
|
|
2493
|
+
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
2494
|
/** `link` */
|
|
2266
2495
|
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
2496
|
/** `image-off` */
|
|
@@ -2361,7 +2590,7 @@ function inlineNodesText(nodes, soft) {
|
|
|
2361
2590
|
import { lookupEntity } from "#entities";
|
|
2362
2591
|
|
|
2363
2592
|
// src/markdown/options.ts
|
|
2364
|
-
var DEFAULT_MARKDOWN = { breaks: false, setext: true, autolinks: true, syntax: [], inline: [], block: [], escape: "" };
|
|
2593
|
+
var DEFAULT_MARKDOWN = { breaks: false, setext: true, autolinks: true, callouts: true, details: true, syntax: [], inline: [], block: [], escape: "" };
|
|
2365
2594
|
var resolved = /* @__PURE__ */ new WeakMap();
|
|
2366
2595
|
function resolveMarkdown(options) {
|
|
2367
2596
|
if (!options) return DEFAULT_MARKDOWN;
|
|
@@ -2372,6 +2601,8 @@ function resolveMarkdown(options) {
|
|
|
2372
2601
|
breaks: options.breaks ?? false,
|
|
2373
2602
|
setext: options.setext ?? true,
|
|
2374
2603
|
autolinks: options.autolinks ?? true,
|
|
2604
|
+
callouts: options.callouts ?? true,
|
|
2605
|
+
details: options.details ?? true,
|
|
2375
2606
|
syntax,
|
|
2376
2607
|
inline: syntax.flatMap((s) => s.inline ?? []),
|
|
2377
2608
|
block: syntax.flatMap((s) => s.block ?? []),
|
|
@@ -2519,12 +2750,26 @@ function lowerList(list, depth, out, o) {
|
|
|
2519
2750
|
});
|
|
2520
2751
|
}
|
|
2521
2752
|
function lowerQuote(children, out, o) {
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2753
|
+
const alert = o.callouts === false ? null : calloutOf2(children);
|
|
2754
|
+
const callout = alert?.type;
|
|
2755
|
+
const start = out.length;
|
|
2756
|
+
children.forEach((child, i) => {
|
|
2757
|
+
if (child.type !== "paragraph") return;
|
|
2758
|
+
const content = lowerInlines(i === 0 && alert ? alert.rest : child.children, o);
|
|
2759
|
+
if (isEmptyLine(content)) out.push(quote([], void 0, callout));
|
|
2760
|
+
else if (content.length > 0) out.push(quote(content, void 0, callout));
|
|
2761
|
+
});
|
|
2762
|
+
if (callout && out.length === start) out.push(quote([], void 0, callout));
|
|
2763
|
+
}
|
|
2764
|
+
var ALERT_MARKER = new RegExp(`^\\[!(${CALLOUT_TYPES.join("|")})\\]$`, "i");
|
|
2765
|
+
function calloutOf2(children) {
|
|
2766
|
+
const first = children[0];
|
|
2767
|
+
if (first?.type !== "paragraph") return null;
|
|
2768
|
+
const [marker, after] = first.children;
|
|
2769
|
+
const m = marker?.type === "text" ? ALERT_MARKER.exec(marker.value) : null;
|
|
2770
|
+
if (!m) return null;
|
|
2771
|
+
if (after && after.type !== "softBreak" && after.type !== "hardBreak") return null;
|
|
2772
|
+
return { type: m[1].toLowerCase(), rest: first.children.slice(2) };
|
|
2528
2773
|
}
|
|
2529
2774
|
|
|
2530
2775
|
// src/markdown/inline.ts
|
|
@@ -2637,6 +2882,10 @@ function decodeEntity(entity2) {
|
|
|
2637
2882
|
}
|
|
2638
2883
|
return lookupEntity(entity2.slice(1, -1)) ?? null;
|
|
2639
2884
|
}
|
|
2885
|
+
var reEntity = new RegExp(ENTITY, "g");
|
|
2886
|
+
function decodeEntities(s) {
|
|
2887
|
+
return s.includes("&") ? s.replace(reEntity, (m) => decodeEntity(m) ?? m) : s;
|
|
2888
|
+
}
|
|
2640
2889
|
function unescapeString(s) {
|
|
2641
2890
|
if (!s.includes("\\") && !s.includes("&")) return s;
|
|
2642
2891
|
return s.replace(reEntityOrEscapedChar, (m) => m[0] === "\\" ? m[1] : decodeEntity(m) ?? m);
|
|
@@ -3356,6 +3605,10 @@ var reHtmlBlockOpen = [
|
|
|
3356
3605
|
/^<[/]?(?: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
3606
|
new RegExp(`^(?:${OPENTAG}|${CLOSETAG})[ \\t]*$`, "i")
|
|
3358
3607
|
];
|
|
3608
|
+
function interruptsParagraph(text) {
|
|
3609
|
+
for (let type = 1; type <= 6; type++) if (reHtmlBlockOpen[type].test(text)) return true;
|
|
3610
|
+
return false;
|
|
3611
|
+
}
|
|
3359
3612
|
var reHtmlBlockClose = [
|
|
3360
3613
|
/^$/,
|
|
3361
3614
|
/<\/(?:script|pre|textarea|style)>/i,
|
|
@@ -4118,6 +4371,29 @@ function htmlSectionEnd(nodes, i) {
|
|
|
4118
4371
|
}
|
|
4119
4372
|
return i;
|
|
4120
4373
|
}
|
|
4374
|
+
var reDetailsOpen = /^<details(\s+open(?:\s*=\s*(?:""|''|"open"|'open'|open))?)?\s*>\s*<summary>([^<]*)<\/summary>\s*$/i;
|
|
4375
|
+
var reDetailsClose = /^<\/details>\s*$/i;
|
|
4376
|
+
function detailsSections(nodes) {
|
|
4377
|
+
const out = /* @__PURE__ */ new Map();
|
|
4378
|
+
const open = [];
|
|
4379
|
+
nodes.forEach((node, i) => {
|
|
4380
|
+
if (node.type !== "htmlBlock") return;
|
|
4381
|
+
const start = reDetailsOpen.exec(node.value);
|
|
4382
|
+
if (start) {
|
|
4383
|
+
open.push({ index: i, block: details(plain(decodeEntities(start[2].trim())), { open: !!start[1] }) });
|
|
4384
|
+
} else if (reDetailsClose.test(node.value)) {
|
|
4385
|
+
const section = open.pop();
|
|
4386
|
+
if (!section) return;
|
|
4387
|
+
out.set(section.index, section.block);
|
|
4388
|
+
out.set(i, detailsEnd());
|
|
4389
|
+
} else {
|
|
4390
|
+
const tags2 = [];
|
|
4391
|
+
applyTags(node.value, tags2);
|
|
4392
|
+
if (tags2.length > 0) open.length = 0;
|
|
4393
|
+
}
|
|
4394
|
+
});
|
|
4395
|
+
return out;
|
|
4396
|
+
}
|
|
4121
4397
|
var slotMarker = (index) => `\uE000${index}\uE001`;
|
|
4122
4398
|
var SLOT_MARKER = /(\d+)/g;
|
|
4123
4399
|
function splitHtmlSection(source, options = DEFAULT_MARKDOWN) {
|
|
@@ -4179,9 +4455,12 @@ function serializeBlocks(blocks, options) {
|
|
|
4179
4455
|
text = block3.content.length === 0 ? " " : inlineToMarkdown(block3.content, ctx.paragraph);
|
|
4180
4456
|
break;
|
|
4181
4457
|
case "quote": {
|
|
4182
|
-
|
|
4458
|
+
let body = block3.content.length === 0 ? " " : 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}`;
|
|
4183
4462
|
text = prefixLines(body, "> ", ">");
|
|
4184
|
-
if (
|
|
4463
|
+
if (joined) separator = "\n>\n";
|
|
4185
4464
|
break;
|
|
4186
4465
|
}
|
|
4187
4466
|
case "heading":
|
|
@@ -4205,6 +4484,15 @@ function serializeBlocks(blocks, options) {
|
|
|
4205
4484
|
case "divider":
|
|
4206
4485
|
text = "---";
|
|
4207
4486
|
break;
|
|
4487
|
+
case "details": {
|
|
4488
|
+
const title = inlineText(block3.content).replace(/[&<>]/g, (c) => c === "&" ? "&" : c === "<" ? "<" : ">");
|
|
4489
|
+
text = `<details${block3.open ? " open" : ""}>
|
|
4490
|
+
<summary>${title}</summary>`;
|
|
4491
|
+
break;
|
|
4492
|
+
}
|
|
4493
|
+
case "detailsEnd":
|
|
4494
|
+
text = "</details>";
|
|
4495
|
+
break;
|
|
4208
4496
|
}
|
|
4209
4497
|
if (out) out += separator;
|
|
4210
4498
|
out += text;
|
|
@@ -4240,7 +4528,7 @@ function serializeCode(language, text) {
|
|
|
4240
4528
|
${text ? text + "\n" : ""}${fence}`;
|
|
4241
4529
|
}
|
|
4242
4530
|
function serializeTable(align, rows, ctx) {
|
|
4243
|
-
const row = (cells) => "| " + cells.map((cell) => inlineToMarkdown(cell, ctx).replace(/\|/g, "\\|")).join(" | ") + " |";
|
|
4531
|
+
const row = (cells) => "| " + cells.map((cell) => inlineToMarkdown(representableCell(cell), ctx).replace(/\|/g, "\\|")).join(" | ") + " |";
|
|
4244
4532
|
const delimiter = "| " + align.map((a) => a === "left" ? ":--" : a === "center" ? ":-:" : a === "right" ? "--:" : "---").join(" | ") + " |";
|
|
4245
4533
|
const [header, ...body] = rows;
|
|
4246
4534
|
return [row(header ?? align.map(() => [])), delimiter, ...body.map(row)].join("\n");
|
|
@@ -4321,6 +4609,25 @@ function sameInline(a, b) {
|
|
|
4321
4609
|
});
|
|
4322
4610
|
}
|
|
4323
4611
|
var reSpecWhitespace = /^[\t\n\f\r\p{Zs}]+|[\t\n\f\r\p{Zs}]+$/gu;
|
|
4612
|
+
var ODD_BACKSLASH_PIPE = /(?<!\\)(?:\\\\)*\\\|/;
|
|
4613
|
+
function representableCell(inline3) {
|
|
4614
|
+
if (!inline3.some((s) => s.marks.includes("code") && ODD_BACKSLASH_PIPE.test(s.text))) return inline3;
|
|
4615
|
+
return normalizeInline(
|
|
4616
|
+
inline3.flatMap((s) => {
|
|
4617
|
+
if (!s.marks.includes("code")) return [s];
|
|
4618
|
+
const marks = s.marks.filter((m) => m !== "code");
|
|
4619
|
+
const out = [];
|
|
4620
|
+
let from = 0;
|
|
4621
|
+
for (const m of s.text.matchAll(new RegExp(ODD_BACKSLASH_PIPE, "g"))) {
|
|
4622
|
+
const pipe = m.index + m[0].length - 1;
|
|
4623
|
+
out.push({ ...s, text: s.text.slice(from, pipe) }, { ...s, text: "|", marks });
|
|
4624
|
+
from = pipe + 1;
|
|
4625
|
+
}
|
|
4626
|
+
out.push({ ...s, text: s.text.slice(from) });
|
|
4627
|
+
return out.filter((span) => span.text !== "");
|
|
4628
|
+
})
|
|
4629
|
+
);
|
|
4630
|
+
}
|
|
4324
4631
|
function representableInline(inline3) {
|
|
4325
4632
|
let spans = normalizeInline(
|
|
4326
4633
|
inline3.flatMap((s) => {
|
|
@@ -4526,8 +4833,10 @@ function render(spans, ctx, strategy, bare = false) {
|
|
|
4526
4833
|
let out = "";
|
|
4527
4834
|
tokens.forEach((tok, i) => {
|
|
4528
4835
|
if (tok.kind === "delim") out += tok.ch.repeat(tok.count);
|
|
4529
|
-
else if (tok.kind === "raw")
|
|
4530
|
-
|
|
4836
|
+
else if (tok.kind === "raw") {
|
|
4837
|
+
if (ctx.lineStart && out.endsWith("\n") && interruptsParagraph(tok.text)) out += " ";
|
|
4838
|
+
out += tok.text;
|
|
4839
|
+
} else {
|
|
4531
4840
|
out += escapeText(tok, ctx, {
|
|
4532
4841
|
before: out ? out[out.length - 1] : void 0,
|
|
4533
4842
|
after: edgeChar(tokens[i + 1], "first"),
|
|
@@ -4720,14 +5029,16 @@ function loadMarkdown(text, options) {
|
|
|
4720
5029
|
const groups = [];
|
|
4721
5030
|
const groupOf = /* @__PURE__ */ new WeakMap();
|
|
4722
5031
|
let lastEnd = 0;
|
|
5032
|
+
const sections2 = (options ?? DEFAULT_MARKDOWN).details === false ? null : detailsSections(root.children);
|
|
4723
5033
|
for (let i = 0; i < root.children.length; i++) {
|
|
4724
5034
|
const node = root.children[i];
|
|
4725
|
-
const
|
|
5035
|
+
const section = sections2?.get(i);
|
|
5036
|
+
const last = section ? i : htmlSectionEnd(root.children, i);
|
|
4726
5037
|
const from = lineStarts[root.lines[i].start - 1] ?? text.length;
|
|
4727
5038
|
const lines = root.lines[last];
|
|
4728
5039
|
const to = lineEnds[Math.max(lines.start, lines.end) - 1] ?? text.length;
|
|
4729
5040
|
const source = text.slice(from, to);
|
|
4730
|
-
const lowered = last > i ? [htmlBlock(source)] : lowerTopLevel(node, options ?? DEFAULT_MARKDOWN, source);
|
|
5041
|
+
const lowered = section ? [section] : last > i ? [htmlBlock(source)] : lowerTopLevel(node, options ?? DEFAULT_MARKDOWN, source);
|
|
4731
5042
|
i = last;
|
|
4732
5043
|
blocks.push(...lowered);
|
|
4733
5044
|
if (lowered.length === 0 || from < lastEnd || to < from) continue;
|
|
@@ -4743,7 +5054,8 @@ function isOpen(source, options) {
|
|
|
4743
5054
|
return parseAst(source + "\n\nx", options).children.length < 2;
|
|
4744
5055
|
}
|
|
4745
5056
|
function joins(a, b) {
|
|
4746
|
-
|
|
5057
|
+
if (a?.type === "quote" && b?.type === "quote") return a.callout === b.callout;
|
|
5058
|
+
return a?.type === "listItem" && b?.type === "listItem";
|
|
4747
5059
|
}
|
|
4748
5060
|
function saveWithSource(blocks, source, options) {
|
|
4749
5061
|
const text = source.text;
|
|
@@ -5274,10 +5586,12 @@ function defaultKeymap() {
|
|
|
5274
5586
|
"Mod-Alt-1": ({ editor }) => editor.commands.toggleHeading({ level: 1 }) || true,
|
|
5275
5587
|
"Mod-Alt-2": ({ editor }) => editor.commands.toggleHeading({ level: 2 }) || true,
|
|
5276
5588
|
"Mod-Alt-3": ({ editor }) => editor.commands.toggleHeading({ level: 3 }) || true,
|
|
5589
|
+
"Mod-Alt-4": ({ editor }) => editor.commands.toggleHeading({ level: 4 }) || true,
|
|
5277
5590
|
"Mod-Alt-c": ({ editor }) => editor.commands.toggleCodeBlock() || true,
|
|
5278
5591
|
"Mod-Shift-7": ({ editor }) => editor.commands.toggleOrderedList() || true,
|
|
5279
5592
|
"Mod-Shift-8": ({ editor }) => editor.commands.toggleBulletList() || true,
|
|
5280
5593
|
"Mod-Shift-9": ({ editor }) => editor.commands.toggleTaskList() || true,
|
|
5594
|
+
"Mod-Shift-6": ({ editor }) => editor.commands.toggleDetails() || true,
|
|
5281
5595
|
"Mod-a": ({ editor }) => selectAll2(editor),
|
|
5282
5596
|
"Mod-z": ({ editor }) => editor.commands.undo() || true,
|
|
5283
5597
|
"Mod-Shift-z": ({ editor }) => editor.commands.redo() || true,
|
|
@@ -5989,7 +6303,8 @@ var TEXT_STYLES = [
|
|
|
5989
6303
|
{ id: "text", spec: { type: "paragraph" }, keys: mod("Alt+0") },
|
|
5990
6304
|
{ id: "heading1", spec: { type: "heading", level: 1 }, keys: mod("Alt+1") },
|
|
5991
6305
|
{ id: "heading2", spec: { type: "heading", level: 2 }, keys: mod("Alt+2") },
|
|
5992
|
-
{ id: "heading3", spec: { type: "heading", level: 3 }, keys: mod("Alt+3") }
|
|
6306
|
+
{ id: "heading3", spec: { type: "heading", level: 3 }, keys: mod("Alt+3") },
|
|
6307
|
+
{ id: "heading4", spec: { type: "heading", level: 4 }, keys: mod("Alt+4") }
|
|
5993
6308
|
];
|
|
5994
6309
|
var LIST_TYPES = [
|
|
5995
6310
|
{ id: "bulletList", listType: "bullet", keys: mod("Shift+8") },
|
|
@@ -6000,7 +6315,7 @@ var TOOLTIP_DELAY = 500;
|
|
|
6000
6315
|
var TOOLTIP_GRACE = 300;
|
|
6001
6316
|
function blockState(editor) {
|
|
6002
6317
|
const blocks = convertibleBlocks(editor.state);
|
|
6003
|
-
const styleOf2 = (b) => b.type === "paragraph" ? "text" : b.type === "heading" && b.level <=
|
|
6318
|
+
const styleOf2 = (b) => b.type === "paragraph" ? "text" : b.type === "heading" && b.level <= 4 ? `heading${b.level}` : null;
|
|
6004
6319
|
const every = (f) => {
|
|
6005
6320
|
const first = blocks[0] ? f(blocks[0]) : null;
|
|
6006
6321
|
return blocks.every((b) => f(b) === first) ? first : null;
|
|
@@ -6340,6 +6655,9 @@ var FILL_ATTR = "data-mbe-fill";
|
|
|
6340
6655
|
var ATOM_ATTR = "data-atom";
|
|
6341
6656
|
var LIST_START_ATTR = "data-list-start";
|
|
6342
6657
|
var QUOTE_JOINED_ATTR = "data-quote-joined";
|
|
6658
|
+
var SECTION_HIDDEN_ATTR = "data-section-hidden";
|
|
6659
|
+
var SECTION_COLLAPSED_ATTR = "data-collapsed";
|
|
6660
|
+
var SECTION_INSIDE_ATTR = "data-in-section";
|
|
6343
6661
|
var MARK_TAGS = {
|
|
6344
6662
|
bold: ["strong"],
|
|
6345
6663
|
italic: ["em"],
|
|
@@ -6369,6 +6687,11 @@ function blockClasses(block3, theme) {
|
|
|
6369
6687
|
return theme.raw;
|
|
6370
6688
|
case "divider":
|
|
6371
6689
|
return void 0;
|
|
6690
|
+
// on the <hr>
|
|
6691
|
+
case "details":
|
|
6692
|
+
return theme.details;
|
|
6693
|
+
case "detailsEnd":
|
|
6694
|
+
return void 0;
|
|
6372
6695
|
}
|
|
6373
6696
|
}
|
|
6374
6697
|
var defaultResolveUrl = (url) => {
|
|
@@ -6387,6 +6710,9 @@ function sameReveal(a, b) {
|
|
|
6387
6710
|
for (const key of a) if (!b.has(key)) return false;
|
|
6388
6711
|
return true;
|
|
6389
6712
|
}
|
|
6713
|
+
function calloutName(type) {
|
|
6714
|
+
return `callout${type[0].toUpperCase()}${type.slice(1)}`;
|
|
6715
|
+
}
|
|
6390
6716
|
function markImageBlock(el, block3) {
|
|
6391
6717
|
const offset = imageBlockOffset(block3);
|
|
6392
6718
|
if (offset === null) return;
|
|
@@ -6394,6 +6720,24 @@ function markImageBlock(el, block3) {
|
|
|
6394
6720
|
const align = sliceInline(block3.content, offset, offset + 1)[0]?.image?.align;
|
|
6395
6721
|
if (align) el.dataset.align = align;
|
|
6396
6722
|
}
|
|
6723
|
+
function renderCallout(block3, type, ctx, reveal) {
|
|
6724
|
+
const doc = ctx.doc;
|
|
6725
|
+
const root = doc.createElement("blockquote");
|
|
6726
|
+
root.dir = "auto";
|
|
6727
|
+
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
|
+
const content = doc.createElement("div");
|
|
6736
|
+
content.className = "mbe-content";
|
|
6737
|
+
fillContent(content, block3.content, ctx, block3, reveal);
|
|
6738
|
+
root.append(title, content);
|
|
6739
|
+
return root;
|
|
6740
|
+
}
|
|
6397
6741
|
function renderBlock(block3, ctx, reveal) {
|
|
6398
6742
|
const { doc, labels } = ctx;
|
|
6399
6743
|
const el = (tag, className2) => {
|
|
@@ -6406,6 +6750,10 @@ function renderBlock(block3, ctx, reveal) {
|
|
|
6406
6750
|
case "paragraph":
|
|
6407
6751
|
case "heading":
|
|
6408
6752
|
case "quote":
|
|
6753
|
+
if (block3.type === "quote" && block3.callout) {
|
|
6754
|
+
root = renderCallout(block3, block3.callout, ctx, reveal);
|
|
6755
|
+
break;
|
|
6756
|
+
}
|
|
6409
6757
|
root = el(block3.type === "paragraph" ? "p" : block3.type === "quote" ? "blockquote" : `h${block3.level}`);
|
|
6410
6758
|
root.dir = "auto";
|
|
6411
6759
|
fillContent(root, block3.content, ctx, block3, reveal);
|
|
@@ -6481,6 +6829,26 @@ function renderBlock(block3, ctx, reveal) {
|
|
|
6481
6829
|
root.contentEditable = "false";
|
|
6482
6830
|
root.appendChild(el("hr", ctx.classes.divider));
|
|
6483
6831
|
break;
|
|
6832
|
+
case "details": {
|
|
6833
|
+
root = el("div");
|
|
6834
|
+
root.dir = "auto";
|
|
6835
|
+
const marker = el("span", "mbe-details-marker");
|
|
6836
|
+
marker.contentEditable = "false";
|
|
6837
|
+
const toggle = el("button", "mbe-details-toggle");
|
|
6838
|
+
toggle.type = "button";
|
|
6839
|
+
toggle.tabIndex = -1;
|
|
6840
|
+
const icon = ctx.icon?.("chevronRight");
|
|
6841
|
+
if (icon) toggle.appendChild(icon);
|
|
6842
|
+
marker.appendChild(toggle);
|
|
6843
|
+
const content = el("div", "mbe-content");
|
|
6844
|
+
fillContent(content, block3.content, ctx, block3, void 0, void 0, false);
|
|
6845
|
+
root.append(marker, content);
|
|
6846
|
+
break;
|
|
6847
|
+
}
|
|
6848
|
+
case "detailsEnd":
|
|
6849
|
+
root = el("div");
|
|
6850
|
+
root.contentEditable = "false";
|
|
6851
|
+
break;
|
|
6484
6852
|
case "table": {
|
|
6485
6853
|
root = el("div");
|
|
6486
6854
|
root.contentEditable = "false";
|
|
@@ -6507,7 +6875,8 @@ function renderBlock(block3, ctx, reveal) {
|
|
|
6507
6875
|
}
|
|
6508
6876
|
}
|
|
6509
6877
|
root.setAttribute(BLOCK_ATTR, block3.id);
|
|
6510
|
-
|
|
6878
|
+
const name = block3.type === "listItem" ? "list-item" : block3.type === "detailsEnd" ? "details-end" : block3.type;
|
|
6879
|
+
let className = `${root.className ? root.className + " " : ""}mbe-block mbe-${name}`;
|
|
6511
6880
|
if (block3.type === "listItem" && block3.checked) className += " mbe-checked";
|
|
6512
6881
|
if ("content" in block3 && inlineLength(block3.content) === 0) className += " mbe-empty";
|
|
6513
6882
|
const themed = blockClasses(block3, ctx.classes);
|
|
@@ -6584,7 +6953,7 @@ function renderFlow(blocks, ctx) {
|
|
|
6584
6953
|
elements.set(block3.id, el);
|
|
6585
6954
|
flow.appendChild(el);
|
|
6586
6955
|
}
|
|
6587
|
-
updateNeighborMarks({ blocks }, (id) => elements.get(id), /* @__PURE__ */ new WeakMap());
|
|
6956
|
+
updateNeighborMarks({ blocks }, (id) => elements.get(id), /* @__PURE__ */ new WeakMap(), /* @__PURE__ */ new Set(), ctx.labels);
|
|
6588
6957
|
for (const el of Array.from(flow.querySelectorAll(`[${BLOCK_ATTR}], [${CONTENT_ATTR}], [contenteditable], [data-row]`))) {
|
|
6589
6958
|
el.removeAttribute(BLOCK_ATTR);
|
|
6590
6959
|
el.removeAttribute(CONTENT_ATTR);
|
|
@@ -6835,6 +7204,8 @@ var BlockRenderer = class {
|
|
|
6835
7204
|
codeCopy = false;
|
|
6836
7205
|
/** An image failed to load and now shows as unavailable. */
|
|
6837
7206
|
onImageError;
|
|
7207
|
+
/** Collapsible sections shown collapsed, by the ID of their title block. */
|
|
7208
|
+
collapsed = /* @__PURE__ */ new Set();
|
|
6838
7209
|
/** Per block, the views that show their source. A block re-renders when its entry changes. */
|
|
6839
7210
|
revealed = /* @__PURE__ */ new Map();
|
|
6840
7211
|
/**
|
|
@@ -6980,7 +7351,11 @@ var BlockRenderer = class {
|
|
|
6980
7351
|
}
|
|
6981
7352
|
}
|
|
6982
7353
|
this.rendered = next;
|
|
6983
|
-
updateNeighborMarks(doc, (id) => next.get(id)?.el, this.numbers);
|
|
7354
|
+
updateNeighborMarks(doc, (id) => next.get(id)?.el, this.numbers, this.collapsed, this.labels);
|
|
7355
|
+
}
|
|
7356
|
+
/** Marks blocks again after `collapsed` changed, without rendering any. */
|
|
7357
|
+
updateSections(doc) {
|
|
7358
|
+
updateNeighborMarks(doc, (id) => this.rendered.get(id)?.el, this.numbers, this.collapsed, this.labels);
|
|
6984
7359
|
}
|
|
6985
7360
|
elementFor(id) {
|
|
6986
7361
|
return this.rendered.get(id)?.el;
|
|
@@ -7001,12 +7376,33 @@ var BlockRenderer = class {
|
|
|
7001
7376
|
this.rendered.delete(id);
|
|
7002
7377
|
}
|
|
7003
7378
|
};
|
|
7004
|
-
function
|
|
7379
|
+
function markSection(el, depth, hidden, collapsed, labels) {
|
|
7380
|
+
const value = depth > 0 ? String(depth) : "";
|
|
7381
|
+
if (el.style.getPropertyValue("--mbe-section-depth") !== value) {
|
|
7382
|
+
if (value) el.style.setProperty("--mbe-section-depth", value);
|
|
7383
|
+
else el.style.removeProperty("--mbe-section-depth");
|
|
7384
|
+
}
|
|
7385
|
+
setFlag(el, SECTION_INSIDE_ATTR, depth > 0);
|
|
7386
|
+
setFlag(el, SECTION_HIDDEN_ATTR, hidden);
|
|
7387
|
+
if (collapsed === null) return;
|
|
7388
|
+
setFlag(el, SECTION_COLLAPSED_ATTR, collapsed);
|
|
7389
|
+
const toggle = el.querySelector(".mbe-details-toggle");
|
|
7390
|
+
const expanded = String(!collapsed);
|
|
7391
|
+
if (toggle && toggle.getAttribute("aria-expanded") !== expanded) {
|
|
7392
|
+
toggle.setAttribute("aria-expanded", expanded);
|
|
7393
|
+
toggle.setAttribute("aria-label", collapsed ? labels.expandSection : labels.collapseSection);
|
|
7394
|
+
}
|
|
7395
|
+
}
|
|
7396
|
+
function updateNeighborMarks(doc, elementFor, written, collapsed, labels) {
|
|
7005
7397
|
const counters = [];
|
|
7398
|
+
const sections2 = [];
|
|
7006
7399
|
doc.blocks.forEach((block3, i) => {
|
|
7007
7400
|
const before = doc.blocks[i - 1];
|
|
7008
7401
|
const el = elementFor(block3.id);
|
|
7009
|
-
if (block3.type === "
|
|
7402
|
+
if (block3.type === "detailsEnd") sections2.pop();
|
|
7403
|
+
if (el) markSection(el, sections2.length, sections2.includes(true), block3.type === "details" ? collapsed.has(block3.id) : null, labels);
|
|
7404
|
+
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);
|
|
7010
7406
|
if (block3.type !== "listItem") {
|
|
7011
7407
|
counters.length = 0;
|
|
7012
7408
|
return;
|
|
@@ -7031,8 +7427,8 @@ function keepDetailsOpen(from, to) {
|
|
|
7031
7427
|
if (before.length === 0) return;
|
|
7032
7428
|
const after = to.querySelectorAll("details");
|
|
7033
7429
|
if (after.length !== before.length) return;
|
|
7034
|
-
before.forEach((
|
|
7035
|
-
after[i].open =
|
|
7430
|
+
before.forEach((details2, i) => {
|
|
7431
|
+
after[i].open = details2.open;
|
|
7036
7432
|
});
|
|
7037
7433
|
}
|
|
7038
7434
|
function setFlag(el, attr, on) {
|
|
@@ -7203,8 +7599,8 @@ var BlockHandle = class {
|
|
|
7203
7599
|
let node = target;
|
|
7204
7600
|
while (node && node.parentElement !== this.editor.root) node = node.parentElement;
|
|
7205
7601
|
if (!node || !node.hasAttribute(BLOCK_ATTR)) return;
|
|
7206
|
-
const
|
|
7207
|
-
if (
|
|
7602
|
+
const owner = this.editor.blockMenuOwner(node.getAttribute(BLOCK_ATTR));
|
|
7603
|
+
if (owner) this.showFor(owner);
|
|
7208
7604
|
else if (this.blockId !== null) this.scheduleHide();
|
|
7209
7605
|
}
|
|
7210
7606
|
/** Shows the block handle next to a block. */
|
|
@@ -7247,6 +7643,199 @@ var BlockHandle = class {
|
|
|
7247
7643
|
}
|
|
7248
7644
|
};
|
|
7249
7645
|
|
|
7646
|
+
// src/ui/linkCard.ts
|
|
7647
|
+
var HOVER_DELAY = 300;
|
|
7648
|
+
var LEAVE_DELAY = 250;
|
|
7649
|
+
var LinkCard = class {
|
|
7650
|
+
constructor(editor, actions) {
|
|
7651
|
+
this.editor = editor;
|
|
7652
|
+
this.actions = actions;
|
|
7653
|
+
const doc = editor.root.ownerDocument;
|
|
7654
|
+
const labels = editor.labels;
|
|
7655
|
+
this.popup = new Popup(editor.root, "mbe-link-card");
|
|
7656
|
+
const el = this.popup.el;
|
|
7657
|
+
el.setAttribute("role", "toolbar");
|
|
7658
|
+
el.setAttribute("aria-label", labels.link);
|
|
7659
|
+
this.url = doc.createElement("a");
|
|
7660
|
+
this.url.className = "mbe-link-card-url";
|
|
7661
|
+
this.url.target = "_blank";
|
|
7662
|
+
this.url.rel = "noopener noreferrer";
|
|
7663
|
+
this.url.addEventListener("click", (e) => {
|
|
7664
|
+
e.preventDefault();
|
|
7665
|
+
if (this.target) actions.open(this.target, e);
|
|
7666
|
+
});
|
|
7667
|
+
const button = (name, onClick) => {
|
|
7668
|
+
const b = doc.createElement("button");
|
|
7669
|
+
b.type = "button";
|
|
7670
|
+
b.className = `mbe-tool mbe-link-card-${name}`;
|
|
7671
|
+
setIcon(b, editor, name);
|
|
7672
|
+
b.setAttribute("aria-label", labels[name]);
|
|
7673
|
+
b.title = labels[name];
|
|
7674
|
+
b.addEventListener("click", (e) => {
|
|
7675
|
+
if (this.target) onClick(e);
|
|
7676
|
+
});
|
|
7677
|
+
return b;
|
|
7678
|
+
};
|
|
7679
|
+
const open = button("openLink", (e) => actions.open(this.target, e));
|
|
7680
|
+
this.copyButton = button("copyLink", () => this.copy());
|
|
7681
|
+
const edit = button("editLink", () => {
|
|
7682
|
+
const target = this.target;
|
|
7683
|
+
this.hide();
|
|
7684
|
+
actions.edit(target);
|
|
7685
|
+
});
|
|
7686
|
+
const remove = button("removeLink", () => {
|
|
7687
|
+
const target = this.target;
|
|
7688
|
+
this.hide();
|
|
7689
|
+
actions.remove(target);
|
|
7690
|
+
});
|
|
7691
|
+
const sep = doc.createElement("span");
|
|
7692
|
+
sep.className = "mbe-tool-sep";
|
|
7693
|
+
el.append(this.url, sep, open, this.copyButton, edit, remove);
|
|
7694
|
+
const root = editor.root;
|
|
7695
|
+
const on = (target, type, fn) => {
|
|
7696
|
+
target.addEventListener(type, fn);
|
|
7697
|
+
this.cleanup.push(() => target.removeEventListener(type, fn));
|
|
7698
|
+
};
|
|
7699
|
+
on(root, "mouseover", (e) => this.onOver(e));
|
|
7700
|
+
on(root, "mouseout", (e) => this.onOut(e));
|
|
7701
|
+
on(el, "mouseenter", () => this.cancelHide());
|
|
7702
|
+
on(el, "mouseleave", () => {
|
|
7703
|
+
if (this.hovered) this.scheduleHide();
|
|
7704
|
+
});
|
|
7705
|
+
}
|
|
7706
|
+
popup;
|
|
7707
|
+
url;
|
|
7708
|
+
copyButton;
|
|
7709
|
+
target = null;
|
|
7710
|
+
/** What shows the card: the pointer on a link, or the caret in one. The pointer wins. */
|
|
7711
|
+
hovered = null;
|
|
7712
|
+
caret = null;
|
|
7713
|
+
showTimer = null;
|
|
7714
|
+
hideTimer = null;
|
|
7715
|
+
copiedTimer = null;
|
|
7716
|
+
cleanup = [];
|
|
7717
|
+
get isOpen() {
|
|
7718
|
+
return this.popup.isOpen;
|
|
7719
|
+
}
|
|
7720
|
+
contains(node) {
|
|
7721
|
+
return this.popup.el.contains(node);
|
|
7722
|
+
}
|
|
7723
|
+
/** Sets the link with the caret (null for none) and shows or hides the card to match. */
|
|
7724
|
+
setCaret(target) {
|
|
7725
|
+
this.caret = target;
|
|
7726
|
+
if (this.hovered && !this.hovered.el.isConnected) this.hovered = null;
|
|
7727
|
+
this.render();
|
|
7728
|
+
}
|
|
7729
|
+
/** Places the card under its link again, after scrolling or a layout change. */
|
|
7730
|
+
reposition() {
|
|
7731
|
+
if (!this.target) return;
|
|
7732
|
+
if (!this.target.el.isConnected) return this.hide();
|
|
7733
|
+
this.place(this.target);
|
|
7734
|
+
}
|
|
7735
|
+
hide() {
|
|
7736
|
+
this.clearTimers();
|
|
7737
|
+
this.hovered = null;
|
|
7738
|
+
this.caret = null;
|
|
7739
|
+
this.target = null;
|
|
7740
|
+
this.popup.hide();
|
|
7741
|
+
}
|
|
7742
|
+
destroy() {
|
|
7743
|
+
this.clearTimers();
|
|
7744
|
+
if (this.copiedTimer !== null) clearTimeout(this.copiedTimer);
|
|
7745
|
+
for (const fn of this.cleanup) fn();
|
|
7746
|
+
this.popup.destroy();
|
|
7747
|
+
}
|
|
7748
|
+
onOver(e) {
|
|
7749
|
+
if (!this.editor.isEditable || e.buttons !== 0) return;
|
|
7750
|
+
const el = e.target?.closest?.("a.mbe-link");
|
|
7751
|
+
if (!el || !this.editor.root.contains(el)) return;
|
|
7752
|
+
this.cancelHide();
|
|
7753
|
+
if (this.hovered?.el === el) return;
|
|
7754
|
+
if (this.showTimer !== null) clearTimeout(this.showTimer);
|
|
7755
|
+
this.showTimer = setTimeout(() => {
|
|
7756
|
+
this.showTimer = null;
|
|
7757
|
+
const target = this.actions.targetOf(el);
|
|
7758
|
+
if (!target || !this.editor.isEditable) return;
|
|
7759
|
+
this.hovered = target;
|
|
7760
|
+
this.render();
|
|
7761
|
+
}, this.popup.isOpen ? 0 : HOVER_DELAY);
|
|
7762
|
+
}
|
|
7763
|
+
onOut(e) {
|
|
7764
|
+
const el = e.target?.closest?.("a.mbe-link");
|
|
7765
|
+
if (!el) return;
|
|
7766
|
+
const next = e.relatedTarget;
|
|
7767
|
+
if (next && (el.contains(next) || this.popup.el.contains(next))) return;
|
|
7768
|
+
if (this.showTimer !== null) {
|
|
7769
|
+
clearTimeout(this.showTimer);
|
|
7770
|
+
this.showTimer = null;
|
|
7771
|
+
}
|
|
7772
|
+
if (this.hovered) this.scheduleHide();
|
|
7773
|
+
}
|
|
7774
|
+
render() {
|
|
7775
|
+
const target = this.hovered ?? this.caret;
|
|
7776
|
+
if (!target) {
|
|
7777
|
+
this.target = null;
|
|
7778
|
+
this.popup.hide();
|
|
7779
|
+
return;
|
|
7780
|
+
}
|
|
7781
|
+
if (this.target?.el !== target.el || this.target.href !== target.href) {
|
|
7782
|
+
this.target = target;
|
|
7783
|
+
this.url.textContent = target.href;
|
|
7784
|
+
this.url.title = target.href;
|
|
7785
|
+
const resolved2 = target.el.getAttribute("href");
|
|
7786
|
+
if (resolved2) this.url.href = resolved2;
|
|
7787
|
+
else this.url.removeAttribute("href");
|
|
7788
|
+
const open = this.popup.el.querySelector(".mbe-link-card-openLink");
|
|
7789
|
+
if (open) open.disabled = !resolved2;
|
|
7790
|
+
this.showCopied(false);
|
|
7791
|
+
}
|
|
7792
|
+
this.place(target);
|
|
7793
|
+
}
|
|
7794
|
+
place(target) {
|
|
7795
|
+
const rects = target.el.getClientRects();
|
|
7796
|
+
const rect = rects.length > 0 ? rects[rects.length - 1] : target.el.getBoundingClientRect();
|
|
7797
|
+
this.popup.show(rect, "below", 4);
|
|
7798
|
+
}
|
|
7799
|
+
copy() {
|
|
7800
|
+
const href = this.target.href;
|
|
7801
|
+
const done = () => this.showCopied(true);
|
|
7802
|
+
const clipboard = this.editor.root.ownerDocument.defaultView?.navigator.clipboard;
|
|
7803
|
+
if (clipboard) clipboard.writeText(href).then(done, () => {
|
|
7804
|
+
});
|
|
7805
|
+
}
|
|
7806
|
+
showCopied(copied) {
|
|
7807
|
+
if (this.copiedTimer !== null) clearTimeout(this.copiedTimer);
|
|
7808
|
+
this.copiedTimer = null;
|
|
7809
|
+
const b = this.copyButton;
|
|
7810
|
+
const name = copied ? "copied" : "copyLink";
|
|
7811
|
+
setIcon(b, this.editor, name);
|
|
7812
|
+
b.setAttribute("aria-label", this.editor.labels[name]);
|
|
7813
|
+
b.title = this.editor.labels[name];
|
|
7814
|
+
if (copied) this.copiedTimer = setTimeout(() => this.showCopied(false), 1500);
|
|
7815
|
+
}
|
|
7816
|
+
scheduleHide() {
|
|
7817
|
+
this.cancelHide();
|
|
7818
|
+
this.hideTimer = setTimeout(() => {
|
|
7819
|
+
this.hideTimer = null;
|
|
7820
|
+
this.hovered = null;
|
|
7821
|
+
this.render();
|
|
7822
|
+
}, LEAVE_DELAY);
|
|
7823
|
+
}
|
|
7824
|
+
cancelHide() {
|
|
7825
|
+
if (this.hideTimer !== null) clearTimeout(this.hideTimer);
|
|
7826
|
+
this.hideTimer = null;
|
|
7827
|
+
}
|
|
7828
|
+
clearTimers() {
|
|
7829
|
+
this.cancelHide();
|
|
7830
|
+
if (this.showTimer !== null) clearTimeout(this.showTimer);
|
|
7831
|
+
this.showTimer = null;
|
|
7832
|
+
}
|
|
7833
|
+
};
|
|
7834
|
+
function setIcon(button, editor, name) {
|
|
7835
|
+
const icon = iconNode(button.ownerDocument, editor.icon(name));
|
|
7836
|
+
button.replaceChildren(...icon ? [icon] : []);
|
|
7837
|
+
}
|
|
7838
|
+
|
|
7250
7839
|
// src/ui/resizeHandles.ts
|
|
7251
7840
|
var MIN_WIDTH = 24;
|
|
7252
7841
|
var SNAP = 8;
|
|
@@ -7533,7 +8122,12 @@ var COLOR_VARS = {
|
|
|
7533
8122
|
popupBackground: "--mbe-popup-bg",
|
|
7534
8123
|
popupBorder: "--mbe-popup-border",
|
|
7535
8124
|
hover: "--mbe-hover",
|
|
7536
|
-
danger: "--mbe-danger"
|
|
8125
|
+
danger: "--mbe-danger",
|
|
8126
|
+
calloutNote: "--mbe-callout-note",
|
|
8127
|
+
calloutTip: "--mbe-callout-tip",
|
|
8128
|
+
calloutImportant: "--mbe-callout-important",
|
|
8129
|
+
calloutWarning: "--mbe-callout-warning",
|
|
8130
|
+
calloutCaution: "--mbe-callout-caution"
|
|
7537
8131
|
};
|
|
7538
8132
|
var SIZE_VARS = {
|
|
7539
8133
|
font: "--mbe-font",
|
|
@@ -7565,10 +8159,13 @@ var SLASH_ITEM_IDS = [
|
|
|
7565
8159
|
"heading1",
|
|
7566
8160
|
"heading2",
|
|
7567
8161
|
"heading3",
|
|
8162
|
+
"heading4",
|
|
7568
8163
|
"bulletList",
|
|
7569
8164
|
"numberedList",
|
|
7570
8165
|
"todoList",
|
|
7571
8166
|
"quote",
|
|
8167
|
+
"callout",
|
|
8168
|
+
"details",
|
|
7572
8169
|
"code",
|
|
7573
8170
|
"table",
|
|
7574
8171
|
"divider"
|
|
@@ -7578,10 +8175,13 @@ var BLOCK_ITEMS2 = [
|
|
|
7578
8175
|
{ id: "heading1", aliases: ["h1", "title"], spec: { type: "heading", level: 1 } },
|
|
7579
8176
|
{ id: "heading2", aliases: ["h2", "subtitle"], spec: { type: "heading", level: 2 } },
|
|
7580
8177
|
{ id: "heading3", aliases: ["h3"], spec: { type: "heading", level: 3 } },
|
|
8178
|
+
{ id: "heading4", aliases: ["h4"], spec: { type: "heading", level: 4 } },
|
|
7581
8179
|
{ id: "bulletList", aliases: ["ul", "unordered", "bullet"], spec: { type: "listItem", listType: "bullet" } },
|
|
7582
8180
|
{ id: "numberedList", aliases: ["ol", "ordered"], spec: { type: "listItem", listType: "ordered" } },
|
|
7583
8181
|
{ id: "todoList", aliases: ["task", "checkbox", "checklist"], spec: { type: "listItem", listType: "task" } },
|
|
7584
8182
|
{ id: "quote", aliases: ["blockquote", "citation"], spec: { type: "quote" } },
|
|
8183
|
+
{ id: "callout", aliases: ["alert", "admonition", "note", "tip", "important", "warning", "caution"], spec: { type: "quote", callout: "note" } },
|
|
8184
|
+
{ id: "details", aliases: ["toggle", "collapse", "collapsible", "summary", "spoiler", "fold"], spec: { type: "details" } },
|
|
7585
8185
|
{ id: "code", aliases: ["pre", "snippet", "fence"], spec: { type: "code" } },
|
|
7586
8186
|
{ id: "table", aliases: ["grid"], spec: { type: "table" } },
|
|
7587
8187
|
{ id: "divider", aliases: ["hr", "separator", "line", "rule"], spec: { type: "divider" } }
|
|
@@ -7673,6 +8273,9 @@ var Editor = class {
|
|
|
7673
8273
|
/** The link popover, and the field for an image's alt text. */
|
|
7674
8274
|
inputPopover;
|
|
7675
8275
|
blockHandle;
|
|
8276
|
+
/** Collapsible sections shown collapsed, by the ID of their title. View state: not saved, not undone. */
|
|
8277
|
+
collapsed = /* @__PURE__ */ new Set();
|
|
8278
|
+
linkCard;
|
|
7676
8279
|
resizeHandles;
|
|
7677
8280
|
/** The selected image's element, which carries the selected class. */
|
|
7678
8281
|
selectedImageEl = null;
|
|
@@ -7711,6 +8314,8 @@ var Editor = class {
|
|
|
7711
8314
|
this.source = loaded.source;
|
|
7712
8315
|
this.current = createState(loaded.doc);
|
|
7713
8316
|
this.renderer = new BlockRenderer(root, this.labels);
|
|
8317
|
+
this.renderer.collapsed = this.collapsed;
|
|
8318
|
+
this.collapseClosedSections(this.current.doc);
|
|
7714
8319
|
this.renderer.widgetsAfter = (blockId) => {
|
|
7715
8320
|
if (this.widgets.length === 0) return void 0;
|
|
7716
8321
|
const els = this.widgets.filter((w) => w.blockId === blockId).map((w) => w.element);
|
|
@@ -7781,6 +8386,12 @@ var Editor = class {
|
|
|
7781
8386
|
this.toolbar = options.toolbar === false ? null : new FormatToolbar(this, typeof options.toolbar === "object" ? options.toolbar.items : void 0);
|
|
7782
8387
|
if (this.toolbar) this.toolbar.onMenuChange = () => this.syncActiveDescendant();
|
|
7783
8388
|
this.blockHandle = new BlockHandle(this);
|
|
8389
|
+
this.linkCard = options.linkCard === false ? null : new LinkCard(this, {
|
|
8390
|
+
open: (target, event) => this.openHref(target.el.getAttribute("href"), event),
|
|
8391
|
+
edit: (target) => this.editLink(target),
|
|
8392
|
+
remove: (target) => this.removeLink(target),
|
|
8393
|
+
targetOf: (el) => this.linkTargetOf(el)
|
|
8394
|
+
});
|
|
7784
8395
|
this.resizeHandles = new ResizeHandles(this);
|
|
7785
8396
|
this.renderer.onImageError = () => {
|
|
7786
8397
|
if (this.destroyed) return;
|
|
@@ -7836,6 +8447,8 @@ var Editor = class {
|
|
|
7836
8447
|
this.blockSel = null;
|
|
7837
8448
|
this.suggestions.reset();
|
|
7838
8449
|
const next = createState(loaded.doc);
|
|
8450
|
+
this.collapsed.clear();
|
|
8451
|
+
this.collapseClosedSections(next.doc);
|
|
7839
8452
|
this.relocateWidgets(this.current.doc, next.doc, true);
|
|
7840
8453
|
this.current = next;
|
|
7841
8454
|
this.paint(true, true);
|
|
@@ -7887,7 +8500,7 @@ var Editor = class {
|
|
|
7887
8500
|
const actual = this.getAttributes(name);
|
|
7888
8501
|
return Object.entries(attrs).every(([k, v]) => actual[k] === v);
|
|
7889
8502
|
}
|
|
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. */
|
|
8503
|
+
/** 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
8504
|
getAttributes(name) {
|
|
7892
8505
|
const s = this.current;
|
|
7893
8506
|
if (name === "link") {
|
|
@@ -7909,6 +8522,10 @@ var Editor = class {
|
|
|
7909
8522
|
return block3.listType === "task" ? { checked: block3.checked, indent: block3.indent } : { indent: block3.indent };
|
|
7910
8523
|
case "raw":
|
|
7911
8524
|
return { syntax: block3.syntax };
|
|
8525
|
+
case "quote":
|
|
8526
|
+
return block3.callout ? { callout: block3.callout } : {};
|
|
8527
|
+
case "details":
|
|
8528
|
+
return { open: block3.open, collapsed: this.collapsed.has(block3.id) };
|
|
7912
8529
|
default:
|
|
7913
8530
|
return {};
|
|
7914
8531
|
}
|
|
@@ -8093,6 +8710,7 @@ var Editor = class {
|
|
|
8093
8710
|
if (!next || next === this.current) return false;
|
|
8094
8711
|
next = dropBrokenTokens(next, this.current, this.markdown.inline);
|
|
8095
8712
|
next = clampListIndents(next, this.current);
|
|
8713
|
+
next = balanceSections(next);
|
|
8096
8714
|
if (next.doc !== this.current.doc && sameBlocks(next.doc, this.current.doc)) next = { ...next, doc: this.current.doc };
|
|
8097
8715
|
if (next.doc === this.current.doc && next.selection === this.current.selection && next.storedMarks === this.current.storedMarks) {
|
|
8098
8716
|
return false;
|
|
@@ -8114,6 +8732,10 @@ var Editor = class {
|
|
|
8114
8732
|
toggleOrderedList: () => block3({ type: "listItem", listType: "ordered" }),
|
|
8115
8733
|
toggleTaskList: () => block3({ type: "listItem", listType: "task" }),
|
|
8116
8734
|
toggleBlockquote: () => block3({ type: "quote" }),
|
|
8735
|
+
// Without callouts or sections in the Markdown dialect, they would not read back as such.
|
|
8736
|
+
toggleCallout: (attrs = {}) => this.markdown.callouts && block3({ type: "quote", callout: attrs.type ?? "note" }),
|
|
8737
|
+
toggleDetails: () => this.markdown.details && block3({ type: "details" }),
|
|
8738
|
+
setCallout: ({ type }) => (this.markdown.callouts || type === null) && run((s) => setCallout(s, s.selection.focus.blockId, type)),
|
|
8117
8739
|
toggleCodeBlock: (attrs = {}) => block3({ type: "code", language: attrs.language }),
|
|
8118
8740
|
setLink: ({ href }) => run((s) => setLink(s, href)),
|
|
8119
8741
|
unsetLink: () => run((s) => setLink(s, null)),
|
|
@@ -8262,6 +8884,7 @@ var Editor = class {
|
|
|
8262
8884
|
this.toolbar?.destroy();
|
|
8263
8885
|
this.inputPopover.destroy();
|
|
8264
8886
|
this.blockHandle.destroy();
|
|
8887
|
+
this.linkCard?.destroy();
|
|
8265
8888
|
this.resizeHandles.destroy();
|
|
8266
8889
|
setPopupContainer(this.root, void 0);
|
|
8267
8890
|
for (const name of Object.keys(this.runtime.attributes ?? {})) this.root.removeAttribute(name);
|
|
@@ -8375,9 +8998,10 @@ var Editor = class {
|
|
|
8375
8998
|
const el = this.renderer.elementFor(block3.id);
|
|
8376
8999
|
if (!el || !el.classList.contains("mbe-empty")) continue;
|
|
8377
9000
|
let hint = "";
|
|
8378
|
-
if (block3.type === "heading") hint = this.labels[`heading${Math.min(block3.level,
|
|
9001
|
+
if (block3.type === "heading") hint = this.labels[`heading${Math.min(block3.level, 4)}`];
|
|
8379
9002
|
else if (block3.type === "listItem") hint = this.labels.listHint;
|
|
8380
|
-
else if (block3.type === "quote") hint = this.labels.quoteHint;
|
|
9003
|
+
else if (block3.type === "quote" && !block3.callout) hint = this.labels.quoteHint;
|
|
9004
|
+
else if (block3.type === "details") hint = this.labels.detailsHint;
|
|
8381
9005
|
if (hint && el.dataset.hint !== hint) el.dataset.hint = hint;
|
|
8382
9006
|
}
|
|
8383
9007
|
this.updateUi();
|
|
@@ -8469,7 +9093,7 @@ var Editor = class {
|
|
|
8469
9093
|
const end = blockIndex(this.state.doc, to.blockId);
|
|
8470
9094
|
for (let i = from + dir; (end - i) * dir > 0; i += dir) {
|
|
8471
9095
|
const block3 = blocks[i];
|
|
8472
|
-
if (block3
|
|
9096
|
+
if (!this.skipsCaret(block3)) return this.blockEntry(block3, dir === 1, x);
|
|
8473
9097
|
}
|
|
8474
9098
|
return null;
|
|
8475
9099
|
}
|
|
@@ -8624,7 +9248,7 @@ var Editor = class {
|
|
|
8624
9248
|
const index2 = blockIndex(this.state.doc, selected.pos.blockId);
|
|
8625
9249
|
for (let i = index2 + (forward ? 1 : -1); i >= 0 && i < blocks.length; i += forward ? 1 : -1) {
|
|
8626
9250
|
const block3 = blocks[i];
|
|
8627
|
-
if (block3
|
|
9251
|
+
if (this.skipsCaret(block3)) continue;
|
|
8628
9252
|
const offset2 = imageBlockOffset(block3);
|
|
8629
9253
|
if (offset2 !== null) return { anchor: { blockId: block3.id, offset: offset2 }, focus: { blockId: block3.id, offset: offset2 + 1 } };
|
|
8630
9254
|
const vertical = key === "ArrowDown" || key === "ArrowUp";
|
|
@@ -8672,7 +9296,7 @@ var Editor = class {
|
|
|
8672
9296
|
}
|
|
8673
9297
|
for (let i = index + dir; i >= 0 && i < blocks.length; i += dir) {
|
|
8674
9298
|
const next = blocks[i];
|
|
8675
|
-
if (next
|
|
9299
|
+
if (this.skipsCaret(next)) continue;
|
|
8676
9300
|
if (next.type === "table") {
|
|
8677
9301
|
const r = dir === 1 ? 0 : next.rows.length - 1;
|
|
8678
9302
|
const c = Math.min(col, next.align.length - 1);
|
|
@@ -8760,7 +9384,7 @@ var Editor = class {
|
|
|
8760
9384
|
}
|
|
8761
9385
|
case "insertParagraph": {
|
|
8762
9386
|
if (this.suggestions.isOpen && this.suggestions.accept()) return;
|
|
8763
|
-
this.run(splitBlock);
|
|
9387
|
+
this.run((s) => this.collapsed.has(s.selection.focus.blockId) ? splitCollapsedTitle(s) : splitBlock(s));
|
|
8764
9388
|
return;
|
|
8765
9389
|
}
|
|
8766
9390
|
case "insertLineBreak":
|
|
@@ -8829,7 +9453,7 @@ var Editor = class {
|
|
|
8829
9453
|
/** Markdown shortcuts and suggestion menus that typing `text` triggers. */
|
|
8830
9454
|
afterTyping(text) {
|
|
8831
9455
|
const typed = this.state;
|
|
8832
|
-
if (text === " " || text === "-") this.run((s) => applyBlockInputRules(s));
|
|
9456
|
+
if (text === " " || text === "-") this.run((s) => applyBlockInputRules(s, this.markdown));
|
|
8833
9457
|
if (text.length === 1 && "*_`~".includes(text)) this.run((s) => applyInlineInputRules(s));
|
|
8834
9458
|
if (this.markdown.inline.length > 0) this.run((s) => applyTokenInputRules(s, this.markdown.inline) ?? s);
|
|
8835
9459
|
if (text === " " && this.markdown.autolinks) this.run((s) => applyAutolinkInputRule(s) ?? s);
|
|
@@ -8970,7 +9594,7 @@ var Editor = class {
|
|
|
8970
9594
|
if (blockId !== void 0 && block3.id !== blockId) continue;
|
|
8971
9595
|
const el = this.renderer.elementFor(block3.id);
|
|
8972
9596
|
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
|
|
9597
|
+
const containers2 = block3.type === "table" ? block3.rows.flatMap((row, r) => row.map((_, c) => ({ cell: { row: r, col: c } }))) : isTextless(block3) ? [] : [{}];
|
|
8974
9598
|
for (const { cell } of containers2) {
|
|
8975
9599
|
const contentEl = contentElement(el, cell);
|
|
8976
9600
|
const content = containerContent(getBlock(state.doc, block3.id), cell);
|
|
@@ -9074,6 +9698,7 @@ var Editor = class {
|
|
|
9074
9698
|
}
|
|
9075
9699
|
}
|
|
9076
9700
|
if (mod2 && !e.altKey) {
|
|
9701
|
+
if (e.key === "/" && !e.shiftKey) this.refreshSelection();
|
|
9077
9702
|
if (e.key === "/" && !e.shiftKey && this.hasBlockMenu(this.state.selection.focus.blockId)) {
|
|
9078
9703
|
return handled(() => this.openBlockMenu(this.state.selection.focus.blockId));
|
|
9079
9704
|
}
|
|
@@ -9139,7 +9764,7 @@ var Editor = class {
|
|
|
9139
9764
|
const blocks = this.state.doc.blocks;
|
|
9140
9765
|
for (let i = key.from + key.vertical; i >= 0 && i < blocks.length; i += key.vertical) {
|
|
9141
9766
|
const block3 = blocks[i];
|
|
9142
|
-
if (block3
|
|
9767
|
+
if (this.skipsCaret(block3)) continue;
|
|
9143
9768
|
this.caretKey = null;
|
|
9144
9769
|
const row = key.vertical === 1 ? 0 : block3.type === "table" ? block3.rows.length - 1 : 0;
|
|
9145
9770
|
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 +9772,10 @@ var Editor = class {
|
|
|
9147
9772
|
this.scrollCaretIntoView();
|
|
9148
9773
|
return;
|
|
9149
9774
|
}
|
|
9775
|
+
if (key.vertical === 1 && blocks[blocks.length - 1].type === "detailsEnd") {
|
|
9776
|
+
this.caretKey = null;
|
|
9777
|
+
this.run((s) => appendParagraph(s));
|
|
9778
|
+
}
|
|
9150
9779
|
});
|
|
9151
9780
|
}
|
|
9152
9781
|
/** Selects all the text of the block (or table cell) holding `target`. False if it holds none. */
|
|
@@ -9173,6 +9802,13 @@ var Editor = class {
|
|
|
9173
9802
|
e.preventDefault();
|
|
9174
9803
|
return;
|
|
9175
9804
|
}
|
|
9805
|
+
const toggle = e.button === 0 ? target.closest?.(".mbe-details-toggle") : null;
|
|
9806
|
+
const toggleBlock = toggle?.closest(`[${BLOCK_ATTR}]`)?.getAttribute(BLOCK_ATTR);
|
|
9807
|
+
if (toggleBlock && this.root.contains(toggle)) {
|
|
9808
|
+
e.preventDefault();
|
|
9809
|
+
this.setSectionCollapsed(toggleBlock, !this.collapsed.has(toggleBlock));
|
|
9810
|
+
return;
|
|
9811
|
+
}
|
|
9176
9812
|
this.dropBlockSelection();
|
|
9177
9813
|
if (target === this.root && e.button === 0 && !this.readOnly && this.clickBelowLastBlock(e)) return;
|
|
9178
9814
|
const imageEl = e.button === 0 && !e.shiftKey && !this.readOnly ? target.closest?.(".mbe-image") : null;
|
|
@@ -9192,6 +9828,13 @@ var Editor = class {
|
|
|
9192
9828
|
e.preventDefault();
|
|
9193
9829
|
return;
|
|
9194
9830
|
}
|
|
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) {
|
|
9834
|
+
e.preventDefault();
|
|
9835
|
+
this.openBlockMenu(titleBlock, title.getBoundingClientRect());
|
|
9836
|
+
return;
|
|
9837
|
+
}
|
|
9195
9838
|
if (e.button === 0) this.pointerDown = true;
|
|
9196
9839
|
if (target.classList?.contains("mbe-checkbox")) {
|
|
9197
9840
|
e.preventDefault();
|
|
@@ -9207,7 +9850,7 @@ var Editor = class {
|
|
|
9207
9850
|
const blocks = this.state.doc.blocks;
|
|
9208
9851
|
const last = blocks[blocks.length - 1];
|
|
9209
9852
|
const image = last ? imageBlockOffset(last) : null;
|
|
9210
|
-
if (!last || last.type !== "code" && last.type !== "table" && last
|
|
9853
|
+
if (!last || last.type !== "code" && last.type !== "table" && !isTextless(last) && image === null) return false;
|
|
9211
9854
|
const el = this.root.querySelector(`:scope > [data-block-id="${last.id}"]`);
|
|
9212
9855
|
if (!el || e.clientY <= el.getBoundingClientRect().bottom) return false;
|
|
9213
9856
|
e.preventDefault();
|
|
@@ -9233,11 +9876,12 @@ var Editor = class {
|
|
|
9233
9876
|
const link = target.closest?.("a.mbe-link");
|
|
9234
9877
|
if (!link) return;
|
|
9235
9878
|
e.preventDefault();
|
|
9236
|
-
if (this.readOnly || (isMac ? e.metaKey : e.ctrlKey))
|
|
9237
|
-
|
|
9238
|
-
|
|
9239
|
-
|
|
9240
|
-
}
|
|
9879
|
+
if (this.readOnly || (isMac ? e.metaKey : e.ctrlKey)) this.openHref(link.getAttribute("href"), e);
|
|
9880
|
+
}
|
|
9881
|
+
/** Opens a resolved link URL, as a click on a link does: through `onLinkClick`, else in a new tab. */
|
|
9882
|
+
openHref(href, event) {
|
|
9883
|
+
if (!href || this.runtime.onLinkClick?.({ editor: this, href, event })) return;
|
|
9884
|
+
this.root.ownerDocument.defaultView?.open(href, "_blank", "noopener,noreferrer");
|
|
9241
9885
|
}
|
|
9242
9886
|
/** Copies the code of the code block holding `button`, and shows that it did for a moment. */
|
|
9243
9887
|
copyCode(button) {
|
|
@@ -9305,6 +9949,7 @@ var Editor = class {
|
|
|
9305
9949
|
}
|
|
9306
9950
|
onScroll() {
|
|
9307
9951
|
this.blockHandle.hide();
|
|
9952
|
+
this.linkCard?.reposition();
|
|
9308
9953
|
this.resizeHandles.reposition();
|
|
9309
9954
|
if (this.suggestions.isActive || this.toolbar?.isOpen || this.blockMenu.isOpen) this.updateUi();
|
|
9310
9955
|
}
|
|
@@ -9316,7 +9961,7 @@ var Editor = class {
|
|
|
9316
9961
|
if (range) {
|
|
9317
9962
|
if (!e.clipboardData) return;
|
|
9318
9963
|
e.preventDefault();
|
|
9319
|
-
const doc2 = { blocks: this.state.doc.blocks.slice(range.from, range.to + 1).map(cloneBlock) };
|
|
9964
|
+
const doc2 = { blocks: closeSections(this.state.doc.blocks.slice(range.from, range.to + 1).map(cloneBlock)) };
|
|
9320
9965
|
writeClipboard(e.clipboardData, doc2, serializeBlocks(doc2.blocks, this.markdown));
|
|
9321
9966
|
if (cut && !this.readOnly) this.deleteSelectedBlocks();
|
|
9322
9967
|
return;
|
|
@@ -9324,7 +9969,7 @@ var Editor = class {
|
|
|
9324
9969
|
this.refreshSelection();
|
|
9325
9970
|
if (isCollapsed(this.state.selection) || !e.clipboardData) return;
|
|
9326
9971
|
e.preventDefault();
|
|
9327
|
-
const doc = { blocks: selectedBlocks(this.state) };
|
|
9972
|
+
const doc = { blocks: closeSections(selectedBlocks(this.state)) };
|
|
9328
9973
|
writeClipboard(e.clipboardData, doc, serializeMarkdown(doc, this.markdown).replace(/\n$/, ""));
|
|
9329
9974
|
if (cut && !this.readOnly) this.run(deleteSelection);
|
|
9330
9975
|
}
|
|
@@ -9410,7 +10055,7 @@ var Editor = class {
|
|
|
9410
10055
|
/** The slash menu, as a suggestion. */
|
|
9411
10056
|
slashSuggestion() {
|
|
9412
10057
|
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 }));
|
|
10058
|
+
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
10059
|
return {
|
|
9415
10060
|
name: "slash",
|
|
9416
10061
|
trigger: SLASH_CHARS,
|
|
@@ -9444,7 +10089,37 @@ var Editor = class {
|
|
|
9444
10089
|
const doc = this.current.doc;
|
|
9445
10090
|
const a = blockIndex(doc, this.blockSel.anchor);
|
|
9446
10091
|
const h = blockIndex(doc, this.blockSel.head);
|
|
9447
|
-
|
|
10092
|
+
if (a < 0 || h < 0) return null;
|
|
10093
|
+
return this.wholeSections({ from: Math.min(a, h), to: Math.max(a, h) });
|
|
10094
|
+
}
|
|
10095
|
+
/** `range` grown so that a collapsible section with its title or its end in it is in it whole. */
|
|
10096
|
+
wholeSections(range) {
|
|
10097
|
+
const blocks = this.current.doc.blocks;
|
|
10098
|
+
let { from, to } = range;
|
|
10099
|
+
if (!blocks.some((b) => b.type === "details")) return range;
|
|
10100
|
+
for (let changed = true; changed; ) {
|
|
10101
|
+
changed = false;
|
|
10102
|
+
for (let i = from; i <= to; i++) {
|
|
10103
|
+
const block3 = blocks[i];
|
|
10104
|
+
if (block3.type === "details") {
|
|
10105
|
+
const end = sectionEnd(blocks, i) ?? i;
|
|
10106
|
+
if (end > to) to = end, changed = true;
|
|
10107
|
+
} else if (block3.type === "detailsEnd") {
|
|
10108
|
+
const title = sectionTitle(blocks, i);
|
|
10109
|
+
if (title !== null && title < from) from = title, changed = true;
|
|
10110
|
+
}
|
|
10111
|
+
}
|
|
10112
|
+
}
|
|
10113
|
+
return { from, to };
|
|
10114
|
+
}
|
|
10115
|
+
/** The next block a block selection moves to from `index`: blocks shown on screen, not section ends. */
|
|
10116
|
+
nextSelectable(index, dir) {
|
|
10117
|
+
const blocks = this.current.doc.blocks;
|
|
10118
|
+
for (let i = index + dir; i >= 0 && i < blocks.length; i += dir) {
|
|
10119
|
+
const block3 = blocks[i];
|
|
10120
|
+
if (block3.type !== "detailsEnd" && !this.renderer.elementFor(block3.id)?.hasAttribute("data-section-hidden")) return block3.id;
|
|
10121
|
+
}
|
|
10122
|
+
return blocks[index].id;
|
|
9448
10123
|
}
|
|
9449
10124
|
/** Selects whole blocks, from the block `anchor` to the block `head`. */
|
|
9450
10125
|
selectBlockRange(anchor, head) {
|
|
@@ -9513,7 +10188,6 @@ var Editor = class {
|
|
|
9513
10188
|
const blocks = this.state.doc.blocks;
|
|
9514
10189
|
const plain2 = !e.metaKey && !e.ctrlKey && !e.altKey;
|
|
9515
10190
|
const mod2 = isMac ? e.metaKey : e.ctrlKey;
|
|
9516
|
-
const clamp = (i) => blocks[Math.max(0, Math.min(blocks.length - 1, i))].id;
|
|
9517
10191
|
switch (e.key) {
|
|
9518
10192
|
case "Escape":
|
|
9519
10193
|
if (!plain2 || e.shiftKey) return false;
|
|
@@ -9525,9 +10199,11 @@ var Editor = class {
|
|
|
9525
10199
|
if (!plain2) return false;
|
|
9526
10200
|
const up = e.key === "ArrowUp";
|
|
9527
10201
|
if (e.shiftKey) {
|
|
9528
|
-
|
|
10202
|
+
let head = blockIndex(this.current.doc, this.blockSel.head);
|
|
10203
|
+
if (!up && blocks[head]?.type === "details") head = sectionEnd(blocks, head) ?? head;
|
|
10204
|
+
this.selectBlockRange(this.blockSel.anchor, this.nextSelectable(head, up ? -1 : 1));
|
|
9529
10205
|
} else {
|
|
9530
|
-
const id =
|
|
10206
|
+
const id = this.nextSelectable(up ? range.from : range.to, up ? -1 : 1);
|
|
9531
10207
|
this.selectBlockRange(id, id);
|
|
9532
10208
|
}
|
|
9533
10209
|
return true;
|
|
@@ -9588,6 +10264,35 @@ var Editor = class {
|
|
|
9588
10264
|
})));
|
|
9589
10265
|
sections2.push({ title: this.labels.tableSection, items });
|
|
9590
10266
|
}
|
|
10267
|
+
if (block3.type === "quote" && block3.callout) {
|
|
10268
|
+
const current = block3.callout;
|
|
10269
|
+
const items = CALLOUT_TYPES.map((type) => {
|
|
10270
|
+
const name = calloutName(type);
|
|
10271
|
+
return {
|
|
10272
|
+
id: name,
|
|
10273
|
+
label: this.labels[name],
|
|
10274
|
+
icon: this.icon(name),
|
|
10275
|
+
checked: type === current,
|
|
10276
|
+
run: () => this.run((s) => setCallout(s, blockId, type))
|
|
10277
|
+
};
|
|
10278
|
+
});
|
|
10279
|
+
sections2.push({ title: this.labels.callout, items });
|
|
10280
|
+
sections2.push({
|
|
10281
|
+
items: [
|
|
10282
|
+
{
|
|
10283
|
+
id: "delete",
|
|
10284
|
+
label: this.labels.delete,
|
|
10285
|
+
icon: this.icon("delete"),
|
|
10286
|
+
danger: true,
|
|
10287
|
+
run: () => this.run((s) => {
|
|
10288
|
+
const run = quoteRun(s, blockId);
|
|
10289
|
+
return run ? deleteBlocks(s, { from: run.start, to: run.end }) : null;
|
|
10290
|
+
})
|
|
10291
|
+
}
|
|
10292
|
+
]
|
|
10293
|
+
});
|
|
10294
|
+
return sections2;
|
|
10295
|
+
}
|
|
9591
10296
|
const imageOffset = imageBlockOffset(block3);
|
|
9592
10297
|
if (imageOffset !== null) {
|
|
9593
10298
|
const pos = { blockId, offset: imageOffset };
|
|
@@ -9634,15 +10339,26 @@ var Editor = class {
|
|
|
9634
10339
|
}
|
|
9635
10340
|
/**
|
|
9636
10341
|
* @internal
|
|
9637
|
-
* Only large blocks get the block handle and block menu: tables, code blocks
|
|
9638
|
-
* image blocks. Other blocks change type through the slash menu
|
|
9639
|
-
* shortcuts.
|
|
10342
|
+
* Only large blocks get the block handle and block menu: tables, code blocks,
|
|
10343
|
+
* image blocks and callouts. Other blocks change type through the slash menu
|
|
10344
|
+
* or Markdown shortcuts.
|
|
9640
10345
|
*/
|
|
9641
10346
|
hasBlockMenu(blockId) {
|
|
9642
10347
|
const block3 = this.state.doc.blocks.find((b) => b.id === blockId);
|
|
9643
|
-
return block3?.type === "table" || block3?.type === "code" || !!block3 && isImageBlock(block3);
|
|
10348
|
+
return block3?.type === "table" || block3?.type === "code" || block3?.type === "quote" && !!block3.callout || !!block3 && isImageBlock(block3);
|
|
9644
10349
|
}
|
|
9645
|
-
/**
|
|
10350
|
+
/**
|
|
10351
|
+
* @internal
|
|
10352
|
+
* 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
|
|
10354
|
+
* the block itself.
|
|
10355
|
+
*/
|
|
10356
|
+
blockMenuOwner(blockId) {
|
|
10357
|
+
if (!this.hasBlockMenu(blockId)) return null;
|
|
10358
|
+
const run = quoteRun(this.state, blockId);
|
|
10359
|
+
return run ? this.state.doc.blocks[run.start].id : blockId;
|
|
10360
|
+
}
|
|
10361
|
+
/** @internal Opens the block menu of a table, code block, image block or callout, as the block handle and Mod+/ do. */
|
|
9646
10362
|
openBlockMenu(blockId, anchor) {
|
|
9647
10363
|
if (this.readOnly || !this.hasBlockMenu(blockId)) return;
|
|
9648
10364
|
this.dropBlockSelection();
|
|
@@ -9652,7 +10368,7 @@ var Editor = class {
|
|
|
9652
10368
|
if (imageOffset !== null) {
|
|
9653
10369
|
this.current = selectImage(this.state, { blockId, offset: imageOffset });
|
|
9654
10370
|
if (!this.hasFocus()) this.focus();
|
|
9655
|
-
} else if (this.state.selection.focus.blockId !== blockId) {
|
|
10371
|
+
} else if (this.state.selection.focus.blockId !== blockId && !this.inSameCallout(this.state.selection.focus.blockId, blockId)) {
|
|
9656
10372
|
const block3 = getBlock(this.state.doc, blockId);
|
|
9657
10373
|
const start = startOf(block3);
|
|
9658
10374
|
this.current = { ...this.state, selection: { anchor: start, focus: start } };
|
|
@@ -9665,6 +10381,14 @@ var Editor = class {
|
|
|
9665
10381
|
if (rect) this.blockMenu.popup.show(rect, "below");
|
|
9666
10382
|
this.syncActiveDescendant();
|
|
9667
10383
|
}
|
|
10384
|
+
/** True if the blocks `a` and `b` are in the same callout. */
|
|
10385
|
+
inSameCallout(a, b) {
|
|
10386
|
+
const block3 = getBlock(this.state.doc, b);
|
|
10387
|
+
const run = block3.type === "quote" && block3.callout ? quoteRun(this.state, b) : null;
|
|
10388
|
+
if (!run) return false;
|
|
10389
|
+
const i = blockIndex(this.state.doc, a);
|
|
10390
|
+
return i >= run.start && i <= run.end;
|
|
10391
|
+
}
|
|
9668
10392
|
closeBlockMenu() {
|
|
9669
10393
|
this.blockMenu.hide();
|
|
9670
10394
|
this.syncActiveDescendant();
|
|
@@ -9709,6 +10433,7 @@ var Editor = class {
|
|
|
9709
10433
|
// UI that follows the selection
|
|
9710
10434
|
updateUi() {
|
|
9711
10435
|
if (this.destroyed) return;
|
|
10436
|
+
this.expandAroundSelection();
|
|
9712
10437
|
const focused = this.hasFocus();
|
|
9713
10438
|
const pos = this.state.selection.focus;
|
|
9714
10439
|
const el = focused && !this.blockSel && isCollapsed(this.state.selection) ? this.renderer.elementFor(pos.blockId) : void 0;
|
|
@@ -9734,12 +10459,130 @@ var Editor = class {
|
|
|
9734
10459
|
else this.toolbar.hide();
|
|
9735
10460
|
}
|
|
9736
10461
|
if (focused && !this.readOnly && isTouch()) {
|
|
9737
|
-
|
|
10462
|
+
const owner = this.blockMenuOwner(pos.blockId);
|
|
10463
|
+
if (owner) this.blockHandle.showFor(owner);
|
|
9738
10464
|
else this.blockHandle.hide();
|
|
9739
10465
|
}
|
|
9740
10466
|
if (!focused && this.blockMenu.isOpen && !this.root.ownerDocument.activeElement?.closest?.(".mbe-ui")) this.blockMenu.hide();
|
|
10467
|
+
if (this.linkCard) {
|
|
10468
|
+
if (this.readOnly) this.linkCard.hide();
|
|
10469
|
+
else this.linkCard.setCaret(focused && !this.composing && !this.blockSel && !this.suggestions.isActive && !this.blockMenu.isOpen && !this.inputPopover.isOpen ? this.caretLink() : null);
|
|
10470
|
+
}
|
|
9741
10471
|
this.syncActiveDescendant();
|
|
9742
10472
|
}
|
|
10473
|
+
// -------------------------------------------------------------------------
|
|
10474
|
+
// Collapsible sections
|
|
10475
|
+
/**
|
|
10476
|
+
* Collapses or expands the collapsible section titled by the block
|
|
10477
|
+
* `blockId`. This changes the view only: the Markdown, history and events
|
|
10478
|
+
* stay as they are. A caret inside a section that collapses moves to the
|
|
10479
|
+
* end of its title. Returns false when the block is not a section title.
|
|
10480
|
+
*/
|
|
10481
|
+
setSectionCollapsed(blockId, collapsed) {
|
|
10482
|
+
if (this.destroyed) return false;
|
|
10483
|
+
const doc = this.state.doc;
|
|
10484
|
+
const index = blockIndex(doc, blockId);
|
|
10485
|
+
if (doc.blocks[index]?.type !== "details") return false;
|
|
10486
|
+
if (this.collapsed.has(blockId) === collapsed) return true;
|
|
10487
|
+
if (collapsed) this.collapsed.add(blockId);
|
|
10488
|
+
else this.collapsed.delete(blockId);
|
|
10489
|
+
if (collapsed) {
|
|
10490
|
+
const end = sectionEnd(doc.blocks, index) ?? index;
|
|
10491
|
+
const inside = (p) => {
|
|
10492
|
+
const i = blockIndex(doc, p.blockId);
|
|
10493
|
+
return i > index && i <= end;
|
|
10494
|
+
};
|
|
10495
|
+
const { anchor, focus } = this.state.selection;
|
|
10496
|
+
if (inside(anchor) || inside(focus)) {
|
|
10497
|
+
const title = endOf(doc.blocks[index]);
|
|
10498
|
+
this.dropBlockSelection();
|
|
10499
|
+
this.current = { ...this.current, selection: { anchor: title, focus: title }, storedMarks: null };
|
|
10500
|
+
this.syncDomSelection();
|
|
10501
|
+
}
|
|
10502
|
+
}
|
|
10503
|
+
this.renderer.updateSections(doc);
|
|
10504
|
+
this.updateUi();
|
|
10505
|
+
return true;
|
|
10506
|
+
}
|
|
10507
|
+
/** True when the section titled by `blockId` is shown collapsed. */
|
|
10508
|
+
isSectionCollapsed(blockId) {
|
|
10509
|
+
return this.collapsed.has(blockId);
|
|
10510
|
+
}
|
|
10511
|
+
/** Sections that are not saved open start collapsed, as a Markdown renderer shows them. */
|
|
10512
|
+
collapseClosedSections(doc) {
|
|
10513
|
+
for (const block3 of doc.blocks) if (block3.type === "details" && !block3.open) this.collapsed.add(block3.id);
|
|
10514
|
+
}
|
|
10515
|
+
/** Expands the collapsed sections around the selection's focus, so the caret is never hidden. */
|
|
10516
|
+
expandAroundSelection() {
|
|
10517
|
+
if (this.collapsed.size === 0) return;
|
|
10518
|
+
const focusId = this.state.selection.focus.blockId;
|
|
10519
|
+
if (!this.renderer.elementFor(focusId)?.hasAttribute("data-section-hidden")) return;
|
|
10520
|
+
const titles = [];
|
|
10521
|
+
for (const block3 of this.state.doc.blocks) {
|
|
10522
|
+
if (block3.id === focusId) break;
|
|
10523
|
+
if (block3.type === "details") titles.push(block3.id);
|
|
10524
|
+
else if (block3.type === "detailsEnd") titles.pop();
|
|
10525
|
+
}
|
|
10526
|
+
for (const id of titles) this.collapsed.delete(id);
|
|
10527
|
+
this.renderer.updateSections(this.state.doc);
|
|
10528
|
+
}
|
|
10529
|
+
/** Blocks the caret passes over: dividers, section ends, and blocks inside a collapsed section. */
|
|
10530
|
+
skipsCaret(block3) {
|
|
10531
|
+
return isTextless(block3) || !!this.renderer.elementFor(block3.id)?.hasAttribute("data-section-hidden");
|
|
10532
|
+
}
|
|
10533
|
+
// -------------------------------------------------------------------------
|
|
10534
|
+
// Links (see ui/linkCard.ts)
|
|
10535
|
+
/** The link the caret is inside, not at its edge, with its element. */
|
|
10536
|
+
caretLink() {
|
|
10537
|
+
if (!isCollapsed(this.state.selection)) return null;
|
|
10538
|
+
const link = activeLink(this.state);
|
|
10539
|
+
if (!link || link.pos.offset <= link.from || link.pos.offset >= link.to) return null;
|
|
10540
|
+
const blockEl = this.renderer.elementFor(link.pos.blockId);
|
|
10541
|
+
if (!blockEl) return null;
|
|
10542
|
+
const start = { ...link.pos, offset: link.from };
|
|
10543
|
+
for (const el of blockEl.querySelectorAll("a.mbe-link")) {
|
|
10544
|
+
const pos = this.linkStart(el);
|
|
10545
|
+
if (pos && samePosition(pos, start)) return this.linkTargetOf(el);
|
|
10546
|
+
}
|
|
10547
|
+
return null;
|
|
10548
|
+
}
|
|
10549
|
+
/** The document position where a rendered link starts. */
|
|
10550
|
+
linkStart(el) {
|
|
10551
|
+
return domToPosition(this.root, el, 0);
|
|
10552
|
+
}
|
|
10553
|
+
/** The link a rendered link element shows, or null for one outside the document's blocks. */
|
|
10554
|
+
linkTargetOf(el) {
|
|
10555
|
+
if (el.closest(".mbe-flow")) return null;
|
|
10556
|
+
const pos = this.linkStart(el);
|
|
10557
|
+
if (!pos) return null;
|
|
10558
|
+
const block3 = this.state.doc.blocks.find((b) => b.id === pos.blockId);
|
|
10559
|
+
const content = block3 && containerContent(block3, pos.cell);
|
|
10560
|
+
const link = content && linkAt(content, pos.offset);
|
|
10561
|
+
return link && link.from === pos.offset ? { el, href: link.href } : null;
|
|
10562
|
+
}
|
|
10563
|
+
/** The selection of a link's whole text, from a rendered link element. */
|
|
10564
|
+
linkSelection(target) {
|
|
10565
|
+
const from = this.linkStart(target.el);
|
|
10566
|
+
if (!from) return null;
|
|
10567
|
+
const block3 = getBlock(this.state.doc, from.blockId);
|
|
10568
|
+
const content = containerContent(block3, from.cell);
|
|
10569
|
+
const link = content && linkAt(content, from.offset);
|
|
10570
|
+
return link ? { anchor: from, focus: { ...from, offset: link.to } } : null;
|
|
10571
|
+
}
|
|
10572
|
+
/** Opens the link popover for a link, as Mod+K does with the caret in it. */
|
|
10573
|
+
editLink(target) {
|
|
10574
|
+
const range = this.linkSelection(target);
|
|
10575
|
+
if (!range || this.readOnly) return;
|
|
10576
|
+
this.focus();
|
|
10577
|
+
this.setSelection(range);
|
|
10578
|
+
this.openLinkPopover();
|
|
10579
|
+
}
|
|
10580
|
+
/** Removes a link and keeps its text, as one undo step. */
|
|
10581
|
+
removeLink(target) {
|
|
10582
|
+
const range = this.linkSelection(target);
|
|
10583
|
+
if (!range || this.readOnly) return;
|
|
10584
|
+
this.run((s) => ({ ...setLink({ ...s, selection: range }, null), selection: s.selection }));
|
|
10585
|
+
}
|
|
9743
10586
|
/** Marks the selected image's element, and hides the browser's selection highlight over it. */
|
|
9744
10587
|
paintSelectedImage(el) {
|
|
9745
10588
|
if (this.selectedImageEl !== el) {
|
|
@@ -9812,6 +10655,7 @@ var Editor = class {
|
|
|
9812
10655
|
this.blockMenu.hide();
|
|
9813
10656
|
this.toolbar?.hide();
|
|
9814
10657
|
this.blockHandle.hide();
|
|
10658
|
+
this.linkCard?.setCaret(null);
|
|
9815
10659
|
this.resizeHandles.hide();
|
|
9816
10660
|
this.paintSelectedImage(null);
|
|
9817
10661
|
this.hintEl?.classList.remove("mbe-show-hint");
|
|
@@ -9841,6 +10685,8 @@ function blockName(block3) {
|
|
|
9841
10685
|
return "blockquote";
|
|
9842
10686
|
case "code":
|
|
9843
10687
|
return "codeBlock";
|
|
10688
|
+
case "detailsEnd":
|
|
10689
|
+
return "details";
|
|
9844
10690
|
default:
|
|
9845
10691
|
return block3.type;
|
|
9846
10692
|
}
|
|
@@ -10178,6 +11024,7 @@ function fileHandler(options) {
|
|
|
10178
11024
|
}
|
|
10179
11025
|
export {
|
|
10180
11026
|
ATOM_CHAR,
|
|
11027
|
+
CALLOUT_TYPES,
|
|
10181
11028
|
DEFAULT_LABELS,
|
|
10182
11029
|
Editor,
|
|
10183
11030
|
MARK_ORDER,
|
|
@@ -10197,6 +11044,8 @@ export {
|
|
|
10197
11044
|
defaultKeymap,
|
|
10198
11045
|
defaultResolveUrl,
|
|
10199
11046
|
deleteInline,
|
|
11047
|
+
details,
|
|
11048
|
+
detailsEnd,
|
|
10200
11049
|
divider,
|
|
10201
11050
|
docToHtml,
|
|
10202
11051
|
emptyTable,
|
|
@@ -10216,6 +11065,7 @@ export {
|
|
|
10216
11065
|
isImageBlock,
|
|
10217
11066
|
isPlainTextBlock,
|
|
10218
11067
|
isTextBlock,
|
|
11068
|
+
isTextless,
|
|
10219
11069
|
linkAt,
|
|
10220
11070
|
listItem,
|
|
10221
11071
|
loadMarkdown,
|