@14ch/svelte-md-outliner 0.0.16 → 0.0.18
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 +25 -0
- package/dist/components/EditorSurface.svelte +1 -36
- package/dist/components/EditorSurface.svelte.d.ts +0 -7
- package/dist/components/serverPlaceholder.d.ts +7 -0
- package/dist/components/serverPlaceholder.js +37 -0
- package/dist/models/markdown/serializer.js +42 -5
- package/dist/operations/plugins/tablePaste.js +8 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,31 @@ 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.18] - 2026-09-28
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Copying a deeply nested list item no longer carries its depth into the paste.
|
|
13
|
+
The levels that had held the copied items came along as empty bullets, so
|
|
14
|
+
pasting at the top of a document rebuilt the original nesting instead of
|
|
15
|
+
landing where the cursor was. A copy now starts from the item you selected,
|
|
16
|
+
keeping only the nesting between the copied items. Selecting from the
|
|
17
|
+
outermost item still copies the whole structure as before.
|
|
18
|
+
|
|
19
|
+
## [0.0.17] - 2026-09-25
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
- Text copied from a table's body cell can be pasted outside the table again.
|
|
24
|
+
The paste did nothing at all, while text copied from a header cell pasted
|
|
25
|
+
fine — which made it look as though body rows were special. Both behave the
|
|
26
|
+
same now.
|
|
27
|
+
- Indentation after a line break inside a table cell survives saving. Pressing
|
|
28
|
+
Shift+Enter in a cell and indenting the next line — the usual way to fake a
|
|
29
|
+
bulleted list inside a cell — lost those leading spaces every time the
|
|
30
|
+
document was written out. Whitespace at the very start and end of a cell is
|
|
31
|
+
still dropped, because a GFM table discards it and it cannot be written back.
|
|
32
|
+
|
|
8
33
|
## [0.0.16] - 2026-09-24
|
|
9
34
|
|
|
10
35
|
### Fixed
|
|
@@ -1,41 +1,6 @@
|
|
|
1
|
-
<script module lang="ts">
|
|
2
|
-
/**
|
|
3
|
-
* サーバー側で描画されたときの代わりの表示。
|
|
4
|
-
*
|
|
5
|
-
* `EditorView` はブラウザの DOM を必要とするため、サーバー側では編集機能が成立しない。
|
|
6
|
-
* ただし利用者はページ全体をサーバーで描画するため、ここを通ること自体は正常な使い方である。
|
|
7
|
-
* したがって「例外を投げない」だけでは足りず、動かないことに開発者が気づける必要がある。
|
|
8
|
-
*
|
|
9
|
-
* 警告は 1 プロセスにつき 1 度だけ出す。
|
|
10
|
-
*
|
|
11
|
-
* ここだけモジュールスコープの可変状態を許す。インスタンス間の干渉を防ぐという
|
|
12
|
-
* 制約の趣旨に照らし、ログ出力の抑制はエディタの振る舞いにも状態にも影響しないためである。
|
|
13
|
-
*/
|
|
14
|
-
let warned = false;
|
|
15
|
-
|
|
16
|
-
const MESSAGE = '[svelte-md-outliner] SSR/SSG ではエディタを初期化できません。';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* 代わりの表示であることを示す印を返す。編集の仕組みができていれば付けない。
|
|
20
|
-
*
|
|
21
|
-
* 判定を「描画される属性の値」として行うのは、そこが確実に評価される場所だからである
|
|
22
|
-
* (`<script>` に直に書いた文は、サーバー側の描画では実行されないことがある)。
|
|
23
|
-
*/
|
|
24
|
-
export function serverPlaceholderMark(hasSession: boolean): string | undefined {
|
|
25
|
-
if (hasSession) return undefined;
|
|
26
|
-
if (typeof document === 'undefined') warnOnce();
|
|
27
|
-
return 'true';
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function warnOnce(): void {
|
|
31
|
-
if (warned) return;
|
|
32
|
-
warned = true;
|
|
33
|
-
console.warn(MESSAGE);
|
|
34
|
-
}
|
|
35
|
-
</script>
|
|
36
|
-
|
|
37
1
|
<script lang="ts">
|
|
38
2
|
import { untrack } from 'svelte';
|
|
3
|
+
import { serverPlaceholderMark } from './serverPlaceholder';
|
|
39
4
|
import { createEditorSession } from '../states/editorSession';
|
|
40
5
|
import type {
|
|
41
6
|
EditorPresentation,
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 代わりの表示であることを示す印を返す。編集の仕組みができていれば付けない。
|
|
3
|
-
*
|
|
4
|
-
* 判定を「描画される属性の値」として行うのは、そこが確実に評価される場所だからである
|
|
5
|
-
* (`<script>` に直に書いた文は、サーバー側の描画では実行されないことがある)。
|
|
6
|
-
*/
|
|
7
|
-
export declare function serverPlaceholderMark(hasSession: boolean): string | undefined;
|
|
8
1
|
import type { EditorPresentation, EditorSession, EditorSessionOptions } from '../states/editorSession.types';
|
|
9
2
|
interface Props {
|
|
10
3
|
options: EditorSessionOptions;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* サーバー側で描画されたときの代わりの表示。
|
|
3
|
+
*
|
|
4
|
+
* `EditorView` はブラウザの DOM を必要とするため、サーバー側では編集機能が成立しない。
|
|
5
|
+
* ただし利用者はページ全体をサーバーで描画するため、ここを通ること自体は正常な使い方である。
|
|
6
|
+
* したがって「例外を投げない」だけでは足りず、動かないことに開発者が気づける必要がある。
|
|
7
|
+
*
|
|
8
|
+
* 警告は 1 プロセスにつき 1 度だけ出す。
|
|
9
|
+
*
|
|
10
|
+
* ここだけモジュールスコープの可変状態を許す。インスタンス間の干渉を防ぐという
|
|
11
|
+
* 制約の趣旨に照らし、ログ出力の抑制はエディタの振る舞いにも状態にも影響しないためである。
|
|
12
|
+
*
|
|
13
|
+
* **編集エリアの部品(`EditorSurface.svelte`)から切り出して、ここに置く。**
|
|
14
|
+
* 「1 プロセスに 1 度」を数え直すには読み込み直すしかなく、部品に置くと編集基盤
|
|
15
|
+
* まるごとを読み込み直すことになって、確認が実行時間で頭打ちになっていた。
|
|
16
|
+
*/
|
|
17
|
+
let warned = false;
|
|
18
|
+
const MESSAGE = '[svelte-md-outliner] SSR/SSG ではエディタを初期化できません。';
|
|
19
|
+
/**
|
|
20
|
+
* 代わりの表示であることを示す印を返す。編集の仕組みができていれば付けない。
|
|
21
|
+
*
|
|
22
|
+
* 判定を「描画される属性の値」として行うのは、そこが確実に評価される場所だからである
|
|
23
|
+
* (`<script>` に直に書いた文は、サーバー側の描画では実行されないことがある)。
|
|
24
|
+
*/
|
|
25
|
+
export function serverPlaceholderMark(hasSession) {
|
|
26
|
+
if (hasSession)
|
|
27
|
+
return undefined;
|
|
28
|
+
if (typeof document === 'undefined')
|
|
29
|
+
warnOnce();
|
|
30
|
+
return 'true';
|
|
31
|
+
}
|
|
32
|
+
function warnOnce() {
|
|
33
|
+
if (warned)
|
|
34
|
+
return;
|
|
35
|
+
warned = true;
|
|
36
|
+
console.warn(MESSAGE);
|
|
37
|
+
}
|
|
@@ -28,7 +28,35 @@ export function serializeSlice(slice) {
|
|
|
28
28
|
return line.type.spec.code ? line.textContent : writeLine(line);
|
|
29
29
|
}
|
|
30
30
|
// スライスは単体では文書として成立しないため、内容検証を伴わないコンテナへ載せる
|
|
31
|
-
return serializeMarkdown(n.doc.create(null, wrapTableRows(slice.content)));
|
|
31
|
+
return serializeMarkdown(n.doc.create(null, wrapTableRows(withoutCutItems(slice.content))));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 切り口に残った、**行を持たない項目**を取り除く。
|
|
35
|
+
*
|
|
36
|
+
* 深い項目を選ぶと、断片にはその項目を囲んでいた親の項目も入る。親の行(先頭の段落)は
|
|
37
|
+
* 選択の外なので切り落とされ、中身が入れ子の項目だけになった**抜け殻**が残る。そのまま
|
|
38
|
+
* 書き出すと記号だけが並び(`- - - 1-1-1`)、貼ると写した覚えのない空の項目ごと、
|
|
39
|
+
* もとの深さで入る(利用者の指摘、2026-09-26)。
|
|
40
|
+
*
|
|
41
|
+
* **写したのは選んだ項目であって、それを囲んでいた入れ物ではない。** 抜け殻を外すと、
|
|
42
|
+
* 書き出しは選んだ項目を頂点とする形になり、選んだ項目どうしの深さの関係だけが残る。
|
|
43
|
+
* 見出しが貼り先の深さへ付け替わるのと同じ考え方である(→ `markdownClipboard` の
|
|
44
|
+
* `relevel`)。
|
|
45
|
+
*
|
|
46
|
+
* **見るのは断片の先頭だけである。** 切り口は選択の始まりにしかなく、行を持つ項目に
|
|
47
|
+
* 行き当たった時点で、そこから先は選択の中にまるごと入っている。
|
|
48
|
+
*/
|
|
49
|
+
function withoutCutItems(content) {
|
|
50
|
+
const first = content.firstChild;
|
|
51
|
+
if (!first)
|
|
52
|
+
return content;
|
|
53
|
+
// セクションは行を持たない入れ物である。切り口は中にある
|
|
54
|
+
if (first.type === n.section || first.type === n.intro_section) {
|
|
55
|
+
return content.replaceChild(0, first.copy(withoutCutItems(first.content)));
|
|
56
|
+
}
|
|
57
|
+
if (first.type !== n.list || first.firstChild?.isTextblock)
|
|
58
|
+
return content;
|
|
59
|
+
return withoutCutItems(first.content).append(content.cut(first.nodeSize));
|
|
32
60
|
}
|
|
33
61
|
/**
|
|
34
62
|
* 選択が 1 つの行(テキストブロック)の中で完結しているなら、その行を返す。
|
|
@@ -118,7 +146,7 @@ function writeSections(parent, depth) {
|
|
|
118
146
|
flush();
|
|
119
147
|
const level = Math.min(depth, MAX_HEADING_LEVEL);
|
|
120
148
|
// タイトルが空の見出し(まだ書いていない見出し)では、記号の後ろに空白を残さない
|
|
121
|
-
const title = writeInline(child.content);
|
|
149
|
+
const title = writeInline(child.content).trim();
|
|
122
150
|
parts.push(title ? `${'#'.repeat(level)} ${title}` : '#'.repeat(level));
|
|
123
151
|
return;
|
|
124
152
|
}
|
|
@@ -133,16 +161,19 @@ function writeBlocks(content) {
|
|
|
133
161
|
.replace(/\n+$/, '');
|
|
134
162
|
}
|
|
135
163
|
function writeInline(content) {
|
|
136
|
-
return writeBlocks(Fragment.from(n.paragraph.create(null, content)))
|
|
164
|
+
return writeBlocks(Fragment.from(n.paragraph.create(null, content)));
|
|
137
165
|
}
|
|
138
166
|
/**
|
|
139
167
|
* 行(テキストブロック)の中身を書き出す。**改行の記法は行の側が決める**
|
|
140
168
|
* (→ スキーマの `htmlLineBreak`)。
|
|
169
|
+
*
|
|
170
|
+
* 行の前後の空白は落とす。**記法として書けないためである**——行頭の空白は読み込みで
|
|
171
|
+
* 捨てられ(段落は 3 つまで無視、表のマス目は前後を無条件に捨てる)、書いても戻らない。
|
|
141
172
|
*/
|
|
142
173
|
function writeLine(line) {
|
|
143
174
|
return line.type.spec.htmlLineBreak
|
|
144
175
|
? writeHtmlBreakLine(line.content)
|
|
145
|
-
: writeInline(line.content);
|
|
176
|
+
: writeInline(line.content).trim();
|
|
146
177
|
}
|
|
147
178
|
/**
|
|
148
179
|
* 改行を `<br>` で書く行。**改行で区切って、区切りごとに書き出す。**
|
|
@@ -150,6 +181,12 @@ function writeLine(line) {
|
|
|
150
181
|
* `hard_break` の書き出し(行末の `\`)へ回さないのは、行末が来ないためである——
|
|
151
182
|
* セルは 1 行で、続きは同じ行に並ぶ。区切って書けば、改行の次の文字が行頭に来ないことも
|
|
152
183
|
* そのまま表れる(行頭の記号のエスケープが要らない)。
|
|
184
|
+
*
|
|
185
|
+
* **落とす空白は、つないだ全体の前後だけである。** 区切りごとに落とすと、`<br>` の次の
|
|
186
|
+
* 行頭の空白まで消える。セルの中で改行して字下げする書き方(擬似的な箇条書き)が
|
|
187
|
+
* 保存で崩れていた(利用者の指摘、2026-09-25)。読み込みは `<br>` の前後の空白を
|
|
188
|
+
* そのまま保つので、**書ける空白を書かずに捨てていただけである。** 全体の前後だけは
|
|
189
|
+
* GFM の表が無条件に捨てるため、書いても戻らない。
|
|
153
190
|
*/
|
|
154
191
|
function writeHtmlBreakLine(content) {
|
|
155
192
|
const parts = [];
|
|
@@ -165,7 +202,7 @@ function writeHtmlBreakLine(content) {
|
|
|
165
202
|
pending.push(child);
|
|
166
203
|
});
|
|
167
204
|
flush();
|
|
168
|
-
return parts.join('<br>');
|
|
205
|
+
return parts.join('<br>').trim();
|
|
169
206
|
}
|
|
170
207
|
const serializeParagraph = (state, node) => {
|
|
171
208
|
state.renderInline(node);
|
|
@@ -29,6 +29,13 @@ export function tablePastePlugin() {
|
|
|
29
29
|
*
|
|
30
30
|
* 直すものが 1 つも無ければ、渡された文字列をそのまま返す。読み直して書き出すと、
|
|
31
31
|
* 直す必要の無い HTML まで別の文字列になる。
|
|
32
|
+
*
|
|
33
|
+
* **書き出す形は、受け取った形と同じ「中身の並び」にする。** 文書ごと書き出すと
|
|
34
|
+
* `<html>` で始まる文字列になり、実行環境がコピーの先頭へ付ける `<meta charset>` が
|
|
35
|
+
* `<head>` の中へ移る。編集基盤は**文字列の先頭の `<meta>` しか外さない**ため、外され
|
|
36
|
+
* ないまま残った `<meta>` が、読み込んだ入れ物の最初の要素になる。編集基盤はそこから
|
|
37
|
+
* `data-pm-slice` の包みの数だけ内側へ降りるので、表ではなく `<meta>` の中へ降り、
|
|
38
|
+
* **貼り付けた内容がまるごと消える**(利用者の指摘、2026-09-25)。
|
|
32
39
|
*/
|
|
33
40
|
function rewrite(html, view) {
|
|
34
41
|
const doc = new DOMParser().parseFromString(html, 'text/html');
|
|
@@ -48,7 +55,7 @@ function rewrite(html, view) {
|
|
|
48
55
|
cell.innerHTML = lines.join('<br>');
|
|
49
56
|
rewritten = true;
|
|
50
57
|
}
|
|
51
|
-
return rewritten ? doc.
|
|
58
|
+
return rewritten ? doc.head.innerHTML + doc.body.innerHTML : html;
|
|
52
59
|
}
|
|
53
60
|
/**
|
|
54
61
|
* 貼り先から、マス目の種別を決める。
|
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.18",
|
|
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.",
|