facade.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. var u = Object.defineProperty;
  2. var _ = (i, e, t) => e in i ? u(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
  3. var c = (i, e, t) => _(i, typeof e != "symbol" ? e + "" : e, t);
  4. import { Inject as p, Injector as m, IUniverInstanceService as f, Disposable as v, FUniver as d } from "@univerjs/core";
  5. import { IFindReplaceService as b, FindReplaceModel as g, createInitFindReplaceState as S, FindReplaceState as F, FindBy as h } from "@univerjs/find-replace";
  6. import { FRange as y } from "@univerjs/sheets/facade";
  7. var R = Object.defineProperty, w = Object.getOwnPropertyDescriptor, C = (i, e, t, s) => {
  8. for (var n = s > 1 ? void 0 : s ? w(e, t) : e, r = i.length - 1, a; r >= 0; r--)
  9. (a = i[r]) && (n = (s ? a(e, t, n) : a(n)) || n);
  10. return s && n && R(e, t, n), n;
  11. }, o = (i, e) => (t, s) => e(t, s, i);
  12. let l = class extends v {
  13. constructor(e, t, s, n) {
  14. super();
  15. c(this, "_state", new F());
  16. c(this, "_model");
  17. c(this, "_complete");
  18. this._injector = t, this._univerInstanceService = s, this._findReplaceService = n;
  19. const r = this._findReplaceService.getProviders();
  20. this._model = this._injector.createInstance(g, this._state, r);
  21. const a = {
  22. ...S(),
  23. ...e
  24. };
  25. this._state.changeState(a);
  26. }
  27. findAll() {
  28. return !this._state.findCompleted || !this._complete ? [] : this._complete.results.map((e) => this._findMatchToFRange(e));
  29. }
  30. findNext() {
  31. var t;
  32. if (!this._state.findCompleted || !this._complete)
  33. return null;
  34. const e = (t = this._model) == null ? void 0 : t.moveToNextMatch();
  35. return e ? this._findMatchToFRange(e) : null;
  36. }
  37. findPrevious() {
  38. var t;
  39. const e = (t = this._model) == null ? void 0 : t.moveToPreviousMatch();
  40. return e ? this._findMatchToFRange(e) : null;
  41. }
  42. getCurrentMatch() {
  43. var t;
  44. if (!this._state.findCompleted || !this._complete)
  45. throw new Error("Find operation is not completed.");
  46. const e = (t = this._model) == null ? void 0 : t.currentMatch$.value;
  47. return e ? this._findMatchToFRange(e) : null;
  48. }
  49. async matchCaseAsync(e) {
  50. return this._state.changeState({ caseSensitive: e }), new Promise((t) => {
  51. const s = this._state.stateUpdates$.subscribe((n) => {
  52. n.findCompleted === !0 && (s.unsubscribe(), t(this));
  53. });
  54. });
  55. }
  56. async matchEntireCellAsync(e) {
  57. return this._state.changeState({ matchesTheWholeCell: e }), new Promise((t) => {
  58. const s = this._state.stateUpdates$.subscribe((n) => {
  59. n.findCompleted === !0 && (s.unsubscribe(), t(this));
  60. });
  61. });
  62. }
  63. async matchFormulaTextAsync(e) {
  64. return this._state.changeState({ findBy: e ? h.FORMULA : h.VALUE }), new Promise((t) => {
  65. const s = this._state.stateUpdates$.subscribe((n) => {
  66. n.findCompleted === !0 && (s.unsubscribe(), t(this));
  67. });
  68. });
  69. }
  70. async replaceAllWithAsync(e) {
  71. var s, n, r;
  72. await this._state.changeState({ replaceRevealed: !0, replaceString: e });
  73. const t = (r = (n = await ((s = this._model) == null ? void 0 : s.replaceAll())) == null ? void 0 : n.success) != null ? r : 0;
  74. return this._state.changeState({ replaceRevealed: !1 }), t;
  75. }
  76. async replaceWithAsync(e) {
  77. var t;
  78. return await this._state.changeState({ replaceRevealed: !0, replaceString: e }), await ((t = this._model) == null ? void 0 : t.replace()), this._state.changeState({ replaceRevealed: !1 }), !0;
  79. }
  80. async ensureCompleteAsync() {
  81. var e;
  82. return (!this._state.findCompleted || !this._complete) && (this._complete = await ((e = this._model) == null ? void 0 : e.start())), this._complete;
  83. }
  84. _findMatchToFRange(e) {
  85. const { unitId: t } = e, { subUnitId: s, range: n } = e.range, r = this._univerInstanceService.getUnit(t), a = r.getSheetBySheetId(s);
  86. return this._injector.createInstance(y, r, a, n);
  87. }
  88. };
  89. l = C([
  90. o(1, p(m)),
  91. o(2, f),
  92. o(3, b)
  93. ], l);
  94. class I extends d {
  95. async createTextFinderAsync(e) {
  96. const t = { findString: e }, s = this._injector.createInstance(l, t);
  97. return await s.ensureCompleteAsync(), s;
  98. }
  99. }
  100. d.extend(I);