react-excel-lite 0.2.0 → 0.3.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(g,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],b):(g=typeof globalThis<"u"?globalThis:g||self,b(g.ReactExcelLite={},g.ReactJsxRuntime,g.React))})(this,(function(g,b,r){"use strict";function G(...e){return e.filter(Boolean).join(" ")}function Y(e){return`${e.row}-${e.col}`}function Z(e){const[n,t]=e.split("-").map(Number);return{row:n,col:t}}function ee(e,n){if(!e||!n)return e?[e]:[];const t=Math.min(e.row,n.row),a=Math.max(e.row,n.row),u=Math.min(e.col,n.col),x=Math.max(e.col,n.col),f=[];for(let C=t;C<=a;C++)for(let d=u;d<=x;d++)f.push({row:C,col:d});return f}function q(e,n){if(!n.start)return!1;const t=n.end||n.start,a=Math.min(n.start.row,t.row),u=Math.max(n.start.row,t.row),x=Math.min(n.start.col,t.col),f=Math.max(n.start.col,t.col);return e.row>=a&&e.row<=u&&e.col>=x&&e.col<=f}function V(e){return e.split(/\r?\n/).filter(n=>n.trim()).map(n=>n.split(" ").map(t=>t.trim()))}function P(e){return e.map(n=>n.join(" ")).join(`
2
- `)}function L(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 oe(e,n){if(e.row===n.row&&e.col===n.col)return[];const t=Math.min(e.row,n.row),a=Math.max(e.row,n.row),u=Math.min(e.col,n.col),x=Math.max(e.col,n.col),f=[];for(let C=t;C<=a;C++)for(let d=u;d<=x;d++)C===e.row&&d===e.col||f.push({row:C,col:d});return f}function $({containerRef:e}){const[n,t]=r.useState({start:null,end:null}),[a,u]=r.useState(!1),x=r.useCallback(i=>{t({start:i,end:i}),u(!0)},[]),f=r.useCallback(i=>{a&&t(l=>({...l,end:i}))},[a]),C=r.useCallback(()=>{u(!1)},[]),d=r.useCallback(()=>{t({start:null,end:null}),u(!1)},[]),k=r.useCallback(i=>q(i,n),[n]);return r.useEffect(()=>{const i=()=>{a&&u(!1)};return window.addEventListener("mouseup",i),()=>window.removeEventListener("mouseup",i)},[a]),r.useEffect(()=>{const i=l=>{e.current&&!e.current.contains(l.target)&&d()};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[e,d]),{selection:n,isSelecting:a,isCellSelected:k,handleCellMouseDown:x,handleCellMouseEnter:f,handleMouseUp:C,clearSelection:d,setSelection:t}}function J({selection:e,getValue:n,setValues:t,setSelection:a,rowCount:u,colCount:x}){const f=r.useCallback(()=>{const l=L(e);if(!l.start||!l.end)return[];const M=[];for(let w=l.start.row;w<=l.end.row;w++){const D=[];for(let s=l.start.col;s<=l.end.col;s++)D.push(n({row:w,col:s}));M.push(D)}return M},[e,n]),C=r.useCallback(async()=>{const l=f();if(l.length===0)return;const M=P(l);try{await navigator.clipboard.writeText(M)}catch(w){console.error("Clipboard copy failed:",w)}},[f]),d=r.useCallback(async()=>{if(e.start)try{const l=await navigator.clipboard.readText(),M=V(l);if(M.length===0)return;const w=e.start.row,D=e.start.col,s=[];M.forEach((y,h)=>{const p=w+h;p>=u||y.forEach((T,N)=>{const c=D+N;c>=x||s.push({coord:{row:p,col:c},value:T})})}),s.length>0&&t(s)}catch(l){console.error("Clipboard paste failed:",l)}},[e.start,t,u,x]),k=r.useCallback(()=>{const l=L(e);if(!l.start||!l.end)return;const M=[];for(let w=l.start.row;w<=l.end.row;w++)for(let D=l.start.col;D<=l.end.col;D++)M.push({coord:{row:w,col:D},value:""});M.length>0&&t(M)},[e,t]),i=r.useCallback(l=>{if(!(l.target instanceof HTMLInputElement&&!l.target.readOnly)){if(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(l.key)){l.preventDefault();const w=L(e).start??{row:0,col:0};let D=w.row,s=w.col;switch(l.key){case"ArrowUp":D=Math.max(0,w.row-1);break;case"ArrowDown":D=Math.min(u-1,w.row+1);break;case"ArrowLeft":s=Math.max(0,w.col-1);break;case"ArrowRight":s=Math.min(x-1,w.col+1);break}a({start:{row:D,col:s},end:{row:D,col:s}});return}(l.ctrlKey||l.metaKey)&&l.key==="c"&&(l.preventDefault(),C()),(l.ctrlKey||l.metaKey)&&l.key==="v"&&(l.preventDefault(),d()),(l.key==="Backspace"||l.key==="Delete")&&(l.preventDefault(),k())}},[C,d,k,e,a,u,x]);return{handleCopy:C,handlePaste:d,handleKeyDown:i}}function ne(e){if(e.trim()==="")return null;const n=Number(e);return isNaN(n)?null:n}function X(e){if(e.length===0)return null;const n=e.map(ne);if(n.some(u=>u===null))return null;const t=n;if(t.length===1)return{numbers:t,diff:0};const a=t[1]-t[0];for(let u=2;u<t.length;u++)if(t[u]-t[u-1]!==a)return{numbers:t,diff:0};return{numbers:t,diff:a}}function _({selection:e,getValue:n,setValues:t}){const[a,u]=r.useState(null),[x,f]=r.useState([]),[C,d]=r.useState(!1),[k,i]=r.useState(null),l=r.useCallback(s=>{u(s),d(!0),f([]),i(null)},[]),M=r.useCallback(s=>{if(!C||!e.start)return;const y=L(e);if(!y.start||!y.end)return;i(s);const h={row:Math.min(y.start.row,s.row),col:Math.min(y.start.col,s.col)},p={row:Math.max(y.end.row,s.row),col:Math.max(y.end.col,s.col)},T=[];for(let N=h.row;N<=p.row;N++)for(let c=h.col;c<=p.col;c++)N>=y.start.row&&N<=y.end.row&&c>=y.start.col&&c<=y.end.col||T.push({row:N,col:c});f(T)},[C,e]),w=r.useCallback(()=>{if(!e.start||x.length===0||!k){u(null),f([]),d(!1),i(null);return}const s=L(e);if(!s.start||!s.end){u(null),f([]),d(!1),i(null);return}const y=[],h=s.start,p=s.end,T=p.row-h.row+1,N=p.col-h.col+1;x.forEach(c=>{let I,z;if(c.row<h.row){const F=h.row-c.row;I=p.row-(F-1)%T}else if(c.row>p.row){const F=c.row-p.row;I=h.row+(F-1)%T}else I=c.row;if(c.col<h.col){const F=h.col-c.col;z=p.col-(F-1)%N}else if(c.col>p.col){const F=c.col-p.col;z=h.col+(F-1)%N}else z=c.col;let H=n({row:I,col:z});if(c.row!==I&&c.col>=h.col&&c.col<=p.col){const F=[];for(let v=h.row;v<=p.row;v++)F.push(n({row:v,col:c.col}));const E=X(F);if(E&&E.diff!==0){if(c.row>p.row){const v=c.row-p.row;H=String(E.numbers[E.numbers.length-1]+E.diff*v)}else if(c.row<h.row){const v=h.row-c.row;H=String(E.numbers[0]-E.diff*v)}}}if(c.col!==z&&c.row>=h.row&&c.row<=p.row){const F=[];for(let v=h.col;v<=p.col;v++)F.push(n({row:c.row,col:v}));const E=X(F);if(E&&E.diff!==0){if(c.col>p.col){const v=c.col-p.col;H=String(E.numbers[E.numbers.length-1]+E.diff*v)}else if(c.col<h.col){const v=h.col-c.col;H=String(E.numbers[0]-E.diff*v)}}}y.push({coord:c,value:H})}),y.length>0&&t(y),u(null),f([]),d(!1),i(null)},[e,x,k,n,t]),D=r.useCallback(s=>x.some(y=>y.row===s.row&&y.col===s.col),[x]);return r.useEffect(()=>{const s=()=>{C&&w()};return window.addEventListener("mouseup",s),()=>window.removeEventListener("mouseup",s)},[C,w]),{fillSource:a,fillTargets:x,isDraggingFill:C,isFillTarget:D,handleFillHandleMouseDown:l,handleCellMouseEnterForFill:M,handleFillMouseUp:w}}const le={position:"relative",border:"1px solid #d1d5db",padding:0,height:"28px",minWidth:"80px"},te={width:"100%",height:"100%",padding:"4px",textAlign:"right",fontSize:"12px",boxSizing:"border-box",cursor:"cell",backgroundColor:"transparent",outline:"none",border:"none"},re={position:"absolute",bottom:"-2px",right:"-2px",width:"8px",height:"8px",cursor:"crosshair",zIndex:20,backgroundColor:"#3b82f6"},se={position:"absolute",top:0,left:0,minWidth:"100%",height:"100%",zIndex:30},ce={height:"100%",padding:"4px",textAlign:"right",fontSize:"12px",boxSizing:"border-box",backgroundColor:"#fff",border:"2px solid #3b82f6",outline:"none",minWidth:"100%"},ie={position:"absolute",visibility:"hidden",whiteSpace:"pre",fontSize:"12px",padding:"4px"},ae={backgroundColor:"#dbeafe",outline:"2px solid #3b82f6",outlineOffset:"-2px"},ue={backgroundColor:"#eff6ff"};function Q({coord:e,value:n,isSelected:t,isFillTarget:a,showFillHandle:u,onMouseDown:x,onMouseEnter:f,onChange:C,onFillHandleMouseDown:d,styles:k}){const[i,l]=r.useState(!1),[M,w]=r.useState(!1),[D,s]=r.useState(null),y=r.useRef(null),h=r.useRef(null),p=r.useRef(null),T=r.useRef(null);r.useLayoutEffect(()=>{if(i&&p.current&&T.current){const o=p.current.offsetWidth,m=T.current.offsetWidth;s(Math.max(o+16,m))}},[i,n]),r.useEffect(()=>{i&&h.current?(h.current.focus(),M&&(h.current.select(),w(!1))):t&&!i&&y.current&&y.current.focus()},[t,i,M]),r.useEffect(()=>{!t&&i&&(l(!1),s(null))},[t,i]);const N=o=>{C(e,o.target.value)},c=o=>{o.target.classList.contains("fill-handle")||x(e)},I=()=>{l(!0),w(!0)},z=()=>{l(!1)},H=o=>{i?(o.key==="Enter"||o.key==="Escape")&&l(!1):o.key==="Enter"?(o.preventDefault(),l(!0),w(!0)):o.key.length===1&&!o.ctrlKey&&!o.metaKey&&(o.preventDefault(),C(e,o.key),l(!0))},F=o=>{o.stopPropagation(),o.preventDefault(),d(e)},E=!!k?.selected,v=!!k?.fillTarget,B=!!k?.fillHandle,A={...le,...t&&!E?ae:{},...a&&!v?ue:{}},j={...re,...B?{backgroundColor:void 0}:{}},O={...te,overflow:"hidden",textOverflow:"ellipsis"};return b.jsxs("td",{ref:T,className:G(k?.cell,t&&k?.selected,a&&k?.fillTarget),style:A,onMouseDown:c,onMouseEnter:()=>f(e),onDoubleClick:I,children:[b.jsx("input",{ref:y,type:"text",value:n,readOnly:!0,onChange:N,onKeyDown:H,style:O,tabIndex:i?-1:0}),i&&b.jsx("div",{style:se,children:b.jsx("input",{ref:h,type:"text",value:n,onChange:N,onBlur:z,onKeyDown:H,style:{...ce,width:D??"100%"}})}),i&&b.jsx("span",{ref:p,style:ie,children:n}),u&&b.jsx("div",{className:G("fill-handle",k?.fillHandle),style:j,onMouseDown:F})]})}const fe={outline:"none",overflowX:"auto"},de={borderCollapse:"collapse",fontSize:"12px",userSelect:"none"},we={position:"sticky",left:0,zIndex:10,border:"1px solid #d1d5db",padding:"6px 8px",textAlign:"center",fontWeight:500},he={border:"1px solid #d1d5db",padding:"6px 4px",textAlign:"center",fontWeight:500},pe={border:"1px solid #d1d5db",padding:"4px",textAlign:"center",fontWeight:500,fontSize:"11px"},me={backgroundColor:"#f3f4f6"},be={backgroundColor:"#dbeafe",color:"#1d4ed8"},Ce={backgroundColor:"#f9fafb"};function ye({data:e,onChange:n,rowHeaders:t,colHeaders:a,className:u,rowHeaderTitle:x="",styles:f}){const C=r.useRef(null),d=e.length,k=r.useMemo(()=>a?a.reduce((o,m)=>o+m.headers.length,0):e[0]?.length??0,[a,e]),i=r.useMemo(()=>a?a.flatMap(o=>o.headers):[],[a]),l=r.useMemo(()=>{if(!t)return null;const o=[];return t.forEach((m,S)=>{m.headers.forEach((R,W)=>{o.push({groupIndex:S,isFirstInGroup:W===0,groupLabel:m.label,groupRowCount:m.headers.length,rowHeader:R,groupClassName:m.className,groupDescription:m.description})})}),o},[t]),M=r.useCallback(o=>o.row<0||o.row>=d||o.col<0||o.col>=k?"":e[o.row]?.[o.col]??"",[e,d,k]),w=r.useCallback((o,m)=>{const S=e.map((R,W)=>W===o.row?R.map((K,U)=>U===o.col?m:K):R);n(S)},[e,n]),D=r.useCallback(o=>{if(o.length===0)return;const m=e.map(S=>[...S]);o.forEach(({coord:S,value:R})=>{S.row>=0&&S.row<d&&S.col>=0&&S.col<k&&(m[S.row][S.col]=R)}),n(m)},[e,n,d,k]),{selection:s,isSelecting:y,isCellSelected:h,handleCellMouseDown:p,handleCellMouseEnter:T,setSelection:N}=$({containerRef:C}),{handleKeyDown:c}=J({selection:s,getValue:M,setValues:D,setSelection:N,rowCount:d,colCount:k}),{isDraggingFill:I,isFillTarget:z,handleFillHandleMouseDown:H,handleCellMouseEnterForFill:F}=_({selection:s,getValue:M,setValues:D}),E=r.useCallback(o=>{I?F(o):y&&T(o)},[I,y,F,T]),v=r.useCallback((o,m)=>{w(o,m)},[w]),B=r.useCallback(o=>{if(!s.start)return!1;const m=L(s);return!m.start||!m.end?!1:o.row===m.end.row&&o.col===m.end.col},[s]),A=o=>({...we,...!o&&!f?.rowHeader?me:{}}),j=o=>({...he,...!o&&!f?.colGroup?be:{}}),O=o=>({...pe,...!o&&!f?.colHeader?Ce:{}});return b.jsx("div",{ref:C,className:u,style:fe,tabIndex:0,onKeyDown:c,children:b.jsxs("table",{style:de,children:[b.jsxs("thead",{children:[a&&b.jsxs("tr",{children:[t&&b.jsx("th",{colSpan:2,className:f?.rowHeader,style:A(),children:x}),a.map((o,m)=>b.jsx("th",{colSpan:o.headers.length,className:G(f?.colGroup,o.className),style:j(o.className),title:o.description,children:o.label},m))]}),a&&b.jsxs("tr",{children:[t&&b.jsx("th",{colSpan:2,className:f?.rowHeader,style:A()}),i.map(o=>b.jsx("th",{className:G(f?.colHeader,o.className),style:O(o.className),title:o.description,children:o.label},o.key))]})]}),b.jsx("tbody",{children:e.map((o,m)=>{const S=l?.[m];return b.jsxs("tr",{children:[S&&b.jsxs(b.Fragment,{children:[S.isFirstInGroup&&b.jsx("td",{rowSpan:S.groupRowCount,className:G(f?.rowHeader,S.groupClassName),style:A(S.groupClassName),title:S.groupDescription,children:S.groupLabel}),b.jsx("td",{className:G(f?.rowHeader,S.rowHeader.className),style:A(S.rowHeader.className),title:S.rowHeader.description,children:S.rowHeader.label})]}),o.map((R,W)=>{const K={row:m,col:W},U=h(K),xe=z(K),ke=B(K);return b.jsx(Q,{coord:K,value:M(K),isSelected:U,isFillTarget:xe,showFillHandle:ke&&!I,onMouseDown:p,onMouseEnter:E,onChange:v,onFillHandleMouseDown:H,styles:f},W)})]},m)})})]})})}function Se(e){const n=typeof e=="string"?parseFloat(e.replace(/,/g,"")):e;return isNaN(n)?"0":new Intl.NumberFormat("ko-KR").format(n)}function ge(e){const n=parseInt(e.replace(/,/g,""),10);return isNaN(n)?0:n}g.ExcelGrid=ye,g.GridCell=Q,g.cn=G,g.coordToKey=Y,g.formatCurrency=Se,g.getCellsInRange=ee,g.getFillTargetCells=oe,g.isCellInRange=q,g.keyToCoord=Z,g.normalizeRange=L,g.parseCurrency=ge,g.parseTSV=V,g.toTSV=P,g.useGridClipboard=J,g.useGridDragFill=_,g.useGridSelection=$,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
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"})}));
package/dist/types.d.ts CHANGED
@@ -26,7 +26,7 @@ export interface Header {
26
26
  * Header group
27
27
  */
28
28
  export interface HeaderGroup {
29
- label: string;
29
+ label?: string;
30
30
  headers: Header[];
31
31
  description?: string;
32
32
  /** Custom class name for this group header */
@@ -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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,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;CAC9E"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-excel-lite",
3
- "version": "0.2.0",
3
+ "version": "0.3.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",