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 support for toggling spellcheck per note Signed-off-by: 01zulfi <[email protected]>
01zulfif6b59eeb9991
diff --git a/apps/web/src/common/app-events.ts b/apps/web/src/common/app-events.tsindex 9fdd8467c..ce157d9bc 100644--- a/apps/web/src/common/app-events.ts+++ b/apps/web/src/common/app-events.ts@@ -44,5 +44,6 @@ export const AppEvents = {toggleEditor: "app:toggleEditor",onOpenLink: "onOpenLink",- onCreateItem: "onCreateItem"+ onCreateItem: "onCreateItem",+ spellcheckUpdated: "spellcheck:updated"};diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsxindex b2d8824ba..1c8dc2a64 100644--- a/apps/web/src/components/editor/index.tsx+++ b/apps/web/src/components/editor/index.tsx@@ -407,7 +407,8 @@ function EditorView({}}options={{readonly: session?.type === "readonly" || session?.type === "deleted",- focusMode: isFocusMode+ focusMode: isFocusMode,+ spellcheck: "note" in session && session.note.spellcheck}}/></Flex>@@ -472,6 +473,7 @@ type EditorOptions = {headless?: boolean;readonly?: boolean;focusMode?: boolean;+ spellcheck?: boolean;onRequestFocus?: () => void;};type EditorProps = {@@ -497,10 +499,11 @@ export function Editor(props: EditorProps) {onContentChange,onPreviewDocument} = props;- const { readonly, headless } = options || {+ const { readonly, headless, spellcheck } = options || {headless: false,readonly: false,- focusMode: false+ focusMode: false,+ spellcheck: false};const saveSessionContentIfNotSaved = useEditorStore((store) => store.saveSessionContentIfNotSaved@@ -554,6 +557,7 @@ export function Editor(props: EditorProps) {isHydrating={!!session.needsHydration}nonce={nonce}readonly={readonly}+ spellcheck={spellcheck}content={content}downloadOptions={{corsHost: Config.get("corsProxy", "https://cors.notesnook.com")diff --git a/apps/web/src/components/editor/tiptap.tsx b/apps/web/src/components/editor/tiptap.tsxindex 291f95441..5db4814b0 100644--- a/apps/web/src/components/editor/tiptap.tsx+++ b/apps/web/src/components/editor/tiptap.tsx@@ -99,6 +99,7 @@ type TipTapProps = {onAutoSaveDisabled: () => void;content?: () => string | undefined;readonly?: boolean;+ spellcheck?: boolean;nonce?: number;isMobile?: boolean;isTablet?: boolean;@@ -664,6 +665,26 @@ function TiptapWrapper(};}, [editorConfig.zoom]);+ useEffect(() => {+ const { unsubscribe } = AppEventManager.subscribe(+ AppEvents.spellcheckUpdated,+ ({ noteIds, spellcheck }) => {+ const session = useEditorStore.getState().getSession(props.id);+ if (+ session &&+ "note" in session &&+ noteIds.includes(session.note.id) &&+ editorContainerRef.current+ ) {+ editorContainerRef.current.spellcheck = spellcheck;+ }+ }+ );+ return () => {+ unsubscribe();+ };+ }, []);+return (<Flexref={containerRef}@@ -711,6 +732,7 @@ function TiptapWrapper(editorContainer.style.fontFamily =getFontById(editorConfig.fontFamily)?.font || "sans-serif";editorContainer.tabIndex = -1;+ editorContainer.spellcheck = props.spellcheck === true;editorContainerRef.current = editorContainer;return editorContainer;}}diff --git a/apps/web/src/components/editor/title-box.tsx b/apps/web/src/components/editor/title-box.tsxindex d9aa85156..f8f376e75 100644--- a/apps/web/src/components/editor/title-box.tsx+++ b/apps/web/src/components/editor/title-box.tsx@@ -43,6 +43,10 @@ function TitleBox(props: TitleBoxProps) {const session = store.getSession(id, ["default"]);return session?.note.isGeneratedTitle ? session.note.title : null;});+ const sessionSpellcheck = useEditorStore((store) => {+ const session = store.getSession(id);+ return session && "note" in session && session?.note.spellcheck;+ });const { editorConfig } = useEditorConfig();const dateFormat = useSettingsStore((store) => store.dateFormat);const timeFormat = useSettingsStore((store) => store.timeFormat);@@ -91,8 +95,30 @@ function TitleBox(props: TitleBoxProps) {});+ const { unsubscribe: unsubscribeSpellcheckUpdatedEvent } =+ AppEventManager.subscribe(+ AppEvents.spellcheckUpdated,+ ({ noteIds, spellcheck }) => {+ const sessions = useEditorStore.getState().sessions;+ const sessionsToUpdate: string[] = [];+ for (const session of sessions) {+ if ("note" in session && noteIds.includes(session.note.id)) {+ sessionsToUpdate.push(session.id);+ }+ }+ for (const sessionId of sessionsToUpdate) {+ const sessionTitleBox = document.querySelector(+ `#editor-title[data-session-id="${sessionId}"]`+ ) as HTMLTextAreaElement;+ if (!sessionTitleBox) continue;+ sessionTitleBox.spellcheck = spellcheck;+ }+ }+ );+return () => {unsubscribe();+ unsubscribeSpellcheckUpdatedEvent();};}, [id]);@@ -102,9 +128,11 @@ function TitleBox(props: TitleBoxProps) {variant="clean"id={`editor-title-${id}`}data-test-id="editor-title"+ data-session-id={id}className="editorTitle"placeholder={strings.noteTitle()}readOnly={readonly}+ spellCheck={sessionSpellcheck}dir="auto"wrap="soft"rows={1}diff --git a/apps/web/src/components/icons/index.tsx b/apps/web/src/components/icons/index.tsxindex 734b82e2f..fe72cfa5e 100644--- a/apps/web/src/components/icons/index.tsx+++ b/apps/web/src/components/icons/index.tsx@@ -228,7 +228,8 @@ import {mdiNoteEditOutline,mdiArrowUp,mdiInbox,- mdiConsoleLine+ mdiConsoleLine,+ mdiSpellcheck} from "@mdi/js";import { useTheme } from "@emotion/react";import { Theme } from "@notesnook/theme";@@ -584,3 +585,4 @@ export const ExpandSidebar = createIcon(mdiArrowCollapseRight);export const HamburgerMenu = createIcon(mdiMenu);export const ArrowUp = createIcon(mdiArrowUp);export const Inbox = createIcon(mdiInbox);+export const SpellCheck = createIcon(mdiSpellcheck);diff --git a/apps/web/src/components/note/index.tsx b/apps/web/src/components/note/index.tsxindex 9f99da8ff..35cf1e160 100644--- a/apps/web/src/components/note/index.tsx+++ b/apps/web/src/components/note/index.tsx@@ -89,6 +89,7 @@ import {Readonly,Reminder,RemoveShortcutLink,+ SpellCheck,Star,StarOutline,Sync,@@ -104,6 +105,7 @@ import { PublishDialog } from "../publish-view";import TimeAgo from "../time-ago";import { NoteExpiryDateDialog } from "../../dialogs/note-expiry-date-dialog";import { withFeatureCheck } from "../../common";+import { useSpellChecker } from "../../hooks/use-spell-checker";type NoteProps = NoteResolvedData & {item: NoteType;@@ -419,6 +421,16 @@ export const noteMenuItems: (onClick: () => store.archive(!note.archived, ...ids),multiSelect: true},+ {+ type: "button",+ key: "spellcheck",+ title: strings.spellCheck(),+ isChecked: note.spellcheck,+ icon: SpellCheck.path,+ isHidden: IS_DESKTOP_APP && !useSpellChecker.getState().enabled,+ onClick: () => store.spellcheck(!note.spellcheck, ...ids),+ multiSelect: true+ },{ key: "sep1", type: "separator" },{type: "button",diff --git a/apps/web/src/components/properties/index.tsx b/apps/web/src/components/properties/index.tsxindex f35278e73..ad286d396 100644--- a/apps/web/src/components/properties/index.tsx+++ b/apps/web/src/components/properties/index.tsx@@ -32,7 +32,8 @@ import {ReferencedIn as ReferencedInIcon,Note as NoteIcon,Archive,- Edit+ Edit,+ SpellCheck} from "../icons";import { Button, Flex, Text, FlexProps } from "@theme-ui/components";import {@@ -94,6 +95,12 @@ const tools = [icon: SyncOff,label: strings.disableSync(),property: "localOnly"+ },+ {+ key: "spellcheck",+ icon: SpellCheck,+ label: strings.spellCheck(),+ property: "spellcheck"}] as const;@@ -873,7 +880,14 @@ export function Section({}function changeToggleState(- prop: "lock" | "readonly" | "local-only" | "pin" | "favorite" | "archive",+ prop:+ | "lock"+ | "readonly"+ | "local-only"+ | "pin"+ | "favorite"+ | "archive"+ | "spellcheck",session: ReadonlyEditorSession | DefaultEditorSession) {const {@@ -882,7 +896,8 @@ function changeToggleState(localOnly,pinned,favorite,- archived+ archived,+ spellcheck} = session.note;if (!sessionId) return;switch (prop) {@@ -900,6 +915,8 @@ function changeToggleState(return noteStore.favorite(!favorite, sessionId);case "archive":return noteStore.archive(!archived, sessionId);+ case "spellcheck":+ return noteStore.spellcheck(!spellcheck, sessionId);default:return;}diff --git a/apps/web/src/stores/editor-store.ts b/apps/web/src/stores/editor-store.tsindex c16e02d0b..f6f64f3ab 100644--- a/apps/web/src/stores/editor-store.ts+++ b/apps/web/src/stores/editor-store.ts@@ -410,6 +410,8 @@ class EditorStore extends BaseStore<EditorStore> {event.item.dateCreated ?? session.note.dateCreated;session.note.dateEdited =event.item.dateEdited ?? session.note.dateEdited;+ session.note.spellcheck =+ event.item.spellcheck ?? session.note.spellcheck;});}}diff --git a/apps/web/src/stores/note-store.ts b/apps/web/src/stores/note-store.tsindex fe1fe0e32..7e44114d8 100644--- a/apps/web/src/stores/note-store.ts+++ b/apps/web/src/stores/note-store.ts@@ -26,6 +26,7 @@ import BaseStore from ".";import Config from "../utils/config";import { Note, VirtualizedGrouping } from "@notesnook/core";import { Context } from "../components/list-container/types";+import { AppEventManager, AppEvents } from "../common/app-events";type ViewMode = "detailed" | "compact";class NoteStore extends BaseStore<NoteStore> {@@ -94,6 +95,16 @@ class NoteStore extends BaseStore<NoteStore> {await this.refresh();};+ spellcheck = async (state: boolean, ...ids: string[]) => {+ await db.notes.spellcheck(state, ...ids);+ await this.refresh();++ AppEventManager.publish(AppEvents.spellcheckUpdated, {+ noteIds: ids,+ spellcheck: state+ });+ };+unlock = async (id: string) => {return await Vault.unlockNote(id).then(async (res) => {await this.refresh();diff --git a/packages/core/src/collections/notes.ts b/packages/core/src/collections/notes.tsindex ad5c868e5..1d0347608 100644--- a/packages/core/src/collections/notes.ts+++ b/packages/core/src/collections/notes.ts@@ -367,6 +367,9 @@ export class Notes implements ICollection {await this.db.content.updateByNoteId({ localOnly: state }, ...ids);});}+ spellcheck(state: boolean, ...ids: string[]) {+ return this.collection.update(ids, { spellcheck: state });+ }async export(id: string, options: ExportOptions): Promise<false | string>;async export(note: Note, options: ExportOptions): Promise<false | string>;diff --git a/packages/core/src/database/index.ts b/packages/core/src/database/index.tsindex 86b7c8f64..f9e03c45a 100644--- a/packages/core/src/database/index.ts+++ b/packages/core/src/database/index.ts@@ -236,7 +236,8 @@ const BooleanProperties: Set<BooleanFields> = new Set(["synced","isGeneratedTitle","archived",- "selfDestruct"+ "selfDestruct",+ "spellcheck"]);const DataMappers: Partial<Record<ItemType, (row: any) => void>> = {diff --git a/packages/core/src/database/migrations.ts b/packages/core/src/database/migrations.tsindex 03f3f33f9..cfd44470c 100644--- a/packages/core/src/database/migrations.ts+++ b/packages/core/src/database/migrations.ts@@ -430,7 +430,19 @@ export class NNMigrationProvider implements MigrationProvider {async up(db) {await db.schema.alterTable("monographs")- .addColumn("publishUrl", "text", COLLATE_NOCASE)+ .addColumn("publishUrl", "text", COLLATE_NOCASE);+ }+ },+ "a-2026-04-06": {+ async up(db) {+ await db.schema+ .alterTable("notes")+ .addColumn("spellcheck", "boolean")+ .execute();+ await db+ .updateTable("notes")+ .set({ spellcheck: true })+ .where("spellcheck", "is", null).execute();}}diff --git a/packages/core/src/types.ts b/packages/core/src/types.tsindex 203e44c8b..cb314589f 100644--- a/packages/core/src/types.ts+++ b/packages/core/src/types.ts@@ -214,6 +214,7 @@ export interface Note extends BaseItem<"note"> {dateModified: number;value: number | null;};+ spellcheck?: boolean;}export interface Notebook extends BaseItem<"notebook"> {