sparnatural
Version:
Visual client-side SPARQL query builder and knowledge graph exploration tool
119 lines • 5.45 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 _StartClassGroup_instances, _StartClassGroup_addEventListener, _StartClassGroup_createSparqlVar, _StartClassGroup_syncDefaultLblVar, _StartClassGroup_valueWasSelected;
import ClassTypeId from "./ClassTypeId";
import { HTMLComponent } from "../../../../HtmlComponent";
import { TippyInfo } from "../../../../buttons/TippyInfo";
import { TOOLTIP_CONFIG } from "../../../../../settings/defaultSettings";
/**
* Selection of the start class in a criteria/line
**/
class StartClassGroup extends HTMLComponent {
constructor(ParentCriteriaGroup, specProvider, temporaryLabel, startClassVal, renderEyeBtn) {
super("StartClassGroup", ParentCriteriaGroup, null);
_StartClassGroup_instances.add(this);
this.renderEyeBtn = false;
// shadow variable for http://data.sparna.fr/ontologies/sparnatural-config-core/index-en.html#defaultLabelProperty
this.defaultLblVar = {
type: null,
variable: null
};
this.specProvider = specProvider;
this.temporaryLabel = temporaryLabel;
this.inputSelector = new ClassTypeId(this, this.specProvider, this.temporaryLabel, startClassVal);
this.parentCriteriaGroup = this.parentComponent;
this.startClassVal = startClassVal
? startClassVal
: {
type: null,
variable: null,
};
this.renderEyeBtn = renderEyeBtn;
}
render() {
super.render();
this.inputSelector.render();
__classPrivateFieldGet(this, _StartClassGroup_instances, "m", _StartClassGroup_addEventListener).call(this);
return this;
}
/**
* This can be called from the outside when deleting the first row and the second row becomes root
*/
autoSelectEyeBtn() {
this.inputSelector.selectViewVariableBtn.render();
this.inputSelector.selectViewVariableBtn.widgetHtml[0].dispatchEvent(new Event('click'));
}
getVarName() {
return this.startClassVal.variable;
}
setVarName(name) {
this.startClassVal.variable = name;
__classPrivateFieldGet(this, _StartClassGroup_instances, "m", _StartClassGroup_syncDefaultLblVar).call(this);
}
getTypeSelected() {
return this.startClassVal.type;
}
getDefaultLblVar() {
return this.defaultLblVar?.variable;
}
/**
* @returns true if the 'eye' icon on this arrow is selected
*/
isVarSelected() {
return this.inputSelector?.selectViewVariableBtn?.selected;
}
}
_StartClassGroup_instances = new WeakSet(), _StartClassGroup_addEventListener = function _StartClassGroup_addEventListener() {
this.html[0].addEventListener("classTypeValueSelected", (e) => {
if (e.detail === "" || !e.detail)
throw Error('No value received on "classTypeValueSelected"');
e.stopImmediatePropagation();
//only create new SPARQL variable if the startClassVal is not set by the parent component
if (!this.startClassVal.variable) {
__classPrivateFieldGet(this, _StartClassGroup_instances, "m", _StartClassGroup_createSparqlVar).call(this, e.detail);
}
else {
__classPrivateFieldGet(this, _StartClassGroup_instances, "m", _StartClassGroup_syncDefaultLblVar).call(this);
}
// Iff(!) First StartClass of first GrpWrapper: eye btn automatically rendered + selected
if (this.renderEyeBtn)
this.autoSelectEyeBtn();
__classPrivateFieldGet(this, _StartClassGroup_instances, "m", _StartClassGroup_valueWasSelected).call(this);
});
}, _StartClassGroup_createSparqlVar = function _StartClassGroup_createSparqlVar(type) {
this.startClassVal.type = type;
this.html[0].dispatchEvent(new CustomEvent("getSparqlVar", {
bubbles: true,
detail: {
type: type,
callback: (variable) => {
//callback
this.startClassVal.variable = variable;
}
}
}));
}, _StartClassGroup_syncDefaultLblVar = function _StartClassGroup_syncDefaultLblVar() {
let type = this.startClassVal.type;
let name = this.startClassVal.variable;
const lbl = this.specProvider.getEntity(type).getDefaultLabelProperty();
if (lbl) {
this.defaultLblVar.type = lbl;
this.defaultLblVar.variable = `${name}_label`;
}
}, _StartClassGroup_valueWasSelected = function _StartClassGroup_valueWasSelected() {
this.html[0].dispatchEvent(new CustomEvent("StartClassGroupSelected", {
bubbles: true,
detail: this.startClassVal,
}));
var desc = this.specProvider.getEntity(this.startClassVal.type).getTooltip();
if (desc) {
var tippySettings = Object.assign({}, TOOLTIP_CONFIG);
tippySettings.placement = "top-start";
new TippyInfo(this, desc, tippySettings);
}
};
export default StartClassGroup;
//# sourceMappingURL=StartClassGroup.js.map