@artmate/chat
Version:
**开箱即用的AI组件库(基于 Vue3 + ElementPlus)**
89 lines (88 loc) • 2.83 kB
JavaScript
import { defineComponent as D, ref as n, computed as f, createBlock as E, openBlock as P, unref as o, withCtx as h, createElementVNode as T, normalizeStyle as k, normalizeClass as N, renderSlot as V, createVNode as $ } from "vue";
import { onClickOutside as z } from "../../../node_modules/@vueuse/core/index.js";
import { ElTooltip as K, ElCascaderPanel as L } from "element-plus";
import { useNamespace as S } from "../hooks/useNamespace.js";
import W from "./useActive.js";
const q = /* @__PURE__ */ D({
__name: "index",
props: {
direction: {},
open: { type: Boolean },
className: {},
rootClassName: { default: "" },
style: {},
items: {},
block: { type: Boolean },
styles: {},
classNames: {}
},
emits: ["openChange", "select"],
setup(_, { emit: w }) {
const t = _, u = w, i = S("suggestion"), p = n(), m = n(), d = f(() => t.direction === "rtl"), l = n(), v = n(), a = n(t.open), C = f(() => typeof t.items == "function" ? t.items(m.value) : t.items);
function r(e) {
var s;
a.value = e, u("openChange", e), e || (s = p.value) == null || s.clearCheckedNodes();
}
function g(e) {
u("select", e[e.length - 1]), r(!1);
}
function c() {
r(!1);
}
const R = (e) => {
e === !1 ? r(!1) : (m.value = e, r(!0));
}, [y, B] = W(C, a, d, g, c);
function b(e) {
e ? g(y.value) : c();
}
const x = f(() => t.block && l.value ? `${l.value.offsetWidth}px` : "max-content");
return z(l, () => {
var e;
(e = v.value) != null && e.isFocusInsideContent() || a.value && c();
}), (e, s) => (P(), E(o(K), {
ref_key: "popperRef",
ref: v,
"class-name": [t.rootClassName],
trigger: "click",
placement: d.value ? "top-end" : "top-start",
visible: a.value,
"gpu-acceleration": !1,
effect: "light",
pure: "",
"manual-mode": "",
persistent: "",
role: "listbox",
onHide: b
}, {
content: h(() => [
$(o(L), {
ref_key: "CascaderPanelRef",
ref: p,
style: k({ width: x.value }),
class: N(o(i).b("cascader-panel")),
options: C.value,
border: !1,
"model-value": o(y),
onClose: s[0] || (s[0] = (A) => b(!0))
}, null, 8, ["style", "class", "options", "model-value"])
]),
default: h(() => [
T("div", {
ref_key: "defaultContainer",
ref: l,
class: N([o(i).b(), t.rootClassName, t.className, o(i).b("wrapper")]),
style: k(t.style)
}, [
V(e.$slots, "default", {
onTrigger: R,
onKeyDown: o(B)
}, void 0, !0)
], 6)
]),
_: 3
}, 8, ["class-name", "placement", "visible"]));
}
});
export {
q as default
};