Skip to content

Commit

Permalink
Make NodeView in columnResizing optional (#226)
Browse files Browse the repository at this point in the history
Co-authored-by: ocavue <[email protected]>
  • Loading branch information
matej-svejda and ocavue authored Jul 2, 2024
1 parent 6737161 commit 3fb40e0
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/columnresizing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@ export type ColumnResizingOptions = {
handleWidth?: number;
cellMinWidth?: number;
lastColumnResizable?: boolean;
View?: new (
node: ProsemirrorNode,
cellMinWidth: number,
view: EditorView,
) => NodeView;
/**
* A custom node view for the rendering table nodes. By default, the plugin
* uses the {@link TableView} class. You can explicitly set this to `null` to
* not use a custom node view.
*/
View?:
| (new (
node: ProsemirrorNode,
cellMinWidth: number,
view: EditorView,
) => NodeView)
| null;
};

/**
Expand All @@ -50,9 +57,13 @@ export function columnResizing({
key: columnResizingPluginKey,
state: {
init(_, state) {
plugin.spec!.props!.nodeViews![
tableNodeTypes(state.schema).table.name
] = (node, view) => new View(node, cellMinWidth, view);
const nodeViews = plugin.spec?.props?.nodeViews;
const tableName = tableNodeTypes(state.schema).table.name;
if (View && nodeViews) {
nodeViews[tableName] = (node, view) => {
return new View(node, cellMinWidth, view);
};
}
return new ResizeState(-1, false);
},
apply(tr, prev) {
Expand Down

0 comments on commit 3fb40e0

Please sign in to comment.