@sheetxl/grid-react 0.7.28-beta.4 → 0.8.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/browser/cjs/index.cjs +3 -3
  2. package/browser/esm/index.mjs +2052 -1487
  3. package/licenses/dependencies.txt +35 -1
  4. package/node/esm/index.mjs +1662 -1108
  5. package/package.json +3 -3
  6. package/types/src/cell/CellRenderer.d.ts +14 -3
  7. package/types/src/editor/DefaultEditable.d.ts +9 -0
  8. package/types/src/editor/EditSession.d.ts +6 -0
  9. package/types/src/editor/EditState.d.ts +6 -0
  10. package/types/src/editor/EditorInput.d.ts +2 -1
  11. package/types/src/editor/useEditorKeymap.d.ts +11 -0
  12. package/types/src/header/useHeaderSelectionPointer.d.ts +6 -2
  13. package/types/src/layer/GridFloatPanel.d.ts +18 -0
  14. package/types/src/layer/HoverTipLayer.d.ts +20 -47
  15. package/types/src/layer/RangeFloatLayer.d.ts +146 -0
  16. package/types/src/layer/StickyAnchor.d.ts +2 -4
  17. package/types/src/layer/StickyFloat.d.ts +4 -1
  18. package/types/src/layer/index.d.ts +3 -1
  19. package/types/src/layer/useGridAnchor.d.ts +23 -6
  20. package/types/src/layer/useRangeHover.d.ts +5 -4
  21. package/types/src/list/CheckboxList.d.ts +11 -0
  22. package/types/src/list/List.d.ts +14 -5
  23. package/types/src/list/ListSearch.d.ts +31 -0
  24. package/types/src/list/ListSurface.d.ts +93 -0
  25. package/types/src/list/PickList.d.ts +71 -0
  26. package/types/src/list/_measureText.d.ts +14 -0
  27. package/types/src/list/index.d.ts +3 -0
  28. package/types/src/range/DragHandle.d.ts +14 -0
  29. package/types/src/range/Draggable.d.ts +111 -6
  30. package/types/src/range/FillHandle.d.ts +28 -1
  31. package/types/src/range/RangeInsertBar.d.ts +91 -0
  32. package/types/src/range/index.d.ts +2 -0
  33. package/types/src/selection/SelectionLayer.d.ts +91 -9
  34. package/types/src/selection/SelectionStyle.d.ts +30 -0
  35. package/types/src/selection/useDragCells.d.ts +36 -0
@@ -1,11 +1,11 @@
1
1
  import { default as React } from 'react';
2
- import { CellCoords, RangeCoords } from '@sheetxl/utils';
2
+ import { RangeAxis, CellCoords, RangeCoords } from '@sheetxl/utils';
3
3
  import { LayerProps, GridPlacement } from '../layer';
4
4
  import { VisualSVGProps } from '../svg';
5
5
  import { RangeEdge } from '../range';
6
6
  import { ISelection } from './ISelection';
7
7
  import { SelectionNavigation } from './Types';
8
- import { SelectionRangeStyle } from './SelectionStyle';
8
+ import { SelectionRangeStyle, InsertBarStyle } from './SelectionStyle';
9
9
  /**
10
10
  * The in-flight selection gesture passed to {@link SelectionLayerProps.renderTip}:
11
11
  * - `select` — a drag-select growing the active range (Excel's live R×C);
@@ -19,11 +19,43 @@ export type SelectionGesture = {
19
19
  kind: 'move';
20
20
  from: RangeCoords;
21
21
  to: RangeCoords;
22
+ drop: MoveDrop;
22
23
  } | {
23
24
  kind: 'fill';
24
25
  template: RangeCoords;
25
26
  destination: RangeCoords;
26
27
  };
28
+ /**
29
+ * What a move drag would DO if released now — the destination plus the mode its modifiers select.
30
+ * Excel's three grip gestures, as data: drag relocates, Ctrl+drag copies, Shift+drag inserts (and
31
+ * Ctrl+Shift inserts a copy).
32
+ *
33
+ * @remarks
34
+ * The mode lives here rather than being re-derived from a pointer event by each consumer, because the
35
+ * modifiers change with the pointer standing still — see {@link DragMoveInfo}.
36
+ */
37
+ export interface MoveDrop {
38
+ /**
39
+ * Where the block lands. For an insert this is the block RE-ANCHORED on the pointer's cell, not the
40
+ * drag's translation — take the destination from here rather than re-deriving it.
41
+ */
42
+ to: RangeCoords;
43
+ /** Ctrl / Cmd is held: the source is copied rather than cut. */
44
+ copy: boolean;
45
+ /**
46
+ * Shift is held: INSERT at {@link MoveDrop.to} instead of dropping over it — the cells already there
47
+ * step aside along this axis (`Row` = down, `Column` = right), which is also the edge of `to` the
48
+ * I-beam is drawn on. Absent for a plain overwrite drop.
49
+ */
50
+ insert?: RangeAxis;
51
+ /**
52
+ * The drop cannot be performed and a release does nothing: a cut INSERT whose line falls inside the
53
+ * block being dragged, or one that would shift only part of it (see `CoordUtils.classifyInsertCut`
54
+ * - the same call the model makes, so a beam drawn as legal is one the model will accept). The
55
+ * preview draws the I-beam in the refused color instead, and `onMove` never fires.
56
+ */
57
+ refused?: boolean;
58
+ }
27
59
  /**
28
60
  * Props for {@link SelectionLayer}.
29
61
  */
