@14ch/svelte-md-outliner 0.0.11 → 0.0.13

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 CHANGED
@@ -5,6 +5,33 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.0.13] - 2026-09-19
9
+
10
+ ### Fixed
11
+
12
+ - Pasting into an empty line now replaces that line instead of leaving it above
13
+ the pasted content. An empty line is a line you have not written yet, and
14
+ pasting is writing there, so the leftover line had to be deleted by hand every
15
+ time. Empty paragraphs are not written out as Markdown, so this only showed up
16
+ on screen. Pasting plain text into an empty line is unchanged — the text simply
17
+ fills it.
18
+ - Pasted content that does not fit inside the line you are on is no longer
19
+ dropped. Pasting a heading into an empty list item that has children used to
20
+ discard the paste entirely; it is now placed after the outermost block.
21
+
22
+ ## [0.0.12] - 2026-09-18
23
+
24
+ ### Changed
25
+
26
+ - Outdenting a top-level list item now turns it into a paragraph where it
27
+ stands. The item used to move to the end of the list first, so the line you
28
+ pressed on jumped away from where you were reading. Turning a line into a
29
+ paragraph from the block-type menu has always left it in place and split the
30
+ list in two; outdenting now does the same. The list does split, and an ordered
31
+ list restarts its numbering after the paragraph — moving the paragraph out of
32
+ the run joins the list again. In exchange, Shift+Tab followed by Tab now
33
+ returns the line to where it was.
34
+
8
35
  ## [0.0.11] - 2026-09-17
9
36
 
10
37
  ### Fixed
@@ -109,11 +109,3 @@ export declare function correctItemDepth(state: EditorState): Transaction | null
109
109
  * **対象が項目であることの確かめ**だけである。
110
110
  */
111
111
  export declare function moveItemAcrossSection(direction: MoveDirection): EditorCommand;
112
- /**
113
- * `from` 以降で、連続する項目が終わるインデックス。
114
- *
115
- * **セクションの中身の末尾ではない。** 間に段落や表が挟まっていれば、そこで止まる。飛び越えると、
116
- * 書き手が見ている「このリスト」の外へ出てしまう。既存の `blockRunEnd` はブロック全体の
117
- * 連なりを返すもので種別を見ないため流用できない。
118
- */
119
- export declare function listRunEnd(parent: Node, from: number): number;
@@ -492,10 +492,15 @@ function indentList(state, dispatch) {
492
492
  /**
493
493
  * 項目を 1 段浅くする。最上位の項目では箇条書きを解除して段落に戻す。
494
494
  *
495
- * **持ち上げるのではなく移す。** 対象を元の親の配下すべての後ろへ出す。持ち上げる変換は
496
- * 文書の並び順を変えないため、対象の後ろに並んでいた兄弟が対象の配下へ取り込まれてしまう。
497
- * 書き手が触っていない項目の親子関係が黙って変わることになる。移り終えた時点で深さは
498
- * 1 段浅くなっているので、包み直しは要らない。
495
+ * **入れ子の項目は、持ち上げるのではなく移す。** 対象を元の親の配下すべての後ろへ出す。
496
+ * 持ち上げる変換は文書の並び順を変えないため、対象の後ろに並んでいた兄弟が対象の配下へ
497
+ * 取り込まれてしまう。書き手が触っていない項目の親子関係が黙って変わることになる。
498
+ * 移り終えた時点で深さは 1 段浅くなっているので、包み直しは要らない。
499
+ *
500
+ * **最上位の項目は、その場で解く。** 行き先が無いので動かす必要がない。リストは
501
+ * 押した行で 2 つに割れ、番号付きなら後半の連番は振り直される。それは
502
+ * 「この行を段落にする」(ブロック種別の変換)と同じ結果であり、**同じことをする 2 つの
503
+ * 操作が違う結果を出さない**。割れたリストは、段落を並びの外へ動かせばまた 1 つに戻る。
499
504
  *
500
505
  * 分岐は**親が項目かどうか**の 1 つだけである。折りたたみ・種別・空かどうかを
501
506
  * 分岐条件に持ち込まない。
@@ -512,7 +517,7 @@ function dedentList(state, dispatch) {
512
517
  items.push(range.parent.child(index));
513
518
  }
514
519
  const tr = state.tr;
515
- const at = moveContent(tr, range.start, range.end, nested ? afterParent(range) : afterRun(range));
520
+ const at = nested ? moveContent(tr, range.start, range.end, afterParent(range)) : range.start;
516
521
  if (!nested)
517
522
  unwrapItems(tr, at, items);
518
523
  // 覆った範囲の先頭からの隔たりを、移り先の同じ隔たりへ置き直す。覆っていない側まで
@@ -529,17 +534,8 @@ function dedentList(state, dispatch) {
529
534
  function afterParent(range) {
530
535
  return range.$from.after(range.depth);
531
536
  }
532
- /** 最上位の項目の行き先。連続する項目の並びの後ろ(→ `listRunEnd`) */
533
- function afterRun(range) {
534
- const runEnd = listRunEnd(range.parent, range.endIndex);
535
- let at = range.end;
536
- for (let index = range.endIndex; index < runEnd; index += 1) {
537
- at += range.parent.child(index).nodeSize;
538
- }
539
- return at;
540
- }
541
537
  /**
542
- * 移した項目を解いて段落へ戻す。配下は 1 段浅い項目として、その段落の後ろへ並ぶ。
538
+ * 項目を解いて段落へ戻す。配下は 1 段浅い項目として、その段落の後ろへ並ぶ。
543
539
  *
544
540
  * **後ろの項目から順に解く。** 前から解くと、後ろの項目の位置が解いた分だけずれる。
545
541
  */
@@ -570,19 +566,6 @@ function unwrappedOffset(items, offset) {
570
566
  }
571
567
  return unwrapped + rest;
572
568
  }
