@molecule/app-spreadsheet-grid-solid 0.0.0-stage → 0.0.1-stage

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,74 @@
1
+ import type { CellMap, CellRef, CellValue, SpreadsheetSelection } from './types.js';
2
+ /**
3
+ * Convert a 0-indexed column number to its A1 letter (`0` → `'A'`, `25` →
4
+ * `'Z'`, `26` → `'AA'`, `701` → `'ZZ'`, `702` → `'AAA'`).
5
+ *
6
+ * @param col - 0-indexed column number.
7
+ * @returns Uppercase A1 column letter.
8
+ */
9
+ export declare function columnLetter(col: number): string;
10
+ /**
11
+ * Build an A1 reference from 0-indexed row and column numbers.
12
+ *
13
+ * @param row - 0-indexed row number.
14
+ * @param col - 0-indexed column number.
15
+ * @returns A1-style cell reference (e.g. `'B3'`).
16
+ */
17
+ export declare function cellRef(row: number, col: number): CellRef;
18
+ /**
19
+ * Normalize a possibly-inverted selection so `r1 <= r2 && c1 <= c2`.
20
+ *
21
+ * @param sel - Raw selection (anchor and focus).
22
+ * @returns Selection with `r1`/`c1` as top-left and `r2`/`c2` as bottom-right.
23
+ */
24
+ export declare function normalizeSelection(sel: SpreadsheetSelection): SpreadsheetSelection;
25
+ /**
26
+ * Test whether `(row, col)` is inside the selection.
27
+ *
28
+ * @param sel - Selection to test against.
29
+ * @param row - 0-indexed row number.
30
+ * @param col - 0-indexed column number.
31
+ * @returns `true` when the cell is in the selection.
32
+ */
33
+ export declare function isInSelection(sel: SpreadsheetSelection, row: number, col: number): boolean;
34
+ /**
35
+ * Format a cell value for display. `null`/`undefined` render as the empty
36
+ * string; booleans become `TRUE`/`FALSE` (matching common spreadsheet
37
+ * tools); numbers and strings stringify as-is.
38
+ *
39
+ * @param value - The raw cell value.
40
+ * @returns Display string.
41
+ */
42
+ export declare function formatCellValue(value: CellValue | undefined): string;
43
+ /**
44
+ * Parse a TSV (tab-separated values) string into a 2D array of strings.
45
+ * Empty trailing lines are ignored. Used to ingest clipboard paste data.
46
+ *
47
+ * @param text - Clipboard text (typically TSV).
48
+ * @returns 2D array of cell strings — `rows[r][c]`.
49
+ */
50
+ export declare function parseClipboardTsv(text: string): string[][];
51
+ /**
52
+ * Serialize a rectangular selection to TSV (tab-separated values) so it
53
+ * can round-trip with Excel/Google Sheets via the system clipboard.
54
+ *
55
+ * @param cells - Source cell map.
56
+ * @param sel - Selection to serialize.
57
+ * @returns TSV-formatted string with `\n` row separators.
58
+ */
59
+ export declare function serializeSelectionTsv(cells: CellMap, sel: SpreadsheetSelection): string;
60
+ /**
61
+ * Compute the inclusive `[start, end]` window of indices to render given
62
+ * the scroll offset, viewport size, item size, and total count. Adds an
63
+ * `overscan` margin on each side so newly-visible cells are pre-rendered
64
+ * during fast scrolls.
65
+ *
66
+ * @param scroll - Current scroll position (px).
67
+ * @param viewport - Viewport size (px) along the scroll axis.
68
+ * @param itemSize - Per-item size (px) along the scroll axis.
69
+ * @param total - Total number of items.
70
+ * @param overscan - Extra items to render on each side (default `2`).
71
+ * @returns `[startIndex, endIndex]` (both inclusive, clamped to `[0, total)`).
72
+ */
73
+ export declare function computeVisibleRange(scroll: number, viewport: number, itemSize: number, total: number, overscan?: number): [number, number];
74
+ //# sourceMappingURL=utilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAEnF;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAQhD;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,oBAAoB,GAAG,oBAAoB,CAOlF;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,oBAAoB,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAG1F;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,MAAM,CAIpE;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,CAM1D;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,oBAAoB,GAAG,MAAM,CAWvF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,QAAQ,SAAI,GACX,CAAC,MAAM,EAAE,MAAM,CAAC,CAKlB"}
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Convert a 0-indexed column number to its A1 letter (`0` → `'A'`, `25` →
3
+ * `'Z'`, `26` → `'AA'`, `701` → `'ZZ'`, `702` → `'AAA'`).
4
+ *
5
+ * @param col - 0-indexed column number.
6
+ * @returns Uppercase A1 column letter.
7
+ */
8
+ export function columnLetter(col) {
9
+ let n = col;
10
+ let result = '';
11
+ while (n >= 0) {
12
+ result = String.fromCharCode(65 + (n % 26)) + result;
13
+ n = Math.floor(n / 26) - 1;
14
+ }
15
+ return result;
16
+ }
17
+ /**
18
+ * Build an A1 reference from 0-indexed row and column numbers.
19
+ *
20
+ * @param row - 0-indexed row number.
21
+ * @param col - 0-indexed column number.
22
+ * @returns A1-style cell reference (e.g. `'B3'`).
23
+ */
24
+ export function cellRef(row, col) {
25
+ return `${columnLetter(col)}${row + 1}`;
26
+ }
27
+ /**
28
+ * Normalize a possibly-inverted selection so `r1 <= r2 && c1 <= c2`.
29
+ *
30
+ * @param sel - Raw selection (anchor and focus).
31
+ * @returns Selection with `r1`/`c1` as top-left and `r2`/`c2` as bottom-right.
32
+ */
33
+ export function normalizeSelection(sel) {
34
+ return {
35
+ r1: Math.min(sel.r1, sel.r2),
36
+ c1: Math.min(sel.c1, sel.c2),
37
+ r2: Math.max(sel.r1, sel.r2),
38
+ c2: Math.max(sel.c1, sel.c2),
39
+ };
40
+ }
41
+ /**
42
+ * Test whether `(row, col)` is inside the selection.
43
+ *
44
+ * @param sel - Selection to test against.
45
+ * @param row - 0-indexed row number.
46
+ * @param col - 0-indexed column number.
47
+ * @returns `true` when the cell is in the selection.
48
+ */
49
+ export function isInSelection(sel, row, col) {
50
+ const n = normalizeSelection(sel);
51
+ return row >= n.r1 && row <= n.r2 && col >= n.c1 && col <= n.c2;
52
+ }
53
+ /**
54
+ * Format a cell value for display. `null`/`undefined` render as the empty
55
+ * string; booleans become `TRUE`/`FALSE` (matching common spreadsheet
56
+ * tools); numbers and strings stringify as-is.
57
+ *
58
+ * @param value - The raw cell value.
59
+ * @returns Display string.
60
+ */
61
+ export function formatCellValue(value) {
62
+ if (value === null || value === undefined)
63
+ return '';
64
+ if (typeof value === 'boolean')
65
+ return value ? 'TRUE' : 'FALSE';
66
+ return String(value);
67
+ }
68
+ /**
69
+ * Parse a TSV (tab-separated values) string into a 2D array of strings.
70
+ * Empty trailing lines are ignored. Used to ingest clipboard paste data.
71
+ *
72
+ * @param text - Clipboard text (typically TSV).
73
+ * @returns 2D array of cell strings — `rows[r][c]`.
74
+ */
75
+ export function parseClipboardTsv(text) {
76
+ const lines = text.replace(/\r\n/g, '\n').split('\n');
77
+ while (lines.length > 0 && lines[lines.length - 1] === '') {
78
+ lines.pop();
79
+ }
80
+ return lines.map((line) => line.split('\t'));
81
+ }
82
+ /**
83
+ * Serialize a rectangular selection to TSV (tab-separated values) so it
84
+ * can round-trip with Excel/Google Sheets via the system clipboard.
85
+ *
86
+ * @param cells - Source cell map.
87
+ * @param sel - Selection to serialize.
88
+ * @returns TSV-formatted string with `\n` row separators.
89
+ */
90
+ export function serializeSelectionTsv(cells, sel) {
91
+ const n = normalizeSelection(sel);
92
+ const rows = [];
93
+ for (let r = n.r1; r <= n.r2; r += 1) {
94
+ const cols = [];
95
+ for (let c = n.c1; c <= n.c2; c += 1) {
96
+ cols.push(formatCellValue(cells.get(cellRef(r, c))));
97
+ }
98
+ rows.push(cols.join('\t'));
99
+ }
100
+ return rows.join('\n');
101
+ }
102
+ /**
103
+ * Compute the inclusive `[start, end]` window of indices to render given
104
+ * the scroll offset, viewport size, item size, and total count. Adds an
105
+ * `overscan` margin on each side so newly-visible cells are pre-rendered
106
+ * during fast scrolls.
107
+ *
108
+ * @param scroll - Current scroll position (px).
109
+ * @param viewport - Viewport size (px) along the scroll axis.
110
+ * @param itemSize - Per-item size (px) along the scroll axis.
111
+ * @param total - Total number of items.
112
+ * @param overscan - Extra items to render on each side (default `2`).
113
+ * @returns `[startIndex, endIndex]` (both inclusive, clamped to `[0, total)`).
114
+ */
115
+ export function computeVisibleRange(scroll, viewport, itemSize, total, overscan = 2) {
116
+ if (total <= 0 || itemSize <= 0)
117
+ return [0, -1];
118
+ const start = Math.max(0, Math.floor(scroll / itemSize) - overscan);
119
+ const end = Math.min(total - 1, Math.ceil((scroll + viewport) / itemSize) + overscan);
120
+ return [start, end];
121
+ }
122
+ //# sourceMappingURL=utilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.js","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,IAAI,CAAC,GAAG,GAAG,CAAA;IACX,IAAI,MAAM,GAAG,EAAE,CAAA;IACf,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACd,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,MAAM,CAAA;QACpD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IACD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACxB,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAc,EACd,QAAgB,EAChB,QAAgB,EAChB,KAAa,EACb,QAAQ,GAAG,CAAC;IAEZ,IAAI,KAAK,IAAI,CAAC,IAAI,QAAQ,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAC/C,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,GAAG,QAAQ,CAAC,CAAA;IACnE,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,QAAQ,CAAC,GAAG,QAAQ,CAAC,GAAG,QAAQ,CAAC,CAAA;IACrF,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;AACrB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,70 @@
1
1
  {
2
2
  "name": "@molecule/app-spreadsheet-grid-solid",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.1-stage",
4
+ "description": "High-performance virtualized spreadsheet cell grid with frozen rows/columns, range selection, copy/paste as TSV, and in-cell editing — pairs with @molecule/api-formula-engine",
5
+ "homepage": "https://www.molecule.dev/packages/app-spreadsheet-grid-solid",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc",
21
+ "dev": "tsc --watch",
22
+ "test": "vitest run",
23
+ "test:watch": "vitest"
24
+ },
25
+ "keywords": [
26
+ "molecule",
27
+ "spreadsheet",
28
+ "grid",
29
+ "virtualized",
30
+ "solid"
31
+ ],
32
+ "author": "Molecule Dev, Inc. (https://molecule.dev)",
33
+ "license": "Apache-2.0",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/molecule-dev/molecule.git",
37
+ "directory": "packages/app/features/spreadsheet-grid-solid"
38
+ },
39
+ "engines": {
40
+ "node": ">=20"
41
+ },
42
+ "bugs": "https://github.com/molecule-dev/molecule/issues",
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "peerDependencies": {
47
+ "@molecule/app-clipboard": "^1.0.1",
48
+ "@molecule/app-i18n": "^1.0.1",
49
+ "@molecule/app-solid": "^3.5.0",
50
+ "@molecule/app-ui": "^1.3.11",
51
+ "@molecule/app-ui-solid": "^1.1.0",
52
+ "solid-js": "^1.8.0"
53
+ },
54
+ "devDependencies": {
55
+ "@molecule/app-clipboard": "1.0.5",
56
+ "@molecule/app-framework-conformance": "0.0.0",
57
+ "@molecule/app-i18n": "1.2.2",
58
+ "@molecule/app-icons": "1.0.4",
59
+ "@molecule/app-solid": "3.7.2",
60
+ "@molecule/app-ui": "1.4.0",
61
+ "@molecule/app-ui-solid": "1.1.5",
62
+ "@molecule/app-ui-tailwind": "1.3.0",
63
+ "@types/node": "26.6.5",
64
+ "jsdom": "30.1.3",
65
+ "solid-js": "1.9.17",
66
+ "typescript": "6.0.3",
67
+ "vite-plugin-solid": "2.11.15",
68
+ "vitest": "4.1.12"
69
+ }
70
+ }