@rowsncolumns/spreadsheet 10.15.0 → 10.18.0

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.
Files changed (130) hide show
  1. package/dist/cjs/api/editor-formula.d.ts +40 -0
  2. package/dist/cjs/api/editor-formula.d.ts.map +1 -0
  3. package/dist/cjs/api/editor-formula.js +87 -0
  4. package/dist/cjs/atoms/cell-input-context.atom.d.ts.map +1 -1
  5. package/dist/cjs/components/autocorrect-options-smart-tag/index.d.ts +22 -8
  6. package/dist/cjs/components/autocorrect-options-smart-tag/index.d.ts.map +1 -1
  7. package/dist/cjs/components/autocorrect-options-smart-tag/index.js +107 -22
  8. package/dist/cjs/components/canvas-grid/frozen-start.d.ts +130 -0
  9. package/dist/cjs/components/canvas-grid/frozen-start.d.ts.map +1 -0
  10. package/dist/cjs/components/canvas-grid/frozen-start.js +266 -0
  11. package/dist/cjs/components/canvas-grid/index.d.ts.map +1 -1
  12. package/dist/cjs/components/canvas-grid/index.js +515 -71
  13. package/dist/cjs/components/canvas-grid/typings.d.ts +24 -8
  14. package/dist/cjs/components/canvas-grid/typings.d.ts.map +1 -1
  15. package/dist/cjs/components/cell-input/cell-input.d.ts.map +1 -1
  16. package/dist/cjs/components/cell-input/cell-input.js +3 -1
  17. package/dist/cjs/components/embeds/embed-draggable.d.ts.map +1 -1
  18. package/dist/cjs/components/embeds/embed-draggable.js +42 -19
  19. package/dist/cjs/components/embeds/object-cell-offset.d.ts +10 -0
  20. package/dist/cjs/components/embeds/object-cell-offset.d.ts.map +1 -0
  21. package/dist/cjs/components/embeds/object-cell-offset.js +12 -0
  22. package/dist/cjs/components/embeds/object-focus.d.ts +16 -3
  23. package/dist/cjs/components/embeds/object-focus.d.ts.map +1 -1
  24. package/dist/cjs/components/embeds/object-focus.js +62 -6
  25. package/dist/cjs/components/outline-gutter/index.d.ts +11 -3
  26. package/dist/cjs/components/outline-gutter/index.d.ts.map +1 -1
  27. package/dist/cjs/components/outline-gutter/index.js +11 -6
  28. package/dist/cjs/components/selection/index.d.ts +1 -1
  29. package/dist/cjs/components/selection/index.d.ts.map +1 -1
  30. package/dist/cjs/components/selection/index.js +2 -2
  31. package/dist/cjs/components/selection/types.d.ts +2 -0
  32. package/dist/cjs/components/selection/types.d.ts.map +1 -1
  33. package/dist/cjs/hooks/object-spec-schema.generated.d.ts.map +1 -1
  34. package/dist/cjs/hooks/object-spec-schema.generated.js +16 -0
  35. package/dist/cjs/hooks/use-editable.d.ts.map +1 -1
  36. package/dist/cjs/hooks/use-editable.js +5 -1
  37. package/dist/cjs/hooks/use-editor-change.d.ts.map +1 -1
  38. package/dist/cjs/hooks/use-editor-change.js +3 -1
  39. package/dist/cjs/hooks/use-export-range.d.ts +12 -1
  40. package/dist/cjs/hooks/use-export-range.d.ts.map +1 -1
  41. package/dist/cjs/hooks/use-export-range.js +75 -35
  42. package/dist/cjs/hooks/use-flash-fill-suggestion.d.ts.map +1 -1
  43. package/dist/cjs/hooks/use-flash-fill-suggestion.js +15 -4
  44. package/dist/cjs/hooks/use-grid-children.d.ts +27 -2
  45. package/dist/cjs/hooks/use-grid-children.d.ts.map +1 -1
  46. package/dist/cjs/hooks/use-grid-children.js +61 -21
  47. package/dist/cjs/hooks/use-header-actions.d.ts +3 -1
  48. package/dist/cjs/hooks/use-header-actions.d.ts.map +1 -1
  49. package/dist/cjs/hooks/use-header-actions.js +5 -4
  50. package/dist/cjs/hooks/use-hidden-dimension-markers.d.ts +7 -1
  51. package/dist/cjs/hooks/use-hidden-dimension-markers.d.ts.map +1 -1
  52. package/dist/cjs/hooks/use-hidden-dimension-markers.js +9 -5
  53. package/dist/cjs/hooks/use-selection-interceptors.d.ts +7 -1
  54. package/dist/cjs/hooks/use-selection-interceptors.d.ts.map +1 -1
  55. package/dist/cjs/hooks/use-selection-interceptors.js +5 -3
  56. package/dist/cjs/hooks/use-selection-renderer.d.ts.map +1 -1
  57. package/dist/cjs/hooks/use-selection-renderer.js +18 -4
  58. package/dist/cjs/hooks/use-sizer.d.ts +9 -1
  59. package/dist/cjs/hooks/use-sizer.d.ts.map +1 -1
  60. package/dist/cjs/hooks/use-sizer.js +5 -3
  61. package/dist/cjs/release-date.js +1 -1
  62. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  63. package/dist/cjs/types.d.ts +24 -0
  64. package/dist/cjs/types.d.ts.map +1 -1
  65. package/dist/esm/api/editor-formula.d.ts +40 -0
  66. package/dist/esm/api/editor-formula.d.ts.map +1 -0
  67. package/dist/esm/api/editor-formula.js +76 -0
  68. package/dist/esm/atoms/cell-input-context.atom.d.ts.map +1 -1
  69. package/dist/esm/components/autocorrect-options-smart-tag/index.d.ts +22 -8
  70. package/dist/esm/components/autocorrect-options-smart-tag/index.d.ts.map +1 -1
  71. package/dist/esm/components/autocorrect-options-smart-tag/index.js +103 -22
  72. package/dist/esm/components/canvas-grid/frozen-start.d.ts +130 -0
  73. package/dist/esm/components/canvas-grid/frozen-start.d.ts.map +1 -0
  74. package/dist/esm/components/canvas-grid/frozen-start.js +222 -0
  75. package/dist/esm/components/canvas-grid/index.d.ts.map +1 -1
  76. package/dist/esm/components/canvas-grid/index.js +439 -20
  77. package/dist/esm/components/canvas-grid/typings.d.ts +24 -8
  78. package/dist/esm/components/canvas-grid/typings.d.ts.map +1 -1
  79. package/dist/esm/components/cell-input/cell-input.d.ts.map +1 -1
  80. package/dist/esm/components/cell-input/cell-input.js +4 -2
  81. package/dist/esm/components/embeds/embed-draggable.d.ts.map +1 -1
  82. package/dist/esm/components/embeds/embed-draggable.js +34 -14
  83. package/dist/esm/components/embeds/object-cell-offset.d.ts +10 -0
  84. package/dist/esm/components/embeds/object-cell-offset.d.ts.map +1 -0
  85. package/dist/esm/components/embeds/object-cell-offset.js +9 -0
  86. package/dist/esm/components/embeds/object-focus.d.ts +16 -3
  87. package/dist/esm/components/embeds/object-focus.d.ts.map +1 -1
  88. package/dist/esm/components/embeds/object-focus.js +38 -2
  89. package/dist/esm/components/outline-gutter/index.d.ts +11 -3
  90. package/dist/esm/components/outline-gutter/index.d.ts.map +1 -1
  91. package/dist/esm/components/outline-gutter/index.js +11 -6
  92. package/dist/esm/components/selection/index.d.ts +1 -1
  93. package/dist/esm/components/selection/index.d.ts.map +1 -1
  94. package/dist/esm/components/selection/index.js +2 -2
  95. package/dist/esm/components/selection/types.d.ts +2 -0
  96. package/dist/esm/components/selection/types.d.ts.map +1 -1
  97. package/dist/esm/hooks/object-spec-schema.generated.d.ts.map +1 -1
  98. package/dist/esm/hooks/object-spec-schema.generated.js +16 -0
  99. package/dist/esm/hooks/use-editable.d.ts.map +1 -1
  100. package/dist/esm/hooks/use-editable.js +6 -2
  101. package/dist/esm/hooks/use-editor-change.d.ts.map +1 -1
  102. package/dist/esm/hooks/use-editor-change.js +4 -2
  103. package/dist/esm/hooks/use-export-range.d.ts +12 -1
  104. package/dist/esm/hooks/use-export-range.d.ts.map +1 -1
  105. package/dist/esm/hooks/use-export-range.js +31 -4
  106. package/dist/esm/hooks/use-flash-fill-suggestion.d.ts.map +1 -1
  107. package/dist/esm/hooks/use-flash-fill-suggestion.js +15 -4
  108. package/dist/esm/hooks/use-grid-children.d.ts +27 -2
  109. package/dist/esm/hooks/use-grid-children.d.ts.map +1 -1
  110. package/dist/esm/hooks/use-grid-children.js +53 -16
  111. package/dist/esm/hooks/use-header-actions.d.ts +3 -1
  112. package/dist/esm/hooks/use-header-actions.d.ts.map +1 -1
  113. package/dist/esm/hooks/use-header-actions.js +3 -2
  114. package/dist/esm/hooks/use-hidden-dimension-markers.d.ts +7 -1
  115. package/dist/esm/hooks/use-hidden-dimension-markers.d.ts.map +1 -1
  116. package/dist/esm/hooks/use-hidden-dimension-markers.js +7 -3
  117. package/dist/esm/hooks/use-selection-interceptors.d.ts +7 -1
  118. package/dist/esm/hooks/use-selection-interceptors.d.ts.map +1 -1
  119. package/dist/esm/hooks/use-selection-interceptors.js +5 -3
  120. package/dist/esm/hooks/use-selection-renderer.d.ts.map +1 -1
  121. package/dist/esm/hooks/use-selection-renderer.js +18 -4
  122. package/dist/esm/hooks/use-sizer.d.ts +9 -1
  123. package/dist/esm/hooks/use-sizer.d.ts.map +1 -1
  124. package/dist/esm/hooks/use-sizer.js +5 -3
  125. package/dist/esm/release-date.js +1 -1
  126. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  127. package/dist/esm/types.d.ts +24 -0
  128. package/dist/esm/types.d.ts.map +1 -1
  129. package/dist/spreadsheet.min.css +1 -1
  130. package/package.json +3 -3
