VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /var/www/html/libs/absol-full/dist/js/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/libs/absol-full/dist/js/mdls__absol-sheet__js__fragment__TableEditor.js
/*** module: node_modules/absol-sheet/js/fragment/TableEditor.js ***/
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

require("../../css/tableeditable.css");

var _SCore = require("../dom/SCore");

var _TableData = _interopRequireDefault(require("../viewer/TableData"));

var _ResizeSystem = _interopRequireDefault(require("absol/src/HTML5/ResizeSystem"));

require("./editor/TDEText");

require("./editor/TDENumber");

require("./editor/TDEDate");

require("./editor/TDEDateTime");

require("./editor/TDEEnum");

require("./editor/TDEEnumSet");

require("./editor/TDEBoolean");

require("./editor/TDETreeEnum");

require("./editor/TDETreeLeafEnum");

require("./editor/TDETime");

require("./editor/TDETimeRange24");

require("./editor/TDEWeek");

require("./editor/TDEDateNLevel");

require("absol-acomp/js/BContextCapture");

var _ContextMenu = _interopRequireDefault(require("absol-acomp/js/ContextMenu"));

var _OOP = _interopRequireDefault(require("absol/src/HTML5/OOP"));

var _EventEmitter = _interopRequireWildcard(require("absol/src/HTML5/EventEmitter"));

var _TDEBase = _interopRequireDefault(require("./editor/TDEBase"));

var _Toast = _interopRequireDefault(require("absol-acomp/js/Toast"));

var _TDRecord = _interopRequireDefault(require("../viewer/TDRecord"));

var _DomSignal = _interopRequireDefault(require("absol/src/HTML5/DomSignal"));

var _dialogs = require("./dialogs");

var _noop = _interopRequireDefault(require("absol/src/Code/noop"));

var _Clipboard = require("absol/src/HTML5/Clipboard");

var _Attributes = _interopRequireDefault(require("absol/src/AppPattern/Attributes"));

var _util = require("../util");

var _Fragment = _interopRequireDefault(require("absol/src/AppPattern/Fragment"));

var _safeThrow = _interopRequireDefault(require("absol/src/Code/safeThrow"));

var _utils = require("absol-acomp/js/utils");

var _Abstractions = require("./Abstractions");

var _AElement = _interopRequireDefault(require("absol/src/HTML5/AElement"));

var _stringFormat = require("absol/src/String/stringFormat");

var _attribute = require("absol/src/JSX/attribute");

var _Dom = _interopRequireWildcard(require("absol/src/HTML5/Dom"));

var _Scroller = require("absol-acomp/js/Scroller");




function getScrollSize() {
  var parent = (0, _SCore._)({
    style: {
      'z-index': '-100',
      opacity: '0',
      width: '100px',
      height: '100px',
      overflow: 'scroll',
      top: '0',
      left: '0',
      'box-sizing': 'content-box',
      position: 'fixed'
    }
  }).addTo(document.body);
  var child = (0, _SCore._)({
    style: {
      width: '100%',
      height: '100%'
    }
  }).addTo(parent);
  var parentBound = parent.getBoundingClientRect();
  var childBound = child.getBoundingClientRect();
  return {
    width: parentBound.width - childBound.width,
    height: parentBound.height - childBound.height
  };
}

var EV_CONTENT_CHANGE = 'contentchange';
/***
 * @typedef TableEditorOpt
 *
 */

/***
 * @extends EventEmitter
 * @constructor
 */

function TableEditor(opt) {
  _Abstractions.ASHTEditor.call(this, opt);

  this.lcEmitter = new _EventEmitter.default();
  this.autoStateMng = new StateAutoManager(this);
  this.layoutCtrl = new LayoutController(this);
  this.selectTool = new SelectTool(this);
  this.editTool = new EditTool(this);
  this.commandCtrl = new CommandController(this);
  this.fixedYCtrl = new TEFixedYController(this);
  this.fixedXCtrl = new TEFixedXController(this);
  this.fixedXYCtrl = new TEFixedXYController(this);

  for (var key in this) {
    if (key.startsWith('ev_')) {
      this[key] = this[key].bind(this);
    }
  }

  this.lcEmitter.on(EV_CONTENT_CHANGE, () => {
    this.fixedXYCtrl.updateContent();
    this.fixedYCtrl.updateContent();
    this.fixedXCtrl.updateContent();

    _ResizeSystem.default.updateUp(this.$view, true);
  });
}

_OOP.default.mixClass(TableEditor, _Abstractions.ASHTEditor);

TableEditor.prototype.opt = {};

