Merge branch 'fork/xingyu4j/antdv-next'

This commit is contained in:
Jin Mao
2026-05-19 14:14:28 +08:00
168 changed files with 4489 additions and 4284 deletions

View File

@@ -87,7 +87,7 @@ class IndexedDBDriver implements IStorageDriver {
});
}
async setItem<T>(key: string, value: T): Promise<void> {
async setItem(key: string, value: unknown): Promise<void> {
const db = await this.getDB();
return new Promise((resolve, reject) => {
const tx = db.transaction(this.storeName, 'readwrite');

View File

@@ -62,7 +62,7 @@ class LocalStorageDriver implements IStorageDriver {
this.storage.removeItem(key);
}
async setItem<T>(key: string, value: T): Promise<void> {
async setItem(key: string, value: unknown): Promise<void> {
this.storage.setItem(key, JSON.stringify(value));
}
}

View File

@@ -24,7 +24,7 @@ class MemoryStorageDriver implements IStorageDriver {
this.store.delete(key);
}
async setItem<T>(key: string, value: T): Promise<void> {
async setItem(key: string, value: unknown): Promise<void> {
this.store.set(key, value);
}
}

View File

@@ -106,10 +106,10 @@ class StorageManager {
* @param value 值
* @param ttl 存活时间(毫秒)
*/
async setItem<T>(key: string, value: T, ttl?: number): Promise<void> {
async setItem(key: string, value: unknown, ttl?: number): Promise<void> {
const fullKey = this.getFullKey(key);
const expiry = ttl ? Date.now() + ttl : undefined;
const item: StorageItem<T> = { expiry, value };
const item: StorageItem<unknown> = { expiry, value };
await this.driver.setItem(fullKey, item);
}

View File

@@ -17,7 +17,7 @@ interface IStorageDriver {
removeItem(key: string): Promise<void>;
/** 设置存储项 */
setItem<T>(key: string, value: T): Promise<void>;
setItem(key: string, value: unknown): Promise<void>;
}
/**

View File

@@ -34,7 +34,9 @@ describe('stateHandler', () => {
}, 10);
// 等待过程中,期望 Promise 被 reject
await expect(handler.waitForCondition()).rejects.toThrow();
await expect(handler.waitForCondition()).rejects.toThrow(
'Condition was set to false',
);
expect(handler.isConditionTrue()).toBe(false);
});

View File

@@ -138,8 +138,10 @@ describe('getNestedValue', () => {
expect(result).toBe(2);
});
it('should return the entire object if path is empty', () => {
expect(() => getNestedValue(data, '')()).toThrow();
it('should throw if path is empty', () => {
expect(() => getNestedValue(data, '')).toThrow(
'Path must be a non-empty string',
);
});
it('should handle paths with array indexes', () => {

View File

@@ -1,6 +1,6 @@
export class StateHandler {
private condition: boolean = false;
private rejectCondition: (() => void) | null = null;
private rejectCondition: ((reason?: Error) => void) | null = null;
private resolveCondition: (() => void) | null = null;
isConditionTrue(): boolean {
@@ -16,7 +16,7 @@ export class StateHandler {
setConditionFalse() {
this.condition = false;
if (this.rejectCondition) {
this.rejectCondition();
this.rejectCondition(new Error('Condition was set to false'));
this.clearPromises();
}
}

View File

@@ -180,11 +180,7 @@ class PreferenceManager {
* 更新扩展偏好设置
* @param updates - 要更新的扩展偏好设置
*/
updateCustomPreferences = <
TCustomPreferences extends object = CustomPreferencesRecord,
>(
updates: DeepPartial<TCustomPreferences>,
) => {
updateCustomPreferences = (updates: DeepPartial<object>) => {
if (!this.customPreferencesExtension) {
return;
}

View File

@@ -66,6 +66,7 @@ function findPlaceholderPos(doc: ProseMirrorNode, blobUrl: string): number {
found = offset;
return false;
}
return true;
});
return found;
}

View File

@@ -1,3 +1,4 @@
/* eslint-disable unicorn/no-nested-ternary */
import type { VxeGridProps as VxeTableGridProps } from 'vxe-table';
import type {
@@ -182,13 +183,11 @@ export function useViewedRow<T = any>(
options: ViewedRowOptions<T> & { keyField: string },
) {
// ========== 解析持久化配置 ==========
let persistOpts: null | ViewedRowPersistOptions = null;
if (options.persist) {
persistOpts =
typeof options.persist === 'string'
? { key: options.persist, type: 'localStorage' }
: options.persist;
}
const persistOpts: null | ViewedRowPersistOptions = options.persist
? typeof options.persist === 'string'
? { key: options.persist, type: 'localStorage' }
: options.persist
: null;
const adapter = createStorageAdapter(options.persist);
const maxSize = persistOpts?.maxSize ?? 100;
@@ -521,12 +520,12 @@ export function applyViewedRowOptions(
};
// 拦截 CellOperation columns
let actionCodes: string[] = [];
if (!isBoolean(viewedRowConfig) && viewedRowConfig.actionCodes) {
actionCodes = Array.isArray(viewedRowConfig.actionCodes)
? viewedRowConfig.actionCodes
: [viewedRowConfig.actionCodes];
}
const actionCodes =
!isBoolean(viewedRowConfig) && viewedRowConfig.actionCodes
? Array.isArray(viewedRowConfig.actionCodes)
? viewedRowConfig.actionCodes
: [viewedRowConfig.actionCodes]
: [];
if (actionCodes.length > 0 && Array.isArray(mergedOptions.columns)) {
mergedOptions.columns = wrapColumnsForViewedRow(

View File

@@ -50,24 +50,18 @@ describe('requestClient', () => {
it('should handle network errors', async () => {
mock.onGet('/test/error').networkError();
try {
await requestClient.get('/test/error');
expect(true).toBe(false);
} catch (error: any) {
expect(error.isAxiosError).toBe(true);
expect(error.message).toBe('Network Error');
}
await expect(requestClient.get('/test/error')).rejects.toMatchObject({
isAxiosError: true,
message: 'Network Error',
});
});
it('should handle timeout', async () => {
mock.onGet('/test/timeout').timeout();
try {
await requestClient.get('/test/timeout');
expect(true).toBe(false);
} catch (error: any) {
expect(error.isAxiosError).toBe(true);
expect(error.code).toBe('ECONNABORTED');
}
await expect(requestClient.get('/test/timeout')).rejects.toMatchObject({
isAxiosError: true,
code: 'ECONNABORTED',
});
});
it('should successfully upload a file', async () => {
@@ -92,7 +86,7 @@ describe('requestClient', () => {
mock.onGet('/test/download').reply(200, mockFileContent);
const res = await requestClient.download('/test/download');
const res = await requestClient.download<any>('/test/download');
expect(res.data).toBeInstanceOf(Blob);
});