123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- import { align, getAlignmentClasses, checkSelectionConsistency, markLabelAsSelected } from './../utils';
- import { KEY as SEPARATOR } from './separator';
- export var KEY = 'alignment';
- export default function alignmentItem() {
- return {
- key: KEY,
- name: 'Alignment',
- disabled: function disabled() {
- return !(this.getSelectedRange() && !this.selection.selectedHeader.corner);
- },
- submenu: {
- items: [{
- key: KEY + ':left',
- name: function name() {
- var _this = this;
- var label = 'Left';
- var hasClass = checkSelectionConsistency(this.getSelectedRange(), function (row, col) {
- var className = _this.getCellMeta(row, col).className;
- if (className && className.indexOf('htLeft') !== -1) {
- return true;
- }
- });
- if (hasClass) {
- label = markLabelAsSelected(label);
- }
- return label;
- },
- callback: function callback() {
- var _this2 = this;
- var range = this.getSelectedRange();
- var stateBefore = getAlignmentClasses(range, function (row, col) {
- return _this2.getCellMeta(row, col).className;
- });
- var type = 'horizontal';
- var alignment = 'htLeft';
- this.runHooks('beforeCellAlignment', stateBefore, range, type, alignment);
- align(range, type, alignment, function (row, col) {
- return _this2.getCellMeta(row, col);
- }, function (row, col, key, value) {
- return _this2.setCellMeta(row, col, key, value);
- });
- this.render();
- },
- disabled: false
- }, {
- key: KEY + ':center',
- name: function name() {
- var _this3 = this;
- var label = 'Center';
- var hasClass = checkSelectionConsistency(this.getSelectedRange(), function (row, col) {
- var className = _this3.getCellMeta(row, col).className;
- if (className && className.indexOf('htCenter') !== -1) {
- return true;
- }
- });
- if (hasClass) {
- label = markLabelAsSelected(label);
- }
- return label;
- },
- callback: function callback() {
- var _this4 = this;
- var range = this.getSelectedRange();
- var stateBefore = getAlignmentClasses(range, function (row, col) {
- return _this4.getCellMeta(row, col).className;
- });
- var type = 'horizontal';
- var alignment = 'htCenter';
- this.runHooks('beforeCellAlignment', stateBefore, range, type, alignment);
- align(range, type, alignment, function (row, col) {
- return _this4.getCellMeta(row, col);
- }, function (row, col, key, value) {
- return _this4.setCellMeta(row, col, key, value);
- });
- this.render();
- },
- disabled: false
- }, {
- key: KEY + ':right',
- name: function name() {
- var _this5 = this;
- var label = 'Right';
- var hasClass = checkSelectionConsistency(this.getSelectedRange(), function (row, col) {
- var className = _this5.getCellMeta(row, col).className;
- if (className && className.indexOf('htRight') !== -1) {
- return true;
- }
- });
- if (hasClass) {
- label = markLabelAsSelected(label);
- }
- return label;
- },
- callback: function callback() {
- var _this6 = this;
- var range = this.getSelectedRange();
- var stateBefore = getAlignmentClasses(range, function (row, col) {
- return _this6.getCellMeta(row, col).className;
- });
- var type = 'horizontal';
- var alignment = 'htRight';
- this.runHooks('beforeCellAlignment', stateBefore, range, type, alignment);
- align(range, type, alignment, function (row, col) {
- return _this6.getCellMeta(row, col);
- }, function (row, col, key, value) {
- return _this6.setCellMeta(row, col, key, value);
- });
- this.render();
- },
- disabled: false
- }, {
- key: KEY + ':justify',
- name: function name() {
- var _this7 = this;
- var label = 'Justify';
- var hasClass = checkSelectionConsistency(this.getSelectedRange(), function (row, col) {
- var className = _this7.getCellMeta(row, col).className;
- if (className && className.indexOf('htJustify') !== -1) {
- return true;
- }
- });
- if (hasClass) {
- label = markLabelAsSelected(label);
- }
- return label;
- },
- callback: function callback() {
- var _this8 = this;
- var range = this.getSelectedRange();
- var stateBefore = getAlignmentClasses(range, function (row, col) {
- return _this8.getCellMeta(row, col).className;
- });
- var type = 'horizontal';
- var alignment = 'htJustify';
- this.runHooks('beforeCellAlignment', stateBefore, range, type, alignment);
- align(range, type, alignment, function (row, col) {
- return _this8.getCellMeta(row, col);
- }, function (row, col, key, value) {
- return _this8.setCellMeta(row, col, key, value);
- });
- this.render();
- },
- disabled: false
- }, {
- name: SEPARATOR
- }, {
- key: KEY + ':top',
- name: function name() {
- var _this9 = this;
- var label = 'Top';
- var hasClass = checkSelectionConsistency(this.getSelectedRange(), function (row, col) {
- var className = _this9.getCellMeta(row, col).className;
- if (className && className.indexOf('htTop') !== -1) {
- return true;
- }
- });
- if (hasClass) {
- label = markLabelAsSelected(label);
- }
- return label;
- },
- callback: function callback() {
- var _this10 = this;
- var range = this.getSelectedRange();
- var stateBefore = getAlignmentClasses(range, function (row, col) {
- return _this10.getCellMeta(row, col).className;
- });
- var type = 'vertical';
- var alignment = 'htTop';
- this.runHooks('beforeCellAlignment', stateBefore, range, type, alignment);
- align(range, type, alignment, function (row, col) {
- return _this10.getCellMeta(row, col);
- }, function (row, col, key, value) {
- return _this10.setCellMeta(row, col, key, value);
- });
- this.render();
- },
- disabled: false
- }, {
- key: KEY + ':middle',
- name: function name() {
- var _this11 = this;
- var label = 'Middle';
- var hasClass = checkSelectionConsistency(this.getSelectedRange(), function (row, col) {
- var className = _this11.getCellMeta(row, col).className;
- if (className && className.indexOf('htMiddle') !== -1) {
- return true;
- }
- });
- if (hasClass) {
- label = markLabelAsSelected(label);
- }
- return label;
- },
- callback: function callback() {
- var _this12 = this;
- var range = this.getSelectedRange();
- var stateBefore = getAlignmentClasses(range, function (row, col) {
- return _this12.getCellMeta(row, col).className;
- });
- var type = 'vertical';
- var alignment = 'htMiddle';
- this.runHooks('beforeCellAlignment', stateBefore, range, type, alignment);
- align(range, type, alignment, function (row, col) {
- return _this12.getCellMeta(row, col);
- }, function (row, col, key, value) {
- return _this12.setCellMeta(row, col, key, value);
- });
- this.render();
- },
- disabled: false
- }, {
- key: KEY + ':bottom',
- name: function name() {
- var _this13 = this;
- var label = 'Bottom';
- var hasClass = checkSelectionConsistency(this.getSelectedRange(), function (row, col) {
- var className = _this13.getCellMeta(row, col).className;
- if (className && className.indexOf('htBottom') !== -1) {
- return true;
- }
- });
- if (hasClass) {
- label = markLabelAsSelected(label);
- }
- return label;
- },
- callback: function callback() {
- var _this14 = this;
- var range = this.getSelectedRange();
- var stateBefore = getAlignmentClasses(range, function (row, col) {
- return _this14.getCellMeta(row, col).className;
- });
- var type = 'vertical';
- var alignment = 'htBottom';
- this.runHooks('beforeCellAlignment', stateBefore, range, type, alignment);
- align(range, type, alignment, function (row, col) {
- return _this14.getCellMeta(row, col);
- }, function (row, col, key, value) {
- return _this14.setCellMeta(row, col, key, value);
- });
- this.render();
- },
- disabled: false
- }]
- }
- };
- }
|