TableEditor.prototype.createView = function () {
  _ContextMenu.default.auto();

  this.$view = (0, _SCore._)({
    elt: this.opt.elt,
    extendEvent: 'contextmenu',
    class: ['asht-table-editor'],
    child: ['attachhook', {
      class: 'asht-table-editor-main-viewport',
      child: [{
        class: 'asht-table-editor-main-scroller',
        child: 'table.asht-table-data'
      }, {
        class: 'asht-table-editor-fixed-y-viewport',
        child: {
          class: 'asht-table-editor-fixed-y-scroller',
          child: {
            class: 'asht-table-editor-fixed-y-size-wrapper',
            child: {
              tag: 'table',
              class: 'asht-table-editor-fixed-y'
            }
          }
        }
      }, {
        class: 'asht-table-editor-fixed-x-viewport',
        child: {
          class: 'asht-table-editor-fixed-x-scroller',
          child: {
            tag: 'table',
            class: 'asht-table-editor-fixed-x'
          }
        }
      }, {
        class: 'asht-table-editor-fixed-xy-viewport',
        child: {
          tag: 'table',
          class: 'asht-table-editor-fixed-xy',
          child: {
            tag: 'thead',
            child: {
              tag: 'tr',
              child: 'td'
            }
          }
        }
      }, {
        class: 'asht-table-editor-foreground',
        child: ['.asht-table-editor-selected-box']
      }, '.asht-table-editor-editing-box']
    }, {
      tag: 'vscrollbar',
      class: 'asht-table-editor-v-scrollbar',
      child: {}
    }, {
      tag: _Scroller.HScrollbar,
      class: 'asht-table-editor-h-scrollbar'
    }]
  });
  this.$attachook = (0, _SCore.$)('attachhook', this.$view);
  this.$attachook.requestUpdateSize = this.ev_resize;
  this.$attachook.on('attached', function () {
    _ResizeSystem.default.add(this);

    this.requestUpdateSize();
  });
  this.$view.requestUpdateSize = this.ev_resize;
  this.$domSignal = (0, _SCore._)('attachhook').addTo(this.$view);
  this.domSignal = new _DomSignal.default(this.$domSignal);
  this.$body = (0, _SCore.$)('.asht-table-editor-body', this.$view);
  this.$mainViewport = (0, _SCore.$)('.asht-table-editor-main-viewport', this.$view);
  this.$mainScroller = (0, _SCore.$)('.asht-table-editor-main-scroller', this.$view);
  this.$tableData = (0, _SCore.$)('table.asht-table-data', this.$view);
  this.$hscrollbar = (0, _SCore.$)('.asht-table-editor-h-scrollbar', this.$view);
  this.$vscrollbar = (0, _SCore.$)('.asht-table-editor-v-scrollbar', this.$view);
  this.$fixedYScroller = (0, _SCore.$)('.asht-table-editor-fixed-y-scroller', this.$view);
  this.$fixedXScroller = (0, _SCore.$)('.asht-table-editor-fixed-x-scroller', this.$view);
  this.$foreground = (0, _SCore.$)('.asht-table-editor-foreground', this.$view);
  this.$editingbox = (0, _SCore.$)('.asht-table-editor-editing-box', this.$view).addStyle('display', 'none');
  this.$selectedbox = (0, _SCore.$)('.asht-table-editor-selected-box', this.$foreground).addStyle('display', 'none');
  this.$header = (0, _SCore.$)('.asht-table-editor-header', this.$view);
  this.$headRow = (0, _SCore.$)('tr', this.$header); // this.$fixedYHeaderScroller = $('.ash-fixed-y-header-scroller', this.$view);
  // // this.$fixedYHeaderSizeWrapper = $('.ash-fixed-y-header-size-wrapper', this.$view);
  //
  // this.$fixedXYHeader = $('.as-table-scroller-fixed-xy-header', this.$view);
  // this.$fixXCol = $('.as-table-scroller-fixed-x-col', this.$view);
  // this.$vscroller = $('.as-table-scroller-vertical-scroller', this.$view);
  // this.$hscroller = $('.as-table-scroller-horizontal-scroller', this.$view);
  // this.$indexSccroller = $('.asht-table-editor-index-scroller', this.$view);

  this.opt.loadAttributeHandlers(this.optHandlers);
  this.$view.tableEditor = this;
  var scrollSize = getScrollSize();
  this.$view.addStyle('--sys-scrollbar-width', scrollSize.width + 'px');
  this.$view.addStyle('--sys-scrollbar-height', scrollSize.height + 'px');
  this.autoStateMng.onViewCreated();
  this.layoutCtrl.onViewCreated();
  this.fixedYCtrl.onViewCreated();
  this.fixedXCtrl.onViewCreated();
  this.fixedXYCtrl.onViewCreated();
  this.selectTool.onViewCreated();
  this.editTool.onViewCreated();
  this.commandCtrl.onViewCreated();
  return this.$view;
};

TableEditor.prototype.setData = function (data) {
  data = (0, _util.duplicateData)(data);
  if (this.$tableData) this.$tableData.remove();
  var tableData = new _TableData.default(this, {
    elt: this.$tableData
  });
  this.$mainScroller.addChild(this.$tableData);
  tableData.import(data);
  this.tableData = tableData;
  this.layoutCtrl.onData(); //? this.domSignal.emit('request_load_foreground_content');

  tableData.on('new_row_property_change', this.ev_newRowPropertyChange);
};

TableEditor.prototype.getHash = function () {
  if (this.tableData) return this.tableData.getHash();
  return 0;
};

TableEditor.prototype.getData = function () {
  return this.tableData && this.tableData.export();
};

TableEditor.prototype.getRecords = function () {
  return this.tableData && this.tableData.records;
};

TableEditor.prototype.onStart = function () {// console.log('start')
};

TableEditor.prototype.onStop = function () {// console.log('stop')
};

TableEditor.prototype.ev_resize = function (event) {
  this.layoutCtrl.onResize();
  this.editTool.updateEditingBoxPosition();
  this.selectTool.updateSelectedPosition();
};

var t = 10;

TableEditor.prototype.ev_newRowPropertyChange = function (event) {
  this.tableData.flushNewRow({});
  this.fixedXCtrl.updateContent();
  (0, _utils.vScrollIntoView)(this.tableData.newRow.elt);
};

TableEditor.prototype.editCellDelay = function (row, col) {
  this.editTool.editCellDelay(row, col);
};

TableEditor.prototype.editCell = function (row, col) {
  this.editTool.editCell(row, col);
};

TableEditor.prototype.selectRow = function (row) {
  this.selectTool.selectRow(row);
};

TableEditor.prototype.selectCol = function (col) {
  this.selectTool.selectCol(col);
};

TableEditor.prototype.selectAll = function () {
  this.selectTool.selectAll();
};

TableEditor.prototype.focusIncompleteCell = function () {
  this.editTool.focusIncompleteCell();
};

TableEditor.prototype.insertRow = function (atIdx, record) {
  var tableData = this.tableData;
  tableData.addRowAt(atIdx, record);
  this.lcEmitter.emit(EV_CONTENT_CHANGE);
};

TableEditor.prototype.removeRow = function (atIdx) {
  var tableData = this.tableData;
  tableData.removeRowAt(atIdx);
  this.lcEmitter.emit(EV_CONTENT_CHANGE);
};

TableEditor.prototype.showError = function (title, message) {
  var toast = _Toast.default.make({
    props: {
      htitle: title,
      message: message,
      variant: 'error'
    }
  });

  setTimeout(toast.disappear.bind(toast), 2000);
};

TableEditor.prototype.optHandlers = {};
TableEditor.prototype.optHandlers.readOnly = {
  set: function (value) {
    if (value) {
      this.$view.addClass('asht-read-only');
    } else {
      this.$view.removeClass('asht-read-only');
    } // ResizeSystem.update();

  },
  get: function () {
    return this.$view.hasClass('asht-read-only');
  },
  descriptor: {
    type: 'bool'
  }
};
TableEditor.prototype.optHandlers.headless = {
  set: function (value) {
    if (value) {
      this.$view.addClass('asht-headless');
    } else {
      this.$view.removeClass('asht-headless');
    } // ResizeSystem.update();

  },
  get: function () {
    return this.$view.hasClass('asht-headless');
  }
};
Object.defineProperty(TableEditor.prototype, 'records', {
  get: function () {
    return this.tableData && this.tableData.records;
  }
});
var _default = TableEditor;
/***
 *
 * @param {TableEditor} editor
 * @constructor
 */

exports.default = _default;

function StateAutoManager(editor) {
  this.editor = editor;
}

