react-excel-lite 0.0.6 → 0.1.0

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.
@@ -1,2 +1,2 @@
1
- (function(m,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],g):(m=typeof globalThis<"u"?globalThis:m||self,g(m.ReactExcelLite={},m.ReactJsxRuntime,m.React))})(this,(function(m,g,r){"use strict";function K(...l){return l.filter(Boolean).join(" ")}function V(l){return`${l.row}-${l.col}`}function X(l){const[o,e]=l.split("-").map(Number);return{row:o,col:e}}function _(l,o){if(!l||!o)return l?[l]:[];const e=Math.min(l.row,o.row),c=Math.max(l.row,o.row),f=Math.min(l.col,o.col),S=Math.max(l.col,o.col),a=[];for(let p=e;p<=c;p++)for(let d=f;d<=S;d++)a.push({row:p,col:d});return a}function A(l,o){if(!o.start)return!1;const e=o.end||o.start,c=Math.min(o.start.row,e.row),f=Math.max(o.start.row,e.row),S=Math.min(o.start.col,e.col),a=Math.max(o.start.col,e.col);return l.row>=c&&l.row<=f&&l.col>=S&&l.col<=a}function U(l){return l.split(/\r?\n/).filter(o=>o.trim()).map(o=>o.split(" ").map(e=>e.trim()))}function H(l){return l.map(o=>o.join(" ")).join(`
2
- `)}function j(l){return!l.start||!l.end?l:{start:{row:Math.min(l.start.row,l.end.row),col:Math.min(l.start.col,l.end.col)},end:{row:Math.max(l.start.row,l.end.row),col:Math.max(l.start.col,l.end.col)}}}function Q(l,o){if(l.row===o.row&&l.col===o.col)return[];const e=Math.min(l.row,o.row),c=Math.max(l.row,o.row),f=Math.min(l.col,o.col),S=Math.max(l.col,o.col),a=[];for(let p=e;p<=c;p++)for(let d=f;d<=S;d++)p===l.row&&d===l.col||a.push({row:p,col:d});return a}function P(){const[l,o]=r.useState({start:null,end:null}),[e,c]=r.useState(!1),f=r.useCallback(u=>{o({start:u,end:u}),c(!0)},[]),S=r.useCallback(u=>{e&&o(t=>({...t,end:u}))},[e]),a=r.useCallback(()=>{c(!1)},[]),p=r.useCallback(()=>{o({start:null,end:null}),c(!1)},[]),d=r.useCallback(u=>A(u,l),[l]);return r.useEffect(()=>{const u=()=>{e&&c(!1)};return window.addEventListener("mouseup",u),()=>window.removeEventListener("mouseup",u)},[e]),{selection:l,isSelecting:e,isCellSelected:d,handleCellMouseDown:f,handleCellMouseEnter:S,handleMouseUp:a,clearSelection:p,setSelection:o}}function W({selection:l,getValue:o,setValues:e,rowCount:c,colCount:f}){const S=r.useCallback(()=>{const t=j(l);if(!t.start||!t.end)return[];const y=[];for(let M=t.start.row;M<=t.end.row;M++){const x=[];for(let k=t.start.col;k<=t.end.col;k++)x.push(o({row:M,col:k}));y.push(x)}return y},[l,o]),a=r.useCallback(async()=>{const t=S();if(t.length===0)return;const y=H(t);try{await navigator.clipboard.writeText(y)}catch(M){console.error("Clipboard copy failed:",M)}},[S]),p=r.useCallback(async()=>{if(l.start)try{const t=await navigator.clipboard.readText(),y=U(t);if(y.length===0)return;const M=l.start.row,x=l.start.col,k=[];y.forEach((h,b)=>{const w=M+b;w>=c||h.forEach((i,v)=>{const F=x+v;F>=f||k.push({coord:{row:w,col:F},value:i})})}),k.length>0&&e(k)}catch(t){console.error("Clipboard paste failed:",t)}},[l.start,e,c,f]),d=r.useCallback(()=>{const t=j(l);if(!t.start||!t.end)return;const y=[];for(let M=t.start.row;M<=t.end.row;M++)for(let x=t.start.col;x<=t.end.col;x++)y.push({coord:{row:M,col:x},value:""});y.length>0&&e(y)},[l,e]),u=r.useCallback(t=>{(t.ctrlKey||t.metaKey)&&t.key==="c"&&(t.preventDefault(),a()),(t.ctrlKey||t.metaKey)&&t.key==="v"&&(t.preventDefault(),p()),(t.key==="Backspace"||t.key==="Delete")&&(t.preventDefault(),d())},[a,p,d]);return{handleCopy:a,handlePaste:p,handleKeyDown:u}}function Y(l){if(l.trim()==="")return null;const o=Number(l);return isNaN(o)?null:o}function O(l){if(l.length===0)return null;const o=l.map(Y);if(o.some(f=>f===null))return null;const e=o;if(e.length===1)return{numbers:e,diff:0};const c=e[1]-e[0];for(let f=2;f<e.length;f++)if(e[f]-e[f-1]!==c)return{numbers:e,diff:0};return{numbers:e,diff:c}}function $({selection:l,getValue:o,setValues:e}){const[c,f]=r.useState(null),[S,a]=r.useState([]),[p,d]=r.useState(!1),[u,t]=r.useState(null),y=r.useCallback(h=>{f(h),d(!0),a([]),t(null)},[]),M=r.useCallback(h=>{if(!p||!l.start)return;const b=j(l);if(!b.start||!b.end)return;t(h);const w={row:Math.min(b.start.row,h.row),col:Math.min(b.start.col,h.col)},i={row:Math.max(b.end.row,h.row),col:Math.max(b.end.col,h.col)},v=[];for(let F=w.row;F<=i.row;F++)for(let s=w.col;s<=i.col;s++)F>=b.start.row&&F<=b.end.row&&s>=b.start.col&&s<=b.end.col||v.push({row:F,col:s});a(v)},[p,l]),x=r.useCallback(()=>{if(!l.start||S.length===0||!u){f(null),a([]),d(!1),t(null);return}const h=j(l);if(!h.start||!h.end){f(null),a([]),d(!1),t(null);return}const b=[],w=h.start,i=h.end,v=i.row-w.row+1,F=i.col-w.col+1;S.forEach(s=>{let N,G;if(s.row<w.row){const E=w.row-s.row;N=i.row-(E-1)%v}else if(s.row>i.row){const E=s.row-i.row;N=w.row+(E-1)%v}else N=s.row;if(s.col<w.col){const E=w.col-s.col;G=i.col-(E-1)%F}else if(s.col>i.col){const E=s.col-i.col;G=w.col+(E-1)%F}else G=s.col;let B=o({row:N,col:G});if(s.row!==N&&s.col>=w.col&&s.col<=i.col){const E=[];for(let n=w.row;n<=i.row;n++)E.push(o({row:n,col:s.col}));const D=O(E);if(D&&D.diff!==0){if(s.row>i.row){const n=s.row-i.row;B=String(D.numbers[D.numbers.length-1]+D.diff*n)}else if(s.row<w.row){const n=w.row-s.row;B=String(D.numbers[0]-D.diff*n)}}}if(s.col!==G&&s.row>=w.row&&s.row<=i.row){const E=[];for(let n=w.col;n<=i.col;n++)E.push(o({row:s.row,col:n}));const D=O(E);if(D&&D.diff!==0){if(s.col>i.col){const n=s.col-i.col;B=String(D.numbers[D.numbers.length-1]+D.diff*n)}else if(s.col<w.col){const n=w.col-s.col;B=String(D.numbers[0]-D.diff*n)}}}b.push({coord:s,value:B})}),b.length>0&&e(b),f(null),a([]),d(!1),t(null)},[l,S,u,o,e]),k=r.useCallback(h=>S.some(b=>b.row===h.row&&b.col===h.col),[S]);return r.useEffect(()=>{const h=()=>{p&&x()};return window.addEventListener("mouseup",h),()=>window.removeEventListener("mouseup",h)},[p,x]),{fillSource:c,fillTargets:S,isDraggingFill:p,isFillTarget:k,handleFillHandleMouseDown:y,handleCellMouseEnterForFill:M,handleFillMouseUp:x}}const Z={position:"relative",border:"1px solid #d1d5db",padding:0},ll={width:"100%",height:"100%",paddingLeft:"4px",paddingRight:"4px",paddingTop:"4px",paddingBottom:"4px",textAlign:"right",fontSize:"12px",backgroundColor:"transparent",outline:"none",cursor:"cell"},ol={position:"absolute",bottom:"-2px",right:"-2px",width:"8px",height:"8px",cursor:"crosshair",zIndex:20,backgroundColor:"#3b82f6"},nl={backgroundColor:"#dbeafe",outline:"2px solid #3b82f6",outlineOffset:"-2px"},el={backgroundColor:"#eff6ff"};function J({coord:l,value:o,isSelected:e,isFillTarget:c,showFillHandle:f,onMouseDown:S,onMouseEnter:a,onChange:p,onFillHandleMouseDown:d,styles:u}){const t=i=>{p(l,i.target.value)},y=i=>{i.target.classList.contains("fill-handle")||S(l)},M=i=>{i.stopPropagation(),i.preventDefault(),d(l)},x=!!u?.selected,k=!!u?.fillTarget,h=!!u?.fillHandle,b={...Z,...e&&!x?nl:{},...c&&!k?el:{}},w={...ol,...h?{backgroundColor:void 0}:{}};return g.jsxs("td",{className:K(u?.cell,e&&u?.selected,c&&u?.fillTarget),style:b,onMouseDown:y,onMouseEnter:()=>a(l),children:[g.jsx("input",{type:"text",value:o,onChange:t,style:ll}),f&&g.jsx("div",{className:K("fill-handle",u?.fillHandle),style:w,onMouseDown:M})]})}const tl={outline:"none",overflowX:"auto"},sl={borderCollapse:"collapse",fontSize:"12px",userSelect:"none"},I={position:"sticky",left:0,zIndex:10,backgroundColor:"#f3f4f6",border:"1px solid #d1d5db",padding:"6px 8px",textAlign:"center",fontWeight:500},rl={backgroundColor:"#dbeafe",border:"1px solid #d1d5db",padding:"6px 4px",textAlign:"center",fontWeight:500,color:"#1d4ed8"},cl={backgroundColor:"#f9fafb",border:"1px solid #d1d5db",padding:"4px",textAlign:"center",fontWeight:500,fontSize:"11px"};function il({data:l,onChange:o,rowHeaders:e,colHeaders:c,className:f,rowHeaderTitle:S="",styles:a}){const p=r.useRef(null),d=l.length,u=r.useMemo(()=>c?c.reduce((n,C)=>n+C.headers.length,0):l[0]?.length??0,[c,l]),t=r.useMemo(()=>c?c.flatMap(n=>n.headers):[],[c]),y=r.useCallback(n=>n.row<0||n.row>=d||n.col<0||n.col>=u?"":l[n.row]?.[n.col]??"",[l,d,u]),M=r.useCallback((n,C)=>{const T=l.map((z,R)=>R===n.row?z.map((L,q)=>q===n.col?C:L):z);o(T)},[l,o]),x=r.useCallback(n=>{if(n.length===0)return;const C=l.map(T=>[...T]);n.forEach(({coord:T,value:z})=>{T.row>=0&&T.row<d&&T.col>=0&&T.col<u&&(C[T.row][T.col]=z)}),o(C)},[l,o,d,u]),{selection:k,isSelecting:h,isCellSelected:b,handleCellMouseDown:w,handleCellMouseEnter:i}=P(),{handleKeyDown:v}=W({selection:k,getValue:y,setValues:x,rowCount:d,colCount:u}),{isDraggingFill:F,isFillTarget:s,handleFillHandleMouseDown:N,handleCellMouseEnterForFill:G}=$({selection:k,getValue:y,setValues:x}),B=r.useCallback(n=>{F?G(n):h&&i(n)},[F,h,G,i]),E=r.useCallback((n,C)=>{M(n,C)},[M]),D=r.useCallback(n=>{if(!k.start)return!1;const C=j(k);return!C.start||!C.end?!1:n.row===C.end.row&&n.col===C.end.col},[k]);return g.jsx("div",{ref:p,className:f,style:tl,tabIndex:0,onKeyDown:v,children:g.jsxs("table",{style:sl,children:[g.jsxs("thead",{children:[c&&g.jsxs("tr",{children:[e&&g.jsx("th",{className:a?.rowHeader,style:I,children:S}),c.map((n,C)=>g.jsx("th",{colSpan:n.headers.length,className:K(a?.colGroup,n.className),style:rl,children:n.label},C))]}),c&&g.jsxs("tr",{children:[e&&g.jsx("th",{className:a?.rowHeader,style:I}),t.map(n=>g.jsx("th",{className:K(a?.colHeader,n.className),style:cl,title:n.description,children:n.label},n.key))]})]}),g.jsx("tbody",{children:l.map((n,C)=>g.jsxs("tr",{children:[e&&e[C]&&g.jsx("td",{className:K(a?.rowHeader,e[C].className),style:I,title:e[C].description,children:e[C].label}),n.map((T,z)=>{const R={row:C,col:z},L=b(R),q=s(R),fl=D(R);return g.jsx(J,{coord:R,value:y(R),isSelected:L,isFillTarget:q,showFillHandle:fl&&!F,onMouseDown:w,onMouseEnter:B,onChange:E,onFillHandleMouseDown:N,styles:a},z)})]},C))})]})})}function al(l){const o=typeof l=="string"?parseFloat(l.replace(/,/g,"")):l;return isNaN(o)?"0":new Intl.NumberFormat("ko-KR").format(o)}function ul(l){const o=parseInt(l.replace(/,/g,""),10);return isNaN(o)?0:o}m.ExcelGrid=il,m.GridCell=J,m.cn=K,m.coordToKey=V,m.formatCurrency=al,m.getCellsInRange=_,m.getFillTargetCells=Q,m.isCellInRange=A,m.keyToCoord=X,m.normalizeRange=j,m.parseCurrency=ul,m.parseTSV=U,m.toTSV=H,m.useGridClipboard=W,m.useGridDragFill=$,m.useGridSelection=P,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(g,k){typeof exports=="object"&&typeof module<"u"?k(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],k):(g=typeof globalThis<"u"?globalThis:g||self,k(g.ReactExcelLite={},g.ReactJsxRuntime,g.React))})(this,(function(g,k,c){"use strict";function L(...e){return e.filter(Boolean).join(" ")}function X(e){return`${e.row}-${e.col}`}function _(e){const[o,n]=e.split("-").map(Number);return{row:o,col:n}}function Q(e,o){if(!e||!o)return e?[e]:[];const n=Math.min(e.row,o.row),i=Math.max(e.row,o.row),u=Math.min(e.col,o.col),M=Math.max(e.col,o.col),f=[];for(let p=n;p<=i;p++)for(let d=u;d<=M;d++)f.push({row:p,col:d});return f}function U(e,o){if(!o.start)return!1;const n=o.end||o.start,i=Math.min(o.start.row,n.row),u=Math.max(o.start.row,n.row),M=Math.min(o.start.col,n.col),f=Math.max(o.start.col,n.col);return e.row>=i&&e.row<=u&&e.col>=M&&e.col<=f}function q(e){return e.split(/\r?\n/).filter(o=>o.trim()).map(o=>o.split(" ").map(n=>n.trim()))}function O(e){return e.map(o=>o.join(" ")).join(`
2
+ `)}function z(e){return!e.start||!e.end?e:{start:{row:Math.min(e.start.row,e.end.row),col:Math.min(e.start.col,e.end.col)},end:{row:Math.max(e.start.row,e.end.row),col:Math.max(e.start.col,e.end.col)}}}function Y(e,o){if(e.row===o.row&&e.col===o.col)return[];const n=Math.min(e.row,o.row),i=Math.max(e.row,o.row),u=Math.min(e.col,o.col),M=Math.max(e.col,o.col),f=[];for(let p=n;p<=i;p++)for(let d=u;d<=M;d++)p===e.row&&d===e.col||f.push({row:p,col:d});return f}function V({containerRef:e}){const[o,n]=c.useState({start:null,end:null}),[i,u]=c.useState(!1),M=c.useCallback(w=>{n({start:w,end:w}),u(!0)},[]),f=c.useCallback(w=>{i&&n(l=>({...l,end:w}))},[i]),p=c.useCallback(()=>{u(!1)},[]),d=c.useCallback(()=>{n({start:null,end:null}),u(!1)},[]),D=c.useCallback(w=>U(w,o),[o]);return c.useEffect(()=>{const w=()=>{i&&u(!1)};return window.addEventListener("mouseup",w),()=>window.removeEventListener("mouseup",w)},[i]),c.useEffect(()=>{const w=l=>{e.current&&!e.current.contains(l.target)&&d()};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[e,d]),{selection:o,isSelecting:i,isCellSelected:D,handleCellMouseDown:M,handleCellMouseEnter:f,handleMouseUp:p,clearSelection:d,setSelection:n}}function W({selection:e,getValue:o,setValues:n,setSelection:i,rowCount:u,colCount:M}){const f=c.useCallback(()=>{const l=z(e);if(!l.start||!l.end)return[];const E=[];for(let h=l.start.row;h<=l.end.row;h++){const x=[];for(let s=l.start.col;s<=l.end.col;s++)x.push(o({row:h,col:s}));E.push(x)}return E},[e,o]),p=c.useCallback(async()=>{const l=f();if(l.length===0)return;const E=O(l);try{await navigator.clipboard.writeText(E)}catch(h){console.error("Clipboard copy failed:",h)}},[f]),d=c.useCallback(async()=>{if(e.start)try{const l=await navigator.clipboard.readText(),E=q(l);if(E.length===0)return;const h=e.start.row,x=e.start.col,s=[];E.forEach((y,b)=>{const m=h+b;m>=u||y.forEach((T,v)=>{const r=x+v;r>=M||s.push({coord:{row:m,col:r},value:T})})}),s.length>0&&n(s)}catch(l){console.error("Clipboard paste failed:",l)}},[e.start,n,u,M]),D=c.useCallback(()=>{const l=z(e);if(!l.start||!l.end)return;const E=[];for(let h=l.start.row;h<=l.end.row;h++)for(let x=l.start.col;x<=l.end.col;x++)E.push({coord:{row:h,col:x},value:""});E.length>0&&n(E)},[e,n]),w=c.useCallback(l=>{if(!(l.target instanceof HTMLInputElement&&!l.target.readOnly)){if(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(l.key)){l.preventDefault();const h=z(e).start??{row:0,col:0};let x=h.row,s=h.col;switch(l.key){case"ArrowUp":x=Math.max(0,h.row-1);break;case"ArrowDown":x=Math.min(u-1,h.row+1);break;case"ArrowLeft":s=Math.max(0,h.col-1);break;case"ArrowRight":s=Math.min(M-1,h.col+1);break}i({start:{row:x,col:s},end:{row:x,col:s}});return}(l.ctrlKey||l.metaKey)&&l.key==="c"&&(l.preventDefault(),p()),(l.ctrlKey||l.metaKey)&&l.key==="v"&&(l.preventDefault(),d()),(l.key==="Backspace"||l.key==="Delete")&&(l.preventDefault(),D())}},[p,d,D,e,i,u,M]);return{handleCopy:p,handlePaste:d,handleKeyDown:w}}function Z(e){if(e.trim()==="")return null;const o=Number(e);return isNaN(o)?null:o}function P(e){if(e.length===0)return null;const o=e.map(Z);if(o.some(u=>u===null))return null;const n=o;if(n.length===1)return{numbers:n,diff:0};const i=n[1]-n[0];for(let u=2;u<n.length;u++)if(n[u]-n[u-1]!==i)return{numbers:n,diff:0};return{numbers:n,diff:i}}function $({selection:e,getValue:o,setValues:n}){const[i,u]=c.useState(null),[M,f]=c.useState([]),[p,d]=c.useState(!1),[D,w]=c.useState(null),l=c.useCallback(s=>{u(s),d(!0),f([]),w(null)},[]),E=c.useCallback(s=>{if(!p||!e.start)return;const y=z(e);if(!y.start||!y.end)return;w(s);const b={row:Math.min(y.start.row,s.row),col:Math.min(y.start.col,s.col)},m={row:Math.max(y.end.row,s.row),col:Math.max(y.end.col,s.col)},T=[];for(let v=b.row;v<=m.row;v++)for(let r=b.col;r<=m.col;r++)v>=y.start.row&&v<=y.end.row&&r>=y.start.col&&r<=y.end.col||T.push({row:v,col:r});f(T)},[p,e]),h=c.useCallback(()=>{if(!e.start||M.length===0||!D){u(null),f([]),d(!1),w(null);return}const s=z(e);if(!s.start||!s.end){u(null),f([]),d(!1),w(null);return}const y=[],b=s.start,m=s.end,T=m.row-b.row+1,v=m.col-b.col+1;M.forEach(r=>{let H,G;if(r.row<b.row){const F=b.row-r.row;H=m.row-(F-1)%T}else if(r.row>m.row){const F=r.row-m.row;H=b.row+(F-1)%T}else H=r.row;if(r.col<b.col){const F=b.col-r.col;G=m.col-(F-1)%v}else if(r.col>m.col){const F=r.col-m.col;G=b.col+(F-1)%v}else G=r.col;let I=o({row:H,col:G});if(r.row!==H&&r.col>=b.col&&r.col<=m.col){const F=[];for(let N=b.row;N<=m.row;N++)F.push(o({row:N,col:r.col}));const a=P(F);if(a&&a.diff!==0){if(r.row>m.row){const N=r.row-m.row;I=String(a.numbers[a.numbers.length-1]+a.diff*N)}else if(r.row<b.row){const N=b.row-r.row;I=String(a.numbers[0]-a.diff*N)}}}if(r.col!==G&&r.row>=b.row&&r.row<=m.row){const F=[];for(let N=b.col;N<=m.col;N++)F.push(o({row:r.row,col:N}));const a=P(F);if(a&&a.diff!==0){if(r.col>m.col){const N=r.col-m.col;I=String(a.numbers[a.numbers.length-1]+a.diff*N)}else if(r.col<b.col){const N=b.col-r.col;I=String(a.numbers[0]-a.diff*N)}}}y.push({coord:r,value:I})}),y.length>0&&n(y),u(null),f([]),d(!1),w(null)},[e,M,D,o,n]),x=c.useCallback(s=>M.some(y=>y.row===s.row&&y.col===s.col),[M]);return c.useEffect(()=>{const s=()=>{p&&h()};return window.addEventListener("mouseup",s),()=>window.removeEventListener("mouseup",s)},[p,h]),{fillSource:i,fillTargets:M,isDraggingFill:p,isFillTarget:x,handleFillHandleMouseDown:l,handleCellMouseEnterForFill:E,handleFillMouseUp:h}}const ee={position:"relative",border:"1px solid #d1d5db",padding:0,height:"28px",minWidth:"80px"},oe={width:"100%",height:"100%",padding:"4px",textAlign:"right",fontSize:"12px",boxSizing:"border-box",cursor:"cell",backgroundColor:"transparent",outline:"none",border:"none"},le={position:"absolute",bottom:"-2px",right:"-2px",width:"8px",height:"8px",cursor:"crosshair",zIndex:20,backgroundColor:"#3b82f6"},ne={backgroundColor:"#dbeafe",outline:"2px solid #3b82f6",outlineOffset:"-2px"},te={backgroundColor:"#eff6ff"};function J({coord:e,value:o,isSelected:n,isFillTarget:i,showFillHandle:u,onMouseDown:M,onMouseEnter:f,onChange:p,onFillHandleMouseDown:d,styles:D}){const[w,l]=c.useState(!1),[E,h]=c.useState(!1),x=c.useRef(null);c.useEffect(()=>{n&&x.current&&(x.current.focus(),w&&E&&(x.current.select(),h(!1)))},[n,w,E]),c.useEffect(()=>{!n&&w&&l(!1)},[n,w]);const s=a=>{p(e,a.target.value)},y=a=>{a.target.classList.contains("fill-handle")||M(e)},b=()=>{l(!0),h(!0)},m=()=>{l(!1)},T=a=>{w?(a.key==="Enter"||a.key==="Escape")&&l(!1):a.key==="Enter"?(a.preventDefault(),l(!0),h(!0)):a.key.length===1&&!a.ctrlKey&&!a.metaKey&&(a.preventDefault(),p(e,a.key),l(!0))},v=a=>{a.stopPropagation(),a.preventDefault(),d(e)},r=!!D?.selected,H=!!D?.fillTarget,G=!!D?.fillHandle,I={...ee,...n&&!r?ne:{},...i&&!H?te:{}},F={...le,...G?{backgroundColor:void 0}:{}};return k.jsxs("td",{className:L(D?.cell,n&&D?.selected,i&&D?.fillTarget),style:I,onMouseDown:y,onMouseEnter:()=>f(e),onDoubleClick:b,children:[k.jsx("input",{ref:x,type:"text",value:o,readOnly:!w,onChange:s,onBlur:m,onKeyDown:T,style:oe}),u&&k.jsx("div",{className:L("fill-handle",D?.fillHandle),style:F,onMouseDown:v})]})}const re={outline:"none",overflowX:"auto"},se={borderCollapse:"collapse",fontSize:"12px",userSelect:"none"},ce={position:"sticky",left:0,zIndex:10,border:"1px solid #d1d5db",padding:"6px 8px",textAlign:"center",fontWeight:500},ae={border:"1px solid #d1d5db",padding:"6px 4px",textAlign:"center",fontWeight:500},ie={border:"1px solid #d1d5db",padding:"4px",textAlign:"center",fontWeight:500,fontSize:"11px"},ue={backgroundColor:"#f3f4f6"},fe={backgroundColor:"#dbeafe",color:"#1d4ed8"},de={backgroundColor:"#f9fafb"};function we({data:e,onChange:o,rowHeaders:n,colHeaders:i,className:u,rowHeaderTitle:M="",styles:f}){const p=c.useRef(null),d=e.length,D=c.useMemo(()=>i?i.reduce((t,C)=>t+C.headers.length,0):e[0]?.length??0,[i,e]),w=c.useMemo(()=>i?i.flatMap(t=>t.headers):[],[i]),l=c.useMemo(()=>{if(!n)return null;const t=[];return n.forEach((C,S)=>{C.headers.forEach((K,A)=>{t.push({groupIndex:S,isFirstInGroup:A===0,groupLabel:C.label,groupRowCount:C.headers.length,rowHeader:K,groupClassName:C.className,groupDescription:C.description})})}),t},[n]),E=c.useCallback(t=>t.row<0||t.row>=d||t.col<0||t.col>=D?"":e[t.row]?.[t.col]??"",[e,d,D]),h=c.useCallback((t,C)=>{const S=e.map((K,A)=>A===t.row?K.map((R,j)=>j===t.col?C:R):K);o(S)},[e,o]),x=c.useCallback(t=>{if(t.length===0)return;const C=e.map(S=>[...S]);t.forEach(({coord:S,value:K})=>{S.row>=0&&S.row<d&&S.col>=0&&S.col<D&&(C[S.row][S.col]=K)}),o(C)},[e,o,d,D]),{selection:s,isSelecting:y,isCellSelected:b,handleCellMouseDown:m,handleCellMouseEnter:T,setSelection:v}=V({containerRef:p}),{handleKeyDown:r}=W({selection:s,getValue:E,setValues:x,setSelection:v,rowCount:d,colCount:D}),{isDraggingFill:H,isFillTarget:G,handleFillHandleMouseDown:I,handleCellMouseEnterForFill:F}=$({selection:s,getValue:E,setValues:x}),a=c.useCallback(t=>{H?F(t):y&&T(t)},[H,y,F,T]),N=c.useCallback((t,C)=>{h(t,C)},[h]),me=c.useCallback(t=>{if(!s.start)return!1;const C=z(s);return!C.start||!C.end?!1:t.row===C.end.row&&t.col===C.end.col},[s]),B=t=>({...ce,...!t&&!f?.rowHeader?ue:{}}),be=t=>({...ae,...!t&&!f?.colGroup?fe:{}}),Ce=t=>({...ie,...!t&&!f?.colHeader?de:{}});return k.jsx("div",{ref:p,className:u,style:re,tabIndex:0,onKeyDown:r,children:k.jsxs("table",{style:se,children:[k.jsxs("thead",{children:[i&&k.jsxs("tr",{children:[n&&k.jsx("th",{colSpan:2,className:f?.rowHeader,style:B(),children:M}),i.map((t,C)=>k.jsx("th",{colSpan:t.headers.length,className:L(f?.colGroup,t.className),style:be(t.className),title:t.description,children:t.label},C))]}),i&&k.jsxs("tr",{children:[n&&k.jsx("th",{colSpan:2,className:f?.rowHeader,style:B()}),w.map(t=>k.jsx("th",{className:L(f?.colHeader,t.className),style:Ce(t.className),title:t.description,children:t.label},t.key))]})]}),k.jsx("tbody",{children:e.map((t,C)=>{const S=l?.[C];return k.jsxs("tr",{children:[S&&k.jsxs(k.Fragment,{children:[S.isFirstInGroup&&k.jsx("td",{rowSpan:S.groupRowCount,className:L(f?.rowHeader,S.groupClassName),style:B(S.groupClassName),title:S.groupDescription,children:S.groupLabel}),k.jsx("td",{className:L(f?.rowHeader,S.rowHeader.className),style:B(S.rowHeader.className),title:S.rowHeader.description,children:S.rowHeader.label})]}),t.map((K,A)=>{const R={row:C,col:A},j=b(R),ye=G(R),Se=me(R);return k.jsx(J,{coord:R,value:E(R),isSelected:j,isFillTarget:ye,showFillHandle:Se&&!H,onMouseDown:m,onMouseEnter:a,onChange:N,onFillHandleMouseDown:I,styles:f},A)})]},C)})})]})})}function he(e){const o=typeof e=="string"?parseFloat(e.replace(/,/g,"")):e;return isNaN(o)?"0":new Intl.NumberFormat("ko-KR").format(o)}function pe(e){const o=parseInt(e.replace(/,/g,""),10);return isNaN(o)?0:o}g.ExcelGrid=we,g.GridCell=J,g.cn=L,g.coordToKey=X,g.formatCurrency=he,g.getCellsInRange=Q,g.getFillTargetCells=Y,g.isCellInRange=U,g.keyToCoord=_,g.normalizeRange=z,g.parseCurrency=pe,g.parseTSV=q,g.toTSV=O,g.useGridClipboard=W,g.useGridDragFill=$,g.useGridSelection=V,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
package/dist/types.d.ts CHANGED
@@ -28,17 +28,28 @@ export interface ColHeader {
28
28
  export interface ColHeaderGroup {
29
29
  label: string;
30
30
  headers: ColHeader[];
31
+ description?: string;
31
32
  /** Custom class name for this group header */
32
33
  className?: string;
33
34
  }
35
+ /**
36
+ * Row header definition
37
+ */
38
+ export interface RowHeader {
39
+ key: string;
40
+ label: string;
41
+ description?: string;
42
+ /** Custom class name for this header cell */
43
+ className?: string;
44
+ }
34
45
  /**
35
46
  * Row header group
36
47
  */
37
48
  export interface RowHeaderGroup {
38
- key: string;
39
49
  label: string;
50
+ headers: RowHeader[];
40
51
  description?: string;
41
- /** Custom class name for this row header */
52
+ /** Custom class name for this group header */
42
53
  className?: string;
43
54
  }
44
55
  /**
@@ -69,7 +80,7 @@ export interface ExcelGridProps {
69
80
  data: string[][];
70
81
  /** Data change callback */
71
82
  onChange: (data: string[][]) => void;
72
- /** Row header definitions (overridable per row) */
83
+ /** Row header group definitions */
73
84
  rowHeaders?: RowHeaderGroup[];
74
85
  /** Column header group definitions */
75
86
  colHeaders?: ColHeaderGroup[];
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IACxB,GAAG,EAAE,SAAS,GAAG,IAAI,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,SAAS,EAAE,CAAC;IACrB,8CAA8C;IAC9C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,+BAA+B;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+FAA+F;IAC/F,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uFAAuF;IACvF,UAAU,CAAC,EAAE,MAAM,CAAC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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-excel-lite",
3
- "version": "0.0.6",
3
+ "version": "0.1.0",
4
4
  "description": "A lightweight, Excel-like editable grid component for React with cell selection, copy/paste, auto-fill with arithmetic sequence detection, and customizable styling.",
5
5
  "license": "MIT",
6
6
  "type": "module",