@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.
- package/LICENSE +21 -0
- package/README.md +79 -2
- package/dist/book.d.ts +89 -0
- package/dist/book.js +84 -0
- package/dist/compute.d.ts +17 -0
- package/dist/compute.js +103 -0
- package/dist/custom-elements.json +754 -0
- package/dist/define.d.ts +5 -0
- package/dist/define.js +6 -0
- package/dist/element.d.ts +3 -0
- package/dist/element.js +1 -0
- package/dist/elements/baht-spreadsheet.d.ts +125 -0
- package/dist/elements/baht-spreadsheet.js +712 -0
- package/dist/formula.d.ts +64 -0
- package/dist/formula.js +477 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/parse.d.ts +15 -0
- package/dist/parse.js +233 -0
- package/dist/session.d.ts +132 -0
- package/dist/session.js +370 -0
- package/dist/spreadsheet.css +327 -0
- package/dist/tsv.d.ts +3 -0
- package/dist/tsv.js +23 -0
- package/dist/workbook.d.ts +36 -0
- package/dist/workbook.js +40 -0
- package/package.json +75 -4
package/dist/session.js
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import { addressOf, MAX_COLUMNS, MAX_ROWS, MAX_SHEETS, mergeAt, mergesOf, overlaps, rangeName, rangeOf, sheetOf, } from './book.js';
|
|
2
|
+
import { cellInput, inputText } from './compute.js';
|
|
3
|
+
const HISTORY = 100;
|
|
4
|
+
const ORIGIN = { row: 0, column: 0 };
|
|
5
|
+
const HEADING = { bold: true, fill: '#e8eef7' };
|
|
6
|
+
export function openBook(book, sheet) {
|
|
7
|
+
const shown = (sheet === undefined ? undefined : sheetOf(book, sheet)) ?? book.sheets[0];
|
|
8
|
+
return {
|
|
9
|
+
book,
|
|
10
|
+
sheet: shown?.key ?? '',
|
|
11
|
+
active: ORIGIN,
|
|
12
|
+
end: ORIGIN,
|
|
13
|
+
editing: null,
|
|
14
|
+
undo: [],
|
|
15
|
+
redo: [],
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function shownSheet(state) {
|
|
19
|
+
return sheetOf(state.book, state.sheet);
|
|
20
|
+
}
|
|
21
|
+
export function selectionOf(state) {
|
|
22
|
+
const sheet = shownSheet(state);
|
|
23
|
+
let range = rangeOf(state.active, state.end);
|
|
24
|
+
if (!sheet)
|
|
25
|
+
return range;
|
|
26
|
+
const merges = mergesOf(sheet);
|
|
27
|
+
for (let grown = true; grown;) {
|
|
28
|
+
grown = false;
|
|
29
|
+
for (const merge of merges) {
|
|
30
|
+
if (!overlaps(range, merge))
|
|
31
|
+
continue;
|
|
32
|
+
const wider = {
|
|
33
|
+
top: Math.min(range.top, merge.top),
|
|
34
|
+
left: Math.min(range.left, merge.left),
|
|
35
|
+
bottom: Math.max(range.bottom, merge.bottom),
|
|
36
|
+
right: Math.max(range.right, merge.right),
|
|
37
|
+
};
|
|
38
|
+
if (rangeName(wider) !== rangeName(range)) {
|
|
39
|
+
range = wider;
|
|
40
|
+
grown = true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return range;
|
|
45
|
+
}
|
|
46
|
+
export function savedBook(book) {
|
|
47
|
+
return {
|
|
48
|
+
...book,
|
|
49
|
+
sheets: book.sheets.map((sheet) => (sheet.source ? { ...sheet, cells: {} } : sheet)),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const cellOf = (sheet, address) => Object.hasOwn(sheet.cells, address) ? sheet.cells[address] : undefined;
|
|
53
|
+
function changedCell(before, change) {
|
|
54
|
+
const after = change(before ?? {});
|
|
55
|
+
if (after.style && Object.keys(after.style).length === 0)
|
|
56
|
+
delete after.style;
|
|
57
|
+
return Object.keys(after).length === 0 ? null : after;
|
|
58
|
+
}
|
|
59
|
+
function changedCells(sheet, range, change) {
|
|
60
|
+
const changed = new Map();
|
|
61
|
+
for (let row = range.top; row <= range.bottom; row++) {
|
|
62
|
+
for (let column = range.left; column <= range.right; column++) {
|
|
63
|
+
const address = addressOf({ row, column });
|
|
64
|
+
changed.set(address, changedCell(cellOf(sheet, address), (cell) => change(cell, { row, column })));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const cells = {};
|
|
68
|
+
for (const [address, cell] of Object.entries(sheet.cells))
|
|
69
|
+
if (!changed.has(address))
|
|
70
|
+
cells[address] = cell;
|
|
71
|
+
for (const [address, cell] of changed)
|
|
72
|
+
if (cell)
|
|
73
|
+
cells[address] = cell;
|
|
74
|
+
return { ...sheet, cells };
|
|
75
|
+
}
|
|
76
|
+
const typed = (cell, text) => ({
|
|
77
|
+
...(cell.style ? { style: cell.style } : {}),
|
|
78
|
+
...cellInput(text),
|
|
79
|
+
});
|
|
80
|
+
const within = (cell) => ({
|
|
81
|
+
row: Math.min(MAX_ROWS - 1, Math.max(0, cell.row)),
|
|
82
|
+
column: Math.min(MAX_COLUMNS - 1, Math.max(0, cell.column)),
|
|
83
|
+
});
|
|
84
|
+
function anchorOf(sheet, cell) {
|
|
85
|
+
const merge = mergeAt(sheet, cell);
|
|
86
|
+
return merge ? { row: merge.top, column: merge.left } : cell;
|
|
87
|
+
}
|
|
88
|
+
function stepped(sheet, from, direction) {
|
|
89
|
+
const range = mergeAt(sheet, from) ?? rangeOf(from);
|
|
90
|
+
const to = {
|
|
91
|
+
up: { row: range.top - 1, column: from.column },
|
|
92
|
+
down: { row: range.bottom + 1, column: from.column },
|
|
93
|
+
left: { row: from.row, column: range.left - 1 },
|
|
94
|
+
right: { row: from.row, column: range.right + 1 },
|
|
95
|
+
};
|
|
96
|
+
return within(to[direction]);
|
|
97
|
+
}
|
|
98
|
+
const same = (state) => ({ state, changed: false });
|
|
99
|
+
function written(state, sheet, more = {}) {
|
|
100
|
+
const book = {
|
|
101
|
+
...state.book,
|
|
102
|
+
sheets: state.book.sheets.map((other) => (other.key === sheet.key ? sheet : other)),
|
|
103
|
+
};
|
|
104
|
+
return rewritten(state, book, more);
|
|
105
|
+
}
|
|
106
|
+
function rewritten(state, book, more = {}) {
|
|
107
|
+
return {
|
|
108
|
+
state: {
|
|
109
|
+
...state,
|
|
110
|
+
...more,
|
|
111
|
+
book,
|
|
112
|
+
undo: [...state.undo, state.book].slice(-HISTORY),
|
|
113
|
+
redo: [],
|
|
114
|
+
},
|
|
115
|
+
changed: true,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function freeName(book, base, except) {
|
|
119
|
+
const taken = new Set(book.sheets.filter((sheet) => sheet.key !== except).map((sheet) => sheet.name.toLowerCase()));
|
|
120
|
+
let name = base;
|
|
121
|
+
for (let n = 2; taken.has(name.toLowerCase()); n++)
|
|
122
|
+
name = `${base} ${String(n)}`;
|
|
123
|
+
return name;
|
|
124
|
+
}
|
|
125
|
+
const cleanName = (name) => name
|
|
126
|
+
.replace(/[\\/?*[\]:!']/g, ' ')
|
|
127
|
+
.trim()
|
|
128
|
+
.slice(0, 31);
|
|
129
|
+
function addSheet(state, msg) {
|
|
130
|
+
if (state.book.sheets.length >= MAX_SHEETS)
|
|
131
|
+
return same(state);
|
|
132
|
+
const keys = new Set(state.book.sheets.map((sheet) => sheet.key));
|
|
133
|
+
let n = state.book.sheets.length + 1;
|
|
134
|
+
while (keys.has(`sheet_${String(n)}`))
|
|
135
|
+
n++;
|
|
136
|
+
const base = cleanName(msg.name ?? '') || (msg.source ? 'Data' : `Sheet${String(n)}`);
|
|
137
|
+
const sheet = {
|
|
138
|
+
key: `sheet_${String(n)}`,
|
|
139
|
+
name: freeName(state.book, base),
|
|
140
|
+
cells: {},
|
|
141
|
+
...(msg.source ? { source: msg.source } : {}),
|
|
142
|
+
};
|
|
143
|
+
const book = { ...state.book, sheets: [...state.book.sheets, sheet] };
|
|
144
|
+
return rewritten(state, book, { sheet: sheet.key, active: ORIGIN, end: ORIGIN, editing: null });
|
|
145
|
+
}
|
|
146
|
+
function removeSheet(state, key) {
|
|
147
|
+
const at = state.book.sheets.findIndex((sheet) => sheet.key === key);
|
|
148
|
+
if (at < 0 || state.book.sheets.length < 2)
|
|
149
|
+
return same(state);
|
|
150
|
+
const sheets = state.book.sheets.filter((sheet) => sheet.key !== key);
|
|
151
|
+
const shown = state.sheet === key ? (sheets[Math.min(at, sheets.length - 1)]?.key ?? '') : state.sheet;
|
|
152
|
+
const moved = state.sheet === key ? { active: ORIGIN, end: ORIGIN, editing: null } : {};
|
|
153
|
+
return rewritten(state, { ...state.book, sheets }, { sheet: shown, ...moved });
|
|
154
|
+
}
|
|
155
|
+
function fill(state, key, data) {
|
|
156
|
+
const sheet = sheetOf(state.book, key);
|
|
157
|
+
if (!sheet?.source)
|
|
158
|
+
return same(state);
|
|
159
|
+
const cells = {};
|
|
160
|
+
const columns = data.columns.slice(0, MAX_COLUMNS);
|
|
161
|
+
columns.forEach((label, column) => {
|
|
162
|
+
cells[addressOf({ row: 0, column })] = { value: label, style: HEADING };
|
|
163
|
+
});
|
|
164
|
+
data.rows.slice(0, MAX_ROWS - 1).forEach((values, r) => {
|
|
165
|
+
columns.forEach((_, column) => {
|
|
166
|
+
const value = values[column];
|
|
167
|
+
if (value !== null && value !== undefined && value !== '')
|
|
168
|
+
cells[addressOf({ row: r + 1, column })] = { value };
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
const book = {
|
|
172
|
+
...state.book,
|
|
173
|
+
sheets: state.book.sheets.map((other) => (other.key === key ? { ...sheet, cells } : other)),
|
|
174
|
+
};
|
|
175
|
+
return { state: { ...state, book }, changed: false };
|
|
176
|
+
}
|
|
177
|
+
function merged(state, sheet) {
|
|
178
|
+
const range = selectionOf(state);
|
|
179
|
+
if (range.top === range.bottom && range.left === range.right)
|
|
180
|
+
return same(state);
|
|
181
|
+
const kept = mergesOf(sheet).filter((merge) => !overlaps(merge, range));
|
|
182
|
+
const anchor = { row: range.top, column: range.left };
|
|
183
|
+
const emptied = changedCells(sheet, range, (cell, at) => at.row === anchor.row && at.column === anchor.column
|
|
184
|
+
? cell
|
|
185
|
+
: { ...(cell.style ? { style: cell.style } : {}) });
|
|
186
|
+
return written(state, { ...emptied, merges: [...kept.map(rangeName), rangeName(range)] }, { active: anchor, end: anchor });
|
|
187
|
+
}
|
|
188
|
+
function unmerged(state, sheet) {
|
|
189
|
+
const range = selectionOf(state);
|
|
190
|
+
const kept = mergesOf(sheet).filter((merge) => !overlaps(merge, range));
|
|
191
|
+
if (kept.length === (sheet.merges ?? []).length)
|
|
192
|
+
return same(state);
|
|
193
|
+
const { merges: _merges, ...rest } = sheet;
|
|
194
|
+
return written(state, kept.length ? { ...rest, merges: kept.map(rangeName) } : rest);
|
|
195
|
+
}
|
|
196
|
+
function styled(cell, patch) {
|
|
197
|
+
const off = (value) => value === null || value === false;
|
|
198
|
+
const style = Object.fromEntries(Object.entries({ ...cell.style, ...patch }).filter(([, value]) => !off(value)));
|
|
199
|
+
return { ...cell, style };
|
|
200
|
+
}
|
|
201
|
+
function pasted(state, sheet, rows) {
|
|
202
|
+
const from = selectionOf(state);
|
|
203
|
+
const height = Math.min(rows.length, MAX_ROWS - from.top);
|
|
204
|
+
const width = Math.min(Math.max(0, ...rows.map((row) => row.length)), MAX_COLUMNS - from.left);
|
|
205
|
+
if (height === 0 || width === 0)
|
|
206
|
+
return same(state);
|
|
207
|
+
const range = {
|
|
208
|
+
top: from.top,
|
|
209
|
+
left: from.left,
|
|
210
|
+
bottom: from.top + height - 1,
|
|
211
|
+
right: from.left + width - 1,
|
|
212
|
+
};
|
|
213
|
+
const after = changedCells(sheet, range, (cell, at) => typed(cell, rows[at.row - from.top]?.[at.column - from.left] ?? ''));
|
|
214
|
+
return written(state, after, {
|
|
215
|
+
active: anchorOf(after, { row: range.top, column: range.left }),
|
|
216
|
+
end: { row: range.bottom, column: range.right },
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
const READS = new Set(['select', 'move', 'cancel', 'width']);
|
|
220
|
+
function onSheet(state, sheet, msg) {
|
|
221
|
+
if (sheet.source && !READS.has(msg.type))
|
|
222
|
+
return same(state);
|
|
223
|
+
switch (msg.type) {
|
|
224
|
+
case 'select': {
|
|
225
|
+
const cell = within(msg.cell);
|
|
226
|
+
if (msg.extend === true)
|
|
227
|
+
return same({ ...state, end: cell, editing: null });
|
|
228
|
+
const active = anchorOf(sheet, cell);
|
|
229
|
+
return same({ ...state, active, end: active, editing: null });
|
|
230
|
+
}
|
|
231
|
+
case 'move': {
|
|
232
|
+
if (msg.extend === true)
|
|
233
|
+
return same({ ...state, end: stepped(sheet, state.end, msg.direction) });
|
|
234
|
+
const active = anchorOf(sheet, stepped(sheet, state.active, msg.direction));
|
|
235
|
+
return same({ ...state, active, end: active, editing: null });
|
|
236
|
+
}
|
|
237
|
+
case 'edit':
|
|
238
|
+
return same({
|
|
239
|
+
...state,
|
|
240
|
+
end: state.active,
|
|
241
|
+
editing: msg.text ?? inputText(cellOf(sheet, addressOf(state.active))),
|
|
242
|
+
});
|
|
243
|
+
case 'type':
|
|
244
|
+
return state.editing === null ? same(state) : same({ ...state, editing: msg.text });
|
|
245
|
+
case 'cancel':
|
|
246
|
+
return same({ ...state, editing: null });
|
|
247
|
+
case 'commit':
|
|
248
|
+
case 'set': {
|
|
249
|
+
const text = msg.type === 'set' ? msg.text : state.editing;
|
|
250
|
+
if (text === null)
|
|
251
|
+
return same(state);
|
|
252
|
+
const address = addressOf(state.active);
|
|
253
|
+
if (text === inputText(cellOf(sheet, address)))
|
|
254
|
+
return same({ ...state, editing: null });
|
|
255
|
+
return written(state, changedCells(sheet, rangeOf(state.active), (cell) => typed(cell, text)), { editing: null });
|
|
256
|
+
}
|
|
257
|
+
case 'clear':
|
|
258
|
+
return written(state, changedCells(sheet, selectionOf(state), (cell) => typed(cell, '')));
|
|
259
|
+
case 'paste':
|
|
260
|
+
return pasted(state, sheet, msg.cells);
|
|
261
|
+
case 'style':
|
|
262
|
+
return written(state, changedCells(sheet, selectionOf(state), (cell) => styled(cell, msg.style)));
|
|
263
|
+
case 'merge':
|
|
264
|
+
return merged(state, sheet);
|
|
265
|
+
case 'unmerge':
|
|
266
|
+
return unmerged(state, sheet);
|
|
267
|
+
case 'width': {
|
|
268
|
+
const letter = addressOf({ row: 0, column: msg.column }).replace(/\d+$/, '');
|
|
269
|
+
const width = Math.round(Math.min(600, Math.max(24, msg.width)));
|
|
270
|
+
return written(state, { ...sheet, widths: { ...sheet.widths, [letter]: width } });
|
|
271
|
+
}
|
|
272
|
+
case 'show':
|
|
273
|
+
case 'add-sheet':
|
|
274
|
+
case 'rename-sheet':
|
|
275
|
+
case 'remove-sheet':
|
|
276
|
+
case 'fill':
|
|
277
|
+
case 'undo':
|
|
278
|
+
case 'redo':
|
|
279
|
+
return same(state);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
function renameSheet(state, key, wanted) {
|
|
283
|
+
const sheet = sheetOf(state.book, key);
|
|
284
|
+
const base = cleanName(wanted);
|
|
285
|
+
if (!sheet || base === '')
|
|
286
|
+
return same(state);
|
|
287
|
+
const name = freeName(state.book, base, sheet.key);
|
|
288
|
+
if (name === sheet.name)
|
|
289
|
+
return same(state);
|
|
290
|
+
return rewritten(state, {
|
|
291
|
+
...state.book,
|
|
292
|
+
sheets: state.book.sheets.map((other) => (other === sheet ? { ...sheet, name } : other)),
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
function stepBack(state, from) {
|
|
296
|
+
const to = from === 'undo' ? 'redo' : 'undo';
|
|
297
|
+
const book = state[from].at(-1);
|
|
298
|
+
if (!book)
|
|
299
|
+
return same(state);
|
|
300
|
+
const kept = {
|
|
301
|
+
...book,
|
|
302
|
+
sheets: book.sheets.map((sheet) => {
|
|
303
|
+
const now = sheetOf(state.book, sheet.key);
|
|
304
|
+
return sheet.source && now?.source ? { ...sheet, cells: now.cells } : sheet;
|
|
305
|
+
}),
|
|
306
|
+
};
|
|
307
|
+
const shown = sheetOf(kept, state.sheet) ? state.sheet : (kept.sheets[0]?.key ?? '');
|
|
308
|
+
const moved = shown === state.sheet ? {} : { active: ORIGIN, end: ORIGIN };
|
|
309
|
+
return {
|
|
310
|
+
state: {
|
|
311
|
+
...state,
|
|
312
|
+
...moved,
|
|
313
|
+
book: kept,
|
|
314
|
+
sheet: shown,
|
|
315
|
+
editing: null,
|
|
316
|
+
[from]: state[from].slice(0, -1),
|
|
317
|
+
[to]: [...state[to], state.book].slice(-HISTORY),
|
|
318
|
+
},
|
|
319
|
+
changed: true,
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
export function updateBook(state, msg) {
|
|
323
|
+
switch (msg.type) {
|
|
324
|
+
case 'show':
|
|
325
|
+
return sheetOf(state.book, msg.sheet) && msg.sheet !== state.sheet
|
|
326
|
+
? same({ ...state, sheet: msg.sheet, active: ORIGIN, end: ORIGIN, editing: null })
|
|
327
|
+
: same(state);
|
|
328
|
+
case 'add-sheet':
|
|
329
|
+
return addSheet(state, msg);
|
|
330
|
+
case 'remove-sheet':
|
|
331
|
+
return removeSheet(state, msg.sheet);
|
|
332
|
+
case 'rename-sheet':
|
|
333
|
+
return renameSheet(state, msg.sheet, msg.name);
|
|
334
|
+
case 'fill':
|
|
335
|
+
return fill(state, msg.sheet, msg.data);
|
|
336
|
+
case 'undo':
|
|
337
|
+
case 'redo':
|
|
338
|
+
return stepBack(state, msg.type);
|
|
339
|
+
case 'select':
|
|
340
|
+
case 'move':
|
|
341
|
+
case 'edit':
|
|
342
|
+
case 'type':
|
|
343
|
+
case 'commit':
|
|
344
|
+
case 'cancel':
|
|
345
|
+
case 'set':
|
|
346
|
+
case 'clear':
|
|
347
|
+
case 'paste':
|
|
348
|
+
case 'style':
|
|
349
|
+
case 'merge':
|
|
350
|
+
case 'unmerge':
|
|
351
|
+
case 'width': {
|
|
352
|
+
const sheet = shownSheet(state);
|
|
353
|
+
return sheet ? onSheet(state, sheet, msg) : same(state);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
export function copied(state, text) {
|
|
358
|
+
const sheet = shownSheet(state);
|
|
359
|
+
if (!sheet)
|
|
360
|
+
return [];
|
|
361
|
+
const range = selectionOf(state);
|
|
362
|
+
const rows = [];
|
|
363
|
+
for (let row = range.top; row <= range.bottom; row++) {
|
|
364
|
+
const cells = [];
|
|
365
|
+
for (let column = range.left; column <= range.right; column++)
|
|
366
|
+
cells.push(text(cellOf(sheet, addressOf({ row, column })), { row, column }));
|
|
367
|
+
rows.push(cells);
|
|
368
|
+
}
|
|
369
|
+
return rows;
|
|
370
|
+
}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/* @20baht/spreadsheet: <baht-spreadsheet>'s classes. It reads the base --baht-* tokens (space, type,
|
|
2
|
+
colour, radius) of @20baht/ui/tokens.css: link that sheet first, then this one. */
|
|
3
|
+
|
|
4
|
+
baht-spreadsheet {
|
|
5
|
+
display: block;
|
|
6
|
+
min-height: 0;
|
|
7
|
+
}
|
|
8
|
+
.baht-spreadsheet {
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: column;
|
|
11
|
+
height: 100%;
|
|
12
|
+
min-height: 0;
|
|
13
|
+
border: 1px solid var(--baht-color-border, #d6dce8);
|
|
14
|
+
border-radius: var(--baht-radius-md, 8px);
|
|
15
|
+
background: var(--baht-color-surface, #fff);
|
|
16
|
+
font-family: var(--baht-font-family, system-ui, sans-serif);
|
|
17
|
+
font-size: var(--baht-text-sm, 14px);
|
|
18
|
+
color: var(--baht-color-text, #1a2233);
|
|
19
|
+
overflow: hidden;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/* ---- tools ---- */
|
|
23
|
+
.baht-spreadsheet-tools {
|
|
24
|
+
display: flex;
|
|
25
|
+
flex-wrap: wrap;
|
|
26
|
+
align-items: center;
|
|
27
|
+
gap: 2px;
|
|
28
|
+
padding: var(--baht-space-1, 4px) var(--baht-space-2, 8px);
|
|
29
|
+
border-bottom: 1px solid var(--baht-color-border, #d6dce8);
|
|
30
|
+
}
|
|
31
|
+
.baht-spreadsheet-gap {
|
|
32
|
+
width: 1px;
|
|
33
|
+
height: 18px;
|
|
34
|
+
margin: 0 var(--baht-space-1, 4px);
|
|
35
|
+
background: var(--baht-color-border, #d6dce8);
|
|
36
|
+
}
|
|
37
|
+
.baht-spreadsheet-tool {
|
|
38
|
+
appearance: none;
|
|
39
|
+
display: inline-flex;
|
|
40
|
+
align-items: center;
|
|
41
|
+
justify-content: center;
|
|
42
|
+
min-width: 28px;
|
|
43
|
+
height: 28px;
|
|
44
|
+
padding: 0 6px;
|
|
45
|
+
border: 1px solid transparent;
|
|
46
|
+
border-radius: var(--baht-radius-sm, 6px);
|
|
47
|
+
background: none;
|
|
48
|
+
font: inherit;
|
|
49
|
+
color: inherit;
|
|
50
|
+
cursor: pointer;
|
|
51
|
+
}
|
|
52
|
+
.baht-spreadsheet-tool:hover:not(:disabled) {
|
|
53
|
+
background: var(--baht-color-primary-wash, #eef4ff);
|
|
54
|
+
}
|
|
55
|
+
.baht-spreadsheet-tool[aria-pressed='true'] {
|
|
56
|
+
border-color: var(--baht-color-primary, #0755d9);
|
|
57
|
+
background: var(--baht-color-primary-wash, #eef4ff);
|
|
58
|
+
color: var(--baht-color-primary, #0755d9);
|
|
59
|
+
}
|
|
60
|
+
.baht-spreadsheet-tool:disabled {
|
|
61
|
+
opacity: 0.4;
|
|
62
|
+
cursor: default;
|
|
63
|
+
}
|
|
64
|
+
.baht-spreadsheet-tool:focus-visible,
|
|
65
|
+
.baht-spreadsheet-tab:focus-visible,
|
|
66
|
+
.baht-spreadsheet-format:focus-visible {
|
|
67
|
+
outline: 2px solid var(--baht-color-primary, #0755d9);
|
|
68
|
+
outline-offset: 1px;
|
|
69
|
+
}
|
|
70
|
+
.baht-spreadsheet-tool [data-look='bold'] {
|
|
71
|
+
font-weight: 700;
|
|
72
|
+
}
|
|
73
|
+
.baht-spreadsheet-tool [data-look='italic'] {
|
|
74
|
+
font-style: italic;
|
|
75
|
+
font-family: Georgia, serif;
|
|
76
|
+
}
|
|
77
|
+
.baht-spreadsheet-tool [data-look='underline'] {
|
|
78
|
+
text-decoration: underline;
|
|
79
|
+
}
|
|
80
|
+
.baht-spreadsheet-colour {
|
|
81
|
+
position: relative;
|
|
82
|
+
display: inline-flex;
|
|
83
|
+
align-items: center;
|
|
84
|
+
justify-content: center;
|
|
85
|
+
width: 28px;
|
|
86
|
+
height: 28px;
|
|
87
|
+
border-radius: var(--baht-radius-sm, 6px);
|
|
88
|
+
cursor: pointer;
|
|
89
|
+
}
|
|
90
|
+
.baht-spreadsheet-colour:hover {
|
|
91
|
+
background: var(--baht-color-primary-wash, #eef4ff);
|
|
92
|
+
}
|
|
93
|
+
.baht-spreadsheet-colour input {
|
|
94
|
+
position: absolute;
|
|
95
|
+
inset: 0;
|
|
96
|
+
width: 100%;
|
|
97
|
+
height: 100%;
|
|
98
|
+
opacity: 0;
|
|
99
|
+
cursor: pointer;
|
|
100
|
+
}
|
|
101
|
+
.baht-spreadsheet-colour [data-swatch] {
|
|
102
|
+
font-weight: 700;
|
|
103
|
+
line-height: 1;
|
|
104
|
+
padding-bottom: 2px;
|
|
105
|
+
border-bottom: 4px solid var(--swatch);
|
|
106
|
+
}
|
|
107
|
+
.baht-spreadsheet-colour [data-swatch='fill'] {
|
|
108
|
+
padding: 1px 4px 2px;
|
|
109
|
+
border: 1px solid var(--baht-color-border, #d6dce8);
|
|
110
|
+
border-bottom-width: 4px;
|
|
111
|
+
border-bottom-color: var(--swatch);
|
|
112
|
+
border-radius: 3px;
|
|
113
|
+
}
|
|
114
|
+
.baht-spreadsheet-format {
|
|
115
|
+
height: 28px;
|
|
116
|
+
margin-left: var(--baht-space-1, 4px);
|
|
117
|
+
border: 1px solid var(--baht-color-border, #d6dce8);
|
|
118
|
+
border-radius: var(--baht-radius-sm, 6px);
|
|
119
|
+
background: var(--baht-color-surface, #fff);
|
|
120
|
+
font: inherit;
|
|
121
|
+
font-size: var(--baht-text-xs, 12px);
|
|
122
|
+
color: inherit;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/* ---- the formula bar ---- */
|
|
126
|
+
.baht-spreadsheet-bar {
|
|
127
|
+
display: flex;
|
|
128
|
+
align-items: center;
|
|
129
|
+
gap: var(--baht-space-2, 8px);
|
|
130
|
+
padding: var(--baht-space-1, 4px) var(--baht-space-2, 8px);
|
|
131
|
+
border-bottom: 1px solid var(--baht-color-border, #d6dce8);
|
|
132
|
+
}
|
|
133
|
+
.baht-spreadsheet-name {
|
|
134
|
+
min-width: 72px;
|
|
135
|
+
font-size: var(--baht-text-xs, 12px);
|
|
136
|
+
font-variant-numeric: tabular-nums;
|
|
137
|
+
color: var(--baht-color-text-muted, #5b6679);
|
|
138
|
+
}
|
|
139
|
+
.baht-spreadsheet-fx {
|
|
140
|
+
font-style: italic;
|
|
141
|
+
font-family: Georgia, serif;
|
|
142
|
+
color: var(--baht-color-text-muted, #5b6679);
|
|
143
|
+
}
|
|
144
|
+
.baht-spreadsheet-bar-input {
|
|
145
|
+
flex: 1;
|
|
146
|
+
min-width: 0;
|
|
147
|
+
height: 26px;
|
|
148
|
+
padding: 0 var(--baht-space-2, 8px);
|
|
149
|
+
border: 1px solid transparent;
|
|
150
|
+
border-radius: var(--baht-radius-sm, 6px);
|
|
151
|
+
background: none;
|
|
152
|
+
font: inherit;
|
|
153
|
+
color: inherit;
|
|
154
|
+
}
|
|
155
|
+
.baht-spreadsheet-bar-input:focus {
|
|
156
|
+
outline: none;
|
|
157
|
+
border-color: var(--baht-color-primary, #0755d9);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.baht-spreadsheet-notice {
|
|
161
|
+
display: flex;
|
|
162
|
+
align-items: center;
|
|
163
|
+
justify-content: space-between;
|
|
164
|
+
gap: var(--baht-space-2, 8px);
|
|
165
|
+
padding: var(--baht-space-1, 4px) var(--baht-space-3, 12px);
|
|
166
|
+
border-bottom: 1px solid var(--baht-color-border, #d6dce8);
|
|
167
|
+
background: var(--baht-color-primary-wash, #eef4ff);
|
|
168
|
+
font-size: var(--baht-text-xs, 12px);
|
|
169
|
+
}
|
|
170
|
+
.baht-spreadsheet-notice[data-failed] {
|
|
171
|
+
background: color-mix(in srgb, var(--baht-color-danger, #b42318) 12%, transparent);
|
|
172
|
+
color: var(--baht-color-danger, #b42318);
|
|
173
|
+
}
|
|
174
|
+
.baht-spreadsheet-notice .baht-spreadsheet-tool {
|
|
175
|
+
border-color: currentColor;
|
|
176
|
+
font-size: var(--baht-text-xs, 12px);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/* ---- the grid ---- */
|
|
180
|
+
.baht-spreadsheet-scroll {
|
|
181
|
+
flex: 1;
|
|
182
|
+
min-height: 0;
|
|
183
|
+
overflow: auto;
|
|
184
|
+
}
|
|
185
|
+
.baht-spreadsheet-grid {
|
|
186
|
+
border-collapse: separate;
|
|
187
|
+
border-spacing: 0;
|
|
188
|
+
table-layout: fixed;
|
|
189
|
+
width: max-content;
|
|
190
|
+
font-variant-numeric: tabular-nums;
|
|
191
|
+
outline: none;
|
|
192
|
+
user-select: none;
|
|
193
|
+
}
|
|
194
|
+
.baht-spreadsheet-grid col.baht-spreadsheet-corner {
|
|
195
|
+
width: 44px;
|
|
196
|
+
}
|
|
197
|
+
.baht-spreadsheet-grid th,
|
|
198
|
+
.baht-spreadsheet-grid td {
|
|
199
|
+
height: var(--baht-spreadsheet-row, 26px);
|
|
200
|
+
padding: 0 6px;
|
|
201
|
+
border-right: 1px solid var(--baht-color-border, #d6dce8);
|
|
202
|
+
border-bottom: 1px solid var(--baht-color-border, #d6dce8);
|
|
203
|
+
overflow: hidden;
|
|
204
|
+
white-space: nowrap;
|
|
205
|
+
text-overflow: ellipsis;
|
|
206
|
+
box-sizing: border-box;
|
|
207
|
+
}
|
|
208
|
+
.baht-spreadsheet-grid th {
|
|
209
|
+
position: sticky;
|
|
210
|
+
z-index: 1;
|
|
211
|
+
background: var(--baht-color-surface-alt, #f3f5f9);
|
|
212
|
+
font-weight: 500;
|
|
213
|
+
font-size: var(--baht-text-xs, 12px);
|
|
214
|
+
color: var(--baht-color-text-muted, #5b6679);
|
|
215
|
+
text-align: center;
|
|
216
|
+
}
|
|
217
|
+
.baht-spreadsheet-grid thead th {
|
|
218
|
+
top: 0;
|
|
219
|
+
z-index: 2;
|
|
220
|
+
}
|
|
221
|
+
.baht-spreadsheet-grid tbody th,
|
|
222
|
+
.baht-spreadsheet-grid th.baht-spreadsheet-corner {
|
|
223
|
+
left: 0;
|
|
224
|
+
}
|
|
225
|
+
.baht-spreadsheet-grid th.baht-spreadsheet-corner {
|
|
226
|
+
z-index: 3;
|
|
227
|
+
}
|
|
228
|
+
.baht-spreadsheet-grid th[data-selected] {
|
|
229
|
+
/* mixed, not the wash itself: a header stays opaque over the rows that scroll under it */
|
|
230
|
+
background: color-mix(
|
|
231
|
+
in srgb,
|
|
232
|
+
var(--baht-color-primary, #0755d9) 16%,
|
|
233
|
+
var(--baht-color-surface-alt, #f3f5f9)
|
|
234
|
+
);
|
|
235
|
+
color: var(--baht-color-primary, #0755d9);
|
|
236
|
+
}
|
|
237
|
+
.baht-spreadsheet-grid td {
|
|
238
|
+
position: relative;
|
|
239
|
+
background: var(--baht-color-surface, #fff);
|
|
240
|
+
cursor: cell;
|
|
241
|
+
}
|
|
242
|
+
.baht-spreadsheet-grid td[data-selected] {
|
|
243
|
+
box-shadow: inset 0 0 0 999px
|
|
244
|
+
color-mix(in srgb, var(--baht-color-primary, #0755d9) 12%, transparent);
|
|
245
|
+
}
|
|
246
|
+
.baht-spreadsheet-grid td[data-active] {
|
|
247
|
+
box-shadow: inset 0 0 0 2px var(--baht-color-primary, #0755d9);
|
|
248
|
+
}
|
|
249
|
+
.baht-spreadsheet-grid td[data-error] {
|
|
250
|
+
color: var(--baht-color-danger, #b42318);
|
|
251
|
+
}
|
|
252
|
+
.baht-spreadsheet-spacer td {
|
|
253
|
+
padding: 0;
|
|
254
|
+
border: 0;
|
|
255
|
+
height: auto;
|
|
256
|
+
}
|
|
257
|
+
.baht-spreadsheet-resize {
|
|
258
|
+
position: absolute;
|
|
259
|
+
top: 0;
|
|
260
|
+
right: -3px;
|
|
261
|
+
width: 7px;
|
|
262
|
+
height: 100%;
|
|
263
|
+
cursor: col-resize;
|
|
264
|
+
touch-action: none;
|
|
265
|
+
}
|
|
266
|
+
.baht-spreadsheet-editor {
|
|
267
|
+
position: absolute;
|
|
268
|
+
inset: 0;
|
|
269
|
+
width: 100%;
|
|
270
|
+
height: 100%;
|
|
271
|
+
padding: 0 6px;
|
|
272
|
+
border: 0;
|
|
273
|
+
background: var(--baht-color-surface, #fff);
|
|
274
|
+
font: inherit;
|
|
275
|
+
color: var(--baht-color-text, #1a2233);
|
|
276
|
+
outline: 2px solid var(--baht-color-primary, #0755d9);
|
|
277
|
+
outline-offset: -2px;
|
|
278
|
+
box-sizing: border-box;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/* ---- sheets ---- */
|
|
282
|
+
.baht-spreadsheet-tabs {
|
|
283
|
+
display: flex;
|
|
284
|
+
flex-wrap: wrap;
|
|
285
|
+
align-items: center;
|
|
286
|
+
gap: 2px;
|
|
287
|
+
padding: 2px var(--baht-space-2, 8px);
|
|
288
|
+
border-top: 1px solid var(--baht-color-border, #d6dce8);
|
|
289
|
+
background: var(--baht-color-surface-alt, #f3f5f9);
|
|
290
|
+
}
|
|
291
|
+
.baht-spreadsheet-tab {
|
|
292
|
+
appearance: none;
|
|
293
|
+
display: inline-flex;
|
|
294
|
+
align-items: center;
|
|
295
|
+
gap: 6px;
|
|
296
|
+
padding: var(--baht-space-1, 4px) var(--baht-space-3, 12px);
|
|
297
|
+
border: 0;
|
|
298
|
+
border-bottom: 2px solid transparent;
|
|
299
|
+
background: none;
|
|
300
|
+
font: inherit;
|
|
301
|
+
color: var(--baht-color-text-muted, #5b6679);
|
|
302
|
+
cursor: pointer;
|
|
303
|
+
}
|
|
304
|
+
.baht-spreadsheet-tab[aria-selected='true'] {
|
|
305
|
+
border-bottom-color: var(--baht-color-primary, #0755d9);
|
|
306
|
+
background: var(--baht-color-surface, #fff);
|
|
307
|
+
color: var(--baht-color-text, #1a2233);
|
|
308
|
+
font-weight: 600;
|
|
309
|
+
}
|
|
310
|
+
.baht-spreadsheet-badge {
|
|
311
|
+
padding: 0 6px;
|
|
312
|
+
border-radius: 999px;
|
|
313
|
+
background: var(--baht-color-primary-wash, #eef4ff);
|
|
314
|
+
font-size: 10px;
|
|
315
|
+
font-weight: 600;
|
|
316
|
+
letter-spacing: 0.02em;
|
|
317
|
+
text-transform: uppercase;
|
|
318
|
+
color: var(--baht-color-primary, #0755d9);
|
|
319
|
+
}
|
|
320
|
+
.baht-spreadsheet-rename {
|
|
321
|
+
width: 120px;
|
|
322
|
+
height: 26px;
|
|
323
|
+
padding: 0 var(--baht-space-2, 8px);
|
|
324
|
+
border: 1px solid var(--baht-color-primary, #0755d9);
|
|
325
|
+
border-radius: var(--baht-radius-sm, 6px);
|
|
326
|
+
font: inherit;
|
|
327
|
+
}
|
package/dist/tsv.d.ts
ADDED