UNPKG

@sheetxl/studio-vanilla

Version:

SheetXL Studio - Vanilla entry point for integrating SheetXL UI.

46 lines (45 loc) 3.45 kB
import { r as n, z as f, j as o, A as $, B as z, M as b, k as O, l as p, p as r } from "./Bf37sZn7h1jSr98w.mjs"; /** * @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 A = ["Ok", "Cancel"], V = n.memo((j) => { const { initialValue: s = null, context: l, onInput: h, onOption: T, onValidateOption: d, onDone: u, options: k = A, defaultOption: c = k?.[0], cancelOption: g = "Cancel", sx: D, ...F } = j, M = n.useMemo(() => (s ?? l?.()?.getHyperlink()) !== null, []), x = n.useMemo(() => { let e = null, t = null; s && (typeof s == "string" ? t = s : e = s); const i = e ?? l?.()?.getHyperlink(); return { address: t ?? i?.getAddress() ?? "", textToDisplay: i?.getDisplayText() ?? "" }; }, [s, l]), [a, v] = n.useState(x.address), [m, w] = n.useState(() => { const e = l?.().toTextUnformatted() ?? x.displayText; return e === x.address ? "" : e; }), [I, y] = n.useState(!1), H = n.useCallback((e) => { w(e.target.value); }, []), C = n.useCallback(async (e, t) => null, []), P = f(async (e) => { const t = a === "" ? null : { address: a }, i = e === g; i || h?.({ address: t?.address ?? null, displayText: m ?? null }), T?.(e, i, e === c), u?.(); }, [a, m, l, h, u, T, c, g]), B = f((e) => { v(e.target.value), C(e.target.value, null); }, [d]), S = f(async (e) => { let t = await Promise.resolve(d?.(e)); try { t !== !1 && (t = await C(a, e)); } catch { } return t ?? !0; }, [d]); return o.jsx($, { title: (M ? "Edit" : "Insert") + " Link", options: k, onDone: u, onOption: (e) => P(e), onValidateOption: S, defaultOption: c, cancelOption: g, autoFocusSel: ".autoFocus", sx: { width: "480px", ...D }, ...F, children: o.jsxs(z, { 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) => { I || e.target?.select(), y(!0); }, sx: { "& .MuiFormHelperText-root": { marginTop: (e) => e.spacing(0.5) } }, slotProps: { inputLabel: { shrink: !0 }, htmlInput: { 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: a, 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: a?.startsWith("#") ? a.substring(1) : a, onFocus: () => { y(!0); }, sx: { "& .MuiFormHelperText-root": { marginTop: (e) => e.spacing(0.5) } }, slotProps: { inputLabel: { shrink: !0 }, htmlInput: { 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: m, onChange: H, onContextMenu: (e) => { e.stopPropagation(); } }) })] }) }); }); export { V as HyperlinkDialog, V as default };