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-poser__fragment__PoserQuestionTreeEditor.js
/*** module: node_modules/absol-poser/fragment/PoserQuestionTreeEditor.js ***/
"use strict";

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

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

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

var _Core = require("../dom/Core");

require("absol-form/css/cmdtool.css");

var _ExpTree = _interopRequireWildcard(require("absol-acomp/js/ExpTree"));

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

var _QuestionTypeItems = require("../contants/QuestionTypeItems");

var _Hanger = _interopRequireDefault(require("absol-acomp/js/Hanger"));

var _Vec = _interopRequireDefault(require("absol/src/Math/Vec2"));

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




/***
 * @extends Fragment
 * @param poserEditor
 * @constructor
 */
function PoserQuestionTreeEditor(poserEditor) {
  _Fragment.default.call(this);

  this.poserEditor = poserEditor;

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

  this._dragData = {
    tree: null
  };
}

_OOP.default.mixClass(PoserQuestionTreeEditor, _Fragment.default);

PoserQuestionTreeEditor.prototype.createView = function () {
  this.$view = (0, _Core._)({
    class: 'ap-question-tree-editor',
    child: [{
      class: 'ap-question-tree-exp-scroller'
    }]
  });
  this.$scroller = (0, _Core.$)('.ap-question-tree-exp-scroller', this.$view);

  if (!this.poserEditor.opt.hasSection) {
    this.$view.addClass('ap-without-section');
  }
};

PoserQuestionTreeEditor.prototype.reload = function () {
  var thisE = this;
  this.$scroller.clearChild();
  this.$root = (0, _Core._)({
    tag: _ExpTree.ExpGroup.tag
  });
  var readOnly = this.poserEditor.opt.readOnly;
  (0, _Core._)({
    tag: readOnly ? 'div' : _Hanger.default.tag,
    elt: this.$root,
    on: {
      predrag: this.ev_predrag,
      dragstart: this.ev_dragstart,
      dragend: this.ev_dragend,
      drag: this.ev_drag
    },
    props: {
      hangOn: 5
    }
  });
  this.$scroller.addChild(this.$root);
  Array.prototype.reduce.call(this.poserEditor.$data.childNodes, function (ac, elt) {
    if (elt.apBlockType === 'section') {
      ac.section = (0, _Core._)({
        tag: _ExpTree.default.tag,
        props: {
          name: elt.data.name,
          icon: 'span.mdi.mdi-format-section',
          bindingBlock: elt,
          bindingBlockType: 'section'
        }
      });
      elt.bindingTreeNode = ac.section;
      ac.root.addChild(ac.section);
      ac.section.on('press', thisE.ev_press.bind(thisE, ac.section));
    } else if (elt.apBlockType === 'question') {
      var qt = (0, _Core._)({
        tag: _ExpTree.default.tag,
        props: {
          name: elt.data.content,
          icon: _QuestionTypeItems.QuestionType2Icon[elt.data.type],
          bindingBlock: elt,
          bindingBlockType: 'question'
        }
      });
      if (elt.hasClass('ap-focus')) qt.addClass('ap-focus');
      elt.bindingTreeNode = qt;
      ac.section.addChild(qt);
      qt.on('press', thisE.ev_press.bind(thisE, qt));
    }

    return ac;
  }, {
    root: this.$root,
    section: null
  });
};

PoserQuestionTreeEditor.prototype._findTree = function (elt) {
  while (elt && elt !== this.$root) {
    if (elt.classList && elt.classList.contains('absol-exp-tree')) {
      return elt;
    }

    elt = elt.parentElement;
  }

  return null;
};

PoserQuestionTreeEditor.prototype.ev_dragstart = function (event) {
  this.$view.addClass('ap-dragging');
  var dData = this._dragData;
  dData.initTreeBound = dData.tree.getBoundingClientRect();
  var crRootBound = this.$root.getBoundingClientRect();
  dData.initRootBound = crRootBound;
  dData.mouseOffset = event.currentPoint.sub(new _Vec.default(dData.initTreeBound.left, dData.initTreeBound.top));
  dData.clonedTree = (0, _Core.$)(dData.tree.cloneNode(true)).addClass('ap-question-tree-editor-cloned-node').addStyle('width', dData.initTreeBound.width + 'px');
  dData.nextTree = dData.tree.parentElement.findChildAfter(dData.tree);
  dData.tree.addClass('ap-moving');
  dData.initY = dData.initTreeBound.top - dData.initRootBound.top;

  if (dData.type === 'section') {
    dData.positions = dData.positions || Array.prototype.map.call(this.$root.childNodes, function (node) {
      return {
        bfr: node,
        y: node.getBoundingClientRect().top - crRootBound.top
      };
    }).concat({
      bfr: null,
      //last
      y: crRootBound.height
    });
  } else {
    dData.positions = dData.positions || Array.prototype.reduce.call(this.$root.childNodes, function (ac, sectionTree) {
      var questionNodes = sectionTree.getChildren();
      var sPositions = questionNodes.map(function (qNode) {
        return {
          bfr: qNode,
          parent: sectionTree,
          y: qNode.getBoundingClientRect().top - crRootBound.top
        };
      });
      sPositions.push({
        bfr: null,
        parent: sectionTree,
        y: sectionTree.getBoundingClientRect().bottom - crRootBound.top
      });
      ac = ac.concat(sPositions);
      return ac;
    }, []);
  }

  var eBoundRect = _Rectangle.default.fromClientRect(this.$view.getBoundingClientRect());

  dData.clonedTree.addStyle('top', event.currentPoint.sub(eBoundRect.A()).sub(dData.mouseOffset).y + 'px');
  this.$view.appendChild(dData.clonedTree);
};

