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-acomp__js__tablescroller__TSLMoveTool.js
/*** module: node_modules/absol-acomp/js/tablescroller/TSLMoveTool.js ***/
"use strict";

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

var _Hanger = _interopRequireDefault(require("../Hanger"));

var _ACore = require("../../ACore");

var _Rectangle = _interopRequireDefault(require("absol/src/Math/Rectangle"));


/***
 *
 * @param {TableScroller} elt
 * @constructor
 */
function TSLMoveTool(elt) {
  this.elt = elt;
  this.$table = null;
  Object.keys(TSLMoveTool.prototype).forEach(key => {
    if (key.startsWith('ev_')) {
      this[key] = this[key].bind(this);
    }
  });
  this.init();
}

TSLMoveTool.prototype.init = function () {
  this.elt = (0, _ACore._)({
    tag: _Hanger.default,
    elt: this.elt,
    on: {
      predrag: this.ev_preDrag,
      dragstart: this.ev_dragStart,
      drag: this.ev_drag,
      dragend: this.ev_dragEnd
    }
  });
};

TSLMoveTool.prototype.onAttachTable = function () {};

TSLMoveTool.prototype.ev_preDrag = function (event) {
  var e = event.target;
  var isOK = false;

  while (e && e.tagName !== 'TABLE') {
    if (e.classList && e.classList.contains('as-drag-zone')) {
      isOK = true;
      break;
    }

    e = e.parentElement;
  }

  if (isOK) {
    event.preventDefault();
  } else {
    event.cancel();
  }
};

TSLMoveTool.prototype._findRowIdx = function (y) {
  var newY = _Rectangle.default.fromClientRect(this.elt.$originTableBody.getBoundingClientRect()).y;

  var oldY = this.dragData.bodyBound.y;
  var dy = newY - oldY;
  var yArr = this.dragData.rowBounds.map(rect => rect.y + dy + rect.height / 2);
  if (this.dragData.rowBounds.length === 0) yArr.push(0);
  var low = 0;
  var high = yArr.length - 1;
  var mid0, mid1;

  while (low < high) {
    mid0 = low + high >> 1;
    mid1 = mid0 + 1;

    if (Math.abs(y - yArr[mid0]) < Math.abs(y - yArr[mid1])) {
      high = mid0;
    } else {
      low = mid1;
    }
  }

  return low;
};

TSLMoveTool.prototype.ev_dragStart = function (event) {
  var t = this.findRow(event.target);
  if (!t) return;
  this.elt.addClass('as-dragging');
  this.dragData = Object.assign({}, t);
  this.dragData.copy.addClass('as-dragging');
  this.dragData.original.addClass('as-dragging');

  var rowBound = _Rectangle.default.fromClientRect(this.dragData.original.getBoundingClientRect());

  var bodyBound = _Rectangle.default.fromClientRect(this.elt.$originTableBody.getBoundingClientRect());

  this.dragData.mouseOffset = event.currentPoint.sub(rowBound.A());
  this.dragData.rowIdx = Array.prototype.indexOf.call(this.elt.$originTableBody.childNodes, this.dragData.original);
  this.dragData.newRowIdx = this.dragData.rowIdx;
  this.dragData.rowBound = rowBound;
  this.dragData.bodyBound = bodyBound;
  this.dragData.rowOffset = rowBound.A().sub(bodyBound.A());
  this.dragData.rowBounds = Array.prototype.map.call(this.elt.$originTableBody.childNodes, elt => _Rectangle.default.fromClientRect(elt.getBoundingClientRect()));
};

