@lvce-editor/text-search-worker 2.0.0 → 2.1.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.
@@ -62,11 +62,14 @@ const None = 'none';
62
62
  const Status = 'status';
63
63
  const Tree = 'tree';
64
64
  const TreeItem$1 = 'treeitem';
65
+ const ToolBar = 'toolbar';
65
66
 
66
67
  const Chevron = 'Chevron';
67
68
  const CloseMaskIcon = 'MaskIcon MaskIconClose';
68
69
  const Empty = '';
69
70
  const FileIcon = 'FileIcon';
71
+ const IconButton = 'IconButton';
72
+ const Actions = 'Actions';
70
73
  const FocusOutline = 'FocusOutline';
71
74
  const Highlight = 'Highlight';
72
75
  const HighlightDeleted = 'HighlightDeleted';
@@ -91,10 +94,7 @@ const TreeItemActive = 'TreeItemActive';
91
94
  const Viewlet = 'Viewlet';
92
95
  const ViewletSearchMessage = 'ViewletSearchMessage';
93
96
 
94
- const HandleClick = 'handleClick';
95
- const HandleHeaderClick = 'handleHeaderClick';
96
- const HandleHeaderFocusIn = 'handleHeaderFocusIn';
97
- const HandleListBlur = 'handleListBlur';
97
+ const Button$1 = 1;
98
98
 
99
99
  const Button = 1;
100
100
  const Div = 4;
@@ -106,6 +106,180 @@ const Ins = 20;
106
106
  const Del = 21;
107
107
  const TextArea = 62;
108
108
 
