feat: add custom bubble menu support

This commit is contained in:
Michael Yang 2024-07-01 09:56:56 +08:00
parent 182e7b4bc3
commit df3f8b0347
2 changed files with 7 additions and 6 deletions

View File

@ -3,7 +3,7 @@ import {Editor, EditorEvents} from "@tiptap/core";
import tippy, {Instance} from "tippy.js";
import {BubbleMenuItem} from "./bubbles/types.ts";
import {MenuRecord} from "./bubbles/items/MenuRecord.ts";
import { t } from "i18next";
import {t} from "i18next";
export abstract class AbstractBubbleMenu extends HTMLElement implements AiEditorEvent {
@ -62,10 +62,10 @@ export abstract class AbstractBubbleMenu extends HTMLElement implements AiEditor
this.tippyInstance = value;
}
protected initItemsByOptions(allMenuItems: MenuRecord, optionItems?: (string)[]) {
protected initItemsByOptions(allMenuItems: MenuRecord, optionItems?: (string | BubbleMenuItem)[]) {
if (optionItems && optionItems.length > 0) {
for (let key of optionItems) {
const linkMenuItem = allMenuItems.getItem(key);
const linkMenuItem = typeof key === "string" ? allMenuItems.getItem(key) : key;
if (linkMenuItem) this.items.push(linkMenuItem);
}
} else {

View File

@ -15,6 +15,7 @@ import {DOMParser} from "@tiptap/pm/model";
import {AiGlobalConfig} from "../ai/AiGlobalConfig.ts";
import {AiModelManager} from "../ai/AiModelManager.ts";
import {defineCustomElement} from "../commons/defineCustomElement.ts";
import {BubbleMenuItem} from "../components/bubbles/types.ts";
defineCustomElement('aie-header', Header);
@ -71,13 +72,13 @@ export type AiEditorOptions = {
textSelectionBubbleMenu?: {
enable?: boolean,
elementTagName?: string,
items?: (string)[],
items?: (string | BubbleMenuItem)[],
},
link?: {
autolink?: boolean,
rel?: string,
class?: string,
bubbleMenuItems?: (string)[],
bubbleMenuItems?: (string | BubbleMenuItem)[],
},
uploader?: (file: File, uploadUrl: string, headers: Record<string, any>, formName: string) => Promise<Record<string, any>>,
image?: {
@ -89,7 +90,7 @@ export type AiEditorOptions = {
uploaderEvent?: UploaderEvent,
defaultSize?: number,
allowBase64?: boolean,
bubbleMenuItems?: (string)[],
bubbleMenuItems?: (string | BubbleMenuItem)[],
},
video?: {
customMenuInvoke?: (editor: AiEditor) => void;