@sheetxl/studio-vanilla
Version:
SheetXL Studio - Vanilla entry point for integrating SheetXL UI.
7 lines (6 loc) • 3.51 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"),P=["Ok","Cancel"],j=e.reactExports.memo(E=>{const{initialValue:b,context:x,onOption:m,onValidateOption:l,onInput:d,onDone:p,options:g=P,defaultOption:r=g?.[0],cancelOption:i="Cancel",sx:v,...C}=E,[a,y]=e.reactExports.useState(b),[k,T]=e.reactExports.useState(!1),u=e.reactExports.useCallback(async(t,o)=>!0,[]),c=e.k(async t=>{const o=t===i;o||d?.(a,t),m?.(t,o,t===r),p?.()},[a,d,p,m,i,r]),O=e.k(async t=>{t.keyCode===e.Ko.Enter&&await u?.(a,null)!==!1&&c(r)},[a,c]),R=e.k(t=>{y(t.target.value),u?.(t.target.value,null)},[l]),S=e.k(async t=>{let o=await Promise.resolve(l?.(t));try{o!==!1&&(o=await Promise.resolve(u?.(a,t))??!0)}catch{}return o??!0},[l]),[h,f]=e.reactExports.useState(e.Ne.Styles.lookupStyle(a).formatType??e.Ne.Type.Custom);e.reactExports.useEffect(()=>{f(e.Ne.Styles.lookupStyle(a).formatType??e.Ne.Type.Custom)},[a]);const F=e.reactExports.useMemo(()=>{const t=e.Ne.Styles.lookupPrimary(),o=n=>e.jsxRuntimeExports.jsx(e.MenuItem,{value:n,children:n},n),s=Object.keys(t).map(n=>o(t[n].formatType));return s.push(o(e.Ne.Type.Custom)),s},[]),N=e.reactExports.useCallback(t=>{const o=t.target.value;f(o);const s=e.Ne.Styles.lookupDefault(o);s&&y(s)},[]),w=e.reactExports.useMemo(()=>{const t=x?.();return t?t.createTemporaryCell({value:t.getValue()??12345,style:{numberFormat:a}}):null},[h,a,x]);return e.jsxRuntimeExports.jsx(e.Or,{title:"Number Format",options:g,onDone:p,onOption:t=>c(t),onValidateOption:S,defaultOption:r,cancelOption:i,autoFocusSel:".autoFocus",sx:{width:"580px",...v},...C,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=>{k||t.target?.select(),T(!0)},sx:{"& .MuiFormHelperText-root":{marginTop:t=>t.spacing(.5)}},slotProps:{inputLabel:{shrink:!0},htmlInput:{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:a,onChange:R,onKeyDown:O,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:w?.getNumberFormat().displayText||"(empty)"})]})]})})});exports.NumberFormatDialog=j,exports.default=j;