tablecellpaddingcommand.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /**
  6. * @module table/tablecellproperties/commands/tablecellpaddingcommand
  7. */
  8. import { addDefaultUnitToNumericValue, getSingleValue } from '../../commands/utils';
  9. import TableCellPropertyCommand from './tablecellpropertycommand';
  10. /**
  11. * The table cell padding command.
  12. *
  13. * The command is registered by the {@link module:table/tablecellproperties/tablecellpropertiesediting~TableCellPropertiesEditing} as
  14. * the `'tableCellPadding'` editor command.
  15. *
  16. * To change the padding of selected cells, execute the command:
  17. *
  18. * editor.execute( 'tableCellPadding', {
  19. * value: '5px'
  20. * } );
  21. *
  22. * **Note**: This command adds the default `'px'` unit to numeric values. Executing:
  23. *
  24. * editor.execute( 'tableCellPadding', {
  25. * value: '5'
  26. * } );
  27. *
  28. * will set the `padding` attribute to `'5px'` in the model.
  29. *
  30. * @extends module:table/tablecellproperties/commands/tablecellpropertycommand~TableCellPropertyCommand
  31. */
  32. export default class TableCellPaddingCommand extends TableCellPropertyCommand {
  33. /**
  34. * Creates a new `TableCellPaddingCommand` instance.
  35. *
  36. * @param {module:core/editor/editor~Editor} editor An editor in which this command will be used.
  37. */
  38. constructor( editor ) {
  39. super( editor, 'padding' );
  40. }
  41. /**
  42. * @inheritDoc
  43. */
  44. _getAttribute( tableCell ) {
  45. if ( !tableCell ) {
  46. return;
  47. }
  48. return getSingleValue( tableCell.getAttribute( this.attributeName ) );
  49. }
  50. /**
  51. * @inheritDoc
  52. */
  53. _getValueToSet( value ) {
  54. return addDefaultUnitToNumericValue( value, 'px' );
  55. }
  56. }