Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: use custom solution for autoresizing textarea

thecodrrcbdef98ae627
diff --git a/apps/web/package.json b/apps/web/package.json
index 80b3e7d79..3bf89d9fe 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -26,7 +26,6 @@
"react-modal": "^3.11.2",
"react-qrcode-logo": "^2.2.1",
"react-scripts": "3.4.1",
- "react-textarea-autosize": "^8.3.0",
"react-virtualized-auto-sizer": "^1.0.2",
"react-window": "^1.8.5",
"rebass": "^4.0.7",
diff --git a/apps/web/src/common/selectionoptions.js b/apps/web/src/common/selectionoptions.js
index b93c983f6..6bd8ad07c 100644
--- a/apps/web/src/common/selectionoptions.js
+++ b/apps/web/src/common/selectionoptions.js
@@ -84,6 +84,18 @@ const AddToNotebookOption = createOption(
}
);
+const ExportOption = createOption("exportOption", Icon.Export, async function (
+ state
+) {
+ alert("TODO.");
+ //const items = state.selectedItems.map((item) => item.id);
+
+ // if (await showMoveNoteDialog(items)) {
+ // //TODO show proper snack
+ // console.log("Notes moved successfully!");
+ // }
+});
+
const RestoreOption = createOption(
"restoreOption",
Icon.Restore,
@@ -94,7 +106,7 @@ const RestoreOption = createOption(
}
);
-const NotesOptions = createOptions([AddToNotebookOption]);
+const NotesOptions = createOptions([AddToNotebookOption, ExportOption]);
const NotebooksOptions = createOptions();
const TopicOptions = createOptions();
const TrashOptions = createOptions([RestoreOption]);
diff --git a/apps/web/src/components/editor/editor.css b/apps/web/src/components/editor/editor.css
index 684a7d8bf..dc4d3a885 100644
--- a/apps/web/src/components/editor/editor.css
+++ b/apps/web/src/components/editor/editor.css
@@ -1,8 +1,3 @@
-.editorTitle:focus {
- border: none;
- outline: none;
-}
-
.ql-editor {
height: auto !important;
overflow: hidden !important;
diff --git a/apps/web/src/components/editor/index.js b/apps/web/src/components/editor/index.js
index 4d59c42dd..729b91005 100644
--- a/apps/web/src/components/editor/index.js
+++ b/apps/web/src/components/editor/index.js
@@ -116,7 +116,7 @@ function Editor() {
<Animated.Flex
variant="columnFill"
className="editor"
- sx={{ mx: [0, 0, "20%"] }}
+ sx={{ mx: [0, 0, "15%"] }}
animate={
isFocusMode && {
marginRight: "25%",
diff --git a/apps/web/src/components/editor/titlebox.js b/apps/web/src/components/editor/titlebox.js
index 018bcbd6a..b6c5c8942 100644
--- a/apps/web/src/components/editor/titlebox.js
+++ b/apps/web/src/components/editor/titlebox.js
@@ -1,52 +1,103 @@
-import React, { useEffect, useRef } from "react";
+import React, { useCallback, useEffect, useRef, useState } from "react";
import "./editor.css";
-import TextArea from "react-textarea-autosize";
-import { useTheme } from "emotion-theming";
+import { Text, Flex } from "rebass";
+import { Input } from "@rebass/forms";
var changeTimeout;
function TitleBox(props) {
- const theme = useTheme();
const { title, setTitle, changeInterval, shouldFocus } = props;
+
+ const [height, setHeight] = useState("auto");
const inputRef = useRef();
+ const resize = useCallback(() => {
+ const textarea = document.querySelector(".editorTitle");
+ const dummy = document.querySelector(".dummyEditorTitle");
+ dummy.innerHTML = textarea.value;
+ setHeight(dummy.scrollHeight);
+ }, []);
+
+ useEffect(() => {
+ if (!window.ResizeObserver) return;
+ const myObserver = new ResizeObserver((entries) => {
+ const newHeight = entries[0].contentRect.height;
+ setHeight(newHeight);
+ });
+ myObserver.observe(document.querySelector(".dummyEditorTitle"));
+ }, []);
+
useEffect(() => {
if (!inputRef.current) return;
clearTimeout(changeTimeout);
inputRef.current.value = title;
- }, [title]);
+ resize();
+ }, [title, resize]);
useEffect(() => {
if (shouldFocus) inputRef.current.focus();
}, [shouldFocus]);
return (
- <TextArea
- ref={inputRef}
- autoFocus={shouldFocus}
- className="editorTitle"
- data-test-id="editor-title"
- placeholder="Untitled"
- maxLength={240}
- style={{
- backgroundColor: "transparent",
- fontFamily: theme.fonts["heading"],
- fontSize: "2.625em",
- fontWeight: theme.fontWeights["heading"],
- resize: "none",
- paddingRight: theme.space[2],
- paddingLeft: theme.space[2],
- border: "none",
- color: theme.colors["text"],
- width: "100%",
- }}
- onChange={(e) => {
- clearTimeout(changeTimeout);
- changeTimeout = setTimeout(
- setTitle.bind(this, e.target.value),
- changeInterval
- );
- }}
- />
+ <Flex width="100%" sx={{ position: "relative" }} py={2}>
+ <Text
+ as="pre"
+ className="dummyEditorTitle"
+ variant="heading"
+ fontSize="2.625em"
+ sx={{ whiteSpace: "pre-wrap", position: "absolute", zIndex: -1 }}
+ ></Text>
+ <Input
+ ref={inputRef}
+ className="editorTitle"
+ autoFocus={shouldFocus}
+ placeholder="Untitled"
+ as="textarea"
+ width="100%"
+ p={0}
+ sx={{
+ height,
+ overflowY: "hidden",
+ fontFamily: "heading",
+ fontSize: "2.625em",
+ fontWeight: "heading",
+ border: "none",
+ resize: "none",
+ ":focus": { outline: "none" },
+ }}
+ onKeyDown={(e) => {
+ if (e.key === "Enter") e.preventDefault();
+ }}
+ onChange={(e) => {
+ resize();
+ clearTimeout(changeTimeout);
+ changeTimeout = setTimeout(
+ setTitle.bind(this, e.target.value),
+ changeInterval
+ );
+ }}
+ />
+ </Flex>
+ // <TextArea
+ // ref={inputRef}
+ // autoFocus={shouldFocus}
+ // className="editorTitle"
+ // data-test-id="editor-title"
+ // placeholder="Untitled"
+ // maxLength={240}
+ // style={{
+ // backgroundColor: "transparent",
+ // fontFamily: theme.fonts["heading"],
+ // fontSize: "2.625em",
+ // fontWeight: theme.fontWeights["heading"],
+ // resize: "none",
+ // paddingRight: theme.space[2],
+ // paddingLeft: theme.space[2],
+ // border: "none",
+ // color: theme.colors["text"],
+ // width: "100%",
+ // }}
+
+ // />
);
}
diff --git a/apps/web/src/components/editor/toolbar.js b/apps/web/src/components/editor/toolbar.js
index 6036f7555..475abc1e2 100644
--- a/apps/web/src/components/editor/toolbar.js
+++ b/apps/web/src/components/editor/toolbar.js
@@ -24,7 +24,7 @@ function Toolbar(props) {
const editorScroll = document.querySelector(".editorScroll");
function onScroll(e) {
const headerOffset = document.querySelector(".editorTitle").scrollHeight;
- const hideOffset = headerOffset + 100;
+ const hideOffset = headerOffset + 60;
if (e.target.scrollTop > hideOffset && !isTitleVisible)
setIsTitleVisible(true);
else if (e.target.scrollTop <= hideOffset && isTitleVisible)