From 8d1100cdb1646bf8822112993c00881cf9e39a5e Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Fri, 14 Jul 2023 19:24:21 +0800 Subject: [PATCH] feat: add table row and col size option #214 --- docs/guide/option.md | 1 + src/editor/core/command/CommandAdapt.ts | 9 +++------ src/editor/index.ts | 1 + src/editor/interface/Editor.ts | 1 + 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/guide/option.md b/docs/guide/option.md index df501e9..7a87e62 100644 --- a/docs/guide/option.md +++ b/docs/guide/option.md @@ -44,6 +44,7 @@ interface IEditorOption { pageMode?: PageMode; // 纸张模式:连页、分页。默认:分页 tdPadding?: number; // 单元格内边距。默认:5 defaultTrMinHeight?: number; // 默认表格行最小高度。默认:40 + defaultColMinWidth?: number; // 默认表格列最小宽度(整体宽度足够时应用,否则会按比例缩小)。默认:40 defaultHyperlinkColor?: string; // 默认超链接颜色。默认:#0000FF header?: IHeader; // 页眉信息。{top?:number; maxHeightRadio?:MaxHeightRatio;} footer?: IFooter; // 页脚信息。{bottom?:number; maxHeightRadio?:MaxHeightRatio;} diff --git a/src/editor/core/command/CommandAdapt.ts b/src/editor/core/command/CommandAdapt.ts index 92c1fa6..b3e7649 100644 --- a/src/editor/core/command/CommandAdapt.ts +++ b/src/editor/core/command/CommandAdapt.ts @@ -35,11 +35,8 @@ import { Position } from '../position/Position' import { RangeManager } from '../range/RangeManager' import { WorkerManager } from '../worker/WorkerManager' - export class CommandAdapt { - private readonly defaultWidth: number = 40 - private draw: Draw private range: RangeManager private position: Position @@ -533,7 +530,7 @@ export class CommandAdapt { for (let r = 0; r < row; r++) { const tdList: ITd[] = [] const tr: ITr = { - height: 40, + height: this.options.defaultTrMinHeight, tdList } for (let c = 0; c < col; c++) { @@ -726,7 +723,7 @@ export class CommandAdapt { // 重新计算宽度 const colgroup = element.colgroup! colgroup.splice(curTdIndex, 0, { - width: this.defaultWidth + width: this.options.defaultColMinWidth }) const colgroupWidth = colgroup.reduce((pre, cur) => pre + cur.width, 0) const width = this.draw.getOriginalInnerWidth() @@ -783,7 +780,7 @@ export class CommandAdapt { // 重新计算宽度 const colgroup = element.colgroup! colgroup.splice(curTdIndex, 0, { - width: this.defaultWidth + width: this.options.defaultColMinWidth }) const colgroupWidth = colgroup.reduce((pre, cur) => pre + cur.width, 0) const width = this.draw.getOriginalInnerWidth() diff --git a/src/editor/index.ts b/src/editor/index.ts index 7ef7823..0b2a0b8 100644 --- a/src/editor/index.ts +++ b/src/editor/index.ts @@ -125,6 +125,7 @@ export default class Editor { pageMode: PageMode.PAGING, tdPadding: 5, defaultTrMinHeight: 40, + defaultColMinWidth: 40, defaultHyperlinkColor: '#0000FF', paperDirection: PaperDirection.VERTICAL, inactiveAlpha: 0.6, diff --git a/src/editor/interface/Editor.ts b/src/editor/interface/Editor.ts index a540b2b..da08596 100644 --- a/src/editor/interface/Editor.ts +++ b/src/editor/interface/Editor.ts @@ -48,6 +48,7 @@ export interface IEditorOption { pageMode?: PageMode; tdPadding?: number; defaultTrMinHeight?: number; + defaultColMinWidth?: number; defaultHyperlinkColor?: string; paperDirection?: PaperDirection; inactiveAlpha?: number;