-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored sheetTable, pulling interactions out.
- Loading branch information
erikh2000
authored and
erikh2000
committed
Jan 1, 2025
1 parent
9f930a6
commit 021cafd
Showing
13 changed files
with
104 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { CSSProperties, RefObject } from 'react'; | ||
import HoneSheet from '@/sheets/types/HoneSheet'; | ||
import DOMTextMeasurer from '@/components/sheetTable/DOMTextMeasurer'; | ||
import { plural } from '@/common/englishGrammarUtil'; | ||
import rowStyles from '@/components/sheetTable/SheetRow.module.css'; | ||
import { GeneratedFooterText } from '@/components/sheetTable/types/GeneratedFooterText'; | ||
import HorizontalScroll from '@/components/sheetTable/types/HorizontalScroll'; | ||
import VerticalScroll from '@/components/sheetTable/types/VerticalScroll'; | ||
|
||
type DivRef = RefObject<HTMLDivElement>; | ||
|
||
export function measureColumnWidths(sheetTableElement:HTMLDivElement, sheet:HoneSheet):number[] { | ||
const measurer = new DOMTextMeasurer(sheetTableElement, rowStyles.measureCellText); | ||
const widths = sheet.columns.map(column => measurer.measureTextWidth(column.name)); | ||
for(let rowI = 0; rowI < sheet.rows.length; rowI++) { | ||
const row = sheet.rows[rowI]; | ||
for(let cellI = 0; cellI < row.length; cellI++) { | ||
const cell = '' + row[cellI]; | ||
widths[cellI] = Math.max(widths[cellI], measurer.measureTextWidth(cell)); | ||
} | ||
} | ||
return widths; | ||
} | ||
|
||
export function getFooterText(footerText:string|GeneratedFooterText|undefined, sheet:HoneSheet):string { | ||
if (footerText === undefined) return ''; | ||
if (footerText === GeneratedFooterText.ROW_COUNT) return `${sheet.rows.length} ${plural('row', sheet.rows.length)}`; | ||
return footerText; | ||
} | ||
|
||
export function syncScrollableElements(headerInnerElement:DivRef, rowsScrollElement:DivRef) { | ||
if (!headerInnerElement.current || !rowsScrollElement.current) return; | ||
const scrollLeft = rowsScrollElement.current.scrollLeft; | ||
headerInnerElement.current.style.transform = `translateX(-${scrollLeft}px)`; | ||
} | ||
|
||
export function getRowScrollContainerStyle(displayRowCount:number|undefined, parentElement:HTMLDivElement|null):CSSProperties { | ||
if (!displayRowCount || !parentElement) return {}; | ||
const measurer = new DOMTextMeasurer(parentElement, rowStyles.measureCellText); | ||
const lineHeight = measurer.getLineHeight(); | ||
return {maxHeight:displayRowCount * lineHeight + 'px'}; | ||
} | ||
|
||
export function setHorizontalScroll(rowsScrollElement:DivRef, horizontalScroll?:HorizontalScroll) { | ||
if (horizontalScroll === undefined || horizontalScroll === HorizontalScroll.CLEAR || rowsScrollElement.current === null) return; | ||
if (horizontalScroll === HorizontalScroll.LEFT) { | ||
rowsScrollElement.current.scrollLeft = 0; | ||
} else if (horizontalScroll === HorizontalScroll.RIGHT) { | ||
rowsScrollElement.current.scrollLeft = rowsScrollElement.current.scrollWidth; | ||
} | ||
} | ||
|
||
export function setVerticalScroll(rowsScrollElement:DivRef, verticalScroll?:VerticalScroll) { | ||
if (verticalScroll === undefined || verticalScroll === VerticalScroll.CLEAR || rowsScrollElement.current === null) return; | ||
if (verticalScroll === VerticalScroll.TOP) { | ||
rowsScrollElement.current.scrollTop = 0; | ||
} else if (verticalScroll === VerticalScroll.BOTTOM) { | ||
rowsScrollElement.current.scrollTop = rowsScrollElement.current.scrollHeight; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum GeneratedFooterText { | ||
ROW_COUNT = 0, | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
enum HorizontalScroll { | ||
CLEAR = 0, | ||
LEFT, | ||
RIGHT | ||
} | ||
|
||
export default HorizontalScroll; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
enum VerticalScroll { | ||
CLEAR = 0, | ||
TOP, | ||
BOTTOM | ||
} | ||
|
||
export default VerticalScroll; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters