@20baht/spreadsheet 0.0.0-stage → 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/dist/parse.js ADDED
@@ -0,0 +1,245 @@
1
+ import { ALIGNS, BORDER_SIDES, MAX_COLUMNS, MAX_ROWS, MAX_SHEETS, NUMBER_FORMATS, overlaps, parseAddress, parseRange, } from './book.js';
2
+ const COLOR = /^#[0-9a-fA-F]{6}$/;
3
+ const KEY = /^[A-Za-z0-9_-]{1,64}$/;
4
+ const UNSAFE = new Set(['__proto__', 'constructor', 'prototype']);
5
+ const MAX_TEXT = 32_767;
6
+ const MAX_FORMULA = 2000;
7
+ const NOT_OBJECT = 'must be an object';
8
+ const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
9
+ class Gate {
10
+ constructor() {
11
+ this.issues = [];
12
+ }
13
+ fail(path, message) {
14
+ this.issues.push({ path, message });
15
+ }
16
+ #oneOf(value, known, path) {
17
+ if (value === undefined)
18
+ return undefined;
19
+ const found = known.find((candidate) => candidate === value);
20
+ if (found === undefined)
21
+ this.fail(path, `must be one of ${known.join(', ')}`);
22
+ return found;
23
+ }
24
+ #colour(value, path) {
25
+ if (value === undefined)
26
+ return undefined;
27
+ if (typeof value !== 'string' || !COLOR.test(value)) {
28
+ this.fail(path, 'must be a colour like #1a2b3c');
29
+ return undefined;
30
+ }
31
+ return value.toLowerCase();
32
+ }
33
+ #flag(value, path) {
34
+ if (value !== undefined && typeof value !== 'boolean')
35
+ this.fail(path, 'must be true or false');
36
+ return value === true;
37
+ }
38
+ #sides(value, path) {
39
+ if (value === undefined)
40
+ return undefined;
41
+ if (!Array.isArray(value) || value.some((side) => !BORDER_SIDES.some((s) => s === side))) {
42
+ this.fail(path, `must be a list of ${BORDER_SIDES.join(', ')}`);
43
+ return undefined;
44
+ }
45
+ const sides = BORDER_SIDES.filter((side) => value.includes(side));
46
+ return sides.length ? sides : undefined;
47
+ }
48
+ style(value, path) {
49
+ if (value === undefined)
50
+ return undefined;
51
+ if (!isRecord(value)) {
52
+ this.fail(path, NOT_OBJECT);
53
+ return undefined;
54
+ }
55
+ const bold = this.#flag(value.bold, `${path}.bold`);
56
+ const italic = this.#flag(value.italic, `${path}.italic`);
57
+ const underline = this.#flag(value.underline, `${path}.underline`);
58
+ const color = this.#colour(value.color, `${path}.color`);
59
+ const fill = this.#colour(value.fill, `${path}.fill`);
60
+ const align = this.#oneOf(value.align, ALIGNS, `${path}.align`);
61
+ const format = this.#oneOf(value.format, NUMBER_FORMATS, `${path}.format`);
62
+ const border = this.#sides(value.border, `${path}.border`);
63
+ const style = {
64
+ ...(bold ? { bold } : {}),
65
+ ...(italic ? { italic } : {}),
66
+ ...(underline ? { underline } : {}),
67
+ ...(color === undefined ? {} : { color }),
68
+ ...(fill === undefined ? {} : { fill }),
69
+ ...(align === undefined ? {} : { align }),
70
+ ...(format === undefined ? {} : { format }),
71
+ ...(border === undefined ? {} : { border }),
72
+ };
73
+ return Object.keys(style).length ? style : undefined;
74
+ }
75
+ cell(value, path) {
76
+ if (!isRecord(value)) {
77
+ this.fail(path, NOT_OBJECT);
78
+ return undefined;
79
+ }
80
+ const cell = {};
81
+ const held = value.value;
82
+ if (typeof held === 'string' && held.length > MAX_TEXT)
83
+ this.fail(`${path}.value`, `holds at most ${String(MAX_TEXT)} characters`);
84
+ else if (typeof held === 'number' && !Number.isFinite(held))
85
+ this.fail(`${path}.value`, 'must be a finite number');
86
+ else if (typeof held === 'string' || typeof held === 'number' || typeof held === 'boolean')
87
+ cell.value = held;
88
+ else if (held !== undefined)
89
+ this.fail(`${path}.value`, 'must be text, a number or true / false');
90
+ if (value.formula !== undefined) {
91
+ if (typeof value.formula !== 'string' || value.formula === '')
92
+ this.fail(`${path}.formula`, 'must be a formula without its =');
93
+ else if (value.formula.length > MAX_FORMULA)
94
+ this.fail(`${path}.formula`, `holds at most ${String(MAX_FORMULA)} characters`);
95
+ else if (cell.value !== undefined)
96
+ this.fail(path, 'holds a value or a formula, not both');
97
+ else
98
+ cell.formula = value.formula;
99
+ }
100
+ const style = this.style(value.style, `${path}.style`);
101
+ if (style)
102
+ cell.style = style;
103
+ return Object.keys(cell).length ? cell : undefined;
104
+ }
105
+ cells(value, path) {
106
+ const cells = {};
107
+ if (value === undefined)
108
+ return cells;
109
+ if (!isRecord(value)) {
110
+ this.fail(path, 'must be an object of cells by address');
111
+ return cells;
112
+ }
113
+ for (const [address, raw] of Object.entries(value)) {
114
+ const at = parseAddress(address);
115
+ if (!at ||
116
+ address !== address.toUpperCase() ||
117
+ at.row >= MAX_ROWS ||
118
+ at.column >= MAX_COLUMNS) {
119
+ this.fail(`${path}.${address}`, 'is not a cell of the grid (A1 … )');
120
+ continue;
121
+ }
122
+ const cell = this.cell(raw, `${path}.${address}`);
123
+ if (cell)
124
+ cells[address] = cell;
125
+ }
126
+ return cells;
127
+ }
128
+ merges(value, path) {
129
+ if (value === undefined)
130
+ return undefined;
131
+ if (!Array.isArray(value)) {
132
+ this.fail(path, 'must be a list of ranges');
133
+ return undefined;
134
+ }
135
+ const ranges = [];
136
+ const names = [];
137
+ value.forEach((raw, i) => {
138
+ const at = `${path}[${String(i)}]`;
139
+ const range = typeof raw === 'string' && raw === raw.toUpperCase() ? parseRange(raw) : null;
140
+ if (!range || range.bottom >= MAX_ROWS || range.right >= MAX_COLUMNS)
141
+ this.fail(at, 'must be a range like A1:C2');
142
+ else if (range.top === range.bottom && range.left === range.right)
143
+ this.fail(at, 'must cover more than one cell');
144
+ else if (ranges.some((other) => overlaps(other, range)))
145
+ this.fail(at, 'overlaps another merged range');
146
+ else {
147
+ ranges.push(range);
148
+ names.push(raw);
149
+ }
150
+ });
151
+ return names.length ? names : undefined;
152
+ }
153
+ widths(value, path) {
154
+ if (value === undefined)
155
+ return undefined;
156
+ if (!isRecord(value)) {
157
+ this.fail(path, 'must be an object of widths by column');
158
+ return undefined;
159
+ }
160
+ const widths = {};
161
+ for (const [column, width] of Object.entries(value)) {
162
+ if (!/^[A-Z]{1,3}$/.test(column) ||
163
+ typeof width !== 'number' ||
164
+ !(width >= 24 && width <= 600))
165
+ this.fail(`${path}.${column}`, 'must be a column (A, B, …) and 24 to 600 pixels');
166
+ else
167
+ widths[column] = width;
168
+ }
169
+ return Object.keys(widths).length ? widths : undefined;
170
+ }
171
+ source(value, path) {
172
+ if (value === undefined)
173
+ return undefined;
174
+ if (!isRecord(value) || typeof value.name !== 'string' || value.name === '') {
175
+ this.fail(path, 'must be an object with the name of a source');
176
+ return undefined;
177
+ }
178
+ if (value.params !== undefined && !isRecord(value.params)) {
179
+ this.fail(`${path}.params`, NOT_OBJECT);
180
+ return undefined;
181
+ }
182
+ return { name: value.name, ...(value.params ? { params: value.params } : {}) };
183
+ }
184
+ sheet(value, path) {
185
+ if (!isRecord(value)) {
186
+ this.fail(path, NOT_OBJECT);
187
+ return undefined;
188
+ }
189
+ const { key, name } = value;
190
+ if (typeof key !== 'string' || !KEY.test(key) || UNSAFE.has(key)) {
191
+ this.fail(`${path}.key`, 'must be a key of letters, digits, _ and -');
192
+ return undefined;
193
+ }
194
+ if (typeof name !== 'string' ||
195
+ name.trim() === '' ||
196
+ name.length > 31 ||
197
+ /[\\/?*[\]:!']/.test(name)) {
198
+ this.fail(`${path}.name`, "must be 1 to 31 characters, none of \\ / ? * [ ] : ! '");
199
+ return undefined;
200
+ }
201
+ const merges = this.merges(value.merges, `${path}.merges`);
202
+ const widths = this.widths(value.widths, `${path}.widths`);
203
+ const source = this.source(value.source, `${path}.source`);
204
+ return {
205
+ key,
206
+ name,
207
+ cells: source ? {} : this.cells(value.cells, `${path}.cells`),
208
+ ...(merges ? { merges } : {}),
209
+ ...(widths ? { widths } : {}),
210
+ ...(source ? { source } : {}),
211
+ };
212
+ }
213
+ }
214
+ export function parseBook(value) {
215
+ const gate = new Gate();
216
+ if (!isRecord(value) || !Array.isArray(value.sheets)) {
217
+ return { ok: false, issues: [{ path: 'sheets', message: 'must be a list of sheets' }] };
218
+ }
219
+ if (value.sheets.length === 0 || value.sheets.length > MAX_SHEETS)
220
+ gate.fail('sheets', `must hold 1 to ${String(MAX_SHEETS)} sheets`);
221
+ if (value.title !== undefined && typeof value.title !== 'string')
222
+ gate.fail('title', 'must be text');
223
+ const keys = new Set();
224
+ const names = new Set();
225
+ const sheets = [];
226
+ value.sheets.slice(0, MAX_SHEETS).forEach((raw, i) => {
227
+ const path = `sheets[${String(i)}]`;
228
+ const sheet = gate.sheet(raw, path);
229
+ if (!sheet)
230
+ return;
231
+ if (keys.has(sheet.key))
232
+ gate.fail(`${path}.key`, 'is the key of another sheet');
233
+ if (names.has(sheet.name.toLowerCase()))
234
+ gate.fail(`${path}.name`, 'is the name of another sheet');
235
+ keys.add(sheet.key);
236
+ names.add(sheet.name.toLowerCase());
237
+ sheets.push(sheet);
238
+ });
239
+ if (gate.issues.length)
240
+ return { ok: false, issues: gate.issues };
241
+ return {
242
+ ok: true,
243
+ book: { ...(typeof value.title === 'string' ? { title: value.title } : {}), sheets },
244
+ };
245
+ }
package/dist/refs.d.ts ADDED
@@ -0,0 +1,43 @@
1
+ /** One end of a reference as written: `$B$3`, `B3`, or for whole columns `B` (no `row`). */
2
+ export interface RefEnd {
3
+ column: number;
4
+ /** From 0; unset on the end of whole columns (`A:C`). */
5
+ row?: number;
6
+ /** Written with `$`: copied to another cell, it stays. */
7
+ columnFixed: boolean;
8
+ rowFixed: boolean;
9
+ }
10
+ /** A reference as a formula writes it: a cell, or a range from one end to the other. */
11
+ export interface FormulaRef {
12
+ /** The sheet's name, when the formula names one. */
13
+ sheet?: string;
14
+ from: RefEnd;
15
+ to?: RefEnd;
16
+ }
17
+ /** A sheet's name as a formula writes it: in quotes unless it is one plain word. */
18
+ export declare function sheetRef(name: string): string;
19
+ /**
20
+ * The formula with every reference written again by `change`: the reference it gives, `null` for a
21
+ * place that is no more (`#REF!`), `undefined` to leave it as it is written.
22
+ */
23
+ export declare function rewriteRefs(formula: string, change: (ref: FormulaRef) => FormulaRef | null | undefined): string;
24
+ /** Rows or columns put in before `at`, or taken out from `at`. */
25
+ export interface Move {
26
+ axis: 'row' | 'column';
27
+ at: number;
28
+ count: number;
29
+ remove: boolean;
30
+ }
31
+ /** Where a row or column is after the move; `null` when it was taken out or is past the grid. */
32
+ export declare function movedIndex(index: number, move: Move): number | null;
33
+ /** Where a span of rows or columns is after the move: it shrinks around what was taken out; `null` when all of it was. */
34
+ export declare function movedSpan(low: number, high: number, move: Move): [number, number] | null;
35
+ /**
36
+ * The formula after rows or columns moved on the sheet called `sheet`. `own`: the formula is on
37
+ * that sheet, so the references that name no sheet are its own.
38
+ */
39
+ export declare function movedRefs(formula: string, move: Move, sheet: string, own: boolean): string;
40
+ /** The formula as it reads copied `rows` down and `columns` right: what is written with `$` stays. */
41
+ export declare function shiftedRefs(formula: string, rows: number, columns: number): string;
42
+ /** The formula with the sheet called `from` called `to`. */
43
+ export declare function renamedRefs(formula: string, from: string, to: string): string;
package/dist/refs.js ADDED
@@ -0,0 +1,120 @@
1
+ import { columnIndex, columnName, MAX_COLUMNS, MAX_ROWS } from './book.js';
2
+ const NAME = String.raw `'(?:[^']|'')*'|[\p{L}_][\p{L}\p{N}_.]*`;
3
+ const CELL = String.raw `\$?[A-Za-z]{1,3}\$?[1-9]\d{0,6}`;
4
+ const COLUMN = String.raw `\$?[A-Za-z]{1,3}`;
5
+ const PLACES = new RegExp(String.raw `"(?:[^"]|"")*"|(?<![\p{L}\p{N}_.$'])(?:(${NAME})!)?(${CELL}(?::${CELL})?|${COLUMN}:${COLUMN})(?![\p{L}\p{N}_.(!$])`, 'gu');
6
+ const END = /^(\$?)([A-Za-z]{1,3})(\$?)(\d*)$/;
7
+ const PLAIN = /^[\p{L}_][\p{L}\p{N}_.]*$/u;
8
+ const LIKE_A_PLACE = /^(?:[A-Za-z]{1,3}\d*|TRUE|FALSE)$/i;
9
+ function endOf(text) {
10
+ const [, columnFixed, letters = '', rowFixed, digits] = END.exec(text) ?? [];
11
+ return {
12
+ column: columnIndex(letters),
13
+ ...(digits ? { row: Number(digits) - 1 } : {}),
14
+ columnFixed: columnFixed === '$',
15
+ rowFixed: rowFixed === '$',
16
+ };
17
+ }
18
+ function endText(end) {
19
+ const column = `${end.columnFixed ? '$' : ''}${columnName(end.column)}`;
20
+ return end.row === undefined
21
+ ? column
22
+ : `${column}${end.rowFixed ? '$' : ''}${String(end.row + 1)}`;
23
+ }
24
+ export function sheetRef(name) {
25
+ return PLAIN.test(name) && !LIKE_A_PLACE.test(name) ? name : `'${name.replaceAll("'", "''")}'`;
26
+ }
27
+ function refText(ref) {
28
+ const sheet = ref.sheet === undefined ? '' : `${sheetRef(ref.sheet)}!`;
29
+ return `${sheet}${endText(ref.from)}${ref.to ? `:${endText(ref.to)}` : ''}`;
30
+ }
31
+ export function rewriteRefs(formula, change) {
32
+ return formula.replace(PLACES, (found, sheet, place) => {
33
+ if (place === undefined)
34
+ return found;
35
+ const [from = '', to] = place.split(':');
36
+ const changed = change({
37
+ ...(sheet === undefined
38
+ ? {}
39
+ : { sheet: sheet.startsWith("'") ? sheet.slice(1, -1).replaceAll("''", "'") : sheet }),
40
+ from: endOf(from),
41
+ ...(to === undefined ? {} : { to: endOf(to) }),
42
+ });
43
+ if (changed === undefined)
44
+ return found;
45
+ return changed === null ? '#REF!' : refText(changed);
46
+ });
47
+ }
48
+ const limitOf = (axis) => (axis === 'row' ? MAX_ROWS : MAX_COLUMNS);
49
+ export function movedIndex(index, move) {
50
+ if (index < move.at)
51
+ return index;
52
+ if (!move.remove)
53
+ return index + move.count < limitOf(move.axis) ? index + move.count : null;
54
+ return index < move.at + move.count ? null : index - move.count;
55
+ }
56
+ export function movedSpan(low, high, move) {
57
+ if (!move.remove) {
58
+ const to = movedIndex(high, move);
59
+ return to === null ? null : [movedIndex(low, move) ?? low, to];
60
+ }
61
+ const end = move.at + move.count;
62
+ if (low >= move.at && high < end)
63
+ return null;
64
+ return [
65
+ low >= end ? low - move.count : Math.min(low, move.at),
66
+ high >= end ? high - move.count : high >= move.at ? move.at - 1 : high,
67
+ ];
68
+ }
69
+ const key = (axis) => axis;
70
+ function movedRef(ref, move) {
71
+ const axis = key(move.axis);
72
+ const a = ref.from[axis];
73
+ if (a === undefined)
74
+ return undefined;
75
+ if (!ref.to) {
76
+ const to = movedIndex(a, move);
77
+ return to === null ? null : { ...ref, from: { ...ref.from, [axis]: to } };
78
+ }
79
+ const b = ref.to[axis] ?? a;
80
+ const span = movedSpan(Math.min(a, b), Math.max(a, b), move);
81
+ if (!span)
82
+ return null;
83
+ const [low, high] = span;
84
+ return {
85
+ ...ref,
86
+ from: { ...ref.from, [axis]: a <= b ? low : high },
87
+ to: { ...ref.to, [axis]: a <= b ? high : low },
88
+ };
89
+ }
90
+ export function movedRefs(formula, move, sheet, own) {
91
+ const name = sheet.toLowerCase();
92
+ return rewriteRefs(formula, (ref) => {
93
+ const there = ref.sheet === undefined ? own : ref.sheet.toLowerCase() === name;
94
+ return there ? movedRef(ref, move) : undefined;
95
+ });
96
+ }
97
+ function shiftedEnd(end, rows, columns) {
98
+ const column = end.columnFixed ? end.column : end.column + columns;
99
+ const row = end.row === undefined || end.rowFixed ? end.row : end.row + rows;
100
+ if (column < 0 || column >= MAX_COLUMNS)
101
+ return null;
102
+ if (row !== undefined && (row < 0 || row >= MAX_ROWS))
103
+ return null;
104
+ return { ...end, column, ...(row === undefined ? {} : { row }) };
105
+ }
106
+ export function shiftedRefs(formula, rows, columns) {
107
+ if (rows === 0 && columns === 0)
108
+ return formula;
109
+ return rewriteRefs(formula, (ref) => {
110
+ const from = shiftedEnd(ref.from, rows, columns);
111
+ const to = ref.to ? shiftedEnd(ref.to, rows, columns) : undefined;
112
+ if (!from || to === null)
113
+ return null;
114
+ return { ...ref, from, ...(to ? { to } : {}) };
115
+ });
116
+ }
117
+ export function renamedRefs(formula, from, to) {
118
+ const name = from.toLowerCase();
119
+ return rewriteRefs(formula, (ref) => ref.sheet?.toLowerCase() === name ? { ...ref, sheet: to } : undefined);
120
+ }
@@ -0,0 +1,157 @@
1
+ import { type Book, type BookCell, type BookSheet, type BookSource, type CellPos, type CellRange, type CellStyle, type CellValue } from './book.js';
2
+ export interface BookState {
3
+ book: Book;
4
+ /** The key of the sheet shown. */
5
+ sheet: string;
6
+ /** The cell that takes the keyboard. In a merged range, its top left cell. */
7
+ active: CellPos;
8
+ /** The selection's other corner; the active cell when one cell is selected. */
9
+ end: CellPos;
10
+ /** The text being typed into the active cell; `null` when no cell is being edited. */
11
+ editing: string | null;
12
+ undo: readonly Book[];
13
+ redo: readonly Book[];
14
+ }
15
+ export type BookDirection = 'up' | 'down' | 'left' | 'right';
16
+ /** A change to how cells look: a key set to `null` is taken off. */
17
+ export type StylePatch = {
18
+ [Key in keyof CellStyle]?: CellStyle[Key] | null;
19
+ };
20
+ /** What a source answered: the columns' labels, then a row of values for each record. */
21
+ export interface SourceRows {
22
+ columns: readonly string[];
23
+ /** A `Date` becomes a date cell: its wall clock where this runs, shown with its time unless it is midnight. */
24
+ rows: readonly (readonly (CellValue | Date | null)[])[];
25
+ }
26
+ export type BookMsg =
27
+ /** Another sheet. */
28
+ {
29
+ type: 'show';
30
+ sheet: string;
31
+ }
32
+ /** A click (`extend`: with Shift, or a drag). */
33
+ | {
34
+ type: 'select';
35
+ cell: CellPos;
36
+ extend?: boolean;
37
+ }
38
+ /** An arrow key. `extend`: with Shift. */
39
+ | {
40
+ type: 'move';
41
+ direction: BookDirection;
42
+ extend?: boolean;
43
+ }
44
+ /** Start editing the active cell: over what it holds (F2, a double click), or with `text` in its place (typing). */
45
+ | {
46
+ type: 'edit';
47
+ text?: string;
48
+ }
49
+ /** The text being edited, as it is typed. */
50
+ | {
51
+ type: 'type';
52
+ text: string;
53
+ }
54
+ /** Keep what was typed. */
55
+ | {
56
+ type: 'commit';
57
+ }
58
+ /** Drop what was typed. */
59
+ | {
60
+ type: 'cancel';
61
+ }
62
+ /** Put `text` into the active cell as if it were typed there. */
63
+ | {
64
+ type: 'set';
65
+ text: string;
66
+ }
67
+ /** Empty the selected cells; how they look stays. */
68
+ | {
69
+ type: 'clear';
70
+ }
71
+ /** Rows of typed text, from the selection's top left cell. */
72
+ | {
73
+ type: 'paste';
74
+ cells: readonly (readonly string[])[];
75
+ }
76
+ /** Change how the selected cells look. */
77
+ | {
78
+ type: 'style';
79
+ style: StylePatch;
80
+ }
81
+ /** Lines on the selected cells: every side of each (`all`), the selection's edge (`outer`), or none. */
82
+ | {
83
+ type: 'border';
84
+ sides: 'all' | 'outer' | 'none';
85
+ }
86
+ /** Show the selection as one cell: its top left cell keeps what it holds, the others are emptied. */
87
+ | {
88
+ type: 'merge';
89
+ }
90
+ /** Split every merged range the selection touches. */
91
+ | {
92
+ type: 'unmerge';
93
+ }
94
+ /** A column's width in pixels. */
95
+ | {
96
+ type: 'width';
97
+ column: number;
98
+ width: number;
99
+ }
100
+ /**
101
+ * The cells of `from` copied over the rest of `to` (the fill handle, Ctrl+D): a formula reads
102
+ * from as far away as it did, numbers in step go on in step, anything else repeats.
103
+ */
104
+ | {
105
+ type: 'spread';
106
+ from: CellRange;
107
+ to: CellRange;
108
+ }
109
+ /** As many empty rows (or columns) as the selection has, before it. Every formula follows. */
110
+ | {
111
+ type: 'insert';
112
+ axis: 'row' | 'column';
113
+ }
114
+ /** Take the selection's rows (or columns) out. A formula that named one of them reads `#REF!`. */
115
+ | {
116
+ type: 'remove';
117
+ axis: 'row' | 'column';
118
+ }
119
+ /** A new sheet, shown; with `source`, a data sheet. */
120
+ | {
121
+ type: 'add-sheet';
122
+ name?: string;
123
+ source?: BookSource;
124
+ } | {
125
+ type: 'rename-sheet';
126
+ sheet: string;
127
+ name: string;
128
+ } | {
129
+ type: 'remove-sheet';
130
+ sheet: string;
131
+ }
132
+ /** What a data sheet's source answered. Not a change to the book as it is saved. */
133
+ | {
134
+ type: 'fill';
135
+ sheet: string;
136
+ data: SourceRows;
137
+ } | {
138
+ type: 'undo';
139
+ } | {
140
+ type: 'redo';
141
+ };
142
+ export interface BookUpdate {
143
+ state: BookState;
144
+ /** The book as it is saved is no longer what it was. */
145
+ changed: boolean;
146
+ }
147
+ export declare function openBook(book: Book, sheet?: string): BookState;
148
+ /** The sheet shown. */
149
+ export declare function shownSheet(state: BookState): BookSheet | undefined;
150
+ /** The selected rectangle: from the active cell to the other corner, grown over every merged range it touches. */
151
+ export declare function selectionOf(state: BookState): CellRange;
152
+ /** The sheets of a book without what their sources answered: the book as it is saved. */
153
+ export declare function savedBook(book: Book): Book;
154
+ /** The state after a message, and whether the book as it is saved changed. */
155
+ export declare function updateBook(state: BookState, msg: BookMsg): BookUpdate;
156
+ /** The selected cells as the text a clipboard takes: what each shows as it was typed. */
157
+ export declare function copied(state: BookState, text: (cell: BookCell | undefined, at: CellPos) => string): string[][];