添加插入视频菜单

This commit is contained in:
wux_labs
2025-02-18 13:12:00 +08:00
parent 6a49ef311a
commit 6ab33e2060
8 changed files with 232 additions and 0 deletions
+6
View File
@@ -48,6 +48,7 @@ import { Print } from "./base/Print.ts";
import { Link } from "./insert/Link.ts";
import { Image } from "./insert/Image.ts";
import { Video } from "./insert/Video.ts";
/**
* 传统菜单栏
@@ -107,6 +108,7 @@ export class Classic extends HTMLElement implements UAIEditorEventListener {
// 插入菜单
insertMenuLink!: Link;
insertMenuImage!: Image;
insertMenuVideo!: Video;
constructor(defaultToolbarMenus: Record<string, any>[]) {
super();
@@ -282,6 +284,9 @@ export class Classic extends HTMLElement implements UAIEditorEventListener {
this.insertMenuImage = new Image({ menuType: "button", enable: true, header: "classic", hideText: false });
this.eventComponents.push(this.insertMenuImage);
this.insertMenuVideo = new Video({ menuType: "button", enable: true, header: "classic", hideText: false });
this.eventComponents.push(this.insertMenuVideo);
}
/**
* 创建基础菜单
@@ -361,5 +366,6 @@ export class Classic extends HTMLElement implements UAIEditorEventListener {
this.classicMenuInsertGroup.appendChild(group1);
group1.appendChild(this.insertMenuLink);
group1.appendChild(this.insertMenuImage);
group1.appendChild(this.insertMenuVideo);
}
}
+6
View File
@@ -50,6 +50,7 @@ import { Print } from "./base/Print.ts";
import { Link } from "./insert/Link.ts";
import { Image } from "./insert/Image.ts";
import { Video } from "./insert/Video.ts";
/**
* 经典菜单栏
@@ -110,6 +111,7 @@ export class Ribbon extends HTMLElement implements UAIEditorEventListener {
// 插入菜单
insertMenuLink!: Link;
insertMenuImage!: Image;
insertMenuVideo!: Video;
constructor(defaultToolbarMenus: Record<string, any>[]) {
super();
@@ -305,6 +307,9 @@ export class Ribbon extends HTMLElement implements UAIEditorEventListener {
this.insertMenuImage = new Image({ menuType: "button", enable: true, huge: true });
this.eventComponents.push(this.insertMenuImage);
this.insertMenuVideo = new Video({ menuType: "button", enable: true, huge: true });
this.eventComponents.push(this.insertMenuVideo);
}
/**
@@ -458,5 +463,6 @@ export class Ribbon extends HTMLElement implements UAIEditorEventListener {
this.ribbonMenuInsertGroup.appendChild(group1);
group1.appendChild(this.insertMenuLink);
group1.appendChild(this.insertMenuImage);
group1.appendChild(this.insertMenuVideo);
}
}
@@ -0,0 +1,72 @@
// Copyright (c) 2024-present AI-Labs
// @ ts-nocheck
import { MenuButton, MenuButtonOptions } from "../../MenuButton.ts";
import icon from "../../../../assets/icons/video.svg";
import { t } from "i18next";
import { UAIEditorEventListener, UAIEditorOptions } from "../../../../core/UAIEditor.ts";
import { EditorEvents } from "@tiptap/core";
/**
* 插入菜单:插入视频
*/
export class Video extends HTMLElement implements UAIEditorEventListener {
// 按钮选项
menuButtonOptions: MenuButtonOptions = {
menuType: "button",
enable: true,
icon: icon,
hideText: false,
text: t('insert.video'),
tooltip: t('insert.video'),
}
// 功能按钮
menuButton: MenuButton;
constructor(options: MenuButtonOptions) {
super();
// 初始化功能按钮选项
this.menuButtonOptions = { ...this.menuButtonOptions, ...options };
// 创建功能按钮
this.menuButton = new MenuButton(this.menuButtonOptions);
}
/**
* 定义创建方法
* @param event
* @param options
*/
onCreate(event: EditorEvents["create"], options: UAIEditorOptions) {
this.menuButton.onCreate(event, options);
this.appendChild(this.menuButton);
// 定义按钮点击事件,插入视频
this.addEventListener("click", () => {
if (this.menuButtonOptions.enable) {
event.editor.chain().focus().selectFiles('video', true).run()
}
})
}
/**
* 定义Transaction监听方法
* @param event
* @param options
*/
onTransaction(event: EditorEvents["transaction"], options: UAIEditorOptions) {
this.menuButton.onTransaction(event, options);
if (this.menuButton.menuButton) {
var disable = event.editor.isEditable;
this.onEditableChange(disable);
}
}
onEditableChange(editable: boolean) {
this.menuButtonOptions.enable = editable;
this.menuButton.onEditableChange(editable);
}
}