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: make toolbar compact with subgroups
thecodrrf9791a37b8ea
diff --git a/packages/editor/dist/components/menu/menu.d.ts b/packages/editor/dist/components/menu/menu.d.tsindex 63ae319a8..5ec21b401 100644--- a/packages/editor/dist/components/menu/menu.d.ts+++ b/packages/editor/dist/components/menu/menu.d.ts@@ -10,7 +10,7 @@ export declare function Menu(props: MenuProps): JSX.Element;declare type MenuContainerProps = FlexProps & {title?: string;};-declare type MenuPresenterProps = MenuContainerProps & {+export declare type MenuPresenterProps = MenuContainerProps & {items: MenuItemType[];options: MenuOptions;isOpen: boolean;diff --git a/packages/editor/dist/components/menu/menu.js b/packages/editor/dist/components/menu/menu.jsindex be94557d3..7138d7ace 100644--- a/packages/editor/dist/components/menu/menu.js+++ b/packages/editor/dist/components/menu/menu.js@@ -126,7 +126,7 @@ export function Menu(props) {var items = props.items, title = props.title, closeMenu = props.closeMenu, containerProps = __rest(props, ["items", "title", "closeMenu"]);var hoverTimeout = useRef();var onAction = useCallback(function (e, item) {- e.stopPropagation();+ e === null || e === void 0 ? void 0 : e.stopPropagation();if (closeMenu)closeMenu();if (item.onClick) {@@ -151,7 +151,7 @@ export function Menu(props) {return;}var _a = getPosition(subMenuRef.current, {- yOffset: menuItemElement.offsetHeight,+ // yOffset: menuItemElement.offsetHeight,target: menuItemElement,location: "right",}), top = _a.top, left = _a.left;@@ -191,7 +191,7 @@ export function Menu(props) {}function MenuContainer(props) {var children = props.children, title = props.title, sx = props.sx, flexProps = __rest(props, ["children", "title", "sx"]);- return (_jsxs(Box, __assign({ className: "menuContainer", as: "ul", tabIndex: -1, sx: __assign({ bg: "background", py: 1, display: "flex", flexDirection: "column", position: "relative", listStyle: "none", padding: 0, margin: 0, borderRadius: "default", boxShadow: "menu", border: "1px solid var(--border)", width: 220 }, sx) }, flexProps, { children: [title && (_jsx(Text, __assign({ sx: {+ return (_jsxs(Box, __assign({ className: "menuContainer", as: "ul", tabIndex: -1, sx: __assign({ bg: "background", py: 1, display: "flex", flexDirection: "column", position: "relative", listStyle: "none", padding: 0, margin: 0, borderRadius: "default", boxShadow: "menu", border: "1px solid var(--border)", minWidth: 220 }, sx) }, flexProps, { children: [title && (_jsx(Text, __assign({ sx: {fontFamily: "body",fontSize: "subtitle",color: "primary",diff --git a/packages/editor/dist/components/menu/menuitem.d.ts b/packages/editor/dist/components/menu/menuitem.d.tsindex 9270bbd0e..9348c2448 100644--- a/packages/editor/dist/components/menu/menuitem.d.ts+++ b/packages/editor/dist/components/menu/menuitem.d.ts@@ -5,7 +5,7 @@ declare type MenuItemProps = {isFocused: boolean;onMouseEnter: () => void;onMouseLeave: () => void;- onClick: React.MouseEventHandler<HTMLButtonElement>;+ onClick: (e?: any) => void;};declare function MenuItem(props: MenuItemProps): JSX.Element;export default MenuItem;diff --git a/packages/editor/dist/components/menu/menuitem.js b/packages/editor/dist/components/menu/menuitem.jsindex 4d0f0d936..b85598746 100644--- a/packages/editor/dist/components/menu/menuitem.js+++ b/packages/editor/dist/components/menu/menuitem.js@@ -9,7 +9,7 @@ var __assign = (this && this.__assign) || function () {};return __assign.apply(this, arguments);};-import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";+import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";// import { Check, ChevronRight, Pro } from "../icons";import { useRef } from "react";import { Flex, Box, Text, Button } from "rebass";@@ -21,7 +21,7 @@ function MenuItem(props) {// color,icon = item.icon,// iconColor,- type = item.type, tooltip = item.tooltip, isDisabled = item.isDisabled, isChecked = item.isChecked, hasSubmenu = item.hasSubmenu, Component = item.component, modifier = item.modifier;+ type = item.type, tooltip = item.tooltip, isDisabled = item.isDisabled, isChecked = item.isChecked, items = item.items, Component = item.component, modifier = item.modifier;var itemRef = useRef(null);if (type === "seperator")return (_jsx(Box, { as: "li", sx: {@@ -31,19 +31,19 @@ function MenuItem(props) {my: 2,alignSelf: "center",} }, key));- return (_jsx(Flex, __assign({ as: "li", sx: { flex: 1, flexDirection: "column" }, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave }, { children: _jsx(Button, __assign({ id: key, "data-test-id": "menuitem-".concat(key), ref: itemRef, tabIndex: -1, variant: "menuitem", title: tooltip, disabled: isDisabled, onClick: onClick, sx: {+ return (_jsx(Flex, __assign({ as: "li", sx: { flex: 1, flexDirection: "column" }, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave }, { children: Component ? (_jsx(Component, { onClick: onClick })) : (_jsxs(Button, __assign({ id: key, "data-test-id": "menuitem-".concat(key), ref: itemRef, tabIndex: -1, variant: "menuitem", title: tooltip, disabled: isDisabled, onClick: onClick, sx: {bg: isFocused ? "hover" : "transparent",display: "flex",alignItems: "center",justifyContent: "space-between",- } }, { children: Component ? (_jsx(Component, {})) : (_jsxs(_Fragment, { children: [_jsxs(Flex, { children: [icon && (_jsx(Icon, { path: Icons[icon], color: "text", size: 15, sx: { mr: 2 } })), _jsx(Text, __assign({ as: "span", sx: {- fontFamily: "body",- fontSize: "menu",- color: "text",- } }, { children: title }))] }), _jsxs(Flex, { children: [isChecked && _jsx(Icon, { path: Icons.check, size: 14 }), modifier && (_jsx(Text, __assign({ as: "span", sx: {- fontFamily: "body",- fontSize: "menu",- color: "fontTertiary",- } }, { children: modifier })))] })] })) }), key) })));+ } }, { children: [_jsxs(Flex, { children: [icon && (_jsx(Icon, { path: Icons[icon], color: "text", size: 15, sx: { mr: 2 } })), _jsx(Text, __assign({ as: "span", sx: {+ fontFamily: "body",+ fontSize: "menu",+ color: "text",+ } }, { children: title }))] }), _jsxs(Flex, { children: [isChecked && _jsx(Icon, { path: Icons.check, size: 14 }), (items === null || items === void 0 ? void 0 : items.length) && _jsx(Icon, { path: Icons.chevronRight, size: 14 }), modifier && (_jsx(Text, __assign({ as: "span", sx: {+ fontFamily: "body",+ fontSize: "menu",+ color: "fontTertiary",+ } }, { children: modifier })))] })] }), key)) })));}export default MenuItem;diff --git a/packages/editor/dist/components/menu/types.d.ts b/packages/editor/dist/components/menu/types.d.tsindex b654f7de1..843b21a8f 100644--- a/packages/editor/dist/components/menu/types.d.ts+++ b/packages/editor/dist/components/menu/types.d.ts@@ -1,9 +1,12 @@/// <reference types="react" />import { IconNames } from "../../toolbar/icons";+declare type MenuItemComponentProps = {+ onClick?: (e?: any) => void;+};export declare type MenuItem = {type: "menuitem" | "seperator";key: string;- component?: (props: any) => JSX.Element;+ component?: (props: MenuItemComponentProps) => JSX.Element;onClick?: () => void;title?: string;icon?: IconNames;@@ -15,3 +18,4 @@ export declare type MenuItem = {modifier?: string;items?: MenuItem[];};+export {};diff --git a/packages/editor/dist/toolbar/components/dropdown.d.ts b/packages/editor/dist/toolbar/components/dropdown.d.tsindex b51bc5ede..f1011513b 100644--- a/packages/editor/dist/toolbar/components/dropdown.d.ts+++ b/packages/editor/dist/toolbar/components/dropdown.d.ts@@ -4,6 +4,7 @@ declare type DropdownProps = {selectedItem: string | JSX.Element;items: MenuItem[];buttonRef?: React.MutableRefObject<HTMLButtonElement | undefined>;+ menuWidth?: number;};export declare function Dropdown(props: DropdownProps): JSX.Element;export {};diff --git a/packages/editor/dist/toolbar/components/dropdown.js b/packages/editor/dist/toolbar/components/dropdown.jsindex b39d24059..0041fee59 100644--- a/packages/editor/dist/toolbar/components/dropdown.js+++ b/packages/editor/dist/toolbar/components/dropdown.js@@ -32,7 +32,7 @@ import { Icon } from "./icon";import { Icons } from "../icons";import { MenuPresenter } from "../../components/menu/menu";export function Dropdown(props) {- var items = props.items, selectedItem = props.selectedItem, buttonRef = props.buttonRef;+ var items = props.items, selectedItem = props.selectedItem, buttonRef = props.buttonRef, menuWidth = props.menuWidth;var internalRef = useRef();var _a = __read(useState(false), 2), isOpen = _a[0], setIsOpen = _a[1];return (_jsxs(_Fragment, { children: [_jsxs(Button, __assign({ ref: function (ref) {@@ -50,7 +50,7 @@ export function Dropdown(props) {":last-of-type": {mr: 0,},- }, onClick: function () { return setIsOpen(function (s) { return !s; }); } }, { children: [typeof selectedItem === "string" ? (_jsx(Text, __assign({ sx: { fontSize: 12, mr: 1, color: "text" } }, { children: selectedItem }))) : (selectedItem), _jsx(Icon, { path: Icons.chevronDown, size: 16, color: "text" })] })), _jsx(MenuPresenter, { options: {+ }, onClick: function () { return setIsOpen(function (s) { return !s; }); } }, { children: [typeof selectedItem === "string" ? (_jsx(Text, __assign({ sx: { fontSize: 12, mr: 1, color: "text" } }, { children: selectedItem }))) : (selectedItem), _jsx(Icon, { path: Icons.chevronDown, size: 14, color: "text" })] })), _jsx(MenuPresenter, { options: {type: "menu",position: {target: internalRef.current || undefined,@@ -58,5 +58,5 @@ export function Dropdown(props) {location: "below",yOffset: 5,},- }, isOpen: isOpen, items: items, onClose: function () { return setIsOpen(false); } })] }));+ }, isOpen: isOpen, items: items, onClose: function () { return setIsOpen(false); }, sx: { minWidth: menuWidth } })] }));}diff --git a/packages/editor/dist/toolbar/components/splitbutton.d.ts b/packages/editor/dist/toolbar/components/splitbutton.d.tsnew file mode 100644index 000000000..416056db4--- /dev/null+++ b/packages/editor/dist/toolbar/components/splitbutton.d.ts@@ -0,0 +1,8 @@+import { PropsWithChildren } from "react";+import { ToolButtonProps } from "./tool-button";+import { MenuPresenterProps } from "../../components/menu/menu";+declare type SplitButtonProps = ToolButtonProps & {+ menuPresenterProps?: Partial<MenuPresenterProps>;+};+export declare function SplitButton(props: PropsWithChildren<SplitButtonProps>): JSX.Element;+export {};diff --git a/packages/editor/dist/toolbar/components/splitbutton.js b/packages/editor/dist/toolbar/components/splitbutton.jsnew file mode 100644index 000000000..cb9ed8fcb--- /dev/null+++ b/packages/editor/dist/toolbar/components/splitbutton.js@@ -0,0 +1,71 @@+var __assign = (this && this.__assign) || function () {+ __assign = Object.assign || function(t) {+ for (var s, i = 1, n = arguments.length; i < n; i++) {+ s = arguments[i];+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))+ t[p] = s[p];+ }+ return t;+ };+ return __assign.apply(this, arguments);+};+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};+var __read = (this && this.__read) || function (o, n) {+ var m = typeof Symbol === "function" && o[Symbol.iterator];+ if (!m) return o;+ var i = m.call(o), r, ar = [], e;+ try {+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);+ }+ catch (error) { e = { error: error }; }+ finally {+ try {+ if (r && !r.done && (m = i["return"])) m.call(i);+ }+ finally { if (e) throw e.error; }+ }+ return ar;+};+import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";+import { useRef, useState } from "react";+import { Button, Flex } from "rebass";+import { Icons } from "../icons";+import { Icon } from "./icon";+import { ToolButton } from "./tool-button";+import { MenuPresenter } from "../../components/menu/menu";+export function SplitButton(props) {+ var menuPresenterProps = props.menuPresenterProps, children = props.children, toolButtonProps = __rest(props, ["menuPresenterProps", "children"]);+ var _a = __read(useState(false), 2), isOpen = _a[0], setIsOpen = _a[1];+ var ref = useRef(null);+ return (_jsxs(_Fragment, { children: [_jsxs(Flex, __assign({ ref: ref, sx: {+ borderRadius: "default",+ bg: isOpen ? "hover" : "transparent",+ ":hover": { bg: "hover" },+ } }, { children: [_jsx(ToolButton, __assign({}, toolButtonProps)), _jsx(Button, __assign({ sx: {+ p: 0,+ m: 0,+ bg: "transparent",+ ":hover": { bg: "hover" },+ ":last-of-type": {+ mr: 0,+ },+ }, onClick: function () { return setIsOpen(function (s) { return !s; }); } }, { children: _jsx(Icon, { path: Icons.chevronDown, color: "text", size: 14 }) }))] })), _jsx(MenuPresenter, __assign({ isOpen: isOpen, onClose: function () { return setIsOpen(false); }, options: {+ type: "menu",+ position: {+ target: ref.current || undefined,+ isTargetAbsolute: true,+ location: "below",+ yOffset: 5,+ },+ }, items: [] }, menuPresenterProps, { children: children }))] }));+}diff --git a/packages/editor/dist/toolbar/components/toolbutton.d.ts b/packages/editor/dist/toolbar/components/toolbutton.d.tsindex 934abc304..824e90ced 100644--- a/packages/editor/dist/toolbar/components/toolbutton.d.ts+++ b/packages/editor/dist/toolbar/components/toolbutton.d.ts@@ -2,12 +2,11 @@ import { SchemeColors } from "@notesnook/theme/dist/theme/colorscheme";import React from "react";import { ButtonProps } from "rebass";import { IconNames } from "../icons";-declare type ToolButtonProps = ButtonProps & {+export declare type ToolButtonProps = ButtonProps & {icon: IconNames;iconColor?: keyof SchemeColors;iconSize?: number;toggled: boolean;- buttonRef?: React.Ref<HTMLButtonElement>;+ buttonRef?: React.MutableRefObject<HTMLButtonElement | null | undefined>;};export declare function ToolButton(props: ToolButtonProps): JSX.Element;-export {};diff --git a/packages/editor/dist/toolbar/floatingmenus/table.js b/packages/editor/dist/toolbar/floatingmenus/table.jsindex 9d3dd60a2..c8d886f5a 100644--- a/packages/editor/dist/toolbar/floatingmenus/table.js+++ b/packages/editor/dist/toolbar/floatingmenus/table.js@@ -77,7 +77,6 @@ import { Flex, Text } from "rebass";import { MenuPresenter } from "../../components/menu/menu";import { Popup } from "../components/popup";import { ToolButton } from "../components/tool-button";-import { ColorPicker, DEFAULT_COLORS } from "../tools/colors";import { selectedRect } from "prosemirror-tables";export function TableRowFloatingMenu(props) {var editor = props.editor;@@ -350,7 +349,7 @@ function ColorPickerTool(props) {isTargetAbsolute: true,yOffset: 5,},- } }, { children: _jsx(Flex, __assign({ sx: {+ } }, { children: _jsx(Flex, { sx: {flexDirection: "column",bg: "background",boxShadow: "menu",@@ -358,7 +357,7 @@ function ColorPickerTool(props) {borderRadius: "default",p: 1,width: 160,- } }, { children: _jsx(ColorPicker, { colors: DEFAULT_COLORS, color: color, onClear: function () { return onColorChange(); }, onChange: function (color) { return onColorChange(color); } }) })) }))] }));+ } }) }))] }));}/*** Done:diff --git a/packages/editor/dist/toolbar/icons.d.ts b/packages/editor/dist/toolbar/icons.d.tsindex d03aff89d..d22fd89bc 100644--- a/packages/editor/dist/toolbar/icons.d.ts+++ b/packages/editor/dist/toolbar/icons.d.ts@@ -65,5 +65,7 @@ export declare const Icons: {download: string;chevronDown: string;chevronUp: string;+ chevronRight: string;+ none: string;};export declare type IconNames = keyof typeof Icons;diff --git a/packages/editor/dist/toolbar/icons.js b/packages/editor/dist/toolbar/icons.jsindex 88c952cff..7bd0a850d 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, mdiTableColumnPlusAfter, mdiTableColumnPlusBefore, mdiTableColumnRemove, mdiUploadOutline, mdiPlus, mdiSquareRoundedBadgeOutline, mdiFormatColorFill, mdiBorderAllVariant, mdiClose, mdiSortDescending, mdiArrowExpandRight, mdiArrowExpandLeft, mdiArrowExpandDown, mdiArrowExpandUp, mdiTrashCanOutline, mdiTableMergeCells, mdiTableSplitCell, mdiDeleteOutline, mdiDownloadOutline, mdiFormatListCheckbox, mdiDrag, mdiCheckboxMarkedOutline, mdiChevronUp, mdiArrowUp, mdiArrowDown, mdiRegex, mdiFormatLetterCase, mdiFormatLetterMatches, mdiMoviePlusOutline, mdiLink, } 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, mdiDeleteOutline, mdiDownloadOutline, mdiFormatListCheckbox, mdiDrag, mdiCheckboxMarkedOutline, mdiChevronUp, mdiArrowUp, mdiArrowDown, mdiRegex, mdiFormatLetterCase, mdiFormatLetterMatches, mdiMoviePlusOutline, mdiLink, mdiChevronRight, } from "@mdi/js";export var Icons = {bold: mdiFormatBold,italic: mdiFormatItalic,@@ -66,4 +66,6 @@ export var Icons = {download: mdiDownloadOutline,chevronDown: mdiChevronDown,chevronUp: mdiChevronUp,+ chevronRight: mdiChevronRight,+ none: "",};diff --git a/packages/editor/dist/toolbar/popups/embedpopup.d.ts b/packages/editor/dist/toolbar/popups/embedpopup.d.tsindex 15a854407..dd78097a9 100644--- a/packages/editor/dist/toolbar/popups/embedpopup.d.ts+++ b/packages/editor/dist/toolbar/popups/embedpopup.d.ts@@ -4,8 +4,8 @@ import { IconNames } from "../icons";declare type Embed = Required<EmbedAttributes> & EmbedAlignmentOptions;export declare type EmbedPopupProps = {onClose: (embed: Embed) => void;- title: string;- icon: IconNames;+ title?: string;+ icon?: IconNames;embed?: Embed;onSizeChanged?: (size: EmbedSizeOptions) => void;onSourceChanged?: (src: string) => void;diff --git a/packages/editor/dist/toolbar/popups/tablepopup.d.ts b/packages/editor/dist/toolbar/popups/tablepopup.d.tsnew file mode 100644index 000000000..d69028602--- /dev/null+++ b/packages/editor/dist/toolbar/popups/tablepopup.d.ts@@ -0,0 +1,10 @@+/// <reference types="react" />+declare type TableSize = {+ columns: number;+ rows: number;+};+export declare type TablePopupProps = {+ onClose: (size: TableSize) => void;+};+export declare function TablePopup(props: TablePopupProps): JSX.Element;+export {};diff --git a/packages/editor/dist/toolbar/popups/tablepopup.js b/packages/editor/dist/toolbar/popups/tablepopup.jsnew file mode 100644index 000000000..bf78dc086--- /dev/null+++ b/packages/editor/dist/toolbar/popups/tablepopup.js@@ -0,0 +1,99 @@+var __assign = (this && this.__assign) || function () {+ __assign = Object.assign || function(t) {+ for (var s, i = 1, n = arguments.length; i < n; i++) {+ s = arguments[i];+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))+ t[p] = s[p];+ }+ return t;+ };+ return __assign.apply(this, arguments);+};+var __read = (this && this.__read) || function (o, n) {+ var m = typeof Symbol === "function" && o[Symbol.iterator];+ if (!m) return o;+ var i = m.call(o), r, ar = [], e;+ try {+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);+ }+ catch (error) { e = { error: error }; }+ finally {+ try {+ if (r && !r.done && (m = i["return"])) m.call(i);+ }+ finally { if (e) throw e.error; }+ }+ return ar;+};+import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";+import { Box, Flex, Text } from "rebass";+import { useEffect, useState } from "react";+var MAX_COLUMNS = 20;+var MAX_ROWS = 20;+var MIN_COLUMNS = 12;+var MIN_ROWS = 6;+export function TablePopup(props) {+ var onClose = props.onClose;+ var _a = __read(useState({+ column: 0,+ row: 0,+ }), 2), cellLocation = _a[0], setCellLocation = _a[1];+ var _b = __read(useState({+ columns: MIN_COLUMNS,+ rows: MIN_ROWS,+ }), 2), tableSize = _b[0], setTableSize = _b[1];+ useEffect(function () {+ setTableSize(function (old) {+ var columns = old.columns, rows = old.rows;+ var column = cellLocation.column, row = cellLocation.row;+ var isDecrease = row === rows - 2 || column === columns - 2;+ var rowFactor = Number(row === rows || row === rows - 2);+ var columnFactor = Number(column === columns || column === columns - 2);+ return {+ columns: isDecrease+ ? Math.max(column + columnFactor, MIN_COLUMNS)+ : Math.min(old.columns + columnFactor, MAX_COLUMNS),+ rows: isDecrease+ ? Math.max(row + rowFactor, MIN_ROWS)+ : Math.min(old.rows + rowFactor, MAX_ROWS),+ };+ });+ }, [cellLocation]);+ return (_jsxs(Flex, __assign({ sx: { p: 1, flexDirection: "column", alignItems: "center" } }, { children: [_jsx(Box, __assign({ sx: {+ display: "grid",+ gridTemplateColumns: "1fr ".repeat(tableSize.columns),+ gap: "3px",+ bg: "background",+ } }, { children: Array(tableSize.columns * tableSize.rows)+ .fill(0)+ .map(function (_, index) { return (_jsx(Box, { width: 15, height: 15, sx: {+ border: "1px solid var(--disabled)",+ borderRadius: "2px",+ bg: isCellHighlighted(index, cellLocation, tableSize)+ ? "disabled"+ : "transparent",+ ":hover": {+ bg: "disabled",+ },+ }, onMouseEnter: function () {+ setCellLocation(getCellLocation(index, tableSize));+ }, onClick: function () {+ onClose({+ columns: cellLocation.column,+ rows: cellLocation.row,+ });+ } })); }) })), _jsxs(Text, __assign({ variant: "body", sx: { mt: 1 } }, { children: [cellLocation.column, "x", cellLocation.row] }))] })));+}+function getCellLocation(index, tableSize) {+ var cellIndex = index + 1;+ var column = cellIndex % tableSize.columns;+ var row = cellIndex / tableSize.columns;+ var flooredRow = Math.floor(row);+ row = row === flooredRow ? row : flooredRow + 1;+ return { column: column ? column : tableSize.columns, row: row };+}+function isCellHighlighted(index, currentCellLocation, tableSize) {+ var cellLocation = getCellLocation(index, tableSize);+ return (cellLocation.row <= currentCellLocation.row &&+ cellLocation.column <= currentCellLocation.column);+}diff --git a/packages/editor/dist/toolbar/toolbar.js b/packages/editor/dist/toolbar/toolbar.jsindex 5ca0bfa46..98c352ced 100644--- a/packages/editor/dist/toolbar/toolbar.js+++ b/packages/editor/dist/toolbar/toolbar.js@@ -9,37 +9,113 @@ var __assign = (this && this.__assign) || function () {};return __assign.apply(this, arguments);};-import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};+var __read = (this && this.__read) || function (o, n) {+ var m = typeof Symbol === "function" && o[Symbol.iterator];+ if (!m) return o;+ var i = m.call(o), r, ar = [], e;+ try {+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);+ }+ catch (error) { e = { error: error }; }+ finally {+ try {+ if (r && !r.done && (m = i["return"])) m.call(i);+ }+ finally { if (e) throw e.error; }+ }+ return ar;+};+import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";import { useTheme } from "@notesnook/theme";import { Flex } from "rebass";import { findToolById } from "./tools";import { ThemeProvider } from "emotion-theming";import { EditorFloatingMenus } from "./floating-menus";+import { getToolDefinition } from "./tool-definitions";+import { ToolButton } from "./components/tool-button";+import { useContext, useRef, useState } from "react";+import { MenuPresenter } from "../components/menu";+import { Popup } from "./components/popup";+import React from "react";+var ToolbarContext = React.createContext({});export function Toolbar(props) {var editor = props.editor, theme = props.theme, accent = props.accent, scale = props.scale;var themeProperties = useTheme({ accent: accent, theme: theme, scale: scale });+ var _a = __read(useState(), 2), currentPopup = _a[0], setCurrentPopup = _a[1];var tools = [- ["bold", "italic", "underline", "strikethrough", "code"],- // ["fontSize", "fontFamily", "headings"],- // ["alignLeft", "alignCenter", "alignRight", "alignJustify"],- // ["subscript", "superscript", "horizontalRule"],- // ["codeblock", "blockquote"],- // ["formatClear", "ltr", "rtl"],- // ["numberedList", "bulletList", "checklist"],- // ["link", "image", "attachment", "table", "embed"],- // ["textColor", "highlight"],+ ["insertBlock"],+ [+ "bold",+ "italic",+ "underline",+ [+ "strikethrough",+ "code",+ "subscript",+ "superscript",+ "highlight",+ "textColor",+ ],+ ],+ ["fontSize", "headings", ["fontFamily"]],+ ["numberedList", "bulletList"],+ ["link"],+ ["alignCenter", ["alignLeft", "alignRight", "alignJustify", "ltr", "rtl"]],+ ["clearformatting"],];if (!editor)return null;- return (_jsxs(ThemeProvider, __assign({ theme: themeProperties }, { children: [_jsx(Flex, __assign({ className: "editor-toolbar", sx: { flexWrap: "wrap" } }, { children: tools.map(function (tools) {- return (_jsx(Flex, __assign({ className: "toolbar-group", sx: {- pr: 2,- mr: 2,- borderRight: "1px solid var(--border)",- ":last-of-type": { mr: 0, pr: 0, borderRight: "none" },- } }, { children: tools.map(function (toolId) {- var Component = findToolById(toolId);- return _jsx(Component, { editor: editor, id: toolId });- }) })));- }) })), _jsx(EditorFloatingMenus, { editor: editor })] })));+ return (_jsxs(ThemeProvider, __assign({ theme: themeProperties }, { children: [_jsx(ToolbarContext.Provider, __assign({ value: { setCurrentPopup: setCurrentPopup, currentPopup: currentPopup } }, { children: _jsx(Flex, __assign({ className: "editor-toolbar", sx: { flexWrap: "wrap" } }, { children: tools.map(function (tools) {+ return (_jsx(ToolbarGroup, { tools: tools, editor: editor, sx: {+ pr: 2,+ mr: 2,+ borderRight: "1px solid var(--border)",+ ":last-of-type": { mr: 0, pr: 0, borderRight: "none" },+ } }));+ }) })) })), _jsx(EditorFloatingMenus, { editor: editor })] })));+}+function ToolbarGroup(props) {+ var tools = props.tools, editor = props.editor, flexProps = __rest(props, ["tools", "editor"]);+ return (_jsx(Flex, __assign({ className: "toolbar-group" }, flexProps, { children: tools.map(function (toolId) {+ if (Array.isArray(toolId)) {+ return (_jsx(MoreTools, { popupId: toolId.join(""), tools: toolId, editor: editor }));+ }+ else {+ var Component = findToolById(toolId);+ var toolDefinition = getToolDefinition(toolId);+ return _jsx(Component, __assign({ editor: editor, id: toolId }, toolDefinition));+ }+ }) })));+}+function MoreTools(props) {+ var popupId = props.popupId;+ var _a = useContext(ToolbarContext), currentPopup = _a.currentPopup, setCurrentPopup = _a.setCurrentPopup;+ var buttonRef = useRef();+ var show = popupId === currentPopup;+ var setShow = function (state) {+ return setCurrentPopup === null || setCurrentPopup === void 0 ? void 0 : setCurrentPopup(state ? popupId : undefined);+ };+ return (_jsxs(_Fragment, { children: [_jsx(ToolButton, { icon: "more", title: "More", toggled: show, buttonRef: buttonRef, onClick: function () { return setShow(!show); } }), _jsx(MenuPresenter, __assign({ isOpen: show, onClose: function () { return setShow(false); }, items: [], options: {+ type: "autocomplete",+ position: {+ isTargetAbsolute: true,+ target: buttonRef.current || "mouse",+ align: "center",+ location: "below",+ yOffset: 5,+ },+ } }, { children: _jsx(Popup, { children: _jsx(ToolbarGroup, { tools: props.tools, editor: props.editor, sx: {+ p: 1,+ } }) }) }))] }));}diff --git a/packages/editor/dist/toolbar/tooldefinitions.d.ts b/packages/editor/dist/toolbar/tooldefinitions.d.tsnew file mode 100644index 000000000..f56f4264a--- /dev/null+++ b/packages/editor/dist/toolbar/tooldefinitions.d.ts@@ -0,0 +1,3 @@+import { ToolDefinition } from "./types";+import { ToolId } from "./tools";+export declare function getToolDefinition(id: ToolId): ToolDefinition;diff --git a/packages/editor/dist/toolbar/tooldefinitions.js b/packages/editor/dist/toolbar/tooldefinitions.jsnew file mode 100644index 000000000..3960b3767--- /dev/null+++ b/packages/editor/dist/toolbar/tooldefinitions.js@@ -0,0 +1,97 @@+var tools = {+ bold: {+ icon: "bold",+ title: "Bold",+ },+ italic: {+ icon: "italic",+ title: "Italic",+ },+ underline: {+ icon: "underline",+ title: "Underline",+ },+ strikethrough: {+ icon: "strikethrough",+ title: "Strikethrough",+ },+ link: {+ icon: "link",+ title: "Link",+ },+ code: {+ icon: "code",+ title: "Code",+ },+ clearformatting: {+ icon: "formatClear",+ title: "Clear all formatting",+ },+ subscript: {+ icon: "subscript",+ title: "Subscript",+ },+ superscript: {+ icon: "superscript",+ title: "Superscript",+ },+ insertBlock: {+ icon: "plus",+ title: "Insert",+ },+ bulletList: {+ icon: "bulletList",+ title: "Bullet list",+ },+ numberedList: {+ icon: "numberedList",+ title: "Numbered list",+ },+ fontFamily: {+ icon: "none",+ title: "Font family",+ },+ fontSize: {+ icon: "none",+ title: "Font size",+ },+ headings: {+ icon: "none",+ title: "Headings",+ },+ alignCenter: {+ icon: "alignCenter",+ title: "Align center",+ },+ alignLeft: {+ icon: "alignLeft",+ title: "Align left",+ },+ alignRight: {+ icon: "alignRight",+ title: "Align right",+ },+ alignJustify: {+ icon: "alignJustify",+ title: "Justify",+ },+ ltr: {+ icon: "ltr",+ title: "Left to right",+ },+ rtl: {+ icon: "rtl",+ title: "Right to left",+ },+ highlight: {+ icon: "highlight",+ title: "Highlight",+ },+ textColor: {+ icon: "textColor",+ title: "Text color",+ },+};+export function getToolDefinition(id) {+ return tools[id];+}diff --git a/packages/editor/dist/toolbar/tools/alignment.d.ts b/packages/editor/dist/toolbar/tools/alignment.d.tsindex 3e93ca384..6e121e63e 100644--- a/packages/editor/dist/toolbar/tools/alignment.d.ts+++ b/packages/editor/dist/toolbar/tools/alignment.d.ts@@ -1,25 +1,6 @@/// <reference types="react" />-import { ITool, ToolProps } from "../types";-import { ToolId } from ".";-import { IconNames } from "../icons";-declare class AlignmentTool<TId extends ToolId, TTitle extends string> implements ITool {- readonly id: TId;- readonly title: TTitle;- private readonly alignment;- private readonly icon;- constructor(id: TId, title: TTitle, alignment: "left" | "right" | "center" | "justify", icon: IconNames);- render: (props: ToolProps) => JSX.Element;-}-export declare class AlignCenter extends AlignmentTool<ToolId, string> {- constructor();-}-export declare class AlignRight extends AlignmentTool<ToolId, string> {- constructor();-}-export declare class AlignLeft extends AlignmentTool<ToolId, string> {- constructor();-}-export declare class AlignJustify extends AlignmentTool<ToolId, string> {- constructor();-}-export {};+import { ToolProps } from "../types";+export declare function AlignCenter(props: ToolProps): JSX.Element;+export declare function AlignLeft(props: ToolProps): JSX.Element;+export declare function AlignRight(props: ToolProps): JSX.Element;+export declare function AlignJustify(props: ToolProps): JSX.Element;diff --git a/packages/editor/dist/toolbar/tools/alignment.js b/packages/editor/dist/toolbar/tools/alignment.jsindex 706356f12..9ea25b34e 100644--- a/packages/editor/dist/toolbar/tools/alignment.js+++ b/packages/editor/dist/toolbar/tools/alignment.js@@ -1,65 +1,40 @@-var __extends = (this && this.__extends) || (function () {- var extendStatics = function (d, b) {- extendStatics = Object.setPrototypeOf ||- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };- return extendStatics(d, b);+var __assign = (this && this.__assign) || function () {+ __assign = Object.assign || function(t) {+ for (var s, i = 1, n = arguments.length; i < n; i++) {+ s = arguments[i];+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))+ t[p] = s[p];+ }+ return t;};- return function (d, b) {- if (typeof b !== "function" && b !== null)- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");- extendStatics(d, b);- function __() { this.constructor = d; }- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());- };-})();+ return __assign.apply(this, arguments);+};+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};import { jsx as _jsx } from "react/jsx-runtime";import { ToolButton } from "../components/tool-button";-var AlignmentTool = /** @class */ (function () {- function AlignmentTool(id, title, alignment, icon) {- var _this = this;- this.id = id;- this.title = title;- this.alignment = alignment;- this.icon = icon;- this.render = function (props) {- var editor = props.editor;- return (_jsx(ToolButton, { title: _this.title, id: _this.id, icon: _this.icon, onClick: function () {- return editor.chain().focus().setTextAlign(_this.alignment).run();- }, toggled: editor.isActive({ textAlign: _this.alignment }) }));- };- }- return AlignmentTool;-}());-var AlignCenter = /** @class */ (function (_super) {- __extends(AlignCenter, _super);- function AlignCenter() {- return _super.call(this, "alignCenter", "Align center", "center", "alignCenter") || this;- }- return AlignCenter;-}(AlignmentTool));-export { AlignCenter };-var AlignRight = /** @class */ (function (_super) {- __extends(AlignRight, _super);- function AlignRight() {- return _super.call(this, "alignRight", "Align right", "right", "alignRight") || this;- }- return AlignRight;-}(AlignmentTool));-export { AlignRight };-var AlignLeft = /** @class */ (function (_super) {- __extends(AlignLeft, _super);- function AlignLeft() {- return _super.call(this, "alignLeft", "Align left", "left", "alignLeft") || this;- }- return AlignLeft;-}(AlignmentTool));-export { AlignLeft };-var AlignJustify = /** @class */ (function (_super) {- __extends(AlignJustify, _super);- function AlignJustify() {- return _super.call(this, "alignJustify", "Justify", "justify", "alignJustify") || this;- }- return AlignJustify;-}(AlignmentTool));-export { AlignJustify };+function AlignmentTool(props) {+ var editor = props.editor, alignment = props.alignment, toolProps = __rest(props, ["editor", "alignment"]);+ return (_jsx(ToolButton, __assign({}, toolProps, { onClick: function () { return editor.chain().focus().setTextAlign(alignment).run(); }, toggled: editor.isActive({ textAlign: alignment }) })));+}+export function AlignCenter(props) {+ return _jsx(AlignmentTool, __assign({ alignment: "center" }, props));+}+export function AlignLeft(props) {+ return _jsx(AlignmentTool, __assign({ alignment: "left" }, props));+}+export function AlignRight(props) {+ return _jsx(AlignmentTool, __assign({ alignment: "right" }, props));+}+export function AlignJustify(props) {+ return _jsx(AlignmentTool, __assign({ alignment: "justify" }, props));+}diff --git a/packages/editor/dist/toolbar/tools/block.d.ts b/packages/editor/dist/toolbar/tools/block.d.tsindex c9c743822..9ab2e4d50 100644--- a/packages/editor/dist/toolbar/tools/block.d.ts+++ b/packages/editor/dist/toolbar/tools/block.d.ts@@ -1,44 +1,3 @@/// <reference types="react" />-import { ITool, ToolProps } from "../types";-import { Editor } from "@tiptap/core";-import { ToolId } from ".";-import { IconNames } from "../icons";-declare class BlockTool<TId extends ToolId> implements ITool {- readonly id: TId;- readonly title: string;- private readonly icon;- private readonly command;- constructor(id: TId, title: string, icon: IconNames, command: (editor: Editor) => boolean);- render: (props: ToolProps) => JSX.Element;-}-export declare class HorizontalRule extends BlockTool<ToolId> {- constructor();-}-export declare class CodeBlock extends BlockTool<ToolId> {- constructor();-}-export declare class Blockquote extends BlockTool<ToolId> {- constructor();-}-export declare class Image implements ITool {- id: ToolId;- title: string;- render: (props: ToolProps) => JSX.Element;-}-export declare class Embed implements ITool {- id: ToolId;- title: string;- render: (props: ToolProps) => JSX.Element;-}-export declare class Table implements ITool {- id: ToolId;- title: string;- private MAX_COLUMNS;- private MAX_ROWS;- private MIN_COLUMNS;- private MIN_ROWS;- render: (props: ToolProps) => JSX.Element;- private getCellLocation;- private isCellHighlighted;-}-export {};+import { ToolProps } from "../types";+export declare function InsertBlock(props: ToolProps): JSX.Element;diff --git a/packages/editor/dist/toolbar/tools/block.js b/packages/editor/dist/toolbar/tools/block.jsindex 90518f945..58fd1543f 100644--- a/packages/editor/dist/toolbar/tools/block.js+++ b/packages/editor/dist/toolbar/tools/block.js@@ -1,18 +1,3 @@-var __extends = (this && this.__extends) || (function () {- var extendStatics = function (d, b) {- extendStatics = Object.setPrototypeOf ||- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };- return extendStatics(d, b);- };- return function (d, b) {- if (typeof b !== "function" && b !== null)- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");- extendStatics(d, b);- function __() { this.constructor = d; }- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());- };-})();var __assign = (this && this.__assign) || function () {__assign = Object.assign || function(t) {for (var s, i = 1, n = arguments.length; i < n; i++) {@@ -41,212 +26,130 @@ var __read = (this && this.__read) || function (o, n) {return ar;};import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";-import { ToolButton } from "../components/tool-button";import { Icons } from "../icons";import { MenuPresenter } from "../../components/menu/menu";-import { useEffect, useRef, useState } from "react";-import { Dropdown } from "../components/dropdown";+import { useRef, useState } from "react";import { Icon } from "../components/icon";-import { Box, Button, Flex, Text } from "rebass";-import { Popup } from "../components/popup";-import { EmbedPopup } from "../popups/embed-popup";-var BlockTool = /** @class */ (function () {- function BlockTool(id, title, icon, command) {- var _this = this;- this.id = id;- this.title = title;- this.icon = icon;- this.command = command;- this.render = function (props) {- var editor = props.editor;- return (_jsx(ToolButton, { id: _this.id, title: _this.title, icon: _this.icon, onClick: function () { return _this.command(editor); }, toggled: editor.isActive(_this.id) }));- };- }- return BlockTool;-}());-var HorizontalRule = /** @class */ (function (_super) {- __extends(HorizontalRule, _super);- function HorizontalRule() {- return _super.call(this, "horizontalRule", "Horizontal rule", "horizontalRule", function (editor) {- return editor.chain().focus().setHorizontalRule().run();- }) || this;- }- return HorizontalRule;-}(BlockTool));-export { HorizontalRule };-var CodeBlock = /** @class */ (function (_super) {- __extends(CodeBlock, _super);- function CodeBlock() {- return _super.call(this, "codeblock", "Codeblock", "codeblock", function (editor) {- return editor.chain().focus().toggleCodeBlock().run();- }) || this;- }- return CodeBlock;-}(BlockTool));-export { CodeBlock };-var Blockquote = /** @class */ (function (_super) {- __extends(Blockquote, _super);- function Blockquote() {- return _super.call(this, "blockquote", "Blockquote", "blockquote", function (editor) {- return editor.chain().focus().toggleBlockquote().run();- }) || this;- }- return Blockquote;-}(BlockTool));-export { Blockquote };-var Image = /** @class */ (function () {- function Image() {- this.id = "image";- this.title = "Image";- this.render = function (props) {- var editor = props.editor;- return (_jsx(_Fragment, { children: _jsx(Dropdown, { selectedItem: _jsx(Icon, { path: Icons.image, size: 16 }), items: [- {- key: "upload-from-disk",- type: "menuitem",- title: "Upload from disk",- icon: "upload",- onClick: function () { },- },- {- key: "upload-from-url",- type: "menuitem",- title: "Attach from URL",- icon: "link",- onClick: function () { },- },- ] }) }));- };- }- return Image;-}());-export { Image };-var Embed = /** @class */ (function () {- function Embed() {- var _this = this;- this.id = "embed";- this.title = "Embed";- this.render = function (props) {- var editor = props.editor;- var _a = __read(useState(false), 2), isOpen = _a[0], setIsOpen = _a[1];- var buttonRef = useRef(null);- return (_jsxs(_Fragment, { children: [_jsx(ToolButton, { buttonRef: buttonRef, id: _this.id, title: _this.title, icon: "embed", onClick: function () { return setIsOpen(function (s) { return !s; }); }, toggled: isOpen }), _jsx(MenuPresenter, __assign({ isOpen: isOpen, items: [], onClose: function () { return setIsOpen(false); }, options: {- type: "menu",- position: {- target: buttonRef.current || undefined,- isTargetAbsolute: true,- location: "below",- yOffset: 10,- },- } }, { children: _jsx(EmbedPopup, { title: "Insert embed", icon: "check", onClose: function (embed) {- editor.chain().focus().insertEmbed(embed).run();- } }) }))] }));- };- }- return Embed;-}());-export { Embed };-var Table = /** @class */ (function () {- function Table() {- var _this = this;- this.id = "table";- this.title = "Table";- this.MAX_COLUMNS = 20;- this.MAX_ROWS = 20;- this.MIN_COLUMNS = 4;- this.MIN_ROWS = 4;- this.render = function (props) {- var editor = props.editor;- var _a = __read(useState(false), 2), isOpen = _a[0], setIsOpen = _a[1];- var ref = useRef(null);- var _b = __read(useState({- column: 0,- row: 0,- }), 2), cellLocation = _b[0], setCellLocation = _b[1];- var _c = __read(useState({- columns: _this.MIN_COLUMNS,- rows: _this.MIN_ROWS,- }), 2), tableSize = _c[0], setTableSize = _c[1];- useEffect(function () {- setTableSize(function (old) {- var columns = old.columns, rows = old.rows;- var column = cellLocation.column, row = cellLocation.row;- var isDecrease = row === rows - 2 || column === columns - 2;- var rowFactor = Number(row === rows || row === rows - 2);- var columnFactor = Number(column === columns || column === columns - 2);- return {- columns: isDecrease- ? Math.max(column + columnFactor, _this.MIN_COLUMNS)- : Math.min(old.columns + columnFactor, _this.MAX_COLUMNS),- rows: isDecrease- ? Math.max(row + rowFactor, _this.MIN_ROWS)- : Math.min(old.rows + rowFactor, _this.MAX_ROWS),- };- });- }, [cellLocation]);- return (_jsxs(Flex, __assign({ ref: ref }, { children: [_jsxs(Button, __assign({ sx: {- p: 1,- m: 0,- bg: isOpen ? "hover" : "transparent",- mr: 1,- display: "flex",- alignItems: "center",- ":hover": { bg: "hover" },- ":last-of-type": {- mr: 0,- },- }, onClick: function () { return setIsOpen(function (s) { return !s; }); } }, { children: [_jsx(Icon, { path: Icons.table, color: "text", size: 18 }), _jsx(Icon, { path: Icons.chevronDown, color: "text", size: 18 })] })), _jsx(MenuPresenter, __assign({ isOpen: isOpen, onClose: function () { return setIsOpen(false); }, items: [], options: {- type: "menu",- position: {- target: ref.current || undefined,- isTargetAbsolute: true,- location: "below",- yOffset: 5,- },- } }, { children: _jsx(Popup, { children: _jsxs(Flex, __assign({ sx: { p: 1, flexDirection: "column", alignItems: "center" } }, { children: [_jsx(Box, __assign({ sx: {- display: "grid",- gridTemplateColumns: "1fr ".repeat(tableSize.columns),- gap: "3px",- bg: "background",- } }, { children: Array(tableSize.columns * tableSize.rows)- .fill(0)- .map(function (_, index) { return (_jsx(Box, { width: 15, height: 15, sx: {- border: "1px solid var(--disabled)",- borderRadius: "2px",- bg: _this.isCellHighlighted(index, cellLocation, tableSize)- ? "disabled"- : "transparent",- ":hover": {- bg: "disabled",- },- }, onMouseEnter: function () {- setCellLocation(_this.getCellLocation(index, tableSize));- }, onClick: function () {- editor- .chain()- .focus()- .insertTable({- cols: cellLocation.column,- rows: cellLocation.row,- })- .run();- setIsOpen(false);- } })); }) })), _jsxs(Text, __assign({ variant: "body", sx: { mt: 1 } }, { children: [cellLocation.column, "x", cellLocation.row] }))] })) }) }))] })));- };- }- Table.prototype.getCellLocation = function (index, tableSize) {- var cellIndex = index + 1;- var column = cellIndex % tableSize.columns;- var row = cellIndex / tableSize.columns;- var flooredRow = Math.floor(row);- row = row === flooredRow ? row : flooredRow + 1;- return { column: column ? column : tableSize.columns, row: row };- };- Table.prototype.isCellHighlighted = function (index, currentCellLocation, tableSize) {- var cellLocation = this.getCellLocation(index, tableSize);- return (cellLocation.row <= currentCellLocation.row &&- cellLocation.column <= currentCellLocation.column);- };- return Table;-}());-export { Table };+import { Button } from "rebass";+import { TablePopup } from "../popups/table-popup";+export function InsertBlock(props) {+ var buttonRef = useRef();+ var _a = __read(useState(false), 2), isOpen = _a[0], setIsOpen = _a[1];+ return (_jsxs(_Fragment, { children: [_jsx(Button, __assign({ ref: buttonRef, sx: {+ p: 1,+ m: 0,+ bg: isOpen ? "hover" : "transparent",+ mr: 1,+ display: "flex",+ alignItems: "center",+ ":hover": { bg: "hover" },+ ":last-of-type": {+ mr: 0,+ },+ }, onClick: function () { return setIsOpen(function (s) { return !s; }); } }, { children: _jsx(Icon, { path: Icons.plus, size: 18, color: "primary" }) })), _jsx(MenuPresenter, { options: {+ type: "menu",+ position: {+ target: buttonRef.current || undefined,+ isTargetAbsolute: true,+ location: "below",+ yOffset: 5,+ },+ }, isOpen: isOpen, items: [+ tasklist(editor),+ horizontalRule(editor),+ codeblock(editor),+ blockquote(editor),+ image(editor),+ attachment(editor),+ embed(editor),+ table(editor),+ ], onClose: function () { return setIsOpen(false); } })] }));+}+var horizontalRule = function (editor) { return ({+ key: "hr",+ type: "menuitem",+ title: "Horizontal rule",+ icon: "horizontalRule",+ isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("horizontalRule"),+ onClick: function () { return editor === null || editor === void 0 ? void 0 : editor.chain().focus().setHorizontalRule().run(); },+}); };+var codeblock = function (editor) { return ({+ key: "codeblock",+ type: "menuitem",+ title: "Code block",+ icon: "codeblock",+ isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("codeBlock"),+ onClick: function () { return editor === null || editor === void 0 ? void 0 : editor.chain().focus().toggleCodeBlock().run(); },+}); };+var blockquote = function (editor) { return ({+ key: "blockquote",+ type: "menuitem",+ title: "Quote",+ icon: "blockquote",+ isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("blockQuote"),+ onClick: function () { return editor === null || editor === void 0 ? void 0 : editor.chain().focus().toggleBlockquote().run(); },+}); };+var image = function (editor) { return ({+ key: "image",+ type: "menuitem",+ title: "Image",+ icon: "image",+ items: [+ {+ key: "upload-from-disk",+ type: "menuitem",+ title: "Upload from disk",+ icon: "upload",+ onClick: function () { },+ },+ {+ key: "upload-from-url",+ type: "menuitem",+ title: "Attach from URL",+ icon: "link",+ onClick: function () { },+ },+ ],+}); };+var embed = function (editor) { return ({+ key: "embed",+ type: "menuitem",+ title: "Embed",+ icon: "embed",+}); };+var table = function (editor) { return ({+ key: "table",+ type: "menuitem",+ title: "Table",+ icon: "table",+ items: [+ {+ key: "table-size-selector",+ type: "menuitem",+ component: function (props) { return (_jsx(TablePopup, { onClose: function (size) {+ var _a;+ editor === null || editor === void 0 ? void 0 : editor.chain().focus().insertTable({+ rows: size.rows,+ cols: size.columns,+ }).run();+ (_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props);+ } })); },+ },+ ],+}); };+var attachment = function (editor) { return ({+ key: "attachment",+ type: "menuitem",+ title: "Attachment",+ icon: "attachment",+ isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("attachment"),+ onClick: function () { return editor === null || editor === void 0 ? void 0 : editor.chain().focus().openAttachmentPicker().run(); },+}); };+var tasklist = function (editor) { return ({+ key: "tasklist",+ type: "menuitem",+ title: "Task list",+ icon: "checkbox",+ isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("taskList"),+ onClick: function () { return editor === null || editor === void 0 ? void 0 : editor.chain().focus().toggleTaskList().run(); },+}); };diff --git a/packages/editor/dist/toolbar/tools/colors.d.ts b/packages/editor/dist/toolbar/tools/colors.d.tsindex 0584f5fbc..2b501e6fc 100644--- a/packages/editor/dist/toolbar/tools/colors.d.ts+++ b/packages/editor/dist/toolbar/tools/colors.d.ts@@ -1,23 +1,8 @@/// <reference types="react" />-import { ITool, ToolProps } from "../types";-import { Editor } from "@tiptap/core";-import { ToolId } from ".";-import { IconNames } from "../icons";+import { ToolProps } from "../types";export declare const DEFAULT_COLORS: string[];-declare class ColorTool implements ITool {- readonly id: ToolId;- readonly title: string;- private readonly icon;- private readonly onColorChange;- constructor(id: ToolId, title: string, icon: IconNames, onColorChange: (editor: Editor, color?: string) => void);- render: (props: ToolProps) => JSX.Element;-}-export declare class Highlight extends ColorTool {- constructor();-}-export declare class TextColor extends ColorTool {- constructor();-}+export declare function Highlight(props: ToolProps): JSX.Element;+export declare function TextColor(props: ToolProps): JSX.Element;declare type ColorPickerProps = {colors: string[];color: string;diff --git a/packages/editor/dist/toolbar/tools/colors.js b/packages/editor/dist/toolbar/tools/colors.jsindex 1c20cf21d..cab7467eb 100644--- a/packages/editor/dist/toolbar/tools/colors.js+++ b/packages/editor/dist/toolbar/tools/colors.js@@ -1,18 +1,3 @@-var __extends = (this && this.__extends) || (function () {- var extendStatics = function (d, b) {- extendStatics = Object.setPrototypeOf ||- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };- return extendStatics(d, b);- };- return function (d, b) {- if (typeof b !== "function" && b !== null)- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");- extendStatics(d, b);- function __() { this.constructor = d; }- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());- };-})();var __assign = (this && this.__assign) || function () {__assign = Object.assign || function(t) {for (var s, i = 1, n = arguments.length; i < n; i++) {@@ -24,6 +9,17 @@ var __assign = (this && this.__assign) || function () {};return __assign.apply(this, arguments);};+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};var __read = (this && this.__read) || function (o, n) {var m = typeof Symbol === "function" && o[Symbol.iterator];if (!m) return o;@@ -45,9 +41,8 @@ import { Box, Button, Flex, Text } from "rebass";import { Input } from "@rebass/forms";import { Icon } from "../components/icon";import { Icons } from "../icons";-import { ToolButton } from "../components/tool-button";-import { MenuPresenter } from "../../components/menu/menu";-import { useRef, useState } from "react";+import { SplitButton } from "../components/split-button";+import { useState } from "react";import tinycolor from "tinycolor2";export var DEFAULT_COLORS = ["#f44336",@@ -65,75 +60,37 @@ export var DEFAULT_COLORS = ["#ffeb3b","#ffc107",];-var ColorTool = /** @class */ (function () {- function ColorTool(id, title, icon, onColorChange) {- var _this = this;- this.id = id;- this.title = title;- this.icon = icon;- this.onColorChange = onColorChange;- this.render = function (props) {- var editor = props.editor;- var _a = __read(useState(false), 2), isOpen = _a[0], setIsOpen = _a[1];- var attrs = editor.getAttributes(_this.id === "highlight" ? "highlight" : "textStyle");- var ref = useRef(null);- var isActive = editor.isActive(_this.id === "highlight" ? "highlight" : "textStyle", { color: /\W+/gm });- return (_jsxs(Flex, __assign({ ref: ref }, { children: [_jsx(ToolButton, { title: _this.title, id: _this.id, icon: _this.icon, onClick: function () { }, toggled: false, sx: { mr: 0, bg: isActive ? attrs.color : "transparent" } }), _jsx(Button, __assign({ sx: {- p: 0,- m: 0,- bg: "transparent",- ":hover": { bg: "hover" },- ":last-of-type": {- mr: 0,- },- }, onClick: function () { return setIsOpen(function (s) { return !s; }); } }, { children: _jsx(Icon, { path: Icons.chevronDown, color: "text", size: 18 }) })), _jsx(MenuPresenter, __assign({ isOpen: isOpen, onClose: function () { return setIsOpen(false); }, items: [],- // sx={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr", p: 1 }}- options: {- type: "menu",- position: {- target: ref.current || undefined,- isTargetAbsolute: true,- location: "below",- align: "center",- yOffset: 5,- },- } }, { children: _jsx(Flex, __assign({ sx: {- flexDirection: "column",- bg: "background",- boxShadow: "menu",- border: "1px solid var(--border)",- borderRadius: "default",- p: 1,- width: 160,- } }, { children: _jsx(ColorPicker, { colors: DEFAULT_COLORS, color: attrs.color, onClear: function () { return _this.onColorChange(editor); }, onChange: function (color) { return _this.onColorChange(editor, color); } }) })) }))] })));- };- }- return ColorTool;-}());-var Highlight = /** @class */ (function (_super) {- __extends(Highlight, _super);- function Highlight() {- return _super.call(this, "highlight", "Highlight", "highlight", function (editor, color) {+function ColorTool(props) {+ var editor = props.editor, onColorChange = props.onColorChange, isActive = props.isActive, getActiveColor = props.getActiveColor, toolProps = __rest(props, ["editor", "onColorChange", "isActive", "getActiveColor"]);+ var activeColor = getActiveColor(editor);+ var _isActive = isActive(editor);+ return (_jsx(SplitButton, __assign({}, toolProps, { toggled: false, sx: {+ mr: 0,+ bg: _isActive ? activeColor : "transparent",+ } }, { children: _jsx(Flex, __assign({ sx: {+ flexDirection: "column",+ bg: "background",+ boxShadow: "menu",+ border: "1px solid var(--border)",+ borderRadius: "default",+ p: 1,+ width: 160,+ } }, { children: _jsx(ColorPicker, { colors: DEFAULT_COLORS, color: activeColor, onClear: function () { return onColorChange(editor); }, onChange: function (color) { return onColorChange(editor, color); } }) })) })));+}+export function Highlight(props) {+ return (_jsx(ColorTool, __assign({}, props, { isActive: function (editor) { return editor.isActive("highlight", { color: /\W+/gm }); }, getActiveColor: function (editor) { return editor.getAttributes("highlight").color; }, onColorChange: function (editor, color) {return color? editor.chain().focus().toggleHighlight({ color: color }).run(): editor.chain().focus().unsetHighlight().run();- }) || this;- }- return Highlight;-}(ColorTool));-export { Highlight };-var TextColor = /** @class */ (function (_super) {- __extends(TextColor, _super);- function TextColor() {- return _super.call(this, "textColor", "Text color", "textColor", function (editor, color) {+ } })));+}+export function TextColor(props) {+ return (_jsx(ColorTool, __assign({}, props, { isActive: function (editor) { return editor.isActive("textStyle", { color: /\W+/gm }); }, getActiveColor: function (editor) { return editor.getAttributes("textStyle").color; }, onColorChange: function (editor, color) {return color? editor.chain().focus().setColor(color).run(): editor.chain().focus().unsetColor().run();- }) || this;- }- return TextColor;-}(ColorTool));-export { TextColor };+ } })));+}export function ColorPicker(props) {var colors = props.colors, color = props.color, onClear = props.onClear, onChange = props.onChange;var _a = __read(useState(tinycolor(color || colors[0]).toHexString()), 2), currentColor = _a[0], setCurrentColor = _a[1];diff --git a/packages/editor/dist/toolbar/tools/font.d.ts b/packages/editor/dist/toolbar/tools/font.d.tsindex 180bbba6e..e7818addd 100644--- a/packages/editor/dist/toolbar/tools/font.d.ts+++ b/packages/editor/dist/toolbar/tools/font.d.ts@@ -1,16 +1,4 @@/// <reference types="react" />-import { ITool, ToolProps } from "../types";-import { ToolId } from ".";-export declare class FontSize implements ITool {- title: string;- id: ToolId;- private defaultFontSizes;- render: (props: ToolProps) => JSX.Element;-}-export declare class FontFamily implements ITool {- title: string;- id: ToolId;- private fontFamilies;- render: (props: ToolProps) => JSX.Element;- private toMenuItems;-}+import { ToolProps } from "../types";+export declare function FontSize(props: ToolProps): JSX.Element;+export declare function FontFamily(props: ToolProps): JSX.Element;diff --git a/packages/editor/dist/toolbar/tools/font.js b/packages/editor/dist/toolbar/tools/font.jsindex a77fa466b..61e5a0a82 100644--- a/packages/editor/dist/toolbar/tools/font.js+++ b/packages/editor/dist/toolbar/tools/font.js@@ -16,70 +16,51 @@ var __read = (this && this.__read) || function (o, n) {};import { jsx as _jsx } from "react/jsx-runtime";import { Dropdown } from "../components/dropdown";-var FontSize = /** @class */ (function () {- function FontSize() {- var _this = this;- this.title = "Font size";- this.id = "fontSize";- this.defaultFontSizes = [- 12, 14, 16, 18, 20, 24, 28, 32, 36, 42, 48, 60, 72, 100,- ];- this.render = function (props) {- var editor = props.editor;- var currentFontSize = _this.defaultFontSizes.find(function (size) {- return editor.isActive("textStyle", { fontSize: "".concat(size, "px") });- }) || 16;- return (_jsx(Dropdown, { selectedItem: "".concat(currentFontSize, "px"), items: _this.defaultFontSizes.map(function (size) { return ({- key: "".concat(size, "px"),- type: "menuitem",- title: "".concat(size, "px"),- isChecked: size === currentFontSize,- onClick: function () { return editor.chain().focus().setFontSize("".concat(size, "px")).run(); },- }); }) }));- };- }- return FontSize;-}());-export { FontSize };-var FontFamily = /** @class */ (function () {- function FontFamily() {- var _this = this;- this.title = "Font family";- this.id = "fontFamily";- this.fontFamilies = {- System: "Open Sans",- Serif: "serif",- Monospace: "monospace",- };- this.render = function (props) {- var _a, _b;- var editor = props.editor;- var currentFontFamily = ((_b = (_a = Object.entries(_this.fontFamilies)- .find(function (_a) {- var _b = __read(_a, 2), key = _b[0], value = _b[1];- return editor.isActive("textStyle", { fontFamily: value });- })) === null || _a === void 0 ? void 0 : _a.map(function (a) { return a; })) === null || _b === void 0 ? void 0 : _b.at(0)) || "System";- return (_jsx(Dropdown, { selectedItem: currentFontFamily, items: _this.toMenuItems(editor, currentFontFamily) }));- };- }- FontFamily.prototype.toMenuItems = function (editor, currentFontFamily) {- var menuItems = [];- var _loop_1 = function (key) {- var value = this_1.fontFamilies[key];- menuItems.push({- key: key,- type: "menuitem",- title: key,- isChecked: key === currentFontFamily,- onClick: function () { return editor.chain().focus().setFontFamily(value).run(); },- });- };- var this_1 = this;- for (var key in this.fontFamilies) {- _loop_1(key);- }- return menuItems;+var defaultFontSizes = [+ 12, 14, 16, 18, 20, 24, 28, 32, 36, 42, 48, 60, 72, 100,+];+export function FontSize(props) {+ var editor = props.editor;+ var currentFontSize = defaultFontSizes.find(function (size) {+ return editor.isActive("textStyle", { fontSize: "".concat(size, "px") });+ }) || 16;+ return (_jsx(Dropdown, { selectedItem: "".concat(currentFontSize, "px"), items: defaultFontSizes.map(function (size) { return ({+ key: "".concat(size, "px"),+ type: "menuitem",+ title: "".concat(size, "px"),+ isChecked: size === currentFontSize,+ onClick: function () { return editor.chain().focus().setFontSize("".concat(size, "px")).run(); },+ }); }), menuWidth: 100 }));+}+var fontFamilies = {+ System: "Open Sans",+ Serif: "serif",+ Monospace: "monospace",+};+export function FontFamily(props) {+ var _a, _b;+ var editor = props.editor;+ var currentFontFamily = ((_b = (_a = Object.entries(fontFamilies)+ .find(function (_a) {+ var _b = __read(_a, 2), key = _b[0], value = _b[1];+ return editor.isActive("textStyle", { fontFamily: value });+ })) === null || _a === void 0 ? void 0 : _a.map(function (a) { return a; })) === null || _b === void 0 ? void 0 : _b.at(0)) || "System";+ return (_jsx(Dropdown, { selectedItem: currentFontFamily, items: toMenuItems(editor, currentFontFamily), menuWidth: 130 }));+}+function toMenuItems(editor, currentFontFamily) {+ var menuItems = [];+ var _loop_1 = function (key) {+ var value = fontFamilies[key];+ menuItems.push({+ key: key,+ type: "menuitem",+ title: key,+ isChecked: key === currentFontFamily,+ onClick: function () { return editor.chain().focus().setFontFamily(value).run(); },+ });};- return FontFamily;-}());-export { FontFamily };+ for (var key in fontFamilies) {+ _loop_1(key);+ }+ return menuItems;+}diff --git a/packages/editor/dist/toolbar/tools/headings.d.ts b/packages/editor/dist/toolbar/tools/headings.d.tsindex e3afa3d71..e237b7e5f 100644--- a/packages/editor/dist/toolbar/tools/headings.d.ts+++ b/packages/editor/dist/toolbar/tools/headings.d.ts@@ -1,10 +1,3 @@/// <reference types="react" />-import { ITool, ToolProps } from "../types";-import { ToolId } from ".";-export declare class Headings implements ITool {- title: string;- id: ToolId;- private defaultLevels;- render: (props: ToolProps) => JSX.Element;- private toMenuItems;-}+import { ToolProps } from "../types";+export declare function Headings(props: ToolProps): JSX.Element;diff --git a/packages/editor/dist/toolbar/tools/headings.js b/packages/editor/dist/toolbar/tools/headings.jsindex 86ab926ca..41ed1ae6b 100644--- a/packages/editor/dist/toolbar/tools/headings.js+++ b/packages/editor/dist/toolbar/tools/headings.js@@ -25,43 +25,34 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {};import { jsx as _jsx } from "react/jsx-runtime";import { Dropdown } from "../components/dropdown";-var Headings = /** @class */ (function () {- function Headings() {- var _this = this;- this.title = "Headings";- this.id = "headings";- this.defaultLevels = [1, 2, 3, 4, 5, 6];- this.render = function (props) {- var editor = props.editor;- var currentHeadingLevel = _this.defaultLevels.find(function (level) {- return editor.isActive("heading", { level: level });- });- return (_jsx(Dropdown, { selectedItem: currentHeadingLevel ? "Heading ".concat(currentHeadingLevel) : "Paragraph", items: _this.toMenuItems(editor, currentHeadingLevel) }));- };- }- Headings.prototype.toMenuItems = function (editor, currentHeadingLevel) {- var menuItems = this.defaultLevels.map(function (level) { return ({- type: "menuitem",- key: "heading-".concat(level),- title: "Heading ".concat(level),- isChecked: level === currentHeadingLevel,- onClick: function () {- return editor- .chain()- .focus()- .setHeading({ level: level })- .run();- },- }); });- var paragraph = {- key: "paragraph",- type: "menuitem",- title: "Paragraph",- isChecked: !currentHeadingLevel,- onClick: function () { return editor.chain().focus().setParagraph().run(); },- };- return __spreadArray([paragraph], __read(menuItems), false);+var defaultLevels = [1, 2, 3, 4, 5, 6];+export function Headings(props) {+ var editor = props.editor;+ var currentHeadingLevel = defaultLevels.find(function (level) {+ return editor.isActive("heading", { level: level });+ });+ return (_jsx(Dropdown, { selectedItem: currentHeadingLevel ? "Heading ".concat(currentHeadingLevel) : "Paragraph", items: toMenuItems(editor, currentHeadingLevel), menuWidth: 130 }));+}+function toMenuItems(editor, currentHeadingLevel) {+ var menuItems = defaultLevels.map(function (level) { return ({+ type: "menuitem",+ key: "heading-".concat(level),+ title: "Heading ".concat(level),+ isChecked: level === currentHeadingLevel,+ onClick: function () {+ return editor+ .chain()+ .focus()+ .setHeading({ level: level })+ .run();+ },+ }); });+ var paragraph = {+ key: "paragraph",+ type: "menuitem",+ title: "Paragraph",+ isChecked: !currentHeadingLevel,+ onClick: function () { return editor.chain().focus().setParagraph().run(); },};- return Headings;-}());-export { Headings };+ return __spreadArray([paragraph], __read(menuItems), false);+}diff --git a/packages/editor/dist/toolbar/tools/index.d.ts b/packages/editor/dist/toolbar/tools/index.d.tsindex cdf12181b..5c7fd2c4d 100644--- a/packages/editor/dist/toolbar/tools/index.d.ts+++ b/packages/editor/dist/toolbar/tools/index.d.ts@@ -1,6 +1,13 @@import React from "react";import { ToolProps } from "../types";-import { Bold, Italic, Underline, Strikethrough, Code, Subscript, Superscript, ClearFormatting, Link, Attachment } from "./inline";+import { Bold, Italic, Underline, Strikethrough, Code, Subscript, Superscript, ClearFormatting, Link } from "./inline";+import { InsertBlock } from "./block";+import { FontSize, FontFamily } from "./font";+import { AlignCenter, AlignLeft, AlignRight, AlignJustify } from "./alignment";+import { Headings } from "./headings";+import { NumberedList, BulletList } from "./lists";+import { LeftToRight, RightToLeft } from "./text-direction";+import { Highlight, TextColor } from "./colors";declare const tools: {bold: typeof Bold;italic: typeof Italic;@@ -11,7 +18,20 @@ declare const tools: {superscript: typeof Superscript;clearformatting: typeof ClearFormatting;link: typeof Link;- attachment: typeof Attachment;+ insertBlock: typeof InsertBlock;+ numberedList: typeof NumberedList;+ bulletList: typeof BulletList;+ fontSize: typeof FontSize;+ fontFamily: typeof FontFamily;+ headings: typeof Headings;+ alignCenter: typeof AlignCenter;+ alignRight: typeof AlignRight;+ alignLeft: typeof AlignLeft;+ alignJustify: typeof AlignJustify;+ ltr: typeof LeftToRight;+ rtl: typeof RightToLeft;+ textColor: typeof TextColor;+ highlight: typeof Highlight;};export declare type ToolId = keyof typeof tools;export declare function findToolById(id: ToolId): React.FunctionComponent<ToolProps>;diff --git a/packages/editor/dist/toolbar/tools/index.js b/packages/editor/dist/toolbar/tools/index.jsindex c32a6f056..6aaf4f495 100644--- a/packages/editor/dist/toolbar/tools/index.js+++ b/packages/editor/dist/toolbar/tools/index.js@@ -1,6 +1,7 @@-import { Bold, Italic, Underline, Strikethrough, Code, Subscript, Superscript, ClearFormatting, Link, Attachment, } from "./inline";-// import { FontSize, FontFamily } from "./font";-// import { AlignCenter, AlignLeft, AlignRight, AlignJustify } from "./alignment";+import { Bold, Italic, Underline, Strikethrough, Code, Subscript, Superscript, ClearFormatting, Link, } from "./inline";+import { InsertBlock } from "./block";+import { FontSize, FontFamily } from "./font";+import { AlignCenter, AlignLeft, AlignRight, AlignJustify } from "./alignment";// import {// Blockquote,// CodeBlock,@@ -9,10 +10,10 @@ import { Bold, Italic, Underline, Strikethrough, Code, Subscript, Superscript, C// Table,// Embed,// } from "./block";-// import { Headings } from "./headings";-// import { NumberedList, BulletList, Checklist } from "./lists";-// import { LeftToRight, RightToLeft } from "./text-direction";-// import { Highlight, TextColor } from "./colors";+import { Headings } from "./headings";+import { NumberedList, BulletList } from "./lists";+import { LeftToRight, RightToLeft } from "./text-direction";+import { Highlight, TextColor } from "./colors";// const tools = {// bold: new Bold(),// italic: new Italic(),@@ -20,25 +21,13 @@ import { Bold, Italic, Underline, Strikethrough, Code, Subscript, Superscript, C// strikethrough: new Strikethrough(),// code: new Code(),// formatClear: new ClearFormatting(),-// alignCenter: new AlignCenter(),-// alignRight: new AlignRight(),-// alignLeft: new AlignLeft(),-// alignJustify: new AlignJustify(),// subscript: new Subscript(),// superscript: new Superscript(),-// fontSize: new FontSize(),-// fontFamily: new FontFamily(),// horizontalRule: new HorizontalRule(),// codeblock: new CodeBlock(),// blockquote: new Blockquote(),// headings: new Headings(),-// ltr: new LeftToRight(),-// rtl: new RightToLeft(),-// numberedList: new NumberedList(),-// bulletList: new BulletList(),// checklist: new Checklist(),-// textColor: new TextColor(),-// highlight: new Highlight(),// link: new Link(),// image: new Image(),// attachment: new Attachment(),@@ -55,7 +44,20 @@ var tools = {superscript: Superscript,clearformatting: ClearFormatting,link: Link,- attachment: Attachment,+ insertBlock: InsertBlock,+ numberedList: NumberedList,+ bulletList: BulletList,+ fontSize: FontSize,+ fontFamily: FontFamily,+ headings: Headings,+ alignCenter: AlignCenter,+ alignRight: AlignRight,+ alignLeft: AlignLeft,+ alignJustify: AlignJustify,+ ltr: LeftToRight,+ rtl: RightToLeft,+ textColor: TextColor,+ highlight: Highlight,};export function findToolById(id) {return tools[id];diff --git a/packages/editor/dist/toolbar/tools/inline.d.ts b/packages/editor/dist/toolbar/tools/inline.d.tsindex c27d47cc0..87ad73d07 100644--- a/packages/editor/dist/toolbar/tools/inline.d.ts+++ b/packages/editor/dist/toolbar/tools/inline.d.ts@@ -9,4 +9,3 @@ export declare function Subscript(props: ToolProps): JSX.Element;export declare function Superscript(props: ToolProps): JSX.Element;export declare function ClearFormatting(props: ToolProps): JSX.Element;export declare function Link(props: ToolProps): JSX.Element;-export declare function Attachment(props: ToolProps): JSX.Element;diff --git a/packages/editor/dist/toolbar/tools/inline.js b/packages/editor/dist/toolbar/tools/inline.jsindex 32cd63437..6f1ac8f6e 100644--- a/packages/editor/dist/toolbar/tools/inline.js+++ b/packages/editor/dist/toolbar/tools/inline.js@@ -112,7 +112,3 @@ export function Link(props) {},} }, { children: _jsxs(Flex, __assign({ sx: { p: 1, width: 300, flexDirection: "column" } }, { children: [_jsx(Input, { type: "text", placeholder: "Link text", value: text, onChange: function (e) { return setText(e.target.value); } }), _jsx(Input, { type: "url", sx: { mt: 1 }, autoFocus: true, placeholder: "https://example.com/", value: href, onChange: function (e) { return setHref(e.target.value); } })] })) })) }))] }));}-export function Attachment(props) {- var editor = props.editor;- return (_jsx(InlineTool, __assign({}, props, { isToggled: function () { return false; }, onClick: function () { return editor.chain().focus().openAttachmentPicker().run(); } })));-}diff --git a/packages/editor/dist/toolbar/tools/lists.d.ts b/packages/editor/dist/toolbar/tools/lists.d.tsindex fe8d31586..50718c842 100644--- a/packages/editor/dist/toolbar/tools/lists.d.ts+++ b/packages/editor/dist/toolbar/tools/lists.d.ts@@ -1,37 +1,4 @@/// <reference types="react" />-import { ITool, ToolProps } from "../types";-import { Editor } from "@tiptap/core";-import { ToolId } from ".";-import { IconNames } from "../icons";-declare type ListSubType<TListStyleTypes> = {- items: string[];- title: string;- type: TListStyleTypes;-};-declare type ListOptions<TListStyleTypes> = {- icon: IconNames;- type: "bulletList" | "orderedList";- onClick: (editor: Editor) => void;- subTypes: ListSubType<TListStyleTypes>[];-};-declare class ListTool<TListStyleTypes extends string> implements ITool {- readonly id: ToolId;- readonly title: string;- private readonly options;- constructor(id: ToolId, title: string, options: ListOptions<TListStyleTypes>);- render: (props: ToolProps) => JSX.Element;-}-declare type NumberedListStyleTypes = "lower-roman" | "upper-roman" | "lower-greek" | "lower-alpha" | "upper-alpha" | "decimal";-export declare class NumberedList extends ListTool<NumberedListStyleTypes> {- constructor();-}-declare type BulletListStyleTypes = "circle" | "square" | "disc";-export declare class BulletList extends ListTool<BulletListStyleTypes> {- constructor();-}-export declare class Checklist implements ITool {- id: ToolId;- title: string;- render: (props: ToolProps) => JSX.Element;-}-export {};+import { ToolProps } from "../types";+export declare function NumberedList(props: ToolProps): JSX.Element;+export declare function BulletList(props: ToolProps): JSX.Element;diff --git a/packages/editor/dist/toolbar/tools/lists.js b/packages/editor/dist/toolbar/tools/lists.jsindex 2b12173f9..07bbe5e67 100644--- a/packages/editor/dist/toolbar/tools/lists.js+++ b/packages/editor/dist/toolbar/tools/lists.js@@ -1,18 +1,3 @@-var __extends = (this && this.__extends) || (function () {- var extendStatics = function (d, b) {- extendStatics = Object.setPrototypeOf ||- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };- return extendStatics(d, b);- };- return function (d, b) {- if (typeof b !== "function" && b !== null)- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");- extendStatics(d, b);- function __() { this.constructor = d; }- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());- };-})();var __assign = (this && this.__assign) || function () {__assign = Object.assign || function(t) {for (var s, i = 1, n = arguments.length; i < n; i++) {@@ -24,138 +9,85 @@ var __assign = (this && this.__assign) || function () {};return __assign.apply(this, arguments);};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];}- finally { if (e) throw e.error; }- }- return ar;+ return t;};-import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";+import { jsx as _jsx } from "react/jsx-runtime";import { Box, Button, Flex } from "rebass";-import { Icon } from "../components/icon";-import { Icons } from "../icons";-import { ToolButton } from "../components/tool-button";-import { MenuPresenter } from "../../components/menu/menu";-import { useRef, useState } from "react";-var ListTool = /** @class */ (function () {- function ListTool(id, title, options) {- var _this = this;- this.id = id;- this.title = title;- this.options = options;- this.render = function (props) {- var editor = props.editor;- var _a = __read(useState(false), 2), isOpen = _a[0], setIsOpen = _a[1];- var ref = useRef(null);- var isActive = editor.isActive(_this.options.type);- return (_jsxs(Flex, __assign({ ref: ref }, { children: [_jsx(ToolButton, { title: _this.title, id: _this.id, icon: _this.options.icon, onClick: function () { return _this.options.onClick(editor); }, toggled: isActive, sx: { mr: 0 } }), _jsx(Button, __assign({ sx: {- p: 0,- m: 0,- bg: "transparent",- ":hover": { bg: "hover" },- ":last-of-type": {- mr: 0,- },- }, onClick: function () { return setIsOpen(function (s) { return !s; }); } }, { children: _jsx(Icon, { path: Icons.chevronDown, color: "text", size: 18 }) })), _jsx(MenuPresenter, { isOpen: isOpen, onClose: function () { return setIsOpen(false); }, items: _this.options.subTypes.map(function (item) { return ({- key: item.type,- tooltip: item.title,- type: "menuitem",- component: function () { return _jsx(ListThumbnail, { listStyleType: item.type }); },- onClick: function () {- var chain = editor.chain().focus();- if (!isActive) {- if (_this.options.type === "bulletList")- chain = chain.toggleBulletList();- else- chain = chain.toggleOrderedList();- }- return chain- .updateAttributes(_this.options.type, { listType: item.type })- .run();- },- }); }), sx: { display: "grid", gridTemplateColumns: "1fr 1fr 1fr", p: 1 }, options: {- type: "menu",- position: {- target: ref.current || undefined,- isTargetAbsolute: true,- location: "below",- yOffset: 5,- },- } })] })));- };- }- return ListTool;-}());-var NumberedList = /** @class */ (function (_super) {- __extends(NumberedList, _super);- function NumberedList() {- var options = {- type: "orderedList",- icon: "numberedList",- onClick: function (editor) { return editor.chain().focus().toggleOrderedList().run(); },- subTypes: [- { type: "decimal", title: "Decimal", items: ["1", "2", "3"] },- { type: "upper-alpha", title: "Upper alpha", items: ["A", "B", "C"] },- { type: "lower-alpha", title: "Lower alpha", items: ["a", "b", "c"] },- {- type: "upper-roman",- title: "Upper Roman",- items: ["I", "II", "III"],+import { SplitButton } from "../components/split-button";+function ListTool(props) {+ var editor = props.editor, options = props.options, toolProps = __rest(props, ["editor", "options"]);+ var isActive = editor.isActive(options.type);+ return (_jsx(SplitButton, __assign({}, toolProps, { onClick: function () { return options.onClick(editor); }, toggled: isActive, sx: { mr: 0 }, menuPresenterProps: {+ items: options.subTypes.map(function (item) { return ({+ key: item.type,+ tooltip: item.title,+ type: "menuitem",+ component: function (_a) {+ var onClick = _a.onClick;+ return (_jsx(Button, __assign({ variant: "menuitem", onClick: onClick }, { children: _jsx(ListThumbnail, { listStyleType: item.type }) })));},- {- type: "lower-roman",- title: "Lower Roman",- items: ["i", "ii", "iii"],+ onClick: function () {+ var chain = editor.chain().focus();+ if (!isActive) {+ if (options.type === "bulletList")+ chain = chain.toggleBulletList();+ else+ chain = chain.toggleOrderedList();+ }+ return chain+ .updateAttributes(options.type, { listType: item.type })+ .run();},- { type: "lower-greek", title: "Lower Greek", items: ["α", "β", "γ"] },- ],- };- return _super.call(this, "numberedList", "Numbered list", options) || this;- }- return NumberedList;-}(ListTool));-export { NumberedList };-var BulletList = /** @class */ (function (_super) {- __extends(BulletList, _super);- function BulletList() {- var options = {- type: "bulletList",- icon: "bulletList",- onClick: function (editor) { return editor.chain().focus().toggleOrderedList().run(); },- subTypes: [- { type: "disc", title: "Decimal", items: ["1", "2", "3"] },- { type: "circle", title: "Upper alpha", items: ["A", "B", "C"] },- { type: "square", title: "Lower alpha", items: ["a", "b", "c"] },- ],- };- return _super.call(this, "bulletList", "Bullet list", options) || this;- }- return BulletList;-}(ListTool));-export { BulletList };-var Checklist = /** @class */ (function () {- function Checklist() {- var _this = this;- this.id = "checklist";- this.title = "Checklist";- this.render = function (props) {- var editor = props.editor;- return (_jsx(ToolButton, { title: _this.title, id: _this.id, icon: "checklist", onClick: function () { return editor.chain().focus().toggleTaskList().run(); }, toggled: false }));- };- }- return Checklist;-}());-export { Checklist };+ }); }),+ sx: { display: "grid", gridTemplateColumns: "1fr 1fr 1fr", p: 1 },+ } })));+}+export function NumberedList(props) {+ var options = {+ type: "orderedList",+ icon: "numberedList",+ onClick: function (editor) { return editor.chain().focus().toggleOrderedList().run(); },+ subTypes: [+ { type: "decimal", title: "Decimal", items: ["1", "2", "3"] },+ { type: "upper-alpha", title: "Upper alpha", items: ["A", "B", "C"] },+ { type: "lower-alpha", title: "Lower alpha", items: ["a", "b", "c"] },+ {+ type: "upper-roman",+ title: "Upper Roman",+ items: ["I", "II", "III"],+ },+ {+ type: "lower-roman",+ title: "Lower Roman",+ items: ["i", "ii", "iii"],+ },+ { type: "lower-greek", title: "Lower Greek", items: ["α", "β", "γ"] },+ ],+ };+ return _jsx(ListTool, __assign({}, props, { options: options }));+}+export function BulletList(props) {+ var options = {+ type: "bulletList",+ icon: "bulletList",+ onClick: function (editor) { return editor.chain().focus().toggleOrderedList().run(); },+ subTypes: [+ { type: "disc", title: "Decimal", items: ["1", "2", "3"] },+ { type: "circle", title: "Upper alpha", items: ["A", "B", "C"] },+ { type: "square", title: "Lower alpha", items: ["a", "b", "c"] },+ ],+ };+ return _jsx(ListTool, __assign({}, props, { options: options }));+}function ListThumbnail(props) {var listStyleType = props.listStyleType;return (_jsx(Flex, __assign({ as: "ul", sx: {diff --git a/packages/editor/dist/toolbar/tools/textdirection.d.ts b/packages/editor/dist/toolbar/tools/textdirection.d.tsindex 7a5bf3f3d..a625990f0 100644--- a/packages/editor/dist/toolbar/tools/textdirection.d.ts+++ b/packages/editor/dist/toolbar/tools/textdirection.d.ts@@ -1,19 +1,4 @@/// <reference types="react" />-import { ITool, ToolProps } from "../types";-import { ToolId } from ".";-import { IconNames } from "../icons";-declare class TextDirectionTool<TId extends ToolId, TTitle extends string> implements ITool {- readonly id: TId;- readonly title: TTitle;- private readonly icon;- private readonly direction;- constructor(id: TId, title: TTitle, icon: IconNames, direction: "ltr" | "rtl");- render: (props: ToolProps) => JSX.Element;-}-export declare class LeftToRight extends TextDirectionTool<ToolId, string> {- constructor();-}-export declare class RightToLeft extends TextDirectionTool<ToolId, string> {- constructor();-}-export {};+import { ToolProps } from "../types";+export declare function RightToLeft(props: ToolProps): JSX.Element;+export declare function LeftToRight(props: ToolProps): JSX.Element;diff --git a/packages/editor/dist/toolbar/tools/textdirection.js b/packages/editor/dist/toolbar/tools/textdirection.jsindex b99fe4a72..fc9247232 100644--- a/packages/editor/dist/toolbar/tools/textdirection.js+++ b/packages/editor/dist/toolbar/tools/textdirection.js@@ -1,49 +1,34 @@-var __extends = (this && this.__extends) || (function () {- var extendStatics = function (d, b) {- extendStatics = Object.setPrototypeOf ||- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };- return extendStatics(d, b);+var __assign = (this && this.__assign) || function () {+ __assign = Object.assign || function(t) {+ for (var s, i = 1, n = arguments.length; i < n; i++) {+ s = arguments[i];+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))+ t[p] = s[p];+ }+ return t;};- return function (d, b) {- if (typeof b !== "function" && b !== null)- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");- extendStatics(d, b);- function __() { this.constructor = d; }- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());- };-})();+ return __assign.apply(this, arguments);+};+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};import { jsx as _jsx } from "react/jsx-runtime";import { ToolButton } from "../components/tool-button";-var TextDirectionTool = /** @class */ (function () {- function TextDirectionTool(id, title, icon, direction) {- var _this = this;- this.id = id;- this.title = title;- this.icon = icon;- this.direction = direction;- this.render = function (props) {- var editor = props.editor;- return (_jsx(ToolButton, { title: _this.title, id: _this.id, icon: _this.icon, onClick: function () {- return editor.chain().focus().setTextDirection(_this.direction).run();- }, toggled: editor.isActive({ textDirection: _this.direction }) }));- };- }- return TextDirectionTool;-}());-var LeftToRight = /** @class */ (function (_super) {- __extends(LeftToRight, _super);- function LeftToRight() {- return _super.call(this, "ltr", "Left-to-right", "ltr", "ltr") || this;- }- return LeftToRight;-}(TextDirectionTool));-export { LeftToRight };-var RightToLeft = /** @class */ (function (_super) {- __extends(RightToLeft, _super);- function RightToLeft() {- return _super.call(this, "rtl", "Right-to-left", "rtl", "rtl") || this;- }- return RightToLeft;-}(TextDirectionTool));-export { RightToLeft };+function TextDirectionTool(props) {+ var editor = props.editor, direction = props.direction, toolProps = __rest(props, ["editor", "direction"]);+ return (_jsx(ToolButton, __assign({}, toolProps, { onClick: function () { return editor.chain().focus().setTextDirection(direction).run(); }, toggled: editor.isActive({ textDirection: direction }) })));+}+export function RightToLeft(props) {+ return _jsx(TextDirectionTool, __assign({ direction: "rtl" }, props));+}+export function LeftToRight(props) {+ return _jsx(TextDirectionTool, __assign({ direction: "ltr" }, props));+}diff --git a/packages/editor/src/components/menu/menu.tsx b/packages/editor/src/components/menu/menu.tsxindex a58eb3f61..47810d28a 100644--- a/packages/editor/src/components/menu/menu.tsx+++ b/packages/editor/src/components/menu/menu.tsx@@ -115,7 +115,7 @@ export function Menu(props: MenuProps) {const hoverTimeout = useRef<NodeJS.Timeout>();const onAction = useCallback((e, item) => {- e.stopPropagation();+ e?.stopPropagation();if (closeMenu) closeMenu();if (item.onClick) {item.onClick();@@ -148,7 +148,7 @@ export function Menu(props: MenuProps) {}const { top, left } = getPosition(subMenuRef.current, {- yOffset: menuItemElement.offsetHeight,+ // yOffset: menuItemElement.offsetHeight,target: menuItemElement,location: "right",});@@ -231,7 +231,7 @@ function MenuContainer(props: PropsWithChildren<MenuContainerProps>) {borderRadius: "default",boxShadow: "menu",border: "1px solid var(--border)",- width: 220,+ minWidth: 220,...sx,}}{...flexProps}@@ -258,7 +258,7 @@ function MenuContainer(props: PropsWithChildren<MenuContainerProps>) {);}-type MenuPresenterProps = MenuContainerProps & {+export type MenuPresenterProps = MenuContainerProps & {items: MenuItemType[];options: MenuOptions;isOpen: boolean;diff --git a/packages/editor/src/components/menu/menuitem.tsx b/packages/editor/src/components/menu/menuitem.tsxindex 9f9b6556d..f6c54963b 100644--- a/packages/editor/src/components/menu/menuitem.tsx+++ b/packages/editor/src/components/menu/menuitem.tsx@@ -11,7 +11,7 @@ type MenuItemProps = {isFocused: boolean;onMouseEnter: () => void;onMouseLeave: () => void;- onClick: React.MouseEventHandler<HTMLButtonElement>;+ onClick: (e?: any) => void;};function MenuItem(props: MenuItemProps) {@@ -26,7 +26,7 @@ function MenuItem(props: MenuItemProps) {tooltip,isDisabled,isChecked,- hasSubmenu,+ items,component: Component,modifier,} = item;@@ -54,67 +54,64 @@ function MenuItem(props: MenuItemProps) {onMouseEnter={onMouseEnter}onMouseLeave={onMouseLeave}>- <Button- id={key}- data-test-id={`menuitem-${key}`}- key={key}- ref={itemRef}- tabIndex={-1}- variant="menuitem"- title={tooltip}- disabled={isDisabled}- onClick={onClick}- sx={{- bg: isFocused ? "hover" : "transparent",- display: "flex",- alignItems: "center",- justifyContent: "space-between",- }}- >- {Component ? (- <Component />- ) : (- <>- <Flex>- {icon && (- <Icon- path={Icons[icon]}- color={"text"}- size={15}- sx={{ mr: 2 }}- />- )}+ {Component ? (+ <Component onClick={onClick} />+ ) : (+ <Button+ id={key}+ data-test-id={`menuitem-${key}`}+ key={key}+ ref={itemRef}+ tabIndex={-1}+ variant="menuitem"+ title={tooltip}+ disabled={isDisabled}+ onClick={onClick}+ sx={{+ bg: isFocused ? "hover" : "transparent",+ display: "flex",+ alignItems: "center",+ justifyContent: "space-between",+ }}+ >+ <Flex>+ {icon && (+ <Icon+ path={Icons[icon]}+ color={"text"}+ size={15}+ sx={{ mr: 2 }}+ />+ )}+ <Text+ as="span"+ sx={{+ fontFamily: "body",+ fontSize: "menu",+ color: "text",+ }}+ >+ {title}+ </Text>+ </Flex>+ <Flex>+ {isChecked && <Icon path={Icons.check} size={14} />}+ {items?.length && <Icon path={Icons.chevronRight} size={14} />}+ {modifier && (<Textas="span"sx={{fontFamily: "body",fontSize: "menu",- color: "text",+ color: "fontTertiary",}}>- {title}+ {modifier}</Text>- </Flex>- <Flex>- {isChecked && <Icon path={Icons.check} size={14} />}- {/*- {hasSubmenu && <ChevronRight size={14} />} */}- {modifier && (- <Text- as="span"- sx={{- fontFamily: "body",- fontSize: "menu",- color: "fontTertiary",- }}- >- {modifier}- </Text>- )}- </Flex>- </>- )}- </Button>+ )}+ </Flex>+ </Button>+ )}</Flex>);}diff --git a/packages/editor/src/components/menu/types.ts b/packages/editor/src/components/menu/types.tsindex 4a5284e4d..4438c8d57 100644--- a/packages/editor/src/components/menu/types.ts+++ b/packages/editor/src/components/menu/types.ts@@ -20,10 +20,13 @@import { IconNames } from "../../toolbar/icons";+type MenuItemComponentProps = {+ onClick?: (e?: any) => void;+};export type MenuItem = {type: "menuitem" | "seperator";key: string;- component?: (props: any) => JSX.Element;+ component?: (props: MenuItemComponentProps) => JSX.Element;onClick?: () => void;title?: string;icon?: IconNames;diff --git a/packages/editor/src/toolbar/components/dropdown.tsx b/packages/editor/src/toolbar/components/dropdown.tsxindex 69eb9351d..85500dd74 100644--- a/packages/editor/src/toolbar/components/dropdown.tsx+++ b/packages/editor/src/toolbar/components/dropdown.tsx@@ -2,16 +2,17 @@ import { useRef, useState } from "react";import { Button, Flex, Text } from "rebass";import { Icon } from "./icon";import { Icons } from "../icons";-import { MenuPresenter } from "../../components/menu/menu";+import { MenuPresenter, MenuPresenterProps } from "../../components/menu/menu";import { MenuItem } from "../../components/menu/types";type DropdownProps = {selectedItem: string | JSX.Element;items: MenuItem[];buttonRef?: React.MutableRefObject<HTMLButtonElement | undefined>;+ menuWidth?: number;};export function Dropdown(props: DropdownProps) {- const { items, selectedItem, buttonRef } = props;+ const { items, selectedItem, buttonRef, menuWidth } = props;const internalRef = useRef<any>();const [isOpen, setIsOpen] = useState(false);@@ -43,7 +44,7 @@ export function Dropdown(props: DropdownProps) {) : (selectedItem)}- <Icon path={Icons.chevronDown} size={16} color={"text"} />+ <Icon path={Icons.chevronDown} size={14} color={"text"} /></Button><MenuPresenteroptions={{@@ -58,6 +59,7 @@ export function Dropdown(props: DropdownProps) {isOpen={isOpen}items={items}onClose={() => setIsOpen(false)}+ sx={{ minWidth: menuWidth }}/></>);diff --git a/packages/editor/src/toolbar/components/split-button.tsx b/packages/editor/src/toolbar/components/split-button.tsxnew file mode 100644index 000000000..1863e236f--- /dev/null+++ b/packages/editor/src/toolbar/components/split-button.tsx@@ -0,0 +1,63 @@+import { SchemeColors } from "@notesnook/theme/dist/theme/colorscheme";+import React, { PropsWithChildren, useRef, useState } from "react";+import { Button, ButtonProps, Flex } from "rebass";+import { IconNames, Icons } from "../icons";+import { Icon } from "./icon";+import { ToolButton, ToolButtonProps } from "./tool-button";+import { MenuPresenter, MenuPresenterProps } from "../../components/menu/menu";++type SplitButtonProps = ToolButtonProps & {+ menuPresenterProps?: Partial<MenuPresenterProps>;+};+export function SplitButton(props: PropsWithChildren<SplitButtonProps>) {+ const { menuPresenterProps, children, ...toolButtonProps } = props;++ const [isOpen, setIsOpen] = useState(false);+ const ref = useRef<HTMLDivElement>(null);++ return (+ <>+ <Flex+ ref={ref}+ sx={{+ borderRadius: "default",+ bg: isOpen ? "hover" : "transparent",+ ":hover": { bg: "hover" },+ }}+ >+ <ToolButton {...toolButtonProps} />+ <Button+ sx={{+ p: 0,+ m: 0,+ bg: "transparent",+ ":hover": { bg: "hover" },+ ":last-of-type": {+ mr: 0,+ },+ }}+ onClick={() => setIsOpen((s) => !s)}+ >+ <Icon path={Icons.chevronDown} color="text" size={14} />+ </Button>+ </Flex>+ <MenuPresenter+ isOpen={isOpen}+ onClose={() => setIsOpen(false)}+ options={{+ type: "menu",+ position: {+ target: ref.current || undefined,+ isTargetAbsolute: true,+ location: "below",+ yOffset: 5,+ },+ }}+ items={[]}+ {...menuPresenterProps}+ >+ {children}+ </MenuPresenter>+ </>+ );+}diff --git a/packages/editor/src/toolbar/components/tool-button.tsx b/packages/editor/src/toolbar/components/tool-button.tsxindex c16c9e3eb..cda3163ab 100644--- a/packages/editor/src/toolbar/components/tool-button.tsx+++ b/packages/editor/src/toolbar/components/tool-button.tsx@@ -4,12 +4,12 @@ import { Button, ButtonProps } from "rebass";import { IconNames, Icons } from "../icons";import { Icon } from "./icon";-type ToolButtonProps = ButtonProps & {+export type ToolButtonProps = ButtonProps & {icon: IconNames;iconColor?: keyof SchemeColors;iconSize?: number;toggled: boolean;- buttonRef?: React.Ref<HTMLButtonElement>;+ buttonRef?: React.MutableRefObject<HTMLButtonElement | null | undefined>;};export function ToolButton(props: ToolButtonProps) {const {diff --git a/packages/editor/src/toolbar/floating-menus/table.tsx b/packages/editor/src/toolbar/floating-menus/table.tsxindex b706feee1..1107a58b9 100644--- a/packages/editor/src/toolbar/floating-menus/table.tsx+++ b/packages/editor/src/toolbar/floating-menus/table.tsx@@ -8,7 +8,7 @@ import { getElementPosition, MenuOptions } from "../../components/menu/useMenu";import { Popup } from "../components/popup";import { ToolButton } from "../components/tool-button";import { IconNames } from "../icons";-import { ColorPicker, DEFAULT_COLORS } from "../tools/colors";+// import { ColorPicker, DEFAULT_COLORS } from "../tools/colors";import { FloatingMenuProps } from "./types";import { selectedRect, TableMap, TableRect } from "prosemirror-tables";import { Transaction } from "prosemirror-state";@@ -486,12 +486,12 @@ function ColorPickerTool(props: ColorPickerToolProps) {width: 160,}}>- <ColorPicker+ {/* <ColorPickercolors={DEFAULT_COLORS}color={color}onClear={() => onColorChange()}onChange={(color) => onColorChange(color)}- />+ /> */}</Flex></MenuPresenter></>diff --git a/packages/editor/src/toolbar/icons.ts b/packages/editor/src/toolbar/icons.tsindex 4607864fc..66cb62255 100644--- a/packages/editor/src/toolbar/icons.ts+++ b/packages/editor/src/toolbar/icons.ts@@ -77,6 +77,7 @@ import {mdiFormatLetterMatches,mdiMoviePlusOutline,mdiLink,+ mdiChevronRight,} from "@mdi/js";export const Icons = {@@ -149,6 +150,9 @@ export const Icons = {download: mdiDownloadOutline,chevronDown: mdiChevronDown,chevronUp: mdiChevronUp,+ chevronRight: mdiChevronRight,++ none: "",};export type IconNames = keyof typeof Icons;diff --git a/packages/editor/src/toolbar/popups/embed-popup.tsx b/packages/editor/src/toolbar/popups/embed-popup.tsxindex 19a29b3b6..bde63c2d1 100644--- a/packages/editor/src/toolbar/popups/embed-popup.tsx+++ b/packages/editor/src/toolbar/popups/embed-popup.tsx@@ -16,8 +16,8 @@ type Embed = Required<EmbedAttributes> & EmbedAlignmentOptions;type EmbedSource = "url" | "code";export type EmbedPopupProps = {onClose: (embed: Embed) => void;- title: string;- icon: IconNames;+ title?: string;+ icon?: IconNames;embed?: Embed;onSizeChanged?: (size: EmbedSizeOptions) => void;diff --git a/packages/editor/src/toolbar/popups/table-popup.tsx b/packages/editor/src/toolbar/popups/table-popup.tsxnew file mode 100644index 000000000..6f3060bc4--- /dev/null+++ b/packages/editor/src/toolbar/popups/table-popup.tsx@@ -0,0 +1,113 @@+import { Box, Flex, Text } from "rebass";+import { useEffect, useState } from "react";+import { Popup } from "../components/popup";++const MAX_COLUMNS = 20;+const MAX_ROWS = 20;+const MIN_COLUMNS = 12;+const MIN_ROWS = 6;++type CellLocation = { column: number; row: number };+type TableSize = { columns: number; rows: number };++export type TablePopupProps = {+ onClose: (size: TableSize) => void;+};+export function TablePopup(props: TablePopupProps) {+ const { onClose } = props;+ const [cellLocation, setCellLocation] = useState<CellLocation>({+ column: 0,+ row: 0,+ });+ const [tableSize, setTableSize] = useState<TableSize>({+ columns: MIN_COLUMNS,+ rows: MIN_ROWS,+ });++ useEffect(() => {+ setTableSize((old) => {+ const { columns, rows } = old;+ const { column, row } = cellLocation;++ let isDecrease = row === rows - 2 || column === columns - 2;++ let rowFactor = Number(row === rows || row === rows - 2);+ let columnFactor = Number(column === columns || column === columns - 2);++ return {+ columns: isDecrease+ ? Math.max(column + columnFactor, MIN_COLUMNS)+ : Math.min(old.columns + columnFactor, MAX_COLUMNS),+ rows: isDecrease+ ? Math.max(row + rowFactor, MIN_ROWS)+ : Math.min(old.rows + rowFactor, MAX_ROWS),+ };+ });+ }, [cellLocation]);++ return (+ <Flex sx={{ p: 1, flexDirection: "column", alignItems: "center" }}>+ <Box+ sx={{+ display: "grid",+ gridTemplateColumns: "1fr ".repeat(tableSize.columns),+ gap: "3px",+ bg: "background",+ }}+ >+ {Array(tableSize.columns * tableSize.rows)+ .fill(0)+ .map((_, index) => (+ <Box+ width={15}+ height={15}+ sx={{+ border: "1px solid var(--disabled)",+ borderRadius: "2px",+ bg: isCellHighlighted(index, cellLocation, tableSize)+ ? "disabled"+ : "transparent",+ ":hover": {+ bg: "disabled",+ },+ }}+ onMouseEnter={() => {+ setCellLocation(getCellLocation(index, tableSize));+ }}+ onClick={() => {+ onClose({+ columns: cellLocation.column,+ rows: cellLocation.row,+ });+ }}+ />+ ))}+ </Box>+ <Text variant={"body"} sx={{ mt: 1 }}>+ {cellLocation.column}x{cellLocation.row}+ </Text>+ </Flex>+ );+}++function getCellLocation(index: number, tableSize: TableSize): CellLocation {+ const cellIndex = index + 1;+ const column = cellIndex % tableSize.columns;+ let row = cellIndex / tableSize.columns;+ const flooredRow = Math.floor(row);+ row = row === flooredRow ? row : flooredRow + 1;++ return { column: column ? column : tableSize.columns, row };+}++function isCellHighlighted(+ index: number,+ currentCellLocation: CellLocation,+ tableSize: TableSize+) {+ const cellLocation = getCellLocation(index, tableSize);+ return (+ cellLocation.row <= currentCellLocation.row &&+ cellLocation.column <= currentCellLocation.column+ );+}diff --git a/packages/editor/src/toolbar/tool-definitions.ts b/packages/editor/src/toolbar/tool-definitions.tsindex ba44b6c46..f09c592b4 100644--- a/packages/editor/src/toolbar/tool-definitions.ts+++ b/packages/editor/src/toolbar/tool-definitions.ts@@ -1,45 +1,101 @@import { ToolDefinition } from "./types";import { ToolId } from "./tools";-const InlineTools: Record<ToolId, ToolDefinition> = {- attachment: {- icon: "attachment",- title: "Attachment",- },+const tools: Record<ToolId, ToolDefinition> = {bold: {icon: "bold",title: "Bold",},italic: {- icon: "attachment",- title: "Attachment",+ icon: "italic",+ title: "Italic",},underline: {- icon: "attachment",- title: "Attachment",+ icon: "underline",+ title: "Underline",},strikethrough: {- icon: "attachment",- title: "Attachment",+ icon: "strikethrough",+ title: "Strikethrough",},link: {- icon: "attachment",- title: "Attachment",+ icon: "link",+ title: "Link",},code: {- icon: "attachment",- title: "Attachment",+ icon: "code",+ title: "Code",},clearformatting: {- icon: "attachment",- title: "Attachment",+ icon: "formatClear",+ title: "Clear all formatting",},subscript: {- icon: "attachment",- title: "Attachment",+ icon: "subscript",+ title: "Subscript",},superscript: {- icon: "attachment",- title: "Attachment",+ icon: "superscript",+ title: "Superscript",+ },+ insertBlock: {+ icon: "plus",+ title: "Insert",+ },+ bulletList: {+ icon: "bulletList",+ title: "Bullet list",+ },+ numberedList: {+ icon: "numberedList",+ title: "Numbered list",+ },+ fontFamily: {+ icon: "none",+ title: "Font family",+ },+ fontSize: {+ icon: "none",+ title: "Font size",+ },+ headings: {+ icon: "none",+ title: "Headings",+ },+ alignCenter: {+ icon: "alignCenter",+ title: "Align center",+ },+ alignLeft: {+ icon: "alignLeft",+ title: "Align left",+ },+ alignRight: {+ icon: "alignRight",+ title: "Align right",+ },+ alignJustify: {+ icon: "alignJustify",+ title: "Justify",+ },+ ltr: {+ icon: "ltr",+ title: "Left to right",+ },+ rtl: {+ icon: "rtl",+ title: "Right to left",+ },+ highlight: {+ icon: "highlight",+ title: "Highlight",+ },+ textColor: {+ icon: "textColor",+ title: "Text color",},};++export function getToolDefinition(id: ToolId) {+ return tools[id];+}diff --git a/packages/editor/src/toolbar/toolbar.tsx b/packages/editor/src/toolbar/toolbar.tsxindex 7d5d31847..c65ed08c9 100644--- a/packages/editor/src/toolbar/toolbar.tsx+++ b/packages/editor/src/toolbar/toolbar.tsx@@ -1,10 +1,22 @@import { useTheme } from "@notesnook/theme";import { ThemeConfig } from "@notesnook/theme/dist/theme/types";import { Editor } from "@tiptap/core";-import { Flex } from "rebass";+import { Flex, FlexProps } from "rebass";import { findToolById, ToolId } from "./tools";import { ThemeProvider } from "emotion-theming";import { EditorFloatingMenus } from "./floating-menus";+import { getToolDefinition } from "./tool-definitions";+import { Dropdown } from "./components/dropdown";+import { ToolButton } from "./components/tool-button";+import { useContext, useRef, useState } from "react";+import { MenuPresenter } from "../components/menu";+import { Popup } from "./components/popup";+import React from "react";++const ToolbarContext = React.createContext<{+ currentPopup?: string;+ setCurrentPopup?: React.Dispatch<React.SetStateAction<string | undefined>>;+}>({});// type Colors = {// text: string;@@ -15,7 +27,8 @@ import { EditorFloatingMenus } from "./floating-menus";// border: string;// };-type ToolbarDefinition = ToolId[][];+type ToolbarGroupDefinition = (ToolId | ToolId[])[];+type ToolbarDefinition = ToolbarGroupDefinition[];type ToolbarProps = ThemeConfig & {editor: Editor | null;@@ -25,43 +38,128 @@ type ToolbarProps = ThemeConfig & {export function Toolbar(props: ToolbarProps) {const { editor, theme, accent, scale } = props;const themeProperties = useTheme({ accent, theme, scale });+ const [currentPopup, setCurrentPopup] = useState<string | undefined>();const tools: ToolbarDefinition = [- ["bold", "italic", "underline", "strikethrough", "code"],- // ["fontSize", "fontFamily", "headings"],- // ["alignLeft", "alignCenter", "alignRight", "alignJustify"],- // ["subscript", "superscript", "horizontalRule"],- // ["codeblock", "blockquote"],- // ["formatClear", "ltr", "rtl"],- // ["numberedList", "bulletList", "checklist"],- // ["link", "image", "attachment", "table", "embed"],- // ["textColor", "highlight"],+ ["insertBlock"],+ [+ "bold",+ "italic",+ "underline",+ [+ "strikethrough",+ "code",+ "subscript",+ "superscript",+ "highlight",+ "textColor",+ ],+ ],+ ["fontSize", "headings", ["fontFamily"]],+ ["numberedList", "bulletList"],+ ["link"],+ ["alignCenter", ["alignLeft", "alignRight", "alignJustify", "ltr", "rtl"]],+ ["clearformatting"],];if (!editor) return null;return (<ThemeProvider theme={themeProperties}>- <Flex className="editor-toolbar" sx={{ flexWrap: "wrap" }}>- {tools.map((tools) => {- return (- <Flex- className="toolbar-group"- sx={{- pr: 2,- mr: 2,- borderRight: "1px solid var(--border)",- ":last-of-type": { mr: 0, pr: 0, borderRight: "none" },- }}- >- {tools.map((toolId) => {- const Component = findToolById(toolId);- return <Component editor={editor} id={toolId} />;- })}- </Flex>- );- })}- </Flex>+ <ToolbarContext.Provider value={{ setCurrentPopup, currentPopup }}>+ <Flex className="editor-toolbar" sx={{ flexWrap: "wrap" }}>+ {tools.map((tools) => {+ return (+ <ToolbarGroup+ tools={tools}+ editor={editor}+ sx={{+ pr: 2,+ mr: 2,+ borderRight: "1px solid var(--border)",+ ":last-of-type": { mr: 0, pr: 0, borderRight: "none" },+ }}+ />+ );+ })}+ </Flex>+ </ToolbarContext.Provider><EditorFloatingMenus editor={editor} /></ThemeProvider>);}++type ToolbarGroupProps = FlexProps & {+ tools: ToolbarGroupDefinition;+ editor: Editor;+};+function ToolbarGroup(props: ToolbarGroupProps) {+ const { tools, editor, ...flexProps } = props;++ return (+ <Flex className="toolbar-group" {...flexProps}>+ {tools.map((toolId) => {+ if (Array.isArray(toolId)) {+ return (+ <MoreTools+ popupId={toolId.join("")}+ tools={toolId}+ editor={editor}+ />+ );+ } else {+ const Component = findToolById(toolId);+ const toolDefinition = getToolDefinition(toolId);+ return <Component editor={editor} id={toolId} {...toolDefinition} />;+ }+ })}+ </Flex>+ );+}++type MoreToolsProps = { popupId: string; tools: ToolId[]; editor: Editor };+function MoreTools(props: MoreToolsProps) {+ const { popupId } = props;+ const { currentPopup, setCurrentPopup } = useContext(ToolbarContext);+ const buttonRef = useRef<HTMLButtonElement | null>();++ const show = popupId === currentPopup;+ const setShow = (state: boolean) =>+ setCurrentPopup?.(state ? popupId : undefined);++ return (+ <>+ <ToolButton+ icon="more"+ title="More"+ toggled={show}+ buttonRef={buttonRef}+ onClick={() => setShow(!show)}+ />+ <MenuPresenter+ isOpen={show}+ onClose={() => setShow(false)}+ items={[]}+ options={{+ type: "autocomplete",+ position: {+ isTargetAbsolute: true,+ target: buttonRef.current || "mouse",+ align: "center",+ location: "below",+ yOffset: 5,+ },+ }}+ >+ <Popup>+ <ToolbarGroup+ tools={props.tools}+ editor={props.editor}+ sx={{+ p: 1,+ }}+ />+ </Popup>+ </MenuPresenter>+ </>+ );+}diff --git a/packages/editor/src/toolbar/tools/alignment.tsx b/packages/editor/src/toolbar/tools/alignment.tsxindex 9813a5f74..56b129b3d 100644--- a/packages/editor/src/toolbar/tools/alignment.tsx+++ b/packages/editor/src/toolbar/tools/alignment.tsx@@ -1,56 +1,33 @@-import { ITool, ToolProps } from "../types";+import { ToolProps } from "../types";import { Editor } from "@tiptap/core";import { ToolButton } from "../components/tool-button";import { ToolId } from ".";import { IconNames, Icons } from "../icons";-class AlignmentTool<TId extends ToolId, TTitle extends string>- implements ITool-{- constructor(- readonly id: TId,- readonly title: TTitle,- private readonly alignment: "left" | "right" | "center" | "justify",- private readonly icon: IconNames- ) {}+type AlignmentToolProps = ToolProps & {+ alignment: "left" | "right" | "center" | "justify";+};+function AlignmentTool(props: AlignmentToolProps) {+ const { editor, alignment, ...toolProps } = props;- render = (props: ToolProps) => {- const { editor } = props;-- return (- <ToolButton- title={this.title}- id={this.id}- icon={this.icon}- onClick={() =>- editor.chain().focus().setTextAlign(this.alignment).run()- }- toggled={editor.isActive({ textAlign: this.alignment })}- />- );- };+ return (+ <ToolButton+ {...toolProps}+ onClick={() => editor.chain().focus().setTextAlign(alignment).run()}+ toggled={editor.isActive({ textAlign: alignment })}+ />+ );}-export class AlignCenter extends AlignmentTool<ToolId, string> {- constructor() {- super("alignCenter", "Align center", "center", "alignCenter");- }+export function AlignCenter(props: ToolProps) {+ return <AlignmentTool alignment="center" {...props} />;}--export class AlignRight extends AlignmentTool<ToolId, string> {- constructor() {- super("alignRight", "Align right", "right", "alignRight");- }+export function AlignLeft(props: ToolProps) {+ return <AlignmentTool alignment="left" {...props} />;}--export class AlignLeft extends AlignmentTool<ToolId, string> {- constructor() {- super("alignLeft", "Align left", "left", "alignLeft");- }+export function AlignRight(props: ToolProps) {+ return <AlignmentTool alignment="right" {...props} />;}--export class AlignJustify extends AlignmentTool<ToolId, string> {- constructor() {- super("alignJustify", "Justify", "justify", "alignJustify");- }+export function AlignJustify(props: ToolProps) {+ return <AlignmentTool alignment="justify" {...props} />;}diff --git a/packages/editor/src/toolbar/tools/block.tsx b/packages/editor/src/toolbar/tools/block.tsxindex ab92c855e..5877ad169 100644--- a/packages/editor/src/toolbar/tools/block.tsx+++ b/packages/editor/src/toolbar/tools/block.tsx@@ -1,4 +1,4 @@-import { ITool, ToolProps } from "../types";+import { ToolProps } from "../types";import { Editor } from "@tiptap/core";import { ToolButton } from "../components/tool-button";import { ToolId } from ".";@@ -10,286 +10,158 @@ import { Icon } from "../components/icon";import { Box, Button, Flex, Text } from "rebass";import { Popup } from "../components/popup";import { EmbedPopup } from "../popups/embed-popup";--class BlockTool<TId extends ToolId> implements ITool {- constructor(- readonly id: TId,- readonly title: string,- private readonly icon: IconNames,- private readonly command: (editor: Editor) => boolean- ) {}-- render = (props: ToolProps) => {- const { editor } = props;-- return (- <ToolButton- id={this.id}- title={this.title}- icon={this.icon}- onClick={() => this.command(editor)}- toggled={editor.isActive(this.id)}+import { TablePopup } from "../popups/table-popup";+import { MenuItem } from "../../components/menu/types";++export function InsertBlock(props: ToolProps) {+ const buttonRef = useRef<HTMLButtonElement | null>();+ const [isOpen, setIsOpen] = useState(false);+ return (+ <>+ <Button+ ref={buttonRef}+ sx={{+ p: 1,+ m: 0,+ bg: isOpen ? "hover" : "transparent",+ mr: 1,+ display: "flex",+ alignItems: "center",+ ":hover": { bg: "hover" },+ ":last-of-type": {+ mr: 0,+ },+ }}+ onClick={() => setIsOpen((s) => !s)}+ >+ <Icon path={Icons.plus} size={18} color={"primary"} />+ </Button>+ <MenuPresenter+ options={{+ type: "menu",+ position: {+ target: buttonRef.current || undefined,+ isTargetAbsolute: true,+ location: "below",+ yOffset: 5,+ },+ }}+ isOpen={isOpen}+ items={[+ tasklist(editor),+ horizontalRule(editor),+ codeblock(editor),+ blockquote(editor),+ image(editor),+ attachment(editor),+ embed(editor),+ table(editor),+ ]}+ onClose={() => setIsOpen(false)}/>- );- };-}--export class HorizontalRule extends BlockTool<ToolId> {- constructor() {- super("horizontalRule", "Horizontal rule", "horizontalRule", (editor) =>- editor.chain().focus().setHorizontalRule().run()- );- }-}--export class CodeBlock extends BlockTool<ToolId> {- constructor() {- super("codeblock", "Codeblock", "codeblock", (editor) =>- editor.chain().focus().toggleCodeBlock().run()- );- }-}--export class Blockquote extends BlockTool<ToolId> {- constructor() {- super("blockquote", "Blockquote", "blockquote", (editor) =>- editor.chain().focus().toggleBlockquote().run()- );- }-}--export class Image implements ITool {- id: ToolId = "image";- title: string = "Image";-- render = (props: ToolProps) => {- const { editor } = props;- return (- <>- <Dropdown- selectedItem={<Icon path={Icons.image} size={16} />}- items={[- {- key: "upload-from-disk",- type: "menuitem",- title: "Upload from disk",- icon: "upload",- onClick: () => {},- },- {- key: "upload-from-url",- type: "menuitem",- title: "Attach from URL",- icon: "link",- onClick: () => {},- },- ]}- />- </>- );- };+ </>+ );}-export class Embed implements ITool {- id: ToolId = "embed";- title: string = "Embed";-- render = (props: ToolProps) => {- const { editor } = props;- const [isOpen, setIsOpen] = useState(false);- const buttonRef = useRef<HTMLButtonElement>(null);- return (- <>- <ToolButton- buttonRef={buttonRef}- id={this.id}- title={this.title}- icon={"embed"}- onClick={() => setIsOpen((s) => !s)}- toggled={isOpen}- />- <MenuPresenter- isOpen={isOpen}- items={[]}- onClose={() => setIsOpen(false)}- options={{- type: "menu",- position: {- target: buttonRef.current || undefined,- isTargetAbsolute: true,- location: "below",- yOffset: 10,- },+const horizontalRule = (editor: Editor | null): MenuItem => ({+ key: "hr",+ type: "menuitem",+ title: "Horizontal rule",+ icon: "horizontalRule",+ isChecked: editor?.isActive("horizontalRule"),+ onClick: () => editor?.chain().focus().setHorizontalRule().run(),+});++const codeblock = (editor: Editor | null): MenuItem => ({+ key: "codeblock",+ type: "menuitem",+ title: "Code block",+ icon: "codeblock",+ isChecked: editor?.isActive("codeBlock"),+ onClick: () => editor?.chain().focus().toggleCodeBlock().run(),+});++const blockquote = (editor: Editor | null): MenuItem => ({+ key: "blockquote",+ type: "menuitem",+ title: "Quote",+ icon: "blockquote",+ isChecked: editor?.isActive("blockQuote"),+ onClick: () => editor?.chain().focus().toggleBlockquote().run(),+});++const image = (editor: Editor | null): MenuItem => ({+ key: "image",+ type: "menuitem",+ title: "Image",+ icon: "image",+ items: [+ {+ key: "upload-from-disk",+ type: "menuitem",+ title: "Upload from disk",+ icon: "upload",+ onClick: () => {},+ },+ {+ key: "upload-from-url",+ type: "menuitem",+ title: "Attach from URL",+ icon: "link",+ onClick: () => {},+ },+ ],+});++const embed = (editor: Editor | null): MenuItem => ({+ key: "embed",+ type: "menuitem",+ title: "Embed",+ icon: "embed",+});++const table = (editor: Editor | null): MenuItem => ({+ key: "table",+ type: "menuitem",+ title: "Table",+ icon: "table",+ items: [+ {+ key: "table-size-selector",+ type: "menuitem",+ component: (props) => (+ <TablePopup+ onClose={(size) => {+ editor+ ?.chain()+ .focus()+ .insertTable({+ rows: size.rows,+ cols: size.columns,+ })+ .run();+ props.onClick?.();}}- >- <EmbedPopup- title="Insert embed"- icon="check"- onClose={(embed) => {- editor.chain().focus().insertEmbed(embed).run();- }}- />- </MenuPresenter>- </>- );- };-}--type CellLocation = { column: number; row: number };-type TableSize = { columns: number; rows: number };-export class Table implements ITool {- id: ToolId = "table";- title: string = "Table";- private MAX_COLUMNS = 20;- private MAX_ROWS = 20;-- private MIN_COLUMNS = 4;- private MIN_ROWS = 4;-- render = (props: ToolProps) => {- const { editor } = props;- const [isOpen, setIsOpen] = useState(false);- const ref = useRef<HTMLDivElement>(null);- const [cellLocation, setCellLocation] = useState<CellLocation>({- column: 0,- row: 0,- });- const [tableSize, setTableSize] = useState<TableSize>({- columns: this.MIN_COLUMNS,- rows: this.MIN_ROWS,- });-- useEffect(() => {- setTableSize((old) => {- const { columns, rows } = old;- const { column, row } = cellLocation;-- let isDecrease = row === rows - 2 || column === columns - 2;-- let rowFactor = Number(row === rows || row === rows - 2);- let columnFactor = Number(column === columns || column === columns - 2);-- return {- columns: isDecrease- ? Math.max(column + columnFactor, this.MIN_COLUMNS)- : Math.min(old.columns + columnFactor, this.MAX_COLUMNS),- rows: isDecrease- ? Math.max(row + rowFactor, this.MIN_ROWS)- : Math.min(old.rows + rowFactor, this.MAX_ROWS),- };- });- }, [cellLocation]);-- return (- <Flex ref={ref}>- <Button- sx={{- p: 1,- m: 0,- bg: isOpen ? "hover" : "transparent",- mr: 1,- display: "flex",- alignItems: "center",- ":hover": { bg: "hover" },- ":last-of-type": {- mr: 0,- },- }}- onClick={() => setIsOpen((s) => !s)}- >- <Icon path={Icons.table} color="text" size={18} />- <Icon path={Icons.chevronDown} color="text" size={18} />- </Button>- <MenuPresenter- isOpen={isOpen}- onClose={() => setIsOpen(false)}- items={[]}- options={{- type: "menu",- position: {- target: ref.current || undefined,- isTargetAbsolute: true,- location: "below",- yOffset: 5,- },- }}- >- <Popup>- <Flex sx={{ p: 1, flexDirection: "column", alignItems: "center" }}>- <Box- sx={{- display: "grid",- gridTemplateColumns: "1fr ".repeat(tableSize.columns),- gap: "3px",- bg: "background",- }}- >- {Array(tableSize.columns * tableSize.rows)- .fill(0)- .map((_, index) => (- <Box- width={15}- height={15}- sx={{- border: "1px solid var(--disabled)",- borderRadius: "2px",- bg: this.isCellHighlighted(- index,- cellLocation,- tableSize- )- ? "disabled"- : "transparent",- ":hover": {- bg: "disabled",- },- }}- onMouseEnter={() => {- setCellLocation(this.getCellLocation(index, tableSize));- }}- onClick={() => {- editor- .chain()- .focus()- .insertTable({- cols: cellLocation.column,- rows: cellLocation.row,- })- .run();- setIsOpen(false);- }}- />- ))}- </Box>- <Text variant={"body"} sx={{ mt: 1 }}>- {cellLocation.column}x{cellLocation.row}- </Text>- </Flex>- </Popup>- </MenuPresenter>- </Flex>- );- };-- private getCellLocation(index: number, tableSize: TableSize): CellLocation {- const cellIndex = index + 1;- const column = cellIndex % tableSize.columns;- let row = cellIndex / tableSize.columns;- const flooredRow = Math.floor(row);- row = row === flooredRow ? row : flooredRow + 1;-- return { column: column ? column : tableSize.columns, row };- }-- private isCellHighlighted(- index: number,- currentCellLocation: CellLocation,- tableSize: TableSize- ) {- const cellLocation = this.getCellLocation(index, tableSize);- return (- cellLocation.row <= currentCellLocation.row &&- cellLocation.column <= currentCellLocation.column- );- }-}+ />+ ),+ },+ ],+});++const attachment = (editor: Editor | null): MenuItem => ({+ key: "attachment",+ type: "menuitem",+ title: "Attachment",+ icon: "attachment",+ isChecked: editor?.isActive("attachment"),+ onClick: () => editor?.chain().focus().openAttachmentPicker().run(),+});++const tasklist = (editor: Editor | null): MenuItem => ({+ key: "tasklist",+ type: "menuitem",+ title: "Task list",+ icon: "checkbox",+ isChecked: editor?.isActive("taskList"),+ onClick: () => editor?.chain().focus().toggleTaskList().run(),+});diff --git a/packages/editor/src/toolbar/tools/colors.tsx b/packages/editor/src/toolbar/tools/colors.tsxindex a33206c9f..cb6864fc7 100644--- a/packages/editor/src/toolbar/tools/colors.tsx+++ b/packages/editor/src/toolbar/tools/colors.tsx@@ -1,13 +1,11 @@-import { ITool, ToolProps } from "../types";+import { ToolProps } from "../types";import { Editor } from "@tiptap/core";-import { ToolId } from ".";-import { Dropdown } from "../components/dropdown";-import { MenuItem } from "../../components/menu/types";import { Box, Button, Flex, Text } from "rebass";import { Input } from "@rebass/forms";import { Icon } from "../components/icon";-import { IconNames, Icons } from "../icons";+import { Icons } from "../icons";import { ToolButton } from "../components/tool-button";+import { SplitButton } from "../components/split-button";import { MenuPresenter } from "../../components/menu/menu";import { useRef, useState } from "react";import tinycolor from "tinycolor2";@@ -28,109 +26,76 @@ export const DEFAULT_COLORS = ["#ffeb3b","#ffc107",];+type ColorToolProps = ToolProps & {+ onColorChange: (editor: Editor, color?: string) => void;+ isActive: (editor: Editor) => boolean;+ getActiveColor: (editor: Editor) => string;+};+function ColorTool(props: ColorToolProps) {+ const { editor, onColorChange, isActive, getActiveColor, ...toolProps } =+ props;+ const activeColor = getActiveColor(editor);+ const _isActive = isActive(editor);-class ColorTool implements ITool {- constructor(- readonly id: ToolId,- readonly title: string,- private readonly icon: IconNames,- private readonly onColorChange: (editor: Editor, color?: string) => void- ) {}-- render = (props: ToolProps) => {- const { editor } = props;- const [isOpen, setIsOpen] = useState(false);- const attrs = editor.getAttributes(- this.id === "highlight" ? "highlight" : "textStyle"- );- const ref = useRef<HTMLDivElement>(null);- const isActive = editor.isActive(- this.id === "highlight" ? "highlight" : "textStyle",- { color: /\W+/gm }- );-- return (- <Flex ref={ref}>- <ToolButton- title={this.title}- id={this.id}- icon={this.icon}- onClick={() => {}}- toggled={false}- sx={{ mr: 0, bg: isActive ? attrs.color : "transparent" }}+ return (+ <SplitButton+ {...toolProps}+ toggled={false}+ sx={{+ mr: 0,+ bg: _isActive ? activeColor : "transparent",+ }}+ >+ <Flex+ sx={{+ flexDirection: "column",+ bg: "background",+ boxShadow: "menu",+ border: "1px solid var(--border)",+ borderRadius: "default",+ p: 1,+ width: 160,+ }}+ >+ <ColorPicker+ colors={DEFAULT_COLORS}+ color={activeColor}+ onClear={() => onColorChange(editor)}+ onChange={(color) => onColorChange(editor, color)}/>- <Button- sx={{- p: 0,- m: 0,- bg: "transparent",- ":hover": { bg: "hover" },- ":last-of-type": {- mr: 0,- },- }}- onClick={() => setIsOpen((s) => !s)}- >- <Icon path={Icons.chevronDown} color="text" size={18} />- </Button>- <MenuPresenter- isOpen={isOpen}- onClose={() => setIsOpen(false)}- items={[]}- // sx={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr", p: 1 }}- options={{- type: "menu",- position: {- target: ref.current || undefined,- isTargetAbsolute: true,- location: "below",- align: "center",- yOffset: 5,- },- }}- >- <Flex- sx={{- flexDirection: "column",- bg: "background",- boxShadow: "menu",- border: "1px solid var(--border)",- borderRadius: "default",- p: 1,- width: 160,- }}- >- <ColorPicker- colors={DEFAULT_COLORS}- color={attrs.color}- onClear={() => this.onColorChange(editor)}- onChange={(color) => this.onColorChange(editor, color)}- />- </Flex>- </MenuPresenter></Flex>- );- };+ </SplitButton>+ );}-export class Highlight extends ColorTool {- constructor() {- super("highlight", "Highlight", "highlight", (editor, color) =>- color- ? editor.chain().focus().toggleHighlight({ color }).run()- : editor.chain().focus().unsetHighlight().run()- );- }+export function Highlight(props: ToolProps) {+ return (+ <ColorTool+ {...props}+ isActive={(editor) => editor.isActive("highlight", { color: /\W+/gm })}+ getActiveColor={(editor) => editor.getAttributes("highlight").color}+ onColorChange={(editor, color) =>+ color+ ? editor.chain().focus().toggleHighlight({ color }).run()+ : editor.chain().focus().unsetHighlight().run()+ }+ />+ );}-export class TextColor extends ColorTool {- constructor() {- super("textColor", "Text color", "textColor", (editor, color) =>- color- ? editor.chain().focus().setColor(color).run()- : editor.chain().focus().unsetColor().run()- );- }+export function TextColor(props: ToolProps) {+ return (+ <ColorTool+ {...props}+ isActive={(editor) => editor.isActive("textStyle", { color: /\W+/gm })}+ getActiveColor={(editor) => editor.getAttributes("textStyle").color}+ onColorChange={(editor, color) =>+ color+ ? editor.chain().focus().setColor(color).run()+ : editor.chain().focus().unsetColor().run()+ }+ />+ );}type ColorPickerProps = {diff --git a/packages/editor/src/toolbar/tools/font.tsx b/packages/editor/src/toolbar/tools/font.tsxindex 1c7fba065..4cfa7f703 100644--- a/packages/editor/src/toolbar/tools/font.tsx+++ b/packages/editor/src/toolbar/tools/font.tsx@@ -1,78 +1,70 @@-import { ITool, ToolProps } from "../types";+import { ToolProps } from "../types";import { Dropdown } from "../components/dropdown";import { ToolId } from ".";import { MenuItem } from "../../components/menu/types";import { Editor } from "@tiptap/core";-export class FontSize implements ITool {- title = "Font size";- id: ToolId = "fontSize";- private defaultFontSizes = [- 12, 14, 16, 18, 20, 24, 28, 32, 36, 42, 48, 60, 72, 100,- ];+const defaultFontSizes = [+ 12, 14, 16, 18, 20, 24, 28, 32, 36, 42, 48, 60, 72, 100,+];+export function FontSize(props: ToolProps) {+ const { editor } = props;+ const currentFontSize =+ defaultFontSizes.find((size) =>+ editor.isActive("textStyle", { fontSize: `${size}px` })+ ) || 16;- render = (props: ToolProps) => {- const { editor } = props;- const currentFontSize =- this.defaultFontSizes.find((size) =>- editor.isActive("textStyle", { fontSize: `${size}px` })- ) || 16;-- return (- <Dropdown- selectedItem={`${currentFontSize}px`}- items={this.defaultFontSizes.map((size) => ({- key: `${size}px`,- type: "menuitem",- title: `${size}px`,- isChecked: size === currentFontSize,- onClick: () => editor.chain().focus().setFontSize(`${size}px`).run(),- }))}- />- );- };+ return (+ <Dropdown+ selectedItem={`${currentFontSize}px`}+ items={defaultFontSizes.map((size) => ({+ key: `${size}px`,+ type: "menuitem",+ title: `${size}px`,+ isChecked: size === currentFontSize,+ onClick: () => editor.chain().focus().setFontSize(`${size}px`).run(),+ }))}+ menuWidth={100}+ />+ );}-export class FontFamily implements ITool {- title = "Font family";- id: ToolId = "fontFamily";- private fontFamilies = {- System: "Open Sans",- Serif: "serif",- Monospace: "monospace",- };-- render = (props: ToolProps) => {- const { editor } = props;+const fontFamilies = {+ System: "Open Sans",+ Serif: "serif",+ Monospace: "monospace",+};+export function FontFamily(props: ToolProps) {+ const { editor } = props;- const currentFontFamily =- Object.entries(this.fontFamilies)- .find(([key, value]) =>- editor.isActive("textStyle", { fontFamily: value })- )- ?.map((a) => a)- ?.at(0) || "System";+ const currentFontFamily =+ Object.entries(fontFamilies)+ .find(([key, value]) =>+ editor.isActive("textStyle", { fontFamily: value })+ )+ ?.map((a) => a)+ ?.at(0) || "System";- return (- <Dropdown- selectedItem={currentFontFamily}- items={this.toMenuItems(editor, currentFontFamily)}- />- );- };+ return (+ <Dropdown+ selectedItem={currentFontFamily}+ items={toMenuItems(editor, currentFontFamily)}+ menuWidth={130}+ />+ );+}- private toMenuItems(editor: Editor, currentFontFamily: string): MenuItem[] {- const menuItems: MenuItem[] = [];- for (const key in this.fontFamilies) {- const value = this.fontFamilies[key as keyof typeof this.fontFamilies];- menuItems.push({- key,- type: "menuitem",- title: key,- isChecked: key === currentFontFamily,- onClick: () => editor.chain().focus().setFontFamily(value).run(),- });- }- return menuItems;+function toMenuItems(editor: Editor, currentFontFamily: string): MenuItem[] {+ const menuItems: MenuItem[] = [];+ for (const key in fontFamilies) {+ const value = fontFamilies[key as keyof typeof fontFamilies];+ menuItems.push({+ key,+ type: "menuitem",+ title: key,+ isChecked: key === currentFontFamily,+ onClick: () => editor.chain().focus().setFontFamily(value).run(),+ });}+ return menuItems;}diff --git a/packages/editor/src/toolbar/tools/headings.tsx b/packages/editor/src/toolbar/tools/headings.tsxindex d4dd9da26..458837fe3 100644--- a/packages/editor/src/toolbar/tools/headings.tsx+++ b/packages/editor/src/toolbar/tools/headings.tsx@@ -1,53 +1,47 @@-import { ITool, ToolProps } from "../types";+import { ToolProps } from "../types";import { Editor } from "@tiptap/core";import { ToolId } from ".";import { Dropdown } from "../components/dropdown";import { MenuItem } from "../../components/menu/types";-export class Headings implements ITool {- title = "Headings";- id: ToolId = "headings";- private defaultLevels = [1, 2, 3, 4, 5, 6];+const defaultLevels = [1, 2, 3, 4, 5, 6];- render = (props: ToolProps) => {- const { editor } = props;+export function Headings(props: ToolProps) {+ const { editor } = props;- const currentHeadingLevel = this.defaultLevels.find((level) =>- editor.isActive("heading", { level })- );- return (- <Dropdown- selectedItem={- currentHeadingLevel ? `Heading ${currentHeadingLevel}` : "Paragraph"- }- items={this.toMenuItems(editor, currentHeadingLevel)}- />- );- };+ const currentHeadingLevel = defaultLevels.find((level) =>+ editor.isActive("heading", { level })+ );+ return (+ <Dropdown+ selectedItem={+ currentHeadingLevel ? `Heading ${currentHeadingLevel}` : "Paragraph"+ }+ items={toMenuItems(editor, currentHeadingLevel)}+ menuWidth={130}+ />+ );+}- private toMenuItems(- editor: Editor,- currentHeadingLevel?: number- ): MenuItem[] {- const menuItems: MenuItem[] = this.defaultLevels.map((level) => ({- type: "menuitem",- key: `heading-${level}`,- title: `Heading ${level}`,- isChecked: level === currentHeadingLevel,- onClick: () =>- editor- .chain()- .focus()- .setHeading({ level: level as any })- .run(),- }));- const paragraph: MenuItem = {- key: "paragraph",- type: "menuitem",- title: "Paragraph",- isChecked: !currentHeadingLevel,- onClick: () => editor.chain().focus().setParagraph().run(),- };- return [paragraph, ...menuItems];- }+function toMenuItems(editor: Editor, currentHeadingLevel?: number): MenuItem[] {+ const menuItems: MenuItem[] = defaultLevels.map((level) => ({+ type: "menuitem",+ key: `heading-${level}`,+ title: `Heading ${level}`,+ isChecked: level === currentHeadingLevel,+ onClick: () =>+ editor+ .chain()+ .focus()+ .setHeading({ level: level as any })+ .run(),+ }));+ const paragraph: MenuItem = {+ key: "paragraph",+ type: "menuitem",+ title: "Paragraph",+ isChecked: !currentHeadingLevel,+ onClick: () => editor.chain().focus().setParagraph().run(),+ };+ return [paragraph, ...menuItems];}diff --git a/packages/editor/src/toolbar/tools/index.ts b/packages/editor/src/toolbar/tools/index.tsindex 0a21a7980..9aced6d22 100644--- a/packages/editor/src/toolbar/tools/index.ts+++ b/packages/editor/src/toolbar/tools/index.ts@@ -10,10 +10,10 @@ import {Superscript,ClearFormatting,Link,- Attachment,} from "./inline";-// import { FontSize, FontFamily } from "./font";-// import { AlignCenter, AlignLeft, AlignRight, AlignJustify } from "./alignment";+import { InsertBlock } from "./block";+import { FontSize, FontFamily } from "./font";+import { AlignCenter, AlignLeft, AlignRight, AlignJustify } from "./alignment";// import {// Blockquote,// CodeBlock,@@ -22,10 +22,10 @@ import {// Table,// Embed,// } from "./block";-// import { Headings } from "./headings";-// import { NumberedList, BulletList, Checklist } from "./lists";-// import { LeftToRight, RightToLeft } from "./text-direction";-// import { Highlight, TextColor } from "./colors";+import { Headings } from "./headings";+import { NumberedList, BulletList } from "./lists";+import { LeftToRight, RightToLeft } from "./text-direction";+import { Highlight, TextColor } from "./colors";// const tools = {// bold: new Bold(),@@ -34,31 +34,24 @@ import {// strikethrough: new Strikethrough(),// code: new Code(),// formatClear: new ClearFormatting(),-// alignCenter: new AlignCenter(),-// alignRight: new AlignRight(),-// alignLeft: new AlignLeft(),-// alignJustify: new AlignJustify(),+// subscript: new Subscript(),// superscript: new Superscript(),-// fontSize: new FontSize(),-// fontFamily: new FontFamily(),+// horizontalRule: new HorizontalRule(),// codeblock: new CodeBlock(),// blockquote: new Blockquote(),// headings: new Headings(),-// ltr: new LeftToRight(),-// rtl: new RightToLeft(),-// numberedList: new NumberedList(),-// bulletList: new BulletList(),+// checklist: new Checklist(),-// textColor: new TextColor(),-// highlight: new Highlight(),+// link: new Link(),// image: new Image(),// attachment: new Attachment(),// table: new Table(),// embed: new Embed(),// };+const tools = {bold: Bold,italic: Italic,@@ -69,8 +62,22 @@ const tools = {superscript: Superscript,clearformatting: ClearFormatting,link: Link,- attachment: Attachment,+ insertBlock: InsertBlock,+ numberedList: NumberedList,+ bulletList: BulletList,+ fontSize: FontSize,+ fontFamily: FontFamily,+ headings: Headings,+ alignCenter: AlignCenter,+ alignRight: AlignRight,+ alignLeft: AlignLeft,+ alignJustify: AlignJustify,+ ltr: LeftToRight,+ rtl: RightToLeft,+ textColor: TextColor,+ highlight: Highlight,};+export type ToolId = keyof typeof tools;export function findToolById(id: ToolId): React.FunctionComponent<ToolProps> {return tools[id];diff --git a/packages/editor/src/toolbar/tools/inline.tsx b/packages/editor/src/toolbar/tools/inline.tsxindex ddf5a2a9f..f3662159b 100644--- a/packages/editor/src/toolbar/tools/inline.tsx+++ b/packages/editor/src/toolbar/tools/inline.tsx@@ -201,15 +201,3 @@ export function Link(props: ToolProps) {</>);}--export function Attachment(props: ToolProps) {- const { editor } = props;-- return (- <InlineTool- {...props}- isToggled={() => false}- onClick={() => editor.chain().focus().openAttachmentPicker().run()}- />- );-}diff --git a/packages/editor/src/toolbar/tools/lists.tsx b/packages/editor/src/toolbar/tools/lists.tsxindex e4f00fa8f..c0298b6ed 100644--- a/packages/editor/src/toolbar/tools/lists.tsx+++ b/packages/editor/src/toolbar/tools/lists.tsx@@ -1,4 +1,4 @@-import { ITool, ToolProps } from "../types";+import { ToolProps } from "../types";import { Editor } from "@tiptap/core";import { ToolId } from ".";import { Dropdown } from "../components/dropdown";@@ -9,6 +9,7 @@ import { IconNames, Icons } from "../icons";import { ToolButton } from "../components/tool-button";import { MenuPresenter } from "../../components/menu/menu";import { useRef, useState } from "react";+import { SplitButton } from "../components/split-button";type ListSubType<TListStyleTypes> = {items: string[];@@ -21,79 +22,50 @@ type ListOptions<TListStyleTypes> = {onClick: (editor: Editor) => void;subTypes: ListSubType<TListStyleTypes>[];};-class ListTool<TListStyleTypes extends string> implements ITool {- constructor(- readonly id: ToolId,- readonly title: string,- private readonly options: ListOptions<TListStyleTypes>- ) {}- render = (props: ToolProps) => {- const { editor } = props;- const [isOpen, setIsOpen] = useState(false);- const ref = useRef<HTMLDivElement>(null);- const isActive = editor.isActive(this.options.type);+type ListToolProps<TListStyleTypes> = ToolProps & {+ options: ListOptions<TListStyleTypes>;+};+function ListTool<TListStyleTypes extends string>(+ props: ListToolProps<TListStyleTypes>+) {+ const { editor, options, ...toolProps } = props;+ const isActive = editor.isActive(options.type);- return (- <Flex ref={ref}>- <ToolButton- title={this.title}- id={this.id}- icon={this.options.icon}- onClick={() => this.options.onClick(editor)}- toggled={isActive}- sx={{ mr: 0 }}- />- <Button- sx={{- p: 0,- m: 0,- bg: "transparent",- ":hover": { bg: "hover" },- ":last-of-type": {- mr: 0,- },- }}- onClick={() => setIsOpen((s) => !s)}- >- <Icon path={Icons.chevronDown} color="text" size={18} />- </Button>- <MenuPresenter- isOpen={isOpen}- onClose={() => setIsOpen(false)}- items={this.options.subTypes.map((item) => ({- key: item.type,- tooltip: item.title,- type: "menuitem",- component: () => <ListThumbnail listStyleType={item.type} />,- onClick: () => {- let chain = editor.chain().focus();+ return (+ <SplitButton+ {...toolProps}+ onClick={() => options.onClick(editor)}+ toggled={isActive}+ sx={{ mr: 0 }}+ menuPresenterProps={{+ items: options.subTypes.map((item) => ({+ key: item.type,+ tooltip: item.title,+ type: "menuitem",+ component: ({ onClick }) => (+ <Button variant={"menuitem"} onClick={onClick}>+ <ListThumbnail listStyleType={item.type} />+ </Button>+ ),+ onClick: () => {+ let chain = editor.chain().focus();- if (!isActive) {- if (this.options.type === "bulletList")- chain = chain.toggleBulletList();- else chain = chain.toggleOrderedList();- }+ if (!isActive) {+ if (options.type === "bulletList")+ chain = chain.toggleBulletList();+ else chain = chain.toggleOrderedList();+ }- return chain- .updateAttributes(this.options.type, { listType: item.type })- .run();- },- }))}- sx={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr", p: 1 }}- options={{- type: "menu",- position: {- target: ref.current || undefined,- isTargetAbsolute: true,- location: "below",- yOffset: 5,- },- }}- />- </Flex>- );- };+ return chain+ .updateAttributes(options.type, { listType: item.type })+ .run();+ },+ })),+ sx: { display: "grid", gridTemplateColumns: "1fr 1fr 1fr", p: 1 },+ }}+ />+ );}type NumberedListStyleTypes =@@ -103,67 +75,45 @@ type NumberedListStyleTypes =| "lower-alpha"| "upper-alpha"| "decimal";-export class NumberedList extends ListTool<NumberedListStyleTypes> {- constructor() {- const options: ListOptions<NumberedListStyleTypes> = {- type: "orderedList",- icon: "numberedList",- onClick: (editor) => editor.chain().focus().toggleOrderedList().run(),- subTypes: [- { type: "decimal", title: "Decimal", items: ["1", "2", "3"] },- { type: "upper-alpha", title: "Upper alpha", items: ["A", "B", "C"] },- { type: "lower-alpha", title: "Lower alpha", items: ["a", "b", "c"] },- {- type: "upper-roman",- title: "Upper Roman",- items: ["I", "II", "III"],- },- {- type: "lower-roman",- title: "Lower Roman",- items: ["i", "ii", "iii"],- },- { type: "lower-greek", title: "Lower Greek", items: ["α", "β", "γ"] },- ],- };- super("numberedList", "Numbered list", options);- }-}-type BulletListStyleTypes = "circle" | "square" | "disc";-export class BulletList extends ListTool<BulletListStyleTypes> {- constructor() {- const options: ListOptions<BulletListStyleTypes> = {- type: "bulletList",- icon: "bulletList",- onClick: (editor) => editor.chain().focus().toggleOrderedList().run(),- subTypes: [- { type: "disc", title: "Decimal", items: ["1", "2", "3"] },- { type: "circle", title: "Upper alpha", items: ["A", "B", "C"] },- { type: "square", title: "Lower alpha", items: ["a", "b", "c"] },- ],- };- super("bulletList", "Bullet list", options);- }+export function NumberedList(props: ToolProps) {+ const options: ListOptions<NumberedListStyleTypes> = {+ type: "orderedList",+ icon: "numberedList",+ onClick: (editor) => editor.chain().focus().toggleOrderedList().run(),+ subTypes: [+ { type: "decimal", title: "Decimal", items: ["1", "2", "3"] },+ { type: "upper-alpha", title: "Upper alpha", items: ["A", "B", "C"] },+ { type: "lower-alpha", title: "Lower alpha", items: ["a", "b", "c"] },+ {+ type: "upper-roman",+ title: "Upper Roman",+ items: ["I", "II", "III"],+ },+ {+ type: "lower-roman",+ title: "Lower Roman",+ items: ["i", "ii", "iii"],+ },+ { type: "lower-greek", title: "Lower Greek", items: ["α", "β", "γ"] },+ ],+ };+ return <ListTool {...props} options={options} />;}-export class Checklist implements ITool {- id: ToolId = "checklist";- title = "Checklist";-- render = (props: ToolProps) => {- const { editor } = props;-- return (- <ToolButton- title={this.title}- id={this.id}- icon="checklist"- onClick={() => editor.chain().focus().toggleTaskList().run()}- toggled={false}- />- );+type BulletListStyleTypes = "circle" | "square" | "disc";+export function BulletList(props: ToolProps) {+ const options: ListOptions<BulletListStyleTypes> = {+ type: "bulletList",+ icon: "bulletList",+ onClick: (editor) => editor.chain().focus().toggleOrderedList().run(),+ subTypes: [+ { type: "disc", title: "Decimal", items: ["1", "2", "3"] },+ { type: "circle", title: "Upper alpha", items: ["A", "B", "C"] },+ { type: "square", title: "Lower alpha", items: ["a", "b", "c"] },+ ],};+ return <ListTool {...props} options={options} />;}type ListThumbnailProps = { listStyleType: string };diff --git a/packages/editor/src/toolbar/tools/text-direction.tsx b/packages/editor/src/toolbar/tools/text-direction.tsxindex d058efc9b..8765e1ebe 100644--- a/packages/editor/src/toolbar/tools/text-direction.tsx+++ b/packages/editor/src/toolbar/tools/text-direction.tsx@@ -1,44 +1,25 @@-import { ITool, ToolProps } from "../types";-import { Editor } from "@tiptap/core";+import { ToolProps } from "../types";import { ToolButton } from "../components/tool-button";-import { ToolId } from ".";-import { IconNames } from "../icons";-class TextDirectionTool<TId extends ToolId, TTitle extends string>- implements ITool-{- constructor(- readonly id: TId,- readonly title: TTitle,- private readonly icon: IconNames,- private readonly direction: "ltr" | "rtl"- ) {}+type TextDirectionToolProps = ToolProps & {+ direction: "ltr" | "rtl";+};+function TextDirectionTool(props: TextDirectionToolProps) {+ const { editor, direction, ...toolProps } = props;- render = (props: ToolProps) => {- const { editor } = props;-- return (- <ToolButton- title={this.title}- id={this.id}- icon={this.icon}- onClick={() =>- editor.chain().focus().setTextDirection(this.direction).run()- }- toggled={editor.isActive({ textDirection: this.direction })}- />- );- };+ return (+ <ToolButton+ {...toolProps}+ onClick={() => editor.chain().focus().setTextDirection(direction).run()}+ toggled={editor.isActive({ textDirection: direction })}+ />+ );}-export class LeftToRight extends TextDirectionTool<ToolId, string> {- constructor() {- super("ltr", "Left-to-right", "ltr", "ltr");- }+export function RightToLeft(props: ToolProps) {+ return <TextDirectionTool direction="rtl" {...props} />;}-export class RightToLeft extends TextDirectionTool<ToolId, string> {- constructor() {- super("rtl", "Right-to-left", "rtl", "rtl");- }+export function LeftToRight(props: ToolProps) {+ return <TextDirectionTool direction="ltr" {...props} />;}diff --git a/packages/editor/toolbar.md b/packages/editor/toolbar.mdindex e2c3e0486..076181cd8 100644--- a/packages/editor/toolbar.md+++ b/packages/editor/toolbar.md@@ -91,6 +91,13 @@ What's next:1. A tool defines it's own UI- This gives it maximum flexibility to do whatever it wants.+ - However, this also restricts the tool to be shown in specific places+ - For example: if all block tools are defined as menu buttons, they can only be shown in a menu+ - But since this toolbar is application specific, this is alright. We already know where a certain+ tool is going to be rendered. Locking things down, while reduces flexibility, also allows us to+ easily customize a specific tool's behavior. A generic toolbar would be great in cases where multiple+ apps are going to be using it.2. Some factors of a tool's UI can be defined externally- For example, a tool's icon + title + description?-3.+3. It wouldn't be a bad idea to separate out action & toggle state of a tool as well. This can be useful in+ cases where we want to invoke a specific tool or get a specific tool's toggle state.