@@ -34,6 +34,37 @@ basic.spec.nodes = basic.spec.nodes.update("image", {
3434 inline : false ,
3535} ) ;
3636
37+ basic . spec . nodes = basic . spec . nodes . update ( "card_deck" , {
38+ group : "block" ,
39+ content : "card+" ,
40+ toDOM ( ) {
41+ return [ "div" , { "data-node-type" : "card_deck" } , 0 ] ;
42+ } ,
43+ parseDOM : [
44+ {
45+ tag : 'div[data-node-type="card_deck"]' ,
46+ } ,
47+ ] ,
48+ } ) ;
49+
50+ basic . spec . nodes = basic . spec . nodes . update ( "card" , {
51+ content : "paragraph+" ,
52+ toDOM ( ) {
53+ return [ "div" , { "data-node-type" : "card" } , 0 ] ;
54+ } ,
55+ parseDOM : [
56+ {
57+ tag : 'div[data-node-type="card"]' ,
58+ } ,
59+ ] ,
60+ pitterPatter : {
61+ shuffle : {
62+ containedBy : "card_deck" ,
63+ draggable : true ,
64+ } ,
65+ } ,
66+ } ) ;
67+
3768let nodes = basic . spec . nodes . update ( "paragraph" , {
3869 ...basic . spec . nodes . get ( "paragraph" ) ,
3970 toDOM ( ) {
@@ -63,6 +94,23 @@ const doc = schema.nodes.doc.create(null, [
6394 src : "https://t4.ftcdn.net/jpg/02/71/88/53/360_F_271885326_Jkc8UkWTYmgB3dJjhrot2QZEiLneCaaM.jpg" ,
6495 } ) ,
6596 schema . nodes . paragraph . create ( null , schema . text ( "Another paragraph not in a row." ) ) ,
97+ schema . nodes . card_deck . create ( { shuffleStart : 2 , shuffleEnd : 11 } , [
98+ schema . nodes . card . create ( null , [
99+ schema . nodes . paragraph . create ( null , [
100+ schema . text ( "You can configure containment on node types, too." ) ,
101+ ] ) ,
102+ ] ) ,
103+ schema . nodes . card . create ( null , [
104+ schema . nodes . paragraph . create ( null , [
105+ schema . text ( "These cards can be dragged around within their deck…" ) ,
106+ ] ) ,
107+ ] ) ,
108+ schema . nodes . card . create ( null , [
109+ schema . nodes . paragraph . create ( null , [
110+ schema . text ( "…but they can't be dropped outside of it!" ) ,
111+ ] ) ,
112+ ] ) ,
113+ ] ) ,
66114] ) ;
67115
68116function Image ( { nodeProps, ref, children : _ , ...props } : NodeViewComponentProps ) {
@@ -81,6 +129,8 @@ function Image({ nodeProps, ref, children: _, ...props }: NodeViewComponentProps
81129
82130const nodeViewComponents = {
83131 image : Image ,
132+ card_deck : CardDeck ,
133+ card : Card ,
84134} ;
85135
86136function hoverDecorations ( from : number , to : number ) {
@@ -111,3 +161,24 @@ export function ShuffleDemo() {
111161 </ ProseMirror >
112162 ) ;
113163}
164+
165+ function CardDeck ( { nodeProps : _ , ref, children, ...props } : NodeViewComponentProps ) {
166+ return (
167+ < div
168+ ref = { ref }
169+ { ...props }
170+ className = { `card-deck ${ props . className ?? "" } ` }
171+ data-node-type = "card_deck"
172+ >
173+ { children }
174+ </ div >
175+ ) ;
176+ }
177+
178+ function Card ( { nodeProps : _ , ref, children, ...props } : NodeViewComponentProps ) {
179+ return (
180+ < div ref = { ref } { ...props } className = { `card ${ props . className ?? "" } ` } data-node-type = "card" >
181+ { children }
182+ </ div >
183+ ) ;
184+ }
0 commit comments