var at = Object.defineProperty; var ot = (t, e, n) => e in t ? at(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n; var l = (t, e, n) => ot(t, typeof e != "symbol" ? e + "" : e, n); import { createIdentifier as ct, Inject as F, Injector as Q, Disposable as X, DisposableCollection as lt, toDisposable as $, IUniverInstanceService as ge, IContextService as ee, CommandType as y, LocaleService as w, useDependency as C, ICommandService as te, FOCUSING_SHEET as me, EDITOR_ACTIVATED as ve, UniverInstanceType as dt, RxDisposable as ut, Plugin as ht, merge as ft, IConfigService as pt } from "@univerjs/core"; import { IConfirmService as _t, IMessageService as Se, useObservable as D, ILayoutService as Ce, KeyCode as b, MetaKeys as x, MenuItemType as gt, getMenuHiddenObservable as mt, RibbonStartGroup as vt, ComponentManager as St, IMenuManagerService as Ct, IShortcutService as Rt, IDialogService as Mt } from "@univerjs/ui"; import { throttleTime as bt, BehaviorSubject as P, combineLatest as Re, debounceTime as xt, Subject as Me, fromEvent as yt, map as It, takeUntil as oe } from "rxjs"; import { MessageType as E, InputWithSlot as Ft, Pager as Dt, Button as N, FormLayout as M, Input as Pt, Select as G, FormDualColumnLayout as ce, Checkbox as le } from "@univerjs/design"; import { RENDER_RAW_FORMULA_KEY as Ot } from "@univerjs/engine-render"; import Tt, { forwardRef as U, useRef as H, createElement as be, useCallback as p, useEffect as A, useMemo as ie, useImperativeHandle as Et } from "react"; const Nt = "find-replace.config", de = {}; var g = function() { return g = Object.assign || function(t) { for (var e, n = 1, i = arguments.length; n < i; n++) { e = arguments[n]; for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && (t[r] = e[r]); } return t; }, g.apply(this, arguments); }, $t = function(t, e) { var n = {}; for (var i in t) Object.prototype.hasOwnProperty.call(t, i) && e.indexOf(i) < 0 && (n[i] = t[i]); if (t != null && typeof Object.getOwnPropertySymbols == "function") for (var r = 0, i = Object.getOwnPropertySymbols(t); r < i.length; r++) e.indexOf(i[r]) < 0 && Object.prototype.propertyIsEnumerable.call(t, i[r]) && (n[i[r]] = t[i[r]]); return n; }, xe = U(function(t, e) { var n = t.icon, i = t.id, r = t.className, s = t.extend, a = $t(t, ["icon", "id", "className", "extend"]), d = "univerjs-icon univerjs-icon-".concat(i, " ").concat(r || "").trim(), c = H("_".concat(jt())); return ye(n, "".concat(i), { defIds: n.defIds, idSuffix: c.current }, g({ ref: e, className: d }, a), s); }); function ye(t, e, n, i, r) { return be(t.tag, g(g({ key: e }, At(t, n, r)), i), (Lt(t, n).children || []).map(function(s, a) { return ye(s, "".concat(e, "-").concat(t.tag, "-").concat(a), n, void 0, r); })); } function At(t, e, n) { var i = g({}, t.attrs); n != null && n.colorChannel1 && i.fill === "colorChannel1" && (i.fill = n.colorChannel1); var r = e.defIds; return !r || r.length === 0 || (t.tag === "use" && i["xlink:href"] && (i["xlink:href"] = i["xlink:href"] + e.idSuffix), Object.entries(i).forEach(function(s) { var a = s[0], d = s[1]; typeof d == "string" && (i[a] = d.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")"))); })), i; } function Lt(t, e) { var n, i = e.defIds; return !i || i.length === 0 ? t : t.tag === "defs" && (!((n = t.children) === null || n === void 0) && n.length) ? g(g({}, t), { children: t.children.map(function(r) { return typeof r.attrs.id == "string" && i && i.indexOf(r.attrs.id) > -1 ? g(g({}, r), { attrs: g(g({}, r.attrs), { id: r.attrs.id + e.idSuffix }) }) : r; }) }) : t; } function jt() { return Math.random().toString(36).substring(2, 8); } xe.displayName = "UniverIcon"; var wt = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 17 17", width: "1em", height: "1em" }, children: [{ tag: "mask", attrs: { id: "mask0_217_40", style: { maskType: "alpha" }, width: 17, height: 17, x: 0, y: 0, maskUnits: "userSpaceOnUse" }, children: [{ tag: "path", attrs: { fill: "#D9D9D9", d: "M0.9 0.09H16.9V16.09H0.9z" } }] }, { tag: "g", attrs: { mask: "url(#mask0_217_40)" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M2.39551 7.37266C2.39551 4.18105 4.98281 1.59375 8.17441 1.59375C11.366 1.59375 13.9533 4.18105 13.9533 7.37266C13.9533 8.72342 13.4898 9.96603 12.7133 10.95L15.1964 13.4331C15.4619 13.6986 15.4619 14.1291 15.1964 14.3946C14.9309 14.6601 14.5004 14.6601 14.2349 14.3946L11.7518 11.9115C10.7678 12.6881 9.52525 13.1516 8.17441 13.1516C4.98281 13.1516 2.39551 10.5642 2.39551 7.37266ZM8.17441 2.95349C5.73378 2.95349 3.75525 4.93202 3.75525 7.37266C3.75525 9.81333 5.73378 11.7918 8.17441 11.7918C10.6151 11.7918 12.5936 9.81333 12.5936 7.37266C12.5936 4.93202 10.6151 2.95349 8.17441 2.95349Z", fillRule: "evenodd", clipRule: "evenodd" } }] }] }, Ie = U(function(t, e) { return be(xe, Object.assign({}, t, { id: "search-single-16", ref: e, icon: wt })); }); Ie.displayName = "SearchSingle16"; const Fe = "FIND_REPLACE_INPUT_FOCUS", De = "FIND_REPLACE_DIALOG_FOCUS", Pe = "FIND_REPLACE_REPLACE_REVEALED"; var Ut = Object.defineProperty, Bt = Object.getOwnPropertyDescriptor, Oe = (t, e, n, i) => { for (var r = i > 1 ? void 0 : i ? Bt(e, n) : e, s = t.length - 1, a; s >= 0; s--) (a = t[s]) && (r = (i ? a(e, n, r) : a(r)) || r); return i && r && Ut(e, n, r), r; }, q = (t, e) => (n, i) => e(n, i, t); class Di extends X { } const m = ct("find-replace.service"); function Wt(t) { return typeof t.findString < "u" || typeof t.inputtingFindString < "u" || typeof t.findDirection < "u" || typeof t.matchesTheWholeCell < "u" || typeof t.caseSensitive < "u" || typeof t.findScope < "u" || typeof t.findBy < "u"; } let J = class extends X { constructor(e, n, i) { super(); l(this, "currentMatch$", new P(null)); l(this, "replaceables$", new P([])); /** All find models returned by providers. */ l(this, "_findModels", []); /** The find model that the current match is from. */ l(this, "_matchingModel", null); l(this, "_matches", []); l(this, "_currentSearchingDisposables", null); this._state = e, this._providers = n, this._univerInstanceService = i, this.disposeWithMe( this._state.stateUpdates$.pipe(bt(200, void 0, { leading: !0, trailing: !0 })).subscribe(async (r) => { const s = this._state.state; Wt(r) && (s.findString !== "" && !s.replaceRevealed ? (await this._startSearching(), this._state.changeState({ findCompleted: !0 })) : r.replaceRevealed !== !0 && this._stopSearching()); }) ); } get searched() { return this._findModels.length > 0; } dispose() { super.dispose(), this._stopSearching(), this.currentMatch$.complete(), this.replaceables$.complete(), this._state.changeState({ ...ne(), revealed: !1 }); } async start() { if (!this._state.findString) return { results: [] }; const e = await this._startSearching(); return this._state.changeState({ findCompleted: !0 }), e; } /** Call this method to start a `searching`. */ async _startSearching() { if (!this._state.findString) return { results: [] }; const e = Array.from(this._providers), n = this._findModels = (await Promise.all(e.map((r) => r.find({ findString: this._state.findString, findDirection: this._state.findDirection, findScope: this._state.findScope, findBy: this._state.findBy, replaceRevealed: this._state.replaceRevealed, caseSensitive: this._state.caseSensitive, matchesTheWholeCell: this._state.matchesTheWholeCell })))).flat(); this._subscribeToModelsChanges(n); const i = this._matches = n.map((r) => r.getMatches()).flat(); return this.replaceables$.next(i.filter((r) => r.replaceable)), i.length ? (this._moveToInitialMatch(n), this._state.changeState({ matchesCount: i.length }), { results: i }) : (this._state.changeState({ matchesCount: 0, matchesPosition: 0 }), { results: [] }); } /** Terminate the current searching session, when searching string is empty. */ _stopSearching() { var e; this._providers.forEach((n) => n.terminate()), this._findModels = [], this._matches = [], this._matchingModel = null, (e = this._currentSearchingDisposables) == null || e.dispose(), this._currentSearchingDisposables = null, this.currentMatch$.next(null), this.replaceables$.next([]), this._state.changeState({ findCompleted: !1, matchesCount: 0, matchesPosition: 0 }); } // When a document's content changes, we should reset all matches and try to move to the next match. _subscribeToModelsChanges(e) { const n = this._currentSearchingDisposables = new lt(), i = Re(e.map((r) => r.matchesUpdate$)).pipe(xt(220)).subscribe(([...r]) => { const s = this._matches = r.flat(); s.length ? (this._moveToInitialMatch(this._findModels, !0), this._state.changeState({ matchesCount: s.length }), this.replaceables$.next(s.filter((a) => a.replaceable))) : (this._state.changeState({ matchesCount: 0, matchesPosition: 0 }), this.replaceables$.next([])); }); e.forEach((r) => n.add($(r.activelyChangingMatch$.subscribe((s) => { const a = this._matches.findIndex((d) => d === s); this._state.changeState({ matchesPosition: a + 1 }); })))), n.add($(i)); } async replace() { return this._matchingModel ? this._matchingModel.replace(this._state.replaceString) : !1; } async replaceAll() { const e = await Promise.all(this._findModels.map((n) => n.replaceAll(this._state.replaceString))).then((n) => n.reduce((i, r) => (i.success += r.success, i.failure += r.failure, i), { success: 0, failure: 0 })); return e.failure === 0 && this._stopSearching(), e; } getCurrentMatch() { return this._state.matchesPosition > 0 ? this._matches[this._state.matchesPosition - 1] : null; } _markMatch(e) { const n = this._matches.findIndex((i) => i === e); this.currentMatch$.next(e), this._state.changeState({ matchesPosition: n + 1 }); } moveToNextMatch() { if (!this._matchingModel) return; const e = this._findModels.length === 1, n = this._matchingModel.moveToNextMatch({ loop: e }); if (n) return this._markMatch(n), n; { const i = this._findModels.findIndex((r) => r === this._matchingModel); return this._moveToNextUnitMatch(i); } } _moveToNextUnitMatch(e) { const n = this._findModels.length; for (let i = (e + 1) % n; i !== e; ) { const r = this._findModels[i], s = r.moveToNextMatch({ ignoreSelection: !0 }); if (s) return this._matchingModel = r, this._markMatch(s), s; i = (i + 1) % n; } if (this._matchingModel) { const i = this._matchingModel.moveToNextMatch({ ignoreSelection: !0 }); return i && this._markMatch(i), i; } } moveToPreviousMatch() { if (!this._matchingModel) return; const e = this._findModels.length === 1, n = this._matchingModel.moveToPreviousMatch({ loop: e }); if (n) { const i = this._matches.findIndex((r) => r === n); return this.currentMatch$.next(n), this._state.changeState({ matchesPosition: i + 1 }), n; } else { const i = this._findModels.length, r = this._findModels.findIndex((a) => a === this._matchingModel); for (let a = (r - 1 + i) % i; a !== r; ) { const d = this._findModels[a], c = d.moveToPreviousMatch({ ignoreSelection: !0 }); if (c) return this._matchingModel = d, this._markMatch(c), c; a = (a - 1) % i; } const s = this._matchingModel.moveToPreviousMatch({ ignoreSelection: !0 }); return s && this._markMatch(s), s; } } _moveToInitialMatch(e, n = !1) { var s; const i = (s = this._univerInstanceService.getFocusedUnit()) == null ? void 0 : s.getUnitId(); if (!i) return -1; const r = e.findIndex((a) => a.unitId === i); if (r !== -1) { this._matchingModel = e[r]; const a = this._matchingModel.moveToNextMatch({ stayIfOnMatch: !0, noFocus: n }); if (a) return this._markMatch(a), r; } return this._moveToNextUnitMatch(r), 0; } }; J = Oe([ q(2, ge) ], J); var K = /* @__PURE__ */ ((t) => (t.ROW = "row", t.COLUMN = "column", t))(K || {}), z = /* @__PURE__ */ ((t) => (t.VALUE = "value", t.FORMULA = "formula", t))(z || {}), Y = /* @__PURE__ */ ((t) => (t.SUBUNIT = "subunit", t.UNIT = "unit", t))(Y || {}); function ne() { return { caseSensitive: !1, findBy: "value", findCompleted: !1, findDirection: "row", findScope: "subunit", findString: "", inputtingFindString: "", matchesCount: 0, matchesPosition: 0, matchesTheWholeCell: !1, replaceRevealed: !1, replaceString: "", revealed: !0 }; } class Gt { constructor() { l(this, "_stateUpdates$", new Me()); l(this, "stateUpdates$", this._stateUpdates$.asObservable()); l(this, "_state$", new P(ne())); l(this, "state$", this._state$.asObservable()); l(this, "_findString", ""); l(this, "_inputtingFindString", ""); l(this, "_replaceString", ""); l(this, "_revealed", !1); l(this, "_replaceRevealed", !1); l(this, "_matchesPosition", 0); l(this, "_matchesCount", 0); l(this, "_caseSensitive", !0); l(this, "_matchesTheWholeCell", !1); l(this, "_findDirection", "row"); l(this, "_findScope", "subunit"); l(this, "_findBy", "value"); l(this, "_findCompleted", !1); } get state() { return this._state$.getValue(); } get inputtingFindString() { return this._inputtingFindString; } get findString() { return this._findString; } get revealed() { return this._revealed; } get replaceRevealed() { return this._replaceRevealed; } get matchesPosition() { return this._matchesPosition; } get matchesCount() { return this._matchesCount; } get replaceString() { return this._replaceString; } get caseSensitive() { return this._caseSensitive; } get matchesTheWholeCell() { return this._matchesTheWholeCell; } get findDirection() { return this._findDirection; } get findScope() { return this._findScope; } get findBy() { return this._findBy; } get findCompleted() { return this._findCompleted; } // eslint-disable-next-line max-lines-per-function, complexity changeState(e) { let n = !1; const i = {}; typeof e.findString < "u" && e.findString !== this._findString && (this._findString = e.findString, i.findString = this._findString, n = !0), typeof e.revealed < "u" && e.revealed !== this._revealed && (this._revealed = e.revealed, i.revealed = e.revealed, n = !0), typeof e.replaceRevealed < "u" && e.replaceRevealed !== this._replaceRevealed && (this._replaceRevealed = e.replaceRevealed, i.replaceRevealed = e.replaceRevealed, n = !0), typeof e.replaceString < "u" && e.replaceString !== this._replaceString && (this._replaceString = e.replaceString, i.replaceString = e.replaceString, n = !0), typeof e.matchesCount < "u" && e.matchesCount !== this._matchesCount && (this._matchesCount = e.matchesCount, i.matchesCount = e.matchesCount, n = !0), typeof e.matchesPosition < "u" && e.matchesPosition !== this._matchesPosition && (this._matchesPosition = e.matchesPosition, i.matchesPosition = e.matchesPosition, n = !0), typeof e.findBy < "u" && e.findBy !== this._findBy && (this._findBy = e.findBy, i.findBy = e.findBy, n = !0), typeof e.findScope < "u" && e.findScope !== this._findScope && (this._findScope = e.findScope, i.findScope = e.findScope, n = !0), typeof e.findDirection < "u" && e.findDirection !== this._findDirection && (this._findDirection = e.findDirection, i.findDirection = e.findDirection, n = !0), typeof e.caseSensitive < "u" && e.caseSensitive !== this._caseSensitive && (this._caseSensitive = e.caseSensitive, i.caseSensitive = e.caseSensitive, n = !0), typeof e.matchesTheWholeCell < "u" && e.matchesTheWholeCell !== this._matchesTheWholeCell && (this._matchesTheWholeCell = e.matchesTheWholeCell, i.matchesTheWholeCell = e.matchesTheWholeCell, n = !0), typeof e.inputtingFindString < "u" && e.inputtingFindString !== this._inputtingFindString && (this._inputtingFindString = e.inputtingFindString, i.inputtingFindString = e.inputtingFindString, n = !0), typeof e.findCompleted < "u" && e.findCompleted !== this._findCompleted && (this._findCompleted = e.findCompleted, i.findCompleted = e.findCompleted, n = !0), n && (this._state$.next({ caseSensitive: this._caseSensitive, findBy: this._findBy, findCompleted: this._findCompleted, findDirection: this._findDirection, findScope: this._findScope, findString: this._findString, inputtingFindString: this._inputtingFindString, matchesCount: this._matchesCount, matchesPosition: this._matchesPosition, matchesTheWholeCell: this._matchesTheWholeCell, replaceRevealed: this._replaceRevealed, revealed: this._revealed }), this._stateUpdates$.next(i)); } } let Z = class extends X { constructor(e, n) { super(); l(this, "_providers", /* @__PURE__ */ new Set()); l(this, "_state", new Gt()); l(this, "_model"); l(this, "_currentMatch$", new P(null)); l(this, "currentMatch$", this._currentMatch$.asObservable()); l(this, "_replaceables$", new P([])); l(this, "replaceables$", this._replaceables$.asObservable()); l(this, "_focusSignal$", new Me()); l(this, "focusSignal$", this._focusSignal$.asObservable()); this._injector = e, this._contextService = n; } get stateUpdates$() { return this._state.stateUpdates$; } get state$() { return this._state.state$; } get revealed() { return this._state.revealed; } get replaceRevealed() { return this._state.replaceRevealed; } dispose() { super.dispose(), this._currentMatch$.next(null), this._currentMatch$.complete(), this._replaceables$.next([]), this._replaceables$.complete(), this._focusSignal$.complete(); } getProviders() { return this._providers; } getCurrentMatch() { var e; return (e = this._model) == null ? void 0 : e.getCurrentMatch(); } getFindString() { return this._state.findString; } changeFindString(e) { this._state.changeState({ findString: e }); } focusFindInput() { this._focusSignal$.next(); } changeInputtingFindString(e) { e ? this._state.changeState({ inputtingFindString: e }) : this._state.changeState({ inputtingFindString: "", findString: "" }); } changeReplaceString(e) { this._state.changeState({ replaceString: e }); } changeMatchesTheWholeCell(e) { this._state.changeState({ matchesTheWholeCell: e }); } changeCaseSensitive(e) { this._state.changeState({ caseSensitive: e }); } changeFindBy(e) { this._state.changeState({ findBy: e }), this._toggleDisplayRawFormula( e === "formula" /* FORMULA */ ); } changeFindScope(e) { this._state.changeState({ findScope: e }); } changeFindDirection(e) { this._state.changeState({ findDirection: e }); } moveToNextMatch() { this._model && (this._state.replaceRevealed && !this._model.searched ? (this._state.changeState({ findString: this._state.inputtingFindString }), this._model.start()) : this._model.moveToNextMatch(), this._focusSignal$.next()); } moveToPreviousMatch() { this._model && (this._state.replaceRevealed && !this._model.searched ? (this._state.changeState({ findString: this._state.inputtingFindString }), this._model.start()) : this._model.moveToPreviousMatch(), this._focusSignal$.next()); } async replace() { return this._model ? this._model.replace() : !1; } async replaceAll() { if (!this._model) throw new Error("[FindReplaceService] replaceAll: model is not initialized!"); return this._model.replaceAll(); } revealReplace() { this._state.changeState({ replaceRevealed: !0, inputtingFindString: this._state.findString }), this._toggleRevealReplace(!0); } start(e = !1) { if (this._providers.size === 0) return !1; this._model = this._injector.createInstance(J, this._state, this._providers), this._model.currentMatch$.subscribe((i) => this._currentMatch$.next(i)), this._model.replaceables$.subscribe((i) => this._replaceables$.next(i)); const n = ne(); return e && (n.replaceRevealed = !0), this._state.changeState(n), this._toggleRevealReplace(e), !0; } find() { var e; (e = this._model) == null || e.start(); } terminate() { var e; (e = this._model) == null || e.dispose(), this._model = null, this._toggleDisplayRawFormula(!1), this._toggleRevealReplace(!1); } registerFindReplaceProvider(e) { return this._providers.add(e), $(() => this._providers.delete(e)); } _toggleRevealReplace(e) { this._contextService.setContextValue(Pe, e); } _toggleDisplayRawFormula(e) { this._contextService.setContextValue(Ot, e); } }; Z = Oe([ q(0, F(Q)), q(1, ee) ], Z); const Te = { id: "ui.command.replace-current-match", type: y.COMMAND, handler: (t) => t.get(m).replace() }, kt = "CONFIRM_REPLACE_ALL", Ee = { id: "ui.command.replace-all-matches", type: y.COMMAND, handler: async (t) => { const e = t.get(_t), n = t.get(w), i = t.get(Se); if (!await e.confirm({ id: kt, title: { title: n.t("find-replace.replace.confirm.title") }, cancelText: n.t("button.cancel"), confirmText: n.t("button.confirm") })) return !1; const s = await t.get(m).replaceAll(), { success: a, failure: d } = s; return d > 0 ? (a === 0 ? i.show({ type: E.Error, content: n.t("find-replace.replace.all-failure") }) : i.show({ type: E.Warning, content: n.t("find-replace.replace.partial-success", `${a}`, `${d}`) }), !1) : (i.show({ type: E.Success, content: n.t("find-replace.replace.all-success", `${a}`) }), !0); } }, O = { id: "ui.operation.open-find-dialog", type: y.OPERATION, handler: (t) => { const e = t.get(m); return e.revealed ? e.focusFindInput() : e.start(), !0; } }, re = { id: "ui.operation.open-replace-dialog", type: y.OPERATION, handler: (t) => { const e = t.get(m); return e.revealed ? e.replaceRevealed ? e.focusFindInput() : e.revealReplace() : e.start(!0), !0; } }, Ne = { type: y.OPERATION, id: "ui.operation.go-to-next-match", handler: (t) => (t.get(m).moveToNextMatch(), !0) }, $e = { type: y.OPERATION, id: "ui.operation.go-to-previous-match", handler: (t) => (t.get(m).moveToPreviousMatch(), !0) }; var k = { exports: {} }, I = {}; /** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var ue; function Vt() { if (ue) return I; ue = 1; var t = Tt, e = Symbol.for("react.element"), n = Symbol.for("react.fragment"), i = Object.prototype.hasOwnProperty, r = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, s = { key: !0, ref: !0, __self: !0, __source: !0 }; function a(d, c, _) { var u, h = {}, R = null, v = null; _ !== void 0 && (R = "" + _), c.key !== void 0 && (R = "" + c.key), c.ref !== void 0 && (v = c.ref); for (u in c) i.call(c, u) && !s.hasOwnProperty(u) && (h[u] = c[u]); if (d && d.defaultProps) for (u in c = d.defaultProps, c) h[u] === void 0 && (h[u] = c[u]); return { $$typeof: e, type: d, key: R, ref: v, props: h, _owner: r.current }; } return I.Fragment = n, I.jsx = a, I.jsxs = a, I; } var he; function Ht() { return he || (he = 1, k.exports = Vt()), k.exports; } var o = Ht(); const qt = "univer-find-replace-dialog-container", Jt = "univer-find-replace-expand-container", Kt = "univer-button-text", zt = "univer-find-replace-buttons-group", Yt = "univer-find-replace-buttons-group-right", L = { findReplaceDialogContainer: qt, findReplaceExpandContainer: Jt, buttonText: Kt, findReplaceButtonsGroup: zt, findReplaceButtonsGroupRight: Yt }; function Ae(t) { const { findCompleted: e, localeService: n, matchesCount: i, matchesPosition: r, findString: s, findReplaceService: a, onChange: d, ...c } = t, u = e && i === 0 ? n.t("find-replace.dialog.no-result") : i === 0 ? " " : void 0; return /* @__PURE__ */ o.jsx( Ft, { autoFocus: !0, placeholder: n.t("find-replace.dialog.find-placeholder"), slot: /* @__PURE__ */ o.jsx( Dt, { loop: !0, text: u, value: r, total: i, onChange: (h) => { r === i && h === 1 ? a.moveToNextMatch() : r === 1 && h === i || h < r ? a.moveToPreviousMatch() : a.moveToNextMatch(); } } ), value: s, onChange: (h) => d == null ? void 0 : d(h), ...c } ); } function Le(t, e) { const n = p(() => { var r; (r = document.querySelector(".univer-find-input input")) == null || r.focus(); }, []), i = p(() => { const r = document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input"); return Array.from(r).some((s) => s === document.activeElement); }, []); return Et(e, () => ({ focus: n, selectHasFocus: i })), A(() => { const r = t.focusSignal$.subscribe(() => n()); return () => r.unsubscribe(); }, [t, n]), { focus: n, selectHasFocus: i }; } const Zt = U(function(e, n) { const i = C(w), r = C(m), s = C(te), a = D(r.state$, void 0, !0), { findCompleted: d, findString: c, matchesCount: _, matchesPosition: u } = a, h = p(() => { s.executeCommand(re.id); }, [s]), R = p((v) => r.changeFindString(v), [r]); return Le(r, n), /* @__PURE__ */ o.jsxs(o.Fragment, { children: [ /* @__PURE__ */ o.jsx( Ae, { findCompleted: d, className: "univer-find-input", matchesCount: _, matchesPosition: u, findReplaceService: r, localeService: i, findString: c, onChange: R } ), /* @__PURE__ */ o.jsx("div", { className: L.findReplaceExpandContainer, children: /* @__PURE__ */ o.jsx(N, { type: "text", size: "small", onClick: h, children: i.t("find-replace.dialog.advanced-finding") }) }) ] }); }), Qt = U(function(e, n) { const i = C(m), r = C(w), s = C(te), a = C(Se), d = D(i.currentMatch$, void 0, !0), c = D(i.replaceables$, void 0, !0), _ = D(i.state$, void 0, !0), { matchesCount: u, matchesPosition: h, findString: R, inputtingFindString: v, replaceString: Ue, caseSensitive: Be, matchesTheWholeCell: We, findDirection: Ge, findScope: ke, findBy: Ve, findCompleted: W } = _, He = v.length === 0, qe = u === 0 || !(d != null && d.replaceable), Je = c.length === 0, Ke = p( (f) => i.changeInputtingFindString(f), [i] ), ze = p( (f) => i.changeReplaceString(f), [i] ), { focus: Ye } = Le(i, n), Ze = p(() => { R === v ? i.moveToNextMatch() : (i.changeFindString(v), i.find()); }, [R, v, i]), Qe = p(() => s.executeCommand(Te.id), [s]), Xe = p(async () => { await s.executeCommand(Ee.id), Ye(); }, [s]), et = p((f) => { i.changeFindDirection(f); }, [i]), tt = p((f) => { i.changeFindScope(f); }, [i]), it = p((f) => { i.changeFindBy(f); }, [i]), nt = ei(r), rt = ti(r), st = ii(r); return A(() => { W && u === 0 && a.show({ content: r.t("find-replace.dialog.no-match"), type: E.Warning, duration: 5e3 }); }, [W, u, a, r]), /* @__PURE__ */ o.jsxs(o.Fragment, { children: [ /* @__PURE__ */ o.jsx(M, { label: r.t("find-replace.dialog.find"), children: /* @__PURE__ */ o.jsx( Ae, { findCompleted: W, className: "univer-find-input", matchesCount: u, matchesPosition: h, findReplaceService: i, localeService: r, findString: v, onChange: Ke } ) }), /* @__PURE__ */ o.jsx(M, { label: r.t("find-replace.dialog.replace"), children: /* @__PURE__ */ o.jsx( Pt, { placeholder: r.t("find-replace.dialog.replace-placeholder"), value: Ue, onChange: (f) => ze(f) } ) }), /* @__PURE__ */ o.jsx(M, { label: r.t("find-replace.dialog.find-direction.title"), children: /* @__PURE__ */ o.jsx(G, { value: Ge, options: rt, onChange: et }) }), /* @__PURE__ */ o.jsx(ce, { children: /* @__PURE__ */ o.jsxs(o.Fragment, { children: [ /* @__PURE__ */ o.jsx(M, { label: r.t("find-replace.dialog.find-scope.title"), children: /* @__PURE__ */ o.jsx(G, { value: ke, options: nt, onChange: tt }) }), /* @__PURE__ */ o.jsx(M, { label: r.t("find-replace.dialog.find-by.title"), children: /* @__PURE__ */ o.jsx(G, { value: Ve, options: st, onChange: it }) }) ] }) }), /* @__PURE__ */ o.jsx(ce, { children: /* @__PURE__ */ o.jsxs(o.Fragment, { children: [ /* @__PURE__ */ o.jsx(M, { children: /* @__PURE__ */ o.jsx( le, { checked: Be, onChange: (f) => { i.changeCaseSensitive(f); }, children: r.t("find-replace.dialog.case-sensitive") } ) }), /* @__PURE__ */ o.jsx(M, { children: /* @__PURE__ */ o.jsx( le, { checked: We, onChange: (f) => { i.changeMatchesTheWholeCell(f); }, children: r.t("find-replace.dialog.match-the-whole-cell") } ) }) ] }) }), /* @__PURE__ */ o.jsxs("div", { className: L.findReplaceButtonsGroup, children: [ /* @__PURE__ */ o.jsx(N, { type: "primary", onClick: Ze, disabled: He, children: r.t("find-replace.dialog.find") }), /* @__PURE__ */ o.jsxs("span", { className: L.findReplaceButtonsGroupRight, children: [ /* @__PURE__ */ o.jsx(N, { disabled: qe, onClick: Qe, children: r.t("find-replace.dialog.replace") }), /* @__PURE__ */ o.jsx(N, { disabled: Je, onClick: Xe, children: r.t("find-replace.dialog.replace-all") }) ] }) ] }) ] }); }); function Xt() { const t = C(m), e = C(Ce), n = C(ee), i = D(t.state$, void 0, !0), r = H(null); A(() => { let c; return r.current && (c = e.registerContainerElement(r.current)), () => c == null ? void 0 : c.dispose(); }, [e]); const s = H(null), a = p( (c) => n.setContextValue(De, c), [n] ), d = p( (c) => n.setContextValue(Fe, c), [n] ); return A(() => { var _; const c = yt(document, "focusin").subscribe((u) => { var h; u.target && ((h = r.current) != null && h.contains(u.target)) ? a(!0) : a(!1), !s.current || !s.current.selectHasFocus() ? d(!0) : d(!1); }); return (_ = s.current) == null || _.focus(), a(!0), d(!0), () => { c.unsubscribe(), a(!1); }; }, [a, d]), /* @__PURE__ */ o.jsx("div", { className: L.findReplaceDialogContainer, ref: r, children: i.replaceRevealed ? /* @__PURE__ */ o.jsx(Qt, { ref: s }) : /* @__PURE__ */ o.jsx(Zt, { ref: s }) }); } function ei(t) { const e = t.getCurrentLocale(); return ie(() => [ { label: t.t("find-replace.dialog.find-scope.current-sheet"), value: Y.SUBUNIT }, { label: t.t("find-replace.dialog.find-scope.workbook"), value: Y.UNIT } ], [e]); } function ti(t) { const e = t.getCurrentLocale(); return ie(() => [ { label: t.t("find-replace.dialog.find-direction.row"), value: K.ROW }, { label: t.t("find-replace.dialog.find-direction.column"), value: K.COLUMN } ], [e]); } function ii(t) { const e = t.getCurrentLocale(); return ie(() => [ { label: t.t("find-replace.dialog.find-by.value"), value: z.VALUE }, { label: t.t("find-replace.dialog.find-by.formula"), value: z.FORMULA } ], [e]); } function T(t) { return t.getContextValue(De); } function ni(t) { return t.getContextValue(Pe); } function je(t) { return t.getContextValue(Fe); } const B = "7_find-replace-shortcuts"; function se(t) { return t.getContextValue(me); } function ae(t) { return !t.getContextValue(ve); } const ri = { id: O.id, description: "find-replace.shortcut.open-find-dialog", binding: b.F | x.CTRL_COMMAND, group: B, preconditions(t) { return !T(t) && se(t) && ae(t); } }, si = { id: O.id, description: "find-replace.shortcut.open-find-dialog", binding: b.F | x.CTRL_COMMAND, mac: b.F | x.MAC_CTRL, preconditions(t) { return !T(t) && se(t) && ae(t); } }, ai = { id: re.id, description: "find-replace.shortcut.open-replace-dialog", binding: b.H | x.CTRL_COMMAND, mac: b.H | x.MAC_CTRL, group: B, preconditions(t) { return se(t) && ae(t) && (!T(t) || !ni(t)); } }, oi = { id: Ne.id, description: "find-replace.shortcut.go-to-next-match", binding: b.ENTER, group: B, priority: 1e3, preconditions(t) { return je(t) && T(t); } }, ci = { id: $e.id, description: "find-replace.shortcut.go-to-previous-match", binding: b.ENTER | x.SHIFT, group: B, priority: 1e3, preconditions(t) { return je(t) && T(t); } }; function li(t) { const e = t.get(ee); return { id: O.id, icon: "SearchIcon", tooltip: "find-replace.toolbar", type: gt.BUTTON, hidden$: mt(t, dt.UNIVER_SHEET), disabled$: Re([ e.subscribeContextValue$(ve), e.subscribeContextValue$(me) ]).pipe(It(([n, i]) => n || !i)) }; } const di = { [vt.OTHERS]: { [O.id]: { order: 2, menuItemFactory: li } } }; var ui = Object.defineProperty, hi = Object.getOwnPropertyDescriptor, fi = (t, e, n, i) => { for (var r = i > 1 ? void 0 : i ? hi(e, n) : e, s = t.length - 1, a; s >= 0; s--) (a = t[s]) && (r = (i ? a(e, n, r) : a(r)) || r); return i && r && ui(e, n, r), r; }, S = (t, e) => (n, i) => e(n, i, t); const fe = "DESKTOP_FIND_REPLACE_DIALOG", we = 350, pi = 20, _i = -90; let j = class extends ut { constructor(e, n, i, r, s, a, d, c, _, u) { super(); l(this, "_closingListenerDisposable"); this._univerInstanceService = e, this._menuManagerService = n, this._shortcutService = i, this._commandService = r, this._findReplaceService = s, this._dialogService = a, this._layoutService = d, this._localeService = c, this._componentManager = _, this._injector = u, this._initCommands(), this._initUI(), this._initShortcuts(); } dispose() { var e; super.dispose(), (e = this._closingListenerDisposable) == null || e.dispose(), this._closingListenerDisposable = null; } _initCommands() { [ O, re, Ne, $e, Ee, Te ].forEach((e) => { this.disposeWithMe(this._commandService.registerCommand(e)); }); } _initShortcuts() { [ ai, ri, si, ci, oi ].forEach((e) => this.disposeWithMe(this._shortcutService.registerShortcut(e))); } _initUI() { this.disposeWithMe(this._componentManager.register("FindReplaceDialog", Xt)), this.disposeWithMe(this._componentManager.register("SearchIcon", Ie)), this._menuManagerService.mergeMenu(di), this._findReplaceService.stateUpdates$.pipe(oe(this.dispose$)).subscribe((e) => { e.revealed === !0 && this._openPanel(); }); } _openPanel() { this._dialogService.open({ id: fe, draggable: !0, width: we, title: { title: this._localeService.t("find-replace.dialog.title") }, children: { label: "FindReplaceDialog" }, destroyOnClose: !0, defaultPosition: gi(), preservePositionOnDestroy: !0, onClose: () => this.closePanel() }), this._closingListenerDisposable = $(this._univerInstanceService.focused$.pipe(oe(this.dispose$)).subscribe((e) => { (!e || !this._univerInstanceService.getUniverSheetInstance(e)) && this.closePanel(); })); } closePanel() { this._closingListenerDisposable && (this._closingListenerDisposable.dispose(), this._closingListenerDisposable = null, this._dialogService.close(fe), this._findReplaceService.terminate(), queueMicrotask(() => this._layoutService.focus())); } }; j = fi([ S(0, ge), S(1, Ct), S(2, Rt), S(3, te), S(4, m), S(5, Mt), S(6, Ce), S(7, F(w)), S(8, F(St)), S(9, F(Q)) ], j); function gi() { const { innerWidth: t } = window; return { x: (t - we) / 2 - pi, y: _i }; } var mi = Object.defineProperty, vi = Object.getOwnPropertyDescriptor, Si = (t, e, n, i) => { for (var r = i > 1 ? void 0 : i ? vi(e, n) : e, s = t.length - 1, a; s >= 0; s--) (a = t[s]) && (r = (i ? a(e, n, r) : a(r)) || r); return i && r && mi(e, n, r), r; }, pe = (t, e) => (n, i) => e(n, i, t); const Ci = "UNIVER_FIND_REPLACE_PLUGIN"; var V; let _e = (V = class extends ht { constructor(t = de, e, n) { super(), this._config = t, this._injector = e, this._configService = n; const { ...i } = ft( {}, de, this._config ); this._configService.setConfig(Nt, i); } onStarting() { [ [j], [m, { useClass: Z }] ].forEach((t) => this._injector.add(t)); } onRendered() { this._injector.get(j); } }, l(V, "pluginName", Ci), V); _e = Si([ pe(1, F(Q)), pe(2, pt) ], _e); export { z as FindBy, K as FindDirection, Di as FindModel, j as FindReplaceController, J as FindReplaceModel, Gt as FindReplaceState, Y as FindScope, Ne as GoToNextMatchOperation, $e as GoToPreviousMatchOperation, m as IFindReplaceService, O as OpenFindDialogOperation, re as OpenReplaceDialogOperation, Ee as ReplaceAllMatchesCommand, Te as ReplaceCurrentMatchCommand, _e as UniverFindReplacePlugin, ne as createInitFindReplaceState };