@teambit/component 0.0.666 → 0.0.669

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/dist/index.d.ts CHANGED
@@ -17,7 +17,7 @@ export { ComponentMap } from './component-map';
17
17
  export type { ComponentMain } from './component.main.runtime';
18
18
  export type { ComponentUI } from './component.ui.runtime';
19
19
  export { Section } from './section';
20
- export { ComponentContext, ComponentDescriptorContext } from './ui/context/component-context';
20
+ export { ComponentContext, ComponentDescriptorContext, useComponentDescriptor } from './ui/context/component-context';
21
21
  export type { ComponentProviderProps, ComponentDescriptorProviderProps } from './ui/context';
22
22
  export { ConsumePlugin } from './ui/menu';
23
23
  export { RegisteredComponentRoute, ComponentUrlParams } from './component.route';
package/dist/index.js CHANGED
@@ -150,6 +150,12 @@ Object.defineProperty(exports, "TagProps", {
150
150
  }
151
151
  });
152
152
  exports.default = void 0;
153
+ Object.defineProperty(exports, "useComponentDescriptor", {
154
+ enumerable: true,
155
+ get: function () {
156
+ return _componentContext().useComponentDescriptor;
157
+ }
158
+ });
153
159
  Object.defineProperty(exports, "useComponentHost", {
154
160
  enumerable: true,
155
161
  get: function () {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":["ComponentAspect"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;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;;AAIA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIA;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;;AAGA;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;;AApBA;AACA;AAGA;AACA;AAgBA;AACA;eAEeA,4B","sourcesContent":["import { ComponentAspect } from './component.aspect';\n\nexport { useComponentHost } from './host';\nexport { Component, InvalidComponent } from './component';\nexport { ComponentID } from '@teambit/component-id';\nexport { default as ComponentFS } from './component-fs';\nexport type { default as ComponentConfig } from './config';\nexport type { ComponentFactory } from './component-factory';\nexport type { AspectList } from './aspect-list';\nexport { AspectEntry, AspectData, ResolveComponentIdFunc } from './aspect-entry';\n// TODO: check why it's not working when using the index in snap dir like this:\n// export { Snap, Author } from './snap';\nexport { Snap, SnapProps } from './snap/snap';\nexport type { Author } from './snap/author';\n// TODO: check why it's not working when using the index in tag dir like this:\n// export { Tag } from './tag';\nexport { Tag, TagProps } from './tag/tag';\nexport { State } from './state';\nexport type { Hash } from './hash';\nexport { TagMap } from './tag-map';\nexport { ComponentMap } from './component-map';\nexport type { ComponentMain } from './component.main.runtime';\nexport type { ComponentUI } from './component.ui.runtime';\nexport { Section } from './section';\nexport { ComponentContext, ComponentDescriptorContext } from './ui/context/component-context';\nexport type { ComponentProviderProps, ComponentDescriptorProviderProps } from './ui/context';\nexport { ConsumePlugin } from './ui/menu';\nexport { RegisteredComponentRoute, ComponentUrlParams } from './component.route';\nexport { ComponentModel, ComponentModelProps } from './ui/component-model';\nexport type { ShowFragment, ShowRow } from './show';\nexport { default as Config } from './config';\n// export { AspectList } from './aspect-list';\n// export { AspectEntry } from './aspect-entry';\nexport { ComponentAspect };\nexport default ComponentAspect;\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":["ComponentAspect"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;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;;AAIA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIA;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;;AAGA;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;;AApBA;AACA;AAGA;AACA;AAgBA;AACA;eAEeA,4B","sourcesContent":["import { ComponentAspect } from './component.aspect';\n\nexport { useComponentHost } from './host';\nexport { Component, InvalidComponent } from './component';\nexport { ComponentID } from '@teambit/component-id';\nexport { default as ComponentFS } from './component-fs';\nexport type { default as ComponentConfig } from './config';\nexport type { ComponentFactory } from './component-factory';\nexport type { AspectList } from './aspect-list';\nexport { AspectEntry, AspectData, ResolveComponentIdFunc } from './aspect-entry';\n// TODO: check why it's not working when using the index in snap dir like this:\n// export { Snap, Author } from './snap';\nexport { Snap, SnapProps } from './snap/snap';\nexport type { Author } from './snap/author';\n// TODO: check why it's not working when using the index in tag dir like this:\n// export { Tag } from './tag';\nexport { Tag, TagProps } from './tag/tag';\nexport { State } from './state';\nexport type { Hash } from './hash';\nexport { TagMap } from './tag-map';\nexport { ComponentMap } from './component-map';\nexport type { ComponentMain } from './component.main.runtime';\nexport type { ComponentUI } from './component.ui.runtime';\nexport { Section } from './section';\nexport { ComponentContext, ComponentDescriptorContext, useComponentDescriptor } from './ui/context/component-context';\nexport type { ComponentProviderProps, ComponentDescriptorProviderProps } from './ui/context';\nexport { ConsumePlugin } from './ui/menu';\nexport { RegisteredComponentRoute, ComponentUrlParams } from './component.route';\nexport { ComponentModel, ComponentModelProps } from './ui/component-model';\nexport type { ShowFragment, ShowRow } from './show';\nexport { default as Config } from './config';\n// export { AspectList } from './aspect-list';\n// export { AspectEntry } from './aspect-entry';\nexport { ComponentAspect };\nexport default ComponentAspect;\n"]}
@@ -3,3 +3,4 @@ import type { ComponentDescriptor } from '@teambit/component-descriptor';
3
3
  import { ComponentModel } from '../component-model';
4
4
  export declare const ComponentContext: React.Context<ComponentModel>;
5
5
  export declare const ComponentDescriptorContext: React.Context<ComponentDescriptor | undefined>;
6
+ export declare const useComponentDescriptor: () => ComponentDescriptor | undefined;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.ComponentDescriptorContext = exports.ComponentContext = void 0;
6
+ exports.useComponentDescriptor = exports.ComponentDescriptorContext = exports.ComponentContext = void 0;
7
7
 
8
8
  function _react() {
9
9
  const data = require("react");
@@ -30,4 +30,8 @@ exports.ComponentContext = ComponentContext;
30
30
  const ComponentDescriptorContext = /*#__PURE__*/(0, _react().createContext)(undefined);
31
31
  exports.ComponentDescriptorContext = ComponentDescriptorContext;
32
32
 
33
+ const useComponentDescriptor = () => (0, _react().useContext)(ComponentDescriptorContext);
34
+
35
+ exports.useComponentDescriptor = useComponentDescriptor;
36
+
33
37
  //# sourceMappingURL=component-context.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["component-context.ts"],"names":["ComponentContext","ComponentModel","empty","ComponentDescriptorContext","undefined"],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,gBAA+C,gBAAG,4BAA8BC,iCAAeC,KAAf,EAA9B,CAAxD;;AACA,MAAMC,0BAA0E,gBAAG,4BAExFC,SAFwF,CAAnF","sourcesContent":["import { createContext } from 'react';\nimport type { ComponentDescriptor } from '@teambit/component-descriptor';\n\nimport { ComponentModel } from '../component-model';\n\nexport const ComponentContext: React.Context<ComponentModel> = createContext<ComponentModel>(ComponentModel.empty());\nexport const ComponentDescriptorContext: React.Context<ComponentDescriptor | undefined> = createContext<\n ComponentDescriptor | undefined\n>(undefined);\n"]}
1
+ {"version":3,"sources":["component-context.ts"],"names":["ComponentContext","ComponentModel","empty","ComponentDescriptorContext","undefined","useComponentDescriptor"],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,gBAA+C,gBAAG,4BAA8BC,iCAAeC,KAAf,EAA9B,CAAxD;;AACA,MAAMC,0BAA0E,gBAAG,4BAExFC,SAFwF,CAAnF;;;AAIA,MAAMC,sBAAsB,GAAG,MAAM,yBAAWF,0BAAX,CAArC","sourcesContent":["import { createContext, useContext } from 'react';\nimport type { ComponentDescriptor } from '@teambit/component-descriptor';\n\nimport { ComponentModel } from '../component-model';\n\nexport const ComponentContext: React.Context<ComponentModel> = createContext<ComponentModel>(ComponentModel.empty());\nexport const ComponentDescriptorContext: React.Context<ComponentDescriptor | undefined> = createContext<\n ComponentDescriptor | undefined\n>(undefined);\n\nexport const useComponentDescriptor = () => useContext(ComponentDescriptorContext)"]}
@@ -1,3 +1,3 @@
1
- export { ComponentContext, ComponentDescriptorContext } from './component-context';
1
+ export { ComponentContext, ComponentDescriptorContext, useComponentDescriptor } from './component-context';
2
2
  export { ComponentProvider, ComponentDescriptorProvider } from './component-provider';
3
3
  export type { ComponentProviderProps, ComponentDescriptorProviderProps } from './component-provider';
@@ -27,6 +27,12 @@ Object.defineProperty(exports, "ComponentProvider", {
27
27
  return _componentProvider().ComponentProvider;
28
28
  }
29
29
  });
30
+ Object.defineProperty(exports, "useComponentDescriptor", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _componentContext().useComponentDescriptor;
34
+ }
35
+ });
30
36
 
31
37
  function _componentContext() {
32
38
  const data = require("./component-context");
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA","sourcesContent":["export { ComponentContext, ComponentDescriptorContext } from './component-context';\nexport { ComponentProvider, ComponentDescriptorProvider } from './component-provider';\nexport type { ComponentProviderProps, ComponentDescriptorProviderProps } from './component-provider';\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA","sourcesContent":["export { ComponentContext, ComponentDescriptorContext, useComponentDescriptor } from './component-context';\nexport { ComponentProvider, ComponentDescriptorProvider } from './component-provider';\nexport type { ComponentProviderProps, ComponentDescriptorProviderProps } from './component-provider';\n"]}
@@ -104,8 +104,11 @@ const componentFields = (0, _client().gql)`
104
104
  ...componentIdFields
105
105
  }
106
106
  aspects(include: ["teambit.preview/preview", "teambit.pipelines/builder"]) {
107
- id
108
- data
107
+ # 'id' property in gql refers to a *global* identifier and used for caching.
108
+ # this makes aspect data cache under the same key, even when they are under different components.
109
+ # renaming the property fixes that.
110
+ aspectId: id
111
+ aspectData: data
109
112
  }
110
113
  packageName
111
114
  elementsUrl
@@ -286,13 +289,8 @@ function useComponentQuery(componentId, host) {
286
289
  }, []);
287
290
  const rawComponent = data === null || data === void 0 ? void 0 : (_data$getHost = data.getHost) === null || _data$getHost === void 0 ? void 0 : _data$getHost.get;
288
291
  return (0, _react().useMemo)(() => {
289
- var _rawComponent$aspects;
290
-
291
292
  const aspectList = {
292
- entries: rawComponent === null || rawComponent === void 0 ? void 0 : (_rawComponent$aspects = rawComponent.aspects) === null || _rawComponent$aspects === void 0 ? void 0 : _rawComponent$aspects.map(aspect => ({
293
- aspectId: aspect.id,
294
- aspectData: aspect.data
295
- }))
293
+ entries: rawComponent === null || rawComponent === void 0 ? void 0 : rawComponent.aspects
296
294
  };
297
295
 
298
296
  const id = rawComponent && _componentId().ComponentID.fromObject(rawComponent.id);
@@ -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","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;;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;;;;;;AAEA,MAAMA,iBAAiB,GAAG,kBAAI;AAC9B;AACA;AACA;AACA;AACA;AACA,CANA;AAQA,MAAMC,eAAe,GAAG,kBAAI;AAC5B;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,IAAID,iBAAkB;AACtB,CA5CA;AA8CA,MAAME,aAAa,GAAG,kBAAI;AAC1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAID,eAAgB;AACpB,CAVA;AAYA,MAAME,sBAAsB,GAAG,kBAAI;AACnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIF,eAAgB;AACpB,CATA;AAWA,MAAMG,qBAAqB,GAAG,kBAAI;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIH,eAAgB;AACpB,CATA;AAWA,MAAMI,qBAAqB,GAAG,kBAAI;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIL,iBAAkB;AACtB,CATA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zF;AAEL5B,MAAAA,SAAS,EAAEgB,YAAY,GAAGa,iCAAeC,IAAf,iCAAyBd,YAAzB;AAAuCpC,QAAAA;AAAvC,SAAH,GAAoDgD,SAFtE;AAGL;AACA5C,MAAAA,KAAK,EAAEA,KAAK,GACR,KAAI+C,gCAAJ,EAAmB,GAAnB,EAAwB/C,KAAK,CAACgD,OAA9B,CADQ,GAER,CAAChB,YAAD,IAAiB,CAAC/B,OAAlB,GACA,KAAI8C,gCAAJ,EAAmB,GAAnB,CADA,GAEAH;AARC,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\", \"teambit.pipelines/builder\"]) {\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 logs(type: $logType, offset: $logOffset, limit: $logLimit) {\n message\n username\n email\n date\n hash\n tag\n }\n preview {\n includesEnvTemplate\n }\n }\n ${componentIdFields}\n`;\n\nconst GET_COMPONENT = gql`\n query Component($id: String!, $extensionId: String!, $logType: String, $logOffset: Int, $logLimit: Int) {\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($logType: String, $logOffset: Int, $logLimit: Int) {\n componentAdded {\n component {\n ...componentFields\n }\n }\n }\n ${componentFields}\n`;\n\nconst SUB_COMPONENT_CHANGED = gql`\n subscription OnComponentChanged($logType: String, $logOffset: Int, $logLimit: Int) {\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
+ {"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","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;;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;;;;;;AAEA,MAAMA,iBAAiB,GAAG,kBAAI;AAC9B;AACA;AACA;AACA;AACA;AACA,CANA;AAQA,MAAMC,eAAe,GAAG,kBAAI;AAC5B;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,IAAID,iBAAkB;AACtB,CA/CA;AAiDA,MAAME,aAAa,GAAG,kBAAI;AAC1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAID,eAAgB;AACpB,CAVA;AAYA,MAAME,sBAAsB,GAAG,kBAAI;AACnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIF,eAAgB;AACpB,CATA;AAWA,MAAMG,qBAAqB,GAAG,kBAAI;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIH,eAAgB;AACpB,CATA;AAWA,MAAMI,qBAAqB,GAAG,kBAAI;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIL,iBAAkB;AACtB,CATA;AAWA;;AACO,SAASM,iBAAT,CAA2BC,WAA3B,EAAgDC,IAAhD,EAA8D;AAAA;;AACnE,QAAMC,KAAK,GAAG,qBAAOF,WAAP,CAAd;AACAE,EAAAA,KAAK,CAACC,OAAN,GAAgBH,WAAhB;AACA,QAAM;AAAEI,IAAAA,IAAF;AAAQC,IAAAA,KAAR;AAAeC,IAAAA,OAAf;A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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\", \"teambit.pipelines/builder\"]) {\n # 'id' property in gql refers to a *global* identifier and used for caching.\n # this makes aspect data cache under the same key, even when they are under different components.\n # renaming the property fixes that.\n aspectId: id\n aspectData: 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 logs(type: $logType, offset: $logOffset, limit: $logLimit) {\n message\n username\n email\n date\n hash\n tag\n }\n preview {\n includesEnvTemplate\n }\n }\n ${componentIdFields}\n`;\n\nconst GET_COMPONENT = gql`\n query Component($id: String!, $extensionId: String!, $logType: String, $logOffset: Int, $logLimit: Int) {\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($logType: String, $logOffset: Int, $logLimit: Int) {\n componentAdded {\n component {\n ...componentFields\n }\n }\n }\n ${componentFields}\n`;\n\nconst SUB_COMPONENT_CHANGED = gql`\n subscription OnComponentChanged($logType: String, $logOffset: Int, $logLimit: Int) {\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,\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"]}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/component",
3
- "version": "0.0.666",
3
+ "version": "0.0.669",
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.666"
9
+ "version": "0.0.669"
10
10
  },
11
11
  "dependencies": {
12
12
  "@teambit/any-fs": "0.0.5",
@@ -29,37 +29,37 @@
29
29
  "@teambit/base-ui.routing.routing-provider": "1.0.0",
30
30
  "@teambit/component-id": "0.0.401",
31
31
  "@teambit/ui-foundation.ui.menu-widget-icon": "0.0.488",
32
- "@teambit/aspect-loader": "0.0.666",
32
+ "@teambit/aspect-loader": "0.0.669",
33
33
  "@teambit/legacy-bit-id": "0.0.398",
34
34
  "@teambit/toolbox.string.capitalize": "0.0.483",
35
- "@teambit/cli": "0.0.450",
36
- "@teambit/config": "0.0.463",
37
- "@teambit/express": "0.0.544",
38
- "@teambit/graphql": "0.0.666",
35
+ "@teambit/cli": "0.0.451",
36
+ "@teambit/config": "0.0.464",
37
+ "@teambit/express": "0.0.545",
38
+ "@teambit/graphql": "0.0.669",
39
39
  "@teambit/bit-error": "0.0.394",
40
- "@teambit/command-bar": "0.0.666",
41
- "@teambit/preview": "0.0.666",
42
- "@teambit/pubsub": "0.0.666",
40
+ "@teambit/command-bar": "0.0.669",
41
+ "@teambit/preview": "0.0.669",
42
+ "@teambit/pubsub": "0.0.669",
43
43
  "@teambit/ui-foundation.ui.is-browser": "0.0.486",
44
44
  "@teambit/ui-foundation.ui.main-dropdown": "0.0.486",
45
45
  "@teambit/ui-foundation.ui.react-router.slot-router": "0.0.488",
46
46
  "@teambit/ui-foundation.ui.use-box.menu": "0.0.111",
47
- "@teambit/ui": "0.0.666",
47
+ "@teambit/ui": "0.0.669",
48
48
  "@teambit/component-issues": "0.0.46",
49
49
  "@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.487",
50
50
  "@teambit/cli-table": "0.0.33",
51
- "@teambit/component-descriptor": "0.0.11",
51
+ "@teambit/component-descriptor": "0.0.12",
52
52
  "@teambit/ui-foundation.ui.react-router.use-query": "0.0.486",
53
53
  "@teambit/design.ui.empty-box": "0.0.353",
54
54
  "@teambit/harmony.ui.aspect-box": "0.0.486",
55
55
  "@teambit/design.ui.pages.not-found": "0.0.353",
56
56
  "@teambit/design.ui.pages.server-error": "0.0.353",
57
- "@teambit/compositions": "0.0.666",
58
- "@teambit/deprecation": "0.0.666",
59
- "@teambit/envs": "0.0.666",
57
+ "@teambit/compositions": "0.0.669",
58
+ "@teambit/deprecation": "0.0.669",
59
+ "@teambit/envs": "0.0.669",
60
60
  "@teambit/legacy-component-log": "0.0.391",
61
- "@teambit/component.ui.version-dropdown": "0.0.494",
62
- "@teambit/lanes.ui.lanes": "0.0.10",
61
+ "@teambit/component.ui.version-dropdown": "0.0.495",
62
+ "@teambit/lanes.ui.lanes": "0.0.11",
63
63
  "@teambit/ui-foundation.ui.full-loader": "0.0.486",
64
64
  "@teambit/ui-foundation.ui.use-box.dropdown": "0.0.111",
65
65
  "@teambit/ui-foundation.ui.react-router.extend-path": "0.0.486"
@@ -81,7 +81,7 @@
81
81
  },
82
82
  "peerDependencies": {
83
83
  "@apollo/client": "^3.0.0",
84
- "@teambit/legacy": "1.0.229",
84
+ "@teambit/legacy": "1.0.230",
85
85
  "react-dom": "^16.8.0 || ^17.0.0",
86
86
  "react": "^16.8.0 || ^17.0.0"
87
87
  },
@@ -109,7 +109,7 @@
109
109
  "react": "-"
110
110
  },
111
111
  "peerDependencies": {
112
- "@teambit/legacy": "1.0.229",
112
+ "@teambit/legacy": "1.0.230",
113
113
  "react-dom": "^16.8.0 || ^17.0.0",
114
114
  "react": "^16.8.0 || ^17.0.0"
115
115
  }
@@ -1 +1 @@
1
- export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component@0.0.666/dist/component.docs.mdx')]
1
+ export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component@0.0.669/dist/component.docs.mdx')]
@@ -1,4 +1,4 @@
1
- import { createContext } from 'react';
1
+ import { createContext, useContext } from 'react';
2
2
  import type { ComponentDescriptor } from '@teambit/component-descriptor';
3
3
 
4
4
  import { ComponentModel } from '../component-model';
@@ -7,3 +7,5 @@ export const ComponentContext: React.Context<ComponentModel> = createContext<Com
7
7
  export const ComponentDescriptorContext: React.Context<ComponentDescriptor | undefined> = createContext<
8
8
  ComponentDescriptor | undefined
9
9
  >(undefined);
10
+
11
+ export const useComponentDescriptor = () => useContext(ComponentDescriptorContext)
@@ -1,3 +1,3 @@
1
- export { ComponentContext, ComponentDescriptorContext } from './component-context';
1
+ export { ComponentContext, ComponentDescriptorContext, useComponentDescriptor } from './component-context';
2
2
  export { ComponentProvider, ComponentDescriptorProvider } from './component-provider';
3
3
  export type { ComponentProviderProps, ComponentDescriptorProviderProps } from './component-provider';
@@ -21,8 +21,11 @@ const componentFields = gql`
21
21
  ...componentIdFields
22
22
  }
23
23
  aspects(include: ["teambit.preview/preview", "teambit.pipelines/builder"]) {
24
- id
25
- data
24
+ # 'id' property in gql refers to a *global* identifier and used for caching.
25
+ # this makes aspect data cache under the same key, even when they are under different components.
26
+ # renaming the property fixes that.
27
+ aspectId: id
28
+ aspectData: data
26
29
  }
27
30
  packageName
28
31
  elementsUrl
@@ -201,7 +204,7 @@ export function useComponentQuery(componentId: string, host: string) {
201
204
  const rawComponent = data?.getHost?.get;
202
205
  return useMemo(() => {
203
206
  const aspectList = {
204
- entries: rawComponent?.aspects?.map((aspect) => ({ aspectId: aspect.id, aspectData: aspect.data })),
207
+ entries: rawComponent?.aspects,
205
208
  };
206
209
  const id = rawComponent && ComponentID.fromObject(rawComponent.id);
207
210
  return {