@mui/docs 5.15.9 → 5.15.12
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/CHANGELOG.md +375 -133
- package/DocsProvider/DocsProvider.d.ts +16 -0
- package/DocsProvider/DocsProvider.js +26 -0
- package/DocsProvider/index.d.ts +1 -0
- package/DocsProvider/index.js +1 -0
- package/DocsProvider/package.json +6 -0
- package/Link/Link.d.ts +16 -0
- package/Link/Link.js +106 -0
- package/Link/index.d.ts +1 -0
- package/Link/index.js +1 -0
- package/Link/package.json +6 -0
- package/i18n/i18n.d.ts +28 -0
- package/i18n/i18n.js +99 -0
- package/i18n/index.d.ts +1 -0
- package/i18n/index.js +1 -0
- package/i18n/package.json +6 -0
- package/legacy/DocsProvider/DocsProvider.js +25 -0
- package/legacy/DocsProvider/index.js +1 -0
- package/legacy/Link/Link.js +101 -0
- package/legacy/Link/index.js +1 -0
- package/legacy/i18n/i18n.js +105 -0
- package/legacy/i18n/index.js +1 -0
- package/legacy/translations/index.js +4 -0
- package/node/DocsProvider/DocsProvider.js +35 -0
- package/node/DocsProvider/index.js +16 -0
- package/node/Link/Link.js +113 -0
- package/node/Link/index.js +16 -0
- package/node/i18n/i18n.js +112 -0
- package/node/i18n/index.js +16 -0
- package/node/translations/index.js +11 -0
- package/package.json +8 -7
- package/translations/index.d.ts +3 -0
- package/translations/index.js +4 -0
- package/translations/package.json +6 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/index.d.ts +0 -0
- package/index.js +0 -11
- package/legacy/index.js +0 -11
- package/node/index.js +0 -41
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Translations } from '../i18n';
|
|
3
|
+
export interface DocsConfig {
|
|
4
|
+
LANGUAGES: string[];
|
|
5
|
+
LANGUAGES_SSR: string[];
|
|
6
|
+
LANGUAGES_IN_PROGRESS: string[];
|
|
7
|
+
LANGUAGES_IGNORE_PAGES: (pathname: string) => boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface DocsProviderProps {
|
|
10
|
+
config: DocsConfig;
|
|
11
|
+
defaultUserLanguage: string;
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
translations?: Translations;
|
|
14
|
+
}
|
|
15
|
+
export declare function DocsProvider({ config, defaultUserLanguage, translations, children, }: DocsProviderProps): React.JSX.Element;
|
|
16
|
+
export declare function useDocsConfig(): DocsConfig;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { UserLanguageProvider } from '../i18n';
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
const DocsConfigContext = /*#__PURE__*/React.createContext(null);
|
|
5
|
+
export function DocsProvider({
|
|
6
|
+
config,
|
|
7
|
+
defaultUserLanguage,
|
|
8
|
+
translations,
|
|
9
|
+
children
|
|
10
|
+
}) {
|
|
11
|
+
return /*#__PURE__*/_jsx(DocsConfigContext.Provider, {
|
|
12
|
+
value: config,
|
|
13
|
+
children: /*#__PURE__*/_jsx(UserLanguageProvider, {
|
|
14
|
+
defaultUserLanguage: defaultUserLanguage,
|
|
15
|
+
translations: translations,
|
|
16
|
+
children: children
|
|
17
|
+
})
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export function useDocsConfig() {
|
|
21
|
+
const config = React.useContext(DocsConfigContext);
|
|
22
|
+
if (!config) {
|
|
23
|
+
throw new Error('Could not find docs config context value; please ensure the component is wrapped in a <DocsProvider>');
|
|
24
|
+
}
|
|
25
|
+
return config;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './DocsProvider';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './DocsProvider';
|
package/Link/Link.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { LinkProps as NextLinkProps } from 'next/link';
|
|
3
|
+
import { LinkProps as MuiLinkProps } from '@mui/material/Link';
|
|
4
|
+
interface NextLinkComposedProps extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'href'>, Omit<NextLinkProps, 'href' | 'as' | 'passHref' | 'onMouseEnter' | 'onClick' | 'onTouchStart'> {
|
|
5
|
+
to: NextLinkProps['href'];
|
|
6
|
+
linkAs?: NextLinkProps['as'];
|
|
7
|
+
}
|
|
8
|
+
export type LinkProps = {
|
|
9
|
+
activeClassName?: string;
|
|
10
|
+
as?: NextLinkProps['as'];
|
|
11
|
+
href: NextLinkProps['href'];
|
|
12
|
+
linkAs?: NextLinkProps['as'];
|
|
13
|
+
noLinkStyle?: boolean;
|
|
14
|
+
} & Omit<NextLinkComposedProps, 'to' | 'linkAs' | 'href'> & Omit<MuiLinkProps, 'href'>;
|
|
15
|
+
export declare const Link: React.ForwardRefExoticComponent<Omit<LinkProps, "ref"> & React.RefAttributes<HTMLAnchorElement>>;
|
|
16
|
+
export {};
|
package/Link/Link.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["to", "linkAs", "replace", "scroll", "shallow", "prefetch", "legacyBehavior", "locale"],
|
|
4
|
+
_excluded2 = ["activeClassName", "as", "className", "href", "legacyBehavior", "linkAs", "locale", "noLinkStyle", "prefetch", "replace", "role", "scroll", "shallow"];
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
import clsx from 'clsx';
|
|
7
|
+
import { useRouter } from 'next/router';
|
|
8
|
+
import NextLink from 'next/link';
|
|
9
|
+
import MuiLink from '@mui/material/Link';
|
|
10
|
+
import { styled } from '@mui/material/styles';
|
|
11
|
+
import { useUserLanguage } from '../i18n';
|
|
12
|
+
import { useDocsConfig } from '../DocsProvider';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* File to keep in sync with:
|
|
16
|
+
*
|
|
17
|
+
* - /docs/src/modules/components/Link.tsx
|
|
18
|
+
* - /examples/material-ui-nextjs-pages-router/src/Link.js
|
|
19
|
+
* - /examples/material-ui-nextjs-pages-router-ts/src/Link.tsx
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
// Add support for the sx prop for consistency with the other branches.
|
|
23
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
|
+
const Anchor = styled('a')({});
|
|
25
|
+
const NextLinkComposed = /*#__PURE__*/React.forwardRef(function NextLinkComposed(props, ref) {
|
|
26
|
+
const {
|
|
27
|
+
to,
|
|
28
|
+
linkAs,
|
|
29
|
+
replace,
|
|
30
|
+
scroll,
|
|
31
|
+
shallow,
|
|
32
|
+
prefetch,
|
|
33
|
+
legacyBehavior = true,
|
|
34
|
+
locale
|
|
35
|
+
} = props,
|
|
36
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
37
|
+
return /*#__PURE__*/_jsx(NextLink, {
|
|
38
|
+
href: to,
|
|
39
|
+
prefetch: prefetch,
|
|
40
|
+
as: linkAs,
|
|
41
|
+
replace: replace,
|
|
42
|
+
scroll: scroll,
|
|
43
|
+
shallow: shallow,
|
|
44
|
+
passHref: true,
|
|
45
|
+
locale: locale,
|
|
46
|
+
legacyBehavior: legacyBehavior,
|
|
47
|
+
children: /*#__PURE__*/_jsx(Anchor, _extends({
|
|
48
|
+
"data-no-markdown-link": "true",
|
|
49
|
+
ref: ref
|
|
50
|
+
}, other))
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
// A styled version of the Next.js Pages Router Link component:
|
|
54
|
+
// https://nextjs.org/docs/pages/api-reference/components/link
|
|
55
|
+
export const Link = /*#__PURE__*/React.forwardRef(function Link(props, ref) {
|
|
56
|
+
const {
|
|
57
|
+
activeClassName = 'active',
|
|
58
|
+
as,
|
|
59
|
+
className: classNameProps,
|
|
60
|
+
href,
|
|
61
|
+
legacyBehavior,
|
|
62
|
+
linkAs: linkAsProp,
|
|
63
|
+
locale,
|
|
64
|
+
noLinkStyle,
|
|
65
|
+
prefetch,
|
|
66
|
+
replace,
|
|
67
|
+
// Link don't have roles.
|
|
68
|
+
scroll,
|
|
69
|
+
shallow
|
|
70
|
+
} = props,
|
|
71
|
+
other = _objectWithoutPropertiesLoose(props, _excluded2);
|
|
72
|
+
const router = useRouter();
|
|
73
|
+
const pathname = typeof href === 'string' ? href : href == null ? void 0 : href.pathname;
|
|
74
|
+
const routerPathname = router.pathname.replace('/[docsTab]', '');
|
|
75
|
+
const shouldBeActive = routerPathname === pathname;
|
|
76
|
+
const className = clsx(classNameProps, shouldBeActive && activeClassName);
|
|
77
|
+
const userLanguage = useUserLanguage();
|
|
78
|
+
const {
|
|
79
|
+
LANGUAGES_IGNORE_PAGES
|
|
80
|
+
} = useDocsConfig();
|
|
81
|
+
let linkAs = linkAsProp || as || href;
|
|
82
|
+
if (userLanguage !== 'en' && pathname && pathname.indexOf('/') === 0 && !LANGUAGES_IGNORE_PAGES(pathname) && !pathname.startsWith(`/${userLanguage}/`)) {
|
|
83
|
+
linkAs = `/${userLanguage}${linkAs}`;
|
|
84
|
+
}
|
|
85
|
+
const nextjsProps = {
|
|
86
|
+
to: href,
|
|
87
|
+
linkAs,
|
|
88
|
+
replace,
|
|
89
|
+
scroll,
|
|
90
|
+
shallow,
|
|
91
|
+
legacyBehavior,
|
|
92
|
+
prefetch,
|
|
93
|
+
locale
|
|
94
|
+
};
|
|
95
|
+
if (noLinkStyle) {
|
|
96
|
+
return /*#__PURE__*/_jsx(NextLinkComposed, _extends({
|
|
97
|
+
className: className,
|
|
98
|
+
ref: ref
|
|
99
|
+
}, nextjsProps, other));
|
|
100
|
+
}
|
|
101
|
+
return /*#__PURE__*/_jsx(MuiLink, _extends({
|
|
102
|
+
component: NextLinkComposed,
|
|
103
|
+
className: className,
|
|
104
|
+
ref: ref
|
|
105
|
+
}, nextjsProps, other));
|
|
106
|
+
});
|
package/Link/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Link';
|
package/Link/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Link';
|
package/i18n/i18n.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
export interface UserLanguageProviderProps {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
translations?: Translations;
|
|
6
|
+
defaultUserLanguage: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function UserLanguageProvider(props: UserLanguageProviderProps): React.JSX.Element;
|
|
9
|
+
export declare namespace UserLanguageProvider {
|
|
10
|
+
var propTypes: {
|
|
11
|
+
children: PropTypes.Validator<NonNullable<PropTypes.ReactNodeLike>>;
|
|
12
|
+
defaultUserLanguage: PropTypes.Requireable<string>;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export declare function useUserLanguage(): string;
|
|
16
|
+
export declare function useSetUserLanguage(): React.Dispatch<React.SetStateAction<string>>;
|
|
17
|
+
export interface TranslateOptions {
|
|
18
|
+
ignoreWarning?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare function useTranslate(): (key: string, options?: TranslateOptions) => any;
|
|
21
|
+
export type Translations = {
|
|
22
|
+
[key in string]?: string | Translations;
|
|
23
|
+
};
|
|
24
|
+
export interface RequireContext {
|
|
25
|
+
(req: string): string;
|
|
26
|
+
keys: () => string[];
|
|
27
|
+
}
|
|
28
|
+
export declare function mapTranslations(req: RequireContext): Translations;
|
package/i18n/i18n.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { deepmerge } from '@mui/utils';
|
|
4
|
+
import defaultTranslations from '../translations';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
const TranslationsContext = /*#__PURE__*/React.createContext(defaultTranslations);
|
|
7
|
+
function TranslationsProvider({
|
|
8
|
+
translations = {},
|
|
9
|
+
children
|
|
10
|
+
}) {
|
|
11
|
+
const currentTranslations = React.useContext(TranslationsContext);
|
|
12
|
+
const mergedTranslations = React.useMemo(() => deepmerge(currentTranslations, translations), [currentTranslations, translations]);
|
|
13
|
+
return /*#__PURE__*/_jsx(TranslationsContext.Provider, {
|
|
14
|
+
value: mergedTranslations,
|
|
15
|
+
children: children
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function getPath(obj, path) {
|
|
19
|
+
if (!path || typeof path !== 'string') {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return path.split('.').reduce((acc, item) => acc && acc[item] ? acc[item] : null, obj);
|
|
23
|
+
}
|
|
24
|
+
const UserLanguageContext = /*#__PURE__*/React.createContext({
|
|
25
|
+
userLanguage: '',
|
|
26
|
+
setUserLanguage: () => {}
|
|
27
|
+
});
|
|
28
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
29
|
+
UserLanguageContext.displayName = 'UserLanguage';
|
|
30
|
+
}
|
|
31
|
+
export function UserLanguageProvider(props) {
|
|
32
|
+
const {
|
|
33
|
+
children,
|
|
34
|
+
translations,
|
|
35
|
+
defaultUserLanguage
|
|
36
|
+
} = props;
|
|
37
|
+
const [userLanguage, setUserLanguage] = React.useState(defaultUserLanguage);
|
|
38
|
+
const contextValue = React.useMemo(() => {
|
|
39
|
+
return {
|
|
40
|
+
userLanguage,
|
|
41
|
+
setUserLanguage
|
|
42
|
+
};
|
|
43
|
+
}, [userLanguage]);
|
|
44
|
+
return /*#__PURE__*/_jsx(TranslationsProvider, {
|
|
45
|
+
translations: translations,
|
|
46
|
+
children: /*#__PURE__*/_jsx(UserLanguageContext.Provider, {
|
|
47
|
+
value: contextValue,
|
|
48
|
+
children: children
|
|
49
|
+
})
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
process.env.NODE_ENV !== "production" ? UserLanguageProvider.propTypes = {
|
|
53
|
+
children: PropTypes.node.isRequired,
|
|
54
|
+
defaultUserLanguage: PropTypes.string
|
|
55
|
+
} : void 0;
|
|
56
|
+
export function useUserLanguage() {
|
|
57
|
+
return React.useContext(UserLanguageContext).userLanguage;
|
|
58
|
+
}
|
|
59
|
+
export function useSetUserLanguage() {
|
|
60
|
+
return React.useContext(UserLanguageContext).setUserLanguage;
|
|
61
|
+
}
|
|
62
|
+
const warnedOnce = {};
|
|
63
|
+
export function useTranslate() {
|
|
64
|
+
const userLanguage = useUserLanguage();
|
|
65
|
+
const translations = React.useContext(TranslationsContext);
|
|
66
|
+
return React.useMemo(() => function translate(key, options = {}) {
|
|
67
|
+
const {
|
|
68
|
+
ignoreWarning = false
|
|
69
|
+
} = options;
|
|
70
|
+
const wordings = translations[userLanguage];
|
|
71
|
+
if (!wordings) {
|
|
72
|
+
console.error(`Missing language: ${userLanguage}.`);
|
|
73
|
+
return '…';
|
|
74
|
+
}
|
|
75
|
+
const translation = getPath(wordings, key);
|
|
76
|
+
if (!translation) {
|
|
77
|
+
const fullKey = `${userLanguage}:${key}`;
|
|
78
|
+
// No warnings in CI env
|
|
79
|
+
if (!ignoreWarning && !warnedOnce[fullKey] && typeof window !== 'undefined') {
|
|
80
|
+
console.error(`Missing translation for ${fullKey}`);
|
|
81
|
+
warnedOnce[fullKey] = true;
|
|
82
|
+
}
|
|
83
|
+
return getPath(translations.en, key);
|
|
84
|
+
}
|
|
85
|
+
return translation;
|
|
86
|
+
}, [userLanguage, translations]);
|
|
87
|
+
}
|
|
88
|
+
export function mapTranslations(req) {
|
|
89
|
+
const result = {};
|
|
90
|
+
req.keys().forEach(filename => {
|
|
91
|
+
const match = filename.match(/-([a-z]{2}).json$/);
|
|
92
|
+
if (match) {
|
|
93
|
+
result[match[1]] = req(filename);
|
|
94
|
+
} else {
|
|
95
|
+
result.en = req(filename);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
return result;
|
|
99
|
+
}
|
package/i18n/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './i18n';
|
package/i18n/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './i18n';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { UserLanguageProvider } from '../i18n';
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
var DocsConfigContext = /*#__PURE__*/React.createContext(null);
|
|
5
|
+
export function DocsProvider(_ref) {
|
|
6
|
+
var config = _ref.config,
|
|
7
|
+
defaultUserLanguage = _ref.defaultUserLanguage,
|
|
8
|
+
translations = _ref.translations,
|
|
9
|
+
children = _ref.children;
|
|
10
|
+
return /*#__PURE__*/_jsx(DocsConfigContext.Provider, {
|
|
11
|
+
value: config,
|
|
12
|
+
children: /*#__PURE__*/_jsx(UserLanguageProvider, {
|
|
13
|
+
defaultUserLanguage: defaultUserLanguage,
|
|
14
|
+
translations: translations,
|
|
15
|
+
children: children
|
|
16
|
+
})
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export function useDocsConfig() {
|
|
20
|
+
var config = React.useContext(DocsConfigContext);
|
|
21
|
+
if (!config) {
|
|
22
|
+
throw new Error('Could not find docs config context value; please ensure the component is wrapped in a <DocsProvider>');
|
|
23
|
+
}
|
|
24
|
+
return config;
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './DocsProvider';
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import clsx from 'clsx';
|
|
5
|
+
import { useRouter } from 'next/router';
|
|
6
|
+
import NextLink from 'next/link';
|
|
7
|
+
import MuiLink from '@mui/material/Link';
|
|
8
|
+
import { styled } from '@mui/material/styles';
|
|
9
|
+
import { useUserLanguage } from '../i18n';
|
|
10
|
+
import { useDocsConfig } from '../DocsProvider';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* File to keep in sync with:
|
|
14
|
+
*
|
|
15
|
+
* - /docs/src/modules/components/Link.tsx
|
|
16
|
+
* - /examples/material-ui-nextjs-pages-router/src/Link.js
|
|
17
|
+
* - /examples/material-ui-nextjs-pages-router-ts/src/Link.tsx
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
// Add support for the sx prop for consistency with the other branches.
|
|
21
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
|
+
var Anchor = styled('a')({});
|
|
23
|
+
var NextLinkComposed = /*#__PURE__*/React.forwardRef(function NextLinkComposed(props, ref) {
|
|
24
|
+
var to = props.to,
|
|
25
|
+
linkAs = props.linkAs,
|
|
26
|
+
replace = props.replace,
|
|
27
|
+
scroll = props.scroll,
|
|
28
|
+
shallow = props.shallow,
|
|
29
|
+
prefetch = props.prefetch,
|
|
30
|
+
_props$legacyBehavior = props.legacyBehavior,
|
|
31
|
+
legacyBehavior = _props$legacyBehavior === void 0 ? true : _props$legacyBehavior,
|
|
32
|
+
locale = props.locale,
|
|
33
|
+
other = _objectWithoutProperties(props, ["to", "linkAs", "replace", "scroll", "shallow", "prefetch", "legacyBehavior", "locale"]);
|
|
34
|
+
return /*#__PURE__*/_jsx(NextLink, {
|
|
35
|
+
href: to,
|
|
36
|
+
prefetch: prefetch,
|
|
37
|
+
as: linkAs,
|
|
38
|
+
replace: replace,
|
|
39
|
+
scroll: scroll,
|
|
40
|
+
shallow: shallow,
|
|
41
|
+
passHref: true,
|
|
42
|
+
locale: locale,
|
|
43
|
+
legacyBehavior: legacyBehavior,
|
|
44
|
+
children: /*#__PURE__*/_jsx(Anchor, _extends({
|
|
45
|
+
"data-no-markdown-link": "true",
|
|
46
|
+
ref: ref
|
|
47
|
+
}, other))
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
// A styled version of the Next.js Pages Router Link component:
|
|
51
|
+
// https://nextjs.org/docs/pages/api-reference/components/link
|
|
52
|
+
export var Link = /*#__PURE__*/React.forwardRef(function Link(props, ref) {
|
|
53
|
+
var _props$activeClassNam = props.activeClassName,
|
|
54
|
+
activeClassName = _props$activeClassNam === void 0 ? 'active' : _props$activeClassNam,
|
|
55
|
+
as = props.as,
|
|
56
|
+
classNameProps = props.className,
|
|
57
|
+
href = props.href,
|
|
58
|
+
legacyBehavior = props.legacyBehavior,
|
|
59
|
+
linkAsProp = props.linkAs,
|
|
60
|
+
locale = props.locale,
|
|
61
|
+
noLinkStyle = props.noLinkStyle,
|
|
62
|
+
prefetch = props.prefetch,
|
|
63
|
+
replace = props.replace,
|
|
64
|
+
role = props.role,
|
|
65
|
+
scroll = props.scroll,
|
|
66
|
+
shallow = props.shallow,
|
|
67
|
+
other = _objectWithoutProperties(props, ["activeClassName", "as", "className", "href", "legacyBehavior", "linkAs", "locale", "noLinkStyle", "prefetch", "replace", "role", "scroll", "shallow"]);
|
|
68
|
+
var router = useRouter();
|
|
69
|
+
var pathname = typeof href === 'string' ? href : href == null ? void 0 : href.pathname;
|
|
70
|
+
var routerPathname = router.pathname.replace('/[docsTab]', '');
|
|
71
|
+
var shouldBeActive = routerPathname === pathname;
|
|
72
|
+
var className = clsx(classNameProps, shouldBeActive && activeClassName);
|
|
73
|
+
var userLanguage = useUserLanguage();
|
|
74
|
+
var _useDocsConfig = useDocsConfig(),
|
|
75
|
+
LANGUAGES_IGNORE_PAGES = _useDocsConfig.LANGUAGES_IGNORE_PAGES;
|
|
76
|
+
var linkAs = linkAsProp || as || href;
|
|
77
|
+
if (userLanguage !== 'en' && pathname && pathname.indexOf('/') === 0 && !LANGUAGES_IGNORE_PAGES(pathname) && !pathname.startsWith("/".concat(userLanguage, "/"))) {
|
|
78
|
+
linkAs = "/".concat(userLanguage).concat(linkAs);
|
|
79
|
+
}
|
|
80
|
+
var nextjsProps = {
|
|
81
|
+
to: href,
|
|
82
|
+
linkAs: linkAs,
|
|
83
|
+
replace: replace,
|
|
84
|
+
scroll: scroll,
|
|
85
|
+
shallow: shallow,
|
|
86
|
+
legacyBehavior: legacyBehavior,
|
|
87
|
+
prefetch: prefetch,
|
|
88
|
+
locale: locale
|
|
89
|
+
};
|
|
90
|
+
if (noLinkStyle) {
|
|
91
|
+
return /*#__PURE__*/_jsx(NextLinkComposed, _extends({
|
|
92
|
+
className: className,
|
|
93
|
+
ref: ref
|
|
94
|
+
}, nextjsProps, other));
|
|
95
|
+
}
|
|
96
|
+
return /*#__PURE__*/_jsx(MuiLink, _extends({
|
|
97
|
+
component: NextLinkComposed,
|
|
98
|
+
className: className,
|
|
99
|
+
ref: ref
|
|
100
|
+
}, nextjsProps, other));
|
|
101
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Link';
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { deepmerge } from '@mui/utils';
|
|
4
|
+
import defaultTranslations from '../translations';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
var TranslationsContext = /*#__PURE__*/React.createContext(defaultTranslations);
|
|
7
|
+
function TranslationsProvider(_ref) {
|
|
8
|
+
var _ref$translations = _ref.translations,
|
|
9
|
+
translations = _ref$translations === void 0 ? {} : _ref$translations,
|
|
10
|
+
children = _ref.children;
|
|
11
|
+
var currentTranslations = React.useContext(TranslationsContext);
|
|
12
|
+
var mergedTranslations = React.useMemo(function () {
|
|
13
|
+
return deepmerge(currentTranslations, translations);
|
|
14
|
+
}, [currentTranslations, translations]);
|
|
15
|
+
return /*#__PURE__*/_jsx(TranslationsContext.Provider, {
|
|
16
|
+
value: mergedTranslations,
|
|
17
|
+
children: children
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function getPath(obj, path) {
|
|
21
|
+
if (!path || typeof path !== 'string') {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return path.split('.').reduce(function (acc, item) {
|
|
25
|
+
return acc && acc[item] ? acc[item] : null;
|
|
26
|
+
}, obj);
|
|
27
|
+
}
|
|
28
|
+
var UserLanguageContext = /*#__PURE__*/React.createContext({
|
|
29
|
+
userLanguage: '',
|
|
30
|
+
setUserLanguage: function setUserLanguage() {}
|
|
31
|
+
});
|
|
32
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
33
|
+
UserLanguageContext.displayName = 'UserLanguage';
|
|
34
|
+
}
|
|
35
|
+
export function UserLanguageProvider(props) {
|
|
36
|
+
var children = props.children,
|
|
37
|
+
translations = props.translations,
|
|
38
|
+
defaultUserLanguage = props.defaultUserLanguage;
|
|
39
|
+
var _React$useState = React.useState(defaultUserLanguage),
|
|
40
|
+
userLanguage = _React$useState[0],
|
|
41
|
+
setUserLanguage = _React$useState[1];
|
|
42
|
+
var contextValue = React.useMemo(function () {
|
|
43
|
+
return {
|
|
44
|
+
userLanguage: userLanguage,
|
|
45
|
+
setUserLanguage: setUserLanguage
|
|
46
|
+
};
|
|
47
|
+
}, [userLanguage]);
|
|
48
|
+
return /*#__PURE__*/_jsx(TranslationsProvider, {
|
|
49
|
+
translations: translations,
|
|
50
|
+
children: /*#__PURE__*/_jsx(UserLanguageContext.Provider, {
|
|
51
|
+
value: contextValue,
|
|
52
|
+
children: children
|
|
53
|
+
})
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
process.env.NODE_ENV !== "production" ? UserLanguageProvider.propTypes = {
|
|
57
|
+
children: PropTypes.node.isRequired,
|
|
58
|
+
defaultUserLanguage: PropTypes.string
|
|
59
|
+
} : void 0;
|
|
60
|
+
export function useUserLanguage() {
|
|
61
|
+
return React.useContext(UserLanguageContext).userLanguage;
|
|
62
|
+
}
|
|
63
|
+
export function useSetUserLanguage() {
|
|
64
|
+
return React.useContext(UserLanguageContext).setUserLanguage;
|
|
65
|
+
}
|
|
66
|
+
var warnedOnce = {};
|
|
67
|
+
export function useTranslate() {
|
|
68
|
+
var userLanguage = useUserLanguage();
|
|
69
|
+
var translations = React.useContext(TranslationsContext);
|
|
70
|
+
return React.useMemo(function () {
|
|
71
|
+
return function translate(key) {
|
|
72
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
73
|
+
var _options$ignoreWarnin = options.ignoreWarning,
|
|
74
|
+
ignoreWarning = _options$ignoreWarnin === void 0 ? false : _options$ignoreWarnin;
|
|
75
|
+
var wordings = translations[userLanguage];
|
|
76
|
+
if (!wordings) {
|
|
77
|
+
console.error("Missing language: ".concat(userLanguage, "."));
|
|
78
|
+
return '…';
|
|
79
|
+
}
|
|
80
|
+
var translation = getPath(wordings, key);
|
|
81
|
+
if (!translation) {
|
|
82
|
+
var fullKey = "".concat(userLanguage, ":").concat(key);
|
|
83
|
+
// No warnings in CI env
|
|
84
|
+
if (!ignoreWarning && !warnedOnce[fullKey] && typeof window !== 'undefined') {
|
|
85
|
+
console.error("Missing translation for ".concat(fullKey));
|
|
86
|
+
warnedOnce[fullKey] = true;
|
|
87
|
+
}
|
|
88
|
+
return getPath(translations.en, key);
|
|
89
|
+
}
|
|
90
|
+
return translation;
|
|
91
|
+
};
|
|
92
|
+
}, [userLanguage, translations]);
|
|
93
|
+
}
|
|
94
|
+
export function mapTranslations(req) {
|
|
95
|
+
var result = {};
|
|
96
|
+
req.keys().forEach(function (filename) {
|
|
97
|
+
var match = filename.match(/-([a-z]{2}).json$/);
|
|
98
|
+
if (match) {
|
|
99
|
+
result[match[1]] = req(filename);
|
|
100
|
+
} else {
|
|
101
|
+
result.en = req(filename);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './i18n';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DocsProvider = DocsProvider;
|
|
7
|
+
exports.useDocsConfig = useDocsConfig;
|
|
8
|
+
var React = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _i18n = require("../i18n");
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
|
+
const DocsConfigContext = /*#__PURE__*/React.createContext(null);
|
|
14
|
+
function DocsProvider({
|
|
15
|
+
config,
|
|
16
|
+
defaultUserLanguage,
|
|
17
|
+
translations,
|
|
18
|
+
children
|
|
19
|
+
}) {
|
|
20
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(DocsConfigContext.Provider, {
|
|
21
|
+
value: config,
|
|
22
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_i18n.UserLanguageProvider, {
|
|
23
|
+
defaultUserLanguage: defaultUserLanguage,
|
|
24
|
+
translations: translations,
|
|
25
|
+
children: children
|
|
26
|
+
})
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function useDocsConfig() {
|
|
30
|
+
const config = React.useContext(DocsConfigContext);
|
|
31
|
+
if (!config) {
|
|
32
|
+
throw new Error('Could not find docs config context value; please ensure the component is wrapped in a <DocsProvider>');
|
|
33
|
+
}
|
|
34
|
+
return config;
|
|
35
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _DocsProvider = require("./DocsProvider");
|
|
7
|
+
Object.keys(_DocsProvider).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _DocsProvider[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _DocsProvider[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|