@teambit/component 0.0.555 → 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 (77) hide show
  1. package/package.json +40 -34
  2. package/aspect-entry.ts +0 -67
  3. package/aspect-list.ts +0 -100
  4. package/aspect.section.tsx +0 -16
  5. package/component-factory.ts +0 -106
  6. package/component-fs.ts +0 -60
  7. package/component-map/component-map.ts +0 -106
  8. package/component-map/index.ts +0 -1
  9. package/component-meta.ts +0 -29
  10. package/component.aspect.ts +0 -9
  11. package/component.docs.mdx +0 -8
  12. package/component.graphql.ts +0 -202
  13. package/component.main.runtime.ts +0 -162
  14. package/component.route.ts +0 -26
  15. package/component.ts +0 -278
  16. package/component.ui.runtime.tsx +0 -216
  17. package/config.ts +0 -34
  18. package/dependencies/dependencies.ts +0 -74
  19. package/dependencies/index.ts +0 -1
  20. package/exceptions/could-not-find-latest.ts +0 -8
  21. package/exceptions/host-not-found.ts +0 -14
  22. package/exceptions/index.ts +0 -4
  23. package/exceptions/nothing-to-snap.ts +0 -1
  24. package/hash.ts +0 -4
  25. package/head.ts +0 -0
  26. package/history-graph.ts +0 -1
  27. package/host/component-host-model.ts +0 -9
  28. package/host/index.ts +0 -2
  29. package/host/use-component-host.ts +0 -39
  30. package/index.ts +0 -32
  31. package/on-load.ts +0 -0
  32. package/package-tar/teambit-component-0.0.555.tgz +0 -0
  33. package/section/index.ts +0 -1
  34. package/section/section.tsx +0 -8
  35. package/show/extensions.fragment.ts +0 -23
  36. package/show/files.fragment.ts +0 -24
  37. package/show/id.fragment.ts +0 -20
  38. package/show/index.ts +0 -8
  39. package/show/main-file.fragment.ts +0 -13
  40. package/show/name.fragment.ts +0 -13
  41. package/show/scope.fragment.ts +0 -15
  42. package/show/show-fragment.ts +0 -44
  43. package/show/show.cmd.ts +0 -85
  44. package/snap/author.ts +0 -19
  45. package/snap/index.ts +0 -2
  46. package/snap/snap.ts +0 -63
  47. package/state.ts +0 -73
  48. package/store.ts +0 -3
  49. package/tag/index.ts +0 -1
  50. package/tag/tag.ts +0 -37
  51. package/tag-map.ts +0 -87
  52. package/tsconfig.json +0 -34
  53. package/types/asset.d.ts +0 -29
  54. package/types/style.d.ts +0 -42
  55. package/ui/aspect-page/aspect-page.module.scss +0 -20
  56. package/ui/aspect-page/aspect-page.tsx +0 -64
  57. package/ui/aspect-page/index.ts +0 -1
  58. package/ui/component-error/component-error.tsx +0 -22
  59. package/ui/component-error/index.ts +0 -1
  60. package/ui/component-model/component-model.ts +0 -169
  61. package/ui/component-model/index.ts +0 -1
  62. package/ui/component.module.scss +0 -7
  63. package/ui/component.tsx +0 -48
  64. package/ui/context/component-context.ts +0 -5
  65. package/ui/context/component-provider.tsx +0 -20
  66. package/ui/context/index.ts +0 -2
  67. package/ui/index.ts +0 -3
  68. package/ui/menu/index.ts +0 -2
  69. package/ui/menu/menu-nav.tsx +0 -37
  70. package/ui/menu/menu.module.scss +0 -62
  71. package/ui/menu/menu.tsx +0 -94
  72. package/ui/menu/nav-plugin.tsx +0 -9
  73. package/ui/top-bar-nav/index.ts +0 -1
  74. package/ui/top-bar-nav/top-bar-nav.module.scss +0 -52
  75. package/ui/top-bar-nav/top-bar-nav.tsx +0 -26
  76. package/ui/use-component-query.ts +0 -195
  77. package/ui/use-component.tsx +0 -34
@@ -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
- }