@sheetxl/studio-vanilla
Version:
SheetXL Studio - Vanilla entry point for integrating SheetXL UI.
42 lines (41 loc) • 2.59 kB
JavaScript
import { r as n, z as u, j as r, A as S, B as b, a0 as k, $ as B } from "./Bf37sZn7h1jSr98w.mjs";
/**
* @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 A = ["Ok", "Cancel"], M = n.memo((O) => {
const { initialValue: a = null, context: t, onOption: p, onValidateOption: E, onDone: c, onInput: g, options: m = A, defaultOption: x = m?.[0], cancelOption: f = "Cancel", sx: C, ...h } = O, N = n.useMemo(() => t?.().getNames().findValidName("Range1"), []), y = n.useMemo(() => {
if (!a) return !0;
}, []), [l, R] = n.useState({ displayText: a?.getName() ?? N, errorText: null }), [s, v] = n.useState({ displayValue: a?.getRanges() ?? t?.().selection() ?? null, errorText: null }), [T, V] = n.useState(!1), j = n.useCallback(async (e) => !l.errorText && !s.errorText, []), w = u((e, o, d) => {
if (!o) {
let i = null;
y ? i = t?.().getNames().addReference(l?.displayText, s?.displayValue, !1) : (a.getType() === "reference" && a.doBatch(() => {
a.setName(l?.displayText), a.setReference(s?.displayValue);
}, `Edit Named '${l?.displayText}'`), i = a), i && (i.select(), g(i));
}
p?.(e, o, d), c?.();
}, [t, l, s, c, p, x, f, g]), D = u((e) => {
let o = null;
try {
t?.().getNames().validateName(e);
} catch (d) {
o = d.message;
}
R({ displayText: e, errorText: o });
}, []), F = u((e) => {
a && a.getName().toLowerCase() === e.toLowerCase() || t?.().getNames().validateName(e);
}, [t, a]), I = n.useCallback((e) => {
v({ displayValue: e ?? null, errorText: null });
}, []);
return r.jsx(S, { title: (y ? "Define" : "Edit") + " Range", options: m, onOption: w, onValidateOption: j, defaultOption: x, cancelOption: f, autoFocusSel: ".autoFocus", sx: { width: "460px", ...C }, ...h, children: r.jsxs(b, { sx: { paddingTop: (e) => e.spacing(1), paddingBottom: (e) => e.spacing(0), rowGap: (e) => e.spacing(1), range: "flex", flexDirection: "column" }, children: [r.jsx(k, { formName: "name", defaultInput: N, value: l.displayText, onChangeInput: D, onValidate: F, onFocus: (e) => {
T || e.target?.select(), V(!0);
} }), r.jsx(B, { formName: "range", value: s.displayValue, onChangeInput: I, resolvedAddress: t ? t().getNames().getRanges.bind(t().getNames()) : void 0, onFocus: (e) => {
T || e.target?.select(), V(!0);
} })] }) });
});
export {
M as NamedReferenceDialog,
M as default
};