UNPKG

@devgateway/dvz-ui-react

Version:

A modular, embeddable React component library for data visualization and UI, built with TypeScript. Provides reusable components for charts, maps, dashboards, and more, with built-in support for internationalization and Redux integration.

49 lines (48 loc) 1.98 kB
import { Config as S } from "../../conf/index.js"; import { get as y } from "../../api/commons.js"; function p(n) { return JSON.parse(JSON.stringify(n)); } const g = process.env.VITE_REACT_APP_API_ROOT || S.REACT_APP_API_ROOT || null, A = typeof window < "u" ? window.location.origin : "", l = {}, f = {}, C = 3 * 60 * 1e3; function O(n) { return Object.keys(n).map((t) => encodeURIComponent(t) + "=" + encodeURIComponent(n[t])).join("&"); } function _(n, t = !1) { const e = n, r = Date.now(); if (f[e] && r - f[e].timestamp < C) return Promise.resolve(p(f[e].data)); if (l[e]) return l[e].then(p); const c = y(n, {}).then((a) => (f[e] = { data: a, timestamp: Date.now() }, t ? { data: p(a), meta: f[e].meta } : p(a))).finally(() => { delete l[e]; }); return l[e] = c, c; } const E = ({ app: n, params: t }) => { const e = `${g || A}/api/${n}/categories${t ? "?" + O(t) : ""}`; return _(e); }, U = ({ source: n, app: t, params: e }) => { const r = `${g || A}/api/${t}/stats/${n}${e ? "?" + O(e) : ""}`; return _(r); }, D = ({ postType: n, taxonomy: t, category: e, taxonomyFilters: r, before: c, perPage: a, page: h, locale: w, after: m }) => { const R = `${S.REACT_APP_WP_API}/wp/v2/${n}`, i = new URLSearchParams(), d = /* @__PURE__ */ new Map(), T = (s, o) => { if (!s || o == null) return; const u = d.get(s) || []; Array.isArray(o) ? o.forEach((P) => { P != null && u.push(String(P)); }) : u.push(String(o)), d.set(s, u); }; r && r instanceof Map && r.forEach((s, o) => { T(o, s); }), d.forEach((s, o) => { const u = Array.from(new Set(s)); i.set(o, u.join(",")); }), c && i.append("before", c.toISOString()), a && i.append("per_page", a.toString()), i.append("page", h.toString()), i.append("locale", w), m && i.append("after", m.toISOString()); const $ = i.toString().replace(/%2C/g, ","); return y(`${R}?${$}`, {}); }; export { E as getCategories, D as getCustomPosts, U as getData };