react-excel-lite 0.3.0 → 0.4.1

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(x,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],m):(x=typeof globalThis<"u"?globalThis:x||self,m(x.ReactExcelLite={},x.ReactJsxRuntime,x.React))})(this,(function(x,m,r){"use strict";function R(...e){return e.filter(Boolean).join(" ")}function ee(e){return`${e.row}-${e.col}`}function oe(e){const[o,l]=e.split("-").map(Number);return{row:o,col:l}}function ne(e,o){if(!e||!o)return e?[e]:[];const l=Math.min(e.row,o.row),c=Math.max(e.row,o.row),f=Math.min(e.col,o.col),S=Math.max(e.col,o.col),d=[];for(let b=l;b<=c;b++)for(let w=f;w<=S;w++)d.push({row:b,col:w});return d}function P(e,o){if(!o.start)return!1;const l=o.end||o.start,c=Math.min(o.start.row,l.row),f=Math.max(o.start.row,l.row),S=Math.min(o.start.col,l.col),d=Math.max(o.start.col,l.col);return e.row>=c&&e.row<=f&&e.col>=S&&e.col<=d}function $(e){return e.split(/\r?\n/).filter(o=>o.trim()).map(o=>o.split(" ").map(l=>l.trim()))}function J(e){return e.map(o=>o.join(" ")).join(`
2
- `)}function K(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 le(e,o){if(e.row===o.row&&e.col===o.col)return[];const l=Math.min(e.row,o.row),c=Math.max(e.row,o.row),f=Math.min(e.col,o.col),S=Math.max(e.col,o.col),d=[];for(let b=l;b<=c;b++)for(let w=f;w<=S;w++)b===e.row&&w===e.col||d.push({row:b,col:w});return d}function X({containerRef:e}){const[o,l]=r.useState({start:null,end:null}),[c,f]=r.useState(!1),S=r.useCallback(a=>{l({start:a,end:a}),f(!0)},[]),d=r.useCallback(a=>{c&&l(n=>({...n,end:a}))},[c]),b=r.useCallback(()=>{f(!1)},[]),w=r.useCallback(()=>{l({start:null,end:null}),f(!1)},[]),k=r.useCallback(a=>P(a,o),[o]);return r.useEffect(()=>{const a=()=>{c&&f(!1)};return window.addEventListener("mouseup",a),()=>window.removeEventListener("mouseup",a)},[c]),r.useEffect(()=>{const a=n=>{e.current&&!e.current.contains(n.target)&&w()};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[e,w]),{selection:o,isSelecting:c,isCellSelected:k,handleCellMouseDown:S,handleCellMouseEnter:d,handleMouseUp:b,clearSelection:w,setSelection:l}}function _({selection:e,getValue:o,setValues:l,setSelection:c,rowCount:f,colCount:S}){const d=r.useCallback(()=>{const n=K(e);if(!n.start||!n.end)return[];const M=[];for(let p=n.start.row;p<=n.end.row;p++){const D=[];for(let i=n.start.col;i<=n.end.col;i++)D.push(o({row:p,col:i}));M.push(D)}return M},[e,o]),b=r.useCallback(async()=>{const n=d();if(n.length===0)return;const M=J(n);try{await navigator.clipboard.writeText(M)}catch(p){console.error("Clipboard copy failed:",p)}},[d]),w=r.useCallback(async()=>{if(e.start)try{const n=await navigator.clipboard.readText(),M=$(n);if(M.length===0)return;const p=e.start.row,D=e.start.col,i=[];M.forEach((C,u)=>{const h=p+u;h>=f||C.forEach((I,T)=>{const s=D+T;s>=S||i.push({coord:{row:h,col:s},value:I})})}),i.length>0&&l(i)}catch(n){console.error("Clipboard paste failed:",n)}},[e.start,l,f,S]),k=r.useCallback(()=>{const n=K(e);if(!n.start||!n.end)return;const M=[];for(let p=n.start.row;p<=n.end.row;p++)for(let D=n.start.col;D<=n.end.col;D++)M.push({coord:{row:p,col:D},value:""});M.length>0&&l(M)},[e,l]),a=r.useCallback(n=>{if(!(n.target instanceof HTMLInputElement&&!n.target.readOnly)){if(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(n.key)){n.preventDefault();const p=K(e).start??{row:0,col:0};let D=p.row,i=p.col;switch(n.key){case"ArrowUp":D=Math.max(0,p.row-1);break;case"ArrowDown":D=Math.min(f-1,p.row+1);break;case"ArrowLeft":i=Math.max(0,p.col-1);break;case"ArrowRight":i=Math.min(S-1,p.col+1);break}c({start:{row:D,col:i},end:{row:D,col:i}});return}(n.ctrlKey||n.metaKey)&&n.key==="c"&&(n.preventDefault(),b()),(n.ctrlKey||n.metaKey)&&n.key==="v"&&(n.preventDefault(),w()),(n.key==="Backspace"||n.key==="Delete")&&(n.preventDefault(),k())}},[b,w,k,e,c,f,S]);return{handleCopy:b,handlePaste:w,handleKeyDown:a}}function te(e){if(e.trim()==="")return null;const o=Number(e);return isNaN(o)?null:o}function Q(e){if(e.length===0)return null;const o=e.map(te);if(o.some(f=>f===null))return null;const l=o;if(l.length===1)return{numbers:l,diff:0};const c=l[1]-l[0];for(let f=2;f<l.length;f++)if(l[f]-l[f-1]!==c)return{numbers:l,diff:0};return{numbers:l,diff:c}}function Y({selection:e,getValue:o,setValues:l}){const[c,f]=r.useState(null),[S,d]=r.useState([]),[b,w]=r.useState(!1),[k,a]=r.useState(null),n=r.useCallback(i=>{f(i),w(!0),d([]),a(null)},[]),M=r.useCallback(i=>{if(!b||!e.start)return;const C=K(e);if(!C.start||!C.end)return;a(i);const u={row:Math.min(C.start.row,i.row),col:Math.min(C.start.col,i.col)},h={row:Math.max(C.end.row,i.row),col:Math.max(C.end.col,i.col)},I=[];for(let T=u.row;T<=h.row;T++)for(let s=u.col;s<=h.col;s++)T>=C.start.row&&T<=C.end.row&&s>=C.start.col&&s<=C.end.col||I.push({row:T,col:s});d(I)},[b,e]),p=r.useCallback(()=>{if(!e.start||S.length===0||!k){f(null),d([]),w(!1),a(null);return}const i=K(e);if(!i.start||!i.end){f(null),d([]),w(!1),a(null);return}const C=[],u=i.start,h=i.end,I=h.row-u.row+1,T=h.col-u.col+1;S.forEach(s=>{let z,L;if(s.row<u.row){const N=u.row-s.row;z=h.row-(N-1)%I}else if(s.row>h.row){const N=s.row-h.row;z=u.row+(N-1)%I}else z=s.row;if(s.col<u.col){const N=u.col-s.col;L=h.col-(N-1)%T}else if(s.col>h.col){const N=s.col-h.col;L=u.col+(N-1)%T}else L=s.col;let G=o({row:z,col:L});if(s.row!==z&&s.col>=u.col&&s.col<=h.col){const N=[];for(let E=u.row;E<=h.row;E++)N.push(o({row:E,col:s.col}));const F=Q(N);if(F&&F.diff!==0){if(s.row>h.row){const E=s.row-h.row;G=String(F.numbers[F.numbers.length-1]+F.diff*E)}else if(s.row<u.row){const E=u.row-s.row;G=String(F.numbers[0]-F.diff*E)}}}if(s.col!==L&&s.row>=u.row&&s.row<=h.row){const N=[];for(let E=u.col;E<=h.col;E++)N.push(o({row:s.row,col:E}));const F=Q(N);if(F&&F.diff!==0){if(s.col>h.col){const E=s.col-h.col;G=String(F.numbers[F.numbers.length-1]+F.diff*E)}else if(s.col<u.col){const E=u.col-s.col;G=String(F.numbers[0]-F.diff*E)}}}C.push({coord:s,value:G})}),C.length>0&&l(C),f(null),d([]),w(!1),a(null)},[e,S,k,o,l]),D=r.useCallback(i=>S.some(C=>C.row===i.row&&C.col===i.col),[S]);return r.useEffect(()=>{const i=()=>{b&&p()};return window.addEventListener("mouseup",i),()=>window.removeEventListener("mouseup",i)},[b,p]),{fillSource:c,fillTargets:S,isDraggingFill:b,isFillTarget:D,handleFillHandleMouseDown:n,handleCellMouseEnterForFill:M,handleFillMouseUp:p}}const re={position:"relative",border:"1px solid #d1d5db",padding:0,height:"28px",minWidth:"80px"},se={width:"100%",height:"100%",padding:"4px",textAlign:"right",fontSize:"12px",boxSizing:"border-box",cursor:"cell",backgroundColor:"transparent",outline:"none",border:"none"},ie={position:"absolute",bottom:"-2px",right:"-2px",width:"8px",height:"8px",cursor:"crosshair",zIndex:20,backgroundColor:"#3b82f6"},ce={position:"absolute",top:0,left:0,minWidth:"100%",height:"100%",zIndex:30},ae={height:"100%",padding:"4px",textAlign:"right",fontSize:"12px",boxSizing:"border-box",backgroundColor:"#fff",border:"2px solid #3b82f6",outline:"none",minWidth:"100%"},ue={position:"absolute",visibility:"hidden",whiteSpace:"pre",fontSize:"12px",padding:"4px"},fe={backgroundColor:"#dbeafe",outline:"2px solid #3b82f6",outlineOffset:"-2px"},de={backgroundColor:"#eff6ff"};function Z({coord:e,value:o,isSelected:l,isFillTarget:c,showFillHandle:f,onMouseDown:S,onMouseEnter:d,onChange:b,onFillHandleMouseDown:w,styles:k}){const[a,n]=r.useState(!1),[M,p]=r.useState(!1),[D,i]=r.useState(null),C=r.useRef(null),u=r.useRef(null),h=r.useRef(null),I=r.useRef(null);r.useLayoutEffect(()=>{if(a&&h.current&&I.current){const v=h.current.offsetWidth,q=I.current.offsetWidth;i(Math.max(v+16,q))}},[a,o]),r.useEffect(()=>{a&&u.current?(u.current.focus(),M&&(u.current.select(),p(!1))):l&&!a&&C.current&&C.current.focus()},[l,a,M]),r.useEffect(()=>{!l&&a&&(n(!1),i(null))},[l,a]);const T=v=>{b(e,v.target.value)},s=v=>{v.target.classList.contains("fill-handle")||S(e)},z=()=>{n(!0),p(!0)},L=()=>{n(!1)},G=v=>{a?(v.key==="Enter"||v.key==="Escape")&&n(!1):v.key==="Enter"?(v.preventDefault(),n(!0),p(!0)):v.key.length===1&&!v.ctrlKey&&!v.metaKey&&(v.preventDefault(),b(e,v.key),n(!0))},N=v=>{v.stopPropagation(),v.preventDefault(),w(e)},F=!!k?.selected,E=!!k?.fillTarget,j=!!k?.fillHandle,O={...re,...l&&!F?fe:{},...c&&!E?de:{}},U={...ie,...j?{backgroundColor:void 0}:{}},W={...se,overflow:"hidden",textOverflow:"ellipsis"};return m.jsxs("td",{ref:I,className:R(k?.cell,l&&k?.selected,c&&k?.fillTarget),style:O,onMouseDown:s,onMouseEnter:()=>d(e),onDoubleClick:z,children:[m.jsx("input",{ref:C,type:"text",value:o,readOnly:!0,onChange:T,onKeyDown:G,style:W,tabIndex:a?-1:0}),a&&m.jsx("div",{style:ce,children:m.jsx("input",{ref:u,type:"text",value:o,onChange:T,onBlur:L,onKeyDown:G,style:{...ae,width:D??"100%"}})}),a&&m.jsx("span",{ref:h,style:ue,children:o}),f&&m.jsx("div",{className:R("fill-handle",k?.fillHandle),style:U,onMouseDown:N})]})}const we={outline:"none",overflowX:"auto"},he={borderCollapse:"collapse",fontSize:"12px",userSelect:"none"},pe={position:"sticky",left:0,zIndex:10,border:"1px solid #d1d5db",padding:"6px 8px",textAlign:"center",fontWeight:500},me={border:"1px solid #d1d5db",padding:"6px 4px",textAlign:"center",fontWeight:500},be={border:"1px solid #d1d5db",padding:"4px",textAlign:"center",fontWeight:500,fontSize:"11px"},Ce={backgroundColor:"#f3f4f6"},ye={backgroundColor:"#dbeafe",color:"#1d4ed8"},Se={backgroundColor:"#f9fafb"};function ge({data:e,onChange:o,rowHeaders:l,colHeaders:c,className:f,rowHeaderTitle:S="",styles:d}){const b=r.useRef(null),w=e.length,k=r.useMemo(()=>c?c.reduce((t,y)=>t+y.headers.length,0):e[0]?.length??0,[c,e]),a=r.useMemo(()=>c?c.flatMap(t=>t.headers):[],[c]),n=r.useMemo(()=>c?c.some(t=>t.label!==void 0):!1,[c]),M=r.useMemo(()=>l?l.some(t=>t.label!==void 0):!1,[l]),p=r.useMemo(()=>{if(!l)return null;const t=[];return l.forEach((y,g)=>{y.headers.forEach((A,B)=>{t.push({groupIndex:g,isFirstInGroup:B===0,groupLabel:y.label,groupRowCount:y.headers.length,rowHeader:A,groupClassName:y.className,groupDescription:y.description})})}),t},[l]),D=r.useCallback(t=>t.row<0||t.row>=w||t.col<0||t.col>=k?"":e[t.row]?.[t.col]??"",[e,w,k]),i=r.useCallback((t,y)=>{const g=e.map((A,B)=>B===t.row?A.map((H,V)=>V===t.col?y:H):A);o(g)},[e,o]),C=r.useCallback(t=>{if(t.length===0)return;const y=e.map(g=>[...g]);t.forEach(({coord:g,value:A})=>{g.row>=0&&g.row<w&&g.col>=0&&g.col<k&&(y[g.row][g.col]=A)}),o(y)},[e,o,w,k]),{selection:u,isSelecting:h,isCellSelected:I,handleCellMouseDown:T,handleCellMouseEnter:s,setSelection:z}=X({containerRef:b}),{handleKeyDown:L}=_({selection:u,getValue:D,setValues:C,setSelection:z,rowCount:w,colCount:k}),{isDraggingFill:G,isFillTarget:N,handleFillHandleMouseDown:F,handleCellMouseEnterForFill:E}=Y({selection:u,getValue:D,setValues:C}),j=r.useCallback(t=>{G?E(t):h&&s(t)},[G,h,E,s]),O=r.useCallback((t,y)=>{i(t,y)},[i]),U=r.useCallback(t=>{if(!u.start)return!1;const y=K(u);return!y.start||!y.end?!1:t.row===y.end.row&&t.col===y.end.col},[u]),W=t=>({...pe,...!t&&!d?.rowHeader?Ce:{}}),v=t=>({...me,...!t&&!d?.colGroup?ye:{}}),q=t=>({...be,...!t&&!d?.colHeader?Se:{}});return m.jsx("div",{ref:b,className:f,style:we,tabIndex:0,onKeyDown:L,children:m.jsxs("table",{style:he,children:[m.jsxs("thead",{children:[c&&n&&m.jsxs("tr",{children:[l&&m.jsx("th",{colSpan:M?2:1,className:d?.rowHeader,style:W(),children:S}),c.map((t,y)=>m.jsx("th",{colSpan:t.headers.length,className:R(d?.colGroup,t.className),style:v(t.className),title:t.description,children:t.label??""},y))]}),c&&m.jsxs("tr",{children:[l&&m.jsx("th",{colSpan:M?2:1,className:d?.rowHeader,style:W(),children:!n&&S}),a.map(t=>m.jsx("th",{className:R(d?.colHeader,t.className),style:q(t.className),title:t.description,children:t.label},t.key))]})]}),m.jsx("tbody",{children:e.map((t,y)=>{const g=p?.[y];return m.jsxs("tr",{children:[g&&m.jsxs(m.Fragment,{children:[M&&g.isFirstInGroup&&m.jsx("td",{rowSpan:g.groupRowCount,className:R(d?.rowHeader,g.groupClassName),style:W(g.groupClassName),title:g.groupDescription,children:g.groupLabel??""}),m.jsx("td",{className:R(d?.rowHeader,g.rowHeader.className),style:W(g.rowHeader.className),title:g.rowHeader.description,children:g.rowHeader.label})]}),t.map((A,B)=>{const H={row:y,col:B},V=I(H),Me=N(H),De=U(H);return m.jsx(Z,{coord:H,value:D(H),isSelected:V,isFillTarget:Me,showFillHandle:De&&!G,onMouseDown:T,onMouseEnter:j,onChange:O,onFillHandleMouseDown:F,styles:d},B)})]},y)})})]})})}function xe(e){const o=typeof e=="string"?parseFloat(e.replace(/,/g,"")):e;return isNaN(o)?"0":new Intl.NumberFormat("ko-KR").format(o)}function ke(e){const o=parseInt(e.replace(/,/g,""),10);return isNaN(o)?0:o}x.ExcelGrid=ge,x.GridCell=Z,x.cn=R,x.coordToKey=ee,x.formatCurrency=xe,x.getCellsInRange=ne,x.getFillTargetCells=le,x.isCellInRange=P,x.keyToCoord=oe,x.normalizeRange=K,x.parseCurrency=ke,x.parseTSV=$,x.toTSV=J,x.useGridClipboard=_,x.useGridDragFill=Y,x.useGridSelection=X,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(k,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],p):(k=typeof globalThis<"u"?globalThis:k||self,p(k.ReactExcelLite={},k.ReactJsxRuntime,k.React))})(this,(function(k,p,r){"use strict";function R(...e){return e.filter(Boolean).join(" ")}function oe(e){return`${e.row}-${e.col}`}function ne(e){const[n,l]=e.split("-").map(Number);return{row:n,col:l}}function le(e,n){if(!e||!n)return e?[e]:[];const l=Math.min(e.row,n.row),a=Math.max(e.row,n.row),u=Math.min(e.col,n.col),S=Math.max(e.col,n.col),f=[];for(let y=l;y<=a;y++)for(let m=u;m<=S;m++)f.push({row:y,col:m});return f}function $(e,n){if(!n.start)return!1;const l=n.end||n.start,a=Math.min(n.start.row,l.row),u=Math.max(n.start.row,l.row),S=Math.min(n.start.col,l.col),f=Math.max(n.start.col,l.col);return e.row>=a&&e.row<=u&&e.col>=S&&e.col<=f}function J(e){return e.split(/\r?\n/).filter(n=>n.trim()).map(n=>n.split(" ").map(l=>l.trim()))}function X(e){return e.map(n=>n.join(" ")).join(`
2
+ `)}function A(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 te(e,n){if(e.row===n.row&&e.col===n.col)return[];const l=Math.min(e.row,n.row),a=Math.max(e.row,n.row),u=Math.min(e.col,n.col),S=Math.max(e.col,n.col),f=[];for(let y=l;y<=a;y++)for(let m=u;m<=S;m++)y===e.row&&m===e.col||f.push({row:y,col:m});return f}function _({containerRef:e}){const[n,l]=r.useState({start:null,end:null}),[a,u]=r.useState(!1),S=r.useCallback(w=>{l({start:w,end:w}),u(!0)},[]),f=r.useCallback(w=>{a&&l(t=>({...t,end:w}))},[a]),y=r.useCallback(()=>{u(!1)},[]),m=r.useCallback(()=>{l({start:null,end:null}),u(!1)},[]),M=r.useCallback(w=>$(w,n),[n]);return r.useEffect(()=>{const w=()=>{a&&u(!1)};return window.addEventListener("mouseup",w),()=>window.removeEventListener("mouseup",w)},[a]),r.useEffect(()=>{const w=t=>{e.current&&!e.current.contains(t.target)&&m()};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[e,m]),{selection:n,isSelecting:a,isCellSelected:M,handleCellMouseDown:S,handleCellMouseEnter:f,handleMouseUp:y,clearSelection:m,setSelection:l}}function Q({selection:e,getValue:n,setValues:l,setSelection:a,rowCount:u,colCount:S}){const f=r.useCallback(()=>{const t=A(e);if(!t.start||!t.end)return[];const D=[];for(let i=t.start.row;i<=t.end.row;i++){const g=[];for(let c=t.start.col;c<=t.end.col;c++)g.push(n({row:i,col:c}));D.push(g)}return D},[e,n]),y=r.useCallback(async()=>{const t=f();if(t.length===0)return;const D=X(t);try{await navigator.clipboard.writeText(D)}catch(i){console.error("Clipboard copy failed:",i)}},[f]),m=r.useCallback(async()=>{if(e.start)try{const t=await navigator.clipboard.readText(),D=J(t);if(D.length===0)return;const i=e.start.row,g=e.start.col,c=[];D.forEach((b,C)=>{const d=i+C;d>=u||b.forEach((T,N)=>{const s=g+N;s>=S||c.push({coord:{row:d,col:s},value:T})})}),c.length>0&&l(c)}catch(t){console.error("Clipboard paste failed:",t)}},[e.start,l,u,S]),M=r.useCallback(()=>{const t=A(e);if(!t.start||!t.end)return;const D=[];for(let i=t.start.row;i<=t.end.row;i++)for(let g=t.start.col;g<=t.end.col;g++)D.push({coord:{row:i,col:g},value:""});D.length>0&&l(D)},[e,l]),w=r.useCallback(t=>{if(!(t.target instanceof HTMLInputElement&&!t.target.readOnly)){if(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(t.key)){t.preventDefault();const i=A(e).start??{row:0,col:0};let g=i.row,c=i.col;switch(t.key){case"ArrowUp":g=Math.max(0,i.row-1);break;case"ArrowDown":g=Math.min(u-1,i.row+1);break;case"ArrowLeft":c=Math.max(0,i.col-1);break;case"ArrowRight":c=Math.min(S-1,i.col+1);break}a({start:{row:g,col:c},end:{row:g,col:c}});return}(t.ctrlKey||t.metaKey)&&t.key==="c"&&(t.preventDefault(),y()),(t.ctrlKey||t.metaKey)&&t.key==="v"&&(t.preventDefault(),m()),(t.key==="Backspace"||t.key==="Delete")&&(t.preventDefault(),M())}},[y,m,M,e,a,u,S]);return{handleCopy:y,handlePaste:m,handleKeyDown:w}}function re(e){if(e.trim()==="")return null;const n=Number(e);return isNaN(n)?null:n}function Y(e){if(e.length===0)return null;const n=e.map(re);if(n.some(u=>u===null))return null;const l=n;if(l.length===1)return{numbers:l,diff:0};const a=l[1]-l[0];for(let u=2;u<l.length;u++)if(l[u]-l[u-1]!==a)return{numbers:l,diff:0};return{numbers:l,diff:a}}function Z({selection:e,getValue:n,setValues:l}){const[a,u]=r.useState(null),[S,f]=r.useState([]),[y,m]=r.useState(!1),[M,w]=r.useState(null),t=r.useCallback(c=>{u(c),m(!0),f([]),w(null)},[]),D=r.useCallback(c=>{if(!y||!e.start)return;const b=A(e);if(!b.start||!b.end)return;w(c);const C={row:Math.min(b.start.row,c.row),col:Math.min(b.start.col,c.col)},d={row:Math.max(b.end.row,c.row),col:Math.max(b.end.col,c.col)},T=[];for(let N=C.row;N<=d.row;N++)for(let s=C.col;s<=d.col;s++)N>=b.start.row&&N<=b.end.row&&s>=b.start.col&&s<=b.end.col||T.push({row:N,col:s});f(T)},[y,e]),i=r.useCallback(()=>{if(!e.start||S.length===0||!M){u(null),f([]),m(!1),w(null);return}const c=A(e);if(!c.start||!c.end){u(null),f([]),m(!1),w(null);return}const b=[],C=c.start,d=c.end,T=d.row-C.row+1,N=d.col-C.col+1;S.forEach(s=>{let I,G;if(s.row<C.row){const v=C.row-s.row;I=d.row-(v-1)%T}else if(s.row>d.row){const v=s.row-d.row;I=C.row+(v-1)%T}else I=s.row;if(s.col<C.col){const v=C.col-s.col;G=d.col-(v-1)%N}else if(s.col>d.col){const v=s.col-d.col;G=C.col+(v-1)%N}else G=s.col;let L=n({row:I,col:G});if(s.row!==I&&s.col>=C.col&&s.col<=d.col){const v=[];for(let E=C.row;E<=d.row;E++)v.push(n({row:E,col:s.col}));const F=Y(v);if(F&&F.diff!==0){if(s.row>d.row){const E=s.row-d.row;L=String(F.numbers[F.numbers.length-1]+F.diff*E)}else if(s.row<C.row){const E=C.row-s.row;L=String(F.numbers[0]-F.diff*E)}}}if(s.col!==G&&s.row>=C.row&&s.row<=d.row){const v=[];for(let E=C.col;E<=d.col;E++)v.push(n({row:s.row,col:E}));const F=Y(v);if(F&&F.diff!==0){if(s.col>d.col){const E=s.col-d.col;L=String(F.numbers[F.numbers.length-1]+F.diff*E)}else if(s.col<C.col){const E=C.col-s.col;L=String(F.numbers[0]-F.diff*E)}}}b.push({coord:s,value:L})}),b.length>0&&l(b),u(null),f([]),m(!1),w(null)},[e,S,M,n,l]),g=r.useCallback(c=>S.some(b=>b.row===c.row&&b.col===c.col),[S]);return r.useEffect(()=>{const c=()=>{y&&i()};return window.addEventListener("mouseup",c),()=>window.removeEventListener("mouseup",c)},[y,i]),{fillSource:a,fillTargets:S,isDraggingFill:y,isFillTarget:g,handleFillHandleMouseDown:t,handleCellMouseEnterForFill:D,handleFillMouseUp:i}}const se={position:"relative",border:"1px solid #d1d5db",padding:0,height:"28px",minWidth:"80px"},ie={width:"100%",height:"100%",padding:"4px",textAlign:"right",fontSize:"12px",boxSizing:"border-box",cursor:"cell",backgroundColor:"transparent",outline:"none",border:"none"},ce={position:"absolute",bottom:"-2px",right:"-2px",width:"8px",height:"8px",cursor:"crosshair",zIndex:20,backgroundColor:"#3b82f6"},ae={position:"absolute",top:0,minWidth:"100%",height:"100%",zIndex:30},ue={height:"100%",padding:"4px",textAlign:"right",fontSize:"12px",boxSizing:"border-box",backgroundColor:"#fff",border:"2px solid #3b82f6",outline:"none",minWidth:"100%"},fe={position:"absolute",visibility:"hidden",whiteSpace:"pre",fontSize:"12px",padding:"4px"},de={backgroundColor:"#dbeafe",outline:"2px solid #3b82f6",outlineOffset:"-2px"},we={backgroundColor:"#eff6ff"};function ee({coord:e,value:n,isSelected:l,isFillTarget:a,showFillHandle:u,onMouseDown:S,onMouseEnter:f,onChange:y,onFillHandleMouseDown:m,styles:M,cellClassName:w,colCount:t}){const D=e.col>=t/2,[i,g]=r.useState(!1),[c,b]=r.useState(!1),[C,d]=r.useState(null),T=r.useRef(null),N=r.useRef(null),s=r.useRef(null),I=r.useRef(null);r.useLayoutEffect(()=>{if(i&&s.current&&I.current){const o=s.current.offsetWidth,h=I.current.offsetWidth;d(Math.max(o+16,h))}},[i,n]),r.useEffect(()=>{i&&N.current?(N.current.focus(),c&&(N.current.select(),b(!1))):l&&!i&&T.current&&T.current.focus()},[l,i,c]),r.useEffect(()=>{!l&&i&&(g(!1),d(null))},[l,i]);const G=o=>{y(e,o.target.value)},L=o=>{o.target.classList.contains("fill-handle")||S(e)},v=()=>{g(!0),b(!0)},F=()=>{g(!1)},E=o=>{i?(o.key==="Enter"||o.key==="Escape")&&g(!1):o.key==="Enter"?(o.preventDefault(),g(!0),b(!0)):o.key.length===1&&!o.ctrlKey&&!o.metaKey&&(o.preventDefault(),y(e,o.key),g(!0))},W=o=>{o.stopPropagation(),o.preventDefault(),m(e)},j=!!M?.selected,O=!!M?.fillTarget,U=!!M?.fillHandle,H={...se,...l&&!j?de:{},...a&&!O?we:{}},q={...ce,...U?{backgroundColor:void 0}:{}},V={...ie,overflow:"hidden",textOverflow:"ellipsis"};return p.jsxs("td",{ref:I,className:R(M?.cell,l&&M?.selected,a&&M?.fillTarget,w),style:H,onMouseDown:L,onMouseEnter:()=>f(e),onDoubleClick:v,children:[p.jsx("input",{ref:T,type:"text",value:n,readOnly:!0,onChange:G,onKeyDown:E,style:V,tabIndex:i?-1:0}),i&&p.jsx("div",{style:{...ae,...D?{right:0}:{left:0}},children:p.jsx("input",{ref:N,type:"text",value:n,onChange:G,onBlur:F,onKeyDown:E,style:{...ue,width:C??"100%",textAlign:D?"right":"left"}})}),i&&p.jsx("span",{ref:s,style:fe,children:n}),u&&p.jsx("div",{className:R("fill-handle",M?.fillHandle),style:q,onMouseDown:W})]})}const he={outline:"none",overflowX:"auto"},pe={borderCollapse:"collapse",fontSize:"12px",userSelect:"none"},me={position:"sticky",left:0,zIndex:10,border:"1px solid #d1d5db",padding:"6px 8px",textAlign:"center",fontWeight:500},be={border:"1px solid #d1d5db",padding:"6px 4px",textAlign:"center",fontWeight:500},Ce={border:"1px solid #d1d5db",padding:"4px",textAlign:"center",fontWeight:500,fontSize:"11px"},ye={backgroundColor:"#f3f4f6"},Se={backgroundColor:"#dbeafe",color:"#1d4ed8"},ge={backgroundColor:"#f9fafb"};function xe({data:e,onChange:n,rowHeaders:l,colHeaders:a,className:u,rowHeaderTitle:S="",styles:f,cellStyles:y}){const m=r.useRef(null),M=e.length,w=r.useMemo(()=>a?a.reduce((o,h)=>o+h.headers.length,0):e[0]?.length??0,[a,e]),t=r.useMemo(()=>a?a.flatMap(o=>o.headers):[],[a]),D=r.useMemo(()=>a?a.some(o=>o.label!==void 0):!1,[a]),i=r.useMemo(()=>l?l.some(o=>o.label!==void 0):!1,[l]),g=r.useMemo(()=>{if(!l)return null;const o=[];return l.forEach((h,x)=>{h.headers.forEach((K,B)=>{o.push({groupIndex:x,isFirstInGroup:B===0,groupLabel:h.label,groupRowCount:h.headers.length,rowHeader:K,groupClassName:h.className,groupDescription:h.description})})}),o},[l]),c=r.useCallback(o=>o.row<0||o.row>=M||o.col<0||o.col>=w?"":e[o.row]?.[o.col]??"",[e,M,w]),b=r.useCallback((o,h)=>{const x=e.map((K,B)=>B===o.row?K.map((z,P)=>P===o.col?h:z):K);n(x)},[e,n]),C=r.useCallback(o=>{if(o.length===0)return;const h=e.map(x=>[...x]);o.forEach(({coord:x,value:K})=>{x.row>=0&&x.row<M&&x.col>=0&&x.col<w&&(h[x.row][x.col]=K)}),n(h)},[e,n,M,w]),{selection:d,isSelecting:T,isCellSelected:N,handleCellMouseDown:s,handleCellMouseEnter:I,setSelection:G}=_({containerRef:m}),{handleKeyDown:L}=Q({selection:d,getValue:c,setValues:C,setSelection:G,rowCount:M,colCount:w}),{isDraggingFill:v,isFillTarget:F,handleFillHandleMouseDown:E,handleCellMouseEnterForFill:W}=Z({selection:d,getValue:c,setValues:C}),j=r.useCallback(o=>{v?W(o):T&&I(o)},[v,T,W,I]),O=r.useCallback((o,h)=>{b(o,h)},[b]),U=r.useCallback(o=>{if(!d.start)return!1;const h=A(d);return!h.start||!h.end?!1:o.row===h.end.row&&o.col===h.end.col},[d]),H=o=>({...me,...!o&&!f?.rowHeader?ye:{}}),q=o=>({...be,...!o&&!f?.colGroup?Se:{}}),V=o=>({...Ce,...!o&&!f?.colHeader?ge:{}});return p.jsx("div",{ref:m,className:u,style:he,tabIndex:0,onKeyDown:L,children:p.jsxs("table",{style:pe,children:[p.jsxs("thead",{children:[a&&D&&p.jsxs("tr",{children:[l&&p.jsx("th",{colSpan:i?2:1,className:f?.rowHeader,style:H(),children:S}),a.map((o,h)=>p.jsx("th",{colSpan:o.headers.length,className:R(f?.colGroup,o.className),style:q(o.className),title:o.description,children:o.label??""},h))]}),a&&p.jsxs("tr",{children:[l&&p.jsx("th",{colSpan:i?2:1,className:f?.rowHeader,style:H(),children:!D&&S}),t.map(o=>p.jsx("th",{className:R(f?.colHeader,o.className),style:V(o.className),title:o.description,children:o.label},o.key))]})]}),p.jsx("tbody",{children:e.map((o,h)=>{const x=g?.[h];return p.jsxs("tr",{children:[x&&p.jsxs(p.Fragment,{children:[i&&x.isFirstInGroup&&p.jsx("td",{rowSpan:x.groupRowCount,className:R(f?.rowHeader,x.groupClassName),style:H(x.groupClassName),title:x.groupDescription,children:x.groupLabel??""}),p.jsx("td",{className:R(f?.rowHeader,x.rowHeader.className),style:H(x.rowHeader.className),title:x.rowHeader.description,children:x.rowHeader.label})]}),o.map((K,B)=>{const z={row:h,col:B},P=N(z),De=F(z),Ee=U(z),ve=y?.(z);return p.jsx(ee,{coord:z,value:c(z),isSelected:P,isFillTarget:De,showFillHandle:Ee&&!v,onMouseDown:s,onMouseEnter:j,onChange:O,onFillHandleMouseDown:E,styles:f,cellClassName:ve,colCount:w},B)})]},h)})})]})})}function ke(e){const n=typeof e=="string"?parseFloat(e.replace(/,/g,"")):e;return isNaN(n)?"0":new Intl.NumberFormat("ko-KR").format(n)}function Me(e){const n=parseInt(e.replace(/,/g,""),10);return isNaN(n)?0:n}k.ExcelGrid=xe,k.GridCell=ee,k.cn=R,k.coordToKey=oe,k.formatCurrency=ke,k.getCellsInRange=le,k.getFillTargetCells=te,k.isCellInRange=$,k.keyToCoord=ne,k.normalizeRange=A,k.parseCurrency=Me,k.parseTSV=J,k.toTSV=X,k.useGridClipboard=Q,k.useGridDragFill=Z,k.useGridSelection=_,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})}));
package/dist/types.d.ts CHANGED
@@ -70,6 +70,8 @@ export interface ExcelGridProps {
70
70
  rowHeaderTitle?: string;
71
71
  /** Style configuration */
72
72
  styles?: GridStyles;
73
+ /** Function to apply custom className to specific cells */
74
+ cellStyles?: (coord: CellCoord) => string | undefined;
73
75
  }
74
76
  /**
75
77
  * Cell component Props
@@ -86,5 +88,9 @@ export interface GridCellProps {
86
88
  onFillHandleMouseDown: (coord: CellCoord) => void;
87
89
  /** Cell styles */
88
90
  styles?: Pick<GridStyles, "cell" | "selected" | "fillTarget" | "fillHandle">;
91
+ /** Custom className for this specific cell */
92
+ cellClassName?: string;
93
+ /** Total column count (used for determining input expansion direction) */
94
+ colCount: number;
89
95
  }
90
96
  //# sourceMappingURL=types.d.ts.map
@@ -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,MAAM;IACrB,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,WAAW;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8CAA8C;IAC9C,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;IACpB,yCAA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AmC;IACnC,UAAU,CAAC,EAAE,WAAW,EAAE,CAAC;IAC3B,sCAAsC;IACtC,UAAU,CAAC,EAAE,WAAW,EAAE,CAAC;IAC3B,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8BAA8B;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,0BAA0B;IAC1B,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,2DAA2D;IAC3D,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,MAAM,GAAG,SAAS,CAAC;CACvD;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,OAAO,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC;IACxB,WAAW,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;IACxC,YAAY,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;IACzC,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACpD,qBAAqB,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;IAClD,kBAAkB;IAClB,MAAM,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,GAAG,YAAY,GAAG,YAAY,CAAC,CAAC;IAC7E,8CAA8C;IAC9C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,0EAA0E;IAC1E,QAAQ,EAAE,MAAM,CAAC;CAClB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-excel-lite",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
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",