@file-viewer/renderer-spreadsheet 3.0.2 → 3.1.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.
@@ -13,6 +13,7 @@ interface TableConfigOptions {
13
13
  resizableColumns?: boolean;
14
14
  resizableRows?: boolean;
15
15
  copySelection?: (params: SpreadsheetCopyParams) => void;
16
+ searchCell?: (row: number, col: number) => 'active' | 'match' | undefined;
16
17
  sheetDefaults: SheetDefaults;
17
18
  virtualState: VirtualSheetState;
18
19
  zoomScale?: number;
@@ -32,7 +33,8 @@ export declare const buildColumns: (ws: SheetModel) => {
32
33
  dataKeys: string[];
33
34
  };
34
35
  export declare const getDisplayColumns: (columns: Column[], zoomScale?: number) => Column[];
36
+ export declare const getSearchColumnLeft: (columns: Column[], key: string) => number | undefined;
35
37
  export declare const createTextLayer: (documentRef: Document, value: unknown, style: CellStyleCache, padding: number) => HTMLSpanElement;
36
38
  export declare const normalizeCellStyle: (meta: SheetCellMetadata | undefined) => CellStyleCache | undefined;
37
- export declare const createTableConfig: ({ hostHeight, darkMode, resizableColumns, resizableRows, copySelection, sheetDefaults, virtualState, zoomScale }: TableConfigOptions) => ConfigType;
39
+ export declare const createTableConfig: ({ hostHeight, darkMode, resizableColumns, resizableRows, copySelection, searchCell, sheetDefaults, virtualState, zoomScale }: TableConfigOptions) => ConfigType;
38
40
  export {};
@@ -353,6 +353,28 @@ export const getDisplayColumns = (columns, zoomScale = 1) => {
353
353
  }
354
354
  return columns.map(column => scaleColumn(column, normalizedScale));
355
355
  };
