@univerjs/find-replace 1.0.0-insiders.20260809-70eefdd → 1.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +0 -1
  3. package/lib/cjs/index.js +521 -8
  4. package/lib/cjs/locale/ar-SA.js +7 -1
  5. package/lib/cjs/locale/ca-ES.js +7 -1
  6. package/lib/cjs/locale/de-DE.js +7 -1
  7. package/lib/cjs/locale/en-US.js +7 -1
  8. package/lib/cjs/locale/es-ES.js +7 -1
  9. package/lib/cjs/locale/fa-IR.js +7 -1
  10. package/lib/cjs/locale/fr-FR.js +7 -1
  11. package/lib/cjs/locale/id-ID.js +7 -1
  12. package/lib/cjs/locale/it-IT.js +7 -1
  13. package/lib/cjs/locale/ja-JP.js +7 -1
  14. package/lib/cjs/locale/ko-KR.js +7 -1
  15. package/lib/cjs/locale/pl-PL.js +7 -1
  16. package/lib/cjs/locale/pt-BR.js +7 -1
  17. package/lib/cjs/locale/ru-RU.js +7 -1
  18. package/lib/cjs/locale/sk-SK.js +7 -1
  19. package/lib/cjs/locale/vi-VN.js +7 -1
  20. package/lib/cjs/locale/zh-CN.js +7 -1
  21. package/lib/cjs/locale/zh-HK.js +7 -1
  22. package/lib/cjs/locale/zh-TW.js +7 -1
  23. package/lib/es/index.js +520 -14
  24. package/lib/es/locale/ar-SA.js +7 -1
  25. package/lib/es/locale/ca-ES.js +7 -1
  26. package/lib/es/locale/de-DE.js +7 -1
  27. package/lib/es/locale/en-US.js +7 -1
  28. package/lib/es/locale/es-ES.js +7 -1
  29. package/lib/es/locale/fa-IR.js +7 -1
  30. package/lib/es/locale/fr-FR.js +7 -1
  31. package/lib/es/locale/id-ID.js +7 -1
  32. package/lib/es/locale/it-IT.js +7 -1
  33. package/lib/es/locale/ja-JP.js +7 -1
  34. package/lib/es/locale/ko-KR.js +7 -1
  35. package/lib/es/locale/pl-PL.js +7 -1
  36. package/lib/es/locale/pt-BR.js +7 -1
  37. package/lib/es/locale/ru-RU.js +7 -1
  38. package/lib/es/locale/sk-SK.js +7 -1
  39. package/lib/es/locale/vi-VN.js +7 -1
  40. package/lib/es/locale/zh-CN.js +7 -1
  41. package/lib/es/locale/zh-HK.js +7 -1
  42. package/lib/es/locale/zh-TW.js +7 -1
  43. package/lib/index.css +204 -0
  44. package/lib/index.js +520 -14
  45. package/lib/locale/ar-SA.js +7 -1
  46. package/lib/locale/ca-ES.js +7 -1
  47. package/lib/locale/de-DE.js +7 -1
  48. package/lib/locale/en-US.js +7 -1
  49. package/lib/locale/es-ES.js +7 -1
  50. package/lib/locale/fa-IR.js +7 -1
  51. package/lib/locale/fr-FR.js +7 -1
  52. package/lib/locale/id-ID.js +7 -1
  53. package/lib/locale/it-IT.js +7 -1
  54. package/lib/locale/ja-JP.js +7 -1
  55. package/lib/locale/ko-KR.js +7 -1
  56. package/lib/locale/pl-PL.js +7 -1
  57. package/lib/locale/pt-BR.js +7 -1
  58. package/lib/locale/ru-RU.js +7 -1
  59. package/lib/locale/sk-SK.js +7 -1
  60. package/lib/locale/vi-VN.js +7 -1
  61. package/lib/locale/zh-CN.js +7 -1
  62. package/lib/locale/zh-HK.js +7 -1
  63. package/lib/locale/zh-TW.js +7 -1
  64. package/lib/types/commands/operations/find-replace.operation.d.ts +1 -0
  65. package/lib/types/const.d.ts +17 -0
  66. package/lib/types/controllers/find-replace.controller.d.ts +1 -0
  67. package/lib/types/controllers/mobile/components.controller.d.ts +20 -0
  68. package/lib/types/controllers/mobile/find-replace.controller.d.ts +21 -0
  69. package/lib/types/index.d.ts +2 -1
  70. package/lib/types/locale/en-US.d.ts +7 -1
  71. package/lib/types/menu/mobile-schema.d.ts +17 -0
  72. package/lib/types/mobile-plugin.d.ts +28 -0
  73. package/lib/types/services/find-replace.service.d.ts +2 -0
  74. package/lib/types/views/mobile/MobileFindReplaceBar.d.ts +16 -0
  75. package/lib/types/views/mobile/MobileFindReplaceSettings.d.ts +16 -0
  76. package/lib/umd/index.js +1 -1
  77. package/lib/umd/locale/ar-SA.js +1 -1
  78. package/lib/umd/locale/ca-ES.js +1 -1
  79. package/lib/umd/locale/de-DE.js +1 -1
  80. package/lib/umd/locale/en-US.js +1 -1
  81. package/lib/umd/locale/es-ES.js +1 -1
  82. package/lib/umd/locale/fa-IR.js +1 -1
  83. package/lib/umd/locale/fr-FR.js +1 -1
  84. package/lib/umd/locale/id-ID.js +1 -1
  85. package/lib/umd/locale/it-IT.js +1 -1
  86. package/lib/umd/locale/ja-JP.js +1 -1
  87. package/lib/umd/locale/ko-KR.js +1 -1
  88. package/lib/umd/locale/pl-PL.js +1 -1
  89. package/lib/umd/locale/pt-BR.js +1 -1
  90. package/lib/umd/locale/ru-RU.js +1 -1
  91. package/lib/umd/locale/sk-SK.js +1 -1
  92. package/lib/umd/locale/vi-VN.js +1 -1
  93. package/lib/umd/locale/zh-CN.js +1 -1
  94. package/lib/umd/locale/zh-HK.js +1 -1
  95. package/lib/umd/locale/zh-TW.js +1 -1
  96. package/package.json +9 -9
