@sheetxl/studio-vanilla
Version:
SheetXL Studio - Vanilla entry point for integrating SheetXL UI.
57 lines (56 loc) • 4.66 kB
JavaScript
import { r as n, L, q as O, O as E, P as M, T as u, j as a, z as W, D as A, B as o, Q as q, W as K, K as h, U as Q, X as U, Y as f, s as y, _ as b, $ as j } 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 _ = n.memo((w) => {
const { title: S, onHide: C, autoFocusSel: N = ".range-input input", context: R, notifier: l = L, command: r, commands: c, ...T } = w, [v, d] = n.useState(!1), [g, m] = n.useState(!1), x = n.useRef(null), [V, D] = n.useReducer((e) => e + 1, 0), [F, { width: X }] = O();
E(r);
const s = R ?? r.context(), t = s.table(), [B, H] = n.useState(() => t ? s.getNames().getRanges(t.getRange()) : null), P = n.useMemo(() => t?.getName() ?? "", [t]);
M(s.table(), { onAnchorCoordsChange(e) {
H(s.getNames().getRanges(e.getRange()));
}, onProtectedChange(e) {
D();
} });
const I = u((e) => {
s?.table().setName(e);
}, [s]), z = u((e) => {
s?.table().resize(e.at(0));
}, [s]);
let p = null;
return s.table() || (p = a.jsx("div", { style: { position: "absolute", top: "0", left: "0", width: "100%", height: "100%", opacity: 1, display: "flex", alignItems: "center", justifyItems: "center", justifyContent: "center", boxSizing: "border-box" }, children: a.jsx("div", { children: "No table selected" }) })), a.jsx(W, { ref: x, title: S ?? "Table Details", initialPosition: { y: "35" }, autoFocusSel: N, onHide: C, onFocus: () => d(!0), onBlur: (e) => {
x?.current?.contains(e.relatedTarget) || d(!1);
}, PaperProps: { elevation: v ? 3 : 1 }, ...T, children: a.jsxs(A, { dividers: !0, ref: F, sx: { display: "flex", flexDirection: "column", position: "relative", paddingLeft: (e) => e.spacing(1.5), paddingRight: (e) => e.spacing(1.5) }, children: [a.jsxs(o, { sx: { display: "flex", flexDirection: "column", transition: "opacity 60ms", opacity: s.table() ? 1 : 0 }, children: [a.jsx(o, { sx: { display: "flex", flexDirection: "row", gap: (e) => e.spacing(1) }, children: a.jsx(o, { sx: { display: "flex", flexDirection: "column", maxWidth: "100%", boxSizing: "border-box", paddingLeft: (e) => e.spacing(2), paddingRight: (e) => e.spacing(2) }, children: a.jsxs(o, { sx: { display: "flex", flexDirection: "column", alignItems: "center" }, children: [a.jsx(q, { formName: "name", defaultInput: P, value: t?.getName() ?? "No table", onChangeInput: I, onValidate: (e) => {
t && t.getName().toLowerCase() === e.toLowerCase() || s?.getNames().validateName(e);
}, disabled: t?.isProtected() ?? !0, onFocus: (e) => {
g || e.target?.select(), m(!0);
} }), a.jsx(K, { formName: "range", value: B, onChangeInput: z, resolvedAddress: s.getNames().getRanges.bind(s.getNames()), disabled: t?.isProtected() ?? !0, onFocus: (e) => {
g || e.target?.select(), m(!0);
} })] }) }) }), a.jsxs(o, { sx: { minHeight: "10px", flex: "1 1 100%", display: "flex", flexDirection: "column", gap: (e) => e.spacing(0.5), marginTop: (e) => e.spacing(1) }, children: [a.jsx(h, { orientation: "horizontal", sx: { marginTop: (e) => e.spacing(1.5), marginBottom: (e) => e.spacing(0.75) } }), a.jsx(Q, { disabled: t?.isProtected(), styleOptions: t?.getStyleOptions() ?? null, onStyleOptionsChange: (e) => {
t.updateStyleOptions(e);
}, showHeaderRow: t?.getShowHeaders(), onShowHeaderRowChange: (e) => {
try {
t.setShowHeaders(e);
} catch (i) {
l.showError(i);
}
}, showTotalRow: t?.getShowTotals(), onShowTotalRowChange: (e) => {
try {
t.setShowTotals(e);
} catch (i) {
l.showError(i);
}
}, showFilterButton: t?.getFilter() ? t.getShowFilterButton() : null, onShowFilterButtonChange: (e) => {
try {
t.setShowFilterButton(e);
} catch (i) {
l.showError(i);
}
} }), a.jsx(o, { sx: { display: "flex", alignItems: "center", justifyContent: "center", flexDirection: "column", marginTop: (e) => e.spacing(2), marginBottom: (e) => e.spacing(1) }, children: a.jsx(U, { table: t, styles: s.styles(), bodyStyle: s.bodyStyle(), cellHeight: 30, isLive: !0 }) }), a.jsx(h, { orientation: "horizontal" }), a.jsxs(o, { sx: { display: "flex", flexDirection: "column", justifyContent: "center" }, children: [a.jsx(f, { variant: b.Menuitem, command: c.getCommand("convertTableToRange"), commandState: t, icon: y(a.jsx(j, {})) }), a.jsx(f, { variant: b.Menuitem, commandState: t, command: c.getCommand("deleteTable"), icon: y(a.jsx(j, {})) })] })] })] }), p] }) });
});
export {
_ as TableDetailsWindow,
_ as default
};