@@ -23,7 +23,7 @@ import { findWrapping } from 'prosemirror-transform'
23
23
import { schema as complexSchema } from './complexSchema.js'
24
24
import * as promise from 'lib0/promise'
25
25
26
- const schema = /** @type {any } */ ( basicSchema . schema )
26
+ const schema = /** @type {import('prosemirror-model').Schema } */ ( basicSchema . schema )
27
27
28
28
/**
29
29
* Verify that update events in plugins are only fired once.
@@ -452,6 +452,30 @@ export const testAddToHistoryIgnore = (_tc) => {
452
452
)
453
453
}
454
454
455
+ /**
456
+ * @param {t.TestCase } tc
457
+ */
458
+ export const testMarksOnNodes = ( _tc ) => {
459
+ const view = createNewProsemirrorView ( new Y . Doc ( ) )
460
+ view . dispatch (
461
+ view . state . tr . insert (
462
+ 0 ,
463
+ /** @type {any } */ ( schema . node ( 'image' , { src : 'http://example.com' , alt : null , title : null } , [ ] , [ schema . mark ( 'link' , { href : 'https://yjs.dev' , title : null } ) ] ) )
464
+ )
465
+ )
466
+ // convert to JSON and back because the ProseMirror schema messes with the constructors
467
+ const stateJSON = JSON . parse ( JSON . stringify ( view . state . doc . toJSON ( ) ) )
468
+ // test if transforming back and forth from Yjs doc works
469
+ const backandforth = JSON . parse ( JSON . stringify ( yDocToProsemirrorJSON (
470
+ prosemirrorJSONToYDoc ( /** @type {any } */ ( schema ) , stateJSON )
471
+ ) ) )
472
+ // Add the missing alt and title attributes, these are defaults for the image mark
473
+ backandforth . content [ 0 ] . content [ 0 ] . attrs . alt = null
474
+ backandforth . content [ 0 ] . content [ 0 ] . attrs . title = null
475
+
476
+ t . compare ( stateJSON , backandforth , 'marks on nodes are preserved' )
477
+ }
478
+
455
479
const createNewProsemirrorViewWithSchema = ( y , schema , undoManager = false ) => {
456
480
const view = new EditorView ( null , {
457
481
// @ts -ignore
0 commit comments