ooxml-core 1.3.0 → 1.5.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.
Files changed (94) hide show
  1. package/README.md +2 -0
  2. package/dist/automation/index.cjs +6089 -5381
  3. package/dist/automation/index.mjs +6089 -5381
  4. package/dist/teams/index.cjs +73 -23
  5. package/dist/teams/index.mjs +73 -23
  6. package/dist/visio/basic-shapes.d.ts +18 -0
  7. package/dist/visio/basic-shapes.d.ts.map +1 -0
  8. package/dist/visio/edit-commands.d.ts +13 -2
  9. package/dist/visio/edit-commands.d.ts.map +1 -1
  10. package/dist/visio/edit-page-size.d.ts +5 -0
  11. package/dist/visio/edit-page-size.d.ts.map +1 -0
  12. package/dist/visio/edit-pages.d.ts.map +1 -1
  13. package/dist/visio/edit-shape-create.d.ts.map +1 -1
  14. package/dist/visio/edit-text-range-commands.d.ts +21 -0
  15. package/dist/visio/edit-text-range-commands.d.ts.map +1 -0
  16. package/dist/visio/edit-text-range-plan.d.ts +7 -0
  17. package/dist/visio/edit-text-range-plan.d.ts.map +1 -0
  18. package/dist/visio/edit-text-ranges.d.ts +4 -0
  19. package/dist/visio/edit-text-ranges.d.ts.map +1 -0
  20. package/dist/visio/edit-text-target.d.ts +3 -0
  21. package/dist/visio/edit-text-target.d.ts.map +1 -0
  22. package/dist/visio/edit-text.d.ts.map +1 -1
  23. package/dist/visio/edit.d.ts +1 -1
  24. package/dist/visio/edit.d.ts.map +1 -1
  25. package/dist/visio/index.cjs +623 -49
  26. package/dist/visio/index.d.ts +2 -1
  27. package/dist/visio/index.d.ts.map +1 -1
  28. package/dist/visio/index.mjs +621 -50
  29. package/dist/visio/model.d.ts +3 -0
  30. package/dist/visio/model.d.ts.map +1 -1
  31. package/dist/visio/parser.d.ts.map +1 -1
  32. package/dist/visio/ui/draw-plan.d.ts +4 -1
  33. package/dist/visio/ui/draw-plan.d.ts.map +1 -1
  34. package/dist/visio/ui/edit-commands.d.ts.map +1 -1
  35. package/dist/visio/ui/index.cjs +139 -14
  36. package/dist/visio/ui/index.d.ts +1 -0
  37. package/dist/visio/ui/index.d.ts.map +1 -1
  38. package/dist/visio/ui/index.mjs +135 -15
  39. package/dist/visio/ui/page-size.d.ts +31 -0
  40. package/dist/visio/ui/page-size.d.ts.map +1 -0
  41. package/dist/visio/ui/scene-validation.d.ts.map +1 -1
  42. package/dist/visio/ui/snapshot-scene.d.ts.map +1 -1
  43. package/dist/visio/ui/text-replace-types.d.ts +6 -2
  44. package/dist/visio/ui/text-replace-types.d.ts.map +1 -1
  45. package/dist/visio/ui/text-replace.d.ts +3 -4
  46. package/dist/visio/ui/text-replace.d.ts.map +1 -1
  47. package/dist/visio/xml-validation.d.ts.map +1 -1
  48. package/dist/xlsx/collab/codec.d.ts +2 -0
  49. package/dist/xlsx/collab/codec.d.ts.map +1 -1
  50. package/dist/xlsx/collab/index.cjs +5 -0
  51. package/dist/xlsx/collab/index.mjs +5 -0
  52. package/dist/xlsx/display-text.d.ts +4 -0
  53. package/dist/xlsx/display-text.d.ts.map +1 -0
  54. package/dist/xlsx/edit/cell-values.d.ts +4 -3
  55. package/dist/xlsx/edit/cell-values.d.ts.map +1 -1
  56. package/dist/xlsx/edit/clipboard.d.ts.map +1 -1
  57. package/dist/xlsx/edit/context.d.ts +7 -5
  58. package/dist/xlsx/edit/context.d.ts.map +1 -1
  59. package/dist/xlsx/edit/deps.d.ts +1 -1
  60. package/dist/xlsx/edit/deps.d.ts.map +1 -1
  61. package/dist/xlsx/edit/dimensions.d.ts.map +1 -1
  62. package/dist/xlsx/edit/fill.d.ts.map +1 -1
  63. package/dist/xlsx/edit/filter.d.ts.map +1 -1
  64. package/dist/xlsx/edit/find.d.ts.map +1 -1
  65. package/dist/xlsx/edit/paste-selection.d.ts.map +1 -1
  66. package/dist/xlsx/edit/shift-formulas.d.ts +10 -4
  67. package/dist/xlsx/edit/shift-formulas.d.ts.map +1 -1
  68. package/dist/xlsx/edit/shift-sheet.d.ts.map +1 -1
  69. package/dist/xlsx/edit/structure.d.ts +1 -1
  70. package/dist/xlsx/edit/structure.d.ts.map +1 -1
  71. package/dist/xlsx/edit/table-header-names.d.ts +3 -0
  72. package/dist/xlsx/edit/table-header-names.d.ts.map +1 -0
  73. package/dist/xlsx/edit/tables.d.ts +1 -2
  74. package/dist/xlsx/edit/tables.d.ts.map +1 -1
  75. package/dist/xlsx/filter-rows.d.ts +12 -0
  76. package/dist/xlsx/filter-rows.d.ts.map +1 -0
  77. package/dist/xlsx/formula/functions/math-sum.d.ts.map +1 -1
  78. package/dist/xlsx/formula/table-refs.d.ts +2 -0
  79. package/dist/xlsx/formula/table-refs.d.ts.map +1 -1
  80. package/dist/xlsx/index.cjs +466 -329
  81. package/dist/xlsx/index.mjs +466 -329
  82. package/dist/xlsx/load/index.cjs +7622 -7585
  83. package/dist/xlsx/load/index.mjs +7622 -7585
  84. package/dist/xlsx/model.d.ts +4 -0
  85. package/dist/xlsx/model.d.ts.map +1 -1
  86. package/dist/xlsx/read/load.d.ts.map +1 -1
  87. package/dist/xlsx/ui/index.cjs +464 -329
  88. package/dist/xlsx/ui/index.mjs +464 -329
  89. package/dist/xlsx/ui/locales/de/shell.d.ts.map +1 -1
  90. package/dist/xlsx/ui/locales/en/shell.d.ts.map +1 -1
  91. package/dist/xlsx/ui/locales/es/shell.d.ts.map +1 -1
  92. package/dist/xlsx/ui/locales/fr/shell.d.ts.map +1 -1
  93. package/dist/xlsx/ui/locales/zh-CN/shell.d.ts.map +1 -1
  94. package/package.json +1 -1
@@ -7747,6 +7747,57 @@ function liftCriteria(ctx, pairs, fn) {
7747
7747
  });
7748
7748
  }
7749
7749
 
