@rowsncolumns/spreadsheet-state 28.0.72 → 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 +2 -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/paste-special.d.ts +48 -0
- package/dist/cjs/api/paste-special.d.ts.map +1 -0
- package/dist/cjs/api/paste-special.js +229 -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 +13 -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/components/editors/table-editor.js +7 -2
- package/dist/cjs/hooks/use-calculation-worker.d.ts.map +1 -1
- package/dist/cjs/hooks/use-calculation-worker.js +39 -8
- package/dist/cjs/hooks/use-calculation.d.ts +12 -2
- package/dist/cjs/hooks/use-calculation.d.ts.map +1 -1
- package/dist/cjs/hooks/use-calculation.js +71 -35
- 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-paste.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-paste.js +82 -52
- package/dist/cjs/hooks/use-on-remove-duplicates.d.ts +2 -1
- package/dist/cjs/hooks/use-on-remove-duplicates.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-remove-duplicates.js +5 -3
- package/dist/cjs/hooks/use-on-show-column.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-show-column.js +2 -0
- package/dist/cjs/hooks/use-on-show-row.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-show-row.js +2 -0
- 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 +3 -0
- package/dist/cjs/hooks/use-sheet-properties.d.ts.map +1 -1
- package/dist/cjs/hooks/use-sheet-properties.js +8 -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 +98 -18
- package/dist/cjs/index.d.ts +9 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +9 -0
- package/dist/cjs/interface/calculation-interface.d.ts.map +1 -1
- package/dist/cjs/interface/calculation-interface.js +5 -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/hide-column.d.ts.map +1 -1
- package/dist/cjs/interface/hide-column.js +4 -0
- package/dist/cjs/interface/hide-row.d.ts.map +1 -1
- package/dist/cjs/interface/hide-row.js +4 -0
- package/dist/cjs/interface/remove-duplicates.d.ts +3 -2
- package/dist/cjs/interface/remove-duplicates.d.ts.map +1 -1
- package/dist/cjs/interface/remove-duplicates.js +41 -7
- 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 +2 -1
- package/dist/cjs/interface/spreadsheet-interface.d.ts.map +1 -1
- package/dist/cjs/interface/spreadsheet-interface.js +5 -5
- 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 +2 -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/paste-special.d.ts +48 -0
- package/dist/esm/api/paste-special.d.ts.map +1 -0
- package/dist/esm/api/paste-special.js +220 -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 +13 -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/components/editors/table-editor.js +7 -4
- package/dist/esm/hooks/use-calculation-worker.d.ts.map +1 -1
- package/dist/esm/hooks/use-calculation-worker.js +20 -2
- package/dist/esm/hooks/use-calculation.d.ts +12 -2
- package/dist/esm/hooks/use-calculation.d.ts.map +1 -1
- package/dist/esm/hooks/use-calculation.js +38 -7
- 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-paste.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-paste.js +49 -14
- package/dist/esm/hooks/use-on-remove-duplicates.d.ts +2 -1
- package/dist/esm/hooks/use-on-remove-duplicates.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-remove-duplicates.js +5 -3
- package/dist/esm/hooks/use-on-show-column.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-show-column.js +2 -0
- package/dist/esm/hooks/use-on-show-row.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-show-row.js +2 -0
- 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 +3 -0
- package/dist/esm/hooks/use-sheet-properties.d.ts.map +1 -1
- package/dist/esm/hooks/use-sheet-properties.js +8 -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 +89 -16
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +9 -0
- package/dist/esm/interface/calculation-interface.d.ts.map +1 -1
- package/dist/esm/interface/calculation-interface.js +3 -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/hide-column.d.ts.map +1 -1
- package/dist/esm/interface/hide-column.js +4 -0
- package/dist/esm/interface/hide-row.d.ts.map +1 -1
- package/dist/esm/interface/hide-row.js +4 -0
- package/dist/esm/interface/remove-duplicates.d.ts +3 -2
- package/dist/esm/interface/remove-duplicates.d.ts.map +1 -1
- package/dist/esm/interface/remove-duplicates.js +37 -6
- 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 +2 -1
- package/dist/esm/interface/spreadsheet-interface.d.ts.map +1 -1
- package/dist/esm/interface/spreadsheet-interface.js +5 -5
- 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,MA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AAkBF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAC7B,SAAS,qBAAqB,EAC9B,UAAU,eAAe,KACxB,kBAAkB,GAAG,SAsDvB,CAAC;AAEF,gFAAgF;AAChF,MAAM,MAAM,0BAA0B,GAAG;IACvC,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC3D,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC3D,aAAa,EAAE,CACb,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,SAAS,EAChB,MAAM,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,EAAE,EAAE,KAC3C,IAAI,CAAC;CACX,CAAC;AAEF,iGAAiG;AACjG,eAAO,MAAM,uBAAuB,GAClC,SAAS,MAAM,EACf,MAAM,kBAAkB,EACxB,UAAU,0BAA0B,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,WAAW,EACZ,MAAM,2BAA2B,CAAC;AASnC,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAQxE,KAAK,SAAS,CAAC,CAAC,SAAS,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAC;AAC7D,KAAK,gBAAgB,CAAC,CAAC,SAAS,QAAQ,GAAG,IAAI,GAAG,SAAS,IACzD,2BAA2B,CAAC,CAAC,CAAC,CAAC;AAEjC,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,QAAQ,EACjD,OAAO,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAC1B,SAAS,MAAM,EACf,WAAW,MAAM,KAgBD,KAAK,CAAC,gBAAgB,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC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ationRules = {
|
|
|
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 },
|
|
74
|
+
EXPAND: { type: "fixed_index", index: 0 },
|
|
73
75
|
TOCOL: { type: "fixed_index", index: 0 },
|
|
74
76
|
TOROW: { type: "fixed_index", index: 0 },
|
|
75
77
|
WRAPROWS: { 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
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { CellData, PasteSpecialOperation, PasteSpecialOptions, PasteSpecialType } from "@rowsncolumns/spreadsheet";
|
|
2
|
+
/** Synthetic clipboard key carrying the legacy single-mode `PasteSpecialType`. */
|
|
3
|
+
export declare const PASTE_SPECIAL_TYPE_KEY = "pasteSpecialType";
|
|
4
|
+
/** Synthetic clipboard key carrying a JSON-encoded `PasteSpecialOptions`. */
|
|
5
|
+
export declare const PASTE_SPECIAL_OPTIONS_KEY = "pasteSpecialOptions";
|
|
6
|
+
export type ResolvedPasteSpecialOptions = {
|
|
7
|
+
paste: NonNullable<PasteSpecialOptions["paste"]>;
|
|
8
|
+
operation?: PasteSpecialOperation;
|
|
9
|
+
skipBlanks: boolean;
|
|
10
|
+
transpose: boolean;
|
|
11
|
+
/** True when any Paste Special mode is active (the destination is not a plain overwrite). */
|
|
12
|
+
isSpecial: boolean;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Normalize a `PasteSpecialOptions` (or the legacy single-mode string) into
|
|
16
|
+
* the flags the paste pipelines branch on.
|
|
17
|
+
*/
|
|
18
|
+
export declare const normalizePasteSpecialOptions: (input: PasteSpecialOptions | PasteSpecialType | null | undefined) => ResolvedPasteSpecialOptions;
|
|
19
|
+
/**
|
|
20
|
+
* Read the Paste Special request the grid stashed on the clipboard event
|
|
21
|
+
* (`pasteSpecialOptions` JSON wins over the legacy `pasteSpecialType`).
|
|
22
|
+
*/
|
|
23
|
+
export declare const resolvePasteSpecialOptions: (clipboardData: Pick<DataTransfer, "getData"> | null | undefined) => ResolvedPasteSpecialOptions;
|
|
24
|
+
/**
|
|
25
|
+
* A clipboard cell that carries no value: Paste Special "Skip blanks" leaves
|
|
26
|
+
* the destination untouched for these. A shared-string reference counts as a
|
|
27
|
+
* value.
|
|
28
|
+
*/
|
|
29
|
+
export declare const isBlankClipboardCell: (cell: CellData | null | undefined) => boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Excel Paste Special → Operation. Combines one clipboard cell with the
|
|
32
|
+
* destination cell it lands on and returns the cell data to write there:
|
|
33
|
+
*
|
|
34
|
+
* - number ⊕ number → the arithmetic result (blank destination counts as 0,
|
|
35
|
+
* numeric text is coerced; a non-finite result such as `x/0` is written as
|
|
36
|
+
* the formula `=x/0` so the cell shows `#DIV/0!`).
|
|
37
|
+
* - a formula on either side → a combined formula (`=(dest)+(source)`), the
|
|
38
|
+
* source formula already relocated to the destination by the paste.
|
|
39
|
+
* - blank source → the destination is left as it is (Excel: `d + 0`; the
|
|
40
|
+
* classic "paste-add a blank cell" trick still coerces numeric text).
|
|
41
|
+
* - non-numeric text destination → left as it is.
|
|
42
|
+
* - non-numeric text source → `=dest+"text"` (Excel's `#VALUE!`).
|
|
43
|
+
*
|
|
44
|
+
* `paste: "values"` callers pre-resolve the source to values with
|
|
45
|
+
* `pickValue`, so the source side is never a formula there.
|
|
46
|
+
*/
|
|
47
|
+
export declare const applyPasteOperation: <T extends CellData>(source: T | CellData | null | undefined, destination: CellData | null | undefined, operation: PasteSpecialOperation, sheetId: number, locale?: string) => CellData;
|
|
48
|
+
//# sourceMappingURL=paste-special.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paste-special.d.ts","sourceRoot":"","sources":["../../../api/paste-special.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,EACjB,MAAM,2BAA2B,CAAC;AAanC,kFAAkF;AAClF,eAAO,MAAM,sBAAsB,qBAAqB,CAAC;AACzD,6EAA6E;AAC7E,eAAO,MAAM,yBAAyB,wBAAwB,CAAC;AAE/D,MAAM,MAAM,2BAA2B,GAAG;IACxC,KAAK,EAAE,WAAW,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC;IACjD,SAAS,CAAC,EAAE,qBAAqB,CAAC;IAClC,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,6FAA6F;IAC7F,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AA+BF;;;GAGG;AACH,eAAO,MAAM,4BAA4B,GACvC,OAAO,mBAAmB,GAAG,gBAAgB,GAAG,IAAI,GAAG,SAAS,KAC/D,2BAsBF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,0BAA0B,GACrC,eAAe,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC,GAAG,IAAI,GAAG,SAAS,KAC9D,2BAkBF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAC/B,MAAM,QAAQ,GAAG,IAAI,GAAG,SAAS,KAChC,OAWF,CAAC;AA8FF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,QAAQ,EACpD,QAAQ,CAAC,GAAG,QAAQ,GAAG,IAAI,GAAG,SAAS,EACvC,aAAa,QAAQ,GAAG,IAAI,GAAG,SAAS,EACxC,WAAW,qBAAqB,EAChC,SAAS,MAAM,EACf,SAAS,MAAM,KACd,QAmCF,CAAC"}
|