automediaembed.js 18 KB

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