| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- var u = Object.defineProperty;
- var _ = (i, e, t) => e in i ? u(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
- var c = (i, e, t) => _(i, typeof e != "symbol" ? e + "" : e, t);
- import { Inject as p, Injector as m, IUniverInstanceService as f, Disposable as v, FUniver as d } from "@univerjs/core";
- import { IFindReplaceService as b, FindReplaceModel as g, createInitFindReplaceState as S, FindReplaceState as F, FindBy as h } from "@univerjs/find-replace";
- import { FRange as y } from "@univerjs/sheets/facade";
- var R = Object.defineProperty, w = Object.getOwnPropertyDescriptor, C = (i, e, t, s) => {
- for (var n = s > 1 ? void 0 : s ? w(e, t) : e, r = i.length - 1, a; r >= 0; r--)
- (a = i[r]) && (n = (s ? a(e, t, n) : a(n)) || n);
- return s && n && R(e, t, n), n;
- }, o = (i, e) => (t, s) => e(t, s, i);
- let l = class extends v {
- constructor(e, t, s, n) {
- super();
- c(this, "_state", new F());
- c(this, "_model");
- c(this, "_complete");
- this._injector = t, this._univerInstanceService = s, this._findReplaceService = n;
- const r = this._findReplaceService.getProviders();
- this._model = this._injector.createInstance(g, this._state, r);
- const a = {
- ...S(),
- ...e
- };
- this._state.changeState(a);
- }
- findAll() {
- return !this._state.findCompleted || !this._complete ? [] : this._complete.results.map((e) => this._findMatchToFRange(e));
- }
- findNext() {
- var t;
- if (!this._state.findCompleted || !this._complete)
- return null;
- const e = (t = this._model) == null ? void 0 : t.moveToNextMatch();
- return e ? this._findMatchToFRange(e) : null;
- }
- findPrevious() {
- var t;
- const e = (t = this._model) == null ? void 0 : t.moveToPreviousMatch();
- return e ? this._findMatchToFRange(e) : null;
- }
- getCurrentMatch() {
- var t;
- if (!this._state.findCompleted || !this._complete)
- throw new Error("Find operation is not completed.");
- const e = (t = this._model) == null ? void 0 : t.currentMatch$.value;
- return e ? this._findMatchToFRange(e) : null;
- }
- async matchCaseAsync(e) {
- return this._state.changeState({ caseSensitive: e }), new Promise((t) => {
- const s = this._state.stateUpdates$.subscribe((n) => {
- n.findCompleted === !0 && (s.unsubscribe(), t(this));
- });
- });
- }
- async matchEntireCellAsync(e) {
- return this._state.changeState({ matchesTheWholeCell: e }), new Promise((t) => {
- const s = this._state.stateUpdates$.subscribe((n) => {
- n.findCompleted === !0 && (s.unsubscribe(), t(this));
- });
- });
- }
- async matchFormulaTextAsync(e) {
- return this._state.changeState({ findBy: e ? h.FORMULA : h.VALUE }), new Promise((t) => {
- const s = this._state.stateUpdates$.subscribe((n) => {
- n.findCompleted === !0 && (s.unsubscribe(), t(this));
- });
- });
- }
- async replaceAllWithAsync(e) {
- var s, n, r;
- await this._state.changeState({ replaceRevealed: !0, replaceString: e });
- const t = (r = (n = await ((s = this._model) == null ? void 0 : s.replaceAll())) == null ? void 0 : n.success) != null ? r : 0;
- return this._state.changeState({ replaceRevealed: !1 }), t;
- }
- async replaceWithAsync(e) {
- var t;
- return await this._state.changeState({ replaceRevealed: !0, replaceString: e }), await ((t = this._model) == null ? void 0 : t.replace()), this._state.changeState({ replaceRevealed: !1 }), !0;
- }
- async ensureCompleteAsync() {
- var e;
- return (!this._state.findCompleted || !this._complete) && (this._complete = await ((e = this._model) == null ? void 0 : e.start())), this._complete;
- }
- _findMatchToFRange(e) {
- const { unitId: t } = e, { subUnitId: s, range: n } = e.range, r = this._univerInstanceService.getUnit(t), a = r.getSheetBySheetId(s);
- return this._injector.createInstance(y, r, a, n);
- }
- };
- l = C([
- o(1, p(m)),
- o(2, f),
- o(3, b)
- ], l);
- class I extends d {
- async createTextFinderAsync(e) {
- const t = { findString: e }, s = this._injector.createInstance(l, t);
- return await s.ensureCompleteAsync(), s;
- }
- }
- d.extend(I);
|