@teambit/scope 0.0.866 → 0.0.868

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/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/scope",
3
- "version": "0.0.866",
3
+ "version": "0.0.868",
4
4
  "homepage": "https://bit.dev/teambit/scope/scope",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.scope",
8
8
  "name": "scope",
9
- "version": "0.0.866"
9
+ "version": "0.0.868"
10
10
  },
11
11
  "dependencies": {
12
12
  "chalk": "2.4.2",
@@ -16,8 +16,8 @@
16
16
  "fs-extra": "10.0.0",
17
17
  "lodash": "4.17.21",
18
18
  "multimatch": "5.0.0",
19
- "reset-css": "5.0.1",
20
19
  "classnames": "2.2.6",
20
+ "reset-css": "5.0.1",
21
21
  "@babel/runtime": "7.12.18",
22
22
  "core-js": "^3.0.0",
23
23
  "@teambit/harmony": "0.3.3",
@@ -25,41 +25,44 @@
25
25
  "@teambit/base-ui.surfaces.split-pane.hover-splitter": "1.0.0",
26
26
  "@teambit/base-ui.surfaces.split-pane.split-pane": "1.0.0",
27
27
  "@teambit/base-ui.utils.composer": "1.0.0",
28
- "@teambit/scope.models.scope-model": "0.0.234",
29
- "@teambit/scope.ui.hooks.scope-context": "0.0.234",
30
- "@teambit/cli": "0.0.577",
31
- "@teambit/component": "0.0.866",
32
- "@teambit/logger": "0.0.670",
33
- "@teambit/aspect-loader": "0.0.866",
28
+ "@teambit/scope.models.scope-model": "0.0.236",
29
+ "@teambit/scope.ui.hooks.scope-context": "0.0.236",
30
+ "@teambit/cli": "0.0.579",
31
+ "@teambit/component": "0.0.868",
32
+ "@teambit/logger": "0.0.672",
33
+ "@teambit/aspect-loader": "0.0.868",
34
34
  "@teambit/bit-error": "0.0.400",
35
- "@teambit/builder": "0.0.866",
36
- "@teambit/compiler": "0.0.866",
37
- "@teambit/envs": "0.0.866",
38
- "@teambit/express": "0.0.675",
39
- "@teambit/graphql": "0.0.866",
35
+ "@teambit/builder": "0.0.868",
36
+ "@teambit/compiler": "0.0.868",
37
+ "@teambit/envs": "0.0.868",
38
+ "@teambit/express": "0.0.677",
39
+ "@teambit/graphql": "0.0.868",
40
40
  "@teambit/harmony.modules.requireable-component": "0.0.490",
41
- "@teambit/isolator": "0.0.866",
41
+ "@teambit/isolator": "0.0.868",
42
42
  "@teambit/legacy-bit-id": "0.0.414",
43
- "@teambit/ui": "0.0.866",
43
+ "@teambit/ui": "0.0.868",
44
44
  "@teambit/workspace.modules.match-pattern": "0.0.495",
45
45
  "@teambit/component-id": "0.0.417",
46
- "@teambit/component.ui.component-drawer": "0.0.131",
46
+ "@teambit/component.ui.component-drawer": "0.0.133",
47
47
  "@teambit/design.ui.tree": "0.0.12",
48
- "@teambit/ui-foundation.ui.side-bar": "0.0.648",
49
- "@teambit/command-bar": "0.0.866",
50
- "@teambit/component-tree": "0.0.654",
48
+ "@teambit/lanes.hooks.use-lane-components": "0.0.38",
49
+ "@teambit/lanes.hooks.use-lanes": "0.0.39",
50
+ "@teambit/ui-foundation.ui.side-bar": "0.0.650",
51
+ "@teambit/command-bar": "0.0.868",
52
+ "@teambit/component-tree": "0.0.656",
51
53
  "@teambit/component.modules.component-url": "0.0.140",
52
- "@teambit/component.ui.component-filters.component-filter-context": "0.0.7",
53
- "@teambit/component.ui.component-filters.deprecate-filter": "0.0.7",
54
- "@teambit/component.ui.component-filters.env-filter": "0.0.13",
55
- "@teambit/sidebar": "0.0.866",
54
+ "@teambit/component.ui.component-filters.component-filter-context": "0.0.8",
55
+ "@teambit/component.ui.component-filters.deprecate-filter": "0.0.8",
56
+ "@teambit/component.ui.component-filters.env-filter": "0.0.14",
57
+ "@teambit/component.ui.component-filters.show-main-filter": "0.0.1",
58
+ "@teambit/sidebar": "0.0.868",
56
59
  "@teambit/ui-foundation.ui.main-dropdown": "0.0.493",
57
60
  "@teambit/ui-foundation.ui.menu": "0.0.493",
58
61
  "@teambit/ui-foundation.ui.react-router.slot-router": "0.0.496",
59
62
  "@teambit/ui-foundation.ui.tree.drawer": "0.0.505",
60
- "@teambit/lane-id": "0.0.95",
63
+ "@teambit/lane-id": "0.0.97",
61
64
  "@teambit/ui-foundation.ui.constants.z-indexes": "0.0.494",
62
- "@teambit/scope.ui.hooks.use-scope": "0.0.239",
65
+ "@teambit/scope.ui.hooks.use-scope": "0.0.241",
63
66
  "@teambit/ui-foundation.ui.buttons.collapser": "0.0.201",
64
67
  "@teambit/ui-foundation.ui.corner": "0.0.504",
65
68
  "@teambit/ui-foundation.ui.full-loader": "0.0.492",
@@ -88,7 +91,7 @@
88
91
  },
