streaksheet
Advanced tools
Comparing version 0.8.0 to 0.8.1
import * as React from 'react'; | ||
import { ComponentType, CSSProperties } from 'react'; | ||
import useSheetData from './useSheetData'; | ||
import { UnsupportedOperation, Row, RowsResult } from './internalTypes'; | ||
import type { ColumnAndOverviewData, ColumnInfo, RowId, Section, SheetData, SheetDataOptions } from './useSheetData'; | ||
import { UnsupportedOperation, Row } from './internalTypes'; | ||
import type { ColumnAndOverviewData, ColumnInfo, RowId, Section, SheetData, SheetDataOptions, ExposedRowsResult } from './useSheetData'; | ||
export { useSheetData }; | ||
export type { SheetDataOptions, SheetData, Section, ColumnInfo, ColumnAndOverviewData, Row, RowsResult, RowId, }; | ||
export type { SheetDataOptions, SheetData, Section, ColumnInfo, ColumnAndOverviewData, Row, ExposedRowsResult as RowsResult, RowId, }; | ||
export interface CellPosition { | ||
@@ -9,0 +9,0 @@ sectionKey: string; |
@@ -114,2 +114,3 @@ "use strict"; | ||
getEffectiveSectionRowCount = sheetData.getEffectiveSectionRowCount; | ||
var sheetDataForStreakSheet = sheetData.useByStreakSheet(); | ||
var visibleColumns = (0, React.useMemo)(function () { | ||
@@ -367,3 +368,3 @@ return columnAndOverviewData.columns.filter(function (col) { | ||
} | ||
var cellDataMappers = (0, _useCellDataMappers["default"])(rowsBySection, visibleColumns, sectionRowMatcher, columnAndOverviewData, getEffectiveSectionRowCount); | ||
var cellDataMappers = (0, _useCellDataMappers["default"])(rowsBySection, visibleColumns, sectionRowMatcher, columnAndOverviewData, sheetDataForStreakSheet.getIndexForRow); | ||
var cellIndexesToKeysAndData = cellDataMappers.cellIndexesToKeysAndData, | ||
@@ -596,3 +597,2 @@ cellIndexesToKeys = cellDataMappers.cellIndexesToKeys, | ||
}, [Cell, editedCellRef, cellBeingEdited, cellIndexesToKeys, cellIndexesToKeysAndData, sectionRowMatcher, styles, setCellBeingEdited, props.rowHoveredClassName]); | ||
var sheetDataForStreakSheet = sheetData.useByStreakSheet(); | ||
var onItemsRendered = (0, React.useCallback)(function (_ref4) { | ||
@@ -599,0 +599,0 @@ var visibleRowStartIndex = _ref4.visibleRowStartIndex, |
import { CellKeys, ColumnInfo } from '.'; | ||
import { CellIndexes, CellIndexesToKeysAndDataResult, CellRegion, RowsBySection } from './internalTypes'; | ||
import SectionRowMatcher from './SectionRowMatcher'; | ||
import { ColumnAndOverviewData, Section } from './useSheetData'; | ||
import { ColumnAndOverviewData } from './useSheetData'; | ||
export declare type KeysAndDataByIndex<T> = { | ||
@@ -16,2 +16,2 @@ [x: number]: { | ||
} | ||
export default function useCellDataMappers<T>(rowsBySection: RowsBySection<T>, visibleColumns: ColumnInfo[], sectionRowMatcher: SectionRowMatcher, columnAndOverviewData: ColumnAndOverviewData, getEffectiveSectionRowCount: (section: Section) => number): CellDataMappers<T>; | ||
export default function useCellDataMappers<T>(rowsBySection: RowsBySection<T>, visibleColumns: ColumnInfo[], sectionRowMatcher: SectionRowMatcher, columnAndOverviewData: ColumnAndOverviewData, rowKeysToIndex: (sectionKey: string, rowKey: string) => number | undefined): CellDataMappers<T>; |
@@ -14,4 +14,2 @@ "use strict"; | ||
var _getSectionRawRowIndex = _interopRequireDefault(require("./section/getSectionRawRowIndex")); | ||
var _getRegionBoundary2 = _interopRequireDefault(require("./selection/getRegionBoundary")); | ||
@@ -23,3 +21,3 @@ | ||
function useCellDataMappers(rowsBySection, visibleColumns, sectionRowMatcher, columnAndOverviewData, getEffectiveSectionRowCount) { | ||
function useCellDataMappers(rowsBySection, visibleColumns, sectionRowMatcher, columnAndOverviewData, rowKeysToIndex) { | ||
var cellIndexesToKeysAndData = (0, _react.useCallback)(function (rowIndex, columnIndex) { | ||
@@ -114,37 +112,4 @@ var columnKey = visibleColumns[columnIndex].key; | ||
}, [cellIndexesToKeysAndData]); | ||
var rowKeysToIndex = (0, _react.useCallback)(function (sectionKey, rowKey) { | ||
var rowsChunks = rowsBySection[sectionKey]; | ||
if (!rowsChunks) { | ||
return null; | ||
} | ||
var rowIndexWithinSection = function () { | ||
if (rowKey == null) { | ||
// Section header | ||
return -1; | ||
} | ||
for (var rowsChunkIndex = 0; rowsChunkIndex < rowsChunks.length; rowsChunkIndex++) { | ||
var rowsChunk = rowsChunks[rowsChunkIndex]; | ||
for (var _rowIndex = 0; _rowIndex < rowsChunk.rowsResult.rows.length; _rowIndex++) { | ||
var row = rowsChunk.rowsResult.rows[_rowIndex]; | ||
if (rowKey === row.key) { | ||
return _rowIndex; | ||
} | ||
} | ||
} | ||
}(); | ||
if (rowIndexWithinSection === undefined) { | ||
return null; | ||
} | ||
var rowIndex = rowIndexWithinSection + (0, _getSectionRawRowIndex["default"])(columnAndOverviewData.sections, sectionKey, getEffectiveSectionRowCount) + 1; | ||
return rowIndex; | ||
}, [columnAndOverviewData.sections, getEffectiveSectionRowCount, rowsBySection]); | ||
var cellKeysToIndexes = (0, _react.useCallback)(function (sectionKey, rowKey, columnKey) { | ||
var rowIndex = rowKeysToIndex(sectionKey, rowKey); | ||
var rowIndex = rowKey ? rowKeysToIndex(sectionKey, rowKey) : -1; | ||
@@ -151,0 +116,0 @@ if (!rowIndex) { |
@@ -19,2 +19,3 @@ import { RowsBySection, StartedRowsRequests } from './internalTypes'; | ||
getEffectiveSectionRowCount(section: Section): number; | ||
getIndexForRow(sectionKey: string, rowKey: string): number | undefined; | ||
} | ||
@@ -21,0 +22,0 @@ declare type RowMutation<T> = RowAddMutation<T> | RowDeleteMutation; |
@@ -38,2 +38,4 @@ "use strict"; | ||
var _getSectionRawRowIndex = _interopRequireDefault(require("./section/getSectionRawRowIndex")); | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
@@ -742,2 +744,30 @@ | ||
}, [calculatedRowsBySection]); | ||
var getIndexForRow = (0, _react.useCallback)(function (sectionKey, rowKey) { | ||
var rowsChunks = calculatedRowsBySection[sectionKey]; | ||
if (!rowsChunks) { | ||
return; | ||
} | ||
var rowIndexWithinSection = function () { | ||
for (var rowsChunkIndex = 0; rowsChunkIndex < rowsChunks.length; rowsChunkIndex++) { | ||
var rowsChunk = rowsChunks[rowsChunkIndex]; | ||
for (var _rowIndex = 0; _rowIndex < rowsChunk.rowsResult.rows.length; _rowIndex++) { | ||
var row = rowsChunk.rowsResult.rows[_rowIndex]; | ||
if (rowKey === row.key) { | ||
return _rowIndex; | ||
} | ||
} | ||
} | ||
}(); | ||
if (rowIndexWithinSection === undefined) { | ||
return; | ||
} | ||
var rowIndex = rowIndexWithinSection + (0, _getSectionRawRowIndex["default"])(sections, sectionKey, getEffectiveSectionRowCount) + 1; | ||
return rowIndex; | ||
}, [calculatedRowsBySection, getEffectiveSectionRowCount, sections]); | ||
return { | ||
@@ -753,5 +783,6 @@ getEffectiveSectionRowCount: getEffectiveSectionRowCount, | ||
setRowData: setRowData, | ||
getRowData: getRowData | ||
getRowData: getRowData, | ||
getIndexForRow: getIndexForRow | ||
}; | ||
} | ||
//# sourceMappingURL=useRowsBySection.js.map |
@@ -113,6 +113,8 @@ /// <reference types="react" /> | ||
getEffectiveSectionRowCount(section: Section): number; | ||
getIndexForRow(sectionKey: string, rowKey: string): number; | ||
} | ||
export interface SheetDataForStreakSheet { | ||
onScroll(visibleRowStartIndex: number, visibleRowStopIndex: number): void; | ||
getIndexForRow(sectionKey: string, rowKey: string): number | undefined; | ||
} | ||
export default function useSheetData<T>(options: SheetDataOptions<T>): SheetData<T>; |
@@ -47,3 +47,4 @@ "use strict"; | ||
refreshRows = _useRowsBySection.refreshRows, | ||
getEffectiveSectionRowCount = _useRowsBySection.getEffectiveSectionRowCount; | ||
getEffectiveSectionRowCount = _useRowsBySection.getEffectiveSectionRowCount, | ||
_getIndexForRow = _useRowsBySection.getIndexForRow; | ||
@@ -153,3 +154,4 @@ verify(options); | ||
return onScrollLatest.current(visibleRowStartIndex, visibleRowStopIndex); | ||
} | ||
}, | ||
getIndexForRow: _getIndexForRow | ||
}; | ||
@@ -159,2 +161,11 @@ }, []); | ||
var getIndexForRow = (0, _react.useCallback)(function (sectionKey, rowKey) { | ||
var index = _getIndexForRow(sectionKey, rowKey); | ||
if (!index) { | ||
throw new Error("attempted to get index for unloaded row (sectionKey=".concat(sectionKey, ", rowKey=").concat(rowKey, ")")); | ||
} | ||
return index; | ||
}, [_getIndexForRow]); | ||
return { | ||
@@ -179,3 +190,4 @@ addRowData: addRowData, | ||
useByStreakSheet: useByStreakSheet, | ||
getEffectiveSectionRowCount: getEffectiveSectionRowCount | ||
getEffectiveSectionRowCount: getEffectiveSectionRowCount, | ||
getIndexForRow: getIndexForRow | ||
}; | ||
@@ -182,0 +194,0 @@ } // SectionRow can have a negative section to represent the column headers, |
{ | ||
"name": "streaksheet", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"author": "Chris Cowan <agentme49@gmail.com>", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
584923
5110