-
Notifications
You must be signed in to change notification settings - Fork 173
Description
Hi there, I am using prosemirror-tables via TipTap
I have plugged in my own TableView implementation that is aware of customized table-widths (e.g. table width is set to 100%).
While I can customize how the table resizes and treats the new size. And how it renders it, I cannot seem to get a hold of it during the resizing when dragging the cursor. It always seemed that the resize-dragging was width-unaware while I implemented a width-aware view. "aware" as in aware that I customized the table to be "width: 100%" and expecting that the width remains and is not overriden during resize
While the resize-plugin allows to plugin a different view (which I do) the on-resize rending is hard-wired to the default implementation of TableView
https://github.com/ProseMirror/prosemirror-tables/blob/v1.7.1/src/columnresizing.ts#L375
import { TableView, updateColumnsOnResize } from './tableview';
...
function displayColumnWidth(
view: EditorView,
cell: number,
width: number,
defaultCellMinWidth: number,
): void {
const $cell = view.state.doc.resolve(cell);
const table = $cell.node(-1),
start = $cell.start(-1);
const col =
TableMap.get(table).colCount($cell.pos - start) +
$cell.nodeAfter!.attrs.colspan -
1;
let dom: Node | null = view.domAtPos($cell.start(-1)).node;
while (dom && dom.nodeName != 'TABLE') {
dom = dom.parentNode;
}
if (!dom) return;
updateColumnsOnResize(
table,
dom.firstChild as HTMLTableColElement,
dom as HTMLTableElement,
defaultCellMinWidth,
col,
width,
);
}
The part I customized goes somewhere along the line of
if (node.attrs["width"] != null) {
table.style.width = node.attrs["width"]
}
export function rewrittenColumnResize(
node: ProseMirrorNode,
colgroup: HTMLTableColElement, // <colgroup> has the same prototype as <col>
table: HTMLTableElement,
cellMinWidth: number,
firstLoad: boolean
) {
...
if (node.attrs["width"] != null) {
table.style.width = node.attrs["width"]
}
else if (fixedWidth) {
table.style.width = `${totalWidth}px`
table.style.minWidth = ''
} else {
table.style.width = ''
table.style.minWidth = `${totalWidth}px`
}
}
Currently, the resizing itself works fine, but looks off during the resizing and might confuse users. The implementations misalign and with that create an odd experience
a) is it intended that the columnsresizing refers to rewrittenColumnResize of tableview.ts statically? regardless of a custom view or not?
b) do you think we could allow on option for a custom "updateColumnsOnResize" function? Or delegate to the view if the custom View ships comes with one?
initially I thought this is something for the tiptap project, but then noticed that they mostly just delegate to this prosemirror plugin
I think what I am facing here is that I have made adjustments to the table-sizing on the outside (adjustable via attributes), which clash with the resizing plugin. And there appears to be no way to overrule/replace the resizing done in this part of the plugin