@rowsncolumns/spreadsheet-state 28.0.73 → 28.0.74
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/advanced-filter.d.ts +72 -0
- package/dist/cjs/api/advanced-filter.d.ts.map +1 -0
- package/dist/cjs/api/advanced-filter.js +0 -0
- package/dist/cjs/api/goal-seek.d.ts +29 -0
- package/dist/cjs/api/goal-seek.d.ts.map +1 -0
- package/dist/cjs/api/goal-seek.js +131 -0
- package/dist/cjs/api/immer-utils.d.ts.map +1 -1
- package/dist/cjs/api/immer-utils.js +1 -0
- package/dist/cjs/api/paint-format.d.ts +41 -0
- package/dist/cjs/api/paint-format.d.ts.map +1 -0
- package/dist/cjs/api/paint-format.js +115 -0
- package/dist/cjs/api/split-text.d.ts +12 -0
- package/dist/cjs/api/split-text.d.ts.map +1 -1
- package/dist/cjs/api/split-text.js +41 -0
- package/dist/cjs/api/subtotal.d.ts +85 -0
- package/dist/cjs/api/subtotal.d.ts.map +1 -0
- package/dist/cjs/api/subtotal.js +250 -0
- package/dist/cjs/commands.d.ts +8 -0
- package/dist/cjs/commands.d.ts.map +1 -1
- package/dist/cjs/components/editors/data-validation-rule-editor.d.ts.map +1 -1
- package/dist/cjs/components/editors/data-validation-rule-editor.js +83 -16
- package/dist/cjs/hooks/use-calculation-worker.d.ts.map +1 -1
- package/dist/cjs/hooks/use-calculation-worker.js +1 -0
- package/dist/cjs/hooks/use-on-advanced-filter.d.ts +21 -0
- package/dist/cjs/hooks/use-on-advanced-filter.d.ts.map +1 -0
- package/dist/cjs/hooks/use-on-advanced-filter.js +42 -0
- package/dist/cjs/hooks/use-on-goal-seek.d.ts +30 -0
- package/dist/cjs/hooks/use-on-goal-seek.d.ts.map +1 -0
- package/dist/cjs/hooks/use-on-goal-seek.js +140 -0
- package/dist/cjs/hooks/use-on-import-excel.d.ts +10 -1
- package/dist/cjs/hooks/use-on-import-excel.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-import-excel.js +8 -4
- package/dist/cjs/hooks/use-on-merge-unmerge-cells.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-merge-unmerge-cells.js +53 -34
- package/dist/cjs/hooks/use-on-subtotal.d.ts +26 -0
- package/dist/cjs/hooks/use-on-subtotal.d.ts.map +1 -0
- package/dist/cjs/hooks/use-on-subtotal.js +53 -0
- package/dist/cjs/hooks/use-paint-format.d.ts +19 -3
- package/dist/cjs/hooks/use-paint-format.d.ts.map +1 -1
- package/dist/cjs/hooks/use-paint-format.js +85 -31
- package/dist/cjs/hooks/use-sheet-properties.d.ts +2 -0
- package/dist/cjs/hooks/use-sheet-properties.d.ts.map +1 -1
- package/dist/cjs/hooks/use-sheet-properties.js +4 -0
- package/dist/cjs/hooks/use-split-text-to-columns.d.ts +2 -1
- package/dist/cjs/hooks/use-split-text-to-columns.d.ts.map +1 -1
- package/dist/cjs/hooks/use-split-text-to-columns.js +3 -2
- package/dist/cjs/hooks/use-spreadsheet-state.d.ts +50 -36
- package/dist/cjs/hooks/use-spreadsheet-state.d.ts.map +1 -1
- package/dist/cjs/hooks/use-spreadsheet-state.js +97 -18
- package/dist/cjs/index.d.ts +8 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +8 -0
- package/dist/cjs/interface/change-batch-stream.d.ts.map +1 -1
- package/dist/cjs/interface/change-batch-stream.js +12 -6
- package/dist/cjs/interface/change-batch.d.ts.map +1 -1
- package/dist/cjs/interface/change-batch.js +17 -9
- package/dist/cjs/interface/change-formatting.d.ts.map +1 -1
- package/dist/cjs/interface/change-formatting.js +30 -11
- package/dist/cjs/interface/split-text.d.ts +2 -1
- package/dist/cjs/interface/split-text.d.ts.map +1 -1
- package/dist/cjs/interface/split-text.js +7 -3
- package/dist/cjs/interface/spreadsheet-interface.d.ts.map +1 -1
- package/dist/cjs/interface/spreadsheet-interface.js +2 -2
- package/dist/cjs/sheet-cell.d.ts.map +1 -1
- package/dist/cjs/sheet-cell.js +7 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/api/advanced-filter.d.ts +72 -0
- package/dist/esm/api/advanced-filter.d.ts.map +1 -0
- package/dist/esm/api/advanced-filter.js +0 -0
- package/dist/esm/api/goal-seek.d.ts +29 -0
- package/dist/esm/api/goal-seek.d.ts.map +1 -0
- package/dist/esm/api/goal-seek.js +108 -0
- package/dist/esm/api/immer-utils.d.ts.map +1 -1
- package/dist/esm/api/immer-utils.js +1 -0
- package/dist/esm/api/paint-format.d.ts +41 -0
- package/dist/esm/api/paint-format.d.ts.map +1 -0
- package/dist/esm/api/paint-format.js +77 -0
- package/dist/esm/api/split-text.d.ts +12 -0
- package/dist/esm/api/split-text.d.ts.map +1 -1
- package/dist/esm/api/split-text.js +28 -0
- package/dist/esm/api/subtotal.d.ts +85 -0
- package/dist/esm/api/subtotal.d.ts.map +1 -0
- package/dist/esm/api/subtotal.js +181 -0
- package/dist/esm/commands.d.ts +8 -0
- package/dist/esm/commands.d.ts.map +1 -1
- package/dist/esm/components/editors/data-validation-rule-editor.d.ts.map +1 -1
- package/dist/esm/components/editors/data-validation-rule-editor.js +52 -4
- package/dist/esm/hooks/use-calculation-worker.d.ts.map +1 -1
- package/dist/esm/hooks/use-calculation-worker.js +1 -0
- package/dist/esm/hooks/use-on-advanced-filter.d.ts +21 -0
- package/dist/esm/hooks/use-on-advanced-filter.d.ts.map +1 -0
- package/dist/esm/hooks/use-on-advanced-filter.js +41 -0
- package/dist/esm/hooks/use-on-goal-seek.d.ts +30 -0
- package/dist/esm/hooks/use-on-goal-seek.d.ts.map +1 -0
- package/dist/esm/hooks/use-on-goal-seek.js +82 -0
- package/dist/esm/hooks/use-on-import-excel.d.ts +10 -1
- package/dist/esm/hooks/use-on-import-excel.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-import-excel.js +8 -4
- package/dist/esm/hooks/use-on-merge-unmerge-cells.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-merge-unmerge-cells.js +13 -13
- package/dist/esm/hooks/use-on-subtotal.d.ts +26 -0
- package/dist/esm/hooks/use-on-subtotal.d.ts.map +1 -0
- package/dist/esm/hooks/use-on-subtotal.js +48 -0
- package/dist/esm/hooks/use-paint-format.d.ts +19 -3
- package/dist/esm/hooks/use-paint-format.d.ts.map +1 -1
- package/dist/esm/hooks/use-paint-format.js +71 -29
- package/dist/esm/hooks/use-sheet-properties.d.ts +2 -0
- package/dist/esm/hooks/use-sheet-properties.d.ts.map +1 -1
- package/dist/esm/hooks/use-sheet-properties.js +4 -0
- package/dist/esm/hooks/use-split-text-to-columns.d.ts +2 -1
- package/dist/esm/hooks/use-split-text-to-columns.d.ts.map +1 -1
- package/dist/esm/hooks/use-split-text-to-columns.js +3 -2
- package/dist/esm/hooks/use-spreadsheet-state.d.ts +50 -36
- package/dist/esm/hooks/use-spreadsheet-state.d.ts.map +1 -1
- package/dist/esm/hooks/use-spreadsheet-state.js +88 -16
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +8 -0
- package/dist/esm/interface/change-batch-stream.d.ts.map +1 -1
- package/dist/esm/interface/change-batch-stream.js +12 -6
- package/dist/esm/interface/change-batch.d.ts.map +1 -1
- package/dist/esm/interface/change-batch.js +15 -9
- package/dist/esm/interface/change-formatting.d.ts.map +1 -1
- package/dist/esm/interface/change-formatting.js +28 -11
- package/dist/esm/interface/split-text.d.ts +2 -1
- package/dist/esm/interface/split-text.d.ts.map +1 -1
- package/dist/esm/interface/split-text.js +6 -3
- package/dist/esm/interface/spreadsheet-interface.d.ts.map +1 -1
- package/dist/esm/interface/spreadsheet-interface.js +2 -2
- package/dist/esm/sheet-cell.d.ts.map +1 -1
- package/dist/esm/sheet-cell.js +7 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +18 -18
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { GridRange } from "@rowsncolumns/common-types";
|
|
2
|
+
import type { AdvancedFilterAction, AdvancedFilterOptions } from "@rowsncolumns/spreadsheet";
|
|
3
|
+
/**
|
|
4
|
+
* Excel's Data → Sort & Filter → Advanced: a list range (header row + records)
|
|
5
|
+
* filtered by a CRITERIA RANGE — a header row naming list columns, then one
|
|
6
|
+
* or more criteria rows. Conditions on one criteria row AND together; the
|
|
7
|
+
* rows OR together. A criterion cell is an Excel comparison string:
|
|
8
|
+
*
|
|
9
|
+
* `>100` `<=5` `<>done` `=apple` operator + value
|
|
10
|
+
* `app` text begins with "app" (case-insensitive)
|
|
11
|
+
* `="=apple"` → `=apple` exact text match
|
|
12
|
+
* `a*e` `?at` `~*` `*` any run, `?` one char, `~` escapes
|
|
13
|
+
* blank no condition (a fully blank criteria row
|
|
14
|
+
* matches every record, as in Excel)
|
|
15
|
+
*
|
|
16
|
+
* Numbers compare numerically when both sides are numeric; text compares
|
|
17
|
+
* case-insensitively. A criteria header that matches no list header is a
|
|
18
|
+
* computed criterion in Excel — those need a formula per record and are not
|
|
19
|
+
* evaluated here (the condition is ignored; see the compatibility doc).
|
|
20
|
+
*/
|
|
21
|
+
export type { AdvancedFilterAction, AdvancedFilterOptions };
|
|
22
|
+
export type CellValueReader = (rowIndex: number, columnIndex: number) => string | number | boolean | null | undefined;
|
|
23
|
+
type Operator = "=" | "<>" | "<" | "<=" | ">" | ">=" | "begins";
|
|
24
|
+
export type Criterion = {
|
|
25
|
+
columnIndex: number;
|
|
26
|
+
operator: Operator;
|
|
27
|
+
value: string;
|
|
28
|
+
};
|
|
29
|
+
/** Excel wildcard pattern → anchored RegExp (`~` escapes `*`, `?`, `~`). */
|
|
30
|
+
export declare const wildcardToRegExp: (pattern: string, anchorEnd?: boolean) => RegExp;
|
|
31
|
+
/** Whether one record cell satisfies one criterion. */
|
|
32
|
+
export declare const matchesCriterion: (cellValue: string | number | boolean | null | undefined, criterion: Criterion) => boolean;
|
|
33
|
+
/**
|
|
34
|
+
* One OR-branch of the criteria range: the AND-ed criteria of one criteria
|
|
35
|
+
* row. An empty array is a blank criteria row — it matches every record.
|
|
36
|
+
*/
|
|
37
|
+
export type CriteriaRow = Criterion[];
|
|
38
|
+
/**
|
|
39
|
+
* Reads the criteria range against the list's header row. Criteria headers
|
|
40
|
+
* resolve to list columns case-insensitively; a header without a list match
|
|
41
|
+
* (a computed criterion) is skipped.
|
|
42
|
+
*/
|
|
43
|
+
export declare const parseCriteriaRange: (listRange: GridRange, criteriaRange: GridRange, getValue: CellValueReader) => CriteriaRow[];
|
|
44
|
+
/** A record matches when any criteria row's conditions all hold. */
|
|
45
|
+
export declare const matchesCriteria: (rowIndex: number, criteriaRows: CriteriaRow[], getValue: CellValueReader) => boolean;
|
|
46
|
+
export type AdvancedFilterPlan = {
|
|
47
|
+
/** Record rows that satisfy the criteria (absolute indexes, ascending). */
|
|
48
|
+
matchingRows: number[];
|
|
49
|
+
/** `filter`: record rows to hide (non-matching). */
|
|
50
|
+
hideRows: number[];
|
|
51
|
+
/** `filter`: record rows to show (matching — undoes an earlier in-place filter). */
|
|
52
|
+
showRows: number[];
|
|
53
|
+
/** `copy`: the header row + matching records to write at `copyTo`. */
|
|
54
|
+
copy?: {
|
|
55
|
+
range: GridRange;
|
|
56
|
+
values: (string | number | boolean | null)[][];
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Plans an Advanced Filter over the list range. Returns `undefined` when the
|
|
61
|
+
* list has no records, or `copy` was asked for without a destination.
|
|
62
|
+
*/
|
|
63
|
+
export declare const planAdvancedFilter: (options: AdvancedFilterOptions, getValue: CellValueReader) => AdvancedFilterPlan | undefined;
|
|
64
|
+
/** The state callbacks a plan is applied through — the same in both engines. */
|
|
65
|
+
export type AdvancedFilterPlanExecutor = {
|
|
66
|
+
onHideRow: (sheetId: number, rowIndexes: number[]) => void;
|
|
67
|
+
onShowRow: (sheetId: number, rowIndexes: number[]) => void;
|
|
68
|
+
onChangeBatch: (sheetId: number, range: GridRange, values: (string | number | boolean | null)[][]) => void;
|
|
69
|
+
};
|
|
70
|
+
/** Applies an {@link AdvancedFilterPlan}: show the matches, hide the rest, or write the copy. */
|
|
71
|
+
export declare const applyAdvancedFilterPlan: (sheetId: number, plan: AdvancedFilterPlan, executor: AdvancedFilterPlanExecutor) => void;
|
|
72
|
+
//# sourceMappingURL=advanced-filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advanced-filter.d.ts","sourceRoot":"","sources":["../../../api/advanced-filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,EACV,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,2BAA2B,CAAC;AAEnC;;;;;;;;;;;;;;;;;GAiBG;AACH,YAAY,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,CAAC;AAE5D,MAAM,MAAM,eAAe,GAAG,CAC5B,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,KAChB,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;AAElD,KAAK,QAAQ,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,QAAQ,CAAC;AAEhE,MAAM,MAAM,SAAS,GAAG;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAkBF,4EAA4E;AAC5E,eAAO,MAAM,gBAAgB,GAAI,SAAS,MAAM,EAAE,mBAAgB,KAAG,MAepE,CAAC;AAqBF,uDAAuD;AACvD,eAAO,MAAM,gBAAgB,GAC3B,WAAW,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,EACvD,WAAW,SAAS,KACnB,OA6CF,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,SAAS,EAAE,CAAC;AAEtC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SAQrC,CAAC"}
|
|
Binary file
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Excel's Data → What-If Analysis → Goal Seek solver.
|
|
3
|
+
*
|
|
4
|
+
* Excel's defaults are 100 iterations and a change-tolerance of 0.001 (its
|
|
5
|
+
* Calculation options → "Maximum Iterations" / "Maximum Change"). The
|
|
6
|
+
* search is a secant method — Excel's own is a secant/Newton hybrid — with
|
|
7
|
+
* bisection whenever a sign change has been bracketed and the secant step
|
|
8
|
+
* would leave the bracket, so a monotone target converges in a handful of
|
|
9
|
+
* evaluations while a badly scaled one still narrows a bracket.
|
|
10
|
+
*
|
|
11
|
+
* `evaluate(trial)` returns the set cell's value with the changing cell at
|
|
12
|
+
* `trial`; `undefined` means the trial produced an error (`#DIV/0!`, text…),
|
|
13
|
+
* which the solver treats as "step somewhere else".
|
|
14
|
+
*/
|
|
15
|
+
import type { GoalSeekResult, GoalSeekStatus } from "@rowsncolumns/spreadsheet";
|
|
16
|
+
export declare const GOAL_SEEK_MAX_ITERATIONS = 100;
|
|
17
|
+
export declare const GOAL_SEEK_TOLERANCE = 0.001;
|
|
18
|
+
export type GoalSeekEvaluate = (trial: number) => Promise<number | undefined>;
|
|
19
|
+
export type { GoalSeekResult, GoalSeekStatus };
|
|
20
|
+
export type GoalSeekOptions = {
|
|
21
|
+
evaluate: GoalSeekEvaluate;
|
|
22
|
+
targetValue: number;
|
|
23
|
+
/** Starting trial — the changing cell's current value (0 when blank). */
|
|
24
|
+
initialValue?: number;
|
|
25
|
+
maxIterations?: number;
|
|
26
|
+
tolerance?: number;
|
|
27
|
+
};
|
|
28
|
+
export declare const goalSeek: ({ evaluate, targetValue, initialValue, maxIterations, tolerance, }: GoalSeekOptions) => Promise<GoalSeekResult>;
|
|
29
|
+
//# sourceMappingURL=goal-seek.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goal-seek.d.ts","sourceRoot":"","sources":["../../../api/goal-seek.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhF,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAC5C,eAAO,MAAM,mBAAmB,QAAQ,CAAC;AAEzC,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;AAE9E,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,CAAC;AAE/C,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,yEAAyE;IACzE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAKF,eAAO,MAAM,QAAQ,GAAU,oEAM5B,eAAe,KAAG,OAAO,CAAC,cAAc,CAqG1C,CAAC"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { __awaiter, __generator } from "tslib";
|
|
2
|
+
export var GOAL_SEEK_MAX_ITERATIONS = 100;
|
|
3
|
+
export var GOAL_SEEK_TOLERANCE = 0.001;
|
|
4
|
+
var isUsable = function (value) {
|
|
5
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
6
|
+
};
|
|
7
|
+
export var goalSeek = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
8
|
+
var iterations, best, residualAt, finish, negative, positive, bracket, x0, f0, nudges, x1, shrinks, backoffs, f1, x2, slope, lo, hi;
|
|
9
|
+
var evaluate = _b.evaluate, targetValue = _b.targetValue, _c = _b.initialValue, initialValue = _c === void 0 ? 0 : _c, _d = _b.maxIterations, maxIterations = _d === void 0 ? GOAL_SEEK_MAX_ITERATIONS : _d, _e = _b.tolerance, tolerance = _e === void 0 ? GOAL_SEEK_TOLERANCE : _e;
|
|
10
|
+
return __generator(this, function (_f) {
|
|
11
|
+
switch (_f.label) {
|
|
12
|
+
case 0:
|
|
13
|
+
iterations = 0;
|
|
14
|
+
best = {
|
|
15
|
+
value: initialValue,
|
|
16
|
+
currentValue: undefined,
|
|
17
|
+
residual: Number.POSITIVE_INFINITY,
|
|
18
|
+
};
|
|
19
|
+
residualAt = function (trial) { return __awaiter(void 0, void 0, void 0, function () {
|
|
20
|
+
var current, residual;
|
|
21
|
+
return __generator(this, function (_a) {
|
|
22
|
+
switch (_a.label) {
|
|
23
|
+
case 0:
|
|
24
|
+
iterations++;
|
|
25
|
+
return [4 /*yield*/, evaluate(trial)];
|
|
26
|
+
case 1:
|
|
27
|
+
current = _a.sent();
|
|
28
|
+
if (!isUsable(current))
|
|
29
|
+
return [2 /*return*/, undefined];
|
|
30
|
+
residual = current - targetValue;
|
|
31
|
+
if (Math.abs(residual) < best.residual) {
|
|
32
|
+
best = { value: trial, currentValue: current, residual: Math.abs(residual) };
|
|
33
|
+
}
|
|
34
|
+
return [2 /*return*/, residual];
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}); };
|
|
38
|
+
finish = function (status) { return ({
|
|
39
|
+
status: status,
|
|
40
|
+
value: best.value,
|
|
41
|
+
currentValue: best.currentValue,
|
|
42
|
+
targetValue: targetValue,
|
|
43
|
+
iterations: iterations,
|
|
44
|
+
}); };
|
|
45
|
+
bracket = function (x, f) {
|
|
46
|
+
if (f < 0)
|
|
47
|
+
negative = x;
|
|
48
|
+
else
|
|
49
|
+
positive = x;
|
|
50
|
+
};
|
|
51
|
+
x0 = initialValue;
|
|
52
|
+
return [4 /*yield*/, residualAt(x0)];
|
|
53
|
+
case 1:
|
|
54
|
+
f0 = _f.sent();
|
|
55
|
+
nudges = 0;
|
|
56
|
+
_f.label = 2;
|
|
57
|
+
case 2:
|
|
58
|
+
if (!(f0 === undefined && iterations < maxIterations && nudges < 8)) return [3 /*break*/, 4];
|
|
59
|
+
x0 = x0 === 0 ? 1 : x0 * 2;
|
|
60
|
+
return [4 /*yield*/, residualAt(x0)];
|
|
61
|
+
case 3:
|
|
62
|
+
f0 = _f.sent();
|
|
63
|
+
nudges++;
|
|
64
|
+
return [3 /*break*/, 2];
|
|
65
|
+
case 4:
|
|
66
|
+
if (f0 === undefined)
|
|
67
|
+
return [2 /*return*/, finish("not-found")];
|
|
68
|
+
if (Math.abs(f0) <= tolerance)
|
|
69
|
+
return [2 /*return*/, finish("found")];
|
|
70
|
+
bracket(x0, f0);
|
|
71
|
+
x1 = x0 === 0 ? 0.01 : x0 * 1.01;
|
|
72
|
+
shrinks = 0;
|
|
73
|
+
backoffs = 0;
|
|
74
|
+
_f.label = 5;
|
|
75
|
+
case 5:
|
|
76
|
+
if (!(iterations < maxIterations)) return [3 /*break*/, 7];
|
|
77
|
+
return [4 /*yield*/, residualAt(x1)];
|
|
78
|
+
case 6:
|
|
79
|
+
f1 = _f.sent();
|
|
80
|
+
if (f1 === undefined) {
|
|
81
|
+
// Errored trial: pull it halfway back toward the last good point.
|
|
82
|
+
if (++shrinks > 16)
|
|
83
|
+
return [2 /*return*/, finish("not-found")];
|
|
84
|
+
x1 = x0 + (x1 - x0) / 2;
|
|
85
|
+
return [3 /*break*/, 5];
|
|
86
|
+
}
|
|
87
|
+
shrinks = 0;
|
|
88
|
+
if (Math.abs(f1) <= tolerance)
|
|
89
|
+
return [2 /*return*/, finish("found")];
|
|
90
|
+
bracket(x1, f1);
|
|
91
|
+
// A secant step that made things worse with no sign change in sight is
|
|
92
|
+
// heading away from the root (a flat or curving function such as =1/A1):
|
|
93
|
+
// back off — half the step, in the opposite direction — instead of
|
|
94
|
+
// following it to infinity. The bracketed case below never needs this.
|
|
95
|
+
if ((negative === undefined || positive === undefined) &&
|
|
96
|
+
Math.abs(f1) > Math.abs(f0)) {
|
|
97
|
+
if (++backoffs > 24)
|
|
98
|
+
return [2 /*return*/, finish("not-found")];
|
|
99
|
+
x1 = x0 - (x1 - x0) / 2;
|
|
100
|
+
return [3 /*break*/, 5];
|
|
101
|
+
}
|
|
102
|
+
backoffs = 0;
|
|
103
|
+
x2 = void 0;
|
|
104
|
+
slope = f1 - f0;
|
|
105
|
+
if (slope === 0 || !Number.isFinite(slope)) {
|
|
106
|
+
// Flat: widen the step in the same direction to find any change.
|
|
107
|
+
x2 = x1 + (x1 - x0 || 0.01) * 2;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
x2 = x1 - (f1 * (x1 - x0)) / slope;
|
|
111
|
+
}
|
|
112
|
+
if (negative !== undefined && positive !== undefined) {
|
|
113
|
+
lo = Math.min(negative, positive);
|
|
114
|
+
hi = Math.max(negative, positive);
|
|
115
|
+
if (!Number.isFinite(x2) || x2 <= lo || x2 >= hi) {
|
|
116
|
+
x2 = (lo + hi) / 2;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else if (!Number.isFinite(x2)) {
|
|
120
|
+
return [2 /*return*/, finish("not-found")];
|
|
121
|
+
}
|
|
122
|
+
if (x2 === x1)
|
|
123
|
+
return [2 /*return*/, finish(Math.abs(f1) <= tolerance ? "found" : "not-found")];
|
|
124
|
+
x0 = x1;
|
|
125
|
+
f0 = f1;
|
|
126
|
+
x1 = x2;
|
|
127
|
+
return [3 /*break*/, 5];
|
|
128
|
+
case 7: return [2 /*return*/, finish("not-found")];
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}); };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"immer-utils.d.ts","sourceRoot":"","sources":["../../../api/immer-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,gBAAgB,IAAI,2BAA2B,EAC/C,SAAS,IAAI,oBAAoB,EAClC,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI7E,OAAO,KAAK,EACV,QAAQ,EACR,YAAY,EACZ,gBAAgB,EAChB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AAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,EACzC,kBAAkB,eAAe,EACjC,wBAAwB,UAAU,CAChC,OAAO,kBAAkB,CAC1B,CAAC,uBAAuB,CAAC,YAc3B,CAAC;AAkFF;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,EAAE,UAAU,gBAAgB,CAAC,CAAC,CAAC;;;;;;;;;CAY5D,CAAC;AAEF,eAAO,MAAM,wBAAwB,GAAI,CAAC,SAAS,QAAQ,EACzD,SAAS,MAAM,GAAG,SAAc,EAChC,YAAY,CAAC,QAAQ,GAAG,aAAa,GAAG,UAAU,CAAC,EAAE,EACrD,OAAO,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,EACzC,SAAS,MAAM,EACf,QAAQ,MAAM,GAAG,SAAS,EAC1B,kBAAkB,eAAe,gCA2ClC,CAAC"}
|
|
@@ -70,6 +70,7 @@ var formatDerivationRules = {
|
|
|
70
70
|
UNIQUE: { type: "fixed_index", index: 0 },
|
|
71
71
|
TAKE: { type: "fixed_index", index: 0 },
|
|
72
72
|
DROP: { type: "fixed_index", index: 0 },
|
|
73
|
+
TRIMRANGE: { type: "fixed_index", index: 0 },
|
|
73
74
|
EXPAND: { type: "fixed_index", index: 0 },
|
|
74
75
|
TOCOL: { type: "fixed_index", index: 0 },
|
|
75
76
|
TOROW: { type: "fixed_index", index: 0 },
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { CellFormat, GridRange } from "@rowsncolumns/common-types";
|
|
2
|
+
/**
|
|
3
|
+
* Format-painter pattern shared by both engines: the captured 2-D format grid plus the
|
|
4
|
+
* source block's merge configuration, re-based to the block's top-left so it can be tiled
|
|
5
|
+
* onto any target (Google Sheets copies merges with the format; Excel's painter does too).
|
|
6
|
+
*/
|
|
7
|
+
export type PaintPattern = {
|
|
8
|
+
formats: (CellFormat | null | undefined)[][];
|
|
9
|
+
/** Merges fully inside the source block, as 0-based offsets from its top-left. */
|
|
10
|
+
merges: GridRange[];
|
|
11
|
+
/** Source block size — the tiling period. */
|
|
12
|
+
rows: number;
|
|
13
|
+
cols: number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The merges the painter carries from a source block: every merge that lies FULLY inside
|
|
17
|
+
* `source`, re-based to 0-based offsets from the block's top-left. A merge reaching outside the
|
|
18
|
+
* block is not part of its pattern (Sheets/Excel behave the same — the painter copies the look of
|
|
19
|
+
* the selected cells, not of the cells around them).
|
|
20
|
+
*/
|
|
21
|
+
export declare const collectPaintMerges: (merges: GridRange[] | null | undefined, source: GridRange) => GridRange[];
|
|
22
|
+
/**
|
|
23
|
+
* Tile a pattern's relative merges across `target` with the pattern's period (`rows` × `cols`),
|
|
24
|
+
* the same way the format grid itself is tiled by the formatting applier. A merge that a partial
|
|
25
|
+
* trailing tile would push past the target's edge is dropped — the painter never creates a merge
|
|
26
|
+
* that the user did not drag over.
|
|
27
|
+
*/
|
|
28
|
+
export declare const tilePaintMerges: (relativeMerges: GridRange[], rows: number, cols: number, target: GridRange) => GridRange[];
|
|
29
|
+
/**
|
|
30
|
+
* The banded (table stripe / alternating-colour) format the grid paints under a cell, looked up
|
|
31
|
+
* in the map `getBandedCells` builds for a sheet.
|
|
32
|
+
*/
|
|
33
|
+
export declare const getBandedCellFormat: (bandedCells: Map<string, CellFormat> | undefined | null, rowIndex: number, columnIndex: number) => CellFormat | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Layer a cell's explicit format over the banded format the grid would paint beneath it, so the
|
|
36
|
+
* captured pattern carries the VISIBLE look (Sheets copies the alternating colours as static cell
|
|
37
|
+
* fills — it does not create a table or banding at the target). Explicit keys win; an explicit
|
|
38
|
+
* `undefined` never clobbers a banded value.
|
|
39
|
+
*/
|
|
40
|
+
export declare const layerBandedFormat: (explicit: CellFormat | null | undefined, banded: CellFormat | undefined) => CellFormat | null | undefined;
|
|
41
|
+
//# sourceMappingURL=paint-format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paint-format.d.ts","sourceRoot":"","sources":["../../../api/paint-format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAGxE;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,CAAC,UAAU,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,EAAE,CAAC;IAC7C,kFAAkF;IAClF,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAQF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAC7B,QAAQ,SAAS,EAAE,GAAG,IAAI,GAAG,SAAS,EACtC,QAAQ,SAAS,KAChB,SAAS,EAaX,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAC1B,gBAAgB,SAAS,EAAE,EAC3B,MAAM,MAAM,EACZ,MAAM,MAAM,EACZ,QAAQ,SAAS,KAChB,SAAS,EAqBX,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAC9B,aAAa,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,SAAS,GAAG,IAAI,EACvD,UAAU,MAAM,EAChB,aAAa,MAAM,KAClB,UAAU,GAAG,SACyC,CAAC;AAE1D;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAC5B,UAAU,UAAU,GAAG,IAAI,GAAG,SAAS,EACvC,QAAQ,UAAU,GAAG,SAAS,KAC7B,UAAU,GAAG,IAAI,GAAG,SAWtB,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { __assign, __read, __values } from "tslib";
|
|
2
|
+
import { cellIdentifier } from "@rowsncolumns/grid";
|
|
3
|
+
var rangeContains = function (outer, inner) {
|
|
4
|
+
return inner.startRowIndex >= outer.startRowIndex &&
|
|
5
|
+
inner.endRowIndex <= outer.endRowIndex &&
|
|
6
|
+
inner.startColumnIndex >= outer.startColumnIndex &&
|
|
7
|
+
inner.endColumnIndex <= outer.endColumnIndex;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The merges the painter carries from a source block: every merge that lies FULLY inside
|
|
11
|
+
* `source`, re-based to 0-based offsets from the block's top-left. A merge reaching outside the
|
|
12
|
+
* block is not part of its pattern (Sheets/Excel behave the same — the painter copies the look of
|
|
13
|
+
* the selected cells, not of the cells around them).
|
|
14
|
+
*/
|
|
15
|
+
export var collectPaintMerges = function (merges, source) {
|
|
16
|
+
var e_1, _a;
|
|
17
|
+
if (!(merges === null || merges === void 0 ? void 0 : merges.length))
|
|
18
|
+
return [];
|
|
19
|
+
var out = [];
|
|
20
|
+
try {
|
|
21
|
+
for (var merges_1 = __values(merges), merges_1_1 = merges_1.next(); !merges_1_1.done; merges_1_1 = merges_1.next()) {
|
|
22
|
+
var merge = merges_1_1.value;
|
|
23
|
+
if (!rangeContains(source, merge))
|
|
24
|
+
continue;
|
|
25
|
+
out.push({
|
|
26
|
+
startRowIndex: merge.startRowIndex - source.startRowIndex,
|
|
27
|
+
endRowIndex: merge.endRowIndex - source.startRowIndex,
|
|
28
|
+
startColumnIndex: merge.startColumnIndex - source.startColumnIndex,
|
|
29
|
+
endColumnIndex: merge.endColumnIndex - source.startColumnIndex,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
34
|
+
finally {
|
|
35
|
+
try {
|
|
36
|
+
if (merges_1_1 && !merges_1_1.done && (_a = merges_1.return)) _a.call(merges_1);
|
|
37
|
+
}
|
|
38
|
+
finally { if (e_1) throw e_1.error; }
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Tile a pattern's relative merges across `target` with the pattern's period (`rows` × `cols`),
|
|
44
|
+
* the same way the format grid itself is tiled by the formatting applier. A merge that a partial
|
|
45
|
+
* trailing tile would push past the target's edge is dropped — the painter never creates a merge
|
|
46
|
+
* that the user did not drag over.
|
|
47
|
+
*/
|
|
48
|
+
export var tilePaintMerges = function (relativeMerges, rows, cols, target) {
|
|
49
|
+
var e_2, _a;
|
|
50
|
+
if (!relativeMerges.length || rows <= 0 || cols <= 0)
|
|
51
|
+
return [];
|
|
52
|
+
var out = [];
|
|
53
|
+
for (var top_1 = target.startRowIndex; top_1 <= target.endRowIndex; top_1 += rows) {
|
|
54
|
+
for (var left = target.startColumnIndex; left <= target.endColumnIndex; left += cols) {
|
|
55
|
+
try {
|
|
56
|
+
for (var relativeMerges_1 = (e_2 = void 0, __values(relativeMerges)), relativeMerges_1_1 = relativeMerges_1.next(); !relativeMerges_1_1.done; relativeMerges_1_1 = relativeMerges_1.next()) {
|
|
57
|
+
var merge = relativeMerges_1_1.value;
|
|
58
|
+
var placed = {
|
|
59
|
+
startRowIndex: top_1 + merge.startRowIndex,
|
|
60
|
+
endRowIndex: top_1 + merge.endRowIndex,
|
|
61
|
+
startColumnIndex: left + merge.startColumnIndex,
|
|
62
|
+
endColumnIndex: left + merge.endColumnIndex,
|
|
63
|
+
};
|
|
64
|
+
if (rangeContains(target, placed))
|
|
65
|
+
out.push(placed);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
69
|
+
finally {
|
|
70
|
+
try {
|
|
71
|
+
if (relativeMerges_1_1 && !relativeMerges_1_1.done && (_a = relativeMerges_1.return)) _a.call(relativeMerges_1);
|
|
72
|
+
}
|
|
73
|
+
finally { if (e_2) throw e_2.error; }
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return out;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* The banded (table stripe / alternating-colour) format the grid paints under a cell, looked up
|
|
81
|
+
* in the map `getBandedCells` builds for a sheet.
|
|
82
|
+
*/
|
|
83
|
+
export var getBandedCellFormat = function (bandedCells, rowIndex, columnIndex) {
|
|
84
|
+
return bandedCells === null || bandedCells === void 0 ? void 0 : bandedCells.get(cellIdentifier(rowIndex, columnIndex));
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Layer a cell's explicit format over the banded format the grid would paint beneath it, so the
|
|
88
|
+
* captured pattern carries the VISIBLE look (Sheets copies the alternating colours as static cell
|
|
89
|
+
* fills — it does not create a table or banding at the target). Explicit keys win; an explicit
|
|
90
|
+
* `undefined` never clobbers a banded value.
|
|
91
|
+
*/
|
|
92
|
+
export var layerBandedFormat = function (explicit, banded) {
|
|
93
|
+
var e_3, _a;
|
|
94
|
+
if (!banded)
|
|
95
|
+
return explicit;
|
|
96
|
+
var merged = __assign({}, banded);
|
|
97
|
+
if (explicit) {
|
|
98
|
+
try {
|
|
99
|
+
for (var _b = __values(Object.entries(explicit)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
100
|
+
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
101
|
+
if (value !== undefined) {
|
|
102
|
+
merged[key] = value;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
107
|
+
finally {
|
|
108
|
+
try {
|
|
109
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
110
|
+
}
|
|
111
|
+
finally { if (e_3) throw e_3.error; }
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return merged;
|
|
115
|
+
};
|
|
@@ -1,2 +1,14 @@
|
|
|
1
|
+
import type { SplitTextOptions } from "@rowsncolumns/spreadsheet";
|
|
1
2
|
export declare const splitTextToColumns: (values: (string | null | undefined)[], delimiter?: string) => string[][];
|
|
3
|
+
export type { SplitTextOptions };
|
|
4
|
+
/** Normalized, ascending, de-duplicated positive break positions. */
|
|
5
|
+
export declare const normalizeColumnBreaks: (columnBreaks: number[]) => number[];
|
|
6
|
+
/**
|
|
7
|
+
* Excel's Text to Columns → Fixed width: cut each cell at the given
|
|
8
|
+
* character positions. Fields are trimmed like the delimited path (Excel's
|
|
9
|
+
* General column data format drops the padding spaces fixed-width data is
|
|
10
|
+
* aligned with). Cells without breaks inside their text still split — the
|
|
11
|
+
* trailing fields are empty — so the resulting block is rectangular.
|
|
12
|
+
*/
|
|
13
|
+
export declare const splitTextFixedWidth: (values: (string | null | undefined)[], columnBreaks: number[]) => string[][];
|
|
2
14
|
//# sourceMappingURL=split-text.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"split-text.d.ts","sourceRoot":"","sources":["../../../api/split-text.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"split-text.d.ts","sourceRoot":"","sources":["../../../api/split-text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAIlE,eAAO,MAAM,kBAAkB,GAC7B,QAAQ,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,EACrC,YAAW,MAAY,KACtB,MAAM,EAAE,EAwBV,CAAC;AAEF,YAAY,EAAE,gBAAgB,EAAE,CAAC;AAEjC,qEAAqE;AACrE,eAAO,MAAM,qBAAqB,GAAI,cAAc,MAAM,EAAE,KAAG,MAAM,EAG3C,CAAC;AAE3B;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAC9B,QAAQ,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,EACrC,cAAc,MAAM,EAAE,KACrB,MAAM,EAAE,EAgBV,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { __read, __spreadArray, __values } from "tslib";
|
|
1
2
|
import { isNil } from "@rowsncolumns/utils";
|
|
2
3
|
// Split text to columns - takes a single column and returns 2D array
|
|
3
4
|
export var splitTextToColumns = function (values, delimiter) {
|
|
@@ -23,3 +24,43 @@ export var splitTextToColumns = function (values, delimiter) {
|
|
|
23
24
|
return trimmedParts;
|
|
24
25
|
});
|
|
25
26
|
};
|
|
27
|
+
/** Normalized, ascending, de-duplicated positive break positions. */
|
|
28
|
+
export var normalizeColumnBreaks = function (columnBreaks) {
|
|
29
|
+
return __spreadArray([], __read(new Set(columnBreaks)), false).filter(function (position) { return Number.isInteger(position) && position > 0; })
|
|
30
|
+
.sort(function (a, b) { return a - b; });
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Excel's Text to Columns → Fixed width: cut each cell at the given
|
|
34
|
+
* character positions. Fields are trimmed like the delimited path (Excel's
|
|
35
|
+
* General column data format drops the padding spaces fixed-width data is
|
|
36
|
+
* aligned with). Cells without breaks inside their text still split — the
|
|
37
|
+
* trailing fields are empty — so the resulting block is rectangular.
|
|
38
|
+
*/
|
|
39
|
+
export var splitTextFixedWidth = function (values, columnBreaks) {
|
|
40
|
+
var breaks = normalizeColumnBreaks(columnBreaks);
|
|
41
|
+
return values.map(function (cell) {
|
|
42
|
+
var e_1, _a;
|
|
43
|
+
if (isNil(cell)) {
|
|
44
|
+
return [""];
|
|
45
|
+
}
|
|
46
|
+
var text = String(cell);
|
|
47
|
+
var parts = [];
|
|
48
|
+
var start = 0;
|
|
49
|
+
try {
|
|
50
|
+
for (var breaks_1 = __values(breaks), breaks_1_1 = breaks_1.next(); !breaks_1_1.done; breaks_1_1 = breaks_1.next()) {
|
|
51
|
+
var position = breaks_1_1.value;
|
|
52
|
+
parts.push(text.slice(start, position).trim());
|
|
53
|
+
start = position;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
57
|
+
finally {
|
|
58
|
+
try {
|
|
59
|
+
if (breaks_1_1 && !breaks_1_1.done && (_a = breaks_1.return)) _a.call(breaks_1);
|
|
60
|
+
}
|
|
61
|
+
finally { if (e_1) throw e_1.error; }
|
|
62
|
+
}
|
|
63
|
+
parts.push(text.slice(start).trim());
|
|
64
|
+
return parts;
|
|
65
|
+
});
|
|
66
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { GridRange } from "@rowsncolumns/common-types";
|
|
2
|
+
import { SUBTOTAL_FUNCTIONS, type SubtotalFunction, type SubtotalOptions } from "@rowsncolumns/spreadsheet";
|
|
3
|
+
export { SUBTOTAL_FUNCTIONS };
|
|
4
|
+
export type { SubtotalFunction, SubtotalOptions };
|
|
5
|
+
/**
|
|
6
|
+
* The `SUBTOTAL(function_num, …)` code each "Use function" entry writes.
|
|
7
|
+
* Codes 1–11 (not 101–111): the subtotal rows Excel inserts count manually
|
|
8
|
+
* hidden rows.
|
|
9
|
+
*/
|
|
10
|
+
export declare const SUBTOTAL_FUNCTION_NUMBERS: Record<SubtotalFunction, number>;
|
|
11
|
+
/** Excel's total-row labels: "<group> Total" per group, "Grand Total" at the bottom. */
|
|
12
|
+
export declare const SUBTOTAL_GRAND_TOTAL_LABEL = "Grand Total";
|
|
13
|
+
export declare const subtotalGroupLabel: (groupValue: string) => string;
|
|
14
|
+
/**
|
|
15
|
+
* Reads a cell of the data range. `getValue` should return the DISPLAYED text
|
|
16
|
+
* when the host has one (Excel groups and labels on what the cells show —
|
|
17
|
+
* `1/1/2024 Total`, not `45292 Total`). `getFormula` returns the `=…` text for
|
|
18
|
+
* a formula cell. `getOutlineLevel` returns a row's current outline level so
|
|
19
|
+
* "Replace current subtotals" can rebuild the outline from level 0.
|
|
20
|
+
*/
|
|
21
|
+
export type SubtotalReader = {
|
|
22
|
+
getValue: (rowIndex: number, columnIndex: number) => string | number | boolean | null | undefined;
|
|
23
|
+
getFormula: (rowIndex: number, columnIndex: number) => string | undefined;
|
|
24
|
+
getOutlineLevel?: (rowIndex: number) => number | undefined;
|
|
25
|
+
};
|
|
26
|
+
/** One `change-batch` write: a single row segment at final coordinates. */
|
|
27
|
+
export type SubtotalWrite = {
|
|
28
|
+
rowIndex: number;
|
|
29
|
+
startColumnIndex: number;
|
|
30
|
+
values: (string | null)[];
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The plan applies in this order, every index already in FINAL coordinates
|
|
34
|
+
* (the sheet after all removals and insertions):
|
|
35
|
+
* 1. `deleteRows` (descending original indexes — existing subtotal rows),
|
|
36
|
+
* 2. `insertRows` ascending: inserting at final row `r` shifts the not-yet
|
|
37
|
+
* final rows below it, so ascending order lands each new row exactly
|
|
38
|
+
* where the plan expects it,
|
|
39
|
+
* 3. `writes` (labels + SUBTOTAL formulas),
|
|
40
|
+
* 4. `ungroupRows`: one `ungroup-rows` call per entry — the outline reset of
|
|
41
|
+
* "Replace current subtotals". Group / ungroup are ±1 steps in both
|
|
42
|
+
* engines, so pass `k` lists the surviving data rows that were deeper
|
|
43
|
+
* than level `k`; after the passes every row of the range is back at
|
|
44
|
+
* level 0 (empty when nothing was outlined or when not replacing), then
|
|
45
|
+
* 5. `outlineGroups`: one `group-rows` call per entry (Excel's levels — the
|
|
46
|
+
* first spans every row above the grand total, the second the detail
|
|
47
|
+
* rows of each group, so detail rows end at level 2 and subtotal rows
|
|
48
|
+
* at level 1 — the same three-level outline on every re-apply).
|
|
49
|
+
*/
|
|
50
|
+
export type SubtotalPlan = {
|
|
51
|
+
deleteRows: number[];
|
|
52
|
+
insertRows: number[];
|
|
53
|
+
writes: SubtotalWrite[];
|
|
54
|
+
ungroupRows: number[][];
|
|
55
|
+
outlineGroups: number[][];
|
|
56
|
+
/** Number of groups found. */
|
|
57
|
+
groupCount: number;
|
|
58
|
+
/** The range after the plan is applied (header row included when present). */
|
|
59
|
+
resultRange: GridRange;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Plans Excel's Subtotal command over `options.range`. Consecutive rows with
|
|
63
|
+
* the same group-column value form a group (Excel does not sort — it expects
|
|
64
|
+
* the data sorted and totals each run of equal values). Each group gets a
|
|
65
|
+
* total row right below it holding "<value> Total" in the group column and
|
|
66
|
+
* `=SUBTOTAL(n, first:last)` over the group's data rows in every aggregate
|
|
67
|
+
* column; a grand-total row closes the range with `SUBTOTAL` over the whole
|
|
68
|
+
* data block (SUBTOTAL ignores the nested subtotal rows, like Excel). With
|
|
69
|
+
* `replaceCurrent` the range's existing outline is cleared too, so a re-apply
|
|
70
|
+
* yields Excel's fresh detail 2 / subtotal 1 / grand total 0 levels instead
|
|
71
|
+
* of nesting deeper; without it the new levels stack on the old ones (Excel's
|
|
72
|
+
* nested subtotals). Returns `undefined` when the range has no data rows.
|
|
73
|
+
*/
|
|
74
|
+
export declare const planSubtotals: (options: SubtotalOptions, reader: SubtotalReader) => SubtotalPlan | undefined;
|
|
75
|
+
/** The state callbacks a plan is applied through — the same in both engines. */
|
|
76
|
+
export type SubtotalPlanExecutor = {
|
|
77
|
+
onDeleteRow: (sheetId: number, rowIndexes: number[]) => void;
|
|
78
|
+
onInsertRow: (sheetId: number, referenceRowIndex: number, numRows?: number) => void;
|
|
79
|
+
onChangeBatch: (sheetId: number, range: GridRange, values: (string | null)[][]) => void;
|
|
80
|
+
onGroupRows: (sheetId: number, rowIndexes: number[]) => void;
|
|
81
|
+
onUngroupRows: (sheetId: number, rowIndexes: number[]) => void;
|
|
82
|
+
};
|
|
83
|
+
/** Applies a {@link SubtotalPlan} in its documented order. */
|
|
84
|
+
export declare const applySubtotalPlan: (sheetId: number, plan: SubtotalPlan, executor: SubtotalPlanExecutor) => void;
|
|
85
|
+
//# sourceMappingURL=subtotal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subtotal.d.ts","sourceRoot":"","sources":["../../../api/subtotal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EACL,kBAAkB,EAClB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACrB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAC9B,YAAY,EAAE,gBAAgB,EAAE,eAAe,E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