update: 升级vben5.5.9到5.7.0

This commit is contained in:
2026-09-22 17:09:46 +08:00
parent 345e4a31f8
commit 802f72cd9e
766 changed files with 28468 additions and 15447 deletions
@@ -1,21 +0,0 @@
import { defineBuildConfig } from 'unbuild';
export default defineBuildConfig({
clean: true,
declaration: true,
entries: [
{
builder: 'mkdist',
input: './src',
loaders: ['vue'],
pattern: ['**/*.vue'],
},
{
builder: 'mkdist',
format: 'esm',
input: './src',
loaders: ['js'],
pattern: ['**/*.ts'],
},
],
});
@@ -1,6 +1,6 @@
{
"name": "@vben-core/popup-ui",
"version": "5.2.1",
"version": "5.7.0",
"homepage": "https://github.com/vbenjs/vue-vben-admin",
"bugs": "https://github.com/vbenjs/vue-vben-admin/issues",
"repository": {
@@ -11,7 +11,7 @@
"license": "MIT",
"type": "module",
"scripts": {
"build": "pnpm unbuild",
"build": "pnpm exec tsdown",
"prepublishOnly": "npm run build"
},
"files": [
@@ -22,16 +22,19 @@
],
"main": "./dist/index.mjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./src/index.ts",
"development": "./src/index.ts",
"production": "./src/index.ts",
"default": "./dist/index.mjs"
}
},
"publishConfig": {
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.mjs"
}
}
@@ -44,5 +47,8 @@
"@vben-core/typings": "workspace:*",
"@vueuse/core": "catalog:",
"vue": "catalog:"
},
"devDependencies": {
"unplugin-vue": "catalog:"
}
}
@@ -1 +0,0 @@
export { default } from '@vben/tailwind-config/postcss';
@@ -144,24 +144,26 @@ export async function vbenPrompt<T = any>(
const modelValue = ref<T | undefined>(defaultValue);
const inputComponentRef = ref<null | VNode>(null);
const staticContents: Component[] = [];
staticContents.push(h(VbenRenderContent, { content, renderBr: true }));
const staticContents: Component[] = [
h(VbenRenderContent, { content, renderBr: true }),
];
const modelPropName = _modelPropName || 'modelValue';
const componentProps = { ..._componentProps };
// 每次渲染时都会重新计算的内容函数
const contentRenderer = () => {
const currentProps = { ...componentProps };
const currentProps = {
...componentProps,
[modelPropName]: modelValue.value,
[`onUpdate:${modelPropName}`]: (val: T) => {
modelValue.value = val;
},
};
// 设置当前值
currentProps[modelPropName] = modelValue.value;
// 设置更新处理函数
currentProps[`onUpdate:${modelPropName}`] = (val: T) => {
modelValue.value = val;
};
// 创建输入组件
inputComponentRef.value = h(
@@ -147,9 +147,9 @@ async function handleOpenChange(val: boolean) {
:class="
cn(
containerClass,
'left-0 right-0 mx-auto flex max-h-[80%] flex-col p-0 duration-300 sm:w-[520px] sm:max-w-[80%] sm:rounded-[var(--radius)]',
'inset-x-0 mx-auto flex max-h-[80%] flex-col p-0 duration-300 sm:w-130 sm:max-w-[80%] sm:rounded-(--radius)',
{
'border-border border': bordered,
'border border-border': bordered,
'shadow-3xl': !bordered,
},
)
@@ -168,13 +168,13 @@ async function handleOpenChange(val: boolean) {
:disabled="loading"
@click="handleCancel"
>
<X class="text-muted-foreground size-4" />
<X class="size-4 text-muted-foreground" />
</VbenButton>
</AlertDialogCancel>
</div>
</AlertDialogTitle>
<AlertDialogDescription>
<div class="m-4 min-h-[30px]">
<div class="m-4 min-h-7.5">
<VbenRenderContent :content="content" render-br />
</div>
<VbenLoading v-if="loading && contentMasking" :spinning="loading" />
@@ -13,21 +13,20 @@ vi.mock('@vben-core/shared/store', () => {
return this._state;
}
private _state: DrawerState;
private subscribers: Array<(state: DrawerState) => void> = [];
private options: any;
constructor(initialState: DrawerState, options: any) {
constructor(initialState: DrawerState) {
this._state = initialState;
this.options = options;
}
batch(cb: () => void) {
cb();
}
setState(fn: (prev: DrawerState) => DrawerState) {
this._state = fn(this._state);
this.options.onUpdate();
this.subscribers.forEach((sub) => sub(this._state));
}
subscribe(fn: (state: DrawerState) => void) {
this.subscribers.push(fn);
return { unsubscribe: () => {} };
}
},
};
@@ -56,23 +56,18 @@ export class DrawerApi {
title: '',
};
this.store = new Store<DrawerState>(
{
...defaultState,
...storeState,
},
{
onUpdate: () => {
const state = this.store.state;
if (state?.isOpen === this.state?.isOpen) {
this.state = state;
} else {
this.state = state;
this.api.onOpenChange?.(!!state?.isOpen);
}
},
},
);
this.store = new Store<DrawerState>({
...defaultState,
...storeState,
});
this.store.subscribe((state) => {
const prevIsOpen = this.state?.isOpen;
this.state = state;
if (state?.isOpen !== prevIsOpen) {
this.api.onOpenChange?.(!!state?.isOpen);
}
});
this.state = this.store.state;
this.api = {
onBeforeClose,
@@ -75,7 +75,7 @@ export interface DrawerProps {
*/
headerClass?: ClassType;
/**
* 弹窗是否显示
* 抽屉加载状态
* @default false
*/
loading?: boolean;
@@ -54,6 +54,7 @@ const components = globalShareState.getComponents();
const id = useId();
provide('DISMISSABLE_DRAWER_ID', id);
// @ts-expect-error unused
const wrapperRef = ref<HTMLElement>();
const { $t } = useSimpleLocale();
const { isMobile } = useIsMobile();
@@ -184,9 +185,9 @@ const getForceMount = computed(() => {
<SheetContent
:append-to="getAppendTo"
:class="
cn('flex w-[520px] flex-col', drawerClass, {
'!w-full': isMobile || placement === 'bottom' || placement === 'top',
'max-h-[100vh]': placement === 'bottom' || placement === 'top',
cn('flex w-130 flex-col', drawerClass, {
'w-full!': isMobile || placement === 'bottom' || placement === 'top',
'max-h-screen': placement === 'bottom' || placement === 'top',
hidden: isClosed,
})
"
@@ -209,7 +210,7 @@ const getForceMount = computed(() => {
v-if="showHeader"
:class="
cn(
'!flex flex-row items-center justify-between border-b px-6 py-5',
'flex! flex-row items-center justify-between border-b px-6 py-5',
headerClass,
{
'px-4 py-3': closable,
@@ -223,7 +224,7 @@ const getForceMount = computed(() => {
v-if="closable && closeIconPlacement === 'left'"
as-child
:disabled="submitting"
class="data-[state=open]:bg-secondary ml-[2px] cursor-pointer rounded-full opacity-80 transition-opacity hover:opacity-100 focus:outline-none disabled:pointer-events-none"
class="ml-0.5 cursor-pointer rounded-full opacity-80 transition-opacity hover:opacity-100 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-secondary"
>
<slot name="close-icon">
<VbenIconButton>
@@ -233,7 +234,7 @@ const getForceMount = computed(() => {
</SheetClose>
<Separator
v-if="closable && closeIconPlacement === 'left'"
class="ml-1 mr-2 h-8"
class="mr-2 ml-1 h-8"
decorative
orientation="vertical"
/>
@@ -264,7 +265,7 @@ const getForceMount = computed(() => {
v-if="closable && closeIconPlacement === 'right'"
as-child
:disabled="submitting"
class="data-[state=open]:bg-secondary ml-[2px] cursor-pointer rounded-full opacity-80 transition-opacity hover:opacity-100 focus:outline-none disabled:pointer-events-none"
class="ml-0.5 cursor-pointer rounded-full opacity-80 transition-opacity hover:opacity-100 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-secondary"
>
<slot name="close-icon">
<VbenIconButton>
@@ -12,21 +12,20 @@ vi.mock('@vben-core/shared/store', () => {
return this._state;
}
private _state: ModalState;
private subscribers: Array<(state: ModalState) => void> = [];
private options: any;
constructor(initialState: ModalState, options: any) {
constructor(initialState: ModalState) {
this._state = initialState;
this.options = options;
}
batch(cb: () => void) {
cb();
}
setState(fn: (prev: ModalState) => ModalState) {
this._state = fn(this._state);
this.options.onUpdate();
this.subscribers.forEach((sub) => sub(this._state));
}
subscribe(fn: (state: ModalState) => void) {
this.subscribers.push(fn);
return { unsubscribe: () => {} };
}
},
};
@@ -46,6 +46,7 @@ export class ModalApi {
contentClass: '',
destroyOnClose: true,
draggable: false,
overflow: false,
footer: true,
footerClass: '',
fullscreen: false,
@@ -62,25 +63,19 @@ export class ModalApi {
animationType: 'slide',
};
this.store = new Store<ModalState>(
{
...defaultState,
...storeState,
},
{
onUpdate: () => {
const state = this.store.state;
this.store = new Store<ModalState>({
...defaultState,
...storeState,
});
// 每次更新状态时,都会调用 onOpenChange 回调函数
if (state?.isOpen === this.state?.isOpen) {
this.state = state;
} else {
this.state = state;
this.api.onOpenChange?.(!!state?.isOpen);
}
},
},
);
this.store.subscribe((state) => {
// 每次更新状态时,都会调用 onOpenChange 回调函数
const prevIsOpen = this.state?.isOpen;
this.state = state;
if (state?.isOpen !== prevIsOpen) {
this.api.onOpenChange?.(!!state?.isOpen);
}
});
this.state = this.store.state;
@@ -107,7 +102,6 @@ export class ModalApi {
this.store.setState((prev) => ({
...prev,
isOpen: false,
submitting: false,
}));
}
}
@@ -162,7 +156,11 @@ export class ModalApi {
}
open() {
this.store.setState((prev) => ({ ...prev, isOpen: true }));
this.store.setState((prev) => ({
...prev,
isOpen: true,
submitting: false,
}));
}
setData<T>(payload: T) {
@@ -1,6 +1,6 @@
import type { Component, Ref } from 'vue';
import type { MaybePromise } from '@vben-core/typings';
import type { ClassType, MaybePromise } from '@vben-core/typings';
import type { ModalApi } from './modal-api';
@@ -30,7 +30,7 @@ export interface ModalProps {
*/
centered?: boolean;
class?: string;
class?: ClassType;
/**
* 是否显示右上角的关闭按钮
@@ -60,7 +60,7 @@ export interface ModalProps {
* 确定按钮文字
*/
confirmText?: string;
contentClass?: string;
contentClass?: ClassType;
/**
* 弹窗描述
*/
@@ -79,7 +79,7 @@ export interface ModalProps {
* @default true
*/
footer?: boolean;
footerClass?: string;
footerClass?: ClassType;
/**
* 是否全屏
* @default false
@@ -95,9 +95,9 @@ export interface ModalProps {
* @default true
*/
header?: boolean;
headerClass?: string;
headerClass?: ClassType;
/**
* 弹窗是否显示
* 弹窗加载状态
* @default false
*/
loading?: boolean;
@@ -110,6 +110,11 @@ export interface ModalProps {
* 是否自动聚焦
*/
openAutoFocus?: boolean;
/**
* 拖动范围是否可以超出可视区
* @default false
*/
overflow?: boolean;
/**
* 弹窗遮罩模糊效果
*/
@@ -50,9 +50,11 @@ const props = withDefaults(defineProps<Props>(), {
const components = globalShareState.getComponents();
const contentRef = ref();
// @ts-expect-error unused
const wrapperRef = ref<HTMLElement>();
const dialogRef = ref();
const headerRef = ref();
// @ts-expect-error unused
const footerRef = ref();
const id = useId();
@@ -79,6 +81,7 @@ const {
description,
destroyOnClose,
draggable,
overflow,
footer: showFooter,
footerClass,
fullscreen,
@@ -104,6 +107,10 @@ const shouldDraggable = computed(
() => draggable.value && !shouldFullscreen.value && header.value,
);
const shouldCentered = computed(
() => centered.value && !shouldFullscreen.value,
);
const getAppendTo = computed(() => {
return appendToMain.value
? `#${ELEMENT_ID_MAIN_CONTENT}>div:not(.absolute)>div`
@@ -115,6 +122,8 @@ const { dragging, transform } = useModalDraggable(
headerRef,
shouldDraggable,
getAppendTo,
shouldCentered,
overflow,
);
const firstOpened = ref(false);
@@ -132,7 +141,9 @@ watch(
dialogRef.value = innerContentRef.$el;
// reopen modal reassign value
const { offsetX, offsetY } = transform;
dialogRef.value.style.transform = `translate(${offsetX}px, ${offsetY}px)`;
dialogRef.value.style.transform = shouldCentered.value
? `translate(${offsetX}px, calc(-50% + ${offsetY}px))`
: `translate(${offsetX}px, ${offsetY}px)`;
}
},
{ immediate: true },
@@ -180,7 +191,7 @@ function escapeKeyDown(e: KeyboardEvent) {
}
}
function handerOpenAutoFocus(e: Event) {
function handleOpenAutoFocus(e: Event) {
if (!openAutoFocus.value) {
e?.preventDefault();
}
@@ -209,6 +220,12 @@ const getForceMount = computed(() => {
return !unref(destroyOnClose) && unref(firstOpened);
});
const handleOpened = () => {
requestAnimationFrame(() => {
props.modalApi?.onOpened();
});
};
function handleClosed() {
isClosed.value = true;
props.modalApi?.onClosed();
@@ -225,15 +242,15 @@ function handleClosed() {
:append-to="getAppendTo"
:class="
cn(
'left-0 right-0 top-[10vh] mx-auto flex max-h-[80%] w-[520px] flex-col p-0',
shouldFullscreen ? 'sm:rounded-none' : 'sm:rounded-[var(--radius)]',
'inset-x-0 top-[10vh] mx-auto flex max-h-[80%] w-130 flex-col p-0',
shouldFullscreen ? 'sm:rounded-none' : 'sm:rounded-(--radius)',
modalClass,
{
'border-border border': bordered,
'border border-border': bordered,
'shadow-3xl': !bordered,
'left-0 top-0 size-full max-h-full !translate-x-0 !translate-y-0':
'top-0 left-0 size-full max-h-full transform-[translate(0,0)]!':
shouldFullscreen,
'top-1/2 !-translate-y-1/2': centered && !shouldFullscreen,
'top-1/2': centered && !shouldFullscreen,
'duration-300': !dragging,
hidden: isClosed,
},
@@ -253,8 +270,8 @@ function handleClosed() {
@escape-key-down="escapeKeyDown"
@focus-outside="handleFocusOutside"
@interact-outside="interactOutside"
@open-auto-focus="handerOpenAutoFocus"
@opened="() => modalApi?.onOpened()"
@open-auto-focus="handleOpenAutoFocus"
@opened="handleOpened"
@pointer-down-outside="pointerDownOutside"
>
<DialogHeader
@@ -303,24 +320,18 @@ function handleClosed() {
<slot></slot>
</div>
<VbenLoading v-if="showLoading || submitting" spinning />
<!-- 关闭按钮左侧:全屏 + 自定义操作;从右到左为 关闭 | 自定义 | 全屏 -->
<div
class="absolute right-10 top-3 hidden items-center gap-1 sm:flex"
<VbenIconButton
v-if="fullscreenButton"
class="absolute top-3 right-10 flex-center hidden size-6 rounded-full px-1 text-lg text-foreground/80 opacity-70 transition-opacity hover:bg-accent hover:text-accent-foreground hover:opacity-100 focus:outline-hidden disabled:pointer-events-none sm:block"
@click="handleFullscreen"
>
<VbenIconButton
v-if="fullscreenButton"
class="hover:bg-accent hover:text-accent-foreground text-foreground/80 flex-center size-6 rounded-full px-1 text-lg opacity-70 transition-opacity hover:opacity-100 focus:outline-none disabled:pointer-events-none"
@click="handleFullscreen"
>
<Shrink v-if="fullscreen" class="size-3.5" />
<Expand v-else class="size-3.5" />
</VbenIconButton>
<slot name="header-actions"></slot>
</div>
<Shrink v-if="fullscreen" class="size-3.5" />
<Expand v-else class="size-3.5" />
</VbenIconButton>
<DialogFooter
v-if="showFooter"
ref="footerRef"
v-if="showFooter"
:class="
cn(
'flex-row items-center justify-end p-2',
@@ -14,6 +14,8 @@ export function useModalDraggable(
dragRef: Ref<HTMLElement | undefined>,
draggable: ComputedRef<boolean>,
containerSelector?: ComputedRef<string | undefined>,
centered?: ComputedRef<boolean>,
overflow?: ComputedRef<boolean>,
) {
const transform = reactive({
offsetX: 0,
@@ -66,14 +68,19 @@ export function useModalDraggable(
let moveX = offsetX + e.clientX - downX;
let moveY = offsetY + e.clientY - downY;
moveX = Math.min(Math.max(moveX, minLeft), maxLeft);
moveY = Math.min(Math.max(moveY, minTop), maxTop);
if (!overflow?.value) {
moveX = Math.min(Math.max(moveX, minLeft), maxLeft);
moveY = Math.min(Math.max(moveY, minTop), maxTop);
}
transform.offsetX = moveX;
transform.offsetY = moveY;
if (targetRef.value) {
targetRef.value.style.transform = `translate(${moveX}px, ${moveY}px)`;
const isCentered = centered?.value;
targetRef.value.style.transform = isCentered
? `translate(${moveX}px, calc(-50% + ${moveY}px))`
: `translate(${moveX}px, ${moveY}px)`;
dragging.value = true;
}
};
@@ -108,7 +115,7 @@ export function useModalDraggable(
const target = unrefElement(targetRef);
if (target) {
target.style.transform = 'none';
target.style.transform = '';
}
};
@@ -41,6 +41,7 @@ export function useVbenModal<TParentModalProps extends ModalProps = ModalProps>(
// 不能用 Object.assign,会丢失 api 的原型函数
Object.setPrototypeOf(extendedApi, api);
},
consumed: false,
options,
async reCreateModal() {
isModalReady.value = false;
@@ -73,7 +74,13 @@ export function useVbenModal<TParentModalProps extends ModalProps = ModalProps>(
return [Modal, extendedApi as ExtendedModalApi] as const;
}
const injectData = inject<any>(USER_MODAL_INJECT_KEY, {});
let injectData = inject<any>(USER_MODAL_INJECT_KEY, {});
// 这个数据已经被使用了,说明这个弹窗是嵌套的弹窗,不应该merge上层的配置
if (injectData.consumed) {
injectData = {};
} else {
injectData.consumed = true;
}
const mergedOptions = {
...DEFAULT_MODAL_PROPS,
@@ -90,6 +97,7 @@ export function useVbenModal<TParentModalProps extends ModalProps = ModalProps>(
mergedOptions.onClosed = () => {
onClosed?.();
if (mergedOptions.destroyOnClose) {
injectData.consumed = false;
injectData.reCreateModal?.();
}
};
@@ -1 +0,0 @@
export { default } from '@vben/tailwind-config';
@@ -0,0 +1,21 @@
import { defineConfig } from 'tsdown';
import Vue from 'unplugin-vue/rolldown';
export default defineConfig({
clean: true,
deps: {
skipNodeModulesBundle: true,
},
dts: {
vue: true,
},
entry: ['src/index.ts'],
format: ['esm'],
outExtensions: () => ({
dts: '.d.ts',
js: '.mjs',
}),
platform: 'neutral',
plugins: [Vue({ isProduction: true })],
unbundle: true,
});