@14ch/svelte-md-outliner 0.0.19 → 0.0.21
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/CHANGELOG.md +43 -1
- package/README.ja.md +48 -25
- package/README.md +48 -25
- package/dist/assets/styles/editor.css +57 -7
- package/dist/assets/styles/theme.css +66 -11
- package/dist/components/ContextMenu.svelte +1 -1
- package/dist/components/EditorSurface.svelte +2 -2
- package/dist/components/FocusBreadcrumb.svelte +7 -1
- package/dist/components/MarkdownEditor.svelte +69 -17
- package/dist/components/MarkdownEditor.svelte.d.ts +16 -3
- package/dist/components/ShortcutHelpDialog.svelte +3 -3
- package/dist/components/internal/Modal.svelte +3 -3
- package/dist/components/internal/Popup.svelte +3 -3
- package/dist/index.d.ts +12 -4
- package/dist/index.js +4 -2
- package/dist/markdown.d.ts +2 -0
- package/dist/markdown.js +1 -0
- package/dist/messages/index.d.ts +2 -2
- package/dist/messages/index.js +2 -2
- package/dist/models/document/bodySelection.js +1 -1
- package/dist/models/document/schema.d.ts +10 -1
- package/dist/models/document/schema.js +13 -2
- package/dist/models/document/sectionTree.d.ts +1 -1
- package/dist/models/document/sectionTree.js +2 -2
- package/dist/models/markdown/normalize.d.ts +20 -0
- package/dist/models/markdown/normalize.js +25 -0
- package/dist/models/markdown/parser.js +8 -6
- package/dist/models/markdown/serializer.js +12 -11
- package/dist/models/viewState/viewStateCodec.d.ts +1 -1
- package/dist/models/viewState/viewStateCodec.js +3 -3
- package/dist/operations/autoformat.js +3 -3
- package/dist/operations/commands/block.js +4 -4
- package/dist/operations/commands/element.js +9 -9
- package/dist/operations/commands/fencedBlock.js +2 -2
- package/dist/operations/commands/frontMatter.js +5 -5
- package/dist/operations/commands/lineBreak.js +1 -1
- package/dist/operations/commands/link.js +1 -1
- package/dist/operations/commands/list.js +59 -6
- package/dist/operations/commands/section.d.ts +1 -1
- package/dist/operations/commands/section.js +5 -5
- package/dist/operations/commands/sectionFold.d.ts +1 -1
- package/dist/operations/commands/sectionFold.js +5 -5
- package/dist/operations/commands/sectionJump.js +2 -2
- package/dist/operations/commands/selectedBlock.js +3 -3
- package/dist/operations/commands/table.js +43 -2
- package/dist/operations/documentDiff.d.ts +12 -0
- package/dist/operations/documentDiff.js +191 -0
- package/dist/operations/keymap/assemble.js +5 -5
- package/dist/operations/keymap/coreActions.js +13 -13
- package/dist/operations/keymap/menuItems.js +2 -2
- package/dist/operations/keymap/shortcutKeys.js +1 -1
- package/dist/operations/keymap/viewActions.js +5 -5
- package/dist/operations/plugins/blockHandle.js +1 -1
- package/dist/operations/plugins/compositionState.d.ts +30 -0
- package/dist/operations/plugins/compositionState.js +65 -0
- package/dist/operations/plugins/contextMenu.js +2 -2
- package/dist/operations/plugins/focus.js +19 -8
- package/dist/operations/plugins/foldClick.js +1 -1
- package/dist/operations/plugins/foldGuard.js +2 -2
- package/dist/operations/plugins/frontMatterGuard.js +4 -4
- package/dist/operations/plugins/frontMatterView.js +3 -3
- package/dist/operations/plugins/headingLevel.js +1 -1
- package/dist/operations/plugins/imagePaste.js +2 -2
- package/dist/operations/plugins/imageView.js +1 -1
- package/dist/operations/plugins/linkPaste.js +2 -2
- package/dist/operations/plugins/listStructure.js +1 -1
- package/dist/operations/plugins/markdownClipboard.js +8 -8
- package/dist/operations/plugins/mermaidView.js +2 -2
- package/dist/operations/plugins/requiredSelectionEntry.js +1 -1
- package/dist/operations/plugins/sectionView.js +1 -1
- package/dist/operations/plugins/tableHandles.js +2 -2
- package/dist/operations/transactionOrigin.d.ts +9 -5
- package/dist/operations/transactionOrigin.js +2 -1
- package/dist/states/contextMenuController.svelte.js +5 -5
- package/dist/states/editorSession.js +69 -50
- package/dist/states/editorSession.types.d.ts +41 -3
- package/dist/states/outlineViewController.svelte.d.ts +1 -7
- package/dist/states/outlineViewController.svelte.js +7 -22
- package/package.json +1 -1
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
import type {
|
|
5
5
|
FrontMatterFields,
|
|
6
6
|
FrontMatterWriteError,
|
|
7
|
-
FrontMatterWriteOutcome
|
|
8
|
-
MarkdownParseError
|
|
7
|
+
FrontMatterWriteOutcome
|
|
9
8
|
} from '../models/markdown/markdown.types';
|
|
10
9
|
import type { Result } from '../utils/result.types';
|
|
11
10
|
import type { ViewState } from '../models/viewState/viewState.types';
|
|
11
|
+
import type { ApplyOutcome, MarkdownWriteError } from '../states/editorSession.types';
|
|
12
12
|
|
|
13
13
|
export interface MarkdownEditorProps {
|
|
14
14
|
/**
|
|
@@ -141,7 +141,17 @@
|
|
|
141
141
|
* 文書全体を入れ替え、取り消し履歴を初期化する(別の文書を開く用途)。
|
|
142
142
|
* バインドされた値を新しい文書の Markdown で更新し、`onChange` を発火する。
|
|
143
143
|
*/
|
|
144
|
-
resetDocument(markdown: string): Result<void,
|
|
144
|
+
resetDocument(markdown: string): Result<void, MarkdownWriteError>;
|
|
145
|
+
/**
|
|
146
|
+
* 本文を置き換える。利用者の操作として**取り消せる**。
|
|
147
|
+
* OPML の取り込みのように、利用者が起こした置き換えに使う。
|
|
148
|
+
*/
|
|
149
|
+
replaceMarkdown(markdown: string): Result<ApplyOutcome, MarkdownWriteError>;
|
|
150
|
+
/**
|
|
151
|
+
* 他の書き手の変更を反映する。**取り消し履歴に積まず**、変わった箇所だけを当てる。
|
|
152
|
+
* 変わっていない箇所のカーソル・取り消しの手順・折りたたみは動かない。
|
|
153
|
+
*/
|
|
154
|
+
applyRemoteChange(markdown: string): Result<ApplyOutcome, MarkdownWriteError>;
|
|
145
155
|
/**
|
|
146
156
|
* フロントマターへ項目を書き込む。キーと JSON の値を渡し、記法はモジュールが持つ。
|
|
147
157
|
*
|
|
@@ -157,10 +167,20 @@
|
|
|
157
167
|
}
|
|
158
168
|
</script>
|
|
159
169
|
|
|
170
|
+
<!--
|
|
171
|
+
本文を当てる命令を 2 つに分けているのは、**約束が違う**ためである。`replaceMarkdown` は
|
|
172
|
+
取り消せることを、`applyRemoteChange` は履歴に積まないことを約束する。1 つの命令に種類を
|
|
173
|
+
渡す形だと、どちらの約束が効くかが引数の値に隠れ、型と doc で書き分けられない。
|
|
174
|
+
|
|
175
|
+
どちらも、かな漢字変換で確定した文字が入りきるまでは当てず `'deferred'` を返す。
|
|
176
|
+
**変換の状態を問い合わせる口は置かない。** 置くと、利用側が自分で分岐を書くことになり、
|
|
177
|
+
「確定した文字が入りきるまで当てない」判断が 2 か所に生まれる。見送りの戻り値で足りる。
|
|
178
|
+
-->
|
|
179
|
+
|
|
160
180
|
<script lang="ts">
|
|
161
181
|
import { untrack } from 'svelte';
|
|
162
|
-
import { resolveMessages } from '../messages';
|
|
163
|
-
import { EMPTY_VIEW_STATE, isSameViewState } from '../models/viewState/viewStateCodec';
|
|
182
|
+
import { resolveMessages } from '../messages/index.js';
|
|
183
|
+
import { EMPTY_VIEW_STATE, isSameViewState } from '../models/viewState/viewStateCodec.js';
|
|
164
184
|
import { createContextMenuController } from '../states/contextMenuController.svelte';
|
|
165
185
|
import { createOutlineViewController } from '../states/outlineViewController.svelte';
|
|
166
186
|
import type { EditorSession } from '../states/editorSession.types';
|
|
@@ -193,6 +213,14 @@
|
|
|
193
213
|
|
|
194
214
|
let session: EditorSession | null = $state(null);
|
|
195
215
|
|
|
216
|
+
/**
|
|
217
|
+
* 見送った `value` の適用が残っているか。
|
|
218
|
+
*
|
|
219
|
+
* **本文は控えない。** 当て直すときはその時点の `value` と現在の本文を突き合わせる。
|
|
220
|
+
* 控えると、書き込みと読み出しが別の経路に分かれて食い違う。
|
|
221
|
+
*/
|
|
222
|
+
let valueDeferred = false;
|
|
223
|
+
|
|
196
224
|
// --- 導出 ---
|
|
197
225
|
|
|
198
226
|
const text = $derived(resolveMessages(lang, messages));
|
|
@@ -283,6 +311,11 @@
|
|
|
283
311
|
publishViewState();
|
|
284
312
|
|
|
285
313
|
if (!docChanged) return;
|
|
314
|
+
// 見送っていた `value` を当て直す。**この購読をそのまま引き金にする**——
|
|
315
|
+
// 確定した文字が文書へ入るときには Transaction が立ち、購読は内容が変わったかの
|
|
316
|
+
// 判定より前に呼ばれる。当たればその適用の通知が束縛された値を更新する
|
|
317
|
+
if (valueDeferred && applyValue(value)) return;
|
|
318
|
+
|
|
286
319
|
value = markdown;
|
|
287
320
|
onChange?.(markdown);
|
|
288
321
|
});
|
|
@@ -312,25 +345,36 @@
|
|
|
312
345
|
onViewStateChange?.(current);
|
|
313
346
|
}
|
|
314
347
|
|
|
348
|
+
/**
|
|
349
|
+
* 渡された本文を当てる。当てたなら真を返す。
|
|
350
|
+
*
|
|
351
|
+
* 変換の確定した文字が入りきるまでは当たらない。そのときは見送りを控えておき、
|
|
352
|
+
* 次に文書が変わったときに**その時点の `value`** で当て直す。
|
|
353
|
+
*/
|
|
354
|
+
function applyValue(next: string): boolean {
|
|
355
|
+
if (!session || next === session.getMarkdown()) {
|
|
356
|
+
valueDeferred = false;
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const result = session.applyMarkdown(next, 'replacement');
|
|
361
|
+
valueDeferred = result.ok && result.value.status === 'deferred';
|
|
362
|
+
return result.ok && result.value.status === 'applied';
|
|
363
|
+
}
|
|
364
|
+
|
|
315
365
|
// --- 外からの変更に追随する ---
|
|
316
366
|
|
|
317
367
|
/**
|
|
318
|
-
*
|
|
368
|
+
* 本文を変わった箇所ごとの置き換えとして当てる。取り消せる置き換えとして扱う。
|
|
319
369
|
*
|
|
320
370
|
* 「自身が直近に書き込んだ値」はセッションが持っている内容そのものなので、それと突き合わせる。
|
|
321
371
|
* 別の変数に控えておく作りにすると、書き込みと読み出しが別の経路(購読の中と効果の中)に
|
|
322
372
|
* 分かれるぶん食い違いが起きやすく、外部変更として扱い直す往復が止まらなくなる。
|
|
323
|
-
*
|
|
324
|
-
* 差分適用は変更範囲のノードを作り直すため、そのままでは間にあるセクションの
|
|
325
|
-
* 折りたたみまで失われる。控えて当て直す(`preserveFolds`)。
|
|
326
373
|
*/
|
|
327
374
|
$effect(() => {
|
|
328
375
|
const next = value;
|
|
329
376
|
if (!session) return;
|
|
330
|
-
untrack(() =>
|
|
331
|
-
if (!session || next === session.getMarkdown()) return;
|
|
332
|
-
controller.preserveFolds(() => session!.applyMarkdown(next));
|
|
333
|
-
});
|
|
377
|
+
untrack(() => applyValue(next));
|
|
334
378
|
});
|
|
335
379
|
|
|
336
380
|
/**
|
|
@@ -358,13 +402,21 @@
|
|
|
358
402
|
return controller.getViewState();
|
|
359
403
|
}
|
|
360
404
|
|
|
361
|
-
export function resetDocument(markdown: string): Result<void,
|
|
362
|
-
if (!session) {
|
|
363
|
-
return { ok: false, error: { kind: 'invalid-structure', detail: 'まだ準備できていない' } };
|
|
364
|
-
}
|
|
405
|
+
export function resetDocument(markdown: string): Result<void, MarkdownWriteError> {
|
|
406
|
+
if (!session) return { ok: false, error: { kind: 'not-ready' } };
|
|
365
407
|
return session.resetDocument(markdown);
|
|
366
408
|
}
|
|
367
409
|
|
|
410
|
+
export function replaceMarkdown(markdown: string): Result<ApplyOutcome, MarkdownWriteError> {
|
|
411
|
+
if (!session) return { ok: false, error: { kind: 'not-ready' } };
|
|
412
|
+
return session.applyMarkdown(markdown, 'replacement');
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
export function applyRemoteChange(markdown: string): Result<ApplyOutcome, MarkdownWriteError> {
|
|
416
|
+
if (!session) return { ok: false, error: { kind: 'not-ready' } };
|
|
417
|
+
return session.applyMarkdown(markdown, 'remote');
|
|
418
|
+
}
|
|
419
|
+
|
|
368
420
|
export function writeFrontMatterFields(
|
|
369
421
|
fields: FrontMatterFields
|
|
370
422
|
): Result<FrontMatterWriteOutcome, FrontMatterWriteError> {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { EditorLang, EditorMessagesOverride } from '../messages/messages.types';
|
|
2
2
|
import type { ImageUpload } from '../operations/plugins/imagePaste';
|
|
3
|
-
import type { FrontMatterFields, FrontMatterWriteError, FrontMatterWriteOutcome
|
|
3
|
+
import type { FrontMatterFields, FrontMatterWriteError, FrontMatterWriteOutcome } from '../models/markdown/markdown.types';
|
|
4
4
|
import type { Result } from '../utils/result.types';
|
|
5
5
|
import type { ViewState } from '../models/viewState/viewState.types';
|
|
6
|
+
import type { ApplyOutcome, MarkdownWriteError } from '../states/editorSession.types';
|
|
6
7
|
export interface MarkdownEditorProps {
|
|
7
8
|
/**
|
|
8
9
|
* 本文の Markdown。`bind:value` で双方向に扱う。
|
|
@@ -111,7 +112,17 @@ export interface MarkdownEditorApi {
|
|
|
111
112
|
* 文書全体を入れ替え、取り消し履歴を初期化する(別の文書を開く用途)。
|
|
112
113
|
* バインドされた値を新しい文書の Markdown で更新し、`onChange` を発火する。
|
|
113
114
|
*/
|
|
114
|
-
resetDocument(markdown: string): Result<void,
|
|
115
|
+
resetDocument(markdown: string): Result<void, MarkdownWriteError>;
|
|
116
|
+
/**
|
|
117
|
+
* 本文を置き換える。利用者の操作として**取り消せる**。
|
|
118
|
+
* OPML の取り込みのように、利用者が起こした置き換えに使う。
|
|
119
|
+
*/
|
|
120
|
+
replaceMarkdown(markdown: string): Result<ApplyOutcome, MarkdownWriteError>;
|
|
121
|
+
/**
|
|
122
|
+
* 他の書き手の変更を反映する。**取り消し履歴に積まず**、変わった箇所だけを当てる。
|
|
123
|
+
* 変わっていない箇所のカーソル・取り消しの手順・折りたたみは動かない。
|
|
124
|
+
*/
|
|
125
|
+
applyRemoteChange(markdown: string): Result<ApplyOutcome, MarkdownWriteError>;
|
|
115
126
|
/**
|
|
116
127
|
* フロントマターへ項目を書き込む。キーと JSON の値を渡し、記法はモジュールが持つ。
|
|
117
128
|
*
|
|
@@ -126,7 +137,9 @@ export interface MarkdownEditorApi {
|
|
|
126
137
|
declare const MarkdownEditor: import("svelte").Component<MarkdownEditorProps, {
|
|
127
138
|
getMarkdown: () => string;
|
|
128
139
|
getViewState: () => ViewState;
|
|
129
|
-
resetDocument: (markdown: string) => Result<void,
|
|
140
|
+
resetDocument: (markdown: string) => Result<void, MarkdownWriteError>;
|
|
141
|
+
replaceMarkdown: (markdown: string) => Result<ApplyOutcome, MarkdownWriteError>;
|
|
142
|
+
applyRemoteChange: (markdown: string) => Result<ApplyOutcome, MarkdownWriteError>;
|
|
130
143
|
writeFrontMatterFields: (fields: FrontMatterFields) => Result<FrontMatterWriteOutcome, FrontMatterWriteError>;
|
|
131
144
|
focus: () => void;
|
|
132
145
|
}, "value" | "viewState">;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { EditorMessages } from '../messages/messages.types';
|
|
3
|
-
import { editorKeymap } from '../operations/keymap/assemble';
|
|
4
|
-
import { SHORTCUT_CATEGORY_ORDER } from '../operations/keymap/menuItems';
|
|
5
|
-
import { formatAllShortcutKeys } from '../operations/keymap/shortcutKeys';
|
|
3
|
+
import { editorKeymap } from '../operations/keymap/assemble.js';
|
|
4
|
+
import { SHORTCUT_CATEGORY_ORDER } from '../operations/keymap/menuItems.js';
|
|
5
|
+
import { formatAllShortcutKeys } from '../operations/keymap/shortcutKeys.js';
|
|
6
6
|
import type { EditorAction } from '../operations/operations.types';
|
|
7
7
|
import Dialog from './internal/Dialog.svelte';
|
|
8
8
|
|
|
@@ -113,9 +113,9 @@
|
|
|
113
113
|
background-color: var(--markdown-editor-dialog-background);
|
|
114
114
|
color: var(--markdown-editor-dialog-text);
|
|
115
115
|
box-shadow:
|
|
116
|
-
0 11px 15px -7px
|
|
117
|
-
0 24px 38px 3px
|
|
118
|
-
0 9px 46px 8px
|
|
116
|
+
0 11px 15px -7px var(--markdown-editor-dialog-shadow-strong),
|
|
117
|
+
0 24px 38px 3px var(--markdown-editor-dialog-shadow),
|
|
118
|
+
0 9px 46px 8px var(--markdown-editor-dialog-shadow-weak);
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
.modal::backdrop {
|
|
@@ -195,9 +195,9 @@
|
|
|
195
195
|
color: var(--markdown-editor-popup-text);
|
|
196
196
|
font-family: var(--markdown-editor-font);
|
|
197
197
|
box-shadow:
|
|
198
|
-
0 11px 15px -7px
|
|
199
|
-
0 24px 38px 3px
|
|
200
|
-
0 9px 46px 8px
|
|
198
|
+
0 11px 15px -7px var(--markdown-editor-popup-shadow-strong),
|
|
199
|
+
0 24px 38px 3px var(--markdown-editor-popup-shadow),
|
|
200
|
+
0 9px 46px 8px var(--markdown-editor-popup-shadow-weak);
|
|
201
201
|
overflow: hidden;
|
|
202
202
|
/*
|
|
203
203
|
* 巻き取りを中で止める。端まで来た続きが背後のページへ流れると、
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export { default as MarkdownEditor } from './components/MarkdownEditor.svelte';
|
|
8
8
|
export type { MarkdownEditorProps, MarkdownEditorApi } from './components/MarkdownEditor.svelte';
|
|
9
|
-
export { en, ja } from './messages';
|
|
9
|
+
export { en, ja } from './messages/index.js';
|
|
10
10
|
export type { EditorMessages, EditorMessagesOverride, EditorLang, EditorShortcutCategory } from './messages/messages.types';
|
|
11
11
|
/**
|
|
12
12
|
* 貼り付けられた画像の引き受け先の型(`MarkdownEditor` の `uploadImage` に渡す)。
|
|
@@ -14,9 +14,18 @@ export type { EditorMessages, EditorMessagesOverride, EditorLang, EditorShortcut
|
|
|
14
14
|
*/
|
|
15
15
|
export type { ImageUpload } from './operations/plugins/imagePaste';
|
|
16
16
|
export type { ViewState, ViewSectionRef } from './models/viewState/viewState.types';
|
|
17
|
+
/**
|
|
18
|
+
* 外から本文を当てる命令(`replaceMarkdown` / `applyRemoteChange`)の戻り値に現れる型。
|
|
19
|
+
*
|
|
20
|
+
* 適用の種類を表す型は公開しない。公開面では**名前が約束を運ぶ**ため、
|
|
21
|
+
* 利用側が種類の値を扱う場所が無い。
|
|
22
|
+
*/
|
|
23
|
+
export type { ApplyOutcome, ApplyStatus, MarkdownWriteError } from './states/editorSession.types';
|
|
17
24
|
/**
|
|
18
25
|
* マークダウン文字列を、エディタを置かずに読み書きするための純関数。
|
|
19
26
|
*
|
|
27
|
+
* - `normalizeMarkdown`: 書き方を正準形へ揃える。**エディタを通した本文と文字列として
|
|
28
|
+
* 一致する**ため、別の経路で書かれた本文と突き合わせる前に通す
|
|
20
29
|
* - `readFrontMatterField`: 指定した項目の値。一覧のような場所でタイトルを出すために使う
|
|
21
30
|
* - `readFrontMatterFields`: フロントマターの全項目。何が書かれているかをキーを知らずに読む
|
|
22
31
|
* - `readBody`: フロントマターを除いた本文
|
|
@@ -32,6 +41,5 @@ export type { ViewState, ViewSectionRef } from './models/viewState/viewState.typ
|
|
|
32
41
|
* 項目の値は文字列のまま返し、**型として解釈しない**。これが、利用者がモジュールを
|
|
33
42
|
* YAML の解析器として扱い始めるのを避けるための境界である。
|
|
34
43
|
*/
|
|
35
|
-
export { readBody, readBodyBlocks, readFrontMatterField, readFrontMatterFields, readPlainText, writeFrontMatterFields } from './markdown';
|
|
36
|
-
export type { FrontMatterFields, FrontMatterValues, FrontMatterWriteError, FrontMatterWriteOutcome, JsonValue, MarkdownBlock, MarkdownBlockKind, Result } from './markdown';
|
|
37
|
-
export type { MarkdownParseError } from './models/markdown/markdown.types';
|
|
44
|
+
export { normalizeMarkdown, readBody, readBodyBlocks, readFrontMatterField, readFrontMatterFields, readPlainText, writeFrontMatterFields } from './markdown.js';
|
|
45
|
+
export type { FrontMatterFields, FrontMatterValues, FrontMatterWriteError, FrontMatterWriteOutcome, JsonValue, MarkdownBlock, MarkdownBlockKind, MarkdownParseError, Result } from './markdown';
|
package/dist/index.js
CHANGED
|
@@ -6,10 +6,12 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export { default as MarkdownEditor } from './components/MarkdownEditor.svelte';
|
|
8
8
|
// 表示文言(同梱の辞書と型)。独自の言語を作るときは既定を土台にできる
|
|
9
|
-
export { en, ja } from './messages';
|
|
9
|
+
export { en, ja } from './messages/index.js';
|
|
10
10
|
/**
|
|
11
11
|
* マークダウン文字列を、エディタを置かずに読み書きするための純関数。
|
|
12
12
|
*
|
|
13
|
+
* - `normalizeMarkdown`: 書き方を正準形へ揃える。**エディタを通した本文と文字列として
|
|
14
|
+
* 一致する**ため、別の経路で書かれた本文と突き合わせる前に通す
|
|
13
15
|
* - `readFrontMatterField`: 指定した項目の値。一覧のような場所でタイトルを出すために使う
|
|
14
16
|
* - `readFrontMatterFields`: フロントマターの全項目。何が書かれているかをキーを知らずに読む
|
|
15
17
|
* - `readBody`: フロントマターを除いた本文
|
|
@@ -25,4 +27,4 @@ export { en, ja } from './messages';
|
|
|
25
27
|
* 項目の値は文字列のまま返し、**型として解釈しない**。これが、利用者がモジュールを
|
|
26
28
|
* YAML の解析器として扱い始めるのを避けるための境界である。
|
|
27
29
|
*/
|
|
28
|
-
export { readBody, readBodyBlocks, readFrontMatterField, readFrontMatterFields, readPlainText, writeFrontMatterFields } from './markdown';
|
|
30
|
+
export { normalizeMarkdown, readBody, readBodyBlocks, readFrontMatterField, readFrontMatterFields, readPlainText, writeFrontMatterFields } from './markdown.js';
|
package/dist/markdown.d.ts
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export { readBody, readFrontMatterField, readFrontMatterFields, writeFrontMatterFields } from './models/markdown/frontMatter.js';
|
|
9
9
|
export { readBodyBlocks } from './models/markdown/blockOutline.js';
|
|
10
|
+
export { normalizeMarkdown } from './models/markdown/normalize.js';
|
|
10
11
|
export { readPlainText } from './models/markdown/plainText.js';
|
|
12
|
+
export type { MarkdownParseError } from './models/markdown/markdown.types';
|
|
11
13
|
export type { FrontMatterFields, FrontMatterValues, FrontMatterWriteError, FrontMatterWriteOutcome, MarkdownBlock, MarkdownBlockKind } from './models/markdown/markdown.types';
|
|
12
14
|
export type { JsonValue } from './utils/json.types';
|
|
13
15
|
export type { Result } from './utils/result.types';
|
package/dist/markdown.js
CHANGED
|
@@ -7,4 +7,5 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export { readBody, readFrontMatterField, readFrontMatterFields, writeFrontMatterFields } from './models/markdown/frontMatter.js';
|
|
9
9
|
export { readBodyBlocks } from './models/markdown/blockOutline.js';
|
|
10
|
+
export { normalizeMarkdown } from './models/markdown/normalize.js';
|
|
10
11
|
export { readPlainText } from './models/markdown/plainText.js';
|
package/dist/messages/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { en } from './en';
|
|
2
|
-
import { ja } from './ja';
|
|
1
|
+
import { en } from './en.js';
|
|
2
|
+
import { ja } from './ja.js';
|
|
3
3
|
import type { EditorLang, EditorMessages, EditorMessagesOverride } from './messages.types';
|
|
4
4
|
export { en, ja };
|
|
5
5
|
export type { EditorLang, EditorMessages, EditorMessagesOverride, EditorShortcutCategory } from './messages.types';
|
package/dist/messages/index.js
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
|
-
import { Schema } from 'prosemirror-model';
|
|
1
|
+
import { Schema, type NodeType } from 'prosemirror-model';
|
|
2
2
|
export declare const outlineSchema: Schema<string, string>;
|
|
3
|
+
/**
|
|
4
|
+
* 項目の行になれるブロックか。**1 行で書けるものだけが、項目の記号と同じ行に並べられる。**
|
|
5
|
+
*
|
|
6
|
+
* コードブロックは文字を持つが、1 行目は開きの記号であり同じ行には並べられない。表・引用・
|
|
7
|
+
* 水平線も同じである。スキーマはこれらを項目の先頭に置ける(`block+`)ので、**置かないのは
|
|
8
|
+
* 操作の側の責任**である。置くと、書き出して読み直すだけで空の項目行が 1 つ増える
|
|
9
|
+
* (→ `parser.ts` の `withOwnLine`)。
|
|
10
|
+
*/
|
|
11
|
+
export declare function canBeItemLine(type: NodeType): boolean;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Schema } from 'prosemirror-model';
|
|
2
2
|
import { createListSpec, defaultAttributesGetter, listToDOM } from 'prosemirror-flat-list';
|
|
3
3
|
import { tableNodes } from 'prosemirror-tables';
|
|
4
|
-
import { foldStateAttrs } from './foldable';
|
|
5
|
-
import { MAX_HEADING_LEVEL, MIN_HEADING_LEVEL } from './document.types';
|
|
4
|
+
import { foldStateAttrs } from './foldable.js';
|
|
5
|
+
import { MAX_HEADING_LEVEL, MIN_HEADING_LEVEL } from './document.types.js';
|
|
6
6
|
/**
|
|
7
7
|
* `requiredSelectionBlock` は**要選択ブロックのフラグ**である。中にカーソルを置いても
|
|
8
8
|
* 階層操作や `Tab` が中身に対して働いてしまい、ブロック自身を指せないものに付ける
|
|
@@ -506,3 +506,14 @@ export const outlineSchema = new Schema({
|
|
|
506
506
|
nodes: { ...structureNodes, ...blockNodes, ...tableSpec },
|
|
507
507
|
marks
|
|
508
508
|
});
|
|
509
|
+
/**
|
|
510
|
+
* 項目の行になれるブロックか。**1 行で書けるものだけが、項目の記号と同じ行に並べられる。**
|
|
511
|
+
*
|
|
512
|
+
* コードブロックは文字を持つが、1 行目は開きの記号であり同じ行には並べられない。表・引用・
|
|
513
|
+
* 水平線も同じである。スキーマはこれらを項目の先頭に置ける(`block+`)ので、**置かないのは
|
|
514
|
+
* 操作の側の責任**である。置くと、書き出して読み直すだけで空の項目行が 1 つ増える
|
|
515
|
+
* (→ `parser.ts` の `withOwnLine`)。
|
|
516
|
+
*/
|
|
517
|
+
export function canBeItemLine(type) {
|
|
518
|
+
return type === outlineSchema.nodes.paragraph || type === outlineSchema.nodes.nested_heading;
|
|
519
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Node } from 'prosemirror-model';
|
|
2
2
|
import type { EditorState, Transaction } from 'prosemirror-state';
|
|
3
|
-
import { type SectionPath, type SectionRef } from './document.types';
|
|
3
|
+
import { type SectionPath, type SectionRef } from './document.types.js';
|
|
4
4
|
/**
|
|
5
5
|
* 見出しの**読める 1 行の文字**。パンくず・折りたたみの見出し・表示状態の突合キーは
|
|
6
6
|
* すべてこれを使う。
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MAX_HEADING_LEVEL, MIN_HEADING_LEVEL } from './document.types';
|
|
2
|
-
import { outlineSchema } from './schema';
|
|
1
|
+
import { MAX_HEADING_LEVEL, MIN_HEADING_LEVEL } from './document.types.js';
|
|
2
|
+
import { outlineSchema } from './schema.js';
|
|
3
3
|
const SECTION = outlineSchema.nodes.section;
|
|
4
4
|
const INTRO_SECTION = outlineSchema.nodes.intro_section;
|
|
5
5
|
const IMAGE = outlineSchema.nodes.image;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { MarkdownParseError } from './markdown.types';
|
|
2
|
+
import type { Result } from '../../utils/result.types';
|
|
3
|
+
/**
|
|
4
|
+
* 書き方を正準形へ揃える。**意味は変えない。**
|
|
5
|
+
*
|
|
6
|
+
* 落ちるのは書き方の違いだけである(`*` と `-`、下線と `#`、表の区切りの間隔、
|
|
7
|
+
* 番号の振り方、余分な空行、行の区切り、末尾の改行)。何が書かれているかは変わらない。
|
|
8
|
+
*
|
|
9
|
+
* **約束は、エディタを通した本文と文字列として一致することである。** 読み込み直後の
|
|
10
|
+
* `getMarkdown()`、`resetDocument` の後、`replaceMarkdown` / `applyRemoteChange` の
|
|
11
|
+
* 戻り値——どの経路を通っても同じ文字列になる。1 つでも外れると、その道を通った本文
|
|
12
|
+
* だけが差として現れる(→ `normalizeInvariance.svelte.spec.ts`)。
|
|
13
|
+
*
|
|
14
|
+
* 2 回通しても変わらない。
|
|
15
|
+
*
|
|
16
|
+
* **新しい規則を持たない。** 正準形を決めているのは読み込みと書き出しであり、ここは
|
|
17
|
+
* その往復を 1 本の関数として公開面へ出すだけである。規則をここに持つと、エディタを
|
|
18
|
+
* 通した本文との一致が 2 つの規則のあいだの約束になり、どちらかが動いたときに破れる。
|
|
19
|
+
*/
|
|
20
|
+
export declare function normalizeMarkdown(markdown: string): Result<string, MarkdownParseError>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { parseMarkdown } from './parser.js';
|
|
2
|
+
import { serializeMarkdown } from './serializer.js';
|
|
3
|
+
/**
|
|
4
|
+
* 書き方を正準形へ揃える。**意味は変えない。**
|
|
5
|
+
*
|
|
6
|
+
* 落ちるのは書き方の違いだけである(`*` と `-`、下線と `#`、表の区切りの間隔、
|
|
7
|
+
* 番号の振り方、余分な空行、行の区切り、末尾の改行)。何が書かれているかは変わらない。
|
|
8
|
+
*
|
|
9
|
+
* **約束は、エディタを通した本文と文字列として一致することである。** 読み込み直後の
|
|
10
|
+
* `getMarkdown()`、`resetDocument` の後、`replaceMarkdown` / `applyRemoteChange` の
|
|
11
|
+
* 戻り値——どの経路を通っても同じ文字列になる。1 つでも外れると、その道を通った本文
|
|
12
|
+
* だけが差として現れる(→ `normalizeInvariance.svelte.spec.ts`)。
|
|
13
|
+
*
|
|
14
|
+
* 2 回通しても変わらない。
|
|
15
|
+
*
|
|
16
|
+
* **新しい規則を持たない。** 正準形を決めているのは読み込みと書き出しであり、ここは
|
|
17
|
+
* その往復を 1 本の関数として公開面へ出すだけである。規則をここに持つと、エディタを
|
|
18
|
+
* 通した本文との一致が 2 つの規則のあいだの約束になり、どちらかが動いたときに破れる。
|
|
19
|
+
*/
|
|
20
|
+
export function normalizeMarkdown(markdown) {
|
|
21
|
+
const parsed = parseMarkdown(markdown);
|
|
22
|
+
if (!parsed.ok)
|
|
23
|
+
return parsed;
|
|
24
|
+
return { ok: true, value: serializeMarkdown(parsed.value) };
|
|
25
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fragment, Mark } from 'prosemirror-model';
|
|
2
|
-
import { MAX_HEADING_LEVEL } from '../document/document.types';
|
|
3
|
-
import { outlineSchema } from '../document/schema';
|
|
2
|
+
import { MAX_HEADING_LEVEL } from '../document/document.types.js';
|
|
3
|
+
import { canBeItemLine, outlineSchema } from '../document/schema.js';
|
|
4
4
|
import { splitFrontMatter } from './frontMatter.js';
|
|
5
5
|
import { markdownIt } from './markdownIt.js';
|
|
6
6
|
const n = outlineSchema.nodes;
|
|
@@ -128,7 +128,11 @@ function readBlock(tokens, start) {
|
|
|
128
128
|
case 'fence':
|
|
129
129
|
case 'code_block': {
|
|
130
130
|
const language = token.info.trim().split(/\s+/)[0] ?? '';
|
|
131
|
-
|
|
131
|
+
// **閉じの記号の前の改行は記法である。** 中身は 2 つの記号に挟まれた行であり、
|
|
132
|
+
// 取り込むと書かれていない空行を 1 つ持つ(消しても書き出しは変わらないため、
|
|
133
|
+
// 開き直すたびに戻る)。空行を書いた形(`\n\n`)は 1 つだけ落として保つ
|
|
134
|
+
const text = token.content.replace(/\n$/, '');
|
|
135
|
+
const content = text ? outlineSchema.text(text) : null;
|
|
132
136
|
// 書き出しは常に `mermaid` を出すため、表記ゆれ(`Mermaid` 等)を取り込むと
|
|
133
137
|
// 往復でフェンスの文字が変わる。小文字完全一致だけを専用ブロックにする
|
|
134
138
|
return {
|
|
@@ -273,9 +277,7 @@ function keepTaskMarker(blocks) {
|
|
|
273
277
|
function withOwnLine(blocks) {
|
|
274
278
|
if (blocks.length === 0)
|
|
275
279
|
return [n.paragraph.createChecked(null)];
|
|
276
|
-
|
|
277
|
-
// 1 行目は開きの記号であり、項目の記号と同じ行には並べられない
|
|
278
|
-
if (blocks[0].type === n.paragraph || blocks[0].type === n.nested_heading)
|
|
280
|
+
if (canBeItemLine(blocks[0].type))
|
|
279
281
|
return blocks;
|
|
280
282
|
return [n.paragraph.createChecked(null), ...blocks];
|
|
281
283
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MarkdownSerializer } from 'prosemirror-markdown';
|
|
2
2
|
import { Fragment } from 'prosemirror-model';
|
|
3
|
-
import { MAX_HEADING_LEVEL } from '../document/document.types';
|
|
4
|
-
import { outlineSchema } from '../document/schema';
|
|
3
|
+
import { MAX_HEADING_LEVEL } from '../document/document.types.js';
|
|
4
|
+
import { outlineSchema } from '../document/schema.js';
|
|
5
5
|
const n = outlineSchema.nodes;
|
|
6
6
|
/**
|
|
7
7
|
* 文書を Markdown へ書き出す。
|
|
@@ -219,23 +219,24 @@ const serializeMermaidBlock = (state, node) => {
|
|
|
219
219
|
writeFencedBlock(state, node, 'mermaid');
|
|
220
220
|
};
|
|
221
221
|
/**
|
|
222
|
-
*
|
|
222
|
+
* 中身の行を 2 つの記号で挟む。
|
|
223
223
|
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
224
|
+
* **閉じの記号の前の改行は記法であり、中身ではない**(→ `parser.ts` の `fence`)。
|
|
225
|
+
* だから中身を書き終えたら改行を 1 つ必ず置く。`ensureNewLine` では足りない——
|
|
226
|
+
* 中身の最後が空行のとき、その行を書き終えた時点ですでに行頭に立っており、
|
|
227
|
+
* **空行と記法の改行が 1 つに潰れて空行が消える**。
|
|
227
228
|
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
229
|
+
* 中身が空のときは行を 1 つも書かない。書くと、空のコードブロックが空行を 1 つ
|
|
230
|
+
* 抱えた形で書き出される。
|
|
230
231
|
*/
|
|
231
232
|
function writeFencedBlock(state, node, language) {
|
|
232
233
|
const content = node.textContent;
|
|
233
234
|
const fence = longestFence(content);
|
|
234
235
|
state.write(`${fence}${language}\n`);
|
|
235
|
-
if (content)
|
|
236
|
+
if (content) {
|
|
236
237
|
state.text(content, false);
|
|
237
|
-
|
|
238
|
-
|
|
238
|
+
state.write('\n');
|
|
239
|
+
}
|
|
239
240
|
state.write(fence);
|
|
240
241
|
state.closeBlock(node);
|
|
241
242
|
}
|
|
@@ -2,7 +2,7 @@ import type { Node } from 'prosemirror-model';
|
|
|
2
2
|
import type { EditorState } from 'prosemirror-state';
|
|
3
3
|
import type { Result } from '../../utils/result.types';
|
|
4
4
|
import type { SectionPath } from '../document/document.types';
|
|
5
|
-
import { type ResolvedViewState, type ViewState, type ViewStateError } from './viewState.types';
|
|
5
|
+
import { type ResolvedViewState, type ViewState, type ViewStateError } from './viewState.types.js';
|
|
6
6
|
/** 形式の版。将来の変更で増やし、古い側は「未対応」として安全に無視できるようにする */
|
|
7
7
|
export declare const VIEW_STATE_VERSION = 1;
|
|
8
8
|
/** 何も畳んでおらず、フォーカスもしていない状態 */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { outlineSchema } from '../document/schema';
|
|
2
|
-
import { headingText, sectionTree } from '../document/sectionTree';
|
|
3
|
-
import { isViewState } from './viewState.types';
|
|
1
|
+
import { outlineSchema } from '../document/schema.js';
|
|
2
|
+
import { headingText, sectionTree } from '../document/sectionTree.js';
|
|
3
|
+
import { isViewState } from './viewState.types.js';
|
|
4
4
|
const SECTION = outlineSchema.nodes.section;
|
|
5
5
|
/** 形式の版。将来の変更で増やし、古い側は「未対応」として安全に無視できるようにする */
|
|
6
6
|
export const VIEW_STATE_VERSION = 1;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { wrapIn } from 'prosemirror-commands';
|
|
2
2
|
import { InputRule } from 'prosemirror-inputrules';
|
|
3
3
|
import { wrappingListInputRule } from 'prosemirror-flat-list';
|
|
4
|
-
import { outlineSchema } from '../models/document/schema';
|
|
5
|
-
import { changeLine, convertFromMarkup, setBlockKind } from './commands/block';
|
|
6
|
-
import { toFencedBlock } from './commands/fencedBlock';
|
|
4
|
+
import { outlineSchema } from '../models/document/schema.js';
|
|
5
|
+
import { changeLine, convertFromMarkup, setBlockKind } from './commands/block.js';
|
|
6
|
+
import { toFencedBlock } from './commands/fencedBlock.js';
|
|
7
7
|
/**
|
|
8
8
|
* 記法を打つと書式になる(オートフォーマット)。
|
|
9
9
|
*
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { chainCommands, lift, setBlockType, wrapIn } from 'prosemirror-commands';
|
|
2
2
|
import { EditorState, TextSelection } from 'prosemirror-state';
|
|
3
|
-
import { outlineSchema } from '../../models/document/schema';
|
|
4
|
-
import { setCursor } from '../transaction';
|
|
5
|
-
import { blockInsideItem, blockToListItem, itemToParagraph, listCommands } from './list';
|
|
6
|
-
import { blockContentEnd, convertToHeadings, dissolveLevel, previousSiblingSection, sectionToListItem, targetSection } from './section';
|
|
3
|
+
import { outlineSchema } from '../../models/document/schema.js';
|
|
4
|
+
import { setCursor } from '../transaction.js';
|
|
5
|
+
import { blockInsideItem, blockToListItem, itemToParagraph, listCommands } from './list.js';
|
|
6
|
+
import { blockContentEnd, convertToHeadings, dissolveLevel, previousSiblingSection, sectionToListItem, targetSection } from './section.js';
|
|
7
7
|
const n = outlineSchema.nodes;
|
|
8
8
|
/**
|
|
9
9
|
* ブロックの種別を変える。
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { chainCommands } from 'prosemirror-commands';
|
|
2
2
|
import { TextSelection } from 'prosemirror-state';
|
|
3
3
|
import { CellSelection, isInTable } from 'prosemirror-tables';
|
|
4
|
-
import { outlineSchema } from '../../models/document/schema';
|
|
5
|
-
import { selectBlockAt, setCursor } from '../transaction';
|
|
6
|
-
import { isTabEscaped } from '../plugins/tabEscape';
|
|
7
|
-
import { setBlockKind, toggleHeading } from './block';
|
|
8
|
-
import { indentInCodeBlock, outdentInCodeBlock } from './codeBlock';
|
|
9
|
-
import { blockInsideItem, listCommands, moveItemAcrossSection, paragraphToListItem } from './list';
|
|
10
|
-
import { coveredEnd, liftSection, moveBlockAcrossSection, moveRange, moveSection, neighborSide, restoreMovedSelection, siblingRange, sinkSection, targetSection, topLevelBlock } from './section';
|
|
11
|
-
import { liftSelectedBlock, requiredSelectionBlock, sinkSelectedBlock } from './selectedBlock';
|
|
12
|
-
import { tableCommands } from './table';
|
|
4
|
+
import { outlineSchema } from '../../models/document/schema.js';
|
|
5
|
+
import { selectBlockAt, setCursor } from '../transaction.js';
|
|
6
|
+
import { isTabEscaped } from '../plugins/tabEscape.js';
|
|
7
|
+
import { setBlockKind, toggleHeading } from './block.js';
|
|
8
|
+
import { indentInCodeBlock, outdentInCodeBlock } from './codeBlock.js';
|
|
9
|
+
import { blockInsideItem, listCommands, moveItemAcrossSection, paragraphToListItem } from './list.js';
|
|
10
|
+
import { coveredEnd, liftSection, moveBlockAcrossSection, moveRange, moveSection, neighborSide, restoreMovedSelection, siblingRange, sinkSection, targetSection, topLevelBlock } from './section.js';
|
|
11
|
+
import { liftSelectedBlock, requiredSelectionBlock, sinkSelectedBlock } from './selectedBlock.js';
|
|
12
|
+
import { tableCommands } from './table.js';
|
|
13
13
|
const n = outlineSchema.nodes;
|
|
14
14
|
export const sectionCommands = {
|
|
15
15
|
sinkSection,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { setBlockType } from 'prosemirror-commands';
|
|
2
|
-
import { outlineSchema } from '../../models/document/schema';
|
|
3
|
-
import { changeLine, convertFromMarkup } from './block';
|
|
2
|
+
import { outlineSchema } from '../../models/document/schema.js';
|
|
3
|
+
import { changeLine, convertFromMarkup } from './block.js';
|
|
4
4
|
const n = outlineSchema.nodes;
|
|
5
5
|
/**
|
|
6
6
|
* 行頭からカーソルまでがフェンスの記法だけか。言語名に使える文字は autoformat の
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { TextSelection } from 'prosemirror-state';
|
|
2
|
-
import { bodyStart, frontMatterContentStart } from '../../models/document/bodySelection';
|
|
3
|
-
import { outlineSchema } from '../../models/document/schema';
|
|
4
|
-
import { findFieldRanges, writeFields } from '../../models/markdown/frontMatter';
|
|
5
|
-
import { markOrigin } from '../transactionOrigin';
|
|
6
|
-
import { listCommands } from './list';
|
|
2
|
+
import { bodyStart, frontMatterContentStart } from '../../models/document/bodySelection.js';
|
|
3
|
+
import { outlineSchema } from '../../models/document/schema.js';
|
|
4
|
+
import { findFieldRanges, writeFields } from '../../models/markdown/frontMatter.js';
|
|
5
|
+
import { markOrigin } from '../transactionOrigin.js';
|
|
6
|
+
import { listCommands } from './list.js';
|
|
7
7
|
/**
|
|
8
8
|
* フロントマターの中身を差し替える変更を組み立てる。
|
|
9
9
|
*
|