@@ -0,0 +1,130 @@
1
+ import type { CellInterface, CellPosition, ItemSizeHint } from "@rowsncolumns/grid";
2
+ /**
3
+ * A sheet frozen while scrolled (demo-app-monorepo#57258 W-5): Excel's Freeze Panes on a sheet
4
+ * scrolled to row 40 freezes from row 40, and rows 1 … 39 stay out of view above the frozen band
5
+ * (`<sheetView topLeftCell>` of a frozen view, stored as `frozenRowStart` / `frozenColumnStart`).
6
+ *
7
+ * The grid draws this with two things only: the rows / columns above the start get NO SIZE in what
8
+ * the grid lays out, and the grid's frozen count covers them (`start − 1 + count`). Everything that
9
+ * is not layout (copy, paste, fill, sort, filters, Find, auto-fit, export, print, the stored sizes)
10
+ * keeps reading the sheet's own sizes and sees those rows as ordinary rows. With no start (or a
11
+ * start of 1) every helper here hands back what it was given, so nothing changes.
12
+ */
13
+ /**
14
+ * How many rows (or columns) sit above the frozen start: `start − 1`, or 0 when there is no start,
15
+ * the start is 1, nothing is frozen on that axis, or the frozen area would run past the sheet (the
16
+ * engine does not store such a start; a hand-edited document is drawn as if it had none).
17
+ */
18
+ export declare const linesAboveFrozenStart: (start: number | null | undefined, frozenCount: number | null | undefined, lineCount: number) => number;
19
+ /** Whether a grid row / column index (1-based sheet line) lies above the frozen start. */
20
+ export declare const isAboveFrozenStart: (index: number, linesAbove: number) => boolean;
21
+ /** The grid's size function: lines above the start have no size. The same function without a start. */
22
+ export declare const sizeAboveFrozenStartZero: (size: (index: number) => number, linesAbove: number) => ((index: number) => number);
23
+ type Range = {
24
+ start: number;
25
+ end: number;
26
+ };
27
+ /**
28
+ * The grid's visible row ranges without the rows above the start: the grid treats rows outside
29
+ * them as having no height (its size-hint path never asks their size). The same array without a
30
+ * start.
31
+ */
32
+ export declare const rangesWithoutLinesAboveFrozenStart: <T extends Range>(ranges: T[], linesAbove: number) => T[];
33
+ /**
34
+ * The grid's column size hint with the columns above the start listed as exceptions (the grid then
35
+ * asks their size, which is 0). At most 16,383 columns; the same hint without a start.
36
+ */
37
+ export declare const sizeHintWithLinesAboveFrozenStart: (hint: ItemSizeHint, linesAbove: number) => ItemSizeHint;
38
+ /**
39
+ * The sum of the sheet's own (unscaled) sizes of lines `from … to`, measured the way the grid's
40
+ * size hint describes them: `defaultSize` for every line between exceptions, `size(e)` for an
41
+ * exception, 0 for a line outside `visibleRanges` (rows hidden by a filter). O(exceptions and ranges
42
+ * in the span), whatever its length, so a start at row 1,000,000 costs no more than one at row 40.
43
+ */
44
+ export declare const sumLineSizes: ({ from, to, size, hint, visibleRanges, }: {
45
+ from: number;
46
+ to: number;
47
+ size: (index: number) => number;
48
+ hint: ItemSizeHint;
49
+ visibleRanges?: Range[];
50
+ }) => number;
51
+ /**
52
+ * Where an OBJECT lays out a cell (charts, pictures, slicers): the grid's own answer, except for a
53
+ * cell above the frozen start, which is placed where it would be if those lines kept their size:
54
+ * that far above the first frozen line. An object anchored there is then drawn cut at the top of
55
+ * the frozen band (or not at all, when it lies wholly above), never squashed onto the band's edge.
56
+ * `distanceAbove(axis, index)` is the scaled distance from the line's top / left edge to the start.
57
+ */
58
+ export declare const objectCellOffsetAboveFrozenStart: ({ getCellOffsetFromCoords, rowsAbove, columnsAbove, rowSize, columnSize, distanceAbove, }: {
59
+ getCellOffsetFromCoords: (cell: CellInterface) => CellPosition | undefined;
60
+ rowsAbove: number;
61
+ columnsAbove: number;
62
+ /** Scaled size of one line, as the sheet stores it. */
63
+ rowSize: (index: number) => number;
64
+ columnSize: (index: number) => number;
65
+ distanceAbove: (axis: "row" | "column", index: number) => number;
66
+ }) => (cell: CellInterface) => CellPosition | undefined;
67
+ /**
68
+ * Freeze Panes up to a line ("Freeze up to Row 45"): Excel freezes from the top line on screen,
69
+ * `firstShown`, so the count is measured from there and the start is sent when it is not line 1. A
70
+ * line above `firstShown` (reached with the keyboard on a sheet frozen from a start) freezes from
71
+ * line 1. 0 unfreezes, and an unfreeze carries no start.
72
+ */
73
+ export declare const freezeUpTo: (line: number, firstShown: number) => {
74
+ count: number;
75
+ start?: number;
76
+ };
77
+ /** One axis of a frozen area as the grid lays it out: lines above the start, frozen lines. */
78
+ export type FrozenAxis = {
79
+ lines: number;
80
+ count: number;
81
+ };
82
+ /** A freeze or unfreeze this window sent and has not seen arrive yet. */
83
+ export type PendingFreeze = {
84
+ expected: FrozenAxis;
85
+ scrollBefore: number;
86
+ };
87
+ /** The last freeze or unfreeze from a start this window made: its undo and redo are this window's. */
88
+ export type LocalFreeze = {
89
+ before: FrozenAxis;
90
+ after: FrozenAxis;
91
+ scrollBefore: number;
92
+ };
93
+ /** Where the view was on one axis before a frozen area changed, read in the old layout. */
94
+ export type FrozenViewSnapshot = {
95
+ /** The first scrolling line on screen. */
96
+ topLine: number;
97
+ /** How far into it the view was scrolled (px). */
98
+ intoLine: number;
99
+ };
100
+ /**
101
+ * Where one axis of the view goes when its frozen area changes and a start is involved
102
+ * (demo-app-monorepo#57258 W-5). `undefined` = leave the scroll position as it is (every change
103
+ * without a start, as before).
104
+ *
105
+ * - **A freeze or unfreeze this window sent** (`pending`, matched by the area it asked for): freezing
106
+ * from a start puts the scrolling area right below the band (0); unfreezing keeps the start's line
107
+ * first on screen. This window's next undo / redo of it is remembered (`local`).
108
+ * - **This window's undo of that change** (the area goes back from `local.after` to `local.before`):
109
+ * back where the window was before the change. Its redo: as the change itself.
110
+ * - **Anything else** (another window's freeze, unfreeze, undo or redo): the same line stays first on
111
+ * screen, at the same depth; the scroll moves by the band's change. When that line now lies in the
112
+ * band or above the start it cannot stay: the view lands on the first scrolling line (0).
113
+ *
114
+ * `offset(index)` is a line's offset in the NEW layout; scroll positions are measured from the first
115
+ * scrolling line, as the grid's are.
116
+ */
117
+ export declare const frozenStartScroll: ({ before, after, pending, local, snapshot, offset, }: {
118
+ before: FrozenAxis;
119
+ after: FrozenAxis;
120
+ pending?: PendingFreeze;
121
+ local?: LocalFreeze;
122
+ snapshot?: FrozenViewSnapshot;
123
+ offset: (index: number) => number;
124
+ }) => {
125
+ scroll?: number;
126
+ consumed: boolean;
127
+ local?: LocalFreeze;
128
+ };
129
+ export {};
130
+ //# sourceMappingURL=frozen-start.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frozen-start.d.ts","sourceRoot":"","sources":["../../../../components/canvas-grid/frozen-start.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,222 @@
1
+ /**
2
+ * A sheet frozen while scrolled (demo-app-monorepo#57258 W-5): Excel's Freeze Panes on a sheet
3
+ * scrolled to row 40 freezes from row 40, and rows 1 … 39 stay out of view above the frozen band
4
+ * (`<sheetView topLeftCell>` of a frozen view, stored as `frozenRowStart` / `frozenColumnStart`).
5
+ *
6
+ * The grid draws this with two things only: the rows / columns above the start get NO SIZE in what
7
+ * the grid lays out, and the grid's frozen count covers them (`start − 1 + count`). Everything that
8
+ * is not layout (copy, paste, fill, sort, filters, Find, auto-fit, export, print, the stored sizes)
9
+ * keeps reading the sheet's own sizes and sees those rows as ordinary rows. With no start (or a
10
+ * start of 1) every helper here hands back what it was given, so nothing changes.
11
+ */
12
+ /**
13
+ * How many rows (or columns) sit above the frozen start: `start − 1`, or 0 when there is no start,
14
+ * the start is 1, nothing is frozen on that axis, or the frozen area would run past the sheet (the
15
+ * engine does not store such a start; a hand-edited document is drawn as if it had none).
16
+ */
17
+ export const linesAboveFrozenStart = (start, frozenCount, lineCount) => {
18
+ const count = Math.floor(Number(frozenCount ?? 0));
19
+ if (!Number.isFinite(count) || count <= 0)
20
+ return 0;
21
+ const first = Math.floor(Number(start ?? 1));
22
+ if (!Number.isFinite(first) || first <= 1)
23
+ return 0;
24
+ if (first - 1 + count > lineCount)
25
+ return 0;
26
+ return first - 1;
27
+ };
28
+ /** Whether a grid row / column index (1-based sheet line) lies above the frozen start. */
29
+ export const isAboveFrozenStart = (index, linesAbove) => linesAbove > 0 && index >= 1 && index <= linesAbove;
30
+ /** The grid's size function: lines above the start have no size. The same function without a start. */
31
+ export const sizeAboveFrozenStartZero = (size, linesAbove) => linesAbove > 0
32
+ ? (index) => (isAboveFrozenStart(index, linesAbove) ? 0 : size(index))
33
+ : size;
34
+ /**
35
+ * The grid's visible row ranges without the rows above the start: the grid treats rows outside
36
+ * them as having no height (its size-hint path never asks their size). The same array without a
37
+ * start.
38
+ */
39
+ export const rangesWithoutLinesAboveFrozenStart = (ranges, linesAbove) => {
40
+ if (linesAbove <= 0)
41
+ return ranges;
42
+ const next = [];
43
+ for (const range of ranges) {
44
+ if (range.end < 1 || range.start > linesAbove) {
45
+ next.push(range);
46
+ continue;
47
+ }
48
+ if (range.start < 1)
49
+ next.push({ ...range, end: 0 });
50
+ if (range.end > linesAbove)
51
+ next.push({ ...range, start: linesAbove + 1 });
52
+ }
53
+ return next;
54
+ };
55
+ /**
56
+ * The grid's column size hint with the columns above the start listed as exceptions (the grid then
57
+ * asks their size, which is 0). At most 16,383 columns; the same hint without a start.
58
+ */
59
+ export const sizeHintWithLinesAboveFrozenStart = (hint, linesAbove) => {
60
+ if (linesAbove <= 0)
61
+ return hint;
62
+ const { exceptions } = hint;
63
+ const merged = [];
64
+ for (let i = 1; i <= linesAbove; i++)
65
+ merged.push(i);
66
+ for (let i = 0; i < exceptions.length; i++) {
67
+ if (exceptions[i] < 1 || exceptions[i] > linesAbove)
68
+ merged.push(exceptions[i]);
69
+ }
70
+ merged.sort((a, b) => a - b);
71
+ return { defaultSize: hint.defaultSize, exceptions: merged };
72
+ };
73
+ /**
74
+ * The sum of the sheet's own (unscaled) sizes of lines `from … to`, measured the way the grid's
75
+ * size hint describes them: `defaultSize` for every line between exceptions, `size(e)` for an
76
+ * exception, 0 for a line outside `visibleRanges` (rows hidden by a filter). O(exceptions and ranges
77
+ * in the span), whatever its length, so a start at row 1,000,000 costs no more than one at row 40.
78
+ */
79
+ export const sumLineSizes = ({ from, to, size, hint, visibleRanges, }) => {
80
+ if (to < from)
81
+ return 0;
82
+ const { exceptions, defaultSize } = hint;
83
+ const isVisible = (index) => {
84
+ if (!visibleRanges)
85
+ return true;
86
+ let low = 0;
87
+ let high = visibleRanges.length - 1;
88
+ while (low <= high) {
89
+ const middle = (low + high) >> 1;
90
+ const range = visibleRanges[middle];
91
+ if (index < range.start)
92
+ high = middle - 1;
93
+ else if (index > range.end)
94
+ low = middle + 1;
95
+ else
96
+ return true;
97
+ }
98
+ return false;
99
+ };
100
+ let visibleCount = 0;
101
+ if (visibleRanges) {
102
+ for (const range of visibleRanges) {
103
+ const start = Math.max(range.start, from);
104
+ const end = Math.min(range.end, to);
105
+ if (end >= start)
106
+ visibleCount += end - start + 1;
107
+ }
108
+ }
109
+ else {
110
+ visibleCount = to - from + 1;
111
+ }
112
+ let total = visibleCount * defaultSize;
113
+ let low = 0;
114
+ let high = exceptions.length;
115
+ while (low < high) {
116
+ const middle = (low + high) >> 1;
117
+ if (exceptions[middle] < from)
118
+ low = middle + 1;
119
+ else
120
+ high = middle;
121
+ }
122
+ for (let i = low; i < exceptions.length && exceptions[i] <= to; i++) {
123
+ const index = exceptions[i];
124
+ total += size(index) - (isVisible(index) ? defaultSize : 0);
125
+ }
126
+ return total;
127
+ };
128
+ /**
129
+ * Where an OBJECT lays out a cell (charts, pictures, slicers): the grid's own answer, except for a
130
+ * cell above the frozen start, which is placed where it would be if those lines kept their size:
131
+ * that far above the first frozen line. An object anchored there is then drawn cut at the top of
132
+ * the frozen band (or not at all, when it lies wholly above), never squashed onto the band's edge.
133
+ * `distanceAbove(axis, index)` is the scaled distance from the line's top / left edge to the start.
134
+ */
135
+ export const objectCellOffsetAboveFrozenStart = ({ getCellOffsetFromCoords, rowsAbove, columnsAbove, rowSize, columnSize, distanceAbove, }) => {
136
+ if (rowsAbove <= 0 && columnsAbove <= 0)
137
+ return getCellOffsetFromCoords;
138
+ return (cell) => {
139
+ const rowAbove = isAboveFrozenStart(cell.rowIndex, rowsAbove);
140
+ const columnAbove = isAboveFrozenStart(cell.columnIndex, columnsAbove);
141
+ if (!rowAbove && !columnAbove)
142
+ return getCellOffsetFromCoords(cell);
143
+ const own = getCellOffsetFromCoords({
144
+ rowIndex: rowAbove ? rowsAbove + 1 : cell.rowIndex,
145
+ columnIndex: columnAbove ? columnsAbove + 1 : cell.columnIndex,
146
+ });
147
+ if (!own)
148
+ return own;
149
+ return {
150
+ x: columnAbove ? own.x - distanceAbove("column", cell.columnIndex) : own.x,
151
+ y: rowAbove ? own.y - distanceAbove("row", cell.rowIndex) : own.y,
152
+ width: columnAbove ? columnSize(cell.columnIndex) : own.width,
153
+ height: rowAbove ? rowSize(cell.rowIndex) : own.height,
154
+ };
155
+ };
156
+ };
157
+ /**
158
+ * Freeze Panes up to a line ("Freeze up to Row 45"): Excel freezes from the top line on screen,
159
+ * `firstShown`, so the count is measured from there and the start is sent when it is not line 1. A
160
+ * line above `firstShown` (reached with the keyboard on a sheet frozen from a start) freezes from
161
+ * line 1. 0 unfreezes, and an unfreeze carries no start.
162
+ */
163
+ export const freezeUpTo = (line, firstShown) => {
164
+ if (line <= 0)
165
+ return { count: 0 };
166
+ const start = firstShown > 1 && firstShown <= line ? firstShown : 1;
167
+ return start > 1 ? { count: line - start + 1, start } : { count: line };
168
+ };
169
+ const sameAxis = (a, b) => a.lines === b.lines && a.count === b.count;
170
+ /**
171
+ * Where one axis of the view goes when its frozen area changes and a start is involved
172
+ * (demo-app-monorepo#57258 W-5). `undefined` = leave the scroll position as it is (every change
173
+ * without a start, as before).
174
+ *
175
+ * - **A freeze or unfreeze this window sent** (`pending`, matched by the area it asked for): freezing
176
+ * from a start puts the scrolling area right below the band (0); unfreezing keeps the start's line
177
+ * first on screen. This window's next undo / redo of it is remembered (`local`).
178
+ * - **This window's undo of that change** (the area goes back from `local.after` to `local.before`):
179
+ * back where the window was before the change. Its redo: as the change itself.
180
+ * - **Anything else** (another window's freeze, unfreeze, undo or redo): the same line stays first on
181
+ * screen, at the same depth; the scroll moves by the band's change. When that line now lies in the
182
+ * band or above the start it cannot stay: the view lands on the first scrolling line (0).
183
+ *
184
+ * `offset(index)` is a line's offset in the NEW layout; scroll positions are measured from the first
185
+ * scrolling line, as the grid's are.
186
+ */
187
+ export const frozenStartScroll = ({ before, after, pending, local, snapshot, offset, }) => {
188
+ if (sameAxis(before, after))
189
+ return { consumed: false, local };
190
+ const withStart = before.lines > 0 || after.lines > 0;
191
+ const firstScrolling = 1 + after.lines + after.count;
192
+ const asSent = () => {
193
+ if (after.lines > 0)
194
+ return 0;
195
+ if (before.lines > 0 && after.lines === 0 && after.count === 0) {
196
+ return Math.max(0, offset(before.lines + 1) - offset(1));
197
+ }
198
+ return undefined;
199
+ };
200
+ if (pending && sameAxis(after, pending.expected)) {
201
+ return {
202
+ scroll: asSent(),
203
+ consumed: true,
204
+ local: withStart ? { before, after, scrollBefore: pending.scrollBefore } : undefined,
205
+ };
206
+ }
207
+ if (local && sameAxis(before, local.after) && sameAxis(after, local.before)) {
208
+ return { scroll: local.scrollBefore, consumed: false, local };
209
+ }
210
+ if (local && sameAxis(before, local.before) && sameAxis(after, local.after)) {
211
+ return { scroll: asSent(), consumed: false, local };
212
+ }
213
+ if (!withStart || !snapshot)
214
+ return { consumed: false, local };
215
+ if (snapshot.topLine < firstScrolling)
216
+ return { scroll: 0, consumed: false, local };
217
+ return {
218
+ scroll: Math.max(0, offset(snapshot.topLine) + snapshot.intoLine - offset(firstScrolling)),
219
+ consumed: false,
220
+ local,
221
+ };
222
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/canvas-grid/index.tsx"],"names":[],"mappings":"AAqEA,OAAO,KASN,MAAM,OAAO,CAAC;AA6Qf,OAAO,KAAK,EAGV,QAAQ,EAYT,MAAM,aAAa,CAAC;AA4CrB,OAAO,KAAK,EACV,wBAAwB,EACxB,iBAAiB,EACjB,eAAe,EAEhB,MAAM,WAAW,CAAC;AAmkPnB,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;AAqRf,OAAO,KAAK,EAGV,QAAQ,EAcT,MAAM,aAAa,CAAC;AA0DrB,OAAO,KAAK,EACV,wBAAwB,EACxB,iBAAiB,EACjB,eAAe,EAEhB,MAAM,WAAW,CAAC;AA4mQnB,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"}