@fileflow/sdk 0.1.23 → 0.1.24
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/{ImportWizard-x7cTPmMH.js → ImportWizard-Bueox6It.js} +2 -2
- package/dist/{ImportWizard-x7cTPmMH.js.map → ImportWizard-Bueox6It.js.map} +1 -1
- package/dist/{ImportWizard-_wJ7Qxpr.mjs → ImportWizard-CnoaPUwN.mjs} +4 -4
- package/dist/{ImportWizard-_wJ7Qxpr.mjs.map → ImportWizard-CnoaPUwN.mjs.map} +1 -1
- package/dist/import.js +1 -1
- package/dist/import.mjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
* LICENSE.md file in the root directory of this source tree.
|
|
75
75
|
*
|
|
76
76
|
* @license MIT
|
|
77
|
-
*/function Ge(e,o){return e?jn(e)?ye.createElement(e,o):e:null}function jn(e){return In(e)||typeof e=="function"||$n(e)}function In(e){return typeof e=="function"&&(()=>{const o=Object.getPrototypeOf(e);return o.prototype&&o.prototype.isReactComponent})()}function $n(e){return typeof e=="object"&&typeof e.$$typeof=="symbol"&&["react.memo","react.forward_ref"].includes(e.$$typeof.description)}function Nn(e){const o={state:{},onStateChange:()=>{},renderFallbackValue:null,...e},[t]=ye.useState(()=>({current:vn(o)})),[n,r]=ye.useState(()=>t.current.initialState);return t.current.setOptions(s=>({...s,...e,state:{...n,...e.state},onStateChange:i=>{r(i),e.onStateChange==null||e.onStateChange(i)}})),t.current}const Ie=({editable:e=!0,deletable:o=!0,pageSize:t=25,onCellEdit:n,onRowDelete:r})=>{const{rows:s,schema:i,mappings:a,errorsByRow:f,editingCell:d,startEditing:p,stopEditing:g,updateCell:c,deleteRow:u}=ee(),[m,h]=b.useState([]),[x,v]=b.useState(""),[C,R]=b.useState(""),$=b.useMemo(()=>a.filter(F=>F.targetKey!==null).map(F=>{const j=i==null?void 0:i.columns.find(N=>N.key===F.targetKey);return{sourceColumn:F.sourceColumn,targetKey:F.targetKey,label:(j==null?void 0:j.label)||F.targetKey,type:(j==null?void 0:j.type)||"string"}}),[a,i]),_=b.useCallback((F,j)=>{const N=f.get(F);return N==null?void 0:N.find(T=>T.columnKey===j)},[f]),V=(F,j,N)=>{R(N),p(F,j)},Q=()=>{d&&(c(d.rowIndex,d.columnKey,C),n==null||n(d.rowIndex,d.columnKey,C)),g()},E=()=>{R(""),g()},B=F=>{u(F),r==null||r(F)},X=Vt(),L=b.useMemo(()=>[X.accessor("rowIndex",{header:"#",size:o?80:60,cell:F=>{const j=F.getValue();return l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[l.jsx("span",{className:"ff-font-mono ff-text-xs",style:{color:"var(--ff-text-muted)"},children:j+1}),o&&l.jsx("button",{onClick:N=>{N.stopPropagation(),B(j)},title:"Delete row",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:"4px",borderRadius:"4px",cursor:"pointer",color:"#8e8d89",background:"transparent",border:"none",transition:"color 0.15s, background-color 0.15s",marginLeft:"2px",flexShrink:0},onMouseEnter:N=>{N.currentTarget.style.color="#d43338",N.currentTarget.style.backgroundColor="#fcdede"},onMouseLeave:N=>{N.currentTarget.style.color="#8e8d89",N.currentTarget.style.backgroundColor="transparent"},children:l.jsx(Nt,{style:{width:"14px",height:"14px",display:"block"}})})]})}}),...$.map(F=>X.accessor(j=>j.data[F.targetKey]||j.data[F.sourceColumn],{id:F.targetKey,header:F.label,cell:j=>{const N=j.row.original.rowIndex,T=String(j.getValue()??""),z=_(N,F.targetKey);return(d==null?void 0:d.rowIndex)===N&&(d==null?void 0:d.columnKey)===F.targetKey?l.jsxs("div",{className:"ff-flex ff-items-center ff-gap-2 ff-min-w-[280px]",children:[l.jsx("input",{type:"text",value:C,onChange:J=>R(J.target.value),onKeyDown:J=>{J.key==="Enter"&&Q(),J.key==="Escape"&&E()},className:"ff-input ff-py-2 ff-px-3 ff-text-sm ff-flex-1 ff-min-w-[160px]",autoFocus:!0}),l.jsx("button",{onClick:Q,className:"ff-btn ff-btn-primary ff-btn-sm ff-flex-shrink-0",children:"Save"}),l.jsx("button",{onClick:E,className:"ff-btn ff-btn-secondary ff-btn-sm ff-flex-shrink-0",children:"Cancel"})]}):l.jsxs("div",{className:w.clsx("ff-group ff-flex ff-items-center ff-gap-2",(z==null?void 0:z.severity)==="error"&&"ff-cell-error",(z==null?void 0:z.severity)==="warning"&&"ff-cell-warning"),children:[l.jsx("span",{className:"ff-flex-1 ff-truncate",children:T||l.jsx("span",{style:{color:"var(--ff-text-muted)"},children:"—"})}),z&&l.jsxs("div",{className:"ff-relative ff-group/tooltip",children:[z.severity==="error"?l.jsx(w.CircleAlert,{className:"ff-w-4 ff-h-4",style:{color:"var(--ff-error)"}}):l.jsx(w.TriangleAlert,{className:"ff-w-4 ff-h-4",style:{color:"var(--ff-warning)"}}),l.jsxs("div",{className:"ff-tooltip ff-bottom-full ff-left-1/2 ff-transform ff--translate-x-1/2 ff-mb-2 ff-w-48 group-hover/tooltip:ff-tooltip-visible",children:[z.message,z.suggestion&&l.jsx("span",{className:"ff-block ff-mt-1",style:{color:"var(--ff-text-muted)"},children:z.suggestion})]})]}),e&&l.jsx("button",{onClick:()=>V(N,F.targetKey,T),className:"ff-opacity-0 group-hover:ff-opacity-100 ff-p-1 ff-rounded ff-transition-opacity ff-edit-btn",children:l.jsx(Ft,{className:"ff-w-3 ff-h-3"})})]})}}))],[$,d,C,e,o,_,X]),O=Nn({data:s,columns:L,state:{sorting:m,globalFilter:x},onSortingChange:h,onGlobalFilterChange:v,getCoreRowModel:xn(),getPaginationRowModel:_n(),getSortedRowModel:Fn(),getFilteredRowModel:Rn(),initialState:{pagination:{pageSize:t}}});return l.jsxs("div",{className:"ff-space-y-4",children:[l.jsxs("div",{className:"ff-flex ff-items-center ff-justify-between",children:[l.jsx("input",{type:"text",value:x,onChange:F=>v(F.target.value),placeholder:"Search all columns...",className:"ff-input ff-max-w-xs"}),l.jsxs("div",{className:"ff-text-sm",style:{color:"var(--ff-text-muted)"},children:[O.getFilteredRowModel().rows.length," rows"]})]}),l.jsx("div",{className:"ff-table-container ff-max-h-[500px]",children:l.jsxs("table",{className:"ff-table",children:[l.jsx("thead",{children:O.getHeaderGroups().map(F=>l.jsx("tr",{children:F.headers.map(j=>l.jsx("th",{style:{width:j.getSize()},onClick:j.column.getToggleSortingHandler(),className:w.clsx(j.column.getCanSort()&&"ff-cursor-pointer ff-select-none"),children:l.jsxs("div",{className:"ff-flex ff-items-center ff-gap-1",children:[Ge(j.column.columnDef.header,j.getContext()),j.column.getIsSorted()&&l.jsx("span",{children:j.column.getIsSorted()==="asc"?"↑":"↓"})]})},j.id))},F.id))}),l.jsx("tbody",{children:O.getRowModel().rows.map(F=>{const j=f.has(F.original.rowIndex);return l.jsx("tr",{className:w.clsx(j&&"ff-row-error"),children:F.getVisibleCells().map(N=>l.jsx("td",{children:Ge(N.column.columnDef.cell,N.getContext())},N.id))},F.id)})})]})}),l.jsxs("div",{className:"ff-flex ff-items-center ff-justify-between ff-px-2",children:[l.jsxs("div",{className:"ff-text-sm",style:{color:"var(--ff-text-muted)"},children:["Page ",O.getState().pagination.pageIndex+1," of ",O.getPageCount()]}),l.jsxs("div",{className:"ff-flex ff-items-center ff-gap-2",children:[l.jsxs("button",{onClick:()=>O.previousPage(),disabled:!O.getCanPreviousPage(),className:"ff-btn ff-btn-secondary ff-btn-sm",children:[l.jsx(gt,{className:"ff-w-4 ff-h-4"}),"Previous"]}),l.jsxs("button",{onClick:()=>O.nextPage(),disabled:!O.getCanNextPage(),className:"ff-btn ff-btn-secondary ff-btn-sm",children:["Next",l.jsx(w.ChevronRight,{className:"ff-w-4 ff-h-4"})]})]})]})]})},$e=({showDetails:e=!0})=>{const{validationResults:o}=ee();if(!o)return null;const{isValid:t,totalRows:n,validRows:r,errorCount:s,warningCount:i,infoCount:a,summary:f}=o,d=Math.round(r/n*100);return l.jsxs("div",{className:"ff-space-y-4",children:[l.jsxs("div",{className:"ff-flex ff-items-center ff-gap-4 ff-p-4 ff-rounded-lg ff-border",style:{backgroundColor:t?"var(--ff-success-light)":"var(--ff-error-light)",borderColor:t?"var(--ff-success)":"var(--ff-error)"},children:[t?l.jsx(w.CircleCheckBig,{className:"ff-w-8 ff-h-8",style:{color:"var(--ff-success)"}}):l.jsx(w.CircleX,{className:"ff-w-8 ff-h-8",style:{color:"var(--ff-error)"}}),l.jsxs("div",{children:[l.jsx("h3",{className:"ff-text-lg ff-font-semibold",style:{color:t?"var(--ff-success-dark)":"var(--ff-error-dark)"},children:t?"Validation Passed":"Validation Failed"}),l.jsxs("p",{className:"ff-text-sm",style:{color:t?"var(--ff-success)":"var(--ff-error)"},children:[r," of ",n," rows are valid (",d,"%)"]})]})]}),l.jsxs("div",{className:"ff-grid ff-grid-cols-4 ff-gap-4",children:[l.jsxs("div",{className:"ff-border ff-rounded-lg ff-p-4 ff-text-center",style:{backgroundColor:"var(--ff-bg-primary)",borderColor:"var(--ff-border-light)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-text-primary)"},children:n}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-text-muted)"},children:"Total Rows"})]}),l.jsxs("div",{className:"ff-border ff-rounded-lg ff-p-4 ff-text-center",style:{backgroundColor:"var(--ff-success-light)",borderColor:"var(--ff-success)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-success-dark)"},children:r}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-success)"},children:"Valid Rows"})]}),l.jsxs("div",{className:"ff-border ff-rounded-lg ff-p-4 ff-text-center",style:{backgroundColor:"var(--ff-error-light)",borderColor:"var(--ff-error)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-error-dark)"},children:s}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-error)"},children:"Errors"})]}),l.jsxs("div",{className:"ff-border ff-rounded-lg ff-p-4 ff-text-center",style:{backgroundColor:"var(--ff-warning-light)",borderColor:"var(--ff-warning)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-warning-dark)"},children:i}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-warning)"},children:"Warnings"})]})]}),e&&f.byColumn&&Object.keys(f.byColumn).length>0&&l.jsxs("div",{className:"ff-border ff-rounded-xl ff-overflow-hidden",style:{backgroundColor:"var(--ff-bg-primary)",borderColor:"var(--ff-border-light)"},children:[l.jsx("div",{className:"ff-px-4 ff-py-3",style:{backgroundColor:"var(--ff-bg-secondary)"},children:l.jsx("h4",{className:"ff-font-medium ff-text-sm",style:{color:"var(--ff-text-secondary)"},children:"Issues by Column"})}),l.jsx("div",{children:Object.entries(f.byColumn).filter(([,p])=>p.errorCount>0||p.warningCount>0).map(([p,g],c,u)=>l.jsxs("div",{className:"ff-flex ff-items-center ff-justify-between ff-px-4 ff-py-3",style:{borderTop:c>0?"1px solid var(--ff-border-light)":void 0},children:[l.jsxs("div",{className:"ff-flex-1 ff-min-w-0 ff-mr-4",children:[l.jsx("p",{className:"ff-font-medium ff-text-sm",style:{color:"var(--ff-text-primary)"},children:g.columnKey}),g.mostCommonError&&l.jsx("p",{className:"ff-text-sm ff-truncate",style:{color:"var(--ff-text-muted)"},children:g.mostCommonError})]}),l.jsxs("div",{className:"ff-flex ff-items-center ff-gap-2 ff-flex-shrink-0",children:[g.errorCount>0&&l.jsxs("span",{className:"ff-badge ff-badge-error ff-whitespace-nowrap",children:[l.jsx(w.CircleX,{className:"ff-w-3 ff-h-3 ff-mr-1"}),g.errorCount," ",g.errorCount===1?"error":"errors"]}),g.warningCount>0&&l.jsxs("span",{className:"ff-badge ff-badge-warning ff-whitespace-nowrap",children:[l.jsx(w.TriangleAlert,{className:"ff-w-3 ff-h-3 ff-mr-1"}),g.warningCount," ",g.warningCount===1?"warning":"warnings"]})]})]},p))})]}),e&&f.duplicates&&f.duplicates.length>0&&l.jsx("div",{className:"ff-border ff-rounded-lg ff-p-4",style:{backgroundColor:"var(--ff-warning-light)",borderColor:"var(--ff-warning)"},children:l.jsxs("div",{className:"ff-flex ff-items-start ff-gap-3",children:[l.jsx(w.TriangleAlert,{className:"ff-w-5 ff-h-5 ff-flex-shrink-0 ff-mt-0.5",style:{color:"var(--ff-warning)"}}),l.jsxs("div",{children:[l.jsx("h4",{className:"ff-font-medium",style:{color:"var(--ff-warning-dark)"},children:"Duplicate Values Found"}),l.jsxs("ul",{className:"ff-mt-2 ff-space-y-1 ff-text-sm",style:{color:"var(--ff-warning-dark)"},children:[f.duplicates.slice(0,5).map((p,g)=>l.jsxs("li",{children:[l.jsx("span",{className:"ff-font-mono",children:p.columnKey}),': "',String(p.value),'" appears'," ",p.rowIndices.length," times (rows"," ",p.rowIndices.slice(0,3).map(c=>c+1).join(", "),p.rowIndices.length>3?"...":"",")"]},g)),f.duplicates.length>5&&l.jsxs("li",{style:{color:"var(--ff-warning)"},children:["... and ",f.duplicates.length-5," more duplicate groups"]})]})]})]})})]})},Ce=["upload","mapping","validation","complete"],Mn=[{key:"upload",label:"Upload",icon:w.Upload},{key:"mapping",label:"Map Columns",icon:Rt},{key:"validation",label:"Validate",icon:It},{key:"review",label:"Review",icon:vt},{key:"complete",label:"Complete",icon:w.CircleCheckBig}],Vn=({template:e,schema:o,mode:t="modal",theme:n,useShadowDom:r=!1,onComplete:s,onCancel:i,onError:a})=>{const{step:f,sessionId:d,file:p,mappings:g,validationResults:c,isLoading:u,error:m,setSchema:h,setSessionId:x,setParsedData:v,setMappings:C,setUnmapped:R,setValidationResults:$,setStep:_,nextStep:V,previousStep:Q,setLoading:E,setError:B,reset:X}=ee(),[L,O]=b.useState(null),[F,j]=b.useState(null),[N,T]=b.useState(0),[z,Z]=b.useState("");b.useEffect(()=>{if(j(null),e)if(w.templateExists(e)){const I=w.getTemplateSchema(e);I?O(I):(j(`Failed to load template "${e}"`),a==null||a(new Error(`Failed to load template "${e}"`)))}else{const I=`Template "${e}" not found. Available templates: ${w.VALID_TEMPLATE_IDS.join(", ")}`;j(I),a==null||a(new Error(I))}else if(o)O(o);else{const I=`No template or schema provided. Please specify a template (${w.VALID_TEMPLATE_IDS.join(", ")}) or provide a custom schema.`;j(I),a==null||a(new Error(I))}},[e,o,a]),b.useEffect(()=>{L&&(h(L),J(L))},[L]);const J=async I=>{try{E(!0);const P=await w.getClient().createImportSession(I);x(P.sessionId)}catch(M){const P=M;B(P.message),a==null||a(P)}finally{E(!1)}},Je=b.useCallback(async I=>{if(d)try{E(!0),B(null),T(10),Z("Uploading file...");const M=w.getClient();T(30),Z("Parsing file data...");const P=await M.uploadFile(d,I);T(60),Z("Processing rows...");const K=(D,H)=>({rowIndex:D.rowIndex??H,data:D.data??D,rawData:D.rawData??Object.values(D.data??D)});v({headers:P.data.headers,rows:P.data.sampleRows.map(K),totalRows:P.data.totalRows,sampleRows:P.data.sampleRows.map(K)}),T(80),Z("Matching columns..."),V(),await et(),T(100),Z("Done")}catch(M){B(`Failed to process the uploaded file: ${M.message}`)}finally{E(!1),T(0),Z("")}},[d]),et=async()=>{if(d)try{E(!0);const M=await w.getClient().matchColumns(d);C(M.mappings),R(M.unmappedSource,M.unmappedTarget)}catch(I){B(`Column matching failed: ${I.message}`)}finally{E(!1)}},tt=async()=>{if(d)try{E(!0),B(null);const M=await w.getClient().validateImport(d);$(M.validation),V()}catch(I){B(`Validation failed: ${I.message}`)}finally{E(!1)}},[ke,le]=b.useState(null),[k,be]=b.useState(null),nt=async()=>{if(d)try{E(!0),B(null),le(null);const P=await w.getClient().completeImport(d,{skipInvalidRows:!0,acknowledgeWarnings:!0}),K={...P,data:(P.data||[]).map(D=>D.data&&typeof D.data=="object"&&!Array.isArray(D.data)?{rowIndex:D.rowIndex??0,data:D.data,wasEdited:D.wasEdited??!1}:D)};be(K),_("complete"),s==null||s(K)}catch(I){le(I.message),_("complete")}finally{E(!1)}},ie=()=>{X(),i==null||i()},Ee=()=>{le(null),be(null),T(0),Z(""),X(),L&&(h(L),J(L))},ot=()=>Mn.findIndex(I=>I.key===f),rt=()=>{switch(f){case"upload":return p!==null;case"mapping":return g.length>0&&g.some(I=>I.targetKey!==null);case"validation":return c!==null;case"review":return c!==null&&(c.isValid||c.errorCount===0);default:return!1}},st=async()=>{switch(f){case"mapping":await tt();break;case"validation":V();break;case"review":await nt();break;default:V()}};if(F)return l.jsx(w.StyleProvider,{theme:n,useShadowDom:r,children:l.jsx("div",{className:"ff-container ff-bg-white ff-rounded-xl ff-shadow-xl ff-overflow-hidden ff-p-6",children:l.jsxs("div",{className:"ff-flex ff-flex-col ff-items-center ff-justify-center ff-py-8",children:[l.jsx("div",{className:"ff-w-16 ff-h-16 ff-rounded-full ff-flex ff-items-center ff-justify-center ff-mb-4",style:{backgroundColor:"var(--ff-error-light)"},children:l.jsx(w.X,{className:"ff-w-10 ff-h-10",style:{color:"var(--ff-error)"}})}),l.jsx("h3",{className:"ff-text-xl ff-font-semibold ff-mb-2",style:{color:"var(--ff-text-primary)"},children:"Configuration Error"}),l.jsx("p",{className:"ff-text-center ff-max-w-md ff-mb-4",style:{color:"var(--ff-text-muted)"},children:F}),i&&l.jsx("button",{onClick:ie,className:"ff-btn ff-btn-secondary",children:"Close"})]})})});if(!L)return l.jsx(w.StyleProvider,{theme:n,useShadowDom:r,children:l.jsx("div",{className:"ff-container ff-bg-white ff-rounded-xl ff-shadow-xl ff-overflow-hidden ff-p-6",children:l.jsxs("div",{className:"ff-flex ff-flex-col ff-items-center ff-justify-center ff-py-8",children:[l.jsx(w.LoaderCircle,{className:"ff-w-10 ff-h-10 ff-animate-spin ff-mb-4",style:{color:"var(--ff-primary-90)"}}),l.jsx("p",{style:{color:"var(--ff-text-muted)"},children:"Loading template..."})]})})});const ne=()=>{const I=f==="review"?"validation":f;return Ce.indexOf(I)},lt=t==="embed"?"ff-container ff-embed":"ff-container ff-modal",Le=l.jsx(l.Fragment,{children:l.jsxs("div",{className:lt,children:[l.jsxs("div",{className:"ff-modal-header",children:[l.jsxs("div",{className:"ff-modal-header-left",children:[l.jsxs("div",{className:"ff-flex ff-items-center ff-gap-3",children:[l.jsx("div",{className:"ff-modal-icon",children:l.jsx(wt,{})}),l.jsx("h2",{className:"ff-modal-title",children:"Import Data"})]}),l.jsx("div",{className:"ff-steps ff-ml-4",children:Ce.map((I,M)=>l.jsxs(b.Fragment,{children:[l.jsx("div",{className:w.clsx("ff-step",ne()===M&&"ff-step-active",ne()>M&&"ff-step-complete",ne()<M&&"ff-step-pending"),children:ne()>M?"✓":M+1}),M<Ce.length-1&&l.jsx("div",{className:w.clsx("ff-step-connector",ne()>M&&"ff-step-connector-complete")})]},I))})]}),l.jsx("button",{onClick:ie,className:"ff-modal-close",children:l.jsx(w.X,{className:"ff-w-5 ff-h-5"})})]}),l.jsxs("div",{className:"ff-modal-body",children:[m&&l.jsx("div",{className:"ff-mb-4 ff-p-4 ff-border ff-rounded-lg ff-text-sm",style:{backgroundColor:"var(--ff-error-light)",borderColor:"var(--ff-error)",color:"var(--ff-error)"},children:m}),f==="upload"&&l.jsx("div",{className:"ff-py-4",children:l.jsx("div",{className:"ff-max-w-xl ff-mx-auto",children:u&&N>0?l.jsxs("div",{className:"ff-p-8 ff-text-center",children:[l.jsx(w.LoaderCircle,{className:"ff-w-10 ff-h-10 ff-animate-spin ff-mx-auto ff-mb-4",style:{color:"var(--ff-primary-90)"}}),l.jsx("p",{className:"ff-font-medium ff-mb-2",style:{color:"var(--ff-text-primary)"},children:z}),l.jsx("div",{className:"ff-progress ff-w-full ff-max-w-xs ff-mx-auto ff-mb-2",children:l.jsx("div",{className:"ff-progress-bar",style:{width:`${N}%`,transition:"width 0.3s ease"}})}),l.jsxs("p",{className:"ff-text-sm",style:{color:"var(--ff-text-muted)"},children:[N,"% complete"]})]}):l.jsx(Oe,{onFileSelect:Je})})}),f==="mapping"&&(u&&N>0?l.jsxs("div",{className:"ff-py-12 ff-text-center",children:[l.jsx(w.LoaderCircle,{className:"ff-w-10 ff-h-10 ff-animate-spin ff-mx-auto ff-mb-4",style:{color:"var(--ff-primary-90)"}}),l.jsx("p",{className:"ff-font-medium ff-mb-3",style:{color:"var(--ff-text-primary)"},children:z}),l.jsx("div",{className:"ff-progress ff-w-full ff-max-w-xs ff-mx-auto ff-mb-2",children:l.jsx("div",{className:"ff-progress-bar",style:{width:`${N}%`,transition:"width 0.3s ease"}})}),l.jsxs("p",{className:"ff-text-sm",style:{color:"var(--ff-text-muted)"},children:[N,"% complete"]})]}):l.jsx(Te,{})),f==="validation"&&l.jsxs("div",{className:"ff-space-y-6",children:[l.jsx($e,{}),l.jsx(Ie,{editable:!0})]}),f==="review"&&l.jsxs("div",{className:"ff-space-y-6",children:[l.jsx($e,{showDetails:!1}),l.jsx(Ie,{editable:!1,pageSize:10})]}),f==="complete"&&l.jsx("div",{className:"ff-flex ff-flex-col ff-items-center ff-justify-center ff-py-8",children:ke?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"ff-w-16 ff-h-16 ff-rounded-full ff-flex ff-items-center ff-justify-center ff-mb-4",style:{backgroundColor:"var(--ff-error-light)"},children:l.jsx(w.X,{className:"ff-w-10 ff-h-10",style:{color:"var(--ff-error)"}})}),l.jsx("h3",{className:"ff-text-xl ff-font-semibold ff-mb-2",style:{color:"var(--ff-text-primary)"},children:"Import Failed"}),l.jsx("p",{className:"ff-text-center ff-max-w-md ff-mb-4",style:{color:"var(--ff-text-muted)"},children:ke}),l.jsxs("div",{className:"ff-flex ff-gap-3",children:[l.jsx("button",{onClick:()=>{le(null),_("review")},className:"ff-btn ff-btn-secondary",children:"Back to Review"}),i&&l.jsx("button",{onClick:ie,className:"ff-btn ff-btn-secondary",children:"Close"})]})]}):l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"ff-w-20 ff-h-20 ff-rounded-2xl ff-flex ff-items-center ff-justify-center ff-mb-6",style:{backgroundColor:"var(--ff-success-light)"},children:l.jsx(w.CircleCheckBig,{className:"ff-w-10 ff-h-10",style:{color:"var(--ff-success)"}})}),l.jsx("h3",{className:"ff-text-xl ff-font-semibold ff-mb-2",style:{color:"var(--ff-text-primary)"},children:"Import Complete!"}),l.jsx("p",{className:"ff-mb-6",style:{color:"var(--ff-text-muted)"},children:"Your data has been successfully imported."}),l.jsxs("div",{className:"ff-flex ff-gap-6 ff-mb-6",children:[l.jsxs("div",{className:"ff-text-center ff-px-6 ff-py-3 ff-rounded-xl ff-border",style:{borderColor:"var(--ff-border-light)",backgroundColor:"var(--ff-bg-primary)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-text-primary)"},children:(k==null?void 0:k.totalRows)??(c==null?void 0:c.totalRows)??0}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-text-muted)"},children:"Total Rows"})]}),l.jsxs("div",{className:"ff-text-center ff-px-6 ff-py-3 ff-rounded-xl ff-border",style:{borderColor:"var(--ff-success)",backgroundColor:"var(--ff-success-light)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-success-dark)"},children:(k==null?void 0:k.importedRows)??(c==null?void 0:c.validRows)??0}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-success)"},children:"Imported"})]}),((k==null?void 0:k.skippedRows)??0)>0&&l.jsxs("div",{className:"ff-text-center ff-px-6 ff-py-3 ff-rounded-xl ff-border",style:{borderColor:"var(--ff-warning)",backgroundColor:"var(--ff-warning-light)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-warning-dark)"},children:(k==null?void 0:k.skippedRows)??0}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-warning)"},children:"Skipped"})]}),l.jsxs("div",{className:"ff-text-center ff-px-6 ff-py-3 ff-rounded-xl ff-border",style:{borderColor:"var(--ff-border-light)",backgroundColor:"var(--ff-bg-primary)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-text-primary)"},children:g.filter(I=>I.targetKey!==null).length}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-text-muted)"},children:"Columns Mapped"})]})]}),(k==null?void 0:k.data)&&k.data.length>0&&(()=>{const I=k.data.slice(0,5),M=I[0],P=(M==null?void 0:M.data)||M,K=Object.keys(typeof P=="object"?P:{}).slice(0,6),D=(L==null?void 0:L.columns)||[];return K.length===0?null:l.jsxs("div",{className:"ff-w-full ff-mb-6",children:[l.jsxs("p",{className:"ff-text-xs ff-font-semibold ff-uppercase ff-tracking-wider ff-mb-2",style:{color:"var(--ff-text-muted)"},children:["Data Preview (first ",I.length," rows)"]}),l.jsx("div",{className:"ff-table-container ff-max-h-[250px]",children:l.jsxs("table",{className:"ff-table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{style:{width:40},children:"#"}),K.map(H=>{const te=D.find(oe=>oe.key===H);return l.jsx("th",{children:(te==null?void 0:te.label)||H},H)}),K.length<Object.keys(typeof P=="object"?P:{}).length&&l.jsx("th",{children:"..."})]})}),l.jsx("tbody",{children:I.map((H,te)=>{const oe=(H==null?void 0:H.data)||H;return l.jsxs("tr",{children:[l.jsx("td",{children:l.jsx("span",{className:"ff-font-mono ff-text-xs",style:{color:"var(--ff-text-muted)"},children:((H==null?void 0:H.rowIndex)??te)+1})}),K.map(De=>l.jsx("td",{children:l.jsx("span",{className:"ff-text-sm ff-truncate ff-block ff-max-w-[150px]",children:String((oe==null?void 0:oe[De])??"—")})},De)),K.length<Object.keys(typeof P=="object"?P:{}).length&&l.jsx("td",{children:l.jsx("span",{style:{color:"var(--ff-text-muted)"},children:"..."})})]},te)})})]})}),k.data.length>5&&l.jsxs("p",{className:"ff-text-xs ff-mt-1",style:{color:"var(--ff-text-muted)"},children:["Showing 5 of ",k.data.length," imported rows"]})]})})(),l.jsxs("div",{className:"ff-flex ff-gap-3",children:[l.jsx("button",{onClick:Ee,className:"ff-btn ff-btn-primary",children:"Start New Import"}),i&&l.jsx("button",{onClick:ie,className:"ff-btn ff-btn-secondary",children:"Close"})]})]})})]}),l.jsx("div",{className:"ff-modal-footer",children:f==="complete"?l.jsxs(l.Fragment,{children:[l.jsx("div",{}),l.jsx("button",{onClick:Ee,className:"ff-btn ff-btn-primary",children:"Start New Import"})]}):l.jsxs(l.Fragment,{children:[l.jsx("button",{onClick:Q,disabled:ot()===0||u,className:"ff-btn ff-btn-ghost",children:"Back"}),l.jsx("button",{onClick:st,disabled:!rt()||u,className:"ff-btn ff-btn-primary",children:u?l.jsxs(l.Fragment,{children:[l.jsx(w.LoaderCircle,{className:"ff-w-4 ff-h-4 ff-animate-spin"}),"Processing..."]}):f==="review"?"Complete Import":"Continue"})]})})]})});return l.jsx(w.StyleProvider,{theme:n,useShadowDom:r,children:t==="modal"?l.jsx("div",{className:"ff-overlay",children:Le}):Le})};exports.ColumnMapper=Te;exports.DataTable=Ie;exports.FileUploader=Oe;exports.ImportWizard=Vn;exports.ValidationSummary=$e;exports.useImportStore=ee;
|
|
78
|
-
//# sourceMappingURL=ImportWizard-
|
|
77
|
+
*/function Ge(e,o){return e?jn(e)?ye.createElement(e,o):e:null}function jn(e){return In(e)||typeof e=="function"||$n(e)}function In(e){return typeof e=="function"&&(()=>{const o=Object.getPrototypeOf(e);return o.prototype&&o.prototype.isReactComponent})()}function $n(e){return typeof e=="object"&&typeof e.$$typeof=="symbol"&&["react.memo","react.forward_ref"].includes(e.$$typeof.description)}function Nn(e){const o={state:{},onStateChange:()=>{},renderFallbackValue:null,...e},[t]=ye.useState(()=>({current:vn(o)})),[n,r]=ye.useState(()=>t.current.initialState);return t.current.setOptions(s=>({...s,...e,state:{...n,...e.state},onStateChange:i=>{r(i),e.onStateChange==null||e.onStateChange(i)}})),t.current}const Ie=({editable:e=!0,deletable:o=!0,pageSize:t=25,onCellEdit:n,onRowDelete:r})=>{const{rows:s,schema:i,mappings:a,errorsByRow:f,editingCell:d,startEditing:p,stopEditing:g,updateCell:c,deleteRow:u}=ee(),[m,h]=b.useState([]),[x,v]=b.useState(""),[C,R]=b.useState(""),$=b.useMemo(()=>a.filter(F=>F.targetKey!==null).map(F=>{const j=i==null?void 0:i.columns.find(N=>N.key===F.targetKey);return{sourceColumn:F.sourceColumn,targetKey:F.targetKey,label:(j==null?void 0:j.label)||F.targetKey,type:(j==null?void 0:j.type)||"string"}}),[a,i]),_=b.useCallback((F,j)=>{const N=f.get(F);return N==null?void 0:N.find(T=>T.columnKey===j)},[f]),V=(F,j,N)=>{R(N),p(F,j)},Q=()=>{d&&(c(d.rowIndex,d.columnKey,C),n==null||n(d.rowIndex,d.columnKey,C)),g()},E=()=>{R(""),g()},B=F=>{u(F),r==null||r(F)},X=Vt(),L=b.useMemo(()=>[X.accessor("rowIndex",{header:"#",size:o?80:60,cell:F=>{const j=F.getValue();return l.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[l.jsx("span",{className:"ff-font-mono ff-text-xs",style:{color:"var(--ff-text-muted)"},children:j+1}),o&&l.jsx("button",{onClick:N=>{N.stopPropagation(),B(j)},title:"Delete row",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:"4px",borderRadius:"4px",cursor:"pointer",color:"#8e8d89",background:"transparent",border:"none",transition:"color 0.15s, background-color 0.15s",marginLeft:"2px",flexShrink:0},onMouseEnter:N=>{N.currentTarget.style.color="#d43338",N.currentTarget.style.backgroundColor="#fcdede"},onMouseLeave:N=>{N.currentTarget.style.color="#8e8d89",N.currentTarget.style.backgroundColor="transparent"},children:l.jsx(Nt,{style:{width:"14px",height:"14px",display:"block"}})})]})}}),...$.map(F=>X.accessor(j=>j.data[F.targetKey]||j.data[F.sourceColumn],{id:F.targetKey,header:F.label,cell:j=>{const N=j.row.original.rowIndex,T=String(j.getValue()??""),z=_(N,F.targetKey);return(d==null?void 0:d.rowIndex)===N&&(d==null?void 0:d.columnKey)===F.targetKey?l.jsxs("div",{className:"ff-flex ff-items-center ff-gap-2 ff-min-w-[280px]",children:[l.jsx("input",{type:"text",value:C,onChange:J=>R(J.target.value),onKeyDown:J=>{J.key==="Enter"&&Q(),J.key==="Escape"&&E()},className:"ff-input ff-py-2 ff-px-3 ff-text-sm ff-flex-1 ff-min-w-[160px]",autoFocus:!0}),l.jsx("button",{onClick:Q,className:"ff-btn ff-btn-primary ff-btn-sm ff-flex-shrink-0",children:"Save"}),l.jsx("button",{onClick:E,className:"ff-btn ff-btn-secondary ff-btn-sm ff-flex-shrink-0",children:"Cancel"})]}):l.jsxs("div",{className:w.clsx("ff-group ff-flex ff-items-center ff-gap-2",(z==null?void 0:z.severity)==="error"&&"ff-cell-error",(z==null?void 0:z.severity)==="warning"&&"ff-cell-warning"),children:[l.jsx("span",{className:"ff-flex-1 ff-truncate",children:T||l.jsx("span",{style:{color:"var(--ff-text-muted)"},children:"—"})}),z&&l.jsxs("div",{className:"ff-relative ff-group/tooltip",children:[z.severity==="error"?l.jsx(w.CircleAlert,{className:"ff-w-4 ff-h-4",style:{color:"var(--ff-error)"}}):l.jsx(w.TriangleAlert,{className:"ff-w-4 ff-h-4",style:{color:"var(--ff-warning)"}}),l.jsxs("div",{className:"ff-tooltip ff-bottom-full ff-left-1/2 ff-transform ff--translate-x-1/2 ff-mb-2 ff-w-48 group-hover/tooltip:ff-tooltip-visible",children:[z.message,z.suggestion&&l.jsx("span",{className:"ff-block ff-mt-1",style:{color:"var(--ff-text-muted)"},children:z.suggestion})]})]}),e&&l.jsx("button",{onClick:()=>V(N,F.targetKey,T),className:"ff-opacity-0 group-hover:ff-opacity-100 ff-p-1 ff-rounded ff-transition-opacity ff-edit-btn",children:l.jsx(Ft,{className:"ff-w-3 ff-h-3"})})]})}}))],[$,d,C,e,o,_,X]),O=Nn({data:s,columns:L,state:{sorting:m,globalFilter:x},onSortingChange:h,onGlobalFilterChange:v,getCoreRowModel:xn(),getPaginationRowModel:_n(),getSortedRowModel:Fn(),getFilteredRowModel:Rn(),initialState:{pagination:{pageSize:t}}});return l.jsxs("div",{className:"ff-space-y-4",children:[l.jsxs("div",{className:"ff-flex ff-items-center ff-justify-between",children:[l.jsx("input",{type:"text",value:x,onChange:F=>v(F.target.value),placeholder:"Search all columns...",className:"ff-input ff-max-w-xs"}),l.jsxs("div",{className:"ff-text-sm",style:{color:"var(--ff-text-muted)"},children:[O.getFilteredRowModel().rows.length," rows"]})]}),l.jsx("div",{className:"ff-table-container ff-max-h-[500px]",children:l.jsxs("table",{className:"ff-table",children:[l.jsx("thead",{children:O.getHeaderGroups().map(F=>l.jsx("tr",{children:F.headers.map(j=>l.jsx("th",{style:{width:j.getSize()},onClick:j.column.getToggleSortingHandler(),className:w.clsx(j.column.getCanSort()&&"ff-cursor-pointer ff-select-none"),children:l.jsxs("div",{className:"ff-flex ff-items-center ff-gap-1",children:[Ge(j.column.columnDef.header,j.getContext()),j.column.getIsSorted()&&l.jsx("span",{children:j.column.getIsSorted()==="asc"?"↑":"↓"})]})},j.id))},F.id))}),l.jsx("tbody",{children:O.getRowModel().rows.map(F=>{const j=f.has(F.original.rowIndex);return l.jsx("tr",{className:w.clsx(j&&"ff-row-error"),children:F.getVisibleCells().map(N=>l.jsx("td",{children:Ge(N.column.columnDef.cell,N.getContext())},N.id))},F.id)})})]})}),l.jsxs("div",{className:"ff-flex ff-items-center ff-justify-between ff-px-2",children:[l.jsxs("div",{className:"ff-text-sm",style:{color:"var(--ff-text-muted)"},children:["Page ",O.getState().pagination.pageIndex+1," of ",O.getPageCount()]}),l.jsxs("div",{className:"ff-flex ff-items-center ff-gap-2",children:[l.jsxs("button",{onClick:()=>O.previousPage(),disabled:!O.getCanPreviousPage(),className:"ff-btn ff-btn-secondary ff-btn-sm",children:[l.jsx(gt,{className:"ff-w-4 ff-h-4"}),"Previous"]}),l.jsxs("button",{onClick:()=>O.nextPage(),disabled:!O.getCanNextPage(),className:"ff-btn ff-btn-secondary ff-btn-sm",children:["Next",l.jsx(w.ChevronRight,{className:"ff-w-4 ff-h-4"})]})]})]})]})},$e=({showDetails:e=!0})=>{const{validationResults:o}=ee();if(!o)return null;const{isValid:t,totalRows:n,validRows:r,errorCount:s,warningCount:i,infoCount:a,summary:f}=o,d=Math.round(r/n*100);return l.jsxs("div",{className:"ff-space-y-4",children:[l.jsxs("div",{className:"ff-flex ff-items-center ff-gap-4 ff-p-4 ff-rounded-lg ff-border",style:{backgroundColor:t?"var(--ff-success-light)":"var(--ff-error-light)",borderColor:t?"var(--ff-success)":"var(--ff-error)"},children:[t?l.jsx(w.CircleCheckBig,{className:"ff-w-8 ff-h-8",style:{color:"var(--ff-success)"}}):l.jsx(w.CircleX,{className:"ff-w-8 ff-h-8",style:{color:"var(--ff-error)"}}),l.jsxs("div",{children:[l.jsx("h3",{className:"ff-text-lg ff-font-semibold",style:{color:t?"var(--ff-success-dark)":"var(--ff-error-dark)"},children:t?"Validation Passed":"Validation Failed"}),l.jsxs("p",{className:"ff-text-sm",style:{color:t?"var(--ff-success)":"var(--ff-error)"},children:[r," of ",n," rows are valid (",d,"%)"]})]})]}),l.jsxs("div",{className:"ff-grid ff-grid-cols-4 ff-gap-4",children:[l.jsxs("div",{className:"ff-border ff-rounded-lg ff-p-4 ff-text-center",style:{backgroundColor:"var(--ff-bg-primary)",borderColor:"var(--ff-border-light)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-text-primary)"},children:n}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-text-muted)"},children:"Total Rows"})]}),l.jsxs("div",{className:"ff-border ff-rounded-lg ff-p-4 ff-text-center",style:{backgroundColor:"var(--ff-success-light)",borderColor:"var(--ff-success)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-success-dark)"},children:r}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-success)"},children:"Valid Rows"})]}),l.jsxs("div",{className:"ff-border ff-rounded-lg ff-p-4 ff-text-center",style:{backgroundColor:"var(--ff-error-light)",borderColor:"var(--ff-error)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-error-dark)"},children:s}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-error)"},children:"Errors"})]}),l.jsxs("div",{className:"ff-border ff-rounded-lg ff-p-4 ff-text-center",style:{backgroundColor:"var(--ff-warning-light)",borderColor:"var(--ff-warning)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-warning-dark)"},children:i}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-warning)"},children:"Warnings"})]})]}),e&&f.byColumn&&Object.keys(f.byColumn).length>0&&l.jsxs("div",{className:"ff-border ff-rounded-xl ff-overflow-hidden",style:{backgroundColor:"var(--ff-bg-primary)",borderColor:"var(--ff-border-light)"},children:[l.jsx("div",{className:"ff-px-4 ff-py-3",style:{backgroundColor:"var(--ff-bg-secondary)"},children:l.jsx("h4",{className:"ff-font-medium ff-text-sm",style:{color:"var(--ff-text-secondary)"},children:"Issues by Column"})}),l.jsx("div",{children:Object.entries(f.byColumn).filter(([,p])=>p.errorCount>0||p.warningCount>0).map(([p,g],c,u)=>l.jsxs("div",{className:"ff-flex ff-items-center ff-justify-between ff-px-4 ff-py-3",style:{borderTop:c>0?"1px solid var(--ff-border-light)":void 0},children:[l.jsxs("div",{className:"ff-flex-1 ff-min-w-0 ff-mr-4",children:[l.jsx("p",{className:"ff-font-medium ff-text-sm",style:{color:"var(--ff-text-primary)"},children:g.columnKey}),g.mostCommonError&&l.jsx("p",{className:"ff-text-sm ff-truncate",style:{color:"var(--ff-text-muted)"},children:g.mostCommonError})]}),l.jsxs("div",{className:"ff-flex ff-items-center ff-gap-2 ff-flex-shrink-0",children:[g.errorCount>0&&l.jsxs("span",{className:"ff-badge ff-badge-error ff-whitespace-nowrap",children:[l.jsx(w.CircleX,{className:"ff-w-3 ff-h-3 ff-mr-1"}),g.errorCount," ",g.errorCount===1?"error":"errors"]}),g.warningCount>0&&l.jsxs("span",{className:"ff-badge ff-badge-warning ff-whitespace-nowrap",children:[l.jsx(w.TriangleAlert,{className:"ff-w-3 ff-h-3 ff-mr-1"}),g.warningCount," ",g.warningCount===1?"warning":"warnings"]})]})]},p))})]}),e&&f.duplicates&&f.duplicates.length>0&&l.jsx("div",{className:"ff-border ff-rounded-lg ff-p-4",style:{backgroundColor:"var(--ff-warning-light)",borderColor:"var(--ff-warning)"},children:l.jsxs("div",{className:"ff-flex ff-items-start ff-gap-3",children:[l.jsx(w.TriangleAlert,{className:"ff-w-5 ff-h-5 ff-flex-shrink-0 ff-mt-0.5",style:{color:"var(--ff-warning)"}}),l.jsxs("div",{children:[l.jsx("h4",{className:"ff-font-medium",style:{color:"var(--ff-warning-dark)"},children:"Duplicate Values Found"}),l.jsxs("ul",{className:"ff-mt-2 ff-space-y-1 ff-text-sm",style:{color:"var(--ff-warning-dark)"},children:[f.duplicates.slice(0,5).map((p,g)=>l.jsxs("li",{children:[l.jsx("span",{className:"ff-font-mono",children:p.columnKey}),': "',String(p.value),'" appears'," ",p.rowIndices.length," times (rows"," ",p.rowIndices.slice(0,3).map(c=>c+1).join(", "),p.rowIndices.length>3?"...":"",")"]},g)),f.duplicates.length>5&&l.jsxs("li",{style:{color:"var(--ff-warning)"},children:["... and ",f.duplicates.length-5," more duplicate groups"]})]})]})]})})]})},Ce=["upload","mapping","validation","complete"],Mn=[{key:"upload",label:"Upload",icon:w.Upload},{key:"mapping",label:"Map Columns",icon:Rt},{key:"validation",label:"Validate",icon:It},{key:"review",label:"Review",icon:vt},{key:"complete",label:"Complete",icon:w.CircleCheckBig}],Vn=({template:e,schema:o,mode:t="modal",theme:n,useShadowDom:r=!1,onComplete:s,onCancel:i,onError:a})=>{const{step:f,sessionId:d,file:p,mappings:g,validationResults:c,isLoading:u,error:m,setSchema:h,setSessionId:x,setParsedData:v,setMappings:C,setUnmapped:R,setValidationResults:$,setStep:_,nextStep:V,previousStep:Q,setLoading:E,setError:B,reset:X}=ee(),[L,O]=b.useState(null),[F,j]=b.useState(null),[N,T]=b.useState(0),[z,Z]=b.useState("");b.useEffect(()=>{if(j(null),e)if(w.templateExists(e)){const I=w.getTemplateSchema(e);I?O(I):(j(`Failed to load template "${e}"`),a==null||a(new Error(`Failed to load template "${e}"`)))}else{const I=`Template "${e}" not found. Available templates: ${w.VALID_TEMPLATE_IDS.join(", ")}`;j(I),a==null||a(new Error(I))}else if(o)O(o);else{const I=`No template or schema provided. Please specify a template (${w.VALID_TEMPLATE_IDS.join(", ")}) or provide a custom schema.`;j(I),a==null||a(new Error(I))}},[e,o,a]),b.useEffect(()=>{L&&(h(L),J(L))},[L]);const J=async I=>{try{E(!0);const P=await w.getClient().createImportSession(I);x(P.sessionId)}catch(M){const P=M;B(P.message),a==null||a(P)}finally{E(!1)}},Je=b.useCallback(async I=>{if(d)try{E(!0),B(null),C([]),R([],[]),$(null),T(10),Z("Uploading file...");const M=w.getClient();T(30),Z("Parsing file data...");const P=await M.uploadFile(d,I);T(60),Z("Processing rows...");const K=(D,H)=>({rowIndex:D.rowIndex??H,data:D.data??D,rawData:D.rawData??Object.values(D.data??D)});v({headers:P.data.headers,rows:P.data.sampleRows.map(K),totalRows:P.data.totalRows,sampleRows:P.data.sampleRows.map(K)}),T(80),Z("Matching columns..."),_("mapping"),await et(),T(100),Z("Done")}catch(M){B(`Failed to process the uploaded file: ${M.message}`)}finally{E(!1),T(0),Z("")}},[d]),et=async()=>{if(d)try{E(!0);const M=await w.getClient().matchColumns(d);C(M.mappings),R(M.unmappedSource,M.unmappedTarget)}catch(I){B(`Column matching failed: ${I.message}`)}finally{E(!1)}},tt=async()=>{if(d)try{E(!0),B(null);const M=await w.getClient().validateImport(d);$(M.validation),V()}catch(I){B(`Validation failed: ${I.message}`)}finally{E(!1)}},[ke,le]=b.useState(null),[k,be]=b.useState(null),nt=async()=>{if(d)try{E(!0),B(null),le(null);const P=await w.getClient().completeImport(d,{skipInvalidRows:!1,acknowledgeWarnings:!0}),K={...P,data:(P.data||[]).map(D=>D.data&&typeof D.data=="object"&&!Array.isArray(D.data)?{rowIndex:D.rowIndex??0,data:D.data,wasEdited:D.wasEdited??!1}:D)};be(K),_("complete"),s==null||s(K)}catch(I){le(I.message),_("complete")}finally{E(!1)}},ie=()=>{X(),i==null||i()},Ee=()=>{le(null),be(null),T(0),Z(""),X(),L&&(h(L),J(L))},ot=()=>Mn.findIndex(I=>I.key===f),rt=()=>{switch(f){case"upload":return p!==null;case"mapping":return g.length>0&&g.some(I=>I.targetKey!==null);case"validation":return c!==null;case"review":return c!==null&&(c.isValid||c.errorCount===0);default:return!1}},st=async()=>{switch(f){case"mapping":await tt();break;case"validation":V();break;case"review":await nt();break;default:V()}};if(F)return l.jsx(w.StyleProvider,{theme:n,useShadowDom:r,children:l.jsx("div",{className:"ff-container ff-bg-white ff-rounded-xl ff-shadow-xl ff-overflow-hidden ff-p-6",children:l.jsxs("div",{className:"ff-flex ff-flex-col ff-items-center ff-justify-center ff-py-8",children:[l.jsx("div",{className:"ff-w-16 ff-h-16 ff-rounded-full ff-flex ff-items-center ff-justify-center ff-mb-4",style:{backgroundColor:"var(--ff-error-light)"},children:l.jsx(w.X,{className:"ff-w-10 ff-h-10",style:{color:"var(--ff-error)"}})}),l.jsx("h3",{className:"ff-text-xl ff-font-semibold ff-mb-2",style:{color:"var(--ff-text-primary)"},children:"Configuration Error"}),l.jsx("p",{className:"ff-text-center ff-max-w-md ff-mb-4",style:{color:"var(--ff-text-muted)"},children:F}),i&&l.jsx("button",{onClick:ie,className:"ff-btn ff-btn-secondary",children:"Close"})]})})});if(!L)return l.jsx(w.StyleProvider,{theme:n,useShadowDom:r,children:l.jsx("div",{className:"ff-container ff-bg-white ff-rounded-xl ff-shadow-xl ff-overflow-hidden ff-p-6",children:l.jsxs("div",{className:"ff-flex ff-flex-col ff-items-center ff-justify-center ff-py-8",children:[l.jsx(w.LoaderCircle,{className:"ff-w-10 ff-h-10 ff-animate-spin ff-mb-4",style:{color:"var(--ff-primary-90)"}}),l.jsx("p",{style:{color:"var(--ff-text-muted)"},children:"Loading template..."})]})})});const ne=()=>{const I=f==="review"?"validation":f;return Ce.indexOf(I)},lt=t==="embed"?"ff-container ff-embed":"ff-container ff-modal",Le=l.jsx(l.Fragment,{children:l.jsxs("div",{className:lt,children:[l.jsxs("div",{className:"ff-modal-header",children:[l.jsxs("div",{className:"ff-modal-header-left",children:[l.jsxs("div",{className:"ff-flex ff-items-center ff-gap-3",children:[l.jsx("div",{className:"ff-modal-icon",children:l.jsx(wt,{})}),l.jsx("h2",{className:"ff-modal-title",children:"Import Data"})]}),l.jsx("div",{className:"ff-steps ff-ml-4",children:Ce.map((I,M)=>l.jsxs(b.Fragment,{children:[l.jsx("div",{className:w.clsx("ff-step",ne()===M&&"ff-step-active",ne()>M&&"ff-step-complete",ne()<M&&"ff-step-pending"),children:ne()>M?"✓":M+1}),M<Ce.length-1&&l.jsx("div",{className:w.clsx("ff-step-connector",ne()>M&&"ff-step-connector-complete")})]},I))})]}),l.jsx("button",{onClick:ie,className:"ff-modal-close",children:l.jsx(w.X,{className:"ff-w-5 ff-h-5"})})]}),l.jsxs("div",{className:"ff-modal-body",children:[m&&l.jsx("div",{className:"ff-mb-4 ff-p-4 ff-border ff-rounded-lg ff-text-sm",style:{backgroundColor:"var(--ff-error-light)",borderColor:"var(--ff-error)",color:"var(--ff-error)"},children:m}),f==="upload"&&l.jsx("div",{className:"ff-py-4",children:l.jsx("div",{className:"ff-max-w-xl ff-mx-auto",children:u&&N>0?l.jsxs("div",{className:"ff-p-8 ff-text-center",children:[l.jsx(w.LoaderCircle,{className:"ff-w-10 ff-h-10 ff-animate-spin ff-mx-auto ff-mb-4",style:{color:"var(--ff-primary-90)"}}),l.jsx("p",{className:"ff-font-medium ff-mb-2",style:{color:"var(--ff-text-primary)"},children:z}),l.jsx("div",{className:"ff-progress ff-w-full ff-max-w-xs ff-mx-auto ff-mb-2",children:l.jsx("div",{className:"ff-progress-bar",style:{width:`${N}%`,transition:"width 0.3s ease"}})}),l.jsxs("p",{className:"ff-text-sm",style:{color:"var(--ff-text-muted)"},children:[N,"% complete"]})]}):l.jsx(Oe,{onFileSelect:Je})})}),f==="mapping"&&(u&&N>0?l.jsxs("div",{className:"ff-py-12 ff-text-center",children:[l.jsx(w.LoaderCircle,{className:"ff-w-10 ff-h-10 ff-animate-spin ff-mx-auto ff-mb-4",style:{color:"var(--ff-primary-90)"}}),l.jsx("p",{className:"ff-font-medium ff-mb-3",style:{color:"var(--ff-text-primary)"},children:z}),l.jsx("div",{className:"ff-progress ff-w-full ff-max-w-xs ff-mx-auto ff-mb-2",children:l.jsx("div",{className:"ff-progress-bar",style:{width:`${N}%`,transition:"width 0.3s ease"}})}),l.jsxs("p",{className:"ff-text-sm",style:{color:"var(--ff-text-muted)"},children:[N,"% complete"]})]}):l.jsx(Te,{})),f==="validation"&&l.jsxs("div",{className:"ff-space-y-6",children:[l.jsx($e,{}),l.jsx(Ie,{editable:!0})]}),f==="review"&&l.jsxs("div",{className:"ff-space-y-6",children:[l.jsx($e,{showDetails:!1}),l.jsx(Ie,{editable:!1,pageSize:10})]}),f==="complete"&&l.jsx("div",{className:"ff-flex ff-flex-col ff-items-center ff-justify-center ff-py-8",children:ke?l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"ff-w-16 ff-h-16 ff-rounded-full ff-flex ff-items-center ff-justify-center ff-mb-4",style:{backgroundColor:"var(--ff-error-light)"},children:l.jsx(w.X,{className:"ff-w-10 ff-h-10",style:{color:"var(--ff-error)"}})}),l.jsx("h3",{className:"ff-text-xl ff-font-semibold ff-mb-2",style:{color:"var(--ff-text-primary)"},children:"Import Failed"}),l.jsx("p",{className:"ff-text-center ff-max-w-md ff-mb-4",style:{color:"var(--ff-text-muted)"},children:ke}),l.jsxs("div",{className:"ff-flex ff-gap-3",children:[l.jsx("button",{onClick:()=>{le(null),_("review")},className:"ff-btn ff-btn-secondary",children:"Back to Review"}),i&&l.jsx("button",{onClick:ie,className:"ff-btn ff-btn-secondary",children:"Close"})]})]}):l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"ff-w-20 ff-h-20 ff-rounded-2xl ff-flex ff-items-center ff-justify-center ff-mb-6",style:{backgroundColor:"var(--ff-success-light)"},children:l.jsx(w.CircleCheckBig,{className:"ff-w-10 ff-h-10",style:{color:"var(--ff-success)"}})}),l.jsx("h3",{className:"ff-text-xl ff-font-semibold ff-mb-2",style:{color:"var(--ff-text-primary)"},children:"Import Complete!"}),l.jsx("p",{className:"ff-mb-6",style:{color:"var(--ff-text-muted)"},children:"Your data has been successfully imported."}),l.jsxs("div",{className:"ff-flex ff-gap-6 ff-mb-6",children:[l.jsxs("div",{className:"ff-text-center ff-px-6 ff-py-3 ff-rounded-xl ff-border",style:{borderColor:"var(--ff-border-light)",backgroundColor:"var(--ff-bg-primary)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-text-primary)"},children:(k==null?void 0:k.totalRows)??(c==null?void 0:c.totalRows)??0}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-text-muted)"},children:"Total Rows"})]}),l.jsxs("div",{className:"ff-text-center ff-px-6 ff-py-3 ff-rounded-xl ff-border",style:{borderColor:"var(--ff-success)",backgroundColor:"var(--ff-success-light)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-success-dark)"},children:(k==null?void 0:k.importedRows)??(c==null?void 0:c.validRows)??0}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-success)"},children:"Imported"})]}),((k==null?void 0:k.skippedRows)??0)>0&&l.jsxs("div",{className:"ff-text-center ff-px-6 ff-py-3 ff-rounded-xl ff-border",style:{borderColor:"var(--ff-warning)",backgroundColor:"var(--ff-warning-light)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-warning-dark)"},children:(k==null?void 0:k.skippedRows)??0}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-warning)"},children:"Skipped"})]}),l.jsxs("div",{className:"ff-text-center ff-px-6 ff-py-3 ff-rounded-xl ff-border",style:{borderColor:"var(--ff-border-light)",backgroundColor:"var(--ff-bg-primary)"},children:[l.jsx("p",{className:"ff-text-2xl ff-font-bold",style:{color:"var(--ff-text-primary)"},children:g.filter(I=>I.targetKey!==null).length}),l.jsx("p",{className:"ff-text-sm",style:{color:"var(--ff-text-muted)"},children:"Columns Mapped"})]})]}),(k==null?void 0:k.data)&&k.data.length>0&&(()=>{const I=k.data.slice(0,5),M=I[0],P=(M==null?void 0:M.data)||M,K=Object.keys(typeof P=="object"?P:{}).slice(0,6),D=(L==null?void 0:L.columns)||[];return K.length===0?null:l.jsxs("div",{className:"ff-w-full ff-mb-6",children:[l.jsxs("p",{className:"ff-text-xs ff-font-semibold ff-uppercase ff-tracking-wider ff-mb-2",style:{color:"var(--ff-text-muted)"},children:["Data Preview (first ",I.length," rows)"]}),l.jsx("div",{className:"ff-table-container ff-max-h-[250px]",children:l.jsxs("table",{className:"ff-table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{style:{width:40},children:"#"}),K.map(H=>{const te=D.find(oe=>oe.key===H);return l.jsx("th",{children:(te==null?void 0:te.label)||H},H)}),K.length<Object.keys(typeof P=="object"?P:{}).length&&l.jsx("th",{children:"..."})]})}),l.jsx("tbody",{children:I.map((H,te)=>{const oe=(H==null?void 0:H.data)||H;return l.jsxs("tr",{children:[l.jsx("td",{children:l.jsx("span",{className:"ff-font-mono ff-text-xs",style:{color:"var(--ff-text-muted)"},children:((H==null?void 0:H.rowIndex)??te)+1})}),K.map(De=>l.jsx("td",{children:l.jsx("span",{className:"ff-text-sm ff-truncate ff-block ff-max-w-[150px]",children:String((oe==null?void 0:oe[De])??"—")})},De)),K.length<Object.keys(typeof P=="object"?P:{}).length&&l.jsx("td",{children:l.jsx("span",{style:{color:"var(--ff-text-muted)"},children:"..."})})]},te)})})]})}),k.data.length>5&&l.jsxs("p",{className:"ff-text-xs ff-mt-1",style:{color:"var(--ff-text-muted)"},children:["Showing 5 of ",k.data.length," imported rows"]})]})})(),l.jsxs("div",{className:"ff-flex ff-gap-3",children:[l.jsx("button",{onClick:Ee,className:"ff-btn ff-btn-primary",children:"Start New Import"}),i&&l.jsx("button",{onClick:ie,className:"ff-btn ff-btn-secondary",children:"Close"})]})]})})]}),l.jsx("div",{className:"ff-modal-footer",children:f==="complete"?l.jsxs(l.Fragment,{children:[l.jsx("div",{}),l.jsx("button",{onClick:Ee,className:"ff-btn ff-btn-primary",children:"Start New Import"})]}):l.jsxs(l.Fragment,{children:[l.jsx("button",{onClick:Q,disabled:ot()===0||u,className:"ff-btn ff-btn-ghost",children:"Back"}),l.jsx("button",{onClick:st,disabled:!rt()||u,className:"ff-btn ff-btn-primary",children:u?l.jsxs(l.Fragment,{children:[l.jsx(w.LoaderCircle,{className:"ff-w-4 ff-h-4 ff-animate-spin"}),"Processing..."]}):f==="review"?"Complete Import":"Continue"})]})})]})});return l.jsx(w.StyleProvider,{theme:n,useShadowDom:r,children:t==="modal"?l.jsx("div",{className:"ff-overlay",children:Le}):Le})};exports.ColumnMapper=Te;exports.DataTable=Ie;exports.FileUploader=Oe;exports.ImportWizard=Vn;exports.ValidationSummary=$e;exports.useImportStore=ee;
|
|
78
|
+
//# sourceMappingURL=ImportWizard-Bueox6It.js.map
|