@dooboostore/dom-render
Version:
html view template engine
125 lines (124 loc) • 4.51 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var CheckBox_exports = {};
__export(CheckBox_exports, {
CheckBox: () => CheckBox,
default: () => CheckBox_default
});
module.exports = __toCommonJS(CheckBox_exports);
var import_ComponentBase = require("../ComponentBase");
var import_DomRender = require("../../DomRender");
var import_RawSet = require("../../rawsets/RawSet");
var CheckBox;
((_CheckBox) => {
_CheckBox.selector = "dr-checkbox";
class CheckBoxBase extends import_ComponentBase.ComponentBase {
constructor() {
super(...arguments);
this.hidden = true;
}
}
class Checked extends CheckBoxBase {
constructor() {
super({ onlyParentType: CheckBox2 });
this.name = "checked";
}
}
_CheckBox.Checked = Checked;
class UnChecked extends CheckBoxBase {
constructor() {
super({ onlyParentType: CheckBox2 });
this.name = "unChecked";
}
}
_CheckBox.UnChecked = UnChecked;
class CheckBox2 extends import_ComponentBase.ComponentBase {
constructor() {
super(...arguments);
this.checked = false;
}
change(option, checked) {
checked = checked ?? this.checked;
this.checked = checked;
this.setChildrenHidden(checked);
this.getAttribute("change")?.(checked, option);
}
setChildrenHidden(checked) {
this.getChildren(Checked).forEach((it) => {
it.hidden = !checked;
});
this.getChildren(UnChecked).forEach((it) => {
it.hidden = checked;
});
}
onCreatedThisChild(child, childData) {
super.onCreatedThisChild(child, childData);
this.setChildrenHidden(this.checked);
}
onInitInputElement(element) {
this.inputElement = element;
this.inputElement.checked = !!this.getAttribute("checked");
this.change({ type: "initialize" }, !!this.getAttribute("checked"));
}
onChangeAttrRender(name, val, other) {
super.onChangeAttrRender(name, val, other);
if (this.inputElement && this.getAttribute("checked") !== this.checked) {
this.inputElement.checked = !!this.getAttribute("checked");
this.change({ type: "attributeChange" }, !!this.getAttribute("checked"));
}
}
}
_CheckBox.CheckBox = CheckBox2;
})(CheckBox || (CheckBox = {}));
var CheckBox_default = {
checkBoxChecked: (config) => {
return import_RawSet.RawSet.createComponentTargetElement({
name: `${CheckBox.selector}-checked`,
template: '<div dr-if="!@this@.hidden" dr-option-strip="true">#innerHTML#</div>',
objFactory: (e, o, r2, counstructorParam) => {
return import_DomRender.DomRender.run({ rootObject: new CheckBox.Checked(), config });
}
});
},
checkBoxUnchecked: (config) => {
return import_RawSet.RawSet.createComponentTargetElement({
name: `${CheckBox.selector}-unchecked`,
template: '<div dr-if="!@this@.hidden" dr-option-strip="true" >#innerHTML#</div>',
objFactory: (e, o, r2, counstructorParam) => {
return import_DomRender.DomRender.run({ rootObject: new CheckBox.UnChecked(), config });
}
});
},
checkBox: (config) => {
return import_RawSet.RawSet.createComponentTargetElement({
name: `${CheckBox.selector}`,
template: `<label class="\${@this@.getAttribute('class')}$">
<input
name="\${@this@.getAttribute('name')}$"
dr-on-init="@this@.onInitInputElement($element)"
dr-event-change="@this@.change({type: 'event'},$element.checked);"
type="checkbox" hidden="hidden"/>
#innerHTML#
</label>`,
objFactory: (e, o, r2, counstructorParam) => {
return import_DomRender.DomRender.run({ rootObject: new CheckBox.CheckBox(...counstructorParam), config });
}
});
}
};
//# sourceMappingURL=CheckBox.js.map