@teambit/component 0.0.551 → 0.0.556

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/dist/aspect-list.d.ts +18 -0
  2. package/dist/component-factory.d.ts +49 -0
  3. package/dist/component-fs.d.ts +20 -1
  4. package/dist/component-map/component-map.d.ts +32 -0
  5. package/dist/component-meta.d.ts +11 -1
  6. package/dist/component.d.ts +96 -1
  7. package/dist/component.main.runtime.d.ts +30 -1
  8. package/dist/component.ui.runtime.d.ts +21 -1
  9. package/dist/config.d.ts +18 -1
  10. package/dist/dependencies/dependencies.d.ts +18 -0
  11. package/dist/exceptions/host-not-found.d.ts +8 -1
  12. package/dist/hash.d.ts +3 -0
  13. package/dist/show/show-fragment.d.ts +23 -0
  14. package/dist/snap/author.d.ts +12 -0
  15. package/dist/snap/snap.d.ts +39 -1
  16. package/dist/state.d.ts +44 -1
  17. package/dist/tag/tag.d.ts +21 -1
  18. package/dist/tag-map.d.ts +19 -0
  19. package/dist/ui/component-error/component-error.d.ts +15 -1
  20. package/dist/ui/component-model/component-model.d.ts +102 -1
  21. package/dist/ui/component.d.ts +3 -0
  22. package/dist/ui/context/component-provider.d.ts +6 -0
  23. package/dist/ui/menu/menu.d.ts +12 -0
  24. package/dist/ui/use-component-query.d.ts +1 -0
  25. package/package.json +40 -34
  26. package/aspect-entry.ts +0 -67
  27. package/aspect-list.ts +0 -100
  28. package/aspect.section.tsx +0 -16
  29. package/component-factory.ts +0 -106
  30. package/component-fs.ts +0 -60
  31. package/component-map/component-map.ts +0 -106
  32. package/component-map/index.ts +0 -1
  33. package/component-meta.ts +0 -29
  34. package/component.aspect.ts +0 -9
  35. package/component.docs.mdx +0 -8
  36. package/component.graphql.ts +0 -202
  37. package/component.main.runtime.ts +0 -162
  38. package/component.route.ts +0 -26
  39. package/component.ts +0 -278
  40. package/component.ui.runtime.tsx +0 -216
  41. package/config.ts +0 -34
  42. package/dependencies/dependencies.ts +0 -74
  43. package/dependencies/index.ts +0 -1
  44. package/exceptions/could-not-find-latest.ts +0 -8
  45. package/exceptions/host-not-found.ts +0 -14
  46. package/exceptions/index.ts +0 -4
  47. package/exceptions/nothing-to-snap.ts +0 -1
  48. package/hash.ts +0 -4
  49. package/head.ts +0 -0
  50. package/history-graph.ts +0 -1
  51. package/host/component-host-model.ts +0 -9
  52. package/host/index.ts +0 -2
  53. package/host/use-component-host.ts +0 -39
  54. package/index.ts +0 -32
  55. package/on-load.ts +0 -0
  56. package/package-tar/teambit-component-0.0.551.tgz +0 -0
  57. package/section/index.ts +0 -1
  58. package/section/section.tsx +0 -8
  59. package/show/extensions.fragment.ts +0 -23
  60. package/show/files.fragment.ts +0 -24
  61. package/show/id.fragment.ts +0 -20
  62. package/show/index.ts +0 -8
  63. package/show/main-file.fragment.ts +0 -13
  64. package/show/name.fragment.ts +0 -13
  65. package/show/scope.fragment.ts +0 -15
  66. package/show/show-fragment.ts +0 -44
  67. package/show/show.cmd.ts +0 -85
  68. package/snap/author.ts +0 -19
  69. package/snap/index.ts +0 -2
  70. package/snap/snap.ts +0 -63
  71. package/state.ts +0 -73
  72. package/store.ts +0 -3
  73. package/tag/index.ts +0 -1
  74. package/tag/tag.ts +0 -37
  75. package/tag-map.ts +0 -87
  76. package/tsconfig.json +0 -35
  77. package/types/asset.d.ts +0 -29
  78. package/types/style.d.ts +0 -42
  79. package/ui/aspect-page/aspect-page.module.scss +0 -20
  80. package/ui/aspect-page/aspect-page.tsx +0 -64
  81. package/ui/aspect-page/index.ts +0 -1
  82. package/ui/component-error/component-error.tsx +0 -22
  83. package/ui/component-error/index.ts +0 -1
  84. package/ui/component-model/component-model.ts +0 -169
  85. package/ui/component-model/index.ts +0 -1
  86. package/ui/component.module.scss +0 -7
  87. package/ui/component.tsx +0 -48
  88. package/ui/context/component-context.ts +0 -5
  89. package/ui/context/component-provider.tsx +0 -20
  90. package/ui/context/index.ts +0 -2
  91. package/ui/index.ts +0 -3
  92. package/ui/menu/index.ts +0 -2
  93. package/ui/menu/menu-nav.tsx +0 -37
  94. package/ui/menu/menu.module.scss +0 -62
  95. package/ui/menu/menu.tsx +0 -94
  96. package/ui/menu/nav-plugin.tsx +0 -9
  97. package/ui/top-bar-nav/index.ts +0 -1
  98. package/ui/top-bar-nav/top-bar-nav.module.scss +0 -52
  99. package/ui/top-bar-nav/top-bar-nav.tsx +0 -26
  100. package/ui/use-component-query.ts +0 -195
  101. package/ui/use-component.tsx +0 -34
