@lvce-editor/text-search-worker 2.4.0 → 2.5.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.
@@ -86,7 +86,7 @@ const set$1 = (id, fn) => {
86
86
  const get$1 = id => {
87
87
  return state$1.callbacks[id];
88
88
  };
89
- const remove = id => {
89
+ const remove$1 = id => {
90
90
  delete state$1.callbacks[id];
91
91
  };
92
92
  const state$2 = {
@@ -119,7 +119,7 @@ const resolve = (id, args) => {
119
119
  return;
120
120
  }
121
121
  fn(args);
122
- remove(id);
122
+ remove$1(id);
123
123
  };
124
124
  const create$2 = (method, params) => {
125
125
  const {
@@ -505,133 +505,35 @@ const create = (uid, x, y, width, height, workspacePath) => {
505
505
  set(uid, state);
506
506
  };
507
507
 
508
- const focusMatchCase$1 = state => {
509
- return {
510
- ...state,
511
- focus: FocusSearchMatchCase
512
- };
513
- };
514
-
515
- const focusReplaceValue$1 = state => {
516
- return {
517
- ...state,
518
- focus: FocusSearchReplaceInput
519
- };
520
- };
521
-
522
- const focusSearchValue$1 = state => {
523
- return {
524
- ...state,
525
- focus: FocusSearchInput
526
- };
527
- };
508
+ // based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
528
509
 
529
- const focusSearchValueNext$1 = state => {
530
- const {
531
- replaceExpanded
532
- } = state;
533
- if (replaceExpanded) {
534
- return focusReplaceValue$1(state);
510
+ const insertInto = (array, start, newItems) => {
511
+ const originalLength = array.length;
512
+ const newItemsLength = newItems.length;
513
+ array.length = originalLength + newItemsLength;
514
+ // Move the items after the start index, start from the end so that we don't overwrite any value.
515
+ for (let i = originalLength - 1; i >= start; i--) {
516
+ array[i + newItemsLength] = array[i];
517
+ }
518
+ for (let i = 0; i < newItemsLength; i++) {
519
+ array[i + start] = newItems[i];
535
520
  }
536
- return focusMatchCase$1(state);
537
521
  };
538
-
539
- const CheckBox = 'checkbox';
540
- const None = 'none';
541
- const Status = 'status';
542
- const Tree = 'tree';
543
- const TreeItem$1 = 'treeitem';
544
- const ToolBar = 'toolbar';
545
-
546
- const Chevron = 'Chevron';
547
- const CloseMaskIcon = 'MaskIcon MaskIconClose';
548
- const Empty = '';
549
- const FileIcon = 'FileIcon';
550
- const IconButton = 'IconButton';
551
- const Actions = 'Actions';
552
- const FocusOutline = 'FocusOutline';
553
- const Highlight = 'Highlight';
554
- const HighlightDeleted = 'HighlightDeleted';
555
- const HighlightInserted = 'HighlightInserted';
556
- const Label = 'Label';
557
- const List = 'List';
558
- const MaskIcon = 'MaskIcon';
559
- const MaskIconChevronDown = 'MaskIconChevronDown';
560
- const MaskIconChevronRight = 'MaskIconChevronRight';
561
- const MultilineInputBox = 'MultilineInputBox';
562
- const Search$1 = 'Search';
563
- const SearchField = 'SearchField';
564
- const SearchFieldButtons = 'SearchFieldButtons';
565
- const SearchFieldContainer = 'SearchFieldContainer';
566
- const SearchHeader = 'SearchHeader';
567
- const SearchHeaderTop = 'SearchHeaderTop';
568
- const SearchRemove = 'SearchRemove';
569
- const SearchToggleButtonExpanded = 'SearchToggleButtonExpanded';
570
- const SourceControlBadge = 'SourceControlBadge';
571
- const TreeItem = 'TreeItem';
572
- const TreeItemActive = 'TreeItemActive';
573
- const Viewlet = 'Viewlet';
574
- const ViewletSearchMessage = 'ViewletSearchMessage';
575
-
576
- const Button$1 = 1;
577
-
578
- const Button = 1;
579
- const Div = 4;
580
- const Input = 6;
581
- const Span = 8;
582
- const Text = 12;
583
- const Img = 17;
584
- const Ins = 20;
585
- const Del = 21;
586
- const TextArea = 62;
587
-
588
- const getIconVirtualDom = (icon, type = Div) => {
589
- return {
590
- type,
591
- className: `MaskIcon MaskIcon${icon}`,
592
- role: None,
593
- childCount: 0
594
- };
522
+ const push = (array, newItems) => {
523
+ insertInto(array, array.length, newItems);
595
524
  };
596
-
597
- const getActionButtonVirtualDom = action => {
598
- const {
599
- id,
600
- icon,
601
- command
602
- } = action;
603
- return [{
604
- type: Button,
605
- className: IconButton,
606
- title: id,
607
- 'data-command': command,
608
- childCount: 1
609
- }, getIconVirtualDom(icon)];
525
+ const isLastIndex = (array, index) => {
526
+ return index === array.length - 1;
610
527
  };
611
-
612
- const getActionVirtualDom = action => {
613
- switch (action.type) {
614
- case Button$1:
615
- return getActionButtonVirtualDom(action);
616
- default:
617
- return [];
618
- }
528
+ const lastIndex = array => {
529
+ return array.length - 1;
619
530
  };
620
-
621
- const getActionsVirtualDom = actions => {
622
- return [{
623
- type: Div,
624
- className: Actions,
625
- role: ToolBar,
626
- childCount: actions.length
627
- }, ...actions.flatMap(getActionVirtualDom)];
531
+ const toSpliced = (array, index, deleteCount, ...inserted) => {
532
+ return [...array.slice(0, index), ...inserted, ...array.slice(index + deleteCount)];
533
+ };
534
+ const remove = (array, index, deleteCount) => {
535
+ return toSpliced(array, index, deleteCount);
628
536
  };
629
-
630
- const ClearAll = 'ClearAll';
631
- const CollapseAll = 'CollapseAll';
632
- const ListFlat = 'ListFlat';
633
- const NewFile = 'NewFile';
634
- const Refresh = 'Refresh';
635
537
 
636
538
  class AssertionError extends Error {
637
539
  constructor(message) {
@@ -754,6 +656,279 @@ const collapseAll = () => {
754
656
  return i18nString(UiStrings.CollapseAll);
755
657
  };
756
658
 
659
+ const getStatusMessage = (resultCount, fileResultCount) => {
660
+ number(resultCount);
661
+ number(fileResultCount);
662
+ if (resultCount === 0) {
663
+ return noResults();
664
+ }
665
+ if (resultCount === 1) {
666
+ return oneResult();
667
+ }
668
+ if (fileResultCount === 1) {
669
+ return manyResultsInOneFile(resultCount);
670
+ }
671
+ return manyResultsInManyFiles(resultCount, fileResultCount);
672
+ };
673
+
674
+ const File$1 = 1;
675
+ const Match = 2;
676
+
677
+ const getSetSize = (items, index) => {
678
+ let setSize = 0;
679
+ for (let i = index + 1; i < items.length; i++) {
680
+ if (items[i].type === File$1) {
681
+ break;
682
+ }
683
+ setSize++;
684
+ }
685
+ return setSize;
686
+ };
687
+ const getRemoveIndicesFile = (items, item, index, matchCount, fileCount) => {
688
+ const setSize = getSetSize(items, index);
689
+ return {
690
+ startIndex: index,
691
+ removeCount: setSize + 1,
692
+ newFocusedIndex: index + setSize + 1 < items.length ? index : index - 1,
693
+ newFileCount: fileCount - 1,
694
+ newMatchCount: matchCount - setSize
695
+ };
696
+ };
697
+ const getRemoveIndicesMatch = (items, index, matchCount, fileCount) => {
698
+ for (let i = index; i >= 0; i--) {
699
+ if (items[i].type === File$1) {
700
+ const setSize = getSetSize(items, i);
701
+ if (setSize === 1) {
702
+ return {
703
+ startIndex: i,
704
+ removeCount: 2,
705
+ newFocusedIndex: i - 1,
706
+ newFileCount: fileCount - 1,
707
+ newMatchCount: matchCount - 1
708
+ };
709
+ }
710
+ return {
711
+ startIndex: index,
712
+ removeCount: 1,
713
+ newFocusedIndex: index,
714
+ newFileCount: fileCount,
715
+ newMatchCount: matchCount - 1
716
+ };
717
+ }
718
+ }
719
+ throw new Error('could not compute indices to remove');
720
+ };
721
+ const getRemoveIndices = (items, index, matchCount, fileCount) => {
722
+ const item = items[index];
723
+ switch (item.type) {
724
+ case File$1:
725
+ return getRemoveIndicesFile(items, item, index, matchCount, fileCount);
726
+ case Match:
727
+ return getRemoveIndicesMatch(items, index, matchCount, fileCount);
728
+ default:
729
+ throw new Error('unknown search result type');
730
+ }
731
+ };
732
+ const removeItemFromItems = (items, index, matchCount, fileCount) => {
733
+ const {
734
+ startIndex,
735
+ removeCount,
736
+ newFocusedIndex,
737
+ newFileCount,
738
+ newMatchCount
739
+ } = getRemoveIndices(items, index, matchCount, fileCount);
740
+ const newItems = remove(items, startIndex, removeCount);
741
+ return {
742
+ newItems,
743
+ newFocusedIndex,
744
+ newFileCount,
745
+ newMatchCount
746
+ };
747
+ };
748
+ const getNewMinMax = (newItemsLength, minLineY, maxLineY, deltaY, itemHeight) => {
749
+ if (maxLineY > newItemsLength) {
750
+ const diff = maxLineY - minLineY;
751
+ const newMinLineY = Math.max(newItemsLength - diff, 0);
752
+ const newDeltaY = newMinLineY * itemHeight;
753
+ return {
754
+ newDeltaY,
755
+ newMinLineY,
756
+ newMaxLineY: newItemsLength
757
+ };
758
+ }
759
+ return {
760
+ newDeltaY: deltaY,
761
+ newMinLineY: minLineY,
762
+ newMaxLineY: maxLineY
763
+ };
764
+ };
765
+ const dismissItem = state => {
766
+ const {
767
+ items,
768
+ listFocusedIndex,
769
+ fileCount,
770
+ matchCount,
771
+ minLineY,
772
+ maxLineY,
773
+ deltaY,
774
+ itemHeight
775
+ } = state;
776
+ if (listFocusedIndex === -1) {
777
+ return state;
778
+ }
779
+ const {
780
+ newItems,
781
+ newFocusedIndex,
782
+ newMatchCount,
783
+ newFileCount
784
+ } = removeItemFromItems(items, listFocusedIndex, matchCount, fileCount);
785
+ const message = getStatusMessage(newMatchCount, newFileCount);
786
+ const {
787
+ newMinLineY,
788
+ newMaxLineY,
789
+ newDeltaY
790
+ } = getNewMinMax(newItems.length, minLineY, maxLineY, deltaY, itemHeight);
791
+ return {
792
+ ...state,
793
+ items: newItems,
794
+ listFocusedIndex: newFocusedIndex,
795
+ message,
796
+ matchCount: newMatchCount,
797
+ fileCount: newFileCount,
798
+ minLineY: newMinLineY,
799
+ maxLineY: newMaxLineY,
800
+ deltaY: newDeltaY
801
+ };
802
+ };
803
+
804
+ const focusMatchCase$1 = state => {
805
+ return {
806
+ ...state,
807
+ focus: FocusSearchMatchCase
808
+ };
809
+ };
810
+
811
+ const focusReplaceValue$1 = state => {
812
+ return {
813
+ ...state,
814
+ focus: FocusSearchReplaceInput
815
+ };
816
+ };
817
+
818
+ const focusSearchValue$1 = state => {
819
+ return {
820
+ ...state,
821
+ focus: FocusSearchInput
822
+ };
823
+ };
824
+
825
+ const focusSearchValueNext$1 = state => {
826
+ const {
827
+ replaceExpanded
828
+ } = state;
829
+ if (replaceExpanded) {
830
+ return focusReplaceValue$1(state);
831
+ }
832
+ return focusMatchCase$1(state);
833
+ };
834
+
835
+ const CheckBox = 'checkbox';
836
+ const None = 'none';
837
+ const Status = 'status';
838
+ const Tree = 'tree';
839
+ const TreeItem$1 = 'treeitem';
840
+ const ToolBar = 'toolbar';
841
+
842
+ const Chevron = 'Chevron';
843
+ const CloseMaskIcon = 'MaskIcon MaskIconClose';
844
+ const Empty = '';
845
+ const FileIcon = 'FileIcon';
846
+ const IconButton = 'IconButton';
847
+ const Actions = 'Actions';
848
+ const FocusOutline = 'FocusOutline';
849
+ const Highlight = 'Highlight';
850
+ const HighlightDeleted = 'HighlightDeleted';
851
+ const HighlightInserted = 'HighlightInserted';
852
+ const Label = 'Label';
853
+ const List = 'List';
854
+ const MaskIcon = 'MaskIcon';
855
+ const MaskIconChevronDown = 'MaskIconChevronDown';
856
+ const MaskIconChevronRight = 'MaskIconChevronRight';
857
+ const MultilineInputBox = 'MultilineInputBox';
858
+ const Search$1 = 'Search';
859
+ const SearchField = 'SearchField';
860
+ const SearchFieldButtons = 'SearchFieldButtons';
861
+ const SearchFieldContainer = 'SearchFieldContainer';
862
+ const SearchHeader = 'SearchHeader';
863
+ const SearchHeaderTop = 'SearchHeaderTop';
864
+ const SearchRemove = 'SearchRemove';
865
+ const SearchToggleButtonExpanded = 'SearchToggleButtonExpanded';
866
+ const SourceControlBadge = 'SourceControlBadge';
867
+ const TreeItem = 'TreeItem';
868
+ const TreeItemActive = 'TreeItemActive';
869
+ const Viewlet = 'Viewlet';
870
+ const ViewletSearchMessage = 'ViewletSearchMessage';
871
+
872
+ const Button$1 = 1;
873
+
874
+ const Button = 1;
875
+ const Div = 4;
876
+ const Input = 6;
877
+ const Span = 8;
878
+ const Text = 12;
879
+ const Img = 17;
880
+ const Ins = 20;
881
+ const Del = 21;
882
+ const TextArea = 62;
883
+
884
+ const getIconVirtualDom = (icon, type = Div) => {
885
+ return {
886
+ type,
887
+ className: `MaskIcon MaskIcon${icon}`,
888
+ role: None,
889
+ childCount: 0
890
+ };
891
+ };
892
+
893
+ const getActionButtonVirtualDom = action => {
894
+ const {
895
+ id,
896
+ icon,
897
+ command
898
+ } = action;
899
+ return [{
900
+ type: Button,
901
+ className: IconButton,
902
+ title: id,
903
+ 'data-command': command,
904
+ childCount: 1
905
+ }, getIconVirtualDom(icon)];
906
+ };
907
+
908
+ const getActionVirtualDom = action => {
909
+ switch (action.type) {
910
+ case Button$1:
911
+ return getActionButtonVirtualDom(action);
912
+ default:
913
+ return [];
914
+ }
915
+ };
916
+
917
+ const getActionsVirtualDom = actions => {
918
+ return [{
919
+ type: Div,
920
+ className: Actions,
921
+ role: ToolBar,
922
+ childCount: actions.length
923
+ }, ...actions.flatMap(getActionVirtualDom)];
924
+ };
925
+
926
+ const ClearAll = 'ClearAll';
927
+ const CollapseAll = 'CollapseAll';
928
+ const ListFlat = 'ListFlat';
929
+ const NewFile = 'NewFile';
930
+ const Refresh = 'Refresh';
931
+
757
932
  const getActions = () => {
758
933
  return [{
759
934
  type: Button$1,
@@ -787,9 +962,6 @@ const getFileIcon = () => {
787
962
  return '';
788
963
  };
789
964
 
790
- const File$1 = 1;
791
- const Match = 2;
792
-
793
965
  // TODO this should be in FileSystem module
794
966
  const pathBaseName = path => {
795
967
  return path.slice(path.lastIndexOf('/') + 1);
@@ -1319,30 +1491,6 @@ const focusNext = state => {
1319
1491
  return focusIndex(state, nextIndex);
1320
1492
  };
1321
1493
 
1322
- // based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
1323
-
1324
- const insertInto = (array, start, newItems) => {
1325
- const originalLength = array.length;
1326
- const newItemsLength = newItems.length;
1327
- array.length = originalLength + newItemsLength;
1328
- // Move the items after the start index, start from the end so that we don't overwrite any value.
1329
- for (let i = originalLength - 1; i >= start; i--) {
1330
- array[i + newItemsLength] = array[i];
1331
- }
1332
- for (let i = 0; i < newItemsLength; i++) {
1333
- array[i + start] = newItems[i];
1334
- }
1335
- };
1336
- const push = (array, newItems) => {
1337
- insertInto(array, array.length, newItems);
1338
- };
1339
- const isLastIndex = (array, index) => {
1340
- return index === array.length - 1;
1341
- };
1342
- const lastIndex = array => {
1343
- return array.length - 1;
1344
- };
1345
-
1346
1494
  const focusNextPage = state => {
1347
1495
  const {
1348
1496
  focusedIndex,
@@ -2272,21 +2420,6 @@ const textSearch = async (root, query, options, assetDir) => {
2272
2420
  return results;
2273
2421
  };
2274
2422
 
2275
- const getStatusMessage = (resultCount, fileResultCount) => {
2276
- number(resultCount);
2277
- number(fileResultCount);
2278
- if (resultCount === 0) {
2279
- return noResults();
2280
- }
2281
- if (resultCount === 1) {
2282
- return oneResult();
2283
- }
2284
- if (fileResultCount === 1) {
2285
- return manyResultsInOneFile(resultCount);
2286
- }
2287
- return manyResultsInManyFiles(resultCount, fileResultCount);
2288
- };
2289
-
2290
2423
  const handleUpdate = async (state, update) => {
2291
2424
  const partialNewState = {
2292
2425
  ...state,
@@ -2576,6 +2709,7 @@ const commandMap = {
2576
2709
  'TextSearch.clearSearchResults': clearSearchResults$1,
2577
2710
  'TextSearch.copy': copy,
2578
2711
  'TextSearch.create': create,
2712
+ 'TextSearch.dismissItem': dismissItem,
2579
2713
  'TextSearch.doRender': doRender,
2580
2714
  'TextSearch.focusFirst': focusFirst,
2581
2715
  'TextSearch.focusIndex': focusIndex,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "Text Search Worker",
5
5
  "main": "dist/textSearchWorkerMain.js",
6
6
  "type": "module",