@file-viewer/renderer-spreadsheet 3.3.5 → 3.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,6 +6,7 @@ export declare const PREFETCH_BEHIND = 1;
|
|
|
6
6
|
export declare const INDEX_COLUMN_KEY = "__index";
|
|
7
7
|
export declare const ROW_KEY_FIELD = "__k";
|
|
8
8
|
export declare const ROW_STATE_FIELD = "__s";
|
|
9
|
+
export declare const getOrdinaryWindowSize: (columns: number) => number;
|
|
9
10
|
export interface SheetDefaults {
|
|
10
11
|
rowHeight: number;
|
|
11
12
|
colWidth: number;
|
|
@@ -46,6 +47,7 @@ export interface VirtualSheetState {
|
|
|
46
47
|
active: boolean;
|
|
47
48
|
totalRows: number;
|
|
48
49
|
totalCols: number;
|
|
50
|
+
windowSize: number;
|
|
49
51
|
indexOffset: number;
|
|
50
52
|
defaults: SheetDefaults;
|
|
51
53
|
dataKeys: string[];
|
|
@@ -74,15 +76,16 @@ interface CollectWindowStartsOptions {
|
|
|
74
76
|
far?: boolean;
|
|
75
77
|
startRow: number;
|
|
76
78
|
totalRows: number;
|
|
79
|
+
windowSize?: number;
|
|
77
80
|
}
|
|
78
|
-
export declare const createEmptyVirtualState: () => VirtualSheetState;
|
|
81
|
+
export declare const createEmptyVirtualState: (windowSize?: number) => VirtualSheetState;
|
|
79
82
|
export declare const displayCellKey: (row: number, col: number) => string;
|
|
80
83
|
export declare const getDataKey: (index: number) => string;
|
|
81
84
|
export declare const getRowState: (row?: VirtualRow | null) => RowStateValue;
|
|
82
85
|
export declare const buildRows: (count: number) => VirtualRow[];
|
|
83
|
-
export declare const getMaxWindowStart: (totalRows: number) => number;
|
|
84
|
-
export declare const clampWindowStart: (startRow?: number, totalRows?: number) => number;
|
|
85
|
-
export declare const getWindowStart: (row?: number, totalRows?: number) => number;
|
|
86
|
-
export declare const collectWindowStarts: ({ startRow, endRow, direction, totalRows, far }: CollectWindowStartsOptions) => number[];
|
|
87
|
-
export declare const markWindowState: (rows: VirtualRow[], totalRows: number, windowStart: number, nextState: RowStateValue) => void;
|
|
86
|
+
export declare const getMaxWindowStart: (totalRows: number, windowSize?: number) => number;
|
|
87
|
+
export declare const clampWindowStart: (startRow?: number, totalRows?: number, windowSize?: number) => number;
|
|
88
|
+
export declare const getWindowStart: (row?: number, totalRows?: number, windowSize?: number) => number;
|
|
89
|
+
export declare const collectWindowStarts: ({ startRow, endRow, direction, totalRows, windowSize, far }: CollectWindowStartsOptions) => number[];
|
|
90
|
+
export declare const markWindowState: (rows: VirtualRow[], totalRows: number, windowStart: number, nextState: RowStateValue, windowSize?: number) => void;
|
|
88
91
|
export {};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { ORDINARY_GRID_BUDGET } from './sourceRegion.js';
|
|
1
2
|
export const WINDOW_SIZE = 500;
|
|
2
3
|
export const PREFETCH_AHEAD = 3;
|
|
3
4
|
export const PREFETCH_BEHIND = 1;
|
|
4
5
|
export const INDEX_COLUMN_KEY = '__index';
|
|
5
6
|
export const ROW_KEY_FIELD = '__k';
|
|
6
7
|
export const ROW_STATE_FIELD = '__s';
|
|
8
|
+
export const getOrdinaryWindowSize = (columns) => Math.min(WINDOW_SIZE, Math.max(1, Math.floor(ORDINARY_GRID_BUDGET.windowCells / Math.max(1, columns))));
|
|
7
9
|
export const DEFAULT_SHEET_DEFAULTS = {
|
|
8
10
|
rowHeight: 20,
|
|
9
11
|
colWidth: 64
|
|
@@ -13,10 +15,11 @@ export const RowState = {
|
|
|
13
15
|
Loading: 1,
|
|
14
16
|
Loaded: 2
|
|
15
17
|
};
|
|
16
|
-
export const createEmptyVirtualState = () => ({
|
|
18
|
+
export const createEmptyVirtualState = (windowSize = WINDOW_SIZE) => ({
|
|
17
19
|
active: false,
|
|
18
20
|
totalRows: 0,
|
|
19
21
|
totalCols: 0,
|
|
22
|
+
windowSize,
|
|
20
23
|
indexOffset: 0,
|
|
21
24
|
defaults: { ...DEFAULT_SHEET_DEFAULTS },
|
|
22
25
|
dataKeys: [],
|
|
@@ -58,39 +61,39 @@ export const buildRows = (count) => {
|
|
|
58
61
|
}
|
|
59
62
|
return rows;
|
|
60
63
|
};
|
|
61
|
-
export const getMaxWindowStart = (totalRows) => {
|
|
64
|
+
export const getMaxWindowStart = (totalRows, windowSize = WINDOW_SIZE) => {
|
|
62
65
|
if (!totalRows) {
|
|
63
66
|
return 0;
|
|
64
67
|
}
|
|
65
|
-
return Math.floor(Math.max(totalRows - 1, 0) /
|
|
68
|
+
return Math.floor(Math.max(totalRows - 1, 0) / windowSize) * windowSize;
|
|
66
69
|
};
|
|
67
|
-
export const clampWindowStart = (startRow = 0, totalRows = 0) => {
|
|
68
|
-
return Math.min(Math.max(startRow, 0), getMaxWindowStart(totalRows));
|
|
70
|
+
export const clampWindowStart = (startRow = 0, totalRows = 0, windowSize = WINDOW_SIZE) => {
|
|
71
|
+
return Math.min(Math.max(startRow, 0), getMaxWindowStart(totalRows, windowSize));
|
|
69
72
|
};
|
|
70
|
-
export const getWindowStart = (row = 0, totalRows = 0) => {
|
|
71
|
-
const start = Math.floor(Math.max(row, 0) /
|
|
72
|
-
return clampWindowStart(start, totalRows);
|
|
73
|
+
export const getWindowStart = (row = 0, totalRows = 0, windowSize = WINDOW_SIZE) => {
|
|
74
|
+
const start = Math.floor(Math.max(row, 0) / windowSize) * windowSize;
|
|
75
|
+
return clampWindowStart(start, totalRows, windowSize);
|
|
73
76
|
};
|
|
74
|
-
export const collectWindowStarts = ({ startRow, endRow, direction, totalRows, far = false }) => {
|
|
77
|
+
export const collectWindowStarts = ({ startRow, endRow, direction, totalRows, windowSize = WINDOW_SIZE, far = false }) => {
|
|
75
78
|
const starts = new Set();
|
|
76
|
-
const firstWindow = getWindowStart(startRow, totalRows);
|
|
77
|
-
const lastWindow = getWindowStart(endRow, totalRows);
|
|
78
|
-
for (let current = firstWindow; current <= lastWindow; current +=
|
|
79
|
+
const firstWindow = getWindowStart(startRow, totalRows, windowSize);
|
|
80
|
+
const lastWindow = getWindowStart(endRow, totalRows, windowSize);
|
|
81
|
+
for (let current = firstWindow; current <= lastWindow; current += windowSize) {
|
|
79
82
|
starts.add(current);
|
|
80
83
|
}
|
|
81
84
|
const ahead = far ? PREFETCH_AHEAD + 1 : PREFETCH_AHEAD;
|
|
82
85
|
const behind = far ? PREFETCH_BEHIND + 1 : PREFETCH_BEHIND;
|
|
83
86
|
const anchor = direction > 0 ? lastWindow : firstWindow;
|
|
84
87
|
for (let step = 1; step <= ahead; step += 1) {
|
|
85
|
-
starts.add(clampWindowStart(anchor + direction * step *
|
|
88
|
+
starts.add(clampWindowStart(anchor + direction * step * windowSize, totalRows, windowSize));
|
|
86
89
|
}
|
|
87
90
|
for (let step = 1; step <= behind; step += 1) {
|
|
88
|
-
starts.add(clampWindowStart(anchor - direction * step *
|
|
91
|
+
starts.add(clampWindowStart(anchor - direction * step * windowSize, totalRows, windowSize));
|
|
89
92
|
}
|
|
90
93
|
return Array.from(starts);
|
|
91
94
|
};
|
|
92
|
-
export const markWindowState = (rows, totalRows, windowStart, nextState) => {
|
|
93
|
-
const endRow = Math.min(windowStart +
|
|
95
|
+
export const markWindowState = (rows, totalRows, windowStart, nextState, windowSize = WINDOW_SIZE) => {
|
|
96
|
+
const endRow = Math.min(windowStart + windowSize, totalRows);
|
|
94
97
|
for (let rowIndex = windowStart; rowIndex < endRow; rowIndex += 1) {
|
|
95
98
|
const row = rows[rowIndex];
|
|
96
99
|
if (!row) {
|
package/dist/spreadsheet.js
CHANGED
|
@@ -6,7 +6,7 @@ import { createFileViewerWorkerController, createFileViewerTranslator, normalize
|
|
|
6
6
|
import { renderSpreadsheetChart } from './spreadsheet/chartRenderer.js';
|
|
7
7
|
import { createSpreadsheetImageSourceResolver } from './spreadsheet/imageSource.js';
|
|
8
8
|
import { shouldFillSpreadsheetViewport, SpreadsheetViewportFill } from './spreadsheet/viewport.js';
|
|
9
|
-
import { buildRows, clampWindowStart, collectWindowStarts, createEmptyVirtualState, DEFAULT_SHEET_DEFAULTS, displayCellKey, getDataKey, getWindowStart, INDEX_COLUMN_KEY, markWindowState, ROW_STATE_FIELD, RowState,
|
|
9
|
+
import { buildRows, clampWindowStart, collectWindowStarts, createEmptyVirtualState, DEFAULT_SHEET_DEFAULTS, displayCellKey, getDataKey, getOrdinaryWindowSize, getWindowStart, INDEX_COLUMN_KEY, markWindowState, ROW_STATE_FIELD, RowState, } from './spreadsheet/state.js';
|
|
10
10
|
import { buildColumns, createTableConfig, detectIndexOffset, getDisplayColumns, getSearchColumnLeft, getRowHeight, HEADER_HEIGHT, INDEX_COLUMN_WIDTH, normalizeCellStyle, normalizeRowHeight, RESIZABLE_COLUMN_MIN_WIDTH, RESIZABLE_ROW_MIN_HEIGHT, SPREADSHEET_MAX_ZOOM, SPREADSHEET_MIN_ZOOM, } from './spreadsheet/view.js';
|
|
11
11
|
const EXCEL_IMAGE_SCROLLBAR_GUARD = 18;
|
|
12
12
|
const DEFAULT_SPREADSHEET_WORKER_AUTO_THRESHOLD = 1 * 1024 * 1024;
|
|
@@ -638,7 +638,6 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
638
638
|
let sheetDefaults = { ...DEFAULT_SHEET_DEFAULTS };
|
|
639
639
|
let sheetInitializing = true;
|
|
640
640
|
let hasInitialWindow = false;
|
|
641
|
-
let loadedWindowCount = 0;
|
|
642
641
|
let loadingWindowCount = 0;
|
|
643
642
|
let sheetImages = [];
|
|
644
643
|
let sheetCharts = [];
|
|
@@ -890,7 +889,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
890
889
|
if (!totalRows) {
|
|
891
890
|
return '';
|
|
892
891
|
}
|
|
893
|
-
const cachedRows =
|
|
892
|
+
const cachedRows = Array.from(virtualState.windowRows.values()).reduce((count, rows) => count + rows.length, 0);
|
|
894
893
|
return t('spreadsheet.state.cachedRows', {
|
|
895
894
|
cached: cachedRows,
|
|
896
895
|
total: totalRows,
|
|
@@ -1219,7 +1218,6 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1219
1218
|
subscribe: zoomEmitter.subscribe,
|
|
1220
1219
|
});
|
|
1221
1220
|
const syncWindowStats = () => {
|
|
1222
|
-
loadedWindowCount = virtualState.loadedWindows.size;
|
|
1223
1221
|
loadingWindowCount = virtualState.loadingWindows.size;
|
|
1224
1222
|
renderChrome();
|
|
1225
1223
|
};
|
|
@@ -1296,6 +1294,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1296
1294
|
endRow,
|
|
1297
1295
|
direction: scrollDirection,
|
|
1298
1296
|
totalRows: virtualState.totalRows,
|
|
1297
|
+
windowSize: virtualState.windowSize,
|
|
1299
1298
|
}).forEach(windowStart => requestWindow(windowStart, true));
|
|
1300
1299
|
};
|
|
1301
1300
|
const scheduleViewportLoad = () => {
|
|
@@ -1533,21 +1532,21 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1533
1532
|
if (sheetId === undefined) {
|
|
1534
1533
|
return;
|
|
1535
1534
|
}
|
|
1536
|
-
const windowStart = clampWindowStart(startRow, virtualState.totalRows);
|
|
1535
|
+
const windowStart = clampWindowStart(startRow, virtualState.totalRows, virtualState.windowSize);
|
|
1537
1536
|
if (virtualState.loadedWindows.has(windowStart) || virtualState.loadingWindows.has(windowStart)) {
|
|
1538
1537
|
return;
|
|
1539
1538
|
}
|
|
1540
1539
|
virtualState.loadingWindows.add(windowStart);
|
|
1541
1540
|
syncWindowStats();
|
|
1542
1541
|
if (virtualState.active) {
|
|
1543
|
-
markWindowState(virtualState.rows, virtualState.totalRows, windowStart, RowState.Loading);
|
|
1542
|
+
markWindowState(virtualState.rows, virtualState.totalRows, windowStart, RowState.Loading, virtualState.windowSize);
|
|
1544
1543
|
table === null || table === void 0 ? void 0 : table.draw();
|
|
1545
1544
|
}
|
|
1546
1545
|
errorMessage = '';
|
|
1547
1546
|
emitWorker('parseSheet', {
|
|
1548
1547
|
sheet: sheetId,
|
|
1549
1548
|
startRow: windowStart,
|
|
1550
|
-
pageSize:
|
|
1549
|
+
pageSize: virtualState.windowSize,
|
|
1551
1550
|
sessionId: sheetSessionId,
|
|
1552
1551
|
});
|
|
1553
1552
|
if (silent) {
|
|
@@ -1562,7 +1561,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1562
1561
|
}
|
|
1563
1562
|
const { columns, dataKeys } = buildColumns(ws, rowNumberMode);
|
|
1564
1563
|
virtualState = {
|
|
1565
|
-
...createEmptyVirtualState(),
|
|
1564
|
+
...createEmptyVirtualState(virtualState.windowSize),
|
|
1566
1565
|
active: true,
|
|
1567
1566
|
totalRows: meta.totalRows,
|
|
1568
1567
|
totalCols: meta.totalCols,
|
|
@@ -1759,11 +1758,10 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1759
1758
|
flushPendingViewRestore();
|
|
1760
1759
|
requestPendingSearchWindow();
|
|
1761
1760
|
flushPendingSearchJump();
|
|
1762
|
-
|
|
1763
|
-
const end = Math.max(viewportRange.end, meta.endRow - 1, meta.startRow);
|
|
1764
|
-
ensureViewportWindows(start, end);
|
|
1761
|
+
ensureViewportWindows(viewportRange.start, viewportRange.end);
|
|
1765
1762
|
};
|
|
1766
1763
|
const resetViewState = () => {
|
|
1764
|
+
var _a, _b;
|
|
1767
1765
|
autoRowHeight.cancel();
|
|
1768
1766
|
errorMessage = '';
|
|
1769
1767
|
totalRows = 0;
|
|
@@ -1771,7 +1769,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1771
1769
|
sheetDefaults = { ...DEFAULT_SHEET_DEFAULTS };
|
|
1772
1770
|
sheetImages = [];
|
|
1773
1771
|
sheetCharts = [];
|
|
1774
|
-
virtualState = createEmptyVirtualState();
|
|
1772
|
+
virtualState = createEmptyVirtualState(getOrdinaryWindowSize((_b = (_a = getActiveSheet()) === null || _a === void 0 ? void 0 : _a.colCount) !== null && _b !== void 0 ? _b : 0));
|
|
1775
1773
|
hasInitialWindow = false;
|
|
1776
1774
|
resetViewportTracking();
|
|
1777
1775
|
syncWindowStats();
|
|
@@ -1916,7 +1914,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1916
1914
|
const pending = pendingSearchJump;
|
|
1917
1915
|
if (!pending ||
|
|
1918
1916
|
pending.sheetId !== getActiveSheetId() ||
|
|
1919
|
-
!virtualState.loadedWindows.has(getWindowStart(pending.row, virtualState.totalRows)) ||
|
|
1917
|
+
!virtualState.loadedWindows.has(getWindowStart(pending.row, virtualState.totalRows, virtualState.windowSize)) ||
|
|
1920
1918
|
!table) {
|
|
1921
1919
|
return;
|
|
1922
1920
|
}
|
|
@@ -1947,7 +1945,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1947
1945
|
if (!pending || pending.sheetId !== getActiveSheetId() || !virtualState.totalRows) {
|
|
1948
1946
|
return;
|
|
1949
1947
|
}
|
|
1950
|
-
const windowStart = getWindowStart(pending.row, virtualState.totalRows);
|
|
1948
|
+
const windowStart = getWindowStart(pending.row, virtualState.totalRows, virtualState.windowSize);
|
|
1951
1949
|
if (virtualState.loadedWindows.has(windowStart)) {
|
|
1952
1950
|
flushPendingSearchJump();
|
|
1953
1951
|
return;
|
|
@@ -2112,7 +2110,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
2112
2110
|
virtualState.loadingWindows.delete(startRow);
|
|
2113
2111
|
syncWindowStats();
|
|
2114
2112
|
if (virtualState.active) {
|
|
2115
|
-
markWindowState(virtualState.rows, virtualState.totalRows, startRow, RowState.Placeholder);
|
|
2113
|
+
markWindowState(virtualState.rows, virtualState.totalRows, startRow, RowState.Placeholder, virtualState.windowSize);
|
|
2116
2114
|
table === null || table === void 0 ? void 0 : table.draw();
|
|
2117
2115
|
}
|
|
2118
2116
|
}
|