package/lib/es/index.js CHANGED
@@ -1,11 +1,11 @@
1
- import { CommandType, Disposable, DisposableCollection, EDITOR_ACTIVATED, FOCUSING_SHEET, ICommandService, IConfigService, IConfirmService, IContextService, IUniverInstanceService, Inject, Injector, LocaleService, Plugin, RxDisposable, UniverInstanceType, createIdentifier, merge, toDisposable } from "@univerjs/core";
2
- import { Button, Checkbox, FormDualColumnLayout, FormLayout, Input, MessageType, Pager, Select } from "@univerjs/design";
3
- import { ComponentManager, IDialogService, ILayoutService, IMenuManagerService, IMessageService, IShortcutService, IconManager, KeyCode, MenuItemType, MetaKeys, RibbonDataGroup, getMenuHiddenObservable, useDebounceFn, useDependency, useObservable } from "@univerjs/ui";
1
+ import { CommandType, DependentOn, Disposable, DisposableCollection, EDITOR_ACTIVATED, FOCUSING_SHEET, ICommandService, IConfigService, IConfirmService, IContextService, IUniverInstanceService, Inject, Injector, LocaleService, Plugin, RxDisposable, UniverInstanceType, createIdentifier, merge, toDisposable } from "@univerjs/core";
2
+ import { Button, Checkbox, FormDualColumnLayout, FormLayout, Input, MessageType, MobileSelect, Pager, Select, clsx, resetButtonClassName } from "@univerjs/design";
3
+ import { BuiltInUIPart, ComponentManager, IDialogService, ILayoutService, IMenuManagerService, IMessageService, IShortcutService, IUIPartsService, IconManager, KeyCode, MenuItemType, MetaKeys, MobileKeyboardInsetContext, RibbonDataGroup, UniverMobileUIPlugin, connectInjector, getMenuHiddenObservable, useDebounceFn, useDependency, useObservable } from "@univerjs/ui";
4
4
  import { RENDER_RAW_FORMULA_KEY } from "@univerjs/engine-render";
