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-form__js__blocks__CBFunction.js
/*** module: node_modules/absol-form/js/blocks/CBFunction.js ***/
"use strict";

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

var _Assembler = require("../core/Assembler");

var _BaseBlock = _interopRequireDefault(require("../core/BaseBlock"));

var _inheritComponentClass = _interopRequireDefault(require("../core/inheritComponentClass"));

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

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


function CBFunction() {
  _BaseBlock.default.call(this);

  this.func = _noop.default;
  this.attributes.args = [];
  this.attributes.body = '';
  this.pinHandlers = Object.assign({}, CBFunction.prototype.pinHandlers);
  this.receivedArgValues = {};
  this.result = undefined;
}

(0, _inheritComponentClass.default)(CBFunction, _BaseBlock.default);
CBFunction.prototype.tag = 'function';
CBFunction.prototype.menuIcon = 'span.mdi.mdi-function';
CBFunction.prototype.attributeHandlers.body = {
  set: function (value, ref) {
    ref.set(value);

    if (value && this.attributes.args) {
      this.rebuildFunction();
    }

    return value;
  },
  descriptor: {
    type: 'text'
  }
};
CBFunction.prototype.attributeHandlers.args = {
  set: function (args, ref) {
    ref.set(args || []);
    this.rebuildFunction();
    return ref.get();
  },
  descriptor: {
    type: 'text[]'
  }
};
CBFunction.prototype.attributeHandlers.defaultArgs = {
  set: function (value) {
    Object.assign(this.receivedArgValues, value);
    return value;
  },
  descriptor: {
    type: 'object'
  }
};
CBFunction.prototype.pinHandlers.exec = {
  receives: function () {
    this.exec();
  },
  descriptor: {
    type: 'bool'
  }
};
CBFunction.prototype.pinHandlers.result = {
  get: function () {
    return this.result;
  }
};

CBFunction.prototype.rebuildFunction = function () {
  var self = this;

  try {
    this.pinHandlers = this.attributes.args.reduce(function (ac, cr) {
      ac[cr] = {
        receives: function (value) {
          if (value && value.then) {
            value.then(function () {
              self.receivedArgValues[cr] = value;
              self.exec();
            });
          } else {
            self.receivedArgValues[cr] = value;
            self.exec();
          }
        }
      };
      return ac;
    }, {});
    Object.assign(this.pinHandlers, CBFunction.prototype.pinHandlers);
    this.func = new Function([`return function(${this.attributes.args.join(', ')}){`, this.attributes.body, '}'].join('\n'))();
  } catch (error) {
    (0, _safeThrow.default)(error);
    this.func = _noop.default;
  }
};

CBFunction.prototype.exec = function () {
  var self = this;
  var receivedArgValues = this.receivedArgValues;
  var completeArg = true;
  var result;
  var args = this.attributes.args.map(function (name) {
    if (name in receivedArgValues) {
      return receivedArgValues[name];
    } else completeArg = false;
  });

  if (completeArg) {
    var task = this.fragment.newTask();

    try {
      result = this.func.apply(this, args);
    } catch (err) {
      task.finish();
      (0, _safeThrow.default)(err);
      console.error("Execute script error", this, err);
      return;
    }

    if (result && result.then) {
      result.then(function (result) {
        self.result = result;
        if (result !== undefined) self.pinFire('result');
        task.finish();
      }).catch(function (err) {
        (0, _safeThrow.default)(err);
        console.error("Execute script error", this, err);
        task.finish();
      }.bind(this));
    } else {
      this.result = result;
      if (result !== undefined) this.pinFire('result');
      task.finish();
    }
  }
};

_Assembler.AssemblerInstance.addClass(CBFunction);

var _default = CBFunction;
exports.default = _default;

VaKeR 2022