@14ch/svelte-md-outliner 0.0.25 → 0.0.27
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 +44 -0
- package/README.ja.md +4 -1
- package/README.md +4 -1
- package/dist/assets/styles/theme.css +9 -0
- package/dist/components/LinkPopover.svelte +196 -0
- package/dist/components/LinkPopover.svelte.d.ts +9 -0
- package/dist/components/MarkdownEditor.svelte +11 -2
- package/dist/components/MarkdownEditor.svelte.d.ts +2 -1
- package/dist/messages/en.js +1 -0
- package/dist/messages/index.js +1 -0
- package/dist/messages/ja.js +1 -0
- package/dist/messages/messages.types.d.ts +3 -0
- package/dist/operations/plugins/linkClick.d.ts +11 -1
- package/dist/operations/plugins/linkClick.js +24 -7
- package/dist/operations/plugins/linkPopover.d.ts +24 -0
- package/dist/operations/plugins/linkPopover.js +92 -0
- package/dist/states/linkPopoverController.svelte.d.ts +29 -0
- package/dist/states/linkPopoverController.svelte.js +35 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,50 @@ 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.27] - 2026-11-02
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- The link popover's frame no longer follows the `--markdown-editor-popup-*`
|
|
13
|
+
tokens. It has its own: `--markdown-editor-link-popover-background`,
|
|
14
|
+
`-border`, `-shadow-strong`, `-shadow` and `-shadow-weak`.
|
|
15
|
+
- Renamed the link bubble's theme tokens added in 0.0.26:
|
|
16
|
+
`--markdown-editor-url-bubble-color` → `--markdown-editor-link-popover-color`
|
|
17
|
+
and `--markdown-editor-url-bubble-hover` → `--markdown-editor-link-popover-hover`.
|
|
18
|
+
Update any overrides that use the old names.
|
|
19
|
+
- The link popover appears only when you click or tap a link. It no longer
|
|
20
|
+
appears when the cursor enters a link by keyboard, and typing or moving the
|
|
21
|
+
cursor with the keyboard hides it.
|
|
22
|
+
- The link popover is placed in the document and scrolls with the text, so it
|
|
23
|
+
stays attached to the link instead of floating over the page.
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- On phones, the link popover no longer appears far above the link when the
|
|
28
|
+
on-screen keyboard is shown.
|
|
29
|
+
- The link popover no longer overflows an editor narrower than the screen.
|
|
30
|
+
|
|
31
|
+
## [0.0.26] - 2026-11-02
|
|
32
|
+
|
|
33
|
+
### Added
|
|
34
|
+
|
|
35
|
+
- While editing, a bubble showing the link target appears above a link whenever
|
|
36
|
+
the cursor touches it. Clicking or tapping the bubble opens the link, so links
|
|
37
|
+
can now be opened on touch devices, which have no ⌘/Ctrl key. ⌘-click
|
|
38
|
+
(Ctrl-click outside macOS) still opens a link directly. The bubble also calls
|
|
39
|
+
`onLinkClick` first.
|
|
40
|
+
- `linkOpen` message: the accessible name of the bubble. Add it if you pass a
|
|
41
|
+
full message set for a language that is not bundled.
|
|
42
|
+
- Theme tokens for the bubble: `--markdown-editor-url-bubble-color` and
|
|
43
|
+
`--markdown-editor-url-bubble-hover`.
|
|
44
|
+
|
|
45
|
+
### Fixed
|
|
46
|
+
|
|
47
|
+
- ⌘-clicking a link now brings the new tab to the front instead of opening it
|
|
48
|
+
in the background.
|
|
49
|
+
- A plain click on a link while editing no longer navigates the page in apps
|
|
50
|
+
whose router handles link clicks (such as SvelteKit).
|
|
51
|
+
|
|
8
52
|
## [0.0.25] - 2026-10-29
|
|
9
53
|
|
|
10
54
|
### Added
|
package/README.ja.md
CHANGED
|
@@ -91,7 +91,10 @@ const uploadImage = async (file: File) => {
|
|
|
91
91
|
|
|
92
92
|
### リンク
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
リンク先は新しいタブで開く。
|
|
95
|
+
|
|
96
|
+
- **編集中**は、リンクを押す(タップする)とカーソルが置かれ、リンクの上にリンク先を見せる吹き出しが出る。吹き出しを押すと開く。文字を打つ・キーでカーソルを動かすと消え、キーでリンクに入ったときは出ない。タッチ端末でも「リンクをタップして、吹き出しをタップ」で開ける。⌘+クリック(Mac 以外は Ctrl+クリック)なら吹き出しを経ずに開く
|
|
97
|
+
- **読み取り専用**では、素のクリックで開く
|
|
95
98
|
|
|
96
99
|
開く前に `onLinkClick` が書かれたとおりの `href` を受け取る(相対のままでも解決しない)。`event.preventDefault()` を呼べば、新しいタブでは開かない。`./other.md` のように、ブラウザで開いても意味を持たない行き先を利用側で扱うときに使う。
|
|
97
100
|
|
package/README.md
CHANGED
|
@@ -91,7 +91,10 @@ While it waits, a marker is shown at the paste position and **the document is no
|
|
|
91
91
|
|
|
92
92
|
### Links
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
Links open in a new tab.
|
|
95
|
+
|
|
96
|
+
- **While editing**, clicking (or tapping) a link places the cursor and shows a bubble with the target above it; clicking the bubble opens the link. Typing or moving the cursor with the keyboard hides the bubble, and it does not appear when the cursor enters a link by keyboard, 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
|
|
95
98
|
|
|
96
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.
|
|
97
100
|
|
|
@@ -382,6 +382,15 @@
|
|
|
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-link-popover-background: var(--markdown-editor-surface-elevated);
|
|
387
|
+
--markdown-editor-link-popover-border: var(--markdown-editor-border-weak);
|
|
388
|
+
--markdown-editor-link-popover-shadow-strong: var(--markdown-editor-shadow-strong);
|
|
389
|
+
--markdown-editor-link-popover-shadow: var(--markdown-editor-shadow);
|
|
390
|
+
--markdown-editor-link-popover-shadow-weak: var(--markdown-editor-shadow-weak);
|
|
391
|
+
--markdown-editor-link-popover-color: var(--markdown-editor-hyperlink);
|
|
392
|
+
--markdown-editor-link-popover-hover: var(--markdown-editor-hover-overlay);
|
|
393
|
+
|
|
385
394
|
/* コンテキストメニュー */
|
|
386
395
|
--markdown-editor-menu-separator: var(--markdown-editor-border);
|
|
387
396
|
--markdown-editor-menu-group-title-color: var(--markdown-editor-text-subtle);
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
リンクを押して(タップして)カーソルを入れたときに出す吹き出し。リンク先を見せ、押すとそこを開く。
|
|
3
|
+
|
|
4
|
+
**ポップアップ(`Popup`)には載せない。本文の中に絶対配置で置く。** 吹き出しはリンクに
|
|
5
|
+
付いているものであり、本文と一緒に動くのが正しい。画面に固定して重ねると、スクロール
|
|
6
|
+
のたびに閉じるか置き直すかを迫られ、スマートフォンではキーボードが出るだけで本文が
|
|
7
|
+
動いて閉じてしまう。本文の中に置けば、リンクとの相対位置はスクロールでもキーボードでも
|
|
8
|
+
変わらない。
|
|
9
|
+
|
|
10
|
+
位置は「リンクの矩形 − この層の矩形」で決める。**同じ瞬間に同じ測り方で測った差**なので、
|
|
11
|
+
表示領域の基準(スクロール位置・キーボードで縮んだ範囲)がどうであっても打ち消し合う。
|
|
12
|
+
|
|
13
|
+
- **焦点を奪わない。** 焦点が編集エリアを離れると吹き出しは消えるので、奪うと
|
|
14
|
+
押す前に消える。タッチ端末ではキーボードも引っ込む。押しても焦点が動かないよう、
|
|
15
|
+
`mousedown` を止める
|
|
16
|
+
- **リンクの上に出す。** タッチ端末では画面の下半分をキーボードが覆う。エディタの
|
|
17
|
+
上端か表示領域の上端を越えるときだけ下へ返す
|
|
18
|
+
-->
|
|
19
|
+
<script lang="ts">
|
|
20
|
+
import type { LinkPopoverController } from '../states/linkPopoverController.svelte';
|
|
21
|
+
|
|
22
|
+
interface Props {
|
|
23
|
+
controller: LinkPopoverController;
|
|
24
|
+
/** 吹き出しのアクセシブルな名前。リンク先を後ろに続けて読ませる */
|
|
25
|
+
openLabel: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let { controller, openLabel }: Props = $props();
|
|
29
|
+
|
|
30
|
+
/** リンクと吹き出しのあいだ */
|
|
31
|
+
const GAP = 6;
|
|
32
|
+
/** 表示領域の端から空ける距離 */
|
|
33
|
+
const MARGIN = 8;
|
|
34
|
+
|
|
35
|
+
let layerRef: HTMLDivElement | undefined = $state();
|
|
36
|
+
let popoverRef: HTMLDivElement | undefined = $state();
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 出しているあいだ、リンクが動くたびに置き直す。本文が折り返し直す(表示領域の幅が
|
|
40
|
+
* 変わる)ときも置き直す。スクロールでは置き直さない——本文と一緒に動くからである。
|
|
41
|
+
*/
|
|
42
|
+
$effect(() => {
|
|
43
|
+
if (!controller.link || !popoverRef) return;
|
|
44
|
+
|
|
45
|
+
place();
|
|
46
|
+
window.addEventListener('resize', place);
|
|
47
|
+
return () => window.removeEventListener('resize', place);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
/** リンクの先頭に左端をそろえ、上に置く。収まらないときは下へ返し、横は中へ寄せる */
|
|
51
|
+
function place(): void {
|
|
52
|
+
const anchor = controller.measure();
|
|
53
|
+
const layer = layerRef;
|
|
54
|
+
const popover = popoverRef;
|
|
55
|
+
const editor = layer?.parentElement;
|
|
56
|
+
if (!anchor || !layer || !popover || !editor) return;
|
|
57
|
+
|
|
58
|
+
const origin = layer.getBoundingClientRect();
|
|
59
|
+
const bounds = editor.getBoundingClientRect();
|
|
60
|
+
const width = popover.offsetWidth;
|
|
61
|
+
const height = popover.offsetHeight;
|
|
62
|
+
|
|
63
|
+
const above = anchor.top - GAP - height;
|
|
64
|
+
const top = above >= Math.max(bounds.top, 0) ? above : anchor.bottom + GAP;
|
|
65
|
+
|
|
66
|
+
const minLeft = Math.max(bounds.left, MARGIN);
|
|
67
|
+
const maxLeft = Math.min(bounds.right, window.innerWidth - MARGIN) - width;
|
|
68
|
+
const left = Math.max(minLeft, Math.min(anchor.left, maxLeft));
|
|
69
|
+
|
|
70
|
+
popover.style.top = `${top - origin.top}px`;
|
|
71
|
+
popover.style.left = `${left - origin.left}px`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function keepFocus(event: MouseEvent): void {
|
|
75
|
+
event.preventDefault();
|
|
76
|
+
}
|
|
77
|
+
</script>
|
|
78
|
+
|
|
79
|
+
<!-- 位置の原点にする層。高さを持たず、並びを押し広げない -->
|
|
80
|
+
<div class="markdown-editor-link-popover-layer" bind:this={layerRef}>
|
|
81
|
+
{#if controller.link}
|
|
82
|
+
<!-- 押しても焦点を移さないための受け止め。キーで届く操作はボタンが持つ -->
|
|
83
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
84
|
+
<div class="markdown-editor-link-popover" bind:this={popoverRef} onmousedown={keepFocus}>
|
|
85
|
+
<!-- 吹き出し全体を 1 つのボタンにする。押せる面が広いほどタッチ端末で押しやすい -->
|
|
86
|
+
<button
|
|
87
|
+
type="button"
|
|
88
|
+
class="markdown-editor-link-popover__open"
|
|
89
|
+
aria-label="{openLabel}: {controller.link.href}"
|
|
90
|
+
title={controller.link.href}
|
|
91
|
+
onclick={controller.open}
|
|
92
|
+
>
|
|
93
|
+
<!-- 新しいタブで開くことの印。吹き出しはリンクの先頭にそろうので、左に置けば押す目当てが近い -->
|
|
94
|
+
<svg class="markdown-editor-link-popover__icon" viewBox="0 0 16 16" aria-hidden="true">
|
|
95
|
+
<path d="M6 3H3v10h10v-3M9 3h4v4M13 3 7 9" />
|
|
96
|
+
</svg>
|
|
97
|
+
<span class="markdown-editor-link-popover__target">{controller.link.href}</span>
|
|
98
|
+
</button>
|
|
99
|
+
</div>
|
|
100
|
+
{/if}
|
|
101
|
+
</div>
|
|
102
|
+
|
|
103
|
+
<style>
|
|
104
|
+
/**
|
|
105
|
+
* 本文の上へ重ねるため、自分で重なりの文脈を作る(本文の中の位置付きの要素より手前)。
|
|
106
|
+
*/
|
|
107
|
+
.markdown-editor-link-popover-layer {
|
|
108
|
+
position: relative;
|
|
109
|
+
z-index: 1;
|
|
110
|
+
height: 0;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 幅の上限は**エディタの幅**で抑える(層はエディタと同じ幅)。表示領域の幅で抑えると、
|
|
115
|
+
* エディタが画面より狭いとき(スマートフォンで左右に余白がある置き方)にはみ出す。
|
|
116
|
+
*/
|
|
117
|
+
.markdown-editor-link-popover {
|
|
118
|
+
position: absolute;
|
|
119
|
+
box-sizing: border-box;
|
|
120
|
+
max-width: min(360px, 100%);
|
|
121
|
+
border: 1px solid var(--markdown-editor-link-popover-border);
|
|
122
|
+
border-radius: var(--markdown-editor-radius);
|
|
123
|
+
background: var(--markdown-editor-link-popover-background);
|
|
124
|
+
box-shadow:
|
|
125
|
+
0 11px 15px -7px var(--markdown-editor-link-popover-shadow-strong),
|
|
126
|
+
0 24px 38px 3px var(--markdown-editor-link-popover-shadow),
|
|
127
|
+
0 9px 46px 8px var(--markdown-editor-link-popover-shadow-weak);
|
|
128
|
+
overflow: hidden;
|
|
129
|
+
animation: markdown-editor-link-popover-in 120ms forwards;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@keyframes markdown-editor-link-popover-in {
|
|
133
|
+
from {
|
|
134
|
+
opacity: 0;
|
|
135
|
+
}
|
|
136
|
+
to {
|
|
137
|
+
opacity: 1;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
@media (prefers-reduced-motion: reduce) {
|
|
142
|
+
.markdown-editor-link-popover {
|
|
143
|
+
animation-duration: 0.01s;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** 行間は本文のものを引き継がない(地の文ではない) */
|
|
148
|
+
.markdown-editor-link-popover__open {
|
|
149
|
+
box-sizing: border-box;
|
|
150
|
+
display: flex;
|
|
151
|
+
align-items: center;
|
|
152
|
+
gap: 6px;
|
|
153
|
+
max-width: 100%;
|
|
154
|
+
padding: 8px 12px;
|
|
155
|
+
border: 0;
|
|
156
|
+
background: none;
|
|
157
|
+
color: var(--markdown-editor-link-popover-color);
|
|
158
|
+
font: inherit;
|
|
159
|
+
font-size: var(--markdown-editor-font-size-sm);
|
|
160
|
+
line-height: normal;
|
|
161
|
+
text-align: left;
|
|
162
|
+
white-space: nowrap;
|
|
163
|
+
cursor: pointer;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.markdown-editor-link-popover__target {
|
|
167
|
+
min-width: 0;
|
|
168
|
+
overflow: hidden;
|
|
169
|
+
text-overflow: ellipsis;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.markdown-editor-link-popover__icon {
|
|
173
|
+
flex: none;
|
|
174
|
+
width: 1em;
|
|
175
|
+
height: 1em;
|
|
176
|
+
fill: none;
|
|
177
|
+
stroke: currentColor;
|
|
178
|
+
stroke-width: 1.5;
|
|
179
|
+
stroke-linecap: round;
|
|
180
|
+
stroke-linejoin: round;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/* 触れる入力しかない環境では `:hover` が居座るため、囲って外す */
|
|
184
|
+
@media (hover: hover) {
|
|
185
|
+
.markdown-editor-link-popover__open:hover {
|
|
186
|
+
background: var(--markdown-editor-link-popover-hover);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/* 触れる端末でのターゲットの大きさ */
|
|
191
|
+
@media (max-width: 768px) {
|
|
192
|
+
.markdown-editor-link-popover__open {
|
|
193
|
+
min-height: var(--markdown-editor-touch-target);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
</style>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LinkPopoverController } from '../states/linkPopoverController.svelte';
|
|
2
|
+
interface Props {
|
|
3
|
+
controller: LinkPopoverController;
|
|
4
|
+
/** 吹き出しのアクセシブルな名前。リンク先を後ろに続けて読ませる */
|
|
5
|
+
openLabel: string;
|
|
6
|
+
}
|
|
7
|
+
declare const LinkPopover: import("svelte").Component<Props, {}, "">;
|
|
8
|
+
type LinkPopover = ReturnType<typeof LinkPopover>;
|
|
9
|
+
export default LinkPopover;
|
|
@@ -93,7 +93,8 @@
|
|
|
93
93
|
/**
|
|
94
94
|
* リンクが押されたときの通知。`href` は書かれたとおりの値で、相対のままでも解決しない。
|
|
95
95
|
*
|
|
96
|
-
*
|
|
96
|
+
* 編集中はリンクを押すと出る吹き出しを押したときと、⌘+クリック
|
|
97
|
+
* (Mac 以外は Ctrl+クリック)で、読み取り専用では素のクリックで呼ばれる。
|
|
97
98
|
* `event.preventDefault()` を呼べば、新しいタブで開く既定の動きを止められる。
|
|
98
99
|
* 呼ばなければ(または渡さなければ)新しいタブで開く。
|
|
99
100
|
*/
|
|
@@ -191,11 +192,13 @@
|
|
|
191
192
|
import { resolveMessages } from '../messages/index.js';
|
|
192
193
|
import { EMPTY_VIEW_STATE, isSameViewState } from '../models/viewState/viewStateCodec.js';
|
|
193
194
|
import { createContextMenuController } from '../states/contextMenuController.svelte';
|
|
195
|
+
import { createLinkPopoverController } from '../states/linkPopoverController.svelte';
|
|
194
196
|
import { createOutlineViewController } from '../states/outlineViewController.svelte';
|
|
195
197
|
import type { EditorSession } from '../states/editorSession.types';
|
|
196
198
|
import ContextMenu from './ContextMenu.svelte';
|
|
197
199
|
import EditorSurface from './EditorSurface.svelte';
|
|
198
200
|
import FocusBreadcrumb from './FocusBreadcrumb.svelte';
|
|
201
|
+
import LinkPopover from './LinkPopover.svelte';
|
|
199
202
|
import ShortcutHelpDialog from './ShortcutHelpDialog.svelte';
|
|
200
203
|
|
|
201
204
|
// --- props ---
|
|
@@ -274,6 +277,11 @@
|
|
|
274
277
|
isEnabled: () => contextMenu
|
|
275
278
|
});
|
|
276
279
|
|
|
280
|
+
const linkPopover = createLinkPopoverController({
|
|
281
|
+
getSession: () => session,
|
|
282
|
+
getLinkClick: () => onLinkClick
|
|
283
|
+
});
|
|
284
|
+
|
|
277
285
|
/** 一覧へ渡す拡張の宣言。**両方のコントローラのぶんを渡す**(メニューの割り当ても一覧に出す) */
|
|
278
286
|
const listedActions = $derived([
|
|
279
287
|
...controller.extension.actions,
|
|
@@ -295,7 +303,7 @@
|
|
|
295
303
|
*/
|
|
296
304
|
imageUpload: () => uploadImage,
|
|
297
305
|
linkClick: () => onLinkClick,
|
|
298
|
-
extensions: [controller.extension, menuController.extension]
|
|
306
|
+
extensions: [controller.extension, menuController.extension, linkPopover.extension]
|
|
299
307
|
};
|
|
300
308
|
|
|
301
309
|
// --- 関数 ---
|
|
@@ -477,4 +485,5 @@
|
|
|
477
485
|
{#if contextMenu}
|
|
478
486
|
<ContextMenu controller={menuController} {text} />
|
|
479
487
|
{/if}
|
|
488
|
+
<LinkPopover controller={linkPopover} openLabel={text.linkOpen} />
|
|
480
489
|
</div>
|
|
@@ -87,7 +87,8 @@ export interface MarkdownEditorProps {
|
|
|
87
87
|
/**
|
|
88
88
|
* リンクが押されたときの通知。`href` は書かれたとおりの値で、相対のままでも解決しない。
|
|
89
89
|
*
|
|
90
|
-
*
|
|
90
|
+
* 編集中はリンクを押すと出る吹き出しを押したときと、⌘+クリック
|
|
91
|
+
* (Mac 以外は Ctrl+クリック)で、読み取り専用では素のクリックで呼ばれる。
|
|
91
92
|
* `event.preventDefault()` を呼べば、新しいタブで開く既定の動きを止められる。
|
|
92
93
|
* 呼ばなければ(または渡さなければ)新しいタブで開く。
|
|
93
94
|
*/
|
package/dist/messages/en.js
CHANGED
|
@@ -11,6 +11,7 @@ export const en = {
|
|
|
11
11
|
mermaidLoadError: 'Failed to load the diagram renderer',
|
|
12
12
|
imageUploading: 'Uploading image…',
|
|
13
13
|
imageLoadError: 'Failed to load the image',
|
|
14
|
+
linkOpen: 'Open link',
|
|
14
15
|
frontMatterLabel: 'Front Matter',
|
|
15
16
|
shortcutCategories: {
|
|
16
17
|
edit: 'Edit',
|
package/dist/messages/index.js
CHANGED
|
@@ -28,6 +28,7 @@ export function resolveMessages(lang = DEFAULT_LANG, overrides) {
|
|
|
28
28
|
mermaidLoadError: overrides.mermaidLoadError ?? base.mermaidLoadError,
|
|
29
29
|
imageUploading: overrides.imageUploading ?? base.imageUploading,
|
|
30
30
|
imageLoadError: overrides.imageLoadError ?? base.imageLoadError,
|
|
31
|
+
linkOpen: overrides.linkOpen ?? base.linkOpen,
|
|
31
32
|
frontMatterLabel: overrides.frontMatterLabel ?? base.frontMatterLabel
|
|
32
33
|
};
|
|
33
34
|
}
|
package/dist/messages/ja.js
CHANGED
|
@@ -36,6 +36,8 @@ export interface EditorMessages {
|
|
|
36
36
|
readonly imageUploading: string;
|
|
37
37
|
/** 画像の読み込みに失敗したことを伝える表示 */
|
|
38
38
|
readonly imageLoadError: string;
|
|
39
|
+
/** カーソルがリンクにあるときに出す吹き出し(押すとリンク先を開く)のアクセシブルな名前 */
|
|
40
|
+
readonly linkOpen: string;
|
|
39
41
|
/**
|
|
40
42
|
* フロントマターにタイトルが無いときに、その場所へ薄く出す名前。
|
|
41
43
|
* 状態の説明(「未設定です」)ではなく、**そこが何であるか**の表示である
|
|
@@ -61,5 +63,6 @@ export interface EditorMessagesOverride {
|
|
|
61
63
|
readonly mermaidLoadError?: string;
|
|
62
64
|
readonly imageUploading?: string;
|
|
63
65
|
readonly imageLoadError?: string;
|
|
66
|
+
readonly linkOpen?: string;
|
|
64
67
|
readonly frontMatterLabel?: string;
|
|
65
68
|
}
|
|
@@ -11,7 +11,8 @@ export type LinkClickSource = () => LinkClick | undefined;
|
|
|
11
11
|
*
|
|
12
12
|
* 編集中は**修飾キー(Mac は ⌘、それ以外は Ctrl)を添えたときだけ**開く。
|
|
13
13
|
* 素のクリックはカーソルを置く操作であり、奪うとリンクの文字を直せなくなる。
|
|
14
|
-
*
|
|
14
|
+
* 修飾キーの無いタッチ端末では、リンクを押すと出る吹き出しから開く
|
|
15
|
+
* (→ `linkPopover`)。読み取り専用では素のクリックで開く。
|
|
15
16
|
*
|
|
16
17
|
* 開く前に利用側へ知らせる。相対のリンク(`./other.md`)のように、ブラウザで開いても
|
|
17
18
|
* 意味を持たない行き先は、利用側が引き取って扱う。
|
|
@@ -22,3 +23,12 @@ export type LinkClickSource = () => LinkClick | undefined;
|
|
|
22
23
|
* ポインタの形で見せるためで、CSS からはキーの状態が読めない。
|
|
23
24
|
*/
|
|
24
25
|
export declare function linkClickPlugin(getLinkClick: LinkClickSource): Plugin;
|
|
26
|
+
/**
|
|
27
|
+
* 利用側へ知らせ、止められなければ新しいタブで開く。
|
|
28
|
+
*
|
|
29
|
+
* **開くのは押した出来事を抜けてから。** 出来事の最中に開くと、実行環境は押されている
|
|
30
|
+
* 修飾キーを見て開き方を決め、⌘+クリックでは新しいタブを背後に回す。利用者は元の
|
|
31
|
+
* タブに残されたまま、何が起きたのかが分からない。抜けた後なら修飾キーは見られず、
|
|
32
|
+
* 新しいタブが前に出る(押した直後なので、ポップアップの制限にも掛からない)。
|
|
33
|
+
*/
|
|
34
|
+
export declare function openLink(href: string, event: MouseEvent, getLinkClick: LinkClickSource): void;
|
|
@@ -5,7 +5,8 @@ import { isMacPlatform } from '../keymap/shortcutKeys.js';
|
|
|
5
5
|
*
|
|
6
6
|
* 編集中は**修飾キー(Mac は ⌘、それ以外は Ctrl)を添えたときだけ**開く。
|
|
7
7
|
* 素のクリックはカーソルを置く操作であり、奪うとリンクの文字を直せなくなる。
|
|
8
|
-
*
|
|
8
|
+
* 修飾キーの無いタッチ端末では、リンクを押すと出る吹き出しから開く
|
|
9
|
+
* (→ `linkPopover`)。読み取り専用では素のクリックで開く。
|
|
9
10
|
*
|
|
10
11
|
* 開く前に利用側へ知らせる。相対のリンク(`./other.md`)のように、ブラウザで開いても
|
|
11
12
|
* 意味を持たない行き先は、利用側が引き取って扱う。
|
|
@@ -28,24 +29,40 @@ export function linkClickPlugin(getLinkClick) {
|
|
|
28
29
|
function handleClick(view, event, getLinkClick) {
|
|
29
30
|
if (event.button !== 0)
|
|
30
31
|
return false;
|
|
31
|
-
if (view.editable && !isModifierHeld(event))
|
|
32
|
-
return false;
|
|
33
32
|
const target = event.target;
|
|
34
33
|
if (!(target instanceof Element))
|
|
35
34
|
return false;
|
|
36
35
|
const link = target.closest('a.markdown-editor__link');
|
|
37
36
|
if (!(link instanceof HTMLAnchorElement) || !view.dom.contains(link))
|
|
38
37
|
return false;
|
|
38
|
+
// カーソルを置くだけのクリックでも、ページの遷移は止める。編集中のリンクを実行環境は
|
|
39
|
+
// たどらないが、置いた側のルーター(SvelteKit など)は文書全体でクリックを拾ってたどる。
|
|
40
|
+
// カーソルは押した時点(`mousedown`)で置かれているので、止めても妨げない
|
|
41
|
+
if (view.editable && !isModifierHeld(event)) {
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
39
45
|
const href = link.getAttribute('href');
|
|
40
46
|
if (!href)
|
|
41
47
|
return false;
|
|
42
|
-
|
|
43
|
-
if (event.defaultPrevented)
|
|
44
|
-
return true;
|
|
48
|
+
openLink(href, event, getLinkClick);
|
|
45
49
|
event.preventDefault();
|
|
46
|
-
window.open(href, '_blank', 'noopener,noreferrer');
|
|
47
50
|
return true;
|
|
48
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* 利用側へ知らせ、止められなければ新しいタブで開く。
|
|
54
|
+
*
|
|
55
|
+
* **開くのは押した出来事を抜けてから。** 出来事の最中に開くと、実行環境は押されている
|
|
56
|
+
* 修飾キーを見て開き方を決め、⌘+クリックでは新しいタブを背後に回す。利用者は元の
|
|
57
|
+
* タブに残されたまま、何が起きたのかが分からない。抜けた後なら修飾キーは見られず、
|
|
58
|
+
* 新しいタブが前に出る(押した直後なので、ポップアップの制限にも掛からない)。
|
|
59
|
+
*/
|
|
60
|
+
export function openLink(href, event, getLinkClick) {
|
|
61
|
+
getLinkClick()?.(href, event);
|
|
62
|
+
if (event.defaultPrevented)
|
|
63
|
+
return;
|
|
64
|
+
setTimeout(() => window.open(href, '_blank', 'noopener,noreferrer'));
|
|
65
|
+
}
|
|
49
66
|
function isModifierHeld(event) {
|
|
50
67
|
return isMacPlatform() ? event.metaKey : event.ctrlKey;
|
|
51
68
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Plugin } from 'prosemirror-state';
|
|
2
|
+
import type { EditorView } from 'prosemirror-view';
|
|
3
|
+
/** カーソルが触れているリンク。`from` はリンクの先頭の位置 */
|
|
4
|
+
export interface LinkAtCursor {
|
|
5
|
+
readonly href: string;
|
|
6
|
+
readonly from: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* 吹き出しを出すリンクを見張り、変わるたびに知らせる。表示は持たない(→ `LinkPopover`)。
|
|
10
|
+
*
|
|
11
|
+
* **出すのは、リンクを押して(タップして)カーソルを入れたときだけである。** 開きたいかも
|
|
12
|
+
* しれないという合図はそれしかない。矢印キーでリンクを通り過ぎるとき・リンクの文字を
|
|
13
|
+
* 直しているときに出ると邪魔になる。押した後に文字を打つ・キーでカーソルを動かすと消える。
|
|
14
|
+
*
|
|
15
|
+
* 押したかどうかは、編集基盤が押して動いた選択に付ける印(`pointer`)と、押したこと
|
|
16
|
+
* そのもの(`mousedown`)で見る。後者が要るのは、カーソルのある位置を押し直しても
|
|
17
|
+
* 選択は動かず、印の付いた transaction が来ないためである。`click` では受けない——
|
|
18
|
+
* リンクのクリックは `linkClick` が既定の動きを止めるので、後ろのプラグインへ届かない。
|
|
19
|
+
* タップでも `mousedown` は届く。
|
|
20
|
+
*
|
|
21
|
+
* 編集中に焦点があるときだけ出す。読み取り専用では素のクリックで開くので出さない。
|
|
22
|
+
* 変換の最中も出さない。
|
|
23
|
+
*/
|
|
24
|
+
export declare function linkPopoverPlugin(onChange: (view: EditorView, link: LinkAtCursor | null) => void): Plugin;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
2
|
+
import { outlineSchema } from '../../models/document/schema.js';
|
|
3
|
+
import { isEditorFocused } from './editorFocus.js';
|
|
4
|
+
const LINK = outlineSchema.marks.link;
|
|
5
|
+
/**
|
|
6
|
+
* 吹き出しを出すリンクを見張り、変わるたびに知らせる。表示は持たない(→ `LinkPopover`)。
|
|
7
|
+
*
|
|
8
|
+
* **出すのは、リンクを押して(タップして)カーソルを入れたときだけである。** 開きたいかも
|
|
9
|
+
* しれないという合図はそれしかない。矢印キーでリンクを通り過ぎるとき・リンクの文字を
|
|
10
|
+
* 直しているときに出ると邪魔になる。押した後に文字を打つ・キーでカーソルを動かすと消える。
|
|
11
|
+
*
|
|
12
|
+
* 押したかどうかは、編集基盤が押して動いた選択に付ける印(`pointer`)と、押したこと
|
|
13
|
+
* そのもの(`mousedown`)で見る。後者が要るのは、カーソルのある位置を押し直しても
|
|
14
|
+
* 選択は動かず、印の付いた transaction が来ないためである。`click` では受けない——
|
|
15
|
+
* リンクのクリックは `linkClick` が既定の動きを止めるので、後ろのプラグインへ届かない。
|
|
16
|
+
* タップでも `mousedown` は届く。
|
|
17
|
+
*
|
|
18
|
+
* 編集中に焦点があるときだけ出す。読み取り専用では素のクリックで開くので出さない。
|
|
19
|
+
* 変換の最中も出さない。
|
|
20
|
+
*/
|
|
21
|
+
export function linkPopoverPlugin(onChange) {
|
|
22
|
+
const notify = (view) => onChange(view, view.editable && !view.composing && isEditorFocused(view.state) && pointed(view.state)
|
|
23
|
+
? linkAtCursor(view.state)
|
|
24
|
+
: null);
|
|
25
|
+
return new Plugin({
|
|
26
|
+
key: linkPopoverKey,
|
|
27
|
+
state: {
|
|
28
|
+
init: () => false,
|
|
29
|
+
// 押したとき・押して動いた選択で立て、文書の変更・押さずに動いた選択で降ろす。
|
|
30
|
+
// 焦点の出入りのような、どちらでもない transaction では保つ
|
|
31
|
+
apply: (tr, current) => {
|
|
32
|
+
if (tr.getMeta(linkPopoverKey) || tr.getMeta('pointer'))
|
|
33
|
+
return true;
|
|
34
|
+
if (tr.docChanged || tr.selectionSet)
|
|
35
|
+
return false;
|
|
36
|
+
return current;
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
props: {
|
|
40
|
+
handleDOMEvents: {
|
|
41
|
+
mousedown: (view) => {
|
|
42
|
+
if (!pointed(view.state))
|
|
43
|
+
view.dispatch(view.state.tr.setMeta(linkPopoverKey, true));
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
view: (view) => {
|
|
49
|
+
notify(view);
|
|
50
|
+
return {
|
|
51
|
+
update: notify,
|
|
52
|
+
destroy: () => onChange(view, null)
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const linkPopoverKey = new PluginKey('linkPopover');
|
|
58
|
+
/** カーソルが、押して(タップして)置かれたままか */
|
|
59
|
+
function pointed(state) {
|
|
60
|
+
return linkPopoverKey.getState(state);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* カーソルが触れているリンクを返す。範囲を選んでいるときは返さない(選ぶのは直すためである)。
|
|
64
|
+
*
|
|
65
|
+
* 両端も含める。リンクの末尾をタップすると、カーソルはリンクの直後に立つ。
|
|
66
|
+
*/
|
|
67
|
+
function linkAtCursor(state) {
|
|
68
|
+
const { selection } = state;
|
|
69
|
+
if (!selection.empty)
|
|
70
|
+
return null;
|
|
71
|
+
const $pos = selection.$from;
|
|
72
|
+
const mark = linkOf($pos.nodeAfter?.marks) ?? linkOf($pos.nodeBefore?.marks);
|
|
73
|
+
if (!mark)
|
|
74
|
+
return null;
|
|
75
|
+
// 同じリンクが続く区間の先頭を探す(書式が混ざると文字の節は分かれる)
|
|
76
|
+
const parent = $pos.parent;
|
|
77
|
+
let runStart = $pos.start();
|
|
78
|
+
let at = runStart;
|
|
79
|
+
for (let index = 0; index < parent.childCount; index += 1) {
|
|
80
|
+
const child = parent.child(index);
|
|
81
|
+
const end = at + child.nodeSize;
|
|
82
|
+
if (!mark.isInSet(child.marks))
|
|
83
|
+
runStart = end;
|
|
84
|
+
else if (at <= $pos.pos && $pos.pos <= end)
|
|
85
|
+
return { href: mark.attrs.href, from: runStart };
|
|
86
|
+
at = end;
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
function linkOf(marks) {
|
|
91
|
+
return marks?.find((mark) => mark.type === LINK);
|
|
92
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type LinkAtCursor } from '../operations/plugins/linkPopover.js';
|
|
2
|
+
import { type LinkClickSource } from '../operations/plugins/linkClick.js';
|
|
3
|
+
import type { AnchorRect } from '../utils/geometry.types';
|
|
4
|
+
import type { EditorExtension, EditorSession } from './editorSession.types';
|
|
5
|
+
export interface LinkPopoverControllerOptions {
|
|
6
|
+
/** 現在のセッション。生き死にの管理はコンポーネントが持つ */
|
|
7
|
+
readonly getSession: () => EditorSession | null;
|
|
8
|
+
/** リンクが押されたときの受け手。呼ぶ時点の値を読む */
|
|
9
|
+
readonly getLinkClick: LinkClickSource;
|
|
10
|
+
}
|
|
11
|
+
export interface LinkPopoverController {
|
|
12
|
+
/** 基盤へ渡す拡張。セッション生成より前に取得する */
|
|
13
|
+
readonly extension: EditorExtension;
|
|
14
|
+
/**
|
|
15
|
+
* 吹き出しを出しているリンク。出していなければ `null`。
|
|
16
|
+
* 編集基盤が更新するたびに新しい値になる(同じリンクでも、位置は動きうる)
|
|
17
|
+
*/
|
|
18
|
+
readonly link: LinkAtCursor | null;
|
|
19
|
+
/** リンクの先頭の矩形を、いま測る。吹き出しの側と同じ瞬間に測るため、値で持たない */
|
|
20
|
+
measure(): AnchorRect | null;
|
|
21
|
+
/** 吹き出しが押された。利用側へ知らせ、止められなければ新しいタブで開く */
|
|
22
|
+
open(event: MouseEvent): void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* リンクを押したときに出す吹き出しの状態を、エディタ 1 インスタンスに閉じて持つ。
|
|
26
|
+
*
|
|
27
|
+
* **エディタ 1 つにつき 1 つ生成する。** セッションは都度たどるだけで抱え込まない。
|
|
28
|
+
*/
|
|
29
|
+
export declare function createLinkPopoverController(options: LinkPopoverControllerOptions): LinkPopoverController;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { linkPopoverPlugin } from '../operations/plugins/linkPopover.js';
|
|
2
|
+
import { openLink } from '../operations/plugins/linkClick.js';
|
|
3
|
+
/**
|
|
4
|
+
* リンクを押したときに出す吹き出しの状態を、エディタ 1 インスタンスに閉じて持つ。
|
|
5
|
+
*
|
|
6
|
+
* **エディタ 1 つにつき 1 つ生成する。** セッションは都度たどるだけで抱え込まない。
|
|
7
|
+
*/
|
|
8
|
+
export function createLinkPopoverController(options) {
|
|
9
|
+
let link = $state(null);
|
|
10
|
+
const extension = {
|
|
11
|
+
plugins: [
|
|
12
|
+
linkPopoverPlugin((_view, next) => {
|
|
13
|
+
link = next;
|
|
14
|
+
})
|
|
15
|
+
],
|
|
16
|
+
actions: []
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
extension,
|
|
20
|
+
get link() {
|
|
21
|
+
return link;
|
|
22
|
+
},
|
|
23
|
+
measure() {
|
|
24
|
+
const view = options.getSession()?.getView();
|
|
25
|
+
if (!view || !link)
|
|
26
|
+
return null;
|
|
27
|
+
const coords = view.coordsAtPos(link.from);
|
|
28
|
+
return { left: coords.left, right: coords.left, top: coords.top, bottom: coords.bottom };
|
|
29
|
+
},
|
|
30
|
+
open(event) {
|
|
31
|
+
if (link)
|
|
32
|
+
openLink(link.href, event, options.getLinkClick);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
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.27",
|
|
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.",
|