@dooboostore/dom-render
Version:
html view template engine
110 lines • 4.21 kB
JavaScript
import { ComponentBase } from '../ComponentBase';
import { DomRender } from '../../DomRender';
import { RawSet } from '../../rawsets/RawSet';
export var Choose;
(function (Choose_1) {
Choose_1.selector = 'dr-choose';
class ChildOtherWiseBase extends ComponentBase {
constructor() {
super(...arguments);
this.hidden = true;
}
}
class ChildBase extends ChildOtherWiseBase {
}
// @Component({
// template: '<div dr-if="!@this@.hidden" dr-strip="true" >#innerHTML#</div>',
// selector: `${selector}.When`
// })
class When extends ChildBase {
constructor() {
super({ onlyParentType: (Choose) });
}
}
Choose_1.When = When;
// @Component({
// template: '<div dr-if="!@this@.hidden" dr-strip="true" >#innerHTML#</div>',
// selector: `${selector}.OtherWise`
// })
class OtherWise extends ChildBase {
constructor() {
super({ onlyParentType: (Choose) });
}
}
Choose_1.OtherWise = OtherWise;
// @Component({
// template: '#innerHTML#',
// selector: `${selector}`
// })
class Choose extends ComponentBase {
onCreatedThisChild(child, data) {
super.onCreatedThisChild(child, data);
this.setChange(child);
}
onChangeAttrRender(name, value, other) {
super.onChangeAttrRender(name, value, other);
// console.log('-----------changer Choose', name, value);
// this.getChildren(Pending).forEach(it => {
// console.log('------------asdasd', it, it.attribute?.defaultView)
// })
if (this.equalsAttributeName(name, 'data')) {
this.choose = undefined;
const children = this.getChildren([When, OtherWise]).sort((a, b) => (a instanceof OtherWise ? 1 : 0) - (b instanceof OtherWise ? 1 : 0));
children.forEach(it => this.setChange(it));
}
}
setChange(child) {
var _a;
child.data = this.getAttribute('data');
// when.hidden = true;
if (!this.choose && child instanceof When && ((_a = child.getAttribute('test')) === null || _a === void 0 ? void 0 : _a(this.getAttribute('data')))) {
// console.log('------------', child.attribute?.test?.(this.attribute?.data))
this.choose = child;
if (child.hidden) {
child.hidden = false;
}
// console.log('--------', when)
}
else if (this.choose !== child) {
child.hidden = true;
}
if (!this.choose && child instanceof OtherWise) {
this.choose = child;
if (child.hidden) {
child.hidden = false;
}
}
}
}
Choose_1.Choose = Choose;
})(Choose || (Choose = {}));
export default {
chooseWhen: (config) => {
return RawSet.createComponentTargetElement({
name: `${Choose.selector}-when`,
template: '<div dr-if="!@this@.hidden" dr-option-strip="true" >#innerHTML#</div>',
objFactory: (e, o, r2, counstructorParam) => {
return DomRender.run({ rootObject: new Choose.When(), config: config });
}
});
},
chooseOtherWise: (config) => {
return RawSet.createComponentTargetElement({
name: `${Choose.selector}-other-wise`,
template: '<div dr-if="!@this@.hidden" dr-option-strip="true" >#innerHTML#</div>',
objFactory: (e, o, r2, counstructorParam) => {
return DomRender.run({ rootObject: new Choose.OtherWise(), config: config });
}
});
},
choose: (config) => {
return RawSet.createComponentTargetElement({
name: `${Choose.selector}`,
template: '#innerHTML#',
objFactory: (e, o, r2, counstructorParam) => {
return DomRender.run({ rootObject: new Choose.Choose(...counstructorParam), config: config });
}
});
},
};
//# sourceMappingURL=Choose.js.map