diff --git a/packages/ui/src/utils/clone-deep.ts b/packages/ui/src/utils/clone-deep.ts index 09003946e6..7d568f4f2d 100644 --- a/packages/ui/src/utils/clone-deep.ts +++ b/packages/ui/src/utils/clone-deep.ts @@ -15,6 +15,18 @@ export const cloneDeep = (source: T): T => { return new Date(source.getTime()) as any } + if (source instanceof RegExp) { + return new RegExp(source.source, source.flags) as any + } + + if (source instanceof Map) { + return new Map(Array.from(source.entries()).map(([key, value]) => [key, cloneDeep(value)])) as any + } + + if (source instanceof Set) { + return new Set(Array.from(source.values()).map(cloneDeep)) as any + } + if (isObject(source)) { return Object.keys(source).reduce((acc, key) => { acc[key] = cloneDeep(source[key as keyof T]) diff --git a/packages/ui/src/utils/merge-deep.ts b/packages/ui/src/utils/merge-deep.ts index d50ac47eec..09aa2c9d5a 100644 --- a/packages/ui/src/utils/merge-deep.ts +++ b/packages/ui/src/utils/merge-deep.ts @@ -13,7 +13,9 @@ export const mergeDeep = (target: any, source: any): any => { const targetValue = target[key] const sourceValue = source[key] - if (isObject(targetValue) && isObject(sourceValue)) { + if (sourceValue instanceof RegExp || sourceValue instanceof Date) { + target[key] = sourceValue + } else if (isObject(targetValue) && isObject(sourceValue)) { target[key] = mergeDeep(Object.create( Object.getPrototypeOf(targetValue), Object.getOwnPropertyDescriptors(targetValue),