@ferde/data-grid 0.0.1 → 0.0.2

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/dist/index.d.ts CHANGED
@@ -1,17 +1,26 @@
1
1
  import { ColDefField } from 'ag-grid-community';
2
2
  import { JSX } from 'react';
3
+ import { RefObject } from 'react';
3
4
 
4
- declare const DataGrid: <T>({ rows, columns }: DataGridProps<T>) => JSX.Element;
5
+ declare const DataGrid: <T>({ ref, rows, columns, rowIdField }: DataGridProps<T>) => JSX.Element;
5
6
  export default DataGrid;
6
7
 
8
+ declare interface DataGridApi<T> {
9
+ addRow: (row: Partial<T>) => void;
10
+ updateRow: (rowId: string, row: Partial<T>) => void;
11
+ deleteRow: (rowId: string) => void;
12
+ }
13
+
7
14
  export declare interface DataGridColumn<T> {
8
15
  field: ColDefField<T>;
9
16
  headerName: string;
10
17
  }
11
18
 
12
19
  export declare interface DataGridProps<T> {
20
+ ref?: RefObject<DataGridApi<T>>;
13
21
  rows: T[];
14
22
  columns: DataGridColumn<T>[];
23
+ rowIdField: keyof T;
15
24
  }
16
25
 
17
26
  export { }
package/dist/index.js CHANGED
@@ -1,17 +1,69 @@
1
1
  import { AllCommunityModule as e } from "ag-grid-community";
2
2
  import { AgGridProvider as t, AgGridReact as n } from "ag-grid-react";
3
- import { useMemo as r } from "react";
4
- import { jsx as i } from "react/jsx-runtime";
3
+ import { useImperativeHandle as r, useMemo as i, useState as a } from "react";
4
+ import { jsx as o } from "react/jsx-runtime";
5
+ //#region node_modules/uuid/dist/stringify.js
6
+ var s = [];
7
+ for (let e = 0; e < 256; ++e) s.push((e + 256).toString(16).slice(1));
8
+ function c(e, t = 0) {
9
+ return (s[e[t + 0]] + s[e[t + 1]] + s[e[t + 2]] + s[e[t + 3]] + "-" + s[e[t + 4]] + s[e[t + 5]] + "-" + s[e[t + 6]] + s[e[t + 7]] + "-" + s[e[t + 8]] + s[e[t + 9]] + "-" + s[e[t + 10]] + s[e[t + 11]] + s[e[t + 12]] + s[e[t + 13]] + s[e[t + 14]] + s[e[t + 15]]).toLowerCase();
10
+ }
11
+ //#endregion
12
+ //#region node_modules/uuid/dist/rng.js
13
+ var l = new Uint8Array(16);
14
+ function u() {
15
+ return crypto.getRandomValues(l);
16
+ }
17
+ //#endregion
18
+ //#region node_modules/uuid/dist/v4.js
19
+ function d(e, t, n) {
20
+ return !t && !e && crypto.randomUUID ? crypto.randomUUID() : f(e, t, n);
21
+ }
22
+ function f(e, t, n) {
23
+ e ||= {};
24
+ let r = e.random ?? e.rng?.() ?? u();
25
+ if (r.length < 16) throw Error("Random bytes length must be >= 16");
26
+ if (r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, t) {
27
+ if (n ||= 0, n < 0 || n + 16 > t.length) throw RangeError(`UUID byte range ${n}:${n + 15} is out of buffer bounds`);
28
+ for (let e = 0; e < 16; ++e) t[n + e] = r[e];
29
+ return t;
30
+ }
31
+ return c(r);
32
+ }
33
+ //#endregion
5
34
  //#region src/lib/utils.ts
6
- var a = (e) => e.map((e) => ({
35
+ var p = (e) => e.map((e) => ({
7
36
  field: e.field,
8
37
  headerName: e.headerName
9
- })), o = [e], s = ({ rows: e, columns: s }) => /* @__PURE__ */ i(t, {
10
- modules: o,
11
- children: /* @__PURE__ */ i(n, {
12
- rowData: r(() => [...e], [e]),
13
- columnDefs: r(() => a(s), [s])
14
- })
15
- });
38
+ })), m = [e], h = ({ ref: e, rows: s, columns: c, rowIdField: l }) => {
39
+ let [u, f] = a(), h = i(() => [...s], [s]), g = i(() => p(c), [c]);
40
+ return r(e, () => ({
41
+ addRow: (e) => {
42
+ let t = {
43
+ ...e,
44
+ [l]: `--new-row-${d()}`
45
+ };
46
+ u?.applyTransaction({ add: [t] });
47
+ },
48
+ updateRow: (e, t) => {
49
+ let n = u?.getRowNode(e)?.data;
50
+ n && (Object.assign(n, t), u?.applyTransaction({ update: [n] }));
51
+ },
52
+ deleteRow: (e) => {
53
+ let t = u?.getRowNode(e)?.data;
54
+ t && u?.applyTransaction({ remove: [t] });
55
+ }
56
+ }), [u, l]), /* @__PURE__ */ o(t, {
57
+ modules: m,
58
+ children: /* @__PURE__ */ o(n, {
59
+ rowData: h,
60
+ columnDefs: g,
61
+ getRowId: ({ data: e }) => String(e[l]),
62
+ onGridReady: ({ api: e }) => {
63
+ f(e);
64
+ }
65
+ })
66
+ });
67
+ };
16
68
  //#endregion
17
- export { s as default };
69
+ export { h as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ferde/data-grid",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -26,10 +26,11 @@
26
26
  "lint": "eslint .",
27
27
  "prettier": "prettier --write .",
28
28
  "preview": "vite preview",
29
- "prepublishOnly": "npm run build"
29
+ "prepublishOnly": "yarn build"
30
30
  },
31
31
  "dependencies": {
32
- "ag-grid-react": "^35.3.1"
32
+ "ag-grid-react": "^35.3.1",
33
+ "uuid": "^14.0.0"
33
34
  },
34
35
  "peerDependencies": {
35
36
  "react": "^18.0.0 || ^19.0.0",