@sheetxl/studio-vanilla
Version:
SheetXL Studio - Vanilla entry point for integrating SheetXL UI.
7 lines (6 loc) • 10.7 kB
JavaScript
"use strict";/**
* @license @sheetxl/studio-vanilla - SheetXL Studio - Vanilla entry point for integrating SheetXL UI. - v0.7.27
*
* (C) 2025-present SheetXL Inc. & Michael T. Ford
* License: The license can be found at https://www.sheetxl.com/license.
*/Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./Bc1oKNEzl3Kcj4g5.cjs"),w={width:"1.5rem",height:"1.5rem"},k=e.reactExports.memo(E=>{const{label:a,value:u,options:i,onSelect:d,tabIndex:y=0,...T}=E,[C,f]=e.reactExports.useState(()=>H(u,i));e.reactExports.useEffect(()=>{f(H(u,i))},[u,i]);const m=e.k(c=>{f(c.target.value),d?.(i[c.target.value])},[d,i]),g=e.reactExports.useMemo(()=>Object.keys(i).map(c=>e.jsxRuntimeExports.jsx(e.MenuItem,{value:c,children:c},c)),[i]);return e.jsxRuntimeExports.jsxs(e.FormControl,{sx:{minWidth:135},size:"small",children:[e.jsxRuntimeExports.jsx(e.InputLabel,{children:a}),e.jsxRuntimeExports.jsx(e.Select,{inputProps:{tabIndex:y},value:C,label:a,onChange:m,sx:{backgroundImage:`linear-gradient(${e.alpha("#fff",e.getOverlayAlpha(5))}, ${e.alpha("#fff",e.getOverlayAlpha(5))})`},...T,children:g})]})}),N={enter:140,exit:140},q={Formulas:e.Ft.Content.Formulas,Values:e.Ft.Content.Values,Notes:e.Ft.Content.Notes,Comments:e.Ft.Content.Comments},G={...q};delete G.Values;const Z={"By Rows":!0,"By Columns":!1},H=(E,a)=>{const u=Object.keys(a);for(let i=0;i<u.length;i++){const d=u[i];if(a[d]===E)return d}},U=e.reactExports.memo(E=>{const{initialValue:a,context:u,onInput:i,title:d,onHide:y,autoFocus:T,...C}=E,f=a?.replace??!1,m=a?.findOptions,g=m.text??null,c=a?.replaceOptions,R=a?.replaceText??null,F=u?.(),r=e.reactExports.useRef(null),K=e.reactExports.useRef(null),A=e.reactExports.useRef(null),I=e.reactExports.useRef(null),B=e.reactExports.useRef(null),D=e.reactExports.useRef(null),M=(t,n)=>{n&&(n.start(t,{center:!1}),setTimeout(()=>n.stop(t),180))},[L,O]=e.reactExports.useState(!1),[v,J]=e.reactExports.useState(!1),[p,S]=e.reactExports.useState(f),[P,b]=e.reactExports.useState(!1),[V,$]=e.reactExports.useState(!1),[o,l]=e.reactExports.useState({replaceText:null,replace:f,replaceOptions:null,findOptions:{text:null,matchCase:!1,matchEntireCell:!1,useRegex:!1,orientation:e.w.Orientation.Row,fields:[e.Ft.Content.Formulas]},scope:e.Oc.FindScopeOptions.Sheet}),h=e.k(async(t,n,s,j)=>{if(!F)return;const x={...o};x.replaceOptions={...x.replaceOptions},x.findOptions={...x.findOptions},x.replaceOptions.maxCount=s?void 0:1,x.replace=n,n&&o.findOptions.fields?.[0]===e.Ft.Content.Values&&(x.findOptions.fields=[e.Ft.Content.Formulas]),x.findOptions.reverse=!t;const Y=await F({autoFocus:j,...x});b(Y===0)},[o,F]);e.reactExports.useEffect(()=>{b(!1)},[o,v,p]);const Q=e.k((t,n)=>{if(t.keyCode===e.Ko.Enter){if(!o.findOptions.text)return;let s=!0,j=!1;t.shiftKey&&(s=!1),n?(t.ctrlKey&&t.altKey&&(j=!0),M(t,j?D.current:B.current)):M(t,s?I.current:A.current),h(s,n,j,!1)}},[o]),W=e.reactExports.useRef(null);e.reactExports.useLayoutEffect(()=>{l(t=>{const n={...t};n.findOptions.text=g&&g.length>0?g:t.findOptions.text??"",O(!0),R!==null&&(n.replaceText=R??""),m&&(n.findOptions={...n.findOptions,...m}),n.replaceText||(n.replaceText=""),n.replaceOptions&&(n.replaceOptions={...n.replaceOptions}),c&&(n.replaceOptions={...n.replaceOptions,...c}),o.findOptions.fields?.[0]||(o.findOptions.fields=[e.Ft.Content.Formulas]);const s=!(!f&&!c&&R===null);return s&&S(s),n}),V||W.current?.focus()},[a,f,g,R,m,c]),e.reactExports.useEffect(()=>{p?(o.findOptions.fields[0],e.Ft.Content.Values):O(!0)},[p]),e.reactExports.useEffect(()=>{if(L&&r.current&&o.findOptions.text===r.current.value)return r.current===document.activeElement||r.current.contains(document.activeElement)?(r.current?.select(),void O(!1)):void r.current.addEventListener("focus",()=>{r.current?.select(),O(!1)},{once:!0})},[L,o]);const[X,{width:z}]=e.Vt();return e.jsxRuntimeExports.jsx(e.ga,{ref:W,title:d??(p?"Find & Replace":"Find"),initialPosition:{y:"35"},autoFocusSel:".input",onHide:y,onFocus:()=>$(!0),onBlur:()=>{$(!1),b(!1)},slotProps:{paper:{elevation:V?3:1}},...C,children:e.jsxRuntimeExports.jsxs(e.DialogContent,{dividers:!0,ref:X,sx:{display:"flex",flexDirection:"column",paddingLeft:t=>t.spacing(1.5),paddingRight:t=>t.spacing(1.5)},onKeyDown:t=>{if(t.key==="h"&&t.ctrlKey)S(!0),r.current?.contains(document.activeElement)&&K.current?.focus();else if(t.key==="f"&&t.ctrlKey)r.current?.focus();else if(t.key==="c"&&t.altKey)l(n=>{const s={...n};return s.findOptions.matchCase=!n.findOptions.matchCase,s});else if(t.key==="e"&&t.altKey)l(n=>{const s={...n};return s.findOptions.matchEntireCell=!n.findOptions.matchEntireCell,s});else{if(t.key!=="r"||!t.altKey)return;l(n=>{const s={...n};return s.findOptions.useRegex=!n.findOptions.useRegex,s})}t.preventDefault()},children:[e.jsxRuntimeExports.jsxs(e.Box,{sx:{display:"flex",flexDirection:"row",gap:t=>t.spacing(1)},children:[e.jsxRuntimeExports.jsxs(e.Box,{sx:{display:"flex",flexDirection:"row",alignItems:"start",gap:t=>t.spacing(.25),paddingTop:"3px"},children:[e.jsxRuntimeExports.jsx(e.Ss,{selected:v,onSelectToggle:t=>{J(t)},preventFocus:!0,label:"Toggle Additional Options",icon:e.jsxRuntimeExports.jsx(e.co,{iconKey:"FindOptions"})}),e.jsxRuntimeExports.jsx(e.Ss,{selected:p,onSelectToggle:t=>{S(t)},preventFocus:!0,label:"Toggle Replace",icon:e.jsxRuntimeExports.jsx(e.co,{iconKey:"FindReplaceToggle"}),shortcut:{key:p?"F":"H",modifiers:[e.Q.Ctrl]}})]}),e.jsxRuntimeExports.jsxs(e.Box,{sx:{display:"flex",flexDirection:"column",maxWidth:"100%",boxSizing:"border-box"},children:[e.jsxRuntimeExports.jsxs(e.Box,{sx:{display:"flex",flexDirection:"row",alignItems:"center"},children:[e.jsxRuntimeExports.jsx(e.TextField,{label:"Find",slotProps:{input:{sx:{paddingRight:t=>t.spacing(1),minWidth:z>460?"20em":void 0,backgroundImage:`linear-gradient(${e.alpha("#fff",e.getOverlayAlpha(5))}, ${e.alpha("#fff",e.getOverlayAlpha(5))})`},endAdornment:e.jsxRuntimeExports.jsx(e.InputAdornment,{position:"end",children:e.jsxRuntimeExports.jsxs(e.Box,{sx:{display:"flex",alignItems:"center",flexDirection:"row",gap:"2px"},children:[e.jsxRuntimeExports.jsx(e.Ss,{style:w,selected:o.findOptions.matchCase,onBlur:()=>{},onSelectToggle:t=>{l(n=>{const s={...n};return s.findOptions.matchCase=t,s})},label:"Match Case",shortcut:{key:"C",modifiers:[e.Q.Alt]},icon:e.jsxRuntimeExports.jsx(e.co,{iconKey:"FindCaseSensitive",size:"1rem"})}),e.jsxRuntimeExports.jsx(e.Ss,{style:w,selected:o.findOptions.matchEntireCell,onSelectToggle:t=>{l(n=>{const s={...n};return s.findOptions.matchEntireCell=t,s})},label:"Match Entire Cell",shortcut:{key:"E",modifiers:[e.Q.Alt]},icon:e.jsxRuntimeExports.jsx(e.co,{iconKey:"FindWholeWord",size:"1rem"})}),e.jsxRuntimeExports.jsx(e.Ss,{style:w,selected:o.findOptions.useRegex,onSelectToggle:t=>{l(n=>{const s={...n};return s.findOptions.useRegex=t,s})},label:"Use Regular Expression",shortcut:{key:"R",modifiers:[e.Q.Alt]},icon:e.jsxRuntimeExports.jsx(e.co,{iconKey:"FindRegEx",size:"1rem"})})]})})},inputLabel:{shrink:!0},htmlInput:{draggable:!1,ref:r,className:"input",autoFocus:!0,spellCheck:!1,autoComplete:"off",sx:{paddingTop:t=>t.spacing(1.25),paddingBottom:t=>t.spacing(.75)}}},sx:{flex:"1 1 100%",marginRight:t=>t.spacing(1),"& .MuiOutlinedInput-notchedOutline":{borderColor:t=>P?`${t.palette.error.main} !important`:void 0},"& .MuiInputLabel-outlined":{color:t=>P?`${t.palette.error.main} !important`:void 0}},value:o.findOptions.text??"",onChange:t=>{l(n=>{const s={...n};return s.findOptions.text=t.target.value,s})},onKeyDown:t=>Q(t,!1),onContextMenu:t=>{t.stopPropagation()}}),e.jsxRuntimeExports.jsx(e.Ss,{selected:o.findOptions.reverse,onSelectToggle:t=>{h(!1,!1)},touchRippleRef:A,label:"",shortcut:{key:"Enter",modifiers:[e.Q.Shift]},icon:e.jsxRuntimeExports.jsx(e.co,{iconKey:o.findOptions.orientation!==e.w.Orientation.Column?"ArrowBack":"ArrowUpward"}),disabled:!o.findOptions.text}),e.jsxRuntimeExports.jsx(e.Ss,{selected:!o.findOptions.reverse,onSelectToggle:t=>{h(!0,!1)},touchRippleRef:I,label:"Next Match",shortcut:{key:"Enter"},icon:e.jsxRuntimeExports.jsx(e.co,{iconKey:o.findOptions.orientation!==e.w.Orientation.Column?"ArrowForward":"ArrowDownward"}),disabled:!o.findOptions.text})]}),e.jsxRuntimeExports.jsx(e.Collapse,{in:p,timeout:N,onExit:()=>{r.current?.focus()},children:e.jsxRuntimeExports.jsxs(e.Box,{sx:{display:"flex",flexDirection:"row",alignItems:"center",marginTop:t=>t.spacing(2)},children:[e.jsxRuntimeExports.jsx(e.TextField,{label:"Replace",slotProps:{input:{sx:{paddingRight:t=>t.spacing(1),backgroundImage:`linear-gradient(${e.alpha("#fff",e.getOverlayAlpha(5))}, ${e.alpha("#fff",e.getOverlayAlpha(5))})`}},inputLabel:{shrink:!0},htmlInput:{ref:K,className:"input",spellCheck:!1,autoComplete:"off",sx:{paddingTop:t=>t.spacing(1.25),paddingBottom:t=>t.spacing(.75)}}},sx:{flex:"1 1 100%",marginRight:t=>t.spacing(1)},value:o.replaceText??"",onChange:t=>{l(n=>{const s={...n};return s.replaceText=t.target.value,s})},onKeyDown:t=>Q(t,!0),onContextMenu:t=>{t.stopPropagation()}}),e.jsxRuntimeExports.jsx(e.Ss,{onSelectToggle:t=>{h(!0,!0)},touchRippleRef:B,label:"Replace",shortcut:{key:"Enter"},icon:e.jsxRuntimeExports.jsx(e.co,{iconKey:"FindReplace"}),disabled:!o.findOptions.text}),e.jsxRuntimeExports.jsx(e.Ss,{onSelectToggle:t=>{h(!0,!0,!0)},touchRippleRef:D,label:"Replace All",shortcut:{key:"Enter",modifiers:[e.Q.Ctrl,e.Q.Alt]},icon:e.jsxRuntimeExports.jsx(e.co,{iconKey:"FindReplaceAll"}),disabled:!o.findOptions.text})]})})]})]}),e.jsxRuntimeExports.jsx(e.Collapse,{in:v,timeout:N,onExit:()=>{r.current?.focus()},children:e.jsxRuntimeExports.jsxs(e.Box,{sx:{minHeight:"10px",flex:"1 1 100%",display:"flex",flexDirection:"column",gap:t=>t.spacing(1.5),marginTop:t=>t.spacing(1)},children:[e.jsxRuntimeExports.jsx(e.ri,{orientation:"horizontal",sx:{marginBottom:t=>t.spacing(1.5)}}),e.jsxRuntimeExports.jsxs(e.Box,{sx:{display:"flex",flexDirection:z>=383?"row":"column",justifyContent:"space-evenly",alignItems:"center",gap:t=>t.spacing(1),rowGap:t=>t.spacing(2)},tabIndex:-1,children:[e.jsxRuntimeExports.jsx(k,{label:"Within",value:o.scope,options:e.Oc.FindScopeOptions,onSelect:t=>{l(n=>{const s={...n};return s.scope=t,s})}}),e.jsxRuntimeExports.jsx(k,{label:"Search",value:o.findOptions.orientation!==e.w.Orientation.Column,options:Z,onSelect:t=>{l(n=>{const s={...n};return s.findOptions.orientation=t?e.w.Orientation.Row:e.w.Orientation.Column,s})}}),e.jsxRuntimeExports.jsx(k,{label:"Look in",value:p&&o.findOptions.fields?.[0]===e.Ft.Content.Values?e.Ft.Content.Formulas:o.findOptions.fields?.[0],options:p?G:q,onSelect:t=>{l(n=>{const s={...n};return s.findOptions.fields=[t],s})}})]})]})})]})})});exports.FindReplaceWindow=U,exports.default=U;