UNPKG

vue-files-preview-inno

Version:

A tool for previewing files such as doc, excel, pdf, image, markdown, txt, audio, and video and so on.

125 lines (124 loc) 4.12 kB
import { defineComponent as h, ref as y, watch as v, openBlock as n, createElementBlock as l, createElementVNode as a, toDisplayString as r, createTextVNode as b, createCommentVNode as o, Fragment as k, renderList as D } from "vue"; import N from "../../../../node_modules/@kenjiuno/msgreader/lib/index.mjs"; import { getFileRenderByFile as T, getFileRenderByUrl as E } from "../../utils/utils.mjs"; const F = { key: 0, class: "msg-preview" }, w = { class: "msg-header" }, x = { class: "msg-subject" }, B = { class: "msg-meta" }, M = { key: 0, class: "msg-field" }, j = { class: "msg-value" }, H = { key: 0, class: "msg-email" }, L = { key: 1, class: "msg-field" }, R = { class: "msg-value" }, S = { key: 2, class: "msg-field" }, V = { class: "msg-value" }, A = { key: 3, class: "msg-field" }, C = { class: "msg-value msg-attachments" }, $ = { class: "msg-body" }, G = ["innerHTML"], U = { key: 1, class: "msg-body-text" }, q = { key: 2, class: "msg-body-empty" }, K = /* @__PURE__ */ h({ __name: "index", props: { file: { default: () => null }, url: { default: () => null }, name: {} }, emits: ["rendered", "error"], setup(g, { emit: _ }) { const d = g, c = _, s = y(null); function u(t) { try { const e = new N(t); s.value = e.getFileData(), c("rendered"); } catch (e) { c("error", e instanceof Error ? e : new Error("Failed to parse MSG file")); } } v( () => d.file, (t) => { t && T(t).then((e) => { u(e); }).catch((e) => { c("error", e); }); }, { immediate: !0 } ), v( () => d.url, (t) => { t && !d.file && E(t).then((e) => { u(e); }).catch((e) => { c("error", e); }); }, { immediate: !0 } ); function p(t) { return !t || t.length === 0 ? "" : t.map((e) => { const i = e.name || "", m = e.email || e.smtpAddress || ""; return i && m ? `${i} <${m}>` : i || m; }).join("; "); } function f(t) { if (!t) return ""; try { return new Date(t).toLocaleString(); } catch { return t; } } return (t, e) => s.value ? (n(), l("div", F, [ a("div", w, [ a("h2", x, r(s.value.subject || "(No Subject)"), 1), a("div", B, [ s.value.senderName || s.value.senderEmail ? (n(), l("div", M, [ e[0] || (e[0] = a("span", { class: "msg-label" }, "From", -1)), a("span", j, [ b(r(s.value.senderName) + " ", 1), s.value.senderEmail ? (n(), l("span", H, "<" + r(s.value.senderEmail) + ">", 1)) : o("", !0) ]) ])) : o("", !0), s.value.recipients && s.value.recipients.length ? (n(), l("div", L, [ e[1] || (e[1] = a("span", { class: "msg-label" }, "To", -1)), a("span", R, r(p(s.value.recipients)), 1) ])) : o("", !0), s.value.clientSubmitTime || s.value.messageDeliveryTime ? (n(), l("div", S, [ e[2] || (e[2] = a("span", { class: "msg-label" }, "Date", -1)), a("span", V, r(f(s.value.clientSubmitTime || s.value.messageDeliveryTime)), 1) ])) : o("", !0), s.value.attachments && s.value.attachments.length ? (n(), l("div", A, [ e[3] || (e[3] = a("span", { class: "msg-label" }, "Attachments", -1)), a("span", C, [ (n(!0), l(k, null, D(s.value.attachments, (i, m) => (n(), l("span", { key: m, class: "msg-attachment-tag" }, r(i.fileName || i.name || "attachment"), 1))), 128)) ]) ])) : o("", !0) ]) ]), a("div", $, [ s.value.bodyHtml ? (n(), l("div", { key: 0, class: "msg-body-html", innerHTML: s.value.bodyHtml }, null, 8, G)) : s.value.body ? (n(), l("pre", U, r(s.value.body), 1)) : (n(), l("div", q, "No content")) ]) ])) : o("", !0); } }); export { K as default }; //# sourceMappingURL=index.vue2.mjs.map