@pixerate/editor 0.26.0 → 0.27.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 (79) hide show
  1. package/README.md +8 -2
  2. package/dist/agent/index.cjs +59 -9
  3. package/dist/agent/index.cjs.map +1 -1
  4. package/dist/agent/index.d.cts +6 -4
  5. package/dist/agent/index.d.ts +6 -4
  6. package/dist/agent/index.js +52 -2
  7. package/dist/agent/index.js.map +1 -1
  8. package/dist/{builtins-Chj6zv_O.d.ts → builtins-haN82vjT.d.ts} +33 -3
  9. package/dist/{builtins-CdPcLwwF.d.cts → builtins-nMXh9sT3.d.cts} +33 -3
  10. package/dist/canvas/index.cjs +372 -8
  11. package/dist/canvas/index.cjs.map +1 -1
  12. package/dist/canvas/index.d.cts +72 -4
  13. package/dist/canvas/index.d.ts +72 -4
  14. package/dist/canvas/index.js +368 -4
  15. package/dist/canvas/index.js.map +1 -1
  16. package/dist/{chunk-UBCFIABU.js → chunk-5H2OPMXZ.js} +183 -6
  17. package/dist/chunk-5H2OPMXZ.js.map +1 -0
  18. package/dist/{chunk-NFVBT3UZ.cjs → chunk-66IMF6OD.cjs} +108 -25
  19. package/dist/chunk-66IMF6OD.cjs.map +1 -0
  20. package/dist/{chunk-Q2OHWD2A.js → chunk-6IO7WUSU.js} +19 -5
  21. package/dist/chunk-6IO7WUSU.js.map +1 -0
  22. package/dist/{chunk-YOMYSFJU.cjs → chunk-AGR7EVRW.cjs} +49 -35
  23. package/dist/chunk-AGR7EVRW.cjs.map +1 -0
  24. package/dist/{chunk-RRREAOVM.cjs → chunk-HNDSPZ5T.cjs} +4 -4
  25. package/dist/{chunk-RRREAOVM.cjs.map → chunk-HNDSPZ5T.cjs.map} +1 -1
  26. package/dist/chunk-HXDMZQTD.cjs +497 -0
  27. package/dist/chunk-HXDMZQTD.cjs.map +1 -0
  28. package/dist/chunk-IB3ZHQAX.js +497 -0
  29. package/dist/chunk-IB3ZHQAX.js.map +1 -0
  30. package/dist/{chunk-X7HXL2SB.js → chunk-JT7AXQTE.js} +336 -10
  31. package/dist/chunk-JT7AXQTE.js.map +1 -0
  32. package/dist/{chunk-HDYMLS3X.cjs → chunk-MC2LQN5S.cjs} +196 -19
  33. package/dist/chunk-MC2LQN5S.cjs.map +1 -0
  34. package/dist/{chunk-JOIREKL7.js → chunk-UKI64KUD.js} +85 -2
  35. package/dist/chunk-UKI64KUD.js.map +1 -0
  36. package/dist/{chunk-MHEPLBFB.js → chunk-WON34HKM.js} +2 -2
  37. package/dist/{chunk-NQF32I6Z.cjs → chunk-YK5TATOF.cjs} +461 -135
  38. package/dist/chunk-YK5TATOF.cjs.map +1 -0
  39. package/dist/commands/index.cjs +30 -410
  40. package/dist/commands/index.cjs.map +1 -1
  41. package/dist/commands/index.d.cts +1 -1
  42. package/dist/commands/index.d.ts +1 -1
  43. package/dist/commands/index.js +17 -397
  44. package/dist/commands/index.js.map +1 -1
  45. package/dist/{controller-CxXGOEmy.d.cts → controller-w6eRTjF8.d.cts} +67 -2
  46. package/dist/{controller-CxXGOEmy.d.ts → controller-w6eRTjF8.d.ts} +67 -2
  47. package/dist/extensions/index.cjs +23 -5
  48. package/dist/extensions/index.cjs.map +1 -1
  49. package/dist/extensions/index.d.cts +1 -1
  50. package/dist/extensions/index.d.ts +1 -1
  51. package/dist/extensions/index.js +23 -5
  52. package/dist/{index-jcJwmBYt.d.cts → index-C6gaQRH0.d.cts} +53 -4
  53. package/dist/{index-B273Zllk.d.ts → index-DXAv_R08.d.ts} +53 -4
  54. package/dist/index.cjs +66 -26
  55. package/dist/index.cjs.map +1 -1
  56. package/dist/index.d.cts +8 -6
  57. package/dist/index.d.ts +8 -6
  58. package/dist/index.js +46 -6
  59. package/dist/index.js.map +1 -1
  60. package/dist/serializers/index.cjs +5 -3
  61. package/dist/serializers/index.cjs.map +1 -1
  62. package/dist/serializers/index.d.cts +13 -3
  63. package/dist/serializers/index.d.ts +13 -3
  64. package/dist/serializers/index.js +4 -2
  65. package/dist/spreadsheet/index.cjs +22 -2
  66. package/dist/spreadsheet/index.cjs.map +1 -1
  67. package/dist/spreadsheet/index.d.cts +76 -3
  68. package/dist/spreadsheet/index.d.ts +76 -3
  69. package/dist/spreadsheet/index.js +21 -1
  70. package/package.json +1 -1
  71. package/dist/chunk-HDYMLS3X.cjs.map +0 -1
  72. package/dist/chunk-JOIREKL7.js.map +0 -1
  73. package/dist/chunk-NFVBT3UZ.cjs.map +0 -1
  74. package/dist/chunk-NQF32I6Z.cjs.map +0 -1
  75. package/dist/chunk-Q2OHWD2A.js.map +0 -1
  76. package/dist/chunk-UBCFIABU.js.map +0 -1
  77. package/dist/chunk-X7HXL2SB.js.map +0 -1
  78. package/dist/chunk-YOMYSFJU.cjs.map +0 -1
  79. /package/dist/{chunk-MHEPLBFB.js.map → chunk-WON34HKM.js.map} +0 -0
@@ -863,6 +863,27 @@ function remapFormulaReferences(formula, moveCell, options = {}) {
863
863
  return `${formatPart({ ...start, row: minR, col: minC })}:${formatPart({ ...end, row: maxR, col: maxC })}`;
864
864
  });
865
865
  }
866
+ function transposeFormulaReferences(formula, anchor, block) {
867
+ const t = { row: block.startRow + (anchor.col - block.startCol), col: block.startCol + (anchor.row - block.startRow) };
868
+ return mapFormulaReferences(formula, (text, info) => {
869
+ const parts = text.split(":").map(parsePart);
870
+ if (parts.some((p) => p === null || p.row === null)) return text;
871
+ const moved = [];
872
+ for (const part of parts) {
873
+ const row = part.row;
874
+ const colAbs = !!part.colAbs;
875
+ const rowAbs = !!part.rowAbs;
876
+ if ((colAbs || rowAbs) && info.sheet !== void 0) return text;
877
+ if (colAbs && (part.col < block.startCol || part.col > block.endCol)) return text;
878
+ if (rowAbs && (row < block.startRow || row > block.endRow)) return text;
879
+ const newRow = colAbs ? block.startRow + (part.col - block.startCol) : t.row + (part.col - anchor.col);
880
+ const newCol = rowAbs ? block.startCol + (row - block.startRow) : t.col + (row - anchor.row);
881
+ if (newRow < 0 || newCol < 0) return "#REF!";
882
+ moved.push({ colAbs: part.rowAbs, col: newCol, rowAbs: part.colAbs, row: newRow });
883
+ }
884
+ return moved.map(formatPart).join(":");
885
+ });
886
+ }
866
887
  var CELL_LIKE = /^[A-Za-z]{1,3}\d{1,7}$/;
867
888
  var isCellLike = (name) => {
868
889
  if (!CELL_LIKE.test(name)) return false;
@@ -1781,6 +1802,175 @@ function parseRuleRanges(text) {
1781
1802
  }
1782
1803
  return out;
1783
1804
  }
1805
+ function mergeRuleRanges(ranges) {
1806
+ const join = (list, across) => {
1807
+ const [lo, hi, fixedLo, fixedHi] = across === "row" ? ["startRow", "endRow", "startCol", "endCol"] : ["startCol", "endCol", "startRow", "endRow"];
1808
+ const sorted = list.map(normalizeRange).sort((a, b) => a[fixedLo] - b[fixedLo] || a[fixedHi] - b[fixedHi] || a[lo] - b[lo]);
1809
+ const out = [];
1810
+ for (const r of sorted) {
1811
+ const last = out[out.length - 1];
1812
+ if (last && last[fixedLo] === r[fixedLo] && last[fixedHi] === r[fixedHi] && r[lo] <= last[hi] + 1) {
1813
+ last[hi] = Math.max(last[hi], r[hi]);
1814
+ } else {
1815
+ out.push({ ...r });
1816
+ }
1817
+ }
1818
+ return out;
1819
+ };
1820
+ return join(join(ranges, "row"), "col").sort((a, b) => a.startRow - b.startRow || a.startCol - b.startCol);
1821
+ }
1822
+ function sortRuleRanges(ranges, block, newRowOf) {
1823
+ const b = normalizeRange(block);
1824
+ let changed = false;
1825
+ const pieces = [];
1826
+ const moved = /* @__PURE__ */ new Map();
1827
+ for (const range of ranges) {
1828
+ const r = normalizeRange(range);
1829
+ const top = Math.max(r.startRow, b.startRow);
1830
+ const bottom = Math.min(r.endRow, b.endRow);
1831
+ const left = Math.max(r.startCol, b.startCol);
1832
+ const right = Math.min(r.endCol, b.endCol);
1833
+ if (top > bottom || left > right || top === b.startRow && bottom === b.endRow) {
1834
+ pieces.push(r);
1835
+ continue;
1836
+ }
1837
+ changed = true;
1838
+ pieces.push(...subtractRange(r, b));
1839
+ const key = `${left}:${right}`;
1840
+ let entry = moved.get(key);
1841
+ if (!entry) moved.set(key, entry = { startCol: left, endCol: right, rows: [] });
1842
+ for (let row = top; row <= bottom; row++) entry.rows.push(newRowOf(row));
1843
+ }
1844
+ if (!changed) return null;
1845
+ for (const { startCol, endCol, rows } of moved.values()) {
1846
+ rows.sort((x, y) => x - y);
1847
+ let start = rows[0];
1848
+ for (let i = 1; i <= rows.length; i++) {
1849
+ if (i < rows.length && rows[i] <= rows[i - 1] + 1) continue;
1850
+ pieces.push({ startRow: start, startCol, endRow: rows[i - 1], endCol });
1851
+ start = rows[i];
1852
+ }
1853
+ }
1854
+ return mergeRuleRanges(pieces);
1855
+ }
1856
+ function transposeRuleRanges(ranges, block, target) {
1857
+ const s = normalizeRange(block);
1858
+ const t = normalizeRange(target);
1859
+ if (!ranges.some((r) => rangesIntersect(r, s) || rangesIntersect(r, t))) return null;
1860
+ const inside = [];
1861
+ for (const range of ranges) {
1862
+ const r = normalizeRange(range);
1863
+ if (!rangesIntersect(r, s)) continue;
1864
+ const top = Math.max(r.startRow, s.startRow);
1865
+ const bottom = Math.min(r.endRow, s.endRow);
1866
+ const left = Math.max(r.startCol, s.startCol);
1867
+ const right = Math.min(r.endCol, s.endCol);
1868
+ inside.push({
1869
+ startRow: s.startRow + (left - s.startCol),
1870
+ endRow: s.startRow + (right - s.startCol),
1871
+ startCol: s.startCol + (top - s.startRow),
1872
+ endCol: s.startCol + (bottom - s.startRow)
1873
+ });
1874
+ }
1875
+ const outside = subtractRangeFromRanges(subtractRangeFromRanges(ranges, s), t);
1876
+ return { inside: mergeRuleRanges(inside), outside: mergeRuleRanges(outside) };
1877
+ }
1878
+ function reanchorRuleFormula(formula, from, to) {
1879
+ if (from.row === to.row && from.col === to.col) return formula;
1880
+ const hadEquals = formula.trimStart().startsWith("=");
1881
+ const moved = ruleFormulaAt(formula, from, to.row, to.col);
1882
+ return hadEquals ? moved : moved.slice(1);
1883
+ }
1884
+ function transposeRuleFormula(formula, anchor, block) {
1885
+ const hadEquals = formula.trimStart().startsWith("=");
1886
+ const out = transposeFormulaReferences(withEquals(formula), anchor, normalizeRange(block));
1887
+ return hadEquals ? out : out.slice(1);
1888
+ }
1889
+ var isFormulaText = (text) => text !== void 0 && text.trimStart().startsWith("=");
1890
+ function mapConditionalFormatFormulas(rule, fn) {
1891
+ const anchor = (value) => value.type === "formula" ? { ...value, formula: fn(value.formula) } : value;
1892
+ const next = { ...rule };
1893
+ if (next.type === "expression") next.formula = fn(next.formula);
1894
+ if (next.type === "cellIs") {
1895
+ if (isFormulaText(next.value)) next.value = fn(next.value);
1896
+ if (isFormulaText(next.value2)) next.value2 = fn(next.value2);
1897
+ }
1898
+ if (next.type === "colorScale") next.stops = next.stops.map((s) => ({ ...s, value: anchor(s.value) }));
1899
+ if (next.type === "dataBar") {
1900
+ if (next.min) next.min = anchor(next.min);
1901
+ if (next.max) next.max = anchor(next.max);
1902
+ }
1903
+ if (next.type === "iconSet" && next.thresholds) next.thresholds = next.thresholds.map(anchor);
1904
+ return next;
1905
+ }
1906
+ function mapDataValidationFormulas(rule, fn) {
1907
+ const next = { ...rule };
1908
+ if (isFormulaText(next.formula1)) next.formula1 = fn(next.formula1);
1909
+ if (isFormulaText(next.formula2)) next.formula2 = fn(next.formula2);
1910
+ return next;
1911
+ }
1912
+ function hasRuleFormulas(rule, mapFormulas) {
1913
+ let found = false;
1914
+ mapFormulas(rule, (f) => {
1915
+ found = true;
1916
+ return f;
1917
+ });
1918
+ return found;
1919
+ }
1920
+ var sameCell = (a, b) => a.row === b.row && a.col === b.col;
1921
+ function sortRules(rules, block, newRowOf, mapFormulas) {
1922
+ let changed = false;
1923
+ const out = rules.map((rule) => {
1924
+ const ranges = sortRuleRanges(rule.ranges, block, newRowOf);
1925
+ if (!ranges) return rule;
1926
+ changed = true;
1927
+ const from = ruleAnchor(rule.ranges);
1928
+ const to = ruleAnchor(ranges);
1929
+ const next = { ...rule, ranges };
1930
+ return sameCell(from, to) ? next : mapFormulas(next, (f) => reanchorRuleFormula(f, from, to));
1931
+ });
1932
+ return changed ? out : rules;
1933
+ }
1934
+ function transposeRules(rules, block, target, mapFormulas, newId) {
1935
+ const s = normalizeRange(block);
1936
+ let changed = false;
1937
+ const out = [];
1938
+ for (const rule of rules) {
1939
+ const moved = transposeRuleRanges(rule.ranges, s, target);
1940
+ if (!moved) {
1941
+ out.push(rule);
1942
+ continue;
1943
+ }
1944
+ changed = true;
1945
+ const { inside, outside } = moved;
1946
+ const from = ruleAnchor(rule.ranges);
1947
+ const withFormulas = hasRuleFormulas(rule, mapFormulas);
1948
+ const stayed = () => {
1949
+ const to = ruleAnchor(outside);
1950
+ const next = { ...rule, ranges: outside };
1951
+ return withFormulas && !sameCell(from, to) ? mapFormulas(next, (f) => reanchorRuleFormula(f, from, to)) : next;
1952
+ };
1953
+ const transposed = () => {
1954
+ const next = { ...rule, ranges: inside };
1955
+ if (!withFormulas) return next;
1956
+ const first2 = rule.ranges.map(normalizeRange).find((r) => rangesIntersect(r, s));
1957
+ const at = { row: Math.max(first2.startRow, s.startRow), col: Math.max(first2.startCol, s.startCol) };
1958
+ const atT = { row: s.startRow + (at.col - s.startCol), col: s.startCol + (at.row - s.startRow) };
1959
+ const to = ruleAnchor(inside);
1960
+ return mapFormulas(next, (f) => reanchorRuleFormula(transposeRuleFormula(reanchorRuleFormula(f, from, at), at, s), atT, to));
1961
+ };
1962
+ if (inside.length === 0) {
1963
+ if (outside.length > 0) out.push(stayed());
1964
+ } else if (outside.length === 0) {
1965
+ out.push(transposed());
1966
+ } else if (!withFormulas) {
1967
+ out.push({ ...rule, ranges: mergeRuleRanges([...outside, ...inside]) });
1968
+ } else {
1969
+ out.push(stayed(), { ...transposed(), id: newId() });
1970
+ }
1971
+ }
1972
+ return changed ? out : rules;
1973
+ }
1784
1974
 
