UNPKG

@sheetxl/studio-vanilla

Version:

SheetXL Studio - Vanilla entry point for integrating SheetXL UI.

51 lines (50 loc) 2.73 kB
import { a as c } from "./DrQ2E12IEJK6WHfw.js"; import { r as s } from "./BTLmGxC1eZDXb9cY.js"; import { Y as d, Z as P, B as S, a1 as V, v as A, x as O, A as w } 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 E = ["Ok", "Cancel"], H = s.memo((y) => { const { initialValue: k = null, onInput: g, context: v, onOption: f, onValidateOption: r, onDone: p, options: x = E, defaultOption: u = x?.[0], cancelOption: m = "Cancel", sx: F, ...T } = y, h = s.useMemo(() => { const t = k ?? v?.()?.getComments(); let n = ""; if (t && t.content && t.content.runs) { const a = t.content.runs; for (let e = 0; e < a.length; e++) { const i = a[e]; n += i?.text; } } return n; }, []), [o, b] = s.useState(h), [j, D] = s.useState(!1), C = s.useCallback(async (t, n) => null, []), I = d(async (t) => { const n = o === "" ? [] : o.split(` `), a = t === m; if (!a) { const e = n.length, i = new Array(e); for (let l = 0; l < e; l++) i[l] = { text: n[l] }; g?.({ content: { runs: i } }); } f?.(t, a, t === u), p?.(); }, [o, g, p, f, u, m]), B = d((t) => { b(t.target.value), C(t.target.value, null); }, [r]), M = d(async (t) => { let n = await Promise.resolve(r?.(t)); try { n !== !1 && (n = await C(o, t)); } catch { } return n ?? !0; }, [r, o]); return c.jsx(P, { title: (h ? "Edit" : "Insert") + " Comments", options: x, onDone: p, onOption: (t) => I(t), onValidateOption: M, defaultOption: u, cancelOption: m, autoFocusSel: ".autoFocus", sx: { width: "480px", ...F }, ...T, children: c.jsx(S, { sx: { paddingTop: (t) => t.spacing(1), paddingBottom: (t) => t.spacing(0), rowGap: (t) => t.spacing(1), display: "flex", flexDirection: "column" }, children: c.jsx(V, { sx: { paddingTop: (t) => t.spacing(1.5), minWidth: 135, width: "100%" }, size: "small", children: c.jsx(A, { label: "Comments", placeholder: "Enter a comment.", onFocus: (t) => { j || t.target?.select(), D(!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(${O("#fff", w(5))}, ${O("#fff", w(5))})` } } }, value: o, onChange: B, onContextMenu: (t) => { t.stopPropagation(); } }) }) }) }); }); export { H as CommentsDialog, H as default };