@sheetxl/studio-vanilla
Version:
SheetXL Studio - Vanilla entry point for integrating SheetXL UI.
148 lines (147 loc) • 11.7 kB
JavaScript
import { o as E, j as t, r as o, p, w as b, T as M, e as le, q as ae, z as re, D as ce, B as O, R as g, s as m, t as pe, Z as j, v as de, l as Z, h as R, x as ue, y as fe, A as xe, E as ge, k as v, G as Q, H as me, J as he, K as Oe, M as je, f as Ce, I as ye, g as be } 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 Re = E(t.jsx("path", { d: "M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20z" }), "ArrowBack"), ve = E(t.jsx("path", { d: "m20 12-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8z" }), "ArrowDownward"), Te = E(t.jsx("path", { d: "m12 4-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z" }), "ArrowForward"), ke = E(t.jsx("path", { d: "m4 12 1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8z" }), "ArrowUpward"), P = o.memo((T) => {
const { label: h, value: c, options: l, onSelect: d, tabIndex: C = 0, ...F } = T, [I, y] = o.useState(() => ee(c, l));
o.useEffect(() => {
y(ee(c, l));
}, [c, l]);
const D = M((u) => {
y(u.target.value), d?.(l[u.target.value]);
}, [d, l]), a = o.useMemo(() => Object.keys(l).map((u) => t.jsx(je, { value: u, children: u }, u)), [l]);
return t.jsxs(Ce, { sx: { minWidth: 135 }, size: "small", children: [t.jsx(ye, { children: h }), t.jsx(be, { inputProps: { tabIndex: C }, value: I, label: h, onChange: D, sx: { backgroundImage: `linear-gradient(${R("#fff", v(5))}, ${R("#fff", v(5))})` }, ...F, children: a })] });
}), Y = { Workbook: "workbook", Sheet: "sheet" }, _ = { enter: 140, exit: 140 }, ne = { Formulas: p.Content.Formulas, Values: p.Content.Values, Notes: p.Content.Notes, Comments: p.Content.Comments }, te = { ...ne };
delete te.Values;
const Se = { "By Rows": !0, "By Columns": !1 }, ee = (T, h) => {
const c = Object.keys(h);
for (let l = 0; l < c.length; l++) {
const d = c[l];
if (h[d] === T) return d;
}
}, Ee = o.memo((T) => {
const { replace: h = !1, findText: c, replaceText: l, findOptions: d, replaceOptions: C, title: F, onHide: I, onFindOrReplace: y, ...D } = T, a = o.useRef(null), u = o.useRef(null), H = o.useRef(null), V = o.useRef(null), $ = o.useRef(null), z = o.useRef(null), B = (e, n) => {
n && (n.start(e, { center: !1 }), setTimeout(() => n.stop(e), 180));
}, [W, w] = o.useState(!1), [L, se] = o.useState(!1), [f, A] = o.useState(h), [N, K] = o.useState(!1), [G, U] = o.useState(!1), [i, r] = o.useState({ findText: null, replaceText: null, replace: h, replaceOptions: {}, findOptions: { matchCase: !1, matchEntireCell: !1, useRegex: !1, orientation: b.Orientation.Row, fields: [p.Content.Formulas] }, scope: Y.Sheet }), k = M(async (e, n, s, S) => {
if (!y) return;
const x = { ...i };
x.replaceOptions = { ...x.replaceOptions }, x.findOptions = { ...x.findOptions }, x.replaceOptions.maxCount = s ? void 0 : 1, x.replace = n, n && i.findOptions.fields?.[0] === p.Content.Values && (x.findOptions.fields = [p.Content.Formulas]), x.findOptions.reverse = !e;
const oe = await y({ autoFocus: S, ...x });
K(oe === 0);
}, [i, y]);
o.useEffect(() => {
K(!1);
}, [i, L, f]);
const q = M((e, n) => {
if (e.keyCode === le.Enter) {
if (!i.findText) return;
let s = !0, S = !1;
e.shiftKey && (s = !1), n ? (e.ctrlKey && e.altKey && (S = !0), B(e, S ? z.current : $.current)) : B(e, s ? V.current : H.current), k(s, n, S, !1);
}
}, [i]), J = o.useRef(null);
o.useLayoutEffect(() => {
r((e) => {
const n = { ...e };
n.findText = c && c.length > 0 ? c : e.findText ?? "", w(!0), l !== void 0 && (n.replaceText = l), d && (n.findOptions = { ...n.findOptions, ...d }), n.replaceText || (n.replaceText = ""), n.replaceOptions && (n.replaceOptions = { ...n.replaceOptions }), C && (n.replaceOptions = { ...n.replaceOptions, ...C }), i.findOptions.fields?.[0] || (i.findOptions.fields = [p.Content.Formulas]);
const s = !(!C && l === void 0);
return s && A(s), n;
}), G || J.current?.focus();
}, [c, l, d, C]), o.useEffect(() => {
f ? (i.findOptions.fields[0], p.Content.Values) : w(!0);
}, [f]), o.useEffect(() => {
if (W && a.current && i.findText === a.current.value) return a.current === document.activeElement || a.current.contains(document.activeElement) ? (a.current?.select(), void w(!1)) : void a.current.addEventListener("focus", () => {
a.current?.select(), w(!1);
}, { once: !0 });
}, [W, i]);
const [ie, { width: X }] = ae();
return t.jsx(re, { ref: J, title: F ?? (f ? "Find & Replace" : "Find"), initialPosition: { y: "35" }, autoFocusSel: ".input", onHide: I, onFocus: () => U(!0), onBlur: () => {
U(!1), K(!1);
}, PaperProps: { elevation: G ? 3 : 1 }, ...D, children: t.jsxs(ce, { dividers: !0, ref: ie, sx: { display: "flex", flexDirection: "column", paddingLeft: (e) => e.spacing(1.5), paddingRight: (e) => e.spacing(1.5) }, onKeyDown: (e) => {
if (e.key === "h" && e.ctrlKey) A(!0), a.current?.contains(document.activeElement) && u.current?.focus();
else if (e.key === "f" && e.ctrlKey) a.current?.focus();
else if (e.key === "c" && e.altKey) r((n) => {
const s = { ...n };
return s.findOptions.matchCase = !n.findOptions.matchCase, s;
});
else if (e.key === "e" && e.altKey) r((n) => {
const s = { ...n };
return s.findOptions.matchEntireCell = !n.findOptions.matchEntireCell, s;
});
else {
if (e.key !== "r" || !e.altKey) return;
r((n) => {
const s = { ...n };
return s.findOptions.useRegex = !n.findOptions.useRegex, s;
});
}
e.preventDefault();
}, children: [t.jsxs(O, { sx: { display: "flex", flexDirection: "row", gap: (e) => e.spacing(1) }, children: [t.jsxs(O, { sx: { display: "flex", flexDirection: "row", alignItems: "start", gap: (e) => e.spacing(0.25), paddingTop: "3px" }, children: [t.jsx(g, { selected: L, onSelectToggle: (e) => {
se(e);
}, preventFocus: !0, label: "Toggle Additional Options", icon: m(t.jsx(pe, {})) }), t.jsx(g, { selected: f, onSelectToggle: (e) => {
A(e);
}, preventFocus: !0, label: "Toggle Replace", icon: m(t.jsx(de, {})), shortcut: { key: f ? "F" : "H", modifiers: [j.Ctrl] } })] }), t.jsxs(O, { sx: { display: "flex", flexDirection: "column", maxWidth: "100%", boxSizing: "border-box" }, children: [t.jsxs(O, { sx: { display: "flex", flexDirection: "row", alignItems: "center" }, children: [t.jsx(Z, { label: "Find", InputLabelProps: { shrink: !0 }, InputProps: { sx: { paddingRight: (e) => e.spacing(1), minWidth: X > 460 ? "20em" : void 0, backgroundImage: `linear-gradient(${R("#fff", v(5))}, ${R("#fff", v(5))})` }, inputProps: { draggable: !1, ref: a, className: "input", autoFocus: !0, spellCheck: !1, autoComplete: "off", sx: { paddingTop: (e) => e.spacing(1.25), paddingBottom: (e) => e.spacing(0.75) } }, endAdornment: t.jsx(ue, { sx: { transform: "scale(0.75) translateX(16px)" }, position: "end", children: t.jsxs(O, { sx: { display: "flex", alignItems: "center", flexDirection: "row", gap: "1px" }, children: [t.jsx(g, { selected: i.findOptions.matchCase, onSelectToggle: (e) => {
r((n) => {
const s = { ...n };
return s.findOptions.matchCase = e, s;
});
}, label: "Match Case", shortcut: { key: "C", modifiers: [j.Alt] }, icon: m(t.jsx(fe, {})) }), t.jsx(g, { selected: i.findOptions.matchEntireCell, onSelectToggle: (e) => {
r((n) => {
const s = { ...n };
return s.findOptions.matchEntireCell = e, s;
});
}, label: "Match Entire Cell", shortcut: { key: "E", modifiers: [j.Alt] }, icon: m(t.jsx(xe, {})) }), t.jsx(g, { selected: i.findOptions.useRegex, onSelectToggle: (e) => {
r((n) => {
const s = { ...n };
return s.findOptions.useRegex = e, s;
});
}, label: "Use Regular Expression", shortcut: { key: "R", modifiers: [j.Alt] }, icon: m(t.jsx(ge, {})) })] }) }) }, sx: { flex: "1 1 100%", marginRight: (e) => e.spacing(1), "& .MuiOutlinedInput-notchedOutline": { borderColor: (e) => N ? `${e.palette.error.main} !important` : void 0 }, "& .MuiInputLabel-outlined": { color: (e) => N ? `${e.palette.error.main} !important` : void 0 } }, value: i.findText ?? "", onChange: (e) => {
r((n) => {
const s = { ...n };
return s.findText = e.target.value, s;
});
}, onKeyDown: (e) => q(e, !1), onContextMenu: (e) => {
e.stopPropagation();
} }), t.jsx(g, { selected: i.findOptions.reverse, onSelectToggle: (e) => {
k(!1, !1);
}, touchRippleRef: H, label: "", shortcut: { key: "Enter", modifiers: [j.Shift] }, icon: m(i.findOptions.orientation !== b.Orientation.Column ? t.jsx(Re, {}) : t.jsx(ke, {})), disabled: !i.findText }), t.jsx(g, { selected: !i.findOptions.reverse, onSelectToggle: (e) => {
k(!0, !1);
}, touchRippleRef: V, label: "Next Match", shortcut: { key: "Enter" }, icon: m(i.findOptions.orientation !== b.Orientation.Column ? t.jsx(Te, {}) : t.jsx(ve, {})), disabled: !i.findText })] }), t.jsx(Q, { in: f, timeout: _, onExit: () => {
a.current?.focus();
}, children: t.jsxs(O, { sx: { display: "flex", flexDirection: "row", alignItems: "center", marginTop: (e) => e.spacing(2) }, children: [t.jsx(Z, { label: "Replace", InputLabelProps: { shrink: !0 }, InputProps: { sx: { paddingRight: (e) => e.spacing(1), backgroundImage: `linear-gradient(${R("#fff", v(5))}, ${R("#fff", v(5))})` }, inputProps: { ref: u, className: "input", spellCheck: !1, autoComplete: "off", sx: { paddingTop: (e) => e.spacing(1.25), paddingBottom: (e) => e.spacing(0.75) } } }, sx: { flex: "1 1 100%", marginRight: (e) => e.spacing(1) }, value: i.replaceText ?? "", onChange: (e) => {
r((n) => {
const s = { ...n };
return s.replaceText = e.target.value, s;
});
}, onKeyDown: (e) => q(e, !0), onContextMenu: (e) => {
e.stopPropagation();
} }), t.jsx(g, { onSelectToggle: (e) => {
k(!0, !0);
}, touchRippleRef: $, label: "Replace", shortcut: { key: "Enter" }, icon: m(t.jsx(me, {})), disabled: !i.findText }), t.jsx(g, { onSelectToggle: (e) => {
k(!0, !0, !0);
}, touchRippleRef: z, label: "Replace All", shortcut: { key: "Enter", modifiers: [j.Ctrl, j.Alt] }, icon: m(t.jsx(he, {})), disabled: !i.findText })] }) })] })] }), t.jsx(Q, { in: L, timeout: _, onExit: () => {
a.current?.focus();
}, children: t.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: [t.jsx(Oe, { orientation: "horizontal", sx: { marginBottom: (e) => e.spacing(1.5) } }), t.jsxs(O, { sx: { display: "flex", flexDirection: X >= 413 ? "row" : "column", justifyContent: "space-evenly", alignItems: "center", rowGap: (e) => e.spacing(2) }, tabIndex: -1, children: [t.jsx(P, { label: "Within", value: i.scope, options: Y, onSelect: (e) => {
r((n) => {
const s = { ...n };
return s.scope = e, s;
});
} }), t.jsx(P, { label: "Search", value: i.findOptions.orientation !== b.Orientation.Column, options: Se, onSelect: (e) => {
r((n) => {
const s = { ...n };
return s.findOptions.orientation = e ? b.Orientation.Row : b.Orientation.Column, s;
});
} }), t.jsx(P, { label: "Look in", value: f && i.findOptions.fields?.[0] === p.Content.Values ? p.Content.Formulas : i.findOptions.fields?.[0], options: f ? te : ne, onSelect: (e) => {
r((n) => {
const s = { ...n };
return s.findOptions.fields = [e], s;
});
} })] })] }) })] }) });
});
export {
Ee as FindReplaceWindow,
Y as ScopeOptions,
Ee as default
};