@8sheets/data-grid-react 0.0.0-stage → 1.0.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.md ADDED
@@ -0,0 +1,36 @@
1
+ # 8sheets npm Package Licence
2
+
3
+ > Version 1.0, 17 November 2026. It covers the packages published on npm: 8sheets Spreadsheet (`8sheets`, `@8sheets/core`, `@8sheets/react`, `@8sheets/vue`, `@8sheets/angular`) and 8sheets Data Grid (`@8sheets/data-grid`, `@8sheets/data-grid-react`, `@8sheets/data-grid-vue`, `@8sheets/data-grid-angular`). One paid licence covers both products. The full terms of the paid licence, the 8sheets Source Licence, are at https://8sheets.com/licence/; prices are at https://8sheets.com/pricing/.
4
+
5
+ Copyright (c) 2026 8cells Jarosław Kaczmarski. All rights reserved. This is commercial software. It is not open source.
6
+
7
+ ## 1. Evaluation
8
+
9
+ You may install this package and use it free of charge to evaluate 8sheets: in development, in tests, in prototypes and in demos that you do not offer to anyone as a product or service.
10
+
11
+ ## 2. Use in a product
12
+
13
+ Any other use needs a paid licence, bought at https://8sheets.com/pricing/. This includes using the package in an application, website, service or system that you deploy or make available to its users, including your own employees. The licence you buy decides who may use your product:
14
+
15
+ - **Internal** (999 USD, once per company): your product is used only inside your company.
16
+ - **SaaS / OEM** (2,999 USD, once per company): your product is offered to people outside your company.
17
+ - **Enterprise** (priced in a separate agreement): any use, under that agreement.
18
+
19
+ Each licence covers every developer and every deployment of the company that holds it. There is no licence key. Once you hold a licence, the 8sheets Source Licence (https://8sheets.com/licence/) governs your use of this package and replaces sections 1 and 3 of this file.
20
+
21
+ ## 3. Restrictions
22
+
23
+ Without a licence that allows it, you may not:
24
+
25
+ 1. use the package in production, in a product or for a customer;
26
+ 2. publish, sell, sublicense or redistribute the package or any part of it on its own, or as a component, SDK or library for other developers;
27
+ 3. reverse engineer, decompile or de-minify the package, except as far as the law allows despite this restriction;
28
+ 4. remove or change copyright and licence notices.
29
+
30
+ ## 4. Third-party components
31
+
32
+ The package includes data and artwork under their own licences (icons, map data, dictionaries and thesauri). Their notices are in the files next to that data (`*.NOTICE.txt`, `*.LICENSE.txt`, `charts/geo/NOTICE`) and listed at https://8sheets.com/notices/. Those terms apply to those parts.
33
+
34
+ ## 5. No warranty
35
+
36
+ The package is provided "as is", without warranty of any kind. To the extent the law allows, 8cells Jarosław Kaczmarski is not liable for any damages arising from its use.
package/README.md CHANGED
@@ -1,3 +1,46 @@
1
- # Temporary Holding Version
1
+ # 8sheets Data Grid for React
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `<DataGrid>` puts an [8sheets Data Grid](https://8sheets.com/data-grid/) in a React app. It works with React 18 and 19, StrictMode included, and with server rendering. Props, the change event and the ref are typed. This is version 1.0.0.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm i @8sheets/data-grid-react @8sheets/data-grid
9
+ ```
10
+
11
+ ## Use
12
+
13
+ ```jsx
14
+ import { useMemo, useRef } from 'react';
15
+ import { DataGrid } from '@8sheets/data-grid-react';
16
+
17
+ export function Orders({ orders }) {
18
+ const grid = useRef(null);
19
+ const options = useMemo(() => ({ title: 'Orders', data: orders, chrome: 'light' }), [orders]);
20
+ return (
21
+ <div style={{ height: 480 }}>
22
+ <DataGrid ref={grid} options={options} onChange={(change) => console.log(change.action)} />
23
+ </div>
24
+ );
25
+ }
26
+ ```
27
+
28
+ The component renders one `<div>` that fills its container, so the container needs a height.
29
+
30
+ - **`options`** goes to `mountTable` as it is, including options a later release of the grid adds. A changed `chrome` goes to `setChrome` in place; any other changed option mounts the grid again. `data` is compared by identity, so keep the same array (`useMemo`) until the records change.
31
+ - **`onChange(change)`** reports each data change, by the user or through the API. The grid's other events (`onStateChange`, `onRangeChange`, `onBeforeEdit`…) and any other `on…` prop go to the grid as the options of those names. Handlers always come from the latest render.
32
+ - **`onReady(grid)`** gives the grid each time it has mounted; **`onError(err)`** reports a failed mount or an action inside the grid that failed.
33
+ - **The ref** (`DataGridRef`) has `grid` and every method of the grid except `destroy`, `on` and `off`.
34
+ - On unmount the grid is destroyed, with its Worker.
35
+
36
+ ## Next.js and Vite
37
+
38
+ `data-grid.js` is marked `'use client'` and mounts in an effect, so the server sends an empty `<div>`. In Vite set `worker: { format: 'es' }`, and before Vite 8 also `optimizeDeps: { exclude: ['@8sheets/data-grid', '@8sheets/data-grid-react'] }`.
39
+
40
+ ## Documentation
41
+
42
+ [Framework wrappers](https://8sheets.com/docs/data-grid/frameworks/) for this component in detail, and the [API reference](https://8sheets.com/docs/data-grid/api/) for every option of the grid.
43
+
44
+ ## Licence
45
+
46
+ 8sheets is commercial software, not open source. You may install it and try it for free, to evaluate it. Using it in a product, or deploying it for your users or your own staff, needs a licence from [8sheets.com/pricing](https://8sheets.com/pricing/): **Internal** 999 USD or **SaaS / OEM** 2,999 USD, each paid once per company and covering every developer and every deployment, or **Enterprise**, quoted. One licence covers both 8sheets products, Spreadsheet and Data Grid. There is no licence key and nothing in the package checks for one. The terms are in `LICENSE.md` and, once you hold a licence, the [8sheets Source Licence](https://8sheets.com/licence/).
package/data-grid.js ADDED
@@ -0,0 +1,202 @@
1
+ 'use client';
2
+ // <DataGrid>: an 8sheets Data Grid as a React component (React 18 and 19). See README.md.
3
+ import { createElement, forwardRef, useEffect, useImperativeHandle, useLayoutEffect, useRef, useState } from 'react';
4
+ import { mountTable } from '@8sheets/data-grid';
5
+
6
+ // useLayoutEffect warns during server rendering in React 18; neither runs there.
7
+ const useClientLayoutEffect = typeof document === 'undefined' ? useEffect : useLayoutEffect;
8
+
9
+ /** A prop or option that is a callback of the grid: `onChange`, and any `on…` option a later release adds. */
10
+ const isHandler = (key) => /^on[A-Z]/.test(key);
11
+ /** The component's own callbacks, which never go to the grid. */
12
+ const OWN = new Set(['onReady', 'onError']);
13
+ /** Compared by identity, not by value: records can be large. Pass a new array to load new records. */
14
+ const BY_IDENTITY = new Set(['data']);
15
+
16
+ /**
17
+ * The grid's methods the ref handle offers, each calling the mounted grid. The same list is in the Vue and
18
+ * Angular wrappers. `destroy`, `on` and `off` are left out: the component owns the grid's life, and props carry
19
+ * its events across a remount.
20
+ */
21
+ const GRID_METHODS = [
22
+ 'openFile', 'setData', 'setDataSource', 'getSources', 'setSource', 'getSource', 'refresh',
23
+ 'getState', 'setState', 'updateState', 'resetState', 'setSearch',
24
+ 'setFilters', 'addFilter', 'clearFilters', 'setQuickFilter', 'getDistinctValues',
25
+ 'setSort', 'sortBy', 'clearSort', 'setGroups', 'groupBy', 'clearGroups',
26
+ 'expandGroup', 'collapseGroup', 'expandAll', 'collapseAll', 'setSummary', 'setTotalsRow', 'setFilterRow',
27
+ 'getFields', 'getColumn', 'setColumns', 'setColumn', 'moveColumn', 'autosizeColumn', 'addCalculatedField',
28
+ 'getSavedViews', 'saveView', 'restoreView', 'deleteView',
29
+ 'openPivot', 'closePivot', 'getChartData',
30
+ 'getPage', 'setPage', 'setScrolling', 'getViewport', 'scrollToRow', 'scrollToRecord', 'scrollToColumn', 'focusCell', 'getFocusedCell',
31
+ 'getRange', 'setRange', 'copyRange',
32
+ 'getSelection', 'setSelection', 'selectRecords', 'selectAll', 'clearSelection', 'getSelectedIds',
33
+ 'openRecordDetails', 'openDialog', 'closeDialog', 'expandRecord', 'collapseRecord', 'getExpandedRecord',
34
+ 'isEditable', 'enableEditing', 'setCellValue', 'updateRecords', 'addRecords', 'removeRecords', 'paste', 'fillDown',
35
+ 'undo', 'redo', 'canUndo', 'canRedo', 'startEdit', 'stopEdit', 'getEditingCell',
36
+ 'exportResults', 'download', 'createShareLink', 'revokeShareLink',
37
+ 'isLoading', 'cancelLoad',
38
+ 'setChrome', 'getChrome', 'setLanguage', 'getLanguage', 'setOptions',
39
+ 'getRecords', 'getRecord', 'getCell', 'getCounts', 'getTotals',
40
+ ];
41
+
42
+ const isPlain = (v) => v !== null && typeof v === 'object' && (Array.isArray(v) || Object.getPrototypeOf(v) === Object.prototype || Object.getPrototypeOf(v) === null);
43
+
44
+ /**
45
+ * Equal by value through plain objects and arrays, by identity otherwise (elements, files, typed arrays).
46
+ * Two functions count as equal, so an inline renderer or data source method doesn't remount the grid each
47
+ * render: a grid keeps the functions it was mounted with, except handlers, which always reach the latest.
48
+ */
49
+ function same(a, b) {
50
+ if (Object.is(a, b)) return true;
51
+ if (typeof a === 'function' && typeof b === 'function') return true;
52
+ if (!isPlain(a) || !isPlain(b) || Array.isArray(a) !== Array.isArray(b)) return false;
53
+ const ka = Object.keys(a);
54
+ if (ka.length !== Object.keys(b).length) return false;
55
+ return ka.every((k) => Object.prototype.hasOwnProperty.call(b, k) && same(a[k], b[k]));
56
+ }
57
+
58
+ /** A copy of plain objects and arrays, so a value changed in place later still compares as changed. */
59
+ const snapshot = (v) => (Array.isArray(v) ? v.map(snapshot) : isPlain(v) ? Object.fromEntries(Object.entries(v).map(([k, x]) => [k, snapshot(x)])) : v);
60
+
61
+ /** The handler names given now: `on…` props of the component and `on…` functions in `options`. */
62
+ function handlerNames(props) {
63
+ const names = new Set();
64
+ for (const [key, value] of Object.entries(props)) if (isHandler(key) && !OWN.has(key) && typeof value === 'function') names.add(key);
65
+ for (const [key, value] of Object.entries(props.options ?? {})) if (isHandler(key) && typeof value === 'function') names.add(key);
66
+ return names;
67
+ }
68
+
69
+ /** What the grid was mounted with, to compare later props against: options without handlers, and handler names. */
70
+ function mountedWith(props) {
71
+ const options = {};
72
+ for (const [key, value] of Object.entries(props.options ?? {})) if (!isHandler(key)) options[key] = BY_IDENTITY.has(key) ? value : snapshot(value);
73
+ return { options, handlers: handlerNames(props) };
74
+ }
75
+
76
+ /** Whether the grid must be mounted again for these props; `chrome` alone changes in place. */
77
+ function needsRemount(was, props) {
78
+ const next = props.options ?? {};
79
+ for (const name of handlerNames(props)) if (!was.handlers.has(name)) return true;
80
+ for (const key of new Set([...Object.keys(was.options), ...Object.keys(next)])) {
81
+ if (isHandler(key) || key === 'chrome') continue;
82
+ const changed = BY_IDENTITY.has(key) ? !Object.is(was.options[key], next[key]) : !same(was.options[key], next[key]);
83
+ if (changed) return true;
84
+ }
85
+ return false;
86
+ }
87
+
88
+ const report = (props, err) => {
89
+ if (props.onError) props.onError(err);
90
+ else console.error(err);
91
+ };
92
+
93
+ /**
94
+ * An 8sheets Data Grid that fills its container. See README.md for props, events and the ref handle.
95
+ */
96
+ export const DataGrid = forwardRef(function DataGrid(props, ref) {
97
+ const elRef = useRef(null);
98
+ const gridRef = useRef(null);
99
+ const propsRef = useRef(props);
100
+ const mountedRef = useRef(null); // what the current grid was mounted with
101
+ const chainRef = useRef(Promise.resolve()); // mounts on this element run one after another
102
+ const [generation, setGeneration] = useState(0); // a new value mounts the grid again
103
+
104
+ // Handlers are read through this ref, so a new function each render needs no remount.
105
+ useClientLayoutEffect(() => {
106
+ propsRef.current = props;
107
+ });
108
+
109
+ useEffect(() => {
110
+ const el = elRef.current;
111
+ let cancelled = false;
112
+ let grid = null;
113
+ const run = chainRef.current.then(async () => {
114
+ if (cancelled) return;
115
+ const p = propsRef.current;
116
+ const was = mountedWith(p);
117
+ // Every handler goes to the grid as a function that calls the latest one, so the options pass through
118
+ // unchanged: whatever a later release of the grid accepts works here with no change to this file.
119
+ const options = { ...(p.options ?? {}) };
120
+ for (const name of was.handlers) {
121
+ options[name] = (...args) => {
122
+ const latest = propsRef.current;
123
+ const fn = typeof latest[name] === 'function' && !OWN.has(name) ? latest[name] : latest.options?.[name];
124
+ return typeof fn === 'function' ? fn(...args) : undefined;
125
+ };
126
+ }
127
+ // A failure inside the mounted grid reaches the same onError prop as a failed mount (and an onError option).
128
+ options.onError = (err) => {
129
+ const latest = propsRef.current;
130
+ if (typeof latest.options?.onError === 'function') latest.options.onError(err);
131
+ if (typeof latest.onError === 'function') latest.onError(err);
132
+ };
133
+ let mounted;
134
+ try {
135
+ mounted = await mountTable(el, options);
136
+ } catch (err) {
137
+ if (!cancelled) report(propsRef.current, err);
138
+ return;
139
+ }
140
+ if (cancelled) {
141
+ mounted.destroy();
142
+ return;
143
+ }
144
+ grid = mounted;
145
+ gridRef.current = grid;
146
+ mountedRef.current = was;
147
+ // Props that changed while the mount was pending.
148
+ if (needsRemount(was, propsRef.current)) setGeneration((g) => g + 1);
149
+ else syncChrome(grid, was, propsRef.current);
150
+ propsRef.current.onReady?.(grid);
151
+ });
152
+ chainRef.current = run;
153
+ return () => {
154
+ cancelled = true;
155
+ if (grid) {
156
+ gridRef.current = null;
157
+ mountedRef.current = null;
158
+ grid.destroy();
159
+ }
160
+ };
161
+ }, [generation]);
162
+
163
+ // After every render: follow a changed theme in place, and mount again for any other changed option.
164
+ useEffect(() => {
165
+ const grid = gridRef.current;
166
+ const was = mountedRef.current;
167
+ if (!grid || !was) return;
168
+ if (needsRemount(was, props)) setGeneration((g) => g + 1);
169
+ else syncChrome(grid, was, props);
170
+ });
171
+
172
+ useImperativeHandle(ref, () => {
173
+ const need = () => {
174
+ if (!gridRef.current) throw new Error('The grid is not mounted yet; wait for onReady');
175
+ return gridRef.current;
176
+ };
177
+ const handle = {
178
+ get grid() {
179
+ return gridRef.current;
180
+ },
181
+ };
182
+ for (const name of GRID_METHODS) handle[name] = (...args) => need()[name](...args);
183
+ return handle;
184
+ }, []);
185
+
186
+ return createElement('div', {
187
+ ref: elRef,
188
+ className: props.className,
189
+ style: { display: 'block', width: '100%', height: '100%', minHeight: 0, ...props.style },
190
+ });
191
+ });
192
+
193
+ /** Sends a changed `chrome` to `setChrome`, and remembers it. */
194
+ function syncChrome(grid, was, props) {
195
+ const next = props.options?.chrome;
196
+ if (same(was.options.chrome, next)) return;
197
+ grid.setChrome(next ?? 'auto');
198
+ if (next === undefined) delete was.options.chrome;
199
+ else was.options.chrome = snapshot(next);
200
+ }
201
+
202
+ DataGrid.displayName = 'DataGrid';
package/index.d.ts ADDED
@@ -0,0 +1,68 @@
1
+ // Types for <DataGrid>.
2
+ import type { CSSProperties, ForwardRefExoticComponent, RefAttributes } from 'react';
3
+ import type { MountedTable, TableChange, TableOptions } from '@8sheets/data-grid';
4
+
5
+ /**
6
+ * Options for `mountTable`, passed through as they are, so options a later release of the grid adds work too.
7
+ * After mount, a changed `chrome` goes to `setChrome`; any other changed option mounts the grid again. `data`
8
+ * is compared by identity (pass a new array to load new records), everything else by value.
9
+ */
10
+ export type DataGridOptions = TableOptions & Record<string, any>;
11
+
12
+ /** The grid's events, as props. Each goes to the grid as the option of that name; any other `on…` prop does too. */
13
+ export type DataGridEvents = Pick<
14
+ TableOptions,
15
+ | 'onStateChange'
16
+ | 'onSelectionChange'
17
+ | 'onRangeChange'
18
+ | 'onCellClick'
19
+ | 'onCellDoubleClick'
20
+ | 'onRowClick'
21
+ | 'onRowDoubleClick'
22
+ | 'onEditStart'
23
+ | 'onEditEnd'
24
+ | 'onBeforeEdit'
25
+ | 'onBeforeAdd'
26
+ | 'onBeforeRemove'
27
+ | 'onBeforePaste'
28
+ | 'onSourceLoad'
29
+ | 'onViewportChange'
30
+ | 'onLoadStart'
31
+ | 'onLoadProgress'
32
+ | 'onLoadEnd'
33
+ >;
34
+
35
+ /** The component's handler props. Any other `on…` prop goes to the grid as the option of that name. */
36
+ export interface DataGridEventProps extends DataGridEvents {
37
+ /** A data change: an edit, paste, added or removed records, undo or redo, by the user or the API (`source`). */
38
+ onChange?: (change: TableChange) => void;
39
+ [handler: `on${string}`]: ((...args: any[]) => any) | undefined;
40
+ }
41
+
42
+ export interface DataGridProps extends DataGridEventProps {
43
+ /** Given to `mountTable`. */
44
+ options?: DataGridOptions;
45
+ /** Called with the grid each time it has mounted. */
46
+ onReady?: (grid: MountedTable) => void;
47
+ /**
48
+ * A mount that failed, or an action inside the mounted grid that failed (the grid also shows its message).
49
+ * Without it a failed mount goes to console.error.
50
+ */
51
+ onError?: (error: unknown) => void;
52
+ /** Class of the element the grid fills. */
53
+ className?: string;
54
+ /** Style of that element. It is 100% wide and high by default, so its container needs a height. */
55
+ style?: CSSProperties;
56
+ }
57
+
58
+ /**
59
+ * What a ref on <DataGrid> gives: the grid, and each of its methods (`ref.current.setSort(…)` is
60
+ * `grid.setSort(…)`), which throw before onReady. `destroy`, `on` and `off` are left out: the component owns
61
+ * the grid, and its event props survive a remount.
62
+ */
63
+ export type DataGridRef = Omit<MountedTable, 'destroy' | 'on' | 'off'> & {
64
+ /** The mounted grid, or null before onReady and after unmount. */
65
+ readonly grid: MountedTable | null;
66
+ };
67
+
68
+ export const DataGrid: ForwardRefExoticComponent<DataGridProps & RefAttributes<DataGridRef>>;
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@8sheets/data-grid-react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "license": "SEE LICENSE IN LICENSE.md",
5
+ "homepage": "https://8sheets.com",
6
+ "author": "8cells",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "keywords": [
11
+ "data-grid",
12
+ "datagrid",
13
+ "grid",
14
+ "table",
15
+ "data-table",
16
+ "csv",
17
+ "xlsx",
18
+ "excel",
19
+ "pivot-table",
20
+ "filter",
21
+ "group-by",
22
+ "virtual-scroll",
23
+ "react",
24
+ "react-component"
25
+ ],
26
+ "type": "module",
27
+ "sideEffects": false,
28
+ "description": "React component for 8sheets Data Grid: <DataGrid> with options passed through, typed props, change event and ref.",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./index.d.ts",
32
+ "default": "./data-grid.js"
33
+ },
34
+ "./package.json": "./package.json"
35
+ },
36
+ "main": "./data-grid.js",
37
+ "types": "./index.d.ts",
38
+ "files": [
39
+ "data-grid.js",
40
+ "index.d.ts"
41
+ ],
42
+ "peerDependencies": {
43
+ "react": ">=18",
44
+ "@8sheets/data-grid": "1.0.0"
45
+ }
46
+ }