@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
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,73 @@ 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.28] - 2026-11-04
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Selecting text shows a small formatting bar next to the selection with bold,
|
|
13
|
+
italic, strikethrough, inline code and link buttons. It appears above a
|
|
14
|
+
mouse selection and below a touch selection, and `Escape` hides it. Turn it
|
|
15
|
+
off with `selectionToolbar={false}`.
|
|
16
|
+
- A link dialog for adding and editing links, with separate text and URL
|
|
17
|
+
fields, so the link text and its target can differ. Open it from the
|
|
18
|
+
formatting bar, with `Mod-k`, or from the link popover. With nothing
|
|
19
|
+
selected, `Mod-k` inserts a new link at the cursor. A URL without a scheme
|
|
20
|
+
(`example.com`) becomes `https://example.com`.
|
|
21
|
+
- The link popover has **Edit** and **Remove link** buttons.
|
|
22
|
+
- Typing link syntax (`[text](url)`) turns it into a link when you type the
|
|
23
|
+
closing parenthesis.
|
|
24
|
+
- Messages: `selectionToolbarLabel`, `linkAddTitle`, `linkEditTitle`,
|
|
25
|
+
`linkTextLabel`, `linkHrefLabel`, `linkApply`, `linkCancel`, `linkEdit`,
|
|
26
|
+
`linkRemove`. Add them if you pass a full message set for a language that is
|
|
27
|
+
not bundled.
|
|
28
|
+
- Theme tokens: `--markdown-editor-selection-toolbar-*` and
|
|
29
|
+
`--markdown-editor-link-popover-icon`.
|
|
30
|
+
|
|
31
|
+
### Changed
|
|
32
|
+
|
|
33
|
+
- **`@14ch/svelte-ui` (`^0.0.83`) is now a peer dependency.** Dialogs, buttons
|
|
34
|
+
and fields are svelte-ui components. `editor.css` loads only svelte-ui's
|
|
35
|
+
tokens (no fonts, no global element rules).
|
|
36
|
+
- **Removed the `--markdown-editor-dialog-*` tokens.** Dialog colors now follow
|
|
37
|
+
the `--svelte-ui-*` tokens, so they match your app's theme if it uses
|
|
38
|
+
svelte-ui.
|
|
39
|
+
- `Mod-k` opens the link dialog instead of toggling a link. Removing a link is
|
|
40
|
+
done from the dialog or the popover; to link a selected URL, press `Mod-k`
|
|
41
|
+
and then `Enter`. Its description in the shortcut list is now
|
|
42
|
+
"Add or edit link".
|
|
43
|
+
|
|
44
|
+
### Fixed
|
|
45
|
+
|
|
46
|
+
- A `value` set during IME composition is now applied when the composition is
|
|
47
|
+
cancelled, even when the page has `input` listeners (as most Svelte apps do).
|
|
48
|
+
Before, it waited until the next edit, and could be overwritten.
|
|
49
|
+
- Clicking or tapping a link in an unfocused editor now reliably shows the link
|
|
50
|
+
popover.
|
|
51
|
+
|
|
52
|
+
## [0.0.27] - 2026-11-02
|
|
53
|
+
|
|
54
|
+
### Changed
|
|
55
|
+
|
|
56
|
+
- The link popover's frame no longer follows the `--markdown-editor-popup-*`
|
|
57
|
+
tokens. It has its own: `--markdown-editor-link-popover-background`,
|
|
58
|
+
`-border`, `-shadow-strong`, `-shadow` and `-shadow-weak`.
|
|
59
|
+
- Renamed the link bubble's theme tokens added in 0.0.26:
|
|
60
|
+
`--markdown-editor-url-bubble-color` → `--markdown-editor-link-popover-color`
|
|
61
|
+
and `--markdown-editor-url-bubble-hover` → `--markdown-editor-link-popover-hover`.
|
|
62
|
+
Update any overrides that use the old names.
|
|
63
|
+
- The link popover appears only when you click or tap a link. It no longer
|
|
64
|
+
appears when the cursor enters a link by keyboard, and typing or moving the
|
|
65
|
+
cursor with the keyboard hides it.
|
|
66
|
+
- The link popover is placed in the document and scrolls with the text, so it
|
|
67
|
+
stays attached to the link instead of floating over the page.
|
|
68
|
+
|
|
69
|
+
### Fixed
|
|
70
|
+
|
|
71
|
+
- On phones, the link popover no longer appears far above the link when the
|
|
72
|
+
on-screen keyboard is shown.
|
|
73
|
+
- The link popover no longer overflows an editor narrower than the screen.
|
|
74
|
+
|
|
8
75
|
## [0.0.26] - 2026-11-02
|
|
9
76
|
|
|
10
77
|
### Added
|
package/README.ja.md
CHANGED
|
@@ -36,10 +36,10 @@ English: [README.md](README.md)
|
|
|
36
36
|
## 入れる
|
|
37
37
|
|
|
38
38
|
```sh
|
|
39
|
-
npm install @14ch/svelte-md-outliner
|
|
39
|
+
npm install @14ch/svelte-md-outliner @14ch/svelte-ui
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
`svelte@^5` が peer dependency
|
|
42
|
+
`svelte@^5` と `@14ch/svelte-ui` が peer dependency(ダイアログ・ボタン・入力欄は svelte-ui の部品)。スタイルは自分で読み込む(既定のテーマと svelte-ui のトークンは中で読み込まれる。読み込むのはトークンだけで、フォントや要素への規則は含まない)。
|
|
43
43
|
|
|
44
44
|
```ts
|
|
45
45
|
import '@14ch/svelte-md-outliner/styles/editor.css';
|
|
@@ -67,6 +67,7 @@ import '@14ch/svelte-md-outliner/styles/editor.css';
|
|
|
67
67
|
| `messages` | `EditorMessagesOverride` | — | 文字列の差し替え。同梱しない言語は一式を渡す |
|
|
68
68
|
| `shortcutHelp` | `boolean` | `true` | 組み込みのショートカット一覧(`Mod-Alt-/`) |
|
|
69
69
|
| `contextMenu` | `boolean` | `true` | 組み込みのコンテキストメニュー(右クリック / `Mod-/`) |
|
|
70
|
+
| `selectionToolbar` | `boolean` | `true` | 文字を選んだときに、そばに出す書式の帯 |
|
|
70
71
|
| `uploadImage` | `(file: File) => Promise<string \| null>` | — | 貼り付けられた画像を引き受け、表示に使う URL を返す |
|
|
71
72
|
| `onLinkClick` | `(href: string, event: MouseEvent) => void` | — | リンクが押されたときの通知。止めなければ新しいタブで開く |
|
|
72
73
|
|
|
@@ -93,7 +94,8 @@ const uploadImage = async (file: File) => {
|
|
|
93
94
|
|
|
94
95
|
リンク先は新しいタブで開く。
|
|
95
96
|
|
|
96
|
-
-
|
|
97
|
+
- **編集中**は、リンクを押す(タップする)とカーソルが置かれ、リンクの上にリンク先を見せる吹き出しが出る。吹き出しを押すと開く。文字を打つ・キーでカーソルを動かすと消え、キーでリンクに入ったときは出ない。タッチ端末でも「リンクをタップして、吹き出しをタップ」で開ける。⌘+クリック(Mac 以外は Ctrl+クリック)なら吹き出しを経ずに開く
|
|
98
|
+
- **編集中**は、吹き出しに「編集」「リンクを外す」のボタンも並ぶ。`Mod-k` で、選んだ文字へのリンクの追加・カーソルのあるリンクの編集・新しいリンクの挿入のダイアログが開く(リンクの文字と行き先は別々に書ける)。`example.com` のようにスキームの無い行き先は `https://example.com` になる
|
|
97
99
|
- **読み取り専用**では、素のクリックで開く
|
|
98
100
|
|
|
99
101
|
開く前に `onLinkClick` が書かれたとおりの `href` を受け取る(相対のままでも解決しない)。`event.preventDefault()` を呼べば、新しいタブでは開かない。`./other.md` のように、ブラウザで開いても意味を持たない行き先を利用側で扱うときに使う。
|
|
@@ -185,7 +187,7 @@ import './my-theme.css';
|
|
|
185
187
|
}
|
|
186
188
|
```
|
|
187
189
|
|
|
188
|
-
`theme.css` にあるのは色とフォント関連。余白と最大幅は `editor.css`
|
|
190
|
+
`theme.css` にあるのは色とフォント関連。余白と最大幅は `editor.css` 側にあり、上書きの仕方は同じ。ダイアログ・ボタン・入力欄は svelte-ui の部品で、色は `--svelte-ui-*` に従う。アプリが svelte-ui を使っていれば、そのテーマに揃う。
|
|
189
191
|
|
|
190
192
|
## エディタを使わずに読む
|
|
191
193
|
|
package/README.md
CHANGED
|
@@ -36,10 +36,10 @@ Being an outline editor, the heading hierarchy **is** the document structure rat
|
|
|
36
36
|
## Install
|
|
37
37
|
|
|
38
38
|
```sh
|
|
39
|
-
npm install @14ch/svelte-md-outliner
|
|
39
|
+
npm install @14ch/svelte-md-outliner @14ch/svelte-ui
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
`svelte@^5`
|
|
42
|
+
`svelte@^5` and `@14ch/svelte-ui` are peer dependencies (dialogs, buttons and fields are svelte-ui components). Import the stylesheet yourself — it already pulls in the default theme and the svelte-ui tokens (tokens only: no fonts, no global element rules):
|
|
43
43
|
|
|
44
44
|
```ts
|
|
45
45
|
import '@14ch/svelte-md-outliner/styles/editor.css';
|
|
@@ -67,6 +67,7 @@ import '@14ch/svelte-md-outliner/styles/editor.css';
|
|
|
67
67
|
| `messages` | `EditorMessagesOverride` | — | Replace individual strings, or supply a whole language |
|
|
68
68
|
| `shortcutHelp` | `boolean` | `true` | Built-in shortcut sheet (`Mod-Alt-/`) |
|
|
69
69
|
| `contextMenu` | `boolean` | `true` | Built-in context menu (right click / `Mod-/`) |
|
|
70
|
+
| `selectionToolbar` | `boolean` | `true` | Formatting bar shown next to a text selection |
|
|
70
71
|
| `uploadImage` | `(file: File) => Promise<string \| null>` | — | Takes a pasted image, returns the URL to display |
|
|
71
72
|
| `onLinkClick` | `(href: string, event: MouseEvent) => void` | — | Called when a link is clicked; opens in a new tab unless prevented |
|
|
72
73
|
|
|
@@ -93,7 +94,8 @@ While it waits, a marker is shown at the paste position and **the document is no
|
|
|
93
94
|
|
|
94
95
|
Links open in a new tab.
|
|
95
96
|
|
|
96
|
-
- **While editing**, a
|
|
97
|
+
- **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
|
|
98
|
+
- **While editing**, the bubble also has **Edit** and **Remove link** buttons. `Mod-k` opens a dialog to add a link to the selection, edit the link at the cursor, or insert a new one — the link text and the target can differ. A target without a scheme such as `example.com` becomes `https://example.com`
|
|
97
99
|
- **While `readonly`**, a plain click opens the link
|
|
98
100
|
|
|
99
101
|
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.
|
|
@@ -185,7 +187,7 @@ import './my-theme.css';
|
|
|
185
187
|
}
|
|
186
188
|
```
|
|
187
189
|
|
|
188
|
-
`theme.css` holds colors and typography. Spacing and line width live in `editor.css` and override the same way.
|
|
190
|
+
`theme.css` holds colors and typography. Spacing and line width live in `editor.css` and override the same way. Dialogs, buttons and fields are svelte-ui components and follow the `--svelte-ui-*` tokens — if your app already uses svelte-ui, they match its theme.
|
|
189
191
|
|
|
190
192
|
## Reading Markdown without an editor
|
|
191
193
|
|
|
@@ -8,6 +8,13 @@
|
|
|
8
8
|
* クラス名は BEM で書き、他所の CSS と同居しても衝突しにくい接頭辞から始める。
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* ダイアログ・ボタン・入力欄は同梱の svelte-ui の部品を使う。部品が読むトークン
|
|
13
|
+
* (`--svelte-ui-*`)だけを読み込む。フォントの読み込みや要素への規則は含まないので、
|
|
14
|
+
* 置いた先の画面へ持ち込むものは無い。色の差し替えは `--svelte-ui-*` で行う。
|
|
15
|
+
*/
|
|
16
|
+
@import '@14ch/svelte-ui/styles/tokens';
|
|
17
|
+
|
|
11
18
|
/* 既定のテーマ(トークンの値)。利用者は同じ形式のファイルを後から読んで上書きできる */
|
|
12
19
|
@import './theme.css';
|
|
13
20
|
|
|
@@ -95,14 +102,6 @@
|
|
|
95
102
|
* 1 つの値で書くなら、辺ごとのトークンは要らない。
|
|
96
103
|
*/
|
|
97
104
|
--markdown-editor-padding: 1em;
|
|
98
|
-
/**
|
|
99
|
-
* ダイアログの中身の左右の空き。**コンテナではなく中身が持つ。**
|
|
100
|
-
*
|
|
101
|
-
* コンテナ(`.dialog__body`)に持たせると、中身の箱がそのぶん内側へ寄り、
|
|
102
|
-
* **区切りの線が端まで届かない**。中身の側で取れば、線は箱の幅いっぱいに引ける。
|
|
103
|
-
* 値を 1 つにしてあるのは、コンテナの上下の空きと中身の左右の空きを揃えるためである。
|
|
104
|
-
*/
|
|
105
|
-
--markdown-editor-dialog-inset: 24px;
|
|
106
105
|
/**
|
|
107
106
|
* 最大幅(行の長さの上限)。**既定は箱いっぱい**で、狭めたい置き先が値を入れる。
|
|
108
107
|
*
|
|
@@ -383,8 +383,26 @@
|
|
|
383
383
|
--markdown-editor-popup-shadow-weak: var(--markdown-editor-shadow-weak);
|
|
384
384
|
|
|
385
385
|
/* カーソルがリンクにあるあいだ出す吹き出し */
|
|
386
|
-
--markdown-editor-
|
|
387
|
-
--markdown-editor-
|
|
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
|
+
/* 吹き出しのアイコンだけのボタン(編集・リンクを外す) */
|
|
394
|
+
--markdown-editor-link-popover-icon: var(--markdown-editor-text-subtle);
|
|
395
|
+
|
|
396
|
+
/* 文字を選んだときに出す帯(選択ツールバー) */
|
|
397
|
+
--markdown-editor-selection-toolbar-background: var(--markdown-editor-surface-elevated);
|
|
398
|
+
--markdown-editor-selection-toolbar-border: var(--markdown-editor-border-weak);
|
|
399
|
+
--markdown-editor-selection-toolbar-shadow-strong: var(--markdown-editor-shadow-strong);
|
|
400
|
+
--markdown-editor-selection-toolbar-shadow: var(--markdown-editor-shadow);
|
|
401
|
+
--markdown-editor-selection-toolbar-shadow-weak: var(--markdown-editor-shadow-weak);
|
|
402
|
+
--markdown-editor-selection-toolbar-icon: var(--markdown-editor-text);
|
|
403
|
+
--markdown-editor-selection-toolbar-hover: var(--markdown-editor-hover-overlay);
|
|
404
|
+
/* 選んだ範囲にその書式が付いているボタンのアイコン */
|
|
405
|
+
--markdown-editor-selection-toolbar-active: var(--markdown-editor-accent);
|
|
388
406
|
|
|
389
407
|
/* コンテキストメニュー */
|
|
390
408
|
--markdown-editor-menu-separator: var(--markdown-editor-border);
|
|
@@ -396,19 +414,6 @@
|
|
|
396
414
|
/* メニューが対象にしているブロックへ敷く印(編集エリアの側に出る) */
|
|
397
415
|
--markdown-editor-menu-target-fill: var(--markdown-editor-target-fill);
|
|
398
416
|
|
|
399
|
-
/* ダイアログ */
|
|
400
|
-
--markdown-editor-dialog-background: var(--markdown-editor-surface-elevated);
|
|
401
|
-
--markdown-editor-dialog-backdrop: var(--markdown-editor-scrim);
|
|
402
|
-
--markdown-editor-dialog-text: var(--markdown-editor-text);
|
|
403
|
-
--markdown-editor-dialog-border: var(--markdown-editor-border);
|
|
404
|
-
--markdown-editor-dialog-title-color: var(--markdown-editor-text);
|
|
405
|
-
/* 見出しと脚を本文から分ける線(巻き取るときだけ出る) */
|
|
406
|
-
--markdown-editor-dialog-divider: var(--markdown-editor-border);
|
|
407
|
-
/* 浮き上がりの影。メニューとは別の部品なので別に持つ(同じ濃さなのは結果) */
|
|
408
|
-
--markdown-editor-dialog-shadow-strong: var(--markdown-editor-shadow-strong);
|
|
409
|
-
--markdown-editor-dialog-shadow: var(--markdown-editor-shadow);
|
|
410
|
-
--markdown-editor-dialog-shadow-weak: var(--markdown-editor-shadow-weak);
|
|
411
|
-
|
|
412
417
|
/* ショートカット一覧 */
|
|
413
418
|
--markdown-editor-shortcut-group-title-color: var(--markdown-editor-text-subtle);
|
|
414
419
|
--markdown-editor-shortcut-keys-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
|
|
15
|
+
import Popup from './internal/Popup.svelte';
|
|
16
16
|
|
|
17
17
|
interface Props {
|
|
18
18
|
controller: ContextMenuController;
|
|
@@ -84,8 +84,8 @@
|
|
|
84
84
|
/**
|
|
85
85
|
* 選んでいる項目へ実フォーカスを移す。
|
|
86
86
|
*
|
|
87
|
-
* 何も選んでいないあいだはコンテナにフォーカスが載ったままで、`
|
|
88
|
-
* そこへ移している。移し先がコンテナの中なら閉じない(`
|
|
87
|
+
* 何も選んでいないあいだはコンテナにフォーカスが載ったままで、`Popup` が開くときに
|
|
88
|
+
* そこへ移している。移し先がコンテナの中なら閉じない(`Popup` の `onFocusOut` が
|
|
89
89
|
* 移り先を見ている)。
|
|
90
90
|
*/
|
|
91
91
|
function focusActive(): void {
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
});
|
|
116
116
|
</script>
|
|
117
117
|
|
|
118
|
-
<
|
|
118
|
+
<Popup
|
|
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
|
-
</
|
|
170
|
+
</Popup>
|
|
171
171
|
|
|
172
172
|
<style>
|
|
173
173
|
/**
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
リンクのダイアログ。選んだ範囲へリンクを付ける・カーソルの位置へ挿入する(追加)と、
|
|
3
|
+
既存のリンクを直す・外す(編集)を受け持つ。
|
|
4
|
+
|
|
5
|
+
`Enter` はフォームの送信として受ける(キーを判定しない)。`Escape`・背景・キャンセルは
|
|
6
|
+
ダイアログの既定の閉じ方に任せる。どの経路で閉じても、閉じ終えたらコントローラへ知らせる。
|
|
7
|
+
適用で対象を手放した・外から文書が変わって対象が古くなったときは、`request` が消えるので
|
|
8
|
+
自分から閉じる。
|
|
9
|
+
|
|
10
|
+
URL の欄は `type="url"` にしない。スキームの無い入力(`example.com`)を実行環境が弾き、
|
|
11
|
+
`https://` を補う規則(→ `normalizeLinkHref`)まで届かないためである。
|
|
12
|
+
-->
|
|
13
|
+
<script lang="ts">
|
|
14
|
+
import { Button, Dialog, Input } from '@14ch/svelte-ui';
|
|
15
|
+
import type { EditorMessages } from '../messages/messages.types';
|
|
16
|
+
import type { LinkTarget } from '../operations/operations.types';
|
|
17
|
+
import type {
|
|
18
|
+
LinkDialogController,
|
|
19
|
+
LinkDialogRequest
|
|
20
|
+
} from '../states/linkDialogController.svelte';
|
|
21
|
+
import { normalizeLinkHref } from '../utils/linkHref.js';
|
|
22
|
+
|
|
23
|
+
interface Props {
|
|
24
|
+
request: LinkDialogRequest | null;
|
|
25
|
+
controller: LinkDialogController;
|
|
26
|
+
text: EditorMessages;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let { request, controller, text }: Props = $props();
|
|
30
|
+
|
|
31
|
+
const id = $props.id();
|
|
32
|
+
|
|
33
|
+
/** 出している対象。閉じる動きのあいだも見出しとボタンを保つため、`request` が消えても残す */
|
|
34
|
+
let shown = $state<LinkTarget | null>(null);
|
|
35
|
+
let textValue = $state('');
|
|
36
|
+
let hrefValue = $state('');
|
|
37
|
+
|
|
38
|
+
let dialog: Dialog | undefined = $state();
|
|
39
|
+
let textRef: Input | undefined = $state();
|
|
40
|
+
let hrefRef: Input | undefined = $state();
|
|
41
|
+
|
|
42
|
+
const applicable = $derived(normalizeLinkHref(hrefValue) !== null);
|
|
43
|
+
|
|
44
|
+
function submit(event: SubmitEvent): void {
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
controller.submit({ text: textValue, href: hrefValue });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 開いた直後の欄へ焦点を移す。ダイアログは開くと自分自身へ焦点を移すので、その後に呼ぶ。
|
|
51
|
+
* 何も選ばずに開いたら、まず文字を打つ
|
|
52
|
+
*/
|
|
53
|
+
function focusInitial(): void {
|
|
54
|
+
(shown?.kind === 'add' && !shown.text ? textRef : hrefRef)?.focus();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
$effect(() => {
|
|
58
|
+
const target = request?.target;
|
|
59
|
+
if (!target) {
|
|
60
|
+
dialog?.close();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
shown = target;
|
|
65
|
+
textValue = target.kind === 'add' ? target.text : target.run.text;
|
|
66
|
+
hrefValue = target.kind === 'add' ? target.href : target.run.href;
|
|
67
|
+
dialog?.open();
|
|
68
|
+
});
|
|
69
|
+
</script>
|
|
70
|
+
|
|
71
|
+
<Dialog
|
|
72
|
+
bind:this={dialog}
|
|
73
|
+
title={shown?.kind === 'edit' ? text.linkEditTitle : text.linkAddTitle}
|
|
74
|
+
width="min(28em, 90vw)"
|
|
75
|
+
onOpen={focusInitial}
|
|
76
|
+
onClose={() => controller.closed()}
|
|
77
|
+
>
|
|
78
|
+
<!-- 適用は脚にあるので、フォームの外から `form` で結ぶ。欄の中の `Enter` もこのボタンの送信になる -->
|
|
79
|
+
<form id="{id}-form" class="markdown-editor-link-dialog__fields" onsubmit={submit}>
|
|
80
|
+
<label class="markdown-editor-link-dialog__label" for="{id}-text">{text.linkTextLabel}</label>
|
|
81
|
+
<Input
|
|
82
|
+
bind:this={textRef}
|
|
83
|
+
bind:value={textValue}
|
|
84
|
+
id="{id}-text"
|
|
85
|
+
fullWidth
|
|
86
|
+
enterkeyhint="next"
|
|
87
|
+
/>
|
|
88
|
+
<label class="markdown-editor-link-dialog__label" for="{id}-href">{text.linkHrefLabel}</label>
|
|
89
|
+
<Input
|
|
90
|
+
bind:this={hrefRef}
|
|
91
|
+
bind:value={hrefValue}
|
|
92
|
+
id="{id}-href"
|
|
93
|
+
fullWidth
|
|
94
|
+
inputmode="url"
|
|
95
|
+
autocapitalize="off"
|
|
96
|
+
autocomplete="off"
|
|
97
|
+
spellcheck={false}
|
|
98
|
+
enterkeyhint="done"
|
|
99
|
+
/>
|
|
100
|
+
</form>
|
|
101
|
+
|
|
102
|
+
{#snippet footer()}
|
|
103
|
+
{#if shown?.kind === 'edit'}
|
|
104
|
+
<!-- 取り返しのつかない操作なので、キャンセル・適用から離して左端に置く -->
|
|
105
|
+
<Button color="var(--svelte-ui-danger-color)" onclick={controller.remove}>
|
|
106
|
+
{text.linkRemove}
|
|
107
|
+
</Button>
|
|
108
|
+
<span class="markdown-editor-link-dialog__spacer"></span>
|
|
109
|
+
{/if}
|
|
110
|
+
<Button onclick={() => dialog?.close()}>{text.linkCancel}</Button>
|
|
111
|
+
<Button type="submit" form="{id}-form" variant="filled" disabled={!applicable}>
|
|
112
|
+
{text.linkApply}
|
|
113
|
+
</Button>
|
|
114
|
+
{/snippet}
|
|
115
|
+
</Dialog>
|
|
116
|
+
|
|
117
|
+
<style>
|
|
118
|
+
/**
|
|
119
|
+
* 名前の列は 2 行で揃える。列の幅は長いほうの名前で決まる(言語で長さが変わるため、
|
|
120
|
+
* 幅を値で決めない)
|
|
121
|
+
*/
|
|
122
|
+
.markdown-editor-link-dialog__fields {
|
|
123
|
+
display: grid;
|
|
124
|
+
grid-template-columns: auto minmax(0, 1fr);
|
|
125
|
+
gap: 16px 8px;
|
|
126
|
+
align-items: center;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.markdown-editor-link-dialog__label {
|
|
130
|
+
white-space: nowrap;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.markdown-editor-link-dialog__spacer {
|
|
134
|
+
flex: 1;
|
|
135
|
+
}
|
|
136
|
+
</style>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { EditorMessages } from '../messages/messages.types';
|
|
2
|
+
import type { LinkDialogController, LinkDialogRequest } from '../states/linkDialogController.svelte';
|
|
3
|
+
interface Props {
|
|
4
|
+
request: LinkDialogRequest | null;
|
|
5
|
+
controller: LinkDialogController;
|
|
6
|
+
text: EditorMessages;
|
|
7
|
+
}
|
|
8
|
+
declare const LinkDialog: import("svelte").Component<Props, {}, "">;
|
|
9
|
+
type LinkDialog = ReturnType<typeof LinkDialog>;
|
|
10
|
+
export default LinkDialog;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
リンクを押して(タップして)カーソルを入れたときに出す吹き出し。リンク先を見せ、押すとそこを開く。
|
|
3
|
+
右に、リンクを直す「編集」と「リンクを外す」をアイコンだけで並べる。
|
|
4
|
+
|
|
5
|
+
本文の中に浮かせる(→ `AnchoredLayer`)。リンクの先頭に左端をそろえ、上に出す。
|
|
6
|
+
タッチ端末では画面の下半分をキーボードが覆う。上に収まらないときだけ下へ返る。
|
|
7
|
+
|
|
8
|
+
**焦点を奪わない。** 焦点が編集エリアを離れると吹き出しは消えるので、奪うと押す前に
|
|
9
|
+
消える。タッチ端末ではキーボードも引っ込む。押しても焦点が動かないよう、`mousedown` を止める。
|
|
10
|
+
-->
|
|
11
|
+
<script lang="ts">
|
|
12
|
+
import type { EditorMessages } from '../messages/messages.types';
|
|
13
|
+
import type { LinkPopoverController } from '../states/linkPopoverController.svelte';
|
|
14
|
+
import AnchoredLayer from './internal/AnchoredLayer.svelte';
|
|
15
|
+
import Icon from './internal/Icon.svelte';
|
|
16
|
+
|
|
17
|
+
interface Props {
|
|
18
|
+
controller: LinkPopoverController;
|
|
19
|
+
text: EditorMessages;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let { controller, text }: Props = $props();
|
|
23
|
+
|
|
24
|
+
function keepFocus(event: MouseEvent): void {
|
|
25
|
+
event.preventDefault();
|
|
26
|
+
}
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<AnchoredLayer anchor={controller.link} measure={controller.measure} side="above">
|
|
30
|
+
{#snippet children(attach)}
|
|
31
|
+
<!-- 押しても焦点を移さないための受け止め。キーで届く操作はボタンが持つ -->
|
|
32
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
33
|
+
<div class="markdown-editor-link-popover" {@attach attach} onmousedown={keepFocus}>
|
|
34
|
+
<!-- リンク先の表示ごと 1 つのボタンにする。押せる面が広いほどタッチ端末で押しやすい -->
|
|
35
|
+
<button
|
|
36
|
+
type="button"
|
|
37
|
+
class="markdown-editor-link-popover__open"
|
|
38
|
+
aria-label="{text.linkOpen}: {controller.link?.href}"
|
|
39
|
+
title={controller.link?.href}
|
|
40
|
+
onclick={controller.open}
|
|
41
|
+
>
|
|
42
|
+
<!-- 新しいタブで開くことの印。吹き出しはリンクの先頭にそろうので、左に置けば押す目当てが近い -->
|
|
43
|
+
<Icon name="open_in_new" />
|
|
44
|
+
<span class="markdown-editor-link-popover__target">{controller.link?.href}</span>
|
|
45
|
+
</button>
|
|
46
|
+
<button
|
|
47
|
+
type="button"
|
|
48
|
+
class="markdown-editor-link-popover__action"
|
|
49
|
+
aria-label={text.linkEdit}
|
|
50
|
+
title={text.linkEdit}
|
|
51
|
+
onclick={controller.edit}
|
|
52
|
+
>
|
|
53
|
+
<Icon name="edit" />
|
|
54
|
+
</button>
|
|
55
|
+
<button
|
|
56
|
+
type="button"
|
|
57
|
+
class="markdown-editor-link-popover__action"
|
|
58
|
+
aria-label={text.linkRemove}
|
|
59
|
+
title={text.linkRemove}
|
|
60
|
+
onclick={controller.remove}
|
|
61
|
+
>
|
|
62
|
+
<Icon name="link_off" />
|
|
63
|
+
</button>
|
|
64
|
+
</div>
|
|
65
|
+
{/snippet}
|
|
66
|
+
</AnchoredLayer>
|
|
67
|
+
|
|
68
|
+
<style>
|
|
69
|
+
/**
|
|
70
|
+
* 位置は `AnchoredLayer` が決める。
|
|
71
|
+
*
|
|
72
|
+
* 幅の上限は**エディタの幅**で抑える(層はエディタと同じ幅)。表示領域の幅で抑えると、
|
|
73
|
+
* エディタが画面より狭いとき(スマートフォンで左右に余白がある置き方)にはみ出す。
|
|
74
|
+
*/
|
|
75
|
+
.markdown-editor-link-popover {
|
|
76
|
+
position: absolute;
|
|
77
|
+
display: flex;
|
|
78
|
+
box-sizing: border-box;
|
|
79
|
+
max-width: min(360px, 100%);
|
|
80
|
+
border: 1px solid var(--markdown-editor-link-popover-border);
|
|
81
|
+
border-radius: var(--markdown-editor-radius);
|
|
82
|
+
background: var(--markdown-editor-link-popover-background);
|
|
83
|
+
box-shadow:
|
|
84
|
+
0 11px 15px -7px var(--markdown-editor-link-popover-shadow-strong),
|
|
85
|
+
0 24px 38px 3px var(--markdown-editor-link-popover-shadow),
|
|
86
|
+
0 9px 46px 8px var(--markdown-editor-link-popover-shadow-weak);
|
|
87
|
+
overflow: hidden;
|
|
88
|
+
animation: markdown-editor-link-popover-in 120ms forwards;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@keyframes markdown-editor-link-popover-in {
|
|
92
|
+
from {
|
|
93
|
+
opacity: 0;
|
|
94
|
+
}
|
|
95
|
+
to {
|
|
96
|
+
opacity: 1;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@media (prefers-reduced-motion: reduce) {
|
|
101
|
+
.markdown-editor-link-popover {
|
|
102
|
+
animation-duration: 0.01s;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** 行間は本文のものを引き継がない(地の文ではない) */
|
|
107
|
+
.markdown-editor-link-popover__open {
|
|
108
|
+
box-sizing: border-box;
|
|
109
|
+
display: flex;
|
|
110
|
+
flex: 1;
|
|
111
|
+
align-items: center;
|
|
112
|
+
gap: 6px;
|
|
113
|
+
min-width: 0;
|
|
114
|
+
padding: 8px 12px;
|
|
115
|
+
border: 0;
|
|
116
|
+
background: none;
|
|
117
|
+
color: var(--markdown-editor-link-popover-color);
|
|
118
|
+
font: inherit;
|
|
119
|
+
font-size: var(--markdown-editor-font-size-sm);
|
|
120
|
+
line-height: normal;
|
|
121
|
+
text-align: left;
|
|
122
|
+
white-space: nowrap;
|
|
123
|
+
cursor: pointer;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.markdown-editor-link-popover__target {
|
|
127
|
+
min-width: 0;
|
|
128
|
+
overflow: hidden;
|
|
129
|
+
text-overflow: ellipsis;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.markdown-editor-link-popover__action {
|
|
133
|
+
display: flex;
|
|
134
|
+
flex: none;
|
|
135
|
+
align-items: center;
|
|
136
|
+
justify-content: center;
|
|
137
|
+
width: 36px;
|
|
138
|
+
padding: 0;
|
|
139
|
+
border: 0;
|
|
140
|
+
background: none;
|
|
141
|
+
color: var(--markdown-editor-link-popover-icon);
|
|
142
|
+
font: inherit;
|
|
143
|
+
cursor: pointer;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/* 触れる入力しかない環境では `:hover` が居座るため、囲って外す */
|
|
147
|
+
@media (hover: hover) {
|
|
148
|
+
.markdown-editor-link-popover__open:hover,
|
|
149
|
+
.markdown-editor-link-popover__action:hover {
|
|
150
|
+
background: var(--markdown-editor-link-popover-hover);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/* 触れる端末でのターゲットの大きさ */
|
|
155
|
+
@media (max-width: 768px) {
|
|
156
|
+
.markdown-editor-link-popover__open {
|
|
157
|
+
min-height: var(--markdown-editor-touch-target);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.markdown-editor-link-popover__action {
|
|
161
|
+
width: var(--markdown-editor-touch-target);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
</style>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { EditorMessages } from '../messages/messages.types';
|
|
2
|
+
import type { LinkPopoverController } from '../states/linkPopoverController.svelte';
|
|
3
|
+
interface Props {
|
|
4
|
+
controller: LinkPopoverController;
|
|
5
|
+
text: EditorMessages;
|
|
6
|
+
}
|
|
7
|
+
declare const LinkPopover: import("svelte").Component<Props, {}, "">;
|
|
8
|
+
type LinkPopover = ReturnType<typeof LinkPopover>;
|
|
9
|
+
export default LinkPopover;
|