StateAutoManager.prototype.onViewCreated = function () {
  this.editor.domSignal.once('autostart', () => {
    if (this.editor.opt.autoStart && this.editor.state === 'STANDBY' || this.editor.state === 'CREATE') {
      this.editor.start();
    }
  });
  this.editor.domSignal.emit('autostart');
};
/***
 *
 * @param {TableEditor} editor
 * @constructor
 */


function SelectTool(editor) {
  this.editor = editor;
  Object.keys(this.constructor.prototype).forEach(key => {
    if (key.startsWith('ev_')) this[key] = this[key].bind(this);
  });
  this.hoverRow = null;
  this.selectedData = null;
}

SelectTool.prototype.onViewCreated = function () {// this.editor.$editingLayer.on('mousedown', this.ev_editLayerMouseDown);
  // this.editor.$rootCell.on('mousedown', this.ev_rootCellMouseDown);
  // this.editor.$headRow.on('mousedown', this.ev_headerMouseDown);
  // this.editor.$indexCol.on('mousedown', this.ev_indexColMouseDown);
};

SelectTool.prototype.selectRow = function (row) {
  if (row) {
    this.selectedData = {
      type: 'row',
      row: row
    };
    this.editor.$selectedbox.removeStyle('display');
    this.updateSelectedPosition();
  } else {
    // this.$selectrow
    this.selectedData = null;
    this.editor.$selectedbox.addStyle('display', 'none');
  }
};

SelectTool.prototype.selectCol = function (col) {
  if (col) {
    this.selectedData = {
      type: 'col',
      col: col
    };
    this.editor.$selectedbox.removeStyle('display');
    this.updateSelectedPosition();
  } else {
    this.selectedData = null;
    this.editor.$selectedbox.addStyle('display', 'none');
  }
};

SelectTool.prototype.updateSelectedPosition = function () {
  if (!this.selectedData) return;
  var tBound;
  var fBound = this.editor.$foreground.getBoundingClientRect();

  if (this.selectedData.row) {
    var row = this.selectedData.row;
    var rBound = row.elt.getBoundingClientRect();
    this.editor.$selectedbox.addStyle({
      left: rBound.left - fBound.left - 1 + 'px',
      // boder-width = 2px
      top: rBound.top - fBound.top - 1 + 'px',
      'min-width': rBound.width + 2 + 'px',
      'min-height': rBound.height + 2 + 'px'
    });
  } else if (this.selectedData.col) {
    var col = this.selectedData.col;
    var cBound = col.elt.getBoundingClientRect();
    tBound = col.elt.parentElement.parentElement.parentElement.getBoundingClientRect();
    this.editor.$selectedbox.addStyle({
      left: cBound.left - fBound.left - 1 + 'px',
      // boder-width = 2px
      top: tBound.top - fBound.top - 1 + 'px',
      'min-width': cBound.width + 2 + 'px',
      'min-height': tBound.height + 2 + 'px'
    });
  } else if (this.selectedData.type === 'all') {
    tBound = this.editor.tableData.$view.getBoundingClientRect();
    this.editor.$selectedbox.addStyle({
      left: tBound.left - fBound.left - 1 + 'px',
      // boder-width = 2px
      top: tBound.top - fBound.top - 1 + 'px',
      'min-width': tBound.width + 2 + 'px',
      'min-height': tBound.height + 2 + 'px'
    });
  }
};

SelectTool.prototype.selectAll = function () {
  this.selectedData = {
    type: 'all'
  };
  this.editor.$selectedbox.removeStyle('display');
  this.updateSelectedPosition();
};

SelectTool.prototype.ev_rootCellMouseDown = function (ev) {
  if (this.editor.opt.readOnly) return;
  this.selectAll();
  var row = this.editor.tableData.findRowByIndex(0);
  var col = this.editor.tableData.findColByIndex(0);

  if (row && col) {
    this.editor.editCellDelay(row, col);
  }
};

SelectTool.prototype.ev_indexColMouseDown = function (ev) {
  var y = ev.clientY;
  this.hoverRow = this.editor.tableData.findRowByClientY(y);

  if (this.hoverRow) {
    this.selectRow(this.hoverRow);
    this.editor.editCellDelay(this.hoverRow, this.editor.tableData.headCells[0]);
  }
};

SelectTool.prototype.ev_headerMouseDown = function (ev) {
  // if (this.opt.readOnly) return;
  var x = ev.clientX;
  var col = this.editor.tableData.findColByClientX(x);
  var row;

  if (col) {
    this.editor.selectCol(col);
    row = this.editor.tableData.findRowByIndex(0);

    if (row) {
      this.editor.editCellDelay(row, col);
    }
  }
};
/***
 *
 * @param {TableEditor} editor
 * @constructor
 */


function EditTool(editor) {
  this.editor = editor;
  Object.keys(this.constructor.prototype).forEach(key => {
    if (key.startsWith('ev_')) this[key] = this[key].bind(this);
  });
}

EditTool.prototype.onViewCreated = function () {};

EditTool.prototype.editCell = function (row, col) {
  if (this.currentCellEditor) {
    this.currentCellEditor.off('finish', this.ev_cellEditorFinish);
    this.currentCellEditor.destroy();
    this.currentCellEditor = null; // if (document.activeElement && AElement.prototype.isDescendantOf.call(document.activeElement, this.$editingbox)){
    //     // document.activeElement.blur();
    // }

    this.editor.$editingbox.clearChild();
  }

  if (row && col) {
    var cell = row.cells[col.index];
    var EditorClass = _TDEBase.default.typeClasses[cell.descriptor.type];

    if (EditorClass) {
      this.currentCellEditor = new EditorClass(this.editor, row.cells[col.index]);
      this.editor.$editingbox.removeStyle('display');
      this.currentCellEditor.start();
    } else {
      this.currentCellEditor = null;
      this.editor.showError('Data Error', 'Not support ' + cell.descriptor.type);
      this.editor.$editingbox.addStyle('display', 'none');
    }

    this.updateEditingBoxPosition();
    this.editor.layoutCtrl.scrollIntoRow(row);
    this.editor.layoutCtrl.scrollIntoCol(col);

    if (this.currentCellEditor) {
      this.currentCellEditor.on('finish', this.ev_cellEditorFinish);
    }
  } else {
    this.editor.$editingbox.addStyle('display', 'none');
  }
};

EditTool.prototype.editCellDelay = function (row, col) {
  setTimeout(() => {
    this.editCell(row, col);
  }, 100);
};

EditTool.prototype.updateEditingBoxPosition = function () {
  if (!this.currentCellEditor) return;
  var cellEditor = this.currentCellEditor;
  var elt = cellEditor.cell.elt;
  var eLBound = this.editor.$view.getBoundingClientRect();
  var eBound = elt.getBoundingClientRect();
  var left = eBound.left - eLBound.left;
  var width = eBound.width;
  this.editor.$editingbox.addStyle({
    left: left + 'px',
    top: eBound.top - eLBound.top + 'px',
    '--cell-width': width + 'px',
    '--cell-height': eBound.height + 'px'
  });
};

