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.

270 lines (269 loc) 9.95 kB
import { jsx as r, jsxs as nt } from "react/jsx-runtime"; import { PostProvider as gt, PostConsumer as mt } from "@devgateway/wp-react-lib"; import yt from "../connected-templates/PostIntro.js"; import { Container as bt, Modal as F } from "semantic-ui-react"; import * as p from "d3"; import { useWindowDimensionsAndDevice as Ct } from "../../lib/hooks/window-dimensions.js"; import { useScreenOrientation as xt } from "../../lib/hooks/screen-orientation.js"; const wt = { visibility: "visible", position: "relative", height: "auto", width: "auto" }, vt = 0, Tt = (T) => { let { posts: s, lineWidth: P, lineColor: $, config: c, marginLeft: q, marginTop: L, marginRight: G, marginBottom: N, fontSize: y, subtitleWidth: R, subtitleHeight: b, enableTitlePopup: k, enableCirclePopup: D, enableDefaultPopup: U, closePopupOnMouseOut: J, unique: u } = T; R = 250; const C = useRef(), S = useRef(), [W, h] = useState(!1), [H, I] = useState(0), [O, _] = useState(null), { orientation: g } = xt(), { width: V, deviceType: f, height: x } = Ct({ getDeviceType: !0, getHeight: !0 }), B = useCallback((t) => `circle${u}${t}`, [u]), at = useCallback((t) => `title${u}${t}`, [u]), rt = (t) => { var l; return ((l = c[t]) == null ? void 0 : l.size) || 10; }, st = ({ content: t, isOpen: l, style: i }) => { const m = (n) => (n = n.replace( /<ul(.*?)>/g, '<ul class="has-white-color has-text-color has-standard-14-font-size" style="list-style-type:disc !important; list-style: initial !important; padding-left:20px; color:#fefefe;">' ), n = n.replace(/<a(.*?)>/g, '<a$1 style="color:#fefefe;">'), n); return /* @__PURE__ */ nt( F, { open: l, onClose: () => h(!1), size: "fullscreen", closeIcon: !0, centered: !0, style: { maxHeight: "80vh", overflowY: "auto", padding: "0.5rem", ...i }, children: [ /* @__PURE__ */ r(F.Header, { style: { ...i, borderBottom: "none" } }), /* @__PURE__ */ r( F.Content, { className: "styled-list-content", style: { ...i }, dangerouslySetInnerHTML: { __html: m( t.props.children.props.post.content.rendered ) } } ) ] }, `${t.props.children.key}modal` ); }, X = (t) => { var l; return (l = c[t]) == null ? void 0 : l.circleColor; }, Y = (t) => c[t].titleColor, K = (t) => c[t].lineColor, Q = (t) => c[t].tooltipFontColor || "#fff", ct = (t) => c[t].readMoreLabel, Z = useCallback((t, l) => { t.preventDefault(); const i = 260, m = 50; let n = [0, 0]; if (t) { const w = t.target.getBoundingClientRect(), A = t.target.closest(".time").getBoundingClientRect(), a = w.left - A.left, v = w.top + A.top; n = [a + i, v + m]; const M = 400; w.left + a + M + i > window.innerWidth && (n[0] = a - M * 0.6); } h(!0), _({ data: l, id: l.id, position: n }), ut(l.id); }, []), dt = () => { h(!1); }, pt = (t) => { p.selectAll(`#${B(t)}`).style("stroke", "none").style("fill", X(t)), p.selectAll(`#label${t}`).style("font-weight", "normal"); }, ut = (t) => { pt(vt), p.selectAll(`#${B(t)}`).style("stroke", X(t)).style("fill", "#fff"), p.selectAll(`#label${t}`).style("font-weight", "bold"); }; return useLayoutEffect(() => { var lt; const t = { top: L, bottom: N }, l = C.current.clientWidth, i = S.current.clientWidth; i > 0 && I(i); const m = x, n = { mobile: "75", tablet: "150", midTablet: "150", laptop: "150" }, w = { mobile: "250", tablet: "350", midTablet: "350", laptop: "400" }, A = { mobile: 20, tablet: 30, midTablet: 30, laptop: 40 }, a = p.scaleLinear().domain([0, s.length - 1]).range([t.top, m - t.bottom]), v = p.select(C.current); v.selectAll("*").remove(), v.attr("width", l).attr("height", m); const M = p.line(), ft = [ [0, a(0)], [0, a(s.length - 1)] ], ht = M(ft); let tt = `translate(${n[f]},0)`; ((lt = process.env.REACT_APP_THEME) == null ? void 0 : lt.startsWith("cd")) && (tt = `translate(${n[f]},20)`); const z = v.append("g").attr("transform", tt); $ = "#E4E5EA", P = 6, z.append("path").attr("d", ht).attr("stroke-width", P).attr("stroke", $).attr("class", "timeline-path"), z.selectAll(".circle").data(s).enter().append("circle").attr("id", (o, e) => B(e)).attr("cx", 0).attr("class", "timeline-circle").attr("cy", (o, e) => a(e)).attr("r", (o, e) => rt(e)).style("fill", (o, e) => { var d; return ((d = c[e]) == null ? void 0 : d.circleColor) || "#000"; }).style("cursor", D ? "pointer" : "default").on("click", (o, e) => { o.preventDefault(), D && Z(o, e); }), z.selectAll(".title").data(s).enter().append("foreignObject").attr("x", A[f]).attr("y", (o, e) => a(e) - Number.parseInt(b) / 2).attr("width", Number.parseInt(w[f])).attr("height", Number.parseInt(b)).attr("class", "timeline-title").append("xhtml:div").attr("id", (o, e) => at(e)).style("font-size", `${Number.parseInt(y) + 1}px`).style("color", (o, e) => Y(e)).style("font-weight", "bold").style("line-height", "1.2rem").style("text-align", "left").style("cursor", k ? "pointer" : "default").style("overflow", "hidden").style("display", "-webkit-box").style("-webkit-line-clamp", "2").style("-webkit-box-orient", "vertical").style("text-overflow", "ellipsis").style("overflow-wrap", "break-word").html((o, e) => { const d = ct(e); let E = o.title.rendered; return d && (E += `<br><span style="font-size:${Number.parseInt(y) - 3}px;color:${Y( e )};text-decoration:underline;text-underline-offset:3px">${d}</span>`), E; }).each(function(o, e) { const d = p.select(this.parentNode); setTimeout(() => { const E = this.getBoundingClientRect(), it = Math.min( E.height, Number.parseInt(b) * 2 ); d.attr("height", it), d.attr("y", a(e) - it / 2); }, 0); }).on("click", (o, e, d) => { o.preventDefault(), k && Z(o, e); }); const et = +y + 1, ot = 60, j = et * 0.9; z.selectAll(".year-fo").data(s).enter().append("foreignObject").attr("class", "year-fo").attr("x", -70).attr("y", (o, e) => a(e) - j / 2).attr("width", ot).attr("height", j).append("xhtml:div").style("display", "flex").style("align-items", "center").style("justify-content", "flex-end").style("width", `${ot}px`).style("height", `${j}px`).style("font-size", `${et}px`).style("line-height", "1em").style("font-weight", "400").style("color", "#4C4D50").html((o) => o.meta_fields.subtitle); }, [f, g, x]), /* @__PURE__ */ nt( "div", { className: "time line", style: { position: "relative" }, ref: S, children: [ s.filter((t) => O && O.id === t.id).map((t) => { const l = t.slug || "unknown-slug", i = s.indexOf(t); return /* @__PURE__ */ r( st, { isOpen: W, content: /* @__PURE__ */ r( "div", { style: { backgroundColor: K(i), color: Q(i) }, children: /* @__PURE__ */ r( yt, { post: t, style: wt }, l ) } ), closeTooltip: dt, style: { backgroundColor: K(i), color: Q(i) } }, `${l}_modal` ); }), /* @__PURE__ */ r("svg", { height: x, width: H, ref: C, style: { overflow: "visible" } }) ] }, u + f + g ); }, It = (T) => { const { "data-type": s, "data-taxonomy": P, "data-categories": $, "data-items": c, "data-height": q, "data-line-color": L = "#000", "data-config": G = "{}", "data-position": N = "middle", "data-line-width": y = "1", "data-margin-left": R = 50, "data-margin-top": b = 25, "data-margin-right": k = 50, "data-margin-bottom": D = 25, "data-font-size": U = 14, "data-title-width": J = 100, "data-title-height": u = 50, "data-subtitle-width": C = 250, "data-subtitle-height": S = 60, "data-enable-title-popup": W = "false", "data-enable-circle-popup": h = "true", "data-enable-default-popup": H = "false", "data-close-popup-on-mouse-out": I = "false", editing: O, parent: _, unique: g } = T, V = T.intl.locale, x = { unique: g || Math.random().toString(36).substring(2, 9), marginLeft: R, marginTop: b, marginRight: k, marginBottom: D, lineWidth: y, height: q, position: N, lineColor: decodeURIComponent(L), config: JSON.parse(decodeURIComponent(G)), fontSize: U, titleWidth: J, titleHeight: u, subtitleWidth: C, subtitleHeight: S, enableTitlePopup: W == !0 || W == "true", enableCirclePopup: h == !0 || h == "true", enableDefaultPopup: H == !0 || H == "true", closePopupOnMouseOut: I == !0 || I == "true" }; return /* @__PURE__ */ r( bt, { style: { height: "auto" }, className: `viz time line ${O ? "editing" : ""} mobile`, fluid: !0, children: /* @__PURE__ */ r( gt, { locale: V, type: s, taxonomy: P, categories: $, store: `carousel_${_}_${g}`, page: 1, perPage: c, children: /* @__PURE__ */ r(mt, { children: /* @__PURE__ */ r(Tt, { ...x }) }) } ) } ); }; export { It as default };