@teambit/component 0.0.747 → 0.0.750
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/ui/component-model/component-model.d.ts +1 -0
- package/dist/ui/component-model/component-model.js.map +1 -1
- package/dist/ui/component.js +20 -1
- package/dist/ui/component.js.map +1 -1
- package/dist/ui/menu/menu.js +10 -1
- package/dist/ui/menu/menu.js.map +1 -1
- package/dist/ui/menu/mobile-menu-nav.js +45 -9
- package/dist/ui/menu/mobile-menu-nav.js.map +1 -1
- package/dist/ui/use-component-query.d.ts +4 -3
- package/dist/ui/use-component-query.js +2 -1
- package/dist/ui/use-component-query.js.map +1 -1
- package/dist/ui/use-component.d.ts +6 -2
- package/dist/ui/use-component.js +9 -27
- package/dist/ui/use-component.js.map +1 -1
- package/package-tar/teambit-component-0.0.750.tgz +0 -0
- package/package.json +20 -20
- package/{preview-1653967602594.js → preview-1654226751250.js} +2 -2
- package/tsconfig.json +6 -1
- package/ui/component-model/component-model.ts +1 -0
- package/ui/component.tsx +12 -1
- package/ui/menu/menu.tsx +7 -1
- package/ui/menu/mobile-menu-nav.tsx +40 -13
- package/ui/use-component-query.ts +5 -6
- package/ui/use-component.tsx +11 -24
- package/package-tar/teambit-component-0.0.747.tgz +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ComponentModel","constructor","id","displayName","packageName","server","compositions","tags","buildStatus","issuesCount","elementsUrl","status","deprecation","environment","description","labels","host","latest","preview","logs","version","from","env","ComponentID","fromObject","Composition","fromArray","TagMap","map","tag","Tag","componentsProps","rawComponent","empty","name","scope","url"],"sources":["component-model.ts"],"sourcesContent":["import { Composition, CompositionProps } from '@teambit/compositions';\nimport { DeprecationInfo } from '@teambit/deprecation';\nimport { Descriptor } from '@teambit/envs';\nimport { ComponentID, ComponentIdObj } from '@teambit/component-id';\nimport { LegacyComponentLog } from '@teambit/legacy-component-log';\nimport { Tag } from '../../tag';\nimport { TagMap } from '../../tag-map';\nimport { TagProps } from '../../tag/tag';\n// import { Snap } from '../../snap';\n\n// ADDING MORE PROPERTIES HERE IS NOT ALLOWED!!! IF YOU NEED DATA PLEASE ADD A NEW\n// HOOK FROM YOUR ASPECT!!!\n// TODO: remove all properties from here to their rightful place in their aspects.\nexport type ComponentModelProps = {\n id: ComponentIdObj;\n description: string;\n buildStatus?: string;\n server?: ComponentServer;\n displayName: string;\n packageName: string; // pkg aspect\n elementsUrl?: string; // pkg aspect\n compositions?: CompositionProps[];\n tags?: TagProps[];\n issuesCount?: number; // component/issues aspect\n status?: any; // workspace aspect.\n deprecation?: DeprecationInfo; // deprecation aspect\n env?: Descriptor; // env aspect.\n labels?: string[];\n host?: string;\n latest?: string;\n preview?: ComponentPreview;\n logs?: LegacyComponentLog[];\n};\n\nexport type ComponentPreview = {\n includesEnvTemplate?: boolean;\n};\n\nexport type ComponentServer = {\n env: string;\n url: string;\n};\n\nexport class ComponentModel {\n constructor(\n /**\n * id of the component\n */\n readonly id: ComponentID,\n\n /**\n * display name of the component.\n */\n readonly displayName: string,\n\n /**\n * package name of the component.\n */\n readonly packageName: string,\n\n /**\n * the component server.\n */\n readonly server: ComponentServer | undefined,\n\n /**\n * array of compositions\n */\n readonly compositions: Composition[],\n\n /**\n * tags of the component.\n */\n readonly tags: TagMap,\n\n /**\n * component build status\n */\n readonly buildStatus?: string,\n\n /**\n * issues of component.\n */\n readonly issuesCount?: number,\n /**\n * elements url\n */\n readonly elementsUrl?: string,\n /**\n * status of component.\n */\n readonly status?: any,\n\n /**\n * deprecation info of the component.\n */\n readonly deprecation?: DeprecationInfo,\n\n /**\n * env descriptor.\n */\n readonly environment?: Descriptor,\n\n /**\n * description of the component.\n */\n\n readonly description = '',\n\n readonly labels: string[] = [],\n\n /**\n * host of the component\n */\n readonly host?: string,\n\n /**\n * latest version of component\n */\n readonly latest?: string,\n\n readonly preview?: ComponentPreview,\n\n readonly logs?: LegacyComponentLog[]\n ) {}\n\n get version() {\n if (!this.id.version) return 'new';\n return this.id.version;\n }\n\n /**\n * create an instance of a component from a plain object.\n */\n static from({\n id,\n server,\n displayName,\n compositions = [],\n packageName,\n elementsUrl,\n tags = [],\n deprecation,\n buildStatus,\n env,\n status,\n issuesCount,\n description,\n labels,\n host,\n latest,\n preview,\n logs,\n }: ComponentModelProps) {\n return new ComponentModel(\n ComponentID.fromObject(id),\n displayName,\n packageName,\n server,\n Composition.fromArray(compositions),\n TagMap.fromArray(tags.map((tag) => Tag.fromObject(tag))),\n buildStatus,\n issuesCount,\n elementsUrl,\n status,\n deprecation,\n env,\n description,\n labels,\n host,\n latest,\n preview,\n logs\n );\n }\n\n static fromArray(componentsProps: ComponentModelProps[]) {\n return componentsProps.map((rawComponent) => ComponentModel.from(rawComponent));\n }\n\n static empty() {\n return new ComponentModel(\n ComponentID.fromObject({ name: 'root', scope: 'temp' }),\n '',\n '',\n { env: '', url: '' },\n [],\n TagMap.empty()\n );\n }\n}\n"],"mappings":";;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;
|
|
1
|
+
{"version":3,"names":["ComponentModel","constructor","id","displayName","packageName","server","compositions","tags","buildStatus","issuesCount","elementsUrl","status","deprecation","environment","description","labels","host","latest","preview","logs","version","from","env","ComponentID","fromObject","Composition","fromArray","TagMap","map","tag","Tag","componentsProps","rawComponent","empty","name","scope","url"],"sources":["component-model.ts"],"sourcesContent":["import { Composition, CompositionProps } from '@teambit/compositions';\nimport { DeprecationInfo } from '@teambit/deprecation';\nimport { Descriptor } from '@teambit/envs';\nimport { ComponentID, ComponentIdObj } from '@teambit/component-id';\nimport { LegacyComponentLog } from '@teambit/legacy-component-log';\nimport { Tag } from '../../tag';\nimport { TagMap } from '../../tag-map';\nimport { TagProps } from '../../tag/tag';\n// import { Snap } from '../../snap';\n\n// ADDING MORE PROPERTIES HERE IS NOT ALLOWED!!! IF YOU NEED DATA PLEASE ADD A NEW\n// HOOK FROM YOUR ASPECT!!!\n// TODO: remove all properties from here to their rightful place in their aspects.\nexport type ComponentModelProps = {\n id: ComponentIdObj;\n description: string;\n buildStatus?: string;\n server?: ComponentServer;\n displayName: string;\n packageName: string; // pkg aspect\n elementsUrl?: string; // pkg aspect\n compositions?: CompositionProps[];\n tags?: TagProps[];\n issuesCount?: number; // component/issues aspect\n status?: any; // workspace aspect.\n deprecation?: DeprecationInfo; // deprecation aspect\n env?: Descriptor; // env aspect.\n labels?: string[];\n host?: string;\n latest?: string;\n preview?: ComponentPreview;\n logs?: LegacyComponentLog[];\n};\n\nexport type ComponentPreview = {\n includesEnvTemplate?: boolean;\n legacyHeader?: boolean;\n};\n\nexport type ComponentServer = {\n env: string;\n url: string;\n};\n\nexport class ComponentModel {\n constructor(\n /**\n * id of the component\n */\n readonly id: ComponentID,\n\n /**\n * display name of the component.\n */\n readonly displayName: string,\n\n /**\n * package name of the component.\n */\n readonly packageName: string,\n\n /**\n * the component server.\n */\n readonly server: ComponentServer | undefined,\n\n /**\n * array of compositions\n */\n readonly compositions: Composition[],\n\n /**\n * tags of the component.\n */\n readonly tags: TagMap,\n\n /**\n * component build status\n */\n readonly buildStatus?: string,\n\n /**\n * issues of component.\n */\n readonly issuesCount?: number,\n /**\n * elements url\n */\n readonly elementsUrl?: string,\n /**\n * status of component.\n */\n readonly status?: any,\n\n /**\n * deprecation info of the component.\n */\n readonly deprecation?: DeprecationInfo,\n\n /**\n * env descriptor.\n */\n readonly environment?: Descriptor,\n\n /**\n * description of the component.\n */\n\n readonly description = '',\n\n readonly labels: string[] = [],\n\n /**\n * host of the component\n */\n readonly host?: string,\n\n /**\n * latest version of component\n */\n readonly latest?: string,\n\n readonly preview?: ComponentPreview,\n\n readonly logs?: LegacyComponentLog[]\n ) {}\n\n get version() {\n if (!this.id.version) return 'new';\n return this.id.version;\n }\n\n /**\n * create an instance of a component from a plain object.\n */\n static from({\n id,\n server,\n displayName,\n compositions = [],\n packageName,\n elementsUrl,\n tags = [],\n deprecation,\n buildStatus,\n env,\n status,\n issuesCount,\n description,\n labels,\n host,\n latest,\n preview,\n logs,\n }: ComponentModelProps) {\n return new ComponentModel(\n ComponentID.fromObject(id),\n displayName,\n packageName,\n server,\n Composition.fromArray(compositions),\n TagMap.fromArray(tags.map((tag) => Tag.fromObject(tag))),\n buildStatus,\n issuesCount,\n elementsUrl,\n status,\n deprecation,\n env,\n description,\n labels,\n host,\n latest,\n preview,\n logs\n );\n }\n\n static fromArray(componentsProps: ComponentModelProps[]) {\n return componentsProps.map((rawComponent) => ComponentModel.from(rawComponent));\n }\n\n static empty() {\n return new ComponentModel(\n ComponentID.fromObject({ name: 'root', scope: 'temp' }),\n '',\n '',\n { env: '', url: '' },\n [],\n TagMap.empty()\n );\n }\n}\n"],"mappings":";;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAsCO,MAAMA,cAAN,CAAqB;EAC1BC,WAAW;EACT;AACJ;AACA;EACaC,EAJA;EAMT;AACJ;AACA;EACaC,WATA;EAWT;AACJ;AACA;EACaC,WAdA;EAgBT;AACJ;AACA;EACaC,MAnBA;EAqBT;AACJ;AACA;EACaC,YAxBA;EA0BT;AACJ;AACA;EACaC,IA7BA;EA+BT;AACJ;AACA;EACaC,WAlCA;EAoCT;AACJ;AACA;EACaC,WAvCA;EAwCT;AACJ;AACA;EACaC,WA3CA;EA4CT;AACJ;AACA;EACaC,MA/CA;EAiDT;AACJ;AACA;EACaC,WApDA;EAsDT;AACJ;AACA;EACaC,WAzDA;EA2DT;AACJ;AACA;EAEaC,WAAW,GAAG,EA/Dd,EAi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InB,cAAJ,CACLuB,0BAAA,CAAYC,UAAZ,CAAuBtB,EAAvB,CADK,EAELC,WAFK,EAGLC,WAHK,EAILC,MAJK,EAKLoB,2BAAA,CAAYC,SAAZ,CAAsBpB,YAAtB,CALK,EAMLqB,gBAAA,CAAOD,SAAP,CAAiBnB,IAAI,CAACqB,GAAL,CAAUC,GAAD,IAASC,UAAA,CAAIN,UAAJ,CAAeK,GAAf,CAAlB,CAAjB,CANK,EAOLrB,WAPK,EAQLC,WARK,EASLC,WATK,EAULC,MAVK,EAWLC,WAXK,EAYLU,GAZK,EAaLR,WAbK,EAcLC,MAdK,EAeLC,IAfK,EAgBLC,MAhBK,EAiBLC,OAjBK,EAkBLC,IAlBK,CAAP;EAoBD;;EAEe,OAATO,SAAS,CAACK,eAAD,EAAyC;IACvD,OAAOA,eAAe,CAACH,GAAhB,CAAqBI,YAAD,IAAkBhC,cAAc,CAACqB,IAAf,CAAoBW,YAApB,CAAtC,CAAP;EACD;;EAEW,OAALC,KAAK,GAAG;IACb,OAAO,IAAIjC,cAAJ,CACLuB,0BAAA,CAAYC,UAAZ,CAAuB;MAAEU,IAAI,EAAE,MAAR;MAAgBC,KAAK,EAAE;IAAvB,CAAvB,CADK,EAEL,EAFK,EAGL,EAHK,EAIL;MAAEb,GAAG,EAAE,EAAP;MAAWc,GAAG,EAAE;IAAhB,CAJK,EAKL,EALK,EAMLT,gBAAA,CAAOM,KAAP,EANK,CAAP;EAQD;;AAlJyB"}
|
package/dist/ui/component.js
CHANGED
|
@@ -39,6 +39,16 @@ function _uiFoundationUiReactRouter() {
|
|
|
39
39
|
return data;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
function _lanesUi() {
|
|
43
|
+
const data = require("@teambit/lanes.ui.lanes");
|
|
44
|
+
|
|
45
|
+
_lanesUi = function () {
|
|
46
|
+
return data;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return data;
|
|
50
|
+
}
|
|
51
|
+
|
|
42
52
|
function _componentModule() {
|
|
43
53
|
const data = _interopRequireDefault(require("./component.module.scss"));
|
|
44
54
|
|
|
@@ -93,11 +103,20 @@ function Component({
|
|
|
93
103
|
onComponentChange
|
|
94
104
|
}) {
|
|
95
105
|
const componentId = (0, _useComponentFromLocation().useIdFromLocation)();
|
|
106
|
+
const lanesContext = (0, _lanesUi().useLanesContext)();
|
|
107
|
+
const laneComponent = componentId ? lanesContext === null || lanesContext === void 0 ? void 0 : lanesContext.resolveComponent(componentId) : undefined;
|
|
108
|
+
const useComponentOptions = laneComponent && {
|
|
109
|
+
logFilters: {
|
|
110
|
+
log: {
|
|
111
|
+
logHead: laneComponent.version
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
96
115
|
const {
|
|
97
116
|
component,
|
|
98
117
|
componentDescriptor,
|
|
99
118
|
error
|
|
100
|
-
} = (0, _useComponent().useComponent)(host, componentId); // trigger onComponentChange when component changes
|
|
119
|
+
} = (0, _useComponent().useComponent)(host, (laneComponent === null || laneComponent === void 0 ? void 0 : laneComponent.id.toString()) || componentId, useComponentOptions); // trigger onComponentChange when component changes
|
|
101
120
|
|
|
102
121
|
(0, _react().useEffect)(() => onComponentChange === null || onComponentChange === void 0 ? void 0 : onComponentChange(component), [component]); // cleanup when unmounting component
|
|
103
122
|
|
package/dist/ui/component.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Component","routeSlot","containerSlot","host","onComponentChange","componentId","useIdFromLocation","component","componentDescriptor","error","useComponent","
|
|
1
|
+
{"version":3,"names":["Component","routeSlot","containerSlot","host","onComponentChange","componentId","useIdFromLocation","lanesContext","useLanesContext","laneComponent","resolveComponent","undefined","useComponentOptions","logFilters","log","logHead","version","component","componentDescriptor","error","useComponent","id","toString","useEffect","pageItems","useMemo","flatten","values","before","filter","x","type","map","content","after","renderError","styles","container"],"sources":["component.tsx"],"sourcesContent":["import React, { useEffect, ReactNode, useMemo } from 'react';\nimport flatten from 'lodash.flatten';\nimport { RouteSlot, SlotRouter } from '@teambit/ui-foundation.ui.react-router.slot-router';\nimport { SlotRegistry } from '@teambit/harmony';\nimport { useLanesContext } from '@teambit/lanes.ui.lanes';\n\nimport styles from './component.module.scss';\nimport { ComponentProvider, ComponentDescriptorProvider } from './context';\nimport { useComponent } from './use-component';\nimport { ComponentModel } from './component-model';\nimport { useIdFromLocation } from './use-component-from-location';\n\nexport type ComponentPageSlot = SlotRegistry<ComponentPageElement[]>;\nexport type ComponentPageElement = {\n type: 'before' | 'after';\n content: ReactNode;\n};\n\nexport type ComponentProps = {\n containerSlot?: ComponentPageSlot;\n routeSlot: RouteSlot;\n host: string;\n onComponentChange?: (activeComponent?: ComponentModel) => void;\n};\n\n/**\n * main UI component of the Component extension.\n */\nexport function Component({ routeSlot, containerSlot, host, onComponentChange }: ComponentProps) {\n const componentId = useIdFromLocation();\n const lanesContext = useLanesContext();\n const laneComponent = componentId ? lanesContext?.resolveComponent(componentId) : undefined;\n const useComponentOptions = laneComponent && {\n logFilters: { log: { logHead: laneComponent.version } },\n }\n\n const { component, componentDescriptor, error } = useComponent(\n host,\n laneComponent?.id.toString() || componentId,\n useComponentOptions\n );\n // trigger onComponentChange when component changes\n useEffect(() => onComponentChange?.(component), [component]);\n // cleanup when unmounting component\n useEffect(() => () => onComponentChange?.(undefined), []);\n\n const pageItems = useMemo(() => flatten(containerSlot?.values()), [containerSlot]);\n const before = useMemo(() => pageItems.filter((x) => x.type === 'before').map((x) => x.content), [pageItems]);\n const after = useMemo(() => pageItems.filter((x) => x.type === 'after').map((x) => x.content), [pageItems]);\n\n if (error) return error.renderError();\n if (!component) return <div></div>;\n\n return (\n <ComponentDescriptorProvider componentDescriptor={componentDescriptor}>\n <ComponentProvider component={component}>\n {before}\n <div className={styles.container}>\n {routeSlot && <SlotRouter parentPath={`${componentId}/*`} slot={routeSlot} />}\n </div>\n {after}\n </ComponentProvider>\n </ComponentDescriptorProvider>\n );\n}\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAA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,aAAMA,iBAAN,uBAAMA,iBAAiB,CAAGO,SAAH,CAAvC,EAAsD,EAAtD;EAEA,MAAMa,SAAS,GAAG,IAAAC,gBAAA,EAAQ,MAAM,IAAAC,iBAAA,EAAQxB,aAAR,aAAQA,aAAR,uBAAQA,aAAa,CAAEyB,MAAf,EAAR,CAAd,EAAgD,CAACzB,aAAD,CAAhD,CAAlB;EACA,MAAM0B,MAAM,GAAG,IAAAH,gBAAA,EAAQ,MAAMD,SAAS,CAACK,MAAV,CAAkBC,CAAD,IAAOA,CAAC,CAACC,IAAF,KAAW,QAAnC,EAA6CC,GAA7C,CAAkDF,CAAD,IAAOA,CAAC,CAACG,OAA1D,CAAd,EAAkF,CAACT,SAAD,CAAlF,CAAf;EACA,MAAMU,KAAK,GAAG,IAAAT,gBAAA,EAAQ,MAAMD,SAAS,CAACK,MAAV,CAAkBC,CAAD,IAAOA,CAAC,CAACC,IAAF,KAAW,OAAnC,EAA4CC,GAA5C,CAAiDF,CAAD,IAAOA,CAAC,CAACG,OAAzD,CAAd,EAAiF,CAACT,SAAD,CAAjF,CAAd;EAEA,IAAIL,KAAJ,EAAW,OAAOA,KAAK,CAACgB,WAAN,EAAP;EACX,IAAI,CAAClB,SAAL,EAAgB,oBAAO,2CAAP;EAEhB,oBACE,+BAAC,sCAAD;IAA6B,mBAAmB,EAAEC;EAAlD,gBACE,+BAAC,4BAAD;IAAmB,SAAS,EAAED;EAA9B,GACGW,MADH,eAEE;IAAK,SAAS,EAAEQ,0BAAA,CAAOC;EAAvB,GACGpC,SAAS,iBAAI,+BAAC,uCAAD;IAAY,UAAU,EAAG,GAAEI,WAAY,IAAvC;IAA4C,IAAI,EAAEJ;EAAlD,EADhB,CAFF,EAKGiC,KALH,CADF,CADF;AAWD"}
|
package/dist/ui/menu/menu.js
CHANGED
|
@@ -201,9 +201,18 @@ function ComponentMenu({
|
|
|
201
201
|
consumeMethodSlot
|
|
202
202
|
}) {
|
|
203
203
|
const componentId = (0, _useComponentFromLocation().useIdFromLocation)();
|
|
204
|
+
const lanesContext = (0, _lanesUi().useLanesContext)();
|
|
205
|
+
const laneComponent = componentId ? lanesContext === null || lanesContext === void 0 ? void 0 : lanesContext.resolveComponent(componentId) : undefined;
|
|
206
|
+
const useComponentOptions = laneComponent && {
|
|
207
|
+
logFilters: {
|
|
208
|
+
log: {
|
|
209
|
+
logHead: laneComponent.version
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
};
|
|
204
213
|
const {
|
|
205
214
|
component
|
|
206
|
-
} = (0, _useComponent().useComponent)(host, componentId);
|
|
215
|
+
} = (0, _useComponent().useComponent)(host, (laneComponent === null || laneComponent === void 0 ? void 0 : laneComponent.id.toString()) || componentId, useComponentOptions);
|
|
207
216
|
const mainMenuItems = (0, _react().useMemo)(() => (0, _lodash().groupBy)((0, _lodash().flatten)(menuItemSlot.values()), 'category'), [menuItemSlot]);
|
|
208
217
|
if (!component) return /*#__PURE__*/_react().default.createElement(_uiFoundationUi2().FullLoader, null);
|
|
209
218
|
return /*#__PURE__*/_react().default.createElement(_reactRouterDom().Routes, null, /*#__PURE__*/_react().default.createElement(_reactRouterDom().Route, {
|
package/dist/ui/menu/menu.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ComponentMenu","navigationSlot","widgetSlot","className","host","menuItemSlot","consumeMethodSlot","componentId","useIdFromLocation","component","useComponent","mainMenuItems","useMemo","groupBy","flatten","values","classnames","styles","topBar","leftSide","rightSide","widgets","VersionRelatedDropdowns","consumeMethods","location","useLocation","isNew","tags","isEmpty","lanesContext","useLanesContext","currentLane","viewedLane","logs","isWorkspace","snaps","filter","log","tag","map","snap","version","hash","reverse","tagLookup","Map","forEach","set","compact","toArray","get","lanes","getLanesByComponentId","id","localVersion","currentVersion","search","includes","methods","useConsumeMethods","length","useBox","name","latest","componentModel","method","x","Component","Title"],"sources":["menu.tsx"],"sourcesContent":["import { Routes, Route } from 'react-router-dom';\nimport { MainDropdown, MenuItemSlot } from '@teambit/ui-foundation.ui.main-dropdown';\nimport { VersionDropdown } from '@teambit/component.ui.version-dropdown';\nimport { FullLoader } from '@teambit/ui-foundation.ui.full-loader';\nimport type { ConsumeMethod } from '@teambit/ui-foundation.ui.use-box.menu';\nimport { useLocation } from '@teambit/base-react.navigation.link';\nimport { flatten, groupBy, compact } from 'lodash';\nimport classnames from 'classnames';\nimport React, { useMemo } from 'react';\nimport { UseBoxDropdown } from '@teambit/ui-foundation.ui.use-box.dropdown';\nimport { Menu as ConsumeMethodsMenu } from '@teambit/ui-foundation.ui.use-box.menu';\nimport { LaneModel, useLanesContext } from '@teambit/lanes.ui.lanes';\nimport { LegacyComponentLog } from '@teambit/legacy-component-log';\nimport type { ComponentModel } from '../component-model';\nimport { useComponent } from '../use-component';\nimport { MenuNav } from './menu-nav';\nimport { MobileMenuNav } from './mobile-menu-nav';\nimport styles from './menu.module.scss';\nimport { OrderedNavigationSlot, ConsumeMethodSlot } from './nav-plugin';\nimport { useIdFromLocation } from '../use-component-from-location';\n\nexport type MenuProps = {\n className?: string;\n /**\n * slot for top bar menu nav items\n */\n navigationSlot: OrderedNavigationSlot;\n /**\n * right side menu item slot\n */\n widgetSlot: OrderedNavigationSlot;\n host: string;\n /**\n * main dropdown item slot\n */\n menuItemSlot: MenuItemSlot;\n\n consumeMethodSlot: ConsumeMethodSlot;\n};\n\n/**\n * top bar menu.\n */\nexport function ComponentMenu({\n navigationSlot,\n widgetSlot,\n className,\n host,\n menuItemSlot,\n consumeMethodSlot,\n}: MenuProps) {\n const componentId = useIdFromLocation();\n const { component } = useComponent(host, componentId);\n const mainMenuItems = useMemo(() => groupBy(flatten(menuItemSlot.values()), 'category'), [menuItemSlot]);\n if (!component) return <FullLoader />;\n return (\n <Routes>\n <Route\n path={`${componentId}/*`}\n element={\n <div className={classnames(styles.topBar, className)}>\n <div className={styles.leftSide}>\n <MenuNav navigationSlot={navigationSlot} />\n <MobileMenuNav navigationSlot={navigationSlot} widgetSlot={widgetSlot} />\n </div>\n <div className={styles.rightSide}>\n <div className={styles.widgets}>\n <MenuNav navigationSlot={widgetSlot} />\n </div>\n <VersionRelatedDropdowns component={component} consumeMethods={consumeMethodSlot} host={host} />\n <MainDropdown menuItems={mainMenuItems} />\n </div>\n </div>\n }\n />\n </Routes>\n );\n}\n\nfunction VersionRelatedDropdowns({\n component,\n consumeMethods,\n host,\n}: {\n component: ComponentModel;\n consumeMethods: ConsumeMethodSlot;\n host: string;\n}) {\n const location = useLocation();\n const isNew = component.tags.isEmpty();\n const lanesContext = useLanesContext();\n const currentLane = lanesContext?.viewedLane;\n const { logs } = component;\n const isWorkspace = host === 'teambit.workspace/workspace';\n\n const snaps = useMemo(() => {\n return (logs || [])\n .filter((log) => !log.tag)\n .map((snap) => ({ ...snap, version: snap.hash }))\n .reverse();\n }, [logs]);\n\n const tags = useMemo(() => {\n const tagLookup = new Map<string, LegacyComponentLog>();\n (logs || [])\n .filter((log) => log.tag)\n .forEach((tag) => {\n tagLookup.set(tag?.tag as string, tag);\n });\n return compact(\n component.tags\n ?.toArray()\n .reverse()\n .map((tag) => tagLookup.get(tag.version.version))\n ).map((tag) => ({ ...tag, version: tag.tag as string }));\n }, [logs]);\n\n const lanes = lanesContext?.getLanesByComponentId(component.id) || [];\n const localVersion = isWorkspace && !isNew && !currentLane;\n\n const currentVersion =\n isWorkspace && !isNew && !location?.search.includes('version') ? 'workspace' : component.version;\n\n const methods = useConsumeMethods(consumeMethods, component, currentLane);\n return (\n <>\n {tags.length > 0 && (\n <UseBoxDropdown\n position=\"bottom-end\"\n className={styles.useBox}\n Menu={<ConsumeMethodsMenu methods={methods} componentName={component.id.name} />}\n />\n )}\n <VersionDropdown\n tags={tags}\n snaps={snaps}\n lanes={lanes}\n localVersion={localVersion}\n currentVersion={currentVersion}\n latestVersion={component.latest}\n currentLane={currentLane}\n />\n </>\n );\n}\n\nfunction useConsumeMethods(\n consumeMethods: ConsumeMethodSlot,\n componentModel: ComponentModel,\n currentLane?: LaneModel\n): ConsumeMethod[] {\n return useMemo(\n () =>\n flatten(consumeMethods.values())\n .map((method) => {\n return method?.(componentModel, { currentLane });\n })\n .filter((x) => !!x && x.Component && x.Title) as ConsumeMethod[],\n [consumeMethods, componentModel, currentLane]\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;;AAEA;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;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;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;;;;;;;;;;AAqBA;AACA;AACA;AACO,SAASA,aAAT,CAAuB;EAC5BC,cAD4B;EAE5BC,UAF4B;EAG5BC,SAH4B;EAI5BC,IAJ4B;EAK5BC,YAL4B;EAM5BC;AAN4B,CAAvB,EAOO;EACZ,MAAMC,WAAW,GAAG,IAAAC,6CAAA,GAApB;EACA,MAAM;IAAEC;EAAF,IAAgB,IAAAC,4BAAA,EAAaN,IAAb,EAAmBG,WAAnB,CAAtB;EACA,MAAMI,aAAa,GAAG,IAAAC,gBAA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,cAAjB,EAAiCjC,WAAjC,CAPK,CAAP;AASD"}
|
|
1
|
+
{"version":3,"names":["ComponentMenu","navigationSlot","widgetSlot","className","host","menuItemSlot","consumeMethodSlot","componentId","useIdFromLocation","lanesContext","useLanesContext","laneComponent","resolveComponent","undefined","useComponentOptions","logFilters","log","logHead","version","component","useComponent","id","toString","mainMenuItems","useMemo","groupBy","flatten","values","classnames","styles","topBar","leftSide","rightSide","widgets","VersionRelatedDropdowns","consumeMethods","location","useLocation","isNew","tags","isEmpty","currentLane","viewedLane","logs","isWorkspace","snaps","filter","tag","map","snap","hash","reverse","tagLookup","Map","forEach","set","compact","toArray","get","lanes","getLanesByComponentId","localVersion","currentVersion","search","includes","methods","useConsumeMethods","length","useBox","name","latest","componentModel","method","x","Component","Title"],"sources":["menu.tsx"],"sourcesContent":["import { Routes, Route } from 'react-router-dom';\nimport { MainDropdown, MenuItemSlot } from '@teambit/ui-foundation.ui.main-dropdown';\nimport { VersionDropdown } from '@teambit/component.ui.version-dropdown';\nimport { FullLoader } from '@teambit/ui-foundation.ui.full-loader';\nimport type { ConsumeMethod } from '@teambit/ui-foundation.ui.use-box.menu';\nimport { useLocation } from '@teambit/base-react.navigation.link';\nimport { flatten, groupBy, compact } from 'lodash';\nimport classnames from 'classnames';\nimport React, { useMemo } from 'react';\nimport { UseBoxDropdown } from '@teambit/ui-foundation.ui.use-box.dropdown';\nimport { Menu as ConsumeMethodsMenu } from '@teambit/ui-foundation.ui.use-box.menu';\nimport { LaneModel, useLanesContext } from '@teambit/lanes.ui.lanes';\nimport { LegacyComponentLog } from '@teambit/legacy-component-log';\nimport type { ComponentModel } from '../component-model';\nimport { useComponent } from '../use-component';\nimport { MenuNav } from './menu-nav';\nimport { MobileMenuNav } from './mobile-menu-nav';\nimport styles from './menu.module.scss';\nimport { OrderedNavigationSlot, ConsumeMethodSlot } from './nav-plugin';\nimport { useIdFromLocation } from '../use-component-from-location';\n\nexport type MenuProps = {\n className?: string;\n /**\n * slot for top bar menu nav items\n */\n navigationSlot: OrderedNavigationSlot;\n /**\n * right side menu item slot\n */\n widgetSlot: OrderedNavigationSlot;\n host: string;\n /**\n * main dropdown item slot\n */\n menuItemSlot: MenuItemSlot;\n\n consumeMethodSlot: ConsumeMethodSlot;\n};\n\n/**\n * top bar menu.\n */\nexport function ComponentMenu({\n navigationSlot,\n widgetSlot,\n className,\n host,\n menuItemSlot,\n consumeMethodSlot,\n}: MenuProps) {\n const componentId = useIdFromLocation();\n const lanesContext = useLanesContext();\n const laneComponent = componentId ? lanesContext?.resolveComponent(componentId) : undefined;\n const useComponentOptions = laneComponent && {\n logFilters: { log: { logHead: laneComponent.version } },\n };\n\n const { component } = useComponent(host, laneComponent?.id.toString() || componentId, useComponentOptions);\n const mainMenuItems = useMemo(() => groupBy(flatten(menuItemSlot.values()), 'category'), [menuItemSlot]);\n if (!component) return <FullLoader />;\n return (\n <Routes>\n <Route\n path={`${componentId}/*`}\n element={\n <div className={classnames(styles.topBar, className)}>\n <div className={styles.leftSide}>\n <MenuNav navigationSlot={navigationSlot} />\n <MobileMenuNav navigationSlot={navigationSlot} widgetSlot={widgetSlot} />\n </div>\n <div className={styles.rightSide}>\n <div className={styles.widgets}>\n <MenuNav navigationSlot={widgetSlot} />\n </div>\n <VersionRelatedDropdowns component={component} consumeMethods={consumeMethodSlot} host={host} />\n <MainDropdown menuItems={mainMenuItems} />\n </div>\n </div>\n }\n />\n </Routes>\n );\n}\n\nfunction VersionRelatedDropdowns({\n component,\n consumeMethods,\n host,\n}: {\n component: ComponentModel;\n consumeMethods: ConsumeMethodSlot;\n host: string;\n}) {\n const location = useLocation();\n const isNew = component.tags.isEmpty();\n const lanesContext = useLanesContext();\n const currentLane = lanesContext?.viewedLane;\n const { logs } = component;\n const isWorkspace = host === 'teambit.workspace/workspace';\n\n const snaps = useMemo(() => {\n return (logs || [])\n .filter((log) => !log.tag)\n .map((snap) => ({ ...snap, version: snap.hash }))\n .reverse();\n }, [logs]);\n\n const tags = useMemo(() => {\n const tagLookup = new Map<string, LegacyComponentLog>();\n (logs || [])\n .filter((log) => log.tag)\n .forEach((tag) => {\n tagLookup.set(tag?.tag as string, tag);\n });\n return compact(\n component.tags\n ?.toArray()\n .reverse()\n .map((tag) => tagLookup.get(tag.version.version))\n ).map((tag) => ({ ...tag, version: tag.tag as string }));\n }, [logs]);\n\n const lanes = lanesContext?.getLanesByComponentId(component.id) || [];\n const localVersion = isWorkspace && !isNew && !currentLane;\n\n const currentVersion =\n isWorkspace && !isNew && !location?.search.includes('version') ? 'workspace' : component.version;\n\n const methods = useConsumeMethods(consumeMethods, component, currentLane);\n return (\n <>\n {tags.length > 0 && (\n <UseBoxDropdown\n position=\"bottom-end\"\n className={styles.useBox}\n Menu={<ConsumeMethodsMenu methods={methods} componentName={component.id.name} />}\n />\n )}\n <VersionDropdown\n tags={tags}\n snaps={snaps}\n lanes={lanes}\n localVersion={localVersion}\n currentVersion={currentVersion}\n latestVersion={component.latest}\n currentLane={currentLane}\n />\n </>\n );\n}\n\nfunction useConsumeMethods(\n consumeMethods: ConsumeMethodSlot,\n componentModel: ComponentModel,\n currentLane?: LaneModel\n): ConsumeMethod[] {\n return useMemo(\n () =>\n flatten(consumeMethods.values())\n .map((method) => {\n return method?.(componentModel, { currentLane });\n })\n .filter((x) => !!x && x.Component && x.Title) as ConsumeMethod[],\n [consumeMethods, componentModel, currentLane]\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;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAA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
|
return data;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
function _baseReactNavigation() {
|
|
85
|
+
const data = require("@teambit/base-react.navigation.link");
|
|
86
|
+
|
|
87
|
+
_baseReactNavigation = function () {
|
|
88
|
+
return data;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return data;
|
|
92
|
+
}
|
|
93
|
+
|
|
84
94
|
function _topBarNav() {
|
|
85
95
|
const data = require("../top-bar-nav");
|
|
86
96
|
|
|
@@ -159,17 +169,43 @@ function Placeholder(_ref) {
|
|
|
159
169
|
rest = (0, _objectWithoutProperties2().default)(_ref, ["slots"]);
|
|
160
170
|
return /*#__PURE__*/_react().default.createElement("div", (0, _extends2().default)({}, rest, {
|
|
161
171
|
className: _mobileMenuNavModule().default.placeholder
|
|
162
|
-
}),
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
path: menuItem === null || menuItem === void 0 ? void 0 : (_menuItem$props = menuItem.props) === null || _menuItem$props === void 0 ? void 0 : _menuItem$props.href,
|
|
168
|
-
element: typeof (menuItem === null || menuItem === void 0 ? void 0 : (_menuItem$props2 = menuItem.props) === null || _menuItem$props2 === void 0 ? void 0 : _menuItem$props2.children) === 'string' ? menuItem === null || menuItem === void 0 ? void 0 : (_menuItem$props3 = menuItem.props) === null || _menuItem$props3 === void 0 ? void 0 : _menuItem$props3.children : menuItem === null || menuItem === void 0 ? void 0 : (_menuItem$props4 = menuItem.props) === null || _menuItem$props4 === void 0 ? void 0 : _menuItem$props4.displayName
|
|
169
|
-
});
|
|
170
|
-
})), /*#__PURE__*/_react().default.createElement(_designElements().Icon, {
|
|
172
|
+
}), slots.map(([id, menuItem]) => /*#__PURE__*/_react().default.createElement(ShowWhenMatch, {
|
|
173
|
+
key: id,
|
|
174
|
+
href: menuItem.props.href || '',
|
|
175
|
+
end: menuItem.props.exact
|
|
176
|
+
}, typeof menuItem.props.children === 'string' ? menuItem.props.children : menuItem.props.displayName)), /*#__PURE__*/_react().default.createElement(_designElements().Icon, {
|
|
171
177
|
of: "fat-arrow-down"
|
|
172
178
|
}));
|
|
173
179
|
}
|
|
174
180
|
|
|
181
|
+
function ShowWhenMatch({
|
|
182
|
+
href,
|
|
183
|
+
children,
|
|
184
|
+
caseSensitive,
|
|
185
|
+
end: exact
|
|
186
|
+
}) {
|
|
187
|
+
const isMatch = useLinkMatch(href, {
|
|
188
|
+
caseSensitive,
|
|
189
|
+
exact
|
|
190
|
+
});
|
|
191
|
+
if (!isMatch) return null;
|
|
192
|
+
return /*#__PURE__*/_react().default.createElement(_react().default.Fragment, null, children);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function useLinkMatch(href, {
|
|
196
|
+
caseSensitive,
|
|
197
|
+
exact
|
|
198
|
+
} = {}) {
|
|
199
|
+
const location = (0, _baseReactNavigation().useLocation)();
|
|
200
|
+
let pathname = (location === null || location === void 0 ? void 0 : location.pathname) || '/';
|
|
201
|
+
let destination = (0, _reactRouterDom().useResolvedPath)(href).pathname;
|
|
202
|
+
|
|
203
|
+
if (!caseSensitive) {
|
|
204
|
+
pathname = pathname.toLowerCase();
|
|
205
|
+
destination = destination.toLowerCase();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return destination === pathname || !exact && pathname.startsWith(destination) && pathname.charAt(destination.length) === '/';
|
|
209
|
+
}
|
|
210
|
+
|
|
175
211
|
//# sourceMappingURL=mobile-menu-nav.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["MobileMenuNav","navigationSlot","widgetSlot","className","totalSlots","useMemo","toArray","sort","sortFn","classnames","styles","navigation","mobileNav","mobileStyles","mobileMenu","close","map","id","menuItem","props","mobileMenuLink","active","children","displayName","order","first","second","Placeholder","slots","rest","placeholder","href"],"sources":["mobile-menu-nav.tsx"],"sourcesContent":["import React, { useMemo } from 'react';\nimport {
|
|
1
|
+
{"version":3,"names":["MobileMenuNav","navigationSlot","widgetSlot","className","totalSlots","useMemo","toArray","sort","sortFn","classnames","styles","navigation","mobileNav","mobileStyles","mobileMenu","close","map","id","menuItem","props","mobileMenuLink","active","children","displayName","order","first","second","Placeholder","slots","rest","placeholder","href","exact","ShowWhenMatch","caseSensitive","end","isMatch","useLinkMatch","location","useLocation","pathname","destination","useResolvedPath","toLowerCase","startsWith","charAt","length"],"sources":["mobile-menu-nav.tsx"],"sourcesContent":["import React, { ReactNode, useMemo } from 'react';\nimport { useResolvedPath } from 'react-router-dom';\nimport classnames from 'classnames';\nimport { Icon } from '@teambit/design.elements.icon';\nimport { Dropdown } from '@teambit/design.inputs.dropdown';\nimport { useLocation } from '@teambit/base-react.navigation.link';\nimport { TopBarNav } from '../top-bar-nav';\nimport styles from './menu.module.scss';\nimport mobileStyles from './mobile-menu-nav.module.scss';\nimport { NavPlugin, OrderedNavigationSlot } from './nav-plugin';\n\nexport function MobileMenuNav({\n navigationSlot,\n widgetSlot,\n className,\n}: {\n navigationSlot: OrderedNavigationSlot;\n widgetSlot: OrderedNavigationSlot;\n className?: string;\n}) {\n const totalSlots = useMemo(\n () => [...navigationSlot.toArray().sort(sortFn), ...widgetSlot.toArray().sort(sortFn)],\n [navigationSlot, widgetSlot]\n );\n\n return (\n <Dropdown\n // @ts-ignore - mismatch between @types/react\n placeholder={<Placeholder slots={totalSlots} />}\n className={classnames(styles.navigation, styles.mobileNav, className)}\n dropClass={mobileStyles.mobileMenu}\n >\n <nav>\n <Icon of=\"x-thick\" className={mobileStyles.close} />\n {totalSlots.map(([id, menuItem]) => {\n return (\n <TopBarNav\n key={id}\n {...menuItem.props}\n className={mobileStyles.mobileMenuLink}\n activeClassName={mobileStyles.active}\n >\n {typeof menuItem.props.children === 'string' ? menuItem.props.children : menuItem.props.displayName}\n </TopBarNav>\n );\n })}\n </nav>\n </Dropdown>\n );\n}\n\nfunction sortFn([, { order: first }]: [string, NavPlugin], [, { order: second }]: [string, NavPlugin]) {\n // 0 - equal\n // <0 - first < second\n // >0 - first > second\n\n return (first ?? 0) - (second ?? 0);\n}\n\ntype PlaceholderProps = {\n slots: [string, NavPlugin][];\n baseUrl?: string;\n} & React.HTMLAttributes<HTMLDivElement>;\n\nfunction Placeholder({ slots, ...rest }: PlaceholderProps) {\n return (\n <div {...rest} className={mobileStyles.placeholder}>\n {slots.map(([id, menuItem]) => (\n <ShowWhenMatch key={id} href={menuItem.props.href || ''} end={menuItem.props.exact}>\n {typeof menuItem.props.children === 'string' ? menuItem.props.children : menuItem.props.displayName}\n </ShowWhenMatch>\n ))}\n <Icon of=\"fat-arrow-down\" />\n </div>\n );\n}\n\nfunction ShowWhenMatch({\n href,\n children,\n caseSensitive,\n end: exact,\n}: {\n href: string;\n children: ReactNode;\n caseSensitive?: boolean;\n end?: boolean;\n}) {\n const isMatch = useLinkMatch(href, { caseSensitive, exact });\n if (!isMatch) return null;\n return <>{children}</>;\n}\n\nfunction useLinkMatch(href: string, { caseSensitive, exact }: { caseSensitive?: boolean; exact?: boolean } = {}) {\n const location = useLocation();\n let pathname = location?.pathname || '/';\n let destination = useResolvedPath(href).pathname;\n\n if (!caseSensitive) {\n pathname = pathname.toLowerCase();\n destination = destination.toLowerCase();\n }\n\n return (\n destination === pathname ||\n (!exact && pathname.startsWith(destination) && pathname.charAt(destination.length) === '/')\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;;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;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;;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AAR,YAAAA,QAAQ,CAAEE,QAAV,KAAsB,GAArC;EACA,IAAIC,WAAW,GAAG,IAAAC,iCAAA,EAAgBX,IAAhB,EAAsBS,QAAxC;;EAEA,IAAI,CAACN,aAAL,EAAoB;IAClBM,QAAQ,GAAGA,QAAQ,CAACG,WAAT,EAAX;IACAF,WAAW,GAAGA,WAAW,CAACE,WAAZ,EAAd;EACD;;EAED,OACEF,WAAW,KAAKD,QAAhB,IACC,CAACR,KAAD,IAAUQ,QAAQ,CAACI,UAAT,CAAoBH,WAApB,CAAV,IAA8CD,QAAQ,CAACK,MAAT,CAAgBJ,WAAW,CAACK,MAA5B,MAAwC,GAFzF;AAID"}
|
|
@@ -4,8 +4,7 @@ import { ComponentError } from './component-error';
|
|
|
4
4
|
export declare const componentIdFields: import("@apollo/client").DocumentNode;
|
|
5
5
|
export declare const componentOverviewFields: import("@apollo/client").DocumentNode;
|
|
6
6
|
export declare const componentFields: import("@apollo/client").DocumentNode;
|
|
7
|
-
|
|
8
|
-
export declare function useComponentQuery(componentId: string, host: string, filters?: {
|
|
7
|
+
export declare type Filters = {
|
|
9
8
|
log?: {
|
|
10
9
|
logType?: string;
|
|
11
10
|
logOffset?: number;
|
|
@@ -13,7 +12,9 @@ export declare function useComponentQuery(componentId: string, host: string, fil
|
|
|
13
12
|
logHead?: string;
|
|
14
13
|
logSort?: string;
|
|
15
14
|
};
|
|
16
|
-
}
|
|
15
|
+
};
|
|
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
18
|
componentDescriptor: ComponentDescriptor | undefined;
|
|
18
19
|
component: ComponentModel | undefined;
|
|
19
20
|
error: ComponentError | undefined;
|
|
@@ -130,6 +130,7 @@ const componentOverviewFields = (0, _client().gql)`
|
|
|
130
130
|
}
|
|
131
131
|
preview {
|
|
132
132
|
includesEnvTemplate
|
|
133
|
+
legacyHeader
|
|
133
134
|
}
|
|
134
135
|
compositions {
|
|
135
136
|
identifier
|
|
@@ -223,8 +224,8 @@ const SUB_COMPONENT_REMOVED = (0, _client().gql)`
|
|
|
223
224
|
}
|
|
224
225
|
${componentIdFields}
|
|
225
226
|
`;
|
|
226
|
-
/** provides data to component ui page, making sure both variables and return value are safely typed and memoized */
|
|
227
227
|
|
|
228
|
+
/** provides data to component ui page, making sure both variables and return value are safely typed and memoized */
|
|
228
229
|
function useComponentQuery(componentId, host, filters) {
|
|
229
230
|
var _data$getHost;
|
|
230
231
|
|
|
@@ -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","data","error","loading","subscribeToMore","useDataQuery","variables","id","extensionId","log","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","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.pipelines/builder\", \"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 aspectId: id\n aspectData: data\n }\n elementsUrl\n description\n deprecation {\n isDeprecate\n }\n labels\n displayName\n server {\n env\n url\n }\n buildStatus\n env {\n id\n icon\n }\n preview {\n includesEnvTemplate\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`;\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?: { log?: { logType?: string; logOffset?: number; logLimit?: number; logHead?: string; logSort?: string } }\n) {\n const idRef = useRef(componentId);\n idRef.current = componentId;\n const { data, error, loading, subscribeToMore } = 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,\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"],"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;;;;;;AAEO,MAAMA,iBAAiB,GAAG,IAAAC,aAAA,CAAI;AACrC;AACA;AACA;AACA;AACA;AACA,CANO;;AAQA,MAAMC,uBAAuB,GAAG,IAAAD,aAAA,CAAI;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,IAAID,iBAAkB;AACtB,CArCO;;AAuCA,MAAMG,eAAe,GAAG,IAAAF,aAAA,CAAI;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,CA3BO;;AA6BP,MAAME,aAAa,GAAG,IAAAH,aAAA,CAAI;AAC1B;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lC,EAAE,GAAG8B,YAAY,IAAIV,0BAAA,CAAYe,UAAZ,CAAuBL,YAAY,CAAC9B,EAApC,CAA3B;;IACA,OAAO;MACLoC,mBAAmB,EAAEpC,EAAE,GAAGqC,0CAAA,CAAoBF,UAApB,CAA+B;QAAEnC,EAAE,EAAEA,EAAE,CAACsC,QAAH,EAAN;QAAqBN;MAArB,CAA/B,CAAH,GAAuEO,SADzF;MAELzB,SAAS,EAAEgB,YAAY,GAAGU,gCAAA,CAAeC,IAAf,iCAAyBX,YAAzB;QAAuCzC;MAAvC,GAAH,GAAoDkD,SAFtE;MAGL;MACA5C,KAAK,EAAEA,KAAK,GACR,KAAI+C,gCAAJ,EAAmB,GAAnB,EAAwB/C,KAAK,CAACgD,OAA9B,CADQ,GAER,CAACb,YAAD,IAAiB,CAAClC,OAAlB,GACA,KAAI8C,gCAAJ,EAAmB,GAAnB,CADA,GAEAH;IARC,CAAP;EAUD,CAfM,EAeJ,CAACT,YAAD,EAAezC,IAAf,EAAqBM,KAArB,CAfI,CAAP;AAgBD"}
|
|
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","data","error","loading","subscribeToMore","useDataQuery","variables","id","extensionId","log","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","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.pipelines/builder\", \"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 aspectId: id\n aspectData: data\n }\n elementsUrl\n description\n deprecation {\n isDeprecate\n }\n labels\n displayName\n server {\n env\n url\n }\n buildStatus\n env {\n id\n icon\n }\n preview {\n includesEnvTemplate\n legacyHeader\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 } = 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,\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"],"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;;;;;;AAEO,MAAMA,iBAAiB,GAAG,IAAAC,aAAA,CAAI;AACrC;AACA;AACA;AACA;AACA;AACA,CANO;;AAQA,MAAMC,uBAAuB,GAAG,IAAAD,aAAA,CAAI;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;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BA,OAAO,MAAM;MACXS,YAAY;MACZZ,aAAa;MACbkB,YAAY;IACb,CAJD;EAKD,CAlFD,EAkFG,EAlFH;EAoFA,MAAMQ,YAAY,GAAGpC,IAAH,aAAGA,IAAH,wCAAGA,IAAI,CAAEgB,OAAT,kDAAG,cAAeC,GAApC;EACA,OAAO,IAAAoB,gBAAA,EAAQ,MAAM;IACnB,MAAMC,UAAU,GAAG;MACjBC,OAAO,EAAEH,YAAF,aAAEA,YAAF,uBAAEA,YAAY,CAAEI;IADN,CAAnB;;IAGA,MAAMlC,EAAE,GAAG8B,YAAY,IAAIV,0BAAA,CAAYe,UAAZ,CAAuBL,YAAY,CAAC9B,EAApC,CAA3B;;IACA,OAAO;MACLoC,mBAAmB,EAAEpC,EAAE,GAAGqC,0CAAA,CAAoBF,UAApB,CAA+B;QAAEnC,EAAE,EAAEA,EAAE,CAACsC,QAAH,EAAN;QAAqBN;MAArB,CAA/B,CAAH,GAAuEO,SADzF;MAELzB,SAAS,EAAEgB,YAAY,GAAGU,gCAAA,CAAeC,IAAf,iCAAyBX,YAAzB;QAAuCzC;MAAvC,GAAH,GAAoDkD,SAFtE;MAGL;MACA5C,KAAK,EAAEA,KAAK,GACR,KAAI+C,gCAAJ,EAAmB,GAAnB,EAAwB/C,KAAK,CAACgD,OAA9B,CADQ,GAER,CAACb,YAAD,IAAiB,CAAClC,OAAlB,GACA,KAAI8C,gCAAJ,EAAmB,GAAnB,CADA,GAEAH;IARC,CAAP;EAUD,CAfM,EAeJ,CAACT,YAAD,EAAezC,IAAf,EAAqBM,KAArB,CAfI,CAAP;AAgBD"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { ComponentID } from '@teambit/component-id';
|
|
2
1
|
import { ComponentDescriptor } from '@teambit/component-descriptor';
|
|
3
2
|
import { ComponentModel } from './component-model';
|
|
4
3
|
import { ComponentError } from './component-error';
|
|
4
|
+
import { Filters } from './use-component-query';
|
|
5
5
|
export declare type Component = {
|
|
6
6
|
component?: ComponentModel;
|
|
7
7
|
error?: ComponentError;
|
|
8
8
|
componentDescriptor?: ComponentDescriptor;
|
|
9
9
|
};
|
|
10
|
-
export declare
|
|
10
|
+
export declare type UseComponentOptions = {
|
|
11
|
+
version?: string;
|
|
12
|
+
logFilters?: Filters;
|
|
13
|
+
};
|
|
14
|
+
export declare function useComponent(host: string, id?: string, options?: UseComponentOptions): Component;
|
package/dist/ui/use-component.js
CHANGED
|
@@ -15,16 +15,6 @@ function _uiFoundationUiReactRouter() {
|
|
|
15
15
|
return data;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
function _lanesUi() {
|
|
19
|
-
const data = require("@teambit/lanes.ui.lanes");
|
|
20
|
-
|
|
21
|
-
_lanesUi = function () {
|
|
22
|
-
return data;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
return data;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
18
|
function _useComponentQuery() {
|
|
29
19
|
const data = require("./use-component-query");
|
|
30
20
|
|
|
@@ -35,25 +25,17 @@ function _useComponentQuery() {
|
|
|
35
25
|
return data;
|
|
36
26
|
}
|
|
37
27
|
|
|
38
|
-
function useComponent(host, id) {
|
|
39
|
-
var
|
|
28
|
+
function useComponent(host, id, options) {
|
|
29
|
+
var _ref;
|
|
40
30
|
|
|
41
31
|
const query = (0, _uiFoundationUiReactRouter().useQuery)();
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (!
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
const laneComponentId = lanesContext === null || lanesContext === void 0 ? void 0 : (_lanesContext$viewedL = lanesContext.viewedLane) === null || _lanesContext$viewedL === void 0 ? void 0 : (_lanesContext$viewedL2 = _lanesContext$viewedL.components.find(component => component.id.fullName === targetId)) === null || _lanesContext$viewedL2 === void 0 ? void 0 : _lanesContext$viewedL2.id;
|
|
51
|
-
const componentIdStr = laneComponentId ? laneComponentId === null || laneComponentId === void 0 ? void 0 : laneComponentId.toString() : withVersion(targetId, version);
|
|
52
|
-
const logFilters = currentLane ? {
|
|
53
|
-
log: {
|
|
54
|
-
logHead: laneComponentId === null || laneComponentId === void 0 ? void 0 : laneComponentId.version
|
|
55
|
-
}
|
|
56
|
-
} : undefined;
|
|
32
|
+
const {
|
|
33
|
+
version,
|
|
34
|
+
logFilters
|
|
35
|
+
} = options || {};
|
|
36
|
+
const componentVersion = (_ref = version || query.get('version')) !== null && _ref !== void 0 ? _ref : undefined;
|
|
37
|
+
if (!id) throw new TypeError('useComponent received no component id');
|
|
38
|
+
const componentIdStr = withVersion(id, componentVersion);
|
|
57
39
|
return (0, _useComponentQuery().useComponentQuery)(componentIdStr, host, logFilters);
|
|
58
40
|
}
|
|
59
41
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useComponent","host","id","query","useQuery","version","
|
|
1
|
+
{"version":3,"names":["useComponent","host","id","options","query","useQuery","version","logFilters","componentVersion","get","undefined","TypeError","componentIdStr","withVersion","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};\nexport type UseComponentOptions = {\n version?: string;\n logFilters?: Filters\n};\n\nexport function useComponent(host: string, id?: string, options?: UseComponentOptions): Component {\n const query = useQuery();\n const { version, logFilters } = options || {};\n const componentVersion = (version || query.get('version')) ?? undefined;\n \n if (!id) throw new TypeError('useComponent received no component id');\n\n const componentIdStr = withVersion(id, componentVersion);\n\n return useComponentQuery(componentIdStr, host, logFilters);\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;;AAYO,SAASA,YAAT,CAAsBC,IAAtB,EAAoCC,EAApC,EAAiDC,OAAjD,EAA2F;EAAA;;EAChG,MAAMC,KAAK,GAAG,IAAAC,qCAAA,GAAd;EACA,MAAM;IAAEC,OAAF;IAAWC;EAAX,IAA0BJ,OAAO,IAAI,EAA3C;EACA,MAAMK,gBAAgB,WAAIF,OAAO,IAAIF,KAAK,CAACK,GAAN,CAAU,SAAV,CAAf,uCAAwCC,SAA9D;EAEA,IAAI,CAACR,EAAL,EAAS,MAAM,IAAIS,SAAJ,CAAc,uCAAd,CAAN;EAET,MAAMC,cAAc,GAAGC,WAAW,CAACX,EAAD,EAAKM,gBAAL,CAAlC;EAEA,OAAO,IAAAM,sCAAA,EAAkBF,cAAlB,EAAkCX,IAAlC,EAAwCM,UAAxC,CAAP;AACD;;AAED,SAASM,WAAT,CAAqBX,EAArB,EAAiCI,OAAjC,EAAmD;EACjD,IAAI,CAACA,OAAL,EAAc,OAAOJ,EAAP;EACd,IAAIA,EAAE,CAACa,QAAH,CAAY,GAAZ,CAAJ,EAAsB,OAAOb,EAAP;EACtB,OAAQ,GAAEA,EAAG,IAAGI,OAAQ,EAAxB;AACD"}
|
|
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.750",
|
|
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.750"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@teambit/any-fs": "0.0.5",
|
|
@@ -31,42 +31,42 @@
|
|
|
31
31
|
"@teambit/design.inputs.dropdown": "0.0.7",
|
|
32
32
|
"@teambit/component-id": "0.0.402",
|
|
33
33
|
"@teambit/ui-foundation.ui.menu-widget-icon": "0.0.488",
|
|
34
|
-
"@teambit/aspect-loader": "0.0.
|
|
34
|
+
"@teambit/aspect-loader": "0.0.750",
|
|
35
35
|
"@teambit/legacy-bit-id": "0.0.399",
|
|
36
36
|
"@teambit/toolbox.path.match-patterns": "0.0.1",
|
|
37
37
|
"@teambit/toolbox.string.capitalize": "0.0.483",
|
|
38
|
-
"@teambit/cli": "0.0.
|
|
39
|
-
"@teambit/config": "0.0.
|
|
40
|
-
"@teambit/express": "0.0.
|
|
41
|
-
"@teambit/graphql": "0.0.
|
|
38
|
+
"@teambit/cli": "0.0.495",
|
|
39
|
+
"@teambit/config": "0.0.508",
|
|
40
|
+
"@teambit/express": "0.0.593",
|
|
41
|
+
"@teambit/graphql": "0.0.750",
|
|
42
42
|
"@teambit/bit-error": "0.0.394",
|
|
43
|
-
"@teambit/command-bar": "0.0.
|
|
43
|
+
"@teambit/command-bar": "0.0.750",
|
|
44
44
|
"@teambit/component.ui.deprecation-icon": "0.0.493",
|
|
45
|
-
"@teambit/preview": "0.0.
|
|
46
|
-
"@teambit/pubsub": "0.0.
|
|
47
|
-
"@teambit/react-router": "0.0.
|
|
45
|
+
"@teambit/preview": "0.0.750",
|
|
46
|
+
"@teambit/pubsub": "0.0.750",
|
|
47
|
+
"@teambit/react-router": "0.0.750",
|
|
48
48
|
"@teambit/ui-foundation.ui.is-browser": "0.0.486",
|
|
49
49
|
"@teambit/ui-foundation.ui.main-dropdown": "0.0.487",
|
|
50
50
|
"@teambit/ui-foundation.ui.react-router.slot-router": "0.0.490",
|
|
51
51
|
"@teambit/ui-foundation.ui.use-box.menu": "0.0.115",
|
|
52
|
-
"@teambit/ui": "0.0.
|
|
52
|
+
"@teambit/ui": "0.0.750",
|
|
53
53
|
"@teambit/component-issues": "0.0.53",
|
|
54
54
|
"@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.487",
|
|
55
55
|
"@teambit/cli-table": "0.0.34",
|
|
56
|
-
"@teambit/
|
|
57
|
-
"@teambit/
|
|
56
|
+
"@teambit/lanes.ui.lanes": "0.0.62",
|
|
57
|
+
"@teambit/component-descriptor": "0.0.57",
|
|
58
58
|
"@teambit/ui-foundation.ui.react-router.use-query": "0.0.487",
|
|
59
59
|
"@teambit/design.ui.empty-box": "0.0.353",
|
|
60
60
|
"@teambit/harmony.ui.aspect-box": "0.0.486",
|
|
61
61
|
"@teambit/design.ui.pages.not-found": "0.0.355",
|
|
62
62
|
"@teambit/design.ui.pages.server-error": "0.0.355",
|
|
63
|
-
"@teambit/compositions": "0.0.
|
|
64
|
-
"@teambit/deprecation": "0.0.
|
|
65
|
-
"@teambit/envs": "0.0.
|
|
63
|
+
"@teambit/compositions": "0.0.750",
|
|
64
|
+
"@teambit/deprecation": "0.0.750",
|
|
65
|
+
"@teambit/envs": "0.0.750",
|
|
66
66
|
"@teambit/legacy-component-log": "0.0.392",
|
|
67
67
|
"@teambit/design.ui.styles.ellipsis": "0.0.347",
|
|
68
68
|
"@teambit/envs.ui.env-icon": "0.0.486",
|
|
69
|
-
"@teambit/component.ui.version-dropdown": "0.0.
|
|
69
|
+
"@teambit/component.ui.version-dropdown": "0.0.548",
|
|
70
70
|
"@teambit/ui-foundation.ui.full-loader": "0.0.486",
|
|
71
71
|
"@teambit/ui-foundation.ui.use-box.dropdown": "0.0.115",
|
|
72
72
|
"@teambit/ui-foundation.ui.constants.z-indexes": "0.0.487"
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"peerDependencies": {
|
|
89
89
|
"react-router-dom": "^6.0.0",
|
|
90
90
|
"@apollo/client": "^3.0.0",
|
|
91
|
-
"@teambit/legacy": "1.0.
|
|
91
|
+
"@teambit/legacy": "1.0.275",
|
|
92
92
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
93
93
|
"react": "^16.8.0 || ^17.0.0"
|
|
94
94
|
},
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
"react": "-"
|
|
117
117
|
},
|
|
118
118
|
"peerDependencies": {
|
|
119
|
-
"@teambit/legacy": "1.0.
|
|
119
|
+
"@teambit/legacy": "1.0.275",
|
|
120
120
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
121
121
|
"react": "^16.8.0 || ^17.0.0"
|
|
122
122
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component@0.0.
|
|
2
|
-
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component@0.0.
|
|
1
|
+
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component@0.0.750/dist/component.composition.js')]
|
|
2
|
+
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.component_component@0.0.750/dist/component.docs.mdx')]
|
package/tsconfig.json
CHANGED
package/ui/component.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import React, { useEffect, ReactNode, useMemo } from 'react';
|
|
|
2
2
|
import flatten from 'lodash.flatten';
|
|
3
3
|
import { RouteSlot, SlotRouter } from '@teambit/ui-foundation.ui.react-router.slot-router';
|
|
4
4
|
import { SlotRegistry } from '@teambit/harmony';
|
|
5
|
+
import { useLanesContext } from '@teambit/lanes.ui.lanes';
|
|
5
6
|
|
|
6
7
|
import styles from './component.module.scss';
|
|
7
8
|
import { ComponentProvider, ComponentDescriptorProvider } from './context';
|
|
@@ -27,7 +28,17 @@ export type ComponentProps = {
|
|
|
27
28
|
*/
|
|
28
29
|
export function Component({ routeSlot, containerSlot, host, onComponentChange }: ComponentProps) {
|
|
29
30
|
const componentId = useIdFromLocation();
|
|
30
|
-
const
|
|
31
|
+
const lanesContext = useLanesContext();
|
|
32
|
+
const laneComponent = componentId ? lanesContext?.resolveComponent(componentId) : undefined;
|
|
33
|
+
const useComponentOptions = laneComponent && {
|
|
34
|
+
logFilters: { log: { logHead: laneComponent.version } },
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const { component, componentDescriptor, error } = useComponent(
|
|
38
|
+
host,
|
|
39
|
+
laneComponent?.id.toString() || componentId,
|
|
40
|
+
useComponentOptions
|
|
41
|
+
);
|
|
31
42
|
// trigger onComponentChange when component changes
|
|
32
43
|
useEffect(() => onComponentChange?.(component), [component]);
|
|
33
44
|
// cleanup when unmounting component
|
package/ui/menu/menu.tsx
CHANGED
|
@@ -50,7 +50,13 @@ export function ComponentMenu({
|
|
|
50
50
|
consumeMethodSlot,
|
|
51
51
|
}: MenuProps) {
|
|
52
52
|
const componentId = useIdFromLocation();
|
|
53
|
-
const
|
|
53
|
+
const lanesContext = useLanesContext();
|
|
54
|
+
const laneComponent = componentId ? lanesContext?.resolveComponent(componentId) : undefined;
|
|
55
|
+
const useComponentOptions = laneComponent && {
|
|
56
|
+
logFilters: { log: { logHead: laneComponent.version } },
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const { component } = useComponent(host, laneComponent?.id.toString() || componentId, useComponentOptions);
|
|
54
60
|
const mainMenuItems = useMemo(() => groupBy(flatten(menuItemSlot.values()), 'category'), [menuItemSlot]);
|
|
55
61
|
if (!component) return <FullLoader />;
|
|
56
62
|
return (
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import React, { useMemo } from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import React, { ReactNode, useMemo } from 'react';
|
|
2
|
+
import { useResolvedPath } from 'react-router-dom';
|
|
3
3
|
import classnames from 'classnames';
|
|
4
4
|
import { Icon } from '@teambit/design.elements.icon';
|
|
5
5
|
import { Dropdown } from '@teambit/design.inputs.dropdown';
|
|
6
|
+
import { useLocation } from '@teambit/base-react.navigation.link';
|
|
6
7
|
import { TopBarNav } from '../top-bar-nav';
|
|
7
8
|
import styles from './menu.module.scss';
|
|
8
9
|
import mobileStyles from './mobile-menu-nav.module.scss';
|
|
@@ -64,18 +65,44 @@ type PlaceholderProps = {
|
|
|
64
65
|
function Placeholder({ slots, ...rest }: PlaceholderProps) {
|
|
65
66
|
return (
|
|
66
67
|
<div {...rest} className={mobileStyles.placeholder}>
|
|
67
|
-
|
|
68
|
-
{
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
element={
|
|
73
|
-
typeof menuItem?.props?.children === 'string' ? menuItem?.props?.children : menuItem?.props?.displayName
|
|
74
|
-
}
|
|
75
|
-
/>
|
|
76
|
-
))}
|
|
77
|
-
</Routes>
|
|
68
|
+
{slots.map(([id, menuItem]) => (
|
|
69
|
+
<ShowWhenMatch key={id} href={menuItem.props.href || ''} end={menuItem.props.exact}>
|
|
70
|
+
{typeof menuItem.props.children === 'string' ? menuItem.props.children : menuItem.props.displayName}
|
|
71
|
+
</ShowWhenMatch>
|
|
72
|
+
))}
|
|
78
73
|
<Icon of="fat-arrow-down" />
|
|
79
74
|
</div>
|
|
80
75
|
);
|
|
81
76
|
}
|
|
77
|
+
|
|
78
|
+
function ShowWhenMatch({
|
|
79
|
+
href,
|
|
80
|
+
children,
|
|
81
|
+
caseSensitive,
|
|
82
|
+
end: exact,
|
|
83
|
+
}: {
|
|
84
|
+
href: string;
|
|
85
|
+
children: ReactNode;
|
|
86
|
+
caseSensitive?: boolean;
|
|
87
|
+
end?: boolean;
|
|
88
|
+
}) {
|
|
89
|
+
const isMatch = useLinkMatch(href, { caseSensitive, exact });
|
|
90
|
+
if (!isMatch) return null;
|
|
91
|
+
return <>{children}</>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function useLinkMatch(href: string, { caseSensitive, exact }: { caseSensitive?: boolean; exact?: boolean } = {}) {
|
|
95
|
+
const location = useLocation();
|
|
96
|
+
let pathname = location?.pathname || '/';
|
|
97
|
+
let destination = useResolvedPath(href).pathname;
|
|
98
|
+
|
|
99
|
+
if (!caseSensitive) {
|
|
100
|
+
pathname = pathname.toLowerCase();
|
|
101
|
+
destination = destination.toLowerCase();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
destination === pathname ||
|
|
106
|
+
(!exact && pathname.startsWith(destination) && pathname.charAt(destination.length) === '/')
|
|
107
|
+
);
|
|
108
|
+
}
|
|
@@ -45,6 +45,7 @@ export const componentOverviewFields = gql`
|
|
|
45
45
|
}
|
|
46
46
|
preview {
|
|
47
47
|
includesEnvTemplate
|
|
48
|
+
legacyHeader
|
|
48
49
|
}
|
|
49
50
|
compositions {
|
|
50
51
|
identifier
|
|
@@ -141,13 +142,11 @@ const SUB_COMPONENT_REMOVED = gql`
|
|
|
141
142
|
}
|
|
142
143
|
${componentIdFields}
|
|
143
144
|
`;
|
|
144
|
-
|
|
145
|
+
export type Filters = {
|
|
146
|
+
log?: { logType?: string; logOffset?: number; logLimit?: number; logHead?: string; logSort?: string };
|
|
147
|
+
};
|
|
145
148
|
/** provides data to component ui page, making sure both variables and return value are safely typed and memoized */
|
|
146
|
-
export function useComponentQuery(
|
|
147
|
-
componentId: string,
|
|
148
|
-
host: string,
|
|
149
|
-
filters?: { log?: { logType?: string; logOffset?: number; logLimit?: number; logHead?: string; logSort?: string } }
|
|
150
|
-
) {
|
|
149
|
+
export function useComponentQuery(componentId: string, host: string, filters?: Filters) {
|
|
151
150
|
const idRef = useRef(componentId);
|
|
152
151
|
idRef.current = componentId;
|
|
153
152
|
const { data, error, loading, subscribeToMore } = useDataQuery(GET_COMPONENT, {
|
package/ui/use-component.tsx
CHANGED
|
@@ -1,40 +1,27 @@
|
|
|
1
|
-
import { ComponentID } from '@teambit/component-id';
|
|
2
1
|
import { useQuery } from '@teambit/ui-foundation.ui.react-router.use-query';
|
|
3
2
|
import { ComponentDescriptor } from '@teambit/component-descriptor';
|
|
4
|
-
import { useLanesContext } from '@teambit/lanes.ui.lanes';
|
|
5
3
|
import { ComponentModel } from './component-model';
|
|
6
4
|
import { ComponentError } from './component-error';
|
|
7
|
-
import { useComponentQuery } from './use-component-query';
|
|
5
|
+
import { Filters, useComponentQuery } from './use-component-query';
|
|
8
6
|
|
|
9
7
|
export type Component = {
|
|
10
8
|
component?: ComponentModel;
|
|
11
9
|
error?: ComponentError;
|
|
12
10
|
componentDescriptor?: ComponentDescriptor;
|
|
13
11
|
};
|
|
12
|
+
export type UseComponentOptions = {
|
|
13
|
+
version?: string;
|
|
14
|
+
logFilters?: Filters
|
|
15
|
+
};
|
|
14
16
|
|
|
15
|
-
export function useComponent(host: string, id?: string
|
|
17
|
+
export function useComponent(host: string, id?: string, options?: UseComponentOptions): Component {
|
|
16
18
|
const query = useQuery();
|
|
17
|
-
const version =
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
(typeof id === 'string' && id) || (typeof id !== 'undefined' && id.toString({ ignoreVersion: true }));
|
|
22
|
-
if (!targetId) throw new TypeError('useComponent received no component id');
|
|
23
|
-
const currentLane = lanesContext?.viewedLane;
|
|
24
|
-
// when on a lane, always fetch all the logs starting from the 'head' version
|
|
25
|
-
const laneComponentId = lanesContext?.viewedLane?.components.find(
|
|
26
|
-
(component) => component.id.fullName === targetId
|
|
27
|
-
)?.id;
|
|
28
|
-
|
|
29
|
-
const componentIdStr = laneComponentId ? laneComponentId?.toString() : withVersion(targetId, version);
|
|
19
|
+
const { version, logFilters } = options || {};
|
|
20
|
+
const componentVersion = (version || query.get('version')) ?? undefined;
|
|
21
|
+
|
|
22
|
+
if (!id) throw new TypeError('useComponent received no component id');
|
|
30
23
|
|
|
31
|
-
const
|
|
32
|
-
? {
|
|
33
|
-
log: {
|
|
34
|
-
logHead: laneComponentId?.version,
|
|
35
|
-
},
|
|
36
|
-
}
|
|
37
|
-
: undefined;
|
|
24
|
+
const componentIdStr = withVersion(id, componentVersion);
|
|
38
25
|
|
|
39
26
|
return useComponentQuery(componentIdStr, host, logFilters);
|
|
40
27
|
}
|
|
Binary file
|