EditTool.prototype.focusIncompleteCell = function () {
  if (!this.editor.tableData) return false;
  var incompleteCell = this.editor.tableData.findFirsIncompleteCell();
  if (!incompleteCell) return false;
  var col = this.editor.tableData.findColByName(incompleteCell.pName);
  this.editCellDelay(incompleteCell.row, col);
  return true;
};

EditTool.prototype.ev_cellEditorFinish = function (event) {
  if (this.currentCellEditor === event.target) {
    this.editCellDelay(null);
  }
};
/***
 *
 * @param {TableEditor} editor
 * @constructor
 */


function LayoutController(editor) {
  this.editor = editor;
  Object.keys(this.constructor.prototype).forEach(key => {
    if (key.startsWith('ev_')) this[key] = this[key].bind(this);
  });
  this.extendStyle = Object.assign(new _Attributes.default(this), this.extendStyle);
}

LayoutController.prototype.extendStyle = {
  width: 'auto',
  height: 'auto'
};
LayoutController.prototype.styleHandlers = {};
LayoutController.prototype.styleHandlers.width = {
  /**
   * @this LayoutController
   * @param value
   */
  set: function (value) {
    if (typeof value === 'number') value += 'px';else if (typeof value !== "string") value = 'auto';
    var psValue;

    if (value === 'auto') {
      this.editor.$view.style.width = null;
      this.editor.$view.addClass('asht-width-auto');
    } else if (value.indexOf('calc(') >= 0) {
      this.editor.$view.style.width = value;
      this.editor.$view.removeClass('asht-width-auto');
    } else {
      psValue = (0, _attribute.parseMeasureValue)(value);

      if (psValue) {
        if (['px', 'vw', 'vh', 'em', 'rem', 'pt'].indexOf(psValue.unit) >= 0) {
          this.editor.$view.style.width = value;
          this.editor.$view.removeClass('asht-width-auto');
        } else {
          this.editor.$view.style.width = null;
          this.editor.$view.addClass('asht-width-auto');
        }
      } else {
        this.editor.$view.style.width = null;
        this.editor.$view.addClass('asht-width-auto');
      }
    }

    return value;
  }
};
LayoutController.prototype.styleHandlers.height = {
  /**
   * @this LayoutController
   * @param value
   */
  set: function (value) {
    if (typeof value === 'number') value += 'px';else if (typeof value !== "string") value = 'auto';
    var psValue;

    if (value === 'auto') {
      this.editor.$view.style.height = null;
      this.editor.$view.addClass('asht-height-auto');
    } else if (value.indexOf('calc(')) {
      this.editor.$view.style.height = value;
      this.editor.$view.removeClass('asht-height-auto');
    } else {
      psValue = (0, _attribute.parseMeasureValue)(value);

      if (psValue) {
        if (['px', 'vw', 'vh', 'em', 'rem', 'pt'].indexOf(psValue.unit) < 0) {
          this.editor.$view.style.height = null;
          this.editor.$view.addClass('asht-height-auto');
        } else {
          this.editor.$view.style.height = value;
          this.editor.$view.removeClass('asht-height-auto');
        }
      } else {
        this.editor.$view.style.height = null;
        this.editor.$view.addClass('asht-height-auto');
      }
    }

    return value;
  }
};

LayoutController.prototype.addStyle = function () {
  var arg0 = arguments[0];
  var arg1 = arguments[1];
  var key;

  if (arguments.length === 1) {
    if (typeof arg0 === "object") {
      for (key in arg0) {
        this.addStyle(key, arg0[key]);
      }
    }
  } else if (arguments.length === 2) {
    if (arg0 === '--as-width') arg0 = 'width';
    if (arg0 === '--as-height') arg0 = 'height';

    if (typeof arg0 === 'string') {
      if (arg0.startsWith('--')) {
        this.editor.$view.style.setProperty(arg0, arg1);
      } else {
        if (arg0.indexOf('-') >= 0) {
          arg0 = (0, _stringFormat.kebabCaseToCamelCase)(arg0);
        }

        if (this.styleHandlers[arg0]) {
          this.extendStyle[arg0] = arguments[1];
        } else {
          this.editor.$view.style[arg0] = arg1;
        }
      }
    }
  }

  return this.editor.$view;
};

LayoutController.prototype.removeStyle = function () {
  var arg0 = arguments[0];

  if (arguments.length === 1) {
    if (arg0 === '--as-width') arg0 = 'width';
    if (arg0 === '--as-height') arg0 = 'height';

    if (arg0.startsWith('--')) {
      this.editor.$view.style.removeProperty(arg0);
    } else {
      if (arg0.indexOf('-') >= 0) {
        arg0 = (0, _stringFormat.kebabCaseToCamelCase)(arg0);
      }

      if (this.styleHandlers[arg0]) this.extendStyle[arg0] = null;else this.editor.$view.style[arg0] = null;
    }
  } else {
    for (var i = 0; i < arguments.length; ++i) {
      this.removeStyle(arguments[i]);
    }
  }

  return this.editor.$view;
};

LayoutController.prototype.onViewCreated = function () {
  this.editor.$view.extendStyle = this.extendStyle;
  this.extendStyle.loadAttributeHandlers(this.styleHandlers);
  this.editor.$view.addStyle = this.addStyle.bind(this);
  this.editor.$view.removeStyle = this.removeStyle.bind(this);
  this.editor.$hscrollbar.on('scroll', this.ev_scroll.bind(this, 'hscrollbar'));
  this.editor.$vscrollbar.on('scroll', this.ev_scroll.bind(this, 'vscrollbar'));
  this.editor.$mainScroller.on('scroll', this.ev_scroll.bind(this, 'main'));
  this.editor.$fixedXScroller.on('scroll', this.ev_scroll.bind(this, 'fixedXScroller'));
  this.editor.$fixedYScroller.on('scroll', this.ev_scroll.bind(this, 'fixedYScroller')); // this.editor.$fixedYHeaderScroller.on('scroll', this.ev_scroll.bind(this, 'fixedYScroller'));
  //
};

LayoutController.prototype.updateOverflowStatus = function () {
  var tableBound = this.editor.$tableData.getBoundingClientRect();
  this.editor.$view.style.setProperty('--content-width', tableBound.width + 'px');
  this.editor.$view.style.setProperty('--content-height', tableBound.height + 'px');
};

