@lvce-editor/text-search-worker 1.4.0 → 2.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.
@@ -18,6 +18,403 @@ const execute = (command, ...args) => {
18
18
  return fn(...args);
19
19
  };
20
20
 
21
+ const FocusSearchInput = 21;
22
+ const FocusSearchReplaceInput = 31;
23
+ const FocusSearchMatchCase = 32;
24
+ const FocusSearchRegex = 33;
25
+ const FocusSearchWholeWord = 34;
26
+ const FocusSearchReplaceAll = 35;
27
+ const FocusSearchPreserveCase = 36;
28
+
29
+ const focusMatchCase$1 = state => {
30
+ return {
31
+ ...state,
32
+ focus: FocusSearchMatchCase
33
+ };
34
+ };
35
+
36
+ const focusReplaceValue$1 = state => {
37
+ return {
38
+ ...state,
39
+ focus: FocusSearchReplaceInput
40
+ };
41
+ };
42
+
43
+ const focusSearchValue$1 = state => {
44
+ return {
45
+ ...state,
46
+ focus: FocusSearchInput
47
+ };
48
+ };
49
+
50
+ const focusSearchValueNext$1 = state => {
51
+ const {
52
+ replaceExpanded
53
+ } = state;
54
+ if (replaceExpanded) {
55
+ return focusReplaceValue$1(state);
56
+ }
57
+ return focusMatchCase$1(state);
58
+ };
59
+
60
+ const CheckBox = 'checkbox';
61
+ const None = 'none';
62
+ const Status = 'status';
63
+ const Tree = 'tree';
64
+ const TreeItem$1 = 'treeitem';
65
+
66
+ const Chevron = 'Chevron';
67
+ const CloseMaskIcon = 'MaskIcon MaskIconClose';
68
+ const Empty = '';
69
+ const FileIcon = 'FileIcon';
70
+ const FocusOutline = 'FocusOutline';
71
+ const Highlight = 'Highlight';
72
+ const HighlightDeleted = 'HighlightDeleted';
73
+ const HighlightInserted = 'HighlightInserted';
74
+ const Label = 'Label';
75
+ const List = 'List';
76
+ const MaskIcon = 'MaskIcon';
77
+ const MaskIconChevronDown = 'MaskIconChevronDown';
78
+ const MaskIconChevronRight = 'MaskIconChevronRight';
79
+ const MultilineInputBox = 'MultilineInputBox';
80
+ const Search = 'Search';
81
+ const SearchField = 'SearchField';
82
+ const SearchFieldButtons = 'SearchFieldButtons';
83
+ const SearchFieldContainer = 'SearchFieldContainer';
84
+ const SearchHeader = 'SearchHeader';
85
+ const SearchHeaderTop = 'SearchHeaderTop';
86
+ const SearchRemove = 'SearchRemove';
87
+ const SearchToggleButtonExpanded = 'SearchToggleButtonExpanded';
88
+ const SourceControlBadge = 'SourceControlBadge';
89
+ const TreeItem = 'TreeItem';
90
+ const TreeItemActive = 'TreeItemActive';
91
+ const Viewlet = 'Viewlet';
92
+ const ViewletSearchMessage = 'ViewletSearchMessage';
93
+
94
+ const HandleClick = 'handleClick';
95
+ const HandleHeaderClick = 'handleHeaderClick';
96
+ const HandleHeaderFocusIn = 'handleHeaderFocusIn';
97
+ const HandleListBlur = 'handleListBlur';
98
+
99
+ const Button = 1;
100
+ const Div = 4;
101
+ const Input = 6;
102
+ const Span = 8;
103
+ const Text = 12;
104
+ const Img = 17;
105
+ const Ins = 20;
106
+ const Del = 21;
107
+ const TextArea = 62;
108
+
109
+ const getSearchFieldButtonVirtualDom = button => {
110
+ const {
111
+ icon,
112
+ checked,
113
+ title
114
+ } = button;
115
+ return [{
116
+ type: Div,
117
+ className: `SearchFieldButton ${checked ? 'SearchFieldButtonChecked' : ''}`,
118
+ title,
119
+ role: CheckBox,
120
+ ariaChecked: checked,
121
+ tabIndex: 0,
122
+ childCount: 1
123
+ }, {
124
+ type: Div,
125
+ className: `MaskIcon ${icon}`,
126
+ childCount: 0
127
+ }];
128
+ };
129
+
130
+ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, outsideButtons, onFocus = '') => {
131
+ const dom = [{
132
+ type: Div,
133
+ className: SearchField,
134
+ role: None,
135
+ childCount: 2
136
+ }, {
137
+ type: TextArea,
138
+ className: MultilineInputBox,
139
+ spellcheck: false,
140
+ autocapitalize: 'off',
141
+ autocorrect: 'off',
142
+ placeholder,
143
+ name,
144
+ onInput,
145
+ onFocus,
146
+ childCount: 0
147
+ }, {
148
+ type: Div,
149
+ className: SearchFieldButtons,
150
+ childCount: insideButtons.length
151
+ }, ...insideButtons.flatMap(getSearchFieldButtonVirtualDom)];
152
+ if (outsideButtons.length > 0) {
153
+ dom.unshift({
154
+ type: Div,
155
+ className: SearchFieldContainer,
156
+ role: None,
157
+ childCount: 1 + outsideButtons.length
158
+ });
159
+ dom.push(...outsideButtons.flatMap(getSearchFieldButtonVirtualDom));
160
+ }
161
+ return dom;
162
+ };
163
+
164
+ const text = data => {
165
+ return {
166
+ type: Text,
167
+ text: data,
168
+ childCount: 0
169
+ };
170
+ };
171
+
172
+ const getSearchHeaderVirtualDom = (replaceExpanded, matchCase, matchWholeWord, useRegularExpression, detailsExpanded) => {
173
+ const dom = [{
174
+ type: Div,
175
+ className: SearchHeader,
176
+ role: None,
177
+ childCount: 2,
178
+ onClick: HandleHeaderClick,
179
+ onFocusIn: HandleHeaderFocusIn
180
+ }, {
181
+ type: Div,
182
+ className: SearchHeaderTop,
183
+ role: None,
184
+ childCount: 2
185
+ }, {
186
+ type: Button,
187
+ className: `IconButton SearchToggleButton ${replaceExpanded ? SearchToggleButtonExpanded : ''}`,
188
+ title: 'Toggle Replace',
189
+ ariaLabel: 'Toggle Replace',
190
+ ariaExpanded: replaceExpanded,
191
+ childCount: 1,
192
+ 'data-command': 'toggleReplace'
193
+ }, {
194
+ type: Div,
195
+ className: `${MaskIcon} ${replaceExpanded ? MaskIconChevronDown : MaskIconChevronRight}`,
196
+ childCount: 0
197
+ }, {
198
+ type: Div,
199
+ className: 'SearchHeaderTopRight',
200
+ role: None,
201
+ childCount: replaceExpanded ? 2 : 1
202
+ }, ...getSearchFieldVirtualDom('search-value', 'Search', 'handleInput', [{
203
+ icon: 'MaskIconCaseSensitive',
204
+ checked: matchCase,
205
+ title: 'Match Case'
206
+ }, {
207
+ icon: 'MaskIconWholeWord',
208
+ checked: matchWholeWord,
209
+ title: 'Match Whole Word'
210
+ }, {
211
+ icon: 'MaskIconRegex',
212
+ checked: useRegularExpression,
213
+ title: 'Use Regular Expression'
214
+ }], [])];
215
+ if (replaceExpanded) {
216
+ dom.push(...getSearchFieldVirtualDom('search-replace-value', 'Replace', 'handleReplaceInput', [{
217
+ icon: 'MaskIconPreserveCase',
218
+ checked: false,
219
+ title: 'Preserve Case'
220
+ }], [{
221
+ icon: 'MaskIconReplaceAll',
222
+ checked: false,
223
+ title: 'Replace All'
224
+ }]));
225
+ }
226
+ if (detailsExpanded) {
227
+ console.log({
228
+ detailsExpanded
229
+ });
230
+ dom[0].childCount++;
231
+ dom.push({
232
+ type: Div,
233
+ className: 'SearchHeaderDetails',
234
+ childCount: 4
235
+ }, text('files to include'), {
236
+ type: Input,
237
+ childCount: 0
238
+ }, text('files to exclude'), {
239
+ type: Input,
240
+ childCount: 0
241
+ });
242
+ }
243
+ return dom;
244
+ };
245
+
246
+ const getBadgeVirtualDom = (className, count) => {
247
+ return [{
248
+ type: Div,
249
+ className: `Badge ${className}`,
250
+ childCount: 1
251
+ }, text(`${count}`)];
252
+ };
253
+
254
+ const getChevronDownVirtualDom = (extraClassName = '') => {
255
+ return {
256
+ type: Div,
257
+ className: `${Chevron} MaskIconChevronDown ${extraClassName}`,
258
+ childCount: 0
259
+ };
260
+ };
261
+
262
+ const getFileIconVirtualDom = icon => {
263
+ return {
264
+ type: Img,
265
+ className: FileIcon,
266
+ src: icon,
267
+ role: None,
268
+ childCount: 0
269
+ };
270
+ };
271
+
272
+ const File$1 = 1;
273
+ const Match = 2;
274
+
275
+ const PaddingRight = '12px';
276
+
277
+ const deleted = {
278
+ type: Del,
279
+ className: HighlightDeleted,
280
+ childCount: 1
281
+ };
282
+ const inserted = {
283
+ type: Ins,
284
+ className: HighlightInserted,
285
+ childCount: 1
286
+ };
287
+ const highlighted = {
288
+ type: Span,
289
+ className: Highlight,
290
+ childCount: 1
291
+ };
292
+ const getLabelVirtualDom = (displayText, matchLength, matchStart, replacement) => {
293
+ const dom = [];
294
+ const label = {
295
+ type: Div,
296
+ className: Label + ' Grow',
297
+ childCount: 1
298
+ };
299
+ dom.push(label);
300
+ if (matchLength) {
301
+ const before = displayText.slice(0, matchStart);
302
+ const highlight = displayText.slice(matchStart, matchStart + matchLength);
303
+ const after = displayText.slice(matchStart + matchLength);
304
+ if (replacement) {
305
+ dom.push(text(before), deleted, text(highlight), inserted, text(replacement), text(after));
306
+ label.childCount = 4;
307
+ } else {
308
+ label.childCount = 3;
309
+ dom.push(text(before), highlighted, text(highlight), text(after));
310
+ }
311
+ } else {
312
+ dom.push(text(displayText));
313
+ }
314
+ return dom;
315
+ };
316
+ const renderRow = rowInfo => {
317
+ // @ts-ignore
318
+ const {
319
+ top,
320
+ type,
321
+ matchStart,
322
+ matchLength,
323
+ text: displayText,
324
+ title,
325
+ icon,
326
+ setSize,
327
+ posInSet,
328
+ depth,
329
+ replacement,
330
+ matchCount,
331
+ focused
332
+ } = rowInfo;
333
+ const treeItem = {
334
+ type: Div,
335
+ role: TreeItem$1,
336
+ className: TreeItem,
337
+ title,
338
+ ariaSetSize: setSize,
339
+ ariaLevel: depth,
340
+ ariaPosInSet: posInSet,
341
+ ariaLabel: title,
342
+ ariaDescription: '',
343
+ childCount: 1,
344
+ paddingLeft: `${Number(depth) + 1}rem`,
345
+ // TODO use classname and dynamic css
346
+ paddingRight: PaddingRight
347
+ };
348
+ if (focused) {
349
+ treeItem.className += ' ' + TreeItemActive;
350
+ }
351
+ switch (type) {
352
+ case File$1:
353
+ treeItem.ariaExpanded = 'true';
354
+ break;
355
+ }
356
+ const dom = [];
357
+ dom.push(treeItem);
358
+ if (type === File$1) {
359
+ treeItem.childCount += 2;
360
+ dom.push(getChevronDownVirtualDom(), getFileIconVirtualDom(icon));
361
+ }
362
+ dom.push(...getLabelVirtualDom(displayText, matchLength, matchStart, replacement));
363
+ if (matchCount) {
364
+ treeItem.childCount++;
365
+ dom.push(...getBadgeVirtualDom(SourceControlBadge, matchCount));
366
+ }
367
+ treeItem.childCount++;
368
+ dom.push({
369
+ type: Div,
370
+ className: SearchRemove,
371
+ childCount: 1
372
+ }, {
373
+ type: Div,
374
+ className: CloseMaskIcon,
375
+ childCount: 0
376
+ });
377
+ return dom;
378
+ };
379
+ const getSearchResultsVirtualDom = visibleItems => {
380
+ return visibleItems.flatMap(renderRow);
381
+ };
382
+
383
+ const mergeClassNames = (...classNames) => {
384
+ return classNames.filter(Boolean).join(' ');
385
+ };
386
+
387
+ const getSearchVirtualDom = (visibleItems, replaceExpanded, matchCase, matchWholeWord, useRegularExpression, message, detailsExpanded, focusOutline) => {
388
+ /**
389
+ * @type {any[]}
390
+ */
391
+ const dom = [];
392
+ dom.push({
393
+ type: Div,
394
+ className: mergeClassNames(Viewlet, Search),
395
+ childCount: 2
396
+ });
397
+ dom.push(...getSearchHeaderVirtualDom(replaceExpanded, matchCase, matchWholeWord, useRegularExpression, detailsExpanded));
398
+ dom.push({
399
+ type: Div,
400
+ className: ViewletSearchMessage,
401
+ role: Status,
402
+ tabIndex: 0,
403
+ childCount: 1
404
+ }, text(message));
405
+ dom.push({
406
+ type: Div,
407
+ className: mergeClassNames(Viewlet, List, focusOutline ? FocusOutline : Empty),
408
+ role: Tree,
409
+ tabIndex: 0,
410
+ childCount: visibleItems.length,
411
+ onClick: HandleClick,
412
+ onBlur: HandleListBlur
413
+ });
414
+ dom.push(...getSearchResultsVirtualDom(visibleItems));
415
+ return dom;
416
+ };
417
+
21
418
  const state$3 = {
22
419
  /**
23
420
  * @type {any}
@@ -394,51 +791,43 @@ const listen$2 = ipc => {
394
791
  set$1(ipc);
395
792
  };
396
793
 
397
- const FocusSearchInput = 21;
398
- const FocusSearchReplaceInput = 31;
399
- const FocusSearchMatchCase = 32;
400
- const FocusSearchRegex = 33;
401
- const FocusSearchWholeWord = 34;
402
- const FocusSearchReplaceAll = 35;
403
- const FocusSearchPreserveCase = 36;
404
-
405
- const focusSearchValue$1 = state => {
794
+ const focusSearchValue = state => {
406
795
  return {
407
796
  ...state,
408
797
  focus: FocusSearchInput
409
798
  };
410
799
  };
411
- const focusSearchValueNext$1 = state => {
800
+ const focusSearchValueNext = state => {
412
801
  const {
413
802
  replaceExpanded
414
803
  } = state;
415
804
  if (replaceExpanded) {
416
- return focusReplaceValue$1(state);
805
+ return focusReplaceValue(state);
417
806
  }
418
- return focusMatchCase$1(state);
807
+ return focusMatchCase(state);
419
808
  };
420
809
  const focusMatchCasePrevious = state => {
421
810
  const {
422
811
  replaceExpanded
423
812
  } = state;
424
813
  if (replaceExpanded) {
425
- return focusReplaceValue$1(state);
814
+ return focusReplaceValue(state);
426
815
  }
427
- return focusSearchValue$1(state);
816
+ return focusSearchValue(state);
428
817
  };
429
818
  const focusReplaceValueNext = state => {
430
- return focusMatchCase$1(state);
819
+ return focusMatchCase(state);
431
820
  };
432
821
  const focusRegexNext = state => {
433
822
  return focusPreserveCase(state);
434
823
  };
435
- const focusReplaceValue$1 = state => {
824
+ const focusReplaceValue = state => {
436
825
  return {
437
826
  ...state,
438
827
  focus: FocusSearchReplaceInput
439
828
  };
440
829
  };
441
- const focusMatchCase$1 = state => {
830
+ const focusMatchCase = state => {
442
831
  return {
443
832
  ...state,
444
833
  focus: FocusSearchMatchCase
@@ -469,37 +858,6 @@ const focusReplaceAll = state => {
469
858
  };
470
859
  };
471
860
 
472
- const focusMatchCase = state => {
473
- return {
474
- ...state,
475
- focus: FocusSearchMatchCase
476
- };
477
- };
478
-
479
- const focusReplaceValue = state => {
480
- return {
481
- ...state,
482
- focus: FocusSearchReplaceInput
483
- };
484
- };
485
-
486
- const focusSearchValue = state => {
487
- return {
488
- ...state,
489
- focus: FocusSearchInput
490
- };
491
- };
492
-
493
- const focusSearchValueNext = state => {
494
- const {
495
- replaceExpanded
496
- } = state;
497
- if (replaceExpanded) {
498
- return focusReplaceValue(state);
499
- }
500
- return focusMatchCase(state);
501
- };
502
-
503
861
  class AssertionError extends Error {
504
862
  constructor(message) {
505
863
  super(message);
@@ -637,9 +995,6 @@ const splitLines$1 = lines => {
637
995
  return lines.split('\n');
638
996
  };
639
997
 
640
- const File$1 = 1;
641
- const Match = 2;
642
-
643
998
  const textSearchInFile$1 = (file, content, query) => {
644
999
  const results = [];
645
1000
  const lines = splitLines$1(content);
@@ -1192,22 +1547,23 @@ const textSearch = async (root, query, options, assetDir) => {
1192
1547
  };
1193
1548
 
1194
1549
  const commandMap = {
1195
- 'TextSearch.focusMatchCase': focusMatchCase$1,
1550
+ 'SearchView.focusMatchCase': focusMatchCase$1,
1551
+ 'SearchView.focusReplaceValue': focusReplaceValue$1,
1552
+ 'SearchView.focusSearchValue': focusSearchValue$1,
1553
+ 'SearchView.focusSearchValueNext': focusSearchValueNext$1,
1554
+ 'TextSearch.focusMatchCase': focusMatchCase,
1196
1555
  'TextSearch.focusMatchCasePrevious': focusMatchCasePrevious,
1197
1556
  'TextSearch.focusMatchWholeWord': focusMatchWholeWord,
1198
1557
  'TextSearch.focusPreserveCase': focusPreserveCase,
1199
1558
  'TextSearch.focusRegex': focusRegex,
1200
1559
  'TextSearch.focusRegexNext': focusRegexNext,
1201
1560
  'TextSearch.focusReplaceAll': focusReplaceAll,
1202
- 'TextSearch.focusReplaceValue': focusReplaceValue$1,
1561
+ 'TextSearch.focusReplaceValue': focusReplaceValue,
1203
1562
  'TextSearch.focusReplaceValueNext': focusReplaceValueNext,
1204
- 'TextSearch.focusSearchValue': focusSearchValue$1,
1205
- 'TextSearch.focusSearchValueNext': focusSearchValueNext$1,
1206
- 'TextSearch.textSearch': textSearch,
1207
- 'SearchView.focusReplaceValue': focusReplaceValue,
1208
- 'SearchView.focusMatchCase': focusMatchCase,
1209
- 'SearchView.focusSearchValue': focusSearchValue,
1210
- 'SearchView.focusSearchValueNext': focusSearchValueNext
1563
+ 'TextSearch.focusSearchValue': focusSearchValue,
1564
+ 'TextSearch.focusSearchValueNext': focusSearchValueNext,
1565
+ 'TextSearch.getVirtualDom': getSearchVirtualDom,
1566
+ 'TextSearch.textSearch': textSearch
1211
1567
  };
1212
1568
 
1213
1569
  const requiresSocket = () => {
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "1.4.0",
3
+ "version": "2.0.0",
4
4
  "description": "",
5
5
  "main": "dist/textSearchWorkerMain.js",
6
6
  "type": "module",
7
- "keywords": [],
8
- "author": "",
7
+ "keywords": [
8
+ "text-search"
9
+ ],
10
+ "author": "Lvce Editor",
9
11
  "license": "MIT"
10
12
  }