@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.
117 lines (116 loc) • 5.34 kB
JavaScript
import { jsx as e, jsxs as m } from "react/jsx-runtime";
import { Menu as a, Container as f, Image as j } from "semantic-ui-react";
import v, { useEffect as _, useState as M } from "react";
import { utils as C, MenuProvider as S, MediaProvider as y, MediaConsumer as z, MenuConsumer as g } from "@devgateway/wp-react-lib";
import { injectIntl as x } from "react-intl";
import { useParams as N, Link as I, NavLink as E } from "react-router";
import F from "./SearchControl.js";
import $ from "./LangSwitcher.js";
const D = (r, i) => {
const c = [];
return r.items.forEach((s) => {
s.child_items ? s.child_items.forEach((t) => {
t.slug == i.slug && (c.push(s), c.push(t));
}) : s.slug == i.slug && s.url != "/" && c.push(s);
}), c;
}, H = (r, i) => r ? r.substr(r.indexOf("/wp") + 3).startsWith("/" + i) ? r.substr(r.indexOf("/wp") + 3) : "/" + i + r.substr(r.indexOf("/wp") + 3) : "", R = x(({ menu: r, intl: i }) => {
const c = N(), s = D(r, c);
return /* @__PURE__ */ e(v.Fragment, { children: s.filter((t) => t.url != "#wpm-languages").map((t) => t.child_items ? /* @__PURE__ */ m("span", { children: [
t.post_title,
" "
] }) : /* @__PURE__ */ m(
"a",
{
className: t.slug == c.slug ? "active" : "",
href: C.replaceLink(t.url, i.locale),
children: [
" ",
t.post_title
]
}
)) });
}), w = x(({
settings: r,
withIcons: i,
active: c,
menu: s,
onSetSelected: t,
selected: o,
intl: { locale: u }
}) => {
const k = N();
_((n) => {
if (!o) {
const l = D(s, k).filter((h) => h.menu_item_parent == 0);
l && t(l[0]);
}
}, [s, t, o]);
const [p, b] = M(null);
return _(() => {
b(s);
}, [s]), _(() => {
if (r && r.menu_settings && p) {
const n = [], d = s.items.map((l) => (r.menu_settings && r.menu_settings["nav_menu_item[" + l.ID + "]"] === !1 && n.push(l.ID), r.menu_settings && r.menu_settings["nav_menu_item[" + l.ID + "]"] ? (r.menu_settings["nav_menu_item[" + l.ID + "]"], { ...l, ...r.menu_settings["nav_menu_item[" + l.ID + "]"] }) : l));
Object.keys(r.menu_settings).map((l) => {
const h = r.menu_settings[l];
if (h.type == "nav_menu_item") {
const L = /(-)?[0-9]+/g.exec(l), O = parseInt(L[0]);
d.find((P) => P.ID == O) || d.push(h.value);
}
}), b({ ...s, items: d.filter((l) => n.indexOf(l.ID) === -1) });
}
}, [r]), p && /* @__PURE__ */ e(v.Fragment, { children: p.items.filter((n) => n.url != "#wpm-languages").map((n) => /* @__PURE__ */ e(
a.Item,
{
as: I,
className: `divided ${n.child_items ? "has-child-items" : ""} ${o && o.ID == n.ID ? "selected" : ""} ${c == n.slug ? "active" : ""}`,
children: n.child_items ? /* @__PURE__ */ e("span", { onClick: (d) => t(n), children: n.title }) : /* @__PURE__ */ e(
I,
{
onClick: (d) => t(n),
to: n.type === "custom" ? C.replaceLink(n.url, u) : H(n.url, u),
children: n.title
}
)
}
)) });
}), B = ({ intl: r, settings: i }) => {
const [c, s] = M(), { slug: t } = N(), o = ({ media: u }) => u ? /* @__PURE__ */ e(j, { src: u.guid.rendered }) : /* @__PURE__ */ e("img", { className: "brand logo", size: "large", src: "/logo_full.png" });
return /* @__PURE__ */ e(v.Fragment, { children: /* @__PURE__ */ m(S, { slug: "main", locale: r.locale, children: [
/* @__PURE__ */ m(f, { fluid: !0, className: "header classic", children: [
/* @__PURE__ */ e(f, { fluid: !0, className: "background", children: /* @__PURE__ */ m(a, { className: "branding", text: !0, children: [
/* @__PURE__ */ e(a.Item, { children: /* @__PURE__ */ m(E, { to: "/", children: [
i.site_logo != 0 && /* @__PURE__ */ e(y, { id: i.site_logo, children: /* @__PURE__ */ e(z, { children: /* @__PURE__ */ e(o, {}) }) }),
!window.isCustomizedPreview && i.site_logo == 0 && /* @__PURE__ */ e("img", { className: "brand logo", size: "large", src: "/dc-logo_01.png" })
] }) }),
/* @__PURE__ */ e(a.Item, { className: "divider", children: /* @__PURE__ */ e("div", {}) }),
/* @__PURE__ */ e(a.Item, { as: I, fitted: !0, href: "/", children: /* @__PURE__ */ e("div", { className: "site name", children: i.name }) }),
/* @__PURE__ */ e(a.Menu, { className: "pages", children: /* @__PURE__ */ e(g, { children: /* @__PURE__ */ e(
w,
{
settings: i,
active: t,
selected: c,
onSetSelected: s
}
) }) }),
/* @__PURE__ */ e(a.Item, { children: /* @__PURE__ */ e(g, { children: /* @__PURE__ */ e($, { locale: r.locale }) }) }),
/* @__PURE__ */ e(a.Item, { fitted: !0, children: /* @__PURE__ */ e(F, {}) })
] }) }),
/* @__PURE__ */ e(f, { fluid: !0, className: "child", children: c && c.child_items && /* @__PURE__ */ e(a, { fluid: !0, text: !0, children: /* @__PURE__ */ e(
w,
{
active: t,
locale: r.locale,
withIcons: !0,
onSetSelected: (u) => null,
menu: { items: c.child_items }
}
) }) })
] }),
/* @__PURE__ */ e(f, { className: "url breadcrumbs", children: /* @__PURE__ */ e(g, { children: /* @__PURE__ */ e(R, {}) }) })
] }) });
}, X = x(B);
export {
X as default
};