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
monograph: load i18n for editor
Abdullah Attaa74637e9c08e
diff --git a/apps/monograph/app/components/monographpost/editor.client.tsx b/apps/monograph/app/components/monographpost/editor.client.tsxindex e94fbc4fb..625582af4 100644--- a/apps/monograph/app/components/monographpost/editor.client.tsx+++ b/apps/monograph/app/components/monographpost/editor.client.tsx@@ -25,10 +25,23 @@ import {useThemeColors,useThemeEngineStore} from "@notesnook/theme";-import { useLayoutEffect, useMemo, useRef, useState } from "react";+import { useLayoutEffect, useMemo, useRef } from "react";import { Flex } from "@theme-ui/components";import TipTap, { type TipTapProps } from "./tiptap";import { ScopedThemeProvider } from "../theme-provider";+import { setI18nGlobal, Messages } from "@notesnook/intl";+import { i18n } from "@lingui/core";++const locale = import.meta.env.DEV+ ? import("@notesnook/intl/locales/$pseudo-LOCALE.json")+ : import("@notesnook/intl/locales/$en.json");+locale.then(({ default: locale }) => {+ i18n.load({+ en: locale.messages as unknown as Messages+ });+ i18n.activate("en");+});+setI18nGlobal(i18n);export type EditorType = typeof Editor;@@ -37,11 +50,9 @@ export function Editor(props: Omit<TipTapProps, "editorContainer" | "theme">) {const containerRef = useRef<HTMLDivElement>(null);const { theme } = useThemeEngineStore();const { colors, isDark } = useThemeColors("editor");- const [isLoaded, setIsLoaded] = useState(false);useLayoutEffect(() => {if (- !("window" in globalThis) ||!containerRef.current ||!editorContainerRef.current ||editorContainerRef.current.parentElement === containerRef.current@@ -50,11 +61,6 @@ export function Editor(props: Omit<TipTapProps, "editorContainer" | "theme">) {containerRef.current.appendChild(editorContainerRef.current);}, []);- useLayoutEffect(() => {- if (!("window" in globalThis)) return;- setIsLoaded(true);- }, []);-const editorTheme = useMemo(() => {const editorTheme = ThemeFactory.construct({colorScheme: isDark ? "dark" : "light",@@ -82,25 +88,23 @@ export function Editor(props: Omit<TipTapProps, "editorContainer" | "theme">) {}}}>- {isLoaded ? (- <TipTap- {...props}- editorContainer={() => {- if (editorContainerRef.current) return editorContainerRef.current;- const editorContainer = document.createElement("div");- editorContainer.classList.add("selectable", "editor-container");- editorContainer.style.flex = "1";- editorContainer.style.cursor = "text";- editorContainer.style.color =- theme.scopes.editor?.primary?.paragraph ||- theme.scopes.base.primary.paragraph;- editorContainerRef.current = editorContainer;- if (containerRef.current)- containerRef.current.appendChild(editorContainerRef.current);- return editorContainer;- }}- />- ) : null}+ <TipTap+ {...props}+ editorContainer={() => {+ if (editorContainerRef.current) return editorContainerRef.current;+ const editorContainer = document.createElement("div");+ editorContainer.classList.add("selectable", "editor-container");+ editorContainer.style.flex = "1";+ editorContainer.style.cursor = "text";+ editorContainer.style.color =+ theme.scopes.editor?.primary?.paragraph ||+ theme.scopes.base.primary.paragraph;+ editorContainerRef.current = editorContainer;+ if (containerRef.current)+ containerRef.current.appendChild(editorContainerRef.current);+ return editorContainer;+ }}+ /></Flex></ScopedThemeProvider>);diff --git a/apps/monograph/package-lock.json b/apps/monograph/package-lock.jsonindex f4f4c5b14..8d31c8866 100644--- a/apps/monograph/package-lock.json+++ b/apps/monograph/package-lock.json@@ -11,10 +11,13 @@"@emotion/cache": "11.11.0","@emotion/react": "11.11.1","@emotion/server": "11.11.0",+ "@lingui/core": "4.11.4",+ "@lingui/react": "4.11.4","@mdi/js": "^7.4.47","@notesnook/core": "file:../../packages/core","@notesnook/crypto": "file:../../packages/crypto","@notesnook/editor": "file:../../packages/editor",+ "@notesnook/intl": "file:../../packages/intl","@notesnook/theme": "file:../../packages/theme","@notesnook/ui": "file:../../packages/ui","@remix-run/node": "^2.12.1",@@ -223,6 +226,29 @@"zustand": ">=4"}},+ "../../packages/intl": {+ "name": "@notesnook/intl",+ "version": "1.0.0",+ "hasInstallScript": true,+ "license": "GPL-3.0-or-later",+ "devDependencies": {+ "@lingui/cli": "^4.11.4",+ "@lingui/macro": "^4.11.4 ",+ "@lingui/swc-plugin": "^4.0.10",+ "@types/react": "^18.2.39",+ "babel-plugin-macros": "^3.1.0",+ "react": "18.2.0",+ "typescript": "5.5.3",+ "vite": "^5.4.8",+ "vite-plugin-dts": "^4.2.3",+ "vite-plugin-static-copy": "^2.0.0",+ "vite-plugin-swc-transform": "^1.0.1"+ },+ "peerDependencies": {+ "@lingui/macro": "*",+ "react": ">=18"+ }+ },"../../packages/theme": {"name": "@notesnook/theme","version": "2.1.3",@@ -1627,6 +1653,49 @@"integrity": "sha512-Lg3PnLp0QXpxwLIAuuJboLeRaIhrgJjeuh797QADg3xz8wGLugQOS5DpsE8A6i6Adgzf+bacllkKZG3J0tGfDw==","dev": true},+ "node_modules/@lingui/core": {+ "version": "4.11.4",+ "resolved": "https://registry.npmjs.org/@lingui/core/-/core-4.11.4.tgz",+ "integrity": "sha512-W0bBIFe44s//Qs+RQ+NMfzK5vAm9oEKyDddlN94Db6rzeUT/IJo7N+T75A6Bya8v/BrtF2G/W4b77eS3sd0utw==",+ "license": "MIT",+ "dependencies": {+ "@babel/runtime": "^7.20.13",+ "@lingui/message-utils": "4.11.4",+ "unraw": "^3.0.0"+ },+ "engines": {+ "node": ">=16.0.0"+ }+ },+ "node_modules/@lingui/message-utils": {+ "version": "4.11.4",+ "resolved": "https://registry.npmjs.org/@lingui/message-utils/-/message-utils-4.11.4.tgz",+ "integrity": "sha512-ZTCDhGbj5EN+P9Ajcj0Gq9uDP3HZTRW6/kT09WkiFgL4NayYLksPvgBk29sIglsS6M+Y6Iw2BrUK403SZjZKgw==",+ "license": "MIT",+ "dependencies": {+ "@messageformat/parser": "^5.0.0",+ "js-sha256": "^0.10.1"+ },+ "engines": {+ "node": ">=16.0.0"+ }+ },+ "node_modules/@lingui/react": {+ "version": "4.11.4",+ "resolved": "https://registry.npmjs.org/@lingui/react/-/react-4.11.4.tgz",+ "integrity": "sha512-f7re4HhjI6CLBV1CY/PcI3VYP5zS4rtfU33speWnfkymsxGIXQv4ol3BqrgPLGhypMl2nKcL5nfL+LewrLIW8g==",+ "license": "MIT",+ "dependencies": {+ "@babel/runtime": "^7.20.13",+ "@lingui/core": "4.11.4"+ },+ "engines": {+ "node": ">=16.0.0"+ },+ "peerDependencies": {+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0"+ }+ },"node_modules/@mdi/js": {"version": "7.4.47","resolved": "https://registry.npmjs.org/@mdi/js/-/js-7.4.47.tgz",@@ -1663,6 +1732,15 @@"url": "https://opencollective.com/unified"}},+ "node_modules/@messageformat/parser": {+ "version": "5.1.0",+ "resolved": "https://registry.npmjs.org/@messageformat/parser/-/parser-5.1.0.tgz",+ "integrity": "sha512-jKlkls3Gewgw6qMjKZ9SFfHUpdzEVdovKFtW1qRhJ3WI4FW5R/NnGDqr8SDGz+krWDO3ki94boMmQvGke1HwUQ==",+ "license": "MIT",+ "dependencies": {+ "moo": "^0.5.1"+ }+ },"node_modules/@notesnook/core": {"resolved": "../../packages/core","link": true@@ -1675,6 +1753,10 @@"resolved": "../../packages/editor","link": true},+ "node_modules/@notesnook/intl": {+ "resolved": "../../packages/intl",+ "link": true+ },"node_modules/@notesnook/theme": {"resolved": "../../packages/theme","link": true@@ -5909,6 +5991,12 @@"dev": true,"license": "MIT"},+ "node_modules/js-sha256": {+ "version": "0.10.1",+ "resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.10.1.tgz",+ "integrity": "sha512-5obBtsz9301ULlsgggLg542s/jqtddfOpV5KJc4hajc9JV8GeY2gZHSVpYBn4nWqAUTJ9v+xwtbJ1mIBgIH5Vw==",+ "license": "MIT"+ },"node_modules/js-tokens": {"version": "4.0.0","resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",@@ -7470,6 +7558,12 @@"dev": true,"license": "MIT"},+ "node_modules/moo": {+ "version": "0.5.2",+ "resolved": "https://registry.npmjs.org/moo/-/moo-0.5.2.tgz",+ "integrity": "sha512-iSAJLHYKnX41mKcJKjqvnAN9sf0LMDTXDEvFv+ffuRR9a1MIuXLjMNL6EsnDHSkKLTWNqQQ5uo61P4EbU4NU+Q==",+ "license": "BSD-3-Clause"+ },"node_modules/morgan": {"version": "1.10.0","resolved": "https://registry.npmjs.org/morgan/-/morgan-1.10.0.tgz",@@ -10336,6 +10430,12 @@"node": ">= 0.8"}},+ "node_modules/unraw": {+ "version": "3.0.0",+ "resolved": "https://registry.npmjs.org/unraw/-/unraw-3.0.0.tgz",+ "integrity": "sha512-08/DA66UF65OlpUDIQtbJyrqTR0jTAlJ+jsnkQ4jxR7+K5g5YG1APZKQSMCE1vqqmD+2pv6+IdEjmopFatacvg==",+ "license": "MIT"+ },"node_modules/update-browserslist-db": {"version": "1.1.1","resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.1.1.tgz",diff --git a/apps/monograph/package.json b/apps/monograph/package.jsonindex 96ffb3dd5..d66dcce8c 100644--- a/apps/monograph/package.json+++ b/apps/monograph/package.json@@ -15,9 +15,12 @@"@emotion/react": "11.11.1","@emotion/server": "11.11.0","@mdi/js": "^7.4.47",+ "@lingui/core": "4.11.4",+ "@lingui/react": "4.11.4","@notesnook/core": "file:../../packages/core","@notesnook/crypto": "file:../../packages/crypto","@notesnook/editor": "file:../../packages/editor",+ "@notesnook/intl": "file:../../packages/intl","@notesnook/theme": "file:../../packages/theme","@notesnook/ui": "file:../../packages/ui","@remix-run/node": "^2.12.1",