@teambit/component 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.
- package/component.ui.runtime.tsx +53 -20
- package/dist/component.ui.runtime.d.ts +21 -11
- package/dist/component.ui.runtime.js +95 -37
- package/dist/component.ui.runtime.js.map +1 -1
- package/dist/ui/component-searcher/component-result.d.ts +16 -0
- package/dist/ui/component-searcher/component-result.js +91 -0
- package/dist/ui/component-searcher/component-result.js.map +1 -0
- package/dist/ui/component-searcher/component-result.module.scss +13 -0
- package/dist/ui/component-searcher/component-searcher.d.ts +22 -0
- package/dist/ui/component-searcher/component-searcher.js +105 -0
- package/dist/ui/component-searcher/component-searcher.js.map +1 -0
- package/dist/ui/component-searcher/index.d.ts +2 -0
- package/dist/ui/component-searcher/index.js +23 -0
- package/dist/ui/component-searcher/index.js.map +1 -0
- package/package-tar/teambit-component-0.0.709.tgz +0 -0
- package/package.json +29 -22
- package/{preview-1649647448813.js → preview-1650243425150.js} +2 -2
- package/ui/component-searcher/component-result.module.scss +13 -0
- package/ui/component-searcher/component-result.tsx +40 -0
- package/ui/component-searcher/component-searcher.tsx +57 -0
- package/ui/component-searcher/index.ts +2 -0
- package/package-tar/teambit-component-0.0.706.tgz +0 -0
package/component.ui.runtime.tsx
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import flatten from 'lodash.flatten';
|
|
3
|
+
import copy from 'copy-to-clipboard';
|
|
4
|
+
import type { RouteProps } from 'react-router-dom';
|
|
5
|
+
|
|
6
6
|
import { NavLinkProps } from '@teambit/base-ui.routing.nav-link';
|
|
7
|
+
import CommandBarAspect, { CommandBarUI, CommandEntry } from '@teambit/command-bar';
|
|
8
|
+
import { DeprecationIcon } from '@teambit/component.ui.deprecation-icon';
|
|
9
|
+
import { Slot, SlotRegistry } from '@teambit/harmony';
|
|
10
|
+
import PreviewAspect, { ClickInsideAnIframeEvent } from '@teambit/preview';
|
|
11
|
+
import PubsubAspect, { BitBaseEvent, PubsubUI } from '@teambit/pubsub';
|
|
12
|
+
import ReactRouterAspect, { ReactRouterUI } from '@teambit/react-router';
|
|
7
13
|
import { UIRuntime } from '@teambit/ui';
|
|
8
14
|
import { isBrowser } from '@teambit/ui-foundation.ui.is-browser';
|
|
9
|
-
import
|
|
15
|
+
import { MenuItem, MenuItemSlot } from '@teambit/ui-foundation.ui.main-dropdown';
|
|
16
|
+
import { NavigationSlot, RouteSlot } from '@teambit/ui-foundation.ui.react-router.slot-router';
|
|
10
17
|
import { Import } from '@teambit/ui-foundation.ui.use-box.menu';
|
|
11
|
-
|
|
12
|
-
import CommandBarAspect, { CommandBarUI, CommandEntry } from '@teambit/command-bar';
|
|
13
|
-
import copy from 'copy-to-clipboard';
|
|
14
|
-
import { ComponentAspect } from './component.aspect';
|
|
15
|
-
import { Component, ComponentPageElement, ComponentPageSlot } from './ui/component';
|
|
16
|
-
import { Menu, NavPlugin, OrderedNavigationSlot, ConsumeMethodSlot, ConsumePlugin } from './ui/menu';
|
|
18
|
+
|
|
17
19
|
import { AspectSection } from './aspect.section';
|
|
20
|
+
import { ComponentAspect } from './component.aspect';
|
|
18
21
|
import { ComponentModel } from './ui';
|
|
22
|
+
import { Component, ComponentPageElement, ComponentPageSlot } from './ui/component';
|
|
23
|
+
import { ComponentResultPlugin, ComponentSearcher } from './ui/component-searcher';
|
|
24
|
+
import { ConsumeMethodSlot, ConsumePlugin, Menu, NavPlugin, OrderedNavigationSlot } from './ui/menu';
|
|
25
|
+
|
|
26
|
+
export type ComponentSearchResultSlot = SlotRegistry<ComponentResultPlugin[]>;
|
|
19
27
|
|
|
20
28
|
export type Server = {
|
|
21
29
|
env: string;
|
|
@@ -30,6 +38,7 @@ export const componentIdUrlRegex = '[\\w\\/-]*[\\w-]';
|
|
|
30
38
|
|
|
31
39
|
export class ComponentUI {
|
|
32
40
|
readonly routePath = `/:componentId(${componentIdUrlRegex})`;
|
|
41
|
+
private componentSearcher: ComponentSearcher;
|
|
33
42
|
|
|
34
43
|
constructor(
|
|
35
44
|
/**
|
|
@@ -52,8 +61,13 @@ export class ComponentUI {
|
|
|
52
61
|
|
|
53
62
|
private pageItemSlot: ComponentPageSlot,
|
|
54
63
|
|
|
55
|
-
private
|
|
64
|
+
private componentSearchResultSlot: ComponentSearchResultSlot,
|
|
65
|
+
|
|
66
|
+
private commandBarUI: CommandBarUI,
|
|
67
|
+
|
|
68
|
+
reactRouterUi: ReactRouterUI
|
|
56
69
|
) {
|
|
70
|
+
this.componentSearcher = new ComponentSearcher({ navigate: reactRouterUi.navigateTo });
|
|
57
71
|
if (isBrowser) this.registerPubSub();
|
|
58
72
|
}
|
|
59
73
|
|
|
@@ -77,7 +91,7 @@ export class ComponentUI {
|
|
|
77
91
|
private keyBindings: CommandEntry[] = [
|
|
78
92
|
{
|
|
79
93
|
id: 'component.copyBitId', // TODO - extract to a component!
|
|
80
|
-
|
|
94
|
+
action: () => {
|
|
81
95
|
copy(this.activeComponent?.id.toString() || '');
|
|
82
96
|
},
|
|
83
97
|
displayName: 'Copy component ID',
|
|
@@ -85,7 +99,7 @@ export class ComponentUI {
|
|
|
85
99
|
},
|
|
86
100
|
{
|
|
87
101
|
id: 'component.copyNpmId', // TODO - extract to a component!
|
|
88
|
-
|
|
102
|
+
action: this.copyNpmId,
|
|
89
103
|
displayName: 'Copy component package name',
|
|
90
104
|
keybinding: ',',
|
|
91
105
|
},
|
|
@@ -204,7 +218,19 @@ export class ComponentUI {
|
|
|
204
218
|
this.pageItemSlot.register(items);
|
|
205
219
|
};
|
|
206
220
|
|
|
207
|
-
|
|
221
|
+
/** register widgets to the components listed in the command bar */
|
|
222
|
+
registerSearchResultWidget = (...items: ComponentResultPlugin[]) => {
|
|
223
|
+
this.componentSearchResultSlot.register(items);
|
|
224
|
+
const totalPlugins = flatten(this.componentSearchResultSlot.values());
|
|
225
|
+
|
|
226
|
+
this.componentSearcher.updatePlugins(totalPlugins);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
updateComponents = (components: ComponentModel[]) => {
|
|
230
|
+
this.componentSearcher.update(components);
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
static dependencies = [PubsubAspect, CommandBarAspect, ReactRouterAspect];
|
|
208
234
|
|
|
209
235
|
static runtime = UIRuntime;
|
|
210
236
|
|
|
@@ -215,18 +241,20 @@ export class ComponentUI {
|
|
|
215
241
|
Slot.withType<ConsumeMethodSlot>(),
|
|
216
242
|
Slot.withType<MenuItemSlot>(),
|
|
217
243
|
Slot.withType<ComponentPageSlot>(),
|
|
244
|
+
Slot.withType<ComponentSearchResultSlot>(),
|
|
218
245
|
];
|
|
219
246
|
|
|
220
247
|
static async provider(
|
|
221
|
-
[pubsub, commandBarUI]: [PubsubUI, CommandBarUI],
|
|
248
|
+
[pubsub, commandBarUI, reactRouterUI]: [PubsubUI, CommandBarUI, ReactRouterUI],
|
|
222
249
|
config,
|
|
223
|
-
[routeSlot, navSlot, consumeMethodSlot, widgetSlot, menuItemSlot, pageSlot]: [
|
|
250
|
+
[routeSlot, navSlot, consumeMethodSlot, widgetSlot, menuItemSlot, pageSlot, componentSearchResultSlot]: [
|
|
224
251
|
RouteSlot,
|
|
225
252
|
OrderedNavigationSlot,
|
|
226
253
|
ConsumeMethodSlot,
|
|
227
254
|
OrderedNavigationSlot,
|
|
228
255
|
MenuItemSlot,
|
|
229
|
-
ComponentPageSlot
|
|
256
|
+
ComponentPageSlot,
|
|
257
|
+
ComponentSearchResultSlot
|
|
230
258
|
]
|
|
231
259
|
) {
|
|
232
260
|
// TODO: refactor ComponentHost to a separate extension (including sidebar, host, graphql, etc.)
|
|
@@ -239,11 +267,16 @@ export class ComponentUI {
|
|
|
239
267
|
widgetSlot,
|
|
240
268
|
menuItemSlot,
|
|
241
269
|
pageSlot,
|
|
242
|
-
|
|
270
|
+
componentSearchResultSlot,
|
|
271
|
+
commandBarUI,
|
|
272
|
+
reactRouterUI
|
|
243
273
|
);
|
|
244
274
|
const section = new AspectSection();
|
|
245
275
|
|
|
276
|
+
componentUI.registerSearchResultWidget({ key: 'deprecation', end: DeprecationIcon });
|
|
277
|
+
|
|
246
278
|
componentUI.commandBarUI.addCommand(...componentUI.keyBindings);
|
|
279
|
+
commandBarUI.addSearcher(componentUI.componentSearcher);
|
|
247
280
|
componentUI.registerMenuItem(componentUI.menuItems);
|
|
248
281
|
componentUI.registerRoute(section.route);
|
|
249
282
|
componentUI.registerWidget(section.navigationLink, section.order);
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
3
|
-
import { MenuItemSlot, MenuItem } from '@teambit/ui-foundation.ui.main-dropdown';
|
|
4
|
-
import { NavigationSlot, RouteSlot } from '@teambit/ui-foundation.ui.react-router.slot-router';
|
|
2
|
+
import type { RouteProps } from 'react-router-dom';
|
|
5
3
|
import { NavLinkProps } from '@teambit/base-ui.routing.nav-link';
|
|
6
|
-
import { RouteProps } from 'react-router-dom';
|
|
7
4
|
import { CommandBarUI } from '@teambit/command-bar';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
5
|
+
import { SlotRegistry } from '@teambit/harmony';
|
|
6
|
+
import { PubsubUI } from '@teambit/pubsub';
|
|
7
|
+
import { ReactRouterUI } from '@teambit/react-router';
|
|
8
|
+
import { MenuItem, MenuItemSlot } from '@teambit/ui-foundation.ui.main-dropdown';
|
|
9
|
+
import { NavigationSlot, RouteSlot } from '@teambit/ui-foundation.ui.react-router.slot-router';
|
|
10
10
|
import { ComponentModel } from './ui';
|
|
11
|
+
import { ComponentPageElement, ComponentPageSlot } from './ui/component';
|
|
12
|
+
import { ComponentResultPlugin } from './ui/component-searcher';
|
|
13
|
+
import { ConsumeMethodSlot, ConsumePlugin, NavPlugin, OrderedNavigationSlot } from './ui/menu';
|
|
14
|
+
export declare type ComponentSearchResultSlot = SlotRegistry<ComponentResultPlugin[]>;
|
|
11
15
|
export declare type Server = {
|
|
12
16
|
env: string;
|
|
13
17
|
url: string;
|
|
@@ -30,8 +34,10 @@ export declare class ComponentUI {
|
|
|
30
34
|
private widgetSlot;
|
|
31
35
|
private menuItemSlot;
|
|
32
36
|
private pageItemSlot;
|
|
37
|
+
private componentSearchResultSlot;
|
|
33
38
|
private commandBarUI;
|
|
34
39
|
readonly routePath: string;
|
|
40
|
+
private componentSearcher;
|
|
35
41
|
constructor(
|
|
36
42
|
/**
|
|
37
43
|
* Pubsub aspects
|
|
@@ -40,7 +46,7 @@ export declare class ComponentUI {
|
|
|
40
46
|
/**
|
|
41
47
|
* slot for registering a new widget to the menu.
|
|
42
48
|
*/
|
|
43
|
-
widgetSlot: OrderedNavigationSlot, menuItemSlot: MenuItemSlot, pageItemSlot: ComponentPageSlot, commandBarUI: CommandBarUI);
|
|
49
|
+
widgetSlot: OrderedNavigationSlot, menuItemSlot: MenuItemSlot, pageItemSlot: ComponentPageSlot, componentSearchResultSlot: ComponentSearchResultSlot, commandBarUI: CommandBarUI, reactRouterUi: ReactRouterUI);
|
|
44
50
|
/**
|
|
45
51
|
* the current visible component
|
|
46
52
|
*/
|
|
@@ -62,18 +68,22 @@ export declare class ComponentUI {
|
|
|
62
68
|
registerWidget(widget: NavLinkProps, order?: number): void;
|
|
63
69
|
registerMenuItem: (menuItems: MenuItem[]) => void;
|
|
64
70
|
registerPageItem: (...items: ComponentPageElement[]) => void;
|
|
71
|
+
/** register widgets to the components listed in the command bar */
|
|
72
|
+
registerSearchResultWidget: (...items: ComponentResultPlugin[]) => void;
|
|
73
|
+
updateComponents: (components: ComponentModel[]) => void;
|
|
65
74
|
static dependencies: import("@teambit/harmony").Aspect[];
|
|
66
75
|
static runtime: import("@teambit/harmony").RuntimeDefinition;
|
|
67
|
-
static slots: (((registerFn: () => string) =>
|
|
76
|
+
static slots: (((registerFn: () => string) => SlotRegistry<RouteProps<string, {
|
|
68
77
|
[x: string]: string | undefined;
|
|
69
|
-
}>>) | ((registerFn: () => string) =>
|
|
70
|
-
static provider([pubsub, commandBarUI]: [PubsubUI, CommandBarUI], config: any, [routeSlot, navSlot, consumeMethodSlot, widgetSlot, menuItemSlot, pageSlot]: [
|
|
78
|
+
}>>) | ((registerFn: () => string) => SlotRegistry<MenuItemSlot>) | ((registerFn: () => string) => SlotRegistry<NavigationSlot>) | ((registerFn: () => string) => SlotRegistry<NavPlugin>) | ((registerFn: () => string) => SlotRegistry<ConsumeMethodSlot>) | ((registerFn: () => string) => SlotRegistry<ComponentPageSlot>) | ((registerFn: () => string) => SlotRegistry<ComponentSearchResultSlot>))[];
|
|
79
|
+
static provider([pubsub, commandBarUI, reactRouterUI]: [PubsubUI, CommandBarUI, ReactRouterUI], config: any, [routeSlot, navSlot, consumeMethodSlot, widgetSlot, menuItemSlot, pageSlot, componentSearchResultSlot]: [
|
|
71
80
|
RouteSlot,
|
|
72
81
|
OrderedNavigationSlot,
|
|
73
82
|
ConsumeMethodSlot,
|
|
74
83
|
OrderedNavigationSlot,
|
|
75
84
|
MenuItemSlot,
|
|
76
|
-
ComponentPageSlot
|
|
85
|
+
ComponentPageSlot,
|
|
86
|
+
ComponentSearchResultSlot
|
|
77
87
|
]): Promise<ComponentUI>;
|
|
78
88
|
}
|
|
79
89
|
export default ComponentUI;
|
|
@@ -21,20 +21,50 @@ function _defineProperty2() {
|
|
|
21
21
|
return data;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
function
|
|
25
|
-
const data = _interopRequireDefault(require("
|
|
24
|
+
function _react() {
|
|
25
|
+
const data = _interopRequireDefault(require("react"));
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
_react = function () {
|
|
28
28
|
return data;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
return data;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
function
|
|
35
|
-
const data =
|
|
34
|
+
function _lodash() {
|
|
35
|
+
const data = _interopRequireDefault(require("lodash.flatten"));
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
_lodash = function () {
|
|
38
|
+
return data;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return data;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function _copyToClipboard() {
|
|
45
|
+
const data = _interopRequireDefault(require("copy-to-clipboard"));
|
|
46
|
+
|
|
47
|
+
_copyToClipboard = function () {
|
|
48
|
+
return data;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return data;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function _commandBar() {
|
|
55
|
+
const data = _interopRequireDefault(require("@teambit/command-bar"));
|
|
56
|
+
|
|
57
|
+
_commandBar = function () {
|
|
58
|
+
return data;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return data;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function _componentUi() {
|
|
65
|
+
const data = require("@teambit/component.ui.deprecation-icon");
|
|
66
|
+
|
|
67
|
+
_componentUi = function () {
|
|
38
68
|
return data;
|
|
39
69
|
};
|
|
40
70
|
|
|
@@ -51,60 +81,70 @@ function _harmony() {
|
|
|
51
81
|
return data;
|
|
52
82
|
}
|
|
53
83
|
|
|
54
|
-
function
|
|
55
|
-
const data = require("@teambit/
|
|
84
|
+
function _preview() {
|
|
85
|
+
const data = _interopRequireWildcard(require("@teambit/preview"));
|
|
56
86
|
|
|
57
|
-
|
|
87
|
+
_preview = function () {
|
|
58
88
|
return data;
|
|
59
89
|
};
|
|
60
90
|
|
|
61
91
|
return data;
|
|
62
92
|
}
|
|
63
93
|
|
|
64
|
-
function
|
|
65
|
-
const data = require("@teambit/
|
|
94
|
+
function _pubsub() {
|
|
95
|
+
const data = _interopRequireDefault(require("@teambit/pubsub"));
|
|
66
96
|
|
|
67
|
-
|
|
97
|
+
_pubsub = function () {
|
|
68
98
|
return data;
|
|
69
99
|
};
|
|
70
100
|
|
|
71
101
|
return data;
|
|
72
102
|
}
|
|
73
103
|
|
|
74
|
-
function
|
|
75
|
-
const data = _interopRequireDefault(require("react"));
|
|
104
|
+
function _reactRouter() {
|
|
105
|
+
const data = _interopRequireDefault(require("@teambit/react-router"));
|
|
76
106
|
|
|
77
|
-
|
|
107
|
+
_reactRouter = function () {
|
|
78
108
|
return data;
|
|
79
109
|
};
|
|
80
110
|
|
|
81
111
|
return data;
|
|
82
112
|
}
|
|
83
113
|
|
|
84
|
-
function
|
|
85
|
-
const data = require("@teambit/ui
|
|
114
|
+
function _ui() {
|
|
115
|
+
const data = require("@teambit/ui");
|
|
86
116
|
|
|
87
|
-
|
|
117
|
+
_ui = function () {
|
|
88
118
|
return data;
|
|
89
119
|
};
|
|
90
120
|
|
|
91
121
|
return data;
|
|
92
122
|
}
|
|
93
123
|
|
|
94
|
-
function
|
|
95
|
-
const data =
|
|
124
|
+
function _uiFoundationUi() {
|
|
125
|
+
const data = require("@teambit/ui-foundation.ui.is-browser");
|
|
96
126
|
|
|
97
|
-
|
|
127
|
+
_uiFoundationUi = function () {
|
|
98
128
|
return data;
|
|
99
129
|
};
|
|
100
130
|
|
|
101
131
|
return data;
|
|
102
132
|
}
|
|
103
133
|
|
|
104
|
-
function
|
|
105
|
-
const data =
|
|
134
|
+
function _uiFoundationUiUseBox() {
|
|
135
|
+
const data = require("@teambit/ui-foundation.ui.use-box.menu");
|
|
106
136
|
|
|
107
|
-
|
|
137
|
+
_uiFoundationUiUseBox = function () {
|
|
138
|
+
return data;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
return data;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function _aspect() {
|
|
145
|
+
const data = require("./aspect.section");
|
|
146
|
+
|
|
147
|
+
_aspect = function () {
|
|
108
148
|
return data;
|
|
109
149
|
};
|
|
110
150
|
|
|
@@ -131,20 +171,20 @@ function _component2() {
|
|
|
131
171
|
return data;
|
|
132
172
|
}
|
|
133
173
|
|
|
134
|
-
function
|
|
135
|
-
const data = require("./ui/
|
|
174
|
+
function _componentSearcher() {
|
|
175
|
+
const data = require("./ui/component-searcher");
|
|
136
176
|
|
|
137
|
-
|
|
177
|
+
_componentSearcher = function () {
|
|
138
178
|
return data;
|
|
139
179
|
};
|
|
140
180
|
|
|
141
181
|
return data;
|
|
142
182
|
}
|
|
143
183
|
|
|
144
|
-
function
|
|
145
|
-
const data = require("./
|
|
184
|
+
function _menu() {
|
|
185
|
+
const data = require("./ui/menu");
|
|
146
186
|
|
|
147
|
-
|
|
187
|
+
_menu = function () {
|
|
148
188
|
return data;
|
|
149
189
|
};
|
|
150
190
|
|
|
@@ -167,7 +207,7 @@ class ComponentUI {
|
|
|
167
207
|
/**
|
|
168
208
|
* slot for registering a new widget to the menu.
|
|
169
209
|
*/
|
|
170
|
-
widgetSlot, menuItemSlot, pageItemSlot, commandBarUI) {
|
|
210
|
+
widgetSlot, menuItemSlot, pageItemSlot, componentSearchResultSlot, commandBarUI, reactRouterUi) {
|
|
171
211
|
this.pubsub = pubsub;
|
|
172
212
|
this.routeSlot = routeSlot;
|
|
173
213
|
this.navSlot = navSlot;
|
|
@@ -175,8 +215,10 @@ class ComponentUI {
|
|
|
175
215
|
this.widgetSlot = widgetSlot;
|
|
176
216
|
this.menuItemSlot = menuItemSlot;
|
|
177
217
|
this.pageItemSlot = pageItemSlot;
|
|
218
|
+
this.componentSearchResultSlot = componentSearchResultSlot;
|
|
178
219
|
this.commandBarUI = commandBarUI;
|
|
179
220
|
(0, _defineProperty2().default)(this, "routePath", `/:componentId(${componentIdUrlRegex})`);
|
|
221
|
+
(0, _defineProperty2().default)(this, "componentSearcher", void 0);
|
|
180
222
|
(0, _defineProperty2().default)(this, "activeComponent", void 0);
|
|
181
223
|
(0, _defineProperty2().default)(this, "copyNpmId", () => {
|
|
182
224
|
var _this$activeComponent;
|
|
@@ -194,7 +236,7 @@ class ComponentUI {
|
|
|
194
236
|
(0, _defineProperty2().default)(this, "keyBindings", [{
|
|
195
237
|
id: 'component.copyBitId',
|
|
196
238
|
// TODO - extract to a component!
|
|
197
|
-
|
|
239
|
+
action: () => {
|
|
198
240
|
var _this$activeComponent3;
|
|
199
241
|
|
|
200
242
|
(0, _copyToClipboard().default)(((_this$activeComponent3 = this.activeComponent) === null || _this$activeComponent3 === void 0 ? void 0 : _this$activeComponent3.id.toString()) || '');
|
|
@@ -204,7 +246,7 @@ class ComponentUI {
|
|
|
204
246
|
}, {
|
|
205
247
|
id: 'component.copyNpmId',
|
|
206
248
|
// TODO - extract to a component!
|
|
207
|
-
|
|
249
|
+
action: this.copyNpmId,
|
|
208
250
|
displayName: 'Copy component package name',
|
|
209
251
|
keybinding: ','
|
|
210
252
|
}]);
|
|
@@ -274,6 +316,17 @@ class ComponentUI {
|
|
|
274
316
|
(0, _defineProperty2().default)(this, "registerPageItem", (...items) => {
|
|
275
317
|
this.pageItemSlot.register(items);
|
|
276
318
|
});
|
|
319
|
+
(0, _defineProperty2().default)(this, "registerSearchResultWidget", (...items) => {
|
|
320
|
+
this.componentSearchResultSlot.register(items);
|
|
321
|
+
const totalPlugins = (0, _lodash().default)(this.componentSearchResultSlot.values());
|
|
322
|
+
this.componentSearcher.updatePlugins(totalPlugins);
|
|
323
|
+
});
|
|
324
|
+
(0, _defineProperty2().default)(this, "updateComponents", components => {
|
|
325
|
+
this.componentSearcher.update(components);
|
|
326
|
+
});
|
|
327
|
+
this.componentSearcher = new (_componentSearcher().ComponentSearcher)({
|
|
328
|
+
navigate: reactRouterUi.navigateTo
|
|
329
|
+
});
|
|
277
330
|
if (_uiFoundationUi().isBrowser) this.registerPubSub();
|
|
278
331
|
}
|
|
279
332
|
/**
|
|
@@ -337,12 +390,17 @@ class ComponentUI {
|
|
|
337
390
|
});
|
|
338
391
|
}
|
|
339
392
|
|
|
340
|
-
static async provider([pubsub, commandBarUI], config, [routeSlot, navSlot, consumeMethodSlot, widgetSlot, menuItemSlot, pageSlot]) {
|
|
393
|
+
static async provider([pubsub, commandBarUI, reactRouterUI], config, [routeSlot, navSlot, consumeMethodSlot, widgetSlot, menuItemSlot, pageSlot, componentSearchResultSlot]) {
|
|
341
394
|
// TODO: refactor ComponentHost to a separate extension (including sidebar, host, graphql, etc.)
|
|
342
395
|
// TODO: add contextual hook for ComponentHost @uri/@oded
|
|
343
|
-
const componentUI = new ComponentUI(pubsub, routeSlot, navSlot, consumeMethodSlot, widgetSlot, menuItemSlot, pageSlot, commandBarUI);
|
|
396
|
+
const componentUI = new ComponentUI(pubsub, routeSlot, navSlot, consumeMethodSlot, widgetSlot, menuItemSlot, pageSlot, componentSearchResultSlot, commandBarUI, reactRouterUI);
|
|
344
397
|
const section = new (_aspect().AspectSection)();
|
|
398
|
+
componentUI.registerSearchResultWidget({
|
|
399
|
+
key: 'deprecation',
|
|
400
|
+
end: _componentUi().DeprecationIcon
|
|
401
|
+
});
|
|
345
402
|
componentUI.commandBarUI.addCommand(...componentUI.keyBindings);
|
|
403
|
+
commandBarUI.addSearcher(componentUI.componentSearcher);
|
|
346
404
|
componentUI.registerMenuItem(componentUI.menuItems);
|
|
347
405
|
componentUI.registerRoute(section.route);
|
|
348
406
|
componentUI.registerWidget(section.navigationLink, section.order);
|
|
@@ -353,9 +411,9 @@ class ComponentUI {
|
|
|
353
411
|
}
|
|
354
412
|
|
|
355
413
|
exports.ComponentUI = ComponentUI;
|
|
356
|
-
(0, _defineProperty2().default)(ComponentUI, "dependencies", [_pubsub().default, _commandBar().default]);
|
|
414
|
+
(0, _defineProperty2().default)(ComponentUI, "dependencies", [_pubsub().default, _commandBar().default, _reactRouter().default]);
|
|
357
415
|
(0, _defineProperty2().default)(ComponentUI, "runtime", _ui().UIRuntime);
|
|
358
|
-
(0, _defineProperty2().default)(ComponentUI, "slots", [_harmony().Slot.withType(), _harmony().Slot.withType(), _harmony().Slot.withType(), _harmony().Slot.withType(), _harmony().Slot.withType(), _harmony().Slot.withType()]);
|
|
416
|
+
(0, _defineProperty2().default)(ComponentUI, "slots", [_harmony().Slot.withType(), _harmony().Slot.withType(), _harmony().Slot.withType(), _harmony().Slot.withType(), _harmony().Slot.withType(), _harmony().Slot.withType(), _harmony().Slot.withType()]);
|
|
359
417
|
var _default = ComponentUI;
|
|
360
418
|
exports.default = _default;
|
|
361
419
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["component.ui.runtime.tsx"],"names":["componentIdUrlRegex","ComponentUI","constructor","pubsub","routeSlot","navSlot","consumeMethodSlot","widgetSlot","menuItemSlot","pageItemSlot","commandBarUI","packageName","activeComponent","version","id","versionString","handler","toString","displayName","keybinding","copyNpmId","category","title","keyChar","run","comp","options","latest","Title","width","Component","ignoreVersion","name","currentLane","order","menuItems","register","items","isBrowser","registerPubSub","sub","PreviewAspect","be","type","ClickInsideAnIframeEvent","TYPE","event","MouseEvent","view","window","bubbles","cancelable","body","document","dispatchEvent","getComponentUI","host","handleComponentChange","getMenu","registerRoute","route","registerNavigation","nav","props","registerConsumeMethod","consumeMethods","registerWidget","widget","provider","config","pageSlot","componentUI","section","AspectSection","addCommand","keyBindings","registerMenuItem","navigationLink","bitMethod","PubsubAspect","CommandBarAspect","UIRuntime","Slot","withType","ComponentAspect","addRuntime"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;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;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;A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":["import PubsubAspect, { PubsubUI, BitBaseEvent } from '@teambit/pubsub';\nimport PreviewAspect, { ClickInsideAnIframeEvent } from '@teambit/preview';\nimport { MenuItemSlot, MenuItem } from '@teambit/ui-foundation.ui.main-dropdown';\nimport { Slot } from '@teambit/harmony';\nimport { NavigationSlot, RouteSlot } from '@teambit/ui-foundation.ui.react-router.slot-router';\nimport { NavLinkProps } from '@teambit/base-ui.routing.nav-link';\nimport { UIRuntime } from '@teambit/ui';\nimport { isBrowser } from '@teambit/ui-foundation.ui.is-browser';\nimport React from 'react';\nimport { Import } from '@teambit/ui-foundation.ui.use-box.menu';\nimport { RouteProps } from 'react-router-dom';\nimport CommandBarAspect, { CommandBarUI, CommandEntry } from '@teambit/command-bar';\nimport copy from 'copy-to-clipboard';\nimport { ComponentAspect } from './component.aspect';\nimport { Component, ComponentPageElement, ComponentPageSlot } from './ui/component';\nimport { Menu, NavPlugin, OrderedNavigationSlot, ConsumeMethodSlot, ConsumePlugin } from './ui/menu';\nimport { AspectSection } from './aspect.section';\nimport { ComponentModel } from './ui';\n\nexport type Server = {\n env: string;\n url: string;\n};\n\nexport type ComponentMeta = {\n id: string;\n};\n\nexport const componentIdUrlRegex = '[\\\\w\\\\/-]*[\\\\w-]';\n\nexport class ComponentUI {\n readonly routePath = `/:componentId(${componentIdUrlRegex})`;\n\n constructor(\n /**\n * Pubsub aspects\n */\n private pubsub: PubsubUI,\n\n private routeSlot: RouteSlot,\n\n private navSlot: OrderedNavigationSlot,\n\n private consumeMethodSlot: ConsumeMethodSlot,\n\n /**\n * slot for registering a new widget to the menu.\n */\n private widgetSlot: OrderedNavigationSlot,\n\n private menuItemSlot: MenuItemSlot,\n\n private pageItemSlot: ComponentPageSlot,\n\n private commandBarUI: CommandBarUI\n ) {\n if (isBrowser) this.registerPubSub();\n }\n\n /**\n * the current visible component\n */\n private activeComponent?: ComponentModel;\n\n private copyNpmId = () => {\n const packageName = this.activeComponent?.packageName;\n if (packageName) {\n const version = this.activeComponent?.id.version;\n const versionString = version ? `@${version}` : '';\n copy(`${packageName}${versionString}`);\n }\n };\n\n /**\n * key bindings used by component aspect\n */\n private keyBindings: CommandEntry[] = [\n {\n id: 'component.copyBitId', // TODO - extract to a component!\n handler: () => {\n copy(this.activeComponent?.id.toString() || '');\n },\n displayName: 'Copy component ID',\n keybinding: '.',\n },\n {\n id: 'component.copyNpmId', // TODO - extract to a component!\n handler: this.copyNpmId,\n displayName: 'Copy component package name',\n keybinding: ',',\n },\n ];\n\n private menuItems: MenuItem[] = [\n {\n category: 'general',\n title: 'Open command bar',\n keyChar: 'mod+k',\n handler: () => this.commandBarUI?.run('command-bar.open'),\n },\n {\n category: 'general',\n title: 'Toggle component list',\n keyChar: 'alt+s',\n handler: () => this.commandBarUI?.run('sidebar.toggle'),\n },\n {\n category: 'workflow',\n title: 'Copy component ID',\n keyChar: '.',\n handler: () => this.commandBarUI?.run('component.copyBitId'),\n },\n {\n category: 'workflow',\n title: 'Copy component package name',\n keyChar: ',',\n handler: () => this.commandBarUI?.run('component.copyNpmId'),\n },\n ];\n\n private bitMethod: ConsumePlugin = (comp, options) => {\n const version = comp.version === comp.latest ? '' : `@${comp.version}`;\n return {\n Title: <img style={{ width: '20px' }} src=\"https://static.bit.dev/brands/bit-logo-text.svg\" />,\n Component: (\n <Import\n componentId={`${comp.id.toString({ ignoreVersion: true })}${version}`}\n packageName={`${comp.packageName}${version}`}\n componentName={comp.id.name}\n showInstallMethod={!options?.currentLane}\n />\n ),\n order: 0,\n };\n };\n\n registerPubSub() {\n this.pubsub.sub(PreviewAspect.id, (be: BitBaseEvent<any>) => {\n if (be.type === ClickInsideAnIframeEvent.TYPE) {\n const event = new MouseEvent('mousedown', {\n view: window,\n bubbles: true,\n cancelable: true,\n });\n\n const body = document.body;\n body?.dispatchEvent(event);\n }\n });\n }\n\n handleComponentChange = (activeComponent?: ComponentModel) => {\n this.activeComponent = activeComponent;\n };\n\n getComponentUI(host: string) {\n return (\n <Component\n routeSlot={this.routeSlot}\n containerSlot={this.pageItemSlot}\n onComponentChange={this.handleComponentChange}\n host={host}\n />\n );\n }\n\n getMenu(host: string) {\n return (\n <Menu\n navigationSlot={this.navSlot}\n consumeMethodSlot={this.consumeMethodSlot}\n widgetSlot={this.widgetSlot}\n host={host}\n menuItemSlot={this.menuItemSlot}\n />\n );\n }\n\n registerRoute(route: RouteProps) {\n this.routeSlot.register(route);\n return this;\n }\n\n registerNavigation(nav: NavLinkProps, order?: number) {\n this.navSlot.register({\n props: nav,\n order,\n });\n }\n\n registerConsumeMethod(...consumeMethods: ConsumePlugin[]) {\n this.consumeMethodSlot.register(consumeMethods);\n }\n\n registerWidget(widget: NavLinkProps, order?: number) {\n this.widgetSlot.register({ props: widget, order });\n }\n\n registerMenuItem = (menuItems: MenuItem[]) => {\n this.menuItemSlot.register(menuItems);\n };\n\n registerPageItem = (...items: ComponentPageElement[]) => {\n this.pageItemSlot.register(items);\n };\n\n static dependencies = [PubsubAspect, CommandBarAspect];\n\n static runtime = UIRuntime;\n\n static slots = [\n Slot.withType<RouteProps>(),\n Slot.withType<NavPlugin>(),\n Slot.withType<NavigationSlot>(),\n Slot.withType<ConsumeMethodSlot>(),\n Slot.withType<MenuItemSlot>(),\n Slot.withType<ComponentPageSlot>(),\n ];\n\n static async provider(\n [pubsub, commandBarUI]: [PubsubUI, CommandBarUI],\n config,\n [routeSlot, navSlot, consumeMethodSlot, widgetSlot, menuItemSlot, pageSlot]: [\n RouteSlot,\n OrderedNavigationSlot,\n ConsumeMethodSlot,\n OrderedNavigationSlot,\n MenuItemSlot,\n ComponentPageSlot\n ]\n ) {\n // TODO: refactor ComponentHost to a separate extension (including sidebar, host, graphql, etc.)\n // TODO: add contextual hook for ComponentHost @uri/@oded\n const componentUI = new ComponentUI(\n pubsub,\n routeSlot,\n navSlot,\n consumeMethodSlot,\n widgetSlot,\n menuItemSlot,\n pageSlot,\n commandBarUI\n );\n const section = new AspectSection();\n\n componentUI.commandBarUI.addCommand(...componentUI.keyBindings);\n componentUI.registerMenuItem(componentUI.menuItems);\n componentUI.registerRoute(section.route);\n componentUI.registerWidget(section.navigationLink, section.order);\n componentUI.registerConsumeMethod(componentUI.bitMethod);\n return componentUI;\n }\n}\n\nexport default ComponentUI;\n\nComponentAspect.addRuntime(ComponentUI);\n"]}
|
|
1
|
+
{"version":3,"sources":["component.ui.runtime.tsx"],"names":["componentIdUrlRegex","ComponentUI","constructor","pubsub","routeSlot","navSlot","consumeMethodSlot","widgetSlot","menuItemSlot","pageItemSlot","componentSearchResultSlot","commandBarUI","reactRouterUi","packageName","activeComponent","version","id","versionString","action","toString","displayName","keybinding","copyNpmId","category","title","keyChar","handler","run","comp","options","latest","Title","width","Component","ignoreVersion","name","currentLane","order","menuItems","register","items","totalPlugins","values","componentSearcher","updatePlugins","components","update","ComponentSearcher","navigate","navigateTo","isBrowser","registerPubSub","sub","PreviewAspect","be","type","ClickInsideAnIframeEvent","TYPE","event","MouseEvent","view","window","bubbles","cancelable","body","document","dispatchEvent","getComponentUI","host","handleComponentChange","getMenu","registerRoute","route","registerNavigation","nav","props","registerConsumeMethod","consumeMethods","registerWidget","widget","provider","reactRouterUI","config","pageSlot","componentUI","section","AspectSection","registerSearchResultWidget","key","end","DeprecationIcon","addCommand","keyBindings","addSearcher","registerMenuItem","navigationLink","bitMethod","PubsubAspect","CommandBarAspect","ReactRouterAspect","UIRuntime","Slot","withType","ComponentAspect","addRuntime"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIA;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;AAA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';\nimport copy from 'copy-to-clipboard';\nimport type { RouteProps } from 'react-router-dom';\n\nimport { NavLinkProps } from '@teambit/base-ui.routing.nav-link';\nimport CommandBarAspect, { CommandBarUI, CommandEntry } from '@teambit/command-bar';\nimport { DeprecationIcon } from '@teambit/component.ui.deprecation-icon';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport PreviewAspect, { ClickInsideAnIframeEvent } from '@teambit/preview';\nimport PubsubAspect, { BitBaseEvent, PubsubUI } from '@teambit/pubsub';\nimport ReactRouterAspect, { ReactRouterUI } from '@teambit/react-router';\nimport { UIRuntime } from '@teambit/ui';\nimport { isBrowser } from '@teambit/ui-foundation.ui.is-browser';\nimport { MenuItem, MenuItemSlot } from '@teambit/ui-foundation.ui.main-dropdown';\nimport { NavigationSlot, RouteSlot } from '@teambit/ui-foundation.ui.react-router.slot-router';\nimport { Import } from '@teambit/ui-foundation.ui.use-box.menu';\n\nimport { AspectSection } from './aspect.section';\nimport { ComponentAspect } from './component.aspect';\nimport { ComponentModel } from './ui';\nimport { Component, ComponentPageElement, ComponentPageSlot } from './ui/component';\nimport { ComponentResultPlugin, ComponentSearcher } from './ui/component-searcher';\nimport { ConsumeMethodSlot, ConsumePlugin, Menu, NavPlugin, OrderedNavigationSlot } from './ui/menu';\n\nexport type ComponentSearchResultSlot = SlotRegistry<ComponentResultPlugin[]>;\n\nexport type Server = {\n env: string;\n url: string;\n};\n\nexport type ComponentMeta = {\n id: string;\n};\n\nexport const componentIdUrlRegex = '[\\\\w\\\\/-]*[\\\\w-]';\n\nexport class ComponentUI {\n readonly routePath = `/:componentId(${componentIdUrlRegex})`;\n private componentSearcher: ComponentSearcher;\n\n constructor(\n /**\n * Pubsub aspects\n */\n private pubsub: PubsubUI,\n\n private routeSlot: RouteSlot,\n\n private navSlot: OrderedNavigationSlot,\n\n private consumeMethodSlot: ConsumeMethodSlot,\n\n /**\n * slot for registering a new widget to the menu.\n */\n private widgetSlot: OrderedNavigationSlot,\n\n private menuItemSlot: MenuItemSlot,\n\n private pageItemSlot: ComponentPageSlot,\n\n private componentSearchResultSlot: ComponentSearchResultSlot,\n\n private commandBarUI: CommandBarUI,\n\n reactRouterUi: ReactRouterUI\n ) {\n this.componentSearcher = new ComponentSearcher({ navigate: reactRouterUi.navigateTo });\n if (isBrowser) this.registerPubSub();\n }\n\n /**\n * the current visible component\n */\n private activeComponent?: ComponentModel;\n\n private copyNpmId = () => {\n const packageName = this.activeComponent?.packageName;\n if (packageName) {\n const version = this.activeComponent?.id.version;\n const versionString = version ? `@${version}` : '';\n copy(`${packageName}${versionString}`);\n }\n };\n\n /**\n * key bindings used by component aspect\n */\n private keyBindings: CommandEntry[] = [\n {\n id: 'component.copyBitId', // TODO - extract to a component!\n action: () => {\n copy(this.activeComponent?.id.toString() || '');\n },\n displayName: 'Copy component ID',\n keybinding: '.',\n },\n {\n id: 'component.copyNpmId', // TODO - extract to a component!\n action: this.copyNpmId,\n displayName: 'Copy component package name',\n keybinding: ',',\n },\n ];\n\n private menuItems: MenuItem[] = [\n {\n category: 'general',\n title: 'Open command bar',\n keyChar: 'mod+k',\n handler: () => this.commandBarUI?.run('command-bar.open'),\n },\n {\n category: 'general',\n title: 'Toggle component list',\n keyChar: 'alt+s',\n handler: () => this.commandBarUI?.run('sidebar.toggle'),\n },\n {\n category: 'workflow',\n title: 'Copy component ID',\n keyChar: '.',\n handler: () => this.commandBarUI?.run('component.copyBitId'),\n },\n {\n category: 'workflow',\n title: 'Copy component package name',\n keyChar: ',',\n handler: () => this.commandBarUI?.run('component.copyNpmId'),\n },\n ];\n\n private bitMethod: ConsumePlugin = (comp, options) => {\n const version = comp.version === comp.latest ? '' : `@${comp.version}`;\n return {\n Title: <img style={{ width: '20px' }} src=\"https://static.bit.dev/brands/bit-logo-text.svg\" />,\n Component: (\n <Import\n componentId={`${comp.id.toString({ ignoreVersion: true })}${version}`}\n packageName={`${comp.packageName}${version}`}\n componentName={comp.id.name}\n showInstallMethod={!options?.currentLane}\n />\n ),\n order: 0,\n };\n };\n\n registerPubSub() {\n this.pubsub.sub(PreviewAspect.id, (be: BitBaseEvent<any>) => {\n if (be.type === ClickInsideAnIframeEvent.TYPE) {\n const event = new MouseEvent('mousedown', {\n view: window,\n bubbles: true,\n cancelable: true,\n });\n\n const body = document.body;\n body?.dispatchEvent(event);\n }\n });\n }\n\n handleComponentChange = (activeComponent?: ComponentModel) => {\n this.activeComponent = activeComponent;\n };\n\n getComponentUI(host: string) {\n return (\n <Component\n routeSlot={this.routeSlot}\n containerSlot={this.pageItemSlot}\n onComponentChange={this.handleComponentChange}\n host={host}\n />\n );\n }\n\n getMenu(host: string) {\n return (\n <Menu\n navigationSlot={this.navSlot}\n consumeMethodSlot={this.consumeMethodSlot}\n widgetSlot={this.widgetSlot}\n host={host}\n menuItemSlot={this.menuItemSlot}\n />\n );\n }\n\n registerRoute(route: RouteProps) {\n this.routeSlot.register(route);\n return this;\n }\n\n registerNavigation(nav: NavLinkProps, order?: number) {\n this.navSlot.register({\n props: nav,\n order,\n });\n }\n\n registerConsumeMethod(...consumeMethods: ConsumePlugin[]) {\n this.consumeMethodSlot.register(consumeMethods);\n }\n\n registerWidget(widget: NavLinkProps, order?: number) {\n this.widgetSlot.register({ props: widget, order });\n }\n\n registerMenuItem = (menuItems: MenuItem[]) => {\n this.menuItemSlot.register(menuItems);\n };\n\n registerPageItem = (...items: ComponentPageElement[]) => {\n this.pageItemSlot.register(items);\n };\n\n /** register widgets to the components listed in the command bar */\n registerSearchResultWidget = (...items: ComponentResultPlugin[]) => {\n this.componentSearchResultSlot.register(items);\n const totalPlugins = flatten(this.componentSearchResultSlot.values());\n\n this.componentSearcher.updatePlugins(totalPlugins);\n };\n\n updateComponents = (components: ComponentModel[]) => {\n this.componentSearcher.update(components);\n };\n\n static dependencies = [PubsubAspect, CommandBarAspect, ReactRouterAspect];\n\n static runtime = UIRuntime;\n\n static slots = [\n Slot.withType<RouteProps>(),\n Slot.withType<NavPlugin>(),\n Slot.withType<NavigationSlot>(),\n Slot.withType<ConsumeMethodSlot>(),\n Slot.withType<MenuItemSlot>(),\n Slot.withType<ComponentPageSlot>(),\n Slot.withType<ComponentSearchResultSlot>(),\n ];\n\n static async provider(\n [pubsub, commandBarUI, reactRouterUI]: [PubsubUI, CommandBarUI, ReactRouterUI],\n config,\n [routeSlot, navSlot, consumeMethodSlot, widgetSlot, menuItemSlot, pageSlot, componentSearchResultSlot]: [\n RouteSlot,\n OrderedNavigationSlot,\n ConsumeMethodSlot,\n OrderedNavigationSlot,\n MenuItemSlot,\n ComponentPageSlot,\n ComponentSearchResultSlot\n ]\n ) {\n // TODO: refactor ComponentHost to a separate extension (including sidebar, host, graphql, etc.)\n // TODO: add contextual hook for ComponentHost @uri/@oded\n const componentUI = new ComponentUI(\n pubsub,\n routeSlot,\n navSlot,\n consumeMethodSlot,\n widgetSlot,\n menuItemSlot,\n pageSlot,\n componentSearchResultSlot,\n commandBarUI,\n reactRouterUI\n );\n const section = new AspectSection();\n\n componentUI.registerSearchResultWidget({ key: 'deprecation', end: DeprecationIcon });\n\n componentUI.commandBarUI.addCommand(...componentUI.keyBindings);\n commandBarUI.addSearcher(componentUI.componentSearcher);\n componentUI.registerMenuItem(componentUI.menuItems);\n componentUI.registerRoute(section.route);\n componentUI.registerWidget(section.navigationLink, section.order);\n componentUI.registerConsumeMethod(componentUI.bitMethod);\n return componentUI;\n }\n}\n\nexport default ComponentUI;\n\nComponentAspect.addRuntime(ComponentUI);\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React, { ComponentType } from 'react';
|
|
2
|
+
import { ComponentModel } from '@teambit/component';
|
|
3
|
+
export declare type ComponentPluginProps = React.HTMLAttributes<HTMLDivElement> & {
|
|
4
|
+
component: ComponentModel;
|
|
5
|
+
};
|
|
6
|
+
export declare type ComponentResultPlugin = {
|
|
7
|
+
key: string;
|
|
8
|
+
start?: ComponentType<ComponentPluginProps>;
|
|
9
|
+
end?: ComponentType<ComponentPluginProps>;
|
|
10
|
+
};
|
|
11
|
+
declare type ComponentResultProps = {
|
|
12
|
+
component: ComponentModel;
|
|
13
|
+
plugins?: ComponentResultPlugin[];
|
|
14
|
+
};
|
|
15
|
+
export declare function ComponentResult({ component, plugins }: ComponentResultProps): JSX.Element;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.ComponentResult = ComponentResult;
|
|
9
|
+
|
|
10
|
+
function _react() {
|
|
11
|
+
const data = _interopRequireDefault(require("react"));
|
|
12
|
+
|
|
13
|
+
_react = function () {
|
|
14
|
+
return data;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function _lodash() {
|
|
21
|
+
const data = _interopRequireDefault(require("lodash.compact"));
|
|
22
|
+
|
|
23
|
+
_lodash = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function _designUiStyles() {
|
|
31
|
+
const data = require("@teambit/design.ui.styles.ellipsis");
|
|
32
|
+
|
|
33
|
+
_designUiStyles = function () {
|
|
34
|
+
return data;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function _envsUi() {
|
|
41
|
+
const data = require("@teambit/envs.ui.env-icon");
|
|
42
|
+
|
|
43
|
+
_envsUi = function () {
|
|
44
|
+
return data;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function _classnames() {
|
|
51
|
+
const data = _interopRequireDefault(require("classnames"));
|
|
52
|
+
|
|
53
|
+
_classnames = function () {
|
|
54
|
+
return data;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function _componentResultModule() {
|
|
61
|
+
const data = _interopRequireDefault(require("./component-result.module.scss"));
|
|
62
|
+
|
|
63
|
+
_componentResultModule = function () {
|
|
64
|
+
return data;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return data;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function ComponentResult({
|
|
71
|
+
component,
|
|
72
|
+
plugins
|
|
73
|
+
}) {
|
|
74
|
+
const name = component.id.fullName;
|
|
75
|
+
const startPlugins = (0, _lodash().default)(plugins === null || plugins === void 0 ? void 0 : plugins.map(plugin => plugin.start && /*#__PURE__*/_react().default.createElement(plugin.start, {
|
|
76
|
+
key: plugin.key,
|
|
77
|
+
component: component
|
|
78
|
+
})));
|
|
79
|
+
const endPlugins = (0, _lodash().default)(plugins === null || plugins === void 0 ? void 0 : plugins.map(plugin => plugin.end && /*#__PURE__*/_react().default.createElement(plugin.end, {
|
|
80
|
+
key: plugin.key,
|
|
81
|
+
component: component
|
|
82
|
+
})));
|
|
83
|
+
return /*#__PURE__*/_react().default.createElement(_react().default.Fragment, null, startPlugins, /*#__PURE__*/_react().default.createElement(_envsUi().EnvIcon, {
|
|
84
|
+
component: component,
|
|
85
|
+
className: _componentResultModule().default.icon
|
|
86
|
+
}), /*#__PURE__*/_react().default.createElement("div", {
|
|
87
|
+
className: (0, _classnames().default)(_componentResultModule().default.name, _designUiStyles().ellipsis)
|
|
88
|
+
}, name), endPlugins);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
//# sourceMappingURL=component-result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["component-result.tsx"],"names":["ComponentResult","component","plugins","name","id","fullName","startPlugins","map","plugin","start","key","endPlugins","end","styles","icon","ellipsis"],"mappings":";;;;;;;;;AAAA;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;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAcO,SAASA,eAAT,CAAyB;AAAEC,EAAAA,SAAF;AAAaC,EAAAA;AAAb,CAAzB,EAAuE;AAC5E,QAAMC,IAAI,GAAGF,SAAS,CAACG,EAAV,CAAaC,QAA1B;AAEA,QAAMC,YAAY,GAAG,uBACnBJ,OADmB,aACnBA,OADmB,uBACnBA,OAAO,CAAEK,GAAT,CAAcC,MAAD,IAAYA,MAAM,CAACC,KAAP,iBAAgB,+BAAC,MAAD,CAAQ,KAAR;AAAc,IAAA,GAAG,EAAED,MAAM,CAACE,GAA1B;AAA+B,IAAA,SAAS,EAAET;AAA1C,IAAzC,CADmB,CAArB;AAGA,QAAMU,UAAU,GAAG,uBACjBT,OADiB,aACjBA,OADiB,uBACjBA,OAAO,CAAEK,GAAT,CAAcC,MAAD,IAAYA,MAAM,CAACI,GAAP,iBAAc,+BAAC,MAAD,CAAQ,GAAR;AAAY,IAAA,GAAG,EAAEJ,MAAM,CAACE,GAAxB;AAA6B,IAAA,SAAS,EAAET;AAAxC,IAAvC,CADiB,CAAnB;AAIA,sBACE,gEACGK,YADH,eAEE,+BAAC,iBAAD;AAAS,IAAA,SAAS,EAAEL,SAApB;AAA+B,IAAA,SAAS,EAAEY,iCAAOC;AAAjD,IAFF,eAGE;AAAK,IAAA,SAAS,EAAE,2BAAWD,iCAAOV,IAAlB,EAAwBY,0BAAxB;AAAhB,KAAoDZ,IAApD,CAHF,EAIGQ,UAJH,CADF;AAQD","sourcesContent":["import React, { ComponentType } from 'react';\nimport compact from 'lodash.compact';\nimport { ComponentModel } from '@teambit/component';\nimport { ellipsis } from '@teambit/design.ui.styles.ellipsis';\nimport { EnvIcon } from '@teambit/envs.ui.env-icon';\nimport classnames from 'classnames';\n\nimport styles from './component-result.module.scss';\n\nexport type ComponentPluginProps = React.HTMLAttributes<HTMLDivElement> & { component: ComponentModel };\n\nexport type ComponentResultPlugin = {\n key: string;\n start?: ComponentType<ComponentPluginProps>;\n end?: ComponentType<ComponentPluginProps>;\n};\ntype ComponentResultProps = {\n component: ComponentModel;\n plugins?: ComponentResultPlugin[];\n};\n\nexport function ComponentResult({ component, plugins }: ComponentResultProps) {\n const name = component.id.fullName;\n\n const startPlugins = compact(\n plugins?.map((plugin) => plugin.start && <plugin.start key={plugin.key} component={component} />)\n );\n const endPlugins = compact(\n plugins?.map((plugin) => plugin.end && <plugin.end key={plugin.key} component={component} />)\n );\n\n return (\n <>\n {startPlugins}\n <EnvIcon component={component} className={styles.icon} />\n <div className={classnames(styles.name, ellipsis)}>{name}</div>\n {endPlugins}\n </>\n );\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ComponentModel } from '@teambit/component';
|
|
2
|
+
import { Searcher, SearchResult, FuzzySearchItem } from '@teambit/explorer.ui.command-bar';
|
|
3
|
+
import type { SearchProvider } from '@teambit/command-bar';
|
|
4
|
+
import { ComponentResultPlugin } from './component-result';
|
|
5
|
+
export type { ComponentResultPlugin };
|
|
6
|
+
declare type ComponentSearchIdx = {
|
|
7
|
+
name: string;
|
|
8
|
+
displayName: string;
|
|
9
|
+
component: ComponentModel;
|
|
10
|
+
};
|
|
11
|
+
declare type ComponentSearcherOptions = {
|
|
12
|
+
navigate: (path: string) => void;
|
|
13
|
+
resultPlugins?: ComponentResultPlugin[];
|
|
14
|
+
};
|
|
15
|
+
export declare class ComponentSearcher extends Searcher<ComponentModel, ComponentSearchIdx> implements SearchProvider {
|
|
16
|
+
options: ComponentSearcherOptions;
|
|
17
|
+
constructor(options: ComponentSearcherOptions);
|
|
18
|
+
updatePlugins(plugins: ComponentResultPlugin[]): void;
|
|
19
|
+
test(term: string): boolean;
|
|
20
|
+
protected toSearchableItem(item: ComponentModel): ComponentSearchIdx;
|
|
21
|
+
protected toSearchResult: ({ item }: FuzzySearchItem<ComponentSearchIdx>) => SearchResult;
|
|
22
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.ComponentSearcher = void 0;
|
|
9
|
+
|
|
10
|
+
function _defineProperty2() {
|
|
11
|
+
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
+
|
|
13
|
+
_defineProperty2 = function () {
|
|
14
|
+
return data;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function _react() {
|
|
21
|
+
const data = _interopRequireDefault(require("react"));
|
|
22
|
+
|
|
23
|
+
_react = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function _explorerUi() {
|
|
31
|
+
const data = require("@teambit/explorer.ui.command-bar");
|
|
32
|
+
|
|
33
|
+
_explorerUi = function () {
|
|
34
|
+
return data;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function _componentResult() {
|
|
41
|
+
const data = require("./component-result");
|
|
42
|
+
|
|
43
|
+
_componentResult = function () {
|
|
44
|
+
return data;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
51
|
+
|
|
52
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2().default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
53
|
+
|
|
54
|
+
const searchKeys = ['displayName', 'name'];
|
|
55
|
+
|
|
56
|
+
class ComponentSearcher extends _explorerUi().Searcher {
|
|
57
|
+
constructor(options) {
|
|
58
|
+
super({
|
|
59
|
+
searchKeys
|
|
60
|
+
});
|
|
61
|
+
this.options = options;
|
|
62
|
+
(0, _defineProperty2().default)(this, "toSearchResult", ({
|
|
63
|
+
item
|
|
64
|
+
}) => {
|
|
65
|
+
const {
|
|
66
|
+
navigate,
|
|
67
|
+
resultPlugins
|
|
68
|
+
} = this.options;
|
|
69
|
+
const {
|
|
70
|
+
component
|
|
71
|
+
} = item;
|
|
72
|
+
return {
|
|
73
|
+
id: component.id.fullName,
|
|
74
|
+
action: () => navigate(`/${component.id.fullName}`),
|
|
75
|
+
children: /*#__PURE__*/_react().default.createElement(_componentResult().ComponentResult, {
|
|
76
|
+
component: component,
|
|
77
|
+
plugins: resultPlugins
|
|
78
|
+
})
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
updatePlugins(plugins) {
|
|
84
|
+
this.options = _objectSpread(_objectSpread({}, this.options), {}, {
|
|
85
|
+
resultPlugins: plugins
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
test(term) {
|
|
90
|
+
return !term.startsWith('>') && term.length > 0;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
toSearchableItem(item) {
|
|
94
|
+
return {
|
|
95
|
+
name: item.id.name,
|
|
96
|
+
displayName: item.id.fullName,
|
|
97
|
+
component: item
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
exports.ComponentSearcher = ComponentSearcher;
|
|
104
|
+
|
|
105
|
+
//# sourceMappingURL=component-searcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["component-searcher.tsx"],"names":["searchKeys","ComponentSearcher","Searcher","constructor","options","item","navigate","resultPlugins","component","id","fullName","action","children","updatePlugins","plugins","test","term","startsWith","length","toSearchableItem","name","displayName"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;AAUA,MAAMA,UAAwC,GAAG,CAAC,aAAD,EAAgB,MAAhB,CAAjD;;AAOO,MAAMC,iBAAN,SAAgCC,sBAAhC,CAAuG;AAC5GC,EAAAA,WAAW,CAAQC,OAAR,EAA2C;AACpD,UAAM;AAAEJ,MAAAA;AAAF,KAAN;AADoD,SAAnCI,OAAmC,GAAnCA,OAAmC;AAAA,4DAuBlB,CAAC;AAAEC,MAAAA;AAAF,KAAD,KAAiE;AACnG,YAAM;AAAEC,QAAAA,QAAF;AAAYC,QAAAA;AAAZ,UAA8B,KAAKH,OAAzC;AACA,YAAM;AAAEI,QAAAA;AAAF,UAAgBH,IAAtB;AAEA,aAAO;AACLI,QAAAA,EAAE,EAAED,SAAS,CAACC,EAAV,CAAaC,QADZ;AAELC,QAAAA,MAAM,EAAE,MAAML,QAAQ,CAAE,IAAGE,SAAS,CAACC,EAAV,CAAaC,QAAS,EAA3B,CAFjB;AAGLE,QAAAA,QAAQ,eAAE,+BAAC,kCAAD;AAAiB,UAAA,SAAS,EAAEJ,SAA5B;AAAuC,UAAA,OAAO,EAAED;AAAhD;AAHL,OAAP;AAKD,KAhCqD;AAErD;;AAEDM,EAAAA,aAAa,CAACC,OAAD,EAAmC;AAC9C,SAAKV,OAAL,mCACK,KAAKA,OADV;AAEEG,MAAAA,aAAa,EAAEO;AAFjB;AAID;;AAEQC,EAAAA,IAAI,CAACC,IAAD,EAAwB;AACnC,WAAO,CAACA,IAAI,CAACC,UAAL,CAAgB,GAAhB,CAAD,IAAyBD,IAAI,CAACE,MAAL,GAAc,CAA9C;AACD;;AAEkBC,EAAAA,gBAAgB,CAACd,IAAD,EAA2C;AAC5E,WAAO;AACLe,MAAAA,IAAI,EAAEf,IAAI,CAACI,EAAL,CAAQW,IADT;AAELC,MAAAA,WAAW,EAAEhB,IAAI,CAACI,EAAL,CAAQC,QAFhB;AAGLF,MAAAA,SAAS,EAAEH;AAHN,KAAP;AAKD;;AAtB2G","sourcesContent":["import React from 'react';\n\nimport { ComponentModel } from '@teambit/component';\nimport { Searcher, SearchResult, FuzzySearchItem } from '@teambit/explorer.ui.command-bar';\nimport type { SearchProvider } from '@teambit/command-bar';\nimport { ComponentResult, ComponentResultPlugin } from './component-result';\n\nexport type { ComponentResultPlugin };\n\ntype ComponentSearchIdx = {\n name: string;\n displayName: string;\n component: ComponentModel;\n};\n\nconst searchKeys: (keyof ComponentSearchIdx)[] = ['displayName', 'name'];\n\ntype ComponentSearcherOptions = {\n navigate: (path: string) => void;\n resultPlugins?: ComponentResultPlugin[];\n};\n\nexport class ComponentSearcher extends Searcher<ComponentModel, ComponentSearchIdx> implements SearchProvider {\n constructor(public options: ComponentSearcherOptions) {\n super({ searchKeys });\n }\n\n updatePlugins(plugins: ComponentResultPlugin[]) {\n this.options = {\n ...this.options,\n resultPlugins: plugins,\n };\n }\n\n override test(term: string): boolean {\n return !term.startsWith('>') && term.length > 0;\n }\n\n protected override toSearchableItem(item: ComponentModel): ComponentSearchIdx {\n return {\n name: item.id.name,\n displayName: item.id.fullName,\n component: item,\n };\n }\n\n protected override toSearchResult = ({ item }: FuzzySearchItem<ComponentSearchIdx>): SearchResult => {\n const { navigate, resultPlugins } = this.options;\n const { component } = item;\n\n return {\n id: component.id.fullName,\n action: () => navigate(`/${component.id.fullName}`),\n children: <ComponentResult component={component} plugins={resultPlugins} />,\n };\n };\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA","sourcesContent":["export { ComponentSearcher } from './component-searcher';\nexport type { ComponentResultPlugin } from './component-searcher';\n"]}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/component",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.709",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/component/component",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.component",
|
|
8
8
|
"name": "component",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.709"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@teambit/any-fs": "0.0.5",
|
|
@@ -17,52 +17,58 @@
|
|
|
17
17
|
"lodash": "4.17.21",
|
|
18
18
|
"semver": "7.3.4",
|
|
19
19
|
"copy-to-clipboard": "3.3.1",
|
|
20
|
-
"react-router-dom": "5.2.0",
|
|
21
20
|
"lodash.flatten": "4.4.0",
|
|
21
|
+
"react-router-dom": "5.2.0",
|
|
22
22
|
"classnames": "2.2.6",
|
|
23
|
+
"lodash.compact": "3.0.1",
|
|
23
24
|
"@babel/runtime": "7.12.18",
|
|
24
25
|
"core-js": "^3.0.0",
|
|
25
26
|
"@teambit/harmony": "0.3.3",
|
|
26
27
|
"@teambit/base-ui.routing.nav-link": "1.0.0",
|
|
27
28
|
"@teambit/documenter.ui.heading": "4.1.1",
|
|
28
29
|
"@teambit/documenter.ui.separator": "4.1.1",
|
|
30
|
+
"@teambit/explorer.ui.command-bar": "1.0.2",
|
|
29
31
|
"@teambit/base-ui.layout.breakpoints": "1.0.0",
|
|
30
32
|
"@teambit/base-ui.routing.routing-provider": "1.0.0",
|
|
31
33
|
"@teambit/design.elements.icon": "1.0.5",
|
|
32
34
|
"@teambit/design.inputs.dropdown": "0.0.7",
|
|
33
35
|
"@teambit/component-id": "0.0.402",
|
|
34
36
|
"@teambit/ui-foundation.ui.menu-widget-icon": "0.0.488",
|
|
35
|
-
"@teambit/aspect-loader": "0.0.
|
|
37
|
+
"@teambit/aspect-loader": "0.0.709",
|
|
36
38
|
"@teambit/legacy-bit-id": "0.0.399",
|
|
37
39
|
"@teambit/toolbox.string.capitalize": "0.0.483",
|
|
38
|
-
"@teambit/cli": "0.0.
|
|
39
|
-
"@teambit/config": "0.0.
|
|
40
|
-
"@teambit/express": "0.0.
|
|
41
|
-
"@teambit/graphql": "0.0.
|
|
40
|
+
"@teambit/cli": "0.0.472",
|
|
41
|
+
"@teambit/config": "0.0.485",
|
|
42
|
+
"@teambit/express": "0.0.568",
|
|
43
|
+
"@teambit/graphql": "0.0.709",
|
|
42
44
|
"@teambit/bit-error": "0.0.394",
|
|
43
|
-
"@teambit/command-bar": "0.0.
|
|
44
|
-
"@teambit/
|
|
45
|
-
"@teambit/
|
|
45
|
+
"@teambit/command-bar": "0.0.709",
|
|
46
|
+
"@teambit/component.ui.deprecation-icon": "0.0.493",
|
|
47
|
+
"@teambit/preview": "0.0.709",
|
|
48
|
+
"@teambit/pubsub": "0.0.709",
|
|
49
|
+
"@teambit/react-router": "0.0.709",
|
|
46
50
|
"@teambit/ui-foundation.ui.is-browser": "0.0.486",
|
|
47
51
|
"@teambit/ui-foundation.ui.main-dropdown": "0.0.487",
|
|
48
52
|
"@teambit/ui-foundation.ui.react-router.slot-router": "0.0.489",
|
|
49
53
|
"@teambit/ui-foundation.ui.use-box.menu": "0.0.114",
|
|
50
|
-
"@teambit/ui": "0.0.
|
|
54
|
+
"@teambit/ui": "0.0.709",
|
|
51
55
|
"@teambit/component-issues": "0.0.50",
|
|
52
56
|
"@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.487",
|
|
53
|
-
"@teambit/cli-table": "0.0.
|
|
54
|
-
"@teambit/component-descriptor": "0.0.
|
|
55
|
-
"@teambit/lanes.ui.lanes": "0.0.
|
|
57
|
+
"@teambit/cli-table": "0.0.34",
|
|
58
|
+
"@teambit/component-descriptor": "0.0.35",
|
|
59
|
+
"@teambit/lanes.ui.lanes": "0.0.38",
|
|
56
60
|
"@teambit/ui-foundation.ui.react-router.use-query": "0.0.486",
|
|
57
61
|
"@teambit/design.ui.empty-box": "0.0.353",
|
|
58
62
|
"@teambit/harmony.ui.aspect-box": "0.0.486",
|
|
59
63
|
"@teambit/design.ui.pages.not-found": "0.0.354",
|
|
60
64
|
"@teambit/design.ui.pages.server-error": "0.0.354",
|
|
61
|
-
"@teambit/compositions": "0.0.
|
|
62
|
-
"@teambit/deprecation": "0.0.
|
|
63
|
-
"@teambit/envs": "0.0.
|
|
65
|
+
"@teambit/compositions": "0.0.709",
|
|
66
|
+
"@teambit/deprecation": "0.0.709",
|
|
67
|
+
"@teambit/envs": "0.0.709",
|
|
64
68
|
"@teambit/legacy-component-log": "0.0.392",
|
|
65
|
-
"@teambit/
|
|
69
|
+
"@teambit/design.ui.styles.ellipsis": "0.0.347",
|
|
70
|
+
"@teambit/envs.ui.env-icon": "0.0.486",
|
|
71
|
+
"@teambit/component.ui.version-dropdown": "0.0.523",
|
|
66
72
|
"@teambit/ui-foundation.ui.full-loader": "0.0.486",
|
|
67
73
|
"@teambit/ui-foundation.ui.use-box.dropdown": "0.0.114",
|
|
68
74
|
"@teambit/ui-foundation.ui.constants.z-indexes": "0.0.487",
|
|
@@ -73,9 +79,10 @@
|
|
|
73
79
|
"@types/minimatch": "3.0.4",
|
|
74
80
|
"@types/lodash": "4.14.165",
|
|
75
81
|
"@types/semver": "7.3.4",
|
|
76
|
-
"@types/react-router-dom": "5.1.7",
|
|
77
82
|
"@types/lodash.flatten": "4.4.6",
|
|
83
|
+
"@types/react-router-dom": "5.1.7",
|
|
78
84
|
"@types/classnames": "2.2.11",
|
|
85
|
+
"@types/lodash.compact": "3.0.6",
|
|
79
86
|
"@types/mocha": "9.1.0",
|
|
80
87
|
"@types/testing-library__jest-dom": "5.9.5",
|
|
81
88
|
"@types/jest": "^26.0.0",
|
|
@@ -85,7 +92,7 @@
|
|
|
85
92
|
},
|
|
86
93
|
"peerDependencies": {
|
|
87
94
|
"@apollo/client": "^3.0.0",
|
|
88
|
-
"@teambit/legacy": "1.0.
|
|
95
|
+
"@teambit/legacy": "1.0.251",
|
|
89
96
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
90
97
|
"react": "^16.8.0 || ^17.0.0"
|
|
91
98
|
},
|
|
@@ -113,7 +120,7 @@
|
|
|
113
120
|
"react": "-"
|
|
114
121
|
},
|
|
115
122
|
"peerDependencies": {
|
|
116
|
-
"@teambit/legacy": "1.0.
|
|
123
|
+
"@teambit/legacy": "1.0.251",
|
|
117
124
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
118
125
|
"react": "^16.8.0 || ^17.0.0"
|
|
119
126
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component@0.0.
|
|
2
|
-
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component@0.0.
|
|
1
|
+
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component@0.0.709/dist/component.composition.js')]
|
|
2
|
+
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component@0.0.709/dist/component.docs.mdx')]
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React, { ComponentType } from 'react';
|
|
2
|
+
import compact from 'lodash.compact';
|
|
3
|
+
import { ComponentModel } from '@teambit/component';
|
|
4
|
+
import { ellipsis } from '@teambit/design.ui.styles.ellipsis';
|
|
5
|
+
import { EnvIcon } from '@teambit/envs.ui.env-icon';
|
|
6
|
+
import classnames from 'classnames';
|
|
7
|
+
|
|
8
|
+
import styles from './component-result.module.scss';
|
|
9
|
+
|
|
10
|
+
export type ComponentPluginProps = React.HTMLAttributes<HTMLDivElement> & { component: ComponentModel };
|
|
11
|
+
|
|
12
|
+
export type ComponentResultPlugin = {
|
|
13
|
+
key: string;
|
|
14
|
+
start?: ComponentType<ComponentPluginProps>;
|
|
15
|
+
end?: ComponentType<ComponentPluginProps>;
|
|
16
|
+
};
|
|
17
|
+
type ComponentResultProps = {
|
|
18
|
+
component: ComponentModel;
|
|
19
|
+
plugins?: ComponentResultPlugin[];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export function ComponentResult({ component, plugins }: ComponentResultProps) {
|
|
23
|
+
const name = component.id.fullName;
|
|
24
|
+
|
|
25
|
+
const startPlugins = compact(
|
|
26
|
+
plugins?.map((plugin) => plugin.start && <plugin.start key={plugin.key} component={component} />)
|
|
27
|
+
);
|
|
28
|
+
const endPlugins = compact(
|
|
29
|
+
plugins?.map((plugin) => plugin.end && <plugin.end key={plugin.key} component={component} />)
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<>
|
|
34
|
+
{startPlugins}
|
|
35
|
+
<EnvIcon component={component} className={styles.icon} />
|
|
36
|
+
<div className={classnames(styles.name, ellipsis)}>{name}</div>
|
|
37
|
+
{endPlugins}
|
|
38
|
+
</>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { ComponentModel } from '@teambit/component';
|
|
4
|
+
import { Searcher, SearchResult, FuzzySearchItem } from '@teambit/explorer.ui.command-bar';
|
|
5
|
+
import type { SearchProvider } from '@teambit/command-bar';
|
|
6
|
+
import { ComponentResult, ComponentResultPlugin } from './component-result';
|
|
7
|
+
|
|
8
|
+
export type { ComponentResultPlugin };
|
|
9
|
+
|
|
10
|
+
type ComponentSearchIdx = {
|
|
11
|
+
name: string;
|
|
12
|
+
displayName: string;
|
|
13
|
+
component: ComponentModel;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const searchKeys: (keyof ComponentSearchIdx)[] = ['displayName', 'name'];
|
|
17
|
+
|
|
18
|
+
type ComponentSearcherOptions = {
|
|
19
|
+
navigate: (path: string) => void;
|
|
20
|
+
resultPlugins?: ComponentResultPlugin[];
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export class ComponentSearcher extends Searcher<ComponentModel, ComponentSearchIdx> implements SearchProvider {
|
|
24
|
+
constructor(public options: ComponentSearcherOptions) {
|
|
25
|
+
super({ searchKeys });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
updatePlugins(plugins: ComponentResultPlugin[]) {
|
|
29
|
+
this.options = {
|
|
30
|
+
...this.options,
|
|
31
|
+
resultPlugins: plugins,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
override test(term: string): boolean {
|
|
36
|
+
return !term.startsWith('>') && term.length > 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
protected override toSearchableItem(item: ComponentModel): ComponentSearchIdx {
|
|
40
|
+
return {
|
|
41
|
+
name: item.id.name,
|
|
42
|
+
displayName: item.id.fullName,
|
|
43
|
+
component: item,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
protected override toSearchResult = ({ item }: FuzzySearchItem<ComponentSearchIdx>): SearchResult => {
|
|
48
|
+
const { navigate, resultPlugins } = this.options;
|
|
49
|
+
const { component } = item;
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
id: component.id.fullName,
|
|
53
|
+
action: () => navigate(`/${component.id.fullName}`),
|
|
54
|
+
children: <ComponentResult component={component} plugins={resultPlugins} />,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
}
|
|
Binary file
|