@sheetxl/studio-vanilla
Version:
SheetXL Studio - Vanilla entry point for integrating SheetXL UI.
47 lines (46 loc) • 3.66 kB
JavaScript
import { a } from "./DrQ2E12IEJK6WHfw.js";
import { r as i } from "./BTLmGxC1eZDXb9cY.js";
import { w as B, Y as l, K as R, Z as V, B as j, a1 as v, v as A, x as u, A as c, a2 as H, a3 as K, J as L, a4 as N } from "./elB9a338Kjeh3S89.js";
/**
* @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.
*/
const W = ["Autofit", "Ok", "Cancel"], Y = i.memo((w) => {
const { initialValue: b, context: s, onOption: y, onValidateOption: p, onInput: C, onDone: d, options: z = W, defaultOption: r = z?.[1], cancelOption: x = "Cancel", sx: P, ...k } = w, T = i.useMemo(() => s?.().getOrientation() === B.Orientation.Column, [s]), [t, O] = i.useState(b), [D, M] = i.useState(!1), g = i.useCallback(async (n, e) => !0, []), m = i.useMemo(() => {
if (!s().toUnits) return null;
let n = t?.size ?? 0, e = "Px";
return t.unit === "Px" ? (n = s().toUnits?.(n), e = s().getUnitText()) : (n = s().toPixels?.(n), e = "Px"), { size: n, unit: e };
}, [t?.unit, t?.size]), f = l(async (n) => {
const e = n === x;
e || C?.(t, n), y?.(n, e, n === r), d?.();
}, [t, C, d, y, x, r]), U = l(async (n) => {
n.keyCode === R.Enter && await g?.(t, null) !== !1 && f(r);
}, [t, f]), F = l(async (n) => {
let e = await Promise.resolve(p?.(n));
try {
e !== !1 && (e = await Promise.resolve(g?.(t, n)) ?? !0);
} catch {
}
return e ?? !0;
}, [p]), I = l((n) => {
const e = { ...t, size: Number(n.target.value) };
O(e), g?.(e, null);
}, [t, p]), S = l((n) => {
const e = n.target.value, o = { ...t, unit: e };
O(o);
}, [t]), $ = i.useMemo(() => {
const n = s().getUnitText(), e = (h) => a.jsx(N, { value: h, children: h }, h), o = [];
return o.push(e("Px")), o.push(e(n)), o;
}, []);
return a.jsx(V, { title: "Resize " + (T ? "Columns" : "Rows"), options: z, onDone: d, onOption: (n) => f(n), onValidateOption: F, defaultOption: r, cancelOption: x, autoFocusSel: ".autoFocus", sx: { width: "380px", ...P }, ...k, children: a.jsxs(j, { sx: { paddingTop: (n) => n.spacing(0), paddingBottom: (n) => n.spacing(1), display: "flex", flexDirection: "column" }, children: [a.jsxs(j, { sx: { rowGap: (n) => n.spacing(1), display: "flex", flexDirection: "row", gap: (n) => n.spacing(0.5), alignItems: "end", justifyContent: "center" }, children: [a.jsx(v, { sx: { paddingTop: (n) => n.spacing(1.5), minWidth: 135, width: "100%" }, size: "small", children: a.jsx(A, { label: "Size", onFocus: (n) => {
D || n.target?.select(), M(!0);
}, sx: { "& .MuiFormHelperText-root": { marginTop: (n) => n.spacing(0.5) } }, slotProps: { inputLabel: { shrink: !0 }, htmlInput: { className: "autoFocus", spellCheck: !1, autoComplete: "off", type: "number", inputMode: "numeric", pattern: "[0-9]*", sx: { paddingTop: (n) => n.spacing(1.25), paddingBottom: (n) => n.spacing(0.75), backgroundImage: `linear-gradient(${u("#fff", c(5))}, ${u("#fff", c(5))})` } } }, value: t.size, onChange: I, onKeyDown: U, onContextMenu: (n) => {
n.stopPropagation();
} }) }), a.jsxs(v, { sx: { minWidth: 85 }, size: "small", children: [a.jsx(H, { children: "Unit" }), a.jsx(K, { value: t.unit, label: "Unit", onChange: S, sx: { backgroundImage: `linear-gradient(${u("#fff", c(5))}, ${u("#fff", c(5))})` }, children: $ })] })] }), m && a.jsx(j, { children: a.jsxs(L, { variant: "body2", component: "div", sx: { paddingLeft: (n) => n.spacing(2) }, children: [m.size, " ", m.unit] }) })] }) });
});
export {
Y as ResizeHeaderDialog,
Y as default
};