@lvce-editor/text-search-worker 2.0.0 → 2.2.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,289 @@ 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 getFileIcon = () => {
279
+ return '';
280
+ };
281
+
282
+ const File$1 = 1;
283
+ const Match = 2;
284
+
285
+ // TODO this should be in FileSystem module
286
+ const pathBaseName = path => {
287
+ return path.slice(path.lastIndexOf('/') + 1);
288
+ };
289
+ const getAbsolutePath = relativePath => {
290
+ if (relativePath.startsWith('./')) {
291
+ return `/${relativePath.slice(2)}`; // TODO support windows paths
292
+ }
293
+ return `/${relativePath}`; // TODO support windows paths
294
+ };
295
+
296
+ const getDisplayResult = (result, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex) => {
297
+ const {
298
+ type,
299
+ text,
300
+ lineNumber,
301
+ start
302
+ } = result;
303
+ const posInSet = i + 1;
304
+ const top = i * itemHeight;
305
+ const focused = i === focusedIndex;
306
+ switch (type) {
307
+ case File$1:
308
+ const path = text;
309
+ const absolutePath = getAbsolutePath(path);
310
+ const baseName = pathBaseName(path);
311
+ return {
312
+ title: absolutePath,
313
+ type: File$1,
314
+ text: baseName,
315
+ icon: getFileIcon(),
316
+ posInSet,
317
+ setSize,
318
+ top,
319
+ lineNumber,
320
+ matchStart: 0,
321
+ matchLength: 0,
322
+ replacement: '',
323
+ depth: 0,
324
+ matchCount: 0,
325
+ focused
326
+ };
327
+ case Match:
328
+ return {
329
+ title: text,
330
+ type: Match,
331
+ text: text,
332
+ icon: '',
333
+ posInSet,
334
+ setSize,
335
+ top,
336
+ lineNumber,
337
+ matchStart: start,
338
+ matchLength: searchTermLength,
339
+ replacement,
340
+ depth: 1,
341
+ matchCount: 0,
342
+ focused
343
+ };
344
+ default:
345
+ throw new Error('unexpected search result type');
346
+ }
347
+ };
348
+
349
+ const getFilteredResults = (results, collapsedPaths) => {
350
+ const filteredResults = [];
351
+ let isExcluded = false;
352
+ for (const result of results) {
353
+ if (result.type === File$1) {
354
+ if (collapsedPaths.includes(result.text)) {
355
+ isExcluded = true;
356
+ } else {
357
+ isExcluded = false;
358
+ }
359
+ }
360
+ if (!isExcluded) {
361
+ filteredResults.push(result);
362
+ }
363
+ }
364
+ return filteredResults;
365
+ };
366
+ const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLineY, maxLineY, replacement, collapsedPaths, focusedIndex) => {
367
+ const displayResults = [];
368
+ const filteredResults = getFilteredResults(results, collapsedPaths);
369
+ const setSize = resultCount;
370
+ const searchTermLength = searchTerm.length;
371
+ let fileResult = {
372
+ matchCount: 0
373
+ };
374
+ for (let i = minLineY; i < maxLineY; i++) {
375
+ const result = filteredResults[i];
376
+ const displayResult = getDisplayResult(result, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex);
377
+ displayResults.push(displayResult);
378
+ if (result.type === File$1) {
379
+ fileResult = displayResult;
380
+ } else {
381
+ fileResult.matchCount++;
382
+ }
383
+ }
384
+ return displayResults;
385
+ };
386
+
387
+ const HandleClick = 'handleClick';
388
+ const HandleHeaderClick = 'handleHeaderClick';
389
+ const HandleHeaderFocusIn = 'handleHeaderFocusIn';
390
+ const HandleListBlur = 'handleListBlur';
391
+
109
392
  const getSearchFieldButtonVirtualDom = button => {
110
393
  const {
111
394
  icon,
@@ -269,11 +552,6 @@ const getFileIconVirtualDom = icon => {
269
552
  };
270
553
  };
271
554
 
272
- const File$1 = 1;
273
- const Match = 2;
274
-
275
- const PaddingRight = '12px';
276
-
277
555
  const deleted = {
278
556
  type: Del,
279
557
  className: HighlightDeleted,
@@ -313,10 +591,11 @@ const getLabelVirtualDom = (displayText, matchLength, matchStart, replacement) =
313
591
  }
314
592
  return dom;
315
593
  };