7750
+ // xlsx/display-text.ts
7751
+ function displayText(workbook, cell) {
7752
+ if (!cell || cell.value === null) return "";
7753
+ const value2 = cell.value;
7754
+ if (isCellError(value2)) return value2.error;
7755
+ if (typeof value2 === "boolean") return value2 ? "TRUE" : "FALSE";
7756
+ if (cell.richText && typeof value2 === "string") return value2;
7757
+ return formatValue(value2, styleAt(workbook, cell.styleId).numFmt, {
7758
+ date1904: workbook.date1904
7759
+ }).text;
7760
+ }
7761
+
7762
+ // xlsx/filter-rows.ts
7763
+ function rowMatchesFilter(workbook, sheet, row2, filter2) {
7764
+ return (filter2.columns ?? []).every((column) => {
7765
+ if (!column.values && !column.blank) return true;
7766
+ const text2 = displayText(workbook, getCell(sheet, row2, filter2.range.start.col + column.offset));
7767
+ return text2 === "" ? !!column.blank : (column.values ?? []).includes(text2);
7768
+ });
7769
+ }
7770
+ function setRowFiltered(sheet, row2, filteredOut, hasCriteria = false) {
7771
+ const info = { ...sheet.rowInfo.get(row2) };
7772
+ const manual = info.manuallyHidden || info.hidden && !info.filteredOut;
7773
+ if (filteredOut) {
7774
+ info.hidden = true;
7775
+ info.filteredOut = true;
7776
+ if (manual) info.manuallyHidden = true;
7777
+ } else {
7778
+ delete info.filteredOut;
7779
+ delete info.manuallyHidden;
7780
+ if (manual) {
7781
+ info.hidden = true;
7782
+ if (hasCriteria) info.filteredOut = false;
7783
+ } else delete info.hidden;
7784
+ }
7785
+ if (Object.keys(info).length) sheet.rowInfo.set(row2, info);
7786
+ else sheet.rowInfo.delete(row2);
7787
+ }
7788
+ function clearFilteredRows(sheet) {
7789
+ for (const [row2, info] of sheet.rowInfo)
7790
+ if (info.filteredOut !== void 0 || info.manuallyHidden !== void 0)
7791
+ setRowFiltered(sheet, row2, false);
7792
+ }
7793
+ function isFilteredRow(workbook, sheet, row2) {
7794
+ const filter2 = sheet.autoFilter;
7795
+ if (!filter2) return false;
7796
+ const info = sheet.rowInfo.get(row2);
7797
+ if (info?.filteredOut !== void 0) return info.filteredOut;
7798
+ return !!info?.hidden && row2 > filter2.range.start.row && row2 <= filter2.range.end.row && !rowMatchesFilter(workbook, sheet, row2, filter2);
7799
+ }
7800
+
7750
7801
  // xlsx/formula/functions/math-sum.ts
7751
7802
  var C18 = "Math & Trig";
7752
7803
  var numbersOf = (values2) => values2.filter((v) => typeof v === "number");
@@ -7784,7 +7835,7 @@ function pairwise(ctx, args, fn) {
7784
7835
  return total2;
7785
7836
  }
