tablewidthcommand.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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/tableproperties/commands/tablewidthcommand
  7. */
  8. import { addDefaultUnitToNumericValue } from '../../commands/utils';
  9. import TablePropertyCommand from './tablepropertycommand';
  10. /**
  11. * The table width command.
  12. *
  13. * The command is registered by the {@link module:table/tableproperties/tablepropertiesediting~TablePropertiesEditing} as
  14. * `'tableWidth'` editor command.
  15. *
  16. * To change width of the selected table, execute the command:
  17. *
  18. * editor.execute( 'tableWidth', {
  19. * value: '400px'
  20. * } );
  21. *
  22. * **Note**: This command adds the default `'px'` unit to numeric values. Executing:
  23. *
  24. * editor.execute( 'tableWidth', {
  25. * value: '50'
  26. * } );
  27. *
  28. * Will set the `width` attribute to `'50px'` in the model.
  29. *
  30. * @extends module:table/tableproperties/commands/tablepropertycommand
  31. */
  32. export default class TableWidthCommand extends TablePropertyCommand {
  33. /**
  34. * Creates a new `TableWidthCommand` 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, 'width' );
  40. }
  41. /**
  42. * @inheritDoc
  43. */
  44. _getValueToSet( value ) {
  45. return addDefaultUnitToNumericValue( value, 'px' );
  46. }
  47. }