@univerjs/sheets-find-replace 0.20.1 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/lib/cjs/facade.js +204 -1
  2. package/lib/cjs/index.js +936 -1
  3. package/lib/cjs/locale/ca-ES.js +9 -1
  4. package/lib/cjs/locale/en-US.js +24 -1
  5. package/lib/cjs/locale/es-ES.js +9 -1
  6. package/lib/cjs/locale/fa-IR.js +9 -1
  7. package/lib/cjs/locale/fr-FR.js +9 -1
  8. package/lib/cjs/locale/ja-JP.js +9 -1
  9. package/lib/cjs/locale/ko-KR.js +9 -1
  10. package/lib/cjs/locale/ru-RU.js +9 -1
  11. package/lib/cjs/locale/sk-SK.js +9 -1
  12. package/lib/cjs/locale/vi-VN.js +9 -1
  13. package/lib/cjs/locale/zh-CN.js +24 -1
  14. package/lib/cjs/locale/zh-TW.js +9 -1
  15. package/lib/es/facade.js +205 -1
  16. package/lib/es/index.js +923 -1
  17. package/lib/es/locale/ca-ES.js +8 -1
  18. package/lib/es/locale/en-US.js +23 -1
  19. package/lib/es/locale/es-ES.js +8 -1
  20. package/lib/es/locale/fa-IR.js +8 -1
  21. package/lib/es/locale/fr-FR.js +8 -1
  22. package/lib/es/locale/ja-JP.js +8 -1
  23. package/lib/es/locale/ko-KR.js +8 -1
  24. package/lib/es/locale/ru-RU.js +8 -1
  25. package/lib/es/locale/sk-SK.js +8 -1
  26. package/lib/es/locale/vi-VN.js +8 -1
  27. package/lib/es/locale/zh-CN.js +23 -1
  28. package/lib/es/locale/zh-TW.js +8 -1
  29. package/lib/facade.js +205 -1
  30. package/lib/index.js +923 -1
  31. package/lib/locale/ca-ES.js +8 -1
  32. package/lib/locale/en-US.js +23 -1
  33. package/lib/locale/es-ES.js +8 -1
  34. package/lib/locale/fa-IR.js +8 -1
  35. package/lib/locale/fr-FR.js +8 -1
  36. package/lib/locale/ja-JP.js +8 -1
  37. package/lib/locale/ko-KR.js +8 -1
  38. package/lib/locale/ru-RU.js +8 -1
  39. package/lib/locale/sk-SK.js +8 -1
  40. package/lib/locale/vi-VN.js +8 -1
  41. package/lib/locale/zh-CN.js +23 -1
  42. package/lib/locale/zh-TW.js +8 -1
  43. package/lib/umd/index.js +1 -1
  44. package/package.json +8 -8
