@rowsncolumns/spreadsheet 10.19.1 → 10.19.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.
@@ -27,20 +27,36 @@ export declare const seedRangeForSeriesSpec: (target: GridRange, spec: FillSerie
27
27
  /**
28
28
  * How many series values fit before `stop` is passed, starting from the seed's
29
29
  * last value. `undefined` when the spec has no usable stop (no stop, zero step,
30
- * a step that walks away from the stop, …) — the caller then fills the target
31
- * as selected.
30
+ * a trend, AutoFill, a Growth that shrinks toward zero and never reaches a stop
31
+ * on the other side, …): a seed-only selection is then not filled at all. A Date
32
+ * series counts on the calendar: a 1904 workbook's serials (`date1904`) are
33
+ * moved onto the 1900 system first, as the engine does with the seed and stop.
32
34
  */
33
- export declare const seriesCountToStop: (last: number, spec: FillSeriesSpec) => number | undefined;
35
+ export declare const seriesCountToStop: (last: number, spec: FillSeriesSpec, options?: {
36
+ date1904?: boolean;
37
+ }) => number | undefined;
34
38
  export type FillRangeForSeriesSpecArgs = {
35
39
  /** The range the user selected (seed + cells to fill). */
36
40
  target: GridRange;
37
41
  /** From {@link seedRangeForSeriesSpec}. */
38
42
  seed: GridRange;
39
43
  spec: FillSeriesSpec;
40
- /** Numeric value of a seed cell (`undefined` when not a number). */
44
+ /**
45
+ * The value a seed cell starts the series from, or `undefined` when the engine would not run its
46
+ * line as this series (not a number, a formula, or, for a Date series, not a date). A seed-only
47
+ * selection with any such line fills nothing: the engine would fill that line with its regular
48
+ * generator over the whole range, ignoring the stop.
49
+ */
41
50
  getSeedValue(rowIndex: number, columnIndex: number): number | undefined;
51
+ /**
52
+ * Bounds of the fill: the last row index is `rowCount - 1` and the last column index
53
+ * `columnCount - 1`. A host whose rows / columns start at index 1 passes its sheet's last index
54
+ * + 1 (CanvasGrid passes the sheet maximum, 1,048,576 rows × 16,384 columns, not its drawn extent).
55
+ */
42
56
  rowCount: number;
43
57
  columnCount: number;
58
+ /** The workbook counts dates in the 1904 system (a Date series' stop is one of its serials). */
59
+ date1904?: boolean;
44
60
  };
45
61
  /**
46
62
  * The range a Series-dialog fill covers (seed + cells to fill). A selection
@@ -48,9 +64,15 @@ export type FillRangeForSeriesSpecArgs = {
48
64
  * is nothing beyond the seed and no stop): the engines apply the `stop` value
49
65
  * per fill line — every column (Series in Columns) / row (Rows) ends at the
50
66
  * last value within its own stop and the remaining selected cells stay
51
- * untouched, exactly as Excel leaves them. Only a seed-only selection is
52
- * extended along the axis by the number of values that stay within the stop —
53
- * Excel fills down/right from a single line until the value would pass it.
67
+ * untouched, exactly as Excel leaves them. A seed-only selection (one cell, or
68
+ * one line across the axis) is extended along the axis to the LONGEST of its
69
+ * lines' series — Excel runs every line from its own seed until its next value
70
+ * would pass the stop (A1:C1 = 8, 1, 5, Columns, Stop 10 fills A to 10, B to 10
71
+ * and C to 10: rows 2–3, 2–10 and 2–6) — and the engine's stop ends each
72
+ * shorter line inside that range. When any line is one the engine will not run
73
+ * as the series (`getSeedValue` answers `undefined`: text, empty, a formula, a
74
+ * plain number under Date), nothing is filled: the engine would copy or clear
75
+ * that line down the whole range.
54
76
  */
55
- export declare const fillRangeForSeriesSpec: ({ target, seed, spec, getSeedValue, rowCount, columnCount, }: FillRangeForSeriesSpecArgs) => GridRange | undefined;
77
+ export declare const fillRangeForSeriesSpec: ({ target, seed, spec, getSeedValue, rowCount, columnCount, date1904, }: FillRangeForSeriesSpecArgs) => GridRange | undefined;
56
78
  //# sourceMappingURL=fill-series.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fill-series.d.ts","sourceRoot":"","sources":["../../../api/fill-series.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAGpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAkC/C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,oBAAoB,GAC/B,MAAM,MAAM,EACZ,UAAS;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO,KACpD,MAAM,GAAG,SA8CX,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GACjC,QAAQ,SAAS,EACjB,MAAM,cAAc,KACnB,SAGyD,CAAC;AAE7D;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,MAAM,EACZ,MAAM,cAAc,KACnB,MAAM,GAAG,SAuBX,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,0DAA0D;IAC1D,MAAM,EAAE,SAAS,CAAC;IAClB,2CAA2C;IAC3C,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,cAAc,CAAC;IACrB,oEAAoE;IACpE,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACxE,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,GAAI,8DAOpC,0BAA0B,KAAG,SAAS,GAAG,SAwB3C,CAAC"}
1
+ {"version":3,"file":"fill-series.d.ts","sourceRoot":"","sources":["../../../api/fill-series.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAGpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAkC/C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,oBAAoB,GAC/B,MAAM,MAAM,EACZ,UAAS;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO,KACpD,MAAM,GAAG,SA8CX,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GACjC,QAAQ,SAAS,EACjB,MAAM,cAAc,KACnB,SAGyD,CAAC;AAyF7D;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,MAAM,EACZ,MAAM,cAAc,EACpB,UAAS;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO,KACnC,MAAM,GAAG,SA0CX,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,0DAA0D;IAC1D,MAAM,EAAE,SAAS,CAAC;IAClB,2CAA2C;IAC3C,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,cAAc,CAAC;IACrB;;;;;OAKG;IACH,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACxE;;;;OAIG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,gGAAgG;IAChG,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,sBAAsB,GAAI,wEAQpC,0BAA0B,KAAG,SAAS,GAAG,SAgC3C,CAAC"}
@@ -106,16 +106,99 @@ var seedRangeForSeriesSpec = function (target, spec) {
106
106
  ? tslib_1.__assign(tslib_1.__assign({}, target), { endRowIndex: target.startRowIndex }) : tslib_1.__assign(tslib_1.__assign({}, target), { endColumnIndex: target.startColumnIndex });
107
107
  };
108
108
  exports.seedRangeForSeriesSpec = seedRangeForSeriesSpec;
109
+ /**
110
+ * Days from 1970-01-01 to serial 0 of the 1900 system (1899-12-30). The calendar below is the
111
+ * engine's (`civil_from_days` / `days_from_civil`, proleptic Gregorian), in integer arithmetic so a
112
+ * Stop far outside `Date`'s range still counts.
113
+ */
114
+ var SERIAL_EPOCH_CIVIL_DAYS = -25569;
115
+ var serialToYmd = function (serial) {
116
+ var z = serial + SERIAL_EPOCH_CIVIL_DAYS + 719468;
117
+ var era = Math.floor(z / 146097);
118
+ var doe = z - era * 146097;
119
+ var yoe = Math.floor((doe - Math.floor(doe / 1460) + Math.floor(doe / 36524) - Math.floor(doe / 146096)) / 365);
120
+ var doy = doe - (365 * yoe + Math.floor(yoe / 4) - Math.floor(yoe / 100));
121
+ var mp = Math.floor((5 * doy + 2) / 153);
122
+ var day = doy - Math.floor((153 * mp + 2) / 5) + 1;
123
+ var month = mp < 10 ? mp + 3 : mp - 9;
124
+ return [yoe + era * 400 + (month <= 2 ? 1 : 0), month, day];
125
+ };
126
+ var ymdToSerial = function (year, month, day) {
127
+ var y = month <= 2 ? year - 1 : year;
128
+ var era = Math.floor(y / 400);
129
+ var yoe = y - era * 400;
130
+ var doy = Math.floor((153 * (month > 2 ? month - 3 : month + 9) + 2) / 5) + day - 1;
131
+ var doe = yoe * 365 + Math.floor(yoe / 4) - Math.floor(yoe / 100) + doy;
132
+ return era * 146097 + doe - 719468 - SERIAL_EPOCH_CIVIL_DAYS;
133
+ };
134
+ var daysInMonth = function (year, month) {
135
+ return month === 2
136
+ ? (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0
137
+ ? 29
138
+ : 28
139
+ : [4, 6, 9, 11].includes(month)
140
+ ? 30
141
+ : 31;
142
+ };
143
+ /** `serial` + `months` months, the day of month clamped to the target month's length (Jan 31 + 1 → Feb 28). */
144
+ var addMonthsClamped = function (serial, months) {
145
+ var _a = tslib_1.__read(serialToYmd(serial), 3), year = _a[0], month = _a[1], day = _a[2];
146
+ var total = year * 12 + (month - 1) + months;
147
+ var targetYear = Math.floor(total / 12);
148
+ var targetMonth = total - targetYear * 12 + 1;
149
+ return ymdToSerial(targetYear, targetMonth, Math.min(day, daysInMonth(targetYear, targetMonth)));
150
+ };
151
+ /** Weekdays (Mon–Fri) among serials up to `day`, from a fixed origin: serial 0 is a Saturday. */
152
+ var weekdaysThrough = function (day) {
153
+ var weeks = Math.floor(day / 7);
154
+ return weeks * 5 + Math.max(0, day - weeks * 7 - 1);
155
+ };
156
+ /**
157
+ * How many values a Date series in `unit`s of `step` (a whole, non-zero number) takes from the day
158
+ * `lastDay` before passing `stopDay` — the engine's calendar: each weekday step skips Saturdays and
159
+ * Sundays (from a weekend seed the first value is the Monday), and the k-th month / year value is the
160
+ * seed's day of month moved k steps and clamped to that month (1/31 → 2/28 → 3/31).
161
+ */
162
+ var dateCountToStop = function (lastDay, stopDay, step, unit) {
163
+ var ascending = step > 0;
164
+ if (ascending ? stopDay <= lastDay : stopDay >= lastDay)
165
+ return 0;
166
+ var size = Math.abs(step);
167
+ if (unit === "day")
168
+ return Math.floor(Math.abs(stopDay - lastDay) / size);
169
+ if (unit === "weekday") {
170
+ // The k-th value is the (k × step)-th weekday after the seed.
171
+ var weekdays = ascending
172
+ ? weekdaysThrough(stopDay) - weekdaysThrough(lastDay)
173
+ : weekdaysThrough(lastDay - 1) - weekdaysThrough(stopDay - 1);
174
+ return Math.floor(weekdays / size);
175
+ }
176
+ var monthsPerStep = unit === "year" ? 12 * step : step;
177
+ var _a = tslib_1.__read(serialToYmd(lastDay), 2), lastYear = _a[0], lastMonth = _a[1];
178
+ var _b = tslib_1.__read(serialToYmd(stopDay), 2), stopYear = _b[0], stopMonth = _b[1];
179
+ var months = Math.abs(stopYear * 12 + stopMonth - (lastYear * 12 + lastMonth));
180
+ var count = Math.floor(months / Math.abs(monthsPerStep));
181
+ // The value landing in the Stop's own month may still pass it by its day of month.
182
+ var value = addMonthsClamped(lastDay, monthsPerStep * count);
183
+ return count > 0 && (ascending ? value > stopDay : value < stopDay) ? count - 1 : count;
184
+ };
109
185
  /**
110
186
  * How many series values fit before `stop` is passed, starting from the seed's
111
187
  * last value. `undefined` when the spec has no usable stop (no stop, zero step,
112
- * a step that walks away from the stop, …) — the caller then fills the target
113
- * as selected.
188
+ * a trend, AutoFill, a Growth that shrinks toward zero and never reaches a stop
189
+ * on the other side, …): a seed-only selection is then not filled at all. A Date
190
+ * series counts on the calendar: a 1904 workbook's serials (`date1904`) are
191
+ * moved onto the 1900 system first, as the engine does with the seed and stop.
114
192
  */
115
- var seriesCountToStop = function (last, spec) {
193
+ var seriesCountToStop = function (last, spec, options) {
116
194
  var _a, _b;
195
+ if (options === void 0) { options = {}; }
117
196
  var stop = spec.stop;
118
- if (stop === undefined || !Number.isFinite(stop))
197
+ if (stop === undefined || !Number.isFinite(stop) || !Number.isFinite(last)) {
198
+ return undefined;
199
+ }
200
+ // Trend ignores Step and Stop (Excel greys both out).
201
+ if (spec.trend)
119
202
  return undefined;
120
203
  var step = (_a = spec.step) !== null && _a !== void 0 ? _a : 1;
121
204
  if (spec.type === "linear") {
@@ -127,16 +210,29 @@ var seriesCountToStop = function (last, spec) {
127
210
  if (spec.type === "growth") {
128
211
  if (last === 0 || step <= 0 || step === 1)
129
212
  return undefined;
130
- if (Math.sign(last) !== Math.sign(stop))
131
- return 0;
213
+ if (Math.sign(last) !== Math.sign(stop)) {
214
+ // Growing away from zero the first value is already past a stop on the other side; shrinking
215
+ // toward zero the series never reaches it, so it has no count (the engine would run on).
216
+ return step > 1 ? 0 : undefined;
217
+ }
132
218
  var n = Math.floor(Math.log(Math.abs(stop) / Math.abs(last)) / Math.log(step) + 1e-9);
133
219
  return n >= 0 ? n : 0;
134
220
  }
135
- if (spec.type === "date" && ((_b = spec.dateUnit) !== null && _b !== void 0 ? _b : "day") === "day") {
136
- if (step === 0)
221
+ if (spec.type === "date") {
222
+ // The engine steps a date series by whole units; Excel fills nothing for Step 0.
223
+ var wholeStep = Math.trunc(step);
224
+ if (wholeStep === 0)
137
225
  return undefined;
138
- var n = Math.floor((stop - last) / step + 1e-9);
139
- return n >= 0 ? n : 0;
226
+ var shift = options.date1904 ? DATE_1904_OFFSET : 0;
227
+ var lastValue = last + shift;
228
+ var stopValue = stop + shift;
229
+ var lastDay = Math.floor(lastValue);
230
+ // Every value carries the seed's time of day; a value passes the Stop when it is beyond it.
231
+ var time = lastValue - lastDay;
232
+ var stopDay = wholeStep > 0
233
+ ? Math.floor(stopValue - time + 1e-9)
234
+ : Math.ceil(stopValue - time - 1e-9);
235
+ return dateCountToStop(lastDay, stopDay, wholeStep, (_b = spec.dateUnit) !== null && _b !== void 0 ? _b : "day");
140
236
  }
141
237
  return undefined;
142
238
  };
@@ -147,26 +243,42 @@ exports.seriesCountToStop = seriesCountToStop;
147
243
  * is nothing beyond the seed and no stop): the engines apply the `stop` value
148
244
  * per fill line — every column (Series in Columns) / row (Rows) ends at the
149
245
  * last value within its own stop and the remaining selected cells stay
150
- * untouched, exactly as Excel leaves them. Only a seed-only selection is
151
- * extended along the axis by the number of values that stay within the stop —
152
- * Excel fills down/right from a single line until the value would pass it.
246
+ * untouched, exactly as Excel leaves them. A seed-only selection (one cell, or
247
+ * one line across the axis) is extended along the axis to the LONGEST of its
248
+ * lines' series — Excel runs every line from its own seed until its next value
249
+ * would pass the stop (A1:C1 = 8, 1, 5, Columns, Stop 10 fills A to 10, B to 10
250
+ * and C to 10: rows 2–3, 2–10 and 2–6) — and the engine's stop ends each
251
+ * shorter line inside that range. When any line is one the engine will not run
252
+ * as the series (`getSeedValue` answers `undefined`: text, empty, a formula, a
253
+ * plain number under Date), nothing is filled: the engine would copy or clear
254
+ * that line down the whole range.
153
255
  */
154
256
  var fillRangeForSeriesSpec = function (_a) {
155
- var _b;
156
- var target = _a.target, seed = _a.seed, spec = _a.spec, getSeedValue = _a.getSeedValue, rowCount = _a.rowCount, columnCount = _a.columnCount;
257
+ var target = _a.target, seed = _a.seed, spec = _a.spec, getSeedValue = _a.getSeedValue, rowCount = _a.rowCount, columnCount = _a.columnCount, date1904 = _a.date1904;
157
258
  var down = spec.in === "columns";
158
- // Excel reads the stop against the first seed line's last value.
159
- var last = down
160
- ? getSeedValue(seed.endRowIndex, seed.startColumnIndex)
161
- : getSeedValue(seed.startRowIndex, seed.endColumnIndex);
162
259
  var selectedBeyondSeed = down
163
260
  ? target.endRowIndex - seed.endRowIndex
164
261
  : target.endColumnIndex - seed.endColumnIndex;
165
- var extent = selectedBeyondSeed > 0
166
- ? selectedBeyondSeed
167
- : last === undefined
168
- ? 0
169
- : ((_b = (0, exports.seriesCountToStop)(last, spec)) !== null && _b !== void 0 ? _b : 0);
262
+ var extent = selectedBeyondSeed;
263
+ if (extent <= 0) {
264
+ // Every line of the seed continues from its own last value.
265
+ var _b = tslib_1.__read(down
266
+ ? [seed.startColumnIndex, seed.endColumnIndex]
267
+ : [seed.startRowIndex, seed.endRowIndex], 2), first = _b[0], end = _b[1];
268
+ for (var line = first; line <= end; line++) {
269
+ var last = down
270
+ ? getSeedValue(seed.endRowIndex, line)
271
+ : getSeedValue(line, seed.endColumnIndex);
272
+ if (last === undefined)
273
+ return undefined;
274
+ // No count to the stop (no stop, a step that never reaches it, …): the engine would run
275
+ // that line over the whole range, so nothing is filled.
276
+ var count = (0, exports.seriesCountToStop)(last, spec, { date1904: date1904 });
277
+ if (count === undefined)
278
+ return undefined;
279
+ extent = Math.max(extent, count);
280
+ }
281
+ }
170
282
  if (extent <= 0)
171
283
  return undefined;
172
284
  if (down) {
@@ -1,7 +1,12 @@
1
- /** One axis of a freeze as it is sent: how many lines, and the first of them (absent = line 1). */
1
+ /**
2
+ * One axis of a freeze as it is sent: how many lines, and the first of them (absent = line 1).
3
+ * `seq`: the count the axis was noted at (set by {@link useNoteFrozenAreaSent}; absent = the
4
+ * value's `seq`). The grid consumes each axis once, by this count.
5
+ */
2
6
  export type FrozenAxisSent = {
3
7
  count?: number;
4
8
  start?: number | null;
9
+ seq?: number;
5
10
  };
6
11
  /**
7
12
  * The last Freeze Panes / unfreeze this window itself sent, counted, with the area it asked for.
@@ -34,7 +39,13 @@ export declare const useFrozenAreaSentValue: () => {
34
39
  rows?: FrozenAxisSent;
35
40
  columns?: FrozenAxisSent;
36
41
  } | null;
37
- /** Say "the next frozen-area change on this sheet is my own freeze" (see {@link frozenAreaSentAtom}). */
42
+ /**
43
+ * Say "the next frozen-area change on this sheet is my own freeze" (see {@link frozenAreaSentAtom}).
44
+ * Noting one axis keeps the other axis's mark on the same sheet, with the count it was noted at,
45
+ * so a host that changes both axes in one act (`onFreezeRow` then `onFreezeColumn`) marks both;
46
+ * an axis the grid has already consumed keeps its old count and is not taken again
47
+ * (rowsncolumns/spreadsheet#1769). A mark on another sheet is dropped.
48
+ */
38
49
  export declare const useNoteFrozenAreaSent: () => (sheetId: number, area: {
39
50
  rows?: FrozenAxisSent;
40
51
  columns?: FrozenAxisSent;
@@ -1 +1 @@
1
- {"version":3,"file":"frozen-area-sent.atom.d.ts","sourceRoot":"","sources":["../../../atoms/frozen-area-sent.atom.ts"],"names":[],"mappings":"AAGA,mGAAmG;AACnG,MAAM,MAAM,cAAc,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAEvE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB;SACxB,MAAM;aACF,MAAM;WACR,cAAc;cACX,cAAc;;;aAHnB,MAAM;iBACF,MAAM;eACR,cAAc;kBACX,cAAc;;CACX,CAAC;AAEhB,eAAO,MAAM,sBAAsB;SAN5B,MAAM;aACF,MAAM;WACR,cAAc;cACX,cAAc;QAGkD,CAAC;AAE7E,yGAAyG;AACzG,eAAO,MAAM,qBAAqB,kBAGpB,MAAM,QAAQ;IAAE,IAAI,CAAC,EAAE,cAAc,CAAC;IAAC,OAAO,CAAC,EAAE,cAAc,CAAA;CAAE,SAI9E,CAAC"}
1
+ {"version":3,"file":"frozen-area-sent.atom.d.ts","sourceRoot":"","sources":["../../../atoms/frozen-area-sent.atom.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAErF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB;SACxB,MAAM;aACF,MAAM;WACR,cAAc;cACX,cAAc;;;aAHnB,MAAM;iBACF,MAAM;eACR,cAAc;kBACX,cAAc;;CACX,CAAC;AAEhB,eAAO,MAAM,sBAAsB;SAN5B,MAAM;aACF,MAAM;WACR,cAAc;cACX,cAAc;QAGkD,CAAC;AAE7E;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,kBAGpB,MAAM,QAAQ;IAAE,IAAI,CAAC,EAAE,cAAc,CAAC;IAAC,OAAO,CAAC,EAAE,cAAc,CAAA;CAAE,SAqB9E,CAAC"}
@@ -19,11 +19,30 @@ var react_1 = require("react");
19
19
  exports.frozenAreaSentAtom = (0, jotai_1.atom)(null);
20
20
  var useFrozenAreaSentValue = function () { return (0, jotai_1.useAtomValue)(exports.frozenAreaSentAtom); };
21
21
  exports.useFrozenAreaSentValue = useFrozenAreaSentValue;
22
- /** Say "the next frozen-area change on this sheet is my own freeze" (see {@link frozenAreaSentAtom}). */
22
+ /**
23
+ * Say "the next frozen-area change on this sheet is my own freeze" (see {@link frozenAreaSentAtom}).
24
+ * Noting one axis keeps the other axis's mark on the same sheet, with the count it was noted at,
25
+ * so a host that changes both axes in one act (`onFreezeRow` then `onFreezeColumn`) marks both;
26
+ * an axis the grid has already consumed keeps its old count and is not taken again
27
+ * (rowsncolumns/spreadsheet#1769). A mark on another sheet is dropped.
28
+ */
23
29
  var useNoteFrozenAreaSent = function () {
24
30
  var set = (0, jotai_1.useSetAtom)(exports.frozenAreaSentAtom);
25
31
  return (0, react_1.useCallback)(function (sheetId, area) {
26
- return set(function (previous) { var _a; return (tslib_1.__assign({ seq: ((_a = previous === null || previous === void 0 ? void 0 : previous.seq) !== null && _a !== void 0 ? _a : 0) + 1, sheetId: sheetId }, area)); });
32
+ return set(function (previous) {
33
+ var _a;
34
+ var seq = ((_a = previous === null || previous === void 0 ? void 0 : previous.seq) !== null && _a !== void 0 ? _a : 0) + 1;
35
+ var kept = previous && previous.sheetId === sheetId ? previous : undefined;
36
+ var axis = function (noted, held) {
37
+ var _a;
38
+ return noted
39
+ ? tslib_1.__assign(tslib_1.__assign({}, noted), { seq: seq }) : held
40
+ ? tslib_1.__assign(tslib_1.__assign({}, held), { seq: (_a = held.seq) !== null && _a !== void 0 ? _a : kept === null || kept === void 0 ? void 0 : kept.seq }) : undefined;
41
+ };
42
+ var rows = axis(area.rows, kept === null || kept === void 0 ? void 0 : kept.rows);
43
+ var columns = axis(area.columns, kept === null || kept === void 0 ? void 0 : kept.columns);
44
+ return tslib_1.__assign(tslib_1.__assign({ seq: seq, sheetId: sheetId }, (rows ? { rows: rows } : {})), (columns ? { columns: columns } : {}));
45
+ });
27
46
  }, [set]);
28
47
  };
29
48
  exports.useNoteFrozenAreaSent = useNoteFrozenAreaSent;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/canvas-grid/index.tsx"],"names":[],"mappings":"AAqEA,OAAO,KASN,MAAM,OAAO,CAAC;AAuRf,OAAO,KAAK,EAGV,QAAQ,EAcT,MAAM,aAAa,CAAC;AA0DrB,OAAO,KAAK,EACV,wBAAwB,EACxB,iBAAiB,EACjB,eAAe,EAEhB,MAAM,WAAW,CAAC;AAkuQnB,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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/canvas-grid/index.tsx"],"names":[],"mappings":"AAqEA,OAAO,KASN,MAAM,OAAO,CAAC;AAuRf,OAAO,KAAK,EAGV,QAAQ,EAcT,MAAM,aAAa,CAAC;AA0DrB,OAAO,KAAK,EACV,wBAAwB,EACxB,iBAAiB,EACjB,eAAe,EAEhB,MAAM,WAAW,CAAC;AAixQnB,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"}
@@ -170,6 +170,11 @@ function isDetachedEditor(editor) {
170
170
  }
171
171
  /** An empty object list, stable across renders ("For objects, show: none"). */
172
172
  var EMPTY_OBJECTS = [];
173
+ /** One cell (the Series dialog treats it as Excel does: Rows by default, and it stays selected). */
174
+ var isSingleCellRange = function (range) {
175
+ return range.startRowIndex === range.endRowIndex &&
176
+ range.startColumnIndex === range.endColumnIndex;
177
+ };
173
178
  /** "For objects, show: placeholders": an object's frame drawn with nothing in it. */
174
179
  var getObjectPlaceholder = function () { return (react_1.default.createElement("div", { "data-testid": "object-placeholder", "aria-hidden": "true", className: "w-full h-full bg-rnc-muted/40 border border-dashed border-rnc-border" })); };
175
180
  function CanvasGridComponent(props, forwardedRef) {
@@ -1034,7 +1039,14 @@ function CanvasGridComponent(props, forwardedRef) {
1034
1039
  // A freeze / unfreeze this window sent outside the grid's own menu (a host ribbon through the
1035
1040
  // engine hook, or a host calling `useNoteFrozenAreaSent`), counted, with the area it asked for.
1036
1041
  var frozenAreaSent = (0, frozen_area_sent_atom_1.useFrozenAreaSentValue)();
1037
- var seenFrozenAreaRef = (0, react_1.useRef)(frozenAreaSent === null || frozenAreaSent === void 0 ? void 0 : frozenAreaSent.seq);
1042
+ // Each axis's mark is consumed once, by the count it was noted at (a mark noted before the
1043
+ // other axis's in the same act keeps its own count, rowsncolumns/spreadsheet#1769).
1044
+ var axisSeq = function (axis) {
1045
+ var _a;
1046
+ var mark = frozenAreaSent === null || frozenAreaSent === void 0 ? void 0 : frozenAreaSent[axis];
1047
+ return mark ? ((_a = mark.seq) !== null && _a !== void 0 ? _a : frozenAreaSent === null || frozenAreaSent === void 0 ? void 0 : frozenAreaSent.seq) : undefined;
1048
+ };
1049
+ var seenFrozenAreaRef = (0, react_1.useRef)({ rows: axisSeq("rows"), columns: axisSeq("columns") });
1038
1050
  var freezeRowsUpTo = (0, react_1.useCallback)(function (freezeSheetId, rowIndex) {
1039
1051
  var _a, _b;
1040
1052
  if (!onFreezeRow)
@@ -1131,15 +1143,11 @@ function CanvasGridComponent(props, forwardedRef) {
1131
1143
  var historyKind = undoRedoSent && undoRedoSent.seq !== seenUndoRedoRef.current ? undoRedoSent.kind : undefined;
1132
1144
  // A freeze this window sent through the engine hook (a ribbon) that the grid has not seen: what it
1133
1145
  // asked for, per axis, in the grid's terms. One that asks for the area already there leaves no mark.
1134
- var sentFreeze = frozenAreaSent &&
1135
- frozenAreaSent.seq !== seenFrozenAreaRef.current &&
1136
- frozenAreaSent.sheetId === sheetId
1137
- ? frozenAreaSent
1138
- : undefined;
1146
+ var sentFreeze = frozenAreaSent && frozenAreaSent.sheetId === sheetId ? frozenAreaSent : undefined;
1139
1147
  var freezeSentOn = function (axis) {
1140
1148
  var _a, _b, _c;
1141
1149
  var asked = sentFreeze === null || sentFreeze === void 0 ? void 0 : sentFreeze[axis];
1142
- if (!asked)
1150
+ if (!asked || axisSeq(axis) === seenFrozenAreaRef.current[axis])
1143
1151
  return undefined;
1144
1152
  var was = axis === "rows"
1145
1153
  ? { lines: previous.rows, count: previous.rowCount }
@@ -1211,7 +1219,7 @@ function CanvasGridComponent(props, forwardedRef) {
1211
1219
  (0, use_isomorphic_layout_effect_1.useIsomorphicLayoutEffect)(function () {
1212
1220
  pendingFreezeRef.current = {};
1213
1221
  seenUndoRedoRef.current = undoRedoSent === null || undoRedoSent === void 0 ? void 0 : undoRedoSent.seq;
1214
- seenFrozenAreaRef.current = frozenAreaSent === null || frozenAreaSent === void 0 ? void 0 : frozenAreaSent.seq;
1222
+ seenFrozenAreaRef.current = { rows: axisSeq("rows"), columns: axisSeq("columns") };
1215
1223
  });
1216
1224
  /**
1217
1225
  * Get cell coordinates from x and y position
@@ -3487,18 +3495,35 @@ function CanvasGridComponent(props, forwardedRef) {
3487
3495
  * in Columns) / first column (Rows) is the seed line; `stop` may shrink or
3488
3496
  * extend the target along the axis from the seed's last value.
3489
3497
  */
3490
- var applyFillSeriesSpec = (0, react_1.useCallback)(function (fillSheetId, cell, target, spec) {
3498
+ var applyFillSeriesSpec = (0, react_1.useCallback)(function (fillSheetId, cell, target, spec, date1904) {
3491
3499
  var seed = (0, fill_series_1.seedRangeForSeriesSpec)(target.range, spec);
3492
3500
  var fillRange = (0, fill_series_1.fillRangeForSeriesSpec)({
3493
3501
  target: target.range,
3494
3502
  seed: seed,
3495
3503
  spec: spec,
3504
+ // A line the engine runs as this series (rnc-store `fill_val_of` / `fill_seed_vals` /
3505
+ // `series_spec_values`): a seed that is not a formula (a formula seed is copied down
3506
+ // instead) with a number, and for a Date series a date-, date-time- or time-formatted
3507
+ // one. The cell readers answer an ExtendedValue (`{ nv }`), never a bare number.
3496
3508
  getSeedValue: function (r, c) {
3497
- var value = getEffectiveValue(fillSheetId, r, c);
3498
- return typeof value === "number" ? value : undefined;
3509
+ var _a, _b, _c, _d;
3510
+ if (getFormulaValue(fillSheetId, r, c) !== undefined)
3511
+ return undefined;
3512
+ var value = (0, helpers_1.getExtendedValueNumber)(getEffectiveValue(fillSheetId, r, c));
3513
+ if (value === undefined || spec.type !== "date")
3514
+ return value;
3515
+ var format = getCellFormat(fillSheetId, r, c);
3516
+ var userFormat = (_a = getCellData === null || getCellData === void 0 ? void 0 : getCellData(fillSheetId, r, c)) === null || _a === void 0 ? void 0 : _a.userEnteredFormat;
3517
+ var type = (_c = (format && "numberFormat" in format ? (_b = format.numberFormat) === null || _b === void 0 ? void 0 : _b.type : undefined)) !== null && _c !== void 0 ? _c : (userFormat && "numberFormat" in userFormat
3518
+ ? (_d = userFormat.numberFormat) === null || _d === void 0 ? void 0 : _d.type
3519
+ : undefined);
3520
+ return type === "DATE" || type === "DATE_TIME" || type === "TIME" ? value : undefined;
3499
3521
  },
3500
- rowCount: rowCount,
3501
- columnCount: columnCount,
3522
+ // Bounded by the sheet, not by the drawn extent (a host may draw 1,000 rows that grow with
3523
+ // the data): rows and columns start at index 1, so the last index is the maximum itself.
3524
+ rowCount: config_1.MAX_ROW_COUNT + 1,
3525
+ columnCount: config_1.MAX_COLUMN_COUNT + 1,
3526
+ date1904: date1904,
3502
3527
  });
3503
3528
  if (!fillRange)
3504
3529
  return;
@@ -3518,25 +3543,41 @@ function CanvasGridComponent(props, forwardedRef) {
3518
3543
  : "FillDays"
3519
3544
  : undefined;
3520
3545
  onFill === null || onFill === void 0 ? void 0 : onFill(fillSheetId, cell, { range: fillRange }, [tslib_1.__assign(tslib_1.__assign({}, target), { range: seed })], undefined, fillType, { series: spec });
3521
- onChangeSelections === null || onChangeSelections === void 0 ? void 0 : onChangeSelections(fillSheetId, [tslib_1.__assign(tslib_1.__assign({}, target), { range: fillRange })]);
3522
- }, [getEffectiveValue, onFill, onChangeSelections, rowCount, columnCount]);
3546
+ // Excel leaves a seed-only selection (one cell, or one line across the axis) selected after
3547
+ // it runs the series from it to the Stop.
3548
+ var seedOnly = seed.endRowIndex === target.range.endRowIndex &&
3549
+ seed.endColumnIndex === target.range.endColumnIndex;
3550
+ if (!seedOnly) {
3551
+ onChangeSelections === null || onChangeSelections === void 0 ? void 0 : onChangeSelections(fillSheetId, [tslib_1.__assign(tslib_1.__assign({}, target), { range: fillRange })]);
3552
+ }
3553
+ }, [
3554
+ getEffectiveValue,
3555
+ getFormulaValue,
3556
+ getCellFormat,
3557
+ getCellData,
3558
+ onFill,
3559
+ onChangeSelections,
3560
+ ]);
3523
3561
  /** Open the Series dialog for a range (the current selection by default). */
3524
3562
  var openFillSeriesDialogFor = (0, react_1.useCallback)(function (target, initialIn) {
3525
3563
  var _a, _b;
3526
3564
  var selection = (_a = target !== null && target !== void 0 ? target : selections[selections.length - 1]) !== null && _a !== void 0 ? _a : {
3527
3565
  range: (0, grid_1.cellToArea)(activeCell),
3528
3566
  };
3567
+ // Asked once, as the dialog opens (the rnc engine reads it through a formula preview); the
3568
+ // typed Stop and the count to it both use it.
3569
+ var date1904 = (_b = getDate1904 === null || getDate1904 === void 0 ? void 0 : getDate1904()) !== null && _b !== void 0 ? _b : false;
3529
3570
  openFillSeriesDialog({
3530
3571
  sheetId: sheetId,
3531
3572
  activeCell: activeCell,
3532
3573
  selection: selection,
3533
- initialIn: initialIn,
3574
+ // Excel opens on Rows for a single cell; a range keeps the dialog's default.
3575
+ initialIn: initialIn !== null && initialIn !== void 0 ? initialIn : (isSingleCellRange(selection.range) ? "rows" : undefined),
3534
3576
  onApply: function (spec) {
3535
- return applyFillSeriesSpec(sheetId, activeCell, selection, spec);
3577
+ return applyFillSeriesSpec(sheetId, activeCell, selection, spec, date1904);
3536
3578
  },
3537
3579
  locale: locale,
3538
- // Asked once, as the dialog opens (the rnc engine reads it through a formula preview).
3539
- date1904: (_b = getDate1904 === null || getDate1904 === void 0 ? void 0 : getDate1904()) !== null && _b !== void 0 ? _b : false,
3580
+ date1904: date1904,
3540
3581
  parseStop: parseCellEntryNumber,
3541
3582
  });
3542
3583
  }, [
@@ -20,9 +20,9 @@ export type FillSeriesDialogProps = {
20
20
  /**
21
21
  * Excel's Series dialog (Home > Fill > Series…). Series in Rows/Columns, Type
22
22
  * Linear/Growth/Date/AutoFill, Date unit (Type = Date only), Trend
23
- * (Linear/Growth only — disables Step/Stop), Step value (default 1, may be
24
- * negative or fractional) and Stop value. UI-only: the opener turns the spec
25
- * into a fill.
23
+ * (Linear/Growth only — disables Step/Stop and the Date / AutoFill types),
24
+ * Step value (default 1, may be negative or fractional) and Stop value (both
25
+ * disabled for AutoFill). UI-only: the opener turns the spec into a fill.
26
26
  */
27
27
  export declare const FillSeriesDialog: React.MemoExoticComponent<({ open, onOpenChange, initialIn, onApply, locale, date1904, parseStop, }: FillSeriesDialogProps) => React.JSX.Element>;
28
28
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/fill-series-dialog/index.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAiD,MAAM,OAAO,CAAC;AAItE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,MAAM,MAAM,qBAAqB,GAAG;IAClC,2BAA2B;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAClC,oEAAoE;IACpE,SAAS,CAAC,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC;IACjC,OAAO,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CAAC;IACpC,oFAAoF;IACpF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oFAAoF;IACpF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CAC9C,CAAC;AA0BF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,uGASxB,qBAAqB,uBAoNzB,CAAC;AAIF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB;;;CAgBhC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/fill-series-dialog/index.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAiD,MAAM,OAAO,CAAC;AAItE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,MAAM,MAAM,qBAAqB,GAAG;IAClC,2BAA2B;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAClC,oEAAoE;IACpE,SAAS,CAAC,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC;IACjC,OAAO,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CAAC;IACpC,oFAAoF;IACpF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oFAAoF;IACpF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CAC9C,CAAC;AA0BF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,uGASxB,qBAAqB,uBA+NzB,CAAC;AAIF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB;;;CAgBhC,CAAC"}
@@ -28,9 +28,9 @@ var parseNumber = function (text) {
28
28
  /**
29
29
  * Excel's Series dialog (Home > Fill > Series…). Series in Rows/Columns, Type
30
30
  * Linear/Growth/Date/AutoFill, Date unit (Type = Date only), Trend
31
- * (Linear/Growth only — disables Step/Stop), Step value (default 1, may be
32
- * negative or fractional) and Stop value. UI-only: the opener turns the spec
33
- * into a fill.
31
+ * (Linear/Growth only — disables Step/Stop and the Date / AutoFill types),
32
+ * Step value (default 1, may be negative or fractional) and Stop value (both
33
+ * disabled for AutoFill). UI-only: the opener turns the spec into a fill.
34
34
  */
35
35
  exports.FillSeriesDialog = (0, react_1.memo)(function (_a) {
36
36
  var open = _a.open, onOpenChange = _a.onOpenChange, initialIn = _a.initialIn, onApply = _a.onApply, locale = _a.locale, date1904 = _a.date1904, parseStop = _a.parseStop;
@@ -54,7 +54,9 @@ exports.FillSeriesDialog = (0, react_1.memo)(function (_a) {
54
54
  }
55
55
  }, [open, initialIn]);
56
56
  var trendAllowed = type === "linear" || type === "growth";
57
- var stepStopDisabled = trendAllowed && trend;
57
+ var trendOn = trendAllowed && trend;
58
+ // As in Excel: AutoFill has no Step or Stop, and Trend fits its own step and ignores the Stop.
59
+ var stepStopDisabled = type === "autofill" || trendOn;
58
60
  var apply = (0, react_1.useCallback)(function () {
59
61
  var stepValue = parseNumber(step);
60
62
  if (!stepStopDisabled && step.trim() && stepValue === undefined) {
@@ -72,7 +74,7 @@ exports.FillSeriesDialog = (0, react_1.memo)(function (_a) {
72
74
  setError("Stop value must be a number.");
73
75
  return;
74
76
  }
75
- var spec = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({ in: axis, type: type }, (type === "date" ? { dateUnit: dateUnit } : {})), (trendAllowed && trend ? { trend: true } : {})), (!stepStopDisabled && stepValue !== undefined
77
+ var spec = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({ in: axis, type: type }, (type === "date" ? { dateUnit: dateUnit } : {})), (trendOn ? { trend: true } : {})), (!stepStopDisabled && stepValue !== undefined
76
78
  ? { step: stepValue }
77
79
  : {})), (!stepStopDisabled && stopValue !== undefined
78
80
  ? { stop: stopValue }
@@ -83,8 +85,7 @@ exports.FillSeriesDialog = (0, react_1.memo)(function (_a) {
83
85
  axis,
84
86
  type,
85
87
  dateUnit,
86
- trend,
87
- trendAllowed,
88
+ trendOn,
88
89
  step,
89
90
  stop,
90
91
  stepStopDisabled,
@@ -114,8 +115,12 @@ exports.FillSeriesDialog = (0, react_1.memo)(function (_a) {
114
115
  SERIES_TYPES.map(function (_a) {
115
116
  var value = _a.value, label = _a.label;
116
117
  return (react_1.default.createElement("label", { key: value, className: "flex items-center gap-2 text-xs cursor-pointer" },
117
- react_1.default.createElement("input", { type: "radio", name: "fillSeriesType", value: value, checked: type === value, onChange: function () { return setType(value); } }),
118
- label));
118
+ react_1.default.createElement("input", { type: "radio", name: "fillSeriesType", value: value, checked: type === value, onChange: function () { return setType(value); },
119
+ // A trend is Linear or Growth only.
120
+ disabled: trendOn && (value === "date" || value === "autofill") }),
121
+ react_1.default.createElement("span", { className: trendOn && (value === "date" || value === "autofill")
122
+ ? "opacity-50"
123
+ : "" }, label)));
119
124
  })),
120
125
  react_1.default.createElement("fieldset", { className: "flex flex-col gap-1 border-0 p-0 m-0", disabled: type !== "date" },
121
126
  react_1.default.createElement("legend", { className: "text-xs font-medium pb-1" }, "Date unit"),
@@ -126,7 +131,7 @@ exports.FillSeriesDialog = (0, react_1.memo)(function (_a) {
126
131
  react_1.default.createElement("span", { className: type !== "date" ? "opacity-50" : "" }, label)));
127
132
  }))),
128
133
  react_1.default.createElement("label", { className: "flex items-center gap-2 text-xs cursor-pointer" },
129
- react_1.default.createElement("input", { type: "checkbox", name: "fillSeriesTrend", checked: trendAllowed && trend, disabled: !trendAllowed, onChange: function (e) { return setTrend(e.target.checked); } }),
134
+ react_1.default.createElement("input", { type: "checkbox", name: "fillSeriesTrend", checked: trendOn, disabled: !trendAllowed, onChange: function (e) { return setTrend(e.target.checked); } }),
130
135
  react_1.default.createElement("span", { className: !trendAllowed ? "opacity-50" : "" }, "Trend")),
131
136
  react_1.default.createElement("div", { className: "grid grid-cols-2 gap-3" },
132
137
  react_1.default.createElement("label", { className: "flex flex-col gap-1 text-xs" },
@@ -27,20 +27,36 @@ export declare const seedRangeForSeriesSpec: (target: GridRange, spec: FillSerie
27
27
  /**
28
28
  * How many series values fit before `stop` is passed, starting from the seed's
29
29
  * last value. `undefined` when the spec has no usable stop (no stop, zero step,
30
- * a step that walks away from the stop, …) — the caller then fills the target
31
- * as selected.
30
+ * a trend, AutoFill, a Growth that shrinks toward zero and never reaches a stop
31
+ * on the other side, …): a seed-only selection is then not filled at all. A Date
32
+ * series counts on the calendar: a 1904 workbook's serials (`date1904`) are
33
+ * moved onto the 1900 system first, as the engine does with the seed and stop.
32
34
  */
33
- export declare const seriesCountToStop: (last: number, spec: FillSeriesSpec) => number | undefined;
35
+ export declare const seriesCountToStop: (last: number, spec: FillSeriesSpec, options?: {
36
+ date1904?: boolean;
37
+ }) => number | undefined;
34
38
  export type FillRangeForSeriesSpecArgs = {
35
39
  /** The range the user selected (seed + cells to fill). */
36
40
  target: GridRange;
37
41
  /** From {@link seedRangeForSeriesSpec}. */
38
42
  seed: GridRange;
39
43
  spec: FillSeriesSpec;
40
- /** Numeric value of a seed cell (`undefined` when not a number). */
44
+ /**
45
+ * The value a seed cell starts the series from, or `undefined` when the engine would not run its
46
+ * line as this series (not a number, a formula, or, for a Date series, not a date). A seed-only
47
+ * selection with any such line fills nothing: the engine would fill that line with its regular
48
+ * generator over the whole range, ignoring the stop.
49
+ */
41
50
  getSeedValue(rowIndex: number, columnIndex: number): number | undefined;
51
+ /**
52
+ * Bounds of the fill: the last row index is `rowCount - 1` and the last column index
53
+ * `columnCount - 1`. A host whose rows / columns start at index 1 passes its sheet's last index
54
+ * + 1 (CanvasGrid passes the sheet maximum, 1,048,576 rows × 16,384 columns, not its drawn extent).
55
+ */
42
56
  rowCount: number;
43
57
  columnCount: number;
58
+ /** The workbook counts dates in the 1904 system (a Date series' stop is one of its serials). */
59
+ date1904?: boolean;
44
60
  };
45
61
  /**
46
62
  * The range a Series-dialog fill covers (seed + cells to fill). A selection
@@ -48,9 +64,15 @@ export type FillRangeForSeriesSpecArgs = {
48
64
  * is nothing beyond the seed and no stop): the engines apply the `stop` value
49
65
  * per fill line — every column (Series in Columns) / row (Rows) ends at the
50
66
  * last value within its own stop and the remaining selected cells stay
51
- * untouched, exactly as Excel leaves them. Only a seed-only selection is
52
- * extended along the axis by the number of values that stay within the stop —
53
- * Excel fills down/right from a single line until the value would pass it.
67
+ * untouched, exactly as Excel leaves them. A seed-only selection (one cell, or
68
+ * one line across the axis) is extended along the axis to the LONGEST of its
69
+ * lines' series — Excel runs every line from its own seed until its next value
70
+ * would pass the stop (A1:C1 = 8, 1, 5, Columns, Stop 10 fills A to 10, B to 10
71
+ * and C to 10: rows 2–3, 2–10 and 2–6) — and the engine's stop ends each
72
+ * shorter line inside that range. When any line is one the engine will not run
73
+ * as the series (`getSeedValue` answers `undefined`: text, empty, a formula, a
74
+ * plain number under Date), nothing is filled: the engine would copy or clear
75
+ * that line down the whole range.
54
76
  */
55
- export declare const fillRangeForSeriesSpec: ({ target, seed, spec, getSeedValue, rowCount, columnCount, }: FillRangeForSeriesSpecArgs) => GridRange | undefined;
77
+ export declare const fillRangeForSeriesSpec: ({ target, seed, spec, getSeedValue, rowCount, columnCount, date1904, }: FillRangeForSeriesSpecArgs) => GridRange | undefined;
56
78
  //# sourceMappingURL=fill-series.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fill-series.d.ts","sourceRoot":"","sources":["../../../api/fill-series.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAGpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAkC/C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,oBAAoB,GAC/B,MAAM,MAAM,EACZ,UAAS;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO,KACpD,MAAM,GAAG,SA8CX,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GACjC,QAAQ,SAAS,EACjB,MAAM,cAAc,KACnB,SAGyD,CAAC;AAE7D;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,MAAM,EACZ,MAAM,cAAc,KACnB,MAAM,GAAG,SAuBX,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,0DAA0D;IAC1D,MAAM,EAAE,SAAS,CAAC;IAClB,2CAA2C;IAC3C,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,cAAc,CAAC;IACrB,oEAAoE;IACpE,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACxE,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,GAAI,8DAOpC,0BAA0B,KAAG,SAAS,GAAG,SAwB3C,CAAC"}
1
+ {"version":3,"file":"fill-series.d.ts","sourceRoot":"","sources":["../../../api/fill-series.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAGpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAkC/C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,oBAAoB,GAC/B,MAAM,MAAM,EACZ,UAAS;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO,KACpD,MAAM,GAAG,SA8CX,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GACjC,QAAQ,SAAS,EACjB,MAAM,cAAc,KACnB,SAGyD,CAAC;AAyF7D;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,MAAM,EACZ,MAAM,cAAc,EACpB,UAAS;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO,KACnC,MAAM,GAAG,SA0CX,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,0DAA0D;IAC1D,MAAM,EAAE,SAAS,CAAC;IAClB,2CAA2C;IAC3C,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,cAAc,CAAC;IACrB;;;;;OAKG;IACH,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACxE;;;;OAIG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,gGAAgG;IAChG,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,sBAAsB,GAAI,wEAQpC,0BAA0B,KAAG,SAAS,GAAG,SAgC3C,CAAC"}
@@ -95,15 +95,95 @@ export const parseSeriesStopValue = (text, options = {}) => {
95
95
  export const seedRangeForSeriesSpec = (target, spec) => spec.in === "columns"
96
96
  ? { ...target, endRowIndex: target.startRowIndex }
97
97
  : { ...target, endColumnIndex: target.startColumnIndex };
98
+ /**
99
+ * Days from 1970-01-01 to serial 0 of the 1900 system (1899-12-30). The calendar below is the
100
+ * engine's (`civil_from_days` / `days_from_civil`, proleptic Gregorian), in integer arithmetic so a
101
+ * Stop far outside `Date`'s range still counts.
102
+ */
103
+ const SERIAL_EPOCH_CIVIL_DAYS = -25_569;
104
+ const serialToYmd = (serial) => {
105
+ const z = serial + SERIAL_EPOCH_CIVIL_DAYS + 719_468;
106
+ const era = Math.floor(z / 146_097);
107
+ const doe = z - era * 146_097;
108
+ const yoe = Math.floor((doe - Math.floor(doe / 1460) + Math.floor(doe / 36_524) - Math.floor(doe / 146_096)) / 365);
109
+ const doy = doe - (365 * yoe + Math.floor(yoe / 4) - Math.floor(yoe / 100));
110
+ const mp = Math.floor((5 * doy + 2) / 153);
111
+ const day = doy - Math.floor((153 * mp + 2) / 5) + 1;
112
+ const month = mp < 10 ? mp + 3 : mp - 9;
113
+ return [yoe + era * 400 + (month <= 2 ? 1 : 0), month, day];
114
+ };
115
+ const ymdToSerial = (year, month, day) => {
116
+ const y = month <= 2 ? year - 1 : year;
117
+ const era = Math.floor(y / 400);
118
+ const yoe = y - era * 400;
119
+ const doy = Math.floor((153 * (month > 2 ? month - 3 : month + 9) + 2) / 5) + day - 1;
120
+ const doe = yoe * 365 + Math.floor(yoe / 4) - Math.floor(yoe / 100) + doy;
121
+ return era * 146_097 + doe - 719_468 - SERIAL_EPOCH_CIVIL_DAYS;
122
+ };
123
+ const daysInMonth = (year, month) => month === 2
124
+ ? (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0
125
+ ? 29
126
+ : 28
127
+ : [4, 6, 9, 11].includes(month)
128
+ ? 30
129
+ : 31;
130
+ /** `serial` + `months` months, the day of month clamped to the target month's length (Jan 31 + 1 → Feb 28). */
131
+ const addMonthsClamped = (serial, months) => {
132
+ const [year, month, day] = serialToYmd(serial);
133
+ const total = year * 12 + (month - 1) + months;
134
+ const targetYear = Math.floor(total / 12);
135
+ const targetMonth = total - targetYear * 12 + 1;
136
+ return ymdToSerial(targetYear, targetMonth, Math.min(day, daysInMonth(targetYear, targetMonth)));
137
+ };
138
+ /** Weekdays (Mon–Fri) among serials up to `day`, from a fixed origin: serial 0 is a Saturday. */
139
+ const weekdaysThrough = (day) => {
140
+ const weeks = Math.floor(day / 7);
141
+ return weeks * 5 + Math.max(0, day - weeks * 7 - 1);
142
+ };
143
+ /**
144
+ * How many values a Date series in `unit`s of `step` (a whole, non-zero number) takes from the day
145
+ * `lastDay` before passing `stopDay` — the engine's calendar: each weekday step skips Saturdays and
146
+ * Sundays (from a weekend seed the first value is the Monday), and the k-th month / year value is the
147
+ * seed's day of month moved k steps and clamped to that month (1/31 → 2/28 → 3/31).
148
+ */
149
+ const dateCountToStop = (lastDay, stopDay, step, unit) => {
150
+ const ascending = step > 0;
151
+ if (ascending ? stopDay <= lastDay : stopDay >= lastDay)
152
+ return 0;
153
+ const size = Math.abs(step);
154
+ if (unit === "day")
155
+ return Math.floor(Math.abs(stopDay - lastDay) / size);
156
+ if (unit === "weekday") {
157
+ // The k-th value is the (k × step)-th weekday after the seed.
158
+ const weekdays = ascending
159
+ ? weekdaysThrough(stopDay) - weekdaysThrough(lastDay)
160
+ : weekdaysThrough(lastDay - 1) - weekdaysThrough(stopDay - 1);
161
+ return Math.floor(weekdays / size);
162
+ }
163
+ const monthsPerStep = unit === "year" ? 12 * step : step;
164
+ const [lastYear, lastMonth] = serialToYmd(lastDay);
165
+ const [stopYear, stopMonth] = serialToYmd(stopDay);
166
+ const months = Math.abs(stopYear * 12 + stopMonth - (lastYear * 12 + lastMonth));
167
+ const count = Math.floor(months / Math.abs(monthsPerStep));
168
+ // The value landing in the Stop's own month may still pass it by its day of month.
169
+ const value = addMonthsClamped(lastDay, monthsPerStep * count);
170
+ return count > 0 && (ascending ? value > stopDay : value < stopDay) ? count - 1 : count;
171
+ };
98
172
  /**
99
173
  * How many series values fit before `stop` is passed, starting from the seed's
100
174
  * last value. `undefined` when the spec has no usable stop (no stop, zero step,
101
- * a step that walks away from the stop, …) — the caller then fills the target
102
- * as selected.
175
+ * a trend, AutoFill, a Growth that shrinks toward zero and never reaches a stop
176
+ * on the other side, …): a seed-only selection is then not filled at all. A Date
177
+ * series counts on the calendar: a 1904 workbook's serials (`date1904`) are
178
+ * moved onto the 1900 system first, as the engine does with the seed and stop.
103
179
  */
104
- export const seriesCountToStop = (last, spec) => {
180
+ export const seriesCountToStop = (last, spec, options = {}) => {
105
181
  const { stop } = spec;
106
- if (stop === undefined || !Number.isFinite(stop))
182
+ if (stop === undefined || !Number.isFinite(stop) || !Number.isFinite(last)) {
183
+ return undefined;
184
+ }
185
+ // Trend ignores Step and Stop (Excel greys both out).
186
+ if (spec.trend)
107
187
  return undefined;
108
188
  const step = spec.step ?? 1;
109
189
  if (spec.type === "linear") {
@@ -115,16 +195,29 @@ export const seriesCountToStop = (last, spec) => {
115
195
  if (spec.type === "growth") {
116
196
  if (last === 0 || step <= 0 || step === 1)
117
197
  return undefined;
118
- if (Math.sign(last) !== Math.sign(stop))
119
- return 0;
198
+ if (Math.sign(last) !== Math.sign(stop)) {
199
+ // Growing away from zero the first value is already past a stop on the other side; shrinking
200
+ // toward zero the series never reaches it, so it has no count (the engine would run on).
201
+ return step > 1 ? 0 : undefined;
202
+ }
120
203
  const n = Math.floor(Math.log(Math.abs(stop) / Math.abs(last)) / Math.log(step) + 1e-9);
121
204
  return n >= 0 ? n : 0;
122
205
  }
123
- if (spec.type === "date" && (spec.dateUnit ?? "day") === "day") {
124
- if (step === 0)
206
+ if (spec.type === "date") {
207
+ // The engine steps a date series by whole units; Excel fills nothing for Step 0.
208
+ const wholeStep = Math.trunc(step);
209
+ if (wholeStep === 0)
125
210
  return undefined;
126
- const n = Math.floor((stop - last) / step + 1e-9);
127
- return n >= 0 ? n : 0;
211
+ const shift = options.date1904 ? DATE_1904_OFFSET : 0;
212
+ const lastValue = last + shift;
213
+ const stopValue = stop + shift;
214
+ const lastDay = Math.floor(lastValue);
215
+ // Every value carries the seed's time of day; a value passes the Stop when it is beyond it.
216
+ const time = lastValue - lastDay;
217
+ const stopDay = wholeStep > 0
218
+ ? Math.floor(stopValue - time + 1e-9)
219
+ : Math.ceil(stopValue - time - 1e-9);
220
+ return dateCountToStop(lastDay, stopDay, wholeStep, spec.dateUnit ?? "day");
128
221
  }
129
222
  return undefined;
130
223
  };
@@ -134,24 +227,41 @@ export const seriesCountToStop = (last, spec) => {
134
227
  * is nothing beyond the seed and no stop): the engines apply the `stop` value
135
228
  * per fill line — every column (Series in Columns) / row (Rows) ends at the
136
229
  * last value within its own stop and the remaining selected cells stay
137
- * untouched, exactly as Excel leaves them. Only a seed-only selection is
138
- * extended along the axis by the number of values that stay within the stop —
139
- * Excel fills down/right from a single line until the value would pass it.
230
+ * untouched, exactly as Excel leaves them. A seed-only selection (one cell, or
231
+ * one line across the axis) is extended along the axis to the LONGEST of its
232
+ * lines' series — Excel runs every line from its own seed until its next value
233
+ * would pass the stop (A1:C1 = 8, 1, 5, Columns, Stop 10 fills A to 10, B to 10
234
+ * and C to 10: rows 2–3, 2–10 and 2–6) — and the engine's stop ends each
235
+ * shorter line inside that range. When any line is one the engine will not run
236
+ * as the series (`getSeedValue` answers `undefined`: text, empty, a formula, a
237
+ * plain number under Date), nothing is filled: the engine would copy or clear
238
+ * that line down the whole range.
140
239
  */
141
- export const fillRangeForSeriesSpec = ({ target, seed, spec, getSeedValue, rowCount, columnCount, }) => {
240
+ export const fillRangeForSeriesSpec = ({ target, seed, spec, getSeedValue, rowCount, columnCount, date1904, }) => {
142
241
  const down = spec.in === "columns";
143
- // Excel reads the stop against the first seed line's last value.
144
- const last = down
145
- ? getSeedValue(seed.endRowIndex, seed.startColumnIndex)
146
- : getSeedValue(seed.startRowIndex, seed.endColumnIndex);
147
242
  const selectedBeyondSeed = down
148
243
  ? target.endRowIndex - seed.endRowIndex
149
244
  : target.endColumnIndex - seed.endColumnIndex;
150
- const extent = selectedBeyondSeed > 0
151
- ? selectedBeyondSeed
152
- : last === undefined
153
- ? 0
154
- : (seriesCountToStop(last, spec) ?? 0);
245
+ let extent = selectedBeyondSeed;
246
+ if (extent <= 0) {
247
+ // Every line of the seed continues from its own last value.
248
+ const [first, end] = down
249
+ ? [seed.startColumnIndex, seed.endColumnIndex]
250
+ : [seed.startRowIndex, seed.endRowIndex];
251
+ for (let line = first; line <= end; line++) {
252
+ const last = down
253
+ ? getSeedValue(seed.endRowIndex, line)
254
+ : getSeedValue(line, seed.endColumnIndex);
255
+ if (last === undefined)
256
+ return undefined;
257
+ // No count to the stop (no stop, a step that never reaches it, …): the engine would run
258
+ // that line over the whole range, so nothing is filled.
259
+ const count = seriesCountToStop(last, spec, { date1904 });
260
+ if (count === undefined)
261
+ return undefined;
262
+ extent = Math.max(extent, count);
263
+ }
264
+ }
155
265
  if (extent <= 0)
156
266
  return undefined;
157
267
  if (down) {
@@ -1,7 +1,12 @@
1
- /** One axis of a freeze as it is sent: how many lines, and the first of them (absent = line 1). */
1
+ /**
2
+ * One axis of a freeze as it is sent: how many lines, and the first of them (absent = line 1).
3
+ * `seq`: the count the axis was noted at (set by {@link useNoteFrozenAreaSent}; absent = the
4
+ * value's `seq`). The grid consumes each axis once, by this count.
5
+ */
2
6
  export type FrozenAxisSent = {
3
7
  count?: number;
4
8
  start?: number | null;
9
+ seq?: number;
5
10
  };
6
11
  /**
7
12
  * The last Freeze Panes / unfreeze this window itself sent, counted, with the area it asked for.
@@ -34,7 +39,13 @@ export declare const useFrozenAreaSentValue: () => {
34
39
  rows?: FrozenAxisSent;
35
40
  columns?: FrozenAxisSent;
36
41
  } | null;
37
- /** Say "the next frozen-area change on this sheet is my own freeze" (see {@link frozenAreaSentAtom}). */
42
+ /**
43
+ * Say "the next frozen-area change on this sheet is my own freeze" (see {@link frozenAreaSentAtom}).
44
+ * Noting one axis keeps the other axis's mark on the same sheet, with the count it was noted at,
45
+ * so a host that changes both axes in one act (`onFreezeRow` then `onFreezeColumn`) marks both;
46
+ * an axis the grid has already consumed keeps its old count and is not taken again
47
+ * (rowsncolumns/spreadsheet#1769). A mark on another sheet is dropped.
48
+ */
38
49
  export declare const useNoteFrozenAreaSent: () => (sheetId: number, area: {
39
50
  rows?: FrozenAxisSent;
40
51
  columns?: FrozenAxisSent;
@@ -1 +1 @@
1
- {"version":3,"file":"frozen-area-sent.atom.d.ts","sourceRoot":"","sources":["../../../atoms/frozen-area-sent.atom.ts"],"names":[],"mappings":"AAGA,mGAAmG;AACnG,MAAM,MAAM,cAAc,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAEvE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB;SACxB,MAAM;aACF,MAAM;WACR,cAAc;cACX,cAAc;;;aAHnB,MAAM;iBACF,MAAM;eACR,cAAc;kBACX,cAAc;;CACX,CAAC;AAEhB,eAAO,MAAM,sBAAsB;SAN5B,MAAM;aACF,MAAM;WACR,cAAc;cACX,cAAc;QAGkD,CAAC;AAE7E,yGAAyG;AACzG,eAAO,MAAM,qBAAqB,kBAGpB,MAAM,QAAQ;IAAE,IAAI,CAAC,EAAE,cAAc,CAAC;IAAC,OAAO,CAAC,EAAE,cAAc,CAAA;CAAE,SAI9E,CAAC"}
1
+ {"version":3,"file":"frozen-area-sent.atom.d.ts","sourceRoot":"","sources":["../../../atoms/frozen-area-sent.atom.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAErF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB;SACxB,MAAM;aACF,MAAM;WACR,cAAc;cACX,cAAc;;;aAHnB,MAAM;iBACF,MAAM;eACR,cAAc;kBACX,cAAc;;CACX,CAAC;AAEhB,eAAO,MAAM,sBAAsB;SAN5B,MAAM;aACF,MAAM;WACR,cAAc;cACX,cAAc;QAGkD,CAAC;AAE7E;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,kBAGpB,MAAM,QAAQ;IAAE,IAAI,CAAC,EAAE,cAAc,CAAC;IAAC,OAAO,CAAC,EAAE,cAAc,CAAA;CAAE,SAqB9E,CAAC"}
@@ -14,8 +14,30 @@ import { useCallback } from "react";
14
14
  */
15
15
  export const frozenAreaSentAtom = atom(null);
16
16
  export const useFrozenAreaSentValue = () => useAtomValue(frozenAreaSentAtom);
17
- /** Say "the next frozen-area change on this sheet is my own freeze" (see {@link frozenAreaSentAtom}). */
17
+ /**
18
+ * Say "the next frozen-area change on this sheet is my own freeze" (see {@link frozenAreaSentAtom}).
19
+ * Noting one axis keeps the other axis's mark on the same sheet, with the count it was noted at,
20
+ * so a host that changes both axes in one act (`onFreezeRow` then `onFreezeColumn`) marks both;
21
+ * an axis the grid has already consumed keeps its old count and is not taken again
22
+ * (rowsncolumns/spreadsheet#1769). A mark on another sheet is dropped.
23
+ */
18
24
  export const useNoteFrozenAreaSent = () => {
19
25
  const set = useSetAtom(frozenAreaSentAtom);
20
- return useCallback((sheetId, area) => set((previous) => ({ seq: (previous?.seq ?? 0) + 1, sheetId, ...area })), [set]);
26
+ return useCallback((sheetId, area) => set((previous) => {
27
+ const seq = (previous?.seq ?? 0) + 1;
28
+ const kept = previous && previous.sheetId === sheetId ? previous : undefined;
29
+ const axis = (noted, held) => noted
30
+ ? { ...noted, seq }
31
+ : held
32
+ ? { ...held, seq: held.seq ?? kept?.seq }
33
+ : undefined;
34
+ const rows = axis(area.rows, kept?.rows);
35
+ const columns = axis(area.columns, kept?.columns);
36
+ return {
37
+ seq,
38
+ sheetId,
39
+ ...(rows ? { rows } : {}),
40
+ ...(columns ? { columns } : {}),
41
+ };
42
+ }), [set]);
21
43
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/canvas-grid/index.tsx"],"names":[],"mappings":"AAqEA,OAAO,KASN,MAAM,OAAO,CAAC;AAuRf,OAAO,KAAK,EAGV,QAAQ,EAcT,MAAM,aAAa,CAAC;AA0DrB,OAAO,KAAK,EACV,wBAAwB,EACxB,iBAAiB,EACjB,eAAe,EAEhB,MAAM,WAAW,CAAC;AAkuQnB,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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/canvas-grid/index.tsx"],"names":[],"mappings":"AAqEA,OAAO,KASN,MAAM,OAAO,CAAC;AAuRf,OAAO,KAAK,EAGV,QAAQ,EAcT,MAAM,aAAa,CAAC;AA0DrB,OAAO,KAAK,EACV,wBAAwB,EACxB,iBAAiB,EACjB,eAAe,EAEhB,MAAM,WAAW,CAAC;AAixQnB,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"}
@@ -165,6 +165,9 @@ function isDetachedEditor(editor) {
165
165
  }
166
166
  /** An empty object list, stable across renders ("For objects, show: none"). */
167
167
  const EMPTY_OBJECTS = [];
168
+ /** One cell (the Series dialog treats it as Excel does: Rows by default, and it stays selected). */
169
+ const isSingleCellRange = (range) => range.startRowIndex === range.endRowIndex &&
170
+ range.startColumnIndex === range.endColumnIndex;
168
171
  /** "For objects, show: placeholders": an object's frame drawn with nothing in it. */
169
172
  const getObjectPlaceholder = () => (React.createElement("div", { "data-testid": "object-placeholder", "aria-hidden": "true", className: "w-full h-full bg-rnc-muted/40 border border-dashed border-rnc-border" }));
170
173
  function CanvasGridComponent(props, forwardedRef) {
@@ -900,7 +903,13 @@ function CanvasGridComponent(props, forwardedRef) {
900
903
  // A freeze / unfreeze this window sent outside the grid's own menu (a host ribbon through the
901
904
  // engine hook, or a host calling `useNoteFrozenAreaSent`), counted, with the area it asked for.
902
905
  const frozenAreaSent = useFrozenAreaSentValue();
903
- const seenFrozenAreaRef = useRef(frozenAreaSent?.seq);
906
+ // Each axis's mark is consumed once, by the count it was noted at (a mark noted before the
907
+ // other axis's in the same act keeps its own count, rowsncolumns/spreadsheet#1769).
908
+ const axisSeq = (axis) => {
909
+ const mark = frozenAreaSent?.[axis];
910
+ return mark ? (mark.seq ?? frozenAreaSent?.seq) : undefined;
911
+ };
912
+ const seenFrozenAreaRef = useRef({ rows: axisSeq("rows"), columns: axisSeq("columns") });
904
913
  const freezeRowsUpTo = useCallback((freezeSheetId, rowIndex) => {
905
914
  if (!onFreezeRow)
906
915
  return;
@@ -995,14 +1004,10 @@ function CanvasGridComponent(props, forwardedRef) {
995
1004
  const historyKind = undoRedoSent && undoRedoSent.seq !== seenUndoRedoRef.current ? undoRedoSent.kind : undefined;
996
1005
  // A freeze this window sent through the engine hook (a ribbon) that the grid has not seen: what it
997
1006
  // asked for, per axis, in the grid's terms. One that asks for the area already there leaves no mark.
998
- const sentFreeze = frozenAreaSent &&
999
- frozenAreaSent.seq !== seenFrozenAreaRef.current &&
1000
- frozenAreaSent.sheetId === sheetId
1001
- ? frozenAreaSent
1002
- : undefined;
1007
+ const sentFreeze = frozenAreaSent && frozenAreaSent.sheetId === sheetId ? frozenAreaSent : undefined;
1003
1008
  const freezeSentOn = (axis) => {
1004
1009
  const asked = sentFreeze?.[axis];
1005
- if (!asked)
1010
+ if (!asked || axisSeq(axis) === seenFrozenAreaRef.current[axis])
1006
1011
  return undefined;
1007
1012
  const was = axis === "rows"
1008
1013
  ? { lines: previous.rows, count: previous.rowCount }
@@ -1075,7 +1080,7 @@ function CanvasGridComponent(props, forwardedRef) {
1075
1080
  useIsomorphicLayoutEffect(() => {
1076
1081
  pendingFreezeRef.current = {};
1077
1082
  seenUndoRedoRef.current = undoRedoSent?.seq;
1078
- seenFrozenAreaRef.current = frozenAreaSent?.seq;
1083
+ seenFrozenAreaRef.current = { rows: axisSeq("rows"), columns: axisSeq("columns") };
1079
1084
  });
1080
1085
  /**
1081
1086
  * Get cell coordinates from x and y position
@@ -3264,18 +3269,35 @@ function CanvasGridComponent(props, forwardedRef) {
3264
3269
  * in Columns) / first column (Rows) is the seed line; `stop` may shrink or
3265
3270
  * extend the target along the axis from the seed's last value.
3266
3271
  */
3267
- const applyFillSeriesSpec = useCallback((fillSheetId, cell, target, spec) => {
3272
+ const applyFillSeriesSpec = useCallback((fillSheetId, cell, target, spec, date1904) => {
3268
3273
  const seed = seedRangeForSeriesSpec(target.range, spec);
3269
3274
  const fillRange = fillRangeForSeriesSpec({
3270
3275
  target: target.range,
3271
3276
  seed,
3272
3277
  spec,
3278
+ // A line the engine runs as this series (rnc-store `fill_val_of` / `fill_seed_vals` /
3279
+ // `series_spec_values`): a seed that is not a formula (a formula seed is copied down
3280
+ // instead) with a number, and for a Date series a date-, date-time- or time-formatted
3281
+ // one. The cell readers answer an ExtendedValue (`{ nv }`), never a bare number.
3273
3282
  getSeedValue: (r, c) => {
3274
- const value = getEffectiveValue(fillSheetId, r, c);
3275
- return typeof value === "number" ? value : undefined;
3283
+ if (getFormulaValue(fillSheetId, r, c) !== undefined)
3284
+ return undefined;
3285
+ const value = getExtendedValueNumber(getEffectiveValue(fillSheetId, r, c));
3286
+ if (value === undefined || spec.type !== "date")
3287
+ return value;
3288
+ const format = getCellFormat(fillSheetId, r, c);
3289
+ const userFormat = getCellData?.(fillSheetId, r, c)?.userEnteredFormat;
3290
+ const type = (format && "numberFormat" in format ? format.numberFormat?.type : undefined) ??
3291
+ (userFormat && "numberFormat" in userFormat
3292
+ ? userFormat.numberFormat?.type
3293
+ : undefined);
3294
+ return type === "DATE" || type === "DATE_TIME" || type === "TIME" ? value : undefined;
3276
3295
  },
3277
- rowCount,
3278
- columnCount,
3296
+ // Bounded by the sheet, not by the drawn extent (a host may draw 1,000 rows that grow with
3297
+ // the data): rows and columns start at index 1, so the last index is the maximum itself.
3298
+ rowCount: MAX_ROW_COUNT + 1,
3299
+ columnCount: MAX_COLUMN_COUNT + 1,
3300
+ date1904,
3279
3301
  });
3280
3302
  if (!fillRange)
3281
3303
  return;
@@ -3295,8 +3317,21 @@ function CanvasGridComponent(props, forwardedRef) {
3295
3317
  : "FillDays"
3296
3318
  : undefined;
3297
3319
  onFill?.(fillSheetId, cell, { range: fillRange }, [{ ...target, range: seed }], undefined, fillType, { series: spec });
3298
- onChangeSelections?.(fillSheetId, [{ ...target, range: fillRange }]);
3299
- }, [getEffectiveValue, onFill, onChangeSelections, rowCount, columnCount]);
3320
+ // Excel leaves a seed-only selection (one cell, or one line across the axis) selected after
3321
+ // it runs the series from it to the Stop.
3322
+ const seedOnly = seed.endRowIndex === target.range.endRowIndex &&
3323
+ seed.endColumnIndex === target.range.endColumnIndex;
3324
+ if (!seedOnly) {
3325
+ onChangeSelections?.(fillSheetId, [{ ...target, range: fillRange }]);
3326
+ }
3327
+ }, [
3328
+ getEffectiveValue,
3329
+ getFormulaValue,
3330
+ getCellFormat,
3331
+ getCellData,
3332
+ onFill,
3333
+ onChangeSelections,
3334
+ ]);
3300
3335
  /** Open the Series dialog for a range (the current selection by default). */
3301
3336
  const openFillSeriesDialogFor = useCallback((target, initialIn) => {
3302
3337
  const selection = target ??
@@ -3304,15 +3339,18 @@ function CanvasGridComponent(props, forwardedRef) {
3304
3339
  {
3305
3340
  range: cellToArea(activeCell),
3306
3341
  };
3342
+ // Asked once, as the dialog opens (the rnc engine reads it through a formula preview); the
3343
+ // typed Stop and the count to it both use it.
3344
+ const date1904 = getDate1904?.() ?? false;
3307
3345
  openFillSeriesDialog({
3308
3346
  sheetId,
3309
3347
  activeCell,
3310
3348
  selection,
3311
- initialIn,
3312
- onApply: (spec) => applyFillSeriesSpec(sheetId, activeCell, selection, spec),
3349
+ // Excel opens on Rows for a single cell; a range keeps the dialog's default.
3350
+ initialIn: initialIn ?? (isSingleCellRange(selection.range) ? "rows" : undefined),
3351
+ onApply: (spec) => applyFillSeriesSpec(sheetId, activeCell, selection, spec, date1904),
3313
3352
  locale,
3314
- // Asked once, as the dialog opens (the rnc engine reads it through a formula preview).
3315
- date1904: getDate1904?.() ?? false,
3353
+ date1904,
3316
3354
  parseStop: parseCellEntryNumber,
3317
3355
  });
3318
3356
  }, [
@@ -20,9 +20,9 @@ export type FillSeriesDialogProps = {
20
20
  /**
21
21
  * Excel's Series dialog (Home > Fill > Series…). Series in Rows/Columns, Type
22
22
  * Linear/Growth/Date/AutoFill, Date unit (Type = Date only), Trend
23
- * (Linear/Growth only — disables Step/Stop), Step value (default 1, may be
24
- * negative or fractional) and Stop value. UI-only: the opener turns the spec
25
- * into a fill.
23
+ * (Linear/Growth only — disables Step/Stop and the Date / AutoFill types),
24
+ * Step value (default 1, may be negative or fractional) and Stop value (both
25
+ * disabled for AutoFill). UI-only: the opener turns the spec into a fill.
26
26
  */
27
27
  export declare const FillSeriesDialog: React.MemoExoticComponent<({ open, onOpenChange, initialIn, onApply, locale, date1904, parseStop, }: FillSeriesDialogProps) => React.JSX.Element>;
28
28
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/fill-series-dialog/index.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAiD,MAAM,OAAO,CAAC;AAItE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,MAAM,MAAM,qBAAqB,GAAG;IAClC,2BAA2B;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAClC,oEAAoE;IACpE,SAAS,CAAC,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC;IACjC,OAAO,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CAAC;IACpC,oFAAoF;IACpF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oFAAoF;IACpF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CAC9C,CAAC;AA0BF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,uGASxB,qBAAqB,uBAoNzB,CAAC;AAIF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB;;;CAgBhC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/fill-series-dialog/index.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAiD,MAAM,OAAO,CAAC;AAItE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,MAAM,MAAM,qBAAqB,GAAG;IAClC,2BAA2B;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAClC,oEAAoE;IACpE,SAAS,CAAC,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC;IACjC,OAAO,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CAAC;IACpC,oFAAoF;IACpF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oFAAoF;IACpF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,SAAS,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CAC9C,CAAC;AA0BF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,uGASxB,qBAAqB,uBA+NzB,CAAC;AAIF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB;;;CAgBhC,CAAC"}
@@ -24,9 +24,9 @@ const parseNumber = (text) => {
24
24
  /**
25
25
  * Excel's Series dialog (Home > Fill > Series…). Series in Rows/Columns, Type
26
26
  * Linear/Growth/Date/AutoFill, Date unit (Type = Date only), Trend
27
- * (Linear/Growth only — disables Step/Stop), Step value (default 1, may be
28
- * negative or fractional) and Stop value. UI-only: the opener turns the spec
29
- * into a fill.
27
+ * (Linear/Growth only — disables Step/Stop and the Date / AutoFill types),
28
+ * Step value (default 1, may be negative or fractional) and Stop value (both
29
+ * disabled for AutoFill). UI-only: the opener turns the spec into a fill.
30
30
  */
31
31
  export const FillSeriesDialog = memo(({ open, onOpenChange, initialIn, onApply, locale, date1904, parseStop, }) => {
32
32
  const [axis, setAxis] = useState(initialIn ?? "columns");
@@ -49,7 +49,9 @@ export const FillSeriesDialog = memo(({ open, onOpenChange, initialIn, onApply,
49
49
  }
50
50
  }, [open, initialIn]);
51
51
  const trendAllowed = type === "linear" || type === "growth";
52
- const stepStopDisabled = trendAllowed && trend;
52
+ const trendOn = trendAllowed && trend;
53
+ // As in Excel: AutoFill has no Step or Stop, and Trend fits its own step and ignores the Stop.
54
+ const stepStopDisabled = type === "autofill" || trendOn;
53
55
  const apply = useCallback(() => {
54
56
  const stepValue = parseNumber(step);
55
57
  if (!stepStopDisabled && step.trim() && stepValue === undefined) {
@@ -71,7 +73,7 @@ export const FillSeriesDialog = memo(({ open, onOpenChange, initialIn, onApply,
71
73
  in: axis,
72
74
  type,
73
75
  ...(type === "date" ? { dateUnit } : {}),
74
- ...(trendAllowed && trend ? { trend: true } : {}),
76
+ ...(trendOn ? { trend: true } : {}),
75
77
  ...(!stepStopDisabled && stepValue !== undefined
76
78
  ? { step: stepValue }
77
79
  : {}),
@@ -85,8 +87,7 @@ export const FillSeriesDialog = memo(({ open, onOpenChange, initialIn, onApply,
85
87
  axis,
86
88
  type,
87
89
  dateUnit,
88
- trend,
89
- trendAllowed,
90
+ trendOn,
90
91
  step,
91
92
  stop,
92
93
  stepStopDisabled,
@@ -114,15 +115,19 @@ export const FillSeriesDialog = memo(({ open, onOpenChange, initialIn, onApply,
114
115
  React.createElement("fieldset", { className: "flex flex-col gap-1 border-0 p-0 m-0" },
115
116
  React.createElement("legend", { className: "text-xs font-medium pb-1" }, "Type"),
116
117
  SERIES_TYPES.map(({ value, label }) => (React.createElement("label", { key: value, className: "flex items-center gap-2 text-xs cursor-pointer" },
117
- React.createElement("input", { type: "radio", name: "fillSeriesType", value: value, checked: type === value, onChange: () => setType(value) }),
118
- label)))),
118
+ React.createElement("input", { type: "radio", name: "fillSeriesType", value: value, checked: type === value, onChange: () => setType(value),
119
+ // A trend is Linear or Growth only.
120
+ disabled: trendOn && (value === "date" || value === "autofill") }),
121
+ React.createElement("span", { className: trendOn && (value === "date" || value === "autofill")
122
+ ? "opacity-50"
123
+ : "" }, label))))),
119
124
  React.createElement("fieldset", { className: "flex flex-col gap-1 border-0 p-0 m-0", disabled: type !== "date" },
120
125
  React.createElement("legend", { className: "text-xs font-medium pb-1" }, "Date unit"),
121
126
  DATE_UNITS.map(({ value, label }) => (React.createElement("label", { key: value, className: "flex items-center gap-2 text-xs cursor-pointer disabled:opacity-50" },
122
127
  React.createElement("input", { type: "radio", name: "fillSeriesDateUnit", value: value, checked: dateUnit === value, onChange: () => setDateUnit(value), disabled: type !== "date" }),
123
128
  React.createElement("span", { className: type !== "date" ? "opacity-50" : "" }, label)))))),
124
129
  React.createElement("label", { className: "flex items-center gap-2 text-xs cursor-pointer" },
125
- React.createElement("input", { type: "checkbox", name: "fillSeriesTrend", checked: trendAllowed && trend, disabled: !trendAllowed, onChange: (e) => setTrend(e.target.checked) }),
130
+ React.createElement("input", { type: "checkbox", name: "fillSeriesTrend", checked: trendOn, disabled: !trendAllowed, onChange: (e) => setTrend(e.target.checked) }),
126
131
  React.createElement("span", { className: !trendAllowed ? "opacity-50" : "" }, "Trend")),
127
132
  React.createElement("div", { className: "grid grid-cols-2 gap-3" },
128
133
  React.createElement("label", { className: "flex flex-col gap-1 text-xs" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rowsncolumns/spreadsheet",
3
- "version": "10.19.1",
3
+ "version": "10.19.2",
4
4
  "author": "Vinay M",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "main": "./dist/cjs/index.js",