LayoutController.prototype.updateScrollerStatus = function () {
  var viewElt = this.editor.$view;
  var tableElt = this.editor.$tableData;
  var tableBound = tableElt.getBoundingClientRect();
  var cpStyle = getComputedStyle(this.editor.$view);
  var viewBound = viewElt.getBoundingClientRect();
  var parentBound = viewElt.parentElement.getBoundingClientRect();
  var screenViewSize = (0, _Dom.getScreenSize)();

  var getAvailableWidth = () => {
    var res = Infinity;
    var width = this.extendStyle.width || 'auto';
    var psWidth = (0, _attribute.parseMeasureValue)(width);

    if (width !== "auto" && (width.indexOf('calc') >= 0 || psWidth)) {
      res = (0, _attribute.computeMeasureExpression)(width, {
        parentSize: parentBound.width,
        screenViewSize: (0, _Dom.getScreenSize)(),
        style: cpStyle
      });

      if (res.unit === 'px') {
        res = res.value;
      } else if (res.unit === 'vw') {
        res = res.value * screenViewSize.width / 100;
      } else {
        //todo
        res = screenViewSize.width; //todo
      }
    }

    var maxWidth = cpStyle.maxWidth;
    var psMaxWidth = (0, _attribute.parseMeasureValue)(maxWidth);

    if (psMaxWidth && psMaxWidth.unit === 'px') {
      res = Math.min(res, psMaxWidth.value);
    }

    return res;
  };

  var getAvailableHeight = () => {
    var res = Infinity;
    var height = this.extendStyle.height || 'auto';
    var psHeight = (0, _attribute.parseMeasureValue)(height);

    if (height !== 'auto' && (height.indexOf('calc') >= 0 || psHeight)) {
      res = (0, _attribute.computeMeasureExpression)(height, {
        parentSize: parentBound.height,
        screenViewSize: (0, _Dom.getScreenSize)(),
        style: cpStyle
      });

      if (res.unit === 'px') {
        res = res.value;
      } else {
        //todo
        res = Infinity;
      }
    }

    var maxHeight = cpStyle.maxHeight;
    var psMaxHeight = (0, _attribute.parseMeasureValue)(maxHeight);

    if (psMaxHeight && psMaxHeight.unit === 'px') {
      res = Math.min(res, psMaxHeight.value);
    }

    return res;
  };

  var availableWidth = getAvailableWidth();
  var availableHeight = getAvailableHeight();

  if ((0, _utils.isRealNumber)(availableWidth)) {
    viewElt.addStyle('--available-width', availableWidth + 'px');
  } else {
    viewElt.removeStyle('--available-width');
  }

  if ((0, _utils.isRealNumber)(availableHeight)) {
    viewElt.addStyle('--available-height', availableHeight + 'px');
  } else {
    viewElt.removeStyle('--available-height');
  }

  if (tableBound.width > availableWidth - 17 || tableBound.width > viewBound.width) {
    this.editor.$view.addClass('asht-overflow-x');
  } else {
    this.editor.$view.removeClass('asht-overflow-x');
  }

  if (tableBound.height > availableHeight - 17 || tableBound.height > viewBound.height) {
    this.editor.$view.addClass('asht-overflow-y');
  } else {
    this.editor.$view.removeClass('asht-overflow-y');
  }

  tableBound = tableElt.getBoundingClientRect();
  viewElt.style.setProperty('--content-width', tableBound.width + 'px');
  viewElt.style.setProperty('--content-height', tableBound.height + 'px');
  setTimeout(() => {
    var viewportBound = this.editor.$mainViewport.getBoundingClientRect();
    tableBound = tableElt.getBoundingClientRect();
    tableBound = tableElt.getBoundingClientRect();
    viewElt.style.setProperty('--content-width', tableBound.width + 'px');
    viewElt.style.setProperty('--content-height', tableBound.height + 'px');
    this.editor.$hscrollbar.innerWidth = tableBound.width;
    this.editor.$vscrollbar.innerHeight = tableBound.height;
    this.editor.$hscrollbar.outerWidth = viewportBound.width;
    this.editor.$vscrollbar.outerHeight = viewportBound.height;

    if (this.editor.$hscrollbar.innerWidth > this.editor.$hscrollbar.outerWidth) {
      this.editor.$hscrollbar.removeStyle('display');
    } else {
      this.editor.$hscrollbar.addStyle('display', 'none');
    }

    if (this.editor.$vscrollbar.innerHeight > this.editor.$vscrollbar.outerHeight) {
      this.editor.$vscrollbar.removeStyle('display');
    } else {
      this.editor.$vscrollbar.addStyle('display', 'none');
    }
  }, 1);
};

LayoutController.prototype.updateFixedYHeader = function () {
  this.editor.fixedYCtrl.updateContent();
};

LayoutController.prototype.updateFixedYHeaderSize = function () {
  this.editor.fixedYCtrl.updateSize();
};

LayoutController.prototype.fullUpdateFixedXCol = function () {
  console.log("fullUpdateFixedXCol");
};

LayoutController.prototype.updateStyleConfig = function () {
  if (this.editor.tableData.config && this.editor.tableData.config.rowHeight) {
    this.editor.$view.addStyle('--row-height', this.editor.tableData.config.rowHeight + 'px');
  } else {
    this.editor.$view.removeStyle('--row-height');
  }
};

LayoutController.prototype.onResize = function () {
  if (!this.editor.tableData) return;
  this.updateScrollerStatus();
  this.editor.fixedYCtrl.updateSize();
  this.editor.fixedXCtrl.updateSize();
  this.editor.fixedXYCtrl.updateSize();
  this.editor.selectTool.updateSelectedPosition();
  setTimeout(() => {
    this.editor.fixedYCtrl.updateSize();
    this.editor.fixedXCtrl.updateSize();
    this.editor.fixedXYCtrl.updateSize();
    this.editor.selectTool.updateSelectedPosition();
  }, 10);
};

LayoutController.prototype.onData = function () {
  this.updateStyleConfig();
  this.editor.fixedYCtrl.updateContent();
  this.editor.fixedXCtrl.updateContent();
  this.editor.fixedXYCtrl.updateContent();
};

LayoutController.prototype.scrollIntoRow = function (row) {
  var rowBound = row.elt.getBoundingClientRect();
  var bound = this.editor.$view.getBoundingClientRect();
  var headBound = this.editor.fixedYCtrl.$fixedYTable.getBoundingClientRect();

  if (rowBound.top < headBound.bottom) {
    this.editor.$mainScroller.scrollTop -= headBound.bottom - rowBound.top;
  } else if (rowBound.bottom > bound.bottom) {
    this.editor.$mainScroller.scrollTop += rowBound.bottom - bound.bottom;
  }
};

