mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
fix: table controls on "tap" to click in trackpad create new line at bottom
This commit is contained in:
parent
fb2b4ae303
commit
f0699e7aac
@ -1,4 +1,4 @@
|
|||||||
import { Extensions, generateJSON, getSchema } from "@tiptap/core";
|
import { Editor, Extensions, generateJSON, getSchema } from "@tiptap/core";
|
||||||
import { Selection } from "@tiptap/pm/state";
|
import { Selection } from "@tiptap/pm/state";
|
||||||
import { clsx, type ClassValue } from "clsx";
|
import { clsx, type ClassValue } from "clsx";
|
||||||
import { CoreEditorExtensionsWithoutProps } from "src/ui/extensions/core-without-props";
|
import { CoreEditorExtensionsWithoutProps } from "src/ui/extensions/core-without-props";
|
||||||
@ -77,3 +77,10 @@ export const generateJSONfromHTML = (html: string) => {
|
|||||||
editorSchema,
|
editorSchema,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Helper function to focus the editor after an action since most of the times
|
||||||
|
// editor.chain().focus() doesn't focus the editor
|
||||||
|
export const focusPostAction = (editor: Editor, fn: () => void) => {
|
||||||
|
fn();
|
||||||
|
editor.view.dom.focus();
|
||||||
|
};
|
||||||
|
@ -7,6 +7,7 @@ import { Editor } from "@tiptap/core";
|
|||||||
import { CellSelection, TableMap, updateColumnsOnResize } from "@tiptap/pm/tables";
|
import { CellSelection, TableMap, updateColumnsOnResize } from "@tiptap/pm/tables";
|
||||||
|
|
||||||
import { icons } from "src/ui/extensions/table/table/icons";
|
import { icons } from "src/ui/extensions/table/table/icons";
|
||||||
|
import { focusPostAction } from "src/lib/utils";
|
||||||
|
|
||||||
type ToolboxItem = {
|
type ToolboxItem = {
|
||||||
label: string;
|
label: string;
|
||||||
@ -74,7 +75,7 @@ const defaultTippyOptions: Partial<Props> = {
|
|||||||
allowHTML: true,
|
allowHTML: true,
|
||||||
arrow: false,
|
arrow: false,
|
||||||
trigger: "click",
|
trigger: "click",
|
||||||
animation: "scale-subtle",
|
animation: "shift-away",
|
||||||
theme: "light-border no-padding",
|
theme: "light-border no-padding",
|
||||||
interactive: true,
|
interactive: true,
|
||||||
hideOnClick: true,
|
hideOnClick: true,
|
||||||
@ -82,14 +83,16 @@ const defaultTippyOptions: Partial<Props> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function setCellsBackgroundColor(editor: Editor, color: { backgroundColor: string; textColor: string }) {
|
function setCellsBackgroundColor(editor: Editor, color: { backgroundColor: string; textColor: string }) {
|
||||||
return editor
|
return focusPostAction(editor, () =>
|
||||||
.chain()
|
editor
|
||||||
.focus()
|
.chain()
|
||||||
.updateAttributes("tableCell", {
|
.focus()
|
||||||
background: color.backgroundColor,
|
.updateAttributes("tableCell", {
|
||||||
textColor: color.textColor,
|
background: color.backgroundColor,
|
||||||
})
|
textColor: color.textColor,
|
||||||
.run();
|
})
|
||||||
|
.run()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setTableRowBackgroundColor(editor: Editor, color: { backgroundColor: string; textColor: string }) {
|
function setTableRowBackgroundColor(editor: Editor, color: { backgroundColor: string; textColor: string }) {
|
||||||
@ -124,6 +127,7 @@ function setTableRowBackgroundColor(editor: Editor, color: { backgroundColor: st
|
|||||||
});
|
});
|
||||||
|
|
||||||
dispatch(tr);
|
dispatch(tr);
|
||||||
|
editor.view.dom.focus();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,17 +135,20 @@ const columnsToolboxItems: ToolboxItem[] = [
|
|||||||
{
|
{
|
||||||
label: "Toggle column header",
|
label: "Toggle column header",
|
||||||
icon: icons.toggleColumnHeader,
|
icon: icons.toggleColumnHeader,
|
||||||
action: ({ editor }: { editor: Editor }) => editor.chain().focus().toggleHeaderColumn().run(),
|
action: ({ editor }: { editor: Editor }) =>
|
||||||
|
focusPostAction(editor, () => editor.chain().focus().toggleHeaderColumn().run()),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Add column before",
|
label: "Add column before",
|
||||||
icon: icons.insertLeftTableIcon,
|
icon: icons.insertLeftTableIcon,
|
||||||
action: ({ editor }: { editor: Editor }) => editor.chain().focus().addColumnBefore().run(),
|
action: ({ editor }: { editor: Editor }) =>
|
||||||
|
focusPostAction(editor, () => editor.chain().focus().addColumnBefore().run()),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Add column after",
|
label: "Add column after",
|
||||||
icon: icons.insertRightTableIcon,
|
icon: icons.insertRightTableIcon,
|
||||||
action: ({ editor }: { editor: Editor }) => editor.chain().focus().addColumnAfter().run(),
|
action: ({ editor }: { editor: Editor }) =>
|
||||||
|
focusPostAction(editor, () => editor.chain().focus().addColumnAfter().run()),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Pick color",
|
label: "Pick color",
|
||||||
@ -151,7 +158,8 @@ const columnsToolboxItems: ToolboxItem[] = [
|
|||||||
{
|
{
|
||||||
label: "Delete column",
|
label: "Delete column",
|
||||||
icon: icons.deleteColumn,
|
icon: icons.deleteColumn,
|
||||||
action: ({ editor }: { editor: Editor }) => editor.chain().focus().deleteColumn().run(),
|
action: ({ editor }: { editor: Editor }) =>
|
||||||
|
focusPostAction(editor, () => editor.chain().focus().deleteColumn().run()),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -159,17 +167,20 @@ const rowsToolboxItems: ToolboxItem[] = [
|
|||||||
{
|
{
|
||||||
label: "Toggle row header",
|
label: "Toggle row header",
|
||||||
icon: icons.toggleRowHeader,
|
icon: icons.toggleRowHeader,
|
||||||
action: ({ editor }: { editor: Editor }) => editor.chain().focus().toggleHeaderRow().run(),
|
action: ({ editor }: { editor: Editor }) =>
|
||||||
|
focusPostAction(editor, () => editor.chain().focus().toggleHeaderRow().run()),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Add row above",
|
label: "Add row above",
|
||||||
icon: icons.insertTopTableIcon,
|
icon: icons.insertTopTableIcon,
|
||||||
action: ({ editor }: { editor: Editor }) => editor.chain().focus().addRowBefore().run(),
|
action: ({ editor }: { editor: Editor }) =>
|
||||||
|
focusPostAction(editor, () => editor.chain().focus().addRowBefore().run()),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Add row below",
|
label: "Add row below",
|
||||||
icon: icons.insertBottomTableIcon,
|
icon: icons.insertBottomTableIcon,
|
||||||
action: ({ editor }: { editor: Editor }) => editor.chain().focus().addRowAfter().run(),
|
action: ({ editor }: { editor: Editor }) =>
|
||||||
|
focusPostAction(editor, () => editor.chain().focus().addRowAfter().run()),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Pick color",
|
label: "Pick color",
|
||||||
@ -179,7 +190,7 @@ const rowsToolboxItems: ToolboxItem[] = [
|
|||||||
{
|
{
|
||||||
label: "Delete row",
|
label: "Delete row",
|
||||||
icon: icons.deleteRow,
|
icon: icons.deleteRow,
|
||||||
action: ({ editor }: { editor: Editor }) => editor.chain().focus().deleteRow().run(),
|
action: ({ editor }: { editor: Editor }) => focusPostAction(editor, () => editor.chain().focus().deleteRow().run()),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -198,7 +209,7 @@ function createToolbox({
|
|||||||
onSelectColor: (color: { backgroundColor: string; textColor: string }) => void;
|
onSelectColor: (color: { backgroundColor: string; textColor: string }) => void;
|
||||||
colors: { [key: string]: { backgroundColor: string; textColor: string; icon?: string } };
|
colors: { [key: string]: { backgroundColor: string; textColor: string; icon?: string } };
|
||||||
}): Instance<Props> {
|
}): Instance<Props> {
|
||||||
// @ts-expect-error
|
// @ts-expect-error tippy types wrong
|
||||||
const toolbox = tippy(triggerButton, {
|
const toolbox = tippy(triggerButton, {
|
||||||
content: h(
|
content: h(
|
||||||
"div",
|
"div",
|
||||||
@ -340,7 +351,10 @@ export class TableView implements NodeView {
|
|||||||
triggerButton: this.columnsControl.querySelector(".columns-control-div"),
|
triggerButton: this.columnsControl.querySelector(".columns-control-div"),
|
||||||
items: columnsToolboxItems,
|
items: columnsToolboxItems,
|
||||||
colors: columnColors,
|
colors: columnColors,
|
||||||
onSelectColor: (color) => setCellsBackgroundColor(this.editor, color),
|
onSelectColor: (color) => {
|
||||||
|
setCellsBackgroundColor(this.editor, color);
|
||||||
|
this.columnsToolbox?.hide();
|
||||||
|
},
|
||||||
tippyOptions: {
|
tippyOptions: {
|
||||||
...defaultTippyOptions,
|
...defaultTippyOptions,
|
||||||
appendTo: this.controls,
|
appendTo: this.controls,
|
||||||
@ -363,7 +377,10 @@ export class TableView implements NodeView {
|
|||||||
...defaultTippyOptions,
|
...defaultTippyOptions,
|
||||||
appendTo: this.controls,
|
appendTo: this.controls,
|
||||||
},
|
},
|
||||||
onSelectColor: (color) => setTableRowBackgroundColor(editor, color),
|
onSelectColor: (color) => {
|
||||||
|
setTableRowBackgroundColor(editor, color);
|
||||||
|
this.rowsToolbox?.hide();
|
||||||
|
},
|
||||||
onClickItem: (item) => {
|
onClickItem: (item) => {
|
||||||
item.action({
|
item.action({
|
||||||
editor: this.editor,
|
editor: this.editor,
|
||||||
|
Loading…
Reference in New Issue
Block a user