UNPKG

geostyler

Version:
169 lines (168 loc) 5.19 kB
import { jsxs as F, jsx as u } 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, c) => { let a = !0, s = ""; if (S(i, `schema.properties[${c}].type`) === "number") { const t = S(i, `schema.properties[${c}].minimum`), f = S(i, `schema.properties[${c}].maximum`); !isNaN(t) && !isNaN(f) && (typeof p != "number" ? (a = !1, s = "Please enter a number") : p < t ? (a = !1, s = "Minimum Value is " + t) : p > f && (a = !1, s = "Maximum Value is " + f)); } 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(), c = oe("ComparisonFilter"), a = { ...p, ...c }, { attributeNameFilter: s = () => !0, attributeNameMappingFunction: V = (e) => e, filter: t = ["==", "", null], hideAttributeType: f = !1, microUI: n = !1, onFilterChange: l, 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, l && l(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), l && l(o); }, y = (e, o = 2) => { const r = T(t); r[o] = e, l && l(r); }, d = R(t[1]) ? t[1] : void 0, v = d ? (j = (_ = i == null ? void 0 : i.schema) == null ? void 0 : _.properties[d]) == null ? void 0 : j.type : void 0, M = t[0], U = t[2], k = C.value(U, i, d), q = v ? ie[v] : void 0, z = M === "<=x<=", A = v === "number", B = v === "boolean", I = !z && !A && !B, x = t && Array.isArray(t), b = { attribute: x && C.attribute(d) ? "success" : "error", operator: x && C.operator(M) ? "success" : "error", value: x && k.isValid ? "success" : "error" }; function g(e = 1) { const o = n ? "small" : void 0; let r; return t && (r = t[e]), /* @__PURE__ */ u( W, { size: o, value: r, onAttributeChange: H, attributeNameFilter: s, attributeNameMappingFunction: V, validateStatus: b.attribute, hideAttributeType: f } ); } function N(e = 2) { const o = n ? "small" : void 0; let r; return t && (r = t[e]), /* @__PURE__ */ u( Z, { size: o, value: r, onValueChange: (Q) => y(Q, e), validateStatus: b.value } ); } function J(e = 2) { const o = n ? "small" : void 0; let r; return t && (r = t[e]), /* @__PURE__ */ u( Y, { size: o, value: r, selectedAttribute: d, onValueChange: y, validateStatus: b.value } ); } function h(e = 0) { const o = n ? "small" : void 0; let r; return t && (r = t[e]), /* @__PURE__ */ u( 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 = n ? "small" : void 0; let r; return t && (r = t[e]), /* @__PURE__ */ u( ee, { size: o, value: r, onValueChange: y } ); } let m = "gs-comparison-filter-ui"; return n && (m += " micro"), z ? /* @__PURE__ */ F("div", { className: m, children: [ g(), N(2), h(), N(3) ] }) : A ? /* @__PURE__ */ F("div", { className: m, children: [ g(), h(), N() ] }) : B ? /* @__PURE__ */ F("div", { className: m, children: [ g(), h(), K() ] }) : I ? /* @__PURE__ */ F("div", { className: m, children: [ g(), h(), J() ] }) : /* @__PURE__ */ u("div", { className: m, children: "Could not create ComparisonFilter." }); }; export { ge as ComparisonFilter, re as ComparisonFilterDefaultValidator };