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: improve font size tool ux
thecodrra8be830d5a54
diff --git a/packages/editor/dist/toolbar/components/toolbutton.js b/packages/editor/dist/toolbar/components/toolbutton.jsindex 29fde82e0..ab2672bb7 100644--- a/packages/editor/dist/toolbar/components/toolbutton.js+++ b/packages/editor/dist/toolbar/components/toolbutton.js@@ -28,5 +28,5 @@ export function ToolButton(props) {var id = props.id, icon = props.icon, iconSize = props.iconSize, iconColor = props.iconColor, toggled = props.toggled, sx = props.sx, buttonRef = props.buttonRef, _a = props.variant, variant = _a === void 0 ? "normal" : _a, buttonProps = __rest(props, ["id", "icon", "iconSize", "iconColor", "toggled", "sx", "buttonRef", "variant"]);return (_jsx(Button, __assign({ ref: buttonRef, tabIndex: -1, id: "tool-".concat(id), sx: __assign({ p: variant === "small" ? "3px" : 1, borderRadius: variant === "small" ? "small" : "default", m: 0, bg: toggled ? "hover" : "transparent", mr: variant === "small" ? 0 : 1, ":hover": { bg: "hover" }, ":last-of-type": {mr: 0,- } }, sx) }, buttonProps, { children: _jsx(Icon, { path: Icons[icon], color: iconColor || "text", size: iconSize || variant === "small" ? 16 : 18 }) })));+ } }, sx), onMouseDown: function (e) { return e.preventDefault(); } }, buttonProps, { children: _jsx(Icon, { path: Icons[icon], color: iconColor || "text", size: iconSize || variant === "small" ? 16 : 18 }) })));}diff --git a/packages/editor/dist/toolbar/icons.d.ts b/packages/editor/dist/toolbar/icons.d.tsindex ccaed4da3..dc80ff5aa 100644--- a/packages/editor/dist/toolbar/icons.d.ts+++ b/packages/editor/dist/toolbar/icons.d.ts@@ -62,6 +62,7 @@ export declare const Icons: {regex: string;embed: string;plus: string;+ minus: string;close: string;delete: string;download: string;diff --git a/packages/editor/dist/toolbar/icons.js b/packages/editor/dist/toolbar/icons.jsindex eeb1b52e1..c9bddfed3 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, mdiTableRowPlusAfter, 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, mdiTableColumnWidth, mdiTableRowHeight, } 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, mdiTableRowPlusAfter, 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, mdiTableColumnWidth, mdiTableRowHeight, mdiMinus, } from "@mdi/js";export var Icons = {bold: mdiFormatBold,italic: mdiFormatItalic,@@ -63,6 +63,7 @@ export var Icons = {regex: mdiRegex,embed: mdiMoviePlusOutline,plus: mdiPlus,+ minus: mdiMinus,close: mdiClose,delete: mdiDeleteOutline,download: mdiDownloadOutline,diff --git a/packages/editor/dist/toolbar/toolbar.js b/packages/editor/dist/toolbar/toolbar.jsindex 450a01f9a..073f309d2 100644--- a/packages/editor/dist/toolbar/toolbar.js+++ b/packages/editor/dist/toolbar/toolbar.js@@ -73,7 +73,8 @@ export function Toolbar(props) {"textColor",],],- ["fontSize", "headings", "fontFamily"],+ ["fontSize"],+ ["headings", "fontFamily"],["numberedList", "bulletList"],["link"],["alignCenter", ["alignLeft", "alignRight", "alignJustify", "ltr", "rtl"]],diff --git a/packages/editor/dist/toolbar/tools/font.js b/packages/editor/dist/toolbar/tools/font.jsindex e191ace48..24613fe27 100644--- a/packages/editor/dist/toolbar/tools/font.js+++ b/packages/editor/dist/toolbar/tools/font.js@@ -25,32 +25,38 @@ var __read = (this && this.__read) || function (o, n) {}return ar;};-import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";+import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";import { Dropdown } from "../components/dropdown";-import { Box, Button } from "rebass";+import { Flex, Text } from "rebass";+import { ToolButton } from "../components/tool-button";+import { useCallback } from "react";var defaultFontSizes = [8, 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: [- {- key: "font-sizes",- type: "menuitem",- component: function () { return (_jsx(Box, __assign({ sx: { display: "grid", gridTemplateColumns: "repeat(5, 1fr)" } }, { children: defaultFontSizes.map(function (size) { return (_jsxs(Button, __assign({ variant: "menuitem" }, { children: [size, "px"] }))); }) }))); },+ var _a = editor.getAttributes("textStyle").fontSize, fontSize = _a === void 0 ? "16px" : _a;+ var fontSizeAsNumber = parseInt(fontSize.replace("px", ""));+ var decreaseFontSize = useCallback(function () {+ return Math.max(8, fontSizeAsNumber - 1);+ }, [fontSizeAsNumber]);+ return (_jsxs(Flex, __assign({ sx: {+ alignItems: "center",+ mr: 1,+ ":last-of-type": {+ mr: 0,},- ],- // 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 }));+ } }, { children: [_jsx(ToolButton, { toggled: false, title: "Decrease font size", icon: "minus", variant: "small", onClick: function () {+ editor.chain().focus().setFontSize("".concat(decreaseFontSize(), "px")).run();+ } }), _jsx(Text, __assign({ variant: "body", sx: { fontSize: 12, mx: "3px", textAlign: "center" }, title: "Reset font size", onClick: function () {+ editor.chain().focus().setFontSize("16px").run();+ } }, { children: fontSize })), _jsx(ToolButton, { toggled: false, title: "Increase font size", icon: "plus", variant: "small", onClick: function () {+ editor+ .chain()+ .focus()+ .setFontSize("".concat(fontSizeAsNumber + 1, "px"))+ .run();+ } })] })));}var fontFamilies = {System: "Open Sans",diff --git a/packages/editor/src/toolbar/components/tool-button.tsx b/packages/editor/src/toolbar/components/tool-button.tsxindex 440fda48a..f1531a708 100644--- a/packages/editor/src/toolbar/components/tool-button.tsx+++ b/packages/editor/src/toolbar/components/tool-button.tsx@@ -42,6 +42,7 @@ export function ToolButton(props: ToolButtonProps) {},...sx,}}+ onMouseDown={(e) => e.preventDefault()}{...buttonProps}><Icondiff --git a/packages/editor/src/toolbar/icons.ts b/packages/editor/src/toolbar/icons.tsindex bf3ff3b2f..f973bca00 100644--- a/packages/editor/src/toolbar/icons.ts+++ b/packages/editor/src/toolbar/icons.ts@@ -82,6 +82,7 @@ import {mdiTableColumn,mdiTableColumnWidth,mdiTableRowHeight,+ mdiMinus,} from "@mdi/js";export const Icons = {@@ -151,6 +152,7 @@ export const Icons = {embed: mdiMoviePlusOutline,plus: mdiPlus,+ minus: mdiMinus,close: mdiClose,delete: mdiDeleteOutline,download: mdiDownloadOutline,diff --git a/packages/editor/src/toolbar/toolbar.tsx b/packages/editor/src/toolbar/toolbar.tsxindex 3de4267d6..1411f591c 100644--- a/packages/editor/src/toolbar/toolbar.tsx+++ b/packages/editor/src/toolbar/toolbar.tsx@@ -61,7 +61,8 @@ export function Toolbar(props: ToolbarProps) {"textColor",],],- ["fontSize", "headings", "fontFamily"],+ ["fontSize"],+ ["headings", "fontFamily"],["numberedList", "bulletList"],["link"],["alignCenter", ["alignLeft", "alignRight", "alignJustify", "ltr", "rtl"]],diff --git a/packages/editor/src/toolbar/tools/font.tsx b/packages/editor/src/toolbar/tools/font.tsxindex 9469477e5..ef4203557 100644--- a/packages/editor/src/toolbar/tools/font.tsx+++ b/packages/editor/src/toolbar/tools/font.tsx@@ -3,46 +3,66 @@ import { Dropdown } from "../components/dropdown";import { ToolId } from ".";import { MenuItem } from "../../components/menu/types";import { Editor } from "@tiptap/core";-import { Box, Button, Flex } from "rebass";+import { Box, Button, Flex, Text } from "rebass";import { Slider } from "@rebass/forms";+import { ToolButton } from "../components/tool-button";+import { useCallback } from "react";const defaultFontSizes = [8, 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;+ const { fontSize = "16px" } = editor.getAttributes("textStyle");+ const fontSizeAsNumber = parseInt(fontSize.replace("px", ""));++ const decreaseFontSize = useCallback(() => {+ return Math.max(8, fontSizeAsNumber - 1);+ }, [fontSizeAsNumber]);return (- <Dropdown- selectedItem={`${currentFontSize}px`}- items={[- {- key: "font-sizes",- type: "menuitem",- component: () => (- <Box- sx={{ display: "grid", gridTemplateColumns: "repeat(5, 1fr)" }}- >- {defaultFontSizes.map((size) => (- <Button variant={"menuitem"}>{size}px</Button>- ))}- </Box>- ),+ <Flex+ sx={{+ alignItems: "center",+ mr: 1,+ ":last-of-type": {+ mr: 0,},- ]}- // 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}- />+ }}+ >+ <ToolButton+ toggled={false}+ title="Decrease font size"+ icon="minus"+ variant={"small"}+ onClick={() => {+ editor.chain().focus().setFontSize(`${decreaseFontSize()}px`).run();+ }}+ />+ <Text+ variant={"body"}+ sx={{ fontSize: 12, mx: "3px", textAlign: "center" }}+ title="Reset font size"+ onClick={() => {+ editor.chain().focus().setFontSize(`16px`).run();+ }}+ >+ {fontSize}+ </Text>+ <ToolButton+ toggled={false}+ title="Increase font size"+ icon="plus"+ variant={"small"}+ onClick={() => {+ editor+ .chain()+ .focus()+ .setFontSize(`${fontSizeAsNumber + 1}px`)+ .run();+ }}+ />+ </Flex>);}diff --git a/packages/editor/toolbar.md b/packages/editor/toolbar.mdindex bf65cf4e8..8b27d16c9 100644--- a/packages/editor/toolbar.md+++ b/packages/editor/toolbar.md@@ -108,3 +108,7 @@ What's next:- For example, a tool's icon + title + description?3. It wouldn't be a bad idea to separate out action & toggle state of a tool as well. This can be useful incases where we want to invoke a specific tool or get a specific tool's toggle state.++---++1. Keyboard shouldn't close on tool click