@ram_28/kf-ai-sdk 2.0.13 → 2.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.
- package/README.md +2 -1
- package/dist/FileField-BWrSHNRq.js +296 -0
- package/dist/FileField-eDeuzln8.cjs +1 -0
- package/dist/api.cjs +1 -1
- package/dist/api.mjs +2 -2
- package/dist/auth.cjs +1 -1
- package/dist/auth.mjs +1 -1
- package/dist/bdo.cjs +1 -1
- package/dist/bdo.mjs +228 -472
- package/dist/{client-DnO2KKrw.cjs → client-D5k4SYuw.cjs} +1 -1
- package/dist/{client-iQTqFDNI.js → client-_ayziI1d.js} +33 -32
- package/dist/components/hooks/index.d.ts +9 -3
- package/dist/components/hooks/index.d.ts.map +1 -1
- package/dist/{workflow/components → components/hooks}/useActivityForm/createActivityItemProxy.d.ts +9 -5
- package/dist/components/hooks/useActivityForm/createActivityItemProxy.d.ts.map +1 -0
- package/dist/components/hooks/useActivityForm/createActivityResolver.d.ts +23 -0
- package/dist/components/hooks/useActivityForm/createActivityResolver.d.ts.map +1 -0
- package/dist/components/hooks/useActivityForm/index.d.ts.map +1 -0
- package/dist/{workflow/components → components/hooks}/useActivityForm/types.d.ts +11 -7
- package/dist/components/hooks/useActivityForm/types.d.ts.map +1 -0
- package/dist/{workflow/components → components/hooks}/useActivityForm/useActivityForm.d.ts +2 -2
- package/dist/components/hooks/useActivityForm/useActivityForm.d.ts.map +1 -0
- package/dist/components/hooks/useActivityTable/index.d.ts +4 -0
- package/dist/components/hooks/useActivityTable/index.d.ts.map +1 -0
- package/dist/components/hooks/useActivityTable/types.d.ts +36 -0
- package/dist/components/hooks/useActivityTable/types.d.ts.map +1 -0
- package/dist/components/hooks/useActivityTable/useActivityTable.d.ts +4 -0
- package/dist/components/hooks/useActivityTable/useActivityTable.d.ts.map +1 -0
- package/dist/components/hooks/useBDOTable/index.d.ts +3 -0
- package/dist/components/hooks/useBDOTable/index.d.ts.map +1 -0
- package/dist/components/hooks/useBDOTable/types.d.ts +26 -0
- package/dist/components/hooks/useBDOTable/types.d.ts.map +1 -0
- package/dist/components/hooks/useBDOTable/useBDOTable.d.ts +3 -0
- package/dist/components/hooks/useBDOTable/useBDOTable.d.ts.map +1 -0
- package/dist/components/hooks/useTable/index.d.ts +2 -2
- package/dist/components/hooks/useTable/index.d.ts.map +1 -1
- package/dist/components/hooks/useTable/types.d.ts +11 -10
- package/dist/components/hooks/useTable/types.d.ts.map +1 -1
- package/dist/components/hooks/useTable/useTable.d.ts +1 -1
- package/dist/components/hooks/useTable/useTable.d.ts.map +1 -1
- package/dist/createResolver-AIgUwoS6.cjs +1 -0
- package/dist/createResolver-ZHXQ7QMa.js +1078 -0
- package/dist/form.cjs +1 -1
- package/dist/form.mjs +252 -314
- package/dist/{metadata-DpfI3zRN.js → metadata-Cc1mBcLS.js} +1 -1
- package/dist/{metadata-DgLSJkF5.cjs → metadata-DWXQPDav.cjs} +1 -1
- package/dist/table.cjs +1 -1
- package/dist/table.d.ts +1 -0
- package/dist/table.d.ts.map +1 -1
- package/dist/table.mjs +16 -192
- package/dist/table.types.d.ts +2 -1
- package/dist/table.types.d.ts.map +1 -1
- package/dist/types/base-fields.d.ts +4 -4
- package/dist/types/base-fields.d.ts.map +1 -1
- package/dist/useTable-CeRklbdT.cjs +1 -0
- package/dist/useTable-DS0-WInw.js +203 -0
- package/dist/workflow/Activity.d.ts +9 -9
- package/dist/workflow/Activity.d.ts.map +1 -1
- package/dist/workflow/client.d.ts.map +1 -1
- package/dist/workflow/createFieldFromMeta.d.ts +29 -0
- package/dist/workflow/createFieldFromMeta.d.ts.map +1 -0
- package/dist/workflow/index.d.ts +1 -2
- package/dist/workflow/index.d.ts.map +1 -1
- package/dist/workflow/types.d.ts +12 -12
- package/dist/workflow/types.d.ts.map +1 -1
- package/dist/workflow.cjs +1 -1
- package/dist/workflow.d.ts +5 -2
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.mjs +716 -338
- package/dist/workflow.types.d.ts +1 -0
- package/dist/workflow.types.d.ts.map +1 -1
- package/docs/bdo.md +3 -3
- package/docs/gaps.md +410 -0
- package/docs/useActivityTable.md +481 -0
- package/docs/useBDOTable.md +317 -0
- package/docs/useForm.md +4 -1
- package/docs/workflow.md +143 -34
- package/package.json +1 -1
- package/sdk/bdo/fields/UserField.ts +1 -1
- package/sdk/components/hooks/index.ts +28 -5
- package/sdk/components/hooks/useActivityForm/createActivityItemProxy.ts +400 -0
- package/sdk/components/hooks/useActivityForm/createActivityResolver.ts +87 -0
- package/sdk/{workflow/components → components/hooks}/useActivityForm/types.ts +21 -8
- package/sdk/components/hooks/useActivityForm/useActivityForm.ts +628 -0
- package/sdk/components/hooks/useActivityTable/index.ts +8 -0
- package/sdk/components/hooks/useActivityTable/types.ts +45 -0
- package/sdk/components/hooks/useActivityTable/useActivityTable.ts +71 -0
- package/sdk/components/hooks/useBDOTable/index.ts +2 -0
- package/sdk/components/hooks/useBDOTable/types.ts +24 -0
- package/sdk/components/hooks/useBDOTable/useBDOTable.ts +15 -0
- package/sdk/components/hooks/useTable/index.ts +3 -3
- package/sdk/components/hooks/useTable/types.ts +16 -12
- package/sdk/components/hooks/useTable/useTable.ts +56 -49
- package/sdk/table.ts +4 -1
- package/sdk/table.types.ts +7 -4
- package/sdk/types/base-fields.ts +4 -4
- package/sdk/workflow/Activity.ts +14 -13
- package/sdk/workflow/client.ts +21 -8
- package/sdk/workflow/createFieldFromMeta.ts +110 -0
- package/sdk/workflow/index.ts +1 -6
- package/sdk/workflow/types.ts +13 -12
- package/sdk/workflow.ts +11 -2
- package/sdk/workflow.types.ts +7 -0
- package/dist/BaseField-B6da88U7.js +0 -40
- package/dist/BaseField-Drp0-OxL.cjs +0 -1
- package/dist/error-handling-CAoD0Kwb.cjs +0 -1
- package/dist/error-handling-CrhTtD88.js +0 -14
- package/dist/index.esm-Cj63v5ny.js +0 -1014
- package/dist/index.esm-DuwT11sx.cjs +0 -1
- package/dist/workflow/components/useActivityForm/createActivityItemProxy.d.ts.map +0 -1
- package/dist/workflow/components/useActivityForm/createActivityResolver.d.ts +0 -22
- package/dist/workflow/components/useActivityForm/createActivityResolver.d.ts.map +0 -1
- package/dist/workflow/components/useActivityForm/index.d.ts.map +0 -1
- package/dist/workflow/components/useActivityForm/types.d.ts.map +0 -1
- package/dist/workflow/components/useActivityForm/useActivityForm.d.ts.map +0 -1
- package/docs/useTable.md +0 -369
- package/sdk/workflow/components/useActivityForm/createActivityItemProxy.ts +0 -130
- package/sdk/workflow/components/useActivityForm/createActivityResolver.ts +0 -61
- package/sdk/workflow/components/useActivityForm/useActivityForm.ts +0 -386
- /package/dist/{workflow/components → components/hooks}/useActivityForm/index.d.ts +0 -0
- /package/sdk/{workflow/components → components/hooks}/useActivityForm/index.ts +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const P=require("react");var he=e=>e.type==="checkbox",re=e=>e instanceof Date,I=e=>e==null;const rt=e=>typeof e=="object";var k=e=>!I(e)&&!Array.isArray(e)&&rt(e)&&!re(e),_t=e=>k(e)&&e.target?he(e.target)?e.target.checked:e.target.value:e,Ft=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,At=(e,s)=>e.has(Ft(s)),xt=e=>{const s=e.constructor&&e.constructor.prototype;return k(s)&&s.hasOwnProperty("isPrototypeOf")},Se=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function T(e){if(e instanceof Date)return new Date(e);const s=typeof FileList<"u"&&e instanceof FileList;if(Se&&(e instanceof Blob||s))return e;const r=Array.isArray(e);if(!r&&!(k(e)&&xt(e)))return e;const a=r?[]:Object.create(Object.getPrototypeOf(e));for(const u in e)Object.prototype.hasOwnProperty.call(e,u)&&(a[u]=T(e[u]));return a}var _e=e=>/^\w*$/.test(e),w=e=>e===void 0,Oe=e=>Array.isArray(e)?e.filter(Boolean):[],Te=e=>Oe(e.replace(/["|']|\]/g,"").split(/\.|\[/)),h=(e,s,r)=>{if(!s||!k(e))return r;const a=(_e(s)?[s]:Te(s)).reduce((u,n)=>I(u)?u:u[n],e);return w(a)||a===e?w(e[s])?r:e[s]:a},K=e=>typeof e=="boolean",p=e=>typeof e=="function",m=(e,s,r)=>{let a=-1;const u=_e(s)?[s]:Te(s),n=u.length,d=n-1;for(;++a<n;){const y=u[a];let U=r;if(a!==d){const j=e[y];U=k(j)||Array.isArray(j)?j:isNaN(+u[a+1])?{}:[]}if(y==="__proto__"||y==="constructor"||y==="prototype")return;e[y]=U,e=e[y]}};const $e={BLUR:"blur",FOCUS_OUT:"focusout"},$={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},X={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},mt=P.createContext(null);mt.displayName="HookFormContext";var wt=(e,s,r,a=!0)=>{const u={defaultValues:s._defaultValues};for(const n in e)Object.defineProperty(u,n,{get:()=>{const d=n;return s._proxyFormState[d]!==$.all&&(s._proxyFormState[d]=!a||$.all),e[d]}});return u};const Dt=typeof window<"u"?P.useLayoutEffect:P.useEffect;var B=e=>typeof e=="string",kt=(e,s,r,a,u)=>B(e)?(a&&s.watch.add(e),h(r,e,u)):Array.isArray(e)?e.map(n=>(a&&s.watch.add(n),h(r,n))):(a&&(s.watchAll=!0),r),ke=e=>I(e)||!rt(e);function G(e,s,r=new WeakSet){if(ke(e)||ke(s))return Object.is(e,s);if(re(e)&&re(s))return Object.is(e.getTime(),s.getTime());const a=Object.keys(e),u=Object.keys(s);if(a.length!==u.length)return!1;if(r.has(e)||r.has(s))return!0;r.add(e),r.add(s);for(const n of a){const d=e[n];if(!u.includes(n))return!1;if(n!=="ref"){const y=s[n];if(re(d)&&re(y)||k(d)&&k(y)||Array.isArray(d)&&Array.isArray(y)?!G(d,y,r):!Object.is(d,y))return!1}}return!0}var Et=(e,s,r,a,u)=>s?{...r[e],types:{...r[e]&&r[e].types?r[e].types:{},[a]:u||!0}}:{},ce=e=>Array.isArray(e)?e:[e],je=()=>{let e=[];return{get observers(){return e},next:u=>{for(const n of e)n.next&&n.next(u)},subscribe:u=>(e.push(u),{unsubscribe:()=>{e=e.filter(n=>n!==u)}}),unsubscribe:()=>{e=[]}}};function st(e,s){const r={};for(const a in e)if(e.hasOwnProperty(a)){const u=e[a],n=s[a];if(u&&k(u)&&n){const d=st(u,n);k(d)&&(r[a]=d)}else e[a]&&(r[a]=n)}return r}var R=e=>k(e)&&!Object.keys(e).length,Ce=e=>e.type==="file",be=e=>{if(!Se)return!1;const s=e?e.ownerDocument:0;return e instanceof(s&&s.defaultView?s.defaultView.HTMLElement:HTMLElement)},it=e=>e.type==="select-multiple",Le=e=>e.type==="radio",St=e=>Le(e)||he(e),De=e=>be(e)&&e.isConnected;function Ot(e,s){const r=s.slice(0,-1).length;let a=0;for(;a<r;)e=w(e)?a++:e[s[a++]];return e}function Tt(e){for(const s in e)if(e.hasOwnProperty(s)&&!w(e[s]))return!1;return!0}function D(e,s){const r=Array.isArray(s)?s:_e(s)?[s]:Te(s),a=r.length===1?e:Ot(e,r),u=r.length-1,n=r[u];return a&&delete a[n],u!==0&&(k(a)&&R(a)||Array.isArray(a)&&Tt(a))&&D(e,r.slice(0,-1)),e}var Ct=e=>{for(const s in e)if(p(e[s]))return!0;return!1};function at(e){return Array.isArray(e)||k(e)&&!Ct(e)}function Ee(e,s={}){for(const r in e){const a=e[r];at(a)?(s[r]=Array.isArray(a)?[]:{},Ee(a,s[r])):w(a)||(s[r]=!0)}return s}function ae(e,s,r){r||(r=Ee(s));for(const a in e){const u=e[a];if(at(u))w(s)||ke(r[a])?r[a]=Ee(u,Array.isArray(u)?[]:{}):ae(u,I(s)?{}:s[a],r[a]);else{const n=s[a];r[a]=!G(u,n)}}return r}const Ke={value:!1,isValid:!1},ze={value:!0,isValid:!0};var lt=e=>{if(Array.isArray(e)){if(e.length>1){const s=e.filter(r=>r&&r.checked&&!r.disabled).map(r=>r.value);return{value:s,isValid:!!s.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!w(e[0].attributes.value)?w(e[0].value)||e[0].value===""?ze:{value:e[0].value,isValid:!0}:ze:Ke}return Ke},nt=(e,{valueAsNumber:s,valueAsDate:r,setValueAs:a})=>w(e)?e:s?e===""?NaN:e&&+e:r&&B(e)?new Date(e):a?a(e):e;const Ye={isValid:!1,value:null};var ut=e=>Array.isArray(e)?e.reduce((s,r)=>r&&r.checked&&!r.disabled?{isValid:!0,value:r.value}:s,Ye):Ye;function Je(e){const s=e.ref;return Ce(s)?s.files:Le(s)?ut(e.refs).value:it(s)?[...s.selectedOptions].map(({value:r})=>r):he(s)?lt(e.refs).value:nt(w(s.value)?e.ref.value:s.value,e)}var Lt=(e,s,r,a)=>{const u={};for(const n of e){const d=h(s,n);d&&m(u,n,d._f)}return{criteriaMode:r,names:[...e],fields:u,shouldUseNativeValidation:a}},Ve=e=>e instanceof RegExp,de=e=>w(e)?e:Ve(e)?e.source:k(e)?Ve(e.value)?e.value.source:e.value:e,Qe=e=>({isOnSubmit:!e||e===$.onSubmit,isOnBlur:e===$.onBlur,isOnChange:e===$.onChange,isOnAll:e===$.all,isOnTouch:e===$.onTouched});const Xe="AsyncFunction";var Rt=e=>!!e&&!!e.validate&&!!(p(e.validate)&&e.validate.constructor.name===Xe||k(e.validate)&&Object.values(e.validate).find(s=>s.constructor.name===Xe)),Ut=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate),Ze=(e,s,r)=>!r&&(s.watchAll||s.watch.has(e)||[...s.watch].some(a=>e.startsWith(a)&&/^\.\w+/.test(e.slice(a.length))));const ye=(e,s,r,a)=>{for(const u of r||Object.keys(e)){const n=h(e,u);if(n){const{_f:d,...y}=n;if(d){if(d.refs&&d.refs[0]&&s(d.refs[0],u)&&!a)return!0;if(d.ref&&s(d.ref,d.name)&&!a)return!0;if(ye(y,s))break}else if(k(y)&&ye(y,s))break}}};function Ge(e,s,r){const a=h(e,r);if(a||_e(r))return{error:a,name:r};const u=r.split(".");for(;u.length;){const n=u.join("."),d=h(s,n),y=h(e,n);if(d&&!Array.isArray(d)&&r!==n)return{name:r};if(y&&y.type)return{name:n,error:y};if(y&&y.root&&y.root.type)return{name:`${n}.root`,error:y.root};u.pop()}return{name:r}}var It=(e,s,r,a)=>{r(e);const{name:u,...n}=e;return R(n)||Object.keys(n).length>=Object.keys(s).length||Object.keys(n).find(d=>s[d]===(!a||$.all))},Mt=(e,s,r)=>!e||!s||e===s||ce(e).some(a=>a&&(r?a===s:a.startsWith(s)||s.startsWith(a))),Nt=(e,s,r,a,u)=>u.isOnAll?!1:!r&&u.isOnTouch?!(s||e):(r?a.isOnBlur:u.isOnBlur)?!e:(r?a.isOnChange:u.isOnChange)?e:!0,Pt=(e,s)=>!Oe(h(e,s)).length&&D(e,s),Bt=(e,s,r)=>{const a=ce(h(e,r));return m(a,"root",s[r]),m(e,r,a),e};function et(e,s,r="validate"){if(B(e)||Array.isArray(e)&&e.every(B)||K(e)&&!e)return{type:r,message:B(e)?e:"",ref:s}}var ie=e=>k(e)&&!Ve(e)?e:{value:e,message:""},tt=async(e,s,r,a,u,n)=>{const{ref:d,refs:y,required:U,maxLength:j,minLength:le,min:x,max:E,pattern:b,validate:z,name:M,valueAsNumber:Y,mount:q}=e._f,V=h(r,M);if(!q||s.has(M))return{};const J=y?y[0]:d,Q=v=>{u&&J.reportValidity&&(J.setCustomValidity(K(v)?"":v||""),J.reportValidity())},S={},ne=Le(d),ge=he(d),ee=ne||ge,se=(Y||Ce(d))&&w(d.value)&&w(V)||be(d)&&d.value===""||V===""||Array.isArray(V)&&!V.length,W=Et.bind(null,M,a,S),ve=(v,_,O,C=X.maxLength,H=X.minLength)=>{const N=v?_:O;S[M]={type:v?C:H,message:N,ref:d,...W(v?C:H,N)}};if(n?!Array.isArray(V)||!V.length:U&&(!ee&&(se||I(V))||K(V)&&!V||ge&&!lt(y).isValid||ne&&!ut(y).isValid)){const{value:v,message:_}=B(U)?{value:!!U,message:U}:ie(U);if(v&&(S[M]={type:X.required,message:_,ref:J,...W(X.required,_)},!a))return Q(_),S}if(!se&&(!I(x)||!I(E))){let v,_;const O=ie(E),C=ie(x);if(!I(V)&&!isNaN(V)){const H=d.valueAsNumber||V&&+V;I(O.value)||(v=H>O.value),I(C.value)||(_=H<C.value)}else{const H=d.valueAsDate||new Date(V),N=fe=>new Date(new Date().toDateString()+" "+fe),ue=d.type=="time",oe=d.type=="week";B(O.value)&&V&&(v=ue?N(V)>N(O.value):oe?V>O.value:H>new Date(O.value)),B(C.value)&&V&&(_=ue?N(V)<N(C.value):oe?V<C.value:H<new Date(C.value))}if((v||_)&&(ve(!!v,O.message,C.message,X.max,X.min),!a))return Q(S[M].message),S}if((j||le)&&!se&&(B(V)||n&&Array.isArray(V))){const v=ie(j),_=ie(le),O=!I(v.value)&&V.length>+v.value,C=!I(_.value)&&V.length<+_.value;if((O||C)&&(ve(O,v.message,_.message),!a))return Q(S[M].message),S}if(b&&!se&&B(V)){const{value:v,message:_}=ie(b);if(Ve(v)&&!V.match(v)&&(S[M]={type:X.pattern,message:_,ref:d,...W(X.pattern,_)},!a))return Q(_),S}if(z){if(p(z)){const v=await z(V,r),_=et(v,J);if(_&&(S[M]={..._,...W(X.validate,_.message)},!a))return Q(_.message),S}else if(k(z)){let v={};for(const _ in z){if(!R(v)&&!a)break;const O=et(await z[_](V,r),J,_);O&&(v={...O,...W(_,O.message)},Q(O.message),a&&(S[M]=v))}if(!R(v)&&(S[M]={ref:J,...v},!a))return S}}return Q(!0),S};const qt={mode:$.onSubmit,reValidateMode:$.onChange,shouldFocusError:!0};function Wt(e={}){let s={...qt,...e},r={submitCount:0,isDirty:!1,isReady:!1,isLoading:p(s.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:s.errors||{},disabled:s.disabled||!1},a={},u=k(s.defaultValues)||k(s.values)?T(s.defaultValues||s.values)||{}:{},n=s.shouldUnregister?{}:T(u),d={action:!1,mount:!1,watch:!1,keepIsValid:!1},y={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},U,j=0;const le={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},x={...le};let E={...x};const b={array:je(),state:je()},z=s.criteriaMode===$.all,M=t=>i=>{clearTimeout(j),j=setTimeout(t,i)},Y=async t=>{if(!d.keepIsValid&&!s.disabled&&(x.isValid||E.isValid||t)){let i;s.resolver?(i=R((await ee()).errors),q()):i=await W(a,!0),i!==r.isValid&&b.state.next({isValid:i})}},q=(t,i)=>{!s.disabled&&(x.isValidating||x.validatingFields||E.isValidating||E.validatingFields)&&((t||Array.from(y.mount)).forEach(l=>{l&&(i?m(r.validatingFields,l,i):D(r.validatingFields,l))}),b.state.next({validatingFields:r.validatingFields,isValidating:!R(r.validatingFields)}))},V=(t,i=[],l,c,f=!0,o=!0)=>{if(c&&l&&!s.disabled){if(d.action=!0,o&&Array.isArray(h(a,t))){const g=l(h(a,t),c.argA,c.argB);f&&m(a,t,g)}if(o&&Array.isArray(h(r.errors,t))){const g=l(h(r.errors,t),c.argA,c.argB);f&&m(r.errors,t,g),Pt(r.errors,t)}if((x.touchedFields||E.touchedFields)&&o&&Array.isArray(h(r.touchedFields,t))){const g=l(h(r.touchedFields,t),c.argA,c.argB);f&&m(r.touchedFields,t,g)}(x.dirtyFields||E.dirtyFields)&&(r.dirtyFields=ae(u,n)),b.state.next({name:t,isDirty:v(t,i),dirtyFields:r.dirtyFields,errors:r.errors,isValid:r.isValid})}else m(n,t,i)},J=(t,i)=>{m(r.errors,t,i),b.state.next({errors:r.errors})},Q=t=>{r.errors=t,b.state.next({errors:r.errors,isValid:!1})},S=(t,i,l,c)=>{const f=h(a,t);if(f){const o=h(n,t,w(l)?h(u,t):l);w(o)||c&&c.defaultChecked||i?m(n,t,i?o:Je(f._f)):C(t,o),d.mount&&!d.action&&Y()}},ne=(t,i,l,c,f)=>{let o=!1,g=!1;const F={name:t};if(!s.disabled){if(!l||c){(x.isDirty||E.isDirty)&&(g=r.isDirty,r.isDirty=F.isDirty=v(),o=g!==F.isDirty);const A=G(h(u,t),i);g=!!h(r.dirtyFields,t),A?D(r.dirtyFields,t):m(r.dirtyFields,t,!0),F.dirtyFields=r.dirtyFields,o=o||(x.dirtyFields||E.dirtyFields)&&g!==!A}if(l){const A=h(r.touchedFields,t);A||(m(r.touchedFields,t,l),F.touchedFields=r.touchedFields,o=o||(x.touchedFields||E.touchedFields)&&A!==l)}o&&f&&b.state.next(F)}return o?F:{}},ge=(t,i,l,c)=>{const f=h(r.errors,t),o=(x.isValid||E.isValid)&&K(i)&&r.isValid!==i;if(s.delayError&&l?(U=M(()=>J(t,l)),U(s.delayError)):(clearTimeout(j),U=null,l?m(r.errors,t,l):D(r.errors,t)),(l?!G(f,l):f)||!R(c)||o){const g={...c,...o&&K(i)?{isValid:i}:{},errors:r.errors,name:t};r={...r,...g},b.state.next(g)}},ee=async t=>(q(t,!0),await s.resolver(n,s.context,Lt(t||y.mount,a,s.criteriaMode,s.shouldUseNativeValidation))),se=async t=>{const{errors:i}=await ee(t);if(q(t),t)for(const l of t){const c=h(i,l);c?m(r.errors,l,c):D(r.errors,l)}else r.errors=i;return i},W=async(t,i,l={valid:!0})=>{for(const c in t){const f=t[c];if(f){const{_f:o,...g}=f;if(o){const F=y.array.has(o.name),A=f._f&&Rt(f._f);A&&x.validatingFields&&q([o.name],!0);const L=await tt(f,y.disabled,n,z,s.shouldUseNativeValidation&&!i,F);if(A&&x.validatingFields&&q([o.name]),L[o.name]&&(l.valid=!1,i||e.shouldUseNativeValidation))break;!i&&(h(L,o.name)?F?Bt(r.errors,L,o.name):m(r.errors,o.name,L[o.name]):D(r.errors,o.name))}!R(g)&&await W(g,i,l)}}return l.valid},ve=()=>{for(const t of y.unMount){const i=h(a,t);i&&(i._f.refs?i._f.refs.every(l=>!De(l)):!De(i._f.ref))&&Fe(t)}y.unMount=new Set},v=(t,i)=>!s.disabled&&(t&&i&&m(n,t,i),!G(Re(),u)),_=(t,i,l)=>kt(t,y,{...d.mount?n:w(i)?u:B(t)?{[t]:i}:i},l,i),O=t=>Oe(h(d.mount?n:u,t,s.shouldUnregister?h(u,t,[]):[])),C=(t,i,l={})=>{const c=h(a,t);let f=i;if(c){const o=c._f;o&&(!o.disabled&&m(n,t,nt(i,o)),f=be(o.ref)&&I(i)?"":i,it(o.ref)?[...o.ref.options].forEach(g=>g.selected=f.includes(g.value)):o.refs?he(o.ref)?o.refs.forEach(g=>{(!g.defaultChecked||!g.disabled)&&(Array.isArray(f)?g.checked=!!f.find(F=>F===g.value):g.checked=f===g.value||!!f)}):o.refs.forEach(g=>g.checked=g.value===f):Ce(o.ref)?o.ref.value="":(o.ref.value=f,o.ref.type||b.state.next({name:t,values:T(n)})))}(l.shouldDirty||l.shouldTouch)&&ne(t,f,l.shouldTouch,l.shouldDirty,!0),l.shouldValidate&&fe(t)},H=(t,i,l)=>{for(const c in i){if(!i.hasOwnProperty(c))return;const f=i[c],o=t+"."+c,g=h(a,o);(y.array.has(t)||k(f)||g&&!g._f)&&!re(f)?H(o,f,l):C(o,f,l)}},N=(t,i,l={})=>{const c=h(a,t),f=y.array.has(t),o=T(i);m(n,t,o),f?(b.array.next({name:t,values:T(n)}),(x.isDirty||x.dirtyFields||E.isDirty||E.dirtyFields)&&l.shouldDirty&&b.state.next({name:t,dirtyFields:ae(u,n),isDirty:v(t,o)})):c&&!c._f&&!I(o)?H(t,o,l):C(t,o,l),Ze(t,y)?b.state.next({...r,name:t,values:T(n)}):b.state.next({name:d.mount?t:void 0,values:T(n)})},ue=async t=>{d.mount=!0;const i=t.target;let l=i.name,c=!0;const f=h(a,l),o=A=>{c=Number.isNaN(A)||re(A)&&isNaN(A.getTime())||G(A,h(n,l,A))},g=Qe(s.mode),F=Qe(s.reValidateMode);if(f){let A,L;const te=i.type?Je(f._f):_t(t),Z=t.type===$e.BLUR||t.type===$e.FOCUS_OUT,vt=!Ut(f._f)&&!s.resolver&&!h(r.errors,l)&&!f._f.deps||Nt(Z,h(r.touchedFields,l),r.isSubmitted,F,g),me=Ze(l,y,Z);m(n,l,te),Z?(!i||!i.readOnly)&&(f._f.onBlur&&f._f.onBlur(t),U&&U(0)):f._f.onChange&&f._f.onChange(t);const we=ne(l,te,Z),bt=!R(we)||me;if(!Z&&b.state.next({name:l,type:t.type,values:T(n)}),vt)return(x.isValid||E.isValid)&&(s.mode==="onBlur"?Z&&Y():Z||Y()),bt&&b.state.next({name:l,...me?{}:we});if(!Z&&me&&b.state.next({...r}),s.resolver){const{errors:He}=await ee([l]);if(q([l]),o(te),c){const Vt=Ge(r.errors,a,l),pe=Ge(He,a,Vt.name||l);A=pe.error,l=pe.name,L=R(He)}}else q([l],!0),A=(await tt(f,y.disabled,n,z,s.shouldUseNativeValidation))[l],q([l]),o(te),c&&(A?L=!1:(x.isValid||E.isValid)&&(L=await W(a,!0)));c&&(f._f.deps&&(!Array.isArray(f._f.deps)||f._f.deps.length>0)&&fe(f._f.deps),ge(l,L,A,we))}},oe=(t,i)=>{if(h(r.errors,i)&&t.focus)return t.focus(),1},fe=async(t,i={})=>{let l,c;const f=ce(t);if(s.resolver){const o=await se(w(t)?t:f);l=R(o),c=t?!f.some(g=>h(o,g)):l}else t?(c=(await Promise.all(f.map(async o=>{const g=h(a,o);return await W(g&&g._f?{[o]:g}:g)}))).every(Boolean),!(!c&&!r.isValid)&&Y()):c=l=await W(a);return b.state.next({...!B(t)||(x.isValid||E.isValid)&&l!==r.isValid?{}:{name:t},...s.resolver||!t?{isValid:l}:{},errors:r.errors}),i.shouldFocus&&!c&&ye(a,oe,t?f:y.mount),c},Re=(t,i)=>{let l={...d.mount?n:u};return i&&(l=st(i.dirtyFields?r.dirtyFields:r.touchedFields,l)),w(t)?l:B(t)?h(l,t):t.map(c=>h(l,c))},Ue=(t,i)=>({invalid:!!h((i||r).errors,t),isDirty:!!h((i||r).dirtyFields,t),error:h((i||r).errors,t),isValidating:!!h(r.validatingFields,t),isTouched:!!h((i||r).touchedFields,t)}),ot=t=>{t&&ce(t).forEach(i=>D(r.errors,i)),b.state.next({errors:t?r.errors:{}})},Ie=(t,i,l)=>{const c=(h(a,t,{_f:{}})._f||{}).ref,f=h(r.errors,t)||{},{ref:o,message:g,type:F,...A}=f;m(r.errors,t,{...A,...i,ref:c}),b.state.next({name:t,errors:r.errors,isValid:!1}),l&&l.shouldFocus&&c&&c.focus&&c.focus()},ft=(t,i)=>p(t)?b.state.subscribe({next:l=>"values"in l&&t(_(void 0,i),l)}):_(t,i,!0),Me=t=>b.state.subscribe({next:i=>{Mt(t.name,i.name,t.exact)&&It(i,t.formState||x,gt,t.reRenderRoot)&&t.callback({values:{...n},...r,...i,defaultValues:u})}}).unsubscribe,dt=t=>(d.mount=!0,E={...E,...t.formState},Me({...t,formState:{...le,...t.formState}})),Fe=(t,i={})=>{for(const l of t?ce(t):y.mount)y.mount.delete(l),y.array.delete(l),i.keepValue||(D(a,l),D(n,l)),!i.keepError&&D(r.errors,l),!i.keepDirty&&D(r.dirtyFields,l),!i.keepTouched&&D(r.touchedFields,l),!i.keepIsValidating&&D(r.validatingFields,l),!s.shouldUnregister&&!i.keepDefaultValue&&D(u,l);b.state.next({values:T(n)}),b.state.next({...r,...i.keepDirty?{isDirty:v()}:{}}),!i.keepIsValid&&Y()},Ne=({disabled:t,name:i})=>{(K(t)&&d.mount||t||y.disabled.has(i))&&(t?y.disabled.add(i):y.disabled.delete(i))},Ae=(t,i={})=>{let l=h(a,t);const c=K(i.disabled)||K(s.disabled);return m(a,t,{...l||{},_f:{...l&&l._f?l._f:{ref:{name:t}},name:t,mount:!0,...i}}),y.mount.add(t),l?Ne({disabled:K(i.disabled)?i.disabled:s.disabled,name:t}):S(t,!0,i.value),{...c?{disabled:i.disabled||s.disabled}:{},...s.progressive?{required:!!i.required,min:de(i.min),max:de(i.max),minLength:de(i.minLength),maxLength:de(i.maxLength),pattern:de(i.pattern)}:{},name:t,onChange:ue,onBlur:ue,ref:f=>{if(f){Ae(t,i),l=h(a,t);const o=w(f.value)&&f.querySelectorAll&&f.querySelectorAll("input,select,textarea")[0]||f,g=St(o),F=l._f.refs||[];if(g?F.find(A=>A===o):o===l._f.ref)return;m(a,t,{_f:{...l._f,...g?{refs:[...F.filter(De),o,...Array.isArray(h(u,t))?[{}]:[]],ref:{type:o.type,name:t}}:{ref:o}}}),S(t,!1,void 0,o)}else l=h(a,t,{}),l._f&&(l._f.mount=!1),(s.shouldUnregister||i.shouldUnregister)&&!(At(y.array,t)&&d.action)&&y.unMount.add(t)}}},xe=()=>s.shouldFocusError&&ye(a,oe,y.mount),ct=t=>{K(t)&&(b.state.next({disabled:t}),ye(a,(i,l)=>{const c=h(a,l);c&&(i.disabled=c._f.disabled||t,Array.isArray(c._f.refs)&&c._f.refs.forEach(f=>{f.disabled=c._f.disabled||t}))},0,!1))},Pe=(t,i)=>async l=>{let c;l&&(l.preventDefault&&l.preventDefault(),l.persist&&l.persist());let f=T(n);if(b.state.next({isSubmitting:!0}),s.resolver){const{errors:o,values:g}=await ee();q(),r.errors=o,f=T(g)}else await W(a);if(y.disabled.size)for(const o of y.disabled)D(f,o);if(D(r.errors,"root"),R(r.errors)){b.state.next({errors:{}});try{await t(f,l)}catch(o){c=o}}else i&&await i({...r.errors},l),xe(),setTimeout(xe);if(b.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:R(r.errors)&&!c,submitCount:r.submitCount+1,errors:r.errors}),c)throw c},yt=(t,i={})=>{h(a,t)&&(w(i.defaultValue)?N(t,T(h(u,t))):(N(t,i.defaultValue),m(u,t,T(i.defaultValue))),i.keepTouched||D(r.touchedFields,t),i.keepDirty||(D(r.dirtyFields,t),r.isDirty=i.defaultValue?v(t,T(h(u,t))):v()),i.keepError||(D(r.errors,t),x.isValid&&Y()),b.state.next({...r}))},Be=(t,i={})=>{const l=t?T(t):u,c=T(l),f=R(t),o=f?u:c;if(i.keepDefaultValues||(u=l),!i.keepValues){if(i.keepDirtyValues){const g=new Set([...y.mount,...Object.keys(ae(u,n))]);for(const F of Array.from(g)){const A=h(r.dirtyFields,F),L=h(n,F),te=h(o,F);A&&!w(L)?m(o,F,L):!A&&!w(te)&&N(F,te)}}else{if(Se&&w(t))for(const g of y.mount){const F=h(a,g);if(F&&F._f){const A=Array.isArray(F._f.refs)?F._f.refs[0]:F._f.ref;if(be(A)){const L=A.closest("form");if(L){L.reset();break}}}}if(i.keepFieldsRef)for(const g of y.mount)N(g,h(o,g));else a={}}n=s.shouldUnregister?i.keepDefaultValues?T(u):{}:T(o),b.array.next({values:{...o}}),b.state.next({values:{...o}})}y={mount:i.keepDirtyValues?y.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},d.mount=!x.isValid||!!i.keepIsValid||!!i.keepDirtyValues||!s.shouldUnregister&&!R(o),d.watch=!!s.shouldUnregister,d.keepIsValid=!!i.keepIsValid,d.action=!1,i.keepErrors||(r.errors={}),b.state.next({submitCount:i.keepSubmitCount?r.submitCount:0,isDirty:f?!1:i.keepDirty?r.isDirty:!!(i.keepDefaultValues&&!G(t,u)),isSubmitted:i.keepIsSubmitted?r.isSubmitted:!1,dirtyFields:f?{}:i.keepDirtyValues?i.keepDefaultValues&&n?ae(u,n):r.dirtyFields:i.keepDefaultValues&&t?ae(u,t):i.keepDirty?r.dirtyFields:{},touchedFields:i.keepTouched?r.touchedFields:{},errors:i.keepErrors?r.errors:{},isSubmitSuccessful:i.keepIsSubmitSuccessful?r.isSubmitSuccessful:!1,isSubmitting:!1,defaultValues:u})},qe=(t,i)=>Be(p(t)?t(n):t,{...s.resetOptions,...i}),ht=(t,i={})=>{const l=h(a,t),c=l&&l._f;if(c){const f=c.refs?c.refs[0]:c.ref;f.focus&&setTimeout(()=>{f.focus(),i.shouldSelect&&p(f.select)&&f.select()})}},gt=t=>{r={...r,...t}},We={control:{register:Ae,unregister:Fe,getFieldState:Ue,handleSubmit:Pe,setError:Ie,_subscribe:Me,_runSchema:ee,_updateIsValidating:q,_focusError:xe,_getWatch:_,_getDirty:v,_setValid:Y,_setFieldArray:V,_setDisabledField:Ne,_setErrors:Q,_getFieldArray:O,_reset:Be,_resetDefaultValues:()=>p(s.defaultValues)&&s.defaultValues().then(t=>{qe(t,s.resetOptions),b.state.next({isLoading:!1})}),_removeUnmounted:ve,_disableForm:ct,_subjects:b,_proxyFormState:x,get _fields(){return a},get _formValues(){return n},get _state(){return d},set _state(t){d=t},get _defaultValues(){return u},get _names(){return y},set _names(t){y=t},get _formState(){return r},get _options(){return s},set _options(t){s={...s,...t}}},subscribe:dt,trigger:fe,register:Ae,handleSubmit:Pe,watch:ft,setValue:N,getValues:Re,reset:qe,resetField:yt,clearErrors:ot,unregister:Fe,setError:Ie,setFocus:ht,getFieldState:Ue};return{...We,formControl:We}}function Ht(e={}){const s=P.useRef(void 0),r=P.useRef(void 0),[a,u]=P.useState({isDirty:!1,isValidating:!1,isLoading:p(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,isReady:!1,defaultValues:p(e.defaultValues)?void 0:e.defaultValues});if(!s.current)if(e.formControl)s.current={...e.formControl,formState:a},e.defaultValues&&!p(e.defaultValues)&&e.formControl.reset(e.defaultValues,e.resetOptions);else{const{formControl:d,...y}=Wt(e);s.current={...y,formState:a}}const n=s.current.control;return n._options=e,Dt(()=>{const d=n._subscribe({formState:n._proxyFormState,callback:()=>u({...n._formState}),reRenderRoot:!0});return u(y=>({...y,isReady:!0})),n._formState.isReady=!0,d},[n]),P.useEffect(()=>n._disableForm(e.disabled),[n,e.disabled]),P.useEffect(()=>{e.mode&&(n._options.mode=e.mode),e.reValidateMode&&(n._options.reValidateMode=e.reValidateMode)},[n,e.mode,e.reValidateMode]),P.useEffect(()=>{e.errors&&(n._setErrors(e.errors),n._focusError())},[n,e.errors]),P.useEffect(()=>{e.shouldUnregister&&n._subjects.state.next({values:n._getWatch()})},[n,e.shouldUnregister]),P.useEffect(()=>{if(n._proxyFormState.isDirty){const d=n._getDirty();d!==a.isDirty&&n._subjects.state.next({isDirty:d})}},[n,a.isDirty]),P.useEffect(()=>{var d;e.values&&!G(e.values,r.current)?(n._reset(e.values,{keepFieldsRef:!0,...n._options.resetOptions}),!((d=n._options.resetOptions)===null||d===void 0)&&d.keepIsValid||n._setValid(),r.current=e.values,u(y=>({...y}))):n._resetDefaultValues()},[n,e.values]),P.useEffect(()=>{n._state.mount||(n._setValid(),n._state.mount=!0),n._state.watch&&(n._state.watch=!1,n._subjects.state.next({...n._formState})),n._removeUnmounted()}),s.current.formState=wt(a,n),s.current}exports.useForm=Ht;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createActivityItemProxy.d.ts","sourceRoot":"","sources":["../../../../sdk/workflow/components/useActivityForm/createActivityItemProxy.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAQ,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGxE,OAAO,KAAK,EACV,YAAY,EAGb,MAAM,yCAAyC,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EACvE,QAAQ,EAAE,CAAC,EACX,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC,GAC/B,YAAY,CAAC,uBAAuB,CAAC,CAAC,CAAC,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAC,CA+FtE"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { FieldValues } from "react-hook-form";
|
|
2
|
-
import type { Activity } from "../../Activity";
|
|
3
|
-
/**
|
|
4
|
-
* Creates a React Hook Form resolver for Activity field validation.
|
|
5
|
-
*
|
|
6
|
-
* Validates only editable fields using BaseField.validate().
|
|
7
|
-
* Readonly fields (editable: false) are skipped.
|
|
8
|
-
*
|
|
9
|
-
* @param activity - The Activity instance with field definitions
|
|
10
|
-
* @returns RHF Resolver function
|
|
11
|
-
*/
|
|
12
|
-
export declare function createActivityResolver<A extends Activity<any, any, any>>(activity: A): (values: FieldValues, _context: any, options: any) => Promise<{
|
|
13
|
-
values: FieldValues;
|
|
14
|
-
errors: {};
|
|
15
|
-
} | {
|
|
16
|
-
values: {};
|
|
17
|
-
errors: Record<string, {
|
|
18
|
-
type: string;
|
|
19
|
-
message: string;
|
|
20
|
-
}>;
|
|
21
|
-
}>;
|
|
22
|
-
//# sourceMappingURL=createActivityResolver.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createActivityResolver.d.ts","sourceRoot":"","sources":["../../../../sdk/workflow/components/useActivityForm/createActivityResolver.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI/C;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EACtE,QAAQ,EAAE,CAAC,IAGG,QAAQ,WAAW,EAAE,UAAU,GAAG,EAAE,SAAS,GAAG;;;;;;cACvB,MAAM;iBAAW,MAAM;;GAkC/D"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../sdk/workflow/components/useActivityForm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EACV,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,SAAS,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../sdk/workflow/components/useActivityForm/types.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useActivityForm.d.ts","sourceRoot":"","sources":["../../../../sdk/workflow/components/useActivityForm/useActivityForm.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EACV,sBAAsB,EACtB,qBAAqB,EAEtB,MAAM,SAAS,CAAC;AAUjB,wBAAgB,eAAe,CAC7B,CAAC,SAAS,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAEjC,QAAQ,EAAE,CAAC,EACX,OAAO,EAAE,sBAAsB,CAAC,CAAC,CAAC,GACjC,qBAAqB,CAAC,CAAC,CAAC,CAkW1B"}
|
package/docs/useTable.md
DELETED
|
@@ -1,369 +0,0 @@
|
|
|
1
|
-
# Table SDK API
|
|
2
|
-
|
|
3
|
-
React hook for tables, lists, and galleries with sorting, filtering, search, and pagination.
|
|
4
|
-
|
|
5
|
-
## Imports
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
import { useTable } from "@ram_28/kf-ai-sdk/table";
|
|
9
|
-
import type { UseTableOptionsType, UseTableReturnType, ColumnDefinitionType, PaginationStateType } from "@ram_28/kf-ai-sdk/table/types";
|
|
10
|
-
import { ConditionOperator, GroupOperator, FilterValueSource } from "@ram_28/kf-ai-sdk/filter";
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
## Common Mistakes (READ FIRST)
|
|
16
|
-
|
|
17
|
-
### 1. Missing `as keyof FieldType` cast on column fieldId (TS2322)
|
|
18
|
-
|
|
19
|
-
`ColumnDefinitionType<T>.fieldId` is typed as `keyof T`, but `bdo.field.id` returns `string`. MUST cast.
|
|
20
|
-
|
|
21
|
-
```typescript
|
|
22
|
-
// ❌ WRONG — string not assignable to keyof (TS2322)
|
|
23
|
-
const columns: ColumnDefinitionType<AdminProductFieldType>[] = [
|
|
24
|
-
{ fieldId: bdo.product_name.id, label: "Product" },
|
|
25
|
-
];
|
|
26
|
-
|
|
27
|
-
// ✅ CORRECT — cast each fieldId
|
|
28
|
-
const columns: ColumnDefinitionType<AdminProductFieldType>[] = [
|
|
29
|
-
{ fieldId: bdo.product_name.id as keyof AdminProductFieldType, label: "Product" },
|
|
30
|
-
{ fieldId: bdo.unit_price.id as keyof AdminProductFieldType, label: "Price" },
|
|
31
|
-
{ fieldId: bdo.status.id as keyof AdminProductFieldType, label: "Status" },
|
|
32
|
-
];
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### 2. Passing `bdo` instead of `source`
|
|
36
|
-
|
|
37
|
-
`useTable` takes `source` (a BO_ID string), NOT `bdo` (a BDO instance).
|
|
38
|
-
|
|
39
|
-
```typescript
|
|
40
|
-
// ❌ WRONG
|
|
41
|
-
useTable({ bdo: product, columns });
|
|
42
|
-
|
|
43
|
-
// ✅ CORRECT
|
|
44
|
-
useTable({ source: product.meta._id, columns });
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### 3. Calling `.get()` on table rows
|
|
48
|
-
|
|
49
|
-
Table `rows` are **plain objects**, NOT `ItemType`. Access fields directly.
|
|
50
|
-
|
|
51
|
-
```typescript
|
|
52
|
-
// ❌ WRONG — rows are plain objects
|
|
53
|
-
table.rows.map(row => row.product_name.get());
|
|
54
|
-
|
|
55
|
-
// ✅ CORRECT — access directly
|
|
56
|
-
table.rows.map(row => row.product_name);
|
|
57
|
-
table.rows.map(row => String(row.product_name ?? ""));
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### 4. Using entity-level FieldType as generic
|
|
61
|
-
|
|
62
|
-
Entity types exclude `SystemFieldsType` — `row._id` won't work. Use role-specific type.
|
|
63
|
-
|
|
64
|
-
```typescript
|
|
65
|
-
// ❌ WRONG — ProductType excludes _id
|
|
66
|
-
import type { ProductType } from "@/bdo/entities/Product";
|
|
67
|
-
useTable<ProductType>({ ... });
|
|
68
|
-
|
|
69
|
-
// ✅ CORRECT — role type includes SystemFieldsType
|
|
70
|
-
import type { AdminProductFieldType } from "@/bdo/admin/Product";
|
|
71
|
-
useTable<AdminProductFieldType>({ ... });
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### 5. Wrong initialState property names
|
|
75
|
-
|
|
76
|
-
```typescript
|
|
77
|
-
// ❌ WRONG — react-table naming
|
|
78
|
-
initialState: { sorting: [...], pagination: { pageIndex: 0, pageSize: 10 } }
|
|
79
|
-
|
|
80
|
-
// ✅ CORRECT — use sort (not sorting), pageNo (not pageIndex), 1-indexed
|
|
81
|
-
initialState: { sort: [{ [bdo.product_name.id]: "ASC" }], pagination: { pageNo: 1, pageSize: 10 } }
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### 6. Using `header` instead of `label` in columns
|
|
85
|
-
|
|
86
|
-
```typescript
|
|
87
|
-
// ❌ WRONG
|
|
88
|
-
{ fieldId: bdo.product_name.id as keyof T, header: "Product" }
|
|
89
|
-
|
|
90
|
-
// ✅ CORRECT
|
|
91
|
-
{ fieldId: bdo.product_name.id as keyof T, label: "Product" }
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
### 7. Using `useMemo` for filter side effects instead of `useEffect`
|
|
95
|
-
|
|
96
|
-
```tsx
|
|
97
|
-
// ❌ WRONG — side effects in useMemo cause infinite re-render
|
|
98
|
-
useMemo(() => { table.filter.clearAllConditions(); table.filter.addCondition({...}); }, [status]);
|
|
99
|
-
|
|
100
|
-
// ✅ CORRECT — use useEffect
|
|
101
|
-
useEffect(() => { table.filter.clearAllConditions(); table.filter.addCondition({...}); }, [status]);
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
### 8. Rendering Reference/Image/File values in table columns
|
|
105
|
-
|
|
106
|
-
Table rows are plain objects. Reference values are objects `{ _id, _name }` — render `_name`. Image/File values are `FileType | null` / `FileType[]`.
|
|
107
|
-
|
|
108
|
-
```tsx
|
|
109
|
-
// ❌ WRONG — renders [object Object] for reference field
|
|
110
|
-
<td>{row.category}</td>
|
|
111
|
-
|
|
112
|
-
// ❌ WRONG — renders [object Object] for image field
|
|
113
|
-
<td>{row.product_image}</td>
|
|
114
|
-
|
|
115
|
-
// ✅ CORRECT — reference: access _name
|
|
116
|
-
<td>{(row.category as any)?._name ?? "—"}</td>
|
|
117
|
-
|
|
118
|
-
// ✅ CORRECT — file array: show count or names
|
|
119
|
-
<td>{Array.isArray(row.attachments) ? `${(row.attachments as any[]).length} files` : "—"}</td>
|
|
120
|
-
|
|
121
|
-
// ✅ BEST — use transform in column definition
|
|
122
|
-
{ fieldId: bdo.category.id as keyof T, label: "Category", transform: (val) => (val as any)?._name ?? "—" }
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
### 9. Displaying images from ImageField in tables/cards/grids (NEVER use src="#")
|
|
126
|
-
|
|
127
|
-
Use the pre-built `ImageThumbnail` component from `@/components/ui/image-thumbnail`. It handles the server proxy URL, error fallback, and placeholder automatically. NEVER build image URLs manually or use `src="#"`.
|
|
128
|
-
|
|
129
|
-
```tsx
|
|
130
|
-
import { ImageThumbnail } from "@/components/ui/image-thumbnail";
|
|
131
|
-
|
|
132
|
-
// ❌ WRONG — src="#" shows broken image, NEVER do this
|
|
133
|
-
<img src="#" alt="product" />
|
|
134
|
-
|
|
135
|
-
// ❌ WRONG — FileName is just the filename string, NOT a URL
|
|
136
|
-
<img src={(row.product_image as any)?.FileName} />
|
|
137
|
-
|
|
138
|
-
// ✅ CORRECT — use ImageThumbnail in table cell
|
|
139
|
-
<td>
|
|
140
|
-
<ImageThumbnail boId={bdo.meta._id} instanceId={row._id} fieldId={bdo.product_image.id} value={row[bdo.product_image.id]} />
|
|
141
|
-
</td>
|
|
142
|
-
|
|
143
|
-
// ✅ CORRECT — use ImageThumbnail in product card/grid
|
|
144
|
-
<ImageThumbnail
|
|
145
|
-
boId={bdo.meta._id}
|
|
146
|
-
instanceId={row._id}
|
|
147
|
-
fieldId={bdo.product_image.id}
|
|
148
|
-
value={row[bdo.product_image.id]}
|
|
149
|
-
imgClassName="w-full h-full object-cover rounded-lg"
|
|
150
|
-
alt={String(row.product_name ?? "")}
|
|
151
|
-
/>
|
|
152
|
-
|
|
153
|
-
// ✅ CORRECT — use ImageThumbnail in detail page (with bdo.get() ItemType)
|
|
154
|
-
<ImageThumbnail
|
|
155
|
-
boId={bdo.meta._id}
|
|
156
|
-
instanceId={item._id}
|
|
157
|
-
fieldId={bdo.product_image.id}
|
|
158
|
-
value={item.product_image.get()}
|
|
159
|
-
imgClassName="w-48 h-48 object-cover rounded-xl"
|
|
160
|
-
/>
|
|
161
|
-
|
|
162
|
-
// ✅ CORRECT — use in column transform
|
|
163
|
-
{
|
|
164
|
-
fieldId: bdo.product_image.id as keyof T,
|
|
165
|
-
label: "Image",
|
|
166
|
-
transform: (val, row) => (
|
|
167
|
-
<ImageThumbnail boId={bdo.meta._id} instanceId={row._id} fieldId={bdo.product_image.id} value={val} />
|
|
168
|
-
),
|
|
169
|
-
}
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
**Key rules:**
|
|
173
|
-
- ALWAYS use `<ImageThumbnail>` for displaying images outside forms — it builds the correct server proxy URL internally
|
|
174
|
-
- NEVER hardcode `src="#"` or use `FileName` as a URL
|
|
175
|
-
- For forms (upload/edit), use `<ImageUpload>` instead
|
|
176
|
-
|
|
177
|
-
### 10. Displaying files from FileField in tables/cards/grids
|
|
178
|
-
|
|
179
|
-
Use the pre-built `FilePreview` component from `@/components/ui/file-preview`. It shows file names with download links, and inline thumbnails for image files.
|
|
180
|
-
|
|
181
|
-
```tsx
|
|
182
|
-
import { FilePreview } from "@/components/ui/file-preview";
|
|
183
|
-
|
|
184
|
-
// ❌ WRONG — renders [object Object] or meaningless text
|
|
185
|
-
<td>{row.attachments}</td>
|
|
186
|
-
<td>{JSON.stringify(row.attachments)}</td>
|
|
187
|
-
|
|
188
|
-
// ✅ CORRECT — use FilePreview in table cell
|
|
189
|
-
<td>
|
|
190
|
-
<FilePreview boId={bdo.meta._id} instanceId={row._id} fieldId={bdo.attachments.id} value={row[bdo.attachments.id]} />
|
|
191
|
-
</td>
|
|
192
|
-
|
|
193
|
-
// ✅ CORRECT — use in column transform
|
|
194
|
-
{
|
|
195
|
-
fieldId: bdo.attachments.id as keyof T,
|
|
196
|
-
label: "Files",
|
|
197
|
-
transform: (val, row) => (
|
|
198
|
-
<FilePreview boId={bdo.meta._id} instanceId={row._id} fieldId={bdo.attachments.id} value={val} />
|
|
199
|
-
),
|
|
200
|
-
}
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
**Key rules:**
|
|
204
|
-
- ALWAYS use `<FilePreview>` for displaying files outside forms
|
|
205
|
-
- For forms (upload/edit), use `<FileUpload>` instead
|
|
206
|
-
|
|
207
|
-
---
|
|
208
|
-
|
|
209
|
-
## Complete Table Example
|
|
210
|
-
|
|
211
|
-
```tsx
|
|
212
|
-
import { useMemo, useState, useEffect } from "react";
|
|
213
|
-
import { useNavigate } from "react-router-dom";
|
|
214
|
-
import { useTable } from "@ram_28/kf-ai-sdk/table";
|
|
215
|
-
import type { ColumnDefinitionType } from "@ram_28/kf-ai-sdk/table/types";
|
|
216
|
-
import { ConditionOperator, FilterValueSource } from "@ram_28/kf-ai-sdk/filter";
|
|
217
|
-
import { AdminProduct } from "@/bdo/admin/Product";
|
|
218
|
-
import type { AdminProductFieldType } from "@/bdo/admin/Product";
|
|
219
|
-
import { toast } from "sonner";
|
|
220
|
-
|
|
221
|
-
export default function ProductList() {
|
|
222
|
-
const navigate = useNavigate();
|
|
223
|
-
const bdo = useMemo(() => new AdminProduct(), []);
|
|
224
|
-
|
|
225
|
-
// Columns — MUST cast fieldId as keyof FieldType
|
|
226
|
-
const columns: ColumnDefinitionType<AdminProductFieldType>[] = [
|
|
227
|
-
{ fieldId: bdo.product_name.id as keyof AdminProductFieldType, label: bdo.product_name.label, enableSorting: true },
|
|
228
|
-
{ fieldId: bdo.unit_price.id as keyof AdminProductFieldType, label: bdo.unit_price.label, enableSorting: true },
|
|
229
|
-
{ fieldId: bdo.status.id as keyof AdminProductFieldType, label: bdo.status.label },
|
|
230
|
-
{ fieldId: bdo.category.id as keyof AdminProductFieldType, label: bdo.category.label,
|
|
231
|
-
transform: (val) => (val as any)?._name ?? "—" },
|
|
232
|
-
];
|
|
233
|
-
|
|
234
|
-
const table = useTable<AdminProductFieldType>({
|
|
235
|
-
source: bdo.meta._id,
|
|
236
|
-
columns,
|
|
237
|
-
initialState: {
|
|
238
|
-
sort: [{ [bdo.product_name.id]: "ASC" }],
|
|
239
|
-
pagination: { pageNo: 1, pageSize: 10 },
|
|
240
|
-
},
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
// Status filter — useEffect for side effects, NOT useMemo
|
|
244
|
-
const [statusFilter, setStatusFilter] = useState("all");
|
|
245
|
-
useEffect(() => {
|
|
246
|
-
table.filter.clearAllConditions();
|
|
247
|
-
if (statusFilter !== "all") {
|
|
248
|
-
table.filter.addCondition({
|
|
249
|
-
Operator: ConditionOperator.EQ,
|
|
250
|
-
LHSField: bdo.status.id,
|
|
251
|
-
RHSValue: statusFilter,
|
|
252
|
-
RHSType: FilterValueSource.Constant,
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
}, [statusFilter]);
|
|
256
|
-
|
|
257
|
-
if (table.isLoading) return <div>Loading...</div>;
|
|
258
|
-
if (table.error) return <div>Error: {table.error.message}</div>;
|
|
259
|
-
|
|
260
|
-
const handleDelete = async (id: string) => {
|
|
261
|
-
if (!confirm("Delete this item?")) return;
|
|
262
|
-
try {
|
|
263
|
-
await bdo.delete(id);
|
|
264
|
-
toast.success("Deleted");
|
|
265
|
-
table.refetch();
|
|
266
|
-
} catch (e) { toast.error("Failed to delete"); }
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
return (
|
|
270
|
-
<div className="space-y-4">
|
|
271
|
-
{/* Search */}
|
|
272
|
-
<input
|
|
273
|
-
type="text"
|
|
274
|
-
placeholder="Search..."
|
|
275
|
-
value={table.search.query}
|
|
276
|
-
onChange={(e) => table.search.set(bdo.product_name.id as keyof AdminProductFieldType, e.target.value)}
|
|
277
|
-
/>
|
|
278
|
-
|
|
279
|
-
{/* Status filter dropdown */}
|
|
280
|
-
<select value={statusFilter} onChange={(e) => setStatusFilter(e.target.value)}>
|
|
281
|
-
<option value="all">All</option>
|
|
282
|
-
<option value="Active">Active</option>
|
|
283
|
-
<option value="Discontinued">Discontinued</option>
|
|
284
|
-
</select>
|
|
285
|
-
|
|
286
|
-
{/* Table */}
|
|
287
|
-
<table>
|
|
288
|
-
<thead>
|
|
289
|
-
<tr>
|
|
290
|
-
{columns.map((col) => (
|
|
291
|
-
<th key={String(col.fieldId)} onClick={() => col.enableSorting && table.sort.toggle(col.fieldId)}>
|
|
292
|
-
{col.label}
|
|
293
|
-
{table.sort.field === col.fieldId && (table.sort.direction === "ASC" ? " ↑" : " ↓")}
|
|
294
|
-
</th>
|
|
295
|
-
))}
|
|
296
|
-
</tr>
|
|
297
|
-
</thead>
|
|
298
|
-
<tbody>
|
|
299
|
-
{table.rows.map((row) => (
|
|
300
|
-
<tr key={row._id} onClick={() => navigate(`/products/${row._id}`)}>
|
|
301
|
-
<td>{String(row.product_name ?? "")}</td>
|
|
302
|
-
<td>${Number(row.unit_price ?? 0).toFixed(2)}</td>
|
|
303
|
-
<td>{String(row.status ?? "")}</td>
|
|
304
|
-
<td>{(row.category as any)?._name ?? "—"}</td>
|
|
305
|
-
</tr>
|
|
306
|
-
))}
|
|
307
|
-
</tbody>
|
|
308
|
-
</table>
|
|
309
|
-
|
|
310
|
-
{/* Pagination */}
|
|
311
|
-
<div className="flex items-center gap-4">
|
|
312
|
-
<button onClick={table.pagination.goToPrevious} disabled={!table.pagination.canGoPrevious}>Previous</button>
|
|
313
|
-
<span>Page {table.pagination.pageNo} of {table.pagination.totalPages}</span>
|
|
314
|
-
<button onClick={table.pagination.goToNext} disabled={!table.pagination.canGoNext}>Next</button>
|
|
315
|
-
<span>{table.pagination.totalItems} total</span>
|
|
316
|
-
</div>
|
|
317
|
-
</div>
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
```
|
|
321
|
-
|
|
322
|
-
---
|
|
323
|
-
|
|
324
|
-
## Type Definitions
|
|
325
|
-
|
|
326
|
-
### ColumnDefinitionType
|
|
327
|
-
|
|
328
|
-
```typescript
|
|
329
|
-
interface ColumnDefinitionType<T> {
|
|
330
|
-
fieldId: keyof T; // MUST cast: bdo.field.id as keyof T
|
|
331
|
-
label?: string;
|
|
332
|
-
enableSorting?: boolean;
|
|
333
|
-
enableFiltering?: boolean;
|
|
334
|
-
transform?: (value: any, row: T) => React.ReactNode; // Custom rendering
|
|
335
|
-
}
|
|
336
|
-
```
|
|
337
|
-
|
|
338
|
-
### UseTableReturnType
|
|
339
|
-
|
|
340
|
-
```typescript
|
|
341
|
-
interface UseTableReturnType<T> {
|
|
342
|
-
rows: T[]; // Plain objects — access row.field directly (NOT .get())
|
|
343
|
-
totalItems: number;
|
|
344
|
-
isLoading: boolean;
|
|
345
|
-
isFetching: boolean;
|
|
346
|
-
error: Error | null;
|
|
347
|
-
search: { query: string; field: keyof T | null; set: (field: keyof T, query: string) => void; clear: () => void; };
|
|
348
|
-
sort: { field: keyof T | null; direction: "ASC" | "DESC" | null; toggle: (field: keyof T) => void; set: (field: keyof T, dir: "ASC" | "DESC") => void; clear: () => void; };
|
|
349
|
-
filter: UseFilterReturnType<T>; // Full useFilter API
|
|
350
|
-
pagination: { pageNo: number; pageSize: number; totalPages: number; totalItems: number; canGoNext: boolean; canGoPrevious: boolean; goToNext: () => void; goToPrevious: () => void; goToPage: (n: number) => void; setPageSize: (n: number) => void; };
|
|
351
|
-
refetch: () => Promise<any>;
|
|
352
|
-
}
|
|
353
|
-
```
|
|
354
|
-
|
|
355
|
-
### UseTableOptionsType
|
|
356
|
-
|
|
357
|
-
```typescript
|
|
358
|
-
interface UseTableOptionsType<T> {
|
|
359
|
-
source: string; // bdo.meta._id (NOT the bdo instance)
|
|
360
|
-
columns: ColumnDefinitionType<T>[];
|
|
361
|
-
initialState?: {
|
|
362
|
-
sort?: Record<string, "ASC" | "DESC">[];
|
|
363
|
-
pagination?: { pageNo: number; pageSize: number; };
|
|
364
|
-
filter?: UseFilterOptionsType<T>;
|
|
365
|
-
};
|
|
366
|
-
onError?: (error: Error) => void;
|
|
367
|
-
onSuccess?: (data: T[]) => void;
|
|
368
|
-
}
|
|
369
|
-
```
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
// ============================================================
|
|
2
|
-
// ACTIVITY ITEM PROXY
|
|
3
|
-
// ============================================================
|
|
4
|
-
// Proxy-based item that delegates to RHF for state management.
|
|
5
|
-
// Follows the same pattern as createItemProxy for BaseBdo,
|
|
6
|
-
// adapted for Activity.
|
|
7
|
-
|
|
8
|
-
import type { UseFormReturn, Path, FieldValues } from "react-hook-form";
|
|
9
|
-
import type { BaseFieldMetaType } from "../../../bdo/core/types";
|
|
10
|
-
import type { BaseField } from "../../../bdo/fields/BaseField";
|
|
11
|
-
import type {
|
|
12
|
-
FormItemType,
|
|
13
|
-
EditableFormFieldAccessorType,
|
|
14
|
-
ReadonlyFormFieldAccessorType,
|
|
15
|
-
} from "../../../components/hooks/useForm/types";
|
|
16
|
-
import type { Activity } from "../../Activity";
|
|
17
|
-
import type {
|
|
18
|
-
ExtractActivityEditable,
|
|
19
|
-
ExtractActivityReadonly,
|
|
20
|
-
} from "./types";
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Creates a Proxy-based Item that delegates to RHF for state management.
|
|
24
|
-
*
|
|
25
|
-
* Key principle: Item has NO state. It's a view over RHF's state.
|
|
26
|
-
* Editable fields get set(), readonly fields do not.
|
|
27
|
-
*
|
|
28
|
-
* @param activity - The Activity instance for field metadata
|
|
29
|
-
* @param form - The RHF useForm return object
|
|
30
|
-
* @returns FormItemType proxy
|
|
31
|
-
*/
|
|
32
|
-
export function createActivityItemProxy<A extends Activity<any, any, any>>(
|
|
33
|
-
activity: A,
|
|
34
|
-
form: UseFormReturn<FieldValues>,
|
|
35
|
-
): FormItemType<ExtractActivityEditable<A>, ExtractActivityReadonly<A>> {
|
|
36
|
-
const fields = activity._getFields();
|
|
37
|
-
|
|
38
|
-
return new Proxy(
|
|
39
|
-
{} as FormItemType<ExtractActivityEditable<A>, ExtractActivityReadonly<A>>,
|
|
40
|
-
{
|
|
41
|
-
get(_, prop: string | symbol) {
|
|
42
|
-
// Handle symbol properties (e.g., Symbol.toStringTag)
|
|
43
|
-
if (typeof prop === "symbol") {
|
|
44
|
-
return undefined;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// toJSON returns all form values as plain object
|
|
48
|
-
if (prop === "toJSON") {
|
|
49
|
-
return () => form.getValues();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// validate triggers RHF validation for all fields
|
|
53
|
-
if (prop === "validate") {
|
|
54
|
-
return () => form.trigger();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Field accessor
|
|
58
|
-
const bdoField = fields[prop] as BaseField<unknown> | undefined;
|
|
59
|
-
const fieldMeta: BaseFieldMetaType = bdoField?.meta ?? {
|
|
60
|
-
_id: prop,
|
|
61
|
-
Name: prop,
|
|
62
|
-
Type: "String",
|
|
63
|
-
};
|
|
64
|
-
const isReadOnly = bdoField?.readOnly ?? false;
|
|
65
|
-
|
|
66
|
-
// Base validate function
|
|
67
|
-
const validate = () => {
|
|
68
|
-
if (bdoField) {
|
|
69
|
-
return bdoField.validate(form.getValues(prop as Path<FieldValues>));
|
|
70
|
-
}
|
|
71
|
-
return { valid: true, errors: [] };
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// Only add set() for editable fields
|
|
75
|
-
if (!isReadOnly) {
|
|
76
|
-
const accessor: EditableFormFieldAccessorType<unknown> = {
|
|
77
|
-
label: bdoField?.label ?? prop,
|
|
78
|
-
required: bdoField?.required ?? false,
|
|
79
|
-
readOnly: false,
|
|
80
|
-
defaultValue: bdoField?.defaultValue,
|
|
81
|
-
meta: fieldMeta,
|
|
82
|
-
get: () => form.getValues(prop as Path<FieldValues>),
|
|
83
|
-
getOrDefault: (fallback: unknown) =>
|
|
84
|
-
form.getValues(prop as Path<FieldValues>) ?? fallback,
|
|
85
|
-
set: (value: unknown) => {
|
|
86
|
-
form.setValue(prop as Path<FieldValues>, value as any, {
|
|
87
|
-
shouldDirty: true,
|
|
88
|
-
shouldTouch: true,
|
|
89
|
-
shouldValidate: false,
|
|
90
|
-
});
|
|
91
|
-
},
|
|
92
|
-
validate,
|
|
93
|
-
};
|
|
94
|
-
return accessor;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const accessor: ReadonlyFormFieldAccessorType<unknown> = {
|
|
98
|
-
label: bdoField?.label ?? prop,
|
|
99
|
-
required: bdoField?.required ?? false,
|
|
100
|
-
readOnly: true,
|
|
101
|
-
defaultValue: bdoField?.defaultValue,
|
|
102
|
-
meta: fieldMeta,
|
|
103
|
-
get: () => form.getValues(prop as Path<FieldValues>),
|
|
104
|
-
getOrDefault: (fallback: unknown) =>
|
|
105
|
-
form.getValues(prop as Path<FieldValues>) ?? fallback,
|
|
106
|
-
validate,
|
|
107
|
-
};
|
|
108
|
-
return accessor;
|
|
109
|
-
},
|
|
110
|
-
|
|
111
|
-
has(_, prop) {
|
|
112
|
-
if (typeof prop === "symbol") return false;
|
|
113
|
-
if (prop === "toJSON" || prop === "validate") return true;
|
|
114
|
-
return prop in fields;
|
|
115
|
-
},
|
|
116
|
-
|
|
117
|
-
ownKeys(_) {
|
|
118
|
-
return [...Object.keys(fields), "toJSON", "validate"];
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
getOwnPropertyDescriptor(_, prop) {
|
|
122
|
-
if (typeof prop === "symbol") return undefined;
|
|
123
|
-
return {
|
|
124
|
-
configurable: true,
|
|
125
|
-
enumerable: prop !== "toJSON" && prop !== "validate",
|
|
126
|
-
};
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
);
|
|
130
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
// ============================================================
|
|
2
|
-
// ACTIVITY RESOLVER
|
|
3
|
-
// ============================================================
|
|
4
|
-
// RHF resolver for Activity field type validation.
|
|
5
|
-
// Simplified version of createResolver — no expression engine,
|
|
6
|
-
// only field-level type validation via BaseField.validate().
|
|
7
|
-
|
|
8
|
-
import type { FieldValues } from "react-hook-form";
|
|
9
|
-
import type { Activity } from "../../Activity";
|
|
10
|
-
import type { BaseField } from "../../../bdo/fields/BaseField";
|
|
11
|
-
import type { ValidationResultType } from "../../../bdo/core/types";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Creates a React Hook Form resolver for Activity field validation.
|
|
15
|
-
*
|
|
16
|
-
* Validates only editable fields using BaseField.validate().
|
|
17
|
-
* Readonly fields (editable: false) are skipped.
|
|
18
|
-
*
|
|
19
|
-
* @param activity - The Activity instance with field definitions
|
|
20
|
-
* @returns RHF Resolver function
|
|
21
|
-
*/
|
|
22
|
-
export function createActivityResolver<A extends Activity<any, any, any>>(
|
|
23
|
-
activity: A,
|
|
24
|
-
) {
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
-
return async (values: FieldValues, _context: any, options: any) => {
|
|
27
|
-
const errors: Record<string, { type: string; message: string }> = {};
|
|
28
|
-
const fields = activity._getFields();
|
|
29
|
-
|
|
30
|
-
// If validating specific fields (blur/change), only validate those
|
|
31
|
-
// If validating all (submit), options.names is undefined
|
|
32
|
-
const fieldsToValidate = options?.names ?? Object.keys(fields);
|
|
33
|
-
|
|
34
|
-
for (const fieldName of fieldsToValidate) {
|
|
35
|
-
const field = fields[fieldName];
|
|
36
|
-
if (!field) continue;
|
|
37
|
-
|
|
38
|
-
// Skip validation for readonly fields
|
|
39
|
-
if (field.readOnly) continue;
|
|
40
|
-
|
|
41
|
-
const value = values[fieldName];
|
|
42
|
-
|
|
43
|
-
const result: ValidationResultType = (
|
|
44
|
-
field as BaseField<unknown>
|
|
45
|
-
).validate(value);
|
|
46
|
-
|
|
47
|
-
if (!result.valid && result.errors.length > 0) {
|
|
48
|
-
errors[fieldName] = {
|
|
49
|
-
type: "validate",
|
|
50
|
-
message: result.errors[0] || `${fieldName} is invalid`,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Return format for RHF resolver
|
|
56
|
-
if (Object.keys(errors).length === 0) {
|
|
57
|
-
return { values, errors: {} };
|
|
58
|
-
}
|
|
59
|
-
return { values: {}, errors };
|
|
60
|
-
};
|
|
61
|
-
}
|