7786
7837
  var SUBTOTAL_RE = /\b(?:_xlfn\.)?(?:SUBTOTAL|AGGREGATE)\s*\(/i;
7787
- function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true) {
7838
+ function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true, skipFiltered = false) {
7788
7839
  const out = [];
7789
7840
  const host = ctx.frame.host;
7790
7841
  for (const arg of args) {
@@ -7797,6 +7848,7 @@ function subtotalValues(ctx, args, skipHidden, skipErrors, skipNested = true) {
7797
7848
  for (const area of arg.areas) {
7798
7849
  const sheet = ctx.workbook.sheets[area.sheet];
7799
7850
  host.forEachStored(area.sheet, area.range, (value2, row2, col) => {
7851
+ if (skipFiltered && sheet && isFilteredRow(ctx.workbook, sheet, row2)) return;
7800
7852
  if (skipHidden && sheet?.rowInfo.get(row2)?.hidden) return;
7801
7853
  if (skipNested && SUBTOTAL_RE.test(host.cellFormula(area.sheet, row2, col) ?? "")) return;
7802
7854
  if (skipErrors && isError(value2)) return;
@@ -7962,7 +8014,7 @@ var SUM_FUNCTIONS = [
7962
8014
  const code = int(args[0]);
7963
8015
  const base = code > 100 ? code - 100 : code;
7964
8016
  if (base < 1 || base > 11) fail(ERR.VALUE);
7965
- return aggregate(base, subtotalValues(ctx, args.slice(1), code > 100, false));
8017
+ return aggregate(base, subtotalValues(ctx, args.slice(1), code > 100, false, true, true));
7966
8018
  },
7967
8019
  ["value", "any"]
7968
8020
  ),
@@ -13460,6 +13512,31 @@ function renameTableInFormula(formula, oldName, newName) {
13460
13512
  }
13461
13513
  return changed ? joinTokens(tokens) : formula;
13462
13514
  }
13515
+ function renameTableColumnInFormula(formula, tableName, oldName, newName, insideTable = false) {
13516
+ const tokens = safeTokens2(formula);
13517
+ if (!tokens) return formula;
13518
+ const escaped = newName.replace(/['#@[\]]/g, "'$&");
13519
+ let changed = false;
13520
+ for (const [index2, token] of tokens.entries()) {
13521
+ if (token.kind !== "structured" || token.prefix) continue;
13522
+ if (token.value === "" && tokens[index2 - 1]?.prefix) continue;
13523
+ if (token.value === "" ? !insideTable : String(token.value).toLowerCase() !== tableName.toLowerCase())
13524
+ continue;
13525
+ const next = token.text.replace(
13526
+ /\[(@?)((?:[^\[\]']|'[\s\S])*)\]/g,
13527
+ (original, at, name) => {
13528
+ if (name.startsWith("#") || name.replace(/'(.)/g, "$1").toLowerCase() !== oldName.toLowerCase())
13529
+ return original;
13530
+ return `[${at}${escaped}]`;
13531
+ }
13532
+ );
13533
+ if (next !== token.text) {
13534
+ token.text = next;
13535
+ changed = true;
13536
+ }
13537
+ }
13538
+ return changed ? joinTokens(tokens) : formula;
13539
+ }
13463
13540
 
13464
13541
  // xlsx/formula/structured-to-a1.ts
13465
13542
  var abs = (row2, col, rowAbs = true) => `$${columnLabel(col)}${rowAbs ? "$" : ""}${row2 + 1}`;
@@ -14296,16 +14373,6 @@ function forEachPosition(sheet, range2, visit2) {
14296
14373
  for (let row2 = r.start.row; row2 <= r.end.row; row2++)
14297
14374
  for (let col = r.start.col; col <= r.end.col; col++) visit2(row2, col);
14298
14375
  }
14299
- function displayText(workbook, cell) {
14300
- if (!cell) return "";
14301
- const value2 = cell.value;
14302
- if (value2 === null) return "";
14303
- if (isCellError(value2)) return value2.error;
14304
- if (typeof value2 === "boolean") return value2 ? "TRUE" : "FALSE";
14305
- if (cell.richText && typeof value2 === "string") return value2;
14306
- const format = styleAt(workbook, cell.styleId).numFmt;
14307
- return formatValue(value2, format, { date1904: workbook.date1904 }).text;
14308
- }
14309
14376
  function rawText(value2) {
14310
14377
  if (value2 === null) return "";
14311
14378
  if (isCellError(value2)) return value2.error;
@@ -14322,19 +14389,266 @@ function pruneCell(sheet, row2, col) {
14322
14389
  }
14323
14390
  }
14324
14391
 
14392
+ // xlsx/edit/shift-preserved.ts
14393
+ var XM3 = "http://schemas.microsoft.com/office/excel/2006/main";
14394
+ function descendants2(root, ns, local) {
14395
+ return Array.from(root.getElementsByTagNameNS(ns, local));
14396
+ }
14397
+ function editEntries(sheet, key, edit, quick) {
14398
+ const list = sheet.preserved.get(key);
14399
+ if (!list) return;
14400
+ const next = [];
14401
+ for (const xml of list) {
14402
+ if (!quick(xml)) {
14403
+ next.push(xml);
14404
+ continue;
14405
+ }
14406
+ let doc;
14407
+ try {
14408
+ doc = parseXml(xml);
14409
+ } catch {
14410
+ next.push(xml);
14411
+ continue;
14412
+ }
14413
+ const outcome = edit(doc.documentElement);
14414
+ if (outcome === "same") next.push(xml);
14415
+ else if (outcome === "changed") next.push(buildXml(doc));
14416
+ }
14417
+ if (next.length) sheet.preserved.set(key, next);
14418
+ else sheet.preserved.delete(key);
14419
+ }
14420
+ function shiftBreaks(root, shift2) {
14421
+ let changed = false;
14422
+ for (const brk of elements(root).filter((e) => e.localName === "brk")) {
14423
+ const id = Number(brk.getAttribute("id") ?? "0");
14424
+ const moved = shiftIndex(id, shift2);
14425
+ if (moved === id) continue;
14426
+ changed = true;
14427
+ if (moved === void 0 || moved === 0) root.removeChild(brk);
14428
+ else brk.setAttribute("id", String(moved));
14429
+ }
14430
+ if (!changed) return "same";
14431
+ const left2 = elements(root).filter((e) => e.localName === "brk");
14432
+ if (!left2.length) return "drop";
14433
+ if (root.hasAttribute("count")) root.setAttribute("count", String(left2.length));
14434
+ if (root.hasAttribute("manualBreakCount")) {
14435
+ const manual = left2.filter((b) => /^(1|true)$/.test(b.getAttribute("man") ?? "")).length;
14436
+ root.setAttribute("manualBreakCount", String(manual));
14437
+ }
14438
+ return "changed";
14439
+ }
14440
+ function removeUpwards(node, root) {
14441
+ let current = node;
14442
+ while (current && current !== root) {
14443
+ const parent = current.parentNode;
14444
+ parent?.removeChild(current);
14445
+ if (!parent) break;
14446
+ const emptied = elements(parent).length === 0 || parent.localName === "sparklineGroup" && !elements(parent).some((e) => e.localName === "sparklines");
14447
+ if (!emptied) break;
14448
+ current = parent;
14449
+ }
14450
+ }
14451
+ function shiftSqrefs(root, moveRange) {
14452
+ let changed = false;
14453
+ for (const sqref of descendants2(root, XM3, "sqref")) {
14454
+ const old = sqref.textContent ?? "";
14455
+ const ranges = parseSqref(old).map(moveRange).filter((r) => !!r);
14456
+ const text2 = ranges.map(formatRange).join(" ");
14457
+ if (text2 === old.trim()) continue;
14458
+ changed = true;
14459
+ const owner = sqref.parentNode;
14460
+ if (ranges.length) sqref.textContent = text2;
14461
+ else if (owner) removeUpwards(owner, root);
14462
+ }
14463
+ if (!changed) return "same";
14464
+ for (const list of elements(root).flatMap((ext) => elements(ext)))
14465
+ if (list.localName === "dataValidations" && list.hasAttribute("count"))
14466
+ list.setAttribute("count", String(elements(list).length));
14467
+ return elements(root).length > 0 ? "changed" : "drop";
14468
+ }
14469
+ function shiftPreservedXml(sheet, shift2, moveRange, banded) {
14470
+ if (!banded)
14471
+ editEntries(
14472
+ sheet,
14473
+ shift2.axis === "row" ? "rowBreaks" : "colBreaks",
14474
+ (root) => shiftBreaks(root, shift2),
14475
+ (xml) => xml.includes("brk")
14476
+ );
14477
+ editEntries(
14478
+ sheet,
14479
+ "extLst",
14480
+ (root) => shiftSqrefs(root, moveRange),
14481
+ (xml) => xml.includes("sqref")
14482
+ );
14483
+ }
14484
+ function rewritePreservedFormulas(sheet, rewrite) {
14485
+ editEntries(
14486
+ sheet,
14487
+ "extLst",
14488
+ (root) => {
14489
+ let changed = false;
14490
+ for (const f6 of descendants2(root, XM3, "f")) {
14491
+ const text2 = f6.textContent ?? "";
14492
+ let next = text2;
14493
+ try {
14494
+ next = rewrite(text2, sheet.name);
14495
+ } catch {
14496
+ next = text2;
14497
+ }
14498
+ if (next === text2) continue;
14499
+ f6.textContent = next;
14500
+ changed = true;
14501
+ }
14502
+ return changed ? "changed" : "same";
14503
+ },
14504
+ (xml) => xml.includes(":f>")
14505
+ );
14506
+ }
14507
+
14508
+ // xlsx/edit/conditional-formulas.ts
14509
+ function rewriteConditionalRule(rule, rewrite) {
14510
+ const safe2 = (formula) => {
14511
+ try {
14512
+ return rewrite(formula);
14513
+ } catch {
14514
+ return formula;
14515
+ }
14516
+ };
14517
+ if (rule.type === "cellIs") rule.formulas = rule.formulas.map(safe2);
14518
+ else if (rule.type === "expression") rule.formula = safe2(rule.formula);
14519
+ if (rule.type === "colorScale" || rule.type === "iconSet") {
14520
+ for (const threshold of rule.thresholds)
14521
+ if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
14522
+ }
14523
+ if (rule.type === "dataBar") {
14524
+ for (const threshold of [rule.min, rule.max])
14525
+ if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
14526
+ }
14527
+ if (rule.type === "dataBar") rewriteConditionalExtension(rule, safe2);
14528
+ }
14529
+
14530
+ // xlsx/edit/shift-formulas.ts
14531
+ function safe(rewrite, formula, formulaSheet, at) {
14532
+ try {
14533
+ return rewrite(formula, formulaSheet, at);
14534
+ } catch {
14535
+ return formula;
14536
+ }
14537
+ }
14538
+ function rewriteFormulas(workbook, rewrite, formulaCells) {
14539
+ const bySheet = formulaCells && /* @__PURE__ */ new Map();
14540
+ if (bySheet)
14541
+ for (const cell of formulaCells ?? []) {
14542
+ const positions2 = bySheet.get(cell.sheet);
14543
+ if (positions2) positions2.push(cell);
14544
+ else bySheet.set(cell.sheet, [cell]);
14545
+ }
14546
+ workbook.sheets.forEach(
14547
+ (sheet, index2) => rewriteSheetFormulas(sheet, rewrite, bySheet ? bySheet.get(index2) ?? [] : void 0)
14548
+ );
14549
+ for (const definedName of workbook.definedNames) {
14550
+ const local = definedName.localSheet === void 0 ? void 0 : workbook.sheets[definedName.localSheet];
14551
+ definedName.formula = safe(rewrite, definedName.formula, local?.name ?? "");
14552
+ }
14553
+ }
14554
+ function rewriteSheetFormulas(sheet, rewrite, formulaCells) {
14555
+ rewritePreservedFormulas(sheet, rewrite);
14556
+ {
14557
+ const name = sheet.name;
14558
+ for (const table2 of sheet.tables)
14559
+ for (const [index2, column] of table2.columns.entries())
14560
+ if (column.calculatedColumnFormula !== void 0)
14561
+ column.calculatedColumnFormula = safe(rewrite, column.calculatedColumnFormula, name, {
14562
+ row: table2.range.start.row + (table2.headerRow ? 1 : 0),
14563
+ col: table2.range.start.col + index2
14564
+ });
14565
+ if (formulaCells) {
14566
+ for (const at of formulaCells) {
14567
+ const cell = getCell(sheet, at.row, at.col);
14568
+ if (cell?.formula !== void 0) cell.formula = safe(rewrite, cell.formula, name, at);
14569
+ }
14570
+ } else {
14571
+ sheet.rows.forEach(
14572
+ (cells, row2) => cells.forEach((cell, col) => {
14573
+ if (cell.formula !== void 0)
14574
+ cell.formula = safe(rewrite, cell.formula, name, { row: row2, col });
14575
+ })
14576
+ );
14577
+ }
14578
+ for (const cf of sheet.conditionalFormats)
14579
+ for (const rule of cf.rules)
14580
+ rewriteConditionalRule(rule, (f6) => rewrite(f6, name, cf.ranges[0]?.start));
14581
+ for (const dv of sheet.dataValidations) {
14582
+ if (dv.formula1 !== void 0)
14583
+ dv.formula1 = safe(rewrite, dv.formula1, name, dv.ranges[0]?.start);
14584
+ if (dv.formula2 !== void 0)
14585
+ dv.formula2 = safe(rewrite, dv.formula2, name, dv.ranges[0]?.start);
14586
+ }
14587
+ for (const link of sheet.hyperlinks)
14588
+ if (link.location && /![A-Za-z$]/.test(link.location))
14589
+ link.location = safe(rewrite, link.location, name);
14590
+ for (const drawing of sheet.drawings) {
14591
+ if (drawing.kind !== "chart") continue;
14592
+ for (const series of drawing.series) {
14593
+ if (series.nameRef) series.nameRef = safe(rewrite, series.nameRef, name);
14594
+ if (series.categoriesRef) series.categoriesRef = safe(rewrite, series.categoriesRef, name);
14595
+ if (series.valuesRef) series.valuesRef = safe(rewrite, series.valuesRef, name);
14596
+ }
14597
+ }
14598
+ }
14599
+ }
14600
+
14601
+ // xlsx/edit/table-header-names.ts
14602
+ function uniqueHeaders(texts) {
14603
+ const used = /* @__PURE__ */ new Set();
14604
+ return texts.map((text2, i2) => {
14605
+ let base = text2.trim() || `Column${i2 + 1}`;
14606
+ if (!used.has(base.toLowerCase())) {
14607
+ used.add(base.toLowerCase());
14608
+ return base;
14609
+ }
14610
+ for (let n = 2; ; n++) {
14611
+ const candidate = `${base}${n}`;
14612
+ if (!used.has(candidate.toLowerCase())) {
14613
+ used.add(candidate.toLowerCase());
14614
+ base = candidate;
14615
+ return base;
14616
+ }
14617
+ }
14618
+ });
14619
+ }
14620
+
14325
14621
  // xlsx/edit/cell-values.ts
14326
14622
  function tableHeaderAt(sheet, row2, col) {
14327
14623
  return sheet.tables.find(
14328
14624
  (t) => t.headerRow && t.range.start.row === row2 && col >= t.range.start.col && col <= t.range.end.col
14329
14625
  );
14330
14626
  }
14331
- function syncTableHeader(ctx, sheet, row2, col) {
14627
+ function syncTableHeader(ctx, sheet, row2, col, formulaCells) {
14332
14628
  const table2 = tableHeaderAt(sheet, row2, col);
14333
14629
  if (!table2) return;
14334
14630
  const column = table2.columns[col - table2.range.start.col];
14335
14631
  if (!column) return;
14336
14632
  const text2 = displayText(ctx.workbook, getCell(sheet, row2, col)).trim();
14337
- if (text2) column.name = text2;
14633
+ if (!text2 || column.name === text2) return;
14634
+ const oldName = column.name;
14635
+ const others = table2.columns.filter((entry) => entry !== column).map((entry) => entry.name);
14636
+ const newName = uniqueHeaders([...others, text2]).at(-1);
14637
+ column.name = newName;
14638
+ if (newName !== text2) writeValue(sheet, row2, col, newName);
14639
+ const index2 = ctx.workbook.sheets.indexOf(sheet);
14640
+ const cells = formulaCells && (formulaCells.some((cell) => cell.sheet === index2 && cell.row === row2 && cell.col === col) ? formulaCells : [...formulaCells, { sheet: index2, row: row2, col }]);
14641
+ rewriteFormulas(
14642
+ ctx.workbook,
14643
+ (formula, formulaSheet, at) => renameTableColumnInFormula(
14644
+ formula,
14645
+ table2.name,
14646
+ oldName,
14647
+ newName,
14648
+ formulaSheet === sheet.name && !!at && rangeContains(table2.range, at)
14649
+ ),
14650
+ cells
14651
+ );
14338
14652
  }
14339
14653
  function writeScopes(sheet, index2, range2, parts = []) {
14340
14654
  const r = normalizeRange(range2);
@@ -14344,9 +14658,9 @@ function writeScopes(sheet, index2, range2, parts = []) {
14344
14658
  cellRange(t.range.start.row, t.range.start.col, t.range.start.row, t.range.end.col)
14345
14659
  )
14346
14660
  );
14347
- const all2 = touchesHeader && !parts.includes("tables") ? [...parts, "tables"] : parts;
14661
+ if (touchesHeader) return [{ kind: "refs" }, { kind: "cells", sheet: index2, ranges: [r] }];
14348
14662
  const scopes = [{ kind: "cells", sheet: index2, ranges: [r] }];
14349
- if (all2.length) scopes.push({ kind: "parts", sheet: index2, parts: all2 });
14663
+ if (parts.length) scopes.push({ kind: "parts", sheet: index2, parts });
14350
14664
  return scopes;
14351
14665
  }
14352
14666
  function writeInput(ctx, sheet, row2, col, text2) {
@@ -14397,9 +14711,9 @@ function setCellInput(ctx, s, row2, col, text2) {
14397
14711
  `Typing in ${formatAddress({ row: row2, col })}`,
14398
14712
  "cells",
14399
14713
  writeScopes(sheet, s, range2),
14400
- () => {
14714
+ (formulaCells) => {
14401
14715
  writeInput(ctx, sheet, row2, col, text2);
14402
- syncTableHeader(ctx, sheet, row2, col);
14716
+ syncTableHeader(ctx, sheet, row2, col, formulaCells);
14403
14717
  },
14404
14718
  { sheet: s, ranges: [range2] }
14405
14719
  );
@@ -14411,9 +14725,9 @@ function setCellValue(ctx, s, row2, col, value2) {
14411
14725
  `Edit ${formatAddress({ row: row2, col })}`,
14412
14726
  "cells",
14413
14727
  writeScopes(sheet, s, range2),
14414
- () => {
14728
+ (formulaCells) => {
14415
14729
  writeValue(sheet, row2, col, value2);
14416
- syncTableHeader(ctx, sheet, row2, col);
14730
+ syncTableHeader(ctx, sheet, row2, col, formulaCells);
14417
14731
  },
14418
14732
  { sheet: s, ranges: [range2] }
14419
14733
  );
@@ -14840,7 +15154,7 @@ function fillRange(ctx, s, source, target2, mode = "auto") {
14840
15154
  ctx.run(
14841
15155
  "Fill",
14842
15156
  "cells",
14843
- [{ kind: "cells", sheet: s, ranges: [all2] }],
15157
+ writeScopes(sheet, s, all2),
14844
15158
  () => {
14845
15159
  const laneCount = vertical2 ? src.end.col - src.start.col + 1 : src.end.row - src.start.row + 1;
14846
15160
  const length = vertical2 ? src.end.row - src.start.row + 1 : src.end.col - src.start.col + 1;
@@ -14863,6 +15177,7 @@ function fillRange(ctx, s, source, target2, mode = "auto") {
14863
15177
  const step = series?.(k);
14864
15178
  const cell = !step || step.kind === "copy" ? copyCell(origin, row2 - srcRow, col - srcCol) : { value: step.value, ...origin.styleId ? { styleId: origin.styleId } : {} };
14865
15179
  putCell(sheet, row2, col, cell);
15180
+ syncTableHeader(ctx, sheet, row2, col);
14866
15181
  }
14867
15182
  }
14868
15183
  },
@@ -14901,28 +15216,6 @@ function removeValidationArea(rules, area) {
14901
15216
  });
14902
15217
  }
14903
15218
 
14904
- // xlsx/edit/conditional-formulas.ts
14905
- function rewriteConditionalRule(rule, rewrite) {
14906
- const safe2 = (formula) => {
14907
- try {
14908
- return rewrite(formula);
14909
- } catch {
14910
- return formula;
14911
- }
14912
- };
14913
- if (rule.type === "cellIs") rule.formulas = rule.formulas.map(safe2);
14914
- else if (rule.type === "expression") rule.formula = safe2(rule.formula);
14915
- if (rule.type === "colorScale" || rule.type === "iconSet") {
14916
- for (const threshold of rule.thresholds)
14917
- if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
14918
- }
14919
- if (rule.type === "dataBar") {
14920
- for (const threshold of [rule.min, rule.max])
14921
- if (threshold.type === "formula" && threshold.value) threshold.value = safe2(threshold.value);
14922
- }
14923
- if (rule.type === "dataBar") rewriteConditionalExtension(rule, safe2);
14924
- }
14925
-
14926
15219
  // xlsx/edit/conditional-formats.ts
14927
15220
  function formatAt(sheet, index2) {
14928
15221
  const format = sheet.conditionalFormats[index2];
@@ -15332,168 +15625,6 @@ function setBorders(ctx, s, range2, preset, edge = { style: "thin" }) {
15332
15625
  );
15333
15626
  }
15334
15627
 
15335
- // xlsx/edit/shift-preserved.ts
15336
- var XM3 = "http://schemas.microsoft.com/office/excel/2006/main";
15337
- function descendants2(root, ns, local) {
15338
- return Array.from(root.getElementsByTagNameNS(ns, local));
15339
- }
15340
- function editEntries(sheet, key, edit, quick) {
15341
- const list = sheet.preserved.get(key);
15342
- if (!list) return;
15343
- const next = [];
15344
- for (const xml of list) {
15345
- if (!quick(xml)) {
15346
- next.push(xml);
15347
- continue;
15348
- }
15349
- let doc;
15350
- try {
15351
- doc = parseXml(xml);
15352
- } catch {
15353
- next.push(xml);
15354
- continue;
15355
- }
15356
- const outcome = edit(doc.documentElement);
15357
- if (outcome === "same") next.push(xml);
15358
- else if (outcome === "changed") next.push(buildXml(doc));
15359
- }
15360
- if (next.length) sheet.preserved.set(key, next);
15361
- else sheet.preserved.delete(key);
15362
- }
15363
- function shiftBreaks(root, shift2) {
15364
- let changed = false;
15365
- for (const brk of elements(root).filter((e) => e.localName === "brk")) {
15366
- const id = Number(brk.getAttribute("id") ?? "0");
15367
- const moved = shiftIndex(id, shift2);
15368
- if (moved === id) continue;
15369
- changed = true;
15370
- if (moved === void 0 || moved === 0) root.removeChild(brk);
15371
- else brk.setAttribute("id", String(moved));
15372
- }
15373
- if (!changed) return "same";
15374
- const left2 = elements(root).filter((e) => e.localName === "brk");
15375
- if (!left2.length) return "drop";
15376
- if (root.hasAttribute("count")) root.setAttribute("count", String(left2.length));
15377
- if (root.hasAttribute("manualBreakCount")) {
15378
- const manual = left2.filter((b) => /^(1|true)$/.test(b.getAttribute("man") ?? "")).length;
15379
- root.setAttribute("manualBreakCount", String(manual));
15380
- }
15381
- return "changed";
15382
- }
15383
- function removeUpwards(node, root) {
15384
- let current = node;
15385
- while (current && current !== root) {
15386
- const parent = current.parentNode;
15387
- parent?.removeChild(current);
15388
- if (!parent) break;
15389
- const emptied = elements(parent).length === 0 || parent.localName === "sparklineGroup" && !elements(parent).some((e) => e.localName === "sparklines");
15390
- if (!emptied) break;
15391
- current = parent;
15392
- }
15393
- }
15394
- function shiftSqrefs(root, moveRange) {
15395
- let changed = false;
15396
- for (const sqref of descendants2(root, XM3, "sqref")) {
15397
- const old = sqref.textContent ?? "";
15398
- const ranges = parseSqref(old).map(moveRange).filter((r) => !!r);
15399
- const text2 = ranges.map(formatRange).join(" ");
15400
- if (text2 === old.trim()) continue;
15401
- changed = true;
15402
- const owner = sqref.parentNode;
15403
- if (ranges.length) sqref.textContent = text2;
15404
- else if (owner) removeUpwards(owner, root);
15405
- }
15406
- if (!changed) return "same";
15407
- for (const list of elements(root).flatMap((ext) => elements(ext)))
15408
- if (list.localName === "dataValidations" && list.hasAttribute("count"))
15409
- list.setAttribute("count", String(elements(list).length));
15410
- return elements(root).length > 0 ? "changed" : "drop";
15411
- }
15412
- function shiftPreservedXml(sheet, shift2, moveRange, banded) {
15413
- if (!banded)
15414
- editEntries(
15415
- sheet,
15416
- shift2.axis === "row" ? "rowBreaks" : "colBreaks",
15417
- (root) => shiftBreaks(root, shift2),
15418
- (xml) => xml.includes("brk")
15419
- );
15420
- editEntries(
15421
- sheet,
15422
- "extLst",
15423
- (root) => shiftSqrefs(root, moveRange),
15424
- (xml) => xml.includes("sqref")
15425
- );
15426
- }
15427
- function rewritePreservedFormulas(sheet, rewrite) {
15428
- editEntries(
15429
- sheet,
15430
- "extLst",
15431
- (root) => {
15432
- let changed = false;
15433
- for (const f6 of descendants2(root, XM3, "f")) {
15434
- const text2 = f6.textContent ?? "";
15435
- let next = text2;
15436
- try {
15437
- next = rewrite(text2, sheet.name);
15438
- } catch {
15439
- next = text2;
15440
- }
15441
- if (next === text2) continue;
15442
- f6.textContent = next;
15443
- changed = true;
15444
- }
15445
- return changed ? "changed" : "same";
15446
- },
15447
- (xml) => xml.includes(":f>")
15448
- );
15449
- }
15450
-
15451
- // xlsx/edit/shift-formulas.ts
15452
- function safe(rewrite, formula, formulaSheet) {
15453
- try {
15454
- return rewrite(formula, formulaSheet);
15455
- } catch {
15456
- return formula;
15457
- }
15458
- }
15459
- function rewriteFormulas(workbook, rewrite) {
15460
- for (const sheet of workbook.sheets) rewriteSheetFormulas(sheet, rewrite);
15461
- for (const definedName of workbook.definedNames) {
15462
- const local = definedName.localSheet === void 0 ? void 0 : workbook.sheets[definedName.localSheet];
15463
- definedName.formula = safe(rewrite, definedName.formula, local?.name ?? "");
15464
- }
15465
- }
15466
- function rewriteSheetFormulas(sheet, rewrite) {
15467
- rewritePreservedFormulas(sheet, rewrite);
15468
- {
15469
- const name = sheet.name;
15470
- for (const table2 of sheet.tables)
15471
- for (const column of table2.columns)
15472
- if (column.calculatedColumnFormula !== void 0)
15473
- column.calculatedColumnFormula = safe(rewrite, column.calculatedColumnFormula, name);
15474
- for (const cells of sheet.rows.values())
15475
- for (const cell of cells.values())
15476
- if (cell.formula !== void 0) cell.formula = safe(rewrite, cell.formula, name);
15477
- for (const cf of sheet.conditionalFormats)
15478
- for (const rule of cf.rules) rewriteConditionalRule(rule, (f6) => rewrite(f6, name));
15479
- for (const dv of sheet.dataValidations) {
15480
- if (dv.formula1 !== void 0) dv.formula1 = safe(rewrite, dv.formula1, name);
15481
- if (dv.formula2 !== void 0) dv.formula2 = safe(rewrite, dv.formula2, name);
15482
- }
15483
- for (const link of sheet.hyperlinks)
15484
- if (link.location && /![A-Za-z$]/.test(link.location))
15485
- link.location = safe(rewrite, link.location, name);
15486
- for (const drawing of sheet.drawings) {
15487
- if (drawing.kind !== "chart") continue;
15488
- for (const series of drawing.series) {
15489
- if (series.nameRef) series.nameRef = safe(rewrite, series.nameRef, name);
15490
- if (series.categoriesRef) series.categoriesRef = safe(rewrite, series.categoriesRef, name);
15491
- if (series.valuesRef) series.valuesRef = safe(rewrite, series.valuesRef, name);
15492
- }
15493
- }
15494
- }
15495
- }
15496
-
15497
15628
  // xlsx/edit/shift-sheet.ts
15498
15629
  function shiftSheetContent(sheet, shift2, band) {
15499
15630
  const moveRange = (range2) => band ? shiftRangeInBand(range2, shift2, band.lo, band.hi) : shiftRange(range2, shift2);
@@ -15515,8 +15646,10 @@ function shiftSheetContent(sheet, shift2, band) {
15515
15646
  if (sheet.autoFilter) {
15516
15647
  const old = sheet.autoFilter.range;
15517
15648
  const range2 = moveRange(old);
15518
- if (!range2) delete sheet.autoFilter;
15519
- else {
15649
+ if (!range2) {
15650
+ delete sheet.autoFilter;
15651
+ clearFilteredRows(sheet);
15652
+ } else {
15520
15653
  const filter2 = { ...sheet.autoFilter, range: range2 };
15521
15654
  if (shift2.axis === "col" && filter2.columns)
15522
15655
  filter2.columns = filter2.columns.flatMap((fc) => {
@@ -15667,6 +15800,9 @@ function shiftAxis(ctx, s, axis, at, count2, insert) {
15667
15800
  const sheet = sheetAt(ctx.workbook, s);
15668
15801
  const noun = axis === "row" ? count2 === 1 ? "row" : "rows" : count2 === 1 ? "column" : "columns";
15669
15802
  const shift2 = { axis, at, count: insert ? count2 : -count2 };
15803
+ const info = { sheet: s, structural: true };
15804
+ if (!sheet.autoFilter || shiftRange(sheet.autoFilter.range, shift2))
15805
+ info.calc = { kind: "shift", sheet: s, shift: shift2 };
15670
15806
  ctx.run(
15671
15807
  `${insert ? "Insert" : "Delete"} ${noun}`,
15672
15808
  "structure",
@@ -15675,7 +15811,7 @@ function shiftAxis(ctx, s, axis, at, count2, insert) {
15675
15811
  applyAxisShift(ctx, sheet, shift2);
15676
15812
  if (insert) inheritFormats(sheet, axis, at, count2);
15677
15813
  },
15678
- { sheet: s, structural: true, calc: { kind: "shift", sheet: s, shift: shift2 } }
15814
+ info
15679
15815
  );
15680
15816
  }
15681
15817
  var insertRows = (ctx, s, at, count2) => shiftAxis(ctx, s, "row", at, count2, true);
@@ -16483,14 +16619,13 @@ function pasteAt(ctx, s, at, payload, request) {
16483
16619
  if (cut && operation !== "none")
16484
16620
  throw new RangeError("Paste operations are not available for cut cells.");
16485
16621
  const destCells = { kind: "cells", sheet: s, ranges: [dest] };
16486
- const scopes = cut ? [{ kind: "refs" }, { kind: "cells", sheet: cut.sheet, ranges: [cut.range] }, destCells] : [
16487
- destCells,
16488
- {
16489
- kind: "parts",
16490
- sheet: s,
16491
- parts: ["merges", "comments", "dataValidations", "hyperlinks", "conditionalFormats"]
16492
- }
16493
- ];
16622
+ const scopes = cut ? [{ kind: "refs" }, { kind: "cells", sheet: cut.sheet, ranges: [cut.range] }, destCells] : writeScopes(sheet, s, dest, [
16623
+ "merges",
16624
+ "comments",
16625
+ "dataValidations",
16626
+ "hyperlinks",
16627
+ "conditionalFormats"
16628
+ ]);
16494
16629
  const move = cut && {
16495
16630
  fromSheet: sheetAt(workbook, cut.sheet).name,
16496
16631
  range: cut.range,
@@ -16563,6 +16698,8 @@ function pasteAt(ctx, s, at, payload, request) {
16563
16698
  const origin = cells.source?.range.start;
16564
16699
  const formula = clip?.formula === void 0 ? void 0 : move ? moveReferencesInFormula(clip.formula, move.fromSheet, move, move.toSheet) : !origin ? clip.formula : moveFormula(clip.formula, at.row - origin.row, at.col - origin.col);
16565
16700
  writeClip(workbook, sheet, row2, col, clip, mode, formula, styleOf, operation);
16701
+ if (mode !== "formats" && mode !== "comments" && mode !== "validation")
16702
+ syncTableHeader(ctx, sheet, row2, col);
16566
16703
  }
16567
16704
  if (mode === "all" || mode === "mergeFormats" || mode === "noBorders" || mode === "formats") {
16568
16705
  sheet.merges = sheet.merges.filter((m) => !rangesIntersect(m, dest));
@@ -16606,14 +16743,13 @@ function pasteSelection(ctx, sheet, selection, payload, request) {
16606
16743
  return ctx.run(
16607
16744
  "Paste",
16608
16745
  "cells",
16609
- [
16610
- { kind: "cells", sheet, ranges: [dest] },
16611
- {
16612
- kind: "parts",
16613
- sheet,
16614
- parts: ["merges", "comments", "dataValidations", "hyperlinks", "conditionalFormats"]
16615
- }
16616
- ],
16746
+ writeScopes(sheetAt(ctx.workbook, sheet), sheet, dest, [
16747
+ "merges",
16748
+ "comments",
16749
+ "dataValidations",
16750
+ "hyperlinks",
16751
+ "conditionalFormats"
16752
+ ]),
16617
16753
  () => {
16618
16754
  for (let row2 = dest.start.row; row2 <= dest.end.row; row2 += height)
16619
16755
  for (let col = dest.start.col; col <= dest.end.col; col += width)
@@ -16765,9 +16901,19 @@ function setHidden(ctx, s, axis, indices, hidden) {
16765
16901
  }
16766
16902
  for (const row2 of indices) {
16767
16903
  const info = { ...sheet.rowInfo.get(row2) };
16904
+ if (info.filteredOut) {
16905
+ if (hidden) info.manuallyHidden = true;
16906
+ else delete info.manuallyHidden;
16907
+ sheet.rowInfo.set(row2, info);
16908
+ continue;
16909
+ }
16910
+ const filter2 = sheet.autoFilter;
16911
+ if (hidden && filter2?.columns?.length && row2 > filter2.range.start.row && row2 <= filter2.range.end.row)
16912
+ info.filteredOut = false;
16768
16913
  if (hidden) info.hidden = true;
16769
16914
  else {
16770
16915
  delete info.hidden;
16916
+ delete info.filteredOut;
16771
16917
  if (info.height === 0) delete info.height;
16772
16918
  }
16773
16919
  if (Object.keys(info).length) sheet.rowInfo.set(row2, info);
@@ -16919,16 +17065,8 @@ function currentRegion(sheet, at) {
16919
17065
  function applyFilter(ctx, sheet, filter2) {
16920
17066
  const { range: range2 } = filter2;
16921
17067
  for (let row2 = range2.start.row + 1; row2 <= range2.end.row; row2++) {
16922
- const visible = (filter2.columns ?? []).every((fc) => {
16923
- if (!fc.values && !fc.blank) return true;
16924
- const text2 = displayText(ctx.workbook, getCell(sheet, row2, range2.start.col + fc.offset));
16925
- return text2 === "" ? !!fc.blank : (fc.values ?? []).includes(text2);
16926
- });
16927
- const info = { ...sheet.rowInfo.get(row2) };
16928
- if (visible) delete info.hidden;
16929
- else info.hidden = true;
16930
- if (Object.keys(info).length) sheet.rowInfo.set(row2, info);
16931
- else sheet.rowInfo.delete(row2);
17068
+ const visible = rowMatchesFilter(ctx.workbook, sheet, row2, filter2);
17069
+ setRowFiltered(sheet, row2, !visible, !!filter2.columns?.length);
16932
17070
  }
16933
17071
  }
16934
17072
  function setAutoFilter(ctx, s, range2) {
@@ -17086,16 +17224,16 @@ var isSpilledAt = (workbook, at) => {
17086
17224
  return !!sheet && isSpilledCell(getCell(sheet, at.row, at.col));
17087
17225
  };
17088
17226
  var replaceQuery = (query) => query.lookIn === "comments" ? query : { ...query, lookIn: "formulas" };
17089
- function replaceScopes(query, sheet, matches2) {
17227
+ function replaceScopes(ctx, query, sheet, matches2) {
17090
17228
  if (query.lookIn === "comments") return [{ kind: "parts", sheet, parts: ["comments"] }];
17091
17229
  const ranges = matches2.map((m) => ({
17092
17230
  start: { row: m.row, col: m.col },
17093
17231
  end: { row: m.row, col: m.col }
17094
17232
  }));
17095
- return [
17096
- { kind: "cells", sheet, ranges },
17097
- { kind: "parts", sheet, parts: ["tables"] }
17098
- ];
17233
+ const header = ranges.some(
17234
+ (range2) => writeScopes(sheetAt(ctx.workbook, sheet), sheet, range2).some((scope) => scope.kind === "refs")
17235
+ );
17236
+ return [...header ? [{ kind: "refs" }] : [], { kind: "cells", sheet, ranges }];
17099
17237
  }
17100
17238
  function applyReplace(ctx, query, replacement, matches2) {
17101
17239
  let changed = 0;
@@ -17125,14 +17263,24 @@ function replaceAll(ctx, query, replacement) {
17125
17263
  const sheets = [...new Set(matches2.map((m) => m.sheet))];
17126
17264
  const scopes = sheets.flatMap(
17127
17265
  (sheet) => replaceScopes(
17266
+ ctx,
17128
17267
  q,
17129
17268
  sheet,
17130
17269
  matches2.filter((m) => m.sheet === sheet)
17131
17270
  )
17132
17271
  );
17133
- return ctx.run("Replace", "cells", scopes, () => applyReplace(ctx, q, replacement, matches2), {
17134
- ...sheets.length === 1 && sheets[0] !== void 0 ? { sheet: sheets[0] } : {}
17135
- });
17272
+ const uniqueScopes = scopes.filter(
17273
+ (scope, index2) => scope.kind !== "refs" || scopes.findIndex((entry) => entry.kind === "refs") === index2
17274
+ );
17275
+ return ctx.run(
17276
+ "Replace",
17277
+ "cells",
17278
+ uniqueScopes,
17279
+ () => applyReplace(ctx, q, replacement, matches2),
17280
+ {
17281
+ ...sheets.length === 1 && sheets[0] !== void 0 ? { sheet: sheets[0] } : {}
17282
+ }
17283
+ );
17136
17284
  }
17137
17285
  function replaceOne(ctx, query, replacement, at) {
17138
17286
  const q = replaceQuery(query);
@@ -17145,7 +17293,7 @@ function replaceOne(ctx, query, replacement, at) {
17145
17293
  ctx.run(
17146
17294
  "Replace",
17147
17295
  "cells",
17148
- replaceScopes(q, at.sheet, [match2]),
17296
+ replaceScopes(ctx, q, at.sheet, [match2]),
17149
17297
  () => applyReplace(ctx, q, replacement, [match2]),
17150
17298
  { sheet: at.sheet }
17151
17299
  );
@@ -17925,90 +18073,6 @@ function applyTotalsRow(sheet, table2) {
17925
18073
  });
17926
18074
  }
17927
18075
 
17928
- // xlsx/edit/tables.ts
17929
- function nextTableName(workbook) {
17930
- const taken = new Set(workbook.sheets.flatMap((s) => s.tables.map((t) => t.name.toLowerCase())));
17931
- const names = new Set(workbook.definedNames.map((n) => n.name.toLowerCase()));
17932
- for (let n = 1; ; n++) if (!taken.has(`table${n}`) && !names.has(`table${n}`)) return `Table${n}`;
17933
- }
17934
- function uniqueHeaders(texts) {
17935
- const used = /* @__PURE__ */ new Set();
17936
- return texts.map((text2, i2) => {
17937
- let base = text2.trim() || `Column${i2 + 1}`;
17938
- if (!used.has(base.toLowerCase())) {
17939
- used.add(base.toLowerCase());
17940
- return base;
17941
- }
17942
- for (let n = 2; ; n++) {
17943
- const candidate = `${base}${n}`;
17944
- if (!used.has(candidate.toLowerCase())) {
17945
- used.add(candidate.toLowerCase());
17946
- base = candidate;
17947
- return base;
17948
- }
17949
- }
17950
- });
17951
- }
17952
- function createTable(ctx, s, range2, hasHeader, styleName = "TableStyleMedium2") {
17953
- const { workbook } = ctx;
17954
- const sheet = sheetAt(workbook, s);
17955
- let r = normalizeRange(range2);
17956
- if (r.start.row === r.end.row && r.start.col === r.end.col) r = currentRegion(sheet, r.start);
17957
- if (sheet.tables.some((t) => rangesIntersect(t.range, r)))
17958
- throw new Error("A table cannot overlap another table.");
17959
- if (sheet.merges.some((m) => rangesIntersect(m, r)))
17960
- throw new Error("A table cannot contain merged cells.");
17961
- return ctx.run(
17962
- "Create table",
17963
- "structure",
17964
- [hasHeader ? { kind: "sheet", sheet: s } : { kind: "workbook" }],
17965
- () => {
17966
- if (!hasHeader) {
17967
- const shift2 = { axis: "row", at: r.start.row, count: 1 };
17968
- const band = { lo: r.start.col, hi: r.end.col };
17969
- rewriteFormulas(workbook, (f6, fs) => shiftFormulaInBand(f6, fs, sheet.name, shift2, band));
17970
- shiftSheetContent(sheet, shift2, band);
17971
- r = { start: r.start, end: { row: r.end.row + 1, col: r.end.col } };
17972
- }
17973
- const width = r.end.col - r.start.col + 1;
17974
- const texts = Array.from(
17975
- { length: width },
17976
- (_v, i2) => hasHeader ? displayText(workbook, getCell(sheet, r.start.row, r.start.col + i2)) : ""
17977
- );
17978
- const headers = uniqueHeaders(texts);
17979
- const columns = headers.map((name2, i2) => {
17980
- const cell = getCell(sheet, r.start.row, r.start.col + i2);
17981
- if (cell?.value !== name2) {
17982
- const styleId = cell?.styleId;
17983
- writeValue(sheet, r.start.row, r.start.col + i2, name2);
17984
- const written = getCell(sheet, r.start.row, r.start.col + i2);
17985
- if (written && styleId) written.styleId = styleId;
17986
- }
17987
- return { name: name2 };
17988
- });
17989
- const name = nextTableName(workbook);
17990
- const id = Math.max(0, ...workbook.sheets.flatMap((ws) => ws.tables.map((t) => t.id))) + 1;
17991
- const table2 = {
17992
- id,
17993
- name,
17994
- displayName: name,
17995
- range: r,
17996
- headerRow: true,
17997
- totalsRow: false,
17998
- columns,
17999
- styleName,
18000
- showRowStripes: true,
18001
- showColumnStripes: false,
18002
- showFirstColumn: false,
18003
- showLastColumn: false
18004
- };
18005
- sheet.tables.push(table2);
18006
- return table2;
18007
- },
18008
- { sheet: s, ranges: [r], structural: !hasHeader }
18009
- );
18010
- }
18011
-
18012
18076
  // xlsx/edit/table-edits.ts
18013
18077
  function tableIndex(sheet, ref) {
18014
18078
  const index2 = typeof ref === "number" ? ref : sheet.tables.findIndex((t) => t.name.toLowerCase() === ref.toLowerCase());
@@ -21225,8 +21289,8 @@ function setSheetState(ctx, index2, state) {
21225
21289
  const { workbook } = ctx;
21226
21290
  const sheet = sheetAt(workbook, index2);
21227
21291
  if (sheet.state === state) return;
21292
+ assertUnlocked(workbook);
21228
21293
  if (state !== "visible") {
21229
- assertUnlocked(workbook);
21230
21294
  if (sheet.state === "visible" && visibleCount(workbook) <= 1)
21231
21295
  throw new Error("A workbook must contain at least one visible sheet.");
21232
21296
  }
@@ -21256,6 +21320,72 @@ function setTabColor(ctx, index2, color) {
21256
21320
  );
21257
21321
  }
21258
21322
 
21323
+ // xlsx/edit/tables.ts
21324
+ function nextTableName(workbook) {
21325
+ const taken = new Set(workbook.sheets.flatMap((s) => s.tables.map((t) => t.name.toLowerCase())));
21326
+ const names = new Set(workbook.definedNames.map((n) => n.name.toLowerCase()));
21327
+ for (let n = 1; ; n++) if (!taken.has(`table${n}`) && !names.has(`table${n}`)) return `Table${n}`;
21328
+ }
21329
+ function createTable(ctx, s, range2, hasHeader, styleName = "TableStyleMedium2") {
21330
+ const { workbook } = ctx;
21331
+ const sheet = sheetAt(workbook, s);
21332
+ let r = normalizeRange(range2);
21333
+ if (r.start.row === r.end.row && r.start.col === r.end.col) r = currentRegion(sheet, r.start);
21334
+ if (sheet.tables.some((t) => rangesIntersect(t.range, r)))
21335
+ throw new Error("A table cannot overlap another table.");
21336
+ if (sheet.merges.some((m) => rangesIntersect(m, r)))
21337
+ throw new Error("A table cannot contain merged cells.");
21338
+ return ctx.run(
21339
+ "Create table",
21340
+ "structure",
21341
+ [hasHeader ? { kind: "sheet", sheet: s } : { kind: "workbook" }],
21342
+ () => {
21343
+ if (!hasHeader) {
21344
+ const shift2 = { axis: "row", at: r.start.row, count: 1 };
21345
+ const band = { lo: r.start.col, hi: r.end.col };
21346
+ rewriteFormulas(workbook, (f6, fs) => shiftFormulaInBand(f6, fs, sheet.name, shift2, band));
21347
+ shiftSheetContent(sheet, shift2, band);
21348
+ r = { start: r.start, end: { row: r.end.row + 1, col: r.end.col } };
21349
+ }
21350
+ const width = r.end.col - r.start.col + 1;
21351
+ const texts = Array.from(
21352
+ { length: width },
21353
+ (_v, i2) => hasHeader ? displayText(workbook, getCell(sheet, r.start.row, r.start.col + i2)) : ""
21354
+ );
21355
+ const headers = uniqueHeaders(texts);
21356
+ const columns = headers.map((name2, i2) => {
21357
+ const cell = getCell(sheet, r.start.row, r.start.col + i2);
21358
+ if (cell?.value !== name2) {
21359
+ const styleId = cell?.styleId;
21360
+ writeValue(sheet, r.start.row, r.start.col + i2, name2);
21361
+ const written = getCell(sheet, r.start.row, r.start.col + i2);
21362
+ if (written && styleId) written.styleId = styleId;
21363
+ }
21364
+ return { name: name2 };
21365
+ });
21366
+ const name = nextTableName(workbook);
21367
+ const id = Math.max(0, ...workbook.sheets.flatMap((ws) => ws.tables.map((t) => t.id))) + 1;
21368
+ const table2 = {
21369
+ id,
21370
+ name,
21371
+ displayName: name,
21372
+ range: r,
21373
+ headerRow: true,
21374
+ totalsRow: false,
21375
+ columns,
21376
+ styleName,
21377
+ showRowStripes: true,
21378
+ showColumnStripes: false,
21379
+ showFirstColumn: false,
21380
+ showLastColumn: false
21381
+ };
21382
+ sheet.tables.push(table2);
21383
+ return table2;
21384
+ },
21385
+ { sheet: s, ranges: [r], structural: !hasHeader }
21386
+ );
21387
+ }
21388
+
21259
21389
  // xlsx/edit/validation-list.ts
21260
21390
  function listSource(workbook, sheet, formula, evaluate, at, depth = 0) {
21261
21391
  const text2 = formula.replace(/^=/, "").trim();
@@ -21543,7 +21673,7 @@ function createEditSession(workbook, options = {}) {
21543
21673
  const befores = scopes.map((scope) => captureScope(workbook, scope));
21544
21674
  let result2;
21545
21675
  try {
21546
- result2 = fn();
21676
+ result2 = fn(befores.find((snapshot) => snapshot.kind === "refs")?.data.formulas);
21547
21677
  } catch (error) {
21548
21678
  for (let i2 = befores.length - 1; i2 >= 0; i2--) {
21549
21679
  const snapshot = befores[i2];
@@ -26989,6 +27119,7 @@ __export(shell_exports, {
26989
27119
  shell: () => shell
26990
27120
  });
26991
27121
  var shell = {
27122
+ "Finish or cancel the current cell edit before saving.": "Beenden oder verwerfen Sie die aktuelle Zellbearbeitung vor dem Speichern.",
26992
27123
  File: "Datei",
26993
27124
  Ribbon: "Men\xFCband",
26994
27125
  "Ribbon tabs": "Men\xFCbandregisterkarten",
@@ -27374,6 +27505,7 @@ __export(shell_exports2, {
27374
27505
  shell: () => shell2
27375
27506
  });
27376
27507
  var shell2 = {
27508
+ "Finish or cancel the current cell edit before saving.": "Finish or cancel the current cell edit before saving.",
27377
27509
  File: "File",
27378
27510
  Ribbon: "Ribbon",
27379
27511
  "Ribbon tabs": "Ribbon tabs",
@@ -27759,6 +27891,7 @@ __export(shell_exports3, {
27759
27891
  shell: () => shell3
27760
27892
  });
27761
27893
  var shell3 = {
27894
+ "Finish or cancel the current cell edit before saving.": "Finalice o cancele la edici\xF3n de la celda actual antes de guardar.",
27762
27895
  File: "Archivo",
27763
27896
  Ribbon: "Cinta de opciones",
27764
27897
  "Ribbon tabs": "Pesta\xF1as de la cinta",
@@ -28144,6 +28277,7 @@ __export(shell_exports4, {
28144
28277
  shell: () => shell4
28145
28278
  });
28146
28279
  var shell4 = {
28280
+ "Finish or cancel the current cell edit before saving.": "Terminez ou annulez la modification de la cellule avant de sauvegarder.",
28147
28281
  File: "Fichier",
28148
28282
  Ribbon: "Ruban",
28149
28283
  "Ribbon tabs": "Onglets du ruban",
@@ -28529,6 +28663,7 @@ __export(shell_exports5, {
28529
28663
  shell: () => shell5
28530
28664
  });
28531
28665
  var shell5 = {
28666
+ "Finish or cancel the current cell edit before saving.": "\u8BF7\u5148\u5B8C\u6210\u6216\u53D6\u6D88\u5F53\u524D\u5355\u5143\u683C\u7684\u7F16\u8F91\uFF0C\u518D\u4FDD\u5B58\u3002",
28532
28667
  File: "\u6587\u4EF6",
28533
28668
  Ribbon: "\u529F\u80FD\u533A",
28534
28669
  "Ribbon tabs": "\u529F\u80FD\u533A\u9009\u9879\u5361",