@qwanyx/stack 0.2.3 → 0.2.5
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/dist/client/GraphClient.d.ts +51 -0
- package/dist/index.cjs.js +11 -11
- package/dist/index.esm.js +714 -594
- package/package.json +1 -1
|
@@ -83,4 +83,55 @@ export declare class GraphClient {
|
|
|
83
83
|
* Get all nodes of a specific type
|
|
84
84
|
*/
|
|
85
85
|
getNodesByType(type: string): Promise<GraphNode[]>;
|
|
86
|
+
/**
|
|
87
|
+
* Options for file upload
|
|
88
|
+
*/
|
|
89
|
+
private defaultUploadOptions;
|
|
90
|
+
/**
|
|
91
|
+
* Convert File to base64 string
|
|
92
|
+
*/
|
|
93
|
+
private fileToBase64;
|
|
94
|
+
/**
|
|
95
|
+
* Resize an image file if it exceeds maxDimension
|
|
96
|
+
* Returns the original file if not an image or no resize needed
|
|
97
|
+
*/
|
|
98
|
+
private resizeImage;
|
|
99
|
+
/**
|
|
100
|
+
* Upload a file to a node
|
|
101
|
+
* @param nodeId - The node to attach the file to
|
|
102
|
+
* @param filename - The filename to use
|
|
103
|
+
* @param file - The File object to upload
|
|
104
|
+
* @param options - Upload options (maxSizeMB, maxImageDimension, imageQuality)
|
|
105
|
+
*/
|
|
106
|
+
uploadFile(nodeId: string, filename: string, file: File, options?: {
|
|
107
|
+
maxSizeMB?: number;
|
|
108
|
+
maxImageDimension?: number;
|
|
109
|
+
imageQuality?: number;
|
|
110
|
+
}): Promise<{
|
|
111
|
+
success: boolean;
|
|
112
|
+
path?: string;
|
|
113
|
+
error?: string;
|
|
114
|
+
}>;
|
|
115
|
+
/**
|
|
116
|
+
* List files attached to a node
|
|
117
|
+
* @param nodeId - The node to list files for
|
|
118
|
+
*/
|
|
119
|
+
listFiles(nodeId: string): Promise<{
|
|
120
|
+
filename: string;
|
|
121
|
+
path: string;
|
|
122
|
+
}[]>;
|
|
123
|
+
/**
|
|
124
|
+
* Delete a file from a node
|
|
125
|
+
* @param nodeId - The node the file belongs to
|
|
126
|
+
* @param filename - The filename to delete
|
|
127
|
+
*/
|
|
128
|
+
deleteFile(nodeId: string, filename: string): Promise<{
|
|
129
|
+
success: boolean;
|
|
130
|
+
}>;
|
|
131
|
+
/**
|
|
132
|
+
* Get the URL for a file
|
|
133
|
+
* @param nodeId - The node the file belongs to
|
|
134
|
+
* @param filename - The filename
|
|
135
|
+
*/
|
|
136
|
+
getFileUrl(nodeId: string, filename: string): string;
|
|
86
137
|
}
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var wt=Object.defineProperty;var _t=(
|
|
1
|
+
"use strict";var wt=Object.defineProperty;var _t=(p,t,r)=>t in p?wt(p,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):p[t]=r;var ce=(p,t,r)=>_t(p,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react");class jt{constructor(t){ce(this,"config");ce(this,"defaultUploadOptions",{maxSizeMB:10,maxImageDimension:0,imageQuality:.9});if(!t.system_id)throw new Error("GraphClient: system_id is REQUIRED. No system_id → No start.");this.config=t}async callGraph(t,r={}){const n={coprocessor:"graph",method:t,system_id:this.config.system_id,params:r};try{const i=await fetch(`${this.config.baseUrl}/spu/invoke`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.getToken()}`},body:JSON.stringify(n)});if(!i.ok){const l=await i.text();throw new Error(`API error (${i.status}): ${l}`)}const s=await i.json();if(!s.success&&s.error)throw new Error(s.error);return s}catch(i){throw console.error("Graph API call failed:",i),i}}getToken(){return typeof window<"u"&&window.localStorage&&localStorage.getItem("qwanyx_token")||""}async getChildren(t){return(await this.callGraph("get_children",{parent_id:t})).result||[]}async getNode(t){return(await this.callGraph("get_node",{node_id:t})).result||null}async addNode(t){const r={...t,created:t.created||new Date().toISOString(),modified:new Date().toISOString()},n=await this.callGraph("add_node",r);if(!n.result)throw new Error("Failed to add node");return n.result}async updateNode(t,r){const n={node_id:t,updates:{...r,modified:new Date().toISOString()}},i=await this.callGraph("update_node",n);if(!i.result)throw new Error("Failed to update node");return i.result}async deleteNode(t,r=!1){return(await this.callGraph("delete_node",{node_id:t,cascade:r})).success===!0}async getChildrenWithEdges(t,r="children",n,i){return(await this.callGraph("get_children_with_edges",{node_id:t,display_mode:r,edge_type:n,node_type:i})).result||[]}async addEdge(t,r,n="link",i){return await this.callGraph("add_edge",{source_id:t,target_id:r,edge_type:n,data:i})}async deleteEdge(t,r,n){return await this.callGraph("delete_edge",{source_id:t,target_id:r,edge_type:n})}async getEdges(t,r,n){return(await this.callGraph("get_edges",{source_id:t,edge_type:r,target_id:n})).result||[]}async getAncestors(t){return(await this.callGraph("get_ancestors",{node_id:t})).ancestors||[]}async getTree(t,r=10){return(await this.callGraph("get_tree",{root_id:t,max_depth:r})).tree||[]}async moveNode(t,r){const n=await this.callGraph("move",{node_id:t,new_parent_id:r});if(!n.node)throw new Error("Failed to move node");return n.node}async searchNodes(t,r){return(await this.callGraph("search",{query:t,type:r})).nodes||[]}async getNodesByType(t){return(await this.callGraph("get_nodes_by_type",{type:t})).result||[]}fileToBase64(t){return new Promise((r,n)=>{const i=new FileReader;i.onload=()=>{const l=i.result.split(",")[1];r(l)},i.onerror=()=>n(new Error("Failed to read file")),i.readAsDataURL(t)})}async resizeImage(t,r,n){return t.type.startsWith("image/")?new Promise(i=>{const s=new Image,l=URL.createObjectURL(t);s.onload=()=>{if(URL.revokeObjectURL(l),s.width<=r&&s.height<=r){i(t);return}let y,u;s.width>s.height?(y=r,u=Math.round(s.height/s.width*r)):(u=r,y=Math.round(s.width/s.height*r));const d=document.createElement("canvas");d.width=y,d.height=u;const x=d.getContext("2d");if(!x){i(t);return}x.drawImage(s,0,0,y,u);const _=t.type==="image/png"?"image/png":"image/jpeg";d.toBlob(R=>{if(R){const $=new File([R],t.name,{type:_});i($)}else i(t)},_,n)},s.onerror=()=>{URL.revokeObjectURL(l),i(t)},s.src=l}):t}async uploadFile(t,r,n,i={}){const s={...this.defaultUploadOptions,...i};try{let l=n;s.maxImageDimension>0&&n.type.startsWith("image/")&&(l=await this.resizeImage(n,s.maxImageDimension,s.imageQuality));const y=s.maxSizeMB*1024*1024;if(l.size>y)return{success:!1,error:`File too large (${(l.size/1024/1024).toFixed(1)} MB). Max: ${s.maxSizeMB} MB`};const u=await this.fileToBase64(l),d=await this.callGraph("upload_file",{node_id:t,filename:r,content:u});return d.success?{success:!0,path:d.path}:{success:!1,error:d.error||"Upload failed"}}catch(l){return{success:!1,error:l instanceof Error?l.message:"Upload failed"}}}async listFiles(t){return(await this.callGraph("list_files",{node_id:t})).files||[]}async deleteFile(t,r){return{success:(await this.callGraph("delete_file",{node_id:t,filename:r})).success||!1}}getFileUrl(t,r){return`${this.config.baseUrl}/files/${this.config.system_id}/${t}/${r}`}}class Xe{constructor(t){ce(this,"config");if(!t.system_id)throw new Error("MailClient: system_id is REQUIRED");this.config=t}async callMail(t,r={}){const n={coprocessor:"mail",method:t,system_id:this.config.system_id,params:{user_id:this.config.system_id,...r}};try{const i=await fetch(`${this.config.baseUrl}/spu/invoke`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.getToken()}`},body:JSON.stringify(n)});if(!i.ok){const l=await i.text();throw new Error(`API error (${i.status}): ${l}`)}const s=await i.json();if(!s.success&&s.error)throw new Error(s.error);return s.result}catch(i){throw console.error("Mail API call failed:",i),i}}getToken(){return typeof window<"u"&&window.localStorage&&localStorage.getItem("qwanyx_token")||""}async getSettings(){try{return await this.callMail("get_email_settings")||{accounts:[]}}catch{return{accounts:[]}}}async saveSettings(t){await this.callMail("save_email_settings",{accounts:t})}async listEmails(t,r=20){return this.callMail("list_emails",{account_id:t,limit:r})}async deleteEmails(t,r,n=!0){return this.callMail("delete_emails",{account_id:t,uids:r,expunge:n})}async imapExec(t,r){return this.callMail("imap_exec",{account_id:t,commands:r})}async trashEmails(t,r){const n=["SELECT INBOX",...r.map(l=>`UID MOVE ${l} [Gmail]/Trash`)],s=(await this.imapExec(t,n)).responses.filter(l=>l.ok&&l.command==="UID MOVE").length;return{success:s>0,moved:s}}async archiveEmails(t,r){const n=["SELECT INBOX",...r.map(l=>`UID STORE ${l} +FLAGS (\\Deleted)`),"EXPUNGE"],s=(await this.imapExec(t,n)).responses.filter(l=>l.ok&&l.command==="UID STORE").length;return{success:s>0,archived:s}}async listFolders(t){const n=(await this.imapExec(t,['LIST "" *'])).responses.find(i=>i.command==="LIST");return n!=null&&n.ok&&n.folders?{success:!0,folders:n.folders}:{success:!1,folders:[]}}}const Ae="qwanyx_auth_token",$e="qwanyx_refresh_token";class He{static setToken(t){typeof window<"u"&&localStorage.setItem(Ae,t)}static getToken(){return typeof window<"u"?localStorage.getItem(Ae):null}static clearToken(){typeof window<"u"&&(localStorage.removeItem(Ae),localStorage.removeItem($e))}static setRefreshToken(t){typeof window<"u"&&localStorage.setItem($e,t)}static getRefreshToken(){return typeof window<"u"?localStorage.getItem($e):null}static isAuthenticated(){return!!this.getToken()}static getAuthHeader(){const t=this.getToken();return t?{Authorization:`Bearer ${t}`}:{}}}class Ze{constructor(t){ce(this,"config");this.config={timeout:3e4,headers:{"Content-Type":"application/json"},...t}}buildQueryString(t){if(!t||Object.keys(t).length===0)return"";const r=new URLSearchParams;Object.entries(t).forEach(([i,s])=>{s!=null&&r.append(i,String(s))});const n=r.toString();return n?`?${n}`:""}async request(t,r={}){const{method:n="GET",headers:i={},body:s,params:l}=r,y=`${this.config.baseUrl}/${t}${this.buildQueryString(l)}`,u={...this.config.headers,...He.getAuthHeader(),...i},d={method:n,headers:u};s&&n!=="GET"&&(d.body=JSON.stringify(s));try{const x=new AbortController,_=setTimeout(()=>x.abort(),this.config.timeout),R=await fetch(y,{...d,signal:x.signal});if(clearTimeout(_),!R.ok){const $=await R.json().catch(()=>({message:R.statusText}));throw new Error($.message||`HTTP ${R.status}`)}return await R.json()}catch(x){throw x instanceof Error?x:new Error("An unexpected error occurred")}}async get(t,r){return this.request(t,{method:"GET",params:r})}async post(t,r,n){return this.request(t,{method:"POST",body:r,params:n})}async put(t,r,n){return this.request(t,{method:"PUT",body:r,params:n})}async patch(t,r,n){return this.request(t,{method:"PATCH",body:r,params:n})}async delete(t,r){return this.request(t,{method:"DELETE",params:r})}setBaseUrl(t){this.config.baseUrl=t}getBaseUrl(){return this.config.baseUrl}}let je=null;function Et(p){return je=new Ze(p),je}function Me(){if(!je)throw new Error("API client not initialized. Call initializeApiClient() first.");return je}function et(p,t,r={}){const{enabled:n=!0,refetchOnMount:i=!0,onSuccess:s,onError:l}=r,[y,u]=b.useState(null),[d,x]=b.useState(n),[_,R]=b.useState(null),$=b.useCallback(async()=>{if(n){x(!0),R(null);try{const C=await Me().get(p,t);u(C),s==null||s(C)}catch(P){const C=P instanceof Error?P:new Error("Unknown error");R(C),l==null||l(C)}finally{x(!1)}}},[p,JSON.stringify(t),n,s,l]);return b.useEffect(()=>{i&&$()},[$,i]),{data:y,loading:d,error:_,refetch:$}}function St(p,t="POST",r={}){const{onSuccess:n,onError:i}=r,[s,l]=b.useState(null),[y,u]=b.useState(!1),[d,x]=b.useState(null),_=b.useCallback(async $=>{u(!0),x(null);try{const P=Me();let C;switch(t){case"POST":C=await P.post(p,$);break;case"PUT":C=await P.put(p,$);break;case"PATCH":C=await P.patch(p,$);break;case"DELETE":C=await P.delete(p);break;default:throw new Error(`Unsupported method: ${t}`)}return l(C),n==null||n(C,$),C}catch(P){const C=P instanceof Error?P:new Error("Unknown error");return x(C),i==null||i(C,$),null}finally{u(!1)}},[p,t,n,i]),R=b.useCallback(()=>{l(null),x(null),u(!1)},[]);return{data:s,loading:y,error:d,mutate:_,reset:R}}var Fe={exports:{}},ue={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var Ke;function kt(){if(Ke)return
|
|
9
|
+
*/var Ke;function kt(){if(Ke)return ue;Ke=1;var p=b,t=Symbol.for("react.element"),r=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,i=p.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function l(y,u,d){var x,_={},R=null,$=null;d!==void 0&&(R=""+d),u.key!==void 0&&(R=""+u.key),u.ref!==void 0&&($=u.ref);for(x in u)n.call(u,x)&&!s.hasOwnProperty(x)&&(_[x]=u[x]);if(y&&y.defaultProps)for(x in u=y.defaultProps,u)_[x]===void 0&&(_[x]=u[x]);return{$$typeof:t,type:y,key:R,ref:$,props:_,_owner:i.current}}return ue.Fragment=r,ue.jsx=l,ue.jsxs=l,ue}var de={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,21 +14,21 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var
|
|
18
|
-
`+ie+e}}var oe=!1,re;{var ke=typeof WeakMap=="function"?WeakMap:Map;re=new ke}function
|
|
19
|
-
`),G=
|
|
20
|
-
`),
|
|
21
|
-
`+
|
|
17
|
+
*/var Qe;function Rt(){return Qe||(Qe=1,process.env.NODE_ENV!=="production"&&function(){var p=b,t=Symbol.for("react.element"),r=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),y=Symbol.for("react.context"),u=Symbol.for("react.forward_ref"),d=Symbol.for("react.suspense"),x=Symbol.for("react.suspense_list"),_=Symbol.for("react.memo"),R=Symbol.for("react.lazy"),$=Symbol.for("react.offscreen"),P=Symbol.iterator,C="@@iterator";function Q(e){if(e===null||typeof e!="object")return null;var o=P&&e[P]||e[C];return typeof o=="function"?o:null}var z=p.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function g(e){{for(var o=arguments.length,c=new Array(o>1?o-1:0),m=1;m<o;m++)c[m-1]=arguments[m];D("error",e,c)}}function D(e,o,c){{var m=z.ReactDebugCurrentFrame,N=m.getStackAddendum();N!==""&&(o+="%s",c=c.concat([N]));var A=c.map(function(k){return String(k)});A.unshift("Warning: "+o),Function.prototype.apply.call(console[e],console,A)}}var V=!1,X=!1,v=!1,O=!1,F=!1,h;h=Symbol.for("react.module.reference");function T(e){return!!(typeof e=="string"||typeof e=="function"||e===n||e===s||F||e===i||e===d||e===x||O||e===$||V||X||v||typeof e=="object"&&e!==null&&(e.$$typeof===R||e.$$typeof===_||e.$$typeof===l||e.$$typeof===y||e.$$typeof===u||e.$$typeof===h||e.getModuleId!==void 0))}function E(e,o,c){var m=e.displayName;if(m)return m;var N=o.displayName||o.name||"";return N!==""?c+"("+N+")":c}function H(e){return e.displayName||"Context"}function B(e){if(e==null)return null;if(typeof e.tag=="number"&&g("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case n:return"Fragment";case r:return"Portal";case s:return"Profiler";case i:return"StrictMode";case d:return"Suspense";case x:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case y:var o=e;return H(o)+".Consumer";case l:var c=e;return H(c._context)+".Provider";case u:return E(e,e.render,"ForwardRef");case _:var m=e.displayName||null;return m!==null?m:B(e.type)||"Memo";case R:{var N=e,A=N._payload,k=N._init;try{return B(k(A))}catch{return null}}}return null}var S=Object.assign,M=0,Y,fe,pe,he,ge,ye,xe;function me(){}me.__reactDisabledLog=!0;function Ee(){{if(M===0){Y=console.log,fe=console.info,pe=console.warn,he=console.error,ge=console.group,ye=console.groupCollapsed,xe=console.groupEnd;var e={configurable:!0,enumerable:!0,value:me,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}M++}}function Se(){{if(M--,M===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:S({},e,{value:Y}),info:S({},e,{value:fe}),warn:S({},e,{value:pe}),error:S({},e,{value:he}),group:S({},e,{value:ge}),groupCollapsed:S({},e,{value:ye}),groupEnd:S({},e,{value:xe})})}M<0&&g("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ae=z.ReactCurrentDispatcher,ie;function te(e,o,c){{if(ie===void 0)try{throw Error()}catch(N){var m=N.stack.trim().match(/\n( *(at )?)/);ie=m&&m[1]||""}return`
|
|
18
|
+
`+ie+e}}var oe=!1,re;{var ke=typeof WeakMap=="function"?WeakMap:Map;re=new ke}function ve(e,o){if(!e||oe)return"";{var c=re.get(e);if(c!==void 0)return c}var m;oe=!0;var N=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var A;A=ae.current,ae.current=null,Ee();try{if(o){var k=function(){throw Error()};if(Object.defineProperty(k.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(k,[])}catch(q){m=q}Reflect.construct(e,[],k)}else{try{k.call()}catch(q){m=q}e.call(k.prototype)}}else{try{throw Error()}catch(q){m=q}e()}}catch(q){if(q&&m&&typeof q.stack=="string"){for(var j=q.stack.split(`
|
|
19
|
+
`),G=m.stack.split(`
|
|
20
|
+
`),U=j.length-1,I=G.length-1;U>=1&&I>=0&&j[U]!==G[I];)I--;for(;U>=1&&I>=0;U--,I--)if(j[U]!==G[I]){if(U!==1||I!==1)do if(U--,I--,I<0||j[U]!==G[I]){var K=`
|
|
21
|
+
`+j[U].replace(" at new "," at ");return e.displayName&&K.includes("<anonymous>")&&(K=K.replace("<anonymous>",e.displayName)),typeof e=="function"&&re.set(e,K),K}while(U>=1&&I>=0);break}}}finally{oe=!1,ae.current=A,Se(),Error.prepareStackTrace=N}var se=e?e.displayName||e.name:"",ee=se?te(se):"";return typeof e=="function"&&re.set(e,ee),ee}function Re(e,o,c){return ve(e,!1)}function f(e){var o=e.prototype;return!!(o&&o.isReactComponent)}function w(e,o,c){if(e==null)return"";if(typeof e=="function")return ve(e,f(e));if(typeof e=="string")return te(e);switch(e){case d:return te("Suspense");case x:return te("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case u:return Re(e.render);case _:return w(e.type,o,c);case R:{var m=e,N=m._payload,A=m._init;try{return w(A(N),o,c)}catch{}}}return""}var L=Object.prototype.hasOwnProperty,W={},Z=z.ReactDebugCurrentFrame;function J(e){if(e){var o=e._owner,c=w(e.type,e._source,o?o.type:null);Z.setExtraStackFrame(c)}else Z.setExtraStackFrame(null)}function Te(e,o,c,m,N){{var A=Function.call.bind(L);for(var k in e)if(A(e,k)){var j=void 0;try{if(typeof e[k]!="function"){var G=Error((m||"React class")+": "+c+" type `"+k+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[k]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw G.name="Invariant Violation",G}j=e[k](o,k,m,c,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(U){j=U}j&&!(j instanceof Error)&&(J(N),g("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",m||"React class",c,k,typeof j),J(null)),j instanceof Error&&!(j.message in W)&&(W[j.message]=!0,J(N),g("Failed %s type: %s",c,j.message),J(null))}}}var be=Array.isArray;function le(e){return be(e)}function tt(e){{var o=typeof Symbol=="function"&&Symbol.toStringTag,c=o&&e[Symbol.toStringTag]||e.constructor.name||"Object";return c}}function rt(e){try{return Ue(e),!1}catch{return!0}}function Ue(e){return""+e}function De(e){if(rt(e))return g("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",tt(e)),Ue(e)}var Ie=z.ReactCurrentOwner,nt={key:!0,ref:!0,__self:!0,__source:!0},Be,Le;function st(e){if(L.call(e,"ref")){var o=Object.getOwnPropertyDescriptor(e,"ref").get;if(o&&o.isReactWarning)return!1}return e.ref!==void 0}function at(e){if(L.call(e,"key")){var o=Object.getOwnPropertyDescriptor(e,"key").get;if(o&&o.isReactWarning)return!1}return e.key!==void 0}function it(e,o){typeof e.ref=="string"&&Ie.current}function ot(e,o){{var c=function(){Be||(Be=!0,g("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",o))};c.isReactWarning=!0,Object.defineProperty(e,"key",{get:c,configurable:!0})}}function lt(e,o){{var c=function(){Le||(Le=!0,g("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",o))};c.isReactWarning=!0,Object.defineProperty(e,"ref",{get:c,configurable:!0})}}var ct=function(e,o,c,m,N,A,k){var j={$$typeof:t,type:e,key:o,ref:c,props:k,_owner:A};return j._store={},Object.defineProperty(j._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(j,"_self",{configurable:!1,enumerable:!1,writable:!1,value:m}),Object.defineProperty(j,"_source",{configurable:!1,enumerable:!1,writable:!1,value:N}),Object.freeze&&(Object.freeze(j.props),Object.freeze(j)),j};function ut(e,o,c,m,N){{var A,k={},j=null,G=null;c!==void 0&&(De(c),j=""+c),at(o)&&(De(o.key),j=""+o.key),st(o)&&(G=o.ref,it(o,N));for(A in o)L.call(o,A)&&!nt.hasOwnProperty(A)&&(k[A]=o[A]);if(e&&e.defaultProps){var U=e.defaultProps;for(A in U)k[A]===void 0&&(k[A]=U[A])}if(j||G){var I=typeof e=="function"?e.displayName||e.name||"Unknown":e;j&&ot(k,I),G&<(k,I)}return ct(e,j,G,N,m,Ie.current,k)}}var Oe=z.ReactCurrentOwner,ze=z.ReactDebugCurrentFrame;function ne(e){if(e){var o=e._owner,c=w(e.type,e._source,o?o.type:null);ze.setExtraStackFrame(c)}else ze.setExtraStackFrame(null)}var Ce;Ce=!1;function Ne(e){return typeof e=="object"&&e!==null&&e.$$typeof===t}function We(){{if(Oe.current){var e=B(Oe.current.type);if(e)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+e+"`."}return""}}function dt(e){return""}var Ge={};function ft(e){{var
|
|
23
|
+
Check the render method of \``+e+"`."}return""}}function dt(e){return""}var Ge={};function ft(e){{var o=We();if(!o){var c=typeof e=="string"?e:e.displayName||e.name;c&&(o=`
|
|
24
24
|
|
|
25
|
-
Check the top-level render call using <`+c+">.")}return
|
|
25
|
+
Check the top-level render call using <`+c+">.")}return o}}function Ye(e,o){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var c=ft(o);if(Ge[c])return;Ge[c]=!0;var m="";e&&e._owner&&e._owner!==Oe.current&&(m=" It was passed a child from "+B(e._owner.type)+"."),ne(e),g('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',c,m),ne(null)}}function qe(e,o){{if(typeof e!="object")return;if(le(e))for(var c=0;c<e.length;c++){var m=e[c];Ne(m)&&Ye(m,o)}else if(Ne(e))e._store&&(e._store.validated=!0);else if(e){var N=Q(e);if(typeof N=="function"&&N!==e.entries)for(var A=N.call(e),k;!(k=A.next()).done;)Ne(k.value)&&Ye(k.value,o)}}}function pt(e){{var o=e.type;if(o==null||typeof o=="string")return;var c;if(typeof o=="function")c=o.propTypes;else if(typeof o=="object"&&(o.$$typeof===u||o.$$typeof===_))c=o.propTypes;else return;if(c){var m=B(o);Te(c,e.props,"prop",m,e)}else if(o.PropTypes!==void 0&&!Ce){Ce=!0;var N=B(o);g("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",N||"Unknown")}typeof o.getDefaultProps=="function"&&!o.getDefaultProps.isReactClassApproved&&g("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function ht(e){{for(var o=Object.keys(e.props),c=0;c<o.length;c++){var m=o[c];if(m!=="children"&&m!=="key"){ne(e),g("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",m),ne(null);break}}e.ref!==null&&(ne(e),g("Invalid attribute `ref` supplied to `React.Fragment`."),ne(null))}}var Ve={};function Je(e,o,c,m,N,A){{var k=T(e);if(!k){var j="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(j+=" 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 G=dt();G?j+=G:j+=We();var U;e===null?U="null":le(e)?U="array":e!==void 0&&e.$$typeof===t?(U="<"+(B(e.type)||"Unknown")+" />",j=" Did you accidentally export a JSX literal instead of a component?"):U=typeof e,g("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",U,j)}var I=ut(e,o,c,N,A);if(I==null)return I;if(k){var K=o.children;if(K!==void 0)if(m)if(le(K)){for(var se=0;se<K.length;se++)qe(K[se],e);Object.freeze&&Object.freeze(K)}else g("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 qe(K,e)}if(L.call(o,"key")){var ee=B(e),q=Object.keys(o).filter(function(bt){return bt!=="key"}),Pe=q.length>0?"{key: someKey, "+q.join(": ..., ")+": ...}":"{key: someKey}";if(!Ve[ee+Pe]){var vt=q.length>0?"{"+q.join(": ..., ")+": ...}":"{}";g(`A props object containing a "key" prop is being spread into JSX:
|
|
26
26
|
let props = %s;
|
|
27
27
|
<%s {...props} />
|
|
28
28
|
React keys must be passed directly to JSX without using spread:
|
|
29
29
|
let props = %s;
|
|
30
|
-
<%s key={someKey} {...props} />`,Pe,ee,vt,ee),Ve[ee+Pe]=!0}}return e===n?ht(
|
|
30
|
+
<%s key={someKey} {...props} />`,Pe,ee,vt,ee),Ve[ee+Pe]=!0}}return e===n?ht(I):pt(I),I}}function gt(e,o,c){return Je(e,o,c,!0)}function yt(e,o,c){return Je(e,o,c,!1)}var xt=yt,mt=gt;de.Fragment=n,de.jsx=xt,de.jsxs=mt}()),de}process.env.NODE_ENV==="production"?Fe.exports=kt():Fe.exports=Rt();var a=Fe.exports;class _e{static filter(t,r){return t.filter(r)}static filterBy(t,r,n){return t.filter(i=>i[r]===n)}static filterByFields(t,r){return t.filter(n=>Object.entries(r).every(([i,s])=>n[i]===s))}static sort(t,r,n="asc"){return[...t].sort((i,s)=>{const l=i[r],y=s[r];if(l===y)return 0;let u=0;return l>y&&(u=1),l<y&&(u=-1),n==="asc"?u:-u})}static search(t,r,n){if(!r.trim())return t;const i=r.toLowerCase();return t.filter(s=>n.some(l=>{const y=s[l];return y==null?!1:String(y).toLowerCase().includes(i)}))}static paginate(t,r,n){const i=(r-1)*n,s=i+n;return{data:t.slice(i,s),total:t.length,page:r,totalPages:Math.ceil(t.length/n)}}static groupBy(t,r){return t.reduce((n,i)=>{const s=String(i[r]);return n[s]||(n[s]=[]),n[s].push(i),n},{})}static unique(t,r){const n=t.map(i=>i[r]);return[...new Set(n)]}static countBy(t,r){return t.reduce((n,i)=>{const s=String(i[r]);return n[s]=(n[s]||0)+1,n},{})}static pipe(t,r){return r.reduce((n,i)=>i(n),t)}}function Tt({endpoint:p,params:t,layout:r="list",title:n,emptyMessage:i="No items found",renderItem:s,keyExtractor:l=(C,Q)=>C.id||C._id||String(Q),searchable:y=!1,searchFields:u=[],searchPlaceholder:d="Search...",filters:x=[],pageSize:_=20,onItemClick:R,onRefresh:$,theme:P={}}){const{data:C,loading:Q,error:z,refetch:g}=et(p,t),[D,V]=b.useState(""),[X,v]=b.useState({}),[O,F]=b.useState(1),h=b.useMemo(()=>{if(!C)return{data:[],total:0,totalPages:0};let S=C;return y&&D&&u.length>0&&(S=_e.search(S,D,u)),Object.keys(X).length>0&&(S=_e.filterByFields(S,X)),_e.paginate(S,O,_)},[C,D,X,O,_,y,u]);b.useEffect(()=>{F(1)},[D,X]);const T=()=>{V(""),v({}),F(1),g(),$==null||$()},E={background:P.background||"#ffffff",cardBackground:P.cardBackground||"#f9fafb",text:P.text||"#111827",textSecondary:P.textSecondary||"#6b7280",border:P.border||"#e5e7eb",primary:P.primary||"#3b82f6"},B=s||(S=>a.jsxs("div",{style:{padding:"16px",cursor:R?"pointer":"default"},children:[a.jsx("div",{style:{fontSize:"14px",fontWeight:500,color:E.text},children:S.title||S.name||S.label||"Untitled"}),S.description&&a.jsx("div",{style:{fontSize:"13px",color:E.textSecondary,marginTop:"4px"},children:S.description})]}));return Q&&!C?a.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"48px",color:E.textSecondary},children:"Loading..."}):z?a.jsxs("div",{style:{padding:"24px",textAlign:"center",color:"#ef4444"},children:[a.jsx("div",{style:{fontWeight:500,marginBottom:"8px"},children:"Error"}),a.jsx("div",{style:{fontSize:"14px"},children:z.message}),a.jsx("button",{onClick:T,style:{marginTop:"16px",padding:"8px 16px",background:E.primary,color:"white",border:"none",borderRadius:"6px",cursor:"pointer"},children:"Retry"})]}):a.jsxs("div",{style:{background:E.background,borderRadius:"12px",overflow:"hidden"},children:[(n||y||x.length>0)&&a.jsxs("div",{style:{padding:"16px",borderBottom:`1px solid ${E.border}`},children:[a.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:y||x.length>0?"12px":"0"},children:[n&&a.jsx("h2",{style:{margin:0,fontSize:"18px",fontWeight:600,color:E.text},children:n}),a.jsx("button",{onClick:T,style:{padding:"6px 12px",background:"transparent",border:`1px solid ${E.border}`,borderRadius:"6px",color:E.textSecondary,cursor:"pointer",fontSize:"13px"},children:"Refresh"})]}),y&&a.jsx("input",{type:"text",placeholder:d,value:D,onChange:S=>V(S.target.value),style:{width:"100%",padding:"8px 12px",border:`1px solid ${E.border}`,borderRadius:"8px",fontSize:"14px",outline:"none"}})]}),a.jsx("div",{style:{display:r==="grid"?"grid":"flex",flexDirection:r==="list"?"column":void 0,gridTemplateColumns:r==="grid"?"repeat(auto-fill, minmax(250px, 1fr))":void 0,gap:r==="list"?"0":"16px",padding:r==="list"?"0":"16px"},children:h.data.length===0?a.jsx("div",{style:{padding:"48px",textAlign:"center",color:E.textSecondary},children:i}):h.data.map((S,M)=>a.jsx("div",{onClick:()=>R==null?void 0:R(S),style:{background:E.cardBackground,borderRadius:r==="list"?"0":"8px",borderBottom:r==="list"?`1px solid ${E.border}`:"none",transition:"all 0.15s ease"},onMouseEnter:Y=>{R&&(Y.currentTarget.style.background=E.border)},onMouseLeave:Y=>{Y.currentTarget.style.background=E.cardBackground},children:B(S,M)},l(S,M)))}),h.totalPages>1&&a.jsxs("div",{style:{padding:"16px",borderTop:`1px solid ${E.border}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[a.jsxs("div",{style:{fontSize:"13px",color:E.textSecondary},children:["Page ",O," of ",h.totalPages]}),a.jsxs("div",{style:{display:"flex",gap:"8px"},children:[a.jsx("button",{onClick:()=>F(S=>Math.max(1,S-1)),disabled:O===1,style:{padding:"6px 12px",border:`1px solid ${E.border}`,borderRadius:"6px",background:"white",cursor:O===1?"not-allowed":"pointer",opacity:O===1?.5:1},children:"Previous"}),a.jsx("button",{onClick:()=>F(S=>Math.min(h.totalPages,S+1)),disabled:O===h.totalPages,style:{padding:"6px 12px",border:`1px solid ${E.border}`,borderRadius:"6px",background:"white",cursor:O===h.totalPages?"not-allowed":"pointer",opacity:O===h.totalPages?.5:1},children:"Next"})]})]})]})}function Ot({item:p,onClick:t,title:r=l=>l.title||l.name||l.label||"Untitled",subtitle:n=l=>l.description||l.subtitle||"",image:i=l=>l.image||l.thumbnail||l.photo,badge:s=l=>l.badge||l.tag||l.type}){const l=r(p),y=n(p),u=i(p),d=s(p);return a.jsxs("div",{onClick:t,className:`
|
|
31
31
|
flex items-center gap-4 p-4 border-b border-gray-200
|
|
32
32
|
hover:bg-gray-50 transition-colors
|
|
33
33
|
${t?"cursor-pointer":""}
|
|
34
|
-
`,children:[u&&s.jsx("div",{className:"flex-shrink-0",children:s.jsx("img",{src:u,alt:l,className:"w-16 h-16 object-cover rounded-lg"})}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("h3",{className:"font-medium text-gray-900 truncate",children:l}),h&&s.jsx("span",{className:"px-2 py-0.5 text-xs font-medium bg-blue-100 text-blue-800 rounded-full",children:h})]}),v&&s.jsx("p",{className:"text-sm text-gray-600 truncate mt-0.5",children:v})]}),t&&s.jsx("div",{className:"flex-shrink-0 text-gray-400",children:s.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:s.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})})]})}function Ct({item:f,onClose:t,title:r=o=>o.title||o.name||o.label||"Detail",image:n=o=>o.image||o.thumbnail||o.photo,fields:i=[]}){if(!f)return null;const o=r(f),l=n(f);return s.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:s.jsxs("div",{className:"bg-white rounded-xl max-w-2xl w-full max-h-[90vh] overflow-y-auto shadow-2xl",children:[s.jsxs("div",{className:"sticky top-0 bg-white border-b border-gray-200 px-6 py-4 flex items-center justify-between",children:[s.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:o}),t&&s.jsx("button",{onClick:t,className:"p-2 hover:bg-gray-100 rounded-lg transition-colors",children:s.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:s.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),s.jsxs("div",{className:"p-6",children:[l&&s.jsx("div",{className:"mb-6",children:s.jsx("img",{src:l,alt:o,className:"w-full h-64 object-cover rounded-lg"})}),i.length>0&&s.jsx("div",{className:"space-y-4",children:i.map((v,u)=>{const h=v.value(f);return h==null||h===""?null:s.jsxs("div",{children:[s.jsx("div",{className:"text-sm font-medium text-gray-500 mb-1",children:v.label}),s.jsx("div",{className:"text-base text-gray-900",children:typeof h=="object"?JSON.stringify(h,null,2):String(h)})]},u)})}),i.length===0&&s.jsx("pre",{className:"bg-gray-50 p-4 rounded-lg text-sm overflow-x-auto",children:JSON.stringify(f,null,2)})]}),t&&s.jsx("div",{className:"sticky bottom-0 bg-gray-50 border-t border-gray-200 px-6 py-4",children:s.jsx("button",{onClick:t,className:"w-full px-4 py-2 bg-gray-900 text-white rounded-lg hover:bg-gray-800 transition-colors font-medium",children:"Close"})})]})})}const Nt={small:"w-32 h-32",medium:"w-48 h-48",large:"w-64 h-64"};function Pt({nodes:f,cardCount:t=2,minInterval:r=1e3,maxInterval:n=3e3,onCardClick:i,cardSize:o="medium",className:l=""}){const v=Math.min(Math.max(t,1),5),[u,h]=b.useState([]),[x,j]=b.useState([]),[O,D]=b.useState(Array(v).fill(!1)),[P,C]=b.useState(Array(v).fill(!1)),X=b.useRef([]),z=b.useCallback(m=>{const T=f.filter(p=>!m.includes(p._id));if(T.length===0)return null;const $=Math.floor(Math.random()*T.length);return T[$]},[f]),g=b.useCallback(()=>Math.random()*(n-r)+r,[r,n]);b.useEffect(()=>{if(f.length===0){h([]),j([]);return}const m=[],T=[],$=[];for(let p=0;p<v&&p<f.length;p++){const R=z($);R&&(m.push(R),$.push(R._id))}for(let p=0;p<m.length;p++){const R=[m[p]._id,...m.filter((H,B)=>B!==p).map(H=>H._id)],E=z(R);E?T.push(E):T.push(m[p])}h(m),j(T)},[f,v,z]);const I=b.useCallback(m=>{const T=g(),$=setTimeout(()=>{D(p=>{const R=[...p];return R[m]=!R[m],R}),setTimeout(()=>{C(p=>{const R=[...p];return R[m]=!R[m],R}),setTimeout(()=>{const p=!P[m];p&&h(R=>{const E=[...R];return E[m]=x[m],E}),j(R=>{const E=[...R],B=[(p?x[m]:u[m])._id,...u.filter((M,Y)=>Y!==m).map(M=>M._id),...R.filter((M,Y)=>Y!==m).map(M=>M._id)],S=z(B);return S&&(E[m]=S),E}),setTimeout(()=>{I(m)},150)},200)},150)},T);X.current[m]=$},[g,z,u,x,P]),V=b.useRef(!1);b.useEffect(()=>{if(!(u.length===0||f.length<=1)&&!V.current){V.current=!0;for(let m=0;m<u.length;m++)I(m);return()=>{X.current.forEach(m=>clearTimeout(m)),X.current=[],V.current=!1}}},[u.length,f.length]);const Q=m=>{i&&i(m)};return f.length===0?s.jsx("div",{className:`flex items-center justify-center p-8 ${l}`,children:s.jsx("p",{className:"text-gray-500",children:"No nodes available"})}):u.length===0?s.jsx("div",{className:`flex items-center justify-center p-8 ${l}`,children:s.jsx("p",{className:"text-gray-500",children:"Loading..."})}):s.jsx("div",{className:`flex gap-4 justify-center items-center flex-wrap ${l}`,children:u.map((m,T)=>{const $=x[T],p=P[T];return s.jsx("div",{className:`relative ${Nt[o]}`,style:{perspective:"1000px"},onClick:()=>Q(p?$:m),children:s.jsxs("div",{className:"w-full h-full rounded-lg shadow-lg overflow-hidden cursor-pointer hover:shadow-xl",style:{transform:`rotateY(${O[T]?180:0}deg)`,transition:"transform 0.5s",transformStyle:"preserve-3d"},children:[s.jsx("div",{className:"absolute inset-0 transition-opacity duration-200",style:{opacity:p?0:1},children:s.jsxs("div",{style:{transform:O[T]?"scaleX(-1)":"scaleX(1)",width:"100%",height:"100%"},children:[s.jsx("img",{src:m.data.image,alt:m.title,className:"w-full h-full object-cover"}),s.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-gradient-to-t from-black/70 to-transparent p-2",children:s.jsx("p",{className:"text-white text-sm font-medium truncate",children:m.title})})]})}),$&&s.jsx("div",{className:"absolute inset-0 transition-opacity duration-200",style:{opacity:p?1:0},children:s.jsxs("div",{style:{transform:O[T]?"scaleX(-1)":"scaleX(1)",width:"100%",height:"100%"},children:[s.jsx("img",{src:$.data.image,alt:$.title,className:"w-full h-full object-cover"}),s.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-gradient-to-t from-black/70 to-transparent p-2",children:s.jsx("p",{className:"text-white text-sm font-medium truncate",children:$.title})})]})})]})},`slot-${T}`)})})}function we(f){if(!f)return"";const t=/=\?([^?]+)\?([BQbq])\?([^?]*)\?=/g;return f.replace(t,(r,n,i,o)=>{try{if(i.toUpperCase()==="B"){const l=atob(o);return decodeURIComponent(escape(l))}else if(i.toUpperCase()==="Q"){const l=o.replace(/_/g," ").replace(/=([0-9A-Fa-f]{2})/g,(v,u)=>String.fromCharCode(parseInt(u,16)));return decodeURIComponent(escape(l))}}catch(l){console.warn("MIME decode error:",l)}return r}).replace(/\s+/g," ").trim()}const At={background:"#ffffff",cardBackground:"#ffffff",selectedBackground:"#f5f5f5",unreadBackground:"#ffffff",text:"#111827",textSecondary:"#6b7280",border:"#e5e7eb",primary:"#3b82f6",danger:"#ef4444"};function $t({baseUrl:f,systemId:t,accountId:r,limit:n=30,selectable:i=!0,showDetail:o=!1,emptyMessage:l="No emails",autoLoad:v=!0,onSelect:u,onSelectionChange:h,onDelete:x,onError:j,renderItem:O,renderDetail:D,renderActions:P,renderEmpty:C,renderLoading:X,theme:z={}}){const g={...At,...z},[I,V]=b.useState([]),[Q,m]=b.useState(!1),[T,$]=b.useState(null),[p,R]=b.useState(new Set),[E,H]=b.useState(null),[B,S]=b.useState(null),M=b.useMemo(()=>t?new Qe({baseUrl:f,system_id:t}):null,[f,t]),Y=b.useCallback(async()=>{if(M){m(!0),$(null);try{const d=await M.listEmails(r,n);if(d!=null&&d.messages){const w=[...d.messages].sort((L,W)=>new Date(W.date).getTime()-new Date(L.date).getTime());V(w)}}catch(d){const w=d instanceof Error?d:new Error("Failed to fetch emails");$(w.message),j==null||j(w)}m(!1)}},[M,r,n,j]);b.useEffect(()=>{v&&Y()},[v,Y]);const de=b.useCallback((d,w,L)=>{if(!i){u==null||u(d),o&&S(d);return}const W=d.uid;if(L.shiftKey&&E!==null){const Z=Math.min(E,w),J=Math.max(E,w),Te=I.slice(Z,J+1).map(le=>le.uid),ve=new Set(Te);R(ve),h==null||h(Array.from(ve))}else if(L.ctrlKey||L.metaKey)R(Z=>{const J=new Set(Z);return J.has(W)?J.delete(W):J.add(W),h==null||h(Array.from(J)),J}),H(w);else if(p.size===1&&p.has(W))u==null||u(d),o&&S(d);else{const Z=new Set([W]);R(Z),H(w),h==null||h(Array.from(Z))}},[i,E,I,p,u,h,o]),fe=b.useCallback(async()=>{if(!(!M||p.size===0))try{const d=await M.trashEmails(r,Array.from(p));if(console.log("Trash result:",d),d.success&&d.moved>0){V(L=>L.filter(W=>!p.has(W.uid)));const w=Array.from(p);R(new Set),x==null||x(w)}else $("Failed to move emails to trash")}catch(d){const w=d instanceof Error?d:new Error("Trash failed");console.error("Trash error:",w),$(w.message),j==null||j(w)}},[M,r,p,x,j]),pe=b.useCallback(async()=>{if(!(!M||p.size===0))try{const d=await M.archiveEmails(r,Array.from(p));if(console.log("Archive result:",d),d.success&&d.archived>0){V(L=>L.filter(W=>!p.has(W.uid)));const w=Array.from(p);R(new Set),x==null||x(w)}else $("Failed to archive emails")}catch(d){const w=d instanceof Error?d:new Error("Archive failed");console.error("Archive error:",w),$(w.message),j==null||j(w)}},[M,r,p,x,j]),he=b.useCallback(()=>{if(p.size===I.length)R(new Set),h==null||h([]);else{const d=new Set(I.map(w=>w.uid));R(d),h==null||h(Array.from(d))}},[I,p.size,h]),ge=b.useCallback(()=>{R(new Set),h==null||h([])},[h]),ye={delete:fe,archive:pe,refresh:Y,selectAll:he,clearSelection:ge},xe=d=>{if(!d)return"";const w=new Date(d),L=new Date;return w.toDateString()===L.toDateString()?w.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):w.toLocaleDateString([],{month:"short",day:"numeric"})},Ee=(d,w)=>s.jsx("div",{style:{padding:"12px 16px",background:w?g.selectedBackground:d.seen?g.cardBackground:g.unreadBackground,borderBottom:`1px solid ${g.border}`,cursor:"pointer",transition:"background 0.15s ease"},children:s.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:"12px"},children:[s.jsxs("div",{style:{flex:1,minWidth:0},children:[s.jsx("div",{style:{fontSize:"14px",fontWeight:d.seen?400:600,color:g.text,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:we(d.from).split("@")[0]}),s.jsx("div",{style:{fontSize:"14px",fontWeight:d.seen?400:500,color:d.seen?g.textSecondary:g.text,marginTop:"2px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:we(d.subject)||"(No subject)"})]}),s.jsx("div",{style:{fontSize:"12px",color:g.textSecondary,flexShrink:0},children:xe(d.date)})]})}),Se=d=>s.jsxs("div",{style:{padding:"24px"},children:[s.jsx("h2",{style:{margin:"0 0 8px",fontSize:"20px",color:g.text},children:we(d.subject)||"(No subject)"}),s.jsxs("div",{style:{fontSize:"14px",color:g.textSecondary,marginBottom:"16px"},children:["From: ",we(d.from)," • ",new Date(d.date).toLocaleString()]}),s.jsx("div",{style:{fontSize:"14px",color:g.text},children:"Email body not loaded. Implement getEmail(uid) to fetch full content."})]}),ae=(d,w)=>s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 16px",background:g.cardBackground,borderBottom:`1px solid ${g.border}`},children:[s.jsx("button",{onClick:w.selectAll,style:{padding:"6px 12px",background:"transparent",border:`1px solid ${g.border}`,borderRadius:"6px",fontSize:"13px",cursor:"pointer",color:g.text},children:d.length===I.length?"Deselect All":"Select All"}),d.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs("span",{style:{fontSize:"13px",color:g.textSecondary},children:[d.length," selected"]}),s.jsx("button",{onClick:w.archive,title:"Archive",style:{display:"flex",alignItems:"center",justifyContent:"center",width:"32px",height:"32px",background:"transparent",border:`1px solid ${g.border}`,borderRadius:"6px",cursor:"pointer",color:g.textSecondary},children:s.jsx("span",{className:"material-icons",style:{fontSize:"18px"},children:"archive"})}),s.jsx("button",{onClick:w.delete,title:"Delete",style:{display:"flex",alignItems:"center",justifyContent:"center",width:"32px",height:"32px",background:"transparent",border:`1px solid ${g.border}`,borderRadius:"6px",cursor:"pointer",color:g.textSecondary},children:s.jsx("span",{className:"material-icons",style:{fontSize:"18px"},children:"delete"})})]}),s.jsx("div",{style:{flex:1}}),s.jsx("button",{onClick:w.refresh,title:"Refresh",style:{display:"flex",alignItems:"center",justifyContent:"center",width:"32px",height:"32px",background:"transparent",border:`1px solid ${g.border}`,borderRadius:"6px",cursor:"pointer",color:g.textSecondary},children:s.jsx("span",{className:"material-icons",style:{fontSize:"18px"},children:"refresh"})})]}),ie=()=>s.jsx("div",{style:{padding:"48px",textAlign:"center",color:g.textSecondary},children:l}),te=()=>s.jsx("div",{style:{padding:"48px",textAlign:"center",color:g.textSecondary},children:"Loading..."}),oe=O||Ee,re=D||Se,ke=P||ae,me=C||ie,Re=X||te;return Q&&I.length===0?s.jsx("div",{style:{background:g.background,width:"100%",height:"100%"},children:Re()}):s.jsxs("div",{style:{display:"flex",background:g.background,width:"100%",height:"100%"},children:[s.jsxs("div",{style:{flex:o&&B?"0 0 50%":"1",display:"flex",flexDirection:"column",borderRight:o&&B?`1px solid ${g.border}`:"none",overflow:"hidden"},children:[i&&ke(Array.from(p),ye),T&&s.jsx("div",{style:{padding:"12px 16px",background:"#fef2f2",color:g.danger,fontSize:"14px",borderBottom:`1px solid ${g.border}`},children:T}),s.jsx("div",{style:{flex:1,overflowY:"auto"},children:I.length===0?me():I.map((d,w)=>s.jsx("div",{onClick:L=>de(d,w,L),children:oe(d,p.has(d.uid))},d.uid))})]}),o&&B&&s.jsx("div",{style:{flex:1,overflowY:"auto"},children:re(B)})]})}exports.AnimatedCardFlip=Pt;exports.ApiClient=Ze;exports.AuthManager=He;exports.Card=Ot;exports.DataOperations=_e;exports.Detail=Ct;exports.GraphClient=jt;exports.Mail=$t;exports.MailClient=Qe;exports.Stack=Tt;exports.getApiClient=Me;exports.initializeApiClient=Et;exports.useMutation=St;exports.useQuery=et;
|
|
34
|
+
`,children:[u&&a.jsx("div",{className:"flex-shrink-0",children:a.jsx("img",{src:u,alt:l,className:"w-16 h-16 object-cover rounded-lg"})}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("h3",{className:"font-medium text-gray-900 truncate",children:l}),d&&a.jsx("span",{className:"px-2 py-0.5 text-xs font-medium bg-blue-100 text-blue-800 rounded-full",children:d})]}),y&&a.jsx("p",{className:"text-sm text-gray-600 truncate mt-0.5",children:y})]}),t&&a.jsx("div",{className:"flex-shrink-0 text-gray-400",children:a.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:a.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})})]})}function Ct({item:p,onClose:t,title:r=s=>s.title||s.name||s.label||"Detail",image:n=s=>s.image||s.thumbnail||s.photo,fields:i=[]}){if(!p)return null;const s=r(p),l=n(p);return a.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:a.jsxs("div",{className:"bg-white rounded-xl max-w-2xl w-full max-h-[90vh] overflow-y-auto shadow-2xl",children:[a.jsxs("div",{className:"sticky top-0 bg-white border-b border-gray-200 px-6 py-4 flex items-center justify-between",children:[a.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:s}),t&&a.jsx("button",{onClick:t,className:"p-2 hover:bg-gray-100 rounded-lg transition-colors",children:a.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:a.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),a.jsxs("div",{className:"p-6",children:[l&&a.jsx("div",{className:"mb-6",children:a.jsx("img",{src:l,alt:s,className:"w-full h-64 object-cover rounded-lg"})}),i.length>0&&a.jsx("div",{className:"space-y-4",children:i.map((y,u)=>{const d=y.value(p);return d==null||d===""?null:a.jsxs("div",{children:[a.jsx("div",{className:"text-sm font-medium text-gray-500 mb-1",children:y.label}),a.jsx("div",{className:"text-base text-gray-900",children:typeof d=="object"?JSON.stringify(d,null,2):String(d)})]},u)})}),i.length===0&&a.jsx("pre",{className:"bg-gray-50 p-4 rounded-lg text-sm overflow-x-auto",children:JSON.stringify(p,null,2)})]}),t&&a.jsx("div",{className:"sticky bottom-0 bg-gray-50 border-t border-gray-200 px-6 py-4",children:a.jsx("button",{onClick:t,className:"w-full px-4 py-2 bg-gray-900 text-white rounded-lg hover:bg-gray-800 transition-colors font-medium",children:"Close"})})]})})}const Nt={small:"w-32 h-32",medium:"w-48 h-48",large:"w-64 h-64"};function Pt({nodes:p,cardCount:t=2,minInterval:r=1e3,maxInterval:n=3e3,onCardClick:i,cardSize:s="medium",className:l=""}){const y=Math.min(Math.max(t,1),5),[u,d]=b.useState([]),[x,_]=b.useState([]),[R,$]=b.useState(Array(y).fill(!1)),[P,C]=b.useState(Array(y).fill(!1)),Q=b.useRef([]),z=b.useCallback(v=>{const O=p.filter(h=>!v.includes(h._id));if(O.length===0)return null;const F=Math.floor(Math.random()*O.length);return O[F]},[p]),g=b.useCallback(()=>Math.random()*(n-r)+r,[r,n]);b.useEffect(()=>{if(p.length===0){d([]),_([]);return}const v=[],O=[],F=[];for(let h=0;h<y&&h<p.length;h++){const T=z(F);T&&(v.push(T),F.push(T._id))}for(let h=0;h<v.length;h++){const T=[v[h]._id,...v.filter((H,B)=>B!==h).map(H=>H._id)],E=z(T);E?O.push(E):O.push(v[h])}d(v),_(O)},[p,y,z]);const D=b.useCallback(v=>{const O=g(),F=setTimeout(()=>{$(h=>{const T=[...h];return T[v]=!T[v],T}),setTimeout(()=>{C(h=>{const T=[...h];return T[v]=!T[v],T}),setTimeout(()=>{const h=!P[v];h&&d(T=>{const E=[...T];return E[v]=x[v],E}),_(T=>{const E=[...T],B=[(h?x[v]:u[v])._id,...u.filter((M,Y)=>Y!==v).map(M=>M._id),...T.filter((M,Y)=>Y!==v).map(M=>M._id)],S=z(B);return S&&(E[v]=S),E}),setTimeout(()=>{D(v)},150)},200)},150)},O);Q.current[v]=F},[g,z,u,x,P]),V=b.useRef(!1);b.useEffect(()=>{if(!(u.length===0||p.length<=1)&&!V.current){V.current=!0;for(let v=0;v<u.length;v++)D(v);return()=>{Q.current.forEach(v=>clearTimeout(v)),Q.current=[],V.current=!1}}},[u.length,p.length]);const X=v=>{i&&i(v)};return p.length===0?a.jsx("div",{className:`flex items-center justify-center p-8 ${l}`,children:a.jsx("p",{className:"text-gray-500",children:"No nodes available"})}):u.length===0?a.jsx("div",{className:`flex items-center justify-center p-8 ${l}`,children:a.jsx("p",{className:"text-gray-500",children:"Loading..."})}):a.jsx("div",{className:`flex gap-4 justify-center items-center flex-wrap ${l}`,children:u.map((v,O)=>{const F=x[O],h=P[O];return a.jsx("div",{className:`relative ${Nt[s]}`,style:{perspective:"1000px"},onClick:()=>X(h?F:v),children:a.jsxs("div",{className:"w-full h-full rounded-lg shadow-lg overflow-hidden cursor-pointer hover:shadow-xl",style:{transform:`rotateY(${R[O]?180:0}deg)`,transition:"transform 0.5s",transformStyle:"preserve-3d"},children:[a.jsx("div",{className:"absolute inset-0 transition-opacity duration-200",style:{opacity:h?0:1},children:a.jsxs("div",{style:{transform:R[O]?"scaleX(-1)":"scaleX(1)",width:"100%",height:"100%"},children:[a.jsx("img",{src:v.data.image,alt:v.title,className:"w-full h-full object-cover"}),a.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-gradient-to-t from-black/70 to-transparent p-2",children:a.jsx("p",{className:"text-white text-sm font-medium truncate",children:v.title})})]})}),F&&a.jsx("div",{className:"absolute inset-0 transition-opacity duration-200",style:{opacity:h?1:0},children:a.jsxs("div",{style:{transform:R[O]?"scaleX(-1)":"scaleX(1)",width:"100%",height:"100%"},children:[a.jsx("img",{src:F.data.image,alt:F.title,className:"w-full h-full object-cover"}),a.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-gradient-to-t from-black/70 to-transparent p-2",children:a.jsx("p",{className:"text-white text-sm font-medium truncate",children:F.title})})]})})]})},`slot-${O}`)})})}function we(p){if(!p)return"";const t=/=\?([^?]+)\?([BQbq])\?([^?]*)\?=/g;return p.replace(t,(r,n,i,s)=>{try{if(i.toUpperCase()==="B"){const l=atob(s);return decodeURIComponent(escape(l))}else if(i.toUpperCase()==="Q"){const l=s.replace(/_/g," ").replace(/=([0-9A-Fa-f]{2})/g,(y,u)=>String.fromCharCode(parseInt(u,16)));return decodeURIComponent(escape(l))}}catch(l){console.warn("MIME decode error:",l)}return r}).replace(/\s+/g," ").trim()}const At={background:"#ffffff",cardBackground:"#ffffff",selectedBackground:"#f5f5f5",unreadBackground:"#ffffff",text:"#111827",textSecondary:"#6b7280",border:"#e5e7eb",primary:"#3b82f6",danger:"#ef4444"};function $t({baseUrl:p,systemId:t,accountId:r,limit:n=30,selectable:i=!0,showDetail:s=!1,emptyMessage:l="No emails",autoLoad:y=!0,onSelect:u,onSelectionChange:d,onDelete:x,onError:_,renderItem:R,renderDetail:$,renderActions:P,renderEmpty:C,renderLoading:Q,theme:z={}}){const g={...At,...z},[D,V]=b.useState([]),[X,v]=b.useState(!1),[O,F]=b.useState(null),[h,T]=b.useState(new Set),[E,H]=b.useState(null),[B,S]=b.useState(null),M=b.useMemo(()=>t?new Xe({baseUrl:p,system_id:t}):null,[p,t]),Y=b.useCallback(async()=>{if(M){v(!0),F(null);try{const f=await M.listEmails(r,n);if(f!=null&&f.messages){const w=[...f.messages].sort((L,W)=>new Date(W.date).getTime()-new Date(L.date).getTime());V(w)}}catch(f){const w=f instanceof Error?f:new Error("Failed to fetch emails");F(w.message),_==null||_(w)}v(!1)}},[M,r,n,_]);b.useEffect(()=>{y&&Y()},[y,Y]);const fe=b.useCallback((f,w,L)=>{if(!i){u==null||u(f),s&&S(f);return}const W=f.uid;if(L.shiftKey&&E!==null){const Z=Math.min(E,w),J=Math.max(E,w),Te=D.slice(Z,J+1).map(le=>le.uid),be=new Set(Te);T(be),d==null||d(Array.from(be))}else if(L.ctrlKey||L.metaKey)T(Z=>{const J=new Set(Z);return J.has(W)?J.delete(W):J.add(W),d==null||d(Array.from(J)),J}),H(w);else if(h.size===1&&h.has(W))u==null||u(f),s&&S(f);else{const Z=new Set([W]);T(Z),H(w),d==null||d(Array.from(Z))}},[i,E,D,h,u,d,s]),pe=b.useCallback(async()=>{if(!(!M||h.size===0))try{const f=await M.trashEmails(r,Array.from(h));if(console.log("Trash result:",f),f.success&&f.moved>0){V(L=>L.filter(W=>!h.has(W.uid)));const w=Array.from(h);T(new Set),x==null||x(w)}else F("Failed to move emails to trash")}catch(f){const w=f instanceof Error?f:new Error("Trash failed");console.error("Trash error:",w),F(w.message),_==null||_(w)}},[M,r,h,x,_]),he=b.useCallback(async()=>{if(!(!M||h.size===0))try{const f=await M.archiveEmails(r,Array.from(h));if(console.log("Archive result:",f),f.success&&f.archived>0){V(L=>L.filter(W=>!h.has(W.uid)));const w=Array.from(h);T(new Set),x==null||x(w)}else F("Failed to archive emails")}catch(f){const w=f instanceof Error?f:new Error("Archive failed");console.error("Archive error:",w),F(w.message),_==null||_(w)}},[M,r,h,x,_]),ge=b.useCallback(()=>{if(h.size===D.length)T(new Set),d==null||d([]);else{const f=new Set(D.map(w=>w.uid));T(f),d==null||d(Array.from(f))}},[D,h.size,d]),ye=b.useCallback(()=>{T(new Set),d==null||d([])},[d]),xe={delete:pe,archive:he,refresh:Y,selectAll:ge,clearSelection:ye},me=f=>{if(!f)return"";const w=new Date(f),L=new Date;return w.toDateString()===L.toDateString()?w.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):w.toLocaleDateString([],{month:"short",day:"numeric"})},Ee=(f,w)=>a.jsx("div",{style:{padding:"12px 16px",background:w?g.selectedBackground:f.seen?g.cardBackground:g.unreadBackground,borderBottom:`1px solid ${g.border}`,cursor:"pointer",transition:"background 0.15s ease"},children:a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:"12px"},children:[a.jsxs("div",{style:{flex:1,minWidth:0},children:[a.jsx("div",{style:{fontSize:"14px",fontWeight:f.seen?400:600,color:g.text,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:we(f.from).split("@")[0]}),a.jsx("div",{style:{fontSize:"14px",fontWeight:f.seen?400:500,color:f.seen?g.textSecondary:g.text,marginTop:"2px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:we(f.subject)||"(No subject)"})]}),a.jsx("div",{style:{fontSize:"12px",color:g.textSecondary,flexShrink:0},children:me(f.date)})]})}),Se=f=>a.jsxs("div",{style:{padding:"24px"},children:[a.jsx("h2",{style:{margin:"0 0 8px",fontSize:"20px",color:g.text},children:we(f.subject)||"(No subject)"}),a.jsxs("div",{style:{fontSize:"14px",color:g.textSecondary,marginBottom:"16px"},children:["From: ",we(f.from)," • ",new Date(f.date).toLocaleString()]}),a.jsx("div",{style:{fontSize:"14px",color:g.text},children:"Email body not loaded. Implement getEmail(uid) to fetch full content."})]}),ae=(f,w)=>a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 16px",background:g.cardBackground,borderBottom:`1px solid ${g.border}`},children:[a.jsx("button",{onClick:w.selectAll,style:{padding:"6px 12px",background:"transparent",border:`1px solid ${g.border}`,borderRadius:"6px",fontSize:"13px",cursor:"pointer",color:g.text},children:f.length===D.length?"Deselect All":"Select All"}),f.length>0&&a.jsxs(a.Fragment,{children:[a.jsxs("span",{style:{fontSize:"13px",color:g.textSecondary},children:[f.length," selected"]}),a.jsx("button",{onClick:w.archive,title:"Archive",style:{display:"flex",alignItems:"center",justifyContent:"center",width:"32px",height:"32px",background:"transparent",border:`1px solid ${g.border}`,borderRadius:"6px",cursor:"pointer",color:g.textSecondary},children:a.jsx("span",{className:"material-icons",style:{fontSize:"18px"},children:"archive"})}),a.jsx("button",{onClick:w.delete,title:"Delete",style:{display:"flex",alignItems:"center",justifyContent:"center",width:"32px",height:"32px",background:"transparent",border:`1px solid ${g.border}`,borderRadius:"6px",cursor:"pointer",color:g.textSecondary},children:a.jsx("span",{className:"material-icons",style:{fontSize:"18px"},children:"delete"})})]}),a.jsx("div",{style:{flex:1}}),a.jsx("button",{onClick:w.refresh,title:"Refresh",style:{display:"flex",alignItems:"center",justifyContent:"center",width:"32px",height:"32px",background:"transparent",border:`1px solid ${g.border}`,borderRadius:"6px",cursor:"pointer",color:g.textSecondary},children:a.jsx("span",{className:"material-icons",style:{fontSize:"18px"},children:"refresh"})})]}),ie=()=>a.jsx("div",{style:{padding:"48px",textAlign:"center",color:g.textSecondary},children:l}),te=()=>a.jsx("div",{style:{padding:"48px",textAlign:"center",color:g.textSecondary},children:"Loading..."}),oe=R||Ee,re=$||Se,ke=P||ae,ve=C||ie,Re=Q||te;return X&&D.length===0?a.jsx("div",{style:{background:g.background,width:"100%",height:"100%"},children:Re()}):a.jsxs("div",{style:{display:"flex",background:g.background,width:"100%",height:"100%"},children:[a.jsxs("div",{style:{flex:s&&B?"0 0 50%":"1",display:"flex",flexDirection:"column",borderRight:s&&B?`1px solid ${g.border}`:"none",overflow:"hidden"},children:[i&&ke(Array.from(h),xe),O&&a.jsx("div",{style:{padding:"12px 16px",background:"#fef2f2",color:g.danger,fontSize:"14px",borderBottom:`1px solid ${g.border}`},children:O}),a.jsx("div",{style:{flex:1,overflowY:"auto"},children:D.length===0?ve():D.map((f,w)=>a.jsx("div",{onClick:L=>fe(f,w,L),children:oe(f,h.has(f.uid))},f.uid))})]}),s&&B&&a.jsx("div",{style:{flex:1,overflowY:"auto"},children:re(B)})]})}exports.AnimatedCardFlip=Pt;exports.ApiClient=Ze;exports.AuthManager=He;exports.Card=Ot;exports.DataOperations=_e;exports.Detail=Ct;exports.GraphClient=jt;exports.Mail=$t;exports.MailClient=Xe;exports.Stack=Tt;exports.getApiClient=Me;exports.initializeApiClient=Et;exports.useMutation=St;exports.useQuery=et;
|