sparnatural
Version:
Visual client-side SPARQL query builder and knowledge graph exploration tool
79 lines • 4.76 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 _SelectViewVariableBtn_instances, _SelectViewVariableBtn_addClickListener, _SelectViewVariableBtn_removeClickListener;
import { HTMLComponent } from "../HtmlComponent";
/*
Switch Component having a binary state:
selected: Switching between the states with onClick
*/
export class SelectViewVariableBtn extends HTMLComponent {
constructor(ParentComponent, callBack) {
let widgetHtml = $("<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"feather feather-eye-off\"><path d=\"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24\"></path><line x1=\"1\" y1=\"1\" x2=\"23\" y2=\"23\"></line></svg>" /* UiuxConfig.ICON_NOT_SELECTED_VARIABLE */); //default
super("selectViewVariableBtn", ParentComponent, widgetHtml);
_SelectViewVariableBtn_instances.add(this);
this.selected = false;
this.alwaysDisabled = false;
this.callBack = callBack;
}
render() {
if (this.selected) {
this.widgetHtml = $("<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"feather feather-eye\"><path d=\"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z\"></path><circle cx=\"12\" cy=\"12\" r=\"3\"></circle></svg>" /* UiuxConfig.ICON_SELECTED_VARIABLE */);
}
else {
this.widgetHtml = $("<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"feather feather-eye-off\"><path d=\"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24\"></path><line x1=\"1\" y1=\"1\" x2=\"23\" y2=\"23\"></line></svg>" /* UiuxConfig.ICON_NOT_SELECTED_VARIABLE */);
}
super.render();
if (!this.alwaysDisabled) {
__classPrivateFieldGet(this, _SelectViewVariableBtn_instances, "m", _SelectViewVariableBtn_addClickListener).call(this);
}
else {
this.disable();
}
return this;
}
setAlwaysDisabled(ad) {
this.alwaysDisabled = ad;
if (this.alwaysDisabled) {
this.disable();
}
else {
this.enable();
}
}
disable() {
this.html.addClass("disabled");
__classPrivateFieldGet(this, _SelectViewVariableBtn_instances, "m", _SelectViewVariableBtn_removeClickListener).call(this);
}
enable() {
// can never be reenabled if always disabled
if (this.alwaysDisabled)
return;
// make sure we don't enable twise
if (this.html.hasClass("disabled")) {
this.html.removeClass("disabled");
__classPrivateFieldGet(this, _SelectViewVariableBtn_instances, "m", _SelectViewVariableBtn_addClickListener).call(this);
}
}
}
_SelectViewVariableBtn_instances = new WeakSet(), _SelectViewVariableBtn_addClickListener = function _SelectViewVariableBtn_addClickListener() {
this.widgetHtml.on("click", (e) => {
// one Variable always(!) needs to be selected
let lastSelectedVar = false;
this.widgetHtml[0].dispatchEvent(new CustomEvent("getSelectedVarLength", { bubbles: true, detail: (length) => {
// add here Toast notification
if (length < 2 && this.selected === true)
lastSelectedVar = true;
} }));
if (lastSelectedVar)
return;
this.selected = this.selected ? false : true;
this.render();
this.callBack(this.selected);
});
}, _SelectViewVariableBtn_removeClickListener = function _SelectViewVariableBtn_removeClickListener() {
this.widgetHtml.off("click");
};
//# sourceMappingURL=SelectViewVariableBtn.js.map