@14ch/svelte-md-outliner 0.0.24 → 0.0.26

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 CHANGED
@@ -5,6 +5,40 @@ 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.26] - 2026-11-02
9
+
10
+ ### Added
11
+
12
+ - While editing, a bubble showing the link target appears above a link whenever
13
+ the cursor touches it. Clicking or tapping the bubble opens the link, so links
14
+ can now be opened on touch devices, which have no ⌘/Ctrl key. ⌘-click
15
+ (Ctrl-click outside macOS) still opens a link directly. The bubble also calls
16
+ `onLinkClick` first.
17
+ - `linkOpen` message: the accessible name of the bubble. Add it if you pass a
18
+ full message set for a language that is not bundled.
19
+ - Theme tokens for the bubble: `--markdown-editor-url-bubble-color` and
20
+ `--markdown-editor-url-bubble-hover`.
21
+
22
+ ### Fixed
23
+
24
+ - ⌘-clicking a link now brings the new tab to the front instead of opening it
25
+ in the background.
26
+ - A plain click on a link while editing no longer navigates the page in apps
27
+ whose router handles link clicks (such as SvelteKit).
28
+
29
+ ## [0.0.25] - 2026-10-29
30
+
31
+ ### Added
32
+
33
+ - Links open in a new tab: ⌘-click (Ctrl-click outside macOS) while editing,
34
+ a plain click while `readonly`. A plain click while editing still places the
35
+ cursor. The pointer turns into a hand over a link only when a click would
36
+ open it.
37
+ - `onLinkClick` prop: called with the `href` as written (relative links are not
38
+ resolved) before the link opens. Call `event.preventDefault()` to handle the
39
+ link yourself instead of opening a new tab — for example, links between
40
+ Markdown files. The `LinkClick` type is exported.
41
+
8
42
  ## [0.0.24] - 2026-10-28
9
43
 
10
44
  ### Changed
package/README.ja.md CHANGED
@@ -51,23 +51,24 @@ import '@14ch/svelte-md-outliner/styles/editor.css';
51
51
  <MarkdownEditor bind:value bind:viewState label="議事録" maxWidth="42rem" />
