@teambit/command-bar 0.0.804 → 0.0.807
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.
- package/command-bar.ui.runtime.tsx +24 -9
- package/dist/command-bar.ui.runtime.d.ts +12 -4
- package/dist/command-bar.ui.runtime.js +16 -5
- package/dist/command-bar.ui.runtime.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -1
- package/dist/searchers/command-searcher/command-searcher.d.ts +2 -2
- package/dist/searchers/command-searcher/command-searcher.js +1 -1
- package/dist/searchers/command-searcher/command-searcher.js.map +1 -1
- package/dist/searchers/search-provider.d.ts +2 -2
- package/dist/searchers/search-provider.js.map +1 -1
- package/package-tar/teambit-command-bar-0.0.807.tgz +0 -0
- package/package.json +9 -9
- package/{preview-1659347901202.js → preview-1659583874630.js} +2 -2
- package/searchers/command-searcher/command-searcher.tsx +2 -2
- package/searchers/search-provider.ts +2 -2
- package/package-tar/teambit-command-bar-0.0.804.tgz +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
1
|
+
import React, { useState, ComponentType } from 'react';
|
|
2
2
|
import flatten from 'lodash.flatten';
|
|
3
3
|
import Mousetrap from 'mousetrap';
|
|
4
4
|
import { Slot, SlotRegistry } from '@teambit/harmony';
|
|
@@ -6,7 +6,7 @@ import UIAspect, { UIRuntime, UiUI } from '@teambit/ui';
|
|
|
6
6
|
import { PubsubAspect, PubsubUI } from '@teambit/pubsub';
|
|
7
7
|
import { ReactRouterAspect } from '@teambit/react-router';
|
|
8
8
|
import { isBrowser } from '@teambit/ui-foundation.ui.is-browser';
|
|
9
|
-
import { CommandBar, useSearcher } from '@teambit/explorer.ui.command-bar';
|
|
9
|
+
import { CommandBar, useSearcher, ResultsComponentProps } from '@teambit/explorer.ui.command-bar';
|
|
10
10
|
import { CommandBarAspect } from './command-bar.aspect';
|
|
11
11
|
import { commandBarCommands } from './command-bar.commands';
|
|
12
12
|
import { CommandSearcher, SearchProvider } from './searchers';
|
|
@@ -15,13 +15,16 @@ import { DuplicateCommandError } from './duplicate-command-error';
|
|
|
15
15
|
import { KeyEvent } from './model/key-event';
|
|
16
16
|
import { MousetrapStub } from './mousetrap-stub';
|
|
17
17
|
import { openCommandBarKeybinding } from './keybinding';
|
|
18
|
-
|
|
19
18
|
import styles from './command-bar.module.scss';
|
|
20
19
|
|
|
21
20
|
const RESULT_LIMIT = 5;
|
|
22
21
|
type SearcherSlot = SlotRegistry<SearchProvider[]>;
|
|
23
22
|
type CommandSlot = SlotRegistry<CommandEntry[]>;
|
|
24
23
|
|
|
24
|
+
export type CommandBarConfig = {
|
|
25
|
+
debounce?: number
|
|
26
|
+
};
|
|
27
|
+
|
|
25
28
|
export type CommandEntry = {
|
|
26
29
|
id: CommandId;
|
|
27
30
|
action: CommandHandler;
|
|
@@ -105,7 +108,7 @@ export class CommandBarUI {
|
|
|
105
108
|
const searchers = flatten(this.searcherSlot.values());
|
|
106
109
|
|
|
107
110
|
const searcher = searchers.find((x) => x && x.test(term));
|
|
108
|
-
return searcher?.search(term, limit) || [];
|
|
111
|
+
return searcher?.search(term, limit) || { items: [] };
|
|
109
112
|
};
|
|
110
113
|
|
|
111
114
|
private getCommand(id: CommandId) {
|
|
@@ -134,11 +137,13 @@ export class CommandBarUI {
|
|
|
134
137
|
/**
|
|
135
138
|
* generate the ui for command bar
|
|
136
139
|
*/
|
|
137
|
-
CommandBar = () => {
|
|
140
|
+
CommandBar = ({ ResultComponent }: { ResultComponent?: ComponentType<ResultsComponentProps> }) => {
|
|
138
141
|
const [visible, setVisibility] = useState(false);
|
|
139
142
|
this.setVisibility = setVisibility;
|
|
140
143
|
|
|
141
|
-
const results = useSearcher(this.search
|
|
144
|
+
const results = useSearcher(this.search, {
|
|
145
|
+
debounce: this.config.debounce
|
|
146
|
+
});
|
|
142
147
|
|
|
143
148
|
return (
|
|
144
149
|
<CommandBar
|
|
@@ -147,23 +152,33 @@ export class CommandBarUI {
|
|
|
147
152
|
className={styles.commanderUi}
|
|
148
153
|
placeholder="Search anything or type > to only search commands"
|
|
149
154
|
visible={visible}
|
|
155
|
+
ResultsComponent={ResultComponent}
|
|
150
156
|
onVisibilityChange={setVisibility}
|
|
151
157
|
autofocus
|
|
152
158
|
/>
|
|
153
159
|
);
|
|
154
160
|
};
|
|
155
161
|
|
|
156
|
-
constructor(
|
|
162
|
+
constructor(
|
|
163
|
+
private searcherSlot: SearcherSlot,
|
|
164
|
+
private commandSlot: CommandSlot,
|
|
165
|
+
private config: CommandBarConfig
|
|
166
|
+
) {}
|
|
157
167
|
|
|
158
168
|
static dependencies = [UIAspect, PubsubAspect, ReactRouterAspect];
|
|
159
169
|
static slots = [Slot.withType<SearchProvider>(), Slot.withType<CommandEntry[]>()];
|
|
170
|
+
static defaultConfig: CommandBarConfig = {
|
|
171
|
+
debounce: undefined
|
|
172
|
+
};
|
|
173
|
+
|
|
160
174
|
static runtime = UIRuntime;
|
|
175
|
+
|
|
161
176
|
static async provider(
|
|
162
177
|
[uiUi, pubsubUI]: [UiUI | undefined, PubsubUI | undefined],
|
|
163
|
-
config,
|
|
178
|
+
config: CommandBarConfig,
|
|
164
179
|
[searcherSlot, commandSlots]: [SearcherSlot, CommandSlot]
|
|
165
180
|
) {
|
|
166
|
-
const commandBar = new CommandBarUI(searcherSlot, commandSlots);
|
|
181
|
+
const commandBar = new CommandBarUI(searcherSlot, commandSlots, config);
|
|
167
182
|
|
|
168
183
|
commandBar.addSearcher(commandBar.commandSearcher);
|
|
169
184
|
commandBar.addCommand({
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import React, { ComponentType } from 'react';
|
|
2
2
|
import { SlotRegistry } from '@teambit/harmony';
|
|
3
3
|
import { UiUI } from '@teambit/ui';
|
|
4
4
|
import { PubsubUI } from '@teambit/pubsub';
|
|
5
|
+
import { ResultsComponentProps } from '@teambit/explorer.ui.command-bar';
|
|
5
6
|
import { SearchProvider } from './searchers';
|
|
6
7
|
import { Keybinding, CommandHandler, CommandId } from './types';
|
|
7
8
|
declare type SearcherSlot = SlotRegistry<SearchProvider[]>;
|
|
8
9
|
declare type CommandSlot = SlotRegistry<CommandEntry[]>;
|
|
10
|
+
export declare type CommandBarConfig = {
|
|
11
|
+
debounce?: number;
|
|
12
|
+
};
|
|
9
13
|
export declare type CommandEntry = {
|
|
10
14
|
id: CommandId;
|
|
11
15
|
action: CommandHandler;
|
|
@@ -16,6 +20,7 @@ export declare type CommandEntry = {
|
|
|
16
20
|
export declare class CommandBarUI {
|
|
17
21
|
private searcherSlot;
|
|
18
22
|
private commandSlot;
|
|
23
|
+
private config;
|
|
19
24
|
private mousetrap;
|
|
20
25
|
private commandSearcher;
|
|
21
26
|
/** Opens the command bar */
|
|
@@ -48,11 +53,14 @@ export declare class CommandBarUI {
|
|
|
48
53
|
/**
|
|
49
54
|
* generate the ui for command bar
|
|
50
55
|
*/
|
|
51
|
-
CommandBar: (
|
|
52
|
-
|
|
56
|
+
CommandBar: ({ ResultComponent }: {
|
|
57
|
+
ResultComponent?: React.ComponentType<ResultsComponentProps<import("@teambit/explorer.ui.command-bar").SearchResult[], any>> | undefined;
|
|
58
|
+
}) => JSX.Element;
|
|
59
|
+
constructor(searcherSlot: SearcherSlot, commandSlot: CommandSlot, config: CommandBarConfig);
|
|
53
60
|
static dependencies: import("@teambit/harmony").Aspect[];
|
|
54
61
|
static slots: (((registerFn: () => string) => SlotRegistry<SearchProvider>) | ((registerFn: () => string) => SlotRegistry<CommandEntry[]>))[];
|
|
62
|
+
static defaultConfig: CommandBarConfig;
|
|
55
63
|
static runtime: import("@teambit/harmony").RuntimeDefinition;
|
|
56
|
-
static provider([uiUi, pubsubUI]: [UiUI | undefined, PubsubUI | undefined], config:
|
|
64
|
+
static provider([uiUi, pubsubUI]: [UiUI | undefined, PubsubUI | undefined], config: CommandBarConfig, [searcherSlot, commandSlots]: [SearcherSlot, CommandSlot]): Promise<CommandBarUI>;
|
|
57
65
|
}
|
|
58
66
|
export {};
|
|
@@ -278,9 +278,10 @@ class CommandBarUI {
|
|
|
278
278
|
*/
|
|
279
279
|
|
|
280
280
|
|
|
281
|
-
constructor(searcherSlot, commandSlot) {
|
|
281
|
+
constructor(searcherSlot, commandSlot, config) {
|
|
282
282
|
this.searcherSlot = searcherSlot;
|
|
283
283
|
this.commandSlot = commandSlot;
|
|
284
|
+
this.config = config;
|
|
284
285
|
(0, _defineProperty2().default)(this, "mousetrap", _uiFoundationUi().isBrowser ? new (_mousetrap().default)() : new (_mousetrapStub().MousetrapStub)());
|
|
285
286
|
(0, _defineProperty2().default)(this, "commandSearcher", new (_searchers().CommandSearcher)([]));
|
|
286
287
|
(0, _defineProperty2().default)(this, "open", () => {
|
|
@@ -300,18 +301,25 @@ class CommandBarUI {
|
|
|
300
301
|
(0, _defineProperty2().default)(this, "search", (term, limit = RESULT_LIMIT) => {
|
|
301
302
|
const searchers = (0, _lodash().default)(this.searcherSlot.values());
|
|
302
303
|
const searcher = searchers.find(x => x && x.test(term));
|
|
303
|
-
return (searcher === null || searcher === void 0 ? void 0 : searcher.search(term, limit)) ||
|
|
304
|
+
return (searcher === null || searcher === void 0 ? void 0 : searcher.search(term, limit)) || {
|
|
305
|
+
items: []
|
|
306
|
+
};
|
|
304
307
|
});
|
|
305
308
|
(0, _defineProperty2().default)(this, "setVisibility", void 0);
|
|
306
|
-
(0, _defineProperty2().default)(this, "CommandBar", (
|
|
309
|
+
(0, _defineProperty2().default)(this, "CommandBar", ({
|
|
310
|
+
ResultComponent
|
|
311
|
+
}) => {
|
|
307
312
|
const [visible, setVisibility] = (0, _react().useState)(false);
|
|
308
313
|
this.setVisibility = setVisibility;
|
|
309
|
-
const results = (0, _explorerUi().useSearcher)(this.search
|
|
314
|
+
const results = (0, _explorerUi().useSearcher)(this.search, {
|
|
315
|
+
debounce: this.config.debounce
|
|
316
|
+
});
|
|
310
317
|
return /*#__PURE__*/_react().default.createElement(_explorerUi().CommandBar, (0, _extends2().default)({}, results, {
|
|
311
318
|
key: "CommandBarUI",
|
|
312
319
|
className: _commandBarModule().default.commanderUi,
|
|
313
320
|
placeholder: "Search anything or type > to only search commands",
|
|
314
321
|
visible: visible,
|
|
322
|
+
ResultsComponent: ResultComponent,
|
|
315
323
|
onVisibilityChange: setVisibility,
|
|
316
324
|
autofocus: true
|
|
317
325
|
}));
|
|
@@ -319,7 +327,7 @@ class CommandBarUI {
|
|
|
319
327
|
}
|
|
320
328
|
|
|
321
329
|
static async provider([uiUi, pubsubUI], config, [searcherSlot, commandSlots]) {
|
|
322
|
-
const commandBar = new CommandBarUI(searcherSlot, commandSlots);
|
|
330
|
+
const commandBar = new CommandBarUI(searcherSlot, commandSlots, config);
|
|
323
331
|
commandBar.addSearcher(commandBar.commandSearcher);
|
|
324
332
|
commandBar.addCommand({
|
|
325
333
|
id: _commandBar2().commandBarCommands.open,
|
|
@@ -347,6 +355,9 @@ class CommandBarUI {
|
|
|
347
355
|
exports.CommandBarUI = CommandBarUI;
|
|
348
356
|
(0, _defineProperty2().default)(CommandBarUI, "dependencies", [_ui().default, _pubsub().PubsubAspect, _reactRouter().ReactRouterAspect]);
|
|
349
357
|
(0, _defineProperty2().default)(CommandBarUI, "slots", [_harmony().Slot.withType(), _harmony().Slot.withType()]);
|
|
358
|
+
(0, _defineProperty2().default)(CommandBarUI, "defaultConfig", {
|
|
359
|
+
debounce: undefined
|
|
360
|
+
});
|
|
350
361
|
(0, _defineProperty2().default)(CommandBarUI, "runtime", _ui().UIRuntime);
|
|
351
362
|
|
|
352
363
|
_commandBar().CommandBarAspect.addRuntime(CommandBarUI);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"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","flatten","searcher","test","search","visible","useState","results","useSearcher","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"],"sources":["command-bar.ui.runtime.tsx"],"sourcesContent":["import React, { useState } from 'react';\nimport flatten from 'lodash.flatten';\nimport Mousetrap from 'mousetrap';\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, useSearcher } 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 && 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 CommandBar = () => {\n const [visible, setVisibility] = useState(false);\n this.setVisibility = setVisibility;\n\n const results = useSearcher(this.search);\n\n return (\n <CommandBar\n {...results}\n key=\"CommandBarUI\"\n className={styles.commanderUi}\n placeholder=\"Search anything or type > to only search commands\"\n visible={visible}\n onVisibilityChange={setVisibility}\n autofocus\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAA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IT","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","config","isBrowser","Mousetrap","MousetrapStub","CommandSearcher","setVisibility","trigger","term","limit","searchers","flatten","searcher","test","search","items","ResultComponent","visible","useState","results","useSearcher","debounce","styles","commanderUi","provider","uiUi","pubsubUI","commandSlots","commandBar","commandBarCommands","open","openCommandBarKeybinding","sub","CommandBarAspect","e","keyboardEvent","KeyboardEvent","type","data","document","dispatchEvent","registerHudItem","UIAspect","PubsubAspect","ReactRouterAspect","Slot","withType","UIRuntime","addRuntime"],"sources":["command-bar.ui.runtime.tsx"],"sourcesContent":["import React, { useState, ComponentType } from 'react';\nimport flatten from 'lodash.flatten';\nimport Mousetrap from 'mousetrap';\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, useSearcher, ResultsComponentProps } 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';\nimport styles from './command-bar.module.scss';\n\nconst RESULT_LIMIT = 5;\ntype SearcherSlot = SlotRegistry<SearchProvider[]>;\ntype CommandSlot = SlotRegistry<CommandEntry[]>;\n\nexport type CommandBarConfig = {\n debounce?: number\n};\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 && x.test(term));\n return searcher?.search(term, limit) || { items: [] };\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 CommandBar = ({ ResultComponent }: { ResultComponent?: ComponentType<ResultsComponentProps> }) => {\n const [visible, setVisibility] = useState(false);\n this.setVisibility = setVisibility;\n\n const results = useSearcher(this.search, {\n debounce: this.config.debounce\n });\n\n return (\n <CommandBar\n {...results}\n key=\"CommandBarUI\"\n className={styles.commanderUi}\n placeholder=\"Search anything or type > to only search commands\"\n visible={visible}\n ResultsComponent={ResultComponent}\n onVisibilityChange={setVisibility}\n autofocus\n />\n );\n };\n\n constructor(\n private searcherSlot: SearcherSlot, \n private commandSlot: CommandSlot,\n private config: CommandBarConfig\n ) {}\n\n static dependencies = [UIAspect, PubsubAspect, ReactRouterAspect];\n static slots = [Slot.withType<SearchProvider>(), Slot.withType<CommandEntry[]>()];\n static defaultConfig: CommandBarConfig = {\n debounce: undefined\n };\n\n static runtime = UIRuntime;\n \n static async provider(\n [uiUi, pubsubUI]: [UiUI | undefined, PubsubUI | undefined],\n config: CommandBarConfig,\n [searcherSlot, commandSlots]: [SearcherSlot, CommandSlot]\n ) {\n const commandBar = new CommandBarUI(searcherSlot, commandSlots, config);\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.addRunt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IAAiB;QACjD,MAAMC,aAAa,GAAG,IAAIC,aAAJ,CAAkBF,CAAC,CAACG,IAApB,EAA0BH,CAAC,CAACI,IAA5B,CAAtB;QACAC,QAAQ,CAACC,aAAT,CAAuBL,aAAvB;MACD,CAHD;IAID;;IAED,IAAIV,IAAJ,EAAU;MACRA,IAAI,CAACgB,eAAL,eAAqB,+BAAC,UAAD,CAAY,UAAZ,OAArB;IACD;;IAED,OAAOb,UAAP;EACD;;AAvKuB;;;gCAAbjE,Y,kBAoIW,CAAC+E,aAAD,EAAWC,sBAAX,EAAyBC,gCAAzB,C;gCApIXjF,Y,WAqII,CAACkF,eAAA,CAAKC,QAAL,EAAD,EAAkCD,eAAA,CAAKC,QAAL,EAAlC,C;gCArIJnF,Y,mBAsI8B;EACvC0D,QAAQ,EAAE/C;AAD6B,C;gCAtI9BX,Y,aA0IMoF,e;;AAgCnBd,8BAAA,CAAiBe,UAAjB,CAA4BrF,YAA5B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export { commandBarCommands } from './command-bar.commands';
|
|
|
3
3
|
export type { SearchProvider } from './searchers';
|
|
4
4
|
export type { CommandBarUI, CommandEntry } from './command-bar.ui.runtime';
|
|
5
5
|
export type { CommandHandler, CommandId, Keybinding } from './types';
|
|
6
|
-
export type { SearchResult } from '@teambit/explorer.ui.command-bar';
|
|
6
|
+
export type { SearchResult, ResultsComponentProps, SearchResults } from '@teambit/explorer.ui.command-bar';
|
|
7
|
+
export { FuzzySearcher, FuzzySearchItem, CommandBarItem } from '@teambit/explorer.ui.command-bar';
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,24 @@ Object.defineProperty(exports, "CommandBarAspect", {
|
|
|
9
9
|
return _commandBar().CommandBarAspect;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
+
Object.defineProperty(exports, "CommandBarItem", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _explorerUi().CommandBarItem;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "FuzzySearchItem", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _explorerUi().FuzzySearchItem;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "FuzzySearcher", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _explorerUi().FuzzySearcher;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
12
30
|
Object.defineProperty(exports, "commandBarCommands", {
|
|
13
31
|
enumerable: true,
|
|
14
32
|
get: function () {
|
|
@@ -42,4 +60,14 @@ function _commandBar2() {
|
|
|
42
60
|
return data;
|
|
43
61
|
}
|
|
44
62
|
|
|
63
|
+
function _explorerUi() {
|
|
64
|
+
const data = require("@teambit/explorer.ui.command-bar");
|
|
65
|
+
|
|
66
|
+
_explorerUi = function () {
|
|
67
|
+
return data;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return data;
|
|
71
|
+
}
|
|
72
|
+
|
|
45
73
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"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"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"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, ResultsComponentProps, SearchResults } from '@teambit/explorer.ui.command-bar';\nexport { FuzzySearcher, FuzzySearchItem, CommandBarItem } from '@teambit/explorer.ui.command-bar';\n "],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAKA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FuzzySearcher, SearchResult, FuzzySearchItem } from '@teambit/explorer.ui.command-bar';
|
|
2
2
|
import { SearchProvider } from '../search-provider';
|
|
3
3
|
import { Command } from './command';
|
|
4
|
-
export declare class CommandSearcher extends
|
|
4
|
+
export declare class CommandSearcher extends FuzzySearcher<Command, Command> implements SearchProvider {
|
|
5
5
|
constructor(commands: Command[]);
|
|
6
6
|
test(term: string): boolean;
|
|
7
7
|
protected toSearchableItem(item: Command): Command;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["searchKeys","CommandSearcher","
|
|
1
|
+
{"version":3,"names":["searchKeys","CommandSearcher","FuzzySearcher","constructor","commands","update","test","term","startsWith","toSearchableItem","item","toSearchResult","id","action","children"],"sources":["command-searcher.tsx"],"sourcesContent":["import React from 'react';\nimport { FuzzySearcher, SearchResult, FuzzySearchItem } from '@teambit/explorer.ui.command-bar';\nimport { SearchProvider } from '../search-provider';\nimport { CommandResult } from './command-result';\nimport { Command } from './command';\n\nconst searchKeys: (keyof Command)[] = ['displayName'];\n\nexport class CommandSearcher extends FuzzySearcher<Command, Command> implements SearchProvider {\n constructor(commands: Command[]) {\n super({ searchKeys });\n\n this.update(commands);\n }\n\n override test(term: string): boolean {\n return term.startsWith('>');\n }\n\n protected override toSearchableItem(item: Command) {\n return item;\n }\n\n protected override toSearchResult({ item }: FuzzySearchItem<Command>): SearchResult {\n return {\n id: item.id,\n action: item.action,\n children: <CommandResult command={item} />,\n };\n }\n}\n"],"mappings":";;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA,MAAMA,UAA6B,GAAG,CAAC,aAAD,CAAtC;;AAEO,MAAMC,eAAN,SAA8BC,2BAA9B,CAAwF;EAC7FC,WAAW,CAACC,QAAD,EAAsB;IAC/B,MAAM;MAAEJ;IAAF,CAAN;IAEA,KAAKK,MAAL,CAAYD,QAAZ;EACD;;EAEQE,IAAI,CAACC,IAAD,EAAwB;IACnC,OAAOA,IAAI,CAACC,UAAL,CAAgB,GAAhB,CAAP;EACD;;EAEkBC,gBAAgB,CAACC,IAAD,EAAgB;IACjD,OAAOA,IAAP;EACD;;EAEkBC,cAAc,CAAC;IAAED;EAAF,CAAD,EAAmD;IAClF,OAAO;MACLE,EAAE,EAAEF,IAAI,CAACE,EADJ;MAELC,MAAM,EAAEH,IAAI,CAACG,MAFR;MAGLC,QAAQ,eAAE,+BAAC,8BAAD;QAAe,OAAO,EAAEJ;MAAxB;IAHL,CAAP;EAKD;;AArB4F"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SearchProvider as Searcher } from '@teambit/explorer.ui.command-bar';
|
|
2
2
|
export interface SearchProvider {
|
|
3
3
|
/** provide completions for this search term */
|
|
4
|
-
search
|
|
4
|
+
search: Searcher;
|
|
5
5
|
/** determines what terms are handled by this searcher. */
|
|
6
6
|
test(term: string): boolean;
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["search-provider.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"names":[],"sources":["search-provider.ts"],"sourcesContent":["import { SearchProvider as Searcher } from '@teambit/explorer.ui.command-bar';\n\nexport interface SearchProvider {\n /** provide completions for this search term */\n search: Searcher,\n /** determines what terms are handled by this searcher. */\n test(term: string): boolean;\n}\n"],"mappings":""}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/command-bar",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.807",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/explorer/command-bar",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.explorer",
|
|
8
8
|
"name": "command-bar",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.807"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"lodash.flatten": "4.4.0",
|
|
13
13
|
"mousetrap": "1.6.5",
|
|
14
|
-
"is-primitive": "3.0.1",
|
|
15
14
|
"classnames": "2.2.6",
|
|
15
|
+
"is-primitive": "3.0.1",
|
|
16
16
|
"@babel/runtime": "7.12.18",
|
|
17
17
|
"core-js": "^3.0.0",
|
|
18
18
|
"@teambit/harmony": "0.3.3",
|
|
19
|
-
"@teambit/explorer.ui.command-bar": "2.0.
|
|
19
|
+
"@teambit/explorer.ui.command-bar": "2.0.3",
|
|
20
20
|
"@teambit/base-ui.text.muted-text": "1.0.1",
|
|
21
|
-
"@teambit/preview": "0.0.
|
|
22
|
-
"@teambit/pubsub": "0.0.
|
|
23
|
-
"@teambit/react-router": "0.0.
|
|
21
|
+
"@teambit/preview": "0.0.807",
|
|
22
|
+
"@teambit/pubsub": "0.0.807",
|
|
23
|
+
"@teambit/react-router": "0.0.807",
|
|
24
24
|
"@teambit/ui-foundation.ui.is-browser": "0.0.486",
|
|
25
|
-
"@teambit/ui": "0.0.
|
|
25
|
+
"@teambit/ui": "0.0.807",
|
|
26
26
|
"@teambit/bit-error": "0.0.394",
|
|
27
27
|
"@teambit/design.ui.styles.ellipsis": "0.0.347",
|
|
28
28
|
"@teambit/ui-foundation.ui.keycap": "0.0.486"
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@types/node": "12.20.4"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@teambit/legacy": "1.0.
|
|
42
|
+
"@teambit/legacy": "1.0.321",
|
|
43
43
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
44
44
|
"react": "^16.8.0 || ^17.0.0"
|
|
45
45
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.explorer_command-bar@0.0.
|
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.explorer_command-bar@0.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.explorer_command-bar@0.0.807/dist/command-bar.composition.js';
|
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.explorer_command-bar@0.0.807/dist/command-bar.docs.mdx';
|
|
3
3
|
|
|
4
4
|
export const compositions = [compositions_0];
|
|
5
5
|
export const overview = [overview_0];
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { FuzzySearcher, SearchResult, FuzzySearchItem } from '@teambit/explorer.ui.command-bar';
|
|
3
3
|
import { SearchProvider } from '../search-provider';
|
|
4
4
|
import { CommandResult } from './command-result';
|
|
5
5
|
import { Command } from './command';
|
|
6
6
|
|
|
7
7
|
const searchKeys: (keyof Command)[] = ['displayName'];
|
|
8
8
|
|
|
9
|
-
export class CommandSearcher extends
|
|
9
|
+
export class CommandSearcher extends FuzzySearcher<Command, Command> implements SearchProvider {
|
|
10
10
|
constructor(commands: Command[]) {
|
|
11
11
|
super({ searchKeys });
|
|
12
12
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SearchProvider as Searcher } from '@teambit/explorer.ui.command-bar';
|
|
2
2
|
|
|
3
3
|
export interface SearchProvider {
|
|
4
4
|
/** provide completions for this search term */
|
|
5
|
-
search
|
|
5
|
+
search: Searcher,
|
|
6
6
|
/** determines what terms are handled by this searcher. */
|
|
7
7
|
test(term: string): boolean;
|
|
8
8
|
}
|
|
Binary file
|