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: readonly mode
Ammar Ahmed4113d1f4b3b5
diff --git a/packages/editor-mobile/src/components/editor.tsx b/packages/editor-mobile/src/components/editor.tsxindex d20cafb8a..46849cdfa 100644--- a/packages/editor-mobile/src/components/editor.tsx+++ b/packages/editor-mobile/src/components/editor.tsx@@ -1,9 +1,10 @@import { useTheme } from "@notesnook/theme";import { PortalProvider, Toolbar, useTiptap } from "notesnook-editor";-import { useLayoutEffect, useRef, useState } from "react";+import { useEffect, useLayoutEffect, useRef, useState } from "react";import { useEditorController } from "../hooks/useEditorController";import { useSettings } from "../hooks/useSettings";import { useEditorThemeStore } from "../state/theme";+import { Settings } from "../utils";import Header from "./header";import StatusBar from "./statusbar";import Tags from "./tags";@@ -12,6 +13,15 @@ import Title from "./title";const Tiptap = () => {const settings = useSettings();const theme = useEditorThemeStore((state) => state.colors);+ const [initialProps, setInitialProps] = useState<Partial<Settings>>({+ readonly: global.readonly || global.readonly || settings.readonly,+ noHeader: global.noHeader || settings.noHeader,+ noToolbar:+ global.noToolbar ||+ settings.noToolbar ||+ global.readonly ||+ settings.readonly,+ });const contentRef = useRef<HTMLDivElement>(null);const containerRef = useRef<HTMLDivElement>(null);const [layout, setLayout] = useState(false);@@ -81,14 +91,22 @@ const Tiptap = () => {},theme: editorTheme,element: !layout ? undefined : contentRef.current || undefined,+ editable: !initialProps.readonly,+ editorProps: {+ editable: () => !initialProps.readonly,+ },},- [layout]+ [layout, initialProps.readonly]);const controller = useEditorController(editor);const controllerRef = useRef(controller);globalThis.editorController = controller;globalThis.editor = editor;+ useEffect(() => {+ setInitialProps({ ...settings });+ }, [settings]);+useLayoutEffect(() => {setLayout(true);}, []);@@ -104,7 +122,7 @@ const Tiptap = () => {marginBottom: "5px",}}>- <Header />+ <Header noHeader={initialProps.noHeader || false} /><divonScroll={controller.scroll}ref={containerRef}@@ -117,9 +135,13 @@ const Tiptap = () => {display: "flex",}}>- <Tags />- <Title controller={controllerRef} title={controller.title} />- <StatusBar container={containerRef} editor={editor} />+ {initialProps.noHeader ? null : (+ <>+ <Tags />+ <Title controller={controllerRef} title={controller.title} />+ <StatusBar container={containerRef} editor={editor} />+ </>+ )}<divref={contentRef}style={{@@ -131,20 +153,22 @@ const Tiptap = () => {/></div>- <div- style={{- paddingLeft: 10,- paddingTop: 5,- }}- >- <Toolbar- isMobile={true}- theme={toolbarTheme}- editor={editor}- location="bottom"- tools={settings.tools}- />- </div>+ {initialProps.noToolbar ? null : (+ <div+ style={{+ paddingLeft: 10,+ paddingTop: 5,+ }}+ >+ <Toolbar+ isMobile={true}+ theme={toolbarTheme}+ editor={editor}+ location="bottom"+ tools={settings.tools}+ />+ </div>+ )}</div></>);diff --git a/packages/editor-mobile/src/components/header.tsx b/packages/editor-mobile/src/components/header.tsxindex 1f4eac4e4..a33c7e328 100644--- a/packages/editor-mobile/src/components/header.tsx+++ b/packages/editor-mobile/src/components/header.tsx@@ -41,134 +41,139 @@ const Button = ({);};-export default React.memo(function Header() {- const insets = useSafeArea();- const settings = useSettings();- return (- <div- style={{- display: "flex",- alignItems: "center",- height: `${50 + insets.top}px`,- backgroundColor: "var(--nn_bg)",- position: "sticky",- width: "100vw",- }}- >+export default React.memo(+ function Header({ noHeader }: { noHeader: boolean }) {+ const insets = useSafeArea();+ const settings = useSettings();+ return (<divstyle={{display: "flex",- width: "100%",- justifyContent: "space-between",- flexDirection: "row",- paddingTop: insets.top,+ alignItems: "center",+ height: noHeader ? `${insets.top}px` : `${50 + insets.top}px`,+ backgroundColor: "var(--nn_bg)",+ position: "sticky",+ width: "100vw",}}>- <Button- onPress={() => {- post(EventTypes.back);- }}- style={{- borderWidth: 0,- borderRadius: 100,- color: "var(--nn_icon)",- marginLeft: 6,- width: 40,- height: 40,- display: "flex",- justifyContent: "center",- alignItems: "start",- flexDirection: "column",- }}- >- <ArrowBackIcon size={28} color="var(--nn_pri)" />- </Button>-- <div- style={{- display: "flex",- alignItems: "center",- flexDirection: "row",- }}- >- {!settings.premium && (+ {noHeader ? null : (+ <div+ style={{+ display: "flex",+ width: "100%",+ justifyContent: "space-between",+ flexDirection: "row",+ paddingTop: insets.top,+ }}+ ><ButtononPress={() => {- post(EventTypes.pro);+ post(EventTypes.back);}}style={{borderWidth: 0,borderRadius: 100,color: "var(--nn_icon)",- marginRight: 10,- width: 39,- height: 39,+ marginLeft: 6,+ width: 40,+ height: 40,display: "flex",justifyContent: "center",- alignItems: "center",+ alignItems: "start",+ flexDirection: "column",}}>- <CrownIcon size={28} color="orange" />+ <ArrowBackIcon size={28} color="var(--nn_pri)" /></Button>- )}- <Button- onPress={() => {- //- }}- style={{- borderWidth: 0,- borderRadius: 100,- color: "var(--nn_icon)",- marginRight: 10,- width: 39,- height: 39,- display: "flex",- justifyContent: "center",- alignItems: "center",- }}- >- <MagnifyIcon size={28} color="var(--nn_pri)" />- </Button>- <Button- onPress={() => {- post(EventTypes.monograph);- }}- style={{- borderWidth: 0,- borderRadius: 100,- color: "var(--nn_icon)",- marginRight: 10,- width: 39,- height: 39,- display: "flex",- justifyContent: "center",- alignItems: "center",- }}- >- <CloudUploadOutlineIcon size={28} color="var(--nn_pri)" />- </Button>+ <div+ style={{+ display: "flex",+ alignItems: "center",+ flexDirection: "row",+ }}+ >+ {!settings.premium && (+ <Button+ onPress={() => {+ post(EventTypes.pro);+ }}+ style={{+ borderWidth: 0,+ borderRadius: 100,+ color: "var(--nn_icon)",+ marginRight: 10,+ width: 39,+ height: 39,+ display: "flex",+ justifyContent: "center",+ alignItems: "center",+ }}+ >+ <CrownIcon size={28} color="orange" />+ </Button>+ )}+ <Button+ onPress={() => {+ //+ }}+ style={{+ borderWidth: 0,+ borderRadius: 100,+ color: "var(--nn_icon)",+ marginRight: 10,- <Button- onPress={() => {- post(EventTypes.properties);- }}- style={{- borderWidth: 0,- borderRadius: 100,- color: "var(--nn_icon)",- marginRight: 12,- width: 39,- height: 39,- display: "flex",- justifyContent: "center",- alignItems: "center",- }}- >- <DotsHorizontalIcon size={28} color="var(--nn_pri)" />- </Button>- </div>+ width: 39,+ height: 39,+ display: "flex",+ justifyContent: "center",+ alignItems: "center",+ }}+ >+ <MagnifyIcon size={28} color="var(--nn_pri)" />+ </Button>+ <Button+ onPress={() => {+ post(EventTypes.monograph);+ }}+ style={{+ borderWidth: 0,+ borderRadius: 100,+ color: "var(--nn_icon)",+ marginRight: 10,+ width: 39,+ height: 39,+ display: "flex",+ justifyContent: "center",+ alignItems: "center",+ }}+ >+ <CloudUploadOutlineIcon size={28} color="var(--nn_pri)" />+ </Button>++ <Button+ onPress={() => {+ post(EventTypes.properties);+ }}+ style={{+ borderWidth: 0,+ borderRadius: 100,+ color: "var(--nn_icon)",+ marginRight: 12,+ width: 39,+ height: 39,+ display: "flex",+ justifyContent: "center",+ alignItems: "center",+ }}+ >+ <DotsHorizontalIcon size={28} color="var(--nn_pri)" />+ </Button>+ </div>+ </div>+ )}</div>- </div>- );-});+ );+ },+ (prev, next) => prev.noHeader !== next.noHeader+);diff --git a/packages/editor-mobile/src/components/title.tsx b/packages/editor-mobile/src/components/title.tsxindex 48b06f271..dba355e02 100644--- a/packages/editor-mobile/src/components/title.tsx+++ b/packages/editor-mobile/src/components/title.tsx@@ -25,6 +25,8 @@ function Title({<inputref={titleRef}className={styles.titleBar}+ contentEditable={!global.readonly}+ disabled={global.readonly}style={{height: 50,fontSize: 27,diff --git a/packages/editor-mobile/src/utils/index.ts b/packages/editor-mobile/src/utils/index.tsindex 55ffb2adf..75b1797cc 100644--- a/packages/editor-mobile/src/utils/index.ts+++ b/packages/editor-mobile/src/utils/index.ts@@ -16,9 +16,14 @@ export type Settings = {deviceMode: "mobile" | "smallTablet" | "tablet";premium: boolean;tools: ToolbarGroupDefinition[];+ noToolbar?: boolean;+ noHeader?: boolean;};declare global {+ var readonly: boolean;+ var noToolbar: boolean;+ var noHeader: boolean;/*** Id of current session*/