@14ch/svelte-md-outliner 0.0.1
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/README.ja.md +190 -0
- package/README.md +190 -0
- package/dist/assets/styles/editor.css +1459 -0
- package/dist/assets/styles/theme.css +486 -0
- package/dist/components/ContextMenu.svelte +279 -0
- package/dist/components/ContextMenu.svelte.d.ts +9 -0
- package/dist/components/EditorSurface.svelte +99 -0
- package/dist/components/EditorSurface.svelte.d.ts +16 -0
- package/dist/components/FocusBreadcrumb.svelte +138 -0
- package/dist/components/FocusBreadcrumb.svelte.d.ts +16 -0
- package/dist/components/MarkdownEditor.svelte +393 -0
- package/dist/components/MarkdownEditor.svelte.d.ts +119 -0
- package/dist/components/ShortcutHelpDialog.svelte +155 -0
- package/dist/components/ShortcutHelpDialog.svelte.d.ts +12 -0
- package/dist/components/internal/Dialog.svelte +157 -0
- package/dist/components/internal/Dialog.svelte.d.ts +23 -0
- package/dist/components/internal/Modal.svelte +181 -0
- package/dist/components/internal/Modal.svelte.d.ts +18 -0
- package/dist/components/internal/Popup.svelte +248 -0
- package/dist/components/internal/Popup.svelte.d.ts +26 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +28 -0
- package/dist/markdown.d.ts +13 -0
- package/dist/markdown.js +10 -0
- package/dist/messages/en.d.ts +2 -0
- package/dist/messages/en.js +107 -0
- package/dist/messages/index.d.ts +13 -0
- package/dist/messages/index.js +31 -0
- package/dist/messages/ja.d.ts +2 -0
- package/dist/messages/ja.js +112 -0
- package/dist/messages/messages.types.d.ts +59 -0
- package/dist/messages/messages.types.js +1 -0
- package/dist/models/document/bodySelection.d.ts +32 -0
- package/dist/models/document/bodySelection.js +43 -0
- package/dist/models/document/document.types.d.ts +27 -0
- package/dist/models/document/document.types.js +8 -0
- package/dist/models/document/foldable.d.ts +18 -0
- package/dist/models/document/foldable.js +21 -0
- package/dist/models/document/schema.d.ts +2 -0
- package/dist/models/document/schema.js +428 -0
- package/dist/models/document/sectionTree.d.ts +15 -0
- package/dist/models/document/sectionTree.js +123 -0
- package/dist/models/markdown/blockOutline.d.ts +9 -0
- package/dist/models/markdown/blockOutline.js +82 -0
- package/dist/models/markdown/frontMatter.d.ts +98 -0
- package/dist/models/markdown/frontMatter.js +300 -0
- package/dist/models/markdown/markdown.types.d.ts +60 -0
- package/dist/models/markdown/markdown.types.js +1 -0
- package/dist/models/markdown/markdownIt.d.ts +1 -0
- package/dist/models/markdown/markdownIt.js +92 -0
- package/dist/models/markdown/parser.d.ts +4 -0
- package/dist/models/markdown/parser.js +505 -0
- package/dist/models/markdown/plainText.d.ts +1 -0
- package/dist/models/markdown/plainText.js +25 -0
- package/dist/models/markdown/serializer.d.ts +17 -0
- package/dist/models/markdown/serializer.js +453 -0
- package/dist/models/viewState/viewState.types.d.ts +38 -0
- package/dist/models/viewState/viewState.types.js +17 -0
- package/dist/models/viewState/viewStateCodec.d.ts +31 -0
- package/dist/models/viewState/viewStateCodec.js +173 -0
- package/dist/operations/autoformat.d.ts +9 -0
- package/dist/operations/autoformat.js +86 -0
- package/dist/operations/commands/block.d.ts +24 -0
- package/dist/operations/commands/block.js +139 -0
- package/dist/operations/commands/codeBlock.d.ts +7 -0
- package/dist/operations/commands/codeBlock.js +26 -0
- package/dist/operations/commands/element.d.ts +67 -0
- package/dist/operations/commands/element.js +269 -0
- package/dist/operations/commands/frontMatter.d.ts +35 -0
- package/dist/operations/commands/frontMatter.js +120 -0
- package/dist/operations/commands/lineBreak.d.ts +9 -0
- package/dist/operations/commands/lineBreak.js +16 -0
- package/dist/operations/commands/link.d.ts +7 -0
- package/dist/operations/commands/link.js +21 -0
- package/dist/operations/commands/list.d.ts +126 -0
- package/dist/operations/commands/list.js +652 -0
- package/dist/operations/commands/mermaidBlock.d.ts +9 -0
- package/dist/operations/commands/mermaidBlock.js +28 -0
- package/dist/operations/commands/section.d.ts +217 -0
- package/dist/operations/commands/section.js +865 -0
- package/dist/operations/commands/sectionFold.d.ts +36 -0
- package/dist/operations/commands/sectionFold.js +219 -0
- package/dist/operations/commands/sectionJump.d.ts +8 -0
- package/dist/operations/commands/sectionJump.js +144 -0
- package/dist/operations/commands/selectedBlock.d.ts +37 -0
- package/dist/operations/commands/selectedBlock.js +170 -0
- package/dist/operations/commands/table.d.ts +64 -0
- package/dist/operations/commands/table.js +437 -0
- package/dist/operations/keymap/assemble.d.ts +22 -0
- package/dist/operations/keymap/assemble.js +165 -0
- package/dist/operations/keymap/coreActions.d.ts +2 -0
- package/dist/operations/keymap/coreActions.js +711 -0
- package/dist/operations/keymap/menuItems.d.ts +52 -0
- package/dist/operations/keymap/menuItems.js +114 -0
- package/dist/operations/keymap/shortcutKeys.d.ts +42 -0
- package/dist/operations/keymap/shortcutKeys.js +114 -0
- package/dist/operations/keymap/viewActions.d.ts +30 -0
- package/dist/operations/keymap/viewActions.js +182 -0
- package/dist/operations/operations.types.d.ts +121 -0
- package/dist/operations/operations.types.js +1 -0
- package/dist/operations/plugins/blockHandle.d.ts +25 -0
- package/dist/operations/plugins/blockHandle.js +112 -0
- package/dist/operations/plugins/contextMenu.d.ts +33 -0
- package/dist/operations/plugins/contextMenu.js +204 -0
- package/dist/operations/plugins/focus.d.ts +39 -0
- package/dist/operations/plugins/focus.js +350 -0
- package/dist/operations/plugins/foldClick.d.ts +11 -0
- package/dist/operations/plugins/foldClick.js +117 -0
- package/dist/operations/plugins/foldGuard.d.ts +15 -0
- package/dist/operations/plugins/foldGuard.js +31 -0
- package/dist/operations/plugins/frontMatterGuard.d.ts +21 -0
- package/dist/operations/plugins/frontMatterGuard.js +150 -0
- package/dist/operations/plugins/frontMatterView.d.ts +34 -0
- package/dist/operations/plugins/frontMatterView.js +137 -0
- package/dist/operations/plugins/linkPaste.d.ts +3 -0
- package/dist/operations/plugins/linkPaste.js +20 -0
- package/dist/operations/plugins/listStructure.d.ts +13 -0
- package/dist/operations/plugins/listStructure.js +18 -0
- package/dist/operations/plugins/markdownClipboard.d.ts +8 -0
- package/dist/operations/plugins/markdownClipboard.js +208 -0
- package/dist/operations/plugins/mermaidView.d.ts +20 -0
- package/dist/operations/plugins/mermaidView.js +206 -0
- package/dist/operations/plugins/requiredSelectionEntry.d.ts +10 -0
- package/dist/operations/plugins/requiredSelectionEntry.js +124 -0
- package/dist/operations/plugins/sectionView.d.ts +12 -0
- package/dist/operations/plugins/sectionView.js +44 -0
- package/dist/operations/plugins/tabEscape.d.ts +21 -0
- package/dist/operations/plugins/tabEscape.js +41 -0
- package/dist/operations/plugins/tableHandles.d.ts +24 -0
- package/dist/operations/plugins/tableHandles.js +89 -0
- package/dist/operations/transaction.d.ts +26 -0
- package/dist/operations/transaction.js +51 -0
- package/dist/operations/transactionOrigin.d.ts +17 -0
- package/dist/operations/transactionOrigin.js +9 -0
- package/dist/states/contextMenuController.svelte.d.ts +57 -0
- package/dist/states/contextMenuController.svelte.js +206 -0
- package/dist/states/editorSession.d.ts +12 -0
- package/dist/states/editorSession.js +268 -0
- package/dist/states/editorSession.types.d.ts +57 -0
- package/dist/states/editorSession.types.js +1 -0
- package/dist/states/outlineViewController.svelte.d.ts +52 -0
- package/dist/states/outlineViewController.svelte.js +134 -0
- package/dist/utils/dateText.d.ts +25 -0
- package/dist/utils/dateText.js +71 -0
- package/dist/utils/geometry.types.d.ts +13 -0
- package/dist/utils/geometry.types.js +1 -0
- package/dist/utils/json.types.d.ts +4 -0
- package/dist/utils/json.types.js +1 -0
- package/dist/utils/platform.d.ts +8 -0
- package/dist/utils/platform.js +10 -0
- package/dist/utils/result.types.d.ts +7 -0
- package/dist/utils/result.types.js +1 -0
- package/package.json +109 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
コンテキストメニュー。分類ごとに項目を並べ、1 項目を「説明」と「キー表記」の 2 欄で見せる。
|
|
3
|
+
|
|
4
|
+
キーの判定を持たない。押されたキーはそのままコントローラへ渡し、照合は
|
|
5
|
+
`createKeyStrokeMatcher` が行う(キー入力は必ず正規化レイヤーを通す)。
|
|
6
|
+
開閉と選んでいる位置もコントローラが持ち、部品側に二重に持たせない。
|
|
7
|
+
-->
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import { tick } from 'svelte';
|
|
10
|
+
|
|
11
|
+
import type { EditorMessages } from '../messages/messages.types';
|
|
12
|
+
import { formatShortcutKeys } from '../operations/keymap/shortcutKeys';
|
|
13
|
+
import type { EditorAction, ShortcutCategory } from '../operations/operations.types';
|
|
14
|
+
import type { ContextMenuController } from '../states/contextMenuController.svelte';
|
|
15
|
+
import Popup from './internal/Popup.svelte';
|
|
16
|
+
|
|
17
|
+
interface Props {
|
|
18
|
+
controller: ContextMenuController;
|
|
19
|
+
text: EditorMessages;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let { controller, text }: Props = $props();
|
|
23
|
+
|
|
24
|
+
/** 同じページに複数のエディタが置かれても id が衝突しないようにする */
|
|
25
|
+
const uid = $props.id();
|
|
26
|
+
|
|
27
|
+
let menuRef: HTMLElement | undefined = $state();
|
|
28
|
+
let itemRefs: HTMLElement[] = $state([]);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 描くのは開いているあいだだけにする。
|
|
32
|
+
*
|
|
33
|
+
* キーの表記は実行環境で決まるため、**表示された後にだけ組み立てる**
|
|
34
|
+
* (サーバー側で出すと、macOS の利用者には差し替わるまで誤った表記が見える)。
|
|
35
|
+
* 分類をまたいだ通し番号も、ここで一度だけ振る。
|
|
36
|
+
*/
|
|
37
|
+
const groups = $derived.by(() => {
|
|
38
|
+
if (!controller.isOpen) return [];
|
|
39
|
+
|
|
40
|
+
let index = 0;
|
|
41
|
+
return controller.groups.map((group) => ({
|
|
42
|
+
category: group.category,
|
|
43
|
+
title: text.shortcutCategories[group.category],
|
|
44
|
+
items: group.actions.map((action) => ({
|
|
45
|
+
action,
|
|
46
|
+
index: index++,
|
|
47
|
+
// 向きが決まる操作は、いま起きる方の説明を引く
|
|
48
|
+
description: text.shortcuts[controller.descriptionIds[action.id] ?? action.id] ?? action.id,
|
|
49
|
+
// 同じキーを分け合う文脈では、押して実際に起きる側にだけ表記を付ける
|
|
50
|
+
keys: controller.keyLabelledIds.includes(action.id) ? formatShortcutKeys(action) : ''
|
|
51
|
+
}))
|
|
52
|
+
}));
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
/** 何も選んでいないあいだは指す先を持たない(開いた直後がこの状態) */
|
|
56
|
+
const activeId = $derived(
|
|
57
|
+
controller.isOpen && controller.activeIndex >= 0 ? itemId(controller.activeIndex) : undefined
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
function itemId(index: number): string {
|
|
61
|
+
return `${uid}-item-${index}`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function groupId(category: ShortcutCategory): string {
|
|
65
|
+
return `${uid}-group-${category}`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* キーの判定は持たない。受け取った出来事をそのまま渡す(正規化レイヤーを通す規約)。
|
|
70
|
+
*
|
|
71
|
+
* **キーで動かしたときだけ実フォーカスを移す。** ポインタを乗せただけで移すと、
|
|
72
|
+
* 乗せるたびにフォーカスが持って行かれる。受け止めたかどうかは、コントローラが
|
|
73
|
+
* 既定動作を止めたかで分かる。
|
|
74
|
+
*/
|
|
75
|
+
function handleKeyDown(event: KeyboardEvent): void {
|
|
76
|
+
controller.handleKey(event);
|
|
77
|
+
if (event.defaultPrevented) focusActive();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function execute(action: EditorAction): void {
|
|
81
|
+
controller.run(action);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 選んでいる項目へ実フォーカスを移す。
|
|
86
|
+
*
|
|
87
|
+
* 何も選んでいないあいだはコンテナにフォーカスが載ったままで、`Popup` が開くときに
|
|
88
|
+
* そこへ移している。移し先がコンテナの中なら閉じない(`Popup` の `onFocusOut` が
|
|
89
|
+
* 移り先を見ている)。
|
|
90
|
+
*/
|
|
91
|
+
function focusActive(): void {
|
|
92
|
+
const index = controller.activeIndex;
|
|
93
|
+
if (index < 0) return;
|
|
94
|
+
|
|
95
|
+
tick().then(() => itemRefs[index]?.focus());
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* メニューの外が押されたら閉じる。
|
|
100
|
+
*
|
|
101
|
+
* 編集エリアの中の押下はプラグインが受け止める(カーソルを動かさないため)。ここが見るのは
|
|
102
|
+
* 編集エリアの外である。**開いているあいだだけ**登録し、読み込みだけで `document` に触れない。
|
|
103
|
+
*/
|
|
104
|
+
$effect(() => {
|
|
105
|
+
if (!controller.isOpen) return;
|
|
106
|
+
|
|
107
|
+
const closeIfOutside = (event: MouseEvent) => {
|
|
108
|
+
const target = event.target;
|
|
109
|
+
if (target instanceof Node && menuRef?.contains(target)) return;
|
|
110
|
+
controller.close();
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
document.addEventListener('mousedown', closeIfOutside, true);
|
|
114
|
+
return () => document.removeEventListener('mousedown', closeIfOutside, true);
|
|
115
|
+
});
|
|
116
|
+
</script>
|
|
117
|
+
|
|
118
|
+
<Popup
|
|
119
|
+
open={controller.isOpen}
|
|
120
|
+
anchor={controller.anchor}
|
|
121
|
+
class="markdown-editor-context-menu"
|
|
122
|
+
ariaLabel={text.contextMenuLabel}
|
|
123
|
+
ariaActivedescendant={activeId}
|
|
124
|
+
onKeyDown={handleKeyDown}
|
|
125
|
+
onFocusOut={controller.close}
|
|
126
|
+
onClose={controller.close}
|
|
127
|
+
>
|
|
128
|
+
<!-- 中身は開いているあいだだけ描画する(ShortcutHelpDialog と同じ作法) -->
|
|
129
|
+
<div class="markdown-editor-context-menu__body" bind:this={menuRef}>
|
|
130
|
+
{#each groups as group (group.category)}
|
|
131
|
+
<ul
|
|
132
|
+
class="markdown-editor-context-menu__group"
|
|
133
|
+
role="group"
|
|
134
|
+
aria-labelledby={groupId(group.category)}
|
|
135
|
+
data-category={group.category}
|
|
136
|
+
>
|
|
137
|
+
<li class="markdown-editor-context-menu__group-title" id={groupId(group.category)}>
|
|
138
|
+
{group.title}
|
|
139
|
+
</li>
|
|
140
|
+
{#each group.items as item (item.action.id)}
|
|
141
|
+
<li class="markdown-editor-context-menu__row">
|
|
142
|
+
<!-- 実行できない操作はそもそも並ばない(無効として残さない) -->
|
|
143
|
+
<button
|
|
144
|
+
bind:this={itemRefs[item.index]}
|
|
145
|
+
type="button"
|
|
146
|
+
role="menuitem"
|
|
147
|
+
tabindex="-1"
|
|
148
|
+
id={itemId(item.index)}
|
|
149
|
+
class="markdown-editor-context-menu__item"
|
|
150
|
+
class:markdown-editor-context-menu__item--active={item.index ===
|
|
151
|
+
controller.activeIndex}
|
|
152
|
+
onclick={() => execute(item.action)}
|
|
153
|
+
onmouseenter={() => controller.setActive(item.index)}
|
|
154
|
+
onfocus={() => controller.setActive(item.index)}
|
|
155
|
+
>
|
|
156
|
+
<span class="markdown-editor-context-menu__description">{item.description}</span>
|
|
157
|
+
<span class="markdown-editor-context-menu__keys">{item.keys}</span>
|
|
158
|
+
</button>
|
|
159
|
+
</li>
|
|
160
|
+
{/each}
|
|
161
|
+
</ul>
|
|
162
|
+
{/each}
|
|
163
|
+
</div>
|
|
164
|
+
</Popup>
|
|
165
|
+
|
|
166
|
+
<style>
|
|
167
|
+
/**
|
|
168
|
+
* **行間は本文のものを引き継がない。** 本文の行間(1.8)は読み続ける面のための値で、
|
|
169
|
+
* メニューは地の文ではない。実行環境の既定(`normal`)へ戻す
|
|
170
|
+
* (引き継ぐと項目が 1 行ぶん高くなる)。
|
|
171
|
+
*/
|
|
172
|
+
.markdown-editor-context-menu__body {
|
|
173
|
+
max-height: var(--markdown-editor-menu-max-height);
|
|
174
|
+
min-width: 160px;
|
|
175
|
+
padding: 8px 0;
|
|
176
|
+
line-height: normal;
|
|
177
|
+
overflow-y: auto;
|
|
178
|
+
/* 端まで巻き取った続きを背後のページへ流さない(流れると閉じてしまう) */
|
|
179
|
+
overscroll-behavior: contain;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.markdown-editor-context-menu__group {
|
|
183
|
+
margin: 0;
|
|
184
|
+
padding: 0;
|
|
185
|
+
list-style: none;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* 線は分類の箱の上辺として引くので、上の空きは `margin`、下の空きは `padding` で取る。
|
|
190
|
+
*/
|
|
191
|
+
.markdown-editor-context-menu__group + .markdown-editor-context-menu__group {
|
|
192
|
+
border-top: 1px solid var(--markdown-editor-menu-separator);
|
|
193
|
+
margin-top: 8px;
|
|
194
|
+
padding-top: 8px;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* 分類の見出しは**どれも同じ見た目**にし、項目との差は文字の大きさだけで付ける。
|
|
199
|
+
*
|
|
200
|
+
* **ショートカット一覧の分類の見出しと同じ見た目である。** 同じものを 2 か所から
|
|
201
|
+
* 見せているので、片方を変えるならもう片方も変える(`shortcutHelpAppearance` の
|
|
202
|
+
* spec が食い違いを捕まえる)。
|
|
203
|
+
*/
|
|
204
|
+
.markdown-editor-context-menu__group-title {
|
|
205
|
+
padding: 0.2em 1em;
|
|
206
|
+
color: var(--markdown-editor-menu-group-title-color);
|
|
207
|
+
font-size: var(--markdown-editor-font-size-sm);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
.markdown-editor-context-menu__row {
|
|
211
|
+
margin: 0;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* 説明とキーの 2 欄の格子にする。**キー表記を持たない項目でも欄は残る**ので、
|
|
216
|
+
* 説明の左端が項目ごとにずれない。
|
|
217
|
+
*/
|
|
218
|
+
.markdown-editor-context-menu__item {
|
|
219
|
+
display: grid;
|
|
220
|
+
grid-template-columns: 1fr auto;
|
|
221
|
+
gap: 0 1.5em;
|
|
222
|
+
/* 説明とキー表記は同じ大きさなので、中央で合わせて崩れない */
|
|
223
|
+
align-items: center;
|
|
224
|
+
width: 100%;
|
|
225
|
+
padding: 8px 16px;
|
|
226
|
+
border: 0;
|
|
227
|
+
background: none;
|
|
228
|
+
color: inherit;
|
|
229
|
+
font: inherit;
|
|
230
|
+
text-align: left;
|
|
231
|
+
white-space: nowrap;
|
|
232
|
+
cursor: pointer;
|
|
233
|
+
transition: background-color 0.2s ease;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
@media (prefers-reduced-motion: reduce) {
|
|
237
|
+
.markdown-editor-context-menu__item {
|
|
238
|
+
transition: none;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/* 触れる端末でのターゲットの大きさ */
|
|
243
|
+
@media (max-width: 768px) {
|
|
244
|
+
.markdown-editor-context-menu__item {
|
|
245
|
+
min-height: var(--markdown-editor-touch-target);
|
|
246
|
+
padding: 12px 16px;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* **乗っている項目と選んでいる項目は同じ見え方にする。**
|
|
252
|
+
* ポインタで乗ることとキーで選ぶことは同じ「いまこれ」であり、2 通りに見せない。
|
|
253
|
+
* 触れる入力しかない環境では `:hover` が居座るため、囲って外す。
|
|
254
|
+
*/
|
|
255
|
+
@media (hover: hover) {
|
|
256
|
+
.markdown-editor-context-menu__item:hover,
|
|
257
|
+
.markdown-editor-context-menu__item--active {
|
|
258
|
+
background: var(--markdown-editor-menu-item-hover);
|
|
259
|
+
outline: none;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
.markdown-editor-context-menu__item--active {
|
|
264
|
+
background: var(--markdown-editor-menu-item-hover);
|
|
265
|
+
outline: none;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/* キーで到達したときだけ輪郭を出す(内側へ寄せて、項目の箱から食み出させない) */
|
|
269
|
+
.markdown-editor-context-menu__item:focus-visible {
|
|
270
|
+
background: var(--markdown-editor-menu-item-hover);
|
|
271
|
+
outline: 2px solid var(--markdown-editor-menu-focus-ring);
|
|
272
|
+
outline-offset: -2px;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
.markdown-editor-context-menu__keys {
|
|
276
|
+
color: var(--markdown-editor-menu-keys-color);
|
|
277
|
+
font-family: var(--markdown-editor-code-font);
|
|
278
|
+
}
|
|
279
|
+
</style>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { EditorMessages } from '../messages/messages.types';
|
|
2
|
+
import type { ContextMenuController } from '../states/contextMenuController.svelte';
|
|
3
|
+
interface Props {
|
|
4
|
+
controller: ContextMenuController;
|
|
5
|
+
text: EditorMessages;
|
|
6
|
+
}
|
|
7
|
+
declare const ContextMenu: import("svelte").Component<Props, {}, "">;
|
|
8
|
+
type ContextMenu = ReturnType<typeof ContextMenu>;
|
|
9
|
+
export default ContextMenu;
|
|
@@ -0,0 +1,99 @@
|
|
|
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 = '[markdown-editor] 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
|
+
<script lang="ts">
|
|
38
|
+
import { untrack } from 'svelte';
|
|
39
|
+
import { createEditorSession } from '../states/editorSession';
|
|
40
|
+
import type {
|
|
41
|
+
EditorPresentation,
|
|
42
|
+
EditorSession,
|
|
43
|
+
EditorSessionOptions
|
|
44
|
+
} from '../states/editorSession.types';
|
|
45
|
+
|
|
46
|
+
interface Props {
|
|
47
|
+
options: EditorSessionOptions;
|
|
48
|
+
presentation: EditorPresentation;
|
|
49
|
+
onSession: (session: EditorSession | null) => void;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let { options, presentation, onSession }: Props = $props();
|
|
53
|
+
|
|
54
|
+
let element: HTMLDivElement;
|
|
55
|
+
let session: EditorSession | null = $state(null);
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 編集の仕組みを組み立てる。ブラウザで表示された後にだけ動く(`$effect` はサーバーでは動かない)。
|
|
59
|
+
*
|
|
60
|
+
* 中身をすべて `untrack` で包み、反応する値をひとつも読まない形にしている。
|
|
61
|
+
* ここで props や state を読むと、値が変わるたびにこの効果が動き直し、
|
|
62
|
+
* そのつどエディタが捨てられて作り直される。作り直されたエディタは初期値に戻るため、
|
|
63
|
+
* 打った文字が消え、外部変更として当て直す往復が止まらなくなる。
|
|
64
|
+
*/
|
|
65
|
+
$effect(() =>
|
|
66
|
+
untrack(() => {
|
|
67
|
+
const result = createEditorSession(element, options);
|
|
68
|
+
if (!result.ok) return;
|
|
69
|
+
|
|
70
|
+
const created = result.value;
|
|
71
|
+
session = created;
|
|
72
|
+
onSession(created);
|
|
73
|
+
|
|
74
|
+
return () => {
|
|
75
|
+
created.destroy();
|
|
76
|
+
session = null;
|
|
77
|
+
onSession(null);
|
|
78
|
+
};
|
|
79
|
+
})
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
// 表示の指定だけは変化に追随させる(読み取り専用・ラベル・言語)
|
|
83
|
+
$effect(() => {
|
|
84
|
+
const next = { ...presentation };
|
|
85
|
+
untrack(() => session)?.setPresentation(next);
|
|
86
|
+
});
|
|
87
|
+
</script>
|
|
88
|
+
|
|
89
|
+
<!--
|
|
90
|
+
サーバー側では編集エリアと同じ大きさのコンテナだけを描画し、内容は描画しない。
|
|
91
|
+
編集できない代わりの表示であることを、生成された内容から判別できるようにする。
|
|
92
|
+
大きさの指定は `editor.css`(`.markdown-editor__mount`)が持つ。高さの受け渡しは
|
|
93
|
+
親から編集エリアまで一続きなので、途中だけを別のファイルに置かない。
|
|
94
|
+
-->
|
|
95
|
+
<div
|
|
96
|
+
bind:this={element}
|
|
97
|
+
class="markdown-editor__mount"
|
|
98
|
+
data-markdown-editor-placeholder={serverPlaceholderMark(session !== null)}
|
|
99
|
+
></div>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 代わりの表示であることを示す印を返す。編集の仕組みができていれば付けない。
|
|
3
|
+
*
|
|
4
|
+
* 判定を「描画される属性の値」として行うのは、そこが確実に評価される場所だからである
|
|
5
|
+
* (`<script>` に直に書いた文は、サーバー側の描画では実行されないことがある)。
|
|
6
|
+
*/
|
|
7
|
+
export declare function serverPlaceholderMark(hasSession: boolean): string | undefined;
|
|
8
|
+
import type { EditorPresentation, EditorSession, EditorSessionOptions } from '../states/editorSession.types';
|
|
9
|
+
interface Props {
|
|
10
|
+
options: EditorSessionOptions;
|
|
11
|
+
presentation: EditorPresentation;
|
|
12
|
+
onSession: (session: EditorSession | null) => void;
|
|
13
|
+
}
|
|
14
|
+
declare const EditorSurface: import("svelte").Component<Props, {}, "">;
|
|
15
|
+
type EditorSurface = ReturnType<typeof EditorSurface>;
|
|
16
|
+
export default EditorSurface;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { SectionPath } from '../models/document/document.types';
|
|
3
|
+
import type { FocusBreadcrumbItem } from '../operations/plugins/focus';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
/** 上位見出しの連なり。末尾がいま見ているセクション */
|
|
7
|
+
items: readonly FocusBreadcrumbItem[];
|
|
8
|
+
/** 領域の名前(支援技術向け) */
|
|
9
|
+
label: string;
|
|
10
|
+
/** 連なりの根(全体表示)のラベル */
|
|
11
|
+
clearLabel: string;
|
|
12
|
+
onClear: () => void;
|
|
13
|
+
/** 上位の階層を選んだとき、そこへフォーカスを移す */
|
|
14
|
+
onSelect: (path: SectionPath) => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let { items, label, clearLabel, onClear, onSelect }: Props = $props();
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<!--
|
|
21
|
+
フォーカス中だけ、いまどこを見ているかと、上へ戻る手立てを出す。
|
|
22
|
+
フォーカスしていないときは何も描かない(サーバー側の描画でも同じ)。
|
|
23
|
+
|
|
24
|
+
**連なりの先頭は「全体」であり、押すとフォーカスを解く。** 上位を押して移れる以上、
|
|
25
|
+
解除だけを別のボタンで持つ必要がない。フォーカスの解除にキーは無い(実行環境に
|
|
26
|
+
奪われるため外した)ので、ここが唯一の出口になる。
|
|
27
|
+
|
|
28
|
+
末尾はいま見ているセクション自身なので押せない。押しても同じ場所へ移るだけで、
|
|
29
|
+
押せるように見せる意味がない。
|
|
30
|
+
-->
|
|
31
|
+
{#if items.length > 0}
|
|
32
|
+
<nav class="markdown-editor-focus-breadcrumb" aria-label={label}>
|
|
33
|
+
<ol class="markdown-editor-focus-breadcrumb__path">
|
|
34
|
+
<li class="markdown-editor-focus-breadcrumb__item">
|
|
35
|
+
<button type="button" class="markdown-editor-focus-breadcrumb__link" onclick={onClear}>
|
|
36
|
+
{clearLabel}
|
|
37
|
+
</button>
|
|
38
|
+
</li>
|
|
39
|
+
{#each items as item, index (item.path.join('.'))}
|
|
40
|
+
<li class="markdown-editor-focus-breadcrumb__item">
|
|
41
|
+
{#if index === items.length - 1}
|
|
42
|
+
{item.title}
|
|
43
|
+
{:else}
|
|
44
|
+
<button
|
|
45
|
+
type="button"
|
|
46
|
+
class="markdown-editor-focus-breadcrumb__link"
|
|
47
|
+
onclick={() => onSelect(item.path)}
|
|
48
|
+
>
|
|
49
|
+
{item.title}
|
|
50
|
+
</button>
|
|
51
|
+
{/if}
|
|
52
|
+
</li>
|
|
53
|
+
{/each}
|
|
54
|
+
</ol>
|
|
55
|
+
</nav>
|
|
56
|
+
{/if}
|
|
57
|
+
|
|
58
|
+
<style>
|
|
59
|
+
/**
|
|
60
|
+
* フォーカスしているあいだだけ現れる。色・寸法は公開した変数から引き、利用者が上書きできる。
|
|
61
|
+
*
|
|
62
|
+
* **自分では文字の大きさを変えない**(縮めるのは中の連なり)。`em` で書いた余白は自分の
|
|
63
|
+
* 文字の大きさで解かれるため、ここで縮めると編集エリアの余白と同じ値を書いても幅が食い違い、
|
|
64
|
+
* 本文の左端と頭がそろわない。
|
|
65
|
+
*/
|
|
66
|
+
.markdown-editor-focus-breadcrumb {
|
|
67
|
+
display: flex;
|
|
68
|
+
align-items: center;
|
|
69
|
+
/* 編集エリアの内側の余白に合わせる(辺ごとに、左は行頭の帯のぶんまで含めて同じ式で出す) */
|
|
70
|
+
padding-top: var(--markdown-editor-padding-top, var(--markdown-editor-padding));
|
|
71
|
+
padding-right: var(--markdown-editor-padding-right, var(--markdown-editor-padding));
|
|
72
|
+
padding-left: max(
|
|
73
|
+
var(--markdown-editor-padding-left, var(--markdown-editor-padding)),
|
|
74
|
+
var(--markdown-editor-fold-marker-size)
|
|
75
|
+
);
|
|
76
|
+
/**
|
|
77
|
+
* 本文とのあいだは `--markdown-editor-meta-gap`。**編集エリアの上の余白のぶんは
|
|
78
|
+
* すでに空いている**ので、下に持つのはその差だけである(フロントマターは編集エリアの
|
|
79
|
+
* 内側にあり、上の余白の下から測る。同じ見え方にするには、ここで引いておく必要がある)。
|
|
80
|
+
*/
|
|
81
|
+
padding-bottom: 0;
|
|
82
|
+
margin-bottom: max(
|
|
83
|
+
0px,
|
|
84
|
+
calc(
|
|
85
|
+
var(--markdown-editor-meta-gap) -
|
|
86
|
+
var(--markdown-editor-padding-top, var(--markdown-editor-padding))
|
|
87
|
+
)
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 最大幅は本文と同じにする。本文が中央へ寄ったときに、道筋だけ左端に残ると
|
|
93
|
+
* 同じ文書の一部に見えない(掛ける先も同じく、面ではなく中身である)。
|
|
94
|
+
*/
|
|
95
|
+
.markdown-editor-focus-breadcrumb__path {
|
|
96
|
+
display: flex;
|
|
97
|
+
flex-wrap: wrap;
|
|
98
|
+
align-items: center;
|
|
99
|
+
gap: 0.35em;
|
|
100
|
+
/* 幅いっぱいまで広げてから版面に収める。頭の位置は、その中の左端で決まる */
|
|
101
|
+
flex: 1;
|
|
102
|
+
max-width: var(--markdown-editor-max-width);
|
|
103
|
+
margin: 0 auto;
|
|
104
|
+
padding: 0;
|
|
105
|
+
list-style: none;
|
|
106
|
+
min-width: 0;
|
|
107
|
+
color: var(--markdown-editor-breadcrumb-color);
|
|
108
|
+
font-size: var(--markdown-editor-font-size-sm);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.markdown-editor-focus-breadcrumb__item:not(:first-child)::before {
|
|
112
|
+
content: var(--markdown-editor-breadcrumb-separator);
|
|
113
|
+
margin-right: 0.35em;
|
|
114
|
+
color: var(--markdown-editor-breadcrumb-separator-color);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.markdown-editor-focus-breadcrumb__item:last-child {
|
|
118
|
+
color: var(--markdown-editor-breadcrumb-current-color);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/* 押せる階層。文字の並びを崩さないよう、ボタンらしい箱は持たせない */
|
|
122
|
+
.markdown-editor-focus-breadcrumb__link {
|
|
123
|
+
padding: 0;
|
|
124
|
+
background: none;
|
|
125
|
+
border: none;
|
|
126
|
+
font: inherit;
|
|
127
|
+
cursor: pointer;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.markdown-editor-focus-breadcrumb__link:hover {
|
|
131
|
+
text-decoration: underline;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.markdown-editor-focus-breadcrumb__link:focus-visible {
|
|
135
|
+
outline: 2px solid var(--markdown-editor-breadcrumb-focus-ring);
|
|
136
|
+
outline-offset: 1px;
|
|
137
|
+
}
|
|
138
|
+
</style>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SectionPath } from '../models/document/document.types';
|
|
2
|
+
import type { FocusBreadcrumbItem } from '../operations/plugins/focus';
|
|
3
|
+
interface Props {
|
|
4
|
+
/** 上位見出しの連なり。末尾がいま見ているセクション */
|
|
5
|
+
items: readonly FocusBreadcrumbItem[];
|
|
6
|
+
/** 領域の名前(支援技術向け) */
|
|
7
|
+
label: string;
|
|
8
|
+
/** 連なりの根(全体表示)のラベル */
|
|
9
|
+
clearLabel: string;
|
|
10
|
+
onClear: () => void;
|
|
11
|
+
/** 上位の階層を選んだとき、そこへフォーカスを移す */
|
|
12
|
+
onSelect: (path: SectionPath) => void;
|
|
13
|
+
}
|
|
14
|
+
declare const FocusBreadcrumb: import("svelte").Component<Props, {}, "">;
|
|
15
|
+
type FocusBreadcrumb = ReturnType<typeof FocusBreadcrumb>;
|
|
16
|
+
export default FocusBreadcrumb;
|