Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: customMergeCell support array config #3202 #3237

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vtable",
"comment": "feat: customMergeCell support array config #3202",
"type": "none"
}
],
"packageName": "@visactor/vtable"
}
5 changes: 3 additions & 2 deletions packages/vtable/src/core/BaseTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ import type { ITableAnimationOption } from '../ts-types/animation/appear';
import { checkCellInSelect } from '../state/common/check-in-select';
import type { CustomCellStylePlugin, ICustomCellStylePlugin } from '../plugins/custom-cell-style';
import { isCellDisableSelect } from '../state/select/is-cell-select-highlight';
import { getCustomMergeCellFunc } from './utils/get-custom-merge-cell-func';

const { toBoxArray } = utilStyle;
const { isTouchEvent } = event;
Expand Down Expand Up @@ -498,7 +499,7 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {

internalProps.stick = { changedCells: new Map() };

internalProps.customMergeCell = options.customMergeCell;
internalProps.customMergeCell = getCustomMergeCellFunc(options.customMergeCell);

const CustomCellStylePlugin = Factory.getComponent('customCellStylePlugin') as ICustomCellStylePlugin;
if (CustomCellStylePlugin) {
Expand Down Expand Up @@ -2427,7 +2428,7 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
this.clearColWidthCache();
this.clearRowHeightCache();

internalProps.customMergeCell = options.customMergeCell;
internalProps.customMergeCell = getCustomMergeCellFunc(options.customMergeCell);

this.customCellStylePlugin?.updateCustomCell(
options.customCellStyle ?? [],
Expand Down
21 changes: 21 additions & 0 deletions packages/vtable/src/core/utils/get-custom-merge-cell-func.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { isArray, isFunction } from '@visactor/vutils';
import type { CustomMergeCell } from '../../ts-types';

export function getCustomMergeCellFunc(customMergeCell?: CustomMergeCell) {
if (isFunction(customMergeCell)) {
return customMergeCell;
}
if (isArray(customMergeCell)) {
return (col: number, row: number) => {
return customMergeCell.find(item => {
return (
item.range.start.col <= col &&
item.range.end.col >= col &&
item.range.start.row <= row &&
item.range.end.row >= row
);
});
};
}
return undefined;
}
5 changes: 3 additions & 2 deletions packages/vtable/src/ts-types/base-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ import type {
ColumnInfo,
RowInfo,
CellAddressWithBound,
Placement
Placement,
CustomMergeCellFunc
} from '.';
import type { TooltipOptions } from './tooltip';
import type { IWrapTextGraphicAttribute } from '../scenegraph/graphic/text';
Expand Down Expand Up @@ -259,7 +260,7 @@ export interface IBaseTableProtected {

stick: { changedCells: Map<string, StickCell> };

customMergeCell?: CustomMergeCell;
customMergeCell?: CustomMergeCellFunc;
/**
* 'auto':和浏览器滚动行为一致 表格滚动到顶部/底部时 触发浏览器默认行为;
* 设置为 'none' 时, 表格滚动到顶部/底部时, 不再触发父容器滚动
Expand Down
5 changes: 4 additions & 1 deletion packages/vtable/src/ts-types/table-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,10 @@ export interface IExtensionRowDefine {

export type StickCell = { col: number; row: number; dx: number; dy: number };

export type CustomMergeCell = (col: number, row: number, table: BaseTableAPI) => undefined | CustomMerge;
export type CustomMergeCell = CustomMergeCellFunc | CustomMergeCellArray;

export type CustomMergeCellFunc = (col: number, row: number, table: BaseTableAPI) => undefined | CustomMerge;
export type CustomMergeCellArray = CustomMerge[];
export type CustomMerge = {
range: CellRange;
text?: string;
Expand Down
Loading