UNPKG

sparnatural

Version:

Visual client-side SPARQL query builder and knowledge graph exploration tool

144 lines 6.52 kB
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 _EndClassGroup_instances, _EndClassGroup_addEventListener, _EndClassGroup_createSparqlVar, _EndClassGroup_syncDefaultLblVar, _EndClassGroup_valueWasSelected, _EndClassGroup_renderUnselectBtn; import ClassTypeId from "./ClassTypeId"; import tippy from "tippy.js"; import { TOOLTIP_CONFIG } from "../../../../../../sparnatural/settings/defaultSettings"; import { HTMLComponent } from "../../../../HtmlComponent"; import EditComponents from "../edit-components/EditComponents"; /** * The "range" select, encapsulating a ClassTypeId **/ class EndClassGroup extends HTMLComponent { constructor(ParentCriteriaGroup, specProvider) { super("EndClassGroup", ParentCriteriaGroup, null); _EndClassGroup_instances.add(this); this.endClassVal = { type: null, variable: null, }; // 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.ParentCriteriaGroup = this.parentComponent; // this.endClassWidgetGroup = new EndClassWidgetGroup(this, this.specProvider); } render() { super.render(); this.variableSelector = null; __classPrivateFieldGet(this, _EndClassGroup_instances, "m", _EndClassGroup_addEventListener).call(this); return this; } // triggered when the subject/domain is selected onStartClassGroupSelected(startClassVal) { this.startClassVal = startClassVal; // render the inputComponent for a user to select an Object this.inputSelector = new ClassTypeId(this, this.specProvider, '', startClassVal); this.inputSelector.render(); } onObjectPropertyGroupSelected(objectPropVal) { this.objectPropVal = objectPropVal; if (!this.editComponents) { // this is where the widgets will be determined and rendered this.editComponents = new EditComponents(this, this.startClassVal, objectPropVal, this.endClassVal, this.specProvider).render(); } } // renders the "eye" btn renderSelectViewVar() { this.inputSelector.selectViewVariableBtn.render(); } getVarName() { return this.endClassVal.variable; } getDefaultLblVar() { return this.defaultLblVar?.variable; } setVarName(name) { this.endClassVal.variable = name; __classPrivateFieldGet(this, _EndClassGroup_instances, "m", _EndClassGroup_syncDefaultLblVar).call(this); } getTypeSelected() { return this.endClassVal.type; } /** * @returns true if the 'eye' icon on this arrow is selected */ isVarSelected() { return this.inputSelector?.selectViewVariableBtn?.selected; } /** * @returns the widgetComponent inside this EndClassGroup, to examine its characteristics * (e.g. determine if single or multiple values) */ getWidgetComponent() { return this.editComponents.widgetWrapper.widgetComponent; } } _EndClassGroup_instances = new WeakSet(), _EndClassGroup_addEventListener = function _EndClassGroup_addEventListener() { this.html[0].addEventListener("classTypeValueSelected", (e) => { if (e.detail === "" || !e.detail) throw Error('No value received on "classTypeValueSelected"'); e.stopImmediatePropagation(); __classPrivateFieldGet(this, _EndClassGroup_instances, "m", _EndClassGroup_createSparqlVar).call(this, e.detail); __classPrivateFieldGet(this, _EndClassGroup_instances, "m", _EndClassGroup_valueWasSelected).call(this); }); this.html[0].addEventListener("onSelectViewVar", (e) => { if (e.detail.selected) { e.detail.selected ? this.html.addClass("VariableSelected") : this.html.removeClass("VariableSelected"); } }); }, _EndClassGroup_createSparqlVar = function _EndClassGroup_createSparqlVar(type) { this.endClassVal.type = type; this.html[0].dispatchEvent(new CustomEvent("getSparqlVar", { bubbles: true, detail: { type: type, callback: (variable) => { //callback this.endClassVal.variable = variable; } } })); }, _EndClassGroup_syncDefaultLblVar = function _EndClassGroup_syncDefaultLblVar() { let type = this.endClassVal.type; let name = this.endClassVal.variable; const lbl = this.specProvider.getEntity(type).getDefaultLabelProperty(); if (lbl) { this.defaultLblVar.type = lbl; this.defaultLblVar.variable = `${name}_label`; } }, _EndClassGroup_valueWasSelected = function _EndClassGroup_valueWasSelected() { __classPrivateFieldGet(this, _EndClassGroup_instances, "m", _EndClassGroup_renderUnselectBtn).call(this); // trigger the event that will call the ObjectPropertyGroup this.html[0].dispatchEvent(new CustomEvent("EndClassGroupSelected", { bubbles: true, detail: this.endClassVal, })); let entity = this.specProvider.getEntity(this.endClassVal.type); var desc = entity.getTooltip(); if (desc) { $(this.html).find(".ClassTypeId").attr("data-tippy-content", desc.replace(/"/g, '"')); var tippySettings = Object.assign({}, TOOLTIP_CONFIG); tippySettings.placement = "top-start"; tippy(".EndClassGroup .ClassTypeId[data-tippy-content]", tippySettings); } else { $(this.ParentCriteriaGroup.endClassGroup.html).removeAttr("data-tippy-content"); } // if entity is a blank node, deactivate eye selector if (entity.isBlankNodeEntity()) { this.inputSelector.selectViewVariableBtn.setAlwaysDisabled(true); } }, _EndClassGroup_renderUnselectBtn = function _EndClassGroup_renderUnselectBtn() { this.inputSelector.renderUnselectBtn(); }; export default EndClassGroup; //# sourceMappingURL=EndClassGroup.js.map