@14ch/svelte-md-outliner 0.0.19 → 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.
Files changed (75) hide show
  1. package/CHANGELOG.md +22 -1
  2. package/README.ja.md +47 -24
  3. package/README.md +47 -24
  4. package/dist/assets/styles/editor.css +42 -2
  5. package/dist/components/ContextMenu.svelte +1 -1
  6. package/dist/components/EditorSurface.svelte +2 -2
  7. package/dist/components/MarkdownEditor.svelte +69 -17
  8. package/dist/components/MarkdownEditor.svelte.d.ts +16 -3
  9. package/dist/components/ShortcutHelpDialog.svelte +3 -3
  10. package/dist/index.d.ts +12 -4
  11. package/dist/index.js +4 -2
  12. package/dist/markdown.d.ts +2 -0
  13. package/dist/markdown.js +1 -0
  14. package/dist/messages/index.d.ts +2 -2
  15. package/dist/messages/index.js +2 -2
  16. package/dist/models/document/bodySelection.js +1 -1
  17. package/dist/models/document/schema.d.ts +10 -1
  18. package/dist/models/document/schema.js +13 -2
  19. package/dist/models/document/sectionTree.d.ts +1 -1
  20. package/dist/models/document/sectionTree.js +2 -2
  21. package/dist/models/markdown/normalize.d.ts +20 -0
  22. package/dist/models/markdown/normalize.js +25 -0
  23. package/dist/models/markdown/parser.js +8 -6
  24. package/dist/models/markdown/serializer.js +12 -11
  25. package/dist/models/viewState/viewStateCodec.d.ts +1 -1
  26. package/dist/models/viewState/viewStateCodec.js +3 -3
  27. package/dist/operations/autoformat.js +3 -3
  28. package/dist/operations/commands/block.js +4 -4
  29. package/dist/operations/commands/element.js +9 -9
  30. package/dist/operations/commands/fencedBlock.js +2 -2
  31. package/dist/operations/commands/frontMatter.js +5 -5
  32. package/dist/operations/commands/lineBreak.js +1 -1
  33. package/dist/operations/commands/link.js +1 -1
  34. package/dist/operations/commands/list.js +59 -6
  35. package/dist/operations/commands/section.d.ts +1 -1
  36. package/dist/operations/commands/section.js +5 -5
  37. package/dist/operations/commands/sectionFold.d.ts +1 -1
  38. package/dist/operations/commands/sectionFold.js +5 -5
  39. package/dist/operations/commands/sectionJump.js +2 -2
  40. package/dist/operations/commands/selectedBlock.js +3 -3
  41. package/dist/operations/commands/table.js +43 -2
  42. package/dist/operations/documentDiff.d.ts +12 -0
  43. package/dist/operations/documentDiff.js +191 -0
  44. package/dist/operations/keymap/assemble.js +5 -5
  45. package/dist/operations/keymap/coreActions.js +13 -13
  46. package/dist/operations/keymap/menuItems.js +2 -2
  47. package/dist/operations/keymap/shortcutKeys.js +1 -1
  48. package/dist/operations/keymap/viewActions.js +5 -5
  49. package/dist/operations/plugins/blockHandle.js +1 -1
  50. package/dist/operations/plugins/compositionState.d.ts +30 -0
  51. package/dist/operations/plugins/compositionState.js +65 -0
  52. package/dist/operations/plugins/contextMenu.js +2 -2
  53. package/dist/operations/plugins/focus.js +19 -8
  54. package/dist/operations/plugins/foldClick.js +1 -1
  55. package/dist/operations/plugins/foldGuard.js +2 -2
  56. package/dist/operations/plugins/frontMatterGuard.js +4 -4
  57. package/dist/operations/plugins/frontMatterView.js +3 -3
  58. package/dist/operations/plugins/headingLevel.js +1 -1
  59. package/dist/operations/plugins/imagePaste.js +2 -2
  60. package/dist/operations/plugins/imageView.js +1 -1
  61. package/dist/operations/plugins/linkPaste.js +2 -2
  62. package/dist/operations/plugins/listStructure.js +1 -1
  63. package/dist/operations/plugins/markdownClipboard.js +8 -8
  64. package/dist/operations/plugins/mermaidView.js +2 -2
  65. package/dist/operations/plugins/requiredSelectionEntry.js +1 -1
  66. package/dist/operations/plugins/sectionView.js +1 -1
  67. package/dist/operations/plugins/tableHandles.js +2 -2
  68. package/dist/operations/transactionOrigin.d.ts +9 -5
  69. package/dist/operations/transactionOrigin.js +2 -1
  70. package/dist/states/contextMenuController.svelte.js +5 -5
  71. package/dist/states/editorSession.js +69 -50
  72. package/dist/states/editorSession.types.d.ts +41 -3
  73. package/dist/states/outlineViewController.svelte.d.ts +1 -7
  74. package/dist/states/outlineViewController.svelte.js +7 -22
  75. package/package.json +1 -1
