PageSourceSearch

https://conversiontab.com/build/assets/csv-editor-page-Dg7Nt1Bh.js

js conversiontab.com collected 2026-09-24 10:06:54 UTC 12,155 bytes, 7 lines download raw bytes

1import{T as Ve}from"./app-gOHIPY12.js";import{P as ce}from"./papaparse.min-DtqB8VRF.js";import{saveResultFile as je}from"./ctResultAccessAd-Dk9whJZs.js";import{C as xe,r as Ae,M as De}from"./csvSqlCore-M_4k9GW7.js";import{w as Ye,c as Te}from"./fileDropzone-CA_uaFcV.js";import"./_commonjsHelpers-BosuxZz1.js";import"./FileSaver.min-BR20wtAe.js";import"./ctFullscreenAd-CL-AA_Ul.js";import"./transientNotice-Ds_di7lD.js";const ae=2500,G=80,Ze=De*1024*1024,Ke=48;function g(c){return c.length===0?1:Math.min(G,Math.max(1,...c.map(a=>a.length)))}function i(c){const a=g(c);for(const E of c){for(;E.length<a;)E.push("");E.length>a&&(E.length=a)}}function Se(c){return c.map(a=>[...a])}function be(c){let a=!1,E=!1,C=c.map(y=>(Array.isArray(y)?y:[]).map(d=>d==null?"":String(d)));if(C.length===0)return{rows:[[""]],truncatedRows:!1,truncatedCols:!1};let S=Math.max(1,...C.map(y=>y.length));return S>G&&(E=!0,S=G),C=C.map(y=>{const d=y.slice(0,S);for(;d.length<S;)d.push("");return d}),C.length>ae&&(a=!0,C=C.slice(0,ae)),i(C),{rows:C,truncatedRows:a,truncatedCols:E}}function V(c){const a=(c==null?void 0:c.value)??",";return a==="\\t"||a==="	"?"	":a||","}function et(c,a){return!c||c.value==="__same__"?V(a):V(c)}function it(){var me,pe,he,ge,Ee,Ce,ve,ye,we,Ie,ke;const c=document.getElementById("ct-csv-editor-root");if(!c)return;const a=document.getElementById("ctCsvEdTextarea"),E=document.getElementById("ctCsvEdDelimiter"),C=document.getElementById("ctCsvEdQuoteChar"),S=document.getElementById("ctCsvEdEscapeChar"),y=document.getElementById("ctCsvEdSkipEmpty"),d=document.getElementById("ctCsvEdHeader"),j=document.getElementById("ctCsvEdWriteDelim"),Y=document.getElementById("ctCsvEdEol"),Z=document.getElementById("ctCsvEdWriteHeader"),K=document.getElementById("ctCsvEdQuoteAll"),O=document.getElementById("ctCsvEdFilename"),J=document.getElementById("ctCsvEdThead"),Q=document.getElementById("ctCsvEdTbody"),de=document.getElementById("ctCsvEdMeta"),q=document.getElementById("ctCsvEdTrunc"),b=document.getElementById("ctCsvEdFile"),ee=document.getElementById("ctCsvEdDrop"),Re=document.getElementById("ctCsvEdDropCaption"),M=document.getElementById("ctCsvEdUndo"),N=document.getElementById("ctCsvEdRedo"),_=document.getElementById("ctCsvEdResetSnap"),F=document.getElementById("ctCsvEdReloadFile");if(!a||!E||!C||!S||!y||!d||!j||!Y||!Z||!K||!O||!J||!Q||!de||!q)return;let t=[[""]],L=null,x=null,w=null,v=[],D=[],$=!1,P=!1,W=!1;function m(e,n=!0){const s=document.getElementById("ctCsvEdToast"),r=document.getElementById("ctCsvEdToastBody");if(!s||!r){window.alert(e);return}r.textContent=e,s.classList.remove("text-bg-success","text-bg-danger"),s.classList.add(n?"text-bg-danger":"text-bg-success"),Ve.getOrCreateInstance(s,{delay:4200}).show()}function te(){const e=C.value||'"';return e.length?e[0]:'"'}function ie(){const e=S.value.trim();return e.length?e[0]:te()}function ue(e){const n=te(),s=ie();return{delimiter:e,quoteChar:n,escapeChar:s,skipEmptyLines:y.checked?"greedy":!1}}function ne(){return JSON.stringify({rows:Se(t),hasHeader:d.checked})}function fe(e){const n=JSON.parse(e);t=Array.isArray(n.rows)?n.rows.map(s=>[...s]):[[""]],d.checked=!!n.hasHeader,i(t)}function A(){M&&(M.disabled=v.length===0),N&&(N.disabled=D.length===0)}function I(){$||(v.push(ne()),v.length>Ke&&v.shift(),D.length=0,A())}function re(){v=[],D=[],A()}function se(){_&&(_.disabled=x==null),F&&(F.disabled=w==null)}function Me(){var o;if(x==null)return null;const e=V(E),n=ce.parse(x,ue(e));if((o=n.errors)!=null&&o.length&&n.errors.find(h=>h.type==="Quotes"||h.type==="Delimiter"))return null;const s=Array.isArray(n.data)?n.data:[],{rows:r}=be(s);let l=r;return i(l),d.checked&&l.length===1&&(l=[...l,Array(g(l)).fill("")],i(l)),l}function u(){const e=t.length,n=g(t);let s=0;for(const o of t)for(const f of o)String(f).trim()!==""&&(s+=1);let r="no snapshot";if(x!=null){const o=Me();o?r=JSON.stringify(t)===JSON.stringify(o)?"matches snapshot":"edited":r="edited (parse error)"}de.textContent=`Rows: ${e} · Cols: ${n} · Non-empty cells: ${s} · ${r}`;const l=[];P&&l.push(`rows capped at ${ae}`),W&&l.push(`columns capped at ${G}`),l.length?(q.textContent=`For performance, ${l.join(" and ")}
1. Download exports the grid as shown.`,q.classList.remove("d-none")):q.classList.add("d-none")}function oe(e,n,s,r){const l=document.createElement(r?"th":"td");l.className="p-0 align-middle";const o=document.createElement("input");return o.type="text",o.className="form-control form-control-sm border-0 rounded-0 shadow-none",o.value=s,o.dataset.r=String(e),o.dataset.c=String(n),o.autocomplete="off",o.spellcheck=!1,l.appendChild(o),l}function p(){const e=d.checked;J.innerHTML="",Q.innerHTML="";const n=g(t);if(e&&t.length>0){const s=document.createElement("tr");for(let r=0;r<n;r+=1)s.appendChild(oe(0,r,t[0][r]??"",!0));J.appendChild(s);for(let r=1;r<t.length;r+=1){const l=document.createElement("tr");for(let o=0;o<n;o+=1)l.appendChild(oe(r,o,t[r][o]??"",!1));Q.appendChild(l)}}else{const s=document.createElement("tr");for(let r=0;r<n;r+=1){const l=document.createElement("th");l.className="small text-body-secondary fw-semibold",l.textContent=`Column ${r+1}`,s.appendChild(l)}J.appendChild(s);for(let r=0;r<t.length;r+=1){const l=document.createElement("tr");for(let o=0;o<n;o+=1)l.appendChild(oe(r,o,t[r][o]??"",!1));Q.appendChild(l)}}}function R(e,n,s,r){var U;r&&re();const l=V(E),o=ce.parse(e,ue(l));if((U=o.errors)!=null&&U.length){const X=o.errors.find(H=>H.type==="Quotes"||H.type==="Delimiter");if(X)return m(X.message||"Could not parse CSV."),!1}const f=Array.isArray(o.data)?o.data:[],{rows:h,truncatedRows:k,truncatedCols:T}=be(f);return t=h,i(t),d.checked&&t.length===1&&(t.push(Array(g(t)).fill("")),i(t)),P=k,W=T,x=e,w=n&&s?s:null,se(),u(),p(),!0}function Ne(e){const n=e.target;if(!(n instanceof HTMLInputElement)||!n.closest("#ctCsvEdTable"))return;const s=parseInt(n.dataset.r??"",10),r=parseInt(n.dataset.c??"",10);Number.isNaN(s)||Number.isNaN(r)||t[s]&&(t[s][r]=n.value,u())}c.addEventListener("input",Ne),c.addEventListener("focusin",e=>{const n=e.target;n instanceof HTMLInputElement&&n.closest("#ctCsvEdTable")&&(n.dataset.r==null||n.dataset.c==null||(L={r:parseInt(n.dataset.r,10),c:parseInt(n.dataset.c,10)}))}),c.addEventListener("keydown",e=>{const n=e.target;if(!(n instanceof HTMLInputElement)||!n.closest("#ctCsvEdTable"))return;const s=parseInt(n.dataset.r??"",10),r=parseInt(n.dataset.c??"",10);if(Number.isNaN(s)||Number.isNaN(r))return;const l=g(t),o=t.length;let f=s,h=r;if(e.key==="ArrowDown")e.preventDefault(),f=Math.min(o-1,s+1);else if(e.key==="ArrowUp")e.preventDefault(),f=Math.max(0,s-1);else if(e.key==="ArrowRight")n.selectionStart===n.value.length&&(e.preventDefault(),h=Math.min(l-1,r+1));else if(e.key==="ArrowLeft")n.selectionStart===0&&(e.preventDefault(),h=Math.max(0,r-1));else return;if(f===s&&h===r)return;const k=c.querySelector(`#ctCsvEdTable input[data-r="${f}"][data-c="${h}"]`);k instanceof HTMLElement&&k.focus()}),c.addEventListener("paste",e=>{var Be;const n=e.target;if(!(n instanceof HTMLInputElement)||!n.closest("#ctCsvEdTable"))return;const s=(Be=e.clipboardData)==null?void 0:Be.getData("text/plain");if(!s)return;const r=s.replace(/\r\n/g,`
2`).replace(/\r/g,`
3`);if(!r.includes("	")&&!r.includes(`
4`))return;e.preventDefault(),I();let l=r.split(`
5`);for(;l.length>0&&l[l.length-1]==="";)l.pop();const o=l.map(B=>B.split("	")),f=o.length,h=Math.max(1,...o.map(B=>B.length)),k=parseInt(n.dataset.r??"0",10),T=parseInt(n.dataset.c??"0",10),U=k+f,X=T+h;for(;t.length<U;)t.push(Array(g(t)).fill(""));for(i(t);g(t)<X;)for(const B of t)B.push("");i(t);for(let B=0;B<f;B+=1){const Ge=o[B]||[];for(let z=0;z<h;z+=1){const le=k+B,Le=T+z;le<t.length&&Le<t[le].length&&(t[le][Le]=Ge[z]??"")}}i(t),u(),p();const H=c.querySelector(`#ctCsvEdTable input[data-r="${k}"][data-c="${T}"]`);H instanceof HTMLElement&&H.focus()},!0);function _e(){I(),i(t),t.push(Array(g(t)).fill("")),u(),p()}function Fe(){I(),i(t);for(const e of t)e.push("");u(),p()}function $e(){if(L==null){m("Click a cell in the row you want to delete.");return}I();const e=L.r;if(t.length<=1&&g(t)<=1&&(t[0][0]||"")===""){m("Nothing to delete."),v.pop(),A();return}t.splice(e,1),t.length===0&&(t=[[""]]),i(t),d.checked&&t.length===1&&(t.push(Array(g(t)).fill("")),i(t)),L=null,u(),p()}function He(){if(L==null){m("Click a cell in the column you want to delete.");return}I();const e=L.c;if(g(t)<=1){for(const n of t)n[0]="";L=null,u(),p();return}for(const n of t)e<n.length&&n.splice(e,1);i(t),L=null,u(),p()}function Oe(){I(),t=t.map(e=>e.map(n=>String(n).trim())),u(),p(),m("Trimmed all cells.",!1)}function Je(){I(),i(t);const e=t.length,n=g(t),s=[];for(let r=0;r<n;r+=1){const l=[];for(let o=0;o<e;o+=1)l.push(t[o][r]??"");s.push(l)}t=s.length?s:[[""]],i(t),m("Transposed. Review “First row is header” if needed.",!1),u(),p()}function Qe(){i(t);let e=Se(t);d.checked&&!Z.checked&&(e=e.slice(1),e.length===0&&(e=[[""]]));const n=et(j,E),s=Y.value==="crlf"?`\r
6`:`
7`,r=te(),l=ie(),o=K.checked;let f;try{f=ce.unparse(e,{delimiter:n,newline:s,quotes:o,quoteChar:r,escapeChar:l===r?r:l})}catch(T){m(T instanceof Error?T.message:"Could not build CSV.");return}const h=(O.value||"data").trim().replace(/\.csv$/i,"").replace(/[/\\?%*:|"<>]/g,"-")||"data",k=new Blob([f],{type:"text/csv;charset=utf-8"});je(k,`${h}.csv`),m("Download started.",!1)}function qe(){if(x==null){m("No snapshot yet. Load text or a file first.");return}window.confirm("Discard edits and restore the last loaded source using current read options?")&&(I(),R(x,w!=null,w,!1)||(v.pop(),A()))}async function Pe(){if(!w){m("Open a file first.");return}if(window.confirm("Read the file again from disk? All edits will be lost."))try{const e=await Ae(w);a.value=e,I(),R(e,!0,w,!1)||(v.pop(),A())}catch{m("Could not read file again.")}}function We(){const e=x??a.value;if(!e.trim()){m("Nothing to parse. Paste text, load a file, or use “Load into grid”.");return}I(),R(e,w!=null,w,!1)||(v.pop(),A())}function Ue(){if(v.length===0)return;$=!0,D.push(ne());const e=v.pop();e&&fe(e),$=!1,u(),p(),A()}
7function Xe(){if(D.length===0)return;$=!0,v.push(ne());const e=D.pop();e&&fe(e),$=!1,u(),p(),A()}function ze(){t=[[""]],d.checked=!1,K.checked=!1,Z.checked=!0,y.checked=!1,j.value="__same__",Y.value="lf",a.value="",O.value="data",L=null,x=null,w=null,re(),se(),b&&Te(b),P=!1,W=!1,u(),p()}(me=document.getElementById("ctCsvEdApplyText"))==null||me.addEventListener("click",()=>{R(a.value,!1,null,!0)}),(pe=document.getElementById("ctCsvEdAddRow"))==null||pe.addEventListener("click",_e),(he=document.getElementById("ctCsvEdAddCol"))==null||he.addEventListener("click",Fe),(ge=document.getElementById("ctCsvEdDelRow"))==null||ge.addEventListener("click",$e),(Ee=document.getElementById("ctCsvEdDelCol"))==null||Ee.addEventListener("click",He),(Ce=document.getElementById("ctCsvEdDownload"))==null||Ce.addEventListener("click",Qe),(ve=document.getElementById("ctCsvEdClear"))==null||ve.addEventListener("click",ze),(ye=document.getElementById("ctCsvEdTrim"))==null||ye.addEventListener("click",Oe),(we=document.getElementById("ctCsvEdTranspose"))==null||we.addEventListener("click",Je),M==null||M.addEventListener("click",Ue),N==null||N.addEventListener("click",Xe),_==null||_.addEventListener("click",qe),F==null||F.addEventListener("click",()=>{Pe()}),(Ie=document.getElementById("ctCsvEdApplyReadOpts"))==null||Ie.addEventListener("click",We),(ke=document.getElementById("ctCsvEdSample"))==null||ke.addEventListener("click",()=>{d.checked=!0,E.value=",",a.value=xe,R(xe,!1,null,!0)}),d.addEventListener("change",()=>{i(t),d.checked&&t.length===1&&(t.push(Array(g(t)).fill("")),i(t)),u(),p()}),y.addEventListener("change",()=>u()),b&&ee&&(Ye({input:b,drop:ee,dragContainer:ee.closest(".card-body"),captionEl:Re??void 0}),b.addEventListener("change",async()=>{var n;const e=(n=b.files)==null?void 0:n[0];if(e){if(e.size>Ze){m(`File exceeds ${De} MB.`),Te(b);return}try{const s=await Ae(e);a.value=s,R(s,!0,e,!0);const r=e.name.replace(/\.[^/.]+$/,"")||"data";O.value=r}catch{m("Could not read file.")}}})),re(),se(),P=!1,W=!1,u(),p()}export{it as initCsvEditorPage};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.