@sheetxl/studio-vanilla
Version:
SheetXL Studio - Vanilla entry point for integrating SheetXL UI.
40 lines (39 loc) • 2.44 kB
JavaScript
import { r as e, T as o, e as z, j as i, S as E, B as K, f as R, l as W, h as O, aI as q, k as y } 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 A = ["Input"], J = e.memo(e.forwardRef((w, T) => {
const { initialValue: I = "", onOption: S, onValidateOption: l, onInputOption: r, onValidateInputOption: p, onDone: u, inputProps: c, inputLabel: F, inputType: P, inputPlaceHolder: j, options: d = A, autoFocusSel: k = ".autoFocus", cancelOption: g, defaultOption: f = d?.[0], ...v } = w, [C, b] = e.useState(!1), [t, V] = e.useState(I), [B, D] = e.useState(""), [H, L] = e.useState(!0), s = o(async (a, n) => {
if (!p) return !0;
const h = await p?.(a, n);
D(h?.message ?? "");
const x = h?.valid ?? !0;
return L(x), x;
}, [p]), m = o(async (a) => {
r?.(t, a);
}, [t, r, u, S, g, f]), M = o(async (a) => {
a.keyCode === z.Enter && await s?.(t, null);
}, [t, m]), N = o((a) => {
V(a.target.value), s?.(a.target.value, null);
}, [l]), $ = o(async (a) => {
let n = await s(t, a);
try {
n !== !1 && (n = await s(t, a));
} catch {
}
return n ?? !0;
}, [t, l]);
return i.jsx(E, { options: d, onDone: u, onOption: (a, n) => {
n || m(a);
}, onValidateOption: $, cancelOption: g, defaultOption: f, autoFocusSel: k, ref: T, ...v, children: i.jsx(K, { sx: { paddingTop: (a) => a.spacing(1), paddingBottom: (a) => a.spacing(0) }, children: i.jsx(R, { sx: { paddingTop: (a) => a.spacing(1.5), minWidth: 135, width: "100%" }, size: "small", children: i.jsx(W, { onFocus: (a) => {
C || a.target?.select(), b(!0);
}, type: P, label: F, helperText: B || " ", sx: { width: "100%", "& .MuiFormHelperText-root": { marginTop: (a) => a.spacing(0.5), color: H ? void 0 : "error.main" } }, InputLabelProps: { shrink: !0 }, InputProps: { inputProps: { placeholder: j, spellCheck: !1, autoComplete: "off", ...c, className: q("autoFocus", c?.className), sx: { paddingTop: (a) => a.spacing(1.25), paddingBottom: (a) => a.spacing(0.75), backgroundImage: `linear-gradient(${O("#fff", y(5))}, ${O("#fff", y(5))})` } } }, value: t, onChange: N, onKeyDown: M, onContextMenu: (a) => {
a.stopPropagation();
} }) }) }) });
}));
export {
J as default
};