@univerjs/find-replace 1.0.0-insiders.20260813-7c9aa50 → 1.0.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 +532 -17
  4. package/lib/cjs/locale/ar-SA.js +7 -2
  5. package/lib/cjs/locale/ca-ES.js +7 -2
  6. package/lib/cjs/locale/de-DE.js +7 -2
  7. package/lib/cjs/locale/en-US.js +7 -2
  8. package/lib/cjs/locale/es-ES.js +7 -2
  9. package/lib/cjs/locale/fa-IR.js +7 -2
  10. package/lib/cjs/locale/fr-FR.js +7 -2
  11. package/lib/cjs/locale/id-ID.js +7 -2
  12. package/lib/cjs/locale/it-IT.js +7 -2
  13. package/lib/cjs/locale/ja-JP.js +7 -2
  14. package/lib/cjs/locale/ko-KR.js +7 -2
  15. package/lib/cjs/locale/pl-PL.js +7 -2
  16. package/lib/cjs/locale/pt-BR.js +7 -2
  17. package/lib/cjs/locale/ru-RU.js +7 -2
  18. package/lib/cjs/locale/sk-SK.js +7 -2
  19. package/lib/cjs/locale/vi-VN.js +7 -2
  20. package/lib/cjs/locale/zh-CN.js +7 -2
  21. package/lib/cjs/locale/zh-HK.js +7 -2
  22. package/lib/cjs/locale/zh-TW.js +7 -2
  23. package/lib/es/index.js +531 -23
  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 +531 -23
  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/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, useMobileKeyboardViewportLayout } from "@univerjs/design";
3
+ import { BuiltInUIPart, ComponentManager, IDialogService, ILayoutService, IMenuManagerService, IMessageService, IShortcutService, IUIPartsService, IconManager, KeyCode, MenuItemType, MetaKeys, 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, useEffect, useImperativeHandle, useRef, useState } from "react";
9
9
 
10
10
  //#region src/services/context-keys.ts
