@norio-office/rich-text 0.1.0 → 0.6.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 +1753 -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 +56 -1
- package/dist/components/RichTextOutline.vue.d.ts +30 -0
- package/dist/composables/useRichTextEditor.d.ts +7 -1
- package/dist/extensions/comment-mark.d.ts +2 -0
- package/dist/extensions/image-block.d.ts +7 -1
- package/dist/extensions/video-block.d.ts +7 -1
- package/dist/{html2canvas-Bwmq6fGh.js → html2canvas-4hiP1s1t.js} +2 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +7163 -5226
- package/dist/index.umd.cjs +1472 -705
- package/dist/style.css +1 -1
- package/dist/types.d.ts +154 -0
- package/dist/utils/url.d.ts +2 -0
- package/docs/usage.md +94 -92
- package/package.json +1 -1
- package/yjs/README.md +63 -63
- package/yjs/index.js +224 -224
- package/yjs/package.json +14 -14
- package/dist/index.es-C4X5YiRo.js +0 -5751
- package/dist/jspdf.es.min-ByaXFVjc.js +0 -18214
- package/dist/purify.es-B5ixYH9L.js +0 -549
- package/dist/typeof-Dz1Ap89p.js +0 -11
package/dist/types.d.ts
CHANGED
|
@@ -1,19 +1,41 @@
|
|
|
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;
|
|
15
|
+
mention?: boolean;
|
|
12
16
|
collaboration?: RichTextEditorCollaborationOptions | null;
|
|
17
|
+
comments?: RichTextEditorCommentThread[] | null;
|
|
18
|
+
commentUser?: RichTextEditorCommentUser | null;
|
|
19
|
+
showComments?: boolean;
|
|
20
|
+
commentMention?: boolean;
|
|
21
|
+
uploadImage?: RichTextEditorUploadHook | null;
|
|
22
|
+
uploadVideo?: RichTextEditorUploadHook | null;
|
|
23
|
+
uploadFile?: RichTextEditorUploadHook | null;
|
|
24
|
+
uploadCommentImage?: RichTextEditorUploadHook | null;
|
|
25
|
+
onUploadError?: RichTextEditorUploadErrorHandler | null;
|
|
26
|
+
commentMentionProvider?: RichTextEditorCommentMentionProvider | null;
|
|
27
|
+
onCommentMentionSearch?: RichTextEditorCommentMentionProvider | null;
|
|
13
28
|
mentionProvider?: RichTextEditorMentionProvider | null;
|
|
14
29
|
onMentionSearch?: RichTextEditorMentionProvider | null;
|
|
15
30
|
};
|
|
16
31
|
export type RichTextEditorMessages = Partial<Record<string, string>>;
|
|
32
|
+
export type RichTextEditorWatermarkOptions = {
|
|
33
|
+
text: string;
|
|
34
|
+
color?: string;
|
|
35
|
+
fontSize?: number;
|
|
36
|
+
rotate?: number;
|
|
37
|
+
showInEdit?: boolean;
|
|
38
|
+
};
|
|
17
39
|
export type RichTextEditorExportItemKey = 'pdf' | 'html' | 'image' | 'print';
|
|
18
40
|
export type RichTextEditorInsertMenuItemKey = 'image' | 'video' | 'table' | 'local-file' | 'columns' | 'highlight-block' | 'date' | 'code-block' | 'formula' | 'blockquote' | 'emoji' | 'link' | 'divider' | 'countdown' | 'markdown-import';
|
|
19
41
|
export type RichTextEditorToolbarActionKey = 'blockquote';
|
|
@@ -39,6 +61,8 @@ export type RichTextEditorCollaborationOptions = {
|
|
|
39
61
|
field?: string;
|
|
40
62
|
provider?: RichTextEditorCollaborationProvider | null;
|
|
41
63
|
user?: RichTextEditorCollaborationUser | null;
|
|
64
|
+
initializeContent?: boolean;
|
|
65
|
+
initialContent?: JSONContent | null;
|
|
42
66
|
};
|
|
43
67
|
export type RichTextEditorMentionType = 1 | 2;
|
|
44
68
|
export type RichTextEditorMentionItem = {
|
|
@@ -57,6 +81,112 @@ export type RichTextEditorMentionProviderPayload = {
|
|
|
57
81
|
};
|
|
58
82
|
export type RichTextEditorMentionProvider = (payload: RichTextEditorMentionProviderPayload) => RichTextEditorMentionItem[] | Promise<RichTextEditorMentionItem[]>;
|
|
59
83
|
export type RichTextEditorAlign = 'left' | 'center' | 'right';
|
|
84
|
+
export type RichTextEditorUploadKind = 'image' | 'video' | 'file';
|
|
85
|
+
export type RichTextEditorUploadInput = {
|
|
86
|
+
file: File;
|
|
87
|
+
kind: RichTextEditorUploadKind;
|
|
88
|
+
};
|
|
89
|
+
export type RichTextEditorUploadResult = {
|
|
90
|
+
url: string;
|
|
91
|
+
name?: string;
|
|
92
|
+
size?: number;
|
|
93
|
+
mimeType?: string;
|
|
94
|
+
alt?: string;
|
|
95
|
+
description?: string;
|
|
96
|
+
};
|
|
97
|
+
export type RichTextEditorUploadHook = (payload: RichTextEditorUploadInput) => RichTextEditorUploadResult | Promise<RichTextEditorUploadResult>;
|
|
98
|
+
export type RichTextEditorUploadErrorPayload = {
|
|
99
|
+
kind: RichTextEditorUploadKind;
|
|
100
|
+
fileName: string;
|
|
101
|
+
error: unknown;
|
|
102
|
+
};
|
|
103
|
+
export type RichTextEditorUploadErrorHandler = (payload: RichTextEditorUploadErrorPayload) => void;
|
|
104
|
+
export type RichTextEditorCommentUser = {
|
|
105
|
+
id: string;
|
|
106
|
+
name: string;
|
|
107
|
+
avatar?: string;
|
|
108
|
+
color?: string;
|
|
109
|
+
[key: string]: unknown;
|
|
110
|
+
};
|
|
111
|
+
export type RichTextEditorCommentImage = RichTextEditorUploadResult;
|
|
112
|
+
export type RichTextEditorCommentMentionItem = RichTextEditorMentionItem;
|
|
113
|
+
export type RichTextEditorCommentMentionProviderPayload = RichTextEditorMentionProviderPayload & {
|
|
114
|
+
threadId?: string;
|
|
115
|
+
commentId?: string;
|
|
116
|
+
parentId?: string;
|
|
117
|
+
content: string;
|
|
118
|
+
};
|
|
119
|
+
export type RichTextEditorCommentMentionProvider = (payload: RichTextEditorCommentMentionProviderPayload) => RichTextEditorCommentMentionItem[] | Promise<RichTextEditorCommentMentionItem[]>;
|
|
120
|
+
export type RichTextEditorCommentItem = {
|
|
121
|
+
id: string;
|
|
122
|
+
parentId?: string;
|
|
123
|
+
content: string;
|
|
124
|
+
author: RichTextEditorCommentUser;
|
|
125
|
+
createdAt: string;
|
|
126
|
+
updatedAt?: string;
|
|
127
|
+
images?: RichTextEditorCommentImage[];
|
|
128
|
+
mentions?: RichTextEditorCommentMentionItem[];
|
|
129
|
+
};
|
|
130
|
+
export type RichTextEditorCommentThread = {
|
|
131
|
+
id: string;
|
|
132
|
+
anchorText?: string;
|
|
133
|
+
status?: 'open' | 'resolved';
|
|
134
|
+
comments: RichTextEditorCommentItem[];
|
|
135
|
+
};
|
|
136
|
+
export type RichTextEditorCommentCreatePayload = {
|
|
137
|
+
threadId: string;
|
|
138
|
+
commentId: string;
|
|
139
|
+
anchorText: string;
|
|
140
|
+
content: string;
|
|
141
|
+
images: RichTextEditorCommentImage[];
|
|
142
|
+
mentions: RichTextEditorCommentMentionItem[];
|
|
143
|
+
author: RichTextEditorCommentUser;
|
|
144
|
+
createdAt: string;
|
|
145
|
+
};
|
|
146
|
+
export type RichTextEditorCommentReplyPayload = {
|
|
147
|
+
threadId: string;
|
|
148
|
+
commentId: string;
|
|
149
|
+
parentId?: string;
|
|
150
|
+
targetCommentId?: string;
|
|
151
|
+
targetUserId?: string;
|
|
152
|
+
targetUserName?: string;
|
|
153
|
+
content: string;
|
|
154
|
+
images: RichTextEditorCommentImage[];
|
|
155
|
+
mentions: RichTextEditorCommentMentionItem[];
|
|
156
|
+
author: RichTextEditorCommentUser;
|
|
157
|
+
createdAt: string;
|
|
158
|
+
};
|
|
159
|
+
export type RichTextEditorCommentUpdatePayload = {
|
|
160
|
+
threadId: string;
|
|
161
|
+
commentId: string;
|
|
162
|
+
content: string;
|
|
163
|
+
images?: RichTextEditorCommentImage[];
|
|
164
|
+
mentions: RichTextEditorCommentMentionItem[];
|
|
165
|
+
author?: RichTextEditorCommentUser;
|
|
166
|
+
updatedAt: string;
|
|
167
|
+
};
|
|
168
|
+
export type RichTextEditorCommentSubmitPayload = {
|
|
169
|
+
action: 'create' | 'reply' | 'update';
|
|
170
|
+
threadId: string;
|
|
171
|
+
commentId: string;
|
|
172
|
+
targetCommentId?: string;
|
|
173
|
+
targetUserId?: string;
|
|
174
|
+
targetUserName?: string;
|
|
175
|
+
content: string;
|
|
176
|
+
images?: RichTextEditorCommentImage[];
|
|
177
|
+
mentions: RichTextEditorCommentMentionItem[];
|
|
178
|
+
author?: RichTextEditorCommentUser;
|
|
179
|
+
createdAt?: string;
|
|
180
|
+
updatedAt?: string;
|
|
181
|
+
};
|
|
182
|
+
export type RichTextEditorCommentDeletePayload = {
|
|
183
|
+
threadId: string;
|
|
184
|
+
commentId?: string;
|
|
185
|
+
};
|
|
186
|
+
export type RichTextEditorCommentResolvePayload = {
|
|
187
|
+
threadId: string;
|
|
188
|
+
resolved: boolean;
|
|
189
|
+
};
|
|
60
190
|
export type RichTextEditorImagePayload = {
|
|
61
191
|
src: string;
|
|
62
192
|
alt?: string;
|
|
@@ -88,10 +218,25 @@ export type RichTextEditorLocalFilePayload = {
|
|
|
88
218
|
size?: number;
|
|
89
219
|
mimeType?: string;
|
|
90
220
|
};
|
|
221
|
+
export type RichTextEditorCollectedFilePayload = ({
|
|
222
|
+
kind: 'file';
|
|
223
|
+
} & RichTextEditorFilePayload) | ({
|
|
224
|
+
kind: 'local-file';
|
|
225
|
+
} & RichTextEditorLocalFilePayload);
|
|
91
226
|
export type RichTextEditorImageExportOptions = {
|
|
92
227
|
type?: 'image/png' | 'image/jpeg';
|
|
93
228
|
quality?: number;
|
|
94
229
|
};
|
|
230
|
+
export type RichTextEditorOutlineItem = {
|
|
231
|
+
pos: number;
|
|
232
|
+
level: number;
|
|
233
|
+
text: string;
|
|
234
|
+
};
|
|
235
|
+
export type RichTextEditorOutlineState = {
|
|
236
|
+
items: RichTextEditorOutlineItem[];
|
|
237
|
+
activePos: number | null;
|
|
238
|
+
};
|
|
239
|
+
export type RichTextEditorOutlineChangeHandler = (state: RichTextEditorOutlineState) => void;
|
|
95
240
|
export type RichTextEditorInstance = {
|
|
96
241
|
exportPdf: () => Promise<Blob | null>;
|
|
97
242
|
exportImage: (options?: RichTextEditorImageExportOptions) => Promise<Blob | null>;
|
|
@@ -104,6 +249,15 @@ export type RichTextEditorInstance = {
|
|
|
104
249
|
openLocalFilePicker: () => void;
|
|
105
250
|
focus: () => void;
|
|
106
251
|
getJSON: () => JSONContent | null;
|
|
252
|
+
getText: () => string;
|
|
253
|
+
getImages: () => RichTextEditorImagePayload[];
|
|
254
|
+
getVideos: () => RichTextEditorVideoPayload[];
|
|
255
|
+
getFiles: () => RichTextEditorCollectedFilePayload[];
|
|
256
|
+
getOutlineItems: () => RichTextEditorOutlineItem[];
|
|
257
|
+
getActiveOutlinePos: () => number | null;
|
|
258
|
+
focusOutlineItem: (pos: number) => boolean;
|
|
259
|
+
onOutlineChange: (handler: RichTextEditorOutlineChangeHandler) => () => void;
|
|
260
|
+
focusCommentThread: (threadId: string) => boolean;
|
|
107
261
|
};
|
|
108
262
|
export type OfficeIconProps = {
|
|
109
263
|
name: string;
|
package/docs/usage.md
CHANGED
|
@@ -1,95 +1,97 @@
|
|
|
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
|
-
- optional Yjs collaboration mode with the same component API
|
|
17
|
-
- async `@` mention candidates for people and documents
|
|
18
|
-
- export to PDF, image, and HTML through instance methods
|
|
19
|
-
- external upload integration for image, video, and file insertion
|
|
20
|
-
- typed public instance API for Vue `ref` usage
|
|
21
|
-
|
|
22
|
-
## Mention
|
|
23
|
-
|
|
24
|
-
Provide `@mention-search` to load people and document candidates when the user types `@`. The handler may return an array or a `Promise`.
|
|
25
|
-
|
|
26
|
-
```ts
|
|
27
|
-
import type { RichTextEditorMentionItem, RichTextEditorMentionProviderPayload } from '@norio-office/rich-text'
|
|
28
|
-
|
|
29
|
-
async function handleMentionSearch(payload: RichTextEditorMentionProviderPayload): Promise<RichTextEditorMentionItem[]> {
|
|
30
|
-
return [
|
|
31
|
-
{ id: 'u-1', name: '崔国强', type: 1, avatar: 'https://cdn.xxx.com/avatar.png' },
|
|
32
|
-
{ id: 'd-1', name: 'IT资产管理系统', type: 2, icon: 'https://cdn.xxx.com/doc.png', updatedAt: '2025年12月1日' },
|
|
33
|
-
].filter((item) => payload.type === 'all' || !payload.type || item.type === payload.type)
|
|
34
|
-
}
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
```vue
|
|
38
|
-
<RichTextEditor
|
|
39
|
-
v-model="content"
|
|
40
|
-
@mention-search="handleMentionSearch"
|
|
41
|
-
@mention-item-click="handleMentionItemClick"
|
|
42
|
-
@mention-submit="handleMentionSubmit"
|
|
43
|
-
/>
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
`type: 1` means person and `type: 2` means document. The editor inserts a mention only after the user clicks `提及`.
|
|
47
|
-
|
|
48
|
-
## Collaboration
|
|
49
|
-
|
|
50
|
-
Use the optional `collaboration` prop to bind the editor to a Yjs document.
|
|
51
|
-
|
|
52
|
-
```ts
|
|
53
|
-
import * as Y from 'yjs'
|
|
54
|
-
import { WebsocketProvider } from 'y-websocket'
|
|
55
|
-
|
|
56
|
-
const ydoc = new Y.Doc()
|
|
57
|
-
const provider = new WebsocketProvider('ws://localhost:1234', 'office-word-demo', ydoc)
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
```vue
|
|
61
|
-
<RichTextEditor
|
|
62
|
-
v-model="content"
|
|
63
|
-
:collaboration="{
|
|
64
|
-
document: ydoc,
|
|
65
|
-
field: 'content',
|
|
66
|
-
provider,
|
|
67
|
-
user: {
|
|
68
|
-
name: '张三',
|
|
69
|
-
color: '#3b82f6',
|
|
70
|
-
},
|
|
71
|
-
}"
|
|
72
|
-
/>
|
|
73
|
-
```
|
|
74
|
-
|
|
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
|
+
- optional Yjs collaboration mode with the same component API
|
|
17
|
+
- async `@` mention candidates for people and documents
|
|
18
|
+
- export to PDF, image, and HTML through instance methods
|
|
19
|
+
- external upload integration for image, video, and file insertion
|
|
20
|
+
- typed public instance API for Vue `ref` usage
|
|
21
|
+
|
|
22
|
+
## Mention
|
|
23
|
+
|
|
24
|
+
Provide `@mention-search` to load people and document candidates when the user types `@`. The handler may return an array or a `Promise`.
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import type { RichTextEditorMentionItem, RichTextEditorMentionProviderPayload } from '@norio-office/rich-text'
|
|
28
|
+
|
|
29
|
+
async function handleMentionSearch(payload: RichTextEditorMentionProviderPayload): Promise<RichTextEditorMentionItem[]> {
|
|
30
|
+
return [
|
|
31
|
+
{ id: 'u-1', name: '崔国强', type: 1, avatar: 'https://cdn.xxx.com/avatar.png' },
|
|
32
|
+
{ id: 'd-1', name: 'IT资产管理系统', type: 2, icon: 'https://cdn.xxx.com/doc.png', updatedAt: '2025年12月1日' },
|
|
33
|
+
].filter((item) => payload.type === 'all' || !payload.type || item.type === payload.type)
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```vue
|
|
38
|
+
<RichTextEditor
|
|
39
|
+
v-model="content"
|
|
40
|
+
@mention-search="handleMentionSearch"
|
|
41
|
+
@mention-item-click="handleMentionItemClick"
|
|
42
|
+
@mention-submit="handleMentionSubmit"
|
|
43
|
+
/>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`type: 1` means person and `type: 2` means document. The editor inserts a mention only after the user clicks `提及`.
|
|
47
|
+
|
|
48
|
+
## Collaboration
|
|
49
|
+
|
|
50
|
+
Use the optional `collaboration` prop to bind the editor to a Yjs document.
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import * as Y from 'yjs'
|
|
54
|
+
import { WebsocketProvider } from 'y-websocket'
|
|
55
|
+
|
|
56
|
+
const ydoc = new Y.Doc()
|
|
57
|
+
const provider = new WebsocketProvider('ws://localhost:1234', 'office-word-demo', ydoc)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```vue
|
|
61
|
+
<RichTextEditor
|
|
62
|
+
v-model="content"
|
|
63
|
+
:collaboration="{
|
|
64
|
+
document: ydoc,
|
|
65
|
+
field: 'content',
|
|
66
|
+
provider,
|
|
67
|
+
user: {
|
|
68
|
+
name: '张三',
|
|
69
|
+
color: '#3b82f6',
|
|
70
|
+
},
|
|
71
|
+
}"
|
|
72
|
+
/>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
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
76
|
|
|
77
|
-
|
|
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
|
-
```
|
|
77
|
+
In collaboration mode, the shared Yjs fragment is authoritative. The editor does not write `modelValue` into an empty collaborative fragment by default. If a brand-new room needs initial business content, the host must first confirm this client owns initialization, then pass `initializeContent: true` and `initialContent` inside the `collaboration` object. Do not use those flags when the backend already has a Yjs snapshot.
|
|
86
78
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
```
|
|
79
|
+
## Bundled Yjs Server
|
|
80
|
+
|
|
81
|
+
The npm package also ships a minimal websocket server example in `yjs/`.
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
cd node_modules/@norio-office/rich-text/yjs
|
|
85
|
+
npm install
|
|
86
|
+
npm run start
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Client side:
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import * as Y from 'yjs'
|
|
93
|
+
import { WebsocketProvider } from 'y-websocket'
|
|
94
|
+
|
|
95
|
+
const ydoc = new Y.Doc()
|
|
96
|
+
const provider = new WebsocketProvider('ws://127.0.0.1:1234', 'office-word-demo', ydoc)
|
|
97
|
+
```
|
package/package.json
CHANGED
package/yjs/README.md
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
# Yjs Server Example
|
|
2
|
-
|
|
3
|
-
This folder is shipped with the npm package so consumers can run a minimal `y-websocket`-compatible Yjs server without adding another backend dependency.
|
|
4
|
-
|
|
5
|
-
## Files
|
|
6
|
-
|
|
7
|
-
- `index.js`: minimal websocket server compatible with `y-websocket`
|
|
8
|
-
- `package.json`: runtime dependencies and `npm run start`
|
|
9
|
-
|
|
10
|
-
## Start
|
|
11
|
-
|
|
12
|
-
```bash
|
|
13
|
-
cd yjs
|
|
14
|
-
npm install
|
|
15
|
-
npm run start
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
By default the server listens on `ws://0.0.0.0:1234`.
|
|
19
|
-
|
|
20
|
-
To override host or port:
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
HOST=0.0.0.0 PORT=1234 npm run start
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
PowerShell:
|
|
27
|
-
|
|
28
|
-
```powershell
|
|
29
|
-
$env:HOST="0.0.0.0"
|
|
30
|
-
$env:PORT="1234"
|
|
31
|
-
npm run start
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Client Link Example
|
|
35
|
-
|
|
36
|
-
```ts
|
|
37
|
-
import * as Y from 'yjs'
|
|
38
|
-
import { WebsocketProvider } from 'y-websocket'
|
|
39
|
-
|
|
40
|
-
const ydoc = new Y.Doc()
|
|
41
|
-
const provider = new WebsocketProvider('ws://127.0.0.1:1234', 'office-word-demo', ydoc)
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
```vue
|
|
45
|
-
<RichTextEditor
|
|
46
|
-
v-model="content"
|
|
47
|
-
:collaboration="{
|
|
48
|
-
document: ydoc,
|
|
49
|
-
field: 'content',
|
|
50
|
-
provider,
|
|
51
|
-
user: {
|
|
52
|
-
name: '张三',
|
|
53
|
-
color: '#3b82f6',
|
|
54
|
-
},
|
|
55
|
-
}"
|
|
56
|
-
/>
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## Notes
|
|
60
|
-
|
|
61
|
-
- all collaborators must use the same websocket address and the same room name
|
|
62
|
-
- if clients are on different machines, do not use `127.0.0.1`; use the server's real LAN or public address
|
|
63
|
-
- this sample server is in-memory only; document state is lost after restart
|
|
1
|
+
# Yjs Server Example
|
|
2
|
+
|
|
3
|
+
This folder is shipped with the npm package so consumers can run a minimal `y-websocket`-compatible Yjs server without adding another backend dependency.
|
|
4
|
+
|
|
5
|
+
## Files
|
|
6
|
+
|
|
7
|
+
- `index.js`: minimal websocket server compatible with `y-websocket`
|
|
8
|
+
- `package.json`: runtime dependencies and `npm run start`
|
|
9
|
+
|
|
10
|
+
## Start
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
cd yjs
|
|
14
|
+
npm install
|
|
15
|
+
npm run start
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
By default the server listens on `ws://0.0.0.0:1234`.
|
|
19
|
+
|
|
20
|
+
To override host or port:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
HOST=0.0.0.0 PORT=1234 npm run start
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
PowerShell:
|
|
27
|
+
|
|
28
|
+
```powershell
|
|
29
|
+
$env:HOST="0.0.0.0"
|
|
30
|
+
$env:PORT="1234"
|
|
31
|
+
npm run start
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Client Link Example
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import * as Y from 'yjs'
|
|
38
|
+
import { WebsocketProvider } from 'y-websocket'
|
|
39
|
+
|
|
40
|
+
const ydoc = new Y.Doc()
|
|
41
|
+
const provider = new WebsocketProvider('ws://127.0.0.1:1234', 'office-word-demo', ydoc)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
```vue
|
|
45
|
+
<RichTextEditor
|
|
46
|
+
v-model="content"
|
|
47
|
+
:collaboration="{
|
|
48
|
+
document: ydoc,
|
|
49
|
+
field: 'content',
|
|
50
|
+
provider,
|
|
51
|
+
user: {
|
|
52
|
+
name: '张三',
|
|
53
|
+
color: '#3b82f6',
|
|
54
|
+
},
|
|
55
|
+
}"
|
|
56
|
+
/>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Notes
|
|
60
|
+
|
|
61
|
+
- all collaborators must use the same websocket address and the same room name
|
|
62
|
+
- if clients are on different machines, do not use `127.0.0.1`; use the server's real LAN or public address
|
|
63
|
+
- this sample server is in-memory only; document state is lost after restart
|