356
+ export const getSearchColumnLeft = (columns, key) => {
357
+ let left = 0;
358
+ const visit = (list) => {
359
+ var _a;
360
+ for (const column of list) {
361
+ if (column.hide)
362
+ continue;
363
+ if ((_a = column.children) === null || _a === void 0 ? void 0 : _a.length) {
364
+ const childLeft = visit(column.children);
365
+ if (childLeft !== undefined)
366
+ return childLeft;
367
+ }
368
+ else {
369
+ if (`${column.key}` === key)
370
+ return left;
371
+ left += Number(column.width) || 0;
372
+ }
373
+ }
374
+ return undefined;
375
+ };
376
+ return visit(columns);
377
+ };
356
378
  const toBorderWidth = (value) => {
357
379
  if (typeof value === 'number' && Number.isFinite(value)) {
358
380
  return Math.max(value, 0);
@@ -883,7 +905,7 @@ export const normalizeCellStyle = (meta) => {
883
905
  }
884
906
  return nextStyle;
885
907
  };
886
- export const createTableConfig = ({ hostHeight, darkMode = false, resizableColumns = false, resizableRows = false, copySelection, sheetDefaults, virtualState, zoomScale = 1 }) => {
908
+ export const createTableConfig = ({ hostHeight, darkMode = false, resizableColumns = false, resizableRows = false, copySelection, searchCell, sheetDefaults, virtualState, zoomScale = 1 }) => {
887
909
  const normalizedScale = normalizeZoomScale(zoomScale);
888
910
  const scaledPadding = scaleNumber(CELL_PADDING, normalizedScale);
889
911
  const scaledHeaderHeight = scaleNumber(HEADER_HEIGHT, normalizedScale);
@@ -920,7 +942,9 @@ export const createTableConfig = ({ hostHeight, darkMode = false, resizableColum
920
942
  if (getRowState(currentRow) !== RowState.Loaded) {
921
943
  return loadingStyle;
922
944
  }
923
- return scaleCellStyle(virtualState.cellCache.get(getCellCacheKey(rowIndex, colIndex, column)), normalizedScale);
945
+ const style = scaleCellStyle(virtualState.cellCache.get(getCellCacheKey(rowIndex, colIndex, column)), normalizedScale);
946
+ const match = searchCell === null || searchCell === void 0 ? void 0 : searchCell(rowIndex, getDataColumnIndex(column, colIndex));
947
+ return match ? { ...style, backgroundColor: match === 'active' ? '#ffbf47' : '#fff1a8', color: '#202124' } : style;
924
948
  };
925
949
  const renderMethod = ({ row, rowIndex, colIndex, column, value }) => {
926
950
  const currentRow = row;
@@ -938,13 +962,16 @@ export const createTableConfig = ({ hostHeight, darkMode = false, resizableColum
938
962
  const mirror = !hasRenderableValue(value)
939
963
  ? getLeftOverflowMirror(virtualState, currentRow, rowIndex, dataColIndex, normalizedScale, measureDocument)
940
964
  : undefined;
941
- const renderText = shouldRenderTextInOverlay(style, column) || !!overflowLayout || !!mirror;
965
+ const match = searchCell === null || searchCell === void 0 ? void 0 : searchCell(rowIndex, dataColIndex);
966
+ const renderText = shouldRenderTextInOverlay(style, column) || !!overflowLayout || !!mirror || !!match;
942
967
  if (!hasBorder(style) && !renderText) {
943
968
  return undefined;
944
969
  }
945
970
  return ((cellEl) => {
946
971
  const baseStyle = {
947
972
  ...(style || {}),
973
+ font: (style === null || style === void 0 ? void 0 : style.font) || getBodyFont(normalizedScale),
974
+ color: match ? '#202124' : style === null || style === void 0 ? void 0 : style.color,
948
975
  horizontalAlign: (style === null || style === void 0 ? void 0 : style.horizontalAlign) || (column === null || column === void 0 ? void 0 : column.align),
949
976
  verticalAlign: (style === null || style === void 0 ? void 0 : style.verticalAlign) || (column === null || column === void 0 ? void 0 : column.verticalAlign)
950
977
  };
@@ -952,6 +979,18 @@ export const createTableConfig = ({ hostHeight, darkMode = false, resizableColum
952
979
  ? getCollapsedBorderStyle(virtualState, rowIndex, dataColIndex, baseStyle, normalizedScale)
953
980
  : baseStyle;
954
981
  renderCellOverlay(cellEl, collapsedStyle, (mirror === null || mirror === void 0 ? void 0 : mirror.style) || collapsedStyle, mirror ? mirror.value : value, renderText, (mirror === null || mirror === void 0 ? void 0 : mirror.overflowLayout) || overflowLayout, normalizedScale);
982
+ cellEl.style.boxShadow = match === 'active' ? 'inset 0 0 0 2px #9a5700' : '';
983
+ if (match) {
984
+ cellEl.dataset.spreadsheetSearch = match;
985
+ cellEl.dataset.spreadsheetRow = `${rowIndex}`;
986
+ cellEl.dataset.spreadsheetCol = `${dataColIndex}`;
987
+ cellEl.style.background = match === 'active' ? '#ffbf47' : '#fff1a8';
988
+ }
989
+ else {
990
+ delete cellEl.dataset.spreadsheetSearch;
991
+ delete cellEl.dataset.spreadsheetRow;
992
+ delete cellEl.dataset.spreadsheetCol;
993
+ }
955
994
  });
956
995
  };
957
996
  return {
@@ -1006,6 +1045,9 @@ export const createTableConfig = ({ hostHeight, darkMode = false, resizableColum
1006
1045
  RESIZE_ROW_LINE_COLOR: EXCEL_GREEN,
1007
1046
  RESIZE_ROW_MIN_HEIGHT: scaleNumber(RESIZABLE_ROW_MIN_HEIGHT, normalizedScale),
1008
1047
  ENABLE_KEYBOARD: true,
1048
+ // The table finder only indexes loaded rows and competes with the viewer's
1049
+ // workbook-wide search shortcut. Keep one search owner for all integrations.
1050
+ ENABLE_FINDER: false,
1009
1051
  ENABLE_COPY: true,
1010
1052
  BEFORE_COPY_METHOD: copySelection
1011
1053
  ? (params) => {
@@ -1038,7 +1080,7 @@ export const createTableConfig = ({ hostHeight, darkMode = false, resizableColum
1038
1080
  const mirror = !hasRenderableValue(value)
1039
1081
  ? getLeftOverflowMirror(virtualState, currentRow, rowIndex, dataColIndex, normalizedScale, measureDocument)
1040
1082
  : undefined;
1041
- if (shouldRenderTextInOverlay(style, column) || overflowLayout || mirror) {
1083
+ if (shouldRenderTextInOverlay(style, column) || overflowLayout || mirror || (searchCell === null || searchCell === void 0 ? void 0 : searchCell(rowIndex, dataColIndex))) {
1042
1084
  return '';
1043
1085
  }
1044
1086
  if (value === null || value === undefined) {
@@ -1,8 +1,8 @@
1
1
  import { createFileViewerWorkerController, createFileViewerTranslator, createFileViewerZoomChangeEmitter as createZoomChangeEmitter, createEmptyFileViewerSearchState, registerFileViewerSearchProvider, registerFileViewerZoomProvider, resolveFileViewerColorScheme, resolveFileViewerFitScale, resolveFileViewerRuntimeAssetBaseUrl, resolveFileViewerSpreadsheetWorkerUrl, unregisterFileViewerSearchProvider, unregisterFileViewerZoomProvider, } from '@file-viewer/core';
2
2
  import { renderSpreadsheetChart } from './spreadsheet/chartRenderer.js';
3
3
  import { createSpreadsheetImageSourceResolver } from './spreadsheet/imageSource.js';
4
- import { buildRows, clampWindowStart, collectWindowStarts, createEmptyVirtualState, DEFAULT_SHEET_DEFAULTS, displayCellKey, getDataKey, INDEX_COLUMN_KEY, markWindowState, ROW_STATE_FIELD, RowState, WINDOW_SIZE, } from './spreadsheet/state.js';
5
- import { buildColumns, createTableConfig, detectIndexOffset, getDisplayColumns, 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';
4
+ import { buildRows, clampWindowStart, collectWindowStarts, createEmptyVirtualState, DEFAULT_SHEET_DEFAULTS, displayCellKey, getDataKey, getWindowStart, INDEX_COLUMN_KEY, markWindowState, ROW_STATE_FIELD, RowState, WINDOW_SIZE, } from './spreadsheet/state.js';
5
+ 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';
6
6
  const EXCEL_IMAGE_SCROLLBAR_GUARD = 18;
7
7
  const DEFAULT_SPREADSHEET_WORKER_AUTO_THRESHOLD = 1 * 1024 * 1024;
8
8
  const E_VIRT_TABLE_STYLE_MARKERS = [
@@ -669,6 +669,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
669
669
  let hasAppliedDefaultInitialFit = false;
670
670
  let searchState = createEmptyFileViewerSearchState();
671
671
  let searchMatches = [];
672
+ let searchCells = new Set();
672
673
  let searchOptions = {};
673
674
  let searchRequestSequence = 0;
674
675
  let latestSearchRequest = 0;
@@ -719,6 +720,11 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
719
720
  ? ((currentIndex % matches.length) + matches.length) % matches.length
720
721
  : -1;
721
722
  searchMatches = matches;
723
+ searchCells = new Set(matches.map(match => {
724
+ var _a;
725
+ const cell = (_a = match.anchor) === null || _a === void 0 ? void 0 : _a.spreadsheet;
726
+ return cell ? `${cell.sheetId}:${cell.row}:${cell.col}` : '';
727
+ }));
722
728
  searchState = {
723
729
  query,
724
730
  total: matches.length,
@@ -726,8 +732,18 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
726
732
  current: normalizedIndex >= 0 ? matches[normalizedIndex] : null,
727
733
  matches,
728
734
  };
735
+ table === null || table === void 0 ? void 0 : table.draw();
729
736
  return searchState;
730
737
  };
738
+ const getSearchCell = (row, col) => {
739
+ var _a, _b;
740
+ if (!searchCells.has(`${getActiveSheetId()}:${row}:${col}`))
741
+ return undefined;
742
+ const current = (_b = (_a = searchState.current) === null || _a === void 0 ? void 0 : _a.anchor) === null || _b === void 0 ? void 0 : _b.spreadsheet;
743
+ return (current === null || current === void 0 ? void 0 : current.sheetId) === getActiveSheetId() && current.row === row && current.col === col
744
+ ? 'active'
745
+ : 'match';
746
+ };
731
747
  const getHostHeight = () => tableHost.clientHeight || 0;
732
748
  const showBlockingLoading = () => !errorMessage && !hasInitialWindow && (loadingState || sheetInitializing);
733
749
  const showStreamingLoading = () => !showBlockingLoading() &&
@@ -1165,6 +1181,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1165
1181
  resizableColumns,
1166
1182
  resizableRows,
1167
1183
  copySelection: copySpreadsheetSelection,
1184
+ searchCell: getSearchCell,
1168
1185
  sheetDefaults,
1169
1186
  virtualState,
1170
1187
  zoomScale: zoom,
@@ -1222,6 +1239,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1222
1239
  resizableColumns,
1223
1240
  resizableRows,
1224
1241
  copySelection: copySpreadsheetSelection,
1242
+ searchCell: getSearchCell,
1225
1243
  sheetDefaults,
1226
1244
  virtualState,
1227
1245
  zoomScale: zoom,
@@ -1243,6 +1261,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1243
1261
  resizableColumns,
1244
1262
  resizableRows,
1245
1263
  copySelection: copySpreadsheetSelection,
1264
+ searchCell: getSearchCell,
1246
1265
  sheetDefaults,
1247
1266
  virtualState,
1248
1267
  zoomScale: zoom,
@@ -1370,8 +1389,14 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1370
1389
  if (activeSheetId !== undefined) {
1371
1390
  sheetStateCache.set(activeSheetId, virtualState);
1372
1391
  }
1373
- clearTableResizableHeaderCache();
1374
- syncTableLayout();
1392
+ // e-virt-table writes its pixel-width cache after emitting the resize event.
1393
+ // Clear it after that write so our unscaled, per-sheet widths remain authoritative.
1394
+ queueMicrotask(() => {
1395
+ if (disposed || !table)
1396
+ return;
1397
+ clearTableResizableHeaderCache();
1398
+ syncTableLayout();
1399
+ });
1375
1400
  }
1376
1401
  function handleRowResizeChange(event) {
1377
1402
  if (!resizableRows || disposed) {
@@ -1694,17 +1719,23 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1694
1719
  const pending = pendingSearchJump;
1695
1720
  if (!pending ||
1696
1721
  pending.sheetId !== getActiveSheetId() ||
1697
- !virtualState.loadedWindows.has(clampWindowStart(pending.row, virtualState.totalRows)) ||
1722
+ !virtualState.loadedWindows.has(getWindowStart(pending.row, virtualState.totalRows)) ||
1698
1723
  !table) {
1699
1724
  return;
1700
1725
  }
1701
- pendingSearchJump = null;
1702
1726
  requestAnimationFrame(() => {
1703
- if (disposed || !table) {
1727
+ if (disposed || !table || pendingSearchJump !== pending || pending.sheetId !== getActiveSheetId()) {
1704
1728
  return;
1705
1729
  }
1730
+ pendingSearchJump = null;
1706
1731
  const targetTop = Math.max(0, getSearchRowTop(pending.row) - Math.max(0, (tableHost.clientHeight || 0) * 0.35));
1707
- table.scrollTo(0, targetTop);
1732
+ // The vendor's rendered header index can still be empty before its first
1733
+ // draw. Source column geometry is ready as soon as the window is loaded.
1734
+ const columnLeft = getSearchColumnLeft(getDisplayColumns(virtualState.columns, zoom), virtualState.dataKeys[pending.col] || getDataKey(pending.col));
1735
+ const targetLeft = columnLeft === undefined
1736
+ ? table.ctx.scrollX || 0
1737
+ : Math.max(0, columnLeft - tableHost.clientWidth / 2);
1738
+ table.scrollTo(targetLeft, targetTop);
1708
1739
  table.draw();
1709
1740
  syncImageViewport();
1710
1741
  scheduleViewportLoad();
@@ -1715,7 +1746,7 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1715
1746
  if (!pending || pending.sheetId !== getActiveSheetId() || !virtualState.totalRows) {
1716
1747
  return;
1717
1748
  }
1718
- const windowStart = clampWindowStart(pending.row, virtualState.totalRows);
1749
+ const windowStart = getWindowStart(pending.row, virtualState.totalRows);
1719
1750
  if (virtualState.loadedWindows.has(windowStart)) {
1720
1751
  flushPendingSearchJump();
1721
1752
  return;
@@ -1725,10 +1756,10 @@ const renderFileViewerSpreadsheet = async (buffer, target, type, context) => {
1725
1756
  function jumpToSpreadsheetSearchMatch(match) {
1726
1757
  var _a, _b;
1727
1758
  const spreadsheet = (_a = match === null || match === void 0 ? void 0 : match.anchor) === null || _a === void 0 ? void 0 : _a.spreadsheet;
1759
+ pendingSearchJump = spreadsheet || null;
1728
1760
  if (!spreadsheet) {
1729
1761
  return;
1730
1762
  }
1731
- pendingSearchJump = spreadsheet;
1732
1763
  if (spreadsheet.sheetId !== getActiveSheetId()) {
1733
1764
  cacheCurrentSheetState();
1734
1765
  sheetIndex = spreadsheet.sheetId;