@teambit/command-bar 0.0.707 → 0.0.710

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 (90) hide show
  1. package/command-bar.module.scss +11 -0
  2. package/command-bar.ui.runtime.tsx +48 -36
  3. package/dist/command-bar.module.scss +11 -0
  4. package/dist/command-bar.ui.runtime.d.ts +10 -11
  5. package/dist/command-bar.ui.runtime.js +81 -55
  6. package/dist/command-bar.ui.runtime.js.map +1 -1
  7. package/dist/index.d.ts +3 -3
  8. package/dist/index.js +0 -32
  9. package/dist/index.js.map +1 -1
  10. package/dist/searchers/command-searcher/command-result.d.ts +7 -0
  11. package/dist/searchers/command-searcher/command-result.js +93 -0
  12. package/dist/searchers/command-searcher/command-result.js.map +1 -0
  13. package/dist/searchers/command-searcher/command-result.module.scss +15 -0
  14. package/dist/searchers/command-searcher/command-searcher.d.ts +9 -0
  15. package/dist/searchers/command-searcher/command-searcher.js +74 -0
  16. package/dist/searchers/command-searcher/command-searcher.js.map +1 -0
  17. package/dist/searchers/command-searcher/command.d.ts +8 -0
  18. package/dist/searchers/command-searcher/command.js +3 -0
  19. package/dist/searchers/command-searcher/command.js.map +1 -0
  20. package/dist/{ui → searchers}/command-searcher/index.d.ts +0 -0
  21. package/dist/{ui → searchers}/command-searcher/index.js +0 -0
  22. package/dist/{ui → searchers}/command-searcher/index.js.map +0 -0
  23. package/dist/searchers/index.d.ts +2 -0
  24. package/dist/searchers/index.js +23 -0
  25. package/dist/{ui/command-bar-context → searchers}/index.js.map +1 -1
  26. package/dist/searchers/search-provider.d.ts +7 -0
  27. package/dist/searchers/search-provider.js +3 -0
  28. package/dist/searchers/search-provider.js.map +1 -0
  29. package/dist/types.d.ts +1 -15
  30. package/package-tar/teambit-command-bar-0.0.710.tgz +0 -0
  31. package/package.json +14 -14
  32. package/{preview-1649733938651.js → preview-1650252279523.js} +2 -2
  33. package/searchers/command-searcher/command-result.module.scss +15 -0
  34. package/searchers/command-searcher/command-result.tsx +25 -0
  35. package/searchers/command-searcher/command-searcher.tsx +31 -0
  36. package/searchers/command-searcher/command.ts +8 -0
  37. package/{ui → searchers}/command-searcher/index.ts +0 -0
  38. package/searchers/index.ts +2 -0
  39. package/searchers/search-provider.ts +8 -0
  40. package/types.tsx +2 -17
  41. package/dist/ui/autocomplete-input/autocomplete-input.d.ts +0 -11
  42. package/dist/ui/autocomplete-input/autocomplete-input.js +0 -112
  43. package/dist/ui/autocomplete-input/autocomplete-input.js.map +0 -1
  44. package/dist/ui/autocomplete-input/autocomplete-input.module.scss +0 -13
  45. package/dist/ui/autocomplete-input/index.d.ts +0 -1
  46. package/dist/ui/autocomplete-input/index.js +0 -20
  47. package/dist/ui/autocomplete-input/index.js.map +0 -1
  48. package/dist/ui/command-bar/command-bar.d.ts +0 -9
  49. package/dist/ui/command-bar/command-bar.js +0 -149
  50. package/dist/ui/command-bar/command-bar.js.map +0 -1
  51. package/dist/ui/command-bar/command-bar.module.scss +0 -44
  52. package/dist/ui/command-bar/index.d.ts +0 -1
  53. package/dist/ui/command-bar/index.js +0 -29
  54. package/dist/ui/command-bar/index.js.map +0 -1
  55. package/dist/ui/command-bar-context/command-bar-context.d.ts +0 -3
  56. package/dist/ui/command-bar-context/command-bar-context.js +0 -21
  57. package/dist/ui/command-bar-context/command-bar-context.js.map +0 -1
  58. package/dist/ui/command-bar-context/index.d.ts +0 -1
  59. package/dist/ui/command-bar-context/index.js +0 -23
  60. package/dist/ui/command-bar-item/command-bar-item.d.ts +0 -7
  61. package/dist/ui/command-bar-item/command-bar-item.js +0 -109
  62. package/dist/ui/command-bar-item/command-bar-item.js.map +0 -1
  63. package/dist/ui/command-bar-item/command-bar-item.module.scss +0 -38
  64. package/dist/ui/command-bar-item/index.d.ts +0 -1
  65. package/dist/ui/command-bar-item/index.js +0 -29
  66. package/dist/ui/command-bar-item/index.js.map +0 -1
  67. package/dist/ui/command-searcher/command-searcher.d.ts +0 -8
  68. package/dist/ui/command-searcher/command-searcher.js +0 -67
  69. package/dist/ui/command-searcher/command-searcher.js.map +0 -1
  70. package/dist/ui/component-searcher/component-searcher.d.ts +0 -14
  71. package/dist/ui/component-searcher/component-searcher.js +0 -89
  72. package/dist/ui/component-searcher/component-searcher.js.map +0 -1
  73. package/dist/ui/component-searcher/index.d.ts +0 -1
  74. package/dist/ui/component-searcher/index.js +0 -23
  75. package/dist/ui/component-searcher/index.js.map +0 -1
  76. package/package-tar/teambit-command-bar-0.0.707.tgz +0 -0
  77. package/ui/autocomplete-input/autocomplete-input.module.scss +0 -13
  78. package/ui/autocomplete-input/autocomplete-input.tsx +0 -62
  79. package/ui/autocomplete-input/index.ts +0 -1
  80. package/ui/command-bar/command-bar.module.scss +0 -44
  81. package/ui/command-bar/command-bar.tsx +0 -66
  82. package/ui/command-bar/index.ts +0 -1
  83. package/ui/command-bar-context/command-bar-context.tsx +0 -4
  84. package/ui/command-bar-context/index.ts +0 -1
  85. package/ui/command-bar-item/command-bar-item.module.scss +0 -38
  86. package/ui/command-bar-item/command-bar-item.tsx +0 -30
  87. package/ui/command-bar-item/index.ts +0 -1
  88. package/ui/command-searcher/command-searcher.ts +0 -31
  89. package/ui/component-searcher/component-searcher.ts +0 -44
  90. package/ui/component-searcher/index.ts +0 -1