TSLMoveTool.prototype.ev_drag = function (event) {
  if (!this.dragData) return;

  var bodyBound = _Rectangle.default.fromClientRect(this.elt.$originTableBody.getBoundingClientRect());

  var rowA = bodyBound.A().add(this.dragData.rowOffset);
  var rowTransformed = event.currentPoint.sub(this.dragData.mouseOffset);
  var transform = rowTransformed.sub(rowA);
  var originalRow = this.dragData.original;
  originalRow.addStyle('transform', `translate(0, ${transform.y}px )`);
  this.dragData.copy.addStyle('transform', `translate(0, ${transform.y}px )`);
  this.dragData.hiddenCells = Array.prototype.filter.call(this.dragData.original.childNodes, e => e.tagName === 'TD').slice(0, this.elt.fixedCol);
  this.dragData.hiddenCells.forEach(e => (0, _ACore.$)(e).addClass('as-transparent-fix'));

  var newIdx = this._findRowIdx(rowTransformed.y + this.dragData.rowBound.height / 2);

  this.dragData.newRowIdx = newIdx;
  var rows = this.elt.$originTableBody.childNodes;
  var curIdx = this.dragData.rowIdx; // var copyRows = this.elt.$f

  var rowBound = this.dragData.rowBound;
  rows.forEach((elt, i) => {
    if (elt === originalRow) return;
    var copyElt = this.elt.leftCopyRows[elt.getAttribute('data-id')];
    var dy = 0;

    if (i >= Math.min(newIdx, curIdx) && i <= Math.max(newIdx, curIdx)) {
      if (i > curIdx && i <= newIdx) {
        dy = -rowBound.height;
      } else if (i >= newIdx && i < curIdx) {
        dy = rowBound.height;
      }
    }

    elt.addStyle('transform', `translate(0, ${dy}px)`);
    copyElt.addStyle('transform', `translate(0, ${dy}px)`);
  });
};

TSLMoveTool.prototype.ev_dragEnd = function (event) {
  this.dragData.original.removeStyle('transform');
  this.dragData.copy.removeStyle('transform');
  this.dragData.copy.removeClass('as-dragging');
  this.dragData.original.removeClass('as-dragging');
  this.elt.removeClass('as-dragging');
  this.elt.removeClass('as-has-new-pos');
  this.dragData.hiddenCells.forEach(e => e.removeClass('as-transparent-fix'));
  var rows = this.elt.$originTableBody.childNodes;
  rows.forEach(elt => {
    var copyElt = this.elt.leftCopyRows[elt.getAttribute('data-id')];
    elt.addStyle('transform', 'translate(0, 0)');
    copyElt.addStyle('transform', 'translate(0, 0)');
  });
  var at, copyAt;

  if (this.dragData.newRowIdx !== this.dragData.rowIdx) {
    at = rows[this.dragData.newRowIdx];
    copyAt = this.elt.leftCopyRows[at.attr('data-id')];

    if (this.dragData.rowIdx < this.dragData.newRowIdx) {
      (0, _ACore.$)(at.parentElement).addChildAfter(this.dragData.original, at);
      (0, _ACore.$)(copyAt.parentElement).addChildAfter(this.dragData.copy, copyAt);
    } else {
      (0, _ACore.$)(at.parentElement).addChildBefore(this.dragData.original, at);
      (0, _ACore.$)(copyAt.parentElement).addChildBefore(this.dragData.copy, copyAt);
    }

    this.elt.reindexRows();
    this.elt.emit('orderchange', {
      target: this.elt,
      from: this.dragData.rowIdx,
      to: this.dragData.newRowIdx
    }, this.elt);
  }
};

TSLMoveTool.prototype.findRow = function (fromElt) {
  var e = fromElt;
  var rowElt;

  while (e) {
    if (e.tagName === 'TR') {
      rowElt = e;
      break;
    }

    e = e.parentElement;
  }

  if (!rowElt) return null;
  var id = rowElt.getAttribute('data-id');
  return {
    original: (0, _ACore.$)(this.elt.originalRows[id]),
    copy: (0, _ACore.$)(this.elt.leftCopyRows[id])
  };
};

var _default = TSLMoveTool;
exports.default = _default;

VaKeR 2022