|
|
@@ -7,9 +7,8 @@
|
|
|
* @module table/tableproperties/commands/tablebordercolorcommand
|
|
|
*/
|
|
|
|
|
|
-import Command from '@ckeditor/ckeditor5-core/src/command';
|
|
|
-
|
|
|
-import { findAncestor, getSingleValue } from '../../commands/utils';
|
|
|
+import TablePropertyCommand from './tablepropertycommand';
|
|
|
+import { getSingleValue } from '../../commands/utils';
|
|
|
|
|
|
/**
|
|
|
* The table border color command.
|
|
|
@@ -20,31 +19,24 @@ import { findAncestor, getSingleValue } from '../../commands/utils';
|
|
|
* To change border color of the selected , execute the command:
|
|
|
*
|
|
|
* editor.execute( 'tableBorderColor', {
|
|
|
- * value: '5px'
|
|
|
+ * value: '#f00'
|
|
|
* } );
|
|
|
*
|
|
|
- * @extends module:core/command~Command
|
|
|
+ * @extends module:table/tableproperties/commands/tablepropertycommand
|
|
|
*/
|
|
|
-export default class TableBorderColorCommand extends Command {
|
|
|
+export default class TableBorderColorCommand extends TablePropertyCommand {
|
|
|
+ /**
|
|
|
+ * Creates a new `TableBorderColorCommand` instance.
|
|
|
+ *
|
|
|
+ * @param {module:core/editor/editor~Editor} editor Editor on which this command will be used.
|
|
|
+ */
|
|
|
constructor( editor ) {
|
|
|
- super( editor );
|
|
|
-
|
|
|
- this.attributeName = 'borderColor';
|
|
|
+ super( editor, 'borderColor' );
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @inheritDoc
|
|
|
*/
|
|
|
- refresh() {
|
|
|
- const editor = this.editor;
|
|
|
- const selection = editor.model.document.selection;
|
|
|
-
|
|
|
- const table = findAncestor( 'table', selection.getFirstPosition() );
|
|
|
-
|
|
|
- this.isEnabled = !!table;
|
|
|
- this.value = this._getValue( table );
|
|
|
- }
|
|
|
-
|
|
|
_getValue( table ) {
|
|
|
if ( !table ) {
|
|
|
return;
|
|
|
@@ -52,30 +44,4 @@ export default class TableBorderColorCommand extends Command {
|
|
|
|
|
|
return getSingleValue( table.getAttribute( this.attributeName ) );
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * Executes the command.
|
|
|
- *
|
|
|
- * @fires execute
|
|
|
- * @param {Object} [options]
|
|
|
- * @param {Boolean} [options.value] If set the command will set border color.
|
|
|
- * If border color is not set the command will remove the attribute.
|
|
|
- */
|
|
|
- execute( options = {} ) {
|
|
|
- const model = this.editor.model;
|
|
|
- const selection = model.document.selection;
|
|
|
-
|
|
|
- const { value, batch } = options;
|
|
|
-
|
|
|
- const tables = Array.from( selection.getSelectedBlocks() )
|
|
|
- .map( element => findAncestor( 'table', model.createPositionAt( element, 0 ) ) );
|
|
|
-
|
|
|
- model.enqueueChange( batch || 'default', writer => {
|
|
|
- if ( value ) {
|
|
|
- tables.forEach( table => writer.setAttribute( this.attributeName, value, table ) );
|
|
|
- } else {
|
|
|
- tables.forEach( table => writer.removeAttribute( this.attributeName, table ) );
|
|
|
- }
|
|
|
- } );
|
|
|
- }
|
|
|
}
|