@14ch/svelte-md-outliner 0.0.12 → 0.0.14
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 +26 -0
- package/dist/operations/plugins/markdownClipboard.js +91 -24
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,32 @@ 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.14] - 2026-09-19
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Pasting Markdown that carries front matter now replaces the document's front
|
|
13
|
+
matter with it. The pasted front matter used to land in the body as a `yaml`
|
|
14
|
+
code block, leaving the document's own metadata untouched — so copying a whole
|
|
15
|
+
document into a new one meant deleting that block and moving its lines into the
|
|
16
|
+
metadata by hand every time. Content pasted without front matter (or with an
|
|
17
|
+
empty one) leaves the document's metadata alone, and the result now matches
|
|
18
|
+
what you get when pasting over a full selection.
|
|
19
|
+
|
|
20
|
+
## [0.0.13] - 2026-09-19
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- Pasting into an empty line now replaces that line instead of leaving it above
|
|
25
|
+
the pasted content. An empty line is a line you have not written yet, and
|
|
26
|
+
pasting is writing there, so the leftover line had to be deleted by hand every
|
|
27
|
+
time. Empty paragraphs are not written out as Markdown, so this only showed up
|
|
28
|
+
on screen. Pasting plain text into an empty line is unchanged — the text simply
|
|
29
|
+
fills it.
|
|
30
|
+
- Pasted content that does not fit inside the line you are on is no longer
|
|
31
|
+
dropped. Pasting a heading into an empty list item that has children used to
|
|
32
|
+
discard the paste entirely; it is now placed after the outermost block.
|
|
33
|
+
|
|
8
34
|
## [0.0.12] - 2026-09-18
|
|
9
35
|
|
|
10
36
|
### Changed
|
|
@@ -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,23 @@ export function markdownClipboardPlugin() {
|
|
|
48
77
|
return false;
|
|
49
78
|
// 文書全体への貼り付けは**差し替え**である。メタデータごと入れ替わる
|
|
50
79
|
if (view.state.selection instanceof AllSelection) {
|
|
51
|
-
|
|
80
|
+
const replaced = replaceDocument(view.state, parsed.value.content);
|
|
81
|
+
view.dispatch(replaced.setMeta('paste', true).scrollIntoView());
|
|
52
82
|
return true;
|
|
53
83
|
}
|
|
84
|
+
const source = parsed.value.content;
|
|
85
|
+
const pasted = source.firstChild?.type === n.front_matter ? source.firstChild : null;
|
|
86
|
+
const body = pasted ? source.cut(pasted.nodeSize) : source;
|
|
87
|
+
const meta = pasted && pasted.content.size > 0 ? pasted : null;
|
|
54
88
|
const baseDepth = pasteDepth(view.state.doc, view.state.selection.from);
|
|
55
|
-
const content = relevel(
|
|
56
|
-
if (content.childCount === 0)
|
|
89
|
+
const content = relevel(body, baseDepth);
|
|
90
|
+
if (content.childCount === 0 && !meta)
|
|
57
91
|
return false;
|
|
58
|
-
const transaction = intoEmptyItem(view.state, content) ?? view.state
|
|
59
|
-
|
|
92
|
+
const transaction = intoEmptyItem(view.state, content) ?? intoSelection(view.state, content);
|
|
93
|
+
if (meta)
|
|
94
|
+
transaction.replaceWith(0, view.state.doc.child(0).nodeSize, meta);
|
|
95
|
+
// 空行の後始末(`appendTransaction`)が見る印
|
|
96
|
+
view.dispatch(transaction.setMeta('paste', true).scrollIntoView());
|
|
60
97
|
return true;
|
|
61
98
|
}
|
|
62
99
|
}
|
|
@@ -89,25 +126,6 @@ function replaceDocument(state, content) {
|
|
|
89
126
|
// 打ち間違いとして本文へ移される
|
|
90
127
|
return markDocumentReplacement(tr);
|
|
91
128
|
}
|
|
92
|
-
/**
|
|
93
|
-
* 貼った内容の先頭にあるフロントマターを、`yaml` のコードブロックへ置き換える。中身が無ければ
|
|
94
|
-
* 取り除く。
|
|
95
|
-
*
|
|
96
|
-
* 貼り先のフロントマターは触らない。挿入で貼り先のメタデータが
|
|
97
|
-
* 書き換わってはならず、かといって貼った側の文字を捨てることもできないため、
|
|
98
|
-
* **文字を失わないコンテナ**へ移す。区切りの行を中身に含めるのは、
|
|
99
|
-
* 切り取ってメタデータ欄へ貼り直せるようにするためである。
|
|
100
|
-
*/
|
|
101
|
-
function frontMatterAsCodeBlock(content) {
|
|
102
|
-
const first = content.firstChild;
|
|
103
|
-
if (first?.type !== n.front_matter)
|
|
104
|
-
return content;
|
|
105
|
-
const rest = content.cut(first.nodeSize);
|
|
106
|
-
if (first.content.size === 0)
|
|
107
|
-
return rest;
|
|
108
|
-
const source = outlineSchema.text(`---\n${first.textContent}\n---`);
|
|
109
|
-
return Fragment.from(n.code_block.createChecked({ language: 'yaml' }, source)).append(rest);
|
|
110
|
-
}
|
|
111
129
|
/**
|
|
112
130
|
* 空の項目への貼り付け。**貼り付ける内容がその項目に成り代わる。** 対象でなければ null。
|
|
113
131
|
*
|
|
@@ -134,6 +152,55 @@ function intoEmptyItem(state, content) {
|
|
|
134
152
|
tr.setSelection(TextSelection.near(tr.doc.resolve(Math.min(end, tr.doc.content.size)), -1));
|
|
135
153
|
return tr;
|
|
136
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* 既定の置き換え。入らなかったときは、いちばん外側のブロックの後ろへ置く。
|
|
157
|
+
*
|
|
158
|
+
* 編集基盤の当てはめは、貼り先のどこにも収まらない内容を黙って捨てる。文字を失わない
|
|
159
|
+
* ことを優先する(要件 10.18)。
|
|
160
|
+
*/
|
|
161
|
+
function intoSelection(state, content) {
|
|
162
|
+
const tr = state.tr.replaceSelection(pasted(content));
|
|
163
|
+
if (tr.docChanged)
|
|
164
|
+
return tr;
|
|
165
|
+
const $from = state.selection.$from;
|
|
166
|
+
let depth = $from.depth;
|
|
167
|
+
while (depth > 0 && !isLineContainer($from.node(depth - 1)))
|
|
168
|
+
depth -= 1;
|
|
169
|
+
const after = $from.after(depth);
|
|
170
|
+
tr.replaceRange(after, after, pasted(content));
|
|
171
|
+
tr.setSelection(TextSelection.near(tr.doc.resolve(Math.min(after, tr.doc.content.size)), 1));
|
|
172
|
+
return tr;
|
|
173
|
+
}
|
|
174
|
+
/** セクションの中身を直に持つコンテナか */
|
|
175
|
+
function isLineContainer(node) {
|
|
176
|
+
return node.type === n.section || node.type === n.intro_section;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* カーソルがいる空行。段落ならその段落、項目の本文なら項目そのものである。
|
|
180
|
+
* 配下を持つ項目は除く(取り除くと配下ごと消える)。
|
|
181
|
+
*/
|
|
182
|
+
function emptyLineAt(state) {
|
|
183
|
+
const cursor = state.selection instanceof TextSelection ? state.selection.$cursor : null;
|
|
184
|
+
if (!cursor || cursor.parent.type !== n.paragraph || cursor.parent.content.size > 0)
|
|
185
|
+
return null;
|
|
186
|
+
const depth = cursor.depth - 1;
|
|
187
|
+
const container = cursor.node(depth);
|
|
188
|
+
if (container.type === n.list) {
|
|
189
|
+
const childless = container.childCount === 1 && cursor.index(depth) === 0;
|
|
190
|
+
return childless ? { node: container, pos: cursor.before(depth) } : null;
|
|
191
|
+
}
|
|
192
|
+
if (container.type !== n.section && container.type !== n.intro_section)
|
|
193
|
+
return null;
|
|
194
|
+
return { node: cursor.parent, pos: cursor.before(cursor.depth) };
|
|
195
|
+
}
|
|
196
|
+
/** 何も書かれていない行か(空の段落、または本文が空で配下を持たない項目) */
|
|
197
|
+
function isEmptyLine(node) {
|
|
198
|
+
if (node.type === n.paragraph)
|
|
199
|
+
return node.content.size === 0;
|
|
200
|
+
if (node.type !== n.list)
|
|
201
|
+
return false;
|
|
202
|
+
return node.childCount === 1 && node.child(0).content.size === 0;
|
|
203
|
+
}
|
|
137
204
|
/**
|
|
138
205
|
* 空の項目を置き換える中身。
|
|
139
206
|
*
|
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.14",
|
|
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.",
|