@sheetxl/studio-vanilla
Version:
SheetXL Studio - Vanilla entry point for integrating SheetXL UI.
45 lines (44 loc) • 3.42 kB
JavaScript
import { r as t, T as x, j as o, S as L, B as W, f as b, l as O, h as p, k as r } 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 z = ["Ok", "Cancel"], E = t.memo((P) => {
const { initialHyperlink: s = null, initialDisplay: D = null, onUpdateHyperlink: f, context: l, onOption: m, onValidateOption: d, onDone: u, options: h = z, defaultOption: c = h?.[0], cancelOption: i = "Cancel", sx: j, ...F } = P, H = t.useMemo(() => (s ?? l?.()?.getHyperlink()) !== null, []), k = t.useMemo(() => {
let e = null, a = null;
s && (typeof s == "string" ? a = s : e = s);
const C = e ?? l?.()?.getHyperlink();
return { address: a ?? C?.getAddress() ?? "", textToDisplay: C?.getDisplayText() ?? "" };
}, [s, l]), [n, I] = t.useState(k.address), [g, v] = t.useState(() => {
const e = l?.().toTextUnformatted() ?? D;
return e === k.address ? "" : e;
}), [w, y] = t.useState(!1), M = t.useCallback((e) => {
v(e.target.value);
}, []), T = t.useCallback(async (e, a) => null, []), S = x(async (e) => {
e !== i && f?.(n === "" ? null : { address: n }, g), m?.(e, e === i, e === c), u?.();
}, [n, g, f, u, m, c, i]), B = x((e) => {
I(e.target.value), T(e.target.value, null);
}, [d]), $ = x(async (e) => {
let a = await Promise.resolve(d?.(e));
try {
a !== !1 && (a = await T(n, e));
} catch {
}
return a ?? !0;
}, [d]);
return o.jsx(L, { title: (H ? "Edit" : "Insert") + " Link", options: h, onDone: u, onOption: (e) => S(e), onValidateOption: $, defaultOption: c, cancelOption: i, autoFocusSel: ".autoFocus", sx: { width: "480px", ...j }, ...F, children: o.jsxs(W, { sx: { paddingTop: (e) => e.spacing(1), paddingBottom: (e) => e.spacing(0), rowGap: (e) => e.spacing(1), display: "flex", flexDirection: "column" }, children: [o.jsx(b, { sx: { paddingTop: (e) => e.spacing(1.5), minWidth: 135, width: "100%" }, size: "small", children: o.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: n, onChange: B, onContextMenu: (e) => {
e.stopPropagation();
} }) }), o.jsx(b, { sx: { paddingTop: (e) => e.spacing(1.5), minWidth: 135, width: "100%" }, size: "small", children: o.jsx(O, { label: "Display Text", placeholder: n?.startsWith("#") ? n.substring(1) : n, 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 {
E as HyperlinkDialog,
E as default
};