@20baht/spreadsheet 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Lit's `@customElement`, tolerating a tag being defined already (two copies of this package in
3
+ * one page keep the first and warn). The Custom Elements Manifest analyzer keys on this name.
4
+ */
5
+ export declare function customElement(tag: string): (cls: CustomElementConstructor) => void;
package/dist/define.js ADDED
@@ -0,0 +1,6 @@
1
+ import { defineOnce } from '@20baht/element';
2
+ export function customElement(tag) {
3
+ return (cls) => {
4
+ defineOnce(tag, cls, '@20baht/spreadsheet');
5
+ };
6
+ }
@@ -0,0 +1,3 @@
1
+ export { BahtSpreadsheet, SPREADSHEET_LABELS, type SpreadsheetLabels, type SpreadsheetLoader, } from './elements/baht-spreadsheet.js';
2
+ export type { Book, BookSheet, BookSource } from './book.js';
3
+ export type { SourceRows } from './session.js';
@@ -0,0 +1 @@
1
+ export { BahtSpreadsheet, SPREADSHEET_LABELS, } from './elements/baht-spreadsheet.js';
@@ -0,0 +1,125 @@
1
+ import { type PropertyValues, type TemplateResult } from 'lit';
2
+ import { BahtElement } from '@20baht/element';
3
+ import { type Book, type BookSheet, type BookSource } from '../book.js';
4
+ import { type SourceRows } from '../session.js';
5
+ /** Every word the element shows of its own. Give `labels` the ones to say otherwise. */
6
+ export interface SpreadsheetLabels {
7
+ bold: string;
8
+ italic: string;
9
+ underline: string;
10
+ textColor: string;
11
+ fillColor: string;
12
+ noFill: string;
13
+ alignLeft: string;
14
+ alignCenter: string;
15
+ alignRight: string;
16
+ merge: string;
17
+ unmerge: string;
18
+ format: string;
19
+ formatGeneral: string;
20
+ formatNumber: string;
21
+ formatInteger: string;
22
+ formatPercent: string;
23
+ undo: string;
24
+ redo: string;
25
+ cell: string;
26
+ formula: string;
27
+ addSheet: string;
28
+ removeSheet: string;
29
+ renameSheet: string;
30
+ dataSheet: string;
31
+ refresh: string;
32
+ loading: string;
33
+ loadFailed: string;
34
+ readOnlyData: string;
35
+ }
36
+ export declare const SPREADSHEET_LABELS: SpreadsheetLabels;
37
+ /** What a data sheet's source answers with: the host's function. */
38
+ export type SpreadsheetLoader = (source: BookSource, sheet: BookSheet) => Promise<SourceRows>;
39
+ /**
40
+ * A book (spec 12) worked like a spreadsheet: free cells holding text, numbers and formulas, bold /
41
+ * italic / colours, merged ranges, several sheets, and data sheets the host fills (`load`).
42
+ * Click or use the arrows to select, type to write, `=` to start a formula, Shift to select a
43
+ * rectangle, copy and paste with Excel, Delete to empty, Ctrl+B / I / U, Ctrl+Z / Y.
44
+ *
45
+ * @element baht-spreadsheet
46
+ * @fires {CustomEvent<{ value: Book }>} baht-change - The book changed: the book as it is saved, the data sheets empty.
47
+ */
48
+ export declare class BahtSpreadsheet extends BahtElement {
49
+ /** The book (spec 12 §1). Set as a property: `el.value = json`. Starts as the host gives it, then follows the grid (`baht-change`). */
50
+ value: Book;
51
+ /** Shown, selected and copied, never changed. */
52
+ readonly: boolean;
53
+ /** Answers a data sheet's source. Called when a book is opened, a data sheet is added and on `refresh()`. */
54
+ load: SpreadsheetLoader | undefined;
55
+ /** The element's own words, the ones to say otherwise (`SPREADSHEET_LABELS` has them all). */
56
+ labels: Partial<SpreadsheetLabels>;
57
+ private session;
58
+ /** The first row drawn. */
59
+ private first;
60
+ /** The data sheets being loaded, and the ones whose load failed, by key. */
61
+ private pending;
62
+ private failures;
63
+ /** The sheet whose name is being typed. */
64
+ private renaming;
65
+ /** A column being dragged wider or narrower. */
66
+ private resizing;
67
+ /** The next `value` change is the element's own, already in the session. */
68
+ private ownValue;
69
+ /** The book's data sheets are to be loaded after this update. */
70
+ private stale;
71
+ private dragging;
72
+ private computed;
73
+ /** The book with what its data sheets hold now: what `bookWorkbook()` takes for a file. */
74
+ get book(): Book;
75
+ /** Ask every data sheet's source again (or one sheet's). */
76
+ refresh(sheet?: string): Promise<void>;
77
+ /** Add a data sheet, show it and ask its source. */
78
+ addDataSheet(name: string, source: BookSource): Promise<void>;
79
+ private get words();
80
+ private get values();
81
+ protected willUpdate(changed: PropertyValues<this>): void;
82
+ protected updated(): void;
83
+ private barFocused;
84
+ private send;
85
+ private grid;
86
+ /** Scroll so the selection's moving corner is in view. */
87
+ private reveal;
88
+ private scrolled;
89
+ private gridKey;
90
+ private onKey;
91
+ /** Ctrl (or ⌘) with a letter; copy, cut and paste arrive as their own events. */
92
+ private shortcut;
93
+ private editorKey;
94
+ private barKey;
95
+ private barInput;
96
+ private shownText;
97
+ private copy;
98
+ private paste;
99
+ private placeOf;
100
+ private pointerDown;
101
+ private pointerOver;
102
+ private doubleClick;
103
+ private resizeStart;
104
+ private get activeStyle();
105
+ private toggle;
106
+ private look;
107
+ protected render(): TemplateResult;
108
+ private tool;
109
+ private tools;
110
+ private formatLabel;
111
+ /** The name of what is selected, and what the active cell holds as it was typed. */
112
+ private bar;
113
+ /** A data sheet says what it is, that it is loading, or that it could not. */
114
+ private notice;
115
+ private widthOf;
116
+ private table;
117
+ private row;
118
+ private cell;
119
+ private tabs;
120
+ }
121
+ declare global {
122
+ interface HTMLElementTagNameMap {
123
+ 'baht-spreadsheet': BahtSpreadsheet;
124
+ }
125
+ }