@@ -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';
@@ -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
  export { en, ja };
4
4
  const bundled = { en, ja };
5
5
  export const DEFAULT_LANG = 'en';
@@ -1,5 +1,5 @@
1
1
  import { Selection } from 'prosemirror-state';
2
- import { outlineSchema } from './schema';
2
+ import { outlineSchema } from './schema.js';
3
3
  /**
4
4
  * 文書を開いた直後に置く選択。フロントマターの後ろの、本文の先頭。
5
5
  *
@@ -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
- const content = token.content ? outlineSchema.text(token.content) : null;
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
- // 1 行で書けるブロックだけが「項目の行」になれる。コードブロックは文字を持つが、
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
- * 中身を書き終えた時点で、書き手はすでに次の行の頭に立っている。そこへもう 1 つ
225
- * 改行を足すと、**字下げの中(項目の中のコードブロック)で「字下げだけの行」が挟まる**。
226
- * その行は読み直したときに中身の空行として数えられ、往復のたびに行が 1 つずつ増える。
224
+ * **閉じの記号の前の改行は記法であり、中身ではない**(→ `parser.ts` の `fence`)。
225
+ * だから中身を書き終えたら改行を 1 つ必ず置く。`ensureNewLine` では足りない——
226
+ * 中身の最後が空行のとき、その行を書き終えた時点ですでに行頭に立っており、
227
+ * **空行と記法の改行が 1 つに潰れて空行が消える**。
227
228
  *
228
- * 字下げの無い場所では、足しても足さなくても同じ文字になるため、書き出しは変わらない。
229
- * 中身が空のときは 1 文字も書かない(字下げだけの行を作らないため)。
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
- if (!content.endsWith('\n'))
238
- state.ensureNewLine();
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
  *
@@ -1,4 +1,4 @@
1
- import { outlineSchema } from '../../models/document/schema';
1
+ import { outlineSchema } from '../../models/document/schema.js';
2
2
  /**
3
3
  * 段落を分けずに改行する。
4
4
  *
@@ -1,4 +1,4 @@
1
- import { outlineSchema } from '../../models/document/schema';
1
+ import { outlineSchema } from '../../models/document/schema.js';
2
2
  export const URL_PATTERN = /^(https?:\/\/|mailto:)\S+$/;
3
3
  /**
4
4
  * リンクの適用と解除。すでにリンクなら解除し、選択した文字が URL ならその URL へのリンクにする。
@@ -1,15 +1,15 @@
1
- import { joinTextblockBackward, wrapIn } from 'prosemirror-commands';
2
- import { backspaceCommand, createIndentListCommand, createSplitListCommand, createToggleListCommand, createUnwrapListCommand, doSplitList, findListsRange, isListNode } from 'prosemirror-flat-list';
1
+ import { chainCommands, joinTextblockBackward, wrapIn } from 'prosemirror-commands';
2
+ import { backspaceCommand, createIndentListCommand, createSplitListCommand, createUnwrapListCommand, createWrapInListCommand, doSplitList, findListsRange, isListNode } from 'prosemirror-flat-list';
3
3
  import { TextSelection } from 'prosemirror-state';
4
- import { outlineSchema } from '../../models/document/schema';
5
- import { moveContent, setCursor } from '../transaction';
6
- import { coveredEnd, moveBlockAcrossSection, moveRange, neighborSide, restoreMovedSelection, siblingRange } from './section';
4
+ import { canBeItemLine, outlineSchema } from '../../models/document/schema.js';
5
+ import { moveContent, setCursor } from '../transaction.js';
6
+ import { coveredEnd, moveBlockAcrossSection, moveRange, neighborSide, restoreMovedSelection, siblingRange } from './section.js';
7
7
  export const listCommands = {
8
8
  indentList,
9
9
  dedentList,
10
10
  splitListItem,
11
11
  toggleTaskChecked,
12
- toggleListKind: (kind) => createToggleListCommand({ kind }),
12
+ toggleListKind,
13
13
  unwrapList: createUnwrapListCommand(),
14
14
  moveListItem,
15
15
  backspace: listBackspace,
@@ -17,6 +17,59 @@ export const listCommands = {
17
17
  isInList: (state) => enclosingListItem(state) !== null,
18
18
  enclosingListItem
19
19
  };
20
+ /**
21
+ * 箇条書きにする(同じ種別なら解除する)。
22
+ *
23
+ * **項目の行になれないブロックは、選択に混ざっていても項目にしない**
24
+ * (→ スキーマの `canBeItemLine`)。コードブロックを項目にすると「中黒の付いた
25
+ * コードブロック」になり、書き出して読み直すと空の項目行が 1 つ増える。
26
+ * 解除の判定は選択の全体で見る——ブロックごとに掛け外しすると、段落と項目が
27
+ * 混ざった選択で、触っていない項目まで解けてしまう。
28
+ */
29
+ function toggleListKind(kind) {
30
+ return chainCommands(createUnwrapListCommand({ kind }), wrapItemLinesInList(kind));
31
+ }
32
+ /**
33
+ * 選択の中の**項目の行になれるブロックだけ**を項目にする。
34
+ *
35
+ * 1 ブロックずつ包む(ライブラリの包む操作も同じ単位で動く)。後ろから順に当てるのは、
36
+ * 後ろを包んでも前のブロックの位置が動かないためである。
37
+ */
38
+ function wrapItemLinesInList(kind) {
39
+ const wrapOne = createWrapInListCommand({ kind });
40
+ return (state, dispatch) => {
41
+ const { $from, $to } = state.selection;
42
+ const range = $from.blockRange($to);
43
+ if (!range)
44
+ return false;
45
+ const targets = [];
46
+ for (let index = range.startIndex; index < range.endIndex; index += 1) {
47
+ const child = range.parent.child(index);
48
+ // すでに項目なら種別の変更として通す(判定はライブラリが持つ)
49
+ if (!isListNode(child) && !canBeItemLine(child.type))
50
+ continue;
51
+ targets.push($from.posAtIndex(index, range.depth) + 1);
52
+ }
53
+ if (targets.length === 0)
54
+ return false;
55
+ if (!dispatch)
56
+ return true;
57
+ const tr = state.tr;
58
+ let current = state;
59
+ for (const pos of targets.reverse()) {
60
+ const at = current.apply(current.tr.setSelection(TextSelection.near(current.doc.resolve(pos))));
61
+ wrapOne(at, (next) => {
62
+ for (const step of next.steps)
63
+ tr.step(step);
64
+ current = at.apply(next);
65
+ });
66
+ }
67
+ if (!tr.docChanged)
68
+ return false;
69
+ dispatch(tr.scrollIntoView());
70
+ return true;
71
+ };
72
+ }
20
73
  /**
21
74
  * 段落を箇条書きの項目にする。
22
75
  *
@@ -1,6 +1,6 @@
1
1
  import type { Node } from 'prosemirror-model';
2
2
  import { type EditorState, type Transaction } from 'prosemirror-state';
3
- import { type HeadingLevel, type SectionRef } from '../../models/document/document.types';
3
+ import { type HeadingLevel, type SectionRef } from '../../models/document/document.types.js';
4
4
  import type { EditorCommand, MoveDirection } from '../operations.types';
5
5
  /**
6
6
  * 見出しを 1 段深くする。直前の兄弟セクションの中身の末尾へ移す。
@@ -1,10 +1,10 @@
1
1
  import { joinTextblockBackward } from 'prosemirror-commands';
2
2
  import { NodeSelection, Selection, TextSelection } from 'prosemirror-state';
3
- import { MAX_HEADING_LEVEL } from '../../models/document/document.types';
4
- import { bodyCount, bodyIndex, bodyStart } from '../../models/document/bodySelection';
5
- import { outlineSchema } from '../../models/document/schema';
6
- import { sectionTree } from '../../models/document/sectionTree';
7
- import { moveContent, selectBlockAt, setCursor } from '../transaction';
3
+ import { MAX_HEADING_LEVEL } from '../../models/document/document.types.js';
4
+ import { bodyCount, bodyIndex, bodyStart } from '../../models/document/bodySelection.js';
5
+ import { outlineSchema } from '../../models/document/schema.js';
6
+ import { sectionTree } from '../../models/document/sectionTree.js';
7
+ import { moveContent, selectBlockAt, setCursor } from '../transaction.js';
8
8
  const n = outlineSchema.nodes;
9
9
  /**
10
10
  * 見出しを 1 段深くする。直前の兄弟セクションの中身の末尾へ移す。
@@ -1,6 +1,6 @@
1
1
  import type { Node } from 'prosemirror-model';
2
2
  import { type EditorState } from 'prosemirror-state';
3
- import { type HeadingLevel, type SectionPath } from '../../models/document/document.types';
3
+ import { type HeadingLevel, type SectionPath } from '../../models/document/document.types.js';
4
4
  import type { EditorCommand } from '../operations.types';
5
5
  export interface FoldCommands {
6
6
  /** カーソル位置の見出しまたは箇条書きの項目の折りたたみを反転する */
