UNPKG

@sheetxl/studio-vanilla

Version:

SheetXL Studio - Vanilla entry point for integrating SheetXL UI.

148 lines (147 loc) 11.7 kB
import { r as o, U as ee, V as d, E as b, z as W, K as pe, W as de, j as i, i as ue, D as fe, B as h, X as x, o as g, Y as C, k as te, l as v, I as xe, p as S, Z as ne, _ as ge, Q as me, M as he, P as Oe, S as ye } 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 P = { width: "1.5rem", height: "1.5rem" }, V = o.memo((F) => { const { label: c, value: m, options: l, onSelect: O, tabIndex: K = 0, ...$ } = F, [I, y] = o.useState(() => se(m, l)); o.useEffect(() => { y(se(m, l)); }, [m, l]); const j = W((p) => { y(p.target.value), O?.(l[p.target.value]); }, [O, l]), R = o.useMemo(() => Object.keys(l).map((p) => i.jsx(me, { value: p, children: p }, p)), [l]); return i.jsxs(he, { sx: { minWidth: 135 }, size: "small", children: [i.jsx(Oe, { children: c }), i.jsx(ye, { inputProps: { tabIndex: K }, value: I, label: c, onChange: j, sx: { backgroundImage: `linear-gradient(${v("#fff", S(5))}, ${v("#fff", S(5))})` }, ...$, children: R })] }); }), ie = { enter: 140, exit: 140 }, oe = { Formulas: d.Content.Formulas, Values: d.Content.Values, Notes: d.Content.Notes, Comments: d.Content.Comments }, le = { ...oe }; delete le.Values; const Ce = { "By Rows": !0, "By Columns": !1 }, se = (F, c) => { const m = Object.keys(c); for (let l = 0; l < m.length; l++) { const O = m[l]; if (c[O] === F) return O; } }, Re = o.memo((F) => { const { initialValue: c, context: m, onInput: l, title: O, onHide: K, autoFocus: $, ...I } = F, y = c?.replace ?? !1, j = c?.findOptions, R = j.text ?? null, p = c?.replaceOptions, T = c?.replaceText ?? null, D = m?.(), a = o.useRef(null), z = o.useRef(null), L = o.useRef(null), N = o.useRef(null), H = o.useRef(null), U = o.useRef(null), G = (e, t) => { t && (t.start(e, { center: !1 }), setTimeout(() => t.stop(e), 180)); }, [Q, w] = o.useState(!1), [A, ae] = o.useState(!1), [u, B] = o.useState(y), [X, M] = o.useState(!1), [Y, Z] = o.useState(!1), [s, r] = o.useState({ replaceText: null, replace: y, replaceOptions: null, findOptions: { text: null, matchCase: !1, matchEntireCell: !1, useRegex: !1, orientation: b.Orientation.Row, fields: [d.Content.Formulas] }, scope: ee.FindScopeOptions.Sheet }), k = W(async (e, t, n, E) => { if (!D) return; const f = { ...s }; f.replaceOptions = { ...f.replaceOptions }, f.findOptions = { ...f.findOptions }, f.replaceOptions.maxCount = n ? void 0 : 1, f.replace = t, t && s.findOptions.fields?.[0] === d.Content.Values && (f.findOptions.fields = [d.Content.Formulas]), f.findOptions.reverse = !e; const ce = await D({ autoFocus: E, ...f }); M(ce === 0); }, [s, D]); o.useEffect(() => { M(!1); }, [s, A, u]); const _ = W((e, t) => { if (e.keyCode === pe.Enter) { if (!s.findOptions.text) return; let n = !0, E = !1; e.shiftKey && (n = !1), t ? (e.ctrlKey && e.altKey && (E = !0), G(e, E ? U.current : H.current)) : G(e, n ? N.current : L.current), k(n, t, E, !1); } }, [s]), q = o.useRef(null); o.useLayoutEffect(() => { r((e) => { const t = { ...e }; t.findOptions.text = R && R.length > 0 ? R : e.findOptions.text ?? "", w(!0), T !== null && (t.replaceText = T ?? ""), j && (t.findOptions = { ...t.findOptions, ...j }), t.replaceText || (t.replaceText = ""), t.replaceOptions && (t.replaceOptions = { ...t.replaceOptions }), p && (t.replaceOptions = { ...t.replaceOptions, ...p }), s.findOptions.fields?.[0] || (s.findOptions.fields = [d.Content.Formulas]); const n = !(!y && !p && T === null); return n && B(n), t; }), Y || q.current?.focus(); }, [c, y, R, T, j, p]), o.useEffect(() => { u ? (s.findOptions.fields[0], d.Content.Values) : w(!0); }, [u]), o.useEffect(() => { if (Q && a.current && s.findOptions.text === 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 }); }, [Q, s]); const [re, { width: J }] = de(); return i.jsx(ue, { ref: q, title: O ?? (u ? "Find & Replace" : "Find"), initialPosition: { y: "35" }, autoFocusSel: ".input", onHide: K, onFocus: () => Z(!0), onBlur: () => { Z(!1), M(!1); }, slotProps: { paper: { elevation: Y ? 3 : 1 } }, ...I, children: i.jsxs(fe, { dividers: !0, ref: re, 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) B(!0), a.current?.contains(document.activeElement) && z.current?.focus(); else if (e.key === "f" && e.ctrlKey) a.current?.focus(); else if (e.key === "c" && e.altKey) r((t) => { const n = { ...t }; return n.findOptions.matchCase = !t.findOptions.matchCase, n; }); else if (e.key === "e" && e.altKey) r((t) => { const n = { ...t }; return n.findOptions.matchEntireCell = !t.findOptions.matchEntireCell, n; }); else { if (e.key !== "r" || !e.altKey) return; r((t) => { const n = { ...t }; return n.findOptions.useRegex = !t.findOptions.useRegex, n; }); } e.preventDefault(); }, children: [i.jsxs(h, { sx: { display: "flex", flexDirection: "row", gap: (e) => e.spacing(1) }, children: [i.jsxs(h, { sx: { display: "flex", flexDirection: "row", alignItems: "start", gap: (e) => e.spacing(0.25), paddingTop: "3px" }, children: [i.jsx(x, { selected: A, onSelectToggle: (e) => { ae(e); }, preventFocus: !0, label: "Toggle Additional Options", icon: i.jsx(g, { iconKey: "FindOptions" }) }), i.jsx(x, { selected: u, onSelectToggle: (e) => { B(e); }, preventFocus: !0, label: "Toggle Replace", icon: i.jsx(g, { iconKey: "FindReplaceToggle" }), shortcut: { key: u ? "F" : "H", modifiers: [C.Ctrl] } })] }), i.jsxs(h, { sx: { display: "flex", flexDirection: "column", maxWidth: "100%", boxSizing: "border-box" }, children: [i.jsxs(h, { sx: { display: "flex", flexDirection: "row", alignItems: "center" }, children: [i.jsx(te, { label: "Find", slotProps: { input: { sx: { paddingRight: (e) => e.spacing(1), minWidth: J > 460 ? "20em" : void 0, backgroundImage: `linear-gradient(${v("#fff", S(5))}, ${v("#fff", S(5))})` }, endAdornment: i.jsx(xe, { position: "end", children: i.jsxs(h, { sx: { display: "flex", alignItems: "center", flexDirection: "row", gap: "2px" }, children: [i.jsx(x, { style: P, selected: s.findOptions.matchCase, onBlur: () => { }, onSelectToggle: (e) => { r((t) => { const n = { ...t }; return n.findOptions.matchCase = e, n; }); }, label: "Match Case", shortcut: { key: "C", modifiers: [C.Alt] }, icon: i.jsx(g, { iconKey: "FindCaseSensitive", size: "1rem" }) }), i.jsx(x, { style: P, selected: s.findOptions.matchEntireCell, onSelectToggle: (e) => { r((t) => { const n = { ...t }; return n.findOptions.matchEntireCell = e, n; }); }, label: "Match Entire Cell", shortcut: { key: "E", modifiers: [C.Alt] }, icon: i.jsx(g, { iconKey: "FindWholeWord", size: "1rem" }) }), i.jsx(x, { style: P, selected: s.findOptions.useRegex, onSelectToggle: (e) => { r((t) => { const n = { ...t }; return n.findOptions.useRegex = e, n; }); }, label: "Use Regular Expression", shortcut: { key: "R", modifiers: [C.Alt] }, icon: i.jsx(g, { iconKey: "FindRegEx", size: "1rem" }) })] }) }) }, inputLabel: { shrink: !0 }, htmlInput: { 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) } } }, sx: { flex: "1 1 100%", marginRight: (e) => e.spacing(1), "& .MuiOutlinedInput-notchedOutline": { borderColor: (e) => X ? `${e.palette.error.main} !important` : void 0 }, "& .MuiInputLabel-outlined": { color: (e) => X ? `${e.palette.error.main} !important` : void 0 } }, value: s.findOptions.text ?? "", onChange: (e) => { r((t) => { const n = { ...t }; return n.findOptions.text = e.target.value, n; }); }, onKeyDown: (e) => _(e, !1), onContextMenu: (e) => { e.stopPropagation(); } }), i.jsx(x, { selected: s.findOptions.reverse, onSelectToggle: (e) => { k(!1, !1); }, touchRippleRef: L, label: "", shortcut: { key: "Enter", modifiers: [C.Shift] }, icon: i.jsx(g, { iconKey: s.findOptions.orientation !== b.Orientation.Column ? "ArrowBack" : "ArrowUpward" }), disabled: !s.findOptions.text }), i.jsx(x, { selected: !s.findOptions.reverse, onSelectToggle: (e) => { k(!0, !1); }, touchRippleRef: N, label: "Next Match", shortcut: { key: "Enter" }, icon: i.jsx(g, { iconKey: s.findOptions.orientation !== b.Orientation.Column ? "ArrowForward" : "ArrowDownward" }), disabled: !s.findOptions.text })] }), i.jsx(ne, { in: u, timeout: ie, onExit: () => { a.current?.focus(); }, children: i.jsxs(h, { sx: { display: "flex", flexDirection: "row", alignItems: "center", marginTop: (e) => e.spacing(2) }, children: [i.jsx(te, { label: "Replace", slotProps: { input: { sx: { paddingRight: (e) => e.spacing(1), backgroundImage: `linear-gradient(${v("#fff", S(5))}, ${v("#fff", S(5))})` } }, inputLabel: { shrink: !0 }, htmlInput: { ref: z, 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: s.replaceText ?? "", onChange: (e) => { r((t) => { const n = { ...t }; return n.replaceText = e.target.value, n; }); }, onKeyDown: (e) => _(e, !0), onContextMenu: (e) => { e.stopPropagation(); } }), i.jsx(x, { onSelectToggle: (e) => { k(!0, !0); }, touchRippleRef: H, label: "Replace", shortcut: { key: "Enter" }, icon: i.jsx(g, { iconKey: "FindReplace" }), disabled: !s.findOptions.text }), i.jsx(x, { onSelectToggle: (e) => { k(!0, !0, !0); }, touchRippleRef: U, label: "Replace All", shortcut: { key: "Enter", modifiers: [C.Ctrl, C.Alt] }, icon: i.jsx(g, { iconKey: "FindReplaceAll" }), disabled: !s.findOptions.text })] }) })] })] }), i.jsx(ne, { in: A, timeout: ie, onExit: () => { a.current?.focus(); }, children: i.jsxs(h, { sx: { minHeight: "10px", flex: "1 1 100%", display: "flex", flexDirection: "column", gap: (e) => e.spacing(1.5), marginTop: (e) => e.spacing(1) }, children: [i.jsx(ge, { orientation: "horizontal", sx: { marginBottom: (e) => e.spacing(1.5) } }), i.jsxs(h, { sx: { display: "flex", flexDirection: J >= 383 ? "row" : "column", justifyContent: "space-evenly", alignItems: "center", gap: (e) => e.spacing(1), rowGap: (e) => e.spacing(2) }, tabIndex: -1, children: [i.jsx(V, { label: "Within", value: s.scope, options: ee.FindScopeOptions, onSelect: (e) => { r((t) => { const n = { ...t }; return n.scope = e, n; }); } }), i.jsx(V, { label: "Search", value: s.findOptions.orientation !== b.Orientation.Column, options: Ce, onSelect: (e) => { r((t) => { const n = { ...t }; return n.findOptions.orientation = e ? b.Orientation.Row : b.Orientation.Column, n; }); } }), i.jsx(V, { label: "Look in", value: u && s.findOptions.fields?.[0] === d.Content.Values ? d.Content.Formulas : s.findOptions.fields?.[0], options: u ? le : oe, onSelect: (e) => { r((t) => { const n = { ...t }; return n.findOptions.fields = [e], n; }); } })] })] }) })] }) }); }); export { Re as FindReplaceWindow, Re as default };