1- import { Inline , Attribute } from 'prosemirror/dist/model' ;
1+ import { Inline , Block , Attribute } from 'prosemirror/dist/model' ;
22import MarkdownVideoPlugin from 'markdown-it-video' ;
33import ExecutionEnvironment from 'exenv' ;
4+ import { videoUrlParser } from './video-url' ;
45
56
67let Dropdown = function ( ) { }
@@ -13,16 +14,20 @@ if (ExecutionEnvironment.canUseDOM) {
1314}
1415
1516
16- export class VideoEmbed extends Inline {
17+
18+
19+ export class VideoEmbed extends Block {
1720 // Not sure what this is for other than tagging
1821 get attrs ( ) {
1922 return {
23+ // url: new Attribute({label: 'video url'}),
2024 videoId : new Attribute ( { label : 'video id' } ) ,
2125 service : new Attribute ( { label : 'hosting service' } ) ,
2226 width : new Attribute ( { label : 'embed width' , default : 320 } ) ,
2327 height : new Attribute ( { label : 'embed height' , default : 240 } ) ,
2428 }
2529 }
30+ get contains ( ) { return null }
2631}
2732
2833const generateVideoUrl = ( attrs ) => {
@@ -35,22 +40,22 @@ const generateVideoUrl = (attrs) => {
3540 }
3641}
3742
38- const generateTempVideoNode = ( attrs ) => {
43+ const generateTempVideoNode = ( s , attrs ) => {
3944 let { service, videoId} = attrs ;
4045 const videoUrl = generateVideoUrl ( attrs ) ;
4146
42- return elt ( 'span' , {
47+ return s . elt ( 'span' , {
4348 'class' : `prosemirror-video-embed prosemirror-video-embed-${ service } ` ,
4449 'contenteditable' : 'false'
45- } , elt ( 'span' , {
50+ } , s . elt ( 'span' , {
4651 'class' : `prosemirror-video-embed-label`
4752 } , `video at ${ videoUrl } ` ) )
4853} ;
4954
5055VideoEmbed . prototype . serializeMarkdown = ( state , node ) => {
5156 state . write ( `@[${ node . attrs . service } ](${ node . attrs . videoId } )` )
5257}
53- VideoEmbed . prototype . serializeDOM = ( node ) => {
58+ VideoEmbed . prototype . serializeDOM = ( node , serializer ) => {
5459 const { service, videoId} = node . attrs ;
5560 if ( [ 'vimeo' , 'youtube' ] . indexOf ( service . toLowerCase ( ) ) < 0 ) {
5661 return ;
@@ -64,7 +69,7 @@ VideoEmbed.prototype.serializeDOM = (node) => {
6469 // })
6570 // }
6671
67- return generateTempVideoNode ( node . attrs ) ;
72+ return serializer . elt ( 'div' , null , generateTempVideoNode ( serializer , node . attrs ) ) ;
6873}
6974
7075
@@ -86,14 +91,10 @@ VideoEmbed.register("command", "insert", {
8691 } )
8792
8893VideoEmbed . register ( 'parseMarkdown' , 'video' , { parse : function ( state , tok ) {
89- state . addNode ( this , { service : tok . service , videoId : tok . videoID } ) ;
94+ state . addNode ( this , { service : tok . service , videoId : tok . videoID , markup : '<div>' } ) ;
9095} } )
9196
9297
9398VideoEmbed . register ( 'configureMarkdown' , 'video' , parser => {
9499 return parser . use ( MarkdownVideoPlugin ) ;
95100} )
96-
97- // export const dynamicMenu = new Dropdown({label: 'Insert dynamic field'}, new MenuCommandGroup('dynamic'))
98-
99-
0 commit comments