11
11
  /**
@@ -36,7 +36,7 @@ const FIND_REPLACE_REPLACE_REVEALED = "FIND_REPLACE_REPLACE_REVEALED";
36
36
  const FIND_REPLACE_AVAILABLE = "FIND_REPLACE_AVAILABLE";
37
37
 
38
38
  //#endregion
39
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
39
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
40
40
  function _typeof(o) {
41
41
  "@babel/helpers - typeof";
42
42
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -47,7 +47,7 @@ function _typeof(o) {
47
47
  }
48
48
 
49
49
  //#endregion
50
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPrimitive.js
50
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
51
51
  function toPrimitive(t, r) {
52
52
  if ("object" != _typeof(t) || !t) return t;
53
53
  var e = t[Symbol.toPrimitive];
@@ -60,14 +60,14 @@ function toPrimitive(t, r) {
60
60
  }
61
61
 
62
62
  //#endregion
63
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPropertyKey.js
63
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
64
64
  function toPropertyKey(t) {
65
65
  var i = toPrimitive(t, "string");
66
66
  return "symbol" == _typeof(i) ? i : i + "";
67
67
  }
68
68
 
69
69
  //#endregion
70
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/defineProperty.js
70
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
71
71
  function _defineProperty(e, r, t) {
72
72
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
73
73
  value: t,
@@ -78,7 +78,7 @@ function _defineProperty(e, r, t) {
78
78
  }
79
79
 
80
80
  //#endregion
81
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateParam.js
81
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
82
82
  function __decorateParam(paramIndex, decorator) {
83
83
  return function(target, key) {
84
84
  decorator(target, key, paramIndex);
@@ -86,7 +86,7 @@ function __decorateParam(paramIndex, decorator) {
86
86
  }
87
87
 
88
88
  //#endregion
89
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
89
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
90
90
  function __decorate(decorators, target, key, desc) {
91
91
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
92
92
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -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.20260813-7c9aa50";
1039
+ var version = "1.0.0";
1016
1040
 
1017
1041
  //#endregion
1018
1042
  //#region src/config/config.ts
@@ -1020,6 +1044,478 @@ 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 commandService = useDependency(ICommandService);
1242
+ const dialogService = useDependency(IDialogService);
1243
+ const findReplaceService = useDependency(IFindReplaceService);
1244
+ const localeService = useDependency(LocaleService);
1245
+ const state = useObservable(findReplaceService.state$, void 0, true);
1246
+ const currentMatch = useObservable(findReplaceService.currentMatch$, null, true);
1247
+ const replaceables = useObservable(findReplaceService.replaceables$, [], true);
1248
+ const [findValue, setFindValue] = useState(() => state.replaceRevealed ? state.inputtingFindString : state.findString);
1249
+ const barRef = useRef(null);
1250
+ const inputRef = useRef(null);
1251
+ const searchTimerRef = useRef(null);
1252
+ const suppressNextFocusRef = useRef(false);
1253
+ const keyboardLayout = useMobileKeyboardViewportLayout(barRef);
1254
+ useEffect(() => {
1255
+ const frame = requestAnimationFrame(() => {
1256
+ var _inputRef$current;
1257
+ return (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
1258
+ });
1259
+ return () => cancelAnimationFrame(frame);
1260
+ }, []);
1261
+ useEffect(() => {
1262
+ const subscription = findReplaceService.focusSignal$.subscribe(() => {
1263
+ var _inputRef$current2;
1264
+ if (suppressNextFocusRef.current) {
1265
+ suppressNextFocusRef.current = false;
1266
+ return;
1267
+ }
1268
+ (_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 || _inputRef$current2.focus();
1269
+ });
1270
+ return () => subscription.unsubscribe();
1271
+ }, [findReplaceService]);
1272
+ useEffect(() => () => {
1273
+ if (searchTimerRef.current) clearTimeout(searchTimerRef.current);
1274
+ }, []);
1275
+ function clearSearchTimer() {
1276
+ if (searchTimerRef.current) {
1277
+ clearTimeout(searchTimerRef.current);
1278
+ searchTimerRef.current = null;
1279
+ }
1280
+ }
1281
+ function commitSearch(value) {
1282
+ clearSearchTimer();
1283
+ if (!value) {
1284
+ findReplaceService.changeInputtingFindString("");
1285
+ return;
1286
+ }
1287
+ if (findReplaceService.replaceRevealed) {
1288
+ findReplaceService.changeInputtingFindString(value);
1289
+ findReplaceService.changeFindString(value);
1290
+ findReplaceService.find();
1291
+ return;
1292
+ }
1293
+ findReplaceService.changeFindString(value);
1294
+ }
1295
+ function scheduleSearch(value) {
1296
+ clearSearchTimer();
1297
+ if (!value) {
1298
+ commitSearch(value);
1299
+ return;
1300
+ }
1301
+ searchTimerRef.current = setTimeout(() => commitSearch(value), SEARCH_DEBOUNCE_TIME);
1302
+ }
1303
+ function blurActiveElement() {
1304
+ if (document.activeElement instanceof HTMLElement) document.activeElement.blur();
1305
+ }
1306
+ function executeAfterBlur(commandId, suppressFocusSignal = false) {
1307
+ blurActiveElement();
1308
+ if (findValue !== state.findString) {
1309
+ commitSearch(findValue);
1310
+ if (commandId === GoToNextMatchOperation.id || commandId === GoToPreviousMatchOperation.id) return;
1311
+ }
1312
+ suppressNextFocusRef.current = suppressFocusSignal;
1313
+ const execution = commandService.executeCommand(commandId);
1314
+ suppressNextFocusRef.current = false;
1315
+ execution.catch(() => void 0);
1316
+ }
1317
+ function openSettings() {
1318
+ commitSearch(findValue);
1319
+ blurActiveElement();
1320
+ dialogService.open({
1321
+ id: MOBILE_FIND_REPLACE_SETTINGS_DIALOG_ID,
1322
+ title: { title: localeService.t("find-replace.mobile.settings-title") },
1323
+ children: { label: MOBILE_FIND_REPLACE_SETTINGS_COMPONENT }
1324
+ });
1325
+ }
1326
+ const resultText = state.findCompleted && state.matchesCount === 0 ? localeService.t("find-replace.dialog.no-result") : state.matchesCount > 0 ? `${state.matchesPosition}/${state.matchesCount}` : void 0;
1327
+ const navigationDisabled = state.matchesCount === 0;
1328
+ const replaceDisabled = state.matchesCount === 0 || !(currentMatch === null || currentMatch === void 0 ? void 0 : currentMatch.replaceable);
1329
+ const replaceAllDisabled = replaceables.length === 0;
1330
+ return /* @__PURE__ */ jsxs("div", {
1331
+ ref: barRef,
1332
+ "data-u-comp": "mobile-find-replace-bar",
1333
+ 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",
1334
+ style: {
1335
+ bottom: (keyboardLayout === null || keyboardLayout === void 0 ? void 0 : keyboardLayout.bottom) ?? 0,
1336
+ paddingBottom: "calc(6px + env(safe-area-inset-bottom, 0px))"
1337
+ },
1338
+ children: [/* @__PURE__ */ jsxs("div", {
1339
+ className: "univer-flex",
1340
+ children: [
1341
+ /* @__PURE__ */ jsx(IconButton, {
1342
+ label: localeService.t("find-replace.mobile.settings"),
1343
+ onClick: openSettings,
1344
+ children: /* @__PURE__ */ jsx(ConfigureTabIcon, {})
1345
+ }),
1346
+ /* @__PURE__ */ jsxs("div", {
1347
+ className: "univer-relative univer-mr-2 univer-min-w-0 univer-flex-1",
1348
+ 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, {
1349
+ ref: inputRef,
1350
+ size: "middle",
1351
+ allowClear: true,
1352
+ value: findValue,
1353
+ placeholder: localeService.t("find-replace.dialog.find-placeholder"),
1354
+ inputClass: "!univer-pl-10",
1355
+ slot: resultText ? /* @__PURE__ */ jsx("span", {
1356
+ className: "univer-text-xs univer-text-gray-400",
1357
+ children: resultText
1358
+ }) : void 0,
1359
+ onChange: (value) => {
1360
+ setFindValue(value);
1361
+ scheduleSearch(value);
1362
+ },
1363
+ onKeyDown: (event) => {
1364
+ if (event.key === "Enter") executeAfterBlur(GoToNextMatchOperation.id);
1365
+ }
1366
+ })]
1367
+ }),
1368
+ /* @__PURE__ */ jsx(IconButton, {
1369
+ disabled: navigationDisabled,
1370
+ label: localeService.t("find-replace.mobile.previous-match"),
1371
+ onClick: () => executeAfterBlur(GoToPreviousMatchOperation.id, true),
1372
+ children: /* @__PURE__ */ jsx(ArrowUpIcon, {})
1373
+ }),
1374
+ /* @__PURE__ */ jsx(IconButton, {
1375
+ disabled: navigationDisabled,
1376
+ label: localeService.t("find-replace.mobile.next-match"),
1377
+ onClick: () => executeAfterBlur(GoToNextMatchOperation.id, true),
1378
+ children: /* @__PURE__ */ jsx(ArrowDownIcon, {})
1379
+ }),
1380
+ /* @__PURE__ */ jsx(IconButton, {
1381
+ label: localeService.t("find-replace.mobile.close"),
1382
+ onClick: () => {
1383
+ blurActiveElement();
1384
+ commandService.executeCommand(CloseFindDialogOperation.id).catch(() => void 0);
1385
+ },
1386
+ children: /* @__PURE__ */ jsx(CloseIcon, {})
1387
+ })
1388
+ ]
1389
+ }), state.replaceRevealed && /* @__PURE__ */ jsxs("div", {
1390
+ className: "univer-flex univer-gap-1 univer-pl-9",
1391
+ children: [
1392
+ /* @__PURE__ */ jsx(Input, {
1393
+ size: "middle",
1394
+ className: "univer-min-w-0 univer-flex-1",
1395
+ value: state.replaceString,
1396
+ placeholder: localeService.t("find-replace.dialog.replace-placeholder"),
1397
+ onChange: (value) => findReplaceService.changeReplaceString(value)
1398
+ }),
1399
+ /* @__PURE__ */ jsx(ActionButton, {
1400
+ disabled: replaceDisabled,
1401
+ onClick: () => executeAfterBlur(ReplaceCurrentMatchCommand.id),
1402
+ children: localeService.t("find-replace.dialog.replace")
1403
+ }),
1404
+ /* @__PURE__ */ jsx(ActionButton, {
1405
+ disabled: replaceAllDisabled,
1406
+ onClick: () => executeAfterBlur(ReplaceAllMatchesCommand.id),
1407
+ children: localeService.t("find-replace.dialog.replace-all")
1408
+ })
1409
+ ]
1410
+ })]
1411
+ });
1412
+ }
1413
+ function IconButton(props) {
1414
+ return /* @__PURE__ */ jsx("button", {
1415
+ type: "button",
1416
+ "aria-label": props.label,
1417
+ disabled: props.disabled,
1418
+ 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"),
1419
+ onClick: props.onClick,
1420
+ children: props.children
1421
+ });
1422
+ }
1423
+ function ActionButton(props) {
1424
+ return /* @__PURE__ */ jsx("button", {
1425
+ type: "button",
1426
+ disabled: props.disabled,
1427
+ 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"),
1428
+ onClick: props.onClick,
1429
+ children: props.children
1430
+ });
1431
+ }
1432
+
1433
+ //#endregion
1434
+ //#region src/controllers/mobile/find-replace.controller.ts
1435
+ /**
1436
+ * Copyright 2023-present DreamNum Co., Ltd.
1437
+ *
1438
+ * Licensed under the Apache License, Version 2.0 (the "License");
1439
+ * you may not use this file except in compliance with the License.
1440
+ * You may obtain a copy of the License at
1441
+ *
1442
+ * http://www.apache.org/licenses/LICENSE-2.0
1443
+ *
1444
+ * Unless required by applicable law or agreed to in writing, software
1445
+ * distributed under the License is distributed on an "AS IS" BASIS,
1446
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1447
+ * See the License for the specific language governing permissions and
1448
+ * limitations under the License.
1449
+ */
1450
+ let FindReplaceMobileController = class FindReplaceMobileController extends RxDisposable {
1451
+ constructor(injector, commandService, dialogService, findReplaceService, menuManagerService, univerInstanceService, uiPartsService) {
1452
+ super();
1453
+ [
1454
+ OpenFindDialogOperation,
1455
+ OpenReplaceDialogOperation,
1456
+ CloseFindDialogOperation,
1457
+ GoToNextMatchOperation,
1458
+ GoToPreviousMatchOperation,
1459
+ ReplaceAllMatchesCommand,
1460
+ ReplaceCurrentMatchCommand,
1461
+ FocusSelectionOperation
1462
+ ].forEach((command) => this.disposeWithMe(commandService.registerCommand(command)));
1463
+ menuManagerService.mergeMenu(mobileMenuSchema);
1464
+ this.disposeWithMe(uiPartsService.registerComponent(BuiltInUIPart.FOOTER, () => connectInjector(MobileFindReplaceBar, injector)));
1465
+ findReplaceService.stateUpdates$.pipe(takeUntil(this.dispose$)).subscribe((state) => {
1466
+ if (state.revealed === false) dialogService.close(MOBILE_FIND_REPLACE_SETTINGS_DIALOG_ID);
1467
+ });
1468
+ let sessionUnitId = null;
1469
+ findReplaceService.stateUpdates$.pipe(takeUntil(this.dispose$)).subscribe((state) => {
1470
+ if (state.revealed === true) {
1471
+ var _univerInstanceServic;
1472
+ sessionUnitId = ((_univerInstanceServic = univerInstanceService.getFocusedUnit()) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getUnitId()) ?? null;
1473
+ } else if (state.revealed === false) sessionUnitId = null;
1474
+ });
1475
+ univerInstanceService.focused$.pipe(takeUntil(this.dispose$)).subscribe((focused) => {
1476
+ if (sessionUnitId && focused !== sessionUnitId) findReplaceService.terminate();
1477
+ });
1478
+ }
1479
+ };
1480
+ FindReplaceMobileController = __decorate([
1481
+ __decorateParam(0, Inject(Injector)),
1482
+ __decorateParam(1, ICommandService),
1483
+ __decorateParam(2, IDialogService),
1484
+ __decorateParam(3, IFindReplaceService),
1485
+ __decorateParam(4, IMenuManagerService),
1486
+ __decorateParam(5, IUniverInstanceService),
1487
+ __decorateParam(6, IUIPartsService)
1488
+ ], FindReplaceMobileController);
1489
+
1490
+ //#endregion
1491
+ //#region src/mobile-plugin.ts
1492
+ let UniverFindReplaceMobileUIPlugin = class UniverFindReplaceMobileUIPlugin extends Plugin {
1493
+ constructor(_config = defaultPluginConfig, _injector, _configService) {
1494
+ super();
1495
+ this._config = _config;
1496
+ this._injector = _injector;
1497
+ this._configService = _configService;
1498
+ const { ...rest } = merge({}, defaultPluginConfig, this._config);
1499
+ this._configService.setConfig(FIND_REPLACE_PLUGIN_CONFIG_KEY, rest);
1500
+ }
1501
+ onStarting() {
1502
+ this._injector.add([MobileComponentsController]);
1503
+ this._injector.get(MobileComponentsController);
1504
+ [[FindReplaceMobileController], [IFindReplaceService, { useClass: FindReplaceService }]].forEach((dependency) => this._injector.add(dependency));
1505
+ }
1506
+ onRendered() {
1507
+ this._injector.get(FindReplaceMobileController);
1508
+ }
1509
+ };
1510
+ _defineProperty(UniverFindReplaceMobileUIPlugin, "pluginName", "UNIVER_FIND_REPLACE_PLUGIN");
1511
+ _defineProperty(UniverFindReplaceMobileUIPlugin, "packageName", name);
1512
+ _defineProperty(UniverFindReplaceMobileUIPlugin, "version", version);
1513
+ UniverFindReplaceMobileUIPlugin = __decorate([
1514
+ DependentOn(UniverMobileUIPlugin),
1515
+ __decorateParam(1, Inject(Injector)),
1516
+ __decorateParam(2, IConfigService)
1517
+ ], UniverFindReplaceMobileUIPlugin);
1518
+
1023
1519
  //#endregion
