Bläddra i källkod

feat: update build result

zhupei 1 år sedan
förälder
incheckning
a8885b78d4
9 ändrade filer med 20325 tillägg och 11 borttagningar
  1. 0 1
      .gitignore
  2. 6 0
      README.md
  3. 165 0
      demos/docs-ts/dist/index.html
  4. 0 0
      dist/index.cjs
  5. 435 0
      dist/index.d.ts
  6. 19709 0
      dist/index.js
  7. 0 0
      dist/style.css
  8. 1 1
      package.json
  9. 9 9
      src/core/AiEditor.ts

+ 0 - 1
.gitignore

@@ -17,7 +17,6 @@ aimp/
 /docs/.vitepress/dist/
 /demos/vanilla-ts/dist/
 
-dist
 
 # Editor directories and files
 .vscode/*

+ 6 - 0
README.md

@@ -19,6 +19,12 @@
 $ npm install --save git+http://gitlab.smartai.com/zhupei/linwitai-doc.git
 ```
 
+```js
+// 引入
+import linwitDocEditor from 'linwitdoc-editor'
+import 'linwitdoc-editor/dist/index.css'
+```
+
 注意:
 
 1. `aiEditor`换为`linwitDocEditor`

+ 165 - 0
demos/docs-ts/dist/index.html

@@ -0,0 +1,165 @@
+<!doctype html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8"/>
+    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
+    <title>AiEditor Demo</title>
+    <script>
+        var _hmt = _hmt || [];
+        (function () {
+            var hm = document.createElement("script");
+            hm.src = "https://hm.baidu.com/hm.js?9fd447a0f9e62a84d1b752a2cacb2c6b";
+            var s = document.getElementsByTagName("script")[0];
+            s.parentNode.insertBefore(hm, s);
+        })();
+    </script>
+    <style>
+
+        .page-header {
+            background-color: #fff;
+            height: 50px;
+            line-height: 50px;
+            padding: 0 2rem;
+            display: flex;
+            position: sticky;
+            border-bottom: 1px solid #efefef;
+            top: 0;
+            z-index: 1;
+        }
+
+        .aie-header-panel {
+            position: sticky;
+            top: 51px;
+            z-index: 1;
+        }
+
+        .aie-header-panel aie-header > div {
+            align-items: center;
+            justify-content: center;
+            padding: 10px 0;
+        }
+
+        .aie-container {
+            border: none !important;
+        }
+
+        .aie-container-panel {
+            width: calc(100% - 2rem - 2px);
+            max-width: 800px;
+            margin: 1rem auto;
+            border: 1px solid rgb(229 231 235);
+            background-color: #fff;
+            height: 100%;
+            min-height: 100vh;
+            padding: 1rem;
+            z-index: 99;
+        }
+
+        .aie-main {
+            position: relative;
+        }
+
+        .aie-directory {
+            position: absolute;
+            top: 30px;
+            left: 10px;
+            width: 260px;
+            z-index: 0;
+
+        }
+
+        .aie-directory h5 {
+            color: #000000c4;
+            font-size: 16px;
+            text-indent: 4px;
+            line-height: 32px;
+        }
+
+        .aie-directory a {
+            height: 30px;
+            font-size: 14px;
+            color: #000000a3;
+            text-indent: 4px;
+            line-height: 30px;
+            text-decoration: none;
+            width: 100%;
+            display: inline-block;
+            margin: 0;
+            padding: 0;
+            white-space: nowrap;
+            overflow: hidden;
+            -o-text-overflow: ellipsis;
+            text-overflow: ellipsis;
+        }
+
+        .aie-directory a:hover {
+            cursor: pointer;
+            background-color: #334d660f;
+            border-radius: 4px;
+        }
+
+        .aie-title1 {
+            font-size: 14px;
+            font-weight: 500;
+        }
+
+        .aie-title2, .aie-title3, .aie-title4, .aie-title5, .aie-title6 {
+            font-size: 12px;
+        }
+
+        .aie-directory-content {
+            position: sticky;
+            top: 108px;
+        }
+
+        @media screen and (max-width: 1280px) {
+            .aie-directory {
+                display: none;
+            }
+        }
+
+        @media screen and (max-width: 1400px) {
+            .aie-directory {
+                width: 200px;
+            }
+        }
+    </style>
+  <script type="module" crossorigin src="/assets/index-3ee91809.js"></script>
+  <link rel="stylesheet" href="/assets/index-57142b80.css">
+</head>
+<body style="padding: 0;margin: 0;background: #f3f4f6;">
+<div class="page-header">
+    <div><a href="https://aieditor.dev" target="_blank">AiEditor Logo</a></div>
+    <div style="margin-left: auto;display: flex">
+        <a href="https://github.com/aieditor-team/aieditor" target="_blank" style="margin: auto">
+            <svg style="width: 22px;display: block" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
+                <path fill="none" d="M0 0h24v24H0z"></path>
+                <path d="M12.001 2C6.47598 2 2.00098 6.475 2.00098 12C2.00098 16.425 4.86348 20.1625 8.83848 21.4875C9.33848 21.575 9.52598 21.275 9.52598 21.0125C9.52598 20.775 9.51348 19.9875 9.51348 19.15C7.00098 19.6125 6.35098 18.5375 6.15098 17.975C6.03848 17.6875 5.55098 16.8 5.12598 16.5625C4.77598 16.375 4.27598 15.9125 5.11348 15.9C5.90098 15.8875 6.46348 16.625 6.65098 16.925C7.55098 18.4375 8.98848 18.0125 9.56348 17.75C9.65098 17.1 9.91348 16.6625 10.201 16.4125C7.97598 16.1625 5.65098 15.3 5.65098 11.475C5.65098 10.3875 6.03848 9.4875 6.67598 8.7875C6.57598 8.5375 6.22598 7.5125 6.77598 6.1375C6.77598 6.1375 7.61348 5.875 9.52598 7.1625C10.326 6.9375 11.176 6.825 12.026 6.825C12.876 6.825 13.726 6.9375 14.526 7.1625C16.4385 5.8625 17.276 6.1375 17.276 6.1375C17.826 7.5125 17.476 8.5375 17.376 8.7875C18.0135 9.4875 18.401 10.375 18.401 11.475C18.401 15.3125 16.0635 16.1625 13.8385 16.4125C14.201 16.725 14.5135 17.325 14.5135 18.2625C14.5135 19.6 14.501 20.675 14.501 21.0125C14.501 21.275 14.6885 21.5875 15.1885 21.4875C19.259 20.1133 21.9999 16.2963 22.001 12C22.001 6.475 17.526 2 12.001 2Z"></path>
+            </svg>
+        </a>
+    </div>
+</div>
+
+<div id="aiEditor" style="padding: 0;margin: 0">
+    <div class="aie-container" style="background-color: #f3f4f6">
+        <div class="aie-header-panel">
+            <div class="aie-container-header" style="background: #fff;"></div>
+        </div>
+        <div class="aie-main">
+            <div class="aie-directory-content">
+                <div class="aie-directory">
+                    <h5>文档目录</h5>
+                    <div id="outline">
+                    </div>
+                </div>
+            </div>
+            <div class="aie-container-panel">
+                <div class="aie-container-main"></div>
+            </div>
+        </div>
+        <div class="aie-container-footer"></div>
+    </div>
+</div>
+
+</body>
+</html>

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
dist/index.cjs


+ 435 - 0
dist/index.d.ts

@@ -0,0 +1,435 @@
+import { ChainedCommands } from '@tiptap/core/dist/packages/core/src/types';
+import { ChainedCommands as ChainedCommands_2 } from '@tiptap/core';
+import { Editor } from '@tiptap/core';
+import { EditorEvents } from '@tiptap/core';
+import { EditorOptions } from '@tiptap/core';
+import { Extensions } from '@tiptap/core';
+import { Fragment } from 'prosemirror-model';
+import { Instance } from 'tippy.js';
+import { JSONContent } from '@tiptap/core';
+import { SingleCommands } from '@tiptap/core';
+import { Transaction } from '@tiptap/pm/state';
+
+declare class AbstractMenuButton extends HTMLElement implements AiEditorEventListener {
+    template: string;
+    editor?: InnerEditor;
+    options?: AiEditorOptions;
+    alwaysEnabledButtons: string[];
+    protected constructor();
+    protected registerClickListener(): void;
+    connectedCallback(): void;
+    onClick(commands: ChainedCommands): void;
+    onCreate(props: EditorEvents["create"], options: AiEditorOptions): void;
+    onTransaction(event: EditorEvents["transaction"]): void;
+    onActive(editor: Editor): boolean;
+    onEditableChange(editable: boolean): void;
+}
+
+export declare type AIBubbleMenuItem = {
+    prompt: string;
+    icon: string;
+    title: string;
+} | string;
+
+export declare interface AiClient {
+    start: (payload: string) => void;
+    stop: () => void;
+}
+
+export declare interface AiClientListener {
+    onStart: (aiClient: AiClient) => void;
+    onStop: () => void;
+    onMessage: (bodyString: string) => void;
+}
+
+export declare class AiEditor {
+    customLayout: boolean;
+    innerEditor: InnerEditor;
+    container: HTMLDivElement;
+    header: Header;
+    mainEl: HTMLDivElement;
+    footer: Footer;
+    options: AiEditorOptions;
+    eventComponents: AiEditorEventListener[];
+    constructor(_: AiEditorOptions);
+    private initI18nAndInnerEditor;
+    protected initInnerEditor(): void;
+    protected getExtensions(): Extensions;
+    protected onCreate(props: EditorEvents['create']): void;
+    protected onTransaction(transEvent: EditorEvents['transaction']): void;
+    getHtml(): string;
+    getJson(): JSONContent;
+    getText(): string;
+    getSelectedText(): string;
+    getMarkdown(): any;
+    getOptions(): AiEditorOptions;
+    getAttributes(name: string): Record<string, any>;
+    setAttributes(name: string, attributes: Record<string, any>): void;
+    isActive(nameOrAttrs: any, attrs?: {}): boolean;
+    commands(): SingleCommands;
+    commandsChain(): ChainedCommands_2;
+    getOutline(): any[];
+    focus(): this;
+    focusPos(pos: number): this;
+    focusStart(): this;
+    focusEnd(): this;
+    isFocused(): boolean;
+    blur(): this;
+    insert(content: any): this;
+    insertMarkdown(content: string): this;
+    setEditable(editable: boolean): this;
+    setContent(content: string): this;
+    setMarkdownContent(content: string): this;
+    clear(): this;
+    isEmpty(): boolean;
+    changeLang(lang: string): this;
+    changeTheme(theme?: "dark" | "light"): void;
+    removeRetention(): this;
+    destroy(): void;
+    isDestroyed(): boolean;
+}
+
+export declare interface AiEditorEvent {
+    type: string;
+    value: any;
+}
+
+export declare interface AiEditorEventListener {
+    onCreate: (props: EditorEvents['create'], options: AiEditorOptions) => void;
+    onTransaction: (props: EditorEvents['transaction']) => void;
+    onEditableChange: (editable: boolean) => void;
+    onEvent?: (event: AiEditorEvent) => void;
+}
+
+export declare type AiEditorOptions = {
+    element: string | Element;
+    content?: string;
+    contentIsMarkdown?: boolean;
+    contentRetention?: boolean;
+    contentRetentionKey?: string;
+    lang?: string;
+    editable?: boolean;
+    i18n?: Record<string, Record<string, string>>;
+    placeholder?: string;
+    theme?: "light" | "dark";
+    onMentionQuery?: (query: string) => any[] | Promise<any[]>;
+    onCreateBefore?: (editor: AiEditor, extensions: Extensions) => void | Extensions;
+    onCreated?: (editor: AiEditor) => void;
+    onChange?: (editor: AiEditor) => void;
+    onTransaction?: (editor: AiEditor, transaction: Transaction) => void;
+    onFocus?: (editor: AiEditor) => void;
+    onBlur?: (editor: AiEditor) => void;
+    onDestroy?: (editor: AiEditor) => void;
+    onSave?: (editor: AiEditor) => boolean;
+    onFullscreen?: (isFullscreen: boolean) => void;
+    toolbarKeys?: (string | CustomMenu | MenuGroup)[];
+    alwaysEnabledToolbarKeys?: string[];
+    toolbarExcludeKeys?: DefaultToolbarKey[];
+    toolbarSize?: 'small' | 'medium' | 'large';
+    draggable?: boolean;
+    htmlPasteConfig?: HtmlPasteConfig;
+    codeBlock?: {
+        languages?: LanguageItem[];
+        codeExplainPrompt?: string;
+        codeCommentsPrompt?: string;
+    };
+    textSelectionBubbleMenu?: {
+        enable?: boolean;
+        elementTagName?: string;
+        items?: (string | BubbleMenuItem)[];
+    };
+    link?: {
+        autolink?: boolean;
+        rel?: string;
+        class?: string;
+        bubbleMenuItems?: (string | BubbleMenuItem)[];
+    };
+    container?: {
+        defaultType?: string;
+        typeItems?: string[];
+    };
+    uploader?: Uploader;
+    image?: {
+        customMenuInvoke?: (editor: AiEditor) => void;
+        uploadUrl?: string;
+        uploadHeaders?: (() => Record<string, any>) | Record<string, any>;
+        uploadFormName?: string;
+        uploader?: Uploader;
+        uploaderEvent?: UploaderEvent;
+        defaultSize?: number;
+        allowBase64?: boolean;
+        bubbleMenuEnable?: boolean;
+        bubbleMenuItems?: (string | BubbleMenuItem)[];
+    };
+    video?: {
+        customMenuInvoke?: (editor: AiEditor) => void;
+        uploadUrl?: string;
+        uploadHeaders?: (() => Record<string, any>) | Record<string, any>;
+        uploadFormName?: string;
+        uploader?: Uploader;
+        uploaderEvent?: UploaderEvent;
+    };
+    attachment?: {
+        customMenuInvoke?: (editor: AiEditor) => void;
+        uploadUrl?: string;
+        uploadHeaders?: (() => Record<string, any>) | Record<string, any>;
+        uploadFormName?: string;
+        uploader?: Uploader;
+        uploaderEvent?: UploaderEvent;
+    };
+    fontFamily?: {
+        values: NameAndValue[];
+    };
+    fontSize?: {
+        defaultValue?: number;
+        values?: NameAndValue[];
+    };
+    lineHeight?: {
+        values?: string[];
+    };
+    emoji?: {
+        values?: string[];
+    };
+    textCounter?: (text: string) => number;
+    ai?: AiGlobalConfig;
+} & Partial<Omit<EditorOptions, "element">>;
+
+export declare interface AiGlobalConfig {
+    models: Record<string, AiModelConfig>;
+    modelFactory?: AiModelFactory;
+    onTokenConsume?: (modelName: string, modelConfig: AiModelConfig, count: number) => void;
+    onCreateClientUrl?: (modelName: string, modelConfig: AiModelConfig, onSuccess: (url: string) => void, onFailure: () => void) => void;
+    bubblePanelEnable?: boolean;
+    bubblePanelModel?: string;
+    bubblePanelMenus?: AIBubbleMenuItem[];
+    bubblePanelIcon?: string;
+    menus?: AiMenu[];
+    commands?: AiMenu[];
+    translate?: {
+        prompt?: (language: string, selectText: string) => string;
+        translateMenuItems?: TranslateMenuItem[];
+    };
+    codeBlock?: {
+        codeComments?: {
+            model: string;
+            prompt: string;
+        };
+        codeExplain?: {
+            model: string;
+            prompt: string;
+        };
+    };
+}
+
+export declare interface AiMenu {
+    icon: string;
+    name: string;
+    prompt?: string;
+    text?: "selected" | "focusBefore";
+    model?: string;
+    onClick?: (event: MouseEvent, editor: AiEditor) => void;
+    children?: AiMenu[];
+}
+
+export declare interface AiMessage {
+    role: string;
+    content: string;
+    index: number;
+    status: 0 | 1 | 2;
+}
+
+export declare interface AiMessageListener {
+    onStart: (aiClient: AiClient) => void;
+    onStop: () => void;
+    onMessage: (message: AiMessage) => void;
+}
+
+declare abstract class AiModel {
+    editor: InnerEditor;
+    globalConfig: AiGlobalConfig;
+    aiModelName: string;
+    aiModelConfig: AiModelConfig;
+    protected constructor(editor: InnerEditor, globalConfig: AiGlobalConfig, aiModelName: string);
+    chatWithPayload(payload: any, listener: AiMessageListener): void;
+    chat(selectedText: string, prompt: string, listener: AiMessageListener): void;
+    /**
+     * 创建客户端链接 URL
+     */
+    abstract createAiClientUrl(): string;
+    /**
+     * 创建客户端
+     */
+    abstract createAiClient(url: string, listener: AiMessageListener): AiClient;
+    /**
+     * 封装消息,把 prompt 转换为协议需要的格式
+     * @param prompt
+     */
+    abstract wrapPayload(prompt: string): any;
+}
+
+declare interface AiModelConfig {
+    temperature?: number;
+    maxTokens?: number;
+}
+
+export declare interface AiModelFactory {
+    create: (name: string, editor: Editor, globalConfig: AiGlobalConfig) => AiModel;
+}
+
+export declare class AiModelManager {
+    private static models;
+    static init(editor: InnerEditor, globalConfig: AiGlobalConfig): void;
+    static get(modelName: string): AiModel;
+    static set(modelName: string, aiModel: AiModel): void;
+}
+
+export declare type BubbleMenuItem = {
+    id: string;
+    title?: string;
+    icon: string;
+    holder?: any;
+    isActive?: (editor: AiEditor) => boolean;
+    onInit?: (editor: AiEditor, tippyInstance: Instance, parentEle: HTMLElement) => any;
+    onClick?: (editor: AiEditor, tippyInstance: Instance, parentEle: HTMLElement, holder: any) => void;
+};
+
+export declare class CustomAiModel extends AiModel {
+    constructor(editor: InnerEditor, globalConfig: AiGlobalConfig);
+    createAiClient(url: string, listener: AiMessageListener): AiClient;
+    wrapPayload(promptMessage: string): string;
+    createAiClientUrl(): string;
+}
+
+export declare interface CustomAiModelConfig extends AiModelConfig {
+    url: (() => string) | string;
+    method?: string;
+    headers?: () => Record<string, any> | undefined;
+    wrapPayload: (prompt: string) => string;
+    parseMessage: (bodyString: string) => AiMessage | undefined;
+    protocol: "sse" | "websocket" | "http";
+}
+
+export declare interface CustomMenu {
+    id?: string;
+    className?: string;
+    icon?: string;
+    html?: string;
+    tip?: string;
+    onClick?: (event: MouseEvent, editor: AiEditor) => void;
+    onCreate?: (button: HTMLElement, editor: AiEditor) => void;
+}
+
+declare type DefaultToolbarKey = (typeof defaultToolbarKeys)[number];
+
+declare const defaultToolbarKeys: string[];
+
+declare class Footer extends HTMLElement implements AiEditorEventListener {
+    count: number;
+    draggable: boolean;
+    constructor();
+    initDraggable(draggable?: boolean): void;
+    updateCharacters(): void;
+    onCreate(event: EditorEvents["create"], _: AiEditorOptions): void;
+    onTransaction(event: EditorEvents["transaction"]): void;
+    onEditableChange(editable: boolean): void;
+}
+
+declare class Header extends HTMLElement implements AiEditorEventListener {
+    menuButtons: AbstractMenuButton[];
+    constructor();
+    connectedCallback(): void;
+    onCreate(event: EditorEvents["create"], options: AiEditorOptions): void;
+    onTransaction(event: EditorEvents["transaction"]): void;
+    onEditableChange(editable: boolean): void;
+}
+
+export declare interface HtmlPasteConfig {
+    pasteAsText?: boolean;
+    pasteClean?: boolean;
+    removeEmptyParagraphs?: boolean;
+    pasteProcessor?: (html: string) => string;
+}
+
+export declare class InnerEditor extends Editor {
+    linwitDocEditor: AiEditor;
+    constructor(linwitDocEditor: AiEditor, options?: Partial<EditorOptions>);
+    parseHtml(html: string): Fragment;
+    parseMarkdown(markdown: string): Fragment;
+    insertMarkdown(markdown: string): void;
+}
+
+declare type LanguageItem = {
+    name: string;
+    value: string;
+    alias?: string[];
+};
+
+export declare interface MenuGroup {
+    title?: string;
+    icon?: string;
+    toolbarKeys: (string | CustomMenu | MenuGroup)[];
+}
+
+export declare interface NameAndValue {
+    name: string;
+    value: any;
+}
+
+export declare class OpenaiAiModel extends AiModel {
+    constructor(editor: InnerEditor, globalConfig: AiGlobalConfig);
+    createAiClient(url: string, listener: AiMessageListener): AiClient;
+    wrapPayload(prompt: string): string;
+    createAiClientUrl(): string;
+}
+
+export declare interface OpenaiModelConfig extends AiModelConfig {
+    endpoint?: string;
+    customUrl?: string | (() => string);
+    apiKey?: string;
+    model: string;
+}
+
+export declare class SparkAiModel extends AiModel {
+    constructor(editor: InnerEditor, globalConfig: AiGlobalConfig);
+    createAiClient(url: string, listener: AiMessageListener): AiClient;
+    wrapPayload(promptMessage: string): string;
+    getDomain(sparkAiModelConfig: SparkAiModelConfig): "4.0Ultra" | "generalv3.5" | "generalv3" | "generalv2" | "lite" | "general";
+    createAiClientUrl(): string;
+}
+
+export declare interface SparkAiModelConfig extends AiModelConfig {
+    appId: string;
+    apiKey: string;
+    apiSecret: string;
+    protocol?: string;
+    version?: string;
+}
+
+export declare type TranslateMenuItem = {
+    title: string;
+    language?: string;
+} | string;
+
+export declare type Uploader = (file: File, uploadUrl: string, headers: Record<string, any>, formName: string) => Promise<Record<string, any>>;
+
+export declare interface UploaderEvent {
+    onUploadBefore?: (file: File, uploadUrl: string, headers: Record<string, any>) => void | boolean;
+    onSuccess?: (file: File, response: any) => any;
+    onFailed?: (file: File, response: any) => void;
+    onError?: (file: File, err: any) => void;
+}
+
+export declare class WenXinAiModel extends AiModel {
+    constructor(editor: InnerEditor, globalConfig: AiGlobalConfig);
+    createAiClient(url: string, listener: AiMessageListener): AiClient;
+    wrapPayload(prompt: string): string;
+    createAiClientUrl(): string;
+}
+
+export declare interface WenXinAiModelConfig extends AiModelConfig {
+    access_token: string;
+    protocol?: string;
+    version?: string;
+}
+
+export { }

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 19709 - 0
dist/index.js


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 0 - 0
dist/style.css


