Skip to content

Commit

Permalink
feat: make default editor extensible (#4090)
Browse files Browse the repository at this point in the history
#### What type of PR is this?

/area console
/kind feature
/milestone 2.7.x

#### What this PR does / why we need it:

默认编辑器支持扩展,包括输入类型、工具栏、Slash Command 等。

Ref halo-sigs/richtext-editor#16

## 定义方式

```ts
import ExtensionFoo from "./tiptap/extension-foo.ts"

export default definePlugin({
  extensionPoints: {
    "default:editor:extension:create": () => {
      return [ExtensionFoo];
    },
  },
});
```

其中,`ExtensionFoo` 是一个 Tiptap Extension,可以参考 [Tiptap 文档](https://tiptap.dev/) 和 [https://github.com/halo-sigs/richtext-editor/blob/main/docs/extension.md](https://github.com/halo-sigs/richtext-editor/blob/main/docs/extension.md)。

#### Which issue(s) this PR fixes:

Fixes #4028

#### Does this PR introduce a user-facing change?

```release-note
Console 端的默认编辑器支持被扩展
```
  • Loading branch information
ruibaby authored Jun 26, 2023
1 parent 532d7e0 commit c39691d
Show file tree
Hide file tree
Showing 5 changed files with 496 additions and 549 deletions.
19 changes: 19 additions & 0 deletions console/docs/extension-points/default-editor–extension.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 默认编辑器扩展点

该扩展点用于扩展默认编辑器的功能,包括 Tiptap Extension,以及工具栏、悬浮工具栏、Slash Command。

## 定义方式

```ts
import ExtensionFoo from "./tiptap/extension-foo.ts"

export default definePlugin({
extensionPoints: {
"default:editor:extension:create": () => {
return [ExtensionFoo];
},
},
});
```

其中,`ExtensionFoo` 是一个 Tiptap Extension,可以参考 [Tiptap 文档](https://tiptap.dev/)[https://github.com/halo-sigs/richtext-editor/blob/main/docs/extension.md](https://github.com/halo-sigs/richtext-editor/blob/main/docs/extension.md)
3 changes: 2 additions & 1 deletion console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@
"@halo-dev/api-client": "workspace:*",
"@halo-dev/components": "workspace:*",
"@halo-dev/console-shared": "workspace:*",
"@halo-dev/richtext-editor": "0.0.0-alpha.22",
"@halo-dev/richtext-editor": "0.0.0-alpha.23",
"@tanstack/vue-query": "^4.29.1",
"@tiptap/extension-character-count": "^2.0.0-beta.220",
"@tiptap/vue-3": "^2.0.3",
"@uppy/core": "^3.2.0",
"@uppy/dashboard": "^3.4.0",
"@uppy/drag-drop": "^3.0.2",
Expand Down
5 changes: 5 additions & 0 deletions console/packages/shared/src/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { RouteRecordRaw, RouteRecordName } from "vue-router";
import type { FunctionalPage } from "../states/pages";
import type { AttachmentSelectProvider } from "../states/attachment-selector";
import type { EditorProvider } from "..";
import type { AnyExtension } from "@tiptap/vue-3";
import type { CommentSubjectRefProvider } from "@/states/comment-subject-ref";

export interface RouteRecordAppend {
Expand All @@ -20,6 +21,10 @@ export interface ExtensionPoint {

"editor:create"?: () => EditorProvider[] | Promise<EditorProvider[]>;

"default:editor:extension:create": () =>
| AnyExtension[]
| Promise<AnyExtension[]>;

"comment:subject-ref:create"?: () => CommentSubjectRefProvider[];
}

Expand Down
Loading

0 comments on commit c39691d

Please sign in to comment.