mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-09-01 11:39:21 +02:00
Compare commits
2 Commits
cleanup/ma
...
editor/rea
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5962f059ce | ||
|
|
4991bdf689 |
@@ -1,49 +0,0 @@
|
|||||||
import { Node as ProseMirrorNode } from "@tiptap/pm/model";
|
|
||||||
import { NodeView } from "@tiptap/pm/view";
|
|
||||||
import { updateColumnsOnResize } from "./prosemirror-tables/tableview.js";
|
|
||||||
|
|
||||||
export class TableView implements NodeView {
|
|
||||||
node: ProseMirrorNode;
|
|
||||||
|
|
||||||
cellMinWidth: number;
|
|
||||||
|
|
||||||
dom: HTMLElement;
|
|
||||||
|
|
||||||
table: HTMLTableElement;
|
|
||||||
|
|
||||||
colgroup: HTMLTableColElement;
|
|
||||||
|
|
||||||
contentDOM: HTMLElement;
|
|
||||||
|
|
||||||
constructor(node: ProseMirrorNode, cellMinWidth: number) {
|
|
||||||
this.node = node;
|
|
||||||
this.cellMinWidth = cellMinWidth;
|
|
||||||
this.dom = document.createElement("div");
|
|
||||||
this.dom.className = "tableWrapper";
|
|
||||||
this.table = this.dom.appendChild(document.createElement("table"));
|
|
||||||
this.colgroup = this.table.appendChild(document.createElement("colgroup"));
|
|
||||||
updateColumnsOnResize(node, this.colgroup, this.table, cellMinWidth);
|
|
||||||
this.contentDOM = this.table.appendChild(document.createElement("tbody"));
|
|
||||||
}
|
|
||||||
|
|
||||||
update(node: ProseMirrorNode) {
|
|
||||||
if (node.type !== this.node.type) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.node = node;
|
|
||||||
updateColumnsOnResize(node, this.colgroup, this.table, this.cellMinWidth);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
ignoreMutation(
|
|
||||||
mutation: MutationRecord | { type: "selection"; target: Element }
|
|
||||||
) {
|
|
||||||
return (
|
|
||||||
mutation.type === "attributes" &&
|
|
||||||
(mutation.target === this.table ||
|
|
||||||
this.colgroup.contains(mutation.target))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -90,16 +90,20 @@ export function TableComponent(
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DesktopOnly>
|
<DesktopOnly>
|
||||||
<TableRowToolbar
|
{editor.isEditable ? (
|
||||||
editor={editor}
|
<>
|
||||||
table={tableRef}
|
<TableRowToolbar
|
||||||
textDirection={textDirection}
|
editor={editor}
|
||||||
/>
|
table={tableRef}
|
||||||
<TableColumnToolbar
|
textDirection={textDirection}
|
||||||
editor={editor}
|
/>
|
||||||
table={tableRef}
|
<TableColumnToolbar
|
||||||
textDirection={textDirection}
|
editor={editor}
|
||||||
/>
|
table={tableRef}
|
||||||
|
textDirection={textDirection}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
<SimpleBar autoHide style={{ overflowY: "hidden" }}>
|
<SimpleBar autoHide style={{ overflowY: "hidden" }}>
|
||||||
<div dir={textDirection}>
|
<div dir={textDirection}>
|
||||||
<table
|
<table
|
||||||
|
|||||||
@@ -143,8 +143,6 @@ function handleMouseDown(
|
|||||||
cellMinWidth: number,
|
cellMinWidth: number,
|
||||||
defaultCellMinWidth: number
|
defaultCellMinWidth: number
|
||||||
): boolean {
|
): boolean {
|
||||||
if (!view.editable) return false;
|
|
||||||
|
|
||||||
const win = view.dom.ownerDocument.defaultView ?? window;
|
const win = view.dom.ownerDocument.defaultView ?? window;
|
||||||
|
|
||||||
const pluginState = columnResizingPluginKey.getState(view.state);
|
const pluginState = columnResizingPluginKey.getState(view.state);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
callOrReturn,
|
callOrReturn,
|
||||||
|
Editor,
|
||||||
getExtensionField,
|
getExtensionField,
|
||||||
mergeAttributes,
|
mergeAttributes,
|
||||||
Node,
|
Node,
|
||||||
@@ -30,7 +31,6 @@ import { EditorView, NodeView } from "@tiptap/pm/view";
|
|||||||
import { createColGroup } from "./utilities/createColGroup.js";
|
import { createColGroup } from "./utilities/createColGroup.js";
|
||||||
import { createTable } from "./utilities/createTable.js";
|
import { createTable } from "./utilities/createTable.js";
|
||||||
import { deleteTableWhenAllCellsSelected } from "./utilities/deleteTableWhenAllCellsSelected.js";
|
import { deleteTableWhenAllCellsSelected } from "./utilities/deleteTableWhenAllCellsSelected.js";
|
||||||
import { TableView } from "./TableView.js";
|
|
||||||
import { TableNodeView } from "./component.js";
|
import { TableNodeView } from "./component.js";
|
||||||
import {
|
import {
|
||||||
addColumnAfter,
|
addColumnAfter,
|
||||||
@@ -477,7 +477,7 @@ export const Table = Node.create<TableOptions>({
|
|||||||
},
|
},
|
||||||
|
|
||||||
addProseMirrorPlugins() {
|
addProseMirrorPlugins() {
|
||||||
const isResizable = this.options.resizable && this.editor.isEditable;
|
const isResizable = this.options.resizable;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
...(isResizable
|
...(isResizable
|
||||||
@@ -489,7 +489,7 @@ export const Table = Node.create<TableOptions>({
|
|||||||
this.options.showResizeHandleOnSelection
|
this.options.showResizeHandleOnSelection
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
: [tiptapTableView(this.options.cellMinWidth)]),
|
: [tiptapTableView(this.editor, this.options.cellMinWidth)]),
|
||||||
tableEditing({
|
tableEditing({
|
||||||
allowTableNodeSelection: this.options.allowTableNodeSelection
|
allowTableNodeSelection: this.options.allowTableNodeSelection
|
||||||
})
|
})
|
||||||
@@ -512,11 +512,16 @@ export const Table = Node.create<TableOptions>({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const TiptapTableViewPluginKey = new PluginKey("TiptapTableView");
|
const TiptapTableViewPluginKey = new PluginKey("TiptapTableView");
|
||||||
function tiptapTableView(cellMinWidth: number): Plugin {
|
function tiptapTableView(editor: Editor, cellMinWidth: number): Plugin {
|
||||||
return new Plugin({
|
return new Plugin({
|
||||||
key: TiptapTableViewPluginKey,
|
key: TiptapTableViewPluginKey,
|
||||||
props: {
|
props: {
|
||||||
nodeViews: { [Table.name]: (node) => new TableView(node, cellMinWidth) }
|
nodeViews: {
|
||||||
|
[Table.name]: (node, view) => {
|
||||||
|
const View = TableNodeView(editor);
|
||||||
|
return new View(node, cellMinWidth, view);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user