52
52
  ```
53
53
 
54
- | | 型 | 既定 | |
55
- | ------------------- | ----------------------------------------- | ---------- | ---------------------------------------------------------------- |
56
- | `value` | `string` | `''` | 本文のマークダウン(`bind:` 可)。取り消せる置き換えとして当たる |
57
- | `onChange` | `(markdown: string) => void` | — | `bind:value` を使うなら不要 |
58
- | `viewState` | `ViewState` | — | どの見出しを畳んでいるか、どこをフォーカスしているか |
59
- | `onViewStateChange` | `(viewState: ViewState) => void` | — | `bind:viewState` を使うなら不要 |
60
- | `label` | `string` | 内蔵の文言 | 編集エリアのアクセシブルネーム |
61
- | `readonly` | `boolean` | `false` | 入力・編集コマンド・貼り付けを受け付けない |
62
- | `autofocus` | `boolean` | `false` | マウント時にフォーカスする |
63
- | `class` | `string` | `''` | 追加のクラス名 |
64
- | `padding` | `string` | トークン | CSS の `padding` と同じ書き方 |
65
- | `maxWidth` | `string` | トークン | 行の長さ。**クリックできる範囲は元の幅のまま** |
66
- | `lang` | `'en' \| 'ja'` | `'en'` | 同梱の言語 |
67
- | `messages` | `EditorMessagesOverride` | — | 文字列の差し替え。同梱しない言語は一式を渡す |
68
- | `shortcutHelp` | `boolean` | `true` | 組み込みのショートカット一覧(`Mod-Alt-/`) |
69
- | `contextMenu` | `boolean` | `true` | 組み込みのコンテキストメニュー(右クリック / `Mod-/`) |
70
- | `uploadImage` | `(file: File) => Promise<string \| null>` | — | 貼り付けられた画像を引き受け、表示に使う URL を返す |
54
+ | | 型 | 既定 | |
55
+ | ------------------- | ------------------------------------------- | ---------- | ---------------------------------------------------------------- |
56
+ | `value` | `string` | `''` | 本文のマークダウン(`bind:` 可)。取り消せる置き換えとして当たる |
57
+ | `onChange` | `(markdown: string) => void` | — | `bind:value` を使うなら不要 |
58
+ | `viewState` | `ViewState` | — | どの見出しを畳んでいるか、どこをフォーカスしているか |
59
+ | `onViewStateChange` | `(viewState: ViewState) => void` | — | `bind:viewState` を使うなら不要 |
60
+ | `label` | `string` | 内蔵の文言 | 編集エリアのアクセシブルネーム |
61
+ | `readonly` | `boolean` | `false` | 入力・編集コマンド・貼り付けを受け付けない |
62
+ | `autofocus` | `boolean` | `false` | マウント時にフォーカスする |
63
+ | `class` | `string` | `''` | 追加のクラス名 |
64
+ | `padding` | `string` | トークン | CSS の `padding` と同じ書き方 |
65
+ | `maxWidth` | `string` | トークン | 行の長さ。**クリックできる範囲は元の幅のまま** |
66
+ | `lang` | `'en' \| 'ja'` | `'en'` | 同梱の言語 |
67
+ | `messages` | `EditorMessagesOverride` | — | 文字列の差し替え。同梱しない言語は一式を渡す |
68
+ | `shortcutHelp` | `boolean` | `true` | 組み込みのショートカット一覧(`Mod-Alt-/`) |
69
+ | `contextMenu` | `boolean` | `true` | 組み込みのコンテキストメニュー(右クリック / `Mod-/`) |
70
+ | `uploadImage` | `(file: File) => Promise<string \| null>` | — | 貼り付けられた画像を引き受け、表示に使う URL を返す |
71
+ | `onLinkClick` | `(href: string, event: MouseEvent) => void` | — | リンクが押されたときの通知。止めなければ新しいタブで開く |
71
72
 
72
73
  `viewState` は**今どう見ているか**であって、文書の内容ではない。このモジュールは何も保存しないので、保存先は利用側が決める(保存しなくてもよい)。
73
74
 
@@ -88,6 +89,24 @@ const uploadImage = async (file: File) => {
88
89
 
89
90
  **画像を描くと、その先へ取りに行く。** 外部の URL が書かれた文書は、表示のたびにその先へ取得が飛ぶ(記法を描く以上避けられない)。
90
91
 
92
+ ### リンク
93
+
94
+ リンク先は新しいタブで開く。
95
+
96
+ - **編集中**は、カーソルがリンクに触れているあいだ、リンクの上にリンク先を見せる吹き出しが出て、吹き出しを押すと開く。リンクの素のクリック(タップ)はカーソルを置く操作のままなので、タッチ端末でも「リンクをタップして、吹き出しをタップ」で開ける。⌘+クリック(Mac 以外は Ctrl+クリック)なら吹き出しを経ずに開く
97
+ - **読み取り専用**では、素のクリックで開く
98
+
99
+ 開く前に `onLinkClick` が書かれたとおりの `href` を受け取る(相対のままでも解決しない)。`event.preventDefault()` を呼べば、新しいタブでは開かない。`./other.md` のように、ブラウザで開いても意味を持たない行き先を利用側で扱うときに使う。
100
+
101
+ ```ts
102
+ const onLinkClick = (href: string, event: MouseEvent) => {
103
+ if (href.endsWith('.md')) {
104
+ event.preventDefault();
105
+ openDocument(href);
106
+ }
107
+ };
108
+ ```
109
+
91
110
  同梱していない言語は、同梱の一式を土台にする。
92
111
 
93
112
  ```ts
package/README.md CHANGED
@@ -51,23 +51,24 @@ import '@14ch/svelte-md-outliner/styles/editor.css';
51
51
  <MarkdownEditor bind:value bind:viewState label="Meeting notes" maxWidth="42rem" />
