@molecule/app-spreadsheet-grid-svelte 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 +334 -2
- package/dist/SpreadsheetGrid.svelte +387 -0
- package/dist/SpreadsheetGrid.svelte.d.ts +5 -0
- package/dist/SpreadsheetGrid.svelte.d.ts.map +1 -0
- package/dist/components.d.ts +8 -0
- package/dist/components.d.ts.map +1 -0
- package/dist/components.js +7 -0
- package/dist/index.d.ts +70 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +69 -0
- package/dist/layout.d.ts +167 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +182 -0
- package/dist/types.d.ts +76 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/utilities.d.ts +74 -0
- package/dist/utilities.d.ts.map +1 -0
- package/dist/utilities.js +121 -0
- package/dist/value.d.ts +33 -0
- package/dist/value.d.ts.map +1 -0
- package/dist/value.js +41 -0
- package/package.json +77 -4
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
SpreadsheetGrid: the Svelte counterpart of
|
|
3
|
+
`@molecule/app-spreadsheet-grid-react`'s `SpreadsheetGrid` — a virtualized
|
|
4
|
+
cell grid with frozen rows/columns, range selection, copy/paste as TSV and
|
|
5
|
+
in-cell editing. Same props (React names), same DOM for the same input, and
|
|
6
|
+
the same callbacks. React's `renderCell` render prop is a snippet receiving
|
|
7
|
+
the value and the A1 reference.
|
|
8
|
+
-->
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import { copyTextWithFallback } from '@molecule/app-clipboard'
|
|
11
|
+
import { useTranslation } from '@molecule/app-svelte'
|
|
12
|
+
import { getClassMap } from '@molecule/app-ui'
|
|
13
|
+
|
|
14
|
+
import { computeLayout, type GridCell, type GridEditing } from './layout.js'
|
|
15
|
+
import type { CellValue, SpreadsheetGridProps } from './types.js'
|
|
16
|
+
import {
|
|
17
|
+
cellRef,
|
|
18
|
+
formatCellValue,
|
|
19
|
+
normalizeSelection,
|
|
20
|
+
parseClipboardTsv,
|
|
21
|
+
serializeSelectionTsv,
|
|
22
|
+
} from './utilities.js'
|
|
23
|
+
import { reactInputValue } from './value.js'
|
|
24
|
+
|
|
25
|
+
let {
|
|
26
|
+
rows,
|
|
27
|
+
columns,
|
|
28
|
+
cells,
|
|
29
|
+
onCellChange,
|
|
30
|
+
selection,
|
|
31
|
+
onSelectionChange,
|
|
32
|
+
frozenRows = 0,
|
|
33
|
+
frozenCols = 0,
|
|
34
|
+
cellWidth = 96,
|
|
35
|
+
cellHeight = 28,
|
|
36
|
+
gutterWidth = 48,
|
|
37
|
+
headerHeight = 28,
|
|
38
|
+
viewportWidth = 720,
|
|
39
|
+
viewportHeight = 360,
|
|
40
|
+
dataMolId,
|
|
41
|
+
renderCell,
|
|
42
|
+
}: SpreadsheetGridProps = $props()
|
|
43
|
+
|
|
44
|
+
const cm = $derived(getClassMap())
|
|
45
|
+
const { t } = useTranslation()
|
|
46
|
+
|
|
47
|
+
let scrollLeft = $state(0)
|
|
48
|
+
let scrollTop = $state(0)
|
|
49
|
+
let editing = $state<GridEditing | null>(null)
|
|
50
|
+
/** The editor field, focused and selected once each time editing starts. */
|
|
51
|
+
let editorEl = $state<HTMLInputElement | null>(null)
|
|
52
|
+
/** Where the current drag started, while a mouse button is held. */
|
|
53
|
+
let dragAnchor: { row: number; col: number } | null = null
|
|
54
|
+
|
|
55
|
+
const layout = $derived(
|
|
56
|
+
computeLayout(
|
|
57
|
+
{
|
|
58
|
+
rows,
|
|
59
|
+
columns,
|
|
60
|
+
cells,
|
|
61
|
+
selection,
|
|
62
|
+
frozenRows,
|
|
63
|
+
frozenCols,
|
|
64
|
+
cellWidth,
|
|
65
|
+
cellHeight,
|
|
66
|
+
gutterWidth,
|
|
67
|
+
headerHeight,
|
|
68
|
+
viewportWidth,
|
|
69
|
+
viewportHeight,
|
|
70
|
+
scrollLeft,
|
|
71
|
+
scrollTop,
|
|
72
|
+
editing,
|
|
73
|
+
},
|
|
74
|
+
cm,
|
|
75
|
+
),
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
// React's `useEffect(() => { focus(); select() }, [editing])`: runs after the
|
|
79
|
+
// editor is in the DOM, and again whenever the draft changes (as React's
|
|
80
|
+
// effect re-runs on each new editing object).
|
|
81
|
+
$effect(() => {
|
|
82
|
+
if (!editing) return
|
|
83
|
+
const field = editorEl
|
|
84
|
+
field?.focus()
|
|
85
|
+
field?.select()
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Opens the in-cell editor on one cell, seeding the draft from its value.
|
|
90
|
+
*
|
|
91
|
+
* @param row - 0-indexed row.
|
|
92
|
+
* @param col - 0-indexed column.
|
|
93
|
+
*/
|
|
94
|
+
function beginEdit(row: number, col: number): void {
|
|
95
|
+
editing = { row, col, draft: formatCellValue(cells.get(cellRef(row, col))) }
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Commits the open edit: empty clears the cell, number-like text becomes a number. */
|
|
99
|
+
function commitEdit(): void {
|
|
100
|
+
const current = editing
|
|
101
|
+
if (!current) return
|
|
102
|
+
const ref = cellRef(current.row, current.col)
|
|
103
|
+
const trimmed = current.draft
|
|
104
|
+
let next: CellValue
|
|
105
|
+
if (trimmed === '') next = null
|
|
106
|
+
else if (/^-?\d+(\.\d+)?$/.test(trimmed)) next = Number(trimmed)
|
|
107
|
+
else next = trimmed
|
|
108
|
+
onCellChange(ref, next)
|
|
109
|
+
editing = null
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Closes the editor without committing. */
|
|
113
|
+
function cancelEdit(): void {
|
|
114
|
+
editing = null
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* React's cell `onMouseDown`: commits an open edit, then starts or extends
|
|
119
|
+
* the selection.
|
|
120
|
+
*
|
|
121
|
+
* @param row - 0-indexed row.
|
|
122
|
+
* @param col - 0-indexed column.
|
|
123
|
+
* @param shiftKey - Whether Shift was held (extend from the anchor).
|
|
124
|
+
*/
|
|
125
|
+
function handleMouseDown(row: number, col: number, shiftKey: boolean): void {
|
|
126
|
+
if (editing) commitEdit()
|
|
127
|
+
if (shiftKey) {
|
|
128
|
+
onSelectionChange({ r1: selection.r1, c1: selection.c1, r2: row, c2: col })
|
|
129
|
+
} else {
|
|
130
|
+
dragAnchor = { row, col }
|
|
131
|
+
onSelectionChange({ r1: row, c1: col, r2: row, c2: col })
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* React's cell `onMouseEnter`: extends the selection while the primary
|
|
137
|
+
* button is held.
|
|
138
|
+
*
|
|
139
|
+
* @param row - 0-indexed row.
|
|
140
|
+
* @param col - 0-indexed column.
|
|
141
|
+
* @param buttonsDown - Whether the primary button is held.
|
|
142
|
+
*/
|
|
143
|
+
function handleMouseEnter(row: number, col: number, buttonsDown: boolean): void {
|
|
144
|
+
if (!buttonsDown) return
|
|
145
|
+
const anchor = dragAnchor
|
|
146
|
+
if (!anchor) return
|
|
147
|
+
onSelectionChange({ r1: anchor.row, c1: anchor.col, r2: row, c2: col })
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Clears the drag anchor on mouse up. */
|
|
151
|
+
function handleMouseUp(): void {
|
|
152
|
+
dragAnchor = null
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* React's container `onKeyDown`: copy, and Edit on Enter / F2.
|
|
157
|
+
*
|
|
158
|
+
* @param event - The keyboard event.
|
|
159
|
+
*/
|
|
160
|
+
function handleKeyDown(event: KeyboardEvent): void {
|
|
161
|
+
const isMod = event.ctrlKey || event.metaKey
|
|
162
|
+
if (editing) return
|
|
163
|
+
if (isMod && event.key.toLowerCase() === 'c') {
|
|
164
|
+
event.preventDefault()
|
|
165
|
+
void handleCopy()
|
|
166
|
+
return
|
|
167
|
+
}
|
|
168
|
+
if (isMod && event.key.toLowerCase() === 'v') return
|
|
169
|
+
if (event.key === 'Enter' || event.key === 'F2') {
|
|
170
|
+
event.preventDefault()
|
|
171
|
+
beginEdit(selection.r1, selection.c1)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The editor field's key handling: Enter commits, Escape cancels. The grid's
|
|
177
|
+
* own key handler runs only while no editor is open (React reads the state
|
|
178
|
+
* the render before the event began, so a key that commits here never
|
|
179
|
+
* reaches it), so the event stays on the field.
|
|
180
|
+
*
|
|
181
|
+
* @param event - The keyboard event.
|
|
182
|
+
*/
|
|
183
|
+
function handleEditorKeyDown(event: KeyboardEvent): void {
|
|
184
|
+
event.stopPropagation()
|
|
185
|
+
if (event.key === 'Enter') {
|
|
186
|
+
event.preventDefault()
|
|
187
|
+
commitEdit()
|
|
188
|
+
} else if (event.key === 'Escape') {
|
|
189
|
+
event.preventDefault()
|
|
190
|
+
cancelEdit()
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Serializes the selection to TSV and copies it through the clipboard bond.
|
|
196
|
+
*
|
|
197
|
+
* @returns The TSV text.
|
|
198
|
+
*/
|
|
199
|
+
async function handleCopy(): Promise<string> {
|
|
200
|
+
const tsv = serializeSelectionTsv(cells, selection)
|
|
201
|
+
await copyTextWithFallback(tsv)
|
|
202
|
+
return tsv
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Writes pasted TSV into cells starting at the selection anchor.
|
|
207
|
+
*
|
|
208
|
+
* @param text - Clipboard text (typically TSV).
|
|
209
|
+
*/
|
|
210
|
+
function handlePaste(text: string): void {
|
|
211
|
+
const grid = parseClipboardTsv(text)
|
|
212
|
+
if (grid.length === 0) return
|
|
213
|
+
const n = normalizeSelection(selection)
|
|
214
|
+
for (let r = 0; r < grid.length; r += 1) {
|
|
215
|
+
const row = grid[r]!
|
|
216
|
+
for (let c = 0; c < row.length; c += 1) {
|
|
217
|
+
const targetRow = n.r1 + r
|
|
218
|
+
const targetCol = n.c1 + c
|
|
219
|
+
if (targetRow >= rows || targetCol >= columns) continue
|
|
220
|
+
const raw = row[c]!
|
|
221
|
+
let next: CellValue
|
|
222
|
+
if (raw === '') next = null
|
|
223
|
+
else if (/^-?\d+(\.\d+)?$/.test(raw)) next = Number(raw)
|
|
224
|
+
else next = raw
|
|
225
|
+
onCellChange(cellRef(targetRow, targetCol), next)
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* React's container `onPaste`: intercepts the native paste event.
|
|
232
|
+
*
|
|
233
|
+
* @param event - The clipboard event.
|
|
234
|
+
*/
|
|
235
|
+
function handlePasteEvent(event: ClipboardEvent): void {
|
|
236
|
+
const text = event.clipboardData ? event.clipboardData.getData('text/plain') : ''
|
|
237
|
+
if (!text) return
|
|
238
|
+
event.preventDefault()
|
|
239
|
+
handlePaste(text)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* The editor's body: each typed value becomes the draft.
|
|
244
|
+
*
|
|
245
|
+
* @param event - The input event.
|
|
246
|
+
*/
|
|
247
|
+
function handleDraftInput(event: Event): void {
|
|
248
|
+
const current = editing
|
|
249
|
+
if (!current) return
|
|
250
|
+
editing = { ...current, draft: (event.currentTarget as HTMLInputElement).value }
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* The scroller's `scroll` handler: refreshes the rendered window.
|
|
255
|
+
*
|
|
256
|
+
* @param event - The scroll event.
|
|
257
|
+
*/
|
|
258
|
+
function handleScroll(event: Event): void {
|
|
259
|
+
const element = event.currentTarget as HTMLDivElement
|
|
260
|
+
scrollLeft = element.scrollLeft
|
|
261
|
+
scrollTop = element.scrollTop
|
|
262
|
+
}
|
|
263
|
+
</script>
|
|
264
|
+
|
|
265
|
+
{#snippet cellBox(cell: GridCell)}
|
|
266
|
+
<div
|
|
267
|
+
role="gridcell"
|
|
268
|
+
data-mol-id="spreadsheet-grid-cell-{cell.ref}"
|
|
269
|
+
tabindex={cell.anchor ? 0 : -1}
|
|
270
|
+
aria-selected={cell.selected ? 'true' : undefined}
|
|
271
|
+
class={cell.classes}
|
|
272
|
+
style={cell.style}
|
|
273
|
+
onmousedown={(event) => handleMouseDown(cell.row, cell.col, event.shiftKey)}
|
|
274
|
+
onmouseenter={(event) => handleMouseEnter(cell.row, cell.col, event.buttons === 1)}
|
|
275
|
+
ondblclick={() => beginEdit(cell.row, cell.col)}
|
|
276
|
+
>
|
|
277
|
+
{#if editing && editing.row === cell.row && editing.col === cell.col}
|
|
278
|
+
<input
|
|
279
|
+
bind:this={editorEl}
|
|
280
|
+
data-mol-id="spreadsheet-grid-editor-{cell.ref}"
|
|
281
|
+
class={layout.editorClasses}
|
|
282
|
+
use:reactInputValue={{ value: editing.draft }}
|
|
283
|
+
oninput={handleDraftInput}
|
|
284
|
+
onblur={commitEdit}
|
|
285
|
+
onkeydown={handleEditorKeyDown}
|
|
286
|
+
aria-label={t(
|
|
287
|
+
'spreadsheetGrid.cellEditor',
|
|
288
|
+
{ ref: cell.ref },
|
|
289
|
+
{ defaultValue: 'Edit cell {{ref}}' },
|
|
290
|
+
)}
|
|
291
|
+
/>
|
|
292
|
+
{:else}
|
|
293
|
+
<div class={layout.contentClasses}>
|
|
294
|
+
{#if renderCell}{@render renderCell(cell.value, cell.ref)}{:else}{cell.text}{/if}
|
|
295
|
+
</div>
|
|
296
|
+
{/if}
|
|
297
|
+
</div>
|
|
298
|
+
{/snippet}
|
|
299
|
+
|
|
300
|
+
<div
|
|
301
|
+
data-mol-id={dataMolId ?? 'spreadsheet-grid'}
|
|
302
|
+
role="grid"
|
|
303
|
+
tabindex="0"
|
|
304
|
+
aria-rowcount={rows}
|
|
305
|
+
aria-colcount={columns}
|
|
306
|
+
aria-label={t('spreadsheetGrid.label', undefined, { defaultValue: 'Spreadsheet' })}
|
|
307
|
+
class={layout.rootClasses}
|
|
308
|
+
style={layout.rootStyle}
|
|
309
|
+
onkeydown={handleKeyDown}
|
|
310
|
+
onpaste={handlePasteEvent}
|
|
311
|
+
onmouseup={handleMouseUp}
|
|
312
|
+
>
|
|
313
|
+
<!-- Top-left corner (gutter × header). -->
|
|
314
|
+
<div aria-hidden="true" class={layout.cornerClasses} style={layout.cornerStyle}></div>
|
|
315
|
+
<!-- Column-letter header (frozen + scrollable). -->
|
|
316
|
+
<div role="row" aria-rowindex="1" class={layout.headerLaneClasses} style={layout.headerLaneStyle}>
|
|
317
|
+
{#each layout.frozenHeaderCells as header (header.key)}
|
|
318
|
+
<div
|
|
319
|
+
role="columnheader"
|
|
320
|
+
aria-colindex={header.index + 1}
|
|
321
|
+
class={header.classes}
|
|
322
|
+
style={header.style}
|
|
323
|
+
>
|
|
324
|
+
{header.text}
|
|
325
|
+
</div>
|
|
326
|
+
{/each}
|
|
327
|
+
<div style={layout.headerScrollerStyle}>
|
|
328
|
+
{#each layout.scrollingHeaderCells as header (header.key)}
|
|
329
|
+
<div
|
|
330
|
+
role="columnheader"
|
|
331
|
+
aria-colindex={header.index + 1}
|
|
332
|
+
class={header.classes}
|
|
333
|
+
style={header.style}
|
|
334
|
+
>
|
|
335
|
+
{header.text}
|
|
336
|
+
</div>
|
|
337
|
+
{/each}
|
|
338
|
+
</div>
|
|
339
|
+
</div>
|
|
340
|
+
<!-- Row-number gutter (frozen + scrollable). -->
|
|
341
|
+
<div aria-hidden="true" class={layout.gutterLaneClasses} style={layout.gutterLaneStyle}>
|
|
342
|
+
{#each layout.frozenGutterCells as label (label.key)}
|
|
343
|
+
<div class={label.classes} style={label.style}>{label.text}</div>
|
|
344
|
+
{/each}
|
|
345
|
+
<div style={layout.gutterScrollerStyle}>
|
|
346
|
+
{#each layout.scrollingGutterCells as label (label.key)}
|
|
347
|
+
<div class={label.classes} style={label.style}>{label.text}</div>
|
|
348
|
+
{/each}
|
|
349
|
+
</div>
|
|
350
|
+
</div>
|
|
351
|
+
<!-- Frozen-rows × scrolling-cols region. -->
|
|
352
|
+
{#if layout.showFrozenRows}
|
|
353
|
+
<div style={layout.frozenRowsRegionStyle}>
|
|
354
|
+
<div style={layout.frozenRowsInnerStyle}>
|
|
355
|
+
{#each layout.frozenRowsCells as cell (cell.ref)}{@render cellBox(cell)}{/each}
|
|
356
|
+
</div>
|
|
357
|
+
</div>
|
|
358
|
+
{/if}
|
|
359
|
+
<!-- Frozen-cols × scrolling-rows region. -->
|
|
360
|
+
{#if layout.showFrozenCols}
|
|
361
|
+
<div style={layout.frozenColsRegionStyle}>
|
|
362
|
+
<div style={layout.frozenColsInnerStyle}>
|
|
363
|
+
{#each layout.frozenColsCells as cell (cell.ref)}{@render cellBox(cell)}{/each}
|
|
364
|
+
</div>
|
|
365
|
+
</div>
|
|
366
|
+
{/if}
|
|
367
|
+
<!-- Frozen-rows × frozen-cols corner. -->
|
|
368
|
+
{#if layout.showFrozenCorner}
|
|
369
|
+
<div style={layout.frozenCornerStyle}>
|
|
370
|
+
{#each layout.frozenCornerCells as cell (cell.ref)}{@render cellBox(cell)}{/each}
|
|
371
|
+
</div>
|
|
372
|
+
{/if}
|
|
373
|
+
<!-- Main scrollable region. -->
|
|
374
|
+
<div
|
|
375
|
+
data-mol-id="spreadsheet-grid-scroll"
|
|
376
|
+
style={layout.scrollRegionStyle}
|
|
377
|
+
onscroll={handleScroll}
|
|
378
|
+
>
|
|
379
|
+
<div style={layout.scrollSpacerStyle}>
|
|
380
|
+
{#each layout.mainCells as cell (cell.ref)}{@render cellBox(cell)}{/each}
|
|
381
|
+
</div>
|
|
382
|
+
</div>
|
|
383
|
+
<!-- Hidden total-size hint for accessibility tooling. -->
|
|
384
|
+
<span class={layout.totalClasses} style={layout.totalStyle} aria-hidden="true"
|
|
385
|
+
>{layout.totalText}</span
|
|
386
|
+
>
|
|
387
|
+
</div>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SpreadsheetGridProps } from './types.js';
|
|
2
|
+
declare const SpreadsheetGrid: import("svelte").Component<SpreadsheetGridProps, {}, "">;
|
|
3
|
+
type SpreadsheetGrid = ReturnType<typeof SpreadsheetGrid>;
|
|
4
|
+
export default SpreadsheetGrid;
|
|
5
|
+
//# sourceMappingURL=SpreadsheetGrid.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpreadsheetGrid.svelte.d.ts","sourceRoot":"","sources":["../src/SpreadsheetGrid.svelte"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAa,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAoVjE,QAAA,MAAM,eAAe,0DAAwC,CAAC;AAC9D,KAAK,eAAe,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;AAC1D,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The package's components: one Svelte 5 component per React component in
|
|
3
|
+
* `@molecule/app-spreadsheet-grid-react`, under the same React name.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
export { default as SpreadsheetGrid } from './SpreadsheetGrid.svelte';
|
|
8
|
+
//# sourceMappingURL=components.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../src/components.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,0BAA0B,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-performance virtualized spreadsheet cell grid for Svelte.
|
|
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
|
+
* ```svelte
|
|
19
|
+
* <script lang="ts">
|
|
20
|
+
* import { SpreadsheetGrid } from '@molecule/app-spreadsheet-grid-svelte'
|
|
21
|
+
* import type { CellMap, SpreadsheetSelection } from '@molecule/app-spreadsheet-grid-svelte'
|
|
22
|
+
*
|
|
23
|
+
* let cells = $state<CellMap>(new Map())
|
|
24
|
+
* let selection = $state<SpreadsheetSelection>({ r1: 0, c1: 0, r2: 0, c2: 0 })
|
|
25
|
+
* </script>
|
|
26
|
+
*
|
|
27
|
+
* <SpreadsheetGrid
|
|
28
|
+
* rows={1000}
|
|
29
|
+
* columns={26}
|
|
30
|
+
* {cells}
|
|
31
|
+
* frozenRows={1}
|
|
32
|
+
* frozenCols={1}
|
|
33
|
+
* onCellChange={(ref, value) => {
|
|
34
|
+
* const next = new Map(cells)
|
|
35
|
+
* if (value === null) next.delete(ref)
|
|
36
|
+
* else next.set(ref, value)
|
|
37
|
+
* cells = next
|
|
38
|
+
* }}
|
|
39
|
+
* {selection}
|
|
40
|
+
* onSelectionChange={(next) => {
|
|
41
|
+
* selection = next
|
|
42
|
+
* }}
|
|
43
|
+
* />
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* - Must render with a ClassMap bond wired (`getClassMap()` throws
|
|
48
|
+
* otherwise), and inside the app's i18n provider (or with the bonded one).
|
|
49
|
+
* - The viewport is FIXED-PIXEL: `viewportWidth`/`viewportHeight`
|
|
50
|
+
* (defaults 720×360) — the grid does not auto-size to its container.
|
|
51
|
+
* Measure the container and pass px if you need it to fill.
|
|
52
|
+
* - Copy (Ctrl/Cmd+C) writes TSV through `copyTextWithFallback()` from
|
|
53
|
+
* `@molecule/app-clipboard`, which uses the bonded clipboard provider with
|
|
54
|
+
* a selection-and-copy fallback and never throws. Paste is handled through
|
|
55
|
+
* the native paste event, so the grid container must have focus (click a
|
|
56
|
+
* cell first). Keyboard support is Enter/F2 (edit) + copy/paste only; there
|
|
57
|
+
* is NO arrow-key cell navigation.
|
|
58
|
+
* - Committed edits and pasted cells auto-coerce number-like strings to
|
|
59
|
+
* numbers (`'42'` → `42`); empty string clears the cell (`null`).
|
|
60
|
+
* - Gridlines/selection/header styling uses Material-3 design-token
|
|
61
|
+
* utilities (`bg-surface`, `border-outline-variant`, …). Apps whose
|
|
62
|
+
* Tailwind theme does not define those tokens (the minimal scaffold
|
|
63
|
+
* theme does not) get a functional but unstyled grid.
|
|
64
|
+
*
|
|
65
|
+
* @module
|
|
66
|
+
*/
|
|
67
|
+
export * from './components.js';
|
|
68
|
+
export * from './types.js';
|
|
69
|
+
export * from './utilities.js';
|
|
70
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AAEH,cAAc,iBAAiB,CAAA;AAC/B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-performance virtualized spreadsheet cell grid for Svelte.
|
|
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
|
+
* ```svelte
|
|
19
|
+
* <script lang="ts">
|
|
20
|
+
* import { SpreadsheetGrid } from '@molecule/app-spreadsheet-grid-svelte'
|
|
21
|
+
* import type { CellMap, SpreadsheetSelection } from '@molecule/app-spreadsheet-grid-svelte'
|
|
22
|
+
*
|
|
23
|
+
* let cells = $state<CellMap>(new Map())
|
|
24
|
+
* let selection = $state<SpreadsheetSelection>({ r1: 0, c1: 0, r2: 0, c2: 0 })
|
|
25
|
+
* </script>
|
|
26
|
+
*
|
|
27
|
+
* <SpreadsheetGrid
|
|
28
|
+
* rows={1000}
|
|
29
|
+
* columns={26}
|
|
30
|
+
* {cells}
|
|
31
|
+
* frozenRows={1}
|
|
32
|
+
* frozenCols={1}
|
|
33
|
+
* onCellChange={(ref, value) => {
|
|
34
|
+
* const next = new Map(cells)
|
|
35
|
+
* if (value === null) next.delete(ref)
|
|
36
|
+
* else next.set(ref, value)
|
|
37
|
+
* cells = next
|
|
38
|
+
* }}
|
|
39
|
+
* {selection}
|
|
40
|
+
* onSelectionChange={(next) => {
|
|
41
|
+
* selection = next
|
|
42
|
+
* }}
|
|
43
|
+
* />
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* - Must render with a ClassMap bond wired (`getClassMap()` throws
|
|
48
|
+
* otherwise), and inside the app's i18n provider (or with the bonded one).
|
|
49
|
+
* - The viewport is FIXED-PIXEL: `viewportWidth`/`viewportHeight`
|
|
50
|
+
* (defaults 720×360) — the grid does not auto-size to its container.
|
|
51
|
+
* Measure the container and pass px if you need it to fill.
|
|
52
|
+
* - Copy (Ctrl/Cmd+C) writes TSV through `copyTextWithFallback()` from
|
|
53
|
+
* `@molecule/app-clipboard`, which uses the bonded clipboard provider with
|
|
54
|
+
* a selection-and-copy fallback and never throws. Paste is handled through
|
|
55
|
+
* the native paste event, so the grid container must have focus (click a
|
|
56
|
+
* cell first). Keyboard support is Enter/F2 (edit) + copy/paste only; there
|
|
57
|
+
* is NO arrow-key cell navigation.
|
|
58
|
+
* - Committed edits and pasted cells auto-coerce number-like strings to
|
|
59
|
+
* numbers (`'42'` → `42`); empty string clears the cell (`null`).
|
|
60
|
+
* - Gridlines/selection/header styling uses Material-3 design-token
|
|
61
|
+
* utilities (`bg-surface`, `border-outline-variant`, …). Apps whose
|
|
62
|
+
* Tailwind theme does not define those tokens (the minimal scaffold
|
|
63
|
+
* theme does not) get a functional but unstyled grid.
|
|
64
|
+
*
|
|
65
|
+
* @module
|
|
66
|
+
*/
|
|
67
|
+
export * from './components.js';
|
|
68
|
+
export * from './types.js';
|
|
69
|
+
export * from './utilities.js';
|