5
- import { BehaviorSubject, Subject, combineLatest, debounceTime, fromEvent, map, takeUntil, throttleTime } from "rxjs";
6
- import { SearchIcon } from "@univerjs/icons";
7
- import { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from "react";
5
+ import { BehaviorSubject, Subject, combineLatest, debounceTime, fromEvent, map, startWith, takeUntil, throttleTime } from "rxjs";
6
+ import { ArrowDownIcon, ArrowUpIcon, CloseIcon, ConfigureTabIcon, SearchIcon } from "@univerjs/icons";
8
7
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
+ import { forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useRef, useState } from "react";
9
9
 
10
10
  //#region src/services/context-keys.ts
11
11
  /**
@@ -649,6 +649,13 @@ let FindReplaceService = class FindReplaceService extends Disposable {
649
649
  });
650
650
  this._toggleRevealReplace(true);
651
651
  }
652
+ hideReplace() {
653
+ this._state.changeState({
654
+ replaceRevealed: false,
655
+ findString: this._state.inputtingFindString
656
+ });
657
+ this._toggleRevealReplace(false);
658
+ }
652
659
  focusSelection() {
653
660
  var _this$_model2;
654
661
  (_this$_model2 = this._model) === null || _this$_model2 === void 0 || _this$_model2.focusSelection();
@@ -774,6 +781,14 @@ const OpenReplaceDialogOperation = {
774
781
  return true;
775
782
  }
776
783
  };
784
+ const CloseFindDialogOperation = {
785
+ id: "ui.operation.close-find-dialog",
786
+ type: CommandType.OPERATION,
787
+ handler: (accessor) => {
788
+ accessor.get(IFindReplaceService).terminate();
789
+ return true;
790
+ }
791
+ };
777
792
  const GoToNextMatchOperation = {
778
793
  type: CommandType.OPERATION,
779
794
  id: "ui.operation.go-to-next-match",
@@ -809,7 +824,11 @@ function FindReplaceMenuItemFactory(accessor) {
809
824
  tooltip: "find-replace.toolbar",
810
825
  type: MenuItemType.BUTTON,
811
826
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
812
- disabled$: combineLatest([contextService.subscribeContextValue$(EDITOR_ACTIVATED), contextService.subscribeContextValue$(FOCUSING_SHEET)]).pipe(map(([editorActivated, focusingSheet]) => editorActivated || !focusingSheet))
827
+ disabled$: combineLatest([
828
+ contextService.subscribeContextValue$(EDITOR_ACTIVATED),
829
+ contextService.subscribeContextValue$(FOCUSING_SHEET),
830
+ contextService.subscribeContextValue$(FIND_REPLACE_AVAILABLE).pipe(startWith(contextService.getContextValue(FIND_REPLACE_AVAILABLE)))
831
+ ]).pipe(map(([editorActivated, focusingSheet, available]) => editorActivated || !focusingSheet || !available))
813
832
  };
814
833
  }
815
834
 
@@ -938,6 +957,7 @@ let FindReplaceController = class FindReplaceController extends RxDisposable {
938
957
  [
939
958
  OpenFindDialogOperation,
940
959
  OpenReplaceDialogOperation,
960
+ CloseFindDialogOperation,
941
961
  GoToNextMatchOperation,
942
962
  GoToPreviousMatchOperation,
943
963
  ReplaceAllMatchesCommand,
@@ -961,6 +981,7 @@ let FindReplaceController = class FindReplaceController extends RxDisposable {
961
981
  this._menuManagerService.mergeMenu(menuSchema);
962
982
  this._findReplaceService.stateUpdates$.pipe(takeUntil(this.dispose$)).subscribe((newState) => {
963
983
  if (newState.revealed === true) this._openPanel();
984
+ else if (newState.revealed === false) this._closePanel(false);
964
985
  });
965
986
  }
966
987
  _openPanel() {
@@ -983,11 +1004,14 @@ let FindReplaceController = class FindReplaceController extends RxDisposable {
983
1004
  }));
984
1005
  }
985
1006
  closePanel() {
1007
+ this._closePanel(true);
1008
+ }
1009
+ _closePanel(terminateSession) {
986
1010
  if (!this._closingListenerDisposable) return;
987
1011
  this._closingListenerDisposable.dispose();
988
1012
  this._closingListenerDisposable = null;
989
1013
  this._dialogService.close(FIND_REPLACE_DIALOG_ID);
990
- this._findReplaceService.terminate();
1014
+ if (terminateSession) this._findReplaceService.terminate();
991
1015
  queueMicrotask(() => this._layoutService.focus());
992
1016
  }
993
1017
  };
@@ -1012,7 +1036,7 @@ function getFindReplaceDialogDefaultPosition(direction) {
1012
1036
  //#endregion
1013
1037
  //#region package.json
1014
1038
  var name = "@univerjs/find-replace";
1015
- var version = "1.0.0-insiders.20260809-70eefdd";
1039
+ var version = "1.0.0-rc.0";
1016
1040
 
1017
1041
  //#endregion
1018
1042
  //#region src/config/config.ts
@@ -1020,6 +1044,476 @@ const FIND_REPLACE_PLUGIN_CONFIG_KEY = "find-replace.config";
1020
1044
  const configSymbol = Symbol(FIND_REPLACE_PLUGIN_CONFIG_KEY);
1021
1045
  const defaultPluginConfig = {};
1022
1046
 
1047
+ //#endregion
1048
+ //#region src/const.ts
1049
+ /**
1050
+ * Copyright 2023-present DreamNum Co., Ltd.
1051
+ *
1052
+ * Licensed under the Apache License, Version 2.0 (the "License");
1053
+ * you may not use this file except in compliance with the License.
1054
+ * You may obtain a copy of the License at
1055
+ *
1056
+ * http://www.apache.org/licenses/LICENSE-2.0
1057
+ *
1058
+ * Unless required by applicable law or agreed to in writing, software
1059
+ * distributed under the License is distributed on an "AS IS" BASIS,
1060
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1061
+ * See the License for the specific language governing permissions and
1062
+ * limitations under the License.
1063
+ */
1064
+ const MOBILE_FIND_REPLACE_SETTINGS_COMPONENT = "MobileFindReplaceSettings";
1065
+ const MOBILE_FIND_REPLACE_SETTINGS_DIALOG_ID = "MOBILE_FIND_REPLACE_SETTINGS_DIALOG";
1066
+
1067
+ //#endregion
1068
+ //#region src/views/mobile/MobileFindReplaceSettings.tsx
1069
+ const FIND_SCOPE_OPTIONS$1 = [{
1070
+ label: "find-replace.dialog.find-scope.current-sheet",
1071
+ value: "subunit"
1072
+ }, {
1073
+ label: "find-replace.dialog.find-scope.workbook",
1074
+ value: "unit"
1075
+ }];
1076
+ const FIND_DIRECTION_OPTIONS$1 = [{
1077
+ label: "find-replace.dialog.find-direction.row",
1078
+ value: "row"
1079
+ }, {
1080
+ label: "find-replace.dialog.find-direction.column",
1081
+ value: "column"
1082
+ }];
1083
+ const FIND_BY_OPTIONS$1 = [{
1084
+ label: "find-replace.dialog.find-by.value",
1085
+ value: "value"
1086
+ }, {
1087
+ label: "find-replace.dialog.find-by.formula",
1088
+ value: "formula"
1089
+ }];
1090
+ function MobileFindReplaceSettings() {
1091
+ const findReplaceService = useDependency(IFindReplaceService);
1092
+ const localeService = useDependency(LocaleService);
1093
+ const state = useObservable(findReplaceService.state$, void 0, true);
1094
+ const capabilities = useObservable(findReplaceService.providerCapabilities$, null, true);
1095
+ function refreshSearch(force = false) {
1096
+ if (state.findString && (force || state.replaceRevealed)) findReplaceService.find();
1097
+ }
1098
+ const findScopeOptions = FIND_SCOPE_OPTIONS$1.map((option) => ({
1099
+ ...option,
1100
+ label: localeService.t(option.label)
1101
+ }));
1102
+ const findDirectionOptions = FIND_DIRECTION_OPTIONS$1.map((option) => ({
1103
+ ...option,
1104
+ label: localeService.t(option.label)
1105
+ }));
1106
+ const findByOptions = FIND_BY_OPTIONS$1.map((option) => ({
1107
+ ...option,
1108
+ label: localeService.t(option.label)
1109
+ }));
1110
+ return /* @__PURE__ */ jsxs("div", {
1111
+ className: "univer-grid univer-gap-2",
1112
+ "data-u-comp": "mobile-find-replace-settings",
1113
+ children: [
1114
+ /* @__PURE__ */ jsx(SettingCheckbox, {
1115
+ checked: state.replaceRevealed,
1116
+ label: localeService.t("find-replace.dialog.replace"),
1117
+ onChange: (checked) => {
1118
+ if (checked) findReplaceService.revealReplace();
1119
+ else findReplaceService.hideReplace();
1120
+ refreshSearch(true);
1121
+ }
1122
+ }),
1123
+ (capabilities === null || capabilities === void 0 ? void 0 : capabilities.findDirection) && /* @__PURE__ */ jsx(SettingSelect, {
1124
+ label: localeService.t("find-replace.dialog.find-direction.title"),
1125
+ value: state.findDirection,
1126
+ options: findDirectionOptions,
1127
+ onChange: (value) => {
1128
+ findReplaceService.changeFindDirection(value);
1129
+ refreshSearch();
1130
+ }
1131
+ }),
1132
+ (capabilities === null || capabilities === void 0 ? void 0 : capabilities.findScope) && /* @__PURE__ */ jsx(SettingSelect, {
1133
+ label: localeService.t("find-replace.dialog.find-scope.title"),
1134
+ value: state.findScope,
1135
+ options: findScopeOptions,
1136
+ onChange: (value) => {
1137
+ findReplaceService.changeFindScope(value);
1138
+ refreshSearch();
1139
+ }
1140
+ }),
1141
+ (capabilities === null || capabilities === void 0 ? void 0 : capabilities.findBy) && /* @__PURE__ */ jsx(SettingSelect, {
1142
+ label: localeService.t("find-replace.dialog.find-by.title"),
1143
+ value: state.findBy,
1144
+ options: findByOptions,
1145
+ onChange: (value) => {
1146
+ findReplaceService.changeFindBy(value);
1147
+ refreshSearch();
1148
+ }
1149
+ }),
1150
+ (capabilities === null || capabilities === void 0 ? void 0 : capabilities.caseSensitive) && /* @__PURE__ */ jsx(SettingCheckbox, {
1151
+ checked: state.caseSensitive,
1152
+ label: localeService.t("find-replace.dialog.case-sensitive"),
1153
+ onChange: (checked) => {
1154
+ findReplaceService.changeCaseSensitive(checked);
1155
+ refreshSearch();
1156
+ }
1157
+ }),
1158
+ (capabilities === null || capabilities === void 0 ? void 0 : capabilities.matchesTheWholeCell) && /* @__PURE__ */ jsx(SettingCheckbox, {
1159
+ checked: state.matchesTheWholeCell,
1160
+ label: localeService.t("find-replace.dialog.match-the-whole-cell"),
1161
+ onChange: (checked) => {
1162
+ findReplaceService.changeMatchesTheWholeCell(checked);
1163
+ refreshSearch();
1164
+ }
1165
+ }),
1166
+ (capabilities === null || capabilities === void 0 ? void 0 : capabilities.matchesTheWholeWord) && /* @__PURE__ */ jsx(SettingCheckbox, {
1167
+ checked: state.matchesTheWholeWord,
1168
+ label: localeService.t("find-replace.dialog.match-the-whole-word"),
1169
+ onChange: (checked) => {
1170
+ findReplaceService.changeMatchesTheWholeWord(checked);
1171
+ refreshSearch();
1172
+ }
1173
+ })
1174
+ ]
1175
+ });
1176
+ }
1177
+ function SettingSelect(props) {
1178
+ return /* @__PURE__ */ jsxs("label", {
1179
+ className: "univer-grid univer-gap-1 univer-text-sm univer-text-gray-700 dark:!univer-text-gray-300",
1180
+ children: [/* @__PURE__ */ jsx("span", { children: props.label }), /* @__PURE__ */ jsx(MobileSelect, {
1181
+ value: props.value,
1182
+ options: props.options,
1183
+ onChange: props.onChange
1184
+ })]
1185
+ });
1186
+ }
1187
+ function SettingCheckbox(props) {
1188
+ return /* @__PURE__ */ jsx("div", {
1189
+ className: "univer-flex univer-min-h-9 univer-items-center",
1190
+ children: /* @__PURE__ */ jsx(Checkbox, {
1191
+ checked: props.checked,
1192
+ onChange: (checked) => props.onChange(Boolean(checked)),
1193
+ children: props.label
1194
+ })
1195
+ });
1196
+ }
1197
+
1198
+ //#endregion
1199
+ //#region src/controllers/mobile/components.controller.ts
1200
+ /**
1201
+ * Copyright 2023-present DreamNum Co., Ltd.
1202
+ *
1203
+ * Licensed under the Apache License, Version 2.0 (the "License");
1204
+ * you may not use this file except in compliance with the License.
1205
+ * You may obtain a copy of the License at
1206
+ *
1207
+ * http://www.apache.org/licenses/LICENSE-2.0
1208
+ *
1209
+ * Unless required by applicable law or agreed to in writing, software
1210
+ * distributed under the License is distributed on an "AS IS" BASIS,
1211
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
+ * See the License for the specific language governing permissions and
1213
+ * limitations under the License.
1214
+ */
1215
+ let MobileComponentsController = class MobileComponentsController extends Disposable {
1216
+ constructor(componentManager, iconManager) {
1217
+ super();
1218
+ this.disposeWithMe(iconManager.register({ SearchIcon }));
1219
+ this.disposeWithMe(componentManager.register(MOBILE_FIND_REPLACE_SETTINGS_COMPONENT, MobileFindReplaceSettings));
1220
+ }
1221
+ };
1222
+ MobileComponentsController = __decorate([__decorateParam(0, Inject(ComponentManager)), __decorateParam(1, Inject(IconManager))], MobileComponentsController);
1223
+
1224
+ //#endregion
1225
+ //#region src/menu/mobile-schema.ts
1226
+ const mobileMenuSchema = { [RibbonDataGroup.ORGANIZATION]: { [OpenFindDialogOperation.id]: {
1227
+ order: 2,
1228
+ menuItemFactory: FindReplaceMenuItemFactory
1229
+ } } };
1230
+
1231
+ //#endregion
1232
+ //#region src/views/mobile/MobileFindReplaceBar.tsx
1233
+ const SEARCH_DEBOUNCE_TIME = 500;
1234
+ function MobileFindReplaceBar() {
1235
+ const findReplaceService = useDependency(IFindReplaceService);
1236
+ useObservable(findReplaceService.state$, void 0, true);
1237
+ if (!findReplaceService.revealed) return null;
1238
+ return /* @__PURE__ */ jsx(MobileFindReplaceBarContent, {});
1239
+ }
1240
+ function MobileFindReplaceBarContent() {
1241
+ const keyboardInset = useContext(MobileKeyboardInsetContext);
1242
+ const commandService = useDependency(ICommandService);
1243
+ const dialogService = useDependency(IDialogService);
1244
+ const findReplaceService = useDependency(IFindReplaceService);
1245
+ const localeService = useDependency(LocaleService);
1246
+ const state = useObservable(findReplaceService.state$, void 0, true);
1247
+ const currentMatch = useObservable(findReplaceService.currentMatch$, null, true);
1248
+ const replaceables = useObservable(findReplaceService.replaceables$, [], true);
1249
+ const [findValue, setFindValue] = useState(() => state.replaceRevealed ? state.inputtingFindString : state.findString);
1250
+ const inputRef = useRef(null);
1251
+ const searchTimerRef = useRef(null);
1252
+ const suppressNextFocusRef = useRef(false);
1253
+ useEffect(() => {
1254
+ const frame = requestAnimationFrame(() => {
1255
+ var _inputRef$current;
1256
+ return (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
1257
+ });
1258
+ return () => cancelAnimationFrame(frame);
1259
+ }, []);
1260
+ useEffect(() => {
1261
+ const subscription = findReplaceService.focusSignal$.subscribe(() => {
1262
+ var _inputRef$current2;
1263
+ if (suppressNextFocusRef.current) {
1264
+ suppressNextFocusRef.current = false;
1265
+ return;
1266
+ }
1267
+ (_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 || _inputRef$current2.focus();
1268
+ });
1269
+ return () => subscription.unsubscribe();
1270
+ }, [findReplaceService]);
1271
+ useEffect(() => () => {
1272
+ if (searchTimerRef.current) clearTimeout(searchTimerRef.current);
1273
+ }, []);
1274
+ function clearSearchTimer() {
1275
+ if (searchTimerRef.current) {
1276
+ clearTimeout(searchTimerRef.current);
1277
+ searchTimerRef.current = null;
1278
+ }
1279
+ }
1280
+ function commitSearch(value) {
1281
+ clearSearchTimer();
1282
+ if (!value) {
1283
+ findReplaceService.changeInputtingFindString("");
1284
+ return;
1285
+ }
1286
+ if (findReplaceService.replaceRevealed) {
1287
+ findReplaceService.changeInputtingFindString(value);
1288
+ findReplaceService.changeFindString(value);
1289
+ findReplaceService.find();
1290
+ return;
1291
+ }
1292
+ findReplaceService.changeFindString(value);
1293
+ }
1294
+ function scheduleSearch(value) {
1295
+ clearSearchTimer();
1296
+ if (!value) {
1297
+ commitSearch(value);
1298
+ return;
1299
+ }
1300
+ searchTimerRef.current = setTimeout(() => commitSearch(value), SEARCH_DEBOUNCE_TIME);
1301
+ }
1302
+ function blurActiveElement() {
1303
+ if (document.activeElement instanceof HTMLElement) document.activeElement.blur();
1304
+ }
1305
+ function executeAfterBlur(commandId, suppressFocusSignal = false) {
1306
+ blurActiveElement();
1307
+ if (findValue !== state.findString) {
1308
+ commitSearch(findValue);
1309
+ if (commandId === GoToNextMatchOperation.id || commandId === GoToPreviousMatchOperation.id) return;
1310
+ }
1311
+ suppressNextFocusRef.current = suppressFocusSignal;
1312
+ const execution = commandService.executeCommand(commandId);
1313
+ suppressNextFocusRef.current = false;
1314
+ execution.catch(() => void 0);
1315
+ }
1316
+ function openSettings() {
1317
+ commitSearch(findValue);
1318
+ blurActiveElement();
1319
+ dialogService.open({
1320
+ id: MOBILE_FIND_REPLACE_SETTINGS_DIALOG_ID,
1321
+ title: { title: localeService.t("find-replace.mobile.settings-title") },
1322
+ children: { label: MOBILE_FIND_REPLACE_SETTINGS_COMPONENT }
1323
+ });
1324
+ }
1325
+ const resultText = state.findCompleted && state.matchesCount === 0 ? localeService.t("find-replace.dialog.no-result") : state.matchesCount > 0 ? `${state.matchesPosition}/${state.matchesCount}` : void 0;
1326
+ const navigationDisabled = state.matchesCount === 0;
1327
+ const replaceDisabled = state.matchesCount === 0 || !(currentMatch === null || currentMatch === void 0 ? void 0 : currentMatch.replaceable);
1328
+ const replaceAllDisabled = replaceables.length === 0;
1329
+ return /* @__PURE__ */ jsxs("div", {
1330
+ "data-u-comp": "mobile-find-replace-bar",
1331
+ className: "univer-fixed univer-inset-x-0 univer-z-40 univer-grid univer-gap-2 univer-bg-gray-0 univer-px-2 univer-pt-1.5 univer-shadow-[0_-4px_16px_rgba(0,0,0,0.08)] dark:!univer-bg-gray-800",
1332
+ style: {
1333
+ bottom: keyboardInset,
1334
+ paddingBottom: "calc(6px + env(safe-area-inset-bottom, 0px))"
1335
+ },
1336
+ children: [/* @__PURE__ */ jsxs("div", {
1337
+ className: "univer-flex",
1338
+ children: [
1339
+ /* @__PURE__ */ jsx(IconButton, {
1340
+ label: localeService.t("find-replace.mobile.settings"),
1341
+ onClick: openSettings,
1342
+ children: /* @__PURE__ */ jsx(ConfigureTabIcon, {})
1343
+ }),
1344
+ /* @__PURE__ */ jsxs("div", {
1345
+ className: "univer-relative univer-mr-2 univer-min-w-0 univer-flex-1",
1346
+ children: [/* @__PURE__ */ jsx(SearchIcon, { className: "univer-pointer-events-none univer-absolute univer-left-3 univer-top-1/2 univer-z-10 univer-size-5 -univer-translate-y-1/2 univer-text-gray-500" }), /* @__PURE__ */ jsx(Input, {
1347
+ ref: inputRef,
1348
+ size: "middle",
1349
+ allowClear: true,
1350
+ value: findValue,
1351
+ placeholder: localeService.t("find-replace.dialog.find-placeholder"),
1352
+ inputClass: "!univer-pl-10",
1353
+ slot: resultText ? /* @__PURE__ */ jsx("span", {
1354
+ className: "univer-text-xs univer-text-gray-400",
1355
+ children: resultText
1356
+ }) : void 0,
1357
+ onChange: (value) => {
1358
+ setFindValue(value);
1359
+ scheduleSearch(value);
1360
+ },
1361
+ onKeyDown: (event) => {
1362
+ if (event.key === "Enter") executeAfterBlur(GoToNextMatchOperation.id);
1363
+ }
1364
+ })]
1365
+ }),
1366
+ /* @__PURE__ */ jsx(IconButton, {
1367
+ disabled: navigationDisabled,
1368
+ label: localeService.t("find-replace.mobile.previous-match"),
1369
+ onClick: () => executeAfterBlur(GoToPreviousMatchOperation.id, true),
1370
+ children: /* @__PURE__ */ jsx(ArrowUpIcon, {})
1371
+ }),
1372
+ /* @__PURE__ */ jsx(IconButton, {
1373
+ disabled: navigationDisabled,
1374
+ label: localeService.t("find-replace.mobile.next-match"),
1375
+ onClick: () => executeAfterBlur(GoToNextMatchOperation.id, true),
1376
+ children: /* @__PURE__ */ jsx(ArrowDownIcon, {})
1377
+ }),
1378
+ /* @__PURE__ */ jsx(IconButton, {
1379
+ label: localeService.t("find-replace.mobile.close"),
1380
+ onClick: () => {
1381
+ blurActiveElement();
1382
+ commandService.executeCommand(CloseFindDialogOperation.id).catch(() => void 0);
1383
+ },
1384
+ children: /* @__PURE__ */ jsx(CloseIcon, {})
1385
+ })
1386
+ ]
1387
+ }), state.replaceRevealed && /* @__PURE__ */ jsxs("div", {
1388
+ className: "univer-flex univer-gap-1 univer-pl-9",
1389
+ children: [
1390
+ /* @__PURE__ */ jsx(Input, {
1391
+ size: "middle",
1392
+ className: "univer-min-w-0 univer-flex-1",
1393
+ value: state.replaceString,
1394
+ placeholder: localeService.t("find-replace.dialog.replace-placeholder"),
1395
+ onChange: (value) => findReplaceService.changeReplaceString(value)
1396
+ }),
1397
+ /* @__PURE__ */ jsx(ActionButton, {
1398
+ disabled: replaceDisabled,
1399
+ onClick: () => executeAfterBlur(ReplaceCurrentMatchCommand.id),
1400
+ children: localeService.t("find-replace.dialog.replace")
1401
+ }),
1402
+ /* @__PURE__ */ jsx(ActionButton, {
1403
+ disabled: replaceAllDisabled,
1404
+ onClick: () => executeAfterBlur(ReplaceAllMatchesCommand.id),
1405
+ children: localeService.t("find-replace.dialog.replace-all")
1406
+ })
1407
+ ]
1408
+ })]
1409
+ });
1410
+ }
1411
+ function IconButton(props) {
1412
+ return /* @__PURE__ */ jsx("button", {
1413
+ type: "button",
1414
+ "aria-label": props.label,
1415
+ disabled: props.disabled,
1416
+ className: clsx(resetButtonClassName, "univer-flex univer-size-9 univer-flex-none univer-items-center univer-justify-center univer-rounded-full univer-text-lg univer-text-gray-700 active:univer-bg-gray-100 disabled:univer-opacity-35 dark:!univer-text-gray-200 dark:active:!univer-bg-gray-700"),
1417
+ onClick: props.onClick,
1418
+ children: props.children
1419
+ });
1420
+ }
1421
+ function ActionButton(props) {
1422
+ return /* @__PURE__ */ jsx("button", {
1423
+ type: "button",
1424
+ disabled: props.disabled,
1425
+ className: clsx(resetButtonClassName, "univer-h-10 univer-flex-none univer-whitespace-nowrap univer-rounded-lg univer-bg-primary-600 univer-px-3 univer-text-sm univer-font-medium univer-text-gray-0 active:univer-bg-primary-700 disabled:univer-bg-gray-100 disabled:univer-text-gray-400 dark:disabled:!univer-bg-gray-700 dark:disabled:!univer-text-gray-500"),
1426
+ onClick: props.onClick,
1427
+ children: props.children
1428
+ });
1429
+ }
1430
+
1431
+ //#endregion
1432
+ //#region src/controllers/mobile/find-replace.controller.ts
1433
+ /**
1434
+ * Copyright 2023-present DreamNum Co., Ltd.
1435
+ *
1436
+ * Licensed under the Apache License, Version 2.0 (the "License");
1437
+ * you may not use this file except in compliance with the License.
1438
+ * You may obtain a copy of the License at
1439
+ *
1440
+ * http://www.apache.org/licenses/LICENSE-2.0
1441
+ *
1442
+ * Unless required by applicable law or agreed to in writing, software
1443
+ * distributed under the License is distributed on an "AS IS" BASIS,
1444
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1445
+ * See the License for the specific language governing permissions and
1446
+ * limitations under the License.
1447
+ */
1448
+ let FindReplaceMobileController = class FindReplaceMobileController extends RxDisposable {
1449
+ constructor(injector, commandService, dialogService, findReplaceService, menuManagerService, univerInstanceService, uiPartsService) {
1450
+ super();
1451
+ [
1452
+ OpenFindDialogOperation,
1453
+ OpenReplaceDialogOperation,
1454
+ CloseFindDialogOperation,
1455
+ GoToNextMatchOperation,
1456
+ GoToPreviousMatchOperation,
1457
+ ReplaceAllMatchesCommand,
1458
+ ReplaceCurrentMatchCommand,
1459
+ FocusSelectionOperation
1460
+ ].forEach((command) => this.disposeWithMe(commandService.registerCommand(command)));
1461
+ menuManagerService.mergeMenu(mobileMenuSchema);
1462
+ this.disposeWithMe(uiPartsService.registerComponent(BuiltInUIPart.FOOTER, () => connectInjector(MobileFindReplaceBar, injector)));
1463
+ findReplaceService.stateUpdates$.pipe(takeUntil(this.dispose$)).subscribe((state) => {
1464
+ if (state.revealed === false) dialogService.close(MOBILE_FIND_REPLACE_SETTINGS_DIALOG_ID);
1465
+ });
1466
+ let sessionUnitId = null;
1467
+ findReplaceService.stateUpdates$.pipe(takeUntil(this.dispose$)).subscribe((state) => {
1468
+ if (state.revealed === true) {
1469
+ var _univerInstanceServic;
1470
+ sessionUnitId = ((_univerInstanceServic = univerInstanceService.getFocusedUnit()) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getUnitId()) ?? null;
1471
+ } else if (state.revealed === false) sessionUnitId = null;
1472
+ });
1473
+ univerInstanceService.focused$.pipe(takeUntil(this.dispose$)).subscribe((focused) => {
1474
+ if (sessionUnitId && focused !== sessionUnitId) findReplaceService.terminate();
1475
+ });
1476
+ }
1477
+ };
1478
+ FindReplaceMobileController = __decorate([
1479
+ __decorateParam(0, Inject(Injector)),
1480
+ __decorateParam(1, ICommandService),
1481
+ __decorateParam(2, IDialogService),
1482
+ __decorateParam(3, IFindReplaceService),
1483
+ __decorateParam(4, IMenuManagerService),
1484
+ __decorateParam(5, IUniverInstanceService),
1485
+ __decorateParam(6, IUIPartsService)
1486
+ ], FindReplaceMobileController);
1487
+
1488
+ //#endregion
1489
+ //#region src/mobile-plugin.ts
1490
+ let UniverFindReplaceMobileUIPlugin = class UniverFindReplaceMobileUIPlugin extends Plugin {
1491
+ constructor(_config = defaultPluginConfig, _injector, _configService) {
1492
+ super();
1493
+ this._config = _config;
1494
+ this._injector = _injector;
1495
+ this._configService = _configService;
1496
+ const { ...rest } = merge({}, defaultPluginConfig, this._config);
1497
+ this._configService.setConfig(FIND_REPLACE_PLUGIN_CONFIG_KEY, rest);
1498
+ }
1499
+ onStarting() {
1500
+ this._injector.add([MobileComponentsController]);
1501
+ this._injector.get(MobileComponentsController);
1502
+ [[FindReplaceMobileController], [IFindReplaceService, { useClass: FindReplaceService }]].forEach((dependency) => this._injector.add(dependency));
1503
+ }
1504
+ onRendered() {
1505
+ this._injector.get(FindReplaceMobileController);
1506
+ }
1507
+ };
1508
+ _defineProperty(UniverFindReplaceMobileUIPlugin, "pluginName", "UNIVER_FIND_REPLACE_PLUGIN");
1509
+ _defineProperty(UniverFindReplaceMobileUIPlugin, "packageName", name);
1510
+ _defineProperty(UniverFindReplaceMobileUIPlugin, "version", version);
1511
+ UniverFindReplaceMobileUIPlugin = __decorate([
1512
+ DependentOn(UniverMobileUIPlugin),
1513
+ __decorateParam(1, Inject(Injector)),
1514
+ __decorateParam(2, IConfigService)
1515
+ ], UniverFindReplaceMobileUIPlugin);
1516
+
1023
1517
  //#endregion
1024
1518
  //#region src/views/dialog/SearchInput.tsx
1025
1519
  function SearchInput(props) {
@@ -1081,10 +1575,18 @@ const FIND_BY_OPTIONS = [{
1081
1575
  value: "formula"
1082
1576
  }];
1083
1577
  function useFindInputFocus(findReplaceService, ref) {
1578
+ const pendingFocusFrameRef = useRef(null);
1084
1579
  const focus = useCallback(() => {
1085
1580
  var _document$querySelect;
1086
1581
  (_document$querySelect = document.querySelector(".univer-find-input input")) === null || _document$querySelect === void 0 || _document$querySelect.focus();
1087
1582
  }, []);
1583
+ const focusAfterDialogClose = useCallback(() => {
1584
+ focus();
1585
+ pendingFocusFrameRef.current = requestAnimationFrame(() => {
1586
+ pendingFocusFrameRef.current = null;
1587
+ focus();
1588
+ });
1589
+ }, [focus]);
1088
1590
  const selectHasFocus = useCallback(() => {
1089
1591
  const allInputs = document.querySelectorAll("[data-u-comp=find-replace-dialog] [data-u-comp=search-input]");
1090
1592
  return Array.from(allInputs).some((input) => input === document.activeElement);
@@ -1095,10 +1597,14 @@ function useFindInputFocus(findReplaceService, ref) {
1095
1597
  }));
1096
1598
  useEffect(() => {
1097
1599
  const subscription = findReplaceService.focusSignal$.subscribe(() => focus());
1098
- return () => subscription.unsubscribe();
1600
+ return () => {
1601
+ subscription.unsubscribe();
1602
+ if (pendingFocusFrameRef.current !== null) cancelAnimationFrame(pendingFocusFrameRef.current);
1603
+ };
1099
1604
  }, [findReplaceService, focus]);
1100
1605
  return {
1101
1606
  focus,
1607
+ focusAfterDialogClose,
1102
1608
  selectHasFocus
1103
1609
  };
1104
1610
  }
@@ -1144,7 +1650,7 @@ const ReplaceDialog = forwardRef(function ReplaceDialogImpl(_props, ref) {
1144
1650
  const replaceAllDisabled = replaceables.length === 0;
1145
1651
  const onFindStringChange = useCallback((newValue) => findReplaceService.changeInputtingFindString(newValue), [findReplaceService]);
1146
1652
  const onReplaceStringChange = useCallback((replaceString) => findReplaceService.changeReplaceString(replaceString), [findReplaceService]);
1147
- const { focus } = useFindInputFocus(findReplaceService, ref);
1653
+ const { focusAfterDialogClose } = useFindInputFocus(findReplaceService, ref);
1148
1654
  const onClickFindButton = useCallback(() => {
1149
1655
  if (findString === inputtingFindString) findReplaceService.moveToNextMatch();
1150
1656
  else {
@@ -1159,8 +1665,8 @@ const ReplaceDialog = forwardRef(function ReplaceDialogImpl(_props, ref) {
1159
1665
  const onClickReplaceButton = useCallback(() => commandService.executeCommand(ReplaceCurrentMatchCommand.id), [commandService]);
1160
1666
  const onClickReplaceAllButton = useCallback(async () => {
1161
1667
  await commandService.executeCommand(ReplaceAllMatchesCommand.id);
1162
- focus();
1163
- }, [commandService, focus]);
1668
+ focusAfterDialogClose();
1669
+ }, [commandService, focusAfterDialogClose]);
1164
1670
  const onChangeFindDirection = useCallback((findDirection) => {
1165
1671
  findReplaceService.changeFindDirection(findDirection);
1166
1672
  }, [findReplaceService]);
@@ -1384,4 +1890,4 @@ _defineProperty(UniverFindReplacePlugin, "version", version);
1384
1890
  UniverFindReplacePlugin = __decorate([__decorateParam(1, Inject(Injector)), __decorateParam(2, IConfigService)], UniverFindReplacePlugin);
1385
1891
 
1386
1892
  //#endregion
1387
- export { FindBy, FindDirection, FindModel, FindReplaceController, menuSchema as FindReplaceMenuSchema, FindReplaceModel, FindReplaceService, FindReplaceState, FindScope, GoToNextMatchOperation, GoToPreviousMatchOperation, IFindReplaceService, OpenFindDialogOperation, OpenReplaceDialogOperation, ReplaceAllMatchesCommand, ReplaceCurrentMatchCommand, UniverFindReplacePlugin, createInitFindReplaceState };
1893
+ export { CloseFindDialogOperation, FindBy, FindDirection, FindModel, FindReplaceController, menuSchema as FindReplaceMenuSchema, FindReplaceModel, FindReplaceService, FindReplaceState, FindScope, GoToNextMatchOperation, GoToPreviousMatchOperation, IFindReplaceService, OpenFindDialogOperation, OpenReplaceDialogOperation, ReplaceAllMatchesCommand, ReplaceCurrentMatchCommand, UniverFindReplaceMobileUIPlugin, UniverFindReplacePlugin, createInitFindReplaceState };
@@ -1,10 +1,16 @@
1
1
  //#region src/locale/ar-SA.ts
2
2
  const locale = { "find-replace": {
3
3
  toolbar: "بحث واستبدال",
4
+ mobile: {
5
+ settings: "إعدادات البحث والاستبدال",
6
+ "settings-title": "إعدادات البحث والاستبدال",
7
+ "previous-match": "التطابق السابق",
8
+ "next-match": "التطابق التالي",
9
+ close: "إغلاق البحث والاستبدال"
10
+ },
4
11
  shortcut: {
5
12
  "open-find-dialog": "فتح مربع حوار البحث",
6
13
  "open-replace-dialog": "فتح مربع حوار الاستبدال",
7
- "close-dialog": "إغلاق مربع حوار البحث والاستبدال",
8
14
  "go-to-next-match": "الانتقال إلى التطابق التالي",
9
15
  "go-to-previous-match": "الانتقال إلى التطابق السابق",
10
16
  "focus-selection": "تركيز التحديد",
@@ -1,10 +1,16 @@
1
1
  //#region src/locale/ca-ES.ts
2
2
  const locale = { "find-replace": {
3
3
  toolbar: "Cerca i reemplaça",
4
+ mobile: {
5
+ settings: "Configuració de cerca i reemplaçament",
6
+ "settings-title": "Configuració de cerca i reemplaçament",
7
+ "previous-match": "Coincidència anterior",
8
+ "next-match": "Coincidència següent",
9
+ close: "Tanca la cerca i el reemplaçament"
10
+ },
4
11
  shortcut: {
5
12
  "open-find-dialog": "Obrir el diàleg de cerca",
6
13
  "open-replace-dialog": "Obrir el diàleg de reemplaçament",
7
- "close-dialog": "Tancar el diàleg de cerca i reemplaçament",
8
14
  "go-to-next-match": "Anar a la següent coincidència",
9
15
  "go-to-previous-match": "Anar a la coincidència anterior",
10
16
  "focus-selection": "Enfocar la selecció",