refactor: Move useToast and clickOutside to UI package

- Export useToast composable from @prompt-optimizer/ui
- Remove local useToast and clickOutside implementations from web package
- Update import statements in App.vue to use UI package exports
This commit is contained in:
linshen committed 2025-02-15 15:54:29 +08:00
1 parent 5e42a81aa4
commit 671872b9a4
4 files changed
+6 -58

No files matched your search

+4 -1
View File
@@ -15,4 +15,7 @@ export { default as Modal } from './components/Modal.vue'
export { default as ApiKeyConfig } from './components/ApiKeyConfig.vue'
// 导出指令
export { clickOutside } from './directives/clickOutside'
export { clickOutside } from './directives/clickOutside'
// 导出组合式函数
export { useToast } from './composables/useToast'
+2 -2
View File
@@ -173,9 +173,9 @@ import {
HistoryDrawer,
InputPanel,
Modal,
ApiKeyConfig
ApiKeyConfig,
useToast
} from '@prompt-optimizer/ui'
import { useToast } from './composables/useToast'
import { v4 as uuidv4 } from 'uuid'
// 初始化服务
-36
View File
@@ -1,36 +0,0 @@
import { ref } from 'vue'
const toasts = ref([])
export function useToast() {
const add = (message, type = 'info', duration = 3000) => {
const id = Date.now()
toasts.value.push({ id, message, type })
setTimeout(() => {
remove(id)
}, duration)
}
const remove = (id) => {
const index = toasts.value.findIndex(toast => toast.id === id)
if (index > -1) {
toasts.value.splice(index, 1)
}
}
const success = (message, duration) => add(message, 'success', duration)
const error = (message, duration) => add(message, 'error', duration)
const info = (message, duration) => add(message, 'info', duration)
const warning = (message, duration) => add(message, 'warning', duration)
return {
toasts,
add,
remove,
success,
error,
info,
warning
}
}
@@ -1,19 +0,0 @@
interface ExtendedHTMLElement extends HTMLElement {
_clickOutside?: (event: Event) => void
}
export const clickOutside = {
mounted(el: ExtendedHTMLElement, binding: { value: () => void }) {
el._clickOutside = (event: Event) => {
if (!(el === event.target || el.contains(event.target as Node))) {
binding.value()
}
}
document.addEventListener('click', el._clickOutside)
},
unmounted(el: ExtendedHTMLElement) {
if (el._clickOutside) {
document.removeEventListener('click', el._clickOutside)
}
}
}