Skip to content

Commit 9306f56

Browse files
committed
refactor: replace scrollview with SimpleBar in v2Editor
- Replace native scroll with SimpleBar component - Restructure editor layout to accommodate SimpleBar - Maintain scroll behavior and PDF view compatibility
1 parent 3c8d203 commit 9306f56

File tree

1 file changed

+51
-47
lines changed

1 file changed

+51
-47
lines changed

apps/web/src/components/v2Editor/index.tsx

+51-47
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ import {
113113
} from '@heroicons/react/24/outline'
114114
import { useOnClickOutside } from '@/hooks/useOnClickOutside'
115115
import RunAllV2 from '../RunAllV2'
116+
import SimpleBar from 'simplebar-react'
116117

117118
// The react-dnd package does not export this...
118119
type Identifier = string | symbol
@@ -1700,62 +1701,65 @@ const Editor = (props: Props) => {
17001701
/>
17011702
)}
17021703

1703-
<div
1704+
<SimpleBar
17041705
id="editor-scrollview"
1705-
ref={props.scrollViewRef}
1706-
className={clsx(
1707-
'flex h-full justify-center',
1708-
props.isFullScreen ? 'px-20' : 'sm:px-0 px-4',
1709-
{
1710-
'overflow-y-auto overflow-x-hidden': !props.isPDF,
1711-
}
1712-
)}
1706+
scrollableNodeProps={{ ref: props.scrollViewRef }}
1707+
className={clsx('h-full w-full', {
1708+
'overflow-y-auto overflow-x-hidden': !props.isPDF,
1709+
})}
17131710
>
17141711
<div
1715-
id="editor-wrapper"
1716-
ref={editorWrapperRef}
17171712
className={clsx(
1718-
'flex-grow h-full py-2',
1719-
props.isFullScreen ? 'w-full' : widthClasses
1713+
'flex justify-center w-full',
1714+
props.isFullScreen ? 'px-20' : 'sm:px-0 px-4'
17201715
)}
17211716
>
1722-
<div className={!props.isPDF ? 'pt-12' : ''}>
1723-
<Title
1724-
content={props.yDoc.getXmlFragment('title')}
1725-
isLoading={props.isSyncing}
1726-
isEditable={
1727-
props.isEditable && !props.isApp && props.role !== 'viewer'
1728-
}
1729-
isPDF={props.isPDF}
1730-
/>
1731-
</div>
1732-
1733-
<ContentSkeleton visible={props.isSyncing} />
1734-
1735-
<HotkeysProvider initiallyActiveScopes={['editor']}>
1736-
{!props.isSyncing && (
1737-
<>
1738-
{domBlocks}
1739-
1740-
{domBlocks.length === 0 && (
1741-
<div className="w-full">
1742-
<PlusButton
1743-
workspaceId={props.document.workspaceId}
1744-
isLast
1745-
alwaysOpen
1746-
onAddBlock={addBlockToBottom}
1747-
isEditable={props.isEditable}
1748-
writebackEnabled={hasWriteback}
1749-
/>
1750-
</div>
1751-
)}
1752-
</>
1717+
<div
1718+
id="editor-wrapper"
1719+
ref={editorWrapperRef}
1720+
className={clsx(
1721+
'flex-grow h-full py-2',
1722+
props.isFullScreen ? 'w-full' : widthClasses
17531723
)}
1754-
</HotkeysProvider>
1724+
>
1725+
<div className={!props.isPDF ? 'pt-12' : ''}>
1726+
<Title
1727+
content={props.yDoc.getXmlFragment('title')}
1728+
isLoading={props.isSyncing}
1729+
isEditable={
1730+
props.isEditable && !props.isApp && props.role !== 'viewer'
1731+
}
1732+
isPDF={props.isPDF}
1733+
/>
1734+
</div>
17551735

1756-
{!props.isPDF && <div className="pb-72" />}
1736+
<ContentSkeleton visible={props.isSyncing} />
1737+
1738+
<HotkeysProvider initiallyActiveScopes={['editor']}>
1739+
{!props.isSyncing && (
1740+
<>
1741+
{domBlocks}
1742+
1743+
{domBlocks.length === 0 && (
1744+
<div className="w-full">
1745+
<PlusButton
1746+
workspaceId={props.document.workspaceId}
1747+
isLast
1748+
alwaysOpen
1749+
onAddBlock={addBlockToBottom}
1750+
isEditable={props.isEditable}
1751+
writebackEnabled={hasWriteback}
1752+
/>
1753+
</div>
1754+
)}
1755+
</>
1756+
)}
1757+
</HotkeysProvider>
1758+
1759+
{!props.isPDF && <div className="pb-72" />}
1760+
</div>
17571761
</div>
1758-
</div>
1762+
</SimpleBar>
17591763
{!props.isPublicViewer && !props.isPDF && (
17601764
<EnvBar
17611765
onOpenFiles={props.onOpenFiles}

0 commit comments

Comments
 (0)