nl_tokens: Adds support for Press This / Reblog .
pl_tokens: function handlePressThis ( calypsoPort ) { calypsoPort . addEventListener ( 'message' , onPressThis , false ) ; calypsoPort . start ( ) ; function onPressThis ( message ) { const action = get ( message , 'data.action' ) ; const payload = get ( message , 'data.payload' ) ; if ( action !== 'pressThis' || ! payload ) { return ; } calypsoPort . removeEventListener ( 'message' , onPressThis , false ) ; const unsubscribe = subscribe ( ( ) => { // Calypso sends the message as soon as the iframe is loaded, so we // need to be sure that the editor is initialized and the core blocks // registered. There is no specific hook or selector for that, so we use // `isCleanNewPost` which is triggered when everything is initialized if // the post is new. const isCleanNewPost = select ( 'core/editor' ) . isCleanNewPost ( ) ; if ( ! isCleanNewPost ) { return ; } unsubscribe ( ) ; const title = get ( payload , 'title' ) ; const text = get ( payload , 'text' ) ; const url = get ( payload , 'url' ) ; const image = get ( payload , 'image' ) ; const embed = get ( payload , 'embed' ) ; const link = ` ${ url } ${ <mask> } ` ; const blocks = [ ] ; if ( embed ) { blocks . push ( createBlock ( 'core/embed' , { url : embed } ) ) ; } if ( image ) { blocks . push ( createBlock ( 'core/image' , { url : image , caption : text ? '' : link , } ) ) ; } if ( text ) { blocks . push ( createBlock ( 'core/quote' , { value : ` ${ text } ` , citation : link , } ) ) ; } dispatch ( 'core/editor' ) . resetBlocks ( blocks ) ; dispatch ( 'core/editor' ) . editPost ( { title : title } ) ; } ) ; } }