Merge pull request #75 from TendernessCJS/feat-export-default-configs
feat(AiEditorOptions): excludeKeys API 拓展
This commit is contained in:
commit
01aedc0ebc
|
@ -94,12 +94,14 @@ export type MenuButtonOptions = {
|
|||
svg: string,
|
||||
}
|
||||
|
||||
const defaultMenus = ["undo", "redo", "brush", "eraser", "divider", "heading", "font-family", "font-size", "divider", "bold", "italic", "underline"
|
||||
export const defaultMenus = ["undo", "redo", "brush", "eraser", "divider", "heading", "font-family", "font-size", "divider", "bold", "italic", "underline"
|
||||
, "strike", "link", "code", "subscript", "superscript", "hr", "todo", "emoji", "divider", "highlight", "font-color", "divider"
|
||||
, "align", "line-height", "divider", "bullet-list", "ordered-list", "indent-decrease", "indent-increase", "break", "divider"
|
||||
, "image", "video", "attachment", "quote", "container", "code-block", "table", "divider", "source-code", "printer", "fullscreen", "ai"
|
||||
];
|
||||
] as const;
|
||||
|
||||
export const inbuiltTools = defaultMenus.filter((key) => key !== "divider");
|
||||
export type InbuiltToolKey = (typeof inbuiltTools)[number];
|
||||
|
||||
export class Header extends HTMLElement implements AiEditorEvent {
|
||||
// template:string;
|
||||
|
@ -123,7 +125,20 @@ export class Header extends HTMLElement implements AiEditorEvent {
|
|||
}
|
||||
|
||||
onCreate(event: EditorEvents["create"], options: AiEditorOptions): void {
|
||||
let toolbarKeys = options.toolbarKeys || defaultMenus;
|
||||
let toolbarKeys = options.toolbarKeys || defaultMenus as unknown as string[];
|
||||
toolbarKeys = toolbarKeys.filter((tool) => {
|
||||
if (typeof tool === "string") {
|
||||
return !options.excludeKeys?.includes(tool as any);
|
||||
}
|
||||
return true;
|
||||
}).filter((tool, index, array) => {
|
||||
const prevTool = array[index - 1];
|
||||
if (typeof tool === "string" && (typeof prevTool === "string" || typeof prevTool === "undefined")) {
|
||||
const dividers = ["divider", "|", undefined];
|
||||
return dividers.includes(tool) ? !dividers.includes(prevTool) : true;
|
||||
}
|
||||
return true;
|
||||
})
|
||||
initToolbarKeys(event, options, this.menuButtons, toolbarKeys);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ type Holder = {
|
|||
}
|
||||
|
||||
|
||||
const defaultAiPanelMenus = [
|
||||
export const defaultAiPanelMenus = [
|
||||
{
|
||||
prompt: `<content>{content}</content>\n请帮我优化一下这段内容,并直接返回优化后的结果。\n注意:你应该先判断一下这句话是中文还是英文,如果是中文,请给我返回中文的内容,如果是英文,请给我返回英文内容,只需要返回内容即可,不需要告知我是中文还是英文。`,
|
||||
icon: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M15.1986 9.94447C14.7649 9.5337 14.4859 8.98613 14.4085 8.39384L14.0056 5.31138L11.275 6.79724C10.7503 7.08274 10.1433 7.17888 9.55608 7.06948L6.49998 6.50015L7.06931 9.55625C7.17871 10.1435 7.08257 10.7505 6.79707 11.2751L5.31121 14.0057L8.39367 14.4086C8.98596 14.4861 9.53353 14.7651 9.94431 15.1987L12.0821 17.4557L13.4178 14.6486C13.6745 14.1092 14.109 13.6747 14.6484 13.418L17.4555 12.0823L15.1986 9.94447ZM15.2238 15.5079L13.0111 20.1581C12.8687 20.4573 12.5107 20.5844 12.2115 20.442C12.1448 20.4103 12.0845 20.3665 12.0337 20.3129L8.49229 16.5741C8.39749 16.474 8.27113 16.4096 8.13445 16.3918L3.02816 15.7243C2.69958 15.6814 2.46804 15.3802 2.51099 15.0516C2.52056 14.9784 2.54359 14.9075 2.5789 14.8426L5.04031 10.3192C5.1062 10.1981 5.12839 10.058 5.10314 9.92253L4.16 4.85991C4.09931 4.53414 4.3142 4.22086 4.63997 4.16017C4.7126 4.14664 4.78711 4.14664 4.85974 4.16017L9.92237 5.10331C10.0579 5.12855 10.198 5.10637 10.319 5.04048L14.8424 2.57907C15.1335 2.42068 15.4979 2.52825 15.6562 2.81931C15.6916 2.88421 15.7146 2.95507 15.7241 3.02833L16.3916 8.13462C16.4095 8.2713 16.4739 8.39766 16.5739 8.49245L20.3127 12.0338C20.5533 12.2617 20.5636 12.6415 20.3357 12.8821C20.2849 12.9357 20.2246 12.9795 20.1579 13.0112L15.5078 15.224C15.3833 15.2832 15.283 15.3835 15.2238 15.5079ZM16.0206 17.435L17.4348 16.0208L21.6775 20.2634L20.2633 21.6776L16.0206 17.435Z"></path></svg>`,
|
||||
|
|
|
@ -6,39 +6,45 @@ import {AiMenu} from "../../ai/AiGlobalConfig.ts";
|
|||
import {DefaultAiMessageListener} from "../../ai/core/DefaultAiMessageListener.ts";
|
||||
import {t} from "i18next";
|
||||
|
||||
export const dafaultAiMenus: AiMenu[] = [
|
||||
{
|
||||
icon: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M4 18.9997H20V13.9997H22V19.9997C22 20.552 21.5523 20.9997 21 20.9997H3C2.44772 20.9997 2 20.552 2 19.9997V13.9997H4V18.9997ZM16.1716 6.9997L12.2218 3.04996L13.636 1.63574L20 7.9997L13.636 14.3637L12.2218 12.9495L16.1716 8.9997H5V6.9997H16.1716Z"></path></svg>`,
|
||||
name: `ai-continuation`,
|
||||
prompt: "<content>{content}</content>\n请帮我继续扩展一些这段话的内容。\n注意:你应该先判断一下这句话是中文还是英文,如果是中文,请给我返回中文的内容,如果是英文,请给我返回英文内容,只需要返回内容即可,不需要告知我是中文还是英文。",
|
||||
text: "focusBefore",
|
||||
model: "auto",
|
||||
},
|
||||
{
|
||||
icon: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M15 5.25C16.7949 5.25 18.25 3.79493 18.25 2H19.75C19.75 3.79493 21.2051 5.25 23 5.25V6.75C21.2051 6.75 19.75 8.20507 19.75 10H18.25C18.25 8.20507 16.7949 6.75 15 6.75V5.25ZM4 7C4 5.89543 4.89543 5 6 5H13V3H6C3.79086 3 2 4.79086 2 7V17C2 19.2091 3.79086 21 6 21H18C20.2091 21 22 19.2091 22 17V12H20V17C20 18.1046 19.1046 19 18 19H6C4.89543 19 4 18.1046 4 17V7Z"></path></svg>`,
|
||||
name: `ai-optimization`,
|
||||
prompt: "<content>{content}</content>\n请帮我优化一下这段文字的内容,并返回结果\n注意:你应该先判断一下这句话是中文还是英文,如果是中文,请给我返回中文的内容,如果是英文,请给我返回英文内容,只需要返回内容即可,不需要告知我是中文还是英文。",
|
||||
text: "selected",
|
||||
model: "auto",
|
||||
},
|
||||
{
|
||||
icon: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M17.934 3.0359L19.666 4.0359L18.531 6H21V8H19V12H21V14H19V21H17V14L13.9157 14.0004C13.5914 16.8623 12.3522 19.3936 10.5466 21.1933L8.98361 19.9233C10.5031 18.4847 11.5801 16.4008 11.9008 14.0009L10 14V12L12 11.999V8H10V6H12.467L11.334 4.0359L13.066 3.0359L14.777 6H16.221L17.934 3.0359ZM5 13.803L3 14.339V12.268L5 11.732V8H3V6H5V3H7V6H9V8H7V11.197L9 10.661V12.731L7 13.267V18.5C7 19.8807 5.88071 21 4.5 21H3V19H4.5C4.74546 19 4.94961 18.8231 4.99194 18.5899L5 18.5V13.803ZM17 8H14V12H17V8Z"></path></svg>`,
|
||||
name: `ai-proofreading`,
|
||||
prompt: "<content>{content}</content>\n请帮我找出这段话的错别字,把错别字修改后,并返回结果,不要解释或其他多余的内容\n注意:你应该先判断一下这句话是中文还是英文,如果是中文,请给我返回中文的内容,如果是英文,请给我返回英文内容,只需要返回内容即可,不需要告知我是中文还是英文。",
|
||||
text: "selected",
|
||||
model: "auto",
|
||||
},
|
||||
{
|
||||
icon: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M5 15V17C5 18.0544 5.81588 18.9182 6.85074 18.9945L7 19H10V21H7C4.79086 21 3 19.2091 3 17V15H5ZM18 10L22.4 21H20.245L19.044 18H14.954L13.755 21H11.601L16 10H18ZM17 12.8852L15.753 16H18.245L17 12.8852ZM8 2V4H12V11H8V14H6V11H2V4H6V2H8ZM17 3C19.2091 3 21 4.79086 21 7V9H19V7C19 5.89543 18.1046 5 17 5H14V3H17ZM6 6H4V9H6V6ZM10 6H8V9H10V6Z"></path></svg>`,
|
||||
name: `ai-translation`,
|
||||
prompt: "请帮我翻译以上内容,在翻译之前,想先判断一下这个内容是不是中文,如果是中文,则翻译问英文,如果是其他语言,则需要翻译为中文,注意,你只需要返回翻译的结果,不需要对此进行任何解释,不需要除了翻译结果以外的其他任何内容。",
|
||||
text: "selected",
|
||||
model: "auto",
|
||||
}
|
||||
]
|
||||
|
||||
export class Ai extends AbstractDropdownMenuButton<AiMenu> {
|
||||
|
||||
aiMenus: AiMenu[] = [
|
||||
{
|
||||
icon: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M4 18.9997H20V13.9997H22V19.9997C22 20.552 21.5523 20.9997 21 20.9997H3C2.44772 20.9997 2 20.552 2 19.9997V13.9997H4V18.9997ZM16.1716 6.9997L12.2218 3.04996L13.636 1.63574L20 7.9997L13.636 14.3637L12.2218 12.9495L16.1716 8.9997H5V6.9997H16.1716Z"></path></svg>`,
|
||||
name: `${t('ai-continuation')}`,
|
||||
prompt: "<content>{content}</content>\n请帮我继续扩展一些这段话的内容。\n注意:你应该先判断一下这句话是中文还是英文,如果是中文,请给我返回中文的内容,如果是英文,请给我返回英文内容,只需要返回内容即可,不需要告知我是中文还是英文。",
|
||||
text: "focusBefore",
|
||||
model: "auto",
|
||||
},
|
||||
{
|
||||
icon: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M15 5.25C16.7949 5.25 18.25 3.79493 18.25 2H19.75C19.75 3.79493 21.2051 5.25 23 5.25V6.75C21.2051 6.75 19.75 8.20507 19.75 10H18.25C18.25 8.20507 16.7949 6.75 15 6.75V5.25ZM4 7C4 5.89543 4.89543 5 6 5H13V3H6C3.79086 3 2 4.79086 2 7V17C2 19.2091 3.79086 21 6 21H18C20.2091 21 22 19.2091 22 17V12H20V17C20 18.1046 19.1046 19 18 19H6C4.89543 19 4 18.1046 4 17V7Z"></path></svg>`,
|
||||
name: `${t('ai-optimization')}`,
|
||||
prompt: "<content>{content}</content>\n请帮我优化一下这段文字的内容,并返回结果\n注意:你应该先判断一下这句话是中文还是英文,如果是中文,请给我返回中文的内容,如果是英文,请给我返回英文内容,只需要返回内容即可,不需要告知我是中文还是英文。",
|
||||
text: "selected",
|
||||
model: "auto",
|
||||
},
|
||||
{
|
||||
icon: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M17.934 3.0359L19.666 4.0359L18.531 6H21V8H19V12H21V14H19V21H17V14L13.9157 14.0004C13.5914 16.8623 12.3522 19.3936 10.5466 21.1933L8.98361 19.9233C10.5031 18.4847 11.5801 16.4008 11.9008 14.0009L10 14V12L12 11.999V8H10V6H12.467L11.334 4.0359L13.066 3.0359L14.777 6H16.221L17.934 3.0359ZM5 13.803L3 14.339V12.268L5 11.732V8H3V6H5V3H7V6H9V8H7V11.197L9 10.661V12.731L7 13.267V18.5C7 19.8807 5.88071 21 4.5 21H3V19H4.5C4.74546 19 4.94961 18.8231 4.99194 18.5899L5 18.5V13.803ZM17 8H14V12H17V8Z"></path></svg>`,
|
||||
name: `${t('ai-proofreading')}`,
|
||||
prompt: "<content>{content}</content>\n请帮我找出这段话的错别字,把错别字修改后,并返回结果,不要解释或其他多余的内容\n注意:你应该先判断一下这句话是中文还是英文,如果是中文,请给我返回中文的内容,如果是英文,请给我返回英文内容,只需要返回内容即可,不需要告知我是中文还是英文。",
|
||||
text: "selected",
|
||||
model: "auto",
|
||||
},
|
||||
{
|
||||
icon: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"></path><path d="M5 15V17C5 18.0544 5.81588 18.9182 6.85074 18.9945L7 19H10V21H7C4.79086 21 3 19.2091 3 17V15H5ZM18 10L22.4 21H20.245L19.044 18H14.954L13.755 21H11.601L16 10H18ZM17 12.8852L15.753 16H18.245L17 12.8852ZM8 2V4H12V11H8V14H6V11H2V4H6V2H8ZM17 3C19.2091 3 21 4.79086 21 7V9H19V7C19 5.89543 18.1046 5 17 5H14V3H17ZM6 6H4V9H6V6ZM10 6H8V9H10V6Z"></path></svg>`,
|
||||
name: `${t('ai-translation')}`,
|
||||
prompt: "请帮我翻译以上内容,在翻译之前,想先判断一下这个内容是不是中文,如果是中文,则翻译问英文,如果是其他语言,则需要翻译为中文,注意,你只需要返回翻译的结果,不需要对此进行任何解释,不需要除了翻译结果以外的其他任何内容。",
|
||||
text: "selected",
|
||||
model: "auto",
|
||||
aiMenus = dafaultAiMenus.map((menu) => {
|
||||
return {
|
||||
...menu,
|
||||
name: `${t(menu.name)}`
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
|
|
@ -24,9 +24,14 @@ 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";
|
||||
import {InbuiltToolKey} from "../components/Header.ts";
|
||||
import {LanguageItem} from "../extensions/CodeBlockExt.ts";
|
||||
import {Transaction} from "@tiptap/pm/state";
|
||||
|
||||
export {defaultCommands as defaultAiCommands} from "../extensions/AiCommandExt.ts";
|
||||
export {defaultMenus,inbuiltTools,type InbuiltToolKey} from "../components/Header.ts";
|
||||
export {defaultAiPanelMenus} from "../components/bubbles/items/selection/AI.ts"
|
||||
export {dafaultAiMenus} from "../components/menus/Ai.ts";
|
||||
|
||||
defineCustomElement('aie-header', Header);
|
||||
defineCustomElement('aie-footer', Footer);
|
||||
|
@ -88,6 +93,7 @@ export type AiEditorOptions = {
|
|||
onDestroy?: (editor: AiEditor) => void,
|
||||
onSave?: (editor: AiEditor) => boolean,
|
||||
toolbarKeys?: (string | CustomMenu | MenuGroup)[],
|
||||
excludeKeys?: InbuiltToolKey[],
|
||||
draggable?: boolean,
|
||||
codeBlock?: {
|
||||
languages?: LanguageItem[],
|
||||
|
|
12
src/main.ts
12
src/main.ts
|
@ -1,5 +1,5 @@
|
|||
import {AiEditor} from "./core/AiEditor.ts";
|
||||
import {config} from "./spark.ts";
|
||||
// import {config} from "./spark.ts";
|
||||
// import { config } from "./spark.ts";
|
||||
// import {OpenaiModelConfig} from "./ai/openai/OpenaiModelConfig.ts";
|
||||
// @ts-ignore
|
||||
|
@ -23,8 +23,10 @@ window.aiEditor = new AiEditor({
|
|||
{
|
||||
|
||||
toolbarKeys: ["undo", "redo", "brush", "font-color", "line-height"]
|
||||
}
|
||||
},
|
||||
"ai",
|
||||
],
|
||||
excludeKeys: ["undo", "redo", "brush", "eraser", "heading", "font-family", "font-size"],
|
||||
|
||||
// fontSize:{
|
||||
// defaultValue:18
|
||||
|
@ -60,9 +62,9 @@ window.aiEditor = new AiEditor({
|
|||
// },
|
||||
ai: {
|
||||
models: {
|
||||
spark: {
|
||||
...config
|
||||
},
|
||||
// spark: {
|
||||
// ...config
|
||||
// },
|
||||
// openai: {
|
||||
// endpoint: "https://api.moonshot.cn",
|
||||
// model: "moonshot-v1-8k",
|
||||
|
|
Loading…
Reference in New Issue