There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
chore: improves scrolling performance and loading component for dark theme (#8795)
fundonb5fa8472d908
diff --git a/packages/frontend/core/src/components/attachment-viewer/pdf-viewer.tsx b/packages/frontend/core/src/components/attachment-viewer/pdf-viewer.tsxindex a60926c7f6..4de7630160 100644--- a/packages/frontend/core/src/components/attachment-viewer/pdf-viewer.tsx+++ b/packages/frontend/core/src/components/attachment-viewer/pdf-viewer.tsx@@ -15,13 +15,18 @@ import {type PDFVirtuosoContext,type PDFVirtuosoProps,Scroller,+ ScrollSeekPlaceholder,} from '@affine/core/modules/pdf/views';import type { AttachmentBlockModel } from '@blocksuite/affine/blocks';import { CollapseIcon, ExpandIcon } from '@blocksuite/icons/rc';import { useLiveData, useService } from '@toeverything/infra';import clsx from 'clsx';import { useCallback, useEffect, useMemo, useRef, useState } from 'react';-import { Virtuoso, type VirtuosoHandle } from 'react-virtuoso';+import {+ type ScrollSeekConfiguration,+ Virtuoso,+ type VirtuosoHandle,+} from 'react-virtuoso';import * as styles from './styles.css';import { calculatePageNum } from './utils';@@ -112,6 +117,13 @@ const PDFViewerInner = ({ pdf, state }: PDFViewerInnerProps) => {};}, [state, viewportInfo, onPageSelect]);+ const scrollSeekConfig = useMemo<ScrollSeekConfiguration>(() => {+ return {+ enter: velocity => Math.abs(velocity) > 1024,+ exit: velocity => Math.abs(velocity) < 10,+ };+ }, []);+useEffect(() => {const viewer = viewerRef.current;if (!viewer) return;@@ -142,12 +154,14 @@ const PDFViewerInner = ({ pdf, state }: PDFViewerInnerProps) => {Scroller,Header: ListPadding,Footer: ListPadding,+ ScrollSeekPlaceholder,}}context={{width: state.meta.width,height: state.meta.height,pageClassName: styles.pdfPage,}}+ scrollSeekConfiguration={scrollSeekConfig}/><div className={clsx(['thumbnails', styles.pdfThumbnails])}><div className={clsx([styles.pdfThumbnailsList, { collapsed }])}>@@ -159,9 +173,11 @@ const PDFViewerInner = ({ pdf, state }: PDFViewerInnerProps) => {itemContent={pageContent}components={{Item,- Scroller,List: ListWithSmallGap,+ Scroller,+ ScrollSeekPlaceholder,}}+ scrollSeekConfiguration={scrollSeekConfig}style={thumbnailsConfig.style}context={thumbnailsConfig.context}/>diff --git a/packages/frontend/core/src/components/attachment-viewer/styles.css.ts b/packages/frontend/core/src/components/attachment-viewer/styles.css.tsindex 65525db4af..b1abeaa6c0 100644--- a/packages/frontend/core/src/components/attachment-viewer/styles.css.ts+++ b/packages/frontend/core/src/components/attachment-viewer/styles.css.ts@@ -84,7 +84,7 @@ export const viewer = style({display: 'flex',flex: 1,overflow: 'hidden',- resize: 'both',+ resize: 'none',selectors: {'&:before': {position: 'absolute',diff --git a/packages/frontend/core/src/modules/pdf/views/components.tsx b/packages/frontend/core/src/modules/pdf/views/components.tsxindex abffd86fdc..05c5fa87f6 100644--- a/packages/frontend/core/src/modules/pdf/views/components.tsx+++ b/packages/frontend/core/src/modules/pdf/views/components.tsx@@ -1,7 +1,7 @@import { Scrollable } from '@affine/component';import clsx from 'clsx';import { type CSSProperties, forwardRef, memo } from 'react';-import type { VirtuosoProps } from 'react-virtuoso';+import type { ScrollSeekPlaceholderProps, VirtuosoProps } from 'react-virtuoso';import * as styles from './styles.css';@@ -27,6 +27,26 @@ export const Scroller = forwardRef<HTMLDivElement, PDFVirtuosoProps>(Scroller.displayName = 'pdf-virtuoso-scroller';+export const ScrollSeekPlaceholder = forwardRef<+ HTMLDivElement,+ ScrollSeekPlaceholderProps & {+ context?: PDFVirtuosoContext;+ }+>(({ context }, ref) => {+ const className = context?.pageClassName;+ const width = context?.width ?? 537;+ const height = context?.height ?? 759;+ const style = { width, aspectRatio: `${width} / ${height}` };++ return (+ <div className={className} style={style} ref={ref}>+ <LoadingSvg />+ </div>+ );+});++ScrollSeekPlaceholder.displayName = 'pdf-virtuoso-scroll-seek-placeholder';+export const List = forwardRef<HTMLDivElement, PDFVirtuosoProps>(({ context: _, className, ...props }, ref) => {return (@@ -63,123 +83,33 @@ export const ListPadding = () => (<div style={{ width: '100%', height: '20px' }} />);-export const LoadingSvg = memo(function LoadingSvg({- style,- className,-}: {- style?: CSSProperties;- className?: string;-}) {- return (- <svg- className={clsx([styles.pdfLoading, className])}- style={style}- width="16"- height="24"- viewBox="0 0 537 759"- fill="none"- xmlns="http://www.w3.org/2000/svg"- >- <rect width="537" height="759" fill="white" />- <rect- x="32"- y="82"- width="361"- height="30"- rx="4"- fill="black"- fillOpacity="0.07"- />- <rect- x="32"- y="142"- width="444"- height="30"- rx="4"- fill="black"- fillOpacity="0.07"- />- <rect- x="32"- y="202"- width="387"- height="30"- rx="4"- fill="black"- fillOpacity="0.07"- />- <rect- x="32"- y="262"- width="461"- height="30"- rx="4"- fill="black"- fillOpacity="0.07"- />- <rect- x="32"- y="322"- width="282"- height="30"- rx="4"- fill="black"- fillOpacity="0.07"- />- <rect- x="32"- y="382"- width="361"- height="30"- rx="4"- fill="black"- fillOpacity="0.07"- />- <rect- x="32"- y="442"- width="444"- height="30"- rx="4"- fill="black"- fillOpacity="0.07"- />- <rect- x="32"- y="502"- width="240"- height="30"- rx="4"- fill="black"- fillOpacity="0.07"- />- <rect- x="32"- y="562"- width="201"- height="30"- rx="4"- fill="black"- fillOpacity="0.07"- />- <rect- x="32"- y="622"- width="224"- height="30"- rx="4"- fill="black"- fillOpacity="0.07"- />- <rect- x="314"- y="502"- width="191"- height="166"- rx="4"- fill="black"+export const LoadingSvg = memo(+ ({ className, style }: { className?: string; style?: CSSProperties }) => {+ return (+ <svg+ className={clsx([styles.pdfLoading, className])}+ style={style}+ width="16"+ height="24"+ viewBox="0 0 537 759"+ xmlns="http://www.w3.org/2000/svg"+ fill="currentColor"fillOpacity="0.07"- />- </svg>- );-});+ >+ <rect x="32" y="82" width="361" height="30" rx="4" />+ <rect x="32" y="142" width="444" height="30" rx="4" />+ <rect x="32" y="202" width="387" height="30" rx="4" />+ <rect x="32" y="262" width="461" height="30" rx="4" />+ <rect x="32" y="322" width="282" height="30" rx="4" />+ <rect x="32" y="382" width="361" height="30" rx="4" />+ <rect x="32" y="442" width="444" height="30" rx="4" />+ <rect x="32" y="502" width="240" height="30" rx="4" />+ <rect x="32" y="562" width="201" height="30" rx="4" />+ <rect x="32" y="622" width="224" height="30" rx="4" />+ <rect x="314" y="502" width="191" height="166" rx="4" />+ </svg>+ );+ }+);++LoadingSvg.displayName = 'pdf-loading';diff --git a/packages/frontend/core/src/modules/pdf/views/index.ts b/packages/frontend/core/src/modules/pdf/views/index.tsindex 09e3135cad..7314709cc2 100644--- a/packages/frontend/core/src/modules/pdf/views/index.ts+++ b/packages/frontend/core/src/modules/pdf/views/index.ts@@ -7,5 +7,6 @@ export {type PDFVirtuosoContext,type PDFVirtuosoProps,Scroller,+ ScrollSeekPlaceholder,} from './components';export { PDFPageRenderer } from './page-renderer';diff --git a/packages/frontend/core/src/modules/pdf/views/styles.css.ts b/packages/frontend/core/src/modules/pdf/views/styles.css.tsindex 7ded9648ad..0b45c32164 100644--- a/packages/frontend/core/src/modules/pdf/views/styles.css.ts+++ b/packages/frontend/core/src/modules/pdf/views/styles.css.ts@@ -58,6 +58,7 @@ export const pdfPageCanvas = style({export const pdfLoading = style({display: 'flex',alignSelf: 'center',+ margin: 'auto',width: '100%',height: '100%',maxWidth: '537px',