| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753 |
- /**
- * @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 TableEditing from '../../src/tableediting';
- 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 { defaultConversion, defaultSchema, modelTable, viewTable } from '../_utils/utils';
- function paragraphInTableCell() {
- return dispatcher => dispatcher.on( 'insert:paragraph', ( evt, data, conversionApi ) => {
- const tableCell = data.item.parent;
- if ( tableCell.is( 'tableCell' ) && tableCell.childCount > 1 ) {
- for ( const child of tableCell.getChildren() ) {
- if ( child.name != 'paragraph' ) {
- continue;
- }
- const viewElement = conversionApi.mapper.toViewElement( child );
- if ( viewElement && viewElement.name === 'span' ) {
- conversionApi.mapper.unbindModelElement( tableCell );
- conversionApi.writer.removeStyle( 'display', viewElement );
- conversionApi.writer.rename( 'p', viewElement );
- conversionApi.mapper.bindElements( child, viewElement );
- }
- }
- }
- }, { converterPriority: 'highest' } );
- }
- describe( 'downcast converters', () => {
- let editor, model, doc, root, view;
- testUtils.createSinonSandbox();
- describe( 'downcastInsertTable()', () => {
- // The beforeEach is duplicated due to ckeditor/ckeditor5#6574. New test are written using TableEditing.
- beforeEach( () => {
- return VirtualTestEditor.create()
- .then( newEditor => {
- editor = newEditor;
- model = editor.model;
- doc = model.document;
- root = doc.getRoot( 'main' );
- view = editor.editing.view;
- defaultSchema( model.schema );
- defaultConversion( editor.conversion );
- } );
- } );
- it( 'should create table with tbody', () => {
- setModelData( model, modelTable( [ [ '' ] ] ) );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ),
- '<figure class="table">' +
- '<table>' +
- '<tbody>' +
- '<tr><td></td></tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- it( 'should create table with tbody and thead', () => {
- setModelData( model, modelTable( [
- [ '00' ],
- [ '10' ]
- ], { headingRows: 1 } ) );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ),
- '<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( getViewData( view, { withoutSelection: true } ),
- '<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( getViewData( view, { withoutSelection: true } ),
- '<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( getViewData( view, { withoutSelection: true } ),
- '<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( getViewData( view, { withoutSelection: true } ),
- '<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( getViewData( view, { withoutSelection: true } ),
- '<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( getViewData( view, { withoutSelection: true } ),
- '<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( getViewData( view, { withoutSelection: true } ),
- '<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( getViewData( view, { withoutSelection: true } ),
- '<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( getViewData( view, { withoutSelection: true } ),
- '<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( getViewData( view, { withoutSelection: true } ),
- '<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 colspan="2" rowspan="2">20</th><td>23</td></tr>' +
- '<tr><th>32</th><td>33</td></tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- } );
- describe( 'options.asWidget=true', () => {
- beforeEach( () => {
- return VirtualTestEditor.create()
- .then( newEditor => {
- editor = newEditor;
- model = editor.model;
- doc = model.document;
- root = doc.getRoot( 'main' );
- view = editor.editing.view;
- defaultSchema( model.schema );
- defaultConversion( editor.conversion, true );
- markerConversion( editor.conversion );
- } );
- } );
- 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>'
- );
- } );
- it( 'should apply marker class on tableCell', () => {
- 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>'
- );
- } );
- } );
- } );
- describe( 'downcastInsertRow()', () => {
- // The beforeEach is duplicated due to ckeditor/ckeditor5#6574. New test are written using TableEditing.
- beforeEach( () => {
- return VirtualTestEditor.create()
- .then( newEditor => {
- editor = newEditor;
- model = editor.model;
- doc = model.document;
- root = doc.getRoot( 'main' );
- view = editor.editing.view;
- defaultSchema( model.schema );
- defaultConversion( editor.conversion );
- } );
- } );
- 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' ],
- [ '', '' ]
- ] ) );
- } );
- 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' ],
- [ '', '' ]
- ] ) );
- 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' ],
- [ '', '' ],
- [ '', '' ]
- ] ) );
- } );
- 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' ]
- ] ) );
- } );
- 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 } ) );
- 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 } ) );
- } );
- 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 } ) );
- } );
- it( 'should react to changed rows when previous rows\' cells has rowspans', () => {
- setModelData( model, modelTable( [
- [ { rowspan: 3, 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' );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ { rowspan: 3, contents: '00' }, '01' ],
- [ '22' ],
- [ '' ]
- ] ) );
- } );
- it( 'should properly create row headings', () => {
- setModelData( model, modelTable( [
- [ { rowspan: 3, 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: 3, contents: '00', isHeading: true }, '01' ],
- [ '22' ],
- [ '' ],
- [ { contents: '', isHeading: true }, '' ]
- ] ) );
- } );
- describe( 'options.asWidget=true', () => {
- beforeEach( () => {
- return VirtualTestEditor.create()
- .then( newEditor => {
- editor = newEditor;
- model = editor.model;
- doc = model.document;
- root = doc.getRoot( 'main' );
- view = editor.editing.view;
- defaultSchema( model.schema );
- defaultConversion( editor.conversion, true );
- markerConversion( editor.conversion );
- } );
- } );
- 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"></td>' +
- '</tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- it( 'should apply marker class on tableCell', () => {
- 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"></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"></td>' +
- '</tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- } );
- } );
- describe( 'downcastInsertCell()', () => {
- // The beforeEach is duplicated due to ckeditor/ckeditor5#6574. New test are written using TableEditing.
- beforeEach( () => {
- return VirtualTestEditor.create()
- .then( newEditor => {
- editor = newEditor;
- model = editor.model;
- doc = model.document;
- root = doc.getRoot( 'main' );
- view = editor.editing.view;
- defaultSchema( model.schema );
- defaultConversion( editor.conversion );
- } );
- } );
- 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' ]
- ] ) );
- } );
- 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' ]
- ] ) );
- } );
- it( 'should add tableCell on proper index in tr when previous row have rowspans', () => {
- setModelData( model, modelTable( [
- [ { rowspan: 2, contents: '00' }, '13' ],
- [ '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' }, '', '13' ],
- [ '', '11', '12' ]
- ] ) );
- } );
- 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' ]
- ] ) );
- } );
- 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' ]
- ] ) );
- } );
- describe( 'options.asWidget=true', () => {
- beforeEach( () => {
- return VirtualTestEditor.create()
- .then( newEditor => {
- editor = newEditor;
- model = editor.model;
- doc = model.document;
- root = doc.getRoot( 'main' );
- view = editor.editing.view;
- defaultSchema( model.schema );
- defaultConversion( editor.conversion, true );
- markerConversion( editor.conversion );
- } );
- } );
- 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"></td>' +
- '</tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- it( 'should apply marker class on tableCell', () => {
- 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"></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"></td>' +
- '</tr>' +
- '</tbody>' +
- '</table>' +
- '</figure>'
- );
- } );
- } );
- } );
- describe( 'downcastTableHeadingColumnsChange()', () => {
- // The beforeEach is duplicated due to ckeditor/ckeditor5#6574. New test are written using TableEditing.
- beforeEach( () => {
- return VirtualTestEditor.create()
- .then( newEditor => {
- editor = newEditor;
- model = editor.model;
- doc = model.document;
- root = doc.getRoot( 'main' );
- view = editor.editing.view;
- defaultSchema( model.schema );
- defaultConversion( editor.conversion );
- } );
- } );
- 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 } ) );
- } );
- 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' ]
- ] ) );
- } );
- 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 } ) );
- } );
- 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' ]
- ] ) );
- } );
- 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="table" headingColumns="1">' +
- '<table>' +
- '<tbody>' +
- '<tr><td>00</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'
- ]
- ] ) );
- } );
- describe( 'options.asWidget=true', () => {
- beforeEach( () => {
- return VirtualTestEditor.create()
- .then( newEditor => {
- editor = newEditor;
- model = editor.model;
- doc = model.document;
- root = doc.getRoot( 'main' );
- view = editor.editing.view;
- defaultSchema( model.schema );
- defaultConversion( editor.conversion, true );
- markerConversion( editor.conversion );
- } );
- } );
- 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>'
- );
- } );
- it( 'should preserve marker class on tableCell', () => {
- 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;
- } );
- } );
- } );
- describe( 'downcastTableHeadingRowsChange()', () => {
- // The beforeEach is duplicated due to ckeditor/ckeditor5#6574. New test are written using TableEditing.
- beforeEach( () => {
- return VirtualTestEditor.create( { plugins: [ Paragraph, TableEditing ] } )
- .then( newEditor => {
- editor = newEditor;
- model = editor.model;
- doc = model.document;
- root = doc.getRoot( 'main' );
- view = editor.editing.view;
- markerConversion( editor.conversion, 'marker' );
- } );
- } );
- // The heading rows change downcast conversion is not executed in data pipeline.
- 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 be possible to overwrite', () => {
- editor.conversion.attributeToAttribute( {
- model: 'headingRows',
- view: 'headingRows',
- converterPriority: 'high'
- } );
- 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" headingRows="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 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 preserve marker class on tableCell', () => {
- 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( 'downcastRemoveRow()', () => {
- // The beforeEach is duplicated due to ckeditor/ckeditor5#6574. New test are written using TableEditing.
- beforeEach( async () => {
- editor = await VirtualTestEditor.create( { plugins: [ Paragraph, TableEditing ] } );
- model = editor.model;
- root = model.document.getRoot( 'main' );
- view = editor.editing.view;
- } );
- // 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 form 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 form 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 form 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( 'options.asWidget=true', () => {
- beforeEach( () => {
- return VirtualTestEditor.create()
- .then( newEditor => {
- editor = newEditor;
- model = editor.model;
- doc = model.document;
- root = doc.getRoot( 'main' );
- view = editor.editing.view;
- defaultSchema( model.schema );
- defaultConversion( editor.conversion, true );
- editor.conversion.for( 'downcast' ).add( paragraphInTableCell() );
- } );
- } );
- it( 'should rename <span> to <p> when more then one block content inside table cell', () => {
- setModelData( model, modelTable( [
- [ '00[]' ]
- ] ) );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ '00' ]
- ], { asWidget: true } ) );
- const table = root.getChild( 0 );
- model.change( writer => {
- const nodeByPath = table.getNodeByPath( [ 0, 0, 0 ] );
- const paragraph = writer.createElement( 'paragraph' );
- writer.insert( paragraph, nodeByPath, 'after' );
- writer.setSelection( nodeByPath.nextSibling, 0 );
- } );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ '<p>00</p><p></p>' ]
- ], { asWidget: true } ) );
- } );
- it( 'should rename <span> to <p> for single paragraph with attribute', () => {
- model.schema.extend( '$block', { allowAttributes: 'foo' } );
- editor.conversion.attributeToAttribute( { model: 'foo', view: 'foo' } );
- setModelData( model, modelTable( [
- [ '<paragraph foo="bar">00[]</paragraph>' ]
- ] ) );
- assertEqualMarkup( getViewData( view, { withoutSelection: true } ), viewTable( [
- [ '<p foo="bar">00</p>' ]
- ], { asWidget: true } ) );
- } );
- } );
- 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' );
- }
- } );
|