tableclipboard.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* globals document */
  6. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  7. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  8. import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
  9. import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  10. import TableEditing from '../src/tableediting';
  11. import { assertSelectedCells, modelTable, viewTable } from './_utils/utils';
  12. import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
  13. import TableClipboard from '../src/tableclipboard';
  14. describe( 'table clipboard', () => {
  15. let editor, model, modelRoot, tableSelection, viewDocument, element;
  16. beforeEach( async () => {
  17. element = document.createElement( 'div' );
  18. document.body.appendChild( element );
  19. editor = await ClassicTestEditor.create( element, {
  20. plugins: [ TableEditing, TableClipboard, Paragraph, Clipboard ]
  21. } );
  22. model = editor.model;
  23. modelRoot = model.document.getRoot();
  24. viewDocument = editor.editing.view.document;
  25. tableSelection = editor.plugins.get( 'TableSelection' );
  26. setModelData( model, modelTable( [
  27. [ '00[]', '01', '02' ],
  28. [ '10', '11', '12' ],
  29. [ '20', '21', '22' ]
  30. ] ) );
  31. } );
  32. afterEach( async () => {
  33. await editor.destroy();
  34. element.remove();
  35. } );
  36. describe( 'Clipboard integration', () => {
  37. describe( 'copy', () => {
  38. it( 'should do nothing for normal selection in table', () => {
  39. const dataTransferMock = createDataTransfer();
  40. const spy = sinon.spy();
  41. viewDocument.on( 'clipboardOutput', spy );
  42. viewDocument.fire( 'copy', {
  43. dataTransfer: dataTransferMock,
  44. preventDefault: sinon.spy()
  45. } );
  46. sinon.assert.calledOnce( spy );
  47. } );
  48. it( 'should copy selected table cells as a standalone table', () => {
  49. const preventDefaultSpy = sinon.spy();
  50. tableSelection._setCellSelection(
  51. modelRoot.getNodeByPath( [ 0, 0, 1 ] ),
  52. modelRoot.getNodeByPath( [ 0, 1, 2 ] )
  53. );
  54. const data = {
  55. dataTransfer: createDataTransfer(),
  56. preventDefault: preventDefaultSpy
  57. };
  58. viewDocument.fire( 'copy', data );
  59. sinon.assert.calledOnce( preventDefaultSpy );
  60. expect( data.dataTransfer.getData( 'text/html' ) ).to.equal( viewTable( [
  61. [ '01', '02' ],
  62. [ '11', '12' ]
  63. ] ) );
  64. } );
  65. it( 'should trim selected table to a selection rectangle (inner cell with colspan, no colspan after trim)', () => {
  66. setModelData( model, modelTable( [
  67. [ '00[]', '01', '02' ],
  68. [ '10', { contents: '11', colspan: 2 } ],
  69. [ '20', '21', '22' ]
  70. ] ) );
  71. tableSelection._setCellSelection(
  72. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  73. modelRoot.getNodeByPath( [ 0, 2, 1 ] )
  74. );
  75. assertClipboardContentOnMethod( 'copy', viewTable( [
  76. [ '00', '01' ],
  77. [ '10', '11' ],
  78. [ '20', '21' ]
  79. ] ) );
  80. } );
  81. it( 'should trim selected table to a selection rectangle (inner cell with colspan, has colspan after trim)', () => {
  82. setModelData( model, modelTable( [
  83. [ '00[]', '01', '02' ],
  84. [ { contents: '10', colspan: 3 } ],
  85. [ '20', '21', '22' ]
  86. ] ) );
  87. tableSelection._setCellSelection(
  88. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  89. modelRoot.getNodeByPath( [ 0, 2, 1 ] )
  90. );
  91. assertClipboardContentOnMethod( 'copy', viewTable( [
  92. [ '00', '01' ],
  93. [ { contents: '10', colspan: 2 } ],
  94. [ '20', '21' ]
  95. ] ) );
  96. } );
  97. it( 'should trim selected table to a selection rectangle (inner cell with rowspan, no colspan after trim)', () => {
  98. setModelData( model, modelTable( [
  99. [ '00[]', '01', '02' ],
  100. [ '10', { contents: '11', rowspan: 2 }, '12' ],
  101. [ '20', '21', '22' ]
  102. ] ) );
  103. tableSelection._setCellSelection(
  104. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  105. modelRoot.getNodeByPath( [ 0, 1, 2 ] )
  106. );
  107. assertClipboardContentOnMethod( 'copy', viewTable( [
  108. [ '00', '01', '02' ],
  109. [ '10', '11', '12' ]
  110. ] ) );
  111. } );
  112. it( 'should trim selected table to a selection rectangle (inner cell with rowspan, has rowspan after trim)', () => {
  113. setModelData( model, modelTable( [
  114. [ '00[]', { contents: '01', rowspan: 3 }, '02' ],
  115. [ '10', '12' ],
  116. [ '20', '22' ]
  117. ] ) );
  118. tableSelection._setCellSelection(
  119. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  120. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  121. );
  122. assertClipboardContentOnMethod( 'copy', viewTable( [
  123. [ '00', { contents: '01', rowspan: 2 }, '02' ],
  124. [ '10', '12' ]
  125. ] ) );
  126. } );
  127. it( 'should prepend spanned columns with empty cells (outside cell with colspan)', () => {
  128. setModelData( model, modelTable( [
  129. [ '00[]', '01', '02' ],
  130. [ { contents: '10', colspan: 2 }, '12' ],
  131. [ '20', '21', '22' ]
  132. ] ) );
  133. tableSelection._setCellSelection(
  134. modelRoot.getNodeByPath( [ 0, 0, 1 ] ),
  135. modelRoot.getNodeByPath( [ 0, 2, 2 ] )
  136. );
  137. assertClipboardContentOnMethod( 'copy', viewTable( [
  138. [ '01', '02' ],
  139. [ ' ', '12' ],
  140. [ '21', '22' ]
  141. ] ) );
  142. } );
  143. it( 'should prepend spanned columns with empty cells (outside cell with rowspan)', () => {
  144. setModelData( model, modelTable( [
  145. [ '00[]', { contents: '01', rowspan: 2 }, '02' ],
  146. [ '10', '12' ],
  147. [ '20', '21', '22' ]
  148. ] ) );
  149. tableSelection._setCellSelection(
  150. modelRoot.getNodeByPath( [ 0, 1, 0 ] ),
  151. modelRoot.getNodeByPath( [ 0, 2, 2 ] )
  152. );
  153. assertClipboardContentOnMethod( 'copy', viewTable( [
  154. [ '10', ' ', '12' ],
  155. [ '20', '21', '22' ]
  156. ] ) );
  157. } );
  158. it( 'should fix selected table to a selection rectangle (hardcore case)', () => {
  159. // This test check how previous simple rules run together (mixed prepending and trimming).
  160. // In the example below a selection is set from cell "32" to "88"
  161. //
  162. // Input table: Copied table:
  163. //
  164. // +----+----+----+----+----+----+----+----+----+
  165. // | 00 | 01 | 02 | 03 | 04 | 06 | 07 | 08 |
  166. // +----+----+ +----+ +----+----+----+
  167. // | 10 | 11 | | 13 | | 16 | 17 | 18 |
  168. // +----+----+ +----+ +----+----+----+ +----+----+----+---------+----+----+
  169. // | 20 | 21 | | 23 | | 26 | | 21 | | 23 | | | 26 | |
  170. // +----+----+ +----+ +----+----+----+ +----+----+----+----+----+----+----+
  171. // | 30 | 31 | | 33 | | 36 | 37 | | 31 | | 33 | | | 36 | 37 |
  172. // +----+----+----+----+ +----+----+----+ +----+----+----+----+----+----+----+
  173. // | 40 | | 46 | 47 | 48 | | | | | | | 46 | 47 |
  174. // +----+----+----+----+ +----+----+----+ ==> +----+----+----+----+----+----+----+
  175. // | 50 | 51 | 52 | 53 | | 56 | 57 | 58 | | 51 | 52 | 53 | | | 56 | 57 |
  176. // +----+----+----+----+----+----+ +----+----+ +----+----+----+----+----+----+----+
  177. // | 60 | 61 | 64 | 65 | | 67 | 68 | | 61 | | | 64 | 65 | | 67 |
  178. // +----+----+----+----+----+----+ +----+----+ +----+----+----+----+----+----+----+
  179. // | 70 | 71 | 72 | 73 | 74 | 75 | | 77 | 78 | | 71 | 72 | 73 | 74 | 75 | | 77 |
  180. // +----+ +----+----+----+----+ +----+----+ +----+----+----+----+----+----+----+
  181. // | 80 | | 82 | 83 | 84 | 85 | | 87 | 88 |
  182. // +----+----+----+----+----+----+----+----+----+
  183. //
  184. setModelData( model, modelTable( [
  185. [ '00', '01', { contents: '02', rowspan: 4 }, '03', { contents: '04', colspan: 2, rowspan: 7 }, '07', '07', '08' ],
  186. [ '10', '11', '13', '17', '17', '18' ],
  187. [ '20', '21', '23', { contents: '27', colspan: 3 } ],
  188. [ '30', '31', '33', '37', { contents: '37', colspan: 2 } ],
  189. [ { contents: '40', colspan: 4 }, '47', '47', '48' ],
  190. [ '50', '51', '52', '53', { contents: '57', rowspan: 4 }, '57', '58' ],
  191. [ '60', { contents: '61', colspan: 3 }, '67', '68' ],
  192. [ '70', { contents: '71', rowspan: 2 }, '72', '73', '74', '75', '77', '78' ],
  193. [ '80', '82', '83', '84', '85', '87', '88' ]
  194. ] ) );
  195. tableSelection._setCellSelection(
  196. modelRoot.getNodeByPath( [ 0, 2, 1 ] ),
  197. modelRoot.getNodeByPath( [ 0, 7, 6 ] )
  198. );
  199. assertClipboardContentOnMethod( 'copy', viewTable( [
  200. [ '21', ' ', '23', ' ', ' ', { contents: '27', colspan: 2 } ],
  201. [ '31', ' ', '33', ' ', ' ', '37', '37' ],
  202. [ ' ', ' ', ' ', ' ', ' ', '47', '47' ],
  203. [ '51', '52', '53', ' ', ' ', { contents: '57', rowspan: 3 }, '57' ],
  204. [ { contents: '61', colspan: 3 }, ' ', ' ', ' ', '67' ],
  205. [ '71', '72', '73', '74', '75', '77' ]
  206. ] ) );
  207. } );
  208. it( 'should update table heading attributes (selection with headings)', () => {
  209. setModelData( model, modelTable( [
  210. [ '00', '01', '02', '03', '04' ],
  211. [ '10', '11', '12', '13', '14' ],
  212. [ '20', '21', '22', '23', '24' ],
  213. [ '30', '31', '32', '33', '34' ],
  214. [ '40', '41', '42', '43', '44' ]
  215. ], { headingRows: 3, headingColumns: 2 } ) );
  216. tableSelection._setCellSelection(
  217. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  218. modelRoot.getNodeByPath( [ 0, 3, 3 ] )
  219. );
  220. assertClipboardContentOnMethod( 'copy', viewTable( [
  221. [ '11', '12', '13' ],
  222. [ '21', '22', '23' ],
  223. [ { contents: '31', isHeading: true }, '32', '33' ] // TODO: bug in viewTable
  224. ], { headingRows: 2, headingColumns: 1 } ) );
  225. } );
  226. it( 'should update table heading attributes (selection without headings)', () => {
  227. setModelData( model, modelTable( [
  228. [ '00', '01', '02', '03', '04' ],
  229. [ '10', '11', '12', '13', '14' ],
  230. [ '20', '21', '22', '23', '24' ],
  231. [ '30', '31', '32', '33', '34' ],
  232. [ '40', '41', '42', '43', '44' ]
  233. ], { headingRows: 3, headingColumns: 2 } ) );
  234. tableSelection._setCellSelection(
  235. modelRoot.getNodeByPath( [ 0, 3, 2 ] ),
  236. modelRoot.getNodeByPath( [ 0, 4, 4 ] )
  237. );
  238. assertClipboardContentOnMethod( 'copy', viewTable( [
  239. [ '32', '33', '34' ],
  240. [ '42', '43', '44' ]
  241. ] ) );
  242. } );
  243. } );
  244. describe( 'cut', () => {
  245. it( 'should not block clipboardOutput if no multi-cell selection', () => {
  246. setModelData( model, modelTable( [
  247. [ '[00]', '01', '02' ],
  248. [ '10', '11', '12' ],
  249. [ '20', '21', '22' ]
  250. ] ) );
  251. const dataTransferMock = createDataTransfer();
  252. viewDocument.fire( 'cut', {
  253. dataTransfer: dataTransferMock,
  254. preventDefault: sinon.spy()
  255. } );
  256. expect( dataTransferMock.getData( 'text/html' ) ).to.equal( '00' );
  257. } );
  258. it( 'should be preventable', () => {
  259. tableSelection._setCellSelection(
  260. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  261. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  262. );
  263. viewDocument.on( 'clipboardOutput', evt => evt.stop(), { priority: 'high' } );
  264. viewDocument.fire( 'cut', {
  265. dataTransfer: createDataTransfer(),
  266. preventDefault: sinon.spy()
  267. } );
  268. assertEqualMarkup( getModelData( model ), modelTable( [
  269. [ { contents: '00', isSelected: true }, { contents: '01', isSelected: true }, '02' ],
  270. [ { contents: '10', isSelected: true }, { contents: '11', isSelected: true }, '12' ],
  271. [ '20', '21', '22' ]
  272. ] ) );
  273. } );
  274. it( 'is clears selected table cells', () => {
  275. const spy = sinon.spy();
  276. viewDocument.on( 'clipboardOutput', spy );
  277. tableSelection._setCellSelection(
  278. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  279. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  280. );
  281. viewDocument.fire( 'cut', {
  282. dataTransfer: createDataTransfer(),
  283. preventDefault: sinon.spy()
  284. } );
  285. assertEqualMarkup( getModelData( model ), modelTable( [
  286. [ '', '', '02' ],
  287. [ '', '[]', '12' ],
  288. [ '20', '21', '22' ]
  289. ] ) );
  290. } );
  291. it( 'should copy selected table cells as a standalone table', () => {
  292. const preventDefaultSpy = sinon.spy();
  293. tableSelection._setCellSelection(
  294. modelRoot.getNodeByPath( [ 0, 0, 1 ] ),
  295. modelRoot.getNodeByPath( [ 0, 1, 2 ] )
  296. );
  297. const data = {
  298. dataTransfer: createDataTransfer(),
  299. preventDefault: preventDefaultSpy
  300. };
  301. viewDocument.fire( 'cut', data );
  302. sinon.assert.calledOnce( preventDefaultSpy );
  303. expect( data.dataTransfer.getData( 'text/html' ) ).to.equal( viewTable( [
  304. [ '01', '02' ],
  305. [ '11', '12' ]
  306. ] ) );
  307. } );
  308. it( 'should be disabled in a readonly mode', () => {
  309. const preventDefaultStub = sinon.stub();
  310. editor.isReadOnly = true;
  311. tableSelection._setCellSelection(
  312. modelRoot.getNodeByPath( [ 0, 0, 1 ] ),
  313. modelRoot.getNodeByPath( [ 0, 1, 2 ] )
  314. );
  315. const data = {
  316. dataTransfer: createDataTransfer(),
  317. preventDefault: preventDefaultStub
  318. };
  319. viewDocument.fire( 'cut', data );
  320. editor.isReadOnly = false;
  321. expect( data.dataTransfer.getData( 'text/html' ) ).to.be.undefined;
  322. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  323. [ '00', '01', '02' ],
  324. [ '10', '11', '12' ],
  325. [ '20', '21', '22' ]
  326. ] ) );
  327. sinon.assert.calledOnce( preventDefaultStub );
  328. } );
  329. } );
  330. describe( 'paste', () => {
  331. beforeEach( () => {
  332. setModelData( model, modelTable( [
  333. [ '00[]', '01', '02', '03' ],
  334. [ '10', '11', '12', '13' ],
  335. [ '20', '21', '22', '23' ],
  336. [ '30', '31', '32', '33' ]
  337. ] ) );
  338. } );
  339. describe( 'pasted table is equal to the selected area', () => {
  340. it( 'should be disabled in a readonly mode', () => {
  341. editor.isReadOnly = true;
  342. tableSelection._setCellSelection(
  343. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  344. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  345. );
  346. const data = pasteTable( [
  347. [ 'aa', 'ab' ],
  348. [ 'ba', 'bb' ]
  349. ] );
  350. editor.isReadOnly = false;
  351. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  352. [ '00', '01', '02', '03' ],
  353. [ '10', '11', '12', '13' ],
  354. [ '20', '21', '22', '23' ],
  355. [ '30', '31', '32', '33' ]
  356. ] ) );
  357. sinon.assert.calledOnce( data.preventDefault );
  358. } );
  359. it( 'should allow normal paste if no table cells are selected', () => {
  360. const data = {
  361. dataTransfer: createDataTransfer(),
  362. preventDefault: sinon.spy(),
  363. stopPropagation: sinon.spy()
  364. };
  365. data.dataTransfer.setData( 'text/html', '<p>foo</p>' );
  366. viewDocument.fire( 'paste', data );
  367. editor.isReadOnly = false;
  368. assertEqualMarkup( getModelData( model ), modelTable( [
  369. [ '00foo[]', '01', '02', '03' ],
  370. [ '10', '11', '12', '13' ],
  371. [ '20', '21', '22', '23' ],
  372. [ '30', '31', '32', '33' ]
  373. ] ) );
  374. } );
  375. describe( 'no spans', () => {
  376. it( 'handles simple table paste to a simple table fragment - at the beginning of a table', () => {
  377. tableSelection._setCellSelection(
  378. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  379. modelRoot.getNodeByPath( [ 0, 1, 1 ] )
  380. );
  381. pasteTable( [
  382. [ 'aa', 'ab' ],
  383. [ 'ba', 'bb' ]
  384. ] );
  385. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  386. [ 'aa', 'ab', '02', '03' ],
  387. [ 'ba', 'bb', '12', '13' ],
  388. [ '20', '21', '22', '23' ],
  389. [ '30', '31', '32', '33' ]
  390. ] ) );
  391. assertSelectedCells( model, [
  392. [ 1, 1, 0, 0 ],
  393. [ 1, 1, 0, 0 ],
  394. [ 0, 0, 0, 0 ],
  395. [ 0, 0, 0, 0 ]
  396. ] );
  397. } );
  398. it( 'handles simple table paste to a simple table fragment - at the end of a table', () => {
  399. tableSelection._setCellSelection(
  400. modelRoot.getNodeByPath( [ 0, 2, 2 ] ),
  401. modelRoot.getNodeByPath( [ 0, 3, 3 ] )
  402. );
  403. pasteTable( [
  404. [ 'aa', 'ab' ],
  405. [ 'ba', 'bb' ]
  406. ] );
  407. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  408. [ '00', '01', '02', '03' ],
  409. [ '10', '11', '12', '13' ],
  410. [ '20', '21', 'aa', 'ab' ],
  411. [ '30', '31', 'ba', 'bb' ]
  412. ] ) );
  413. assertSelectedCells( model, [
  414. [ 0, 0, 0, 0 ],
  415. [ 0, 0, 0, 0 ],
  416. [ 0, 0, 1, 1 ],
  417. [ 0, 0, 1, 1 ]
  418. ] );
  419. } );
  420. it( 'handles simple table paste to a simple table fragment - in the middle of a table', () => {
  421. tableSelection._setCellSelection(
  422. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  423. modelRoot.getNodeByPath( [ 0, 2, 2 ] )
  424. );
  425. pasteTable( [
  426. [ 'aa', 'ab' ],
  427. [ 'ba', 'bb' ]
  428. ] );
  429. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  430. [ '00', '01', '02', '03' ],
  431. [ '10', 'aa', 'ab', '13' ],
  432. [ '20', 'ba', 'bb', '23' ],
  433. [ '30', '31', '32', '33' ]
  434. ] ) );
  435. assertSelectedCells( model, [
  436. [ 0, 0, 0, 0 ],
  437. [ 0, 1, 1, 0 ],
  438. [ 0, 1, 1, 0 ],
  439. [ 0, 0, 0, 0 ]
  440. ] );
  441. } );
  442. it( 'handles simple row paste to a simple row fragment - in the middle of a table', () => {
  443. tableSelection._setCellSelection(
  444. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  445. modelRoot.getNodeByPath( [ 0, 1, 2 ] )
  446. );
  447. pasteTable( [
  448. [ 'aa', 'ab' ]
  449. ] );
  450. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  451. [ '00', '01', '02', '03' ],
  452. [ '10', 'aa', 'ab', '13' ],
  453. [ '20', '21', '22', '23' ],
  454. [ '30', '31', '32', '33' ]
  455. ] ) );
  456. assertSelectedCells( model, [
  457. [ 0, 0, 0, 0 ],
  458. [ 0, 1, 1, 0 ],
  459. [ 0, 0, 0, 0 ],
  460. [ 0, 0, 0, 0 ]
  461. ] );
  462. } );
  463. it( 'handles simple column paste to a simple column fragment - in the middle of a table', () => {
  464. tableSelection._setCellSelection(
  465. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  466. modelRoot.getNodeByPath( [ 0, 2, 1 ] )
  467. );
  468. pasteTable( [
  469. [ 'aa' ],
  470. [ 'ba' ]
  471. ] );
  472. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  473. [ '00', '01', '02', '03' ],
  474. [ '10', 'aa', '12', '13' ],
  475. [ '20', 'ba', '22', '23' ],
  476. [ '30', '31', '32', '33' ]
  477. ] ) );
  478. assertSelectedCells( model, [
  479. [ 0, 0, 0, 0 ],
  480. [ 0, 1, 0, 0 ],
  481. [ 0, 1, 0, 0 ],
  482. [ 0, 0, 0, 0 ]
  483. ] );
  484. } );
  485. it( 'handles simple table paste to a simple table fragment - whole table selected', () => {
  486. tableSelection._setCellSelection(
  487. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  488. modelRoot.getNodeByPath( [ 0, 3, 3 ] )
  489. );
  490. pasteTable( [
  491. [ 'aa', 'ab', 'ac', 'ad' ],
  492. [ 'ba', 'bb', 'bc', 'bd' ],
  493. [ 'ca', 'cb', 'cc', 'cd' ],
  494. [ 'da', 'db', 'dc', 'dd' ]
  495. ] );
  496. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  497. [ 'aa', 'ab', 'ac', 'ad' ],
  498. [ 'ba', 'bb', 'bc', 'bd' ],
  499. [ 'ca', 'cb', 'cc', 'cd' ],
  500. [ 'da', 'db', 'dc', 'dd' ]
  501. ] ) );
  502. assertSelectedCells( model, [
  503. [ 1, 1, 1, 1 ],
  504. [ 1, 1, 1, 1 ],
  505. [ 1, 1, 1, 1 ],
  506. [ 1, 1, 1, 1 ]
  507. ] );
  508. } );
  509. } );
  510. describe( 'pasted table has spans', () => {
  511. it( 'handles pasting table that has cell with colspan', () => {
  512. tableSelection._setCellSelection(
  513. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  514. modelRoot.getNodeByPath( [ 0, 2, 2 ] )
  515. );
  516. pasteTable( [
  517. [ { colspan: 2, contents: 'aa' } ],
  518. [ 'ba', 'bb' ]
  519. ] );
  520. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  521. [ '00', '01', '02', '03' ],
  522. [ '10', { colspan: 2, contents: 'aa' }, '13' ],
  523. [ '20', 'ba', 'bb', '23' ],
  524. [ '30', '31', '32', '33' ]
  525. ] ) );
  526. /* eslint-disable no-multi-spaces */
  527. assertSelectedCells( model, [
  528. [ 0, 0, 0, 0 ],
  529. [ 0, 1, 0 ],
  530. [ 0, 1, 1, 0 ],
  531. [ 0, 0, 0, 0 ]
  532. ] );
  533. /* eslint-enable no-multi-spaces */
  534. } );
  535. it( 'handles pasting table that has many cells with various colspan', () => {
  536. tableSelection._setCellSelection(
  537. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  538. modelRoot.getNodeByPath( [ 0, 3, 2 ] )
  539. );
  540. pasteTable( [
  541. [ 'aa', { colspan: 2, contents: 'ab' } ],
  542. [ { colspan: 3, contents: 'ba' } ],
  543. [ 'ca', 'cb', 'cc' ],
  544. [ { colspan: 2, contents: 'da' }, 'dc' ]
  545. ] );
  546. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  547. [ 'aa', { colspan: 2, contents: 'ab' }, '03' ],
  548. [ { colspan: 3, contents: 'ba' }, '13' ],
  549. [ 'ca', 'cb', 'cc', '23' ],
  550. [ { colspan: 2, contents: 'da' }, 'dc', '33' ]
  551. ] ) );
  552. /* eslint-disable no-multi-spaces */
  553. assertSelectedCells( model, [
  554. [ 1, 1, 0 ],
  555. [ 1, 0 ],
  556. [ 1, 1, 1, 0 ],
  557. [ 1, 1, 0 ]
  558. ] );
  559. /* eslint-enable no-multi-spaces */
  560. } );
  561. it( 'handles pasting table that has cell with rowspan', () => {
  562. tableSelection._setCellSelection(
  563. modelRoot.getNodeByPath( [ 0, 1, 1 ] ),
  564. modelRoot.getNodeByPath( [ 0, 2, 2 ] )
  565. );
  566. pasteTable( [
  567. [ { rowspan: 2, contents: 'aa' }, 'ab' ],
  568. [ 'bb' ]
  569. ] );
  570. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  571. [ '00', '01', '02', '03' ],
  572. [ '10', { rowspan: 2, contents: 'aa' }, 'ab', '13' ],
  573. [ '20', 'bb', '23' ],
  574. [ '30', '31', '32', '33' ]
  575. ] ) );
  576. /* eslint-disable no-multi-spaces */
  577. assertSelectedCells( model, [
  578. [ 0, 0, 0, 0 ],
  579. [ 0, 1, 1, 0 ],
  580. [ 0, 1, 0 ],
  581. [ 0, 0, 0, 0 ]
  582. ] );
  583. /* eslint-enable no-multi-spaces */
  584. } );
  585. it( 'handles pasting table that has many cells with various rowspan', () => {
  586. tableSelection._setCellSelection(
  587. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  588. modelRoot.getNodeByPath( [ 0, 2, 3 ] )
  589. );
  590. pasteTable( [
  591. [ 'aa', { rowspan: 3, contents: 'ab' }, { rowspan: 2, contents: 'ac' }, 'ad' ],
  592. [ { rowspan: 2, contents: 'ba' }, 'bd' ],
  593. [ 'cc', 'cd' ]
  594. ] );
  595. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  596. [ 'aa', { rowspan: 3, contents: 'ab' }, { rowspan: 2, contents: 'ac' }, 'ad' ],
  597. [ { rowspan: 2, contents: 'ba' }, 'bd' ],
  598. [ 'cc', 'cd' ],
  599. [ '30', '31', '32', '33' ]
  600. ] ) );
  601. /* eslint-disable no-multi-spaces */
  602. assertSelectedCells( model, [
  603. [ 1, 1, 1, 1 ],
  604. [ 1, 1 ],
  605. [ 1, 1 ],
  606. [ 0, 0, 0 ]
  607. ] );
  608. /* eslint-enable no-multi-spaces */
  609. } );
  610. it( 'handles pasting multi-spanned table', () => {
  611. setModelData( model, modelTable( [
  612. [ '00', '01', '02', '03', '04', '05' ],
  613. [ '10', '11', '12', '13', '14', '15' ],
  614. [ '20', '21', '22', '23', '24', '25' ],
  615. [ '30', '31', '32', '33', '34', '35' ],
  616. [ '40', '41', '42', '43', '44', '45' ]
  617. ] ) );
  618. tableSelection._setCellSelection(
  619. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  620. modelRoot.getNodeByPath( [ 0, 3, 4 ] )
  621. );
  622. // +----+----+----+----+----+
  623. // | aa | ac | ad | ae |
  624. // +----+----+----+----+ +
  625. // | ba | bb | |
  626. // +----+ +----+
  627. // | ca | | ce |
  628. // + +----+----+----+----+
  629. // | | db | dc | dd |
  630. // +----+----+----+----+----+
  631. pasteTable( [
  632. [ { contents: 'aa', colspan: 2 }, 'ac', 'ad', { contents: 'ae', rowspan: 2 } ],
  633. [ 'ba', { contents: 'bb', colspan: 3, rowspan: 2 } ],
  634. [ { contents: 'ca', rowspan: 2 }, 'ce' ],
  635. [ 'db', 'dc', { contents: 'dd', colspan: 2 } ]
  636. ] );
  637. // +----+----+----+----+----+----+
  638. // | aa | ac | ad | ae | 05 |
  639. // +----+----+----+----+ +----+
  640. // | ba | bb | | 15 |
  641. // +----+ +----+----+
  642. // | ca | | ce | 25 |
  643. // + +----+----+----+----+----+
  644. // | | db | dc | dd | 35 |
  645. // +----+----+----+----+----+----+
  646. // | 40 | 41 | 42 | 43 | 44 | 45 |
  647. // +----+----+----+----+----+----+
  648. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  649. [ { contents: 'aa', colspan: 2 }, 'ac', 'ad', { contents: 'ae', rowspan: 2 }, '05' ],
  650. [ 'ba', { contents: 'bb', colspan: 3, rowspan: 2 }, '15' ],
  651. [ { contents: 'ca', rowspan: 2 }, 'ce', '25' ],
  652. [ 'db', 'dc', { contents: 'dd', colspan: 2 }, '35' ],
  653. [ '40', '41', '42', '43', '44', '45' ]
  654. ] ) );
  655. /* eslint-disable no-multi-spaces */
  656. assertSelectedCells( model, [
  657. [ 1, 1, 1, 1, 0 ],
  658. [ 1, 1, 0 ],
  659. [ 1, 1, 0 ],
  660. [ 1, 1, 1, 0 ],
  661. [ 0, 0, 0, 0, 0, 0 ]
  662. ] );
  663. /* eslint-enable no-multi-spaces */
  664. } );
  665. } );
  666. describe( 'content table has spans', () => {
  667. it( 'handles pasting simple table over a table with colspans (no colspan exceeds selection)', () => {
  668. setModelData( model, modelTable( [
  669. [ '00[]', '01', '02', '03' ],
  670. [ { colspan: 3, contents: '10' }, '13' ],
  671. [ { colspan: 2, contents: '20' }, '22', '23' ],
  672. [ '30', '31', { colspan: 2, contents: '31' } ]
  673. ] ) );
  674. tableSelection._setCellSelection(
  675. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  676. modelRoot.getNodeByPath( [ 0, 2, 1 ] )
  677. );
  678. pasteTable( [
  679. [ 'aa', 'ab', 'ac' ],
  680. [ 'ba', 'bb', 'bc' ],
  681. [ 'ca', 'cb', 'cc' ]
  682. ] );
  683. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  684. [ 'aa', 'ab', 'ac', '03' ],
  685. [ 'ba', 'bb', 'bc', '13' ],
  686. [ 'ca', 'cb', 'cc', '23' ],
  687. [ '30', '31', { colspan: 2, contents: '31' } ]
  688. ] ) );
  689. /* eslint-disable no-multi-spaces */
  690. assertSelectedCells( model, [
  691. [ 1, 1, 1, 0 ],
  692. [ 1, 1, 1, 0 ],
  693. [ 1, 1, 1, 0 ],
  694. [ 0, 0, 0 ]
  695. ] );
  696. /* eslint-enable no-multi-spaces */
  697. } );
  698. it( 'handles pasting simple table over a table with rowspans (no rowspan exceeds selection)', () => {
  699. setModelData( model, modelTable( [
  700. [ '00', { rowspan: 3, contents: '01' }, { rowspan: 2, contents: '02' }, '03' ],
  701. [ { rowspan: 2, contents: '10' }, '13' ],
  702. [ '22', '23' ],
  703. [ '30', '31', '32', '33' ]
  704. ] ) );
  705. tableSelection._setCellSelection(
  706. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  707. modelRoot.getNodeByPath( [ 0, 2, 0 ] )
  708. );
  709. pasteTable( [
  710. [ 'aa', 'ab', 'ac' ],
  711. [ 'ba', 'bb', 'bc' ],
  712. [ 'ca', 'cb', 'cc' ]
  713. ] );
  714. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  715. [ 'aa', 'ab', 'ac', '03' ],
  716. [ 'ba', 'bb', 'bc', '13' ],
  717. [ 'ca', 'cb', 'cc', '23' ],
  718. [ '30', '31', '32', '33' ]
  719. ] ) );
  720. /* eslint-disable no-multi-spaces */
  721. assertSelectedCells( model, [
  722. [ 1, 1, 1, 0 ],
  723. [ 1, 1, 1, 0 ],
  724. [ 1, 1, 1, 0 ],
  725. [ 0, 0, 0 ]
  726. ] );
  727. /* eslint-enable no-multi-spaces */
  728. } );
  729. it( 'handles pasting simple table over table with multi-spans (no span exceeds selection)', () => {
  730. // +----+----+----+----+----+----+
  731. // | 00 | 02 | 03 | 05 |
  732. // + + + +----+
  733. // | | | | 15 |
  734. // +----+----+----+ +----+
  735. // | 20 | 21 | | 25 |
  736. // + +----+----+----+----+----+
  737. // | | 31 | 32 | 34 | 35 |
  738. // +----+----+----+----+----+----+
  739. // | 40 | 41 | 42 | 43 | 44 | 45 |
  740. // +----+----+----+----+----+----+
  741. setModelData( model, modelTable( [
  742. [
  743. { contents: '00', colspan: 2, rowspan: 2 },
  744. { contents: '02', rowspan: 2 },
  745. { contents: '03', colspan: 2, rowspan: 3 },
  746. '05'
  747. ],
  748. [ '15' ],
  749. [ { contents: '20', rowspan: 2 }, { contents: '21', colspan: 2 }, '25' ],
  750. [ '31', { contents: '32', colspan: 2 }, '34', '35' ],
  751. [ '40', '41', '42', '43', '44', '45' ]
  752. ] ) );
  753. tableSelection._setCellSelection(
  754. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  755. modelRoot.getNodeByPath( [ 0, 3, 2 ] )
  756. );
  757. pasteTable( [
  758. [ 'aa', 'ab', 'ac', 'ad', 'ae' ],
  759. [ 'ba', 'bb', 'bc', 'bd', 'be' ],
  760. [ 'ca', 'cb', 'cc', 'cd', 'ce' ],
  761. [ 'da', 'db', 'dc', 'dd', 'de' ]
  762. ] );
  763. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  764. [ 'aa', 'ab', 'ac', 'ad', 'ae', '05' ],
  765. [ 'ba', 'bb', 'bc', 'bd', 'be', '15' ],
  766. [ 'ca', 'cb', 'cc', 'cd', 'ce', '25' ],
  767. [ 'da', 'db', 'dc', 'dd', 'de', '35' ],
  768. [ '40', '41', '42', '43', '44', '45' ]
  769. ] ) );
  770. /* eslint-disable no-multi-spaces */
  771. assertSelectedCells( model, [
  772. [ 1, 1, 1, 1, 1, 0 ],
  773. [ 1, 1, 1, 1, 1, 0 ],
  774. [ 1, 1, 1, 1, 1, 0 ],
  775. [ 1, 1, 1, 1, 1, 0 ],
  776. [ 0, 0, 0, 0, 0, 0 ]
  777. ] );
  778. /* eslint-enable no-multi-spaces */
  779. } );
  780. } );
  781. describe( 'content and paste tables have spans', () => {
  782. it( 'handles pasting colspanned table over table with colspans (no colspan exceeds selection)', () => {
  783. setModelData( model, modelTable( [
  784. [ '00[]', '01', '02', '03' ],
  785. [ { colspan: 3, contents: '10' }, '13' ],
  786. [ { colspan: 2, contents: '20' }, '22', '23' ],
  787. [ '30', '31', { colspan: 2, contents: '31' } ]
  788. ] ) );
  789. tableSelection._setCellSelection(
  790. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  791. modelRoot.getNodeByPath( [ 0, 2, 1 ] )
  792. );
  793. pasteTable( [
  794. [ 'aa', { colspan: 2, contents: 'ab' } ],
  795. [ { colspan: 3, contents: 'ba' } ],
  796. [ 'ca', 'cb', 'cc' ]
  797. ] );
  798. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  799. [ 'aa', { colspan: 2, contents: 'ab' }, '03' ],
  800. [ { colspan: 3, contents: 'ba' }, '13' ],
  801. [ 'ca', 'cb', 'cc', '23' ],
  802. [ '30', '31', { colspan: 2, contents: '31' } ]
  803. ] ) );
  804. /* eslint-disable no-multi-spaces */
  805. assertSelectedCells( model, [
  806. [ 1, 1, 0 ],
  807. [ 1, 0 ],
  808. [ 1, 1, 1, 0 ],
  809. [ 0, 0, 0 ]
  810. ] );
  811. /* eslint-enable no-multi-spaces */
  812. } );
  813. it( 'handles pasting rowspanned table over table with rowspans (no rowspan exceeds selection)', () => {
  814. setModelData( model, modelTable( [
  815. [ { rowspan: 3, contents: '00' }, { rowspan: 2, contents: '01' }, '02', '03' ],
  816. [ { rowspan: 2, contents: '12' }, '13' ],
  817. [ '21', '23' ],
  818. [ '30', '31', '32', '33' ]
  819. ] ) );
  820. tableSelection._setCellSelection(
  821. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  822. modelRoot.getNodeByPath( [ 0, 2, 1 ] )
  823. );
  824. pasteTable( [
  825. [ 'aa', { rowspan: 3, contents: 'ab' }, { rowspan: 2, contents: 'ac' }, 'ad' ],
  826. [ { rowspan: 2, contents: 'ba' }, 'bd' ],
  827. [ 'cc', 'cd' ]
  828. ] );
  829. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  830. [ 'aa', { rowspan: 3, contents: 'ab' }, { rowspan: 2, contents: 'ac' }, 'ad' ],
  831. [ { rowspan: 2, contents: 'ba' }, 'bd' ],
  832. [ 'cc', 'cd' ],
  833. [ '30', '31', '32', '33' ]
  834. ] ) );
  835. /* eslint-disable no-multi-spaces */
  836. assertSelectedCells( model, [
  837. [ 1, 1, 1, 1 ],
  838. [ 1, 1 ],
  839. [ 1, 1 ],
  840. [ 0, 0, 0, 0 ]
  841. ] );
  842. /* eslint-enable no-multi-spaces */
  843. } );
  844. it( 'handles pasting multi-spanned table over table with multi-spans (no span exceeds selection)', () => {
  845. // +----+----+----+----+----+----+
  846. // | 00 | 02 | 03 | 05 |
  847. // + + + +----+
  848. // | | | | 15 |
  849. // +----+----+----+ +----+
  850. // | 20 | 21 | | 25 |
  851. // + +----+----+----+----+----+
  852. // | | 31 | 32 | 34 | 35 |
  853. // +----+----+----+----+----+----+
  854. // | 40 | 41 | 42 | 43 | 44 | 45 |
  855. // +----+----+----+----+----+----+
  856. setModelData( model, modelTable( [
  857. [
  858. { contents: '00', colspan: 2, rowspan: 2 },
  859. { contents: '02', rowspan: 2 },
  860. { contents: '03', colspan: 2, rowspan: 3 },
  861. '05'
  862. ],
  863. [ '15' ],
  864. [ { contents: '20', rowspan: 2 }, { contents: '21', colspan: 2 }, '25' ],
  865. [ '31', { contents: '32', colspan: 2 }, '34', '35' ],
  866. [ '40', '41', '42', '43', '44', '45' ]
  867. ] ) );
  868. tableSelection._setCellSelection(
  869. modelRoot.getNodeByPath( [ 0, 0, 0 ] ),
  870. modelRoot.getNodeByPath( [ 0, 3, 2 ] )
  871. );
  872. // +----+----+----+----+----+
  873. // | aa | ac | ad | ae |
  874. // +----+----+----+----+ +
  875. // | ba | bb | |
  876. // +----+ +----+
  877. // | ca | | ce |
  878. // + +----+----+----+----+
  879. // | | db | dc | dd |
  880. // +----+----+----+----+----+
  881. pasteTable( [
  882. [ { contents: 'aa', colspan: 2 }, 'ac', 'ad', { contents: 'ae', rowspan: 2 } ],
  883. [ 'ba', { contents: 'bb', colspan: 3, rowspan: 2 } ],
  884. [ { contents: 'ca', rowspan: 2 }, 'ce' ],
  885. [ 'db', 'dc', { contents: 'dd', colspan: 2 } ]
  886. ] );
  887. // +----+----+----+----+----+----+
  888. // | aa | ac | ad | ae | 05 |
  889. // +----+----+----+----+ +----+
  890. // | ba | bb | | 15 |
  891. // +----+ +----+----+
  892. // | ca | | ce | 25 |
  893. // + +----+----+----+----+----+
  894. // | | db | dc | dd | 35 |
  895. // +----+----+----+----+----+----+
  896. // | 40 | 41 | 42 | 43 | 44 | 45 |
  897. // +----+----+----+----+----+----+
  898. assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
  899. [ { contents: 'aa', colspan: 2 }, 'ac', 'ad', { contents: 'ae', rowspan: 2 }, '05' ],
  900. [ 'ba', { contents: 'bb', colspan: 3, rowspan: 2 }, '15' ],
  901. [ { contents: 'ca', rowspan: 2 }, 'ce', '25' ],
  902. [ 'db', 'dc', { contents: 'dd', colspan: 2 }, '35' ],
  903. [ '40', '41', '42', '43', '44', '45' ]
  904. ] ) );
  905. /* eslint-disable no-multi-spaces */
  906. assertSelectedCells( model, [
  907. [ 1, 1, 1, 1, 0 ],
  908. [ 1, 1, 0 ],
  909. [ 1, 1, 0 ],
  910. [ 1, 1, 1, 0 ],
  911. [ 0, 0, 0, 0, 0, 0 ]
  912. ] );
  913. /* eslint-enable no-multi-spaces */
  914. } );
  915. } );
  916. } );
  917. } );
  918. } );
  919. function assertClipboardContentOnMethod( method, expectedViewTable ) {
  920. const data = {
  921. dataTransfer: createDataTransfer(),
  922. preventDefault: sinon.spy()
  923. };
  924. viewDocument.fire( method, data );
  925. expect( data.dataTransfer.getData( 'text/html' ) ).to.equal( expectedViewTable );
  926. }
  927. function pasteTable( tableData ) {
  928. const data = {
  929. dataTransfer: createDataTransfer(),
  930. preventDefault: sinon.spy(),
  931. stopPropagation: sinon.spy()
  932. };
  933. data.dataTransfer.setData( 'text/html', viewTable( tableData ) );
  934. viewDocument.fire( 'paste', data );
  935. return data;
  936. }
  937. function createDataTransfer() {
  938. const store = new Map();
  939. return {
  940. setData( type, data ) {
  941. store.set( type, data );
  942. },
  943. getData( type ) {
  944. return store.get( type );
  945. }
  946. };
  947. }
  948. } );