@teambit/component 1.0.106 → 1.0.108

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 (84) hide show
  1. package/aspect-entry.ts +73 -0
  2. package/aspect-list.ts +132 -0
  3. package/component-factory.ts +190 -0
  4. package/component-fs.ts +66 -0
  5. package/component-interface.ts +26 -0
  6. package/component-meta.ts +29 -0
  7. package/component.aspect.ts +9 -0
  8. package/component.graphql.ts +256 -0
  9. package/component.main.runtime.ts +170 -0
  10. package/component.route.ts +38 -0
  11. package/component.ts +319 -0
  12. package/config.ts +24 -0
  13. package/dist/aspect-entry.d.ts +4 -4
  14. package/dist/aspect-entry.js +1 -2
  15. package/dist/aspect-entry.js.map +1 -1
  16. package/dist/aspect-list.js +2 -2
  17. package/dist/aspect-list.js.map +1 -1
  18. package/dist/aspect.section.d.ts +3 -3
  19. package/dist/component-factory.d.ts +3 -3
  20. package/dist/component-interface.d.ts +1 -1
  21. package/dist/component-map/component-map.d.ts +2 -2
  22. package/dist/component.composition.d.ts +2 -2
  23. package/dist/component.d.ts +3 -3
  24. package/dist/component.graphql.d.ts +13 -13
  25. package/dist/component.graphql.js +3 -6
  26. package/dist/component.graphql.js.map +1 -1
  27. package/dist/component.js +5 -9
  28. package/dist/component.js.map +1 -1
  29. package/dist/component.main.runtime.d.ts +2 -2
  30. package/dist/component.route.d.ts +2 -2
  31. package/dist/component.ui.runtime.d.ts +7 -7
  32. package/dist/component.ui.runtime.js +12 -27
  33. package/dist/component.ui.runtime.js.map +1 -1
  34. package/dist/get-component-opts.d.ts +1 -1
  35. package/dist/hash.d.ts +1 -1
  36. package/dist/{preview-1703505948637.js → preview-1703647408454.js} +2 -2
  37. package/dist/snap/author.d.ts +1 -1
  38. package/dist/snap/snap.d.ts +1 -1
  39. package/dist/tag/tag.d.ts +1 -1
  40. package/dist/tag-map.d.ts +1 -1
  41. package/dist/ui/aspect-page/aspect-page.d.ts +2 -2
  42. package/dist/ui/aspect-page/aspect-page.js +1 -2
  43. package/dist/ui/aspect-page/aspect-page.js.map +1 -1
  44. package/dist/ui/component-error/component-error.d.ts +4 -4
  45. package/dist/ui/component-model/component-model.d.ts +21 -21
  46. package/dist/ui/component-model/component-model.js +1 -1
  47. package/dist/ui/component-model/component-model.js.map +1 -1
  48. package/dist/ui/component-searcher/component-result.d.ts +4 -4
  49. package/dist/ui/component-searcher/component-result.js +2 -2
  50. package/dist/ui/component-searcher/component-result.js.map +1 -1
  51. package/dist/ui/component-searcher/component-searcher.d.ts +2 -2
  52. package/dist/ui/component.d.ts +5 -5
  53. package/dist/ui/component.js +6 -6
  54. package/dist/ui/component.js.map +1 -1
  55. package/dist/ui/context/component-context.d.ts +1 -1
  56. package/dist/ui/context/component-provider.d.ts +5 -5
  57. package/dist/ui/menu/menu-nav.d.ts +2 -2
  58. package/dist/ui/menu/menu-nav.js +5 -5
  59. package/dist/ui/menu/menu-nav.js.map +1 -1
  60. package/dist/ui/menu/menu.d.ts +9 -9
  61. package/dist/ui/menu/menu.js +28 -31
  62. package/dist/ui/menu/menu.js.map +1 -1
  63. package/dist/ui/menu/nav-plugin.d.ts +7 -7
  64. package/dist/ui/top-bar-nav/top-bar-nav.d.ts +2 -2
  65. package/dist/ui/use-component-from-location.js +1 -1
  66. package/dist/ui/use-component-from-location.js.map +1 -1
  67. package/dist/ui/use-component-logs.d.ts +7 -7
  68. package/dist/ui/use-component-logs.js +5 -6
  69. package/dist/ui/use-component-logs.js.map +1 -1
  70. package/dist/ui/use-component-query.js +13 -17
  71. package/dist/ui/use-component-query.js.map +1 -1
  72. package/dist/ui/use-component.model.d.ts +7 -7
  73. package/get-component-opts.ts +14 -0
  74. package/hash.ts +4 -0
  75. package/head.ts +0 -0
  76. package/history-graph.ts +1 -0
  77. package/index.ts +50 -0
  78. package/on-load.ts +0 -0
  79. package/package.json +34 -41
  80. package/state.ts +88 -0
  81. package/store.ts +3 -0
  82. package/tag-map.ts +87 -0
  83. package/tsconfig.json +16 -21
  84. package/types/asset.d.ts +15 -3
