@univerjs/sheets-find-replace 0.6.0 → 0.6.1
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.
- package/lib/cjs/facade.js +1 -1
- package/lib/es/facade.js +33 -33
- package/lib/types/facade/f-text-finder.d.ts +246 -62
- package/lib/types/facade/f-univer.d.ts +25 -1
- package/lib/umd/facade.js +1 -1
- package/package.json +9 -9
package/lib/cjs/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var p=Object.defineProperty;var _=(a,e,t)=>e in a?p(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var o=(a,e,t)=>_(a,typeof e!="symbol"?e+"":e,t);const l=require("@univerjs/core"),c=require("@univerjs/find-replace"),m=require("@univerjs/sheets/facade"),u=require("@univerjs/core/facade");var f=Object.getOwnPropertyDescriptor,v=(a,e,t,s)=>{for(var n=s>1?void 0:s?f(e,t):e,i=a.length-1,r;i>=0;i--)(r=a[i])&&(n=r(n)||n);return n},h=(a,e)=>(t,s)=>e(t,s,a);let d=class extends l.Disposable{constructor(e,t,s,n){super();o(this,"_state",new c.FindReplaceState);o(this,"_model");o(this,"_complete");this._injector=t,this._univerInstanceService=s,this._findReplaceService=n;const i=this._findReplaceService.getProviders();this._model=this._injector.createInstance(c.FindReplaceModel,this._state,i);const r={...c.createInitFindReplaceState(),...e};this._state.changeState(r)}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,findCompleted:!1}),new Promise(t=>{const s=this._state.stateUpdates$.subscribe(async n=>{n.findCompleted===!0&&(s.unsubscribe(),await this.ensureCompleteAsync(),t(this))})})}async matchEntireCellAsync(e){return this._state.changeState({matchesTheWholeCell:e,findCompleted:!1}),new Promise(t=>{const s=this._state.stateUpdates$.subscribe(async n=>{n.findCompleted===!0&&(s.unsubscribe(),await this.ensureCompleteAsync(),t(this))})})}async matchFormulaTextAsync(e){return this._state.changeState({findBy:e?c.FindBy.FORMULA:c.FindBy.VALUE,findCompleted:!1}),new Promise(t=>{const s=this._state.stateUpdates$.subscribe(async n=>{n.findCompleted===!0&&(s.unsubscribe(),await this.ensureCompleteAsync(),t(this))})})}async replaceAllWithAsync(e){var s,n,i;await this._state.changeState({replaceRevealed:!0,replaceString:e});const t=(i=(n=await((s=this._model)==null?void 0:s.replaceAll()))==null?void 0:n.success)!=null?i: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;this._complete=await((e=this._model)==null?void 0:e.start())}_findMatchToFRange(e){const{unitId:t}=e,{subUnitId:s,range:n}=e.range,i=this._univerInstanceService.getUnit(t),r=i.getSheetBySheetId(s);return this._injector.createInstance(m.FRange,i,r,n)}};d=v([h(1,l.Inject(l.Injector)),h(2,l.IUniverInstanceService),h(3,c.IFindReplaceService)],d);class y extends u.FUniver{async createTextFinderAsync(e){const t={findString:e},s=this._injector.createInstance(d,t);return await s.ensureCompleteAsync(),s}}u.FUniver.extend(y);
|
package/lib/es/facade.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
var u = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var c = (
|
|
4
|
-
import { Inject as
|
|
5
|
-
import { IFindReplaceService as g, FindReplaceModel as
|
|
6
|
-
import { FRange as
|
|
2
|
+
var p = (a, e, t) => e in a ? u(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
|
|
3
|
+
var c = (a, e, t) => p(a, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { Inject as m, Injector as _, IUniverInstanceService as f, Disposable as v } from "@univerjs/core";
|
|
5
|
+
import { IFindReplaceService as g, FindReplaceModel as y, createInitFindReplaceState as S, FindReplaceState as b, FindBy as h } from "@univerjs/find-replace";
|
|
6
|
+
import { FRange as F } from "@univerjs/sheets/facade";
|
|
7
7
|
import { FUniver as d } from "@univerjs/core/facade";
|
|
8
|
-
var
|
|
9
|
-
for (var n = s > 1 ? void 0 : s ?
|
|
10
|
-
(
|
|
8
|
+
var w = Object.getOwnPropertyDescriptor, C = (a, e, t, s) => {
|
|
9
|
+
for (var n = s > 1 ? void 0 : s ? w(e, t) : e, i = a.length - 1, r; i >= 0; i--)
|
|
10
|
+
(r = a[i]) && (n = r(n) || n);
|
|
11
11
|
return n;
|
|
12
|
-
}, o = (
|
|
12
|
+
}, o = (a, e) => (t, s) => e(t, s, a);
|
|
13
13
|
let l = class extends v {
|
|
14
14
|
constructor(e, t, s, n) {
|
|
15
15
|
super();
|
|
16
|
-
c(this, "_state", new
|
|
16
|
+
c(this, "_state", new b());
|
|
17
17
|
c(this, "_model");
|
|
18
18
|
c(this, "_complete");
|
|
19
19
|
this._injector = t, this._univerInstanceService = s, this._findReplaceService = n;
|
|
20
|
-
const
|
|
21
|
-
this._model = this._injector.createInstance(
|
|
22
|
-
const
|
|
23
|
-
...
|
|
20
|
+
const i = this._findReplaceService.getProviders();
|
|
21
|
+
this._model = this._injector.createInstance(y, this._state, i);
|
|
22
|
+
const r = {
|
|
23
|
+
...S(),
|
|
24
24
|
...e
|
|
25
25
|
};
|
|
26
|
-
this._state.changeState(
|
|
26
|
+
this._state.changeState(r);
|
|
27
27
|
}
|
|
28
28
|
findAll() {
|
|
29
29
|
return !this._state.findCompleted || !this._complete ? [] : this._complete.results.map((e) => this._findMatchToFRange(e));
|
|
@@ -48,30 +48,30 @@ let l = class extends v {
|
|
|
48
48
|
return e ? this._findMatchToFRange(e) : null;
|
|
49
49
|
}
|
|
50
50
|
async matchCaseAsync(e) {
|
|
51
|
-
return this._state.changeState({ caseSensitive: e }), new Promise((t) => {
|
|
52
|
-
const s = this._state.stateUpdates$.subscribe((n) => {
|
|
53
|
-
n.findCompleted === !0 && (s.unsubscribe(), t(this));
|
|
51
|
+
return this._state.changeState({ caseSensitive: e, findCompleted: !1 }), new Promise((t) => {
|
|
52
|
+
const s = this._state.stateUpdates$.subscribe(async (n) => {
|
|
53
|
+
n.findCompleted === !0 && (s.unsubscribe(), await this.ensureCompleteAsync(), t(this));
|
|
54
54
|
});
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
57
|
async matchEntireCellAsync(e) {
|
|
58
|
-
return this._state.changeState({ matchesTheWholeCell: e }), new Promise((t) => {
|
|
59
|
-
const s = this._state.stateUpdates$.subscribe((n) => {
|
|
60
|
-
n.findCompleted === !0 && (s.unsubscribe(), t(this));
|
|
58
|
+
return this._state.changeState({ matchesTheWholeCell: e, findCompleted: !1 }), new Promise((t) => {
|
|
59
|
+
const s = this._state.stateUpdates$.subscribe(async (n) => {
|
|
60
|
+
n.findCompleted === !0 && (s.unsubscribe(), await this.ensureCompleteAsync(), t(this));
|
|
61
61
|
});
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
async matchFormulaTextAsync(e) {
|
|
65
|
-
return this._state.changeState({ findBy: e ? h.FORMULA : h.VALUE }), new Promise((t) => {
|
|
66
|
-
const s = this._state.stateUpdates$.subscribe((n) => {
|
|
67
|
-
n.findCompleted === !0 && (s.unsubscribe(), t(this));
|
|
65
|
+
return this._state.changeState({ findBy: e ? h.FORMULA : h.VALUE, findCompleted: !1 }), new Promise((t) => {
|
|
66
|
+
const s = this._state.stateUpdates$.subscribe(async (n) => {
|
|
67
|
+
n.findCompleted === !0 && (s.unsubscribe(), await this.ensureCompleteAsync(), t(this));
|
|
68
68
|
});
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
async replaceAllWithAsync(e) {
|
|
72
|
-
var s, n,
|
|
72
|
+
var s, n, i;
|
|
73
73
|
await this._state.changeState({ replaceRevealed: !0, replaceString: e });
|
|
74
|
-
const t = (
|
|
74
|
+
const t = (i = (n = await ((s = this._model) == null ? void 0 : s.replaceAll())) == null ? void 0 : n.success) != null ? i : 0;
|
|
75
75
|
return this._state.changeState({ replaceRevealed: !1 }), t;
|
|
76
76
|
}
|
|
77
77
|
async replaceWithAsync(e) {
|
|
@@ -80,22 +80,22 @@ let l = class extends v {
|
|
|
80
80
|
}
|
|
81
81
|
async ensureCompleteAsync() {
|
|
82
82
|
var e;
|
|
83
|
-
|
|
83
|
+
this._complete = await ((e = this._model) == null ? void 0 : e.start());
|
|
84
84
|
}
|
|
85
85
|
_findMatchToFRange(e) {
|
|
86
|
-
const { unitId: t } = e, { subUnitId: s, range: n } = e.range,
|
|
87
|
-
return this._injector.createInstance(
|
|
86
|
+
const { unitId: t } = e, { subUnitId: s, range: n } = e.range, i = this._univerInstanceService.getUnit(t), r = i.getSheetBySheetId(s);
|
|
87
|
+
return this._injector.createInstance(F, i, r, n);
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
|
-
l =
|
|
91
|
-
o(1,
|
|
90
|
+
l = C([
|
|
91
|
+
o(1, m(_)),
|
|
92
92
|
o(2, f),
|
|
93
93
|
o(3, g)
|
|
94
94
|
], l);
|
|
95
|
-
class
|
|
95
|
+
class R extends d {
|
|
96
96
|
async createTextFinderAsync(e) {
|
|
97
97
|
const t = { findString: e }, s = this._injector.createInstance(l, t);
|
|
98
98
|
return await s.ensureCompleteAsync(), s;
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
-
d.extend(
|
|
101
|
+
d.extend(R);
|
|
@@ -6,130 +6,314 @@ import { FRange } from '@univerjs/sheets/facade';
|
|
|
6
6
|
*/
|
|
7
7
|
export interface IFTextFinder {
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* @
|
|
9
|
+
* Get all the matched cells of the current sheet, the current matched cell is the last matched cell.
|
|
10
|
+
* If current sheet changed, use `await textFinder.ensureCompleteAsync()` to ensure the find operation is completed.
|
|
11
|
+
* @returns {FRange[]} All the matched cells.
|
|
12
|
+
* @throws If the find operation is not completed.
|
|
12
13
|
* @example
|
|
13
14
|
* ```typescript
|
|
14
|
-
*
|
|
15
|
-
* const
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* // Assume the current sheet is empty sheet.
|
|
16
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
17
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
18
|
+
* const fRange = fWorksheet.getRange('A1:D10');
|
|
19
|
+
* fRange.setValues([
|
|
20
|
+
* [1, 2, 3, 4],
|
|
21
|
+
* [2, 3, 4, 5],
|
|
22
|
+
* [3, 4, 5, 6],
|
|
23
|
+
* [4, 5, 6, 7],
|
|
24
|
+
* [5, 6, 7, 8],
|
|
25
|
+
* [6, 7, 8, 9],
|
|
26
|
+
* [7, 8, 9, 10],
|
|
27
|
+
* [8, 9, 10, 11],
|
|
28
|
+
* [9, 10, 11, 12],
|
|
29
|
+
* [10, 11, 12, 13]
|
|
30
|
+
* ]);
|
|
31
|
+
*
|
|
32
|
+
* // Create a text-finder to find the text '5'.
|
|
33
|
+
* const textFinder = await univerAPI.createTextFinderAsync('5');
|
|
34
|
+
*
|
|
35
|
+
* // Find all cells that contain the text '5'.
|
|
36
|
+
* const matchCells = textFinder.findAll();
|
|
37
|
+
* matchCells.forEach((cell) => {
|
|
38
|
+
* console.log(cell.getA1Notation()); // D2, C3, B4, A5
|
|
18
39
|
* });
|
|
19
40
|
* ```
|
|
20
41
|
*/
|
|
21
42
|
findAll(): FRange[];
|
|
22
43
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* @
|
|
26
|
-
* @
|
|
44
|
+
* Get the next matched cell of the current sheet, if exists return the next matched cell and move the current matched cell to the next matched cell.
|
|
45
|
+
* If current sheet changed, use `await textFinder.ensureCompleteAsync()` to ensure the find operation is completed.
|
|
46
|
+
* @returns {Nullable<FRange>} The next matched cell.
|
|
47
|
+
* @throws If the find operation is not completed.
|
|
27
48
|
* @example
|
|
28
49
|
* ```typescript
|
|
29
|
-
*
|
|
30
|
-
* const
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
50
|
+
* // Assume the current sheet is empty sheet.
|
|
51
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
52
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
53
|
+
* const fRange = fWorksheet.getRange('A1:D10');
|
|
54
|
+
* fRange.setValues([
|
|
55
|
+
* [1, 2, 3, 4],
|
|
56
|
+
* [2, 3, 4, 5],
|
|
57
|
+
* [3, 4, 5, 6],
|
|
58
|
+
* [4, 5, 6, 7],
|
|
59
|
+
* [5, 6, 7, 8],
|
|
60
|
+
* [6, 7, 8, 9],
|
|
61
|
+
* [7, 8, 9, 10],
|
|
62
|
+
* [8, 9, 10, 11],
|
|
63
|
+
* [9, 10, 11, 12],
|
|
64
|
+
* [10, 11, 12, 13]
|
|
65
|
+
* ]);
|
|
66
|
+
*
|
|
67
|
+
* // Create a text-finder to find the text '5'.
|
|
68
|
+
* const textFinder = await univerAPI.createTextFinderAsync('5');
|
|
69
|
+
* console.log(textFinder.getCurrentMatch().getA1Notation()); // current match cell is A5
|
|
70
|
+
*
|
|
71
|
+
* // Find the next matched range
|
|
72
|
+
* const nextMatch = textFinder.findNext();
|
|
73
|
+
* console.log(nextMatch.getA1Notation()); // D2
|
|
74
|
+
* console.log(textFinder.getCurrentMatch().getA1Notation()); // current match cell is D2
|
|
34
75
|
* ```
|
|
35
76
|
*/
|
|
36
77
|
findNext(): Nullable<FRange>;
|
|
37
78
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* @
|
|
41
|
-
* @
|
|
79
|
+
* Get the previous matched cell of the current sheet, if exists return the previous matched cell and move the current matched cell to the previous matched cell.
|
|
80
|
+
* If current sheet changed, use `await textFinder.ensureCompleteAsync()` to ensure the find operation is completed.
|
|
81
|
+
* @returns {Nullable<FRange>} The previous matched cell.
|
|
82
|
+
* @throws If the find operation is not completed.
|
|
42
83
|
* @example
|
|
43
84
|
* ```typescript
|
|
44
|
-
*
|
|
45
|
-
* const
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
85
|
+
* // Assume the current sheet is empty sheet.
|
|
86
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
87
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
88
|
+
* const fRange = fWorksheet.getRange('A1:D10');
|
|
89
|
+
* fRange.setValues([
|
|
90
|
+
* [1, 2, 3, 4],
|
|
91
|
+
* [2, 3, 4, 5],
|
|
92
|
+
* [3, 4, 5, 6],
|
|
93
|
+
* [4, 5, 6, 7],
|
|
94
|
+
* [5, 6, 7, 8],
|
|
95
|
+
* [6, 7, 8, 9],
|
|
96
|
+
* [7, 8, 9, 10],
|
|
97
|
+
* [8, 9, 10, 11],
|
|
98
|
+
* [9, 10, 11, 12],
|
|
99
|
+
* [10, 11, 12, 13]
|
|
100
|
+
* ]);
|
|
101
|
+
*
|
|
102
|
+
* // Create a text-finder to find the text '5'.
|
|
103
|
+
* const textFinder = await univerAPI.createTextFinderAsync('5');
|
|
104
|
+
* console.log(textFinder.getCurrentMatch().getA1Notation()); // current match cell is A5
|
|
105
|
+
*
|
|
106
|
+
* // Find the previous matched range.
|
|
107
|
+
* const previousMatch = textFinder.findPrevious();
|
|
108
|
+
* console.log(previousMatch.getA1Notation()); // B4
|
|
109
|
+
* console.log(textFinder.getCurrentMatch().getA1Notation()); // current match cell is B4
|
|
49
110
|
* ```
|
|
50
111
|
*/
|
|
51
112
|
findPrevious(): Nullable<FRange>;
|
|
52
113
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* @
|
|
114
|
+
* Get the current matched cell of the current sheet.
|
|
115
|
+
* If current sheet changed, use `await textFinder.ensureCompleteAsync()` to ensure the find operation is completed.
|
|
116
|
+
* @returns {Nullable<FRange>} The current matched cell.
|
|
117
|
+
* @throws If the find operation is not completed.
|
|
56
118
|
* @example
|
|
57
119
|
* ```typescript
|
|
58
|
-
*
|
|
59
|
-
* const
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
120
|
+
* // Assume the current sheet is empty sheet.
|
|
121
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
122
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
123
|
+
* const fRange = fWorksheet.getRange('A1:D10');
|
|
124
|
+
* fRange.setValues([
|
|
125
|
+
* [1, 2, 3, 4],
|
|
126
|
+
* [2, 3, 4, 5],
|
|
127
|
+
* [3, 4, 5, 6],
|
|
128
|
+
* [4, 5, 6, 7],
|
|
129
|
+
* [5, 6, 7, 8],
|
|
130
|
+
* [6, 7, 8, 9],
|
|
131
|
+
* [7, 8, 9, 10],
|
|
132
|
+
* [8, 9, 10, 11],
|
|
133
|
+
* [9, 10, 11, 12],
|
|
134
|
+
* [10, 11, 12, 13]
|
|
135
|
+
* ]);
|
|
136
|
+
*
|
|
137
|
+
* // Create a text-finder to find the text '5'.
|
|
138
|
+
* const textFinder = await univerAPI.createTextFinderAsync('5');
|
|
139
|
+
*
|
|
140
|
+
* // Get the current matched range.
|
|
141
|
+
* const currentMatch = textFinder.getCurrentMatch();
|
|
142
|
+
* console.log(currentMatch.getA1Notation()); // A5
|
|
63
143
|
* ```
|
|
64
144
|
*/
|
|
65
145
|
getCurrentMatch(): Nullable<FRange>;
|
|
66
146
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* @
|
|
147
|
+
* Set the match case option, if true, the find operation will match case, otherwise, the find operation will ignore case.
|
|
148
|
+
* If current sheet changed, use `await textFinder.ensureCompleteAsync()` to ensure the find operation is completed.
|
|
149
|
+
* @param {boolean} matchCase - Whether to match case.
|
|
150
|
+
* @returns {Promise<IFTextFinder>} The text-finder instance.
|
|
70
151
|
* @example
|
|
71
152
|
* ```typescript
|
|
72
|
-
*
|
|
153
|
+
* // Assume the current sheet is empty sheet.
|
|
154
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
155
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
156
|
+
* const fRange = fWorksheet.getRange('A1:D1');
|
|
157
|
+
* fRange.setValues([
|
|
158
|
+
* ['hello univer', 'hello UNIVER', 'HELLO UNIVER', 'HELLO univer'],
|
|
159
|
+
* ]);
|
|
160
|
+
*
|
|
161
|
+
* // Create a text-finder to find the text 'univer'.
|
|
162
|
+
* const textFinder = await univerAPI.createTextFinderAsync('univer');
|
|
163
|
+
* let matchCells = textFinder.findAll();
|
|
164
|
+
* matchCells.forEach((cell) => {
|
|
165
|
+
* console.log(cell.getA1Notation()); // A1, B1, C1, D1
|
|
166
|
+
* });
|
|
167
|
+
*
|
|
168
|
+
* // Set the match case.
|
|
73
169
|
* await textFinder.matchCaseAsync(true);
|
|
170
|
+
* matchCells = textFinder.findAll();
|
|
171
|
+
* matchCells.forEach((cell) => {
|
|
172
|
+
* console.log(cell.getA1Notation()); // A1, D1
|
|
173
|
+
* });
|
|
74
174
|
* ```
|
|
75
175
|
*/
|
|
76
176
|
matchCaseAsync(matchCase: boolean): Promise<IFTextFinder>;
|
|
77
177
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* @
|
|
178
|
+
* Set the match entire cell option, if true, the find operation will match entire cell value, otherwise, the find operation will match part of the cell value.
|
|
179
|
+
* If current sheet changed, use `await textFinder.ensureCompleteAsync()` to ensure the find operation is completed.
|
|
180
|
+
* @param {boolean} matchEntireCell - Whether to match entire cell value.
|
|
181
|
+
* @returns {Promise<IFTextFinder>} The text-finder instance.
|
|
81
182
|
* @example
|
|
82
183
|
* ```typescript
|
|
83
|
-
*
|
|
184
|
+
* // Assume the current sheet is empty sheet.
|
|
185
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
186
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
187
|
+
* const fRange = fWorksheet.getRange('A1:D1');
|
|
188
|
+
* fRange.setValues([
|
|
189
|
+
* ['hello univer', 'hello univer 1', 'hello univer 2', 'hello univer 3'],
|
|
190
|
+
* ]);
|
|
191
|
+
*
|
|
192
|
+
* // Create a text-finder to find the text 'hello univer'.
|
|
193
|
+
* const textFinder = await univerAPI.createTextFinderAsync('hello univer');
|
|
194
|
+
* let matchCells = textFinder.findAll();
|
|
195
|
+
* matchCells.forEach((cell) => {
|
|
196
|
+
* console.log(cell.getA1Notation()); // A1, B1, C1, D1
|
|
197
|
+
* });
|
|
198
|
+
*
|
|
199
|
+
* // Set the match entire cell.
|
|
84
200
|
* await textFinder.matchEntireCellAsync(true);
|
|
201
|
+
* matchCells = textFinder.findAll();
|
|
202
|
+
* matchCells.forEach((cell) => {
|
|
203
|
+
* console.log(cell.getA1Notation()); // A1
|
|
204
|
+
* });
|
|
85
205
|
* ```
|
|
86
206
|
*/
|
|
87
207
|
matchEntireCellAsync(matchEntireCell: boolean): Promise<IFTextFinder>;
|
|
88
208
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* @
|
|
209
|
+
* Set the match formula text option, if true, the find operation will match formula text, otherwise, the find operation will match value.
|
|
210
|
+
* If current sheet changed, use `await textFinder.ensureCompleteAsync()` to ensure the find operation is completed.
|
|
211
|
+
* @param {boolean} matchFormulaText - Whether to match formula text.
|
|
212
|
+
* @returns {Promise<IFTextFinder>} The text-finder instance.
|
|
92
213
|
* @example
|
|
93
214
|
* ```typescript
|
|
94
|
-
*
|
|
215
|
+
* // Assume the current sheet is empty sheet.
|
|
216
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
217
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
218
|
+
* const fRange = fWorksheet.getRange('A1:D1');
|
|
219
|
+
* fRange.setValues([
|
|
220
|
+
* ['sum', '1', '=SUM(2)', '3'],
|
|
221
|
+
* ]);
|
|
222
|
+
*
|
|
223
|
+
* // Create a text-finder to find the text 'sum'.
|
|
224
|
+
* const textFinder = await univerAPI.createTextFinderAsync('sum');
|
|
225
|
+
* let matchCells = textFinder.findAll();
|
|
226
|
+
* matchCells.forEach((cell) => {
|
|
227
|
+
* console.log(cell.getA1Notation()); // A1
|
|
228
|
+
* });
|
|
229
|
+
*
|
|
230
|
+
* // Set the match entire cell.
|
|
95
231
|
* await textFinder.matchFormulaTextAsync(true);
|
|
232
|
+
* matchCells = textFinder.findAll();
|
|
233
|
+
* matchCells.forEach((cell) => {
|
|
234
|
+
* console.log(cell.getA1Notation()); // A1, C1
|
|
235
|
+
* });
|
|
96
236
|
* ```
|
|
97
237
|
*/
|
|
98
238
|
matchFormulaTextAsync(matchFormulaText: boolean): Promise<IFTextFinder>;
|
|
99
239
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* @
|
|
103
|
-
* @
|
|
240
|
+
* Replace all the matched text with the given text.
|
|
241
|
+
* If current sheet changed, use `await textFinder.ensureCompleteAsync()` to ensure the find operation is completed.
|
|
242
|
+
* @param {string} replaceText - The text to replace.
|
|
243
|
+
* @returns {Promise<number>} The count of replaced text.
|
|
244
|
+
* @throws If the find operation is not completed.
|
|
104
245
|
* @example
|
|
105
246
|
* ```typescript
|
|
247
|
+
* // Assume the current sheet is empty sheet.
|
|
248
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
249
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
250
|
+
* const fRange = fWorksheet.getRange('A1:D1');
|
|
251
|
+
* fRange.setValues([
|
|
252
|
+
* ['hello', 'hello', 'hello', 'hello'],
|
|
253
|
+
* ]);
|
|
254
|
+
*
|
|
255
|
+
* // Create a text-finder to find the text 'hello'.
|
|
106
256
|
* const textFinder = await univerAPI.createTextFinderAsync('hello');
|
|
107
|
-
*
|
|
108
|
-
*
|
|
257
|
+
*
|
|
258
|
+
* // Replace all the matched text with 'hello univer'.
|
|
259
|
+
* const count = await textFinder.replaceAllWithAsync('hello univer');
|
|
260
|
+
* console.log(count); // 4
|
|
261
|
+
* console.log(fRange.getValues()); // [['hello univer', 'hello univer', 'hello univer', 'hello univer']]
|
|
109
262
|
* ```
|
|
110
263
|
*/
|
|
111
264
|
replaceAllWithAsync(replaceText: string): Promise<number>;
|
|
112
265
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* @
|
|
116
|
-
* @
|
|
266
|
+
* Replace the current matched text with the given text.
|
|
267
|
+
* If current sheet changed, use `await textFinder.ensureCompleteAsync()` to ensure the find operation is completed.
|
|
268
|
+
* @param {string} replaceText - The text to replace.
|
|
269
|
+
* @returns {Promise<boolean>} Whether the replace is successful.
|
|
270
|
+
* @throws If the find operation is not completed.
|
|
117
271
|
* @example
|
|
118
272
|
* ```typescript
|
|
273
|
+
* // Assume the current sheet is empty sheet.
|
|
274
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
275
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
276
|
+
* const fRange = fWorksheet.getRange('B1:E1');
|
|
277
|
+
* fRange.setValues([
|
|
278
|
+
* ['hello', 'hello', 'hello', 'hello'],
|
|
279
|
+
* ]);
|
|
280
|
+
*
|
|
281
|
+
* // Create a text-finder to find the text 'hello'.
|
|
119
282
|
* const textFinder = await univerAPI.createTextFinderAsync('hello');
|
|
120
|
-
*
|
|
121
|
-
*
|
|
283
|
+
*
|
|
284
|
+
* // Replace the current matched text with 'hello univer'.
|
|
285
|
+
* const replaced = await textFinder.replaceWithAsync('hello univer');
|
|
286
|
+
* console.log(replaced); // true
|
|
287
|
+
* console.log(fRange.getValues()); // [['hello', 'hello', 'hello', 'hello univer']]
|
|
122
288
|
* ```
|
|
123
289
|
*/
|
|
124
290
|
replaceWithAsync(replaceText: string): Promise<boolean>;
|
|
125
291
|
/**
|
|
126
|
-
* ensure the find operation is completed
|
|
127
|
-
* @returns
|
|
292
|
+
* Ensure the find operation is completed. Especially when the current sheet changed use this method to ensure the find operation is completed.
|
|
293
|
+
* @returns {Promise<Nullable<IFindComplete>>} The find complete result.
|
|
128
294
|
* @example
|
|
129
295
|
* ```typescript
|
|
130
|
-
*
|
|
131
|
-
* const
|
|
132
|
-
*
|
|
296
|
+
* // Create a text-finder to find the text '1'.
|
|
297
|
+
* const textFinder = await univerAPI.createTextFinderAsync('1');
|
|
298
|
+
*
|
|
299
|
+
* // Find all cells that contain the text '1'.
|
|
300
|
+
* const matchCells = textFinder.findAll();
|
|
301
|
+
* matchCells.forEach((cell) => {
|
|
302
|
+
* console.log(cell.getA1Notation());
|
|
303
|
+
* });
|
|
304
|
+
*
|
|
305
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
306
|
+
* const sheets = fWorkbook.getSheets();
|
|
307
|
+
*
|
|
308
|
+
* // Change the current sheet to the second sheet.
|
|
309
|
+
* sheets[1]?.activate();
|
|
310
|
+
*
|
|
311
|
+
* // Ensure the find operation is completed of the current sheet.
|
|
312
|
+
* await textFinder.ensureCompleteAsync();
|
|
313
|
+
* const matchCells2 = textFinder.findAll();
|
|
314
|
+
* matchCells2.forEach((cell) => {
|
|
315
|
+
* console.log(cell.getA1Notation());
|
|
316
|
+
* });
|
|
133
317
|
* ```
|
|
134
318
|
*/
|
|
135
319
|
ensureCompleteAsync(): Promise<Nullable<IFindComplete>>;
|
|
@@ -10,7 +10,31 @@ export interface IFUniverFindReplaceMixin {
|
|
|
10
10
|
* @returns {Promise<FTextFinder | null>} A promise that resolves to the text-finder instance.
|
|
11
11
|
* @example
|
|
12
12
|
* ```typescript
|
|
13
|
-
*
|
|
13
|
+
* // Assume the current sheet is empty sheet.
|
|
14
|
+
* const fWorkbook = univerAPI.getActiveWorkbook();
|
|
15
|
+
* const fWorksheet = fWorkbook.getActiveSheet();
|
|
16
|
+
* const fRange = fWorksheet.getRange('A1:D10');
|
|
17
|
+
* fRange.setValues([
|
|
18
|
+
* [1, 2, 3, 4],
|
|
19
|
+
* [2, 3, 4, 5],
|
|
20
|
+
* [3, 4, 5, 6],
|
|
21
|
+
* [4, 5, 6, 7],
|
|
22
|
+
* [5, 6, 7, 8],
|
|
23
|
+
* [6, 7, 8, 9],
|
|
24
|
+
* [7, 8, 9, 10],
|
|
25
|
+
* [8, 9, 10, 11],
|
|
26
|
+
* [9, 10, 11, 12],
|
|
27
|
+
* [10, 11, 12, 13]
|
|
28
|
+
* ]);
|
|
29
|
+
*
|
|
30
|
+
* // Create a text-finder to find the text '5'.
|
|
31
|
+
* const textFinder = await univerAPI.createTextFinderAsync('5');
|
|
32
|
+
*
|
|
33
|
+
* // Find all cells that contain the text '5'.
|
|
34
|
+
* const matchCells = textFinder.findAll();
|
|
35
|
+
* matchCells.forEach((cell) => {
|
|
36
|
+
* console.log(cell.getA1Notation()); // D2, C3, B4, A5
|
|
37
|
+
* });
|
|
14
38
|
* ```
|
|
15
39
|
*/
|
|
16
40
|
createTextFinderAsync(text: string): Promise<FTextFinder | null>;
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(i,n){typeof exports=="object"&&typeof module<"u"?n(require("@univerjs/core"),require("@univerjs/find-replace"),require("@univerjs/sheets/facade"),require("@univerjs/core/facade")):typeof define=="function"&&define.amd?define(["@univerjs/core","@univerjs/find-replace","@univerjs/sheets/facade","@univerjs/core/facade"],n):(i=typeof globalThis<"u"?globalThis:i||self,n(i.UniverCore,i.UniverFindReplace,i.UniverSheetsFacade,i.UniverCoreFacade))})(this,function(i,n,c,
|
|
1
|
+
(function(i,n){typeof exports=="object"&&typeof module<"u"?n(require("@univerjs/core"),require("@univerjs/find-replace"),require("@univerjs/sheets/facade"),require("@univerjs/core/facade")):typeof define=="function"&&define.amd?define(["@univerjs/core","@univerjs/find-replace","@univerjs/sheets/facade","@univerjs/core/facade"],n):(i=typeof globalThis<"u"?globalThis:i||self,n(i.UniverCore,i.UniverFindReplace,i.UniverSheetsFacade,i.UniverCoreFacade))})(this,function(i,n,c,p){"use strict";var v=Object.defineProperty;var y=(i,n,c)=>n in i?v(i,n,{enumerable:!0,configurable:!0,writable:!0,value:c}):i[n]=c;var l=(i,n,c)=>y(i,typeof n!="symbol"?n+"":n,c);var _=Object.getOwnPropertyDescriptor,f=(o,e,t,s)=>{for(var r=s>1?void 0:s?_(e,t):e,a=o.length-1,h;a>=0;a--)(h=o[a])&&(r=h(r)||r);return r},u=(o,e)=>(t,s)=>e(t,s,o);let d=class extends i.Disposable{constructor(e,t,s,r){super();l(this,"_state",new n.FindReplaceState);l(this,"_model");l(this,"_complete");this._injector=t,this._univerInstanceService=s,this._findReplaceService=r;const a=this._findReplaceService.getProviders();this._model=this._injector.createInstance(n.FindReplaceModel,this._state,a);const h={...n.createInitFindReplaceState(),...e};this._state.changeState(h)}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,findCompleted:!1}),new Promise(t=>{const s=this._state.stateUpdates$.subscribe(async r=>{r.findCompleted===!0&&(s.unsubscribe(),await this.ensureCompleteAsync(),t(this))})})}async matchEntireCellAsync(e){return this._state.changeState({matchesTheWholeCell:e,findCompleted:!1}),new Promise(t=>{const s=this._state.stateUpdates$.subscribe(async r=>{r.findCompleted===!0&&(s.unsubscribe(),await this.ensureCompleteAsync(),t(this))})})}async matchFormulaTextAsync(e){return this._state.changeState({findBy:e?n.FindBy.FORMULA:n.FindBy.VALUE,findCompleted:!1}),new Promise(t=>{const s=this._state.stateUpdates$.subscribe(async r=>{r.findCompleted===!0&&(s.unsubscribe(),await this.ensureCompleteAsync(),t(this))})})}async replaceAllWithAsync(e){var s,r,a;await this._state.changeState({replaceRevealed:!0,replaceString:e});const t=(a=(r=await((s=this._model)==null?void 0:s.replaceAll()))==null?void 0:r.success)!=null?a: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;this._complete=await((e=this._model)==null?void 0:e.start())}_findMatchToFRange(e){const{unitId:t}=e,{subUnitId:s,range:r}=e.range,a=this._univerInstanceService.getUnit(t),h=a.getSheetBySheetId(s);return this._injector.createInstance(c.FRange,a,h,r)}};d=f([u(1,i.Inject(i.Injector)),u(2,i.IUniverInstanceService),u(3,n.IFindReplaceService)],d);class m extends p.FUniver{async createTextFinderAsync(e){const t={findString:e},s=this._injector.createInstance(d,t);return await s.ensureCompleteAsync(),s}}p.FUniver.extend(m)});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-find-replace",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UniverSheet find replace plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -58,18 +58,18 @@
|
|
|
58
58
|
"rxjs": ">=7.0.0"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@univerjs/core": "0.6.
|
|
62
|
-
"@univerjs/
|
|
63
|
-
"@univerjs/
|
|
64
|
-
"@univerjs/
|
|
65
|
-
"@univerjs/sheets": "0.6.
|
|
61
|
+
"@univerjs/core": "0.6.1",
|
|
62
|
+
"@univerjs/engine-render": "0.6.1",
|
|
63
|
+
"@univerjs/sheets": "0.6.1",
|
|
64
|
+
"@univerjs/find-replace": "0.6.1",
|
|
65
|
+
"@univerjs/sheets-ui": "0.6.1"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"rxjs": "^7.8.1",
|
|
69
69
|
"typescript": "^5.7.3",
|
|
70
|
-
"vite": "^6.1.
|
|
71
|
-
"vitest": "^3.0.
|
|
72
|
-
"@univerjs-infra/shared": "0.6.
|
|
70
|
+
"vite": "^6.1.1",
|
|
71
|
+
"vitest": "^3.0.6",
|
|
72
|
+
"@univerjs-infra/shared": "0.6.1"
|
|
73
73
|
},
|
|
74
74
|
"scripts": {
|
|
75
75
|
"test": "vitest run",
|