@@ -1,26 +0,0 @@
1
- import { NavLink, NavLinkProps } from '@teambit/base-ui.routing.nav-link';
2
- import { extendPath } from '@teambit/ui-foundation.ui.react-router.extend-path';
3
- import classnames from 'classnames';
4
- import React from 'react';
5
- import { useRouteMatch, useLocation } from 'react-router-dom';
6
-
7
- import styles from './top-bar-nav.module.scss';
8
-
9
- export function TopBarNav(props: NavLinkProps) {
10
- const { url } = useRouteMatch();
11
- const { search } = useLocation(); // sticky query params
12
- const { href } = props;
13
-
14
- const target = `${extendPath(url, href)}${search}`;
15
-
16
- return (
17
- <NavLink
18
- {...props}
19
- className={classnames(props.className, styles.topBarLink)}
20
- activeClassName={classnames(props.className, styles.active)}
21
- href={target}
22
- >
23
- <div>{props.children}</div>
24
- </NavLink>
25
- );
26
- }
@@ -1,195 +0,0 @@
1
- import { useMemo, useEffect, useRef } from 'react';
2
- import { gql } from '@apollo/client';
3
- import { useDataQuery } from '@teambit/ui-foundation.ui.hooks.use-data-query';
4
- import { ComponentID, ComponentIdObj } from '@teambit/component-id';
5
-
6
- import { ComponentModel } from './component-model';
7
- import { ComponentError } from './component-error';
8
-
9
- const componentIdFields = gql`
10
- fragment componentIdFields on ComponentID {
11
- name
12
- version
13
- scope
14
- }
15
- `;
16
-
17
- const componentFields = gql`
18
- fragment componentFields on Component {
19
- id {
20
- ...componentIdFields
21
- }
22
- packageName
23
- elementsUrl
24
- displayName
25
- server {
26
- env
27
- url
28
- }
29
- buildStatus
30
- compositions {
31
- identifier
32
- displayName
33
- }
34
- tags {
35
- version
36
- }
37
- env {
38
- id
39
- icon
40
- }
41
- }
42
- ${componentIdFields}
43
- `;
44
-
45
- const GET_COMPONENT = gql`
46
- query Component($id: String!, $extensionId: String!) {
47
- getHost(id: $extensionId) {
48
- id # used for GQL caching
49
- get(id: $id) {
50
- ...componentFields
51
- }
52
- }
53
- }
54
- ${componentFields}
55
- `;
56
-
57
- const SUB_SUBSCRIPTION_ADDED = gql`
58
- subscription OnComponentAdded {
59
- componentAdded {
60
- component {
61
- ...componentFields
62
- }
63
- }
64
- }
65
- ${componentFields}
66
- `;
67
-
68
- const SUB_COMPONENT_CHANGED = gql`
69
- subscription OnComponentChanged {
70
- componentChanged {
71
- component {
72
- ...componentFields
73
- }
74
- }
75
- }
76
- ${componentFields}
77
- `;
78
-
79
- const SUB_COMPONENT_REMOVED = gql`
80
- subscription OnComponentRemoved {
81
- componentRemoved {
82
- componentIds {
83
- ...componentIdFields
84
- }
85
- }
86
- }
87
- ${componentIdFields}
88
- `;
89
-
90
- /** provides data to component ui page, making sure both variables and return value are safely typed and memoized */
91
- export function useComponentQuery(componentId: string, host: string) {
92
- const idRef = useRef(componentId);
93
- idRef.current = componentId;
94
- const { data, error, loading, subscribeToMore } = useDataQuery(GET_COMPONENT, {
95
- variables: { id: componentId, extensionId: host },
96
- });
97
-
98
- useEffect(() => {
99
- // @TODO @Kutner fix subscription for scope
100
- if (host !== 'teambit.workspace/workspace') {
101
- return () => {};
102
- }
103
-
104
- const unsubAddition = subscribeToMore({
105
- document: SUB_SUBSCRIPTION_ADDED,
106
- updateQuery: (prev, { subscriptionData }) => {
107
- const prevComponent = prev?.getHost?.get;
108
- const addedComponent = subscriptionData?.data?.componentAdded?.component;
109
-
110
- if (!addedComponent || prevComponent) return prev;
111
-
112
- if (idRef.current === addedComponent.id.name) {
113
- return {
114
- ...prev,
115
- getHost: {
116
- ...prev.getHost,
117
- get: addedComponent,
118
- },
119
- };
120
- }
121
-
122
- return prev;
123
- },
124
- });
125
-
126
- const unsubChanges = subscribeToMore({
127
- document: SUB_COMPONENT_CHANGED,
128
- updateQuery: (prev, { subscriptionData }) => {
129
- if (!subscriptionData.data) return prev;
130
-
131
- const prevComponent = prev?.getHost?.get;
132
- const updatedComponent = subscriptionData?.data?.componentChanged?.component;
133
-
134
- const isUpdated = updatedComponent && ComponentID.isEqualObj(prevComponent?.id, updatedComponent?.id);
135
-
136
- if (isUpdated) {
137
- return {
138
- ...prev,
139
- getHost: {
140
- ...prev.getHost,
141
- get: updatedComponent,
142
- },
143
- };
144
- }
145
-
146
- return prev;
147
- },
148
- });
149
-
150
- const unsubRemoval = subscribeToMore({
151
- document: SUB_COMPONENT_REMOVED,
152
- updateQuery: (prev, { subscriptionData }) => {
153
- if (!subscriptionData.data) return prev;
154
-
155
- const prevComponent = prev?.getHost?.get;
156
- const removedIds: ComponentIdObj[] | undefined = subscriptionData?.data?.componentRemoved?.componentIds;
157
- if (!prevComponent || !removedIds?.length) return prev;
158
-
159
- const isRemoved = removedIds.some((removedId) => ComponentID.isEqualObj(removedId, prevComponent.id));
160
-
161
- if (isRemoved) {
162
- return {
163
- ...prev,
164
- getHost: {
165
- ...prev.getHost,
166
- get: null,
167
- },
168
- };
169
- }
170
-
171
- return prev;
172
- },
173
- });
174
-
175
- return () => {
176
- unsubChanges();
177
- unsubAddition();
178
- unsubRemoval();
179
- };
180
- }, []);
181
-
182
- const rawComponent = data?.getHost?.get;
183
-
184
- return useMemo(() => {
185
- return {
186
- component: rawComponent ? ComponentModel.from({ ...rawComponent, host }) : undefined,
187
- // eslint-disable-next-line
188
- error: error
189
- ? new ComponentError(500, error.message)
190
- : !rawComponent && !loading
191
- ? new ComponentError(404)
192
- : undefined,
193
- };
194
- }, [rawComponent, host, error]);
195
- }
@@ -1,34 +0,0 @@
1
- import { useRouteMatch } from 'react-router-dom';
2
- import { ComponentID } from '@teambit/component-id';
3
- import { useQuery } from '@teambit/ui-foundation.ui.react-router.use-query';
4
- import { ComponentModel } from './component-model';
5
- import { ComponentError } from './component-error';
6
- import { useComponentQuery } from './use-component-query';
7
-
8
- export type Component = {
9
- component?: ComponentModel;
10
- error?: ComponentError;
11
- };
12
-
13
- type ComponentRoute = {
14
- componentId?: string;
15
- };
16
-
17
- export function useComponent(host: string, id?: ComponentID): Component {
18
- const {
19
- params: { componentId },
20
- } = useRouteMatch<ComponentRoute>();
21
- const query = useQuery();
22
- const version = query.get('version') || undefined;
23
-
24
- const targetId = id?.toString({ ignoreVersion: true }) || componentId;
25
- if (!targetId) throw new TypeError('useComponent received no component id');
26
-
27
- return useComponentQuery(withVersion(targetId, version), host);
28
- }
29
-
30
- function withVersion(id: string, version?: string) {
31
- if (!version) return id;
32
- if (id.includes('@')) return id;
33
- return `${id}@${version}`;
34
- }