@extend-ai/react-xlsx 0.24.0 → 0.24.1
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.md +8 -4
- package/dist/{chunk-DGNSB5M5.cjs → chunk-WW6G674Q.cjs} +728 -618
- package/dist/chunk-WW6G674Q.cjs.map +1 -0
- package/dist/{chunk-C4WTJIRG.js → chunk-XUHSQ3GF.js} +146 -36
- package/dist/chunk-XUHSQ3GF.js.map +1 -0
- package/dist/index.cjs +344 -234
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +146 -36
- package/dist/index.js.map +1 -1
- package/dist/{internal-CwTqluL7.d.cts → internal-D5HReXVR.d.cts} +9 -1
- package/dist/{internal-CwTqluL7.d.ts → internal-D5HReXVR.d.ts} +9 -1
- package/dist/internal.cjs +2 -2
- package/dist/internal.d.cts +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +1 -1
- package/dist/vanilla.cjs +2 -2
- package/dist/vanilla.d.cts +2 -2
- package/dist/vanilla.d.ts +2 -2
- package/dist/vanilla.js +1 -1
- package/dist/{workbook-runtime-QFXDLSSI.cjs → workbook-runtime-7WEPIK5Y.cjs} +41 -29
- package/dist/workbook-runtime-7WEPIK5Y.cjs.map +1 -0
- package/dist/{workbook-runtime-56Y3B64Y.js → workbook-runtime-BAAYDYYK.js} +17 -5
- package/dist/workbook-runtime-BAAYDYYK.js.map +1 -0
- package/dist/{workbook-runtime-7DSKESFL.js → workbook-runtime-FCKPXLTW.js} +17 -5
- package/dist/workbook-runtime-FCKPXLTW.js.map +1 -0
- package/dist/{workbook-runtime-MEI3CEWO.cjs → workbook-runtime-MOGSEJ5R.cjs} +41 -29
- package/dist/workbook-runtime-MOGSEJ5R.cjs.map +1 -0
- package/dist/xlsx-worker.js +16 -4
- package/dist/xlsx-worker.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-C4WTJIRG.js.map +0 -1
- package/dist/chunk-DGNSB5M5.cjs.map +0 -1
- package/dist/workbook-runtime-56Y3B64Y.js.map +0 -1
- package/dist/workbook-runtime-7DSKESFL.js.map +0 -1
- package/dist/workbook-runtime-MEI3CEWO.cjs.map +0 -1
- package/dist/workbook-runtime-QFXDLSSI.cjs.map +0 -1
|
@@ -154,6 +154,80 @@ function* bandIndices(bands) {
|
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
+
// src/read-only-layout.ts
|
|
158
|
+
function changedVisibilityRanges(existing, ranges, hidden, fromSelection) {
|
|
159
|
+
if (!hidden && !existing.size) return [];
|
|
160
|
+
let firstVisible = 0;
|
|
161
|
+
if (!hidden && fromSelection) {
|
|
162
|
+
while (existing.has(firstVisible)) firstVisible++;
|
|
163
|
+
}
|
|
164
|
+
const changed = [];
|
|
165
|
+
for (const range of ranges) {
|
|
166
|
+
const start = firstVisible > 0 && range.start === firstVisible ? 0 : range.start;
|
|
167
|
+
for (let index = start; index <= range.end; index++) {
|
|
168
|
+
if (existing.has(index) !== hidden) {
|
|
169
|
+
changed.push({ start, end: range.end });
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return changed;
|
|
175
|
+
}
|
|
176
|
+
function nextVisibleIndex(index, limit, isHidden) {
|
|
177
|
+
let next = index;
|
|
178
|
+
while (next < limit && isHidden(next)) next++;
|
|
179
|
+
if (next < limit) return next;
|
|
180
|
+
next = index - 1;
|
|
181
|
+
while (next >= 0 && isHidden(next)) next--;
|
|
182
|
+
return next;
|
|
183
|
+
}
|
|
184
|
+
function visibleAxis(hidden, max, originalIndices, originalSizes, overrides, defaultSize) {
|
|
185
|
+
const indices = [];
|
|
186
|
+
const sizes = [];
|
|
187
|
+
let offset = 0;
|
|
188
|
+
for (let index = 0; index <= max; index++) {
|
|
189
|
+
const originalSize = originalIndices[offset] === index ? originalSizes[offset++] : void 0;
|
|
190
|
+
if (hidden.has(index)) continue;
|
|
191
|
+
indices.push(index);
|
|
192
|
+
sizes.push(originalSize ?? overrides[index] ?? defaultSize);
|
|
193
|
+
}
|
|
194
|
+
return { indices, sizes };
|
|
195
|
+
}
|
|
196
|
+
function applyReadOnlyLayout(sheet, layout) {
|
|
197
|
+
if (!layout) return sheet;
|
|
198
|
+
const view = { ...sheet };
|
|
199
|
+
if (layout.freezePanes !== void 0) view.freezePanes = layout.freezePanes;
|
|
200
|
+
if (layout.hiddenRows) {
|
|
201
|
+
const rows = visibleAxis(
|
|
202
|
+
layout.hiddenRows,
|
|
203
|
+
sheet.maxUsedRow,
|
|
204
|
+
sheet.visibleRows,
|
|
205
|
+
sheet.rowHeights,
|
|
206
|
+
sheet.rowHeightOverridesPx,
|
|
207
|
+
sheet.defaultRowHeightPx
|
|
208
|
+
);
|
|
209
|
+
view.hiddenRows = Array.from(layout.hiddenRows).sort((a, b) => a - b);
|
|
210
|
+
view.visibleRows = rows.indices;
|
|
211
|
+
view.rowHeights = rows.sizes;
|
|
212
|
+
view.rowCount = rows.indices.length;
|
|
213
|
+
}
|
|
214
|
+
if (layout.hiddenCols) {
|
|
215
|
+
const cols = visibleAxis(
|
|
216
|
+
layout.hiddenCols,
|
|
217
|
+
sheet.maxUsedCol,
|
|
218
|
+
sheet.visibleCols,
|
|
219
|
+
sheet.colWidths,
|
|
220
|
+
sheet.colWidthOverridesPx,
|
|
221
|
+
sheet.defaultColWidthPx
|
|
222
|
+
);
|
|
223
|
+
view.hiddenCols = Array.from(layout.hiddenCols).sort((a, b) => a - b);
|
|
224
|
+
view.visibleCols = cols.indices;
|
|
225
|
+
view.colWidths = cols.sizes;
|
|
226
|
+
view.colCount = cols.indices.length;
|
|
227
|
+
}
|
|
228
|
+
return view;
|
|
229
|
+
}
|
|
230
|
+
|
|
157
231
|
// src/merged-range-lookup.ts
|
|
158
232
|
function createMergedRangeLookup(ranges) {
|
|
159
233
|
const normalizedRanges = [];
|
|
@@ -1069,7 +1143,7 @@ var XlsxWorkerClient = class {
|
|
|
1069
1143
|
}
|
|
1070
1144
|
async getMainRuntime() {
|
|
1071
1145
|
if (this.disposed) throw createAbortError();
|
|
1072
|
-
this.mainRuntime ??= import("./workbook-runtime-
|
|
1146
|
+
this.mainRuntime ??= import("./workbook-runtime-FCKPXLTW.js").then(({ createWorkbookRuntime }) => createWorkbookRuntime());
|
|
1073
1147
|
const runtime = await this.mainRuntime;
|
|
1074
1148
|
if (this.disposed) {
|
|
1075
1149
|
runtime.dispose();
|
|
@@ -2045,6 +2119,8 @@ function downloadUrl(src, fileName) {
|
|
|
2045
2119
|
}
|
|
2046
2120
|
function useXlsxViewerController(options2) {
|
|
2047
2121
|
const {
|
|
2122
|
+
allowFreezeInReadOnly = false,
|
|
2123
|
+
allowHideInReadOnly = false,
|
|
2048
2124
|
allowResizeInReadOnly = false,
|
|
2049
2125
|
deferLoadingAboveBytes = DEFAULT_DEFER_LOADING_ABOVE_BYTES,
|
|
2050
2126
|
file,
|
|
@@ -2063,7 +2139,8 @@ function useXlsxViewerController(options2) {
|
|
|
2063
2139
|
const [isLoading, setIsLoading] = d(Boolean(file ?? src));
|
|
2064
2140
|
const [error, setError] = d(null);
|
|
2065
2141
|
const [workbook, setWorkbook] = d(null);
|
|
2066
|
-
const [
|
|
2142
|
+
const [readOnlyLayouts, setReadOnlyLayouts] = d({});
|
|
2143
|
+
const [workbookSheets, setSheets] = d([]);
|
|
2067
2144
|
const [chartsByWorkbookSheetIndex, setChartsByWorkbookSheetIndex] = d([]);
|
|
2068
2145
|
const [chartsheets, setChartsheets] = d([]);
|
|
2069
2146
|
const [tabs, setTabs] = d([]);
|
|
@@ -2118,6 +2195,7 @@ function useXlsxViewerController(options2) {
|
|
|
2118
2195
|
const displayFileName = T(() => resolveDisplayFileName(src, fileName), [fileName, src]);
|
|
2119
2196
|
const shouldDeferLoading = deferLoadingAboveBytes > 0;
|
|
2120
2197
|
const readOnly = requestedReadOnly || forcedReadOnly;
|
|
2198
|
+
const sheets = T(() => readOnly ? workbookSheets.map((sheet) => applyReadOnlyLayout(sheet, readOnlyLayouts[sheet.workbookSheetIndex])) : workbookSheets, [readOnly, readOnlyLayouts, workbookSheets]);
|
|
2121
2199
|
const drawingMutationEpoch = A(0);
|
|
2122
2200
|
const drawingMutationState = A({ workbook, revision, readOnly, activeCell, activeSheetIndex });
|
|
2123
2201
|
drawingMutationState.current = { workbook, revision, readOnly, activeCell, activeSheetIndex };
|
|
@@ -2279,6 +2357,7 @@ function useXlsxViewerController(options2) {
|
|
|
2279
2357
|
}, [disposeWorkerClient]);
|
|
2280
2358
|
h(() => {
|
|
2281
2359
|
loadGenerationRef.current += 1;
|
|
2360
|
+
setReadOnlyLayouts({});
|
|
2282
2361
|
if (!file && !src) {
|
|
2283
2362
|
disposeWorkerClient();
|
|
2284
2363
|
setForcedReadOnly(false);
|
|
@@ -3570,28 +3649,50 @@ function useXlsxViewerController(options2) {
|
|
|
3570
3649
|
}));
|
|
3571
3650
|
setRevision((current) => current + 1);
|
|
3572
3651
|
}, [activeSheet]);
|
|
3652
|
+
const canChangeVisibility = Boolean(activeSheet && !isLoading && (readOnly ? allowHideInReadOnly : workbook));
|
|
3653
|
+
const canChangeFreezePanes = Boolean(activeSheet && !isLoading && (readOnly ? allowFreezeInReadOnly : workbook));
|
|
3654
|
+
const activeLayout = activeSheet && readOnly ? readOnlyLayouts[activeSheet.workbookSheetIndex] : void 0;
|
|
3655
|
+
h(() => {
|
|
3656
|
+
if (!activeCell || !activeLayout) return;
|
|
3657
|
+
const { hiddenRows, hiddenCols } = activeLayout;
|
|
3658
|
+
const row3 = hiddenRows?.has(activeCell.row) ? nextVisibleIndex(activeCell.row, XLSX_MAX_ROWS, (index) => hiddenRows.has(index)) : activeCell.row;
|
|
3659
|
+
const col = hiddenCols?.has(activeCell.col) ? nextVisibleIndex(activeCell.col, XLSX_MAX_COLUMNS, (index) => hiddenCols.has(index)) : activeCell.col;
|
|
3660
|
+
if (row3 === activeCell.row && col === activeCell.col) return;
|
|
3661
|
+
const cell = row3 < 0 || col < 0 ? null : { row: row3, col };
|
|
3662
|
+
setActiveCell(cell);
|
|
3663
|
+
setSelection(cell && { start: cell, end: cell });
|
|
3664
|
+
selectionAnchorRef.current = cell;
|
|
3665
|
+
}, [activeCell, activeLayout, setSelection]);
|
|
3573
3666
|
const setAxisHidden = q((axis, hidden, start, end = start) => {
|
|
3574
|
-
if (
|
|
3667
|
+
if (!canChangeVisibility || !activeSheet) return;
|
|
3575
3668
|
const limit = axis === "row" ? XLSX_MAX_ROWS : XLSX_MAX_COLUMNS;
|
|
3576
|
-
const
|
|
3669
|
+
const fromSelection = start === void 0 && end === void 0;
|
|
3670
|
+
const ranges = fromSelection ? selectionRanges.map((area) => ({ start: area.start[axis], end: area.end[axis] })) : [{ start: start ?? -1, end: end ?? -1 }];
|
|
3577
3671
|
if (!ranges.length || ranges.some((range) => !Number.isInteger(range.start) || !Number.isInteger(range.end) || range.start < 0 || range.end < range.start || range.end >= limit)) return;
|
|
3578
|
-
const
|
|
3579
|
-
|
|
3580
|
-
const
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3672
|
+
const sheetIndex = activeSheet.workbookSheetIndex;
|
|
3673
|
+
if (readOnly) {
|
|
3674
|
+
const key = axis === "row" ? "hiddenRows" : "hiddenCols";
|
|
3675
|
+
setReadOnlyLayouts((current) => {
|
|
3676
|
+
const layout = current[sheetIndex];
|
|
3677
|
+
const existing = layout?.[key] ?? new Set(activeSheet[key]);
|
|
3678
|
+
const changes = changedVisibilityRanges(existing, ranges, hidden, fromSelection);
|
|
3679
|
+
if (!changes.length) return current;
|
|
3680
|
+
const next = new Set(existing);
|
|
3681
|
+
for (const range of changes) {
|
|
3682
|
+
for (let index = range.start; index <= range.end; index++) {
|
|
3683
|
+
if (hidden) next.add(index);
|
|
3684
|
+
else next.delete(index);
|
|
3685
|
+
}
|
|
3592
3686
|
}
|
|
3593
|
-
return
|
|
3687
|
+
return { ...current, [sheetIndex]: { ...layout, [key]: next } };
|
|
3594
3688
|
});
|
|
3689
|
+
return;
|
|
3690
|
+
}
|
|
3691
|
+
if (!workbook) return;
|
|
3692
|
+
const worksheet = workbook.getSheet(sheetIndex);
|
|
3693
|
+
try {
|
|
3694
|
+
const existing = new Set(axis === "row" ? worksheet.hiddenRows : worksheet.hiddenColumns);
|
|
3695
|
+
const changes = changedVisibilityRanges(existing, ranges, hidden, fromSelection);
|
|
3595
3696
|
if (!changes.length) return;
|
|
3596
3697
|
recordHistoryBeforeMutation();
|
|
3597
3698
|
for (const range of changes) {
|
|
@@ -3599,13 +3700,11 @@ function useXlsxViewerController(options2) {
|
|
|
3599
3700
|
else worksheet.setColumnsHidden(range.start, range.end, hidden);
|
|
3600
3701
|
}
|
|
3601
3702
|
if (hidden && activeCell && changes.some((range) => range.start <= activeCell[axis] && activeCell[axis] <= range.end)) {
|
|
3602
|
-
const
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
while (index >= 0 && isHidden(index)) index--;
|
|
3608
|
-
}
|
|
3703
|
+
const index = nextVisibleIndex(
|
|
3704
|
+
activeCell[axis],
|
|
3705
|
+
limit,
|
|
3706
|
+
(value) => axis === "row" ? worksheet.isRowHidden(value) : worksheet.isColumnHidden(value)
|
|
3707
|
+
);
|
|
3609
3708
|
if (index >= 0) {
|
|
3610
3709
|
const cell = { ...activeCell, [axis]: index };
|
|
3611
3710
|
setActiveCell(cell);
|
|
@@ -3617,16 +3716,23 @@ function useXlsxViewerController(options2) {
|
|
|
3617
3716
|
} finally {
|
|
3618
3717
|
worksheet.free();
|
|
3619
3718
|
}
|
|
3620
|
-
}, [activeCell, activeSheet, readOnly, recordHistoryBeforeMutation, refreshWorkbookState, selectionRanges, setSelection, workbook]);
|
|
3719
|
+
}, [activeCell, activeSheet, canChangeVisibility, readOnly, recordHistoryBeforeMutation, refreshWorkbookState, selectionRanges, setSelection, workbook]);
|
|
3621
3720
|
const hideRows = q((start, end) => setAxisHidden("row", true, start, end), [setAxisHidden]);
|
|
3622
3721
|
const unhideRows = q((start, end) => setAxisHidden("row", false, start, end), [setAxisHidden]);
|
|
3623
3722
|
const hideColumns = q((start, end) => setAxisHidden("col", true, start, end), [setAxisHidden]);
|
|
3624
3723
|
const unhideColumns = q((start, end) => setAxisHidden("col", false, start, end), [setAxisHidden]);
|
|
3625
3724
|
const setFreezeBoundary = q((cell) => {
|
|
3626
|
-
if (
|
|
3725
|
+
if (!canChangeFreezePanes || !activeSheet) return;
|
|
3627
3726
|
const { row: row3, col } = cell;
|
|
3628
3727
|
if (!Number.isInteger(row3) || row3 < 0 || row3 >= XLSX_MAX_ROWS || !Number.isInteger(col) || col < 0 || col >= XLSX_MAX_COLUMNS) return;
|
|
3629
|
-
const
|
|
3728
|
+
const sheetIndex = activeSheet.workbookSheetIndex;
|
|
3729
|
+
if (readOnly) {
|
|
3730
|
+
const freezePanes2 = row3 || col ? { row: row3, col } : null;
|
|
3731
|
+
setReadOnlyLayouts((current) => ({ ...current, [sheetIndex]: { ...current[sheetIndex], freezePanes: freezePanes2 } }));
|
|
3732
|
+
return;
|
|
3733
|
+
}
|
|
3734
|
+
if (!workbook) return;
|
|
3735
|
+
const worksheet = workbook.getSheet(sheetIndex);
|
|
3630
3736
|
try {
|
|
3631
3737
|
const current = parseWorksheetFreezePanes(worksheet);
|
|
3632
3738
|
if (row3 === (current?.row ?? 0) && col === (current?.col ?? 0)) return;
|
|
@@ -3636,9 +3742,9 @@ function useXlsxViewerController(options2) {
|
|
|
3636
3742
|
} finally {
|
|
3637
3743
|
worksheet.free();
|
|
3638
3744
|
}
|
|
3639
|
-
}, [activeSheet, readOnly, recordHistoryBeforeMutation, refreshWorkbookState, workbook]);
|
|
3745
|
+
}, [activeSheet, canChangeFreezePanes, readOnly, recordHistoryBeforeMutation, refreshWorkbookState, workbook]);
|
|
3640
3746
|
const freezeCell = resolveFreezePanesCell(activeCell, selection);
|
|
3641
|
-
const canFreezePanes = Boolean(
|
|
3747
|
+
const canFreezePanes = Boolean(canChangeFreezePanes && freezeCell && (freezeCell.row > 0 || freezeCell.col > 0));
|
|
3642
3748
|
const freezePanes = q((cell = freezeCell) => {
|
|
3643
3749
|
if (cell) setFreezeBoundary(cell);
|
|
3644
3750
|
}, [freezeCell, setFreezeBoundary]);
|
|
@@ -4929,6 +5035,8 @@ function useXlsxViewerController(options2) {
|
|
|
4929
5035
|
resizeChartBy,
|
|
4930
5036
|
resizeImageBy,
|
|
4931
5037
|
frozenPanes: activeSheet?.freezePanes ?? null,
|
|
5038
|
+
canChangeFreezePanes,
|
|
5039
|
+
canChangeVisibility,
|
|
4932
5040
|
canFreezePanes,
|
|
4933
5041
|
hideRows,
|
|
4934
5042
|
unhideRows,
|
|
@@ -5081,6 +5189,8 @@ function useXlsxViewerController(options2) {
|
|
|
5081
5189
|
revision,
|
|
5082
5190
|
resizeChartBy,
|
|
5083
5191
|
resizeImageBy,
|
|
5192
|
+
canChangeFreezePanes,
|
|
5193
|
+
canChangeVisibility,
|
|
5084
5194
|
canFreezePanes,
|
|
5085
5195
|
hideRows,
|
|
5086
5196
|
unhideRows,
|
|
@@ -7681,7 +7791,7 @@ function XlsxContextMenu({
|
|
|
7681
7791
|
label: `${row3 ? messages.rowHeight : messages.columnWidth}\u2026`,
|
|
7682
7792
|
separatorBefore: true
|
|
7683
7793
|
}] : [],
|
|
7684
|
-
|
|
7794
|
+
...controller.canChangeVisibility ?? !controller.readOnly ? [
|
|
7685
7795
|
{ id: row3 ? "hideRows" : "hideColumns", label: messages.hide, separatorBefore: !canResize },
|
|
7686
7796
|
{ id: row3 ? "unhideRows" : "unhideColumns", label: messages.unhide }
|
|
7687
7797
|
] : []
|
|
@@ -15542,7 +15652,7 @@ function XlsxGrid({
|
|
|
15542
15652
|
);
|
|
15543
15653
|
if (worksheet) {
|
|
15544
15654
|
for (let col = 0; col < displayColLimit; col += 1) {
|
|
15545
|
-
if (
|
|
15655
|
+
if (hiddenColSet.has(col)) {
|
|
15546
15656
|
continue;
|
|
15547
15657
|
}
|
|
15548
15658
|
const width = worksheet.getColumnWidth(col);
|
|
@@ -15642,7 +15752,7 @@ function XlsxGrid({
|
|
|
15642
15752
|
estimatedHeights.set(row3, estimatedHeight);
|
|
15643
15753
|
}
|
|
15644
15754
|
for (let row3 = 0; row3 < displayRowLimit; row3 += 1) {
|
|
15645
|
-
if (
|
|
15755
|
+
if (hiddenRowSet.has(row3)) continue;
|
|
15646
15756
|
const height = worksheet.getRowHeight(row3);
|
|
15647
15757
|
if (height !== void 0 && height !== null) {
|
|
15648
15758
|
heights[row3] = Math.max(
|
|
@@ -22238,7 +22348,7 @@ function XlsxGrid({
|
|
|
22238
22348
|
}
|
|
22239
22349
|
return;
|
|
22240
22350
|
}
|
|
22241
|
-
if (!readOnly && !selectedChart && !selectedImage && event.ctrlKey && !event.metaKey && !event.altKey) {
|
|
22351
|
+
if ((controller.canChangeVisibility ?? !readOnly) && !selectedChart && !selectedImage && event.ctrlKey && !event.metaKey && !event.altKey) {
|
|
22242
22352
|
if (event.code === "Digit9" || event.code === "Digit0") {
|
|
22243
22353
|
event.preventDefault();
|
|
22244
22354
|
if (event.code === "Digit9") {
|
|
@@ -23839,4 +23949,4 @@ export {
|
|
|
23839
23949
|
__createContentNode,
|
|
23840
23950
|
__createContentRoot
|
|
23841
23951
|
};
|
|
23842
|
-
//# sourceMappingURL=chunk-
|
|
23952
|
+
//# sourceMappingURL=chunk-XUHSQ3GF.js.map
|