UNPKG

@sheetxl/studio-vanilla

Version:

SheetXL Studio - Vanilla entry point for integrating SheetXL UI.

49 lines (48 loc) 2.63 kB
import { r as s, T as u, j as l, S, B, f as M, l as E, h, k as C } 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 V = ["Ok", "Cancel"], z = s.memo((O) => { const { initialComments: k = null, onUpdateComments: m, context: T, onOption: d, onValidateOption: c, onDone: p, options: g = V, defaultOption: r = g?.[0], cancelOption: i = "Cancel", sx: j, ...w } = O, f = s.useMemo(() => { const n = k ?? T?.()?.getComments(); let t = ""; if (n && n.content && n.content.runs) { const a = n.content.runs; for (let o = 0; o < a.length; o++) { const I = a[o]; t += I?.text; } } return t; }, []), [e, y] = s.useState(f), [F, P] = s.useState(!1), x = s.useCallback(async (n, t) => null, []), b = u(async (n) => { const t = e === "" ? [] : e.split(` `); if (n !== i) { const a = []; for (let o = 0; o < t.length; o++) a.push({ text: t[o] }); m?.({ content: { runs: a } }); } d?.(n, n === i, n === r), p?.(); }, [e, m, p, d, r, i]), v = u((n) => { y(n.target.value), x(n.target.value, null); }, [c]), D = u(async (n) => { let t = await Promise.resolve(c?.(n)); try { t !== !1 && (t = await x(e, n)); } catch { } return t ?? !0; }, [c, e]); return l.jsx(S, { title: (f ? "Edit" : "Insert") + " Comments", options: g, onDone: p, onOption: (n) => b(n), onValidateOption: D, defaultOption: r, cancelOption: i, autoFocusSel: ".autoFocus", sx: { width: "480px", ...j }, ...w, children: l.jsx(B, { sx: { paddingTop: (n) => n.spacing(1), paddingBottom: (n) => n.spacing(0), rowGap: (n) => n.spacing(1), display: "flex", flexDirection: "column" }, children: l.jsx(M, { sx: { paddingTop: (n) => n.spacing(1.5), minWidth: 135, width: "100%" }, size: "small", children: l.jsx(E, { label: "Comments", placeholder: "Enter a comment.", onFocus: (n) => { F || n.target?.select(), P(!0); }, sx: { "& .MuiFormHelperText-root": { marginTop: (n) => n.spacing(0.5) } }, InputLabelProps: { shrink: !0 }, InputProps: { inputProps: { className: "autoFocus", spellCheck: !1, autoComplete: "off", sx: { paddingTop: (n) => n.spacing(1.25), paddingBottom: (n) => n.spacing(0.75), backgroundImage: `linear-gradient(${h("#fff", C(5))}, ${h("#fff", C(5))})` } } }, value: e, onChange: v, onContextMenu: (n) => { n.stopPropagation(); } }) }) }) }); }); export { z as CommentsDialog, z as default };