@14ch/svelte-md-outliner 0.0.1 → 0.0.2

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 ADDED
@@ -0,0 +1,42 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.0.2] - 2026-09-01
9
+
10
+ ### Added
11
+
12
+ - Tables: `Shift+Enter` inserts a line break inside a cell. It is written as
13
+ `<br>` in Markdown and read back as a line break.
14
+
15
+ ### Fixed
16
+
17
+ - You can now write below a table, quote, code block or Mermaid block that sits
18
+ at the end of the document (and above one that starts the document). Pressing
19
+ the down arrow from the end of such a block puts the cursor outside it, and
20
+ typing there creates a paragraph.
21
+ - The context menu's fold entry no longer folds an outer section. It is offered
22
+ only when the item the menu points at can itself be folded (a heading or a
23
+ list item), not when the cursor is in a paragraph, table, code block or quote.
24
+ The keyboard shortcut is unchanged.
25
+ - In the context menu, hovering an item with the pointer no longer makes it the
26
+ target of `Enter`. Only an item chosen with the arrow keys is activated.
27
+
28
+ ## [0.0.1] - 2026-08-30
29
+
30
+ ### Added
31
+
32
+ - Initial release of `@14ch/svelte-md-outliner`.
33
+ - `MarkdownEditor` component: an outline editor where headings form a real
34
+ nested hierarchy you can fold, focus, and re-nest from the keyboard.
35
+ - Markdown input rules for headings, lists, task lists, quotes, emphasis and
36
+ inline code, applied as you type.
37
+ - Tables, Mermaid diagrams and front matter.
38
+ - Built-in context menu and shortcut sheet, both of which can be turned off.
39
+ - Replaceable strings (English and Japanese bundled) and a theme exposed as CSS
40
+ custom properties.
41
+ - `@14ch/svelte-md-outliner/markdown`: read and write front matter, body blocks
42
+ and plain text without mounting an editor.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 iyodatakashi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.ja.md CHANGED
@@ -187,4 +187,4 @@ npm run lint # 整形と静的解析
187
187
 
188
188
  ## ライセンス
189
189
 