316
- const renderRow = rowInfo => {
317
- // @ts-ignore
594
+
595
+ const PaddingRight = '12px';
596
+
597
+ const getSearchResultVirtualDom = rowInfo => {
318
598
  const {
319
- top,
320
599
  type,
321
600
  matchStart,
322
601
  matchLength,
@@ -376,8 +655,9 @@ const renderRow = rowInfo => {
376
655
  });
377
656
  return dom;
378
657
  };
658
+
379
659
  const getSearchResultsVirtualDom = visibleItems => {
380
- return visibleItems.flatMap(renderRow);
660
+ return visibleItems.flatMap(getSearchResultVirtualDom);
381
661
  };
382
662
 
383
663
  const mergeClassNames = (...classNames) => {
@@ -429,13 +709,13 @@ const set$1 = ipc => {
429
709
  };
430
710
 
431
711
  const Two = '2.0';
432
- let AssertionError$1 = class AssertionError extends Error {
712
+ class AssertionError extends Error {
433
713
  constructor(message) {
434
714
  super(message);
435
715
  this.name = 'AssertionError';
436
716
  }
437
- };
438
- const getType$1 = value => {
717
+ }
718
+ const getType = value => {
439
719
  switch (typeof value) {
440
720
  case 'number':
441
721
  return 'number';
@@ -458,9 +738,9 @@ const getType$1 = value => {
458
738
  }
459
739
  };
460
740
  const number = value => {
461
- const type = getType$1(value);
741
+ const type = getType(value);
462
742
  if (type !== 'number') {
463
- throw new AssertionError$1('expected value to be of type number');
743
+ throw new AssertionError('expected value to be of type number');
464
744
  }
465
745
  };
466
746
  const state$1 = {
@@ -858,41 +1138,6 @@ const focusReplaceAll = state => {
858
1138
  };
859
1139
  };
860
1140
 
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
1141
  const RE_PROTOCOL = /^([a-z\-]+):\/\//;
897
1142
  const getProtocol = uri => {
898
1143
  const protocolMatch = uri.match(RE_PROTOCOL);
@@ -1379,11 +1624,6 @@ const isNotReadableError = error => {
1379
1624
  return error && error.name === NotReadableError;
1380
1625
  };
1381
1626
 
1382
- /**
1383
- *
1384
- * @param {FileSystemFileHandle} handle
1385
- * @returns
1386
- */
1387
1627
  const getFile = handle => {
1388
1628
  return handle.getFile();
1389
1629
  };
@@ -1456,7 +1696,6 @@ const textSearch$3 = async (scheme, root, query) => {
1456
1696
  const relativeRoot = root.slice('html://'.length);
1457
1697
  const handle = await getDirectoryHandle(relativeRoot);
1458
1698
  if (!handle) {
1459
- // @ts-ignore
1460
1699
  throw new VError$1(`Folder not found ${relativeRoot}`);
1461
1700
  }
1462
1701
  const all = [];
@@ -1562,6 +1801,9 @@ const commandMap = {
1562
1801
  'TextSearch.focusReplaceValueNext': focusReplaceValueNext,
1563
1802
  'TextSearch.focusSearchValue': focusSearchValue,
1564
1803
  'TextSearch.focusSearchValueNext': focusSearchValueNext,
1804
+ 'TextSearch.getActions': getActions,
1805
+ 'TextSearch.getActionsVirtualDom': getActionsVirtualDom,
1806
+ 'TextSearch.getSearchDisplayResults': getDisplayResults,
1565
1807
  'TextSearch.getVirtualDom': getSearchVirtualDom,
1566
1808
  'TextSearch.textSearch': textSearch
1567
1809
  };
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.2.0",
4
4
  "description": "",
5
5
  "main": "dist/textSearchWorkerMain.js",
6
6
  "type": "module",