@teambit/command-bar 0.0.706 → 0.0.709

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.709.tgz +0 -0
  31. package/package.json +12 -12
  32. package/{preview-1649647448813.js → preview-1650243425150.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.706.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
@@ -0,0 +1,11 @@
1
+ .commanderUi {
2
+ position: fixed;
3
+ top: 130px;
4
+ left: 50%;
5
+ transform: translate(-50%, 0);
6
+
7
+ width: 643px;
8
+ max-width: 90%;
9
+
10
+ font-size: 20px;
11
+ }
@@ -1,28 +1,31 @@
1
- import React, { ReactNode } from 'react';
2
- import { Slot, SlotRegistry } from '@teambit/harmony';
1
+ import React, { useState } from 'react';
2
+ import flatten from 'lodash.flatten';
3
3
  import Mousetrap from 'mousetrap';
4
4
 
5
+ import { Slot, SlotRegistry } from '@teambit/harmony';
5
6
  import UIAspect, { UIRuntime, UiUI } from '@teambit/ui';
6
7
  import { PubsubAspect, PubsubUI } from '@teambit/pubsub';
8
+ import { ReactRouterAspect } from '@teambit/react-router';
7
9
  import { isBrowser } from '@teambit/ui-foundation.ui.is-browser';
8
- import { CommandBar } from './ui/command-bar';
9
- import { CommandSearcher } from './ui/command-searcher';
10
+ import { CommandBar } from '@teambit/explorer.ui.command-bar';
10
11
  import { CommandBarAspect } from './command-bar.aspect';
11
12
  import { commandBarCommands } from './command-bar.commands';
12
- import { SearchProvider, Keybinding, CommandHandler, CommandId } from './types';
13
+ import { CommandSearcher, SearchProvider } from './searchers';
14
+ import { Keybinding, CommandHandler, CommandId } from './types';
13
15
  import { DuplicateCommandError } from './duplicate-command-error';
14
16
  import { KeyEvent } from './model/key-event';
15
- import { CommandBarContext } from './ui/command-bar-context';
16
17
  import { MousetrapStub } from './mousetrap-stub';
17
18
  import { openCommandBarKeybinding } from './keybinding';
18
19
 
20
+ import styles from './command-bar.module.scss';
21
+
19
22
  const RESULT_LIMIT = 5;
20
- type SearcherSlot = SlotRegistry<SearchProvider>;
23
+ type SearcherSlot = SlotRegistry<SearchProvider[]>;
21
24
  type CommandSlot = SlotRegistry<CommandEntry[]>;
22
25
 
23
26
  export type CommandEntry = {
24
27
  id: CommandId;
25
- handler: CommandHandler;
28
+ action: CommandHandler;
26
29
  keybinding?: Keybinding;
27
30
  displayName: string;
28
31
  };
@@ -44,7 +47,7 @@ export class CommandBarUI {
44
47
  };
45
48
 
46
49
  /** Add and autocomplete provider. To support keyboard navigation, each result should have a props `active: boolean`, and `exectue: () => any` */
47
- addSearcher(commandSearcher: SearchProvider) {
50
+ addSearcher(...commandSearcher: SearchProvider[]) {
48
51
  this.searcherSlot.register(commandSearcher);
49
52
  return this;
50
53
  }
@@ -61,7 +64,7 @@ export class CommandBarUI {
61
64
  const commands = originalCommands.map((x) => ({
62
65
  id: x.id,
63
66
  displayName: x.displayName,
64
- handler: x.handler,
67
+ action: x.action,
65
68
  keybinding: x.keybinding,
66
69
  }));
67
70
 
@@ -76,7 +79,7 @@ export class CommandBarUI {
76
79
  this.updateCommandsSearcher();
77
80
 
78
81
  const updaters = commands.map((command) => (next: CommandHandler) => {
79
- command.handler = next;
82
+ command.action = next;
80
83
  });
81
84
  return updaters;
82
85
  }
@@ -89,7 +92,7 @@ export class CommandBarUI {
89
92
  const commandEntry = this.getCommand(commandId);
90
93
  if (!commandEntry) return undefined;
91
94
 
92
- return commandEntry.handler();
95
+ return commandEntry.action();
93
96
  }
94
97
 
95
98
  /**
@@ -100,7 +103,7 @@ export class CommandBarUI {
100
103
  };
101
104
 
102
105
  private search = (term: string, limit: number = RESULT_LIMIT) => {
103
- const searchers = this.searcherSlot.values();
106
+ const searchers = flatten(this.searcherSlot.values());
104
107
 
105
108
  const searcher = searchers.find((x) => x.test(term));
106
109
  return searcher?.search(term, limit) || [];
@@ -124,51 +127,60 @@ export class CommandBarUI {
124
127
  this.mousetrap.bind(key, this.run.bind(this, command));
125
128
  }
126
129
 
127
- private renderContext = ({ children }: { children: ReactNode }) => {
128
- return <CommandBarContext.Provider value={this}>{children}</CommandBarContext.Provider>;
129
- };
130
-
131
130
  /**
132
- * internal. Opens and closes the command bar UI.
131
+ * Opens and closes the command bar UI.
133
132
  */
134
- setVisibility?: (visible: boolean) => void;
133
+ private setVisibility?: (visible: boolean) => void;
135
134
 
136
135
  /**
137
136
  * generate the ui for command bar
138
137
  */
139
- getCommandBar = () => {
140
- return <CommandBar key="CommandBarUI" search={this.search} commander={this} />;
138
+ private CommandBar = () => {
139
+ const [visible, setVisibility] = useState(false);
140
+ this.setVisibility = setVisibility;
141
+
142
+ return (
143
+ <CommandBar
144
+ key="CommandBarUI"
145
+ className={styles.commanderUi}
146
+ searcher={this.search}
147
+ placeholder="Search anything or type > to only search commands"
148
+ visible={visible}
149
+ onVisibilityChange={setVisibility}
150
+ />
151
+ );
141
152
  };
142
153
 
143
- constructor(private searcherSlot: SearcherSlot, private commandSlot: CommandSlot, pubSub: PubsubUI) {
144
- this.addSearcher(this.commandSearcher);
145
- pubSub.sub(CommandBarAspect.id, (e: KeyEvent) => {
146
- const keyboardEvent = new KeyboardEvent(e.type, e.data);
147
- document.dispatchEvent(keyboardEvent);
148
- });
149
- }
154
+ constructor(private searcherSlot: SearcherSlot, private commandSlot: CommandSlot) {}
150
155
 
151
- static dependencies = [UIAspect, PubsubAspect];
156
+ static dependencies = [UIAspect, PubsubAspect, ReactRouterAspect];
152
157
  static slots = [Slot.withType<SearchProvider>(), Slot.withType<CommandEntry[]>()];
153
158
  static runtime = UIRuntime;
154
159
  static async provider(
155
- [uiUi, pubsubUI]: [UiUI, PubsubUI],
160
+ [uiUi, pubsubUI]: [UiUI | undefined, PubsubUI | undefined],
156
161
  config,
157
162
  [searcherSlot, commandSlots]: [SearcherSlot, CommandSlot]
158
163
  ) {
159
- const commandBar = new CommandBarUI(searcherSlot, commandSlots, pubsubUI);
164
+ const commandBar = new CommandBarUI(searcherSlot, commandSlots);
160
165
 
166
+ commandBar.addSearcher(commandBar.commandSearcher);
161
167
  commandBar.addCommand({
162
168
  id: commandBarCommands.open,
163
- handler: commandBar.open,
169
+ action: commandBar.open,
164
170
  displayName: 'Open command bar',
165
171
  keybinding: openCommandBarKeybinding,
166
172
  });
167
173
 
168
- uiUi.registerHudItem(commandBar.getCommandBar());
169
- uiUi.registerRenderHooks({
170
- reactContext: commandBar.renderContext,
171
- });
174
+ if (pubsubUI) {
175
+ pubsubUI.sub(CommandBarAspect.id, (e: KeyEvent) => {
176
+ const keyboardEvent = new KeyboardEvent(e.type, e.data);
177
+ document.dispatchEvent(keyboardEvent);
178
+ });
179
+ }
180
+
181
+ if (uiUi) {
182
+ uiUi.registerHudItem(<commandBar.CommandBar />);
183
+ }
172
184
 
173
185
  return commandBar;
174
186
  }
@@ -0,0 +1,11 @@
1
+ .commanderUi {
2
+ position: fixed;
3
+ top: 130px;
4
+ left: 50%;
5
+ transform: translate(-50%, 0);
6
+
7
+ width: 643px;
8
+ max-width: 90%;
9
+
10
+ font-size: 20px;
11
+ }
@@ -1,13 +1,13 @@
1
- /// <reference types="react" />
2
1
  import { SlotRegistry } from '@teambit/harmony';
3
2
  import { UiUI } from '@teambit/ui';
4
3
  import { PubsubUI } from '@teambit/pubsub';
5
- import { SearchProvider, Keybinding, CommandHandler, CommandId } from './types';
6
- declare type SearcherSlot = SlotRegistry<SearchProvider>;
4
+ import { SearchProvider } from './searchers';
5
+ import { Keybinding, CommandHandler, CommandId } from './types';
6
+ declare type SearcherSlot = SlotRegistry<SearchProvider[]>;
7
7
  declare type CommandSlot = SlotRegistry<CommandEntry[]>;
8
8
  export declare type CommandEntry = {
9
9
  id: CommandId;
10
- handler: CommandHandler;
10
+ action: CommandHandler;
11
11
  keybinding?: Keybinding;
12
12
  displayName: string;
13
13
  };
@@ -22,7 +22,7 @@ export declare class CommandBarUI {
22
22
  /** Closes the command bar */
23
23
  close: () => void;
24
24
  /** Add and autocomplete provider. To support keyboard navigation, each result should have a props `active: boolean`, and `exectue: () => any` */
25
- addSearcher(commandSearcher: SearchProvider): this;
25
+ addSearcher(...commandSearcher: SearchProvider[]): this;
26
26
  /**
27
27
  * registers a command
28
28
  */
@@ -40,19 +40,18 @@ export declare class CommandBarUI {
40
40
  private getCommand;
41
41
  private updateCommandsSearcher;
42
42
  private addKeybinding;
43
- private renderContext;
44
43
  /**
45
- * internal. Opens and closes the command bar UI.
44
+ * Opens and closes the command bar UI.
46
45
  */
47
- setVisibility?: (visible: boolean) => void;
46
+ private setVisibility?;
48
47
  /**
49
48
  * generate the ui for command bar
50
49
  */
51
- getCommandBar: () => JSX.Element;
52
- constructor(searcherSlot: SearcherSlot, commandSlot: CommandSlot, pubSub: PubsubUI);
50
+ private CommandBar;
51
+ constructor(searcherSlot: SearcherSlot, commandSlot: CommandSlot);
53
52
  static dependencies: import("@teambit/harmony").Aspect[];
54
53
  static slots: (((registerFn: () => string) => SlotRegistry<SearchProvider>) | ((registerFn: () => string) => SlotRegistry<CommandEntry[]>))[];
55
54
  static runtime: import("@teambit/harmony").RuntimeDefinition;
56
- static provider([uiUi, pubsubUI]: [UiUI, PubsubUI], config: any, [searcherSlot, commandSlots]: [SearcherSlot, CommandSlot]): Promise<CommandBarUI>;
55
+ static provider([uiUi, pubsubUI]: [UiUI | undefined, PubsubUI | undefined], config: any, [searcherSlot, commandSlots]: [SearcherSlot, CommandSlot]): Promise<CommandBarUI>;
57
56
  }
58
57
  export {};
@@ -28,7 +28,7 @@ function _defineProperty2() {
28
28
  }
29
29
 
30
30
  function _react() {
31
- const data = _interopRequireDefault(require("react"));
31
+ const data = _interopRequireWildcard(require("react"));
32
32
 
33
33
  _react = function () {
34
34
  return data;
@@ -37,10 +37,10 @@ function _react() {
37
37
  return data;
38
38
  }
39
39
 
40
- function _harmony() {
41
- const data = require("@teambit/harmony");
40
+ function _lodash() {
41
+ const data = _interopRequireDefault(require("lodash.flatten"));
42
42
 
43
- _harmony = function () {
43
+ _lodash = function () {
44
44
  return data;
45
45
  };
46
46
 
@@ -57,6 +57,16 @@ function _mousetrap() {
57
57
  return data;
58
58
  }
59
59
 
60
+ function _harmony() {
61
+ const data = require("@teambit/harmony");
62
+
63
+ _harmony = function () {
64
+ return data;
65
+ };
66
+
67
+ return data;
68
+ }
69
+
60
70
  function _ui() {
61
71
  const data = _interopRequireWildcard(require("@teambit/ui"));
62
72
 
@@ -77,70 +87,70 @@ function _pubsub() {
77
87
  return data;
78
88
  }
79
89
 
80
- function _uiFoundationUi() {
81
- const data = require("@teambit/ui-foundation.ui.is-browser");
90
+ function _reactRouter() {
91
+ const data = require("@teambit/react-router");
82
92
 
83
- _uiFoundationUi = function () {
93
+ _reactRouter = function () {
84
94
  return data;
85
95
  };
86
96
 
87
97
  return data;
88
98
  }
89
99
 
90
- function _commandBar() {
91
- const data = require("./ui/command-bar");
100
+ function _uiFoundationUi() {
101
+ const data = require("@teambit/ui-foundation.ui.is-browser");
92
102
 
93
- _commandBar = function () {
103
+ _uiFoundationUi = function () {
94
104
  return data;
95
105
  };
96
106
 
97
107
  return data;
98
108
  }
99
109
 
100
- function _commandSearcher() {
101
- const data = require("./ui/command-searcher");
110
+ function _explorerUi() {
111
+ const data = require("@teambit/explorer.ui.command-bar");
102
112
 
103
- _commandSearcher = function () {
113
+ _explorerUi = function () {
104
114
  return data;
105
115
  };
106
116
 
107
117
  return data;
108
118
  }
109
119
 
110
- function _commandBar2() {
120
+ function _commandBar() {
111
121
  const data = require("./command-bar.aspect");
112
122
 
113
- _commandBar2 = function () {
123
+ _commandBar = function () {
114
124
  return data;
115
125
  };
116
126
 
117
127
  return data;
118
128
  }
119
129
 
120
- function _commandBar3() {
130
+ function _commandBar2() {
121
131
  const data = require("./command-bar.commands");
122
132
 
123
- _commandBar3 = function () {
133
+ _commandBar2 = function () {
124
134
  return data;
125
135
  };
126
136
 
127
137
  return data;
128
138
  }
129
139
 
130
- function _duplicateCommandError() {
131
- const data = require("./duplicate-command-error");
140
+ function _searchers() {
141
+ const data = require("./searchers");
132
142
 
133
- _duplicateCommandError = function () {
143
+ _searchers = function () {
134
144
  return data;
135
145
  };
136
146
 
137
147
  return data;
138
148
  }
139
149
 
140
- function _commandBarContext() {
141
- const data = require("./ui/command-bar-context");
150
+ function _duplicateCommandError() {
151
+ const data = require("./duplicate-command-error");
142
152
 
143
- _commandBarContext = function () {
153
+ _duplicateCommandError = function () {
144
154
  return data;
145
155
  };
146
156
 
@@ -167,6 +177,16 @@ function _keybinding() {
167
177
  return data;
168
178
  }
169
179
 
180
+ function _commandBarModule() {
181
+ const data = _interopRequireDefault(require("./command-bar.module.scss"));
182
+
183
+ _commandBarModule = function () {
184
+ return data;
185
+ };
186
+
187
+ return data;
188
+ }
189
+
170
190
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
171
191
 
172
192
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -180,7 +200,7 @@ class CommandBarUI {
180
200
  /** Closes the command bar */
181
201
 
182
202
  /** Add and autocomplete provider. To support keyboard navigation, each result should have a props `active: boolean`, and `exectue: () => any` */
183
- addSearcher(commandSearcher) {
203
+ addSearcher(...commandSearcher) {
184
204
  this.searcherSlot.register(commandSearcher);
185
205
  return this;
186
206
  }
@@ -199,7 +219,7 @@ class CommandBarUI {
199
219
  const commands = originalCommands.map(x => ({
200
220
  id: x.id,
201
221
  displayName: x.displayName,
202
- handler: x.handler,
222
+ action: x.action,
203
223
  keybinding: x.keybinding
204
224
  }));
205
225
  this.commandSlot.register(commands);
@@ -210,7 +230,7 @@ class CommandBarUI {
210
230
  });
211
231
  this.updateCommandsSearcher();
212
232
  const updaters = commands.map(command => next => {
213
- command.handler = next;
233
+ command.action = next;
214
234
  });
215
235
  return updaters;
216
236
  }
@@ -223,7 +243,7 @@ class CommandBarUI {
223
243
  run(commandId) {
224
244
  const commandEntry = this.getCommand(commandId);
225
245
  if (!commandEntry) return undefined;
226
- return commandEntry.handler();
246
+ return commandEntry.action();
227
247
  }
228
248
  /**
229
249
  * executes a keyboard shortcut manually
@@ -243,12 +263,16 @@ class CommandBarUI {
243
263
  addKeybinding(key, command) {
244
264
  this.mousetrap.bind(key, this.run.bind(this, command));
245
265
  }
266
+ /**
267
+ * Opens and closes the command bar UI.
268
+ */
246
269
 
247
- constructor(searcherSlot, commandSlot, pubSub) {
270
+
271
+ constructor(searcherSlot, commandSlot) {
248
272
  this.searcherSlot = searcherSlot;
249
273
  this.commandSlot = commandSlot;
250
274
  (0, _defineProperty2().default)(this, "mousetrap", _uiFoundationUi().isBrowser ? new (_mousetrap().default)() : new (_mousetrapStub().MousetrapStub)());
251
- (0, _defineProperty2().default)(this, "commandSearcher", new (_commandSearcher().CommandSearcher)([]));
275
+ (0, _defineProperty2().default)(this, "commandSearcher", new (_searchers().CommandSearcher)([]));
252
276
  (0, _defineProperty2().default)(this, "open", () => {
253
277
  var _this$setVisibility;
254
278
 
@@ -264,54 +288,56 @@ class CommandBarUI {
264
288
  this.mousetrap.trigger(key);
265
289
  });
266
290
  (0, _defineProperty2().default)(this, "search", (term, limit = RESULT_LIMIT) => {
267
- const searchers = this.searcherSlot.values();
291
+ const searchers = (0, _lodash().default)(this.searcherSlot.values());
268
292
  const searcher = searchers.find(x => x.test(term));
269
293
  return (searcher === null || searcher === void 0 ? void 0 : searcher.search(term, limit)) || [];
270
294
  });
271
- (0, _defineProperty2().default)(this, "renderContext", ({
272
- children
273
- }) => {
274
- return /*#__PURE__*/_react().default.createElement(_commandBarContext().CommandBarContext.Provider, {
275
- value: this
276
- }, children);
277
- });
278
295
  (0, _defineProperty2().default)(this, "setVisibility", void 0);
279
- (0, _defineProperty2().default)(this, "getCommandBar", () => {
280
- return /*#__PURE__*/_react().default.createElement(_commandBar().CommandBar, {
296
+ (0, _defineProperty2().default)(this, "CommandBar", () => {
297
+ const [visible, setVisibility] = (0, _react().useState)(false);
298
+ this.setVisibility = setVisibility;
299
+ return /*#__PURE__*/_react().default.createElement(_explorerUi().CommandBar, {
281
300
  key: "CommandBarUI",
282
- search: this.search,
283
- commander: this
301
+ className: _commandBarModule().default.commanderUi,
302
+ searcher: this.search,
303
+ placeholder: "Search anything or type > to only search commands",
304
+ visible: visible,
305
+ onVisibilityChange: setVisibility
284
306
  });
285
307
  });
286
- this.addSearcher(this.commandSearcher);
287
- pubSub.sub(_commandBar2().CommandBarAspect.id, e => {
288
- const keyboardEvent = new KeyboardEvent(e.type, e.data);
289
- document.dispatchEvent(keyboardEvent);
290
- });
291
308
  }
292
309
 
293
310
  static async provider([uiUi, pubsubUI], config, [searcherSlot, commandSlots]) {
294
- const commandBar = new CommandBarUI(searcherSlot, commandSlots, pubsubUI);
311
+ const commandBar = new CommandBarUI(searcherSlot, commandSlots);
312
+ commandBar.addSearcher(commandBar.commandSearcher);
295
313
  commandBar.addCommand({
296
- id: _commandBar3().commandBarCommands.open,
297
- handler: commandBar.open,
314
+ id: _commandBar2().commandBarCommands.open,
315
+ action: commandBar.open,
298
316
  displayName: 'Open command bar',
299
317
  keybinding: _keybinding().openCommandBarKeybinding
300
318
  });
301
- uiUi.registerHudItem(commandBar.getCommandBar());
302
- uiUi.registerRenderHooks({
303
- reactContext: commandBar.renderContext
304
- });
319
+
320
+ if (pubsubUI) {
321
+ pubsubUI.sub(_commandBar().CommandBarAspect.id, e => {
322
+ const keyboardEvent = new KeyboardEvent(e.type, e.data);
323
+ document.dispatchEvent(keyboardEvent);
324
+ });
325
+ }
326
+
327
+ if (uiUi) {
328
+ uiUi.registerHudItem( /*#__PURE__*/_react().default.createElement(commandBar.CommandBar, null));
329
+ }
330
+
305
331
  return commandBar;
306
332
  }
307
333
 
308
334
  }
309
335
 
310
336
  exports.CommandBarUI = CommandBarUI;
311
- (0, _defineProperty2().default)(CommandBarUI, "dependencies", [_ui().default, _pubsub().PubsubAspect]);
337
+ (0, _defineProperty2().default)(CommandBarUI, "dependencies", [_ui().default, _pubsub().PubsubAspect, _reactRouter().ReactRouterAspect]);
312
338
  (0, _defineProperty2().default)(CommandBarUI, "slots", [_harmony().Slot.withType(), _harmony().Slot.withType()]);
313
339
  (0, _defineProperty2().default)(CommandBarUI, "runtime", _ui().UIRuntime);
314
340
 
315
- _commandBar2().CommandBarAspect.addRuntime(CommandBarUI);
341
+ _commandBar().CommandBarAspect.addRuntime(CommandBarUI);
316
342
 
317
343
  //# sourceMappingURL=command-bar.ui.runtime.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["command-bar.ui.runtime.tsx"],"names":["RESULT_LIMIT","CommandBarUI","addSearcher","commandSearcher","searcherSlot","register","addCommand","originalCommands","forEach","id","commandId","getCommand","undefined","DuplicateCommandError","commands","map","x","displayName","handler","keybinding","commandSlot","command","addKeybinding","updateCommandsSearcher","updaters","next","run","commandEntry","relevantCommands","values","find","filter","pop","flat","update","key","mousetrap","bind","constructor","pubSub","isBrowser","Mousetrap","MousetrapStub","CommandSearcher","setVisibility","trigger","term","limit","searchers","searcher","test","search","children","sub","CommandBarAspect","e","keyboardEvent","KeyboardEvent","type","data","document","dispatchEvent","provider","uiUi","pubsubUI","config","commandSlots","commandBar","commandBarCommands","open","openCommandBarKeybinding","registerHudItem","getCommandBar","registerRenderHooks","reactContext","renderContext","UIAspect","PubsubAspect","Slot","withType","UIRuntime","addRuntime"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;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AQ,CACnB,CAACC,IAAD,EAAOC,QAAP,CADmB,EAEnBC,MAFmB,EAGnB,CAAC7D,YAAD,EAAe8D,YAAf,CAHmB,EAInB;AACA,UAAMC,UAAU,GAAG,IAAIlE,YAAJ,CAAiBG,YAAjB,EAA+B8D,YAA/B,EAA6CF,QAA7C,CAAnB;AAEAG,IAAAA,UAAU,CAAC7D,UAAX,CAAsB;AACpBG,MAAAA,EAAE,EAAE2D,kCAAmBC,IADH;AAEpBnD,MAAAA,OAAO,EAAEiD,UAAU,CAACE,IAFA;AAGpBpD,MAAAA,WAAW,EAAE,kBAHO;AAIpBE,MAAAA,UAAU,EAAEmD;AAJQ,KAAtB;AAOAP,IAAAA,IAAI,CAACQ,eAAL,CAAqBJ,UAAU,CAACK,aAAX,EAArB;AACAT,IAAAA,IAAI,CAACU,mBAAL,CAAyB;AACvBC,MAAAA,YAAY,EAAEP,UAAU,CAACQ;AADF,KAAzB;AAIA,WAAOR,UAAP;AACD;;AA/IuB;;;gCAAblE,Y,kBAwHW,CAAC2E,aAAD,EAAWC,sBAAX,C;gCAxHX5E,Y,WAyHI,CAAC6E,gBAAKC,QAAL,EAAD,EAAkCD,gBAAKC,QAAL,EAAlC,C;gCAzHJ9E,Y,aA0HM+E,e;;AAwBnB1B,gCAAiB2B,UAAjB,CAA4BhF,YAA5B","sourcesContent":["import React, { ReactNode } from 'react';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport Mousetrap from 'mousetrap';\n\nimport UIAspect, { UIRuntime, UiUI } from '@teambit/ui';\nimport { PubsubAspect, PubsubUI } from '@teambit/pubsub';\nimport { isBrowser } from '@teambit/ui-foundation.ui.is-browser';\nimport { CommandBar } from './ui/command-bar';\nimport { CommandSearcher } from './ui/command-searcher';\nimport { CommandBarAspect } from './command-bar.aspect';\nimport { commandBarCommands } from './command-bar.commands';\nimport { SearchProvider, Keybinding, CommandHandler, CommandId } from './types';\nimport { DuplicateCommandError } from './duplicate-command-error';\nimport { KeyEvent } from './model/key-event';\nimport { CommandBarContext } from './ui/command-bar-context';\nimport { MousetrapStub } from './mousetrap-stub';\nimport { openCommandBarKeybinding } from './keybinding';\n\nconst RESULT_LIMIT = 5;\ntype SearcherSlot = SlotRegistry<SearchProvider>;\ntype CommandSlot = SlotRegistry<CommandEntry[]>;\n\nexport type CommandEntry = {\n id: CommandId;\n handler: CommandHandler;\n keybinding?: Keybinding;\n displayName: string;\n};\n\n/** Quick launch actions. Use the `addSearcher` slot to extend the available actions */\nexport class CommandBarUI {\n private mousetrap = isBrowser ? new Mousetrap() : new MousetrapStub();\n private commandSearcher = new CommandSearcher([]);\n\n /** Opens the command bar */\n open = () => {\n this.setVisibility?.(true);\n return false; // aka prevent default\n };\n\n /** Closes the command bar */\n close = () => {\n this.setVisibility?.(false);\n };\n\n /** Add and autocomplete provider. To support keyboard navigation, each result should have a props `active: boolean`, and `exectue: () => any` */\n addSearcher(commandSearcher: SearchProvider) {\n this.searcherSlot.register(commandSearcher);\n return this;\n }\n\n /**\n * registers a command\n */\n addCommand(...originalCommands: CommandEntry[]) {\n originalCommands.forEach(({ id: commandId }) => {\n if (this.getCommand(commandId) !== undefined) throw new DuplicateCommandError(commandId);\n });\n\n // commands could mutate later on, clone to ensure immutability 👌\n const commands = originalCommands.map((x) => ({\n id: x.id,\n displayName: x.displayName,\n handler: x.handler,\n keybinding: x.keybinding,\n }));\n\n this.commandSlot.register(commands);\n\n commands.forEach((command) => {\n if (command.keybinding) {\n this.addKeybinding(command.keybinding, command.id);\n }\n });\n\n this.updateCommandsSearcher();\n\n const updaters = commands.map((command) => (next: CommandHandler) => {\n command.handler = next;\n });\n return updaters;\n }\n\n /**\n * executes command by name, if exists.\n * @param commandId\n */\n run(commandId: CommandId) {\n const commandEntry = this.getCommand(commandId);\n if (!commandEntry) return undefined;\n\n return commandEntry.handler();\n }\n\n /**\n * executes a keyboard shortcut manually\n */\n trigger = (key: string) => {\n this.mousetrap.trigger(key);\n };\n\n private search = (term: string, limit: number = RESULT_LIMIT) => {\n const searchers = this.searcherSlot.values();\n\n const searcher = searchers.find((x) => x.test(term));\n return searcher?.search(term, limit) || [];\n };\n\n private getCommand(id: CommandId) {\n const relevantCommands = this.commandSlot\n .values()\n .map((commands) => commands.find((command) => command.id === id))\n .filter((x) => !!x);\n\n return relevantCommands.pop();\n }\n\n private updateCommandsSearcher() {\n const commands = this.commandSlot.values().flat();\n this.commandSearcher.update(commands);\n }\n\n private addKeybinding(key: Keybinding, command: CommandId) {\n this.mousetrap.bind(key, this.run.bind(this, command));\n }\n\n private renderContext = ({ children }: { children: ReactNode }) => {\n return <CommandBarContext.Provider value={this}>{children}</CommandBarContext.Provider>;\n };\n\n /**\n * internal. Opens and closes the command bar UI.\n */\n setVisibility?: (visible: boolean) => void;\n\n /**\n * generate the ui for command bar\n */\n getCommandBar = () => {\n return <CommandBar key=\"CommandBarUI\" search={this.search} commander={this} />;\n };\n\n constructor(private searcherSlot: SearcherSlot, private commandSlot: CommandSlot, pubSub: PubsubUI) {\n this.addSearcher(this.commandSearcher);\n pubSub.sub(CommandBarAspect.id, (e: KeyEvent) => {\n const keyboardEvent = new KeyboardEvent(e.type, e.data);\n document.dispatchEvent(keyboardEvent);\n });\n }\n\n static dependencies = [UIAspect, PubsubAspect];\n static slots = [Slot.withType<SearchProvider>(), Slot.withType<CommandEntry[]>()];\n static runtime = UIRuntime;\n static async provider(\n [uiUi, pubsubUI]: [UiUI, PubsubUI],\n config,\n [searcherSlot, commandSlots]: [SearcherSlot, CommandSlot]\n ) {\n const commandBar = new CommandBarUI(searcherSlot, commandSlots, pubsubUI);\n\n commandBar.addCommand({\n id: commandBarCommands.open,\n handler: commandBar.open,\n displayName: 'Open command bar',\n keybinding: openCommandBarKeybinding,\n });\n\n uiUi.registerHudItem(commandBar.getCommandBar());\n uiUi.registerRenderHooks({\n reactContext: commandBar.renderContext,\n });\n\n return commandBar;\n }\n}\n\nCommandBarAspect.addRuntime(CommandBarUI);\n"]}
1
+ {"version":3,"sources":["command-bar.ui.runtime.tsx"],"names":["RESULT_LIMIT","CommandBarUI","addSearcher","commandSearcher","searcherSlot","register","addCommand","originalCommands","forEach","id","commandId","getCommand","undefined","DuplicateCommandError","commands","map","x","displayName","action","keybinding","commandSlot","command","addKeybinding","updateCommandsSearcher","updaters","next","run","commandEntry","relevantCommands","values","find","filter","pop","flat","update","key","mousetrap","bind","constructor","isBrowser","Mousetrap","MousetrapStub","CommandSearcher","setVisibility","trigger","term","limit","searchers","searcher","test","search","visible","styles","commanderUi","provider","uiUi","pubsubUI","config","commandSlots","commandBar","commandBarCommands","open","openCommandBarKeybinding","sub","CommandBarAspect","e","keyboardEvent","KeyboardEvent","type","data","document","dispatchEvent","registerHudItem","UIAspect","PubsubAspect","ReactRouterAspect","Slot","withType","UIRuntime","addRuntime"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;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CAAuByD,UAAU,CAACxD,eAAlC;AACAwD,IAAAA,UAAU,CAACrD,UAAX,CAAsB;AACpBG,MAAAA,EAAE,EAAEmD,kCAAmBC,IADH;AAEpB3C,MAAAA,MAAM,EAAEyC,UAAU,CAACE,IAFC;AAGpB5C,MAAAA,WAAW,EAAE,kBAHO;AAIpBE,MAAAA,UAAU,EAAE2C;AAJQ,KAAtB;;AAOA,QAAIN,QAAJ,EAAc;AACZA,MAAAA,QAAQ,CAACO,GAAT,CAAaC,+BAAiBvD,EAA9B,EAAmCwD,CAAD,IAAiB;AACjD,cAAMC,aAAa,GAAG,IAAIC,aAAJ,CAAkBF,CAAC,CAACG,IAApB,EAA0BH,CAAC,CAACI,IAA5B,CAAtB;AACAC,QAAAA,QAAQ,CAACC,aAAT,CAAuBL,aAAvB;AACD,OAHD;AAID;;AAED,QAAIX,IAAJ,EAAU;AACRA,MAAAA,IAAI,CAACiB,eAAL,eAAqB,+BAAC,UAAD,CAAY,UAAZ,OAArB;AACD;;AAED,WAAOb,UAAP;AACD;;AAxJuB;;;gCAAb1D,Y,kBA0HW,CAACwE,aAAD,EAAWC,sBAAX,EAAyBC,gCAAzB,C;gCA1HX1E,Y,WA2HI,CAAC2E,gBAAKC,QAAL,EAAD,EAAkCD,gBAAKC,QAAL,EAAlC,C;gCA3HJ5E,Y,aA4HM6E,e;;AA+BnBd,+BAAiBe,UAAjB,CAA4B9E,YAA5B","sourcesContent":["import React, { useState } from 'react';\nimport flatten from 'lodash.flatten';\nimport Mousetrap from 'mousetrap';\n\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport UIAspect, { UIRuntime, UiUI } from '@teambit/ui';\nimport { PubsubAspect, PubsubUI } from '@teambit/pubsub';\nimport { ReactRouterAspect } from '@teambit/react-router';\nimport { isBrowser } from '@teambit/ui-foundation.ui.is-browser';\nimport { CommandBar } from '@teambit/explorer.ui.command-bar';\nimport { CommandBarAspect } from './command-bar.aspect';\nimport { commandBarCommands } from './command-bar.commands';\nimport { CommandSearcher, SearchProvider } from './searchers';\nimport { Keybinding, CommandHandler, CommandId } from './types';\nimport { DuplicateCommandError } from './duplicate-command-error';\nimport { KeyEvent } from './model/key-event';\nimport { MousetrapStub } from './mousetrap-stub';\nimport { openCommandBarKeybinding } from './keybinding';\n\nimport styles from './command-bar.module.scss';\n\nconst RESULT_LIMIT = 5;\ntype SearcherSlot = SlotRegistry<SearchProvider[]>;\ntype CommandSlot = SlotRegistry<CommandEntry[]>;\n\nexport type CommandEntry = {\n id: CommandId;\n action: CommandHandler;\n keybinding?: Keybinding;\n displayName: string;\n};\n\n/** Quick launch actions. Use the `addSearcher` slot to extend the available actions */\nexport class CommandBarUI {\n private mousetrap = isBrowser ? new Mousetrap() : new MousetrapStub();\n private commandSearcher = new CommandSearcher([]);\n\n /** Opens the command bar */\n open = () => {\n this.setVisibility?.(true);\n return false; // aka prevent default\n };\n\n /** Closes the command bar */\n close = () => {\n this.setVisibility?.(false);\n };\n\n /** Add and autocomplete provider. To support keyboard navigation, each result should have a props `active: boolean`, and `exectue: () => any` */\n addSearcher(...commandSearcher: SearchProvider[]) {\n this.searcherSlot.register(commandSearcher);\n return this;\n }\n\n /**\n * registers a command\n */\n addCommand(...originalCommands: CommandEntry[]) {\n originalCommands.forEach(({ id: commandId }) => {\n if (this.getCommand(commandId) !== undefined) throw new DuplicateCommandError(commandId);\n });\n\n // commands could mutate later on, clone to ensure immutability 👌\n const commands = originalCommands.map((x) => ({\n id: x.id,\n displayName: x.displayName,\n action: x.action,\n keybinding: x.keybinding,\n }));\n\n this.commandSlot.register(commands);\n\n commands.forEach((command) => {\n if (command.keybinding) {\n this.addKeybinding(command.keybinding, command.id);\n }\n });\n\n this.updateCommandsSearcher();\n\n const updaters = commands.map((command) => (next: CommandHandler) => {\n command.action = next;\n });\n return updaters;\n }\n\n /**\n * executes command by name, if exists.\n * @param commandId\n */\n run(commandId: CommandId) {\n const commandEntry = this.getCommand(commandId);\n if (!commandEntry) return undefined;\n\n return commandEntry.action();\n }\n\n /**\n * executes a keyboard shortcut manually\n */\n trigger = (key: string) => {\n this.mousetrap.trigger(key);\n };\n\n private search = (term: string, limit: number = RESULT_LIMIT) => {\n const searchers = flatten(this.searcherSlot.values());\n\n const searcher = searchers.find((x) => x.test(term));\n return searcher?.search(term, limit) || [];\n };\n\n private getCommand(id: CommandId) {\n const relevantCommands = this.commandSlot\n .values()\n .map((commands) => commands.find((command) => command.id === id))\n .filter((x) => !!x);\n\n return relevantCommands.pop();\n }\n\n private updateCommandsSearcher() {\n const commands = this.commandSlot.values().flat();\n this.commandSearcher.update(commands);\n }\n\n private addKeybinding(key: Keybinding, command: CommandId) {\n this.mousetrap.bind(key, this.run.bind(this, command));\n }\n\n /**\n * Opens and closes the command bar UI.\n */\n private setVisibility?: (visible: boolean) => void;\n\n /**\n * generate the ui for command bar\n */\n private CommandBar = () => {\n const [visible, setVisibility] = useState(false);\n this.setVisibility = setVisibility;\n\n return (\n <CommandBar\n key=\"CommandBarUI\"\n className={styles.commanderUi}\n searcher={this.search}\n placeholder=\"Search anything or type > to only search commands\"\n visible={visible}\n onVisibilityChange={setVisibility}\n />\n );\n };\n\n constructor(private searcherSlot: SearcherSlot, private commandSlot: CommandSlot) {}\n\n static dependencies = [UIAspect, PubsubAspect, ReactRouterAspect];\n static slots = [Slot.withType<SearchProvider>(), Slot.withType<CommandEntry[]>()];\n static runtime = UIRuntime;\n static async provider(\n [uiUi, pubsubUI]: [UiUI | undefined, PubsubUI | undefined],\n config,\n [searcherSlot, commandSlots]: [SearcherSlot, CommandSlot]\n ) {\n const commandBar = new CommandBarUI(searcherSlot, commandSlots);\n\n commandBar.addSearcher(commandBar.commandSearcher);\n commandBar.addCommand({\n id: commandBarCommands.open,\n action: commandBar.open,\n displayName: 'Open command bar',\n keybinding: openCommandBarKeybinding,\n });\n\n if (pubsubUI) {\n pubsubUI.sub(CommandBarAspect.id, (e: KeyEvent) => {\n const keyboardEvent = new KeyboardEvent(e.type, e.data);\n document.dispatchEvent(keyboardEvent);\n });\n }\n\n if (uiUi) {\n uiUi.registerHudItem(<commandBar.CommandBar />);\n }\n\n return commandBar;\n }\n}\n\nCommandBarAspect.addRuntime(CommandBarUI);\n"]}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { CommandBarAspect, CommandBarAspect as default } from './command-bar.aspect';
2
2
  export { commandBarCommands } from './command-bar.commands';
3
- export { ComponentSearcher } from './ui/component-searcher';
4
- export { CommandBarContext } from './ui/command-bar-context';
3
+ export type { SearchProvider } from './searchers';
5
4
  export type { CommandBarUI, CommandEntry } from './command-bar.ui.runtime';
6
- export type { CommandHandler, CommanderSearchResult, CommandId, Keybinding, SearchProvider } from './types';
5
+ export type { CommandHandler, CommandId, Keybinding } from './types';
6
+ export type { SearchResult } from '@teambit/explorer.ui.command-bar';
package/dist/index.js CHANGED
@@ -9,18 +9,6 @@ Object.defineProperty(exports, "CommandBarAspect", {
9
9
  return _commandBar().CommandBarAspect;
10
10
  }
11
11
  });
12
- Object.defineProperty(exports, "CommandBarContext", {
13
- enumerable: true,
14
- get: function () {
15
- return _commandBarContext().CommandBarContext;
16
- }
17
- });
18
- Object.defineProperty(exports, "ComponentSearcher", {
19
- enumerable: true,
20
- get: function () {
21
- return _componentSearcher().ComponentSearcher;
22
- }
23
- });
24
12
  Object.defineProperty(exports, "commandBarCommands", {
25
13
  enumerable: true,
26
14
  get: function () {
@@ -54,24 +42,4 @@ function _commandBar2() {
54
42
  return data;
55
43
  }
56
44
 
57
- function _componentSearcher() {
58
- const data = require("./ui/component-searcher");
59
-
60
- _componentSearcher = function () {
61
- return data;
62
- };
63
-
64
- return data;
65
- }
66
-
67
- function _commandBarContext() {
68
- const data = require("./ui/command-bar-context");
69
-
70
- _commandBarContext = function () {
71
- return data;
72
- };
73
-
74
- return data;
75
- }
76
-
77
45
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA","sourcesContent":["export { CommandBarAspect, CommandBarAspect as default } from './command-bar.aspect';\nexport { commandBarCommands } from './command-bar.commands';\nexport { ComponentSearcher } from './ui/component-searcher';\nexport { CommandBarContext } from './ui/command-bar-context';\nexport type { CommandBarUI, CommandEntry } from './command-bar.ui.runtime';\nexport type { CommandHandler, CommanderSearchResult, CommandId, Keybinding, SearchProvider } from './types';\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA","sourcesContent":["export { CommandBarAspect, CommandBarAspect as default } from './command-bar.aspect';\nexport { commandBarCommands } from './command-bar.commands';\nexport type { SearchProvider } from './searchers';\nexport type { CommandBarUI, CommandEntry } from './command-bar.ui.runtime';\nexport type { CommandHandler, CommandId, Keybinding } from './types';\nexport type { SearchResult } from '@teambit/explorer.ui.command-bar';\n"]}
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import { Command } from './command';
3
+ declare type CommandResultProps = {
4
+ command: Command;
5
+ };
6
+ export declare function CommandResult({ command }: CommandResultProps): JSX.Element;
7
+ export {};