@extend-ai/react-xlsx 0.8.1 → 0.8.2
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/dist/index.cjs +124 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +124 -21
- package/dist/index.js.map +1 -1
- package/dist/xlsx-worker.js +85 -8
- package/dist/xlsx-worker.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -6309,6 +6309,84 @@ function resizeImageRect(rect, handle, deltaX, deltaY, minimumSize = 16) {
|
|
|
6309
6309
|
return { height, left, top, width };
|
|
6310
6310
|
}
|
|
6311
6311
|
|
|
6312
|
+
// src/safe-calculate.ts
|
|
6313
|
+
var SHEET_REF_REGEX = /'((?:[^']|'')+)'!|([A-Za-z_\u0080-\uFFFF][\w.\u0080-\uFFFF]*)!/g;
|
|
6314
|
+
function collectReferencedSheetNames(workbook) {
|
|
6315
|
+
const referenced = /* @__PURE__ */ new Set();
|
|
6316
|
+
for (let sheetIdx = 0; sheetIdx < workbook.sheetCount; sheetIdx += 1) {
|
|
6317
|
+
let sheet;
|
|
6318
|
+
try {
|
|
6319
|
+
sheet = workbook.getSheet(sheetIdx);
|
|
6320
|
+
} catch {
|
|
6321
|
+
continue;
|
|
6322
|
+
}
|
|
6323
|
+
const cells = sheet.formulaCells;
|
|
6324
|
+
if (!Array.isArray(cells)) {
|
|
6325
|
+
continue;
|
|
6326
|
+
}
|
|
6327
|
+
for (const cell of cells) {
|
|
6328
|
+
const formula = cell?.formula;
|
|
6329
|
+
if (!formula) {
|
|
6330
|
+
continue;
|
|
6331
|
+
}
|
|
6332
|
+
SHEET_REF_REGEX.lastIndex = 0;
|
|
6333
|
+
let match;
|
|
6334
|
+
while ((match = SHEET_REF_REGEX.exec(formula)) !== null) {
|
|
6335
|
+
const raw = match[1] ?? match[2];
|
|
6336
|
+
if (!raw) {
|
|
6337
|
+
continue;
|
|
6338
|
+
}
|
|
6339
|
+
referenced.add(raw.replace(/''/g, "'"));
|
|
6340
|
+
}
|
|
6341
|
+
}
|
|
6342
|
+
}
|
|
6343
|
+
return referenced;
|
|
6344
|
+
}
|
|
6345
|
+
function hasUnresolvedSheetReferences(workbook) {
|
|
6346
|
+
let names;
|
|
6347
|
+
try {
|
|
6348
|
+
names = workbook.sheetNames;
|
|
6349
|
+
} catch {
|
|
6350
|
+
return false;
|
|
6351
|
+
}
|
|
6352
|
+
const known = new Set(names);
|
|
6353
|
+
const referenced = collectReferencedSheetNames(workbook);
|
|
6354
|
+
for (const name of referenced) {
|
|
6355
|
+
if (!known.has(name)) {
|
|
6356
|
+
return true;
|
|
6357
|
+
}
|
|
6358
|
+
}
|
|
6359
|
+
return false;
|
|
6360
|
+
}
|
|
6361
|
+
function safeCalculate(workbook, options = {}) {
|
|
6362
|
+
if (hasUnresolvedSheetReferences(workbook)) {
|
|
6363
|
+
return { workbook, calculated: false, skipReason: "unresolved-sheet-refs" };
|
|
6364
|
+
}
|
|
6365
|
+
try {
|
|
6366
|
+
workbook.calculate();
|
|
6367
|
+
return { workbook, calculated: true, skipReason: null };
|
|
6368
|
+
} catch (err) {
|
|
6369
|
+
console.warn("[react-xlsx] workbook.calculate() trapped; falling back to cached formula values", err);
|
|
6370
|
+
if (options.reparse) {
|
|
6371
|
+
try {
|
|
6372
|
+
return { workbook: options.reparse(), calculated: false, skipReason: "calculate-trapped" };
|
|
6373
|
+
} catch (reparseErr) {
|
|
6374
|
+
console.warn("[react-xlsx] workbook reparse after calculate trap failed", reparseErr);
|
|
6375
|
+
}
|
|
6376
|
+
}
|
|
6377
|
+
return { workbook, calculated: false, skipReason: "calculate-trapped" };
|
|
6378
|
+
}
|
|
6379
|
+
}
|
|
6380
|
+
function tryRecalculate(workbook) {
|
|
6381
|
+
try {
|
|
6382
|
+
workbook.calculate();
|
|
6383
|
+
return { calculated: true, error: null };
|
|
6384
|
+
} catch (err) {
|
|
6385
|
+
console.warn("[react-xlsx] workbook.calculate() trapped during recalculation", err);
|
|
6386
|
+
return { calculated: false, error: err };
|
|
6387
|
+
}
|
|
6388
|
+
}
|
|
6389
|
+
|
|
6312
6390
|
// src/wasm.ts
|
|
6313
6391
|
var wasmModulePromise = null;
|
|
6314
6392
|
function getSheetsWasmModule() {
|
|
@@ -7117,18 +7195,21 @@ async function resolveWorkbookBuffer({ file, src }, signal) {
|
|
|
7117
7195
|
}
|
|
7118
7196
|
async function parseWorkbookBuffer(buffer) {
|
|
7119
7197
|
const wasmModule = await getSheetsWasmModule();
|
|
7120
|
-
const
|
|
7198
|
+
const initialWorkbook = wasmModule.Workbook.fromBytes(new Uint8Array(buffer));
|
|
7121
7199
|
let totalFormulas = 0;
|
|
7122
|
-
for (let index = 0; index <
|
|
7123
|
-
totalFormulas +=
|
|
7200
|
+
for (let index = 0; index < initialWorkbook.sheetCount; index += 1) {
|
|
7201
|
+
totalFormulas += initialWorkbook.getSheet(index).formulaCount;
|
|
7124
7202
|
}
|
|
7125
7203
|
const shouldAutoCalculate = totalFormulas <= FORMULA_COUNT_THRESHOLD;
|
|
7126
|
-
if (shouldAutoCalculate) {
|
|
7127
|
-
workbook
|
|
7204
|
+
if (!shouldAutoCalculate) {
|
|
7205
|
+
return { shouldAutoCalculate, workbook: initialWorkbook };
|
|
7128
7206
|
}
|
|
7207
|
+
const result = safeCalculate(initialWorkbook, {
|
|
7208
|
+
reparse: () => wasmModule.Workbook.fromBytes(new Uint8Array(buffer))
|
|
7209
|
+
});
|
|
7129
7210
|
return {
|
|
7130
|
-
shouldAutoCalculate,
|
|
7131
|
-
workbook
|
|
7211
|
+
shouldAutoCalculate: result.calculated,
|
|
7212
|
+
workbook: result.workbook
|
|
7132
7213
|
};
|
|
7133
7214
|
}
|
|
7134
7215
|
function scheduleLowPriorityTask(task) {
|
|
@@ -8369,7 +8450,10 @@ function useXlsxViewerController(options) {
|
|
|
8369
8450
|
if (!shouldAutoCalculate) {
|
|
8370
8451
|
return;
|
|
8371
8452
|
}
|
|
8372
|
-
targetWorkbook
|
|
8453
|
+
const result = tryRecalculate(targetWorkbook);
|
|
8454
|
+
if (!result.calculated) {
|
|
8455
|
+
setShouldAutoCalculate(false);
|
|
8456
|
+
}
|
|
8373
8457
|
}, [shouldAutoCalculate]);
|
|
8374
8458
|
const getActiveWorksheet = React.useCallback(() => {
|
|
8375
8459
|
if (!workbook || !activeSheet) {
|
|
@@ -9006,8 +9090,12 @@ function useXlsxViewerController(options) {
|
|
|
9006
9090
|
if (!workbook) {
|
|
9007
9091
|
return;
|
|
9008
9092
|
}
|
|
9009
|
-
workbook
|
|
9010
|
-
|
|
9093
|
+
const result = tryRecalculate(workbook);
|
|
9094
|
+
if (result.calculated) {
|
|
9095
|
+
refreshWorkbookState(workbook);
|
|
9096
|
+
return;
|
|
9097
|
+
}
|
|
9098
|
+
setShouldAutoCalculate(false);
|
|
9011
9099
|
}, [refreshWorkbookState, workbook]);
|
|
9012
9100
|
const resizeColumn = React.useCallback((col, widthPx) => {
|
|
9013
9101
|
if (readOnly && !canResizeReadOnly || !workbook || !activeSheet) {
|
|
@@ -20491,6 +20579,7 @@ function GridRow({
|
|
|
20491
20579
|
actualRow,
|
|
20492
20580
|
editingCell,
|
|
20493
20581
|
editingValue,
|
|
20582
|
+
frozenRowHeaderZIndex,
|
|
20494
20583
|
getCellData,
|
|
20495
20584
|
headerLabelLiveScale,
|
|
20496
20585
|
leadingSpacerWidth,
|
|
@@ -20507,6 +20596,7 @@ function GridRow({
|
|
|
20507
20596
|
readOnly,
|
|
20508
20597
|
renderCellAdornment,
|
|
20509
20598
|
rowHeight,
|
|
20599
|
+
rowHeaderZIndex,
|
|
20510
20600
|
rowHeaderWidth,
|
|
20511
20601
|
stickyLeftByCol,
|
|
20512
20602
|
stickyTop,
|
|
@@ -20539,7 +20629,7 @@ function GridRow({
|
|
|
20539
20629
|
textAlign: "center",
|
|
20540
20630
|
userSelect: "none",
|
|
20541
20631
|
width: rowHeaderWidth,
|
|
20542
|
-
zIndex: stickyTop !== void 0 ?
|
|
20632
|
+
zIndex: stickyTop !== void 0 ? frozenRowHeaderZIndex : rowHeaderZIndex
|
|
20543
20633
|
},
|
|
20544
20634
|
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { position: "relative" }, children: [
|
|
20545
20635
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
@@ -22348,7 +22438,7 @@ function XlsxGrid({
|
|
|
22348
22438
|
const geometryCell = resolvePointerCellFromGeometry(clientX, clientY);
|
|
22349
22439
|
const hitCell = resolvePointerCellFromHitTest(clientX, clientY);
|
|
22350
22440
|
const actualRow = hitCell && rowIndexByActual.has(hitCell.row) ? hitCell.row : geometryCell?.row;
|
|
22351
|
-
const actualCol =
|
|
22441
|
+
const actualCol = hitCell?.col ?? geometryCell?.col;
|
|
22352
22442
|
if (actualRow === void 0 || actualCol === void 0) {
|
|
22353
22443
|
return null;
|
|
22354
22444
|
}
|
|
@@ -25003,7 +25093,7 @@ function XlsxGrid({
|
|
|
25003
25093
|
paneContext.textBaseline = "middle";
|
|
25004
25094
|
paneContext.fillText(`${row.actualRow + 1}`, rowHeaderWidth / 2, row.localTop + row.height / 2);
|
|
25005
25095
|
}
|
|
25006
|
-
cornerContext.fillStyle = palette.
|
|
25096
|
+
cornerContext.fillStyle = palette.headerSurface;
|
|
25007
25097
|
cornerContext.fillRect(0, 0, rowHeaderWidth, headerHeight);
|
|
25008
25098
|
cornerContext.strokeStyle = palette.border;
|
|
25009
25099
|
cornerContext.lineWidth = 1;
|
|
@@ -25286,7 +25376,18 @@ function XlsxGrid({
|
|
|
25286
25376
|
const canvasSelectionTransition = shouldAnimateCanvasSelection ? "left 120ms cubic-bezier(0.22, 1, 0.36, 1), top 120ms cubic-bezier(0.22, 1, 0.36, 1), width 120ms cubic-bezier(0.22, 1, 0.36, 1), height 120ms cubic-bezier(0.22, 1, 0.36, 1), opacity 100ms linear" : "none";
|
|
25287
25377
|
const rowColSpan = renderedCols.length + 1 + (leadingColumnSpacerWidth > 0 ? 1 : 0) + (trailingColumnSpacerWidth > 0 ? 1 : 0);
|
|
25288
25378
|
const gutterSeparatorShadow = `inset -1px 0 0 ${palette.border}, inset 0 -1px 0 ${palette.border}`;
|
|
25289
|
-
const
|
|
25379
|
+
const maxDrawingOverlayZIndex = Math.max(
|
|
25380
|
+
0,
|
|
25381
|
+
...shapes.map((shape) => shape.zIndex + 20),
|
|
25382
|
+
...formControls.map((control) => control.zIndex + 20),
|
|
25383
|
+
...images.map((image) => image.zIndex + 22),
|
|
25384
|
+
...charts.map((chart) => chart.zIndex + 22)
|
|
25385
|
+
);
|
|
25386
|
+
const rowHeaderOverlayZIndex = Math.max(35, maxDrawingOverlayZIndex + 1);
|
|
25387
|
+
const canvasHeaderOverlayZIndex = Math.max(50, rowHeaderOverlayZIndex + 1);
|
|
25388
|
+
const stickyHeaderOverlayZIndex = canvasHeaderOverlayZIndex + 1;
|
|
25389
|
+
const cornerHeaderOverlayZIndex = canvasHeaderOverlayZIndex + 2;
|
|
25390
|
+
const frozenRowHeaderOverlayZIndex = rowHeaderOverlayZIndex;
|
|
25290
25391
|
const headerCellStyle = scaleCssProperties({
|
|
25291
25392
|
backgroundColor: palette.headerSurface,
|
|
25292
25393
|
borderBottom: "none",
|
|
@@ -25303,7 +25404,7 @@ function XlsxGrid({
|
|
|
25303
25404
|
top: 0,
|
|
25304
25405
|
userSelect: "none",
|
|
25305
25406
|
whiteSpace: "nowrap",
|
|
25306
|
-
zIndex:
|
|
25407
|
+
zIndex: canvasHeaderOverlayZIndex
|
|
25307
25408
|
}, zoomFactor);
|
|
25308
25409
|
const columnResizeHandleStyle = scaleCssProperties({
|
|
25309
25410
|
backgroundColor: "transparent",
|
|
@@ -25392,7 +25493,7 @@ function XlsxGrid({
|
|
|
25392
25493
|
display: topFrozenHeaderCanvasWidth > 0 && drawingViewport.height > 0 ? "block" : "none",
|
|
25393
25494
|
left: displayRowHeaderWidth,
|
|
25394
25495
|
top: 0,
|
|
25395
|
-
zIndex:
|
|
25496
|
+
zIndex: stickyHeaderOverlayZIndex
|
|
25396
25497
|
};
|
|
25397
25498
|
const canvasTopScrollHeaderStyle = {
|
|
25398
25499
|
...canvasHeaderBaseStyle,
|
|
@@ -25406,7 +25507,7 @@ function XlsxGrid({
|
|
|
25406
25507
|
display: leftFrozenHeaderCanvasHeight > 0 && drawingViewport.width > 0 ? "block" : "none",
|
|
25407
25508
|
left: 0,
|
|
25408
25509
|
top: displayHeaderHeight,
|
|
25409
|
-
zIndex:
|
|
25510
|
+
zIndex: stickyHeaderOverlayZIndex
|
|
25410
25511
|
};
|
|
25411
25512
|
const canvasLeftScrollHeaderStyle = {
|
|
25412
25513
|
...canvasHeaderBaseStyle,
|
|
@@ -25422,7 +25523,7 @@ function XlsxGrid({
|
|
|
25422
25523
|
position: "absolute",
|
|
25423
25524
|
top: 0,
|
|
25424
25525
|
transformOrigin: "0 0",
|
|
25425
|
-
zIndex:
|
|
25526
|
+
zIndex: cornerHeaderOverlayZIndex
|
|
25426
25527
|
};
|
|
25427
25528
|
const editingOverlayRect = experimentalCanvas && editingCell ? resolveCellDisplayRect(editingCell) : null;
|
|
25428
25529
|
const activeCellAdornment = experimentalCanvas && activeCell ? renderCellAdornment(activeCell) : null;
|
|
@@ -26756,7 +26857,7 @@ function XlsxGrid({
|
|
|
26756
26857
|
)),
|
|
26757
26858
|
trailingColumnSpacerWidth > 0 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("col", { style: { width: trailingColumnSpacerWidth } }) : null
|
|
26758
26859
|
] }),
|
|
26759
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("thead", { style: { position: "sticky", top: 0, zIndex:
|
|
26860
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("thead", { style: { position: "sticky", top: 0, zIndex: canvasHeaderOverlayZIndex }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("tr", { children: [
|
|
26760
26861
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
26761
26862
|
"th",
|
|
26762
26863
|
{
|
|
@@ -26765,7 +26866,7 @@ function XlsxGrid({
|
|
|
26765
26866
|
backgroundColor: palette.headerSurface,
|
|
26766
26867
|
left: 0,
|
|
26767
26868
|
width: displayRowHeaderWidth,
|
|
26768
|
-
zIndex:
|
|
26869
|
+
zIndex: cornerHeaderOverlayZIndex
|
|
26769
26870
|
}
|
|
26770
26871
|
}
|
|
26771
26872
|
),
|
|
@@ -26779,7 +26880,7 @@ function XlsxGrid({
|
|
|
26779
26880
|
style: {
|
|
26780
26881
|
...headerCellStyle,
|
|
26781
26882
|
left: stickyLeftByCol.get(column.actualCol),
|
|
26782
|
-
zIndex: stickyLeftByCol.has(column.actualCol) ?
|
|
26883
|
+
zIndex: stickyLeftByCol.has(column.actualCol) ? stickyHeaderOverlayZIndex : headerCellStyle.zIndex
|
|
26783
26884
|
},
|
|
26784
26885
|
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { position: "relative" }, children: [
|
|
26785
26886
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
@@ -26834,6 +26935,7 @@ function XlsxGrid({
|
|
|
26834
26935
|
actualRow,
|
|
26835
26936
|
editingCell,
|
|
26836
26937
|
editingValue,
|
|
26938
|
+
frozenRowHeaderZIndex: frozenRowHeaderOverlayZIndex,
|
|
26837
26939
|
getCellData,
|
|
26838
26940
|
leadingSpacerWidth: leadingColumnSpacerWidth,
|
|
26839
26941
|
onCellClick: handleCellClick,
|
|
@@ -26850,6 +26952,7 @@ function XlsxGrid({
|
|
|
26850
26952
|
readOnly,
|
|
26851
26953
|
renderCellAdornment,
|
|
26852
26954
|
rowHeight: virtualRow.size,
|
|
26955
|
+
rowHeaderZIndex: rowHeaderOverlayZIndex,
|
|
26853
26956
|
rowHeaderWidth: displayRowHeaderWidth,
|
|
26854
26957
|
stickyLeftByCol,
|
|
26855
26958
|
stickyTop: stickyTopByRow.get(actualRow),
|