UNPKG

@artmate/chat

Version:

**开箱即用的AI组件库(基于 Vue3 + ElementPlus)**

134 lines (133 loc) 5.01 kB
import { defineComponent as S, ref as k, computed as z, createBlock as m, openBlock as r, unref as l, withCtx as u, createElementVNode as C, normalizeClass as c, renderSlot as p, createCommentVNode as g, createElementBlock as D, resolveDynamicComponent as E, normalizeStyle as H, createTextVNode as I, toDisplayString as P, createVNode as b } from "vue"; import { MoreFilled as T } from "@element-plus/icons-vue"; import { ElTooltip as W, ElIcon as N, ElButton as F } from "element-plus"; import O from "../dropdown/index.vue.js"; import { useNamespace as U } from "../hooks/useNamespace.js"; const L = /* @__PURE__ */ S({ __name: "item", props: { direction: {}, className: {}, active: { type: Boolean }, info: {}, menu: {}, inEllipsis: { type: Boolean, default: !0 }, line: { default: 1 } }, emits: ["click"], setup(h, { emit: A }) { const n = h, B = A, d = k(!1), a = U("conversations"), V = z(() => { var e, i; return [ n.className, a.b("item"), { [a.b("item-active")]: n.active && !((e = n.info) != null && e.disabled) }, { [a.b("item-disabled")]: (i = n.info) == null ? void 0 : i.disabled } ]; }); function $(e) { e.stopPropagation(); } const s = k(); function w() { var e, i, o, t, f; if ((e = n.info) != null && e.disabled) { d.value = !1; return; } s.value && (d.value = ((i = s.value) == null ? void 0 : i.scrollWidth) > ((o = s.value) == null ? void 0 : o.offsetWidth) || ((t = s.value) == null ? void 0 : t.scrollHeight) > ((f = s.value) == null ? void 0 : f.offsetHeight)); } function M() { var e; (e = n.info) != null && e.disabled || B("click", n.info); } function R(e) { var i, o; Array.isArray(n.menu) || n.info && ((o = (i = n.menu) == null ? void 0 : i.onClick) == null || o.call(i, { ...n.info, key: e })); } return (e, i) => { var o; return r(), m(l(W), { visible: d.value, "onUpdate:visible": i[0] || (i[0] = (t) => d.value = t), content: (o = e.info) == null ? void 0 : o.label, disabled: e.inEllipsis && !d.value, placement: e.direction === "rtl" ? "left" : "right" }, { default: u(() => { var t, f, v; return [ C("li", { class: c(V.value), onClick: M }, [ p(e.$slots, "default", { class: "icon" }, () => [ e.info.icon ? (r(), D("div", { key: 0, class: c(l(a).b("icon")) }, [ typeof e.info.icon == "string" ? (r(), m(l(N), { key: 0 }, { default: u(() => [ (r(), m(E(e.info.icon))) ]), _: 1 })) : (r(), m(E(e.info.icon), { key: 1 })) ], 2)) : g("", !0) ]), C("div", { ref_key: "textRef", ref: s, class: c(l(a).b("label")), style: H({ textOverflow: "ellipsis", "-webkit-line-clamp": e.line }), onMouseenter: w }, [ p(e.$slots, "label", { item: e.info }, () => [ I(P(e.info.label), 1) ]) ], 38), e.menu && !((t = e.info) != null && t.disabled) ? (r(), m(O, { key: 0, disabled: (f = e.info) == null ? void 0 : f.disabled, menu: Array.isArray(e.menu) ? e.menu : e.menu.items, placement: e.direction === "rtl" ? "bottom-start" : "bottom-end", trigger: "click", teleported: Array.isArray(e.menu) ? !0 : (v = e.menu) == null ? void 0 : v.teleported, onCommand: R }, { default: u(() => { var y; return [ b(l(F), { disabled: (y = e.info) == null ? void 0 : y.disabled, link: "", onClick: $ }, { default: u(() => [ p(e.$slots, "menu-icon", { info: e.info }, () => [ b(l(N), { class: c(l(a).b("menu-icon")) }, { default: u(() => [ b(l(T)) ]), _: 1 }, 8, ["class"]) ]) ]), _: 3 }, 8, ["disabled"]) ]; }), _: 3 }, 8, ["disabled", "menu", "placement", "teleported"])) : g("", !0) ], 2) ]; }), _: 3 }, 8, ["visible", "content", "disabled", "placement"]); }; } }); export { L as default };