LayoutController.prototype.scrollIntoCol = function (col) {
  var colBound = col.elt.getBoundingClientRect();
  var bound = this.editor.$view.getBoundingClientRect();
  var iBound = this.editor.fixedXCtrl.$fixXTable.getBoundingClientRect();

  if (colBound.left < iBound.right) {
    this.editor.$mainScroller.scrollLeft -= iBound.right - colBound.left;
  } else if (colBound.right > bound.right) {
    this.editor.$mainScroller.scrollLeft += colBound.right - bound.right;
  }
};

LayoutController.prototype.ev_scroll = function (tag, event) {
  var now = new Date().getTime();
  if (this._scrollTarget && this._scrollTarget.tag !== tag && now - this._scrollTarget.time < 100) return;
  this._scrollTarget = {
    tag: tag,
    time: now
  };
  var scrollLeft, scrollTop;

  if (tag === 'main') {
    scrollLeft = this.editor.$mainScroller.scrollLeft;

    if (scrollLeft < 0) {
      this.editor.$mainScroller.scrollLeft = 0;
      scrollLeft = 0;
    } else if (scrollLeft > this.editor.$hscrollbar.innerWidth - this.editor.$hscrollbar.outerWidth) {
      scrollLeft = this.editor.$hscrollbar.innerWidth - this.editor.$hscrollbar.outerWidth;
      this.editor.$mainScroller.scrollLeft = scrollLeft;
    }

    this.editor.$hscrollbar.innerOffset = scrollLeft;
    this.editor.$fixedYScroller.scrollLeft = scrollLeft;
    scrollTop = this.editor.$mainScroller.scrollTop;

    if (scrollTop < 0) {
      this.editor.$mainScroller.scrollTop = 0;
      scrollTop = 0;
    } else if (scrollTop > this.editor.$vscrollbar.innerHeight - this.editor.$vscrollbar.outerHeight) {
      scrollTop = this.editor.$vscrollbar.innerHeight - this.editor.$vscrollbar.outerHeight;
      this.editor.$mainScroller.scrollTop = scrollTop;
    }

    this.editor.$vscrollbar.innerOffset = scrollTop;
    this.editor.$fixedXScroller.scrollTop = scrollTop; //todo
  } else if (tag === 'hscrollbar') {
    scrollLeft = this.editor.$hscrollbar.innerOffset;
    this.editor.$mainScroller.scrollLeft = scrollLeft;
    this.editor.$fixedYScroller.scrollLeft = scrollLeft; // this.editor.$fixedYHeaderScroller.scrollLeft = scrollLeft;
  } else if (tag === 'vscrollbar') {
    scrollTop = this.editor.$vscrollbar.innerOffset;
    this.editor.$mainScroller.scrollTop = scrollTop; //todo
  } else if (tag === 'fixedYScroller') {
    scrollLeft = this.editor.$fixedYScroller.scrollLeft;

    if (scrollLeft < 0) {
      scrollLeft = 0;
      this.editor.$fixedYScroller.scrollLeft = 0;
    } else if (scrollLeft > this.editor.$hscrollbar.innerWidth - this.editor.$hscrollbar.outerWidth) {
      scrollLeft = this.editor.$hscrollbar.innerWidth - this.editor.$hscrollbar.outerWidth;
      this.editor.$fixedYScroller.scrollLeft = scrollLeft;
    }

    this.editor.$hscrollbar.innerOffset = scrollLeft;
    this.editor.$mainScroller.scrollLeft = scrollLeft;
  } else if (tag === 'fixedXScroller') {
    scrollTop = this.editor.$fixedXScroller.scrollTop;

    if (scrollTop < 0) {
      this.editor.$fixedXScroller.scrollTop = 0;
      scrollTop = 0;
    } else if (scrollTop > this.editor.$vscrollbar.innerHeight - this.editor.$vscrollbar.outerHeight) {
      scrollTop = this.editor.$vscrollbar.innerHeight - this.editor.$vscrollbar.outerHeight;
      this.editor.$fixedXScroller.scrollTop = scrollTop;
    }

    this.editor.$vscrollbar.innerOffset = scrollTop;
    this.editor.$mainScroller.scrollTop = scrollTop;
  }

  this.editor.editTool.updateEditingBoxPosition();
  this.editor.selectTool.updateSelectedPosition();
};
/**
 * @param {TableEditor} editor
 * @param editor
 * @constructor
 */


function TEFixedYController(editor) {
  this.editor = editor;
}

TEFixedYController.prototype.onViewCreated = function () {
  this.$fixedYTable = (0, _SCore.$)('.asht-table-editor-fixed-y', this.editor.$view);
};

TEFixedYController.prototype.updateContent = function () {
  var head = (0, _SCore.$)(this.editor.tableData.$thead.cloneNode(false));
  head.$origin = this.editor.tableData.$thead;
  var headRows = Array.prototype.filter.call(this.editor.tableData.$thead.childNodes, elt => elt.tagName === 'TR').map(tr => {
    var copyTr = (0, _SCore.$)(tr.cloneNode(false));
    copyTr.$origin = tr;
    var cells = Array.prototype.filter.call(tr.childNodes, elt => elt.tagName === 'TH' || elt.tagName === 'TD').map(td => (0, _SCore.$)(Object.assign(td.cloneNode(true), {
      $origin: td
    })));
    copyTr.addChild(cells);
    return copyTr;
  });
  head.addChild(headRows);
  this.$fixedYTable.clearChild().addChild(head);
  this.$fixedYTable.attr('class', this.editor.tableData.$view.attr('class')).addClass('asht-table-editor-fixed-y');
};

TEFixedYController.prototype.updateSize = function () {
  var cells = this.$fixedYTable.firstChild && Array.prototype.slice.call(this.$fixedYTable.firstChild.firstChild.childNodes);
  var headBound = this.editor.tableData.$thead.getBoundingClientRect();
  cells.forEach((elt, i) => {
    if (i > 0) elt.addStyle('width', elt.$origin.getBoundingClientRect().width + 'px');
  });
  this.editor.$view.addStyle('--head-height', headBound.height + 'px');
};
/**
 * @param {TableEditor} editor
 * @param editor
 * @constructor
 */


function TEFixedXController(editor) {
  this.editor = editor;
}

TEFixedXController.prototype.onViewCreated = function () {
  this.$fixXTable = (0, _SCore.$)('.asht-table-editor-fixed-x', this.editor.$view);
};

