@univerjs/find-replace 0.1.1 → 0.1.3
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/README.md +12 -2
- package/lib/cjs/index.js +2 -2
- package/lib/es/index.js +773 -417
- package/lib/index.css +1 -1
- package/lib/types/{views/dialog/Dialog.d.ts → commands/command/replace.command.d.ts} +3 -2
- package/lib/types/commands/operations/find-replace.operation.d.ts +0 -2
- package/lib/types/controllers/find-replace.controller.d.ts +7 -5
- package/lib/types/controllers/find-replace.shortcut.d.ts +1 -1
- package/lib/types/index.d.ts +3 -2
- package/lib/types/locale/en-US.d.ts +48 -2
- package/lib/types/locale/zh-CN.d.ts +2 -16
- package/lib/types/services/context-keys.d.ts +7 -2
- package/lib/types/services/find-replace.service.d.ts +165 -30
- package/lib/types/views/dialog/FindReplaceDialog.d.ts +19 -0
- package/lib/types/views/dialog/SearchInput.d.ts +28 -0
- package/lib/umd/index.js +2 -2
- package/package.json +17 -15
- /package/lib/types/views/dialog/{Dialog.stories.d.ts → FindReplaceDialog.stories.d.ts} +0 -0
package/lib/index.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.univer-find-replace-expand-container{margin-top:16px;text-align:center}
|
|
1
|
+
.univer-find-replace-dialog-container{display:block}.univer-find-replace-expand-container{margin-top:16px;text-align:center}.univer-find-replace-expand-container .univer-button-text{color:rgb(var(--primary-color))}.univer-find-replace-buttons-group{display:flex;justify-content:space-between;margin-top:24px}.univer-find-replace-buttons-group-right>button:not(:first-child){margin-left:8px}
|
|
@@ -13,5 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import
|
|
17
|
-
export declare
|
|
16
|
+
import type { ICommand } from '@univerjs/core';
|
|
17
|
+
export declare const ReplaceCurrentMatchCommand: ICommand;
|
|
18
|
+
export declare const ReplaceAllMatchesCommand: ICommand;
|
|
@@ -16,7 +16,5 @@
|
|
|
16
16
|
import type { IOperation } from '@univerjs/core';
|
|
17
17
|
export declare const OpenFindDialogOperation: IOperation;
|
|
18
18
|
export declare const OpenReplaceDialogOperation: IOperation;
|
|
19
|
-
export declare const ToggleReplaceDialogOperation: IOperation;
|
|
20
|
-
export declare const CloseFindReplaceDialogOperation: IOperation;
|
|
21
19
|
export declare const GoToNextMatchOperation: IOperation;
|
|
22
20
|
export declare const GoToPreviousMatchOperation: IOperation;
|
|
@@ -13,25 +13,27 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { ICommandService, IContextService, LocaleService, RxDisposable } from '@univerjs/core';
|
|
16
|
+
import { ICommandService, IContextService, ILogService, IUniverInstanceService, LocaleService, RxDisposable } from '@univerjs/core';
|
|
17
17
|
import { ComponentManager, IDialogService, ILayoutService, IMenuService, IShortcutService } from '@univerjs/ui';
|
|
18
18
|
import { Injector } from '@wendellhu/redi';
|
|
19
19
|
import { IFindReplaceService } from '../services/find-replace.service';
|
|
20
20
|
export declare class FindReplaceController extends RxDisposable {
|
|
21
|
+
private readonly _univerInstanceService;
|
|
21
22
|
private readonly _menuService;
|
|
22
23
|
private readonly _shortcutService;
|
|
23
24
|
private readonly _commandService;
|
|
24
25
|
private readonly _findReplaceService;
|
|
26
|
+
private readonly _logService;
|
|
25
27
|
private readonly _dialogService;
|
|
26
28
|
private readonly _contextService;
|
|
27
29
|
private readonly _layoutService;
|
|
28
30
|
private readonly _localeService;
|
|
29
31
|
private readonly _componentManager;
|
|
30
32
|
private readonly _injector;
|
|
31
|
-
constructor(_menuService: IMenuService, _shortcutService: IShortcutService, _commandService: ICommandService, _findReplaceService: IFindReplaceService, _dialogService: IDialogService, _contextService: IContextService, _layoutService: ILayoutService, _localeService: LocaleService, _componentManager: ComponentManager, _injector: Injector);
|
|
32
|
-
private
|
|
33
|
-
private _initUI;
|
|
33
|
+
constructor(_univerInstanceService: IUniverInstanceService, _menuService: IMenuService, _shortcutService: IShortcutService, _commandService: ICommandService, _findReplaceService: IFindReplaceService, _logService: ILogService, _dialogService: IDialogService, _contextService: IContextService, _layoutService: ILayoutService, _localeService: LocaleService, _componentManager: ComponentManager, _injector: Injector);
|
|
34
|
+
private _initCommands;
|
|
34
35
|
private _initShortcuts;
|
|
36
|
+
private _initUI;
|
|
35
37
|
private _openPanel;
|
|
36
|
-
|
|
38
|
+
closePanel(): void;
|
|
37
39
|
}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { type IShortcutItem } from '@univerjs/ui';
|
|
17
17
|
export declare const OpenFindDialogShortcutItem: IShortcutItem;
|
|
18
|
+
export declare const MacOpenFindDialogShortcutItem: IShortcutItem;
|
|
18
19
|
export declare const OpenReplaceDialogShortcutItem: IShortcutItem;
|
|
19
|
-
export declare const CloseFRDialogShortcutItem: IShortcutItem;
|
|
20
20
|
export declare const GoToNextFindMatchShortcutItem: IShortcutItem;
|
|
21
21
|
export declare const GoToPreviousFindMatchShortcutItem: IShortcutItem;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -14,5 +14,6 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
export { UniverFindReplacePlugin } from './plugin';
|
|
17
|
-
export
|
|
18
|
-
export {
|
|
17
|
+
export { FindReplaceController } from './controllers/find-replace.controller';
|
|
18
|
+
export type { IFindComplete, IFindMoveParams, IFindMatch, IFindQuery, IFindReplaceProvider, IReplaceAllResult, } from './services/find-replace.service';
|
|
19
|
+
export { FindModel, IFindReplaceService, FindBy, FindScope, FindDirection } from './services/find-replace.service';
|
|
@@ -13,6 +13,52 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
declare const locale: {
|
|
17
|
+
'find-replace': {
|
|
18
|
+
toolbar: string;
|
|
19
|
+
shortcut: {
|
|
20
|
+
'open-find-dialog': string;
|
|
21
|
+
'open-replace-dialog': string;
|
|
22
|
+
'close-dialog': string;
|
|
23
|
+
'go-to-next-match': string;
|
|
24
|
+
'go-to-previous-match': string;
|
|
25
|
+
};
|
|
26
|
+
dialog: {
|
|
27
|
+
title: string;
|
|
28
|
+
find: string;
|
|
29
|
+
replace: string;
|
|
30
|
+
'replace-all': string;
|
|
31
|
+
'case-sensitive': string;
|
|
32
|
+
'find-placeholder': string;
|
|
33
|
+
'advanced-finding': string;
|
|
34
|
+
'replace-placeholder': string;
|
|
35
|
+
'match-the-whole-cell': string;
|
|
36
|
+
'find-direction': {
|
|
37
|
+
title: string;
|
|
38
|
+
row: string;
|
|
39
|
+
column: string;
|
|
40
|
+
};
|
|
41
|
+
'find-scope': {
|
|
42
|
+
title: string;
|
|
43
|
+
'current-sheet': string;
|
|
44
|
+
workbook: string;
|
|
45
|
+
};
|
|
46
|
+
'find-by': {
|
|
47
|
+
title: string;
|
|
48
|
+
value: string;
|
|
49
|
+
formula: string;
|
|
50
|
+
};
|
|
51
|
+
'no-match': string;
|
|
52
|
+
'no-result': string;
|
|
53
|
+
};
|
|
54
|
+
replace: {
|
|
55
|
+
'all-success': string;
|
|
56
|
+
'all-failure': string;
|
|
57
|
+
confirm: {
|
|
58
|
+
title: string;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
'find-replace-shortcuts': string;
|
|
63
|
+
};
|
|
18
64
|
export default locale;
|
|
@@ -13,20 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
'find-replace': {
|
|
19
|
-
dialog: {
|
|
20
|
-
title: string;
|
|
21
|
-
find: string;
|
|
22
|
-
replace: string;
|
|
23
|
-
'replace-all': string;
|
|
24
|
-
'find-range': string;
|
|
25
|
-
'find-placeholder': string;
|
|
26
|
-
'advanced-finding': string;
|
|
27
|
-
'replace-placeholder': string;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
};
|
|
16
|
+
import type enUS from './en-US';
|
|
17
|
+
declare const locale: typeof enUS;
|
|
32
18
|
export default locale;
|
|
@@ -13,7 +13,12 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
export declare const FIND_REPLACE_INPUT_FOCUS = "FIND_REPLACE_INPUT_FOCUS";
|
|
16
17
|
/**
|
|
17
|
-
* If find replace
|
|
18
|
+
* If find replace panel is focused.
|
|
18
19
|
*/
|
|
19
|
-
export declare const
|
|
20
|
+
export declare const FIND_REPLACE_DIALOG_FOCUS = "FIND_REPLACE_DIALOG_FOCUS";
|
|
21
|
+
/**
|
|
22
|
+
* If the find replace feature is activated and the replace is revealed.
|
|
23
|
+
*/
|
|
24
|
+
export declare const FIND_REPLACE_REPLACE_REVEALED = "FIND_REPLACE_REPLACE_REVEALED";
|
|
@@ -13,10 +13,12 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
16
|
+
import type { Nullable } from '@univerjs/core';
|
|
17
|
+
import { Disposable, IContextService, ILogService, IUniverInstanceService } from '@univerjs/core';
|
|
17
18
|
import type { IDisposable } from '@wendellhu/redi';
|
|
18
19
|
import { Injector } from '@wendellhu/redi';
|
|
19
20
|
import type { Observable } from 'rxjs';
|
|
21
|
+
import { BehaviorSubject } from 'rxjs';
|
|
20
22
|
export type FindProgressFn = () => void;
|
|
21
23
|
export interface IFindComplete<T extends IFindMatch = IFindMatch> {
|
|
22
24
|
results: T[];
|
|
@@ -25,26 +27,64 @@ export interface IFindMatch<T = unknown> {
|
|
|
25
27
|
provider: string;
|
|
26
28
|
unitId: string;
|
|
27
29
|
range: T;
|
|
30
|
+
/** Indicates if the match could be replaced. */
|
|
31
|
+
replaceable?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface IFindMoveParams {
|
|
34
|
+
/** Go to next (previous) matching in a loop. */
|
|
35
|
+
loop?: boolean;
|
|
36
|
+
/** If the the selection is on the match and then should stay on the match. */
|
|
37
|
+
stayIfOnMatch?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* If this param is true, we should only change matching position without performing focusing.
|
|
40
|
+
* This usually happens when "moving" is triggered when a document's content changes.
|
|
41
|
+
*/
|
|
42
|
+
noFocus?: boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface IReplaceAllResult {
|
|
45
|
+
success: number;
|
|
46
|
+
failure: number;
|
|
28
47
|
}
|
|
29
48
|
export declare abstract class FindModel extends Disposable {
|
|
30
49
|
abstract readonly unitId: string;
|
|
50
|
+
/**
|
|
51
|
+
* Find model should emit new matches from this observable if they changed no matter due to incremental
|
|
52
|
+
* or document's content changes.
|
|
53
|
+
*/
|
|
54
|
+
abstract readonly matchesUpdate$: Observable<IFindMatch[]>;
|
|
55
|
+
abstract readonly activelyChangingMatch$: Observable<IFindMatch>;
|
|
31
56
|
abstract getMatches(): IFindMatch[];
|
|
32
|
-
abstract moveToNextMatch(
|
|
33
|
-
abstract moveToPreviousMatch(
|
|
57
|
+
abstract moveToNextMatch(params?: IFindMoveParams): IFindMatch | null;
|
|
58
|
+
abstract moveToPreviousMatch(params?: IFindMoveParams): IFindMatch | null;
|
|
59
|
+
/** Replace the currently focused matching if there is one. */
|
|
60
|
+
abstract replace(replaceString: string): Promise<boolean>;
|
|
61
|
+
/**
|
|
62
|
+
* Replace all matches. This method would return how many
|
|
63
|
+
*/
|
|
64
|
+
abstract replaceAll(replaceString: string): Promise<IReplaceAllResult>;
|
|
34
65
|
}
|
|
35
66
|
/**
|
|
36
67
|
* A provider should be implemented by a business to provide the find results.
|
|
37
68
|
*/
|
|
38
69
|
export interface IFindReplaceProvider {
|
|
39
70
|
find(query: IFindQuery): Promise<FindModel[]>;
|
|
40
|
-
|
|
71
|
+
terminate(): void;
|
|
41
72
|
}
|
|
73
|
+
type IReplaceableMatch = IFindMatch & {
|
|
74
|
+
replaceable: boolean;
|
|
75
|
+
};
|
|
42
76
|
/**
|
|
43
77
|
* This service works as a core of the find & replace feature.
|
|
44
78
|
*/
|
|
45
79
|
export interface IFindReplaceService {
|
|
46
80
|
readonly stateUpdates$: Observable<Partial<IFindReplaceState>>;
|
|
47
81
|
readonly state$: Observable<IFindReplaceState>;
|
|
82
|
+
readonly currentMatch$: Observable<Nullable<IFindMatch>>;
|
|
83
|
+
/** An observable value of all matches those could be replaced. */
|
|
84
|
+
readonly replaceables$: Observable<IReplaceableMatch[]>;
|
|
85
|
+
readonly focusSignal$: Observable<void>;
|
|
86
|
+
readonly revealed: boolean;
|
|
87
|
+
readonly replaceRevealed: boolean;
|
|
48
88
|
/**
|
|
49
89
|
* Register a find replace provider to the service. The provider is the actual bearer to
|
|
50
90
|
* perform the find in different kinds of documents or different environments.
|
|
@@ -52,60 +92,114 @@ export interface IFindReplaceService {
|
|
|
52
92
|
* @param provider the find replace provider
|
|
53
93
|
*/
|
|
54
94
|
registerFindReplaceProvider(provider: IFindReplaceProvider): IDisposable;
|
|
95
|
+
/**
|
|
96
|
+
* Get find string from the internal state.
|
|
97
|
+
*/
|
|
98
|
+
getFindString(): string;
|
|
55
99
|
/**
|
|
56
100
|
* Start a find & replace session.
|
|
57
101
|
*
|
|
58
|
-
* @returns
|
|
102
|
+
* @returns execution result
|
|
103
|
+
*/
|
|
104
|
+
start(revealReplace?: boolean): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Terminate a find session and clear all caches.
|
|
59
107
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
108
|
+
terminate(): void;
|
|
109
|
+
/**
|
|
110
|
+
* Start searching with the current conditions.
|
|
111
|
+
*/
|
|
112
|
+
find(): void;
|
|
113
|
+
focusFindInput(): void;
|
|
62
114
|
revealReplace(): void;
|
|
63
115
|
changeFindString(value: string): void;
|
|
116
|
+
changeInputtingFindString(value: string): void;
|
|
117
|
+
changeReplaceString(value: string): void;
|
|
118
|
+
changeCaseSensitive(sensitive: boolean): void;
|
|
119
|
+
changeMatchesTheWholeCell(wholeCell: boolean): void;
|
|
120
|
+
changeFindScope(scope: FindScope): void;
|
|
121
|
+
changeFindDirection(direction: FindDirection): void;
|
|
122
|
+
changeFindBy(findBy: FindBy): void;
|
|
64
123
|
moveToNextMatch(): void;
|
|
65
124
|
moveToPreviousMatch(): void;
|
|
66
|
-
replace(): boolean
|
|
67
|
-
replaceAll():
|
|
125
|
+
replace(): Promise<boolean>;
|
|
126
|
+
replaceAll(): Promise<IReplaceAllResult>;
|
|
68
127
|
}
|
|
69
128
|
export declare const IFindReplaceService: import("@wendellhu/redi").IdentifierDecorator<IFindReplaceService>;
|
|
70
129
|
/**
|
|
71
130
|
* The find query object with finding options.
|
|
72
131
|
*/
|
|
73
|
-
export interface IFindQuery {
|
|
74
|
-
text: string;
|
|
75
|
-
isRegex?: boolean;
|
|
76
|
-
ignoreCase?: boolean;
|
|
77
|
-
/** Other possible options set by business. */
|
|
78
|
-
[key: string]: boolean | string | number | undefined;
|
|
132
|
+
export interface IFindQuery extends Pick<IFindReplaceState, 'replaceRevealed' | 'findString' | 'caseSensitive' | 'findBy' | 'findDirection' | 'findScope' | 'matchesTheWholeCell'> {
|
|
79
133
|
}
|
|
80
134
|
/**
|
|
81
135
|
* This class stores find replace results and provides methods to perform replace or something.
|
|
136
|
+
*
|
|
137
|
+
* It **only** live through a find-replace session and would be disposed when the user
|
|
138
|
+
* close the find replace dialog (considered as session being terminated).
|
|
82
139
|
*/
|
|
83
140
|
export declare class FindReplaceModel extends Disposable {
|
|
84
141
|
private readonly _state;
|
|
85
142
|
private readonly _providers;
|
|
86
|
-
private readonly _logService;
|
|
87
143
|
private readonly _univerInstanceService;
|
|
88
|
-
private
|
|
144
|
+
private readonly _logService;
|
|
145
|
+
readonly currentMatch$: BehaviorSubject<Nullable<IFindMatch<unknown>>>;
|
|
146
|
+
readonly replaceables$: BehaviorSubject<IReplaceableMatch[]>;
|
|
147
|
+
/** All find models returned by providers. */
|
|
89
148
|
private _findModels;
|
|
149
|
+
/** The find model that the current match is from. */
|
|
150
|
+
private _matchingModel;
|
|
90
151
|
private _matches;
|
|
91
|
-
private
|
|
92
|
-
|
|
93
|
-
|
|
152
|
+
private _currentSearchingDisposables;
|
|
153
|
+
get searched(): boolean;
|
|
154
|
+
constructor(_state: FindReplaceState, _providers: Set<IFindReplaceProvider>, _univerInstanceService: IUniverInstanceService, _logService: ILogService);
|
|
155
|
+
dispose(): void;
|
|
156
|
+
start(): Promise<IFindComplete>;
|
|
157
|
+
/** Call this method to start a `searching`. */
|
|
158
|
+
private _startSearching;
|
|
159
|
+
/** Terminate the current searching session, when searching string is empty. */
|
|
160
|
+
private _stopSearching;
|
|
161
|
+
private _subscribeToModelsChanges;
|
|
162
|
+
replace(): Promise<boolean>;
|
|
163
|
+
replaceAll(): Promise<IReplaceAllResult>;
|
|
164
|
+
getCurrentMatch(): Nullable<IFindMatch>;
|
|
94
165
|
moveToNextMatch(): void;
|
|
95
166
|
moveToPreviousMatch(): void;
|
|
96
167
|
private _moveToInitialMatch;
|
|
97
|
-
|
|
168
|
+
}
|
|
169
|
+
export declare enum FindDirection {
|
|
170
|
+
/** Default. */
|
|
171
|
+
ROW = "row",
|
|
172
|
+
COLUMN = "column"
|
|
173
|
+
}
|
|
174
|
+
export declare enum FindBy {
|
|
175
|
+
VALUE = "value",
|
|
176
|
+
FORMULA = "formula"
|
|
177
|
+
}
|
|
178
|
+
export declare enum FindScope {
|
|
179
|
+
/** Default. */
|
|
180
|
+
SUBUNIT = "subunit",
|
|
181
|
+
/** Find the scope in the current unit. */
|
|
182
|
+
UNIT = "unit"
|
|
98
183
|
}
|
|
99
184
|
export interface IFindReplaceState {
|
|
100
185
|
revealed: boolean;
|
|
101
186
|
/** The string user inputs in the input box. */
|
|
102
187
|
findString: string;
|
|
188
|
+
inputtingFindString: string;
|
|
103
189
|
replaceString?: string;
|
|
104
190
|
/** Indicates if is in replacing mode. */
|
|
105
191
|
replaceRevealed: boolean;
|
|
106
192
|
/** The currently focused match's index (1-based). */
|
|
107
193
|
matchesPosition: number;
|
|
194
|
+
/** The number of all matches. */
|
|
108
195
|
matchesCount: number;
|
|
196
|
+
/** Indicates if an user triggered finding process is progressed. */
|
|
197
|
+
findCompleted: boolean;
|
|
198
|
+
caseSensitive: boolean;
|
|
199
|
+
matchesTheWholeCell: boolean;
|
|
200
|
+
findDirection: FindDirection;
|
|
201
|
+
findScope: FindScope;
|
|
202
|
+
findBy: FindBy;
|
|
109
203
|
}
|
|
110
204
|
/**
|
|
111
205
|
* This class stores find replace options state. These state are stored
|
|
@@ -119,31 +213,72 @@ export declare class FindReplaceState {
|
|
|
119
213
|
readonly state$: Observable<IFindReplaceState>;
|
|
120
214
|
get state(): IFindReplaceState;
|
|
121
215
|
private _findString;
|
|
216
|
+
private _inputtingFindString;
|
|
217
|
+
private _replaceString;
|
|
122
218
|
private _revealed;
|
|
123
219
|
private _replaceRevealed;
|
|
124
220
|
private _matchesPosition;
|
|
125
221
|
private _matchesCount;
|
|
222
|
+
private _caseSensitive;
|
|
223
|
+
private _matchesTheWholeCell;
|
|
224
|
+
private _findDirection;
|
|
225
|
+
private _findScope;
|
|
226
|
+
private _findBy;
|
|
227
|
+
private _findCompleted;
|
|
228
|
+
get inputtingFindString(): string;
|
|
126
229
|
get findString(): string;
|
|
230
|
+
get revealed(): boolean;
|
|
231
|
+
get replaceRevealed(): boolean;
|
|
232
|
+
get matchesPosition(): number;
|
|
233
|
+
get matchesCount(): number;
|
|
234
|
+
get replaceString(): string;
|
|
235
|
+
get caseSensitive(): boolean;
|
|
236
|
+
get matchesTheWholeCell(): boolean;
|
|
237
|
+
get findDirection(): FindDirection;
|
|
238
|
+
get findScope(): FindScope;
|
|
239
|
+
get findBy(): FindBy;
|
|
240
|
+
get findCompleted(): boolean;
|
|
127
241
|
changeState(changes: Partial<IFindReplaceState>): void;
|
|
128
242
|
}
|
|
129
243
|
export declare class FindReplaceService extends Disposable implements IFindReplaceService {
|
|
130
244
|
private readonly _injector;
|
|
131
|
-
private readonly
|
|
132
|
-
private readonly _logService;
|
|
245
|
+
private readonly _contextService;
|
|
133
246
|
private readonly _providers;
|
|
134
247
|
private readonly _state;
|
|
135
248
|
private _model;
|
|
249
|
+
private readonly _currentMatch$;
|
|
250
|
+
readonly currentMatch$: Observable<Nullable<IFindMatch<unknown>>>;
|
|
251
|
+
private readonly _replaceables$;
|
|
252
|
+
readonly replaceables$: Observable<IReplaceableMatch[]>;
|
|
253
|
+
private readonly _focusSignal$;
|
|
254
|
+
readonly focusSignal$: Observable<void>;
|
|
136
255
|
get stateUpdates$(): Observable<Partial<IFindReplaceState>>;
|
|
137
256
|
get state$(): Observable<IFindReplaceState>;
|
|
138
|
-
|
|
139
|
-
|
|
257
|
+
get revealed(): boolean;
|
|
258
|
+
get replaceRevealed(): boolean;
|
|
259
|
+
constructor(_injector: Injector, _contextService: IContextService);
|
|
260
|
+
dispose(): void;
|
|
261
|
+
getCurrentMatch(): Nullable<IFindMatch>;
|
|
262
|
+
getFindString(): string;
|
|
263
|
+
changeFindString(findString: string): void;
|
|
264
|
+
focusFindInput(): void;
|
|
265
|
+
changeInputtingFindString(value: string): void;
|
|
266
|
+
changeReplaceString(replaceString: string): void;
|
|
267
|
+
changeMatchesTheWholeCell(matchesTheWholeCell: boolean): void;
|
|
268
|
+
changeCaseSensitive(caseSensitive: boolean): void;
|
|
269
|
+
changeFindBy(findBy: FindBy): void;
|
|
270
|
+
changeFindScope(scope: FindScope): void;
|
|
271
|
+
changeFindDirection(direction: FindDirection): void;
|
|
140
272
|
moveToNextMatch(): void;
|
|
141
273
|
moveToPreviousMatch(): void;
|
|
142
|
-
replace(): boolean
|
|
143
|
-
replaceAll():
|
|
274
|
+
replace(): Promise<boolean>;
|
|
275
|
+
replaceAll(): Promise<IReplaceAllResult>;
|
|
144
276
|
revealReplace(): void;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
277
|
+
start(revealReplace?: boolean): boolean;
|
|
278
|
+
find(): void;
|
|
279
|
+
terminate(): void;
|
|
148
280
|
registerFindReplaceProvider(provider: IFindReplaceProvider): IDisposable;
|
|
281
|
+
private _toggleRevealReplace;
|
|
282
|
+
private _toggleDisplayRawFormula;
|
|
149
283
|
}
|
|
284
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import React from 'react';
|
|
17
|
+
export declare const FindDialog: React.ForwardRefExoticComponent<React.RefAttributes<unknown>>;
|
|
18
|
+
export declare const ReplaceDialog: React.ForwardRefExoticComponent<React.RefAttributes<unknown>>;
|
|
19
|
+
export declare function FindReplaceDialog(): React.JSX.Element;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { LocaleService } from '@univerjs/core';
|
|
17
|
+
import type { IInputWithSlotProps } from '@univerjs/design';
|
|
18
|
+
import React from 'react';
|
|
19
|
+
import type { IFindReplaceService } from '../../services/find-replace.service';
|
|
20
|
+
export interface ISearchInputProps extends Pick<IInputWithSlotProps, 'onFocus' | 'onBlur' | 'className' | 'onChange'> {
|
|
21
|
+
findCompleted: boolean;
|
|
22
|
+
localeService: LocaleService;
|
|
23
|
+
findReplaceService: IFindReplaceService;
|
|
24
|
+
matchesPosition: number;
|
|
25
|
+
matchesCount: number;
|
|
26
|
+
findString: string;
|
|
27
|
+
}
|
|
28
|
+
export declare function SearchInput(props: ISearchInputProps): React.JSX.Element;
|
package/lib/umd/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(c,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/ui"),require("rxjs"),require("react"),require("@univerjs/design"),require("@wendellhu/redi/react-bindings")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/ui","rxjs","react","@univerjs/design","@wendellhu/redi/react-bindings"],o):(c=typeof globalThis<"u"?globalThis:c||self,o(c.UniverFindReplace={},c.UniverCore,c["@wendellhu/redi"],c.UniverUi,c.rxjs,c.React,c.UniverDesign,c["@wendellhu/redi/react-bindings"]))})(this,function(c,o,v,h,O,p,_,T){"use strict";var je=Object.defineProperty;var be=(c,o,v)=>o in c?je(c,o,{enumerable:!0,configurable:!0,writable:!0,value:v}):c[o]=v;var u=(c,o,v)=>(be(c,typeof o!="symbol"?o+"":o,v),v);var g=function(){return g=Object.assign||function(t){for(var e,r=1,i=arguments.length;r<i;r++){e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t},g.apply(this,arguments)},z=function(t,e){var r={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(r[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,i=Object.getOwnPropertySymbols(t);n<i.length;n++)e.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(t,i[n])&&(r[i[n]]=t[i[n]]);return r},E=p.forwardRef(function(t,e){var r=t.icon,i=t.id,n=t.className,a=t.extend,s=z(t,["icon","id","className","extend"]),l="univerjs-icon univerjs-icon-".concat(i," ").concat(n||"").trim(),m=p.useRef("_".concat(Y()));return D(r,"".concat(i),{defIds:r.defIds,idSuffix:m.current},g({ref:e,className:l},s),a)});function D(t,e,r,i,n){return p.createElement(t.tag,g(g({key:e},Z(t,r,n)),i),(J(t,r).children||[]).map(function(a,s){return D(a,"".concat(e,"-").concat(t.tag,"-").concat(s),r,void 0,n)}))}function Z(t,e,r){var i=g({},t.attrs);r!=null&&r.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=r.colorChannel1);var n=e.defIds;return!n||n.length===0||(t.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+e.idSuffix),Object.entries(i).forEach(function(a){var s=a[0],l=a[1];typeof l=="string"&&(i[s]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),i}function J(t,e){var r,i=e.defIds;return!i||i.length===0?t:t.tag==="defs"&&(!((r=t.children)===null||r===void 0)&&r.length)?g(g({},t),{children:t.children.map(function(n){return typeof n.attrs.id=="string"&&i&&i.indexOf(n.attrs.id)>-1?g(g({},n),{attrs:g(g({},n.attrs),{id:n.attrs.id+e.idSuffix})}):n})}):t}function Y(){return Math.random().toString(36).substring(2,8)}E.displayName="UniverIcon";var Q={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"}}]}]},N=p.forwardRef(function(t,e){return p.createElement(E,Object.assign({},t,{id:"search-single-16",ref:e,icon:Q}))});N.displayName="SearchSingle16";var X=Object.defineProperty,$=Object.getOwnPropertyDescriptor,U=(t,e,r,i)=>{for(var n=i>1?void 0:i?$(e,r):e,a=t.length-1,s;a>=0;a--)(s=t[a])&&(n=(i?s(e,r,n):s(n))||n);return i&&n&&X(e,r,n),n},M=(t,e)=>(r,i)=>e(r,i,t);class q extends o.Disposable{}const x=v.createIdentifier("univer.find-replace.service");let j=class extends o.Disposable{constructor(e,r,i,n){super();u(this,"_matchPositionFindModel",null);u(this,"_findModels",[]);u(this,"_matches",[]);u(this,"_positionModel",null);this._state=e,this._providers=r,this._logService=i,this._univerInstanceService=n,this._state.stateUpdates$.subscribe(a=>{typeof a.findString<"u"&&(a.findString?this.find():this._cancelFinding())})}async find(){this._cancelFinding();const e=Array.from(this._providers),r=this._findModels=(await Promise.all(e.map(a=>a.find({text:this._state.findString})))).flat(),i=r.map(a=>a.getMatches()).flat();if(this._matches=i,!i.length)return{results:[]};const n=this._moveToInitialMatch(r,i);return this._state.changeState({matchesCount:i.length,matchesPosition:n+1}),{results:i}}moveToNextMatch(){if(!this._positionModel)return;const e=this._findModels.length===1,r=this._positionModel.moveToNextMatch(e);if(r){const i=this._matches.findIndex(n=>n===r);this._state.changeState({matchesPosition:i+1})}else{const i=this._findModels.findIndex(l=>l===this._positionModel),n=this._findModels[(i+1)%this._findModels.length],a=n.moveToNextMatch(),s=this._matches.findIndex(l=>l===a);this._positionModel=n,this._state.changeState({matchesPosition:s+1})}}moveToPreviousMatch(){if(!this._positionModel)return;const e=this._findModels.length===1,r=this._positionModel.moveToPreviousMatch(e);if(r){const i=this._matches.findIndex(n=>n===r);this._state.changeState({matchesPosition:i+1})}else{const i=this._findModels.findIndex(l=>l===this._positionModel),n=this._findModels[(i-1+this._findModels.length)%this._findModels.length],a=n.moveToPreviousMatch(),s=this._matches.findIndex(l=>l===a);this._positionModel=n,this._state.changeState({matchesPosition:s+1})}}_moveToInitialMatch(e,r){var l;const i=(l=this._univerInstanceService.getFocusedUniverInstance())==null?void 0:l.getUnitId();if(!i)return-1;const n=e.find(m=>m.unitId===i);if(n){this._positionModel=n;const m=n.moveToNextMatch();return r.findIndex(I=>I===m)}this._positionModel=e[0];const a=this._positionModel.moveToNextMatch();return this._matches.findIndex(m=>m===a)}_cancelFinding(){this._providers.forEach(e=>e.cancel()),this._state.changeState({matchesCount:0,matchesPosition:0})}};j=U([M(2,o.ILogService),M(3,o.IUniverInstanceService)],j);function L(){return{revealed:!0,findString:"",replaceRevealed:!1,matchesPosition:0,matchesCount:0}}class ee{constructor(){u(this,"_stateUpdates$",new O.Subject);u(this,"stateUpdates$",this._stateUpdates$.asObservable());u(this,"_state$",new O.BehaviorSubject(L()));u(this,"state$",this._state$.asObservable());u(this,"_findString","");u(this,"_revealed",!1);u(this,"_replaceRevealed",!1);u(this,"_matchesPosition",0);u(this,"_matchesCount",0)}get state(){return this._state$.getValue()}get findString(){return this._findString}changeState(e){let r=!1;const i={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,i.findString=this._findString,r=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,i.revealed=e.revealed,r=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,i.replaceRevealed=e.replaceRevealed,r=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,i.matchesCount=e.matchesCount,r=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,i.matchesPosition=e.matchesPosition,r=!0),r&&(this._stateUpdates$.next(i),this._state$.next({findString:this._findString,revealed:this._revealed,replaceRevealed:this._replaceRevealed,matchesCount:this._matchesCount,matchesPosition:this._matchesPosition}))}}let b=class extends o.Disposable{constructor(e,r,i){super();u(this,"_providers",new Set);u(this,"_state",new ee);u(this,"_model");this._injector=e,this._univerInstanceService=r,this._logService=i}get stateUpdates$(){return this._state.stateUpdates$}get state$(){return this._state.state$}changeFindString(e){this._state.changeState({findString:e})}moveToNextMatch(){var e;this._model&&((e=this._model)==null||e.moveToNextMatch())}moveToPreviousMatch(){var e;this._model&&((e=this._model)==null||e.moveToPreviousMatch())}replace(){return!0}replaceAll(){return!0}revealReplace(){this._state.changeState({replaceRevealed:!0})}disposeModel(){var e;(e=this._model)==null||e.dispose(),this._model=null}start(){if(this._providers.size===0)return!1;this._model=this._injector.createInstance(j,this._state,this._providers);const e=L();return e.revealed=!0,this._state.changeState(e),!0}end(){return this._state.changeState({revealed:!1,replaceRevealed:!1}),!0}registerFindReplaceProvider(e){return this._providers.add(e),o.toDisposable(()=>this._providers.delete(e))}};b=U([M(0,v.Inject(v.Injector)),M(1,o.IUniverInstanceService),M(2,o.ILogService)],b);const F={id:"ui.operation.open-find-dialog",type:o.CommandType.OPERATION,handler:t=>(t.get(x).start(),!0)},w={id:"ui.operation.open-replace-dialog",type:o.CommandType.OPERATION,handler:t=>(t.get(x).start(),!0)},te={id:"ui.operation.toggle-replace-dialog",type:o.CommandType.OPERATION,handler:t=>(t.get(x),!0)},A={id:"ui.operation.close-find-replace-dialog",type:o.CommandType.OPERATION,handler:t=>!0},V={type:o.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:t=>(t.get(x).moveToNextMatch(),!0)},B={type:o.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:t=>(t.get(x).moveToPreviousMatch(),!0)},R="FIND_REPLACE_ACTIVATED";var K={exports:{}},y={};/**
|
|
1
|
+
(function(u,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/engine-render"),require("react"),require("@univerjs/design"),require("@wendellhu/redi/react-bindings")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/ui","rxjs","@univerjs/engine-render","react","@univerjs/design","@wendellhu/redi/react-bindings"],o):(u=typeof globalThis<"u"?globalThis:u||self,o(u.UniverFindReplace={},u.UniverCore,u["@wendellhu/redi"],u.UniverUi,u.rxjs,u.UniverEngineRender,u.React,u.UniverDesign,u["@wendellhu/redi/react-bindings"]))})(this,function(u,o,R,f,S,he,l,p,I){"use strict";var St=Object.defineProperty;var Ct=(u,o,R)=>o in u?St(u,o,{enumerable:!0,configurable:!0,writable:!0,value:R}):u[o]=R;var h=(u,o,R)=>(Ct(u,typeof o!="symbol"?o+"":o,R),R);var b=function(){return b=Object.assign||function(n){for(var e,i=1,t=arguments.length;i<t;i++){e=arguments[i];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(n[s]=e[s])}return n},b.apply(this,arguments)},ue=function(n,e){var i={};for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&e.indexOf(t)<0&&(i[t]=n[t]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,t=Object.getOwnPropertySymbols(n);s<t.length;s++)e.indexOf(t[s])<0&&Object.prototype.propertyIsEnumerable.call(n,t[s])&&(i[t[s]]=n[t[s]]);return i},K=l.forwardRef(function(n,e){var i=n.icon,t=n.id,s=n.className,a=n.extend,r=ue(n,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(t," ").concat(s||"").trim(),_=l.useRef("_".concat(_e()));return $(i,"".concat(t),{defIds:i.defIds,idSuffix:_.current},b({ref:e,className:c},r),a)});function $(n,e,i,t,s){return l.createElement(n.tag,b(b({key:e},fe(n,i,s)),t),(pe(n,i).children||[]).map(function(a,r){return $(a,"".concat(e,"-").concat(n.tag,"-").concat(r),i,void 0,s)}))}function fe(n,e,i){var t=b({},n.attrs);i!=null&&i.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=i.colorChannel1);var s=e.defIds;return!s||s.length===0||(n.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+e.idSuffix),Object.entries(t).forEach(function(a){var r=a[0],c=a[1];typeof c=="string"&&(t[r]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),t}function pe(n,e){var i,t=e.defIds;return!t||t.length===0?n:n.tag==="defs"&&(!((i=n.children)===null||i===void 0)&&i.length)?b(b({},n),{children:n.children.map(function(s){return typeof s.attrs.id=="string"&&t&&t.indexOf(s.attrs.id)>-1?b(b({},s),{attrs:b(b({},s.attrs),{id:s.attrs.id+e.idSuffix})}):s})}):n}function _e(){return Math.random().toString(36).substring(2,8)}K.displayName="UniverIcon";var ge={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"}}]}]},z=l.forwardRef(function(n,e){return l.createElement(K,Object.assign({},n,{id:"search-single-16",ref:e,icon:ge}))});z.displayName="SearchSingle16";const Y="FIND_REPLACE_INPUT_FOCUS",Z="FIND_REPLACE_DIALOG_FOCUS",J="FIND_REPLACE_REPLACE_REVEALED";var me=Object.defineProperty,ve=Object.getOwnPropertyDescriptor,Q=(n,e,i,t)=>{for(var s=t>1?void 0:t?ve(e,i):e,a=n.length-1,r;a>=0;a--)(r=n[a])&&(s=(t?r(e,i,s):r(s))||s);return t&&s&&me(e,i,s),s},T=(n,e)=>(i,t)=>e(i,t,n);class Se extends o.Disposable{}const y=R.createIdentifier("find-replace.service");function Ce(n){return typeof n.findString<"u"||typeof n.inputtingFindString<"u"||typeof n.findDirection<"u"||typeof n.matchesTheWholeCell<"u"||typeof n.caseSensitive<"u"||typeof n.findScope<"u"||typeof n.findBy<"u"}let U=class extends o.Disposable{constructor(e,i,t,s){super();h(this,"currentMatch$",new S.BehaviorSubject(null));h(this,"replaceables$",new S.BehaviorSubject([]));h(this,"_findModels",[]);h(this,"_matchingModel",null);h(this,"_matches",[]);h(this,"_currentSearchingDisposables",null);this._state=e,this._providers=i,this._univerInstanceService=t,this._logService=s,this.disposeWithMe(this._state.stateUpdates$.pipe(S.throttleTime(200,void 0,{leading:!0,trailing:!0})).subscribe(async a=>{const r=this._state.state;Ce(a)&&(r.findString!==""&&!r.replaceRevealed?(await this._startSearching(),this._state.changeState({findCompleted:!0})):a.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({...B(),revealed:!1})}async start(){if(!this._state.findString)return{results:[]};const e=await this._startSearching();return this._state.changeState({findCompleted:!0}),e}async _startSearching(){if(!this._state.findString)return{results:[]};const e=Array.from(this._providers),i=this._findModels=(await Promise.all(e.map(a=>a.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(i);const t=this._matches=i.map(a=>a.getMatches()).flat();if(this.replaceables$.next(t.filter(a=>a.replaceable)),!t.length)return this._state.changeState({matchesCount:0,matchesPosition:0}),{results:[]};const s=this._moveToInitialMatch(i,t);return this._state.changeState({matchesCount:t.length,matchesPosition:s+1}),{results:t}}_stopSearching(){var e;this._providers.forEach(i=>i.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})}_subscribeToModelsChanges(e){const i=this._currentSearchingDisposables=new o.DisposableCollection,t=S.combineLatest(e.map(s=>s.matchesUpdate$)).pipe(S.debounceTime(220)).subscribe(([...s])=>{const a=this._matches=s.flat();if(a.length){const r=this._moveToInitialMatch(this._findModels,a,!0);this._state.changeState({matchesCount:a.length,matchesPosition:r+1}),this.replaceables$.next(a.filter(c=>c.replaceable))}else this._state.changeState({matchesCount:0,matchesPosition:0}),this.replaceables$.next([])});e.forEach(s=>i.add(o.toDisposable(s.activelyChangingMatch$.subscribe(a=>{const r=this._matches.findIndex(c=>c===a);this._state.changeState({matchesPosition:r+1})})))),i.add(o.toDisposable(t))}async replace(){return this._matchingModel?this._matchingModel.replace(this._state.replaceString):!1}async replaceAll(){const e=await Promise.all(this._findModels.map(i=>i.replaceAll(this._state.replaceString))).then(i=>i.reduce((t,s)=>(t.success+=s.success,t.failure+=s.failure,t),{success:0,failure:0}));return e.failure===0&&this._stopSearching(),e}getCurrentMatch(){return this._state.matchesPosition>0?this._matches[this._state.matchesPosition-1]:null}moveToNextMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,i=this._matchingModel.moveToNextMatch({loop:e});if(i){const t=this._matches.findIndex(s=>s===i);this.currentMatch$.next(i),this._state.changeState({matchesPosition:t+1})}else{const t=this._findModels.findIndex(c=>c===this._matchingModel),s=this._findModels[(t+1)%this._findModels.length],a=s.moveToNextMatch(),r=this._matches.findIndex(c=>c===a);this.currentMatch$.next(a),this._matchingModel=s,this._state.changeState({matchesPosition:r+1})}}moveToPreviousMatch(){if(!this._matchingModel)return;const e=this._findModels.length===1,i=this._matchingModel.moveToPreviousMatch({loop:e});if(i){const t=this._matches.findIndex(s=>s===i);this.currentMatch$.next(i),this._state.changeState({matchesPosition:t+1})}else{const t=this._findModels.findIndex(c=>c===this._matchingModel),s=this._findModels[(t-1+this._findModels.length)%this._findModels.length],a=s.moveToPreviousMatch(),r=this._matches.findIndex(c=>c===a);this.currentMatch$.next(a),this._matchingModel=s,this._state.changeState({matchesPosition:r+1})}}_moveToInitialMatch(e,i,t=!1){var _;const s=(_=this._univerInstanceService.getFocusedUniverInstance())==null?void 0:_.getUnitId();if(!s)return-1;const a=e.find(m=>m.unitId===s);if(a){this._matchingModel=a;const m=a.moveToNextMatch({stayIfOnMatch:!0,noFocus:t}),C=i.findIndex(v=>v===m);return this.currentMatch$.next(m),C}this._matchingModel=e[0];const r=this._matchingModel.moveToNextMatch({noFocus:t}),c=this._matches.findIndex(m=>m===r);return this.currentMatch$.next(r),c}};U=Q([T(2,o.IUniverInstanceService),T(3,o.ILogService)],U);var O=(n=>(n.ROW="row",n.COLUMN="column",n))(O||{}),P=(n=>(n.VALUE="value",n.FORMULA="formula",n))(P||{}),E=(n=>(n.SUBUNIT="subunit",n.UNIT="unit",n))(E||{});function B(){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 Re{constructor(){h(this,"_stateUpdates$",new S.Subject);h(this,"stateUpdates$",this._stateUpdates$.asObservable());h(this,"_state$",new S.BehaviorSubject(B()));h(this,"state$",this._state$.asObservable());h(this,"_findString","");h(this,"_inputtingFindString","");h(this,"_replaceString","");h(this,"_revealed",!1);h(this,"_replaceRevealed",!1);h(this,"_matchesPosition",0);h(this,"_matchesCount",0);h(this,"_caseSensitive",!0);h(this,"_matchesTheWholeCell",!1);h(this,"_findDirection","row");h(this,"_findScope","subunit");h(this,"_findBy","value");h(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}changeState(e){let i=!1;const t={};typeof e.findString<"u"&&e.findString!==this._findString&&(this._findString=e.findString,t.findString=this._findString,i=!0),typeof e.revealed<"u"&&e.revealed!==this._revealed&&(this._revealed=e.revealed,t.revealed=e.revealed,i=!0),typeof e.replaceRevealed<"u"&&e.replaceRevealed!==this._replaceRevealed&&(this._replaceRevealed=e.replaceRevealed,t.replaceRevealed=e.replaceRevealed,i=!0),typeof e.replaceString<"u"&&e.replaceString!==this._replaceString&&(this._replaceString=e.replaceString,t.replaceString=e.replaceString,i=!0),typeof e.matchesCount<"u"&&e.matchesCount!==this._matchesCount&&(this._matchesCount=e.matchesCount,t.matchesCount=e.matchesCount,i=!0),typeof e.matchesPosition<"u"&&e.matchesPosition!==this._matchesPosition&&(this._matchesPosition=e.matchesPosition,t.matchesPosition=e.matchesPosition,i=!0),typeof e.findBy<"u"&&e.findBy!==this._findBy&&(this._findBy=e.findBy,t.findBy=e.findBy,i=!0),typeof e.findScope<"u"&&e.findScope!==this._findScope&&(this._findScope=e.findScope,t.findScope=e.findScope,i=!0),typeof e.findDirection<"u"&&e.findDirection!==this._findDirection&&(this._findDirection=e.findDirection,t.findDirection=e.findDirection,i=!0),typeof e.caseSensitive<"u"&&e.caseSensitive!==this._caseSensitive&&(this._caseSensitive=e.caseSensitive,t.caseSensitive=e.caseSensitive,i=!0),typeof e.matchesTheWholeCell<"u"&&e.matchesTheWholeCell!==this._matchesTheWholeCell&&(this._matchesTheWholeCell=e.matchesTheWholeCell,t.matchesTheWholeCell=e.matchesTheWholeCell,i=!0),typeof e.inputtingFindString<"u"&&e.inputtingFindString!==this._inputtingFindString&&(this._inputtingFindString=e.inputtingFindString,t.inputtingFindString=e.inputtingFindString,i=!0),typeof e.findCompleted<"u"&&e.findCompleted!==this._findCompleted&&(this._findCompleted=e.findCompleted,t.findCompleted=e.findCompleted,i=!0),i&&(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(t))}}let W=class extends o.Disposable{constructor(e,i){super();h(this,"_providers",new Set);h(this,"_state",new Re);h(this,"_model");h(this,"_currentMatch$",new S.BehaviorSubject(null));h(this,"currentMatch$",this._currentMatch$.asObservable());h(this,"_replaceables$",new S.BehaviorSubject([]));h(this,"replaceables$",this._replaceables$.asObservable());h(this,"_focusSignal$",new S.Subject);h(this,"focusSignal$",this._focusSignal$.asObservable());this._injector=e,this._contextService=i}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()}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")}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(U,this._state,this._providers),this._model.currentMatch$.subscribe(t=>this._currentMatch$.next(t)),this._model.replaceables$.subscribe(t=>this._replaceables$.next(t));const i=B();return e&&(i.replaceRevealed=!0),this._state.changeState(i),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),o.toDisposable(()=>this._providers.delete(e))}_toggleRevealReplace(e){this._contextService.setContextValue(J,e)}_toggleDisplayRawFormula(e){this._contextService.setContextValue(he.RENDER_RAW_FORMULA_KEY,e)}};W=Q([T(0,R.Inject(R.Injector)),T(1,o.IContextService)],W);const N={id:"ui.operation.open-find-dialog",type:o.CommandType.OPERATION,handler:n=>{const e=n.get(y);return e.revealed?e.focusFindInput():e.start(),!0}},k={id:"ui.operation.open-replace-dialog",type:o.CommandType.OPERATION,handler:n=>{const e=n.get(y);return e.revealed?e.replaceRevealed?e.focusFindInput():e.revealReplace():e.start(!0),!0}},X={type:o.CommandType.OPERATION,id:"ui.operation.go-to-next-match",handler:n=>(n.get(y).moveToNextMatch(),!0)},q={type:o.CommandType.OPERATION,id:"ui.operation.go-to-previous-match",handler:n=>(n.get(y).moveToPreviousMatch(),!0)};var ee={exports:{}},L={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var ie=p,ne=Symbol.for("react.element"),re=Symbol.for("react.fragment"),ae=Object.prototype.hasOwnProperty,oe=ie.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,se={key:!0,ref:!0,__self:!0,__source:!0};function k(t,e,r){var i,n={},a=null,s=null;r!==void 0&&(a=""+r),e.key!==void 0&&(a=""+e.key),e.ref!==void 0&&(s=e.ref);for(i in e)ae.call(e,i)&&!se.hasOwnProperty(i)&&(n[i]=e[i]);if(t&&t.defaultProps)for(i in e=t.defaultProps,e)n[i]===void 0&&(n[i]=e[i]);return{$$typeof:ne,type:t,key:a,ref:s,props:n,_owner:oe.current}}y.Fragment=re,y.jsx=k,y.jsxs=k,K.exports=y;var f=K.exports;const G={findReplaceExpandContainer:"univer-find-replace-expand-container"};function ce(){const t=T.useDependency(x),e=T.useDependency(o.LocaleService),r=T.useDependency(h.ILayoutService),[i,n]=p.useState(""),[a,s]=p.useState(""),l=p.useRef(null),m=_.useObservable(t.state$,!0),{matchesCount:C,matchesPosition:I}=m,Me=p.useCallback(()=>t.revealReplace(),[t]),ye=p.useCallback(d=>t.changeFindString(d),[t]),Pe=p.useCallback(d=>{n(d),ye(d)},[t]),W=p.useCallback(d=>{s(d)},[t]);p.useEffect(()=>{let d;return l.current&&(d=r.registerContainerElement(l.current)),()=>d==null?void 0:d.dispose()},[l.current]);function Oe(){return f.jsxs(p.Fragment,{children:[f.jsx(_.InputWithSlot,{autoFocus:!0,placeholder:e.t("univer.find-replace.dialog.find-placeholder"),slot:f.jsx(_.Pager,{loop:!0,value:I,total:C,onChange:d=>{I===C&&d===1?t.moveToNextMatch():I===1&&d===C||d<I?t.moveToPreviousMatch():t.moveToNextMatch()}}),value:i,onChange:d=>Pe(d)}),f.jsx("div",{className:G.findReplaceExpandContainer,children:f.jsx(_.Button,{type:"text",size:"small",onClick:Me,children:e.t("univer.find-replace.dialog.advanced-finding")})})]})}function Te(){return f.jsxs(p.Fragment,{children:[f.jsx(_.FormLayout,{label:e.t("univer.find-replace.dialog.find"),children:f.jsx(_.Input,{placeholder:e.t("univer.find-replace.dialog.find-placeholder"),autoFocus:!0,value:i,onChange:d=>W(d)})}),f.jsx(_.FormLayout,{label:e.t("univer.find-replace.dialog.replace"),children:f.jsx(_.Input,{placeholder:e.t("univer.find-replace.dialog.replace-placeholder"),value:a,onChange:d=>W(d)})}),f.jsx(_.FormLayout,{label:e.t("univer.find-replace.dialog.find-range"),children:f.jsx(_.Select,{value:"123",onChange:()=>{}})}),f.jsx(_.Button,{type:"primary",children:e.t("univer.find-replace.dialog.find")}),f.jsx(_.Button,{children:e.t("univer.find-replace.dialog.replace")}),f.jsx(_.Button,{children:e.t("univer.find-replace.dialog.replace-all")})]})}return f.jsx("div",{className:G.findReplaceDialogContainer,ref:l,children:m.replaceRevealed?Te():Oe()})}function le(t){return{id:F.id,icon:"SearchIcon",tooltip:"toolbar.find-replace",group:h.MenuGroup.TOOLBAR_OTHERS,type:h.MenuItemType.BUTTON,positions:[h.MenuPosition.TOOLBAR_START],hidden$:h.getMenuHiddenObservable(t,o.UniverInstanceType.SHEET)}}const de={id:F.id,description:"shortcut.find-replace.open-find-dialog",binding:h.KeyCode.F|h.MetaKeys.CTRL_COMMAND,group:"4_find-replace",preconditions(t){return!t.getContextValue(R)}},he={id:w.id,description:"shortcut.find-replace.open-replace-dialog",binding:h.KeyCode.H|h.MetaKeys.CTRL_COMMAND,group:"4_find-replace",preconditions(t){return!t.getContextValue(R)}},ue={id:A.id,description:"shortcut.find-replace.close-dialog",binding:h.KeyCode.ESC,group:"4_find-replace",priority:1e3,preconditions(t){return!!t.getContextValue(R)}},pe={id:V.id,description:"shortcut.find-replace.go-to-next-find-match",binding:h.KeyCode.ENTER,group:"4_find-replace",priority:1e3,preconditions(t){return!!t.getContextValue(R)}},fe={id:B.id,description:"shortcut.find-replace.go-to-previous-find-match",binding:h.KeyCode.ENTER|h.MetaKeys.SHIFT,group:"4_find-replace",priority:1e3,preconditions(t){return!!t.getContextValue(R)}};var ve=Object.defineProperty,_e=Object.getOwnPropertyDescriptor,ge=(t,e,r,i)=>{for(var n=i>1?void 0:i?_e(e,r):e,a=t.length-1,s;a>=0;a--)(s=t[a])&&(n=(i?s(e,r,n):s(n))||n);return i&&n&&ve(e,r,n),n},S=(t,e)=>(r,i)=>e(r,i,t);const H="DESKTOP_FIND_REPLACE_DIALOG";let P=class extends o.RxDisposable{constructor(t,e,r,i,n,a,s,l,m,C){super(),this._menuService=t,this._shortcutService=e,this._commandService=r,this._findReplaceService=i,this._dialogService=n,this._contextService=a,this._layoutService=s,this._localeService=l,this._componentManager=m,this._injector=C,this._initOperations(),this._initUI(),this._initShortcuts()}_initOperations(){[A,F,w,te,V,B].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initUI(){[le].forEach(t=>{this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(t)))}),this.disposeWithMe(this._componentManager.register("FindReplaceDialog",ce)),this.disposeWithMe(this._componentManager.register("SearchIcon",N)),this._findReplaceService.stateUpdates$.pipe(O.takeUntil(this.dispose$)).subscribe(t=>{t.revealed===!0?this._openPanel():t.revealed===!1&&this._closePanel()})}_initShortcuts(){[he,de,ue,fe,pe].forEach(t=>{this.disposeWithMe(this._shortcutService.registerShortcut(t))})}_openPanel(){this._dialogService.open({id:H,draggable:!0,width:350,title:{title:this._localeService.t("univer.find-replace.dialog.title")},children:{label:"FindReplaceDialog"},onClose:()=>this._closePanel()}),this._contextService.setContextValue(R,!0)}_closePanel(){this._dialogService.close(H),this._contextService.setContextValue(R,!1),this._layoutService.focus(),this._findReplaceService.end()}};P=ge([o.OnLifecycle(o.LifecycleStages.Rendered,P),S(0,h.IMenuService),S(1,h.IShortcutService),S(2,o.ICommandService),S(3,x),S(4,h.IDialogService),S(5,o.IContextService),S(6,h.ILayoutService),S(7,v.Inject(o.LocaleService)),S(8,v.Inject(h.ComponentManager)),S(9,v.Inject(v.Injector))],P);const me={univer:{"find-replace":{dialog:{title:"查找",find:"查找",replace:"替换","replace-all":"替换全部","find-range":"查找范围","find-placeholder":"输入查找内容","advanced-finding":"替换 / 高级查找","replace-placeholder":"输入替换内容"}}}};var Se=Object.defineProperty,xe=Object.getOwnPropertyDescriptor,Re=(t,e,r,i)=>{for(var n=i>1?void 0:i?xe(e,r):e,a=t.length-1,s;a>=0;a--)(s=t[a])&&(n=(i?s(e,r,n):s(n))||n);return i&&n&&Se(e,r,n),n},Ce=(t,e)=>(r,i)=>e(r,i,t);const Ie="FIND_REPLACE";c.UniverFindReplacePlugin=class extends o.Plugin{constructor(e,r){super(Ie),this._injector=e,this._localeService=r,this._localeService.load({zhCN:me})}onStarting(e){[[P],[x,{useClass:b}]].forEach(r=>{e.add(r)})}},c.UniverFindReplacePlugin=Re([Ce(1,v.Inject(o.LocaleService))],c.UniverFindReplacePlugin),c.FindModel=q,c.IFindReplaceService=x,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
|
9
|
+
*/var be=l,ye=Symbol.for("react.element"),Me=Symbol.for("react.fragment"),Ie=Object.prototype.hasOwnProperty,Fe=be.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,xe={key:!0,ref:!0,__self:!0,__source:!0};function te(n,e,i){var t,s={},a=null,r=null;i!==void 0&&(a=""+i),e.key!==void 0&&(a=""+e.key),e.ref!==void 0&&(r=e.ref);for(t in e)Ie.call(e,t)&&!xe.hasOwnProperty(t)&&(s[t]=e[t]);if(n&&n.defaultProps)for(t in e=n.defaultProps,e)s[t]===void 0&&(s[t]=e[t]);return{$$typeof:ye,type:n,key:a,ref:r,props:s,_owner:Fe.current}}L.Fragment=Me,L.jsx=te,L.jsxs=te,ee.exports=L;var d=ee.exports;const ne={id:"ui.command.replace-current-match",type:o.CommandType.COMMAND,handler:n=>n.get(y).replace()},De="CONFIRM_REPLACE_ALL",ie={id:"ui.command.replace-all-matches",type:o.CommandType.COMMAND,handler:async n=>{const e=n.get(f.IConfirmService),i=n.get(o.LocaleService),t=n.get(f.IMessageService);if(!await e.confirm({id:De,title:{title:i.t("find-replace.replace.confirm.title")},cancelText:i.t("button.cancel"),confirmText:i.t("button.confirm")}))return!1;const a=await n.get(y).replaceAll(),{success:r,failure:c}=a;return c>0?(r===0?t.show({type:p.MessageType.Error,content:i.t("find-replace.replace.all-failure")}):t.show({type:p.MessageType.Warning,content:i.t("find-replace.replace.partial-success",`${r}`,`${c}`)}),!1):(t.show({type:p.MessageType.Success,content:i.t("find-replace.replace.all-success",`${r}`)}),!0)}};function se(n){const{findCompleted:e,localeService:i,matchesCount:t,matchesPosition:s,findString:a,findReplaceService:r,onChange:c,..._}=n,C=e&&t===0?i.t("find-replace.dialog.no-result"):t===0?" ":void 0;return d.jsx(p.InputWithSlot,{autoFocus:!0,placeholder:i.t("find-replace.dialog.find-placeholder"),slot:d.jsx(p.Pager,{loop:!0,text:C,value:s,total:t,onChange:v=>{s===t&&v===1?r.moveToNextMatch():s===1&&v===t||v<s?r.moveToPreviousMatch():r.moveToNextMatch()}}),value:a,onChange:v=>c==null?void 0:c(v),..._})}const j={findReplaceDialogContainer:"univer-find-replace-dialog-container",findReplaceExpandContainer:"univer-find-replace-expand-container",buttonText:"univer-button-text",findReplaceButtonsGroup:"univer-find-replace-buttons-group",findReplaceButtonsGroupRight:"univer-find-replace-buttons-group-right"};function ae(n,e){const i=l.useCallback(()=>{var s;(s=document.querySelector(".univer-find-input input"))==null||s.focus()},[]),t=l.useCallback(()=>{const s=document.querySelectorAll(".univer-find-replace-dialog-container .univer-select-selection-search-input");return Array.from(s).some(a=>a===document.activeElement)},[]);return l.useImperativeHandle(e,()=>({focus:i,selectHasFocus:t})),l.useEffect(()=>{const s=n.focusSignal$.subscribe(()=>i());return()=>s.unsubscribe()},[n,i]),{focus:i,selectHasFocus:t}}const Te=l.forwardRef(function(e,i){const t=I.useDependency(o.LocaleService),s=I.useDependency(y),a=I.useDependency(o.ICommandService),r=f.useObservable(s.state$,void 0,!0),{findCompleted:c,findString:_,matchesCount:m,matchesPosition:C}=r,v=l.useCallback(()=>{a.executeCommand(k.id)},[a]),x=l.useCallback(F=>s.changeFindString(F),[s]);return ae(s,i),d.jsxs(l.Fragment,{children:[d.jsx(se,{findCompleted:c,className:"univer-find-input",matchesCount:m,matchesPosition:C,findReplaceService:s,localeService:t,findString:_,onChange:x}),d.jsx("div",{className:j.findReplaceExpandContainer,children:d.jsx(p.Button,{type:"text",size:"small",onClick:v,children:t.t("find-replace.dialog.advanced-finding")})})]})}),Oe=l.forwardRef(function(e,i){const t=I.useDependency(y),s=I.useDependency(o.LocaleService),a=I.useDependency(o.ICommandService),r=I.useDependency(f.IMessageService),c=f.useObservable(t.currentMatch$,void 0,!0),_=f.useObservable(t.replaceables$,void 0,!0),m=f.useObservable(t.state$,void 0,!0),{matchesCount:C,matchesPosition:v,findString:x,inputtingFindString:F,replaceString:et,caseSensitive:le,matchesTheWholeCell:de,findDirection:tt,findScope:nt,findBy:it,findCompleted:H}=m,st=F.length===0,at=C===0||!(c!=null&&c.replaceable),rt=_.length===0,ot=l.useCallback(g=>t.changeInputtingFindString(g),[t]),ct=l.useCallback(g=>t.changeReplaceString(g),[t]),{focus:lt}=ae(t,i),dt=l.useCallback(()=>{x===F?t.moveToNextMatch():(t.changeFindString(F),t.find())},[x,F,t]),ht=l.useCallback(()=>a.executeCommand(ne.id),[a]),ut=l.useCallback(async()=>{await a.executeCommand(ie.id),lt()},[a]),ft=l.useCallback(g=>{t.changeFindDirection(g)},[t]),pt=l.useCallback(g=>{t.changeFindScope(g)},[t]),_t=l.useCallback(g=>{t.changeFindBy(g)},[t]),gt=Ee(s),mt=Ne(s),vt=Le(s);return l.useEffect(()=>{const g=H&&C===0;let A=null;return g&&(A=r.show({content:s.t("find-replace.dialog.no-match"),type:p.MessageType.Warning,delay:5e3})),()=>A==null?void 0:A.dispose()},[H,C,r,s]),d.jsxs(l.Fragment,{children:[d.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find"),children:d.jsx(se,{findCompleted:H,className:"univer-find-input",matchesCount:C,matchesPosition:v,findReplaceService:t,localeService:s,findString:F,onChange:ot})}),d.jsx(p.FormLayout,{label:s.t("find-replace.dialog.replace"),children:d.jsx(p.Input,{placeholder:s.t("find-replace.dialog.replace-placeholder"),value:et,onChange:g=>ct(g)})}),d.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find-direction.title"),children:d.jsx(p.Select,{value:tt,options:mt,onChange:ft})}),d.jsx(p.FormDualColumnLayout,{children:d.jsxs(l.Fragment,{children:[d.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find-scope.title"),children:d.jsx(p.Select,{value:nt,options:gt,onChange:pt})}),d.jsx(p.FormLayout,{label:s.t("find-replace.dialog.find-by.title"),children:d.jsx(p.Select,{value:it,options:vt,onChange:_t})})]})}),d.jsx(p.FormDualColumnLayout,{children:d.jsxs(l.Fragment,{children:[d.jsx(p.FormLayout,{children:d.jsx(p.Checkbox,{checked:le,value:le,onChange:g=>{t.changeCaseSensitive(g)},children:s.t("find-replace.dialog.case-sensitive")})}),d.jsx(p.FormLayout,{children:d.jsx(p.Checkbox,{checked:de,value:de,onChange:g=>{t.changeMatchesTheWholeCell(g)},children:s.t("find-replace.dialog.match-the-whole-cell")})})]})}),d.jsxs("div",{className:j.findReplaceButtonsGroup,children:[d.jsx(p.Button,{type:"primary",onClick:dt,disabled:st,children:s.t("find-replace.dialog.find")}),d.jsxs("span",{className:j.findReplaceButtonsGroupRight,children:[d.jsx(p.Button,{disabled:at,onClick:ht,children:s.t("find-replace.dialog.replace")}),d.jsx(p.Button,{disabled:rt,onClick:ut,children:s.t("find-replace.dialog.replace-all")})]})]})]})});function Pe(){const n=I.useDependency(y),e=I.useDependency(f.ILayoutService),i=I.useDependency(o.IContextService),t=f.useObservable(n.state$,void 0,!0),s=l.useRef(null);l.useEffect(()=>{let _;return s.current&&(_=e.registerContainerElement(s.current)),()=>_==null?void 0:_.dispose()},[e]);const a=l.useRef(null),r=l.useCallback(_=>i.setContextValue(Z,_),[i]),c=l.useCallback(_=>i.setContextValue(Y,_),[i]);return l.useEffect(()=>{var m;const _=S.fromEvent(document,"focusin").subscribe(C=>{var v;C.target&&((v=s.current)!=null&&v.contains(C.target))?r(!0):r(!1),!a.current||!a.current.selectHasFocus()?c(!0):c(!1)});return(m=a.current)==null||m.focus(),r(!0),c(!0),()=>{_.unsubscribe(),r(!1)}},[r,c]),d.jsx("div",{className:j.findReplaceDialogContainer,ref:s,children:t.replaceRevealed?d.jsx(Oe,{ref:a}):d.jsx(Te,{ref:a})})}function Ee(n){const e=n.getCurrentLocale();return l.useMemo(()=>[{label:n.t("find-replace.dialog.find-scope.current-sheet"),value:E.SUBUNIT},{label:n.t("find-replace.dialog.find-scope.workbook"),value:E.UNIT}],[e])}function Ne(n){const e=n.getCurrentLocale();return l.useMemo(()=>[{label:n.t("find-replace.dialog.find-direction.row"),value:O.ROW},{label:n.t("find-replace.dialog.find-direction.column"),value:O.COLUMN}],[e])}function Le(n){const e=n.getCurrentLocale();return l.useMemo(()=>[{label:n.t("find-replace.dialog.find-by.value"),value:P.VALUE},{label:n.t("find-replace.dialog.find-by.formula"),value:P.FORMULA}],[e])}function D(n){return n.getContextValue(Z)}function je(n){return n.getContextValue(J)}function re(n){return n.getContextValue(Y)}const w="7_find-replace-shortcuts";function G(n){return n.getContextValue(o.FOCUSING_SHEET)}function V(n){return!n.getContextValue(o.EDITOR_ACTIVATED)}const we={id:N.id,description:"find-replace.shortcut.open-find-dialog",binding:f.KeyCode.F|f.MetaKeys.CTRL_COMMAND,group:w,preconditions(n){return!D(n)&&G(n)&&V(n)}},Ae={id:N.id,description:"find-replace.shortcut.open-find-dialog",binding:f.KeyCode.F|f.MetaKeys.CTRL_COMMAND,mac:f.KeyCode.F|f.MetaKeys.MAC_CTRL,preconditions(n){return!D(n)&&G(n)&&V(n)}},Ue={id:k.id,description:"find-replace.shortcut.open-replace-dialog",binding:f.KeyCode.H|f.MetaKeys.CTRL_COMMAND,mac:f.KeyCode.H|f.MetaKeys.MAC_CTRL,group:w,preconditions(n){return G(n)&&V(n)&&(!D(n)||!je(n))}},Be={id:X.id,description:"find-replace.shortcut.go-to-next-match",binding:f.KeyCode.ENTER,group:w,priority:1e3,preconditions(n){return re(n)&&D(n)}},We={id:q.id,description:"find-replace.shortcut.go-to-previous-match",binding:f.KeyCode.ENTER|f.MetaKeys.SHIFT,group:w,priority:1e3,preconditions(n){return re(n)&&D(n)}};function ke(n){const e=n.get(o.IContextService);return{id:N.id,icon:"SearchIcon",tooltip:"find-replace.toolbar",group:f.MenuGroup.TOOLBAR_OTHERS,type:f.MenuItemType.BUTTON,positions:[f.MenuPosition.TOOLBAR_START],hidden$:f.getMenuHiddenObservable(n,o.UniverInstanceType.SHEET),disabled$:S.combineLatest([e.subscribeContextValue$(o.EDITOR_ACTIVATED),e.subscribeContextValue$(o.FOCUSING_SHEET)]).pipe(S.map(([i,t])=>i||!t))}}var Ge=Object.defineProperty,Ve=Object.getOwnPropertyDescriptor,He=(n,e,i,t)=>{for(var s=t>1?void 0:t?Ve(e,i):e,a=n.length-1,r;a>=0;a--)(r=n[a])&&(s=(t?r(e,i,s):r(s))||s);return t&&s&&Ge(e,i,s),s},M=(n,e)=>(i,t)=>e(i,t,n);const oe="DESKTOP_FIND_REPLACE_DIALOG",ce=350,Ke=20,$e=0;u.FindReplaceController=class extends o.RxDisposable{constructor(e,i,t,s,a,r,c,_,m,C,v,x){super(),this._univerInstanceService=e,this._menuService=i,this._shortcutService=t,this._commandService=s,this._findReplaceService=a,this._logService=r,this._dialogService=c,this._contextService=_,this._layoutService=m,this._localeService=C,this._componentManager=v,this._injector=x,this._initCommands(),this._initUI(),this._initShortcuts()}_initCommands(){[N,k,X,q,ie,ne].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initShortcuts(){[Ue,we,Ae,We,Be].forEach(e=>this.disposeWithMe(this._shortcutService.registerShortcut(e)))}_initUI(){this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(ke))),this.disposeWithMe(this._componentManager.register("FindReplaceDialog",Pe)),this.disposeWithMe(this._componentManager.register("SearchIcon",z)),this._findReplaceService.stateUpdates$.pipe(S.takeUntil(this.dispose$)).subscribe(e=>{e.revealed===!0&&this._openPanel()}),this.disposeWithMe(this._univerInstanceService.focused$.pipe(S.takeUntil(this.dispose$)).subscribe(e=>{(!e||!this._univerInstanceService.getUniverSheetInstance(e))&&this.closePanel()}))}_openPanel(){this._dialogService.open({id:oe,draggable:!0,width:ce,title:{title:this._localeService.t("find-replace.dialog.title")},children:{label:"FindReplaceDialog"},destroyOnClose:!0,defaultPosition:ze(),onClose:()=>this.closePanel()})}closePanel(){this._dialogService.close(oe),this._findReplaceService.terminate(),queueMicrotask(()=>this._layoutService.focus())}},u.FindReplaceController=He([o.OnLifecycle(o.LifecycleStages.Rendered,u.FindReplaceController),M(0,o.IUniverInstanceService),M(1,f.IMenuService),M(2,f.IShortcutService),M(3,o.ICommandService),M(4,y),M(5,o.ILogService),M(6,f.IDialogService),M(7,o.IContextService),M(8,f.ILayoutService),M(9,R.Inject(o.LocaleService)),M(10,R.Inject(f.ComponentManager)),M(11,R.Inject(R.Injector))],u.FindReplaceController);function ze(){const{innerWidth:n}=window;return{x:n-ce-Ke,y:$e}}const Ye={"find-replace":{toolbar:"查找替换",shortcut:{"open-find-dialog":"打开查找对话框","open-replace-dialog":"打开替换对话框","close-dialog":"关闭查找替换对话框","go-to-next-match":"下一个匹配项","go-to-previous-match":"下一个匹配项"},dialog:{title:"查找",find:"查找",replace:"替换","replace-all":"替换全部","find-placeholder":"输入查找内容","advanced-finding":"替换 / 高级查找","replace-placeholder":"输入替换内容","case-sensitive":"匹配大小写","match-the-whole-cell":"匹配整个单元格","find-scope":{title:"查找范围","current-sheet":"当前子表",workbook:"整个工作簿"},"find-direction":{title:"查找顺序",column:"按列查找",row:"按行查找"},"find-by":{title:"查找方式",formula:"查找公式",value:"查找值"},"no-match":"已完成搜索,但是未找到任何匹配项","no-result":"无结果"},replace:{"all-success":"已全部替换 {0} 个匹配项","all-failure":"替换失败",confirm:{title:"确定要替换所有的匹配项吗?"}}},"find-replace-shortcuts":"查找替换"};var Ze=Object.defineProperty,Je=Object.getOwnPropertyDescriptor,Qe=(n,e,i,t)=>{for(var s=t>1?void 0:t?Je(e,i):e,a=n.length-1,r;a>=0;a--)(r=n[a])&&(s=(t?r(e,i,s):r(s))||s);return t&&s&&Ze(e,i,s),s},Xe=(n,e)=>(i,t)=>e(i,t,n);const qe="FIND_REPLACE";u.UniverFindReplacePlugin=class extends o.Plugin{constructor(e,i){super(qe),this._injector=e,this._localeService=i,this._localeService.load({zhCN:Ye})}onStarting(e){[[u.FindReplaceController],[y,{useClass:W}]].forEach(i=>{e.add(i)})}},u.UniverFindReplacePlugin=Qe([Xe(1,R.Inject(o.LocaleService))],u.UniverFindReplacePlugin),u.FindBy=P,u.FindDirection=O,u.FindModel=Se,u.FindScope=E,u.IFindReplaceService=y,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|