frappe-react-sdk 1.2.4 → 1.2.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.
|
@@ -4254,13 +4254,13 @@ const Pa = (n, e, t = !1, r = !1, s, i) => {
|
|
|
4254
4254
|
r.off(n);
|
|
4255
4255
|
};
|
|
4256
4256
|
}, [n, e]);
|
|
4257
|
-
}, Va = (n, e, t = !0
|
|
4257
|
+
}, Va = (n, e, t, r = !0) => {
|
|
4258
4258
|
const {
|
|
4259
4259
|
socket: s
|
|
4260
4260
|
} = ee(te), [i, o] = P([]);
|
|
4261
|
-
Xe(() => (s.emit("doc_subscribe", n, e),
|
|
4262
|
-
s.emit("doc_unsubscribe", n, e),
|
|
4263
|
-
}), [n, e,
|
|
4261
|
+
Xe(() => (s.emit("doc_subscribe", n, e), r && s.emit("doc_open", n, e), () => {
|
|
4262
|
+
s.emit("doc_unsubscribe", n, e), r && s.emit("doc_close", n, e);
|
|
4263
|
+
}), [n, e, r]), kn("doc_update", t);
|
|
4264
4264
|
const c = M(() => {
|
|
4265
4265
|
s.emit("doc_open", n, e);
|
|
4266
4266
|
}, [n, e]), f = M(() => {
|
|
@@ -41,4 +41,4 @@ Check the render method of \``+u+"`."}return""}}function Ea(u){{if(u!==void 0){v
|
|
|
41
41
|
|
|
42
42
|
Check your code at `+p+":"+m+"."}return""}}var ws={};function Sa(u){{var p=_s();if(!p){var m=typeof u=="string"?u:u.displayName||u.name;m&&(p=`
|
|
43
43
|
|
|
44
|
-
Check the top-level render call using <`+m+">.")}return p}}function Es(u,p){{if(!u._store||u._store.validated||u.key!=null)return;u._store.validated=!0;var m=Sa(p);if(ws[m])return;ws[m]=!0;var _="";u&&u._owner&&u._owner!==Bn.current&&(_=" It was passed a child from "+ee(u._owner.type)+"."),Ge(u),T('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',m,_),Ge(null)}}function Ss(u,p){{if(typeof u!="object")return;if(ze(u))for(var m=0;m<u.length;m++){var _=u[m];Un(_)&&Es(_,p)}else if(Un(u))u._store&&(u._store.validated=!0);else if(u){var D=x(u);if(typeof D=="function"&&D!==u.entries)for(var U=D.call(u),O;!(O=U.next()).done;)Un(O.value)&&Es(O.value,p)}}}function Ra(u){{var p=u.type;if(p==null||typeof p=="string")return;var m;if(typeof p=="function")m=p.propTypes;else if(typeof p=="object"&&(p.$$typeof===f||p.$$typeof===l))m=p.propTypes;else return;if(m){var _=ee(p);he(m,u.props,"prop",_,u)}else if(p.PropTypes!==void 0&&!In){In=!0;var D=ee(p);T("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",D||"Unknown")}typeof p.getDefaultProps=="function"&&!p.getDefaultProps.isReactClassApproved&&T("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Ca(u){{for(var p=Object.keys(u.props),m=0;m<p.length;m++){var _=p[m];if(_!=="children"&&_!=="key"){Ge(u),T("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",_),Ge(null);break}}u.ref!==null&&(Ge(u),T("Invalid attribute `ref` supplied to `React.Fragment`."),Ge(null))}}function Rs(u,p,m,_,D,U){{var O=P(u);if(!O){var C="";(u===void 0||typeof u=="object"&&u!==null&&Object.keys(u).length===0)&&(C+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var re=Ea(D);re?C+=re:C+=_s();var q;u===null?q="null":ze(u)?q="array":u!==void 0&&u.$$typeof===e?(q="<"+(ee(u.type)||"Unknown")+" />",C=" Did you accidentally export a JSX literal instead of a component?"):q=typeof u,T("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",q,C)}var G=wa(u,p,m,D,U);if(G==null)return G;if(O){var le=p.children;if(le!==void 0)if(_)if(ze(le)){for(var Xe=0;Xe<le.length;Xe++)Ss(le[Xe],u);Object.freeze&&Object.freeze(le)}else T("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Ss(le,u)}return u===r?Ca(G):Ra(G),G}}function Ta(u,p,m){return Rs(u,p,m,!0)}function Oa(u,p,m){return Rs(u,p,m,!1)}var xa=Oa,Aa=Ta;ct.Fragment=r,ct.jsx=xa,ct.jsxs=Aa}()),ct}(function(n){process.env.NODE_ENV==="production"?n.exports=Xo():n.exports=Qo()})(fs);const Zo=fs.exports.jsx,Z=d.createContext(null),$o=({url:n="",tokenParams:e,socketPort:t,children:r})=>{const s=d.useMemo(()=>{const i=new ki.FrappeApp(n,e);return{url:n,tokenParams:e,app:i,auth:i.auth(),db:i.db(),call:i.call(),file:i.file(),socket:new Go(n,t).socket}},[n,e,t]);return Zo(Z.Provider,{value:s,children:r})},ea=n=>{const{url:e,auth:t,tokenParams:r}=d.useContext(Z),[s,i]=d.useState(),o=d.useCallback(()=>{const w=document.cookie.split(";").find(E=>E.trim().startsWith("user_id="));if(w){const E=w.split("=")[1];i(E&&E!=="Guest"?E:null)}else i(null)},[]);d.useEffect(()=>{r&&r.useToken?i(null):o()},[]);const{data:c,error:f,isLoading:a,isValidating:h,mutate:l}=it(()=>r&&r.useToken||s?`${e}/api/method/frappe.auth.get_logged_user`:null,()=>t.getLoggedInUser(),{onError:()=>{i(null)},shouldRetryOnError:!1,revalidateOnFocus:!1,...n}),v=d.useCallback(async(w,E)=>t.loginWithUsernamePassword({username:w,password:E}).then(x=>{o()}),[]),y=d.useCallback(async()=>t.logout().then(()=>l(null)).then(()=>i(null)),[]);return{isLoading:s===void 0||a,currentUser:c,isValidating:h,error:f,login:v,logout:y,updateCurrentUser:l,getUserCookie:o}},Fn=(n,e,t)=>{let r=`${e}/api/resource/`;return t?r+=`${n}/${t}`:r+=`${n}`,r},ta=(n,e,t,r)=>{const{url:s,db:i}=d.useContext(Z);return{...it(t===void 0?Fn(n,s,e):t,()=>i.getDoc(n,e),r)}},ps=n=>{var t,r,s;let e="";if(n!=null&&n.fields&&(e+="fields="+JSON.stringify(n==null?void 0:n.fields)+"&"),n!=null&&n.filters&&(e+="filters="+JSON.stringify(n==null?void 0:n.filters)+"&"),n!=null&&n.orFilters&&(e+="or_filters="+JSON.stringify(n==null?void 0:n.orFilters)+"&"),n!=null&&n.limit_start&&(e+="limit_start="+JSON.stringify(n==null?void 0:n.limit_start)+"&"),n!=null&&n.limit&&(e+="limit="+JSON.stringify(n==null?void 0:n.limit)+"&"),n!=null&&n.groupBy&&(e+="group_by="+String(n.groupBy)+"&"),n!=null&&n.orderBy){const i=`${String((t=n.orderBy)==null?void 0:t.field)} ${(s=(r=n.orderBy)==null?void 0:r.order)!=null?s:"asc"}`;e+="order_by="+i+"&"}return n!=null&&n.asDict&&(e+="as_dict="+n.asDict),e},na=(n,e,t,r)=>{const{url:s,db:i}=d.useContext(Z);return{...it(t===void 0?`${Fn(n,s)}?${ps(e)}`:t,()=>i.getDocList(n,e),r)}},ra=()=>{const{db:n}=d.useContext(Z),[e,t]=d.useState(!1),[r,s]=d.useState(null),[i,o]=d.useState(!1),c=d.useCallback(()=>{t(!1),s(null),o(!1)},[]);return{createDoc:d.useCallback(async(a,h)=>(s(null),o(!1),t(!0),n.createDoc(a,h).then(l=>(t(!1),o(!0),l)).catch(l=>{throw t(!1),o(!1),s(l),l})),[]),loading:e,error:r,isCompleted:i,reset:c}},sa=()=>{const{db:n}=d.useContext(Z),[e,t]=d.useState(!1),[r,s]=d.useState(null),[i,o]=d.useState(!1),c=d.useCallback(()=>{t(!1),s(null),o(!1)},[]);return{updateDoc:d.useCallback(async(a,h,l)=>(s(null),o(!1),t(!0),n.updateDoc(a,h,l).then(v=>(t(!1),o(!0),v)).catch(v=>{throw t(!1),o(!1),s(v),v})),[]),loading:e,error:r,reset:c,isCompleted:i}},ia=()=>{const{db:n}=d.useContext(Z),[e,t]=d.useState(!1),[r,s]=d.useState(null),[i,o]=d.useState(!1),c=d.useCallback(()=>{t(!1),s(null),o(!1)},[]);return{deleteDoc:d.useCallback(async(a,h)=>(s(null),o(!1),t(!0),n.deleteDoc(a,h).then(l=>(t(!1),o(!0),l)).catch(l=>{throw t(!1),o(!1),s(l),l})),[]),loading:e,error:r,reset:c,isCompleted:i}};function vs(n){const e=[];for(let t in n)e.push(encodeURIComponent(t)+"="+encodeURIComponent(n[t]));return e.join("&")}const oa=(n,e,t=!1,r=!1,s,i)=>{const{url:o,db:c}=d.useContext(Z);return{...it(s===void 0?(()=>{const h=vs(t?{doctype:n,filters:e!=null?e:[],cache:t,debug:r}:{doctype:n,filters:e!=null?e:[],debug:r});return`${o}/api/method/frappe.client.get_count?${h}`})():s,()=>c.getCount(n,e,t,r),i)}},ys=(n,e,t,r)=>{const{call:s}=d.useContext(Z),i=vs(e!=null?e:{}),o=`${n}?${i}`;return{...it(t===void 0?o:t,()=>s.get(n,e),r)}},aa=n=>{const{call:e}=d.useContext(Z),[t,r]=d.useState(null),[s,i]=d.useState(!1),[o,c]=d.useState(null),[f,a]=d.useState(!1),h=d.useCallback(()=>{r(null),i(!1),c(null),a(!1)},[]);return{call:d.useCallback(async v=>(c(null),a(!1),i(!0),r(null),e.post(n,v).then(y=>(r(y),i(!1),a(!0),y)).catch(y=>{throw i(!1),a(!1),c(y),y})),[]),result:t,loading:s,error:o,reset:h,isCompleted:f}},ua=n=>{const{call:e}=d.useContext(Z),[t,r]=d.useState(null),[s,i]=d.useState(!1),[o,c]=d.useState(null),[f,a]=d.useState(!1),h=d.useCallback(()=>{r(null),i(!1),c(null),a(!1)},[]);return{call:d.useCallback(async v=>(c(null),a(!1),i(!0),r(null),e.put(n,v).then(y=>(r(y),i(!1),a(!0),y)).catch(y=>{throw i(!1),a(!1),c(y),y})),[]),result:t,loading:s,error:o,reset:h,isCompleted:f}},ca=n=>{const{call:e}=d.useContext(Z),[t,r]=d.useState(null),[s,i]=d.useState(!1),[o,c]=d.useState(null),[f,a]=d.useState(!1),h=d.useCallback(()=>{r(null),i(!1),c(null),a(!1)},[]);return{call:d.useCallback(async v=>(c(null),a(!1),i(!0),r(null),e.delete(n,v).then(y=>(r(y),i(!1),a(!0),y)).catch(y=>{throw i(!1),a(!1),c(y),y})),[]),result:t,loading:s,error:o,reset:h,isCompleted:f}},la=()=>{const{file:n}=d.useContext(Z),[e,t]=d.useState(0),[r,s]=d.useState(!1),[i,o]=d.useState(null),[c,f]=d.useState(!1),a=d.useCallback(async(l,v)=>(h(),s(!0),n.uploadFile(l,v,(y,w)=>t(Math.round(y/w*100))).then(y=>(f(!0),t(100),s(!1),y.data.message)).catch(y=>{throw console.error(y),o(y),s(!1),y})),[]),h=d.useCallback(()=>{t(0),s(!1),o(null),f(!1)},[]);return{upload:a,progress:e,loading:r,isCompleted:c,error:i,reset:h}},fa=(n,e,t=[],r=20,s=250)=>{const i=ha(e,s);return ys("frappe.desk.search.search_link",{doctype:n,page_length:r,txt:i,filters:JSON.stringify(t!=null?t:[])})},ha=(n,e)=>{const[t,r]=d.useState(n);return d.useEffect(()=>{const s=setTimeout(()=>{r(n)},e);return()=>{clearTimeout(s)}},[n,e]),t},Pt=(n,e)=>{const{socket:t}=d.useContext(Z);d.useEffect(()=>{let r=t.on(n,e);return()=>{r.off(n)}},[n,e])},da=(n,e,t=!0
|
|
44
|
+
Check the top-level render call using <`+m+">.")}return p}}function Es(u,p){{if(!u._store||u._store.validated||u.key!=null)return;u._store.validated=!0;var m=Sa(p);if(ws[m])return;ws[m]=!0;var _="";u&&u._owner&&u._owner!==Bn.current&&(_=" It was passed a child from "+ee(u._owner.type)+"."),Ge(u),T('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',m,_),Ge(null)}}function Ss(u,p){{if(typeof u!="object")return;if(ze(u))for(var m=0;m<u.length;m++){var _=u[m];Un(_)&&Es(_,p)}else if(Un(u))u._store&&(u._store.validated=!0);else if(u){var D=x(u);if(typeof D=="function"&&D!==u.entries)for(var U=D.call(u),O;!(O=U.next()).done;)Un(O.value)&&Es(O.value,p)}}}function Ra(u){{var p=u.type;if(p==null||typeof p=="string")return;var m;if(typeof p=="function")m=p.propTypes;else if(typeof p=="object"&&(p.$$typeof===f||p.$$typeof===l))m=p.propTypes;else return;if(m){var _=ee(p);he(m,u.props,"prop",_,u)}else if(p.PropTypes!==void 0&&!In){In=!0;var D=ee(p);T("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",D||"Unknown")}typeof p.getDefaultProps=="function"&&!p.getDefaultProps.isReactClassApproved&&T("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Ca(u){{for(var p=Object.keys(u.props),m=0;m<p.length;m++){var _=p[m];if(_!=="children"&&_!=="key"){Ge(u),T("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",_),Ge(null);break}}u.ref!==null&&(Ge(u),T("Invalid attribute `ref` supplied to `React.Fragment`."),Ge(null))}}function Rs(u,p,m,_,D,U){{var O=P(u);if(!O){var C="";(u===void 0||typeof u=="object"&&u!==null&&Object.keys(u).length===0)&&(C+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var re=Ea(D);re?C+=re:C+=_s();var q;u===null?q="null":ze(u)?q="array":u!==void 0&&u.$$typeof===e?(q="<"+(ee(u.type)||"Unknown")+" />",C=" Did you accidentally export a JSX literal instead of a component?"):q=typeof u,T("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",q,C)}var G=wa(u,p,m,D,U);if(G==null)return G;if(O){var le=p.children;if(le!==void 0)if(_)if(ze(le)){for(var Xe=0;Xe<le.length;Xe++)Ss(le[Xe],u);Object.freeze&&Object.freeze(le)}else T("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Ss(le,u)}return u===r?Ca(G):Ra(G),G}}function Ta(u,p,m){return Rs(u,p,m,!0)}function Oa(u,p,m){return Rs(u,p,m,!1)}var xa=Oa,Aa=Ta;ct.Fragment=r,ct.jsx=xa,ct.jsxs=Aa}()),ct}(function(n){process.env.NODE_ENV==="production"?n.exports=Xo():n.exports=Qo()})(fs);const Zo=fs.exports.jsx,Z=d.createContext(null),$o=({url:n="",tokenParams:e,socketPort:t,children:r})=>{const s=d.useMemo(()=>{const i=new ki.FrappeApp(n,e);return{url:n,tokenParams:e,app:i,auth:i.auth(),db:i.db(),call:i.call(),file:i.file(),socket:new Go(n,t).socket}},[n,e,t]);return Zo(Z.Provider,{value:s,children:r})},ea=n=>{const{url:e,auth:t,tokenParams:r}=d.useContext(Z),[s,i]=d.useState(),o=d.useCallback(()=>{const w=document.cookie.split(";").find(E=>E.trim().startsWith("user_id="));if(w){const E=w.split("=")[1];i(E&&E!=="Guest"?E:null)}else i(null)},[]);d.useEffect(()=>{r&&r.useToken?i(null):o()},[]);const{data:c,error:f,isLoading:a,isValidating:h,mutate:l}=it(()=>r&&r.useToken||s?`${e}/api/method/frappe.auth.get_logged_user`:null,()=>t.getLoggedInUser(),{onError:()=>{i(null)},shouldRetryOnError:!1,revalidateOnFocus:!1,...n}),v=d.useCallback(async(w,E)=>t.loginWithUsernamePassword({username:w,password:E}).then(x=>{o()}),[]),y=d.useCallback(async()=>t.logout().then(()=>l(null)).then(()=>i(null)),[]);return{isLoading:s===void 0||a,currentUser:c,isValidating:h,error:f,login:v,logout:y,updateCurrentUser:l,getUserCookie:o}},Fn=(n,e,t)=>{let r=`${e}/api/resource/`;return t?r+=`${n}/${t}`:r+=`${n}`,r},ta=(n,e,t,r)=>{const{url:s,db:i}=d.useContext(Z);return{...it(t===void 0?Fn(n,s,e):t,()=>i.getDoc(n,e),r)}},ps=n=>{var t,r,s;let e="";if(n!=null&&n.fields&&(e+="fields="+JSON.stringify(n==null?void 0:n.fields)+"&"),n!=null&&n.filters&&(e+="filters="+JSON.stringify(n==null?void 0:n.filters)+"&"),n!=null&&n.orFilters&&(e+="or_filters="+JSON.stringify(n==null?void 0:n.orFilters)+"&"),n!=null&&n.limit_start&&(e+="limit_start="+JSON.stringify(n==null?void 0:n.limit_start)+"&"),n!=null&&n.limit&&(e+="limit="+JSON.stringify(n==null?void 0:n.limit)+"&"),n!=null&&n.groupBy&&(e+="group_by="+String(n.groupBy)+"&"),n!=null&&n.orderBy){const i=`${String((t=n.orderBy)==null?void 0:t.field)} ${(s=(r=n.orderBy)==null?void 0:r.order)!=null?s:"asc"}`;e+="order_by="+i+"&"}return n!=null&&n.asDict&&(e+="as_dict="+n.asDict),e},na=(n,e,t,r)=>{const{url:s,db:i}=d.useContext(Z);return{...it(t===void 0?`${Fn(n,s)}?${ps(e)}`:t,()=>i.getDocList(n,e),r)}},ra=()=>{const{db:n}=d.useContext(Z),[e,t]=d.useState(!1),[r,s]=d.useState(null),[i,o]=d.useState(!1),c=d.useCallback(()=>{t(!1),s(null),o(!1)},[]);return{createDoc:d.useCallback(async(a,h)=>(s(null),o(!1),t(!0),n.createDoc(a,h).then(l=>(t(!1),o(!0),l)).catch(l=>{throw t(!1),o(!1),s(l),l})),[]),loading:e,error:r,isCompleted:i,reset:c}},sa=()=>{const{db:n}=d.useContext(Z),[e,t]=d.useState(!1),[r,s]=d.useState(null),[i,o]=d.useState(!1),c=d.useCallback(()=>{t(!1),s(null),o(!1)},[]);return{updateDoc:d.useCallback(async(a,h,l)=>(s(null),o(!1),t(!0),n.updateDoc(a,h,l).then(v=>(t(!1),o(!0),v)).catch(v=>{throw t(!1),o(!1),s(v),v})),[]),loading:e,error:r,reset:c,isCompleted:i}},ia=()=>{const{db:n}=d.useContext(Z),[e,t]=d.useState(!1),[r,s]=d.useState(null),[i,o]=d.useState(!1),c=d.useCallback(()=>{t(!1),s(null),o(!1)},[]);return{deleteDoc:d.useCallback(async(a,h)=>(s(null),o(!1),t(!0),n.deleteDoc(a,h).then(l=>(t(!1),o(!0),l)).catch(l=>{throw t(!1),o(!1),s(l),l})),[]),loading:e,error:r,reset:c,isCompleted:i}};function vs(n){const e=[];for(let t in n)e.push(encodeURIComponent(t)+"="+encodeURIComponent(n[t]));return e.join("&")}const oa=(n,e,t=!1,r=!1,s,i)=>{const{url:o,db:c}=d.useContext(Z);return{...it(s===void 0?(()=>{const h=vs(t?{doctype:n,filters:e!=null?e:[],cache:t,debug:r}:{doctype:n,filters:e!=null?e:[],debug:r});return`${o}/api/method/frappe.client.get_count?${h}`})():s,()=>c.getCount(n,e,t,r),i)}},ys=(n,e,t,r)=>{const{call:s}=d.useContext(Z),i=vs(e!=null?e:{}),o=`${n}?${i}`;return{...it(t===void 0?o:t,()=>s.get(n,e),r)}},aa=n=>{const{call:e}=d.useContext(Z),[t,r]=d.useState(null),[s,i]=d.useState(!1),[o,c]=d.useState(null),[f,a]=d.useState(!1),h=d.useCallback(()=>{r(null),i(!1),c(null),a(!1)},[]);return{call:d.useCallback(async v=>(c(null),a(!1),i(!0),r(null),e.post(n,v).then(y=>(r(y),i(!1),a(!0),y)).catch(y=>{throw i(!1),a(!1),c(y),y})),[]),result:t,loading:s,error:o,reset:h,isCompleted:f}},ua=n=>{const{call:e}=d.useContext(Z),[t,r]=d.useState(null),[s,i]=d.useState(!1),[o,c]=d.useState(null),[f,a]=d.useState(!1),h=d.useCallback(()=>{r(null),i(!1),c(null),a(!1)},[]);return{call:d.useCallback(async v=>(c(null),a(!1),i(!0),r(null),e.put(n,v).then(y=>(r(y),i(!1),a(!0),y)).catch(y=>{throw i(!1),a(!1),c(y),y})),[]),result:t,loading:s,error:o,reset:h,isCompleted:f}},ca=n=>{const{call:e}=d.useContext(Z),[t,r]=d.useState(null),[s,i]=d.useState(!1),[o,c]=d.useState(null),[f,a]=d.useState(!1),h=d.useCallback(()=>{r(null),i(!1),c(null),a(!1)},[]);return{call:d.useCallback(async v=>(c(null),a(!1),i(!0),r(null),e.delete(n,v).then(y=>(r(y),i(!1),a(!0),y)).catch(y=>{throw i(!1),a(!1),c(y),y})),[]),result:t,loading:s,error:o,reset:h,isCompleted:f}},la=()=>{const{file:n}=d.useContext(Z),[e,t]=d.useState(0),[r,s]=d.useState(!1),[i,o]=d.useState(null),[c,f]=d.useState(!1),a=d.useCallback(async(l,v)=>(h(),s(!0),n.uploadFile(l,v,(y,w)=>t(Math.round(y/w*100))).then(y=>(f(!0),t(100),s(!1),y.data.message)).catch(y=>{throw console.error(y),o(y),s(!1),y})),[]),h=d.useCallback(()=>{t(0),s(!1),o(null),f(!1)},[]);return{upload:a,progress:e,loading:r,isCompleted:c,error:i,reset:h}},fa=(n,e,t=[],r=20,s=250)=>{const i=ha(e,s);return ys("frappe.desk.search.search_link",{doctype:n,page_length:r,txt:i,filters:JSON.stringify(t!=null?t:[])})},ha=(n,e)=>{const[t,r]=d.useState(n);return d.useEffect(()=>{const s=setTimeout(()=>{r(n)},e);return()=>{clearTimeout(s)}},[n,e]),t},Pt=(n,e)=>{const{socket:t}=d.useContext(Z);d.useEffect(()=>{let r=t.on(n,e);return()=>{r.off(n)}},[n,e])},da=(n,e,t,r=!0)=>{const{socket:s}=d.useContext(Z),[i,o]=d.useState([]);d.useEffect(()=>(s.emit("doc_subscribe",n,e),r&&s.emit("doc_open",n,e),()=>{s.emit("doc_unsubscribe",n,e),r&&s.emit("doc_close",n,e)}),[n,e,r]),Pt("doc_update",t);const c=d.useCallback(()=>{s.emit("doc_open",n,e)},[n,e]),f=d.useCallback(()=>{s.emit("doc_close",n,e)},[n,e]),a=d.useCallback(h=>{h.doctype===n&&h.docname===e&&o(h.users)},[n,e]);return Pt("doc_viewers",a),{viewers:i,emitDocOpen:c,emitDocClose:f}},pa=(n,e)=>{const{socket:t}=d.useContext(Z);d.useEffect(()=>(t.emit("doctype_subscribe",n),()=>{t.emit("doctype_unsubscribe",n)}),[n]),Pt("list_update",e)};A.FrappeContext=Z,A.FrappeProvider=$o,A.getDocListQueryString=ps,A.getRequestURL=Fn,A.useFrappeAuth=ea,A.useFrappeCreateDoc=ra,A.useFrappeDeleteCall=ca,A.useFrappeDeleteDoc=ia,A.useFrappeDocTypeEventListener=pa,A.useFrappeDocumentEventListener=da,A.useFrappeEventListener=Pt,A.useFrappeFileUpload=la,A.useFrappeGetCall=ys,A.useFrappeGetDoc=ta,A.useFrappeGetDocCount=oa,A.useFrappeGetDocList=na,A.useFrappePostCall=aa,A.useFrappePutCall=ua,A.useFrappeUpdateDoc=sa,A.useSearch=fa,Object.defineProperties(A,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -332,7 +332,7 @@ export interface DocumentUpdateEventData {
|
|
|
332
332
|
* @param onUpdateCallback Function to be called when the document is updated. It is recommended to memoize this function.
|
|
333
333
|
* @returns viewers - array of userID's, emitDocOpen - function to emit doc_open event, emitDocClose - function to emit doc_close event
|
|
334
334
|
*/
|
|
335
|
-
export declare const useFrappeDocumentEventListener: (doctype: string, docname: string,
|
|
335
|
+
export declare const useFrappeDocumentEventListener: (doctype: string, docname: string, onUpdateCallback: (eventData: DocumentUpdateEventData) => void, emitOpenCloseEventsOnMount?: boolean) => {
|
|
336
336
|
/** Array of user IDs of users currently viewing the document. This is updated when "doc_viewers" event is published */
|
|
337
337
|
viewers: string[];
|
|
338
338
|
/** Emit doc_open event - this will explicitly send a doc_open event to the server. */
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "frappe-react-sdk",
|
|
3
3
|
"description": "React hooks for Frappe Framework",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.6",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "The Commit Company",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
}
|
|
90
90
|
},
|
|
91
91
|
"dependencies": {
|
|
92
|
-
"frappe-js-sdk": "^1.3.
|
|
92
|
+
"frappe-js-sdk": "^1.3.4",
|
|
93
93
|
"socket.io-client": "^4.5.1",
|
|
94
94
|
"swr": "^2.2.0"
|
|
95
95
|
}
|