@kerebron/yjs 0.0.0-stage → 0.9.2

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.
Files changed (88) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +4 -2
  3. package/esm/ExtensionYjs.d.ts +19 -0
  4. package/esm/ExtensionYjs.js +144 -0
  5. package/esm/ExtensionYjs.js.map +1 -0
  6. package/esm/MarkYChange.d.ts +6 -0
  7. package/esm/MarkYChange.js +21 -0
  8. package/esm/MarkYChange.js.map +1 -0
  9. package/esm/WebsocketProvider.d.ts +69 -0
  10. package/esm/WebsocketProvider.js +377 -0
  11. package/esm/WebsocketProvider.js.map +1 -0
  12. package/esm/YjsEditorKit.d.ts +10 -0
  13. package/esm/YjsEditorKit.js +44 -0
  14. package/esm/YjsEditorKit.js.map +1 -0
  15. package/esm/YjsProvider.d.ts +47 -0
  16. package/esm/YjsProvider.js +12 -0
  17. package/esm/YjsProvider.js.map +1 -0
  18. package/esm/binding/BindingMetadata.d.ts +5 -0
  19. package/esm/binding/BindingMetadata.js +2 -0
  20. package/esm/binding/BindingMetadata.js.map +1 -0
  21. package/esm/binding/DiffViewer.d.ts +16 -0
  22. package/esm/binding/DiffViewer.js +95 -0
  23. package/esm/binding/DiffViewer.js.map +1 -0
  24. package/esm/binding/PmYjsBinding.d.ts +46 -0
  25. package/esm/binding/PmYjsBinding.js +246 -0
  26. package/esm/binding/PmYjsBinding.js.map +1 -0
  27. package/esm/binding/convertUtils.d.ts +47 -0
  28. package/esm/binding/convertUtils.js +80 -0
  29. package/esm/binding/convertUtils.js.map +1 -0
  30. package/esm/binding/createNodeFromYElement.d.ts +9 -0
  31. package/esm/binding/createNodeFromYElement.js +123 -0
  32. package/esm/binding/createNodeFromYElement.js.map +1 -0
  33. package/esm/binding/updateYFragment.d.ts +16 -0
  34. package/esm/binding/updateYFragment.js +337 -0
  35. package/esm/binding/updateYFragment.js.map +1 -0
  36. package/esm/debug.d.ts +12 -0
  37. package/esm/debug.js +158 -0
  38. package/esm/debug.js.map +1 -0
  39. package/esm/keys.d.ts +7 -0
  40. package/esm/keys.js +5 -0
  41. package/esm/keys.js.map +1 -0
  42. package/esm/lib.d.ts +7 -0
  43. package/esm/lib.js +2 -0
  44. package/esm/lib.js.map +1 -0
  45. package/esm/package.json +3 -0
  46. package/esm/position.d.ts +7 -0
  47. package/esm/position.js +165 -0
  48. package/esm/position.js.map +1 -0
  49. package/esm/ui/RoomController.d.ts +16 -0
  50. package/esm/ui/RoomController.js +115 -0
  51. package/esm/ui/RoomController.js.map +1 -0
  52. package/esm/ui/selection.d.ts +28 -0
  53. package/esm/ui/selection.js +128 -0
  54. package/esm/ui/selection.js.map +1 -0
  55. package/esm/utils.d.ts +3 -0
  56. package/esm/utils.js +15 -0
  57. package/esm/utils.js.map +1 -0
  58. package/esm/yPositionPlugin.d.ts +26 -0
  59. package/esm/yPositionPlugin.js +216 -0
  60. package/esm/yPositionPlugin.js.map +1 -0
  61. package/esm/ySyncPlugin.d.ts +22 -0
  62. package/esm/ySyncPlugin.js +140 -0
  63. package/esm/ySyncPlugin.js.map +1 -0
  64. package/esm/yUndoPlugin.d.ts +22 -0
  65. package/esm/yUndoPlugin.js +128 -0
  66. package/esm/yUndoPlugin.js.map +1 -0
  67. package/package.json +53 -3
  68. package/src/ExtensionYjs.ts +204 -0
  69. package/src/MarkYChange.ts +23 -0
  70. package/src/WebsocketProvider.ts +528 -0
  71. package/src/YjsEditorKit.ts +58 -0
  72. package/src/YjsProvider.ts +75 -0
  73. package/src/binding/BindingMetadata.ts +6 -0
  74. package/src/binding/DiffViewer.ts +138 -0
  75. package/src/binding/PmYjsBinding.ts +383 -0
  76. package/src/binding/convertUtils.ts +124 -0
  77. package/src/binding/createNodeFromYElement.ts +175 -0
  78. package/src/binding/updateYFragment.ts +447 -0
  79. package/src/debug.ts +239 -0
  80. package/src/keys.ts +14 -0
  81. package/src/lib.ts +12 -0
  82. package/src/position.ts +191 -0
  83. package/src/ui/RoomController.ts +131 -0
  84. package/src/ui/selection.ts +217 -0
  85. package/src/utils.ts +19 -0
  86. package/src/yPositionPlugin.ts +351 -0
  87. package/src/ySyncPlugin.ts +211 -0
  88. package/src/yUndoPlugin.ts +175 -0
