@object-ui/plugin-grid 4.0.5 → 4.0.6
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 +27 -0
- package/dist/index.js +3 -2
- package/dist/index.umd.cjs +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @object-ui/plugin-grid
|
|
2
2
|
|
|
3
|
+
## 4.0.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 89ae109: Fix click navigation and required-FK form rendering
|
|
8
|
+
- **plugin-grid**: ObjectGrid's `getSelectFields()` now always includes `id` in
|
|
9
|
+
the SELECT projection. Previously, when a view configured `columns` without
|
|
10
|
+
`id`, the SQL driver stripped it from results, and row-click handlers silently
|
|
11
|
+
no-oped because `record.id` was undefined.
|
|
12
|
+
- **plugin-form / fields**: Master-detail fields now render as a single-value
|
|
13
|
+
lookup picker (`LookupField`) in create/edit forms instead of a one-to-many
|
|
14
|
+
related-list widget. From the child-side, master-detail is the FK to the
|
|
15
|
+
parent record and is typically NOT NULL — it must appear in forms. Prior
|
|
16
|
+
behavior dropped it via the auto-layout exclusion list, which caused server
|
|
17
|
+
errors like "NOT NULL constraint failed: contact.account" when users tried
|
|
18
|
+
to create child records.
|
|
19
|
+
|
|
20
|
+
- Updated dependencies [89ae109]
|
|
21
|
+
- Updated dependencies [925051d]
|
|
22
|
+
- Updated dependencies [1b6dc64]
|
|
23
|
+
- @object-ui/fields@4.0.6
|
|
24
|
+
- @object-ui/components@4.0.6
|
|
25
|
+
- @object-ui/types@4.0.6
|
|
26
|
+
- @object-ui/core@4.0.6
|
|
27
|
+
- @object-ui/react@4.0.6
|
|
28
|
+
- @object-ui/mobile@4.0.6
|
|
29
|
+
|
|
3
30
|
## 4.0.5
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -459,8 +459,9 @@ var it = ({ schema: r, dataSource: i, onEdit: o, onDelete: p, onRowSelect: h, on
|
|
|
459
459
|
if (e || M(t), i && q) {
|
|
460
460
|
let n = {
|
|
461
461
|
$select: (() => {
|
|
462
|
-
|
|
463
|
-
if (
|
|
462
|
+
let e = (e) => e.map((e) => typeof e == "string" ? e : e?.name || e?.field).includes("id") ? e : ["id", ...e];
|
|
463
|
+
if (J) return e(J);
|
|
464
|
+
if (Y && Array.isArray(Y)) return e(Y.map((e) => typeof e == "string" ? e : e.field));
|
|
464
465
|
})(),
|
|
465
466
|
$top: We?.pageSize || qe || 50
|
|
466
467
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`react`),require(`@object-ui/core`),require(`@object-ui/react`),require(`@object-ui/fields`),require(`@object-ui/components`),require(`@object-ui/mobile`),require(`lucide-react`),require(`react/jsx-runtime`),require(`@tanstack/react-virtual`)):typeof define==`function`&&define.amd?define([`exports`,`react`,`@object-ui/core`,`@object-ui/react`,`@object-ui/fields`,`@object-ui/components`,`@object-ui/mobile`,`lucide-react`,`react/jsx-runtime`,`@tanstack/react-virtual`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginGrid={},e.React,e._object_ui_core,e._object_ui_react,e._object_ui_fields,e._object_ui_components,e._object_ui_mobile,e.lucide_react,e.react_jsx_runtime,e._tanstack_react_virtual))})(this,function(e,t,n,r,i,a,o,s,c,l){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var u=Object.create,d=Object.defineProperty,f=Object.getOwnPropertyDescriptor,p=Object.getOwnPropertyNames,m=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty,g=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=p(t),a=0,o=i.length,s;a<o;a++)s=i[a],!h.call(e,s)&&s!==n&&d(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=f(t,s))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:u(m(e)),g(t||!e||!e.__esModule?d(n,`default`,{value:e,enumerable:!0}):n,e)))(t,1);var _={red:`bg-red-100`,green:`bg-green-100`,blue:`bg-blue-100`,yellow:`bg-yellow-100`,orange:`bg-orange-100`,purple:`bg-purple-100`,pink:`bg-pink-100`,gray:`bg-gray-100`,grey:`bg-gray-100`,indigo:`bg-indigo-100`,teal:`bg-teal-100`,cyan:`bg-cyan-100`,amber:`bg-amber-100`,lime:`bg-lime-100`,emerald:`bg-emerald-100`,rose:`bg-rose-100`,sky:`bg-sky-100`,violet:`bg-violet-100`,fuchsia:`bg-fuchsia-100`,slate:`bg-slate-100`,zinc:`bg-zinc-100`,stone:`bg-stone-100`,neutral:`bg-neutral-100`};function v(e){return e.startsWith(`bg-`)?e:_[e.toLowerCase().trim()]}function y(e){return(0,t.useCallback)(t=>{if(!e?.field||!e.colors)return;let n=String(t[e.field]??``),r=e.colors[n];if(r)return v(r)},[e?.field,e?.colors])}function b(e){if(e==null||e===``)return``;if(Array.isArray(e))return e.map(e=>b(e)).join(`|`);if(typeof e==`object`){let t=e.id??e._id??e.pk??e.value;if(t!=null&&t!==``)return String(t);let n=e.name??e.label??e.title;if(n!=null&&n!==``)return String(n);try{return JSON.stringify(e)}catch{return``}}return String(e)}function x(e,t){return b(e[t])}function S(e,t,n){if(e==null||e===``)return`(empty)`;if(n){let r=n(t,e);if(r!==void 0&&r!==``)return r}if(Array.isArray(e))return e.map(e=>{if(n){let r=n(t,e);if(r!==void 0&&r!==``)return r}return S(e,t)}).join(`, `)||`(empty)`;if(typeof e==`object`){let t=e.name??e.label??e.title??e.display_name??e.displayName??e.fullName??e.full_name;if(t!=null&&t!==``)return String(t);let n=e.id??e._id??e.pk;return n!=null&&n!==``?String(n):`(empty)`}return String(e)}function C(e,t){return t.map(({field:t,type:n})=>{let r=e.map(e=>Number(e[t])).filter(e=>Number.isFinite(e)),i;switch(n){case`count`:i=r.length;break;case`sum`:i=r.reduce((e,t)=>e+t,0);break;case`avg`:i=r.length>0?r.reduce((e,t)=>e+t,0)/r.length:0;break;case`min`:i=r.length>0?Math.min(...r):0;break;case`max`:i=r.length>0?Math.max(...r):0;break;default:i=0}return{field:t,type:n,value:i}})}function w(e,t,n){let r=e.localeCompare(t,void 0,{numeric:!0,sensitivity:`base`});return n===`desc`?-r:r}function T(e,n,r,i){let a=e?.fields,o=!!(a&&a.length>0),[s,c]=(0,t.useState)({});return{groups:(0,t.useMemo)(()=>{if(!o||!a)return[];let e=(t,n,o)=>{if(n>=a.length)return[];let c=a[n],l=new Map,u=[];for(let e of t){let t=x(e,c.field);l.has(t)||(l.set(t,{label:S(e[c.field],c.field,i),rows:[]}),u.push(t)),l.get(t).rows.push(e)}let d=c.order??`asc`;return u.sort((e,t)=>w(l.get(e)?.label??e,l.get(t)?.label??t,d)),u.map(t=>{let i=l.get(t),u=o?`${o}__${n}:${t}`:`${n}:${t}`,d=!!c.collapsed,f=u in s?s[u]:d,p=r&&r.length>0?C(i.rows,r):[],m=n+1<a.length?e(i.rows,n+1,u):[];return{key:u,label:i.label,field:c.field,depth:n,rows:i.rows,collapsed:f,aggregations:p,subgroups:m}})};return e(n,0,``)},[n,a,o,s,r,i]),isGrouped:o,toggleGroup:(0,t.useCallback)(e=>{c(t=>{let n=e.split(`__`).pop()||``,r=/^(\d+):/.exec(n),i=r?Number(r[1]):0,o=!!a?.[i]?.collapsed;return{...t,[e]:t[e]===void 0?!o:!t[e]}})},[a])}}var E=({groupKey:e,label:t,count:n,collapsed:r,aggregations:i,onToggle:a,children:o})=>(0,c.jsxs)(`div`,{className:`border rounded-md`,"data-testid":`group-row-${e}`,children:[(0,c.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 px-3 py-2 text-sm font-medium text-left bg-muted/50 hover:bg-muted transition-colors`,onClick:()=>a(e),"aria-expanded":!r,children:[r?(0,c.jsx)(s.ChevronRight,{className:`h-4 w-4 shrink-0`}):(0,c.jsx)(s.ChevronDown,{className:`h-4 w-4 shrink-0`}),(0,c.jsx)(`span`,{className:`group-label`,children:t}),i&&i.length>0&&(0,c.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground group-aggregations`,children:i.map(e=>(0,c.jsxs)(`span`,{className:`mr-2`,children:[e.type,`: `,Number.isInteger(e.value)?e.value:e.value.toFixed(2)]},`${e.field}-${e.type}`))}),(0,c.jsxs)(`span`,{className:`ml-auto text-xs text-muted-foreground group-count`,children:[`(`,n,`)`]})]}),!r&&o]});function D(e){return typeof e==`string`?{type:e}:e}function O(e,t){if(t.length===0)return null;switch(e){case`count`:return t.length;case`sum`:return t.reduce((e,t)=>e+t,0);case`avg`:return t.reduce((e,t)=>e+t,0)/t.length;case`min`:return Math.min(...t);case`max`:return Math.max(...t);default:return null}}function k(e,t){return t===null?``:`${{count:`Count`,sum:`Sum`,avg:`Avg`,min:`Min`,max:`Max`}[e]||e}: ${e===`avg`?t.toLocaleString(void 0,{maximumFractionDigits:2}):t.toLocaleString()}`}function A(e,n){return(0,t.useMemo)(()=>{let t=new Map;if(!e||e.length===0||n.length===0)return{summaries:t,hasSummary:!1};for(let r of e){if(!r.summary)continue;let e=D(r.summary),i=e.field||r.field,a=[];for(let e of n){let t=e[i];if(t!=null&&typeof t==`number`&&!isNaN(t))a.push(t);else if(t!=null&&typeof t==`string`){let e=parseFloat(t);isNaN(e)||a.push(e)}}let o;if(e.type===`count`){let e=n.filter(e=>e[i]!=null&&e[i]!==``).length;o=e>0?e:null}else o=O(e.type,a);t.set(r.field,{field:r.field,value:o,label:k(e.type,o)})}return{summaries:t,hasSummary:t.size>0}},[e,n])}function j(e){return e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}var M=({row:e,rowActions:t,canEdit:n,canDelete:r,onEdit:i,onDelete:o,onAction:l})=>(0,c.jsxs)(a.DropdownMenu,{children:[(0,c.jsx)(a.DropdownMenuTrigger,{asChild:!0,children:(0,c.jsxs)(a.Button,{variant:`ghost`,size:`icon`,className:`h-8 w-8 min-h-[44px] min-w-[44px] sm:min-h-0 sm:min-w-0`,"data-testid":`row-action-trigger`,children:[(0,c.jsx)(s.MoreVertical,{className:`h-4 w-4`}),(0,c.jsx)(`span`,{className:`sr-only`,children:`Open menu`})]})}),(0,c.jsxs)(a.DropdownMenuContent,{align:`end`,children:[n&&i&&(0,c.jsxs)(a.DropdownMenuItem,{onClick:()=>i(e),children:[(0,c.jsx)(s.Edit,{className:`mr-2 h-4 w-4`}),`Edit`]}),r&&o&&(0,c.jsxs)(a.DropdownMenuItem,{onClick:()=>o(e),children:[(0,c.jsx)(s.Trash2,{className:`mr-2 h-4 w-4`}),`Delete`]}),t?.map(t=>(0,c.jsx)(a.DropdownMenuItem,{onClick:()=>l?.(t,e),"data-testid":`row-action-${t}`,children:j(t)},t))]})]}),N=({selectedRows:e,actions:t,onAction:n,onClearSelection:r})=>!t||t.length===0||e.length===0?null:(0,c.jsxs)(`div`,{className:`border-t px-4 py-1.5 flex items-center gap-2 text-xs bg-primary/5 shrink-0`,"data-testid":`bulk-actions-bar`,children:[(0,c.jsxs)(`span`,{className:`text-muted-foreground font-medium`,children:[e.length,` selected`]}),(0,c.jsx)(`div`,{className:`flex items-center gap-1 ml-2`,children:t.map(t=>(0,c.jsx)(a.Button,{variant:`outline`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:()=>n?.(t,e),"data-testid":`bulk-action-${t}`,children:j(t)},t))}),(0,c.jsx)(a.Button,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs ml-auto`,onClick:r,children:`Clear`})]}),P={"grid.actions":`Actions`,"grid.edit":`Edit`,"grid.delete":`Delete`,"grid.export":`Export`,"grid.exportAs":`Export as {{format}}`,"grid.loading":`Loading grid...`,"grid.errorLoading":`Error loading grid`,"grid.pullToRefresh":`Pull to refresh`,"grid.refreshing":`Refreshing…`,"grid.openRecord":`Open record`};function ee(){try{let e=(0,r.useObjectTranslation)();return e.t(`grid.actions`)===`grid.actions`?{t:(e,t)=>{let n=P[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n}}:{t:e.t}}catch{return{t:(e,t)=>{let n=P[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n}}}}function F(e){if(e!=null)return typeof e==`string`?e:void 0}function I(e){return e.data?Array.isArray(e.data)?{provider:`value`,items:e.data}:e.data:e.staticData?{provider:`value`,items:e.staticData}:e.objectName?{provider:`object`,object:e.objectName}:null}function L(e){if(!(!e||e.length===0))return typeof e[0]==`object`&&e[0],e}var R=({schema:e,dataSource:l,onEdit:u,onDelete:d,onRowSelect:f,onRowClick:p,onCellChange:m,onRowSave:h,onBatchSave:g,onAddRecord:_,...v})=>{let[b,x]=(0,t.useState)([]),[S,C]=(0,t.useState)(!0),[w,D]=(0,t.useState)(null),{t:O}=ee(),{fieldLabel:k,translateOptions:P}=(0,r.useSafeFieldLabel)(),[R,te]=(0,t.useState)(null),[ne,re]=(0,t.useState)(!1),[ie,ae]=(0,t.useState)(0),[oe,z]=(0,t.useState)(!1),[se,ce]=(0,t.useState)(!1),B=(0,a.useExportJob)({dataSource:l}),[V,le]=(0,t.useState)(e.rowHeight??`compact`),[ue,de]=(0,t.useState)([]),fe=t.default.useMemo(()=>e.id?`grid-columns-${e.objectName}-${e.id}`:`grid-columns-${e.objectName}`,[e.objectName,e.id]),[H,U]=(0,t.useState)(()=>{try{let e=localStorage.getItem(fe);return e?JSON.parse(e):{}}catch{return{}}}),pe=(0,t.useCallback)(e=>{U(e);try{localStorage.setItem(fe,JSON.stringify(e))}catch(e){console.warn(`Failed to persist column state:`,e)}},[fe]),{ref:me,isRefreshing:he,pullDistance:ge}=(0,o.usePullToRefresh)({onRefresh:(0,t.useCallback)(async()=>{ae(e=>e+1)},[]),enabled:!!l&&!!e.objectName});(0,t.useEffect)(()=>{let e=()=>re(window.innerWidth<480);return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]);let W=v.data,G=(0,r.useDataScope)(e.bind),_e=I(e),K=t.default.useMemo(()=>W&&Array.isArray(W)?{provider:`value`,items:W}:G&&Array.isArray(G)?{provider:`value`,items:G}:_e,[JSON.stringify(_e),G,W]),q=K?.provider===`value`,J=K?.provider===`object`&&K&&`object`in K?K.object:e.objectName,Y=e.fields,X=e.columns,ve=e.filter,Z=e.sort,ye=e.pagination,be=e.pageSize;(0,t.useEffect)(()=>{q&&K?.provider===`value`&&(x(e=>{let t=K.items;return JSON.stringify(e)===JSON.stringify(t)?e:t}),C(!1))},[q,K]),(0,t.useEffect)(()=>{if(!q||!J||!l)return;let e=!1;return(async()=>{try{if(typeof l.getObjectSchema!=`function`)return;let t=await l.getObjectSchema(J);e||te(t)}catch(e){console.warn(`[ObjectGrid] Failed to fetch objectSchema for inline data (objectName: ${J}):`,e)}})(),()=>{e=!0}},[q,J,l]),(0,t.useEffect)(()=>{if(q)return;let t=!1;return(async()=>{C(!0),D(null);try{let r=null,i=L(X)||Y;if(J&&l)if(typeof l.getObjectSchema==`function`){let e=await l.getObjectSchema(J);if(t)return;r=e}else r={name:J,fields:{}};else if(i&&J)r={name:J,fields:{}};else if(J)throw Error(`DataSource required`);else throw Error(`Object name required for data fetching`);if(t||te(r),l&&J){let i={$select:(()=>{if(Y)return Y;if(X&&Array.isArray(X))return X.map(e=>typeof e==`string`?e:e.field)})(),$top:ye?.pageSize||be||50};ve&&Array.isArray(ve)?i.$filter=ve:e.defaultFilters&&(i.$filter=e.defaultFilters),Z?typeof Z==`string`?i.$orderby=Z:Array.isArray(Z)&&(i.$orderby=Z.map(e=>`${e.field} ${e.order}`).join(`, `)):e.defaultSort&&(i.$orderby=`${e.defaultSort.field} ${e.defaultSort.order}`);let a=(0,n.buildExpandFields)(r?.fields,X??Y);a.length>0&&(i.$expand=a);let o=await l.find(J,i);if(t)return;x(o.data||[])}}catch(e){t||D(e)}finally{t||C(!1)}})(),()=>{t=!0}},[J,Y,X,ve,Z,ye,be,l,q,K,ie]);let Q=(0,r.useNavigationOverlay)({navigation:e.navigation,objectName:e.objectName,onNavigate:e.onNavigate,onRowClick:p}),{execute:xe}=(0,r.useAction)(),Se=y(e.rowColor),Ce=(0,t.useCallback)(t=>{let r=e.conditionalFormatting;if(!(!r||r.length===0))for(let e of r){let r=!1,i=(`condition`in e?e.condition:void 0)||(`expression`in e?e.expression:void 0)||void 0;if(i)r=(0,n.evaluatePlainCondition)(i,t);else if(`field`in e&&`operator`in e&&e.field&&e.operator){let n=e,i=t[n.field];switch(n.operator){case`equals`:r=i===n.value;break;case`not_equals`:r=i!==n.value;break;case`contains`:r=typeof i==`string`&&typeof n.value==`string`&&i.includes(n.value);break;case`greater_than`:r=typeof i==`number`&&typeof n.value==`number`&&i>n.value;break;case`less_than`:r=typeof i==`number`&&typeof n.value==`number`&&i<n.value;break;case`in`:r=Array.isArray(n.value)&&n.value.includes(i);break}}if(r){let t={};return`style`in e&&e.style&&Object.assign(t,e.style),`backgroundColor`in e&&e.backgroundColor&&(t.backgroundColor=e.backgroundColor),`textColor`in e&&e.textColor&&(t.color=e.textColor),`borderColor`in e&&e.borderColor&&(t.borderColor=e.borderColor),t}}},[e.conditionalFormatting]),we=t.default.useMemo(()=>{let t=e.grouping;if(!t?.fields?.length)return;let n=new Map;for(let r of t.fields){let t=r.field,i=R?.fields?.[t],a=L(e.columns)?.find?.(e=>typeof e==`object`&&e?.field===t),o=a?.type||i?.type,s=a?.options||i?.options,c=new Map;if(Array.isArray(s)&&s.length>0){let n=e.objectName?P(e.objectName,t,s):s;for(let e of n)if(e&&e.value!==void 0&&e.value!==null){let t=e.label;c.set(String(e.value),String(t??e.value))}}n.set(t,{type:o||void 0,options:c.size>0?c:void 0})}return(e,t)=>{let r=n.get(e);if(r){if(r.options){let e=r.options.get(String(t));if(e!==void 0)return e}if(r.type===`boolean`||typeof t==`boolean`){if(t===!0||t===`true`)return O(`grid.booleanTrue`,`Yes`);if(t===!1||t===`false`)return O(`grid.booleanFalse`,`No`)}}}},[e.grouping,e.columns,e.objectName,R,P,O]),{groups:Te,isGrouped:Ee,toggleGroup:De}=T(e.grouping,b,void 0,we),{summaries:Oe,hasSummary:ke}=A(t.default.useMemo(()=>{let t=L(e.columns);if(t&&t.length>0&&typeof t[0]==`object`)return t},[e.columns]),b),Ae=(0,t.useCallback)(()=>{let t=e=>e&&{text:(0,c.jsx)(s.Type,{className:`h-3.5 w-3.5`}),number:(0,c.jsx)(s.Hash,{className:`h-3.5 w-3.5`}),currency:(0,c.jsx)(s.Hash,{className:`h-3.5 w-3.5`}),percent:(0,c.jsx)(s.Hash,{className:`h-3.5 w-3.5`}),date:(0,c.jsx)(s.Calendar,{className:`h-3.5 w-3.5`}),datetime:(0,c.jsx)(s.Clock,{className:`h-3.5 w-3.5`}),boolean:(0,c.jsx)(s.CheckSquare,{className:`h-3.5 w-3.5`}),user:(0,c.jsx)(s.User,{className:`h-3.5 w-3.5`}),select:(0,c.jsx)(s.Tag,{className:`h-3.5 w-3.5`})}[e]||(0,c.jsx)(s.Type,{className:`h-3.5 w-3.5`}),n=e=>{if(e.type)return e.type;let t=e.field.toLowerCase();if([`completed`,`is_completed`,`done`,`active`,`enabled`,`archived`].some(e=>t===e||t===`is_${e}`))return`boolean`;if([`created_time`,`modified_time`,`updated_time`,`created_at`,`updated_at`,`modified_at`,`last_login`,`logged_at`].some(e=>t===e||t.endsWith(`_${e}`)))return`datetime`;if([`date`,`due`,`created`,`updated`,`deadline`,`start`,`end`,`expires`].some(e=>t.includes(e))){if(b.length>0){let t=b.find(t=>t[e.field]!=null)?.[e.field];if(typeof t==`string`&&!isNaN(Date.parse(t)))return`date`}return`date`}if([`probability`,`percent`,`percentage`,`completion`,`progress`,`rate`].some(e=>t.includes(e))&&b.length>0&&typeof b.find(t=>t[e.field]!=null)?.[e.field]==`number`)return`percent`;if([`status`,`priority`,`category`,`stage`,`type`,`severity`,`level`].some(e=>t.includes(e))&&b.length>0){let t=new Set(b.map(t=>t[e.field]).filter(Boolean));if(t.size>0&&t.size<=10)return`select`}if([`assignee`,`owner`,`author`,`reporter`,`creator`,`user`].some(e=>t.includes(e)))return`user`;if([`amount`,`price`,`total`,`revenue`,`cost`,`budget`,`salary`].some(e=>t.includes(e))&&b.length>0&&typeof b.find(t=>t[e.field]!=null)?.[e.field]==`number`)return`currency`;if(b.length>0){let t=b.find(t=>t[e.field]!=null)?.[e.field];if(typeof t==`string`&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(t))return`datetime`}return null},r=L(X);if(r){if(r.length>0&&typeof r[0]==`object`&&r[0]!==null){let o=r[0];if(`accessorKey`in o)return r.map(r=>{if(r.cell)return r;let a=n({field:r.accessorKey,label:r.header,type:r.type});if(!a)return r;let o=(0,i.getCellRenderer)(a),s={name:r.accessorKey,type:a};return a===`select`&&(s.options=Array.from(new Set(b.map(e=>e[r.accessorKey]).filter(Boolean))).map(e=>({value:e,label:(0,i.humanizeLabel)(String(e))}))),{...r,...e.showColumnTypeIcons&&{headerIcon:t(a)},cell:e=>(0,c.jsx)(o,{value:e,field:s})}});if(`field`in o)return r.filter(e=>e?.field&&typeof e.field==`string`&&!e.hidden).map((r,o)=>{let s=F(r.label)||r.field.charAt(0).toUpperCase()+r.field.slice(1).replace(/_/g,` `),l=e.objectName?k(e.objectName,r.field,s):s,u,d=R?.fields?.[r.field],f=r.type||d?.type||n({field:r.field})||null,p=f?(0,i.getCellRenderer)(f):null,m={name:r.field,type:f||`text`};d&&(d.label&&(m.label=d.label),d.currency&&(m.currency=d.currency),d.precision!==void 0&&(m.precision=d.precision),d.format&&(m.format=d.format),d.options&&(m.options=P(e.objectName,r.field,d.options))),f===`select`&&!m.options&&(m.options=Array.from(new Set(b.map(e=>e[r.field]).filter(Boolean))).map(e=>({value:e,label:(0,i.humanizeLabel)(String(e))}))),r.options&&(m.options=P(e.objectName,r.field,r.options));let h=o===0&&!r.link&&!r.action,g=r.link||h;u=r.link&&r.action||h&&r.action||g?(e,t)=>(0,c.jsx)(`button`,{type:`button`,className:`text-primary font-medium underline-offset-4 hover:underline cursor-pointer bg-transparent border-none p-0 text-left font-inherit`,"data-testid":h?`primary-field-link`:`link-cell`,onClick:e=>{e.stopPropagation(),Q.handleClick(t)},children:p?(0,c.jsx)(p,{value:e,field:m}):e!=null&&e!==``?String(e):(0,c.jsx)(`span`,{className:`text-muted-foreground/50 text-xs italic`,children:`—`})}):r.action?(e,t)=>(0,c.jsx)(a.Button,{variant:`outline`,size:`sm`,className:`h-7 text-xs`,"data-testid":`action-cell`,onClick:n=>{n.stopPropagation(),xe({type:r.action,params:{record:t,field:r.field,value:e}})},children:j(r.action)}):p?e=>(0,c.jsx)(p,{value:e,field:m}):e=>e!=null&&e!==``?(0,c.jsx)(`span`,{children:String(e)}):(0,c.jsx)(a.EmptyValue,{});let _=r.prefix;if(_?.field){let e=u,t=_.type===`badge`?(0,i.getCellRenderer)(`select`):null;u=(n,r)=>{let i=r[_.field];return(0,c.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[i!=null&&i!==``?t?(0,c.jsx)(t,{value:i,field:{name:_.field,type:`select`}}):(0,c.jsx)(`span`,{className:`text-muted-foreground text-xs mr-1.5`,children:String(i)}):null,e(n,r)]})}}let v=[`number`,`currency`,`percent`],y=f||r.type,x=r.align||(y&&v.includes(y)?`right`:void 0),S=o===0||r.essential===!0;return{header:l,accessorKey:r.field,...e.showColumnTypeIcons&&{headerIcon:t(f)},...!S&&{className:`hidden sm:table-cell`},...r.width&&{width:r.width},...x&&{align:x},sortable:r.sortable!==!1,...r.resizable!==void 0&&{resizable:r.resizable},...r.wrap!==void 0&&{wrap:r.wrap},...u&&{cell:u},...r.pinned&&{pinned:r.pinned}}})}return r.filter(e=>typeof e==`string`&&e.trim().length>0).map((r,a)=>{let o=R?.fields?.[r],s=o?.label||r.charAt(0).toUpperCase()+r.slice(1).replace(/_/g,` `),l=e.objectName?k(e.objectName,r,s):s,u=o?.type||n({field:r})||null,d=u?(0,i.getCellRenderer)(u):null,f={name:r,type:u||`text`};o&&(o.label&&(f.label=o.label),o.currency&&(f.currency=o.currency),o.precision!==void 0&&(f.precision=o.precision),o.format&&(f.format=o.format),o.options&&(f.options=P(e.objectName,r,o.options))),u===`select`&&!f.options&&(f.options=Array.from(new Set(b.map(e=>e[r]).filter(Boolean))).map(e=>({value:e,label:(0,i.humanizeLabel)(String(e))})));let p=u&&[`number`,`currency`,`percent`].includes(u)?`right`:void 0,m=a===0,h;return m&&d?h=(e,t)=>(0,c.jsx)(`button`,{type:`button`,className:`text-primary font-medium underline-offset-4 hover:underline cursor-pointer bg-transparent border-none p-0 text-left font-inherit`,"data-testid":`primary-field-link`,onClick:e=>{e.stopPropagation(),Q.handleClick(t)},children:(0,c.jsx)(d,{value:e,field:f})}):m?h=(e,t)=>(0,c.jsx)(`button`,{type:`button`,className:`text-primary font-medium underline-offset-4 hover:underline cursor-pointer bg-transparent border-none p-0 text-left font-inherit`,"data-testid":`primary-field-link`,onClick:e=>{e.stopPropagation(),Q.handleClick(t)},children:e!=null&&e!==``?String(e):(0,c.jsx)(`span`,{className:`text-muted-foreground/50 text-xs italic`,children:`—`})}):d&&(h=e=>(0,c.jsx)(d,{value:e,field:f})),{header:l,accessorKey:r,...e.showColumnTypeIcons&&u&&{headerIcon:t(u)},...p&&{align:p},...h&&{cell:h},sortable:o?.sortable!==!1}})}if(q){let r=K?.provider===`value`?K.items:[];if(r.length>0)return(Y||Object.keys(r[0])).map(r=>{let a=R?.fields?.[r],o=a?.type||n({field:r})||null,s=o?(0,i.getCellRenderer)(o):null,l=a?.label||r.charAt(0).toUpperCase()+r.slice(1).replace(/_/g,` `),u={name:r,type:o||`text`};a&&(a.label&&(u.label=a.label),a.currency&&(u.currency=a.currency),a.precision!==void 0&&(u.precision=a.precision),a.format&&(u.format=a.format),a.options&&(u.options=P(e.objectName,r,a.options))),o===`select`&&!u.options&&(u.options=Array.from(new Set(b.map(e=>e[r]).filter(Boolean))).map(e=>({value:e,label:(0,i.humanizeLabel)(String(e))})));let d=o&&[`number`,`currency`,`percent`].includes(o)?`right`:void 0;return{header:l,accessorKey:r,...e.showColumnTypeIcons&&o&&{headerIcon:t(o)},...d&&{align:d},...s&&{cell:e=>(0,c.jsx)(s,{value:e,field:u})},sortable:a?.sortable!==!1}})}if(!R)return[];let o=[],l=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`_version`,`_rev`]),u=R?.compactLayout,d=Object.keys(R.fields||{}),f;if(Y)f=Y;else if(u?.length)f=u.filter(e=>R.fields?.[e]);else{let e=d.filter(e=>{let t=R.fields?.[e];return!(!t||t.hidden||t.readonly&&l.has(e))});f=[...e.filter(e=>!l.has(e)),...e.filter(e=>l.has(e))]}return f.forEach(t=>{let n=R.fields?.[t];if(!n||n.permissions&&n.permissions.read===!1)return;let r=(0,i.getCellRenderer)(n.type),a=[`number`,`currency`,`percent`],s=n.options?{...n,options:P(e.objectName,t,n.options)}:n;o.push({header:e.objectName?k(e.objectName,t,n.label||t):n.label||t,accessorKey:t,...a.includes(n.type)&&{align:`right`},cell:e=>(0,c.jsx)(r,{value:e,field:s}),sortable:n.sortable!==!1})}),o},[R,Y,X,K,q,Q.handleClick,xe,b,k,P,e.objectName]),je=(0,t.useCallback)(t=>{let n=e.exportOptions,r=n?.maxRecords||0,i=n?.includeHeaders!==!1,a=n?.fileNamePrefix||e.objectName||`export`;if((t===`csv`||t===`xlsx`||t===`json`)&&B.isSupported&&e.objectName&&!q&&n?.streaming!==!1){let n=Ae().filter(e=>e.accessorKey!==`_actions`).map(e=>e.accessorKey).filter(Boolean);z(!1),ce(!0),B.start(e.objectName,{format:t===`json`?`json`:t,fields:n.length?n:void 0,includeHeaders:i,limit:r>0?r:void 0});return}let o=r>0?b.slice(0,r):b,s=(e,t)=>{let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,r.click(),URL.revokeObjectURL(n)},c=e=>{let t=e==null?``:String(e);return t.includes(`,`)||t.includes(`"`)||t.includes(`
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`react`),require(`@object-ui/core`),require(`@object-ui/react`),require(`@object-ui/fields`),require(`@object-ui/components`),require(`@object-ui/mobile`),require(`lucide-react`),require(`react/jsx-runtime`),require(`@tanstack/react-virtual`)):typeof define==`function`&&define.amd?define([`exports`,`react`,`@object-ui/core`,`@object-ui/react`,`@object-ui/fields`,`@object-ui/components`,`@object-ui/mobile`,`lucide-react`,`react/jsx-runtime`,`@tanstack/react-virtual`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ObjectUIPluginGrid={},e.React,e._object_ui_core,e._object_ui_react,e._object_ui_fields,e._object_ui_components,e._object_ui_mobile,e.lucide_react,e.react_jsx_runtime,e._tanstack_react_virtual))})(this,function(e,t,n,r,i,a,o,s,c,l){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var u=Object.create,d=Object.defineProperty,f=Object.getOwnPropertyDescriptor,p=Object.getOwnPropertyNames,m=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty,g=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=p(t),a=0,o=i.length,s;a<o;a++)s=i[a],!h.call(e,s)&&s!==n&&d(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=f(t,s))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:u(m(e)),g(t||!e||!e.__esModule?d(n,`default`,{value:e,enumerable:!0}):n,e)))(t,1);var _={red:`bg-red-100`,green:`bg-green-100`,blue:`bg-blue-100`,yellow:`bg-yellow-100`,orange:`bg-orange-100`,purple:`bg-purple-100`,pink:`bg-pink-100`,gray:`bg-gray-100`,grey:`bg-gray-100`,indigo:`bg-indigo-100`,teal:`bg-teal-100`,cyan:`bg-cyan-100`,amber:`bg-amber-100`,lime:`bg-lime-100`,emerald:`bg-emerald-100`,rose:`bg-rose-100`,sky:`bg-sky-100`,violet:`bg-violet-100`,fuchsia:`bg-fuchsia-100`,slate:`bg-slate-100`,zinc:`bg-zinc-100`,stone:`bg-stone-100`,neutral:`bg-neutral-100`};function v(e){return e.startsWith(`bg-`)?e:_[e.toLowerCase().trim()]}function y(e){return(0,t.useCallback)(t=>{if(!e?.field||!e.colors)return;let n=String(t[e.field]??``),r=e.colors[n];if(r)return v(r)},[e?.field,e?.colors])}function b(e){if(e==null||e===``)return``;if(Array.isArray(e))return e.map(e=>b(e)).join(`|`);if(typeof e==`object`){let t=e.id??e._id??e.pk??e.value;if(t!=null&&t!==``)return String(t);let n=e.name??e.label??e.title;if(n!=null&&n!==``)return String(n);try{return JSON.stringify(e)}catch{return``}}return String(e)}function x(e,t){return b(e[t])}function S(e,t,n){if(e==null||e===``)return`(empty)`;if(n){let r=n(t,e);if(r!==void 0&&r!==``)return r}if(Array.isArray(e))return e.map(e=>{if(n){let r=n(t,e);if(r!==void 0&&r!==``)return r}return S(e,t)}).join(`, `)||`(empty)`;if(typeof e==`object`){let t=e.name??e.label??e.title??e.display_name??e.displayName??e.fullName??e.full_name;if(t!=null&&t!==``)return String(t);let n=e.id??e._id??e.pk;return n!=null&&n!==``?String(n):`(empty)`}return String(e)}function C(e,t){return t.map(({field:t,type:n})=>{let r=e.map(e=>Number(e[t])).filter(e=>Number.isFinite(e)),i;switch(n){case`count`:i=r.length;break;case`sum`:i=r.reduce((e,t)=>e+t,0);break;case`avg`:i=r.length>0?r.reduce((e,t)=>e+t,0)/r.length:0;break;case`min`:i=r.length>0?Math.min(...r):0;break;case`max`:i=r.length>0?Math.max(...r):0;break;default:i=0}return{field:t,type:n,value:i}})}function w(e,t,n){let r=e.localeCompare(t,void 0,{numeric:!0,sensitivity:`base`});return n===`desc`?-r:r}function T(e,n,r,i){let a=e?.fields,o=!!(a&&a.length>0),[s,c]=(0,t.useState)({});return{groups:(0,t.useMemo)(()=>{if(!o||!a)return[];let e=(t,n,o)=>{if(n>=a.length)return[];let c=a[n],l=new Map,u=[];for(let e of t){let t=x(e,c.field);l.has(t)||(l.set(t,{label:S(e[c.field],c.field,i),rows:[]}),u.push(t)),l.get(t).rows.push(e)}let d=c.order??`asc`;return u.sort((e,t)=>w(l.get(e)?.label??e,l.get(t)?.label??t,d)),u.map(t=>{let i=l.get(t),u=o?`${o}__${n}:${t}`:`${n}:${t}`,d=!!c.collapsed,f=u in s?s[u]:d,p=r&&r.length>0?C(i.rows,r):[],m=n+1<a.length?e(i.rows,n+1,u):[];return{key:u,label:i.label,field:c.field,depth:n,rows:i.rows,collapsed:f,aggregations:p,subgroups:m}})};return e(n,0,``)},[n,a,o,s,r,i]),isGrouped:o,toggleGroup:(0,t.useCallback)(e=>{c(t=>{let n=e.split(`__`).pop()||``,r=/^(\d+):/.exec(n),i=r?Number(r[1]):0,o=!!a?.[i]?.collapsed;return{...t,[e]:t[e]===void 0?!o:!t[e]}})},[a])}}var E=({groupKey:e,label:t,count:n,collapsed:r,aggregations:i,onToggle:a,children:o})=>(0,c.jsxs)(`div`,{className:`border rounded-md`,"data-testid":`group-row-${e}`,children:[(0,c.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 px-3 py-2 text-sm font-medium text-left bg-muted/50 hover:bg-muted transition-colors`,onClick:()=>a(e),"aria-expanded":!r,children:[r?(0,c.jsx)(s.ChevronRight,{className:`h-4 w-4 shrink-0`}):(0,c.jsx)(s.ChevronDown,{className:`h-4 w-4 shrink-0`}),(0,c.jsx)(`span`,{className:`group-label`,children:t}),i&&i.length>0&&(0,c.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground group-aggregations`,children:i.map(e=>(0,c.jsxs)(`span`,{className:`mr-2`,children:[e.type,`: `,Number.isInteger(e.value)?e.value:e.value.toFixed(2)]},`${e.field}-${e.type}`))}),(0,c.jsxs)(`span`,{className:`ml-auto text-xs text-muted-foreground group-count`,children:[`(`,n,`)`]})]}),!r&&o]});function D(e){return typeof e==`string`?{type:e}:e}function O(e,t){if(t.length===0)return null;switch(e){case`count`:return t.length;case`sum`:return t.reduce((e,t)=>e+t,0);case`avg`:return t.reduce((e,t)=>e+t,0)/t.length;case`min`:return Math.min(...t);case`max`:return Math.max(...t);default:return null}}function k(e,t){return t===null?``:`${{count:`Count`,sum:`Sum`,avg:`Avg`,min:`Min`,max:`Max`}[e]||e}: ${e===`avg`?t.toLocaleString(void 0,{maximumFractionDigits:2}):t.toLocaleString()}`}function A(e,n){return(0,t.useMemo)(()=>{let t=new Map;if(!e||e.length===0||n.length===0)return{summaries:t,hasSummary:!1};for(let r of e){if(!r.summary)continue;let e=D(r.summary),i=e.field||r.field,a=[];for(let e of n){let t=e[i];if(t!=null&&typeof t==`number`&&!isNaN(t))a.push(t);else if(t!=null&&typeof t==`string`){let e=parseFloat(t);isNaN(e)||a.push(e)}}let o;if(e.type===`count`){let e=n.filter(e=>e[i]!=null&&e[i]!==``).length;o=e>0?e:null}else o=O(e.type,a);t.set(r.field,{field:r.field,value:o,label:k(e.type,o)})}return{summaries:t,hasSummary:t.size>0}},[e,n])}function j(e){return e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}var M=({row:e,rowActions:t,canEdit:n,canDelete:r,onEdit:i,onDelete:o,onAction:l})=>(0,c.jsxs)(a.DropdownMenu,{children:[(0,c.jsx)(a.DropdownMenuTrigger,{asChild:!0,children:(0,c.jsxs)(a.Button,{variant:`ghost`,size:`icon`,className:`h-8 w-8 min-h-[44px] min-w-[44px] sm:min-h-0 sm:min-w-0`,"data-testid":`row-action-trigger`,children:[(0,c.jsx)(s.MoreVertical,{className:`h-4 w-4`}),(0,c.jsx)(`span`,{className:`sr-only`,children:`Open menu`})]})}),(0,c.jsxs)(a.DropdownMenuContent,{align:`end`,children:[n&&i&&(0,c.jsxs)(a.DropdownMenuItem,{onClick:()=>i(e),children:[(0,c.jsx)(s.Edit,{className:`mr-2 h-4 w-4`}),`Edit`]}),r&&o&&(0,c.jsxs)(a.DropdownMenuItem,{onClick:()=>o(e),children:[(0,c.jsx)(s.Trash2,{className:`mr-2 h-4 w-4`}),`Delete`]}),t?.map(t=>(0,c.jsx)(a.DropdownMenuItem,{onClick:()=>l?.(t,e),"data-testid":`row-action-${t}`,children:j(t)},t))]})]}),N=({selectedRows:e,actions:t,onAction:n,onClearSelection:r})=>!t||t.length===0||e.length===0?null:(0,c.jsxs)(`div`,{className:`border-t px-4 py-1.5 flex items-center gap-2 text-xs bg-primary/5 shrink-0`,"data-testid":`bulk-actions-bar`,children:[(0,c.jsxs)(`span`,{className:`text-muted-foreground font-medium`,children:[e.length,` selected`]}),(0,c.jsx)(`div`,{className:`flex items-center gap-1 ml-2`,children:t.map(t=>(0,c.jsx)(a.Button,{variant:`outline`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:()=>n?.(t,e),"data-testid":`bulk-action-${t}`,children:j(t)},t))}),(0,c.jsx)(a.Button,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs ml-auto`,onClick:r,children:`Clear`})]}),P={"grid.actions":`Actions`,"grid.edit":`Edit`,"grid.delete":`Delete`,"grid.export":`Export`,"grid.exportAs":`Export as {{format}}`,"grid.loading":`Loading grid...`,"grid.errorLoading":`Error loading grid`,"grid.pullToRefresh":`Pull to refresh`,"grid.refreshing":`Refreshing…`,"grid.openRecord":`Open record`};function ee(){try{let e=(0,r.useObjectTranslation)();return e.t(`grid.actions`)===`grid.actions`?{t:(e,t)=>{let n=P[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n}}:{t:e.t}}catch{return{t:(e,t)=>{let n=P[e]||e;if(t)for(let[e,r]of Object.entries(t))n=n.replace(`{{${e}}}`,String(r));return n}}}}function F(e){if(e!=null)return typeof e==`string`?e:void 0}function I(e){return e.data?Array.isArray(e.data)?{provider:`value`,items:e.data}:e.data:e.staticData?{provider:`value`,items:e.staticData}:e.objectName?{provider:`object`,object:e.objectName}:null}function L(e){if(!(!e||e.length===0))return typeof e[0]==`object`&&e[0],e}var R=({schema:e,dataSource:l,onEdit:u,onDelete:d,onRowSelect:f,onRowClick:p,onCellChange:m,onRowSave:h,onBatchSave:g,onAddRecord:_,...v})=>{let[b,x]=(0,t.useState)([]),[S,C]=(0,t.useState)(!0),[w,D]=(0,t.useState)(null),{t:O}=ee(),{fieldLabel:k,translateOptions:P}=(0,r.useSafeFieldLabel)(),[R,te]=(0,t.useState)(null),[ne,re]=(0,t.useState)(!1),[ie,ae]=(0,t.useState)(0),[oe,z]=(0,t.useState)(!1),[se,ce]=(0,t.useState)(!1),B=(0,a.useExportJob)({dataSource:l}),[V,le]=(0,t.useState)(e.rowHeight??`compact`),[ue,de]=(0,t.useState)([]),fe=t.default.useMemo(()=>e.id?`grid-columns-${e.objectName}-${e.id}`:`grid-columns-${e.objectName}`,[e.objectName,e.id]),[H,U]=(0,t.useState)(()=>{try{let e=localStorage.getItem(fe);return e?JSON.parse(e):{}}catch{return{}}}),pe=(0,t.useCallback)(e=>{U(e);try{localStorage.setItem(fe,JSON.stringify(e))}catch(e){console.warn(`Failed to persist column state:`,e)}},[fe]),{ref:me,isRefreshing:he,pullDistance:ge}=(0,o.usePullToRefresh)({onRefresh:(0,t.useCallback)(async()=>{ae(e=>e+1)},[]),enabled:!!l&&!!e.objectName});(0,t.useEffect)(()=>{let e=()=>re(window.innerWidth<480);return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]);let W=v.data,G=(0,r.useDataScope)(e.bind),_e=I(e),K=t.default.useMemo(()=>W&&Array.isArray(W)?{provider:`value`,items:W}:G&&Array.isArray(G)?{provider:`value`,items:G}:_e,[JSON.stringify(_e),G,W]),q=K?.provider===`value`,J=K?.provider===`object`&&K&&`object`in K?K.object:e.objectName,Y=e.fields,X=e.columns,ve=e.filter,Z=e.sort,ye=e.pagination,be=e.pageSize;(0,t.useEffect)(()=>{q&&K?.provider===`value`&&(x(e=>{let t=K.items;return JSON.stringify(e)===JSON.stringify(t)?e:t}),C(!1))},[q,K]),(0,t.useEffect)(()=>{if(!q||!J||!l)return;let e=!1;return(async()=>{try{if(typeof l.getObjectSchema!=`function`)return;let t=await l.getObjectSchema(J);e||te(t)}catch(e){console.warn(`[ObjectGrid] Failed to fetch objectSchema for inline data (objectName: ${J}):`,e)}})(),()=>{e=!0}},[q,J,l]),(0,t.useEffect)(()=>{if(q)return;let t=!1;return(async()=>{C(!0),D(null);try{let r=null,i=L(X)||Y;if(J&&l)if(typeof l.getObjectSchema==`function`){let e=await l.getObjectSchema(J);if(t)return;r=e}else r={name:J,fields:{}};else if(i&&J)r={name:J,fields:{}};else if(J)throw Error(`DataSource required`);else throw Error(`Object name required for data fetching`);if(t||te(r),l&&J){let i={$select:(()=>{let e=e=>e.map(e=>typeof e==`string`?e:e?.name||e?.field).includes(`id`)?e:[`id`,...e];if(Y)return e(Y);if(X&&Array.isArray(X))return e(X.map(e=>typeof e==`string`?e:e.field))})(),$top:ye?.pageSize||be||50};ve&&Array.isArray(ve)?i.$filter=ve:e.defaultFilters&&(i.$filter=e.defaultFilters),Z?typeof Z==`string`?i.$orderby=Z:Array.isArray(Z)&&(i.$orderby=Z.map(e=>`${e.field} ${e.order}`).join(`, `)):e.defaultSort&&(i.$orderby=`${e.defaultSort.field} ${e.defaultSort.order}`);let a=(0,n.buildExpandFields)(r?.fields,X??Y);a.length>0&&(i.$expand=a);let o=await l.find(J,i);if(t)return;x(o.data||[])}}catch(e){t||D(e)}finally{t||C(!1)}})(),()=>{t=!0}},[J,Y,X,ve,Z,ye,be,l,q,K,ie]);let Q=(0,r.useNavigationOverlay)({navigation:e.navigation,objectName:e.objectName,onNavigate:e.onNavigate,onRowClick:p}),{execute:xe}=(0,r.useAction)(),Se=y(e.rowColor),Ce=(0,t.useCallback)(t=>{let r=e.conditionalFormatting;if(!(!r||r.length===0))for(let e of r){let r=!1,i=(`condition`in e?e.condition:void 0)||(`expression`in e?e.expression:void 0)||void 0;if(i)r=(0,n.evaluatePlainCondition)(i,t);else if(`field`in e&&`operator`in e&&e.field&&e.operator){let n=e,i=t[n.field];switch(n.operator){case`equals`:r=i===n.value;break;case`not_equals`:r=i!==n.value;break;case`contains`:r=typeof i==`string`&&typeof n.value==`string`&&i.includes(n.value);break;case`greater_than`:r=typeof i==`number`&&typeof n.value==`number`&&i>n.value;break;case`less_than`:r=typeof i==`number`&&typeof n.value==`number`&&i<n.value;break;case`in`:r=Array.isArray(n.value)&&n.value.includes(i);break}}if(r){let t={};return`style`in e&&e.style&&Object.assign(t,e.style),`backgroundColor`in e&&e.backgroundColor&&(t.backgroundColor=e.backgroundColor),`textColor`in e&&e.textColor&&(t.color=e.textColor),`borderColor`in e&&e.borderColor&&(t.borderColor=e.borderColor),t}}},[e.conditionalFormatting]),we=t.default.useMemo(()=>{let t=e.grouping;if(!t?.fields?.length)return;let n=new Map;for(let r of t.fields){let t=r.field,i=R?.fields?.[t],a=L(e.columns)?.find?.(e=>typeof e==`object`&&e?.field===t),o=a?.type||i?.type,s=a?.options||i?.options,c=new Map;if(Array.isArray(s)&&s.length>0){let n=e.objectName?P(e.objectName,t,s):s;for(let e of n)if(e&&e.value!==void 0&&e.value!==null){let t=e.label;c.set(String(e.value),String(t??e.value))}}n.set(t,{type:o||void 0,options:c.size>0?c:void 0})}return(e,t)=>{let r=n.get(e);if(r){if(r.options){let e=r.options.get(String(t));if(e!==void 0)return e}if(r.type===`boolean`||typeof t==`boolean`){if(t===!0||t===`true`)return O(`grid.booleanTrue`,`Yes`);if(t===!1||t===`false`)return O(`grid.booleanFalse`,`No`)}}}},[e.grouping,e.columns,e.objectName,R,P,O]),{groups:Te,isGrouped:Ee,toggleGroup:De}=T(e.grouping,b,void 0,we),{summaries:Oe,hasSummary:ke}=A(t.default.useMemo(()=>{let t=L(e.columns);if(t&&t.length>0&&typeof t[0]==`object`)return t},[e.columns]),b),Ae=(0,t.useCallback)(()=>{let t=e=>e&&{text:(0,c.jsx)(s.Type,{className:`h-3.5 w-3.5`}),number:(0,c.jsx)(s.Hash,{className:`h-3.5 w-3.5`}),currency:(0,c.jsx)(s.Hash,{className:`h-3.5 w-3.5`}),percent:(0,c.jsx)(s.Hash,{className:`h-3.5 w-3.5`}),date:(0,c.jsx)(s.Calendar,{className:`h-3.5 w-3.5`}),datetime:(0,c.jsx)(s.Clock,{className:`h-3.5 w-3.5`}),boolean:(0,c.jsx)(s.CheckSquare,{className:`h-3.5 w-3.5`}),user:(0,c.jsx)(s.User,{className:`h-3.5 w-3.5`}),select:(0,c.jsx)(s.Tag,{className:`h-3.5 w-3.5`})}[e]||(0,c.jsx)(s.Type,{className:`h-3.5 w-3.5`}),n=e=>{if(e.type)return e.type;let t=e.field.toLowerCase();if([`completed`,`is_completed`,`done`,`active`,`enabled`,`archived`].some(e=>t===e||t===`is_${e}`))return`boolean`;if([`created_time`,`modified_time`,`updated_time`,`created_at`,`updated_at`,`modified_at`,`last_login`,`logged_at`].some(e=>t===e||t.endsWith(`_${e}`)))return`datetime`;if([`date`,`due`,`created`,`updated`,`deadline`,`start`,`end`,`expires`].some(e=>t.includes(e))){if(b.length>0){let t=b.find(t=>t[e.field]!=null)?.[e.field];if(typeof t==`string`&&!isNaN(Date.parse(t)))return`date`}return`date`}if([`probability`,`percent`,`percentage`,`completion`,`progress`,`rate`].some(e=>t.includes(e))&&b.length>0&&typeof b.find(t=>t[e.field]!=null)?.[e.field]==`number`)return`percent`;if([`status`,`priority`,`category`,`stage`,`type`,`severity`,`level`].some(e=>t.includes(e))&&b.length>0){let t=new Set(b.map(t=>t[e.field]).filter(Boolean));if(t.size>0&&t.size<=10)return`select`}if([`assignee`,`owner`,`author`,`reporter`,`creator`,`user`].some(e=>t.includes(e)))return`user`;if([`amount`,`price`,`total`,`revenue`,`cost`,`budget`,`salary`].some(e=>t.includes(e))&&b.length>0&&typeof b.find(t=>t[e.field]!=null)?.[e.field]==`number`)return`currency`;if(b.length>0){let t=b.find(t=>t[e.field]!=null)?.[e.field];if(typeof t==`string`&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(t))return`datetime`}return null},r=L(X);if(r){if(r.length>0&&typeof r[0]==`object`&&r[0]!==null){let o=r[0];if(`accessorKey`in o)return r.map(r=>{if(r.cell)return r;let a=n({field:r.accessorKey,label:r.header,type:r.type});if(!a)return r;let o=(0,i.getCellRenderer)(a),s={name:r.accessorKey,type:a};return a===`select`&&(s.options=Array.from(new Set(b.map(e=>e[r.accessorKey]).filter(Boolean))).map(e=>({value:e,label:(0,i.humanizeLabel)(String(e))}))),{...r,...e.showColumnTypeIcons&&{headerIcon:t(a)},cell:e=>(0,c.jsx)(o,{value:e,field:s})}});if(`field`in o)return r.filter(e=>e?.field&&typeof e.field==`string`&&!e.hidden).map((r,o)=>{let s=F(r.label)||r.field.charAt(0).toUpperCase()+r.field.slice(1).replace(/_/g,` `),l=e.objectName?k(e.objectName,r.field,s):s,u,d=R?.fields?.[r.field],f=r.type||d?.type||n({field:r.field})||null,p=f?(0,i.getCellRenderer)(f):null,m={name:r.field,type:f||`text`};d&&(d.label&&(m.label=d.label),d.currency&&(m.currency=d.currency),d.precision!==void 0&&(m.precision=d.precision),d.format&&(m.format=d.format),d.options&&(m.options=P(e.objectName,r.field,d.options))),f===`select`&&!m.options&&(m.options=Array.from(new Set(b.map(e=>e[r.field]).filter(Boolean))).map(e=>({value:e,label:(0,i.humanizeLabel)(String(e))}))),r.options&&(m.options=P(e.objectName,r.field,r.options));let h=o===0&&!r.link&&!r.action,g=r.link||h;u=r.link&&r.action||h&&r.action||g?(e,t)=>(0,c.jsx)(`button`,{type:`button`,className:`text-primary font-medium underline-offset-4 hover:underline cursor-pointer bg-transparent border-none p-0 text-left font-inherit`,"data-testid":h?`primary-field-link`:`link-cell`,onClick:e=>{e.stopPropagation(),Q.handleClick(t)},children:p?(0,c.jsx)(p,{value:e,field:m}):e!=null&&e!==``?String(e):(0,c.jsx)(`span`,{className:`text-muted-foreground/50 text-xs italic`,children:`—`})}):r.action?(e,t)=>(0,c.jsx)(a.Button,{variant:`outline`,size:`sm`,className:`h-7 text-xs`,"data-testid":`action-cell`,onClick:n=>{n.stopPropagation(),xe({type:r.action,params:{record:t,field:r.field,value:e}})},children:j(r.action)}):p?e=>(0,c.jsx)(p,{value:e,field:m}):e=>e!=null&&e!==``?(0,c.jsx)(`span`,{children:String(e)}):(0,c.jsx)(a.EmptyValue,{});let _=r.prefix;if(_?.field){let e=u,t=_.type===`badge`?(0,i.getCellRenderer)(`select`):null;u=(n,r)=>{let i=r[_.field];return(0,c.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[i!=null&&i!==``?t?(0,c.jsx)(t,{value:i,field:{name:_.field,type:`select`}}):(0,c.jsx)(`span`,{className:`text-muted-foreground text-xs mr-1.5`,children:String(i)}):null,e(n,r)]})}}let v=[`number`,`currency`,`percent`],y=f||r.type,x=r.align||(y&&v.includes(y)?`right`:void 0),S=o===0||r.essential===!0;return{header:l,accessorKey:r.field,...e.showColumnTypeIcons&&{headerIcon:t(f)},...!S&&{className:`hidden sm:table-cell`},...r.width&&{width:r.width},...x&&{align:x},sortable:r.sortable!==!1,...r.resizable!==void 0&&{resizable:r.resizable},...r.wrap!==void 0&&{wrap:r.wrap},...u&&{cell:u},...r.pinned&&{pinned:r.pinned}}})}return r.filter(e=>typeof e==`string`&&e.trim().length>0).map((r,a)=>{let o=R?.fields?.[r],s=o?.label||r.charAt(0).toUpperCase()+r.slice(1).replace(/_/g,` `),l=e.objectName?k(e.objectName,r,s):s,u=o?.type||n({field:r})||null,d=u?(0,i.getCellRenderer)(u):null,f={name:r,type:u||`text`};o&&(o.label&&(f.label=o.label),o.currency&&(f.currency=o.currency),o.precision!==void 0&&(f.precision=o.precision),o.format&&(f.format=o.format),o.options&&(f.options=P(e.objectName,r,o.options))),u===`select`&&!f.options&&(f.options=Array.from(new Set(b.map(e=>e[r]).filter(Boolean))).map(e=>({value:e,label:(0,i.humanizeLabel)(String(e))})));let p=u&&[`number`,`currency`,`percent`].includes(u)?`right`:void 0,m=a===0,h;return m&&d?h=(e,t)=>(0,c.jsx)(`button`,{type:`button`,className:`text-primary font-medium underline-offset-4 hover:underline cursor-pointer bg-transparent border-none p-0 text-left font-inherit`,"data-testid":`primary-field-link`,onClick:e=>{e.stopPropagation(),Q.handleClick(t)},children:(0,c.jsx)(d,{value:e,field:f})}):m?h=(e,t)=>(0,c.jsx)(`button`,{type:`button`,className:`text-primary font-medium underline-offset-4 hover:underline cursor-pointer bg-transparent border-none p-0 text-left font-inherit`,"data-testid":`primary-field-link`,onClick:e=>{e.stopPropagation(),Q.handleClick(t)},children:e!=null&&e!==``?String(e):(0,c.jsx)(`span`,{className:`text-muted-foreground/50 text-xs italic`,children:`—`})}):d&&(h=e=>(0,c.jsx)(d,{value:e,field:f})),{header:l,accessorKey:r,...e.showColumnTypeIcons&&u&&{headerIcon:t(u)},...p&&{align:p},...h&&{cell:h},sortable:o?.sortable!==!1}})}if(q){let r=K?.provider===`value`?K.items:[];if(r.length>0)return(Y||Object.keys(r[0])).map(r=>{let a=R?.fields?.[r],o=a?.type||n({field:r})||null,s=o?(0,i.getCellRenderer)(o):null,l=a?.label||r.charAt(0).toUpperCase()+r.slice(1).replace(/_/g,` `),u={name:r,type:o||`text`};a&&(a.label&&(u.label=a.label),a.currency&&(u.currency=a.currency),a.precision!==void 0&&(u.precision=a.precision),a.format&&(u.format=a.format),a.options&&(u.options=P(e.objectName,r,a.options))),o===`select`&&!u.options&&(u.options=Array.from(new Set(b.map(e=>e[r]).filter(Boolean))).map(e=>({value:e,label:(0,i.humanizeLabel)(String(e))})));let d=o&&[`number`,`currency`,`percent`].includes(o)?`right`:void 0;return{header:l,accessorKey:r,...e.showColumnTypeIcons&&o&&{headerIcon:t(o)},...d&&{align:d},...s&&{cell:e=>(0,c.jsx)(s,{value:e,field:u})},sortable:a?.sortable!==!1}})}if(!R)return[];let o=[],l=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`_version`,`_rev`]),u=R?.compactLayout,d=Object.keys(R.fields||{}),f;if(Y)f=Y;else if(u?.length)f=u.filter(e=>R.fields?.[e]);else{let e=d.filter(e=>{let t=R.fields?.[e];return!(!t||t.hidden||t.readonly&&l.has(e))});f=[...e.filter(e=>!l.has(e)),...e.filter(e=>l.has(e))]}return f.forEach(t=>{let n=R.fields?.[t];if(!n||n.permissions&&n.permissions.read===!1)return;let r=(0,i.getCellRenderer)(n.type),a=[`number`,`currency`,`percent`],s=n.options?{...n,options:P(e.objectName,t,n.options)}:n;o.push({header:e.objectName?k(e.objectName,t,n.label||t):n.label||t,accessorKey:t,...a.includes(n.type)&&{align:`right`},cell:e=>(0,c.jsx)(r,{value:e,field:s}),sortable:n.sortable!==!1})}),o},[R,Y,X,K,q,Q.handleClick,xe,b,k,P,e.objectName]),je=(0,t.useCallback)(t=>{let n=e.exportOptions,r=n?.maxRecords||0,i=n?.includeHeaders!==!1,a=n?.fileNamePrefix||e.objectName||`export`;if((t===`csv`||t===`xlsx`||t===`json`)&&B.isSupported&&e.objectName&&!q&&n?.streaming!==!1){let n=Ae().filter(e=>e.accessorKey!==`_actions`).map(e=>e.accessorKey).filter(Boolean);z(!1),ce(!0),B.start(e.objectName,{format:t===`json`?`json`:t,fields:n.length?n:void 0,includeHeaders:i,limit:r>0?r:void 0});return}let o=r>0?b.slice(0,r):b,s=(e,t)=>{let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,r.click(),URL.revokeObjectURL(n)},c=e=>{let t=e==null?``:String(e);return t.includes(`,`)||t.includes(`"`)||t.includes(`
|
|
2
2
|
`)||t.includes(`\r`)?`"${t.replace(/"/g,`""`)}"`:t};if(t===`csv`){let e=Ae().filter(e=>e.accessorKey!==`_actions`),t=e.map(e=>e.accessorKey),n=e.map(e=>e.header),r=[];i&&r.push(n.join(`,`)),o.forEach(e=>{r.push(t.map(t=>c(e[t])).join(`,`))}),s(new Blob([r.join(`
|
|
3
3
|
`)],{type:`text/csv;charset=utf-8;`}),`${a}.csv`)}else t===`json`&&s(new Blob([JSON.stringify(o,null,2)],{type:`application/json`}),`${a}.json`);z(!1)},[b,e.exportOptions,e.objectName,Ae,B,q]);if(w)return(0,c.jsxs)(`div`,{className:`p-3 sm:p-4 border border-red-300 bg-red-50 rounded-md`,children:[(0,c.jsx)(`h3`,{className:`text-red-800 font-semibold`,children:O(`grid.errorLoading`)}),(0,c.jsx)(`p`,{className:`text-red-600 text-sm mt-1`,children:w.message})]});if(S&&b.length===0)return ne?(0,c.jsx)(`div`,{className:`space-y-2 p-2`,children:[1,2,3].map(e=>(0,c.jsxs)(`div`,{className:`border rounded-lg p-3 bg-card animate-pulse`,children:[(0,c.jsx)(`div`,{className:`h-5 bg-muted rounded w-3/4 mb-3`}),(0,c.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,c.jsx)(`div`,{className:`h-4 bg-muted rounded w-1/4`}),(0,c.jsx)(`div`,{className:`h-5 bg-muted rounded-full w-20`})]}),(0,c.jsx)(`div`,{className:`h-3 bg-muted rounded w-1/3`})]},e))}):(0,c.jsxs)(`div`,{className:`p-4 sm:p-8 text-center`,children:[(0,c.jsx)(`div`,{className:`inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-foreground`}),(0,c.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:O(`grid.loading`)})]});let Me=[...Ae()];if(H.widths&&(Me=Me.map(e=>{let t=H.widths?.[e.accessorKey];return t?{...e,size:t}:e})),H.order&&H.order.length>0){let e=new Map(H.order.map((e,t)=>[e,t]));Me.sort((t,n)=>(e.get(t.accessorKey)??1/0)-(e.get(n.accessorKey)??1/0))}let $=`operations`in e?e.operations:void 0,Ne=$&&($.update||$.delete),Pe=e.rowActions&&e.rowActions.length>0,Fe=Ne||Pe?[...Me,{header:O(`grid.actions`),accessorKey:`_actions`,cell:(t,n)=>(0,c.jsx)(M,{row:n,rowActions:e.rowActions,canEdit:!!($?.update&&u),canDelete:!!($?.delete&&d),onEdit:u,onDelete:d,onAction:(e,t)=>xe({type:e,params:{record:t}})}),sortable:!1}]:Me,Ie=Fe.filter(e=>e.pinned===`left`),Le=Fe.filter(e=>e.pinned===`right`),Re=Fe.filter(e=>!e.pinned),ze=Ie.length>0||Le.length>0,Be=`sticky right-0 z-10 bg-background border-l border-border`,Ve=ze?[...Ie,...Re,...Le.map(e=>({...e,className:[e.className,Be].filter(Boolean).join(` `),cellClassName:[e.cellClassName,Be].filter(Boolean).join(` `)}))]:Fe,He=ze?Ie.length:e.frozenColumns??1,Ue=e.batchActions??e.bulkActions,We=Ue&&Ue.length>0,Ge=!1;e.selection?.type?Ge=e.selection.type===`none`?!1:e.selection.type:e.selectable===void 0?We&&(Ge=`multiple`):Ge=e.selectable;let Ke=e.pagination===void 0?e.showPagination===void 0?!0:e.showPagination:!0,qe=e.pagination?.pageSize||e.pageSize||10,Je=e.searchableFields===void 0?e.showSearch===void 0?!0:e.showSearch:e.searchableFields.length>0,Ye={type:`data-table`,caption:e.label||e.title,columns:Ve,data:b,pagination:Ke,pageSize:qe,searchable:Je,selectable:Ge,sortable:!0,exportable:$?.export,rowActions:!!(e.editable&&Ne),resizableColumns:e.resizable??e.resizableColumns??!0,reorderableColumns:e.reorderableColumns??!1,editable:e.editable??!1,singleClickEdit:e.singleClickEdit??!0,className:e.className,cellClassName:V===`compact`?`px-3 py-1 text-[13px] leading-tight`:V===`short`?`px-3 py-1 text-[13px] leading-normal`:V===`tall`?`px-3 py-2.5 text-sm`:V===`extra_tall`?`px-3 py-3.5 text-sm leading-relaxed`:`px-3 py-1.5 text-[13px] leading-normal`,showRowNumbers:!0,showAddRow:!!$?.create,onAddRecord:_,rowClassName:e.rowColor?(e,t)=>Se(e):void 0,rowStyle:e.conditionalFormatting?.length?(e,t)=>Ce(e):void 0,frozenColumns:He,onSelectionChange:e=>{de(e),f?.(e)},onRowClick:Q.handleClick,onCellChange:m,onRowSave:h,onBatchSave:g,onColumnResize:(e,t)=>{pe({...H,widths:{...H.widths,[e]:t}})},onColumnReorder:e=>{pe({...H,order:e})}},Xe=e=>({...Ye,caption:void 0,data:e,pagination:!1,searchable:!1}),Ze=e.label?`${e.label} Detail`:e.objectName?`${e.objectName.charAt(0).toUpperCase()+e.objectName.slice(1)} Detail`:`Record Detail`;if(ne&&b.length>0&&!Ee){let e=Ae().filter(e=>e.accessorKey!==`_actions`),t=new Map;e.forEach(e=>t.set(e.accessorKey,e));let n=e[0],r=[`amount`,`price`,`total`,`revenue`,`cost`,`value`,`budget`,`salary`],o=[`stage`,`status`,`priority`,`category`,`severity`,`level`],s=[`date`,`due`,`created`,`updated`,`deadline`,`start`,`end`,`expires`],l=[`probability`,`percent`,`rate`,`ratio`,`confidence`,`score`],u=e=>{let t=(e||``).toLowerCase();return t.includes(`won`)||t.includes(`completed`)||t.includes(`done`)||t.includes(`active`)||t===`activated`||t===`success`||t===`approved`||t===`paid`?`bg-green-50 text-green-700 border-green-200 dark:bg-green-950/40 dark:text-green-300 dark:border-green-900/60`:t.includes(`lost`)||t.includes(`cancelled`)||t.includes(`rejected`)||t.includes(`closed lost`)||t===`expired`||t===`terminated`||t===`failed`||t===`overdue`?`bg-red-50 text-red-700 border-red-200 dark:bg-red-950/40 dark:text-red-300 dark:border-red-900/60`:t.includes(`negotiation`)||t.includes(`review`)||t.includes(`in progress`)||t.includes(`approval`)||t===`in_approval`||t===`pending_approval`?`bg-yellow-50 text-yellow-800 border-yellow-200 dark:bg-yellow-950/40 dark:text-yellow-300 dark:border-yellow-900/60`:t.includes(`proposal`)||t.includes(`pending`)?`bg-blue-50 text-blue-700 border-blue-200 dark:bg-blue-950/40 dark:text-blue-300 dark:border-blue-900/60`:t.includes(`qualification`)||t.includes(`qualified`)?`bg-indigo-50 text-indigo-700 border-indigo-200 dark:bg-indigo-950/40 dark:text-indigo-300 dark:border-indigo-900/60`:t.includes(`prospecting`)||t.includes(`new`)||t.includes(`open`)?`bg-purple-50 text-purple-700 border-purple-200 dark:bg-purple-950/40 dark:text-purple-300 dark:border-purple-900/60`:t===`draft`||t.includes(`draft`)?`bg-slate-50 text-slate-700 border-slate-200 dark:bg-slate-950/40 dark:text-slate-300 dark:border-slate-900/60`:`bg-muted text-muted-foreground border-border`},d=e=>{let t=(e||``).toLowerCase();return t.includes(`won`)||t.includes(`completed`)||t.includes(`done`)||t.includes(`active`)||t===`activated`?`border-l-green-500`:t.includes(`lost`)||t.includes(`cancelled`)||t.includes(`rejected`)||t===`expired`||t===`terminated`?`border-l-red-500`:t.includes(`negotiation`)||t.includes(`review`)||t.includes(`in progress`)||t.includes(`approval`)?`border-l-yellow-500`:t.includes(`proposal`)||t.includes(`pending`)?`border-l-blue-500`:t.includes(`qualification`)||t.includes(`qualified`)?`border-l-indigo-500`:t.includes(`prospecting`)||t.includes(`new`)||t.includes(`open`)?`border-l-purple-500`:t===`draft`||t.includes(`draft`)?`border-l-slate-400`:`border-l-gray-300`},f=e=>{let t=e.toLowerCase();return r.some(e=>t.includes(e))?`amount`:o.some(e=>t.includes(e))?`stage`:s.some(e=>t.includes(e))?`date`:l.some(e=>t.includes(e))?`percent`:`other`};return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(`div`,{className:`space-y-2 p-2`,children:b.map((t,r)=>{let o=e.slice(1,5),s=o.find(e=>f(e.accessorKey)===`amount`),l=o.find(e=>f(e.accessorKey)===`stage`),p=o.filter(e=>f(e.accessorKey)===`date`),m=o.filter(e=>f(e.accessorKey)===`percent`),h=o.filter(e=>e!==s&&e!==l&&!p.includes(e)&&!m.includes(e)),g=l?String(t[l.accessorKey]??``):``,_=g?d(g):``;return(0,c.jsxs)(`div`,{className:[`border rounded-lg p-2.5 bg-card hover:bg-accent/50 cursor-pointer transition-colors touch-manipulation`,_?`border-l-[3px] ${_}`:``].filter(Boolean).join(` `),onClick:()=>Q.handleClick(t),children:[n&&(0,c.jsx)(`div`,{className:`font-semibold text-sm truncate mb-1`,children:t[n.accessorKey]!=null&&typeof t[n.accessorKey]==`object`?String(t[n.accessorKey]):t[n.accessorKey]??`—`}),(s||l)&&(0,c.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1`,children:[s&&(0,c.jsx)(`span`,{className:`text-sm tabular-nums font-medium`,children:typeof t[s.accessorKey]==`number`?(0,i.formatCompactCurrency)(t[s.accessorKey]):t[s.accessorKey]!=null&&typeof t[s.accessorKey]==`object`?String(t[s.accessorKey]):t[s.accessorKey]??`—`}),l&&t[l.accessorKey]&&(0,c.jsx)(a.Badge,{variant:`outline`,className:`text-xs shrink-0 max-w-[140px] truncate ${u(String(t[l.accessorKey]))}`,children:String(t[l.accessorKey])})]}),(p.length>0||m.length>0)&&(0,c.jsxs)(`div`,{className:`flex items-center justify-between py-0.5 text-xs text-muted-foreground`,children:[p[0]&&(0,c.jsx)(`span`,{className:`tabular-nums`,children:t[p[0].accessorKey]?(0,i.formatDate)(t[p[0].accessorKey],`short`):`—`}),m[0]&&t[m[0].accessorKey]!=null&&(0,c.jsx)(`span`,{className:`tabular-nums`,children:(0,i.formatPercent)(Number(t[m[0].accessorKey]))})]}),p.slice(1).map(e=>(0,c.jsxs)(`div`,{className:`flex justify-between items-center py-0.5`,children:[(0,c.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.header}),(0,c.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:t[e.accessorKey]?(0,i.formatDate)(t[e.accessorKey],`short`):`—`})]},e.accessorKey)),h.map(e=>{let n=t[e.accessorKey];return n==null||n===``?null:(0,c.jsxs)(`div`,{className:`flex justify-between items-center py-0.5`,children:[(0,c.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.header}),(0,c.jsx)(`span`,{className:`text-xs font-medium truncate ml-2 text-right`,children:e.cell?e.cell(n,t):String(n)})]},e.accessorKey)})]},t.id||t._id||r)})}),Q.isOverlay&&(0,c.jsx)(a.NavigationOverlay,{...Q,title:Ze,children:e=>(0,c.jsx)(`div`,{className:`space-y-3`,children:Object.entries(e).map(([e,t])=>(0,c.jsxs)(`div`,{className:`flex flex-col`,children:[(0,c.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e.replace(/_/g,` `)}),(0,c.jsx)(`span`,{className:`text-sm`,children:String(t??`—`)})]},e))})})]})}let Qe=()=>{le(e=>e===`compact`?`short`:e===`short`?`medium`:e===`medium`?`tall`:e===`tall`?`extra_tall`:`compact`)},$e={compact:s.Rows4,short:s.Rows3,medium:s.Rows2,tall:s.AlignJustify,extra_tall:s.AlignJustify}[V],et=e.rowHeight!==void 0,tt=e.exportOptions||et?(0,c.jsxs)(`div`,{className:`flex items-center justify-end gap-1 px-2 py-1`,children:[et&&(0,c.jsxs)(a.Button,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground hover:text-primary text-xs`,onClick:Qe,title:`Row height: ${V}`,children:[(0,c.jsx)($e,{className:`h-3.5 w-3.5 mr-1.5`}),(0,c.jsx)(`span`,{className:`hidden sm:inline capitalize`,children:V})]}),e.exportOptions&&(0,c.jsxs)(a.Popover,{open:oe,onOpenChange:z,children:[(0,c.jsx)(a.PopoverTrigger,{asChild:!0,children:(0,c.jsxs)(a.Button,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground hover:text-primary text-xs`,children:[(0,c.jsx)(s.Download,{className:`h-3.5 w-3.5 mr-1.5`}),(0,c.jsx)(`span`,{className:`hidden sm:inline`,children:O(`grid.export`)})]})}),(0,c.jsx)(a.PopoverContent,{align:`end`,className:`w-48 p-2`,children:(0,c.jsx)(`div`,{className:`space-y-1`,children:(e.exportOptions.formats||[`csv`,`json`]).map(e=>(0,c.jsxs)(a.Button,{variant:`ghost`,size:`sm`,className:`w-full justify-start h-8 text-xs`,onClick:()=>je(e),children:[(0,c.jsx)(s.Download,{className:`h-3.5 w-3.5 mr-2`}),O(`grid.exportAs`,{format:e.toUpperCase()})]},e))})})]})]}):null,nt=e=>{let t=[`_id`,`id`,`created_at`,`updated_at`,`created_by`,`updated_by`],n=Object.entries(e),r=n.filter(([e])=>!t.includes(e)),o=n.filter(([e])=>t.includes(e)&&e!==`_id`&&e!==`id`),s=e=>e.charAt(0).toUpperCase()+e.slice(1).replace(/_/g,` `),l=(e,t)=>{if(t==null||t===``)return(0,c.jsx)(`span`,{className:`text-muted-foreground/50 text-sm italic`,children:`Empty`});let n=R?.fields?.[e];if(n?.type){let e=(0,i.getCellRenderer)(n.type);if(e)return(0,c.jsx)(e,{value:t,field:n})}return typeof t==`boolean`?(0,c.jsx)(a.Badge,{variant:t?`default`:`outline`,children:t?`Yes`:`No`}):typeof t==`string`&&!isNaN(Date.parse(t))&&(e.includes(`date`)||e.includes(`_at`)||e.includes(`time`))?(0,c.jsx)(`span`,{className:`text-sm tabular-nums`,children:(0,i.formatDate)(t)}):typeof t==`number`&&[`amount`,`price`,`total`,`revenue`,`cost`,`value`,`budget`,`salary`].some(t=>e.toLowerCase().includes(t))?(0,c.jsx)(`span`,{className:`text-sm tabular-nums font-medium`,children:(0,i.formatCurrency)(t)}):(0,c.jsx)(`span`,{className:`text-sm break-words`,children:String(t)})};return(0,c.jsxs)(`div`,{className:`space-y-4`,"data-testid":`record-detail-panel`,children:[(0,c.jsx)(`div`,{className:`rounded-lg border bg-card`,children:(0,c.jsx)(`div`,{className:`divide-y`,children:r.map(([e,t])=>(0,c.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-start gap-1 sm:gap-4 px-4 py-3`,children:[(0,c.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground sm:w-1/3 sm:text-right sm:pt-0.5 uppercase tracking-wide shrink-0`,children:s(e)}),(0,c.jsx)(`div`,{className:`flex-1 min-w-0`,children:l(e,t)})]},e))})}),o.length>0&&(0,c.jsxs)(`div`,{className:`rounded-lg border bg-muted/30`,children:[(0,c.jsx)(`div`,{className:`px-4 py-2 border-b`,children:(0,c.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:`System`})}),(0,c.jsx)(`div`,{className:`divide-y divide-border/50`,children:o.map(([e,t])=>(0,c.jsxs)(`div`,{className:`flex items-center gap-4 px-4 py-2`,children:[(0,c.jsx)(`span`,{className:`text-xs text-muted-foreground w-1/3 text-right shrink-0`,children:s(e)}),(0,c.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1 min-w-0 break-words`,children:String(t??``)})]},e))})]})]})},rt=ke?(0,c.jsx)(`div`,{className:`border-t bg-muted/30 px-2 py-1.5`,"data-testid":`column-summary-footer`,children:(0,c.jsx)(`div`,{className:`flex gap-4 text-xs text-muted-foreground font-medium`,children:Ve.filter(e=>Oe.has(e.accessorKey)).map(e=>{let t=Oe.get(e.accessorKey);return(0,c.jsxs)(`span`,{"data-testid":`summary-${e.accessorKey}`,children:[e.header,`: `,t.label]},e.accessorKey)})})}):null,it=e=>(0,c.jsx)(`div`,{style:e.depth>0?{marginLeft:e.depth*16}:void 0,children:(0,c.jsx)(E,{groupKey:e.key,label:e.label,count:e.rows.length,collapsed:e.collapsed,aggregations:e.aggregations,onToggle:De,children:e.subgroups.length>0?(0,c.jsx)(`div`,{className:`space-y-2 p-2`,children:e.subgroups.map(it)}):(0,c.jsx)(r.SchemaRenderer,{schema:Xe(e.rows)})})},e.key),at=Ee?(0,c.jsx)(`div`,{className:`space-y-2`,children:Te.map(it)}):(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(r.SchemaRenderer,{schema:Ye}),rt]}),ot=(0,c.jsx)(a.ExportProgressDialog,{open:se,onOpenChange:ce,job:B,filename:`${e.exportOptions?.fileNamePrefix||e.objectName||`export`}.${B.progress?.format||`csv`}`,closeAfterDownloadMs:400});return Q.isOverlay&&Q.mode===`split`?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(a.NavigationOverlay,{...Q,title:Ze,mainContent:(0,c.jsxs)(c.Fragment,{children:[tt,at,(0,c.jsx)(N,{selectedRows:ue,actions:Ue??[],onAction:(e,t)=>xe({type:e,params:{records:t}}),onClearSelection:()=>de([])})]}),children:e=>nt(e)}),ot]}):(0,c.jsxs)(`div`,{ref:me,className:`relative h-full`,children:[ge>0&&(0,c.jsx)(`div`,{className:`flex items-center justify-center text-xs text-muted-foreground`,style:{height:ge},children:O(he?`grid.refreshing`:`grid.pullToRefresh`)}),tt,at,(0,c.jsx)(N,{selectedRows:ue,actions:Ue??[],onAction:(e,t)=>xe({type:e,params:{records:t}}),onClearSelection:()=>de([])}),Q.isOverlay&&(0,c.jsx)(a.NavigationOverlay,{...Q,title:Ze,children:e=>nt(e)}),ot]})},te=({data:e,columns:n,rowHeight:r=40,height:i=600,className:a=``,headerClassName:o=``,rowClassName:s,onRowClick:u,overscan:d=5})=>{let f=(0,t.useRef)(null),p=(0,l.useVirtualizer)({count:e.length,getScrollElement:()=>f.current,estimateSize:()=>r,overscan:d}),m=p.getVirtualItems();return(0,c.jsxs)(`div`,{className:a,children:[(0,c.jsx)(`div`,{className:`grid border-b sticky top-0 bg-muted/30 z-10 ${o}`,style:{gridTemplateColumns:n.map(e=>e.width||`1fr`).join(` `)},children:n.map((e,t)=>(0,c.jsx)(`div`,{className:`px-4 py-2 text-[11px] font-semibold uppercase tracking-wider text-muted-foreground/70 ${e.align===`center`?`text-center`:e.align===`right`?`text-right`:`text-left`}`,children:e.header},t))}),(0,c.jsx)(`div`,{ref:f,className:`overflow-auto`,style:{height:typeof i==`number`?`${i}px`:i,contain:`strict`},children:(0,c.jsx)(`div`,{style:{height:`${p.getTotalSize()}px`,width:`100%`,position:`relative`},children:m.map(t=>{let r=e[t.index];return(0,c.jsx)(`div`,{className:`grid border-b hover:bg-muted/50 cursor-pointer ${typeof s==`function`?s(r,t.index):s||``}`,style:{position:`absolute`,top:0,left:0,width:`100%`,height:`${t.size}px`,transform:`translateY(${t.start}px)`,gridTemplateColumns:n.map(e=>e.width||`1fr`).join(` `)},onClick:()=>u?.(r,t.index),children:n.map((e,t)=>{let n=r[e.accessorKey],i=e.cell?e.cell(n,r):typeof n==`object`&&n?String(n):n;return(0,c.jsx)(`div`,{className:`px-4 py-2 text-sm flex items-center ${e.align===`center`?`text-center justify-center`:e.align===`right`?`text-right justify-end`:`text-left justify-start`}`,children:i},t)})},t.key)})})}),(0,c.jsxs)(`div`,{className:`px-4 py-2 text-xs text-muted-foreground border-t`,children:[`Showing `,m.length,` of `,e.length,` rows (virtual scrolling enabled)`]})]})},ne=10;function re(e){let t=[],n=[],r=``,i=!1;for(let a=0;a<e.length;a++){let o=e[a],s=e[a+1];i?o===`"`&&s===`"`?(r+=`"`,a++):o===`"`?i=!1:r+=o:o===`"`?i=!0:o===`,`?(n.push(r.trim()),r=``):o===`
|
|
4
4
|
`||o===`\r`&&s===`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/plugin-grid",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Grid plugin for Object UI",
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@tanstack/react-virtual": "^3.13.24",
|
|
19
19
|
"lucide-react": "^1.14.0",
|
|
20
|
-
"@object-ui/components": "4.0.
|
|
21
|
-
"@object-ui/core": "4.0.
|
|
22
|
-
"@object-ui/fields": "4.0.
|
|
23
|
-
"@object-ui/mobile": "4.0.
|
|
24
|
-
"@object-ui/react": "4.0.
|
|
25
|
-
"@object-ui/types": "4.0.
|
|
20
|
+
"@object-ui/components": "4.0.6",
|
|
21
|
+
"@object-ui/core": "4.0.6",
|
|
22
|
+
"@object-ui/fields": "4.0.6",
|
|
23
|
+
"@object-ui/mobile": "4.0.6",
|
|
24
|
+
"@object-ui/react": "4.0.6",
|
|
25
|
+
"@object-ui/types": "4.0.6"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"react": "^18.0.0 || ^19.0.0",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"typescript": "^6.0.3",
|
|
35
35
|
"vite": "^8.0.10",
|
|
36
36
|
"vite-plugin-dts": "^5.0.0",
|
|
37
|
-
"@object-ui/data-objectstack": "4.0.
|
|
37
|
+
"@object-ui/data-objectstack": "4.0.6"
|
|
38
38
|
},
|
|
39
39
|
"keywords": [
|
|
40
40
|
"objectui",
|