@molecule/app-spreadsheet-grid-svelte 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,121 @@
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
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Svelte action reproducing react-dom's controlled-input `value` handling for
3
+ * the grid's in-cell editor.
4
+ *
5
+ * Svelte's `value={x}` sets only the `value` property, while a React input
6
+ * carries BOTH the property and the `value` attribute (react-dom applies the
7
+ * value through the `defaultValue` property, whose reflection IS that
8
+ * attribute). Vue writes both for a plain `value` prop, Solid uses
9
+ * `attr:value`, Angular binds `[attr.value]` plus a property sync; this
10
+ * package's raw input needs the same two writes, so this action re-applies
11
+ * React's documented behavior: the property, then the attribute through
12
+ * `defaultValue`, on mount and on every value change.
13
+ *
14
+ * @module
15
+ */
16
+ /**
17
+ * Applies `props.value` to the input the way react-dom applies a controlled
18
+ * `value`: through the `value` property (the live value) and the
19
+ * `defaultValue` property (whose reflection is the DOM `value` attribute), so
20
+ * both reads of the field agree.
21
+ *
22
+ * @param node - The input element.
23
+ * @param props - The controlled value, as React's `<input value>` takes it.
24
+ * @returns The action's update, re-applying on a changed value.
25
+ */
26
+ export declare function reactInputValue(node: HTMLInputElement, props: {
27
+ value?: unknown;
28
+ }): {
29
+ update: (next: {
30
+ value?: unknown;
31
+ }) => void;
32
+ };
33
+ //# sourceMappingURL=value.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value.d.ts","sourceRoot":"","sources":["../src/value.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,gBAAgB,EACtB,KAAK,EAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GACzB;IAAE,MAAM,EAAE,CAAC,IAAI,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAA;CAAE,CAajD"}
package/dist/value.js ADDED
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Svelte action reproducing react-dom's controlled-input `value` handling for
3
+ * the grid's in-cell editor.
4
+ *
5
+ * Svelte's `value={x}` sets only the `value` property, while a React input
6
+ * carries BOTH the property and the `value` attribute (react-dom applies the
7
+ * value through the `defaultValue` property, whose reflection IS that
8
+ * attribute). Vue writes both for a plain `value` prop, Solid uses
9
+ * `attr:value`, Angular binds `[attr.value]` plus a property sync; this
10
+ * package's raw input needs the same two writes, so this action re-applies
11
+ * React's documented behavior: the property, then the attribute through
12
+ * `defaultValue`, on mount and on every value change.
13
+ *
14
+ * @module
15
+ */
16
+ /**
17
+ * Applies `props.value` to the input the way react-dom applies a controlled
18
+ * `value`: through the `value` property (the live value) and the
19
+ * `defaultValue` property (whose reflection is the DOM `value` attribute), so
20
+ * both reads of the field agree.
21
+ *
22
+ * @param node - The input element.
23
+ * @param props - The controlled value, as React's `<input value>` takes it.
24
+ * @returns The action's update, re-applying on a changed value.
25
+ */
26
+ export function reactInputValue(node, props) {
27
+ const apply = (next) => {
28
+ const { value } = next;
29
+ if (value === undefined || value === null) {
30
+ node.removeAttribute('value');
31
+ return;
32
+ }
33
+ const text = String(value);
34
+ if (node.value !== text)
35
+ node.value = text;
36
+ if (node.defaultValue !== text)
37
+ node.defaultValue = text;
38
+ };
39
+ apply(props);
40
+ return { update: apply };
41
+ }
package/package.json CHANGED
@@ -1,6 +1,79 @@
1
1
  {
2
2
  "name": "@molecule/app-spreadsheet-grid-svelte",
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-svelte",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "svelte": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "svelte": "./dist/index.js",
18
+ "files": [
19
+ "dist",
20
+ "!dist/**/__tests__",
21
+ "!dist/**/*.test.*",
22
+ "!dist/**/*.spec.*",
23
+ "README.md"
24
+ ],
25
+ "scripts": {
26
+ "build": "svelte-check --tsconfig ./tsconfig.json --fail-on-warnings && svelte-package --input src --output dist --tsconfig ./tsconfig.json",
27
+ "dev": "svelte-package --input src --output dist --tsconfig ./tsconfig.json --watch",
28
+ "test": "vitest run",
29
+ "test:watch": "vitest"
30
+ },
31
+ "keywords": [
32
+ "molecule",
33
+ "spreadsheet",
34
+ "grid",
35
+ "virtualized",
36
+ "svelte"
37
+ ],
38
+ "author": "Molecule Dev, Inc. (https://molecule.dev)",
39
+ "license": "Apache-2.0",
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "https://github.com/molecule-dev/molecule.git",
43
+ "directory": "packages/app/features/spreadsheet-grid-svelte"
44
+ },
45
+ "engines": {
46
+ "node": ">=20"
47
+ },
48
+ "bugs": "https://github.com/molecule-dev/molecule/issues",
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "peerDependencies": {
53
+ "@molecule/app-clipboard": "^1.0.1",
54
+ "@molecule/app-i18n": "^1.0.1",
55
+ "@molecule/app-svelte": "^3.5.0",
56
+ "@molecule/app-ui": "^1.3.11",
57
+ "@molecule/app-ui-svelte": "^1.1.0",
58
+ "svelte": "^5.0.0"
59
+ },
60
+ "devDependencies": {
61
+ "@molecule/app-clipboard": "1.0.5",
62
+ "@molecule/app-framework-conformance": "0.0.0",
63
+ "@molecule/app-i18n": "1.2.2",
64
+ "@molecule/app-icons": "1.0.4",
65
+ "@molecule/app-svelte": "3.7.2",
66
+ "@molecule/app-ui": "1.4.0",
67
+ "@molecule/app-ui-svelte": "1.1.7",
68
+ "@molecule/app-ui-tailwind": "1.3.0",
69
+ "@sveltejs/package": "3.0.2",
70
+ "@sveltejs/vite-plugin-svelte": "7.1.2",
71
+ "@types/node": "26.6.5",
72
+ "jsdom": "30.1.3",
73
+ "svelte": "5.57.2",
74
+ "svelte-check": "4.7.7",
75
+ "typescript": "6.0.3",
76
+ "vite": "8.3.5",
77
+ "vitest": "4.1.12"
78
+ }
79
+ }