UNPKG

@sheetxl/studio-vanilla

Version:

SheetXL Studio - Vanilla entry point for integrating SheetXL UI.

48 lines (47 loc) 3.53 kB
import { a as o } from "./DrQ2E12IEJK6WHfw.js"; import { r as n } from "./BTLmGxC1eZDXb9cY.js"; import { Y as f, Z as $, B as A, a1 as b, v as O, x as r, A as p } from "./elB9a338Kjeh3S89.js"; /** * @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 L = ["Ok", "Cancel"], E = n.memo((v) => { const { initialValue: s = null, context: l, onInput: h, onOption: T, onValidateOption: d, onDone: u, options: y = L, defaultOption: c = y?.[0], cancelOption: g = "Cancel", sx: D, ...F } = v, j = n.useMemo(() => (s ?? l?.()?.getHyperlink()) !== null, []), m = n.useMemo(() => { let t = null, e = null; s && (typeof s == "string" ? e = s : t = s); const i = t ?? l?.()?.getHyperlink(); return { address: e ?? i?.getAddress() ?? "", textToDisplay: i?.getDisplayText() ?? "" }; }, [s, l]), [a, w] = n.useState(m.address), [x, I] = n.useState(() => { const t = l?.().toTextUnformatted() ?? m.displayText; return t === m.address ? "" : t; }), [M, k] = n.useState(!1), H = n.useCallback((t) => { I(t.target.value); }, []), C = n.useCallback(async (t, e) => null, []), P = f(async (t) => { const e = a === "" ? null : { address: a }, i = t === g; i || h?.({ address: e?.address ?? null, displayText: x ?? null }), T?.(t, i, t === c), u?.(); }, [a, x, l, h, u, T, c, g]), B = f((t) => { w(t.target.value), C(t.target.value, null); }, [d]), S = f(async (t) => { let e = await Promise.resolve(d?.(t)); try { e !== !1 && (e = await C(a, t)); } catch { } return e ?? !0; }, [d]); return o.jsx($, { title: (j ? "Edit" : "Insert") + " Link", options: y, onDone: u, onOption: (t) => P(t), onValidateOption: S, defaultOption: c, cancelOption: g, autoFocusSel: ".autoFocus", sx: { width: "480px", ...D }, ...F, children: o.jsxs(A, { sx: { paddingTop: (t) => t.spacing(1), paddingBottom: (t) => t.spacing(0), rowGap: (t) => t.spacing(1), display: "flex", flexDirection: "column" }, children: [o.jsx(b, { sx: { paddingTop: (t) => t.spacing(1.5), minWidth: 135, width: "100%" }, size: "small", children: o.jsx(O, { label: "Address", placeholder: "Enter a url or cell reference.", onFocus: (t) => { M || t.target?.select(), k(!0); }, sx: { "& .MuiFormHelperText-root": { marginTop: (t) => t.spacing(0.5) } }, slotProps: { inputLabel: { shrink: !0 }, htmlInput: { className: "autoFocus", spellCheck: !1, autoComplete: "off", sx: { paddingTop: (t) => t.spacing(1.25), paddingBottom: (t) => t.spacing(0.75), backgroundImage: `linear-gradient(${r("#fff", p(5))}, ${r("#fff", p(5))})` } } }, value: a, onChange: B, onContextMenu: (t) => { t.stopPropagation(); } }) }), o.jsx(b, { sx: { paddingTop: (t) => t.spacing(1.5), minWidth: 135, width: "100%" }, size: "small", children: o.jsx(O, { label: "Display Text", placeholder: a?.startsWith("#") ? a.substring(1) : a, onFocus: () => { k(!0); }, sx: { "& .MuiFormHelperText-root": { marginTop: (t) => t.spacing(0.5) } }, slotProps: { inputLabel: { shrink: !0 }, htmlInput: { spellCheck: !1, autoComplete: "off", sx: { paddingTop: (t) => t.spacing(1.25), paddingBottom: (t) => t.spacing(0.75), backgroundImage: `linear-gradient(${r("#fff", p(5))}, ${r("#fff", p(5))})` } } }, value: x, onChange: H, onContextMenu: (t) => { t.stopPropagation(); } }) })] }) }); }); export { E as HyperlinkDialog, E as default };