UNPKG

@progress/kendo-react-grid

Version:

React Data Grid (Table) provides 100+ ready-to-use data grid features. KendoReact Grid package

166 lines (165 loc) 5.88 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ import { combineSmartFilters as b } from "../filterCommon.mjs"; import { GridAICommands as g } from "../interfaces/GridAICommands.mjs"; function A(t, e, a) { var h, p, u, k; const i = { ...e }, l = []; let f = !1; return (h = t == null ? void 0 : t.data) != null && h.commands && t.data.commands.forEach((s) => { switch (s.type) { // Sort commands case g.GridSort: s.sort && (i.sort = v(s.sort, e.sort)), s.message && l.push(s.message); break; case g.GridClearSort: i.sort = [], s.message && l.push(s.message); break; // Filter commands case g.GridFilter: s.filter && (i.filter = G(s.filter, e.filter)), s.message && l.push(s.message); break; case g.GridClearFilter: i.filter = void 0, s.message && l.push(s.message); break; // Group commands case g.GridGroup: s.group && (i.group = P(s.group, e.group)), s.message && l.push(s.message); break; case g.GridClearGroup: i.group = [], s.message && l.push(s.message); break; // Highlight commands case g.GridHighlight: s.highlight && a && (i.highlight = [s.highlight]), s.message && l.push(s.message); break; case g.GridClearHighlight: i.highlight = [], s.message && l.push(s.message); break; // Selection commands case g.GridSelect: s.select && a && (i.select = [s.select]), s.message && l.push(s.message); break; case g.GridClearSelect: i.select = [], s.message && l.push(s.message); break; // Column visibility commands case g.GridColumnHide: s.id && e.columnsState && (i.columnsState = o(s.id, !0, e.columnsState)), s.message && l.push(s.message); break; case g.GridColumnShow: s.id && e.columnsState && (i.columnsState = o(s.id, !1, e.columnsState)), s.message && l.push(s.message); break; // Column resize commands case g.GridColumnResize: s.id && s.size && e.columnsState && (i.columnsState = z(s.id, s.size, e.columnsState)), s.message && l.push(s.message); break; // Column reorder commands case g.GridColumnReorder: s.id && s.position !== void 0 && e.columnsState && (i.columnsState = M( s.id, s.position, e.columnsState )), s.message && l.push(s.message); break; // Column lock/unlock commands case g.GridColumnLock: s.id && e.columnsState && (i.columnsState = C(s.id, !0, e.columnsState)), s.message && l.push(s.message); break; case g.GridColumnUnlock: s.id && e.columnsState && (i.columnsState = C(s.id, !1, e.columnsState)), s.message && l.push(s.message); break; // Pagination commands case g.GridPage: if (s.page !== void 0 && a) { const r = x( a, s.page, e.skip, e.take ); i.skip = r.skip, i.take = r.take; } s.message && l.push(s.message); break; case g.GridPageSize: if (s.pageSize !== void 0 && a) { const r = S( s.pageSize, e.skip, e.take ); i.skip = r.skip, i.take = r.take; } s.message && l.push(s.message); break; // Export commands case g.GridExportPDF: f = !0, s.message && l.push(s.message); break; } }), !((u = (p = t == null ? void 0 : t.data) == null ? void 0 : p.commands) != null && u.length) && ((k = t == null ? void 0 : t.data) != null && k.message) && l.push(t.data.message), { state: i, messages: l, shouldExportPdf: f }; } const v = (t, e) => { const a = Array.isArray(t) ? t : [t]; if (a.length === 0) return []; const l = (e != null ? e : []).filter( (f) => !a.some((h) => h.field === f.field) ); return l.push(...a), l; }, G = (t, e) => t ? b( { logic: t.logic ? t.logic : "and", filters: t.filters }, e ) || void 0 : e, P = (t, e) => { if (!t) return e != null ? e : []; const a = Array.isArray(t) ? t : [t]; if (a.length === 0) return []; const l = (e != null ? e : []).filter( (f) => !a.some((h) => h.field === f.field) ); return l.push(...a), l; }, o = (t, e, a) => a.map((i) => i.id === t ? { ...i, hidden: e } : i), z = (t, e, a) => a.map( (i) => i.id === t ? { ...i, width: parseFloat(e) } : i ), M = (t, e, a) => { if (!a.find((p) => p.id === t)) return a; const l = [...a], f = l.findIndex((p) => p.id === t), [h] = l.splice(f, 1); return l.splice(e, 0, h), l.map((p, u) => ({ ...p, orderIndex: u })); }, C = (t, e, a) => a.map((i) => i.id === t ? { ...i, locked: e } : i), x = (t, e, a = 0, i = 10) => { const l = t.getLeafDataItems().length, f = Math.max(1, Math.floor(e)), h = t.getTotal(), p = Math.floor(i != null ? i : l), u = Math.floor((f - 1) * p); return u < h ? { skip: u, take: p } : { skip: a, take: p }; }, S = (t, e = 0, a = 10) => { const i = Math.max(1, Math.floor(t)), l = a != null ? a : 0, f = Math.floor(e / l); let h = 0; return l > 0 && (h = Math.max(0, f * i)), { skip: h, take: i }; }; export { A as handleAIResponse, C as handleColumnLock, M as handleColumnReorder, z as handleColumnResize, o as handleColumnVisibility, G as handleFilterCommand, P as handleGroupCommand, x as handlePageChange, S as handlePageSizeChange, v as handleSortCommand };