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