A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
feat: add cell split/merge
thecodrr9ccdf646d140
diff --git a/packages/editor/dist/toolbar/floatingmenus/table.js b/packages/editor/dist/toolbar/floatingmenus/table.jsindex 99581ec79..456fd0f54 100644--- a/packages/editor/dist/toolbar/floatingmenus/table.js+++ b/packages/editor/dist/toolbar/floatingmenus/table.js@@ -45,6 +45,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };}};+var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {+ if (ar || !(i in from)) {+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);+ ar[i] = from[i];+ }+ }+ return to.concat(ar || Array.prototype.slice.call(from));+};import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";import { Slider } from "@rebass/forms";import { useEffect, useRef, useState } from "react";@@ -61,8 +70,12 @@ export function TableRowFloatingMenu(props) {var _b = useState(false), isMenuOpen = _b[0], setIsMenuOpen = _b[1];useEffect(function () {var _a;- if (!editor.isActive("tableRow"))+ if (!editor.isActive("tableCell") &&+ !editor.isActive("tableRow") &&+ !editor.isActive("tableHeader")) {+ setPosition(null);return;+ }var $from = editor.state.selection.$from;var selectedNode = $from.node();var pos = selectedNode.isTextblock ? $from.before() : $from.pos;@@ -135,13 +148,19 @@ export function TableColumnFloatingMenu(props) {var _this = this;var editor = props.editor;var _a = useState(null), position = _a[0], setPosition = _a[1];+ var isInsideCellSelection = !editor.state.selection.empty &&+ editor.state.selection.$anchor.node().type.name === "tableCell";var _b = useState(false), isMenuOpen = _b[0], setIsMenuOpen = _b[1];var _c = useState(false), showCellProps = _c[0], setShowCellProps = _c[1];var _d = useState(null), menuPosition = _d[0], setMenuPosition = _d[1];useEffect(function () {var _a;- if (!editor.isActive("tableRow"))+ if (!editor.isActive("tableCell") &&+ !editor.isActive("tableRow") &&+ !editor.isActive("tableHeader")) {+ setPosition(null);return;+ }var $from = editor.state.selection.$from;var selectedNode = $from.node();var pos = selectedNode.isTextblock ? $from.before() : $from.pos;@@ -164,6 +183,85 @@ export function TableColumnFloatingMenu(props) {}, [editor.state.selection]);if (!position)return null;+ var columnProperties = [+ {+ key: "addColumnLeft",+ type: "menuitem",+ title: "Add column left",+ onClick: function () { return editor.chain().focus().addColumnBefore().run(); },+ icon: "insertColumnLeft",+ },+ {+ key: "addColumnRight",+ type: "menuitem",+ title: "Add column right",+ onClick: function () { return editor.chain().focus().addColumnAfter().run(); },+ icon: "insertColumnRight",+ },+ {+ key: "moveColumnLeft",+ type: "menuitem",+ title: "Move column left",+ onClick: function () { return moveColumnLeft(editor); },+ icon: "moveColumnLeft",+ },+ {+ key: "moveColumnRight",+ type: "menuitem",+ title: "Move column right",+ onClick: function () { return moveColumnRight(editor); },+ icon: "moveColumnRight",+ },+ {+ key: "deleteColumn",+ type: "menuitem",+ title: "Delete column",+ onClick: function () { return editor.chain().focus().deleteColumn().run(); },+ icon: "deleteColumn",+ },+ ];+ var mergeSplitProperties = [+ {+ key: "splitCells",+ type: "menuitem",+ title: "Split cells",+ onClick: function () { return editor.chain().focus().splitCell().run(); },+ icon: "splitCells",+ },+ {+ key: "mergeCells",+ type: "menuitem",+ title: "Merge cells",+ onClick: function () { return editor.chain().focus().mergeCells().run(); },+ icon: "mergeCells",+ },+ ];+ var cellProperties = [+ {+ key: "cellProperties",+ type: "menuitem",+ title: "Cell properties",+ onClick: function () {+ setShowCellProps(true);+ setMenuPosition({+ target: position.target || undefined,+ isTargetAbsolute: true,+ yOffset: 10,+ location: "below",+ });+ },+ icon: "cellProperties",+ },+ ];+ var tableProperties = [+ {+ key: "deleteTable",+ type: "menuitem",+ title: "Delete table",+ icon: "deleteTable",+ onClick: function () { return editor.chain().focus().deleteTable().run(); },+ },+ ];return (_jsxs(MenuPresenter, __assign({ isOpen: true, items: [], onClose: function () { }, options: {type: "autocomplete",position: position,@@ -177,64 +275,18 @@ export function TableColumnFloatingMenu(props) {},} }, { children: [_jsx(ToolButton, { toggled: isMenuOpen, title: "Column properties", id: "properties", icon: "more", onClick: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {return [2 /*return*/, setIsMenuOpen(true)];- }); }); }, iconSize: 16, sx: { mr: 0, p: "3px", borderRadius: "small" } }), _jsx(ToolButton, { toggled: false, title: "Insert column right", id: "insertColumnRight", icon: "insertColumnRight", onClick: function () { return editor.chain().focus().addColumnAfter().run(); }, sx: { mr: 0, p: "3px", borderRadius: "small" }, iconSize: 16 })] })), _jsx(MenuPresenter, { isOpen: isMenuOpen, onClose: function () {+ }); }); }, iconSize: 16, sx: { mr: 0, p: "3px", borderRadius: "small" } }), _jsx(ToolButton, { toggled: false, title: "Insert column right", id: "insertColumnRight", icon: "plus", onClick: function () { return editor.chain().focus().addColumnAfter().run(); }, sx: { mr: 0, p: "3px", borderRadius: "small" }, iconSize: 16 })] })), _jsx(MenuPresenter, { isOpen: isMenuOpen, onClose: function () {setIsMenuOpen(false);editor.commands.focus();}, options: {type: "menu",position: {},- }, items: [- {- key: "addColumnAbove",- type: "menuitem",- title: "Add column left",- onClick: function () { return editor.chain().focus().addColumnBefore().run(); },- icon: "insertColumnLeft",- },- {- key: "moveColumnLeft",- type: "menuitem",- title: "Move column left",- onClick: function () { return moveColumnLeft(editor); },- icon: "moveColumnLeft",- },- {- key: "moveColumnRight",- type: "menuitem",- title: "Move column right",- onClick: function () { return moveColumnRight(editor); },- icon: "moveColumnRight",- },- {- key: "deleteColumn",- type: "menuitem",- title: "Delete column",- onClick: function () { return editor.chain().focus().deleteColumn().run(); },- icon: "deleteColumn",- },- {- key: "sortDesc",- type: "menuitem",- title: "Sort descending",- onClick: function () { },- icon: "sortDesc",- },- {- key: "cellProperties",- type: "menuitem",- title: "Cell properties",- onClick: function () {- setShowCellProps(true);- setMenuPosition({- target: position.target || undefined,- isTargetAbsolute: true,- yOffset: 10,- location: "below",- });- },- icon: "cellProperties",- },- ] }), _jsx(MenuPresenter, __assign({ isOpen: showCellProps, onClose: function () {+ }, items: isInsideCellSelection+ ? __spreadArray(__spreadArray([], mergeSplitProperties, true), cellProperties, true) : __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], columnProperties, true), [+ { type: "seperator", key: "cellSeperator" }+ ], false), cellProperties, true), [+ { type: "seperator", key: "tableSeperator" }+ ], false), tableProperties, true) }), _jsx(MenuPresenter, __assign({ isOpen: showCellProps, onClose: function () {setShowCellProps(false);editor.commands.focus();}, options: {diff --git a/packages/editor/dist/toolbar/icons.d.ts b/packages/editor/dist/toolbar/icons.d.tsindex c3d34b14a..400ef8832 100644--- a/packages/editor/dist/toolbar/icons.d.ts+++ b/packages/editor/dist/toolbar/icons.d.ts@@ -44,7 +44,11 @@ export declare const Icons: {cellProperties: string;backgroundColor: string;borderColor: string;+ plus: string;close: string;sortDesc: string;+ deleteTable: string;+ mergeCells: string;+ splitCells: string;};export declare type IconNames = keyof typeof Icons;diff --git a/packages/editor/dist/toolbar/icons.js b/packages/editor/dist/toolbar/icons.jsindex 239b62ef3..d5ded62be 100644--- a/packages/editor/dist/toolbar/icons.js+++ b/packages/editor/dist/toolbar/icons.js@@ -1,4 +1,4 @@-import { mdiAttachment, mdiBorderHorizontal, mdiCheck, mdiChevronDown, mdiCodeBraces, mdiCodeTags, mdiDotsVertical, mdiFormatAlignCenter, mdiFormatAlignJustify, mdiFormatAlignLeft, mdiFormatAlignRight, mdiFormatBold, mdiFormatClear, mdiFormatColorHighlight, mdiFormatColorText, mdiFormatItalic, mdiFormatListBulleted, mdiFormatListNumbered, mdiFormatQuoteClose, mdiFormatStrikethrough, mdiFormatSubscript, mdiFormatSuperscript, mdiFormatTextdirectionLToR, mdiFormatTextdirectionRToL, mdiFormatUnderline, mdiImage, mdiInvertColorsOff, mdiLinkPlus, mdiLoading, mdiTable, mdiTableBorder, mdiTableRowPlusBefore, mdiTableRowRemove, mdiTableColumnPlusBefore, mdiTableColumnRemove, mdiUploadOutline, mdiPlus, mdiSquareRoundedBadgeOutline, mdiFormatColorFill, mdiBorderAllVariant, mdiClose, mdiSortDescending, mdiArrowExpandRight, mdiArrowExpandLeft, mdiArrowExpandDown, mdiArrowExpandUp, } from "@mdi/js";+import { mdiAttachment, mdiBorderHorizontal, mdiCheck, mdiChevronDown, mdiCodeBraces, mdiCodeTags, mdiDotsVertical, mdiFormatAlignCenter, mdiFormatAlignJustify, mdiFormatAlignLeft, mdiFormatAlignRight, mdiFormatBold, mdiFormatClear, mdiFormatColorHighlight, mdiFormatColorText, mdiFormatItalic, mdiFormatListBulleted, mdiFormatListNumbered, mdiFormatQuoteClose, mdiFormatStrikethrough, mdiFormatSubscript, mdiFormatSuperscript, mdiFormatTextdirectionLToR, mdiFormatTextdirectionRToL, mdiFormatUnderline, mdiImage, mdiInvertColorsOff, mdiLinkPlus, mdiLoading, mdiTable, mdiTableBorder, mdiTableRowPlusBefore, mdiTableRowRemove, mdiTableColumnPlusAfter, mdiTableColumnPlusBefore, mdiTableColumnRemove, mdiUploadOutline, mdiPlus, mdiSquareRoundedBadgeOutline, mdiFormatColorFill, mdiBorderAllVariant, mdiClose, mdiSortDescending, mdiArrowExpandRight, mdiArrowExpandLeft, mdiArrowExpandDown, mdiArrowExpandUp, mdiTrashCanOutline, mdiTableMergeCells, mdiTableSplitCell, } from "@mdi/js";export var Icons = {bold: mdiFormatBold,italic: mdiFormatItalic,@@ -37,7 +37,7 @@ export var Icons = {moveRowUp: mdiArrowExpandUp,deleteRow: mdiTableRowRemove,toggleHeaderRow: mdiTableBorder,- insertColumnRight: mdiPlus,+ insertColumnRight: mdiTableColumnPlusAfter,insertColumnLeft: mdiTableColumnPlusBefore,moveColumnRight: mdiArrowExpandRight,moveColumnLeft: mdiArrowExpandLeft,@@ -45,6 +45,10 @@ export var Icons = {cellProperties: mdiSquareRoundedBadgeOutline,backgroundColor: mdiFormatColorFill,borderColor: mdiBorderAllVariant,+ plus: mdiPlus,close: mdiClose,sortDesc: mdiSortDescending,+ deleteTable: mdiTrashCanOutline,+ mergeCells: mdiTableMergeCells,+ splitCells: mdiTableSplitCell,};diff --git a/packages/editor/src/toolbar/floating-menus/table.tsx b/packages/editor/src/toolbar/floating-menus/table.tsxindex 30fdff05f..b706feee1 100644--- a/packages/editor/src/toolbar/floating-menus/table.tsx+++ b/packages/editor/src/toolbar/floating-menus/table.tsx@@ -12,6 +12,7 @@ import { ColorPicker, DEFAULT_COLORS } from "../tools/colors";import { FloatingMenuProps } from "./types";import { selectedRect, TableMap, TableRect } from "prosemirror-tables";import { Transaction } from "prosemirror-state";+import { MenuItem } from "../../components/menu/types";export function TableRowFloatingMenu(props: FloatingMenuProps) {const { editor } = props;@@ -22,7 +23,14 @@ export function TableRowFloatingMenu(props: FloatingMenuProps) {const [isMenuOpen, setIsMenuOpen] = useState(false);useEffect(() => {- if (!editor.isActive("tableRow")) return;+ if (+ !editor.isActive("tableCell") &&+ !editor.isActive("tableRow") &&+ !editor.isActive("tableHeader")+ ) {+ setPosition(null);+ return;+ }let { $from } = editor.state.selection;@@ -137,6 +145,10 @@ export function TableColumnFloatingMenu(props: FloatingMenuProps) {const [position, setPosition] = useState<MenuOptions["position"] | null>(null);+ const isInsideCellSelection =+ !editor.state.selection.empty &&+ editor.state.selection.$anchor.node().type.name === "tableCell";+const [isMenuOpen, setIsMenuOpen] = useState(false);const [showCellProps, setShowCellProps] = useState(false);const [menuPosition, setMenuPosition] = useState<@@ -144,8 +156,14 @@ export function TableColumnFloatingMenu(props: FloatingMenuProps) {>(null);useEffect(() => {- if (!editor.isActive("tableRow")) return;-+ if (+ !editor.isActive("tableCell") &&+ !editor.isActive("tableRow") &&+ !editor.isActive("tableHeader")+ ) {+ setPosition(null);+ return;+ }let { $from } = editor.state.selection;const selectedNode = $from.node();@@ -174,6 +192,89 @@ export function TableColumnFloatingMenu(props: FloatingMenuProps) {if (!position) return null;+ const columnProperties: MenuItem[] = [+ {+ key: "addColumnLeft",+ type: "menuitem",+ title: "Add column left",+ onClick: () => editor.chain().focus().addColumnBefore().run(),+ icon: "insertColumnLeft",+ },+ {+ key: "addColumnRight",+ type: "menuitem",+ title: "Add column right",+ onClick: () => editor.chain().focus().addColumnAfter().run(),+ icon: "insertColumnRight",+ },+ {+ key: "moveColumnLeft",+ type: "menuitem",+ title: "Move column left",+ onClick: () => moveColumnLeft(editor),+ icon: "moveColumnLeft",+ },+ {+ key: "moveColumnRight",+ type: "menuitem",+ title: "Move column right",+ onClick: () => moveColumnRight(editor),+ icon: "moveColumnRight",+ },+ {+ key: "deleteColumn",+ type: "menuitem",+ title: "Delete column",+ onClick: () => editor.chain().focus().deleteColumn().run(),+ icon: "deleteColumn",+ },+ ];++ const mergeSplitProperties: MenuItem[] = [+ {+ key: "splitCells",+ type: "menuitem",+ title: "Split cells",+ onClick: () => editor.chain().focus().splitCell().run(),+ icon: "splitCells",+ },+ {+ key: "mergeCells",+ type: "menuitem",+ title: "Merge cells",+ onClick: () => editor.chain().focus().mergeCells().run(),+ icon: "mergeCells",+ },+ ];++ const cellProperties: MenuItem[] = [+ {+ key: "cellProperties",+ type: "menuitem",+ title: "Cell properties",+ onClick: () => {+ setShowCellProps(true);+ setMenuPosition({+ target: position.target || undefined,+ isTargetAbsolute: true,+ yOffset: 10,+ location: "below",+ });+ },+ icon: "cellProperties",+ },+ ];++ const tableProperties: MenuItem[] = [+ {+ key: "deleteTable",+ type: "menuitem",+ title: "Delete table",+ icon: "deleteTable",+ onClick: () => editor.chain().focus().deleteTable().run(),+ },+ ];+return (<MenuPresenterisOpen@@ -208,7 +309,7 @@ export function TableColumnFloatingMenu(props: FloatingMenuProps) {toggled={false}title="Insert column right"id="insertColumnRight"- icon="insertColumnRight"+ icon="plus"onClick={() => editor.chain().focus().addColumnAfter().run()}sx={{ mr: 0, p: "3px", borderRadius: "small" }}iconSize={16}@@ -225,58 +326,17 @@ export function TableColumnFloatingMenu(props: FloatingMenuProps) {type: "menu",position: {},}}- items={[- {- key: "addColumnAbove",- type: "menuitem",- title: "Add column left",- onClick: () => editor.chain().focus().addColumnBefore().run(),- icon: "insertColumnLeft",- },- {- key: "moveColumnLeft",- type: "menuitem",- title: "Move column left",- onClick: () => moveColumnLeft(editor),- icon: "moveColumnLeft",- },- {- key: "moveColumnRight",- type: "menuitem",- title: "Move column right",- onClick: () => moveColumnRight(editor),- icon: "moveColumnRight",- },- {- key: "deleteColumn",- type: "menuitem",- title: "Delete column",- onClick: () => editor.chain().focus().deleteColumn().run(),- icon: "deleteColumn",- },- {- key: "sortDesc",- type: "menuitem",- title: "Sort descending",- onClick: () => {},- icon: "sortDesc",- },- {- key: "cellProperties",- type: "menuitem",- title: "Cell properties",- onClick: () => {- setShowCellProps(true);- setMenuPosition({- target: position.target || undefined,- isTargetAbsolute: true,- yOffset: 10,- location: "below",- });- },- icon: "cellProperties",- },- ]}+ items={+ isInsideCellSelection+ ? [...mergeSplitProperties, ...cellProperties]+ : [+ ...columnProperties,+ { type: "seperator", key: "cellSeperator" },+ ...cellProperties,+ { type: "seperator", key: "tableSeperator" },+ ...tableProperties,+ ]+ }/><MenuPresenterdiff --git a/packages/editor/src/toolbar/icons.ts b/packages/editor/src/toolbar/icons.tsindex b9e08115d..cc23727dd 100644--- a/packages/editor/src/toolbar/icons.ts+++ b/packages/editor/src/toolbar/icons.ts@@ -47,6 +47,9 @@ import {mdiArrowExpandLeft,mdiArrowExpandDown,mdiArrowExpandUp,+ mdiTrashCanOutline,+ mdiTableMergeCells,+ mdiTableSplitCell,} from "@mdi/js";export const Icons = {@@ -87,7 +90,7 @@ export const Icons = {moveRowUp: mdiArrowExpandUp,deleteRow: mdiTableRowRemove,toggleHeaderRow: mdiTableBorder,- insertColumnRight: mdiPlus,+ insertColumnRight: mdiTableColumnPlusAfter,insertColumnLeft: mdiTableColumnPlusBefore,moveColumnRight: mdiArrowExpandRight,moveColumnLeft: mdiArrowExpandLeft,@@ -95,8 +98,12 @@ export const Icons = {cellProperties: mdiSquareRoundedBadgeOutline,backgroundColor: mdiFormatColorFill,borderColor: mdiBorderAllVariant,+ plus: mdiPlus,close: mdiClose,sortDesc: mdiSortDescending,+ deleteTable: mdiTrashCanOutline,+ mergeCells: mdiTableMergeCells,+ splitCells: mdiTableSplitCell,};export type IconNames = keyof typeof Icons;diff --git a/packages/editor/toolbar.md b/packages/editor/toolbar.mdindex 03546cefd..84543e384 100644--- a/packages/editor/toolbar.md+++ b/packages/editor/toolbar.md@@ -67,6 +67,6 @@ Total Tools:- [x] image- [x] attachment- [] media-- [] table+- [x] table- [x] ltr rtl- [] searchreplace