@@ -1 +1 @@
1
- {"version":3,"names":["_react","data","require","_uiFoundationUiHooks","_componentId","_componentDescriptor","_componentModel","_useComponent","_useComponentLogs","_componentError","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","obj","key","value","_toPropertyKey","configurable","writable","i","_toPrimitive","String","Symbol","toPrimitive","call","TypeError","Number","useComponentQuery","componentId","host","filters","skip","_data$getHost","_rawComponent$id","_rawComponent$id2","_rawComponent$id3","idRef","useRef","current","variables","id","extensionId","error","loading","subscribeToMore","useDataQuery","GET_COMPONENT","errorPolicy","loadingLogs","componentLogs","logs","useComponentLogs","rawComponent","getHost","get","useEffect","unsubAddition","document","SUB_SUBSCRIPTION_ADDED","updateQuery","prev","subscriptionData","_prev$getHost","_subscriptionData$dat","prevComponent","addedComponent","componentAdded","component","name","unsubChanges","SUB_COMPONENT_CHANGED","_prev$getHost2","_subscriptionData$dat2","updatedComponent","componentChanged","isUpdated","ComponentID","isEqualObj","unsubRemoval","SUB_COMPONENT_REMOVED","_prev$getHost3","_subscriptionData$dat3","removedIds","componentRemoved","componentIds","isRemoved","some","removedId","idDepKey","scope","version","undefined","useMemo","fromObject","componentError","ComponentError","message","ComponentModel","from","toString","componentDescriptor","aspectList","entries","aspects","map","aspectObject","aspectId","aspectData","ComponentDescriptor"],"sources":["use-component-query.ts"],"sourcesContent":["import { useMemo, useEffect, useRef } from 'react';\nimport { useDataQuery } from '@teambit/ui-foundation.ui.hooks.use-data-query';\nimport { ComponentID, ComponentIdObj } from '@teambit/component-id';\nimport { ComponentDescriptor } from '@teambit/component-descriptor';\nimport { ComponentModel } from './component-model';\nimport { ComponentQueryResult, Filters } from './use-component.model';\nimport {\n GET_COMPONENT,\n SUB_COMPONENT_CHANGED,\n SUB_COMPONENT_REMOVED,\n SUB_SUBSCRIPTION_ADDED,\n} from './use-component.fragments';\nimport { useComponentLogs } from './use-component-logs';\nimport { ComponentError } from './component-error';\n\n/** provides data to component ui page, making sure both variables and return value are safely typed and memoized */\nexport function useComponentQuery(\n componentId: string,\n host: string,\n filters?: Filters,\n skip?: boolean\n): ComponentQueryResult {\n const idRef = useRef(componentId);\n idRef.current = componentId;\n const variables = {\n id: componentId,\n extensionId: host,\n };\n\n const { data, error, loading, subscribeToMore } = useDataQuery(GET_COMPONENT, {\n variables,\n skip,\n errorPolicy: 'all',\n });\n\n const { loading: loadingLogs, componentLogs: { logs } = {} } = useComponentLogs(componentId, host, filters, skip);\n\n const rawComponent = data?.getHost?.get;\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 idDepKey = rawComponent?.id\n ? `${rawComponent?.id?.scope}/${rawComponent?.id?.name}@${rawComponent?.id?.version}}`\n : undefined;\n\n const id: ComponentID | undefined = useMemo(\n () => (rawComponent ? ComponentID.fromObject(rawComponent.id) : undefined),\n [idDepKey]\n );\n\n const componentError =\n error && !data\n ? new ComponentError(500, error.message)\n : (!rawComponent && !loading && new ComponentError(404)) || undefined;\n\n const component = useMemo(\n () => (rawComponent ? ComponentModel.from({ ...rawComponent, host, logs }) : undefined),\n [id?.toString(), logs]\n );\n\n const componentDescriptor = useMemo(() => {\n const aspectList = {\n entries: rawComponent?.aspects.map((aspectObject) => {\n return {\n ...aspectObject,\n aspectId: aspectObject.id,\n aspectData: aspectObject.data,\n };\n }),\n };\n\n return id ? ComponentDescriptor.fromObject({ id: id.toString(), aspectList }) : undefined;\n }, [id?.toString()]);\n\n return useMemo(() => {\n return {\n componentDescriptor,\n component,\n componentLogs: {\n loading: loadingLogs,\n logs,\n },\n error: componentError || undefined,\n loading,\n };\n }, [host, component, componentDescriptor, componentError]);\n}\n"],"mappings":";;;;;;AAAA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,qBAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,oBAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,aAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA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IAAEvB,IAAI;IAAEqB;EAAI,EAAE,CAAC,GAAGyC,SAAU,EACvF,CAACnD,EAAE,aAAFA,EAAE,uBAAFA,EAAE,CAAE2D,QAAQ,CAAC,CAAC,EAAEjD,IAAI,CACvB,CAAC;EAED,MAAMkD,mBAAmB,GAAG,IAAAR,gBAAO,EAAC,MAAM;IACxC,MAAMS,UAAU,GAAG;MACjBC,OAAO,EAAElD,YAAY,aAAZA,YAAY,uBAAZA,YAAY,CAAEmD,OAAO,CAACC,GAAG,CAAEC,YAAY,IAAK;QACnD,OAAApG,aAAA,CAAAA,aAAA,KACKoG,YAAY;UACfC,QAAQ,EAAED,YAAY,CAACjE,EAAE;UACzBmE,UAAU,EAAEF,YAAY,CAAC1H;QAAI;MAEjC,CAAC;IACH,CAAC;IAED,OAAOyD,EAAE,GAAGoE,0CAAmB,CAACf,UAAU,CAAC;MAAErD,EAAE,EAAEA,EAAE,CAAC2D,QAAQ,CAAC,CAAC;MAAEE;IAAW,CAAC,CAAC,GAAGV,SAAS;EAC3F,CAAC,EAAE,CAACnD,EAAE,aAAFA,EAAE,uBAAFA,EAAE,CAAE2D,QAAQ,CAAC,CAAC,CAAC,CAAC;EAEpB,OAAO,IAAAP,gBAAO,EAAC,MAAM;IACnB,OAAO;MACLQ,mBAAmB;MACnBjC,SAAS;MACTlB,aAAa,EAAE;QACbN,OAAO,EAAEK,WAAW;QACpBE;MACF,CAAC;MACDR,KAAK,EAAEoD,cAAc,IAAIH,SAAS;MAClChD;IACF,CAAC;EACH,CAAC,EAAE,CAACd,IAAI,EAAEsC,SAAS,EAAEiC,mBAAmB,EAAEN,cAAc,CAAC,CAAC;AAC5D"}
1
+ {"version":3,"names":["_react","data","require","_uiFoundationUiHooks","_componentId","_componentDescriptor","_componentModel","_useComponent","_useComponentLogs","_componentError","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","obj","key","value","_toPropertyKey","configurable","writable","i","_toPrimitive","String","Symbol","toPrimitive","call","TypeError","Number","useComponentQuery","componentId","host","filters","skip","idRef","useRef","current","variables","id","extensionId","error","loading","subscribeToMore","useDataQuery","GET_COMPONENT","errorPolicy","loadingLogs","componentLogs","logs","useComponentLogs","rawComponent","getHost","get","useEffect","unsubAddition","document","SUB_SUBSCRIPTION_ADDED","updateQuery","prev","subscriptionData","prevComponent","addedComponent","componentAdded","component","name","unsubChanges","SUB_COMPONENT_CHANGED","updatedComponent","componentChanged","isUpdated","ComponentID","isEqualObj","unsubRemoval","SUB_COMPONENT_REMOVED","removedIds","componentRemoved","componentIds","isRemoved","some","removedId","idDepKey","scope","version","undefined","useMemo","fromObject","componentError","ComponentError","message","ComponentModel","from","toString","componentDescriptor","aspectList","entries","aspects","map","aspectObject","aspectId","aspectData","ComponentDescriptor"],"sources":["use-component-query.ts"],"sourcesContent":["import { useMemo, useEffect, useRef } from 'react';\nimport { useDataQuery } from '@teambit/ui-foundation.ui.hooks.use-data-query';\nimport { ComponentID, ComponentIdObj } from '@teambit/component-id';\nimport { ComponentDescriptor } from '@teambit/component-descriptor';\nimport { ComponentModel } from './component-model';\nimport { ComponentQueryResult, Filters } from './use-component.model';\nimport {\n GET_COMPONENT,\n SUB_COMPONENT_CHANGED,\n SUB_COMPONENT_REMOVED,\n SUB_SUBSCRIPTION_ADDED,\n} from './use-component.fragments';\nimport { useComponentLogs } from './use-component-logs';\nimport { ComponentError } from './component-error';\n\n/** provides data to component ui page, making sure both variables and return value are safely typed and memoized */\nexport function useComponentQuery(\n componentId: string,\n host: string,\n filters?: Filters,\n skip?: boolean\n): ComponentQueryResult {\n const idRef = useRef(componentId);\n idRef.current = componentId;\n const variables = {\n id: componentId,\n extensionId: host,\n };\n\n const { data, error, loading, subscribeToMore } = useDataQuery(GET_COMPONENT, {\n variables,\n skip,\n errorPolicy: 'all',\n });\n\n const { loading: loadingLogs, componentLogs: { logs } = {} } = useComponentLogs(componentId, host, filters, skip);\n\n const rawComponent = data?.getHost?.get;\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 idDepKey = rawComponent?.id\n ? `${rawComponent?.id?.scope}/${rawComponent?.id?.name}@${rawComponent?.id?.version}}`\n : undefined;\n\n const id: ComponentID | undefined = useMemo(\n () => (rawComponent ? ComponentID.fromObject(rawComponent.id) : undefined),\n [idDepKey]\n );\n\n const componentError =\n error && !data\n ? new ComponentError(500, error.message)\n : (!rawComponent && !loading && new ComponentError(404)) || undefined;\n\n const component = useMemo(\n () => (rawComponent ? ComponentModel.from({ ...rawComponent, host, logs }) : undefined),\n [id?.toString(), logs]\n );\n\n const componentDescriptor = useMemo(() => {\n const aspectList = {\n entries: rawComponent?.aspects.map((aspectObject) => {\n return {\n ...aspectObject,\n aspectId: aspectObject.id,\n aspectData: aspectObject.data,\n };\n }),\n };\n\n return id ? ComponentDescriptor.fromObject({ id: id.toString(), aspectList }) : undefined;\n }, [id?.toString()]);\n\n return useMemo(() => {\n return {\n componentDescriptor,\n component,\n componentLogs: {\n loading: loadingLogs,\n logs,\n },\n error: componentError || undefined,\n loading,\n };\n }, [host, component, componentDescriptor, componentError]);\n}\n"],"mappings":";;;;;;AAAA,SAAAA,OAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,MAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,qBAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,oBAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,aAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,YAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,qBAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,oBAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,gBAAA;EAAA,MAAAL,IAAA,GAAAC,OAAA;EAAAI,eAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAM,cAAA;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,QAAQ,EAAED,YAAY,CAAC3D,EAAE;UACzB6D,UAAU,EAAEF,YAAY,CAAChH;QAAI;MAEjC,CAAC;IACH,CAAC;IAED,OAAOqD,EAAE,GAAG8D,0CAAmB,CAACf,UAAU,CAAC;MAAE/C,EAAE,EAAEA,EAAE,CAACqD,QAAQ,CAAC,CAAC;MAAEE;IAAW,CAAC,CAAC,GAAGV,SAAS;EAC3F,CAAC,EAAE,CAAC7C,EAAE,EAAEqD,QAAQ,CAAC,CAAC,CAAC,CAAC;EAEpB,OAAO,IAAAP,gBAAO,EAAC,MAAM;IACnB,OAAO;MACLQ,mBAAmB;MACnB7B,SAAS;MACThB,aAAa,EAAE;QACbN,OAAO,EAAEK,WAAW;QACpBE;MACF,CAAC;MACDR,KAAK,EAAE8C,cAAc,IAAIH,SAAS;MAClC1C;IACF,CAAC;EACH,CAAC,EAAE,CAACV,IAAI,EAAEgC,SAAS,EAAE6B,mBAAmB,EAAEN,cAAc,CAAC,CAAC;AAC5D"}
@@ -3,33 +3,33 @@ import { LegacyComponentLog } from '@teambit/legacy-component-log';
3
3
  import { ComponentID } from '../';
