diff --git a/CHANGELOG.md b/CHANGELOG.md index de18234..16b438f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # CHANGELOG +## 0.6.2 + +_2024-06-19_ + +### Bugfix + +- (Docs) updated types + ## 0.6.1 _2024-06-17_ diff --git a/package.json b/package.json index 2566cbd..8dce5c0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-fluid-table", - "version": "0.6.1", + "version": "0.6.2", "description": "A React table inspired by react-window", "author": "Mckervin Ceme ", "license": "MIT", diff --git a/src/Header.tsx b/src/Header.tsx index ab1b81a..77220e7 100644 --- a/src/Header.tsx +++ b/src/Header.tsx @@ -99,8 +99,8 @@ const Header = forwardRef( } = useContext(TableContext); // variables - const { scrollWidth, clientWidth } = ((ref as React.MutableRefObject).current || - NO_NODE) as HTMLDivElement; + const { scrollWidth, clientWidth } = + (ref as React.MutableRefObject).current || NO_NODE; const width = scrollWidth <= clientWidth ? "100%" : undefined; const stickyStyle: React.CSSProperties = { zIndex: columns.find(c => c.frozen) ? 2 : undefined diff --git a/src/NumberTree.ts b/src/NumberTree.ts index 201d34d..44eea5b 100644 --- a/src/NumberTree.ts +++ b/src/NumberTree.ts @@ -1,7 +1,7 @@ -interface LeafProps { +type LeafProps = { height: number; index: number; -} +}; class Leaf { index: number; diff --git a/src/Table.tsx b/src/Table.tsx index 9c310c7..ad6ce92 100644 --- a/src/Table.tsx +++ b/src/Table.tsx @@ -38,6 +38,14 @@ type ListProps = Omit, "columns" | "borders"> & { borders: boolean; }; +type ListRef = VariableSizeList & { + _instanceProps: { + itemMetadataMap: { + [x: number]: { size: number }; + }; + }; +}; + /** * The main table component */ @@ -57,7 +65,7 @@ const ListComponent = forwardRef(function ( ) { // hooks const timeoutRef = useRef(0); - const listRef = useRef(null); + const listRef = useRef(null); const prevWidthRef = useRef(width); const [tree] = useState(new NumberTree()); const tableRef = useRef(null); @@ -101,7 +109,7 @@ const ListComponent = forwardRef(function ( const node = tableRef.current?.children[1].children[0] as HTMLElement; const resetIndex = Number(node?.dataset.index || "0") + 1; tree.clearFromIndex(resetIndex); - listRef.current.resetAfterIndex(resetIndex); + listRef.current!.resetAfterIndex(resetIndex); }, timeout); }, [] @@ -233,9 +241,9 @@ const ListComponent = forwardRef(function ( /* misc */ // provide access to window functions useImperativeHandle(ref, () => ({ - scrollTo: (scrollOffset: number): void => listRef.current.scrollTo(scrollOffset), + scrollTo: (scrollOffset: number): void => listRef.current!.scrollTo(scrollOffset), scrollToItem: (index: number, align: ScrollAlign = "auto"): void => - listRef.current.scrollToItem(index, align) + listRef.current!.scrollToItem(index, align) })); return ( diff --git a/src/constants.ts b/src/constants.ts index 594c132..ea1b3fc 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,4 +1,4 @@ export const DEFAULT_ROW_HEIGHT = 37; export const DEFAULT_HEADER_HEIGHT = 37; export const DEFAULT_FOOTER_HEIGHT = 37; -export const NO_NODE = { scrollWidth: 0, clientWidth: 0 }; +export const NO_NODE = { scrollWidth: 0, clientWidth: 0 } as HTMLDivElement;