mirror of
https://github.com/outline/outline.git
synced 2026-11-20 21:23:06 +03:00
Every remote change is applied as a full document replacement, which invalidates the column resize handle while the drag is still active. Releasing the pointer then resolved position -1 and threw. Cancel the drag when the handle no longer points at a cell. Fixes OUTLINE-CLOUD-B3R
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import type { Transaction, EditorState } from "prosemirror-state";
|
|
import { Plugin } from "prosemirror-state";
|
|
import { columnResizingPluginKey } from "prosemirror-tables";
|
|
|
|
/**
|
|
* A ProseMirror plugin that cancels an in-progress column resize once the drag
|
|
* handle no longer points at a cell. The handle is invalidated whenever the
|
|
* document is replaced under the pointer, such as by a collaborative edit from
|
|
* another user, and resizing with an invalid handle throws.
|
|
*/
|
|
export class TableColumnResizePlugin extends Plugin {
|
|
constructor() {
|
|
super({
|
|
appendTransaction: (
|
|
transactions: readonly Transaction[],
|
|
_oldState: EditorState,
|
|
newState: EditorState
|
|
) => {
|
|
if (!transactions.some((transaction) => transaction.docChanged)) {
|
|
return undefined;
|
|
}
|
|
|
|
const resizeState = columnResizingPluginKey.getState(newState);
|
|
if (!resizeState?.dragging || resizeState.activeHandle > -1) {
|
|
return undefined;
|
|
}
|
|
|
|
return newState.tr.setMeta(columnResizingPluginKey, {
|
|
setDragging: null,
|
|
});
|
|
},
|
|
});
|
|
}
|
|
}
|