@sheetxl/studio-vanilla
Version:
SheetXL Studio - Vanilla entry point for integrating SheetXL UI.
7 lines (6 loc) • 3.5 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"),w=["Ok","Cancel"],j=e.reactExports.memo(E=>{const{initialValue:T,context:x,onOption:m,onValidateOption:p,onInputOption:d,onDone:l,options:g=w,defaultOption:r=g?.[0],cancelOption:i="Cancel",sx:b,...v}=E,[o,y]=e.reactExports.useState(T),[C,O]=e.reactExports.useState(!1),u=e.reactExports.useCallback(async(t,a)=>!0,[]),c=e.T(async t=>{d?.(o,t),m?.(t,t===i,t===r),l?.()},[o,d,l,m,i,r]),S=e.T(async t=>{t.keyCode===e.eo.Enter&&await u?.(o,null)!==!1&&c(r)},[o,c]),k=e.T(t=>{y(t.target.value),u?.(t.target.value,null)},[p]),R=e.T(async t=>{let a=await Promise.resolve(p?.(t));try{a!==!1&&(a=await Promise.resolve(u?.(o,t))??!0)}catch{}return a??!0},[p]),[h,f]=e.reactExports.useState(e.Nt.Styles.lookupStyle(o).formatType??e.Nt.Type.Custom);e.reactExports.useEffect(()=>{f(e.Nt.Styles.lookupStyle(o).formatType??e.Nt.Type.Custom)},[o]);const F=e.reactExports.useMemo(()=>{const t=e.Nt.Styles.lookupPrimary(),a=n=>e.jsxRuntimeExports.jsx(e.MenuItem,{value:n,children:n},n),s=Object.keys(t).map(n=>a(t[n].formatType));return s.push(a(e.Nt.Type.Custom)),s},[]),N=e.reactExports.useCallback(t=>{const a=t.target.value;f(a);const s=e.Nt.Styles.lookupDefault(a);s&&y(s)},[]),P=e.reactExports.useMemo(()=>{const t=x();return t.createTemporaryCell({value:t.getValue()??12345,style:{numberFormat:o}})},[h,o,x]);return e.jsxRuntimeExports.jsx(e.S3,{title:"Number Format",options:g,onDone:l,onOption:t=>c(t),onValidateOption:R,defaultOption:r,cancelOption:i,autoFocusSel:".autoFocus",sx:{width:"580px",...b},...v,children:e.jsxRuntimeExports.jsxs(e.Box,{sx:{paddingTop:t=>t.spacing(1),paddingBottom:t=>t.spacing(0),rowGap:t=>t.spacing(1),display:"flex",flexDirection:"column"},children:[e.jsxRuntimeExports.jsxs(e.FormControl,{sx:{minWidth:135},size:"small",children:[e.jsxRuntimeExports.jsx(e.InputLabel,{children:"Category"}),e.jsxRuntimeExports.jsx(e.Select,{value:h,label:"Category",onChange:N,sx:{backgroundImage:`linear-gradient(${e.alpha("#fff",e.getOverlayAlpha(5))}, ${e.alpha("#fff",e.getOverlayAlpha(5))})`},children:F})]}),e.jsxRuntimeExports.jsx(e.FormControl,{sx:{paddingTop:t=>t.spacing(1.5),minWidth:135,width:"100%"},size:"small",children:e.jsxRuntimeExports.jsx(e.TextField,{label:"Code",onFocus:t=>{C||t.target?.select(),O(!0)},sx:{"& .MuiFormHelperText-root":{marginTop:t=>t.spacing(.5)}},InputLabelProps:{shrink:!0},InputProps:{inputProps:{className:"autoFocus",spellCheck:!1,autoComplete:"off",sx:{paddingTop:t=>t.spacing(1.25),paddingBottom:t=>t.spacing(.75),backgroundImage:`linear-gradient(${e.alpha("#fff",e.getOverlayAlpha(5))}, ${e.alpha("#fff",e.getOverlayAlpha(5))})`}}},value:o,onChange:k,onKeyDown:S,onContextMenu:t=>{t.stopPropagation()}})}),e.jsxRuntimeExports.jsxs(e.Box,{children:[e.jsxRuntimeExports.jsx(e.Typography,{variant:"caption",component:"div",sx:{paddingLeft:t=>t.spacing(2)},children:"Preview"}),e.jsxRuntimeExports.jsx(e.Typography,{variant:"body2",component:"div",sx:{borderRadius:t=>`${t.shape.borderRadius}px`,padding:t=>t.spacing(1),border:t=>`1px solid ${t.palette.grey[400]}`},children:P.getNumberFormat().displayText||"(empty)"})]})]})})});exports.NumberFormatDialog=j,exports.default=j;