Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function renameViewTableCell( tableCell, desiredCellElementName, conversionApi, asWidget ) {
const viewWriter = conversionApi.writer;
const viewCell = conversionApi.mapper.toViewElement( tableCell );
// View cell might be not yet converted - skip it as it will be properly created by cell converter later on.
if ( !viewCell ) {
return;
}
let renamedCell;
if ( asWidget ) {
const editable = viewWriter.createEditableElement( desiredCellElementName, viewCell.getAttributes() );
renamedCell = toWidgetEditable( editable, viewWriter );
viewWriter.insert( viewWriter.createPositionAfter( viewCell ), renamedCell );
viewWriter.move( viewWriter.createRangeIn( viewCell ), viewWriter.createPositionAt( renamedCell, 0 ) );
viewWriter.remove( viewWriter.createRangeOn( viewCell ) );
} else {
renamedCell = viewWriter.rename( desiredCellElementName, viewCell );
}
conversionApi.mapper.unbindViewElement( viewCell );
conversionApi.mapper.bindElements( tableCell, renamedCell );
}
view: ( modelItem, viewWriter ) => {
return toWidgetEditable( viewWriter.createEditableElement( 'td' ), viewWriter );
}
} );
viewWriter
);
viewWriter.setCustomProperty( 'objectBlock', true, templateViewElement );
const viewSlots = findViewSlots( viewWriter.createRangeIn( templateViewElement ) );
const modelSlots = findObjectBlockModelSlots( modelElement );
if ( Object.keys( viewSlots ).sort().join( ',' ) != Object.keys( modelSlots ).sort().join( ',' ) ) {
throw new Error( 'Different set of slots in the template and in the model.' );
}
for ( const slotName of Object.keys( viewSlots ) ) {
editor.editing.mapper.bindElements( modelSlots[ slotName ], viewSlots[ slotName ] );
toWidgetEditable( viewSlots[ slotName ], viewWriter );
}
return toWidget( templateViewElement, viewWriter );
}
} );
return writer => {
const editable = writer.createEditableElement( 'figcaption' );
writer.setCustomProperty( 'imageCaption', true, editable );
enablePlaceholder( {
view,
element: editable,
text: placeholderText
} );
return toWidgetEditable( editable, writer );
};
}
function createViewTableCellElement( tableWalkerValue, tableAttributes, insertPosition, conversionApi, options ) {
const asWidget = options && options.asWidget;
const cellElementName = getCellElementName( tableWalkerValue, tableAttributes );
const cellElement = asWidget ?
toWidgetEditable( conversionApi.writer.createEditableElement( cellElementName ), conversionApi.writer ) :
conversionApi.writer.createContainerElement( cellElementName );
const tableCell = tableWalkerValue.cell;
const firstChild = tableCell.getChild( 0 );
const isSingleParagraph = tableCell.childCount === 1 && firstChild.name === 'paragraph';
conversionApi.writer.insert( insertPosition, cellElement );
if ( isSingleParagraph && !hasAnyAttribute( firstChild ) ) {
const innerParagraph = tableCell.getChild( 0 );
const paragraphInsertPosition = conversionApi.writer.createPositionAt( cellElement, 'end' );
conversionApi.consumable.consume( innerParagraph, 'insert' );
if ( options.asWidget ) {