@rowsncolumns/spreadsheet 10.10.3 → 10.10.5
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/cjs/api/error-checking.d.ts +39 -3
- package/dist/cjs/api/error-checking.d.ts.map +1 -1
- package/dist/cjs/api/error-checking.js +169 -13
- package/dist/cjs/api/excel-edit-value.d.ts +18 -0
- package/dist/cjs/api/excel-edit-value.d.ts.map +1 -0
- package/dist/cjs/api/excel-edit-value.js +98 -0
- package/dist/cjs/api/split-pane.d.ts +19 -0
- package/dist/cjs/api/split-pane.d.ts.map +1 -0
- package/dist/cjs/api/split-pane.js +70 -0
- package/dist/cjs/atoms/cell-input-context.atom.d.ts.map +1 -1
- package/dist/cjs/components/canvas-grid/index.d.ts.map +1 -1
- package/dist/cjs/components/canvas-grid/index.js +125 -68
- package/dist/cjs/components/canvas-grid/typings.d.ts +30 -0
- package/dist/cjs/components/canvas-grid/typings.d.ts.map +1 -1
- package/dist/cjs/components/error-check-smart-tag/index.d.ts +3 -2
- package/dist/cjs/components/error-check-smart-tag/index.d.ts.map +1 -1
- package/dist/cjs/components/error-check-smart-tag/index.js +4 -2
- package/dist/cjs/components/filter-box/filter-by-color.d.ts +1 -1
- package/dist/cjs/components/filter-box/filter-by-color.d.ts.map +1 -1
- package/dist/cjs/components/filter-box/filter-by-color.js +3 -6
- package/dist/cjs/components/filter-box/index.d.ts.map +1 -1
- package/dist/cjs/components/filter-box/index.js +1 -3
- package/dist/cjs/components/hidden-markers/index.d.ts.map +1 -1
- package/dist/cjs/components/hidden-markers/index.js +7 -8
- package/dist/cjs/components/hidden-markers/style.d.ts +0 -7
- package/dist/cjs/components/hidden-markers/style.d.ts.map +1 -1
- package/dist/cjs/components/hidden-markers/style.js +2 -13
- package/dist/cjs/components/print-preview/page-block.d.ts +2 -0
- package/dist/cjs/components/print-preview/page-block.d.ts.map +1 -1
- package/dist/cjs/components/print-preview/page-block.js +131 -101
- package/dist/cjs/components/print-preview/page-break-preview.d.ts.map +1 -1
- package/dist/cjs/components/print-preview/page-break-preview.js +5 -3
- package/dist/cjs/components/print-preview/print-preview-dialog.d.ts +1 -1
- package/dist/cjs/components/print-preview/print-preview-dialog.d.ts.map +1 -1
- package/dist/cjs/components/print-preview/print-preview-dialog.js +38 -17
- package/dist/cjs/components/print-preview/settings.d.ts +22 -1
- package/dist/cjs/components/print-preview/settings.d.ts.map +1 -1
- package/dist/cjs/components/print-preview/settings.js +54 -1
- package/dist/cjs/components/print-preview/sheet-page-setup.d.ts +22 -1
- package/dist/cjs/components/print-preview/sheet-page-setup.d.ts.map +1 -1
- package/dist/cjs/components/print-preview/sheet-page-setup.js +59 -3
- package/dist/cjs/hooks/use-copy-paste-cut.d.ts.map +1 -1
- package/dist/cjs/hooks/use-copy-paste-cut.js +5 -2
- package/dist/cjs/hooks/use-editor-submit.d.ts +9 -1
- package/dist/cjs/hooks/use-editor-submit.d.ts.map +1 -1
- package/dist/cjs/hooks/use-editor-submit.js +39 -15
- package/dist/cjs/hooks/use-embeds-charts.d.ts.map +1 -1
- package/dist/cjs/hooks/use-embeds-charts.js +6 -4
- package/dist/cjs/hooks/use-selection-renderer.d.ts +3 -1
- package/dist/cjs/hooks/use-selection-renderer.d.ts.map +1 -1
- package/dist/cjs/hooks/use-selection-renderer.js +4 -3
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/release-date.js +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/cjs/types.d.ts +44 -2
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/esm/api/error-checking.d.ts +39 -3
- package/dist/esm/api/error-checking.d.ts.map +1 -1
- package/dist/esm/api/error-checking.js +128 -3
- package/dist/esm/api/excel-edit-value.d.ts +18 -0
- package/dist/esm/api/excel-edit-value.d.ts.map +1 -0
- package/dist/esm/api/excel-edit-value.js +90 -0
- package/dist/esm/api/split-pane.d.ts +19 -0
- package/dist/esm/api/split-pane.d.ts.map +1 -0
- package/dist/esm/api/split-pane.js +63 -0
- package/dist/esm/atoms/cell-input-context.atom.d.ts.map +1 -1
- package/dist/esm/components/canvas-grid/index.d.ts.map +1 -1
- package/dist/esm/components/canvas-grid/index.js +59 -5
- package/dist/esm/components/canvas-grid/typings.d.ts +30 -0
- package/dist/esm/components/canvas-grid/typings.d.ts.map +1 -1
- package/dist/esm/components/error-check-smart-tag/index.d.ts +3 -2
- package/dist/esm/components/error-check-smart-tag/index.d.ts.map +1 -1
- package/dist/esm/components/error-check-smart-tag/index.js +4 -2
- package/dist/esm/components/filter-box/filter-by-color.d.ts +1 -1
- package/dist/esm/components/filter-box/filter-by-color.d.ts.map +1 -1
- package/dist/esm/components/filter-box/filter-by-color.js +3 -6
- package/dist/esm/components/filter-box/index.d.ts.map +1 -1
- package/dist/esm/components/filter-box/index.js +1 -3
- package/dist/esm/components/hidden-markers/index.d.ts.map +1 -1
- package/dist/esm/components/hidden-markers/index.js +8 -9
- package/dist/esm/components/hidden-markers/style.d.ts +0 -7
- package/dist/esm/components/hidden-markers/style.d.ts.map +1 -1
- package/dist/esm/components/hidden-markers/style.js +1 -8
- package/dist/esm/components/print-preview/page-block.d.ts +2 -0
- package/dist/esm/components/print-preview/page-block.d.ts.map +1 -1
- package/dist/esm/components/print-preview/page-block.js +141 -110
- package/dist/esm/components/print-preview/page-break-preview.d.ts.map +1 -1
- package/dist/esm/components/print-preview/page-break-preview.js +6 -4
- package/dist/esm/components/print-preview/print-preview-dialog.d.ts +1 -1
- package/dist/esm/components/print-preview/print-preview-dialog.d.ts.map +1 -1
- package/dist/esm/components/print-preview/print-preview-dialog.js +40 -19
- package/dist/esm/components/print-preview/settings.d.ts +22 -1
- package/dist/esm/components/print-preview/settings.d.ts.map +1 -1
- package/dist/esm/components/print-preview/settings.js +50 -0
- package/dist/esm/components/print-preview/sheet-page-setup.d.ts +22 -1
- package/dist/esm/components/print-preview/sheet-page-setup.d.ts.map +1 -1
- package/dist/esm/components/print-preview/sheet-page-setup.js +51 -0
- package/dist/esm/hooks/use-copy-paste-cut.d.ts.map +1 -1
- package/dist/esm/hooks/use-copy-paste-cut.js +5 -2
- package/dist/esm/hooks/use-editor-submit.d.ts +9 -1
- package/dist/esm/hooks/use-editor-submit.d.ts.map +1 -1
- package/dist/esm/hooks/use-editor-submit.js +24 -1
- package/dist/esm/hooks/use-embeds-charts.d.ts.map +1 -1
- package/dist/esm/hooks/use-embeds-charts.js +7 -4
- package/dist/esm/hooks/use-selection-renderer.d.ts +3 -1
- package/dist/esm/hooks/use-selection-renderer.d.ts.map +1 -1
- package/dist/esm/hooks/use-selection-renderer.js +4 -3
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/release-date.js +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esm/types.d.ts +44 -2
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/spreadsheet.min.css +1 -1
- package/package.json +6 -6
|
@@ -19,6 +19,114 @@ export const parseNumberStoredAsText = (text) => {
|
|
|
19
19
|
return undefined;
|
|
20
20
|
return isPercent ? value / 100 : value;
|
|
21
21
|
};
|
|
22
|
+
/**
|
|
23
|
+
* The functions Excel's "Formulas which omit cells in a region" rule looks at: the ones that sum
|
|
24
|
+
* up a block of numbers (`=SUM(A3:A5)` beside more numbers).
|
|
25
|
+
*/
|
|
26
|
+
const REGION_FUNCTIONS = "SUM|AVERAGE|AVERAGEA|COUNT|COUNTA|MIN|MAX|MINA|MAXA|PRODUCT|MEDIAN|MODE|STDEV|STDEV\\.S|STDEV\\.P|STDEVA|STDEVP|VAR|VAR\\.S|VAR\\.P|VARA|VARP";
|
|
27
|
+
/** `FN( A1:A9 )` with a single same-sheet range argument; quoted text is skipped by the caller. */
|
|
28
|
+
const REGION_CALL = new RegExp(`(?<![A-Za-z0-9_.!])(?:${REGION_FUNCTIONS})\\(\\s*(\\$?)([A-Za-z]{1,3})(\\$?)(\\d+):(\\$?)([A-Za-z]{1,3})(\\$?)(\\d+)\\s*\\)`, "gi");
|
|
29
|
+
const columnNumber = (letters) => letters
|
|
30
|
+
.toUpperCase()
|
|
31
|
+
.split("")
|
|
32
|
+
.reduce((total, letter) => total * 26 + letter.charCodeAt(0) - 64, 0);
|
|
33
|
+
const columnLetters = (column) => {
|
|
34
|
+
let letters = "";
|
|
35
|
+
for (let n = column; n > 0; n = Math.floor((n - 1) / 26)) {
|
|
36
|
+
letters = String.fromCharCode(65 + ((n - 1) % 26)) + letters;
|
|
37
|
+
}
|
|
38
|
+
return letters;
|
|
39
|
+
};
|
|
40
|
+
const MAX_REFERENCE_CACHE = 5_000;
|
|
41
|
+
const referenceCache = new Map();
|
|
42
|
+
/** The one-column / one-row ranges a formula hands to {@link REGION_FUNCTIONS}, in text order. */
|
|
43
|
+
const regionReferences = (formula) => {
|
|
44
|
+
const cached = referenceCache.get(formula);
|
|
45
|
+
if (cached)
|
|
46
|
+
return cached;
|
|
47
|
+
// Blank out string literals so a quoted `"SUM(A1:A2)"` is not read as a call.
|
|
48
|
+
const text = formula.replace(/"(?:[^"]|"")*"/g, (match) => " ".repeat(match.length));
|
|
49
|
+
const references = [];
|
|
50
|
+
for (const match of text.matchAll(REGION_CALL)) {
|
|
51
|
+
const [whole, a1, c1, a2, r1, a3, c2, a4, r2] = match;
|
|
52
|
+
const startColumn = columnNumber(c1);
|
|
53
|
+
const endColumn = columnNumber(c2);
|
|
54
|
+
const startRow = Number(r1);
|
|
55
|
+
const endRow = Number(r2);
|
|
56
|
+
if (startRow > endRow || startColumn > endColumn)
|
|
57
|
+
continue;
|
|
58
|
+
if (startRow !== endRow && startColumn !== endColumn)
|
|
59
|
+
continue;
|
|
60
|
+
const offset = match.index + whole.indexOf("(") + 1;
|
|
61
|
+
const start = text.indexOf(`${a1}${c1}`, offset);
|
|
62
|
+
references.push({
|
|
63
|
+
start,
|
|
64
|
+
end: start + `${a1}${c1}${a2}${r1}:${a3}${c2}${a4}${r2}`.length,
|
|
65
|
+
range: {
|
|
66
|
+
startRowIndex: startRow,
|
|
67
|
+
endRowIndex: endRow,
|
|
68
|
+
startColumnIndex: startColumn,
|
|
69
|
+
endColumnIndex: endColumn,
|
|
70
|
+
},
|
|
71
|
+
absolute: [a1 === "$", a2 === "$", a3 === "$", a4 === "$"],
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (referenceCache.size >= MAX_REFERENCE_CACHE)
|
|
75
|
+
referenceCache.clear();
|
|
76
|
+
referenceCache.set(formula, references);
|
|
77
|
+
return references;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Excel's "Formulas which omit cells in a region" rule: a formula such as `=SUM(A3:A5)` whose
|
|
81
|
+
* one-column (or one-row) range stops next to more numbers in that column (row) — `A2` holds a
|
|
82
|
+
* number. The adjacent run of numbers on each end is what "Update Formula to Include Cells" adds;
|
|
83
|
+
* it never runs into the formula's own cell. `isNumber` says whether a cell holds a number typed as a
|
|
84
|
+
* value (not text, not a formula). `undefined` when the formula omits nothing.
|
|
85
|
+
*/
|
|
86
|
+
export const findOmittedAdjacentCells = (formula, formulaCell, isNumber) => {
|
|
87
|
+
if (!formula)
|
|
88
|
+
return undefined;
|
|
89
|
+
for (const reference of regionReferences(formula)) {
|
|
90
|
+
const { range } = reference;
|
|
91
|
+
const vertical = range.startColumnIndex === range.endColumnIndex;
|
|
92
|
+
const at = (index) => vertical
|
|
93
|
+
? { rowIndex: index, columnIndex: range.startColumnIndex }
|
|
94
|
+
: { rowIndex: range.startRowIndex, columnIndex: index };
|
|
95
|
+
const usable = (index) => {
|
|
96
|
+
if (index < 1)
|
|
97
|
+
return false;
|
|
98
|
+
const cell = at(index);
|
|
99
|
+
if (cell.rowIndex === formulaCell.rowIndex &&
|
|
100
|
+
cell.columnIndex === formulaCell.columnIndex) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
return isNumber(cell.rowIndex, cell.columnIndex);
|
|
104
|
+
};
|
|
105
|
+
const first = vertical ? range.startRowIndex : range.startColumnIndex;
|
|
106
|
+
const last = vertical ? range.endRowIndex : range.endColumnIndex;
|
|
107
|
+
let newFirst = first;
|
|
108
|
+
while (usable(newFirst - 1))
|
|
109
|
+
newFirst--;
|
|
110
|
+
let newLast = last;
|
|
111
|
+
// A range of one cell has no direction to grow along beyond its own.
|
|
112
|
+
while (first !== last && usable(newLast + 1))
|
|
113
|
+
newLast++;
|
|
114
|
+
if (newFirst === first && newLast === last)
|
|
115
|
+
continue;
|
|
116
|
+
const expandedRange = vertical
|
|
117
|
+
? { ...range, startRowIndex: newFirst, endRowIndex: newLast }
|
|
118
|
+
: { ...range, startColumnIndex: newFirst, endColumnIndex: newLast };
|
|
119
|
+
const [c1, r1, c2, r2] = reference.absolute.map((flag) => (flag ? "$" : ""));
|
|
120
|
+
const text = `${c1}${columnLetters(expandedRange.startColumnIndex)}${r1}${expandedRange.startRowIndex}:` +
|
|
121
|
+
`${c2}${columnLetters(expandedRange.endColumnIndex)}${r2}${expandedRange.endRowIndex}`;
|
|
122
|
+
return {
|
|
123
|
+
range,
|
|
124
|
+
expandedRange,
|
|
125
|
+
updatedFormula: formula.slice(0, reference.start) + text + formula.slice(reference.end),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
return undefined;
|
|
129
|
+
};
|
|
22
130
|
/**
|
|
23
131
|
* The text a cell's value is, or `undefined` when its value is not text: `ev.sv` when the cell has
|
|
24
132
|
* an effective value (a number typed into a Text-formatted cell, or after an apostrophe, is text
|
|
@@ -32,10 +140,15 @@ const getCellText = (userEnteredValue, effectiveValue) => effectiveValue
|
|
|
32
140
|
* A typed error constant (`#N/A` entered as a value) is not flagged — only a formula's result.
|
|
33
141
|
* A data-validation failure is not an error-checking rule (Excel only circles it on request).
|
|
34
142
|
*/
|
|
35
|
-
export const getErrorCheckKind = ({ userEnteredValue, effectiveValue, errorValue, }) => {
|
|
143
|
+
export const getErrorCheckKind = ({ userEnteredValue, effectiveValue, errorValue, cell, isNumberAt, }) => {
|
|
36
144
|
const formula = userEnteredValue?.fv ?? userEnteredValue?.formulaValue;
|
|
37
145
|
if (formula) {
|
|
38
|
-
|
|
146
|
+
if (errorValue?.type === "Error")
|
|
147
|
+
return "evalError";
|
|
148
|
+
if (cell && isNumberAt && findOmittedAdjacentCells(formula, cell, isNumberAt)) {
|
|
149
|
+
return "formulaRange";
|
|
150
|
+
}
|
|
151
|
+
return undefined;
|
|
39
152
|
}
|
|
40
153
|
const text = getCellText(userEnteredValue, effectiveValue);
|
|
41
154
|
if (parseNumberStoredAsText(text) !== undefined)
|
|
@@ -56,7 +169,9 @@ const ERROR_TITLES = {
|
|
|
56
169
|
/** The menu's heading, as Excel words it. */
|
|
57
170
|
export const getErrorCheckTitle = (kind, errorName) => kind === "numberStoredAsText"
|
|
58
171
|
? "Number Stored as Text"
|
|
59
|
-
:
|
|
172
|
+
: kind === "formulaRange"
|
|
173
|
+
? "Formula Omits Adjacent Cells"
|
|
174
|
+
: (errorName && ERROR_TITLES[errorName]) || "Error in Formula";
|
|
60
175
|
/** Excel's own help pages: hiding error values and error indicators, and the rule options. */
|
|
61
176
|
export const ERROR_CHECKING_HELP_URL = "https://support.microsoft.com/en-us/office/hide-error-values-and-error-indicators-in-cells-d171b96e-8fb4-4863-a1ba-b64557474439";
|
|
62
177
|
const ERROR_HELP_URLS = {
|
|
@@ -151,6 +266,16 @@ export const runErrorCheckOption = (option, context) => {
|
|
|
151
266
|
write();
|
|
152
267
|
return;
|
|
153
268
|
}
|
|
269
|
+
case "updateFormulaToIncludeCells": {
|
|
270
|
+
const cell = context.activeCell;
|
|
271
|
+
if (!cell || !context.isNumberAt)
|
|
272
|
+
return;
|
|
273
|
+
const uev = context.getUserEnteredValue(cell.rowIndex, cell.columnIndex);
|
|
274
|
+
const omitted = findOmittedAdjacentCells(uev?.fv ?? uev?.formulaValue, cell, context.isNumberAt);
|
|
275
|
+
if (omitted)
|
|
276
|
+
context.onChange?.(sheetId, cell, omitted.updatedFormula);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
154
279
|
case "ignore":
|
|
155
280
|
context.onUpdateSheet?.(sheetId, {
|
|
156
281
|
ignoredErrors: appendIgnoredError(context.getIgnoredErrors?.(sheetId), ranges, kind),
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The number format a date, time or percentage cell shows in Excel's formula bar and cell editor:
|
|
3
|
+
* not the cell's display (`2-Jan`, which drops the year), but the whole value in the person's short
|
|
4
|
+
* date and long time, so the entry can be read and edited back to the same value.
|
|
5
|
+
*
|
|
6
|
+
* - a date: the short date (`1/2/2026` in en-US),
|
|
7
|
+
* - a time of day: the long time (`3:00:00 PM`),
|
|
8
|
+
* - a date with a time: both (`1/2/2026 3:00:00 PM`),
|
|
9
|
+
* - a percentage: the number times 100 with `%` (`12.5%`).
|
|
10
|
+
*
|
|
11
|
+
* `undefined` for any other cell: it edits as its number.
|
|
12
|
+
*/
|
|
13
|
+
export declare const excelEditValueOfNumber: (value: number, numberFormatType: string | null | undefined, locale?: string) => string | undefined;
|
|
14
|
+
/** The locale's short date as a number format (`m/d/yyyy` in en-US, `dd.mm.yyyy` in de-DE). */
|
|
15
|
+
export declare const shortDatePattern: (locale?: string) => string;
|
|
16
|
+
/** The locale's long time as a number format (`h:mm:ss AM/PM` in en-US, `h:mm:ss` in de-DE). */
|
|
17
|
+
export declare const longTimePattern: (locale?: string) => string;
|
|
18
|
+
//# sourceMappingURL=excel-edit-value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"excel-edit-value.d.ts","sourceRoot":"","sources":["../../../api/excel-edit-value.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,sBAAsB,GACjC,OAAO,MAAM,EACb,kBAAkB,MAAM,GAAG,IAAI,GAAG,SAAS,EAC3C,SAAS,MAAM,KACd,MAAM,GAAG,SA4BX,CAAC;AAIF,+FAA+F;AAC/F,eAAO,MAAM,gBAAgB,GAAI,eAAgB,KAAG,MA+BnD,CAAC;AAEF,gGAAgG;AAChG,eAAO,MAAM,eAAe,GAAI,eAAgB,KAAG,MAQlD,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { ssfFormat } from "@rowsncolumns/utils";
|
|
2
|
+
/**
|
|
3
|
+
* The number format a date, time or percentage cell shows in Excel's formula bar and cell editor:
|
|
4
|
+
* not the cell's display (`2-Jan`, which drops the year), but the whole value in the person's short
|
|
5
|
+
* date and long time, so the entry can be read and edited back to the same value.
|
|
6
|
+
*
|
|
7
|
+
* - a date: the short date (`1/2/2026` in en-US),
|
|
8
|
+
* - a time of day: the long time (`3:00:00 PM`),
|
|
9
|
+
* - a date with a time: both (`1/2/2026 3:00:00 PM`),
|
|
10
|
+
* - a percentage: the number times 100 with `%` (`12.5%`).
|
|
11
|
+
*
|
|
12
|
+
* `undefined` for any other cell: it edits as its number.
|
|
13
|
+
*/
|
|
14
|
+
export const excelEditValueOfNumber = (value, numberFormatType, locale) => {
|
|
15
|
+
if (!Number.isFinite(value))
|
|
16
|
+
return undefined;
|
|
17
|
+
if (numberFormatType === "PERCENT") {
|
|
18
|
+
return `${Number((value * 100).toPrecision(15))}%`;
|
|
19
|
+
}
|
|
20
|
+
if (numberFormatType !== "DATE" &&
|
|
21
|
+
numberFormatType !== "DATE_TIME" &&
|
|
22
|
+
numberFormatType !== "TIME") {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
// Before Excel's day 0 a date has no spelling: it edits as its number, as in Excel.
|
|
26
|
+
if (value < 0)
|
|
27
|
+
return undefined;
|
|
28
|
+
const day = Math.floor(value);
|
|
29
|
+
const hasTime = value - day > 0 || numberFormatType === "TIME";
|
|
30
|
+
const pattern = day === 0 && numberFormatType !== "DATE"
|
|
31
|
+
? longTimePattern(locale)
|
|
32
|
+
: hasTime
|
|
33
|
+
? `${shortDatePattern(locale)} ${longTimePattern(locale)}`
|
|
34
|
+
: shortDatePattern(locale);
|
|
35
|
+
try {
|
|
36
|
+
const formatted = ssfFormat(pattern, value, locale);
|
|
37
|
+
return typeof formatted === "string" && formatted !== "" ? formatted : undefined;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const shortDateCache = new Map();
|
|
44
|
+
/** The locale's short date as a number format (`m/d/yyyy` in en-US, `dd.mm.yyyy` in de-DE). */
|
|
45
|
+
export const shortDatePattern = (locale = "en-US") => {
|
|
46
|
+
const cached = shortDateCache.get(locale);
|
|
47
|
+
if (cached)
|
|
48
|
+
return cached;
|
|
49
|
+
let pattern = "m/d/yyyy";
|
|
50
|
+
try {
|
|
51
|
+
const parts = new Intl.DateTimeFormat(locale, {
|
|
52
|
+
year: "numeric",
|
|
53
|
+
month: "numeric",
|
|
54
|
+
day: "numeric",
|
|
55
|
+
}).formatToParts(new Date(2026, 0, 2));
|
|
56
|
+
const tokens = parts.map((part) => {
|
|
57
|
+
switch (part.type) {
|
|
58
|
+
case "year":
|
|
59
|
+
return "yyyy";
|
|
60
|
+
case "month":
|
|
61
|
+
return part.value.length > 1 ? "mm" : "m";
|
|
62
|
+
case "day":
|
|
63
|
+
return part.value.length > 1 ? "dd" : "d";
|
|
64
|
+
case "literal":
|
|
65
|
+
return part.value.replace(/[^\s./,-]/g, "");
|
|
66
|
+
default:
|
|
67
|
+
return "";
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
const built = tokens.join("").trim();
|
|
71
|
+
if (/y/.test(built) && /m/.test(built) && /d/.test(built))
|
|
72
|
+
pattern = built;
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// An unknown locale keeps the en-US short date.
|
|
76
|
+
}
|
|
77
|
+
shortDateCache.set(locale, pattern);
|
|
78
|
+
return pattern;
|
|
79
|
+
};
|
|
80
|
+
/** The locale's long time as a number format (`h:mm:ss AM/PM` in en-US, `h:mm:ss` in de-DE). */
|
|
81
|
+
export const longTimePattern = (locale = "en-US") => {
|
|
82
|
+
try {
|
|
83
|
+
const hour12 = new Intl.DateTimeFormat(locale, { hour: "numeric" }).resolvedOptions()
|
|
84
|
+
.hour12;
|
|
85
|
+
return hour12 === false ? "h:mm:ss" : "h:mm:ss AM/PM";
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return "h:mm:ss AM/PM";
|
|
89
|
+
}
|
|
90
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CellInterface } from "@rowsncolumns/common-types";
|
|
2
|
+
import type { SplitPane } from "../types";
|
|
3
|
+
/** Twentieths of a point per CSS pixel (96 px = 72 pt = 1440 twips). */
|
|
4
|
+
export declare const TWIPS_PER_PIXEL = 15;
|
|
5
|
+
/**
|
|
6
|
+
* Excel's View ▸ Split at the active cell: the window splits above and left of it, so the cell
|
|
7
|
+
* starts the bottom-right pane. A cell in the first visible row splits only vertically (left /
|
|
8
|
+
* right), one in the first visible column only horizontally (top / bottom), and the first visible
|
|
9
|
+
* cell itself splits the window into four panes at its middle, as Excel does. `getColumnWidth` /
|
|
10
|
+
* `getRowHeight` are the on-screen sizes in px (at 100% zoom); `firstVisible` is the top-left
|
|
11
|
+
* cell of the scrolled window. Returns `undefined` when there is nothing to split.
|
|
12
|
+
*/
|
|
13
|
+
export declare const splitPaneAtCell: (activeCell: CellInterface, firstVisible: CellInterface, getColumnWidth: (columnIndex: number) => number, getRowHeight: (rowIndex: number) => number) => SplitPane | undefined;
|
|
14
|
+
/** A split's positions in CSS px from the grid's top-left (`undefined` = no split on that axis). */
|
|
15
|
+
export declare const splitPanePixels: (pane: SplitPane | null | undefined) => {
|
|
16
|
+
x?: number;
|
|
17
|
+
y?: number;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=split-pane.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"split-pane.d.ts","sourceRoot":"","sources":["../../../api/split-pane.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAEhE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,wEAAwE;AACxE,eAAO,MAAM,eAAe,KAAK,CAAC;AAUlC;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAC1B,YAAY,aAAa,EACzB,cAAc,aAAa,EAC3B,gBAAgB,CAAC,WAAW,EAAE,MAAM,KAAK,MAAM,EAC/C,cAAc,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,KACzC,SAAS,GAAG,SAmCd,CAAC;AAEF,oGAAoG;AACpG,eAAO,MAAM,eAAe,GAC1B,MAAM,SAAS,GAAG,IAAI,GAAG,SAAS,KACjC;IAAE,CAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,CAAC,EAAE,MAAM,CAAA;CAI1B,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** Twentieths of a point per CSS pixel (96 px = 72 pt = 1440 twips). */
|
|
2
|
+
export const TWIPS_PER_PIXEL = 15;
|
|
3
|
+
const columnLetters = (column) => {
|
|
4
|
+
let letters = "";
|
|
5
|
+
for (let n = column; n > 0; n = Math.floor((n - 1) / 26)) {
|
|
6
|
+
letters = String.fromCharCode(65 + ((n - 1) % 26)) + letters;
|
|
7
|
+
}
|
|
8
|
+
return letters;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Excel's View ▸ Split at the active cell: the window splits above and left of it, so the cell
|
|
12
|
+
* starts the bottom-right pane. A cell in the first visible row splits only vertically (left /
|
|
13
|
+
* right), one in the first visible column only horizontally (top / bottom), and the first visible
|
|
14
|
+
* cell itself splits the window into four panes at its middle, as Excel does. `getColumnWidth` /
|
|
15
|
+
* `getRowHeight` are the on-screen sizes in px (at 100% zoom); `firstVisible` is the top-left
|
|
16
|
+
* cell of the scrolled window. Returns `undefined` when there is nothing to split.
|
|
17
|
+
*/
|
|
18
|
+
export const splitPaneAtCell = (activeCell, firstVisible, getColumnWidth, getRowHeight) => {
|
|
19
|
+
const { rowIndex, columnIndex } = activeCell;
|
|
20
|
+
if (rowIndex <= firstVisible.rowIndex && columnIndex <= firstVisible.columnIndex) {
|
|
21
|
+
// Excel splits the window at the middle when the active cell is its first cell.
|
|
22
|
+
let width = 0;
|
|
23
|
+
let column = firstVisible.columnIndex;
|
|
24
|
+
let height = 0;
|
|
25
|
+
let row = firstVisible.rowIndex;
|
|
26
|
+
// Half a default window: 10 columns and 20 rows.
|
|
27
|
+
for (let i = 0; i < 5; i++)
|
|
28
|
+
width += getColumnWidth(column++);
|
|
29
|
+
for (let i = 0; i < 10; i++)
|
|
30
|
+
height += getRowHeight(row++);
|
|
31
|
+
return {
|
|
32
|
+
xSplit: Math.round(width * TWIPS_PER_PIXEL),
|
|
33
|
+
ySplit: Math.round(height * TWIPS_PER_PIXEL),
|
|
34
|
+
topLeftCell: `${columnLetters(column)}${row}`,
|
|
35
|
+
activePane: "bottomRight",
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
let width = 0;
|
|
39
|
+
for (let column = firstVisible.columnIndex; column < columnIndex; column++) {
|
|
40
|
+
width += getColumnWidth(column);
|
|
41
|
+
}
|
|
42
|
+
let height = 0;
|
|
43
|
+
for (let row = firstVisible.rowIndex; row < rowIndex; row++) {
|
|
44
|
+
height += getRowHeight(row);
|
|
45
|
+
}
|
|
46
|
+
if (width <= 0 && height <= 0)
|
|
47
|
+
return undefined;
|
|
48
|
+
const pane = {
|
|
49
|
+
topLeftCell: `${columnLetters(Math.max(columnIndex, 1))}${Math.max(rowIndex, 1)}`,
|
|
50
|
+
};
|
|
51
|
+
if (width > 0)
|
|
52
|
+
pane.xSplit = Math.round(width * TWIPS_PER_PIXEL);
|
|
53
|
+
if (height > 0)
|
|
54
|
+
pane.ySplit = Math.round(height * TWIPS_PER_PIXEL);
|
|
55
|
+
pane.activePane =
|
|
56
|
+
width > 0 && height > 0 ? "bottomRight" : width > 0 ? "topRight" : "bottomLeft";
|
|
57
|
+
return pane;
|
|
58
|
+
};
|
|
59
|
+
/** A split's positions in CSS px from the grid's top-left (`undefined` = no split on that axis). */
|
|
60
|
+
export const splitPanePixels = (pane) => {
|
|
61
|
+
const px = (twips) => typeof twips === "number" && twips > 0 ? twips / TWIPS_PER_PIXEL : undefined;
|
|
62
|
+
return { x: px(pane?.xSplit), y: px(pane?.ySplit) };
|
|
63
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cell-input-context.atom.d.ts","sourceRoot":"","sources":["../../../atoms/cell-input-context.atom.ts"],"names":[],"mappings":"AAoCA,eAAO,MAAM,mBAAmB;;;;oBAC+
|
|
1
|
+
{"version":3,"file":"cell-input-context.atom.d.ts","sourceRoot":"","sources":["../../../atoms/cell-input-context.atom.ts"],"names":[],"mappings":"AAoCA,eAAO,MAAM,mBAAmB;;;;oBAC+9xF,CAAC;qBAAwB,CAAC;;;;;;;;;;;CAD18xF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/canvas-grid/index.tsx"],"names":[],"mappings":"AAmEA,OAAO,KASN,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/canvas-grid/index.tsx"],"names":[],"mappings":"AAmEA,OAAO,KASN,MAAM,OAAO,CAAC;AAwQf,OAAO,KAAK,EAGV,QAAQ,EAYT,MAAM,aAAa,CAAC;AA4CrB,OAAO,KAAK,EACV,wBAAwB,EACxB,iBAAiB,EACjB,eAAe,EAEhB,MAAM,WAAW,CAAC;AAsoOnB,eAAO,MAAM,UAAU,EAA4C,CACjE,CAAC,SAAS,QAAQ,CAAC,GAAG,CAAC,EAEvB,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,GACvB,wBAAwB,GAAG;IAAE,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;CAAE,KAChE,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC"}
|
|
@@ -11,6 +11,7 @@ import merge from "lodash/merge";
|
|
|
11
11
|
import throttle from "lodash/throttle";
|
|
12
12
|
import React, { forwardRef, memo, startTransition, useCallback, useEffect, useMemo, useRef, useState, } from "react";
|
|
13
13
|
import { getBandedCells } from "../../api/banded-ranges";
|
|
14
|
+
import { excelEditValueOfNumber } from "../../api/excel-edit-value";
|
|
14
15
|
import { getErrorCheckKind, isErrorIgnored, runErrorCheckOption, } from "../../api/error-checking";
|
|
15
16
|
import { formulaBarEditorInstanceAtom } from "../../atoms/formula-bar-editor-value.atom";
|
|
16
17
|
import { clearRangeForInsertedBand, formatsForInsertOption, insertedBandHasValues, } from "../../api/insert-options";
|
|
@@ -156,7 +157,7 @@ function isDetachedEditor(editor) {
|
|
|
156
157
|
return element != null && !element.isConnected;
|
|
157
158
|
}
|
|
158
159
|
function CanvasGridComponent(props, forwardedRef) {
|
|
159
|
-
const { licenseKey, sheetId, sheetType, ChartSheetView: ChartSheetViewComponent = ChartSheetView, instanceId, activeCell = DEFAULT_ACTIVE_CELL, selections = DEFAULT_ARRAY, frozenColumnCount = 0, frozenRowCount = 0, rowCount = DEFAULT_ROW_COUNT, columnCount = DEFAULT_COLUMN_COUNT, autoFocus, basicFilter, tables, namedRanges, bandedRanges = DEFAULT_ARRAY, tableBorderColor = "#008000", filterIconColor = FILTER_BUTTON_GLYPH_COLOR, conditionalFormats, showFilterIcon = true, showCalculatedColumnIcon = true, showHeaders = true, defaultColumnWidth = DEFAULT_COLUMN_WIDTH, defaultRowHeight = DEFAULT_ROW_HEIGHT, lineHeightMode = "fontMetrics", columnHeaderHeight = COLUMN_HEADER_HEIGHT, rowHeaderWidth = ROW_HEADER_WIDTH, gridLineColor = GRIDLINE_COLOR, cellBackgroundColor = DEFAULT_CELL_BACKGROUND_COLOR, cellColor = DEFAULT_CELL_COLOR, headerBorderColor = DEFAULT_HEADER_BORDER_COLOR, headerBackgroundColor = DEFAULT_HEADER_BG, headerColor = DEFAULT_HEADER_COLOR, headerActiveBackgroundColor = DEFAULT_HEADER_ACTIVE_BG, headerSelectedBackgroundColor = DEFAULT_HEADER_SELECTED_BG, headerSelectedColor = "white", headerTableBackgroundColor = DEFAULT_HEADER_TABLE_BG, headerTableActiveBackgroundColor = DEFAULT_HEADER_ACTIVE_TABLE_BG, headerTableSelectedBackgroundColor = DEFAULT_HEADER_SELECTED_TABLE_BG, frozenShadowColor = headerBorderColor, frozenShadowThickness = 1, selectionBackgroundColor = SELECTION_BG, selectionBorderColor = SELECTION_BORDER, selectionStrokeWidth, showActiveCellBorderInSelection, selectionDragBorderColor = SELECTION_BORDER, chartSelectedColor, chipBackgroundColor = CHIP_COLOR, merges = DEFAULT_ARRAY, borderStyles, protectedRanges, allowEditRanges, isWorkbookProtected: isWorkbookProtectedProp = false, getSheetProtection, pivotTables, charts, onUpdateChart, onChangeZOrder, embeds, slicers, rowMetadata = DEFAULT_ARRAY, columnMetadata = DEFAULT_ARRAY, scale: zoomScale = 1, zoomSpeed = 1, overscanCount = 3, enableEditOnEnterKey: enableEditOnEnterKeyProp, enterKeyDirection = "down", enableAutoCorrect, shouldHandleKeyDown, enableTextOverflow = true, showGridLines: _showGridLines, showZeros, rightToLeft: _rightToLeft, pageBreaks, pageBreakPreview: pageBreakPreviewProp, workbookView, printSettings, onChangeHeaderFooter, showRulers = true, workbookTitle, showFormulas = false, protectFormulas = false, showFrozenSeparator = true, HeaderCell = DefaultHeaderCell, Cell = DefaultCell, SelectionTitleComponent = SelectionTitle, CellEditor = DefaultCellEditor, CellTooltip, ContextMenu = DefaultContextMenu, ContextMenuWrapper = DefaultContextMenuWrapper, FilterBox = DefaultFilterBox, HeaderMoveDragComponent = DefaultHeaderMoveDragComponent, SuggestionsDropdown, stickyEditor = true, scrollSnap = false, scrollThrottleTimeout, preventBrowserDefaultScroll, mouseMoveThrottleTimeout = 60, tooltipIntentInterval = 60, selectionPolicy, users, userId, renderCollaboratorCursor, functionDescriptions, showHeaderMenuButton = true, scrollbarSize = SCROLLBAR_SIZE, theme = defaultSpreadsheetTheme, showNotes = true, showAllNotes = false, isNoteVisible: isNoteVisibleProp, showComments = true, circleInvalidData = false, getIgnoredErrors, locale, formulaLocale: formulaLocaleProp, referenceStyle = "A1", agentSuggestions, onReviewSuggestion, onShowFormulas, getDataRowCount, getDataRegion, getArrayFormula, getChartComponent, getEmbedComponent, getLinkedPictureSource: getLinkedPictureSourceProp, getSlicerComponent, onChange, onChangeBatch, onChangeArrayFormula, onExpandCollapse, onPivotDrillDown, onDelete, onChangeEditorValue, onFill, onRequestCalculate, onRequestFunctionArguments, onChangeActiveCell, onChangeActiveSheet, onChangeSelections, getSheetName, getSheetId, getCellData, getNote: getNoteProp, getTextFormatRuns, getDataValidation, getEffectiveFormat, getFormattedValue: getFormattedValueProp, getTooltipContent, errorResolutionComponent, getEffectiveValue: getEffectiveValueProp, getSparklineGroup, getUserEnteredExtendedValue, getEffectiveExtendedValue, getSheetRowCount, getSheetColumnCount, getCellPopoverContent, onScroll, onViewPortChange, windowConditionalFormats = false, engineConditionalFormatResults = false, getConditionalFormatRuleStats, onResize, onAutoResize, onHideColumn, onHideRow, onShowColumn, onShowRow, onGroupRows, onUngroupRows, onCollapseRowGroup, onExpandRowGroup, onGroupColumns, onUngroupColumns, onCollapseColumnGroup, onExpandColumnGroup, onSetOutlineDepth, onDeleteRow, onDeleteColumn, onInsertRow, onInsertColumn, onChangeAutoExpandTables, onChangeAutoCalculatedColumns, onInsertCellsShiftDown, onInsertCellsShiftRight, onDeleteCellsShiftLeft, onDeleteCellsShiftUp, onClearContents, onMoveColumns, onMoveRows, onSelectNextSheet, onSelectPreviousSheet, onCreateNewSheet, onKeyDown, onChangeFormatting, onRepeatFormatting, onClearFormatting, onRequestEditProtectedRange, onRequestUnlockAllowEditRange, onMoveChart, onResizeChart, onDeleteChart, onCutChart, onCopyChart, onMoveEmbed, onResizeEmbed, onDeleteEmbed, onRequestEditEmbed, onMoveSlicer, onResizeSlicer, onDeleteSlicer, onDeleteObjects, onRequestEditSlicer, onFillRange, onFlashFill, onFlashFillSuggest, onAcceptFlashFill, disableFillRightShortcut, keymap, enableAutoComplete = true, onCalculateNow, onRequestGoTo, onMoveSelection, onInsertCutCells, onInsertCopiedCells, onInsertTime, onInsertDate, onInsertDateTime, onInsertAutoSum, onUndo, onRedo, batchHistory, onPaste, onReapplyPaste, onCopy, onCut, onSortColumn, onSortTable, onFilterTable, onFilterPivot, onResizeTable, onUndoTableAutoExpansion, onUndoCalculatedColumn, onOverwriteCalculatedColumn, onRequestEditTable, onRequestEditPivotTable, onRequestDeletePivotTable, onRequestCreatePivotChart, onRemoveTable, onCreateTable, onRequestCreateTable, onInsertTableColumn, onDeleteTableColumn, onInsertTableRow, onDeleteTableRow, onUpdateTable, onRequestResizeTable, onRequestInsertSlicer, onCreateBasicFilter, onRequestDefineNamedRange, onRequestFormatCells, onRequestConditionalFormat, onRequestDataValidation, onRequestInsertComment, onRequestInsertLink, onFreezeColumn, onFreezeRow, onUpdateNote, onProtectRange, onUnProtectRange, onSortRange, onRequestSearch, onRequestReplace, onRequestResize, getRowHeaderText = getDefaultRowHeader, getColumnHeaderText: getColumnHeaderTextProp, getAdditionalCellSpacing, tokenizer: defaultTokenizer = defaultFormulaTokenizer, onChangeScale, onRemoveLink, onSelectLink, onSplitTextToColumns, onRemoveDuplicates, onGoalSeek, onSubtotal, onAdvancedFilter, onRequestExpand, cellExpandPredicate, StructuredResult = DefaultStructuredResult, getMentions, getStructuredProperties: getStructuredPropertiesProp, getFunctionParameterSuggestions, shouldFetchFunctionParameters, MentionTagComponent, MentionDropdownItemComponent, showSelectionResizeHandles = true, enableMagicFill, enableQuickEdit = true, MagicFillComponent, MagicFillContent, QuickEdit, PasteMenu, SuggestionAction, HiddenRowMarkers, HiddenColumnMarkers, enableResizerOverflow, className, defaultFontSizePoint = DEFAULT_FONT_SIZE_PT, defaultCellFormat, readonly, isComparing = false, getCellDiff, enableDataBoundaryNavigation, footerHeight, footerComponent, arrowComponents,
|
|
160
|
+
const { licenseKey, sheetId, sheetType, ChartSheetView: ChartSheetViewComponent = ChartSheetView, instanceId, activeCell = DEFAULT_ACTIVE_CELL, selections = DEFAULT_ARRAY, frozenColumnCount = 0, frozenRowCount = 0, rowCount = DEFAULT_ROW_COUNT, columnCount = DEFAULT_COLUMN_COUNT, autoFocus, basicFilter, tables, namedRanges, bandedRanges = DEFAULT_ARRAY, tableBorderColor = "#008000", filterIconColor = FILTER_BUTTON_GLYPH_COLOR, conditionalFormats, showFilterIcon = true, showCalculatedColumnIcon = true, showHeaders = true, defaultColumnWidth = DEFAULT_COLUMN_WIDTH, defaultRowHeight = DEFAULT_ROW_HEIGHT, lineHeightMode = "fontMetrics", columnHeaderHeight = COLUMN_HEADER_HEIGHT, rowHeaderWidth = ROW_HEADER_WIDTH, gridLineColor = GRIDLINE_COLOR, cellBackgroundColor = DEFAULT_CELL_BACKGROUND_COLOR, cellColor = DEFAULT_CELL_COLOR, headerBorderColor = DEFAULT_HEADER_BORDER_COLOR, headerBackgroundColor = DEFAULT_HEADER_BG, headerColor = DEFAULT_HEADER_COLOR, headerActiveBackgroundColor = DEFAULT_HEADER_ACTIVE_BG, headerSelectedBackgroundColor = DEFAULT_HEADER_SELECTED_BG, headerSelectedColor = "white", headerTableBackgroundColor = DEFAULT_HEADER_TABLE_BG, headerTableActiveBackgroundColor = DEFAULT_HEADER_ACTIVE_TABLE_BG, headerTableSelectedBackgroundColor = DEFAULT_HEADER_SELECTED_TABLE_BG, frozenShadowColor = headerBorderColor, frozenShadowThickness = 1, selectionBackgroundColor = SELECTION_BG, selectionBorderColor = SELECTION_BORDER, selectionStrokeWidth, showActiveCellBorderInSelection, selectionDragBorderColor = SELECTION_BORDER, chartSelectedColor, chipBackgroundColor = CHIP_COLOR, merges = DEFAULT_ARRAY, borderStyles, protectedRanges, allowEditRanges, isWorkbookProtected: isWorkbookProtectedProp = false, getSheetProtection, pivotTables, charts, onUpdateChart, onChangeZOrder, embeds, slicers, rowMetadata = DEFAULT_ARRAY, columnMetadata = DEFAULT_ARRAY, scale: zoomScale = 1, zoomSpeed = 1, overscanCount = 3, enableEditOnEnterKey: enableEditOnEnterKeyProp, enterKeyDirection = "down", enableAutoCorrect, shouldHandleKeyDown, enableTextOverflow = true, showGridLines: _showGridLines, showZeros, enableCellDragAndDrop = true, alertBeforeOverwritingCells = true, autoPercentEntry = false, errorCheckingRules, rightToLeft: _rightToLeft, pageBreaks, pageBreakPreview: pageBreakPreviewProp, workbookView, printSettings, onChangeHeaderFooter, showRulers = true, workbookTitle, showFormulas = false, protectFormulas = false, showFrozenSeparator = true, HeaderCell = DefaultHeaderCell, Cell = DefaultCell, SelectionTitleComponent = SelectionTitle, CellEditor = DefaultCellEditor, CellTooltip, ContextMenu = DefaultContextMenu, ContextMenuWrapper = DefaultContextMenuWrapper, FilterBox = DefaultFilterBox, HeaderMoveDragComponent = DefaultHeaderMoveDragComponent, SuggestionsDropdown, stickyEditor = true, scrollSnap = false, scrollThrottleTimeout, preventBrowserDefaultScroll, mouseMoveThrottleTimeout = 60, tooltipIntentInterval = 60, selectionPolicy, users, userId, renderCollaboratorCursor, functionDescriptions, showHeaderMenuButton = true, scrollbarSize = SCROLLBAR_SIZE, theme = defaultSpreadsheetTheme, showNotes = true, showAllNotes = false, isNoteVisible: isNoteVisibleProp, showComments = true, circleInvalidData = false, getIgnoredErrors, locale, formulaLocale: formulaLocaleProp, referenceStyle = "A1", agentSuggestions, onReviewSuggestion, onShowFormulas, getDataRowCount, getDataRegion, getArrayFormula, getChartComponent, getEmbedComponent, getLinkedPictureSource: getLinkedPictureSourceProp, getSlicerComponent, onChange, onChangeBatch, onChangeArrayFormula, onExpandCollapse, onPivotDrillDown, onDelete, onChangeEditorValue, onFill, onRequestCalculate, onRequestFunctionArguments, onChangeActiveCell, onChangeActiveSheet, onChangeSelections, getSheetName, getSheetId, getCellData, getNote: getNoteProp, getTextFormatRuns, getDataValidation, getEffectiveFormat, getFormattedValue: getFormattedValueProp, getTooltipContent, errorResolutionComponent, getEffectiveValue: getEffectiveValueProp, getSparklineGroup, getUserEnteredExtendedValue, getEffectiveExtendedValue, getSheetRowCount, getSheetColumnCount, getCellPopoverContent, onScroll, onViewPortChange, windowConditionalFormats = false, engineConditionalFormatResults = false, getConditionalFormatRuleStats, onResize, onAutoResize, onHideColumn, onHideRow, onShowColumn, onShowRow, onGroupRows, onUngroupRows, onCollapseRowGroup, onExpandRowGroup, onGroupColumns, onUngroupColumns, onCollapseColumnGroup, onExpandColumnGroup, onSetOutlineDepth, onDeleteRow, onDeleteColumn, onInsertRow, onInsertColumn, onChangeAutoExpandTables, onChangeAutoCalculatedColumns, onInsertCellsShiftDown, onInsertCellsShiftRight, onDeleteCellsShiftLeft, onDeleteCellsShiftUp, onClearContents, onMoveColumns, onMoveRows, onSelectNextSheet, onSelectPreviousSheet, onCreateNewSheet, onKeyDown, onChangeFormatting, onRepeatFormatting, onClearFormatting, onRequestEditProtectedRange, onRequestUnlockAllowEditRange, onMoveChart, onResizeChart, onDeleteChart, onCutChart, onCopyChart, onMoveEmbed, onResizeEmbed, onDeleteEmbed, onRequestEditEmbed, onMoveSlicer, onResizeSlicer, onDeleteSlicer, onDeleteObjects, onRequestEditSlicer, onFillRange, onFlashFill, onFlashFillSuggest, onAcceptFlashFill, disableFillRightShortcut, keymap, enableAutoComplete = true, onCalculateNow, onRequestGoTo, onMoveSelection, onInsertCutCells, onInsertCopiedCells, onInsertTime, onInsertDate, onInsertDateTime, onInsertAutoSum, onUndo, onRedo, batchHistory, onPaste, onReapplyPaste, onCopy, onCut, onSortColumn, onSortTable, onFilterTable, onFilterPivot, onResizeTable, onUndoTableAutoExpansion, onUndoCalculatedColumn, onOverwriteCalculatedColumn, onRequestEditTable, onRequestEditPivotTable, onRequestDeletePivotTable, onRequestCreatePivotChart, onRemoveTable, onCreateTable, onRequestCreateTable, onInsertTableColumn, onDeleteTableColumn, onInsertTableRow, onDeleteTableRow, onUpdateTable, onRequestResizeTable, onRequestInsertSlicer, onCreateBasicFilter, onRequestDefineNamedRange, onRequestFormatCells, onRequestConditionalFormat, onRequestDataValidation, onRequestInsertComment, onRequestInsertLink, onFreezeColumn, onFreezeRow, onUpdateNote, onProtectRange, onUnProtectRange, onSortRange, onRequestSearch, onRequestReplace, onRequestResize, getRowHeaderText = getDefaultRowHeader, getColumnHeaderText: getColumnHeaderTextProp, getAdditionalCellSpacing, tokenizer: defaultTokenizer = defaultFormulaTokenizer, onChangeScale, onRemoveLink, onSelectLink, onSplitTextToColumns, onRemoveDuplicates, onGoalSeek, onSubtotal, onAdvancedFilter, onRequestExpand, cellExpandPredicate, StructuredResult = DefaultStructuredResult, getMentions, getStructuredProperties: getStructuredPropertiesProp, getFunctionParameterSuggestions, shouldFetchFunctionParameters, MentionTagComponent, MentionDropdownItemComponent, showSelectionResizeHandles = true, enableMagicFill, enableQuickEdit = true, MagicFillComponent, MagicFillContent, QuickEdit, PasteMenu, SuggestionAction, HiddenRowMarkers, HiddenColumnMarkers, enableResizerOverflow, className, defaultFontSizePoint = DEFAULT_FONT_SIZE_PT, defaultCellFormat, readonly, isComparing = false, getCellDiff, enableDataBoundaryNavigation, footerHeight, footerComponent, arrowComponents,
|
|
160
161
|
// Host-driven filter props. `hostHiddenRowRanges`
|
|
161
162
|
// supplies compact [start, end] hidden-row tuples; `getFilterValues` supplies a
|
|
162
163
|
// column's distinct values. Both let a million-row filter render without scanning
|
|
@@ -1061,12 +1062,33 @@ function CanvasGridComponent(props, forwardedRef) {
|
|
|
1061
1062
|
const activeIgnoredErrorsKey = JSON.stringify(activeIgnoredErrors ?? null);
|
|
1062
1063
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1063
1064
|
const stableIgnoredErrors = useMemo(() => activeIgnoredErrors, [activeIgnoredErrorsKey]);
|
|
1065
|
+
// "Formulas which omit cells in a region" counts the numbers typed as values beside a range.
|
|
1066
|
+
const isNumberValueAt = useCallback((targetSheetId, rowIndex, columnIndex) => {
|
|
1067
|
+
const uev = getUserEnteredValue(targetSheetId, rowIndex, columnIndex);
|
|
1068
|
+
if (!uev || uev.fv != null || uev.formulaValue != null)
|
|
1069
|
+
return false;
|
|
1070
|
+
const value = getEffectiveValue(targetSheetId, rowIndex, columnIndex);
|
|
1071
|
+
return typeof (value?.nv ?? value?.numberValue) === "number";
|
|
1072
|
+
}, [getUserEnteredValue, getEffectiveValue]);
|
|
1073
|
+
// Keyed on the list's content: a host passing an inline array must not repaint every cell.
|
|
1074
|
+
const errorRulesKey = errorCheckingRules?.join(",");
|
|
1075
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1076
|
+
const enabledErrorRules = useMemo(() => errorCheckingRules, [errorRulesKey]);
|
|
1077
|
+
const formulaRangeOn = !enabledErrorRules || enabledErrorRules.includes("formulaRange");
|
|
1064
1078
|
const getErrorCheck = useCallback((targetSheetId, rowIndex, columnIndex) => {
|
|
1065
1079
|
const kind = getErrorCheckKind({
|
|
1066
1080
|
userEnteredValue: getUserEnteredValue(targetSheetId, rowIndex, columnIndex),
|
|
1067
1081
|
effectiveValue: getEffectiveValue(targetSheetId, rowIndex, columnIndex),
|
|
1068
1082
|
errorValue: getErrorValue(targetSheetId, rowIndex, columnIndex),
|
|
1083
|
+
cell: { rowIndex, columnIndex },
|
|
1084
|
+
isNumberAt: formulaRangeOn
|
|
1085
|
+
? (row, column) => isNumberValueAt(targetSheetId, row, column)
|
|
1086
|
+
: undefined,
|
|
1069
1087
|
});
|
|
1088
|
+
// The person's Error Checking rules: a rule that is off flags nothing.
|
|
1089
|
+
if (kind && enabledErrorRules && !enabledErrorRules.includes(kind)) {
|
|
1090
|
+
return undefined;
|
|
1091
|
+
}
|
|
1070
1092
|
if (kind &&
|
|
1071
1093
|
isErrorIgnored(targetSheetId === sheetId
|
|
1072
1094
|
? stableIgnoredErrors
|
|
@@ -1078,6 +1100,9 @@ function CanvasGridComponent(props, forwardedRef) {
|
|
|
1078
1100
|
getUserEnteredValue,
|
|
1079
1101
|
getEffectiveValue,
|
|
1080
1102
|
getErrorValue,
|
|
1103
|
+
isNumberValueAt,
|
|
1104
|
+
formulaRangeOn,
|
|
1105
|
+
enabledErrorRules,
|
|
1081
1106
|
getIgnoredErrorsStable,
|
|
1082
1107
|
stableIgnoredErrors,
|
|
1083
1108
|
sheetId,
|
|
@@ -1183,14 +1208,22 @@ function CanvasGridComponent(props, forwardedRef) {
|
|
|
1183
1208
|
if (stringValue) {
|
|
1184
1209
|
return stringValue;
|
|
1185
1210
|
}
|
|
1186
|
-
// Check for date value
|
|
1187
1211
|
const numberFormatType = getCellFormat(sheetId, rowIndex, columnIndex)
|
|
1188
1212
|
?.numberFormat?.type;
|
|
1213
|
+
const numberValue = getExtendedValueNumber(userEnteredValue);
|
|
1214
|
+
// A date, time or percentage edits as Excel shows it in the formula bar: the
|
|
1215
|
+
// whole date in the short date (`1/2/2026`, never the display's `2-Jan`), the
|
|
1216
|
+
// time in the long time, the percentage with its `%`.
|
|
1217
|
+
if (!isNil(numberValue)) {
|
|
1218
|
+
const editValue = excelEditValueOfNumber(numberValue, numberFormatType, locale);
|
|
1219
|
+
if (editValue !== undefined) {
|
|
1220
|
+
return editValue;
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1189
1223
|
if (numberFormatType === "DATE" || numberFormatType === "DATE_TIME") {
|
|
1190
1224
|
return getFormattedValue(sheetId, rowIndex, columnIndex);
|
|
1191
1225
|
}
|
|
1192
1226
|
// If the cell is of type number, fallback to number
|
|
1193
|
-
const numberValue = getExtendedValueNumber(userEnteredValue);
|
|
1194
1227
|
if (!isNil(numberValue)) {
|
|
1195
1228
|
return String(numberValue);
|
|
1196
1229
|
}
|
|
@@ -1203,6 +1236,7 @@ function CanvasGridComponent(props, forwardedRef) {
|
|
|
1203
1236
|
getFormattedValue,
|
|
1204
1237
|
getCellFormat,
|
|
1205
1238
|
protectFormulas,
|
|
1239
|
+
locale,
|
|
1206
1240
|
]);
|
|
1207
1241
|
// Add a stable reference to get userEnteredString value
|
|
1208
1242
|
const getUserEnteredStringValueStable = useCallbackRef(getUserEnteredStringValue);
|
|
@@ -2787,7 +2821,12 @@ function CanvasGridComponent(props, forwardedRef) {
|
|
|
2787
2821
|
*/
|
|
2788
2822
|
const openMoveOverwriteConfirm = useOpenMoveOverwriteConfirm();
|
|
2789
2823
|
const isMoveOverwriteConfirmMounted = useIsMoveOverwriteConfirmMounted();
|
|
2790
|
-
const confirmMoveOverwrite = useMemo(() =>
|
|
2824
|
+
const confirmMoveOverwrite = useMemo(() => !alertBeforeOverwritingCells
|
|
2825
|
+
? // "Alert before overwriting cells" off: a drop replaces the data without asking.
|
|
2826
|
+
() => true
|
|
2827
|
+
: isMoveOverwriteConfirmMounted
|
|
2828
|
+
? openMoveOverwriteConfirm
|
|
2829
|
+
: undefined, [alertBeforeOverwritingCells, isMoveOverwriteConfirmMounted, openMoveOverwriteConfirm]);
|
|
2791
2830
|
/**
|
|
2792
2831
|
* Fill handle dragged BACK inside the selection (Excel): the dragged-over cells lose their
|
|
2793
2832
|
* contents — formats stay unless Ctrl/Cmd was held — through the same `onDelete` path as the
|
|
@@ -3136,6 +3175,7 @@ function CanvasGridComponent(props, forwardedRef) {
|
|
|
3136
3175
|
getEffectiveFormat,
|
|
3137
3176
|
onChangeFormatting,
|
|
3138
3177
|
autoCorrect,
|
|
3178
|
+
autoPercentEntry,
|
|
3139
3179
|
});
|
|
3140
3180
|
/**
|
|
3141
3181
|
* User cancels editing the cell
|
|
@@ -3598,6 +3638,14 @@ function CanvasGridComponent(props, forwardedRef) {
|
|
|
3598
3638
|
maxRow: getDataRowCount?.(sheetId) ?? Number.MAX_SAFE_INTEGER,
|
|
3599
3639
|
maxColumn: getDataColumnCount?.(sheetId) ?? Number.MAX_SAFE_INTEGER,
|
|
3600
3640
|
getIgnoredErrors,
|
|
3641
|
+
activeCell: {
|
|
3642
|
+
rowIndex: activeCell.rowIndex,
|
|
3643
|
+
columnIndex: activeCell.columnIndex,
|
|
3644
|
+
},
|
|
3645
|
+
isNumberAt: (rowIndex, columnIndex) => isNumberValueAt(sheetId, rowIndex, columnIndex),
|
|
3646
|
+
onChange: (targetSheetId, cell, value) => {
|
|
3647
|
+
onChange?.(targetSheetId, cell, value, undefined, getFormulaValue(targetSheetId, cell.rowIndex, cell.columnIndex));
|
|
3648
|
+
},
|
|
3601
3649
|
onChangeBatch,
|
|
3602
3650
|
batchHistory,
|
|
3603
3651
|
onUpdateSheet,
|
|
@@ -4422,6 +4470,7 @@ function CanvasGridComponent(props, forwardedRef) {
|
|
|
4422
4470
|
* 3. When the grid is readonly — a fill is a write
|
|
4423
4471
|
*/
|
|
4424
4472
|
const showFillHandle = !readonly &&
|
|
4473
|
+
enableCellDragAndDrop &&
|
|
4425
4474
|
!isSelectionInProgress &&
|
|
4426
4475
|
!isEditInProgress &&
|
|
4427
4476
|
!isResizingTable &&
|
|
@@ -4448,6 +4497,7 @@ function CanvasGridComponent(props, forwardedRef) {
|
|
|
4448
4497
|
scale,
|
|
4449
4498
|
isFillShrink: fillShrink !== undefined,
|
|
4450
4499
|
onSelectionMouseDown: onSelectionElementMouseDown,
|
|
4500
|
+
enableCellDragAndDrop,
|
|
4451
4501
|
onMouseDownResizeHandle: onMouseDownResizeHandle,
|
|
4452
4502
|
onMouseDownChartSourceResizeHandle,
|
|
4453
4503
|
onMouseDownMoveSelection: onMouseDownMoveSelection,
|
|
@@ -4974,7 +5024,11 @@ function CanvasGridComponent(props, forwardedRef) {
|
|
|
4974
5024
|
* in formula mode. A readonly grid has nothing to move, so the
|
|
4975
5025
|
* gesture does not start at all (no move cursor, no selection jump).
|
|
4976
5026
|
*/
|
|
4977
|
-
const enableSelectionDrag =
|
|
5027
|
+
const enableSelectionDrag = enableCellDragAndDrop &&
|
|
5028
|
+
!readonly &&
|
|
5029
|
+
!isSelectionInProgress &&
|
|
5030
|
+
!isEditInProgress &&
|
|
5031
|
+
!formulaMode;
|
|
4978
5032
|
// A chartsheet IS its chart: no grid, headers, editor or cell menus — only the chart and its
|
|
4979
5033
|
// context menu (Excel).
|
|
4980
5034
|
if (sheetType === "chartsheet") {
|
|
@@ -8,6 +8,7 @@ import type { ElementType } from "react";
|
|
|
8
8
|
import type React from "react";
|
|
9
9
|
import type { CalculatedColumnFill } from "../../api/calculated-column-fill";
|
|
10
10
|
import type { CfRangeStats } from "../../api/cf-overlays";
|
|
11
|
+
import type { ErrorCheckKind } from "../../api/error-checking";
|
|
11
12
|
import type { TableAutoExpansion } from "../../api/table-auto-expansion";
|
|
12
13
|
import type { ContextMenuWrapperProps } from "../../hooks/use-context-menu";
|
|
13
14
|
import type { PasteSpecialOptions, PasteSpecialRequest } from "../../hooks/use-copy-paste-cut";
|
|
@@ -423,6 +424,35 @@ export type CanvasGridProps<T extends CellData = CellData<any, any>> = {
|
|
|
423
424
|
* this sheet; the value itself is untouched.
|
|
424
425
|
*/
|
|
425
426
|
showZeros?: Maybe<boolean>;
|
|
427
|
+
/**
|
|
428
|
+
* Excel's "Enable fill handle and cell drag-and-drop" (Preferences ▸ Edit). `false` hides the
|
|
429
|
+
* fill handle and makes the selection border undraggable (no drag move / copy / insert).
|
|
430
|
+
* Default `true`.
|
|
431
|
+
*/
|
|
432
|
+
enableCellDragAndDrop?: boolean;
|
|
433
|
+
/**
|
|
434
|
+
* Excel's "Alert before overwriting cells" (Preferences ▸ Edit). `false` lets a drag-and-drop
|
|
435
|
+
* move or copy replace non-empty cells without the "There's already data here" prompt.
|
|
436
|
+
* Default `true`.
|
|
437
|
+
*/
|
|
438
|
+
alertBeforeOverwritingCells?: boolean;
|
|
439
|
+
/**
|
|
440
|
+
* Excel's "Enable automatic percent entry" (Preferences ▸ Edit): a plain number typed into a
|
|
441
|
+
* Percentage-formatted cell is read as a percent (`5` → 5%, stored 0.05); a number typed with
|
|
442
|
+
* its own `%`, or below 1 (`0.5`), is kept as it is. Default `false` (the number is stored as
|
|
443
|
+
* typed, so `5` shows 500%).
|
|
444
|
+
*/
|
|
445
|
+
autoPercentEntry?: boolean;
|
|
446
|
+
/**
|
|
447
|
+
* Excel's Error Checking rules (Preferences ▸ Error Checking): the error-check kinds the grid
|
|
448
|
+
* flags with the green triangle — `evalError` ("Cells containing formulas that result in an
|
|
449
|
+
* error"), `numberStoredAsText`, `formulaRange` ("Formulas which omit cells in a region").
|
|
450
|
+
* A kind left out is not flagged and its cells offer no smart tag. Default: all of them.
|
|
451
|
+
* `[]` turns background error checking off.
|
|
452
|
+
* A person setting, like Excel's: nothing is written to the workbook (Ignore Error on one cell
|
|
453
|
+
* still records that cell in the sheet's `ignoredErrors`, as Excel saves it).
|
|
454
|
+
*/
|
|
455
|
+
errorCheckingRules?: ReadonlyArray<ErrorCheckKind>;
|
|
426
456
|
/**
|
|
427
457
|
* The sheet displays right-to-left (`<sheetView rightToLeft="1">`, Page
|
|
428
458
|
* Layout ▸ Sheet Right-to-Left): column A on the right, row headings on the
|