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.

2 lines (1 loc) 1.68 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("../../conf/index.js"),y=require("../../api/commons.js");function f(t){return JSON.parse(JSON.stringify(t))}const l=process.env.VITE_REACT_APP_API_ROOT||S.Config.REACT_APP_API_ROOT||null,A=typeof window<"u"?window.location.origin:"",p={},g={},$=3*60*1e3;function C(t){return Object.keys(t).map(n=>encodeURIComponent(n)+"="+encodeURIComponent(t[n])).join("&")}function O(t,n=!1){const e=t,r=Date.now();if(g[e]&&r-g[e].timestamp<$)return Promise.resolve(f(g[e].data));if(p[e])return p[e].then(f);const c=y.get(t,{}).then(a=>(g[e]={data:a,timestamp:Date.now()},n?{data:f(a),meta:g[e].meta}:f(a))).finally(()=>{delete p[e]});return p[e]=c,c}const q=({app:t,params:n})=>{const e=`${l||A}/api/${t}/categories${n?"?"+C(n):""}`;return O(e)},I=({source:t,app:n,params:e})=>{const r=`${l||A}/api/${n}/stats/${t}${e?"?"+C(e):""}`;return O(r)},E=({postType:t,taxonomy:n,category:e,taxonomyFilters:r,before:c,perPage:a,page:T,locale:_,after:m})=>{const h=`${S.Config.REACT_APP_WP_API}/wp/v2/${t}`,i=new URLSearchParams,d=new Map,w=(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)=>{w(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",T.toString()),i.append("locale",_),m&&i.append("after",m.toISOString());const R=i.toString().replace(/%2C/g,",");return y.get(`${h}?${R}`,{})};exports.getCategories=q;exports.getCustomPosts=E;exports.getData=I;