@ram_28/kf-ai-sdk 1.0.13 → 1.0.15

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./jsx-runtime-BYECrxsp.cjs"),p=require("react"),o=require("./cn-mXUIg4vp.cjs");function C(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const n in a)if(n!=="default"){const s=Object.getOwnPropertyDescriptor(a,n);Object.defineProperty(e,n,s.get?s:{enumerable:!0,get:()=>a[n]})}}return e.default=a,Object.freeze(e)}const r=C(p),l=r.forwardRef(({className:a,...e},n)=>t.jsxRuntimeExports.jsx("div",{ref:n,className:o.cn("flex h-full flex-grow items-start gap-x-4 overflow-x-auto py-2",a),...e}));l.displayName="Kanban";const i=r.forwardRef(({className:a,...e},n)=>t.jsxRuntimeExports.jsx("div",{ref:n,className:o.cn("flex h-full min-w-[300px] flex-col rounded-lg border bg-gray-50 p-3",a),...e}));i.displayName="KanbanColumn";const m=r.forwardRef(({className:a,...e},n)=>t.jsxRuntimeExports.jsx("div",{ref:n,className:o.cn("mb-3 flex items-center justify-between",a),...e}));m.displayName="KanbanColumnHeader";const d=r.forwardRef(({className:a,...e},n)=>t.jsxRuntimeExports.jsx("h3",{ref:n,className:o.cn("text-sm font-semibold text-gray-700",a),...e}));d.displayName="KanbanColumnTitle";const c=r.forwardRef(({className:a,...e},n)=>t.jsxRuntimeExports.jsx("div",{ref:n,className:o.cn("flex-1 space-y-2 overflow-y-auto",a),...e}));c.displayName="KanbanColumnContent";const u=r.forwardRef(({className:a,...e},n)=>t.jsxRuntimeExports.jsx("div",{ref:n,className:o.cn("rounded-lg border border-gray-200 bg-white p-3 shadow-sm hover:shadow-md transition-shadow cursor-move",a),...e}));u.displayName="KanbanCard";const b=r.forwardRef(({className:a,...e},n)=>t.jsxRuntimeExports.jsx("div",{ref:n,className:o.cn("font-medium text-gray-900 mb-1",a),...e}));b.displayName="KanbanCardTitle";const x=r.forwardRef(({className:a,...e},n)=>t.jsxRuntimeExports.jsx("div",{ref:n,className:o.cn("text-sm text-gray-600",a),...e}));x.displayName="KanbanCardDescription";const f=r.forwardRef(({className:a,...e},n)=>t.jsxRuntimeExports.jsx("div",{ref:n,className:o.cn("mt-3 pt-3 border-t border-gray-200",a),...e}));f.displayName="KanbanColumnFooter";exports.Kanban=l;exports.KanbanCard=u;exports.KanbanCardDescription=x;exports.KanbanCardTitle=b;exports.KanbanColumn=i;exports.KanbanColumnContent=c;exports.KanbanColumnFooter=f;exports.KanbanColumnHeader=m;exports.KanbanColumnTitle=d;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),K=require("react"),t=require("./cn-mXUIg4vp.cjs");function p(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const n in a)if(n!=="default"){const s=Object.getOwnPropertyDescriptor(a,n);Object.defineProperty(e,n,s.get?s:{enumerable:!0,get:()=>a[n]})}}return e.default=a,Object.freeze(e)}const r=p(K),l=r.forwardRef(({className:a,...e},n)=>o.jsx("div",{ref:n,className:t.cn("flex h-full flex-grow items-start gap-x-4 overflow-x-auto py-2",a),...e}));l.displayName="Kanban";const d=r.forwardRef(({className:a,...e},n)=>o.jsx("div",{ref:n,className:t.cn("flex h-full min-w-[300px] flex-col rounded-lg border bg-gray-50 p-3",a),...e}));d.displayName="KanbanColumn";const c=r.forwardRef(({className:a,...e},n)=>o.jsx("div",{ref:n,className:t.cn("mb-3 flex items-center justify-between",a),...e}));c.displayName="KanbanColumnHeader";const i=r.forwardRef(({className:a,...e},n)=>o.jsx("h3",{ref:n,className:t.cn("text-sm font-semibold text-gray-700",a),...e}));i.displayName="KanbanColumnTitle";const m=r.forwardRef(({className:a,...e},n)=>o.jsx("div",{ref:n,className:t.cn("flex-1 space-y-2 overflow-y-auto",a),...e}));m.displayName="KanbanColumnContent";const b=r.forwardRef(({className:a,...e},n)=>o.jsx("div",{ref:n,className:t.cn("rounded-lg border border-gray-200 bg-white p-3 shadow-sm hover:shadow-md transition-shadow cursor-move",a),...e}));b.displayName="KanbanCard";const f=r.forwardRef(({className:a,...e},n)=>o.jsx("div",{ref:n,className:t.cn("font-medium text-gray-900 mb-1",a),...e}));f.displayName="KanbanCardTitle";const u=r.forwardRef(({className:a,...e},n)=>o.jsx("div",{ref:n,className:t.cn("text-sm text-gray-600",a),...e}));u.displayName="KanbanCardDescription";const C=r.forwardRef(({className:a,...e},n)=>o.jsx("div",{ref:n,className:t.cn("mt-3 pt-3 border-t border-gray-200",a),...e}));C.displayName="KanbanColumnFooter";exports.Kanban=l;exports.KanbanCard=b;exports.KanbanCardDescription=u;exports.KanbanCardTitle=f;exports.KanbanColumn=d;exports.KanbanColumnContent=m;exports.KanbanColumnFooter=C;exports.KanbanColumnHeader=c;exports.KanbanColumnTitle=i;
@@ -1,11 +1,11 @@
1
- import { j as o } from "./jsx-runtime-DGlMoOmv.js";
2
- import * as s from "react";
3
- import { c as r } from "./cn-Dr87sK3i.js";
4
- const t = s.forwardRef(({ className: a, ...e }, n) => /* @__PURE__ */ o.jsx(
1
+ import { jsx as o } from "react/jsx-runtime";
2
+ import * as r from "react";
3
+ import { c as s } from "./cn-Dr87sK3i.js";
4
+ const t = r.forwardRef(({ className: a, ...e }, n) => /* @__PURE__ */ o(
5
5
  "div",
6
6
  {
7
7
  ref: n,
8
- className: r(
8
+ className: s(
9
9
  "flex h-full flex-grow items-start gap-x-4 overflow-x-auto py-2",
10
10
  a
11
11
  ),
@@ -13,11 +13,11 @@ const t = s.forwardRef(({ className: a, ...e }, n) => /* @__PURE__ */ o.jsx(
13
13
  }
14
14
  ));
15
15
  t.displayName = "Kanban";
16
- const d = s.forwardRef(({ className: a, ...e }, n) => /* @__PURE__ */ o.jsx(
16
+ const d = r.forwardRef(({ className: a, ...e }, n) => /* @__PURE__ */ o(
17
17
  "div",
18
18
  {
19
19
  ref: n,
20
- className: r(
20
+ className: s(
21
21
  "flex h-full min-w-[300px] flex-col rounded-lg border bg-gray-50 p-3",
22
22
  a
23
23
  ),
@@ -25,38 +25,38 @@ const d = s.forwardRef(({ className: a, ...e }, n) => /* @__PURE__ */ o.jsx(
25
25
  }
26
26
  ));
27
27
  d.displayName = "KanbanColumn";
28
- const m = s.forwardRef(({ className: a, ...e }, n) => /* @__PURE__ */ o.jsx(
28
+ const l = r.forwardRef(({ className: a, ...e }, n) => /* @__PURE__ */ o(
29
29
  "div",
30
30
  {
31
31
  ref: n,
32
- className: r("mb-3 flex items-center justify-between", a),
32
+ className: s("mb-3 flex items-center justify-between", a),
33
33
  ...e
34
34
  }
35
35
  ));
36
- m.displayName = "KanbanColumnHeader";
37
- const l = s.forwardRef(({ className: a, ...e }, n) => /* @__PURE__ */ o.jsx(
36
+ l.displayName = "KanbanColumnHeader";
37
+ const m = r.forwardRef(({ className: a, ...e }, n) => /* @__PURE__ */ o(
38
38
  "h3",
39
39
  {
40
40
  ref: n,
41
- className: r("text-sm font-semibold text-gray-700", a),
41
+ className: s("text-sm font-semibold text-gray-700", a),
42
42
  ...e
43
43
  }
44
44
  ));
45
- l.displayName = "KanbanColumnTitle";
46
- const i = s.forwardRef(({ className: a, ...e }, n) => /* @__PURE__ */ o.jsx(
45
+ m.displayName = "KanbanColumnTitle";
46
+ const i = r.forwardRef(({ className: a, ...e }, n) => /* @__PURE__ */ o(
47
47
  "div",
48
48
  {
49
49
  ref: n,
50
- className: r("flex-1 space-y-2 overflow-y-auto", a),
50
+ className: s("flex-1 space-y-2 overflow-y-auto", a),
51
51
  ...e
52
52
  }
53
53
  ));
54
54
  i.displayName = "KanbanColumnContent";
55
- const f = s.forwardRef(({ className: a, ...e }, n) => /* @__PURE__ */ o.jsx(
55
+ const f = r.forwardRef(({ className: a, ...e }, n) => /* @__PURE__ */ o(
56
56
  "div",
57
57
  {
58
58
  ref: n,
59
- className: r(
59
+ className: s(
60
60
  "rounded-lg border border-gray-200 bg-white p-3 shadow-sm hover:shadow-md transition-shadow cursor-move",
61
61
  a
62
62
  ),
@@ -64,33 +64,33 @@ const f = s.forwardRef(({ className: a, ...e }, n) => /* @__PURE__ */ o.jsx(
64
64
  }
65
65
  ));
66
66
  f.displayName = "KanbanCard";
67
- const b = s.forwardRef(({ className: a, ...e }, n) => /* @__PURE__ */ o.jsx(
67
+ const b = r.forwardRef(({ className: a, ...e }, n) => /* @__PURE__ */ o(
68
68
  "div",
69
69
  {
70
70
  ref: n,
71
- className: r("font-medium text-gray-900 mb-1", a),
71
+ className: s("font-medium text-gray-900 mb-1", a),
72
72
  ...e
73
73
  }
74
74
  ));
75
75
  b.displayName = "KanbanCardTitle";
76
- const c = s.forwardRef(({ className: a, ...e }, n) => /* @__PURE__ */ o.jsx(
76
+ const c = r.forwardRef(({ className: a, ...e }, n) => /* @__PURE__ */ o(
77
77
  "div",
78
78
  {
79
79
  ref: n,
80
- className: r("text-sm text-gray-600", a),
80
+ className: s("text-sm text-gray-600", a),
81
81
  ...e
82
82
  }
83
83
  ));
84
84
  c.displayName = "KanbanCardDescription";
85
- const x = s.forwardRef(({ className: a, ...e }, n) => /* @__PURE__ */ o.jsx(
85
+ const p = r.forwardRef(({ className: a, ...e }, n) => /* @__PURE__ */ o(
86
86
  "div",
87
87
  {
88
88
  ref: n,
89
- className: r("mt-3 pt-3 border-t border-gray-200", a),
89
+ className: s("mt-3 pt-3 border-t border-gray-200", a),
90
90
  ...e
91
91
  }
92
92
  ));
93
- x.displayName = "KanbanColumnFooter";
93
+ p.displayName = "KanbanColumnFooter";
94
94
  export {
95
95
  t as Kanban,
96
96
  f as KanbanCard,
@@ -98,7 +98,7 @@ export {
98
98
  b as KanbanCardTitle,
99
99
  d as KanbanColumn,
100
100
  i as KanbanColumnContent,
101
- x as KanbanColumnFooter,
102
- m as KanbanColumnHeader,
103
- l as KanbanColumnTitle
101
+ p as KanbanColumnFooter,
102
+ l as KanbanColumnHeader,
103
+ m as KanbanColumnTitle
104
104
  };
package/dist/table.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),O=require("./useQuery-BScHEo7x.cjs"),Q=require("./client-C15j4O5B.cjs"),_=require("./useFilter-D-bCDo6Z.cjs");function $(t){var N,m,P,k,z,T,F,M,w,E;const[o,p]=a.useState({query:""}),[n,y]=a.useState({field:((m=(N=t.initialState)==null?void 0:N.sorting)==null?void 0:m.field)||null,direction:((k=(P=t.initialState)==null?void 0:P.sorting)==null?void 0:k.direction)||null}),[i,c]=a.useState({pageNo:((T=(z=t.initialState)==null?void 0:z.pagination)==null?void 0:T.pageNo)||1,pageSize:((M=(F=t.initialState)==null?void 0:F.pagination)==null?void 0:M.pageSize)||10}),s=_.useFilter({initialConditions:(w=t.initialState)==null?void 0:w.filters,initialOperator:((E=t.initialState)==null?void 0:E.filterOperator)||"And"}),u=a.useMemo(()=>{const e={};return o.query&&(e.Search=o.query),s.payload&&(e.Filter=s.payload),e},[o.query,s.payload]),b=a.useMemo(()=>{const e={...u};return n.field&&n.direction&&(e.Sort=[{[String(n.field)]:n.direction==="asc"?"ASC":"DESC"}]),t.enablePagination&&(e.Page=i.pageNo,e.PageSize=i.pageSize),e},[u,n,i,t.enablePagination]),{data:l,isLoading:L,isFetching:R,error:x,refetch:q}=O.useQuery({queryKey:["table",t.source,b],queryFn:async()=>{try{const e=await Q.api(t.source).list(b);return t.onSuccess&&t.onSuccess(e.Data),e}catch(e){throw t.onError&&t.onError(e),e}},staleTime:0,gcTime:0}),{data:g,isLoading:A,isFetching:D,error:G,refetch:C}=O.useQuery({queryKey:["table-count",t.source,u],queryFn:async()=>{try{return await Q.api(t.source).count(u)}catch(e){throw t.onError&&t.onError(e),e}},staleTime:0,gcTime:0}),K=a.useMemo(()=>(l==null?void 0:l.Data)||[],[l]),S=a.useMemo(()=>(g==null?void 0:g.Count)||0,[g]),d=a.useMemo(()=>Math.ceil(S/i.pageSize),[S,i.pageSize]),j=a.useCallback(e=>{y(r=>{if(r.field===e){if(r.direction==="asc")return{field:e,direction:"desc"};if(r.direction==="desc")return{field:null,direction:null}}return{field:e,direction:"asc"}})},[]),I=a.useCallback(()=>{y({field:null,direction:null})},[]),B=a.useCallback((e,r)=>{y({field:e,direction:r})},[]),H=a.useCallback(e=>{p({query:e}),c(r=>({...r,pageNo:1}))},[]),J=a.useCallback(()=>{p({query:""})},[]),f=i.pageNo<d,h=i.pageNo>1,U=a.useCallback(()=>{f&&c(e=>({...e,pageNo:e.pageNo+1}))},[f]),V=a.useCallback(()=>{h&&c(e=>({...e,pageNo:e.pageNo-1}))},[h]),W=a.useCallback(e=>{const r=Math.max(1,Math.min(e,d));c(Z=>({...Z,pageNo:r}))},[d]),X=a.useCallback(e=>{c(r=>({...r,pageSize:e,pageNo:1}))},[]),Y=a.useCallback(async()=>{const[e]=await Promise.all([q(),C()]);return e.data||{Data:[]}},[q,C]);return{rows:K,totalItems:S,isLoading:L||A,isFetching:R||D,error:x||G,search:{query:o.query,setQuery:H,clear:J},sort:{field:n.field,direction:n.direction,toggle:j,clear:I,set:B},filter:s,pagination:{currentPage:i.pageNo,pageSize:i.pageSize,totalPages:d,totalItems:S,canGoNext:f,canGoPrevious:h,goToNext:U,goToPrevious:V,goToPage:W,setPageSize:X},refetch:Y}}exports.useTable=$;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),O=require("@tanstack/react-query"),Q=require("./client-C15j4O5B.cjs"),_=require("./useFilter-Dofowpr_.cjs");function $(t){var N,m,P,k,z,T,F,M,w,E;const[o,p]=a.useState({query:""}),[n,y]=a.useState({field:((m=(N=t.initialState)==null?void 0:N.sorting)==null?void 0:m.field)||null,direction:((k=(P=t.initialState)==null?void 0:P.sorting)==null?void 0:k.direction)||null}),[i,c]=a.useState({pageNo:((T=(z=t.initialState)==null?void 0:z.pagination)==null?void 0:T.pageNo)||1,pageSize:((M=(F=t.initialState)==null?void 0:F.pagination)==null?void 0:M.pageSize)||10}),s=_.useFilter({initialConditions:(w=t.initialState)==null?void 0:w.filters,initialOperator:((E=t.initialState)==null?void 0:E.filterOperator)||"And"}),l=a.useMemo(()=>{const e={};return o.query&&(e.Search=o.query),s.payload&&(e.Filter=s.payload),e},[o.query,s.payload]),b=a.useMemo(()=>{const e={...l};return n.field&&n.direction&&(e.Sort=[{[String(n.field)]:n.direction==="asc"?"ASC":"DESC"}]),t.enablePagination&&(e.Page=i.pageNo,e.PageSize=i.pageSize),e},[l,n,i,t.enablePagination]),{data:u,isLoading:L,isFetching:R,error:x,refetch:q}=O.useQuery({queryKey:["table",t.source,b],queryFn:async()=>{try{const e=await Q.api(t.source).list(b);return t.onSuccess&&t.onSuccess(e.Data),e}catch(e){throw t.onError&&t.onError(e),e}},staleTime:0,gcTime:0}),{data:g,isLoading:A,isFetching:D,error:G,refetch:C}=O.useQuery({queryKey:["table-count",t.source,l],queryFn:async()=>{try{return await Q.api(t.source).count(l)}catch(e){throw t.onError&&t.onError(e),e}},staleTime:0,gcTime:0}),K=a.useMemo(()=>(u==null?void 0:u.Data)||[],[u]),S=a.useMemo(()=>(g==null?void 0:g.Count)||0,[g]),d=a.useMemo(()=>Math.ceil(S/i.pageSize),[S,i.pageSize]),j=a.useCallback(e=>{y(r=>{if(r.field===e){if(r.direction==="asc")return{field:e,direction:"desc"};if(r.direction==="desc")return{field:null,direction:null}}return{field:e,direction:"asc"}})},[]),I=a.useCallback(()=>{y({field:null,direction:null})},[]),B=a.useCallback((e,r)=>{y({field:e,direction:r})},[]),H=a.useCallback(e=>{p({query:e}),c(r=>({...r,pageNo:1}))},[]),J=a.useCallback(()=>{p({query:""})},[]),f=i.pageNo<d,h=i.pageNo>1,U=a.useCallback(()=>{f&&c(e=>({...e,pageNo:e.pageNo+1}))},[f]),V=a.useCallback(()=>{h&&c(e=>({...e,pageNo:e.pageNo-1}))},[h]),W=a.useCallback(e=>{const r=Math.max(1,Math.min(e,d));c(Z=>({...Z,pageNo:r}))},[d]),X=a.useCallback(e=>{c(r=>({...r,pageSize:e,pageNo:1}))},[]),Y=a.useCallback(async()=>{const[e]=await Promise.all([q(),C()]);return e.data||{Data:[]}},[q,C]);return{rows:K,totalItems:S,isLoading:L||A,isFetching:R||D,error:x||G,search:{query:o.query,setQuery:H,clear:J},sort:{field:n.field,direction:n.direction,toggle:j,clear:I,set:B},filter:s,pagination:{currentPage:i.pageNo,pageSize:i.pageSize,totalPages:d,totalItems:S,canGoNext:f,canGoPrevious:h,goToNext:U,goToPrevious:V,goToPage:W,setPageSize:X},refetch:Y}}exports.useTable=$;
package/dist/table.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { useState as m, useMemo as c, useCallback as i } from "react";
2
- import { u as A } from "./useQuery-KpZFg80c.js";
2
+ import { useQuery as A } from "@tanstack/react-query";
3
3
  import { a as D } from "./client-CfvLiGfP.js";
4
- import { u as v } from "./useFilter-CXFqEHyI.js";
4
+ import { u as v } from "./useFilter-Dv-mr9QW.js";
5
5
  function ae(t) {
6
6
  var F, T, C, b, w, E, x, L, M, O;
7
7
  const [s, N] = m({
@@ -0,0 +1 @@
1
+ "use strict";const u=require("react"),d=r=>"Condition"in r,R=r=>"LHSField"in r;let _=0;const l=()=>`filter_${Date.now()}_${++_}`,$=r=>r.id?r:{...r,id:l()},k=r=>r.map(o=>{const n=$(o);return d(n)?{...n,Condition:k(n.Condition)}:n}),O=r=>r.map(o=>{if(d(o)){const{id:b,...C}=o;return{...C,Condition:O(o.Condition)}}const{id:n,...t}=o;return t}),h=(r,o)=>{for(const n of r){if(n.id===o)return n;if(d(n)){const t=h(n.Condition,o);if(t)return t}}},f=(r,o,n)=>r.map(t=>t.id===o?n(t):d(t)?{...t,Condition:f(t.Condition,o,n)}:t),G=(r,o)=>r.filter(n=>n.id!==o).map(n=>d(n)?{...n,Condition:G(n.Condition,o)}:n),p=(r,o,n)=>r.map(t=>t.id===o&&d(t)?{...t,Condition:[...t.Condition,n]}:d(t)?{...t,Condition:p(t.Condition,o,n)}:t);function q(r={}){const[o,n]=u.useState(()=>k(r.initialConditions||[])),[t,b]=u.useState(r.initialOperator||"And"),C=u.useMemo(()=>{if(o.length!==0)return{Operator:t,Condition:O(o)}},[o,t]),g=o.length>0,v=u.useCallback((i,s)=>{const c=l(),e={...i,id:c};return n(s?a=>p(a,s,e):a=>[...a,e]),c},[]),F=u.useCallback((i,s)=>{const c=l(),e={id:c,Operator:i,Condition:[]};return n(s?a=>p(a,s,e):a=>[...a,e]),c},[]),I=u.useCallback((i,s)=>{n(c=>f(c,i,e=>d(e)?e:{...e,...s}))},[]),S=u.useCallback((i,s)=>{n(c=>f(c,i,e=>d(e)?{...e,Operator:s}:e))},[]),w=u.useCallback(i=>{n(s=>G(s,i))},[]),T=u.useCallback(i=>h(o,i),[o]),y=u.useCallback(()=>{n([])},[]),A=u.useCallback(i=>{b(i)},[]);return{operator:t,items:o,payload:C,hasConditions:g,addCondition:v,addConditionGroup:F,updateCondition:I,updateGroupOperator:S,removeCondition:w,getCondition:T,clearAllConditions:y,setRootOperator:A}}exports.isCondition=R;exports.isConditionGroup=d;exports.useFilter=q;
@@ -0,0 +1,117 @@
1
+ import { useState as h, useMemo as k, useCallback as c } from "react";
2
+ const u = (t) => "Condition" in t, H = (t) => "LHSField" in t;
3
+ let x = 0;
4
+ const f = () => `filter_${Date.now()}_${++x}`, B = (t) => t.id ? t : { ...t, id: f() }, g = (t) => t.map((o) => {
5
+ const n = B(o);
6
+ return u(n) ? {
7
+ ...n,
8
+ Condition: g(n.Condition)
9
+ } : n;
10
+ }), v = (t) => t.map((o) => {
11
+ if (u(o)) {
12
+ const { id: O, ...C } = o;
13
+ return {
14
+ ...C,
15
+ Condition: v(o.Condition)
16
+ };
17
+ }
18
+ const { id: n, ...r } = o;
19
+ return r;
20
+ }), G = (t, o) => {
21
+ for (const n of t) {
22
+ if (n.id === o)
23
+ return n;
24
+ if (u(n)) {
25
+ const r = G(n.Condition, o);
26
+ if (r) return r;
27
+ }
28
+ }
29
+ }, p = (t, o, n) => t.map((r) => r.id === o ? n(r) : u(r) ? {
30
+ ...r,
31
+ Condition: p(r.Condition, o, n)
32
+ } : r), I = (t, o) => t.filter((n) => n.id !== o).map((n) => u(n) ? {
33
+ ...n,
34
+ Condition: I(n.Condition, o)
35
+ } : n), l = (t, o, n) => t.map((r) => r.id === o && u(r) ? {
36
+ ...r,
37
+ Condition: [...r.Condition, n]
38
+ } : u(r) ? {
39
+ ...r,
40
+ Condition: l(r.Condition, o, n)
41
+ } : r);
42
+ function L(t = {}) {
43
+ const [o, n] = h(
44
+ () => g(t.initialConditions || [])
45
+ ), [r, O] = h(
46
+ t.initialOperator || "And"
47
+ ), C = k(() => {
48
+ if (o.length !== 0)
49
+ return {
50
+ Operator: r,
51
+ Condition: v(o)
52
+ };
53
+ }, [o, r]), w = o.length > 0, F = c(
54
+ (i, s) => {
55
+ const d = f(), e = { ...i, id: d };
56
+ return n(s ? (a) => l(a, s, e) : (a) => [...a, e]), d;
57
+ },
58
+ []
59
+ ), S = c(
60
+ (i, s) => {
61
+ const d = f(), e = {
62
+ id: d,
63
+ Operator: i,
64
+ Condition: []
65
+ };
66
+ return n(s ? (a) => l(a, s, e) : (a) => [...a, e]), d;
67
+ },
68
+ []
69
+ ), T = c(
70
+ (i, s) => {
71
+ n(
72
+ (d) => p(d, i, (e) => u(e) ? e : { ...e, ...s })
73
+ );
74
+ },
75
+ []
76
+ ), y = c(
77
+ (i, s) => {
78
+ n(
79
+ (d) => p(d, i, (e) => u(e) ? { ...e, Operator: s } : e)
80
+ );
81
+ },
82
+ []
83
+ ), A = c((i) => {
84
+ n((s) => I(s, i));
85
+ }, []), _ = c(
86
+ (i) => G(o, i),
87
+ [o]
88
+ ), $ = c(() => {
89
+ n([]);
90
+ }, []), b = c((i) => {
91
+ O(i);
92
+ }, []);
93
+ return {
94
+ // State
95
+ operator: r,
96
+ items: o,
97
+ payload: C,
98
+ hasConditions: w,
99
+ // Add operations
100
+ addCondition: F,
101
+ addConditionGroup: S,
102
+ // Update operations
103
+ updateCondition: T,
104
+ updateGroupOperator: y,
105
+ // Remove & access
106
+ removeCondition: A,
107
+ getCondition: _,
108
+ // Utility
109
+ clearAllConditions: $,
110
+ setRootOperator: b
111
+ };
112
+ }
113
+ export {
114
+ u as a,
115
+ H as i,
116
+ L as u
117
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ram_28/kf-ai-sdk",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "Type-safe, AI-driven SDK for building modern web applications with role-based access control",
5
5
  "author": "Ramprasad",
6
6
  "license": "MIT",
@@ -41,6 +41,20 @@ export const isCondition = (
41
41
  // HOOK-SPECIFIC TYPE DEFINITIONS
42
42
  // ============================================================
43
43
 
44
+ /**
45
+ * Builder interface for fluent condition group construction
46
+ */
47
+ export interface ConditionGroupBuilder {
48
+ /** The id of the created group */
49
+ readonly id: string;
50
+
51
+ /** Add a condition to this group */
52
+ addCondition(condition: Omit<ConditionType, "id">): ConditionGroupBuilder;
53
+
54
+ /** Add a nested condition group */
55
+ addConditionGroup(operator: ConditionGroupOperatorType): ConditionGroupBuilder;
56
+ }
57
+
44
58
  /**
45
59
  * Hook options (minimal configuration)
46
60
  */
@@ -76,30 +90,20 @@ export interface UseFilterReturnType {
76
90
  // ============================================================
77
91
 
78
92
  /**
79
- * Add a leaf condition at root level
80
- * @returns The id of the created condition
81
- */
82
- add: (condition: Omit<ConditionType, "id">) => string;
83
-
84
- /**
85
- * Add a condition group at root level
86
- * @returns The id of the created group
87
- */
88
- addGroup: (operator: ConditionGroupOperatorType) => string;
89
-
90
- /**
91
- * Add a leaf condition to a specific parent group
92
- * @param parentId - The id of the parent ConditionGroup
93
+ * Add a leaf condition at root level or to a specific parent group
94
+ * @param condition - The condition to add (without id)
95
+ * @param parentId - Optional id of the parent ConditionGroup. If omitted, adds at root level
93
96
  * @returns The id of the created condition
94
97
  */
95
- addTo: (parentId: string, condition: Omit<ConditionType, "id">) => string;
98
+ addCondition: (condition: Omit<ConditionType, "id">, parentId?: string) => string;
96
99
 
97
100
  /**
98
- * Add a condition group to a specific parent group
99
- * @param parentId - The id of the parent ConditionGroup
101
+ * Add a condition group at root level or to a specific parent group
102
+ * @param operator - The operator for the new group ("And" | "Or" | "Not")
103
+ * @param parentId - Optional id of the parent ConditionGroup. If omitted, adds at root level
100
104
  * @returns The id of the created group
101
105
  */
102
- addGroupTo: (parentId: string, operator: ConditionGroupOperatorType) => string;
106
+ addConditionGroup: (operator: ConditionGroupOperatorType, parentId?: string) => string;
103
107
 
104
108
  // ============================================================
105
109
  // UPDATE OPERATIONS
@@ -110,14 +114,14 @@ export interface UseFilterReturnType {
110
114
  * @param id - The id of the condition to update
111
115
  * @param updates - Partial updates to apply
112
116
  */
113
- update: (id: string, updates: Partial<Omit<ConditionType, "id">>) => void;
117
+ updateCondition: (id: string, updates: Partial<Omit<ConditionType, "id">>) => void;
114
118
 
115
119
  /**
116
120
  * Update a condition group's operator by id
117
121
  * @param id - The id of the group to update
118
122
  * @param operator - The new operator
119
123
  */
120
- updateOperator: (id: string, operator: ConditionGroupOperatorType) => void;
124
+ updateGroupOperator: (id: string, operator: ConditionGroupOperatorType) => void;
121
125
 
122
126
  // ============================================================
123
127
  // REMOVE & ACCESS
@@ -127,22 +131,22 @@ export interface UseFilterReturnType {
127
131
  * Remove a condition or group by id
128
132
  * @param id - The id of the item to remove
129
133
  */
130
- remove: (id: string) => void;
134
+ removeCondition: (id: string) => void;
131
135
 
132
136
  /**
133
137
  * Get a condition or group by id
134
138
  * @param id - The id to look up
135
139
  * @returns The item or undefined if not found
136
140
  */
137
- get: (id: string) => ConditionType | ConditionGroupType | undefined;
141
+ getCondition: (id: string) => ConditionType | ConditionGroupType | undefined;
138
142
 
139
143
  // ============================================================
140
144
  // UTILITY
141
145
  // ============================================================
142
146
 
143
147
  /** Clear all conditions */
144
- clear: () => void;
148
+ clearAllConditions: () => void;
145
149
 
146
150
  /** Set the root operator for combining conditions */
147
- setOperator: (op: ConditionGroupOperatorType) => void;
151
+ setRootOperator: (op: ConditionGroupOperatorType) => void;
148
152
  }