tablecellproperites.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * @license Copyright (c) 2003-2019, 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
  7. */
  8. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  9. import { downcastToStyle, upcastAttribute, upcastBorderStyles } from './tableproperties/utils';
  10. /**
  11. * The table cell properties feature.
  12. *
  13. * @extends module:core/plugin~Plugin
  14. */
  15. export default class TableCellProperties extends Plugin {
  16. /**
  17. * @inheritDoc
  18. */
  19. static get pluginName() {
  20. return 'TableCellProperties';
  21. }
  22. /**
  23. * @inheritDoc
  24. */
  25. afterInit() {
  26. const editor = this.editor;
  27. const model = editor.model;
  28. const schema = model.schema;
  29. const conversion = editor.conversion;
  30. // Table cell attributes.
  31. schema.extend( 'tableCell', {
  32. allowAttributes: [ 'borderWidth', 'borderColor', 'borderStyle' ]
  33. } );
  34. upcastBorderStyles( conversion, 'td' );
  35. upcastBorderStyles( conversion, 'th' );
  36. downcastToStyle( conversion, 'tableCell', 'borderStyle', 'border-style' );
  37. downcastToStyle( conversion, 'tableCell', 'borderColor', 'border-color' );
  38. downcastToStyle( conversion, 'tableCell', 'borderWidth', 'border-width' );
  39. schema.extend( 'tableCell', {
  40. allowAttributes: [ 'backgroundColor' ]
  41. } );
  42. upcastAttribute( conversion, 'tableCell', 'backgroundColor', 'background-color' );
  43. downcastToStyle( conversion, 'tableCell', 'backgroundColor', 'background-color' );
  44. schema.extend( 'tableCell', {
  45. allowAttributes: [ 'padding' ]
  46. } );
  47. upcastAttribute( conversion, 'tableCell', 'padding', 'padding' );
  48. downcastToStyle( conversion, 'tableCell', 'padding', 'padding' );
  49. schema.extend( 'tableCell', {
  50. allowAttributes: [ 'verticalAlignment' ]
  51. } );
  52. upcastAttribute( conversion, 'tableCell', 'verticalAlignment', 'vertical-align' );
  53. downcastToStyle( conversion, 'tableCell', 'verticalAlignment', 'vertical-align' );
  54. }
  55. }