UNPKG

@sheetxl/studio-vanilla

Version:

SheetXL Studio - Vanilla entry point for integrating SheetXL UI.

42 lines (41 loc) 2.55 kB
import { r as n, T as p, j as r, S as b, B as k, Q as B, W as I } 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 E = ["Ok", "Cancel"], A = n.memo((V) => { const { value: a = null, context: t, onOption: c, onValidateOption: L, onDone: g, onUpdate: m, options: x = E, defaultOption: f = x?.[0], cancelOption: N = "Cancel", sx: C, ...h } = V, T = n.useMemo(() => t?.getNames().findValidName("Range1"), []), d = n.useMemo(() => { if (!a) return !0; }, []), [l, R] = n.useState({ displayText: a?.getName() ?? T, errorText: null }), [s, v] = n.useState({ displayValue: a?.getRanges() ?? t?.selection() ?? null, errorText: null }), [y, O] = n.useState(!1), j = n.useCallback(async (e) => !l.errorText && !s.errorText, [t]), S = p((e, o, u) => { if (!o) { let i = null; d ? 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, d)); } c?.(e, o, u), g?.(); }, [t, l, s, g, c, f, N, m]), w = p((e) => { let o = null; try { t?.getNames().validateName(e); } catch (u) { o = u.message; } R({ displayText: e, errorText: o }); }, []), D = p((e) => { a && a.getName().toLowerCase() === e.toLowerCase() || t?.getNames().validateName(e); }, [t, a]), F = n.useCallback((e) => { v({ displayValue: e ?? null, errorText: null }); }, []); return r.jsx(b, { title: (d ? "Define" : "Edit") + " Range", options: x, onOption: S, onValidateOption: j, defaultOption: f, cancelOption: N, autoFocusSel: ".autoFocus", sx: { width: "460px", ...C }, ...h, children: r.jsxs(k, { sx: { paddingTop: (e) => e.spacing(1), paddingBottom: (e) => e.spacing(0), rowGap: (e) => e.spacing(1), range: "flex", flexDirection: "column" }, children: [r.jsx(B, { formName: "name", defaultInput: T, value: l.displayText, onChangeInput: w, onValidate: D, onFocus: (e) => { y || e.target?.select(), O(!0); } }), r.jsx(I, { formName: "range", value: s.displayValue, onChangeInput: F, resolvedAddress: t.getNames().getRanges.bind(t.getNames()), onFocus: (e) => { y || e.target?.select(), O(!0); } })] }) }); }); export { A as NamedReferenceDialog, A as default };