@file-viewer/renderer-spreadsheet 3.2.1 → 3.3.0
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.
- package/README.en.md +67 -3
- package/README.md +67 -3
- package/README.zh-CN.md +71 -0
- package/dist/spreadsheet/chartRenderer.js +10 -1
- package/dist/spreadsheet/rangeNavigation.d.ts +21 -0
- package/dist/spreadsheet/rangeNavigation.js +163 -0
- package/dist/spreadsheet/viewport.js +2 -2
- package/dist/spreadsheet/worker/sheetjs/formulaValues.d.ts +5 -0
- package/dist/spreadsheet/worker/sheetjs/formulaValues.js +412 -0
- package/dist/spreadsheet/worker/sheetjs/parser.js +63 -15
- package/dist/spreadsheet.js +131 -4
- package/dist/worker/sheet.worker.js +48 -48
- package/dist/worker.THIRD_PARTY_LICENSES.txt +1 -1
- package/package.json +7 -2
package/dist/spreadsheet.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createSpreadsheetRangeNavigation } from './spreadsheet/rangeNavigation.js';
|
|
2
|
+
import { createFileViewerWorkerController, createFileViewerTranslator, createFileViewerZoomChangeEmitter as createZoomChangeEmitter, createEmptyFileViewerSearchState, registerFileViewerSearchProvider, registerFileViewerViewStateProvider, registerFileViewerZoomProvider, resolveFileViewerColorScheme, resolveFileViewerFitScale, resolveFileViewerRuntimeAssetBaseUrl, resolveFileViewerSpreadsheetWorkerUrl, unregisterFileViewerSearchProvider, unregisterFileViewerViewStateProvider, unregisterFileViewerZoomProvider, } from '@file-viewer/core';
|
|
2
3
|
import { renderSpreadsheetChart } from './spreadsheet/chartRenderer.js';
|
|
3
4
|
import { createSpreadsheetImageSourceResolver } from './spreadsheet/imageSource.js';
|
|
4
5
|
import { shouldFillSpreadsheetViewport, SpreadsheetViewportFill } from './spreadsheet/viewport.js';
|
|
@@ -666,6 +667,9 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
666
667
|
let searchRequestSequence = 0;
|
|
667
668
|
let latestSearchRequest = 0;
|
|
668
669
|
let pendingSearchJump = null;
|
|
670
|
+
let pendingViewRestore = null;
|
|
671
|
+
let lastViewScrollX = 0;
|
|
672
|
+
let lastViewScrollY = 0;
|
|
669
673
|
let resolveWorkbookReady = null;
|
|
670
674
|
const workbookReady = new Promise(resolve => {
|
|
671
675
|
resolveWorkbookReady = resolve;
|
|
@@ -683,6 +687,27 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
683
687
|
return visible.length ? visible : sheets;
|
|
684
688
|
};
|
|
685
689
|
const getActiveSheetId = () => { var _a; return sheetIndex !== null && sheetIndex !== void 0 ? sheetIndex : (_a = sheets[0]) === null || _a === void 0 ? void 0 : _a.id; };
|
|
690
|
+
const rangeNavigation = createSpreadsheetRangeNavigation({
|
|
691
|
+
ready: workbookReady,
|
|
692
|
+
isVisibleSheet: id => sheets.some(sheet => sheet.id === id && !sheet.hidden),
|
|
693
|
+
getScale: () => zoom,
|
|
694
|
+
getState: () => ({
|
|
695
|
+
zoom: getZoomState(),
|
|
696
|
+
scroll: readSpreadsheetScroll(),
|
|
697
|
+
spreadsheet: { sheetId: getActiveSheetId() },
|
|
698
|
+
}),
|
|
699
|
+
restoreState: restoreSpreadsheetView,
|
|
700
|
+
fit: request => fitSpreadsheet(request),
|
|
701
|
+
onNavigate: () => { latestSearchRequest += 1; },
|
|
702
|
+
jump: range => jumpToSpreadsheetCell({ sheetId: range.sheetId, row: range.startRow, col: range.startCol }),
|
|
703
|
+
clearJump: () => {
|
|
704
|
+
pendingSearchJump = null;
|
|
705
|
+
const restore = pendingViewRestore;
|
|
706
|
+
pendingViewRestore = null;
|
|
707
|
+
restore === null || restore === void 0 ? void 0 : restore.resolve();
|
|
708
|
+
table === null || table === void 0 ? void 0 : table.draw();
|
|
709
|
+
},
|
|
710
|
+
});
|
|
686
711
|
const getColumnLabel = (column) => {
|
|
687
712
|
let value = Math.max(0, column) + 1;
|
|
688
713
|
let label = '';
|
|
@@ -732,6 +757,8 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
732
757
|
};
|
|
733
758
|
const getSearchCell = (row, col) => {
|
|
734
759
|
var _a, _b;
|
|
760
|
+
if (rangeNavigation.contains(getActiveSheetId(), row, col))
|
|
761
|
+
return 'active';
|
|
735
762
|
if (!searchCells.has(`${getActiveSheetId()}:${row}:${col}`))
|
|
736
763
|
return undefined;
|
|
737
764
|
const current = (_b = (_a = searchState.current) === null || _a === void 0 ? void 0 : _a.anchor) === null || _b === void 0 ? void 0 : _b.spreadsheet;
|
|
@@ -1216,6 +1243,12 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1216
1243
|
const head = Math.max(table.ctx.body.headIndex || 0, 0);
|
|
1217
1244
|
const tail = Math.max(table.ctx.body.tailIndex || head, head);
|
|
1218
1245
|
const scrollY = table.ctx.scrollY || 0;
|
|
1246
|
+
const scrollX = table.ctx.scrollX || 0;
|
|
1247
|
+
if (scrollX !== lastViewScrollX || scrollY !== lastViewScrollY) {
|
|
1248
|
+
lastViewScrollX = scrollX;
|
|
1249
|
+
lastViewScrollY = scrollY;
|
|
1250
|
+
rangeNavigation.notify('scroll', 'viewer');
|
|
1251
|
+
}
|
|
1219
1252
|
scrollDirection = scrollY >= lastScrollY ? 1 : -1;
|
|
1220
1253
|
lastScrollY = scrollY;
|
|
1221
1254
|
viewportRange = { start: head, end: tail };
|
|
@@ -1622,6 +1655,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1622
1655
|
if (isFirstWindow) {
|
|
1623
1656
|
scheduleStableFirstPaintRefresh();
|
|
1624
1657
|
}
|
|
1658
|
+
flushPendingViewRestore();
|
|
1625
1659
|
requestPendingSearchWindow();
|
|
1626
1660
|
flushPendingSearchJump();
|
|
1627
1661
|
const start = viewportRange.start || meta.startRow;
|
|
@@ -1713,6 +1747,68 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1713
1747
|
}
|
|
1714
1748
|
return top;
|
|
1715
1749
|
};
|
|
1750
|
+
function readSpreadsheetScroll() {
|
|
1751
|
+
const content = getSpreadsheetContentSize();
|
|
1752
|
+
const width = Math.max(tableHost.clientWidth, content.contentWidth * zoom);
|
|
1753
|
+
const height = Math.max(tableHost.clientHeight, content.contentHeight * zoom);
|
|
1754
|
+
const top = (table === null || table === void 0 ? void 0 : table.ctx.scrollY) || 0;
|
|
1755
|
+
const left = (table === null || table === void 0 ? void 0 : table.ctx.scrollX) || 0;
|
|
1756
|
+
return {
|
|
1757
|
+
top, left, width, height,
|
|
1758
|
+
clientWidth: tableHost.clientWidth,
|
|
1759
|
+
clientHeight: tableHost.clientHeight,
|
|
1760
|
+
topRatio: height > tableHost.clientHeight ? top / (height - tableHost.clientHeight) : 0,
|
|
1761
|
+
leftRatio: width > tableHost.clientWidth ? left / (width - tableHost.clientWidth) : 0,
|
|
1762
|
+
};
|
|
1763
|
+
}
|
|
1764
|
+
function restoreSpreadsheetView(state, isCurrent) {
|
|
1765
|
+
var _a, _b, _c, _d, _e;
|
|
1766
|
+
if (!isCurrent())
|
|
1767
|
+
return;
|
|
1768
|
+
const scale = Number((_a = state.scale) !== null && _a !== void 0 ? _a : (_b = state.zoom) === null || _b === void 0 ? void 0 : _b.scale);
|
|
1769
|
+
if (Number.isFinite(scale) && scale > 0)
|
|
1770
|
+
setZoom(scale);
|
|
1771
|
+
if (((_c = state.spreadsheet) === null || _c === void 0 ? void 0 : _c.range) || !sheets.length)
|
|
1772
|
+
return;
|
|
1773
|
+
const nextSheet = (_e = (_d = state.spreadsheet) === null || _d === void 0 ? void 0 : _d.sheetId) !== null && _e !== void 0 ? _e : getActiveSheetId();
|
|
1774
|
+
if (nextSheet === getActiveSheetId() && !state.scroll)
|
|
1775
|
+
return;
|
|
1776
|
+
return new Promise(resolve => {
|
|
1777
|
+
pendingViewRestore = { state, sheetId: nextSheet, isCurrent, resolve };
|
|
1778
|
+
if (nextSheet !== getActiveSheetId()) {
|
|
1779
|
+
cacheCurrentSheetState();
|
|
1780
|
+
sheetIndex = nextSheet;
|
|
1781
|
+
renderChrome();
|
|
1782
|
+
startSheetSession();
|
|
1783
|
+
scrollActiveSheetIntoView();
|
|
1784
|
+
}
|
|
1785
|
+
flushPendingViewRestore();
|
|
1786
|
+
});
|
|
1787
|
+
}
|
|
1788
|
+
function flushPendingViewRestore() {
|
|
1789
|
+
const restore = pendingViewRestore;
|
|
1790
|
+
if (!restore || !table || !virtualState.active || restore.sheetId !== getActiveSheetId())
|
|
1791
|
+
return;
|
|
1792
|
+
requestAnimationFrame(() => requestAnimationFrame(() => {
|
|
1793
|
+
if (pendingViewRestore !== restore || !restore.isCurrent() || !table || disposed)
|
|
1794
|
+
return;
|
|
1795
|
+
const scroll = restore.state.scroll;
|
|
1796
|
+
const current = readSpreadsheetScroll();
|
|
1797
|
+
const coordinate = (value, ratio, maximum) => Number.isFinite(value) ? Number(value) : Number.isFinite(ratio) ? Number(ratio) * maximum : 0;
|
|
1798
|
+
const left = coordinate(scroll === null || scroll === void 0 ? void 0 : scroll.left, scroll === null || scroll === void 0 ? void 0 : scroll.leftRatio, Math.max(0, current.width - current.clientWidth));
|
|
1799
|
+
const top = coordinate(scroll === null || scroll === void 0 ? void 0 : scroll.top, scroll === null || scroll === void 0 ? void 0 : scroll.topRatio, Math.max(0, current.height - current.clientHeight));
|
|
1800
|
+
table.scrollTo(Math.max(0, left), Math.max(0, top));
|
|
1801
|
+
table.draw();
|
|
1802
|
+
syncImageViewport();
|
|
1803
|
+
scheduleViewportLoad();
|
|
1804
|
+
requestAnimationFrame(() => {
|
|
1805
|
+
if (pendingViewRestore !== restore || !restore.isCurrent())
|
|
1806
|
+
return;
|
|
1807
|
+
pendingViewRestore = null;
|
|
1808
|
+
restore.resolve();
|
|
1809
|
+
});
|
|
1810
|
+
}));
|
|
1811
|
+
}
|
|
1716
1812
|
function flushPendingSearchJump() {
|
|
1717
1813
|
const pending = pendingSearchJump;
|
|
1718
1814
|
if (!pending ||
|
|
@@ -1726,6 +1822,10 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1726
1822
|
return;
|
|
1727
1823
|
}
|
|
1728
1824
|
pendingSearchJump = null;
|
|
1825
|
+
const navigatingRange = rangeNavigation.isPending();
|
|
1826
|
+
const finishRange = rangeNavigation.prepare(virtualState.totalRows, virtualState.totalCols);
|
|
1827
|
+
if (navigatingRange && !finishRange)
|
|
1828
|
+
return;
|
|
1729
1829
|
const targetTop = Math.max(0, getSearchRowTop(pending.row) - Math.max(0, (tableHost.clientHeight || 0) * 0.35));
|
|
1730
1830
|
const columnLeft = getSearchColumnLeft(getDisplayColumns(virtualState.columns, zoom), virtualState.dataKeys[pending.col] || getDataKey(pending.col));
|
|
1731
1831
|
const targetLeft = columnLeft === undefined
|
|
@@ -1735,6 +1835,8 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1735
1835
|
table.draw();
|
|
1736
1836
|
syncImageViewport();
|
|
1737
1837
|
scheduleViewportLoad();
|
|
1838
|
+
if (finishRange)
|
|
1839
|
+
requestAnimationFrame(finishRange);
|
|
1738
1840
|
});
|
|
1739
1841
|
}
|
|
1740
1842
|
function requestPendingSearchWindow() {
|
|
@@ -1750,9 +1852,13 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1750
1852
|
requestWindow(windowStart, false);
|
|
1751
1853
|
}
|
|
1752
1854
|
function jumpToSpreadsheetSearchMatch(match) {
|
|
1753
|
-
var _a
|
|
1855
|
+
var _a;
|
|
1754
1856
|
const spreadsheet = (_a = match === null || match === void 0 ? void 0 : match.anchor) === null || _a === void 0 ? void 0 : _a.spreadsheet;
|
|
1755
|
-
|
|
1857
|
+
jumpToSpreadsheetCell(spreadsheet || null);
|
|
1858
|
+
}
|
|
1859
|
+
function jumpToSpreadsheetCell(spreadsheet) {
|
|
1860
|
+
var _a;
|
|
1861
|
+
pendingSearchJump = spreadsheet;
|
|
1756
1862
|
if (!spreadsheet) {
|
|
1757
1863
|
return;
|
|
1758
1864
|
}
|
|
@@ -1763,12 +1869,14 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1763
1869
|
startSheetSession();
|
|
1764
1870
|
scrollActiveSheetIntoView();
|
|
1765
1871
|
const view = getTargetWindow(target);
|
|
1766
|
-
(
|
|
1872
|
+
(_a = view === null || view === void 0 ? void 0 : view.queueMicrotask) === null || _a === void 0 ? void 0 : _a.call(view, requestPendingSearchWindow);
|
|
1767
1873
|
return;
|
|
1768
1874
|
}
|
|
1769
1875
|
requestPendingSearchWindow();
|
|
1770
1876
|
}
|
|
1771
1877
|
function handleSheet(index) {
|
|
1878
|
+
latestSearchRequest += 1;
|
|
1879
|
+
rangeNavigation.cancel();
|
|
1772
1880
|
if (sheetIndex === index) {
|
|
1773
1881
|
scrollActiveSheetIntoView();
|
|
1774
1882
|
return;
|
|
@@ -1792,6 +1900,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1792
1900
|
});
|
|
1793
1901
|
const searchProvider = {
|
|
1794
1902
|
async search(query, options = {}) {
|
|
1903
|
+
rangeNavigation.cancel();
|
|
1795
1904
|
const normalizedQuery = query.replace(/\s+/g, ' ').trim();
|
|
1796
1905
|
searchOptions = options;
|
|
1797
1906
|
const requestNumber = ++latestSearchRequest;
|
|
@@ -1800,6 +1909,8 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1800
1909
|
return setSearchState('', []);
|
|
1801
1910
|
}
|
|
1802
1911
|
await workbookReady;
|
|
1912
|
+
if (requestNumber !== latestSearchRequest || disposed || errorMessage)
|
|
1913
|
+
return searchState;
|
|
1803
1914
|
const matches = await requestWorkbookSearch(normalizedQuery, searchOptions);
|
|
1804
1915
|
if (requestNumber !== latestSearchRequest || disposed) {
|
|
1805
1916
|
return searchState;
|
|
@@ -1816,6 +1927,8 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1816
1927
|
return nextState;
|
|
1817
1928
|
},
|
|
1818
1929
|
next() {
|
|
1930
|
+
latestSearchRequest += 1;
|
|
1931
|
+
rangeNavigation.cancel();
|
|
1819
1932
|
if (!searchMatches.length) {
|
|
1820
1933
|
return searchState;
|
|
1821
1934
|
}
|
|
@@ -1824,6 +1937,8 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1824
1937
|
return nextState;
|
|
1825
1938
|
},
|
|
1826
1939
|
previous() {
|
|
1940
|
+
latestSearchRequest += 1;
|
|
1941
|
+
rangeNavigation.cancel();
|
|
1827
1942
|
if (!searchMatches.length) {
|
|
1828
1943
|
return searchState;
|
|
1829
1944
|
}
|
|
@@ -1832,6 +1947,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1832
1947
|
return nextState;
|
|
1833
1948
|
},
|
|
1834
1949
|
clear() {
|
|
1950
|
+
rangeNavigation.cancel();
|
|
1835
1951
|
latestSearchRequest += 1;
|
|
1836
1952
|
pendingSearchJump = null;
|
|
1837
1953
|
return setSearchState('', []);
|
|
@@ -1841,6 +1957,10 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1841
1957
|
},
|
|
1842
1958
|
};
|
|
1843
1959
|
registerFileViewerSearchProvider(root, searchProvider);
|
|
1960
|
+
registerFileViewerViewStateProvider(root, rangeNavigation.provider);
|
|
1961
|
+
const unsubscribeViewStateZoom = zoomEmitter.subscribe(() => {
|
|
1962
|
+
rangeNavigation.notify('zoom-change', 'viewer');
|
|
1963
|
+
});
|
|
1844
1964
|
const emitParseWorkbook = () => {
|
|
1845
1965
|
var _a, _b;
|
|
1846
1966
|
emitWorker('parseWorkbook', {
|
|
@@ -1879,6 +1999,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1879
1999
|
if (sessionId && sessionId !== sheetSessionId) {
|
|
1880
2000
|
return;
|
|
1881
2001
|
}
|
|
2002
|
+
rangeNavigation.cancel('failed');
|
|
1882
2003
|
sheetInitializing = false;
|
|
1883
2004
|
loadingState = false;
|
|
1884
2005
|
if (typeof startRow === 'number') {
|
|
@@ -1897,6 +2018,9 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1897
2018
|
renderChrome();
|
|
1898
2019
|
});
|
|
1899
2020
|
controller.onWorkerError((event) => {
|
|
2021
|
+
rangeNavigation.cancel('failed');
|
|
2022
|
+
resolveWorkbookReady === null || resolveWorkbookReady === void 0 ? void 0 : resolveWorkbookReady();
|
|
2023
|
+
resolveWorkbookReady = null;
|
|
1900
2024
|
sheetInitializing = false;
|
|
1901
2025
|
loadingState = false;
|
|
1902
2026
|
errorMessage = event.message || t('spreadsheet.error.workerFailed');
|
|
@@ -1948,6 +2072,9 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
|
|
|
1948
2072
|
unmount() {
|
|
1949
2073
|
var _a, _b;
|
|
1950
2074
|
disposed = true;
|
|
2075
|
+
rangeNavigation.cancel('disposed');
|
|
2076
|
+
unsubscribeViewStateZoom();
|
|
2077
|
+
unregisterFileViewerViewStateProvider(root);
|
|
1951
2078
|
imageSourceResolver.dispose();
|
|
1952
2079
|
closeImageLightbox();
|
|
1953
2080
|
tableHostShell.removeEventListener('dblclick', handleImageDoubleClick, true);
|