@@ -41,7 +73,7 @@ export interface SelectionLayerProps extends LayerProps {
41
73
  getContentBounds?: () => RangeCoords;
42
74
  /**
43
75
  * The bounding REGION enclosing a cell — a table's data range from a tier that knows tables (the sheet
44
- * layer), else `null` (the bare sheet). Drives Tab/Enter wrapping inside a table and the row/column
76
+ * layer), else `null` (the bare sheet). Drives Tab wrapping inside a table and the row/column
45
77
  * span of Ctrl/Shift+Space. Omit it (the dumb {@link DefaultSelection} tier) and there is no enclosing
46
78
  * region: Tab is a plain move and Ctrl/Shift+Space select the whole grid. The layer never learns it's a
47
79
  * sheet — just a `cell → bounds | null` getter; any escalation lives in the provider.
@@ -70,6 +102,25 @@ export interface SelectionLayerProps extends LayerProps {
70
102
  singleAnchorStyle?: VisualSVGProps;
71
103
  /** The Ctrl/Cmd-drag remove rubber-band. Merged (slot-by-slot) over {@link DEFAULT_REMOVE_PREVIEW_STYLE}. */
72
104
  removePreviewStyle?: SelectionRangeStyle;
105
+ /** The Shift-drag insert I-beam. Merged over {@link DEFAULT_INSERT_BAR_STYLE}. */
106
+ insertBarStyle?: InsertBarStyle;
107
+ /**
108
+ * Whether a drop would be REFUSED - drawn as a refused I-beam, and inert on release. Defaults to
109
+ * the geometry a grid can see on its own (`CoordUtils.classifyInsertCut`: a cut whose gap the
110
+ * insert would only half close, or a line dropped inside the block itself).
111
+ *
112
+ * @remarks
113
+ * A model knows more than the grid does - a merge the shift would tear, a table it would split -
114
+ * so a host that has one should answer from it (`ICellRange.canInsertFrom`), which is what keeps
115
+ * the beam honest about drops the grid could not have ruled out.
116
+ */
117
+ isDropRefused?: (from: RangeCoords, drop: MoveDrop) => boolean;
118
+ /**
119
+ * The mute drawn over the source while a **cut** (plain) move drag is in flight — see
120
+ * {@link DEFAULT_MOVE_SOURCE_STYLE}, which it merges over. `null` draws no mute, leaving the cursor
121
+ * as the only cut-vs-copy tell.
122
+ */
123
+ moveSourceStyle?: SelectionRangeStyle | null;
73
124
  /**
74
125
  * Stacked layers (fill, move, …) rendered when a single range is selected.
75
126
  */
@@ -86,21 +137,33 @@ export interface SelectionLayerProps extends LayerProps {
86
137
  enabledMove?: boolean;
87
138
  /**
88
139
  * Called when the single range is moved by its border — `from` is the original range, `to` the new
89
- * one. The selection follows automatically; use this for the data side-effect (cut-move).
140
+ * one (`drop.to`, snapped when inserting). The selection follows automatically; use this for the data
141
+ * side-effect, which `drop` describes: a cut-move, a copy, or an insert along `drop.insert`.
90
142
  */
91
- onMove?: (from: RangeCoords, to: RangeCoords, e: React.PointerEvent) => void;
143
+ onMove?: (from: RangeCoords, to: RangeCoords, e: React.PointerEvent, drop: MoveDrop) => void;
92
144
  /** The move drag started (before any translation) — `from` is the range being moved. */
93
- onMoveStart?: (from: RangeCoords, e: React.PointerEvent) => void;
145
+ onMoveStart?: (from: RangeCoords, e: React.PointerEvent, drop: MoveDrop) => void;
94
146
  /**
95
- * Live during the move drag — `to` is the in-flight translated range. `e` carries the current
96
- * modifiers (Ctrl = copy, Shift = insert), so a consumer can reflect the mode (cursor/description).
147
+ * Live during the move drag — `to` is the in-flight destination and `drop` what a release would do.
148
+ * Fires on every change, INCLUDING a modifier pressed or released with the pointer standing still
149
+ * (that is the whole point: the mode must be reflected — cursor, status description — the instant
150
+ * the key goes down). Take the mode from `drop`; `e` is merely the last pointer event.
97
151
  */
98
- onMoveUpdate?: (from: RangeCoords, to: RangeCoords, e: React.PointerEvent) => void;
152
+ onMoveUpdate?: (from: RangeCoords, to: RangeCoords, e: React.PointerEvent, drop: MoveDrop) => void;
99
153
  /**
100
154
  * The move drag ended (fires on release regardless of whether the range actually moved) — for teardown
101
155
  * of anything {@link SelectionLayerProps.onMoveStart}/`onMoveUpdate` set (e.g. clearing a drag mode).
102
156
  */
103
157
  onMoveEnd?: () => void;
158
+ /**
159
+ * The cursor to paint while the move grip is dragged — pass one derived from the live
160
+ * {@link MoveDrop} (`copy` while Ctrl is held, say) to show the drop mode under the pointer. The
161
+ * grip is pointer-captured for the duration, so this is the cursor the browser shows anywhere on
162
+ * screen, and it is the only place a mode cursor can come from during the drag.
163
+ *
164
+ * @defaultValue 'grabbing'
165
+ */
166
+ moveCursor?: string;
104
167
  /**
105
168
  * Enable the built-in fill handle on a single range (the Excel fill square at the bottom-right
106
169
  * corner; drag to fill). Opt-in (unlike the always-on move grip) because it adds a visible handle.
@@ -133,6 +196,17 @@ export interface SelectionLayerProps extends LayerProps {
133
196
  * anything {@link SelectionLayerProps.onFillPreview} set (e.g. closing the preview tooltip).
134
197
  */
135
198
  onFillEnd?: () => void;
199
+ /**
200
+ * A **right-button** fill drag was released — Excel's right-drag of the fill handle, which offers a
201
+ * menu of fills at the pointer instead of filling. Fires INSTEAD of {@link SelectionLayerProps.onFill}
202
+ * for that gesture, and the selection is NOT extended: nothing has been decided yet, so the consumer
203
+ * extends it (or not) once a menu entry is chosen. Supplying it is what enables the right-button drag;
204
+ * left-drag is untouched.
205
+ *
206
+ * The dashed fill preview stays up while the menu decides; call `done` once it has answered or closed
207
+ * without answering, and the preview clears.
208
+ */
209
+ onFillMenu?: (template: RangeCoords, destination: RangeCoords, e: React.PointerEvent, done: () => void) => void;
136
210
  /**
137
211
  * Resolve the destination for a **double-clicked** fill handle — Excel's "ride the rails" fill,
138
212
  * whose extent comes from the data flanking the template rather than from a drag. Return the
@@ -154,6 +228,14 @@ export interface SelectionLayerProps extends LayerProps {
154
228
  * {@link SelectionPointerOptions.onSelectionEnd}.
155
229
  */
156
230
  onSelectionEnd?: (e: React.PointerEvent) => void;
231
+ /**
232
+ * The pointer drag-select started (`'extend'` / `'remove'`) or ended (`null`) — for reflecting an
233
+ * in-flight selection somewhere this layer's own {@link SelectionLayerProps.renderTip} can't reach
234
+ * (the name box's live `nR x nC`). Read off the drag engine rather than a start/end callback pair,
235
+ * so it is balanced by construction: the `null` also arrives for an aborted drag (Escape /
236
+ * `pointercancel`), which never reaches a release.
237
+ */
238
+ onDragModeChange?: (dragMode: 'extend' | 'remove' | null) => void;
157
239
  /**
158
240
  * Render a transient tip during a gesture — a drag-select ({@link SelectionGesture} `select`, live
159
241
  * R×C), a move (`move`, the destination address), or a fill (`fill`, the preview). Return a falsy node
@@ -25,4 +25,34 @@ export declare const DEFAULT_MULTI_STYLE: SelectionRangeStyle;
25
25
  export declare const DEFAULT_ANCHOR_STYLE: VisualSVGProps;
26
26
  /** The transient rubber-band shown while Ctrl/Cmd-dragging to remove an area (fill + border stack). */
27
27
  export declare const DEFAULT_REMOVE_PREVIEW_STYLE: SelectionRangeStyle;
28
+ /** The look of the insert I-beam — the `RangeInsertBar` shown while Shift-dragging the move grip. */
29
+ export interface InsertBarStyle {
30
+ /** The bar color. */
31
+ color?: string;
32
+ /** The bar color when the drop would be REFUSED (`MoveDrop.refused`) - the theme's warning. */
33
+ refusedColor?: string;
34
+ /** Bar thickness in DEVICE px (the same currency as a border's `alignWidth`). */
35
+ alignWidth?: number;
36
+ /** How far each end cap reaches past the bar, per side, in DEVICE px. */
37
+ capExtent?: number;
38
+ /** How long the bar takes to travel to a new line, in ms. `0` places it instantly. */
39
+ transitionDuration?: number;
40
+ /** The curve it travels on - a hard decelerate reads as a snap onto the line. */
41
+ transitionEasing?: string;
42
+ /** How long the beam takes to grow into a new ORIENTATION, in ms. `0` shows it at once. */
43
+ axisDuration?: number;
44
+ }
45
+ /**
46
+ * The insert I-beam: the selection color, heavier than the selection outline so it reads as a drop
47
+ * target rather than a border. A drop the model would refuse draws in the theme's WARNING instead
48
+ * (the same token the remove rubber-band uses) - the gesture stays visible, it just says no.
49
+ */
50
+ export declare const DEFAULT_INSERT_BAR_STYLE: InsertBarStyle;
51
+ /**
52
+ * The **mute** laid over the SOURCE of a move (cut) drag — a scrim in the grid's own surface color,
53
+ * drawn under the selection visuals so it fades the cell content while the outline stays crisp. The
54
+ * content reads as already lifted out; a Ctrl (copy) drag draws no mute, so the two modes are
55
+ * distinguishable at a glance rather than by cursor alone.
56
+ */
57
+ export declare const DEFAULT_MOVE_SOURCE_STYLE: SelectionRangeStyle;
28
58
  //# sourceMappingURL=SelectionStyle.d.ts.map
@@ -36,6 +36,23 @@ export declare const edgeScrollPane: (pane: IGridPane, point: {
36
36
  x?: boolean;
37
37
  y?: boolean;
38
38
  }) => boolean;
39
+ /**
40
+ * The modifier keys held during a drag — Excel's *mode* keys: Ctrl turns a move into a copy, Shift
41
+ * into an insert. Tracked by the engine off BOTH the pointer and the keyboard, so it stays true while
42
+ * the pointer stands still (pressing Ctrl fires no pointer event).
43
+ */
44
+ export interface DragModifiers {
45
+ ctrlKey: boolean;
46
+ shiftKey: boolean;
47
+ altKey: boolean;
48
+ metaKey: boolean;
49
+ }
50
+ /** Nothing held — what a drag starts from unless its pointer-down says otherwise. */
51
+ export declare const NO_DRAG_MODIFIERS: DragModifiers;
52
+ /** Snapshot the modifier flags off any event that carries them (pointer, mouse, or keyboard). */
53
+ export declare const readDragModifiers: (e: Partial<DragModifiers>) => DragModifiers;
54
+ /** Whether two modifier snapshots describe the same held keys. */
55
+ export declare const isSameDragModifiers: (a: DragModifiers, b: DragModifiers) => boolean;
39
56
  /**
40
57
  * The in-flight gesture returned by {@link DragCellsOptions.onStart}. It carries the *policy* — how a
41
58
  * given cell-drag mutates the model — while the engine owns the *mechanics* (pointer capture, `lastCell`
@@ -56,6 +73,25 @@ export interface DragCellsSession {
56
73
  * (no pointer event fires while the pointer is parked past the edge), so treat it as optional.
57
74
  */
58
75
  drag: (cell: CellCoords, e?: React.PointerEvent) => void;
76
+ /**
77
+ * The pointer is AT a position — fired on every move (including one that stays inside the cell it is
78
+ * already in) and on every held-still auto-scroll tick, right after any `drag` the same position
79
+ * triggered. For policies whose result is sub-cell, which the per-cell `drag` cannot express: a move
80
+ * drag's insert line snaps to the nearer HALF of the cell under the cursor, so it has to see the
81
+ * pointer cross a midpoint. `cell` is the cell resolved at that point; `e` is absent on an
82
+ * auto-scroll tick. Fires only when a cell resolved.
83
+ *
84
+ * It is called at pointer rate, so a consumer should report onward only what actually changed.
85
+ */
86
+ point?: (cell: CellCoords, clientX: number, clientY: number, e?: React.PointerEvent) => void;
87
+ /**
88
+ * The held modifier keys CHANGED mid-drag — fired on every press/release of Ctrl / Shift / Alt / Meta
89
+ * (never on start, and only on an actual change). Excel's mode keys take effect the instant they are
90
+ * pressed, even with the pointer standing still — and a key press fires no pointer event, so `drag`
91
+ * alone can never see it. Wire this to whatever reflects the mode (a status description, a cursor, a
92
+ * drop preview).
93
+ */
94
+ modifiers?: (mods: DragModifiers) => void;
59
95
  /**
60
96
  * The auto-scroll step: given the pointer's client `point`, scroll the viewport ONE cell toward any edge
61
97
  * the pointer is at (see {@link edgeScrollPane}), and return whether an edge is still engaged so the