TEFixedXController.prototype.updateFullContent = function () {
  console.log("updateFullContent");
  var head, body;
  this.$fixXTable.clearChild();
  this.$fixXTable.$origin = this.editor.tableData.$view;
  head = (0, _SCore.$)(this.editor.tableData.$thead.cloneNode(false));
  head.$origin = this.editor.tableData.$thead;
  var headRows = Array.prototype.filter.call(this.editor.tableData.$thead.childNodes, elt => elt.tagName === 'TR').map(tr => {
    var copyTr = (0, _SCore.$)(tr.cloneNode(false));
    copyTr.$origin = tr;
    var cells = Array.prototype.filter.call(tr.childNodes, elt => elt.tagName === 'TH' || elt.tagName === 'TD');
    cells = cells.slice(0, 1).map(td => (0, _SCore.$)(Object.assign(td.cloneNode(true), {
      $origin: td
    })));
    copyTr.addChild(cells);
    return copyTr;
  });
  head.addChild(headRows);
  body = (0, _SCore.$)(this.editor.tableData.$tbody.cloneNode());
  body.$origin = this.editor.tableData.$tbody;
  var rows = Array.prototype.filter.call(this.editor.tableData.$tbody.childNodes, elt => elt.tagName === 'TR').map(tr => {
    var copyTr = (0, _SCore.$)(tr.cloneNode(false));
    copyTr.$origin = tr;
    var cells = Array.prototype.filter.call(tr.childNodes, elt => elt.tagName === 'TH' || elt.tagName === 'TD');
    cells = cells.slice(0, 1).map(td => (0, _SCore.$)(Object.assign(td.cloneNode(true), {
      $origin: td
    }))); // cells.forEach(elt => {
    //     swapChildrenInElt(elt, elt.$origin);
    //     this._swappedPairs.push([elt, elt.$origin]);
    // });

    copyTr.addChild(cells);
    return copyTr;
  });
  body.addChild(rows);
  this.$fixXTable.addChild(head).addChild(body);
  this.$fixXTable.attr('class', this.editor.tableData.$view.attr('class')).addClass('as-table-scroller-fixed-x');
};

TEFixedXController.prototype.updateChangedContent = function () {
  var body = this.$fixXTable.lastChild;
  var rows = Array.prototype.slice.call(this.editor.tableData.$tbody.childNodes);
  var i = 0;

  while (i < body.childNodes.length) {
    if (body.childNodes[i].$origin !== rows[i]) break;
    i++;
  }

  i = Math.max(0, Math.min(body.childNodes.length - 1, i));

  while (body.childNodes.length > i) {
    body.lastChild.remove();
  }

  rows = rows.slice(i).map(tr => {
    var copyTr = (0, _SCore.$)(tr.cloneNode(false));
    copyTr.$origin = tr;
    var cells = Array.prototype.filter.call(tr.childNodes, elt => elt.tagName === 'TH' || elt.tagName === 'TD');
    cells = cells.slice(0, 1).map(td => (0, _SCore.$)(Object.assign(td.cloneNode(true), {
      $origin: td
    }))); // cells.forEach(elt => {
    //     swapChildrenInElt(elt, elt.$origin);
    //     this._swappedPairs.push([elt, elt.$origin]);
    // });

    copyTr.addChild(cells);
    return copyTr;
  });
  body.addChild(rows);
};

TEFixedXController.prototype.updateContent = function () {
  if (this.$fixXTable.$origin !== this.editor.tableData.$view) {
    this.updateFullContent();
  } else {
    this.updateChangedContent();
  }
};

TEFixedXController.prototype.updateSize = function () {
  // var bound = this.editor.tableData.$view.getBoundingClientRect();
  //todo: index col width set by record length
  // this.$fixXCol.addStyle('height', bound.height + 'px');
  if (!this.editor.tableData) return;
  var firstCell = this.editor.tableData.$view.firstChild.firstChild.firstChild;
  var colSize = firstCell.getBoundingClientRect();
  var colWidth = colSize.width;
  var rowLength = this.editor.tableData.bodyRow.length;
  this.editor.$view.addStyle('--index-col-width', (0, _util.calcIndexColumnWidth)(rowLength) + 'px');
  Array.prototype.forEach.call(this.$fixXTable.firstChild.childNodes, elt => {
    elt.addStyle('height', elt.$origin.getBoundingClientRect().height + 'px'); // elt.addStyle('width', colWidth + 'px');
  });
  Array.prototype.forEach.call(this.$fixXTable.lastChild.childNodes, elt => {
    elt.addStyle('height', elt.$origin.getBoundingClientRect().height + 'px'); // elt.addStyle('width', colWidth + 'px');
  });
};
/**
 * @param {TableEditor} editor
 * @param editor
 * @constructor
 */


function TEFixedXYController(editor) {
  this.editor = editor;
}

TEFixedXYController.prototype.onViewCreated = function () {
  this.$fixedXYTable = (0, _SCore.$)('.asht-table-editor-fixed-xy', this.editor.$view);
  this.$fixedXYTable.addClass('asht-table-data');
};

TEFixedXYController.prototype.updateContent = function () {};

TEFixedXYController.prototype.updateSize = function () {};
/***
 *
 * @param {TableEditor} editor
 * @constructor
 */


function CommandController(editor) {
  this.editor = editor;
  Object.keys(this.constructor.prototype).forEach(key => {
    if (key.startsWith('ev_')) this[key] = this[key].bind(this);
  });
}

CommandController.prototype.onViewCreated = function () {
  _ContextMenu.default.auto();

  this.editor.$view.on('click', this.ev_click);
  this.editor.$view.on('contextmenu', this.ev_contextMenu); // this.editor.$indexCol.on('contextmenu', this.ev_indexColContextMenu);
};

CommandController.prototype.ev_click = function (event) {
  if (this.editor.tableData && (0, _EventEmitter.hitElement)(this.editor.tableData.$view, event)) {
    this.ev_clickTable(event);
  } else if ((0, _EventEmitter.hitElement)(this.editor.fixedXCtrl.$fixXTable.lastChild, event)) {
    this.ev_clickIndexCol(event);
  }
};

CommandController.prototype.ev_contextMenu = function (event) {
  if (this.editor.opt.readOnly) return;

  if ((0, _EventEmitter.hitElement)(this.editor.tableData.$view, event)) {} else if ((0, _EventEmitter.hitElement)(this.editor.fixedXCtrl.$fixXTable.lastChild, event)) {
    this.ev_indexColContextMenu(event);
  } else if ((0, _EventEmitter.hitElement)(this.editor.fixedXYCtrl.$fixedXYTable, event)) {
    this.ev_rootCellContextMenu(event);
  }
};

CommandController.prototype.ev_clickTable = function (event) {
  var c = event.target;
  var cellElt;

  while (c) {
    if (c.hasClass && c.hasClass('asht-table-cell')) {
      cellElt = c;
      this.ev_clickCell(cellElt, event);
      return;
    }

    c = c.parentElement;
  }
};

