@14ch/svelte-md-outliner 0.0.26 → 0.0.28
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 +67 -0
- package/README.ja.md +6 -4
- package/README.md +6 -4
- package/dist/assets/styles/editor.css +7 -8
- package/dist/assets/styles/theme.css +20 -15
- package/dist/components/ContextMenu.svelte +5 -5
- package/dist/components/LinkDialog.svelte +136 -0
- package/dist/components/LinkDialog.svelte.d.ts +10 -0
- package/dist/components/LinkPopover.svelte +164 -0
- package/dist/components/LinkPopover.svelte.d.ts +9 -0
- package/dist/components/MarkdownEditor.svelte +53 -13
- package/dist/components/MarkdownEditor.svelte.d.ts +6 -1
- package/dist/components/SelectionToolbar.svelte +136 -0
- package/dist/components/SelectionToolbar.svelte.d.ts +9 -0
- package/dist/components/ShortcutHelpDialog.svelte +26 -18
- package/dist/components/internal/AnchoredLayer.svelte +102 -0
- package/dist/components/internal/AnchoredLayer.svelte.d.ts +16 -0
- package/dist/components/internal/Icon.svelte +26 -0
- package/dist/components/internal/Icon.svelte.d.ts +7 -0
- package/dist/components/internal/Popup.svelte +130 -40
- package/dist/components/internal/Popup.svelte.d.ts +17 -9
- package/dist/components/internal/icons.d.ts +22 -0
- package/dist/components/internal/icons.js +22 -0
- package/dist/messages/en.js +10 -1
- package/dist/messages/index.js +9 -0
- package/dist/messages/ja.js +10 -1
- package/dist/messages/messages.types.d.ts +27 -0
- package/dist/operations/autoformat.js +17 -0
- package/dist/operations/commands/link.d.ts +27 -4
- package/dist/operations/commands/link.js +111 -14
- package/dist/operations/keymap/coreActions.js +0 -10
- package/dist/operations/keymap/linkActions.d.ts +13 -0
- package/dist/operations/keymap/linkActions.js +30 -0
- package/dist/operations/keymap/toolbarItems.d.ts +17 -0
- package/dist/operations/keymap/toolbarItems.js +62 -0
- package/dist/operations/operations.types.d.ts +51 -0
- package/dist/operations/plugins/compositionState.js +21 -1
- package/dist/operations/plugins/linkClick.d.ts +2 -2
- package/dist/operations/plugins/linkClick.js +2 -2
- package/dist/operations/plugins/linkDialogGuard.d.ts +9 -0
- package/dist/operations/plugins/linkDialogGuard.js +18 -0
- package/dist/operations/plugins/linkPopover.d.ts +22 -0
- package/dist/operations/plugins/linkPopover.js +72 -0
- package/dist/operations/plugins/selectionToolbar.d.ts +15 -0
- package/dist/operations/plugins/selectionToolbar.js +96 -0
- package/dist/states/linkDialogController.svelte.d.ts +43 -0
- package/dist/states/linkDialogController.svelte.js +104 -0
- package/dist/states/linkPopoverController.svelte.d.ts +36 -0
- package/dist/states/linkPopoverController.svelte.js +48 -0
- package/dist/states/selectionToolbarController.svelte.d.ts +29 -0
- package/dist/states/selectionToolbarController.svelte.js +51 -0
- package/dist/utils/linkHref.d.ts +7 -0
- package/dist/utils/linkHref.js +16 -0
- package/package.json +5 -2
- package/dist/components/LinkBubble.svelte +0 -120
- package/dist/components/LinkBubble.svelte.d.ts +0 -9
- package/dist/components/internal/Dialog.svelte +0 -157
- package/dist/components/internal/Dialog.svelte.d.ts +0 -23
- package/dist/components/internal/MenuPopup.svelte +0 -145
- package/dist/components/internal/MenuPopup.svelte.d.ts +0 -26
- package/dist/components/internal/Modal.svelte +0 -181
- package/dist/components/internal/Modal.svelte.d.ts +0 -18
- package/dist/operations/plugins/linkBubble.d.ts +0 -14
- package/dist/operations/plugins/linkBubble.js +0 -55
- package/dist/states/linkBubbleController.svelte.d.ts +0 -27
- package/dist/states/linkBubbleController.svelte.js +0 -42
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { EditorView } from 'prosemirror-view';
|
|
2
|
+
import { type LinkClickSource } from '../operations/plugins/linkClick.js';
|
|
3
|
+
import type { LinkRun } from '../operations/operations.types';
|
|
4
|
+
import type { AnchorRect } from '../utils/geometry.types';
|
|
5
|
+
import type { EditorExtension, EditorSession } from './editorSession.types';
|
|
6
|
+
export interface LinkPopoverControllerOptions {
|
|
7
|
+
/** 現在のセッション。生き死にの管理はコンポーネントが持つ */
|
|
8
|
+
readonly getSession: () => EditorSession | null;
|
|
9
|
+
/** リンクが押されたときの受け手。呼ぶ時点の値を読む */
|
|
10
|
+
readonly getLinkClick: LinkClickSource;
|
|
11
|
+
/** そのリンクを編集するダイアログを開く。吹き出しはダイアログの中身を知らない */
|
|
12
|
+
readonly openLinkDialog: (view: EditorView, run: LinkRun) => void;
|
|
13
|
+
}
|
|
14
|
+
export interface LinkPopoverController {
|
|
15
|
+
/** 基盤へ渡す拡張。セッション生成より前に取得する */
|
|
16
|
+
readonly extension: EditorExtension;
|
|
17
|
+
/**
|
|
18
|
+
* 吹き出しを出しているリンク。出していなければ `null`。
|
|
19
|
+
* 編集基盤が更新するたびに新しい値になる(同じリンクでも、位置は動きうる)
|
|
20
|
+
*/
|
|
21
|
+
readonly link: LinkRun | null;
|
|
22
|
+
/** リンクの先頭の矩形を、いま測る。吹き出しの側と同じ瞬間に測るため、値で持たない */
|
|
23
|
+
measure(): AnchorRect | null;
|
|
24
|
+
/** 吹き出しが押された。利用側へ知らせ、止められなければ新しいタブで開く */
|
|
25
|
+
open(event: MouseEvent): void;
|
|
26
|
+
/** 「編集」。そのリンクを編集するダイアログを開く(焦点が移り、吹き出しは消える) */
|
|
27
|
+
edit(): void;
|
|
28
|
+
/** 「リンクを外す」。リンクの全体から外し、文字を残す(1 つの取り消しの単位) */
|
|
29
|
+
remove(): void;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* リンクを押したときに出す吹き出しの状態を、エディタ 1 インスタンスに閉じて持つ。
|
|
33
|
+
*
|
|
34
|
+
* **エディタ 1 つにつき 1 つ生成する。** セッションは都度たどるだけで抱え込まない。
|
|
35
|
+
*/
|
|
36
|
+
export declare function createLinkPopoverController(options: LinkPopoverControllerOptions): LinkPopoverController;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { closeHistory } from 'prosemirror-history';
|
|
2
|
+
import { removeLink } from '../operations/commands/link.js';
|
|
3
|
+
import { linkPopoverPlugin } from '../operations/plugins/linkPopover.js';
|
|
4
|
+
import { openLink } from '../operations/plugins/linkClick.js';
|
|
5
|
+
/**
|
|
6
|
+
* リンクを押したときに出す吹き出しの状態を、エディタ 1 インスタンスに閉じて持つ。
|
|
7
|
+
*
|
|
8
|
+
* **エディタ 1 つにつき 1 つ生成する。** セッションは都度たどるだけで抱え込まない。
|
|
9
|
+
*/
|
|
10
|
+
export function createLinkPopoverController(options) {
|
|
11
|
+
let link = $state(null);
|
|
12
|
+
const extension = {
|
|
13
|
+
plugins: [
|
|
14
|
+
linkPopoverPlugin((_view, next) => {
|
|
15
|
+
link = next;
|
|
16
|
+
})
|
|
17
|
+
],
|
|
18
|
+
actions: []
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
extension,
|
|
22
|
+
get link() {
|
|
23
|
+
return link;
|
|
24
|
+
},
|
|
25
|
+
measure() {
|
|
26
|
+
const view = options.getSession()?.getView();
|
|
27
|
+
if (!view || !link)
|
|
28
|
+
return null;
|
|
29
|
+
const coords = view.coordsAtPos(link.from);
|
|
30
|
+
return { left: coords.left, right: coords.left, top: coords.top, bottom: coords.bottom };
|
|
31
|
+
},
|
|
32
|
+
open(event) {
|
|
33
|
+
if (link)
|
|
34
|
+
openLink(link.href, event, options.getLinkClick);
|
|
35
|
+
},
|
|
36
|
+
edit() {
|
|
37
|
+
const view = options.getSession()?.getView();
|
|
38
|
+
if (view && link)
|
|
39
|
+
options.openLinkDialog(view, link);
|
|
40
|
+
},
|
|
41
|
+
remove() {
|
|
42
|
+
const view = options.getSession()?.getView();
|
|
43
|
+
if (!view || !link)
|
|
44
|
+
return;
|
|
45
|
+
removeLink(link)(view.state, (tr) => view.dispatch(closeHistory(tr)), view);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { EditorAction, SelectionToolbarAnchor, ToolbarButton } from '../operations/operations.types';
|
|
2
|
+
import type { AnchorRect } from '../utils/geometry.types';
|
|
3
|
+
import type { EditorExtension, EditorSession } from './editorSession.types';
|
|
4
|
+
export interface SelectionToolbarControllerOptions {
|
|
5
|
+
/** 現在のセッション。生き死にの管理はコンポーネントが持つ */
|
|
6
|
+
readonly getSession: () => EditorSession | null;
|
|
7
|
+
/** 基盤の宣言に加えて並べうる宣言(`format.link` はここから来る) */
|
|
8
|
+
readonly getExtensionActions: () => readonly EditorAction[];
|
|
9
|
+
/** 組み込みの帯を使うか */
|
|
10
|
+
readonly isEnabled: () => boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface SelectionToolbarController {
|
|
13
|
+
/** 基盤へ渡す拡張。セッション生成より前に取得する */
|
|
14
|
+
readonly extension: EditorExtension;
|
|
15
|
+
/** 帯を出しているあいだの錨。出していなければ `null` */
|
|
16
|
+
readonly anchor: SelectionToolbarAnchor | null;
|
|
17
|
+
readonly buttons: readonly ToolbarButton[];
|
|
18
|
+
/** 選択範囲の矩形を、いま測る。帯の側と同じ瞬間に測るため、値で持たない */
|
|
19
|
+
measure(): AnchorRect | null;
|
|
20
|
+
/** ボタンが押された。キーで実行したときと同じ覆いを通す */
|
|
21
|
+
run(action: EditorAction): void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 文字を選んだときに出す帯の錨とボタンを、エディタ 1 インスタンスに閉じて持つ。
|
|
25
|
+
*
|
|
26
|
+
* 見張りが錨を知らせるたびにボタンを導き直し、1 つも働かなければ出さない。
|
|
27
|
+
* **エディタ 1 つにつき 1 つ生成する。** セッションは都度たどるだけで抱え込まない。
|
|
28
|
+
*/
|
|
29
|
+
export declare function createSelectionToolbarController(options: SelectionToolbarControllerOptions): SelectionToolbarController;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { editorKeymap } from '../operations/keymap/assemble.js';
|
|
2
|
+
import { toolbarButtonsFor } from '../operations/keymap/toolbarItems.js';
|
|
3
|
+
import { selectionToolbarPlugin } from '../operations/plugins/selectionToolbar.js';
|
|
4
|
+
/**
|
|
5
|
+
* 文字を選んだときに出す帯の錨とボタンを、エディタ 1 インスタンスに閉じて持つ。
|
|
6
|
+
*
|
|
7
|
+
* 見張りが錨を知らせるたびにボタンを導き直し、1 つも働かなければ出さない。
|
|
8
|
+
* **エディタ 1 つにつき 1 つ生成する。** セッションは都度たどるだけで抱え込まない。
|
|
9
|
+
*/
|
|
10
|
+
export function createSelectionToolbarController(options) {
|
|
11
|
+
let anchor = $state(null);
|
|
12
|
+
let buttons = $state([]);
|
|
13
|
+
const extension = {
|
|
14
|
+
plugins: [selectionToolbarPlugin(update)],
|
|
15
|
+
actions: []
|
|
16
|
+
};
|
|
17
|
+
function update(view, next) {
|
|
18
|
+
const available = next && options.isEnabled()
|
|
19
|
+
? toolbarButtonsFor([...editorKeymap.coreActions, ...options.getExtensionActions()], view)
|
|
20
|
+
: [];
|
|
21
|
+
buttons = available;
|
|
22
|
+
anchor = available.length > 0 ? next : null;
|
|
23
|
+
}
|
|
24
|
+
function viewOf() {
|
|
25
|
+
return options.getSession()?.getView() ?? null;
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
extension,
|
|
29
|
+
get anchor() {
|
|
30
|
+
return anchor;
|
|
31
|
+
},
|
|
32
|
+
get buttons() {
|
|
33
|
+
return buttons;
|
|
34
|
+
},
|
|
35
|
+
/** 上端は始まりの行の上、下端は終わりの行の下。左端は選択の始まりにそろえる */
|
|
36
|
+
measure() {
|
|
37
|
+
const view = viewOf();
|
|
38
|
+
if (!view || !anchor)
|
|
39
|
+
return null;
|
|
40
|
+
const start = view.coordsAtPos(anchor.from, 1);
|
|
41
|
+
const end = view.coordsAtPos(anchor.to, -1);
|
|
42
|
+
return { left: start.left, right: end.right, top: start.top, bottom: end.bottom };
|
|
43
|
+
},
|
|
44
|
+
run(action) {
|
|
45
|
+
const view = viewOf();
|
|
46
|
+
if (!view)
|
|
47
|
+
return;
|
|
48
|
+
editorKeymap.decorate(action)(view.state, view.dispatch.bind(view), view);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const SCHEME = /^[a-zA-Z][a-zA-Z0-9+.-]*:/;
|
|
2
|
+
const RELATIVE = /^(\/|\.\/|\.\.\/|#|\?)/;
|
|
3
|
+
/**
|
|
4
|
+
* 入力された行き先を整える。前後の空白を除き、スキームも相対の書き方も無ければ
|
|
5
|
+
* `https://` を補う。空白だけなら `null`。
|
|
6
|
+
*
|
|
7
|
+
* ダイアログの「適用」を押せるかもこの戻り値で決める。判定を 2 通りにしない。
|
|
8
|
+
*/
|
|
9
|
+
export function normalizeLinkHref(input) {
|
|
10
|
+
const href = input.trim();
|
|
11
|
+
if (!href)
|
|
12
|
+
return null;
|
|
13
|
+
if (SCHEME.test(href) || RELATIVE.test(href))
|
|
14
|
+
return href;
|
|
15
|
+
return `https://${href}`;
|
|
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.28",
|
|
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.",
|
|
@@ -66,9 +66,11 @@
|
|
|
66
66
|
"format": "prettier --write .",
|
|
67
67
|
"test:unit": "vitest",
|
|
68
68
|
"test": "npm run test:unit -- --run && npm run test:e2e",
|
|
69
|
-
"test:e2e": "playwright install && playwright test"
|
|
69
|
+
"test:e2e": "playwright install && playwright test",
|
|
70
|
+
"release": "bash scripts/release.sh"
|
|
70
71
|
},
|
|
71
72
|
"peerDependencies": {
|
|
73
|
+
"@14ch/svelte-ui": "^0.0.83",
|
|
72
74
|
"svelte": "^5.0.0"
|
|
73
75
|
},
|
|
74
76
|
"dependencies": {
|
|
@@ -88,6 +90,7 @@
|
|
|
88
90
|
"prosemirror-view": "^1.42.0"
|
|
89
91
|
},
|
|
90
92
|
"devDependencies": {
|
|
93
|
+
"@14ch/svelte-ui": "^0.0.83",
|
|
91
94
|
"@eslint/js": "^10.0.1",
|
|
92
95
|
"@playwright/test": "^1.60.0",
|
|
93
96
|
"@sveltejs/adapter-static": "^3.0.10",
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
<!--
|
|
2
|
-
カーソルがリンクにあるあいだ出す吹き出し。リンク先を見せ、押すとそこを開く。
|
|
3
|
-
|
|
4
|
-
土台(`Popup`)に載せ、吹き出しの振る舞いをここに書く。
|
|
5
|
-
|
|
6
|
-
- **焦点を奪わない。** 焦点が編集エリアを離れると吹き出しは消えるので、奪うと押す
|
|
7
|
-
押す前に消える。タッチ端末ではキーボードも引っ込む。押しても焦点が動かないよう、
|
|
8
|
-
`mousedown` を止める
|
|
9
|
-
- **リンクの上に出す。** タッチ端末では画面の下半分をキーボードが覆う。上に入らない
|
|
10
|
-
ときだけ下へ返す
|
|
11
|
-
- **外の動きでは閉じず、付いていく。** 閉じると、カーソルを動かし直すまで出てこない
|
|
12
|
-
-->
|
|
13
|
-
<script lang="ts">
|
|
14
|
-
import type { LinkBubbleController } from '../states/linkBubbleController.svelte';
|
|
15
|
-
import type { AnchorRect } from '../utils/geometry.types';
|
|
16
|
-
import Popup from './internal/Popup.svelte';
|
|
17
|
-
|
|
18
|
-
interface Props {
|
|
19
|
-
controller: LinkBubbleController;
|
|
20
|
-
/** 吹き出しのアクセシブルな名前。リンク先を後ろに続けて読ませる */
|
|
21
|
-
openLabel: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
let { controller, openLabel }: Props = $props();
|
|
25
|
-
|
|
26
|
-
/** リンクと吹き出しのあいだ */
|
|
27
|
-
const GAP = 6;
|
|
28
|
-
/** 表示領域の端から空ける距離 */
|
|
29
|
-
const MARGIN = 8;
|
|
30
|
-
|
|
31
|
-
/** リンクの先頭に左端をそろえ、上に置く。はみ出すときは表示領域の中へ寄せる */
|
|
32
|
-
function place(element: HTMLDivElement, rect: AnchorRect): void {
|
|
33
|
-
const box = element.getBoundingClientRect();
|
|
34
|
-
|
|
35
|
-
const above = rect.top - GAP - box.height;
|
|
36
|
-
const top = above >= MARGIN ? above : rect.bottom + GAP;
|
|
37
|
-
const left = Math.max(MARGIN, Math.min(rect.left, window.innerWidth - box.width - MARGIN));
|
|
38
|
-
|
|
39
|
-
element.style.transform = `translate(${left}px, ${top}px)`;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function keepFocus(event: MouseEvent): void {
|
|
43
|
-
event.preventDefault();
|
|
44
|
-
}
|
|
45
|
-
</script>
|
|
46
|
-
|
|
47
|
-
<Popup
|
|
48
|
-
open={controller.href !== null}
|
|
49
|
-
anchor={controller.anchor}
|
|
50
|
-
{place}
|
|
51
|
-
class="markdown-editor-link-bubble"
|
|
52
|
-
onViewportChange={controller.refresh}
|
|
53
|
-
onmousedown={keepFocus}
|
|
54
|
-
>
|
|
55
|
-
<!-- 吹き出し全体を 1 つのボタンにする。押せる面が広いほどタッチ端末で押しやすい -->
|
|
56
|
-
<button
|
|
57
|
-
type="button"
|
|
58
|
-
class="markdown-editor-link-bubble__open"
|
|
59
|
-
aria-label="{openLabel}: {controller.href}"
|
|
60
|
-
title={controller.href}
|
|
61
|
-
onclick={controller.open}
|
|
62
|
-
>
|
|
63
|
-
<!-- 新しいタブで開くことの印。吹き出しはリンクの先頭にそろうので、左に置けば押す目当てが近い -->
|
|
64
|
-
<svg class="markdown-editor-link-bubble__icon" viewBox="0 0 16 16" aria-hidden="true">
|
|
65
|
-
<path d="M6 3H3v10h10v-3M9 3h4v4M13 3 7 9" />
|
|
66
|
-
</svg>
|
|
67
|
-
<span class="markdown-editor-link-bubble__target">{controller.href}</span>
|
|
68
|
-
</button>
|
|
69
|
-
</Popup>
|
|
70
|
-
|
|
71
|
-
<style>
|
|
72
|
-
/** 行間は本文のものを引き継がない(地の文ではない) */
|
|
73
|
-
.markdown-editor-link-bubble__open {
|
|
74
|
-
display: flex;
|
|
75
|
-
align-items: center;
|
|
76
|
-
gap: 6px;
|
|
77
|
-
max-width: min(360px, calc(100vw - 16px));
|
|
78
|
-
padding: 8px 12px;
|
|
79
|
-
border: 0;
|
|
80
|
-
background: none;
|
|
81
|
-
color: var(--markdown-editor-url-bubble-color);
|
|
82
|
-
font: inherit;
|
|
83
|
-
font-size: var(--markdown-editor-font-size-sm);
|
|
84
|
-
line-height: normal;
|
|
85
|
-
text-align: left;
|
|
86
|
-
cursor: pointer;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
.markdown-editor-link-bubble__target {
|
|
90
|
-
min-width: 0;
|
|
91
|
-
overflow: hidden;
|
|
92
|
-
text-overflow: ellipsis;
|
|
93
|
-
white-space: nowrap;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
.markdown-editor-link-bubble__icon {
|
|
97
|
-
flex: none;
|
|
98
|
-
width: 1em;
|
|
99
|
-
height: 1em;
|
|
100
|
-
fill: none;
|
|
101
|
-
stroke: currentColor;
|
|
102
|
-
stroke-width: 1.5;
|
|
103
|
-
stroke-linecap: round;
|
|
104
|
-
stroke-linejoin: round;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/* 触れる入力しかない環境では `:hover` が居座るため、囲って外す */
|
|
108
|
-
@media (hover: hover) {
|
|
109
|
-
.markdown-editor-link-bubble__open:hover {
|
|
110
|
-
background: var(--markdown-editor-url-bubble-hover);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/* 触れる端末でのターゲットの大きさ */
|
|
115
|
-
@media (max-width: 768px) {
|
|
116
|
-
.markdown-editor-link-bubble__open {
|
|
117
|
-
min-height: var(--markdown-editor-touch-target);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
</style>
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { LinkBubbleController } from '../states/linkBubbleController.svelte';
|
|
2
|
-
interface Props {
|
|
3
|
-
controller: LinkBubbleController;
|
|
4
|
-
/** 吹き出しのアクセシブルな名前。リンク先を後ろに続けて読ませる */
|
|
5
|
-
openLabel: string;
|
|
6
|
-
}
|
|
7
|
-
declare const LinkBubble: import("svelte").Component<Props, {}, "">;
|
|
8
|
-
type LinkBubble = ReturnType<typeof LinkBubble>;
|
|
9
|
-
export default LinkBubble;
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
<!--
|
|
2
|
-
ダイアログ。`Modal` の上に、見出し・本文・脚の枠組みを載せる。
|
|
3
|
-
`scrollable` のときはヘッダーとフッターを固定し、本文だけを巻き取る。
|
|
4
|
-
-->
|
|
5
|
-
<script lang="ts">
|
|
6
|
-
import type { Snippet } from 'svelte';
|
|
7
|
-
import Modal from './Modal.svelte';
|
|
8
|
-
|
|
9
|
-
interface Props {
|
|
10
|
-
header?: Snippet;
|
|
11
|
-
children?: Snippet;
|
|
12
|
-
footer?: Snippet;
|
|
13
|
-
title?: string;
|
|
14
|
-
/** dialog 要素へ足すクラス(外から指す・見た目を上書きするための印) */
|
|
15
|
-
class?: string;
|
|
16
|
-
/** CSS の幅(例: 'min(40em, 90vw)') */
|
|
17
|
-
width?: string;
|
|
18
|
-
/** 本文が収まらないとき、ヘッダー・フッターを固定して本文だけをスクロールさせる */
|
|
19
|
-
scrollable?: boolean;
|
|
20
|
-
closeIfClickOutside?: boolean;
|
|
21
|
-
ariaLabel?: string;
|
|
22
|
-
/** 閉じたときの通知。閉じる経路によらず 1 度呼ばれる */
|
|
23
|
-
onClose?: () => void;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
let {
|
|
27
|
-
header,
|
|
28
|
-
children,
|
|
29
|
-
footer,
|
|
30
|
-
title = '',
|
|
31
|
-
class: className = '',
|
|
32
|
-
width = '20em',
|
|
33
|
-
scrollable = false,
|
|
34
|
-
closeIfClickOutside = true,
|
|
35
|
-
ariaLabel,
|
|
36
|
-
onClose
|
|
37
|
-
}: Props = $props();
|
|
38
|
-
|
|
39
|
-
let modalRef: Modal;
|
|
40
|
-
|
|
41
|
-
export function open(): void {
|
|
42
|
-
modalRef?.open();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function close(): void {
|
|
46
|
-
modalRef?.close();
|
|
47
|
-
}
|
|
48
|
-
</script>
|
|
49
|
-
|
|
50
|
-
<Modal
|
|
51
|
-
bind:this={modalRef}
|
|
52
|
-
class={className}
|
|
53
|
-
style={`width: ${width}; border-radius: var(--markdown-editor-radius); overflow: hidden;`}
|
|
54
|
-
{closeIfClickOutside}
|
|
55
|
-
ariaLabel={ariaLabel ?? title}
|
|
56
|
-
{onClose}
|
|
57
|
-
>
|
|
58
|
-
<div class="dialog {scrollable ? 'dialog--scrollable' : ''}">
|
|
59
|
-
{#if header || title}
|
|
60
|
-
<div class="dialog__header">
|
|
61
|
-
{#if header}
|
|
62
|
-
{@render header()}
|
|
63
|
-
{:else}
|
|
64
|
-
<div class="dialog__title">{title}</div>
|
|
65
|
-
{/if}
|
|
66
|
-
</div>
|
|
67
|
-
{/if}
|
|
68
|
-
{#if children}
|
|
69
|
-
<div class="dialog__body">
|
|
70
|
-
{@render children()}
|
|
71
|
-
</div>
|
|
72
|
-
{/if}
|
|
73
|
-
{#if footer}
|
|
74
|
-
<div class="dialog__footer">
|
|
75
|
-
{@render footer()}
|
|
76
|
-
</div>
|
|
77
|
-
{/if}
|
|
78
|
-
</div>
|
|
79
|
-
</Modal>
|
|
80
|
-
|
|
81
|
-
<style>
|
|
82
|
-
.dialog {
|
|
83
|
-
display: flex;
|
|
84
|
-
flex-direction: column;
|
|
85
|
-
justify-content: stretch;
|
|
86
|
-
border: 1px solid var(--markdown-editor-dialog-border);
|
|
87
|
-
border-radius: var(--markdown-editor-radius);
|
|
88
|
-
max-height: calc(100dvh - 2em - 6px);
|
|
89
|
-
overflow: auto;
|
|
90
|
-
font-family: var(--markdown-editor-font);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/*
|
|
94
|
-
* グローバルの `* { box-sizing: border-box }` を敷けないモジュールなので、
|
|
95
|
-
* その前提をこのブロックの中へ持ち込む(56px は padding 込みの高さ)。
|
|
96
|
-
*/
|
|
97
|
-
.dialog,
|
|
98
|
-
.dialog *,
|
|
99
|
-
.dialog *::before,
|
|
100
|
-
.dialog *::after {
|
|
101
|
-
box-sizing: border-box;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
.dialog__header {
|
|
105
|
-
display: flex;
|
|
106
|
-
gap: 16px;
|
|
107
|
-
align-items: center;
|
|
108
|
-
justify-content: stretch;
|
|
109
|
-
min-height: 56px;
|
|
110
|
-
padding: 16px 24px;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
.dialog__title {
|
|
114
|
-
flex-grow: 1;
|
|
115
|
-
font-size: var(--markdown-editor-font-size-xl);
|
|
116
|
-
line-height: normal;
|
|
117
|
-
color: var(--markdown-editor-dialog-title-color);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* **左右の空きは持たない。** 中身の箱がそのぶん内側へ寄ると、中身が引く区切りの線が
|
|
122
|
-
* 箱の端まで届かなくなる。左右は中身の側が
|
|
123
|
-
* `--markdown-editor-dialog-inset` で取る。
|
|
124
|
-
*/
|
|
125
|
-
.dialog__body {
|
|
126
|
-
flex-shrink: 1;
|
|
127
|
-
position: relative;
|
|
128
|
-
padding: 0 0 var(--markdown-editor-dialog-inset);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
.dialog__footer {
|
|
132
|
-
display: flex;
|
|
133
|
-
gap: 8px;
|
|
134
|
-
justify-content: end;
|
|
135
|
-
padding: 8px;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/* scrollable のとき: ヘッダー・フッター固定 + 本文のみスクロール */
|
|
139
|
-
.dialog--scrollable {
|
|
140
|
-
overflow: hidden;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
.dialog--scrollable .dialog__header {
|
|
144
|
-
margin-bottom: 0;
|
|
145
|
-
border-bottom: 1px solid var(--markdown-editor-dialog-divider);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
.dialog--scrollable .dialog__body {
|
|
149
|
-
flex-shrink: 1;
|
|
150
|
-
padding: var(--markdown-editor-dialog-inset) 0;
|
|
151
|
-
overflow: auto;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
.dialog--scrollable .dialog__footer {
|
|
155
|
-
border-top: 1px solid var(--markdown-editor-dialog-divider);
|
|
156
|
-
}
|
|
157
|
-
</style>
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Snippet } from 'svelte';
|
|
2
|
-
interface Props {
|
|
3
|
-
header?: Snippet;
|
|
4
|
-
children?: Snippet;
|
|
5
|
-
footer?: Snippet;
|
|
6
|
-
title?: string;
|
|
7
|
-
/** dialog 要素へ足すクラス(外から指す・見た目を上書きするための印) */
|
|
8
|
-
class?: string;
|
|
9
|
-
/** CSS の幅(例: 'min(40em, 90vw)') */
|
|
10
|
-
width?: string;
|
|
11
|
-
/** 本文が収まらないとき、ヘッダー・フッターを固定して本文だけをスクロールさせる */
|
|
12
|
-
scrollable?: boolean;
|
|
13
|
-
closeIfClickOutside?: boolean;
|
|
14
|
-
ariaLabel?: string;
|
|
15
|
-
/** 閉じたときの通知。閉じる経路によらず 1 度呼ばれる */
|
|
16
|
-
onClose?: () => void;
|
|
17
|
-
}
|
|
18
|
-
declare const Dialog: import("svelte").Component<Props, {
|
|
19
|
-
open: () => void;
|
|
20
|
-
close: () => void;
|
|
21
|
-
}, "">;
|
|
22
|
-
type Dialog = ReturnType<typeof Dialog>;
|
|
23
|
-
export default Dialog;
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
<!--
|
|
2
|
-
メニューとして開くポップアップ。土台(`Popup`)に、メニューの振る舞いを足す。
|
|
3
|
-
|
|
4
|
-
- 開くと焦点を中へ移し、`Tab` を中で循環させる
|
|
5
|
-
- 錨の右上に置く
|
|
6
|
-
- 外の動き(スクロール・リサイズ)で閉じたいことを `onClose` で伝える。自分では閉じない
|
|
7
|
-
-->
|
|
8
|
-
<script lang="ts">
|
|
9
|
-
import type { Snippet } from 'svelte';
|
|
10
|
-
|
|
11
|
-
import type { AnchorRect } from '../../utils/geometry.types';
|
|
12
|
-
import Popup from './Popup.svelte';
|
|
13
|
-
|
|
14
|
-
interface Props {
|
|
15
|
-
children: Snippet;
|
|
16
|
-
/** 錨の矩形。開くたびに読み直す */
|
|
17
|
-
anchor: AnchorRect | null;
|
|
18
|
-
open: boolean;
|
|
19
|
-
/** コンテナの役割。既定は menu */
|
|
20
|
-
role?: string;
|
|
21
|
-
ariaLabel?: string;
|
|
22
|
-
/** いま選んでいる子要素の id。中身の側は実フォーカスもそこへ移す */
|
|
23
|
-
ariaActivedescendant?: string;
|
|
24
|
-
class?: string;
|
|
25
|
-
/**
|
|
26
|
-
* 中で押されたキー。`Tab` の循環より**先**に呼ぶ。
|
|
27
|
-
* 既定動作を止めた(受け止めた)ときは、循環の判定へ進まない
|
|
28
|
-
*/
|
|
29
|
-
onKeyDown?: (event: KeyboardEvent) => void;
|
|
30
|
-
/** 操作対象がポップアップの外へ移ったときの通知。中での移動では呼ばない */
|
|
31
|
-
onFocusOut?: () => void;
|
|
32
|
-
/** 外の動き(スクロール・リサイズ)で閉じたいときの通知。自分では閉じない */
|
|
33
|
-
onClose?: () => void;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let {
|
|
37
|
-
children,
|
|
38
|
-
anchor,
|
|
39
|
-
open,
|
|
40
|
-
role = 'menu',
|
|
41
|
-
ariaLabel,
|
|
42
|
-
ariaActivedescendant,
|
|
43
|
-
class: className = '',
|
|
44
|
-
onKeyDown,
|
|
45
|
-
onFocusOut,
|
|
46
|
-
onClose
|
|
47
|
-
}: Props = $props();
|
|
48
|
-
|
|
49
|
-
/** 錨と表示領域の端から空ける距離 */
|
|
50
|
-
const MARGIN = 8;
|
|
51
|
-
|
|
52
|
-
/** 開いた直後は何も選んでいないので、操作対象の行き先はコンテナになる */
|
|
53
|
-
function focusOnOpen(element: HTMLDivElement): void {
|
|
54
|
-
element.focus();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* 錨の**右上**に置き、表示領域からはみ出すときは中へ寄せる。
|
|
59
|
-
* 高さが収まらないときは、押し込めるだけ押し込んで中をスクロールさせる。
|
|
60
|
-
*
|
|
61
|
-
* 右へ出すのは、錨そのもの(対象にしている行)を覆わないためである。
|
|
62
|
-
* 上端をそろえるので、どの行に対して開いたのかが目で追える。
|
|
63
|
-
*/
|
|
64
|
-
function place(element: HTMLDivElement, rect: AnchorRect): void {
|
|
65
|
-
// 前回の寄せの跡を消してから測る(残すと 2 回目以降が前回の高さに縛られる)
|
|
66
|
-
element.style.maxHeight = '';
|
|
67
|
-
element.style.overflowY = '';
|
|
68
|
-
|
|
69
|
-
const box = element.getBoundingClientRect();
|
|
70
|
-
const viewport = { width: window.innerWidth, height: window.innerHeight };
|
|
71
|
-
|
|
72
|
-
let top = rect.top;
|
|
73
|
-
// 下に入らず、上のほうが広ければ、錨の下端に合わせて上へ返す
|
|
74
|
-
const below = viewport.height - top - MARGIN;
|
|
75
|
-
const above = rect.bottom - MARGIN * 2;
|
|
76
|
-
if (box.height > below && above > below) top = rect.bottom - box.height;
|
|
77
|
-
|
|
78
|
-
const left = clamp(rect.right + MARGIN, MARGIN, viewport.width - box.width - MARGIN);
|
|
79
|
-
top = clamp(top, MARGIN, viewport.height - box.height - MARGIN);
|
|
80
|
-
|
|
81
|
-
const available = viewport.height - top - MARGIN;
|
|
82
|
-
if (box.height > available) {
|
|
83
|
-
element.style.maxHeight = `${available}px`;
|
|
84
|
-
element.style.overflowY = 'auto';
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
element.style.transform = `translate(${left}px, ${top}px)`;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/** 収まらない値を渡されたら手前の端に付ける(`max < min` でも表示領域の外へ出さない) */
|
|
91
|
-
function clamp(value: number, min: number, max: number): number {
|
|
92
|
-
return Math.max(min, Math.min(value, max));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/** 移り先がポップアップの中なら、外へ出たことにはしない */
|
|
96
|
-
function handleFocusOut(event: FocusEvent & { currentTarget: HTMLDivElement }): void {
|
|
97
|
-
const next = event.relatedTarget;
|
|
98
|
-
if (next instanceof Node && event.currentTarget.contains(next)) return;
|
|
99
|
-
onFocusOut?.();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/** 中で押されたキー。使う側へ先に渡し、残りは Tab の循環だけを見る */
|
|
103
|
-
function handleKeydown(event: KeyboardEvent & { currentTarget: HTMLDivElement }): void {
|
|
104
|
-
onKeyDown?.(event);
|
|
105
|
-
if (event.defaultPrevented) return;
|
|
106
|
-
cycleTab(event);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/** Tab を中で循環させる */
|
|
110
|
-
function cycleTab(event: KeyboardEvent & { currentTarget: HTMLDivElement }): void {
|
|
111
|
-
if (event.key !== 'Tab') return;
|
|
112
|
-
|
|
113
|
-
const focusable = event.currentTarget.querySelectorAll<HTMLElement>(
|
|
114
|
-
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
|
|
115
|
-
);
|
|
116
|
-
if (focusable.length === 0) return;
|
|
117
|
-
|
|
118
|
-
const first = focusable[0];
|
|
119
|
-
const last = focusable[focusable.length - 1];
|
|
120
|
-
if (event.shiftKey && document.activeElement === first) {
|
|
121
|
-
event.preventDefault();
|
|
122
|
-
last.focus();
|
|
123
|
-
} else if (!event.shiftKey && document.activeElement === last) {
|
|
124
|
-
event.preventDefault();
|
|
125
|
-
first.focus();
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
</script>
|
|
129
|
-
|
|
130
|
-
<Popup
|
|
131
|
-
{anchor}
|
|
132
|
-
{open}
|
|
133
|
-
{place}
|
|
134
|
-
class={className}
|
|
135
|
-
{role}
|
|
136
|
-
tabindex={-1}
|
|
137
|
-
aria-label={ariaLabel}
|
|
138
|
-
aria-activedescendant={ariaActivedescendant}
|
|
139
|
-
onOpen={focusOnOpen}
|
|
140
|
-
onViewportChange={onClose}
|
|
141
|
-
onkeydown={handleKeydown}
|
|
142
|
-
onfocusout={handleFocusOut}
|
|
143
|
-
>
|
|
144
|
-
{@render children()}
|
|
145
|
-
</Popup>
|