This commit is contained in:
Devon22 2026-06-22 17:46:20 +08:00
parent 8a5950caaf
commit 16212135fb
8 changed files with 72 additions and 42 deletions

View file

@ -1,7 +1,7 @@
{
"id": "mediaviewer",
"name": "Media Viewer",
"version": "2.1.7",
"version": "2.1.8",
"minAppVersion": "1.8.7",
"description": "View and manage media files within your notes.",
"author": "Devon22",

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "mediaviewer",
"version": "2.1.7",
"version": "2.1.8",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "mediaviewer",
"version": "2.1.7",
"version": "2.1.8",
"license": "MIT",
"devDependencies": {
"@types/node": "^16.11.6",

View file

@ -1,6 +1,6 @@
{
"name": "mediaviewer",
"version": "2.1.7",
"version": "2.1.8",
"description": "View and manage media files within your notes.",
"main": "main.js",
"scripts": {

View file

@ -822,6 +822,10 @@ export class FullScreenModal extends Modal {
const media = this.mediaUrls[this.currentIndex];
this.onMediaContextMenu(e, media);
};
this.fullVideo.addEventListener('focus', () => {
this.fullVideo.blur();
});
}
private onMediaContextMenu(event: MouseEvent | { clientX: number, clientY: number }, media: Media) {

View file

@ -844,7 +844,7 @@ export class GalleryBlock {
const addIconText = activeDocument.createElement('div');
addIconText.className = 'mvgb-add-media-text';
addIconText.textContent = t('add_image');
addIconText.textContent = t('add_item');
addIcon.appendChild(addIconText);
addContainer.onclick = () => {
@ -916,7 +916,7 @@ export class GalleryBlock {
if (containerInfo.addButtonEnabled || items.length === 0) {
const addButton = paginationDiv.createEl('button', {
cls: 'mvgb-gallery-control-button mvgb-add-image-button',
text: t('add_image')
text: t('add_item')
});
addButton.onclick = () => {
const modal = new ImageUploadModal(this.app, this.plugin, galleryDiv, sourcePath);
@ -1593,7 +1593,7 @@ export class GalleryBlock {
private addGalleryBlockMenuItems(menu: Menu, galleryDiv: HTMLElement, galleryId: string, sourcePath?: string) {
menu.addItem((item) => {
item
.setTitle(t('add_image'))
.setTitle(t('add_item'))
.setIcon("image")
.onClick(() => {
const modal = new ImageUploadModal(this.app, this.plugin, galleryDiv, sourcePath);

View file

@ -1,4 +1,4 @@
import { App, Modal, Notice, TFile } from 'obsidian';
import { App, Modal, Notice, TFile, FuzzySuggestModal, Setting } from 'obsidian';
import MediaViewPlugin from './main';
import { t } from './translations';
import { captureScrollRestore } from './scrollHelper';
@ -73,36 +73,28 @@ export class ImageUploadModal extends Modal {
void this.handleClipboardPaste();
});
const insertPositionContainer = contentEl.createDiv('mvgb-insert-position-container');
insertPositionContainer.addClass('mvgb-setting-item');
const insertPositionLabel = insertPositionContainer.createDiv('mvgb-setting-label');
insertPositionLabel.setText(t('insert_position'));
const insertPositionControl = insertPositionContainer.createDiv('mvgb-setting-control');
const insertPositionDropdown = insertPositionControl.createEl('select', {
cls: 'mvgb-insert-position-dropdown',
const chooseNoteButton = contentEl.createEl('button', {
text: t('choose_note'),
cls: 'mvgb-paste-button mvgb-choose-note-button',
});
const endOption = insertPositionDropdown.createEl('option', {
text: t('insert_at_end'),
value: 'true',
chooseNoteButton.addEventListener('click', () => {
const noteSuggest = new NoteSuggestModal(this.app, (file) => {
const linkText = this.app.metadataCache.fileToLinktext(file, this.sourcePath ?? '', true);
void this.handleLinks([`[[${linkText}]]`]);
});
noteSuggest.open();
});
const startOption = insertPositionDropdown.createEl('option', {
text: t('insert_at_start'),
value: 'false',
});
if (this.insertAtEnd) {
endOption.selected = true;
} else {
startOption.selected = true;
}
insertPositionDropdown.addEventListener('change', () => {
this.insertAtEnd = insertPositionDropdown.value === 'true';
});
new Setting(contentEl)
.setName(t('insert_position'))
.addDropdown(dropdown => dropdown
.addOption('true', t('insert_at_end'))
.addOption('false', t('insert_at_start'))
.setValue(this.insertAtEnd ? 'true' : 'false')
.onChange(value => {
this.insertAtEnd = value === 'true';
}));
// 拖曳時用左右半區快速決定插入到 gallery 開頭或結尾。
dropZone.addEventListener('dragover', (e: DragEvent) => {
@ -466,3 +458,25 @@ export class ImageUploadModal extends Modal {
});
}
}
export class NoteSuggestModal extends FuzzySuggestModal<TFile> {
onChoose: (file: TFile) => void;
constructor(app: App, onChoose: (file: TFile) => void) {
super(app);
this.onChoose = onChoose;
this.setPlaceholder(t('choose_note_placeholder'));
}
getItems(): TFile[] {
return this.app.vault.getMarkdownFiles();
}
getItemText(file: TFile): string {
return file.path;
}
onChooseItem(file: TFile, evt: MouseEvent | KeyboardEvent): void {
this.onChoose(file);
}
}

View file

@ -33,13 +33,13 @@ const TRANSLATIONS: Translations = {
'file_renamed': '檔案已重新命名',
// 按鈕和標籤
'delete': '除',
'delete': '除',
'confirm': '確認',
'cancel': '取消',
'drag_and_drop': '拖曳圖片到這裡或點擊選擇檔案',
'drag_reorder': '拖曳以重新排序',
'paste_from_clipboard': '從剪貼簿貼上圖片',
'add_image': '新增圖片',
'add_item': '新增項目',
'auto_play': '自動播放',
'stop_auto_play': '停止播放',
'move_left': '向左移動',
@ -48,6 +48,8 @@ const TRANSLATIONS: Translations = {
'new_filename': '新的檔案名稱',
'copy_alt': '複製 alt 內容',
'alt_copied': '已複製 alt 內容',
'choose_note': '選擇筆記',
'choose_note_placeholder': '搜尋筆記名稱...',
// 設定
'allow_media_deletion': '允許刪除媒體檔案',
@ -113,13 +115,13 @@ const TRANSLATIONS: Translations = {
'file_renamed': 'File renamed',
// Buttons and Labels
'delete': 'Delete',
'delete': 'Remove',
'confirm': 'Confirm',
'cancel': 'Cancel',
'drag_and_drop': 'Drag and drop images here or click to select files',
'drag_reorder': 'Drag to reorder',
'paste_from_clipboard': 'Paste image from clipboard',
'add_image': 'Add image',
'add_item': 'Add item',
'auto_play': 'Auto Play',
'stop_auto_play': 'Stop Auto Play',
'move_left': 'Move Left',
@ -128,6 +130,8 @@ const TRANSLATIONS: Translations = {
'new_filename': 'New filename',
'copy_alt': 'Copy alt text',
'alt_copied': 'Alt text copied',
'choose_note': 'Choose Note',
'choose_note_placeholder': 'Search note name...',
// Settings
'allow_media_deletion': 'Allow media deletion',
@ -193,13 +197,13 @@ const TRANSLATIONS: Translations = {
'file_renamed': '文件已重命名',
// 按钮和标签
'delete': '除',
'delete': '除',
'confirm': '确认',
'cancel': '取消',
'drag_and_drop': '拖曳图片到这裡或点击选择图片',
'drag_reorder': '拖拽以重新排序',
'paste_from_clipboard': '从剪贴板粘贴图片',
'add_image': '新增图片',
'add_item': '新增项目',
'auto_play': '自动播放',
'stop_auto_play': '停止播放',
'move_left': '向左移动',
@ -208,6 +212,8 @@ const TRANSLATIONS: Translations = {
'new_filename': '新的文件名',
'copy_alt': '复制 alt 内容',
'alt_copied': '已复制 alt 内容',
'choose_note': '选择笔记',
'choose_note_placeholder': '搜索笔记名称...',
// 设置
'allow_media_deletion': '允许删除媒体文件',
@ -273,19 +279,21 @@ const TRANSLATIONS: Translations = {
'file_renamed': 'ファイル名を変更しました',
// ボタンとラベル
'delete': '削除',
'delete': '取り除く',
'confirm': '確認',
'cancel': 'キャンセル',
'drag_and_drop': '画像をドラッグ&ドロップするか、クリックしてファイルを選択',
'drag_reorder': 'ドラッグして並べ替え',
'paste_from_clipboard': 'クリップボードから画像を貼り付け',
'add_image': '画像を追加',
'add_item': '項目を追加',
'move_left': '左に移動',
'move_right': '右に移動',
'rename': '名前を変更',
'new_filename': '新しいファイル名',
'copy_alt': 'alt テキストをコピー',
'alt_copied': 'alt テキストをコピーしました',
'choose_note': 'ノートを選択',
'choose_note_placeholder': 'ノートの名前を検索...',
// 設定
'allow_media_deletion': 'メディア削除を許可',

View file

@ -809,6 +809,10 @@
transition: background-color 0.2s ease;
}
.mvgb-paste-button.mvgb-choose-note-button {
margin-top: 10px;
}
.mvgb-paste-button:hover {
background-color: var(--interactive-accent-hover);
}