@datalayer/cells 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/README.md +55 -2
- package/lib/chrome/index.d.ts +7 -0
- package/lib/chrome/index.d.ts.map +1 -0
- package/lib/chrome/index.js +7 -0
- package/lib/chrome/index.js.map +1 -0
- package/lib/collab/index.d.ts +7 -0
- package/lib/collab/index.d.ts.map +1 -0
- package/lib/collab/index.js +7 -0
- package/lib/collab/index.js.map +1 -0
- package/lib/core/axis.d.ts +97 -0
- package/lib/core/axis.d.ts.map +1 -0
- package/lib/core/axis.js +431 -0
- package/lib/core/axis.js.map +1 -0
- package/lib/core/cells.d.ts +71 -0
- package/lib/core/cells.d.ts.map +1 -0
- package/lib/core/cells.js +285 -0
- package/lib/core/cells.js.map +1 -0
- package/lib/core/index.d.ts +8 -0
- package/lib/core/index.d.ts.map +1 -0
- package/lib/core/index.js +7 -0
- package/lib/core/index.js.map +1 -0
- package/lib/core/strings.d.ts +19 -0
- package/lib/core/strings.d.ts.map +1 -0
- package/lib/core/strings.js +61 -0
- package/lib/core/strings.js.map +1 -0
- package/lib/core/styles.d.ts +48 -0
- package/lib/core/styles.d.ts.map +1 -0
- package/lib/core/styles.js +102 -0
- package/lib/core/styles.js.map +1 -0
- package/lib/core/values.d.ts +20 -0
- package/lib/core/values.d.ts.map +1 -0
- package/lib/core/values.js +39 -0
- package/lib/core/values.js.map +1 -0
- package/lib/core/zone.d.ts +48 -0
- package/lib/core/zone.d.ts.map +1 -0
- package/lib/core/zone.js +89 -0
- package/lib/core/zone.js.map +1 -0
- package/lib/csv/index.d.ts +7 -0
- package/lib/csv/index.d.ts.map +1 -0
- package/lib/csv/index.js +7 -0
- package/lib/csv/index.js.map +1 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +13 -0
- package/lib/index.js.map +1 -0
- package/lib/plugin/index.d.ts +7 -0
- package/lib/plugin/index.d.ts.map +1 -0
- package/lib/plugin/index.js +7 -0
- package/lib/plugin/index.js.map +1 -0
- package/lib/points/resolve.d.ts +56 -0
- package/lib/points/resolve.d.ts.map +1 -0
- package/lib/points/resolve.js +106 -0
- package/lib/points/resolve.js.map +1 -0
- package/lib/xlsx/index.d.ts +7 -0
- package/lib/xlsx/index.d.ts.map +1 -0
- package/lib/xlsx/index.js +7 -0
- package/lib/xlsx/index.js.map +1 -0
- package/package.json +115 -4
- package/style/cells.css +7 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022-2026 Datalayer, Inc.
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
const KEYS = [
|
|
7
|
+
'font',
|
|
8
|
+
'size',
|
|
9
|
+
'bold',
|
|
10
|
+
'italic',
|
|
11
|
+
'underline',
|
|
12
|
+
'strike',
|
|
13
|
+
'color',
|
|
14
|
+
'fill',
|
|
15
|
+
'align',
|
|
16
|
+
'valign',
|
|
17
|
+
'wrap',
|
|
18
|
+
'borders',
|
|
19
|
+
'format',
|
|
20
|
+
];
|
|
21
|
+
const KEY_SET = new Set(KEYS);
|
|
22
|
+
const MAX_STYLES = 0xffff;
|
|
23
|
+
/** A canonical text for a style: its set keys in a fixed order, falsy flags dropped. */
|
|
24
|
+
function canonical(style) {
|
|
25
|
+
const out = {};
|
|
26
|
+
for (const key of KEYS) {
|
|
27
|
+
const value = style[key];
|
|
28
|
+
if (value === undefined || value === false)
|
|
29
|
+
continue;
|
|
30
|
+
out[key] = key === 'borders' ? canonicalBorders(value) : value;
|
|
31
|
+
}
|
|
32
|
+
return JSON.stringify(out);
|
|
33
|
+
}
|
|
34
|
+
function canonicalBorders(b) {
|
|
35
|
+
if (b === undefined)
|
|
36
|
+
return undefined;
|
|
37
|
+
const out = {};
|
|
38
|
+
for (const side of ['top', 'right', 'bottom', 'left'])
|
|
39
|
+
if (b[side])
|
|
40
|
+
out[side] = b[side];
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
/** Throws a sentence naming the first thing wrong with a style. */
|
|
44
|
+
export function checkStyle(style, where = 'style') {
|
|
45
|
+
if (typeof style !== 'object' || style === null || Array.isArray(style)) {
|
|
46
|
+
throw new Error(`${where}: a style is an object.`);
|
|
47
|
+
}
|
|
48
|
+
for (const key of Object.keys(style)) {
|
|
49
|
+
if (!KEY_SET.has(key))
|
|
50
|
+
throw new Error(`${where}: '${key}' is not a style property (${KEYS.join(', ')}).`);
|
|
51
|
+
}
|
|
52
|
+
const s = style;
|
|
53
|
+
for (const key of ['bold', 'italic', 'underline', 'strike', 'wrap']) {
|
|
54
|
+
if (s[key] !== undefined && typeof s[key] !== 'boolean')
|
|
55
|
+
throw new Error(`${where}.${key}: true or false.`);
|
|
56
|
+
}
|
|
57
|
+
for (const key of ['font', 'color', 'fill', 'format']) {
|
|
58
|
+
if (s[key] !== undefined && typeof s[key] !== 'string')
|
|
59
|
+
throw new Error(`${where}.${key}: a string.`);
|
|
60
|
+
}
|
|
61
|
+
if (s.size !== undefined && !(typeof s.size === 'number' && s.size > 0)) {
|
|
62
|
+
throw new Error(`${where}.size: a positive number.`);
|
|
63
|
+
}
|
|
64
|
+
if (s.align !== undefined && !['left', 'center', 'right'].includes(s.align)) {
|
|
65
|
+
throw new Error(`${where}.align: left, center or right.`);
|
|
66
|
+
}
|
|
67
|
+
if (s.valign !== undefined && !['top', 'middle', 'bottom'].includes(s.valign)) {
|
|
68
|
+
throw new Error(`${where}.valign: top, middle or bottom.`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export class StyleTable {
|
|
72
|
+
#styles = [{}];
|
|
73
|
+
#index = new Map([[canonical({}), 0]]);
|
|
74
|
+
/** The index of a style, adding it when new. Index 0 is the default style. */
|
|
75
|
+
intern(style) {
|
|
76
|
+
const key = canonical(style);
|
|
77
|
+
let i = this.#index.get(key);
|
|
78
|
+
if (i === undefined) {
|
|
79
|
+
if (this.#styles.length > MAX_STYLES) {
|
|
80
|
+
throw new Error(`A workbook holds at most ${MAX_STYLES + 1} distinct styles.`);
|
|
81
|
+
}
|
|
82
|
+
i = this.#styles.length;
|
|
83
|
+
this.#styles.push(JSON.parse(key));
|
|
84
|
+
this.#index.set(key, i);
|
|
85
|
+
}
|
|
86
|
+
return i;
|
|
87
|
+
}
|
|
88
|
+
get(index) {
|
|
89
|
+
const style = this.#styles[index];
|
|
90
|
+
if (style === undefined)
|
|
91
|
+
throw new Error(`No style ${index}; the workbook has ${this.#styles.length}.`);
|
|
92
|
+
return style;
|
|
93
|
+
}
|
|
94
|
+
get size() {
|
|
95
|
+
return this.#styles.length;
|
|
96
|
+
}
|
|
97
|
+
/** Every style, in index order (the file format's `styles`). */
|
|
98
|
+
all() {
|
|
99
|
+
return this.#styles;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../../src/core/styles.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA0CH,MAAM,IAAI,GAA6B;IACrC,MAAM;IACN,MAAM;IACN,MAAM;IACN,QAAQ;IACR,WAAW;IACX,QAAQ;IACR,OAAO;IACP,MAAM;IACN,OAAO;IACP,QAAQ;IACR,MAAM;IACN,SAAS;IACT,QAAQ;CACT,CAAC;AACF,MAAM,OAAO,GAAwB,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;AACnD,MAAM,UAAU,GAAG,MAAM,CAAC;AAE1B,wFAAwF;AACxF,SAAS,SAAS,CAAC,KAAY;IAC7B,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;QACzB,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,KAAK;YAAE,SAAS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@module core/values
|
|
5
|
+
*/
|
|
6
|
+
/** The errors a cell can hold, as Excel spells them (`#CYCLE!` and `#BUSY!` are ours). */
|
|
7
|
+
export declare const CELL_ERRORS: readonly ["#DIV/0!", "#REF!", "#NAME?", "#VALUE!", "#N/A", "#NUM!", "#NULL!", "#CYCLE!", "#BUSY!", "#SPILL!"];
|
|
8
|
+
export type CellErrorCode = (typeof CELL_ERRORS)[number];
|
|
9
|
+
/** An error value, with an optional sentence saying why (shown in the cell's tooltip). */
|
|
10
|
+
export interface CellError {
|
|
11
|
+
readonly error: CellErrorCode;
|
|
12
|
+
readonly message?: string;
|
|
13
|
+
}
|
|
14
|
+
/** What a cell evaluates to. `null` is empty. */
|
|
15
|
+
export type CellValue = number | string | boolean | CellError | null;
|
|
16
|
+
/** An error value; refuses a code that is not one of {@link CELL_ERRORS}. */
|
|
17
|
+
export declare function cellError(code: CellErrorCode, message?: string): CellError;
|
|
18
|
+
export declare function isCellError(value: unknown): value is CellError;
|
|
19
|
+
export declare function isErrorCode(text: string): text is CellErrorCode;
|
|
20
|
+
//# sourceMappingURL=values.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"values.d.ts","sourceRoot":"","sources":["../../src/core/values.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AAEH,0FAA0F;AAC1F,eAAO,MAAM,WAAW,+GAWd,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzD,0FAA0F;AAC1F,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,iDAAiD;AACjD,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,IAAI,CAAC;AAIrE,6EAA6E;AAC7E,wBAAgB,SAAS,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAI1E;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAM9D;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,aAAa,CAE/D"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022-2026 Datalayer, Inc.
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Cell values and errors.
|
|
8
|
+
*
|
|
9
|
+
* @module core/values
|
|
10
|
+
*/
|
|
11
|
+
/** The errors a cell can hold, as Excel spells them (`#CYCLE!` and `#BUSY!` are ours). */
|
|
12
|
+
export const CELL_ERRORS = [
|
|
13
|
+
'#DIV/0!',
|
|
14
|
+
'#REF!',
|
|
15
|
+
'#NAME?',
|
|
16
|
+
'#VALUE!',
|
|
17
|
+
'#N/A',
|
|
18
|
+
'#NUM!',
|
|
19
|
+
'#NULL!',
|
|
20
|
+
'#CYCLE!',
|
|
21
|
+
'#BUSY!',
|
|
22
|
+
'#SPILL!',
|
|
23
|
+
];
|
|
24
|
+
const ERROR_SET = new Set(CELL_ERRORS);
|
|
25
|
+
/** An error value; refuses a code that is not one of {@link CELL_ERRORS}. */
|
|
26
|
+
export function cellError(code, message) {
|
|
27
|
+
if (!ERROR_SET.has(code))
|
|
28
|
+
throw new Error(`'${code}' is not a cell error; there are ${CELL_ERRORS.join(' ')}.`);
|
|
29
|
+
return message === undefined ? { error: code } : { error: code, message };
|
|
30
|
+
}
|
|
31
|
+
export function isCellError(value) {
|
|
32
|
+
return (typeof value === 'object' &&
|
|
33
|
+
value !== null &&
|
|
34
|
+
ERROR_SET.has(value.error));
|
|
35
|
+
}
|
|
36
|
+
export function isErrorCode(text) {
|
|
37
|
+
return ERROR_SET.has(text);
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"values.js","sourceRoot":"","sources":["../../src/core/values.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AAEH,0FAA0F;AAC1F,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,SAAS;IACT,OAAO;IACP,QAAQ;IACR,SAAS;IACT,MAAM;IACN,OAAO;IACP,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,SAAS;CACD,CAAC;AAaX,MAAM,SAAS,GAAwB,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC;AAE5D,6EAA6E;AAC7E,MAAM,UAAU,SAAS,CAAC,IAAmB,EAAE,OAAgB;IAC7D,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,IAAI,IAAI,oCAAoC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACxF,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC5E,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,SAAS,CAAC,GAAG,CAAE,KAA6B,CAAC,KAAe,CAAC,CAC9D,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Positions, zones and A1 notation. Rows and columns are 0-based in memory;
|
|
3
|
+
* A1 is 1-based for rows and lettered for columns.
|
|
4
|
+
*
|
|
5
|
+
* @module core/zone
|
|
6
|
+
*/
|
|
7
|
+
/** A cell position: row and column, 0-based. */
|
|
8
|
+
export interface Position {
|
|
9
|
+
readonly row: number;
|
|
10
|
+
readonly col: number;
|
|
11
|
+
}
|
|
12
|
+
/** A rectangle of cells, inclusive on both ends, 0-based. */
|
|
13
|
+
export interface Zone {
|
|
14
|
+
readonly top: number;
|
|
15
|
+
readonly left: number;
|
|
16
|
+
readonly bottom: number;
|
|
17
|
+
readonly right: number;
|
|
18
|
+
}
|
|
19
|
+
/** A position on a named sheet. */
|
|
20
|
+
export interface CellAddress extends Position {
|
|
21
|
+
readonly sheet: string;
|
|
22
|
+
}
|
|
23
|
+
/** Column letters of a 0-based index: 0 → A, 25 → Z, 26 → AA. */
|
|
24
|
+
export declare function columnLetters(col: number): string;
|
|
25
|
+
/** The 0-based index of column letters: A → 0, AA → 26. Case-insensitive. */
|
|
26
|
+
export declare function columnIndex(letters: string): number;
|
|
27
|
+
/** `B3` for {row: 2, col: 1}. */
|
|
28
|
+
export declare function toA1(p: Position): string;
|
|
29
|
+
/** The position of `B3` (anchors ignored). Throws on anything else. */
|
|
30
|
+
export declare function parseA1(text: string): Position;
|
|
31
|
+
/** The zone of `A1:C4`, `B3` (one cell), in any corner order. */
|
|
32
|
+
export declare function parseZone(text: string): Zone;
|
|
33
|
+
/** `A1:C4`, or `B3` for a single cell. */
|
|
34
|
+
export declare function zoneToA1(z: Zone): string;
|
|
35
|
+
/** The smallest zone holding both positions. */
|
|
36
|
+
export declare function zoneOf(a: Position, b?: Position): Zone;
|
|
37
|
+
export declare function zoneContains(z: Zone, p: Position): boolean;
|
|
38
|
+
export declare function zonesOverlap(a: Zone, b: Zone): boolean;
|
|
39
|
+
export declare function zoneSize(z: Zone): {
|
|
40
|
+
rows: number;
|
|
41
|
+
cols: number;
|
|
42
|
+
};
|
|
43
|
+
/** A reference that may name a sheet: `Sheet2!B3`, `'My sheet'!A1:B2`. */
|
|
44
|
+
export declare function splitSheet(ref: string): {
|
|
45
|
+
sheet?: string;
|
|
46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AAC,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,GAAG,OAAO,CAE1D;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,OAAO,CAEtD;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAEhE;AAED,0EAA0E;AAC1E,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAWvE"}
|
package/lib/core/zone.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022-2026 Datalayer, Inc.
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
/** Column letters of a 0-based index: 0 → A, 25 → Z, 26 → AA. */
|
|
7
|
+
export function columnLetters(col) {
|
|
8
|
+
if (!Number.isInteger(col) || col < 0)
|
|
9
|
+
throw new Error(`No column at index ${col}.`);
|
|
10
|
+
let name = '';
|
|
11
|
+
let n = col + 1;
|
|
12
|
+
while (n > 0) {
|
|
13
|
+
const rest = (n - 1) % 26;
|
|
14
|
+
name = String.fromCharCode(65 + rest) + name;
|
|
15
|
+
n = Math.floor((n - 1) / 26);
|
|
16
|
+
}
|
|
17
|
+
return name;
|
|
18
|
+
}
|
|
19
|
+
/** The 0-based index of column letters: A → 0, AA → 26. Case-insensitive. */
|
|
20
|
+
export function columnIndex(letters) {
|
|
21
|
+
if (!/^[A-Za-z]{1,3}$/.test(letters))
|
|
22
|
+
throw new Error(`'${letters}' is not a column (A to XFD).`);
|
|
23
|
+
let n = 0;
|
|
24
|
+
for (const ch of letters.toUpperCase())
|
|
25
|
+
n = n * 26 + (ch.charCodeAt(0) - 64);
|
|
26
|
+
return n - 1;
|
|
27
|
+
}
|
|
28
|
+
/** `B3` for {row: 2, col: 1}. */
|
|
29
|
+
export function toA1(p) {
|
|
30
|
+
return `${columnLetters(p.col)}${p.row + 1}`;
|
|
31
|
+
}
|
|
32
|
+
const CELL = /^\$?([A-Za-z]{1,3})\$?([1-9][0-9]{0,6})$/;
|
|
33
|
+
/** The position of `B3` (anchors ignored). Throws on anything else. */
|
|
34
|
+
export function parseA1(text) {
|
|
35
|
+
const m = CELL.exec(text.trim());
|
|
36
|
+
if (!m)
|
|
37
|
+
throw new Error(`'${text}' is not a cell reference such as B3.`);
|
|
38
|
+
return { row: Number(m[2]) - 1, col: columnIndex(m[1]) };
|
|
39
|
+
}
|
|
40
|
+
/** The zone of `A1:C4`, `B3` (one cell), in any corner order. */
|
|
41
|
+
export function parseZone(text) {
|
|
42
|
+
const parts = text.trim().split(':');
|
|
43
|
+
if (parts.length > 2 || parts[0] === '')
|
|
44
|
+
throw new Error(`'${text}' is not a range such as A1:C4.`);
|
|
45
|
+
const a = parseA1(parts[0]);
|
|
46
|
+
const b = parts.length === 2 ? parseA1(parts[1]) : a;
|
|
47
|
+
return zoneOf(a, b);
|
|
48
|
+
}
|
|
49
|
+
/** `A1:C4`, or `B3` for a single cell. */
|
|
50
|
+
export function zoneToA1(z) {
|
|
51
|
+
const tl = toA1({ row: z.top, col: z.left });
|
|
52
|
+
return z.top === z.bottom && z.left === z.right
|
|
53
|
+
? tl
|
|
54
|
+
: `${tl}:${toA1({ row: z.bottom, col: z.right })}`;
|
|
55
|
+
}
|
|
56
|
+
/** The smallest zone holding both positions. */
|
|
57
|
+
export function zoneOf(a, b = a) {
|
|
58
|
+
return {
|
|
59
|
+
top: Math.min(a.row, b.row),
|
|
60
|
+
left: Math.min(a.col, b.col),
|
|
61
|
+
bottom: Math.max(a.row, b.row),
|
|
62
|
+
right: Math.max(a.col, b.col),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export function zoneContains(z, p) {
|
|
66
|
+
return p.row >= z.top && p.row <= z.bottom && p.col >= z.left && p.col <= z.right;
|
|
67
|
+
}
|
|
68
|
+
export function zonesOverlap(a, b) {
|
|
69
|
+
return a.left <= b.right && b.left <= a.right && a.top <= b.bottom && b.top <= a.bottom;
|
|
70
|
+
}
|
|
71
|
+
export function zoneSize(z) {
|
|
72
|
+
return { rows: z.bottom - z.top + 1, cols: z.right - z.left + 1 };
|
|
73
|
+
}
|
|
74
|
+
/** A reference that may name a sheet: `Sheet2!B3`, `'My sheet'!A1:B2`. */
|
|
75
|
+
export function splitSheet(ref) {
|
|
76
|
+
const bang = ref.lastIndexOf('!');
|
|
77
|
+
if (bang < 0)
|
|
78
|
+
return { ref };
|
|
79
|
+
let sheet = ref.slice(0, bang);
|
|
80
|
+
if (sheet.startsWith("'")) {
|
|
81
|
+
if (!sheet.endsWith("'") || sheet.length < 2)
|
|
82
|
+
throw new Error(`'${ref}' has an unclosed sheet name.`);
|
|
83
|
+
sheet = sheet.slice(1, -1).replace(/''/g, "'");
|
|
84
|
+
}
|
|
85
|
+
if (sheet === '')
|
|
86
|
+
throw new Error(`'${ref}' names an empty sheet.`);
|
|
87
|
+
return { sheet, ref: ref.slice(bang + 1) };
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=zone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zone.js","sourceRoot":"","sources":["../../src/core/zone.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA4BH,iEAAiE;AACjE,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,GAAG,GAAG,CAAC,CAAC;IACrF,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACb,MAAM,IAAI,GAAG,C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,GAAG,EAAE,CAAC;IAC7B,IAAI,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IAC/B,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;YAC1C,MAAM,IAAI,KAAK,CAAC,IAAI,GAAG,+BAA+B,CAAC,CAAC;QAC1D,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACjD,CAAC;IACD,IAAI,KAAK,KAAK,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,IAAI,GAAG,yBAAyB,CAAC,CAAC;IACpE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,EAAE,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/csv/index.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AAEH,OAAO,EAAE,CAAC"}
|
package/lib/csv/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/csv/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AAEH,cAAc,iBAAiB,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022-2026 Datalayer, Inc.
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* `@datalayer/cells`: a spreadsheet drawn on canvas, as a React component.
|
|
8
|
+
* Everything of `./core` is re-exported here, so a host imports from one place.
|
|
9
|
+
*
|
|
10
|
+
* @module cells
|
|
11
|
+
*/
|
|
12
|
+
export * from './core/index.js';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AAEH,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AAEH,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading Reactor contribution points the way a spreadsheet must: once, into
|
|
3
|
+
* an indexed table, rebuilt only when the platform changed.
|
|
4
|
+
*
|
|
5
|
+
* Reading a point is an activation event and returns a fresh array; the
|
|
6
|
+
* evaluator and the renderer cannot pay that per cell or per frame. A
|
|
7
|
+
* {@link PointTable} keeps the last resolution and the platform revision it
|
|
8
|
+
* was made at, and resolves again only when the revision moved.
|
|
9
|
+
*
|
|
10
|
+
* @module points/resolve
|
|
11
|
+
*/
|
|
12
|
+
import type { ContributionPoint, ReactorPlatformView } from '@datalayer/reactor';
|
|
13
|
+
/** The platform as a table reads it: contributions, and the revision that dates them. */
|
|
14
|
+
export type CellsPlatform = ReactorPlatformView & {
|
|
15
|
+
getRevision: () => number;
|
|
16
|
+
};
|
|
17
|
+
/** A contribution as a table keeps it: the value, and who contributed it. */
|
|
18
|
+
export interface Resolved<T> {
|
|
19
|
+
readonly value: T;
|
|
20
|
+
readonly plugin: string;
|
|
21
|
+
readonly id: string;
|
|
22
|
+
}
|
|
23
|
+
export interface PointTableOptions<T> {
|
|
24
|
+
/** What the point is, in words, for the refusals ("formula function"). */
|
|
25
|
+
readonly label: string;
|
|
26
|
+
/** The key a contribution is found by (a function's upper-cased name, a command's type). */
|
|
27
|
+
readonly key: (value: T) => string;
|
|
28
|
+
/** Checks a contribution's shape; throws a sentence when it is wrong. */
|
|
29
|
+
readonly check?: (value: T) => void;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A point resolved into a `Map` by key. A key contributed twice is refused
|
|
33
|
+
* with a sentence naming both plugins: two plugins fighting over one name is
|
|
34
|
+
* a bug, and the loser would otherwise fail invisibly.
|
|
35
|
+
*/
|
|
36
|
+
export declare class PointTable<T> {
|
|
37
|
+
#private;
|
|
38
|
+
constructor(platform: CellsPlatform, point: ContributionPoint<T>, options: PointTableOptions<T>);
|
|
39
|
+
/** The contribution of that key, or `undefined`. */
|
|
40
|
+
get(key: string): Resolved<T> | undefined;
|
|
41
|
+
/** Every contribution, in Reactor's order (`order`, then contribution order). */
|
|
42
|
+
all(): readonly Resolved<T>[];
|
|
43
|
+
keys(): IterableIterator<string>;
|
|
44
|
+
/** The platform revision the table was last resolved at. */
|
|
45
|
+
get revision(): number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The one contribution of a point that must have exactly one winner: the
|
|
49
|
+
* first by `order`. None is refused, and so is a tie at the winning `order`
|
|
50
|
+
* (two providers with equal claim), as personal-agent-protocol's
|
|
51
|
+
* `firstContribution` does.
|
|
52
|
+
*/
|
|
53
|
+
export declare function firstContribution<T>(platform: ReactorPlatformView, point: ContributionPoint<T>, label: string): Resolved<T>;
|
|
54
|
+
/** Like {@link firstContribution}, but none is allowed: the feature is off. A tie is still refused. */
|
|
55
|
+
export declare function optionalContribution<T>(platform: ReactorPlatformView, point: ContributionPoint<T>, label: string): Resolved<T> | undefined;
|
|
56
|
+
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/points/resolve.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAgB,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE/F,yFAAyF;AACzF,MAAM,MAAM,aAAa,GAAG,mBAAmB,GAAG;IAAE,WAAW,EAAE,MAAM,MAAM,CAAA;CAAE,CAAC;AAEhF,6EAA6E;AAC7E,MAAM,WAAW,QAAQ,CAAC,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAClB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,0EAA0E;IAC1E,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,4FAA4F;IAC5F,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC;IACnC,yEAAyE;IACzE,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;CACrC;AAED;;;;GAIG;AACH,qBAAa,UAAU,CAAC,CAAC;;gBAQX,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAM/F,oDAAoD;IACpD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS;IAKzC,iFAAiF;IACjF,GAAG,IAAI,SAAS,QAAQ,CAAC,CAAC,CAAC,EAAE;IAK7B,IAAI,IAAI,gBAAgB,CAAC,MAAM,CAAC;IAKhC,4DAA4D;IAC5D,IAAI,QAAQ,IAAI,MAAM,CAGrB;CA6BF;AAeD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,QAAQ,EAAE,mBAAmB,EAC7B,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC3B,KAAK,EAAE,MAAM,GACZ,QAAQ,CAAC,CAAC,CAAC,CAMb;AAED,uGAAuG;AACvG,wBAAgB,oBAAoB,CAAC,CAAC,EACpC,QAAQ,EAAE,mBAAmB,EAC7B,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC3B,KAAK,EAAE,MAAM,GACZ,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAYzB"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022-2026 Datalayer, Inc.
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* A point resolved into a `Map` by key. A key contributed twice is refused
|
|
8
|
+
* with a sentence naming both plugins: two plugins fighting over one name is
|
|
9
|
+
* a bug, and the loser would otherwise fail invisibly.
|
|
10
|
+
*/
|
|
11
|
+
export class PointTable {
|
|
12
|
+
#platform;
|
|
13
|
+
#point;
|
|
14
|
+
#options;
|
|
15
|
+
#revision = -1;
|
|
16
|
+
#byKey = new Map();
|
|
17
|
+
#ordered = [];
|
|
18
|
+
constructor(platform, point, options) {
|
|
19
|
+
this.#platform = platform;
|
|
20
|
+
this.#point = point;
|
|
21
|
+
this.#options = options;
|
|
22
|
+
}
|
|
23
|
+
/** The contribution of that key, or `undefined`. */
|
|
24
|
+
get(key) {
|
|
25
|
+
this.#refresh();
|
|
26
|
+
return this.#byKey.get(key);
|
|
27
|
+
}
|
|
28
|
+
/** Every contribution, in Reactor's order (`order`, then contribution order). */
|
|
29
|
+
all() {
|
|
30
|
+
this.#refresh();
|
|
31
|
+
return this.#ordered;
|
|
32
|
+
}
|
|
33
|
+
keys() {
|
|
34
|
+
this.#refresh();
|
|
35
|
+
return this.#byKey.keys();
|
|
36
|
+
}
|
|
37
|
+
/** The platform revision the table was last resolved at. */
|
|
38
|
+
get revision() {
|
|
39
|
+
this.#refresh();
|
|
40
|
+
return this.#revision;
|
|
41
|
+
}
|
|
42
|
+
#refresh() {
|
|
43
|
+
const revision = this.#platform.getRevision();
|
|
44
|
+
if (revision === this.#revision)
|
|
45
|
+
return;
|
|
46
|
+
const contributions = this.#platform.getContributions(this.#point);
|
|
47
|
+
const byKey = new Map();
|
|
48
|
+
const ordered = [];
|
|
49
|
+
for (const c of contributions) {
|
|
50
|
+
const resolved = checked(c, this.#options);
|
|
51
|
+
const key = this.#options.key(c.value);
|
|
52
|
+
const taken = byKey.get(key);
|
|
53
|
+
if (taken !== undefined) {
|
|
54
|
+
throw new Error(`The ${this.#options.label} '${key}' is contributed twice to ${this.#point.id}: ` +
|
|
55
|
+
`by ${taken.plugin} (id '${taken.id}') and by ${c.plugin} (id '${c.id}'). ` +
|
|
56
|
+
`Disable one of the two plugins, or rename one ${this.#options.label}.`);
|
|
57
|
+
}
|
|
58
|
+
byKey.set(key, resolved);
|
|
59
|
+
ordered.push(resolved);
|
|
60
|
+
}
|
|
61
|
+
// The read itself may have woken lazy plugins, which bumps the revision on
|
|
62
|
+
// a microtask: record the revision read *before* that, so their
|
|
63
|
+
// contributions are picked up on the next access.
|
|
64
|
+
this.#revision = revision;
|
|
65
|
+
this.#byKey = byKey;
|
|
66
|
+
this.#ordered = ordered;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function checked(c, options) {
|
|
70
|
+
if (options.check) {
|
|
71
|
+
try {
|
|
72
|
+
options.check(c.value);
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
throw new Error(`${c.plugin} contributes a malformed ${options.label} (id '${c.id}'): ${error.message}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return { value: c.value, plugin: c.plugin, id: c.id };
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The one contribution of a point that must have exactly one winner: the
|
|
82
|
+
* first by `order`. None is refused, and so is a tie at the winning `order`
|
|
83
|
+
* (two providers with equal claim), as personal-agent-protocol's
|
|
84
|
+
* `firstContribution` does.
|
|
85
|
+
*/
|
|
86
|
+
export function firstContribution(platform, point, label) {
|
|
87
|
+
const found = optionalContribution(platform, point, label);
|
|
88
|
+
if (found === undefined) {
|
|
89
|
+
throw new Error(`No plugin contributes a ${label} (${point.id}).`);
|
|
90
|
+
}
|
|
91
|
+
return found;
|
|
92
|
+
}
|
|
93
|
+
/** Like {@link firstContribution}, but none is allowed: the feature is off. A tie is still refused. */
|
|
94
|
+
export function optionalContribution(platform, point, label) {
|
|
95
|
+
const contributions = platform.getContributions(point);
|
|
96
|
+
const [first, second] = contributions;
|
|
97
|
+
if (first === undefined)
|
|
98
|
+
return undefined;
|
|
99
|
+
if (second !== undefined && second.order === first.order) {
|
|
100
|
+
throw new Error(`Two plugins contribute a ${label} (${point.id}) at the same order ${first.order}: ` +
|
|
101
|
+
`${first.plugin} (id '${first.id}') and ${second.plugin} (id '${second.id}'). ` +
|
|
102
|
+
`Give one a lower order, or disable one.`);
|
|
103
|
+
}
|
|
104
|
+
return { value: first.value, plugin: first.plugin, id: first.id };
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/points/resolve.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAmCH;;;;GAIG;AACH,MAAM,OAAO,UAAU;IACZ,SAAS,CAAgB;IACzB,MAAM,CAAuB;IAC7B,QAAQ,CAAuB;IACxC,SAAS,GAAG,CAAC,CAAC,CAAC;IACf,MAAM,GAAG,IAAI,GAAG,EAAuB,CAAC;IACxC,QAAQ,GAAkB,EAAE,CAAC;IAE7B,YAAY,QAAuB,EAAE,KAA2B,EA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@@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/xlsx/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|