@extclp/vexip-ui
Version:
A Vue 3 UI library, Highly customizability, full TypeScript, performance pretty good
63 lines (62 loc) • 2.03 kB
JavaScript
import { defineComponent as v, toRef as y, ref as b, computed as D, watch as u, onBeforeUnmount as h, createElementBlock as w, openBlock as A, normalizeClass as x, unref as s, toDisplayString as B } from "vue";
import { useProps as H, useNameHelper as S, useLocale as T, useWordSpace as k } from "@vexip-ui/config";
import { format as C, toDate as F } from "@vexip-ui/utils";
import { computeTimeAgo as f, getId as I, subscribe as M, unsubscribe as P } from "./helper.mjs";
import { timeAgoProps as z } from "./props.mjs";
const E = ["title"], q = /* @__PURE__ */ v({
name: "TimeAgo",
__name: "time-ago",
props: z,
setup(d, { expose: g }) {
const t = H("timeAgo", d, {
locale: null,
datetime: {
default: () => Date.now(),
static: !0
},
interval: {
default: !1,
validator: (e) => typeof e == "boolean" || e >= 1
},
title: !1,
titleFormat: "yyyy-MM-dd HH:mm:ss"
}), l = S("time-ago"), r = p(t.datetime), a = T("timeAgo", y(t, "locale")), n = k(), o = b(f(r, Date.now(), a.value, n.value)), m = I(), i = {
datetime: r,
timeAgo: o,
locale: a,
wordSpace: n,
interval: c(t.interval),
updated: Date.now()
}, _ = D(() => {
if (t.title)
return typeof t.title == "string" ? t.title : C(t.datetime, t.titleFormat);
});
M(m, i), u(
() => t.datetime,
(e) => {
i.datetime = p(e), o.value = f(r, Date.now(), a.value, n.value);
}
), u(
() => t.interval,
(e) => {
i.interval = c(e);
}
), h(() => {
P(m);
});
function c(e) {
return e && (e === !0 ? 1e4 : e * 1e3);
}
function p(e) {
return typeof e == "string" && (e = e.replace(/-/g, "/")), F(e);
}
return g({ timeAgo: o }), (e, N) => (A(), w("span", {
class: x([s(l).b(), s(t).inherit && s(l).bm("inherit")]),
title: _.value
}, B(o.value), 11, E));
}
});
export {
q as default
};
//# sourceMappingURL=time-ago.vue2.mjs.map