UNPKG

@sheetxl/studio-vanilla

Version:

SheetXL Studio - Vanilla entry point for integrating SheetXL UI.

44 lines (43 loc) 2.63 kB
import { a as r } from "./ESo6qTbjf45cfiLm.js"; import { r as n } from "./BjUnH-Jak3KkxyMS.js"; import { T as p, S as b, B as k, a7 as B, a8 as I } from "./Dm24M4tfHrPDHOCg.js"; /** * @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"], U = n.memo((V) => { const { value: a = null, context: t, onOption: c, onValidateOption: L, onDone: m, onUpdate: g, 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), S = n.useCallback(async (e) => !l.errorText && !s.errorText, [t]), j = 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(), g(i, d)); } c?.(e, o, u), m?.(); }, [t, l, s, m, c, f, N, g]), 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: j, onValidateOption: S, 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 { U as NamedReferenceDialog, U as default };