@@ -1,89 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- require("core-js/modules/es.regexp.exec.js");
6
-
7
- Object.defineProperty(exports, "__esModule", {
8
- value: true
9
- });
10
- exports.ComponentSearcher = void 0;
11
-
12
- function _defineProperty2() {
13
- const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
-
15
- _defineProperty2 = function () {
16
- return data;
17
- };
18
-
19
- return data;
20
- }
21
-
22
- function _fuse() {
23
- const data = _interopRequireDefault(require("fuse.js"));
24
-
25
- _fuse = function () {
26
- return data;
27
- };
28
-
29
- return data;
30
- }
31
-
32
- function _memoizeOne() {
33
- const data = _interopRequireDefault(require("memoize-one"));
34
-
35
- _memoizeOne = function () {
36
- return data;
37
- };
38
-
39
- return data;
40
- }
41
-
42
- const searchedKeys = ['displayName', 'name'];
43
-
44
- class ComponentSearcher {
45
- constructor(navigate) {
46
- this.navigate = navigate;
47
- (0, _defineProperty2().default)(this, "fuseCommands", new (_fuse().default)([], {
48
- // weight can be included here.
49
- // fields loses weight the longer they get, so it seems ok for now.
50
- keys: searchedKeys
51
- }));
52
- (0, _defineProperty2().default)(this, "update", (0, _memoizeOne().default)(components => {
53
- const {
54
- navigate
55
- } = this;
56
- const searchResults = components.map(c => {
57
- var _c$environment, _c$environment2;
58
-
59
- return {
60
- id: c.id.fullName,
61
- displayName: c.id.fullName,
62
- name: c.id.name,
63
- handler: () => navigate(`/${c.id.fullName}`),
64
- icon: (_c$environment = c.environment) === null || _c$environment === void 0 ? void 0 : _c$environment.icon,
65
- iconAlt: (_c$environment2 = c.environment) === null || _c$environment2 === void 0 ? void 0 : _c$environment2.id
66
- };
67
- });
68
- this.fuseCommands.setCollection(searchResults);
69
- }));
70
- } // this method can be called on every render. memoize to prevent redundant calls
71
-
72
-
73
- search(term, limit) {
74
- const searchResults = this.fuseCommands.search(term, {
75
- limit
76
- }); // @ts-ignore this shows error on Circle for some weird reason
77
-
78
- return searchResults.map(x => x.item);
79
- }
80
-
81
- test(term) {
82
- return !term.startsWith('>') && term.length > 0;
83
- }
84
-
85
- }
86
-
87
- exports.ComponentSearcher = ComponentSearcher;
88
-
89
- //# sourceMappingURL=component-searcher.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["component-searcher.ts"],"names":["searchedKeys","ComponentSearcher","constructor","navigate","Fuse","keys","components","searchResults","map","c","id","fullName","displayName","name","handler","icon","environment","iconAlt","fuseCommands","setCollection","search","term","limit","x","item","test","startsWith","length"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAMA,MAAMA,YAA6C,GAAG,CAAC,aAAD,EAAgB,MAAhB,CAAtD;;AAEO,MAAMC,iBAAN,CAAkD;AAOvDC,EAAAA,WAAW,CAASC,QAAT,EAA2C;AAAA,SAAlCA,QAAkC,GAAlCA,QAAkC;AAAA,0DAN/B,KAAIC,eAAJ,EAAgC,EAAhC,EAAoC;AACzD;AACA;AACAC,MAAAA,IAAI,EAAEL;AAHmD,KAApC,CAM+B;AAAA,oDAG7C,2BAAYM,UAAD,IAAkC;AACpD,YAAM;AAAEH,QAAAA;AAAF,UAAe,IAArB;AAEA,YAAMI,aAAa,GAAGD,UAAU,CAACE,GAAX,CAAgBC,CAAD;AAAA;;AAAA,eAAQ;AAC3CC,UAAAA,EAAE,EAAED,CAAC,CAACC,EAAF,CAAKC,QADkC;AAE3CC,UAAAA,WAAW,EAAEH,CAAC,CAACC,EAAF,CAAKC,QAFyB;AAG3CE,UAAAA,IAAI,EAAEJ,CAAC,CAACC,EAAF,CAAKG,IAHgC;AAI3CC,UAAAA,OAAO,EAAE,MAAMX,QAAQ,CAAE,IAAGM,CAAC,CAACC,EAAF,CAAKC,QAAS,EAAnB,CAJoB;AAK3CI,UAAAA,IAAI,oBAAEN,CAAC,CAACO,WAAJ,mDAAE,eAAeD,IALsB;AAM3CE,UAAAA,OAAO,qBAAER,CAAC,CAACO,WAAJ,oDAAE,gBAAeN;AANmB,SAAR;AAAA,OAAf,CAAtB;AASA,WAAKQ,YAAL,CAAkBC,aAAlB,CAAgCZ,aAAhC;AACD,KAbQ,CAH6C;AAAE,GAPD,CASvD;;;AAgBAa,EAAAA,MAAM,CAACC,IAAD,EAAeC,KAAf,EAAuD;AAC3D,UAAMf,aAAa,GAAG,KAAKW,YAAL,CAAkBE,MAAlB,CAAyBC,IAAzB,EAA+B;AAAEC,MAAAA;AAAF,KAA/B,CAAtB,CAD2D,CAE3D;;AACA,WAAOf,aAAa,CAACC,GAAd,CAAmBe,CAAD,IAAOA,CAAC,CAACC,IAA3B,CAAP;AACD;;AAEDC,EAAAA,IAAI,CAACJ,IAAD,EAAwB;AAC1B,WAAO,CAACA,IAAI,CAACK,UAAL,CAAgB,GAAhB,CAAD,IAAyBL,IAAI,CAACM,MAAL,GAAc,CAA9C;AACD;;AAjCsD","sourcesContent":["import Fuse from 'fuse.js';\nimport memoizeOne from 'memoize-one';\nimport { ComponentModel } from '@teambit/component';\nimport { SearchProvider, CommanderSearchResult } from '../../types';\n\ntype ComponentSearchResult = CommanderSearchResult & { name: string };\n\nconst searchedKeys: (keyof ComponentSearchResult)[] = ['displayName', 'name'];\n\nexport class ComponentSearcher implements SearchProvider {\n private fuseCommands = new Fuse<ComponentSearchResult>([], {\n // weight can be included here.\n // fields loses weight the longer they get, so it seems ok for now.\n keys: searchedKeys,\n });\n\n constructor(private navigate: (path: string) => void) {}\n\n // this method can be called on every render. memoize to prevent redundant calls\n update = memoizeOne((components: ComponentModel[]) => {\n const { navigate } = this;\n\n const searchResults = components.map((c) => ({\n id: c.id.fullName,\n displayName: c.id.fullName,\n name: c.id.name,\n handler: () => navigate(`/${c.id.fullName}`),\n icon: c.environment?.icon,\n iconAlt: c.environment?.id,\n }));\n\n this.fuseCommands.setCollection(searchResults);\n });\n\n search(term: string, limit: number): ComponentSearchResult[] {\n const searchResults = this.fuseCommands.search(term, { limit });\n // @ts-ignore this shows error on Circle for some weird reason\n return searchResults.map((x) => x.item);\n }\n\n test(term: string): boolean {\n return !term.startsWith('>') && term.length > 0;\n }\n}\n"]}
@@ -1 +0,0 @@
1
- export { ComponentSearcher } from './component-searcher';
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "ComponentSearcher", {
7
- enumerable: true,
8
- get: function () {
9
- return _componentSearcher().ComponentSearcher;
10
- }
11
- });
12
-
13
- function _componentSearcher() {
14
- const data = require("./component-searcher");
15
-
16
- _componentSearcher = function () {
17
- return data;
18
- };
19
-
20
- return data;
21
- }
22
-
23
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA","sourcesContent":["export { ComponentSearcher } from './component-searcher';\n"]}
@@ -1,13 +0,0 @@
1
- .input {
2
- font-size: inherit;
3
- font-family: inherit;
4
- color: inherit;
5
- border: none;
6
-
7
- // command bar is open iff input is focused, so outline is not needed
8
- outline: none;
9
-
10
- &::placeholder {
11
- color: var(--bit-text-inactive, #babec9);
12
- }
13
- }
@@ -1,62 +0,0 @@
1
- import React, { useCallback, useEffect, createRef, InputHTMLAttributes } from 'react';
2
- import classNames from 'classnames';
3
- import styles from './autocomplete-input.module.scss';
4
-
5
- type AutoCompleteInputProps = InputHTMLAttributes<HTMLInputElement> & {
6
- onEscape?: (e: React.KeyboardEvent<HTMLInputElement>) => void;
7
- onDown?: (e: React.KeyboardEvent<HTMLInputElement>) => void;
8
- onUp?: (e: React.KeyboardEvent<HTMLInputElement>) => void;
9
- onEnter?: (e: React.KeyboardEvent<HTMLInputElement>) => void;
10
- focus?: Truthy;
11
- };
12
-
13
- type Truthy = boolean | number | string | null | undefined;
14
-
15
- export function AutoCompleteInput({
16
- className,
17
- onEscape,
18
- onDown,
19
- onUp,
20
- onEnter,
21
- onKeyDown,
22
- focus,
23
- ...rest
24
- }: AutoCompleteInputProps) {
25
- const inputRef = createRef<HTMLInputElement>();
26
-
27
- useEffect(() => {
28
- if (focus) inputRef.current?.focus();
29
- }, [focus]);
30
-
31
- const handleKeyDown = useCallback(
32
- (e: React.KeyboardEvent<HTMLInputElement>) => {
33
- onKeyDown?.(e);
34
- if (e.defaultPrevented) return;
35
-
36
- const handlers = {
37
- Escape: () => {
38
- e.preventDefault();
39
- onEscape?.(e);
40
- },
41
- ArrowDown: () => {
42
- e.preventDefault();
43
- onDown?.(e);
44
- },
45
- ArrowUp: () => {
46
- e.preventDefault();
47
- onUp?.(e);
48
- },
49
- Enter: () => {
50
- e.preventDefault();
51
- onEnter?.(e);
52
- },
53
- };
54
-
55
- if (e.key in handlers) handlers[e.key]();
56
- },
57
- [onEscape, onDown, onUp, onEnter]
58
- );
59
-
60
- // @ts-ignore (https://github.com/teambit/bit/issues/4908)
61
- return <input {...rest} ref={inputRef} className={classNames(styles.input, className)} onKeyDown={handleKeyDown} />;
62
- }
@@ -1 +0,0 @@
1
- export * from './autocomplete-input';
@@ -1,44 +0,0 @@
1
- @import '~@teambit/ui-foundation.ui.constants.z-indexes/z-indexes.module.scss';
2
-
3
- .commandBar {
4
- display: none;
5
- flex-direction: column;
6
-
7
- position: fixed;
8
- top: 130px;
9
- left: 50%;
10
- transform: translate(-50%, 0);
11
- width: 643px;
12
- border: 1px solid var(--bit-border-color, #babec9);
13
- max-width: 90%;
14
-
15
- overflow: hidden; // enforce border-radius
16
-
17
- color: var(--bit-text-color-heavy, #2b2b2b);
18
- box-shadow: 0 40px 60px 0 rgba(0, 0, 0, 0.32);
19
-
20
- &.visible {
21
- display: flex;
22
- }
23
- }
24
-
25
- .commandBar {
26
- padding: 0px;
27
- z-index: $modal-z-index;
28
- }
29
-
30
- .input {
31
- padding: 0 24px;
32
- font-size: 20px;
33
- height: 56px;
34
- line-height: 56px;
35
- }
36
-
37
- .results {
38
- font-size: 14px;
39
-
40
- &:not(:empty) {
41
- margin-bottom: 8px;
42
- border-top: solid 1px var(--bit-border-color, #babec9);
43
- }
44
- }
@@ -1,66 +0,0 @@
1
- import React, { useCallback, useEffect, useState, useMemo } from 'react';
2
- import classNames from 'classnames';
3
- import { Card, CardProps } from '@teambit/base-ui.surfaces.card';
4
- import type { CommandBarUI } from '../../command-bar.ui.runtime';
5
- import { CommanderSearchResult } from '../../types';
6
- import { AutoCompleteInput } from '../autocomplete-input';
7
- import { CommandBarItem } from '../command-bar-item';
8
- import styles from './command-bar.module.scss';
9
-
10
- export type CommandBarProps = {
11
- search: (term: string, limit?: number) => CommanderSearchResult[];
12
- commander: CommandBarUI;
13
- } & CardProps;
14
-
15
- const MIN_IDX = 0;
16
-
17
- export function CommandBar({ search, commander, elevation = 'high', className, ...rest }: CommandBarProps) {
18
- const [term, setTerm] = useState('');
19
- const options = useMemo(() => search(term), [term, search]);
20
- const [activeIdx, setActive] = useState(MIN_IDX);
21
- const increment = useCallback(() => setActive((x) => Math.min(x + 1, options.length - 1)), [options.length]);
22
- const decrement = useCallback(() => setActive((x) => Math.max(x - 1, MIN_IDX)), []);
23
- const [visible, setVisibility] = useState(false);
24
-
25
- commander.setVisibility = setVisibility;
26
-
27
- const handleEnter = useCallback(() => {
28
- setVisibility(false);
29
- options[activeIdx]?.handler();
30
- }, [options, activeIdx]);
31
-
32
- useEffect(() => setTerm(''), [visible]);
33
- useEffect(() => setActive(MIN_IDX), [options]);
34
-
35
- return (
36
- <Card
37
- {...rest}
38
- elevation={elevation}
39
- className={classNames(className, styles.commandBar, visible && styles.visible)}
40
- >
41
- <AutoCompleteInput
42
- value={term}
43
- focus={visible}
44
- className={styles.input}
45
- placeholder="Search anything or type > to only search commands"
46
- onChange={(e) => setTerm(e.target.value)}
47
- onDown={increment}
48
- onUp={decrement}
49
- onEnter={handleEnter}
50
- onEscape={() => setVisibility(false)}
51
- onBlur={() => setVisibility(false)}
52
- />
53
- <div className={styles.results}>
54
- {options.map((x, idx) => (
55
- <CommandBarItem
56
- key={idx} // use index instead of id to avoid duplicate keys
57
- entry={x}
58
- active={idx === activeIdx}
59
- // mouseDown happens before blur, which closes the command bar
60
- onMouseDown={x.handler}
61
- />
62
- ))}
63
- </div>
64
- </Card>
65
- );
66
- }
@@ -1 +0,0 @@
1
- export { CommandBar, CommandBarProps } from './command-bar';
@@ -1,4 +0,0 @@
1
- import { createContext } from 'react';
2
- import { CommandBarUI } from '../../command-bar.ui.runtime';
3
-
4
- export const CommandBarContext = createContext<CommandBarUI | undefined>(undefined);
@@ -1 +0,0 @@
1
- export { CommandBarContext } from './command-bar-context';
@@ -1,38 +0,0 @@
1
- .commandBarOption {
2
- display: flex;
3
- align-items: center;
4
-
5
- height: 40px;
6
- padding: 0 24px;
7
- transition: all 180ms;
8
-
9
- user-select: none;
10
- cursor: pointer;
11
-
12
- &:hover {
13
- background-color: var(--bit-bg-heavy, #f6f6f6);
14
- }
15
-
16
- &.active,
17
- &.active:hover {
18
- background-color: var(--bit-accent-bg, #eceaff);
19
- }
20
- }
21
-
22
- .name {
23
- flex: 1 1;
24
- text-overflow: ellipsis;
25
- overflow: hidden;
26
- white-space: nowrap;
27
- }
28
-
29
- .commandKeys {
30
- float: right;
31
- font-size: 15px;
32
- }
33
-
34
- .icon {
35
- width: 16px;
36
- height: 16px;
37
- margin-right: 8px;
38
- }
@@ -1,30 +0,0 @@
1
- import React from 'react';
2
- import classnames from 'classnames';
3
- import { KeySequence } from '@teambit/ui-foundation.ui.keycap';
4
- import { mutedText } from '@teambit/base-ui.text.muted-text';
5
- import { CommanderSearchResult } from '../../types';
6
- import styles from './command-bar-item.module.scss';
7
-
8
- export type CommandItemProps = {
9
- active?: boolean;
10
- entry: CommanderSearchResult;
11
- } & React.HTMLAttributes<HTMLDivElement>;
12
-
13
- export function CommandBarItem({ entry, className, active, ...rest }: CommandItemProps) {
14
- const { handler, displayName: name, icon, iconAlt, keybinding } = entry;
15
- const firstKeybinding = Array.isArray(keybinding) ? keybinding[0] : keybinding;
16
-
17
- return (
18
- <div
19
- {...rest}
20
- className={classnames(className, styles.commandBarOption, active && styles.active)}
21
- onMouseDown={handler}
22
- >
23
- {icon && <img src={icon} alt={iconAlt} className={styles.icon} />}
24
- <div className={styles.name}>{name}</div>
25
- {firstKeybinding && (
26
- <KeySequence className={classnames(styles.commandKeys, mutedText)}>{firstKeybinding}</KeySequence>
27
- )}
28
- </div>
29
- );
30
- }
@@ -1 +0,0 @@
1
- export { CommandBarItem, CommandItemProps } from './command-bar-item';
@@ -1,31 +0,0 @@
1
- import Fuse from 'fuse.js';
2
- import { CommanderSearchResult, SearchProvider } from '../../types';
3
-
4
- const searchedKeys: (keyof CommanderSearchResult)[] = ['displayName'];
5
-
6
- export class CommandSearcher implements SearchProvider {
7
- private fuseCommands = new Fuse<CommanderSearchResult>([], {
8
- // weight can be included here.
9
- // fields loses weight the longer they get, so it seems ok for now.
10
- keys: searchedKeys,
11
- });
12
-
13
- constructor(commands: CommanderSearchResult[]) {
14
- this.fuseCommands.setCollection(commands);
15
- }
16
-
17
- update(commands: CommanderSearchResult[]) {
18
- this.fuseCommands.setCollection(commands);
19
- }
20
-
21
- search(term: string, limit: number): CommanderSearchResult[] {
22
- const unprefixedPattern = term.replace(/^>/, '');
23
- const searchResults = this.fuseCommands.search(unprefixedPattern, { limit });
24
- // @ts-ignore this shows error on Circle for some weird reason
25
- return searchResults.map((x) => x.item);
26
- }
27
-
28
- test(term: string): boolean {
29
- return term.startsWith('>');
30
- }
31
- }
@@ -1,44 +0,0 @@
1
- import Fuse from 'fuse.js';
2
- import memoizeOne from 'memoize-one';
3
- import { ComponentModel } from '@teambit/component';
4
- import { SearchProvider, CommanderSearchResult } from '../../types';
5
-
6
- type ComponentSearchResult = CommanderSearchResult & { name: string };
7
-
8
- const searchedKeys: (keyof ComponentSearchResult)[] = ['displayName', 'name'];
9
-
10
- export class ComponentSearcher implements SearchProvider {
11
- private fuseCommands = new Fuse<ComponentSearchResult>([], {
12
- // weight can be included here.
13
- // fields loses weight the longer they get, so it seems ok for now.
14
- keys: searchedKeys,
15
- });
16
-
17
- constructor(private navigate: (path: string) => void) {}
18
-
19
- // this method can be called on every render. memoize to prevent redundant calls
20
- update = memoizeOne((components: ComponentModel[]) => {
21
- const { navigate } = this;
22
-
23
- const searchResults = components.map((c) => ({
24
- id: c.id.fullName,
25
- displayName: c.id.fullName,
26
- name: c.id.name,
27
- handler: () => navigate(`/${c.id.fullName}`),
28
- icon: c.environment?.icon,
29
- iconAlt: c.environment?.id,
30
- }));
31
-
32
- this.fuseCommands.setCollection(searchResults);
33
- });
34
-
35
- search(term: string, limit: number): ComponentSearchResult[] {
36
- const searchResults = this.fuseCommands.search(term, { limit });
37
- // @ts-ignore this shows error on Circle for some weird reason
38
- return searchResults.map((x) => x.item);
39
- }
40
-
41
- test(term: string): boolean {
42
- return !term.startsWith('>') && term.length > 0;
43
- }
44
- }
@@ -1 +0,0 @@
1
- export { ComponentSearcher } from './component-searcher';