52
52
  ```
53
53
 
54
- | | Type | Default | |
55
- | ------------------- | ----------------------------------------- | -------- | -------------------------------------------------------------- |
56
- | `value` | `string` | `''` | Markdown source (bindable). Applied as an undoable replacement |
57
- | `onChange` | `(markdown: string) => void` | — | Not needed when you use `bind:value` |
58
- | `viewState` | `ViewState` | — | Which headings are folded, which section is zoomed |
59
- | `onViewStateChange` | `(viewState: ViewState) => void` | — | Not needed when you use `bind:viewState` |
60
- | `label` | `string` | built-in | Accessible name for the editing surface |
61
- | `readonly` | `boolean` | `false` | Rejects typing, commands and pastes |
62
- | `autofocus` | `boolean` | `false` | Focus on mount |
63
- | `class` | `string` | `''` | Extra class names |
64
- | `padding` | `string` | token | Written exactly like CSS `padding` |
65
- | `maxWidth` | `string` | token | Line length. **The clickable surface keeps the full width** |
66
- | `lang` | `'en' \| 'ja'` | `'en'` | Bundled UI language |
67
- | `messages` | `EditorMessagesOverride` | — | Replace individual strings, or supply a whole language |
68
- | `shortcutHelp` | `boolean` | `true` | Built-in shortcut sheet (`Mod-Alt-/`) |
69
- | `contextMenu` | `boolean` | `true` | Built-in context menu (right click / `Mod-/`) |
70
- | `uploadImage` | `(file: File) => Promise<string \| null>` | — | Takes a pasted image, returns the URL to display |
54
+ | | Type | Default | |
55
+ | ------------------- | ------------------------------------------- | -------- | ------------------------------------------------------------------ |
56
+ | `value` | `string` | `''` | Markdown source (bindable). Applied as an undoable replacement |
57
+ | `onChange` | `(markdown: string) => void` | — | Not needed when you use `bind:value` |
58
+ | `viewState` | `ViewState` | — | Which headings are folded, which section is zoomed |
59
+ | `onViewStateChange` | `(viewState: ViewState) => void` | — | Not needed when you use `bind:viewState` |
60
+ | `label` | `string` | built-in | Accessible name for the editing surface |
61
+ | `readonly` | `boolean` | `false` | Rejects typing, commands and pastes |
62
+ | `autofocus` | `boolean` | `false` | Focus on mount |
63
+ | `class` | `string` | `''` | Extra class names |
64
+ | `padding` | `string` | token | Written exactly like CSS `padding` |
65
+ | `maxWidth` | `string` | token | Line length. **The clickable surface keeps the full width** |
66
+ | `lang` | `'en' \| 'ja'` | `'en'` | Bundled UI language |
67
+ | `messages` | `EditorMessagesOverride` | — | Replace individual strings, or supply a whole language |
68
+ | `shortcutHelp` | `boolean` | `true` | Built-in shortcut sheet (`Mod-Alt-/`) |
69
+ | `contextMenu` | `boolean` | `true` | Built-in context menu (right click / `Mod-/`) |
70
+ | `uploadImage` | `(file: File) => Promise<string \| null>` | — | Takes a pasted image, returns the URL to display |
71
+ | `onLinkClick` | `(href: string, event: MouseEvent) => void` | — | Called when a link is clicked; opens in a new tab unless prevented |
71
72
 
72
73
  `viewState` is **how you are looking at the document**, not its content. This module stores nothing, so persist it wherever you like — or not at all.
73
74
 
@@ -88,6 +89,24 @@ While it waits, a marker is shown at the paste position and **the document is no
88
89
 
89
90
  **Rendering an image fetches it.** A document that names an external URL will request it from that host every time it is shown — that is what drawing image notation means.
90
91
 
92
+ ### Links
93
+
94
+ Links open in a new tab.
95
+
96
+ - **While editing**, a bubble showing the target appears above the link whenever the cursor touches it; clicking (or tapping) the bubble opens the link. A plain click on the link still just places the cursor, so touch devices open links with "tap the link, then tap the bubble". ⌘-click (Ctrl-click outside macOS) opens directly, skipping the bubble
97
+ - **While `readonly`**, a plain click opens the link
98
+
99
+ Before opening, `onLinkClick` receives the `href` exactly as written (relative links are not resolved). Call `event.preventDefault()` to stop the new tab — useful for targets such as `./other.md` that mean nothing to the browser but something to your app.
100
+
101
+ ```ts
102
+ const onLinkClick = (href: string, event: MouseEvent) => {
103
+ if (href.endsWith('.md')) {
104
+ event.preventDefault();
105
+ openDocument(href);
106
+ }
107
+ };
108
+ ```
109
+
91
110
  For a language that is not bundled, start from a bundled set:
92
111
 
93
112
  ```ts
@@ -1242,6 +1242,13 @@
1242
1242
  color: var(--markdown-editor-link);
1243
1243
  }
1244
1244
 
1245
+ /* 押せば開くときだけ指の形にする。編集中の素のクリックはカーソルを置く操作である
1246
+ (修飾キーの状態は `linkClick` プラグインが `data-link-open` へ写す) */
1247
+ .markdown-editor__surface[aria-readonly] .markdown-editor__link,
1248
+ .markdown-editor__surface[data-link-open] .markdown-editor__link {
1249
+ cursor: pointer;
1250
+ }
1251
+
1245
1252
  /* --- 箇条書き ---
1246
1253
  項目は 1 ノードで 1 項目にあたり、入れ子は項目の中に項目を置く形で表す。
1247
1254
  クラス名と data 属性は編集基盤(prosemirror-flat-list)が付けるものに合わせる。
@@ -382,6 +382,10 @@
382
382
  --markdown-editor-popup-shadow: var(--markdown-editor-shadow);
383
383
  --markdown-editor-popup-shadow-weak: var(--markdown-editor-shadow-weak);
384
384
 
385
+ /* カーソルがリンクにあるあいだ出す吹き出し */
386
+ --markdown-editor-url-bubble-color: var(--markdown-editor-hyperlink);
387
+ --markdown-editor-url-bubble-hover: var(--markdown-editor-hover-overlay);
388
+
385
389
  /* コンテキストメニュー */
