UNPKG

geostyler

Version:
174 lines (173 loc) 5.34 kB
import { jsx as a, jsxs as h } from "react/jsx-runtime"; import { Tree as G, Dropdown as K, Button as O } from "antd"; import { PlusOutlined as _, FilterOutlined as E, MinusOutlined as U, EllipsisOutlined as j } from "@ant-design/icons"; import F from "lodash-es/get.js"; import I from "lodash-es/set.js"; import M from "lodash-es/isEqual.js"; /* empty css */ import { ComparisonFilter as q } from "../ComparisonFilter/ComparisonFilter.js"; import { isCombinationFilter as w, isNegationFilter as N, isComparisonFilter as z, isGeoStylerFunction as R, isGeoStylerBooleanFunction as H } from "geostyler-style"; import p from "../../../Util/FilterUtil.js"; import { useGeoStylerLocale as J } from "../../../context/GeoStylerContext/GeoStylerContext.js"; import Q from "lodash-es/isBoolean.js"; const ae = ({ filter: s = ["==", "", null], onFilterChange: y, ...L }) => { const r = J("FilterTree"), v = (e, n) => { M(e, s) && y(e); let t = structuredClone(s); n === "" || H(t) || Q(t) ? t = e : I(t, n, e), y && y(t); }, x = (e, n) => { const t = p.addFilter(s, e, n); y(t); }, D = (e, n) => { const t = p.changeFilter(s, e, n); y(t); }, S = (e) => { const n = p.removeFilter(s, e); y(n); }, P = (e, n = "") => { const t = (u) => { const g = u.keyPath.reverse(); switch (g[0]) { case "add": x(n, g[1].toString()); break; case "change": D(n, g[1].toString()); break; case "remove": S(n); break; } }, i = []; w(e) && i.push({ label: r.addFilterLabel, key: "add", icon: /* @__PURE__ */ a(_, {}), children: [{ label: r.andDrpdwnLabel, key: "and" }, { label: r.orDrpdwnLabel, key: "or" }, { label: r.notDrpdwnLabel, key: "not" }, { label: r.comparisonDrpdwnLabel, key: "comparison" }] }), i.push({ label: r.changeFilterLabel, key: "change", icon: /* @__PURE__ */ a(E, {}), children: [{ label: r.andDrpdwnLabel, key: "and" }, { label: r.orDrpdwnLabel, key: "or" }, { label: r.notDrpdwnLabel, key: "not" }, { label: r.comparisonDrpdwnLabel, key: "comparison" }] }), i.push({ key: "remove", icon: /* @__PURE__ */ a(U, {}) }); const l = /* @__PURE__ */ a( K, { trigger: ["click"], menu: { items: i, onClick: t }, children: /* @__PURE__ */ a( O, { className: "filter-menu-button", size: "small", icon: /* @__PURE__ */ a(j, {}) } ) } ); let m = "", o; const k = !(w(e) || N(e)); let c = []; if (w(e)) { const u = e[0] === "&&" ? r.andFilterText : r.orFilterText; m = `${e[0] === "&&" ? "and" : "or"}-filter`, o = /* @__PURE__ */ h("span", { className: "node-title", children: [ /* @__PURE__ */ a("span", { className: "filter-text", children: u }), l ] }), c = e.slice(1).map((d, g) => { const b = `${n}[${g + 1}]`; return P(d, b); }); } else N(e) ? (m = "not-filter", o = /* @__PURE__ */ h("span", { className: "node-title", children: [ /* @__PURE__ */ a("span", { className: "filter-text", children: r.notFilterText }), l ] }), c = [P(e[1], `${n}[1]`)]) : z(e) ? (m = "comparison-filter", o = /* @__PURE__ */ h("span", { className: "node-title", children: [ /* @__PURE__ */ a( q, { microUI: !0, filter: e, onFilterChange: (u) => v(u, n) } ), l ] })) : R(e) ? (m = "function-filter", o = /* @__PURE__ */ h("span", { className: "node-title", children: [ "GeoStyler function not supported yet.", l ] })) : (m = "unknown-filter", o = /* @__PURE__ */ h("span", { className: "node-title", children: [ "Unknown filter supplied.", l ] })); return { className: `style-filter-node ${m}`, key: n, isLeaf: k, title: o, children: c }; }; return /* @__PURE__ */ a( G, { className: "gs-filter-tree", draggable: !0, defaultExpandAll: !0, ...L, onDrop: (e) => { const { dragNode: n, node: t } = e; let i = structuredClone(s); const l = n.props.eventKey, m = F(s, l), o = l.substring(0, l.length - 3), k = o === "" ? s : F(s, o), c = p.positionStringAsArray(l), u = c[c.length - 1], d = t.props.eventKey === "0-0" ? "" : t.props.eventKey, g = d.substring(0, d.length - 3), b = p.positionStringAsArray(d), C = b[b.length - 1], T = o === g, B = Array.isArray(k) && k.length <= 2; let f = structuredClone(c); if ((d === "" || g === "") && (d === "" || b[0] < c[0]) && (f[0] = c[0] + 1), T) { if (C < u) { const A = f.length - 1; f[A] = u + 1; } } else B && (f = p.positionStringAsArray(o)); const $ = p.positionArrayAsString(f); i = p.insertAtPosition(i, m, d), i = p.removeAtPosition(i, $), y(i); }, treeData: [P(s)] } ); }; export { ae as FilterTree };