@usememos/editor 26.10.12 → 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 +59 -13
- package/dist/base.css +101 -31
- 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 +1146 -114
- package/dist/index.js.map +4 -4
- package/dist/react.js.map +2 -2
- package/dist/style.css +310 -55
- package/dist/theme.css +86 -25
- package/dist/types/commands.d.ts +48 -3
- package/dist/types/editor.d.ts +65 -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 +21 -0
- package/dist/types/markdown/blocks.d.ts +2 -0
- package/dist/types/markdown/htmlSection.d.ts +37 -0
- 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 +10 -1
- 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 +12 -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,11 @@ 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",
|
|
2346
|
+
/** Shown in the empty paragraph that has the caret, with the `slashHint` option. */
|
|
2145
2347
|
slashHint: "Type '/' for commands",
|
|
2146
2348
|
blockHandle: "Open block menu",
|
|
2147
2349
|
listHint: "List",
|
|
@@ -2189,6 +2391,8 @@ var ICONS = {
|
|
|
2189
2391
|
heading2: ["M4 12h8", "M4 18V6", "M12 18V6", "M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1"],
|
|
2190
2392
|
/** `heading-3` */
|
|
2191
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"],
|
|
2192
2396
|
/** `list` */
|
|
2193
2397
|
bulletList: ["M3 5h.01", "M3 12h.01", "M3 19h.01", "M8 5h13", "M8 12h13", "M8 19h13"],
|
|
2194
2398
|
/** `list-ordered` */
|
|
@@ -2197,6 +2401,24 @@ var ICONS = {
|
|
|
2197
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" }]],
|
|
2198
2402
|
/** `text-quote` */
|
|
2199
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"],
|
|
2200
2422
|
/** `square-code` */
|
|
2201
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" }]],
|
|
2202
2424
|
/** `table` */
|
|
@@ -2261,6 +2483,14 @@ var ICONS = {
|
|
|
2261
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" }]],
|
|
2262
2484
|
/** `code` */
|
|
2263
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"],
|
|
2264
2494
|
/** `link` */
|
|
2265
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"],
|
|
2266
2496
|
/** `image-off` */
|
|
@@ -2360,7 +2590,7 @@ function inlineNodesText(nodes, soft) {
|
|
|
2360
2590
|
import { lookupEntity } from "#entities";
|
|
2361
2591
|
|
|
2362
2592
|
// src/markdown/options.ts
|
|
2363
|
-
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: "" };
|
|
2364
2594
|
var resolved = /* @__PURE__ */ new WeakMap();
|
|
2365
2595
|
function resolveMarkdown(options) {
|
|
2366
2596
|
if (!options) return DEFAULT_MARKDOWN;
|
|
@@ -2371,6 +2601,8 @@ function resolveMarkdown(options) {
|
|
|
2371
2601
|
breaks: options.breaks ?? false,
|
|
2372
2602
|
setext: options.setext ?? true,
|
|
2373
2603
|
autolinks: options.autolinks ?? true,
|
|
2604
|
+
callouts: options.callouts ?? true,
|
|
2605
|
+
details: options.details ?? true,
|
|
2374
2606
|
syntax,
|
|
2375
2607
|
inline: syntax.flatMap((s) => s.inline ?? []),
|
|
2376
2608
|
block: syntax.flatMap((s) => s.block ?? []),
|
|
@@ -2518,11 +2750,26 @@ function lowerList(list, depth, out, o) {
|
|
|
2518
2750
|
});
|
|
2519
2751
|
}
|
|
2520
2752
|
function lowerQuote(children, out, o) {
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
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) };
|
|
2526
2773
|
}
|
|
2527
2774
|
|
|
2528
2775
|
// src/markdown/inline.ts
|
|
@@ -2635,6 +2882,10 @@ function decodeEntity(entity2) {
|
|
|
2635
2882
|
}
|
|
2636
2883
|
return lookupEntity(entity2.slice(1, -1)) ?? null;
|
|
2637
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
|
+
}
|
|
2638
2889
|
function unescapeString(s) {
|
|
2639
2890
|
if (!s.includes("\\") && !s.includes("&")) return s;
|
|
2640
2891
|
return s.replace(reEntityOrEscapedChar, (m) => m[0] === "\\" ? m[1] : decodeEntity(m) ?? m);
|
|
@@ -3354,6 +3605,10 @@ var reHtmlBlockOpen = [
|
|
|
3354
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,
|
|
3355
3606
|
new RegExp(`^(?:${OPENTAG}|${CLOSETAG})[ \\t]*$`, "i")
|
|
3356
3607
|
];
|
|
3608
|
+
function interruptsParagraph(text) {
|
|
3609
|
+
for (let type = 1; type <= 6; type++) if (reHtmlBlockOpen[type].test(text)) return true;
|
|
3610
|
+
return false;
|
|
3611
|
+
}
|
|
3357
3612
|
var reHtmlBlockClose = [
|
|
3358
3613
|
/^$/,
|
|
3359
3614
|
/<\/(?:script|pre|textarea|style)>/i,
|
|
@@ -4069,6 +4324,116 @@ function parseDelimiterRow(line) {
|
|
|
4069
4324
|
return align;
|
|
4070
4325
|
}
|
|
4071
4326
|
|
|
4327
|
+
// src/markdown/htmlSection.ts
|
|
4328
|
+
var VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
4329
|
+
"area",
|
|
4330
|
+
"base",
|
|
4331
|
+
"br",
|
|
4332
|
+
"col",
|
|
4333
|
+
"embed",
|
|
4334
|
+
"hr",
|
|
4335
|
+
"img",
|
|
4336
|
+
"input",
|
|
4337
|
+
"keygen",
|
|
4338
|
+
"link",
|
|
4339
|
+
"meta",
|
|
4340
|
+
"param",
|
|
4341
|
+
"source",
|
|
4342
|
+
"track",
|
|
4343
|
+
"wbr"
|
|
4344
|
+
]);
|
|
4345
|
+
var reOpaque = /<!--[\s\S]*?-->|<(script|style|textarea|pre)\b[^>]*>[\s\S]*?<\/\1\s*>/gi;
|
|
4346
|
+
var reTag = /<(\/?)([A-Za-z][A-Za-z0-9-]*)\b(?:[^>"']|"[^"]*"|'[^']*')*?(\/?)>/g;
|
|
4347
|
+
function applyTags(html, open) {
|
|
4348
|
+
const text = html.replace(reOpaque, "");
|
|
4349
|
+
reTag.lastIndex = 0;
|
|
4350
|
+
for (let m = reTag.exec(text); m; m = reTag.exec(text)) {
|
|
4351
|
+
const name = m[2].toLowerCase();
|
|
4352
|
+
if (!m[1]) {
|
|
4353
|
+
if (!m[3] && !VOID_ELEMENTS.has(name)) open.push(name);
|
|
4354
|
+
continue;
|
|
4355
|
+
}
|
|
4356
|
+
const at = open.lastIndexOf(name);
|
|
4357
|
+
if (at >= 0) open.length = at;
|
|
4358
|
+
}
|
|
4359
|
+
}
|
|
4360
|
+
function htmlSectionEnd(nodes, i) {
|
|
4361
|
+
const first = nodes[i];
|
|
4362
|
+
if (first.type !== "htmlBlock") return i;
|
|
4363
|
+
const open = [];
|
|
4364
|
+
applyTags(first.value, open);
|
|
4365
|
+
if (open.length === 0) return i;
|
|
4366
|
+
for (let j = i + 1; j < nodes.length; j++) {
|
|
4367
|
+
const node = nodes[j];
|
|
4368
|
+
if (node.type !== "htmlBlock") continue;
|
|
4369
|
+
applyTags(node.value, open);
|
|
4370
|
+
if (open.length === 0) return j;
|
|
4371
|
+
}
|
|
4372
|
+
return i;
|
|
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
|
+
}
|
|
4397
|
+
var slotMarker = (index) => `\uE000${index}\uE001`;
|
|
4398
|
+
var SLOT_MARKER = /(\d+)/g;
|
|
4399
|
+
function splitHtmlSection(source, options = DEFAULT_MARKDOWN) {
|
|
4400
|
+
const root = parseAst(source, options);
|
|
4401
|
+
if (root.children.every((node) => node.type === "htmlBlock")) return null;
|
|
4402
|
+
const lineStarts = [0];
|
|
4403
|
+
const lineEnds = [];
|
|
4404
|
+
const re = /\r\n|\n|\r/g;
|
|
4405
|
+
for (let m = re.exec(source); m; m = re.exec(source)) {
|
|
4406
|
+
lineEnds.push(m.index);
|
|
4407
|
+
lineStarts.push(m.index + m[0].length);
|
|
4408
|
+
}
|
|
4409
|
+
lineEnds.push(source.length);
|
|
4410
|
+
const textOf = (i) => {
|
|
4411
|
+
const lines = root.lines[i];
|
|
4412
|
+
const from = lineStarts[lines.start - 1] ?? source.length;
|
|
4413
|
+
const to = lineEnds[Math.max(lines.start, lines.end) - 1] ?? source.length;
|
|
4414
|
+
return source.slice(from, Math.max(from, to));
|
|
4415
|
+
};
|
|
4416
|
+
const parts = [];
|
|
4417
|
+
const slots = [];
|
|
4418
|
+
let slot = null;
|
|
4419
|
+
root.children.forEach((node, i) => {
|
|
4420
|
+
if (node.type === "htmlBlock") {
|
|
4421
|
+
slot = null;
|
|
4422
|
+
parts.push(textOf(i));
|
|
4423
|
+
return;
|
|
4424
|
+
}
|
|
4425
|
+
if (!slot) {
|
|
4426
|
+
slot = [];
|
|
4427
|
+
slots.push(slot);
|
|
4428
|
+
parts.push(`
|
|
4429
|
+
${slotMarker(slots.length - 1)}
|
|
4430
|
+
`);
|
|
4431
|
+
}
|
|
4432
|
+
slot.push(...lowerTopLevel(node, options, textOf(i)));
|
|
4433
|
+
});
|
|
4434
|
+
return { html: parts.join("\n"), slots };
|
|
4435
|
+
}
|
|
4436
|
+
|
|
4072
4437
|
// src/markdown/serialize.ts
|
|
4073
4438
|
function serializeMarkdown(doc, options = {}) {
|
|
4074
4439
|
if (options.source) return saveWithSource(doc.blocks, options.source, options);
|
|
@@ -4083,7 +4448,6 @@ function serializeBlocks(blocks, options) {
|
|
|
4083
4448
|
let prev = null;
|
|
4084
4449
|
const lists = new ListState(ctx.paragraph);
|
|
4085
4450
|
for (const block3 of blocks) {
|
|
4086
|
-
if (block3.type === "quote" && block3.content.length === 0) continue;
|
|
4087
4451
|
let text;
|
|
4088
4452
|
let separator = "\n\n";
|
|
4089
4453
|
switch (block3.type) {
|
|
@@ -4091,8 +4455,12 @@ function serializeBlocks(blocks, options) {
|
|
|
4091
4455
|
text = block3.content.length === 0 ? " " : inlineToMarkdown(block3.content, ctx.paragraph);
|
|
4092
4456
|
break;
|
|
4093
4457
|
case "quote": {
|
|
4094
|
-
|
|
4095
|
-
|
|
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}`;
|
|
4462
|
+
text = prefixLines(body, "> ", ">");
|
|
4463
|
+
if (joined) separator = "\n>\n";
|
|
4096
4464
|
break;
|
|
4097
4465
|
}
|
|
4098
4466
|
case "heading":
|
|
@@ -4116,6 +4484,15 @@ function serializeBlocks(blocks, options) {
|
|
|
4116
4484
|
case "divider":
|
|
4117
4485
|
text = "---";
|
|
4118
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;
|
|
4119
4496
|
}
|
|
4120
4497
|
if (out) out += separator;
|
|
4121
4498
|
out += text;
|
|
@@ -4151,7 +4528,7 @@ function serializeCode(language, text) {
|
|
|
4151
4528
|
${text ? text + "\n" : ""}${fence}`;
|
|
4152
4529
|
}
|
|
4153
4530
|
function serializeTable(align, rows, ctx) {
|
|
4154
|
-
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(" | ") + " |";
|
|
4155
4532
|
const delimiter = "| " + align.map((a) => a === "left" ? ":--" : a === "center" ? ":-:" : a === "right" ? "--:" : "---").join(" | ") + " |";
|
|
4156
4533
|
const [header, ...body] = rows;
|
|
4157
4534
|
return [row(header ?? align.map(() => [])), delimiter, ...body.map(row)].join("\n");
|
|
@@ -4232,6 +4609,25 @@ function sameInline(a, b) {
|
|
|
4232
4609
|
});
|
|
4233
4610
|
}
|
|
4234
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
|
+
}
|
|
4235
4631
|
function representableInline(inline3) {
|
|
4236
4632
|
let spans = normalizeInline(
|
|
4237
4633
|
inline3.flatMap((s) => {
|
|
@@ -4257,7 +4653,7 @@ function representableInline(inline3) {
|
|
|
4257
4653
|
for (const span of spans) {
|
|
4258
4654
|
if (span.marks.includes(mark)) {
|
|
4259
4655
|
if (runStart < 0) runStart = pos;
|
|
4260
|
-
runText += span.text;
|
|
4656
|
+
runText += span.marks.includes("code") ? "x".repeat(span.text.length) : span.text;
|
|
4261
4657
|
} else {
|
|
4262
4658
|
endRun();
|
|
4263
4659
|
}
|
|
@@ -4437,8 +4833,10 @@ function render(spans, ctx, strategy, bare = false) {
|
|
|
4437
4833
|
let out = "";
|
|
4438
4834
|
tokens.forEach((tok, i) => {
|
|
4439
4835
|
if (tok.kind === "delim") out += tok.ch.repeat(tok.count);
|
|
4440
|
-
else if (tok.kind === "raw")
|
|
4441
|
-
|
|
4836
|
+
else if (tok.kind === "raw") {
|
|
4837
|
+
if (ctx.lineStart && out.endsWith("\n") && interruptsParagraph(tok.text)) out += " ";
|
|
4838
|
+
out += tok.text;
|
|
4839
|
+
} else {
|
|
4442
4840
|
out += escapeText(tok, ctx, {
|
|
4443
4841
|
before: out ? out[out.length - 1] : void 0,
|
|
4444
4842
|
after: edgeChar(tokens[i + 1], "first"),
|
|
@@ -4631,14 +5029,16 @@ function loadMarkdown(text, options) {
|
|
|
4631
5029
|
const groups = [];
|
|
4632
5030
|
const groupOf = /* @__PURE__ */ new WeakMap();
|
|
4633
5031
|
let lastEnd = 0;
|
|
5032
|
+
const sections2 = (options ?? DEFAULT_MARKDOWN).details === false ? null : detailsSections(root.children);
|
|
4634
5033
|
for (let i = 0; i < root.children.length; i++) {
|
|
4635
5034
|
const node = root.children[i];
|
|
4636
|
-
const
|
|
5035
|
+
const section = sections2?.get(i);
|
|
5036
|
+
const last = section ? i : htmlSectionEnd(root.children, i);
|
|
4637
5037
|
const from = lineStarts[root.lines[i].start - 1] ?? text.length;
|
|
4638
5038
|
const lines = root.lines[last];
|
|
4639
5039
|
const to = lineEnds[Math.max(lines.start, lines.end) - 1] ?? text.length;
|
|
4640
5040
|
const source = text.slice(from, to);
|
|
4641
|
-
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);
|
|
4642
5042
|
i = last;
|
|
4643
5043
|
blocks.push(...lowered);
|
|
4644
5044
|
if (lowered.length === 0 || from < lastEnd || to < from) continue;
|
|
@@ -4650,22 +5050,12 @@ function loadMarkdown(text, options) {
|
|
|
4650
5050
|
}
|
|
4651
5051
|
return { doc: { blocks }, source: { text, groups, groupOf, definitions: root.definitions } };
|
|
4652
5052
|
}
|
|
4653
|
-
function detailsEnd(nodes, i) {
|
|
4654
|
-
if (nodes[i].type !== "htmlBlock") return i;
|
|
4655
|
-
let depth = 0;
|
|
4656
|
-
for (let j = i; j < nodes.length; j++) {
|
|
4657
|
-
const node = nodes[j];
|
|
4658
|
-
if (node.type !== "htmlBlock") continue;
|
|
4659
|
-
depth += (node.value.match(/<details\b/gi)?.length ?? 0) - (node.value.match(/<\/details\s*>/gi)?.length ?? 0);
|
|
4660
|
-
if (depth <= 0) return j;
|
|
4661
|
-
}
|
|
4662
|
-
return i;
|
|
4663
|
-
}
|
|
4664
5053
|
function isOpen(source, options) {
|
|
4665
5054
|
return parseAst(source + "\n\nx", options).children.length < 2;
|
|
4666
5055
|
}
|
|
4667
5056
|
function joins(a, b) {
|
|
4668
|
-
|
|
5057
|
+
if (a?.type === "quote" && b?.type === "quote") return a.callout === b.callout;
|
|
5058
|
+
return a?.type === "listItem" && b?.type === "listItem";
|
|
4669
5059
|
}
|
|
4670
5060
|
function saveWithSource(blocks, source, options) {
|
|
4671
5061
|
const text = source.text;
|
|
@@ -5196,10 +5586,12 @@ function defaultKeymap() {
|
|
|
5196
5586
|
"Mod-Alt-1": ({ editor }) => editor.commands.toggleHeading({ level: 1 }) || true,
|
|
5197
5587
|
"Mod-Alt-2": ({ editor }) => editor.commands.toggleHeading({ level: 2 }) || true,
|
|
5198
5588
|
"Mod-Alt-3": ({ editor }) => editor.commands.toggleHeading({ level: 3 }) || true,
|
|
5589
|
+
"Mod-Alt-4": ({ editor }) => editor.commands.toggleHeading({ level: 4 }) || true,
|
|
5199
5590
|
"Mod-Alt-c": ({ editor }) => editor.commands.toggleCodeBlock() || true,
|
|
5200
5591
|
"Mod-Shift-7": ({ editor }) => editor.commands.toggleOrderedList() || true,
|
|
5201
5592
|
"Mod-Shift-8": ({ editor }) => editor.commands.toggleBulletList() || true,
|
|
5202
5593
|
"Mod-Shift-9": ({ editor }) => editor.commands.toggleTaskList() || true,
|
|
5594
|
+
"Mod-Shift-6": ({ editor }) => editor.commands.toggleDetails() || true,
|
|
5203
5595
|
"Mod-a": ({ editor }) => selectAll2(editor),
|
|
5204
5596
|
"Mod-z": ({ editor }) => editor.commands.undo() || true,
|
|
5205
5597
|
"Mod-Shift-z": ({ editor }) => editor.commands.redo() || true,
|
|
@@ -5911,7 +6303,8 @@ var TEXT_STYLES = [
|
|
|
5911
6303
|
{ id: "text", spec: { type: "paragraph" }, keys: mod("Alt+0") },
|
|
5912
6304
|
{ id: "heading1", spec: { type: "heading", level: 1 }, keys: mod("Alt+1") },
|
|
5913
6305
|
{ id: "heading2", spec: { type: "heading", level: 2 }, keys: mod("Alt+2") },
|
|
5914
|
-
{ 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") }
|
|
5915
6308
|
];
|
|
5916
6309
|
var LIST_TYPES = [
|
|
5917
6310
|
{ id: "bulletList", listType: "bullet", keys: mod("Shift+8") },
|
|
@@ -5922,7 +6315,7 @@ var TOOLTIP_DELAY = 500;
|
|
|
5922
6315
|
var TOOLTIP_GRACE = 300;
|
|
5923
6316
|
function blockState(editor) {
|
|
5924
6317
|
const blocks = convertibleBlocks(editor.state);
|
|
5925
|
-
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;
|
|
5926
6319
|
const every = (f) => {
|
|
5927
6320
|
const first = blocks[0] ? f(blocks[0]) : null;
|
|
5928
6321
|
return blocks.every((b) => f(b) === first) ? first : null;
|
|
@@ -6262,6 +6655,9 @@ var FILL_ATTR = "data-mbe-fill";
|
|
|
6262
6655
|
var ATOM_ATTR = "data-atom";
|
|
6263
6656
|
var LIST_START_ATTR = "data-list-start";
|
|
6264
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";
|
|
6265
6661
|
var MARK_TAGS = {
|
|
6266
6662
|
bold: ["strong"],
|
|
6267
6663
|
italic: ["em"],
|
|
@@ -6291,6 +6687,11 @@ function blockClasses(block3, theme) {
|
|
|
6291
6687
|
return theme.raw;
|
|
6292
6688
|
case "divider":
|
|
6293
6689
|
return void 0;
|
|
6690
|
+
// on the <hr>
|
|
6691
|
+
case "details":
|
|
6692
|
+
return theme.details;
|
|
6693
|
+
case "detailsEnd":
|
|
6694
|
+
return void 0;
|
|
6294
6695
|
}
|
|
6295
6696
|
}
|
|
6296
6697
|
var defaultResolveUrl = (url) => {
|
|
@@ -6309,6 +6710,9 @@ function sameReveal(a, b) {
|
|
|
6309
6710
|
for (const key of a) if (!b.has(key)) return false;
|
|
6310
6711
|
return true;
|
|
6311
6712
|
}
|
|
6713
|
+
function calloutName(type) {
|
|
6714
|
+
return `callout${type[0].toUpperCase()}${type.slice(1)}`;
|
|
6715
|
+
}
|
|
6312
6716
|
function markImageBlock(el, block3) {
|
|
6313
6717
|
const offset = imageBlockOffset(block3);
|
|
6314
6718
|
if (offset === null) return;
|
|
@@ -6316,6 +6720,24 @@ function markImageBlock(el, block3) {
|
|
|
6316
6720
|
const align = sliceInline(block3.content, offset, offset + 1)[0]?.image?.align;
|
|
6317
6721
|
if (align) el.dataset.align = align;
|
|
6318
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
|
+
}
|
|
6319
6741
|
function renderBlock(block3, ctx, reveal) {
|
|
6320
6742
|
const { doc, labels } = ctx;
|
|
6321
6743
|
const el = (tag, className2) => {
|
|
@@ -6328,6 +6750,10 @@ function renderBlock(block3, ctx, reveal) {
|
|
|
6328
6750
|
case "paragraph":
|
|
6329
6751
|
case "heading":
|
|
6330
6752
|
case "quote":
|
|
6753
|
+
if (block3.type === "quote" && block3.callout) {
|
|
6754
|
+
root = renderCallout(block3, block3.callout, ctx, reveal);
|
|
6755
|
+
break;
|
|
6756
|
+
}
|
|
6331
6757
|
root = el(block3.type === "paragraph" ? "p" : block3.type === "quote" ? "blockquote" : `h${block3.level}`);
|
|
6332
6758
|
root.dir = "auto";
|
|
6333
6759
|
fillContent(root, block3.content, ctx, block3, reveal);
|
|
@@ -6381,11 +6807,15 @@ function renderBlock(block3, ctx, reveal) {
|
|
|
6381
6807
|
break;
|
|
6382
6808
|
}
|
|
6383
6809
|
case "raw": {
|
|
6384
|
-
const
|
|
6810
|
+
const source = inlineText(block3.content);
|
|
6811
|
+
const section = block3.syntax === "html" && !reveal?.has(REVEAL_BLOCK) && ctx.views?.has("html") ? splitHtmlSection(source, ctx.markdown) : null;
|
|
6812
|
+
const view = reveal?.has(REVEAL_BLOCK) ? null : ctx.view?.(block3.syntax, section ? section.html : source, "block");
|
|
6385
6813
|
if (view) {
|
|
6386
6814
|
root = view;
|
|
6387
6815
|
root.classList.add("mbe-view-block");
|
|
6816
|
+
if (block3.syntax === "html") root.classList.add("mbe-view-html");
|
|
6388
6817
|
root.contentEditable = "false";
|
|
6818
|
+
if (section) fillSlots(root, section.slots.length, (i) => renderFlow(section.slots[i], ctx), ctx.doc);
|
|
6389
6819
|
} else {
|
|
6390
6820
|
root = el("pre");
|
|
6391
6821
|
root.spellcheck = false;
|
|
@@ -6399,6 +6829,26 @@ function renderBlock(block3, ctx, reveal) {
|
|
|
6399
6829
|
root.contentEditable = "false";
|
|
6400
6830
|
root.appendChild(el("hr", ctx.classes.divider));
|
|
6401
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;
|
|
6402
6852
|
case "table": {
|
|
6403
6853
|
root = el("div");
|
|
6404
6854
|
root.contentEditable = "false";
|
|
@@ -6425,7 +6875,8 @@ function renderBlock(block3, ctx, reveal) {
|
|
|
6425
6875
|
}
|
|
6426
6876
|
}
|
|
6427
6877
|
root.setAttribute(BLOCK_ATTR, block3.id);
|
|
6428
|
-
|
|
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}`;
|
|
6429
6880
|
if (block3.type === "listItem" && block3.checked) className += " mbe-checked";
|
|
6430
6881
|
if ("content" in block3 && inlineLength(block3.content) === 0) className += " mbe-empty";
|
|
6431
6882
|
const themed = blockClasses(block3, ctx.classes);
|
|
@@ -6462,6 +6913,61 @@ function copyButton(ctx) {
|
|
|
6462
6913
|
if (icon) button.appendChild(icon);
|
|
6463
6914
|
return button;
|
|
6464
6915
|
}
|
|
6916
|
+
function fillSlots(root, count, content, doc) {
|
|
6917
|
+
if (count === 0) return;
|
|
6918
|
+
const texts = [];
|
|
6919
|
+
const walker = doc.createTreeWalker(
|
|
6920
|
+
root,
|
|
6921
|
+
4
|
|
6922
|
+
/* NodeFilter.SHOW_TEXT */
|
|
6923
|
+
);
|
|
6924
|
+
for (let node = walker.nextNode(); node; node = walker.nextNode()) if (node.nodeValue.includes("\uE000")) texts.push(node);
|
|
6925
|
+
const placed = /* @__PURE__ */ new Set();
|
|
6926
|
+
for (const text of texts) {
|
|
6927
|
+
const value = text.nodeValue;
|
|
6928
|
+
const fragment = doc.createDocumentFragment();
|
|
6929
|
+
let last = 0;
|
|
6930
|
+
for (const m of value.matchAll(SLOT_MARKER)) {
|
|
6931
|
+
if (m.index > last) fragment.append(value.slice(last, m.index));
|
|
6932
|
+
const index = Number(m[1]);
|
|
6933
|
+
if (index < count && !placed.has(index)) {
|
|
6934
|
+
placed.add(index);
|
|
6935
|
+
fragment.append(content(index));
|
|
6936
|
+
}
|
|
6937
|
+
last = m.index + m[0].length;
|
|
6938
|
+
}
|
|
6939
|
+
if (last < value.length) fragment.append(value.slice(last));
|
|
6940
|
+
const parent = text.parentElement;
|
|
6941
|
+
const alone = parent !== root && parent?.tagName === "P" && parent.childNodes.length === 1 && !value.replace(SLOT_MARKER, "").trim();
|
|
6942
|
+
(alone ? parent : text).replaceWith(fragment);
|
|
6943
|
+
}
|
|
6944
|
+
if (!root.hasChildNodes()) return;
|
|
6945
|
+
for (let i = 0; i < count; i++) if (!placed.has(i)) root.appendChild(content(i));
|
|
6946
|
+
}
|
|
6947
|
+
function renderFlow(blocks, ctx) {
|
|
6948
|
+
const flow = ctx.doc.createElement("div");
|
|
6949
|
+
flow.className = "mbe-flow";
|
|
6950
|
+
const elements = /* @__PURE__ */ new Map();
|
|
6951
|
+
for (const block3 of blocks) {
|
|
6952
|
+
const el = renderBlock(block3, ctx);
|
|
6953
|
+
elements.set(block3.id, el);
|
|
6954
|
+
flow.appendChild(el);
|
|
6955
|
+
}
|
|
6956
|
+
updateNeighborMarks({ blocks }, (id) => elements.get(id), /* @__PURE__ */ new WeakMap(), /* @__PURE__ */ new Set(), ctx.labels);
|
|
6957
|
+
for (const el of Array.from(flow.querySelectorAll(`[${BLOCK_ATTR}], [${CONTENT_ATTR}], [contenteditable], [data-row]`))) {
|
|
6958
|
+
el.removeAttribute(BLOCK_ATTR);
|
|
6959
|
+
el.removeAttribute(CONTENT_ATTR);
|
|
6960
|
+
el.removeAttribute("contenteditable");
|
|
6961
|
+
el.removeAttribute("data-row");
|
|
6962
|
+
el.removeAttribute("data-col");
|
|
6963
|
+
}
|
|
6964
|
+
for (const input of Array.from(flow.querySelectorAll("input"))) {
|
|
6965
|
+
if (input.type === "checkbox") input.disabled = true;
|
|
6966
|
+
else input.readOnly = true;
|
|
6967
|
+
input.tabIndex = -1;
|
|
6968
|
+
}
|
|
6969
|
+
return flow;
|
|
6970
|
+
}
|
|
6465
6971
|
function fill(doc) {
|
|
6466
6972
|
const br = doc.createElement("br");
|
|
6467
6973
|
br.setAttribute(FILL_ATTR, "");
|
|
@@ -6511,9 +7017,10 @@ function renderInline(inline3, parent, ctx, decorations, reveal, cell) {
|
|
|
6511
7017
|
const viewed = views ? (span, from) => !!span.token && views.has(span.token) && !reveal?.has(tokenKey(cell, from)) : void 0;
|
|
6512
7018
|
const runs = views?.has("html") && inline3.some((s) => s.marks.includes("html")) ? htmlRuns(inline3).filter((run) => !reveal?.has(tokenKey(cell, run.from))) : [];
|
|
6513
7019
|
const inRun = (from) => runs.some((run) => from >= run.from && from < run.to);
|
|
6514
|
-
const
|
|
7020
|
+
const isHtml = (span) => span.marks.includes("html");
|
|
7021
|
+
const atomic = viewed || runs.length > 0 ? (span, from) => !!viewed?.(span, from) || isHtml(span) && inRun(from) : void 0;
|
|
6515
7022
|
const pieces = splitByDecorations(inline3, decorations, atomic);
|
|
6516
|
-
const render2 = (piece) => decorate(renderSpan(piece.span, ctx, piece.atomic && !
|
|
7023
|
+
const render2 = (piece) => decorate(renderSpan(piece.span, ctx, piece.atomic && !isHtml(piece.span)), piece.decorations, doc);
|
|
6517
7024
|
const offsets = /* @__PURE__ */ new Map();
|
|
6518
7025
|
let offset = 0;
|
|
6519
7026
|
for (const piece of pieces) {
|
|
@@ -6524,12 +7031,37 @@ function renderInline(inline3, parent, ctx, decorations, reveal, cell) {
|
|
|
6524
7031
|
while (i < pieces.length) {
|
|
6525
7032
|
const span = pieces[i].span;
|
|
6526
7033
|
const run = runs.find((r) => r.from === offsets.get(pieces[i]));
|
|
6527
|
-
|
|
6528
|
-
|
|
6529
|
-
const
|
|
6530
|
-
|
|
6531
|
-
|
|
6532
|
-
|
|
7034
|
+
if (run) {
|
|
7035
|
+
const html = [];
|
|
7036
|
+
const slots = [];
|
|
7037
|
+
let slot = null;
|
|
7038
|
+
let end = i;
|
|
7039
|
+
for (; end < pieces.length && offsets.get(pieces[end]) < run.to; end++) {
|
|
7040
|
+
const piece = pieces[end];
|
|
7041
|
+
if (isHtml(piece.span)) {
|
|
7042
|
+
html.push(piece.span.text);
|
|
7043
|
+
slot = null;
|
|
7044
|
+
continue;
|
|
7045
|
+
}
|
|
7046
|
+
if (!slot) {
|
|
7047
|
+
slot = [];
|
|
7048
|
+
slots.push(slot);
|
|
7049
|
+
html.push(slotMarker(slots.length - 1));
|
|
7050
|
+
}
|
|
7051
|
+
slot.push(render2(piece));
|
|
7052
|
+
}
|
|
7053
|
+
const view = ctx.view?.("html", html.join(""), "inline");
|
|
7054
|
+
if (view) {
|
|
7055
|
+
fillSlots(view, slots.length, (n) => {
|
|
7056
|
+
const fragment = doc.createDocumentFragment();
|
|
7057
|
+
fragment.append(...slots[n]);
|
|
7058
|
+
return fragment;
|
|
7059
|
+
}, doc);
|
|
7060
|
+
const text = inlineText(sliceInline(inline3, run.from, run.to));
|
|
7061
|
+
parent.appendChild(atom(view, classes("mbe-view", "mbe-view-html", ctx.classes.token?.html), text));
|
|
7062
|
+
i = end;
|
|
7063
|
+
continue;
|
|
7064
|
+
}
|
|
6533
7065
|
}
|
|
6534
7066
|
if (span.link) {
|
|
6535
7067
|
const a = doc.createElement("a");
|
|
@@ -6662,6 +7194,8 @@ var BlockRenderer = class {
|
|
|
6662
7194
|
widgetsAfter;
|
|
6663
7195
|
/** Views of extension syntaxes, by syntax name. */
|
|
6664
7196
|
views;
|
|
7197
|
+
/** The document's Markdown options, for the Markdown inside an HTML section. */
|
|
7198
|
+
markdown;
|
|
6665
7199
|
/** Theme classes for rendered elements. Set before a full render. */
|
|
6666
7200
|
classes = NO_CLASSES;
|
|
6667
7201
|
/** The icon of a UI control. */
|
|
@@ -6670,6 +7204,8 @@ var BlockRenderer = class {
|
|
|
6670
7204
|
codeCopy = false;
|
|
6671
7205
|
/** An image failed to load and now shows as unavailable. */
|
|
6672
7206
|
onImageError;
|
|
7207
|
+
/** Collapsible sections shown collapsed, by the ID of their title block. */
|
|
7208
|
+
collapsed = /* @__PURE__ */ new Set();
|
|
6673
7209
|
/** Per block, the views that show their source. A block re-renders when its entry changes. */
|
|
6674
7210
|
revealed = /* @__PURE__ */ new Map();
|
|
6675
7211
|
/**
|
|
@@ -6695,6 +7231,7 @@ var BlockRenderer = class {
|
|
|
6695
7231
|
decorateCode: this.decorateCode,
|
|
6696
7232
|
views: this.views,
|
|
6697
7233
|
view: this.views && ((syntax, source, kind) => this.renderView(syntax, source, kind)),
|
|
7234
|
+
markdown: this.markdown,
|
|
6698
7235
|
classes: this.classes,
|
|
6699
7236
|
icon: this.icon,
|
|
6700
7237
|
codeCopy: this.codeCopy,
|
|
@@ -6774,7 +7311,12 @@ var BlockRenderer = class {
|
|
|
6774
7311
|
this.renderingBlock = block3.id;
|
|
6775
7312
|
const prev = this.rendered.get(block3.id);
|
|
6776
7313
|
const reveal = this.revealed.get(block3.id);
|
|
6777
|
-
|
|
7314
|
+
let el = prev && kept.has(prev.el) ? prev.el : null;
|
|
7315
|
+
if (!el) {
|
|
7316
|
+
el = renderBlock(block3, ctx, reveal);
|
|
7317
|
+
if (prev && block3.type === "raw") keepDetailsOpen(prev.el, el);
|
|
7318
|
+
}
|
|
7319
|
+
next.set(block3.id, { block: block3, el, reveal });
|
|
6778
7320
|
}
|
|
6779
7321
|
this.loadedImages.clear();
|
|
6780
7322
|
const nodes = [];
|
|
@@ -6809,7 +7351,11 @@ var BlockRenderer = class {
|
|
|
6809
7351
|
}
|
|
6810
7352
|
}
|
|
6811
7353
|
this.rendered = next;
|
|
6812
|
-
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);
|
|
6813
7359
|
}
|
|
6814
7360
|
elementFor(id) {
|
|
6815
7361
|
return this.rendered.get(id)?.el;
|
|
@@ -6830,12 +7376,33 @@ var BlockRenderer = class {
|
|
|
6830
7376
|
this.rendered.delete(id);
|
|
6831
7377
|
}
|
|
6832
7378
|
};
|
|
6833
|
-
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) {
|
|
6834
7397
|
const counters = [];
|
|
7398
|
+
const sections2 = [];
|
|
6835
7399
|
doc.blocks.forEach((block3, i) => {
|
|
6836
7400
|
const before = doc.blocks[i - 1];
|
|
6837
7401
|
const el = elementFor(block3.id);
|
|
6838
|
-
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);
|
|
6839
7406
|
if (block3.type !== "listItem") {
|
|
6840
7407
|
counters.length = 0;
|
|
6841
7408
|
return;
|
|
@@ -6855,6 +7422,15 @@ function updateNeighborMarks(doc, elementFor, written) {
|
|
|
6855
7422
|
written.set(el, n);
|
|
6856
7423
|
});
|
|
6857
7424
|
}
|
|
7425
|
+
function keepDetailsOpen(from, to) {
|
|
7426
|
+
const before = from.querySelectorAll("details");
|
|
7427
|
+
if (before.length === 0) return;
|
|
7428
|
+
const after = to.querySelectorAll("details");
|
|
7429
|
+
if (after.length !== before.length) return;
|
|
7430
|
+
before.forEach((details2, i) => {
|
|
7431
|
+
after[i].open = details2.open;
|
|
7432
|
+
});
|
|
7433
|
+
}
|
|
6858
7434
|
function setFlag(el, attr, on) {
|
|
6859
7435
|
if (el && el.hasAttribute(attr) !== on) el.toggleAttribute(attr, on);
|
|
6860
7436
|
}
|
|
@@ -7023,8 +7599,8 @@ var BlockHandle = class {
|
|
|
7023
7599
|
let node = target;
|
|
7024
7600
|
while (node && node.parentElement !== this.editor.root) node = node.parentElement;
|
|
7025
7601
|
if (!node || !node.hasAttribute(BLOCK_ATTR)) return;
|
|
7026
|
-
const
|
|
7027
|
-
if (
|
|
7602
|
+
const owner = this.editor.blockMenuOwner(node.getAttribute(BLOCK_ATTR));
|
|
7603
|
+
if (owner) this.showFor(owner);
|
|
7028
7604
|
else if (this.blockId !== null) this.scheduleHide();
|
|
7029
7605
|
}
|
|
7030
7606
|
/** Shows the block handle next to a block. */
|
|
@@ -7067,6 +7643,199 @@ var BlockHandle = class {
|
|
|
7067
7643
|
}
|
|
7068
7644
|
};
|
|
7069
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
|
+
|
|
7070
7839
|
// src/ui/resizeHandles.ts
|
|
7071
7840
|
var MIN_WIDTH = 24;
|
|
7072
7841
|
var SNAP = 8;
|
|
@@ -7353,7 +8122,12 @@ var COLOR_VARS = {
|
|
|
7353
8122
|
popupBackground: "--mbe-popup-bg",
|
|
7354
8123
|
popupBorder: "--mbe-popup-border",
|
|
7355
8124
|
hover: "--mbe-hover",
|
|
7356
|
-
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"
|
|
7357
8131
|
};
|
|
7358
8132
|
var SIZE_VARS = {
|
|
7359
8133
|
font: "--mbe-font",
|
|
@@ -7385,10 +8159,13 @@ var SLASH_ITEM_IDS = [
|
|
|
7385
8159
|
"heading1",
|
|
7386
8160
|
"heading2",
|
|
7387
8161
|
"heading3",
|
|
8162
|
+
"heading4",
|
|
7388
8163
|
"bulletList",
|
|
7389
8164
|
"numberedList",
|
|
7390
8165
|
"todoList",
|
|
7391
8166
|
"quote",
|
|
8167
|
+
"callout",
|
|
8168
|
+
"details",
|
|
7392
8169
|
"code",
|
|
7393
8170
|
"table",
|
|
7394
8171
|
"divider"
|
|
@@ -7398,10 +8175,13 @@ var BLOCK_ITEMS2 = [
|
|
|
7398
8175
|
{ id: "heading1", aliases: ["h1", "title"], spec: { type: "heading", level: 1 } },
|
|
7399
8176
|
{ id: "heading2", aliases: ["h2", "subtitle"], spec: { type: "heading", level: 2 } },
|
|
7400
8177
|
{ id: "heading3", aliases: ["h3"], spec: { type: "heading", level: 3 } },
|
|
8178
|
+
{ id: "heading4", aliases: ["h4"], spec: { type: "heading", level: 4 } },
|
|
7401
8179
|
{ id: "bulletList", aliases: ["ul", "unordered", "bullet"], spec: { type: "listItem", listType: "bullet" } },
|
|
7402
8180
|
{ id: "numberedList", aliases: ["ol", "ordered"], spec: { type: "listItem", listType: "ordered" } },
|
|
7403
8181
|
{ id: "todoList", aliases: ["task", "checkbox", "checklist"], spec: { type: "listItem", listType: "task" } },
|
|
7404
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" } },
|
|
7405
8185
|
{ id: "code", aliases: ["pre", "snippet", "fence"], spec: { type: "code" } },
|
|
7406
8186
|
{ id: "table", aliases: ["grid"], spec: { type: "table" } },
|
|
7407
8187
|
{ id: "divider", aliases: ["hr", "separator", "line", "rule"], spec: { type: "divider" } }
|
|
@@ -7493,6 +8273,9 @@ var Editor = class {
|
|
|
7493
8273
|
/** The link popover, and the field for an image's alt text. */
|
|
7494
8274
|
inputPopover;
|
|
7495
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;
|
|
7496
8279
|
resizeHandles;
|
|
7497
8280
|
/** The selected image's element, which carries the selected class. */
|
|
7498
8281
|
selectedImageEl = null;
|
|
@@ -7531,6 +8314,8 @@ var Editor = class {
|
|
|
7531
8314
|
this.source = loaded.source;
|
|
7532
8315
|
this.current = createState(loaded.doc);
|
|
7533
8316
|
this.renderer = new BlockRenderer(root, this.labels);
|
|
8317
|
+
this.renderer.collapsed = this.collapsed;
|
|
8318
|
+
this.collapseClosedSections(this.current.doc);
|
|
7534
8319
|
this.renderer.widgetsAfter = (blockId) => {
|
|
7535
8320
|
if (this.widgets.length === 0) return void 0;
|
|
7536
8321
|
const els = this.widgets.filter((w) => w.blockId === blockId).map((w) => w.element);
|
|
@@ -7538,6 +8323,7 @@ var Editor = class {
|
|
|
7538
8323
|
};
|
|
7539
8324
|
const views = new Map(this.extensions.flatMap((e) => Object.entries(e.views ?? {})));
|
|
7540
8325
|
if (views.size > 0) this.renderer.views = views;
|
|
8326
|
+
this.renderer.markdown = this.markdown;
|
|
7541
8327
|
this.renderer.onViewSettled = (ids) => this.viewsSettled(ids);
|
|
7542
8328
|
const codeDecorators = this.extensions.flatMap((e) => e.codeDecorations ? [e.codeDecorations] : []);
|
|
7543
8329
|
if (codeDecorators.length > 0) {
|
|
@@ -7600,6 +8386,12 @@ var Editor = class {
|
|
|
7600
8386
|
this.toolbar = options.toolbar === false ? null : new FormatToolbar(this, typeof options.toolbar === "object" ? options.toolbar.items : void 0);
|
|
7601
8387
|
if (this.toolbar) this.toolbar.onMenuChange = () => this.syncActiveDescendant();
|
|
7602
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
|
+
});
|
|
7603
8395
|
this.resizeHandles = new ResizeHandles(this);
|
|
7604
8396
|
this.renderer.onImageError = () => {
|
|
7605
8397
|
if (this.destroyed) return;
|
|
@@ -7655,6 +8447,8 @@ var Editor = class {
|
|
|
7655
8447
|
this.blockSel = null;
|
|
7656
8448
|
this.suggestions.reset();
|
|
7657
8449
|
const next = createState(loaded.doc);
|
|
8450
|
+
this.collapsed.clear();
|
|
8451
|
+
this.collapseClosedSections(next.doc);
|
|
7658
8452
|
this.relocateWidgets(this.current.doc, next.doc, true);
|
|
7659
8453
|
this.current = next;
|
|
7660
8454
|
this.paint(true, true);
|
|
@@ -7706,7 +8500,7 @@ var Editor = class {
|
|
|
7706
8500
|
const actual = this.getAttributes(name);
|
|
7707
8501
|
return Object.entries(attrs).every(([k, v]) => actual[k] === v);
|
|
7708
8502
|
}
|
|
7709
|
-
/** 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. */
|
|
7710
8504
|
getAttributes(name) {
|
|
7711
8505
|
const s = this.current;
|
|
7712
8506
|
if (name === "link") {
|
|
@@ -7728,6 +8522,10 @@ var Editor = class {
|
|
|
7728
8522
|
return block3.listType === "task" ? { checked: block3.checked, indent: block3.indent } : { indent: block3.indent };
|
|
7729
8523
|
case "raw":
|
|
7730
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) };
|
|
7731
8529
|
default:
|
|
7732
8530
|
return {};
|
|
7733
8531
|
}
|
|
@@ -7912,6 +8710,7 @@ var Editor = class {
|
|
|
7912
8710
|
if (!next || next === this.current) return false;
|
|
7913
8711
|
next = dropBrokenTokens(next, this.current, this.markdown.inline);
|
|
7914
8712
|
next = clampListIndents(next, this.current);
|
|
8713
|
+
next = balanceSections(next);
|
|
7915
8714
|
if (next.doc !== this.current.doc && sameBlocks(next.doc, this.current.doc)) next = { ...next, doc: this.current.doc };
|
|
7916
8715
|
if (next.doc === this.current.doc && next.selection === this.current.selection && next.storedMarks === this.current.storedMarks) {
|
|
7917
8716
|
return false;
|
|
@@ -7933,6 +8732,10 @@ var Editor = class {
|
|
|
7933
8732
|
toggleOrderedList: () => block3({ type: "listItem", listType: "ordered" }),
|
|
7934
8733
|
toggleTaskList: () => block3({ type: "listItem", listType: "task" }),
|
|
7935
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)),
|
|
7936
8739
|
toggleCodeBlock: (attrs = {}) => block3({ type: "code", language: attrs.language }),
|
|
7937
8740
|
setLink: ({ href }) => run((s) => setLink(s, href)),
|
|
7938
8741
|
unsetLink: () => run((s) => setLink(s, null)),
|
|
@@ -8081,6 +8884,7 @@ var Editor = class {
|
|
|
8081
8884
|
this.toolbar?.destroy();
|
|
8082
8885
|
this.inputPopover.destroy();
|
|
8083
8886
|
this.blockHandle.destroy();
|
|
8887
|
+
this.linkCard?.destroy();
|
|
8084
8888
|
this.resizeHandles.destroy();
|
|
8085
8889
|
setPopupContainer(this.root, void 0);
|
|
8086
8890
|
for (const name of Object.keys(this.runtime.attributes ?? {})) this.root.removeAttribute(name);
|
|
@@ -8194,9 +8998,10 @@ var Editor = class {
|
|
|
8194
8998
|
const el = this.renderer.elementFor(block3.id);
|
|
8195
8999
|
if (!el || !el.classList.contains("mbe-empty")) continue;
|
|
8196
9000
|
let hint = "";
|
|
8197
|
-
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)}`];
|
|
8198
9002
|
else if (block3.type === "listItem") hint = this.labels.listHint;
|
|
8199
|
-
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;
|
|
8200
9005
|
if (hint && el.dataset.hint !== hint) el.dataset.hint = hint;
|
|
8201
9006
|
}
|
|
8202
9007
|
this.updateUi();
|
|
@@ -8288,7 +9093,7 @@ var Editor = class {
|
|
|
8288
9093
|
const end = blockIndex(this.state.doc, to.blockId);
|
|
8289
9094
|
for (let i = from + dir; (end - i) * dir > 0; i += dir) {
|
|
8290
9095
|
const block3 = blocks[i];
|
|
8291
|
-
if (block3
|
|
9096
|
+
if (!this.skipsCaret(block3)) return this.blockEntry(block3, dir === 1, x);
|
|
8292
9097
|
}
|
|
8293
9098
|
return null;
|
|
8294
9099
|
}
|
|
@@ -8443,7 +9248,7 @@ var Editor = class {
|
|
|
8443
9248
|
const index2 = blockIndex(this.state.doc, selected.pos.blockId);
|
|
8444
9249
|
for (let i = index2 + (forward ? 1 : -1); i >= 0 && i < blocks.length; i += forward ? 1 : -1) {
|
|
8445
9250
|
const block3 = blocks[i];
|
|
8446
|
-
if (block3
|
|
9251
|
+
if (this.skipsCaret(block3)) continue;
|
|
8447
9252
|
const offset2 = imageBlockOffset(block3);
|
|
8448
9253
|
if (offset2 !== null) return { anchor: { blockId: block3.id, offset: offset2 }, focus: { blockId: block3.id, offset: offset2 + 1 } };
|
|
8449
9254
|
const vertical = key === "ArrowDown" || key === "ArrowUp";
|
|
@@ -8491,7 +9296,7 @@ var Editor = class {
|
|
|
8491
9296
|
}
|
|
8492
9297
|
for (let i = index + dir; i >= 0 && i < blocks.length; i += dir) {
|
|
8493
9298
|
const next = blocks[i];
|
|
8494
|
-
if (next
|
|
9299
|
+
if (this.skipsCaret(next)) continue;
|
|
8495
9300
|
if (next.type === "table") {
|
|
8496
9301
|
const r = dir === 1 ? 0 : next.rows.length - 1;
|
|
8497
9302
|
const c = Math.min(col, next.align.length - 1);
|
|
@@ -8579,7 +9384,7 @@ var Editor = class {
|
|
|
8579
9384
|
}
|
|
8580
9385
|
case "insertParagraph": {
|
|
8581
9386
|
if (this.suggestions.isOpen && this.suggestions.accept()) return;
|
|
8582
|
-
this.run(splitBlock);
|
|
9387
|
+
this.run((s) => this.collapsed.has(s.selection.focus.blockId) ? splitCollapsedTitle(s) : splitBlock(s));
|
|
8583
9388
|
return;
|
|
8584
9389
|
}
|
|
8585
9390
|
case "insertLineBreak":
|
|
@@ -8648,7 +9453,7 @@ var Editor = class {
|
|
|
8648
9453
|
/** Markdown shortcuts and suggestion menus that typing `text` triggers. */
|
|
8649
9454
|
afterTyping(text) {
|
|
8650
9455
|
const typed = this.state;
|
|
8651
|
-
if (text === " " || text === "-") this.run((s) => applyBlockInputRules(s));
|
|
9456
|
+
if (text === " " || text === "-") this.run((s) => applyBlockInputRules(s, this.markdown));
|
|
8652
9457
|
if (text.length === 1 && "*_`~".includes(text)) this.run((s) => applyInlineInputRules(s));
|
|
8653
9458
|
if (this.markdown.inline.length > 0) this.run((s) => applyTokenInputRules(s, this.markdown.inline) ?? s);
|
|
8654
9459
|
if (text === " " && this.markdown.autolinks) this.run((s) => applyAutolinkInputRule(s) ?? s);
|
|
@@ -8789,7 +9594,7 @@ var Editor = class {
|
|
|
8789
9594
|
if (blockId !== void 0 && block3.id !== blockId) continue;
|
|
8790
9595
|
const el = this.renderer.elementFor(block3.id);
|
|
8791
9596
|
if (!el || !el.isConnected) continue;
|
|
8792
|
-
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) ? [] : [{}];
|
|
8793
9598
|
for (const { cell } of containers2) {
|
|
8794
9599
|
const contentEl = contentElement(el, cell);
|
|
8795
9600
|
const content = containerContent(getBlock(state.doc, block3.id), cell);
|
|
@@ -8893,6 +9698,7 @@ var Editor = class {
|
|
|
8893
9698
|
}
|
|
8894
9699
|
}
|
|
8895
9700
|
if (mod2 && !e.altKey) {
|
|
9701
|
+
if (e.key === "/" && !e.shiftKey) this.refreshSelection();
|
|
8896
9702
|
if (e.key === "/" && !e.shiftKey && this.hasBlockMenu(this.state.selection.focus.blockId)) {
|
|
8897
9703
|
return handled(() => this.openBlockMenu(this.state.selection.focus.blockId));
|
|
8898
9704
|
}
|
|
@@ -8958,7 +9764,7 @@ var Editor = class {
|
|
|
8958
9764
|
const blocks = this.state.doc.blocks;
|
|
8959
9765
|
for (let i = key.from + key.vertical; i >= 0 && i < blocks.length; i += key.vertical) {
|
|
8960
9766
|
const block3 = blocks[i];
|
|
8961
|
-
if (block3
|
|
9767
|
+
if (this.skipsCaret(block3)) continue;
|
|
8962
9768
|
this.caretKey = null;
|
|
8963
9769
|
const row = key.vertical === 1 ? 0 : block3.type === "table" ? block3.rows.length - 1 : 0;
|
|
8964
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);
|
|
@@ -8966,6 +9772,10 @@ var Editor = class {
|
|
|
8966
9772
|
this.scrollCaretIntoView();
|
|
8967
9773
|
return;
|
|
8968
9774
|
}
|
|
9775
|
+
if (key.vertical === 1 && blocks[blocks.length - 1].type === "detailsEnd") {
|
|
9776
|
+
this.caretKey = null;
|
|
9777
|
+
this.run((s) => appendParagraph(s));
|
|
9778
|
+
}
|
|
8969
9779
|
});
|
|
8970
9780
|
}
|
|
8971
9781
|
/** Selects all the text of the block (or table cell) holding `target`. False if it holds none. */
|
|
@@ -8992,6 +9802,13 @@ var Editor = class {
|
|
|
8992
9802
|
e.preventDefault();
|
|
8993
9803
|
return;
|
|
8994
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
|
+
}
|
|
8995
9812
|
this.dropBlockSelection();
|
|
8996
9813
|
if (target === this.root && e.button === 0 && !this.readOnly && this.clickBelowLastBlock(e)) return;
|
|
8997
9814
|
const imageEl = e.button === 0 && !e.shiftKey && !this.readOnly ? target.closest?.(".mbe-image") : null;
|
|
@@ -9011,6 +9828,13 @@ var Editor = class {
|
|
|
9011
9828
|
e.preventDefault();
|
|
9012
9829
|
return;
|
|
9013
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
|
+
}
|
|
9014
9838
|
if (e.button === 0) this.pointerDown = true;
|
|
9015
9839
|
if (target.classList?.contains("mbe-checkbox")) {
|
|
9016
9840
|
e.preventDefault();
|
|
@@ -9026,7 +9850,7 @@ var Editor = class {
|
|
|
9026
9850
|
const blocks = this.state.doc.blocks;
|
|
9027
9851
|
const last = blocks[blocks.length - 1];
|
|
9028
9852
|
const image = last ? imageBlockOffset(last) : null;
|
|
9029
|
-
if (!last || last.type !== "code" && last.type !== "table" && last
|
|
9853
|
+
if (!last || last.type !== "code" && last.type !== "table" && !isTextless(last) && image === null) return false;
|
|
9030
9854
|
const el = this.root.querySelector(`:scope > [data-block-id="${last.id}"]`);
|
|
9031
9855
|
if (!el || e.clientY <= el.getBoundingClientRect().bottom) return false;
|
|
9032
9856
|
e.preventDefault();
|
|
@@ -9052,18 +9876,19 @@ var Editor = class {
|
|
|
9052
9876
|
const link = target.closest?.("a.mbe-link");
|
|
9053
9877
|
if (!link) return;
|
|
9054
9878
|
e.preventDefault();
|
|
9055
|
-
if (this.readOnly || (isMac ? e.metaKey : e.ctrlKey))
|
|
9056
|
-
|
|
9057
|
-
|
|
9058
|
-
|
|
9059
|
-
}
|
|
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");
|
|
9060
9885
|
}
|
|
9061
9886
|
/** Copies the code of the code block holding `button`, and shows that it did for a moment. */
|
|
9062
9887
|
copyCode(button) {
|
|
9063
9888
|
const blockEl = button.closest(`[${BLOCK_ATTR}]`);
|
|
9064
9889
|
const block3 = blockEl && this.state.doc.blocks.find((b) => b.id === blockEl.getAttribute(BLOCK_ATTR));
|
|
9065
|
-
|
|
9066
|
-
|
|
9890
|
+
const text = block3?.type === "code" ? inlineText(block3.content) : button.closest(".mbe-flow .mbe-code")?.querySelector("code")?.textContent;
|
|
9891
|
+
if (text == null) return;
|
|
9067
9892
|
const doc = this.root.ownerDocument;
|
|
9068
9893
|
const show = (name) => {
|
|
9069
9894
|
const icon = iconNode(doc, this.icon(name));
|
|
@@ -9124,6 +9949,7 @@ var Editor = class {
|
|
|
9124
9949
|
}
|
|
9125
9950
|
onScroll() {
|
|
9126
9951
|
this.blockHandle.hide();
|
|
9952
|
+
this.linkCard?.reposition();
|
|
9127
9953
|
this.resizeHandles.reposition();
|
|
9128
9954
|
if (this.suggestions.isActive || this.toolbar?.isOpen || this.blockMenu.isOpen) this.updateUi();
|
|
9129
9955
|
}
|
|
@@ -9135,7 +9961,7 @@ var Editor = class {
|
|
|
9135
9961
|
if (range) {
|
|
9136
9962
|
if (!e.clipboardData) return;
|
|
9137
9963
|
e.preventDefault();
|
|
9138
|
-
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)) };
|
|
9139
9965
|
writeClipboard(e.clipboardData, doc2, serializeBlocks(doc2.blocks, this.markdown));
|
|
9140
9966
|
if (cut && !this.readOnly) this.deleteSelectedBlocks();
|
|
9141
9967
|
return;
|
|
@@ -9143,7 +9969,7 @@ var Editor = class {
|
|
|
9143
9969
|
this.refreshSelection();
|
|
9144
9970
|
if (isCollapsed(this.state.selection) || !e.clipboardData) return;
|
|
9145
9971
|
e.preventDefault();
|
|
9146
|
-
const doc = { blocks: selectedBlocks(this.state) };
|
|
9972
|
+
const doc = { blocks: closeSections(selectedBlocks(this.state)) };
|
|
9147
9973
|
writeClipboard(e.clipboardData, doc, serializeMarkdown(doc, this.markdown).replace(/\n$/, ""));
|
|
9148
9974
|
if (cut && !this.readOnly) this.run(deleteSelection);
|
|
9149
9975
|
}
|
|
@@ -9229,7 +10055,7 @@ var Editor = class {
|
|
|
9229
10055
|
/** The slash menu, as a suggestion. */
|
|
9230
10056
|
slashSuggestion() {
|
|
9231
10057
|
const ids = this.options.slashMenu || SLASH_ITEM_IDS;
|
|
9232
|
-
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 }));
|
|
9233
10059
|
return {
|
|
9234
10060
|
name: "slash",
|
|
9235
10061
|
trigger: SLASH_CHARS,
|
|
@@ -9263,7 +10089,37 @@ var Editor = class {
|
|
|
9263
10089
|
const doc = this.current.doc;
|
|
9264
10090
|
const a = blockIndex(doc, this.blockSel.anchor);
|
|
9265
10091
|
const h = blockIndex(doc, this.blockSel.head);
|
|
9266
|
-
|
|
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;
|
|
9267
10123
|
}
|
|
9268
10124
|
/** Selects whole blocks, from the block `anchor` to the block `head`. */
|
|
9269
10125
|
selectBlockRange(anchor, head) {
|
|
@@ -9332,7 +10188,6 @@ var Editor = class {
|
|
|
9332
10188
|
const blocks = this.state.doc.blocks;
|
|
9333
10189
|
const plain2 = !e.metaKey && !e.ctrlKey && !e.altKey;
|
|
9334
10190
|
const mod2 = isMac ? e.metaKey : e.ctrlKey;
|
|
9335
|
-
const clamp = (i) => blocks[Math.max(0, Math.min(blocks.length - 1, i))].id;
|
|
9336
10191
|
switch (e.key) {
|
|
9337
10192
|
case "Escape":
|
|
9338
10193
|
if (!plain2 || e.shiftKey) return false;
|
|
@@ -9344,9 +10199,11 @@ var Editor = class {
|
|
|
9344
10199
|
if (!plain2) return false;
|
|
9345
10200
|
const up = e.key === "ArrowUp";
|
|
9346
10201
|
if (e.shiftKey) {
|
|
9347
|
-
|
|
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));
|
|
9348
10205
|
} else {
|
|
9349
|
-
const id =
|
|
10206
|
+
const id = this.nextSelectable(up ? range.from : range.to, up ? -1 : 1);
|
|
9350
10207
|
this.selectBlockRange(id, id);
|
|
9351
10208
|
}
|
|
9352
10209
|
return true;
|
|
@@ -9407,6 +10264,35 @@ var Editor = class {
|
|
|
9407
10264
|
})));
|
|
9408
10265
|
sections2.push({ title: this.labels.tableSection, items });
|
|
9409
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
|
+
}
|
|
9410
10296
|
const imageOffset = imageBlockOffset(block3);
|
|
9411
10297
|
if (imageOffset !== null) {
|
|
9412
10298
|
const pos = { blockId, offset: imageOffset };
|
|
@@ -9453,15 +10339,26 @@ var Editor = class {
|
|
|
9453
10339
|
}
|
|
9454
10340
|
/**
|
|
9455
10341
|
* @internal
|
|
9456
|
-
* Only large blocks get the block handle and block menu: tables, code blocks
|
|
9457
|
-
* image blocks. Other blocks change type through the slash menu
|
|
9458
|
-
* 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.
|
|
9459
10345
|
*/
|
|
9460
10346
|
hasBlockMenu(blockId) {
|
|
9461
10347
|
const block3 = this.state.doc.blocks.find((b) => b.id === blockId);
|
|
9462
|
-
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);
|
|
10349
|
+
}
|
|
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;
|
|
9463
10360
|
}
|
|
9464
|
-
/** @internal Opens the block menu of a table, code block
|
|
10361
|
+
/** @internal Opens the block menu of a table, code block, image block or callout, as the block handle and Mod+/ do. */
|
|
9465
10362
|
openBlockMenu(blockId, anchor) {
|
|
9466
10363
|
if (this.readOnly || !this.hasBlockMenu(blockId)) return;
|
|
9467
10364
|
this.dropBlockSelection();
|
|
@@ -9471,7 +10368,7 @@ var Editor = class {
|
|
|
9471
10368
|
if (imageOffset !== null) {
|
|
9472
10369
|
this.current = selectImage(this.state, { blockId, offset: imageOffset });
|
|
9473
10370
|
if (!this.hasFocus()) this.focus();
|
|
9474
|
-
} 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)) {
|
|
9475
10372
|
const block3 = getBlock(this.state.doc, blockId);
|
|
9476
10373
|
const start = startOf(block3);
|
|
9477
10374
|
this.current = { ...this.state, selection: { anchor: start, focus: start } };
|
|
@@ -9484,6 +10381,14 @@ var Editor = class {
|
|
|
9484
10381
|
if (rect) this.blockMenu.popup.show(rect, "below");
|
|
9485
10382
|
this.syncActiveDescendant();
|
|
9486
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
|
+
}
|
|
9487
10392
|
closeBlockMenu() {
|
|
9488
10393
|
this.blockMenu.hide();
|
|
9489
10394
|
this.syncActiveDescendant();
|
|
@@ -9528,11 +10433,13 @@ var Editor = class {
|
|
|
9528
10433
|
// UI that follows the selection
|
|
9529
10434
|
updateUi() {
|
|
9530
10435
|
if (this.destroyed) return;
|
|
10436
|
+
this.expandAroundSelection();
|
|
9531
10437
|
const focused = this.hasFocus();
|
|
9532
10438
|
const pos = this.state.selection.focus;
|
|
9533
10439
|
const el = focused && !this.blockSel && isCollapsed(this.state.selection) ? this.renderer.elementFor(pos.blockId) : void 0;
|
|
9534
10440
|
const placeholderShown = !!this.options.placeholder && this.state.doc.blocks.length === 1;
|
|
9535
|
-
const
|
|
10441
|
+
const slashHint = !!this.options.slashHint && this.options.slashMenu !== false;
|
|
10442
|
+
const showHint = slashHint && el && el.classList.contains("mbe-paragraph") && el.classList.contains("mbe-empty") && !this.readOnly && !placeholderShown;
|
|
9536
10443
|
const nextHint = showHint ? el : null;
|
|
9537
10444
|
if (this.hintEl !== nextHint) {
|
|
9538
10445
|
this.hintEl?.classList.remove("mbe-show-hint");
|
|
@@ -9552,12 +10459,130 @@ var Editor = class {
|
|
|
9552
10459
|
else this.toolbar.hide();
|
|
9553
10460
|
}
|
|
9554
10461
|
if (focused && !this.readOnly && isTouch()) {
|
|
9555
|
-
|
|
10462
|
+
const owner = this.blockMenuOwner(pos.blockId);
|
|
10463
|
+
if (owner) this.blockHandle.showFor(owner);
|
|
9556
10464
|
else this.blockHandle.hide();
|
|
9557
10465
|
}
|
|
9558
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
|
+
}
|
|
9559
10471
|
this.syncActiveDescendant();
|
|
9560
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
|
+
}
|
|
9561
10586
|
/** Marks the selected image's element, and hides the browser's selection highlight over it. */
|
|
9562
10587
|
paintSelectedImage(el) {
|
|
9563
10588
|
if (this.selectedImageEl !== el) {
|
|
@@ -9630,6 +10655,7 @@ var Editor = class {
|
|
|
9630
10655
|
this.blockMenu.hide();
|
|
9631
10656
|
this.toolbar?.hide();
|
|
9632
10657
|
this.blockHandle.hide();
|
|
10658
|
+
this.linkCard?.setCaret(null);
|
|
9633
10659
|
this.resizeHandles.hide();
|
|
9634
10660
|
this.paintSelectedImage(null);
|
|
9635
10661
|
this.hintEl?.classList.remove("mbe-show-hint");
|
|
@@ -9659,6 +10685,8 @@ function blockName(block3) {
|
|
|
9659
10685
|
return "blockquote";
|
|
9660
10686
|
case "code":
|
|
9661
10687
|
return "codeBlock";
|
|
10688
|
+
case "detailsEnd":
|
|
10689
|
+
return "details";
|
|
9662
10690
|
default:
|
|
9663
10691
|
return block3.type;
|
|
9664
10692
|
}
|
|
@@ -9996,6 +11024,7 @@ function fileHandler(options) {
|
|
|
9996
11024
|
}
|
|
9997
11025
|
export {
|
|
9998
11026
|
ATOM_CHAR,
|
|
11027
|
+
CALLOUT_TYPES,
|
|
9999
11028
|
DEFAULT_LABELS,
|
|
10000
11029
|
Editor,
|
|
10001
11030
|
MARK_ORDER,
|
|
@@ -10015,6 +11044,8 @@ export {
|
|
|
10015
11044
|
defaultKeymap,
|
|
10016
11045
|
defaultResolveUrl,
|
|
10017
11046
|
deleteInline,
|
|
11047
|
+
details,
|
|
11048
|
+
detailsEnd,
|
|
10018
11049
|
divider,
|
|
10019
11050
|
docToHtml,
|
|
10020
11051
|
emptyTable,
|
|
@@ -10034,6 +11065,7 @@ export {
|
|
|
10034
11065
|
isImageBlock,
|
|
10035
11066
|
isPlainTextBlock,
|
|
10036
11067
|
isTextBlock,
|
|
11068
|
+
isTextless,
|
|
10037
11069
|
linkAt,
|
|
10038
11070
|
listItem,
|
|
10039
11071
|
loadMarkdown,
|