@ex-grid/sheet-engine 0.2.0-beta.3 → 0.2.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1391,6 +1391,21 @@ declare class MissingNode extends NodeBase {
1391
1391
  static isEmpty(argument: Node_2): boolean;
1392
1392
  }
1393
1393
 
1394
+ /**
1395
+ * The Reference `reference` rewritten to name `range`, written as `reference` was (ADR-0480, section 1): what a
1396
+ * Reference Outline dragged by its edge or its corner square leaves in the Formula. Each part keeps its `$`; a
1397
+ * Sheet qualifier is kept as typed; a one-cell Reference made a range writes both ends in its form, and a range
1398
+ * made one cell writes it once, in its first end's form. Whole columns (rows) that still span every row (column) of
1399
+ * `size` stay whole columns (rows), each end keeping its `$`; resized so that they no longer do, they are written as
1400
+ * the cells they name, the columns' (rows') `$` kept. Column letters are written in upper case. Throws a RangeError
1401
+ * when `reference` is not one Reference over the whole of it, or `range` does not lie inside `size`.
1402
+ *
1403
+ * @param reference - The Reference's text as it stands in the Formula: `$A$1`, `Sheet1!B2:C3`, `A:A`.
1404
+ * @param range - The cells it is to name.
1405
+ * @param size - The Sheet's size (ADR-0460), against which "every row" and "every column" are read.
1406
+ */
1407
+ export declare function moveReference(reference: string, range: CellRange, size?: SheetSize): string;
1408
+
1394
1409
  /**
1395
1410
  * A name that is not a function call, a Reference or a boolean. ExSheet defines no names of its own, so it is
1396
1411
  * `#NAME?` — unless a `LET` around it binds it (ADR-0181).
package/dist/index.js CHANGED
@@ -11397,6 +11397,52 @@ function dateTimeText(serial, culture) {
11397
11397
  return hasTime ? `${date} ${time2.format(Value.fromNumber(serial), culture).text}` : date;
11398
11398
  }
11399
11399
 
11400
+ // src/sheet-size.ts
11401
+ var SheetSize = class _SheetSize {
11402
+ /** Excel's full size, 1,048,576 rows by 16,384 columns (`A1` to `XFD1048576`): what a Sheet holds unless given another. */
11403
+ static excel = new _SheetSize(rowCount, columnCount);
11404
+ /** How many rows, from 1 to 1,048,576. */
11405
+ rows;
11406
+ /** How many columns, from 1 to 16,384. */
11407
+ columns;
11408
+ /** A size of `rows` by `columns`; one of no rows or no columns, or larger than Excel's, is refused with a `RangeError`. */
11409
+ constructor(rows, columns) {
11410
+ if (!Number.isInteger(rows) || rows < 1 || rows > rowCount) {
11411
+ throw new RangeError(`A Sheet holds from 1 to 1,048,576 rows; ${String(rows)} is not that.`);
11412
+ }
11413
+ if (!Number.isInteger(columns) || columns < 1 || columns > columnCount) {
11414
+ throw new RangeError(`A Sheet holds from 1 to 16,384 columns; ${String(columns)} is not that.`);
11415
+ }
11416
+ this.rows = rows;
11417
+ this.columns = columns;
11418
+ }
11419
+ /** The last cell inside the size: `XFD1048576` for Excel's, `J10` for ten by ten. */
11420
+ get lastCell() {
11421
+ return new CellAddress(this.rows - 1, this.columns - 1);
11422
+ }
11423
+ /** Whether `address` lies inside the size. */
11424
+ contains(address) {
11425
+ return address.row < this.rows && address.column < this.columns;
11426
+ }
11427
+ /** Whether a block of `rows` × `columns` with its top-left cell at `origin` lies wholly inside the size. */
11428
+ holds(origin, rows, columns) {
11429
+ return origin.row + rows <= this.rows && origin.column + columns <= this.columns;
11430
+ }
11431
+ /**
11432
+ * `range` as it stands inside the size, or `undefined` when it runs past it. Whole columns and whole rows are
11433
+ * Excel's lines, inside when their columns or rows are, and are answered as long as the size's: `B:B` of ten rows
11434
+ * is `B1:B10`.
11435
+ */
11436
+ fit(range) {
11437
+ const last = new CellAddress(range.isWholeColumns ? this.rows - 1 : range.last.row, range.isWholeRows ? this.columns - 1 : range.last.column);
11438
+ return this.contains(last) && this.contains(range.first) ? new CellRange(range.first, last) : void 0;
11439
+ }
11440
+ /** Whether the two are the same size. */
11441
+ equals(other) {
11442
+ return this.rows === other.rows && this.columns === other.columns;
11443
+ }
11444
+ };
11445
+
11400
11446
  // src/formula-entry.ts
