@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
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { NodeSelection, Plugin, PluginKey, TextSelection } from 'prosemirror-state';
|
|
2
2
|
import { CellSelection, cellAround } from 'prosemirror-tables';
|
|
3
3
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
4
|
-
import { sectionCommands } from '../commands/element';
|
|
5
|
-
import { blockAtBand } from './blockHandle';
|
|
4
|
+
import { sectionCommands } from '../commands/element.js';
|
|
5
|
+
import { blockAtBand } from './blockHandle.js';
|
|
6
6
|
/** 対象アイテムのマーカー。見た目は `editor.css` が持つ(利用者が上書きできる) */
|
|
7
7
|
const TARGET_CLASS = 'markdown-editor__menu-target';
|
|
8
8
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Plugin, PluginKey, TextSelection } from 'prosemirror-state';
|
|
2
2
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
3
|
-
import { outlineSchema } from '../../models/document/schema';
|
|
4
|
-
import { headingText, sectionTree } from '../../models/document/sectionTree';
|
|
5
|
-
import { originOf } from '../transactionOrigin';
|
|
3
|
+
import { outlineSchema } from '../../models/document/schema.js';
|
|
4
|
+
import { headingText, sectionTree } from '../../models/document/sectionTree.js';
|
|
5
|
+
import { originOf } from '../transactionOrigin.js';
|
|
6
6
|
const SECTION = outlineSchema.nodes.section;
|
|
7
7
|
/** 範囲外のブロックに付ける印。隠すかどうかの決定は CSS に委ねる */
|
|
8
8
|
export const OUT_OF_FOCUS_CLASS = 'markdown-editor__out-of-focus';
|
|
@@ -35,7 +35,7 @@ export function createFocusPlugin() {
|
|
|
35
35
|
key,
|
|
36
36
|
state: {
|
|
37
37
|
init: () => IDLE,
|
|
38
|
-
apply: (tr, value,
|
|
38
|
+
apply: (tr, value, oldState, newState) => nextState(key, tr, value, oldState.doc, newState.doc)
|
|
39
39
|
},
|
|
40
40
|
props: {
|
|
41
41
|
decorations: (state) => key.getState(state)?.decorations ?? DecorationSet.empty
|
|
@@ -167,7 +167,7 @@ function requestFocus(state, key, request) {
|
|
|
167
167
|
tr.setMeta('addToHistory', false);
|
|
168
168
|
return tr;
|
|
169
169
|
}
|
|
170
|
-
function nextState(key, tr, value, doc) {
|
|
170
|
+
function nextState(key, tr, value, oldDoc, doc) {
|
|
171
171
|
const meta = tr.getMeta(key);
|
|
172
172
|
if (meta === RESTORE_DONE)
|
|
173
173
|
return { ...value, pendingRestore: null };
|
|
@@ -187,19 +187,30 @@ function nextState(key, tr, value, doc) {
|
|
|
187
187
|
};
|
|
188
188
|
}
|
|
189
189
|
const restorePos = value.restorePos === null ? null : tr.mapping.map(value.restorePos);
|
|
190
|
-
//
|
|
191
|
-
|
|
190
|
+
// 対象の中身だけの変更は、連なりもきょうだいの並びも変えない(文字入力がこれに当たる)
|
|
191
|
+
const range = focusRange(oldDoc, value.anchorPos);
|
|
192
|
+
if (range && staysInside(tr, range)) {
|
|
192
193
|
return { ...value, restorePos, decorations: value.decorations.map(tr.mapping, doc) };
|
|
193
194
|
}
|
|
195
|
+
const breadcrumb = breadcrumbOf(doc, mapped.pos);
|
|
194
196
|
return {
|
|
195
197
|
anchorPos: mapped.pos,
|
|
196
|
-
|
|
198
|
+
// 連なりが同じなら前のものを使う。**同期反映は入力の合間ごとに当たる**ため、
|
|
199
|
+
// 同じ中身で作り直すと、そのたびに画面の組み直しが走る
|
|
200
|
+
breadcrumb: sameBreadcrumb(value.breadcrumb, breadcrumb) ? value.breadcrumb : breadcrumb,
|
|
197
201
|
restorePos,
|
|
198
202
|
restoreScrollTop: value.restoreScrollTop,
|
|
199
203
|
decorations: outOfFocusDecorations(doc, mapped.pos),
|
|
200
204
|
pendingRestore: null
|
|
201
205
|
};
|
|
202
206
|
}
|
|
207
|
+
function sameBreadcrumb(a, b) {
|
|
208
|
+
if (a.length !== b.length)
|
|
209
|
+
return false;
|
|
210
|
+
return a.every((item, index) => item.title === b[index].title &&
|
|
211
|
+
item.path.length === b[index].path.length &&
|
|
212
|
+
item.path.every((step, depth) => step === b[index].path[depth]));
|
|
213
|
+
}
|
|
203
214
|
function fromRequest(request, doc) {
|
|
204
215
|
if (request === null)
|
|
205
216
|
return IDLE;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Plugin } from 'prosemirror-state';
|
|
2
|
-
import { hidingAncestors } from '../commands/sectionFold';
|
|
3
|
-
import { markOrigin } from '../transactionOrigin';
|
|
2
|
+
import { hidingAncestors } from '../commands/sectionFold.js';
|
|
3
|
+
import { markOrigin } from '../transactionOrigin.js';
|
|
4
4
|
/**
|
|
5
5
|
* カーソルが折りたたまれた範囲の内側に取り残されないようにする。
|
|
6
6
|
*
|
|
@@ -1,8 +1,8 @@
|
|
|
1
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';
|
|
2
|
+
import { bodySelection } from '../../models/document/bodySelection.js';
|
|
3
|
+
import { outlineSchema } from '../../models/document/schema.js';
|
|
4
|
+
import { isDocumentReplacement } from '../transaction.js';
|
|
5
|
+
import { originOf } from '../transactionOrigin.js';
|
|
6
6
|
const FRONT_MATTER = outlineSchema.nodes.front_matter;
|
|
7
7
|
/**
|
|
8
8
|
* 全選択の置き換えを「文書まるごとの差し替え」として成立させる見張り。
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Plugin } from 'prosemirror-state';
|
|
2
2
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
3
|
-
import { outlineSchema } from '../../models/document/schema';
|
|
4
|
-
import { isEditorFocused } from './editorFocus';
|
|
5
|
-
import { findDateText } from '../../utils/dateText';
|
|
3
|
+
import { outlineSchema } from '../../models/document/schema.js';
|
|
4
|
+
import { isEditorFocused } from './editorFocus.js';
|
|
5
|
+
import { findDateText } from '../../utils/dateText.js';
|
|
6
6
|
const FRONT_MATTER = outlineSchema.nodes.front_matter;
|
|
7
7
|
/**
|
|
8
8
|
* `front_matter` の NodeView と編集中 decoration を 1 つの Plugin として返す。
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { closeHistory } from 'prosemirror-history';
|
|
2
2
|
import { AllSelection, NodeSelection, Plugin, PluginKey } from 'prosemirror-state';
|
|
3
3
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
4
|
-
import { outlineSchema } from '../../models/document/schema';
|
|
5
|
-
import { hasPastedTable } from '../../utils/pastedTable';
|
|
4
|
+
import { outlineSchema } from '../../models/document/schema.js';
|
|
5
|
+
import { hasPastedTable } from '../../utils/pastedTable.js';
|
|
6
6
|
const IMAGE = outlineSchema.nodes.image;
|
|
7
7
|
const imagePasteKey = new PluginKey('imagePaste');
|
|
8
8
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Plugin } from 'prosemirror-state';
|
|
2
|
-
import { outlineSchema } from '../../models/document/schema';
|
|
3
|
-
import { URL_PATTERN } from '../commands/link';
|
|
2
|
+
import { outlineSchema } from '../../models/document/schema.js';
|
|
3
|
+
import { URL_PATTERN } from '../commands/link.js';
|
|
4
4
|
/** 選択した範囲に URL を貼ると、その範囲をリンクの文字にする */
|
|
5
5
|
export function linkPastePlugin() {
|
|
6
6
|
return new Plugin({
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Fragment, Slice } from 'prosemirror-model';
|
|
2
2
|
import { AllSelection, Plugin, TextSelection } from 'prosemirror-state';
|
|
3
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
|
-
import { hasPastedTable } from '../../utils/pastedTable';
|
|
4
|
+
import { bodySelection } from '../../models/document/bodySelection.js';
|
|
5
|
+
import { parseMarkdown } from '../../models/markdown/parser.js';
|
|
6
|
+
import { serializeSlice } from '../../models/markdown/serializer.js';
|
|
7
|
+
import { MAX_HEADING_LEVEL } from '../../models/document/document.types.js';
|
|
8
|
+
import { outlineSchema } from '../../models/document/schema.js';
|
|
9
|
+
import { sectionTree } from '../../models/document/sectionTree.js';
|
|
10
|
+
import { markDocumentReplacement } from '../transaction.js';
|
|
11
|
+
import { hasPastedTable } from '../../utils/pastedTable.js';
|
|
12
12
|
const n = outlineSchema.nodes;
|
|
13
13
|
/**
|
|
14
14
|
* クリップボードとのやり取りをマークダウンで行う。
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Plugin } from 'prosemirror-state';
|
|
2
2
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
3
|
-
import { outlineSchema } from '../../models/document/schema';
|
|
4
|
-
import { isEditorFocused } from './editorFocus';
|
|
3
|
+
import { outlineSchema } from '../../models/document/schema.js';
|
|
4
|
+
import { isEditorFocused } from './editorFocus.js';
|
|
5
5
|
const MERMAID_BLOCK = outlineSchema.nodes.mermaid_block;
|
|
6
6
|
// --- mermaid の遅延読み込み ---
|
|
7
7
|
//
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { keydownHandler } from 'prosemirror-keymap';
|
|
2
2
|
import { NodeSelection, Plugin, PluginKey, Selection, TextSelection } from 'prosemirror-state';
|
|
3
|
-
import { requiredSelectionBlock } from '../commands/selectedBlock';
|
|
3
|
+
import { requiredSelectionBlock } from '../commands/selectedBlock.js';
|
|
4
4
|
/**
|
|
5
5
|
* 上下移動で要選択ブロックの境を越えたとき、中へ入らずそのブロックを指した状態にする。
|
|
6
6
|
*
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Plugin } from 'prosemirror-state';
|
|
2
2
|
import { TableMap } from 'prosemirror-tables';
|
|
3
3
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
4
|
-
import { insertColumnAt } from '../commands/table';
|
|
5
|
-
import { outlineSchema } from '../../models/document/schema';
|
|
4
|
+
import { insertColumnAt } from '../commands/table.js';
|
|
5
|
+
import { outlineSchema } from '../../models/document/schema.js';
|
|
6
6
|
/**
|
|
7
7
|
* 列の境目に、押すと列が増える手がかりを出す。
|
|
8
8
|
*
|
|
@@ -3,15 +3,19 @@ import type { Transaction } from 'prosemirror-state';
|
|
|
3
3
|
* 変更の由来を Transaction に書き添える。
|
|
4
4
|
*
|
|
5
5
|
* 判定する側(フォーカス範囲外への波及を塞ぐ仕組み)は、変更の内容だけを見ても
|
|
6
|
-
*
|
|
6
|
+
* 「書き手が編集した」のか「利用者のアプリが本文を当てた」のかを区別できない。
|
|
7
7
|
* 区別できないまま一律に塞ぐと、利用者の変更が黙って落ちる。
|
|
8
8
|
*
|
|
9
|
-
* - `
|
|
9
|
+
* - `replacement`: 利用者の操作として取り消せる置き換え(`bind:value` と `replaceMarkdown`)
|
|
10
|
+
* - `remote`: 他の書き手の変更の同期反映。取り消し履歴に積まない
|
|
10
11
|
* - `fold`: 折りたたみの切り替え。表示だけを変えるため通す
|
|
11
12
|
* - `metadata`: フロントマターへの項目の書き込み。領域は表示範囲の外にあるため、
|
|
12
|
-
*
|
|
13
|
-
*
|
|
13
|
+
* 印が無ければ黙って落ちる
|
|
14
|
+
*
|
|
15
|
+
* **値は「何をした変更か」を表し、「その後に何を組み直すか」は表さない。** 組み直しの
|
|
16
|
+
* 要否は変更そのものから決める(→ `focus.ts`)。印の値で決めると、同期反映を足すたびに
|
|
17
|
+
* 組み直しの引き金が増える。
|
|
14
18
|
*/
|
|
15
|
-
export type TransactionOrigin = '
|
|
19
|
+
export type TransactionOrigin = 'replacement' | 'remote' | 'fold' | 'metadata';
|
|
16
20
|
export declare function markOrigin<T extends Transaction>(transaction: T, origin: TransactionOrigin): T;
|
|
17
21
|
export declare function originOf(transaction: Transaction): TransactionOrigin | null;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
const ORIGIN = 'markdown-editor:origin';
|
|
2
|
+
const ORIGINS = ['replacement', 'remote', 'fold', 'metadata'];
|
|
2
3
|
export function markOrigin(transaction, origin) {
|
|
3
4
|
transaction.setMeta(ORIGIN, origin);
|
|
4
5
|
return transaction;
|
|
5
6
|
}
|
|
6
7
|
export function originOf(transaction) {
|
|
7
8
|
const origin = transaction.getMeta(ORIGIN);
|
|
8
|
-
return origin
|
|
9
|
+
return ORIGINS.includes(origin) ? origin : null;
|
|
9
10
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { editorKeymap } from '../operations/keymap/assemble';
|
|
2
|
-
import { describedIds, keyLabelledActions, menuGroupsFor } from '../operations/keymap/menuItems';
|
|
3
|
-
import { createKeyStrokeMatcher } from '../operations/keymap/shortcutKeys';
|
|
4
|
-
import { createContextMenuShortcut } from '../operations/keymap/viewActions';
|
|
5
|
-
import { createContextMenuPlugin } from '../operations/plugins/contextMenu';
|
|
1
|
+
import { editorKeymap } from '../operations/keymap/assemble.js';
|
|
2
|
+
import { describedIds, keyLabelledActions, menuGroupsFor } from '../operations/keymap/menuItems.js';
|
|
3
|
+
import { createKeyStrokeMatcher } from '../operations/keymap/shortcutKeys.js';
|
|
4
|
+
import { createContextMenuShortcut } from '../operations/keymap/viewActions.js';
|
|
5
|
+
import { createContextMenuPlugin } from '../operations/plugins/contextMenu.js';
|
|
6
6
|
/**
|
|
7
7
|
* メニューの開閉・錨・項目を、エディタ 1 インスタンスに閉じて持つ。
|
|
8
8
|
*
|
|
@@ -4,28 +4,30 @@ import { closeHistory, history } from 'prosemirror-history';
|
|
|
4
4
|
import { EditorState } from 'prosemirror-state';
|
|
5
5
|
import { tableEditing } from 'prosemirror-tables';
|
|
6
6
|
import { EditorView } from 'prosemirror-view';
|
|
7
|
-
import { parseMarkdown } from '../models/markdown/parser';
|
|
8
|
-
import { serializeMarkdown } from '../models/markdown/serializer';
|
|
9
|
-
import { editorKeymap } from '../operations/keymap/assemble';
|
|
10
|
-
import { DEFAULT_LANG, resolveMessages } from '../messages';
|
|
11
|
-
import { sectionViewPlugin } from '../operations/plugins/sectionView';
|
|
12
|
-
import { mermaidViewPlugin } from '../operations/plugins/mermaidView';
|
|
13
|
-
import { imagePastePlugin } from '../operations/plugins/imagePaste';
|
|
14
|
-
import { imageViewPlugin } from '../operations/plugins/imageView';
|
|
15
|
-
import { blockHandlePlugin } from '../operations/plugins/blockHandle';
|
|
16
|
-
import { frontMatterGuardPlugin } from '../operations/plugins/frontMatterGuard';
|
|
17
|
-
import { editorFocusPlugin } from '../operations/plugins/editorFocus';
|
|
18
|
-
import { frontMatterViewPlugin } from '../operations/plugins/frontMatterView';
|
|
19
|
-
import { headingLevelPlugin } from '../operations/plugins/headingLevel';
|
|
20
|
-
import { listStructurePlugin } from '../operations/plugins/listStructure';
|
|
21
|
-
import { markdownClipboardPlugin } from '../operations/plugins/markdownClipboard';
|
|
22
|
-
import { tablePastePlugin } from '../operations/plugins/tablePaste';
|
|
23
|
-
import { requiredSelectionEntryPlugin } from '../operations/plugins/requiredSelectionEntry';
|
|
24
|
-
import { tableHandlesPlugin } from '../operations/plugins/tableHandles';
|
|
25
|
-
import { writeFrontMatterFields as writeFrontMatterFieldsCommand } from '../operations/commands/frontMatter';
|
|
26
|
-
import { bodySelection } from '../models/document/bodySelection';
|
|
27
|
-
import { outlineSchema } from '../models/document/schema';
|
|
28
|
-
import {
|
|
7
|
+
import { parseMarkdown } from '../models/markdown/parser.js';
|
|
8
|
+
import { serializeMarkdown } from '../models/markdown/serializer.js';
|
|
9
|
+
import { editorKeymap } from '../operations/keymap/assemble.js';
|
|
10
|
+
import { DEFAULT_LANG, resolveMessages } from '../messages/index.js';
|
|
11
|
+
import { sectionViewPlugin } from '../operations/plugins/sectionView.js';
|
|
12
|
+
import { mermaidViewPlugin } from '../operations/plugins/mermaidView.js';
|
|
13
|
+
import { imagePastePlugin } from '../operations/plugins/imagePaste.js';
|
|
14
|
+
import { imageViewPlugin } from '../operations/plugins/imageView.js';
|
|
15
|
+
import { blockHandlePlugin } from '../operations/plugins/blockHandle.js';
|
|
16
|
+
import { frontMatterGuardPlugin } from '../operations/plugins/frontMatterGuard.js';
|
|
17
|
+
import { editorFocusPlugin } from '../operations/plugins/editorFocus.js';
|
|
18
|
+
import { frontMatterViewPlugin } from '../operations/plugins/frontMatterView.js';
|
|
19
|
+
import { headingLevelPlugin } from '../operations/plugins/headingLevel.js';
|
|
20
|
+
import { listStructurePlugin } from '../operations/plugins/listStructure.js';
|
|
21
|
+
import { markdownClipboardPlugin } from '../operations/plugins/markdownClipboard.js';
|
|
22
|
+
import { tablePastePlugin } from '../operations/plugins/tablePaste.js';
|
|
23
|
+
import { requiredSelectionEntryPlugin } from '../operations/plugins/requiredSelectionEntry.js';
|
|
24
|
+
import { tableHandlesPlugin } from '../operations/plugins/tableHandles.js';
|
|
25
|
+
import { writeFrontMatterFields as writeFrontMatterFieldsCommand } from '../operations/commands/frontMatter.js';
|
|
26
|
+
import { bodySelection } from '../models/document/bodySelection.js';
|
|
27
|
+
import { outlineSchema } from '../models/document/schema.js';
|
|
28
|
+
import { diffTransaction } from '../operations/documentDiff.js';
|
|
29
|
+
import { createCompositionState } from '../operations/plugins/compositionState.js';
|
|
30
|
+
import { markOrigin } from '../operations/transactionOrigin.js';
|
|
29
31
|
/**
|
|
30
32
|
* 編集セッションを 1 つ作る。
|
|
31
33
|
*
|
|
@@ -51,7 +53,14 @@ export function createEditorSession(element, options) {
|
|
|
51
53
|
const listeners = new Set();
|
|
52
54
|
/** 画像の文言。**貼り付けと表示の 2 つが同じものを読む**(読むたびに最新を返す) */
|
|
53
55
|
const imageText = () => presentation.imageText ?? defaultImageText();
|
|
56
|
+
/**
|
|
57
|
+
* 外から書き込めるかの**唯一の情報源**。3 つの命令と `value` の経路がこれを読む。
|
|
58
|
+
* 判定を 2 通り持つと、経路ごとに食い違う
|
|
59
|
+
*/
|
|
60
|
+
const composition = createCompositionState();
|
|
54
61
|
const plugins = [
|
|
62
|
+
// 変換の出来事を受け止める。**キーの割り当てより前**に置く(出来事を取りこぼさない)
|
|
63
|
+
composition.plugin,
|
|
55
64
|
// 上下キーが押されたことの記録は、**キーの割り当てより前**に置く。
|
|
56
65
|
// 後ろに置くと、割り当てが受け止めたキー(表のセル移動など)を見逃し、
|
|
57
66
|
// 表から出た先の要選択ブロックを指せない
|
|
@@ -151,28 +160,45 @@ export function createEditorSession(element, options) {
|
|
|
151
160
|
for (const listener of listeners)
|
|
152
161
|
listener(change);
|
|
153
162
|
}
|
|
163
|
+
function outcome(status) {
|
|
164
|
+
return { ok: true, value: { status, markdown: cachedMarkdown } };
|
|
165
|
+
}
|
|
166
|
+
/** 見送り。文書・カーソル・取り消し履歴・購読者への通知のいずれも変えない */
|
|
167
|
+
function deferred() {
|
|
168
|
+
return { ok: true, value: { status: 'deferred', markdown: cachedMarkdown } };
|
|
169
|
+
}
|
|
154
170
|
return {
|
|
155
171
|
ok: true,
|
|
156
172
|
value: {
|
|
157
173
|
getMarkdown: () => cachedMarkdown,
|
|
158
|
-
|
|
174
|
+
/**
|
|
175
|
+
* **書き込めるかを最初に見る。** 読み取りを先に行うと、見送るだけの呼び出しでも
|
|
176
|
+
* 毎回読み取りの費用が掛かる。利用側は見送られているあいだ繰り返し呼ぶ。
|
|
177
|
+
*
|
|
178
|
+
* 見送った本文は控えない。当て直しは利用側が自分の引き金で行う
|
|
179
|
+
*/
|
|
180
|
+
applyMarkdown(markdown, kind) {
|
|
181
|
+
if (!composition.canWriteFromOutside(view))
|
|
182
|
+
return deferred();
|
|
159
183
|
const result = parseMarkdown(markdown);
|
|
160
184
|
if (!result.ok)
|
|
161
185
|
return result;
|
|
162
186
|
const transaction = diffTransaction(view.state, result.value);
|
|
163
187
|
if (!transaction)
|
|
164
|
-
return
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
// (塞ぐと、利用者が渡した本文が黙って落ちる)
|
|
168
|
-
view.dispatch(markOrigin(closeHistory(transaction), 'host'));
|
|
169
|
-
return { ok: true, value: undefined };
|
|
188
|
+
return outcome('unchanged');
|
|
189
|
+
view.dispatch(applyRule(kind)(transaction));
|
|
190
|
+
return outcome('applied');
|
|
170
191
|
},
|
|
171
192
|
/**
|
|
172
193
|
* 命令を呼び、変更があれば当てて、結果を返すだけ。**判断を持たない。**
|
|
173
|
-
*
|
|
194
|
+
* 同値・失敗の決定は命令の側にある。
|
|
195
|
+
*
|
|
196
|
+
* 見送りだけはこの層で見る。項目を組み立てる純関数は `EditorState` しか
|
|
197
|
+
* 受け取らず、変換中かどうかを見られない(署名も中身も変えない)
|
|
174
198
|
*/
|
|
175
199
|
writeFrontMatterFields(fields) {
|
|
200
|
+
if (!composition.canWriteFromOutside(view))
|
|
201
|
+
return { ok: true, value: 'skipped' };
|
|
176
202
|
const result = writeFrontMatterFieldsCommand(view.state, fields);
|
|
177
203
|
if (!result.ok)
|
|
178
204
|
return result;
|
|
@@ -278,26 +304,19 @@ function sameMermaidText(a, b) {
|
|
|
278
304
|
a.loadError === b.loadError);
|
|
279
305
|
}
|
|
280
306
|
/**
|
|
281
|
-
*
|
|
307
|
+
* 適用の種類ごとの、取り消し履歴の扱いと変更の由来。
|
|
282
308
|
*
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
* (最小差分は求めない。守りたいのはカーソルと履歴であって差分の最小性ではない)。
|
|
309
|
+
* 由来を書き添えるのは、表示範囲を絞る仕組みがこれを見て素通しするためである
|
|
310
|
+
* (塞ぐと、利用者が渡した本文が黙って落ちる)。
|
|
286
311
|
*/
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
const overlap = start - Math.min(endInCurrent, endInNext);
|
|
298
|
-
if (overlap > 0) {
|
|
299
|
-
endInCurrent += overlap;
|
|
300
|
-
endInNext += overlap;
|
|
301
|
-
}
|
|
302
|
-
return state.tr.replace(start, endInCurrent, next.slice(start, endInNext));
|
|
312
|
+
const APPLY_RULES = {
|
|
313
|
+
// 直前の文字入力とは独立した取り消し単位にする
|
|
314
|
+
replacement: { origin: 'replacement', keep: true },
|
|
315
|
+
// 履歴に積まない。積むと、利用者が自分の入力を戻すつもりで他の書き手の変更を消す。
|
|
316
|
+
// 履歴の中の位置は `prosemirror-history` が写す
|
|
317
|
+
remote: { origin: 'remote', keep: false }
|
|
318
|
+
};
|
|
319
|
+
function applyRule(kind) {
|
|
320
|
+
const { origin, keep } = APPLY_RULES[kind];
|
|
321
|
+
return (transaction) => markOrigin(keep ? closeHistory(transaction) : transaction.setMeta('addToHistory', false), origin);
|
|
303
322
|
}
|
|
@@ -53,15 +53,53 @@ export interface EditorSessionOptions extends EditorPresentation {
|
|
|
53
53
|
*/
|
|
54
54
|
readonly imageUpload?: ImageUploadSource;
|
|
55
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* 適用の種類。利用者の操作として取り消せる置き換えか、他の書き手の変更の同期反映か。
|
|
58
|
+
*
|
|
59
|
+
* **既定値を持たない。** 取り消し履歴の扱いが種類で決まるため、呼び出し側が必ず渡す。
|
|
60
|
+
*/
|
|
61
|
+
export type ApplyKind = 'replacement' | 'remote';
|
|
62
|
+
export type ApplyStatus =
|
|
63
|
+
/** 当てた */
|
|
64
|
+
'applied'
|
|
65
|
+
/** 内容が同じだったため何もしなかった */
|
|
66
|
+
| 'unchanged'
|
|
67
|
+
/** かな漢字変換の確定した文字が入りきっていないため見送った。**失敗ではない** */
|
|
68
|
+
| 'deferred';
|
|
69
|
+
/**
|
|
70
|
+
* 本文を書き込めなかった理由。本文を受け取る 3 つの命令(`resetDocument` /
|
|
71
|
+
* `replaceMarkdown` / `applyRemoteChange`)が共通で返す。
|
|
72
|
+
*
|
|
73
|
+
* **未準備を読み取りの失敗に混ぜない。** 混ぜると、利用側は自分の渡した本文が壊れて
|
|
74
|
+
* いるのか呼ぶのが早すぎたのかを区別できず、手がかりが `detail` の文字列しか残らない
|
|
75
|
+
* (内部の説明文であって、約束ではない)。`FrontMatterWriteError` が同じ形を持っている。
|
|
76
|
+
*
|
|
77
|
+
* **見送りを含めない。** 見送りは失敗ではなく正常な流れの一部であり、`ApplyStatus` が表す。
|
|
78
|
+
* 失敗として返すと、利用側のエラー処理が常時発火して本当の失敗が埋もれる。
|
|
79
|
+
*/
|
|
80
|
+
export type MarkdownWriteError = MarkdownParseError | {
|
|
81
|
+
readonly kind: 'not-ready';
|
|
82
|
+
};
|
|
83
|
+
export interface ApplyOutcome {
|
|
84
|
+
readonly status: ApplyStatus;
|
|
85
|
+
/** 正規化した後の本文。`deferred` のときは当てる前の本文 */
|
|
86
|
+
readonly markdown: string;
|
|
87
|
+
}
|
|
56
88
|
export interface EditorSession {
|
|
57
89
|
getMarkdown(): string;
|
|
58
|
-
/**
|
|
59
|
-
|
|
90
|
+
/**
|
|
91
|
+
* 外から渡された本文を、変わった箇所ごとの置き換えとして当てる。
|
|
92
|
+
* 取り消し履歴の扱いと変更の由来は `kind` が決める。
|
|
93
|
+
*
|
|
94
|
+
* 変換の確定した文字が入りきるまでは当てず、`deferred` を返す
|
|
95
|
+
*/
|
|
96
|
+
applyMarkdown(markdown: string, kind: ApplyKind): Result<ApplyOutcome, MarkdownParseError>;
|
|
60
97
|
/** 文書全体を入れ替え、取り消し履歴を初期化する */
|
|
61
98
|
resetDocument(markdown: string): Result<void, MarkdownParseError>;
|
|
62
99
|
/**
|
|
63
100
|
* フロントマターへ項目を書き込む。取り消し履歴に積まず、本文とカーソルを変えない。
|
|
64
|
-
*
|
|
101
|
+
* 利用者がその項目を編集している最中、および変換の確定した文字が入りきるまでは
|
|
102
|
+
* 見送り、`skipped` を返す
|
|
65
103
|
*/
|
|
66
104
|
writeFrontMatterFields(fields: FrontMatterFields): Result<FrontMatterWriteOutcome, FrontMatterWriteError>;
|
|
67
105
|
focus(): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Result } from '../utils/result.types';
|
|
2
|
-
import { type FocusBreadcrumbItem } from '../operations/plugins/focus';
|
|
2
|
+
import { type FocusBreadcrumbItem } from '../operations/plugins/focus.js';
|
|
3
3
|
import type { SectionPath } from '../models/document/document.types';
|
|
4
4
|
import type { ViewState, ViewStateError } from '../models/viewState/viewState.types';
|
|
5
5
|
import type { EditorExtension, EditorSession } from './editorSession.types';
|
|
@@ -33,12 +33,6 @@ export interface OutlineViewController {
|
|
|
33
33
|
focusPath(path: SectionPath): void;
|
|
34
34
|
getViewState(): ViewState;
|
|
35
35
|
applyViewState(value: unknown): Result<void, ViewStateError>;
|
|
36
|
-
/**
|
|
37
|
-
* 本文の差し替えを挟んで、見出しの折りたたみを引き継ぐ。
|
|
38
|
-
* 差分適用は変更範囲のノードを作り直すため、そのままでは折りたたみが失われる。
|
|
39
|
-
* `resetDocument`(別の文書を開く)には用いない。
|
|
40
|
-
*/
|
|
41
|
-
preserveFolds<T>(apply: () => T): T;
|
|
42
36
|
}
|
|
43
37
|
/**
|
|
44
38
|
* 表示状態のまとめ役。
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { foldCommands } from '../operations/commands/sectionFold';
|
|
2
|
-
import { foldClickPlugin } from '../operations/plugins/foldClick';
|
|
3
|
-
import { foldGuardPlugin } from '../operations/plugins/foldGuard';
|
|
4
|
-
import { createFocusPlugin } from '../operations/plugins/focus';
|
|
5
|
-
import { createViewActions } from '../operations/keymap/viewActions';
|
|
6
|
-
import { EMPTY_VIEW_STATE, viewStateCodec } from '../models/viewState/viewStateCodec';
|
|
1
|
+
import { foldCommands } from '../operations/commands/sectionFold.js';
|
|
2
|
+
import { foldClickPlugin } from '../operations/plugins/foldClick.js';
|
|
3
|
+
import { foldGuardPlugin } from '../operations/plugins/foldGuard.js';
|
|
4
|
+
import { createFocusPlugin } from '../operations/plugins/focus.js';
|
|
5
|
+
import { createViewActions } from '../operations/keymap/viewActions.js';
|
|
6
|
+
import { EMPTY_VIEW_STATE, viewStateCodec } from '../models/viewState/viewStateCodec.js';
|
|
7
7
|
/**
|
|
8
8
|
* 表示状態のまとめ役。
|
|
9
9
|
*
|
|
@@ -96,20 +96,6 @@ export function createOutlineViewController(options) {
|
|
|
96
96
|
focus.applyFocus(path)(view.state, view.dispatch.bind(view), view);
|
|
97
97
|
sync();
|
|
98
98
|
}
|
|
99
|
-
function preserveFolds(apply) {
|
|
100
|
-
const before = getViewState();
|
|
101
|
-
const result = apply();
|
|
102
|
-
const view = viewOf();
|
|
103
|
-
if (!view)
|
|
104
|
-
return result;
|
|
105
|
-
// 突合キーによる照合をそのまま使うため、本当に変わったセクションには当たらない
|
|
106
|
-
const decoded = viewStateCodec.decode(before, view.state.doc);
|
|
107
|
-
if (decoded.ok && decoded.value.foldedPaths.length > 0) {
|
|
108
|
-
foldCommands.applyFoldedPaths(decoded.value.foldedPaths)(view.state, view.dispatch.bind(view), view);
|
|
109
|
-
}
|
|
110
|
-
sync();
|
|
111
|
-
return result;
|
|
112
|
-
}
|
|
113
99
|
return {
|
|
114
100
|
extension,
|
|
115
101
|
sync,
|
|
@@ -128,7 +114,6 @@ export function createOutlineViewController(options) {
|
|
|
128
114
|
clearFocus,
|
|
129
115
|
focusPath,
|
|
130
116
|
getViewState,
|
|
131
|
-
applyViewState
|
|
132
|
-
preserveFolds
|
|
117
|
+
applyViewState
|
|
133
118
|
};
|
|
134
119
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@14ch/svelte-md-outliner",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "An outliner-style Markdown editor for Svelte 5. Headings form a real section tree you can fold, focus, and re-nest from the keyboard.",
|