@molecule/app-spreadsheet-grid-vue 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.
- package/LICENSE +202 -0
- package/README.md +427 -2
- package/dist/SpreadsheetGrid.d.ts +155 -0
- package/dist/SpreadsheetGrid.d.ts.map +1 -0
- package/dist/SpreadsheetGrid.js +409 -0
- package/dist/SpreadsheetGrid.js.map +1 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +75 -0
- package/dist/index.js.map +1 -0
- package/dist/layout.d.ts +167 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +183 -0
- package/dist/layout.js.map +1 -0
- package/dist/types.d.ts +76 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/dist/utilities.d.ts +74 -0
- package/dist/utilities.d.ts.map +1 -0
- package/dist/utilities.js +122 -0
- package/dist/utilities.js.map +1 -0
- package/package.json +69 -4
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue spreadsheet grid: a virtualized cell grid with frozen rows/columns,
|
|
3
|
+
* range selection, copy/paste as TSV and in-cell editing, rendered with `h()`.
|
|
4
|
+
*
|
|
5
|
+
* Vue counterpart of `@molecule/app-spreadsheet-grid-react`'s `SpreadsheetGrid`
|
|
6
|
+
* — the same props (React names), the same DOM for the same input, and the
|
|
7
|
+
* same callbacks.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { type PropType, type VNode } from 'vue';
|
|
12
|
+
import type { CellMap, SpreadsheetGridProps, SpreadsheetSelection } from './types.js';
|
|
13
|
+
/**
|
|
14
|
+
* High-performance virtualized spreadsheet cell grid.
|
|
15
|
+
*
|
|
16
|
+
* Renders an `rows × columns` grid backed by a sparse `Map<cellRef, value>`,
|
|
17
|
+
* with frozen rows/columns, range selection (click + drag, Shift+click),
|
|
18
|
+
* copy/paste through the system clipboard as TSV, and in-cell editing
|
|
19
|
+
* (double-click → input; Enter commits, Escape cancels).
|
|
20
|
+
*
|
|
21
|
+
* Only the cells inside the visible viewport (plus a small overscan margin)
|
|
22
|
+
* are rendered, so 10k × 10k grids stay responsive.
|
|
23
|
+
*
|
|
24
|
+
* @param props - Component props (see {@link SpreadsheetGridProps}).
|
|
25
|
+
* @returns The spreadsheet grid component.
|
|
26
|
+
*/
|
|
27
|
+
export declare const SpreadsheetGrid: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
28
|
+
rows: {
|
|
29
|
+
type: NumberConstructor;
|
|
30
|
+
required: true;
|
|
31
|
+
};
|
|
32
|
+
columns: {
|
|
33
|
+
type: NumberConstructor;
|
|
34
|
+
required: true;
|
|
35
|
+
};
|
|
36
|
+
cells: {
|
|
37
|
+
type: PropType<CellMap>;
|
|
38
|
+
required: true;
|
|
39
|
+
};
|
|
40
|
+
onCellChange: {
|
|
41
|
+
type: PropType<SpreadsheetGridProps["onCellChange"]>;
|
|
42
|
+
required: true;
|
|
43
|
+
};
|
|
44
|
+
selection: {
|
|
45
|
+
type: PropType<SpreadsheetSelection>;
|
|
46
|
+
required: true;
|
|
47
|
+
};
|
|
48
|
+
onSelectionChange: {
|
|
49
|
+
type: PropType<SpreadsheetGridProps["onSelectionChange"]>;
|
|
50
|
+
required: true;
|
|
51
|
+
};
|
|
52
|
+
frozenRows: {
|
|
53
|
+
type: NumberConstructor;
|
|
54
|
+
default: number;
|
|
55
|
+
};
|
|
56
|
+
frozenCols: {
|
|
57
|
+
type: NumberConstructor;
|
|
58
|
+
default: number;
|
|
59
|
+
};
|
|
60
|
+
cellWidth: {
|
|
61
|
+
type: NumberConstructor;
|
|
62
|
+
default: number;
|
|
63
|
+
};
|
|
64
|
+
cellHeight: {
|
|
65
|
+
type: NumberConstructor;
|
|
66
|
+
default: number;
|
|
67
|
+
};
|
|
68
|
+
gutterWidth: {
|
|
69
|
+
type: NumberConstructor;
|
|
70
|
+
default: number;
|
|
71
|
+
};
|
|
72
|
+
headerHeight: {
|
|
73
|
+
type: NumberConstructor;
|
|
74
|
+
default: number;
|
|
75
|
+
};
|
|
76
|
+
viewportWidth: {
|
|
77
|
+
type: NumberConstructor;
|
|
78
|
+
default: number;
|
|
79
|
+
};
|
|
80
|
+
viewportHeight: {
|
|
81
|
+
type: NumberConstructor;
|
|
82
|
+
default: number;
|
|
83
|
+
};
|
|
84
|
+
dataMolId: StringConstructor;
|
|
85
|
+
renderCell: PropType<SpreadsheetGridProps["renderCell"]>;
|
|
86
|
+
}>, () => VNode, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
87
|
+
rows: {
|
|
88
|
+
type: NumberConstructor;
|
|
89
|
+
required: true;
|
|
90
|
+
};
|
|
91
|
+
columns: {
|
|
92
|
+
type: NumberConstructor;
|
|
93
|
+
required: true;
|
|
94
|
+
};
|
|
95
|
+
cells: {
|
|
96
|
+
type: PropType<CellMap>;
|
|
97
|
+
required: true;
|
|
98
|
+
};
|
|
99
|
+
onCellChange: {
|
|
100
|
+
type: PropType<SpreadsheetGridProps["onCellChange"]>;
|
|
101
|
+
required: true;
|
|
102
|
+
};
|
|
103
|
+
selection: {
|
|
104
|
+
type: PropType<SpreadsheetSelection>;
|
|
105
|
+
required: true;
|
|
106
|
+
};
|
|
107
|
+
onSelectionChange: {
|
|
108
|
+
type: PropType<SpreadsheetGridProps["onSelectionChange"]>;
|
|
109
|
+
required: true;
|
|
110
|
+
};
|
|
111
|
+
frozenRows: {
|
|
112
|
+
type: NumberConstructor;
|
|
113
|
+
default: number;
|
|
114
|
+
};
|
|
115
|
+
frozenCols: {
|
|
116
|
+
type: NumberConstructor;
|
|
117
|
+
default: number;
|
|
118
|
+
};
|
|
119
|
+
cellWidth: {
|
|
120
|
+
type: NumberConstructor;
|
|
121
|
+
default: number;
|
|
122
|
+
};
|
|
123
|
+
cellHeight: {
|
|
124
|
+
type: NumberConstructor;
|
|
125
|
+
default: number;
|
|
126
|
+
};
|
|
127
|
+
gutterWidth: {
|
|
128
|
+
type: NumberConstructor;
|
|
129
|
+
default: number;
|
|
130
|
+
};
|
|
131
|
+
headerHeight: {
|
|
132
|
+
type: NumberConstructor;
|
|
133
|
+
default: number;
|
|
134
|
+
};
|
|
135
|
+
viewportWidth: {
|
|
136
|
+
type: NumberConstructor;
|
|
137
|
+
default: number;
|
|
138
|
+
};
|
|
139
|
+
viewportHeight: {
|
|
140
|
+
type: NumberConstructor;
|
|
141
|
+
default: number;
|
|
142
|
+
};
|
|
143
|
+
dataMolId: StringConstructor;
|
|
144
|
+
renderCell: PropType<SpreadsheetGridProps["renderCell"]>;
|
|
145
|
+
}>> & Readonly<{}>, {
|
|
146
|
+
cellHeight: number;
|
|
147
|
+
cellWidth: number;
|
|
148
|
+
frozenCols: number;
|
|
149
|
+
frozenRows: number;
|
|
150
|
+
gutterWidth: number;
|
|
151
|
+
headerHeight: number;
|
|
152
|
+
viewportWidth: number;
|
|
153
|
+
viewportHeight: number;
|
|
154
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
155
|
+
//# sourceMappingURL=SpreadsheetGrid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpreadsheetGrid.d.ts","sourceRoot":"","sources":["../src/SpreadsheetGrid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAsB,KAAK,QAAQ,EAAO,KAAK,KAAK,EAA0B,MAAM,KAAK,CAAA;AAahG,OAAO,KAAK,EAAE,OAAO,EAAa,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAmBhG;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;cAKC,QAAQ,CAAC,OAAO,CAAC;;;;cAEtB,QAAQ,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAAC;;;;cAGrC,QAAQ,CAAC,oBAAoB,CAAC;;;;cAEvC,QAAQ,CAAC,oBAAoB,CAAC,mBAAmB,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBAY/C,QAAQ,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAC;UA2RzD,KAAK;;;;;;;;;;cA9SS,QAAQ,CAAC,OAAO,CAAC;;;;cAEtB,QAAQ,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAAC;;;;cAGrC,QAAQ,CAAC,oBAAoB,CAAC;;;;cAEvC,QAAQ,CAAC,oBAAoB,CAAC,mBAAmB,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBAY/C,QAAQ,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAC;;;;;;;;;;4EA2ZtE,CAAA"}
|
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue spreadsheet grid: a virtualized cell grid with frozen rows/columns,
|
|
3
|
+
* range selection, copy/paste as TSV and in-cell editing, rendered with `h()`.
|
|
4
|
+
*
|
|
5
|
+
* Vue counterpart of `@molecule/app-spreadsheet-grid-react`'s `SpreadsheetGrid`
|
|
6
|
+
* — the same props (React names), the same DOM for the same input, and the
|
|
7
|
+
* same callbacks.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { defineComponent, h, ref, watch } from 'vue';
|
|
12
|
+
import { copyTextWithFallback } from '@molecule/app-clipboard';
|
|
13
|
+
import { getClassMap } from '@molecule/app-ui';
|
|
14
|
+
import { useTranslation } from '@molecule/app-vue';
|
|
15
|
+
import { computeLayout, } from './layout.js';
|
|
16
|
+
import { cellRef, formatCellValue, normalizeSelection, parseClipboardTsv, serializeSelectionTsv, } from './utilities.js';
|
|
17
|
+
/**
|
|
18
|
+
* High-performance virtualized spreadsheet cell grid.
|
|
19
|
+
*
|
|
20
|
+
* Renders an `rows × columns` grid backed by a sparse `Map<cellRef, value>`,
|
|
21
|
+
* with frozen rows/columns, range selection (click + drag, Shift+click),
|
|
22
|
+
* copy/paste through the system clipboard as TSV, and in-cell editing
|
|
23
|
+
* (double-click → input; Enter commits, Escape cancels).
|
|
24
|
+
*
|
|
25
|
+
* Only the cells inside the visible viewport (plus a small overscan margin)
|
|
26
|
+
* are rendered, so 10k × 10k grids stay responsive.
|
|
27
|
+
*
|
|
28
|
+
* @param props - Component props (see {@link SpreadsheetGridProps}).
|
|
29
|
+
* @returns The spreadsheet grid component.
|
|
30
|
+
*/
|
|
31
|
+
export const SpreadsheetGrid = defineComponent({
|
|
32
|
+
name: 'SpreadsheetGrid',
|
|
33
|
+
props: {
|
|
34
|
+
rows: { type: Number, required: true },
|
|
35
|
+
columns: { type: Number, required: true },
|
|
36
|
+
cells: { type: Object, required: true },
|
|
37
|
+
onCellChange: {
|
|
38
|
+
type: Function,
|
|
39
|
+
required: true,
|
|
40
|
+
},
|
|
41
|
+
selection: { type: Object, required: true },
|
|
42
|
+
onSelectionChange: {
|
|
43
|
+
type: Function,
|
|
44
|
+
required: true,
|
|
45
|
+
},
|
|
46
|
+
frozenRows: { type: Number, default: 0 },
|
|
47
|
+
frozenCols: { type: Number, default: 0 },
|
|
48
|
+
cellWidth: { type: Number, default: 96 },
|
|
49
|
+
cellHeight: { type: Number, default: 28 },
|
|
50
|
+
gutterWidth: { type: Number, default: 48 },
|
|
51
|
+
headerHeight: { type: Number, default: 28 },
|
|
52
|
+
viewportWidth: { type: Number, default: 720 },
|
|
53
|
+
viewportHeight: { type: Number, default: 360 },
|
|
54
|
+
dataMolId: String,
|
|
55
|
+
renderCell: Function,
|
|
56
|
+
},
|
|
57
|
+
setup(props) {
|
|
58
|
+
const cm = getClassMap();
|
|
59
|
+
const { t } = useTranslation();
|
|
60
|
+
const scrollLeft = ref(0);
|
|
61
|
+
const scrollTop = ref(0);
|
|
62
|
+
const editing = ref(null);
|
|
63
|
+
/** The editor field, focused and selected once each time editing starts. */
|
|
64
|
+
const editInput = ref(null);
|
|
65
|
+
/** Where the current drag started, while a mouse button is held. */
|
|
66
|
+
let dragAnchor = null;
|
|
67
|
+
// React's `useEffect(() => { focus(); select() }, [editing])`.
|
|
68
|
+
watch(editing, (now) => {
|
|
69
|
+
if (!now)
|
|
70
|
+
return;
|
|
71
|
+
const field = editInput.value;
|
|
72
|
+
field?.focus();
|
|
73
|
+
field?.select();
|
|
74
|
+
}, { flush: 'post' });
|
|
75
|
+
/**
|
|
76
|
+
* Opens the in-cell editor on one cell, seeding the draft from its value.
|
|
77
|
+
*
|
|
78
|
+
* @param row - 0-indexed row.
|
|
79
|
+
* @param col - 0-indexed column.
|
|
80
|
+
*/
|
|
81
|
+
const beginEdit = (row, col) => {
|
|
82
|
+
editing.value = {
|
|
83
|
+
row,
|
|
84
|
+
col,
|
|
85
|
+
draft: formatCellValue(props.cells.get(cellRef(row, col))),
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
/** Commits the open edit: empty clears the cell, number-like text becomes a number. */
|
|
89
|
+
const commitEdit = () => {
|
|
90
|
+
const current = editing.value;
|
|
91
|
+
if (!current)
|
|
92
|
+
return;
|
|
93
|
+
const ref = cellRef(current.row, current.col);
|
|
94
|
+
const trimmed = current.draft;
|
|
95
|
+
let next;
|
|
96
|
+
if (trimmed === '')
|
|
97
|
+
next = null;
|
|
98
|
+
else if (/^-?\d+(\.\d+)?$/.test(trimmed))
|
|
99
|
+
next = Number(trimmed);
|
|
100
|
+
else
|
|
101
|
+
next = trimmed;
|
|
102
|
+
props.onCellChange(ref, next);
|
|
103
|
+
editing.value = null;
|
|
104
|
+
};
|
|
105
|
+
/** Closes the editor without committing. */
|
|
106
|
+
const cancelEdit = () => {
|
|
107
|
+
editing.value = null;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* React's cell `onMouseDown`: commits an open edit, then starts or extends
|
|
111
|
+
* the selection.
|
|
112
|
+
*
|
|
113
|
+
* @param row - 0-indexed row.
|
|
114
|
+
* @param col - 0-indexed column.
|
|
115
|
+
* @param shiftKey - Whether Shift was held (extend from the anchor).
|
|
116
|
+
*/
|
|
117
|
+
const handleMouseDown = (row, col, shiftKey) => {
|
|
118
|
+
if (editing.value)
|
|
119
|
+
commitEdit();
|
|
120
|
+
if (shiftKey) {
|
|
121
|
+
props.onSelectionChange({
|
|
122
|
+
r1: props.selection.r1,
|
|
123
|
+
c1: props.selection.c1,
|
|
124
|
+
r2: row,
|
|
125
|
+
c2: col,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
dragAnchor = { row, col };
|
|
130
|
+
props.onSelectionChange({ r1: row, c1: col, r2: row, c2: col });
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* React's cell `onMouseEnter`: extends the selection while the primary
|
|
135
|
+
* button is held.
|
|
136
|
+
*
|
|
137
|
+
* @param row - 0-indexed row.
|
|
138
|
+
* @param col - 0-indexed column.
|
|
139
|
+
* @param buttonsDown - Whether the primary button is held.
|
|
140
|
+
*/
|
|
141
|
+
const handleMouseEnter = (row, col, buttonsDown) => {
|
|
142
|
+
if (!buttonsDown)
|
|
143
|
+
return;
|
|
144
|
+
const anchor = dragAnchor;
|
|
145
|
+
if (!anchor)
|
|
146
|
+
return;
|
|
147
|
+
props.onSelectionChange({ r1: anchor.row, c1: anchor.col, r2: row, c2: col });
|
|
148
|
+
};
|
|
149
|
+
/** Clears the drag anchor on mouse up. */
|
|
150
|
+
const handleMouseUp = () => {
|
|
151
|
+
dragAnchor = null;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Serializes the selection to TSV and copies it through the clipboard bond.
|
|
155
|
+
*
|
|
156
|
+
* @returns The TSV text.
|
|
157
|
+
*/
|
|
158
|
+
const handleCopy = async () => {
|
|
159
|
+
const tsv = serializeSelectionTsv(props.cells, props.selection);
|
|
160
|
+
await copyTextWithFallback(tsv);
|
|
161
|
+
return tsv;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Writes pasted TSV into cells starting at the selection anchor.
|
|
165
|
+
*
|
|
166
|
+
* @param text - Clipboard text (typically TSV).
|
|
167
|
+
*/
|
|
168
|
+
const handlePaste = (text) => {
|
|
169
|
+
const grid = parseClipboardTsv(text);
|
|
170
|
+
if (grid.length === 0)
|
|
171
|
+
return;
|
|
172
|
+
const n = normalizeSelection(props.selection);
|
|
173
|
+
for (let r = 0; r < grid.length; r += 1) {
|
|
174
|
+
const row = grid[r];
|
|
175
|
+
for (let c = 0; c < row.length; c += 1) {
|
|
176
|
+
const targetRow = n.r1 + r;
|
|
177
|
+
const targetCol = n.c1 + c;
|
|
178
|
+
if (targetRow >= props.rows || targetCol >= props.columns)
|
|
179
|
+
continue;
|
|
180
|
+
const raw = row[c];
|
|
181
|
+
let next;
|
|
182
|
+
if (raw === '')
|
|
183
|
+
next = null;
|
|
184
|
+
else if (/^-?\d+(\.\d+)?$/.test(raw))
|
|
185
|
+
next = Number(raw);
|
|
186
|
+
else
|
|
187
|
+
next = raw;
|
|
188
|
+
props.onCellChange(cellRef(targetRow, targetCol), next);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* React's container `onKeyDown`: copy, and Edit on Enter / F2.
|
|
194
|
+
*
|
|
195
|
+
* @param event - The keyboard event.
|
|
196
|
+
*/
|
|
197
|
+
const handleKeyDown = (event) => {
|
|
198
|
+
const isMod = event.ctrlKey || event.metaKey;
|
|
199
|
+
if (editing.value)
|
|
200
|
+
return;
|
|
201
|
+
if (isMod && event.key.toLowerCase() === 'c') {
|
|
202
|
+
event.preventDefault();
|
|
203
|
+
void handleCopy();
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (isMod && event.key.toLowerCase() === 'v')
|
|
207
|
+
return;
|
|
208
|
+
if (event.key === 'Enter' || event.key === 'F2') {
|
|
209
|
+
event.preventDefault();
|
|
210
|
+
beginEdit(props.selection.r1, props.selection.c1);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* React's container `onPaste`: intercepts the native paste event.
|
|
215
|
+
*
|
|
216
|
+
* @param event - The clipboard event.
|
|
217
|
+
*/
|
|
218
|
+
const handlePasteEvent = (event) => {
|
|
219
|
+
const text = event.clipboardData ? event.clipboardData.getData('text/plain') : '';
|
|
220
|
+
if (!text)
|
|
221
|
+
return;
|
|
222
|
+
event.preventDefault();
|
|
223
|
+
handlePaste(text);
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Renders one column-letter or row-number label.
|
|
227
|
+
*
|
|
228
|
+
* @param cell - The label.
|
|
229
|
+
* @param role - The ARIA role the label carries (`columnheader`), if any.
|
|
230
|
+
* @returns The label element.
|
|
231
|
+
*/
|
|
232
|
+
const headerVnode = (cell, role) => h('div', {
|
|
233
|
+
key: cell.key,
|
|
234
|
+
...(role ? { role, 'aria-colindex': cell.index + 1 } : {}),
|
|
235
|
+
class: cell.classes,
|
|
236
|
+
style: cell.style,
|
|
237
|
+
}, cell.text);
|
|
238
|
+
/**
|
|
239
|
+
* Renders one cell box: its editor while it is being edited, its content
|
|
240
|
+
* otherwise.
|
|
241
|
+
*
|
|
242
|
+
* @param cell - The cell.
|
|
243
|
+
* @param layout - The current layout plan.
|
|
244
|
+
* @returns The cell element.
|
|
245
|
+
*/
|
|
246
|
+
const cellVnode = (cell, layout) => {
|
|
247
|
+
const current = editing.value;
|
|
248
|
+
const isEditing = current !== null && current.row === cell.row && current.col === cell.col;
|
|
249
|
+
let child;
|
|
250
|
+
if (isEditing && current) {
|
|
251
|
+
child = h('input', {
|
|
252
|
+
ref: editInput,
|
|
253
|
+
'data-mol-id': `spreadsheet-grid-editor-${cell.ref}`,
|
|
254
|
+
class: layout.editorClasses,
|
|
255
|
+
value: current.draft,
|
|
256
|
+
onInput: (event) => {
|
|
257
|
+
const open = editing.value;
|
|
258
|
+
if (!open)
|
|
259
|
+
return;
|
|
260
|
+
editing.value = { ...open, draft: event.target.value };
|
|
261
|
+
},
|
|
262
|
+
onBlur: commitEdit,
|
|
263
|
+
onKeydown: (event) => {
|
|
264
|
+
// The grid's own key handler runs only while no editor is open
|
|
265
|
+
// (React reads the state the render before the event began, so a
|
|
266
|
+
// key that commits here never reaches it): keep the event on the
|
|
267
|
+
// field, as that guard does.
|
|
268
|
+
event.stopPropagation();
|
|
269
|
+
if (event.key === 'Enter') {
|
|
270
|
+
event.preventDefault();
|
|
271
|
+
commitEdit();
|
|
272
|
+
}
|
|
273
|
+
else if (event.key === 'Escape') {
|
|
274
|
+
event.preventDefault();
|
|
275
|
+
cancelEdit();
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
'aria-label': t('spreadsheetGrid.cellEditor', { ref: cell.ref }, {
|
|
279
|
+
defaultValue: 'Edit cell {{ref}}',
|
|
280
|
+
}),
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
child = h('div', { class: layout.contentClasses }, [
|
|
285
|
+
props.renderCell ? props.renderCell(cell.value, cell.ref) : cell.text,
|
|
286
|
+
]);
|
|
287
|
+
}
|
|
288
|
+
return h('div', {
|
|
289
|
+
key: cell.ref,
|
|
290
|
+
role: 'gridcell',
|
|
291
|
+
'data-mol-id': `spreadsheet-grid-cell-${cell.ref}`,
|
|
292
|
+
// Roving tabindex per the WAI-ARIA grid pattern: exactly one cell —
|
|
293
|
+
// the selection anchor — is in the tab order.
|
|
294
|
+
tabindex: cell.anchor ? 0 : -1,
|
|
295
|
+
'aria-selected': cell.selected ? 'true' : undefined,
|
|
296
|
+
class: cell.classes,
|
|
297
|
+
style: cell.style,
|
|
298
|
+
onMousedown: (event) => handleMouseDown(cell.row, cell.col, event.shiftKey),
|
|
299
|
+
onMouseenter: (event) => handleMouseEnter(cell.row, cell.col, event.buttons === 1),
|
|
300
|
+
onDblclick: () => beginEdit(cell.row, cell.col),
|
|
301
|
+
}, [child]);
|
|
302
|
+
};
|
|
303
|
+
/**
|
|
304
|
+
* Builds the current geometry from the props and the grid's own state.
|
|
305
|
+
*
|
|
306
|
+
* @returns The geometry.
|
|
307
|
+
*/
|
|
308
|
+
const geometry = () => ({
|
|
309
|
+
rows: props.rows,
|
|
310
|
+
columns: props.columns,
|
|
311
|
+
cells: props.cells,
|
|
312
|
+
selection: props.selection,
|
|
313
|
+
frozenRows: props.frozenRows,
|
|
314
|
+
frozenCols: props.frozenCols,
|
|
315
|
+
cellWidth: props.cellWidth,
|
|
316
|
+
cellHeight: props.cellHeight,
|
|
317
|
+
gutterWidth: props.gutterWidth,
|
|
318
|
+
headerHeight: props.headerHeight,
|
|
319
|
+
viewportWidth: props.viewportWidth,
|
|
320
|
+
viewportHeight: props.viewportHeight,
|
|
321
|
+
scrollLeft: scrollLeft.value,
|
|
322
|
+
scrollTop: scrollTop.value,
|
|
323
|
+
editing: editing.value,
|
|
324
|
+
});
|
|
325
|
+
return () => {
|
|
326
|
+
const layout = computeLayout(geometry(), cm);
|
|
327
|
+
return h('div', {
|
|
328
|
+
'data-mol-id': props.dataMolId ?? 'spreadsheet-grid',
|
|
329
|
+
role: 'grid',
|
|
330
|
+
tabindex: 0,
|
|
331
|
+
'aria-rowcount': props.rows,
|
|
332
|
+
'aria-colcount': props.columns,
|
|
333
|
+
'aria-label': t('spreadsheetGrid.label', undefined, { defaultValue: 'Spreadsheet' }),
|
|
334
|
+
class: layout.rootClasses,
|
|
335
|
+
style: layout.rootStyle,
|
|
336
|
+
onKeydown: handleKeyDown,
|
|
337
|
+
onPaste: handlePasteEvent,
|
|
338
|
+
onMouseup: handleMouseUp,
|
|
339
|
+
}, [
|
|
340
|
+
// Top-left corner (gutter × header).
|
|
341
|
+
h('div', {
|
|
342
|
+
'aria-hidden': 'true',
|
|
343
|
+
class: layout.cornerClasses,
|
|
344
|
+
style: layout.cornerStyle,
|
|
345
|
+
}),
|
|
346
|
+
// Column-letter header (frozen + scrollable).
|
|
347
|
+
h('div', {
|
|
348
|
+
role: 'row',
|
|
349
|
+
'aria-rowindex': 1,
|
|
350
|
+
class: layout.headerLaneClasses,
|
|
351
|
+
style: layout.headerLaneStyle,
|
|
352
|
+
}, [
|
|
353
|
+
...layout.frozenHeaderCells.map((cell) => headerVnode(cell, 'columnheader')),
|
|
354
|
+
h('div', { style: layout.headerScrollerStyle }, layout.scrollingHeaderCells.map((cell) => headerVnode(cell, 'columnheader'))),
|
|
355
|
+
]),
|
|
356
|
+
// Row-number gutter (frozen + scrollable).
|
|
357
|
+
h('div', {
|
|
358
|
+
'aria-hidden': 'true',
|
|
359
|
+
class: layout.gutterLaneClasses,
|
|
360
|
+
style: layout.gutterLaneStyle,
|
|
361
|
+
}, [
|
|
362
|
+
...layout.frozenGutterCells.map((cell) => headerVnode(cell)),
|
|
363
|
+
h('div', { style: layout.gutterScrollerStyle }, layout.scrollingGutterCells.map((cell) => headerVnode(cell))),
|
|
364
|
+
]),
|
|
365
|
+
// Frozen-rows × scrolling-cols region.
|
|
366
|
+
...(layout.showFrozenRows
|
|
367
|
+
? [
|
|
368
|
+
h('div', { style: layout.frozenRowsRegionStyle }, [
|
|
369
|
+
h('div', { style: layout.frozenRowsInnerStyle }, layout.frozenRowsCells.map((cell) => cellVnode(cell, layout))),
|
|
370
|
+
]),
|
|
371
|
+
]
|
|
372
|
+
: []),
|
|
373
|
+
// Frozen-cols × scrolling-rows region.
|
|
374
|
+
...(layout.showFrozenCols
|
|
375
|
+
? [
|
|
376
|
+
h('div', { style: layout.frozenColsRegionStyle }, [
|
|
377
|
+
h('div', { style: layout.frozenColsInnerStyle }, layout.frozenColsCells.map((cell) => cellVnode(cell, layout))),
|
|
378
|
+
]),
|
|
379
|
+
]
|
|
380
|
+
: []),
|
|
381
|
+
// Frozen-rows × frozen-cols corner.
|
|
382
|
+
...(layout.showFrozenCorner
|
|
383
|
+
? [
|
|
384
|
+
h('div', { style: layout.frozenCornerStyle }, layout.frozenCornerCells.map((cell) => cellVnode(cell, layout))),
|
|
385
|
+
]
|
|
386
|
+
: []),
|
|
387
|
+
// Main scrollable region.
|
|
388
|
+
h('div', {
|
|
389
|
+
'data-mol-id': 'spreadsheet-grid-scroll',
|
|
390
|
+
style: layout.scrollRegionStyle,
|
|
391
|
+
onScroll: (event) => {
|
|
392
|
+
const element = event.currentTarget;
|
|
393
|
+
scrollLeft.value = element.scrollLeft;
|
|
394
|
+
scrollTop.value = element.scrollTop;
|
|
395
|
+
},
|
|
396
|
+
}, [
|
|
397
|
+
h('div', { style: layout.scrollSpacerStyle }, layout.mainCells.map((cell) => cellVnode(cell, layout))),
|
|
398
|
+
]),
|
|
399
|
+
// Hidden total-size hint for accessibility tooling.
|
|
400
|
+
h('span', {
|
|
401
|
+
class: layout.totalClasses,
|
|
402
|
+
style: layout.totalStyle,
|
|
403
|
+
'aria-hidden': 'true',
|
|
404
|
+
}, layout.totalText),
|
|
405
|
+
]);
|
|
406
|
+
};
|
|
407
|
+
},
|
|
408
|
+
});
|
|
409
|
+
//# sourceMappingURL=SpreadsheetGrid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpreadsheetGrid.js","sourceRoot":"","sources":["../src/SpreadsheetGrid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,eAAe,EAAE,CAAC,EAAiB,GAAG,EAA+B,KAAK,EAAE,MAAM,KAAK,CAAA;AAEhG,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAElD,OAAO,EACL,aAAa,GAKd,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,OAAO,EACP,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,gBAAgB,CAAA;AAYvB;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,eAA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C,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-performance virtualized spreadsheet cell grid for Vue.
|
|
3
|
+
*
|
|
4
|
+
* Exports:
|
|
5
|
+
* - `<SpreadsheetGrid>` — the grid component (virtualized cells, frozen
|
|
6
|
+
* rows/columns, range selection, copy/paste as TSV, in-cell editing).
|
|
7
|
+
* - Types: `SpreadsheetGridProps`, `SpreadsheetSelection`, `CellMap`,
|
|
8
|
+
* `CellRef`, `CellValue`.
|
|
9
|
+
* - Helpers: `cellRef()`, `columnLetter()`, `normalizeSelection()`,
|
|
10
|
+
* `isInSelection()`, `formatCellValue()`, `parseClipboardTsv()`,
|
|
11
|
+
* `serializeSelectionTsv()`, `computeVisibleRange()`.
|
|
12
|
+
*
|
|
13
|
+
* Pairs with `@molecule/api-formula-engine` for formula evaluation —
|
|
14
|
+
* pass evaluated `cells` plus an optional `renderCell` to display
|
|
15
|
+
* formula results.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { createApp, defineComponent, h, ref } from 'vue'
|
|
20
|
+
*
|
|
21
|
+
* import { SpreadsheetGrid, type CellMap, type SpreadsheetSelection } from '@molecule/app-spreadsheet-grid-vue'
|
|
22
|
+
*
|
|
23
|
+
* const Sheet = defineComponent({
|
|
24
|
+
* setup() {
|
|
25
|
+
* const cells = ref<CellMap>(new Map())
|
|
26
|
+
* const selection = ref<SpreadsheetSelection>({ r1: 0, c1: 0, r2: 0, c2: 0 })
|
|
27
|
+
* return () =>
|
|
28
|
+
* h(SpreadsheetGrid, {
|
|
29
|
+
* rows: 1000,
|
|
30
|
+
* columns: 26,
|
|
31
|
+
* cells: cells.value,
|
|
32
|
+
* selection: selection.value,
|
|
33
|
+
* frozenRows: 1,
|
|
34
|
+
* frozenCols: 1,
|
|
35
|
+
* onCellChange: (ref, value) => {
|
|
36
|
+
* const next = new Map(cells.value)
|
|
37
|
+
* if (value === null) next.delete(ref)
|
|
38
|
+
* else next.set(ref, value)
|
|
39
|
+
* cells.value = next
|
|
40
|
+
* },
|
|
41
|
+
* onSelectionChange: (next) => {
|
|
42
|
+
* selection.value = next
|
|
43
|
+
* },
|
|
44
|
+
* })
|
|
45
|
+
* },
|
|
46
|
+
* })
|
|
47
|
+
*
|
|
48
|
+
* createApp(Sheet).mount('#app')
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* - Must render with a ClassMap bond wired (`getClassMap()` throws
|
|
53
|
+
* otherwise), and inside the app's i18n provider (or with the bonded one).
|
|
54
|
+
* - The viewport is FIXED-PIXEL: `viewportWidth`/`viewportHeight`
|
|
55
|
+
* (defaults 720×360) — the grid does not auto-size to its container.
|
|
56
|
+
* Measure the container and pass px if you need it to fill.
|
|
57
|
+
* - Copy (Ctrl/Cmd+C) writes TSV through `copyTextWithFallback()` from
|
|
58
|
+
* `@molecule/app-clipboard`, which uses the bonded clipboard provider with
|
|
59
|
+
* a selection-and-copy fallback and never throws. Paste is handled through
|
|
60
|
+
* the native paste event, so the grid container must have focus (click a
|
|
61
|
+
* cell first). Keyboard support is Enter/F2 (edit) + copy/paste only; there
|
|
62
|
+
* is NO arrow-key cell navigation.
|
|
63
|
+
* - Committed edits and pasted cells auto-coerce number-like strings to
|
|
64
|
+
* numbers (`'42'` → `42`); empty string clears the cell (`null`).
|
|
65
|
+
* - Gridlines/selection/header styling uses Material-3 design-token
|
|
66
|
+
* utilities (`bg-surface`, `border-outline-variant`, …). Apps whose
|
|
67
|
+
* Tailwind theme does not define those tokens (the minimal scaffold
|
|
68
|
+
* theme does not) get a functional but unstyled grid.
|
|
69
|
+
*
|
|
70
|
+
* @module
|
|
71
|
+
*/
|
|
72
|
+
export * from './SpreadsheetGrid.js';
|
|
73
|
+
export * from './types.js';
|
|
74
|
+
export * from './utilities.js';
|
|
75
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsEG;AAEH,cAAc,sBAAsB,CAAA;AACpC,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA"}
|