@ap666/office-word 0.1.2 → 0.1.5
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 +65 -1
- package/dist/composables/useRichTextEditor.d.ts +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4430 -4192
- package/dist/index.umd.cjs +4871 -4811
- package/dist/style.css +1 -1
- package/dist/types.d.ts +24 -0
- package/docs/usage.md +49 -0
- package/package.json +9 -2
- package/yjs/README.md +63 -0
- package/yjs/index.js +224 -0
- package/yjs/package.json +14 -0
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ npm install @ap666/office-word
|
|
|
11
11
|
If your package manager does not auto-install peer dependencies, install the required runtime peers as well:
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
npm install vue @tiptap/core @tiptap/vue-3 @tiptap/pm @tiptap/starter-kit @tiptap/extension-placeholder @tiptap/extension-code-block @tiptap/extension-code-block-lowlight @tiptap/extension-font-family @tiptap/extension-subscript @tiptap/extension-superscript @tiptap/extension-table @tiptap/extension-table-cell @tiptap/extension-table-header @tiptap/extension-table-row @tiptap/extension-task-item @tiptap/extension-task-list @tiptap/extension-text-style @tiptap/extension-underline lowlight
|
|
14
|
+
npm install vue @tiptap/core @tiptap/vue-3 @tiptap/pm @tiptap/starter-kit @tiptap/extension-placeholder @tiptap/extension-code-block @tiptap/extension-code-block-lowlight @tiptap/extension-collaboration @tiptap/extension-collaboration-caret @tiptap/extension-font-family @tiptap/extension-subscript @tiptap/extension-superscript @tiptap/extension-table @tiptap/extension-table-cell @tiptap/extension-table-header @tiptap/extension-table-row @tiptap/extension-task-item @tiptap/extension-task-list @tiptap/extension-text-style @tiptap/extension-underline @tiptap/y-tiptap lowlight y-prosemirror yjs
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
## Basic Use
|
|
@@ -37,6 +37,66 @@ The package imports its own styles from the entry, so no extra CSS import is req
|
|
|
37
37
|
- `modelValue?: JSONContent | null`
|
|
38
38
|
- `editable?: boolean`
|
|
39
39
|
- `placeholder?: string`
|
|
40
|
+
- `collaboration?: RichTextEditorCollaborationOptions | null`
|
|
41
|
+
|
|
42
|
+
## Collaboration
|
|
43
|
+
|
|
44
|
+
The same component supports both normal single-user editing and optional Yjs collaboration.
|
|
45
|
+
|
|
46
|
+
```vue
|
|
47
|
+
<script setup lang="ts">
|
|
48
|
+
import { ref } from 'vue'
|
|
49
|
+
import * as Y from 'yjs'
|
|
50
|
+
import { WebsocketProvider } from 'y-websocket'
|
|
51
|
+
import type { JSONContent } from '@tiptap/core'
|
|
52
|
+
import { RichTextEditor } from '@ap666/office-word'
|
|
53
|
+
|
|
54
|
+
const ydoc = new Y.Doc()
|
|
55
|
+
const provider = new WebsocketProvider('ws://localhost:1234', 'office-word-demo', ydoc)
|
|
56
|
+
const content = ref<JSONContent | null>(null)
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<template>
|
|
60
|
+
<RichTextEditor
|
|
61
|
+
v-model="content"
|
|
62
|
+
:collaboration="{
|
|
63
|
+
document: ydoc,
|
|
64
|
+
field: 'content',
|
|
65
|
+
provider,
|
|
66
|
+
user: {
|
|
67
|
+
name: '张三',
|
|
68
|
+
color: '#3b82f6',
|
|
69
|
+
},
|
|
70
|
+
}"
|
|
71
|
+
/>
|
|
72
|
+
</template>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
In collaboration mode, the shared Yjs fragment becomes the source of truth. The component still emits JSON updates, but external `modelValue` changes are not pushed back into the editor. If you want remote cursors, also install `y-websocket` in the host project and pass `provider + user`.
|
|
76
|
+
|
|
77
|
+
Do not use `modelValue` as the initial seed source for a collaborative room. Seed the Yjs document before mounting the editor if the room needs default content.
|
|
78
|
+
|
|
79
|
+
### Included Yjs Server Example
|
|
80
|
+
|
|
81
|
+
The published package also includes a minimal collaboration server under `yjs/`.
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
cd node_modules/@ap666/office-word/yjs
|
|
85
|
+
npm install
|
|
86
|
+
npm run start
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Default address is `ws://0.0.0.0:1234`.
|
|
90
|
+
|
|
91
|
+
Use the same websocket address and room name on every client:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import * as Y from 'yjs'
|
|
95
|
+
import { WebsocketProvider } from 'y-websocket'
|
|
96
|
+
|
|
97
|
+
const ydoc = new Y.Doc()
|
|
98
|
+
const provider = new WebsocketProvider('ws://127.0.0.1:1234', 'office-word-demo', ydoc)
|
|
99
|
+
```
|
|
40
100
|
|
|
41
101
|
## Instance API
|
|
42
102
|
|
|
@@ -167,6 +227,9 @@ async function uploadFile(file: File) {
|
|
|
167
227
|
|
|
168
228
|
```ts
|
|
169
229
|
import type {
|
|
230
|
+
RichTextEditorCollaborationProvider,
|
|
231
|
+
RichTextEditorCollaborationUser,
|
|
232
|
+
RichTextEditorCollaborationOptions,
|
|
170
233
|
RichTextEditorFilePayload,
|
|
171
234
|
RichTextEditorImageExportOptions,
|
|
172
235
|
RichTextEditorImagePayload,
|
|
@@ -178,3 +241,4 @@ import type {
|
|
|
178
241
|
## Package Docs
|
|
179
242
|
|
|
180
243
|
- usage guide: `docs/usage.md`
|
|
244
|
+
- bundled Yjs server example: `yjs/README.md`
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { JSONContent } from '@tiptap/core';
|
|
2
|
+
import { RichTextEditorCollaborationOptions } from '../types';
|
|
2
3
|
type UseRichTextEditorOptions = {
|
|
3
4
|
content: JSONContent;
|
|
4
5
|
editable: boolean;
|
|
5
6
|
placeholder: string;
|
|
7
|
+
collaboration?: RichTextEditorCollaborationOptions | null;
|
|
6
8
|
onUpdate: (value: JSONContent) => void;
|
|
7
9
|
};
|
|
8
10
|
export declare function useRichTextEditor(options: UseRichTextEditorOptions): import('vue').ShallowRef<import('@tiptap/vue-3').Editor | undefined, import('@tiptap/vue-3').Editor | undefined>;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ import { default as RichTextEditor } from './components/RichTextEditor.vue';
|
|
|
4
4
|
import { default as ScrollArea } from './components/ScrollArea.vue';
|
|
5
5
|
export { OfficeColorIcon, OfficeIcon, RichTextEditor, ScrollArea };
|
|
6
6
|
export { colorIconNames, monoIconNames } from './icons';
|
|
7
|
-
export type { OfficeColorIconProps, OfficeIconProps, RichTextEditorFilePayload, RichTextEditorImageExportOptions, RichTextEditorImagePayload, RichTextEditorInstance, RichTextEditorProps, RichTextEditorVideoPayload, } from './types';
|
|
7
|
+
export type { OfficeColorIconProps, OfficeIconProps, RichTextEditorCollaborationAwareness, RichTextEditorCollaborationDocument, RichTextEditorCollaborationOptions, RichTextEditorCollaborationProvider, RichTextEditorCollaborationUser, RichTextEditorFilePayload, RichTextEditorImageExportOptions, RichTextEditorImagePayload, RichTextEditorInstance, RichTextEditorProps, RichTextEditorVideoPayload, } from './types';
|
|
8
8
|
export default RichTextEditor;
|