@teambit/component 0.0.649 → 0.0.653
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/{__preview-1644981953366.js → __preview-1645393132004.js} +1 -1
- package/dist/aspect-list.d.ts +1 -0
- package/dist/aspect-list.js +9 -1
- package/dist/aspect-list.js.map +1 -1
- package/dist/component-factory.d.ts +1 -1
- package/dist/component.graphql.d.ts +3 -1
- package/dist/component.graphql.js +5 -4
- package/dist/component.graphql.js.map +1 -1
- package/dist/ui/use-component-query.d.ts +2 -0
- package/dist/ui/use-component-query.js +30 -0
- package/dist/ui/use-component-query.js.map +1 -1
- package/dist/ui/use-component.d.ts +2 -0
- package/dist/ui/use-component.js.map +1 -1
- package/package-tar/teambit-component-0.0.653.tgz +0 -0
- package/package.json +32 -31
- package/ui/use-component-query.ts +11 -1
- package/ui/use-component.tsx +2 -1
- package/package-tar/teambit-component-0.0.649.tgz +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component@0.0.
|
|
1
|
+
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component@0.0.653/dist/component.docs.mdx')]
|
package/dist/aspect-list.d.ts
CHANGED
package/dist/aspect-list.js
CHANGED
|
@@ -117,7 +117,7 @@ class AspectList {
|
|
|
117
117
|
const res = {};
|
|
118
118
|
this.entries.forEach(entry => {
|
|
119
119
|
if (entry.config) {
|
|
120
|
-
res[entry.id.toString()] = entry.config;
|
|
120
|
+
res[entry.id.toString()] = (0, _extensionData().removeInternalConfigFields)(entry.config);
|
|
121
121
|
}
|
|
122
122
|
});
|
|
123
123
|
return res;
|
|
@@ -128,6 +128,14 @@ class AspectList {
|
|
|
128
128
|
return serializedEntries;
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
filter(ids) {
|
|
132
|
+
if (!(ids !== null && ids !== void 0 && ids.length)) return new AspectList(this.entries);
|
|
133
|
+
const entries = this.entries.filter(aspectEntry => {
|
|
134
|
+
return ids === null || ids === void 0 ? void 0 : ids.includes(aspectEntry.id.toStringWithoutVersion());
|
|
135
|
+
});
|
|
136
|
+
return new AspectList(entries);
|
|
137
|
+
}
|
|
138
|
+
|
|
131
139
|
toLegacy() {
|
|
132
140
|
const legacyEntries = this.entries.map(entry => entry.legacy);
|
|
133
141
|
return _extensionData().ExtensionDataList.fromArray(legacyEntries);
|
package/dist/aspect-list.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["aspect-list.ts"],"names":["AspectList","constructor","entries","addEntry","aspectId","data","extensionDataEntry","ExtensionDataEntry","undefined","_legacy","entry","AspectEntry","push","withoutEntries","aspectIds","filter","includes","legacy","stringId","ids","list","map","id","toString","get","find","toStringWithoutVersion","ignoreVersion","aspectEntry","isEqual","predicate","pmap","entriesP","Promise","all","toConfigObject","res","forEach","config","serialize","serializedEntries","toLegacy","legacyEntries","ExtensionDataList","fromArray","stringIds","fromLegacyExtensions","legacyDataList","scope","newEntries","getAspectId","extensionId","name","ComponentID","fromString","fromLegacy","Error"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;
|
|
1
|
+
{"version":3,"sources":["aspect-list.ts"],"names":["AspectList","constructor","entries","addEntry","aspectId","data","extensionDataEntry","ExtensionDataEntry","undefined","_legacy","entry","AspectEntry","push","withoutEntries","aspectIds","filter","includes","legacy","stringId","ids","list","map","id","toString","get","find","toStringWithoutVersion","ignoreVersion","aspectEntry","isEqual","predicate","pmap","entriesP","Promise","all","toConfigObject","res","forEach","config","serialize","serializedEntries","length","toLegacy","legacyEntries","ExtensionDataList","fromArray","stringIds","fromLegacyExtensions","legacyDataList","scope","newEntries","getAspectId","extensionId","name","ComponentID","fromString","fromLegacy","Error"],"mappings":";;;;;;;;;;;AAAA;AA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1C,KAAK,CAAC2C,IAAhC,EAAsC,OAAOC,2BAAYC,UAAZ,CAAuB7C,KAAK,CAAC2C,IAA7B,CAAP;AACtC,MAAI3C,KAAK,CAAC0C,WAAV,EAAuB,OAAOE,2BAAYE,UAAZ,CAAuB9C,KAAK,CAAC0C,WAA7B,EAA0CH,KAA1C,CAAP;AACvB,QAAM,IAAIQ,KAAJ,CAAU,+CAAV,CAAN;AACD","sourcesContent":["import {\n ExtensionDataList,\n ExtensionDataEntry,\n removeInternalConfigFields,\n} from '@teambit/legacy/dist/consumer/config/extension-data';\nimport { ComponentID } from '@teambit/component-id';\nimport { AspectEntry, SerializableMap } from './aspect-entry';\n\n/**\n * list of aspects, each may have data and artifacts saved per component.\n */\nexport class AspectList {\n constructor(readonly entries: AspectEntry[]) {}\n\n addEntry(aspectId: ComponentID, data: SerializableMap = {}) {\n const extensionDataEntry = new ExtensionDataEntry(undefined, aspectId._legacy, undefined, {}, data);\n const entry = new AspectEntry(aspectId, extensionDataEntry);\n this.entries.push(entry);\n return entry;\n }\n\n /**\n * transform an aspect list into a new one without the given aspect ids\n */\n withoutEntries(aspectIds: string[]): AspectList {\n const entries = this.entries.filter((entry) => !aspectIds.includes(entry.legacy.stringId));\n return new AspectList(entries);\n }\n\n /**\n * get all ids as strings from the aspect list.\n */\n get ids(): string[] {\n const list = this.entries.map((entry) => entry.id.toString());\n return list;\n }\n\n /**\n * get an aspect from the list using a serialized ID.\n */\n get(id: string): AspectEntry | undefined {\n return this.entries.find((entry) => {\n return entry.legacy.stringId === id || entry.id.toStringWithoutVersion() === id;\n });\n }\n\n /**\n * find aspect by component ID.\n */\n find(id: ComponentID, ignoreVersion = false): AspectEntry | undefined {\n return this.entries.find((aspectEntry) => {\n return id.isEqual(aspectEntry.id, { ignoreVersion });\n });\n }\n\n /**\n * transform an aspect list into a new one.\n */\n map(predicate: (entry: AspectEntry) => AspectEntry) {\n const entries = this.entries.map(predicate);\n return new AspectList(entries);\n }\n\n /**\n * transform an aspect list into a new one.\n */\n async pmap(predicate: (entry: AspectEntry) => Promise<AspectEntry>) {\n const entriesP = this.entries.map(predicate);\n const entries = await Promise.all(entriesP);\n return new AspectList(entries);\n }\n\n toConfigObject() {\n const res = {};\n this.entries.forEach((entry) => {\n if (entry.config) {\n res[entry.id.toString()] = removeInternalConfigFields(entry.config);\n }\n });\n return res;\n }\n\n serialize() {\n const serializedEntries = this.entries.map((entry) => entry.serialize());\n return serializedEntries;\n }\n\n filter(ids?: string[]): AspectList {\n if (!ids?.length) return new AspectList(this.entries);\n const entries = this.entries.filter((aspectEntry) => {\n return ids?.includes(aspectEntry.id.toStringWithoutVersion());\n });\n return new AspectList(entries);\n }\n\n toLegacy(): ExtensionDataList {\n const legacyEntries = this.entries.map((entry) => entry.legacy);\n return ExtensionDataList.fromArray(legacyEntries);\n }\n\n stringIds(): string[] {\n const ids = this.entries.map((entry) => entry.id.toString());\n return ids;\n }\n\n static fromLegacyExtensions(legacyDataList: ExtensionDataList, scope?: string): AspectList {\n const newEntries = legacyDataList.map((entry) => {\n return new AspectEntry(getAspectId(entry, scope), entry);\n });\n\n return new AspectList(newEntries);\n }\n}\n\nfunction getAspectId(entry: ExtensionDataEntry, scope?: string) {\n if (!entry.extensionId && entry.name) return ComponentID.fromString(entry.name);\n if (entry.extensionId) return ComponentID.fromLegacy(entry.extensionId, scope);\n throw new Error('aspect cannot be loaded without setting an ID');\n}\n"]}
|
|
@@ -55,7 +55,7 @@ export interface ComponentFactory {
|
|
|
55
55
|
* load aspects.
|
|
56
56
|
* returns the loaded aspect ids including the loaded versions.
|
|
57
57
|
*/
|
|
58
|
-
loadAspects: (ids: string[], throwOnError
|
|
58
|
+
loadAspects: (ids: string[], throwOnError?: boolean, neededFor?: ComponentID) => Promise<string[]>;
|
|
59
59
|
/**
|
|
60
60
|
* Resolve dirs for aspects
|
|
61
61
|
*/
|
|
@@ -16,7 +16,9 @@ export declare function componentSchema(componentExtension: ComponentMain): {
|
|
|
16
16
|
headTag: (component: Component) => import(".").TagProps | undefined;
|
|
17
17
|
latest: (component: Component) => string | undefined;
|
|
18
18
|
tags: (component: any) => any;
|
|
19
|
-
aspects: (component: Component
|
|
19
|
+
aspects: (component: Component, { include }: {
|
|
20
|
+
include?: string[] | undefined;
|
|
21
|
+
}) => {
|
|
20
22
|
id: string;
|
|
21
23
|
config: {
|
|
22
24
|
[key: string]: any;
|
|
@@ -135,7 +135,7 @@ function componentSchema(componentExtension) {
|
|
|
135
135
|
# list of component releases.
|
|
136
136
|
tags: [Tag]!
|
|
137
137
|
|
|
138
|
-
aspects: [Aspect]
|
|
138
|
+
aspects(include: [String]): [Aspect]
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
type Aspect {
|
|
@@ -200,9 +200,10 @@ function componentSchema(componentExtension) {
|
|
|
200
200
|
// graphql doesn't support map types
|
|
201
201
|
return component.tags.toArray().map(tag => tag.toObject());
|
|
202
202
|
},
|
|
203
|
-
aspects: component
|
|
204
|
-
|
|
205
|
-
|
|
203
|
+
aspects: (component, {
|
|
204
|
+
include
|
|
205
|
+
}) => {
|
|
206
|
+
return component.state.aspects.filter(include).serialize();
|
|
206
207
|
}
|
|
207
208
|
},
|
|
208
209
|
ComponentHost: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["component.graphql.ts"],"names":["componentSchema","componentExtension","typeDefs","resolvers","JSONObject","GraphQLJSONObject","Component","id","component","toObject","displayName","fs","state","filesystem","files","map","file","relative","getFile","path","maybeFile","find","undefined","contents","toString","mainFile","_consumer","headTag","latest","tags","toArray","tag","aspects","serialize","ComponentHost","get","host","componentId","resolveComponentId","error","snaps","getLogs","list","
|
|
1
|
+
{"version":3,"sources":["component.graphql.ts"],"names":["componentSchema","componentExtension","typeDefs","resolvers","JSONObject","GraphQLJSONObject","Component","id","component","toObject","displayName","fs","state","filesystem","files","map","file","relative","getFile","path","maybeFile","find","undefined","contents","toString","mainFile","_consumer","headTag","latest","tags","toArray","tag","aspects","include","filter","serialize","ComponentHost","get","host","componentId","resolveComponentId","error","snaps","getLogs","list","listInvalid","invalidComps","err","errorName","name","errorMessage","message","Query","getHost","componentExt"],"mappings":";;;;;;;;;;;AAAA;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;;AAMO,SAASA,eAAT,CAAyBC,kBAAzB,EAA4D;AACjE,SAAO;AACLC,IAAAA,QAAQ,EAAE,0BAAI;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAzHS;AA0HLC,IAAAA,SAAS,EAAE;AACTC,MAAAA,UAAU,EAAEC,oCADH;AAETC,MAAAA,SAAS,EAAE;AACTC,QAAAA,EAAE,EAAGC,SAAD,IAA0BA,SAAS,CAACD,EAAV,CAAaE,QAAb,EADrB;AAETC,QAAAA,WAAW,EAAGF,SAAD,IAA0BA,SAAS,CAACE,WAFxC;AAGTC,QAAAA,EAAE,EAAGH,SAAD,IAA0B;AAC5B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QAAAA,IAAI,EAAE,MAAOX,IAAP,IAAkC;AACtC,iBAAOA,IAAI,CAACW,IAAZ;AACD;AA/BY,OA5BN;AA6DTG,MAAAA,KAAK,EAAE;AACLC,QAAAA,OAAO,EAAE,CAACC,YAAD,EAA8B;AAAE/C,UAAAA;AAAF,SAA9B,KAAyD;AAChE,iBAAON,kBAAkB,CAACoD,OAAnB,CAA2B9C,EAA3B,CAAP;AACD;AAHI;AA7DE;AA1HN,GAAP;AA8LD","sourcesContent":["import stripAnsi from 'strip-ansi';\nimport gql from 'graphql-tag';\nimport { GraphQLJSONObject } from 'graphql-type-json';\nimport { pathNormalizeToLinux } from '@teambit/legacy/dist/utils';\n\nimport { Component } from './component';\nimport { ComponentFactory } from './component-factory';\nimport { ComponentMain } from './component.main.runtime';\n\nexport function componentSchema(componentExtension: ComponentMain) {\n return {\n typeDefs: gql`\n scalar JSON\n scalar JSONObject\n\n type ComponentID {\n name: String!\n version: String\n scope: String\n }\n\n type Tag {\n # semver assigned to the tag.\n version: String!\n\n # tag hash.\n hash: String!\n }\n\n type Snap {\n # hash of the snapshot.\n hash: String!\n\n # time of the snapshot.\n timestamp: String!\n\n # parents of the snap\n parents: [Snap]!\n\n # snapper\n author: Author!\n\n # snapshot message\n message: String\n }\n\n type LogEntry {\n message: String!\n username: String\n email: String\n date: String\n hash: String!\n tag: String\n # id: String!\n }\n\n type Author {\n # display name of the snapper.\n displayName: String!\n\n # author of the snapper.\n email: String!\n }\n\n type Component {\n # id of the component.\n id: ComponentID!\n\n # head snap of the component.\n head: Snap\n\n # head tag of the component.\n headTag: Tag\n\n # list of all relative component paths.\n fs: [String]\n\n # relative path to the main file of the component\n mainFile: String\n\n # return specific file contents by relative file path.\n getFile(path: String): String\n\n # latest version of the component.\n latest: String\n\n # display name of the component\n displayName: String!\n\n # component buildStatus\n buildStatus: String\n\n # list of component releases.\n tags: [Tag]!\n\n aspects(include: [String]): [Aspect]\n }\n\n type Aspect {\n id: String!\n icon: String\n config: JSONObject\n data: JSONObject\n }\n\n type InvalidComponent {\n id: ComponentID!\n errorName: String!\n errorMessage: String!\n }\n\n type ComponentHost {\n id: ID!\n name: String!\n\n # load a component.\n get(id: String!, withState: Boolean): Component\n\n # list components\n list(offset: Int, limit: Int): [Component]!\n\n # list invalid components and their errors\n listInvalid: [InvalidComponent]!\n\n # get component logs(snaps) by component id\n snaps(id: String!): [LogEntry]!\n }\n\n type Query {\n getHost(id: String): ComponentHost\n }\n `,\n resolvers: {\n JSONObject: GraphQLJSONObject,\n Component: {\n id: (component: Component) => component.id.toObject(),\n displayName: (component: Component) => component.displayName,\n fs: (component: Component) => {\n return component.state.filesystem.files.map((file) => file.relative);\n },\n getFile: (component: Component, { path }: { path: string }) => {\n const maybeFile = component.state.filesystem.files.find(\n (file) => pathNormalizeToLinux(file.relative) === path\n );\n if (!maybeFile) return undefined;\n return maybeFile.contents.toString('utf-8');\n },\n mainFile: (component: Component) => {\n return component.state._consumer.mainFile;\n },\n headTag: (component: Component) => component.headTag?.toObject(),\n latest: (component: Component) => component.latest,\n tags: (component) => {\n // graphql doesn't support map types\n return component.tags.toArray().map((tag) => tag.toObject());\n },\n aspects: (component: Component, { include }: { include?: string[] }) => {\n return component.state.aspects.filter(include).serialize();\n },\n },\n ComponentHost: {\n get: async (host: ComponentFactory, { id }: { id: string }) => {\n try {\n const componentId = await host.resolveComponentId(id);\n const component = await host.get(componentId);\n return component;\n } catch (error: any) {\n return null;\n }\n },\n snaps: async (host: ComponentFactory, { id }: { id: string }) => {\n const componentId = await host.resolveComponentId(id);\n // return (await host.getLogs(componentId)).map(log => ({...log, id: log.hash}))\n return host.getLogs(componentId);\n },\n list: async (host: ComponentFactory, filter?: { offset: number; limit: number }) => {\n return host.list(filter);\n },\n listInvalid: async (host: ComponentFactory) => {\n const invalidComps = await host.listInvalid();\n return invalidComps.map(({ id, err }) => ({\n id,\n errorName: err.name,\n errorMessage: err.message ? stripAnsi(err.message) : err.name,\n }));\n },\n id: async (host: ComponentFactory) => {\n return host.name;\n },\n name: async (host: ComponentFactory) => {\n return host.name;\n },\n },\n Query: {\n getHost: (componentExt: ComponentMain, { id }: { id: string }) => {\n return componentExtension.getHost(id);\n },\n },\n },\n };\n}\n"]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { ComponentDescriptor } from '@teambit/component-descriptor';
|
|
1
2
|
import { ComponentModel } from './component-model';
|
|
2
3
|
import { ComponentError } from './component-error';
|
|
3
4
|
/** provides data to component ui page, making sure both variables and return value are safely typed and memoized */
|
|
4
5
|
export declare function useComponentQuery(componentId: string, host: string): {
|
|
6
|
+
componentDescriptor: ComponentDescriptor | undefined;
|
|
5
7
|
component: ComponentModel | undefined;
|
|
6
8
|
error: ComponentError | undefined;
|
|
7
9
|
};
|
|
@@ -57,6 +57,16 @@ function _componentId() {
|
|
|
57
57
|
return data;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
function _componentDescriptor() {
|
|
61
|
+
const data = require("@teambit/component-descriptor");
|
|
62
|
+
|
|
63
|
+
_componentDescriptor = function () {
|
|
64
|
+
return data;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return data;
|
|
68
|
+
}
|
|
69
|
+
|
|
60
70
|
function _componentModel() {
|
|
61
71
|
const data = require("./component-model");
|
|
62
72
|
|
|
@@ -93,6 +103,10 @@ const componentFields = (0, _client().gql)`
|
|
|
93
103
|
id {
|
|
94
104
|
...componentIdFields
|
|
95
105
|
}
|
|
106
|
+
aspects(include: ["teambit.preview/preview"]) {
|
|
107
|
+
id
|
|
108
|
+
data
|
|
109
|
+
}
|
|
96
110
|
packageName
|
|
97
111
|
elementsUrl
|
|
98
112
|
description
|
|
@@ -115,6 +129,7 @@ const componentFields = (0, _client().gql)`
|
|
|
115
129
|
id
|
|
116
130
|
icon
|
|
117
131
|
}
|
|
132
|
+
|
|
118
133
|
preview {
|
|
119
134
|
includesEnvTemplate
|
|
120
135
|
}
|
|
@@ -264,7 +279,22 @@ function useComponentQuery(componentId, host) {
|
|
|
264
279
|
}, []);
|
|
265
280
|
const rawComponent = data === null || data === void 0 ? void 0 : (_data$getHost = data.getHost) === null || _data$getHost === void 0 ? void 0 : _data$getHost.get;
|
|
266
281
|
return (0, _react().useMemo)(() => {
|
|
282
|
+
var _rawComponent$aspects;
|
|
283
|
+
|
|
284
|
+
const aspectList = {
|
|
285
|
+
entries: rawComponent === null || rawComponent === void 0 ? void 0 : (_rawComponent$aspects = rawComponent.aspects) === null || _rawComponent$aspects === void 0 ? void 0 : _rawComponent$aspects.map(aspect => ({
|
|
286
|
+
aspectId: aspect.id,
|
|
287
|
+
aspectData: aspect.data
|
|
288
|
+
}))
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const id = rawComponent && _componentId().ComponentID.fromObject(rawComponent.id);
|
|
292
|
+
|
|
267
293
|
return {
|
|
294
|
+
componentDescriptor: id ? _componentDescriptor().ComponentDescriptor.fromObject({
|
|
295
|
+
id: id.toString(),
|
|
296
|
+
aspectList
|
|
297
|
+
}) : undefined,
|
|
268
298
|
component: rawComponent ? _componentModel().ComponentModel.from(_objectSpread(_objectSpread({}, rawComponent), {}, {
|
|
269
299
|
host
|
|
270
300
|
})) : undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["use-component-query.ts"],"names":["componentIdFields","componentFields","GET_COMPONENT","SUB_SUBSCRIPTION_ADDED","SUB_COMPONENT_CHANGED","SUB_COMPONENT_REMOVED","useComponentQuery","componentId","host","idRef","current","data","error","loading","subscribeToMore","variables","id","extensionId","unsubAddition","document","updateQuery","prev","subscriptionData","prevComponent","getHost","get","addedComponent","componentAdded","component","name","unsubChanges","updatedComponent","componentChanged","isUpdated","ComponentID","isEqualObj","unsubRemoval","removedIds","componentRemoved","componentIds","length","isRemoved","some","removedId","rawComponent","ComponentModel","from","undefined","ComponentError","message"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;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,CAACG,OADH;AAELC,cAAAA,GAAG,EAAE;AAFA;AAFT;AAOD;;AAED,eAAOJ,IAAP;AACD;AAtBkC,KAAD,CAApC;AAyBA,WAAO,MAAM;AACXS,MAAAA,YAAY;AACZZ,MAAAA,aAAa;AACbkB,MAAAA,YAAY;AACb,KAJD;AAKD,GAlFD,EAkFG,EAlFH;AAoFA,QAAMQ,YAAY,GAAGjC,IAAH,aAAGA,IAAH,wCAAGA,IAAI,CAAEa,OAAT,kDAAG,cAAeC,GAApC;AAEA,SAAO,sBAAQ,MAAM;AACnB,WAAO;AACLG,MAAAA,SAAS,EAAEgB,YAAY,GAAGC,iCAAeC,IAAf,iCAAyBF,YAAzB;AAAuCpC,QAAAA;AAAvC,SAAH,GAAoDuC,SADtE;AAEL;AACAnC,MAAAA,KAAK,EAAEA,KAAK,GACR,KAAIoC,gCAAJ,EAAmB,GAAnB,EAAwBpC,KAAK,CAACqC,OAA9B,CADQ,GAER,CAACL,YAAD,IAAiB,CAAC/B,OAAlB,GACA,KAAImC,gCAAJ,EAAmB,GAAnB,CADA,GAEAD;AAPC,KAAP;AASD,GAVM,EAUJ,CAACH,YAAD,EAAepC,IAAf,EAAqBI,KAArB,CAVI,CAAP;AAWD","sourcesContent":["import { useMemo, useEffect, useRef } from 'react';\nimport { gql } from '@apollo/client';\nimport { useDataQuery } from '@teambit/ui-foundation.ui.hooks.use-data-query';\nimport { ComponentID, ComponentIdObj } from '@teambit/component-id';\n\nimport { ComponentModel } from './component-model';\nimport { ComponentError } from './component-error';\n\nconst componentIdFields = gql`\n fragment componentIdFields on ComponentID {\n name\n version\n scope\n }\n`;\n\nconst componentFields = gql`\n fragment componentFields on Component {\n id {\n ...componentIdFields\n }\n packageName\n elementsUrl\n description\n labels\n displayName\n latest\n server {\n env\n url\n }\n buildStatus\n compositions {\n identifier\n displayName\n }\n tags {\n version\n }\n env {\n id\n icon\n }\n preview {\n includesEnvTemplate\n }\n }\n ${componentIdFields}\n`;\n\nconst GET_COMPONENT = gql`\n query Component($id: String!, $extensionId: String!) {\n getHost(id: $extensionId) {\n id # used for GQL caching\n get(id: $id) {\n ...componentFields\n }\n }\n }\n ${componentFields}\n`;\n\nconst SUB_SUBSCRIPTION_ADDED = gql`\n subscription OnComponentAdded {\n componentAdded {\n component {\n ...componentFields\n }\n }\n }\n ${componentFields}\n`;\n\nconst SUB_COMPONENT_CHANGED = gql`\n subscription OnComponentChanged {\n componentChanged {\n component {\n ...componentFields\n }\n }\n }\n ${componentFields}\n`;\n\nconst SUB_COMPONENT_REMOVED = gql`\n subscription OnComponentRemoved {\n componentRemoved {\n componentIds {\n ...componentIdFields\n }\n }\n }\n ${componentIdFields}\n`;\n\n/** provides data to component ui page, making sure both variables and return value are safely typed and memoized */\nexport function useComponentQuery(componentId: string, host: string) {\n const idRef = useRef(componentId);\n idRef.current = componentId;\n const { data, error, loading, subscribeToMore } = useDataQuery(GET_COMPONENT, {\n variables: { id: componentId, extensionId: host },\n });\n\n useEffect(() => {\n // @TODO @Kutner fix subscription for scope\n if (host !== 'teambit.workspace/workspace') {\n return () => {};\n }\n\n const unsubAddition = subscribeToMore({\n document: SUB_SUBSCRIPTION_ADDED,\n updateQuery: (prev, { subscriptionData }) => {\n const prevComponent = prev?.getHost?.get;\n const addedComponent = subscriptionData?.data?.componentAdded?.component;\n\n if (!addedComponent || prevComponent) return prev;\n\n if (idRef.current === addedComponent.id.name) {\n return {\n ...prev,\n getHost: {\n ...prev.getHost,\n get: addedComponent,\n },\n };\n }\n\n return prev;\n },\n });\n\n const unsubChanges = subscribeToMore({\n document: SUB_COMPONENT_CHANGED,\n updateQuery: (prev, { subscriptionData }) => {\n if (!subscriptionData.data) return prev;\n\n const prevComponent = prev?.getHost?.get;\n const updatedComponent = subscriptionData?.data?.componentChanged?.component;\n\n const isUpdated = updatedComponent && ComponentID.isEqualObj(prevComponent?.id, updatedComponent?.id);\n\n if (isUpdated) {\n return {\n ...prev,\n getHost: {\n ...prev.getHost,\n get: updatedComponent,\n },\n };\n }\n\n return prev;\n },\n });\n\n const unsubRemoval = subscribeToMore({\n document: SUB_COMPONENT_REMOVED,\n updateQuery: (prev, { subscriptionData }) => {\n if (!subscriptionData.data) return prev;\n\n const prevComponent = prev?.getHost?.get;\n const removedIds: ComponentIdObj[] | undefined = subscriptionData?.data?.componentRemoved?.componentIds;\n if (!prevComponent || !removedIds?.length) return prev;\n\n const isRemoved = removedIds.some((removedId) => ComponentID.isEqualObj(removedId, prevComponent.id));\n\n if (isRemoved) {\n return {\n ...prev,\n getHost: {\n ...prev.getHost,\n get: null,\n },\n };\n }\n\n return prev;\n },\n });\n\n return () => {\n unsubChanges();\n unsubAddition();\n unsubRemoval();\n };\n }, []);\n\n const rawComponent = data?.getHost?.get;\n\n return useMemo(() => {\n return {\n component: rawComponent ? ComponentModel.from({ ...rawComponent, host }) : undefined,\n // eslint-disable-next-line\n error: error\n ? new ComponentError(500, error.message)\n : !rawComponent && !loading\n ? new ComponentError(404)\n : undefined,\n };\n }, [rawComponent, host, error]);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["use-component-query.ts"],"names":["componentIdFields","componentFields","GET_COMPONENT","SUB_SUBSCRIPTION_ADDED","SUB_COMPONENT_CHANGED","SUB_COMPONENT_REMOVED","useComponentQuery","componentId","host","idRef","current","data","error","loading","subscribeToMore","variables","id","extensionId","unsubAddition","document","updateQuery","prev","subscriptionData","prevComponent","getHost","get","addedComponent","componentAdded","component","name","unsubChanges","updatedComponent","componentChanged","isUpdated","ComponentID","isEqualObj","unsubRemoval","removedIds","componentRemoved","componentIds","length","isRemoved","some","removedId","rawComponent","aspectList","entries","aspects","map","aspect","aspectId","aspectData","fromObject","componentDescriptor","ComponentDescriptor","toString","undefined","ComponentModel","from","ComponentError","message"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;A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C,KAAP;AAUD,GAfM,EAeJ,CAACZ,YAAD,EAAepC,IAAf,EAAqBI,KAArB,CAfI,CAAP;AAgBD","sourcesContent":["import { useMemo, useEffect, useRef } from 'react';\nimport { gql } from '@apollo/client';\nimport { useDataQuery } from '@teambit/ui-foundation.ui.hooks.use-data-query';\nimport { ComponentID, ComponentIdObj } from '@teambit/component-id';\nimport { ComponentDescriptor } from '@teambit/component-descriptor';\n\nimport { ComponentModel } from './component-model';\nimport { ComponentError } from './component-error';\n\nconst componentIdFields = gql`\n fragment componentIdFields on ComponentID {\n name\n version\n scope\n }\n`;\n\nconst componentFields = gql`\n fragment componentFields on Component {\n id {\n ...componentIdFields\n }\n aspects(include: [\"teambit.preview/preview\"]) {\n id\n data\n }\n packageName\n elementsUrl\n description\n labels\n displayName\n latest\n server {\n env\n url\n }\n buildStatus\n compositions {\n identifier\n displayName\n }\n tags {\n version\n }\n env {\n id\n icon\n }\n\n preview {\n includesEnvTemplate\n }\n }\n ${componentIdFields}\n`;\n\nconst GET_COMPONENT = gql`\n query Component($id: String!, $extensionId: String!) {\n getHost(id: $extensionId) {\n id # used for GQL caching\n get(id: $id) {\n ...componentFields\n }\n }\n }\n ${componentFields}\n`;\n\nconst SUB_SUBSCRIPTION_ADDED = gql`\n subscription OnComponentAdded {\n componentAdded {\n component {\n ...componentFields\n }\n }\n }\n ${componentFields}\n`;\n\nconst SUB_COMPONENT_CHANGED = gql`\n subscription OnComponentChanged {\n componentChanged {\n component {\n ...componentFields\n }\n }\n }\n ${componentFields}\n`;\n\nconst SUB_COMPONENT_REMOVED = gql`\n subscription OnComponentRemoved {\n componentRemoved {\n componentIds {\n ...componentIdFields\n }\n }\n }\n ${componentIdFields}\n`;\n\n/** provides data to component ui page, making sure both variables and return value are safely typed and memoized */\nexport function useComponentQuery(componentId: string, host: string) {\n const idRef = useRef(componentId);\n idRef.current = componentId;\n const { data, error, loading, subscribeToMore } = useDataQuery(GET_COMPONENT, {\n variables: { id: componentId, extensionId: host },\n });\n\n useEffect(() => {\n // @TODO @Kutner fix subscription for scope\n if (host !== 'teambit.workspace/workspace') {\n return () => {};\n }\n\n const unsubAddition = subscribeToMore({\n document: SUB_SUBSCRIPTION_ADDED,\n updateQuery: (prev, { subscriptionData }) => {\n const prevComponent = prev?.getHost?.get;\n const addedComponent = subscriptionData?.data?.componentAdded?.component;\n\n if (!addedComponent || prevComponent) return prev;\n\n if (idRef.current === addedComponent.id.name) {\n return {\n ...prev,\n getHost: {\n ...prev.getHost,\n get: addedComponent,\n },\n };\n }\n\n return prev;\n },\n });\n\n const unsubChanges = subscribeToMore({\n document: SUB_COMPONENT_CHANGED,\n updateQuery: (prev, { subscriptionData }) => {\n if (!subscriptionData.data) return prev;\n\n const prevComponent = prev?.getHost?.get;\n const updatedComponent = subscriptionData?.data?.componentChanged?.component;\n\n const isUpdated = updatedComponent && ComponentID.isEqualObj(prevComponent?.id, updatedComponent?.id);\n\n if (isUpdated) {\n return {\n ...prev,\n getHost: {\n ...prev.getHost,\n get: updatedComponent,\n },\n };\n }\n\n return prev;\n },\n });\n\n const unsubRemoval = subscribeToMore({\n document: SUB_COMPONENT_REMOVED,\n updateQuery: (prev, { subscriptionData }) => {\n if (!subscriptionData.data) return prev;\n\n const prevComponent = prev?.getHost?.get;\n const removedIds: ComponentIdObj[] | undefined = subscriptionData?.data?.componentRemoved?.componentIds;\n if (!prevComponent || !removedIds?.length) return prev;\n\n const isRemoved = removedIds.some((removedId) => ComponentID.isEqualObj(removedId, prevComponent.id));\n\n if (isRemoved) {\n return {\n ...prev,\n getHost: {\n ...prev.getHost,\n get: null,\n },\n };\n }\n\n return prev;\n },\n });\n\n return () => {\n unsubChanges();\n unsubAddition();\n unsubRemoval();\n };\n }, []);\n\n const rawComponent = data?.getHost?.get;\n return useMemo(() => {\n const aspectList = {\n entries: rawComponent?.aspects?.map((aspect) => ({ aspectId: aspect.id, aspectData: aspect.data })),\n };\n const id = rawComponent && ComponentID.fromObject(rawComponent.id);\n return {\n componentDescriptor: id ? ComponentDescriptor.fromObject({ id: id.toString(), aspectList }) : undefined,\n component: rawComponent ? ComponentModel.from({ ...rawComponent, host }) : undefined,\n // eslint-disable-next-line\n error: error\n ? new ComponentError(500, error.message)\n : !rawComponent && !loading\n ? new ComponentError(404)\n : undefined,\n };\n }, [rawComponent, host, error]);\n}\n"]}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ComponentID } from '@teambit/component-id';
|
|
2
|
+
import { ComponentDescriptor } from '@teambit/component-descriptor';
|
|
2
3
|
import { ComponentModel } from './component-model';
|
|
3
4
|
import { ComponentError } from './component-error';
|
|
4
5
|
export declare type Component = {
|
|
5
6
|
component?: ComponentModel;
|
|
6
7
|
error?: ComponentError;
|
|
8
|
+
componentDescriptor?: ComponentDescriptor;
|
|
7
9
|
};
|
|
8
10
|
export declare function useComponent(host: string, id?: ComponentID): Component;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["use-component.tsx"],"names":["useComponent","host","id","params","componentId","query","version","get","undefined","targetId","toString","ignoreVersion","TypeError","withVersion","includes"],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;
|
|
1
|
+
{"version":3,"sources":["use-component.tsx"],"names":["useComponent","host","id","params","componentId","query","version","get","undefined","targetId","toString","ignoreVersion","TypeError","withVersion","includes"],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAYO,SAASA,YAAT,CAAsBC,IAAtB,EAAoCC,EAApC,EAAiE;AACtE,QAAM;AACJC,IAAAA,MAAM,EAAE;AAAEC,MAAAA;AAAF;AADJ,MAEF,sCAFJ;AAGA,QAAMC,KAAK,GAAG,4CAAd;AACA,QAAMC,OAAO,GAAGD,KAAK,CAACE,GAAN,CAAU,SAAV,KAAwBC,SAAxC;AAEA,QAAMC,QAAQ,GAAG,CAAAP,EAAE,SAAF,IAAAA,EAAE,WAAF,YAAAA,EAAE,CAAEQ,QAAJ,CAAa;AAAEC,IAAAA,aAAa,EAAE;AAAjB,GAAb,MAAyCP,WAA1D;AACA,MAAI,CAACK,QAAL,EAAe,MAAM,IAAIG,SAAJ,CAAc,uCAAd,CAAN;AACf,SAAO,4CAAkBC,WAAW,CAACJ,QAAD,EAAWH,OAAX,CAA7B,EAAkDL,IAAlD,CAAP;AACD;;AAED,SAASY,WAAT,CAAqBX,EAArB,EAAiCI,OAAjC,EAAmD;AACjD,MAAI,CAACA,OAAL,EAAc,OAAOJ,EAAP;AACd,MAAIA,EAAE,CAACY,QAAH,CAAY,GAAZ,CAAJ,EAAsB,OAAOZ,EAAP;AACtB,SAAQ,GAAEA,EAAG,IAAGI,OAAQ,EAAxB;AACD","sourcesContent":["import { useRouteMatch } from 'react-router-dom';\nimport { ComponentID } from '@teambit/component-id';\nimport { useQuery } from '@teambit/ui-foundation.ui.react-router.use-query';\nimport { ComponentDescriptor } from '@teambit/component-descriptor';\nimport { ComponentModel } from './component-model';\nimport { ComponentError } from './component-error';\nimport { useComponentQuery } from './use-component-query';\n\nexport type Component = {\n component?: ComponentModel;\n error?: ComponentError;\n componentDescriptor?: ComponentDescriptor;\n};\n\ntype ComponentRoute = {\n componentId?: string;\n};\n\nexport function useComponent(host: string, id?: ComponentID): Component {\n const {\n params: { componentId },\n } = useRouteMatch<ComponentRoute>();\n const query = useQuery();\n const version = query.get('version') || undefined;\n\n const targetId = id?.toString({ ignoreVersion: true }) || componentId;\n if (!targetId) throw new TypeError('useComponent received no component id');\n return useComponentQuery(withVersion(targetId, version), host);\n}\n\nfunction withVersion(id: string, version?: string) {\n if (!version) return id;\n if (id.includes('@')) return id;\n return `${id}@${version}`;\n}\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.653",
|
|
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.653"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@teambit/any-fs": "0.0.5",
|
|
@@ -28,37 +28,38 @@
|
|
|
28
28
|
"@teambit/documenter.ui.separator": "4.1.1",
|
|
29
29
|
"@teambit/base-ui.routing.routing-provider": "1.0.0",
|
|
30
30
|
"@teambit/component-id": "0.0.401",
|
|
31
|
-
"@teambit/ui-foundation.ui.menu-widget-icon": "0.0.
|
|
32
|
-
"@teambit/aspect-loader": "0.0.
|
|
31
|
+
"@teambit/ui-foundation.ui.menu-widget-icon": "0.0.488",
|
|
32
|
+
"@teambit/aspect-loader": "0.0.653",
|
|
33
33
|
"@teambit/legacy-bit-id": "0.0.398",
|
|
34
|
-
"@teambit/toolbox.string.capitalize": "0.0.
|
|
35
|
-
"@teambit/cli": "0.0.
|
|
36
|
-
"@teambit/config": "0.0.
|
|
37
|
-
"@teambit/express": "0.0.
|
|
38
|
-
"@teambit/graphql": "0.0.
|
|
34
|
+
"@teambit/toolbox.string.capitalize": "0.0.483",
|
|
35
|
+
"@teambit/cli": "0.0.445",
|
|
36
|
+
"@teambit/config": "0.0.458",
|
|
37
|
+
"@teambit/express": "0.0.539",
|
|
38
|
+
"@teambit/graphql": "0.0.653",
|
|
39
39
|
"@teambit/bit-error": "0.0.394",
|
|
40
|
-
"@teambit/command-bar": "0.0.
|
|
41
|
-
"@teambit/preview": "0.0.
|
|
42
|
-
"@teambit/pubsub": "0.0.
|
|
43
|
-
"@teambit/ui-foundation.ui.is-browser": "0.0.
|
|
44
|
-
"@teambit/ui-foundation.ui.main-dropdown": "0.0.
|
|
45
|
-
"@teambit/ui-foundation.ui.react-router.slot-router": "0.0.
|
|
46
|
-
"@teambit/ui-foundation.ui.use-box.menu": "0.0.
|
|
47
|
-
"@teambit/ui": "0.0.
|
|
40
|
+
"@teambit/command-bar": "0.0.653",
|
|
41
|
+
"@teambit/preview": "0.0.653",
|
|
42
|
+
"@teambit/pubsub": "0.0.653",
|
|
43
|
+
"@teambit/ui-foundation.ui.is-browser": "0.0.486",
|
|
44
|
+
"@teambit/ui-foundation.ui.main-dropdown": "0.0.486",
|
|
45
|
+
"@teambit/ui-foundation.ui.react-router.slot-router": "0.0.488",
|
|
46
|
+
"@teambit/ui-foundation.ui.use-box.menu": "0.0.110",
|
|
47
|
+
"@teambit/ui": "0.0.653",
|
|
48
48
|
"@teambit/component-issues": "0.0.46",
|
|
49
|
-
"@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.
|
|
49
|
+
"@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.487",
|
|
50
50
|
"@teambit/cli-table": "0.0.33",
|
|
51
|
-
"@teambit/
|
|
51
|
+
"@teambit/component-descriptor": "0.0.3",
|
|
52
|
+
"@teambit/ui-foundation.ui.react-router.use-query": "0.0.486",
|
|
53
|
+
"@teambit/compositions": "0.0.653",
|
|
54
|
+
"@teambit/deprecation": "0.0.653",
|
|
55
|
+
"@teambit/envs": "0.0.653",
|
|
52
56
|
"@teambit/design.ui.empty-box": "0.0.353",
|
|
53
|
-
"@teambit/harmony.ui.aspect-box": "0.0.
|
|
57
|
+
"@teambit/harmony.ui.aspect-box": "0.0.486",
|
|
54
58
|
"@teambit/design.ui.pages.not-found": "0.0.353",
|
|
55
59
|
"@teambit/design.ui.pages.server-error": "0.0.353",
|
|
56
|
-
"@teambit/
|
|
57
|
-
"@teambit/
|
|
58
|
-
"@teambit/
|
|
59
|
-
"@teambit/component.ui.version-dropdown": "0.0.491",
|
|
60
|
-
"@teambit/ui-foundation.ui.use-box.dropdown": "0.0.109",
|
|
61
|
-
"@teambit/ui-foundation.ui.react-router.extend-path": "0.0.485"
|
|
60
|
+
"@teambit/component.ui.version-dropdown": "0.0.492",
|
|
61
|
+
"@teambit/ui-foundation.ui.use-box.dropdown": "0.0.110",
|
|
62
|
+
"@teambit/ui-foundation.ui.react-router.extend-path": "0.0.486"
|
|
62
63
|
},
|
|
63
64
|
"devDependencies": {
|
|
64
65
|
"@types/react": "^17.0.8",
|
|
@@ -68,16 +69,16 @@
|
|
|
68
69
|
"@types/react-router-dom": "5.1.7",
|
|
69
70
|
"@types/lodash.flatten": "4.4.6",
|
|
70
71
|
"@types/classnames": "2.2.11",
|
|
71
|
-
"@types/mocha": "
|
|
72
|
+
"@types/mocha": "9.1.0",
|
|
72
73
|
"@types/testing-library__jest-dom": "5.9.5",
|
|
73
74
|
"@types/jest": "^26.0.0",
|
|
74
75
|
"@types/react-dom": "^17.0.5",
|
|
75
76
|
"@types/node": "12.20.4",
|
|
76
|
-
"@teambit/component.aspect-docs.component": "0.0.
|
|
77
|
+
"@teambit/component.aspect-docs.component": "0.0.132"
|
|
77
78
|
},
|
|
78
79
|
"peerDependencies": {
|
|
79
80
|
"@apollo/client": "^3.0.0",
|
|
80
|
-
"@teambit/legacy": "1.0.
|
|
81
|
+
"@teambit/legacy": "1.0.223",
|
|
81
82
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
82
83
|
"react": "^16.8.0 || ^17.0.0"
|
|
83
84
|
},
|
|
@@ -95,7 +96,7 @@
|
|
|
95
96
|
},
|
|
96
97
|
"devDependencies": {
|
|
97
98
|
"@teambit/legacy": "-",
|
|
98
|
-
"@types/mocha": "
|
|
99
|
+
"@types/mocha": "9.1.0",
|
|
99
100
|
"@types/testing-library__jest-dom": "5.9.5",
|
|
100
101
|
"@types/jest": "^26.0.0",
|
|
101
102
|
"@types/react-dom": "^17.0.5",
|
|
@@ -105,7 +106,7 @@
|
|
|
105
106
|
"react": "-"
|
|
106
107
|
},
|
|
107
108
|
"peerDependencies": {
|
|
108
|
-
"@teambit/legacy": "1.0.
|
|
109
|
+
"@teambit/legacy": "1.0.223",
|
|
109
110
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
110
111
|
"react": "^16.8.0 || ^17.0.0"
|
|
111
112
|
}
|
|
@@ -2,6 +2,7 @@ import { useMemo, useEffect, useRef } from 'react';
|
|
|
2
2
|
import { gql } from '@apollo/client';
|
|
3
3
|
import { useDataQuery } from '@teambit/ui-foundation.ui.hooks.use-data-query';
|
|
4
4
|
import { ComponentID, ComponentIdObj } from '@teambit/component-id';
|
|
5
|
+
import { ComponentDescriptor } from '@teambit/component-descriptor';
|
|
5
6
|
|
|
6
7
|
import { ComponentModel } from './component-model';
|
|
7
8
|
import { ComponentError } from './component-error';
|
|
@@ -19,6 +20,10 @@ const componentFields = gql`
|
|
|
19
20
|
id {
|
|
20
21
|
...componentIdFields
|
|
21
22
|
}
|
|
23
|
+
aspects(include: ["teambit.preview/preview"]) {
|
|
24
|
+
id
|
|
25
|
+
data
|
|
26
|
+
}
|
|
22
27
|
packageName
|
|
23
28
|
elementsUrl
|
|
24
29
|
description
|
|
@@ -41,6 +46,7 @@ const componentFields = gql`
|
|
|
41
46
|
id
|
|
42
47
|
icon
|
|
43
48
|
}
|
|
49
|
+
|
|
44
50
|
preview {
|
|
45
51
|
includesEnvTemplate
|
|
46
52
|
}
|
|
@@ -186,9 +192,13 @@ export function useComponentQuery(componentId: string, host: string) {
|
|
|
186
192
|
}, []);
|
|
187
193
|
|
|
188
194
|
const rawComponent = data?.getHost?.get;
|
|
189
|
-
|
|
190
195
|
return useMemo(() => {
|
|
196
|
+
const aspectList = {
|
|
197
|
+
entries: rawComponent?.aspects?.map((aspect) => ({ aspectId: aspect.id, aspectData: aspect.data })),
|
|
198
|
+
};
|
|
199
|
+
const id = rawComponent && ComponentID.fromObject(rawComponent.id);
|
|
191
200
|
return {
|
|
201
|
+
componentDescriptor: id ? ComponentDescriptor.fromObject({ id: id.toString(), aspectList }) : undefined,
|
|
192
202
|
component: rawComponent ? ComponentModel.from({ ...rawComponent, host }) : undefined,
|
|
193
203
|
// eslint-disable-next-line
|
|
194
204
|
error: error
|
package/ui/use-component.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useRouteMatch } from 'react-router-dom';
|
|
2
2
|
import { ComponentID } from '@teambit/component-id';
|
|
3
3
|
import { useQuery } from '@teambit/ui-foundation.ui.react-router.use-query';
|
|
4
|
+
import { ComponentDescriptor } from '@teambit/component-descriptor';
|
|
4
5
|
import { ComponentModel } from './component-model';
|
|
5
6
|
import { ComponentError } from './component-error';
|
|
6
7
|
import { useComponentQuery } from './use-component-query';
|
|
@@ -8,6 +9,7 @@ import { useComponentQuery } from './use-component-query';
|
|
|
8
9
|
export type Component = {
|
|
9
10
|
component?: ComponentModel;
|
|
10
11
|
error?: ComponentError;
|
|
12
|
+
componentDescriptor?: ComponentDescriptor;
|
|
11
13
|
};
|
|
12
14
|
|
|
13
15
|
type ComponentRoute = {
|
|
@@ -23,7 +25,6 @@ export function useComponent(host: string, id?: ComponentID): Component {
|
|
|
23
25
|
|
|
24
26
|
const targetId = id?.toString({ ignoreVersion: true }) || componentId;
|
|
25
27
|
if (!targetId) throw new TypeError('useComponent received no component id');
|
|
26
|
-
|
|
27
28
|
return useComponentQuery(withVersion(targetId, version), host);
|
|
28
29
|
}
|
|
29
30
|
|
|
Binary file
|