Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
chore: support paste custom (#3538)
ybzkyb0a23bd84a69
diff --git a/packages/sheets-ui/src/controllers/clipboard/utils.ts b/packages/sheets-ui/src/controllers/clipboard/utils.tsindex 38f8cbd497..bdb92b79ba 100644--- a/packages/sheets-ui/src/controllers/clipboard/utils.ts+++ b/packages/sheets-ui/src/controllers/clipboard/utils.ts@@ -14,15 +14,8 @@* limitations under the License.*/-import type { IAccessor, ICellData, ICustomRange, IDocumentBody, IMutationInfo, IParagraph, IRange, Nullable } from '@univerjs/core';import { cellToRange, CustomRangeType, DataStreamTreeTokenType, DEFAULT_STYLES, generateRandomId, IUniverInstanceService, numfmt, ObjectMatrix, Range, Rectangle, Tools } from '@univerjs/core';-import type {- IAddWorksheetMergeMutationParams,- IMoveRangeMutationParams,- IRemoveWorksheetMergeMutationParams,- ISetRangeValuesMutationParams,- ISetSelectionsOperationParams,-} from '@univerjs/sheets';+import { DEFAULT_PADDING_DATA } from '@univerjs/engine-render';import {AddMergeUndoMutationFactory,AddWorksheetMergeMutation,@@ -36,11 +29,18 @@ import {SetSelectionsOperation,SheetInterceptorService,} from '@univerjs/sheets';+import type { IAccessor, ICellData, ICustomRange, IDocumentBody, IMutationInfo, IParagraph, IRange, Nullable } from '@univerjs/core';-import { DEFAULT_PADDING_DATA } from '@univerjs/engine-render';-import type { ICellDataWithSpanInfo, ICopyPastePayload, ISheetDiscreteRangeLocation } from '../../services/clipboard/type';+import type {+ IAddWorksheetMergeMutationParams,+ IMoveRangeMutationParams,+ IRemoveWorksheetMergeMutationParams,+ ISetRangeValuesMutationParams,+ ISetSelectionsOperationParams,+} from '@univerjs/sheets';import { COPY_TYPE } from '../../services/clipboard/type';import { discreteRangeToRange, type IDiscreteRange, virtualizeDiscreteRanges } from '../utils/range-tools';+import type { ICellDataWithSpanInfo, ICopyPastePayload, ISheetDiscreteRangeLocation } from '../../services/clipboard/type';// if special paste need append mutations instead of replace the default, it can use this function to generate default mutations.export function getDefaultOnPasteCellMutations(@@ -72,6 +72,11 @@ export function getDefaultOnPasteCellMutations(redoMutationsInfo.push(...setStyleRedos);undoMutationsInfo.push(...setStyleUndos);+ // set custom+ const { undos: setCustomUndos, redos: setCustomRedos } = getSetCellCustomMutations(pasteTo, pasteFrom, data, accessor);+ redoMutationsInfo.push(...setCustomRedos);+ undoMutationsInfo.push(...setCustomUndos);+// clear and add mergeconst { undos: clearMergeUndos, redos: clearMergeRedos } = getClearAndSetMergeMutations(pasteTo,@@ -337,6 +342,53 @@ export function getSetCellValueMutations(};}+export function getSetCellCustomMutations(+ pasteTo: ISheetDiscreteRangeLocation,+ pasteFrom: Nullable<ISheetDiscreteRangeLocation>,+ matrix: ObjectMatrix<ICellDataWithSpanInfo>,+ accessor: IAccessor+) {+ const { unitId, subUnitId, range } = pasteTo;+ const redoMutationsInfo: IMutationInfo[] = [];+ const undoMutationsInfo: IMutationInfo[] = [];+ const { mapFunc } = virtualizeDiscreteRanges([range]);+ const valueMatrix = new ObjectMatrix<ICellData>();++ matrix.forValue((row, col, value) => {+ const { row: realRow, col: realCol } = mapFunc(row, col);++ if (value.custom) {+ valueMatrix.setValue(realRow, realCol, Tools.deepClone({ custom: value.custom }));+ }+ });++ const setCustomMutation: ISetRangeValuesMutationParams = {+ unitId,+ subUnitId,+ cellValue: Tools.deepClone(valueMatrix.getMatrix()),+ };++ redoMutationsInfo.push({+ id: SetRangeValuesMutation.id,+ params: setCustomMutation,+ });++ // undo+ const undoSetValuesMutation: ISetRangeValuesMutationParams = SetRangeValuesUndoMutationFactory(+ accessor,+ setCustomMutation+ );++ undoMutationsInfo.push({+ id: SetRangeValuesMutation.id,+ params: undoSetValuesMutation,+ });+ return {+ undos: undoMutationsInfo,+ redos: redoMutationsInfo,+ };+}+export function getSetCellStyleMutations(pasteTo: ISheetDiscreteRangeLocation,matrix: ObjectMatrix<ICellDataWithSpanInfo>,