@@ -0,0 +1,217 @@
1
+ import * as Y from 'yjs';
2
+
3
+ import {
4
+ AllSelection,
5
+ EditorState,
6
+ NodeSelection,
7
+ Selection,
8
+ TextSelection,
9
+ Transaction,
10
+ } from 'prosemirror-state';
11
+
12
+ import { YjsData } from '../binding/PmYjsBinding.js';
13
+ import { ProsemirrorMapping } from '../lib.js';
14
+ import {
15
+ absolutePositionToRelativePosition,
16
+ relativePositionToAbsolutePosition,
17
+ } from '../position.js';
18
+ import { CoreEditor } from '@kerebron/editor';
19
+
20
+ interface TransactionSelection {
21
+ type: string;
22
+ anchor: Y.RelativePosition;
23
+ head: Y.RelativePosition;
24
+ }
25
+
26
+ const restoreRelativeSelection = (
27
+ tr: Transaction,
28
+ relSel: TransactionSelection,
29
+ yjs: YjsData,
30
+ mapping: ProsemirrorMapping,
31
+ ) => {
32
+ const { ydoc, xmlFragment } = yjs;
33
+
34
+ if (relSel.anchor !== null && relSel.head !== null) {
35
+ if (relSel.type === 'all') {
36
+ tr.setSelection(new AllSelection(tr.doc));
37
+ } else if (relSel.type === 'node') {
38
+ const anchor = relativePositionToAbsolutePosition(
39
+ ydoc,
40
+ xmlFragment,
41
+ relSel.anchor,
42
+ mapping,
43
+ );
44
+ if (anchor !== null) {
45
+ tr.setSelection(NodeSelection.create(tr.doc, anchor));
46
+ }
47
+ } else {
48
+ const anchor = relativePositionToAbsolutePosition(
49
+ ydoc,
50
+ xmlFragment,
51
+ relSel.anchor,
52
+ mapping,
53
+ );
54
+ const head = relativePositionToAbsolutePosition(
55
+ ydoc,
56
+ xmlFragment,
57
+ relSel.head,
58
+ mapping,
59
+ );
60
+ if (anchor !== null && head !== null) {
61
+ const sel = TextSelection.between(
62
+ tr.doc.resolve(anchor),
63
+ tr.doc.resolve(head),
64
+ );
65
+ tr.setSelection(sel);
66
+ }
67
+ }
68
+ }
69
+ };
70
+
71
+ export const getRelativeSelection = (
72
+ xmlFragment: Y.XmlFragment,
73
+ mapping: ProsemirrorMapping,
74
+ state: EditorState,
75
+ ): TransactionSelection => ({
76
+ type: getSelectionType(state.selection),
77
+ anchor: absolutePositionToRelativePosition(
78
+ state.selection.anchor,
79
+ xmlFragment,
80
+ mapping,
81
+ ),
82
+ head: absolutePositionToRelativePosition(
83
+ state.selection.head,
84
+ xmlFragment,
85
+ mapping,
86
+ ),
87
+ });
88
+
89
+ function getSelectionType(selection: Selection) {
90
+ if (selection instanceof TextSelection) {
91
+ return 'text';
92
+ }
93
+ if (selection instanceof AllSelection) {
94
+ return 'all';
95
+ }
96
+ if (selection instanceof NodeSelection) {
97
+ return 'node';
98
+ }
99
+ return 'other_selection';
100
+ }
101
+
102
+ export class SelectionStash {
103
+ private readonly beforeAllTransactions: () => void;
104
+ private readonly afterAllTransactions: () => void;
105
+
106
+ private _beforeTransactionSelection: TransactionSelection | null = null;
107
+ private _domSelectionInView: boolean = false;
108
+
109
+ constructor(
110
+ private yjs: YjsData,
111
+ private mapping: ProsemirrorMapping,
112
+ private editor: CoreEditor,
113
+ ) {
114
+ this.beforeAllTransactions = () => {
115
+ if (
116
+ !this._beforeTransactionSelection &&
117
+ editor.view
118
+ ) {
119
+ this._beforeTransactionSelection = getRelativeSelection(
120
+ yjs.xmlFragment,
121
+ mapping,
122
+ editor.state,
123
+ );
124
+ }
125
+ };
126
+ this.afterAllTransactions = () => {
127
+ this._beforeTransactionSelection = null;
128
+ };
129
+
130
+ this.yjs.ydoc.on('beforeAllTransactions', this.beforeAllTransactions);
131
+ this.yjs.ydoc.on('afterAllTransactions', this.afterAllTransactions);
132
+ }
133
+
134
+ destroy() {
135
+ this.yjs.ydoc.off('beforeAllTransactions', this.beforeAllTransactions);
136
+ this.yjs.ydoc.off('afterAllTransactions', this.afterAllTransactions);
137
+ }
138
+
139
+ store() {
140
+ this._beforeTransactionSelection = getRelativeSelection(
141
+ this.yjs.xmlFragment,
142
+ this.mapping,
143
+ this.editor.state,
144
+ );
145
+ }
146
+
147
+ overwrite(transactionSelection: TransactionSelection) {
148
+ this._beforeTransactionSelection = transactionSelection;
149
+ }
150
+
151
+ restore(tr: Transaction) {
152
+ if (this._beforeTransactionSelection) {
153
+ restoreRelativeSelection(
154
+ tr,
155
+ this._beforeTransactionSelection,
156
+ this.yjs,
157
+ this.mapping,
158
+ );
159
+ if (this._isLocalCursorInView()) {
160
+ tr.scrollIntoView();
161
+ }
162
+ }
163
+ }
164
+
165
+ _isLocalCursorInView(): boolean {
166
+ if (!this.editor.view.hasFocus()) return false;
167
+
168
+ // const isNode = /* @__PURE__ */(() => typeof process !== 'undefined' && process.release && /node|io\.js/.test(process.release.name) && Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]')()
169
+ const isBrowser =
170
+ /* @__PURE__ */ (() =>
171
+ typeof window !== 'undefined' && typeof document !== 'undefined')(); // && !isNode
172
+
173
+ if (isBrowser && this._domSelectionInView === false) {
174
+ // Calculate the domSelectionInView and clear by next tick after all events are finished
175
+ setTimeout(() => {
176
+ this._domSelectionInView = false;
177
+ }, 0);
178
+ this._domSelectionInView = this._isDomSelectionInView();
179
+ }
180
+ return this._domSelectionInView;
181
+ }
182
+
183
+ _isDomSelectionInView(): boolean {
184
+ const view = this.editor.view;
185
+ if (!('root' in view)) {
186
+ return false;
187
+ }
188
+ const selection = document.getSelection();
189
+
190
+ if (
191
+ !selection || selection.anchorNode == null || selection.focusNode == null
192
+ ) return false;
193
+
194
+ const range = document.createRange();
195
+ range.setStart(selection.anchorNode, selection.anchorOffset);
196
+ range.setEnd(selection.focusNode, selection.focusOffset);
197
+
198
+ // This is a workaround for an edgecase where getBoundingClientRect will
199
+ // return zero values if the selection is collapsed at the start of a newline
200
+ // see reference here: https://stackoverflow.com/a/59780954
201
+ const rects = range.getClientRects();
202
+ if (rects.length === 0) {
203
+ // probably buggy newline behavior, explicitly select the node contents
204
+ if (range.startContainer && range.collapsed) {
205
+ range.selectNodeContents(range.startContainer);
206
+ }
207
+ }
208
+
209
+ const bounding = range.getBoundingClientRect();
210
+ const documentElement = document.documentElement;
211
+
212
+ return bounding.bottom >= 0 && bounding.right >= 0 &&
213
+ bounding.left <=
214
+ (window.innerWidth || documentElement.clientWidth || 0) &&
215
+ bounding.top <= (window.innerHeight || documentElement.clientHeight || 0);
216
+ }
217
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,19 @@
1
+ import * as Y from 'yjs';
2
+ import * as sha256 from 'lib0/hash/sha256';
3
+ import * as buf from 'lib0/buffer';
4
+
5
+ const _convolute = (digest: Uint8Array) => {
6
+ const N = 6;
7
+ for (let i = N; i < digest.length; i++) {
8
+ digest[i % N] = digest[i % N] ^ digest[i];
9
+ }
10
+ return digest.slice(0, N);
11
+ };
12
+
13
+ export const hashOfJSON = (json: any) =>
14
+ buf.toBase64(_convolute(sha256.digest(buf.encodeAny(json))));
15
+
16
+ export const isVisible = (item: Y.Item, snapshot?: Y.Snapshot) =>
17
+ snapshot === undefined ? !item.deleted : (snapshot.sv.has(item.id.client) &&
18
+ (snapshot.sv.get(item.id.client)!) > item.id.clock &&
19
+ !Y.isDeleted(snapshot.ds, item.id));
@@ -0,0 +1,351 @@
1
+ import { Awareness } from 'y-protocols/awareness';
2
+ import * as Y from 'yjs';
3
+
4
+ import { EditorState, Plugin, Transaction } from 'prosemirror-state';
5
+ import { EditorView } from 'prosemirror-view';
6
+
7
+ import type { CoreEditor } from '@kerebron/editor';
8
+ import {
9
+ type ColorMapper,
10
+ defaultColorMapper,
11
+ generateBlankUser,
12
+ type User,
13
+ } from '@kerebron/editor/user';
14
+ import type { SelectionState } from '@kerebron/extension-basic-editor/ExtensionRemoteSelection';
15
+
16
+ import { yPositionPluginKey, ySyncPluginKey } from './keys.js';
17
+ import {
18
+ absolutePositionToRelativePosition,
19
+ relativePositionToAbsolutePosition,
20
+ } from './position.js';
21
+ import type { YSyncPluginState } from './ySyncPlugin.js';
22
+
23
+ /**
24
+ * Is null if no timeout is in progress.
25
+ * Is defined if a timeout is in progress.
26
+ * Maps from view
27
+ */
28
+ let viewsToUpdate: Map<EditorView, Map<any, any>> | null = null;
29
+
30
+ const updateMetas = () => {
31
+ const ups: Map<EditorView, Map<any, any>> | null = viewsToUpdate;
32
+ viewsToUpdate = null;
33
+ if (!ups) {
34
+ return;
35
+ }
36
+ ups.forEach((metas, view) => {
37
+ const tr = view.state.tr;
38
+ const syncState = ySyncPluginKey.getState(view.state);
39
+ if (syncState && syncState.binding) { // && !syncState.binding.isDestroyed
40
+ metas.forEach((val, key) => {
41
+ tr.setMeta(key, val);
42
+ });
43
+ view.dispatch(tr);
44
+ }
45
+ });
46
+ };
47
+
48
+ type AwarenessListener = (
49
+ { added, updated, removed }: {
50
+ added: number[];
51
+ updated: number[];
52
+ removed: number[];
53
+ },
54
+ s: any,
55
+ t: any,
56
+ ) => void;
57
+
58
+ interface PositionPluginConfig {
59
+ getSelection?: (arg0: any) => any;
60
+ }
61
+
62
+ export interface YPositionPluginState {
63
+ awareness?: Awareness;
64
+ awarenessListener?: AwarenessListener;
65
+ cursorStateField: string;
66
+ userStateField: string;
67
+ me: User;
68
+ colorMapper: ColorMapper;
69
+ }
70
+
71
+ function destroyAwareness(
72
+ pluginState: YPositionPluginState,
73
+ ) {
74
+ if (!pluginState.awareness) {
75
+ return;
76
+ }
77
+ const awareness = pluginState.awareness;
78
+ if (pluginState.awarenessListener) {
79
+ awareness.off('change', pluginState.awarenessListener);
80
+ }
81
+ awareness.setLocalStateField(pluginState.cursorStateField, null);
82
+ pluginState.awareness = undefined;
83
+ }
84
+
85
+ function initAwareness(state: YPositionPluginState, editor: CoreEditor) {
86
+ if (!state.awareness) {
87
+ return;
88
+ }
89
+ const awareness = state.awareness;
90
+ const view = editor.view as EditorView;
91
+
92
+ state.awarenessListener = (
93
+ { added, updated, removed },
94
+ ) => {
95
+ const ystate: YSyncPluginState = ySyncPluginKey.getState(view.state)!;
96
+ if (!ystate.binding) {
97
+ return;
98
+ }
99
+ const yjs = ystate.binding.getYjs();
100
+ if (!yjs) {
101
+ return;
102
+ }
103
+
104
+ const clients = added.concat(updated).concat(removed);
105
+ if (
106
+ clients.findIndex((id: number) => id !== awareness.doc.clientID) ===
107
+ -1
108
+ ) {
109
+ return;
110
+ }
111
+
112
+ const { ydoc, xmlFragment } = yjs;
113
+ const remoteStates: SelectionState[] = [];
114
+ awareness.getStates().forEach((aw, clientId) => {
115
+ if (!defaultAwarenessStateFilter(ydoc.clientID, clientId, aw)) {
116
+ return;
117
+ }
118
+
119
+ const cursor = aw[state.cursorStateField];
120
+ const user: User | undefined = aw[state.userStateField];
121
+
122
+ if (!cursor || !user) {
123
+ return;
124
+ }
125
+
126
+ const anchor = relativePositionToAbsolutePosition(
127
+ ydoc,
128
+ xmlFragment,
129
+ Y.createRelativePositionFromJSON(cursor.anchor),
130
+ ystate.binding.getMapping(),
131
+ );
132
+ const head = relativePositionToAbsolutePosition(
133
+ ydoc,
134
+ xmlFragment,
135
+ Y.createRelativePositionFromJSON(cursor.head),
136
+ ystate.binding.getMapping(),
137
+ );
138
+
139
+ if (anchor !== null && head !== null) {
140
+ remoteStates.push({
141
+ clientId,
142
+ user: user,
143
+ cursor: {
144
+ anchor,
145
+ head,
146
+ },
147
+ });
148
+ }
149
+ });
150
+
151
+ const tr = editor.state.tr;
152
+ tr.setMeta('remoteSelectionChange', { remoteStates });
153
+ editor.dispatchTransaction(tr);
154
+ };
155
+
156
+ awareness.on('change', state.awarenessListener);
157
+ }
158
+
159
+ /**
160
+ * Default awareness state filter
161
+ */
162
+ export const defaultAwarenessStateFilter = (
163
+ currentClientId: number,
164
+ userClientId: number,
165
+ _user: any,
166
+ ): boolean => currentClientId !== userClientId;
167
+
168
+ export const yPositionPlugin = (
169
+ editor: CoreEditor,
170
+ {
171
+ getSelection = (state: EditorState) => state.selection,
172
+ }: PositionPluginConfig = {},
173
+ ) => {
174
+ return new Plugin<YPositionPluginState>({
175
+ key: yPositionPluginKey,
176
+ state: {
177
+ init: (): YPositionPluginState => {
178
+ return {
179
+ awareness: undefined,
180
+ cursorStateField: 'kerebron:cursor',
181
+ userStateField: 'kerebron:user',
182
+ me: generateBlankUser(),
183
+ colorMapper: defaultColorMapper,
184
+ };
185
+ },
186
+ apply: (tr: Transaction, pluginState: YPositionPluginState) => {
187
+ const changeUser = tr.getMeta('changeUser');
188
+ if (changeUser) {
189
+ pluginState.me = { ...changeUser.user };
190
+ }
191
+ const setColorMapper = tr.getMeta('setColorMapper');
192
+ if (setColorMapper) {
193
+ pluginState.colorMapper = setColorMapper.colorMapper;
194
+ }
195
+
196
+ const awareness = tr.getMeta('yjs:setAwareness');
197
+ if (awareness) {
198
+ if (pluginState.awareness) {
199
+ destroyAwareness(pluginState);
200
+ }
201
+ pluginState.awareness = awareness;
202
+ if (pluginState.awareness) {
203
+ initAwareness(pluginState, editor);
204
+ }
205
+ }
206
+
207
+ if (tr.getMeta('yjs:removeAwareness')) {
208
+ if (pluginState.awareness) {
209
+ destroyAwareness(pluginState);
210
+ }
211
+ }
212
+ return pluginState;
213
+ },
214
+ },
215
+ view: (view: EditorView) => {
216
+ const updateAwareness = (
217
+ selectionAnchor: number,
218
+ selectionHead: number,
219
+ ) => {
220
+ const state: YPositionPluginState = yPositionPluginKey.getState(
221
+ view.state,
222
+ )!;
223
+ if (!state.awareness) {
224
+ return;
225
+ }
226
+ const awareness = state.awareness;
227
+ const current = awareness.getLocalState() || {};
228
+
229
+ const ystate: YSyncPluginState = ySyncPluginKey.getState(view.state)!;
230
+ const yjs = ystate.binding.getYjs();
231
+ if (!yjs) {
232
+ return;
233
+ }
234
+ const { xmlFragment } = yjs;
235
+
236
+ const anchor: Y.RelativePosition = absolutePositionToRelativePosition(
237
+ selectionAnchor,
238
+ xmlFragment,
239
+ ystate.binding.getMapping(),
240
+ );
241
+ const head: Y.RelativePosition = absolutePositionToRelativePosition(
242
+ selectionHead,
243
+ xmlFragment,
244
+ ystate.binding.getMapping(),
245
+ );
246
+
247
+ const cursor = current[state.cursorStateField];
248
+
249
+ if (
250
+ cursor == null ||
251
+ !Y.compareRelativePositions(
252
+ Y.createRelativePositionFromJSON(cursor.anchor),
253
+ anchor,
254
+ ) ||
255
+ !Y.compareRelativePositions(
256
+ Y.createRelativePositionFromJSON(cursor.head),
257
+ head,
258
+ )
259
+ ) {
260
+ awareness.setLocalStateField(state.cursorStateField, {
261
+ anchor,
262
+ head,
263
+ });
264
+ }
265
+ };
266
+
267
+ const clearAwareness = () => {
268
+ const state: YPositionPluginState = yPositionPluginKey.getState(
269
+ view.state,
270
+ )!;
271
+ if (!state.awareness) {
272
+ return;
273
+ }
274
+
275
+ const ystate: YSyncPluginState = ySyncPluginKey.getState(view.state)!;
276
+ const yjs = ystate.binding.getYjs();
277
+ if (!yjs) {
278
+ return;
279
+ }
280
+
281
+ const awareness = state.awareness;
282
+ const current = awareness.getLocalState() || {};
283
+
284
+ const { ydoc, xmlFragment } = yjs;
285
+
286
+ const cursor = current[state.cursorStateField];
287
+
288
+ if (
289
+ cursor &&
290
+ relativePositionToAbsolutePosition(
291
+ ydoc,
292
+ xmlFragment,
293
+ Y.createRelativePositionFromJSON(cursor.anchor),
294
+ ystate.binding.getMapping(),
295
+ ) !== null
296
+ ) {
297
+ // delete cursor information if current cursor information is owned by this editor binding
298
+ awareness.setLocalStateField(state.cursorStateField, null);
299
+ }
300
+ };
301
+
302
+ const updateCursorInfo = () => {
303
+ if (view.hasFocus()) {
304
+ const selection = getSelection(view.state);
305
+ updateAwareness(selection.anchor, selection.head);
306
+ } else {
307
+ // clearAwareness();
308
+ }
309
+ };
310
+
311
+ const localPositionChangedListener = (event: Event) => {
312
+ if ('detail' in event) {
313
+ const { detail } = event as CustomEvent;
314
+ updateAwareness(detail.anchor, detail.head);
315
+ }
316
+ };
317
+
318
+ editor.addEventListener(
319
+ 'localPositionChanged',
320
+ localPositionChangedListener,
321
+ );
322
+
323
+ view.dom.addEventListener('focusin', updateCursorInfo);
324
+ view.dom.addEventListener('focusout', updateCursorInfo);
325
+
326
+ return {
327
+ update: updateCursorInfo,
328
+ destroy: () => {
329
+ view.dom.removeEventListener('focusin', updateCursorInfo);
330
+ view.dom.removeEventListener('focusout', updateCursorInfo);
331
+
332
+ const pluginState: YPositionPluginState | undefined =
333
+ yPositionPluginKey.getState(
334
+ view.state,
335
+ );
336
+ if (pluginState) {
337
+ destroyAwareness(pluginState);
338
+ }
339
+
340
+ editor.removeEventListener(
341
+ 'localPositionChanged',
342
+ localPositionChangedListener,
343
+ );
344
+ },
345
+ };
346
+ },
347
+ updateCursorInfo(state: EditorState) {
348
+ throw new Error('TODO: merge with updateCursorInfo above');
349
+ },
350
+ });
351
+ };