109
+ const getIconVirtualDom = (icon, type = Div) => {
110
+ return {
111
+ type,
112
+ className: `MaskIcon MaskIcon${icon}`,
113
+ role: None,
114
+ childCount: 0
115
+ };
116
+ };
117
+
118
+ const getActionButtonVirtualDom = action => {
119
+ const {
120
+ id,
121
+ icon,
122
+ command
123
+ } = action;
124
+ return [{
125
+ type: Button,
126
+ className: IconButton,
127
+ title: id,
128
+ 'data-command': command,
129
+ childCount: 1
130
+ }, getIconVirtualDom(icon)];
131
+ };
132
+
133
+ const getActionVirtualDom = action => {
134
+ switch (action.type) {
135
+ case Button$1:
136
+ return getActionButtonVirtualDom(action);
137
+ default:
138
+ return [];
139
+ }
140
+ };
141
+
142
+ const getActionsVirtualDom = actions => {
143
+ return [{
144
+ type: Div,
145
+ className: Actions,
146
+ role: ToolBar,
147
+ childCount: actions.length
148
+ }, ...actions.flatMap(getActionVirtualDom)];
149
+ };
150
+
151
+ const ClearAll = 'ClearAll';
152
+ const CollapseAll = 'CollapseAll';
153
+ const ListFlat = 'ListFlat';
154
+ const NewFile = 'NewFile';
155
+ const Refresh = 'Refresh';
156
+
157
+ let AssertionError$1 = class AssertionError extends Error {
158
+ constructor(message) {
159
+ super(message);
160
+ this.name = 'AssertionError';
161
+ }
162
+ };
163
+ const getType$1 = value => {
164
+ switch (typeof value) {
165
+ case 'number':
166
+ return 'number';
167
+ case 'function':
168
+ return 'function';
169
+ case 'string':
170
+ return 'string';
171
+ case 'object':
172
+ if (value === null) {
173
+ return 'null';
174
+ }
175
+ if (Array.isArray(value)) {
176
+ return 'array';
177
+ }
178
+ return 'object';
179
+ case 'boolean':
180
+ return 'boolean';
181
+ default:
182
+ return 'unknown';
183
+ }
184
+ };
185
+ const string = value => {
186
+ const type = getType$1(value);
187
+ if (type !== 'string') {
188
+ throw new AssertionError$1('expected value to be of type string');
189
+ }
190
+ };
191
+
192
+ const emptyObject = {};
193
+ const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
194
+ const i18nString = (key, placeholders = emptyObject) => {
195
+ if (placeholders === emptyObject) {
196
+ return key;
197
+ }
198
+ const replacer = (match, rest) => {
199
+ // @ts-ignore
200
+ return placeholders[rest];
201
+ };
202
+ return key.replaceAll(RE_PLACEHOLDER, replacer);
203
+ };
204
+
205
+ /**
206
+ * @enum {string}
207
+ */
208
+ const UiStrings = {
209
+ NoResults: 'No results found',
210
+ Oneresult: '1 result in 1 file',
211
+ ManyResultsInOneFile: '{PH1} results in 1 file',
212
+ ManyResultsInManyFiles: '{PH1} results in {PH2} files',
213
+ ReplaceAll: 'Replace All',
214
+ Replace: 'Replace',
215
+ ConfirmReplaceAll: 'Replace All?',
216
+ ConfirmReplaceOneOccurrenceInOneFile: "Replace 1 occurrence across 1 file with '{PH1}'",
217
+ ConfirmReplaceOneOccurrenceInOneFileNoValue: 'Replace 1 occurrence across 1 file',
218
+ ConfirmReplaceManyOccurrencesInOneFile: "Replace {PH1} occurrences across 1 file with '{PH2}'",
219
+ ConfirmReplaceManyOccurrencesInOneFileNoValue: 'Replace {PH1} occurrences across 1 file',
220
+ ConfirmReplaceManyOccurrencesInManyFiles: "Replace {PH1} occurrences across {PH2} files with '{PH3}'",
221
+ ConfirmReplaceManyOccurrencesInManyFilesNoValue: 'Replace {PH1} occurrences across {PH2} files',
222
+ ReplacedOneOccurrenceInOneFile: "Replaced 1 occurrence across 1 file with '{PH1}'",
223
+ ReplacedManyOccurrencesInOneFile: "Replaced {PH1} occurrences across 1 file with '{PH2}'",
224
+ ReplacedManyOccurrencesInManyFiles: "Replaced {PH1} occurrences across {PH2} files with '{PH3}'",
225
+ CopyPath: 'Copy Path',
226
+ Dismiss: 'Dismiss',
227
+ Refresh: 'Refresh',
228
+ ClearSearchResults: 'Clear Search Results',
229
+ OpenNewSearchEditor: 'Open New Search Editor',
230
+ ViewAsTree: 'View as Tree',
231
+ CollapseAll: 'Collapse All'
232
+ };
233
+ const refresh = () => {
234
+ return i18nString(UiStrings.Refresh);
235
+ };
236
+ const clearSearchResults = () => {
237
+ return i18nString(UiStrings.ClearSearchResults);
238
+ };
239
+ const openNewSearchEditor = () => {
240
+ return i18nString(UiStrings.OpenNewSearchEditor);
241
+ };
242
+ const viewAsTree = () => {
243
+ return i18nString(UiStrings.ViewAsTree);
244
+ };
245
+ const collapseAll = () => {
246
+ return i18nString(UiStrings.CollapseAll);
247
+ };
248
+
249
+ const getActions = () => {
250
+ return [{
251
+ type: Button$1,
252
+ id: refresh(),
253
+ icon: Refresh,
254
+ command: 'refresh'
255
+ }, {
256
+ type: Button$1,
257
+ id: clearSearchResults(),
258
+ icon: ClearAll,
259
+ command: 'clearSearchResults'
260
+ }, {
261
+ type: Button$1,
262
+ id: openNewSearchEditor(),
263
+ icon: NewFile,
264
+ command: ''
265
+ }, {
266
+ type: Button$1,
267
+ id: viewAsTree(),
268
+ icon: ListFlat,
269
+ command: ''
270
+ }, {
271
+ type: Button$1,
272
+ id: collapseAll(),
273
+ icon: CollapseAll,
274
+ command: ''
275
+ }];
276
+ };
277
+
278
+ const HandleClick = 'handleClick';
279
+ const HandleHeaderClick = 'handleHeaderClick';
280
+ const HandleHeaderFocusIn = 'handleHeaderFocusIn';
281
+ const HandleListBlur = 'handleListBlur';
282
+
109
283
  const getSearchFieldButtonVirtualDom = button => {
110
284
  const {
111
285
  icon,
@@ -429,13 +603,13 @@ const set$1 = ipc => {
429
603
  };
430
604
 
431
605
  const Two = '2.0';
432
- let AssertionError$1 = class AssertionError extends Error {
606
+ class AssertionError extends Error {
433
607
  constructor(message) {
434
608
  super(message);
435
609
  this.name = 'AssertionError';
436
610
  }
437
- };
438
- const getType$1 = value => {
611
+ }
612
+ const getType = value => {
439
613
  switch (typeof value) {
440
614
  case 'number':
441
615
  return 'number';
@@ -458,9 +632,9 @@ const getType$1 = value => {
458
632
  }
459
633
  };
460
634
  const number = value => {
461
- const type = getType$1(value);
635
+ const type = getType(value);
462
636
  if (type !== 'number') {
463
- throw new AssertionError$1('expected value to be of type number');
637
+ throw new AssertionError('expected value to be of type number');
464
638
  }
465
639
  };
466
640
  const state$1 = {
@@ -858,41 +1032,6 @@ const focusReplaceAll = state => {
858
1032
  };
859
1033
  };
860
1034
 
861
- class AssertionError extends Error {
862
- constructor(message) {
863
- super(message);
864
- this.name = 'AssertionError';
865
- }
866
- }
867
- const getType = value => {
868
- switch (typeof value) {
869
- case 'number':
870
- return 'number';
871
- case 'function':
872
- return 'function';
873
- case 'string':
874
- return 'string';
875
- case 'object':
876
- if (value === null) {
877
- return 'null';
878
- }
879
- if (Array.isArray(value)) {
880
- return 'array';
881
- }
882
- return 'object';
883
- case 'boolean':
884
- return 'boolean';
885
- default:
886
- return 'unknown';
887
- }
888
- };
889
- const string = value => {
890
- const type = getType(value);
891
- if (type !== 'string') {
892
- throw new AssertionError('expected value to be of type string');
893
- }
894
- };
895
-
896
1035
  const RE_PROTOCOL = /^([a-z\-]+):\/\//;
897
1036
  const getProtocol = uri => {
898
1037
  const protocolMatch = uri.match(RE_PROTOCOL);
@@ -1562,6 +1701,8 @@ const commandMap = {
1562
1701
  'TextSearch.focusReplaceValueNext': focusReplaceValueNext,
1563
1702
  'TextSearch.focusSearchValue': focusSearchValue,
1564
1703
  'TextSearch.focusSearchValueNext': focusSearchValueNext,
1704
+ 'TextSearch.getActions': getActions,
1705
+ 'TextSearch.getActionsVirtualDom': getActionsVirtualDom,
1565
1706
  'TextSearch.getVirtualDom': getSearchVirtualDom,
1566
1707
  'TextSearch.textSearch': textSearch
1567
1708
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "main": "dist/textSearchWorkerMain.js",
6
6
  "type": "module",