UNPKG

sparnatural

Version:

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

142 lines 8.16 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 _SparnaturalComponent_instances, _SparnaturalComponent_initCatalog, _SparnaturalComponent_initLang; import { getSettings } from "../../sparnatural/settings/defaultSettings"; import BgWrapper from "./builder-section/BgWrapper"; import SubmitSection from "./submit-section/SubmitSection"; import { SparnaturalSpecificationFactory } from "../spec-providers/SparnaturalSpecificationFactory"; import ActionStore from "../statehandling/ActionStore"; import VariableSection from "./variables-section/VariableSelection"; import { HTMLComponent } from "./HtmlComponent"; import { SparnaturalElement } from "../../SparnaturalElement"; import { I18n } from "../settings/I18n"; import { Catalog, Model } from "rdf-shacl-commons"; class SparnaturalComponent extends HTMLComponent { constructor() { //Sparnatural: Does not have a ParentComponent! super("Sparnatural", null, null); _SparnaturalComponent_instances.add(this); // filter that is applied to optional/not exists green arrows, based on its ID this.filter = $('<svg data-name="Calque 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 0 0" style="width:0;height:0;display:block"><defs><filter style="color-interpolation-filters:sRGB;" inkscape:label="Drop Shadow" id="filter19278" x="-0.15483875" y="-0.11428573" width="1.3096775" height="1.2714286"><feFlood flood-opacity="0.811765" flood-color="rgb(120,120,120)" result="flood" id="feFlood19268" /><feComposite in="flood" in2="SourceGraphic" operator="out" result="composite1" id="feComposite19270" /><feGaussianBlur in="composite1" stdDeviation="2" result="blur" id="feGaussianBlur19272" /><feOffset dx="3.60822e-16" dy="1.8" result="offset" id="feOffset19274" /><feComposite in="offset" in2="SourceGraphic" operator="atop" result="composite2" id="feComposite19276" /></filter></defs></svg>'); // method is exposed from the HTMLElement this.enablePlayBtn = () => { this.submitSection.playBtn.removeLoading(); }; // method is exposed from the HTMLElement this.disablePlayBtn = () => { this.submitSection.playBtn.disable(); }; } render() { __classPrivateFieldGet(this, _SparnaturalComponent_instances, "m", _SparnaturalComponent_initLang).call(this); let afterSpecificationLoaded = (sp) => { this.specProvider = sp; this.actionStore = new ActionStore(this, this.specProvider); this.BgWrapper = new BgWrapper(this, this.specProvider).render(); // display the submit button only if a callback was provided if (getSettings().submitButton) { this.submitSection = new SubmitSection(this).render(); } this.variableSection = new VariableSection(this, this.specProvider).render(); //BGWrapper must be rendered first this.html[0].dispatchEvent(new CustomEvent("redrawBackgroundAndLinks", { bubbles: true })); this.html.append(this.filter); console.log("Found languages in configuration : " + this.specProvider.getLanguages()); this.html[0].dispatchEvent(new CustomEvent(SparnaturalElement.EVENT_INIT, { bubbles: true, detail: { sparnatural: this, config: this.specProvider }, })); }; // chain catalog loading and spec loading let afterCatalogLoaded = (catalog) => { this.catalog = catalog; this.initSpecificationProvider(afterSpecificationLoaded); }; __classPrivateFieldGet(this, _SparnaturalComponent_instances, "m", _SparnaturalComponent_initCatalog).call(this, afterCatalogLoaded); return this; } initSpecificationProvider(callback) { let settings = getSettings(); let specProviderFactory = new SparnaturalSpecificationFactory(); // load only the statistics of the selected endpoints specProviderFactory.build(settings.src, settings.language, this.catalog ? this.catalog.extractSubCatalog(settings.endpoints) : undefined, (sp) => { // call the call back when done callback(sp); }); } setQuiet(quiet) { this.actionStore.quiet = quiet; } isEmpty() { return (this.BgWrapper.componentsList.rootGroupWrapper.criteriaGroup .startClassGroup.startClassVal?.type == null); } getMaxVariableIndexByTypes() { let maxVariableIndexPerType = new Map(); this.BgWrapper.componentsList.rootGroupWrapper.traversePostOrder((grpWrapper) => { // generic counting function to extract the index of a variable and update the max index for its type let processTypeVar = (type, variable) => { if (type && variable) { // if a variable does not match this pattern, it means it will not be counted // which is OK, as there is no risk of collision with the generated variables that always have an index if (variable.match(/_(\d+)$/)) { let index = parseInt(variable.match(/_(\d+)$/)[1]); if (maxVariableIndexPerType.has(type) && maxVariableIndexPerType.get(type) < index) { maxVariableIndexPerType.set(type, index); } else if (!maxVariableIndexPerType.has(type)) { maxVariableIndexPerType.set(type, index); } } // also check the base variable without index, in case there is only one variable of this type which does not have an index let baseVar = Model.getSparqlVariableNameFromUri(type); if (variable === baseVar && !maxVariableIndexPerType.has(type)) { maxVariableIndexPerType.set(type, 1); } } }; // count the variable only if it is the very first if (grpWrapper.depth === 0 && grpWrapper.order === 0) { processTypeVar(grpWrapper.criteriaGroup.startClassGroup?.startClassVal.type, grpWrapper.criteriaGroup.startClassGroup?.startClassVal.variable); } // always count the end class group processTypeVar(grpWrapper.criteriaGroup.endClassGroup?.endClassVal.type, grpWrapper.criteriaGroup.endClassGroup?.endClassVal.variable); // always count the object property group processTypeVar(grpWrapper.criteriaGroup.objectPropertyGroup?.objectPropVal.type, grpWrapper.criteriaGroup.objectPropertyGroup?.objectPropVal.variable); }); return maxVariableIndexPerType; } } _SparnaturalComponent_instances = new WeakSet(), _SparnaturalComponent_initCatalog = function _SparnaturalComponent_initCatalog(callback) { let settings = getSettings(); let me = this; if (settings.catalog) { $.getJSON(settings.catalog, function (data) { callback(new Catalog(data)); }).fail(function (response) { console.error("Sparnatural - unable to load catalog file : " + settings.catalog); callback(undefined); }); } else { // no catalog provided callback(undefined); } }, _SparnaturalComponent_initLang = function _SparnaturalComponent_initLang() { if (getSettings().language === "fr") { I18n.init("fr"); } else { I18n.init("en"); } }; export default SparnaturalComponent; //# sourceMappingURL=SparnaturalComponent.js.map