@mintlify/common 1.0.1343 → 1.0.1345

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.
@@ -20,6 +20,11 @@ export type DivisionState = {
20
20
  href: string;
21
21
  isActive: boolean;
22
22
  isGlobal: boolean;
23
+ /**
24
+ * The href is the current page in this division (e.g. the same page in another version), not a
25
+ * fallback to the division's first page. Switchers use this to carry the URL #anchor across.
26
+ */
27
+ isCurrentPageMatch?: true;
23
28
  };
24
29
  export declare const isActiveDivision: <T extends object>(item: T) => item is T & {
25
30
  isActive: true;
@@ -274,6 +274,7 @@ function buildDivisionItem(param) {
274
274
  const { item, isActive, cache, currentPath, currentVersion, currentLanguage, userGroups, divisionKey, menuDivision, isPreview = false, parentDivisionNames = [], rootNav, } = param;
275
275
  const { dropdownCache } = cache;
276
276
  let href = '';
277
+ let isCurrentPageMatch = false;
277
278
  // TODO: support this for other divisions (versions, languages, etc.)
278
279
  // check if items's subdivisions are dropdowns
279
280
  if (dropdownCache.size && 'dropdowns' in item) {
@@ -298,6 +299,7 @@ function buildDivisionItem(param) {
298
299
  (!hasChildNav && userHref.startsWith('/') && !userHref.startsWith('//')));
299
300
  if (!isUserDefinedHref && divisionKey === 'dropdowns' && !isActive && currentPath) {
300
301
  href = (_c = (_b = findCorrespondingDropdownHref(item, currentPath, userGroups !== null && userGroups !== void 0 ? userGroups : new Set(), isPreview)) !== null && _b !== void 0 ? _b : findSamePageInDropdownVersion(page === null || page === void 0 ? void 0 : page.href, findDivisionName(item), currentPath, rootNav, userGroups !== null && userGroups !== void 0 ? userGroups : new Set(), isPreview)) !== null && _c !== void 0 ? _c : '';
302
+ isCurrentPageMatch = !!href;
301
303
  }
302
304
  if (!href) {
303
305
  href = isUserDefinedHref ? userHref : (page === null || page === void 0 ? void 0 : page.href) || '/';
@@ -308,7 +310,7 @@ function buildDivisionItem(param) {
308
310
  }
309
311
  }
310
312
  }
311
- const baseResult = Object.assign(Object.assign({ name: findDivisionName(item) }, divisionItem), { href: href, isActive, isGlobal: false });
313
+ const baseResult = Object.assign(Object.assign(Object.assign({ name: findDivisionName(item) }, divisionItem), { href: href, isActive, isGlobal: false }), (isCurrentPageMatch && { isCurrentPageMatch: true }));
312
314
  // handle dropdowns for tabs and products with menu
313
315
  if ((divisionKey === 'tabs' || divisionKey === 'products') && 'menu' in item) {
314
316
  if (isActive && (menuDivision === null || menuDivision === void 0 ? void 0 : menuDivision.length)) {
@@ -795,6 +795,23 @@ describe('filterDivisions dropdown corresponding pages', () => {
795
795
  const result = filterDivisions(Object.assign(Object.assign({}, defaultArgs), { decoratedNav: versionedDropdownNav, currentPath: '/vega/0.22/new-feature' }));
796
796
  expect((_a = result.dropdowns.find((d) => d.name === 'Version 0.21')) === null || _a === void 0 ? void 0 : _a.href).toBe('/vega/0.21/overview');
797
797
  });
798
+ describe('isCurrentPageMatch', () => {
799
+ it('marks an inactive dropdown that links to the same page in its version', () => {
800
+ var _a;
801
+ const result = filterDivisions(Object.assign(Object.assign({}, defaultArgs), { decoratedNav: versionedDropdownNav, currentPath: '/vega/0.21/install' }));
802
+ expect((_a = result.dropdowns.find((d) => d.name === 'Version 0.22')) === null || _a === void 0 ? void 0 : _a.isCurrentPageMatch).toBe(true);
803
+ });
804
+ it('does not mark a dropdown that falls back to its first page', () => {
805
+ var _a;
806
+ const result = filterDivisions(Object.assign(Object.assign({}, defaultArgs), { decoratedNav: versionedDropdownNav, currentPath: '/vega/0.22/new-feature' }));
807
+ expect((_a = result.dropdowns.find((d) => d.name === 'Version 0.21')) === null || _a === void 0 ? void 0 : _a.isCurrentPageMatch).toBeUndefined();
808
+ });
809
+ it('does not mark the active dropdown', () => {
810
+ var _a;
811
+ const result = filterDivisions(Object.assign(Object.assign({}, defaultArgs), { decoratedNav: versionedDropdownNav, currentPath: '/vega/0.21/install' }));
812
+ expect((_a = result.dropdowns.find(isActiveDivision)) === null || _a === void 0 ? void 0 : _a.isCurrentPageMatch).toBeUndefined();
813
+ });
814
+ });
798
815
  it('prefers a shared page at the same href over a segment match', () => {
799
816
  var _a;
800
817
  const result = filterDivisions(Object.assign(Object.assign({}, defaultArgs), { decoratedNav: {
@@ -897,9 +914,10 @@ describe('filterDivisions dropdown corresponding pages', () => {
897
914
  ],
898
915
  };
899
916
  it('links to the same page in that version wherever it is in the navigation', () => {
900
- var _a;
917
+ var _a, _b;
901
918
  const result = filterDivisions(Object.assign(Object.assign({}, defaultArgs), { decoratedNav: movedPageNav, currentPath: '/docs/v3/webhooks' }));
902
919
  expect((_a = result.dropdowns.find((d) => d.name === 'v2')) === null || _a === void 0 ? void 0 : _a.href).toBe('/docs/v2/webhooks');
920
+ expect((_b = result.dropdowns.find((d) => d.name === 'v2')) === null || _b === void 0 ? void 0 : _b.isCurrentPageMatch).toBe(true);
903
921
  });
904
922
  it('falls back to the first page when that version has no page the viewer can access', () => {
905
923
  var _a;