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