跳转到内容

Table Plus API 参考

TablePlus.configure(options)
配置项类型默认值说明
theme'light' | 'dark''light'选区覆盖层与上下文菜单配色
locale'zh-CN' | 'en-US''zh-CN'内置语言包
translationsPartial<TablePlusTranslations>—局部翻译覆盖,与语言包浅合并
contextMenu(items: MenuList) => MenuList—自定义上下文菜单项

命令均通过 editor.chain() 调用。行列增删、合并拆分、表头切换等标准命令由 @tiptap/extension-table 提供,以下为本套件扩展的命令。

命令参数说明
clearSelectedCells()—清除选中单元格的内容与样式
clearRowColumnContent(orientation)'row' | 'column'清除当前行 / 列内容,保留样式
setTablePlusTheme(theme)'light' | 'dark'运行时切换主题
命令参数说明
setCellTextColor(color)string设置文字颜色
unsetCellTextColor()—移除文字颜色
setCellTextAlign(align)string | null设置水平对齐
setCellVerticalAlign(align)'top' | 'middle' | 'bottom' | null设置垂直对齐
命令参数说明
setNodeBackgroundColor(color)string设置块级节点背景色
unsetNodeBackgroundColor()—移除背景色
editor.chain().focus().setCellTextColor('#7c3aed').run();
editor.chain().focus().setNodeBackgroundColor('#f4f4f5').run();
函数签名说明
getTablePlusTranslations(editor: Editor | null) => TablePlusTranslations当前生效的翻译对象
getTablePlusTheme(editor: Editor | null) => 'light' | 'dark'当前主题
getTablePlusLocale(editor: Editor | null) => 'zh-CN' | 'en-US'当前语言区域

内置 zh-CN / en-US 语言包,可通过 locale 切换、translations 局部覆盖。

import { enUS, zhCN, getBuiltinTranslations } from '@easyx/tiptap-table-plus';
const t = getBuiltinTranslations('en-US');
字段中文英文
insertRowAbove上方插入行Insert Row Above
insertRowBelow下方插入行Insert Row Below
insertColumnLeft左侧插入列Insert Column Left
insertColumnRight右侧插入列Insert Column Right
mergeCells合并单元格Merge Cells
splitCell拆分单元格Split Cell
textColor文字颜色Text Color
backgroundColor背景色Background Color
horizontalAlign水平对齐Horizontal Align
verticalAlign垂直对齐Vertical Align
alignLeft左对齐Align Left
alignCenter居中Align Center
alignRight右对齐Align Right
alignJustify两端对齐Align Justify
alignTop顶端对齐Align Top
alignMiddle居中(垂直)Align Middle
alignBottom底端对齐Align Bottom
clearContent清除内容Clear Content
toggleHeaderRow切换标题行Toggle Header Row
toggleHeaderColumn切换标题列Toggle Header Column
deleteRow删除行Delete Row
deleteColumn删除列Delete Column
defaultColor默认颜色Default
tableActions表格操作Table Actions
addColumn添加列Add Column
addRow添加行Add Row
customColor自定义颜色Custom Color

contextMenu 接收默认菜单项列表,返回修改后的列表,可增删改。

import { TablePlus, type MenuList } from '@easyx/tiptap-table-plus';
TablePlus.configure({
contextMenu(items: MenuList) {
const filtered = items.filter(
(item) => !('variant' in item && item.variant === 'destructive'),
);
filtered.push(
{ type: 'separator' },
{ label: '自定义操作', iconHtml: '<svg>…</svg>', onClick: () => {} },
);
return filtered;
},
});
type SubMenuItem = {
label: string;
iconHtml: string;
onClick: () => void;
};
type MenuItem = {
label: string;
iconHtml: string;
disabled?: boolean;
variant?: 'default' | 'destructive';
onClick?: () => void;
/** 子级为 'color' 时点击色块触发的操作 */
action?: 'textColor' | 'backgroundColor';
/** 'color' 打开 70 色色板,SubMenuItem[] 打开级联菜单 */
sub?: 'color' | SubMenuItem[];
};
type MenuSeparator = { type: 'separator' };
type MenuList = (MenuItem | MenuSeparator)[];
变量默认值(亮 / 暗)说明
--easyx-tiptap-table-plus-accent#7c3aed / #a78bfa品牌色(选区边框、手柄、高亮)
--easyx-tiptap-table-plus-border#d4d4d8 / #3f3f46边框与分隔线
--easyx-tiptap-table-plus-bg#fff / #1e1e2e菜单与弹出层背景
--easyx-tiptap-table-plus-bg-hover#f4f4f5 / #2d2d3f悬停背景
--easyx-tiptap-table-plus-text#1a1a2e / #e4e4e7主文字色
--easyx-tiptap-table-plus-radius2px圆角
导出说明
TablePlus主扩展,需配合 @tiptap/extension-table
getTablePlusTranslations / getTablePlusTheme / getTablePlusLocale读取运行时状态
zhCN / enUS / getBuiltinTranslations内置语言包
TablePlusOptions / TablePlusTranslations / TablePlusTheme / TablePlusLocale / TablePlusStorage类型
MenuItem / MenuList / MenuSeparator / SubMenuItem上下文菜单类型