@20baht/spreadsheet 0.1.0 → 0.2.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/README.md +9 -5
- package/dist/book.d.ts +10 -2
- package/dist/book.js +2 -1
- package/dist/compute.d.ts +8 -3
- package/dist/compute.js +11 -0
- package/dist/custom-elements.json +153 -1
- package/dist/dates.d.ts +22 -0
- package/dist/dates.js +53 -0
- package/dist/elements/baht-spreadsheet.d.ts +33 -0
- package/dist/elements/baht-spreadsheet.js +196 -6
- package/dist/formula.d.ts +1 -1
- package/dist/formula.js +82 -3
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/parse.js +13 -1
- package/dist/refs.d.ts +43 -0
- package/dist/refs.js +120 -0
- package/dist/session.d.ts +26 -1
- package/dist/session.js +190 -10
- package/dist/spreadsheet.css +57 -2
- package/dist/workbook.d.ts +3 -1
- package/dist/workbook.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@ el.value = saved ?? emptyBook();
|
|
|
30
30
|
// a data sheet's source is yours: a name and what you need to answer it
|
|
31
31
|
el.load = async (source) => {
|
|
32
32
|
const records = await api.query(source.name, source.params);
|
|
33
|
+
// a Date in a row becomes a date cell
|
|
33
34
|
return { columns: ['Number', 'Status', 'Hours'], rows: records.map((r) => [r.id, r.status, r.hours]) };
|
|
34
35
|
};
|
|
35
36
|
el.addEventListener('baht-change', (event) => save(event.detail.value)); // saved without the data
|
|
@@ -46,14 +47,16 @@ download.onclick = async () => saveFile(await xlsx(bookWorkbook(el.book)), 'repo
|
|
|
46
47
|
|
|
47
48
|
Worked like Excel: click or arrows to select, Shift for a rectangle, type to write, `=` for a formula,
|
|
48
49
|
F2 or a double click to edit, Delete to empty, Ctrl+B / I / U, Ctrl+Z / Y, copy and paste with Excel
|
|
49
|
-
and Google Sheets (TSV), drag a column's edge, double click a tab to rename it
|
|
50
|
+
and Google Sheets (TSV), drag a column's edge, double click a tab to rename it, right click a cell
|
|
51
|
+
to put rows and columns in or take them out (formulas follow), drag the square at the selection's
|
|
52
|
+
corner (or Ctrl+D / Ctrl+R) to copy formulas along.
|
|
50
53
|
|
|
51
54
|
## Formulas
|
|
52
55
|
|
|
53
56
|
Excel's spelling, so the .xlsx carries the same formula: `+ - * / ^ &`, the comparisons, `%`, cells
|
|
54
57
|
(`B3`), ranges (`A1:B9`, `A:A`), another sheet (`Data!A:A`, `'My data'!B2`) and
|
|
55
|
-
`SUM` `AVERAGE` `MIN` `MAX` `COUNT` `COUNTA` `COUNTIF` `SUMIF` `IF` `AND` `OR` `NOT` `ROUND` `ABS
|
|
56
|
-
Errors show in the cell: `#DIV/0!` `#NAME?` `#REF!` `#VALUE!` `#CYCLE!` `#ERROR!`.
|
|
58
|
+
`SUM` `AVERAGE` `MIN` `MAX` `COUNT` `COUNTA` `COUNTIF` `SUMIF` `IF` `IFERROR` `AND` `OR` `NOT` `ROUND` `ABS`
|
|
59
|
+
`VLOOKUP` `DATE` `TODAY` `NOW` `YEAR` `MONTH` `DAY`. Errors show in the cell: `#DIV/0!` `#NAME?` `#REF!` `#VALUE!` `#N/A` `#CYCLE!` `#ERROR!`.
|
|
57
60
|
|
|
58
61
|
```ts
|
|
59
62
|
import { computeBook, displayText } from '@20baht/spreadsheet';
|
|
@@ -71,10 +74,11 @@ No DOM, no Lit, for a server, a test or an agent:
|
|
|
71
74
|
| `computeBook(book)` · `displayText` · `parseFormula` · `evaluate` · `FUNCTIONS` | formulas |
|
|
72
75
|
| `openBook` · `updateBook(state, msg)` · `selectionOf` · `copied` · `savedBook` | the grid session, pure |
|
|
73
76
|
| `cellInput(text)` · `inputText(cell)` | typed text → a cell, and back |
|
|
77
|
+
| `rewriteRefs` · `movedRefs` · `shiftedRefs` · `renamedRefs` | a formula's references written again |
|
|
74
78
|
| `toTsv` · `fromTsv` | the clipboard's text |
|
|
75
79
|
| `bookWorkbook(book)` | each sheet as a `LaidSheet` for `@20baht/export`'s `xlsx()` |
|
|
76
80
|
|
|
77
81
|
## Not yet
|
|
78
82
|
|
|
79
|
-
|
|
80
|
-
lookups
|
|
83
|
+
Wrapped text,
|
|
84
|
+
the other lookups, charts, reading an .xlsx in. Spec 12 §7.
|
package/dist/book.d.ts
CHANGED
|
@@ -2,9 +2,15 @@
|
|
|
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
|
-
/**
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* How a number is shown: `number` 1,234.50, `integer` 1,235, `percent` 12.5%, and as a day counted
|
|
7
|
+
* from 1899-12-30 (`dates.ts`): `date` 2026-12-31, `datetime` 2026-12-31 14:30.
|
|
8
|
+
*/
|
|
9
|
+
export declare const NUMBER_FORMATS: readonly ["number", "integer", "percent", "date", "datetime"];
|
|
7
10
|
export type NumberFormat = (typeof NUMBER_FORMATS)[number];
|
|
11
|
+
/** A side of a cell a line is drawn on. */
|
|
12
|
+
export declare const BORDER_SIDES: readonly ["top", "right", "bottom", "left"];
|
|
13
|
+
export type BorderSide = (typeof BORDER_SIDES)[number];
|
|
8
14
|
export interface CellStyle {
|
|
9
15
|
bold?: boolean;
|
|
10
16
|
italic?: boolean;
|
|
@@ -15,6 +21,8 @@ export interface CellStyle {
|
|
|
15
21
|
fill?: string;
|
|
16
22
|
align?: CellAlign;
|
|
17
23
|
format?: NumberFormat;
|
|
24
|
+
/** The sides a thin line is drawn on, in the order of BORDER_SIDES. */
|
|
25
|
+
border?: BorderSide[];
|
|
18
26
|
}
|
|
19
27
|
export interface BookCell {
|
|
20
28
|
value?: CellValue;
|
package/dist/book.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export const ALIGNS = ['left', 'center', 'right'];
|
|
2
|
-
export const NUMBER_FORMATS = ['number', 'integer', 'percent'];
|
|
2
|
+
export const NUMBER_FORMATS = ['number', 'integer', 'percent', 'date', 'datetime'];
|
|
3
|
+
export const BORDER_SIDES = ['top', 'right', 'bottom', 'left'];
|
|
3
4
|
export const MAX_ROWS = 10_000;
|
|
4
5
|
export const MAX_COLUMNS = 200;
|
|
5
6
|
export const MAX_SHEETS = 20;
|
package/dist/compute.d.ts
CHANGED
|
@@ -8,10 +8,15 @@ export interface BookValues {
|
|
|
8
8
|
export declare function computeBook(book: Book): BookValues;
|
|
9
9
|
/** A value as its cell shows it: a number in the cell's format, an error as its code. */
|
|
10
10
|
export declare function displayText(value: Scalar, style?: CellStyle): string;
|
|
11
|
+
/** What typing puts into a cell, and for a date the format that shows it as one. */
|
|
12
|
+
export type TypedCell = Pick<BookCell, 'value' | 'formula'> & {
|
|
13
|
+
format?: 'date' | 'datetime';
|
|
14
|
+
};
|
|
11
15
|
/**
|
|
12
|
-
* What typing `text` into a cell puts there: a formula after `=`, a number (`1,234.5`, `12%`),
|
|
13
|
-
*
|
|
16
|
+
* What typing `text` into a cell puts there: a formula after `=`, a number (`1,234.5`, `12%`), a
|
|
17
|
+
* date (`2026-12-31`, `31/12/2026`, with `14:30` after it: its serial, and the `format` to show
|
|
18
|
+
* it), TRUE / FALSE, otherwise the text; after `'` always the text. Nothing for an empty text.
|
|
14
19
|
*/
|
|
15
|
-
export declare function cellInput(text: string):
|
|
20
|
+
export declare function cellInput(text: string): TypedCell;
|
|
16
21
|
/** What a cell holds as the text that typed it: `=SUM(A1:A3)`, `12.5`, `TRUE`. */
|
|
17
22
|
export declare function inputText(cell: BookCell | undefined): string;
|
package/dist/compute.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { addressOf, extentOf, } from './book.js';
|
|
2
|
+
import { dateText, parseDateText } from './dates.js';
|
|
2
3
|
import { evaluate, failed, isError, parseFormula, } from './formula.js';
|
|
3
4
|
export function computeBook(book) {
|
|
4
5
|
const sheets = new Map();
|
|
@@ -70,6 +71,10 @@ export function displayText(value, style = {}) {
|
|
|
70
71
|
return WHOLE.format(value);
|
|
71
72
|
if (style.format === 'percent')
|
|
72
73
|
return PERCENT.format(value);
|
|
74
|
+
if (style.format === 'date')
|
|
75
|
+
return dateText(value, false);
|
|
76
|
+
if (style.format === 'datetime')
|
|
77
|
+
return dateText(value, true);
|
|
73
78
|
return String(Number(value.toPrecision(12)));
|
|
74
79
|
}
|
|
75
80
|
const NUMERIC = /^[+-]?(?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d+)?(%)?$/;
|
|
@@ -86,6 +91,9 @@ export function cellInput(text) {
|
|
|
86
91
|
const number = Number(trimmed.replaceAll(',', '').replace('%', ''));
|
|
87
92
|
return { value: numeric[1] === undefined ? number : number / 100 };
|
|
88
93
|
}
|
|
94
|
+
const date = parseDateText(trimmed);
|
|
95
|
+
if (date)
|
|
96
|
+
return { value: date.serial, format: date.time ? 'datetime' : 'date' };
|
|
89
97
|
const upper = trimmed.toUpperCase();
|
|
90
98
|
if (upper === 'TRUE' || upper === 'FALSE')
|
|
91
99
|
return { value: upper === 'TRUE' };
|
|
@@ -99,5 +107,8 @@ export function inputText(cell) {
|
|
|
99
107
|
return '';
|
|
100
108
|
if (typeof value === 'boolean')
|
|
101
109
|
return value ? 'TRUE' : 'FALSE';
|
|
110
|
+
const format = cell?.style?.format;
|
|
111
|
+
if (typeof value === 'number' && (format === 'date' || format === 'datetime'))
|
|
112
|
+
return dateText(value, format === 'datetime');
|
|
102
113
|
return String(value);
|
|
103
114
|
}
|
|
@@ -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', merge: 'Merge cells', unmerge: 'Unmerge cells', format: 'Number format', formatGeneral: 'General', formatNumber: '1,234.50', formatInteger: '1,235', formatPercent: '12.5%', 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', 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",
|
|
@@ -112,6 +112,26 @@
|
|
|
112
112
|
"default": "null",
|
|
113
113
|
"description": "A column being dragged wider or narrower."
|
|
114
114
|
},
|
|
115
|
+
{
|
|
116
|
+
"kind": "field",
|
|
117
|
+
"name": "filling",
|
|
118
|
+
"type": {
|
|
119
|
+
"text": "{ from: CellRange; to: CellRange } | null"
|
|
120
|
+
},
|
|
121
|
+
"privacy": "private",
|
|
122
|
+
"default": "null",
|
|
123
|
+
"description": "The cells the fill handle is being dragged over: what was selected, and how far it goes now."
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"kind": "field",
|
|
127
|
+
"name": "menu",
|
|
128
|
+
"type": {
|
|
129
|
+
"text": "{ x: number; y: number } | null"
|
|
130
|
+
},
|
|
131
|
+
"privacy": "private",
|
|
132
|
+
"default": "null",
|
|
133
|
+
"description": "Where the grid's menu is open, from the element's top left corner."
|
|
134
|
+
},
|
|
115
135
|
{
|
|
116
136
|
"kind": "field",
|
|
117
137
|
"name": "ownValue",
|
|
@@ -316,6 +336,25 @@
|
|
|
316
336
|
],
|
|
317
337
|
"description": "Ctrl (or ⌘) with a letter; copy, cut and paste arrive as their own events."
|
|
318
338
|
},
|
|
339
|
+
{
|
|
340
|
+
"kind": "method",
|
|
341
|
+
"name": "fillFromEdge",
|
|
342
|
+
"privacy": "private",
|
|
343
|
+
"return": {
|
|
344
|
+
"type": {
|
|
345
|
+
"text": "void"
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
"parameters": [
|
|
349
|
+
{
|
|
350
|
+
"name": "down",
|
|
351
|
+
"type": {
|
|
352
|
+
"text": "boolean"
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
],
|
|
356
|
+
"description": "Ctrl+D / Ctrl+R: the selection's first row down, or its first column across."
|
|
357
|
+
},
|
|
319
358
|
{
|
|
320
359
|
"kind": "field",
|
|
321
360
|
"name": "editorKey",
|
|
@@ -369,11 +408,73 @@
|
|
|
369
408
|
"name": "pointerDown",
|
|
370
409
|
"privacy": "private"
|
|
371
410
|
},
|
|
411
|
+
{
|
|
412
|
+
"kind": "field",
|
|
413
|
+
"name": "fillStart",
|
|
414
|
+
"privacy": "private",
|
|
415
|
+
"description": "The fill handle pressed: the selection is spread as far as it is dragged, along one way."
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
"kind": "method",
|
|
419
|
+
"name": "fillTo",
|
|
420
|
+
"privacy": "private",
|
|
421
|
+
"return": {
|
|
422
|
+
"type": {
|
|
423
|
+
"text": "CellRange"
|
|
424
|
+
}
|
|
425
|
+
},
|
|
426
|
+
"parameters": [
|
|
427
|
+
{
|
|
428
|
+
"name": "from",
|
|
429
|
+
"type": {
|
|
430
|
+
"text": "CellRange"
|
|
431
|
+
}
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
"name": "cell",
|
|
435
|
+
"type": {
|
|
436
|
+
"text": "CellPos"
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
],
|
|
440
|
+
"description": "How far a fill goes with the pointer on `cell`: down or up, or across, whichever is further."
|
|
441
|
+
},
|
|
372
442
|
{
|
|
373
443
|
"kind": "field",
|
|
374
444
|
"name": "pointerOver",
|
|
375
445
|
"privacy": "private"
|
|
376
446
|
},
|
|
447
|
+
{
|
|
448
|
+
"kind": "field",
|
|
449
|
+
"name": "contextMenu",
|
|
450
|
+
"privacy": "private",
|
|
451
|
+
"description": "A right click on a cell: the rows and columns to put in or take out."
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
"kind": "field",
|
|
455
|
+
"name": "menuAway",
|
|
456
|
+
"privacy": "private"
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
"kind": "method",
|
|
460
|
+
"name": "closeMenu",
|
|
461
|
+
"privacy": "private",
|
|
462
|
+
"return": {
|
|
463
|
+
"type": {
|
|
464
|
+
"text": "void"
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
},
|
|
468
|
+
{
|
|
469
|
+
"kind": "method",
|
|
470
|
+
"name": "menuBox",
|
|
471
|
+
"privacy": "private",
|
|
472
|
+
"return": {
|
|
473
|
+
"type": {
|
|
474
|
+
"text": "TemplateResult | typeof nothing"
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
},
|
|
377
478
|
{
|
|
378
479
|
"kind": "field",
|
|
379
480
|
"name": "doubleClick",
|
|
@@ -642,6 +743,57 @@
|
|
|
642
743
|
}
|
|
643
744
|
]
|
|
644
745
|
},
|
|
746
|
+
{
|
|
747
|
+
"kind": "method",
|
|
748
|
+
"name": "lines",
|
|
749
|
+
"privacy": "private",
|
|
750
|
+
"return": {
|
|
751
|
+
"type": {
|
|
752
|
+
"text": "string[]"
|
|
753
|
+
}
|
|
754
|
+
},
|
|
755
|
+
"parameters": [
|
|
756
|
+
{
|
|
757
|
+
"name": "sheet",
|
|
758
|
+
"type": {
|
|
759
|
+
"text": "BookSheet"
|
|
760
|
+
}
|
|
761
|
+
},
|
|
762
|
+
{
|
|
763
|
+
"name": "at",
|
|
764
|
+
"type": {
|
|
765
|
+
"text": "CellPos"
|
|
766
|
+
}
|
|
767
|
+
},
|
|
768
|
+
{
|
|
769
|
+
"name": "sides",
|
|
770
|
+
"default": "[]",
|
|
771
|
+
"type": {
|
|
772
|
+
"text": "readonly BorderSide[]"
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
],
|
|
776
|
+
"description": "A cell's lines as CSS. Its bottom and right are its own edges; its top and left are the\nneighbour's, so they are drawn inside it, and only when the neighbour draws none there."
|
|
777
|
+
},
|
|
778
|
+
{
|
|
779
|
+
"kind": "method",
|
|
780
|
+
"name": "handle",
|
|
781
|
+
"privacy": "private",
|
|
782
|
+
"return": {
|
|
783
|
+
"type": {
|
|
784
|
+
"text": "TemplateResult | typeof nothing"
|
|
785
|
+
}
|
|
786
|
+
},
|
|
787
|
+
"parameters": [
|
|
788
|
+
{
|
|
789
|
+
"name": "sheet",
|
|
790
|
+
"type": {
|
|
791
|
+
"text": "BookSheet"
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
],
|
|
795
|
+
"description": "The square at the selection's corner that spreads it; not while typing, nor where nothing is written."
|
|
796
|
+
},
|
|
645
797
|
{
|
|
646
798
|
"kind": "method",
|
|
647
799
|
"name": "cell",
|
package/dist/dates.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** The serial of a wall clock; `null` when there is no such day or time. */
|
|
2
|
+
export declare function serialOf(year: number, month: number, day: number, hour?: number, minute?: number, second?: number): number | null;
|
|
3
|
+
/** A moment as the serial of its wall clock where this runs: what a source hands over as a `Date`. */
|
|
4
|
+
export declare function dateSerial(date: Date): number | null;
|
|
5
|
+
/** The wall clock of a serial, to the minute. */
|
|
6
|
+
export declare function serialParts(serial: number): {
|
|
7
|
+
year: number;
|
|
8
|
+
month: number;
|
|
9
|
+
day: number;
|
|
10
|
+
hour: number;
|
|
11
|
+
minute: number;
|
|
12
|
+
};
|
|
13
|
+
/** A serial as `2026-12-31`, with `time` as `2026-12-31 14:30`. */
|
|
14
|
+
export declare function dateText(serial: number, time: boolean): string;
|
|
15
|
+
/**
|
|
16
|
+
* A typed date as its serial: `2026-12-31`, `2026-12-31 14:30`, or day first `31/12/2026`.
|
|
17
|
+
* `time` says a time of day was written. `null` for anything else.
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseDateText(text: string): {
|
|
20
|
+
serial: number;
|
|
21
|
+
time: boolean;
|
|
22
|
+
} | null;
|
package/dist/dates.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const DAY = 86_400_000;
|
|
2
|
+
const EPOCH = Date.UTC(1899, 11, 30);
|
|
3
|
+
export function serialOf(year, month, day, hour = 0, minute = 0, second = 0) {
|
|
4
|
+
const at = new Date(Date.UTC(year, month - 1, day));
|
|
5
|
+
const real = year >= 1900 &&
|
|
6
|
+
year <= 9999 &&
|
|
7
|
+
at.getUTCFullYear() === year &&
|
|
8
|
+
at.getUTCMonth() === month - 1 &&
|
|
9
|
+
at.getUTCDate() === day &&
|
|
10
|
+
hour < 24 &&
|
|
11
|
+
minute < 60 &&
|
|
12
|
+
second < 60;
|
|
13
|
+
if (!real)
|
|
14
|
+
return null;
|
|
15
|
+
return (at.getTime() - EPOCH) / DAY + (hour * 3600 + minute * 60 + second) / 86_400;
|
|
16
|
+
}
|
|
17
|
+
export function dateSerial(date) {
|
|
18
|
+
if (Number.isNaN(date.getTime()))
|
|
19
|
+
return null;
|
|
20
|
+
return serialOf(date.getFullYear(), date.getMonth() + 1, date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds());
|
|
21
|
+
}
|
|
22
|
+
export function serialParts(serial) {
|
|
23
|
+
const seconds = Math.round(serial * 86_400);
|
|
24
|
+
const at = new Date(EPOCH + seconds * 1000);
|
|
25
|
+
return {
|
|
26
|
+
year: at.getUTCFullYear(),
|
|
27
|
+
month: at.getUTCMonth() + 1,
|
|
28
|
+
day: at.getUTCDate(),
|
|
29
|
+
hour: at.getUTCHours(),
|
|
30
|
+
minute: at.getUTCMinutes(),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const two = (n) => String(n).padStart(2, '0');
|
|
34
|
+
export function dateText(serial, time) {
|
|
35
|
+
if (!Number.isFinite(serial) || serial < 0 || serial > 2_958_466)
|
|
36
|
+
return String(serial);
|
|
37
|
+
const { year, month, day, hour, minute } = serialParts(serial);
|
|
38
|
+
const date = `${String(year).padStart(4, '0')}-${two(month)}-${two(day)}`;
|
|
39
|
+
return time ? `${date} ${two(hour)}:${two(minute)}` : date;
|
|
40
|
+
}
|
|
41
|
+
const ISO = /^(\d{4})-(\d{1,2})-(\d{1,2})(?:[ T](\d{1,2}):(\d{2})(?::(\d{2}))?)?$/;
|
|
42
|
+
const DAY_FIRST = /^(\d{1,2})\/(\d{1,2})\/(\d{4})(?: (\d{1,2}):(\d{2})(?::(\d{2}))?)?$/;
|
|
43
|
+
export function parseDateText(text) {
|
|
44
|
+
const iso = ISO.exec(text.trim());
|
|
45
|
+
const dayFirst = iso ? null : DAY_FIRST.exec(text.trim());
|
|
46
|
+
const found = iso ?? dayFirst;
|
|
47
|
+
if (!found)
|
|
48
|
+
return null;
|
|
49
|
+
const [, a, b, c, hour, minute, second] = found;
|
|
50
|
+
const [year, month, day] = iso ? [a, b, c] : [c, b, a];
|
|
51
|
+
const serial = serialOf(Number(year), Number(month), Number(day), Number(hour ?? 0), Number(minute ?? 0), Number(second ?? 0));
|
|
52
|
+
return serial === null ? null : { serial, time: hour !== undefined };
|
|
53
|
+
}
|
|
@@ -13,13 +13,23 @@ export interface SpreadsheetLabels {
|
|
|
13
13
|
alignLeft: string;
|
|
14
14
|
alignCenter: string;
|
|
15
15
|
alignRight: string;
|
|
16
|
+
borderAll: string;
|
|
17
|
+
borderOuter: string;
|
|
18
|
+
borderNone: string;
|
|
16
19
|
merge: string;
|
|
17
20
|
unmerge: string;
|
|
21
|
+
insertRow: string;
|
|
22
|
+
insertColumn: string;
|
|
23
|
+
removeRow: string;
|
|
24
|
+
removeColumn: string;
|
|
25
|
+
fillHandle: string;
|
|
18
26
|
format: string;
|
|
19
27
|
formatGeneral: string;
|
|
20
28
|
formatNumber: string;
|
|
21
29
|
formatInteger: string;
|
|
22
30
|
formatPercent: string;
|
|
31
|
+
formatDate: string;
|
|
32
|
+
formatDateTime: string;
|
|
23
33
|
undo: string;
|
|
24
34
|
redo: string;
|
|
25
35
|
cell: string;
|
|
@@ -64,6 +74,10 @@ export declare class BahtSpreadsheet extends BahtElement {
|
|
|
64
74
|
private renaming;
|
|
65
75
|
/** A column being dragged wider or narrower. */
|
|
66
76
|
private resizing;
|
|
77
|
+
/** The cells the fill handle is being dragged over: what was selected, and how far it goes now. */
|
|
78
|
+
private filling;
|
|
79
|
+
/** Where the grid's menu is open, from the element's top left corner. */
|
|
80
|
+
private menu;
|
|
67
81
|
/** The next `value` change is the element's own, already in the session. */
|
|
68
82
|
private ownValue;
|
|
69
83
|
/** The book's data sheets are to be loaded after this update. */
|
|
@@ -90,6 +104,8 @@ export declare class BahtSpreadsheet extends BahtElement {
|
|
|
90
104
|
private onKey;
|
|
91
105
|
/** Ctrl (or ⌘) with a letter; copy, cut and paste arrive as their own events. */
|
|
92
106
|
private shortcut;
|
|
107
|
+
/** Ctrl+D / Ctrl+R: the selection's first row down, or its first column across. */
|
|
108
|
+
private fillFromEdge;
|
|
93
109
|
private editorKey;
|
|
94
110
|
private barKey;
|
|
95
111
|
private barInput;
|
|
@@ -98,7 +114,17 @@ export declare class BahtSpreadsheet extends BahtElement {
|
|
|
98
114
|
private paste;
|
|
99
115
|
private placeOf;
|
|
100
116
|
private pointerDown;
|
|
117
|
+
/** The fill handle pressed: the selection is spread as far as it is dragged, along one way. */
|
|
118
|
+
private fillStart;
|
|
119
|
+
/** How far a fill goes with the pointer on `cell`: down or up, or across, whichever is further. */
|
|
120
|
+
private fillTo;
|
|
101
121
|
private pointerOver;
|
|
122
|
+
/** A right click on a cell: the rows and columns to put in or take out. */
|
|
123
|
+
private contextMenu;
|
|
124
|
+
private menuAway;
|
|
125
|
+
private closeMenu;
|
|
126
|
+
disconnectedCallback(): void;
|
|
127
|
+
private menuBox;
|
|
102
128
|
private doubleClick;
|
|
103
129
|
private resizeStart;
|
|
104
130
|
private get activeStyle();
|
|
@@ -115,6 +141,13 @@ export declare class BahtSpreadsheet extends BahtElement {
|
|
|
115
141
|
private widthOf;
|
|
116
142
|
private table;
|
|
117
143
|
private row;
|
|
144
|
+
/**
|
|
145
|
+
* A cell's lines as CSS. Its bottom and right are its own edges; its top and left are the
|
|
146
|
+
* neighbour's, so they are drawn inside it, and only when the neighbour draws none there.
|
|
147
|
+
*/
|
|
148
|
+
private lines;
|
|
149
|
+
/** The square at the selection's corner that spreads it; not while typing, nor where nothing is written. */
|
|
150
|
+
private handle;
|
|
118
151
|
private cell;
|
|
119
152
|
private tabs;
|
|
120
153
|
}
|