package/lib/cjs/facade.js CHANGED
@@ -1 +1,204 @@
1
- let e=require(`@univerjs/core`),t=require(`@univerjs/find-replace`),n=require(`@univerjs/sheets/facade`),r=require(`@univerjs/core/facade`);function i(e){"@babel/helpers - typeof";return i=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},i(e)}function a(e,t){if(i(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(i(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function o(e){var t=a(e,`string`);return i(t)==`symbol`?t:t+``}function s(e,t,n){return(t=o(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function c(e,t){return function(n,r){t(n,r,e)}}function l(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let u=class extends e.Disposable{constructor(e,n,r,i){super(),this._injector=n,this._univerInstanceService=r,this._findReplaceService=i,s(this,`_state`,new t.FindReplaceState),s(this,`_model`,void 0),s(this,`_complete`,void 0);let a=this._findReplaceService.getProviders();this._model=this._injector.createInstance(t.FindReplaceModel,this._state,a);let o={...(0,t.createInitFindReplaceState)(),...e};this._state.changeState(o)}findAll(){return!this._state.findCompleted||!this._complete?[]:this._complete.results.map(e=>this._findMatchToFRange(e))}findNext(){var e;if(!this._state.findCompleted||!this._complete)return null;let t=(e=this._model)==null?void 0:e.moveToNextMatch();return t?this._findMatchToFRange(t):null}findPrevious(){var e;let t=(e=this._model)==null?void 0:e.moveToPreviousMatch();return t?this._findMatchToFRange(t):null}getCurrentMatch(){var e;if(!this._state.findCompleted||!this._complete)throw Error(`Find operation is not completed.`);let t=(e=this._model)==null?void 0:e.currentMatch$.value;return t?this._findMatchToFRange(t):null}async matchCaseAsync(e){return this._state.changeState({caseSensitive:e,findCompleted:!1}),new Promise(e=>{let t=this._state.stateUpdates$.subscribe(async n=>{n.findCompleted===!0&&(t.unsubscribe(),await this.ensureCompleteAsync(),e(this))})})}async matchEntireCellAsync(e){return this._state.changeState({matchesTheWholeCell:e,findCompleted:!1}),new Promise(e=>{let t=this._state.stateUpdates$.subscribe(async n=>{n.findCompleted===!0&&(t.unsubscribe(),await this.ensureCompleteAsync(),e(this))})})}async matchFormulaTextAsync(e){return this._state.changeState({findBy:e?t.FindBy.FORMULA:t.FindBy.VALUE,findCompleted:!1}),new Promise(e=>{let t=this._state.stateUpdates$.subscribe(async n=>{n.findCompleted===!0&&(t.unsubscribe(),await this.ensureCompleteAsync(),e(this))})})}async replaceAllWithAsync(e){var t,n,r;await this._state.changeState({replaceRevealed:!0,replaceString:e});let i=(t=(n=await((r=this._model)==null?void 0:r.replaceAll()))==null?void 0:n.success)==null?0:t;return this._state.changeState({replaceRevealed:!1}),i}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;this._complete=await((e=this._model)==null?void 0:e.start())}_findMatchToFRange(e){let{unitId:t}=e,{subUnitId:r,range:i}=e.range,a=this._univerInstanceService.getUnit(t),o=a.getSheetBySheetId(r);return this._injector.createInstance(n.FRange,a,o,i)}};u=l([c(1,(0,e.Inject)(e.Injector)),c(2,e.IUniverInstanceService),c(3,t.IFindReplaceService)],u);var d=class extends r.FUniver{async createTextFinderAsync(e){let t={findString:e},n=this._injector.createInstance(u,t);return await n.ensureCompleteAsync(),n}};r.FUniver.extend(d);
1
+ let _univerjs_core = require("@univerjs/core");
2
+ let _univerjs_find_replace = require("@univerjs/find-replace");
3
+ let _univerjs_sheets_facade = require("@univerjs/sheets/facade");
4
+ let _univerjs_core_facade = require("@univerjs/core/facade");
5
+
6
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
7
+ function _typeof(o) {
8
+ "@babel/helpers - typeof";
9
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
10
+ return typeof o;
11
+ } : function(o) {
12
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
13
+ }, _typeof(o);
14
+ }
15
+
16
+ //#endregion
17
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
18
+ function toPrimitive(t, r) {
19
+ if ("object" != _typeof(t) || !t) return t;
20
+ var e = t[Symbol.toPrimitive];
21
+ if (void 0 !== e) {
22
+ var i = e.call(t, r || "default");
23
+ if ("object" != _typeof(i)) return i;
24
+ throw new TypeError("@@toPrimitive must return a primitive value.");
25
+ }
26
+ return ("string" === r ? String : Number)(t);
27
+ }
28
+
29
+ //#endregion
30
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
31
+ function toPropertyKey(t) {
32
+ var i = toPrimitive(t, "string");
33
+ return "symbol" == _typeof(i) ? i : i + "";
34
+ }
35
+
36
+ //#endregion
37
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
38
+ function _defineProperty(e, r, t) {
39
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
40
+ value: t,
41
+ enumerable: !0,
42
+ configurable: !0,
43
+ writable: !0
44
+ }) : e[r] = t, e;
45
+ }
46
+
47
+ //#endregion
48
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
49
+ function __decorateParam(paramIndex, decorator) {
50
+ return function(target, key) {
51
+ decorator(target, key, paramIndex);
52
+ };
53
+ }
54
+
55
+ //#endregion
56
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
57
+ function __decorate(decorators, target, key, desc) {
58
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
59
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
60
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
61
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
62
+ }
63
+
64
+ //#endregion
65
+ //#region src/facade/f-text-finder.ts
66
+ let FTextFinder = class FTextFinder extends _univerjs_core.Disposable {
67
+ constructor(_initialState, _injector, _univerInstanceService, _findReplaceService) {
68
+ super();
69
+ this._injector = _injector;
70
+ this._univerInstanceService = _univerInstanceService;
71
+ this._findReplaceService = _findReplaceService;
72
+ _defineProperty(this, "_state", new _univerjs_find_replace.FindReplaceState());
73
+ _defineProperty(this, "_model", void 0);
74
+ _defineProperty(this, "_complete", void 0);
75
+ const providers = this._findReplaceService.getProviders();
76
+ this._model = this._injector.createInstance(_univerjs_find_replace.FindReplaceModel, this._state, providers);
77
+ const newState = {
78
+ ...(0, _univerjs_find_replace.createInitFindReplaceState)(),
79
+ ..._initialState
80
+ };
81
+ this._state.changeState(newState);
82
+ }
83
+ findAll() {
84
+ if (!this._state.findCompleted || !this._complete) return [];
85
+ return this._complete.results.map((result) => {
86
+ return this._findMatchToFRange(result);
87
+ });
88
+ }
89
+ findNext() {
90
+ var _this$_model;
91
+ if (!this._state.findCompleted || !this._complete) return null;
92
+ const match = (_this$_model = this._model) === null || _this$_model === void 0 ? void 0 : _this$_model.moveToNextMatch();
93
+ if (!match) return null;
94
+ return this._findMatchToFRange(match);
95
+ }
96
+ findPrevious() {
97
+ var _this$_model2;
98
+ const match = (_this$_model2 = this._model) === null || _this$_model2 === void 0 ? void 0 : _this$_model2.moveToPreviousMatch();
99
+ if (!match) return null;
100
+ return this._findMatchToFRange(match);
101
+ }
102
+ getCurrentMatch() {
103
+ var _this$_model3;
104
+ if (!this._state.findCompleted || !this._complete) throw new Error("Find operation is not completed.");
105
+ const match = (_this$_model3 = this._model) === null || _this$_model3 === void 0 ? void 0 : _this$_model3.currentMatch$.value;
106
+ if (!match) return null;
107
+ return this._findMatchToFRange(match);
108
+ }
109
+ async matchCaseAsync(matchCase) {
110
+ this._state.changeState({
111
+ caseSensitive: matchCase,
112
+ findCompleted: false
113
+ });
114
+ return new Promise((resolve) => {
115
+ const subscribe = this._state.stateUpdates$.subscribe(async (state) => {
116
+ if (state.findCompleted === true) {
117
+ subscribe.unsubscribe();
118
+ await this.ensureCompleteAsync();
119
+ resolve(this);
120
+ }
121
+ });
122
+ });
123
+ }
124
+ async matchEntireCellAsync(matchEntireCell) {
125
+ this._state.changeState({
126
+ matchesTheWholeCell: matchEntireCell,
127
+ findCompleted: false
128
+ });
129
+ return new Promise((resolve) => {
130
+ const subscribe = this._state.stateUpdates$.subscribe(async (state) => {
131
+ if (state.findCompleted === true) {
132
+ subscribe.unsubscribe();
133
+ await this.ensureCompleteAsync();
134
+ resolve(this);
135
+ }
136
+ });
137
+ });
138
+ }
139
+ async matchFormulaTextAsync(matchFormulaText) {
140
+ this._state.changeState({
141
+ findBy: matchFormulaText ? _univerjs_find_replace.FindBy.FORMULA : _univerjs_find_replace.FindBy.VALUE,
142
+ findCompleted: false
143
+ });
144
+ return new Promise((resolve) => {
145
+ const subscribe = this._state.stateUpdates$.subscribe(async (state) => {
146
+ if (state.findCompleted === true) {
147
+ subscribe.unsubscribe();
148
+ await this.ensureCompleteAsync();
149
+ resolve(this);
150
+ }
151
+ });
152
+ });
153
+ }
154
+ async replaceAllWithAsync(replaceText) {
155
+ var _await$this$_model$re, _await$this$_model$re2, _this$_model4;
156
+ await this._state.changeState({
157
+ replaceRevealed: true,
158
+ replaceString: replaceText
159
+ });
160
+ const res = (_await$this$_model$re = (_await$this$_model$re2 = await ((_this$_model4 = this._model) === null || _this$_model4 === void 0 ? void 0 : _this$_model4.replaceAll())) === null || _await$this$_model$re2 === void 0 ? void 0 : _await$this$_model$re2.success) !== null && _await$this$_model$re !== void 0 ? _await$this$_model$re : 0;
161
+ this._state.changeState({ replaceRevealed: false });
162
+ return res;
163
+ }
164
+ async replaceWithAsync(replaceText) {
165
+ var _this$_model5;
166
+ await this._state.changeState({
167
+ replaceRevealed: true,
168
+ replaceString: replaceText
169
+ });
170
+ await ((_this$_model5 = this._model) === null || _this$_model5 === void 0 ? void 0 : _this$_model5.replace());
171
+ this._state.changeState({ replaceRevealed: false });
172
+ return true;
173
+ }
174
+ async ensureCompleteAsync() {
175
+ var _this$_model6;
176
+ this._complete = await ((_this$_model6 = this._model) === null || _this$_model6 === void 0 ? void 0 : _this$_model6.start());
177
+ }
178
+ _findMatchToFRange(match) {
179
+ const { unitId } = match;
180
+ const { subUnitId, range } = match.range;
181
+ const workbook = this._univerInstanceService.getUnit(unitId);
182
+ const worksheet = workbook.getSheetBySheetId(subUnitId);
183
+ return this._injector.createInstance(_univerjs_sheets_facade.FRange, workbook, worksheet, range);
184
+ }
185
+ };
186
+ FTextFinder = __decorate([
187
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
188
+ __decorateParam(2, _univerjs_core.IUniverInstanceService),
189
+ __decorateParam(3, _univerjs_find_replace.IFindReplaceService)
190
+ ], FTextFinder);
191
+
192
+ //#endregion
193
+ //#region src/facade/f-univer.ts
194
+ var FUniverSheetsFindReplaceMixin = class extends _univerjs_core_facade.FUniver {
195
+ async createTextFinderAsync(text) {
196
+ const state = { findString: text };
197
+ const textFinder = this._injector.createInstance(FTextFinder, state);
198
+ await textFinder.ensureCompleteAsync();
199
+ return textFinder;
200
+ }
201
+ };
202
+ _univerjs_core_facade.FUniver.extend(FUniverSheetsFindReplaceMixin);
203
+
204
+ //#endregion