ant-design-x-vue
Version:
Craft AI-driven interfaces effortlessly
137 lines (136 loc) • 3.87 kB
JavaScript
import { defineComponent as M, mergeDefaults as O, toRef as g, useAttrs as W, mergeProps as h, ref as u, watch as m, watchEffect as j, onWatcherCleanup as q, unref as t, nextTick as F, computed as G, createVNode as x } from "vue";
import { a as J, c as Q } from "../attachments/Attachments2.mjs";
import { useEventCallback as Y } from "../_util/hooks/use-event-callback.mjs";
import Z from "../_util/pick-attrs.mjs";
import _ from "../x-provider/hooks/use-x-provider-context.mjs";
import "../x-provider/context.mjs";
import "ant-design-vue";
import tt from "./Bubble.mjs";
import et from "./hooks/useDisplayData.mjs";
import ot from "./hooks/useListData.mjs";
import st from "./style/index.mjs";
import b from "../_util/hooks/use-state.mjs";
import { BubbleContextProvider as lt } from "./context.mjs";
const rt = 1, vt = /* @__PURE__ */ M({
name: "AXBubbleList",
inheritAttrs: !1,
__name: "BubbleList",
props: O({
prefixCls: null,
rootClassName: null,
items: null,
autoScroll: {
type: Boolean
},
roles: null
}, {
autoScroll: !0
}),
setup(e, {
expose: D
}) {
const T = J(e, ["prefixCls", "rootClassName", "items", "autoScroll", "roles"]);
g(e, "roles"), g(e, "items"), g(e, "prefixCls");
const V = W(), A = Z(h(T, V), {
attr: !0,
aria: !0
}), v = u(e.items), S = u(e.roles);
m(() => e.items, () => {
v.value = e.items;
}), m(() => e.roles, () => {
S.value = e.roles;
});
const n = u(null), i = u({}), {
getPrefixCls: N
} = _(), P = N("bubble", e.prefixCls), R = `${P}-list`, [w, B, L] = st(P), [H, I] = b(!1);
j(() => {
I(!0), q(() => {
I(!1);
});
});
const U = ot(v, S), [a, $] = et(U), [E, f] = b(!0), [d, y] = b(0), z = (o) => {
const s = o.target;
f(s.scrollHeight - Math.abs(s.scrollTop) - s.clientHeight <= rt);
};
m(d, () => {
e.autoScroll && t(n) && t(E) && F(() => {
t(n).scrollTo({
top: t(n).scrollHeight
});
});
}), m(() => t(a).length, () => {
var o;
if (e.autoScroll) {
const s = (o = t(a)[t(a).length - 2]) == null ? void 0 : o.key, l = t(i)[s];
if (l) {
const {
nativeElement: r
} = l, {
top: c = 0,
bottom: C = 0
} = (r == null ? void 0 : r.getBoundingClientRect()) ?? {}, {
top: p,
bottom: K
} = t(n).getBoundingClientRect();
c < K && C > p && (y(t(d) + 1), f(!0));
}
}
});
const X = Y(() => {
e.autoScroll && y(t(d) + 1);
}), k = G(() => ({
onUpdate: X
}));
return D({
nativeElement: n,
scrollTo: ({
key: o,
offset: s,
behavior: l = "smooth",
block: r
}) => {
if (typeof s == "number")
t(n).scrollTo({
top: s,
behavior: l
});
else if (o !== void 0) {
const c = t(i)[o];
if (c) {
const C = t(a).findIndex((p) => p.key === o);
f(C === t(a).length - 1), c.nativeElement.scrollIntoView({
behavior: l,
block: r
});
}
}
}
}), () => w(x(lt, {
value: k.value
}, {
default: () => [x("div", h(A, {
class: Q(R, e.rootClassName, B.value, L, {
[`${R}-reach-end`]: E.value
}),
ref: n,
onScroll: z
}), [t(a).map(({
key: o,
onTypingComplete: s,
...l
}) => x(tt, h(l, {
key: o,
ref: (r) => {
r ? i.value[o] = r : delete i.value[o];
},
typing: H.value ? l.typing : !1,
onTypingComplete: () => {
s == null || s(), $(o);
}
}), null))])]
}));
}
});
export {
vt as default
};