Skip to content

Commit

Permalink
refactor!: move text option together (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzxming authored Jan 27, 2025
1 parent bc7dbf0 commit f9df3f8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 24 deletions.
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ const defaultTexts = {
clear: 'Clear',
transparent: 'Transparent',
perWidthInsufficient: 'The percentage width is insufficient. To complete the operation, the table needs to be converted to a fixed width. Do you want to continue?',

InsertTop: 'Insert a row above',
InsertRight: 'Insert a column right',
InsertBottom: 'Insert a row below',
InsertLeft: 'Insert a column Left',
MergeCell: 'Merge Cell',
SplitCell: 'Split Cell',
DeleteRow: 'Delete Row',
DeleteColumn: 'Delete Column',
DeleteTable: 'Delete table',
BackgroundColor: 'Set background color',
BorderColor: 'Set border color',
};
```

Expand All @@ -120,13 +132,12 @@ const defaultTexts = {

### TableMenu Options

| attribute | description | type | default |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------ | ----------------------- |
| tipText | when `tableMenuClass` set `TableUp.TableMenuSelect`, display tip text when hover icon. when `tableMenuClass` set `TableUp.TableMenuContextmenu`(default), display tip text after icon | `boolean` | `true` |
| tipTexts | the text to replace tools tip text | `Record<string, string>` | `{}` |
| localstorageKey | used color save localstorage key | `string` | `__table-bg-used-color` |
| tools | menu items | `Tool[]` | `defaultTools` |
| defaultColorMap | color map | `string[][]` | in source code |
| attribute | description | type | default |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ----------------------- |
| tipText | when `tableMenuClass` set `TableUp.TableMenuSelect`, display tip text when hover icon. when `tableMenuClass` set `TableUp.TableMenuContextmenu`, display tip text after icon | `boolean` | `true` |
| localstorageKey | used color save localstorage key | `string` | `__table-bg-used-color` |
| tools | menu items | `Tool[]` | `defaultTools` |
| defaultColorMap | color map | `string[][]` | in source code |

<details>
<summary> types and default value </summary>
Expand Down
25 changes: 12 additions & 13 deletions docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,6 @@ const quill1 = new Quill('#editor1', {
tableMenuOptions: {
localstorageKey: 'used-color',
tipText: true,
tipTexts: {
InsertTop: '向上插入一行',
InsertRight: '向右插入一列',
InsertBottom: '向下插入一行',
InsertLeft: '向左插入一列',
MergeCell: '合并单元格',
SplitCell: '拆分单元格',
DeleteRow: '删除当前行',
DeleteColumn: '删除当前列',
DeleteTable: '删除当前表格',
BackgroundColor: '设置背景颜色',
BorderColor: '设置边框颜色',
},
defaultColorMap: [
[
'rgb(255, 255, 255)',
Expand Down Expand Up @@ -107,6 +94,18 @@ const quill1 = new Quill('#editor1', {
clear: '清除',
transparent: '透明',
perWidthInsufficient: '百分比宽度不足, 如需完成操作需要转换表格为固定宽度,是否继续?',

InsertTop: '向上插入一行',
InsertRight: '向右插入一列',
InsertBottom: '向下插入一行',
InsertLeft: '向左插入一列',
MergeCell: '合并单元格',
SplitCell: '拆分单元格',
DeleteRow: '删除当前行',
DeleteColumn: '删除当前列',
DeleteTable: '删除当前表格',
BackgroundColor: '设置背景颜色',
BorderColor: '设置边框颜色',
},
},
},
Expand Down
3 changes: 1 addition & 2 deletions src/modules/table-menu/table-menu-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export class TableMenuCommon {
resolveOptions(options: TableMenuOptionsInput) {
const value = Object.assign({
tipText: true,
tipTexts: {},
tools: defaultTools,
localstorageKey: '__table-bg-used-color',
defaultColorMap,
Expand Down Expand Up @@ -109,7 +108,7 @@ export class TableMenuCommon {
}

// add text
const tipText = this.options.tipTexts[name] || tip;
const tipText = this.tableModule.options.texts[name] || tip;
if (this.options.tipText && tipText && tip) {
this.createTipText(item, tipText);
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export type Tool = ToolOption | ToolOptionBreak;

export interface TableMenuOptions {
tipText: boolean;
tipTexts: Record<string, string>;
tools: Tool[];
localstorageKey: string;
defaultColorMap: string[];
Expand All @@ -45,7 +44,8 @@ export interface TableCreatorTextOptions {
notPositiveNumberError: string;
perWidthInsufficient: string;
};
export interface TableTextOptions extends TableCreatorTextOptions {
export type TableMenuTexts = Record<string, string>;
export interface TableTextOptions extends TableCreatorTextOptions, TableMenuTexts {
custom: string;
clear: string;
transparent: string;
Expand Down

0 comments on commit f9df3f8

Please sign in to comment.