2
2
import {
3
3
EditorState ,
4
4
EditorView ,
5
- DOMParser ,
6
5
Schema ,
7
6
baseSchema ,
8
7
history ,
@@ -25,15 +24,13 @@ import {
25
24
yUndoPlugin ,
26
25
yUndo ,
27
26
yRedo ,
28
- prosemirrorToYXmlFragment ,
29
27
} from 'da-y-wrapper' ;
30
28
31
29
// DA
32
30
import prose2aem from '../../shared/prose2aem.js' ;
33
31
import menu from './plugins/menu.js' ;
34
32
import imageDrop from './plugins/imageDrop.js' ;
35
33
import linkConverter from './plugins/linkConverter.js' ;
36
- import { aem2prose , parse } from '../utils/helpers.js' ;
37
34
import { COLLAB_ORIGIN , getDaAdmin } from '../../shared/constants.js' ;
38
35
import { addLocNodes , getLocClass } from './loc-utils.js' ;
39
36
@@ -84,18 +81,6 @@ function pollForUpdates() {
84
81
} , 500 ) ;
85
82
}
86
83
87
- // Apply the document in AEM doc format to the editor.
88
- // For this it's converted to Prose and then applied to the current ydoc as an XML fragment
89
- function setAEMDocInEditor ( aemDoc , yXmlFragment , schema ) {
90
- const doc = parse ( aemDoc ) ;
91
- const pdoc = aem2prose ( doc ) ;
92
- const docc = document . createElement ( 'div' ) ;
93
- docc . append ( ...pdoc ) ;
94
- const parser = DOMParser . fromSchema ( schema ) ;
95
- const fin = parser . parse ( docc ) ;
96
- prosemirrorToYXmlFragment ( fin , yXmlFragment ) ;
97
- }
98
-
99
84
function handleAwarenessUpdates ( wsProvider , daTitle , win ) {
100
85
const users = new Set ( ) ;
101
86
@@ -131,45 +116,12 @@ export function createAwarenessStatusWidget(wsProvider, win) {
131
116
return daTitle ;
132
117
}
133
118
134
- export function handleYDocUpdates ( {
135
- daTitle, editor, ydoc, path, schema, wsProvider, yXmlFragment, fnInitProse,
136
- } , win = window , fnSetAEMDocInEditor = setAEMDocInEditor ) {
137
- let firstUpdate = true ;
138
- ydoc . on ( 'update' , ( _ , originWS ) => {
139
- if ( firstUpdate ) {
140
- firstUpdate = false ;
141
-
142
- // Do the following async to allow the ydoc to init itself with any
143
- // changes coming from other editors
144
- setTimeout ( ( ) => {
145
- const aemMap = ydoc . getMap ( 'aem' ) ;
146
- const current = aemMap . get ( 'content' ) ;
147
- const inital = aemMap . get ( 'initial' ) ;
148
- if ( ! current && inital ) {
149
- fnSetAEMDocInEditor ( inital , yXmlFragment , schema ) ;
150
- }
151
- } , 1 ) ;
152
- }
153
-
154
- const serverInvKey = 'svrinv' ;
155
- const svrUpdate = ydoc . getMap ( 'aem' ) . get ( serverInvKey ) ;
156
- if ( svrUpdate ) {
157
- // push update from the server: re-init document
158
- delete daTitle . collabStatus ;
159
- delete daTitle . collabUsers ;
160
- ydoc . destroy ( ) ;
161
- wsProvider . destroy ( ) ;
162
- editor . innerHTML = '' ;
163
- fnInitProse ( { editor, path } ) ;
164
- return ;
165
- }
166
-
167
- if ( originWS && originWS !== wsProvider ) {
168
- const proseEl = win . view . root . querySelector ( '.ProseMirror' ) ;
169
- const clone = proseEl . cloneNode ( true ) ;
170
- const aem = prose2aem ( clone ) ;
171
- const aemMap = ydoc . getMap ( 'aem' ) ;
172
- aemMap . set ( 'content' , aem ) ;
119
+ function registerErrorHandler ( ydoc ) {
120
+ ydoc . on ( 'update' , ( ) => {
121
+ const errorMap = ydoc . getMap ( 'error' ) ;
122
+ if ( errorMap ) {
123
+ // eslint-disable-next-line no-console
124
+ console . log ( 'Error from server' , JSON . stringify ( ) ) ;
173
125
}
174
126
} ) ;
175
127
}
@@ -209,12 +161,10 @@ export default function initProse({ editor, path }) {
209
161
}
210
162
211
163
const wsProvider = new WebsocketProvider ( server , roomName , ydoc , opts ) ;
212
- const daTitle = createAwarenessStatusWidget ( wsProvider , window ) ;
164
+ createAwarenessStatusWidget ( wsProvider , window ) ;
165
+ registerErrorHandler ( ydoc ) ;
213
166
214
167
const yXmlFragment = ydoc . getXmlFragment ( 'prosemirror' ) ;
215
- handleYDocUpdates ( {
216
- daTitle, editor, ydoc, path, schema, wsProvider, yXmlFragment, fnInitProse : initProse ,
217
- } ) ;
218
168
219
169
if ( window . adobeIMS ?. isSignedInUser ( ) ) {
220
170
window . adobeIMS . getProfile ( ) . then (
@@ -293,4 +243,6 @@ export default function initProse({ editor, path }) {
293
243
294
244
document . execCommand ( 'enableObjectResizing' , false , 'false' ) ;
295
245
document . execCommand ( 'enableInlineTableEditing' , false , 'false' ) ;
246
+
247
+ return wsProvider ;
296
248
}
0 commit comments