@14ch/svelte-md-outliner 0.0.18 → 0.0.20
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 +41 -0
- package/README.ja.md +47 -24
- package/README.md +47 -24
- package/dist/assets/styles/editor.css +42 -3
- package/dist/assets/styles/theme.css +2 -3
- package/dist/components/ContextMenu.svelte +1 -1
- package/dist/components/EditorSurface.svelte +2 -2
- 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/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/en.js +1 -1
- package/dist/messages/index.d.ts +2 -2
- package/dist/messages/index.js +2 -2
- package/dist/messages/ja.js +1 -1
- 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.d.ts +1 -1
- package/dist/operations/autoformat.js +21 -33
- package/dist/operations/commands/block.d.ts +19 -1
- package/dist/operations/commands/block.js +44 -4
- package/dist/operations/commands/element.js +9 -9
- package/dist/operations/commands/fencedBlock.d.ts +21 -0
- package/dist/operations/commands/fencedBlock.js +49 -0
- 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 +16 -16
- 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
- package/dist/operations/commands/mermaidBlock.d.ts +0 -9
- package/dist/operations/commands/mermaidBlock.js +0 -28
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/en.js
CHANGED
|
@@ -64,7 +64,7 @@ export const en = {
|
|
|
64
64
|
'document.undo': 'Undo',
|
|
65
65
|
'document.redo': 'Redo',
|
|
66
66
|
'editing.escapeTab': 'Release Tab so it moves focus',
|
|
67
|
-
'editing.
|
|
67
|
+
'editing.fencedBlockOnEnter': 'At the start of a line, turn ``` into a code or diagram block',
|
|
68
68
|
'editing.splitListItem': 'New list item',
|
|
69
69
|
'editing.undoInputRule': 'Undo the last automatic formatting',
|
|
70
70
|
'editing.dissolveHeading': 'At the start of a heading, drop it and join the section above',
|
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
package/dist/messages/ja.js
CHANGED
|
@@ -69,7 +69,7 @@ export const ja = {
|
|
|
69
69
|
'document.undo': '取り消し',
|
|
70
70
|
'document.redo': 'やり直し',
|
|
71
71
|
'editing.escapeTab': 'Tab でフォーカスを移せる状態にする',
|
|
72
|
-
'editing.
|
|
72
|
+
'editing.fencedBlockOnEnter': '行頭の ``` をコードや図のブロックにする',
|
|
73
73
|
'editing.splitListItem': '新しい項目',
|
|
74
74
|
'editing.undoInputRule': '直前の自動変換を取り消す',
|
|
75
75
|
'editing.dissolveHeading': '見出しの先頭で押すと、見出しをやめて前のセクションへ繋げる',
|
|
@@ -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,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { wrapIn } from 'prosemirror-commands';
|
|
2
|
+
import { InputRule } from 'prosemirror-inputrules';
|
|
2
3
|
import { wrappingListInputRule } from 'prosemirror-flat-list';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { outlineSchema } from '../models/document/schema.js';
|
|
5
|
+
import { changeLine, convertFromMarkup, setBlockKind } from './commands/block.js';
|
|
6
|
+
import { toFencedBlock } from './commands/fencedBlock.js';
|
|
6
7
|
/**
|
|
7
8
|
* 記法を打つと書式になる(オートフォーマット)。
|
|
8
9
|
*
|
|
@@ -10,7 +11,7 @@ import { setBlockKind } from './commands/block';
|
|
|
10
11
|
*/
|
|
11
12
|
export const autoformatRules = [
|
|
12
13
|
// 行頭の `#` は個数を問わない。レベルは構造上の深さから決まるため
|
|
13
|
-
new InputRule(/^#{1,6}\s$/, (state, _match, start, end) =>
|
|
14
|
+
new InputRule(/^#{1,6}\s$/, (state, _match, start, end) => convertFromMarkup(state, start, end, setBlockKind('heading'))),
|
|
14
15
|
// 種別はマークダウンで表せるものだけを作る。ライブラリが用意する一式には
|
|
15
16
|
// 折りたたみ用の種別が含まれており、そのままでは書き出せない項目ができてしまう
|
|
16
17
|
wrappingListInputRule(/^\s?[*-]\s$/, { kind: 'bullet' }),
|
|
@@ -22,10 +23,21 @@ export const autoformatRules = [
|
|
|
22
23
|
kind: 'task',
|
|
23
24
|
checked: /[Xx]/.test(match[1])
|
|
24
25
|
})),
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
/**
|
|
27
|
+
* 引用。**項目の行で打たれたら、項目を解いてから包む**(→ `changeLine`)。
|
|
28
|
+
* 項目の中に残すと「中黒の付いた引用」になり、読み直したときに項目の行が 1 つ増える。
|
|
29
|
+
* 引用の中で打てば引用が入れ子になる(包む操作のままである)。
|
|
30
|
+
*/
|
|
31
|
+
new InputRule(/^\s?>\s$/, (state, _match, start, end) => convertFromMarkup(state, start, end, changeLine(wrapIn(outlineSchema.nodes.blockquote)))),
|
|
32
|
+
/**
|
|
33
|
+
* フェンスの記法。**末尾の空白は言語名の打ち終わりの合図である。**
|
|
34
|
+
* 無いと ` ``` ` を打った時点で変換され、言語名を打つ場所が残らない。
|
|
35
|
+
*
|
|
36
|
+
* 行き先(コードブロックか図のブロックか)と、項目の行で打たれたときの扱いは
|
|
37
|
+
* `toFencedBlock` が持つ。入力規則は文字入力でしか発火しないため、**改行での変換は
|
|
38
|
+
* ここでは起きない**(→ キー割り当ての `editing.fencedBlockOnEnter`)。
|
|
39
|
+
*/
|
|
40
|
+
new InputRule(/^```([a-zA-Z0-9_+#-]*)\s$/, (state, match, start, end) => convertFromMarkup(state, start, end, toFencedBlock(match[1] ?? ''))),
|
|
29
41
|
new InputRule(/^(?:---|___|\*\*\*)$/, (state, _match, start, end) => state.tr.replaceWith(start, end, outlineSchema.nodes.horizontal_rule.create())),
|
|
30
42
|
/**
|
|
31
43
|
* 打った画像記法を、閉じ括弧まで打ち終えた時点で画像にする。
|
|
@@ -49,30 +61,6 @@ export const autoformatRules = [
|
|
|
49
61
|
markInputRule(/(~~([^~]+)~~)$/, outlineSchema.marks.strikethrough),
|
|
50
62
|
markInputRule(/(`([^`]+)`)$/, outlineSchema.marks.code)
|
|
51
63
|
];
|
|
52
|
-
/** 記法の文字を消してから見出しへ変換し、1 つの取り消し単位にまとめる */
|
|
53
|
-
function headingFromMarkup(state, start, end) {
|
|
54
|
-
const stripped = state.tr.delete(start, end);
|
|
55
|
-
// プラグインを持たない状態で変換を組み立てる。`state.apply` を使うと、
|
|
56
|
-
// 表や箇条書きの整合を取るプラグインが文書をさらに変えることがあり、
|
|
57
|
-
// その文書に対して作った手順を元の文書へ当てられなくなる
|
|
58
|
-
const base = EditorState.create({
|
|
59
|
-
schema: outlineSchema,
|
|
60
|
-
doc: stripped.doc,
|
|
61
|
-
selection: stripped.selection
|
|
62
|
-
});
|
|
63
|
-
let converted;
|
|
64
|
-
setBlockKind('heading')(base, (tr) => {
|
|
65
|
-
converted = tr;
|
|
66
|
-
});
|
|
67
|
-
if (!converted)
|
|
68
|
-
return null;
|
|
69
|
-
const merged = state.tr.delete(start, end);
|
|
70
|
-
for (const step of converted.steps)
|
|
71
|
-
merged.step(step);
|
|
72
|
-
// 位置は同じだが、選択は今の文書のものへ作り直す必要がある
|
|
73
|
-
merged.setSelection(TextSelection.near(merged.doc.resolve(converted.selection.from)));
|
|
74
|
-
return merged;
|
|
75
|
-
}
|
|
76
64
|
/**
|
|
77
65
|
* 閉じ記号の入力で、その範囲に文字装飾を適用する。
|
|
78
66
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { EditorState, type Transaction } from 'prosemirror-state';
|
|
2
2
|
import type { BlockKind } from '../../models/document/document.types';
|
|
3
3
|
import type { EditorCommand } from '../operations.types';
|
|
4
4
|
/**
|
|
@@ -8,6 +8,24 @@ import type { EditorCommand } from '../operations.types';
|
|
|
8
8
|
* 箇条書きのツリーと見出しのツリーを行き来する手段はここが担う。
|
|
9
9
|
*/
|
|
10
10
|
export declare function setBlockKind(kind: BlockKind): EditorCommand;
|
|
11
|
+
/**
|
|
12
|
+
* 行そのものを別の種別にする変換を、**文脈に合わせて**当てる。
|
|
13
|
+
*
|
|
14
|
+
* - 項目の行では、項目を解いてから変える(→ `outOfList`)
|
|
15
|
+
* - 項目の本文より後ろのブロックでは、そのブロックだけを変える(→ `blockKindInItem`)
|
|
16
|
+
*
|
|
17
|
+
* 種別の一覧(`BlockKind`)に無い行き先——言語を持つコードブロック・Mermaid ブロック——を
|
|
18
|
+
* 打った記法から作るための入口であり、振り分けの規則は `setBlockKind` と同じものである。
|
|
19
|
+
*/
|
|
20
|
+
export declare function changeLine(command: EditorCommand): EditorCommand;
|
|
21
|
+
/**
|
|
22
|
+
* 打った記法の文字を消してから変換を当て、1 つの取り消し単位にまとめる。
|
|
23
|
+
*
|
|
24
|
+
* プラグインを持たない状態で変換を組み立てる。`state.apply` を使うと、表や箇条書きの
|
|
25
|
+
* 整合を取るプラグインが文書をさらに変えることがあり、その文書に対して作った手順を
|
|
26
|
+
* 元の文書へ当てられなくなる。
|
|
27
|
+
*/
|
|
28
|
+
export declare function convertFromMarkup(state: EditorState, start: number, end: number, command: EditorCommand): Transaction | null;
|
|
11
29
|
/**
|
|
12
30
|
* 見出しとリスト項目を行き来する。
|
|
13
31
|
*
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { chainCommands, lift, setBlockType, wrapIn } from 'prosemirror-commands';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { EditorState, TextSelection } from 'prosemirror-state';
|
|
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';
|
|
6
7
|
const n = outlineSchema.nodes;
|
|
7
8
|
/**
|
|
8
9
|
* ブロックの種別を変える。
|
|
@@ -53,6 +54,45 @@ function blockKindInItem(kind) {
|
|
|
53
54
|
return chainCommands(setBlockType(n.paragraph), lift)(state, dispatch, view);
|
|
54
55
|
};
|
|
55
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* 行そのものを別の種別にする変換を、**文脈に合わせて**当てる。
|
|
59
|
+
*
|
|
60
|
+
* - 項目の行では、項目を解いてから変える(→ `outOfList`)
|
|
61
|
+
* - 項目の本文より後ろのブロックでは、そのブロックだけを変える(→ `blockKindInItem`)
|
|
62
|
+
*
|
|
63
|
+
* 種別の一覧(`BlockKind`)に無い行き先——言語を持つコードブロック・Mermaid ブロック——を
|
|
64
|
+
* 打った記法から作るための入口であり、振り分けの規則は `setBlockKind` と同じものである。
|
|
65
|
+
*/
|
|
66
|
+
export function changeLine(command) {
|
|
67
|
+
return (state, dispatch, view) => (blockInsideItem(state) ? command : outOfList(command))(state, dispatch, view);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 打った記法の文字を消してから変換を当て、1 つの取り消し単位にまとめる。
|
|
71
|
+
*
|
|
72
|
+
* プラグインを持たない状態で変換を組み立てる。`state.apply` を使うと、表や箇条書きの
|
|
73
|
+
* 整合を取るプラグインが文書をさらに変えることがあり、その文書に対して作った手順を
|
|
74
|
+
* 元の文書へ当てられなくなる。
|
|
75
|
+
*/
|
|
76
|
+
export function convertFromMarkup(state, start, end, command) {
|
|
77
|
+
const stripped = state.tr.delete(start, end);
|
|
78
|
+
const base = EditorState.create({
|
|
79
|
+
schema: outlineSchema,
|
|
80
|
+
doc: stripped.doc,
|
|
81
|
+
selection: stripped.selection
|
|
82
|
+
});
|
|
83
|
+
let converted;
|
|
84
|
+
command(base, (tr) => {
|
|
85
|
+
converted = tr;
|
|
86
|
+
});
|
|
87
|
+
if (!converted)
|
|
88
|
+
return null;
|
|
89
|
+
const merged = state.tr.delete(start, end);
|
|
90
|
+
for (const step of converted.steps)
|
|
91
|
+
merged.step(step);
|
|
92
|
+
// 位置は同じだが、選択は今の文書のものへ作り直す必要がある
|
|
93
|
+
merged.setSelection(TextSelection.near(merged.doc.resolve(converted.selection.from)));
|
|
94
|
+
return merged;
|
|
95
|
+
}
|
|
56
96
|
/**
|
|
57
97
|
* 見出しとリスト項目を行き来する。
|
|
58
98
|
*
|
|
@@ -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,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { EditorCommand } from '../operations.types';
|
|
2
|
+
/**
|
|
3
|
+
* フェンスの記法が作るブロックにする。
|
|
4
|
+
*
|
|
5
|
+
* **完全一致の `mermaid` だけが図のブロック**で、それ以外は言語名を持つコードブロックに
|
|
6
|
+
* なる。この振り分けは読み込み(→ `parser.ts`)と同じであり、記法から行き先を決める
|
|
7
|
+
* 判断を 2 つに分けない。
|
|
8
|
+
*
|
|
9
|
+
* 項目の行で打たれたときに項目を解くのは `changeLine` の役目である。フェンスのブロックは
|
|
10
|
+
* 項目の行になれない(→ `parser.ts` の `withOwnLine`)ため、項目を残すと「中黒の付いた
|
|
11
|
+
* コードブロック」になり、読み直したときに項目の行が 1 つ増える。
|
|
12
|
+
*/
|
|
13
|
+
export declare function toFencedBlock(language: string): EditorCommand;
|
|
14
|
+
/**
|
|
15
|
+
* 行頭からの ` ``` `(+言語名)に続く改行で、フェンスのブロックを作る。
|
|
16
|
+
*
|
|
17
|
+
* 空白での変換は autoformat の入力規則が受け持つが、入力規則は文字入力でのみ発火し、
|
|
18
|
+
* Enter では発火しない。**改行の側はこの命令しか受け持てない。**
|
|
19
|
+
* カーソルより後ろの文字は、変換後のブロックの中身として残る。
|
|
20
|
+
*/
|
|
21
|
+
export declare const fencedBlockOnEnter: EditorCommand;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { setBlockType } from 'prosemirror-commands';
|
|
2
|
+
import { outlineSchema } from '../../models/document/schema.js';
|
|
3
|
+
import { changeLine, convertFromMarkup } from './block.js';
|
|
4
|
+
const n = outlineSchema.nodes;
|
|
5
|
+
/**
|
|
6
|
+
* 行頭からカーソルまでがフェンスの記法だけか。言語名に使える文字は autoformat の
|
|
7
|
+
* 入力規則と同じものにする(打ち終わりの合図だけが違う)。
|
|
8
|
+
*/
|
|
9
|
+
const FENCE = /^```([a-zA-Z0-9_+#-]*)$/;
|
|
10
|
+
/**
|
|
11
|
+
* フェンスの記法が作るブロックにする。
|
|
12
|
+
*
|
|
13
|
+
* **完全一致の `mermaid` だけが図のブロック**で、それ以外は言語名を持つコードブロックに
|
|
14
|
+
* なる。この振り分けは読み込み(→ `parser.ts`)と同じであり、記法から行き先を決める
|
|
15
|
+
* 判断を 2 つに分けない。
|
|
16
|
+
*
|
|
17
|
+
* 項目の行で打たれたときに項目を解くのは `changeLine` の役目である。フェンスのブロックは
|
|
18
|
+
* 項目の行になれない(→ `parser.ts` の `withOwnLine`)ため、項目を残すと「中黒の付いた
|
|
19
|
+
* コードブロック」になり、読み直したときに項目の行が 1 つ増える。
|
|
20
|
+
*/
|
|
21
|
+
export function toFencedBlock(language) {
|
|
22
|
+
return changeLine(language === 'mermaid'
|
|
23
|
+
? setBlockType(n.mermaid_block)
|
|
24
|
+
: setBlockType(n.code_block, { language }));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 行頭からの ` ``` `(+言語名)に続く改行で、フェンスのブロックを作る。
|
|
28
|
+
*
|
|
29
|
+
* 空白での変換は autoformat の入力規則が受け持つが、入力規則は文字入力でのみ発火し、
|
|
30
|
+
* Enter では発火しない。**改行の側はこの命令しか受け持てない。**
|
|
31
|
+
* カーソルより後ろの文字は、変換後のブロックの中身として残る。
|
|
32
|
+
*/
|
|
33
|
+
export const fencedBlockOnEnter = (state, dispatch) => {
|
|
34
|
+
const { $from, empty } = state.selection;
|
|
35
|
+
if (!empty)
|
|
36
|
+
return false;
|
|
37
|
+
const parent = $from.parent;
|
|
38
|
+
if (!parent.isTextblock || parent.type.spec.code)
|
|
39
|
+
return false;
|
|
40
|
+
const language = FENCE.exec(parent.textBetween(0, $from.parentOffset))?.[1];
|
|
41
|
+
if (language === undefined)
|
|
42
|
+
return false;
|
|
43
|
+
// 記法は行頭からカーソルまで。位置で消すので、文字として読めないものが混じっても残らない
|
|
44
|
+
const converted = convertFromMarkup(state, $from.start(), $from.pos, toFencedBlock(language));
|
|
45
|
+
if (!converted)
|
|
46
|
+
return false;
|
|
47
|
+
dispatch?.(converted.scrollIntoView());
|
|
48
|
+
return true;
|
|
49
|
+
};
|
|
@@ -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
|
*
|