UNPKG

@univerjs-pro/sheets-pivot

Version:

Pivot table integration for Univer Sheets.

784 lines (783 loc) • 24.8 kB
import type { DataField, FieldsCollection, IBaseGroupFieldJSON, IDataFieldManagerBaseJSON, IFieldsCollectionJSON, ILabelViewHeaderMapItem, IPivotTableChangeSet, IPivotTableFilterInfo, IPivotTableLabelFieldJSON, IPivotTableOptions, IPivotTableSnapshot, IPivotTableSortInfo, IPivotTableValueFieldJSON, IPivotTableValueFilter, IPivotViewInfo, IPivotViewJSON, IPivotViewValueType, PivotCellStyleTypeEnum, PivotDataFieldDataTypeEnum, PivotSubtotalTypeEnum, PivotTableChangeTypeEnum, PivotTableFiledAreaEnum, PivotTableValuePositionEnum, PivotView } from '@univerjs-pro/engine-pivot'; import type { CellValueType, ICellData, IRange, IStyleData, IUndoRedoCommandInfosByInterceptor, IUnitRangeName, Nullable, ObjectMatrix } from '@univerjs/core'; import type { PivotDisplayDataType, PositionType } from './const'; export interface IPivotPerformCheckParams { cellInfo: IPivotCellPositionInfo; view: PivotView; isEmpty: boolean; } export type IPivotGeneratedMutationsParams = IPivotPerformCheckParams; export declare const PIVOT_PERFORM_CHECK: import("@univerjs/core").IAsyncInterceptor<boolean, IPivotPerformCheckParams>; export declare const PIVOT_MUTATION_GENERATE: import("@univerjs/core").IInterceptor<IUndoRedoCommandInfosByInterceptor, IPivotPerformCheckParams>; export interface IPivotTableConfigChangeInfo { unitId: string; subUnitId: string; type: PivotTableOperationEnum; pivotTableId: string; view?: Nullable<PivotView>; } export declare enum CollectionChangeEnum { add = "add", delete = "delete", update = "update" } export type IUnitRangeNameWithSubUnitId = IUnitRangeName & { subUnitId: string; }; export interface ICollectionChangeInfo { token: string; type: CollectionChangeEnum; dataRangeInfo?: IUnitRangeNameWithSubUnitId; unitId?: string; subUnitId?: string; targetCellInfo?: IPivotCellPositionInfo; oldSourceRangeInfo?: IUnitRangeNameWithSubUnitId; } export interface IAddPivotTableParams { pivotTableConfig: IPivotTableConfig; } export interface IUpdatePivotTableSourceRangeMutationParams { pivotTableId: string; deleteIds: string[]; collectionJSON: IFieldsCollectionJSON; dataRangeInfo: IUnitRangeNameWithSubUnitId; unitId: string; subUnitId: string; } export interface IAddPivotTableMutationParams { unitId: string; subUnitId: string; pivotTableId: string; pivotTableConfig: IPivotTableConfig; collectionConfig: IFieldsCollectionJSON; } export interface IAddPivotGroupCollectionMutationParams { unitId: string; subUnitId: string; pivotTableId: string; fieldJSON: IBaseGroupFieldJSON; } export interface IRemovePivotGroupCollectionMutationParams { unitId: string; subUnitId: string; pivotTableId: string; dataFieldId: string; } export interface IAddPivotFieldMutationParams { unitId: string; subUnitId: string; pivotTableId: string; fieldJson: IPivotTableValueFieldJSON | IPivotTableLabelFieldJSON; area: PivotTableFiledAreaEnum; index: number; } export interface IRemovePivotFieldMutationParams { unitId: string; subUnitId: string; pivotTableId: string; fieldId: string; area: PivotTableFiledAreaEnum; index: number; } export interface IRenamePivotFieldMutationParams { unitId: string; subUnitId: string; pivotTableId: string; name: string; fieldId: string; } export interface ISetPivotSortMutationParams { unitId: string; subUnitId: string; pivotTableId: string; fieldId: string; sortInfo: IPivotTableSortInfo | undefined; } export interface ISetPivotOptionMutationParams { unitId: string; subUnitId: string; pivotTableId: string; options: IPivotTableOptions; } export interface ISetPivotFieldFormatMutationParams { unitId: string; subUnitId: string; pivotTableId: string; fieldId: string; format: string | undefined; } export interface IUpdateFieldPositionMutationParams { unitId: string; subUnitId: string; pivotTableId: string; fieldId: string; area: PivotTableFiledAreaEnum; index: number; oldArea: PivotTableFiledAreaEnum; oldIndex: number; } export interface IUpdateValuePositionMutationParams { unitId: string; subUnitId: string; pivotTableId: string; valuePosition: PivotTableValuePositionEnum; index: number; } export interface IUpdatePivotFieldSourceInfoMutationParams { unitId: string; subUnitId: string; pivotTableId: string; dataFieldId: string; sourceName: string; tableFieldId: string; } export interface ISetPivotSubtotalTypeMutationParams { unitId: string; subUnitId: string; pivotTableId: string; fieldId: string; subtotalType: PivotSubtotalTypeEnum; } export interface ISetPivotFilterMutationParams { unitId: string; subUnitId: string; pivotTableId: string; fieldId: string; filterInfo: IPivotTableFilterInfo; isAll?: boolean; } export interface ISetPivotValueFilterMutationParams { unitId: string; subUnitId: string; pivotTableId: string; fieldId: string; filterInfo: IPivotTableValueFilter | undefined; } export interface ISetPivotCollapseMutation { unitId: string; subUnitId: string; pivotTableId: string; fieldId: string; collapse: boolean; item?: string; } export interface IAdjustPivotTableRes { valueMatrix: ObjectMatrix<Nullable<IPivotTableCellData>>; rowInfo: Record<string, IPivotViewInfo>; colInfo: Record<string, IPivotViewInfo>; cornerInfo: Record<string, IPivotViewInfo>; rowHeaderMap: Record<string, ILabelViewHeaderMapItem>; colHeaderMap: Record<string, ILabelViewHeaderMapItem>; } export interface IThemeStyle { rowStyle?: IStyleData; colStyle?: IStyleData; cornerStyle?: IStyleData; pageStyle?: IStyleData; dataStyle?: IStyleData; blankStyle?: IStyleData; subTotalStyle?: IStyleData; leafStyle?: IStyleData; grandTotal?: IStyleData; } export interface IPivotTableFieldsConfig { dim: unknown; } export interface IPivotCellPositionInfo { row: number; col: number; unitId: string; subUnitId: string; sheetName?: string; } export interface IPivotTableConfig { targetCellInfo: IPivotCellPositionInfo; sourceRangeInfo: IUnitRangeNameWithSubUnitId; themeId?: string; fieldsConfig: IPivotTableSnapshot; isEmpty: boolean; } export type IPivotTableConfigModel = Map<string, Map<string, Map<string, IPivotTableConfig>>>; export type IPivotWorkerCache = Map<string, Map<string, Map<string, IPivotWorkerItemCache>>>; export interface IPivotWorkerItemCache { rangeCache?: IPivotRangesInfo; matrix?: ObjectMatrix<Nullable<IPivotTableCellData>>; oldRangeCache?: IPivotRangesInfo; oldMatrix?: ObjectMatrix<Nullable<IPivotTableCellData>>; } export interface IPivotTableRangeInfo { rangeInfo?: IPivotRangesInfo; oldRangeInfo?: IPivotRangesInfo; } export interface IPivotTableMatrixInfo { matrix: ObjectMatrix<Nullable<IPivotTableCellData>>; oldMatrix?: ObjectMatrix<Nullable<IPivotTableCellData>>; } /** * The pivot table view change operation type. */ export declare enum PivotTableOperationEnum { /** * A pivot table added to the sheet cells. */ Add = "add", /** * A pivot table updated in the sheet cells, maybe the range of the pivot table changed or the values of the pivot table cell changed. */ Set = "set", /** * A pivot table removed from the sheet cells. */ Delete = "delete" } export interface IPivotTableCellData { v?: IPivotViewValueType; /** * pivot button type */ pbt?: PivotCellStyleTypeEnum; s?: string | IStyleData; /** * filter index */ fi?: number; t?: CellValueType; } export interface IDataFieldManagerJSON extends IDataFieldManagerBaseJSON { dataRanges: Record<string, IUnitRangeName>; } export interface IPivotTableJson { dataFieldManagerConfig: Record<string, IDataFieldManagerJSON>; pivotTableConfigs: Record<string, Record<string, Record<string, IPivotTableConfig>>>; } export type IRangePosition = 'row' | 'col' | 'corner' | 'data'; export interface IPivotRenderCache { areaInfo?: IPivotAreaViewInfo; rangesInfo?: IPivotRangesInfo; headerMap?: IPivotHeaderMap; } export interface IPivotAreaViewInfo { rowInfo: Record<string, IPivotViewInfo>; colInfo: Record<string, IPivotViewInfo>; cornerInfo: Record<string, IPivotViewInfo>; } export interface IPivotRangesInfo { rowRanges: IRange[]; colRanges: IRange[]; cornerRanges: IRange[]; dataRanges: IRange[]; pageRanges: IRange[]; } export interface IPivotHeaderMap { rowHeaderMap: Record<string, ILabelViewHeaderMapItem>; colHeaderMap: Record<string, ILabelViewHeaderMapItem>; } export interface ISetPivotPositionMutationParams { unitId: string; subUnitId: string; pivotTableId: string; targetCellPosition: { row: number; col: number; }; } export interface IRemovePivotTableMutationParams { unitId: string; subUnitId: string; pivotTableId: string; } export interface IPivotTableViewDirtyMarkOperationParams { [unitId: string]: { [sunUnitId: string]: { [token: string]: boolean; }; }; } export interface ISheetPivotPluginConfig { isPivotTableWorkerMode: boolean; } export interface IPivotMutationDirtyViewInfo { unitId: string; subUnitId: string; token: string; type: PivotTableOperationEnum; pivotConfig?: IPivotTableConfig; } export interface IPivotLocalMutationBaseParams { unitId: string; subUnitId: string; pivotTableId: string; } export interface IGetPivotFilterPanelDataParams { row: number; col: number; tableFieldId?: string; cellData?: IPivotTableCellData; pivotItemRenderInfoCache?: IPivotRenderCache; } export interface IGetPivotPanelDataParams { pivotTableId: string; } export interface IGetAddPivotFieldDataParams { dataFieldId: string; fieldArea: PivotTableFiledAreaEnum; index: number; } export interface IPivotDisplayFilterInfo { tableFieldId: string; pivotTableId: string; items: string[]; itemTypes: PivotDataFieldDataTypeEnum[]; filterInfo: IPivotTableFilterInfo | undefined; sortInfo: IPivotTableSortInfo | undefined; format: string | undefined; } export type IPivotDisplayPanelInfo = IPivotPanelDataInfo; export interface IGetAddPivotTableDataParams { sourceRangeInfo: IUnitRangeName & { subUnitId: string; }; pivotTableId: string; } export interface IGetAddPivotTableWithConfigDataParams { sourceRangeInfo: IUnitRangeName & { subUnitId: string; }; pivotTableId: string; pivotTableIndexConfig: { filters?: IPivotFieldConfig[]; rows?: IPivotFieldConfig[]; columns?: IPivotFieldConfig[]; values?: IValueFieldConfig[]; }; } export interface IGetMovePivotFieldDataParams { fieldId: string; area: PivotTableFiledAreaEnum; index: number; } export interface IGetRemovePivotFieldDataParams { fieldIds: string[]; } export interface IGetPivotCollapseDataParams { tableFieldId: string; collapse: boolean; item: string; } export interface IGetPivotFilterDataParams { tableFieldId: string; items: string[]; isAll?: boolean; } export interface IGetPivotValueFilterDataParams { tableFieldId: string; filterInfo: IPivotTableValueFilter | undefined; } export interface ISetPivotTableConfigDataParams { pivotTableId: string; pivotTableConfig: IPivotTableSnapshot; } export interface IResetPivotTableDataParams { pivotTableId: string; resetArea?: PivotTableFiledAreaEnum; } export interface IGetPivotSortDataParams { tableFieldId: string; info: IPivotTableSortInfo; } export interface IGetPivotOptionParams { pivotTableId: string; info: IPivotTableOptions; } export interface IGetPivotDrillDownDataParams { tuple: string[][]; } export interface IGetPivotSettingDataParams { tableFieldId: string; displayName?: string; format?: string; subtotalType?: PivotSubtotalTypeEnum; } export interface IGetUpdatePivotSourceDataParams { dataRangeInfo: IUnitRangeNameWithSubUnitId; unitId: string; subUnitId: string; } export interface IGetUpdateValuePositionDataParams { position: PivotTableValuePositionEnum; index: number; } export interface IGetPivotDataLocalMutationParams extends IPivotLocalMutationBaseParams { version: string; params: { type: PivotDisplayDataType; filter?: IGetPivotFilterPanelDataParams; panel?: IGetPivotPanelDataParams; addPivotField?: IGetAddPivotFieldDataParams; addPivotTable?: IGetAddPivotTableDataParams; movePivotField?: IGetMovePivotFieldDataParams; removePivotField?: IGetRemovePivotFieldDataParams; setPivotCollapse?: IGetPivotCollapseDataParams; setPivotFilter?: IGetPivotFilterDataParams; setPivotSort?: IGetPivotSortDataParams; setPivotSetting?: IGetPivotSettingDataParams; updatePivotSource?: IGetUpdatePivotSourceDataParams; updateValuePosition?: IGetUpdateValuePositionDataParams; addPivotTableWithConfig?: IGetAddPivotTableWithConfigDataParams; setPivotTableConfig?: ISetPivotTableConfigDataParams; resetPivotTable?: IResetPivotTableDataParams; drillDown?: IGetPivotDrillDownDataParams; setValuePivotFilter?: IGetPivotValueFilterDataParams; setOptions?: IGetPivotOptionParams; }; } export interface IPivotDisplayResult { filter?: IPivotDisplayFilterInfo; panel?: IPivotDisplayPanelInfo; addPivotTable?: IPivotAddPivotTableInfo; addPivotField?: IPivotDisplayBaseInfo; movePivotField?: IPivotDisplayBaseInfo; removePivotField?: IPivotDisplayBaseInfo; setPivotCollapse?: IPivotDisplayBaseInfo; setPivotFilter?: IPivotDisplayBaseInfo; setPivotSort?: IPivotDisplayBaseInfo; setPivotSetting?: IPivotDisplayBaseInfo; updatePivotSource?: IPivotUpdatePivotSourceInfo; updateValuePosition?: IPivotDisplayBaseInfo; addPivotTableWithConfig?: IPivotAddPivotTableInfo & { changesets: IPivotTableChangeSet[]; }; drillDown?: IPivotDrillDownInfo; setValuePivotFilter?: IPivotDisplayBaseInfo; setPivotTableConfig?: IPivotDisplayBaseInfo; resetPivotTable?: IPivotDisplayBaseInfo; setPivotOption?: IPivotDisplayBaseInfo; } export interface IPivotUpdatePivotSourceInfo { view: IPivotViewJSON; changesets: IPivotTableChangeSet[]; isEmpty: boolean; pivotTableConfig: IPivotTableConfig; collectionConfig: IFieldsCollectionJSON; oldCollectionConfig: IFieldsCollectionJSON; deleteIds?: string[]; } export interface IPivotAddPivotTableInfo { view: PivotView; isEmpty: boolean; fieldsConfig: IPivotTableSnapshot; collectionConfig: IFieldsCollectionJSON; } export interface IPivotDrillDownInfo { indexes: number[]; range: IRange; sourceUnitId: string; sourceSubUnitId: string; formatMap: Record<string, string>; } export interface IPivotDisplayBaseInfo { view: IPivotViewJSON; changesets: IPivotTableChangeSet[]; isEmpty: boolean; pivotTableConfig: IPivotTableConfig; shouldBeAddedGroupJSON?: IBaseGroupFieldJSON; } export interface ISendPivotViewItemLocalParams extends IPivotLocalMutationBaseParams { view: IPivotViewJSON; pivotConfig: IPivotTableConfig; type: PivotTableOperationEnum; } export interface ISendPivotViewLocalMutationParams { single?: ISendPivotViewItemLocalParams; batch?: ISendPivotViewItemLocalParams[]; collectionConfig?: Record<string, IDataFieldManagerJSON>; } export interface ISendPivotConfigLocalMutationParams { unitId: string; subUnitId: string; oldSubUnitId: string; pivotTableId: string; pivotTableConfig: IPivotTableConfig; collectionConfig: IDataFieldManagerJSON; } export interface ISendInitPivotTextLocalMutationParams { textInfo: Record<string, string>; } export interface ISendPivotDataLocalMutationParams extends IPivotLocalMutationBaseParams { version: string; result: IPivotDisplayResult; } export interface IPivotTextInfo { subTotal: string; grandTotal: string; blank: string; other: string; value: string; averageName: string; countName: string; countNumsName: string; maxName: string; minName: string; productName: string; stdDevName: string; stdDevpName: string; sumName: string; varName: string; varpName: string; } export interface IPivotPanelTableListItemBase { tableFieldId: string; displayName: string; dataFieldId: string; format?: string; subTotalType?: PivotSubtotalTypeEnum; } export interface IPivotPanelSourceList { id: string; dataFieldId: string; name: string; type: PivotDataFieldDataTypeEnum; checked: boolean; pivotTableId: string; } export interface IPivotPanelDataInfo { sourceRange: IUnitRangeNameWithSubUnitId; sourceList: IPivotPanelSourceList[]; rowFields: IPivotPanelTableListItemBase[]; columnFields: IPivotPanelTableListItemBase[]; valueFields: IPivotPanelTableListItemBase[]; filterFields: IPivotPanelTableListItemBase[]; positionInfo: IPivotTableConfig['targetCellInfo']; } export interface ICurrentDataMatrix { arrayFormulaCellDataMatrix: ObjectMatrix<Nullable<ICellData>> | undefined; unitDataMatrix: ObjectMatrix<Nullable<ICellData>> | undefined; } export interface IPivotFieldConfig { field: number; selectedItems?: string[]; } export interface IValueFieldConfig { field: number; subTotalType?: PivotSubtotalTypeEnum; formatString?: string; } export interface IAddPivotTableWithConfigCommandParams { sourceDataInfo: { unitId: string; subUnitId: string; range?: IRange; }; pivotTableConfig: { filters?: IPivotFieldConfig[]; rows?: IPivotFieldConfig[]; columns?: IPivotFieldConfig[]; values?: IValueFieldConfig[]; }; } export interface IUpdateInfo { collection: FieldsCollection; updateDataFieldList: { index: number; dataField: DataField; }[]; } export interface IPivotViewUpdateInfo { unitId: string; subUnitId: string; pivotTableId: string; rangesCache: IPivotRangesInfo | undefined; valueMatrix: ObjectMatrix<Nullable<IPivotTableCellData>>; type: PivotTableOperationEnum; isEmpty?: boolean; } interface IPivotTableEventParamsBase { /** * The pivot table id.When create a pivot table, the id maybe undefined. */ pivotTableId: string | undefined; /** * The unit id of workbook which the pivot table belongs to. */ unitId: string; } /** * The pivot table added event callback argument. */ export interface IPivotTableAddedEventParams extends IPivotTableEventParamsBase { /** * @property {PositionType} positionType The position type of the pivot table. */ positionType: PositionType; /** * The source range info of the pivot table. */ sourceRangeInfo: { /** * @property {number} startRow The start row of the range. */ startRow: number; /** * @property {number} endRow The end row of the range. */ endRow: number; /** * @property {number} startColumn The start column of the range. */ startColumn: number; /** * @property {number} endColumn The end column of the range. */ endColumn: number; /** * @property {string} unitId The unit id of workbook which the pivot table source range belongs to. */ unitId: string; /** * @property {string} subUnitId The sheet id of workbook which the pivot table source range belongs to. */ subUnitId: string; /** * @property {string} sheetName The sheet name of workbook which the pivot table source range belongs to. */ sheetName?: string; }; /** * The target cell info of the pivot table.Only the PositionType is 'exiting' will have this property. */ targetCellInfo?: { /** * @property {number} row The row of the target cell. */ row: number; /** * @property {number} col The column of the target cell. */ column: number; /** * @property {string} unitId The unit id of workbook which the pivot table target cell belongs to. */ unitId: string; /** * @property {string} subUnitId The sheet id of workbook which the pivot table target cell belongs to. */ subUnitId: string; /** * @property {string} sheetName The sheet name of workbook which the pivot table target cell belongs to. */ sheetName?: string; }; } /** * The pivot table removed event callback argument. */ export interface IPivotTableRemovedEventParams extends IPivotTableEventParamsBase { } /** * The pivot table updated event callback argument. */ export interface IPivotTableUpdatedEventParams extends IPivotTableEventParamsBase { /** * The pivot table change infos, may be a ui drag operation may cause multiple changes. */ changes: { /** * @property {PivotTableChangeTypeEnum} changeType The change type of the pivot table. */ changeType: PivotTableChangeTypeEnum; /** * The pivot table change info. */ changeInfo: IPivotTableChangeSet; }[]; } /** * The pivot table moved event callback argument. */ export interface IPivotTableMovedEventParams extends IPivotTableEventParamsBase { /** * @property {object} originTargetInfo The origin target info of the pivot table. */ originTargetInfo: { /** * @property {string} subUnitId The sheet id of workbook which the pivot table belongs to. */ subUnitId: string; /** * @property {string} unitId The unit id of workbook which the pivot table belongs to. */ unitId: string; /** * @property {number} row The origin row of the pivot table. */ row: number; /** * @property {number} column The origin column of the pivot table. */ column: number; }; /** * @property {object} targetCellInfo The target cell info of the pivot table. */ targetCellInfo: { /** * @property {number} row The row of the target cell. */ row: number; /** * @property {number} col The column of the target cell. */ column: number; /** * @property {string} unitId The unit id of workbook which the pivot table target cell belongs to. */ unitId: string; /** * @property {string} subUnitId The sheet id of workbook which the pivot table target cell belongs to. */ subUnitId: string; }; } /** * The pivot table rendered event callback argument. */ export interface IPivotTableRenderedEventParams extends IPivotTableEventParamsBase { /** * @property {boolean} isEmpty Whether the pivot table is empty. */ isEmpty: boolean; /** * @property {string} subUnitId The sheet id of workbook which the pivot table belongs to. */ subUnitId: string; /** * @property {changeType} changeType The change type of the pivot table. */ changeType: PivotTableOperationEnum; /** * @property {object} rangeInfo The current range info of the pivot table.When the pivot table is empty, the rangeInfo will be undefined. */ rangeInfo?: { /** * @property {Array<IRange>} rowRanges The row header ranges of the pivot table. */ rowRanges: IRange[]; /** * @property {Array<IRange>} colRanges The column header ranges of the pivot table. */ colRanges: IRange[]; /** * @property {Array<IRange>} cornerRanges The cross range of the pivot table row and column header in the left&top. */ cornerRanges: IRange[]; /** * @property {Array<IRange>} dataRanges The data ranges of the pivot table.Which is the main data of the pivot table. */ dataRanges: IRange[]; /** * @property {Array<IRange>} pageRanges The page ranges of the pivot table.Which match the pivot table filters area.In excel it is the page field. */ pageRanges: IRange[]; }; } export {};