@sheetxl/studio-vanilla
Version:
SheetXL Studio - Vanilla entry point for integrating SheetXL UI.
44 lines (43 loc) • 2.67 kB
JavaScript
import { a as r } from "./DrQ2E12IEJK6WHfw.js";
import { r as n } from "./BTLmGxC1eZDXb9cY.js";
import { Y as u, Z as S, B as b, ad as k, ac as B } 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 E = ["Ok", "Cancel"], Y = n.memo((O) => {
const { initialValue: a = null, context: t, onOption: p, onValidateOption: L, onDone: c, onInput: m, options: g = E, defaultOption: x = g?.[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(), m(i));
}
p?.(e, o, d), c?.();
}, [t, l, s, c, p, x, f, m]), 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: g, 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 {
Y as NamedReferenceDialog,
Y as default
};