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