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
fix(sheet): remove custom paste (#4503)
Dushusirecc82569dcc1
diff --git a/packages/sheets-ui/src/controllers/auto-fill.controller.ts b/packages/sheets-ui/src/controllers/auto-fill.controller.tsindex 0f3c719ca2..c91600a23d 100644--- a/packages/sheets-ui/src/controllers/auto-fill.controller.ts+++ b/packages/sheets-ui/src/controllers/auto-fill.controller.ts@@ -356,6 +356,8 @@ export class AutoFillController extends Disposable {copyDataInType.forEach((copySquad) => {const s = getLenS(copySquad.index, rsd);const len = copySquad.index.length * num + s;++ // We do not process cell.custom by default. If the user needs to process it, they can do so in the hook extension.const arrData = this._applyFunctions(copySquad,len,@@ -364,6 +366,7 @@ export class AutoFillController extends Disposable {customApplyFunctions,copyDataPiece);+const arrIndex = getDataIndex(csLen, asLen, copySquad.index);applyDataInTypes[type].push({ data: arrData, index: arrIndex });});diff --git a/packages/sheets-ui/src/controllers/clipboard/utils.ts b/packages/sheets-ui/src/controllers/clipboard/utils.tsindex 6f3c677acb..0deab5fb0d 100644--- a/packages/sheets-ui/src/controllers/clipboard/utils.ts+++ b/packages/sheets-ui/src/controllers/clipboard/utils.ts@@ -89,10 +89,7 @@ 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);+ // Do not process the custom attribute here, users can extend the paste event by themselves// clear and add mergeconst { undos: clearMergeUndos, redos: clearMergeRedos } = getClearAndSetMergeMutations(@@ -377,60 +374,6 @@ export function getSetCellValueMutations(};}-/**- *- * @param pasteTo- * @param pasteFrom- * @param matrix- * @param accessor- */-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,- };-}-/**** @param pasteTodiff --git a/packages/sheets-ui/src/services/auto-fill/tools.ts b/packages/sheets-ui/src/services/auto-fill/tools.tsindex 3731a1c8a9..e4f6f14e0e 100644--- a/packages/sheets-ui/src/services/auto-fill/tools.ts+++ b/packages/sheets-ui/src/services/auto-fill/tools.ts@@ -328,6 +328,8 @@ export function fillCopy(data: Array<Nullable<ICellData>>, len: number) {const index = (i - 1) % data.length;const d = Tools.deepClone(data[index]);+ removeCellCustom(d);+applyData.push({v: null,s: null,@@ -391,6 +393,8 @@ export function fillSeries(data: Array<Nullable<ICellData>>, len: number, directconst index = (i - 1) % data.length;const d = Tools.deepClone(data[index]);+ removeCellCustom(d);+const num = Number(data[data.length - 1]?.v) * (Number(data[1]?.v) / Number(data[0]?.v)) ** i;if (d) {@@ -406,6 +410,8 @@ export function fillSeries(data: Array<Nullable<ICellData>>, len: number, directconst index = (i - 1) % data.length;const d = Tools.deepClone(data[index]);+ removeCellCustom(d);+const forward = direction === Direction.DOWN || direction === Direction.RIGHT;const y = forecast(data.length + i, dataNumArr, xArr, forward);@@ -462,6 +468,8 @@ export function fillExtendNumber(data: Array<Nullable<ICellData>>, len: number,const index = (i - 1) % data.length;const d = Tools.deepClone(data[index]);+ removeCellCustom(d);+const last = `${data[data.length - 1]?.v}`;const match = last?.match(reg);const lastTxt = match?.[match.length - 1];@@ -487,6 +495,8 @@ export function fillOnlyFormat(data: Array<Nullable<ICellData>>, len: number) {const index = (i - 1) % data.length;const d = Tools.deepClone(data[index]);+ removeCellCustom(d);+if (d) {delete d.v;@@ -512,6 +522,8 @@ export function fillChnWeek(data: Array<Nullable<ICellData>>, len: number, step:const index = (i - 1) % data.length;const d = Tools.deepClone(data[index]);+ removeCellCustom(d);+let num = 0;if (data[data.length - 1]?.v === keyword[0]) {num = 7 + step * i;@@ -545,6 +557,8 @@ export function fillChnNumber(data: Array<Nullable<ICellData>>, len: number, steconst index = (i - 1) % data.length;const d = Tools.deepClone(data[index]);+ removeCellCustom(d);+const formattedValue = `${data[data.length - 1]?.v}`;const num = chineseToNumber(formattedValue) + step * i;let txt;@@ -620,6 +634,8 @@ export function fillLoopSeries(data: Array<Nullable<ICellData>>, len: number, stconst index = (i - 1) % data.length;const d = Tools.deepClone(data[index]);+ removeCellCustom(d);+const last = `${data[data.length - 1]?.v}`;let num = series.indexOf(last) + step * i;@@ -798,3 +814,13 @@ export function needsUpdateCellValue(cell: ICellData) {return true;}++/**+ * Remove cell.custom+ * @param cell+ */+export function removeCellCustom(cell: Nullable<ICellData>) {+ if (cell && 'custom' in cell) {+ delete cell.custom;+ }+}diff --git a/packages/sheets-ui/src/services/clipboard/type.ts b/packages/sheets-ui/src/services/clipboard/type.tsindex 497bff42ad..3227bc5d61 100644--- a/packages/sheets-ui/src/services/clipboard/type.ts+++ b/packages/sheets-ui/src/services/clipboard/type.ts@@ -75,48 +75,78 @@ export interface ISpecialPasteInfo {label: string;icon?: string;}+/*** `ClipboardHook` could:* 1. Before copy/cut/paste, decide whether to execute the command and prepare caches if necessary.- * 1. When copying, decide what content could be written into clipboard.- * 1. When pasting, get access to the clipboard content and append mutations to the paste command.+ * 2. When copying, decide what content could be written into clipboard.+ * 3. When pasting, get access to the clipboard content and append mutations to the paste command.*/export interface ISheetClipboardHook {+ /**+ * The unique id of the hook.+ */id: string;++ /**+ * Whether this hook is the default hook.+ */isDefaultHook?: boolean;- specialPasteInfo?: ISpecialPasteInfo; // only special paste info should be provided, which will replace the default hook.++ /**+ * Only special paste info should be provided, which will replace the default hook.+ */+ specialPasteInfo?: ISpecialPasteInfo;++ /**+ * The priority of the hook. The higher the priority, the earlier the hook would be called.+ */priority?: number;/*** The callback would be called after the clipboard service has decided what region need to be copied.* Features could use this hook to build copying cache or any other pre-copy jobs.+ * @param unitId+ * @param subUnitId+ * @param range*/onBeforeCopy?(unitId: string, subUnitId: string, range: IRange): void;+/**+ * Properties that would be appended to the td element.** @param row* @param col* @return content*/onCopyCellContent?(row: number, col: number): string;+/*** Properties that would be appended to the td element.** @deprecated should be merged with `onCopyCellContent` to `onCopyCell`* @param row row of the the copied cell* @param col col of the the copied cell+ * @param rowSpan row span of the the copied cell+ * @param colSpan col span of the the copied cell+ * @return content*/onCopyCellStyle?(row: number, col: number, rowSpan?: number, colSpan?: number): IClipboardPropertyItem | null;+/*** Properties that would be appended to the tr element.* @param row each row of the the copied range+ * @return content*/onCopyRow?(row: number): IClipboardPropertyItem | null;+/*** Properties that would be appended to the col element.* @param col each col of the copied range+ * @return content*/onCopyColumn?(col: number): IClipboardPropertyItem | null;+/*** Would be called after copy content has been written into clipboard.* Features could do some cleaning up jobs here.@@ -132,13 +162,19 @@ export interface ISheetClipboardHook {* The callback would be called after the clipboard service has decided what region need to be pasted.* Features could use this hook to build copying cache or any other pre-copy jobs.*+ * @param pasteTo* @returns if it block copying it should return false*/onBeforePaste?(pasteTo: ISheetDiscreteRangeLocation): boolean;+/**+ * Handles pasting cells, it needs to return Undo Mutations & Redo Mutations that handle the cell contents*- * @param row- * @param col+ * @param pasteFrom+ * @param pasteTo+ * @param data+ * @param payload+ * @returns undo and redo mutations*/onPasteCells?(pasteFrom: ISheetDiscreteRangeLocation | null,@@ -149,6 +185,15 @@ export interface ISheetClipboardHook {undos: IMutationInfo[];redos: IMutationInfo[];};++ /**+ * Handle the pasted row properties, it needs to return the Undo Mutations & Redo Mutations that handle the row properties+ *+ * @param pasteTo+ * @param rowProperties+ * @param payload+ * @returns undo and redo mutations+ */onPasteRows?(pasteTo: ISheetDiscreteRangeLocation,rowProperties: IClipboardPropertyItem[],@@ -157,6 +202,15 @@ export interface ISheetClipboardHook {undos: IMutationInfo[];redos: IMutationInfo[];};++ /**+ * Handle the pasted column properties, it needs to return the Undo Mutations & Redo Mutations that handle the column properties+ *+ * @param pasteTo+ * @param colProperties+ * @param payload+ * @returns undo and redo mutations+ */onPasteColumns?(pasteTo: ISheetDiscreteRangeLocation,colProperties: IClipboardPropertyItem[],@@ -165,6 +219,15 @@ export interface ISheetClipboardHook {undos: IMutationInfo[];redos: IMutationInfo[];};++ /**+ * Hanle the pasted plain text, it needs to return the Undo Mutations & Redo Mutations that handle the plain text+ *+ * @param pasteTo+ * @param text+ * @param payload+ * @returns undo and redo mutations+ */onPastePlainText?(pasteTo: ISheetDiscreteRangeLocation,text: string,@@ -173,6 +236,13 @@ export interface ISheetClipboardHook {undos: IMutationInfo[];redos: IMutationInfo[];};++ /**+ * Would be called after paste content has been written into Univer.+ * Features could do some cleaning up jobs here.+ *+ * @param success whether the paste operation is successful+ */onAfterPaste?(success: boolean): void;/**