mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-08-29 10:09:26 +02:00
Compare commits
2 Commits
3.4.5-andr
...
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 (
|
||||
<>
|
||||
<DesktopOnly>
|
||||
<TableRowToolbar
|
||||
editor={editor}
|
||||
table={tableRef}
|
||||
textDirection={textDirection}
|
||||
/>
|
||||
<TableColumnToolbar
|
||||
editor={editor}
|
||||
table={tableRef}
|
||||
textDirection={textDirection}
|
||||
/>
|
||||
{editor.isEditable ? (
|
||||
<>
|
||||
<TableRowToolbar
|
||||
editor={editor}
|
||||
table={tableRef}
|
||||
textDirection={textDirection}
|
||||
/>
|
||||
<TableColumnToolbar
|
||||
editor={editor}
|
||||
table={tableRef}
|
||||
textDirection={textDirection}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
<SimpleBar autoHide style={{ overflowY: "hidden" }}>
|
||||
<div dir={textDirection}>
|
||||
<table
|
||||
|
||||
@@ -143,8 +143,6 @@ function handleMouseDown(
|
||||
cellMinWidth: number,
|
||||
defaultCellMinWidth: number
|
||||
): boolean {
|
||||
if (!view.editable) return false;
|
||||
|
||||
const win = view.dom.ownerDocument.defaultView ?? window;
|
||||
|
||||
const pluginState = columnResizingPluginKey.getState(view.state);
|
||||
|
||||
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import {
|
||||
callOrReturn,
|
||||
Editor,
|
||||
getExtensionField,
|
||||
mergeAttributes,
|
||||
Node,
|
||||
@@ -30,7 +31,6 @@ import { EditorView, NodeView } from "@tiptap/pm/view";
|
||||
import { createColGroup } from "./utilities/createColGroup.js";
|
||||
import { createTable } from "./utilities/createTable.js";
|
||||
import { deleteTableWhenAllCellsSelected } from "./utilities/deleteTableWhenAllCellsSelected.js";
|
||||
import { TableView } from "./TableView.js";
|
||||
import { TableNodeView } from "./component.js";
|
||||
import {
|
||||
addColumnAfter,
|
||||
@@ -477,7 +477,7 @@ export const Table = Node.create<TableOptions>({
|
||||
},
|
||||
|
||||
addProseMirrorPlugins() {
|
||||
const isResizable = this.options.resizable && this.editor.isEditable;
|
||||
const isResizable = this.options.resizable;
|
||||
|
||||
return [
|
||||
...(isResizable
|
||||
@@ -489,7 +489,7 @@ export const Table = Node.create<TableOptions>({
|
||||
this.options.showResizeHandleOnSelection
|
||||
})
|
||||
]
|
||||
: [tiptapTableView(this.options.cellMinWidth)]),
|
||||
: [tiptapTableView(this.editor, this.options.cellMinWidth)]),
|
||||
tableEditing({
|
||||
allowTableNodeSelection: this.options.allowTableNodeSelection
|
||||
})
|
||||
@@ -512,11 +512,16 @@ export const Table = Node.create<TableOptions>({
|
||||
});
|
||||
|
||||
const TiptapTableViewPluginKey = new PluginKey("TiptapTableView");
|
||||
function tiptapTableView(cellMinWidth: number): Plugin {
|
||||
function tiptapTableView(editor: Editor, cellMinWidth: number): Plugin {
|
||||
return new Plugin({
|
||||
key: TiptapTableViewPluginKey,
|
||||
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