From 283efa6e41349878bfe06a3f3fd939ddec0fc01f Mon Sep 17 00:00:00 2001 From: Muhammad Ali Date: Thu, 25 May 2023 12:11:57 +0500 Subject: [PATCH] editor: prevent table column size reset in readonly mode (#2586) --- packages/editor/src/extensions/table/table.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/editor/src/extensions/table/table.ts b/packages/editor/src/extensions/table/table.ts index 0ecc73bc5..0338e3861 100644 --- a/packages/editor/src/extensions/table/table.ts +++ b/packages/editor/src/extensions/table/table.ts @@ -18,8 +18,9 @@ along with this program. If not, see . */ import { Table as TiptapTable, TableOptions } from "@tiptap/extension-table"; -import { columnResizing, tableEditing } from "@tiptap/pm/tables"; +import { tableEditing, columnResizing, TableView } from "@tiptap/pm/tables"; import { TableNodeView } from "./component"; +import { Plugin, PluginKey } from "prosemirror-state"; export const Table = TiptapTable.extend({ addProseMirrorPlugins() { @@ -35,10 +36,20 @@ export const Table = TiptapTable.extend({ lastColumnResizable: this.options.lastColumnResizable }) ] - : []), + : [tiptapTableView(this.options.cellMinWidth)]), tableEditing({ allowTableNodeSelection: this.options.allowTableNodeSelection }) ]; } }); + +const TiptapTableViewPluginKey = new PluginKey("TiptapTableView"); +function tiptapTableView(cellMinWidth: number): Plugin { + return new Plugin({ + key: TiptapTableViewPluginKey, + props: { + nodeViews: { [Table.name]: (node) => new TableView(node, cellMinWidth) } + } + }); +}