CommandController.prototype.ev_clickCell = function (cellElt, event) {
  if (this.editor.opt.readOnly) return;
  var colIdx = Array.prototype.indexOf.call(cellElt.parentElement.childNodes, cellElt) - 1;
  var col = this.editor.tableData.findColByIndex(colIdx);
  var rowIdx = Array.prototype.indexOf.call(cellElt.parentElement.parentElement.childNodes, cellElt.parentElement);
  var row = this.editor.tableData.findRowByIndex(rowIdx);
  if (!row && rowIdx >= 0) row = this.editor.tableData.newRow;
  this.editor.editTool.editCellDelay(row, col);
};

CommandController.prototype.ev_clickIndexCol = function (ev) {
  if (this.editor.opt.readOnly) return;
  var c = ev.target;

  while (c) {
    if (c.tagName === 'TR') break;
    c = c.parentElement;
  }

  if (!c) return;
  var rowIdx = Array.prototype.indexOf.call(c.parentElement.childNodes, c);
  var row = this.editor.tableData.findRowByIndex(rowIdx) || this.editor.tableData.newRow;
  this.editor.selectRow(row);
  var firstCol = this.editor.tableData.findColByIndex(0);
  this.editor.editTool.editCellDelay(row, firstCol);
};

CommandController.prototype.ev_indexColContextMenu = function (ev) {
  var thisTE = this.editor;
  var c = ev.target;

  while (c) {
    if (c.tagName === 'TR') break;
    c = c.parentElement;
  }

  if (!c) return;
  var rowIdx = Array.prototype.indexOf.call(c.parentElement.childNodes, c);
  var row = this.editor.tableData.findRowByIndex(rowIdx) || this.editor.tableData.newRow;
  this.editor.selectRow(row);
  var items = [];

  if (row.idx === "*") {} else {
    items.push({
      cmd: 'insert_before',
      text: 'Insert Before',
      icon: 'span.mdi.mdi-table-row-plus-before'
    }, {
      cmd: 'insert_after',
      text: 'Insert After',
      icon: 'span.mdi.mdi-table-row-plus-after'
    }, {
      cmd: 'remove',
      text: 'Delete',
      icon: 'span.mdi.mdi-table-row-remove'
    });
  }

  if (items.length > 0 && items[items.length - 1] !== '===') {
    items.push("===");
  }

  if (row.idx !== "*") {
    items.push({
      cmd: 'copy',
      text: "Copy",
      icon: "span.mdi.mdi-content-copy"
    });
  }

  items.push({
    cmd: 'paste',
    text: "Paste",
    icon: 'span.mdi.mdi-content-paste'
  });
  items.push('===', {
    cmd: 'row_height',
    text: 'Row Height',
    icon: 'span.mdi.mdi-table-row-height'
  });
  ev.showContextMenu({
    extendStyle: {
      fontSize: '14px'
    },
    items: items
  }, function (ev1) {
    var cmd = ev1.menuItem.cmd;
    var eventOpt = {
      cmd: cmd
    };
    var ev2;
    console.log(cmd);

    switch (cmd) {
      case 'row_height':
        (0, _dialogs.selectRowHeight)({
          value: thisTE.tableData.config.rowHeight,
          standard: 21
        }).then(function (result) {
          thisTE.tableData.config.rowHeight = result;
          thisTE.layoutCtrl.updateStyleConfig();

          _ResizeSystem.default.updateDown(thisTE.$attachook);
        }, err => {
          if (err) console.error(err);
        });
        break;

      case 'remove':
        eventOpt.type = 'cmd_remove_row';
        eventOpt.rowIdx = row.idx;
        eventOpt.accepted = true;
        ev2 = new _Abstractions.ASHTConfirmEvent(eventOpt);
        thisTE.emit(eventOpt.type, ev2, thisTE);
        ev2.afterThen(isAccept => {
          if (isAccept) thisTE.removeRow(eventOpt.rowIdx);
        });
        break;

      case 'insert_before':
      case 'insert_after':
        eventOpt.type = 'cmd_insert_row';
        eventOpt.rowIdx = row.idx + (cmd === 'insert_after' ? 1 : 0);
        ev2 = new _Abstractions.ASHTWaitValueEvent(eventOpt);
        thisTE.emit(eventOpt.type, ev2, thisTE);
        ev2.afterThen(result => {
          if (result) {
            thisTE.insertRow(eventOpt.rowIdx, result);
          } else if (result === null) {
            thisTE.insertRow(eventOpt.rowIdx, {});
          }
        });
        break;

      case "copy":
        (0, _Clipboard.copyText)(JSON.stringify(row.record));
        break;

      case "paste":
        (0, _Clipboard.pasteText)().then(function (result) {
          try {
            var obj = (0, _util.duplicateData)(JSON.parse(result));
            thisTE.tableData.propertyNames.forEach(function (cr) {
              row.propertyByName[cr].value = obj[cr];
            }, {});

            if (thisTE.editTool.currentCellEditor) {
              thisTE.editTool.currentCellEditor.reload();
            }

            _ResizeSystem.default.update();
          } catch (e) {
            (0, _safeThrow.default)(e);
          }
        });
        break;
    }
  });
};

CommandController.prototype.ev_rootCellContextMenu = function (ev) {
  var thisTE = this.editor;
  ev.showContextMenu({
    items: [{
      cmd: 'insert_first',
      text: 'Insert First',
      icon: 'span.mdi.mdi-table-row-plus-before'
    }, {
      cmd: 'append_last',
      text: 'Append Last',
      icon: 'span.mdi.mdi-table-row-plus-after'
    }]
  }, function (ev1) {
    var cmd = ev1.menuItem.cmd;
    var eventOpt = {
      cmd: cmd
    };
    eventOpt.type = 'cmd_insert_row';
    eventOpt.rowIdx = cmd === 'insert_first' ? 0 : thisTE.tableData.getLength();
    eventOpt.result = {};

    eventOpt.resolve = function (result) {
      this.result = result;
    };

    thisTE.emit(eventOpt.type, eventOpt, thisTE);

    if (eventOpt.result) {
      if (eventOpt.result.then) {
        eventOpt.result.then(function (result) {
          if (result) {
            thisTE.insertRow(eventOpt.rowIdx, result);

            if (cmd === 'append_last') {
              thisTE.$body.scrollTop = thisTE.$body.scrollHeight - thisTE.$body.clientHeight;
            }
          }
        });
      } else {
        thisTE.insertRow(eventOpt.rowIdx, eventOpt.result);
        thisTE.$mainScroller.scrollTop = thisTE.$mainScroller.scrollHeight - thisTE.$mainScroller.clientHeight;
      }
    }
  });
};

VaKeR 2022