1024
1520
  //#region src/views/dialog/SearchInput.tsx
1025
1521
  function SearchInput(props) {
@@ -1081,10 +1577,18 @@ const FIND_BY_OPTIONS = [{
1081
1577
  value: "formula"
1082
1578
  }];
1083
1579
  function useFindInputFocus(findReplaceService, ref) {
1580
+ const pendingFocusFrameRef = useRef(null);
1084
1581
  const focus = useCallback(() => {
1085
1582
  var _document$querySelect;
1086
1583
  (_document$querySelect = document.querySelector(".univer-find-input input")) === null || _document$querySelect === void 0 || _document$querySelect.focus();
1087
1584
  }, []);
1585
+ const focusAfterDialogClose = useCallback(() => {
1586
+ focus();
1587
+ pendingFocusFrameRef.current = requestAnimationFrame(() => {
1588
+ pendingFocusFrameRef.current = null;
1589
+ focus();
1590
+ });
1591
+ }, [focus]);
1088
1592
  const selectHasFocus = useCallback(() => {
1089
1593
  const allInputs = document.querySelectorAll("[data-u-comp=find-replace-dialog] [data-u-comp=search-input]");
1090
1594
  return Array.from(allInputs).some((input) => input === document.activeElement);
@@ -1095,10 +1599,14 @@ function useFindInputFocus(findReplaceService, ref) {
1095
1599
  }));
1096
1600
  useEffect(() => {
1097
1601
  const subscription = findReplaceService.focusSignal$.subscribe(() => focus());
1098
- return () => subscription.unsubscribe();
1602
+ return () => {
1603
+ subscription.unsubscribe();
1604
+ if (pendingFocusFrameRef.current !== null) cancelAnimationFrame(pendingFocusFrameRef.current);
1605
+ };
1099
1606
  }, [findReplaceService, focus]);
1100
1607
  return {
1101
1608
  focus,
1609
+ focusAfterDialogClose,
1102
1610
  selectHasFocus
1103
1611
  };
1104
1612
  }
@@ -1144,7 +1652,7 @@ const ReplaceDialog = forwardRef(function ReplaceDialogImpl(_props, ref) {
1144
1652
  const replaceAllDisabled = replaceables.length === 0;
1145
1653
  const onFindStringChange = useCallback((newValue) => findReplaceService.changeInputtingFindString(newValue), [findReplaceService]);
1146
1654
  const onReplaceStringChange = useCallback((replaceString) => findReplaceService.changeReplaceString(replaceString), [findReplaceService]);
1147
- const { focus } = useFindInputFocus(findReplaceService, ref);
1655
+ const { focusAfterDialogClose } = useFindInputFocus(findReplaceService, ref);
1148
1656
  const onClickFindButton = useCallback(() => {
1149
1657
  if (findString === inputtingFindString) findReplaceService.moveToNextMatch();
1150
1658
  else {
@@ -1159,8 +1667,8 @@ const ReplaceDialog = forwardRef(function ReplaceDialogImpl(_props, ref) {
1159
1667
  const onClickReplaceButton = useCallback(() => commandService.executeCommand(ReplaceCurrentMatchCommand.id), [commandService]);
1160
1668
  const onClickReplaceAllButton = useCallback(async () => {
1161
1669
  await commandService.executeCommand(ReplaceAllMatchesCommand.id);
1162
- focus();
1163
- }, [commandService, focus]);
1670
+ focusAfterDialogClose();
1671
+ }, [commandService, focusAfterDialogClose]);
1164
1672
  const onChangeFindDirection = useCallback((findDirection) => {
1165
1673
  findReplaceService.changeFindDirection(findDirection);
1166
1674
  }, [findReplaceService]);
@@ -1242,20 +1750,20 @@ const ReplaceDialog = forwardRef(function ReplaceDialogImpl(_props, ref) {
1242
1750
  capabilities.caseSensitive && /* @__PURE__ */ jsx(FormLayout, { children: /* @__PURE__ */ jsx(Checkbox, {
1243
1751
  checked: caseSensitive,
1244
1752
  onChange: (checked) => {
1245
- findReplaceService.changeCaseSensitive(checked);
1753
+ findReplaceService.changeCaseSensitive(Boolean(checked));
1246
1754
  if (findCompleted) findReplaceService.find();
1247
1755
  },
1248
1756
  children: localeService.t("find-replace.dialog.case-sensitive")
1249
1757
  }) }),
1250
1758
  capabilities.matchesTheWholeCell && /* @__PURE__ */ jsx(FormLayout, { children: /* @__PURE__ */ jsx(Checkbox, {
1251
1759
  checked: matchesTheWholeCell,
1252
- onChange: (checked) => findReplaceService.changeMatchesTheWholeCell(checked),
1760
+ onChange: (checked) => findReplaceService.changeMatchesTheWholeCell(Boolean(checked)),
1253
1761
  children: localeService.t("find-replace.dialog.match-the-whole-cell")
1254
1762
  }) }),
1255
1763
  capabilities.matchesTheWholeWord && /* @__PURE__ */ jsx(FormLayout, { children: /* @__PURE__ */ jsx(Checkbox, {
1256
1764
  checked: matchesTheWholeWord,
1257
1765
  onChange: (checked) => {
1258
- findReplaceService.changeMatchesTheWholeWord(checked);
1766
+ findReplaceService.changeMatchesTheWholeWord(Boolean(checked));
1259
1767
  if (findCompleted) findReplaceService.find();
1260
1768
  },
1261
1769
  children: localeService.t("find-replace.dialog.match-the-whole-word")
@@ -1384,4 +1892,4 @@ _defineProperty(UniverFindReplacePlugin, "version", version);
1384
1892
  UniverFindReplacePlugin = __decorate([__decorateParam(1, Inject(Injector)), __decorateParam(2, IConfigService)], UniverFindReplacePlugin);
1385
1893
 
1386
1894
  //#endregion
1387
- export { FindBy, FindDirection, FindModel, FindReplaceController, menuSchema as FindReplaceMenuSchema, FindReplaceModel, FindReplaceService, FindReplaceState, FindScope, GoToNextMatchOperation, GoToPreviousMatchOperation, IFindReplaceService, OpenFindDialogOperation, OpenReplaceDialogOperation, ReplaceAllMatchesCommand, ReplaceCurrentMatchCommand, UniverFindReplacePlugin, createInitFindReplaceState };
1895
+ export { CloseFindDialogOperation, FindBy, FindDirection, FindModel, FindReplaceController, menuSchema as FindReplaceMenuSchema, FindReplaceModel, FindReplaceService, FindReplaceState, FindScope, GoToNextMatchOperation, GoToPreviousMatchOperation, IFindReplaceService, OpenFindDialogOperation, OpenReplaceDialogOperation, ReplaceAllMatchesCommand, ReplaceCurrentMatchCommand, UniverFindReplaceMobileUIPlugin, UniverFindReplacePlugin, createInitFindReplaceState };