89
92
  "peerDependencies": {
90
93
  "react-router-dom": "^6.0.0",
91
- "@teambit/legacy": "1.0.358",
94
+ "@teambit/legacy": "1.0.360",
92
95
  "react-dom": "^16.8.0 || ^17.0.0",
93
96
  "react": "^16.8.0 || ^17.0.0"
94
97
  },
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.scope_scope@0.0.866/dist/scope.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.scope_scope@0.0.866/dist/scope.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.scope_scope@0.0.868/dist/scope.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.scope_scope@0.0.868/dist/scope.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
@@ -1,8 +1,18 @@
1
1
  import React, { useContext } from 'react';
2
2
  import { ComponentsDrawer, ComponentFiltersSlot, DrawerWidgetSlot } from '@teambit/component.ui.component-drawer';
3
- import { ScopeContext } from '@teambit/scope.ui.hooks.scope-context';
4
- import { ComponentView, NamespaceTreeNode, PayloadType, ScopePayload } from '@teambit/ui-foundation.ui.side-bar';
5
- import { TreeNodeProps } from '@teambit/design.ui.tree';
3
+ import {
4
+ ComponentView,
5
+ NamespaceTreeNode,
6
+ PayloadType,
7
+ ScopePayload,
8
+ ScopeTreeNode,
9
+ } from '@teambit/ui-foundation.ui.side-bar';
10
+ import { TreeNode as TreeNodeType, TreeNodeProps } from '@teambit/design.ui.tree';
11
+ import { useLanes } from '@teambit/lanes.hooks.use-lanes';
12
+ import { useLaneComponents } from '@teambit/lanes.hooks.use-lane-components';
13
+ import { ComponentModel } from '@teambit/component';
14
+ import { useScope, ScopeContext } from '@teambit/scope.ui.hooks.scope-context';
15
+ // import { WorkspaceModel } from '@teambit/workspace';
6
16
  import { SidebarSlot } from './scope.ui.runtime';
7
17
 
