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__messageinput__MessageInputPlugin.js
/*** module: node_modules/absol-acomp/js/messageinput/MessageInputPlugin.js ***/
"use strict";

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

var _stringGenerate = require("absol/src/String/stringGenerate");

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

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

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


/***
 * @typedef MessageInputPluginOption
 * @property {string} [id]
 * @property {string|Object|AElement} icon
 * @property {function(_thisAdapter: MessageInputPlugin, _:Dom._, Dom.$):AElement} createContent
 * @property {function(_thisAdapter:MessageInputPlugin):void} onPressTrigger
 * @property {"left"|"right"} popupAlign
 * @property {boolean=} alwaysVisible
 */

/***
 *
 * @param {MessageInput} inputElt
 * @param {MessageInputPluginOption} opt
 * @constructor
 */
function MessageInputPlugin(inputElt, opt) {
  this.opt = opt || {};
  this.inputElt = inputElt;
  this.icon = opt.icon;
  this.id = opt.id || (0, _stringGenerate.randomIdent)(16);
  this.alwaysVisible = !!opt.alwaysVisible;
  this.$icon = null;
  this.$triggerBtn = null;
  this.$content = null;
  this.$popup = null;
  if (opt.createContent) this.createContent = opt.createContent;
  if (opt.onPressTrigger) this.onPressTrigger = opt.onPressTrigger;
  this.autoClose = true;

  if ('autoClose' in opt) {
    this.autoClose = !!opt.autoClose;
  }

  this.popupAlign = opt.popupAlign || 'left';
  this.ev_pressTrigger = this.ev_pressTrigger.bind(this);
  this.ev_pressOut = this.ev_pressOut.bind(this);
}

MessageInputPlugin.prototype.isMessagePlugin = true;

MessageInputPlugin.prototype.ev_pressTrigger = function (event) {
  var value = this.inputElt.$preInput.value;
  this._lastInputSelectPosion = this.inputElt.$preInput.getSelectPosition() || {
    start: value.length,
    end: value.length
  };

  if (this.onPressTrigger) {
    this.onPressTrigger(this);
  } else {
    if (this.isPopupOpened()) {
      this.closePopup();
    } else {
      this.openPopup();
    }
  }
};

MessageInputPlugin.prototype.insertText = function (itext) {
  if (!this._lastInputSelectPosion) {
    throw new Error('Invalid call');
  }

  var text = this.inputElt.$preInput.value;
  var newText = text.substr(0, this._lastInputSelectPosion.start) + itext + text.substr(this._lastInputSelectPosion.end);
  var selected = this._lastInputSelectPosion;
  var newOffset = selected.start + itext.length;
  this.inputElt.$preInput.focus();
  this.inputElt.$preInput.applyData(newText, newOffset);
  this.inputElt.$preInput.commitChange(newText, newOffset);
  this.inputElt.notifySizeChange();
  this.inputElt.$preInput.focus();
};

MessageInputPlugin.prototype.appendText = function (itext) {
  if (!this._lastInputSelectPosion) {
    throw new Error('Invalid call');
  }

  var text = this.inputElt.$preInput.value;
  var newText = text + itext;
  var newOffset = newText.length;
  this.inputElt.$preInput.focus();
  this.inputElt.$preInput.applyData(newText, newOffset);
  this.inputElt.$preInput.commitChange(newText, newOffset);
  this.inputElt.notifySizeChange();
  this.inputElt.$preInput.focus();
};

MessageInputPlugin.prototype.replaceText = function (itext) {
  if (!this._lastInputSelectPosion) {
    throw new Error('Invalid call');
  }

  var newText = itext;
  var newOffset = newText.length;
  this.inputElt.$preInput.focus();
  this.inputElt.$preInput.applyData(newText, newOffset);
  this.inputElt.$preInput.commitChange(newText, newOffset);
  this.inputElt.notifySizeChange();
  this.inputElt.$preInput.focus();
};

MessageInputPlugin.prototype.ev_pressOut = function (event) {
  if (_EventEmitter.default.hitElement(this.getTriggerButton(), event)) return;
  if (_EventEmitter.default.hitElement(this.getPopup(), event)) return;
  if (!this.autoClose) return;
  this.closePopup();
};

MessageInputPlugin.prototype.getIconElt = function () {
  if (!this.$icon) this.$icon = (0, _ACore._)(this.icon);
  return this.$icon;
};

MessageInputPlugin.prototype.getTriggerButton = function () {
  if (!this.$triggerBtn) {
    this.$triggerBtn = (0, _ACore._)({
      tag: 'button',
      class: ['as-message-input-plugin-btn', 'as-message-input-plugin-' + this.id],
      child: this.getIconElt(),
      on: {
        click: this.ev_pressTrigger
      }
    });

    if (this.alwaysVisible) {
      this.$triggerBtn.addClass('as-always-visible');
    }
  }

  return this.$triggerBtn;
};

MessageInputPlugin.prototype.createContent = function (_thisAdapter, _, $) {
  return _({
    tag: 'div'
  });
};
/***
 *
 * @type {null|function(_thisAdapter:MessageInputPlugin):void}
 */


MessageInputPlugin.prototype.onPressTrigger = null;

MessageInputPlugin.prototype.getContent = function () {
  if (!this.$content) this.$content = this.createContent(this.inputElt, _ACore._, _ACore.$);
  return this.$content;
};

MessageInputPlugin.prototype.getPopup = function () {
  if (!this.$popup) {
    this.$popup = (0, _ACore._)({
      class: ['as-message-input-external-tools-popup', 'as-align-' + this.popupAlign],
      child: this.getContent()
    });
  }

  return this.$popup;
};

MessageInputPlugin.prototype.openPopup = function () {
  if (this.isPopupOpened()) return;
  this.inputElt.appendChild(this.getPopup());
  document.body.addEventListener('click', this.ev_pressOut);
  this.onOpen();

  if (this.opt.onOpen) {
    this.opt.onOpen.call(this, this.inputElt, _ACore._, _ACore.$);
  }
};

MessageInputPlugin.prototype.closePopup = function () {
  if (!this.isPopupOpened()) return;

  if (this.opt.onClose) {
    this.opt.onClose.call(this, this.inputElt, _ACore._, _ACore.$);
  }

  this.onClose();
  this.getPopup().remove();
  document.body.removeEventListener('click', this.ev_pressOut);
};

MessageInputPlugin.prototype.isPopupOpened = function () {
  return !!this.getPopup().parentElement;
};

MessageInputPlugin.prototype.onOpen = _noop.default;
MessageInputPlugin.prototype.onClose = _noop.default;
Object.defineProperty(MessageInputPlugin.prototype, 'contentElt', {
  get: function () {
    return this.getContent();
  }
});
var _default = MessageInputPlugin;
exports.default = _default;

VaKeR 2022