@8sheets/data-grid-vue 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 +36 -0
- package/README.md +43 -2
- package/data-grid.d.ts +51 -0
- package/data-grid.js +249 -0
- package/index.d.ts +2 -0
- package/index.js +1 -0
- package/package.json +46 -4
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,44 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 8sheets Data Grid for Vue
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`<DataGrid>` puts an [8sheets Data Grid](https://8sheets.com/data-grid/) in a Vue 3 app (Vue 3.4 or later), with server rendering. This is version 1.0.0.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm i @8sheets/data-grid-vue @8sheets/data-grid
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Use
|
|
12
|
+
|
|
13
|
+
```vue
|
|
14
|
+
<script setup>
|
|
15
|
+
import { computed, shallowRef } from 'vue';
|
|
16
|
+
import { DataGrid, useDataGrid } from '@8sheets/data-grid-vue';
|
|
17
|
+
|
|
18
|
+
const records = shallowRef([{ Region: 'East', Units: 2, Price: 24 }]);
|
|
19
|
+
const options = computed(() => ({ title: 'Orders', data: records.value }));
|
|
20
|
+
const { dataGrid, grid } = useDataGrid();
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<template>
|
|
24
|
+
<div style="height: 480px">
|
|
25
|
+
<DataGrid ref="dataGrid" :options="options" @change="(c) => console.log(c.action)" />
|
|
26
|
+
</div>
|
|
27
|
+
</template>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
- **`options`** goes to `mountTable` as it is. A changed `chrome` goes to `setChrome`; any other change mounts the grid again. `data` is compared by identity; keep records in a `shallowRef`.
|
|
31
|
+
- **Events:** `@change` for each data change, the grid's other events by their names (`@state-change`, `@before-edit`…), `@ready` with the grid, `@error` for a failed mount or action. Any other listener `@name` goes to the grid as its `onName` option.
|
|
32
|
+
- **The template ref** exposes `grid`, `whenReady()` and every method of the grid except `destroy`, `on` and `off`.
|
|
33
|
+
|
|
34
|
+
## Vite
|
|
35
|
+
|
|
36
|
+
Set `worker: { format: 'es' }`, and before Vite 8 also `optimizeDeps: { exclude: ['@8sheets/data-grid', '@8sheets/data-grid-vue'] }`.
|
|
37
|
+
|
|
38
|
+
## Documentation
|
|
39
|
+
|
|
40
|
+
[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.
|
|
41
|
+
|
|
42
|
+
## Licence
|
|
43
|
+
|
|
44
|
+
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.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Types for data-grid.js.
|
|
2
|
+
import type { ComponentOptionsMixin, ComputedRef, DefineComponent, PropType, ShallowRef } from 'vue';
|
|
3
|
+
import type { MountedTable, TableChange, TableEventMap, 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
|
+
/**
|
|
13
|
+
* The events: `ready`, `error` (a failed mount, or an action inside the grid that failed) and each event of the
|
|
14
|
+
* grid by its name (`@state-change`, `@before-edit`…). A listener cancels a cancellable one with
|
|
15
|
+
* `e.preventDefault()`; returning false doesn't reach the grid through Vue's emit.
|
|
16
|
+
*/
|
|
17
|
+
type DataGridEmits = {
|
|
18
|
+
ready: (grid: MountedTable) => true;
|
|
19
|
+
error: (error: unknown) => true;
|
|
20
|
+
change: (change: TableChange) => true;
|
|
21
|
+
} & { [K in Exclude<keyof TableEventMap, 'error' | 'change'>]: (event: TableEventMap[K]) => true };
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* What a template ref on `<DataGrid>` exposes: the grid, and each of its methods (`dataGrid.value.setSort(…)`
|
|
25
|
+
* is `grid.setSort(…)`). Methods that return a promise wait for the grid; the others throw before mount.
|
|
26
|
+
* `destroy`, `on` and `off` are left out: the component owns the grid, and its listeners survive a remount.
|
|
27
|
+
*/
|
|
28
|
+
export type DataGridExposed = Omit<MountedTable, 'destroy' | 'on' | 'off'> & {
|
|
29
|
+
/** The grid, or null until it is mounted and after unmount. */
|
|
30
|
+
readonly grid: MountedTable | null;
|
|
31
|
+
/** Resolves with the grid once mounted; rejects when the component is unmounted first or mounting fails. */
|
|
32
|
+
whenReady(): Promise<MountedTable>;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export declare const DataGrid: DefineComponent<
|
|
36
|
+
{ options: { type: PropType<DataGridOptions>; default: () => DataGridOptions } },
|
|
37
|
+
DataGridExposed,
|
|
38
|
+
{},
|
|
39
|
+
{},
|
|
40
|
+
{},
|
|
41
|
+
ComponentOptionsMixin,
|
|
42
|
+
ComponentOptionsMixin,
|
|
43
|
+
DataGridEmits
|
|
44
|
+
>;
|
|
45
|
+
export default DataGrid;
|
|
46
|
+
|
|
47
|
+
/** A template ref for `<DataGrid>` and its grid: `const { dataGrid, grid } = useDataGrid()` with `<DataGrid ref="dataGrid" />`. */
|
|
48
|
+
export declare function useDataGrid(): {
|
|
49
|
+
dataGrid: ShallowRef<DataGridExposed | null>;
|
|
50
|
+
grid: ComputedRef<MountedTable | null>;
|
|
51
|
+
};
|
package/data-grid.js
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
// Vue 3 component for 8sheets Data Grid. A plain ES module with a render function, so it needs no Vue compiler.
|
|
2
|
+
//
|
|
3
|
+
// <DataGrid :options="{ data: records }" style="height: 400px" @change="onChange" @ready="onReady" />
|
|
4
|
+
//
|
|
5
|
+
import { mountTable } from '@8sheets/data-grid';
|
|
6
|
+
import { computed, defineComponent, ErrorCodes, getCurrentInstance, h, handleError, onBeforeUnmount, onMounted, onUpdated, shallowRef, toRaw, watch } from 'vue';
|
|
7
|
+
|
|
8
|
+
/** Compared by identity, not by value: records can be large. Pass a new array to load new records. */
|
|
9
|
+
const BY_IDENTITY = new Set(['data']);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The grid's methods the component exposes, each calling the mounted grid. The same list is in the React and
|
|
13
|
+
* Angular wrappers. `destroy`, `on` and `off` are left out: the component owns the grid's life, and listeners
|
|
14
|
+
* carry its events across a remount.
|
|
15
|
+
*/
|
|
16
|
+
const GRID_METHODS = [
|
|
17
|
+
'openFile', 'setData', 'setDataSource', 'getSources', 'setSource', 'getSource', 'refresh',
|
|
18
|
+
'getState', 'setState', 'updateState', 'resetState', 'setSearch',
|
|
19
|
+
'setFilters', 'addFilter', 'clearFilters', 'setQuickFilter', 'getDistinctValues',
|
|
20
|
+
'setSort', 'sortBy', 'clearSort', 'setGroups', 'groupBy', 'clearGroups',
|
|
21
|
+
'expandGroup', 'collapseGroup', 'expandAll', 'collapseAll', 'setSummary', 'setTotalsRow', 'setFilterRow',
|
|
22
|
+
'getFields', 'getColumn', 'setColumns', 'setColumn', 'moveColumn', 'autosizeColumn', 'addCalculatedField',
|
|
23
|
+
'getSavedViews', 'saveView', 'restoreView', 'deleteView',
|
|
24
|
+
'openPivot', 'closePivot', 'getChartData',
|
|
25
|
+
'getPage', 'setPage', 'setScrolling', 'getViewport', 'scrollToRow', 'scrollToRecord', 'scrollToColumn', 'focusCell', 'getFocusedCell',
|
|
26
|
+
'getRange', 'setRange', 'copyRange',
|
|
27
|
+
'getSelection', 'setSelection', 'selectRecords', 'selectAll', 'clearSelection', 'getSelectedIds',
|
|
28
|
+
'openRecordDetails', 'openDialog', 'closeDialog', 'expandRecord', 'collapseRecord', 'getExpandedRecord',
|
|
29
|
+
'isEditable', 'enableEditing', 'setCellValue', 'updateRecords', 'addRecords', 'removeRecords', 'paste', 'fillDown',
|
|
30
|
+
'undo', 'redo', 'canUndo', 'canRedo', 'startEdit', 'stopEdit', 'getEditingCell',
|
|
31
|
+
'exportResults', 'download', 'createShareLink', 'revokeShareLink',
|
|
32
|
+
'isLoading', 'cancelLoad',
|
|
33
|
+
'setChrome', 'getChrome', 'setLanguage', 'getLanguage', 'setOptions',
|
|
34
|
+
'getRecords', 'getRecord', 'getCell', 'getCounts', 'getTotals',
|
|
35
|
+
];
|
|
36
|
+
/** Methods that answer at once. Before mount they throw; the others wait for the grid. */
|
|
37
|
+
const SYNC_METHODS = new Set([
|
|
38
|
+
'getSources', 'getSource', 'getState', 'getFields', 'getColumn', 'getSavedViews', 'saveView', 'deleteView',
|
|
39
|
+
'getPage', 'getViewport', 'getFocusedCell', 'getRange', 'getSelection', 'closeDialog', 'collapseRecord',
|
|
40
|
+
'getExpandedRecord', 'isEditable', 'canUndo', 'canRedo', 'getEditingCell', 'setChrome', 'getChrome',
|
|
41
|
+
'setLanguage', 'getLanguage', 'getCounts', 'getTotals', 'isLoading', 'cancelLoad',
|
|
42
|
+
]);
|
|
43
|
+
/** The component's own events, which never go to the grid. */
|
|
44
|
+
const OWN = new Set(['onReady', 'onReadyOnce', 'onError', 'onErrorOnce']);
|
|
45
|
+
/** A listener key Vue gives for `@change` (`onChange`), `@change.once` (`onChangeOnce`) and so on. */
|
|
46
|
+
const isListener = (key) => /^on[A-Z]/.test(key);
|
|
47
|
+
/** The grid option a listener key stands for: `onChange` and `onChangeOnce` are both the `onChange` option. */
|
|
48
|
+
const optionOf = (key) => key.replace(/Once$/, '');
|
|
49
|
+
|
|
50
|
+
const isPlain = (v) => v !== null && typeof v === 'object' && (Object.getPrototypeOf(v) === Object.prototype || Object.getPrototypeOf(v) === null);
|
|
51
|
+
|
|
52
|
+
/** A copy without Vue proxies: plain objects and arrays are copied, anything else (files, typed arrays) is kept as is. */
|
|
53
|
+
function plain(value) {
|
|
54
|
+
if (Array.isArray(value)) return Array.from(value, plain);
|
|
55
|
+
if (!isPlain(value)) return toRaw(value);
|
|
56
|
+
const out = {};
|
|
57
|
+
for (const key of Object.keys(value)) out[key] = plain(value[key]);
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Equal by value through plain objects and arrays; two functions count as equal (a grid keeps those it mounted with). */
|
|
62
|
+
function same(a, b) {
|
|
63
|
+
if (Object.is(a, b)) return true;
|
|
64
|
+
if (typeof a === 'function' && typeof b === 'function') return true;
|
|
65
|
+
if (Array.isArray(a) && Array.isArray(b)) return a.length === b.length && a.every((x, i) => same(x, b[i]));
|
|
66
|
+
if (!isPlain(a) || !isPlain(b)) return false;
|
|
67
|
+
const keys = Object.keys(a);
|
|
68
|
+
return keys.length === Object.keys(b).length && keys.every((k) => Object.prototype.hasOwnProperty.call(b, k) && same(a[k], b[k]));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The options to compare, without handlers: `data` as it is (by identity), the rest as plain copies. */
|
|
72
|
+
function comparable(options) {
|
|
73
|
+
const out = {};
|
|
74
|
+
for (const key of Object.keys(options ?? {})) {
|
|
75
|
+
if (isListener(key)) continue;
|
|
76
|
+
out[key] = BY_IDENTITY.has(key) ? toRaw(options[key]) : plain(options[key]);
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const DataGrid = defineComponent({
|
|
82
|
+
name: 'DataGrid',
|
|
83
|
+
props: {
|
|
84
|
+
/** Options for `mountTable`, passed through. A changed `chrome` goes to `setChrome`; any other change mounts again. */
|
|
85
|
+
options: { type: Object, default: () => ({}) },
|
|
86
|
+
},
|
|
87
|
+
// Events are left out of `emits` on purpose, as in ../sheet.js: undeclared, a listener arrives with the
|
|
88
|
+
// attributes, so `@change` and any listener for a callback a later grid adds reach the grid as options.
|
|
89
|
+
inheritAttrs: false,
|
|
90
|
+
setup(props, { emit, expose, attrs }) {
|
|
91
|
+
const instance = getCurrentInstance();
|
|
92
|
+
const el = shallowRef(null);
|
|
93
|
+
/** The grid once mounted. A shallow ref, so Vue never wraps the grid in a proxy. */
|
|
94
|
+
const grid = shallowRef(null);
|
|
95
|
+
let unmounted = false;
|
|
96
|
+
let generation = 0;
|
|
97
|
+
/** What the current grid was mounted with. */
|
|
98
|
+
let was = null;
|
|
99
|
+
|
|
100
|
+
let ready = null;
|
|
101
|
+
let settle = null;
|
|
102
|
+
const newReady = () => {
|
|
103
|
+
ready = new Promise((resolve, reject) => (settle = { resolve, reject }));
|
|
104
|
+
ready.catch(() => {});
|
|
105
|
+
};
|
|
106
|
+
newReady();
|
|
107
|
+
|
|
108
|
+
/** The grid callbacks the parent gives: listeners (`@change`) and `on…` functions in `options`. */
|
|
109
|
+
function handlerNames() {
|
|
110
|
+
const names = new Set();
|
|
111
|
+
for (const [key, value] of Object.entries(attrs)) if (isListener(key) && !OWN.has(key) && value != null) names.add(optionOf(key));
|
|
112
|
+
for (const [key, value] of Object.entries(props.options ?? {})) if (isListener(key) && typeof value === 'function') names.add(key);
|
|
113
|
+
return names;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Calls the latest listener for a grid callback, else the latest function of that name in `options`. */
|
|
117
|
+
function forward(name, args) {
|
|
118
|
+
const listeners = [attrs[name], attrs[`${name}Once`]].flat().filter((f) => typeof f === 'function');
|
|
119
|
+
if (listeners.length) {
|
|
120
|
+
// Through emit, so `.once` and Vue's error handling apply: `onChange` is the `change` event.
|
|
121
|
+
const event = name.slice(2).replace(/^[A-Z]/, (c) => c.toLowerCase());
|
|
122
|
+
emit(event, ...args);
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
const fn = props.options?.[name];
|
|
126
|
+
return typeof fn === 'function' ? fn(...args) : undefined;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function report(error) {
|
|
130
|
+
if (attrs.onError || attrs.onErrorOnce) emit('error', error);
|
|
131
|
+
else handleError(error, instance, ErrorCodes.COMPONENT_EVENT_HANDLER, false);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async function mount() {
|
|
135
|
+
const mine = ++generation;
|
|
136
|
+
const options = { ...(props.options ?? {}) };
|
|
137
|
+
// `data` can be large and is never copied; the rest goes without Vue's proxies.
|
|
138
|
+
for (const key of Object.keys(options)) options[key] = BY_IDENTITY.has(key) ? toRaw(options[key]) : isListener(key) ? options[key] : plain(options[key]);
|
|
139
|
+
const handlers = handlerNames();
|
|
140
|
+
for (const name of handlers) options[name] = (...args) => forward(name, args);
|
|
141
|
+
// A failure inside the mounted grid reaches the same `error` event as a failed mount (and an onError option).
|
|
142
|
+
const own = typeof options.onError === 'function' ? options.onError : null;
|
|
143
|
+
options.onError = (error) => {
|
|
144
|
+
if (!unmounted && mine === generation) {
|
|
145
|
+
if (typeof props.options?.onError === 'function') props.options.onError(error);
|
|
146
|
+
else own?.(error);
|
|
147
|
+
if (attrs.onError || attrs.onErrorOnce) emit('error', error);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
const mountedWith = { options: comparable(props.options), handlers };
|
|
151
|
+
let mounted;
|
|
152
|
+
try {
|
|
153
|
+
mounted = await mountTable(el.value, options);
|
|
154
|
+
} catch (error) {
|
|
155
|
+
if (mine === generation) settle.reject(error);
|
|
156
|
+
if (!unmounted && mine === generation) report(error);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
// Unmounted, or mounted again, while this mount was in progress: this grid arrived for nobody.
|
|
160
|
+
if (unmounted || mine !== generation) {
|
|
161
|
+
mounted.destroy();
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
grid.value = mounted;
|
|
165
|
+
was = mountedWith;
|
|
166
|
+
settle.resolve(mounted);
|
|
167
|
+
emit('ready', mounted);
|
|
168
|
+
follow(); // options that changed while the mount was in progress
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function needsRemount() {
|
|
172
|
+
const next = comparable(props.options);
|
|
173
|
+
for (const name of handlerNames()) if (!was.handlers.has(name)) return true;
|
|
174
|
+
for (const key of new Set([...Object.keys(was.options), ...Object.keys(next)])) {
|
|
175
|
+
if (key === 'chrome') continue;
|
|
176
|
+
if (BY_IDENTITY.has(key) ? !Object.is(was.options[key], next[key]) : !same(was.options[key], next[key])) return true;
|
|
177
|
+
}
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** A changed `chrome` goes to `setChrome`; any other changed option mounts the grid again. */
|
|
182
|
+
function follow() {
|
|
183
|
+
if (!grid.value || !was) return;
|
|
184
|
+
if (needsRemount()) {
|
|
185
|
+
grid.value.destroy();
|
|
186
|
+
grid.value = null;
|
|
187
|
+
was = null;
|
|
188
|
+
newReady();
|
|
189
|
+
mount();
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const chrome = plain(props.options?.chrome);
|
|
193
|
+
if (!same(was.options.chrome, chrome)) {
|
|
194
|
+
grid.value.setChrome(chrome ?? 'auto');
|
|
195
|
+
was.options.chrome = chrome;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
onMounted(mount);
|
|
200
|
+
// Reading the comparable options tracks every value in them, but `data` only by identity.
|
|
201
|
+
watch(() => comparable(props.options), follow);
|
|
202
|
+
// A listener added after mount is a new callback for the grid. Attributes aren't reactive, but a change to
|
|
203
|
+
// them updates the component (see `emits` above).
|
|
204
|
+
onUpdated(follow);
|
|
205
|
+
|
|
206
|
+
onBeforeUnmount(() => {
|
|
207
|
+
unmounted = true;
|
|
208
|
+
if (!grid.value) settle.reject(new Error('The grid was unmounted before it was ready'));
|
|
209
|
+
grid.value?.destroy();
|
|
210
|
+
grid.value = null;
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
const exposed = {
|
|
214
|
+
grid,
|
|
215
|
+
/** Resolves with the grid once it is mounted. */
|
|
216
|
+
whenReady: () => ready,
|
|
217
|
+
};
|
|
218
|
+
for (const name of GRID_METHODS)
|
|
219
|
+
exposed[name] = SYNC_METHODS.has(name)
|
|
220
|
+
? (...args) => {
|
|
221
|
+
if (!grid.value) throw new Error('The grid is not mounted yet; wait for the ready event');
|
|
222
|
+
return grid.value[name](...args);
|
|
223
|
+
}
|
|
224
|
+
: async (...args) => (await ready)[name](...args);
|
|
225
|
+
expose(exposed);
|
|
226
|
+
|
|
227
|
+
// A block that fills its container, with the attributes the parent gives (class, style, id). The grid
|
|
228
|
+
// replaces this element's children, so Vue gives it none.
|
|
229
|
+
return () => {
|
|
230
|
+
const rest = {};
|
|
231
|
+
for (const [key, value] of Object.entries(attrs)) if (key !== 'class' && key !== 'style' && !isListener(key)) rest[key] = value;
|
|
232
|
+
return h('div', { ...rest, ref: el, class: ['s8c-vue-data-grid', attrs.class], style: [{ display: 'block', width: '100%', height: '100%' }, attrs.style] });
|
|
233
|
+
};
|
|
234
|
+
},
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* A template ref for `<DataGrid>` and the grid behind it.
|
|
239
|
+
*
|
|
240
|
+
* const { dataGrid, grid } = useDataGrid();
|
|
241
|
+
* // <DataGrid ref="dataGrid" /> (the variable name and the ref name match)
|
|
242
|
+
*/
|
|
243
|
+
export function useDataGrid() {
|
|
244
|
+
const dataGrid = shallowRef(null);
|
|
245
|
+
const grid = computed(() => dataGrid.value?.grid ?? null);
|
|
246
|
+
return { dataGrid, grid };
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export default DataGrid;
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DataGrid, useDataGrid, default } from './data-grid.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@8sheets/data-grid-vue",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
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
|
+
"vue",
|
|
24
|
+
"vue-component"
|
|
25
|
+
],
|
|
26
|
+
"type": "module",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"description": "Vue 3 component for 8sheets Data Grid: <DataGrid> with options passed through, typed events and template ref.",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./index.d.ts",
|
|
32
|
+
"default": "./index.js"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"main": "./index.js",
|
|
37
|
+
"types": "./index.d.ts",
|
|
38
|
+
"files": [
|
|
39
|
+
"index.js",
|
|
40
|
+
"index.d.ts",
|
|
41
|
+
"data-grid.js",
|
|
42
|
+
"data-grid.d.ts"
|
|
43
|
+
],
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"vue": "^3.4.0",
|
|
46
|
+
"@8sheets/data-grid": "1.0.0"
|
|
47
|
+
}
|
|
48
|
+
}
|