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.

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