Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

editor: fix TouchEvent is not defined when resizing columns

Abdullah Attab5a706a6a987
diff --git a/packages/editor/src/extensions/table/prosemirror-tables/columnresizing.ts b/packages/editor/src/extensions/table/prosemirror-tables/columnresizing.ts
index 382033d96..5a8383dc6 100644
--- a/packages/editor/src/extensions/table/prosemirror-tables/columnresizing.ts
+++ b/packages/editor/src/extensions/table/prosemirror-tables/columnresizing.ts
@@ -1,3 +1,22 @@
+/*
+This file is part of the Notesnook project (https://notesnook.com/)
+
+Copyright (C) 2023 Streetwriters (Private) Limited
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
import { Attrs, Node as ProsemirrorNode } from "prosemirror-model";
import { EditorState, Plugin, PluginKey, Transaction } from "prosemirror-state";
import {
@@ -9,7 +28,7 @@ import {
import { tableNodeTypes } from "./schema.js";
import { TableMap } from "./tablemap.js";
import { TableView, updateColumnsOnResize } from "./tableview.js";
-import { cellAround, CellAttrs, getClientX } from "./util.js";
+import { cellAround, CellAttrs, getClientX, isTouchEvent } from "./util.js";
/**
* @public
@@ -192,8 +211,7 @@ function handleMouseDown(
const pluginState = columnResizingPluginKey.getState(view.state);
if (pluginState?.dragging) {
- if (event instanceof TouchEvent)
- (view as any).domObserver.connectSelection();
+ if (isTouchEvent(event)) (view as any).domObserver.connectSelection();
updateColumnWidth(
view,
activeHandle,
@@ -224,8 +242,7 @@ function handleMouseDown(
win.addEventListener("touchcancel", finish);
win.addEventListener("touchmove", move);
event.preventDefault();
- if (event instanceof TouchEvent)
- (view as any).domObserver.disconnectSelection();
+ if (isTouchEvent(event)) (view as any).domObserver.disconnectSelection();
return true;
}
diff --git a/packages/editor/src/extensions/table/prosemirror-tables/input.ts b/packages/editor/src/extensions/table/prosemirror-tables/input.ts
index e1f9185f9..1e20b3222 100644
--- a/packages/editor/src/extensions/table/prosemirror-tables/input.ts
+++ b/packages/editor/src/extensions/table/prosemirror-tables/input.ts
@@ -1,5 +1,21 @@
-// This file defines a number of helpers for wiring up user input to
-// table-related functionality.
+/*
+This file is part of the Notesnook project (https://notesnook.com/)
+
+Copyright (C) 2023 Streetwriters (Private) Limited
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
import { keydownHandler } from "prosemirror-keymap";
import { Fragment, ResolvedPos, Slice } from "prosemirror-model";
@@ -23,6 +39,7 @@ import {
getClientY,
inSameTable,
isInTable,
+ isTouchEvent,
nextCell,
selectionCell,
tableEditingKey
@@ -313,7 +330,3 @@ function cellUnderMouse(
if (!mousePos) return null;
return mousePos ? cellAround(view.state.doc.resolve(mousePos.pos)) : null;
}
-
-function isTouchEvent(event: Event): event is TouchEvent {
- return "TouchEvent" in window && event instanceof TouchEvent;
-}
diff --git a/packages/editor/src/extensions/table/prosemirror-tables/util.ts b/packages/editor/src/extensions/table/prosemirror-tables/util.ts
index 3372a97b4..0b8f47803 100644
--- a/packages/editor/src/extensions/table/prosemirror-tables/util.ts
+++ b/packages/editor/src/extensions/table/prosemirror-tables/util.ts
@@ -1,4 +1,21 @@
-// Various helper function for working with tables
+/*
+This file is part of the Notesnook project (https://notesnook.com/)
+
+Copyright (C) 2023 Streetwriters (Private) Limited
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
import { EditorState, NodeSelection, PluginKey } from "prosemirror-state";
@@ -216,3 +233,7 @@ export function getClientY(event: MouseEvent | TouchEvent): number | null {
? event.changedTouches[0].clientY
: null;
}
+
+export function isTouchEvent(event: Event): event is TouchEvent {
+ return "TouchEvent" in window && event instanceof TouchEvent;
+}