386
390
  --markdown-editor-menu-separator: var(--markdown-editor-border);
387
391
  --markdown-editor-menu-group-title-color: var(--markdown-editor-text-subtle);
@@ -12,7 +12,7 @@
12
12
  import { formatShortcutKeys } from '../operations/keymap/shortcutKeys.js';
13
13
  import type { EditorAction, ShortcutCategory } from '../operations/operations.types';
14
14
  import type { ContextMenuController } from '../states/contextMenuController.svelte';
15
- import Popup from './internal/Popup.svelte';
15
+ import MenuPopup from './internal/MenuPopup.svelte';
16
16
 
17
17
  interface Props {
18
18
  controller: ContextMenuController;
@@ -84,8 +84,8 @@
84
84
  /**
85
85
  * 選んでいる項目へ実フォーカスを移す。
86
86
  *
87
- * 何も選んでいないあいだはコンテナにフォーカスが載ったままで、`Popup` が開くときに
88
- * そこへ移している。移し先がコンテナの中なら閉じない(`Popup` の `onFocusOut` が
87
+ * 何も選んでいないあいだはコンテナにフォーカスが載ったままで、`MenuPopup` が開くときに
88
+ * そこへ移している。移し先がコンテナの中なら閉じない(`MenuPopup` の `onFocusOut` が
89
89
  * 移り先を見ている)。
90
90
  */
91
91
  function focusActive(): void {
@@ -115,7 +115,7 @@
115
115
  });
116
116
  </script>
117
117
 
118
- <Popup
118
+ <MenuPopup
119
119
  open={controller.isOpen}
120
120
  anchor={controller.anchor}
121
121
  class="markdown-editor-context-menu"
@@ -167,7 +167,7 @@
167
167
  </ul>
168
168
  {/each}
169
169
  </div>
170
- </Popup>
170
+ </MenuPopup>
171
171
 
172
172
  <style>
173
173
  /**
@@ -0,0 +1,120 @@
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>
@@ -0,0 +1,9 @@
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,6 +1,7 @@
1
1
  <script lang="ts" module>
2
2
  import type { EditorLang, EditorMessagesOverride } from '../messages/messages.types';
3
3
  import type { ImageUpload } from '../operations/plugins/imagePaste';
4
+ import type { LinkClick } from '../operations/plugins/linkClick';
4
5
  import type {
5
6
  FrontMatterFields,
6
7
  FrontMatterWriteError,
@@ -89,6 +90,15 @@
89
90
  * 読み取り専用のあいだは呼ばれない。
90
91
  */
91
92
  uploadImage?: ImageUpload;
93
+ /**
94
+ * リンクが押されたときの通知。`href` は書かれたとおりの値で、相対のままでも解決しない。
95
+ *
96
+ * 編集中はカーソルがリンクにあるあいだ出る吹き出しを押したときと、⌘+クリック
97
+ * (Mac 以外は Ctrl+クリック)で、読み取り専用では素のクリックで呼ばれる。
98
+ * `event.preventDefault()` を呼べば、新しいタブで開く既定の動きを止められる。
99
+ * 呼ばなければ(または渡さなければ)新しいタブで開く。
100
+ */
101
+ onLinkClick?: LinkClick;
92
102
  }
93
103
 
94
104
  /** `padding` を四辺へ展開したもの。CSS 側へは辺ごとに渡す(→ `expandPadding`) */
@@ -182,11 +192,13 @@
182
192
  import { resolveMessages } from '../messages/index.js';
183
193
  import { EMPTY_VIEW_STATE, isSameViewState } from '../models/viewState/viewStateCodec.js';
184
194
  import { createContextMenuController } from '../states/contextMenuController.svelte';
195
+ import { createLinkBubbleController } from '../states/linkBubbleController.svelte';
185
196
  import { createOutlineViewController } from '../states/outlineViewController.svelte';
186
197
  import type { EditorSession } from '../states/editorSession.types';
187
198
  import ContextMenu from './ContextMenu.svelte';
188
199
  import EditorSurface from './EditorSurface.svelte';
189
200
  import FocusBreadcrumb from './FocusBreadcrumb.svelte';
201
+ import LinkBubble from './LinkBubble.svelte';
190
202
  import ShortcutHelpDialog from './ShortcutHelpDialog.svelte';
