@extend-ai/react-xlsx 0.13.4 → 0.14.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 +47 -0
- package/dist/duke_sheets_wasm_bg.wasm +0 -0
- package/dist/index.cjs +1060 -212
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +173 -1
- package/dist/index.d.ts +173 -1
- package/dist/index.js +1060 -212
- package/dist/index.js.map +1 -1
- package/dist/xlsx-worker.js +187 -0
- package/dist/xlsx-worker.js.map +1 -1
- package/package.json +2 -2
package/dist/xlsx-worker.js
CHANGED
|
@@ -4229,6 +4229,131 @@ function normalizeHexColor3(value) {
|
|
|
4229
4229
|
}
|
|
4230
4230
|
return "#000000";
|
|
4231
4231
|
}
|
|
4232
|
+
function mapDukeFormControlAnchor(anchor) {
|
|
4233
|
+
return {
|
|
4234
|
+
from: {
|
|
4235
|
+
col: anchor.fromCol,
|
|
4236
|
+
colOffsetEmu: anchor.fromColOffset,
|
|
4237
|
+
row: anchor.fromRow,
|
|
4238
|
+
rowOffsetEmu: anchor.fromRowOffset
|
|
4239
|
+
},
|
|
4240
|
+
kind: "two-cell",
|
|
4241
|
+
to: {
|
|
4242
|
+
col: anchor.toCol,
|
|
4243
|
+
colOffsetEmu: anchor.toColOffset,
|
|
4244
|
+
row: anchor.toRow,
|
|
4245
|
+
rowOffsetEmu: anchor.toRowOffset
|
|
4246
|
+
}
|
|
4247
|
+
};
|
|
4248
|
+
}
|
|
4249
|
+
function mapDukeFormControlKind(kind) {
|
|
4250
|
+
switch (kind.kind) {
|
|
4251
|
+
case "button":
|
|
4252
|
+
return { caption: kind.caption, kind: "button", label: normalizeControlLabel(kind.caption) };
|
|
4253
|
+
case "checkbox":
|
|
4254
|
+
return {
|
|
4255
|
+
caption: kind.caption,
|
|
4256
|
+
checked: kind.state === "checked",
|
|
4257
|
+
kind: "checkbox",
|
|
4258
|
+
label: normalizeControlLabel(kind.caption),
|
|
4259
|
+
linkedCell: kind.cellLink,
|
|
4260
|
+
no3D: kind.no3D,
|
|
4261
|
+
state: kind.state
|
|
4262
|
+
};
|
|
4263
|
+
case "optionButton":
|
|
4264
|
+
return {
|
|
4265
|
+
caption: kind.caption,
|
|
4266
|
+
checked: kind.state === "checked",
|
|
4267
|
+
firstInGroup: kind.firstInGroup,
|
|
4268
|
+
kind: "radio",
|
|
4269
|
+
label: normalizeControlLabel(kind.caption),
|
|
4270
|
+
linkedCell: kind.cellLink,
|
|
4271
|
+
no3D: kind.no3D,
|
|
4272
|
+
state: kind.state
|
|
4273
|
+
};
|
|
4274
|
+
case "label":
|
|
4275
|
+
return { caption: kind.caption, kind: "label", label: normalizeControlLabel(kind.caption) };
|
|
4276
|
+
case "groupBox":
|
|
4277
|
+
return {
|
|
4278
|
+
caption: kind.caption,
|
|
4279
|
+
kind: "group-box",
|
|
4280
|
+
label: normalizeControlLabel(kind.caption),
|
|
4281
|
+
no3D: kind.no3D
|
|
4282
|
+
};
|
|
4283
|
+
case "listBox":
|
|
4284
|
+
return {
|
|
4285
|
+
inputRange: kind.inputRange,
|
|
4286
|
+
kind: "listbox",
|
|
4287
|
+
linkedCell: kind.cellLink,
|
|
4288
|
+
no3D: kind.no3D,
|
|
4289
|
+
selected: [...kind.selected],
|
|
4290
|
+
selection: kind.selection
|
|
4291
|
+
};
|
|
4292
|
+
case "dropdown":
|
|
4293
|
+
return {
|
|
4294
|
+
inputRange: kind.inputRange,
|
|
4295
|
+
kind: "dropdown",
|
|
4296
|
+
lines: kind.lines,
|
|
4297
|
+
linkedCell: kind.cellLink,
|
|
4298
|
+
no3D: kind.no3D,
|
|
4299
|
+
selected: kind.selected
|
|
4300
|
+
};
|
|
4301
|
+
case "scrollbar":
|
|
4302
|
+
return {
|
|
4303
|
+
horizontal: kind.horizontal,
|
|
4304
|
+
increment: kind.increment,
|
|
4305
|
+
kind: "scrollbar",
|
|
4306
|
+
linkedCell: kind.cellLink,
|
|
4307
|
+
max: kind.max,
|
|
4308
|
+
min: kind.min,
|
|
4309
|
+
page: kind.page,
|
|
4310
|
+
value: kind.value
|
|
4311
|
+
};
|
|
4312
|
+
case "spinner":
|
|
4313
|
+
return {
|
|
4314
|
+
increment: kind.increment,
|
|
4315
|
+
kind: "spinner",
|
|
4316
|
+
linkedCell: kind.cellLink,
|
|
4317
|
+
max: kind.max,
|
|
4318
|
+
min: kind.min,
|
|
4319
|
+
value: kind.value
|
|
4320
|
+
};
|
|
4321
|
+
}
|
|
4322
|
+
}
|
|
4323
|
+
function mapDukeFormControl(control, controlIndex, workbookSheetIndex) {
|
|
4324
|
+
return {
|
|
4325
|
+
anchor: mapDukeFormControlAnchor(control.anchor),
|
|
4326
|
+
controlIndex,
|
|
4327
|
+
dukeAnchor: { ...control.anchor },
|
|
4328
|
+
editAs: control.anchor.editAs,
|
|
4329
|
+
hidden: false,
|
|
4330
|
+
id: `form-control-${workbookSheetIndex}-${controlIndex}`,
|
|
4331
|
+
locked: control.locked,
|
|
4332
|
+
name: control.name,
|
|
4333
|
+
printable: control.printable,
|
|
4334
|
+
sheetIndex: workbookSheetIndex,
|
|
4335
|
+
workbookSheetIndex,
|
|
4336
|
+
zIndex: controlIndex + 1,
|
|
4337
|
+
...mapDukeFormControlKind(control.kind)
|
|
4338
|
+
};
|
|
4339
|
+
}
|
|
4340
|
+
function collectWorkbookFormControls(workbook2) {
|
|
4341
|
+
return Array.from({ length: workbook2.sheetCount }, (_, workbookSheetIndex) => {
|
|
4342
|
+
try {
|
|
4343
|
+
const controls = workbook2.getSheet(workbookSheetIndex).formControls;
|
|
4344
|
+
return Array.isArray(controls) ? controls.map((control, controlIndex) => mapDukeFormControl(control, controlIndex, workbookSheetIndex)) : [];
|
|
4345
|
+
} catch {
|
|
4346
|
+
return [];
|
|
4347
|
+
}
|
|
4348
|
+
});
|
|
4349
|
+
}
|
|
4350
|
+
function normalizeControlLabel(label) {
|
|
4351
|
+
if (!label) {
|
|
4352
|
+
return void 0;
|
|
4353
|
+
}
|
|
4354
|
+
const normalized = label.replace(/\u00a0/g, " ").replace(/\s+/g, " ").trim();
|
|
4355
|
+
return normalized.length > 0 ? normalized : void 0;
|
|
4356
|
+
}
|
|
4232
4357
|
function parseWorkbookStructureAssetsFromArchive(archive, options) {
|
|
4233
4358
|
const contentTypes = parseContentTypes(archive);
|
|
4234
4359
|
const workbookSheets = parseWorkbookSheets(archive);
|
|
@@ -4445,6 +4570,7 @@ function normalizeWorksheetVisibility2(value) {
|
|
|
4445
4570
|
var workbook = null;
|
|
4446
4571
|
var chartsByWorkbookSheetIndex = [];
|
|
4447
4572
|
var chartsheets = [];
|
|
4573
|
+
var formControlsByWorkbookSheetIndex = [];
|
|
4448
4574
|
var sheets = [];
|
|
4449
4575
|
var tablesByWorkbookSheetIndex = [];
|
|
4450
4576
|
var tabs = [];
|
|
@@ -4571,6 +4697,60 @@ function parseA1RangeReference2(reference) {
|
|
|
4571
4697
|
}
|
|
4572
4698
|
return normalizeRange({ end, start });
|
|
4573
4699
|
}
|
|
4700
|
+
function resolveWorkbookReference(targetWorkbook, defaultWorkbookSheetIndex, rawReference, resolvingNamedRange = false) {
|
|
4701
|
+
const reference = rawReference.trim().replace(/^=/, "");
|
|
4702
|
+
if (!reference) {
|
|
4703
|
+
return null;
|
|
4704
|
+
}
|
|
4705
|
+
let workbookSheetIndex = defaultWorkbookSheetIndex;
|
|
4706
|
+
let rangeReference = reference;
|
|
4707
|
+
const bangIndex = reference.lastIndexOf("!");
|
|
4708
|
+
if (bangIndex >= 0) {
|
|
4709
|
+
let sheetName = reference.slice(0, bangIndex).trim();
|
|
4710
|
+
rangeReference = reference.slice(bangIndex + 1).trim();
|
|
4711
|
+
if (sheetName.startsWith("'") && sheetName.endsWith("'")) {
|
|
4712
|
+
sheetName = sheetName.slice(1, -1).replace(/''/g, "'");
|
|
4713
|
+
}
|
|
4714
|
+
const resolvedSheetIndex = targetWorkbook.sheetIndex(sheetName);
|
|
4715
|
+
if (resolvedSheetIndex === void 0) {
|
|
4716
|
+
return null;
|
|
4717
|
+
}
|
|
4718
|
+
workbookSheetIndex = resolvedSheetIndex;
|
|
4719
|
+
} else if (!resolvingNamedRange) {
|
|
4720
|
+
const namedRange = targetWorkbook.getNamedRange(reference);
|
|
4721
|
+
if (namedRange) {
|
|
4722
|
+
return resolveWorkbookReference(targetWorkbook, defaultWorkbookSheetIndex, namedRange, true);
|
|
4723
|
+
}
|
|
4724
|
+
}
|
|
4725
|
+
const range = parseA1RangeReference2(rangeReference.replace(/\$/g, ""));
|
|
4726
|
+
if (!range || workbookSheetIndex < 0 || workbookSheetIndex >= targetWorkbook.sheetCount) {
|
|
4727
|
+
return null;
|
|
4728
|
+
}
|
|
4729
|
+
try {
|
|
4730
|
+
return {
|
|
4731
|
+
range,
|
|
4732
|
+
worksheet: targetWorkbook.getSheet(workbookSheetIndex)
|
|
4733
|
+
};
|
|
4734
|
+
} catch {
|
|
4735
|
+
return null;
|
|
4736
|
+
}
|
|
4737
|
+
}
|
|
4738
|
+
function resolveFormControlItems(targetWorkbook, workbookSheetIndex, control) {
|
|
4739
|
+
if (control.kind !== "dropdown" && control.kind !== "listbox" || !control.inputRange) {
|
|
4740
|
+
return [];
|
|
4741
|
+
}
|
|
4742
|
+
const source = resolveWorkbookReference(targetWorkbook, workbookSheetIndex, control.inputRange);
|
|
4743
|
+
if (!source) {
|
|
4744
|
+
return [];
|
|
4745
|
+
}
|
|
4746
|
+
const items = [];
|
|
4747
|
+
for (let row = source.range.start.row; row <= source.range.end.row; row += 1) {
|
|
4748
|
+
for (let col = source.range.start.col; col <= source.range.end.col; col += 1) {
|
|
4749
|
+
items.push(source.worksheet.getFormattedValueAt(row, col));
|
|
4750
|
+
}
|
|
4751
|
+
}
|
|
4752
|
+
return items;
|
|
4753
|
+
}
|
|
4574
4754
|
function parseWorksheetFreezePanes(worksheet) {
|
|
4575
4755
|
const rawFreezePanes = worksheet.freezePanes;
|
|
4576
4756
|
const row = typeof rawFreezePanes?.row === "number" && rawFreezePanes.row >= 0 ? rawFreezePanes.row : null;
|
|
@@ -4891,6 +5071,12 @@ async function loadWorkbook(buffer, skipXmlParsing = false, showHiddenSheets = f
|
|
|
4891
5071
|
activeWorkbook = result.workbook;
|
|
4892
5072
|
}
|
|
4893
5073
|
const nextWorkbook = activeWorkbook;
|
|
5074
|
+
formControlsByWorkbookSheetIndex = collectWorkbookFormControls(nextWorkbook).map(
|
|
5075
|
+
(controls, workbookSheetIndex) => controls.map((control) => ({
|
|
5076
|
+
...control,
|
|
5077
|
+
items: resolveFormControlItems(nextWorkbook, workbookSheetIndex, control)
|
|
5078
|
+
}))
|
|
5079
|
+
);
|
|
4894
5080
|
const shouldUseFastStructureParse = bytes.byteLength >= FAST_STRUCTURE_PARSE_THRESHOLD_BYTES && totalFormulas <= FORMULA_COUNT_THRESHOLD;
|
|
4895
5081
|
const structureAssets = effectiveSkipXmlParsing || shouldUseFastStructureParse || !canParseXmlInWorker() ? null : parseWorkbookStructureAssets(bytes, {
|
|
4896
5082
|
includeCachedFormulaValues: true
|
|
@@ -4922,6 +5108,7 @@ async function loadWorkbook(buffer, skipXmlParsing = false, showHiddenSheets = f
|
|
|
4922
5108
|
return {
|
|
4923
5109
|
chartsByWorkbookSheetIndex,
|
|
4924
5110
|
chartsheets,
|
|
5111
|
+
formControlsByWorkbookSheetIndex,
|
|
4925
5112
|
sheets,
|
|
4926
5113
|
tablesByWorkbookSheetIndex,
|
|
4927
5114
|
tabs
|