2.1.7 • Published 4 months ago

quill-table-up v2.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

quill-table-up

Enhancement of quill table module

demo

quill@1.3.7 table module

  • complete UI operation process
  • insert/delete row/column/table; merge/split cells
  • support all origin quill formats
  • control cells width/height/border/background color
  • 100 percent table width or fixed pixel width
  • line break in cells
  • redo and undo
  • support whole table align left/center/right

Usage

npm install quill-table-up

the registe module name is used internal. so if you want to change it, place use the function updateTableConstants

import Quill from 'quill';
import TableUp, { TableAlign, TableMenuContextmenu, TableResizeBox, TableResizeScale, TableSelection, TableVirtualScrollbar } from 'quill-table-up';
import 'quill/dist/quill.snow.css';
import 'quill-table-up/index.css';
// If using the default customSelect option. You need to import this css
import 'quill-table-up/table-creator.css';

Quill.register({ [`modules/${TableUp.moduleName}`]: TableUp }, true);
// or
// Quill.register({ 'modules/table-up': TableUp }, true);

const quill = new Quill('#editor', {
  // ...
  modules: {
    //  ...
    toolbar: [
      // ...
      [ // use picker to enable the customSelect option
        { [TableUp.toolName]: [] }
      ],
    ],
    [TableUp.moduleName]: {
      scrollbar: TableVirtualScrollbar,
      align: TableAlign,
      resize: TableResizeBox,
      resizeScale: TableResizeScale,
      customSelect: defaultCustomSelect,
      selection: TableSelection,
      selectionOptions: {
        tableMenu: TableMenuContextmenu,
      }
    },
  },
});

Options

TableUp Options

attributedescriptiontypedefault
fullif set true. width max will be 100%booleanfalse
fullSwitchenable to choose insert a full width tablebooleantrue
textsthe text used to create the tableTableTextOptionsdefaultTexts
customSelectdisplay a custom select to custom row and column number add a table. module provides default selector defaultCustomSelect(tableModule: TableUp, picker: Picker) => Promise<HTMLElement> \| HTMLElement-
customBtndisplay a custom button to custom row and column number add a table. it only when use defaultCustomSelect will effectbooleanfalse
selectiontable selection handler. module provides TableSelectionConstructor-
selectionOptionstable selection optionsTableSelectionOptions-
iconpicker svg icon string. it will set with innerHTMLstringorigin table icon
resizetable cell resize handler. module provides TableResizeLine and TableResizeBoxConstructor-
resizeScaleequal scale table cell handler. module provides TableResizeScaleConstructor-
scrollbartable virtual scrollbar handler. module provides TableVirtualScrollbarConstructor-
aligntable alignment handler. module provides TableAlignConstructor-
resizeOptionstable cell resize handler optionsany-
resizeScaleOptionsequal scale table cell handler optionsTableResizeScaleOptions-
alignOptionstable alignment handler optionsany-
scrollbarOptionstable virtual scrollbar handler optionsany-

I'm not suggest to use TableVirtualScrollbar and TableResizeLine at same time, because it will make the virtual scrollbar display blink. Just like the first editor in demo

const defaultTexts = {
  fullCheckboxText: 'Insert full width table',
  customBtnText: 'Custom',
  confirmText: 'Confirm',
  cancelText: 'Cancel',
  rowText: 'Row',
  colText: 'Column',
  notPositiveNumberError: 'Please enter a positive integer',
  custom: 'Custom',
  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',
};

TableResizeScale Options

attributedescriptiontypedefault
blockSizeresize handle block sizenumber12

TableSelection Options

attributedescriptiontypedefault
selectColorselector border colorstring#0589f3
tableMenuthe table operate menu. module provides TableMenuContextmenu and TableMenuSelectConstructor-
tableMenuOptionsmodule TableMenu optionsTableMenuOptions-

TableMenu Options

attributedescriptiontypedefault
tipTextwhen tableMenuClass set TableUp.TableMenuSelect, display tip text when hover icon. when tableMenuClass set TableUp.TableMenuContextmenu, display tip text after iconbooleantrue
localstorageKeyused color save localstorage keystring__table-bg-used-color
toolsmenu itemsTool[]defaultTools
defaultColorMapcolor mapstring[][]in source code
interface ToolOption {
  name: string;
  icon: string | ((tableModule: TableUp) => HTMLElement);
  tip?: string;
  key?: string; // the attribute name to set on td.
  isColorChoose?: boolean;
  handle: (tableModule: TableUp, selectedTds: TableCellInnerFormat[], e: Event | string) => void;
}
interface ToolOptionBreak {
  name: 'break';
}
type Tool = ToolOption | ToolOptionBreak;

