Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/core/src/components/Bubble/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Bubble } from '../../components';
import type { TypewriterProps } from '../Typewriter/types';

export type BubbleProps = Pick<
Expand Down Expand Up @@ -25,3 +26,5 @@ export interface BubbleEmits {
(event: 'writing', instance: TypewriterInstance): void;
(event: 'avatarError', e: Event): void;
}

export type BubbleSlots = InstanceType<typeof Bubble>['$slots'];
26 changes: 10 additions & 16 deletions packages/core/src/components/BubbleList/index.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<script setup lang="ts" generic="T extends BubbleProps">
import type { BubbleProps } from '../Bubble/types';
import type { TypewriterInstance } from '../Typewriter/types.d.ts';
import type { BubbleListEmits, BubbleListProps } from './types.d.ts';
import type {
BubbleListEmits,
BubbleListProps,
BubbleListSlots
} from './types.d.ts';
import { ArrowDownBold } from '@element-plus/icons-vue';
import useScrollDetector from '../../utils/useScrollDetector.ts';
import Bubble from '../Bubble/index.vue';
Expand All @@ -23,6 +27,8 @@ const props = withDefaults(defineProps<BubbleListProps<T>>(), {
btnIconSize: 24
});
const emits = defineEmits<BubbleListEmits>();
defineSlots<BubbleListSlots<T>>();

const TOLERANCE = 30;

// const listMaxHeightStyle = computed(() => {
Expand Down Expand Up @@ -68,7 +74,7 @@ watch(
if (props.list && props.list.length > 0) {
nextTick(() => {
if (props.autoScroll) {
// 每次添加新的气泡,等页面渲染后,在执行自动滚动
// 每次添加新的气泡,等页面渲染后,在执行自动滚动
autoScroll();
}
});
Expand Down Expand Up @@ -243,20 +249,8 @@ defineExpose({
:no-style="item.noStyle"
@finish="instance => handleBubbleComplete(index, instance)"
>
<template v-if="$slots.avatar" #avatar>
<slot name="avatar" :item="item" />
</template>
<template v-if="$slots.header" #header>
<slot name="header" :item="item" />
</template>
<template v-if="$slots.content" #content>
<slot name="content" :item="item" />
</template>
<template v-if="$slots.footer" #footer>
<slot name="footer" :item="item" />
</template>
<template v-if="$slots.loading" #loading>
<slot name="loading" :item="item" />
<template v-for="(_, slotName) in $slots" :key="slotName" #[slotName]>
<slot :name="slotName" :item="item" :index="index" />
</template>
</Bubble>
</div>
Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/components/BubbleList/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BubbleProps } from '../Bubble/types';
import type { BubbleProps, BubbleSlots } from '../Bubble/types';
import type { TypewriterInstance } from '../Typewriter/types.d.ts';

// 暂时这样包一层,后续看有没有拓展
Expand Down Expand Up @@ -29,6 +29,12 @@ export interface BubbleListEmits {
(event: 'complete', instance: TypewriterInstance, index: number): void;
}

export type BubbleListSlots<T> = {
[K in keyof BubbleSlots]: (props: { item: T; index: number }) => void;
} & {
backToBottom: (props: object) => void;
};
Comment on lines +32 to +36
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Make slots optional and return a VNode-ish (or any) instead of void.

Parents won’t provide every slot; returning void is atypical for Vue slots. Mark them optional and loosen return type. Minimal change diff:

-export type BubbleListSlots<T> = {
-  [K in keyof BubbleSlots]: (props: { item: T; index: number }) => void;
-} & {
-  backToBottom: (props: object) => void;
-};
+export type BubbleListSlots<T> = {
+  [K in keyof BubbleSlots]?: (props: { item: T; index: number }) => any;
+} & {
+  backToBottom?: () => any;
+};
🤖 Prompt for AI Agents
In packages/core/src/components/BubbleList/types.d.ts around lines 32 to 36, the
slot function types are required and return void; change them to be optional and
return a VNode-ish type (e.g. any or VNode) instead of void. Update the mapped
slot type to make each slot optional (use Partial or add ? to the property) and
change the function signature from (props: {...}) => void to (props: {...}) =>
any (or an appropriate VNode type), and do the same for backToBottom so it is
optional and returns any.


export interface BubbleListInstance {
scrollToTop: () => void;
scrollToBottom: () => void;
Expand Down