1785
1975
  // src/spreadsheet/conditional-format/icons.ts
1786
1976
  var RED = "#d9534f";
@@ -1877,13 +2067,13 @@ function defaultIconThresholds(set) {
1877
2067
  return Array.from({ length: k }, (_, i) => ({ type: "percent", value: Math.round(i * 100 / k) }));
1878
2068
  }
1879
2069
  var usesStats = (rule) => rule.type === "colorScale" || rule.type === "dataBar" || rule.type === "iconSet" || rule.type === "top10" || rule.type === "aboveAverage" || rule.type === "duplicate" || rule.type === "unique";
1880
- var isFormulaText = (text) => !!text && text.trimStart().startsWith("=");
2070
+ var isFormulaText2 = (text) => !!text && text.trimStart().startsWith("=");
1881
2071
  function usesFormulas(rule) {
1882
2072
  switch (rule.type) {
1883
2073
  case "expression":
1884
2074
  return true;
1885
2075
  case "cellIs":
1886
- return isFormulaText(rule.value) || isFormulaText(rule.value2);
2076
+ return isFormulaText2(rule.value) || isFormulaText2(rule.value2);
1887
2077
  case "colorScale":
1888
2078
  return rule.stops.some((s) => s.value.type === "formula");
1889
2079
  case "dataBar":
@@ -2056,7 +2246,7 @@ var ConditionalFormatEngine = (_class4 = class {
2056
2246
  /** The operand of a `cellIs` rule: a formula result, or typed input. */
2057
2247
  operand(text, rule, row, col) {
2058
2248
  if (text === void 0) return "";
2059
- if (isFormulaText(text)) return this.evalFormula(text, rule, row, col);
2249
+ if (isFormulaText2(text)) return this.evalFormula(text, rule, row, col);
2060
2250
  return _chunkEWCOFSCQcjs.parseCellInput.call(void 0, text).value;
2061
2251
  }
2062
2252
  /** Combines every rule that applies to (row, col). */
@@ -2826,6 +3016,33 @@ var createRuntime = (doc) => ({
2826
3016
  selectedRange: null
2827
3017
  });
2828
3018
  var sameName3 = (a, b) => a.toUpperCase() === b.toUpperCase();
3019
+ var nameKey = (n) => `${_nullishCoalesce(n.sheetId, () => ( ""))}!${n.name.toUpperCase()}`;
3020
+ function normalizeSavedName(n, sheetId) {
3021
+ if (!n || typeof n.name !== "string" || typeof n.refersTo !== "string" || n.name === "") return null;
3022
+ const { sheetId: _ignored, ...rest } = n;
3023
+ return {
3024
+ ...rest,
3025
+ refersTo: n.refersTo.startsWith("=") ? n.refersTo : `=${n.refersTo}`,
3026
+ ...sheetId !== void 0 ? { sheetId } : {}
3027
+ };
3028
+ }
3029
+ function namesFromDocument(doc, sheetId) {
3030
+ if (!Array.isArray(_optionalChain([doc, 'optionalAccess', _97 => _97.names]))) return [];
3031
+ const out = [];
3032
+ const seen = /* @__PURE__ */ new Set();
3033
+ for (const saved of doc.names) {
3034
+ const n = normalizeSavedName(saved, _optionalChain([saved, 'optionalAccess', _98 => _98.sheetId]) !== void 0 ? sheetId : void 0);
3035
+ if (!n || seen.has(nameKey(n))) continue;
3036
+ seen.add(nameKey(n));
3037
+ out.push(n);
3038
+ }
3039
+ return out;
3040
+ }
3041
+ function withoutNames(doc) {
3042
+ if (!("names" in doc)) return doc;
3043
+ const { names: _names, ...rest } = doc;
3044
+ return rest;
3045
+ }
2829
3046
  var DEFAULT_MAX_HISTORY_BYTES = 64 * 1024 * 1024;
2830
3047
  var AST_CACHE_SIZE = 1e5;
2831
3048
  var RANGE_CACHE_MIN_CELLS = 256;
@@ -2836,12 +3053,12 @@ var PositionCache = (_class5 = class {constructor() { _class5.prototype.__init22
2836
3053
  __init23() {this.scanned = 0}
2837
3054
  find(list, id) {
2838
3055
  const pos = this.map.get(id);
2839
- if (pos !== void 0 && _optionalChain([list, 'access', _97 => _97[pos], 'optionalAccess', _98 => _98.id]) === id) return pos;
3056
+ if (pos !== void 0 && _optionalChain([list, 'access', _99 => _99[pos], 'optionalAccess', _100 => _100.id]) === id) return pos;
2840
3057
  if (pos === void 0 && this.scanned <= list.length) {
2841
3058
  for (let i = this.scanned; i < list.length; i++) this.map.set(list[i].id, i);
2842
3059
  this.scanned = list.length;
2843
3060
  const found2 = this.map.get(id);
2844
- if (found2 !== void 0 && _optionalChain([list, 'access', _99 => _99[found2], 'optionalAccess', _100 => _100.id]) === id) return found2;
3061
+ if (found2 !== void 0 && _optionalChain([list, 'access', _101 => _101[found2], 'optionalAccess', _102 => _102.id]) === id) return found2;
2845
3062
  }
2846
3063
  this.map.clear();
2847
3064
  list.forEach((item, i) => this.map.set(item.id, i));
@@ -2942,21 +3159,23 @@ var SpreadsheetController = (_class6 = class {
2942
3159
  type: "freeform"
2943
3160
  }));
2944
3161
  const first2 = {
2945
- id: _optionalChain([options, 'access', _101 => _101.document, 'optionalAccess', _102 => _102.id]) || `sheet_${Date.now()}`,
2946
- name: _optionalChain([options, 'access', _103 => _103.document, 'optionalAccess', _104 => _104.name]) || "Sheet 1",
2947
- columns: _optionalChain([options, 'access', _105 => _105.document, 'optionalAccess', _106 => _106.columns]) || defaultCols,
2948
- rows: _optionalChain([options, 'access', _107 => _107.document, 'optionalAccess', _108 => _108.rows]) || defaultRows,
2949
- cells: _optionalChain([options, 'access', _109 => _109.document, 'optionalAccess', _110 => _110.cells]) || {},
2950
- createdAt: _optionalChain([options, 'access', _111 => _111.document, 'optionalAccess', _112 => _112.createdAt]) || Date.now(),
2951
- updatedAt: _optionalChain([options, 'access', _113 => _113.document, 'optionalAccess', _114 => _114.updatedAt]) || Date.now(),
2952
- ..._optionalChain([options, 'access', _115 => _115.document, 'optionalAccess', _116 => _116.table]) ? { table: options.document.table } : {}
3162
+ id: _optionalChain([options, 'access', _103 => _103.document, 'optionalAccess', _104 => _104.id]) || `sheet_${Date.now()}`,
3163
+ name: _optionalChain([options, 'access', _105 => _105.document, 'optionalAccess', _106 => _106.name]) || "Sheet 1",
3164
+ columns: _optionalChain([options, 'access', _107 => _107.document, 'optionalAccess', _108 => _108.columns]) || defaultCols,
3165
+ rows: _optionalChain([options, 'access', _109 => _109.document, 'optionalAccess', _110 => _110.rows]) || defaultRows,
3166
+ cells: _optionalChain([options, 'access', _111 => _111.document, 'optionalAccess', _112 => _112.cells]) || {},
3167
+ createdAt: _optionalChain([options, 'access', _113 => _113.document, 'optionalAccess', _114 => _114.createdAt]) || Date.now(),
3168
+ updatedAt: _optionalChain([options, 'access', _115 => _115.document, 'optionalAccess', _116 => _116.updatedAt]) || Date.now(),
3169
+ ..._optionalChain([options, 'access', _117 => _117.document, 'optionalAccess', _118 => _118.table]) ? { table: options.document.table } : {}
2953
3170
  };
2954
3171
  if (options.workbook && options.workbook.sheets.length > 0) {
2955
- this.setWorkbookState(options.workbook, false);
3172
+ this.setWorkbookState({ ...options.workbook, sheets: options.workbook.sheets.map((doc) => ({ ...doc })) }, false);
2956
3173
  } else {
2957
3174
  this.runtimes = [createRuntime(first2)];
2958
3175
  this.active = this.ctx = this.runtimes[0];
3176
+ this.names = namesFromDocument(options.document, first2.id);
2959
3177
  }
3178
+ this.syncDocumentNames();
2960
3179
  this.boundSheetId = this.runtimes[0].doc.id;
2961
3180
  this.primaryDataSourceId = options.primaryDataSourceId;
2962
3181
  this.maxHistoryBytes = Math.max(0, _nullishCoalesce(options.maxHistoryBytes, () => ( DEFAULT_MAX_HISTORY_BYTES)));
@@ -3068,6 +3287,7 @@ var SpreadsheetController = (_class6 = class {
3068
3287
  for (const n of this.names) if (n.sheetId === previousId) n.sheetId = loaded.id;
3069
3288
  if (this.boundSheetId === previousId) this.boundSheetId = loaded.id;
3070
3289
  }
3290
+ if (Array.isArray(document.names)) this.loadDocumentNames(document, loaded.id);
3071
3291
  this.activeCell = null;
3072
3292
  this.selectedRange = null;
3073
3293
  this.editingCell = null;
@@ -3080,9 +3300,40 @@ var SpreadsheetController = (_class6 = class {
3080
3300
  this.notifyChange();
3081
3301
  }
3082
3302
  // --- Workbook: loading and saving ---
3083
- /** A deep copy of the workbook: every sheet, the active sheet and the defined names. */
3303
+ /**
3304
+ * Installs the names saved in a document loaded into sheet `sheetId`: they
3305
+ * replace that sheet's own names and, when it is the only sheet, the
3306
+ * workbook names; with other sheets, its workbook names are added (or
3307
+ * replace the same name) and the others are kept.
3308
+ */
3309
+ loadDocumentNames(document, sheetId) {
3310
+ const saved = namesFromDocument(document, sheetId);
3311
+ const onlySheet = this.runtimes.length === 1;
3312
+ const keys = new Set(saved.map(nameKey));
3313
+ this.names = this.names.filter(
3314
+ (n) => n.sheetId !== sheetId && !(n.sheetId === void 0 && (onlySheet || keys.has(nameKey(n))))
3315
+ );
3316
+ this.names.push(...saved);
3317
+ }
3318
+ /**
3319
+ * Writes every sheet's current names into its document (`doc.names`), so
3320
+ * documents passed to `onDocumentChange` or read from `document` carry them.
3321
+ */
3322
+ syncDocumentNames() {
3323
+ for (const rt of this.runtimes) {
3324
+ const names = this.names.filter((n) => n.sheetId === void 0 || n.sheetId === rt.doc.id).map((n) => ({ ...n }));
3325
+ if (names.length > 0) rt.doc.names = names;
3326
+ else delete rt.doc.names;
3327
+ }
3328
+ }
3329
+ /**
3330
+ * A deep copy of the workbook: every sheet, the active sheet and the
3331
+ * defined names. The names are in `names` only (not repeated in each
3332
+ * sheet's `names`).
3333
+ */
3084
3334
  getWorkbook() {
3085
- return JSON.parse(JSON.stringify(this.workbookSnapshot()));
3335
+ const snapshot = this.workbookSnapshot();
3336
+ return JSON.parse(JSON.stringify({ ...snapshot, sheets: snapshot.sheets.map(withoutNames) }));
3086
3337
  }
3087
3338
  /** Replaces the whole workbook (sheets, names, active sheet). Clears undo history. */
3088
3339
  loadWorkbook(workbook) {
@@ -3097,7 +3348,12 @@ var SpreadsheetController = (_class6 = class {
3097
3348
  for (const rt of this.runtimes) this.withSheet(rt, () => this.rederiveTypedValues());
3098
3349
  this.recalculateAll();
3099
3350
  this.notifyChange();
3100
- _optionalChain([this, 'access', _117 => _117.onSelectionChange, 'optionalCall', _118 => _118(this.activeCell, this.selectedRange)]);
3351
+ _optionalChain([this, 'access', _119 => _119.onSelectionChange, 'optionalCall', _120 => _120(this.activeCell, this.selectedRange)]);
3352
+ }
3353
+ /** The workbook as undo data; sheets leave out their copies of the names. */
3354
+ serializeWorkbookSnapshot() {
3355
+ const snapshot = this.workbookSnapshot();
3356
+ return JSON.stringify({ ...snapshot, sheets: snapshot.sheets.map(withoutNames) });
3101
3357
  }
3102
3358
  workbookSnapshot() {
3103
3359
  return {
@@ -3127,7 +3383,19 @@ var SpreadsheetController = (_class6 = class {
3127
3383
  });
3128
3384
  this.runtimes = runtimes;
3129
3385
  this.active = this.ctx = _nullishCoalesce(runtimes.find((rt) => rt.doc.id === workbook.activeSheetId), () => ( runtimes[0]));
3130
- this.names = (_nullishCoalesce(workbook.names, () => ( []))).filter((n) => n.sheetId === void 0 || ids.has(n.sheetId)).map((n) => ({ ...n, refersTo: n.refersTo.startsWith("=") ? n.refersTo : `=${n.refersTo}` }));
3386
+ const seen = /* @__PURE__ */ new Set();
3387
+ this.names = [];
3388
+ const add = (n) => {
3389
+ if (!n || seen.has(nameKey(n))) return;
3390
+ seen.add(nameKey(n));
3391
+ this.names.push(n);
3392
+ };
3393
+ for (const n of _nullishCoalesce(workbook.names, () => ( []))) {
3394
+ if (_optionalChain([n, 'optionalAccess', _121 => _121.sheetId]) === void 0 || ids.has(n.sheetId)) add(normalizeSavedName(n, _optionalChain([n, 'optionalAccess', _122 => _122.sheetId])));
3395
+ }
3396
+ for (const rt of runtimes) {
3397
+ for (const n of namesFromDocument(rt.doc, rt.doc.id)) add(n);
3398
+ }
3131
3399
  if (resetSelection) {
3132
3400
  this.activeCell = null;
3133
3401
  this.selectedRange = null;
@@ -3169,7 +3437,7 @@ var SpreadsheetController = (_class6 = class {
3169
3437
  return {
3170
3438
  value: parsed.value,
3171
3439
  ...numberFormat ? { numberFormat } : {},
3172
- ..._optionalChain([existing, 'optionalAccess', _119 => _119.explicitNumberFormat]) ? { explicitNumberFormat: true } : {},
3440
+ ..._optionalChain([existing, 'optionalAccess', _123 => _123.explicitNumberFormat]) ? { explicitNumberFormat: true } : {},
3173
3441
  format: fixed === void 0 && parsed.cellFormat && (!format || format === "text") ? parsed.cellFormat : format
3174
3442
  };
3175
3443
  }
@@ -3178,14 +3446,14 @@ var SpreadsheetController = (_class6 = class {
3178
3446
  * one, else its column's. Undefined lets typed input choose one.
3179
3447
  */
3180
3448
  fixedNumberFormat(col, existing) {
3181
- if (_optionalChain([existing, 'optionalAccess', _120 => _120.explicitNumberFormat]) && existing.numberFormat !== void 0) return existing.numberFormat;
3182
- return _optionalChain([col, 'optionalAccess', _121 => _121.numberFormat]) && !isGeneralNumberFormat(col.numberFormat) ? col.numberFormat : void 0;
3449
+ if (_optionalChain([existing, 'optionalAccess', _124 => _124.explicitNumberFormat]) && existing.numberFormat !== void 0) return existing.numberFormat;
3450
+ return _optionalChain([col, 'optionalAccess', _125 => _125.numberFormat]) && !isGeneralNumberFormat(col.numberFormat) ? col.numberFormat : void 0;
3183
3451
  }
3184
3452
  /** `numberFormat` / `explicitNumberFormat` fields for a formula, bound or spilled cell. */
3185
3453
  fixedNumberFormatFields(col, existing) {
3186
3454
  const numberFormat = this.fixedNumberFormat(col, existing);
3187
3455
  if (numberFormat === void 0) return {};
3188
- return _optionalChain([existing, 'optionalAccess', _122 => _122.explicitNumberFormat]) ? { numberFormat, explicitNumberFormat: true } : { numberFormat };
3456
+ return _optionalChain([existing, 'optionalAccess', _126 => _126.explicitNumberFormat]) ? { numberFormat, explicitNumberFormat: true } : { numberFormat };
3189
3457
  }
3190
3458
  /**
3191
3459
  * Typed input for a bound field, coerced by the field's declared type:
@@ -3195,7 +3463,7 @@ var SpreadsheetController = (_class6 = class {
3195
3463
  */
3196
3464
  boundInputValue(dataSourceId, field, raw) {
3197
3465
  if (raw.startsWith("=")) return raw;
3198
- const type = _optionalChain([this, 'access', _123 => _123.binder, 'access', _124 => _124.getDataSource, 'call', _125 => _125(dataSourceId), 'optionalAccess', _126 => _126.getFields, 'call', _127 => _127(), 'access', _128 => _128.find, 'call', _129 => _129((f) => f.key === field), 'optionalAccess', _130 => _130.type]);
3466
+ const type = _optionalChain([this, 'access', _127 => _127.binder, 'access', _128 => _128.getDataSource, 'call', _129 => _129(dataSourceId), 'optionalAccess', _130 => _130.getFields, 'call', _131 => _131(), 'access', _132 => _132.find, 'call', _133 => _133((f) => f.key === field), 'optionalAccess', _134 => _134.type]);
3199
3467
  if (type !== "number" && type !== "boolean" && type !== "date") return raw;
3200
3468
  const parsed = _chunkEWCOFSCQcjs.parseCellInput.call(void 0, raw);
3201
3469
  if (type === "number" && parsed.type === "number") return parsed.value;
@@ -3260,7 +3528,7 @@ var SpreadsheetController = (_class6 = class {
3260
3528
  return this.document.columns.find((c) => c.key.toUpperCase() === upper);
3261
3529
  }
3262
3530
  getCell(rowId, colId) {
3263
- const existing = _optionalChain([this, 'access', _131 => _131.document, 'access', _132 => _132.cells, 'access', _133 => _133[rowId], 'optionalAccess', _134 => _134[colId]]);
3531
+ const existing = _optionalChain([this, 'access', _135 => _135.document, 'access', _136 => _136.cells, 'access', _137 => _137[rowId], 'optionalAccess', _138 => _138[colId]]);
3264
3532
  if (existing && existing.raw !== "") return existing;
3265
3533
  if (this.spillCells.size > 0) {
3266
3534
  const spilled = this.spillCells.get(spillCellId(rowId, colId));
@@ -3271,7 +3539,7 @@ var SpreadsheetController = (_class6 = class {
3271
3539
  }
3272
3540
  /** `getCell` for a row and column already looked up. */
3273
3541
  cellOf(row, col) {
3274
- const existing = _optionalChain([this, 'access', _135 => _135.document, 'access', _136 => _136.cells, 'access', _137 => _137[row.id], 'optionalAccess', _138 => _138[col.id]]);
3542
+ const existing = _optionalChain([this, 'access', _139 => _139.document, 'access', _140 => _140.cells, 'access', _141 => _141[row.id], 'optionalAccess', _142 => _142[col.id]]);
3275
3543
  if (existing && existing.raw !== "") return existing;
3276
3544
  if (this.spillCells.size > 0) {
3277
3545
  const spilled = this.spillCells.get(spillCellId(row.id, col.id));
@@ -3310,7 +3578,7 @@ var SpreadsheetController = (_class6 = class {
3310
3578
  ...this.fixedNumberFormatFields(col, void 0)
3311
3579
  };
3312
3580
  }
3313
- return { raw: "", value: "", format: _optionalChain([col, 'optionalAccess', _139 => _139.format]), ...this.fixedNumberFormatFields(col, void 0) };
3581
+ return { raw: "", value: "", format: _optionalChain([col, 'optionalAccess', _143 => _143.format]), ...this.fixedNumberFormatFields(col, void 0) };
3314
3582
  }
3315
3583
  setCellValue(rowId, colId, raw) {
3316
3584
  this.recordCellSnapshot(rowId, colId);
@@ -3322,14 +3590,14 @@ var SpreadsheetController = (_class6 = class {
3322
3590
  const isFormula = raw.startsWith("=");
3323
3591
  const existing = this.document.cells[rowId][colId];
3324
3592
  let cell;
3325
- if (_optionalChain([col, 'optionalAccess', _140 => _140.type]) === "bound" && col.binding && _optionalChain([row, 'optionalAccess', _141 => _141.recordId])) {
3593
+ if (_optionalChain([col, 'optionalAccess', _144 => _144.type]) === "bound" && col.binding && _optionalChain([row, 'optionalAccess', _145 => _145.recordId])) {
3326
3594
  const value = this.boundInputValue(col.binding.dataSource, col.binding.field, raw);
3327
3595
  this.binder.commitBoundValue(col.binding.dataSource, row.recordId, col.binding.field, value);
3328
3596
  cell = { raw, value, format: col.format, ...this.fixedNumberFormatFields(col, existing) };
3329
3597
  } else if (isFormula) {
3330
- cell = { raw, value: raw, format: _optionalChain([col, 'optionalAccess', _142 => _142.format]), ...this.fixedNumberFormatFields(col, existing) };
3598
+ cell = { raw, value: raw, format: _optionalChain([col, 'optionalAccess', _146 => _146.format]), ...this.fixedNumberFormatFields(col, existing) };
3331
3599
  } else {
3332
- cell = { raw, ...this.typedCell(raw, _optionalChain([col, 'optionalAccess', _143 => _143.format]), col, existing) };
3600
+ cell = { raw, ...this.typedCell(raw, _optionalChain([col, 'optionalAccess', _147 => _147.format]), col, existing) };
3333
3601
  }
3334
3602
  const cellKey2 = this.getCellKey(rowId, colId);
3335
3603
  this.registerFormula(cellKey2, isFormula ? raw : null);
@@ -3348,8 +3616,8 @@ var SpreadsheetController = (_class6 = class {
3348
3616
  } finally {
3349
3617
  this.cfIncremental = false;
3350
3618
  }
3351
- const evaluatedVal = _optionalChain([this, 'access', _144 => _144.document, 'access', _145 => _145.cells, 'access', _146 => _146[rowId], 'access', _147 => _147[colId], 'optionalAccess', _148 => _148.value]);
3352
- _optionalChain([this, 'access', _149 => _149.onCellCommit, 'optionalCall', _150 => _150(rowId, colId, raw, evaluatedVal)]);
3619
+ const evaluatedVal = _optionalChain([this, 'access', _148 => _148.document, 'access', _149 => _149.cells, 'access', _150 => _150[rowId], 'access', _151 => _151[colId], 'optionalAccess', _152 => _152.value]);
3620
+ _optionalChain([this, 'access', _153 => _153.onCellCommit, 'optionalCall', _154 => _154(rowId, colId, raw, evaluatedVal)]);
3353
3621
  }
3354
3622
  getCellKey(rowId, colId) {
3355
3623
  const row = this.findRow(rowId);
@@ -3538,7 +3806,7 @@ var SpreadsheetController = (_class6 = class {
3538
3806
  const stored = this.document.cells[row.id];
3539
3807
  for (let c = 0; c < columns.length; c++) {
3540
3808
  const col = columns[c];
3541
- const cell = _nullishCoalesce(_optionalChain([stored, 'optionalAccess', _151 => _151[col.id]]), () => ( (deriving[c] ? this.getDerivedCell(row, col) : null)));
3809
+ const cell = _nullishCoalesce(_optionalChain([stored, 'optionalAccess', _155 => _155[col.id]]), () => ( (deriving[c] ? this.getDerivedCell(row, col) : null)));
3542
3810
  if (cell && typeof cell.raw === "string" && cell.raw.startsWith("=")) {
3543
3811
  const cellKey2 = `${col.key}${row.index + 1}`.toUpperCase();
3544
3812
  this.registerFormula(cellKey2, cell.raw);
@@ -3559,7 +3827,7 @@ var SpreadsheetController = (_class6 = class {
3559
3827
  const onActive = located.rt === this.active;
3560
3828
  this.withSheet(located.rt, () => {
3561
3829
  const hadSpill = this.spills.has(located.key);
3562
- const spillChanges = _nullishCoalesce(_optionalChain([this, 'access', _152 => _152.spillChanges, 'optionalAccess', _153 => _153.size]), () => ( 0));
3830
+ const spillChanges = _nullishCoalesce(_optionalChain([this, 'access', _156 => _156.spillChanges, 'optionalAccess', _157 => _157.size]), () => ( 0));
3563
3831
  if (onActive) this.markValueChanged(located.key);
3564
3832
  if (plan.cyclic.has(qualified)) {
3565
3833
  this.markCycle(located.key);
@@ -3567,7 +3835,7 @@ var SpreadsheetController = (_class6 = class {
3567
3835
  this.evalSingleCellByKey(located.key);
3568
3836
  }
3569
3837
  if (onActive) this.markValueChanged(located.key);
3570
- const spilled = hadSpill || this.spills.has(located.key) || (_nullishCoalesce(_optionalChain([this, 'access', _154 => _154.spillChanges, 'optionalAccess', _155 => _155.size]), () => ( 0))) !== spillChanges;
3838
+ const spilled = hadSpill || this.spills.has(located.key) || (_nullishCoalesce(_optionalChain([this, 'access', _158 => _158.spillChanges, 'optionalAccess', _159 => _159.size]), () => ( 0))) !== spillChanges;
3571
3839
  this.invalidateRangeCache(located.rt.doc.id, spilled ? null : _chunkEWCOFSCQcjs.colNameToIndex.call(void 0, located.key.replace(/\d+$/, "")));
3572
3840
  });
3573
3841
  }
@@ -3684,7 +3952,7 @@ var SpreadsheetController = (_class6 = class {
3684
3952
  if (r === row && c === col) continue;
3685
3953
  const rowObj = this.document.rows[r];
3686
3954
  const key = `${column.key}${r + 1}`.toUpperCase();
3687
- const stored = _optionalChain([this, 'access', _156 => _156.document, 'access', _157 => _157.cells, 'access', _158 => _158[rowObj.id], 'optionalAccess', _159 => _159[column.id]]);
3955
+ const stored = _optionalChain([this, 'access', _160 => _160.document, 'access', _161 => _161.cells, 'access', _162 => _162[rowObj.id], 'optionalAccess', _163 => _163[column.id]]);
3688
3956
  const raw = stored ? stored.raw : this.getDerivedCell(rowObj, column).raw;
3689
3957
  const owner = this.spilledBy.get(key);
3690
3958
  if (raw !== "") {
@@ -3717,7 +3985,7 @@ var SpreadsheetController = (_class6 = class {
3717
3985
  value,
3718
3986
  format: column.format,
3719
3987
  spillAnchor: anchor,
3720
- ...this.fixedNumberFormatFields(column, _optionalChain([this, 'access', _160 => _160.document, 'access', _161 => _161.cells, 'access', _162 => _162[rowObj.id], 'optionalAccess', _163 => _163[column.id]]))
3988
+ ...this.fixedNumberFormatFields(column, _optionalChain([this, 'access', _164 => _164.document, 'access', _165 => _165.cells, 'access', _166 => _166[rowObj.id], 'optionalAccess', _167 => _167[column.id]]))
3721
3989
  };
3722
3990
  if (_chunkEWCOFSCQcjs.isFormulaError.call(void 0, value)) {
3723
3991
  display.error = value;
@@ -3726,9 +3994,9 @@ var SpreadsheetController = (_class6 = class {
3726
3994
  this.spillCells.set(spillCellId(rowObj.id, column.id), display);
3727
3995
  if (this.spilledBy.get(key) !== anchor) {
3728
3996
  this.spilledBy.set(key, anchor);
3729
- _optionalChain([this, 'access', _164 => _164.spillChanges, 'optionalAccess', _165 => _165.add, 'call', _166 => _166(this.qualify(key))]);
3997
+ _optionalChain([this, 'access', _168 => _168.spillChanges, 'optionalAccess', _169 => _169.add, 'call', _170 => _170(this.qualify(key))]);
3730
3998
  } else if (!linked.has(this.qualify(key))) {
3731
- _optionalChain([this, 'access', _167 => _167.spillChanges, 'optionalAccess', _168 => _168.add, 'call', _169 => _169(this.qualify(key))]);
3999
+ _optionalChain([this, 'access', _171 => _171.spillChanges, 'optionalAccess', _172 => _172.add, 'call', _173 => _173(this.qualify(key))]);
3732
4000
  }
3733
4001
  cells.push({ key, rowId: rowObj.id, colId: column.id });
3734
4002
  }
@@ -3757,7 +4025,7 @@ var SpreadsheetController = (_class6 = class {
3757
4025
  if (this.spilledBy.get(cell.key) !== anchor) return;
3758
4026
  this.spilledBy.delete(cell.key);
3759
4027
  this.spillCells.delete(spillCellId(cell.rowId, cell.colId));
3760
- _optionalChain([this, 'access', _170 => _170.spillChanges, 'optionalAccess', _171 => _171.add, 'call', _172 => _172(this.qualify(cell.key))]);
4028
+ _optionalChain([this, 'access', _174 => _174.spillChanges, 'optionalAccess', _175 => _175.add, 'call', _176 => _176(this.qualify(cell.key))]);
3761
4029
  }
3762
4030
  resolveSpillByCoord(colStr, rowNum) {
3763
4031
  const record = this.spills.get(`${colStr}${rowNum}`.toUpperCase());
@@ -3827,7 +4095,7 @@ var SpreadsheetController = (_class6 = class {
3827
4095
  const maxC = Math.max(startC, endC);
3828
4096
  const minR = Math.min(sRow, eRow);
3829
4097
  const maxR = Math.min(Math.max(sRow, eRow), _chunkEWCOFSCQcjs.WHOLE_COLUMN_END_ROW, this.document.rows.length);
3830
- const skipBlanks = _optionalChain([options, 'optionalAccess', _173 => _173.skipBlanks]) === true;
4098
+ const skipBlanks = _optionalChain([options, 'optionalAccess', _177 => _177.skipBlanks]) === true;
3831
4099
  const cacheable = this.rangeCache !== null && !this.valueOverride && (maxC - minC + 1) * (maxR - minR + 1) >= RANGE_CACHE_MIN_CELLS;
3832
4100
  const cacheKey = cacheable ? `${this.document.id}|${minC}|${maxC}|${minR}|${maxR}|${skipBlanks ? 1 : 0}` : "";
3833
4101
  if (cacheable) {
@@ -3851,10 +4119,10 @@ var SpreadsheetController = (_class6 = class {
3851
4119
  if (override && override.row === r - 1) {
3852
4120
  value = override.value;
3853
4121
  } else {
3854
- const stored = _optionalChain([cells, 'access', _174 => _174[row.id], 'optionalAccess', _175 => _175[colId]]);
4122
+ const stored = _optionalChain([cells, 'access', _178 => _178[row.id], 'optionalAccess', _179 => _179[colId]]);
3855
4123
  if (stored && stored.raw !== "") value = stored.value;
3856
4124
  else {
3857
- const spilled = _optionalChain([spills, 'optionalAccess', _176 => _176.get, 'call', _177 => _177(spillCellId(row.id, colId))]);
4125
+ const spilled = _optionalChain([spills, 'optionalAccess', _180 => _180.get, 'call', _181 => _181(spillCellId(row.id, colId))]);
3858
4126
  if (spilled) value = spilled.value;
3859
4127
  else if (stored && (plain || !stored.explicitNumberFormat)) value = stored.value;
3860
4128
  else if (plain) value = "";
@@ -3870,7 +4138,7 @@ var SpreadsheetController = (_class6 = class {
3870
4138
  return results;
3871
4139
  }
3872
4140
  resolveCurrentRowProperty(prop) {
3873
- const rowIndex = _nullishCoalesce(this.evaluatingRowIndex, () => ( _optionalChain([this, 'access', _178 => _178.activeCell, 'optionalAccess', _179 => _179.row])));
4141
+ const rowIndex = _nullishCoalesce(this.evaluatingRowIndex, () => ( _optionalChain([this, 'access', _182 => _182.activeCell, 'optionalAccess', _183 => _183.row])));
3874
4142
  if (rowIndex === void 0 || rowIndex === null) return 0;
3875
4143
  const row = this.document.rows[rowIndex];
3876
4144
  if (!row || !row.recordId || !this.primaryDataSourceId) return 0;
@@ -3888,8 +4156,8 @@ var SpreadsheetController = (_class6 = class {
3888
4156
  this.activeCell = {
3889
4157
  row: activeRow,
3890
4158
  col: activeCol,
3891
- rowId: _optionalChain([rowObj, 'optionalAccess', _180 => _180.id]),
3892
- colId: _optionalChain([colObj, 'optionalAccess', _181 => _181.id])
4159
+ rowId: _optionalChain([rowObj, 'optionalAccess', _184 => _184.id]),
4160
+ colId: _optionalChain([colObj, 'optionalAccess', _185 => _185.id])
3893
4161
  };
3894
4162
  if (extendSelection && this.selectedRange) {
3895
4163
  this.selectedRange = this.expandRangeToMerges({
@@ -3908,16 +4176,16 @@ var SpreadsheetController = (_class6 = class {
3908
4176
  endCol: clampedCol
3909
4177
  };
3910
4178
  }
3911
- _optionalChain([this, 'access', _182 => _182.onSelectionChange, 'optionalCall', _183 => _183(this.activeCell, this.selectedRange)]);
4179
+ _optionalChain([this, 'access', _186 => _186.onSelectionChange, 'optionalCall', _187 => _187(this.activeCell, this.selectedRange)]);
3912
4180
  }
3913
4181
  selectRange(range) {
3914
4182
  this.selectedRange = range;
3915
- _optionalChain([this, 'access', _184 => _184.onSelectionChange, 'optionalCall', _185 => _185(this.activeCell, this.selectedRange)]);
4183
+ _optionalChain([this, 'access', _188 => _188.onSelectionChange, 'optionalCall', _189 => _189(this.activeCell, this.selectedRange)]);
3916
4184
  }
3917
4185
  startEditing(row, col, initialValue) {
3918
- this.selectCell(_nullishCoalesce(_nullishCoalesce(row, () => ( _optionalChain([this, 'access', _186 => _186.activeCell, 'optionalAccess', _187 => _187.row]))), () => ( 0)), _nullishCoalesce(_nullishCoalesce(col, () => ( _optionalChain([this, 'access', _188 => _188.activeCell, 'optionalAccess', _189 => _189.col]))), () => ( 0)));
3919
- const targetRow = _nullishCoalesce(_optionalChain([this, 'access', _190 => _190.activeCell, 'optionalAccess', _191 => _191.row]), () => ( 0));
3920
- const targetCol = _nullishCoalesce(_optionalChain([this, 'access', _192 => _192.activeCell, 'optionalAccess', _193 => _193.col]), () => ( 0));
4186
+ this.selectCell(_nullishCoalesce(_nullishCoalesce(row, () => ( _optionalChain([this, 'access', _190 => _190.activeCell, 'optionalAccess', _191 => _191.row]))), () => ( 0)), _nullishCoalesce(_nullishCoalesce(col, () => ( _optionalChain([this, 'access', _192 => _192.activeCell, 'optionalAccess', _193 => _193.col]))), () => ( 0)));
4187
+ const targetRow = _nullishCoalesce(_optionalChain([this, 'access', _194 => _194.activeCell, 'optionalAccess', _195 => _195.row]), () => ( 0));
4188
+ const targetCol = _nullishCoalesce(_optionalChain([this, 'access', _196 => _196.activeCell, 'optionalAccess', _197 => _197.col]), () => ( 0));
3921
4189
  const rowObj = this.document.rows[targetRow];
3922
4190
  const colObj = this.document.columns[targetCol];
3923
4191
  if (!rowObj || !colObj) return;
@@ -3968,7 +4236,7 @@ var SpreadsheetController = (_class6 = class {
3968
4236
  }
3969
4237
  /** Validates input; when it fails, records and returns the prompt. */
3970
4238
  checkInput(rowId, colId, row, col, raw, editing) {
3971
- if (!_optionalChain([this, 'access', _194 => _194.document, 'access', _195 => _195.table, 'optionalAccess', _196 => _196.dataValidations, 'optionalAccess', _197 => _197.length])) return null;
4239
+ if (!_optionalChain([this, 'access', _198 => _198.document, 'access', _199 => _199.table, 'optionalAccess', _200 => _200.dataValidations, 'optionalAccess', _201 => _201.length])) return null;
3972
4240
  if (this.getCell(rowId, colId).raw === raw) return null;
3973
4241
  const result = this.validateCellInput(row, col, raw);
3974
4242
  if (result.valid) return null;
@@ -3985,7 +4253,7 @@ var SpreadsheetController = (_class6 = class {
3985
4253
  const prompt = this.validationPrompt;
3986
4254
  if (!prompt) return;
3987
4255
  this.validationPrompt = null;
3988
- const editingSameCell = prompt.editing && _optionalChain([this, 'access', _198 => _198.editingCell, 'optionalAccess', _199 => _199.rowId]) === prompt.rowId && _optionalChain([this, 'access', _200 => _200.editingCell, 'optionalAccess', _201 => _201.colId]) === prompt.colId;
4256
+ const editingSameCell = prompt.editing && _optionalChain([this, 'access', _202 => _202.editingCell, 'optionalAccess', _203 => _203.rowId]) === prompt.rowId && _optionalChain([this, 'access', _204 => _204.editingCell, 'optionalAccess', _205 => _205.colId]) === prompt.colId;
3989
4257
  if (action === "accept" && prompt.result.errorStyle !== "stop") {
3990
4258
  this.setCellValue(prompt.rowId, prompt.colId, prompt.raw);
3991
4259
  if (editingSameCell) {
@@ -4032,18 +4300,18 @@ var SpreadsheetController = (_class6 = class {
4032
4300
  // --- Grid Structure Mutations ---
4033
4301
  insertColumn(index, config) {
4034
4302
  this.recordSnapshot();
4035
- const newId = _optionalChain([config, 'optionalAccess', _202 => _202.id]) || this.generateId("col");
4303
+ const newId = _optionalChain([config, 'optionalAccess', _206 => _206.id]) || this.generateId("col");
4036
4304
  const newCol = {
4037
4305
  id: newId,
4038
4306
  key: _chunkEWCOFSCQcjs.indexToColName.call(void 0, index),
4039
- title: _optionalChain([config, 'optionalAccess', _203 => _203.title]) || _chunkEWCOFSCQcjs.indexToColName.call(void 0, index),
4040
- width: _optionalChain([config, 'optionalAccess', _204 => _204.width]) || 130,
4041
- type: _optionalChain([config, 'optionalAccess', _205 => _205.type]) || "freeform",
4042
- binding: _optionalChain([config, 'optionalAccess', _206 => _206.binding]),
4043
- formula: _optionalChain([config, 'optionalAccess', _207 => _207.formula]),
4044
- format: _optionalChain([config, 'optionalAccess', _208 => _208.format]) || "text",
4045
- ..._optionalChain([config, 'optionalAccess', _209 => _209.numberFormat]) ? { numberFormat: config.numberFormat } : {},
4046
- readOnly: _optionalChain([config, 'optionalAccess', _210 => _210.readOnly])
4307
+ title: _optionalChain([config, 'optionalAccess', _207 => _207.title]) || _chunkEWCOFSCQcjs.indexToColName.call(void 0, index),
4308
+ width: _optionalChain([config, 'optionalAccess', _208 => _208.width]) || 130,
4309
+ type: _optionalChain([config, 'optionalAccess', _209 => _209.type]) || "freeform",
4310
+ binding: _optionalChain([config, 'optionalAccess', _210 => _210.binding]),
4311
+ formula: _optionalChain([config, 'optionalAccess', _211 => _211.formula]),
4312
+ format: _optionalChain([config, 'optionalAccess', _212 => _212.format]) || "text",
4313
+ ..._optionalChain([config, 'optionalAccess', _213 => _213.numberFormat]) ? { numberFormat: config.numberFormat } : {},
4314
+ readOnly: _optionalChain([config, 'optionalAccess', _214 => _214.readOnly])
4047
4315
  };
4048
4316
  this.shiftReferences({ axis: "col", index, type: "insert" });
4049
4317
  this.adjustTableForStructuralChange({ axis: "col", index, type: "insert" });
@@ -4068,13 +4336,13 @@ var SpreadsheetController = (_class6 = class {
4068
4336
  }
4069
4337
  insertRow(index, config) {
4070
4338
  this.recordSnapshot();
4071
- const newId = _optionalChain([config, 'optionalAccess', _211 => _211.id]) || this.generateId("row");
4339
+ const newId = _optionalChain([config, 'optionalAccess', _215 => _215.id]) || this.generateId("row");
4072
4340
  const newRow = {
4073
4341
  id: newId,
4074
4342
  index,
4075
- height: _optionalChain([config, 'optionalAccess', _212 => _212.height]) || 32,
4076
- recordId: _optionalChain([config, 'optionalAccess', _213 => _213.recordId]),
4077
- type: _optionalChain([config, 'optionalAccess', _214 => _214.type]) || "freeform"
4343
+ height: _optionalChain([config, 'optionalAccess', _216 => _216.height]) || 32,
4344
+ recordId: _optionalChain([config, 'optionalAccess', _217 => _217.recordId]),
4345
+ type: _optionalChain([config, 'optionalAccess', _218 => _218.type]) || "freeform"
4078
4346
  };
4079
4347
  this.shiftReferences({ axis: "row", index, type: "insert" });
4080
4348
  this.adjustTableForStructuralChange({ axis: "row", index, type: "insert" });
@@ -4108,14 +4376,14 @@ var SpreadsheetController = (_class6 = class {
4108
4376
  const filter = this.referencesTo(changed, rt);
4109
4377
  for (const rowCells of Object.values(rt.doc.cells)) {
4110
4378
  for (const cell of Object.values(rowCells)) {
4111
- if (_optionalChain([cell, 'access', _215 => _215.raw, 'optionalAccess', _216 => _216.startsWith, 'call', _217 => _217("=")])) {
4379
+ if (_optionalChain([cell, 'access', _219 => _219.raw, 'optionalAccess', _220 => _220.startsWith, 'call', _221 => _221("=")])) {
4112
4380
  cell.raw = shiftFormulaReferences(cell.raw, change, filter);
4113
4381
  }
4114
4382
  }
4115
4383
  }
4116
4384
  if (change.axis === "col") {
4117
4385
  for (const col of rt.doc.columns) {
4118
- if (_optionalChain([col, 'access', _218 => _218.formula, 'optionalAccess', _219 => _219.startsWith, 'call', _220 => _220("=")])) {
4386
+ if (_optionalChain([col, 'access', _222 => _222.formula, 'optionalAccess', _223 => _223.startsWith, 'call', _224 => _224("=")])) {
4119
4387
  col.formula = shiftFormulaReferences(col.formula, change, filter);
4120
4388
  }
4121
4389
  }
@@ -4250,7 +4518,7 @@ var SpreadsheetController = (_class6 = class {
4250
4518
  const commits = this.pendingCommits;
4251
4519
  this.pendingCommits = [];
4252
4520
  for (const [rowId, colId, raw] of commits) {
4253
- _optionalChain([this, 'access', _221 => _221.onCellCommit, 'optionalCall', _222 => _222(rowId, colId, raw, _optionalChain([this, 'access', _223 => _223.document, 'access', _224 => _224.cells, 'access', _225 => _225[rowId], 'optionalAccess', _226 => _226[colId], 'optionalAccess', _227 => _227.value]))]);
4521
+ _optionalChain([this, 'access', _225 => _225.onCellCommit, 'optionalCall', _226 => _226(rowId, colId, raw, _optionalChain([this, 'access', _227 => _227.document, 'access', _228 => _228.cells, 'access', _229 => _229[rowId], 'optionalAccess', _230 => _230[colId], 'optionalAccess', _231 => _231.value]))]);
4254
4522
  }
4255
4523
  }
4256
4524
  // --- CSV ---
@@ -4349,7 +4617,7 @@ var SpreadsheetController = (_class6 = class {
4349
4617
  const r = normalizeRange(this.selectedRange);
4350
4618
  return { row: r.startRow, col: r.startCol };
4351
4619
  }
4352
- return { row: _nullishCoalesce(_optionalChain([this, 'access', _228 => _228.activeCell, 'optionalAccess', _229 => _229.row]), () => ( 0)), col: _nullishCoalesce(_optionalChain([this, 'access', _230 => _230.activeCell, 'optionalAccess', _231 => _231.col]), () => ( 0)) };
4620
+ return { row: _nullishCoalesce(_optionalChain([this, 'access', _232 => _232.activeCell, 'optionalAccess', _233 => _233.row]), () => ( 0)), col: _nullishCoalesce(_optionalChain([this, 'access', _234 => _234.activeCell, 'optionalAccess', _235 => _235.col]), () => ( 0)) };
4353
4621
  }
4354
4622
  // --- Table operations: shared helpers ---
4355
4623
  /** The table settings object, created on first use. */
@@ -4386,7 +4654,7 @@ var SpreadsheetController = (_class6 = class {
4386
4654
  const filter = this.referencesTo(moved, rt);
4387
4655
  for (const rowCells of Object.values(rt.doc.cells)) {
4388
4656
  for (const cell of Object.values(rowCells)) {
4389
- if (_optionalChain([cell, 'access', _232 => _232.raw, 'optionalAccess', _233 => _233.startsWith, 'call', _234 => _234("=")])) {
4657
+ if (_optionalChain([cell, 'access', _236 => _236.raw, 'optionalAccess', _237 => _237.startsWith, 'call', _238 => _238("=")])) {
4390
4658
  cell.raw = remapFormulaReferences(cell.raw, moveCell, filter);
4391
4659
  }
4392
4660
  }
@@ -4400,8 +4668,8 @@ var SpreadsheetController = (_class6 = class {
4400
4668
  */
4401
4669
  adjustTableForStructuralChange(change) {
4402
4670
  this.adjustRulesForStructuralChange(change);
4403
- const merges = _optionalChain([this, 'access', _235 => _235.document, 'access', _236 => _236.table, 'optionalAccess', _237 => _237.merges]);
4404
- if (!_optionalChain([merges, 'optionalAccess', _238 => _238.length])) return;
4671
+ const merges = _optionalChain([this, 'access', _239 => _239.document, 'access', _240 => _240.table, 'optionalAccess', _241 => _241.merges]);
4672
+ if (!_optionalChain([merges, 'optionalAccess', _242 => _242.length])) return;
4405
4673
  const startKey = change.axis === "row" ? "startRow" : "startCol";
4406
4674
  const endKey = change.axis === "row" ? "endRow" : "endCol";
4407
4675
  const next = [];
@@ -4432,8 +4700,8 @@ var SpreadsheetController = (_class6 = class {
4432
4700
  const colCount = this.document.columns.length;
4433
4701
  const body = this.getBodyRowBounds();
4434
4702
  const range = options.range ? normalizeRange(options.range) : null;
4435
- const startRow = Math.max(_nullishCoalesce(_optionalChain([range, 'optionalAccess', _239 => _239.startRow]), () => ( body.start)), body.start);
4436
- const endRow = Math.min(_nullishCoalesce(_optionalChain([range, 'optionalAccess', _240 => _240.endRow]), () => ( body.end)), body.end);
4703
+ const startRow = Math.max(_nullishCoalesce(_optionalChain([range, 'optionalAccess', _243 => _243.startRow]), () => ( body.start)), body.start);
4704
+ const endRow = Math.min(_nullishCoalesce(_optionalChain([range, 'optionalAccess', _244 => _244.endRow]), () => ( body.end)), body.end);
4437
4705
  const startCol = range ? Math.max(0, range.startCol) : 0;
4438
4706
  const endCol = range ? Math.min(colCount - 1, range.endCol) : colCount - 1;
4439
4707
  if (endRow - startRow < 1 || startCol > endCol) return false;
@@ -4443,7 +4711,7 @@ var SpreadsheetController = (_class6 = class {
4443
4711
  }));
4444
4712
  if (keyCols.length === 0 || keyCols.some((k) => k.index < startCol || k.index > endCol)) return false;
4445
4713
  const area = { startRow, startCol, endRow, endCol };
4446
- if ((_nullishCoalesce(_optionalChain([this, 'access', _241 => _241.document, 'access', _242 => _242.table, 'optionalAccess', _243 => _243.merges]), () => ( []))).some((m) => rangesIntersect(m, area))) return false;
4714
+ if ((_nullishCoalesce(_optionalChain([this, 'access', _245 => _245.document, 'access', _246 => _246.table, 'optionalAccess', _247 => _247.merges]), () => ( []))).some((m) => rangesIntersect(m, area))) return false;
4447
4715
  if (this.intersectsSpill(area)) return false;
4448
4716
  const sourceRows = [];
4449
4717
  for (let r = startRow; r <= endRow; r++) sourceRows.push(r);
@@ -4464,6 +4732,10 @@ var SpreadsheetController = (_class6 = class {
4464
4732
  if (target === void 0 || col < startCol || col > endCol) return null;
4465
4733
  return { row: target, col };
4466
4734
  });
4735
+ this.moveRulesForSort(
4736
+ { startRow, startCol, endRow, endCol: wholeRows ? Number.MAX_SAFE_INTEGER : endCol },
4737
+ (row) => _nullishCoalesce(newIndexOf.get(row), () => ( row))
4738
+ );
4467
4739
  if (wholeRows) {
4468
4740
  const moved = sorted.map((r) => this.document.rows[r]);
4469
4741
  this.document.rows.splice(startRow, moved.length, ...moved);
@@ -4471,7 +4743,7 @@ var SpreadsheetController = (_class6 = class {
4471
4743
  const colIds = this.document.columns.slice(startCol, endCol + 1).map((c) => c.id);
4472
4744
  const snapshot = sorted.map((oldRow) => {
4473
4745
  const rowId = this.document.rows[oldRow].id;
4474
- return colIds.map((colId) => _optionalChain([this, 'access', _244 => _244.document, 'access', _245 => _245.cells, 'access', _246 => _246[rowId], 'optionalAccess', _247 => _247[colId]]));
4746
+ return colIds.map((colId) => _optionalChain([this, 'access', _248 => _248.document, 'access', _249 => _249.cells, 'access', _250 => _250[rowId], 'optionalAccess', _251 => _251[colId]]));
4475
4747
  });
4476
4748
  snapshot.forEach((cells, i) => {
4477
4749
  const rowId = this.document.rows[startRow + i].id;
@@ -4487,7 +4759,7 @@ var SpreadsheetController = (_class6 = class {
4487
4759
  }
4488
4760
  // --- Filters ---
4489
4761
  getFilterState() {
4490
- return _nullishCoalesce(_optionalChain([this, 'access', _248 => _248.document, 'access', _249 => _249.table, 'optionalAccess', _250 => _250.filter]), () => ( { enabled: false, rules: [] }));
4762
+ return _nullishCoalesce(_optionalChain([this, 'access', _252 => _252.document, 'access', _253 => _253.table, 'optionalAccess', _254 => _254.filter]), () => ( { enabled: false, rules: [] }));
4491
4763
  }
4492
4764
  /** Replaces all filter rules (and turns filters on when there are any). */
4493
4765
  setFilterRules(rules) {
@@ -4564,7 +4836,7 @@ var SpreadsheetController = (_class6 = class {
4564
4836
  }
4565
4837
  setTableCount(key, count, max) {
4566
4838
  const value = Math.max(0, Math.min(Math.floor(count), max));
4567
- if ((_nullishCoalesce(_optionalChain([this, 'access', _251 => _251.document, 'access', _252 => _252.table, 'optionalAccess', _253 => _253[key]]), () => ( 0))) === value) return;
4839
+ if ((_nullishCoalesce(_optionalChain([this, 'access', _255 => _255.document, 'access', _256 => _256.table, 'optionalAccess', _257 => _257[key]]), () => ( 0))) === value) return;
4568
4840
  this.applyTableChange(() => {
4569
4841
  this.table[key] = value;
4570
4842
  });
@@ -4594,7 +4866,7 @@ var SpreadsheetController = (_class6 = class {
4594
4866
  const cells = this.document.cells[row.id] ??= {};
4595
4867
  const existing = cells[col.id];
4596
4868
  if (code === null) {
4597
- if (!_optionalChain([existing, 'optionalAccess', _254 => _254.explicitNumberFormat])) continue;
4869
+ if (!_optionalChain([existing, 'optionalAccess', _258 => _258.explicitNumberFormat])) continue;
4598
4870
  if (existing.raw === "" && existing.value === "" && !existing.error) {
4599
4871
  delete cells[col.id];
4600
4872
  } else {
@@ -4604,7 +4876,7 @@ var SpreadsheetController = (_class6 = class {
4604
4876
  } else {
4605
4877
  cells[col.id] = {
4606
4878
  ..._nullishCoalesce(existing, () => ( { raw: "", value: "" })),
4607
- format: _nullishCoalesce(_nullishCoalesce(kind, () => ( _optionalChain([existing, 'optionalAccess', _255 => _255.format]))), () => ( col.format)),
4879
+ format: _nullishCoalesce(_nullishCoalesce(kind, () => ( _optionalChain([existing, 'optionalAccess', _259 => _259.format]))), () => ( col.format)),
4608
4880
  numberFormat: code,
4609
4881
  explicitNumberFormat: true
4610
4882
  };
@@ -4630,7 +4902,7 @@ var SpreadsheetController = (_class6 = class {
4630
4902
  else col.numberFormat = code;
4631
4903
  for (const row of this.document.rows) {
4632
4904
  const cells = this.document.cells[row.id];
4633
- const cell = _optionalChain([cells, 'optionalAccess', _256 => _256[col.id]]);
4905
+ const cell = _optionalChain([cells, 'optionalAccess', _260 => _260[col.id]]);
4634
4906
  if (cells && cell && !cell.explicitNumberFormat) {
4635
4907
  cells[col.id] = this.withNumberFormat(cell, this.implicitNumberFormat(cell, col, row));
4636
4908
  }
@@ -4655,7 +4927,7 @@ var SpreadsheetController = (_class6 = class {
4655
4927
  const spilled = this.spillCells.get(id);
4656
4928
  if (!spilled) return;
4657
4929
  const { numberFormat: _old, explicitNumberFormat: _explicit, ...rest } = spilled;
4658
- this.spillCells.set(id, { ...rest, ...this.fixedNumberFormatFields(col, _optionalChain([this, 'access', _257 => _257.document, 'access', _258 => _258.cells, 'access', _259 => _259[row.id], 'optionalAccess', _260 => _260[col.id]])) });
4930
+ this.spillCells.set(id, { ...rest, ...this.fixedNumberFormatFields(col, _optionalChain([this, 'access', _261 => _261.document, 'access', _262 => _262.cells, 'access', _263 => _263[row.id], 'optionalAccess', _264 => _264[col.id]])) });
4659
4931
  }
4660
4932
  // --- Hide / unhide ---
4661
4933
  hideRows(indices) {
@@ -4693,7 +4965,7 @@ var SpreadsheetController = (_class6 = class {
4693
4965
  }
4694
4966
  // --- Merged cells ---
4695
4967
  getMerges() {
4696
- return _nullishCoalesce(_optionalChain([this, 'access', _261 => _261.document, 'access', _262 => _262.table, 'optionalAccess', _263 => _263.merges]), () => ( []));
4968
+ return _nullishCoalesce(_optionalChain([this, 'access', _265 => _265.document, 'access', _266 => _266.table, 'optionalAccess', _267 => _267.merges]), () => ( []));
4697
4969
  }
4698
4970
  /** The merge containing (row, col), or null. */
4699
4971
  getMergeAt(row, col) {
@@ -4746,7 +5018,7 @@ var SpreadsheetController = (_class6 = class {
4746
5018
  const rowId = this.document.rows[row].id;
4747
5019
  for (let col = r.startCol; col <= r.endCol; col++) {
4748
5020
  if (row === r.startRow && col === r.startCol) continue;
4749
- _optionalChainDelete([this, 'access', _264 => _264.document, 'access', _265 => _265.cells, 'access', _266 => _266[rowId], 'optionalAccess', _267 => _267[this.document.columns[col].id]]);
5021
+ _optionalChainDelete([this, 'access', _268 => _268.document, 'access', _269 => _269.cells, 'access', _270 => _270[rowId], 'optionalAccess', _271 => _271[this.document.columns[col].id]]);
4750
5022
  }
4751
5023
  }
4752
5024
  this.table.merges = [...merges.filter((m) => !rangeContainsRange(r, m)), r];
@@ -4832,14 +5104,14 @@ var SpreadsheetController = (_class6 = class {
4832
5104
  });
4833
5105
  }
4834
5106
  ungroupRows() {
4835
- if (!_optionalChain([this, 'access', _268 => _268.document, 'access', _269 => _269.table, 'optionalAccess', _270 => _270.grouping])) return;
5107
+ if (!_optionalChain([this, 'access', _272 => _272.document, 'access', _273 => _273.table, 'optionalAccess', _274 => _274.grouping])) return;
4836
5108
  this.applyTableChange(() => {
4837
5109
  delete this.table.grouping;
4838
5110
  });
4839
5111
  }
4840
5112
  /** Sets (or with `null`, removes) the group summary for a column. */
4841
5113
  setGroupSummary(colId, aggregate) {
4842
- const grouping = _optionalChain([this, 'access', _271 => _271.document, 'access', _272 => _272.table, 'optionalAccess', _273 => _273.grouping]);
5114
+ const grouping = _optionalChain([this, 'access', _275 => _275.document, 'access', _276 => _276.table, 'optionalAccess', _277 => _277.grouping]);
4843
5115
  if (!grouping) return;
4844
5116
  this.applyTableChange(() => {
4845
5117
  const others = grouping.summaries.filter((s) => s.colId !== colId);
@@ -4850,7 +5122,7 @@ var SpreadsheetController = (_class6 = class {
4850
5122
  });
4851
5123
  }
4852
5124
  setGroupCollapsed(key, collapsed) {
4853
- const grouping = _optionalChain([this, 'access', _274 => _274.document, 'access', _275 => _275.table, 'optionalAccess', _276 => _276.grouping]);
5125
+ const grouping = _optionalChain([this, 'access', _278 => _278.document, 'access', _279 => _279.table, 'optionalAccess', _280 => _280.grouping]);
4854
5126
  if (!grouping || grouping.collapsed.includes(key) === collapsed) return;
4855
5127
  this.applyTableChange(() => {
4856
5128
  this.table.grouping = {
@@ -4860,7 +5132,7 @@ var SpreadsheetController = (_class6 = class {
4860
5132
  });
4861
5133
  }
4862
5134
  toggleGroupCollapsed(key) {
4863
- const grouping = _optionalChain([this, 'access', _277 => _277.document, 'access', _278 => _278.table, 'optionalAccess', _279 => _279.grouping]);
5135
+ const grouping = _optionalChain([this, 'access', _281 => _281.document, 'access', _282 => _282.table, 'optionalAccess', _283 => _283.grouping]);
4864
5136
  if (!grouping) return;
4865
5137
  this.setGroupCollapsed(key, !grouping.collapsed.includes(key));
4866
5138
  }
@@ -4890,6 +5162,7 @@ var SpreadsheetController = (_class6 = class {
4890
5162
  if (!rangeContains(s, row, col)) return null;
4891
5163
  return { row: s.startRow + (col - s.startCol), col: s.startCol + (row - s.startRow) };
4892
5164
  });
5165
+ this.moveRulesForTranspose(s, t);
4893
5166
  const rowId = (r) => this.document.rows[r].id;
4894
5167
  const colId = (c) => this.document.columns[c].id;
4895
5168
  const moved = [];
@@ -4898,9 +5171,9 @@ var SpreadsheetController = (_class6 = class {
4898
5171
  moved.push({
4899
5172
  row: s.startRow + (c - s.startCol),
4900
5173
  col: s.startCol + (r - s.startRow),
4901
- cell: _optionalChain([this, 'access', _280 => _280.document, 'access', _281 => _281.cells, 'access', _282 => _282[rowId(r)], 'optionalAccess', _283 => _283[colId(c)]])
5174
+ cell: _optionalChain([this, 'access', _284 => _284.document, 'access', _285 => _285.cells, 'access', _286 => _286[rowId(r)], 'optionalAccess', _287 => _287[colId(c)]])
4902
5175
  });
4903
- _optionalChainDelete([this, 'access', _284 => _284.document, 'access', _285 => _285.cells, 'access', _286 => _286[rowId(r)], 'optionalAccess', _287 => _287[colId(c)]]);
5176
+ _optionalChainDelete([this, 'access', _288 => _288.document, 'access', _289 => _289.cells, 'access', _290 => _290[rowId(r)], 'optionalAccess', _291 => _291[colId(c)]]);
4904
5177
  }
4905
5178
  }
4906
5179
  for (const { row, col, cell } of moved) {
@@ -4932,7 +5205,7 @@ var SpreadsheetController = (_class6 = class {
4932
5205
  }
4933
5206
  /** A sheet's document by id or name (live: don't mutate it directly). */
4934
5207
  getSheetDocument(idOrName) {
4935
- return _optionalChain([this, 'access', _288 => _288.findRuntime, 'call', _289 => _289(idOrName), 'optionalAccess', _290 => _290.doc]);
5208
+ return _optionalChain([this, 'access', _292 => _292.findRuntime, 'call', _293 => _293(idOrName), 'optionalAccess', _294 => _294.doc]);
4936
5209
  }
4937
5210
  /** Why `name` can't name a sheet (or null): see `validateSheetName`. `exceptSheet` is the sheet being renamed. */
4938
5211
  validateSheetName(name, exceptSheet) {
@@ -4966,8 +5239,8 @@ var SpreadsheetController = (_class6 = class {
4966
5239
  this.selectedRange = rt.selectedRange;
4967
5240
  this.editingCell = null;
4968
5241
  this.draftValue = "";
4969
- _optionalChain([this, 'access', _291 => _291.onSelectionChange, 'optionalCall', _292 => _292(this.activeCell, this.selectedRange)]);
4970
- _optionalChain([this, 'access', _293 => _293.onActiveSheetChange, 'optionalCall', _294 => _294(rt.doc.id)]);
5242
+ _optionalChain([this, 'access', _295 => _295.onSelectionChange, 'optionalCall', _296 => _296(this.activeCell, this.selectedRange)]);
5243
+ _optionalChain([this, 'access', _297 => _297.onActiveSheetChange, 'optionalCall', _298 => _298(rt.doc.id)]);
4971
5244
  }
4972
5245
  /**
4973
5246
  * Adds a sheet (default: `Sheet N`, empty, after the last sheet) and
@@ -4976,11 +5249,11 @@ var SpreadsheetController = (_class6 = class {
4976
5249
  */
4977
5250
  addSheet(options = {}) {
4978
5251
  const existing = this.runtimes.map((rt2) => rt2.doc.name);
4979
- const name = _nullishCoalesce(_nullishCoalesce(options.name, () => ( _optionalChain([options, 'access', _295 => _295.document, 'optionalAccess', _296 => _296.name]))), () => ( nextSheetName(existing)));
5252
+ const name = _nullishCoalesce(_nullishCoalesce(options.name, () => ( _optionalChain([options, 'access', _299 => _299.document, 'optionalAccess', _300 => _300.name]))), () => ( nextSheetName(existing)));
4980
5253
  const invalid2 = validateSheetName(name, existing);
4981
5254
  if (invalid2) throw new Error(invalid2);
4982
5255
  this.recordWorkbookSnapshot();
4983
- const id = _optionalChain([options, 'access', _297 => _297.document, 'optionalAccess', _298 => _298.id]) && !this.findRuntimeById(options.document.id) ? options.document.id : this.generateSheetId();
5256
+ const id = _optionalChain([options, 'access', _301 => _301.document, 'optionalAccess', _302 => _302.id]) && !this.findRuntimeById(options.document.id) ? options.document.id : this.generateSheetId();
4984
5257
  const doc = {
4985
5258
  columns: Array.from({ length: 4 }, (_, i) => ({
4986
5259
  id: `col_${String.fromCharCode(97 + i)}`,
@@ -4997,6 +5270,10 @@ var SpreadsheetController = (_class6 = class {
4997
5270
  id,
4998
5271
  name
4999
5272
  };
5273
+ const existingNames = new Set(this.names.map(nameKey));
5274
+ for (const n of namesFromDocument(options.document, id)) {
5275
+ if (!existingNames.has(nameKey(n))) this.names.push(n);
5276
+ }
5000
5277
  const rt = createRuntime(doc);
5001
5278
  const index = Math.max(0, Math.min(_nullishCoalesce(options.index, () => ( this.runtimes.length)), this.runtimes.length));
5002
5279
  this.runtimes.splice(index, 0, rt);
@@ -5084,6 +5361,7 @@ var SpreadsheetController = (_class6 = class {
5084
5361
  doc.id = this.generateSheetId();
5085
5362
  doc.name = name;
5086
5363
  doc.createdAt = doc.updatedAt = Date.now();
5364
+ delete doc.names;
5087
5365
  const copies = this.names.filter((n) => n.sheetId === source.doc.id).map((n) => ({ ...n, sheetId: doc.id, refersTo: renameSheetInFormula(n.refersTo, source.doc.name, name) }));
5088
5366
  this.names.push(...copies);
5089
5367
  const rt = createRuntime(doc);
@@ -5099,13 +5377,13 @@ var SpreadsheetController = (_class6 = class {
5099
5377
  for (const rt of this.runtimes) {
5100
5378
  for (const [rowId, rowCells] of Object.entries(rt.doc.cells)) {
5101
5379
  for (const [colId, cell] of Object.entries(rowCells)) {
5102
- if (!_optionalChain([cell, 'access', _299 => _299.raw, 'optionalAccess', _300 => _300.startsWith, 'call', _301 => _301("=")])) continue;
5380
+ if (!_optionalChain([cell, 'access', _303 => _303.raw, 'optionalAccess', _304 => _304.startsWith, 'call', _305 => _305("=")])) continue;
5103
5381
  const raw = rewrite(cell.raw);
5104
5382
  if (raw !== cell.raw) rt.doc.cells[rowId][colId] = { ...cell, raw };
5105
5383
  }
5106
5384
  }
5107
5385
  for (const col of rt.doc.columns) {
5108
- if (_optionalChain([col, 'access', _302 => _302.formula, 'optionalAccess', _303 => _303.startsWith, 'call', _304 => _304("=")])) col.formula = rewrite(col.formula);
5386
+ if (_optionalChain([col, 'access', _306 => _306.formula, 'optionalAccess', _307 => _307.startsWith, 'call', _308 => _308("=")])) col.formula = rewrite(col.formula);
5109
5387
  }
5110
5388
  }
5111
5389
  for (const n of this.names) n.refersTo = rewrite(n.refersTo);
@@ -5127,8 +5405,8 @@ var SpreadsheetController = (_class6 = class {
5127
5405
  }
5128
5406
  /** The defined name `name` visible from the active sheet (its own sheet-scoped name first), or undefined. */
5129
5407
  getName(name, scope) {
5130
- const rt = _optionalChain([scope, 'optionalAccess', _305 => _305.sheet]) !== void 0 ? this.findRuntime(scope.sheet) : void 0;
5131
- const def = _optionalChain([scope, 'optionalAccess', _306 => _306.sheet]) !== void 0 ? rt ? this.names.find((n) => n.sheetId === rt.doc.id && sameName3(n.name, name)) : void 0 : this.findName(name, this.active);
5408
+ const rt = _optionalChain([scope, 'optionalAccess', _309 => _309.sheet]) !== void 0 ? this.findRuntime(scope.sheet) : void 0;
5409
+ const def = _optionalChain([scope, 'optionalAccess', _310 => _310.sheet]) !== void 0 ? rt ? this.names.find((n) => n.sheetId === rt.doc.id && sameName3(n.name, name)) : void 0 : this.findName(name, this.active);
5132
5410
  return def ? this.getNames().find((n) => n.name === def.name && n.sheetId === def.sheetId) : void 0;
5133
5411
  }
5134
5412
  /** Why `name` can't be a defined name (or null): see `validateDefinedName`. */
@@ -5136,7 +5414,7 @@ var SpreadsheetController = (_class6 = class {
5136
5414
  return validateDefinedName(name);
5137
5415
  }
5138
5416
  scopeRuntime(scope) {
5139
- if (_optionalChain([scope, 'optionalAccess', _307 => _307.sheet]) === void 0) return void 0;
5417
+ if (_optionalChain([scope, 'optionalAccess', _311 => _311.sheet]) === void 0) return void 0;
5140
5418
  const rt = this.findRuntime(scope.sheet);
5141
5419
  if (!rt) throw new Error(`There is no sheet "${scope.sheet}".`);
5142
5420
  return rt;
@@ -5155,11 +5433,11 @@ var SpreadsheetController = (_class6 = class {
5155
5433
  try {
5156
5434
  _chunkEWCOFSCQcjs.parseFormula.call(void 0, formula);
5157
5435
  } catch (err) {
5158
- throw new Error(`There's a problem with this formula: ${_nullishCoalesce(_optionalChain([err, 'optionalAccess', _308 => _308.message]), () => ( formula))}`);
5436
+ throw new Error(`There's a problem with this formula: ${_nullishCoalesce(_optionalChain([err, 'optionalAccess', _312 => _312.message]), () => ( formula))}`);
5159
5437
  }
5160
5438
  const rt = this.scopeRuntime(options);
5161
5439
  this.recordWorkbookSnapshot();
5162
- const sheetId = _optionalChain([rt, 'optionalAccess', _309 => _309.doc, 'access', _310 => _310.id]);
5440
+ const sheetId = _optionalChain([rt, 'optionalAccess', _313 => _313.doc, 'access', _314 => _314.id]);
5163
5441
  const index = this.names.findIndex((n) => n.sheetId === sheetId && sameName3(n.name, name));
5164
5442
  const def = {
5165
5443
  name,
@@ -5180,7 +5458,7 @@ var SpreadsheetController = (_class6 = class {
5180
5458
  */
5181
5459
  renameName(oldName, newName, options = {}) {
5182
5460
  const rt = this.scopeRuntime(options);
5183
- const sheetId = _optionalChain([rt, 'optionalAccess', _311 => _311.doc, 'access', _312 => _312.id]);
5461
+ const sheetId = _optionalChain([rt, 'optionalAccess', _315 => _315.doc, 'access', _316 => _316.id]);
5184
5462
  const def = this.names.find((n) => n.sheetId === sheetId && sameName3(n.name, oldName));
5185
5463
  if (!def) throw new Error(`There is no name "${oldName}"${rt ? ` on sheet ${rt.doc.name}` : ""}.`);
5186
5464
  if (def.name === newName) return;
@@ -5191,19 +5469,19 @@ var SpreadsheetController = (_class6 = class {
5191
5469
  }
5192
5470
  this.recordWorkbookSnapshot();
5193
5471
  const shadowedOn = new Set(this.names.filter((n) => n.sheetId !== void 0 && sameName3(n.name, oldName)).map((n) => n.sheetId));
5194
- const appliesOn = (sheet) => sheetId !== void 0 ? _optionalChain([sheet, 'optionalAccess', _313 => _313.doc, 'access', _314 => _314.id]) === sheetId : !sheet || !shadowedOn.has(sheet.doc.id);
5472
+ const appliesOn = (sheet) => sheetId !== void 0 ? _optionalChain([sheet, 'optionalAccess', _317 => _317.doc, 'access', _318 => _318.id]) === sheetId : !sheet || !shadowedOn.has(sheet.doc.id);
5195
5473
  const appliesToSheetName = (sheetName) => appliesOn(this.findRuntimeByName(sheetName));
5196
5474
  for (const sheet of this.runtimes) {
5197
5475
  const options2 = { appliesTo: appliesToSheetName, qualifiedOnly: !appliesOn(sheet) };
5198
5476
  for (const [rowId, rowCells] of Object.entries(sheet.doc.cells)) {
5199
5477
  for (const [colId, cell] of Object.entries(rowCells)) {
5200
- if (!_optionalChain([cell, 'access', _315 => _315.raw, 'optionalAccess', _316 => _316.startsWith, 'call', _317 => _317("=")])) continue;
5478
+ if (!_optionalChain([cell, 'access', _319 => _319.raw, 'optionalAccess', _320 => _320.startsWith, 'call', _321 => _321("=")])) continue;
5201
5479
  const raw = renameNameInFormula(cell.raw, oldName, newName, options2);
5202
5480
  if (raw !== cell.raw) sheet.doc.cells[rowId][colId] = { ...cell, raw };
5203
5481
  }
5204
5482
  }
5205
5483
  for (const col of sheet.doc.columns) {
5206
- if (_optionalChain([col, 'access', _318 => _318.formula, 'optionalAccess', _319 => _319.startsWith, 'call', _320 => _320("=")])) col.formula = renameNameInFormula(col.formula, oldName, newName, options2);
5484
+ if (_optionalChain([col, 'access', _322 => _322.formula, 'optionalAccess', _323 => _323.startsWith, 'call', _324 => _324("=")])) col.formula = renameNameInFormula(col.formula, oldName, newName, options2);
5207
5485
  }
5208
5486
  }
5209
5487
  for (const n of this.names) {
@@ -5223,7 +5501,7 @@ var SpreadsheetController = (_class6 = class {
5223
5501
  */
5224
5502
  deleteName(name, options = {}) {
5225
5503
  const rt = this.scopeRuntime(options);
5226
- const sheetId = _optionalChain([rt, 'optionalAccess', _321 => _321.doc, 'access', _322 => _322.id]);
5504
+ const sheetId = _optionalChain([rt, 'optionalAccess', _325 => _325.doc, 'access', _326 => _326.id]);
5227
5505
  const index = this.names.findIndex((n) => n.sheetId === sheetId && sameName3(n.name, name));
5228
5506
  if (index < 0) return false;
5229
5507
  this.recordWorkbookSnapshot();
@@ -5277,13 +5555,13 @@ var SpreadsheetController = (_class6 = class {
5277
5555
  }
5278
5556
  cellHistory(doc, cells) {
5279
5557
  return {
5280
- cells: cells.map(([rowId, colId]) => [rowId, colId, _nullishCoalesce(_optionalChain([doc, 'access', _323 => _323.cells, 'access', _324 => _324[rowId], 'optionalAccess', _325 => _325[colId]]), () => ( null)), doc.cells[rowId] !== void 0]),
5558
+ cells: cells.map(([rowId, colId]) => [rowId, colId, _nullishCoalesce(_optionalChain([doc, 'access', _327 => _327.cells, 'access', _328 => _328[rowId], 'optionalAccess', _329 => _329[colId]]), () => ( null)), doc.cells[rowId] !== void 0]),
5281
5559
  updatedAt: doc.updatedAt
5282
5560
  };
5283
5561
  }
5284
5562
  recordWorkbookSnapshot() {
5285
5563
  if (this.isApplyingHistory || this.batching) return;
5286
- this.pushUndo({ kind: "workbook", data: JSON.stringify(this.workbookSnapshot()) });
5564
+ this.pushUndo({ kind: "workbook", data: this.serializeWorkbookSnapshot() });
5287
5565
  }
5288
5566
  pushUndo(entry) {
5289
5567
  this.undoStack.push(entry);
@@ -5343,9 +5621,9 @@ var SpreadsheetController = (_class6 = class {
5343
5621
  }
5344
5622
  this.withSheet(rt, () => {
5345
5623
  for (const [rowId, colId] of positions) {
5346
- const raw = _optionalChain([rt, 'access', _326 => _326.doc, 'access', _327 => _327.cells, 'access', _328 => _328[rowId], 'optionalAccess', _329 => _329[colId], 'optionalAccess', _330 => _330.raw]);
5624
+ const raw = _optionalChain([rt, 'access', _330 => _330.doc, 'access', _331 => _331.cells, 'access', _332 => _332[rowId], 'optionalAccess', _333 => _333[colId], 'optionalAccess', _334 => _334.raw]);
5347
5625
  const cellKey2 = this.getCellKey(rowId, colId);
5348
- this.registerFormula(cellKey2, _optionalChain([raw, 'optionalAccess', _331 => _331.startsWith, 'call', _332 => _332("=")]) ? raw : null);
5626
+ this.registerFormula(cellKey2, _optionalChain([raw, 'optionalAccess', _335 => _335.startsWith, 'call', _336 => _336("=")]) ? raw : null);
5349
5627
  this.dropStaleSpillEdges(cellKey2, _nullishCoalesce(raw, () => ( "")));
5350
5628
  }
5351
5629
  this.recalculateWrittenCells(positions);
@@ -5363,7 +5641,7 @@ var SpreadsheetController = (_class6 = class {
5363
5641
  this.activateRuntime(rt);
5364
5642
  }
5365
5643
  } else {
5366
- to.push({ kind: "workbook", data: JSON.stringify(this.workbookSnapshot()) });
5644
+ to.push({ kind: "workbook", data: this.serializeWorkbookSnapshot() });
5367
5645
  const previousActive = this.active.doc.id;
5368
5646
  const selection = { activeCell: this.activeCell, selectedRange: this.selectedRange };
5369
5647
  const saved = new Map(this.runtimes.map((rt) => [rt.doc.id, rt]));
@@ -5381,8 +5659,8 @@ var SpreadsheetController = (_class6 = class {
5381
5659
  } else {
5382
5660
  this.activeCell = this.active.activeCell;
5383
5661
  this.selectedRange = this.active.selectedRange;
5384
- _optionalChain([this, 'access', _333 => _333.onSelectionChange, 'optionalCall', _334 => _334(this.activeCell, this.selectedRange)]);
5385
- _optionalChain([this, 'access', _335 => _335.onActiveSheetChange, 'optionalCall', _336 => _336(this.active.doc.id)]);
5662
+ _optionalChain([this, 'access', _337 => _337.onSelectionChange, 'optionalCall', _338 => _338(this.activeCell, this.selectedRange)]);
5663
+ _optionalChain([this, 'access', _339 => _339.onActiveSheetChange, 'optionalCall', _340 => _340(this.active.doc.id)]);
5386
5664
  }
5387
5665
  }
5388
5666
  this.recalculateAll();
@@ -5394,7 +5672,8 @@ var SpreadsheetController = (_class6 = class {
5394
5672
  notifyChange() {
5395
5673
  if (!this.cfIncremental) this.cfDirty = "all";
5396
5674
  this.invalidCircles = null;
5397
- _optionalChain([this, 'access', _337 => _337.onDocumentChange, 'optionalCall', _338 => _338(this.active.doc)]);
5675
+ this.syncDocumentNames();
5676
+ _optionalChain([this, 'access', _341 => _341.onDocumentChange, 'optionalCall', _342 => _342(this.active.doc)]);
5398
5677
  if (this.onWorkbookChange) {
5399
5678
  const snapshot = this.workbookSnapshot();
5400
5679
  this.onWorkbookChange({ sheets: snapshot.sheets, activeSheetId: snapshot.activeSheetId, names: snapshot.names });
@@ -5424,7 +5703,7 @@ var SpreadsheetController = (_class6 = class {
5424
5703
  evaluateFormulaAt(formula, row, col, entered) {
5425
5704
  const saved = { rowIndex: this.evaluatingRowIndex, cell: this.evaluatingCell, override: this.valueOverride };
5426
5705
  this.evaluatingRowIndex = row;
5427
- this.evaluatingCell = { col: _nullishCoalesce(_optionalChain([this, 'access', _339 => _339.document, 'access', _340 => _340.columns, 'access', _341 => _341[col], 'optionalAccess', _342 => _342.key]), () => ( _chunkEWCOFSCQcjs.indexToColName.call(void 0, col))), row: row + 1 };
5706
+ this.evaluatingCell = { col: _nullishCoalesce(_optionalChain([this, 'access', _343 => _343.document, 'access', _344 => _344.columns, 'access', _345 => _345[col], 'optionalAccess', _346 => _346.key]), () => ( _chunkEWCOFSCQcjs.indexToColName.call(void 0, col))), row: row + 1 };
5428
5707
  this.valueOverride = _nullishCoalesce(entered, () => ( null));
5429
5708
  try {
5430
5709
  const result = this.evaluator.evaluateWithDiagnostics(formula.startsWith("=") ? formula : `=${formula}`);
@@ -5451,7 +5730,7 @@ var SpreadsheetController = (_class6 = class {
5451
5730
  if (!table) return;
5452
5731
  const shiftIfFormula = (text) => text !== void 0 && text.trimStart().startsWith("=") ? shiftRuleFormula(text, change) : text;
5453
5732
  const shiftAnchor = (value) => value.type === "formula" ? { ...value, formula: shiftRuleFormula(value.formula, change) } : value;
5454
- if (_optionalChain([table, 'access', _343 => _343.conditionalFormats, 'optionalAccess', _344 => _344.length])) {
5733
+ if (_optionalChain([table, 'access', _347 => _347.conditionalFormats, 'optionalAccess', _348 => _348.length])) {
5455
5734
  table.conditionalFormats = table.conditionalFormats.map((rule) => {
5456
5735
  const next = { ...rule, ranges: adjustRangesForStructuralChange(rule.ranges, change) };
5457
5736
  if (next.type === "expression") next.formula = shiftRuleFormula(next.formula, change);
@@ -5468,7 +5747,7 @@ var SpreadsheetController = (_class6 = class {
5468
5747
  return next;
5469
5748
  }).filter((rule) => rule.ranges.length > 0);
5470
5749
  }
5471
- if (_optionalChain([table, 'access', _345 => _345.dataValidations, 'optionalAccess', _346 => _346.length])) {
5750
+ if (_optionalChain([table, 'access', _349 => _349.dataValidations, 'optionalAccess', _350 => _350.length])) {
5472
5751
  table.dataValidations = table.dataValidations.map((rule) => {
5473
5752
  const next = { ...rule, ranges: adjustRangesForStructuralChange(rule.ranges, change) };
5474
5753
  if (rule.formula1 !== void 0) next.formula1 = shiftIfFormula(rule.formula1);
@@ -5477,9 +5756,46 @@ var SpreadsheetController = (_class6 = class {
5477
5756
  }).filter((rule) => rule.ranges.length > 0);
5478
5757
  }
5479
5758
  }
5759
+ /**
5760
+ * Moves conditional formats and validations with sorted rows: per-row
5761
+ * parts follow their rows, parts spanning every sorted row stay (Excel).
5762
+ */
5763
+ moveRulesForSort(block, newRowOf) {
5764
+ const table = this.document.table;
5765
+ if (!table) return;
5766
+ if (_optionalChain([table, 'access', _351 => _351.conditionalFormats, 'optionalAccess', _352 => _352.length])) {
5767
+ table.conditionalFormats = sortRules(table.conditionalFormats, block, newRowOf, mapConditionalFormatFormulas);
5768
+ }
5769
+ if (_optionalChain([table, 'access', _353 => _353.dataValidations, 'optionalAccess', _354 => _354.length])) {
5770
+ table.dataValidations = sortRules(table.dataValidations, block, newRowOf, mapDataValidationFormulas);
5771
+ }
5772
+ }
5773
+ /** Moves conditional formats and validations of a transposed block with its cells. */
5774
+ moveRulesForTranspose(block, target) {
5775
+ const table = this.document.table;
5776
+ if (!table) return;
5777
+ if (_optionalChain([table, 'access', _355 => _355.conditionalFormats, 'optionalAccess', _356 => _356.length])) {
5778
+ table.conditionalFormats = transposeRules(
5779
+ table.conditionalFormats,
5780
+ block,
5781
+ target,
5782
+ mapConditionalFormatFormulas,
5783
+ () => this.generateRuleId("cf")
5784
+ );
5785
+ }
5786
+ if (_optionalChain([table, 'access', _357 => _357.dataValidations, 'optionalAccess', _358 => _358.length])) {
5787
+ table.dataValidations = transposeRules(
5788
+ table.dataValidations,
5789
+ block,
5790
+ target,
5791
+ mapDataValidationFormulas,
5792
+ () => this.generateRuleId("dv")
5793
+ );
5794
+ }
5795
+ }
5480
5796
  /** Conditional formats of the sheet, highest priority first. */
5481
5797
  getConditionalFormats() {
5482
- return _nullishCoalesce(_optionalChain([this, 'access', _347 => _347.document, 'access', _348 => _348.table, 'optionalAccess', _349 => _349.conditionalFormats]), () => ( []));
5798
+ return _nullishCoalesce(_optionalChain([this, 'access', _359 => _359.document, 'access', _360 => _360.table, 'optionalAccess', _361 => _361.conditionalFormats]), () => ( []));
5483
5799
  }
5484
5800
  /**
5485
5801
  * Adds a conditional format (one undo step). New rules get the highest
@@ -5499,7 +5815,7 @@ var SpreadsheetController = (_class6 = class {
5499
5815
  }
5500
5816
  /** Changes a conditional format (its condition, ranges or stop-if-true). Returns false when not found. */
5501
5817
  updateConditionalFormat(id, changes) {
5502
- const rules = _nullishCoalesce(_optionalChain([this, 'access', _350 => _350.document, 'access', _351 => _351.table, 'optionalAccess', _352 => _352.conditionalFormats]), () => ( []));
5818
+ const rules = _nullishCoalesce(_optionalChain([this, 'access', _362 => _362.document, 'access', _363 => _363.table, 'optionalAccess', _364 => _364.conditionalFormats]), () => ( []));
5503
5819
  const index = rules.findIndex((r) => r.id === id);
5504
5820
  if (index === -1) return false;
5505
5821
  this.applyTableChange(() => {
@@ -5513,7 +5829,7 @@ var SpreadsheetController = (_class6 = class {
5513
5829
  }
5514
5830
  /** Removes a conditional format. Returns false when not found. */
5515
5831
  deleteConditionalFormat(id) {
5516
- const rules = _nullishCoalesce(_optionalChain([this, 'access', _353 => _353.document, 'access', _354 => _354.table, 'optionalAccess', _355 => _355.conditionalFormats]), () => ( []));
5832
+ const rules = _nullishCoalesce(_optionalChain([this, 'access', _365 => _365.document, 'access', _366 => _366.table, 'optionalAccess', _367 => _367.conditionalFormats]), () => ( []));
5517
5833
  if (!rules.some((r) => r.id === id)) return false;
5518
5834
  this.applyTableChange(() => {
5519
5835
  this.table.conditionalFormats = rules.filter((r) => r.id !== id);
@@ -5525,7 +5841,7 @@ var SpreadsheetController = (_class6 = class {
5525
5841
  * `{ by: -1 }` (up) / `{ by: 1 }` (down). Returns false when nothing moved.
5526
5842
  */
5527
5843
  moveConditionalFormat(id, to) {
5528
- const rules = _nullishCoalesce(_optionalChain([this, 'access', _356 => _356.document, 'access', _357 => _357.table, 'optionalAccess', _358 => _358.conditionalFormats]), () => ( []));
5844
+ const rules = _nullishCoalesce(_optionalChain([this, 'access', _368 => _368.document, 'access', _369 => _369.table, 'optionalAccess', _370 => _370.conditionalFormats]), () => ( []));
5529
5845
  const from = rules.findIndex((r) => r.id === id);
5530
5846
  if (from === -1) return false;
5531
5847
  const target = Math.max(0, Math.min(rules.length - 1, typeof to === "number" ? to : from + to.by));
@@ -5544,7 +5860,7 @@ var SpreadsheetController = (_class6 = class {
5544
5860
  * when `range` is null.
5545
5861
  */
5546
5862
  clearConditionalFormats(range = null) {
5547
- const rules = _nullishCoalesce(_optionalChain([this, 'access', _359 => _359.document, 'access', _360 => _360.table, 'optionalAccess', _361 => _361.conditionalFormats]), () => ( []));
5863
+ const rules = _nullishCoalesce(_optionalChain([this, 'access', _371 => _371.document, 'access', _372 => _372.table, 'optionalAccess', _373 => _373.conditionalFormats]), () => ( []));
5548
5864
  if (rules.length === 0) return;
5549
5865
  this.applyTableChange(() => {
5550
5866
  this.table.conditionalFormats = range ? rules.map((rule) => ({ ...rule, ranges: subtractRangeFromRanges(rule.ranges, range) })).filter((rule) => rule.ranges.length > 0) : [];
@@ -5555,7 +5871,7 @@ var SpreadsheetController = (_class6 = class {
5555
5871
  * cached: after a cell edit only the affected cells are re-evaluated.
5556
5872
  */
5557
5873
  getConditionalFormatOverlay() {
5558
- const rules = _nullishCoalesce(_optionalChain([this, 'access', _362 => _362.document, 'access', _363 => _363.table, 'optionalAccess', _364 => _364.conditionalFormats]), () => ( []));
5874
+ const rules = _nullishCoalesce(_optionalChain([this, 'access', _374 => _374.document, 'access', _375 => _375.table, 'optionalAccess', _376 => _376.conditionalFormats]), () => ( []));
5559
5875
  if (rules.length === 0) {
5560
5876
  this.cfEngine = null;
5561
5877
  this.cfDirty = "all";
@@ -5583,11 +5899,11 @@ var SpreadsheetController = (_class6 = class {
5583
5899
  }
5584
5900
  /** Data validation rules of the sheet. */
5585
5901
  getDataValidations() {
5586
- return _nullishCoalesce(_optionalChain([this, 'access', _365 => _365.document, 'access', _366 => _366.table, 'optionalAccess', _367 => _367.dataValidations]), () => ( []));
5902
+ return _nullishCoalesce(_optionalChain([this, 'access', _377 => _377.document, 'access', _378 => _378.table, 'optionalAccess', _379 => _379.dataValidations]), () => ( []));
5587
5903
  }
5588
5904
  /** The rule that applies to (row, col), if any. */
5589
5905
  getDataValidationAt(row, col) {
5590
- return findDataValidation(_optionalChain([this, 'access', _368 => _368.document, 'access', _369 => _369.table, 'optionalAccess', _370 => _370.dataValidations]), row, col);
5906
+ return findDataValidation(_optionalChain([this, 'access', _380 => _380.document, 'access', _381 => _381.table, 'optionalAccess', _382 => _382.dataValidations]), row, col);
5591
5907
  }
5592
5908
  /**
5593
5909
  * Adds a data validation rule (one undo step). Its cells are first
@@ -5607,7 +5923,7 @@ var SpreadsheetController = (_class6 = class {
5607
5923
  }
5608
5924
  /** Changes a data validation rule. Returns false when not found. */
5609
5925
  updateDataValidation(id, changes) {
5610
- const rules = _nullishCoalesce(_optionalChain([this, 'access', _371 => _371.document, 'access', _372 => _372.table, 'optionalAccess', _373 => _373.dataValidations]), () => ( []));
5926
+ const rules = _nullishCoalesce(_optionalChain([this, 'access', _383 => _383.document, 'access', _384 => _384.table, 'optionalAccess', _385 => _385.dataValidations]), () => ( []));
5611
5927
  const index = rules.findIndex((r) => r.id === id);
5612
5928
  if (index === -1) return false;
5613
5929
  this.applyTableChange(() => {
@@ -5621,7 +5937,7 @@ var SpreadsheetController = (_class6 = class {
5621
5937
  }
5622
5938
  /** Removes a data validation rule. Returns false when not found. */
5623
5939
  deleteDataValidation(id) {
5624
- const rules = _nullishCoalesce(_optionalChain([this, 'access', _374 => _374.document, 'access', _375 => _375.table, 'optionalAccess', _376 => _376.dataValidations]), () => ( []));
5940
+ const rules = _nullishCoalesce(_optionalChain([this, 'access', _386 => _386.document, 'access', _387 => _387.table, 'optionalAccess', _388 => _388.dataValidations]), () => ( []));
5625
5941
  if (!rules.some((r) => r.id === id)) return false;
5626
5942
  this.applyTableChange(() => {
5627
5943
  this.table.dataValidations = rules.filter((r) => r.id !== id);
@@ -5630,7 +5946,7 @@ var SpreadsheetController = (_class6 = class {
5630
5946
  }
5631
5947
  /** Removes validation from the cells of `range`, or every rule when `range` is null. */
5632
5948
  clearDataValidation(range = null) {
5633
- const rules = _nullishCoalesce(_optionalChain([this, 'access', _377 => _377.document, 'access', _378 => _378.table, 'optionalAccess', _379 => _379.dataValidations]), () => ( []));
5949
+ const rules = _nullishCoalesce(_optionalChain([this, 'access', _389 => _389.document, 'access', _390 => _390.table, 'optionalAccess', _391 => _391.dataValidations]), () => ( []));
5634
5950
  if (rules.length === 0) return;
5635
5951
  this.applyTableChange(() => {
5636
5952
  this.table.dataValidations = range ? rules.map((r) => ({ ...r, ranges: subtractRangeFromRanges(r.ranges, range) })).filter((r) => r.ranges.length > 0) : [];
@@ -5638,7 +5954,7 @@ var SpreadsheetController = (_class6 = class {
5638
5954
  }
5639
5955
  /** Checks input for (row, col) against its data validation, without committing it. */
5640
5956
  validateCellInput(row, col, raw) {
5641
- return validateCellInput(this.ruleSheet(), _optionalChain([this, 'access', _380 => _380.document, 'access', _381 => _381.table, 'optionalAccess', _382 => _382.dataValidations]), row, col, raw);
5957
+ return validateCellInput(this.ruleSheet(), _optionalChain([this, 'access', _392 => _392.document, 'access', _393 => _393.table, 'optionalAccess', _394 => _394.dataValidations]), row, col, raw);
5642
5958
  }
5643
5959
  /**
5644
5960
  * Dropdown items of a list-validated cell, or null when the cell has no
@@ -5651,7 +5967,7 @@ var SpreadsheetController = (_class6 = class {
5651
5967
  }
5652
5968
  /** Cells whose current value breaks their validation rule. */
5653
5969
  findInvalidCells() {
5654
- return findInvalidCells(this.ruleSheet(), _optionalChain([this, 'access', _383 => _383.document, 'access', _384 => _384.table, 'optionalAccess', _385 => _385.dataValidations]));
5970
+ return findInvalidCells(this.ruleSheet(), _optionalChain([this, 'access', _395 => _395.document, 'access', _396 => _396.table, 'optionalAccess', _397 => _397.dataValidations]));
5655
5971
  }
5656
5972
  /**
5657
5973
  * Turns "circle invalid data" on or off. View state, not part of the
@@ -5662,7 +5978,7 @@ var SpreadsheetController = (_class6 = class {
5662
5978
  if (this.circlesShown === show) return;
5663
5979
  this.circlesShown = show;
5664
5980
  this.invalidCircles = null;
5665
- _optionalChain([this, 'access', _386 => _386.onDocumentChange, 'optionalCall', _387 => _387(this.document)]);
5981
+ _optionalChain([this, 'access', _398 => _398.onDocumentChange, 'optionalCall', _399 => _399(this.document)]);
5666
5982
  }
5667
5983
  /** Whether invalid cells are circled. */
5668
5984
  getInvalidDataCircles() {
@@ -6094,7 +6410,7 @@ function getSheetTabMenuItems(controller, sheetId, options = {}) {
6094
6410
  fn();
6095
6411
  } catch (err) {
6096
6412
  if (!options.onError) throw err;
6097
- options.onError(_nullishCoalesce(_optionalChain([err, 'optionalAccess', _388 => _388.message]), () => ( String(err))));
6413
+ options.onError(_nullishCoalesce(_optionalChain([err, 'optionalAccess', _400 => _400.message]), () => ( String(err))));
6098
6414
  }
6099
6415
  };
6100
6416
  return [
@@ -6474,5 +6790,15 @@ function sameSpreadsheetViewWindow(a, b) {
6474
6790
 
6475
6791
 
6476
6792
 
6477
- exports.extractNameDependencies = extractNameDependencies; exports.columnDependencyKey = columnDependencyKey; exports.extractCellDependencies = extractCellDependencies; exports.extractReferenceDependencies = extractReferenceDependencies; exports.rangeDependencyKey = rangeDependencyKey; exports.IntervalIndex = IntervalIndex; exports.DependencyGraph = DependencyGraph; exports.shiftFormulaReferences = shiftFormulaReferences; exports.mapFormulaReferences = mapFormulaReferences; exports.offsetFormulaReferences = offsetFormulaReferences; exports.remapFormulaReferences = remapFormulaReferences; exports.sheetNameNeedsQuotes = sheetNameNeedsQuotes; exports.quoteSheetName = quoteSheetName; exports.formatSheetPrefix = formatSheetPrefix; exports.renameSheetInFormula = renameSheetInFormula; exports.deleteSheetInFormula = deleteSheetInFormula; exports.renameNameInFormula = renameNameInFormula; exports.formulaIdentifiers = formulaIdentifiers; exports.getFormulaCaretContext = getFormulaCaretContext; exports.getFormulaHints = getFormulaHints; exports.applyFormulaSuggestion = applyFormulaSuggestion; exports.NUMBER_FORMAT_PRESETS = NUMBER_FORMAT_PRESETS; exports.numberFormatForCellFormat = numberFormatForCellFormat; exports.cellFormatForNumberFormat = cellFormatForNumberFormat; exports.isGeneralNumberFormat = isGeneralNumberFormat; exports.formatCellForDisplay = formatCellForDisplay; exports.formatCellDisplay = formatCellDisplay; exports.formatValueWithCode = formatValueWithCode; exports.DataSourceBinder = DataSourceBinder; exports.MAX_SHEET_NAME_LENGTH = MAX_SHEET_NAME_LENGTH; exports.MAX_DEFINED_NAME_LENGTH = MAX_DEFINED_NAME_LENGTH; exports.validateSheetName = validateSheetName; exports.nextSheetName = nextSheetName; exports.copySheetName = copySheetName; exports.validateDefinedName = validateDefinedName; exports.isLambdaDefinition = isLambdaDefinition; exports.normalizeRange = normalizeRange; exports.rangeContains = rangeContains; exports.rangesIntersect = rangesIntersect; exports.rangeContainsRange = rangeContainsRange; exports.isSingleCellRange = isSingleCellRange; exports.isBlankValue = isBlankValue; exports.toNumber = toNumber; exports.compareCellValues = compareCellValues; exports.matchesFilterRule = matchesFilterRule; exports.aggregateValues = aggregateValues; exports.roundFloat = roundFloat; exports.fillSeries = fillSeries; exports.computeFillTarget = computeFillTarget; exports.getFillDirection = getFillDirection; exports.SPREADSHEET_CLIPBOARD_MIME = SPREADSHEET_CLIPBOARD_MIME; exports.serializeHtmlTable = serializeHtmlTable; exports.parseHtmlTable = parseHtmlTable; exports.createSpreadsheetClipboardData = createSpreadsheetClipboardData; exports.readSpreadsheetClipboard = readSpreadsheetClipboard; exports.rebaseClipboardRows = rebaseClipboardRows; exports.adjustRangeForStructuralChange = adjustRangeForStructuralChange; exports.adjustRangesForStructuralChange = adjustRangesForStructuralChange; exports.subtractRange = subtractRange; exports.subtractRangeFromRanges = subtractRangeFromRanges; exports.rangesContain = rangesContain; exports.ruleAnchor = ruleAnchor; exports.ruleFormulaAt = ruleFormulaAt; exports.shiftRuleFormula = shiftRuleFormula; exports.forEachRangeCell = forEachRangeCell; exports.formatRuleRanges = formatRuleRanges; exports.parseRuleRanges = parseRuleRanges; exports.CONDITIONAL_FORMAT_ICON_SETS = CONDITIONAL_FORMAT_ICON_SETS; exports.conditionalFormatIconCount = conditionalFormatIconCount; exports.getConditionalFormatIcon = getConditionalFormatIcon; exports.conditionalFormatNumber = conditionalFormatNumber; exports.blendConditionalFormatColors = blendConditionalFormatColors; exports.defaultIconThresholds = defaultIconThresholds; exports.EMPTY_CONDITIONAL_FORMAT_OVERLAY = EMPTY_CONDITIONAL_FORMAT_OVERLAY; exports.ConditionalFormatEngine = ConditionalFormatEngine; exports.matchesTimePeriod = matchesTimePeriod; exports.evaluateConditionalFormats = evaluateConditionalFormats; exports.describeConditionalFormat = describeConditionalFormat; exports.describeDataValidation = describeDataValidation; exports.CONDITIONAL_FORMAT_STYLE_PRESETS = CONDITIONAL_FORMAT_STYLE_PRESETS; exports.DEFAULT_CONDITIONAL_FORMAT_STYLE = DEFAULT_CONDITIONAL_FORMAT_STYLE; exports.CONDITIONAL_FORMAT_PRESETS = CONDITIONAL_FORMAT_PRESETS; exports.CONDITIONAL_FORMAT_TIME_PERIODS = CONDITIONAL_FORMAT_TIME_PERIODS; exports.createConditionalFormatRule = createConditionalFormatRule; exports.DATA_VALIDATION_TYPE_OPTIONS = DATA_VALIDATION_TYPE_OPTIONS; exports.DATA_VALIDATION_OPERATOR_OPTIONS = DATA_VALIDATION_OPERATOR_OPTIONS; exports.DATA_VALIDATION_ERROR_STYLE_OPTIONS = DATA_VALIDATION_ERROR_STYLE_OPTIONS; exports.conditionalFormatContrastColor = conditionalFormatContrastColor; exports.getConditionalFormatCss = getConditionalFormatCss; exports.getDataBarCss = getDataBarCss; exports.conditionalFormatStyleString = conditionalFormatStyleString; exports.DEFAULT_DATA_VALIDATION_MESSAGE = DEFAULT_DATA_VALIDATION_MESSAGE; exports.DEFAULT_DATA_VALIDATION_TITLE = DEFAULT_DATA_VALIDATION_TITLE; exports.findDataValidation = findDataValidation; exports.getValidationListValues = getValidationListValues; exports.validateCellInput = validateCellInput; exports.findInvalidCells = findInvalidCells; exports.DEFAULT_ROW_HEIGHT = DEFAULT_ROW_HEIGHT; exports.DEFAULT_COLUMN_WIDTH = DEFAULT_COLUMN_WIDTH; exports.getTableSections = getTableSections; exports.getRowSection = getRowSection; exports.rowPassesFilters = rowPassesFilters; exports.computeRowGroups = computeRowGroups; exports.buildSpreadsheetView = buildSpreadsheetView; exports.SpreadsheetController = SpreadsheetController; exports.runSpreadsheetMenuItem = runSpreadsheetMenuItem; exports.clampMenuPosition = clampMenuPosition; exports.getSpreadsheetMenuItems = getSpreadsheetMenuItems; exports.SPREADSHEET_TABLE_ACTIONS = SPREADSHEET_TABLE_ACTIONS; exports.bindSpreadsheetTableActions = bindSpreadsheetTableActions; exports.csvImportAdapter = csvImportAdapter; exports.tsvImportAdapter = tsvImportAdapter; exports.SPREADSHEET_IMPORT_ADAPTERS = SPREADSHEET_IMPORT_ADAPTERS; exports.registerSpreadsheetImportAdapters = registerSpreadsheetImportAdapters; exports.importFileIntoSpreadsheet = importFileIntoSpreadsheet; exports.getSheetTabMenuItems = getSheetTabMenuItems; exports.sheetDropIndex = sheetDropIndex; exports.getNameManagerRows = getNameManagerRows; exports.SPREADSHEET_COLUMN_HEADER_HEIGHT = SPREADSHEET_COLUMN_HEADER_HEIGHT; exports.SPREADSHEET_ROW_HEADER_WIDTH = SPREADSHEET_ROW_HEADER_WIDTH; exports.SPREADSHEET_GROUP_ROW_HEIGHT = SPREADSHEET_GROUP_ROW_HEIGHT; exports.SPREADSHEET_VIRTUAL_ROW_THRESHOLD = SPREADSHEET_VIRTUAL_ROW_THRESHOLD; exports.SPREADSHEET_VIRTUAL_COLUMN_THRESHOLD = SPREADSHEET_VIRTUAL_COLUMN_THRESHOLD; exports.SPREADSHEET_DEFAULT_VIEWPORT = SPREADSHEET_DEFAULT_VIEWPORT; exports.measureSpreadsheetView = measureSpreadsheetView; exports.shouldVirtualizeSpreadsheet = shouldVirtualizeSpreadsheet; exports.fullSpreadsheetViewWindow = fullSpreadsheetViewWindow; exports.getSpreadsheetViewWindow = getSpreadsheetViewWindow; exports.getSpreadsheetScrollToCell = getSpreadsheetScrollToCell; exports.sameSpreadsheetViewWindow = sameSpreadsheetViewWindow;
6478
- //# sourceMappingURL=chunk-NQF32I6Z.cjs.map
6793
+
6794
+
6795
+
6796
+
6797
+
6798
+
6799
+
6800
+
6801
+
6802
+
6803
+ exports.extractNameDependencies = extractNameDependencies; exports.columnDependencyKey = columnDependencyKey; exports.extractCellDependencies = extractCellDependencies; exports.extractReferenceDependencies = extractReferenceDependencies; exports.rangeDependencyKey = rangeDependencyKey; exports.IntervalIndex = IntervalIndex; exports.DependencyGraph = DependencyGraph; exports.shiftFormulaReferences = shiftFormulaReferences; exports.mapFormulaReferences = mapFormulaReferences; exports.offsetFormulaReferences = offsetFormulaReferences; exports.remapFormulaReferences = remapFormulaReferences; exports.transposeFormulaReferences = transposeFormulaReferences; exports.sheetNameNeedsQuotes = sheetNameNeedsQuotes; exports.quoteSheetName = quoteSheetName; exports.formatSheetPrefix = formatSheetPrefix; exports.renameSheetInFormula = renameSheetInFormula; exports.deleteSheetInFormula = deleteSheetInFormula; exports.renameNameInFormula = renameNameInFormula; exports.formulaIdentifiers = formulaIdentifiers; exports.getFormulaCaretContext = getFormulaCaretContext; exports.getFormulaHints = getFormulaHints; exports.applyFormulaSuggestion = applyFormulaSuggestion; exports.NUMBER_FORMAT_PRESETS = NUMBER_FORMAT_PRESETS; exports.numberFormatForCellFormat = numberFormatForCellFormat; exports.cellFormatForNumberFormat = cellFormatForNumberFormat; exports.isGeneralNumberFormat = isGeneralNumberFormat; exports.formatCellForDisplay = formatCellForDisplay; exports.formatCellDisplay = formatCellDisplay; exports.formatValueWithCode = formatValueWithCode; exports.DataSourceBinder = DataSourceBinder; exports.MAX_SHEET_NAME_LENGTH = MAX_SHEET_NAME_LENGTH; exports.MAX_DEFINED_NAME_LENGTH = MAX_DEFINED_NAME_LENGTH; exports.validateSheetName = validateSheetName; exports.nextSheetName = nextSheetName; exports.copySheetName = copySheetName; exports.validateDefinedName = validateDefinedName; exports.isLambdaDefinition = isLambdaDefinition; exports.normalizeRange = normalizeRange; exports.rangeContains = rangeContains; exports.rangesIntersect = rangesIntersect; exports.rangeContainsRange = rangeContainsRange; exports.isSingleCellRange = isSingleCellRange; exports.isBlankValue = isBlankValue; exports.toNumber = toNumber; exports.compareCellValues = compareCellValues; exports.matchesFilterRule = matchesFilterRule; exports.aggregateValues = aggregateValues; exports.roundFloat = roundFloat; exports.fillSeries = fillSeries; exports.computeFillTarget = computeFillTarget; exports.getFillDirection = getFillDirection; exports.SPREADSHEET_CLIPBOARD_MIME = SPREADSHEET_CLIPBOARD_MIME; exports.serializeHtmlTable = serializeHtmlTable; exports.parseHtmlTable = parseHtmlTable; exports.createSpreadsheetClipboardData = createSpreadsheetClipboardData; exports.readSpreadsheetClipboard = readSpreadsheetClipboard; exports.rebaseClipboardRows = rebaseClipboardRows; exports.adjustRangeForStructuralChange = adjustRangeForStructuralChange; exports.adjustRangesForStructuralChange = adjustRangesForStructuralChange; exports.subtractRange = subtractRange; exports.subtractRangeFromRanges = subtractRangeFromRanges; exports.rangesContain = rangesContain; exports.ruleAnchor = ruleAnchor; exports.ruleFormulaAt = ruleFormulaAt; exports.shiftRuleFormula = shiftRuleFormula; exports.forEachRangeCell = forEachRangeCell; exports.formatRuleRanges = formatRuleRanges; exports.parseRuleRanges = parseRuleRanges; exports.mergeRuleRanges = mergeRuleRanges; exports.sortRuleRanges = sortRuleRanges; exports.transposeRuleRanges = transposeRuleRanges; exports.reanchorRuleFormula = reanchorRuleFormula; exports.transposeRuleFormula = transposeRuleFormula; exports.mapConditionalFormatFormulas = mapConditionalFormatFormulas; exports.mapDataValidationFormulas = mapDataValidationFormulas; exports.sortRules = sortRules; exports.transposeRules = transposeRules; exports.CONDITIONAL_FORMAT_ICON_SETS = CONDITIONAL_FORMAT_ICON_SETS; exports.conditionalFormatIconCount = conditionalFormatIconCount; exports.getConditionalFormatIcon = getConditionalFormatIcon; exports.conditionalFormatNumber = conditionalFormatNumber; exports.blendConditionalFormatColors = blendConditionalFormatColors; exports.defaultIconThresholds = defaultIconThresholds; exports.EMPTY_CONDITIONAL_FORMAT_OVERLAY = EMPTY_CONDITIONAL_FORMAT_OVERLAY; exports.ConditionalFormatEngine = ConditionalFormatEngine; exports.matchesTimePeriod = matchesTimePeriod; exports.evaluateConditionalFormats = evaluateConditionalFormats; exports.describeConditionalFormat = describeConditionalFormat; exports.describeDataValidation = describeDataValidation; exports.CONDITIONAL_FORMAT_STYLE_PRESETS = CONDITIONAL_FORMAT_STYLE_PRESETS; exports.DEFAULT_CONDITIONAL_FORMAT_STYLE = DEFAULT_CONDITIONAL_FORMAT_STYLE; exports.CONDITIONAL_FORMAT_PRESETS = CONDITIONAL_FORMAT_PRESETS; exports.CONDITIONAL_FORMAT_TIME_PERIODS = CONDITIONAL_FORMAT_TIME_PERIODS; exports.createConditionalFormatRule = createConditionalFormatRule; exports.DATA_VALIDATION_TYPE_OPTIONS = DATA_VALIDATION_TYPE_OPTIONS; exports.DATA_VALIDATION_OPERATOR_OPTIONS = DATA_VALIDATION_OPERATOR_OPTIONS; exports.DATA_VALIDATION_ERROR_STYLE_OPTIONS = DATA_VALIDATION_ERROR_STYLE_OPTIONS; exports.conditionalFormatContrastColor = conditionalFormatContrastColor; exports.getConditionalFormatCss = getConditionalFormatCss; exports.getDataBarCss = getDataBarCss; exports.conditionalFormatStyleString = conditionalFormatStyleString; exports.DEFAULT_DATA_VALIDATION_MESSAGE = DEFAULT_DATA_VALIDATION_MESSAGE; exports.DEFAULT_DATA_VALIDATION_TITLE = DEFAULT_DATA_VALIDATION_TITLE; exports.findDataValidation = findDataValidation; exports.getValidationListValues = getValidationListValues; exports.validateCellInput = validateCellInput; exports.findInvalidCells = findInvalidCells; exports.DEFAULT_ROW_HEIGHT = DEFAULT_ROW_HEIGHT; exports.DEFAULT_COLUMN_WIDTH = DEFAULT_COLUMN_WIDTH; exports.getTableSections = getTableSections; exports.getRowSection = getRowSection; exports.rowPassesFilters = rowPassesFilters; exports.computeRowGroups = computeRowGroups; exports.buildSpreadsheetView = buildSpreadsheetView; exports.SpreadsheetController = SpreadsheetController; exports.runSpreadsheetMenuItem = runSpreadsheetMenuItem; exports.clampMenuPosition = clampMenuPosition; exports.getSpreadsheetMenuItems = getSpreadsheetMenuItems; exports.SPREADSHEET_TABLE_ACTIONS = SPREADSHEET_TABLE_ACTIONS; exports.bindSpreadsheetTableActions = bindSpreadsheetTableActions; exports.csvImportAdapter = csvImportAdapter; exports.tsvImportAdapter = tsvImportAdapter; exports.SPREADSHEET_IMPORT_ADAPTERS = SPREADSHEET_IMPORT_ADAPTERS; exports.registerSpreadsheetImportAdapters = registerSpreadsheetImportAdapters; exports.importFileIntoSpreadsheet = importFileIntoSpreadsheet; exports.getSheetTabMenuItems = getSheetTabMenuItems; exports.sheetDropIndex = sheetDropIndex; exports.getNameManagerRows = getNameManagerRows; exports.SPREADSHEET_COLUMN_HEADER_HEIGHT = SPREADSHEET_COLUMN_HEADER_HEIGHT; exports.SPREADSHEET_ROW_HEADER_WIDTH = SPREADSHEET_ROW_HEADER_WIDTH; exports.SPREADSHEET_GROUP_ROW_HEIGHT = SPREADSHEET_GROUP_ROW_HEIGHT; exports.SPREADSHEET_VIRTUAL_ROW_THRESHOLD = SPREADSHEET_VIRTUAL_ROW_THRESHOLD; exports.SPREADSHEET_VIRTUAL_COLUMN_THRESHOLD = SPREADSHEET_VIRTUAL_COLUMN_THRESHOLD; exports.SPREADSHEET_DEFAULT_VIEWPORT = SPREADSHEET_DEFAULT_VIEWPORT; exports.measureSpreadsheetView = measureSpreadsheetView; exports.shouldVirtualizeSpreadsheet = shouldVirtualizeSpreadsheet; exports.fullSpreadsheetViewWindow = fullSpreadsheetViewWindow; exports.getSpreadsheetViewWindow = getSpreadsheetViewWindow; exports.getSpreadsheetScrollToCell = getSpreadsheetScrollToCell; exports.sameSpreadsheetViewWindow = sameSpreadsheetViewWindow;
6804
+ //# sourceMappingURL=chunk-YK5TATOF.cjs.map