automediaembed.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global setTimeout */
  6. import MediaEmbed from '../src/mediaembed';
  7. import AutoMediaEmbed from '../src/automediaembed';
  8. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  9. import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
  10. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  11. import Link from '@ckeditor/ckeditor5-link/src/link';
  12. import List from '@ckeditor/ckeditor5-list/src/list';
  13. import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
  14. import Undo from '@ckeditor/ckeditor5-undo/src/undo';
  15. import Typing from '@ckeditor/ckeditor5-typing/src/typing';
  16. import Image from '@ckeditor/ckeditor5-image/src/image';
  17. import ImageCaption from '@ckeditor/ckeditor5-image/src/imagecaption';
  18. import global from '@ckeditor/ckeditor5-utils/src/dom/global';
  19. import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  20. describe( 'AutoMediaEmbed - integration', () => {
  21. let editorElement, editor;
  22. beforeEach( () => {
  23. editorElement = global.document.createElement( 'div' );
  24. global.document.body.appendChild( editorElement );
  25. return ClassicTestEditor
  26. .create( editorElement, {
  27. plugins: [ MediaEmbed, AutoMediaEmbed, Link, List, Bold, Typing, Image, ImageCaption ]
  28. } )
  29. .then( newEditor => {
  30. editor = newEditor;
  31. } );
  32. } );
  33. afterEach( () => {
  34. editorElement.remove();
  35. return editor.destroy();
  36. } );
  37. it( 'should load Clipboard plugin', () => {
  38. expect( editor.plugins.get( Clipboard ) ).to.instanceOf( Clipboard );
  39. } );
  40. it( 'should load Undo plugin', () => {
  41. expect( editor.plugins.get( Undo ) ).to.instanceOf( Undo );
  42. } );
  43. it( 'has proper name', () => {
  44. expect( AutoMediaEmbed.pluginName ).to.equal( 'AutoMediaEmbed' );
  45. } );
  46. describe( 'use fake timers', () => {
  47. let clock;
  48. beforeEach( () => {
  49. clock = sinon.useFakeTimers();
  50. } );
  51. afterEach( () => {
  52. clock.restore();
  53. } );
  54. it( 'replaces pasted text with media element after 100ms', () => {
  55. setData( editor.model, '<paragraph>[]</paragraph>' );
  56. pasteHtml( editor, 'https://www.youtube.com/watch?v=H08tGjXNHO4' );
  57. expect( getData( editor.model ) ).to.equal(
  58. '<paragraph>https://www.youtube.com/watch?v=H08tGjXNHO4[]</paragraph>'
  59. );
  60. clock.tick( 100 );
  61. expect( getData( editor.model ) ).to.equal(
  62. '[<media url="https://www.youtube.com/watch?v=H08tGjXNHO4"></media>]'
  63. );
  64. } );
  65. it( 'can undo auto-embeding', () => {
  66. setData( editor.model, '<paragraph>[]</paragraph>' );
  67. pasteHtml( editor, 'https://www.youtube.com/watch?v=H08tGjXNHO4' );
  68. expect( getData( editor.model ) ).to.equal(
  69. '<paragraph>https://www.youtube.com/watch?v=H08tGjXNHO4[]</paragraph>'
  70. );
  71. clock.tick( 100 );
  72. editor.commands.execute( 'undo' );
  73. expect( getData( editor.model ) ).to.equal(
  74. '<paragraph>https://www.youtube.com/watch?v=H08tGjXNHO4[]</paragraph>'
  75. );
  76. } );
  77. it( 'works for a full URL (https + "www" sub-domain)', () => {
  78. setData( editor.model, '<paragraph>[]</paragraph>' );
  79. pasteHtml( editor, 'https://www.youtube.com/watch?v=H08tGjXNHO4' );
  80. clock.tick( 100 );
  81. expect( getData( editor.model ) ).to.equal(
  82. '[<media url="https://www.youtube.com/watch?v=H08tGjXNHO4"></media>]'
  83. );
  84. } );
  85. it( 'works for a full URL (https without "wwww" sub-domain)', () => {
  86. setData( editor.model, '<paragraph>[]</paragraph>' );
  87. pasteHtml( editor, 'https://youtube.com/watch?v=H08tGjXNHO4' );
  88. clock.tick( 100 );
  89. expect( getData( editor.model ) ).to.equal(
  90. '[<media url="https://youtube.com/watch?v=H08tGjXNHO4"></media>]'
  91. );
  92. } );
  93. it( 'works for a full URL (http + "www" sub-domain)', () => {
  94. setData( editor.model, '<paragraph>[]</paragraph>' );
  95. pasteHtml( editor, 'http://www.youtube.com/watch?v=H08tGjXNHO4' );
  96. clock.tick( 100 );
  97. expect( getData( editor.model ) ).to.equal(
  98. '[<media url="http://www.youtube.com/watch?v=H08tGjXNHO4"></media>]'
  99. );
  100. } );
  101. it( 'works for a full URL (http without "wwww" sub-domain)', () => {
  102. setData( editor.model, '<paragraph>[]</paragraph>' );
  103. pasteHtml( editor, 'http://youtube.com/watch?v=H08tGjXNHO4' );
  104. clock.tick( 100 );
  105. expect( getData( editor.model ) ).to.equal(
  106. '[<media url="http://youtube.com/watch?v=H08tGjXNHO4"></media>]'
  107. );
  108. } );
  109. it( 'works for a URL without protocol (with "www" sub-domain)', () => {
  110. setData( editor.model, '<paragraph>[]</paragraph>' );
  111. pasteHtml( editor, 'www.youtube.com/watch?v=H08tGjXNHO4' );
  112. clock.tick( 100 );
  113. expect( getData( editor.model ) ).to.equal(
  114. '[<media url="www.youtube.com/watch?v=H08tGjXNHO4"></media>]'
  115. );
  116. } );
  117. it( 'works for a URL without protocol (without "www" sub-domain)', () => {
  118. setData( editor.model, '<paragraph>[]</paragraph>' );
  119. pasteHtml( editor, 'youtube.com/watch?v=H08tGjXNHO4' );
  120. clock.tick( 100 );
  121. expect( getData( editor.model ) ).to.equal(
  122. '[<media url="youtube.com/watch?v=H08tGjXNHO4"></media>]'
  123. );
  124. } );
  125. it( 'works fine if a media has no preview', () => {
  126. setData( editor.model, '<paragraph>[]</paragraph>' );
  127. pasteHtml( editor, 'https://twitter.com/ckeditor/status/1035181110140063749' );
  128. clock.tick( 100 );
  129. expect( getData( editor.model ) ).to.equal(
  130. '[<media url="https://twitter.com/ckeditor/status/1035181110140063749"></media>]'
  131. );
  132. } );
  133. it( 'works for URL that was pasted as a link', () => {
  134. setData( editor.model, '<paragraph>[]</paragraph>' );
  135. pasteHtml( editor, '<a href="https://www.youtube.com/watch?v=H08tGjXNHO4">https://www.youtube.com/watch?v=H08tGjXNHO4</a>' );
  136. clock.tick( 100 );
  137. expect( getData( editor.model ) ).to.equal(
  138. '[<media url="https://www.youtube.com/watch?v=H08tGjXNHO4"></media>]'
  139. );
  140. } );
  141. it( 'works for URL that contains some inline styles', () => {
  142. setData( editor.model, '<paragraph>[]</paragraph>' );
  143. pasteHtml( editor, '<b>https://www.youtube.com/watch?v=H08tGjXNHO4</b>' );
  144. clock.tick( 100 );
  145. expect( getData( editor.model ) ).to.equal(
  146. '[<media url="https://www.youtube.com/watch?v=H08tGjXNHO4"></media>]'
  147. );
  148. } );
  149. it( 'works for not collapsed selection inside single element', () => {
  150. setData( editor.model, '<paragraph>[Foo]</paragraph>' );
  151. pasteHtml( editor, 'https://www.youtube.com/watch?v=H08tGjXNHO4' );
  152. clock.tick( 100 );
  153. expect( getData( editor.model ) ).to.equal(
  154. '[<media url="https://www.youtube.com/watch?v=H08tGjXNHO4"></media>]'
  155. );
  156. } );
  157. it( 'works for not collapsed selection over a few elements', () => {
  158. setData( editor.model, '<paragraph>Fo[o</paragraph><paragraph>Ba]r</paragraph>' );
  159. pasteHtml( editor, 'https://www.youtube.com/watch?v=H08tGjXNHO4' );
  160. clock.tick( 100 );
  161. expect( getData( editor.model ) ).to.equal(
  162. '[<media url="https://www.youtube.com/watch?v=H08tGjXNHO4"></media>]<paragraph>For</paragraph>'
  163. );
  164. } );
  165. it( 'does nothing if a URL is invalid', () => {
  166. setData( editor.model, '<paragraph>[]</paragraph>' );
  167. pasteHtml( editor, 'https://youtube.com' );
  168. clock.tick( 100 );
  169. expect( getData( editor.model ) ).to.equal(
  170. '<paragraph>https://youtube.com[]</paragraph>'
  171. );
  172. } );
  173. it( 'does nothing if pasted two links as text', () => {
  174. setData( editor.model, '<paragraph>[]</paragraph>' );
  175. pasteHtml( editor, 'https://www.youtube.com/watch?v=H08tGjXNHO4 https://www.youtube.com/watch?v=H08tGjXNHO4' );
  176. clock.tick( 100 );
  177. expect( getData( editor.model ) ).to.equal(
  178. '<paragraph>https://www.youtube.com/watch?v=H08tGjXNHO4 https://www.youtube.com/watch?v=H08tGjXNHO4[]</paragraph>'
  179. );
  180. } );
  181. it( 'does nothing if pasted text contains a valid URL', () => {
  182. setData( editor.model, '<paragraph>[]</paragraph>' );
  183. pasteHtml( editor, 'Foo bar https://www.youtube.com/watch?v=H08tGjXNHO4 bar foo.' );
  184. clock.tick( 100 );
  185. expect( getData( editor.model ) ).to.equal(
  186. '<paragraph>Foo bar https://www.youtube.com/watch?v=H08tGjXNHO4 bar foo.[]</paragraph>'
  187. );
  188. } );
  189. it( 'does nothing if pasted more than single node', () => {
  190. setData( editor.model, '<paragraph>[]</paragraph>' );
  191. pasteHtml( editor,
  192. 'https://www.youtube.com/watch?v=H08tGjXNHO4 ' +
  193. '<a href="https://www.youtube.com/watch?v=H08tGjXNHO4">https://www.youtube.com/watch?v=H08tGjXNHO4</a>'
  194. );
  195. clock.tick( 100 );
  196. expect( getData( editor.model ) ).to.equal(
  197. '<paragraph>https://www.youtube.com/watch?v=H08tGjXNHO4 ' +
  198. '<$text linkHref="https://www.youtube.com/watch?v=H08tGjXNHO4">https://www.youtube.com/watch?v=H08tGjXNHO4[]</$text>' +
  199. '</paragraph>'
  200. );
  201. } );
  202. it( 'does nothing if pasted a paragraph with the url', () => {
  203. setData( editor.model, '<paragraph>[]</paragraph>' );
  204. pasteHtml( editor, '<p>https://www.youtube.com/watch?v=H08tGjXNHO4</p>' );
  205. clock.tick( 100 );
  206. expect( getData( editor.model ) ).to.equal(
  207. '<paragraph>https://www.youtube.com/watch?v=H08tGjXNHO4[]</paragraph>'
  208. );
  209. } );
  210. it( 'does nothing if pasted a block of content that looks like a URL', () => {
  211. setData( editor.model, '<paragraph>[]</paragraph>' );
  212. pasteHtml( editor, '<ul><li>https://</li><li>youtube.com/watch?</li></ul><p>v=H08tGjXNHO4</p>' );
  213. clock.tick( 100 );
  214. expect( getData( editor.model ) ).to.equal(
  215. '<listItem listIndent="0" listType="bulleted">https://</listItem>' +
  216. '<listItem listIndent="0" listType="bulleted">youtube.com/watch?</listItem>' +
  217. '<paragraph>v=H08tGjXNHO4[]</paragraph>'
  218. );
  219. } );
  220. it( 'does nothing if a URL is invalid (space inside URL)', () => {
  221. setData( editor.model, '<paragraph>[]</paragraph>' );
  222. pasteHtml( editor, 'youtube.com/watch?v=H08tGjXNHO4&amp;param=foo bar' );
  223. clock.tick( 100 );
  224. expect( getData( editor.model ) ).to.equal(
  225. '<paragraph>youtube.com/watch?v=H08tGjXNHO4&param=foo bar[]</paragraph>'
  226. );
  227. } );
  228. // #47
  229. it( 'does not transform a valid URL into a media if the element cannot be placed in the current position', () => {
  230. setData( editor.model, '<image src="foo.png"><caption>Foo.[]</caption></image>' );
  231. pasteHtml( editor, 'https://www.youtube.com/watch?v=H08tGjXNHO4' );
  232. clock.tick( 100 );
  233. expect( getData( editor.model ) ).to.equal(
  234. '<image src="foo.png"><caption>Foo.https://www.youtube.com/watch?v=H08tGjXNHO4[]</caption></image>'
  235. );
  236. } );
  237. it( 'replaces a URL in media if pasted a link when other media element was selected', () => {
  238. setData(
  239. editor.model,
  240. '[<media url="https://open.spotify.com/album/2IXlgvecaDqOeF3viUZnPI?si=ogVw7KlcQAGZKK4Jz9QzvA"></media>]'
  241. );
  242. pasteHtml( editor, 'https://www.youtube.com/watch?v=H08tGjXNHO4' );
  243. clock.tick( 100 );
  244. expect( getData( editor.model ) ).to.equal(
  245. '[<media url="https://www.youtube.com/watch?v=H08tGjXNHO4"></media>]'
  246. );
  247. } );
  248. it( 'inserts a new media element if pasted a link when other media element was selected in correct place', () => {
  249. setData(
  250. editor.model,
  251. '<paragraph>Foo. <$text linkHref="https://cksource.com">Bar</$text></paragraph>' +
  252. '[<media url="https://open.spotify.com/album/2IXlgvecaDqOeF3viUZnPI?si=ogVw7KlcQAGZKK4Jz9QzvA"></media>]' +
  253. '<paragraph><$text bold="true">Bar</$text>.</paragraph>'
  254. );
  255. pasteHtml( editor, 'https://www.youtube.com/watch?v=H08tGjXNHO4' );
  256. clock.tick( 100 );
  257. expect( getData( editor.model ) ).to.equal(
  258. '<paragraph>Foo. <$text linkHref="https://cksource.com">Bar</$text></paragraph>' +
  259. '[<media url="https://www.youtube.com/watch?v=H08tGjXNHO4"></media>]' +
  260. '<paragraph><$text bold="true">Bar</$text>.</paragraph>'
  261. );
  262. } );
  263. it( 'does nothing if URL match to media but it was removed', () => {
  264. return ClassicTestEditor
  265. .create( editorElement, {
  266. plugins: [ MediaEmbed, AutoMediaEmbed, Paragraph ],
  267. mediaEmbed: {
  268. removeProviders: [ 'youtube' ]
  269. }
  270. } )
  271. .then( newEditor => {
  272. editor = newEditor;
  273. setData( editor.model, '<paragraph>[]</paragraph>' );
  274. pasteHtml( editor, 'https://www.youtube.com/watch?v=H08tGjXNHO4' );
  275. clock.tick( 100 );
  276. expect( getData( editor.model ) ).to.equal(
  277. '<paragraph>https://www.youtube.com/watch?v=H08tGjXNHO4[]</paragraph>'
  278. );
  279. editorElement.remove();
  280. return editor.destroy();
  281. } );
  282. } );
  283. } );
  284. describe( 'use real timers', () => {
  285. const characters = Array( 10 ).fill( 1 ).map( ( x, i ) => String.fromCharCode( 65 + i ) );
  286. it( 'undo breaks the auto-media embed feature (undo was done before auto-media embed)', done => {
  287. setData( editor.model, '<paragraph>[]</paragraph>' );
  288. pasteHtml( editor, 'https://www.youtube.com/watch?v=H08tGjXNHO4' );
  289. expect( getData( editor.model ) ).to.equal(
  290. '<paragraph>https://www.youtube.com/watch?v=H08tGjXNHO4[]</paragraph>'
  291. );
  292. setTimeout( () => {
  293. editor.commands.execute( 'undo' );
  294. expect( getData( editor.model ) ).to.equal(
  295. '<paragraph>[]</paragraph>'
  296. );
  297. done();
  298. } );
  299. } );
  300. // Checking whether paste+typing calls the auto-media handler once.
  301. it( 'pasting handler should be executed once', done => {
  302. const autoMediaEmbedPlugin = editor.plugins.get( AutoMediaEmbed );
  303. const autoMediaHandler = autoMediaEmbedPlugin._embedMediaBetweenPositions;
  304. let counter = 0;
  305. autoMediaEmbedPlugin._embedMediaBetweenPositions = function( ...args ) {
  306. counter += 1;
  307. return autoMediaHandler.apply( this, args );
  308. };
  309. setData( editor.model, '<paragraph>[]</paragraph>' );
  310. pasteHtml( editor, 'https://www.youtube.com/watch?v=H08tGjXNHO4' );
  311. simulateTyping( 'Foo. Bar.' );
  312. setTimeout( () => {
  313. autoMediaEmbedPlugin._embedMediaBetweenPositions = autoMediaHandler;
  314. expect( counter ).to.equal( 1 );
  315. done();
  316. }, 100 );
  317. } );
  318. it( 'typing before pasted link during collaboration should not blow up', done => {
  319. setData( editor.model, '<paragraph>[]</paragraph>' );
  320. pasteHtml( editor, 'https://www.youtube.com/watch?v=H08tGjXNHO4' );
  321. for ( let i = 0; i < 10; ++i ) {
  322. const rootEl = editor.model.document.getRoot();
  323. setTimeout( () => {
  324. editor.model.enqueueChange( 'transparent', writer => {
  325. writer.insertText( characters[ i ], writer.createPositionFromPath( rootEl, [ 0, i ] ) );
  326. } );
  327. }, i * 5 );
  328. }
  329. setTimeout( () => {
  330. expect( getData( editor.model ) ).to.equal(
  331. '[<media url="https://www.youtube.com/watch?v=H08tGjXNHO4"></media>]<paragraph>ABCDEFGHIJ</paragraph>'
  332. );
  333. done();
  334. }, 100 );
  335. } );
  336. it( 'typing after pasted link during collaboration should not blow up', done => {
  337. setData( editor.model, '<paragraph>[]</paragraph>' );
  338. pasteHtml( editor, 'https://www.youtube.com/watch?v=H08tGjXNHO4' );
  339. for ( let i = 0; i < 10; ++i ) {
  340. setTimeout( () => {
  341. editor.model.enqueueChange( 'transparent', writer => {
  342. writer.insertText( characters[ i ], editor.model.document.selection.getFirstPosition() );
  343. } );
  344. }, i * 5 );
  345. }
  346. setTimeout( () => {
  347. expect( getData( editor.model ) ).to.equal(
  348. '[<media url="https://www.youtube.com/watch?v=H08tGjXNHO4"></media>]<paragraph>ABCDEFGHIJ</paragraph>'
  349. );
  350. done();
  351. }, 100 );
  352. } );
  353. it( 'should insert the media element even if parent element where the URL was pasted has been deleted', done => {
  354. setData( editor.model, '<paragraph>Foo.</paragraph><paragraph>Bar.[]</paragraph>' );
  355. pasteHtml( editor, 'https://www.youtube.com/watch?v=H08tGjXNHO4' );
  356. editor.model.enqueueChange( 'transparent', writer => {
  357. writer.remove( writer.createRangeOn( editor.model.document.getRoot().getChild( 1 ) ) );
  358. } );
  359. setTimeout( () => {
  360. expect( getData( editor.model ) ).to.equal(
  361. '<paragraph>Foo.</paragraph>[<media url="https://www.youtube.com/watch?v=H08tGjXNHO4"></media>]'
  362. );
  363. done();
  364. }, 100 );
  365. } );
  366. it( 'should insert the media element even if new element appeared above the pasted URL', done => {
  367. setData( editor.model, '<paragraph>Foo.</paragraph><paragraph>Bar.[]</paragraph>' );
  368. pasteHtml( editor, 'https://www.youtube.com/watch?v=H08tGjXNHO4' );
  369. editor.model.enqueueChange( 'transparent', writer => {
  370. const paragraph = writer.createElement( 'paragraph' );
  371. writer.insert( paragraph, writer.createPositionAfter( editor.model.document.getRoot().getChild( 0 ) ) );
  372. writer.setSelection( paragraph, 'in' );
  373. } );
  374. for ( let i = 0; i < 10; ++i ) {
  375. setTimeout( () => {
  376. editor.model.enqueueChange( 'transparent', writer => {
  377. writer.insertText( characters[ i ], editor.model.document.selection.getFirstPosition() );
  378. } );
  379. }, i * 5 );
  380. }
  381. setTimeout( () => {
  382. expect( getData( editor.model ) ).to.equal(
  383. '<paragraph>Foo.</paragraph>' +
  384. '<paragraph>ABCDEFGHIJ</paragraph>' +
  385. '<paragraph>Bar.</paragraph>' +
  386. '[<media url="https://www.youtube.com/watch?v=H08tGjXNHO4"></media>]'
  387. );
  388. done();
  389. }, 100 );
  390. } );
  391. it( 'should insert the media element even if new element appeared below the pasted URL', done => {
  392. setData( editor.model, '<paragraph>Foo.</paragraph><paragraph>Bar.[]</paragraph>' );
  393. pasteHtml( editor, 'https://www.youtube.com/watch?v=H08tGjXNHO4' );
  394. editor.model.enqueueChange( 'transparent', writer => {
  395. const paragraph = writer.createElement( 'paragraph' );
  396. writer.insert( paragraph, writer.createPositionAfter( editor.model.document.getRoot().getChild( 1 ) ) );
  397. writer.setSelection( paragraph, 'in' );
  398. } );
  399. for ( let i = 0; i < 10; ++i ) {
  400. setTimeout( () => {
  401. editor.model.enqueueChange( 'transparent', writer => {
  402. writer.insertText( characters[ i ], editor.model.document.selection.getFirstPosition() );
  403. } );
  404. }, i * 5 );
  405. }
  406. setTimeout( () => {
  407. expect( getData( editor.model ) ).to.equal(
  408. '<paragraph>Foo.</paragraph>' +
  409. '<paragraph>Bar.</paragraph>' +
  410. '[<media url="https://www.youtube.com/watch?v=H08tGjXNHO4"></media>]' +
  411. '<paragraph>ABCDEFGHIJ</paragraph>'
  412. );
  413. done();
  414. }, 100 );
  415. } );
  416. } );
  417. function simulateTyping( text ) {
  418. // While typing, every character is an atomic change.
  419. text.split( '' ).forEach( character => {
  420. editor.execute( 'input', {
  421. text: character
  422. } );
  423. } );
  424. }
  425. function pasteHtml( editor, html ) {
  426. editor.editing.view.document.fire( 'paste', {
  427. dataTransfer: createDataTransfer( { 'text/html': html } ),
  428. preventDefault() {
  429. }
  430. } );
  431. }
  432. function createDataTransfer( data ) {
  433. return {
  434. getData( type ) {
  435. return data[ type ];
  436. }
  437. };
  438. }
  439. } );