573
- /**
574
- * `from` 以降で、連続する項目が終わるインデックス。
575
- *
576
- * **セクションの中身の末尾ではない。** 間に段落や表が挟まっていれば、そこで止まる。飛び越えると、
577
- * 書き手が見ている「このリスト」の外へ出てしまう。既存の `blockRunEnd` はブロック全体の
578
- * 連なりを返すもので種別を見ないため流用できない。
579
- */
580
- export function listRunEnd(parent, from) {
581
- let index = from;
582
- while (index < parent.childCount && isListNode(parent.child(index)))
583
- index += 1;
584
- return index;
585
- }
586
569
  /** 選択が覆っている項目の範囲。覆ったかどうかの決め方は見出しと共通(→ `coveredEnd`) */
587
570
  function selectedListsRange(state) {
588
571
  const { $from } = state.selection;
@@ -18,6 +18,35 @@ const n = outlineSchema.nodes;
18
18
  */
19
19
  export function markdownClipboardPlugin() {
20
20
  return new Plugin({
21
+ /**
22
+ * 貼り付けたあと、カーソルがいた空行が空のまま残っていれば取り除く。
23
+ *
24
+ * 経路ごとに手当てしない。表を含む HTML・画像・記法として読めない内容は編集基盤の
25
+ * 既定の貼り付けへ譲るため、入口ごとに置くと漏れる。
26
+ */
27
+ appendTransaction(transactions, oldState, newState) {
28
+ if (!transactions.some((transaction) => transaction.getMeta('paste') === true))
29
+ return null;
30
+ const line = emptyLineAt(oldState);
31
+ if (!line)
32
+ return null;
33
+ const pos = transactions.reduce((at, transaction) => transaction.mapping.map(at), line.pos);
34
+ const left = newState.doc.nodeAt(pos);
35
+ // その行へ収まったか、何も入らなかったなら、取り除くものは無い
36
+ if (!left || !isEmptyLine(left) || newState.doc.eq(oldState.doc))
37
+ return null;
38
+ const $line = newState.doc.resolve(pos);
39
+ const container = $line.parent;
40
+ const tr = newState.tr;
41
+ // 見出しを持たないセクションは中身が空だと成立しない。空行しか残らないならセクションごと
42
+ if (container.type === n.intro_section && container.childCount === 1) {
43
+ tr.delete($line.before(), $line.before() + container.nodeSize);
44
+ }
45
+ else {
46
+ tr.delete(pos, pos + left.nodeSize);
47
+ }
48
+ return tr;
49
+ },
21
50
  props: {
22
51
  clipboardTextSerializer: (slice) => serializeSlice(slice),
23
52
  handlePaste: (view, event) => {
@@ -48,15 +77,17 @@ export function markdownClipboardPlugin() {
48
77
  return false;
49
78
  // 文書全体への貼り付けは**差し替え**である。メタデータごと入れ替わる
50
79
  if (view.state.selection instanceof AllSelection) {
51
- view.dispatch(replaceDocument(view.state, parsed.value.content).scrollIntoView());
80
+ const replaced = replaceDocument(view.state, parsed.value.content);
81
+ view.dispatch(replaced.setMeta('paste', true).scrollIntoView());
52
82
  return true;
53
83
  }
54
84
  const baseDepth = pasteDepth(view.state.doc, view.state.selection.from);
55
85
  const content = relevel(frontMatterAsCodeBlock(parsed.value.content), baseDepth);
56
86
  if (content.childCount === 0)
57
87
  return false;
58
- const transaction = intoEmptyItem(view.state, content) ?? view.state.tr.replaceSelection(pasted(content));
59
- view.dispatch(transaction.scrollIntoView());
88
+ const transaction = intoEmptyItem(view.state, content) ?? intoSelection(view.state, content);
89
+ // 空行の後始末(`appendTransaction`)が見る印
90
+ view.dispatch(transaction.setMeta('paste', true).scrollIntoView());
60
91
  return true;
61
92
  }
62
93
  }
@@ -134,6 +165,55 @@ function intoEmptyItem(state, content) {
134
165
  tr.setSelection(TextSelection.near(tr.doc.resolve(Math.min(end, tr.doc.content.size)), -1));
135
166
  return tr;
136
167
  }
168
+ /**
169
+ * 既定の置き換え。入らなかったときは、いちばん外側のブロックの後ろへ置く。
170
+ *
171
+ * 編集基盤の当てはめは、貼り先のどこにも収まらない内容を黙って捨てる。文字を失わない
172
+ * ことを優先する(要件 10.18)。
173
+ */
174
+ function intoSelection(state, content) {
175
+ const tr = state.tr.replaceSelection(pasted(content));
176
+ if (tr.docChanged)
177
+ return tr;
178
+ const $from = state.selection.$from;
179
+ let depth = $from.depth;
180
+ while (depth > 0 && !isLineContainer($from.node(depth - 1)))
181
+ depth -= 1;
182
+ const after = $from.after(depth);
183
+ tr.replaceRange(after, after, pasted(content));
184
+ tr.setSelection(TextSelection.near(tr.doc.resolve(Math.min(after, tr.doc.content.size)), 1));
185
+ return tr;
186
+ }
187
+ /** セクションの中身を直に持つコンテナか */
188
+ function isLineContainer(node) {
189
+ return node.type === n.section || node.type === n.intro_section;
190
+ }
191
+ /**
192
+ * カーソルがいる空行。段落ならその段落、項目の本文なら項目そのものである。
193
+ * 配下を持つ項目は除く(取り除くと配下ごと消える)。
194
+ */
195
+ function emptyLineAt(state) {
196
+ const cursor = state.selection instanceof TextSelection ? state.selection.$cursor : null;
197
+ if (!cursor || cursor.parent.type !== n.paragraph || cursor.parent.content.size > 0)
198
+ return null;
199
+ const depth = cursor.depth - 1;
200
+ const container = cursor.node(depth);
201
+ if (container.type === n.list) {
202
+ const childless = container.childCount === 1 && cursor.index(depth) === 0;
203
+ return childless ? { node: container, pos: cursor.before(depth) } : null;
204
+ }
205
+ if (container.type !== n.section && container.type !== n.intro_section)
206
+ return null;
207
+ return { node: cursor.parent, pos: cursor.before(cursor.depth) };
208
+ }
209
+ /** 何も書かれていない行か(空の段落、または本文が空で配下を持たない項目) */
210
+ function isEmptyLine(node) {
211
+ if (node.type === n.paragraph)
212
+ return node.content.size === 0;
213
+ if (node.type !== n.list)
214
+ return false;
215
+ return node.childCount === 1 && node.child(0).content.size === 0;
216
+ }
137
217
  /**
138
218
  * 空の項目を置き換える中身。
139
219
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@14ch/svelte-md-outliner",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
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.",