improve: history stack memory
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
import { cloneProperty, deepClone, getUUID, isArrayEqual, splitText } from '.'
|
||||
import {
|
||||
cloneProperty,
|
||||
deepClone,
|
||||
deepCloneOmitKeys,
|
||||
getUUID,
|
||||
isArrayEqual,
|
||||
splitText
|
||||
} from '.'
|
||||
import {
|
||||
ElementType,
|
||||
IEditorOption,
|
||||
@@ -28,6 +35,7 @@ import {
|
||||
} from '../dataset/constant/Title'
|
||||
import { ControlComponent, ControlType } from '../dataset/enum/Control'
|
||||
import { DeepRequired } from '../interface/Common'
|
||||
import { IRowElement } from '../interface/Row'
|
||||
import { ITd } from '../interface/table/Td'
|
||||
import { ITr } from '../interface/table/Tr'
|
||||
|
||||
@@ -1169,3 +1177,10 @@ export function getTextFromElementList(elementList: IElement[]) {
|
||||
}
|
||||
return buildText(zipElementList(elementList))
|
||||
}
|
||||
|
||||
export function getSlimCloneElementList(elementList: IElement[]) {
|
||||
return deepCloneOmitKeys<IElement[], IRowElement>(elementList, [
|
||||
'metrics',
|
||||
'style'
|
||||
])
|
||||
}
|
||||
|
||||
@@ -31,6 +31,23 @@ export function throttle(func: Function, delay: number) {
|
||||
}
|
||||
}
|
||||
|
||||
export function deepCloneOmitKeys<T, K>(obj: T, omitKeys: (keyof K)[]): T {
|
||||
if (!obj || typeof obj !== 'object') {
|
||||
return obj
|
||||
}
|
||||
let newObj: any = {}
|
||||
if (Array.isArray(obj)) {
|
||||
newObj = obj.map(item => deepCloneOmitKeys(item, omitKeys))
|
||||
} else {
|
||||
// prettier-ignore
|
||||
(Object.keys(obj) as (keyof K)[]).forEach(key => {
|
||||
if (omitKeys.includes(key)) return
|
||||
return (newObj[key] = deepCloneOmitKeys((obj[key as unknown as keyof T] ), omitKeys))
|
||||
})
|
||||
}
|
||||
return newObj
|
||||
}
|
||||
|
||||
export function deepClone<T>(obj: T): T {
|
||||
if (!obj || typeof obj !== 'object') {
|
||||
return obj
|
||||
@@ -39,8 +56,8 @@ export function deepClone<T>(obj: T): T {
|
||||
if (Array.isArray(obj)) {
|
||||
newObj = obj.map(item => deepClone(item))
|
||||
} else {
|
||||
Object.keys(obj as any).forEach(key => {
|
||||
// @ts-ignore
|
||||
// prettier-ignore
|
||||
(Object.keys(obj) as (keyof T)[]).forEach(key => {
|
||||
return (newObj[key] = deepClone(obj[key]))
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user