4
4
  import { ComponentError } from './component-error';
5
5
  import { ComponentModel } from './component-model';
6
- export declare type LogFilter = {
6
+ export type LogFilter = {
7
7
  offset?: number;
8
8
  limit?: number;
9
9
  head?: string;
10
10
  sort?: string;
11
11
  takeHeadFromComponent?: boolean;
12
12
  };
13
- export declare type Filters = {
13
+ export type Filters = {
14
14
  log?: LogFilter & {
15
15
  type?: string;
16
16
  };
17
17
  loading?: boolean;
18
18
  };
19
- export declare type UseComponentOptions = {
19
+ export type UseComponentOptions = {
20
20
  version?: string;
21
21
  logFilters?: Filters;
22
22
  customUseComponent?: UseComponentType;
23
23
  skip?: boolean;
24
24
  };
25
- export declare type ComponentQueryResult = {
25
+ export type ComponentQueryResult = {
26
26
  component?: ComponentModel;
27
27
  componentDescriptor?: ComponentDescriptor;
28
28
  componentLogs?: ComponentLogs;
29
29
  loading?: boolean;
30
30
  error?: ComponentError;
31
31
  };
32
- export declare type ComponentLogsResult = {
32
+ export type ComponentLogsResult = {
33
33
  id?: ComponentID;
34
34
  componentLogs?: ComponentLogs;
35
35
  latest?: string;
@@ -37,8 +37,8 @@ export declare type ComponentLogsResult = {
37
37
  error?: ComponentError;
38
38
  loading?: boolean;
39
39
  };
40
- export declare type ComponentLogs = {
40
+ export type ComponentLogs = {
41
41
  logs?: LegacyComponentLog[];
42
42
  loading?: boolean;
43
43
  };
44
- export declare type UseComponentType = (id: string, host: string, filters?: Filters, skip?: boolean) => ComponentQueryResult;
44
+ export type UseComponentType = (id: string, host: string, filters?: Filters, skip?: boolean) => ComponentQueryResult;
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { RouteProps } from 'react-router-dom';
3
+ import type { UseComponentType, Filters } from './ui/use-component';
4
+
5
+ export type GetComponentsOptions = {
6
+ useComponent?: UseComponentType;
7
+ componentId?: string | (() => string | undefined);
8
+ useComponentFilters?: () => Filters;
9
+ path?: string;
10
+ skipRightSide?: boolean;
11
+ RightNode?: React.ReactNode;
12
+ className?: string;
13
+ routes?: RouteProps[];
14
+ };
package/hash.ts ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * type for representing content-addressable filesystem hashes.
3
+ */
4
+ export type Hash = string;
package/head.ts ADDED
File without changes
@@ -0,0 +1 @@
1
+ export default class HistoryGraph {}
package/index.ts ADDED
@@ -0,0 +1,50 @@
1
+ import { ComponentAspect } from './component.aspect';
2
+
3
+ export type { GetComponentsOptions } from './get-component-opts';
4
+ export type { UseComponentType } from './ui/use-component';
5
+ export { useComponentHost } from './host';
6
+ export { Component, InvalidComponent } from './component';
7
+ export { ComponentID } from '@teambit/component-id';
8
+ export { default as ComponentFS } from './component-fs';
9
+ export type { Config as ComponentConfig } from './config';
10
+ export type {
11
+ ComponentFactory,
12
+ ResolveAspectsOptions,
13
+ FilterAspectsOptions,
14
+ LoadAspectsOptions,
15
+ } from './component-factory';
16
+ export type { AspectList } from './aspect-list';
17
+ export { AspectEntry, AspectData, ResolveComponentIdFunc } from './aspect-entry';
18
+ // TODO: check why it's not working when using the index in snap dir like this:
19
+ // export { Snap, Author } from './snap';
20
+ export { Snap, SnapProps } from './snap/snap';
21
+ export type { Author } from './snap/author';
22
+ // TODO: check why it's not working when using the index in tag dir like this:
23
+ // export { Tag } from './tag';
24
+ export { Tag, TagProps } from './tag/tag';
25
+ export type { IComponent } from './component-interface';
26
+ export { State } from './state';
27
+ export type { Hash } from './hash';
28
+ export { TagMap } from './tag-map';
29
+ export { ComponentMap } from './component-map';
30
+ export type { ComponentMain } from './component.main.runtime';
31
+ export type { ComponentUI } from './component.ui.runtime';
32
+ export type { Section } from './section';
33
+ export { ComponentContext, ComponentDescriptorContext, useComponentDescriptor } from './ui/context/component-context';
34
+ export type { ComponentProviderProps, ComponentDescriptorProviderProps } from './ui/context';
35
+ export { ComponentProvider, ComponentDescriptorProvider } from './ui/context';
36
+ export { componentFields, componentIdFields, componentOverviewFields } from './ui';
37
+ export type { NavPlugin, ConsumePlugin, MenuNavProps } from './ui/menu';
38
+ export { CollapsibleMenuNav, ComponentMenu, VersionRelatedDropdowns } from './ui/menu';
39
+ export type { RegisteredComponentRoute, ComponentUrlParams } from './component.route';
40
+ export type { ComponentModelProps } from './ui/component-model';
41
+ export { ComponentModel } from './ui/component-model';
42
+ export { TopBarNav } from './ui/top-bar-nav';
43
+ export type { ShowFragment, ShowRow, ShowJSONRow } from './show';
44
+ export { Config } from './config';
45
+ export { useComponent, useIdFromLocation, useComponentLogs, ComponentLogsResult, Filters } from './ui';
46
+
47
+ // export { AspectList } from './aspect-list';
48
+ // export { AspectEntry } from './aspect-entry';
49
+ export { ComponentAspect };
50
+ export default ComponentAspect;
package/on-load.ts ADDED
File without changes
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/component",
3
- "version": "1.0.106",
3
+ "version": "1.0.108",
4
4
  "homepage": "https://bit.cloud/teambit/component/component",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.component",
8
8
  "name": "component",
9
- "version": "1.0.106"
9
+ "version": "1.0.108"
10
10
  },
11
11
  "dependencies": {
12
12
  "@teambit/any-fs": "0.0.5",
@@ -19,8 +19,6 @@
19
19
  "lodash.flatten": "4.4.0",
20
20
  "classnames": "2.2.6",
21
21
  "lodash.compact": "3.0.1",
22
- "core-js": "^3.0.0",
23
- "@babel/runtime": "7.20.0",
24
22
  "@teambit/component-id": "1.2.0",
25
23
  "@teambit/ui-foundation.ui.menu-widget-icon": "0.0.502",
26
24
  "@teambit/graph.cleargraph": "0.0.1",
@@ -37,59 +35,57 @@
37
35
  "@teambit/ui-foundation.ui.react-router.use-query": "0.0.501",
38
36
  "@teambit/design.ui.pages.not-found": "0.0.366",
39
37
  "@teambit/design.ui.pages.server-error": "0.0.366",
40
- "@teambit/design.ui.styles.ellipsis": "0.0.357",
41
- "@teambit/explorer.ui.command-bar": "2.0.14",
42
38
  "@teambit/design.ui.empty-box": "0.0.363",
43
39
  "@teambit/documenter.ui.heading": "4.1.1",
44
40
  "@teambit/documenter.ui.separator": "4.1.1",
41
+ "@teambit/design.ui.styles.ellipsis": "0.0.357",
42
+ "@teambit/explorer.ui.command-bar": "2.0.14",
45
43
  "@teambit/design.navigation.responsive-navbar": "0.0.7",
46
44
  "@teambit/base-ui.layout.breakpoints": "1.0.0",
47
45
  "@teambit/component.ui.version-dropdown": "0.0.852",
48
46
  "@teambit/lanes.hooks.use-lanes": "0.0.254",
49
47
  "@teambit/lanes.ui.models.lanes-model": "0.0.207",
50
48
  "@teambit/ui-foundation.ui.use-box.dropdown": "0.0.141",
51
- "@teambit/aspect-loader": "1.0.106",
52
- "@teambit/graph": "1.0.106",
49
+ "@teambit/aspect-loader": "1.0.108",
50
+ "@teambit/graph": "1.0.108",
53
51
  "@teambit/toolbox.path.match-patterns": "0.0.13",
54
52
  "@teambit/toolbox.string.capitalize": "0.0.494",
55
- "@teambit/cli": "0.0.839",
56
- "@teambit/express": "0.0.938",
57
- "@teambit/graphql": "1.0.106",
58
- "@teambit/command-bar": "1.0.106",
59
- "@teambit/component-package-version": "0.0.430",
60
- "@teambit/preview": "1.0.106",
61
- "@teambit/pubsub": "1.0.106",
62
- "@teambit/react-router": "1.0.106",
63
- "@teambit/ui": "1.0.106",
64
- "@teambit/component-issues": "0.0.137",
65
- "@teambit/cli-table": "0.0.45",
66
- "@teambit/component-descriptor": "0.0.407",
67
- "@teambit/compositions": "1.0.106",
68
- "@teambit/deprecation": "1.0.106",
69
- "@teambit/envs": "1.0.106",
70
- "@teambit/envs.ui.env-icon": "0.0.503",
71
- "@teambit/harmony.ui.aspect-box": "0.0.505"
53
+ "@teambit/cli": "0.0.840",
54
+ "@teambit/express": "0.0.939",
55
+ "@teambit/graphql": "1.0.108",
56
+ "@teambit/command-bar": "1.0.108",
57
+ "@teambit/component-package-version": "0.0.431",
58
+ "@teambit/preview": "1.0.108",
59
+ "@teambit/pubsub": "1.0.108",
60
+ "@teambit/react-router": "1.0.108",
61
+ "@teambit/ui": "1.0.108",
62
+ "@teambit/component-issues": "0.0.138",
63
+ "@teambit/cli-table": "0.0.46",
64
+ "@teambit/component-descriptor": "0.0.408",
65
+ "@teambit/compositions": "1.0.108",
66
+ "@teambit/deprecation": "1.0.108",
67
+ "@teambit/envs": "1.0.108",
68
+ "@teambit/harmony.ui.aspect-box": "0.0.505",
69
+ "@teambit/envs.ui.env-icon": "0.0.503"
72
70
  },
73
71
  "devDependencies": {
74
- "@types/react": "^17.0.8",
75
72
  "@types/lodash": "4.14.165",
76
73
  "@types/semver": "7.3.4",
77
74
  "@types/lodash.flatten": "4.4.6",
78
75
  "@types/classnames": "2.2.11",
79
76
  "@types/lodash.compact": "3.0.6",
80
77
  "@types/mocha": "9.1.0",
81
- "@types/node": "12.20.4",
82
- "@types/react-dom": "^17.0.5",
83
- "@types/jest": "^26.0.0",
84
- "@types/testing-library__jest-dom": "5.9.5",
85
- "@teambit/component.content.component-overview": "1.95.0"
78
+ "@types/jest": "^29.2.2",
79
+ "@types/testing-library__jest-dom": "^5.9.5",
80
+ "@teambit/component.content.component-overview": "1.95.0",
81
+ "@teambit/harmony.envs.core-aspect-env": "0.0.13"
86
82
  },
87
83
  "peerDependencies": {
88
84
  "@apollo/client": "^3.6.0",
89
- "react-router-dom": "^6.0.0",
90
- "@teambit/legacy": "1.0.624",
91
- "react": "^16.8.0 || ^17.0.0",
92
- "react-dom": "^16.8.0 || ^17.0.0"
85
+ "react": "^17.0.0 || ^18.0.0",
86
+ "react-router-dom": "^6.8.1",
87
+ "@types/react": "^18.2.12",
88
+ "@teambit/legacy": "1.0.624"
93
89
  },
94
90
  "license": "Apache-2.0",
95
91
  "optionalDependencies": {},
@@ -103,7 +99,7 @@
103
99
  },
104
100
  "private": false,
105
101
  "engines": {
106
- "node": ">=12.22.0"
102
+ "node": ">=16.0.0"
107
103
  },
108
104
  "repository": {
109
105
  "type": "git",
@@ -112,12 +108,9 @@
112
108
  "keywords": [
113
109
  "bit",
114
110
  "bit-aspect",
111
+ "bit-core-aspect",
115
112
  "components",
116
113
  "collaboration",
117
- "web",
118
- "react",
119
- "react-components",
120
- "angular",
121
- "angular-components"
114
+ "web"
122
115
  ]
123
116
  }
package/state.ts ADDED
@@ -0,0 +1,88 @@
1
+ import { IssuesList } from '@teambit/component-issues';
2
+ import { ComponentID } from '@teambit/component-id';
3
+ import ComponentFS from './component-fs';
4
+ import { Config } from './config';
5
+ import { AspectList } from './aspect-list';
6
+ import { MainFileNotFound } from './exceptions';
7
+
8
+ export class State {
9
+ constructor(
10
+ /**
11
+ * component configuration which is later generated to a component `package.json` and `bit.json`.
12
+ * @deprecated please use `aspects` instead.
13
+ */
14
+ readonly config: Config,
15
+
16
+ /**
17
+ * list of aspects configured on the component.
18
+ */
19
+ private _aspects: AspectList,
20
+
21
+ /**
22
+ * in-memory representation of the component current filesystem.
23
+ */
24
+ readonly filesystem: ComponentFS,
25
+
26
+ /**
27
+ * dependency graph of the component current. ideally package dependencies would be also placed here.
28
+ */
29
+ // readonly dependencies: Dependencies
30
+ readonly dependencies,
31
+
32
+ /**
33
+ * instance of legacy consumer component.
34
+ */
35
+ readonly _consumer: any
36
+ ) {}
37
+
38
+ /**
39
+ * get the main file of the component.
40
+ */
41
+ get mainFile() {
42
+ const file = this.filesystem.files.find((componentFile) => {
43
+ return componentFile.relative === this._consumer.mainFile;
44
+ });
45
+
46
+ if (!file) throw new MainFileNotFound(ComponentID.fromLegacy(this._consumer.id), this._consumer.mainFile);
47
+
48
+ return file;
49
+ }
50
+
51
+ /**
52
+ * calculate the hash of this state
53
+ */
54
+ get hash() {
55
+ return '';
56
+ }
57
+
58
+ get issues(): IssuesList {
59
+ return (this._consumer.issues ||= new IssuesList());
60
+ }
61
+
62
+ /**
63
+ * @deprecated please use `component.isModified`.
64
+ * the way it's implemented here is unreliable and will only work if in the legacy the "isModified" was calculated.
65
+ */
66
+ get isModified(): boolean {
67
+ return this._consumer._isModified;
68
+ }
69
+
70
+ get aspects(): AspectList {
71
+ return this._aspects;
72
+ }
73
+
74
+ set aspects(aspects: AspectList) {
75
+ this._aspects = aspects;
76
+ }
77
+
78
+ // static fromLegacy(consumerComponent: ConsumerComponent) {
79
+ // return new State(
80
+ // new Config(consumerComponent.mainFile, consumerComponent.extensions),
81
+ // consumerComponent.version || 'new',
82
+ // ComponentFS.fromVinyls(consumerComponent.files),
83
+ // Store.fromArray([]),
84
+ // consumerComponent.dependencies,
85
+ // consumerComponent
86
+ // );
87
+ // }
88
+ }
package/store.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { ExtensionDataList } from '@teambit/legacy/dist/consumer/config/extension-data';
2
+
3
+ export class Store extends ExtensionDataList {}
package/tag-map.ts ADDED
@@ -0,0 +1,87 @@
1
+ import { getLatestVersion } from '@teambit/legacy/dist/utils/semver-helper';
2
+ import { SemVer, maxSatisfying } from 'semver';
3
+
4
+ import { CouldNotFindLatest } from './exceptions';
5
+ import { Hash } from './hash';
6
+ import { Tag } from './tag';
7
+
8
+ export class TagMap extends Map<SemVer, Tag> {
9
+ /**
10
+ * get snap by hash.
11
+ */
12
+ byHash(hash: Hash) {
13
+ const tag = Array.from(this.values()).find((currTag) => currTag.hash === hash);
14
+ return tag;
15
+ }
16
+
17
+ /**
18
+ * e.g.
19
+ * {
20
+ * alpha: '1.0.0-alpha.5',
21
+ * dev: '2.2.4-dev.37
22
+ * }
23
+ */
24
+ getPreReleaseLatestTags(): { [preRelease: string]: string } {
25
+ const preReleaseTagsWithAllVersions = this.toArray().reduce((acc, current) => {
26
+ const preReleases = current.version.prerelease;
27
+ if (!preReleases.length) return acc;
28
+ if (preReleases.length !== 2) {
29
+ // it could be length 1, e.g. 1.0.0-0, we ignore it.
30
+ // it could also be length > 2, e.g. 1.0.0-dev.1.alpha.1, we don't support it for now.
31
+ return acc;
32
+ }
33
+ if (typeof preReleases[0] !== 'string') return acc;
34
+ (acc[preReleases[0]] ||= []).push(current.version.raw);
35
+ return acc;
36
+ }, {});
37
+ return Object.keys(preReleaseTagsWithAllVersions).reduce((acc, current) => {
38
+ acc[current] = maxSatisfying<string>(preReleaseTagsWithAllVersions[current], '*', { includePrerelease: true });
39
+ return acc;
40
+ }, {});
41
+ }
42
+
43
+ /**
44
+ * Get a map that map snap hash to tag
45
+ */
46
+ getHashMap(): Map<Hash, Tag> {
47
+ const res: Map<Hash, Tag> = new Map();
48
+ this.forEach((tag: Tag) => {
49
+ res.set(tag.hash, tag);
50
+ });
51
+ return res;
52
+ }
53
+
54
+ /**
55
+ * get the latest semver from the tag map.
56
+ */
57
+ getLatest(): string {
58
+ const versions = this.toArray().map((tag) => tag.version.raw);
59
+ if (this.isEmpty()) throw new CouldNotFindLatest(versions);
60
+ return getLatestVersion(versions);
61
+ }
62
+
63
+ isEmpty() {
64
+ return this.size === 0;
65
+ }
66
+
67
+ /**
68
+ * get an array of all tags.
69
+ */
70
+ toArray(): Tag[] {
71
+ return Array.from(this.values());
72
+ }
73
+
74
+ byVersion(version: string): Tag | undefined {
75
+ const versions = this.toArray().map((tag) => tag);
76
+ return versions.find((tag) => tag.version.raw === version);
77
+ }
78
+
79
+ static fromArray(tags: Tag[]) {
80
+ const tuples: [SemVer, Tag][] = tags.map((tag) => [tag.version, tag]);
81
+ return new TagMap(tuples);
82
+ }
83
+
84
+ static empty() {
85
+ return new TagMap();
86
+ }
87
+ }
package/tsconfig.json CHANGED
@@ -1,38 +1,33 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "lib": [
4
- "es2019",
5
- "DOM",
6
- "ES6",
7
- "DOM.Iterable",
8
- "ScriptHost"
4
+ "esnext",
5
+ "dom",
6
+ "dom.Iterable"
9
7
  ],
10
- "target": "es2015",
11
- "module": "CommonJS",
12
- "jsx": "react",
13
- "allowJs": true,
14
- "composite": true,
8
+ "target": "es2020",
9
+ "module": "es2020",
10
+ "jsx": "react-jsx",
15
11
  "declaration": true,
16
12
  "sourceMap": true,
17
- "skipLibCheck": true,
18
13
  "experimentalDecorators": true,
19
- "outDir": "dist",
14
+ "skipLibCheck": true,
20
15
  "moduleResolution": "node",
21
16
  "esModuleInterop": true,
22
- "rootDir": ".",
23
17
  "resolveJsonModule": true,
24
- "emitDeclarationOnly": true,
25
- "emitDecoratorMetadata": true,
26
- "allowSyntheticDefaultImports": true,
27
- "strictPropertyInitialization": false,
28
- "strict": true,
29
- "noImplicitAny": false,
30
- "preserveConstEnums": true
18
+ "allowJs": true,
19
+ "outDir": "dist",
20
+ "emitDeclarationOnly": true
31
21
  },
32
22
  "exclude": [
23
+ "artifacts",
24
+ "public",
33
25
  "dist",
26
+ "node_modules",
27
+ "package.json",
34
28
  "esm.mjs",
35
- "package.json"
29
+ "**/*.cjs",
30
+ "./dist"
36
31
  ],
37
32
  "include": [
38
33
  "**/*",
package/types/asset.d.ts CHANGED
@@ -5,12 +5,12 @@ declare module '*.png' {
5
5
  declare module '*.svg' {
6
6
  import type { FunctionComponent, SVGProps } from 'react';
7
7
 
8
- export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
8
+ export const ReactComponent: FunctionComponent<
9
+ SVGProps<SVGSVGElement> & { title?: string }
10
+ >;
9
11
  const src: string;
10
12
  export default src;
11
13
  }
12
-
13
- // @TODO Gilad
14
14
  declare module '*.jpg' {
15
15
  const value: any;
16
16
  export = value;
@@ -27,3 +27,15 @@ declare module '*.bmp' {
27
27
  const value: any;
28
28
  export = value;
29
29
  }
30
+ declare module '*.otf' {
31
+ const value: any;
32
+ export = value;
33
+ }
34
+ declare module '*.woff' {
35
+ const value: any;
36
+ export = value;
37
+ }
38
+ declare module '*.woff2' {
39
+ const value: any;
40
+ export = value;
41
+ }