@@ -3,7 +3,7 @@ import { Editor, UI } from './mobiledoc.js'
33const card = {
44 name : 'image' ,
55 type : 'dom' ,
6- render ( { env, opts , payload } ) {
6+ render ( { env, payload } ) {
77 const el = document . createElement ( 'div' )
88 const img = document . createElement ( 'img' )
99 const caption = document . createElement ( 'figcaption' )
@@ -17,7 +17,7 @@ const card = {
1717 el . appendChild ( button )
1818 return el
1919 } ,
20- edit ( { env, opts , payload } ) {
20+ edit ( { env, payload } ) {
2121 const el = document . createElement ( 'div' )
2222 const img = document . createElement ( 'img' )
2323 const button = document . createElement ( 'button' )
@@ -64,14 +64,20 @@ function activateButtons(parentSelector, editor) {
6464 button . addEventListener ( 'click' , ( ) => {
6565 const action = button . getAttribute ( 'data-action' )
6666 const args = button . getAttribute ( 'data-args' ) . split ( ',' )
67- const payload = ( function ( ) {
68- try {
69- return JSON . parse ( button . getAttribute ( 'data-payload' ) )
70- } catch { }
71- } ) ( )
72- if ( args [ 0 ] === 'a' ) UI [ action ] ( editor )
73- else if ( payload ) editor [ action ] ( ...args , payload )
74- else editor [ action ] ( ...args )
67+ if ( args [ 0 ] === 'a' ) {
68+ UI [ action ] ( editor )
69+ } else if ( action === 'insertCard' ) {
70+ args [ 1 ] = JSON . parse ( args [ 1 ] )
71+ editor [ action ] ( ...args )
72+ // Insert a blank paragraph section after card to continue typing
73+ editor . run ( postEditor => {
74+ const section = postEditor . builder . createMarkupSection ( )
75+ postEditor . insertSectionBefore ( editor . post . sections , section , editor . activeSection . next )
76+ postEditor . setRange ( section . toRange ( ) )
77+ } )
78+ } else {
79+ editor [ action ] ( ...args )
80+ }
7581 } )
7682 )
7783}
@@ -98,7 +104,7 @@ function bootstrapEditor() {
98104 const activeSectionTags = editor . activeSections . map ( s => ( s . isNested ? s . parent . tagName : s . tagName ) )
99105 const activeAttributeVals = editor . activeSections . map ( s => Object . values ( s . attributes || { } ) )
100106 const allActive = [ ...activeMarkupTags , ...activeSectionTags , ...activeAttributeVals ]
101- const selector = allActive . map ( arg => `[data-args*=" ${ arg } "]` ) . join ( ',' )
107+ const selector = allActive . map ( arg => `[data-args=" ${ arg } "],[data-args="text-align, ${ arg } "]` ) . join ( ',' )
102108 document . querySelectorAll ( `[data-args]` ) . forEach ( el => el . classList . remove ( 'active' ) )
103109 selector && document . querySelectorAll ( selector ) . forEach ( el => el . classList . add ( 'active' ) )
104110 } )
0 commit comments