@@ -1,10 +1,10 @@
1
1
  import { isListNode } from 'prosemirror-flat-list';
2
2
  import { TextSelection } from 'prosemirror-state';
3
- import { hasFoldableChildren } from '../../models/document/foldable';
4
- import { MAX_HEADING_LEVEL } from '../../models/document/document.types';
5
- import { outlineSchema } from '../../models/document/schema';
6
- import { sectionTree } from '../../models/document/sectionTree';
7
- import { markOrigin } from '../transactionOrigin';
3
+ import { hasFoldableChildren } from '../../models/document/foldable.js';
4
+ import { MAX_HEADING_LEVEL } from '../../models/document/document.types.js';
5
+ import { outlineSchema } from '../../models/document/schema.js';
6
+ import { sectionTree } from '../../models/document/sectionTree.js';
7
+ import { markOrigin } from '../transactionOrigin.js';
8
8
  const SECTION = outlineSchema.nodes.section;
9
9
  export const foldCommands = {
10
10
  toggleFold,
@@ -1,6 +1,6 @@
1
1
  import { TextSelection } from 'prosemirror-state';
2
- import { outlineSchema } from '../../models/document/schema';
3
- import { sectionTree } from '../../models/document/sectionTree';
2
+ import { outlineSchema } from '../../models/document/schema.js';
3
+ import { sectionTree } from '../../models/document/sectionTree.js';
4
4
  const SECTION = outlineSchema.nodes.section;
5
5
  export const headingJump = {
6
6
  jumpToHeading,
@@ -1,7 +1,7 @@
1
1
  import { AllSelection, NodeSelection, TextSelection } from 'prosemirror-state';
2
- import { bodyStart } from '../../models/document/bodySelection';
3
- import { outlineSchema } from '../../models/document/schema';
4
- import { selectBlockAt } from '../transaction';
2
+ import { bodyStart } from '../../models/document/bodySelection.js';
3
+ import { outlineSchema } from '../../models/document/schema.js';
4
+ import { selectBlockAt } from '../transaction.js';
5
5
  export const requiredSelectionBlock = {
6
6
  isRequiredSelectionBlock,
7
7
  selectedBlock,
@@ -1,8 +1,8 @@
1
1
  import { GapCursor } from 'prosemirror-gapcursor';
2
2
  import { Selection, TextSelection } from 'prosemirror-state';
3
3
  import { addColumn, addRow, CellSelection, deleteTable, goToNextCell as goToAdjacentCell, isInTable, moveTableColumn, moveTableRow, nextCell, removeColumn, removeRow, selectedRect, selectionCell, TableMap } from 'prosemirror-tables';
4
- import { bodyStart } from '../../models/document/bodySelection';
5
- import { outlineSchema } from '../../models/document/schema';
4
+ import { bodyStart } from '../../models/document/bodySelection.js';
5
+ import { outlineSchema } from '../../models/document/schema.js';
6
6
  const n = outlineSchema.nodes;
7
7
  /** 見出し行は表の 0 行目である(`table_header` の有無では判定しない) */
8
8
  const HEADER_ROW = 0;
@@ -367,6 +367,9 @@ const canPlaceGapCursor = GapCursor.valid;
367
367
  * はじめてセル単位の選択へ移る。左右は文字の選択と同じ向きなので、これがないと
368
368
  * セルの中を選べなくなる。
369
369
  *
370
+ * **起点が表の外にある選択は、セル範囲にはならない**(要件 7.8 は「カーソルがセル内に
371
+ * あるとき」の規則である)。その選択では表を丸ごと覆う。
372
+ *
370
373
  * 編集基盤にも同じ割り当てがあるが、`goToCellInDirection` と同じ理由で発火しない
371
374
  * (端の判定が「セルがブロックを含む」前提の深さで行われる)。
372
375
  */
@@ -376,6 +379,12 @@ function extendSelectionToCell(direction) {
376
379
  return (state, dispatch, view) => {
377
380
  if (!isInTable(state))
378
381
  return false;
382
+ // 表の外から掛かってきた選択は、セル範囲へ移さず表を丸ごと覆う(→ `coveringTable`)
383
+ const covering = coveringTable(state);
384
+ if (covering) {
385
+ dispatch?.(state.tr.setSelection(covering).scrollIntoView());
386
+ return true;
387
+ }
379
388
  const current = cellSelectionToExtend(state, view, direction);
380
389
  if (!current)
381
390
  return false;
@@ -388,6 +397,38 @@ function extendSelectionToCell(direction) {
388
397
  return true;
389
398
  };
390
399
  }
400
+ /**
401
+ * 表の外から掛かってきた選択を、**表を丸ごと覆う形**にして返す。表の中だけの選択なら
402
+ * `null`(セル範囲の選択として扱う)。
403
+ *
404
+ * 起点を保ったままセル範囲へ移ろうとすると、セル範囲は表の中しか指せないため
405
+ * **表の外にあった起点が失われる**(選んでいた範囲が消える。利用者の指摘、2026-10-06)。
406
+ * 表は丸ごと選ぶブロックである(→ `selectedBlock.ts` の要選択ブロック)ため、
407
+ * 覆う先は起点から遠い側の端——上から来たなら表の後ろ、下から来たなら表の前——である。
408
+ */
409
+ function coveringTable(state) {
410
+ const { $anchor, $head, anchor } = state.selection;
411
+ const table = enclosingTable($head);
412
+ if (!table)
413
+ return null;
414
+ if (anchor > table.pos && anchor < table.pos + table.node.nodeSize)
415
+ return null;
416
+ // 行き先は表の外の文字の位置。表の中(最後のセルの末尾など)に置くと、もう一度
417
+ // 押しても同じ範囲になり、選択が表の先で伸びなくなる
418
+ const forward = anchor < table.pos;
419
+ const beyond = state.doc.resolve(forward ? table.pos + table.node.nodeSize : table.pos);
420
+ const outside = Selection.findFrom(beyond, forward ? 1 : -1, true);
421
+ return TextSelection.between($anchor, outside?.$head ?? beyond);
422
+ }
423
+ /** その位置を包む表。無ければ `null` */
424
+ function enclosingTable($pos) {
425
+ for (let depth = $pos.depth; depth > 0; depth -= 1) {
426
+ const node = $pos.node(depth);
427
+ if (node.type === n.table)
428
+ return { node, pos: $pos.before(depth) };
429
+ }
430
+ return null;
431
+ }
391
432
  /**
392
433
  * 広げる元になるセル範囲。すでにセル範囲を選んでいればそれ、カーソルがセルの中の
393
434
  * その向きの端にあれば、そのセル 1 つを覆う範囲。どちらでもなければ `null`。
@@ -0,0 +1,12 @@
1
+ import { type Node } from 'prosemirror-model';
2
+ import type { EditorState, Transaction } from 'prosemirror-state';
3
+ /**
4
+ * 変わった箇所ごとに置き換えを積んだ Transaction。差分が無ければ `null`。
5
+ *
6
+ * 全体を 1 範囲で置き換えないのは、あいだの一致する箇所まで作り直してしまうためである。
7
+ * 作り直すと、そこにあったカーソル・取り消しの手順の写し先・折りたたみが失われる。
8
+ *
9
+ * 表示だけの属性(折りたたみ)は、比較の前に当てる文書へ写す。写さないと、中身が同じ
10
+ * セクションも「違うノード」として数えられ、範囲がその部分木へ広がる。
11
+ */
12
+ export declare function diffTransaction(state: EditorState, next: Node): Transaction | null;