vue-data-ui
Version:
A user-empowering data visualization Vue 3 components library for eloquent data storytelling
249 lines (248 loc) • 11.4 kB
JavaScript
import { useCssVars as ee, computed as T, ref as s, watch as te, createElementBlock as w, openBlock as y, createCommentVNode as E, createElementVNode as p, normalizeStyle as $, createStaticVNode as oe, Fragment as L, renderList as ae, normalizeClass as le, renderSlot as ne } from "vue";
import ue from "./pdf-DVWl3Adn.js";
import { u as se } from "./useNestedProp-CyyJlG5K.js";
import { u as ie, c as re } from "./index-BsIlHNy8.js";
import { _ as de } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const ce = {
key: 0,
"data-html2canvas-ignore": "",
style: { width: "100%", display: "flex", "justify-content": "end" }
}, he = ["disabled"], ve = ["stroke"], fe = { key: 1 }, ge = ["id"], pe = ["onMousedown", "onTouchstart"], be = ["onMousedown", "onTouchstart"], we = ["onMousedown", "onTouchstart"], ye = ["onMousedown", "onTouchstart"], Te = ["onMousedown", "onTouchstart"], x = 20, me = {
__name: "vue-ui-dashboard",
props: {
dataset: Array,
config: Object
},
emits: ["change"],
setup(P, { expose: S, emit: W }) {
ee((e) => ({
"014a5839": G.value,
c96c137e: q.value
}));
const { vue_ui_dashboard: R } = ie(), X = P, i = T(() => se({
userConfig: X.config,
defaultConfig: R
})), Y = s(re()), c = s(i.value.locked);
function B() {
c.value = !c.value;
}
const u = s(X.dataset.map((e, t) => ({
...e,
index: t
}))), h = s(null), n = s(null), v = s({ x: 0, y: 0 }), f = s({ x: 0, y: 0 }), r = s(null), d = s(!1), g = s(null), k = s(!1), m = s(!1);
function I(e) {
const t = e.target;
(t.tagName === "INPUT" && t.type === "range" || t.classList.contains("range-handle")) && (m.value = !0);
}
function N(e) {
const t = e.target;
t.tagName === "INPUT" && t.type === "range" && (m.value = !1);
}
function H() {
k.value = !0, ue({
domElement: document.getElementById(`vue-ui-dashboard_${Y.value}`),
fileName: "vue-ui-dashboard"
}).finally(() => {
k.value = !1;
});
}
function F(e) {
if (!c.value && (d.value = !0, g.value = e, n.value === null)) {
h.value = e, v.value = { x: event.clientX, y: event.clientY };
const t = u.value[e], a = 100 - t.width, o = 100 - t.height;
t.left < 0 && (t.left = 0), t.top < 0 && (t.top = 0), t.left > a && (t.left = a), t.top > o && (t.top = o), t.left < 0 && (t.left = 0), t.top < 0 && (t.top = 0), t.left + t.width > 100 && (t.left = 100 - t.width), t.top + t.height > 100 && (t.top = 100 - t.height);
}
}
function _(e, t) {
d.value = !0, g.value = e, n.value = { index: e, direction: t };
const a = u.value[e];
f.value = { x: event.clientX, y: event.clientY, initialWidth: a.width, initialHeight: a.height };
}
function D(e, t, a) {
if (n.value.direction.includes("top")) {
const o = e.height - a / r.value.offsetHeight * 100;
o >= x && (e.top += a / r.value.offsetHeight * 100, e.height = o);
}
if (n.value.direction.includes("bottom")) {
const o = e.height + a / r.value.offsetHeight * 100;
o >= x && (e.height = o);
}
if (n.value.direction.includes("left")) {
const o = e.width - t / r.value.offsetWidth * 100;
o >= x && (e.left += t / r.value.offsetWidth * 100, e.width = o);
}
if (n.value.direction.includes("right")) {
const o = e.width + t / r.value.offsetWidth * 100;
o >= x && (e.width = o);
}
}
function U(e) {
if (!(c.value || m.value)) {
if (d.value = !0, h.value !== null) {
const t = u.value[h.value], a = e.clientX - v.value.x, o = e.clientY - v.value.y, l = t.left + a / r.value.offsetWidth * 100, b = t.top + o / r.value.offsetHeight * 100;
l >= 0 && b >= 0 && l + t.width <= 100 && b + t.height <= 100 && (t.left = l, t.top = b), v.value = { x: e.clientX, y: e.clientY };
}
if (n.value !== null) {
const t = u.value[n.value.index], a = e.clientX - f.value.x, o = e.clientY - f.value.y;
D(t, a, o), f.value = { x: e.clientX, y: e.clientY };
}
}
}
const O = W;
te(
u,
(e) => {
e && !d.value && O("change", u.value);
},
{ deep: !0 }
);
function V() {
h.value = null, n.value = null, d.value = !1, g.value = null, u.value.forEach((e) => {
e.left = Math.round(e.left / 100 * 100), e.top = Math.round(e.top / 100 * 100), e.width = Math.round(e.width / 100 * 100), e.height = Math.round(e.height / 100 * 100);
});
}
function j(e) {
c.value || m.value || (d.value = !0, g.value = e, n.value === null && (h.value = e, v.value = { x: event.touches[0].clientX, y: event.touches[0].clientY }));
}
function C(e, t, a) {
if (d.value = !0, g.value = e, n.value === null) {
n.value = { index: e, direction: t };
const o = u.value[e];
f.value = { x: a.touches[0].clientX, y: a.touches[0].clientY, initialWidth: o.width, initialHeight: o.height };
}
}
function z(e) {
if (d.value = !0, e.preventDefault(), n.value !== null) {
const t = u.value[n.value.index], a = e.touches[0].clientX - f.value.x, o = e.touches[0].clientY - f.value.y;
D(t, a, o), f.value = { x: e.touches[0].clientX, y: e.touches[0].clientY };
}
}
function A(e) {
if (!(c.value || m.value) && (d.value = !0, e.preventDefault(), h.value !== null)) {
const t = u.value[h.value], a = e.touches[0].clientX - v.value.x, o = e.touches[0].clientY - v.value.y, l = t.left + a / r.value.offsetWidth * 100, b = t.top + o / r.value.offsetHeight * 100;
l >= 0 && b >= 0 && l + t.width <= 100 && b + t.height <= 100 && (t.left = l, t.top = b), v.value = { x: e.touches[0].clientX, y: e.touches[0].clientY };
}
}
function M() {
d.value = !1, g.value = null, h.value = null, n.value = null, u.value.forEach((e) => {
e.left = Math.round(e.left / 100 * 100), e.top = Math.round(e.top / 100 * 100), e.width = Math.round(e.width / 100 * 100), e.height = Math.round(e.height / 100 * 100);
});
}
const G = T(() => i.value.style.item.borderColor), q = T(() => i.value.style.resizeHandles.backgroundColor), J = T(() => i.value.style.board.aspectRatio), K = T(() => i.value.style.board.backgroundColor), Q = T(() => i.value.style.board.border);
function Z() {
return u.value;
}
return S({
generatePdf: H,
getItemsPositions: Z,
toggleLock: B
}), (e, t) => (y(), w("div", {
onMousedown: I,
onMouseup: N,
onTouchstart: I,
onTouchend: N
}, [
i.value.allowPrint ? (y(), w("div", ce, [
p("button", {
class: "vue-ui-dashboard-button",
onClick: H,
disabled: k.value,
style: $([{ "margin-top": "12px" }, `color:${i.value.style.board.color}`])
}, [
k.value ? (y(), w("svg", {
key: 0,
class: "vue-ui-dashboard-print-icon",
xmlns: "http://www.w3.org/2000/svg",
width: "20",
height: "20",
viewBox: "0 0 24 24",
"stroke-width": "1.5",
stroke: i.value.style.board.color,
fill: "none",
"stroke-linecap": "round",
"stroke-linejoin": "round"
}, t[4] || (t[4] = [
oe('<path stroke="none" d="M0 0h24v24H0z" fill="none" data-v-07570d07></path><path d="M18 16v.01" data-v-07570d07></path><path d="M6 16v.01" data-v-07570d07></path><path d="M12 5v.01" data-v-07570d07></path><path d="M12 12v.01" data-v-07570d07></path><path d="M12 1a4 4 0 0 1 2.001 7.464l.001 .072a3.998 3.998 0 0 1 1.987 3.758l.22 .128a3.978 3.978 0 0 1 1.591 -.417l.2 -.005a4 4 0 1 1 -3.994 3.77l-.28 -.16c-.522 .25 -1.108 .39 -1.726 .39c-.619 0 -1.205 -.14 -1.728 -.391l-.279 .16l.007 .231a4 4 0 1 1 -2.212 -3.579l.222 -.129a3.998 3.998 0 0 1 1.988 -3.756l.002 -.071a4 4 0 0 1 -1.995 -3.265l-.005 -.2a4 4 0 0 1 4 -4z" data-v-07570d07></path>', 6)
]), 8, ve)) : (y(), w("span", fe, "PDF"))
], 12, he)
])) : E("", !0),
p("div", {
class: "vue-ui-dashboard-container",
ref_key: "dashboardContainer",
ref: r,
id: `vue-ui-dashboard_${Y.value}`,
style: $(`border:${Q.value}; sbackground:${K.value}; aspect-ratio:${J.value}`)
}, [
p("div", {
class: "vue-ui-dashboard-grid-container",
ref: "container",
onMousemove: U,
onMouseup: V,
onTouchmove: A,
onTouchend: M,
style: $(`background:${i.value.style.board.backgroundColor}`)
}, [
t[5] || (t[5] = p("div", { class: "vue-ui-dashboard-grid" }, null, -1)),
(y(!0), w(L, null, ae(u.value, (a, o) => (y(), w("div", {
key: a.id,
class: le({ "vue-ui-dashboard-grid-item": !0, "vue-ui-dashboard-grid-item--locked": c.value }),
style: $({
width: `${a.width}%`,
height: `${a.height}%`,
left: `${a.left}%`,
top: `${a.top}%`,
cursor: "move",
boxShadow: g.value === o ? "0 6px 12px -3px rgba(0,0,0,0.3)" : "",
zIndex: g.value === o ? u.value.length + 1 : a.index,
backgroundColor: i.value.style.item.backgroundColor
}),
onMousedown: (l) => F(o),
onTouchstart: (l) => j(o)
}, [
c.value ? E("", !0) : (y(), w(L, { key: 0 }, [
p("div", {
class: "vue-ui-dashboard-resize-handle vue-ui-dashboard-top-left",
onMousedown: (l) => _(o, "top-left"),
onTouchstart: (l) => C(o, "top-left", l),
onTouchmove: t[0] || (t[0] = (l) => z(l)),
onTouchend: M
}, null, 40, be),
p("div", {
class: "vue-ui-dashboard-resize-handle vue-ui-dashboard-top-right",
onMousedown: (l) => _(o, "top-right"),
onTouchstart: (l) => C(o, "top-right", l),
onTouchmove: t[1] || (t[1] = (l) => z(l)),
onTouchend: M
}, null, 40, we),
p("div", {
class: "vue-ui-dashboard-resize-handle vue-ui-dashboard-bottom-left",
onMousedown: (l) => _(o, "bottom-left"),
onTouchstart: (l) => C(o, "bottom-left", l),
onTouchmove: t[2] || (t[2] = (l) => z(l)),
onTouchend: M
}, null, 40, ye),
p("div", {
class: "vue-ui-dashboard-resize-handle vue-ui-dashboard-bottom-right",
onMousedown: (l) => _(o, "bottom-right"),
onTouchstart: (l) => C(o, "bottom-right", l),
onTouchmove: t[3] || (t[3] = (l) => z(l)),
onTouchend: M
}, null, 40, Te)
], 64)),
ne(e.$slots, "content", {
item: a,
index: o,
left: a.left,
top: a.top,
height: a.height,
width: a.width
}, void 0, !0)
], 46, pe))), 128))
], 36)
], 12, ge)
], 32));
}
}, $e = /* @__PURE__ */ de(me, [["__scopeId", "data-v-07570d07"]]);
export {
$e as default
};