+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "linwitdoc-editor",
-  "version": "1.5.0",
+  "version": "1.5.1",
   "type": "module",
   "keywords": [
     "editor",

+ 9 - 9
src/core/AiEditor.ts

@@ -18,15 +18,15 @@ import "../styles"
 import i18next from "i18next";
 import {zh} from "../i18n/zh.ts";
 import {en} from "../i18n/en.ts";
-import {de} from "../i18n/de.ts";
-import {pt} from "../i18n/pt.ts";
-import {es} from "../i18n/es.ts";
-import {hi} from "../i18n/hi.ts";
-import {id} from "../i18n/id.ts";
-import {ja} from "../i18n/ja.ts";
-import {ko} from "../i18n/ko.ts";
-import {th} from "../i18n/th.ts";
-import {vi} from "../i18n/vi.ts";
+// import {de} from "../i18n/de.ts";
+// import {pt} from "../i18n/pt.ts";
+// import {es} from "../i18n/es.ts";
+// import {hi} from "../i18n/hi.ts";
+// import {id} from "../i18n/id.ts";
+// import {ja} from "../i18n/ja.ts";
+// import {ko} from "../i18n/ko.ts";
+// import {th} from "../i18n/th.ts";
+// import {vi} from "../i18n/vi.ts";
 import {Resource} from "i18next";
 
 import {DOMParser} from "@tiptap/pm/model";

Vissa filer visades inte eftersom för många filer har ändrats