8
18
  export type ScopeDrawerProps = {
@@ -10,6 +20,7 @@ export type ScopeDrawerProps = {
10
20
  filtersSlot: ComponentFiltersSlot;
11
21
  drawerWidgetSlot: DrawerWidgetSlot;
12
22
  assumeScopeInUrl?: boolean;
23
+ overrideUseComponents?: () => { components: ComponentModel[] };
13
24
  };
14
25
 
15
26
  export const scopeDrawer = ({
@@ -17,8 +28,9 @@ export const scopeDrawer = ({
17
28
  filtersSlot,
18
29
  drawerWidgetSlot,
19
30
  assumeScopeInUrl = false,
31
+ overrideUseComponents,
20
32
  }: ScopeDrawerProps) => {
21
- const customScopeTreeNodeRenderer = (treeNodeSlot) =>
33
+ const customScopeTreeNodeRenderer = (treeNodeSlot, host?: any) =>
22
34
  function TreeNode(props: TreeNodeProps<PayloadType>) {
23
35
  const children = props.node.children;
24
36
 
@@ -26,6 +38,18 @@ export const scopeDrawer = ({
26
38
 
27
39
  // skip over scope node and render only children
28
40
  if (props.node.payload instanceof ScopePayload) {
41
+ const scopeNameFromNode = props.node.id.slice(0, -1);
42
+ const scope = host?.name;
43
+
44
+ /**
45
+ * this is only valid when viewing component from a lane
46
+ * if the lane component is from a different scope than the current scope
47
+ * show the scope node
48
+ */
49
+ if (scopeNameFromNode !== scope) {
50
+ return <ScopeTreeNode {...props} />;
51
+ }
52
+
29
53
  return (
30
54
  <>
31
55
  {children.map((childNode) => (
@@ -51,13 +75,54 @@ export const scopeDrawer = ({
51
75
  filters: filtersSlot,
52
76
  drawerWidgets: drawerWidgetSlot,
53
77
  },
78
+ useHost: () => useScope(),
54
79
  emptyMessage: 'Scope is empty',
55
- useComponents: () => {
56
- const scope = useContext(ScopeContext);
57
- return {
58
- loading: !scope,
59
- components: scope.components || [],
80
+ // TODO: create an interface for Component host.
81
+ transformTree: (host?: any) => {
82
+ return (rootNode: TreeNodeType) => {
83
+ const thisScopeIndex = rootNode.children?.findIndex((node) => {
84
+ if (!(node.payload instanceof ScopePayload)) return undefined;
85
+ const scopeNameFromNode = node.id.slice(0, -1);
86
+ return scopeNameFromNode === host?.name;
87
+ });
88
+
89
+ const thisScope = rootNode.children ? rootNode.children[thisScopeIndex || ''] : undefined;
90
+
91
+ if (thisScopeIndex && thisScopeIndex !== -1 && rootNode.children) {
92
+ delete rootNode.children[thisScopeIndex];
93
+ const children = rootNode.children.concat(thisScope.children);
94
+ rootNode.children = children;
95
+ }
96
+
97
+ return rootNode;
60
98
  };
61
99
  },
100
+ useComponents:
101
+ overrideUseComponents ||
102
+ (() => {
103
+ const { lanesModel, loading: lanesLoading } = useLanes();
104
+ const viewedLaneId = lanesModel?.viewedLane?.id;
105
+
106
+ const { components: laneComponents = [], loading: laneCompsLoading } = useLaneComponents(
107
+ viewedLaneId?.isDefault() ? undefined : viewedLaneId
108
+ );
109
+ const { components: mainComponents } = useContext(ScopeContext);
110
+ // lane components + main components
111
+ const components = mergeComponents(mainComponents, laneComponents);
112
+
113
+ return {
114
+ loading: lanesLoading || laneCompsLoading,
115
+ components,
116
+ };
117
+ }),
62
118
  });
63
119
  };
120
+
121
+ function mergeComponents(mainComponents: ComponentModel[], laneComponents: ComponentModel[]): ComponentModel[] {
122
+ const mainComponentsThatAreNotOnLane = mainComponents.filter((mainComponent) => {
123
+ return !laneComponents.find(
124
+ (laneComponent) => laneComponent.id.toStringWithoutVersion() === mainComponent.id.toStringWithoutVersion()
125
+ );
126
+ });
127
+ return laneComponents.concat(mainComponentsThatAreNotOnLane);
128
+ }
@@ -24,6 +24,7 @@ import { ComponentFilters } from '@teambit/component.ui.component-filters.compon
24
24
  import { DeprecateFilter } from '@teambit/component.ui.component-filters.deprecate-filter';
25
25
  import { EnvsFilter } from '@teambit/component.ui.component-filters.env-filter';
26
26
  import { ComponentUrlResolver, ComponentUrlProvider } from '@teambit/component.modules.component-url';
27
+ import { ShowMainFilter } from '@teambit/component.ui.component-filters.show-main-filter';
27
28
  import { ScopeMenu, ScopeUseBox } from './ui/menu';
28
29
  import { ScopeAspect } from './scope.aspect';
29
30
  import { Scope } from './ui/scope';
@@ -124,6 +125,7 @@ export class ScopeUI {
124
125
  return (
125
126
  <Scope
126
127
  TargetScopeOverview={options.TargetScopeOverview}
128
+ scopeClassName={options.scopeClassName}
127
129
  TargetCorner={options.Corner}
128
130
  routeSlot={this.routeSlot}
129
131
  menuSlot={this.menuSlot}
@@ -136,6 +138,7 @@ export class ScopeUI {
136
138
  onSidebarTogglerChange={this.setSidebarToggle}
137
139
  cornerSlot={this.cornerSlot}
138
140
  paneClassName={options.paneClassName}
141
+ PaneWrapper={options.PaneWrapper}
139
142
  />
140
143
  );
141
144
  }
@@ -281,13 +284,14 @@ export class ScopeUI {
281
284
  this.drawerWidgetSlot.register(widgets);
282
285
  };
283
286
 
284
- registerDefaultDrawers(assumeScopeInUrl = false) {
287
+ registerDefaultDrawers(assumeScopeInUrl = false, overrideUseComponents?: () => { components: ComponentModel[] }) {
285
288
  this.sidebar.registerDrawer(
286
289
  scopeDrawer({
287
290
  treeWidgets: this.sidebarSlot,
288
291
  filtersSlot: this.drawerComponentsFiltersSlot,
289
292
  drawerWidgetSlot: this.drawerWidgetSlot,
290
293
  assumeScopeInUrl,
294
+ overrideUseComponents,
291
295
  })
292
296
  );
293
297
  }
@@ -332,9 +336,11 @@ export class ScopeUI {
332
336
  return aWeight - bWeight;
333
337
  });
334
338
 
335
- return compact(sorted.map((link) => {
336
- return link.component;
337
- }));
339
+ return compact(
340
+ sorted.map((link) => {
341
+ return link.component;
342
+ })
343
+ );
338
344
  }
339
345
 
340
346
  /** registers available components */
@@ -427,7 +433,7 @@ export class ScopeUI {
427
433
  drawerWidgetSlot,
428
434
  componentFiltersSlot
429
435
  );
430
- scopeUi.registerDrawerComponentFilters([DeprecateFilter, EnvsFilter]);
436
+ scopeUi.registerDrawerComponentFilters([DeprecateFilter, EnvsFilter, ShowMainFilter(false)]);
431
437
  scopeUi.registerDrawerWidgets([
432
438
  <FilterWidget key={'workspace-filter-widget'} />,
433
439
  <TreeToggleWidget key={'workspace-tree-toggle-widget'} />,
@@ -440,7 +446,7 @@ export class ScopeUI {
440
446
  component: function Gallery() {
441
447
  return (
442
448
  <MenuLinkItem exact href="/" icon="comps">
443
- Gallery
449
+ Overview
444
450
  </MenuLinkItem>
445
451
  );
446
452
  },
@@ -40,3 +40,7 @@
40
40
 
41
41
  height: 100%;
42
42
  }
43
+
44
+ .pane {
45
+ height: 100%;
46
+ }
package/ui/scope.tsx CHANGED
@@ -1,4 +1,6 @@
1
+ import React, { useReducer, ComponentType, ReactNode } from 'react';
1
2
  import 'reset-css';
3
+ import classNames from 'classnames';
2
4
  import { SplitPane, Pane, Layout } from '@teambit/base-ui.surfaces.split-pane.split-pane';
3
5
  import { RouteSlot, SlotRouter } from '@teambit/ui-foundation.ui.react-router.slot-router';
4
6
  import { Corner } from '@teambit/ui-foundation.ui.corner';
@@ -7,7 +9,6 @@ import { HoverSplitter } from '@teambit/base-ui.surfaces.split-pane.hover-splitt
7
9
  import { TopBar } from '@teambit/ui-foundation.ui.top-bar';
8
10
  import { Composer, ComponentTuple } from '@teambit/base-ui.utils.composer';
9
11
  import { FullLoader } from '@teambit/ui-foundation.ui.full-loader';
10
- import React, { useReducer, ComponentType } from 'react';
11
12
  import { Route } from 'react-router-dom';
12
13
  import { useIsMobile } from '@teambit/ui-foundation.ui.hooks.use-is-mobile';
13
14
  import { ScopeProvider } from '@teambit/scope.ui.hooks.scope-context';
@@ -31,6 +32,8 @@ export type ScopeProps = {
31
32
  onSidebarTogglerChange: (callback: () => void) => void;
32
33
  TargetCorner?: ComponentType;
33
34
  paneClassName?: string;
35
+ scopeClassName?: string;
36
+ PaneWrapper?: ComponentType<{ children: ReactNode }>;
34
37
  };
35
38
 
36
39
  /**
@@ -44,12 +47,14 @@ export function Scope({
44
47
  badgeSlot,
45
48
  overviewLineSlot,
46
49
  cornerSlot,
50
+ PaneWrapper,
47
51
  context = [],
48
52
  paneClassName,
49
- TargetScopeOverview,
53
+ TargetScopeOverview,
50
54
  TargetCorner,
51
55
  onSidebarTogglerChange,
52
56
  userUseScopeQuery,
57
+ scopeClassName,
53
58
  }: ScopeProps) {
54
59
  const { scope } = userUseScopeQuery ? userUseScopeQuery() : useScopeQuery();
55
60
  const isMobile = useIsMobile();
@@ -67,7 +72,7 @@ TargetScopeOverview,
67
72
  return (
68
73
  <ScopeProvider scope={scope}>
69
74
  <Composer components={Context}>
70
- <div className={styles.scope}>
75
+ <div className={classNames(styles.scope, scopeClassName)}>
71
76
  <TopBar
72
77
  className={styles.topbar}
73
78
  Corner={() => {
@@ -87,23 +92,36 @@ TargetScopeOverview,
87
92
  tooltipContent={`${isSidebarOpen ? 'Hide' : 'Show'} side panel`}
88
93
  />
89
94
  </HoverSplitter>
90
- <Pane className={paneClassName}>
91
- <SlotRouter slot={routeSlot}>
92
- <Route
93
- index
94
- element={
95
- <ScopeOverview
96
- badgeSlot={badgeSlot}
97
- overviewSlot={overviewLineSlot}
98
- TargetOverview={TargetScopeOverview}
99
- />
100
- }
101
- />
102
- </SlotRouter>
103
- </Pane>
95
+ <PaneContainer Wrapper={PaneWrapper}>
96
+ <Pane className={classNames(paneClassName, styles.pane)}>
97
+ <SlotRouter slot={routeSlot}>
98
+ <Route
99
+ index
100
+ element={
101
+ <ScopeOverview
102
+ badgeSlot={badgeSlot}
103
+ overviewSlot={overviewLineSlot}
104
+ TargetOverview={TargetScopeOverview}
105
+ />
106
+ }
107
+ />
108
+ </SlotRouter>
109
+ </Pane>
110
+ </PaneContainer>
104
111
  </SplitPane>
105
112
  </div>
106
113
  </Composer>
107
114
  </ScopeProvider>
108
115
  );
109
116
  }
117
+
118
+ function PaneContainer({
119
+ children,
120
+ Wrapper,
121
+ }: {
122
+ children: ReactNode;
123
+ Wrapper?: ComponentType<{ children: ReactNode }>;
124
+ }) {
125
+ if (!Wrapper) return <>{children}</>;
126
+ return <Wrapper>{children}</Wrapper>;
127
+ }