@sheetxl/studio-vanilla
Version:
SheetXL Studio - Vanilla entry point for integrating SheetXL UI.
47 lines (46 loc) • 3.5 kB
JavaScript
import { a as s } from "./ESo6qTbjf45cfiLm.js";
import { r as n } from "./BjUnH-Jak3KkxyMS.js";
import { T as m, S as L, B as W, q as b, x as O, t as p, v as r } 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 z = ["Ok", "Cancel"], V = n.memo((P) => {
const { initialHyperlink: o = null, initialDisplay: D = null, onUpdateHyperlink: x, context: i, onOption: f, onValidateOption: d, onDone: u, options: h = z, defaultOption: c = h?.[0], cancelOption: l = "Cancel", sx: v, ...F } = P, H = n.useMemo(() => (o ?? i?.()?.getHyperlink()) !== null, []), k = n.useMemo(() => {
let e = null, a = null;
o && (typeof o == "string" ? a = o : e = o);
const C = e ?? i?.()?.getHyperlink();
return { address: a ?? C?.getAddress() ?? "", textToDisplay: C?.getDisplayText() ?? "" };
}, [o, i]), [t, I] = n.useState(k.address), [g, j] = n.useState(() => {
const e = i?.().toTextUnformatted() ?? D;
return e === k.address ? "" : e;
}), [w, y] = n.useState(!1), M = n.useCallback((e) => {
j(e.target.value);
}, []), T = n.useCallback(async (e, a) => null, []), S = m(async (e) => {
e !== l && x?.(t === "" ? null : { address: t }, g), f?.(e, e === l, e === c), u?.();
}, [t, g, x, u, f, c, l]), B = m((e) => {
I(e.target.value), T(e.target.value, null);
}, [d]), $ = m(async (e) => {
let a = await Promise.resolve(d?.(e));
try {
a !== !1 && (a = await T(t, e));
} catch {
}
return a ?? !0;
}, [d]);
return s.jsx(L, { title: (H ? "Edit" : "Insert") + " Link", options: h, onDone: u, onOption: (e) => S(e), onValidateOption: $, defaultOption: c, cancelOption: l, autoFocusSel: ".autoFocus", sx: { width: "480px", ...v }, ...F, children: s.jsxs(W, { sx: { paddingTop: (e) => e.spacing(1), paddingBottom: (e) => e.spacing(0), rowGap: (e) => e.spacing(1), display: "flex", flexDirection: "column" }, children: [s.jsx(b, { sx: { paddingTop: (e) => e.spacing(1.5), minWidth: 135, width: "100%" }, size: "small", children: s.jsx(O, { label: "Address", placeholder: "Enter a url or cell reference.", onFocus: (e) => {
w || e.target?.select(), y(!0);
}, sx: { "& .MuiFormHelperText-root": { marginTop: (e) => e.spacing(0.5) } }, InputLabelProps: { shrink: !0 }, InputProps: { inputProps: { className: "autoFocus", spellCheck: !1, autoComplete: "off", sx: { paddingTop: (e) => e.spacing(1.25), paddingBottom: (e) => e.spacing(0.75), backgroundImage: `linear-gradient(${p("#fff", r(5))}, ${p("#fff", r(5))})` } } }, value: t, onChange: B, onContextMenu: (e) => {
e.stopPropagation();
} }) }), s.jsx(b, { sx: { paddingTop: (e) => e.spacing(1.5), minWidth: 135, width: "100%" }, size: "small", children: s.jsx(O, { label: "Display Text", placeholder: t?.startsWith("#") ? t.substring(1) : t, onFocus: () => {
y(!0);
}, sx: { "& .MuiFormHelperText-root": { marginTop: (e) => e.spacing(0.5) } }, InputLabelProps: { shrink: !0 }, InputProps: { inputProps: { spellCheck: !1, autoComplete: "off", sx: { paddingTop: (e) => e.spacing(1.25), paddingBottom: (e) => e.spacing(0.75), backgroundImage: `linear-gradient(${p("#fff", r(5))}, ${p("#fff", r(5))})` } } }, value: g, onChange: M, onContextMenu: (e) => {
e.stopPropagation();
} }) })] }) });
});
export {
V as HyperlinkDialog,
V as default
};