@object-ui/plugin-aggrid 0.4.1 → 0.5.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/.turbo/turbo-build.log +21 -0
- package/OBJECT_AGGRID_CN.md +483 -0
- package/QUICKSTART.md +186 -0
- package/README.md +221 -1
- package/dist/{AgGridImpl-DKkq6v1B.js → AgGridImpl-BQ6tBvrq.js} +61 -57
- package/dist/ObjectAgGridImpl-CGFeGvOH.js +372 -0
- package/dist/{index-B6NPAFZx.js → index-CLKYMco3.js} +273 -139
- package/dist/index.css +1 -1
- package/dist/index.js +4 -3
- package/dist/index.umd.cjs +5 -2
- package/dist/src/ObjectAgGridImpl.d.ts +6 -0
- package/dist/src/VirtualScrolling.d.ts +72 -0
- package/dist/src/index.d.ts +42 -0
- package/dist/src/object-aggrid.types.d.ts +74 -0
- package/package.json +10 -9
- package/src/AgGridImpl.tsx +5 -1
- package/src/ObjectAgGridImpl.tsx +603 -0
- package/src/VirtualScrolling.ts +74 -0
- package/src/index.test.ts +1 -1
- package/src/index.tsx +182 -0
- package/src/object-aggrid.test.ts +99 -0
- package/src/object-aggrid.types.ts +123 -0
- package/vite.config.ts +13 -0
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { j as d } from "./index-CLKYMco3.js";
|
|
2
|
+
import { useRef as ne, useState as y, useEffect as B, useMemo as P, useCallback as g } from "react";
|
|
3
|
+
import { AgGridReact as ae } from "ag-grid-react";
|
|
4
|
+
const le = {
|
|
5
|
+
text: "agTextColumnFilter",
|
|
6
|
+
textarea: "agTextColumnFilter",
|
|
7
|
+
number: "agNumberColumnFilter",
|
|
8
|
+
currency: "agNumberColumnFilter",
|
|
9
|
+
percent: "agNumberColumnFilter",
|
|
10
|
+
boolean: "agSetColumnFilter",
|
|
11
|
+
date: "agDateColumnFilter",
|
|
12
|
+
datetime: "agDateColumnFilter",
|
|
13
|
+
time: "agTextColumnFilter",
|
|
14
|
+
email: "agTextColumnFilter",
|
|
15
|
+
phone: "agTextColumnFilter",
|
|
16
|
+
url: "agTextColumnFilter",
|
|
17
|
+
select: "agSetColumnFilter"
|
|
18
|
+
};
|
|
19
|
+
function fe({
|
|
20
|
+
objectName: a,
|
|
21
|
+
dataSource: l,
|
|
22
|
+
fields: e,
|
|
23
|
+
fieldNames: t,
|
|
24
|
+
filters: i,
|
|
25
|
+
sort: h,
|
|
26
|
+
pageSize: F = 10,
|
|
27
|
+
pagination: A = !0,
|
|
28
|
+
domLayout: k = "normal",
|
|
29
|
+
animateRows: N = !0,
|
|
30
|
+
rowSelection: D,
|
|
31
|
+
theme: J = "quartz",
|
|
32
|
+
height: w = 500,
|
|
33
|
+
className: K = "",
|
|
34
|
+
editable: E = !1,
|
|
35
|
+
editType: V,
|
|
36
|
+
singleClickEdit: I = !1,
|
|
37
|
+
stopEditingWhenCellsLoseFocus: L = !0,
|
|
38
|
+
exportConfig: m,
|
|
39
|
+
statusBar: S,
|
|
40
|
+
callbacks: o,
|
|
41
|
+
columnConfig: v,
|
|
42
|
+
enableRangeSelection: O = !1,
|
|
43
|
+
enableCharts: U = !1,
|
|
44
|
+
contextMenu: f
|
|
45
|
+
}) {
|
|
46
|
+
const c = ne(null), [Q, x] = y(!0), [_, C] = y(null), [b, W] = y(null), [T, X] = y([]), [ue, Z] = y(0);
|
|
47
|
+
B(() => {
|
|
48
|
+
if (!l) {
|
|
49
|
+
C(new Error("DataSource is required")), x(!1);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
(async () => {
|
|
53
|
+
try {
|
|
54
|
+
x(!0), C(null);
|
|
55
|
+
const r = await l.getObjectSchema(a);
|
|
56
|
+
W(r);
|
|
57
|
+
} catch (r) {
|
|
58
|
+
const s = r instanceof Error ? r : new Error(String(r));
|
|
59
|
+
C(s), o?.onDataError?.(s);
|
|
60
|
+
} finally {
|
|
61
|
+
x(!1);
|
|
62
|
+
}
|
|
63
|
+
})();
|
|
64
|
+
}, [a, l, o]), B(() => {
|
|
65
|
+
if (!l || !b) return;
|
|
66
|
+
(async () => {
|
|
67
|
+
try {
|
|
68
|
+
x(!0), C(null);
|
|
69
|
+
const r = {
|
|
70
|
+
$top: F,
|
|
71
|
+
$skip: 0
|
|
72
|
+
};
|
|
73
|
+
i && (r.$filter = i), h && (r.$orderby = h);
|
|
74
|
+
const s = await l.find(a, r);
|
|
75
|
+
X(s.data || []), Z(s.total || 0), o?.onDataLoaded?.(s.data || []);
|
|
76
|
+
} catch (r) {
|
|
77
|
+
const s = r instanceof Error ? r : new Error(String(r));
|
|
78
|
+
C(s), o?.onDataError?.(s);
|
|
79
|
+
} finally {
|
|
80
|
+
x(!1);
|
|
81
|
+
}
|
|
82
|
+
})();
|
|
83
|
+
}, [a, l, b, i, h, F, o]);
|
|
84
|
+
const ee = P(() => {
|
|
85
|
+
if (!b?.fields) return [];
|
|
86
|
+
const n = e || Object.values(b.fields);
|
|
87
|
+
return (t ? n.filter((s) => t.includes(s.name)) : n).map((s) => {
|
|
88
|
+
const u = {
|
|
89
|
+
field: s.name,
|
|
90
|
+
headerName: s.label || s.name,
|
|
91
|
+
sortable: s.sortable !== !1,
|
|
92
|
+
filter: se(s),
|
|
93
|
+
editable: E && !s.readonly
|
|
94
|
+
// visible_on will be evaluated by the core renderer
|
|
95
|
+
// For now, we just show all fields. Conditional visibility
|
|
96
|
+
// should be handled at a higher level or via dynamic column updates
|
|
97
|
+
};
|
|
98
|
+
return v && (v.resizable !== void 0 && (u.resizable = v.resizable), v.sortable !== void 0 && u.sortable === void 0 && (u.sortable = v.sortable)), oe(u, s), u;
|
|
99
|
+
});
|
|
100
|
+
}, [b, e, t, E, v]), R = P(() => {
|
|
101
|
+
if (!S?.enabled) return;
|
|
102
|
+
const n = S.aggregations || ["count", "sum", "avg"], r = [];
|
|
103
|
+
return n.includes("count") && r.push({ statusPanel: "agAggregationComponent", statusPanelParams: { aggFuncs: ["count"] } }), n.includes("sum") && r.push({ statusPanel: "agAggregationComponent", statusPanelParams: { aggFuncs: ["sum"] } }), n.includes("avg") && r.push({ statusPanel: "agAggregationComponent", statusPanelParams: { aggFuncs: ["avg"] } }), n.includes("min") && r.push({ statusPanel: "agAggregationComponent", statusPanelParams: { aggFuncs: ["min"] } }), n.includes("max") && r.push({ statusPanel: "agAggregationComponent", statusPanelParams: { aggFuncs: ["max"] } }), r;
|
|
104
|
+
}, [S]), $ = g(() => {
|
|
105
|
+
if (!c.current?.api) return;
|
|
106
|
+
const n = {
|
|
107
|
+
fileName: m?.fileName || `${a}-export.csv`,
|
|
108
|
+
skipColumnHeaders: m?.skipColumnHeaders || !1,
|
|
109
|
+
allColumns: m?.allColumns || !1,
|
|
110
|
+
onlySelected: m?.onlySelected || !1
|
|
111
|
+
};
|
|
112
|
+
if (c.current.api.exportDataAsCsv(n), o?.onExport) {
|
|
113
|
+
const r = m?.onlySelected ? c.current.api.getSelectedRows() : T;
|
|
114
|
+
o.onExport(r || [], "csv");
|
|
115
|
+
}
|
|
116
|
+
}, [m, o, T, a]), z = g((n) => {
|
|
117
|
+
if (!f?.enabled) return [];
|
|
118
|
+
const r = [];
|
|
119
|
+
return (f.items || ["copy", "copyWithHeaders", "separator", "export"]).forEach((u) => {
|
|
120
|
+
u === "export" ? r.push({
|
|
121
|
+
name: "Export CSV",
|
|
122
|
+
icon: "<span>📥</span>",
|
|
123
|
+
action: () => $()
|
|
124
|
+
}) : u === "autoSizeAll" ? r.push({
|
|
125
|
+
name: "Auto-size All Columns",
|
|
126
|
+
action: () => {
|
|
127
|
+
c.current?.api && c.current.api.autoSizeAllColumns();
|
|
128
|
+
}
|
|
129
|
+
}) : u === "resetColumns" ? r.push({
|
|
130
|
+
name: "Reset Columns",
|
|
131
|
+
action: () => {
|
|
132
|
+
c.current?.api && c.current.api.resetColumnState();
|
|
133
|
+
}
|
|
134
|
+
}) : r.push(u);
|
|
135
|
+
}), f.customItems && (r.length > 0 && r.push("separator"), f.customItems.forEach((u) => {
|
|
136
|
+
r.push({
|
|
137
|
+
name: u.name,
|
|
138
|
+
disabled: u.disabled,
|
|
139
|
+
action: () => {
|
|
140
|
+
o?.onContextMenuAction && o.onContextMenuAction(u.action, n.node?.data);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
})), r;
|
|
144
|
+
}, [f, $, o]), H = g((n) => {
|
|
145
|
+
o?.onCellClicked?.(n);
|
|
146
|
+
}, [o]), M = g((n) => {
|
|
147
|
+
o?.onRowClicked?.(n);
|
|
148
|
+
}, [o]), q = g((n) => {
|
|
149
|
+
o?.onSelectionChanged?.(n);
|
|
150
|
+
}, [o]), G = g(async (n) => {
|
|
151
|
+
if (o?.onCellValueChanged?.(n), l && n.data && n.data.id)
|
|
152
|
+
try {
|
|
153
|
+
await l.update(a, n.data.id, {
|
|
154
|
+
[n.colDef.field]: n.newValue
|
|
155
|
+
});
|
|
156
|
+
} catch (r) {
|
|
157
|
+
console.error("Failed to update record:", r), n.node.setDataValue(n.colDef.field, n.oldValue);
|
|
158
|
+
}
|
|
159
|
+
}, [o, l, a]), Y = g((n) => {
|
|
160
|
+
c.current = n;
|
|
161
|
+
}, []), te = P(() => ({
|
|
162
|
+
pagination: A,
|
|
163
|
+
paginationPageSize: F,
|
|
164
|
+
domLayout: k,
|
|
165
|
+
animateRows: N,
|
|
166
|
+
rowSelection: D,
|
|
167
|
+
editType: V,
|
|
168
|
+
singleClickEdit: I,
|
|
169
|
+
stopEditingWhenCellsLoseFocus: L,
|
|
170
|
+
statusBar: R ? { statusPanels: R } : void 0,
|
|
171
|
+
enableRangeSelection: O,
|
|
172
|
+
enableCharts: U,
|
|
173
|
+
getContextMenuItems: f?.enabled ? z : void 0,
|
|
174
|
+
suppressCellFocus: !E,
|
|
175
|
+
enableCellTextSelection: !0,
|
|
176
|
+
ensureDomOrder: !0,
|
|
177
|
+
onCellClicked: H,
|
|
178
|
+
onRowClicked: M,
|
|
179
|
+
onSelectionChanged: q,
|
|
180
|
+
onCellValueChanged: G,
|
|
181
|
+
onGridReady: Y
|
|
182
|
+
}), [
|
|
183
|
+
A,
|
|
184
|
+
F,
|
|
185
|
+
k,
|
|
186
|
+
N,
|
|
187
|
+
D,
|
|
188
|
+
V,
|
|
189
|
+
I,
|
|
190
|
+
L,
|
|
191
|
+
R,
|
|
192
|
+
O,
|
|
193
|
+
U,
|
|
194
|
+
f,
|
|
195
|
+
z,
|
|
196
|
+
E,
|
|
197
|
+
H,
|
|
198
|
+
M,
|
|
199
|
+
q,
|
|
200
|
+
G,
|
|
201
|
+
Y
|
|
202
|
+
]), j = P(() => ({
|
|
203
|
+
height: typeof w == "number" ? `${w}px` : w,
|
|
204
|
+
width: "100%"
|
|
205
|
+
}), [w]), re = [
|
|
206
|
+
`ag-theme-${J}`,
|
|
207
|
+
"rounded-xl",
|
|
208
|
+
"border",
|
|
209
|
+
"border-border",
|
|
210
|
+
"overflow-hidden",
|
|
211
|
+
"shadow-lg",
|
|
212
|
+
K
|
|
213
|
+
].filter(Boolean).join(" ");
|
|
214
|
+
return Q ? /* @__PURE__ */ d.jsx("div", { className: "flex items-center justify-center", style: j, children: /* @__PURE__ */ d.jsxs("div", { className: "text-muted-foreground", children: [
|
|
215
|
+
"Loading ",
|
|
216
|
+
a,
|
|
217
|
+
"..."
|
|
218
|
+
] }) }) : _ ? /* @__PURE__ */ d.jsx("div", { className: "flex items-center justify-center", style: j, children: /* @__PURE__ */ d.jsxs("div", { className: "text-destructive", children: [
|
|
219
|
+
"Error loading data: ",
|
|
220
|
+
_.message
|
|
221
|
+
] }) }) : /* @__PURE__ */ d.jsxs("div", { className: "object-aggrid-container", children: [
|
|
222
|
+
m?.enabled && /* @__PURE__ */ d.jsx("div", { className: "mb-2 flex gap-2", children: /* @__PURE__ */ d.jsx(
|
|
223
|
+
"button",
|
|
224
|
+
{
|
|
225
|
+
onClick: $,
|
|
226
|
+
className: "px-3 py-1.5 text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 rounded-md transition-colors",
|
|
227
|
+
children: "Export CSV"
|
|
228
|
+
}
|
|
229
|
+
) }),
|
|
230
|
+
/* @__PURE__ */ d.jsx(
|
|
231
|
+
"div",
|
|
232
|
+
{
|
|
233
|
+
className: re,
|
|
234
|
+
style: j,
|
|
235
|
+
children: /* @__PURE__ */ d.jsx(
|
|
236
|
+
ae,
|
|
237
|
+
{
|
|
238
|
+
ref: c,
|
|
239
|
+
rowData: T,
|
|
240
|
+
columnDefs: ee,
|
|
241
|
+
gridOptions: te
|
|
242
|
+
}
|
|
243
|
+
)
|
|
244
|
+
}
|
|
245
|
+
)
|
|
246
|
+
] });
|
|
247
|
+
}
|
|
248
|
+
function p(a) {
|
|
249
|
+
const l = document.createElement("div");
|
|
250
|
+
return l.textContent = a, l.innerHTML;
|
|
251
|
+
}
|
|
252
|
+
function se(a) {
|
|
253
|
+
return a.filterable === !1 ? !1 : le[a.type] || "agTextColumnFilter";
|
|
254
|
+
}
|
|
255
|
+
function oe(a, l) {
|
|
256
|
+
switch (l.type) {
|
|
257
|
+
case "boolean":
|
|
258
|
+
a.cellRenderer = (e) => e.value === !0 ? "✓ Yes" : e.value === !1 ? "✗ No" : "";
|
|
259
|
+
break;
|
|
260
|
+
case "currency":
|
|
261
|
+
a.valueFormatter = (e) => {
|
|
262
|
+
if (e.value == null) return "";
|
|
263
|
+
const t = l.currency || "USD", i = l.precision || 2;
|
|
264
|
+
return new Intl.NumberFormat("en-US", {
|
|
265
|
+
style: "currency",
|
|
266
|
+
currency: t,
|
|
267
|
+
minimumFractionDigits: i,
|
|
268
|
+
maximumFractionDigits: i
|
|
269
|
+
}).format(e.value);
|
|
270
|
+
};
|
|
271
|
+
break;
|
|
272
|
+
case "percent":
|
|
273
|
+
a.valueFormatter = (e) => {
|
|
274
|
+
if (e.value == null) return "";
|
|
275
|
+
const t = l.precision || 2;
|
|
276
|
+
return `${(e.value * 100).toFixed(t)}%`;
|
|
277
|
+
};
|
|
278
|
+
break;
|
|
279
|
+
case "date":
|
|
280
|
+
a.valueFormatter = (e) => {
|
|
281
|
+
if (!e.value) return "";
|
|
282
|
+
try {
|
|
283
|
+
const t = new Date(e.value);
|
|
284
|
+
return isNaN(t.getTime()) ? "" : t.toLocaleDateString();
|
|
285
|
+
} catch {
|
|
286
|
+
return "";
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
break;
|
|
290
|
+
case "datetime":
|
|
291
|
+
a.valueFormatter = (e) => {
|
|
292
|
+
if (!e.value) return "";
|
|
293
|
+
try {
|
|
294
|
+
const t = new Date(e.value);
|
|
295
|
+
return isNaN(t.getTime()) ? "" : t.toLocaleString();
|
|
296
|
+
} catch {
|
|
297
|
+
return "";
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
break;
|
|
301
|
+
case "time":
|
|
302
|
+
a.valueFormatter = (e) => e.value ? e.value : "";
|
|
303
|
+
break;
|
|
304
|
+
case "email":
|
|
305
|
+
a.cellRenderer = (e) => {
|
|
306
|
+
if (!e.value) return "";
|
|
307
|
+
const t = p(e.value);
|
|
308
|
+
return `<a href="mailto:${t}" class="text-blue-600 hover:underline">${t}</a>`;
|
|
309
|
+
};
|
|
310
|
+
break;
|
|
311
|
+
case "url":
|
|
312
|
+
a.cellRenderer = (e) => {
|
|
313
|
+
if (!e.value) return "";
|
|
314
|
+
const t = p(e.value);
|
|
315
|
+
return `<a href="${t}" target="_blank" rel="noopener noreferrer" class="text-blue-600 hover:underline">${t}</a>`;
|
|
316
|
+
};
|
|
317
|
+
break;
|
|
318
|
+
case "phone":
|
|
319
|
+
a.cellRenderer = (e) => {
|
|
320
|
+
if (!e.value) return "";
|
|
321
|
+
const t = p(e.value);
|
|
322
|
+
return `<a href="tel:${t}" class="text-blue-600 hover:underline">${t}</a>`;
|
|
323
|
+
};
|
|
324
|
+
break;
|
|
325
|
+
case "select":
|
|
326
|
+
a.valueFormatter = (e) => e.value ? (l.options || []).find((h) => h.value === e.value)?.label || e.value : "";
|
|
327
|
+
break;
|
|
328
|
+
case "lookup":
|
|
329
|
+
case "master_detail":
|
|
330
|
+
a.valueFormatter = (e) => e.value ? typeof e.value == "object" ? e.value.name || e.value.label || e.value.id || "" : String(e.value) : "";
|
|
331
|
+
break;
|
|
332
|
+
case "number": {
|
|
333
|
+
const e = l.precision;
|
|
334
|
+
e !== void 0 && (a.valueFormatter = (t) => t.value == null ? "" : Number(t.value).toFixed(e));
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
case "color":
|
|
338
|
+
a.cellRenderer = (e) => {
|
|
339
|
+
if (!e.value) return "";
|
|
340
|
+
const t = p(e.value);
|
|
341
|
+
return `<div class="flex items-center gap-2">
|
|
342
|
+
<div style="width: 16px; height: 16px; background-color: ${t}; border: 1px solid #ccc; border-radius: 2px;"></div>
|
|
343
|
+
<span>${t}</span>
|
|
344
|
+
</div>`;
|
|
345
|
+
};
|
|
346
|
+
break;
|
|
347
|
+
case "rating":
|
|
348
|
+
a.cellRenderer = (e) => {
|
|
349
|
+
if (e.value == null) return "";
|
|
350
|
+
const t = l.max || 5;
|
|
351
|
+
return "⭐".repeat(Math.min(e.value, t));
|
|
352
|
+
};
|
|
353
|
+
break;
|
|
354
|
+
case "image":
|
|
355
|
+
a.cellRenderer = (e) => {
|
|
356
|
+
if (!e.value) return "";
|
|
357
|
+
const t = typeof e.value == "string" ? e.value : e.value.url;
|
|
358
|
+
return t ? `<img src="${p(t)}" alt="" style="width: 40px; height: 40px; object-fit: cover; border-radius: 4px;" />` : "";
|
|
359
|
+
};
|
|
360
|
+
break;
|
|
361
|
+
case "avatar":
|
|
362
|
+
a.cellRenderer = (e) => {
|
|
363
|
+
if (!e.value) return "";
|
|
364
|
+
const t = typeof e.value == "string" ? e.value : e.value.url;
|
|
365
|
+
return t ? `<img src="${p(t)}" alt="" style="width: 32px; height: 32px; object-fit: cover; border-radius: 50%;" />` : "";
|
|
366
|
+
};
|
|
367
|
+
break;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
export {
|
|
371
|
+
fe as default
|
|
372
|
+
};
|