11401
11447
  var LinkedTableColumn = class {
11402
11448
  /** The table's name, as written. */
@@ -11460,6 +11506,36 @@ function referenceText(range, sheet) {
11460
11506
  if (sheet.length === 0) throw new RangeError("The Sheet name is empty.");
11461
11507
  return `${quoteSheetName(sheet)}!${range.toString()}`;
11462
11508
  }
11509
+ function moveReference(reference, range, size = SheetSize.excel) {
11510
+ const match = reference.length === 0 ? void 0 : matchReference(reference, 0);
11511
+ if (match?.index !== 0 || match.length !== reference.length) {
11512
+ throw new RangeError(`'${reference}' is not one Reference over the whole of it.`);
11513
+ }
11514
+ if (!size.contains(range.last)) throw new RangeError(`${range.toString()} does not lie inside the Sheet's ${String(size.rows)} rows by ${String(size.columns)} columns.`);
11515
+ const group3 = (name) => match.groups[name];
11516
+ const absolute = (name) => group3(name)?.value.startsWith("$") === true;
11517
+ const firstPart = group3("c1") ?? group3("cc1") ?? group3("rr1");
11518
+ if (firstPart === void 0) throw new Error("Internal: a Reference matched without a column or a row.");
11519
+ const qualifier = reference.slice(0, firstPart.index);
11520
+ const everyRow = range.first.row === 0 && range.last.row === size.rows - 1;
11521
+ const everyColumn = range.first.column === 0 && range.last.column === size.columns - 1;
11522
+ if (group3("cc1") !== void 0 && everyRow) {
11523
+ return `${qualifier}${columnPart(range.first.column, absolute("cc1"))}:${columnPart(range.last.column, absolute("cc2"))}`;
11524
+ }
11525
+ if (group3("rr1") !== void 0 && everyColumn) {
11526
+ return `${qualifier}${rowPart(range.first.row, absolute("rr1"))}:${rowPart(range.last.row, absolute("rr2"))}`;
11527
+ }
11528
+ const [first, second] = group3("cc1") !== void 0 ? [{ column: absolute("cc1"), row: false }, { column: absolute("cc2"), row: false }] : group3("rr1") !== void 0 ? [{ column: false, row: absolute("rr1") }, { column: false, row: absolute("rr2") }] : [{ column: absolute("c1"), row: absolute("r1") }, group3("c2") === void 0 ? { column: absolute("c1"), row: absolute("r1") } : { column: absolute("c2"), row: absolute("r2") }];
11529
+ const start = columnPart(range.first.column, first.column) + rowPart(range.first.row, first.row);
11530
+ if (range.cellCount === 1) return qualifier + start;
11531
+ return `${qualifier}${start}:${columnPart(range.last.column, second.column)}${rowPart(range.last.row, second.row)}`;
11532
+ }
11533
+ function columnPart(index, absolute) {
11534
+ return (absolute ? "$" : "") + CellAddress.columnName(index);
11535
+ }
11536
+ function rowPart(index, absolute) {
11537
+ return `${absolute ? "$" : ""}${String(index + 1)}`;
11538
+ }
11463
11539
  function structuredReferenceText2(table2, column2) {
11464
11540
  if (table2.length === 0) throw new RangeError("The table name is empty.");
11465
11541
  if (column2.length === 0) throw new RangeError("The column name is empty.");
@@ -15892,52 +15968,6 @@ function recorded(cell) {
15892
15968
  return text2;
15893
15969
  }
15894
15970
 
15895
- // src/sheet-size.ts
15896
- var SheetSize = class _SheetSize {
15897
- /** Excel's full size, 1,048,576 rows by 16,384 columns (`A1` to `XFD1048576`): what a Sheet holds unless given another. */
15898
- static excel = new _SheetSize(rowCount, columnCount);
15899
- /** How many rows, from 1 to 1,048,576. */
15900
- rows;
15901
- /** How many columns, from 1 to 16,384. */
15902
- columns;
15903
- /** A size of `rows` by `columns`; one of no rows or no columns, or larger than Excel's, is refused with a `RangeError`. */
15904
- constructor(rows, columns) {
15905
- if (!Number.isInteger(rows) || rows < 1 || rows > rowCount) {
15906
- throw new RangeError(`A Sheet holds from 1 to 1,048,576 rows; ${String(rows)} is not that.`);
15907
- }
15908
- if (!Number.isInteger(columns) || columns < 1 || columns > columnCount) {
15909
- throw new RangeError(`A Sheet holds from 1 to 16,384 columns; ${String(columns)} is not that.`);
15910
- }
15911
- this.rows = rows;
15912
- this.columns = columns;
15913
- }
15914
- /** The last cell inside the size: `XFD1048576` for Excel's, `J10` for ten by ten. */
15915
- get lastCell() {
15916
- return new CellAddress(this.rows - 1, this.columns - 1);
15917
- }
15918
- /** Whether `address` lies inside the size. */
15919
- contains(address) {
15920
- return address.row < this.rows && address.column < this.columns;
15921
- }
15922
- /** Whether a block of `rows` × `columns` with its top-left cell at `origin` lies wholly inside the size. */
15923
- holds(origin, rows, columns) {
15924
- return origin.row + rows <= this.rows && origin.column + columns <= this.columns;
15925
- }
15926
- /**
15927
- * `range` as it stands inside the size, or `undefined` when it runs past it. Whole columns and whole rows are
15928
- * Excel's lines, inside when their columns or rows are, and are answered as long as the size's: `B:B` of ten rows
15929
- * is `B1:B10`.
15930
- */
15931
- fit(range) {
15932
- const last = new CellAddress(range.isWholeColumns ? this.rows - 1 : range.last.row, range.isWholeRows ? this.columns - 1 : range.last.column);
15933
- return this.contains(last) && this.contains(range.first) ? new CellRange(range.first, last) : void 0;
15934
- }
15935
- /** Whether the two are the same size. */
15936
- equals(other) {
15937
- return this.rows === other.rows && this.columns === other.columns;
15938
- }
15939
- };
15940
-
15941
15971
  // src/sheet-edit.ts
15942
15972
  var alignments = ["general", "left", "center", "right"];
15943
15973
  var fillDirections = ["down", "right", "up", "left"];
@@ -17761,6 +17791,7 @@ export {
17761
17791
  formulaReferences,
17762
17792
  lookupFinds,
17763
17793
  lookupText,
17794
+ moveReference,
17764
17795
  numberFormatColourRgb,
17765
17796
  readCellFormatChange,
17766
17797
  readLinkedRows,