Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/apollo-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
"react-syntax-highlighter": "^16.1.0",
"react-window": "^2.2.1",
"rehype-katex": "^7.0.1",
"remark-breaks": "^4.0.0",
"remark-gfm": "^4.0.1",
"remark-math": "^6.0.0",
"reselect": "^5.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { NodeResizeControl, useReactFlow } from '@uipath/apollo-react/canvas/xyf
import { AnimatePresence } from 'motion/react';
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import ReactMarkdown from 'react-markdown';
import remarkBreaks from 'remark-breaks';
import remarkGfm from 'remark-gfm';
import { GRID_SPACING } from '../../constants';
import type { ToolbarAction } from '../Toolbar';
Expand Down Expand Up @@ -33,6 +34,7 @@ import type { StickyNoteColor, StickyNoteData, TextSelection } from './StickyNot
import { STICKY_NOTE_COLORS, withAlpha } from './StickyNoteNode.types';
import { preserveNewlines } from './StickyNoteNode.utils';
import { useMarkdownShortcuts } from './useMarkdownShortcuts';
import { useScrollCapture } from './useScrollCapture';

export interface StickyNoteNodeProps extends NodeProps {
data: StickyNoteData;
Expand All @@ -57,6 +59,7 @@ const StickyNoteNodeComponent = ({
const [isColorPickerOpen, setIsColorPickerOpen] = useState(false);
const [localContent, setLocalContent] = useState(data.content || '');
const textAreaRef = useRef<HTMLTextAreaElement>(null);
const { ref: markdownRef, scrollCaptureProps } = useScrollCapture();
const colorButtonRef = useRef<HTMLDivElement>(null);
const [activeFormats, setActiveFormats] = useState<ActiveFormats>({
bold: false,
Expand Down Expand Up @@ -353,16 +356,16 @@ const StickyNoteNodeComponent = ({
/>
</>
) : (
<StickyNoteMarkdown>
<StickyNoteMarkdown ref={markdownRef} {...scrollCaptureProps}>
{localContent ? (
<ReactMarkdown remarkPlugins={[remarkGfm]} components={markdownComponents}>
<ReactMarkdown remarkPlugins={[remarkGfm, remarkBreaks]} components={markdownComponents}>
{preserveNewlines(localContent)}
</ReactMarkdown>
) : (
// Render placeholder if renderPlaceholderOnSelect is enabled, node is selected, and the content is empty
renderPlaceholderOnSelect &&
selected && (
<ReactMarkdown remarkPlugins={[remarkGfm]} components={markdownComponents}>
<ReactMarkdown remarkPlugins={[remarkGfm, remarkBreaks]} components={markdownComponents}>
{placeholder}
</ReactMarkdown>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { useCallback, useEffect, useRef, useState } from 'react';

const EVENT_START_POLL_INTERVAL = 150;

/**
* Captures scroll (wheel) events on an overflowing element without hijacking
* an in-progress canvas zoom gesture.
*
* Returns a ref to attach to the scrollable element and props to spread onto it.
* Adds the `nowheel` class only when the pointer entered while no wheel gesture
* was active and the element has overflow.
*/
export function useScrollCapture<T extends HTMLElement = HTMLDivElement>() {
const ref = useRef<T>(null);
const [captureScroll, setCaptureScroll] = useState(false);
const wheelActiveRef = useRef(false);
const wheelTimeoutRef = useRef<ReturnType<typeof setTimeout>>(null);

// Track global wheel activity so we can distinguish "pointer entered while idle"
// from "pointer drifted over during a canvas zoom gesture".
useEffect(() => {
const onWheel = () => {
wheelActiveRef.current = true;
if (wheelTimeoutRef.current) clearTimeout(wheelTimeoutRef.current);
wheelTimeoutRef.current = setTimeout(() => {
wheelActiveRef.current = false;
}, EVENT_START_POLL_INTERVAL);
};
window.addEventListener('wheel', onWheel, { passive: true });
return () => window.removeEventListener('wheel', onWheel);
}, []);

const onMouseEnter = useCallback(() => {
if (wheelActiveRef.current) return;
const el = ref.current;
if (el && el.scrollHeight > el.clientHeight) {
setCaptureScroll(true);
}
}, []);

const onMouseLeave = useCallback(() => {
setCaptureScroll(false);
}, []);

return {
ref,
scrollCaptureProps: {
className: captureScroll ? 'nowheel' : undefined,
onMouseEnter,
onMouseLeave,
},
};
}
20 changes: 20 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading