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: provide class to custom table menu #22

Merged
merged 4 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,22 @@ const defaultTexts = {

### TableSelection Options

| attribute | description | type | default |
| ----------- | ------------------------ | ------------------ | --------- |
| selectColor | selector border color | `string` | `#0589f3` |
| tableMenu | module TableMenu options | `TableMenuOptions` | - |
| attribute | description | type | default |
| -------------- | -------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----------------- |
| selectColor | selector border color | `string` | `#0589f3` |
| tableMenu | module TableMenu options | `TableMenuOptions` | - |
| tableMenuClass | when select a cell will trigger this class to create menu. module provide two menu module `TableMenuContextmenu` and `TableMenuSelect` | `Constructor` | `TableMenuSelect` |

### TableMenu Options

| attribute | description | type | default |
| --------------- | -------------------------------------------------------------------------------- | ------------------------ | ----------------------- |
| tipText | display tip text when hover 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` |
| contextmenu | table menu will display when selected at least one cell and right click on table | `boolean` | `false` |
| defaultColorMap | color map | `string[][]` | in source code |
| texts | the text that menu needs | `TableMenuTexts` | `defaultTexts` |
| attribute | description | type | default |
| --------------- | ---------------------------------- | ------------------------ | ----------------------- |
| tipText | display tip text when hover 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 |
| texts | the text that menu needs | `TableMenuTexts` | `defaultTexts` |

<details>
<summary> types and default value </summary>
Expand Down
74 changes: 37 additions & 37 deletions docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,6 @@ Quill.register({
}, true);

const quill1 = new Quill('#editor1', {
// debug: 'info',
theme: 'snow',
modules: {
toolbar: [
['bold', 'italic', 'underline', 'strike'],
['blockquote', 'code-block', 'code'],
['link', 'image', 'video', 'formula'],
[{ list: 'ordered' }, { list: 'bullet' }, { list: 'check' }],
[{ script: 'sub' }, { script: 'super' }],
[{ indent: '-1' }, { indent: '+1' }],
[{ direction: 'rtl' }],

[{ size: ['small', false, 'large', 'huge'] }],
[{ header: [1, 2, 3, 4, 5, 6, false] }],
[{ color: [] }, { background: [] }],
[{ font: [] }],
[{ align: [] }],
[{ [TableUp.toolName]: [] }],
['clean'],
],
[TableUp.moduleName]: {
full: false,
resizerSetOuter: false,
selection: {
selectColor: '#f40',
tableMenu: {
localstorageKey: 'used-color',
tipText: true,
contextmenu: false,
},
},
},
},
});

const quill2 = new Quill('#editor2', {
// debug: 'info',
theme: 'snow',
modules: {
Expand All @@ -68,10 +32,10 @@ const quill2 = new Quill('#editor2', {
resizerSetOuter: true,
selection: {
selectColor: '#04f',
tableMenuClass: window.TableUp.TableMenuContextmenu,
tableMenu: {
localstorageKey: 'used-color',
tipText: true,
contextmenu: true,
tipTexts: {
InsertTop: '向上插入一行',
InsertRight: '向右插入一列',
Expand Down Expand Up @@ -131,6 +95,42 @@ const quill2 = new Quill('#editor2', {
},
});

const quill2 = new Quill('#editor2', {
// debug: 'info',
theme: 'snow',
modules: {
toolbar: [
['bold', 'italic', 'underline', 'strike'],
['blockquote', 'code-block', 'code'],
['link', 'image', 'video', 'formula'],
[{ list: 'ordered' }, { list: 'bullet' }, { list: 'check' }],
[{ script: 'sub' }, { script: 'super' }],
[{ indent: '-1' }, { indent: '+1' }],
[{ direction: 'rtl' }],

[{ size: ['small', false, 'large', 'huge'] }],
[{ header: [1, 2, 3, 4, 5, 6, false] }],
[{ color: [] }, { background: [] }],
[{ font: [] }],
[{ align: [] }],
[{ [TableUp.toolName]: [] }],
['clean'],
],
[TableUp.moduleName]: {
full: false,
resizerSetOuter: false,
selection: {
selectColor: '#f40',
// tableMenuClass: window.TableUp.TableMenuSelect,
tableMenu: {
localstorageKey: 'used-color',
tipText: true,
},
},
},
},
});

const quill = [
quill1,
quill2,
Expand Down
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default factory({
rules: {
'unicorn/prefer-dom-node-dataset': 'off',
'no-cond-assign': 'off',
'new-cap': 'off',
},
},
],
Expand Down
2 changes: 2 additions & 0 deletions gulpfile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
import autoprefixer from 'autoprefixer';
Expand Down Expand Up @@ -34,6 +35,7 @@ const buildDts = async () => {
const buildTs = async (isDev: boolean = false) => {
const plugins = [
typescript({ tsconfig: './tsconfig.json' }),
nodeResolve(),
svg({ stringify: true }),
];
!isDev && plugins.push(terser());
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@
"peerDependencies": {
"quill": "^2.0.0"
},
"dependencies": {
"@floating-ui/dom": "^1.6.12"
},
"devDependencies": {
"@esbuild-kit/cjs-loader": "^2.4.4",
"@rollup/plugin-node-resolve": "^15.3.0",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@types/node": "^20.14.10",
Expand Down
61 changes: 61 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type Picker from 'quill/ui/picker';
import type { TableColValue, TableConstantsData, TableTextOptions, TableUpOptions } from './utils';
import Quill from 'quill';
import { BlockOverride, BlockquoteOverride, CodeBlockOverride, ContainerFormat, HeaderOverride, ListItemOverride, ScrollOverride, TableBodyFormat, TableCellFormat, TableCellInnerFormat, TableColFormat, TableColgroupFormat, TableMainFormat, TableRowFormat, TableWrapperFormat } from './formats';
import { TableResize, TableResizeLine, TableSelection, TableVitrualScroll } from './modules';
import { TableResizeBox, TableResizeLine, TableSelection, TableVitrualScroll } from './modules';
import { blotName, createSelectBox, debounce, findParentBlot, findParentBlots, isBoolean, isFunction, randomId, tableUpEvent, tableUpSize } from './utils';

const Delta = Quill.import('delta');
Expand Down Expand Up @@ -175,7 +175,7 @@ export class TableUp {
range?: Range | null;
table?: HTMLElement;
tableSelection?: TableSelection;
tableResizer?: TableResize;
tableResizerBox?: TableResizeBox;
tableResizerLine?: TableResizeLine;
tableScrollbar?: TableVitrualScroll;
get statics(): any {
Expand Down Expand Up @@ -481,7 +481,7 @@ export class TableUp {
this.tableScrollbar = new TableVitrualScroll(this, table, quill);
}
if (this.options.resizerSetOuter) {
this.tableResizer = new TableResize(this, table, quill, this.options.resizer || {});
this.tableResizerBox = new TableResizeBox(this, table, quill, this.options.resizeBox || {});
}
}
}
Expand All @@ -500,8 +500,8 @@ export class TableUp {

this.table = undefined;
if (this.options.resizerSetOuter) {
this.tableResizer && this.tableResizer.destroy();
this.tableResizer = undefined;
this.tableResizerBox && this.tableResizerBox.destroy();
this.tableResizerBox = undefined;
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/modules/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export * from './table-menu';
export * from './table-resize';
export * from './table-resize-common';
export * from './table-resize-line';
export * from './table-scrollbar';
export * from './table-selection';
Loading