UNPKG

@sheetxl/studio-vanilla

Version:

SheetXL Studio - Vanilla entry point for integrating SheetXL UI.

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