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
web: add text zoom functionality in editor (#6633) (#6846)
01zulfifab085579a3c
diff --git a/apps/web/src/components/editor/common.ts b/apps/web/src/components/editor/common.tsnew file mode 100644index 000000000..89fbdbf29--- /dev/null+++ b/apps/web/src/components/editor/common.ts@@ -0,0 +1,25 @@+/*+This file is part of the Notesnook project (https://notesnook.com/)++Copyright (C) 2023 Streetwriters (Private) Limited++This program is free software: you can redistribute it and/or modify+it under the terms of the GNU General Public License as published by+the Free Software Foundation, either version 3 of the License, or+(at your option) any later version.++This program is distributed in the hope that it will be useful,+but WITHOUT ANY WARRANTY; without even the implied warranty of+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+GNU General Public License for more details.++You should have received a copy of the GNU General Public License+along with this program. If not, see <http://www.gnu.org/licenses/>.+*/++export const EDITOR_ZOOM = {+ DEFAULT: 100,+ MAX: 500,+ MIN: 30,+ STEP: 10+};diff --git a/apps/web/src/components/editor/footer.tsx b/apps/web/src/components/editor/footer.tsxindex de1ca02d8..b9069f217 100644--- a/apps/web/src/components/editor/footer.tsx+++ b/apps/web/src/components/editor/footer.tsx@@ -20,10 +20,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.import { Button, Flex, Text } from "@theme-ui/components";import { SaveState, useEditorStore } from "../../stores/editor-store";import { Loading, Saved, NotSaved } from "../icons";-import { useNoteStatistics } from "./manager";+import { useEditorConfig, useNoteStatistics } from "./manager";import { getFormattedDate } from "@notesnook/common";import { MAX_AUTO_SAVEABLE_WORDS } from "./types";import { strings } from "@notesnook/intl";+import { EDITOR_ZOOM } from "./common";const SAVE_STATE_ICON_MAP = {"-1": NotSaved,@@ -34,6 +35,7 @@ const SAVE_STATE_ICON_MAP = {function EditorFooter() {const { words } = useNoteStatistics();const session = useEditorStore((store) => store.getActiveSession());+ const { editorConfig, setEditorConfig } = useEditorConfig();if (!session) return null;const saveState =@@ -43,6 +45,44 @@ function EditorFooter() {return (<Flex sx={{ alignItems: "center", justifyContent: "center", gap: 2 }}>+ <Flex sx={{ alignItems: "center", justifyContent: "center" }}>+ <Button+ variant="icon"+ onClick={() =>+ setEditorConfig({+ zoom: Math.max(+ EDITOR_ZOOM.MIN,+ editorConfig.zoom - EDITOR_ZOOM.STEP+ )+ })+ }+ disabled={editorConfig.zoom <= EDITOR_ZOOM.MIN}+ >+ <b>-</b>+ </Button>+ <Text+ className="selectable"+ data-test-id="editor-word-count"+ variant="subBody"+ sx={{ color: "paragraph" }}+ >+ {editorConfig.zoom}%+ </Text>+ <Button+ variant="icon"+ onClick={() =>+ setEditorConfig({+ zoom: Math.min(+ EDITOR_ZOOM.MAX,+ editorConfig.zoom + EDITOR_ZOOM.STEP+ )+ })+ }+ disabled={editorConfig.zoom >= EDITOR_ZOOM.MAX}+ >+ <b>+</b>+ </Button>+ </Flex>{words.total > MAX_AUTO_SAVEABLE_WORDS ? (<TextclassName="selectable"diff --git a/apps/web/src/components/editor/manager.ts b/apps/web/src/components/editor/manager.tsindex 9f1da6492..8450ba808 100644--- a/apps/web/src/components/editor/manager.ts+++ b/apps/web/src/components/editor/manager.ts@@ -24,8 +24,9 @@ import BaseStore from "../../stores";import type { TOCItem, ToolbarDefinition } from "@notesnook/editor";import Config from "../../utils/config";import { getCurrentPreset } from "../../common/toolbar-config";+import { EDITOR_ZOOM } from "./common";-type EditorConfig = { fontFamily: string; fontSize: number };+type EditorConfig = { fontFamily: string; fontSize: number; zoom: number };type EditorContext = {editor?: IEditor;canUndo?: boolean;@@ -39,7 +40,8 @@ class EditorManager extends BaseStore<EditorManager> {toolbarConfig?: ToolbarDefinition;editorConfig: EditorConfig = Config.get("editorConfig", {fontFamily: "sans-serif",- fontSize: 16+ fontSize: 16,+ zoom: EDITOR_ZOOM.DEFAULT});editors: Record<string, EditorContext> = {};diff --git a/apps/web/src/components/editor/tiptap.tsx b/apps/web/src/components/editor/tiptap.tsxindex 03dac7a46..6a51cc650 100644--- a/apps/web/src/components/editor/tiptap.tsx+++ b/apps/web/src/components/editor/tiptap.tsx@@ -62,6 +62,7 @@ import useMobile from "../../hooks/use-mobile";import useTablet from "../../hooks/use-tablet";import { TimeFormat } from "@notesnook/core";import { BuyDialog } from "../../dialogs/buy-dialog";+import { EDITOR_ZOOM } from "./common";export type OnChangeHandler = (content: () => string,@@ -413,7 +414,7 @@ function TiptapWrapper();const containerRef = useRef<HTMLDivElement>(null);const editorContainerRef = useRef<HTMLDivElement>();- const { editorConfig } = useEditorConfig();+ const { editorConfig, setEditorConfig } = useEditorConfig();const isMobile = useMobile();const isTablet = useTablet();@@ -443,6 +444,27 @@ function TiptapWrapper(}}, [isHydrating]);+ useEffect(() => {+ if (!editorContainerRef.current) return;++ const handleWheel = (e: WheelEvent) => {+ if (e.ctrlKey) {+ e.preventDefault();+ const delta =+ Math.ceil(-e.deltaY / 10 / EDITOR_ZOOM.STEP) * EDITOR_ZOOM.STEP;+ const zoom = Math.min(+ EDITOR_ZOOM.MAX,+ Math.max(EDITOR_ZOOM.MIN, editorConfig.zoom + delta)+ );+ setEditorConfig({ zoom });+ }+ };+ editorContainerRef.current.addEventListener("wheel", handleWheel);+ return () => {+ editorContainerRef.current?.removeEventListener("wheel", handleWheel);+ };+ }, [editorConfig.zoom]);+return (<Flexref={containerRef}@@ -450,7 +472,10 @@ function TiptapWrapper(flex: 1,flexDirection: "column",".tiptap.ProseMirror": { pb: 150 },- ".editor-container": { opacity: isHydrating ? 0 : 1 },+ ".editor-container": {+ opacity: isHydrating ? 0 : 1,+ zoom: editorConfig.zoom + "%"+ },".editor-loading-container.hidden": { display: "none" }}}>