Skip to content

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

editor: fix action sheet not closing via drag

Abdullah Attaf26f638ad41f
diff --git a/packages/editor/src/components/action-sheet/index.tsx b/packages/editor/src/components/action-sheet/index.tsx
index d76405530..8a4e19709 100644
--- a/packages/editor/src/components/action-sheet/index.tsx
+++ b/packages/editor/src/components/action-sheet/index.tsx
@@ -29,16 +29,16 @@ import { Box, Button, Flex, Text, FlexProps } from "@theme-ui/components";
import { Icons } from "../../toolbar/icons";
import Modal from "react-modal";
import {
- m,
+ motion,
PanInfo,
useMotionValue,
useTransform,
useAnimation
} from "framer-motion";
import { useTheme } from "@emotion/react";
-import { Theme } from "@notesnook/theme";
+import { EmotionThemeProvider, Theme } from "@notesnook/theme";
-const AnimatedFlex = m(
+const AnimatedFlex = motion(
Flex as React.FunctionComponent<Omit<FlexProps, "onDrag" | "onDragEnd">>
);
@@ -162,8 +162,9 @@ export function ActionSheetPresenter(
}}
overlayElement={(overlayElementProps, contentEl) => {
return (
- <Box
+ <EmotionThemeProvider
{...overlayElementProps}
+ scope="sheet"
style={{
...overlayElementProps.style,
position: blocking ? "fixed" : "sticky",
@@ -173,7 +174,7 @@ export function ActionSheetPresenter(
tabIndex={-1}
>
{blocking && (
- <m.div
+ <motion.div
id="action-sheet-overlay"
style={{
height: "100%",
@@ -186,7 +187,7 @@ export function ActionSheetPresenter(
/>
)}
{contentEl}
- </Box>
+ </EmotionThemeProvider>
);
}}
contentElement={(props, children) => (
@@ -239,7 +240,9 @@ export function ActionSheetPresenter(
onClose?.();
return;
}
- const sheetEl = contentRef.current as HTMLDivElement;
+ const sheetEl = contentRef.current;
+ if (!sheetEl) return;
+
const contentHeight = sheetEl.offsetHeight;
const threshold = 30;
const closingHeight = (contentHeight * threshold) / 100;
@@ -263,7 +266,7 @@ export function ActionSheetPresenter(
<Box
id="pill"
sx={{
- backgroundColor: "hover",
+ bg: "background-secondary",
width: 60,
height: 8,
borderRadius: 100
diff --git a/packages/editor/src/extensions/image/component.tsx b/packages/editor/src/extensions/image/component.tsx
index 6cb42f704..b6d133f2a 100644
--- a/packages/editor/src/extensions/image/component.tsx
+++ b/packages/editor/src/extensions/image/component.tsx
@@ -36,10 +36,10 @@ import {
toBlobURL,
toDataURL
} from "../../utils/downloader";
-import { m, LazyMotion, domAnimation } from "framer-motion";
+import { motion } from "framer-motion";
const IMAGE_SOURCE_CACHE: Record<string, string | undefined> = {};
-export const AnimatedImage = m(Image);
+export const AnimatedImage = motion(Image);
export function ImageComponent(
props: SelectionBasedReactNodeViewProps<
@@ -124,164 +124,162 @@ export function ImageComponent(
}
}}
>
- <LazyMotion features={domAnimation}>
- {!source || error ? (
- <Flex
+ {!source || error ? (
+ <Flex
+ sx={{
+ width: width || "100%",
+ height: height || relativeHeight || "100%",
+ maxWidth: "100%",
+ minWidth: 135,
+ bg: "background",
+ border: selected
+ ? "2px solid var(--accent)"
+ : "2px solid transparent",
+ borderRadius: "default",
+ flexDirection: "column",
+ alignItems: "center",
+ justifyContent: "center",
+ mt: 1,
+ py: 50
+ }}
+ >
+ <Icon
+ path={
+ error
+ ? Icons.imageFailed
+ : isDownloadable(source, src)
+ ? Icons.imageDownload
+ : Icons.image
+ }
+ size={width ? width * 0.2 : 72}
+ color="gray"
+ />
+
+ <Text
+ as="span"
+ variant={"subBody"}
sx={{
- width: width || "100%",
- height: height || relativeHeight || "100%",
- maxWidth: "100%",
- minWidth: 135,
- bg: "background",
- border: selected
- ? "2px solid var(--accent)"
- : "2px solid transparent",
- borderRadius: "default",
- flexDirection: "column",
- alignItems: "center",
- justifyContent: "center",
- mt: 1,
- py: 50
+ display: "inline-block",
+ textDecoration: "none",
+ textAlign: "center",
+ mx: 2,
+ mt: 2
}}
>
- <Icon
- path={
- error
- ? Icons.imageFailed
- : isDownloadable(source, src)
- ? Icons.imageDownload
- : Icons.image
- }
- size={width ? width * 0.2 : 72}
- color="gray"
- />
-
- <Text
- as="span"
- variant={"subBody"}
- sx={{
- display: "inline-block",
- textDecoration: "none",
- textAlign: "center",
- mx: 2,
- mt: 2
+ {error
+ ? `There was an error loading the image: ${error}`
+ : isDownloadable(source, src)
+ ? `Downloading image from ${getHostname(src)}`
+ : ""}
+ </Text>
+ {error ? (
+ <Button
+ variant="secondary"
+ sx={{ mt: 1 }}
+ onClick={() => {
+ setSource(src);
+ setError(undefined);
}}
>
- {error
- ? `There was an error loading the image: ${error}`
- : isDownloadable(source, src)
- ? `Downloading image from ${getHostname(src)}`
- : ""}
- </Text>
- {error ? (
- <Button
- variant="secondary"
- sx={{ mt: 1 }}
- onClick={() => {
- setSource(src);
- setError(undefined);
+ Skip downloading (unsafe)
+ </Button>
+ ) : null}
+ </Flex>
+ ) : (
+ <Resizer
+ style={{ marginTop: 5 }}
+ editor={editor}
+ selected={selected}
+ width={width}
+ onResize={(width, height) => {
+ editor.commands.setImageSize({ width, height });
+ }}
+ >
+ <DesktopOnly>
+ {selected && (
+ <Flex
+ sx={{
+ position: "absolute",
+ top: -40,
+ right: 0,
+ mb: 2,
+ alignItems: "end"
}}
>
- Skip downloading (unsafe)
- </Button>
- ) : null}
- </Flex>
- ) : (
- <Resizer
- style={{ marginTop: 5 }}
- editor={editor}
- selected={selected}
- width={width}
- onResize={(width, height) => {
- editor.commands.setImageSize({ width, height });
- }}
- >
- <DesktopOnly>
- {selected && (
- <Flex
+ <ToolbarGroup
+ editor={editor}
+ tools={
+ isReadonly
+ ? [
+ hash ? "previewAttachment" : "none",
+ hash ? "downloadAttachment" : "none"
+ ]
+ : [
+ hash ? "previewAttachment" : "none",
+ hash ? "downloadAttachment" : "none",
+ "imageAlignLeft",
+ float ? "none" : "imageAlignCenter",
+ "imageAlignRight",
+ "imageProperties"
+ ]
+ }
sx={{
- position: "absolute",
- top: -40,
- right: 0,
- mb: 2,
- alignItems: "end"
+ boxShadow: "menu",
+ borderRadius: "default",
+ bg: "background"
}}
- >
- <ToolbarGroup
- editor={editor}
- tools={
- isReadonly
- ? [
- hash ? "previewAttachment" : "none",
- hash ? "downloadAttachment" : "none"
- ]
- : [
- hash ? "previewAttachment" : "none",
- hash ? "downloadAttachment" : "none",
- "imageAlignLeft",
- float ? "none" : "imageAlignCenter",
- "imageAlignRight",
- "imageProperties"
- ]
- }
- sx={{
- boxShadow: "menu",
- borderRadius: "default",
- bg: "background"
- }}
- />
- </Flex>
- )}
- </DesktopOnly>
- {!isReadonly && selected && (
- <Icon
- className="drag-handle"
- data-drag-handle
- draggable
- path={Icons.dragHandle}
- color="black"
- sx={{
- cursor: "grab",
- position: "absolute",
- top: 1,
- left: 1,
- zIndex: 999
- }}
- />
+ />
+ </Flex>
)}
- <AnimatedImage
- initial={{ opacity: 0 }}
- animate={{ opacity: 1 }}
- transition={{ duration: 0.5, ease: "easeIn" }}
- data-drag-image
- ref={imageRef}
- alt={alt}
- src={source}
- title={title}
+ </DesktopOnly>
+ {!isReadonly && selected && (
+ <Icon
+ className="drag-handle"
+ data-drag-handle
+ draggable
+ path={Icons.dragHandle}
+ color="black"
sx={{
- width: editor.isEditable ? "100%" : width,
- height: editor.isEditable ? "100%" : height,
- border: selected
- ? "2px solid var(--accent)"
- : "2px solid transparent",
- borderRadius: "default"
- }}
- onDoubleClick={() =>
- editor.current?.commands.previewAttachment(node.attrs)
- }
- onLoad={(e) => {
- const { clientHeight, clientWidth } = e.currentTarget;
- if (!height && !width && !aspectRatio) {
- editor.current?.commands.updateImage(
- { src, hash },
- { aspectRatio: clientWidth / clientHeight }
- );
- }
+ cursor: "grab",
+ position: "absolute",
+ top: 1,
+ left: 1,
+ zIndex: 999
}}
/>
- </Resizer>
- )}
- </LazyMotion>
+ )}
+ <AnimatedImage
+ initial={{ opacity: 0 }}
+ animate={{ opacity: 1 }}
+ transition={{ duration: 0.5, ease: "easeIn" }}
+ data-drag-image
+ ref={imageRef}
+ alt={alt}
+ src={source}
+ title={title}
+ sx={{
+ width: editor.isEditable ? "100%" : width,
+ height: editor.isEditable ? "100%" : height,
+ border: selected
+ ? "2px solid var(--accent)"
+ : "2px solid transparent",
+ borderRadius: "default"
+ }}
+ onDoubleClick={() =>
+ editor.current?.commands.previewAttachment(node.attrs)
+ }
+ onLoad={(e) => {
+ const { clientHeight, clientWidth } = e.currentTarget;
+ if (!height && !width && !aspectRatio) {
+ editor.current?.commands.updateImage(
+ { src, hash },
+ { aspectRatio: clientWidth / clientHeight }
+ );
+ }
+ }}
+ />
+ </Resizer>
+ )}
</Box>
</>
);