191
203
 
192
204
  // --- props ---
@@ -206,7 +218,8 @@
206
218
  onViewStateChange,
207
219
  shortcutHelp = true,
208
220
  contextMenu = true,
209
- uploadImage
221
+ uploadImage,
222
+ onLinkClick
210
223
  }: MarkdownEditorProps = $props();
211
224
 
212
225
  // --- 状態 ---
@@ -264,6 +277,11 @@
264
277
  isEnabled: () => contextMenu
265
278
  });
266
279
 
280
+ const linkBubble = createLinkBubbleController({
281
+ getSession: () => session,
282
+ getLinkClick: () => onLinkClick
283
+ });
284
+
267
285
  /** 一覧へ渡す拡張の宣言。**両方のコントローラのぶんを渡す**(メニューの割り当ても一覧に出す) */
268
286
  const listedActions = $derived([
269
287
  ...controller.extension.actions,
@@ -284,7 +302,8 @@
284
302
  * 呼ぶ時点の値が使われ、表示の組み直し(`view.setProps`)も起きない。
285
303
  */
286
304
  imageUpload: () => uploadImage,
287
- extensions: [controller.extension, menuController.extension]
305
+ linkClick: () => onLinkClick,
306
+ extensions: [controller.extension, menuController.extension, linkBubble.extension]
288
307
  };
289
308
 
290
309
  // --- 関数 ---
@@ -466,4 +485,5 @@
466
485
  {#if contextMenu}
467
486
  <ContextMenu controller={menuController} {text} />
468
487
  {/if}
488
+ <LinkBubble controller={linkBubble} openLabel={text.linkOpen} />
469
489
  </div>
@@ -1,5 +1,6 @@
1
1
  import type { EditorLang, EditorMessagesOverride } from '../messages/messages.types';
2
2
  import type { ImageUpload } from '../operations/plugins/imagePaste';
3
+ import type { LinkClick } from '../operations/plugins/linkClick';
3
4
  import type { FrontMatterFields, FrontMatterWriteError, FrontMatterWriteOutcome } from '../models/markdown/markdown.types';
4
5
  import type { Result } from '../utils/result.types';
5
6
  import type { ViewState } from '../models/viewState/viewState.types';
@@ -83,6 +84,15 @@ export interface MarkdownEditorProps {
83
84
  * 読み取り専用のあいだは呼ばれない。
84
85
  */
85
86
  uploadImage?: ImageUpload;
87
+ /**
88
+ * リンクが押されたときの通知。`href` は書かれたとおりの値で、相対のままでも解決しない。
89
+ *
90
+ * 編集中はカーソルがリンクにあるあいだ出る吹き出しを押したときと、⌘+クリック
91
+ * (Mac 以外は Ctrl+クリック)で、読み取り専用では素のクリックで呼ばれる。
92
+ * `event.preventDefault()` を呼べば、新しいタブで開く既定の動きを止められる。
93
+ * 呼ばなければ(または渡さなければ)新しいタブで開く。
94
+ */
95
+ onLinkClick?: LinkClick;
86
96
  }
87
97
  /** `padding` を四辺へ展開したもの。CSS 側へは辺ごとに渡す(→ `expandPadding`) */
88
98
  export interface EditorPadding {
@@ -0,0 +1,145 @@
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>
@@ -0,0 +1,26 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { AnchorRect } from '../../utils/geometry.types';
3
+ interface Props {
4
+ children: Snippet;
5
+ /** 錨の矩形。開くたびに読み直す */
6
+ anchor: AnchorRect | null;
7
+ open: boolean;
8
+ /** コンテナの役割。既定は menu */
9
+ role?: string;
10
+ ariaLabel?: string;
11
+ /** いま選んでいる子要素の id。中身の側は実フォーカスもそこへ移す */
12
+ ariaActivedescendant?: string;
13
+ class?: string;
14
+ /**
15
+ * 中で押されたキー。`Tab` の循環より**先**に呼ぶ。
16
+ * 既定動作を止めた(受け止めた)ときは、循環の判定へ進まない
17
+ */
18
+ onKeyDown?: (event: KeyboardEvent) => void;
19
+ /** 操作対象がポップアップの外へ移ったときの通知。中での移動では呼ばない */
20
+ onFocusOut?: () => void;
21
+ /** 外の動き(スクロール・リサイズ)で閉じたいときの通知。自分では閉じない */
22
+ onClose?: () => void;
23
+ }
24
+ declare const MenuPopup: import("svelte").Component<Props, {}, "">;
25
+ type MenuPopup = ReturnType<typeof MenuPopup>;
26
+ export default MenuPopup;