const defaultTools = [
  {
    name: 'InsertTop',
    icon: InsertTop,
    tip: 'Insert a row above',
    handle: (tableModule) => {},
  },
  {
    name: 'InsertRight',
    icon: InsertRight,
    tip: 'Insert a column right',
    handle: (tableModule) => {},
  },
  {
    name: 'InsertBottom',
    icon: InsertBottom,
    tip: 'Insert a row below',
    handle: (tableModule) => {},
  },
  {
    name: 'InsertLeft',
    icon: InsertLeft,
    tip: 'Insert a column Left',
    handle: (tableModule) => {},
  },
  {
    name: 'break',
  },
  {
    name: 'MergeCell',
    icon: MergeCell,
    tip: 'Merge Cell',
    handle: (tableModule) => {},
  },
  {
    name: 'SplitCell',
    icon: SplitCell,
    tip: 'Split Cell',
    handle: (tableModule) => {},
  },
  {
    name: 'break',
  },
  {
    name: 'DeleteRow',
    icon: RemoveRow,
    tip: 'Delete Row',
    handle: (tableModule) => {},
  },
  {
    name: 'DeleteColumn',
    icon: RemoveColumn,
    tip: 'Delete Column',
    handle: (tableModule) => {},
  },
  {
    name: 'DeleteTable',
    icon: RemoveTable,
    tip: 'Delete table',
    handle: (tableModule) => {},
  },
  {
    name: 'break',
  },
  {
    name: 'BackgroundColor',
    icon: Color,
    isColorChoose: true,
    tip: 'Set background color',
    key: 'background-color',
    handle: (tableModule, selectedTds, color) => {},
  },
  {
    name: 'BorderColor',
    icon: Border,
    isColorChoose: true,
    tip: 'Set border color',
    key: 'border-color',
    handle: (tableModule, selectedTds, color) => {},
  },
];

Overrides

if you need to rewrite extends from quill Block or Scroll blot. you need to use Quill.import() after TableUp registed. beacuse module internal rewrite some functions, but those change only effect formats about table.

Header,List',Blockquote and CodeBlock have been overrides. so if you need to rewrite them, you need to rewrite them before TableUp registed, or you want to rewrite the internal logic. you can use Quill.import() after TableUp registed.

please read source code to know those change.

import { BlockOverride, ScrollOverride, } from 'quill-table-up';

class ScrollBlot extends ScrollOverride {
  // ...
}

Other

Change internal constants variable

If it's not necessary, you should import constants variable from quill-table-up directly but not edit it.

import { blotName, tableUpEvent, tableUpInternal, tableUpSize, } from 'quill-table-up';

You can change internal constants variable by importing updateTableConstants from quill-table-up and call it before TableUp registed.

It helps to migrate from other table modules with the same data structure.

If you change the TableWrapperFormat blot name, you also need to add new css style to make toolbar icon have correct style.

/* change 'table-up' to your new blot name */
.ql-toolbar .ql-picker:not(.ql-color-picker):not(.ql-icon-picker).ql-table-up {
  width: 28px;
}
.ql-toolbar .ql-picker:not(.ql-color-picker):not(.ql-icon-picker).ql-table-up .ql-picker-label {
  padding: 2px 4px;
}
.ql-toolbar .ql-picker:not(.ql-color-picker):not(.ql-icon-picker).ql-table-up .ql-picker-label svg {
  position: static;
  margin-top: 0;
}
2.2.0-beta.0

5 months ago

1.6.0

8 months ago

1.4.0

8 months ago

2.0.3

7 months ago

2.0.2

7 months ago

2.0.5

6 months ago

2.0.4

7 months ago

2.0.6

6 months ago

2.0.1

7 months ago

2.0.0

7 months ago

1.5.2

8 months ago

1.5.1

8 months ago

1.5.0

8 months ago

1.3.2

9 months ago

2.1.2

5 months ago

2.1.1

6 months ago

2.1.4

5 months ago

2.1.3

5 months ago

2.1.6

5 months ago

2.1.5

5 months ago

2.1.7

4 months ago

2.1.0

6 months ago

1.2.0

10 months ago

1.0.2

10 months ago

1.1.0

10 months ago

1.0.1

11 months ago

1.0.0

11 months ago

1.3.1

9 months ago

1.0.4

10 months ago

1.3.0

9 months ago

1.2.1

10 months ago

1.0.3

10 months ago

1.2.0-temp092813

10 months ago

1.2.0-temp092811

10 months ago

1.2.0-temp092816

10 months ago

1.2.0-temp092815

10 months ago

1.2.0-temp09281336

10 months ago

0.1.4-0

12 months ago

0.1.4

12 months ago

0.1.3

12 months ago

0.1.2

12 months ago

0.1.1

12 months ago

0.1.0

12 months ago

0.0.3-beta.1

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.0

1 year ago