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-form/js/components/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/libs/absol-form/js/components/Text.js
import FCore from "../core/FCore";
import ScalableComponent from "../core/ScalableComponent";
import showdown from 'showdown';
import inheritComponentClass from "../core/inheritComponentClass";
import TextStyleHandlers from "./handlers/TextStyleHandlers";
import {AssemblerInstance} from "../core/Assembler";

var _ = FCore._;

var showDownConverter = new showdown.Converter();


/***
 * @extends ScalableComponent
 * @constructor
 */
function Text() {
    ScalableComponent.call(this);
}

inheritComponentClass(Text, ScalableComponent);

Text.prototype.tag = "Text";
Text.prototype.menuIcon = "span.mdi.mdi-format-color-text";

Text.prototype.attributeHandlers.text = {
    set: function (value) {
        var ref = arguments[arguments.length - 1];
        var prev = ref.get();
        value = (value || '') + '';
        switch (this.attributes.textDecode) {
            case 'html':
                this.domElt.innerHTML = value;
                break;
            case 'markdown':
                this.domElt.innerHTML = showDownConverter.makeHtml(value).trim().replace(/(^<p>)|(<\/p>$)/, '');
                break;
            default:
                this.domElt.clearChild().addChild(_({ text: value }));
        }
        ref.set(value);
        if (prev !== value){
            this.pinFire('value');
            this.notifyChange();
        }
        return value;
    },
    descriptor: {
        type: "text",
        long: true,
        sign: "HyperText"
    }
};


Text.prototype.attributeHandlers.textDecode = {
    set: function (value) {
        if (['none', 'markdown', 'html'].indexOf(value) < 0) value = 'none';
        var ref = arguments[arguments.length - 1];
        var currentValue = ref.get();
        if (currentValue !== value) {
            this.domElt.removeClass('as-decode-' + currentValue);
            this.domElt.addClass('as-decode-' + value);
            ref.set(value);
            this.attributes.text = this.attributes.text + '';
        }
        return value;
    },

    export: function (ref) {
        var value = ref.get();
        if (value === 'none') return undefined;
        return value;
    },
    descriptor: {
        type: "enum",
        values: ['none', 'markdown', 'html'],
        sign: 'TextDecode'
    }
};

Object.assign(Text.prototype.styleHandlers, TextStyleHandlers);


Text.prototype.pinHandlers.text = {
    receives: function (value) {
        this.attributes.text = value;
    },
    get: function () {
        return this.attributes.text;
    },
    descriptor: {
        type: 'text'
    }
};


Text.prototype.onCreate = function () {
    ScalableComponent.prototype.onCreate.call(this);
    this.attributes.text = this.attributes.name;
    this.attributes.textDecode = 'none';
    this.style.font = undefined;
    this.style.fontStyle = undefined;
    this.style.textSize = 0;
    this.style.textAlign = 'left';
    this.style.textColor = 'black';
    this.style.font = 'unset';
};

Text.prototype.render = function () {
    return _('div.absol-bscroller.as-text');
};


Text.prototype.getAcceptsStyleNames = function () {
    return ScalableComponent.prototype.getAcceptsStyleNames.call(this).concat(['font', 'fontStyle', 'textSize', 'textAlign', 'textColor']);
};

Text.prototype.createDataBindingDescriptor = function () {
    var thisC = this;
    return {
        set: function (value) {
            thisC.setAttribute('text', value);
        },
        get: function () {
            return thisC.getAttribute('text');
        }
    }
};

AssemblerInstance.addClass(Text);

export default Text;

VaKeR 2022