@opencorestack/opengridx 3.7.0 → 3.8.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/CHANGELOG.md +40 -0
- package/dist/ai.cjs +3 -3
- package/dist/ai.cjs.map +1 -1
- package/dist/ai.es.js +3 -3
- package/dist/ai.es.js.map +1 -1
- package/dist/opengridx.css +1 -1
- package/dist/opengridx.es.js +4982 -4853
- package/dist/opengridx.es.js.map +1 -1
- package/dist/opengridx.umd.js +15 -15
- package/dist/opengridx.umd.js.map +1 -1
- package/docs/features/filtering.md +2 -0
- package/lib/components/DataGrid/DataGrid.css +0 -3
- package/lib/components/DataGrid/DataGrid.tsx +2 -4
- package/lib/components/DataGrid/GridListView.tsx +1 -1
- package/lib/components/DataGrid/GridPinnedRows.tsx +1 -1
- package/lib/components/DataGrid/GridVirtualRows.tsx +1 -1
- package/lib/components/ListView/ListView.css +4 -4
- package/lib/hooks/core/useDataGrid.ts +40 -35
- package/lib/hooks/core/useGridAggregationApi.ts +1 -1
- package/lib/hooks/core/useGridCellSelection.ts +3 -4
- package/lib/hooks/core/useGridClipboardPaste.ts +1 -1
- package/lib/hooks/core/useGridDetailPanel.ts +1 -1
- package/lib/hooks/core/useGridFillHandle.ts +1 -1
- package/lib/hooks/core/useGridHierarchy.ts +2 -2
- package/lib/hooks/core/useGridKeyboardNavigation.ts +1 -1
- package/lib/hooks/core/useGridLiveRowSelection.ts +9 -2
- package/lib/hooks/core/useGridRangeEditing.ts +1 -1
- package/lib/hooks/core/useGridRowInteractions.ts +3 -2
- package/lib/hooks/core/useLayout.ts +34 -24
- package/lib/hooks/features/useGridSpanning.ts +3 -3
- package/lib/hooks/useRowGrouping.ts +19 -10
- package/lib/hooks/useRowReorder.ts +9 -3
- package/lib/styles/base/reset.css +5 -3
- package/lib/types/state.ts +9 -0
- package/lib/utils/editing/targets.ts +2 -3
- package/lib/utils/export/exportShared.ts +22 -4
- package/lib/utils/export/index.ts +8 -4
- package/lib/utils/filtering/index.ts +8 -2
- package/lib/utils/gridApiRows.ts +1 -1
- package/lib/utils/grouping/groupedExportRows.ts +1 -1
- package/lib/utils/grouping/layeredMap.ts +52 -0
- package/lib/utils/parsing.ts +24 -1
- package/lib/utils/rowIndex.ts +67 -0
- package/lib/utils/values.ts +31 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,46 @@
|
|
|
5
5
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
+
## [3.8.0] — 2026-10-13
|
|
9
|
+
|
|
10
|
+
### Performance
|
|
11
|
+
|
|
12
|
+
- **Cell edits, paste, undo, redo and fill no longer re-process every row.** A committed edit updates the row store's id maps in place and patches only the edited positions of the row array, instead of copying two maps and rebuilding the array. The row-reorder index comes from the store. The id lists that cell selection, paste / fill / undo targets and row selection derive from the displayed rows are reused when an edit leaves every row at its position with its id (a reference comparison per row, a lookup only for replaced rows). Measured at 1,000,000 rows in Chromium (Apple M1): one cell edit 561 → ~35 ms, paste of 1,000 × 10 cells ~790 → ~45 ms, undo / redo ~790 → ~45 ms, fill of 1,000 cells 809 → ~50 ms.
|
|
13
|
+
- **Expanding and collapsing a group no longer rebuilds row metadata for every row.** Leaf rows' `GridRowMeta` objects are built once per grouping tree; a toggle rebuilds only the group rows' entries and reads both through one read-only map. At 1,000,000 rows: expand 279 → ~135 ms, collapse ~120 → ~1 ms.
|
|
14
|
+
- Row selection checks for removed ids before copying the selection, so selecting all rows no longer copies the selection once more.
|
|
15
|
+
|
|
16
|
+
### Documentation
|
|
17
|
+
|
|
18
|
+
- `docs/features/filtering.md` (*Quick Filter*): the searched text is cached per row object, so rows must be replaced, not mutated, and a `valueFormatter` that reads outside state needs new column definitions when that state changes.
|
|
19
|
+
|
|
20
|
+
### Internal
|
|
21
|
+
|
|
22
|
+
- `GridInternalState.rows` also holds `rows` (the stored rows in order) and `indexById`. `GridApi.getAllRows()` returns a copy of it. New `lib/utils/rowIndex.ts` (`getRowIndex`) and `lib/utils/grouping/layeredMap.ts` (`LayeredMap`); internal `rowMetaMap` parameters are typed `ReadonlyMap`.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## [3.7.1] — 2026-10-13
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
|
|
30
|
+
- **Exports no longer crash when a column's `valueGetter` throws.** CSV, Excel (HTML and `exportToExcelAdvanced`), JSON, print and PDF read cell values through `getCellValue`, as the grid does: a throwing getter exports an empty value with a one-time development warning.
|
|
31
|
+
- **Formula escaping covers `valueFormatter` text on number, date and boolean columns** (security). A formatter returning `=HYPERLINK(...)` for a number column was written to CSV and HTML-Excel unescaped, because only the raw value's type was checked. Formatter text is now left unescaped only when it reads as a plain formatted number (digits, signs, separators, brackets, `%`, currency symbols), so `-$3` stays as is.
|
|
32
|
+
- **The quick filter matches the text the grid shows** for `singleSelect` (option label), `boolean` (Yes / No) and `date` (locale date) columns without a `valueFormatter`, in addition to the raw value.
|
|
33
|
+
- **Free text is no longer read as a date.** `Date.parse` accepts text such as `hello 5` (a 2001 date in V8); pasting it into a date column stored that date. Date text may now only contain month and weekday names, `T`, `Z`, `AM`/`PM`, `GMT`/`UTC` besides digits and punctuation. The same rule applies to date filters and sorting of date strings.
|
|
34
|
+
- **Pasting a date into a cell that holds a UTC date-time** (`…Z` or `±hh:mm`) kept the time part but changed the zone meaning, so west of UTC the cell showed the day before. The pasted day now keeps the cell's local time of day and is written as UTC.
|
|
35
|
+
- **List view follows the theme.** Its row text read the undeclared `--ogx-grid-cell-text`, and hover / selection used fixed colours; they now use `--ogx-grid-row-text`, `--ogx-grid-row-hover-background`, `--ogx-grid-row-selected-background` and `--ogx-grid-row-selected-hover-background` (`--ogx-selection-bg` / `--ogx-selection-hover-bg` still win when set).
|
|
36
|
+
- **The stylesheet no longer changes the host page.** The `box-sizing: border-box` reset applied to every element on the page; it now applies only to elements with an `ogx` class and their descendants (including portalled menus and panels), at zero specificity. A page that relied on it for its own elements (for example a padded container with a fixed width around the grid) may need its own `box-sizing: border-box` rule.
|
|
37
|
+
|
|
38
|
+
### Changed
|
|
39
|
+
|
|
40
|
+
- The grid no longer draws a shadow on hover (`.ogx:hover`), which repainted the whole grid on every pointer enter and leave. Add `.ogx:hover { box-shadow: var(--ogx-shadow-md); }` to keep it.
|
|
41
|
+
|
|
42
|
+
### Performance
|
|
43
|
+
|
|
44
|
+
- `useLayout` computes row heights and column widths in separate memos: resizing a column no longer walks every row, and sorting or filtering no longer recomputes column widths.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
8
48
|
## [3.7.0] — 2026-10-13
|
|
9
49
|
|
|
10
50
|
### Added
|
package/dist/ai.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Q=new Set;function de(e,t,r){process.env.NODE_ENV==="production"||Q.has(e)||(Q.add(e),console.warn(`[OpenGridX] ${t}.`,r))}function pe(e,t,r){const n=e[t];if(!r?.valueGetter)return{value:n};try{return{value:r.valueGetter({row:e,field:t,value:n})}}catch(o){return{value:void 0,error:o??new Error("valueGetter failed")}}}function ge(e,t,r){if(!r?.valueGetter)return e[t];const{value:n,error:o}=pe(e,t,r);return o!==void 0&&de(`valueGetter:${t}`,`valueGetter for column "${t}" threw; the value is read as undefined`,o),n}const me=/^(\d{4})-(\d{2})-(\d{2})$/;function ee(e){if(e==null)return null;let t;if(e instanceof Date)t=e;else if(typeof e=="number")t=new Date(e);else if(typeof e=="string"){const r=e.trim();if(r==="")return null;const n=me.exec(r);if(n){const o=Number(n[1]),i=Number(n[2])-1,s=Number(n[3]);if(t=new Date(o,i,s),t.getMonth()!==i||t.getDate()!==s)return null}else t=new Date(r)}else return null;return Number.isNaN(t.getTime())?null:t}function ye(e){const t=ee(e);if(!t)return"";const r=String(t.getFullYear()).padStart(4,"0"),n=String(t.getMonth()+1).padStart(2,"0"),o=String(t.getDate()).padStart(2,"0");return`${r}-${n}-${o}`}function be(e){switch(e){case"number":return["=","!=",">",">=","<","<=","isEmpty","isNotEmpty"];case"date":return["is","not","after","onOrAfter","before","onOrBefore","isEmpty","isNotEmpty"];case"boolean":return["is"];case"singleSelect":return["isAnyOf","is","not"];default:return["contains","equals","startsWith","endsWith","isEmpty","isNotEmpty"]}}const he=["sum","avg","count","min","max","unique"],X=["sum","avg","count","min","max"],te=["isEmpty","isNotEmpty"],I=3,U=["filter","sort","grouping","aggregation","pivot","columnVisibility"],H={filter:"filterModel",sort:"sortModel",grouping:"rowGroupingModel",aggregation:"aggregationModel",pivot:"pivotModel",columnVisibility:"columnVisibilityModel"};function S(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function $(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function re(e){const t=Array.isArray(e?.include)?e.include:U,r=Array.isArray(e?.exclude)?e.exclude:[];return U.filter(n=>t.includes(n)&&!r.includes(n))}function J(e){if(!Array.isArray(e))return[];const t=new Set,r=[];for(const n of e){if(!$(n))continue;const o=n.field;typeof o!="string"||o===""||o.startsWith("__")||n.isSpacer===!0||t.has(o)||(t.add(o),r.push(n))}return r}function ne(e){return be(e.type)}const ie=e=>e.filterable!==!1,oe=e=>e.sortable!==!1,G=e=>e.groupable!==!1,se=e=>e.hideable!==!1;function F(e,t=he){if(e.aggregable===!1)return[];const r=e.type==="number"||e.aggregable===!0?t:t.filter(o=>o==="count"),n=e.availableAggregationFunctions;return Array.isArray(n)?r.filter(o=>n.includes(o)):[...r]}function $e(e){const t=[];if(!Array.isArray(e.valueOptions))return t;for(const r of e.valueOptions){const n=r!==null&&typeof r=="object"?r.value:r;(typeof n=="string"||typeof n=="number"&&Number.isFinite(n))&&!t.includes(n)&&t.push(n)}return t}const Ae="OpenGridX grid state",Se=10;function j(e){const t=typeof e.headerName=="string"&&e.headerName!==""?e.headerName:e.field,r=typeof e.description=="string"&&e.description!==""?` (${e.description})`:"";return`${t}${r}`}function O(e,t,r){return r.descriptions?{...e,description:t}:e}function Oe(e,t){return!t.examples||!Array.isArray(e.aiExamples)?[]:e.aiExamples.filter(r=>typeof r=="string"||typeof r=="boolean"||typeof r=="number"&&Number.isFinite(r)).slice(0,Se)}function ve(e,t){let r;switch(e.type){case"number":r={type:"number"};break;case"date":r={type:"string",format:"date"};break;case"boolean":r={type:"boolean"};break;case"singleSelect":{const o=$e(e),i=o.length>0?{enum:o}:{type:"string"};r={anyOf:[i,{type:"array",items:i}]};break}default:r={type:"string"}}const n=Oe(e,t);return n.length>0?{...r,examples:n}:r}function Me(e,t){const r=ne(e),n=r.filter(s=>te.includes(s)),o=e.type==="singleSelect"?"; isAnyOf takes an array":"",i=n.length>0?`${n.join(" and ")} take no value${o}`:o.slice(2);return O({type:"object",properties:{field:{const:e.field},operator:{enum:r},value:ve(e,t)},required:["field","operator"],additionalProperties:!1},i?`${j(e)}: ${i}`:j(e),t)}function Ee(e,t,r){const n=e.filter(ie),o={},i={enum:["and","or"]};if(n.length>0){r.filterItem={oneOf:n.map(s=>Me(s,t))};for(let s=I;s>=1;s--){const l=s===I?{$ref:"#/$defs/filterItem"}:{anyOf:[{$ref:"#/$defs/filterItem"},{$ref:`#/$defs/filterGroup${s+1}`}]};r[`filterGroup${s}`]={type:"object",properties:{logicOperator:i,items:{type:"array",items:l}},required:["logicOperator","items"],additionalProperties:!1}}o.items={type:"array",items:{anyOf:[{$ref:"#/$defs/filterItem"},{$ref:"#/$defs/filterGroup1"}]}},o.logicOperator=i}return o.quickFilterValues=O({type:"array",items:{type:"string"}},"Words a row must contain, in any column",t),{type:"object",properties:o,additionalProperties:!1}}function q(e){return{enum:e.map(t=>t.field)}}function we(e,t,r,n){switch(e){case"filter":return Ee(t,r,n);case"sort":{const o=t.filter(oe);return o.length===0?null:O({type:"array",items:{type:"object",properties:{field:q(o),sort:{enum:["asc","desc"]}},required:["field","sort"],additionalProperties:!1}},"Most significant first",r)}case"grouping":{const o=t.filter(G);return o.length===0?null:O({type:"array",items:q(o),uniqueItems:!0},"Outermost first",r)}case"aggregation":{const o={};for(const i of t){const s=F(i);s.length>0&&(o[i.field]=O({enum:s},j(i),r))}return Object.keys(o).length===0?null:{type:"object",properties:o,additionalProperties:!1}}case"pivot":{const o=t.filter(G),i=t.map(l=>({col:l,fns:F(l,X)})).filter(l=>l.fns.length>0).map(({col:l,fns:a})=>O({type:"object",properties:{field:{const:l.field},aggFn:{enum:a}},required:["field","aggFn"],additionalProperties:!1},j(l),r));if(o.length===0||i.length===0)return null;const s={type:"array",items:q(o),uniqueItems:!0};return{type:"object",properties:{rowFields:s,columnFields:s,valueFields:{type:"array",items:{oneOf:i}}},required:["rowFields","columnFields","valueFields"],additionalProperties:!1}}case"columnVisibility":{const o={};for(const i of t.filter(se))o[i.field]=O({type:"boolean"},j(i),r);return Object.keys(o).length===0?null:O({type:"object",properties:o,additionalProperties:!1},"false hides a column",r)}}}function Y(e,t={}){const r={descriptions:t.descriptions!==!1,examples:t.examples!==!1},n=J(e),o={},i={};for(const l of re(t)){const a=we(l,n,r,o);a&&(i[H[l]]=a)}const s={$schema:"https://json-schema.org/draft/2020-12/schema",schemaVersion:1,title:Ae,type:"object",properties:i,additionalProperties:!1};return r.descriptions&&(s.description="Grid state to apply. Include only the parts the user asked to change."),Object.keys(o).length>0&&(s.$defs=o),s}const Fe=Symbol.for("opengridx.ai.validated");function D(e){return Object.defineProperty(e,Fe,{value:!0,enumerable:!1}),e}const M={ok:!1},h=e=>({ok:!0,value:e}),Ne=/^\d+(?:\.\d*)?(?:e[+-]?\d+)?$/i,_e=/^\.\d+(?:e[+-]?\d+)?$/i,ke=/^\d{1,3}(?:,\d{3})+(?:\.\d*)?$/,je=/[\p{Sc}\s]/gu;function Ge(e){let t=e.replace(je,"");if(t==="")return e.trim()===""?h(null):M;let r=!1;t.startsWith("(")&&t.endsWith(")")&&(r=!0,t=t.slice(1,-1)),(t.startsWith("-")||t.startsWith("+")||t.startsWith("\u2212"))&&(t[0]!=="+"&&(r=!r),t=t.slice(1));let n=!1;if(t.endsWith("%")&&(n=!0,t=t.slice(0,-1)),ke.test(t))t=t.split(",").join("");else if(!Ne.test(t)&&!_e.test(t))return M;let o=Number(t);return Number.isFinite(o)?(n&&(o/=100),r&&(o=-o),h(o)):M}function Te(e,t){const r=e.trim();if(r==="")return h(null);const n=ee(r);return n?h(n):M}const Ve=new Set(["true","yes","1"]),Pe=new Set(["false","no","0"]);function Re(e,t){const r=e.trim().toLowerCase();return r===""?h(null):Ve.has(r)?h(!0):Pe.has(r)?h(!1):M}function Ie(e,t){const r=e.trim();if(r==="")return h(null);if(!t||t.length===0)return M;const n=r.toLowerCase();for(const o of t){const i=typeof o=="object"?o.value:o;if(String(i).toLowerCase()===n)return h(i)}for(const o of t)if(typeof o=="object"&&o.label.toLowerCase()===n)return h(o.value);return M}const p=e=>({ok:!0,value:e}),A={ok:!1,reason:"invalidValue"},L=e=>e.ok?p(e.value):A;function C(e){return e==null||typeof e=="string"&&e.trim()===""}function De(e){return e==null?p(""):typeof e=="string"?p(e):typeof e=="number"||typeof e=="boolean"?p(String(e)):A}function Le(e){return C(e)?p(null):typeof e=="number"?Number.isFinite(e)?p(e):A:typeof e!="string"?A:L(Ge(e))}function Ce(e){return C(e)?p(null):e instanceof Date?Number.isNaN(e.getTime())?A:p(e):typeof e=="number"?Number.isFinite(e)?p(new Date(e)):A:typeof e!="string"?A:L(Te(e))}function le(e){return C(e)?p(null):typeof e=="boolean"?p(e):typeof e!="string"&&typeof e!="number"?A:L(Re(String(e)))}function qe(e,t){if(C(e))return p(null);if(typeof e!="string"&&typeof e!="number"&&typeof e!="boolean")return A;const r=t.valueOptions;return!r||r.length===0?p(e):L(Ie(String(e),r))}function We(e,t){switch(t.type){case"number":return Le(e);case"date":return Ce(e);case"boolean":return le(e);case"singleSelect":return qe(e,t);default:return De(e)}}const W=200,Ue=100;function u(e,t,r){return e.errors.length<Ue&&e.errors.push({path:t,message:r}),null}function c(e){return typeof e=="string"?JSON.stringify(e.slice(0,60)):e===null||typeof e!="object"?String(e):Array.isArray(e)?"a list":"an object"}function ae(e){return typeof e=="string"?e.trim().toLowerCase():null}function K(e){return Object.keys(e).filter(t=>t!=="__proto__")}function N(e,t,r,n,o){const i=typeof t=="string"?e.byField.get(t):void 0;return i?n(i)?i:u(e,r,`Field ${c(t)} cannot be ${o}`):u(e,r,`Unknown field ${c(t)}`)}function _(e,t,r){if(t==null)return[];const n=Array.isArray(t)?t:[t];return n.length>W&&u(e,r,`Only the first ${W} entries are read`),n.slice(0,W)}function T(e,t,r,n){const o=ae(t);return n.find(i=>i.toLowerCase()===o)??u(e,r,`${c(t)} is not one of ${n.join(", ")}`)}function Z(e,t,r,n){const o=We(t,r);if(!o.ok)return u(e,n,`${c(t)} is not a valid ${r.type??"string"} value`);const i=o.value instanceof Date?ye(o.value):o.value;return i==null||i===""?u(e,n,"Missing value"):{v:i}}function Be(e,t,r){const n=N(e,t.field,`${r}.field`,ie,"filtered");if(!n)return null;const o=T(e,t.operator,`${r}.operator`,ne(n));if(o===null)return null;const i={field:n.field,operator:o};if(te.includes(i.operator))return i;const s=S(t,"value")?t.value:void 0;if(i.operator==="isAnyOf"){const a=[];return _(e,s,`${r}.value`).forEach((f,v)=>{const g=Z(e,f,n,`${r}.value[${v}]`);g&&!a.includes(g.v)&&a.push(g.v)}),a.length===0?u(e,`${r}.value`,"No valid values"):(i.value=a,i)}if(Array.isArray(s))return u(e,`${r}.value`,"Expected one value, not a list");const l=Z(e,s,n,`${r}.value`);return l?(i.value=l.v,i):null}function ue(e,t,r){return t===void 0?null:T(e,t,r,["and","or"])}function fe(e,t,r,n){const o=[];return _(e,t,r).forEach((i,s)=>{const l=`${r}[${s}]`;if(!$(i))u(e,l,`Expected a filter, got ${c(i)}`);else if(S(i,"items")||S(i,"logicOperator")){if(n>=I){u(e,l,`Groups nest at most ${I} levels`);return}const a=fe(e,i.items,`${l}.items`,n+1);a.length===0?u(e,l,"Empty group removed"):o.push({logicOperator:ue(e,i.logicOperator,`${l}.logicOperator`)??"and",items:a})}else{const a=Be(e,i,l);a&&o.push(a)}}),o}function Xe(e,t,r){const n={};S(t,"items")&&(n.items=fe(e,t.items,`${r}.items`,0));const o=ue(e,t.logicOperator,`${r}.logicOperator`);return o&&(n.logicOperator=o),S(t,"quickFilterValues")&&(n.quickFilterValues=[],_(e,t.quickFilterValues,`${r}.quickFilterValues`).forEach((i,s)=>{const l=typeof i=="string"||typeof i=="number"?String(i).trim():null;l===null?u(e,`${r}.quickFilterValues[${s}]`,`Expected text, got ${c(i)}`):l!==""&&n.quickFilterValues?.push(l)})),n}function He(e,t,r){const n=[];return _(e,t,r).forEach((o,i)=>{const s=`${r}[${i}]`;if(!$(o))return u(e,s,`Expected { field, sort }, got ${c(o)}`);const l=N(e,o.field,`${s}.field`,oe,"sorted"),a=l&&T(e,o.sort,`${s}.sort`,["asc","desc"]);!l||!a||(n.some(f=>f.field===l.field)?u(e,s,`${c(l.field)} is sorted twice`):n.push({field:l.field,sort:a}))}),n}function B(e,t,r,n,o){const i=[];return _(e,t,r).forEach((s,l)=>{const a=N(e,s,`${r}[${l}]`,n,o);a&&!i.includes(a.field)&&i.push(a.field)}),i}const Je=e=>F(e).length>0,Ye=e=>F(e,X).length>0;function Ke(e,t,r){const n={};for(const o of K(t)){if(ae(t[o])==="none")continue;const i=N(e,o,`${r}.${o}`,Je,"aggregated"),s=i&&T(e,t[o],`${r}.${o}`,F(i));i&&s&&(n[i.field]=s)}return n}function ze(e,t,r){const n=[];return _(e,t.valueFields,`${r}.valueFields`).forEach((o,i)=>{const s=`${r}.valueFields[${i}]`;if(!$(o))return u(e,s,`Expected { field, aggFn }, got ${c(o)}`);const l=N(e,o.field,`${s}.field`,Ye,"a pivot value"),a=l&&T(e,o.aggFn,`${s}.aggFn`,F(l,X));l&&a&&!n.some(f=>f.field===l.field&&f.aggFn===a)&&n.push({field:l.field,aggFn:a})}),{rowFields:B(e,t.rowFields,`${r}.rowFields`,G,"a pivot label"),columnFields:B(e,t.columnFields,`${r}.columnFields`,G,"a pivot label"),valueFields:n}}function Qe(e,t,r){const n={};for(const o of K(t)){const i=N(e,o,`${r}.${o}`,se,"hidden"),s=le(t[o]);i&&(s.ok&&s.value!==null?n[i.field]=s.value:u(e,`${r}.${o}`,`Expected true or false, got ${c(t[o])}`))}return n}function Ze(e,t,r,n,o){t==="sort"?o.sortModel=He(e,r,n):t==="grouping"?o.rowGroupingModel=B(e,r,n,G,"grouped"):$(r)?t==="filter"?o.filterModel=Xe(e,r,n):t==="aggregation"?o.aggregationModel=Ke(e,r,n):t==="pivot"?o.pivotModel=ze(e,r,n):o.columnVisibilityModel=Qe(e,r,n):u(e,n,`Expected an object, got ${c(r)}`)}function z(e,t,r={}){const n=xe(e,t,r);return D(n.state),D(n)}function xe(e,t,r){const n={errors:[],byField:new Map},o={};try{for(const l of J(t))n.byField.set(l.field,l);let i=e;if(typeof e=="string")try{i=JSON.parse(e)}catch{return u(n,"","Not valid JSON"),{state:o,errors:n.errors}}if(!$(i))return u(n,"",`Expected an object, got ${c(i)}`),{state:o,errors:n.errors};const s=re(r);for(const l of K(i)){const a=U.find(f=>H[f]===l);l==="schemaVersion"?i[l]!==1&&u(n,l,`Unsupported schemaVersion ${c(i[l])}`):l==="message"?typeof i[l]!="string"&&u(n,l,`Expected text, got ${c(i[l])}`):a?s.includes(a)?Ze(n,a,i[l],l,o):u(n,l,"Part not allowed"):u(n,l,"Unknown part")}}catch{return u(n,"","Could not read the input"),{state:{},errors:n.errors}}return{state:o,errors:n.errors}}const k="```";function V(){return typeof DOMException=="function"?new DOMException("The operation was aborted.","AbortError"):Object.assign(new Error("The operation was aborted."),{name:"AbortError"})}function et(e){const t=e.trim();if(t.startsWith("{"))return{json:t,message:""};const r=e.indexOf(k),n=r<0?-1:e.indexOf(`
|
|
2
|
-
`,r+
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Q=new Set;function de(e,t,r){process.env.NODE_ENV==="production"||Q.has(e)||(Q.add(e),console.warn(`[OpenGridX] ${t}.`,r))}function pe(e,t,r){const n=e[t];if(!r?.valueGetter)return{value:n};try{return{value:r.valueGetter({row:e,field:t,value:n})}}catch(o){return{value:void 0,error:o??new Error("valueGetter failed")}}}function me(e,t,r){if(!r?.valueGetter)return e[t];const{value:n,error:o}=pe(e,t,r);return o!==void 0&&de(`valueGetter:${t}`,`valueGetter for column "${t}" threw; the value is read as undefined`,o),n}const ge=/^(\d{4})-(\d{2})-(\d{2})$/;function ee(e){if(e==null)return null;let t;if(e instanceof Date)t=e;else if(typeof e=="number")t=new Date(e);else if(typeof e=="string"){const r=e.trim();if(r==="")return null;const n=ge.exec(r);if(n){const o=Number(n[1]),i=Number(n[2])-1,s=Number(n[3]);if(t=new Date(o,i,s),t.getMonth()!==i||t.getDate()!==s)return null}else{if(!$e(r))return null;t=new Date(r)}}else return null;return Number.isNaN(t.getTime())?null:t}const ye=["january","february","march","april","may","june","july","august","september","october","november","december","monday","tuesday","wednesday","thursday","friday","saturday","sunday"],be=new Set(["t","z","am","pm","gmt","utc","sept"]);function he(e){return be.has(e)?!0:e.length>=3&&ye.some(t=>t.startsWith(e))}function $e(e){let t="";for(let r=0;r<=e.length;r++){const n=r<e.length?e[r].toLowerCase():"";if(n>="a"&&n<="z"){t+=n;continue}if(t!==""&&!he(t))return!1;t=""}return!0}function Ae(e){const t=ee(e);if(!t)return"";const r=String(t.getFullYear()).padStart(4,"0"),n=String(t.getMonth()+1).padStart(2,"0"),o=String(t.getDate()).padStart(2,"0");return`${r}-${n}-${o}`}function Se(e){switch(e){case"number":return["=","!=",">",">=","<","<=","isEmpty","isNotEmpty"];case"date":return["is","not","after","onOrAfter","before","onOrBefore","isEmpty","isNotEmpty"];case"boolean":return["is"];case"singleSelect":return["isAnyOf","is","not"];default:return["contains","equals","startsWith","endsWith","isEmpty","isNotEmpty"]}}const Oe=["sum","avg","count","min","max","unique"],X=["sum","avg","count","min","max"],te=["isEmpty","isNotEmpty"],R=3,U=["filter","sort","grouping","aggregation","pivot","columnVisibility"],H={filter:"filterModel",sort:"sortModel",grouping:"rowGroupingModel",aggregation:"aggregationModel",pivot:"pivotModel",columnVisibility:"columnVisibilityModel"};function S(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function $(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function re(e){const t=Array.isArray(e?.include)?e.include:U,r=Array.isArray(e?.exclude)?e.exclude:[];return U.filter(n=>t.includes(n)&&!r.includes(n))}function J(e){if(!Array.isArray(e))return[];const t=new Set,r=[];for(const n of e){if(!$(n))continue;const o=n.field;typeof o!="string"||o===""||o.startsWith("__")||n.isSpacer===!0||t.has(o)||(t.add(o),r.push(n))}return r}function ne(e){return Se(e.type)}const ie=e=>e.filterable!==!1,oe=e=>e.sortable!==!1,T=e=>e.groupable!==!1,se=e=>e.hideable!==!1;function N(e,t=Oe){if(e.aggregable===!1)return[];const r=e.type==="number"||e.aggregable===!0?t:t.filter(o=>o==="count"),n=e.availableAggregationFunctions;return Array.isArray(n)?r.filter(o=>n.includes(o)):[...r]}function ve(e){const t=[];if(!Array.isArray(e.valueOptions))return t;for(const r of e.valueOptions){const n=r!==null&&typeof r=="object"?r.value:r;(typeof n=="string"||typeof n=="number"&&Number.isFinite(n))&&!t.includes(n)&&t.push(n)}return t}const Ee="OpenGridX grid state",Me=10;function k(e){const t=typeof e.headerName=="string"&&e.headerName!==""?e.headerName:e.field,r=typeof e.description=="string"&&e.description!==""?` (${e.description})`:"";return`${t}${r}`}function O(e,t,r){return r.descriptions?{...e,description:t}:e}function we(e,t){return!t.examples||!Array.isArray(e.aiExamples)?[]:e.aiExamples.filter(r=>typeof r=="string"||typeof r=="boolean"||typeof r=="number"&&Number.isFinite(r)).slice(0,Me)}function Ne(e,t){let r;switch(e.type){case"number":r={type:"number"};break;case"date":r={type:"string",format:"date"};break;case"boolean":r={type:"boolean"};break;case"singleSelect":{const o=ve(e),i=o.length>0?{enum:o}:{type:"string"};r={anyOf:[i,{type:"array",items:i}]};break}default:r={type:"string"}}const n=we(e,t);return n.length>0?{...r,examples:n}:r}function _e(e,t){const r=ne(e),n=r.filter(s=>te.includes(s)),o=e.type==="singleSelect"?"; isAnyOf takes an array":"",i=n.length>0?`${n.join(" and ")} take no value${o}`:o.slice(2);return O({type:"object",properties:{field:{const:e.field},operator:{enum:r},value:Ne(e,t)},required:["field","operator"],additionalProperties:!1},i?`${k(e)}: ${i}`:k(e),t)}function Fe(e,t,r){const n=e.filter(ie),o={},i={enum:["and","or"]};if(n.length>0){r.filterItem={oneOf:n.map(s=>_e(s,t))};for(let s=R;s>=1;s--){const l=s===R?{$ref:"#/$defs/filterItem"}:{anyOf:[{$ref:"#/$defs/filterItem"},{$ref:`#/$defs/filterGroup${s+1}`}]};r[`filterGroup${s}`]={type:"object",properties:{logicOperator:i,items:{type:"array",items:l}},required:["logicOperator","items"],additionalProperties:!1}}o.items={type:"array",items:{anyOf:[{$ref:"#/$defs/filterItem"},{$ref:"#/$defs/filterGroup1"}]}},o.logicOperator=i}return o.quickFilterValues=O({type:"array",items:{type:"string"}},"Words a row must contain, in any column",t),{type:"object",properties:o,additionalProperties:!1}}function q(e){return{enum:e.map(t=>t.field)}}function je(e,t,r,n){switch(e){case"filter":return Fe(t,r,n);case"sort":{const o=t.filter(oe);return o.length===0?null:O({type:"array",items:{type:"object",properties:{field:q(o),sort:{enum:["asc","desc"]}},required:["field","sort"],additionalProperties:!1}},"Most significant first",r)}case"grouping":{const o=t.filter(T);return o.length===0?null:O({type:"array",items:q(o),uniqueItems:!0},"Outermost first",r)}case"aggregation":{const o={};for(const i of t){const s=N(i);s.length>0&&(o[i.field]=O({enum:s},k(i),r))}return Object.keys(o).length===0?null:{type:"object",properties:o,additionalProperties:!1}}case"pivot":{const o=t.filter(T),i=t.map(l=>({col:l,fns:N(l,X)})).filter(l=>l.fns.length>0).map(({col:l,fns:a})=>O({type:"object",properties:{field:{const:l.field},aggFn:{enum:a}},required:["field","aggFn"],additionalProperties:!1},k(l),r));if(o.length===0||i.length===0)return null;const s={type:"array",items:q(o),uniqueItems:!0};return{type:"object",properties:{rowFields:s,columnFields:s,valueFields:{type:"array",items:{oneOf:i}}},required:["rowFields","columnFields","valueFields"],additionalProperties:!1}}case"columnVisibility":{const o={};for(const i of t.filter(se))o[i.field]=O({type:"boolean"},k(i),r);return Object.keys(o).length===0?null:O({type:"object",properties:o,additionalProperties:!1},"false hides a column",r)}}}function Y(e,t={}){const r={descriptions:t.descriptions!==!1,examples:t.examples!==!1},n=J(e),o={},i={};for(const l of re(t)){const a=je(l,n,r,o);a&&(i[H[l]]=a)}const s={$schema:"https://json-schema.org/draft/2020-12/schema",schemaVersion:1,title:Ee,type:"object",properties:i,additionalProperties:!1};return r.descriptions&&(s.description="Grid state to apply. Include only the parts the user asked to change."),Object.keys(o).length>0&&(s.$defs=o),s}const ke=Symbol.for("opengridx.ai.validated");function I(e){return Object.defineProperty(e,ke,{value:!0,enumerable:!1}),e}const E={ok:!1},h=e=>({ok:!0,value:e}),Te=/^\d+(?:\.\d*)?(?:e[+-]?\d+)?$/i,Ge=/^\.\d+(?:e[+-]?\d+)?$/i,Ve=/^\d{1,3}(?:,\d{3})+(?:\.\d*)?$/,De=/[\p{Sc}\s]/gu;function Pe(e){let t=e.replace(De,"");if(t==="")return e.trim()===""?h(null):E;let r=!1;t.startsWith("(")&&t.endsWith(")")&&(r=!0,t=t.slice(1,-1)),(t.startsWith("-")||t.startsWith("+")||t.startsWith("\u2212"))&&(t[0]!=="+"&&(r=!r),t=t.slice(1));let n=!1;if(t.endsWith("%")&&(n=!0,t=t.slice(0,-1)),Ve.test(t))t=t.split(",").join("");else if(!Te.test(t)&&!Ge.test(t))return E;let o=Number(t);return Number.isFinite(o)?(n&&(o/=100),r&&(o=-o),h(o)):E}function Re(e,t){const r=e.trim();if(r==="")return h(null);const n=ee(r);return n?h(n):E}const Ie=new Set(["true","yes","1"]),Le=new Set(["false","no","0"]);function Ce(e,t){const r=e.trim().toLowerCase();return r===""?h(null):Ie.has(r)?h(!0):Le.has(r)?h(!1):E}function qe(e,t){const r=e.trim();if(r==="")return h(null);if(!t||t.length===0)return E;const n=r.toLowerCase();for(const o of t){const i=typeof o=="object"?o.value:o;if(String(i).toLowerCase()===n)return h(i)}for(const o of t)if(typeof o=="object"&&o.label.toLowerCase()===n)return h(o.value);return E}const p=e=>({ok:!0,value:e}),A={ok:!1,reason:"invalidValue"},L=e=>e.ok?p(e.value):A;function C(e){return e==null||typeof e=="string"&&e.trim()===""}function We(e){return e==null?p(""):typeof e=="string"?p(e):typeof e=="number"||typeof e=="boolean"?p(String(e)):A}function Ue(e){return C(e)?p(null):typeof e=="number"?Number.isFinite(e)?p(e):A:typeof e!="string"?A:L(Pe(e))}function Be(e){return C(e)?p(null):e instanceof Date?Number.isNaN(e.getTime())?A:p(e):typeof e=="number"?Number.isFinite(e)?p(new Date(e)):A:typeof e!="string"?A:L(Re(e))}function le(e){return C(e)?p(null):typeof e=="boolean"?p(e):typeof e!="string"&&typeof e!="number"?A:L(Ce(String(e)))}function Xe(e,t){if(C(e))return p(null);if(typeof e!="string"&&typeof e!="number"&&typeof e!="boolean")return A;const r=t.valueOptions;return!r||r.length===0?p(e):L(qe(String(e),r))}function He(e,t){switch(t.type){case"number":return Ue(e);case"date":return Be(e);case"boolean":return le(e);case"singleSelect":return Xe(e,t);default:return We(e)}}const W=200,Je=100;function u(e,t,r){return e.errors.length<Je&&e.errors.push({path:t,message:r}),null}function c(e){return typeof e=="string"?JSON.stringify(e.slice(0,60)):e===null||typeof e!="object"?String(e):Array.isArray(e)?"a list":"an object"}function ae(e){return typeof e=="string"?e.trim().toLowerCase():null}function z(e){return Object.keys(e).filter(t=>t!=="__proto__")}function _(e,t,r,n,o){const i=typeof t=="string"?e.byField.get(t):void 0;return i?n(i)?i:u(e,r,`Field ${c(t)} cannot be ${o}`):u(e,r,`Unknown field ${c(t)}`)}function F(e,t,r){if(t==null)return[];const n=Array.isArray(t)?t:[t];return n.length>W&&u(e,r,`Only the first ${W} entries are read`),n.slice(0,W)}function G(e,t,r,n){const o=ae(t);return n.find(i=>i.toLowerCase()===o)??u(e,r,`${c(t)} is not one of ${n.join(", ")}`)}function Z(e,t,r,n){const o=He(t,r);if(!o.ok)return u(e,n,`${c(t)} is not a valid ${r.type??"string"} value`);const i=o.value instanceof Date?Ae(o.value):o.value;return i==null||i===""?u(e,n,"Missing value"):{v:i}}function Ye(e,t,r){const n=_(e,t.field,`${r}.field`,ie,"filtered");if(!n)return null;const o=G(e,t.operator,`${r}.operator`,ne(n));if(o===null)return null;const i={field:n.field,operator:o};if(te.includes(i.operator))return i;const s=S(t,"value")?t.value:void 0;if(i.operator==="isAnyOf"){const a=[];return F(e,s,`${r}.value`).forEach((f,v)=>{const g=Z(e,f,n,`${r}.value[${v}]`);g&&!a.includes(g.v)&&a.push(g.v)}),a.length===0?u(e,`${r}.value`,"No valid values"):(i.value=a,i)}if(Array.isArray(s))return u(e,`${r}.value`,"Expected one value, not a list");const l=Z(e,s,n,`${r}.value`);return l?(i.value=l.v,i):null}function ue(e,t,r){return t===void 0?null:G(e,t,r,["and","or"])}function fe(e,t,r,n){const o=[];return F(e,t,r).forEach((i,s)=>{const l=`${r}[${s}]`;if(!$(i))u(e,l,`Expected a filter, got ${c(i)}`);else if(S(i,"items")||S(i,"logicOperator")){if(n>=R){u(e,l,`Groups nest at most ${R} levels`);return}const a=fe(e,i.items,`${l}.items`,n+1);a.length===0?u(e,l,"Empty group removed"):o.push({logicOperator:ue(e,i.logicOperator,`${l}.logicOperator`)??"and",items:a})}else{const a=Ye(e,i,l);a&&o.push(a)}}),o}function ze(e,t,r){const n={};S(t,"items")&&(n.items=fe(e,t.items,`${r}.items`,0));const o=ue(e,t.logicOperator,`${r}.logicOperator`);return o&&(n.logicOperator=o),S(t,"quickFilterValues")&&(n.quickFilterValues=[],F(e,t.quickFilterValues,`${r}.quickFilterValues`).forEach((i,s)=>{const l=typeof i=="string"||typeof i=="number"?String(i).trim():null;l===null?u(e,`${r}.quickFilterValues[${s}]`,`Expected text, got ${c(i)}`):l!==""&&n.quickFilterValues?.push(l)})),n}function Ke(e,t,r){const n=[];return F(e,t,r).forEach((o,i)=>{const s=`${r}[${i}]`;if(!$(o))return u(e,s,`Expected { field, sort }, got ${c(o)}`);const l=_(e,o.field,`${s}.field`,oe,"sorted"),a=l&&G(e,o.sort,`${s}.sort`,["asc","desc"]);!l||!a||(n.some(f=>f.field===l.field)?u(e,s,`${c(l.field)} is sorted twice`):n.push({field:l.field,sort:a}))}),n}function B(e,t,r,n,o){const i=[];return F(e,t,r).forEach((s,l)=>{const a=_(e,s,`${r}[${l}]`,n,o);a&&!i.includes(a.field)&&i.push(a.field)}),i}const Qe=e=>N(e).length>0,Ze=e=>N(e,X).length>0;function xe(e,t,r){const n={};for(const o of z(t)){if(ae(t[o])==="none")continue;const i=_(e,o,`${r}.${o}`,Qe,"aggregated"),s=i&&G(e,t[o],`${r}.${o}`,N(i));i&&s&&(n[i.field]=s)}return n}function et(e,t,r){const n=[];return F(e,t.valueFields,`${r}.valueFields`).forEach((o,i)=>{const s=`${r}.valueFields[${i}]`;if(!$(o))return u(e,s,`Expected { field, aggFn }, got ${c(o)}`);const l=_(e,o.field,`${s}.field`,Ze,"a pivot value"),a=l&&G(e,o.aggFn,`${s}.aggFn`,N(l,X));l&&a&&!n.some(f=>f.field===l.field&&f.aggFn===a)&&n.push({field:l.field,aggFn:a})}),{rowFields:B(e,t.rowFields,`${r}.rowFields`,T,"a pivot label"),columnFields:B(e,t.columnFields,`${r}.columnFields`,T,"a pivot label"),valueFields:n}}function tt(e,t,r){const n={};for(const o of z(t)){const i=_(e,o,`${r}.${o}`,se,"hidden"),s=le(t[o]);i&&(s.ok&&s.value!==null?n[i.field]=s.value:u(e,`${r}.${o}`,`Expected true or false, got ${c(t[o])}`))}return n}function rt(e,t,r,n,o){t==="sort"?o.sortModel=Ke(e,r,n):t==="grouping"?o.rowGroupingModel=B(e,r,n,T,"grouped"):$(r)?t==="filter"?o.filterModel=ze(e,r,n):t==="aggregation"?o.aggregationModel=xe(e,r,n):t==="pivot"?o.pivotModel=et(e,r,n):o.columnVisibilityModel=tt(e,r,n):u(e,n,`Expected an object, got ${c(r)}`)}function K(e,t,r={}){const n=nt(e,t,r);return I(n.state),I(n)}function nt(e,t,r){const n={errors:[],byField:new Map},o={};try{for(const l of J(t))n.byField.set(l.field,l);let i=e;if(typeof e=="string")try{i=JSON.parse(e)}catch{return u(n,"","Not valid JSON"),{state:o,errors:n.errors}}if(!$(i))return u(n,"",`Expected an object, got ${c(i)}`),{state:o,errors:n.errors};const s=re(r);for(const l of z(i)){const a=U.find(f=>H[f]===l);l==="schemaVersion"?i[l]!==1&&u(n,l,`Unsupported schemaVersion ${c(i[l])}`):l==="message"?typeof i[l]!="string"&&u(n,l,`Expected text, got ${c(i[l])}`):a?s.includes(a)?rt(n,a,i[l],l,o):u(n,l,"Part not allowed"):u(n,l,"Unknown part")}}catch{return u(n,"","Could not read the input"),{state:{},errors:n.errors}}return{state:o,errors:n.errors}}const j="```";function V(){return typeof DOMException=="function"?new DOMException("The operation was aborted.","AbortError"):Object.assign(new Error("The operation was aborted."),{name:"AbortError"})}function it(e){const t=e.trim();if(t.startsWith("{"))return{json:t,message:""};const r=e.indexOf(j),n=r<0?-1:e.indexOf(`
|
|
2
|
+
`,r+j.length),o=n<0?-1:e.indexOf(j,n+1),i=o<0?"":e.slice(r+j.length,n).trim().toLowerCase();return o<0||i!==""&&i!=="json"?{json:null,message:t}:{json:e.slice(n+1,o),message:`${e.slice(0,r)}${e.slice(o+j.length)}`.trim()}}function ot(e){return e instanceof Error&&e.message?e.message:typeof e=="string"&&e?e:"Unknown error"}function ce(e,t){const r={state:I({}),errors:e};return t&&(r.message=t),I(r)}function st(e,t,r){let n=e,o="";if(typeof e=="string"){const a=it(e);if(a.json===null)return ce([],a.message||void 0);o=a.message;try{n=JSON.parse(a.json)}catch{n=a.json}}const i=$(n)&&S(n,"message")&&typeof n.message=="string"?n.message.trim():"",s=[o,i].filter(Boolean).join(`
|
|
3
3
|
|
|
4
|
-
`),l=
|
|
4
|
+
`),l=K(n,t,r);return s&&(l.message=s),l}function lt(e){const{columns:t,callModel:r,parts:n,schemaOptions:o={}}=e,i={include:n??o.include,exclude:o.exclude},s=Y(t,{...o,...i});return async(l,a)=>{const f=a?.signal??new AbortController().signal;if(f.aborted)throw V();const v=new Promise((m,y)=>{f.addEventListener("abort",()=>y(V()),{once:!0})});v.catch(()=>{});let g;try{const m={prompt:String(l),schema:s,currentState:a?.currentState??{},history:Array.isArray(a?.history)?a.history:[]};g=await Promise.race([r(m,{signal:f}),v])}catch(m){if(f.aborted)throw V();return ce([{path:"",message:`The model call failed: ${ot(m)}`}])}if(f.aborted)throw V();return st(g,t,i)}}const at=20,ut=1e3,ft=[{name:"set_filter",part:"filter",description:"Replace the filter model of the grid (filters and quick-filter words)."},{name:"set_sort",part:"sort",description:"Replace the sort model of the grid, most significant field first. An empty list clears sorting."},{name:"set_grouping",part:"grouping",description:"Group the rows by these fields, outermost first. An empty list removes grouping."},{name:"set_aggregation",part:"aggregation",description:"Replace the summaries: field to aggregation function. An empty object removes them."},{name:"set_column_visibility",part:"columnVisibility",description:"Show (true) or hide (false) columns. Columns not listed keep their visibility."}];function w(e,t=""){return{ok:!1,errors:[{path:t,message:e}]}}async function D(e){try{return e()}catch(t){return w(t instanceof Error&&t.message?t.message:"The tool failed")}}function P(e){const t=e?.current;return t&&typeof t.getGridAiState=="function"?t:null}function ct(e){return e instanceof Date?Number.isNaN(e.getTime())?null:e.toISOString():typeof e=="number"?Number.isFinite(e)?e:null:typeof e=="string"||typeof e=="boolean"?e:null}function dt(e,t,r,n,o){const i=H[n],s=Y(t,{include:[n]});if(!S(s.properties,i))return null;const{$schema:l,schemaVersion:a,title:f,description:v,...g}=s;return{name:r,description:o,inputSchema:{...g,required:[i]},execute:m=>D(()=>{const y=P(e);if(!y)return w("The grid is not ready");if(!$(m)||!S(m,i))return w(`Expected an object with "${i}"`,i);const{state:d,errors:M}=K({[i]:m[i]},t,{include:[n]});if(M.length>0)return{ok:!1,errors:M};const b={};return d.filterModel&&y.setFilterModel(b.filterModel=d.filterModel),d.sortModel&&y.setSortModel(b.sortModel=d.sortModel),d.rowGroupingModel&&y.setRowGroupingModel(b.rowGroupingModel=d.rowGroupingModel),d.aggregationModel&&y.setAggregationModel(b.aggregationModel=d.aggregationModel),d.columnVisibilityModel&&(b.columnVisibilityModel={...y.getGridAiState().columnVisibilityModel,...d.columnVisibilityModel},y.setColumnVisibilityModel(b.columnVisibilityModel)),{ok:!0,applied:b}})}}const x={type:"object",properties:{},additionalProperties:!1};function pt(e,t,r={}){const n=J(t),o=[{name:"get_grid_state",description:"Read the current filter, sort, grouping, aggregation, pivot and column visibility of the grid, and its columns.",inputSchema:x,execute:()=>D(()=>{const i=P(e);return i?{ok:!0,state:i.getGridAiState(),columns:n.map(s=>({field:s.field,headerName:typeof s.headerName=="string"?s.headerName:s.field,type:typeof s.type=="string"?s.type:"string"}))}:w("The grid is not ready")})}];for(const{name:i,part:s,description:l}of ft){const a=dt(e,n,i,s,l);a&&o.push(a)}if(o.push({name:"clear_filters",description:"Remove every filter and the quick-filter words.",inputSchema:x,execute:()=>D(()=>{const i=P(e);if(!i)return w("The grid is not ready");const s={items:[]};return i.setFilterModel(s),{ok:!0,applied:{filterModel:s}}})}),r.allowRowAccess===!0){const i=typeof r.maxRows=="number"&&r.maxRows>=1?Math.min(Math.floor(r.maxRows),ut):at,s=Array.isArray(r.fields)?n.filter(l=>r.fields?.includes(l.field)):n;o.push({name:"get_row_summary",description:`Count the rows that pass the current filter and read the first ones (at most ${i}, fields: ${s.map(l=>l.field).join(", ")}).`,inputSchema:{type:"object",properties:{limit:{type:"integer",minimum:1,maximum:i}},additionalProperties:!1},execute:l=>D(()=>{const a=P(e);if(!a)return w("The grid is not ready");const f=$(l)&&S(l,"limit")?l.limit:i,v=typeof f=="number"&&f>=1?Math.min(Math.floor(f),i):i,g=a.getAllFilteredRows(),m=Array.isArray(g)?g:[],y=m.slice(0,v).map(d=>{const M={};if(!$(d))return M;for(const b of s)M[b.field]=ct(me(d,b.field,b));return M});return{ok:!0,rowCount:m.length,rows:y}})})}return o}exports.createGridAgentTools=pt,exports.createGridAiPromptHandler=lt,exports.getGridAiSchema=Y,exports.validateGridAiState=K;
|