@molecule/app-spreadsheet-grid-angular 0.0.0-stage → 1.1.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.
@@ -0,0 +1,220 @@
1
+ import { type DoCheck, type TemplateRef } from '@angular/core';
2
+ import type { UIClassMap } from '@molecule/app-ui';
3
+ import { type GridCell, type GridLayout } from './layout.js';
4
+ import type { CellMap, CellValue, SpreadsheetSelection } from './types.js';
5
+ import * as i0 from "@angular/core";
6
+ /** The open in-cell editor. */
7
+ interface Editing {
8
+ /** 0-indexed row of the edited cell. */
9
+ row: number;
10
+ /** 0-indexed column of the edited cell. */
11
+ col: number;
12
+ /** The draft text the editor shows. */
13
+ draft: string;
14
+ }
15
+ /**
16
+ * SpreadsheetGrid component.
17
+ *
18
+ * High-performance virtualized spreadsheet cell grid: the host IS React's root
19
+ * `<div role="grid">` (`div[mol-spreadsheet-grid]`), so no wrapper element
20
+ * exists. Renders an `rows × columns` grid backed by a sparse
21
+ * `Map<cellRef, value>`, with frozen rows/columns, range selection (click +
22
+ * drag, Shift+click), copy/paste through the system clipboard as TSV, and
23
+ * in-cell editing (double-click → input; Enter commits, Escape cancels).
24
+ * Only the cells inside the visible viewport (plus a small overscan margin)
25
+ * are rendered.
26
+ *
27
+ * React's callbacks are inputs (they keep their React names and their argument
28
+ * lists); React's `renderCell` render prop is an `ng-template`.
29
+ */
30
+ export declare class SpreadsheetGrid implements DoCheck {
31
+ /** Total number of rows in the grid. */
32
+ rows: number;
33
+ /** Total number of columns in the grid. */
34
+ columns: number;
35
+ /** Sparse cell-data map. Cells not present render as empty. */
36
+ cells: CellMap;
37
+ /** Called when the user commits an edit (React's `onCellChange`). */
38
+ onCellChange?: (ref: string, value: CellValue) => void;
39
+ /** Current selection. */
40
+ selection: SpreadsheetSelection;
41
+ /** Called when the user changes the selection (React's `onSelectionChange`). */
42
+ onSelectionChange?: (selection: SpreadsheetSelection) => void;
43
+ /** Number of rows frozen at the top (default `0` at read time). */
44
+ frozenRows?: number;
45
+ /** Number of columns frozen on the left (default `0` at read time). */
46
+ frozenCols?: number;
47
+ /** Per-cell width in pixels (default `96` at read time). */
48
+ cellWidth?: number;
49
+ /** Per-cell height in pixels (default `28` at read time). */
50
+ cellHeight?: number;
51
+ /** Width of the row-number gutter (default `48` at read time). */
52
+ gutterWidth?: number;
53
+ /** Height of the column-letter header (default `28` at read time). */
54
+ headerHeight?: number;
55
+ /** Visible viewport width in pixels (default `720` at read time). */
56
+ viewportWidth?: number;
57
+ /** Visible viewport height in pixels (default `360` at read time). */
58
+ viewportHeight?: number;
59
+ /** `data-mol-id` for AI-agent selectors. */
60
+ dataMolId?: string;
61
+ /** Optional cell renderer (`ng-template`): `$implicit`/`a0` value, `a1` ref. */
62
+ renderCell?: TemplateRef<unknown> | null;
63
+ /** The grid's horizontal scroll offset. */
64
+ protected readonly scrollLeft: import("@angular/core").WritableSignal<number>;
65
+ /** The grid's vertical scroll offset. */
66
+ protected readonly scrollTop: import("@angular/core").WritableSignal<number>;
67
+ /** The open in-cell editor. */
68
+ protected readonly editing: import("@angular/core").WritableSignal<Editing | null>;
69
+ /** The component host (the root `<div role="grid">`). */
70
+ private readonly host;
71
+ /** The injector `afterNextRender` needs outside a constructor. */
72
+ private readonly injector;
73
+ /**
74
+ * Reactive translation, read in the injection context. Its `t` reads the
75
+ * locale, so the view re-renders the labels on a locale switch.
76
+ */
77
+ private readonly i18n;
78
+ /** Where the current drag started, while a mouse button is held. */
79
+ private dragAnchor;
80
+ /** The plan computed for the current change-detection pass. */
81
+ private currentPlan;
82
+ /**
83
+ * The layout plan for the current change-detection pass (recomputed in
84
+ * {@link ngDoCheck}, before the template and host bindings read it).
85
+ *
86
+ * @returns The layout plan.
87
+ */
88
+ protected get plan(): GridLayout;
89
+ /**
90
+ * Recomputes the plan, then re-applies React's controlled-input value: the
91
+ * live value follows the draft after a re-render (the binding sets the
92
+ * attribute; only a user edit moves the property).
93
+ */
94
+ ngDoCheck(): void;
95
+ /**
96
+ * The current class map.
97
+ *
98
+ * @returns The UIClassMap.
99
+ */
100
+ cm(): UIClassMap;
101
+ /**
102
+ * The root's accessible label (React's `t('spreadsheetGrid.label', …)`).
103
+ *
104
+ * @returns The translated label.
105
+ */
106
+ label(): string;
107
+ /**
108
+ * The editor field's accessible label (React's `t('spreadsheetGrid.cellEditor', { ref }, …)`).
109
+ *
110
+ * @param ref - The cell's A1 reference.
111
+ * @returns The translated label.
112
+ */
113
+ cellEditorLabel(ref: string): string;
114
+ /**
115
+ * The editor state of one cell, when that cell is the one being edited.
116
+ *
117
+ * @param row - 0-indexed row.
118
+ * @param col - 0-indexed column.
119
+ * @returns The editor state, or null.
120
+ */
121
+ editorAt(row: number, col: number): Editing | null;
122
+ /**
123
+ * The `renderCell` template, when the caller supplied one.
124
+ *
125
+ * @returns The template, or null.
126
+ */
127
+ renderCellTemplate(): TemplateRef<unknown> | null;
128
+ /**
129
+ * The context a `renderCell` template receives (the value as `$implicit`/`a0`,
130
+ * the A1 reference as `a1`).
131
+ *
132
+ * @param cell - The cell.
133
+ * @returns The template context.
134
+ */
135
+ cellContext(cell: GridCell): Record<string, unknown>;
136
+ /**
137
+ * The current geometry from the inputs and the grid's own state.
138
+ *
139
+ * @returns The geometry.
140
+ */
141
+ private geometry;
142
+ /**
143
+ * Opens the in-cell editor on one cell, seeding the draft from its value.
144
+ *
145
+ * @param row - 0-indexed row.
146
+ * @param col - 0-indexed column.
147
+ */
148
+ beginEdit(row: number, col: number): void;
149
+ /** Commits the open edit: empty clears the cell, number-like text becomes a number. */
150
+ commitEdit(): void;
151
+ /** Closes the editor without committing. */
152
+ cancelEdit(): void;
153
+ /**
154
+ * React's cell `onMouseDown`: commits an open edit, then starts or extends
155
+ * the selection.
156
+ *
157
+ * @param cell - The cell.
158
+ * @param event - The mouse event.
159
+ */
160
+ onCellMouseDown(cell: GridCell, event: MouseEvent): void;
161
+ /**
162
+ * React's cell `onMouseEnter`: extends the selection while the primary
163
+ * button is held.
164
+ *
165
+ * @param cell - The cell.
166
+ * @param event - The mouse event.
167
+ */
168
+ onCellMouseEnter(cell: GridCell, event: MouseEvent): void;
169
+ /** Clears the drag anchor on mouse up. */
170
+ onMouseUp(): void;
171
+ /**
172
+ * React's container `onKeyDown`: copy, and Edit on Enter / F2.
173
+ *
174
+ * @param event - The keyboard event.
175
+ */
176
+ onKeydown(event: KeyboardEvent): void;
177
+ /**
178
+ * The editor field's key handling: Enter commits, Escape cancels. The grid's
179
+ * own key handler runs only while no editor is open (React reads the state
180
+ * the render before the event began, so a key that commits here never
181
+ * reaches it), so the event stays on the field.
182
+ *
183
+ * @param event - The keyboard event.
184
+ */
185
+ onEditorKeydown(event: KeyboardEvent): void;
186
+ /**
187
+ * React's editor `onChange`: each typed value becomes the draft.
188
+ *
189
+ * @param event - The native input event.
190
+ */
191
+ onDraftInput(event: Event): void;
192
+ /**
193
+ * React's container `onPaste`: intercepts the native paste event.
194
+ *
195
+ * @param event - The clipboard event.
196
+ */
197
+ onPaste(event: ClipboardEvent): void;
198
+ /**
199
+ * The scroller's `scroll` handler: refreshes the rendered window.
200
+ *
201
+ * @param event - The scroll event.
202
+ */
203
+ onScroll(event: Event): void;
204
+ /**
205
+ * Serializes the selection to TSV and copies it through the clipboard bond.
206
+ *
207
+ * @returns The TSV text.
208
+ */
209
+ handleCopy(): Promise<string>;
210
+ /**
211
+ * Writes pasted TSV into cells starting at the selection anchor.
212
+ *
213
+ * @param text - Clipboard text (typically TSV).
214
+ */
215
+ handlePaste(text: string): void;
216
+ static ɵfac: i0.ɵɵFactoryDeclaration<SpreadsheetGrid, never>;
217
+ static ɵcmp: i0.ɵɵComponentDeclaration<SpreadsheetGrid, "div[mol-spreadsheet-grid]", never, { "rows": { "alias": "rows"; "required": false; }; "columns": { "alias": "columns"; "required": false; }; "cells": { "alias": "cells"; "required": false; }; "onCellChange": { "alias": "onCellChange"; "required": false; }; "selection": { "alias": "selection"; "required": false; }; "onSelectionChange": { "alias": "onSelectionChange"; "required": false; }; "frozenRows": { "alias": "frozenRows"; "required": false; }; "frozenCols": { "alias": "frozenCols"; "required": false; }; "cellWidth": { "alias": "cellWidth"; "required": false; }; "cellHeight": { "alias": "cellHeight"; "required": false; }; "gutterWidth": { "alias": "gutterWidth"; "required": false; }; "headerHeight": { "alias": "headerHeight"; "required": false; }; "viewportWidth": { "alias": "viewportWidth"; "required": false; }; "viewportHeight": { "alias": "viewportHeight"; "required": false; }; "dataMolId": { "alias": "dataMolId"; "required": false; }; "renderCell": { "alias": "renderCell"; "required": false; }; }, {}, never, never, true, never>;
218
+ }
219
+ export {};
220
+ //# sourceMappingURL=spreadsheet-grid.component.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spreadsheet-grid.component.d.ts","sourceRoot":"","sources":["../src/spreadsheet-grid.component.ts"],"names":[],"mappings":"AAOA,OAAO,EAGL,KAAK,OAAO,EAKZ,KAAK,WAAW,EACjB,MAAM,eAAe,CAAA;AAItB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAGlD,OAAO,EAAiB,KAAK,QAAQ,EAAqB,KAAK,UAAU,EAAE,MAAM,aAAa,CAAA;AAC9F,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;;AAS1E,+BAA+B;AAC/B,UAAU,OAAO;IACf,wCAAwC;IACxC,GAAG,EAAE,MAAM,CAAA;IACX,2CAA2C;IAC3C,GAAG,EAAE,MAAM,CAAA;IACX,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAA;CACd;AAgBD;;;;;;;;;;;;;;GAcG;AACH,qBAsCa,eAAgB,YAAW,OAAO;IAC7C,wCAAwC;IACxC,IAAI,EAAG,MAAM,CAAA;IACb,2CAA2C;IAC3C,OAAO,EAAG,MAAM,CAAA;IAChB,+DAA+D;IAC/D,KAAK,EAAG,OAAO,CAAA;IACf,qEAAqE;IACrE,YAAY,CAAC,EAAE,CAAC,GAAG,EAA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