190
- MIT
190
+ [MIT](LICENSE)
package/README.md CHANGED
@@ -187,4 +187,4 @@ Specifications live in `.kiro/specs/`, conventions in `.kiro/steering/` (Japanes
187
187
 
188
188
  ## License
189
189
 
190
- MIT
190
+ [MIT](LICENSE)
@@ -1425,10 +1425,31 @@
1425
1425
 
1426
1426
  /* --- 表や区切りの前後に立つカーソル --- */
1427
1427
 
1428
+ /**
1429
+ * 文字の入らない選択(前後に立つカーソル・ブロックを指した状態)のあいだは、
1430
+ * **実行環境が描くカーソルと選択の敷き色を出さない。**
1431
+ *
1432
+ * 編集基盤は `ProseMirror-hideselection` を付けるだけで、見た目は同梱の CSS が持つ。
1433
+ * 読み込ませない方針のため、本体の規則をここに置く(置かなければ、表の下に立てた
1434
+ * カーソルの傍らに実行環境のカーソルが並んで点滅する)。
1435
+ */
1436
+ .markdown-editor__surface.ProseMirror-hideselection {
1437
+ caret-color: transparent;
1438
+ }
1439
+
1440
+ .markdown-editor__surface.ProseMirror-hideselection *::selection {
1441
+ background: transparent;
1442
+ }
1443
+
1428
1444
  /**
1429
1445
  * 編集基盤は印を中身のない `div` として置くだけで、見た目を一切持たない。
1430
1446
  * 同梱の CSS を読み込ませない方針のため、本体の規則をここに置く
1431
1447
  * (置かなければ、表の前後へカーソルを移しても画面には何も出ない)。
1448
+ *
1449
+ * **文字を打つときのカーソルと同じ見た目にする。** 同梱の CSS は横棒で描くが、
1450
+ * 書き手から見てこれは「次に打つ場所」であって、別の何かではない。横棒だと
1451
+ * 区切り線のように見え、点滅する意味も読み取れない(利用者の報告、2026-09-01)。
1452
+ * 太さ・色・点滅を実行環境のカーソルに合わせ、高さは 1 行ぶんにする。
1432
1453
  */
1433
1454
  .markdown-editor__surface .ProseMirror-gapcursor {
1434
1455
  display: block;
@@ -1440,9 +1461,9 @@
1440
1461
  content: '';
1441
1462
  display: block;
1442
1463
  position: absolute;
1443
- top: -2px;
1444
- width: 1.5em;
1445
- border-top: 2px solid var(--markdown-editor-gapcursor-color);
1464
+ top: 0;
1465
+ height: 1.2em;
1466
+ border-left: 1px solid var(--markdown-editor-gapcursor-color);
1446
1467
  animation: markdown-editor-gapcursor-blink 1.1s steps(2, start) infinite;
1447
1468
  }
1448
1469
 
@@ -139,7 +139,14 @@
139
139
  </li>
140
140
  {#each group.items as item (item.action.id)}
141
141
  <li class="markdown-editor-context-menu__row">
142
- <!-- 実行できない操作はそもそも並ばない(無効として残さない) -->
142
+ <!--
143
+ 実行できない操作はそもそも並ばない(無効として残さない)。
144
+
145
+ **ポインタを乗せただけでは選ばない。** 押せば実行できるので、乗せることが
146
+ 決定の対象になる必要はない。メニューは押した位置に開くため、乗せた項目を
147
+ 選ぶ形にすると、**ポインタを動かしていないのにその項目が決定の対象になる**
148
+ (キーで開いた直後にそのまま `Enter` を押すと、選んだ覚えのない操作が走る)。
149
+ -->
143
150
  <button
144
151
  bind:this={itemRefs[item.index]}
145
152
  type="button"
@@ -150,7 +157,6 @@
150
157
  class:markdown-editor-context-menu__item--active={item.index ===
151
158
  controller.activeIndex}
152
159
  onclick={() => execute(item.action)}
153
- onmouseenter={() => controller.setActive(item.index)}
154
160
  onfocus={() => controller.setActive(item.index)}
155
161
  >
156
162
  <span class="markdown-editor-context-menu__description">{item.description}</span>
@@ -248,9 +254,12 @@
248
254
  }
249
255
 
250
256
  /**
251
- * **乗っている項目と選んでいる項目は同じ見え方にする。**
257
+ * **乗っている項目と選んでいる項目は同じ敷き色にする。**
252
258
  * ポインタで乗ることとキーで選ぶことは同じ「いまこれ」であり、2 通りに見せない。
253
259
  * 触れる入力しかない環境では `:hover` が居座るため、囲って外す。
260
+ *
261
+ * 決定(`Enter`)の対象になるのはキーで選んだ方だけである。そちらは実フォーカスを
262
+ * 持つため輪郭が付き(下の `:focus-visible`)、両方が見えていても見分けられる。
254
263
  */
255
264
  @media (hover: hover) {
256
265
  .markdown-editor-context-menu__item:hover,
@@ -66,7 +66,7 @@ export const en = {
66
66
  'editing.dissolveHeading': 'At the start of a heading, drop it and join the section above',
67
67
  'editing.insertHeadingBefore': 'At the start of a heading, insert an empty heading above it',
68
68
  'editing.insertSectionAfter': 'Add an empty heading below the section you are in',
69
- 'editing.insertLineBreak': 'Break the line without starting a new paragraph (not in headings or tables)',
69
+ 'editing.insertLineBreak': 'Break the line without starting a new paragraph (not in headings)',
70
70
  'format.toggleTask': 'Toggle task done',
71
71
  'format.bold': 'Bold',
72
72
  'format.italic': 'Italic',
@@ -71,7 +71,7 @@ export const ja = {
71
71
  'editing.dissolveHeading': '見出しの先頭で押すと、見出しをやめて前のセクションへ繋げる',
72
72
  'editing.insertHeadingBefore': '見出しの先頭で押すと、空の見出しを上に足す',
73
73
  'editing.insertSectionAfter': 'いまいるセクションの下に、空の見出しを足す',
74
- 'editing.insertLineBreak': '段落を分けずに改行する(見出し・表の中ではできない)',
74
+ 'editing.insertLineBreak': '段落を分けずに改行する(見出しの中ではできない)',
75
75
  'format.toggleTask': 'チェックの切り替え',
76
76
  'format.bold': '強調',
77
77
  'format.italic': '斜体',
@@ -14,6 +14,13 @@ import { MAX_HEADING_LEVEL, MIN_HEADING_LEVEL } from './document.types';
14
14
  * 印は描画にも読み書きにも現れない。`toDOM` / `parseDOM` とマークダウンの入出力は
15
15
  * 印の有無で変わらない。
16
16
  */
17
+ /**
18
+ * `htmlLineBreak` は**段落内改行を `<br>` で書くノードの印**である。表のセルに付く。
19
+ *
20
+ * マークダウンでは改行の書き方がブロックによって違う。段落は行末の `\` で書けるが、
21
+ * パイプ表のセルは 1 行で、`<br>` 以外に書く形が無い。印を読み書きの両方から見ることで、
22
+ * **書き出しと読み込みが同じ記法を指す**(→ `serializer.ts` / `parser.ts`)。
23
+ */
17
24
  /**
18
25
  * 見出しどうしが作る階層を入れ子の `section` として表す。
19
26
  *
@@ -78,6 +85,17 @@ const structureNodes = {
78
85
  parseDOM: [{ tag: 'div.markdown-editor__intro-section' }]
79
86
  },
80
87
  /**
88
+ * `allowGapCursor` は**要選択ブロックの前後にカーソルの置き場所を作るための指定**である。
89
+ *
90
+ * 既定の判定は「次に来る既定の種別がテキストブロックなら置いてよい」であり、
91
+ * `heading block* section*` では既定の種別が `section` になるため、**セクションの中には
92
+ * 置き場所が 1 つもできない**。文書の末尾が表・コードブロックのとき、その下に書く
93
+ * 手段が無くなる(見出しを持たない `intro_section` は `block+` なので既定の種別が段落
94
+ * になり、そこだけ置けていた)。
95
+ *
96
+ * 明示しても、置き場所ができるのは前後が閉じている位置だけである(→ `createGapCursor`)。
97
+ * 段落と段落のあいだのような、文字を打てる位置が既にあるところには現れない。
98
+ *
81
99
  * `collapsed` は「今どう見ているか」であって「何が書かれているか」ではない。
82
100
  * 属性として持つのは、移動・複製・削除・取り消しにノードごと追随させるためである
83
101
  * (書き出しには現れない。シリアライザは属性を読まない)。
@@ -87,6 +105,7 @@ const structureNodes = {
87
105
  */
88
106
  section: {
89
107
  content: 'heading block* section*',
108
+ allowGapCursor: true,
90
109
  defining: true,
91
110
  attrs: { collapsed: { default: false } },
92
111
  toDOM: (node) => [
@@ -141,9 +160,9 @@ const blockNodes = {
141
160
  *
142
161
  * 中身を `text*` に絞るのは、**見出しに段落内改行を置かせない**ためである。
143
162
  * ATX 見出し(`# ...`)はマークダウンでは 1 行のブロックで、行末の空白 2 つも `\` も
144
- * 改行にならない。書ける手段は生の `<br>` だけであり、このエディタはインラインの HTML を
145
- * 解釈せず文字として残すため、往復で `<br>` という文字列に化ける。
146
- * 見出しの文字列はパンくず・折りたたみの見出しとしても 1 行で出る(→ `hard_break`)。
163
+ * 改行にならない。書ける手段は生の `<br>` だけだが、見出しの文字列はパンくず・
164
+ * 折りたたみの見出しとしても出る**1 行のもの**であり、改行を入れる場所ではない。
165
+ * 解釈せず文字として残すため、書けば往復で `<br>` という文字列のまま残る(→ `hard_break`)。
147
166
  */
148
167
  heading: {
149
168
  content: 'text*',
@@ -200,9 +219,17 @@ const blockNodes = {
200
219
  priority: 60
201
220
  }))
202
221
  },
222
+ /**
223
+ * `createGapCursor` は**このブロックの前後を「閉じている」と見なさせる指定**である。
224
+ * 編集基盤は隣が文字を持つブロックなら閉じていないと判断し、置き場所を作らない。
225
+ * 中身が文字(コードブロック・Mermaid)や段落(引用)であるブロックはこれに当たり、
226
+ * 文書の末尾に来ると**その下に書く手段が無くなる**。表は編集基盤が最初から閉じたもの
227
+ * として扱うため(`isolating`)、指定が要らない。
228
+ */
203
229
  blockquote: {
204
230
  content: 'block+',
205
231
  group: 'block',
232
+ createGapCursor: true,
206
233
  defining: true,
207
234
  requiredSelectionBlock: true,
208
235
  toDOM: () => ['blockquote', { class: 'markdown-editor__blockquote' }, 0],
@@ -212,6 +239,7 @@ const blockNodes = {
212
239
  content: 'text*',
213
240
  group: 'block',
214
241
  code: true,
242
+ createGapCursor: true,
215
243
  defining: true,
216
244
  requiredSelectionBlock: true,
217
245
  marks: '',
@@ -242,6 +270,7 @@ const blockNodes = {
242
270
  content: 'text*',
243
271
  group: 'block',
244
272
  code: true,
273
+ createGapCursor: true,
245
274
  defining: true,
246
275
  requiredSelectionBlock: true,
247
276
  marks: '',
@@ -289,8 +318,10 @@ const blockNodes = {
289
318
  * 消え、差分にも現れないためである。改行が黙って失われる書き方は選ばない。
290
319
  *
291
320
  * 置ける場所は**インラインを持つブロックのうち、`content` が `inline*` のもの**、
292
- * つまり段落だけである。見出しと表のセルは `text*` に絞ってあり、構造として入らない
293
- * (どちらもマークダウンでは 1 行のブロックで、`<br>` 以外に書く手段が無い)。
321
+ * つまり段落と表のセルである。**書き方はブロックによって違う**——段落は行末の `\`、
322
+ * セルは `<br>`(パイプ表のセルは 1 行で、他に書く形が無い → `htmlLineBreak`)。
323
+ *
324
+ * 見出しだけは `text*` に絞ってあり、構造として入らない。
294
325
  */
295
326
  hard_break: {
296
327
  inline: true,
@@ -304,9 +335,8 @@ const blockNodes = {
304
335
  };
305
336
  const tableNodeSpecs = tableNodes({
306
337
  tableGroup: 'block',
307
- // セル内は文字のみ。ブロック要素も段落内改行もスキーマ段階で拒否する
308
- // (パイプ表のセルは 1 行で、改行を `<br>` 以外に書けない → `hard_break`)
309
- cellContent: 'text*',
338
+ // セル内はインラインのみ。ブロック要素はスキーマ段階で拒否する
339
+ cellContent: 'inline*',
310
340
  cellAttributes: {
311
341
  // 列の配置指定。マークダウンの `|:--|--:|` と往復させるために保持する
312
342
  align: {
@@ -333,7 +363,9 @@ const tableNodeSpecs = tableNodes({
333
363
  const tableSpec = {
334
364
  ...tableNodeSpecs,
335
365
  table: { ...tableNodeSpecs.table, requiredSelectionBlock: true },
336
- table_row: { ...tableNodeSpecs.table_row, allowGapCursor: false }
366
+ table_row: { ...tableNodeSpecs.table_row, allowGapCursor: false },
367
+ table_cell: { ...tableNodeSpecs.table_cell, htmlLineBreak: true },
368
+ table_header: { ...tableNodeSpecs.table_header, htmlLineBreak: true }
337
369
  };
338
370
  const marks = {
339
371
  link: {
@@ -19,6 +19,8 @@ const TASK_MARKER = /^\[([ xX])\](\s+|$)/;
19
19
  * (`C:\path` のような素のバックスラッシュを拾わない)。
20
20
  */
21
21
  const ESCAPE_IN_SOURCE = /\\[!-/:-@[-`{-~]/;
22
+ /** 改行として書かれた `<br>`(→ スキーマの `htmlLineBreak`) */
23
+ const BR_TAG = /^<br\s*\/?>$/i;
22
24
  export function parseMarkdown(markdown) {
23
25
  try {
24
26
  const { content, body } = splitFrontMatter(markdown);
@@ -334,7 +336,8 @@ function alignOf(token) {
334
336
  }
335
337
  // --- インライン ---
336
338
  /**
337
- * 段落内改行を置けるかは**行き先のノードに聞く**(見出しと表のセルは置けない)。
339
+ * 段落内改行を置けるかは**行き先のノードに聞く**(見出しには置けない)。書かれ方も
340
+ * 行き先に聞く——表のセルの改行は `<br>` である(→ スキーマの `htmlLineBreak`)。
338
341
  * 規則をスキーマだけが持つことで、置ける場所を変えたときに読み込み側が取り残されない。
339
342
  * 置けない場所では、読めなくなるより繋がる方を採り、空白へ畳む。
340
343
  */
@@ -342,6 +345,7 @@ function parseInline(inline, into) {
342
345
  const tokens = inline?.children ?? [];
343
346
  const nodes = [];
344
347
  const lineBreak = into.contentMatch.matchType(n.hard_break) !== null;
348
+ const htmlLineBreak = lineBreak && into.spec.htmlLineBreak === true;
345
349
  const insideHtml = htmlElementContent(tokens, inline?.content ?? '');
346
350
  let marks = Mark.none;
347
351
  const push = (text) => {
@@ -414,8 +418,18 @@ function parseInline(inline, into) {
414
418
  case 'footnote_ref':
415
419
  pushVerbatim(token.content, m.footnote.create());
416
420
  break;
421
+ /**
422
+ * `<br>` を改行として読むのは、**改行を `<br>` で書く行の中だけ**である。
423
+ * 段落では書き手が書いた HTML のまま残す(段落の改行は `\` で書かれる)。
424
+ */
425
+ case 'html_inline':
426
+ if (htmlLineBreak && BR_TAG.test(token.content))
427
+ nodes.push(n.hard_break.create());
428
+ else
429
+ pushVerbatim(token.content);
430
+ break;
417
431
  default:
418
- // html_inline を含む、表現を持たない記法すべて。**記法の名前で分岐しない**
432
+ // 表現を持たない記法すべて。**記法の名前で分岐しない**
419
433
  pushVerbatim(token.content);
420
434
  break;
421
435
  }
@@ -25,7 +25,7 @@ export function serializeSlice(slice) {
25
25
  const line = partialLine(slice);
26
26
  if (line) {
27
27
  // コードブロックは記法を持たない。書き出しのエスケープ(`\*` など)も入れずに素の文字を返す
28
- return line.type.spec.code ? line.textContent : writeInline(line.content);
28
+ return line.type.spec.code ? line.textContent : writeLine(line);
29
29
  }
30
30
  // スライスは単体では文書として成立しないため、内容検証を伴わないコンテナへ載せる
31
31
  return serializeMarkdown(n.doc.create(null, wrapTableRows(slice.content)));
@@ -135,6 +135,38 @@ function writeBlocks(content) {
135
135
  function writeInline(content) {
136
136
  return writeBlocks(Fragment.from(n.paragraph.create(null, content))).trim();
137
137
  }
138
+ /**
139
+ * 行(テキストブロック)の中身を書き出す。**改行の記法は行の側が決める**
140
+ * (→ スキーマの `htmlLineBreak`)。
141
+ */
142
+ function writeLine(line) {
143
+ return line.type.spec.htmlLineBreak
144
+ ? writeHtmlBreakLine(line.content)
145
+ : writeInline(line.content);
146
+ }
147
+ /**
148
+ * 改行を `<br>` で書く行。**改行で区切って、区切りごとに書き出す。**
149
+ *
150
+ * `hard_break` の書き出し(行末の `\`)へ回さないのは、行末が来ないためである——
151
+ * セルは 1 行で、続きは同じ行に並ぶ。区切って書けば、改行の次の文字が行頭に来ないことも
152
+ * そのまま表れる(行頭の記号のエスケープが要らない)。
153
+ */
154
+ function writeHtmlBreakLine(content) {
155
+ const parts = [];
156
+ let pending = [];
157
+ const flush = () => {
158
+ parts.push(writeInline(Fragment.fromArray(pending)));
159
+ pending = [];
160
+ };
161
+ content.forEach((child) => {
162
+ if (child.type === n.hard_break)
163
+ flush();
164
+ else
165
+ pending.push(child);
166
+ });
167
+ flush();
168
+ return parts.join('<br>');
169
+ }
138
170
  const serializeParagraph = (state, node) => {
139
171
  state.renderInline(node);
140
172
  state.closeBlock(node);
@@ -263,7 +295,7 @@ const serializeTable = (state, node) => {
263
295
  node.forEach((row, _offset, rowIndex) => {
264
296
  const cells = [];
265
297
  row.forEach((cell) => {
266
- cells.push(escapeCell(writeInline(cell.content)));
298
+ cells.push(escapeCell(writeLine(cell)));
267
299
  if (rowIndex === 0)
268
300
  aligns.push(cell.attrs.align);
269
301
  });
@@ -2,8 +2,8 @@ import type { EditorCommand } from '../operations.types';
2
2
  /**
3
3
  * 段落を分けずに改行する。
4
4
  *
5
- * 置けるかどうかはスキーマに聞き、種別で判定しない。見出しと表のセルは中身が `text*` で
6
- * あるため、ここで名前を並べなくても偽が返る(→ スキーマの `hard_break`)。判定を
7
- * 二重に持たないことで、置ける場所を増やしたときに直し忘れが起きない。
5
+ * 置けるかどうかはスキーマに聞き、種別で判定しない。見出しは中身が `text*` であるため、
6
+ * ここで名前を並べなくても偽が返る(→ スキーマの `hard_break`)。判定を二重に持たない
7
+ * ことで、置ける場所を増やしたときに直し忘れが起きない。
8
8
  */
9
9
  export declare const insertLineBreak: EditorCommand;
@@ -2,9 +2,9 @@ import { outlineSchema } from '../../models/document/schema';
2
2
  /**
3
3
  * 段落を分けずに改行する。
4
4
  *
5
- * 置けるかどうかはスキーマに聞き、種別で判定しない。見出しと表のセルは中身が `text*` で
6
- * あるため、ここで名前を並べなくても偽が返る(→ スキーマの `hard_break`)。判定を
7
- * 二重に持たないことで、置ける場所を増やしたときに直し忘れが起きない。
5
+ * 置けるかどうかはスキーマに聞き、種別で判定しない。見出しは中身が `text*` であるため、
6
+ * ここで名前を並べなくても偽が返る(→ スキーマの `hard_break`)。判定を二重に持たない
7
+ * ことで、置ける場所を増やしたときに直し忘れが起きない。
8
8
  */
9
9
  export const insertLineBreak = (state, dispatch) => {
10
10
  const { $from } = state.selection;
@@ -365,8 +365,8 @@ export const coreActions = [
365
365
  /**
366
366
  * 段落を分けずに改行する。`Shift+Enter` は多くのエディタでこの意味を持つ。
367
367
  *
368
- * 置けない場所(見出し・表のセル)では偽を返し、何も起きない。同じキーへ別の意味を
369
- * 用意しないのは、キーの意味を場所ごとに覚えることになるためである。
368
+ * 置けない場所(見出し)では偽を返し、何も起きない。同じキーへ別の意味を用意しない
369
+ * のは、キーの意味を場所ごとに覚えることになるためである。
370
370
  */
371
371
  {
372
372
  id: 'editing.insertLineBreak',
@@ -1,3 +1,4 @@
1
+ import { sectionCommands } from '../commands/element';
1
2
  import { targetSection } from '../commands/section';
2
3
  import { foldCommands } from '../commands/sectionFold';
3
4
  import { headingJump } from '../commands/sectionJump';
@@ -28,7 +29,20 @@ export function createViewActions(focus, toggleShortcutHelp) {
28
29
  changesDocument: false,
29
30
  keys: [{ key: '.', mod: true }],
30
31
  command: foldCommands.toggleFold,
31
- variantId: (state) => foldCommands.isFolded(state) ? 'view.toggleFold.unfold' : 'view.toggleFold.fold'
32
+ /**
33
+ * 折りたたみはサブツリー単位の操作。**印を付けた対象そのものが畳めるとき
34
+ * だけ出す**(見出しと、子を持つ項目)。段落・表・コードブロックの中から
35
+ * 出すと、メニューが指しているアイテムではなく外側のセクションが畳まれ、
36
+ * **印を付けた当のアイテムごと隠れる**。要選択ブロックの中で外側への操作を
37
+ * 出さない規則(→ `coreActions.ts` の `unpointedRequiredSelectionTarget`)
38
+ * とも食い違っていた。キーは従来どおりどこからでも働く
39
+ * (→ `view.focusSection` と同じ扱い)。
40
+ */
41
+ variantId: (state) => {
42
+ if (!foldsPointedItem(state))
43
+ return null;
44
+ return foldCommands.isFolded(state) ? 'view.toggleFold.unfold' : 'view.toggleFold.fold';
45
+ }
32
46
  },
33
47
  // `,` は `<`、`.` は `>` の位置にあり、閉じる・開くの向きとして読める
34
48
  {
@@ -177,6 +191,16 @@ export function createContextMenuShortcut(toggleContextMenu) {
177
191
  }
178
192
  ];
179
193
  }
194
+ /**
195
+ * メニューが指しているアイテムが、そのまま折りたたみの対象になるか。
196
+ *
197
+ * 折りたたみの対象は見出し(セクション)と箇条書きの項目だけである。畳めるかどうか
198
+ * (子を持つか)は実行の可否として別に判定される(→ `menuGroupsFor` の試し実行)。
199
+ */
200
+ function foldsPointedItem(state) {
201
+ const kind = sectionCommands.targetElement(state)?.kind;
202
+ return kind === 'section' || kind === 'listItem';
203
+ }
180
204
  function levels() {
181
205
  return Array.from({ length: MAX_HEADING_LEVEL }, (_, index) => (index + 1));
182
206
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@14ch/svelte-md-outliner",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
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.",
@@ -22,12 +22,17 @@
22
22
  "type": "git",
23
23
  "url": "git+https://github.com/iyodatakashi/svelte-md-outliner.git"
24
24
  },
25
+ "homepage": "https://github.com/iyodatakashi/svelte-md-outliner#readme",
26
+ "bugs": {
27
+ "url": "https://github.com/iyodatakashi/svelte-md-outliner/issues"
28
+ },
25
29
  "publishConfig": {
26
30
  "access": "public"
27
31
  },
28
32
  "files": [
29
33
  "dist",
30
34
  "README.ja.md",
35
+ "CHANGELOG.md",
31
36
  "!dist/**/*.test.*",
32
37
  "!dist/**/*.spec.*"
33
38
  ],