@redocly/theme 0.52.0 → 0.53.0-next.1
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/lib/core/hooks/menu/use-nested-menu.js +1 -1
- package/lib/core/utils/menu.js +1 -1
- package/lib/core/utils/urls.d.ts +8 -1
- package/lib/core/utils/urls.js +9 -3
- package/package.json +2 -2
- package/src/core/hooks/menu/use-nested-menu.ts +2 -2
- package/src/core/utils/menu.ts +5 -7
- package/src/core/utils/urls.ts +9 -2
|
@@ -58,7 +58,7 @@ function useNestedMenu({ item, labelRef, nestedMenuRef }) {
|
|
|
58
58
|
}, [labelRef, isExpanded, item.active]);
|
|
59
59
|
const handleExpand = (0, react_1.useCallback)(() => __awaiter(this, void 0, void 0, function* () {
|
|
60
60
|
if (item.expanded === 'always' ||
|
|
61
|
-
(item.link && item.hasActiveSubItem && item.link !== location.pathname)) {
|
|
61
|
+
(item.link && item.hasActiveSubItem && item.link !== (0, utils_1.withoutPathPrefix)(location.pathname))) {
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
const [firstChild] = item.items;
|
package/lib/core/utils/menu.js
CHANGED
|
@@ -36,7 +36,7 @@ const buildLanguagesGroup = (locales, defaultLocale, currentLocale) => {
|
|
|
36
36
|
items: locales
|
|
37
37
|
.filter((locale) => locale.code !== currentLocale)
|
|
38
38
|
.map((locale) => {
|
|
39
|
-
const newLangPathname = (0, utils_1.
|
|
39
|
+
const newLangPathname = (0, utils_1.getPathnameForLocale)((0, utils_1.withoutPathPrefix)(location.pathname), defaultLocale, locale.code, locales);
|
|
40
40
|
const newUrlWithLanguage = `${newLangPathname}${location.search}${location.hash}`;
|
|
41
41
|
return {
|
|
42
42
|
type: 'link',
|
package/lib/core/utils/urls.d.ts
CHANGED
|
@@ -25,10 +25,17 @@ export declare function slash(path: string): string;
|
|
|
25
25
|
export declare function addTrailingSlash(url: string): string;
|
|
26
26
|
/**
|
|
27
27
|
* Adds locale to pathname, or replaces current locale in pathname with a new one
|
|
28
|
-
* @param originalPathname - Pathname without
|
|
28
|
+
* @param originalPathname - Pathname without path prefix
|
|
29
29
|
* @param defaultLocale - Default locale code
|
|
30
30
|
* @param newLocale - New locale code to apply
|
|
31
31
|
* @param allLocales - Array of all available locales
|
|
32
32
|
*/
|
|
33
33
|
export declare function getPathnameForLocale(originalPathname: string, defaultLocale: string, newLocale: string, allLocales: Locale[]): string;
|
|
34
|
+
/**
|
|
35
|
+
* Extracts the locale code from a pathname
|
|
36
|
+
* @param pathname - URL pathname to extract locale from without path prefix
|
|
37
|
+
* @param defaultLocale - Default locale code to return if no locale found in pathname
|
|
38
|
+
* @param allLocales - Array of all available locales to check against
|
|
39
|
+
* @returns The locale code from the pathname, or the default locale if none found
|
|
40
|
+
*/
|
|
34
41
|
export declare function getLocaleFromPathname(pathname: string, defaultLocale?: string, allLocales?: Locale[]): string;
|
package/lib/core/utils/urls.js
CHANGED
|
@@ -84,7 +84,7 @@ function addTrailingSlash(url) {
|
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
86
|
* Adds locale to pathname, or replaces current locale in pathname with a new one
|
|
87
|
-
* @param originalPathname - Pathname without
|
|
87
|
+
* @param originalPathname - Pathname without path prefix
|
|
88
88
|
* @param defaultLocale - Default locale code
|
|
89
89
|
* @param newLocale - New locale code to apply
|
|
90
90
|
* @param allLocales - Array of all available locales
|
|
@@ -100,9 +100,15 @@ function getPathnameForLocale(originalPathname, defaultLocale, newLocale, allLoc
|
|
|
100
100
|
const newLocalePrefix = newLocale === defaultLocale ? '' : '/' + newLocale;
|
|
101
101
|
return `${newLocalePrefix.toLowerCase()}${pathnameWithoutLocale}`;
|
|
102
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Extracts the locale code from a pathname
|
|
105
|
+
* @param pathname - URL pathname to extract locale from without path prefix
|
|
106
|
+
* @param defaultLocale - Default locale code to return if no locale found in pathname
|
|
107
|
+
* @param allLocales - Array of all available locales to check against
|
|
108
|
+
* @returns The locale code from the pathname, or the default locale if none found
|
|
109
|
+
*/
|
|
103
110
|
function getLocaleFromPathname(pathname, defaultLocale = constants_1.DEFAULT_LOCALE_PLACEHOLDER, allLocales = []) {
|
|
104
|
-
|
|
105
|
-
const maybeLocale = (_a = withoutPathPrefix(pathname)) === null || _a === void 0 ? void 0 : _a.split('/')[1];
|
|
111
|
+
const maybeLocale = pathname === null || pathname === void 0 ? void 0 : pathname.split('/')[1];
|
|
106
112
|
const locale = allLocales.find((locale) => locale.code.toLowerCase() === maybeLocale);
|
|
107
113
|
return (locale === null || locale === void 0 ? void 0 : locale.code) || defaultLocale;
|
|
108
114
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redocly/theme",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.0-next.1",
|
|
4
4
|
"description": "Shared UI components lib",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"theme",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"react-calendar": "4.2.1",
|
|
89
89
|
"react-date-picker": "10.0.3",
|
|
90
90
|
"timeago.js": "4.0.2",
|
|
91
|
-
"@redocly/config": "0.
|
|
91
|
+
"@redocly/config": "0.24.0"
|
|
92
92
|
},
|
|
93
93
|
"scripts": {
|
|
94
94
|
"watch": "tsc -p tsconfig.build.json && (concurrently \"tsc -w -p tsconfig.build.json\" \"tsc-alias -w -p tsconfig.build.json\")",
|
|
@@ -4,7 +4,7 @@ import { useCallback, useEffect, useState } from 'react';
|
|
|
4
4
|
import type { MenuItemProps } from '@redocly/theme/core/types';
|
|
5
5
|
|
|
6
6
|
import { useMenuItemExpanded, useCollapse } from '@redocly/theme/core/hooks';
|
|
7
|
-
import { loadAndNavigate } from '@redocly/theme/core/utils';
|
|
7
|
+
import { loadAndNavigate, withoutPathPrefix } from '@redocly/theme/core/utils';
|
|
8
8
|
|
|
9
9
|
type NestedMenuProps = MenuItemProps & {
|
|
10
10
|
labelRef?: React.RefObject<HTMLElement>;
|
|
@@ -61,7 +61,7 @@ export function useNestedMenu({ item, labelRef, nestedMenuRef }: NestedMenuProps
|
|
|
61
61
|
const handleExpand = useCallback(async () => {
|
|
62
62
|
if (
|
|
63
63
|
item.expanded === 'always' ||
|
|
64
|
-
(item.link && item.hasActiveSubItem && item.link !== location.pathname)
|
|
64
|
+
(item.link && item.hasActiveSubItem && item.link !== withoutPathPrefix(location.pathname))
|
|
65
65
|
) {
|
|
66
66
|
return;
|
|
67
67
|
}
|
package/src/core/utils/menu.ts
CHANGED
|
@@ -64,13 +64,11 @@ export const buildLanguagesGroup = (
|
|
|
64
64
|
items: locales
|
|
65
65
|
.filter((locale) => locale.code !== currentLocale)
|
|
66
66
|
.map((locale) => {
|
|
67
|
-
const newLangPathname =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
locales,
|
|
73
|
-
),
|
|
67
|
+
const newLangPathname = getPathnameForLocale(
|
|
68
|
+
withoutPathPrefix(location.pathname),
|
|
69
|
+
defaultLocale,
|
|
70
|
+
locale.code,
|
|
71
|
+
locales,
|
|
74
72
|
);
|
|
75
73
|
const newUrlWithLanguage = `${newLangPathname}${location.search}${location.hash}`;
|
|
76
74
|
return {
|
package/src/core/utils/urls.ts
CHANGED
|
@@ -88,7 +88,7 @@ export function addTrailingSlash(url: string): string {
|
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
90
|
* Adds locale to pathname, or replaces current locale in pathname with a new one
|
|
91
|
-
* @param originalPathname - Pathname without
|
|
91
|
+
* @param originalPathname - Pathname without path prefix
|
|
92
92
|
* @param defaultLocale - Default locale code
|
|
93
93
|
* @param newLocale - New locale code to apply
|
|
94
94
|
* @param allLocales - Array of all available locales
|
|
@@ -115,12 +115,19 @@ export function getPathnameForLocale(
|
|
|
115
115
|
return `${newLocalePrefix.toLowerCase()}${pathnameWithoutLocale}`;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Extracts the locale code from a pathname
|
|
120
|
+
* @param pathname - URL pathname to extract locale from without path prefix
|
|
121
|
+
* @param defaultLocale - Default locale code to return if no locale found in pathname
|
|
122
|
+
* @param allLocales - Array of all available locales to check against
|
|
123
|
+
* @returns The locale code from the pathname, or the default locale if none found
|
|
124
|
+
*/
|
|
118
125
|
export function getLocaleFromPathname(
|
|
119
126
|
pathname: string,
|
|
120
127
|
defaultLocale: string = DEFAULT_LOCALE_PLACEHOLDER,
|
|
121
128
|
allLocales: Locale[] = [],
|
|
122
129
|
) {
|
|
123
|
-
const maybeLocale =
|
|
130
|
+
const maybeLocale = pathname?.split('/')[1];
|
|
124
131
|
const locale = allLocales.find((locale) => locale.code.toLowerCase() === maybeLocale);
|
|
125
132
|
|
|
126
133
|
return locale?.code || defaultLocale;
|