@14ch/svelte-md-outliner 0.0.1
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.ja.md +190 -0
- package/README.md +190 -0
- package/dist/assets/styles/editor.css +1459 -0
- package/dist/assets/styles/theme.css +486 -0
- package/dist/components/ContextMenu.svelte +279 -0
- package/dist/components/ContextMenu.svelte.d.ts +9 -0
- package/dist/components/EditorSurface.svelte +99 -0
- package/dist/components/EditorSurface.svelte.d.ts +16 -0
- package/dist/components/FocusBreadcrumb.svelte +138 -0
- package/dist/components/FocusBreadcrumb.svelte.d.ts +16 -0
- package/dist/components/MarkdownEditor.svelte +393 -0
- package/dist/components/MarkdownEditor.svelte.d.ts +119 -0
- package/dist/components/ShortcutHelpDialog.svelte +155 -0
- package/dist/components/ShortcutHelpDialog.svelte.d.ts +12 -0
- package/dist/components/internal/Dialog.svelte +157 -0
- package/dist/components/internal/Dialog.svelte.d.ts +23 -0
- package/dist/components/internal/Modal.svelte +181 -0
- package/dist/components/internal/Modal.svelte.d.ts +18 -0
- package/dist/components/internal/Popup.svelte +248 -0
- package/dist/components/internal/Popup.svelte.d.ts +26 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +28 -0
- package/dist/markdown.d.ts +13 -0
- package/dist/markdown.js +10 -0
- package/dist/messages/en.d.ts +2 -0
- package/dist/messages/en.js +107 -0
- package/dist/messages/index.d.ts +13 -0
- package/dist/messages/index.js +31 -0
- package/dist/messages/ja.d.ts +2 -0
- package/dist/messages/ja.js +112 -0
- package/dist/messages/messages.types.d.ts +59 -0
- package/dist/messages/messages.types.js +1 -0
- package/dist/models/document/bodySelection.d.ts +32 -0
- package/dist/models/document/bodySelection.js +43 -0
- package/dist/models/document/document.types.d.ts +27 -0
- package/dist/models/document/document.types.js +8 -0
- package/dist/models/document/foldable.d.ts +18 -0
- package/dist/models/document/foldable.js +21 -0
- package/dist/models/document/schema.d.ts +2 -0
- package/dist/models/document/schema.js +428 -0
- package/dist/models/document/sectionTree.d.ts +15 -0
- package/dist/models/document/sectionTree.js +123 -0
- package/dist/models/markdown/blockOutline.d.ts +9 -0
- package/dist/models/markdown/blockOutline.js +82 -0
- package/dist/models/markdown/frontMatter.d.ts +98 -0
- package/dist/models/markdown/frontMatter.js +300 -0
- package/dist/models/markdown/markdown.types.d.ts +60 -0
- package/dist/models/markdown/markdown.types.js +1 -0
- package/dist/models/markdown/markdownIt.d.ts +1 -0
- package/dist/models/markdown/markdownIt.js +92 -0
- package/dist/models/markdown/parser.d.ts +4 -0
- package/dist/models/markdown/parser.js +505 -0
- package/dist/models/markdown/plainText.d.ts +1 -0
- package/dist/models/markdown/plainText.js +25 -0
- package/dist/models/markdown/serializer.d.ts +17 -0
- package/dist/models/markdown/serializer.js +453 -0
- package/dist/models/viewState/viewState.types.d.ts +38 -0
- package/dist/models/viewState/viewState.types.js +17 -0
- package/dist/models/viewState/viewStateCodec.d.ts +31 -0
- package/dist/models/viewState/viewStateCodec.js +173 -0
- package/dist/operations/autoformat.d.ts +9 -0
- package/dist/operations/autoformat.js +86 -0
- package/dist/operations/commands/block.d.ts +24 -0
- package/dist/operations/commands/block.js +139 -0
- package/dist/operations/commands/codeBlock.d.ts +7 -0
- package/dist/operations/commands/codeBlock.js +26 -0
- package/dist/operations/commands/element.d.ts +67 -0
- package/dist/operations/commands/element.js +269 -0
- package/dist/operations/commands/frontMatter.d.ts +35 -0
- package/dist/operations/commands/frontMatter.js +120 -0
- package/dist/operations/commands/lineBreak.d.ts +9 -0
- package/dist/operations/commands/lineBreak.js +16 -0
- package/dist/operations/commands/link.d.ts +7 -0
- package/dist/operations/commands/link.js +21 -0
- package/dist/operations/commands/list.d.ts +126 -0
- package/dist/operations/commands/list.js +652 -0
- package/dist/operations/commands/mermaidBlock.d.ts +9 -0
- package/dist/operations/commands/mermaidBlock.js +28 -0
- package/dist/operations/commands/section.d.ts +217 -0
- package/dist/operations/commands/section.js +865 -0
- package/dist/operations/commands/sectionFold.d.ts +36 -0
- package/dist/operations/commands/sectionFold.js +219 -0
- package/dist/operations/commands/sectionJump.d.ts +8 -0
- package/dist/operations/commands/sectionJump.js +144 -0
- package/dist/operations/commands/selectedBlock.d.ts +37 -0
- package/dist/operations/commands/selectedBlock.js +170 -0
- package/dist/operations/commands/table.d.ts +64 -0
- package/dist/operations/commands/table.js +437 -0
- package/dist/operations/keymap/assemble.d.ts +22 -0
- package/dist/operations/keymap/assemble.js +165 -0
- package/dist/operations/keymap/coreActions.d.ts +2 -0
- package/dist/operations/keymap/coreActions.js +711 -0
- package/dist/operations/keymap/menuItems.d.ts +52 -0
- package/dist/operations/keymap/menuItems.js +114 -0
- package/dist/operations/keymap/shortcutKeys.d.ts +42 -0
- package/dist/operations/keymap/shortcutKeys.js +114 -0
- package/dist/operations/keymap/viewActions.d.ts +30 -0
- package/dist/operations/keymap/viewActions.js +182 -0
- package/dist/operations/operations.types.d.ts +121 -0
- package/dist/operations/operations.types.js +1 -0
- package/dist/operations/plugins/blockHandle.d.ts +25 -0
- package/dist/operations/plugins/blockHandle.js +112 -0
- package/dist/operations/plugins/contextMenu.d.ts +33 -0
- package/dist/operations/plugins/contextMenu.js +204 -0
- package/dist/operations/plugins/focus.d.ts +39 -0
- package/dist/operations/plugins/focus.js +350 -0
- package/dist/operations/plugins/foldClick.d.ts +11 -0
- package/dist/operations/plugins/foldClick.js +117 -0
- package/dist/operations/plugins/foldGuard.d.ts +15 -0
- package/dist/operations/plugins/foldGuard.js +31 -0
- package/dist/operations/plugins/frontMatterGuard.d.ts +21 -0
- package/dist/operations/plugins/frontMatterGuard.js +150 -0
- package/dist/operations/plugins/frontMatterView.d.ts +34 -0
- package/dist/operations/plugins/frontMatterView.js +137 -0
- package/dist/operations/plugins/linkPaste.d.ts +3 -0
- package/dist/operations/plugins/linkPaste.js +20 -0
- package/dist/operations/plugins/listStructure.d.ts +13 -0
- package/dist/operations/plugins/listStructure.js +18 -0
- package/dist/operations/plugins/markdownClipboard.d.ts +8 -0
- package/dist/operations/plugins/markdownClipboard.js +208 -0
- package/dist/operations/plugins/mermaidView.d.ts +20 -0
- package/dist/operations/plugins/mermaidView.js +206 -0
- package/dist/operations/plugins/requiredSelectionEntry.d.ts +10 -0
- package/dist/operations/plugins/requiredSelectionEntry.js +124 -0
- package/dist/operations/plugins/sectionView.d.ts +12 -0
- package/dist/operations/plugins/sectionView.js +44 -0
- package/dist/operations/plugins/tabEscape.d.ts +21 -0
- package/dist/operations/plugins/tabEscape.js +41 -0
- package/dist/operations/plugins/tableHandles.d.ts +24 -0
- package/dist/operations/plugins/tableHandles.js +89 -0
- package/dist/operations/transaction.d.ts +26 -0
- package/dist/operations/transaction.js +51 -0
- package/dist/operations/transactionOrigin.d.ts +17 -0
- package/dist/operations/transactionOrigin.js +9 -0
- package/dist/states/contextMenuController.svelte.d.ts +57 -0
- package/dist/states/contextMenuController.svelte.js +206 -0
- package/dist/states/editorSession.d.ts +12 -0
- package/dist/states/editorSession.js +268 -0
- package/dist/states/editorSession.types.d.ts +57 -0
- package/dist/states/editorSession.types.js +1 -0
- package/dist/states/outlineViewController.svelte.d.ts +52 -0
- package/dist/states/outlineViewController.svelte.js +134 -0
- package/dist/utils/dateText.d.ts +25 -0
- package/dist/utils/dateText.js +71 -0
- package/dist/utils/geometry.types.d.ts +13 -0
- package/dist/utils/geometry.types.js +1 -0
- package/dist/utils/json.types.d.ts +4 -0
- package/dist/utils/json.types.js +1 -0
- package/dist/utils/platform.d.ts +8 -0
- package/dist/utils/platform.js +10 -0
- package/dist/utils/result.types.d.ts +7 -0
- package/dist/utils/result.types.js +1 -0
- package/package.json +109 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { AllSelection, Plugin, TextSelection } from 'prosemirror-state';
|
|
2
|
+
import { bodySelection } from '../../models/document/bodySelection';
|
|
3
|
+
import { outlineSchema } from '../../models/document/schema';
|
|
4
|
+
import { isDocumentReplacement } from '../transaction';
|
|
5
|
+
import { originOf } from '../transactionOrigin';
|
|
6
|
+
const FRONT_MATTER = outlineSchema.nodes.front_matter;
|
|
7
|
+
/**
|
|
8
|
+
* 全選択の置き換えを「文書まるごとの差し替え」として成立させる見張り。
|
|
9
|
+
*
|
|
10
|
+
* **状態を持たない。** 見るのは「直前の選択が文書全体だったか」という選択の形と、その
|
|
11
|
+
* 書き換えでフロントマターに何が入ったかだけで、意図の推測も控えの状態も持たない。
|
|
12
|
+
* フロントマターは文書の最初のノードなので、テキストの選択がその手前から始まることは
|
|
13
|
+
* 構造上ありえず、**外からフロントマターへ流れ込む選択は文書全体の選択ただ 1 つ**である。
|
|
14
|
+
* 塞ぐ門はここにしかない。
|
|
15
|
+
*
|
|
16
|
+
* 見張りが要るのは、フロントマターが**文書の最初の「文字を置ける場所」**だからである。
|
|
17
|
+
* 全選択への置き換えで、編集基盤は文字を最初に置ける位置——フロントマターの中——へ入れる
|
|
18
|
+
* 。スキーマの `isolating` では防げない(充填処理は挿入先の判定に `isolating` を使わない)。
|
|
19
|
+
*
|
|
20
|
+
* **もう 1 つ、選択が境界をまたぐ道がある。** 中から外へ伸びた選択を消すと、外に残った
|
|
21
|
+
* 文字がフロントマターへ流れ込む(`Shift+↓` で行ごと選び、消したときに起きる)。ここでも
|
|
22
|
+
* `isolating` は効かない——`deleteRange` は見るが、そこで畳めずに素の削除へ落ちた先の
|
|
23
|
+
* 充填処理が見ていない。**またぐ選択そのものを作らせない**ことで、削除・打鍵・貼り付け・
|
|
24
|
+
* 切り取り・引きずりのどこから来ても同じ 1 か所で塞ぐ。
|
|
25
|
+
*/
|
|
26
|
+
export function frontMatterGuardPlugin() {
|
|
27
|
+
return new Plugin({
|
|
28
|
+
props: {
|
|
29
|
+
/**
|
|
30
|
+
* 文書全体を選んで打った文字は、フロントマターではなく本文の先頭へ置く
|
|
31
|
+
*。
|
|
32
|
+
*
|
|
33
|
+
* **本文の形は既定の置き換えに委ねる。** 選択を消すところまでを編集基盤に任せると、
|
|
34
|
+
* フロントマターが無い文書に同じ操作をした場合と同じ形になる。
|
|
35
|
+
* この見張りが受け持つのは、フロントマターを空にすることと文字の着地点だけである。
|
|
36
|
+
*/
|
|
37
|
+
handleTextInput(view, _from, _to, text) {
|
|
38
|
+
if (!(view.state.selection instanceof AllSelection))
|
|
39
|
+
return false;
|
|
40
|
+
const tr = view.state.tr;
|
|
41
|
+
// 文書全体の削除は、フロントマターを空にし、本文を空の 1 行へ戻す
|
|
42
|
+
tr.deleteSelection();
|
|
43
|
+
const at = bodySelection(tr.doc).from;
|
|
44
|
+
tr.insertText(text, at);
|
|
45
|
+
tr.setSelection(TextSelection.create(tr.doc, at + text.length));
|
|
46
|
+
view.dispatch(tr.scrollIntoView());
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
/**
|
|
51
|
+
* 置き換えの結果カーソルがフロントマターの中に立ったら、本文へ移す
|
|
52
|
+
*。削除・貼り付けなど**どの経路から来ても同じ網にかかる**。
|
|
53
|
+
*
|
|
54
|
+
* **文字が入っていれば、その文字ごと本文へ移す。** 日本語入力の変換は
|
|
55
|
+
* `handleTextInput` を通らず書き換えとして届くため、着地点だけを直すと
|
|
56
|
+
* 打った文字がメタデータの中に残る。経路ごとの補正を足すかわりに、結果を見て直す
|
|
57
|
+
* この 1 か所で揃える。
|
|
58
|
+
*/
|
|
59
|
+
appendTransaction(transactions, oldState, newState) {
|
|
60
|
+
const held = holdSelectionInside(newState);
|
|
61
|
+
if (held)
|
|
62
|
+
return held;
|
|
63
|
+
const edits = transactions.filter((transaction) => transaction.docChanged);
|
|
64
|
+
if (edits.length === 0)
|
|
65
|
+
return null;
|
|
66
|
+
// 差し替え(貼り付け)と、外から与えられた変更は見張らない。
|
|
67
|
+
// どちらもメタデータごと入れ替わるのが正しく、書き換えの中身からは区別できない
|
|
68
|
+
if (edits.some((edit) => isDocumentReplacement(edit) || originOf(edit) !== null))
|
|
69
|
+
return null;
|
|
70
|
+
if (!(oldState.selection instanceof AllSelection))
|
|
71
|
+
return null;
|
|
72
|
+
const written = newState.doc.child(0).textContent;
|
|
73
|
+
if (!written) {
|
|
74
|
+
return isInFrontMatter(newState.selection)
|
|
75
|
+
? newState.tr.setSelection(bodySelection(newState.doc))
|
|
76
|
+
: null;
|
|
77
|
+
}
|
|
78
|
+
// 中身が変わっていなければ、その書き換えはフロントマターに触れていない
|
|
79
|
+
// (全選択のままの書式付けなど)。触れていないものを動かさない
|
|
80
|
+
if (written === oldState.doc.child(0).textContent)
|
|
81
|
+
return null;
|
|
82
|
+
const tr = newState.tr.delete(1, 1 + written.length);
|
|
83
|
+
const at = bodySelection(tr.doc).from;
|
|
84
|
+
tr.insertText(written, at);
|
|
85
|
+
return tr.setSelection(TextSelection.create(tr.doc, at + written.length));
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/** その選択がフロントマターの中にあるか */
|
|
90
|
+
function isInFrontMatter(selection) {
|
|
91
|
+
return selection.$from.parent.type === FRONT_MATTER;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 選択がフロントマターの内と外にまたがっていたら、頭を境界へ引き戻す。
|
|
95
|
+
*
|
|
96
|
+
* **またいだまま消すと、外に残った文字がフロントマターへ流れ込む。** メタデータは本文を
|
|
97
|
+
* 受け取る場所ではないので、そもそもまたがせない。動かすのは頭だけで、起点は置いたまま
|
|
98
|
+
* にする——伸ばす向きへ押し続けても境界で止まり、戻す向きへ押せば普通に縮む。
|
|
99
|
+
*
|
|
100
|
+
* 全選択(`AllSelection`)はここで扱わない。文書まるごとの差し替えとして成立させる道が
|
|
101
|
+
* 別にあり(→ `handleTextInput`)、そちらはメタデータごと入れ替わるのが正しい。
|
|
102
|
+
*/
|
|
103
|
+
function holdSelectionInside(state) {
|
|
104
|
+
const selection = state.selection;
|
|
105
|
+
if (!(selection instanceof TextSelection))
|
|
106
|
+
return null;
|
|
107
|
+
const inside = frontMatterRange(state.doc);
|
|
108
|
+
if (!inside)
|
|
109
|
+
return null;
|
|
110
|
+
const anchorInside = covers(inside, selection.anchor);
|
|
111
|
+
if (anchorInside === covers(inside, selection.head))
|
|
112
|
+
return null;
|
|
113
|
+
const head = anchorInside
|
|
114
|
+
? Math.min(Math.max(selection.head, inside.from), inside.to)
|
|
115
|
+
: bodySelection(state.doc).from;
|
|
116
|
+
if (head === selection.head)
|
|
117
|
+
return null;
|
|
118
|
+
const anchor = head === inside.to
|
|
119
|
+
? withLineBreakBefore(state.doc, selection.anchor, inside)
|
|
120
|
+
: selection.anchor;
|
|
121
|
+
const tr = state.tr.setSelection(TextSelection.create(state.doc, anchor, head));
|
|
122
|
+
// 表示上の丸めであって、取り消しの対象になる編集ではない
|
|
123
|
+
tr.setMeta('addToHistory', false);
|
|
124
|
+
return tr;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* 中身の終わりで止めた選択が行頭から始まっていたら、手前の改行まで含める。
|
|
128
|
+
*
|
|
129
|
+
* **最後の行だけ、続く改行を持たない。** 他の行は下へ伸ばすと次の行頭まで(改行ごと)
|
|
130
|
+
* 選ばれるので行ごと消えるが、最後の行は境界で止まるため文字だけが選ばれ、消したあとに
|
|
131
|
+
* 空行が残る。手前の改行を含めれば、どの行も同じように行ごと消える。
|
|
132
|
+
*
|
|
133
|
+
* 行の途中から伸ばしたときは含めない(選んだのは行ではなく、そこから後ろの文字である)。
|
|
134
|
+
* 行末で止める操作(`Shift+End`)にも効かない——あれは中身の終わりで止めた選択ではない。
|
|
135
|
+
*/
|
|
136
|
+
function withLineBreakBefore(doc, anchor, inside) {
|
|
137
|
+
if (anchor <= inside.from)
|
|
138
|
+
return anchor;
|
|
139
|
+
return doc.textBetween(anchor - 1, anchor) === '\n' ? anchor - 1 : anchor;
|
|
140
|
+
}
|
|
141
|
+
/** フロントマターの中身が占める範囲。フロントマターを持たなければ `null` */
|
|
142
|
+
function frontMatterRange(doc) {
|
|
143
|
+
const front = doc.firstChild;
|
|
144
|
+
if (front?.type !== FRONT_MATTER)
|
|
145
|
+
return null;
|
|
146
|
+
return { from: 1, to: 1 + front.content.size };
|
|
147
|
+
}
|
|
148
|
+
function covers(range, pos) {
|
|
149
|
+
return pos >= range.from && pos <= range.to;
|
|
150
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Plugin } from 'prosemirror-state';
|
|
2
|
+
/** 表示のたびに読み直す、フロントマターの見せ方を決めるもの */
|
|
3
|
+
export interface FrontMatterDisplay {
|
|
4
|
+
/** 中身が空のときに出す、そのブロックの名前 */
|
|
5
|
+
readonly label: string;
|
|
6
|
+
/** 日時の書き方を決める言語。文言の一式を選ぶのと同じものを使う */
|
|
7
|
+
readonly lang: string;
|
|
8
|
+
/**
|
|
9
|
+
* 編集できるか。読み取り専用のときは、カーソルが中にあっても読む形のままにする
|
|
10
|
+
* ——直せないのだから、機械向けの表記を見せる理由が無い。
|
|
11
|
+
*/
|
|
12
|
+
readonly editable: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* `front_matter` の NodeView と編集中 decoration を 1 つの Plugin として返す。
|
|
16
|
+
*
|
|
17
|
+
* **カーソルの内外で見せるものを変えない。** 中身をそのまま出し、変わるのはサーフェス(背景)と
|
|
18
|
+
* 余白だけである。かつては外にあるあいだ `title` の行だけを読んで出していたが、
|
|
19
|
+
* モジュールが特定の項目名を知る根拠が無く、`title` を書いていない文書は他に何を
|
|
20
|
+
* 書いていてもメタデータを持たない文書と同じに見えていた。
|
|
21
|
+
*
|
|
22
|
+
* 中身が空のときは**そのブロックの名前**を薄く出す。「メタデータが未設定である」と状態を
|
|
23
|
+
* 告げる表示は置かない——編集エリアは人に見せる面でもあり、催促はそこに置くものではない。
|
|
24
|
+
* 一方で何も見えないと、**書き足す入口が画面から消える**。出すのは状態の説明ではなく、
|
|
25
|
+
* そこが何であるかの名前である。
|
|
26
|
+
*
|
|
27
|
+
* **読むあいだは、日時を人の読む形へ置き換える**(→ `dateText`)。カーソルを入れれば
|
|
28
|
+
* 書かれたとおりの文字が出る。読み取り専用では、直せないのだから読む形のままにする。
|
|
29
|
+
*
|
|
30
|
+
* `getDisplay` は呼び出し時点の値を返す(言語・差し替えの変更に追随させるため関数で渡す)。
|
|
31
|
+
*
|
|
32
|
+
* **文書を変えない。** 表示だけを受け持つ。
|
|
33
|
+
*/
|
|
34
|
+
export declare function frontMatterViewPlugin(getDisplay: () => FrontMatterDisplay): Plugin;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { Plugin } from 'prosemirror-state';
|
|
2
|
+
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
3
|
+
import { outlineSchema } from '../../models/document/schema';
|
|
4
|
+
import { findDateText } from '../../utils/dateText';
|
|
5
|
+
const FRONT_MATTER = outlineSchema.nodes.front_matter;
|
|
6
|
+
/**
|
|
7
|
+
* `front_matter` の NodeView と編集中 decoration を 1 つの Plugin として返す。
|
|
8
|
+
*
|
|
9
|
+
* **カーソルの内外で見せるものを変えない。** 中身をそのまま出し、変わるのはサーフェス(背景)と
|
|
10
|
+
* 余白だけである。かつては外にあるあいだ `title` の行だけを読んで出していたが、
|
|
11
|
+
* モジュールが特定の項目名を知る根拠が無く、`title` を書いていない文書は他に何を
|
|
12
|
+
* 書いていてもメタデータを持たない文書と同じに見えていた。
|
|
13
|
+
*
|
|
14
|
+
* 中身が空のときは**そのブロックの名前**を薄く出す。「メタデータが未設定である」と状態を
|
|
15
|
+
* 告げる表示は置かない——編集エリアは人に見せる面でもあり、催促はそこに置くものではない。
|
|
16
|
+
* 一方で何も見えないと、**書き足す入口が画面から消える**。出すのは状態の説明ではなく、
|
|
17
|
+
* そこが何であるかの名前である。
|
|
18
|
+
*
|
|
19
|
+
* **読むあいだは、日時を人の読む形へ置き換える**(→ `dateText`)。カーソルを入れれば
|
|
20
|
+
* 書かれたとおりの文字が出る。読み取り専用では、直せないのだから読む形のままにする。
|
|
21
|
+
*
|
|
22
|
+
* `getDisplay` は呼び出し時点の値を返す(言語・差し替えの変更に追随させるため関数で渡す)。
|
|
23
|
+
*
|
|
24
|
+
* **文書を変えない。** 表示だけを受け持つ。
|
|
25
|
+
*/
|
|
26
|
+
export function frontMatterViewPlugin(getDisplay) {
|
|
27
|
+
return new Plugin({
|
|
28
|
+
props: {
|
|
29
|
+
decorations: (state) => decorationsFor(state, getDisplay()),
|
|
30
|
+
nodeViews: {
|
|
31
|
+
front_matter: (node, view, _getPos, decorations) => new FrontMatterView(node, view, getDisplay, decorations)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const EDITING_CLASS = 'markdown-editor__front-matter--editing';
|
|
37
|
+
const EMPTY_CLASS = 'markdown-editor__front-matter--empty';
|
|
38
|
+
/** 書かれたとおりの日時を隠す印。読む形の文字はこの手前に差し込む */
|
|
39
|
+
const RAW_CLASS = 'markdown-editor__front-matter-raw';
|
|
40
|
+
/**
|
|
41
|
+
* 編集中のフラグと、日時の置き換えを組み立てる。
|
|
42
|
+
*
|
|
43
|
+
* 「選択がフロントマターの中」の判定はここに閉じ、NodeView は印を class へ写すだけに
|
|
44
|
+
* する。日時の置き換えは、その印が付かないあいだ(=読むあいだ)だけ当てる。
|
|
45
|
+
*/
|
|
46
|
+
function decorationsFor(state, display) {
|
|
47
|
+
const front = state.doc.child(0);
|
|
48
|
+
if (front.type !== FRONT_MATTER)
|
|
49
|
+
return DecorationSet.empty;
|
|
50
|
+
const { $from, $to } = state.selection;
|
|
51
|
+
const inside = $from.parent.type === FRONT_MATTER && $from.sameParent($to);
|
|
52
|
+
if (inside && display.editable) {
|
|
53
|
+
return DecorationSet.create(state.doc, [
|
|
54
|
+
Decoration.node($from.before(), $from.after(), {}, { frontMatterEditing: true })
|
|
55
|
+
]);
|
|
56
|
+
}
|
|
57
|
+
return DecorationSet.create(state.doc, readableDateDecorations(front, display.lang));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 中身の日時を、読む形の文字で覆う。
|
|
61
|
+
*
|
|
62
|
+
* 書かれた文字は**消さずに隠す**。取り除いてしまうと、キャレットの位置と文書の位置の
|
|
63
|
+
* 対応が崩れる(覆っているのは表示だけで、文書は 1 文字も変わらない)。
|
|
64
|
+
*/
|
|
65
|
+
function readableDateDecorations(front, lang) {
|
|
66
|
+
const decorations = [];
|
|
67
|
+
// `front_matter` の中身は先頭が 1、その中でのずれをそのまま足せる
|
|
68
|
+
const offset = 1;
|
|
69
|
+
for (const match of findDateText(front.textContent, lang)) {
|
|
70
|
+
const from = offset + match.start;
|
|
71
|
+
const to = offset + match.end;
|
|
72
|
+
decorations.push(Decoration.inline(from, to, { class: RAW_CLASS }), Decoration.widget(from, () => readableDom(match.text), { side: -1 }));
|
|
73
|
+
}
|
|
74
|
+
return decorations;
|
|
75
|
+
}
|
|
76
|
+
function readableDom(text) {
|
|
77
|
+
const element = document.createElement('span');
|
|
78
|
+
element.className = 'markdown-editor__front-matter-readable';
|
|
79
|
+
element.contentEditable = 'false';
|
|
80
|
+
element.textContent = text;
|
|
81
|
+
return element;
|
|
82
|
+
}
|
|
83
|
+
class FrontMatterView {
|
|
84
|
+
dom;
|
|
85
|
+
contentDOM;
|
|
86
|
+
view;
|
|
87
|
+
getDisplay;
|
|
88
|
+
label;
|
|
89
|
+
constructor(node, view, getDisplay, decorations) {
|
|
90
|
+
this.view = view;
|
|
91
|
+
this.getDisplay = getDisplay;
|
|
92
|
+
this.dom = document.createElement('div');
|
|
93
|
+
this.dom.className = 'markdown-editor__front-matter';
|
|
94
|
+
const source = document.createElement('pre');
|
|
95
|
+
source.className = 'markdown-editor__front-matter-source';
|
|
96
|
+
this.contentDOM = document.createElement('code');
|
|
97
|
+
source.append(this.contentDOM);
|
|
98
|
+
// 名前は自前で管理する(編集の対象にしない)
|
|
99
|
+
this.label = document.createElement('div');
|
|
100
|
+
this.label.className = 'markdown-editor__front-matter-label';
|
|
101
|
+
this.label.contentEditable = 'false';
|
|
102
|
+
this.dom.append(source, this.label);
|
|
103
|
+
this.applyEditing(decorations);
|
|
104
|
+
this.showLabel(node);
|
|
105
|
+
}
|
|
106
|
+
update(node, decorations) {
|
|
107
|
+
if (node.type !== FRONT_MATTER)
|
|
108
|
+
return false;
|
|
109
|
+
this.applyEditing(decorations);
|
|
110
|
+
this.showLabel(node);
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
/** 名前の側の変更を編集基盤の監視から除外する(中身の側は除外しない) */
|
|
114
|
+
ignoreMutation(mutation) {
|
|
115
|
+
if (mutation.type === 'selection')
|
|
116
|
+
return false;
|
|
117
|
+
return !this.contentDOM.contains(mutation.target);
|
|
118
|
+
}
|
|
119
|
+
/** 編集中のフラグは「編集可能 かつ 選択が中(decoration 由来)」のときだけ付く */
|
|
120
|
+
applyEditing(decorations) {
|
|
121
|
+
const editing = this.view.editable && decorations.some((decoration) => decoration.spec.frontMatterEditing);
|
|
122
|
+
this.dom.classList.toggle(EDITING_CLASS, editing);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* 中身が空かどうかだけを印にし、ブロックの名前を書き込む。**出し分けは CSS が行う。**
|
|
126
|
+
*
|
|
127
|
+
* 空は「表示すべき文字を持たない」で判定する。文字どおりの空文字列だけを空とすると、
|
|
128
|
+
* 中身を消して改行が残った状態で名前が出ず、書き足す入口が画面から消える。
|
|
129
|
+
*
|
|
130
|
+
* 中身を読むのはこの判定に限る。**特定の項目名を知らない。** 文言は表示を更新する
|
|
131
|
+
* たびに読み直す(差し替えと言語の変更に追随させるため)。
|
|
132
|
+
*/
|
|
133
|
+
showLabel(node) {
|
|
134
|
+
this.dom.classList.toggle(EMPTY_CLASS, node.textContent.trim() === '');
|
|
135
|
+
this.label.textContent = this.getDisplay().label;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Plugin } from 'prosemirror-state';
|
|
2
|
+
import { outlineSchema } from '../../models/document/schema';
|
|
3
|
+
import { URL_PATTERN } from '../commands/link';
|
|
4
|
+
/** 選択した範囲に URL を貼ると、その範囲をリンクの文字にする */
|
|
5
|
+
export function linkPastePlugin() {
|
|
6
|
+
return new Plugin({
|
|
7
|
+
props: {
|
|
8
|
+
handlePaste: (view, event) => {
|
|
9
|
+
const text = event.clipboardData?.getData('text/plain')?.trim();
|
|
10
|
+
if (!text || !URL_PATTERN.test(text))
|
|
11
|
+
return false;
|
|
12
|
+
if (view.state.selection.empty)
|
|
13
|
+
return false;
|
|
14
|
+
const { from, to } = view.state.selection;
|
|
15
|
+
view.dispatch(view.state.tr.addMark(from, to, outlineSchema.marks.link.create({ href: text })));
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Plugin } from 'prosemirror-state';
|
|
2
|
+
/**
|
|
3
|
+
* 箇条書きの形を、書き換えのたびに整える。
|
|
4
|
+
*
|
|
5
|
+
* 補正を個々の操作へ配らず 1 つの覆いにまとめるのは、**壊れた形の作られ方が 1 つでは
|
|
6
|
+
* ない**ためである。範囲選択での削除・貼り付け・利用者からの本文の差し替え・取り消しの
|
|
7
|
+
* どれもが同じ形を作りうる。入口ごとに手当てすると、必ずどれかが漏れる。
|
|
8
|
+
*
|
|
9
|
+
* **取り消しの履歴から外さない。** 外すと、取り消しは補正を織り込んだ位置へ戻そうとして
|
|
10
|
+
* 元の形に戻せなくなる。補正は書き換えの直後に続くため、取り消しの単位としては
|
|
11
|
+
* 元の操作と同じセクションに入り、1 回で操作の前へ戻る。
|
|
12
|
+
*/
|
|
13
|
+
export declare function listStructurePlugin(): Plugin;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Plugin } from 'prosemirror-state';
|
|
2
|
+
import { correctItemDepth } from '../commands/list';
|
|
3
|
+
/**
|
|
4
|
+
* 箇条書きの形を、書き換えのたびに整える。
|
|
5
|
+
*
|
|
6
|
+
* 補正を個々の操作へ配らず 1 つの覆いにまとめるのは、**壊れた形の作られ方が 1 つでは
|
|
7
|
+
* ない**ためである。範囲選択での削除・貼り付け・利用者からの本文の差し替え・取り消しの
|
|
8
|
+
* どれもが同じ形を作りうる。入口ごとに手当てすると、必ずどれかが漏れる。
|
|
9
|
+
*
|
|
10
|
+
* **取り消しの履歴から外さない。** 外すと、取り消しは補正を織り込んだ位置へ戻そうとして
|
|
11
|
+
* 元の形に戻せなくなる。補正は書き換えの直後に続くため、取り消しの単位としては
|
|
12
|
+
* 元の操作と同じセクションに入り、1 回で操作の前へ戻る。
|
|
13
|
+
*/
|
|
14
|
+
export function listStructurePlugin() {
|
|
15
|
+
return new Plugin({
|
|
16
|
+
appendTransaction: (transactions, _oldState, newState) => transactions.some((transaction) => transaction.docChanged) ? correctItemDepth(newState) : null
|
|
17
|
+
});
|
|
18
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { Fragment, Slice } from 'prosemirror-model';
|
|
2
|
+
import { AllSelection, Plugin, TextSelection } from 'prosemirror-state';
|
|
3
|
+
import { isInTable } from 'prosemirror-tables';
|
|
4
|
+
import { bodySelection } from '../../models/document/bodySelection';
|
|
5
|
+
import { parseMarkdown } from '../../models/markdown/parser';
|
|
6
|
+
import { serializeSlice } from '../../models/markdown/serializer';
|
|
7
|
+
import { MAX_HEADING_LEVEL } from '../../models/document/document.types';
|
|
8
|
+
import { outlineSchema } from '../../models/document/schema';
|
|
9
|
+
import { sectionTree } from '../../models/document/sectionTree';
|
|
10
|
+
import { markDocumentReplacement } from '../transaction';
|
|
11
|
+
const n = outlineSchema.nodes;
|
|
12
|
+
/**
|
|
13
|
+
* クリップボードとのやり取りをマークダウンで行う。
|
|
14
|
+
*
|
|
15
|
+
* - 貼り付け: 記法を解釈し、貼り付け先の深さに合わせて見出しのレベルを付け替える
|
|
16
|
+
* - コピー: 選択範囲を階層構造を保ったマークダウンとして書き出す
|
|
17
|
+
*/
|
|
18
|
+
export function markdownClipboardPlugin() {
|
|
19
|
+
return new Plugin({
|
|
20
|
+
props: {
|
|
21
|
+
clipboardTextSerializer: (slice) => serializeSlice(slice),
|
|
22
|
+
handlePaste: (view, event) => {
|
|
23
|
+
if (!view.editable)
|
|
24
|
+
return false;
|
|
25
|
+
const text = event.clipboardData?.getData('text/plain');
|
|
26
|
+
if (!text)
|
|
27
|
+
return false;
|
|
28
|
+
// コードブロックと表のセルの中では、ブロック要素を作らず文字として扱う
|
|
29
|
+
if (view.state.selection.$from.parent.type.spec.code)
|
|
30
|
+
return false;
|
|
31
|
+
if (isInTable(view.state))
|
|
32
|
+
return false;
|
|
33
|
+
const parsed = parseMarkdown(text);
|
|
34
|
+
if (!parsed.ok)
|
|
35
|
+
return false;
|
|
36
|
+
// 文書全体への貼り付けは**差し替え**である。メタデータごと入れ替わる
|
|
37
|
+
if (view.state.selection instanceof AllSelection) {
|
|
38
|
+
view.dispatch(replaceDocument(view.state, parsed.value.content).scrollIntoView());
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
const baseDepth = pasteDepth(view.state.doc, view.state.selection.from);
|
|
42
|
+
const content = relevel(frontMatterAsCodeBlock(parsed.value.content), baseDepth);
|
|
43
|
+
if (content.childCount === 0)
|
|
44
|
+
return false;
|
|
45
|
+
const transaction = intoEmptyItem(view.state, content) ?? view.state.tr.replaceSelection(pasted(content));
|
|
46
|
+
view.dispatch(transaction.scrollIntoView());
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 貼り付ける断片。**段落 1 つなら、行としてではなく文字として差し込む。**
|
|
54
|
+
*
|
|
55
|
+
* 閉じた断片(`openStart` / `openEnd` が 0)は行として置かれる。行の途中へ貼ると
|
|
56
|
+
* 貼り先の行が 2 つに割れ、見出しの途中なら見出しが 2 つに増える。記法を持たない
|
|
57
|
+
* 段落 1 つは「行」ではなく「文字」であり、カーソルの位置へそのまま入るのが正しい。
|
|
58
|
+
*
|
|
59
|
+
* 2 つ以上のブロックや、記法を持つブロック(項目・見出し・引用)は行として置く。
|
|
60
|
+
* そこでは貼り先の行が割れるのが期待どおりの結果である。
|
|
61
|
+
*/
|
|
62
|
+
function pasted(content) {
|
|
63
|
+
const only = content.childCount === 1 ? content.firstChild : null;
|
|
64
|
+
return only?.type === n.paragraph ? new Slice(only.content, 0, 0) : new Slice(content, 0, 0);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 文書全体への貼り付け。**貼り先を貼った側でまるごと置き換える。**
|
|
68
|
+
*
|
|
69
|
+
* 貼った側がフロントマターを持たなければ、読み込みが空のフロントマターを作るので、
|
|
70
|
+
* 貼り先のメタデータはそのまま空になる。カーソルは本文へ置く。
|
|
71
|
+
*/
|
|
72
|
+
function replaceDocument(state, content) {
|
|
73
|
+
const tr = state.tr.replaceWith(0, state.doc.content.size, content);
|
|
74
|
+
tr.setSelection(bodySelection(tr.doc));
|
|
75
|
+
// 全選択の見張りへ「これは差し替えである」と伝える。伝えないと、貼ったメタデータが
|
|
76
|
+
// 打ち間違いとして本文へ移される
|
|
77
|
+
return markDocumentReplacement(tr);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 貼った内容の先頭にあるフロントマターを、`yaml` のコードブロックへ置き換える。中身が無ければ
|
|
81
|
+
* 取り除く。
|
|
82
|
+
*
|
|
83
|
+
* 貼り先のフロントマターは触らない。挿入で貼り先のメタデータが
|
|
84
|
+
* 書き換わってはならず、かといって貼った側の文字を捨てることもできないため、
|
|
85
|
+
* **文字を失わないコンテナ**へ移す。区切りの行を中身に含めるのは、
|
|
86
|
+
* 切り取ってメタデータ欄へ貼り直せるようにするためである。
|
|
87
|
+
*/
|
|
88
|
+
function frontMatterAsCodeBlock(content) {
|
|
89
|
+
const first = content.firstChild;
|
|
90
|
+
if (first?.type !== n.front_matter)
|
|
91
|
+
return content;
|
|
92
|
+
const rest = content.cut(first.nodeSize);
|
|
93
|
+
if (first.content.size === 0)
|
|
94
|
+
return rest;
|
|
95
|
+
const source = outlineSchema.text(`---\n${first.textContent}\n---`);
|
|
96
|
+
return Fragment.from(n.code_block.createChecked({ language: 'yaml' }, source)).append(rest);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 空の項目への貼り付け。**貼り付ける内容がその項目に成り代わる。** 対象でなければ null。
|
|
100
|
+
*
|
|
101
|
+
* 既定の置き換えは、空のテキストブロックを行き先の候補として数えず、収まる場所を外へ
|
|
102
|
+
* 探しに行く。結果、項目がまるごと消えて段落になる(文字を貼ったとき)か、項目の中へ
|
|
103
|
+
* 入って 1 段深くなる(項目を貼ったとき)。どちらも書き手が指していた項目が失われる。
|
|
104
|
+
*
|
|
105
|
+
* 空の項目は「まだ書いていない項目」であり、貼り付けはそこに書くことである。したがって
|
|
106
|
+
* 文字なら**その項目の本文**になり、項目なら**その項目と入れ替わる**(深さは変わらない)。
|
|
107
|
+
* **配下は保つ**。書いていなかった本文が埋まっただけなので、子は子のままである。
|
|
108
|
+
*/
|
|
109
|
+
function intoEmptyItem(state, content) {
|
|
110
|
+
const item = emptyItemAt(state);
|
|
111
|
+
// 見出し(`section`)を含む内容は項目の中に置けない。既定の置き換えへ譲る
|
|
112
|
+
if (!item || !n.list.validContent(content))
|
|
113
|
+
return null;
|
|
114
|
+
const children = item.node.content.cut(item.node.child(0).nodeSize);
|
|
115
|
+
const replacesItem = content.child(0).type === n.list;
|
|
116
|
+
const tr = state.tr;
|
|
117
|
+
tr.replaceWith(item.pos, item.pos + item.node.nodeSize, replacement(item.node, content, children));
|
|
118
|
+
// 貼り付けた内容の末尾(最後に貼ったブロックの中)へ。配下はその後ろに続く。
|
|
119
|
+
// 項目に成り代わったときは中身が 1 段外側に並ぶぶん、位置が 1 つ手前になる
|
|
120
|
+
const end = item.pos + content.size + (replacesItem ? -1 : 0);
|
|
121
|
+
tr.setSelection(TextSelection.near(tr.doc.resolve(Math.min(end, tr.doc.content.size)), -1));
|
|
122
|
+
return tr;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* 空の項目を置き換える中身。
|
|
126
|
+
*
|
|
127
|
+
* 貼り付ける内容の**先頭が項目かどうか**だけで決める。先頭が項目なら並びごと入れ替わり、
|
|
128
|
+
* 配下は最後の項目に付く(最後が項目でなければ、並びの後ろへそのまま残す)。
|
|
129
|
+
* 先頭が項目でなければ、内容は項目の本文になる(項目そのものは残る)。
|
|
130
|
+
*/
|
|
131
|
+
function replacement(item, content, children) {
|
|
132
|
+
if (content.child(0).type !== n.list)
|
|
133
|
+
return [item.copy(content.append(children))];
|
|
134
|
+
const nodes = toArray(content);
|
|
135
|
+
const last = nodes[nodes.length - 1];
|
|
136
|
+
if (last.type !== n.list)
|
|
137
|
+
return [...nodes, ...toArray(children)];
|
|
138
|
+
return [...nodes.slice(0, -1), last.copy(last.content.append(children))];
|
|
139
|
+
}
|
|
140
|
+
/** カーソルが項目の本文にあり、その本文が空のとき、その項目 */
|
|
141
|
+
function emptyItemAt(state) {
|
|
142
|
+
const cursor = state.selection instanceof TextSelection ? state.selection.$cursor : null;
|
|
143
|
+
if (!cursor || cursor.parent.content.size > 0)
|
|
144
|
+
return null;
|
|
145
|
+
const depth = cursor.depth - 1;
|
|
146
|
+
if (depth < 1)
|
|
147
|
+
return null;
|
|
148
|
+
const item = cursor.node(depth);
|
|
149
|
+
if (item.type !== n.list || cursor.index(depth) !== 0)
|
|
150
|
+
return null;
|
|
151
|
+
return { node: item, pos: cursor.before(depth) };
|
|
152
|
+
}
|
|
153
|
+
/** 貼り付け先のセクションの深さ。見出しを持たないセクションと文書直下は 0 */
|
|
154
|
+
function pasteDepth(doc, pos) {
|
|
155
|
+
const section = sectionTree.resolveSection(doc, pos);
|
|
156
|
+
return section?.level ?? 0;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* 貼り付ける内容の見出しを、貼り付け先の深さに合わせて付け替える。
|
|
160
|
+
* 相対的な階層関係は保つ。最下位を超える見出しは段落として取り込み、文字を失わない。
|
|
161
|
+
*/
|
|
162
|
+
function relevel(content, baseDepth) {
|
|
163
|
+
const nodes = [];
|
|
164
|
+
content.forEach((child) => {
|
|
165
|
+
if (child.type === n.intro_section) {
|
|
166
|
+
nodes.push(...toArray(relevel(child.content, baseDepth)));
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (child.type !== n.section) {
|
|
170
|
+
nodes.push(child);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
nodes.push(...relevelSection(child, baseDepth + 1));
|
|
174
|
+
});
|
|
175
|
+
return Fragment.fromArray(nodes);
|
|
176
|
+
}
|
|
177
|
+
function relevelSection(section, depth) {
|
|
178
|
+
const heading = section.child(0);
|
|
179
|
+
const rest = Fragment.fromArray(toArray(section.content).slice(1));
|
|
180
|
+
if (depth > MAX_HEADING_LEVEL) {
|
|
181
|
+
// 最下位を超える見出しは段落にする(文字は残す)
|
|
182
|
+
return [n.paragraph.createChecked(null, heading.content), ...toArray(relevel(rest, depth - 1))];
|
|
183
|
+
}
|
|
184
|
+
// ブロックはセクションより前にしか置けないため、集めてから並べ直す
|
|
185
|
+
const blocks = [];
|
|
186
|
+
const sections = [];
|
|
187
|
+
rest.forEach((child) => {
|
|
188
|
+
if (child.type !== n.section) {
|
|
189
|
+
blocks.push(child);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
for (const node of relevelSection(child, depth + 1)) {
|
|
193
|
+
(node.type === n.section ? sections : blocks).push(node);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
return [
|
|
197
|
+
n.section.createChecked(null, [
|
|
198
|
+
n.heading.createChecked({ level: depth }, heading.content),
|
|
199
|
+
...blocks,
|
|
200
|
+
...sections
|
|
201
|
+
])
|
|
202
|
+
];
|
|
203
|
+
}
|
|
204
|
+
function toArray(content) {
|
|
205
|
+
const nodes = [];
|
|
206
|
+
content.forEach((child) => nodes.push(child));
|
|
207
|
+
return nodes;
|
|
208
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type mermaidType from 'mermaid';
|
|
2
|
+
import { Plugin } from 'prosemirror-state';
|
|
3
|
+
type Mermaid = typeof mermaidType;
|
|
4
|
+
/** Mermaid ブロックが画面に出す文言。`EditorMessages` から editorSession が写す */
|
|
5
|
+
export interface MermaidBlockText {
|
|
6
|
+
readonly empty: string;
|
|
7
|
+
readonly loading: string;
|
|
8
|
+
readonly renderError: string;
|
|
9
|
+
readonly loadError: string;
|
|
10
|
+
}
|
|
11
|
+
/** 1 度だけ動的 import + 初期化する。失敗したら次の呼び出しで再試行する */
|
|
12
|
+
export declare function loadMermaid(): Promise<Mermaid>;
|
|
13
|
+
/** テストが「import しただけでは読み込まれない」ことを観測するための述語 */
|
|
14
|
+
export declare function mermaidLoadStarted(): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* `mermaid_block` の NodeView と編集中 decoration を 1 つの Plugin として返す。
|
|
17
|
+
* `getText` は呼び出し時点の文言を返す(言語・差し替えの変更に追随させるため関数で渡す)。
|
|
18
|
+
*/
|
|
19
|
+
export declare function mermaidViewPlugin(getText: () => MermaidBlockText): Plugin;
|
|
20
|
+
export {};
|