@teambit/component 0.0.927 → 0.0.928
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/{preview-1670414621516.js → preview-1670470092710.js} +2 -2
- package/dist/ui/top-bar-nav/top-bar-nav.js +1 -1
- package/dist/ui/top-bar-nav/top-bar-nav.js.map +1 -1
- package/dist/ui/use-component-query.d.ts +1 -1
- package/dist/ui/use-component-query.js +3 -2
- package/dist/ui/use-component-query.js.map +1 -1
- package/dist/ui/use-component.d.ts +2 -1
- package/dist/ui/use-component.js +4 -4
- package/dist/ui/use-component.js.map +1 -1
- package/package-tar/teambit-component-0.0.928.tgz +0 -0
- package/package.json +28 -28
- package/ui/top-bar-nav/top-bar-nav.tsx +1 -1
- package/ui/use-component-query.ts +2 -1
- package/ui/use-component.tsx +5 -6
- package/package-tar/teambit-component-0.0.927.tgz +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component@0.0.
|
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component@0.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component@0.0.928/dist/component.composition.js';
|
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component@0.0.928/dist/component.docs.mdx';
|
|
3
3
|
|
|
4
4
|
export const compositions = [compositions_0];
|
|
5
5
|
export const overview = [overview_0];
|
|
@@ -73,7 +73,7 @@ function TopBarNav(_ref) {
|
|
|
73
73
|
// but not for regular menu links (overview, compositions, etc).
|
|
74
74
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
75
75
|
const preventPassingDisplayNameToLink = displayName;
|
|
76
|
-
const target = `${href}${search}`;
|
|
76
|
+
const target = href && `${href}${search}`;
|
|
77
77
|
return /*#__PURE__*/_react().default.createElement(_baseReactNavigation().Link, (0, _extends2().default)({}, rest, {
|
|
78
78
|
className: (0, _classnames().default)(className, _topBarNavModule().default.topBarLink),
|
|
79
79
|
activeClassName: (0, _classnames().default)(activeClassName, _topBarNavModule().default.active),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TopBarNav","href","className","activeClassName","children","displayName","rest","search","useLocation","preventPassingDisplayNameToLink","target","classnames","styles","topBarLink","active"],"sources":["top-bar-nav.tsx"],"sourcesContent":["import React from 'react';\nimport classnames from 'classnames';\nimport { useLocation } from 'react-router-dom';\nimport { Link } from '@teambit/base-react.navigation.link';\nimport { NavPluginProps } from '../menu/nav-plugin';\n\nimport styles from './top-bar-nav.module.scss';\n\nexport function TopBarNav({ href, className, activeClassName, children, displayName, ...rest }: NavPluginProps) {\n const { search } = useLocation(); // sticky query params\n\n // @hack - this is so that the displayName will not pass to the link and cause a warning in the console.\n // it is used for component page nav link widgets (code, aspects etc),\n // but not for regular menu links (overview, compositions, etc).\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const preventPassingDisplayNameToLink = displayName;\n\n const target = `${href}${search}`;\n\n return (\n <Link\n {...rest}\n className={classnames(className, styles.topBarLink)}\n activeClassName={classnames(activeClassName, styles.active)}\n href={target}\n >\n <div>{children}</div>\n </Link>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,SAASA,SAAS,OAAuF;EAAA,IAAtF;MAAEC,IAAI;MAAEC,SAAS;MAAEC,eAAe;MAAEC,QAAQ;MAAEC;IAAqC,CAAC;IAAtBC,IAAI;EAC1F,MAAM;IAAEC;EAAO,CAAC,GAAG,IAAAC,6BAAW,GAAE,CAAC,CAAC;;EAElC;EACA;EACA;EACA;EACA,MAAMC,+BAA+B,GAAGJ,WAAW;EAEnD,MAAMK,MAAM,
|
|
1
|
+
{"version":3,"names":["TopBarNav","href","className","activeClassName","children","displayName","rest","search","useLocation","preventPassingDisplayNameToLink","target","classnames","styles","topBarLink","active"],"sources":["top-bar-nav.tsx"],"sourcesContent":["import React from 'react';\nimport classnames from 'classnames';\nimport { useLocation } from 'react-router-dom';\nimport { Link } from '@teambit/base-react.navigation.link';\nimport { NavPluginProps } from '../menu/nav-plugin';\n\nimport styles from './top-bar-nav.module.scss';\n\nexport function TopBarNav({ href, className, activeClassName, children, displayName, ...rest }: NavPluginProps) {\n const { search } = useLocation(); // sticky query params\n\n // @hack - this is so that the displayName will not pass to the link and cause a warning in the console.\n // it is used for component page nav link widgets (code, aspects etc),\n // but not for regular menu links (overview, compositions, etc).\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const preventPassingDisplayNameToLink = displayName;\n\n const target = href && `${href}${search}`;\n\n return (\n <Link\n {...rest}\n className={classnames(className, styles.topBarLink)}\n activeClassName={classnames(activeClassName, styles.active)}\n href={target}\n >\n <div>{children}</div>\n </Link>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,SAASA,SAAS,OAAuF;EAAA,IAAtF;MAAEC,IAAI;MAAEC,SAAS;MAAEC,eAAe;MAAEC,QAAQ;MAAEC;IAAqC,CAAC;IAAtBC,IAAI;EAC1F,MAAM;IAAEC;EAAO,CAAC,GAAG,IAAAC,6BAAW,GAAE,CAAC,CAAC;;EAElC;EACA;EACA;EACA;EACA,MAAMC,+BAA+B,GAAGJ,WAAW;EAEnD,MAAMK,MAAM,GAAGT,IAAI,IAAK,GAAEA,IAAK,GAAEM,MAAO,EAAC;EAEzC,oBACE,+BAAC,2BAAI,+BACCD,IAAI;IACR,SAAS,EAAE,IAAAK,qBAAU,EAACT,SAAS,EAAEU,0BAAM,CAACC,UAAU,CAAE;IACpD,eAAe,EAAE,IAAAF,qBAAU,EAACR,eAAe,EAAES,0BAAM,CAACE,MAAM,CAAE;IAC5D,IAAI,EAAEJ;EAAO,iBAEb,4CAAMN,QAAQ,CAAO,CAChB;AAEX"}
|
|
@@ -14,7 +14,7 @@ export declare type Filters = {
|
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
16
|
/** provides data to component ui page, making sure both variables and return value are safely typed and memoized */
|
|
17
|
-
export declare function useComponentQuery(componentId: string, host: string, filters?: Filters): {
|
|
17
|
+
export declare function useComponentQuery(componentId: string, host: string, filters?: Filters, skip?: boolean): {
|
|
18
18
|
client: import("@apollo/client").ApolloClient<any>;
|
|
19
19
|
observable: import("@apollo/client").ObservableQuery<any, {
|
|
20
20
|
logType?: string | undefined;
|
|
@@ -209,7 +209,7 @@ const SUB_COMPONENT_REMOVED = (0, _client().gql)`
|
|
|
209
209
|
${componentIdFields}
|
|
210
210
|
`;
|
|
211
211
|
/** provides data to component ui page, making sure both variables and return value are safely typed and memoized */
|
|
212
|
-
function useComponentQuery(componentId, host, filters) {
|
|
212
|
+
function useComponentQuery(componentId, host, filters, skip) {
|
|
213
213
|
var _data$getHost;
|
|
214
214
|
const idRef = (0, _react().useRef)(componentId);
|
|
215
215
|
idRef.current = componentId;
|
|
@@ -217,7 +217,8 @@ function useComponentQuery(componentId, host, filters) {
|
|
|
217
217
|
variables: _objectSpread({
|
|
218
218
|
id: componentId,
|
|
219
219
|
extensionId: host
|
|
220
|
-
}, (filters === null || filters === void 0 ? void 0 : filters.log) || {})
|
|
220
|
+
}, (filters === null || filters === void 0 ? void 0 : filters.log) || {}),
|
|
221
|
+
skip
|
|
221
222
|
}),
|
|
222
223
|
{
|
|
223
224
|
data,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["componentIdFields","gql","componentOverviewFields","componentFields","GET_COMPONENT","SUB_SUBSCRIPTION_ADDED","SUB_COMPONENT_CHANGED","SUB_COMPONENT_REMOVED","useComponentQuery","componentId","host","filters","idRef","useRef","current","useDataQuery","variables","id","extensionId","log","data","error","loading","subscribeToMore","rest","useEffect","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","useMemo","aspectList","entries","aspects","map","aspectObject","aspectId","aspectData","fromObject","componentDescriptor","ComponentDescriptor","toString","undefined","ComponentModel","from","ComponentError","message"],"sources":["use-component-query.ts"],"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\nexport const componentIdFields = gql`\n fragment componentIdFields on ComponentID {\n name\n version\n scope\n }\n`;\n\nexport const componentOverviewFields = gql`\n fragment componentOverviewFields on Component {\n id {\n ...componentIdFields\n }\n aspects(include: [\"teambit.preview/preview\", \"teambit.envs/envs\"]) {\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 id\n data\n }\n elementsUrl\n description\n deprecation {\n isDeprecate\n newId\n }\n labels\n displayName\n server {\n env\n url\n }\n buildStatus\n env {\n id\n icon\n }\n size {\n compressedTotal\n }\n preview {\n includesEnvTemplate\n legacyHeader\n isScaling\n }\n compositions {\n identifier\n displayName\n }\n }\n ${componentIdFields}\n`;\n\nexport const componentFields = gql`\n fragment componentFields on Component {\n id {\n ...componentIdFields\n }\n ...componentOverviewFields\n packageName\n latest\n compositions {\n identifier\n displayName\n }\n tags {\n version\n }\n logs(type: $logType, offset: $logOffset, limit: $logLimit, head: $logHead, sort: $logSort) {\n id\n message\n username\n email\n date\n hash\n tag\n }\n }\n ${componentIdFields}\n ${componentOverviewFields}\n`;\n\nconst GET_COMPONENT = gql`\n query Component(\n $id: String!\n $extensionId: String!\n $logType: String\n $logOffset: Int\n $logLimit: Int\n $logHead: String\n $logSort: String\n ) {\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, $logHead: String, $logSort: String) {\n componentAdded {\n component {\n ...componentFields\n }\n }\n }\n ${componentFields}\n`;\n\nconst SUB_COMPONENT_CHANGED = gql`\n subscription OnComponentChanged(\n $logType: String\n $logOffset: Int\n $logLimit: Int\n $logHead: String\n $logSort: String\n ) {\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`;\nexport type Filters = {\n log?: { logType?: string; logOffset?: number; logLimit?: number; logHead?: string; logSort?: string };\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, filters?: Filters) {\n const idRef = useRef(componentId);\n idRef.current = componentId;\n const { data, error, loading, subscribeToMore, ...rest } = useDataQuery(GET_COMPONENT, {\n variables: { id: componentId, extensionId: host, ...(filters?.log || {}) },\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((aspectObject) => {\n return {\n ...aspectObject,\n aspectId: aspectObject.id,\n aspectData: aspectObject.data,\n };\n }),\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 loading,\n ...rest,\n };\n }, [rawComponent, host, error]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAAmD;AAAA;AAE5C,MAAMA,iBAAiB,GAAG,IAAAC,aAAG,CAAC;AACrC;AACA;AACA;AACA;AACA;AACA,CAAC;AAAC;AAEK,MAAMC,uBAAuB,GAAG,IAAAD,aAAG,CAAC;AAC3C;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,CAAC;AAAC;AAEK,MAAMG,eAAe,GAAG,IAAAF,aAAG,CAAC;AACnC;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,IAAIE,uBAAwB;AAC5B,CAAC;AAAC;AAEF,MAAME,aAAa,GAAG,IAAAH,aAAG,CAAC;AAC1B;AACA;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C,QAAQ,EAAED,YAAY,CAACzC,EAAE;UACzB2C,UAAU,EAAEF,YAAY,CAACtC;QAAI;MAEjC,CAAC;IACH,CAAC;IACD,MAAMH,EAAE,GAAGmC,YAAY,IAAIV,0BAAW,CAACmB,UAAU,CAACT,YAAY,CAACnC,EAAE,CAAC;IAClE;MACE6C,mBAAmB,EAAE7C,EAAE,GAAG8C,0CAAmB,CAACF,UAAU,CAAC;QAAE5C,EAAE,EAAEA,EAAE,CAAC+C,QAAQ,EAAE;QAAEV;MAAW,CAAC,CAAC,GAAGW,SAAS;MACvG7B,SAAS,EAAEgB,YAAY,GAAGc,gCAAc,CAACC,IAAI,iCAAMf,YAAY;QAAE1C;MAAI,GAAG,GAAGuD,SAAS;MACpF;MACA5C,KAAK,EAAEA,KAAK,GACR,KAAI+C,gCAAc,EAAC,GAAG,EAAE/C,KAAK,CAACgD,OAAO,CAAC,GACtC,CAACjB,YAAY,IAAI,CAAC9B,OAAO,GACzB,KAAI8C,gCAAc,EAAC,GAAG,CAAC,GACvBH,SAAS;MACb3C;IAAO,GACJE,IAAI;EAEX,CAAC,EAAE,CAAC4B,YAAY,EAAE1C,IAAI,EAAEW,KAAK,CAAC,CAAC;AACjC"}
|
|
1
|
+
{"version":3,"names":["componentIdFields","gql","componentOverviewFields","componentFields","GET_COMPONENT","SUB_SUBSCRIPTION_ADDED","SUB_COMPONENT_CHANGED","SUB_COMPONENT_REMOVED","useComponentQuery","componentId","host","filters","skip","idRef","useRef","current","useDataQuery","variables","id","extensionId","log","data","error","loading","subscribeToMore","rest","useEffect","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","useMemo","aspectList","entries","aspects","map","aspectObject","aspectId","aspectData","fromObject","componentDescriptor","ComponentDescriptor","toString","undefined","ComponentModel","from","ComponentError","message"],"sources":["use-component-query.ts"],"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\nexport const componentIdFields = gql`\n fragment componentIdFields on ComponentID {\n name\n version\n scope\n }\n`;\n\nexport const componentOverviewFields = gql`\n fragment componentOverviewFields on Component {\n id {\n ...componentIdFields\n }\n aspects(include: [\"teambit.preview/preview\", \"teambit.envs/envs\"]) {\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 id\n data\n }\n elementsUrl\n description\n deprecation {\n isDeprecate\n newId\n }\n labels\n displayName\n server {\n env\n url\n }\n buildStatus\n env {\n id\n icon\n }\n size {\n compressedTotal\n }\n preview {\n includesEnvTemplate\n legacyHeader\n isScaling\n }\n compositions {\n identifier\n displayName\n }\n }\n ${componentIdFields}\n`;\n\nexport const componentFields = gql`\n fragment componentFields on Component {\n id {\n ...componentIdFields\n }\n ...componentOverviewFields\n packageName\n latest\n compositions {\n identifier\n displayName\n }\n tags {\n version\n }\n logs(type: $logType, offset: $logOffset, limit: $logLimit, head: $logHead, sort: $logSort) {\n id\n message\n username\n email\n date\n hash\n tag\n }\n }\n ${componentIdFields}\n ${componentOverviewFields}\n`;\n\nconst GET_COMPONENT = gql`\n query Component(\n $id: String!\n $extensionId: String!\n $logType: String\n $logOffset: Int\n $logLimit: Int\n $logHead: String\n $logSort: String\n ) {\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, $logHead: String, $logSort: String) {\n componentAdded {\n component {\n ...componentFields\n }\n }\n }\n ${componentFields}\n`;\n\nconst SUB_COMPONENT_CHANGED = gql`\n subscription OnComponentChanged(\n $logType: String\n $logOffset: Int\n $logLimit: Int\n $logHead: String\n $logSort: String\n ) {\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`;\nexport type Filters = {\n log?: { logType?: string; logOffset?: number; logLimit?: number; logHead?: string; logSort?: string };\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, filters?: Filters, skip?: boolean) {\n const idRef = useRef(componentId);\n idRef.current = componentId;\n const { data, error, loading, subscribeToMore, ...rest } = useDataQuery(GET_COMPONENT, {\n variables: { id: componentId, extensionId: host, ...(filters?.log || {}) },\n skip,\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((aspectObject) => {\n return {\n ...aspectObject,\n aspectId: aspectObject.id,\n aspectData: aspectObject.data,\n };\n }),\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 loading,\n ...rest,\n };\n }, [rawComponent, host, error]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAAmD;AAAA;AAE5C,MAAMA,iBAAiB,GAAG,IAAAC,aAAG,CAAC;AACrC;AACA;AACA;AACA;AACA;AACA,CAAC;AAAC;AAEK,MAAMC,uBAAuB,GAAG,IAAAD,aAAG,CAAC;AAC3C;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,CAAC;AAAC;AAEK,MAAMG,eAAe,GAAG,IAAAF,aAAG,CAAC;AACnC;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,IAAIE,uBAAwB;AAC5B,CAAC;AAAC;AAEF,MAAME,aAAa,GAAG,IAAAH,aAAG,CAAC;AAC1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIE,eAAgB;AACpB,CAAC;AAED,MAAME,sBAAsB,GAAG,IAAAJ,aAAG,CAAC;AACnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIE,eAAgB;AACpB,CAAC;AAED,MAAMG,qBAAqB,GAAG,IAAAL,aAAG,CAAC;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIE,eAAgB;AACpB,CAAC;AAED,MAAMI,qBAAqB,GAAG,IAAAN,aAAG,CAAC;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAID,iBAAkB;AACtB,CAAC;AAID;AACO,SAASQ,iBAAiB,CAACC,WAAmB,EAAEC,IAAY,EAAEC,OAAiB,EAAEC,IAAc,EAAE;EAAA;EACtG,MAAMC,KAAK,GAAG,IAAAC,eAAM,EAACL,WAAW,CAAC;EACjCI,KAAK,CAACE,OAAO,GA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c,EAAC,GAAG,CAAC,GACvBH,SAAS;MACb3C;IAAO,GACJE,IAAI;EAEX,CAAC,EAAE,CAAC4B,YAAY,EAAE3C,IAAI,EAAEY,KAAK,CAAC,CAAC;AACjC"}
|
|
@@ -12,6 +12,7 @@ export declare type UseComponentOptions = {
|
|
|
12
12
|
version?: string;
|
|
13
13
|
logFilters?: Filters;
|
|
14
14
|
customUseComponent?: UseComponentType;
|
|
15
|
+
skip?: boolean;
|
|
15
16
|
};
|
|
16
|
-
export declare type UseComponentType = (id: string, host: string, filters?: Filters) => Component;
|
|
17
|
+
export declare type UseComponentType = (id: string, host: string, filters?: Filters, skip?: boolean) => Component;
|
|
17
18
|
export declare function useComponent(host: string, id?: string, options?: UseComponentOptions): Component;
|
package/dist/ui/use-component.js
CHANGED
|
@@ -24,13 +24,13 @@ function useComponent(host, id, options) {
|
|
|
24
24
|
const {
|
|
25
25
|
version,
|
|
26
26
|
logFilters,
|
|
27
|
-
customUseComponent
|
|
27
|
+
customUseComponent,
|
|
28
|
+
skip
|
|
28
29
|
} = options || {};
|
|
29
30
|
const componentVersion = (_ref = version || query.get('version')) !== null && _ref !== void 0 ? _ref : undefined;
|
|
30
|
-
|
|
31
|
-
const componentIdStr = withVersion(id, componentVersion);
|
|
31
|
+
const componentIdStr = id && withVersion(id, componentVersion);
|
|
32
32
|
const targetUseComponent = customUseComponent || _useComponentQuery().useComponentQuery;
|
|
33
|
-
return targetUseComponent(componentIdStr, host, logFilters);
|
|
33
|
+
return targetUseComponent(componentIdStr || '', host, logFilters, skip || !id);
|
|
34
34
|
}
|
|
35
35
|
function withVersion(id, version) {
|
|
36
36
|
if (!version) return id;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useComponent","host","id","options","query","useQuery","version","logFilters","customUseComponent","componentVersion","get","undefined","
|
|
1
|
+
{"version":3,"names":["useComponent","host","id","options","query","useQuery","version","logFilters","customUseComponent","skip","componentVersion","get","undefined","componentIdStr","withVersion","targetUseComponent","useComponentQuery","includes"],"sources":["use-component.tsx"],"sourcesContent":["import { 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 { Filters, useComponentQuery } from './use-component-query';\n\nexport type Component = {\n component?: ComponentModel;\n error?: ComponentError;\n componentDescriptor?: ComponentDescriptor;\n loading?: boolean;\n};\nexport type UseComponentOptions = {\n version?: string;\n logFilters?: Filters;\n customUseComponent?: UseComponentType;\n skip?: boolean;\n};\n\nexport type UseComponentType = (id: string, host: string, filters?: Filters, skip?: boolean) => Component;\n\nexport function useComponent(host: string, id?: string, options?: UseComponentOptions): Component {\n const query = useQuery();\n const { version, logFilters, customUseComponent, skip } = options || {};\n const componentVersion = (version || query.get('version')) ?? undefined;\n\n const componentIdStr = id && withVersion(id, componentVersion);\n const targetUseComponent = customUseComponent || useComponentQuery;\n\n return targetUseComponent(componentIdStr || '', host, logFilters, skip || !id);\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"],"mappings":";;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAIA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAiBO,SAASA,YAAY,CAACC,IAAY,EAAEC,EAAW,EAAEC,OAA6B,EAAa;EAAA;EAChG,MAAMC,KAAK,GAAG,IAAAC,qCAAQ,GAAE;EACxB,MAAM;IAAEC,OAAO;IAAEC,UAAU;IAAEC,kBAAkB;IAAEC;EAAK,CAAC,GAAGN,OAAO,IAAI,CAAC,CAAC;EACvE,MAAMO,gBAAgB,WAAIJ,OAAO,IAAIF,KAAK,CAACO,GAAG,CAAC,SAAS,CAAC,uCAAKC,SAAS;EAEvE,MAAMC,cAAc,GAAGX,EAAE,IAAIY,WAAW,CAACZ,EAAE,EAAEQ,gBAAgB,CAAC;EAC9D,MAAMK,kBAAkB,GAAGP,kBAAkB,IAAIQ,sCAAiB;EAElE,OAAOD,kBAAkB,CAACF,cAAc,IAAI,EAAE,EAAEZ,IAAI,EAAEM,UAAU,EAAEE,IAAI,IAAI,CAACP,EAAE,CAAC;AAChF;AAEA,SAASY,WAAW,CAACZ,EAAU,EAAEI,OAAgB,EAAE;EACjD,IAAI,CAACA,OAAO,EAAE,OAAOJ,EAAE;EACvB,IAAIA,EAAE,CAACe,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAOf,EAAE;EAC/B,OAAQ,GAAEA,EAAG,IAAGI,OAAQ,EAAC;AAC3B"}
|
|
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.928",
|
|
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.928"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@teambit/any-fs": "0.0.5",
|
|
@@ -26,50 +26,50 @@
|
|
|
26
26
|
"@teambit/base-react.navigation.link": "2.0.27",
|
|
27
27
|
"@teambit/documenter.ui.heading": "4.1.1",
|
|
28
28
|
"@teambit/documenter.ui.separator": "4.1.1",
|
|
29
|
+
"@teambit/explorer.ui.command-bar": "2.0.3",
|
|
29
30
|
"@teambit/design.navigation.responsive-navbar": "0.0.2",
|
|
30
31
|
"@teambit/base-ui.layout.breakpoints": "1.0.0",
|
|
31
|
-
"@teambit/explorer.ui.command-bar": "2.0.3",
|
|
32
32
|
"@teambit/component-id": "0.0.425",
|
|
33
33
|
"@teambit/ui-foundation.ui.menu-widget-icon": "0.0.497",
|
|
34
|
-
"@teambit/aspect-loader": "0.0.
|
|
35
|
-
"@teambit/graph": "0.0.
|
|
34
|
+
"@teambit/aspect-loader": "0.0.928",
|
|
35
|
+
"@teambit/graph": "0.0.928",
|
|
36
36
|
"@teambit/legacy-bit-id": "0.0.421",
|
|
37
37
|
"@teambit/toolbox.path.match-patterns": "0.0.9",
|
|
38
38
|
"@teambit/toolbox.string.capitalize": "0.0.490",
|
|
39
|
-
"@teambit/cli": "0.0.
|
|
40
|
-
"@teambit/express": "0.0.
|
|
41
|
-
"@teambit/graphql": "0.0.
|
|
39
|
+
"@teambit/cli": "0.0.621",
|
|
40
|
+
"@teambit/express": "0.0.719",
|
|
41
|
+
"@teambit/graphql": "0.0.928",
|
|
42
42
|
"@teambit/bit-error": "0.0.402",
|
|
43
|
-
"@teambit/command-bar": "0.0.
|
|
43
|
+
"@teambit/command-bar": "0.0.928",
|
|
44
44
|
"@teambit/component.ui.deprecation-icon": "0.0.503",
|
|
45
|
-
"@teambit/preview": "0.0.
|
|
46
|
-
"@teambit/pubsub": "0.0.
|
|
47
|
-
"@teambit/react-router": "0.0.
|
|
45
|
+
"@teambit/preview": "0.0.928",
|
|
46
|
+
"@teambit/pubsub": "0.0.928",
|
|
47
|
+
"@teambit/react-router": "0.0.928",
|
|
48
48
|
"@teambit/ui-foundation.ui.is-browser": "0.0.495",
|
|
49
49
|
"@teambit/ui-foundation.ui.main-dropdown": "0.0.496",
|
|
50
|
-
"@teambit/ui-foundation.ui.react-router.slot-router": "0.0.
|
|
50
|
+
"@teambit/ui-foundation.ui.react-router.slot-router": "0.0.500",
|
|
51
51
|
"@teambit/ui-foundation.ui.use-box.menu": "0.0.129",
|
|
52
|
-
"@teambit/ui": "0.0.
|
|
52
|
+
"@teambit/ui": "0.0.928",
|
|
53
53
|
"@teambit/component-issues": "0.0.83",
|
|
54
54
|
"@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.500",
|
|
55
55
|
"@teambit/cli-table": "0.0.41",
|
|
56
|
-
"@teambit/component-descriptor": "0.0.
|
|
56
|
+
"@teambit/component-descriptor": "0.0.191",
|
|
57
57
|
"@teambit/ui-foundation.ui.react-router.use-query": "0.0.496",
|
|
58
|
-
"@teambit/design.ui.pages.not-found": "0.0.366",
|
|
59
|
-
"@teambit/design.ui.pages.server-error": "0.0.366",
|
|
60
|
-
"@teambit/compositions": "0.0.927",
|
|
61
|
-
"@teambit/deprecation": "0.0.927",
|
|
62
|
-
"@teambit/envs": "0.0.927",
|
|
63
|
-
"@teambit/legacy-component-log": "0.0.399",
|
|
64
58
|
"@teambit/design.ui.empty-box": "0.0.363",
|
|
65
59
|
"@teambit/harmony.ui.aspect-box": "0.0.497",
|
|
66
|
-
"@teambit/
|
|
67
|
-
"@teambit/
|
|
68
|
-
"@teambit/
|
|
69
|
-
"@teambit/
|
|
70
|
-
"@teambit/
|
|
60
|
+
"@teambit/compositions": "0.0.928",
|
|
61
|
+
"@teambit/deprecation": "0.0.928",
|
|
62
|
+
"@teambit/envs": "0.0.928",
|
|
63
|
+
"@teambit/legacy-component-log": "0.0.399",
|
|
64
|
+
"@teambit/design.ui.pages.not-found": "0.0.366",
|
|
65
|
+
"@teambit/design.ui.pages.server-error": "0.0.366",
|
|
71
66
|
"@teambit/design.ui.styles.ellipsis": "0.0.357",
|
|
72
|
-
"@teambit/envs.ui.env-icon": "0.0.495"
|
|
67
|
+
"@teambit/envs.ui.env-icon": "0.0.495",
|
|
68
|
+
"@teambit/component.ui.version-dropdown": "0.0.686",
|
|
69
|
+
"@teambit/lanes.hooks.use-lanes": "0.0.84",
|
|
70
|
+
"@teambit/lanes.ui.models.lanes-model": "0.0.46",
|
|
71
|
+
"@teambit/ui-foundation.ui.full-loader": "0.0.495",
|
|
72
|
+
"@teambit/ui-foundation.ui.use-box.dropdown": "0.0.129"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@types/react": "^17.0.8",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"peerDependencies": {
|
|
89
89
|
"react-router-dom": "^6.0.0",
|
|
90
90
|
"@apollo/client": "^3.6.0",
|
|
91
|
-
"@teambit/legacy": "1.0.
|
|
91
|
+
"@teambit/legacy": "1.0.402",
|
|
92
92
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
93
93
|
"react": "^16.8.0 || ^17.0.0"
|
|
94
94
|
},
|
|
@@ -15,7 +15,7 @@ export function TopBarNav({ href, className, activeClassName, children, displayN
|
|
|
15
15
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
16
|
const preventPassingDisplayNameToLink = displayName;
|
|
17
17
|
|
|
18
|
-
const target = `${href}${search}`;
|
|
18
|
+
const target = href && `${href}${search}`;
|
|
19
19
|
|
|
20
20
|
return (
|
|
21
21
|
<Link
|
|
@@ -151,11 +151,12 @@ export type Filters = {
|
|
|
151
151
|
log?: { logType?: string; logOffset?: number; logLimit?: number; logHead?: string; logSort?: string };
|
|
152
152
|
};
|
|
153
153
|
/** provides data to component ui page, making sure both variables and return value are safely typed and memoized */
|
|
154
|
-
export function useComponentQuery(componentId: string, host: string, filters?: Filters) {
|
|
154
|
+
export function useComponentQuery(componentId: string, host: string, filters?: Filters, skip?: boolean) {
|
|
155
155
|
const idRef = useRef(componentId);
|
|
156
156
|
idRef.current = componentId;
|
|
157
157
|
const { data, error, loading, subscribeToMore, ...rest } = useDataQuery(GET_COMPONENT, {
|
|
158
158
|
variables: { id: componentId, extensionId: host, ...(filters?.log || {}) },
|
|
159
|
+
skip,
|
|
159
160
|
});
|
|
160
161
|
|
|
161
162
|
useEffect(() => {
|
package/ui/use-component.tsx
CHANGED
|
@@ -14,21 +14,20 @@ export type UseComponentOptions = {
|
|
|
14
14
|
version?: string;
|
|
15
15
|
logFilters?: Filters;
|
|
16
16
|
customUseComponent?: UseComponentType;
|
|
17
|
+
skip?: boolean;
|
|
17
18
|
};
|
|
18
19
|
|
|
19
|
-
export type UseComponentType = (id: string, host: string, filters?: Filters) => Component;
|
|
20
|
+
export type UseComponentType = (id: string, host: string, filters?: Filters, skip?: boolean) => Component;
|
|
20
21
|
|
|
21
22
|
export function useComponent(host: string, id?: string, options?: UseComponentOptions): Component {
|
|
22
23
|
const query = useQuery();
|
|
23
|
-
const { version, logFilters, customUseComponent } = options || {};
|
|
24
|
+
const { version, logFilters, customUseComponent, skip } = options || {};
|
|
24
25
|
const componentVersion = (version || query.get('version')) ?? undefined;
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const componentIdStr = withVersion(id, componentVersion);
|
|
27
|
+
const componentIdStr = id && withVersion(id, componentVersion);
|
|
29
28
|
const targetUseComponent = customUseComponent || useComponentQuery;
|
|
30
29
|
|
|
31
|
-
return targetUseComponent(componentIdStr, host, logFilters);
|
|
30
|
+
return targetUseComponent(componentIdStr || '', host, logFilters, skip || !id);
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
function withVersion(id: string, version?: string) {
|
|
Binary file
|