| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637 |
- /**
- * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
- */
- import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
- import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
- import UndoEditing from '@ckeditor/ckeditor5-undo/src/undoediting';
- import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
- import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
- import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
- import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
- import { modelTable, viewTable } from '../_utils/utils';
- import TableEditing from '../../src/tableediting';
- describe( 'downcast converters', () => {
- let editor, model, root, view;
- testUtils.createSinonSandbox();
- beforeEach( async () => {
- editor = await VirtualTestEditor.create( { plugins: [ Paragraph, TableEditing, UndoEditing ] } );
- model = editor.model;
- root = model.document.getRoot( 'main' );
- view = editor.editing.view;
- } );
- afterEach( () => {
- return editor.destroy();
- } );
- describe( 'downcastInsertTable()', () => {
- describe( 'editing pipeline', () => {
- it( 'should create table as a widget', () => {
- setModelData( model, modelTable( [ [ '' ] ] ) );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ),
- '<figure class="ck-widget ck-widget_with-selection-handle table" contenteditable="false">' +
- '<div class="ck ck-widget__selection-handle"></div>' +
- '<table>' +
- '<tbody>' +
- '<tr>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block"></span>' +
- '</td>' +
- '</tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- } );
- describe( 'data pipeline', () => {
- it( 'should create table with tbody and thead', () => {
- setModelData( model, modelTable( [
- [ '00' ],
- [ '10' ]
- ], { headingRows: 1 } ) );
- assertEqualMarkup( editor.getData(),
- '<figure class="table">' +
- '<table>' +
- '<thead>' +
- '<tr><th>00</th></tr>' +
- '</thead>' +
- '<tbody>' +
- '<tr><td>10</td></tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- it( 'should create table with thead', () => {
- setModelData( model, modelTable( [
- [ '00' ],
- [ '10' ]
- ], { headingRows: 2 } ) );
- assertEqualMarkup( editor.getData(),
- '<figure class="table">' +
- '<table>' +
- '<thead>' +
- '<tr><th>00</th></tr>' +
- '<tr><th>10</th></tr>' +
- '</thead>' +
- '</table>' +
- '</figure>'
- );
- } );
- it( 'should create table with heading columns and rows', () => {
- setModelData( model, modelTable( [
- [ '00', '01', '02', '03' ],
- [ '10', '11', '12', '13' ]
- ], { headingColumns: 3, headingRows: 1 } ) );
- assertEqualMarkup( editor.getData(),
- '<figure class="table">' +
- '<table>' +
- '<thead>' +
- '<tr><th>00</th><th>01</th><th>02</th><th>03</th></tr>' +
- '</thead>' +
- '<tbody>' +
- '<tr><th>10</th><th>11</th><th>12</th><td>13</td></tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- it( 'should create table with block content', () => {
- setModelData( model, modelTable( [
- [ '<paragraph>00</paragraph><paragraph>foo</paragraph>', '01' ]
- ] ) );
- assertEqualMarkup( editor.getData(),
- '<figure class="table">' +
- '<table>' +
- '<tbody>' +
- '<tr>' +
- '<td><p>00</p><p>foo</p></td>' +
- '<td>01</td>' +
- '</tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- it( 'should create table with block content (attribute on paragraph)', () => {
- editor.conversion.attributeToAttribute(
- {
- model: { key: 'alignment', values: [ 'right', 'center', 'justify' ] },
- view: {
- right: { key: 'style', value: { 'text-align': 'right' } },
- center: { key: 'style', value: { 'text-align': 'center' } },
- justify: { key: 'style', value: { 'text-align': 'justify' } }
- }
- }
- );
- setModelData( model, modelTable( [
- [ '<paragraph alignment="right">00</paragraph>' ]
- ] ) );
- assertEqualMarkup( editor.getData(),
- '<figure class="table">' +
- '<table>' +
- '<tbody>' +
- '<tr>' +
- '<td><p style="text-align:right;">00</p></td>' +
- '</tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- it( 'should be possible to overwrite', () => {
- editor.conversion.elementToElement( { model: 'tableRow', view: 'tr', converterPriority: 'high' } );
- editor.conversion.elementToElement( { model: 'tableCell', view: 'td', converterPriority: 'high' } );
- editor.conversion.for( 'downcast' ).add( dispatcher => {
- dispatcher.on( 'insert:table', ( evt, data, conversionApi ) => {
- conversionApi.consumable.consume( data.item, 'insert' );
- const tableElement = conversionApi.writer.createContainerElement( 'table', { foo: 'bar' } );
- const viewPosition = conversionApi.mapper.toViewPosition( data.range.start );
- conversionApi.mapper.bindElements( data.item, tableElement );
- conversionApi.writer.insert( viewPosition, tableElement );
- }, { priority: 'high' } );
- } );
- setModelData( model, modelTable( [ [ '' ] ] ) );
- assertEqualMarkup( editor.getData(),
- '<table foo="bar">' +
- '<tr><td><p> </p></td></tr>' +
- '</table>'
- );
- } );
- it( 'should re-create table on reinsert', () => {
- model.schema.register( 'wrapper', {
- allowWhere: '$block',
- allowContentOf: '$root'
- } );
- editor.conversion.elementToElement( { model: 'wrapper', view: 'div' } );
- setModelData( model, modelTable( [ [ '[]' ] ] ) );
- assertEqualMarkup( editor.getData(),
- '<figure class="table">' +
- '<table>' +
- '<tbody>' +
- '<tr><td> </td></tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- model.change( writer => {
- const table = model.document.getRoot().getChild( 0 );
- const range = writer.createRange( writer.createPositionBefore( table ), writer.createPositionAfter( table ) );
- const wrapper = writer.createElement( 'wrapper' );
- writer.wrap( range, wrapper );
- } );
- assertEqualMarkup( editor.getData(),
- '<div>' +
- '<figure class="table">' +
- '<table>' +
- '<tbody>' +
- '<tr><td> </td></tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>' +
- '</div>'
- );
- } );
- describe( 'headingColumns attribute', () => {
- it( 'should mark heading columns table cells', () => {
- setModelData( model, modelTable( [
- [ '00', '01', '02' ],
- [ '10', '11', '12' ]
- ], { headingColumns: 2 } ) );
- assertEqualMarkup( editor.getData(),
- '<figure class="table">' +
- '<table>' +
- '<tbody>' +
- '<tr><th>00</th><th>01</th><td>02</td></tr>' +
- '<tr><th>10</th><th>11</th><td>12</td></tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- it( 'should mark heading columns table cells when one has colspan attribute', () => {
- setModelData( model, modelTable( [
- [ '00', '01', '02', '03' ],
- [ { colspan: 2, contents: '10' }, '12', '13' ]
- ], { headingColumns: 3 } ) );
- assertEqualMarkup( editor.getData(),
- '<figure class="table">' +
- '<table>' +
- '<tbody>' +
- '<tr><th>00</th><th>01</th><th>02</th><td>03</td></tr>' +
- '<tr><th colspan="2">10</th><th>12</th><td>13</td></tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- it( 'should work with colspan and rowspan attributes on table cells', () => {
- // The table in this test looks like a table below:
- //
- // Row headings | Normal cells
- // |
- // +----+----+----+----+
- // | 00 | 01 | 02 | 03 |
- // | +----+ +----+
- // | | 11 | | 13 |
- // |----+----+ +----+
- // | 20 | | 23 |
- // | +----+----+
- // | | 32 | 33 |
- // +----+----+----+----+
- setModelData( model, modelTable( [
- [ { rowspan: 2, contents: '00' }, '01', { rowspan: 3, contents: '02' }, '03' ],
- [ '11', '13' ],
- [ { colspan: 2, rowspan: 2, contents: '20' }, '23' ],
- [ '32', '33' ]
- ], { headingColumns: 3 } ) );
- assertEqualMarkup( editor.getData(),
- '<figure class="table">' +
- '<table>' +
- '<tbody>' +
- '<tr><th rowspan="2">00</th><th>01</th><th rowspan="3">02</th><td>03</td></tr>' +
- '<tr><th>11</th><td>13</td></tr>' +
- '<tr><th rowspan="2" colspan="2">20</th><td>23</td></tr>' +
- '<tr><th>32</th><td>33</td></tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- } );
- it( 'should create table with tbody', () => {
- setModelData( model, modelTable( [ [ '' ] ] ) );
- assertEqualMarkup( editor.getData(),
- '<figure class="table">' +
- '<table>' +
- '<tbody>' +
- '<tr><td> </td></tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- } );
- } );
- describe( 'downcastInsertRow()', () => {
- // The insert row downcast conversion is not executed in data pipeline.
- describe( 'editing pipeline', () => {
- it( 'should react to changed rows', () => {
- setModelData( model, modelTable( [
- [ '00', '01' ]
- ] ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- const row = writer.createElement( 'tableRow' );
- writer.insert( row, table, 1 );
- writer.insertElement( 'tableCell', row, 'end' );
- writer.insertElement( 'tableCell', row, 'end' );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ '00', '01' ],
- [ '', '' ]
- ], { asWidget: true } ) );
- } );
- it( 'should properly consume already added rows', () => {
- setModelData( model, modelTable( [
- [ '00', '01' ]
- ] ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- const row = writer.createElement( 'tableRow' );
- writer.insert( row, table, 1 );
- writer.insertElement( 'tableCell', row, 'end' );
- writer.insertElement( 'tableCell', row, 'end' );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ '00', '01' ],
- [ '', '' ]
- ], { asWidget: true } ) );
- model.change( writer => {
- const row = writer.createElement( 'tableRow' );
- writer.insert( row, table, 2 );
- writer.insertElement( 'tableCell', row, 'end' );
- writer.insertElement( 'tableCell', row, 'end' );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ '00', '01' ],
- [ '', '' ],
- [ '', '' ]
- ], { asWidget: true } ) );
- } );
- it( 'should insert row on proper index', () => {
- setModelData( model, modelTable( [
- [ '00', '01' ],
- [ '21', '22' ],
- [ '31', '32' ]
- ] ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- const row = writer.createElement( 'tableRow' );
- writer.insert( row, table, 1 );
- writer.insertElement( 'tableCell', row, 'end' );
- writer.insertElement( 'tableCell', row, 'end' );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ '00', '01' ],
- [ '', '' ],
- [ '21', '22' ],
- [ '31', '32' ]
- ], { asWidget: true } ) );
- } );
- it( 'should insert row on proper index when table has heading rows defined - insert in body', () => {
- setModelData( model, modelTable( [
- [ '00', '01' ],
- [ '21', '22' ],
- [ '31', '32' ]
- ], { headingRows: 1, asWidget: true } ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- const row = writer.createElement( 'tableRow' );
- writer.insert( row, table, 1 );
- writer.insertElement( 'tableCell', row, 'end' );
- writer.insertElement( 'tableCell', row, 'end' );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ '00', '01' ],
- [ '', '' ],
- [ '21', '22' ],
- [ '31', '32' ]
- ], { headingRows: 1, asWidget: true } ) );
- } );
- it( 'should insert row on proper index when table has heading rows defined - insert in heading', () => {
- setModelData( model, modelTable( [
- [ '00', '01' ],
- [ '21', '22' ],
- [ '31', '32' ]
- ], { headingRows: 2 } ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- const row = writer.createElement( 'tableRow' );
- writer.insert( row, table, 1 );
- writer.insertElement( 'tableCell', row, 'end' );
- writer.insertElement( 'tableCell', row, 'end' );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ '00', '01' ],
- [ '', '' ],
- [ '21', '22' ],
- [ '31', '32' ]
- ], { headingRows: 3, asWidget: true } ) );
- } );
- it( 'should react to changed rows when previous rows\' cells has rowspans', () => {
- setModelData( model, modelTable( [
- [ { rowspan: 2, contents: '00' }, '01' ],
- [ '22' ]
- ] ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- const row = writer.createElement( 'tableRow' );
- writer.insert( row, table, 2 );
- writer.insertElement( 'tableCell', row, 'end' );
- writer.insertElement( 'tableCell', row, 'end' );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ { rowspan: 2, contents: '00' }, '01' ],
- [ '22' ],
- [ '', '' ]
- ], { asWidget: true } ) );
- } );
- it( 'should properly create row headings', () => {
- setModelData( model, modelTable( [
- [ { rowspan: 2, contents: '00' }, '01' ],
- [ '22' ]
- ], { headingColumns: 1 } ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- const firstRow = writer.createElement( 'tableRow' );
- writer.insert( firstRow, table, 2 );
- writer.insert( writer.createElement( 'tableCell' ), firstRow, 'end' );
- const secondRow = writer.createElement( 'tableRow' );
- writer.insert( secondRow, table, 3 );
- writer.insert( writer.createElement( 'tableCell' ), secondRow, 'end' );
- writer.insert( writer.createElement( 'tableCell' ), secondRow, 'end' );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ { rowspan: 2, contents: '00', isHeading: true }, '01' ],
- [ '22' ],
- [ { contents: '', isHeading: true }, '' ],
- [ { contents: '', isHeading: true }, '' ]
- ], { asWidget: true } ) );
- } );
- it( 'should create table cell inside inserted row as a widget', () => {
- setModelData( model, modelTable( [ [ '00' ] ] ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- const firstRow = writer.createElement( 'tableRow' );
- writer.insert( firstRow, table, 1 );
- writer.insert( writer.createElement( 'tableCell' ), firstRow, 'end' );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ),
- '<figure class="ck-widget ck-widget_with-selection-handle table" contenteditable="false">' +
- '<div class="ck ck-widget__selection-handle"></div>' +
- '<table>' +
- '<tbody>' +
- '<tr>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">00</span>' +
- '</td>' +
- '</tr>' +
- '<tr>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block"></span>' +
- '</td>' +
- '</tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- } );
- } );
- describe( 'downcastInsertCell()', () => {
- // The insert table cell downcast conversion is not executed in data pipeline.
- describe( 'editing pipeline', () => {
- it( 'should add tableCell on proper index in tr', () => {
- setModelData( model, modelTable( [
- [ '00', '01' ]
- ] ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- const row = table.getChild( 0 );
- writer.insertElement( 'tableCell', row, 1 );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ '00', '', '01' ]
- ], { asWidget: true } ) );
- } );
- it( 'should add tableCell on proper index in tr when previous have colspans', () => {
- setModelData( model, modelTable( [
- [ { colspan: 2, contents: '00' }, '13' ]
- ] ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- const row = table.getChild( 0 );
- writer.insertElement( 'tableCell', row, 1 );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ { colspan: 2, contents: '00' }, '', '13' ]
- ], { asWidget: true } ) );
- } );
- it( 'should add tableCell on proper index in tr when previous row have rowspans', () => {
- setModelData( model, modelTable( [
- [ { rowspan: 2, contents: '00' }, '01', '02' ],
- [ '11', '12' ]
- ] ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- writer.insertElement( 'tableCell', table.getChild( 0 ), 1 );
- writer.insertElement( 'tableCell', table.getChild( 1 ), 0 );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ { rowspan: 2, contents: '00' }, '', '01', '02' ],
- [ '', '11', '12' ]
- ], { asWidget: true } ) );
- } );
- it( 'split cell simulation - simple', () => {
- setModelData( model, modelTable( [
- [ '00', '01' ],
- [ '10', '11' ]
- ] ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- const firstRow = table.getChild( 0 );
- const secondRow = table.getChild( 1 );
- writer.insertElement( 'tableCell', firstRow, 1 );
- writer.setAttribute( 'colspan', 2, secondRow.getChild( 0 ) );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ '00', '', '01' ],
- [ { colspan: 2, contents: '10' }, '11' ]
- ], { asWidget: true } ) );
- } );
- it( 'merge simulation - simple', () => {
- setModelData( model, modelTable( [
- [ '00', '01' ],
- [ '10', '11' ]
- ] ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- const firstRow = table.getChild( 0 );
- writer.setAttribute( 'colspan', 2, firstRow.getChild( 0 ) );
- writer.remove( firstRow.getChild( 1 ) );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ { colspan: 2, contents: '00' } ],
- [ '10', '11' ]
- ], { asWidget: true } ) );
- } );
- it( 'should create inserted table cell as a widget', () => {
- setModelData( model, modelTable( [ [ '00' ] ] ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- const row = table.getChild( 0 );
- writer.insert( writer.createElement( 'tableCell' ), row, 'end' );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ),
- '<figure class="ck-widget ck-widget_with-selection-handle table" contenteditable="false">' +
- '<div class="ck ck-widget__selection-handle"></div>' +
- '<table>' +
- '<tbody>' +
- '<tr>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">00</span>' +
- '</td>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block"></span>' +
- '</td>' +
- '</tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- } );
- } );
- describe( 'downcastTableHeadingColumnsChange()', () => {
- // The heading columns change downcast conversion is not executed in data pipeline.
- describe( 'editing pipeline', () => {
- it( 'should work for adding heading columns', () => {
- setModelData( model, modelTable( [
- [ '00', '01' ],
- [ '10', '11' ]
- ] ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- writer.setAttribute( 'headingColumns', 1, table );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ { isHeading: true, contents: '00' }, '01' ],
- [ { isHeading: true, contents: '10' }, '11' ]
- ], { headingColumns: 1, asWidget: true } ) );
- } );
- it( 'should work for changing heading columns to a bigger number', () => {
- setModelData( model, modelTable( [
- [ '00', '01', '02', '03' ],
- [ '10', '11', '12', '13' ]
- ], { headingColumns: 1 } ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- writer.setAttribute( 'headingColumns', 3, table );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ { isHeading: true, contents: '00' }, { isHeading: true, contents: '01' }, { isHeading: true, contents: '02' }, '03' ],
- [ { isHeading: true, contents: '10' }, { isHeading: true, contents: '11' }, { isHeading: true, contents: '12' }, '13' ]
- ], { asWidget: true } ) );
- } );
- it( 'should work for changing heading columns to a smaller number', () => {
- setModelData( model, modelTable( [
- [ { isHeading: true, contents: '00' }, { isHeading: true, contents: '01' }, { isHeading: true, contents: '02' }, '03' ],
- [ { isHeading: true, contents: '10' }, { isHeading: true, contents: '11' }, { isHeading: true, contents: '12' }, '13' ]
- ], { headingColumns: 3 } ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- writer.setAttribute( 'headingColumns', 1, table );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ { isHeading: true, contents: '00' }, '01', '02', '03' ],
- [ { isHeading: true, contents: '10' }, '11', '12', '13' ]
- ], { headingColumns: 3, asWidget: true } ) );
- } );
- it( 'should work for removing heading columns', () => {
- setModelData( model, modelTable( [
- [ '00', '01' ],
- [ '10', '11' ]
- ], { headingColumns: 1 } ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- writer.removeAttribute( 'headingColumns', table );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ '00', '01' ],
- [ '10', '11' ]
- ], { asWidget: true } ) );
- } );
- it( 'should be possible to overwrite', () => {
- editor.conversion.attributeToAttribute( { model: 'headingColumns', view: 'headingColumns', converterPriority: 'high' } );
- setModelData( model, modelTable( [ [ '00[] ' ] ] ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- writer.setAttribute( 'headingColumns', 1, table );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ),
- '<figure class="ck-widget ck-widget_with-selection-handle table" contenteditable="false" headingColumns="1">' +
- '<div class="ck ck-widget__selection-handle"></div>' +
- '<table>' +
- '<tbody>' +
- '<tr>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">00</span>' +
- '</td>' +
- '</tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- it( 'should work with adding table cells', () => {
- setModelData( model, modelTable( [
- [ { rowspan: 2, contents: '00' }, '01', '13', '14' ],
- [ '11', '12', '13' ],
- [ { colspan: 2, contents: '20' }, '22', '23' ]
- ], { headingColumns: 2 } ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- // Inserting column in heading columns so update table's attribute also
- writer.setAttribute( 'headingColumns', 3, table );
- writer.insertElement( 'tableCell', table.getChild( 0 ), 2 );
- writer.insertElement( 'tableCell', table.getChild( 1 ), 1 );
- writer.insertElement( 'tableCell', table.getChild( 2 ), 1 );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [
- { isHeading: true, rowspan: 2, contents: '00' },
- { isHeading: true, contents: '01' },
- { isHeading: true, contents: '' },
- '13',
- '14'
- ],
- [
- { isHeading: true, contents: '11' },
- { isHeading: true, contents: '' },
- '12',
- '13'
- ],
- [
- { isHeading: true, colspan: 2, contents: '20' },
- { isHeading: true, contents: '' },
- '22',
- '23'
- ]
- ], { asWidget: true } ) );
- } );
- it( 'should create renamed cell as a widget', () => {
- setModelData( model, modelTable( [ [ '00' ] ] ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- writer.setAttribute( 'headingRows', 1, table );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ),
- '<figure class="ck-widget ck-widget_with-selection-handle table" contenteditable="false">' +
- '<div class="ck ck-widget__selection-handle"></div>' +
- '<table>' +
- '<thead>' +
- '<tr>' +
- '<th class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">00</span>' +
- '</th>' +
- '</tr>' +
- '</thead>' +
- '</table>' +
- '</figure>'
- );
- } );
- } );
- } );
- describe( 'downcastTableHeadingRowsChange', () => {
- // The heading rows change downcast conversion is not executed in data pipeline.
- // Note that headingRows table attribute triggers whole table downcast.
- describe( 'editing pipeline', () => {
- it( 'should work for adding heading rows', () => {
- setModelData( model, modelTable( [
- [ '00', '01' ],
- [ '10', '11' ],
- [ '20', '21' ]
- ] ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- writer.setAttribute( 'headingRows', 2, table );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ '00', '01' ],
- [ '10', '11' ],
- [ '20', '21' ]
- ], { headingRows: 2, asWidget: true } ) );
- } );
- it( 'should work for changing number of heading rows to a bigger number', () => {
- setModelData( model, modelTable( [
- [ '00', '01' ],
- [ '10', '11' ],
- [ '20', '21' ]
- ], { headingRows: 1 } ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- writer.setAttribute( 'headingRows', 2, table );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ '00', '01' ],
- [ '10', '11' ],
- [ '20', '21' ]
- ], { headingRows: 2, asWidget: true } ) );
- } );
- it( 'should work for changing number of heading rows to a smaller number', () => {
- setModelData( model, modelTable( [
- [ '00', '01' ],
- [ '10', '11' ],
- [ '20', '21' ],
- [ '30', '31' ]
- ], { headingRows: 3 } ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- writer.setAttribute( 'headingRows', 2, table );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ '00', '01' ],
- [ '10', '11' ],
- [ '20', '21' ],
- [ '30', '31' ]
- ], { headingRows: 2, asWidget: true } ) );
- } );
- it( 'should work for removing heading rows', () => {
- setModelData( model, modelTable( [
- [ '00', '01' ],
- [ '10', '11' ]
- ], { headingRows: 2 } ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- writer.removeAttribute( 'headingRows', table );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ '00', '01' ],
- [ '10', '11' ]
- ], { asWidget: true } ) );
- } );
- it( 'should work for making heading rows without tbody', () => {
- setModelData( model, modelTable( [
- [ '00', '01' ],
- [ '10', '11' ]
- ] ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- writer.setAttribute( 'headingRows', 2, table );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ '00', '01' ],
- [ '10', '11' ]
- ], { headingRows: 2, asWidget: true } ) );
- } );
- it( 'should work with adding table rows at the beginning of a table', () => {
- setModelData( model, modelTable( [
- [ '00', '01' ],
- [ '10', '11' ]
- ], { headingRows: 1 } ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- writer.setAttribute( 'headingRows', 2, table );
- const tableRow = writer.createElement( 'tableRow' );
- writer.insert( tableRow, table, 0 );
- writer.insertElement( 'tableCell', tableRow, 'end' );
- writer.insertElement( 'tableCell', tableRow, 'end' );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ '', '' ],
- [ '00', '01' ],
- [ '10', '11' ]
- ], { headingRows: 2, asWidget: true } ) );
- } );
- it( 'should work with adding a table row and expanding heading', () => {
- setModelData( model, modelTable( [
- [ '00', '01' ],
- [ '10', '11' ],
- [ '20', '21' ]
- ], { headingRows: 1 } ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- writer.setAttribute( 'headingRows', 2, table );
- const tableRow = writer.createElement( 'tableRow' );
- writer.insert( tableRow, table, 1 );
- writer.insertElement( 'tableCell', tableRow, 'end' );
- writer.insertElement( 'tableCell', tableRow, 'end' );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ '00', '01' ],
- [ '', '' ],
- [ '10', '11' ],
- [ '20', '21' ]
- ], { headingRows: 2, asWidget: true } ) );
- } );
- it( 'should create renamed cell as a widget', () => {
- setModelData( model, modelTable( [ [ '00' ] ] ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- writer.setAttribute( 'headingColumns', 1, table );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ),
- '<figure class="ck-widget ck-widget_with-selection-handle table" contenteditable="false">' +
- '<div class="ck ck-widget__selection-handle"></div>' +
- '<table>' +
- '<tbody>' +
- '<tr>' +
- '<th class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">00</span>' +
- '</th>' +
- '</tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- it( 'should properly integrate with undo', () => {
- setModelData( model, modelTable( [
- [ '00', '01' ],
- [ '10', '11' ],
- [ '20', '21' ]
- ], { headingRows: 1 } ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- writer.setAttribute( 'headingRows', 2, table );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ '00', '01' ],
- [ '10', '11' ],
- [ '20', '21' ]
- ], { headingRows: 2, asWidget: true } ) );
- editor.execute( 'undo' );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ '00', '01' ],
- [ '10', '11' ],
- [ '20', '21' ]
- ], { headingRows: 1, asWidget: true } ) );
- } );
- } );
- } );
- describe( 'downcastRemoveRow()', () => {
- // The remove row downcast conversion is not executed in data pipeline.
- describe( 'editing pipeline', () => {
- it( 'should react to removed row from the beginning of a body rows (no heading rows)', () => {
- setModelData( model, modelTable( [
- [ '00[]', '01' ],
- [ '10', '11' ]
- ] ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- writer.remove( table.getChild( 1 ) );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ),
- '<figure class="ck-widget ck-widget_with-selection-handle table" contenteditable="false">' +
- '<div class="ck ck-widget__selection-handle"></div>' +
- '<table>' +
- '<tbody>' +
- '<tr>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">00</span>' +
- '</td>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">01</span>' +
- '</td>' +
- '</tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- it( 'should react to removed row from the end of a body rows (no heading rows)', () => {
- setModelData( model, modelTable( [
- [ '00[]', '01' ],
- [ '10', '11' ]
- ] ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- writer.remove( table.getChild( 0 ) );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ),
- '<figure class="ck-widget ck-widget_with-selection-handle table" contenteditable="false">' +
- '<div class="ck ck-widget__selection-handle"></div>' +
- '<table>' +
- '<tbody>' +
- '<tr>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">10</span>' +
- '</td>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">11</span>' +
- '</td>' +
- '</tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- it( 'should react to removed row from the beginning of a heading rows (no body rows)', () => {
- setModelData( model, modelTable( [
- [ '00[]', '01' ],
- [ '10', '11' ]
- ], { headingRows: 2 } ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- // Removing row from a heading section changes requires changing heading rows attribute.
- writer.setAttribute( 'headingRows', 1, table );
- writer.remove( table.getChild( 0 ) );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ),
- '<figure class="ck-widget ck-widget_with-selection-handle table" contenteditable="false">' +
- '<div class="ck ck-widget__selection-handle"></div>' +
- '<table>' +
- '<thead>' +
- '<tr>' +
- '<th class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">10</span>' +
- '</th>' +
- '<th class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">11</span>' +
- '</th>' +
- '</tr>' +
- '</thead>' +
- '</table>' +
- '</figure>'
- );
- } );
- it( 'should react to removed row from the end of a heading rows (no body rows)', () => {
- setModelData( model, modelTable( [
- [ '00[]', '01' ],
- [ '10', '11' ]
- ], { headingRows: 2 } ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- // Removing row from a heading section changes requires changing heading rows attribute.
- writer.setAttribute( 'headingRows', 1, table );
- writer.remove( table.getChild( 1 ) );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ),
- '<figure class="ck-widget ck-widget_with-selection-handle table" contenteditable="false">' +
- '<div class="ck ck-widget__selection-handle"></div>' +
- '<table>' +
- '<thead>' +
- '<tr>' +
- '<th class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">00</span>' +
- '</th>' +
- '<th class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">01</span>' +
- '</th>' +
- '</tr>' +
- '</thead>' +
- '</table>' +
- '</figure>'
- );
- } );
- it( 'should react to removed row from the end of a heading rows (first cell in body has colspan)', () => {
- setModelData( model, modelTable( [
- [ '00[]', '01', '02', '03' ],
- [ { rowspan: 2, colspan: 2, contents: '10' }, '12', '13' ],
- [ '22', '23' ]
- ], { headingRows: 1 } ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- // Removing row from a heading section changes requires changing heading rows attribute.
- writer.remove( table.getChild( 0 ) );
- writer.setAttribute( 'headingRows', 0, table );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ),
- '<figure class="ck-widget ck-widget_with-selection-handle table" contenteditable="false">' +
- '<div class="ck ck-widget__selection-handle"></div>' +
- '<table>' +
- '<tbody>' +
- '<tr>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" ' +
- 'colspan="2" contenteditable="true" rowspan="2">' +
- '<span style="display:inline-block">10</span>' +
- '</td>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">12</span>' +
- '</td>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">13</span>' +
- '</td>' +
- '</tr>' +
- '<tr>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">22</span>' +
- '</td>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">23</span>' +
- '</td>' +
- '</tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- it( 'should remove empty thead if a last row was removed from a heading rows (has heading and body)', () => {
- setModelData( model, modelTable( [
- [ '00[]', '01' ],
- [ '10', '11' ]
- ], { headingRows: 1 } ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- // Removing row from a heading section changes requires changing heading rows attribute.
- writer.removeAttribute( 'headingRows', table );
- writer.remove( table.getChild( 0 ) );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ),
- '<figure class="ck-widget ck-widget_with-selection-handle table" contenteditable="false">' +
- '<div class="ck ck-widget__selection-handle"></div>' +
- '<table>' +
- '<tbody>' +
- '<tr>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">10</span>' +
- '</td>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">11</span>' +
- '</td>' +
- '</tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- it( 'should remove empty tbody if a last row was removed a body rows (has heading and body)', () => {
- setModelData( model, modelTable( [
- [ '00[]', '01' ],
- [ '10', '11' ]
- ], { headingRows: 1 } ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- writer.remove( table.getChild( 1 ) );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ),
- '<figure class="ck-widget ck-widget_with-selection-handle table" contenteditable="false">' +
- '<div class="ck ck-widget__selection-handle"></div>' +
- '<table>' +
- '<thead>' +
- '<tr>' +
- '<th class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">00</span>' +
- '</th>' +
- '<th class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">01</span>' +
- '</th>' +
- '</tr>' +
- '</thead>' +
- '</table>' +
- '</figure>'
- );
- } );
- } );
- } );
- describe( 'marker highlight conversion on table cell', () => {
- describe( 'single class in highlight descriptor', () => {
- beforeEach( async () => {
- editor = await VirtualTestEditor.create( { plugins: [ Paragraph, TableEditing ] } );
- model = editor.model;
- root = model.document.getRoot( 'main' );
- view = editor.editing.view;
- markerConversion( editor.conversion );
- } );
- it( 'should apply marker class on tableCell - on inserting a table', () => {
- setModelData( model, modelTable( [ [ '00' ] ] ) );
- model.change( writer => {
- const cell = root.getNodeByPath( [ 0, 0, 0 ] );
- writer.addMarker( 'marker:yellow', {
- range: writer.createRangeOn( cell ),
- usingOperation: false
- } );
- checkCustomPropertyForHighlight( editor.editing.mapper.toViewElement( cell ) );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ),
- '<figure class="ck-widget ck-widget_with-selection-handle table" contenteditable="false">' +
- '<div class="ck ck-widget__selection-handle"></div>' +
- '<table>' +
- '<tbody>' +
- '<tr>' +
- '<td class="ck-editor__editable ck-editor__nested-editable highlight-yellow" contenteditable="true">' +
- '<span style="display:inline-block">00</span>' +
- '</td>' +
- '</tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- model.change( writer => {
- writer.removeMarker( 'marker:yellow' );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ),
- '<figure class="ck-widget ck-widget_with-selection-handle table" contenteditable="false">' +
- '<div class="ck ck-widget__selection-handle"></div>' +
- '<table>' +
- '<tbody>' +
- '<tr>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">00</span>' +
- '</td>' +
- '</tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- it( 'should apply marker class on tableCell - on inserting a row', () => {
- setModelData( model, modelTable( [ [ '00' ] ] ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- const firstRow = writer.createElement( 'tableRow' );
- const cell = writer.createElement( 'tableCell' );
- writer.insert( firstRow, table, 1 );
- writer.insert( cell, firstRow, 'end' );
- writer.addMarker( 'marker:yellow', {
- range: writer.createRangeOn( cell ),
- usingOperation: false
- } );
- } );
- const cell = root.getNodeByPath( [ 0, 1, 0 ] );
- checkCustomPropertyForHighlight( editor.editing.mapper.toViewElement( cell ) );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ),
- '<figure class="ck-widget ck-widget_with-selection-handle table" contenteditable="false">' +
- '<div class="ck ck-widget__selection-handle"></div>' +
- '<table>' +
- '<tbody>' +
- '<tr>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">00</span>' +
- '</td>' +
- '</tr>' +
- '<tr>' +
- '<td class="ck-editor__editable ck-editor__nested-editable highlight-yellow" contenteditable="true">' +
- '<span style="display:inline-block"></span>' +
- '</td>' +
- '</tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- model.change( writer => {
- writer.removeMarker( 'marker:yellow' );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ),
- '<figure class="ck-widget ck-widget_with-selection-handle table" contenteditable="false">' +
- '<div class="ck ck-widget__selection-handle"></div>' +
- '<table>' +
- '<tbody>' +
- '<tr>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">00</span>' +
- '</td>' +
- '</tr>' +
- '<tr>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block"></span>' +
- '</td>' +
- '</tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- it( 'should apply marker class on tableCell - on inserting a table cell', () => {
- setModelData( model, modelTable( [ [ '00' ] ] ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- const row = table.getChild( 0 );
- const cell = writer.createElement( 'tableCell' );
- writer.insert( cell, row, 'end' );
- writer.addMarker( 'marker:yellow', {
- range: writer.createRangeOn( cell ),
- usingOperation: false
- } );
- } );
- const cell = root.getNodeByPath( [ 0, 0, 1 ] );
- checkCustomPropertyForHighlight( editor.editing.mapper.toViewElement( cell ) );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ),
- '<figure class="ck-widget ck-widget_with-selection-handle table" contenteditable="false">' +
- '<div class="ck ck-widget__selection-handle"></div>' +
- '<table>' +
- '<tbody>' +
- '<tr>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">00</span>' +
- '</td>' +
- '<td class="ck-editor__editable ck-editor__nested-editable highlight-yellow" contenteditable="true">' +
- '<span style="display:inline-block"></span>' +
- '</td>' +
- '</tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- model.change( writer => {
- writer.removeMarker( 'marker:yellow' );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ),
- '<figure class="ck-widget ck-widget_with-selection-handle table" contenteditable="false">' +
- '<div class="ck ck-widget__selection-handle"></div>' +
- '<table>' +
- '<tbody>' +
- '<tr>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">00</span>' +
- '</td>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block"></span>' +
- '</td>' +
- '</tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- it( 'should preserve marker class on tableCell - when changing heading columns', () => {
- setModelData( model, modelTable( [
- [ '00', '01', '02', '03' ],
- [ '10', '11', '12', '13' ]
- ], { headingColumns: 1 } ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- const cell = root.getNodeByPath( [ 0, 0, 1 ] );
- writer.addMarker( 'marker:yellow', {
- range: writer.createRangeOn( cell ),
- usingOperation: false
- } );
- } );
- model.change( writer => {
- writer.setAttribute( 'headingColumns', 3, table );
- } );
- const cell = root.getNodeByPath( [ 0, 0, 1 ] );
- const viewElement = editor.editing.mapper.toViewElement( cell );
- checkCustomPropertyForHighlight( viewElement );
- expect( viewElement.hasClass( 'highlight-yellow' ) ).to.be.true;
- model.change( writer => {
- writer.removeMarker( 'marker:yellow' );
- } );
- expect( viewElement.hasClass( 'highlight-yellow' ) ).to.be.false;
- } );
- it( 'should preserve marker class on tableCell - when changing heading rows', () => {
- setModelData( model, modelTable( [
- [ '00', '01' ],
- [ '10', '11' ],
- [ '20', '21' ]
- ], { headingRows: 1 } ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- const cell = root.getNodeByPath( [ 0, 1, 0 ] );
- writer.addMarker( 'marker:yellow', {
- range: writer.createRangeOn( cell ),
- usingOperation: false
- } );
- } );
- model.change( writer => {
- writer.setAttribute( 'headingRows', 2, table );
- } );
- const cell = root.getNodeByPath( [ 0, 1, 0 ] );
- const viewElement = editor.editing.mapper.toViewElement( cell );
- checkCustomPropertyForHighlight( viewElement );
- expect( viewElement.hasClass( 'highlight-yellow' ) ).to.be.true;
- model.change( writer => {
- writer.removeMarker( 'marker:yellow' );
- } );
- expect( viewElement.hasClass( 'highlight-yellow' ) ).to.be.false;
- } );
- } );
- describe( 'multiple classes in highlight descriptor', () => {
- beforeEach( async () => {
- editor = await VirtualTestEditor.create( { plugins: [ Paragraph, TableEditing ] } );
- model = editor.model;
- root = model.document.getRoot( 'main' );
- view = editor.editing.view;
- markerConversion( editor.conversion, [ 'marker', 'user-marker' ] );
- } );
- it( 'should apply marker class on tableCell - on inserting a table', () => {
- setModelData( model, modelTable( [ [ '00' ] ] ) );
- model.change( writer => {
- const cell = root.getNodeByPath( [ 0, 0, 0 ] );
- writer.addMarker( 'marker:yellow', {
- range: writer.createRangeOn( cell ),
- usingOperation: false
- } );
- checkCustomPropertyForHighlight( editor.editing.mapper.toViewElement( cell ) );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ),
- '<figure class="ck-widget ck-widget_with-selection-handle table" contenteditable="false">' +
- '<div class="ck ck-widget__selection-handle"></div>' +
- '<table>' +
- '<tbody>' +
- '<tr>' +
- '<td class="ck-editor__editable ck-editor__nested-editable highlight-yellow marker user-marker"' +
- ' contenteditable="true">' +
- '<span style="display:inline-block">00</span>' +
- '</td>' +
- '</tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- model.change( writer => {
- writer.removeMarker( 'marker:yellow' );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ),
- '<figure class="ck-widget ck-widget_with-selection-handle table" contenteditable="false">' +
- '<div class="ck ck-widget__selection-handle"></div>' +
- '<table>' +
- '<tbody>' +
- '<tr>' +
- '<td class="ck-editor__editable ck-editor__nested-editable" contenteditable="true">' +
- '<span style="display:inline-block">00</span>' +
- '</td>' +
- '</tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- } );
- function markerConversion( conversion, extraClasses = null ) {
- conversion.for( 'editingDowncast' ).markerToHighlight( {
- model: 'marker',
- view: data => {
- const className = 'highlight-' + data.markerName.split( ':' )[ 1 ];
- return {
- classes: extraClasses ? [ ...extraClasses, className ] : className
- };
- }
- } );
- }
- function checkCustomPropertyForHighlight( viewElement ) {
- const set = viewElement.getCustomProperty( 'addHighlight' );
- const remove = viewElement.getCustomProperty( 'removeHighlight' );
- expect( typeof set ).to.equal( 'function' );
- expect( typeof remove ).to.equal( 'function' );
- }
- } );
- } );
|