@20baht/spreadsheet 0.2.0 → 0.3.1
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/README.md +3 -2
- package/dist/book.d.ts +10 -2
- package/dist/book.js +9 -2
- package/dist/custom-elements.json +94 -3
- package/dist/elements/baht-spreadsheet.d.ts +15 -0
- package/dist/elements/baht-spreadsheet.js +95 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/parse.js +3 -1
- package/dist/session.d.ts +2 -1
- package/dist/session.js +9 -7
- package/dist/spreadsheet.css +4 -0
- package/dist/workbook.d.ts +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,9 +43,10 @@ download.onclick = async () => saveFile(await xlsx(bookWorkbook(el.book)), 'repo
|
|
|
43
43
|
- `load(source, sheet)` is called when a book is opened, a data sheet is added and on `refresh()`.
|
|
44
44
|
Never on a timer.
|
|
45
45
|
- `readonly`, `labels` (`SPREADSHEET_LABELS` has every word).
|
|
46
|
-
- Give the element a height: the grid scrolls inside it and draws only the rows in view
|
|
46
|
+
- Give the element a height: the grid scrolls inside it and draws only the rows in view, so a sheet may hold
|
|
47
|
+
up to 100 000 rows (a data sheet of 40 000 by 30 columns fills in half a second).
|
|
47
48
|
|
|
48
|
-
Worked like Excel: click or arrows to select, Shift for a rectangle, type to write, `=` for a formula,
|
|
49
|
+
Worked like Excel: click or arrows to select, Shift for a rectangle, a heading for its whole row or column, type to write, `=` for a formula,
|
|
49
50
|
F2 or a double click to edit, Delete to empty, Ctrl+B / I / U, Ctrl+Z / Y, copy and paste with Excel
|
|
50
51
|
and Google Sheets (TSV), drag a column's edge, double click a tab to rename it, right click a cell
|
|
51
52
|
to put rows and columns in or take them out (formulas follow), drag the square at the selection's
|
package/dist/book.d.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
export type CellValue = string | number | boolean;
|
|
3
3
|
export declare const ALIGNS: readonly ["left", "center", "right"];
|
|
4
4
|
export type CellAlign = (typeof ALIGNS)[number];
|
|
5
|
+
export declare const VALIGNS: readonly ["top", "middle", "bottom"];
|
|
6
|
+
export type CellVAlign = (typeof VALIGNS)[number];
|
|
5
7
|
/**
|
|
6
8
|
* How a number is shown: `number` 1,234.50, `integer` 1,235, `percent` 12.5%, and as a day counted
|
|
7
9
|
* from 1899-12-30 (`dates.ts`): `date` 2026-12-31, `datetime` 2026-12-31 14:30.
|
|
@@ -20,6 +22,8 @@ export interface CellStyle {
|
|
|
20
22
|
/** The background's colour, `#rrggbb`. */
|
|
21
23
|
fill?: string;
|
|
22
24
|
align?: CellAlign;
|
|
25
|
+
/** Up and down, in a cell taller than its text (a merged range): where left out, the middle. */
|
|
26
|
+
valign?: CellVAlign;
|
|
23
27
|
format?: NumberFormat;
|
|
24
28
|
/** The sides a thin line is drawn on, in the order of BORDER_SIDES. */
|
|
25
29
|
border?: BorderSide[];
|
|
@@ -64,7 +68,7 @@ export interface CellRange {
|
|
|
64
68
|
bottom: number;
|
|
65
69
|
right: number;
|
|
66
70
|
}
|
|
67
|
-
export declare const MAX_ROWS =
|
|
71
|
+
export declare const MAX_ROWS = 100000;
|
|
68
72
|
export declare const MAX_COLUMNS = 200;
|
|
69
73
|
export declare const MAX_SHEETS = 20;
|
|
70
74
|
/** The grid a sheet shows when it holds less. */
|
|
@@ -87,7 +91,11 @@ export declare function overlaps(a: CellRange, b: CellRange): boolean;
|
|
|
87
91
|
export declare function mergesOf(sheet: BookSheet): CellRange[];
|
|
88
92
|
/** The merged range a cell is part of. */
|
|
89
93
|
export declare function mergeAt(sheet: BookSheet, cell: CellPos): CellRange | null;
|
|
90
|
-
/**
|
|
94
|
+
/**
|
|
95
|
+
* How far the sheet's cells reach: the rows and columns that hold something. Counted once for
|
|
96
|
+
* each set of cells (a book is never changed in place), so a sheet of many thousand rows is not
|
|
97
|
+
* walked again each time it is drawn.
|
|
98
|
+
*/
|
|
91
99
|
export declare function extentOf(sheet: BookSheet): {
|
|
92
100
|
rows: number;
|
|
93
101
|
columns: number;
|
package/dist/book.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export const ALIGNS = ['left', 'center', 'right'];
|
|
2
|
+
export const VALIGNS = ['top', 'middle', 'bottom'];
|
|
2
3
|
export const NUMBER_FORMATS = ['number', 'integer', 'percent', 'date', 'datetime'];
|
|
3
4
|
export const BORDER_SIDES = ['top', 'right', 'bottom', 'left'];
|
|
4
|
-
export const MAX_ROWS =
|
|
5
|
+
export const MAX_ROWS = 100_000;
|
|
5
6
|
export const MAX_COLUMNS = 200;
|
|
6
7
|
export const MAX_SHEETS = 20;
|
|
7
8
|
export const DEFAULT_ROWS = 50;
|
|
@@ -65,7 +66,11 @@ export function mergesOf(sheet) {
|
|
|
65
66
|
export function mergeAt(sheet, cell) {
|
|
66
67
|
return mergesOf(sheet).find((range) => inRange(range, cell)) ?? null;
|
|
67
68
|
}
|
|
69
|
+
const EXTENTS = new WeakMap();
|
|
68
70
|
export function extentOf(sheet) {
|
|
71
|
+
const known = EXTENTS.get(sheet.cells);
|
|
72
|
+
if (known)
|
|
73
|
+
return known;
|
|
69
74
|
let rows = 0;
|
|
70
75
|
let columns = 0;
|
|
71
76
|
for (const address of Object.keys(sheet.cells)) {
|
|
@@ -75,7 +80,9 @@ export function extentOf(sheet) {
|
|
|
75
80
|
rows = Math.max(rows, cell.row + 1);
|
|
76
81
|
columns = Math.max(columns, cell.column + 1);
|
|
77
82
|
}
|
|
78
|
-
|
|
83
|
+
const extent = { rows, columns };
|
|
84
|
+
EXTENTS.set(sheet.cells, extent);
|
|
85
|
+
return extent;
|
|
79
86
|
}
|
|
80
87
|
export function sheetOf(book, key) {
|
|
81
88
|
return book.sheets.find((sheet) => sheet.key === key);
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"type": {
|
|
13
13
|
"text": "SpreadsheetLabels"
|
|
14
14
|
},
|
|
15
|
-
"default": "{ bold: 'Bold', italic: 'Italic', underline: 'Underline', textColor: 'Text colour', fillColor: 'Fill colour', noFill: 'No fill', alignLeft: 'Align left', alignCenter: 'Align centre', alignRight: 'Align right', borderAll: 'All borders', borderOuter: 'Outside borders', borderNone: 'No border', merge: 'Merge cells', unmerge: 'Unmerge cells', insertRow: 'Insert row above', insertColumn: 'Insert column left', removeRow: 'Delete row', removeColumn: 'Delete column', fillHandle: 'Drag to fill', format: 'Number format', formatGeneral: 'General', formatNumber: '1,234.50', formatInteger: '1,235', formatPercent: '12.5%', formatDate: '2026-12-31', formatDateTime: '2026-12-31 14:30', undo: 'Undo', redo: 'Redo', cell: 'Selected cells', formula: 'What the cell holds', addSheet: 'Add sheet', removeSheet: 'Remove sheet', renameSheet: 'Sheet name', dataSheet: 'Data', refresh: 'Refresh data', loading: 'Loading data…', loadFailed: 'The data could not be loaded.', readOnlyData: 'This sheet shows data as it is now. Use it from another sheet with a formula.', }"
|
|
15
|
+
"default": "{ bold: 'Bold', italic: 'Italic', underline: 'Underline', textColor: 'Text colour', fillColor: 'Fill colour', noFill: 'No fill', alignLeft: 'Align left', alignCenter: 'Align centre', alignRight: 'Align right', alignTop: 'Align top', alignMiddle: 'Align middle', alignBottom: 'Align bottom', selectAll: 'Select all', borderAll: 'All borders', borderOuter: 'Outside borders', borderNone: 'No border', merge: 'Merge cells', unmerge: 'Unmerge cells', insertRow: 'Insert row above', insertColumn: 'Insert column left', removeRow: 'Delete row', removeColumn: 'Delete column', fillHandle: 'Drag to fill', format: 'Number format', formatGeneral: 'General', formatNumber: '1,234.50', formatInteger: '1,235', formatPercent: '12.5%', formatDate: '2026-12-31', formatDateTime: '2026-12-31 14:30', undo: 'Undo', redo: 'Redo', cell: 'Selected cells', formula: 'What the cell holds', addSheet: 'Add sheet', removeSheet: 'Remove sheet', renameSheet: 'Sheet name', dataSheet: 'Data', refresh: 'Refresh data', loading: 'Loading data…', loadFailed: 'The data could not be loaded.', readOnlyData: 'This sheet shows data as it is now. Use it from another sheet with a formula.', }"
|
|
16
16
|
},
|
|
17
17
|
{
|
|
18
18
|
"kind": "class",
|
|
@@ -154,12 +154,23 @@
|
|
|
154
154
|
},
|
|
155
155
|
{
|
|
156
156
|
"kind": "field",
|
|
157
|
-
"name": "
|
|
157
|
+
"name": "whole",
|
|
158
158
|
"type": {
|
|
159
159
|
"text": "boolean"
|
|
160
160
|
},
|
|
161
161
|
"privacy": "private",
|
|
162
|
-
"default": "false"
|
|
162
|
+
"default": "false",
|
|
163
|
+
"description": "While a whole row or column is being selected."
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
"kind": "field",
|
|
167
|
+
"name": "dragging",
|
|
168
|
+
"type": {
|
|
169
|
+
"text": "false | 'cells' | Line['axis']"
|
|
170
|
+
},
|
|
171
|
+
"privacy": "private",
|
|
172
|
+
"default": "false",
|
|
173
|
+
"description": "What a held pointer is selecting: cells, or whole rows or columns from their headings."
|
|
163
174
|
},
|
|
164
175
|
{
|
|
165
176
|
"kind": "field",
|
|
@@ -403,6 +414,86 @@
|
|
|
403
414
|
}
|
|
404
415
|
]
|
|
405
416
|
},
|
|
417
|
+
{
|
|
418
|
+
"kind": "method",
|
|
419
|
+
"name": "lineOf",
|
|
420
|
+
"privacy": "private",
|
|
421
|
+
"return": {
|
|
422
|
+
"type": {
|
|
423
|
+
"text": "Line | 'all' | null"
|
|
424
|
+
}
|
|
425
|
+
},
|
|
426
|
+
"parameters": [
|
|
427
|
+
{
|
|
428
|
+
"name": "event",
|
|
429
|
+
"type": {
|
|
430
|
+
"text": "Event"
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
],
|
|
434
|
+
"description": "The row or column whose heading the pointer is on; `all` for the corner."
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
"kind": "method",
|
|
438
|
+
"name": "reach",
|
|
439
|
+
"privacy": "private",
|
|
440
|
+
"return": {
|
|
441
|
+
"type": {
|
|
442
|
+
"text": "CellPos"
|
|
443
|
+
}
|
|
444
|
+
},
|
|
445
|
+
"description": "How far a whole row or column goes: what the sheet holds, and no less than the grid starts with."
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
"kind": "method",
|
|
449
|
+
"name": "wholly",
|
|
450
|
+
"privacy": "private",
|
|
451
|
+
"return": {
|
|
452
|
+
"type": {
|
|
453
|
+
"text": "boolean"
|
|
454
|
+
}
|
|
455
|
+
},
|
|
456
|
+
"parameters": [
|
|
457
|
+
{
|
|
458
|
+
"name": "selection",
|
|
459
|
+
"type": {
|
|
460
|
+
"text": "CellRange"
|
|
461
|
+
}
|
|
462
|
+
},
|
|
463
|
+
{
|
|
464
|
+
"name": "line",
|
|
465
|
+
"type": {
|
|
466
|
+
"text": "Line"
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
],
|
|
470
|
+
"description": "Whether the selection is whole rows (or columns) and `line` is one of them."
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
"kind": "method",
|
|
474
|
+
"name": "selectLine",
|
|
475
|
+
"privacy": "private",
|
|
476
|
+
"return": {
|
|
477
|
+
"type": {
|
|
478
|
+
"text": "void"
|
|
479
|
+
}
|
|
480
|
+
},
|
|
481
|
+
"parameters": [
|
|
482
|
+
{
|
|
483
|
+
"name": "line",
|
|
484
|
+
"type": {
|
|
485
|
+
"text": "Line | 'all'"
|
|
486
|
+
}
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
"name": "extend",
|
|
490
|
+
"type": {
|
|
491
|
+
"text": "boolean"
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
],
|
|
495
|
+
"description": "A whole row or column selected; with `extend`, every one from the active cell's to it."
|
|
496
|
+
},
|
|
406
497
|
{
|
|
407
498
|
"kind": "field",
|
|
408
499
|
"name": "pointerDown",
|
|
@@ -13,6 +13,10 @@ export interface SpreadsheetLabels {
|
|
|
13
13
|
alignLeft: string;
|
|
14
14
|
alignCenter: string;
|
|
15
15
|
alignRight: string;
|
|
16
|
+
alignTop: string;
|
|
17
|
+
alignMiddle: string;
|
|
18
|
+
alignBottom: string;
|
|
19
|
+
selectAll: string;
|
|
16
20
|
borderAll: string;
|
|
17
21
|
borderOuter: string;
|
|
18
22
|
borderNone: string;
|
|
@@ -82,6 +86,9 @@ export declare class BahtSpreadsheet extends BahtElement {
|
|
|
82
86
|
private ownValue;
|
|
83
87
|
/** The book's data sheets are to be loaded after this update. */
|
|
84
88
|
private stale;
|
|
89
|
+
/** While a whole row or column is being selected. */
|
|
90
|
+
private whole;
|
|
91
|
+
/** What a held pointer is selecting: cells, or whole rows or columns from their headings. */
|
|
85
92
|
private dragging;
|
|
86
93
|
private computed;
|
|
87
94
|
/** The book with what its data sheets hold now: what `bookWorkbook()` takes for a file. */
|
|
@@ -113,6 +120,14 @@ export declare class BahtSpreadsheet extends BahtElement {
|
|
|
113
120
|
private copy;
|
|
114
121
|
private paste;
|
|
115
122
|
private placeOf;
|
|
123
|
+
/** The row or column whose heading the pointer is on; `all` for the corner. */
|
|
124
|
+
private lineOf;
|
|
125
|
+
/** How far a whole row or column goes: what the sheet holds, and no less than the grid starts with. */
|
|
126
|
+
private reach;
|
|
127
|
+
/** Whether the selection is whole rows (or columns) and `line` is one of them. */
|
|
128
|
+
private wholly;
|
|
129
|
+
/** A whole row or column selected; with `extend`, every one from the active cell's to it. */
|
|
130
|
+
private selectLine;
|
|
116
131
|
private pointerDown;
|
|
117
132
|
/** The fill handle pressed: the selection is spread as far as it is dragged, along one way. */
|
|
118
133
|
private fillStart;
|
|
@@ -23,6 +23,10 @@ export const SPREADSHEET_LABELS = {
|
|
|
23
23
|
alignLeft: 'Align left',
|
|
24
24
|
alignCenter: 'Align centre',
|
|
25
25
|
alignRight: 'Align right',
|
|
26
|
+
alignTop: 'Align top',
|
|
27
|
+
alignMiddle: 'Align middle',
|
|
28
|
+
alignBottom: 'Align bottom',
|
|
29
|
+
selectAll: 'Select all',
|
|
26
30
|
borderAll: 'All borders',
|
|
27
31
|
borderOuter: 'Outside borders',
|
|
28
32
|
borderNone: 'No border',
|
|
@@ -97,6 +101,11 @@ const ALIGN_PATHS = {
|
|
|
97
101
|
center: 'M2 3h12M4.5 6.5h7M2 10h12M4.5 13.5h7',
|
|
98
102
|
right: 'M2 3h12M7 6.5h7M2 10h12M7 13.5h7',
|
|
99
103
|
};
|
|
104
|
+
const VALIGN_PATHS = {
|
|
105
|
+
top: 'M2 2.5h12M8 14V6M5 9l3-3 3 3',
|
|
106
|
+
middle: 'M2 8h12M8 1.5v4M6 3.5l2 2 2-2M8 14.5v-4M6 12.5l2-2 2 2',
|
|
107
|
+
bottom: 'M2 13.5h12M8 2v8M5 7l3 3 3-3',
|
|
108
|
+
};
|
|
100
109
|
const BORDERS = [
|
|
101
110
|
{ sides: 'all', label: 'borderAll', path: 'M2 2h12v12H2zM8 2v12M2 8h12' },
|
|
102
111
|
{ sides: 'outer', label: 'borderOuter', path: 'M2 2h12v12H2z' },
|
|
@@ -152,6 +161,7 @@ let BahtSpreadsheet = class BahtSpreadsheet extends BahtElement {
|
|
|
152
161
|
this.menu = null;
|
|
153
162
|
this.ownValue = false;
|
|
154
163
|
this.stale = false;
|
|
164
|
+
this.whole = false;
|
|
155
165
|
this.dragging = false;
|
|
156
166
|
this.computed = null;
|
|
157
167
|
this.scrolled = (event) => {
|
|
@@ -218,13 +228,22 @@ let BahtSpreadsheet = class BahtSpreadsheet extends BahtElement {
|
|
|
218
228
|
this.send({ type: 'paste', cells: fromTsv(text) });
|
|
219
229
|
};
|
|
220
230
|
this.pointerDown = (event) => {
|
|
221
|
-
|
|
222
|
-
|
|
231
|
+
if (event.target.closest('.baht-spreadsheet-editor'))
|
|
232
|
+
return;
|
|
233
|
+
const line = this.lineOf(event);
|
|
234
|
+
const cell = line ? null : this.placeOf(event);
|
|
235
|
+
if (!line && !cell)
|
|
223
236
|
return;
|
|
224
237
|
if (this.session.editing !== null)
|
|
225
238
|
this.send({ type: 'commit' });
|
|
226
|
-
|
|
227
|
-
|
|
239
|
+
if (line) {
|
|
240
|
+
this.dragging = line === 'all' ? false : line.axis;
|
|
241
|
+
this.selectLine(line, event.shiftKey);
|
|
242
|
+
}
|
|
243
|
+
else if (cell) {
|
|
244
|
+
this.dragging = 'cells';
|
|
245
|
+
this.send({ type: 'select', cell, extend: event.shiftKey });
|
|
246
|
+
}
|
|
228
247
|
this.grid()?.focus();
|
|
229
248
|
event.preventDefault();
|
|
230
249
|
};
|
|
@@ -254,19 +273,31 @@ let BahtSpreadsheet = class BahtSpreadsheet extends BahtElement {
|
|
|
254
273
|
this.dragging = false;
|
|
255
274
|
return;
|
|
256
275
|
}
|
|
276
|
+
if (this.dragging !== 'cells') {
|
|
277
|
+
const line = this.lineOf(event);
|
|
278
|
+
const head = line !== null && line !== 'all' && line.axis === this.dragging ? line.index : undefined;
|
|
279
|
+
const index = head ?? this.placeOf(event)?.[this.dragging];
|
|
280
|
+
if (index !== undefined)
|
|
281
|
+
this.selectLine({ axis: this.dragging, index }, true);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
257
284
|
const cell = this.placeOf(event);
|
|
258
285
|
if (cell)
|
|
259
286
|
this.send({ type: 'select', cell, extend: true });
|
|
260
287
|
};
|
|
261
288
|
this.contextMenu = (event) => {
|
|
289
|
+
const line = this.lineOf(event);
|
|
262
290
|
const cell = this.placeOf(event);
|
|
263
291
|
const sheet = shownSheet(this.session);
|
|
264
|
-
if (!cell || !sheet || sheet.source || this.readonly)
|
|
292
|
+
if ((!cell && !line) || line === 'all' || !sheet || sheet.source || this.readonly)
|
|
265
293
|
return;
|
|
266
294
|
event.preventDefault();
|
|
267
295
|
const selection = selectionOf(this.session);
|
|
268
|
-
|
|
269
|
-
|
|
296
|
+
if (line) {
|
|
297
|
+
if (!this.wholly(selection, line))
|
|
298
|
+
this.selectLine(line, false);
|
|
299
|
+
}
|
|
300
|
+
else if (cell && !holds(selection, cell))
|
|
270
301
|
this.send({ type: 'select', cell });
|
|
271
302
|
const box = this.getBoundingClientRect();
|
|
272
303
|
this.menu = { x: event.clientX - box.left, y: event.clientY - box.top };
|
|
@@ -342,9 +373,12 @@ let BahtSpreadsheet = class BahtSpreadsheet extends BahtElement {
|
|
|
342
373
|
send(msg) {
|
|
343
374
|
if (this.readonly && WRITES.has(msg.type))
|
|
344
375
|
return;
|
|
376
|
+
const { end } = this.session;
|
|
345
377
|
const { state: next, changed } = updateBook(this.session, msg);
|
|
346
378
|
this.session = next;
|
|
347
|
-
|
|
379
|
+
const moved = next.end.row !== end.row || next.end.column !== end.column;
|
|
380
|
+
if (moved && !this.whole)
|
|
381
|
+
this.reveal();
|
|
348
382
|
if (!changed)
|
|
349
383
|
return;
|
|
350
384
|
this.ownValue = true;
|
|
@@ -400,6 +434,8 @@ let BahtSpreadsheet = class BahtSpreadsheet extends BahtElement {
|
|
|
400
434
|
this.toggle('underline');
|
|
401
435
|
else if (key === 'd' || key === 'r')
|
|
402
436
|
this.fillFromEdge(key === 'd');
|
|
437
|
+
else if (key === 'a')
|
|
438
|
+
this.selectLine('all', false);
|
|
403
439
|
else
|
|
404
440
|
return false;
|
|
405
441
|
return true;
|
|
@@ -415,6 +451,48 @@ let BahtSpreadsheet = class BahtSpreadsheet extends BahtElement {
|
|
|
415
451
|
return null;
|
|
416
452
|
return { row: Number(cell.dataset.row), column: Number(cell.dataset.column) };
|
|
417
453
|
}
|
|
454
|
+
lineOf(event) {
|
|
455
|
+
const target = event.target;
|
|
456
|
+
if (target.closest('.baht-spreadsheet-resize'))
|
|
457
|
+
return null;
|
|
458
|
+
const head = target.closest('th');
|
|
459
|
+
if (!head)
|
|
460
|
+
return null;
|
|
461
|
+
if (head.dataset.column !== undefined)
|
|
462
|
+
return { axis: 'column', index: Number(head.dataset.column) };
|
|
463
|
+
if (head.dataset.row !== undefined)
|
|
464
|
+
return { axis: 'row', index: Number(head.dataset.row) };
|
|
465
|
+
return 'all';
|
|
466
|
+
}
|
|
467
|
+
reach() {
|
|
468
|
+
const sheet = shownSheet(this.session);
|
|
469
|
+
const extent = sheet ? extentOf(sheet) : { rows: 0, columns: 0 };
|
|
470
|
+
return {
|
|
471
|
+
row: Math.max(DEFAULT_ROWS, extent.rows) - 1,
|
|
472
|
+
column: Math.max(DEFAULT_COLUMNS, extent.columns) - 1,
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
wholly(selection, line) {
|
|
476
|
+
const far = this.reach();
|
|
477
|
+
return line.axis === 'row'
|
|
478
|
+
? selection.left === 0 &&
|
|
479
|
+
selection.right >= far.column &&
|
|
480
|
+
line.index >= selection.top &&
|
|
481
|
+
line.index <= selection.bottom
|
|
482
|
+
: selection.top === 0 &&
|
|
483
|
+
selection.bottom >= far.row &&
|
|
484
|
+
line.index >= selection.left &&
|
|
485
|
+
line.index <= selection.right;
|
|
486
|
+
}
|
|
487
|
+
selectLine(line, extend) {
|
|
488
|
+
const far = this.reach();
|
|
489
|
+
const from = line === 'all' ? 0 : extend ? this.session.active[line.axis] : line.index;
|
|
490
|
+
const to = line === 'all' ? far : { ...far, [line.axis]: line.index };
|
|
491
|
+
const cell = line !== 'all' && line.axis === 'row' ? { row: from, column: 0 } : { row: 0, column: from };
|
|
492
|
+
this.whole = true;
|
|
493
|
+
this.send({ type: 'select', cell, to });
|
|
494
|
+
this.whole = false;
|
|
495
|
+
}
|
|
418
496
|
fillTo(from, cell) {
|
|
419
497
|
const rows = Math.max(from.top - cell.row, cell.row - from.bottom, 0);
|
|
420
498
|
const columns = Math.max(from.left - cell.column, cell.column - from.right, 0);
|
|
@@ -540,6 +618,9 @@ let BahtSpreadsheet = class BahtSpreadsheet extends BahtElement {
|
|
|
540
618
|
const align = (to, label) => this.tool(label, icon(ALIGN_PATHS[to]), () => {
|
|
541
619
|
this.look({ align: style.align === to ? null : to });
|
|
542
620
|
}, { name: `align-${to}`, pressed: style.align === to, disabled: locked });
|
|
621
|
+
const valign = (to, label) => this.tool(label, icon(VALIGN_PATHS[to]), () => {
|
|
622
|
+
this.look({ valign: style.valign === to ? null : to });
|
|
623
|
+
}, { name: `valign-${to}`, pressed: style.valign === to, disabled: locked });
|
|
543
624
|
return html `<div class="baht-spreadsheet-tools" role="toolbar">
|
|
544
625
|
${this.tool(words.undo, icon('M6 3 2.5 6.5 6 10M3 6.5h6.5a4 4 0 0 1 0 8H7'), () => {
|
|
545
626
|
this.send({ type: 'undo' });
|
|
@@ -557,6 +638,8 @@ let BahtSpreadsheet = class BahtSpreadsheet extends BahtElement {
|
|
|
557
638
|
<span class="baht-spreadsheet-gap"></span>
|
|
558
639
|
${align('left', words.alignLeft)} ${align('center', words.alignCenter)}
|
|
559
640
|
${align('right', words.alignRight)}
|
|
641
|
+
${valign('top', words.alignTop)} ${valign('middle', words.alignMiddle)}
|
|
642
|
+
${valign('bottom', words.alignBottom)}
|
|
560
643
|
<span class="baht-spreadsheet-gap"></span>
|
|
561
644
|
${BORDERS.map((item) => this.tool(words[item.label], icon(item.path), () => {
|
|
562
645
|
this.send({ type: 'border', sides: item.sides });
|
|
@@ -684,9 +767,10 @@ let BahtSpreadsheet = class BahtSpreadsheet extends BahtElement {
|
|
|
684
767
|
</colgroup>
|
|
685
768
|
<thead>
|
|
686
769
|
<tr>
|
|
687
|
-
<th class="baht-spreadsheet-corner"></th>
|
|
770
|
+
<th class="baht-spreadsheet-corner" aria-label=${this.words.selectAll}></th>
|
|
688
771
|
${numbers.map((column) => html `<th
|
|
689
772
|
scope="col"
|
|
773
|
+
data-column=${column}
|
|
690
774
|
?data-selected=${column >= selection.left && column <= selection.right}
|
|
691
775
|
>
|
|
692
776
|
${columnName(column)}
|
|
@@ -721,7 +805,7 @@ let BahtSpreadsheet = class BahtSpreadsheet extends BahtElement {
|
|
|
721
805
|
row(sheet, row, columns, view) {
|
|
722
806
|
const { selection } = view;
|
|
723
807
|
return html `<tr aria-rowindex=${row + 1}>
|
|
724
|
-
<th scope="row" ?data-selected=${row >= selection.top && row <= selection.bottom}>
|
|
808
|
+
<th scope="row" data-row=${row} ?data-selected=${row >= selection.top && row <= selection.bottom}>
|
|
725
809
|
${row + 1}
|
|
726
810
|
</th>
|
|
727
811
|
${columns.map((column) => {
|
|
@@ -774,6 +858,7 @@ let BahtSpreadsheet = class BahtSpreadsheet extends BahtElement {
|
|
|
774
858
|
style.underline === true ? 'text-decoration:underline' : '',
|
|
775
859
|
`color:${style.color ?? (style.fill === undefined ? '' : inkOn(style.fill))}`,
|
|
776
860
|
style.fill === undefined ? '' : `background-color:${style.fill}`,
|
|
861
|
+
style.valign === undefined ? '' : `vertical-align:${style.valign}`,
|
|
777
862
|
align === undefined ? '' : `text-align:${align}`,
|
|
778
863
|
...this.lines(sheet, at, style.border),
|
|
779
864
|
]
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { addressOf, ALIGNS, BORDER_SIDES, columnIndex, columnName, DEFAULT_COLUMNS, DEFAULT_ROWS, DEFAULT_WIDTH, emptyBook, extentOf, MAX_COLUMNS, MAX_ROWS, MAX_SHEETS, mergeAt, mergesOf, NUMBER_FORMATS, parseAddress, parseRange, rangeName, rangeOf, sheetOf, type Book, type BookCell, type BookSheet, type BookSource, type BorderSide, type CellAlign, type CellPos, type CellRange, type CellStyle, type CellValue, type NumberFormat, } from './book.js';
|
|
1
|
+
export { addressOf, ALIGNS, VALIGNS, BORDER_SIDES, columnIndex, columnName, DEFAULT_COLUMNS, DEFAULT_ROWS, DEFAULT_WIDTH, emptyBook, extentOf, MAX_COLUMNS, MAX_ROWS, MAX_SHEETS, mergeAt, mergesOf, NUMBER_FORMATS, parseAddress, parseRange, rangeName, rangeOf, sheetOf, type Book, type BookCell, type BookSheet, type BookSource, type BorderSide, type CellAlign, type CellVAlign, type CellPos, type CellRange, type CellStyle, type CellValue, type NumberFormat, } from './book.js';
|
|
2
2
|
export { ERRORS, evaluate, FUNCTIONS, isError, parseFormula, type ErrorCode, type FormulaError, type FormulaNode, type FormulaScope, type Scalar, } from './formula.js';
|
|
3
3
|
export { dateSerial, dateText, parseDateText, serialOf, serialParts } from './dates.js';
|
|
4
4
|
export { cellInput, computeBook, displayText, inputText, type BookValues } from './compute.js';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { addressOf, ALIGNS, BORDER_SIDES, columnIndex, columnName, DEFAULT_COLUMNS, DEFAULT_ROWS, DEFAULT_WIDTH, emptyBook, extentOf, MAX_COLUMNS, MAX_ROWS, MAX_SHEETS, mergeAt, mergesOf, NUMBER_FORMATS, parseAddress, parseRange, rangeName, rangeOf, sheetOf, } from './book.js';
|
|
1
|
+
export { addressOf, ALIGNS, VALIGNS, BORDER_SIDES, columnIndex, columnName, DEFAULT_COLUMNS, DEFAULT_ROWS, DEFAULT_WIDTH, emptyBook, extentOf, MAX_COLUMNS, MAX_ROWS, MAX_SHEETS, mergeAt, mergesOf, NUMBER_FORMATS, parseAddress, parseRange, rangeName, rangeOf, sheetOf, } from './book.js';
|
|
2
2
|
export { ERRORS, evaluate, FUNCTIONS, isError, parseFormula, } from './formula.js';
|
|
3
3
|
export { dateSerial, dateText, parseDateText, serialOf, serialParts } from './dates.js';
|
|
4
4
|
export { cellInput, computeBook, displayText, inputText } from './compute.js';
|
package/dist/parse.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ALIGNS, BORDER_SIDES, MAX_COLUMNS, MAX_ROWS, MAX_SHEETS, NUMBER_FORMATS, overlaps, parseAddress, parseRange, } from './book.js';
|
|
1
|
+
import { ALIGNS, VALIGNS, BORDER_SIDES, MAX_COLUMNS, MAX_ROWS, MAX_SHEETS, NUMBER_FORMATS, overlaps, parseAddress, parseRange, } from './book.js';
|
|
2
2
|
const COLOR = /^#[0-9a-fA-F]{6}$/;
|
|
3
3
|
const KEY = /^[A-Za-z0-9_-]{1,64}$/;
|
|
4
4
|
const UNSAFE = new Set(['__proto__', 'constructor', 'prototype']);
|
|
@@ -58,6 +58,7 @@ class Gate {
|
|
|
58
58
|
const color = this.#colour(value.color, `${path}.color`);
|
|
59
59
|
const fill = this.#colour(value.fill, `${path}.fill`);
|
|
60
60
|
const align = this.#oneOf(value.align, ALIGNS, `${path}.align`);
|
|
61
|
+
const valign = this.#oneOf(value.valign, VALIGNS, `${path}.valign`);
|
|
61
62
|
const format = this.#oneOf(value.format, NUMBER_FORMATS, `${path}.format`);
|
|
62
63
|
const border = this.#sides(value.border, `${path}.border`);
|
|
63
64
|
const style = {
|
|
@@ -67,6 +68,7 @@ class Gate {
|
|
|
67
68
|
...(color === undefined ? {} : { color }),
|
|
68
69
|
...(fill === undefined ? {} : { fill }),
|
|
69
70
|
...(align === undefined ? {} : { align }),
|
|
71
|
+
...(valign === undefined ? {} : { valign }),
|
|
70
72
|
...(format === undefined ? {} : { format }),
|
|
71
73
|
...(border === undefined ? {} : { border }),
|
|
72
74
|
};
|
package/dist/session.d.ts
CHANGED
|
@@ -29,11 +29,12 @@ export type BookMsg =
|
|
|
29
29
|
type: 'show';
|
|
30
30
|
sheet: string;
|
|
31
31
|
}
|
|
32
|
-
/** A click (`extend`: with Shift, or a drag). */
|
|
32
|
+
/** A click (`extend`: with Shift, or a drag). With `to`, a range from `cell` to there: a whole row or column. */
|
|
33
33
|
| {
|
|
34
34
|
type: 'select';
|
|
35
35
|
cell: CellPos;
|
|
36
36
|
extend?: boolean;
|
|
37
|
+
to?: CellPos;
|
|
37
38
|
}
|
|
38
39
|
/** An arrow key. `extend`: with Shift. */
|
|
39
40
|
| {
|
package/dist/session.js
CHANGED
|
@@ -377,17 +377,19 @@ function restructured(state, sheet, axis, remove) {
|
|
|
377
377
|
return rewritten(state, book, { active, end: active, editing: null });
|
|
378
378
|
}
|
|
379
379
|
const READS = new Set(['select', 'move', 'cancel', 'width']);
|
|
380
|
+
function picked(state, sheet, msg) {
|
|
381
|
+
const cell = within(msg.cell);
|
|
382
|
+
if (msg.extend === true)
|
|
383
|
+
return { ...state, end: cell, editing: null };
|
|
384
|
+
const active = anchorOf(sheet, cell);
|
|
385
|
+
return { ...state, active, end: msg.to ? within(msg.to) : active, editing: null };
|
|
386
|
+
}
|
|
380
387
|
function onSheet(state, sheet, msg) {
|
|
381
388
|
if (sheet.source && !READS.has(msg.type))
|
|
382
389
|
return same(state);
|
|
383
390
|
switch (msg.type) {
|
|
384
|
-
case 'select':
|
|
385
|
-
|
|
386
|
-
if (msg.extend === true)
|
|
387
|
-
return same({ ...state, end: cell, editing: null });
|
|
388
|
-
const active = anchorOf(sheet, cell);
|
|
389
|
-
return same({ ...state, active, end: active, editing: null });
|
|
390
|
-
}
|
|
391
|
+
case 'select':
|
|
392
|
+
return same(picked(state, sheet, msg));
|
|
391
393
|
case 'move': {
|
|
392
394
|
if (msg.extend === true)
|
|
393
395
|
return same({ ...state, end: stepped(sheet, state.end, msg.direction) });
|
package/dist/spreadsheet.css
CHANGED
package/dist/workbook.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Book, type BorderSide, type CellAlign } from './book.js';
|
|
1
|
+
import { type Book, type BorderSide, type CellAlign, type CellVAlign } from './book.js';
|
|
2
2
|
export interface WorkbookCell {
|
|
3
3
|
/** What the cell holds; for a formula, what it works out to here (a file's reader works it out again). */
|
|
4
4
|
value: string | number | boolean | null;
|
|
@@ -11,6 +11,7 @@ export interface WorkbookCell {
|
|
|
11
11
|
color?: string;
|
|
12
12
|
fill?: string;
|
|
13
13
|
align?: CellAlign;
|
|
14
|
+
valign?: CellVAlign;
|
|
14
15
|
/** The sides a thin line is drawn on. */
|
|
15
16
|
border?: BorderSide[];
|
|
16
17
|
/** An Excel number format. */
|