@dooboostore/dom-render
Version:
html view template engine
122 lines (121 loc) • 4.27 kB
JavaScript
var __decorate = function(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = function(k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { attribute, ComponentBase } from "../ComponentBase.js";
import { DomRender } from "../../DomRender.js";
import { RawSet } from "../../rawsets/RawSet.js";
var A;
(function(A_1) {
A_1.selector = "dr-a";
class A2 extends ComponentBase {
constructor() {
super(...arguments);
this.href = null;
this.target = null;
this.style = null;
this.classAttr = null;
this.drClass = null;
this.click = null;
this.replace = false;
this.scrollToTop = true;
}
onClick(event) {
if (this.click) {
const attributes = {
href: this.href,
target: this.target,
style: this.style,
class: this.classAttr,
replace: this.replace,
scrollToTop: this.scrollToTop
};
this.click({ event, attributes });
}
if (event.defaultPrevented) {
return;
}
if (this.target !== "_blank" && this.href) {
event.preventDefault();
this.domRenderConfig?.router?.go({ path: this.href, replace: this.replace, scrollToTop: this.scrollToTop });
}
}
onChangeAttrRender(name, value, other) {
super.onChangeAttrRender(name, value, other);
if (this.element && name.startsWith("attribute-")) {
this.element.setAttribute(name, value);
}
}
onAElementInit($element) {
this.element = $element;
this.getAttribute("onInit")?.($element);
this.getAttributeNames().filter((it) => it.startsWith("attribute-")).forEach((it) => {
const attrName = it.replace(/^attribute-/, "");
const attrValue = this.getAttribute(it);
this.element.setAttribute(attrName, attrValue);
});
}
}
__decorate([
attribute({ converter: (v) => v || null }),
__metadata("design:type", String)
], A2.prototype, "href", void 0);
__decorate([
attribute({ converter: (v) => v || null }),
__metadata("design:type", String)
], A2.prototype, "target", void 0);
__decorate([
attribute({ converter: (v) => v || null }),
__metadata("design:type", String)
], A2.prototype, "style", void 0);
__decorate([
attribute({ name: "class", converter: (v) => v || null }),
__metadata("design:type", String)
], A2.prototype, "classAttr", void 0);
__decorate([
attribute({ name: "dr-class", converter: (v) => v || null }),
__metadata("design:type", String)
], A2.prototype, "drClass", void 0);
__decorate([
attribute(),
__metadata("design:type", Function)
], A2.prototype, "click", void 0);
__decorate([
attribute({ converter: (v) => v !== null && String(v) !== "false" }),
__metadata("design:type", Object)
], A2.prototype, "replace", void 0);
__decorate([
attribute({ converter: (v) => v !== null && String(v) !== "false" }),
__metadata("design:type", Object)
], A2.prototype, "scrollToTop", void 0);
A_1.A = A2;
})(A || (A = {}));
var A_default = {
a: (config) => {
return RawSet.createComponentTargetElement({
name: A.selector,
template: `<a
href="\${@this@.href}$"
target="\${@this@.target}$"
style="\${@this@.style}$"
class="\${@this@.classAttr}$"
dr-event-click="@this@.onClick($event)"
dr-class="\${@this@.drClass}$"
dr-on-init="@this@.onAElementInit($element)"
>#innerHTML#</a>`,
objFactory: (e, o, r2, constructorParam) => {
return DomRender.run({ rootObject: new A.A(...constructorParam), config });
}
});
}
};
export {
A,
A_default as default
};
//# sourceMappingURL=A.js.map