@@ -163,148 +163,3 @@ export function createInverseOperation(operation: Operation): Operation {
163163 }
164164 }
165165}
166-
167- export function operationToCollaborativePayload ( operation : Operation ) : {
168- operation : string
169- target : string
170- payload : Record < string , unknown >
171- } {
172- switch ( operation . type ) {
173- case 'batch-add-blocks' : {
174- const op = operation as BatchAddBlocksOperation
175- return {
176- operation : 'batch-add-blocks' ,
177- target : 'blocks' ,
178- payload : {
179- blocks : op . data . blockSnapshots ,
180- edges : op . data . edgeSnapshots ,
181- loops : { } ,
182- parallels : { } ,
183- subBlockValues : op . data . subBlockValues ,
184- } ,
185- }
186- }
187-
188- case 'batch-remove-blocks' : {
189- const op = operation as BatchRemoveBlocksOperation
190- return {
191- operation : 'batch-remove-blocks' ,
192- target : 'blocks' ,
193- payload : { ids : op . data . blockSnapshots . map ( ( b ) => b . id ) } ,
194- }
195- }
196-
197- case 'add-edge' :
198- return {
199- operation : 'add' ,
200- target : 'edge' ,
201- payload : { id : operation . data . edgeId } ,
202- }
203-
204- case 'batch-add-edges' : {
205- const op = operation as BatchAddEdgesOperation
206- return {
207- operation : 'batch-add-edges' ,
208- target : 'edges' ,
209- payload : {
210- edges : op . data . edgeSnapshots . map ( ( e ) => ( {
211- id : e . id ,
212- source : e . source ,
213- target : e . target ,
214- sourceHandle : e . sourceHandle ?? null ,
215- targetHandle : e . targetHandle ?? null ,
216- } ) ) ,
217- } ,
218- }
219- }
220-
221- case 'batch-remove-edges' : {
222- const op = operation as BatchRemoveEdgesOperation
223- return {
224- operation : 'batch-remove-edges' ,
225- target : 'edges' ,
226- payload : { ids : op . data . edgeSnapshots . map ( ( e ) => e . id ) } ,
227- }
228- }
229-
230- case 'batch-move-blocks' : {
231- const op = operation as BatchMoveBlocksOperation
232- return {
233- operation : 'batch-update-positions' ,
234- target : 'blocks' ,
235- payload : {
236- moves : op . data . moves . map ( ( m ) => ( {
237- id : m . blockId ,
238- x : m . after . x ,
239- y : m . after . y ,
240- parentId : m . after . parentId ,
241- } ) ) ,
242- } ,
243- }
244- }
245-
246- case 'update-parent' :
247- return {
248- operation : 'update-parent' ,
249- target : 'block' ,
250- payload : {
251- id : operation . data . blockId ,
252- parentId : operation . data . newParentId ,
253- x : operation . data . newPosition . x ,
254- y : operation . data . newPosition . y ,
255- } ,
256- }
257-
258- case 'apply-diff' :
259- return {
260- operation : 'apply-diff' ,
261- target : 'workflow' ,
262- payload : {
263- diffAnalysis : operation . data . diffAnalysis ,
264- } ,
265- }
266-
267- case 'accept-diff' :
268- return {
269- operation : 'accept-diff' ,
270- target : 'workflow' ,
271- payload : {
272- diffAnalysis : operation . data . diffAnalysis ,
273- } ,
274- }
275-
276- case 'reject-diff' :
277- return {
278- operation : 'reject-diff' ,
279- target : 'workflow' ,
280- payload : {
281- diffAnalysis : operation . data . diffAnalysis ,
282- } ,
283- }
284-
285- case 'batch-toggle-enabled' :
286- return {
287- operation : 'batch-toggle-enabled' ,
288- target : 'blocks' ,
289- payload : {
290- blockIds : operation . data . blockIds ,
291- previousStates : operation . data . previousStates ,
292- } ,
293- }
294-
295- case 'batch-toggle-handles' :
296- return {
297- operation : 'batch-toggle-handles' ,
298- target : 'blocks' ,
299- payload : {
300- blockIds : operation . data . blockIds ,
301- previousStates : operation . data . previousStates ,
302- } ,
303- }
304-
305- default : {
306- const exhaustiveCheck : never = operation
307- throw new Error ( `Unhandled operation type: ${ ( exhaustiveCheck as Operation ) . type } ` )
308- }
309- }
310- }
0 commit comments