@sheetxl/studio-vanilla
Version:
SheetXL Studio - Vanilla entry point for integrating SheetXL UI.
7 lines (6 loc) • 10.9 kB
JavaScript
"use strict";/**
* @license @sheetxl/studio-vanilla - SheetXL Studio - Vanilla entry point for integrating SheetXL UI. - v0.6.4
*
* (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("./Bd-US8M4eZh5SC26.cjs"),G=e.createSvgIcon(e.jsxRuntimeExports.jsx("path",{d:"M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20z"}),"ArrowBack"),X=e.createSvgIcon(e.jsxRuntimeExports.jsx("path",{d:"m20 12-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8z"}),"ArrowDownward"),J=e.createSvgIcon(e.jsxRuntimeExports.jsx("path",{d:"m12 4-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z"}),"ArrowForward"),Q=e.createSvgIcon(e.jsxRuntimeExports.jsx("path",{d:"m4 12 1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8z"}),"ArrowUpward"),b=e.reactExports.memo(g=>{const{label:d,value:a,options:i,onSelect:p,tabIndex:f=0,...h}=g,[O,m]=e.reactExports.useState(()=>H(a,i));e.reactExports.useEffect(()=>{m(H(a,i))},[a,i]);const T=e.T(c=>{m(c.target.value),p?.(i[c.target.value])},[p,i]),r=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:d}),e.jsxRuntimeExports.jsx(e.Select,{inputProps:{tabIndex:f},value:O,label:d,onChange:T,sx:{backgroundImage:`linear-gradient(${e.alpha("#fff",e.getOverlayAlpha(5))}, ${e.alpha("#fff",e.getOverlayAlpha(5))})`},...h,children:r})]})}),S={Workbook:"workbook",Sheet:"sheet"},z={enter:140,exit:140},Z={Formulas:e.Te.Content.Formulas,Values:e.Te.Content.Values,Notes:e.Te.Content.Notes,Comments:e.Te.Content.Comments},N={...Z};delete N.Values;const Y={"By Rows":!0,"By Columns":!1},H=(g,d)=>{const a=Object.keys(d);for(let i=0;i<a.length;i++){const p=a[i];if(d[p]===g)return p}},$=e.reactExports.memo(g=>{const{replace:d=!1,findText:a,replaceText:i,findOptions:p,replaceOptions:f,title:h,onHide:O,onFindOrReplace:m,...T}=g,r=e.reactExports.useRef(null),c=e.reactExports.useRef(null),w=e.reactExports.useRef(null),k=e.reactExports.useRef(null),I=e.reactExports.useRef(null),F=e.reactExports.useRef(null),A=(t,n)=>{n&&(n.start(t,{center:!1}),setTimeout(()=>n.stop(t),180))},[L,R]=e.reactExports.useState(!1),[y,W]=e.reactExports.useState(!1),[x,C]=e.reactExports.useState(d),[B,v]=e.reactExports.useState(!1),[D,P]=e.reactExports.useState(!1),[o,l]=e.reactExports.useState({findText:null,replaceText:null,replace:d,replaceOptions:{},findOptions:{matchCase:!1,matchEntireCell:!1,useRegex:!1,orientation:e.w.Orientation.Row,fields:[e.Te.Content.Formulas]},scope:S.Sheet}),j=e.T(async(t,n,s,E)=>{if(!m)return;const u={...o};u.replaceOptions={...u.replaceOptions},u.findOptions={...u.findOptions},u.replaceOptions.maxCount=s?void 0:1,u.replace=n,n&&o.findOptions.fields?.[0]===e.Te.Content.Values&&(u.findOptions.fields=[e.Te.Content.Formulas]),u.findOptions.reverse=!t;const q=await m({autoFocus:E,...u});v(q===0)},[o,m]);e.reactExports.useEffect(()=>{v(!1)},[o,y,x]);const M=e.T((t,n)=>{if(t.keyCode===e.eo.Enter){if(!o.findText)return;let s=!0,E=!1;t.shiftKey&&(s=!1),n?(t.ctrlKey&&t.altKey&&(E=!0),A(t,E?F.current:I.current)):A(t,s?k.current:w.current),j(s,n,E,!1)}},[o]),K=e.reactExports.useRef(null);e.reactExports.useLayoutEffect(()=>{l(t=>{const n={...t};n.findText=a&&a.length>0?a:t.findText??"",R(!0),i!==void 0&&(n.replaceText=i),p&&(n.findOptions={...n.findOptions,...p}),n.replaceText||(n.replaceText=""),n.replaceOptions&&(n.replaceOptions={...n.replaceOptions}),f&&(n.replaceOptions={...n.replaceOptions,...f}),o.findOptions.fields?.[0]||(o.findOptions.fields=[e.Te.Content.Formulas]);const s=!(!f&&i===void 0);return s&&C(s),n}),D||K.current?.focus()},[a,i,p,f]),e.reactExports.useEffect(()=>{x?(o.findOptions.fields[0],e.Te.Content.Values):R(!0)},[x]),e.reactExports.useEffect(()=>{if(L&&r.current&&o.findText===r.current.value)return r.current===document.activeElement||r.current.contains(document.activeElement)?(r.current?.select(),void R(!1)):void r.current.addEventListener("focus",()=>{r.current?.select(),R(!1)},{once:!0})},[L,o]);const[U,{width:V}]=e.No();return e.jsxRuntimeExports.jsx(e.z8,{ref:K,title:h??(x?"Find & Replace":"Find"),initialPosition:{y:"35"},autoFocusSel:".input",onHide:O,onFocus:()=>P(!0),onBlur:()=>{P(!1),v(!1)},PaperProps:{elevation:D?3:1},...T,children:e.jsxRuntimeExports.jsxs(e.DialogContent,{dividers:!0,ref:U,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)C(!0),r.current?.contains(document.activeElement)&&c.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.Re,{selected:y,onSelectToggle:t=>{W(t)},preventFocus:!0,label:"Toggle Additional Options",icon:e.p2(e.jsxRuntimeExports.jsx(e.b9,{}))}),e.jsxRuntimeExports.jsx(e.Re,{selected:x,onSelectToggle:t=>{C(t)},preventFocus:!0,label:"Toggle Replace",icon:e.p2(e.jsxRuntimeExports.jsx(e.g9,{})),shortcut:{key:x?"F":"H",modifiers:[e.Z.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",InputLabelProps:{shrink:!0},InputProps:{sx:{paddingRight:t=>t.spacing(1),minWidth:V>460?"20em":void 0,backgroundImage:`linear-gradient(${e.alpha("#fff",e.getOverlayAlpha(5))}, ${e.alpha("#fff",e.getOverlayAlpha(5))})`},inputProps:{draggable:!1,ref:r,className:"input",autoFocus:!0,spellCheck:!1,autoComplete:"off",sx:{paddingTop:t=>t.spacing(1.25),paddingBottom:t=>t.spacing(.75)}},endAdornment:e.jsxRuntimeExports.jsx(e.InputAdornment,{sx:{transform:"scale(0.75) translateX(16px)"},position:"end",children:e.jsxRuntimeExports.jsxs(e.Box,{sx:{display:"flex",alignItems:"center",flexDirection:"row",gap:"1px"},children:[e.jsxRuntimeExports.jsx(e.Re,{selected:o.findOptions.matchCase,onSelectToggle:t=>{l(n=>{const s={...n};return s.findOptions.matchCase=t,s})},label:"Match Case",shortcut:{key:"C",modifiers:[e.Z.Alt]},icon:e.p2(e.jsxRuntimeExports.jsx(e.x9,{}))}),e.jsxRuntimeExports.jsx(e.Re,{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.Z.Alt]},icon:e.p2(e.jsxRuntimeExports.jsx(e.V9,{}))}),e.jsxRuntimeExports.jsx(e.Re,{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.Z.Alt]},icon:e.p2(e.jsxRuntimeExports.jsx(e.M9,{}))})]})})},sx:{flex:"1 1 100%",marginRight:t=>t.spacing(1),"& .MuiOutlinedInput-notchedOutline":{borderColor:t=>B?`${t.palette.error.main} !important`:void 0},"& .MuiInputLabel-outlined":{color:t=>B?`${t.palette.error.main} !important`:void 0}},value:o.findText??"",onChange:t=>{l(n=>{const s={...n};return s.findText=t.target.value,s})},onKeyDown:t=>M(t,!1),onContextMenu:t=>{t.stopPropagation()}}),e.jsxRuntimeExports.jsx(e.Re,{selected:o.findOptions.reverse,onSelectToggle:t=>{j(!1,!1)},touchRippleRef:w,label:"",shortcut:{key:"Enter",modifiers:[e.Z.Shift]},icon:e.p2(o.findOptions.orientation!==e.w.Orientation.Column?e.jsxRuntimeExports.jsx(G,{}):e.jsxRuntimeExports.jsx(Q,{})),disabled:!o.findText}),e.jsxRuntimeExports.jsx(e.Re,{selected:!o.findOptions.reverse,onSelectToggle:t=>{j(!0,!1)},touchRippleRef:k,label:"Next Match",shortcut:{key:"Enter"},icon:e.p2(o.findOptions.orientation!==e.w.Orientation.Column?e.jsxRuntimeExports.jsx(J,{}):e.jsxRuntimeExports.jsx(X,{})),disabled:!o.findText})]}),e.jsxRuntimeExports.jsx(e.Collapse,{in:x,timeout:z,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",InputLabelProps:{shrink:!0},InputProps:{sx:{paddingRight:t=>t.spacing(1),backgroundImage:`linear-gradient(${e.alpha("#fff",e.getOverlayAlpha(5))}, ${e.alpha("#fff",e.getOverlayAlpha(5))})`},inputProps:{ref:c,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=>M(t,!0),onContextMenu:t=>{t.stopPropagation()}}),e.jsxRuntimeExports.jsx(e.Re,{onSelectToggle:t=>{j(!0,!0)},touchRippleRef:I,label:"Replace",shortcut:{key:"Enter"},icon:e.p2(e.jsxRuntimeExports.jsx(e.z9,{})),disabled:!o.findText}),e.jsxRuntimeExports.jsx(e.Re,{onSelectToggle:t=>{j(!0,!0,!0)},touchRippleRef:F,label:"Replace All",shortcut:{key:"Enter",modifiers:[e.Z.Ctrl,e.Z.Alt]},icon:e.p2(e.jsxRuntimeExports.jsx(e.H9,{})),disabled:!o.findText})]})})]})]}),e.jsxRuntimeExports.jsx(e.Collapse,{in:y,timeout:z,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(.5),marginTop:t=>t.spacing(1)},children:[e.jsxRuntimeExports.jsx(e.m6,{orientation:"horizontal",sx:{marginBottom:t=>t.spacing(1.5)}}),e.jsxRuntimeExports.jsxs(e.Box,{sx:{display:"flex",flexDirection:V>=413?"row":"column",justifyContent:"space-evenly",alignItems:"center",rowGap:t=>t.spacing(2)},tabIndex:-1,children:[e.jsxRuntimeExports.jsx(b,{label:"Within",value:o.scope,options:S,onSelect:t=>{l(n=>{const s={...n};return s.scope=t,s})}}),e.jsxRuntimeExports.jsx(b,{label:"Search",value:o.findOptions.orientation!==e.w.Orientation.Column,options:Y,onSelect:t=>{l(n=>{const s={...n};return s.findOptions.orientation=t?e.w.Orientation.Row:e.w.Orientation.Column,s})}}),e.jsxRuntimeExports.jsx(b,{label:"Look in",value:x&&o.findOptions.fields?.[0]===e.Te.Content.Values?e.Te.Content.Formulas:o.findOptions.fields?.[0],options:x?N:Z,onSelect:t=>{l(n=>{const s={...n};return s.findOptions.fields=[t],s})}})]})]})})]})})});exports.FindReplaceWindow=$,exports.ScopeOptions=S,exports.default=$;