UNPKG

geostyler

Version:
170 lines (169 loc) 5.22 kB
import { jsxs as F, jsx as c } from "react/jsx-runtime"; import S from "lodash-es/get.js"; import T from "lodash-es/cloneDeep.js"; import w from "lodash-es/isEmpty.js"; import R from "lodash-es/isString.js"; import { AttributeCombo as W } from "../AttributeCombo/AttributeCombo.js"; import { OperatorCombo as X } from "../OperatorCombo/OperatorCombo.js"; import { TextFilterField as Y } from "../TextFilterField/TextFilterField.js"; import { NumberFilterField as Z } from "../NumberFilterField/NumberFilterField.js"; import { BoolFilterField as ee } from "../BoolFilterField/BoolFilterField.js"; import { useGeoStylerData as te, useGeoStylerComposition as oe } from "../../../context/GeoStylerContext/GeoStylerContext.js"; /* empty css */ const re = (p, i, f) => { let a = !0, s = ""; if (S(i, `schema.properties[${f}].type`) === "number") { const t = S(i, `schema.properties[${f}].minimum`), d = S(i, `schema.properties[${f}].maximum`); !isNaN(t) && !isNaN(d) && (typeof p != "number" ? (a = !1, s = "Please enter a number") : p < t ? (a = !1, s = "Minimum Value is " + t) : p > d && (a = !1, s = "Maximum Value is " + d)); } return { isValid: a, errorMsg: s }; }, ie = { // eslint-disable-next-line id-blacklist string: ["==", "*=", "!="], // eslint-disable-next-line id-blacklist number: ["==", "!=", "<", "<=", ">", ">=", "<=x<="], integer: ["==", "!=", "<", "<=", ">", ">=", "<=x<="], // eslint-disable-next-line id-blacklist boolean: ["==", "!="], // eslint-disable-next-line id-blacklist any: void 0, object: void 0, array: void 0, null: void 0 }, ge = (p) => { var _, j; const i = te(), f = oe("ComparisonFilter"), a = { ...p, ...f }, { attributeNameFilter: s = () => !0, attributeNameMappingFunction: V = (e) => e, filter: t = ["==", "", null], hideAttributeType: d = !1, microUI: l = !1, onFilterChange: n, operatorLabel: D, operatorNameMappingFunction: O = (e) => e, operatorPlaceholderString: $, operatorTitleMappingFunction: G = (e) => e, operatorValidationHelpString: P, showOperatorTitles: E = !0, validators: C = { attribute: (e) => !w(e), operator: (e) => !w(e), value: re } } = a, H = (e) => { const o = T(t); o[1] = e, n && n(o); }, L = (e) => { const o = T(t); o[0] = e, e !== "<=x<=" && o.length > 3 && o.splice(3, 1), e === "<=x<=" && !o[3] && (o[3] = 0), n && n(o); }, y = (e, o = 2) => { const r = T(t); r[o] = e, n && n(r); }, m = R(t[1]) ? t[1] : void 0, v = m ? (j = (_ = i == null ? void 0 : i.schema) == null ? void 0 : _.properties[m]) == null ? void 0 : j.type : void 0, M = t[0], U = t[2], k = C.value(U, i, m), q = v ? ie[v] : void 0, A = M === "<=x<=", z = v === "number", B = v === "boolean", I = !A && !z && !B, x = t && Array.isArray(t), b = { attribute: x && C.attribute(m) ? "success" : "error", operator: x && C.operator(M) ? "success" : "error", value: x && k.isValid ? "success" : "error" }; function g(e = 1) { const o = l ? "small" : void 0; let r; return t && (r = t[e]), /* @__PURE__ */ c( W, { size: o, value: r, onAttributeChange: H, attributeNameFilter: s, attributeNameMappingFunction: V, validateStatus: b.attribute, hideAttributeType: d } ); } function N(e = 2) { const o = l ? "small" : void 0; let r; return t && (r = t[e]), /* @__PURE__ */ c( Z, { size: o, value: r, onValueChange: (Q) => y(Q, e), validateStatus: b.value, selectedAttribute: m } ); } function J(e = 2) { const o = l ? "small" : void 0; let r; return t && (r = t[e]), /* @__PURE__ */ c( Y, { size: o, value: r, selectedAttribute: m, onValueChange: y, validateStatus: b.value } ); } function h(e = 0) { const o = l ? "small" : void 0; let r; return t && (r = t[e]), /* @__PURE__ */ c( X, { size: o, value: r, onOperatorChange: L, operators: q, operatorNameMappingFunction: O, placeholder: $, label: D, validateStatus: b.operator, help: P, operatorTitleMappingFunction: G, showTitles: E } ); } function K(e = 2) { const o = l ? "small" : void 0; let r; return t && (r = t[e]), /* @__PURE__ */ c( ee, { size: o, value: r, onValueChange: y } ); } let u = "gs-comparison-filter-ui"; return l && (u += " micro"), A ? /* @__PURE__ */ F("div", { className: u, children: [ g(), N(2), h(), N(3) ] }) : z ? /* @__PURE__ */ F("div", { className: u, children: [ g(), h(), N() ] }) : B ? /* @__PURE__ */ F("div", { className: u, children: [ g(), h(), K() ] }) : I ? /* @__PURE__ */ F("div", { className: u, children: [ g(), h(), J() ] }) : /* @__PURE__ */ c("div", { className: u, children: "Could not create ComparisonFilter." }); }; export { ge as ComparisonFilter, re as ComparisonFilterDefaultValidator };