sparnatural
Version:
Visual client-side SPARQL query builder and knowledge graph exploration tool
71 lines • 3.18 kB
JavaScript
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _HTMLComponent_instances, _HTMLComponent_attachComponentHtml, _HTMLComponent_initHtml;
import BaseClassFactory from "./baseClassFactory/BaseClassFactory";
export class HTMLComponent {
constructor(baseCssClass, ParentComponent, widgetHtml) {
_HTMLComponent_instances.add(this);
// TODO this is only temporarly. Some components (ActionWhere) don't need to be attached on there parentcomponent but somewhere else
this.htmlParent = null;
this.baseCssClass = baseCssClass;
this.parentComponent = ParentComponent;
// create the HTML element
this.html = HTMLComponent.BaseClassFactory.getBaseClass(this.baseCssClass);
this.widgetHtml = widgetHtml;
}
render() {
if (this.html != null) {
// TODO: Probably useless? it's always going to be null if super.render() called in the begining of render()
this.html.empty();
this.html.remove();
}
__classPrivateFieldGet(this, _HTMLComponent_instances, "m", _HTMLComponent_initHtml).call(this);
__classPrivateFieldGet(this, _HTMLComponent_instances, "m", _HTMLComponent_attachComponentHtml).call(this);
return this;
}
destroy() {
this.html?.remove();
}
/**
* @returns moves up the component hierarchy and returns the one that does not have a parent component
*/
getRootComponent() {
if (this.parentComponent == null) {
return this;
}
else {
return this.parentComponent.getRootComponent();
}
}
/**
* Utility function to switch css class of an element from oldState to newState.
*/
static switchState(el, oldState, newState) {
el.classList.remove(oldState);
el.classList.add(newState);
}
;
}
_HTMLComponent_instances = new WeakSet(), _HTMLComponent_attachComponentHtml = function _HTMLComponent_attachComponentHtml() {
// sometimes components don't need to be rendered under their parentcomponent but under htmlParent... like ActionWhere
if (this.htmlParent) {
this.htmlParent.append(this.html);
}
else {
$(this.html).appendTo(this.parentComponent.html);
}
}, _HTMLComponent_initHtml = function _HTMLComponent_initHtml() {
if (this.widgetHtml != null) {
// remove existing html
this.html = HTMLComponent.BaseClassFactory.getBaseClass(this.baseCssClass);
this.html.append(this.widgetHtml);
}
else {
this.html = HTMLComponent.BaseClassFactory.getBaseClass(this.baseCssClass);
}
};
HTMLComponent.BaseClassFactory = new BaseClassFactory();
//# sourceMappingURL=HtmlComponent.js.map