@14ch/svelte-md-outliner 0.0.4 → 0.0.6
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 +42 -0
- package/dist/assets/styles/editor.css +2 -2
- package/dist/assets/styles/theme.css +38 -15
- package/dist/messages/en.js +4 -2
- package/dist/messages/ja.js +4 -2
- package/dist/models/document/sectionTree.d.ts +3 -3
- package/dist/models/document/sectionTree.js +36 -16
- package/dist/operations/commands/element.d.ts +1 -1
- package/dist/operations/commands/element.js +68 -5
- package/dist/operations/commands/section.js +3 -17
- package/dist/operations/commands/table.d.ts +4 -3
- package/dist/operations/commands/table.js +23 -9
- package/dist/operations/keymap/coreActions.js +40 -23
- package/dist/operations/operations.types.d.ts +0 -2
- package/dist/operations/plugins/headingLevel.d.ts +14 -0
- package/dist/operations/plugins/headingLevel.js +21 -0
- package/dist/operations/plugins/imagePaste.js +17 -0
- package/dist/operations/plugins/markdownClipboard.js +13 -0
- package/dist/operations/plugins/tablePaste.d.ts +19 -0
- package/dist/operations/plugins/tablePaste.js +218 -0
- package/dist/operations/transaction.d.ts +0 -2
- package/dist/operations/transaction.js +2 -9
- package/dist/states/editorSession.js +9 -0
- package/dist/utils/pastedTable.d.ts +11 -0
- package/dist/utils/pastedTable.js +16 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,48 @@ 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.6] - 2026-09-08
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Links no longer take on your theme colour. `--markdown-editor-link` used to
|
|
13
|
+
follow `--markdown-editor-accent`, so links turned whatever colour the app's
|
|
14
|
+
primary was; it now has its own steps (`--markdown-editor-link-600` / `-300`),
|
|
15
|
+
dark enough to meet 4.5:1 on light and dark surfaces. Override the token as
|
|
16
|
+
before to change it.
|
|
17
|
+
- On dark surfaces, lines and fills follow the same steps as the light side.
|
|
18
|
+
Borders read a notch softer, the menu surface is darker, and the text
|
|
19
|
+
selection, cell selection and hover band keep the relationships they have on
|
|
20
|
+
light — the selection and the hover band no longer share one colour.
|
|
21
|
+
- Headings have more room above them, and the breadcrumb and front matter sit
|
|
22
|
+
further from the body.
|
|
23
|
+
|
|
24
|
+
## [0.0.5] - 2026-09-05
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
|
|
28
|
+
- Spreadsheets paste as tables. Copies from Excel (Mac), Numbers and Google
|
|
29
|
+
Sheets come in as a table instead of one line of tab-separated text. Pasting
|
|
30
|
+
onto an existing table keeps that table's header row and column alignment.
|
|
31
|
+
|
|
32
|
+
### Changed
|
|
33
|
+
|
|
34
|
+
- `EditorMessages` breaking change: `table.alignLeftward` and
|
|
35
|
+
`table.alignRightward` are replaced by `table.alignLeft`, `table.alignCenter`,
|
|
36
|
+
`table.alignRight` and `table.alignNone`. Breaking if you supply a whole
|
|
37
|
+
language set; partial overrides are unaffected.
|
|
38
|
+
- Column alignment is set directly rather than shifted one step at a time.
|
|
39
|
+
`⌘⌥⇧←` and `⌘⌥⇧→` now mean align left and align right; center and
|
|
40
|
+
"no alignment" are on the context menu.
|
|
41
|
+
- Operations no longer reach past the element the cursor is in. Inside a table
|
|
42
|
+
cell, `⌘⇧D` no longer duplicates the whole table. To act on the table or quote
|
|
43
|
+
itself, point at it first.
|
|
44
|
+
|
|
45
|
+
### Fixed
|
|
46
|
+
|
|
47
|
+
- A heading you empty is no longer drawn as an `h1`. The saved Markdown was
|
|
48
|
+
right all along; only the screen was wrong.
|
|
49
|
+
|
|
8
50
|
## [0.0.4] - 2026-09-03
|
|
9
51
|
|
|
10
52
|
### Fixed
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
* 見出しなら 1.2em、段落なら 0.75em と、文書の中身で距離が変わる。どちらも本文ではないものなので、ブロックどうしの隙間より広く取り、
|
|
34
34
|
* 地の文と切り離して見せる。
|
|
35
35
|
*/
|
|
36
|
-
--markdown-editor-meta-gap:
|
|
36
|
+
--markdown-editor-meta-gap: 3em;
|
|
37
37
|
/**
|
|
38
38
|
* 項目の中の段落を詰める量。**項目どうしの隙間そのもの**であり、同じ階層をつなぐ
|
|
39
39
|
* 縦の目印はこの値だけ下へ伸びて隙間をまたぐ。2 か所で別々の値にすると線が切れる。
|
|
@@ -715,7 +715,7 @@
|
|
|
715
715
|
/* 折りたたみの記号を 1 行目の中央へ合わせるため、行の高さを控えておく */
|
|
716
716
|
--markdown-editor-heading-line-height: 1.3;
|
|
717
717
|
|
|
718
|
-
margin:
|
|
718
|
+
margin: 2em 0 0.5em;
|
|
719
719
|
font-size: calc(1em * var(--markdown-editor-heading-scale));
|
|
720
720
|
line-height: var(--markdown-editor-heading-line-height);
|
|
721
721
|
font-weight: 600;
|
|
@@ -119,6 +119,24 @@
|
|
|
119
119
|
--markdown-editor-edit-text-color-on-dark: var(--markdown-editor-edit-500);
|
|
120
120
|
--markdown-editor-edit-text-color-on-light: var(--markdown-editor-edit-600);
|
|
121
121
|
|
|
122
|
+
/**
|
|
123
|
+
* リンクの青。**テーマ色にも編集のサインにも従わない、第 3 の段である。**
|
|
124
|
+
*
|
|
125
|
+
* リンクは文書の中身だが、テーマ色(`primary-*`)から採ると、**置いた先のアプリが
|
|
126
|
+
* 配色を変えるたびにリンクの色が動く**。書き手が色から意味を読むものは文書の中で
|
|
127
|
+
* リンクだけであり、そこはテーマの装飾に明け渡す場所ではない(利用者の指摘、2026-09-06)。
|
|
128
|
+
*
|
|
129
|
+
* 編集のサインの段(`edit-*`)から採らないのは、**同じ結びつきを逆向きに作らない**
|
|
130
|
+
* ためである(操作の色を変えるとリンクが動く)。いま値が `edit-600` / `edit-300` と
|
|
131
|
+
* 同じなのは結果にすぎない。
|
|
132
|
+
*
|
|
133
|
+
* 段は面ごとに 2 つだけ持つ。リンクは**文字**なので、どちらも面に対して 4.5:1 を
|
|
134
|
+
* 満たす値を採る(明るい面で 4.57:1、暗い面で 9.6:1)。下線の指定は持たない
|
|
135
|
+
* (引くかどうかは置いた先の既定に従う)ので、色だけが本文との違いになる。
|
|
136
|
+
*/
|
|
137
|
+
--markdown-editor-link-300: #97c4ea;
|
|
138
|
+
--markdown-editor-link-600: #307ab7;
|
|
139
|
+
|
|
122
140
|
/**
|
|
123
141
|
* 暗いサーフェスの中性色。**白の透かしで持つ**(暖色寄りの中性色を薄めても、暗いサーフェスでは沈む)。
|
|
124
142
|
* 明るい面が `base-*` を使うのと対になる段である。
|
|
@@ -176,6 +194,8 @@
|
|
|
176
194
|
--markdown-editor-surface-accent: var(--markdown-editor-base-50-transparent);
|
|
177
195
|
/* 強調色は不透明。透かすと色味が背景に混ざり、強調に見えない */
|
|
178
196
|
--markdown-editor-accent: var(--markdown-editor-primary-color);
|
|
197
|
+
/* リンクの色。**強調色から独立して持つ**(→ パレットの `link-*`) */
|
|
198
|
+
--markdown-editor-hyperlink: var(--markdown-editor-link-600);
|
|
179
199
|
/* 点・番号・チェックの色。本文より引いて見せる印なので透かす */
|
|
180
200
|
--markdown-editor-marker: var(--markdown-editor-base-500-transparent);
|
|
181
201
|
/**
|
|
@@ -256,7 +276,7 @@
|
|
|
256
276
|
--markdown-editor-number-color: var(--markdown-editor-marker);
|
|
257
277
|
|
|
258
278
|
/* リンク */
|
|
259
|
-
--markdown-editor-link: var(--markdown-editor-
|
|
279
|
+
--markdown-editor-link: var(--markdown-editor-hyperlink);
|
|
260
280
|
--markdown-editor-footnote-marker-color: var(--markdown-editor-text-subtle);
|
|
261
281
|
|
|
262
282
|
/* 折りたたみ。**押すターゲットと、折りたたみのマーカーは別のものである** */
|
|
@@ -428,40 +448,42 @@
|
|
|
428
448
|
:where(:root:not([data-theme='light'])) {
|
|
429
449
|
--markdown-editor-text: var(--markdown-editor-white-800-transparent);
|
|
430
450
|
--markdown-editor-text-subtle: var(--markdown-editor-white-500-transparent);
|
|
431
|
-
--markdown-editor-border: var(--markdown-editor-white-
|
|
432
|
-
--markdown-editor-border-weak: var(--markdown-editor-white-
|
|
433
|
-
--markdown-editor-border-strong: var(--markdown-editor-white-
|
|
434
|
-
--markdown-editor-guide: var(--markdown-editor-white-
|
|
451
|
+
--markdown-editor-border: var(--markdown-editor-white-200-transparent);
|
|
452
|
+
--markdown-editor-border-weak: var(--markdown-editor-white-100-transparent);
|
|
453
|
+
--markdown-editor-border-strong: var(--markdown-editor-white-300-transparent);
|
|
454
|
+
--markdown-editor-guide: var(--markdown-editor-white-100-transparent);
|
|
435
455
|
--markdown-editor-surface-accent: var(--markdown-editor-white-50-transparent);
|
|
436
456
|
--markdown-editor-accent: var(--markdown-editor-primary-lighter);
|
|
457
|
+
--markdown-editor-hyperlink: var(--markdown-editor-link-300);
|
|
437
458
|
--markdown-editor-marker: var(--markdown-editor-white-500-transparent);
|
|
438
|
-
--markdown-editor-selection: var(--markdown-editor-edit-
|
|
459
|
+
--markdown-editor-selection: var(--markdown-editor-edit-900-transparent);
|
|
439
460
|
--markdown-editor-cell-selection: var(--markdown-editor-edit-900-transparent);
|
|
440
461
|
--markdown-editor-block-selection: var(--markdown-editor-edit-lighter);
|
|
441
462
|
--markdown-editor-block-hover: var(--markdown-editor-edit-800-transparent);
|
|
442
|
-
--markdown-editor-surface: var(--markdown-editor-base-
|
|
463
|
+
--markdown-editor-surface: var(--markdown-editor-base-950);
|
|
443
464
|
--markdown-editor-hover-overlay: var(--markdown-editor-white-100-transparent);
|
|
444
|
-
--markdown-editor-target-fill: var(--markdown-editor-edit-
|
|
465
|
+
--markdown-editor-target-fill: var(--markdown-editor-edit-950-transparent);
|
|
445
466
|
}
|
|
446
467
|
}
|
|
447
468
|
|
|
448
469
|
:where([data-theme='dark']) {
|
|
449
470
|
--markdown-editor-text: var(--markdown-editor-white-800-transparent);
|
|
450
471
|
--markdown-editor-text-subtle: var(--markdown-editor-white-500-transparent);
|
|
451
|
-
--markdown-editor-border: var(--markdown-editor-white-
|
|
452
|
-
--markdown-editor-border-weak: var(--markdown-editor-white-
|
|
453
|
-
--markdown-editor-border-strong: var(--markdown-editor-white-
|
|
454
|
-
--markdown-editor-guide: var(--markdown-editor-white-
|
|
472
|
+
--markdown-editor-border: var(--markdown-editor-white-200-transparent);
|
|
473
|
+
--markdown-editor-border-weak: var(--markdown-editor-white-100-transparent);
|
|
474
|
+
--markdown-editor-border-strong: var(--markdown-editor-white-300-transparent);
|
|
475
|
+
--markdown-editor-guide: var(--markdown-editor-white-100-transparent);
|
|
455
476
|
--markdown-editor-surface-accent: var(--markdown-editor-white-50-transparent);
|
|
456
477
|
--markdown-editor-accent: var(--markdown-editor-primary-lighter);
|
|
478
|
+
--markdown-editor-hyperlink: var(--markdown-editor-link-300);
|
|
457
479
|
--markdown-editor-marker: var(--markdown-editor-white-500-transparent);
|
|
458
|
-
--markdown-editor-selection: var(--markdown-editor-edit-
|
|
480
|
+
--markdown-editor-selection: var(--markdown-editor-edit-900-transparent);
|
|
459
481
|
--markdown-editor-cell-selection: var(--markdown-editor-edit-900-transparent);
|
|
460
482
|
--markdown-editor-block-selection: var(--markdown-editor-edit-lighter);
|
|
461
483
|
--markdown-editor-block-hover: var(--markdown-editor-edit-800-transparent);
|
|
462
|
-
--markdown-editor-surface: var(--markdown-editor-base-
|
|
484
|
+
--markdown-editor-surface: var(--markdown-editor-base-950);
|
|
463
485
|
--markdown-editor-hover-overlay: var(--markdown-editor-white-100-transparent);
|
|
464
|
-
--markdown-editor-target-fill: var(--markdown-editor-edit-
|
|
486
|
+
--markdown-editor-target-fill: var(--markdown-editor-edit-950-transparent);
|
|
465
487
|
}
|
|
466
488
|
|
|
467
489
|
/**
|
|
@@ -479,6 +501,7 @@
|
|
|
479
501
|
--markdown-editor-guide: var(--markdown-editor-base-100-transparent);
|
|
480
502
|
--markdown-editor-surface-accent: var(--markdown-editor-base-50-transparent);
|
|
481
503
|
--markdown-editor-accent: var(--markdown-editor-primary-color);
|
|
504
|
+
--markdown-editor-hyperlink: var(--markdown-editor-link-600);
|
|
482
505
|
--markdown-editor-marker: var(--markdown-editor-base-500-transparent);
|
|
483
506
|
--markdown-editor-selection: var(--markdown-editor-edit-100-transparent);
|
|
484
507
|
--markdown-editor-cell-selection: var(--markdown-editor-edit-100-transparent);
|
package/dist/messages/en.js
CHANGED
|
@@ -57,8 +57,10 @@ export const en = {
|
|
|
57
57
|
'table.moveColumnLeft.inTable': 'Move column left',
|
|
58
58
|
'table.moveColumnRight': 'In a table, move the column right',
|
|
59
59
|
'table.moveColumnRight.inTable': 'Move column right',
|
|
60
|
-
'table.
|
|
61
|
-
'table.
|
|
60
|
+
'table.alignLeft': 'Align column left',
|
|
61
|
+
'table.alignCenter': 'Align column center',
|
|
62
|
+
'table.alignRight': 'Align column right',
|
|
63
|
+
'table.alignNone': 'Clear column alignment',
|
|
62
64
|
'document.undo': 'Undo',
|
|
63
65
|
'document.redo': 'Redo',
|
|
64
66
|
'editing.escapeTab': 'Release Tab so it moves focus',
|
package/dist/messages/ja.js
CHANGED
|
@@ -62,8 +62,10 @@ export const ja = {
|
|
|
62
62
|
'table.moveColumnLeft.inTable': '列を左へ移動',
|
|
63
63
|
'table.moveColumnRight': '表の中では、列を右へ移動',
|
|
64
64
|
'table.moveColumnRight.inTable': '列を右へ移動',
|
|
65
|
-
'table.
|
|
66
|
-
'table.
|
|
65
|
+
'table.alignLeft': '列を左寄せにする',
|
|
66
|
+
'table.alignCenter': '列を中央寄せにする',
|
|
67
|
+
'table.alignRight': '列を右寄せにする',
|
|
68
|
+
'table.alignNone': '列の配置指定を外す',
|
|
67
69
|
'document.undo': '取り消し',
|
|
68
70
|
'document.redo': 'やり直し',
|
|
69
71
|
'editing.escapeTab': 'Tab でフォーカスを移せる状態にする',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Node } from 'prosemirror-model';
|
|
2
|
-
import type { Transaction } from 'prosemirror-state';
|
|
2
|
+
import type { EditorState, Transaction } from 'prosemirror-state';
|
|
3
3
|
import { type SectionPath, type SectionRef } from './document.types';
|
|
4
4
|
/**
|
|
5
5
|
* 見出しの**読める 1 行の文字**。パンくず・折りたたみの見出し・表示状態の突合キーは
|
|
@@ -18,7 +18,7 @@ export interface SectionTree {
|
|
|
18
18
|
resolveByPath(doc: Node, path: SectionPath): SectionRef | null;
|
|
19
19
|
/** 文書順のすべてのセクション。見出しを持たない先頭セクションを含む(`path` は `null`) */
|
|
20
20
|
listSections(doc: Node): readonly SectionRef[];
|
|
21
|
-
/**
|
|
22
|
-
|
|
21
|
+
/** 深さと食い違っている見出しレベルを直す書き換え。食い違いが無ければ `null` */
|
|
22
|
+
correctHeadingLevels(state: EditorState): Transaction | null;
|
|
23
23
|
}
|
|
24
24
|
export declare const sectionTree: SectionTree;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MAX_HEADING_LEVEL } from './document.types';
|
|
1
|
+
import { MAX_HEADING_LEVEL, MIN_HEADING_LEVEL } from './document.types';
|
|
2
2
|
import { outlineSchema } from './schema';
|
|
3
3
|
const SECTION = outlineSchema.nodes.section;
|
|
4
4
|
const INTRO_SECTION = outlineSchema.nodes.intro_section;
|
|
@@ -19,7 +19,7 @@ export const sectionTree = {
|
|
|
19
19
|
resolveAncestors,
|
|
20
20
|
resolveByPath,
|
|
21
21
|
listSections,
|
|
22
|
-
|
|
22
|
+
correctHeadingLevels
|
|
23
23
|
};
|
|
24
24
|
function resolveSection(doc, pos) {
|
|
25
25
|
const chain = sectionChain(doc, pos);
|
|
@@ -58,22 +58,42 @@ function listSections(doc) {
|
|
|
58
58
|
});
|
|
59
59
|
return refs;
|
|
60
60
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
61
|
+
/**
|
|
62
|
+
* 見出しレベルは**構造上の深さの写し**であり、深さと独立した真実ではない。写しである以上
|
|
63
|
+
* 食い違いうるので、**書き換えのたびに深さへ合わせ直す**(→ `headingLevelPlugin`)。
|
|
64
|
+
*
|
|
65
|
+
* 合わせ直しを階層操作の側に配らないのは、**食い違いの作られ方が 1 つではない**ためである。
|
|
66
|
+
* 見出しの行を巻き込む範囲選択の削除では、編集基盤が `section` の内容モデル
|
|
67
|
+
* (`heading block* section*`)を満たすために**既定値の見出しを補う**。補われた見出しは
|
|
68
|
+
* どのコマンドも通らないため、レベルが 1 のまま深いところに残る。書き出しは深さから
|
|
69
|
+
* 決まる(→ `serializer.ts`)ので、**画面だけが `h1` になる**(利用者の報告、2026-09-05)。
|
|
70
|
+
*/
|
|
71
|
+
function correctHeadingLevels(state) {
|
|
72
|
+
const tr = state.tr;
|
|
73
|
+
correctSectionsIn(tr, state.doc, 0, MIN_HEADING_LEVEL);
|
|
74
|
+
return tr.steps.length > 0 ? tr : null;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* `container` の直下のセクションを見て回る。`level` はそこに現れる見出しのレベル。
|
|
78
|
+
*
|
|
79
|
+
* セクションを置けるのは `doc` と `section` の中だけなので、見出し以外の中身へは降りない
|
|
80
|
+
* (引用や項目の中の見出しは階層に加わらず、レベルを属性で持つ → スキーマの `nested_heading`)。
|
|
81
|
+
* レベルの書き換えは位置をずらさないため、位置は元の文書のまま数えられる。
|
|
82
|
+
*/
|
|
83
|
+
function correctSectionsIn(tr, container, contentStart, level) {
|
|
84
|
+
let pos = contentStart;
|
|
85
|
+
container.forEach((child) => {
|
|
86
|
+
if (child.type === SECTION) {
|
|
87
|
+
// section は必ず見出しから始まる(→ スキーマの `section`)
|
|
88
|
+
const headingPos = pos + 1;
|
|
89
|
+
const corrected = clampLevel(level);
|
|
90
|
+
if (child.child(0).attrs.level !== corrected) {
|
|
91
|
+
tr.setNodeAttribute(headingPos, 'level', corrected);
|
|
92
|
+
}
|
|
93
|
+
correctSectionsIn(tr, child, headingPos, level + 1);
|
|
73
94
|
}
|
|
74
|
-
|
|
95
|
+
pos += child.nodeSize;
|
|
75
96
|
});
|
|
76
|
-
return tr;
|
|
77
97
|
}
|
|
78
98
|
// --- ヘルパー ---
|
|
79
99
|
/** 位置を包むセクションを、外側から順に返す */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type EditorState } from 'prosemirror-state';
|
|
2
2
|
import type { BlockKind } from '../../models/document/document.types';
|
|
3
3
|
import type { EditorCommand, ElementTarget, MoveDirection } from '../operations.types';
|
|
4
4
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { chainCommands } from 'prosemirror-commands';
|
|
2
|
-
import {
|
|
2
|
+
import { TextSelection } from 'prosemirror-state';
|
|
3
|
+
import { CellSelection, isInTable } from 'prosemirror-tables';
|
|
3
4
|
import { outlineSchema } from '../../models/document/schema';
|
|
4
5
|
import { selectBlockAt, setCursor } from '../transaction';
|
|
5
6
|
import { isTabEscaped } from '../plugins/tabEscape';
|
|
@@ -54,7 +55,69 @@ function targetElement(state) {
|
|
|
54
55
|
if (item)
|
|
55
56
|
return { kind: 'listItem', ...item };
|
|
56
57
|
const block = topLevelBlock(state);
|
|
57
|
-
|
|
58
|
+
if (!block)
|
|
59
|
+
return null;
|
|
60
|
+
return { kind: 'block', ...insideRequiredSelectionBlock(state, block) };
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 要選択ブロック(表・引用・コードブロック)の**中身にカーソルがあるだけ**なら、
|
|
64
|
+
* 対象はその中身である。ブロック自身を対象にするには、まず指す(要選択の原則)。
|
|
65
|
+
*
|
|
66
|
+
* **選んでいる要素ではなく、その上位の要素に対して操作を実行しない。** 表のセルに
|
|
67
|
+
* カーソルを置いて複製すれば表ごと複製される、という状態がここにあった(利用者の指摘、
|
|
68
|
+
* 2026-09-05)。原則は決まっていたのに、実装が `targetElement` の外にあり、**呼ぶ側が
|
|
69
|
+
* それぞれ補っていた**——メニューは項目を隠して補い、キーは補っておらず、印は補いを
|
|
70
|
+
* 知らないまま `targetElement` の答えを映していた。**補いを 3 つ持つのをやめ、原則を
|
|
71
|
+
* ここへ 1 つ置く。**
|
|
72
|
+
*
|
|
73
|
+
* 寄せた先は、表ではセル、引用では中の段落になる。コードブロックは自身がテキストブロック
|
|
74
|
+
* なので変わらない。
|
|
75
|
+
*/
|
|
76
|
+
function insideRequiredSelectionBlock(state, block) {
|
|
77
|
+
if (!requiredSelectionBlock.isRequiredSelectionBlock(block.node))
|
|
78
|
+
return block;
|
|
79
|
+
/**
|
|
80
|
+
* 寄せるのは、**選択が 1 つのテキストブロックに収まっているとき**だけである。
|
|
81
|
+
*
|
|
82
|
+
* セル範囲の選択(`CellSelection`)は、書き手が表の構造を明示的に選んだ状態であり、
|
|
83
|
+
* 対象は表そのものになる(`outline-editing-core` Requirement 4.3a)。またいだ選択も
|
|
84
|
+
* 同じで、収まる先が 1 つに決まらない。
|
|
85
|
+
*/
|
|
86
|
+
const selection = state.selection;
|
|
87
|
+
if (!(selection instanceof TextSelection))
|
|
88
|
+
return block;
|
|
89
|
+
const { $from, $to } = selection;
|
|
90
|
+
if ($from.depth === 0 || !$from.parent.isTextblock)
|
|
91
|
+
return block;
|
|
92
|
+
if ($from.parent !== $to.parent)
|
|
93
|
+
return block;
|
|
94
|
+
return { node: $from.parent, pos: $from.before($from.depth) };
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 単独で複製・削除・移動できない対象か。
|
|
98
|
+
*
|
|
99
|
+
* 2 つある。
|
|
100
|
+
*
|
|
101
|
+
* - **親が構造を持っている要素**(表のセルと行)。1 つ増やせば行ごとの列数が崩れ、
|
|
102
|
+
* 1 つ消せば穴が空く。表の構造を変えるのは行・列のコマンドの仕事である(`table-editing`)
|
|
103
|
+
* - **指していない要選択ブロック**(中身がテキストブロック 1 つのコードブロックなど)。
|
|
104
|
+
* 動かす・消すにはまず指す(要選択の原則)
|
|
105
|
+
*/
|
|
106
|
+
function needsPointing(state, target) {
|
|
107
|
+
if (ownedByParent(target.node))
|
|
108
|
+
return true;
|
|
109
|
+
if (target.kind === 'selectedBlock')
|
|
110
|
+
return false;
|
|
111
|
+
if (!requiredSelectionBlock.isRequiredSelectionBlock(target.node))
|
|
112
|
+
return false;
|
|
113
|
+
// セル範囲の選択は、表の構造を画面上で選んだ状態である。指したのと同じに扱う
|
|
114
|
+
// (`outline-editing-core` Requirement 4.3a)
|
|
115
|
+
return !(state.selection instanceof CellSelection);
|
|
116
|
+
}
|
|
117
|
+
/** 親が構造を持っている要素(表のセルと行) */
|
|
118
|
+
function ownedByParent(node) {
|
|
119
|
+
const role = node.type.spec.tableRole;
|
|
120
|
+
return role === 'cell' || role === 'header_cell' || role === 'row';
|
|
58
121
|
}
|
|
59
122
|
/**
|
|
60
123
|
* カーソルが項目の**本文より後ろ**のブロックにあるとき、そのブロック。
|
|
@@ -113,7 +176,7 @@ function moveElement(direction) {
|
|
|
113
176
|
const move = moveSection(direction);
|
|
114
177
|
return (state, dispatch, view) => {
|
|
115
178
|
const target = targetElement(state);
|
|
116
|
-
if (!target)
|
|
179
|
+
if (!target || needsPointing(state, target))
|
|
117
180
|
return false;
|
|
118
181
|
if (target.kind === 'section')
|
|
119
182
|
return move(state, dispatch, view);
|
|
@@ -165,7 +228,7 @@ function moveBlock(direction, target, state, dispatch) {
|
|
|
165
228
|
*/
|
|
166
229
|
function duplicateElement(state, dispatch) {
|
|
167
230
|
const target = targetElement(state);
|
|
168
|
-
if (!target)
|
|
231
|
+
if (!target || needsPointing(state, target))
|
|
169
232
|
return false;
|
|
170
233
|
if (!dispatch)
|
|
171
234
|
return true;
|
|
@@ -249,7 +312,7 @@ export function inTable(command) {
|
|
|
249
312
|
*/
|
|
250
313
|
function deleteElement(state, dispatch) {
|
|
251
314
|
const target = targetElement(state);
|
|
252
|
-
if (!target)
|
|
315
|
+
if (!target || needsPointing(state, target))
|
|
253
316
|
return false;
|
|
254
317
|
if (!dispatch)
|
|
255
318
|
return true;
|
|
@@ -3,7 +3,7 @@ import { MAX_HEADING_LEVEL } from '../../models/document/document.types';
|
|
|
3
3
|
import { bodyCount, bodyIndex, bodyStart } from '../../models/document/bodySelection';
|
|
4
4
|
import { outlineSchema } from '../../models/document/schema';
|
|
5
5
|
import { sectionTree } from '../../models/document/sectionTree';
|
|
6
|
-
import { moveContent, setCursor
|
|
6
|
+
import { moveContent, setCursor } from '../transaction';
|
|
7
7
|
const n = outlineSchema.nodes;
|
|
8
8
|
/**
|
|
9
9
|
* 見出しを 1 段深くする。直前の兄弟セクションの中身の末尾へ移す。
|
|
@@ -30,7 +30,6 @@ export function sinkSection(state, dispatch) {
|
|
|
30
30
|
const insertAt = pos - 1;
|
|
31
31
|
tr.delete(pos, pos + target.node.nodeSize);
|
|
32
32
|
tr.insert(insertAt, target.node);
|
|
33
|
-
syncFrom(tr, insertAt);
|
|
34
33
|
return { at: insertAt, steps: tr.steps.length };
|
|
35
34
|
});
|
|
36
35
|
restoreSelection(tr, state, targets, moved);
|
|
@@ -70,9 +69,7 @@ function liftOne(tr, pos) {
|
|
|
70
69
|
const $target = tr.doc.resolve(pos);
|
|
71
70
|
const target = $target.nodeAfter;
|
|
72
71
|
const parentEnd = $target.before() + $target.parent.nodeSize;
|
|
73
|
-
|
|
74
|
-
syncFrom(tr, at);
|
|
75
|
-
return at;
|
|
72
|
+
return moveContent(tr, pos, pos + target.nodeSize, parentEnd);
|
|
76
73
|
}
|
|
77
74
|
/** 直前に兄弟のセクションがあり、配下も最下位レベルを超えないこと */
|
|
78
75
|
function canSink(doc, target) {
|
|
@@ -223,7 +220,6 @@ function moveIntoSiblingSection(direction, state, dispatch) {
|
|
|
223
220
|
tr.delete(target.pos, target.pos + target.node.nodeSize);
|
|
224
221
|
const at = tr.mapping.map(insertAt);
|
|
225
222
|
tr.insert(at, target.node);
|
|
226
|
-
syncFrom(tr, at);
|
|
227
223
|
setCursor(tr, at + offsetInSection);
|
|
228
224
|
dispatch(tr.scrollIntoView());
|
|
229
225
|
return true;
|
|
@@ -355,7 +351,6 @@ export function dissolveHeadingAtStart(state, dispatch) {
|
|
|
355
351
|
let movedAt = childrenAt;
|
|
356
352
|
for (const child of moving) {
|
|
357
353
|
tr.insert(movedAt, child);
|
|
358
|
-
syncFrom(tr, movedAt);
|
|
359
354
|
movedAt += child.nodeSize;
|
|
360
355
|
}
|
|
361
356
|
if (blocks.length > 0)
|
|
@@ -363,11 +358,10 @@ export function dissolveHeadingAtStart(state, dispatch) {
|
|
|
363
358
|
// 入れてから消す。入れる位置は消す位置より手前なので、位置がずれる
|
|
364
359
|
const from = tr.mapping.map(sectionPos);
|
|
365
360
|
tr.delete(from, from + section.nodeSize);
|
|
366
|
-
//
|
|
361
|
+
// 残した子のセクションは、消えた親のぶんだけ浅くなる
|
|
367
362
|
let at = from;
|
|
368
363
|
for (const child of staying) {
|
|
369
364
|
tr.insert(at, child);
|
|
370
|
-
syncFrom(tr, at);
|
|
371
365
|
at += child.nodeSize;
|
|
372
366
|
}
|
|
373
367
|
tr.setSelection(TextSelection.near(tr.doc.resolve(target)));
|
|
@@ -527,14 +521,6 @@ export function removeEmptyLeadingBlock(state, dispatch) {
|
|
|
527
521
|
return false;
|
|
528
522
|
if (!dispatch)
|
|
529
523
|
return true;
|
|
530
|
-
// 1 段浅くなった子のセクションは、見出しのレベルを新しい深さへ合わせ直す。
|
|
531
|
-
// 合わせないと、見出しの深さと段数が食い違ったまま書き出される
|
|
532
|
-
let at = start;
|
|
533
|
-
for (const moved of rest) {
|
|
534
|
-
if (moved.type === n.section)
|
|
535
|
-
syncFrom(tr, at);
|
|
536
|
-
at += moved.nodeSize;
|
|
537
|
-
}
|
|
538
524
|
setCursor(tr, start);
|
|
539
525
|
dispatch(tr.scrollIntoView());
|
|
540
526
|
return true;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type EditorState, type Transaction } from 'prosemirror-state';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CellAlign } from '../../models/document/document.types';
|
|
3
|
+
import type { CellDirection, ColumnDirection, EditorCommand, MoveDirection, TableDeleteTarget } from '../operations.types';
|
|
3
4
|
/**
|
|
4
5
|
* 表の構造を変える操作。`prosemirror-tables` への依存をこのファイルに集約する。
|
|
5
6
|
*
|
|
@@ -28,8 +29,8 @@ export interface TableCommands {
|
|
|
28
29
|
readonly deleteSelected: EditorCommand;
|
|
29
30
|
/** 行・列・表を丸ごと選んでいるときだけ、それを削除する。覆いきらない選択では譲る */
|
|
30
31
|
readonly deleteSelectedRowOrColumn: EditorCommand;
|
|
31
|
-
/**
|
|
32
|
-
readonly align: (
|
|
32
|
+
/** 選択している列を、その配置にする。既にその配置なら譲る */
|
|
33
|
+
readonly align: (align: CellAlign) => EditorCommand;
|
|
33
34
|
/** 本文行を隣の本文行と入れ替える。見出し行と端では実行しない */
|
|
34
35
|
readonly moveRow: (direction: MoveDirection) => EditorCommand;
|
|
35
36
|
/** 列を隣の列と入れ替える。配置指定も一緒に動く。端では実行しない */
|
|
@@ -6,8 +6,6 @@ import { outlineSchema } from '../../models/document/schema';
|
|
|
6
6
|
const n = outlineSchema.nodes;
|
|
7
7
|
/** 見出し行は表の 0 行目である(`table_header` の有無では判定しない) */
|
|
8
8
|
const HEADER_ROW = 0;
|
|
9
|
-
/** 配置の線。両端では止まり、押し続けても巡回しない */
|
|
10
|
-
const ALIGN_LINE = [null, 'left', 'center', 'right'];
|
|
11
9
|
export const tableCommands = {
|
|
12
10
|
createTable,
|
|
13
11
|
insertRowBefore: (state, dispatch) => insertRow(state, dispatch, 'before'),
|
|
@@ -16,7 +14,7 @@ export const tableCommands = {
|
|
|
16
14
|
insertColumnAfter: (state, dispatch) => insertColumn(state, dispatch, 'after'),
|
|
17
15
|
deleteSelected,
|
|
18
16
|
deleteSelectedRowOrColumn,
|
|
19
|
-
align: (
|
|
17
|
+
align: (align) => (state, dispatch) => applyAlign(state, dispatch, align),
|
|
20
18
|
moveRow: (direction) => (state, dispatch) => shiftRow(state, dispatch, direction),
|
|
21
19
|
moveColumn: (direction) => (state, dispatch) => shiftColumn(state, dispatch, direction),
|
|
22
20
|
goToNextCell,
|
|
@@ -247,15 +245,31 @@ function keepSelection(tr, rect, rowStep, columnStep) {
|
|
|
247
245
|
return tr.setSelection(CellSelection.create(tr.doc, anchor, head));
|
|
248
246
|
}
|
|
249
247
|
// --- 列の配置 ---
|
|
250
|
-
|
|
248
|
+
/**
|
|
249
|
+
* 選択している列を、その配置にする。**押したらその配置になる。**
|
|
250
|
+
*
|
|
251
|
+
* 段を 1 つずつ動かす形(`leftward` / `rightward`)をやめた(利用者の判断、2026-09-04)。
|
|
252
|
+
* 他のソフト(Word・Google ドキュメント・Pages)はどれも直接その配置にする形であり、
|
|
253
|
+
* 段を動かす形は事例が無い。
|
|
254
|
+
*
|
|
255
|
+
* **`null`(指定なし)は「まだ指定していない」という記法上の状態である。** 見た目は左寄せと
|
|
256
|
+
* 同じで、区別できるのは区切り行の文字(`---` か `:--` か)だけである。既定を左寄せにして
|
|
257
|
+
* `null` を無くすと、`| --- |` と書かれた既存のファイルを開いて保存しただけで、すべての表の
|
|
258
|
+
* 区切り行に差分が出る。**書かれていないものを勝手に書き足さない。**
|
|
259
|
+
*/
|
|
260
|
+
function applyAlign(state, dispatch, next) {
|
|
251
261
|
if (!isInTable(state))
|
|
252
262
|
return false;
|
|
253
263
|
const rect = selectedRect(state);
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
264
|
+
/**
|
|
265
|
+
* 既にその配置なら、**何もしないが受け止める**。
|
|
266
|
+
*
|
|
267
|
+
* 譲ると 2 つ壊れる。キーを共有している操作(見出しへ飛ぶ)が表の中で不意に働き、
|
|
268
|
+
* コンテキストメニューからその配置だけが消えて、4 つのうちどれが今の配置かを
|
|
269
|
+
* 読み取れなくなる。
|
|
270
|
+
*/
|
|
271
|
+
if ((cellAt(rect, HEADER_ROW, rect.left)?.attrs.align ?? null) === next)
|
|
272
|
+
return true;
|
|
259
273
|
if (dispatch) {
|
|
260
274
|
const tr = state.tr;
|
|
261
275
|
for (let column = rect.left; column < rect.right; column += 1) {
|
|
@@ -22,17 +22,6 @@ import { enterTabEscape } from '../plugins/tabEscape';
|
|
|
22
22
|
* 軸は操作であり、キーはその属性である。同じ操作を複数のキーで呼べる場合は、
|
|
23
23
|
* 定義を分けずに `keys` の並びへ足す。
|
|
24
24
|
*/
|
|
25
|
-
/**
|
|
26
|
-
* 対象が「内容物にカーソルがあるだけの要選択ブロック」か。
|
|
27
|
-
*
|
|
28
|
-
* カーソルが内容物にあるとき、メニューはその粒度のものだけを操作する。外側のブロック
|
|
29
|
-
* (表・引用・コードブロック)を動かす・消すには、まず指す(要選択の原則)。指した状態
|
|
30
|
-
* (kind: 'selectedBlock')は対象が見えているので出す。
|
|
31
|
-
*/
|
|
32
|
-
function unpointedRequiredSelectionTarget(state) {
|
|
33
|
-
const target = sectionCommands.targetElement(state);
|
|
34
|
-
return target?.kind === 'block' && requiredSelectionBlock.isRequiredSelectionBlock(target.node);
|
|
35
|
-
}
|
|
36
25
|
/** カーソルが属する箇条書きの項目の種別。項目の中でなければ null */
|
|
37
26
|
function listKindAt(state) {
|
|
38
27
|
const kind = listCommands.enclosingListItem(state)?.node.attrs.kind;
|
|
@@ -157,23 +146,55 @@ export const coreActions = [
|
|
|
157
146
|
command: inTable(tableCommands.moveColumn('right')),
|
|
158
147
|
variantId: () => 'table.moveColumnRight.inTable'
|
|
159
148
|
},
|
|
149
|
+
/**
|
|
150
|
+
* 列の配置。**押したらその配置になる**(利用者の判断、2026-09-04)。段を 1 つずつ動かす
|
|
151
|
+
* 形をやめた。他のソフト(Word・Google ドキュメント・Pages)はどれも直接その配置に
|
|
152
|
+
* する形である。
|
|
153
|
+
*
|
|
154
|
+
* **キーを持つのは左右だけである。** 矢印の向きが配置の向きを表すので中央を `↑`、
|
|
155
|
+
* 指定なしを `↓` に置きたいが、**`Mod-Alt-Shift-↑↓` は「同じ階層の見出しへ飛ぶ」が
|
|
156
|
+
* 既に使っている**。基盤と衝突した拡張の操作は配られないため(`withoutCoreKeys`)、
|
|
157
|
+
* 奪うと見出しジャンプが表の外でも消える。**残る 2 つはコンテキストメニューから行う。**
|
|
158
|
+
*
|
|
159
|
+
* 頭文字(Word・Google ドキュメントの `L` / `E` / `R`)を採らないのは、
|
|
160
|
+
* `Mod-Shift-R` がブラウザのハード再読み込みであり、`Mod-E` を既にインラインコードで
|
|
161
|
+
* 使っているためである。
|
|
162
|
+
*/
|
|
160
163
|
{
|
|
161
|
-
id: 'table.
|
|
164
|
+
id: 'table.alignLeft',
|
|
162
165
|
category: 'table',
|
|
163
166
|
scope: 'item',
|
|
164
167
|
listed: true,
|
|
165
168
|
changesDocument: true,
|
|
166
169
|
keys: [{ key: 'ArrowLeft', mod: true, alt: true, shift: true }],
|
|
167
|
-
command: inTable(tableCommands.align('
|
|
170
|
+
command: inTable(tableCommands.align('left'))
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
id: 'table.alignCenter',
|
|
174
|
+
category: 'table',
|
|
175
|
+
scope: 'item',
|
|
176
|
+
listed: true,
|
|
177
|
+
changesDocument: true,
|
|
178
|
+
keys: [],
|
|
179
|
+
command: inTable(tableCommands.align('center'))
|
|
168
180
|
},
|
|
169
181
|
{
|
|
170
|
-
id: 'table.
|
|
182
|
+
id: 'table.alignRight',
|
|
171
183
|
category: 'table',
|
|
172
184
|
scope: 'item',
|
|
173
185
|
listed: true,
|
|
174
186
|
changesDocument: true,
|
|
175
187
|
keys: [{ key: 'ArrowRight', mod: true, alt: true, shift: true }],
|
|
176
|
-
command: inTable(tableCommands.align('
|
|
188
|
+
command: inTable(tableCommands.align('right'))
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
id: 'table.alignNone',
|
|
192
|
+
category: 'table',
|
|
193
|
+
scope: 'item',
|
|
194
|
+
listed: true,
|
|
195
|
+
changesDocument: true,
|
|
196
|
+
keys: [],
|
|
197
|
+
command: inTable(tableCommands.align(null))
|
|
177
198
|
},
|
|
178
199
|
/**
|
|
179
200
|
* 代替のキーは**独立した定義にせず、この並びの 2 番目以降**に置く。
|
|
@@ -249,8 +270,7 @@ export const coreActions = [
|
|
|
249
270
|
listed: true,
|
|
250
271
|
changesDocument: true,
|
|
251
272
|
keys: [{ key: 'ArrowUp', mod: true }],
|
|
252
|
-
command: moveByContext('up')
|
|
253
|
-
variantId: (state) => (unpointedRequiredSelectionTarget(state) ? null : 'subtree.moveUp')
|
|
273
|
+
command: moveByContext('up')
|
|
254
274
|
},
|
|
255
275
|
{
|
|
256
276
|
id: 'subtree.moveDown',
|
|
@@ -259,8 +279,7 @@ export const coreActions = [
|
|
|
259
279
|
listed: true,
|
|
260
280
|
changesDocument: true,
|
|
261
281
|
keys: [{ key: 'ArrowDown', mod: true }],
|
|
262
|
-
command: moveByContext('down')
|
|
263
|
-
variantId: (state) => (unpointedRequiredSelectionTarget(state) ? null : 'subtree.moveDown')
|
|
282
|
+
command: moveByContext('down')
|
|
264
283
|
},
|
|
265
284
|
{
|
|
266
285
|
id: 'subtree.duplicate',
|
|
@@ -269,8 +288,7 @@ export const coreActions = [
|
|
|
269
288
|
listed: true,
|
|
270
289
|
changesDocument: true,
|
|
271
290
|
keys: [{ key: 'd', mod: true, shift: true }],
|
|
272
|
-
command: sectionCommands.duplicateElement
|
|
273
|
-
variantId: (state) => (unpointedRequiredSelectionTarget(state) ? null : 'subtree.duplicate')
|
|
291
|
+
command: sectionCommands.duplicateElement
|
|
274
292
|
},
|
|
275
293
|
{
|
|
276
294
|
id: 'format.toggleTask',
|
|
@@ -295,8 +313,7 @@ export const coreActions = [
|
|
|
295
313
|
listed: true,
|
|
296
314
|
changesDocument: true,
|
|
297
315
|
keys: [{ key: 'Backspace', mod: true, shift: true }],
|
|
298
|
-
command: sectionCommands.deleteElement
|
|
299
|
-
variantId: (state) => (unpointedRequiredSelectionTarget(state) ? null : 'subtree.delete')
|
|
316
|
+
command: sectionCommands.deleteElement
|
|
300
317
|
},
|
|
301
318
|
{
|
|
302
319
|
id: 'document.undo',
|
|
@@ -113,8 +113,6 @@ export interface SelectedBlock {
|
|
|
113
113
|
export type MoveDirection = 'up' | 'down';
|
|
114
114
|
/** 削除の対象。選択の形から決まる(広い対象から順に、表 → 列 → 行と判定する) */
|
|
115
115
|
export type TableDeleteTarget = 'table' | 'column' | 'row';
|
|
116
|
-
/** 列の配置を動かす向き。「指定なし ← 左 ← 中央 ← 右」の線上を 1 段ずつ動く */
|
|
117
|
-
export type AlignDirection = 'leftward' | 'rightward';
|
|
118
116
|
/** 列を動かす向き。行を動かす向きは `MoveDirection` と同じもので足りる */
|
|
119
117
|
export type ColumnDirection = 'left' | 'right';
|
|
120
118
|
/** 表の中で選択を広げる向き。上下は行、左右は列をたどる */
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Plugin } from 'prosemirror-state';
|
|
2
|
+
/**
|
|
3
|
+
* 見出しのレベルを、書き換えのたびに構造上の深さへ合わせ直す。
|
|
4
|
+
*
|
|
5
|
+
* 合わせ直しを個々の操作へ配らず 1 つの覆いにまとめるのは、**食い違いの作られ方が
|
|
6
|
+
* 1 つではない**ためである。階層操作だけでなく、範囲選択での削除・貼り付け・本文の
|
|
7
|
+
* 差し替え・取り消しのどれもが食い違いを作りうる(→ `correctHeadingLevels`)。
|
|
8
|
+
* 入口ごとに手当てすると、必ずどれかが漏れる(箇条書きの形と同じ構図 →
|
|
9
|
+
* `listStructurePlugin`)。
|
|
10
|
+
*
|
|
11
|
+
* **取り消しの履歴から外さない。** 合わせ直しは書き換えの直後に続くため、取り消しの
|
|
12
|
+
* 単位としては元の操作と同じまとまりに入り、1 回で操作の前へ戻る。
|
|
13
|
+
*/
|
|
14
|
+
export declare function headingLevelPlugin(): Plugin;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Plugin } from 'prosemirror-state';
|
|
2
|
+
import { sectionTree } from '../../models/document/sectionTree';
|
|
3
|
+
/**
|
|
4
|
+
* 見出しのレベルを、書き換えのたびに構造上の深さへ合わせ直す。
|
|
5
|
+
*
|
|
6
|
+
* 合わせ直しを個々の操作へ配らず 1 つの覆いにまとめるのは、**食い違いの作られ方が
|
|
7
|
+
* 1 つではない**ためである。階層操作だけでなく、範囲選択での削除・貼り付け・本文の
|
|
8
|
+
* 差し替え・取り消しのどれもが食い違いを作りうる(→ `correctHeadingLevels`)。
|
|
9
|
+
* 入口ごとに手当てすると、必ずどれかが漏れる(箇条書きの形と同じ構図 →
|
|
10
|
+
* `listStructurePlugin`)。
|
|
11
|
+
*
|
|
12
|
+
* **取り消しの履歴から外さない。** 合わせ直しは書き換えの直後に続くため、取り消しの
|
|
13
|
+
* 単位としては元の操作と同じまとまりに入り、1 回で操作の前へ戻る。
|
|
14
|
+
*/
|
|
15
|
+
export function headingLevelPlugin() {
|
|
16
|
+
return new Plugin({
|
|
17
|
+
appendTransaction: (transactions, _oldState, newState) => transactions.some((transaction) => transaction.docChanged)
|
|
18
|
+
? sectionTree.correctHeadingLevels(newState)
|
|
19
|
+
: null
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -2,6 +2,7 @@ import { closeHistory } from 'prosemirror-history';
|
|
|
2
2
|
import { AllSelection, NodeSelection, Plugin, PluginKey } from 'prosemirror-state';
|
|
3
3
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
4
4
|
import { outlineSchema } from '../../models/document/schema';
|
|
5
|
+
import { hasPastedTable } from '../../utils/pastedTable';
|
|
5
6
|
const IMAGE = outlineSchema.nodes.image;
|
|
6
7
|
const imagePasteKey = new PluginKey('imagePaste');
|
|
7
8
|
/**
|
|
@@ -94,6 +95,9 @@ function handlePaste(view, event, getUpload) {
|
|
|
94
95
|
const files = imageFilesOf(event.clipboardData);
|
|
95
96
|
if (files.length === 0)
|
|
96
97
|
return false;
|
|
98
|
+
// 表が同時に届いているなら、画像より表を優先して譲る
|
|
99
|
+
if (hasPastedTable(event.clipboardData))
|
|
100
|
+
return false;
|
|
97
101
|
// その位置に画像を置けるか。種別の表を持たず、内容の定義へ問う(要件 4.5 の延長)
|
|
98
102
|
if (!canPlaceImage(view.state))
|
|
99
103
|
return false;
|
|
@@ -103,6 +107,19 @@ function handlePaste(view, event, getUpload) {
|
|
|
103
107
|
/**
|
|
104
108
|
* クリップボードの画像ファイル。**画像ファイルがあれば、同時に届く HTML や文字より
|
|
105
109
|
* 優先する**(ブラウザからの画像コピーは両方を含み、HTML の側は読み込み規則が無く落ちる)。
|
|
110
|
+
* ただし表が同時に届いているときは譲る(→ `hasPastedTable`)。
|
|
111
|
+
*
|
|
112
|
+
* macOS のアプリ(Numbers・Excel・Keynote など)は、選んだ範囲の**見た目の写しを画像として**
|
|
113
|
+
* クリップボードへ載せる。「画像ファイルがあれば優先する」だけで判定すると、スプレッドシート
|
|
114
|
+
* のコピーが表ではなく画像になる(0.0.3 で公開した回帰。利用者の報告 → 実機で確認、2026-09-04)。
|
|
115
|
+
*
|
|
116
|
+
* **実機で確かめた中身**: Excel(Mac)は 672 バイトの `image/png`——**描けてしまうので、
|
|
117
|
+
* 表が黙って絵に化ける**。Numbers は `image/png` を名乗る **0 バイトのファイル**で、
|
|
118
|
+
* 描けずに失敗の表示だけが残る。どちらも書き手が写したのは表である。
|
|
119
|
+
*
|
|
120
|
+
* **見分けているのは「画像ファイルがあること」ではなかった。** ブラウザからの画像コピーを
|
|
121
|
+
* 画像たらしめているのは、同時に届く HTML が `<img>` であることである。表が届いているなら、
|
|
122
|
+
* 書き手がコピーしたのは表であって、その見た目ではない。
|
|
106
123
|
*/
|
|
107
124
|
function imageFilesOf(data) {
|
|
108
125
|
if (!data)
|
|
@@ -8,6 +8,7 @@ import { MAX_HEADING_LEVEL } from '../../models/document/document.types';
|
|
|
8
8
|
import { outlineSchema } from '../../models/document/schema';
|
|
9
9
|
import { sectionTree } from '../../models/document/sectionTree';
|
|
10
10
|
import { markDocumentReplacement } from '../transaction';
|
|
11
|
+
import { hasPastedTable } from '../../utils/pastedTable';
|
|
11
12
|
const n = outlineSchema.nodes;
|
|
12
13
|
/**
|
|
13
14
|
* クリップボードとのやり取りをマークダウンで行う。
|
|
@@ -30,6 +31,18 @@ export function markdownClipboardPlugin() {
|
|
|
30
31
|
return false;
|
|
31
32
|
if (isInTable(view.state))
|
|
32
33
|
return false;
|
|
34
|
+
/**
|
|
35
|
+
* **表が同時に届いているなら、文字ではなく表として貼られるべきである**
|
|
36
|
+
* (要件 1.2)。スプレッドシートはタブ区切りの文字と表の HTML を同時に
|
|
37
|
+
* 載せる。ここで文字を読むと、表が 1 行に潰れる。譲った先(編集基盤の
|
|
38
|
+
* 既定の貼り付け)が、HTML を表として取り込む。
|
|
39
|
+
*
|
|
40
|
+
* **置く位置が仕様である。** 読み取り専用・記法を解釈しない場所・表の中と
|
|
41
|
+
* いう 3 つの判断より後に置く。先に置くと、記法を解釈しない場所で表を
|
|
42
|
+
* 貼ったときに、譲った先が表を作ろうとする。
|
|
43
|
+
*/
|
|
44
|
+
if (hasPastedTable(event.clipboardData))
|
|
45
|
+
return false;
|
|
33
46
|
const parsed = parseMarkdown(text);
|
|
34
47
|
if (!parsed.ok)
|
|
35
48
|
return false;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Plugin } from 'prosemirror-state';
|
|
2
|
+
/**
|
|
3
|
+
* 貼り付けられた HTML を、このエディタが読める形へ書き換える。
|
|
4
|
+
*
|
|
5
|
+
* **直すのはマス目の中だけである。** このエディタのマス目は `inline*` で、ブロック要素を
|
|
6
|
+
* 置けない(`schema.ts`「セル内はインラインのみ」)。Numbers はマス目の中に `<p>` を
|
|
7
|
+
* 入れてくるため、そのまま読ませると編集基盤が置けないブロックをマス目の外へ出し、
|
|
8
|
+
* **表がマス目の数だけ割れる**(利用者の実機データで確認、2026-09-04)。
|
|
9
|
+
*
|
|
10
|
+
* **直すのは 2 つある。**
|
|
11
|
+
*
|
|
12
|
+
* 1. マス目の中のブロックを取り除く(Numbers 対策)
|
|
13
|
+
* 2. **先頭行を見出し行にする**(要件 1.5)
|
|
14
|
+
*
|
|
15
|
+
* 書き換えは**全部の貼り付けで走る**。編集基盤は `parseFromClipboard` を `handlePaste` より
|
|
16
|
+
* 先に呼ぶためである。書き換えた結果が使われるのは、どのプラグインも受け止めなかった
|
|
17
|
+
* ときだけになる。表を含まない HTML では 1 文字も変えずに抜ける。
|
|
18
|
+
*/
|
|
19
|
+
export declare function tablePastePlugin(): Plugin;
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { Plugin } from 'prosemirror-state';
|
|
2
|
+
import { isInTable, selectedRect } from 'prosemirror-tables';
|
|
3
|
+
/**
|
|
4
|
+
* 貼り付けられた HTML を、このエディタが読める形へ書き換える。
|
|
5
|
+
*
|
|
6
|
+
* **直すのはマス目の中だけである。** このエディタのマス目は `inline*` で、ブロック要素を
|
|
7
|
+
* 置けない(`schema.ts`「セル内はインラインのみ」)。Numbers はマス目の中に `<p>` を
|
|
8
|
+
* 入れてくるため、そのまま読ませると編集基盤が置けないブロックをマス目の外へ出し、
|
|
9
|
+
* **表がマス目の数だけ割れる**(利用者の実機データで確認、2026-09-04)。
|
|
10
|
+
*
|
|
11
|
+
* **直すのは 2 つある。**
|
|
12
|
+
*
|
|
13
|
+
* 1. マス目の中のブロックを取り除く(Numbers 対策)
|
|
14
|
+
* 2. **先頭行を見出し行にする**(要件 1.5)
|
|
15
|
+
*
|
|
16
|
+
* 書き換えは**全部の貼り付けで走る**。編集基盤は `parseFromClipboard` を `handlePaste` より
|
|
17
|
+
* 先に呼ぶためである。書き換えた結果が使われるのは、どのプラグインも受け止めなかった
|
|
18
|
+
* ときだけになる。表を含まない HTML では 1 文字も変えずに抜ける。
|
|
19
|
+
*/
|
|
20
|
+
export function tablePastePlugin() {
|
|
21
|
+
return new Plugin({
|
|
22
|
+
props: {
|
|
23
|
+
transformPastedHTML: (html, view) => rewrite(html, view)
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 貼り付けられた HTML を、このエディタが読める形へ書き換える。
|
|
29
|
+
*
|
|
30
|
+
* 直すものが 1 つも無ければ、渡された文字列をそのまま返す。読み直して書き出すと、
|
|
31
|
+
* 直す必要の無い HTML まで別の文字列になる。
|
|
32
|
+
*/
|
|
33
|
+
function rewrite(html, view) {
|
|
34
|
+
const doc = new DOMParser().parseFromString(html, 'text/html');
|
|
35
|
+
const tables = doc.querySelectorAll('table');
|
|
36
|
+
if (tables.length === 0)
|
|
37
|
+
return html;
|
|
38
|
+
const plan = planFor(view.state);
|
|
39
|
+
let rewritten = false;
|
|
40
|
+
for (const table of tables) {
|
|
41
|
+
if (applyCellKinds(table, doc, plan))
|
|
42
|
+
rewritten = true;
|
|
43
|
+
}
|
|
44
|
+
for (const cell of doc.querySelectorAll('td, th')) {
|
|
45
|
+
const lines = flatten(cell, doc);
|
|
46
|
+
if (lines === null)
|
|
47
|
+
continue;
|
|
48
|
+
cell.innerHTML = lines.join('<br>');
|
|
49
|
+
rewritten = true;
|
|
50
|
+
}
|
|
51
|
+
return rewritten ? doc.documentElement.outerHTML : html;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 貼り先から、マス目の種別を決める。
|
|
55
|
+
*
|
|
56
|
+
* **表の中へ貼るときは、貼り先のマス目の種別と配置指定を保つ。** そこでの貼り付けは
|
|
57
|
+
* 「カーソルのマス目を左上として置き換える」ことであり(要件 3.1)、見出しかどうかは
|
|
58
|
+
* 貼り先の表が決める。`prosemirror-tables` は既定で**貼った側の種別を勝たせる**ため、
|
|
59
|
+
* 見出しの行へ貼ると見出しでなくなり、`th` を持つ表を本文の行へ貼ると見出しが混ざる
|
|
60
|
+
* (→ `gap-analysis.md` 8.4)。
|
|
61
|
+
*
|
|
62
|
+
* **見出しが 1 つも無い表は保てない。** GFM の表は見出し行を必須とし、書き出しは 1 行目を
|
|
63
|
+
* 無条件に見出しとして書く。放っておくと、保存の前と後で見た目が変わる。
|
|
64
|
+
*
|
|
65
|
+
* 配置指定は**見出し行のマス目**に載っている。そのマス目ごと置き換わるため、引き継がないと
|
|
66
|
+
* 表全体の配置指定が消える。
|
|
67
|
+
*/
|
|
68
|
+
function planFor(state) {
|
|
69
|
+
if (!isInTable(state))
|
|
70
|
+
return { kind: 'new' };
|
|
71
|
+
const rect = selectedRect(state);
|
|
72
|
+
// 見出し行は 1 行目だけである。そこから始まらないなら、すべて本文のマス目になる
|
|
73
|
+
if (rect.top !== 0)
|
|
74
|
+
return { kind: 'body' };
|
|
75
|
+
const aligns = [];
|
|
76
|
+
for (let column = rect.left; column < rect.map.width; column += 1) {
|
|
77
|
+
aligns.push(rect.table.nodeAt(rect.map.map[column])?.attrs.align ?? null);
|
|
78
|
+
}
|
|
79
|
+
return { kind: 'header', aligns };
|
|
80
|
+
}
|
|
81
|
+
/** 表のマス目の種別をそろえる。書き換えたら `true` */
|
|
82
|
+
function applyCellKinds(table, doc, plan) {
|
|
83
|
+
const rows = Array.from(table.querySelectorAll('tr'));
|
|
84
|
+
if (rows.length === 0)
|
|
85
|
+
return false;
|
|
86
|
+
// 表の外へ貼るときは、`th` を 1 つでも持つ表に触らない。どこが見出しかを表が持っている
|
|
87
|
+
if (plan.kind === 'new') {
|
|
88
|
+
if (table.querySelector('th'))
|
|
89
|
+
return false;
|
|
90
|
+
return retagRow(rows[0], 'th', doc, null);
|
|
91
|
+
}
|
|
92
|
+
let rewritten = false;
|
|
93
|
+
rows.forEach((row, index) => {
|
|
94
|
+
const header = plan.kind === 'header' && index === 0;
|
|
95
|
+
const aligns = header ? plan.aligns : null;
|
|
96
|
+
if (retagRow(row, header ? 'th' : 'td', doc, aligns))
|
|
97
|
+
rewritten = true;
|
|
98
|
+
});
|
|
99
|
+
return rewritten;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* 行のマス目を、指定した種別と配置指定にそろえる。書き換えたら `true`。
|
|
103
|
+
*
|
|
104
|
+
* `aligns` を渡したときは、貼り先が配置指定を持たない列で**貼った側の配置指定も落とす**。
|
|
105
|
+
* 保つのは貼り先の配置であって、コピー元の見た目ではない。
|
|
106
|
+
*/
|
|
107
|
+
function retagRow(row, tag, doc, aligns) {
|
|
108
|
+
let rewritten = false;
|
|
109
|
+
Array.from(row.children).forEach((cell, index) => {
|
|
110
|
+
if (cell.tagName !== 'TD' && cell.tagName !== 'TH')
|
|
111
|
+
return;
|
|
112
|
+
const align = aligns ? (aligns[index] ?? null) : undefined;
|
|
113
|
+
const keepsTag = cell.tagName.toLowerCase() === tag;
|
|
114
|
+
if (keepsTag && align === undefined)
|
|
115
|
+
return;
|
|
116
|
+
const replacement = doc.createElement(tag);
|
|
117
|
+
for (const attribute of Array.from(cell.attributes)) {
|
|
118
|
+
replacement.setAttribute(attribute.name, attribute.value);
|
|
119
|
+
}
|
|
120
|
+
replacement.innerHTML = cell.innerHTML;
|
|
121
|
+
if (align !== undefined)
|
|
122
|
+
replacement.style.textAlign = align ?? '';
|
|
123
|
+
// 種別も配置指定も変わらないなら、書き換えたことにしない
|
|
124
|
+
if (keepsTag && replacement.outerHTML === cell.outerHTML)
|
|
125
|
+
return;
|
|
126
|
+
cell.replaceWith(replacement);
|
|
127
|
+
rewritten = true;
|
|
128
|
+
});
|
|
129
|
+
return rewritten;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* マス目の中身を、行の並びへ均す。ブロックが 1 つも無ければ `null`(触らない印)。
|
|
133
|
+
*
|
|
134
|
+
* 取り除いたブロックの区切りは `<br>` になる。`<br>` はマス目の中の改行(`hard_break`)
|
|
135
|
+
* になり、書き出しも `<br>` になる(`schema.ts` の `htmlLineBreak`)。**既にある道に
|
|
136
|
+
* 合流する。**
|
|
137
|
+
*
|
|
138
|
+
* **中身に文字を 1 つも持たないブロックは落とす。** Numbers は中身の無いマス目を
|
|
139
|
+
* `<p><br></p>` で書くため、そのまま置き換えると空のマス目すべてに `<br>` が入る。
|
|
140
|
+
*
|
|
141
|
+
* マス目の中に表が入れ子になっていれば、内側の表も平らになる。マークダウンの表に入れ子は
|
|
142
|
+
* 書けないので、失うのは元から書けないものだけである。
|
|
143
|
+
*/
|
|
144
|
+
function flatten(cell, doc) {
|
|
145
|
+
const lines = [];
|
|
146
|
+
let buffer = doc.createElement('div');
|
|
147
|
+
let found = false;
|
|
148
|
+
const flush = () => {
|
|
149
|
+
if (buffer.textContent?.trim())
|
|
150
|
+
lines.push(buffer.innerHTML);
|
|
151
|
+
buffer = doc.createElement('div');
|
|
152
|
+
};
|
|
153
|
+
const walk = (parent) => {
|
|
154
|
+
for (const child of Array.from(parent.childNodes)) {
|
|
155
|
+
if (child instanceof Element && isBlock(child)) {
|
|
156
|
+
found = true;
|
|
157
|
+
flush();
|
|
158
|
+
walk(child);
|
|
159
|
+
flush();
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
buffer.append(child.cloneNode(true));
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
walk(cell);
|
|
166
|
+
flush();
|
|
167
|
+
return found ? lines : null;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* ブロック要素か。`<br>` はマス目の中の改行として使うので、ここには含めない。
|
|
171
|
+
*
|
|
172
|
+
* 表そのもの(`table` / `tr` / `td` …)を含めているのは、マス目の中の入れ子の表を
|
|
173
|
+
* 平らにするためである。
|
|
174
|
+
*/
|
|
175
|
+
function isBlock(element) {
|
|
176
|
+
return BLOCK.has(element.tagName.toLowerCase());
|
|
177
|
+
}
|
|
178
|
+
const BLOCK = new Set([
|
|
179
|
+
'address',
|
|
180
|
+
'article',
|
|
181
|
+
'aside',
|
|
182
|
+
'blockquote',
|
|
183
|
+
'caption',
|
|
184
|
+
'dd',
|
|
185
|
+
'details',
|
|
186
|
+
'div',
|
|
187
|
+
'dl',
|
|
188
|
+
'dt',
|
|
189
|
+
'fieldset',
|
|
190
|
+
'figcaption',
|
|
191
|
+
'figure',
|
|
192
|
+
'footer',
|
|
193
|
+
'form',
|
|
194
|
+
'h1',
|
|
195
|
+
'h2',
|
|
196
|
+
'h3',
|
|
197
|
+
'h4',
|
|
198
|
+
'h5',
|
|
199
|
+
'h6',
|
|
200
|
+
'header',
|
|
201
|
+
'hgroup',
|
|
202
|
+
'hr',
|
|
203
|
+
'li',
|
|
204
|
+
'main',
|
|
205
|
+
'nav',
|
|
206
|
+
'ol',
|
|
207
|
+
'p',
|
|
208
|
+
'pre',
|
|
209
|
+
'section',
|
|
210
|
+
'table',
|
|
211
|
+
'tbody',
|
|
212
|
+
'td',
|
|
213
|
+
'tfoot',
|
|
214
|
+
'th',
|
|
215
|
+
'thead',
|
|
216
|
+
'tr',
|
|
217
|
+
'ul'
|
|
218
|
+
]);
|
|
@@ -19,8 +19,6 @@ export declare function isDocumentReplacement(transaction: Transaction): boolean
|
|
|
19
19
|
* 書き換えまで通すと二重に写り、複数の対象を同じセクションへ積む場面で文書の外を指す。
|
|
20
20
|
*/
|
|
21
21
|
export declare function moveContent(tr: Transaction, from: number, to: number, insertAt: number): number;
|
|
22
|
-
/** 移動先のセクションとその配下の見出しレベルを、新しい深さへ合わせ直す */
|
|
23
|
-
export declare function syncFrom(tr: Transaction, pos: number): void;
|
|
24
22
|
/** その位置のブロックを指した状態にする。操作の後も対象を指し続けるために使う(要件 5.8) */
|
|
25
23
|
export declare function selectBlockAt(tr: Transaction, pos: number): void;
|
|
26
24
|
export declare function setCursor(tr: Transaction, pos: number): void;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { NodeSelection, TextSelection } from 'prosemirror-state';
|
|
2
|
-
import { sectionTree } from '../models/document/sectionTree';
|
|
3
2
|
/**
|
|
4
|
-
* `Transaction`
|
|
5
|
-
* 依存は `prosemirror-state`
|
|
3
|
+
* `Transaction` を組み立てる道具。コマンドでもプラグインでもない、`operations` 全体で共有するもの。
|
|
4
|
+
* 依存は `prosemirror-state` だけに保つ。
|
|
6
5
|
*/
|
|
7
6
|
const DOCUMENT_REPLACEMENT = 'markdown-editor:document-replacement';
|
|
8
7
|
/**
|
|
@@ -35,12 +34,6 @@ export function moveContent(tr, from, to, insertAt) {
|
|
|
35
34
|
tr.delete(from, to);
|
|
36
35
|
return tr.mapping.slice(before).map(insertAt, -1);
|
|
37
36
|
}
|
|
38
|
-
/** 移動先のセクションとその配下の見出しレベルを、新しい深さへ合わせ直す */
|
|
39
|
-
export function syncFrom(tr, pos) {
|
|
40
|
-
const ref = sectionTree.resolveSection(tr.doc, pos + 1);
|
|
41
|
-
if (ref)
|
|
42
|
-
sectionTree.syncSectionLevels(tr, ref);
|
|
43
|
-
}
|
|
44
37
|
/** その位置のブロックを指した状態にする。操作の後も対象を指し続けるために使う(要件 5.8) */
|
|
45
38
|
export function selectBlockAt(tr, pos) {
|
|
46
39
|
tr.setSelection(NodeSelection.create(tr.doc, pos));
|
|
@@ -15,8 +15,10 @@ import { imageViewPlugin } from '../operations/plugins/imageView';
|
|
|
15
15
|
import { blockHandlePlugin } from '../operations/plugins/blockHandle';
|
|
16
16
|
import { frontMatterGuardPlugin } from '../operations/plugins/frontMatterGuard';
|
|
17
17
|
import { frontMatterViewPlugin } from '../operations/plugins/frontMatterView';
|
|
18
|
+
import { headingLevelPlugin } from '../operations/plugins/headingLevel';
|
|
18
19
|
import { listStructurePlugin } from '../operations/plugins/listStructure';
|
|
19
20
|
import { markdownClipboardPlugin } from '../operations/plugins/markdownClipboard';
|
|
21
|
+
import { tablePastePlugin } from '../operations/plugins/tablePaste';
|
|
20
22
|
import { requiredSelectionEntryPlugin } from '../operations/plugins/requiredSelectionEntry';
|
|
21
23
|
import { tableHandlesPlugin } from '../operations/plugins/tableHandles';
|
|
22
24
|
import { writeFrontMatterFields as writeFrontMatterFieldsCommand } from '../operations/commands/frontMatter';
|
|
@@ -69,6 +71,10 @@ export function createEditorSession(element, options) {
|
|
|
69
71
|
// 後段の `markdownClipboard` が従来どおり働く)
|
|
70
72
|
imagePastePlugin(options.imageUpload ?? (() => undefined), () => imageText()),
|
|
71
73
|
markdownClipboardPlugin(),
|
|
74
|
+
// 貼り付けた HTML の書き換え。**並び順に左右されない**(`transformPastedHTML` は
|
|
75
|
+
// 登録した全部が順に適用され、`handlePaste` より先に走る)。貼り付けを扱うものを
|
|
76
|
+
// 離さないため、ここへ置く
|
|
77
|
+
tablePastePlugin(),
|
|
72
78
|
gapCursor(),
|
|
73
79
|
// 表そのものを指す選択を保つ。既定では全セルを覆うセル範囲の選択へ変換され、
|
|
74
80
|
// 表だけがブロックとして指せない状態になる(セル範囲の選択は変換とは無関係に働く)
|
|
@@ -76,6 +82,9 @@ export function createEditorSession(element, options) {
|
|
|
76
82
|
tableHandlesPlugin(),
|
|
77
83
|
...createListPlugins({ schema: outlineSchema }),
|
|
78
84
|
listStructurePlugin(),
|
|
85
|
+
// 文書の形を整えるものどうしは並び順に左右されない。編集基盤は誰も足さなくなるまで
|
|
86
|
+
// `appendTransaction` を回すため、他が足した書き換えもここを通る
|
|
87
|
+
headingLevelPlugin(),
|
|
79
88
|
sectionViewPlugin(),
|
|
80
89
|
// NodeView を持つ表示の仕組み。どうしも相互作用しないため、同じ場所へまとめる。
|
|
81
90
|
// 文言は表示を更新するたびに読み直す(差し替えの反映は次の表示更新から)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 同時に届いた HTML が表を含むか。**含むなら、書き手が写したのは表である。**
|
|
3
|
+
*
|
|
4
|
+
* 貼り付けは形式ごとに別の道へ分かれる。どれを先に取るかを決めるのがこの判定で、
|
|
5
|
+
* `imagePaste`(画像より表を先に読む)と `markdownClipboard`(タブ区切りの文字より
|
|
6
|
+
* 表を先に読む)の 2 か所が読む。**同じことを調べる処理を 2 つ持たない。**
|
|
7
|
+
*
|
|
8
|
+
* 文字列から `<table` を探さずに HTML として読むのは、`<table` が注記や属性の値の中にも
|
|
9
|
+
* 現れうるためである。
|
|
10
|
+
*/
|
|
11
|
+
export declare function hasPastedTable(data: DataTransfer | null): boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 同時に届いた HTML が表を含むか。**含むなら、書き手が写したのは表である。**
|
|
3
|
+
*
|
|
4
|
+
* 貼り付けは形式ごとに別の道へ分かれる。どれを先に取るかを決めるのがこの判定で、
|
|
5
|
+
* `imagePaste`(画像より表を先に読む)と `markdownClipboard`(タブ区切りの文字より
|
|
6
|
+
* 表を先に読む)の 2 か所が読む。**同じことを調べる処理を 2 つ持たない。**
|
|
7
|
+
*
|
|
8
|
+
* 文字列から `<table` を探さずに HTML として読むのは、`<table` が注記や属性の値の中にも
|
|
9
|
+
* 現れうるためである。
|
|
10
|
+
*/
|
|
11
|
+
export function hasPastedTable(data) {
|
|
12
|
+
const html = data?.getData('text/html');
|
|
13
|
+
if (!html)
|
|
14
|
+
return false;
|
|
15
|
+
return new DOMParser().parseFromString(html, 'text/html').querySelector('table') !== null;
|
|
16
|
+
}
|
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.6",
|
|
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.",
|