UNPKG

sparnatural

Version:

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

109 lines 5.84 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 _NumberWidget_instances, _NumberWidget_getMinMaxHtmlAttributes, _NumberWidget_onFormSubmit, _NumberWidget_addValueBtnClicked, _NumberWidget_checkInput, _NumberWidget_getValueLabel; import { DataFactory } from "rdf-data-factory"; import { AbstractWidget, ValueRepetition } from "./AbstractWidget"; import { I18n } from "../../settings/I18n"; import { AddUserInputBtn } from "../buttons/AddUserInputBtn"; import { InfoBtn } from "../buttons/InfoBtn"; import { TOOLTIP_CONFIG } from "../../settings/defaultSettings"; const factory = new DataFactory(); export class NumberWidgetValue { key() { return "" + this.value.min + "-" + this.value.max; } constructor(v) { this.value = v; } } export class NumberWidget extends AbstractWidget { constructor(parentComponent, configuration, startClassVal, objectPropVal, endClassVal) { super("number-widget", parentComponent, null, startClassVal, objectPropVal, endClassVal, ValueRepetition.SINGLE); _NumberWidget_instances.add(this); _NumberWidget_onFormSubmit.set(this, (event) => { let numberWidgetValue = { label: __classPrivateFieldGet(this, _NumberWidget_getValueLabel, "f").call(this, this.minInput.val().toString(), this.maxInput.val().toString()), min: this.minInput.val() != "" ? Number(this.minInput.val().toString()) : undefined, max: this.maxInput.val() != "" ? Number(this.maxInput.val().toString()) : undefined, }; numberWidgetValue = __classPrivateFieldGet(this, _NumberWidget_instances, "m", _NumberWidget_checkInput).call(this, numberWidgetValue); this.triggerRenderWidgetVal(this.parseInput(numberWidgetValue)); // prevent actual form submission event.preventDefault(); // arreter la propagation de l'evenement pour ne pas qu'il remonte jusqu'au parent event.stopPropagation(); }); _NumberWidget_addValueBtnClicked.set(this, () => { this.form[0].requestSubmit(); }); _NumberWidget_getValueLabel.set(this, function (startLabel, stopLabel) { let valueLabel = ""; if (startLabel != "" && stopLabel != "") { valueLabel = I18n.labels.NumberLabelBetween + " " + startLabel + " " + I18n.labels.NumberLabelAnd + " " + stopLabel; } else if (startLabel != "") { valueLabel = I18n.labels.NumberLabelHigherThan + " " + startLabel; } else if (stopLabel != "") { valueLabel = I18n.labels.NumberLabelLowerThan + " " + stopLabel; } return valueLabel; }); this.configuration = configuration; } render() { super.render(); this.form = $("<form />"); this.html.append(this.form); this.form[0].addEventListener("submit", __classPrivateFieldGet(this, _NumberWidget_onFormSubmit, "f")); this.minInput = $(`<input type="number" size="7" id="input-from" ${__classPrivateFieldGet(this, _NumberWidget_instances, "m", _NumberWidget_getMinMaxHtmlAttributes).call(this)} />`); this.form.append(this.minInput); this.form.append(`&nbsp;&nbsp;${I18n.labels.NumberLabelAnd}&nbsp;&nbsp;`); this.maxInput = $(`<input type="number" size="7" id="input-to" ${__classPrivateFieldGet(this, _NumberWidget_instances, "m", _NumberWidget_getMinMaxHtmlAttributes).call(this)} />`); this.form.append(this.maxInput); // set a tooltip on the info circle var tippySettings = Object.assign({}, TOOLTIP_CONFIG); tippySettings.placement = "left"; tippySettings.trigger = "click"; tippySettings.offset = [40, -20]; tippySettings.delay = [0, 0]; let tooltip = __classPrivateFieldGet(this, _NumberWidget_getValueLabel, "f").call(this, this.configuration.min, this.configuration.max); this.infoBtn = new InfoBtn(this, tooltip, tippySettings).render(); this.addValueBtn = new AddUserInputBtn(this, I18n.labels.ButtonAdd, __classPrivateFieldGet(this, _NumberWidget_addValueBtnClicked, "f")).render(); return this; } parseInput(input) { return new NumberWidgetValue(input); } } _NumberWidget_onFormSubmit = new WeakMap(), _NumberWidget_addValueBtnClicked = new WeakMap(), _NumberWidget_getValueLabel = new WeakMap(), _NumberWidget_instances = new WeakSet(), _NumberWidget_getMinMaxHtmlAttributes = function _NumberWidget_getMinMaxHtmlAttributes() { let result = ""; if (this.configuration.min) { result += ` min="${this.configuration.min}"`; } if (this.configuration.max) { result += ` max="${this.configuration.max}"`; } return result; }, _NumberWidget_checkInput = function _NumberWidget_checkInput(input) { if (input.min && input.max && input.min > input.max) throw Error("lower bound is bigger than upper bound!"); return input; }; // The default implementation of TreeConfiguration NumberWidget.defaultConfiguration = {}; //# sourceMappingURL=NumberWidget.js.map