|
3 | 3 | createExtension, |
4 | 4 | ExtensionOptions, |
5 | 5 | } from "../../editor/BlockNoteExtension.js"; |
6 | | -import { BlockNoteEditorOptions } from "../../editor/BlockNoteEditor.js"; |
| 6 | +import { CollaborationOptions } from "./Collaboration.js"; |
7 | 7 |
|
8 | 8 | export type CollaborationUser = { |
9 | 9 | name: string; |
@@ -67,29 +67,24 @@ function defaultCursorRender(user: CollaborationUser) { |
67 | 67 | } |
68 | 68 |
|
69 | 69 | export const YCursorExtension = createExtension( |
70 | | - ({ |
71 | | - options, |
72 | | - }: ExtensionOptions< |
73 | | - NonNullable<BlockNoteEditorOptions<any, any, any>["collaboration"]> |
74 | | - >) => { |
| 70 | + ({ options }: ExtensionOptions<CollaborationOptions>) => { |
75 | 71 | const recentlyUpdatedCursors = new Map(); |
76 | | - const hasAwareness = |
| 72 | + const awareness = |
77 | 73 | options.provider && |
78 | 74 | "awareness" in options.provider && |
79 | | - typeof options.provider.awareness === "object"; |
80 | | - if (hasAwareness) { |
| 75 | + typeof options.provider.awareness === "object" |
| 76 | + ? options.provider.awareness |
| 77 | + : undefined; |
| 78 | + if (awareness) { |
81 | 79 | if ( |
82 | | - "setLocalStateField" in options.provider.awareness && |
83 | | - typeof options.provider.awareness.setLocalStateField === "function" |
| 80 | + "setLocalStateField" in awareness && |
| 81 | + typeof awareness.setLocalStateField === "function" |
84 | 82 | ) { |
85 | | - options.provider.awareness.setLocalStateField("user", options.user); |
| 83 | + awareness.setLocalStateField("user", options.user); |
86 | 84 | } |
87 | | - if ( |
88 | | - "on" in options.provider.awareness && |
89 | | - typeof options.provider.awareness.on === "function" |
90 | | - ) { |
| 85 | + if ("on" in awareness && typeof awareness.on === "function") { |
91 | 86 | if (options.showCursorLabels !== "always") { |
92 | | - options.provider.awareness.on( |
| 87 | + awareness.on( |
93 | 88 | "change", |
94 | 89 | ({ |
95 | 90 | updated, |
@@ -125,8 +120,8 @@ export const YCursorExtension = createExtension( |
125 | 120 | return { |
126 | 121 | key: "yCursor", |
127 | 122 | prosemirrorPlugins: [ |
128 | | - hasAwareness |
129 | | - ? yCursorPlugin(options.provider.awareness, { |
| 123 | + awareness |
| 124 | + ? yCursorPlugin(awareness, { |
130 | 125 | selectionBuilder: defaultSelectionBuilder, |
131 | 126 | cursorBuilder(user: CollaborationUser, clientID: number) { |
132 | 127 | let cursorData = recentlyUpdatedCursors.get(clientID); |
@@ -177,7 +172,7 @@ export const YCursorExtension = createExtension( |
177 | 172 | ].filter(Boolean), |
178 | 173 | dependsOn: ["ySync"], |
179 | 174 | updateUser(user: { name: string; color: string; [key: string]: string }) { |
180 | | - options.provider.awareness.setLocalStateField("user", user); |
| 175 | + awareness?.setLocalStateField("user", user); |
181 | 176 | }, |
182 | 177 | } as const; |
183 | 178 | }, |
|
0 commit comments