PoserQuestionTreeEditor.prototype.ev_drag = function (event) {
  event.preventDefault();
  var dData = this._dragData;
  var crRootBound = this.$root.getBoundingClientRect();
  var dy = crRootBound.top - dData.initRootBound.top + event.currentPoint.sub(event.startingPoint).y;
  var y = dData.initY + dy;

  var eBoundRect = _Rectangle.default.fromClientRect(this.$view.getBoundingClientRect());

  dData.clonedTree.addStyle('top', event.currentPoint.sub(eBoundRect.A()).sub(dData.mouseOffset).y + 'px');
  dData.nearestPosition = dData.positions.reduce(function (ac, cr) {
    var d = Math.abs(y + 15 - cr.y);

    if (d < ac.minDist) {
      ac.nearest = cr;
      ac.minDist = d;
    }

    return ac;
  }, {
    nearest: null,
    minDist: Infinity
  }).nearest;
  this.$view.addStyle('--new-pos-y', dData.nearestPosition.y + 'px');

  if (dData.nearestPosition.bfr === dData.tree || dData.nearestPosition.bfr === dData.nextTree) {
    this.$view.removeClass('ap-changed');
    dData.changed = false;
  } else {
    this.$view.addClass('ap-changed');
    dData.changed = true;
  }
};

PoserQuestionTreeEditor.prototype.ev_dragend = function () {
  clearInterval(this._scrollAutoInv);
  var dData = this._dragData;
  dData.clonedTree.remove();
  dData.tree.removeClass('ap-moving');
  var blockCtn, bf, af;

  if (dData.changed) {
    blockCtn = dData.tree.bindingBlock.parentElement;
    dData.tree.selfRemove();

    if (dData.type === 'section') {
      var sectionElementList = Array.prototype.reduce.call(blockCtn.childNodes, function (ac, cr) {
        if (ac.end) return ac;

        if (cr === dData.tree.bindingBlock) {
          ac.start = true;
          ac.result.push(cr);
        } else if (ac.start) {
          if (cr.apBlockType === 'section') {
            ac.end = true;
          } else {
            ac.result.push(cr);
          }
        }

        return ac;
      }, {
        start: false,
        end: false,
        result: []
      }).result;
      sectionElementList.forEach(function (elt) {
        elt.selfRemove();
      });

      if (dData.nearestPosition.bfr) {
        this.$root.addChildBefore(dData.tree, dData.nearestPosition.bfr);
        bf = dData.nearestPosition.bfr.bindingBlock;
        sectionElementList.forEach(function (elt) {
          blockCtn.addChildBefore(elt, bf);
        });

        this._focusDelay(sectionElementList[0]);
      } else {
        this.$root.addChild(dData.tree);
        sectionElementList.forEach(function (elt) {
          blockCtn.addChild(elt);
        });

        this._focusDelay(sectionElementList[0]);
      }
    } else {
      dData.tree.bindingBlock.selfRemove();

      if (dData.nearestPosition.bfr) {
        dData.nearestPosition.parent.addChildBefore(dData.tree, dData.nearestPosition.bfr);
        blockCtn.addChildBefore(dData.tree.bindingBlock, dData.nearestPosition.bfr.bindingBlock);
      } else {
        dData.nearestPosition.parent.addChild(dData.tree);
        bf = dData.nearestPosition.parent.parentElement.findChildAfter(dData.nearestPosition.parent);

        if (bf) {
          blockCtn.addChildBefore(dData.tree.bindingBlock, bf.bindingBlock);
        } else {
          blockCtn.addChild(dData.tree.bindingBlock);
        }
      }

      this._focusDelay(dData.tree.bindingBlock);
    }

    this.poserEditor.updateIdx();
    this.poserEditor.notifyChange();
  }

  this._dragData = {};
  this.$view.removeClass('ap-dragging');
  this.$view.removeClass('ap-changed');
};

PoserQuestionTreeEditor.prototype.ev_predrag = function (event) {
  var tree = this._findTree(event.target);

  if (!tree) event.cancel(); // event.cancel();
  // Snackbar.show("Chức năng kéo thả hiện đang được xử lý.");
  // return;

  this._dragData.tree = tree;
  this._dragData.type = tree.bindingBlockType;
  event.preventDefault();
};

PoserQuestionTreeEditor.prototype.ev_press = function (tree, event) {
  this.poserEditor.focusBlock(tree.bindingBlock, true);
};

PoserQuestionTreeEditor.prototype._focusDelay = function (elt) {
  setTimeout(function () {
    this.poserEditor.focusBlock(elt, true);
  }.bind(this), 100);
};

var _default = PoserQuestionTreeEditor;
exports.default = _default;

VaKeR 2022