react-excel-lite 0.3.0 → 0.4.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.
- package/README.md +102 -25
- package/dist/components/excel-grid.d.ts +1 -1
- package/dist/components/excel-grid.d.ts.map +1 -1
- package/dist/components/grid-cell.d.ts +1 -1
- package/dist/components/grid-cell.d.ts.map +1 -1
- package/dist/react-excel-lite.js +344 -340
- package/dist/react-excel-lite.umd.cjs +2 -2
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(
|
|
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 K(...e){return e.filter(Boolean).join(" ")}function oe(e){return`${e.row}-${e.col}`}function ne(e){const[o,l]=e.split("-").map(Number);return{row:o,col:l}}function le(e,o){if(!e||!o)return e?[e]:[];const l=Math.min(e.row,o.row),i=Math.max(e.row,o.row),u=Math.min(e.col,o.col),S=Math.max(e.col,o.col),f=[];for(let b=l;b<=i;b++)for(let m=u;m<=S;m++)f.push({row:b,col:m});return f}function $(e,o){if(!o.start)return!1;const l=o.end||o.start,i=Math.min(o.start.row,l.row),u=Math.max(o.start.row,l.row),S=Math.min(o.start.col,l.col),f=Math.max(o.start.col,l.col);return e.row>=i&&e.row<=u&&e.col>=S&&e.col<=f}function J(e){return e.split(/\r?\n/).filter(o=>o.trim()).map(o=>o.split(" ").map(l=>l.trim()))}function X(e){return e.map(o=>o.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,o){if(e.row===o.row&&e.col===o.col)return[];const l=Math.min(e.row,o.row),i=Math.max(e.row,o.row),u=Math.min(e.col,o.col),S=Math.max(e.col,o.col),f=[];for(let b=l;b<=i;b++)for(let m=u;m<=S;m++)b===e.row&&m===e.col||f.push({row:b,col:m});return f}function _({containerRef:e}){const[o,l]=r.useState({start:null,end:null}),[i,u]=r.useState(!1),S=r.useCallback(w=>{l({start:w,end:w}),u(!0)},[]),f=r.useCallback(w=>{i&&l(n=>({...n,end:w}))},[i]),b=r.useCallback(()=>{u(!1)},[]),m=r.useCallback(()=>{l({start:null,end:null}),u(!1)},[]),M=r.useCallback(w=>$(w,o),[o]);return r.useEffect(()=>{const w=()=>{i&&u(!1)};return window.addEventListener("mouseup",w),()=>window.removeEventListener("mouseup",w)},[i]),r.useEffect(()=>{const w=n=>{e.current&&!e.current.contains(n.target)&&m()};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[e,m]),{selection:o,isSelecting:i,isCellSelected:M,handleCellMouseDown:S,handleCellMouseEnter:f,handleMouseUp:b,clearSelection:m,setSelection:l}}function Q({selection:e,getValue:o,setValues:l,setSelection:i,rowCount:u,colCount:S}){const f=r.useCallback(()=>{const n=A(e);if(!n.start||!n.end)return[];const g=[];for(let d=n.start.row;d<=n.end.row;d++){const D=[];for(let c=n.start.col;c<=n.end.col;c++)D.push(o({row:d,col:c}));g.push(D)}return g},[e,o]),b=r.useCallback(async()=>{const n=f();if(n.length===0)return;const g=X(n);try{await navigator.clipboard.writeText(g)}catch(d){console.error("Clipboard copy failed:",d)}},[f]),m=r.useCallback(async()=>{if(e.start)try{const n=await navigator.clipboard.readText(),g=J(n);if(g.length===0)return;const d=e.start.row,D=e.start.col,c=[];g.forEach((C,h)=>{const a=d+h;a>=u||C.forEach((I,T)=>{const s=D+T;s>=S||c.push({coord:{row:a,col:s},value:I})})}),c.length>0&&l(c)}catch(n){console.error("Clipboard paste failed:",n)}},[e.start,l,u,S]),M=r.useCallback(()=>{const n=A(e);if(!n.start||!n.end)return;const g=[];for(let d=n.start.row;d<=n.end.row;d++)for(let D=n.start.col;D<=n.end.col;D++)g.push({coord:{row:d,col:D},value:""});g.length>0&&l(g)},[e,l]),w=r.useCallback(n=>{if(!(n.target instanceof HTMLInputElement&&!n.target.readOnly)){if(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(n.key)){n.preventDefault();const d=A(e).start??{row:0,col:0};let D=d.row,c=d.col;switch(n.key){case"ArrowUp":D=Math.max(0,d.row-1);break;case"ArrowDown":D=Math.min(u-1,d.row+1);break;case"ArrowLeft":c=Math.max(0,d.col-1);break;case"ArrowRight":c=Math.min(S-1,d.col+1);break}i({start:{row:D,col:c},end:{row:D,col:c}});return}(n.ctrlKey||n.metaKey)&&n.key==="c"&&(n.preventDefault(),b()),(n.ctrlKey||n.metaKey)&&n.key==="v"&&(n.preventDefault(),m()),(n.key==="Backspace"||n.key==="Delete")&&(n.preventDefault(),M())}},[b,m,M,e,i,u,S]);return{handleCopy:b,handlePaste:m,handleKeyDown:w}}function re(e){if(e.trim()==="")return null;const o=Number(e);return isNaN(o)?null:o}function Y(e){if(e.length===0)return null;const o=e.map(re);if(o.some(u=>u===null))return null;const l=o;if(l.length===1)return{numbers:l,diff:0};const i=l[1]-l[0];for(let u=2;u<l.length;u++)if(l[u]-l[u-1]!==i)return{numbers:l,diff:0};return{numbers:l,diff:i}}function Z({selection:e,getValue:o,setValues:l}){const[i,u]=r.useState(null),[S,f]=r.useState([]),[b,m]=r.useState(!1),[M,w]=r.useState(null),n=r.useCallback(c=>{u(c),m(!0),f([]),w(null)},[]),g=r.useCallback(c=>{if(!b||!e.start)return;const C=A(e);if(!C.start||!C.end)return;w(c);const h={row:Math.min(C.start.row,c.row),col:Math.min(C.start.col,c.col)},a={row:Math.max(C.end.row,c.row),col:Math.max(C.end.col,c.col)},I=[];for(let T=h.row;T<=a.row;T++)for(let s=h.col;s<=a.col;s++)T>=C.start.row&&T<=C.end.row&&s>=C.start.col&&s<=C.end.col||I.push({row:T,col:s});f(I)},[b,e]),d=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 C=[],h=c.start,a=c.end,I=a.row-h.row+1,T=a.col-h.col+1;S.forEach(s=>{let G,z;if(s.row<h.row){const E=h.row-s.row;G=a.row-(E-1)%I}else if(s.row>a.row){const E=s.row-a.row;G=h.row+(E-1)%I}else G=s.row;if(s.col<h.col){const E=h.col-s.col;z=a.col-(E-1)%T}else if(s.col>a.col){const E=s.col-a.col;z=h.col+(E-1)%T}else z=s.col;let L=o({row:G,col:z});if(s.row!==G&&s.col>=h.col&&s.col<=a.col){const E=[];for(let N=h.row;N<=a.row;N++)E.push(o({row:N,col:s.col}));const F=Y(E);if(F&&F.diff!==0){if(s.row>a.row){const N=s.row-a.row;L=String(F.numbers[F.numbers.length-1]+F.diff*N)}else if(s.row<h.row){const N=h.row-s.row;L=String(F.numbers[0]-F.diff*N)}}}if(s.col!==z&&s.row>=h.row&&s.row<=a.row){const E=[];for(let N=h.col;N<=a.col;N++)E.push(o({row:s.row,col:N}));const F=Y(E);if(F&&F.diff!==0){if(s.col>a.col){const N=s.col-a.col;L=String(F.numbers[F.numbers.length-1]+F.diff*N)}else if(s.col<h.col){const N=h.col-s.col;L=String(F.numbers[0]-F.diff*N)}}}C.push({coord:s,value:L})}),C.length>0&&l(C),u(null),f([]),m(!1),w(null)},[e,S,M,o,l]),D=r.useCallback(c=>S.some(C=>C.row===c.row&&C.col===c.col),[S]);return r.useEffect(()=>{const c=()=>{b&&d()};return window.addEventListener("mouseup",c),()=>window.removeEventListener("mouseup",c)},[b,d]),{fillSource:i,fillTargets:S,isDraggingFill:b,isFillTarget:D,handleFillHandleMouseDown:n,handleCellMouseEnterForFill:g,handleFillMouseUp:d}}const se={position:"relative",border:"1px solid #d1d5db",padding:0,height:"28px",minWidth:"80px"},ce={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"},ae={position:"absolute",top:0,left: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:o,isSelected:l,isFillTarget:i,showFillHandle:u,onMouseDown:S,onMouseEnter:f,onChange:b,onFillHandleMouseDown:m,styles:M,cellClassName:w}){const[n,g]=r.useState(!1),[d,D]=r.useState(!1),[c,C]=r.useState(null),h=r.useRef(null),a=r.useRef(null),I=r.useRef(null),T=r.useRef(null);r.useLayoutEffect(()=>{if(n&&I.current&&T.current){const v=I.current.offsetWidth,V=T.current.offsetWidth;C(Math.max(v+16,V))}},[n,o]),r.useEffect(()=>{n&&a.current?(a.current.focus(),d&&(a.current.select(),D(!1))):l&&!n&&h.current&&h.current.focus()},[l,n,d]),r.useEffect(()=>{!l&&n&&(g(!1),C(null))},[l,n]);const s=v=>{b(e,v.target.value)},G=v=>{v.target.classList.contains("fill-handle")||S(e)},z=()=>{g(!0),D(!0)},L=()=>{g(!1)},E=v=>{n?(v.key==="Enter"||v.key==="Escape")&&g(!1):v.key==="Enter"?(v.preventDefault(),g(!0),D(!0)):v.key.length===1&&!v.ctrlKey&&!v.metaKey&&(v.preventDefault(),b(e,v.key),g(!0))},F=v=>{v.stopPropagation(),v.preventDefault(),m(e)},N=!!M?.selected,j=!!M?.fillTarget,O=!!M?.fillHandle,U={...se,...l&&!N?de:{},...i&&!j?we:{}},q={...ie,...O?{backgroundColor:void 0}:{}},W={...ce,overflow:"hidden",textOverflow:"ellipsis"};return p.jsxs("td",{ref:T,className:K(M?.cell,l&&M?.selected,i&&M?.fillTarget,w),style:U,onMouseDown:G,onMouseEnter:()=>f(e),onDoubleClick:z,children:[p.jsx("input",{ref:h,type:"text",value:o,readOnly:!0,onChange:s,onKeyDown:E,style:W,tabIndex:n?-1:0}),n&&p.jsx("div",{style:ae,children:p.jsx("input",{ref:a,type:"text",value:o,onChange:s,onBlur:L,onKeyDown:E,style:{...ue,width:c??"100%"}})}),n&&p.jsx("span",{ref:I,style:fe,children:o}),u&&p.jsx("div",{className:K("fill-handle",M?.fillHandle),style:q,onMouseDown:F})]})}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:o,rowHeaders:l,colHeaders:i,className:u,rowHeaderTitle:S="",styles:f,cellStyles:b}){const m=r.useRef(null),M=e.length,w=r.useMemo(()=>i?i.reduce((t,y)=>t+y.headers.length,0):e[0]?.length??0,[i,e]),n=r.useMemo(()=>i?i.flatMap(t=>t.headers):[],[i]),g=r.useMemo(()=>i?i.some(t=>t.label!==void 0):!1,[i]),d=r.useMemo(()=>l?l.some(t=>t.label!==void 0):!1,[l]),D=r.useMemo(()=>{if(!l)return null;const t=[];return l.forEach((y,x)=>{y.headers.forEach((H,B)=>{t.push({groupIndex:x,isFirstInGroup:B===0,groupLabel:y.label,groupRowCount:y.headers.length,rowHeader:H,groupClassName:y.className,groupDescription:y.description})})}),t},[l]),c=r.useCallback(t=>t.row<0||t.row>=M||t.col<0||t.col>=w?"":e[t.row]?.[t.col]??"",[e,M,w]),C=r.useCallback((t,y)=>{const x=e.map((H,B)=>B===t.row?H.map((R,P)=>P===t.col?y:R):H);o(x)},[e,o]),h=r.useCallback(t=>{if(t.length===0)return;const y=e.map(x=>[...x]);t.forEach(({coord:x,value:H})=>{x.row>=0&&x.row<M&&x.col>=0&&x.col<w&&(y[x.row][x.col]=H)}),o(y)},[e,o,M,w]),{selection:a,isSelecting:I,isCellSelected:T,handleCellMouseDown:s,handleCellMouseEnter:G,setSelection:z}=_({containerRef:m}),{handleKeyDown:L}=Q({selection:a,getValue:c,setValues:h,setSelection:z,rowCount:M,colCount:w}),{isDraggingFill:E,isFillTarget:F,handleFillHandleMouseDown:N,handleCellMouseEnterForFill:j}=Z({selection:a,getValue:c,setValues:h}),O=r.useCallback(t=>{E?j(t):I&&G(t)},[E,I,j,G]),U=r.useCallback((t,y)=>{C(t,y)},[C]),q=r.useCallback(t=>{if(!a.start)return!1;const y=A(a);return!y.start||!y.end?!1:t.row===y.end.row&&t.col===y.end.col},[a]),W=t=>({...me,...!t&&!f?.rowHeader?ye:{}}),v=t=>({...be,...!t&&!f?.colGroup?Se:{}}),V=t=>({...Ce,...!t&&!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:[i&&g&&p.jsxs("tr",{children:[l&&p.jsx("th",{colSpan:d?2:1,className:f?.rowHeader,style:W(),children:S}),i.map((t,y)=>p.jsx("th",{colSpan:t.headers.length,className:K(f?.colGroup,t.className),style:v(t.className),title:t.description,children:t.label??""},y))]}),i&&p.jsxs("tr",{children:[l&&p.jsx("th",{colSpan:d?2:1,className:f?.rowHeader,style:W(),children:!g&&S}),n.map(t=>p.jsx("th",{className:K(f?.colHeader,t.className),style:V(t.className),title:t.description,children:t.label},t.key))]})]}),p.jsx("tbody",{children:e.map((t,y)=>{const x=D?.[y];return p.jsxs("tr",{children:[x&&p.jsxs(p.Fragment,{children:[d&&x.isFirstInGroup&&p.jsx("td",{rowSpan:x.groupRowCount,className:K(f?.rowHeader,x.groupClassName),style:W(x.groupClassName),title:x.groupDescription,children:x.groupLabel??""}),p.jsx("td",{className:K(f?.rowHeader,x.rowHeader.className),style:W(x.rowHeader.className),title:x.rowHeader.description,children:x.rowHeader.label})]}),t.map((H,B)=>{const R={row:y,col:B},P=T(R),De=F(R),Ee=q(R),ve=b?.(R);return p.jsx(ee,{coord:R,value:c(R),isSelected:P,isFillTarget:De,showFillHandle:Ee&&!E,onMouseDown:s,onMouseEnter:O,onChange:U,onFillHandleMouseDown:N,styles:f,cellClassName:ve},B)})]},y)})})]})})}function ke(e){const o=typeof e=="string"?parseFloat(e.replace(/,/g,"")):e;return isNaN(o)?"0":new Intl.NumberFormat("ko-KR").format(o)}function Me(e){const o=parseInt(e.replace(/,/g,""),10);return isNaN(o)?0:o}k.ExcelGrid=xe,k.GridCell=ee,k.cn=K,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,7 @@ 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;
|
|
89
93
|
}
|
|
90
94
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"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7E,8CAA8C;IAC9C,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-excel-lite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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",
|