@norio-office/rich-text 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1147 -971
- package/dist/{chunk-efA98nb6.js → chunk-C_CI6nMA.js} +1 -1
- package/dist/components/OutlinePanel.vue.d.ts +22 -11
- package/dist/components/RichTextEditor.vue.d.ts +25 -1
- package/dist/components/RichTextOutline.vue.d.ts +30 -0
- package/dist/composables/useRichTextEditor.d.ts +7 -2
- package/dist/extensions/image-block.d.ts +7 -1
- package/dist/extensions/video-block.d.ts +7 -1
- package/dist/{html2canvas-Bwmq6fGh.js → html2canvas-CmV4ppBE.js} +2 -2
- package/dist/index.d.ts +3 -2
- package/dist/{index.es-C4X5YiRo.js → index.es-D5dDjrL4.js} +1 -1
- package/dist/index.js +5513 -4766
- package/dist/index.umd.cjs +871 -589
- package/dist/{jspdf.es.min-ByaXFVjc.js → jspdf.es.min-B2a2-__Q.js} +17 -17
- package/dist/purify.es-jA1o6Tcu.js +597 -0
- package/dist/style.css +1 -1
- package/dist/types.d.ts +58 -24
- package/dist/utils/url.d.ts +2 -0
- package/docs/usage.md +66 -95
- package/package.json +2 -8
- package/dist/purify.es-B5ixYH9L.js +0 -549
- package/yjs/README.md +0 -63
- package/yjs/index.js +0 -224
- package/yjs/package.json +0 -14
package/dist/types.d.ts
CHANGED
|
@@ -1,45 +1,36 @@
|
|
|
1
1
|
import { JSONContent } from '@tiptap/core';
|
|
2
2
|
export type RichTextEditorProps = {
|
|
3
3
|
modelValue?: JSONContent | null;
|
|
4
|
+
documentName?: string;
|
|
4
5
|
editable?: boolean;
|
|
5
6
|
mode?: 'edit' | 'preview';
|
|
7
|
+
watermark?: RichTextEditorWatermarkOptions | null;
|
|
8
|
+
showOutline?: boolean;
|
|
6
9
|
outlinePlacement?: 'left' | 'right';
|
|
7
10
|
messages?: RichTextEditorMessages | null;
|
|
8
11
|
enabledExportItems?: RichTextEditorExportItemKey[] | null;
|
|
9
12
|
enabledInsertMenuItems?: RichTextEditorInsertMenuItemKey[] | null;
|
|
10
13
|
enabledToolbarActions?: RichTextEditorToolbarActionKey[] | null;
|
|
11
14
|
placeholder?: string;
|
|
12
|
-
|
|
15
|
+
mention?: boolean;
|
|
16
|
+
uploadImage?: RichTextEditorUploadHook | null;
|
|
17
|
+
uploadVideo?: RichTextEditorUploadHook | null;
|
|
18
|
+
uploadFile?: RichTextEditorUploadHook | null;
|
|
19
|
+
onUploadError?: RichTextEditorUploadErrorHandler | null;
|
|
13
20
|
mentionProvider?: RichTextEditorMentionProvider | null;
|
|
14
21
|
onMentionSearch?: RichTextEditorMentionProvider | null;
|
|
15
22
|
};
|
|
16
23
|
export type RichTextEditorMessages = Partial<Record<string, string>>;
|
|
24
|
+
export type RichTextEditorWatermarkOptions = {
|
|
25
|
+
text: string;
|
|
26
|
+
color?: string;
|
|
27
|
+
fontSize?: number;
|
|
28
|
+
rotate?: number;
|
|
29
|
+
showInEdit?: boolean;
|
|
30
|
+
};
|
|
17
31
|
export type RichTextEditorExportItemKey = 'pdf' | 'html' | 'image' | 'print';
|
|
18
32
|
export type RichTextEditorInsertMenuItemKey = 'image' | 'video' | 'table' | 'local-file' | 'columns' | 'highlight-block' | 'date' | 'code-block' | 'formula' | 'blockquote' | 'emoji' | 'link' | 'divider' | 'countdown' | 'markdown-import';
|
|
19
33
|
export type RichTextEditorToolbarActionKey = 'blockquote';
|
|
20
|
-
export type RichTextEditorCollaborationDocument = {
|
|
21
|
-
getXmlFragment: (field: string) => unknown;
|
|
22
|
-
};
|
|
23
|
-
export type RichTextEditorCollaborationAwareness = {
|
|
24
|
-
states: Map<number, unknown>;
|
|
25
|
-
on: (event: 'update', callback: (...args: unknown[]) => void) => void;
|
|
26
|
-
setLocalStateField: (field: string, value: unknown) => void;
|
|
27
|
-
};
|
|
28
|
-
export type RichTextEditorCollaborationProvider = {
|
|
29
|
-
doc?: unknown;
|
|
30
|
-
awareness: RichTextEditorCollaborationAwareness;
|
|
31
|
-
};
|
|
32
|
-
export type RichTextEditorCollaborationUser = {
|
|
33
|
-
name: string;
|
|
34
|
-
color: string;
|
|
35
|
-
[key: string]: unknown;
|
|
36
|
-
};
|
|
37
|
-
export type RichTextEditorCollaborationOptions = {
|
|
38
|
-
document: RichTextEditorCollaborationDocument;
|
|
39
|
-
field?: string;
|
|
40
|
-
provider?: RichTextEditorCollaborationProvider | null;
|
|
41
|
-
user?: RichTextEditorCollaborationUser | null;
|
|
42
|
-
};
|
|
43
34
|
export type RichTextEditorMentionType = 1 | 2;
|
|
44
35
|
export type RichTextEditorMentionItem = {
|
|
45
36
|
id: string;
|
|
@@ -57,6 +48,26 @@ export type RichTextEditorMentionProviderPayload = {
|
|
|
57
48
|
};
|
|
58
49
|
export type RichTextEditorMentionProvider = (payload: RichTextEditorMentionProviderPayload) => RichTextEditorMentionItem[] | Promise<RichTextEditorMentionItem[]>;
|
|
59
50
|
export type RichTextEditorAlign = 'left' | 'center' | 'right';
|
|
51
|
+
export type RichTextEditorUploadKind = 'image' | 'video' | 'file';
|
|
52
|
+
export type RichTextEditorUploadInput = {
|
|
53
|
+
file: File;
|
|
54
|
+
kind: RichTextEditorUploadKind;
|
|
55
|
+
};
|
|
56
|
+
export type RichTextEditorUploadResult = {
|
|
57
|
+
url: string;
|
|
58
|
+
name?: string;
|
|
59
|
+
size?: number;
|
|
60
|
+
mimeType?: string;
|
|
61
|
+
alt?: string;
|
|
62
|
+
description?: string;
|
|
63
|
+
};
|
|
64
|
+
export type RichTextEditorUploadHook = (payload: RichTextEditorUploadInput) => RichTextEditorUploadResult | Promise<RichTextEditorUploadResult>;
|
|
65
|
+
export type RichTextEditorUploadErrorPayload = {
|
|
66
|
+
kind: RichTextEditorUploadKind;
|
|
67
|
+
fileName: string;
|
|
68
|
+
error: unknown;
|
|
69
|
+
};
|
|
70
|
+
export type RichTextEditorUploadErrorHandler = (payload: RichTextEditorUploadErrorPayload) => void;
|
|
60
71
|
export type RichTextEditorImagePayload = {
|
|
61
72
|
src: string;
|
|
62
73
|
alt?: string;
|
|
@@ -88,10 +99,25 @@ export type RichTextEditorLocalFilePayload = {
|
|
|
88
99
|
size?: number;
|
|
89
100
|
mimeType?: string;
|
|
90
101
|
};
|
|
102
|
+
export type RichTextEditorCollectedFilePayload = ({
|
|
103
|
+
kind: 'file';
|
|
104
|
+
} & RichTextEditorFilePayload) | ({
|
|
105
|
+
kind: 'local-file';
|
|
106
|
+
} & RichTextEditorLocalFilePayload);
|
|
91
107
|
export type RichTextEditorImageExportOptions = {
|
|
92
108
|
type?: 'image/png' | 'image/jpeg';
|
|
93
109
|
quality?: number;
|
|
94
110
|
};
|
|
111
|
+
export type RichTextEditorOutlineItem = {
|
|
112
|
+
pos: number;
|
|
113
|
+
level: number;
|
|
114
|
+
text: string;
|
|
115
|
+
};
|
|
116
|
+
export type RichTextEditorOutlineState = {
|
|
117
|
+
items: RichTextEditorOutlineItem[];
|
|
118
|
+
activePos: number | null;
|
|
119
|
+
};
|
|
120
|
+
export type RichTextEditorOutlineChangeHandler = (state: RichTextEditorOutlineState) => void;
|
|
95
121
|
export type RichTextEditorInstance = {
|
|
96
122
|
exportPdf: () => Promise<Blob | null>;
|
|
97
123
|
exportImage: (options?: RichTextEditorImageExportOptions) => Promise<Blob | null>;
|
|
@@ -104,6 +130,14 @@ export type RichTextEditorInstance = {
|
|
|
104
130
|
openLocalFilePicker: () => void;
|
|
105
131
|
focus: () => void;
|
|
106
132
|
getJSON: () => JSONContent | null;
|
|
133
|
+
getText: () => string;
|
|
134
|
+
getImages: () => RichTextEditorImagePayload[];
|
|
135
|
+
getVideos: () => RichTextEditorVideoPayload[];
|
|
136
|
+
getFiles: () => RichTextEditorCollectedFilePayload[];
|
|
137
|
+
getOutlineItems: () => RichTextEditorOutlineItem[];
|
|
138
|
+
getActiveOutlinePos: () => number | null;
|
|
139
|
+
focusOutlineItem: (pos: number) => boolean;
|
|
140
|
+
onOutlineChange: (handler: RichTextEditorOutlineChangeHandler) => () => void;
|
|
107
141
|
};
|
|
108
142
|
export type OfficeIconProps = {
|
|
109
143
|
name: string;
|
package/docs/usage.md
CHANGED
|
@@ -1,95 +1,66 @@
|
|
|
1
|
-
# Package Usage
|
|
2
|
-
|
|
3
|
-
This file is shipped with the npm package so consumers can view the usage guide locally after installation.
|
|
4
|
-
|
|
5
|
-
See the package root `README.md` for the primary integration guide.
|
|
6
|
-
|
|
7
|
-
## Quick Start
|
|
8
|
-
|
|
9
|
-
```ts
|
|
10
|
-
import { RichTextEditor } from '@norio-office/rich-text'
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Main Capabilities
|
|
14
|
-
|
|
15
|
-
- rich text editing with a built-in toolbar UI
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
{ id: '
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
@mention-
|
|
41
|
-
@mention-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
##
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
user: {
|
|
68
|
-
name: '张三',
|
|
69
|
-
color: '#3b82f6',
|
|
70
|
-
},
|
|
71
|
-
}"
|
|
72
|
-
/>
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
When `collaboration` is omitted, the editor stays in normal single-user mode. When `provider + user` are passed, the editor also renders remote cursors and remote selections.
|
|
76
|
-
|
|
77
|
-
## Bundled Yjs Server
|
|
78
|
-
|
|
79
|
-
The npm package also ships a minimal websocket server example in `yjs/`.
|
|
80
|
-
|
|
81
|
-
```bash
|
|
82
|
-
cd node_modules/@norio-office/rich-text/yjs
|
|
83
|
-
npm install
|
|
84
|
-
npm run start
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
Client side:
|
|
88
|
-
|
|
89
|
-
```ts
|
|
90
|
-
import * as Y from 'yjs'
|
|
91
|
-
import { WebsocketProvider } from 'y-websocket'
|
|
92
|
-
|
|
93
|
-
const ydoc = new Y.Doc()
|
|
94
|
-
const provider = new WebsocketProvider('ws://127.0.0.1:1234', 'office-word-demo', ydoc)
|
|
95
|
-
```
|
|
1
|
+
# Package Usage
|
|
2
|
+
|
|
3
|
+
This file is shipped with the npm package so consumers can view the usage guide locally after installation.
|
|
4
|
+
|
|
5
|
+
See the package root `README.md` for the primary integration guide.
|
|
6
|
+
|
|
7
|
+
## Quick Start
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { RichTextEditor } from '@norio-office/rich-text'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Main Capabilities
|
|
14
|
+
|
|
15
|
+
- rich text editing with a built-in toolbar UI
|
|
16
|
+
- async `@` mention candidates for people and documents
|
|
17
|
+
- export to PDF, image, and HTML through instance methods
|
|
18
|
+
- external upload integration for image, video, and file insertion
|
|
19
|
+
- typed public instance API for Vue `ref` usage
|
|
20
|
+
|
|
21
|
+
## Mention
|
|
22
|
+
|
|
23
|
+
Provide `@mention-search` to load people and document candidates when the user types `@`. The handler may return an array or a `Promise`.
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import type { RichTextEditorMentionItem, RichTextEditorMentionProviderPayload } from '@norio-office/rich-text'
|
|
27
|
+
|
|
28
|
+
async function handleMentionSearch(payload: RichTextEditorMentionProviderPayload): Promise<RichTextEditorMentionItem[]> {
|
|
29
|
+
return [
|
|
30
|
+
{ id: 'u-1', name: '崔国强', type: 1, avatar: 'https://cdn.xxx.com/avatar.png' },
|
|
31
|
+
{ id: 'd-1', name: 'IT资产管理系统', type: 2, icon: 'https://cdn.xxx.com/doc.png', updatedAt: '2025年12月1日' },
|
|
32
|
+
].filter((item) => payload.type === 'all' || !payload.type || item.type === payload.type)
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```vue
|
|
37
|
+
<RichTextEditor
|
|
38
|
+
v-model="content"
|
|
39
|
+
@mention-search="handleMentionSearch"
|
|
40
|
+
@mention-item-click="handleMentionItemClick"
|
|
41
|
+
@mention-submit="handleMentionSubmit"
|
|
42
|
+
/>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`type: 1` means person and `type: 2` means document. The editor inserts a mention only after the user clicks `提及`.
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
## Bundled Yjs Server
|
|
49
|
+
|
|
50
|
+
The npm package also ships a minimal websocket server example in `yjs/`.
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
cd node_modules/@norio-office/rich-text/yjs
|
|
54
|
+
npm install
|
|
55
|
+
npm run start
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Client side:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import * as Y from 'yjs'
|
|
62
|
+
import { WebsocketProvider } from 'y-websocket'
|
|
63
|
+
|
|
64
|
+
const ydoc = new Y.Doc()
|
|
65
|
+
const provider = new WebsocketProvider('ws://127.0.0.1:1234', 'office-word-demo', ydoc)
|
|
66
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@norio-office/rich-text",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A reusable Vue 3 rich text editor component built with Tiptap 3.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.umd.cjs",
|
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
"dist",
|
|
19
19
|
"README.md",
|
|
20
20
|
"docs",
|
|
21
|
-
"yjs",
|
|
22
21
|
"LICENSE"
|
|
23
22
|
],
|
|
24
23
|
"sideEffects": [
|
|
@@ -40,8 +39,6 @@
|
|
|
40
39
|
"@tiptap/core": "^3.22.1",
|
|
41
40
|
"@tiptap/extension-code-block": "^3.22.1",
|
|
42
41
|
"@tiptap/extension-code-block-lowlight": "^3.22.1",
|
|
43
|
-
"@tiptap/extension-collaboration": "^3.22.2",
|
|
44
|
-
"@tiptap/extension-collaboration-caret": "^3.22.2",
|
|
45
42
|
"@tiptap/extension-font-family": "^3.22.1",
|
|
46
43
|
"@tiptap/extension-placeholder": "^3.22.1",
|
|
47
44
|
"@tiptap/extension-subscript": "^3.22.1",
|
|
@@ -57,11 +54,8 @@
|
|
|
57
54
|
"@tiptap/pm": "^3.22.1",
|
|
58
55
|
"@tiptap/starter-kit": "^3.22.1",
|
|
59
56
|
"@tiptap/vue-3": "^3.22.1",
|
|
60
|
-
"@tiptap/y-tiptap": "^3.0.2",
|
|
61
57
|
"lowlight": "^3.3.0",
|
|
62
|
-
"vue": "^3.5.0"
|
|
63
|
-
"y-prosemirror": "^1.2.6",
|
|
64
|
-
"yjs": "^13.6.30"
|
|
58
|
+
"vue": "^3.5.0"
|
|
65
59
|
},
|
|
66
60
|
"dependencies": {
|
|
67
61
|
"html2canvas": "^1.4.1",
|