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 text align & text direction one tool each
thecodrrb3a5444c91c3
diff --git a/packages/editor/dist/cjs/index.d.ts b/packages/editor/dist/cjs/index.d.tsindex a9204a864..1fe49d270 100644--- a/packages/editor/dist/cjs/index.d.ts+++ b/packages/editor/dist/cjs/index.d.ts@@ -1,3 +1,4 @@+/// <reference types="react" />import "./extensions";import Toolbar from "./toolbar";import { Theme } from "@notesnook/theme";diff --git a/packages/editor/dist/cjs/toolbar/components/toolbutton.js b/packages/editor/dist/cjs/toolbar/components/toolbutton.jsindex 21ca592ae..c69bdb590 100644--- a/packages/editor/dist/cjs/toolbar/components/toolbutton.js+++ b/packages/editor/dist/cjs/toolbar/components/toolbutton.js@@ -26,5 +26,5 @@ exports.ToolButton = react_1.default.memo(function ToolButton(props) {mr: 0,} }, sx), onMouseDown: (e) => e.preventDefault() }, buttonProps, { children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons[icon], color: iconColor || "icon", size: iconSize || (variant === "small" ? "medium" : "big") }) })));}, (prev, next) => {- return prev.toggled === next.toggled;+ return prev.toggled === next.toggled && prev.icon === next.icon;});diff --git a/packages/editor/dist/cjs/toolbar/tooldefinitions.d.ts b/packages/editor/dist/cjs/toolbar/tooldefinitions.d.tsindex 88e97b56c..576ba91b9 100644--- a/packages/editor/dist/cjs/toolbar/tooldefinitions.d.ts+++ b/packages/editor/dist/cjs/toolbar/tooldefinitions.d.ts@@ -1,5 +1,5 @@import { ToolbarDefinition, ToolDefinition } from "./types";import { ToolId } from "./tools";export declare function getToolDefinition(id: ToolId): ToolDefinition;-export declare function getAllTools(): Record<"fontSize" | "underline" | "bold" | "bulletList" | "code" | "italic" | "subscript" | "superscript" | "fontFamily" | "highlight" | "removeAttachment" | "downloadAttachment" | "deleteColumn" | "deleteRow" | "deleteTable" | "mergeCells" | "ltr" | "rtl" | "strikethrough" | "codeRemove" | "alignCenter" | "alignLeft" | "alignRight" | "alignJustify" | "numberedList" | "textColor" | "openLink" | "linkSettings" | "imageSettings" | "rowProperties" | "insertRowBelow" | "insertRowAbove" | "moveRowDown" | "moveRowUp" | "columnProperties" | "insertColumnRight" | "insertColumnLeft" | "moveColumnRight" | "moveColumnLeft" | "cellProperties" | "cellBorderColor" | "splitCells" | "attachmentSettings" | "embedSettings" | "tableSettings" | "math" | "clearformatting" | "addLink" | "editLink" | "removeLink" | "insertBlock" | "headings" | "imageAlignCenter" | "imageAlignLeft" | "imageAlignRight" | "imageProperties" | "embedAlignCenter" | "embedAlignLeft" | "embedAlignRight" | "embedProperties" | "cellBackgroundColor" | "cellTextColor" | "cellBorderWidth", ToolDefinition>;+export declare function getAllTools(): Record<"fontSize" | "underline" | "bold" | "bulletList" | "code" | "italic" | "subscript" | "superscript" | "textDirection" | "fontFamily" | "highlight" | "removeAttachment" | "downloadAttachment" | "deleteColumn" | "deleteRow" | "deleteTable" | "mergeCells" | "strikethrough" | "codeRemove" | "numberedList" | "textColor" | "openLink" | "linkSettings" | "imageSettings" | "rowProperties" | "insertRowBelow" | "insertRowAbove" | "moveRowDown" | "moveRowUp" | "columnProperties" | "insertColumnRight" | "insertColumnLeft" | "moveColumnRight" | "moveColumnLeft" | "cellProperties" | "cellBorderColor" | "splitCells" | "attachmentSettings" | "embedSettings" | "tableSettings" | "math" | "clearformatting" | "addLink" | "editLink" | "removeLink" | "insertBlock" | "headings" | "alignment" | "imageAlignCenter" | "imageAlignLeft" | "imageAlignRight" | "imageProperties" | "embedAlignCenter" | "embedAlignLeft" | "embedAlignRight" | "embedProperties" | "cellBackgroundColor" | "cellTextColor" | "cellBorderWidth", ToolDefinition>;export declare const DEFAULT_TOOLS: ToolbarDefinition;diff --git a/packages/editor/dist/cjs/toolbar/tooldefinitions.js b/packages/editor/dist/cjs/toolbar/tooldefinitions.jsindex 5866f0389..c6458168a 100644--- a/packages/editor/dist/cjs/toolbar/tooldefinitions.js+++ b/packages/editor/dist/cjs/toolbar/tooldefinitions.js@@ -88,29 +88,13 @@ const tools = {icon: "heading",title: "Headings",},- alignCenter: {+ alignment: {icon: "alignCenter",- title: "Align center",+ title: "Alignment",},- alignLeft: {- icon: "alignLeft",- title: "Align left",- },- alignRight: {- icon: "alignRight",- title: "Align right",- },- alignJustify: {- icon: "alignJustify",- title: "Justify",- },- ltr: {+ textDirection: {icon: "ltr",- title: "Left to right",- },- rtl: {- icon: "rtl",- title: "Right to left",+ title: "Text direction",},highlight: {icon: "highlight",@@ -331,6 +315,6 @@ exports.DEFAULT_TOOLS = [["headings", "fontFamily"],["numberedList", "bulletList"],["addLink"],- ["alignCenter", ["alignLeft", "alignRight", "alignJustify", "ltr", "rtl"]],+ ["alignment", "textDirection"],["clearformatting"],];diff --git a/packages/editor/dist/cjs/toolbar/tools/alignment.d.ts b/packages/editor/dist/cjs/toolbar/tools/alignment.d.tsindex 6e121e63e..198c68a56 100644--- a/packages/editor/dist/cjs/toolbar/tools/alignment.d.ts+++ b/packages/editor/dist/cjs/toolbar/tools/alignment.d.ts@@ -1,6 +1,3 @@/// <reference types="react" />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;+export declare function Alignment(props: ToolProps): JSX.Element;diff --git a/packages/editor/dist/cjs/toolbar/tools/alignment.js b/packages/editor/dist/cjs/toolbar/tools/alignment.jsindex 526c9ae45..933469739 100644--- a/packages/editor/dist/cjs/toolbar/tools/alignment.js+++ b/packages/editor/dist/cjs/toolbar/tools/alignment.js@@ -11,26 +11,37 @@ var __rest = (this && this.__rest) || function (s, e) {return t;};Object.defineProperty(exports, "__esModule", { value: true });-exports.AlignJustify = exports.AlignRight = exports.AlignLeft = exports.AlignCenter = void 0;+exports.Alignment = void 0;const jsx_runtime_1 = require("react/jsx-runtime");const toolbutton_1 = require("../components/toolbutton");+const useRefValue_1 = require("../../hooks/useRefValue");function AlignmentTool(props) {const { editor, alignment } = props, toolProps = __rest(props, ["editor", "alignment"]);- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, toolProps, { onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setTextAlign(alignment).run(); }, toggled: editor.isActive({ textAlign: alignment }) })));+ const alignmentRef = (0, useRefValue_1.useRefValue)(alignment);+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, toolProps, { onClick: () => {+ var _a;+ (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setTextAlign(alignmentRef.current).run();+ }, toggled: false })));}-function AlignCenter(props) {- return (0, jsx_runtime_1.jsx)(AlignmentTool, Object.assign({ alignment: "center" }, props));+function Alignment(props) {+ const { editor } = props;+ const { textAlign } = Object.assign(Object.assign({}, editor.getAttributes("paragraph")), editor.getAttributes("heading"));+ const newAlignment = textAlign === "left"+ ? "center"+ : textAlign === "center"+ ? "right"+ : textAlign === "right"+ ? "justify"+ : textAlign === "justify"+ ? "left"+ : "left";+ const icon = textAlign === "center"+ ? "alignCenter"+ : textAlign === "justify"+ ? "alignJustify"+ : textAlign === "right"+ ? "alignRight"+ : "alignLeft";+ return (0, jsx_runtime_1.jsx)(AlignmentTool, Object.assign({ alignment: newAlignment }, props, { icon: icon }));}-exports.AlignCenter = AlignCenter;-function AlignLeft(props) {- return (0, jsx_runtime_1.jsx)(AlignmentTool, Object.assign({ alignment: "left" }, props));-}-exports.AlignLeft = AlignLeft;-function AlignRight(props) {- return (0, jsx_runtime_1.jsx)(AlignmentTool, Object.assign({ alignment: "right" }, props));-}-exports.AlignRight = AlignRight;-function AlignJustify(props) {- return (0, jsx_runtime_1.jsx)(AlignmentTool, Object.assign({ alignment: "justify" }, props));-}-exports.AlignJustify = AlignJustify;+exports.Alignment = Alignment;diff --git a/packages/editor/dist/cjs/toolbar/tools/index.d.ts b/packages/editor/dist/cjs/toolbar/tools/index.d.tsindex df50761f4..099d7946f 100644--- a/packages/editor/dist/cjs/toolbar/tools/index.d.ts+++ b/packages/editor/dist/cjs/toolbar/tools/index.d.ts@@ -3,10 +3,10 @@ import { ToolProps } from "../types";import { Bold, Italic, Underline, Strikethrough, Code, Subscript, Superscript, ClearFormatting, CodeRemove, Math } from "./inline";import { InsertBlock } from "./block";import { FontSize, FontFamily } from "./font";-import { AlignCenter, AlignLeft, AlignRight, AlignJustify } from "./alignment";+import { Alignment } from "./alignment";import { Headings } from "./headings";import { NumberedList, BulletList } from "./lists";-import { LeftToRight, RightToLeft } from "./text-direction";+import { TextDirection } from "./text-direction";import { Highlight, TextColor } from "./colors";import { TableSettings, ColumnProperties, RowProperties, CellProperties, CellBackgroundColor, CellBorderColor, CellTextColor, CellBorderWidth } from "./table";import { ImageSettings, ImageAlignCenter, ImageAlignLeft, ImageAlignRight, ImageProperties } from "./image";@@ -35,12 +35,8 @@ declare const tools: {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;+ alignment: typeof Alignment;+ textDirection: typeof TextDirection;textColor: typeof TextColor;highlight: typeof Highlight;math: typeof Math;diff --git a/packages/editor/dist/cjs/toolbar/tools/index.js b/packages/editor/dist/cjs/toolbar/tools/index.jsindex d6450a27d..09091fcb5 100644--- a/packages/editor/dist/cjs/toolbar/tools/index.js+++ b/packages/editor/dist/cjs/toolbar/tools/index.js@@ -35,12 +35,8 @@ const tools = {fontSize: font_1.FontSize,fontFamily: font_1.FontFamily,headings: headings_1.Headings,- alignCenter: alignment_1.AlignCenter,- alignRight: alignment_1.AlignRight,- alignLeft: alignment_1.AlignLeft,- alignJustify: alignment_1.AlignJustify,- ltr: textdirection_1.LeftToRight,- rtl: textdirection_1.RightToLeft,+ alignment: alignment_1.Alignment,+ textDirection: textdirection_1.TextDirection,textColor: colors_1.TextColor,highlight: colors_1.Highlight,math: inline_1.Math,diff --git a/packages/editor/dist/cjs/toolbar/tools/textdirection.d.ts b/packages/editor/dist/cjs/toolbar/tools/textdirection.d.tsindex a625990f0..1acbfbb23 100644--- a/packages/editor/dist/cjs/toolbar/tools/textdirection.d.ts+++ b/packages/editor/dist/cjs/toolbar/tools/textdirection.d.ts@@ -1,4 +1,3 @@/// <reference types="react" />import { ToolProps } from "../types";-export declare function RightToLeft(props: ToolProps): JSX.Element;-export declare function LeftToRight(props: ToolProps): JSX.Element;+export declare function TextDirection(props: ToolProps): JSX.Element;diff --git a/packages/editor/dist/cjs/toolbar/tools/textdirection.js b/packages/editor/dist/cjs/toolbar/tools/textdirection.jsindex 8afc01850..05ee1f1e6 100644--- a/packages/editor/dist/cjs/toolbar/tools/textdirection.js+++ b/packages/editor/dist/cjs/toolbar/tools/textdirection.js@@ -11,18 +11,23 @@ var __rest = (this && this.__rest) || function (s, e) {return t;};Object.defineProperty(exports, "__esModule", { value: true });-exports.LeftToRight = exports.RightToLeft = void 0;+exports.TextDirection = void 0;const jsx_runtime_1 = require("react/jsx-runtime");const toolbutton_1 = require("../components/toolbutton");+const useRefValue_1 = require("../../hooks/useRefValue");function TextDirectionTool(props) {const { editor, direction } = props, toolProps = __rest(props, ["editor", "direction"]);- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, toolProps, { onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setTextDirection(direction).run(); }, toggled: editor.isActive({ textDirection: direction }) })));+ const directionRef = (0, useRefValue_1.useRefValue)(direction);+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, toolProps, { onClick: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setTextDirection(directionRef.current).run();+ }, toggled: false })));}-function RightToLeft(props) {- return (0, jsx_runtime_1.jsx)(TextDirectionTool, Object.assign({ direction: "rtl" }, props));+function TextDirection(props) {+ const { editor } = props;+ const { textDirection } = Object.assign(Object.assign({}, editor.getAttributes("paragraph")), editor.getAttributes("heading"));+ const newTextDirection = textDirection === "ltr" ? "rtl" : "ltr";+ const icon = textDirection === "ltr" ? "ltr" : "rtl";+ return ((0, jsx_runtime_1.jsx)(TextDirectionTool, Object.assign({ direction: newTextDirection }, props, { icon: icon })));}-exports.RightToLeft = RightToLeft;-function LeftToRight(props) {- return (0, jsx_runtime_1.jsx)(TextDirectionTool, Object.assign({ direction: "ltr" }, props));-}-exports.LeftToRight = LeftToRight;+exports.TextDirection = TextDirection;diff --git a/packages/editor/dist/es/index.d.ts b/packages/editor/dist/es/index.d.tsindex a9204a864..1fe49d270 100644--- a/packages/editor/dist/es/index.d.ts+++ b/packages/editor/dist/es/index.d.ts@@ -1,3 +1,4 @@+/// <reference types="react" />import "./extensions";import Toolbar from "./toolbar";import { Theme } from "@notesnook/theme";diff --git a/packages/editor/dist/es/index.js b/packages/editor/dist/es/index.jsindex 32ee99f12..4ce525788 100644--- a/packages/editor/dist/es/index.js+++ b/packages/editor/dist/es/index.js@@ -14,7 +14,7 @@ import CharacterCount from "@tiptap/extension-character-count";import Placeholder from "@tiptap/extension-placeholder";import Underline from "@tiptap/extension-underline";import StarterKit from "@tiptap/starter-kit";-import { useMemo } from "react";+import { useEffect, useMemo } from "react";import { EditorView } from "prosemirror-view";import Toolbar from "./toolbar";import TextAlign from "@tiptap/extension-text-align";@@ -47,7 +47,7 @@ import { NodeViewSelectionNotifier, usePortalProvider, } from "./extensions/reacimport { OutlineList } from "./extensions/outline-list";import { OutlineListItem } from "./extensions/outline-list-item";import { Table } from "./extensions/table";-import { useIsMobile } from "./toolbar/stores/toolbar-store";+import { useToolbarStore } from "./toolbar/stores/toolbar-store";import { useEditor } from "./hooks/use-editor";EditorView.prototype.updateState = function updateState(state) {if (!this.docView)@@ -55,11 +55,10 @@ EditorView.prototype.updateState = function updateState(state) {this.updateStateInner(state, this.state.plugins != state.plugins);};const useTiptap = (options = {}, deps = []) => {- const { theme, onDownloadAttachment, onOpenAttachmentPicker } = options, restOptions = __rest(options, ["theme", "onDownloadAttachment", "onOpenAttachmentPicker"]);+ const { theme, isMobile, onDownloadAttachment, onOpenAttachmentPicker } = options, restOptions = __rest(options, ["theme", "isMobile", "onDownloadAttachment", "onOpenAttachmentPicker"]);const PortalProviderAPI = usePortalProvider();- const isMobile = useIsMobile();+ const setIsMobile = useToolbarStore((store) => store.setIsMobile);const defaultOptions = useMemo(() => ({- // enableInputRules: ,extensions: [NodeViewSelectionNotifier,SearchReplace,@@ -139,6 +138,9 @@ const useTiptap = (options = {}, deps = []) => {isMobile,]);const editor = useEditor(Object.assign(Object.assign({}, defaultOptions), restOptions), deps);+ useEffect(() => {+ setIsMobile(isMobile || false);+ }, [isMobile]);return editor;};export { useTiptap, Toolbar };diff --git a/packages/editor/dist/es/toolbar/components/toolbutton.js b/packages/editor/dist/es/toolbar/components/toolbutton.jsindex b54d1bf2a..5fc9f8efb 100644--- a/packages/editor/dist/es/toolbar/components/toolbutton.js+++ b/packages/editor/dist/es/toolbar/components/toolbutton.js@@ -20,5 +20,5 @@ export const ToolButton = React.memo(function ToolButton(props) {mr: 0,} }, sx), onMouseDown: (e) => e.preventDefault() }, buttonProps, { children: _jsx(Icon, { path: Icons[icon], color: iconColor || "icon", size: iconSize || (variant === "small" ? "medium" : "big") }) })));}, (prev, next) => {- return prev.toggled === next.toggled;+ return prev.toggled === next.toggled && prev.icon === next.icon;});diff --git a/packages/editor/dist/es/toolbar/tooldefinitions.d.ts b/packages/editor/dist/es/toolbar/tooldefinitions.d.tsindex 88e97b56c..576ba91b9 100644--- a/packages/editor/dist/es/toolbar/tooldefinitions.d.ts+++ b/packages/editor/dist/es/toolbar/tooldefinitions.d.ts@@ -1,5 +1,5 @@import { ToolbarDefinition, ToolDefinition } from "./types";import { ToolId } from "./tools";export declare function getToolDefinition(id: ToolId): ToolDefinition;-export declare function getAllTools(): Record<"fontSize" | "underline" | "bold" | "bulletList" | "code" | "italic" | "subscript" | "superscript" | "fontFamily" | "highlight" | "removeAttachment" | "downloadAttachment" | "deleteColumn" | "deleteRow" | "deleteTable" | "mergeCells" | "ltr" | "rtl" | "strikethrough" | "codeRemove" | "alignCenter" | "alignLeft" | "alignRight" | "alignJustify" | "numberedList" | "textColor" | "openLink" | "linkSettings" | "imageSettings" | "rowProperties" | "insertRowBelow" | "insertRowAbove" | "moveRowDown" | "moveRowUp" | "columnProperties" | "insertColumnRight" | "insertColumnLeft" | "moveColumnRight" | "moveColumnLeft" | "cellProperties" | "cellBorderColor" | "splitCells" | "attachmentSettings" | "embedSettings" | "tableSettings" | "math" | "clearformatting" | "addLink" | "editLink" | "removeLink" | "insertBlock" | "headings" | "imageAlignCenter" | "imageAlignLeft" | "imageAlignRight" | "imageProperties" | "embedAlignCenter" | "embedAlignLeft" | "embedAlignRight" | "embedProperties" | "cellBackgroundColor" | "cellTextColor" | "cellBorderWidth", ToolDefinition>;+export declare function getAllTools(): Record<"fontSize" | "underline" | "bold" | "bulletList" | "code" | "italic" | "subscript" | "superscript" | "textDirection" | "fontFamily" | "highlight" | "removeAttachment" | "downloadAttachment" | "deleteColumn" | "deleteRow" | "deleteTable" | "mergeCells" | "strikethrough" | "codeRemove" | "numberedList" | "textColor" | "openLink" | "linkSettings" | "imageSettings" | "rowProperties" | "insertRowBelow" | "insertRowAbove" | "moveRowDown" | "moveRowUp" | "columnProperties" | "insertColumnRight" | "insertColumnLeft" | "moveColumnRight" | "moveColumnLeft" | "cellProperties" | "cellBorderColor" | "splitCells" | "attachmentSettings" | "embedSettings" | "tableSettings" | "math" | "clearformatting" | "addLink" | "editLink" | "removeLink" | "insertBlock" | "headings" | "alignment" | "imageAlignCenter" | "imageAlignLeft" | "imageAlignRight" | "imageProperties" | "embedAlignCenter" | "embedAlignLeft" | "embedAlignRight" | "embedProperties" | "cellBackgroundColor" | "cellTextColor" | "cellBorderWidth", ToolDefinition>;export declare const DEFAULT_TOOLS: ToolbarDefinition;diff --git a/packages/editor/dist/es/toolbar/tooldefinitions.js b/packages/editor/dist/es/toolbar/tooldefinitions.jsindex 026120ef6..e027167ce 100644--- a/packages/editor/dist/es/toolbar/tooldefinitions.js+++ b/packages/editor/dist/es/toolbar/tooldefinitions.js@@ -85,29 +85,13 @@ const tools = {icon: "heading",title: "Headings",},- alignCenter: {+ alignment: {icon: "alignCenter",- title: "Align center",+ title: "Alignment",},- alignLeft: {- icon: "alignLeft",- title: "Align left",- },- alignRight: {- icon: "alignRight",- title: "Align right",- },- alignJustify: {- icon: "alignJustify",- title: "Justify",- },- ltr: {+ textDirection: {icon: "ltr",- title: "Left to right",- },- rtl: {- icon: "rtl",- title: "Right to left",+ title: "Text direction",},highlight: {icon: "highlight",@@ -326,6 +310,6 @@ export const DEFAULT_TOOLS = [["headings", "fontFamily"],["numberedList", "bulletList"],["addLink"],- ["alignCenter", ["alignLeft", "alignRight", "alignJustify", "ltr", "rtl"]],+ ["alignment", "textDirection"],["clearformatting"],];diff --git a/packages/editor/dist/es/toolbar/tools/alignment.d.ts b/packages/editor/dist/es/toolbar/tools/alignment.d.tsindex 6e121e63e..198c68a56 100644--- a/packages/editor/dist/es/toolbar/tools/alignment.d.ts+++ b/packages/editor/dist/es/toolbar/tools/alignment.d.ts@@ -1,6 +1,3 @@/// <reference types="react" />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;+export declare function Alignment(props: ToolProps): JSX.Element;diff --git a/packages/editor/dist/es/toolbar/tools/alignment.js b/packages/editor/dist/es/toolbar/tools/alignment.jsindex 459a89cf8..fe15a0bf2 100644--- a/packages/editor/dist/es/toolbar/tools/alignment.js+++ b/packages/editor/dist/es/toolbar/tools/alignment.js@@ -11,19 +11,33 @@ var __rest = (this && this.__rest) || function (s, e) {};import { jsx as _jsx } from "react/jsx-runtime";import { ToolButton } from "../components/tool-button";+import { useRefValue } from "../../hooks/use-ref-value";function AlignmentTool(props) {const { editor, alignment } = props, toolProps = __rest(props, ["editor", "alignment"]);- return (_jsx(ToolButton, Object.assign({}, toolProps, { onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setTextAlign(alignment).run(); }, toggled: editor.isActive({ textAlign: alignment }) })));+ const alignmentRef = useRefValue(alignment);+ return (_jsx(ToolButton, Object.assign({}, toolProps, { onClick: () => {+ var _a;+ (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setTextAlign(alignmentRef.current).run();+ }, toggled: false })));}-export function AlignCenter(props) {- return _jsx(AlignmentTool, Object.assign({ alignment: "center" }, props));-}-export function AlignLeft(props) {- return _jsx(AlignmentTool, Object.assign({ alignment: "left" }, props));-}-export function AlignRight(props) {- return _jsx(AlignmentTool, Object.assign({ alignment: "right" }, props));-}-export function AlignJustify(props) {- return _jsx(AlignmentTool, Object.assign({ alignment: "justify" }, props));+export function Alignment(props) {+ const { editor } = props;+ const { textAlign } = Object.assign(Object.assign({}, editor.getAttributes("paragraph")), editor.getAttributes("heading"));+ const newAlignment = textAlign === "left"+ ? "center"+ : textAlign === "center"+ ? "right"+ : textAlign === "right"+ ? "justify"+ : textAlign === "justify"+ ? "left"+ : "left";+ const icon = textAlign === "center"+ ? "alignCenter"+ : textAlign === "justify"+ ? "alignJustify"+ : textAlign === "right"+ ? "alignRight"+ : "alignLeft";+ return _jsx(AlignmentTool, Object.assign({ alignment: newAlignment }, props, { icon: icon }));}diff --git a/packages/editor/dist/es/toolbar/tools/index.d.ts b/packages/editor/dist/es/toolbar/tools/index.d.tsindex df50761f4..099d7946f 100644--- a/packages/editor/dist/es/toolbar/tools/index.d.ts+++ b/packages/editor/dist/es/toolbar/tools/index.d.ts@@ -3,10 +3,10 @@ import { ToolProps } from "../types";import { Bold, Italic, Underline, Strikethrough, Code, Subscript, Superscript, ClearFormatting, CodeRemove, Math } from "./inline";import { InsertBlock } from "./block";import { FontSize, FontFamily } from "./font";-import { AlignCenter, AlignLeft, AlignRight, AlignJustify } from "./alignment";+import { Alignment } from "./alignment";import { Headings } from "./headings";import { NumberedList, BulletList } from "./lists";-import { LeftToRight, RightToLeft } from "./text-direction";+import { TextDirection } from "./text-direction";import { Highlight, TextColor } from "./colors";import { TableSettings, ColumnProperties, RowProperties, CellProperties, CellBackgroundColor, CellBorderColor, CellTextColor, CellBorderWidth } from "./table";import { ImageSettings, ImageAlignCenter, ImageAlignLeft, ImageAlignRight, ImageProperties } from "./image";@@ -35,12 +35,8 @@ declare const tools: {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;+ alignment: typeof Alignment;+ textDirection: typeof TextDirection;textColor: typeof TextColor;highlight: typeof Highlight;math: typeof Math;diff --git a/packages/editor/dist/es/toolbar/tools/index.js b/packages/editor/dist/es/toolbar/tools/index.jsindex 761442bdf..c3964019b 100644--- a/packages/editor/dist/es/toolbar/tools/index.js+++ b/packages/editor/dist/es/toolbar/tools/index.js@@ -1,10 +1,10 @@import { Bold, Italic, Underline, Strikethrough, Code, Subscript, Superscript, ClearFormatting, CodeRemove, Math, } from "./inline";import { InsertBlock } from "./block";import { FontSize, FontFamily } from "./font";-import { AlignCenter, AlignLeft, AlignRight, AlignJustify } from "./alignment";+import { Alignment } from "./alignment";import { Headings } from "./headings";import { NumberedList, BulletList } from "./lists";-import { LeftToRight, RightToLeft } from "./text-direction";+import { TextDirection } from "./text-direction";import { Highlight, TextColor } from "./colors";import { TableSettings, ColumnProperties, RowProperties, CellProperties, InsertColumnLeft, InsertColumnRight, MoveColumnLeft, MoveColumnRight, DeleteColumn, SplitCells, MergeCells, InsertRowAbove, InsertRowBelow, MoveRowUp, MoveRowDown, DeleteRow, DeleteTable, CellBackgroundColor, CellBorderColor, CellTextColor, CellBorderWidth, } from "./table";import { ImageSettings, ImageAlignCenter, ImageAlignLeft, ImageAlignRight, ImageProperties, } from "./image";@@ -32,12 +32,8 @@ const tools = {fontSize: FontSize,fontFamily: FontFamily,headings: Headings,- alignCenter: AlignCenter,- alignRight: AlignRight,- alignLeft: AlignLeft,- alignJustify: AlignJustify,- ltr: LeftToRight,- rtl: RightToLeft,+ alignment: Alignment,+ textDirection: TextDirection,textColor: TextColor,highlight: Highlight,math: Math,diff --git a/packages/editor/dist/es/toolbar/tools/textdirection.d.ts b/packages/editor/dist/es/toolbar/tools/textdirection.d.tsindex a625990f0..1acbfbb23 100644--- a/packages/editor/dist/es/toolbar/tools/textdirection.d.ts+++ b/packages/editor/dist/es/toolbar/tools/textdirection.d.ts@@ -1,4 +1,3 @@/// <reference types="react" />import { ToolProps } from "../types";-export declare function RightToLeft(props: ToolProps): JSX.Element;-export declare function LeftToRight(props: ToolProps): JSX.Element;+export declare function TextDirection(props: ToolProps): JSX.Element;diff --git a/packages/editor/dist/es/toolbar/tools/textdirection.js b/packages/editor/dist/es/toolbar/tools/textdirection.jsindex 352a49c9e..6943bcf27 100644--- a/packages/editor/dist/es/toolbar/tools/textdirection.js+++ b/packages/editor/dist/es/toolbar/tools/textdirection.js@@ -11,13 +11,19 @@ var __rest = (this && this.__rest) || function (s, e) {};import { jsx as _jsx } from "react/jsx-runtime";import { ToolButton } from "../components/tool-button";+import { useRefValue } from "../../hooks/use-ref-value";function TextDirectionTool(props) {const { editor, direction } = props, toolProps = __rest(props, ["editor", "direction"]);- return (_jsx(ToolButton, Object.assign({}, toolProps, { onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setTextDirection(direction).run(); }, toggled: editor.isActive({ textDirection: direction }) })));+ const directionRef = useRefValue(direction);+ return (_jsx(ToolButton, Object.assign({}, toolProps, { onClick: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setTextDirection(directionRef.current).run();+ }, toggled: false })));}-export function RightToLeft(props) {- return _jsx(TextDirectionTool, Object.assign({ direction: "rtl" }, props));-}-export function LeftToRight(props) {- return _jsx(TextDirectionTool, Object.assign({ direction: "ltr" }, props));+export function TextDirection(props) {+ const { editor } = props;+ const { textDirection } = Object.assign(Object.assign({}, editor.getAttributes("paragraph")), editor.getAttributes("heading"));+ const newTextDirection = textDirection === "ltr" ? "rtl" : "ltr";+ const icon = textDirection === "ltr" ? "ltr" : "rtl";+ return (_jsx(TextDirectionTool, Object.assign({ direction: newTextDirection }, props, { icon: icon })));}diff --git a/packages/editor/src/toolbar/components/tool-button.tsx b/packages/editor/src/toolbar/components/tool-button.tsxindex a4575955b..8c1061d2e 100644--- a/packages/editor/src/toolbar/components/tool-button.tsx+++ b/packages/editor/src/toolbar/components/tool-button.tsx@@ -61,6 +61,6 @@ export const ToolButton = React.memo();},(prev, next) => {- return prev.toggled === next.toggled;+ return prev.toggled === next.toggled && prev.icon === next.icon;});diff --git a/packages/editor/src/toolbar/tool-definitions.ts b/packages/editor/src/toolbar/tool-definitions.tsindex fa3632494..8980549f7 100644--- a/packages/editor/src/toolbar/tool-definitions.ts+++ b/packages/editor/src/toolbar/tool-definitions.ts@@ -88,29 +88,13 @@ const tools: Record<ToolId, ToolDefinition> = {icon: "heading",title: "Headings",},- alignCenter: {+ alignment: {icon: "alignCenter",- title: "Align center",+ title: "Alignment",},- alignLeft: {- icon: "alignLeft",- title: "Align left",- },- alignRight: {- icon: "alignRight",- title: "Align right",- },- alignJustify: {- icon: "alignJustify",- title: "Justify",- },- ltr: {+ textDirection: {icon: "ltr",- title: "Left to right",- },- rtl: {- icon: "rtl",- title: "Right to left",+ title: "Text direction",},highlight: {icon: "highlight",@@ -334,6 +318,6 @@ export const DEFAULT_TOOLS: ToolbarDefinition = [["headings", "fontFamily"],["numberedList", "bulletList"],["addLink"],- ["alignCenter", ["alignLeft", "alignRight", "alignJustify", "ltr", "rtl"]],+ ["alignment", "textDirection"],["clearformatting"],];diff --git a/packages/editor/src/toolbar/tools/alignment.tsx b/packages/editor/src/toolbar/tools/alignment.tsxindex a4126df68..4a8c9bd8d 100644--- a/packages/editor/src/toolbar/tools/alignment.tsx+++ b/packages/editor/src/toolbar/tools/alignment.tsx@@ -1,35 +1,57 @@import { ToolProps } from "../types";-import { Editor } from "@tiptap/core";import { ToolButton } from "../components/tool-button";-import { ToolId } from ".";-import { IconNames, Icons } from "../icons";+import { useRefValue } from "../../hooks/use-ref-value";+import { IconNames } from "../icons";+type Alignment = "left" | "right" | "center" | "justify";type AlignmentToolProps = ToolProps & {- alignment: "left" | "right" | "center" | "justify";+ alignment: Alignment;};function AlignmentTool(props: AlignmentToolProps) {const { editor, alignment, ...toolProps } = props;+ const alignmentRef = useRefValue(alignment);return (<ToolButton{...toolProps}- onClick={() =>- editor.current?.chain().focus().setTextAlign(alignment).run()- }- toggled={editor.isActive({ textAlign: alignment })}+ onClick={() => {+ editor.current+ ?.chain()+ .focus()+ .setTextAlign(alignmentRef.current)+ .run();+ }}+ toggled={false}/>);}-export function AlignCenter(props: ToolProps) {- return <AlignmentTool alignment="center" {...props} />;-}-export function AlignLeft(props: ToolProps) {- return <AlignmentTool alignment="left" {...props} />;-}-export function AlignRight(props: ToolProps) {- return <AlignmentTool alignment="right" {...props} />;-}-export function AlignJustify(props: ToolProps) {- return <AlignmentTool alignment="justify" {...props} />;+export function Alignment(props: ToolProps) {+ const { editor } = props;+ const { textAlign } = {+ ...editor.getAttributes("paragraph"),+ ...editor.getAttributes("heading"),+ } as { textAlign: Alignment };++ const newAlignment: Alignment =+ textAlign === "left"+ ? "center"+ : textAlign === "center"+ ? "right"+ : textAlign === "right"+ ? "justify"+ : textAlign === "justify"+ ? "left"+ : "left";++ const icon: IconNames =+ textAlign === "center"+ ? "alignCenter"+ : textAlign === "justify"+ ? "alignJustify"+ : textAlign === "right"+ ? "alignRight"+ : "alignLeft";++ return <AlignmentTool alignment={newAlignment} {...props} icon={icon} />;}diff --git a/packages/editor/src/toolbar/tools/index.ts b/packages/editor/src/toolbar/tools/index.tsindex 82d9d4db4..2436aad6f 100644--- a/packages/editor/src/toolbar/tools/index.ts+++ b/packages/editor/src/toolbar/tools/index.ts@@ -14,10 +14,10 @@ import {} from "./inline";import { InsertBlock } from "./block";import { FontSize, FontFamily } from "./font";-import { AlignCenter, AlignLeft, AlignRight, AlignJustify } from "./alignment";+import { Alignment } from "./alignment";import { Headings } from "./headings";import { NumberedList, BulletList } from "./lists";-import { LeftToRight, RightToLeft } from "./text-direction";+import { TextDirection } from "./text-direction";import { Highlight, TextColor } from "./colors";import {TableSettings,@@ -85,12 +85,8 @@ const tools = {fontSize: FontSize,fontFamily: FontFamily,headings: Headings,- alignCenter: AlignCenter,- alignRight: AlignRight,- alignLeft: AlignLeft,- alignJustify: AlignJustify,- ltr: LeftToRight,- rtl: RightToLeft,+ alignment: Alignment,+ textDirection: TextDirection,textColor: TextColor,highlight: Highlight,math: Math,diff --git a/packages/editor/src/toolbar/tools/text-direction.tsx b/packages/editor/src/toolbar/tools/text-direction.tsxindex 8603fb431..77b13bde1 100644--- a/packages/editor/src/toolbar/tools/text-direction.tsx+++ b/packages/editor/src/toolbar/tools/text-direction.tsx@@ -1,27 +1,44 @@import { ToolProps } from "../types";import { ToolButton } from "../components/tool-button";+import { IconNames } from "../icons";+import { useRefValue } from "../../hooks/use-ref-value";+type TextDirection = "ltr" | "rtl";type TextDirectionToolProps = ToolProps & {- direction: "ltr" | "rtl";+ direction: TextDirection;};function TextDirectionTool(props: TextDirectionToolProps) {const { editor, direction, ...toolProps } = props;+ const directionRef = useRefValue(direction);return (<ToolButton{...toolProps}onClick={() =>- editor.current?.chain().focus().setTextDirection(direction).run()+ editor.current+ ?.chain()+ .focus()+ .setTextDirection(directionRef.current)+ .run()}- toggled={editor.isActive({ textDirection: direction })}+ toggled={false}/>);}-export function RightToLeft(props: ToolProps) {- return <TextDirectionTool direction="rtl" {...props} />;-}+export function TextDirection(props: ToolProps) {+ const { editor } = props;+ const { textDirection } = {+ ...editor.getAttributes("paragraph"),+ ...editor.getAttributes("heading"),+ } as { textDirection: TextDirection };++ const newTextDirection: TextDirection =+ textDirection === "ltr" ? "rtl" : "ltr";++ const icon: IconNames = textDirection === "ltr" ? "ltr" : "rtl";-export function LeftToRight(props: ToolProps) {- return <TextDirectionTool direction="ltr" {...props} />;+ return (+ <TextDirectionTool direction={newTextDirection} {...props} icon={icon} />+ );}diff --git a/packages/editor/toolbar.md b/packages/editor/toolbar.mdindex 74b296bf1..fb720103d 100644--- a/packages/editor/toolbar.md+++ b/packages/editor/toolbar.md@@ -73,9 +73,9 @@ Total Tools:What's next:-- [ ] Port codeblock extension from tinymce to tiptap-- [ ] Optimize toolbar & editor UI for mobile-- [ ] Refactor & finalize UI + styling+- [x] Port codeblock extension from tinymce to tiptap+- [x] Optimize toolbar & editor UI for mobile+- [x] Refactor & finalize UI + styling- [ ] Write tests## Optimize toolbar & editor UI for mobilediff --git a/packages/editor/tsconfig.json b/packages/editor/tsconfig.jsonindex 17459804c..5379960d7 100644--- a/packages/editor/tsconfig.json+++ b/packages/editor/tsconfig.json@@ -11,7 +11,7 @@// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. *//* Language and Environment */- "target": "ES2015" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,+ "target": "ES6" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,"lib": ["DOM","DOM.Iterable",@@ -28,7 +28,7 @@// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. *//* Modules */- "module": "commonjs" /* Specify what module code is generated. */,+ "module": "esnext" /* Specify what module code is generated. */,// "rootDir": "./", /* Specify the root folder within your source files. */"moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */@@ -51,7 +51,7 @@// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */// "sourceMap": true, /* Create source map files for emitted JavaScript files. */// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */- "outDir": "./dist/cjs" /* Specify an output folder for all emitted files. */,+ "outDir": "./dist/es" /* Specify an output folder for all emitted files. */,// "removeComments": true, /* Disable emitting comments. */// "noEmit": true, /* Disable emitting files from a compilation. */// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */