etudes 2.2.0 → 2.3.0

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.
@@ -137,5 +137,5 @@ declare const _default: <T>(props: React.HTMLAttributes<HTMLDivElement> & {
137
137
  ref?: React.Ref<HTMLDivElement> | undefined;
138
138
  }) => ReactElement;
139
139
  export default _default;
140
- export declare const AccordionHeader: ({ ...props }: HTMLAttributes<HTMLButtonElement>) => JSX.Element;
141
- export declare const AccordionExpandIcon: ({ ...props }: HTMLAttributes<HTMLDivElement>) => JSX.Element;
140
+ export declare const AccordionHeader: ({ ...props }: HTMLAttributes<HTMLButtonElement>) => React.JSX.Element;
141
+ export declare const AccordionExpandIcon: ({ ...props }: HTMLAttributes<HTMLDivElement>) => React.JSX.Element;
@@ -30,4 +30,4 @@ declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTM
30
30
  children?: React.ReactNode;
31
31
  } & React.RefAttributes<HTMLButtonElement>>;
32
32
  export default _default;
33
- export declare const BurgerButtonBar: ({ ...props }: HTMLAttributes<HTMLSpanElement>) => JSX.Element;
33
+ export declare const BurgerButtonBar: ({ ...props }: HTMLAttributes<HTMLSpanElement>) => React.JSX.Element;
@@ -1,5 +1,5 @@
1
- import { PropsWithChildren } from 'react';
1
+ import React, { PropsWithChildren } from 'react';
2
2
  export type ConditionalProps = PropsWithChildren<{
3
3
  if: boolean | (() => boolean);
4
4
  }>;
5
- export default function Conditional({ children, if: boolOrExpression }: ConditionalProps): JSX.Element;
5
+ export default function Conditional({ children, if: boolOrExpression }: ConditionalProps): React.JSX.Element;
package/lib/Dial.d.ts CHANGED
@@ -72,5 +72,5 @@ declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTM
72
72
  children?: React.ReactNode;
73
73
  } & React.RefAttributes<HTMLDivElement>>;
74
74
  export default _default;
75
- export declare const DialTrack: ({ ...props }: SVGAttributes<SVGCircleElement>) => JSX.Element;
76
- export declare const DialKnob: ({ ...props }: SVGAttributes<SVGPathElement>) => JSX.Element;
75
+ export declare const DialTrack: ({ ...props }: SVGAttributes<SVGCircleElement>) => React.JSX.Element;
76
+ export declare const DialKnob: ({ ...props }: SVGAttributes<SVGPathElement>) => React.JSX.Element;
package/lib/Dropdown.d.ts CHANGED
@@ -143,5 +143,5 @@ declare const _default: <T extends DropdownData = DropdownData>(props: React.HTM
143
143
  ref?: React.Ref<HTMLDivElement> | undefined;
144
144
  }) => ReactElement;
145
145
  export default _default;
146
- export declare const DropdownToggle: ({ ...props }: HTMLAttributes<HTMLButtonElement>) => JSX.Element;
147
- export declare const DropdownExpandIcon: ({ ...props }: HTMLAttributes<HTMLDivElement>) => JSX.Element;
146
+ export declare const DropdownToggle: ({ ...props }: HTMLAttributes<HTMLButtonElement>) => React.JSX.Element;
147
+ export declare const DropdownExpandIcon: ({ ...props }: HTMLAttributes<HTMLDivElement>) => React.JSX.Element;
package/lib/Each.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { ReactNode } from 'react';
1
+ import React, { ReactNode } from 'react';
2
2
  export type EachProps<T> = {
3
3
  children?: ReactNode | ((value: T, index: number) => ReactNode);
4
4
  in?: T[];
5
5
  render?: (value: T, index: number) => ReactNode;
6
6
  };
7
- export default function Each<T>({ in: array, children, render, }: EachProps<T>): JSX.Element;
7
+ export default function Each<T>({ in: array, children, render, }: EachProps<T>): React.JSX.Element;
@@ -1,6 +1,6 @@
1
- import { HTMLAttributes } from 'react';
1
+ import React, { HTMLAttributes } from 'react';
2
2
  export type ExtractChildrenProps = HTMLAttributes<HTMLElement>;
3
3
  /**
4
4
  * Extracts all children of a parent component into its own component.
5
5
  */
6
- export default function ExtractChildren({ children, ...props }: ExtractChildrenProps): JSX.Element;
6
+ export default function ExtractChildren({ children, ...props }: ExtractChildrenProps): React.JSX.Element;
@@ -73,6 +73,6 @@ declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTM
73
73
  children?: React.ReactNode;
74
74
  } & React.RefAttributes<HTMLDivElement>>;
75
75
  export default _default;
76
- export declare const PanoramaSliderTrack: ({ ...props }: HTMLAttributes<HTMLDivElement>) => JSX.Element;
77
- export declare const PanoramaSliderReticle: ({ ...props }: HTMLAttributes<HTMLDivElement>) => JSX.Element;
78
- export declare const PanoramaSliderIndicator: ({ ...props }: HTMLAttributes<HTMLDivElement>) => JSX.Element;
76
+ export declare const PanoramaSliderTrack: ({ ...props }: HTMLAttributes<HTMLDivElement>) => React.JSX.Element;
77
+ export declare const PanoramaSliderReticle: ({ ...props }: HTMLAttributes<HTMLDivElement>) => React.JSX.Element;
78
+ export declare const PanoramaSliderIndicator: ({ ...props }: HTMLAttributes<HTMLDivElement>) => React.JSX.Element;
@@ -26,7 +26,7 @@ declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTM
26
26
  children?: React.ReactNode;
27
27
  } & React.RefAttributes<HTMLDivElement>>;
28
28
  export default _default;
29
- export declare const RangeSliderGutter: ({ ...props }: HTMLAttributes<HTMLDivElement>) => JSX.Element;
30
- export declare const RangeSliderLabel: ({ ...props }: HTMLAttributes<HTMLDivElement>) => JSX.Element;
31
- export declare const RangeSliderHighlight: ({ ...props }: HTMLAttributes<HTMLDivElement>) => JSX.Element;
29
+ export declare const RangeSliderGutter: ({ ...props }: HTMLAttributes<HTMLDivElement>) => React.JSX.Element;
30
+ export declare const RangeSliderLabel: ({ ...props }: HTMLAttributes<HTMLDivElement>) => React.JSX.Element;
31
+ export declare const RangeSliderHighlight: ({ ...props }: HTMLAttributes<HTMLDivElement>) => React.JSX.Element;
32
32
  export declare const RangeSliderKnob: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
package/lib/Repeat.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ReactNode } from 'react';
1
+ import React, { ReactNode } from 'react';
2
2
  export type RepeatProps = {
3
3
  children?: ReactNode | ((index: number) => ReactNode);
4
4
  count?: number;
@@ -8,4 +8,4 @@ export type RepeatProps = {
8
8
  * A tag-less component that repeats its children, automatically assigning each
9
9
  * a unique key.
10
10
  */
11
- export default function Repeat({ count, children, render, }: RepeatProps): JSX.Element;
11
+ export default function Repeat({ count, children, render, }: RepeatProps): React.JSX.Element;
@@ -64,4 +64,4 @@ declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTM
64
64
  children?: React.ReactNode;
65
65
  } & React.RefAttributes<HTMLDivElement>>;
66
66
  export default _default;
67
- export declare const RotatingGalleryImage: ({ ...props }: HTMLAttributes<HTMLDivElement>) => JSX.Element;
67
+ export declare const RotatingGalleryImage: ({ ...props }: HTMLAttributes<HTMLDivElement>) => React.JSX.Element;
package/lib/Slider.d.ts CHANGED
@@ -147,6 +147,6 @@ declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTM
147
147
  children?: React.ReactNode;
148
148
  } & React.RefAttributes<HTMLDivElement>>;
149
149
  export default _default;
150
- export declare const SliderTrack: ({ ...props }: HTMLAttributes<HTMLDivElement>) => JSX.Element;
151
- export declare const SliderKnob: ({ ...props }: HTMLAttributes<HTMLDivElement>) => JSX.Element;
152
- export declare const SliderLabel: ({ ...props }: HTMLAttributes<HTMLDivElement>) => JSX.Element;
150
+ export declare const SliderTrack: ({ ...props }: HTMLAttributes<HTMLDivElement>) => React.JSX.Element;
151
+ export declare const SliderKnob: ({ ...props }: HTMLAttributes<HTMLDivElement>) => React.JSX.Element;
152
+ export declare const SliderLabel: ({ ...props }: HTMLAttributes<HTMLDivElement>) => React.JSX.Element;
@@ -193,9 +193,9 @@ declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTM
193
193
  children?: React.ReactNode;
194
194
  } & React.RefAttributes<HTMLDivElement>>;
195
195
  export default _default;
196
- export declare const StepwiseSliderTrack: ({ ...props }: HTMLAttributes<HTMLDivElement>) => JSX.Element;
197
- export declare const StepwiseSliderKnob: ({ ...props }: HTMLAttributes<HTMLDivElement>) => JSX.Element;
198
- export declare const StepwiseSliderLabel: ({ ...props }: HTMLAttributes<HTMLDivElement>) => JSX.Element;
196
+ export declare const StepwiseSliderTrack: ({ ...props }: HTMLAttributes<HTMLDivElement>) => React.JSX.Element;
197
+ export declare const StepwiseSliderKnob: ({ ...props }: HTMLAttributes<HTMLDivElement>) => React.JSX.Element;
198
+ export declare const StepwiseSliderLabel: ({ ...props }: HTMLAttributes<HTMLDivElement>) => React.JSX.Element;
199
199
  /**
200
200
  * Generates a set of steps compatible with this component.
201
201
  *
@@ -1,4 +1,4 @@
1
- import { HTMLAttributes, PropsWithChildren } from 'react';
1
+ import React, { HTMLAttributes, PropsWithChildren } from 'react';
2
2
  export type WithToolTipProps = Pick<HTMLAttributes<HTMLElement>, 'className' | 'style'> & PropsWithChildren<{
3
3
  /**
4
4
  * The height of the arrow. The width (longest edge) of the arrow is always
@@ -34,4 +34,4 @@ export type WithToolTipProps = Pick<HTMLAttributes<HTMLElement>, 'className' | '
34
34
  */
35
35
  threshold?: number;
36
36
  }>;
37
- export default function WithTooltip({ children, className, style, arrowHeight, backgroundColor, gap, hint, maxTextWidth, threshold, }: WithToolTipProps): JSX.Element;
37
+ export default function WithTooltip({ children, className, style, arrowHeight, backgroundColor, gap, hint, maxTextWidth, threshold, }: WithToolTipProps): React.JSX.Element;
@@ -10,6 +10,6 @@ type ScrollPositionContextValue = ScrollPosition & {
10
10
  };
11
11
  type ScrollPositionProviderProps = PropsWithChildren;
12
12
  export declare const ScrollPositionContext: React.Context<ScrollPositionContextValue | undefined>;
13
- export default function ScrollPositionProvider({ children, }: ScrollPositionProviderProps): JSX.Element;
13
+ export default function ScrollPositionProvider({ children, }: ScrollPositionProviderProps): React.JSX.Element;
14
14
  export declare function useScrollPosition(targetRef?: RefObject<Element>): ScrollPosition;
15
15
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "etudes",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "A study of headless React components",
5
5
  "main": "lib",
6
6
  "scripts": {
@@ -29,47 +29,46 @@
29
29
  "lib"
30
30
  ],
31
31
  "devDependencies": {
32
- "@babel/core": "^7.20.12",
33
- "@babel/plugin-transform-runtime": "^7.19.6",
34
- "@babel/preset-env": "^7.20.2",
35
- "@babel/preset-react": "^7.18.6",
36
- "@babel/preset-typescript": "^7.18.6",
37
- "@types/debug": "^4.1.7",
32
+ "@babel/core": "^7.22.11",
33
+ "@babel/plugin-transform-runtime": "^7.22.10",
34
+ "@babel/preset-env": "^7.22.14",
35
+ "@babel/preset-react": "^7.22.5",
36
+ "@babel/preset-typescript": "^7.22.11",
37
+ "@types/debug": "^4.1.8",
38
38
  "@types/html-webpack-plugin": "^3.2.6",
39
39
  "@types/node-polyglot": "^2.4.2",
40
- "@types/react": "^18.0.27",
41
- "@types/react-dom": "^18.0.10",
42
- "@types/react-transition-group": "^4.4.5",
40
+ "@types/react": "^18.2.21",
41
+ "@types/react-dom": "^18.2.7",
42
+ "@types/react-transition-group": "^4.4.6",
43
43
  "@types/styled-components": "^5.1.26",
44
- "@types/webpack": "^5.28.0",
45
- "@types/webpack-env": "^1.18.0",
46
- "@typescript-eslint/eslint-plugin": "^5.50.0",
47
- "@typescript-eslint/parser": "^5.50.0",
48
- "babel-loader": "^9.1.2",
49
- "babel-plugin-styled-components": "^2.0.7",
50
- "concurrently": "^7.6.0",
44
+ "@types/webpack": "^5.28.2",
45
+ "@types/webpack-env": "^1.18.1",
46
+ "@typescript-eslint/eslint-plugin": "^6.5.0",
47
+ "@typescript-eslint/parser": "^6.5.0",
48
+ "babel-loader": "^9.1.3",
49
+ "babel-plugin-styled-components": "^2.1.4",
50
+ "concurrently": "^8.2.1",
51
51
  "cross-env": "^7.0.3",
52
52
  "debug": "^4.3.4",
53
- "eslint": "^8.33.0",
54
- "html-webpack-plugin": "^5.5.0",
53
+ "eslint": "^8.48.0",
54
+ "html-webpack-plugin": "^5.5.3",
55
55
  "react": "^18.2.0",
56
56
  "react-dom": "^18.2.0",
57
- "react-router": "^6.8.0",
58
- "react-router-dom": "^6.8.0",
59
- "rimraf": "^4.1.2",
60
- "styled-components": "^5.3.6",
57
+ "react-router": "^6.15.0",
58
+ "react-router-dom": "^6.15.0",
59
+ "rimraf": "^5.0.1",
60
+ "styled-components": "^6.0.7",
61
61
  "ts-node": "^10.9.1",
62
- "typescript": "^4.9.5",
62
+ "typescript": "^5.2.2",
63
63
  "wait-on": "^7.0.1",
64
- "webpack": "^5.75.0",
65
- "webpack-cli": "^5.0.1",
66
- "webpack-dev-server": "^4.11.1"
64
+ "webpack": "^5.88.2",
65
+ "webpack-cli": "^5.1.4",
66
+ "webpack-dev-server": "^4.15.1"
67
67
  },
68
68
  "dependencies": {
69
69
  "classnames": "^2.3.2",
70
70
  "fast-deep-equal": "^3.1.3",
71
- "interactjs": "^1.10.17",
72
- "node-polyglot": "^2.5.0",
71
+ "interactjs": "^1.10.18",
73
72
  "react-transition-group": "^4.4.5",
74
73
  "resize-observer-polyfill": "^1.5.1",
75
74
  "spase": "^6.5.0"
@@ -78,7 +77,7 @@
78
77
  "react": "^18.2.0"
79
78
  },
80
79
  "optionalDependencies": {
81
- "react-router": "^6.8.0",
82
- "react-router-dom": "^6.8.0"
80
+ "react-router": "^6.15.0",
81
+ "react-router-dom": "^6.15.0"
83
82
  }
84
83
  }
@@ -1,9 +0,0 @@
1
- import { DependencyList } from 'react';
2
- /**
3
- * Hook for adding document title. By default this hook is dependent on the
4
- * `title` only.
5
- *
6
- * @param title - The document title.
7
- * @param deps - Additional dependencies.
8
- */
9
- export default function useDocumentTitle(title: string, deps?: DependencyList): void;
@@ -1,42 +0,0 @@
1
- "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
- if (ar || !(i in from)) {
21
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
- ar[i] = from[i];
23
- }
24
- }
25
- return to.concat(ar || Array.prototype.slice.call(from));
26
- };
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- var react_1 = require("react");
29
- /**
30
- * Hook for adding document title. By default this hook is dependent on the
31
- * `title` only.
32
- *
33
- * @param title - The document title.
34
- * @param deps - Additional dependencies.
35
- */
36
- function useDocumentTitle(title, deps) {
37
- (0, react_1.useEffect)(function () {
38
- document.title = title;
39
- }, __spreadArray([title], __read(deps ? deps : []), false));
40
- }
41
- exports.default = useDocumentTitle;
42
- //# sourceMappingURL=useDocumentTitle.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useDocumentTitle.js","sourceRoot":"/","sources":["hooks/useDocumentTitle.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAiD;AAEjD;;;;;;GAMG;AACH,SAAwB,gBAAgB,CAAC,KAAa,EAAE,IAAqB;IAC3E,IAAA,iBAAS,EAAC;QACR,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAA;IACxB,CAAC,iBAAG,KAAK,UAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,UAAE,CAAA;AAClC,CAAC;AAJD,mCAIC","sourcesContent":["import { DependencyList, useEffect } from 'react'\n\n/**\n * Hook for adding document title. By default this hook is dependent on the\n * `title` only.\n *\n * @param title - The document title.\n * @param deps - Additional dependencies.\n */\nexport default function useDocumentTitle(title: string, deps?: DependencyList) {\n useEffect(() => {\n document.title = title\n }, [title, ...deps ? deps : []])\n}\n"]}
@@ -1,179 +0,0 @@
1
- import Polyglot from 'node-polyglot';
2
- import React, { Dispatch, PropsWithChildren } from 'react';
3
- interface Translation {
4
- [key: string]: Translation | string;
5
- }
6
- type I18nState = {
7
- changeLocaleStrategy: 'action' | 'path' | 'query';
8
- defaultLocale: string;
9
- locale: string;
10
- polyglots: Record<string, Polyglot>;
11
- supportedLocales: string[];
12
- getLocalizedPath?: (path: string) => string;
13
- getLocalizedString: typeof Polyglot.prototype.t;
14
- };
15
- type I18nContextValue = {
16
- state: I18nState;
17
- dispatch?: Dispatch<I18nChangeLocaleAction>;
18
- };
19
- type I18nProviderProps = PropsWithChildren<{
20
- changeLocaleStrategy?: I18nState['changeLocaleStrategy'];
21
- defaultLocale?: I18nState['defaultLocale'];
22
- translations: Record<string, Translation>;
23
- }>;
24
- type I18nChangeLocaleAction = {
25
- type: '@i18n/CHANGE_LOCALE';
26
- locale: string;
27
- };
28
- export declare const I18nContext: React.Context<I18nContextValue | undefined>;
29
- /**
30
- * Context provider whose value consists of the current i18n state. The method
31
- * of modifying the locale is specified by `changeLocaleStrategy`, as follows:
32
- * - If set to `action`, the locale can be modified by dispatching an action
33
- * - If set to `path`, the locale is inferred from the current path name
34
- * - If set to `query`, the locale is inferred from the search parameter
35
- * `locale` in the current path
36
- *
37
- * @param props - See {@link I18nProviderProps}.
38
- *
39
- * @returns The context provider.
40
- */
41
- export default function I18nProvider({ children, defaultLocale, translations, changeLocaleStrategy, }: I18nProviderProps): JSX.Element;
42
- /** @namespace Components */
43
- /**
44
- * Custom {@link Routes} container that generates child {@link Route} components
45
- * for all locales supported by {@link I18nProvider}.
46
- */
47
- export declare function I18nRoutes({ children }: PropsWithChildren): JSX.Element;
48
- /** @namespace Hooks */
49
- /**
50
- * Hook for retrieving the change locale function.
51
- *
52
- * @returns The change locale function.
53
- */
54
- export declare function useChangeLocale(): (locale: string) => void | undefined;
55
- /**
56
- * Hook for retrieving the current locale.
57
- *
58
- * @returns The current locale.
59
- */
60
- export declare function useLocale(): string;
61
- /**
62
- * Hook for retrieving the path localizing function for the current locale.
63
- *
64
- * @returns The path localizing function.
65
- */
66
- export declare function useLocalizedPath(): (path: string) => string;
67
- /**
68
- * Hook for retrieving the string localizing function for the current locale.
69
- *
70
- * @returns The string localizing function.
71
- */
72
- export declare function useLocalizedString(): (phrase: string, options?: number | Polyglot.InterpolationOptions | undefined) => string;
73
- /**
74
- * Hook for retrieving all supported locales.
75
- *
76
- * @returns All supported locales.
77
- */
78
- export declare function useSupportedLocales(): string[];
79
- /** @namespace Utilities */
80
- type URLParts = {
81
- base?: string;
82
- hash?: string;
83
- host?: string;
84
- path?: string;
85
- port?: string;
86
- protocol?: string;
87
- query?: string;
88
- };
89
- type ResolveLocaleOptions = {
90
- /**
91
- * The locale to fallback to if one cannot be inferred from the provided URL.
92
- */
93
- defaultLocale?: string;
94
- /**
95
- * An array of supported locales to validate the inferred locale against. If
96
- * it doesn't exist in the list of supported locales, the default locale (if
97
- * specified) or `undefined` will be returned.
98
- */
99
- supportedLocales?: string[];
100
- };
101
- type ResolveLocalizedURLOptions = ResolveLocaleOptions & {
102
- /**
103
- * Specifies where in the URL the locale should be matched. If `resolver` is
104
- * provided, this option is ignored.
105
- */
106
- resolveStrategy?: 'auto' | 'domain' | 'path' | 'query';
107
- /**
108
- * Custom resolver function.
109
- *
110
- * @param protocol - The matched protocol of the provided url, if available.
111
- * @param host - The matched host of the provided url, if available.
112
- * @param port - The matched port of the provided url, if available.
113
- * @param path - The matched path of the provided url, if available.
114
- *
115
- * @returns The resolved locale.
116
- */
117
- resolver?: (urlParts: URLParts) => string | undefined;
118
- };
119
- type LocalizedURLInfo = {
120
- /**
121
- * The matched locale.
122
- */
123
- locale: string;
124
- /**
125
- * Specifies where in the URL the locale was matched.
126
- */
127
- resolveStrategy: ResolveLocalizedURLOptions['resolveStrategy'] | 'custom';
128
- };
129
- /**
130
- * Resolves the specified locale with the provided options. All parameters are
131
- * optional.
132
- *
133
- * @param locale - The locale to resolve.
134
- * @param options - See {@link ResolveLocaleOptions}.
135
- *
136
- * @returns - The resolved locale.
137
- */
138
- export declare function resolveLocale(locale?: string, { defaultLocale, supportedLocales }?: ResolveLocaleOptions): string | undefined;
139
- /**
140
- * Retrieves the locale identifier from a URL. The default behavior of this
141
- * function to look for the locale identifier in the domain first followed by
142
- * the first directory of the path. You can provide a custom resolver.
143
- *
144
- * @param url - The URL, can be a full URL or a valid path.
145
- * @param options - See {@link ResolveLocalizedURLOptions}.
146
- *
147
- * @returns The inferred locale if it exists.
148
- */
149
- export declare function getLocaleFromURL(url: string, { defaultLocale, resolveStrategy, resolver, supportedLocales }?: ResolveLocalizedURLOptions): LocalizedURLInfo | undefined;
150
- /**
151
- * Returns the unlocalized version of a URL.
152
- *
153
- * @param url - The URL.
154
- * @param options - See {@link ResolveLocalizedURLOptions}.
155
- *
156
- * @returns The unlocalized URL.
157
- */
158
- export declare function getUnlocalizedURL(url: string, { resolveStrategy, resolver, supportedLocales }?: ResolveLocalizedURLOptions): string;
159
- /**
160
- * Returns the localized version of a URL.
161
- *
162
- * @param url - The URL.
163
- * @param locale - The target locale.
164
- * @param options - See {@link ResolveLocalizedURLOptions}.
165
- *
166
- * @returns The localized URL.
167
- */
168
- export declare function getLocalizedURL(url: string, locale: string, { defaultLocale, resolveStrategy, resolver, supportedLocales }?: ResolveLocalizedURLOptions): string;
169
- /**
170
- * Returns all localized versions of a URL based on the specified
171
- * `supportedLocales`.
172
- *
173
- * @param url - The URL.
174
- * @param options - See {@link ResolveLocalizedURLOptions}.
175
- *
176
- * @returns The localized URLs.
177
- */
178
- export declare function getLocalizedURLs(url: string, { defaultLocale, resolveStrategy, resolver, supportedLocales }?: ResolveLocalizedURLOptions): string[];
179
- export {};
@@ -1,470 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- var desc = Object.getOwnPropertyDescriptor(m, k);
16
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
- desc = { enumerable: true, get: function() { return m[k]; } };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }) : (function(o, m, k, k2) {
21
- if (k2 === undefined) k2 = k;
22
- o[k2] = m[k];
23
- }));
24
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
- Object.defineProperty(o, "default", { enumerable: true, value: v });
26
- }) : function(o, v) {
27
- o["default"] = v;
28
- });
29
- var __importStar = (this && this.__importStar) || function (mod) {
30
- if (mod && mod.__esModule) return mod;
31
- var result = {};
32
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
- __setModuleDefault(result, mod);
34
- return result;
35
- };
36
- var __read = (this && this.__read) || function (o, n) {
37
- var m = typeof Symbol === "function" && o[Symbol.iterator];
38
- if (!m) return o;
39
- var i = m.call(o), r, ar = [], e;
40
- try {
41
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
42
- }
43
- catch (error) { e = { error: error }; }
44
- finally {
45
- try {
46
- if (r && !r.done && (m = i["return"])) m.call(i);
47
- }
48
- finally { if (e) throw e.error; }
49
- }
50
- return ar;
51
- };
52
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
53
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
54
- if (ar || !(i in from)) {
55
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
56
- ar[i] = from[i];
57
- }
58
- }
59
- return to.concat(ar || Array.prototype.slice.call(from));
60
- };
61
- var __importDefault = (this && this.__importDefault) || function (mod) {
62
- return (mod && mod.__esModule) ? mod : { "default": mod };
63
- };
64
- Object.defineProperty(exports, "__esModule", { value: true });
65
- exports.getLocalizedURLs = exports.getLocalizedURL = exports.getUnlocalizedURL = exports.getLocaleFromURL = exports.resolveLocale = exports.useSupportedLocales = exports.useLocalizedString = exports.useLocalizedPath = exports.useLocale = exports.useChangeLocale = exports.I18nRoutes = exports.I18nContext = void 0;
66
- var node_polyglot_1 = __importDefault(require("node-polyglot"));
67
- var react_1 = __importStar(require("react"));
68
- var react_router_1 = require("react-router");
69
- var reducer = function (state, action) {
70
- switch (action.type) {
71
- case '@i18n/CHANGE_LOCALE':
72
- return __assign(__assign({}, state), { locale: action.locale, getLocalizedString: function () {
73
- var _a, _b;
74
- var args = [];
75
- for (var _i = 0; _i < arguments.length; _i++) {
76
- args[_i] = arguments[_i];
77
- }
78
- return (_b = (_a = state.polyglots[action.locale]) === null || _a === void 0 ? void 0 : _a.t.apply(_a, __spreadArray([], __read(args), false))) !== null && _b !== void 0 ? _b : args[0];
79
- } });
80
- default:
81
- return state;
82
- }
83
- };
84
- exports.I18nContext = (0, react_1.createContext)(undefined);
85
- /**
86
- * Context provider whose value consists of the current i18n state. The method
87
- * of modifying the locale is specified by `changeLocaleStrategy`, as follows:
88
- * - If set to `action`, the locale can be modified by dispatching an action
89
- * - If set to `path`, the locale is inferred from the current path name
90
- * - If set to `query`, the locale is inferred from the search parameter
91
- * `locale` in the current path
92
- *
93
- * @param props - See {@link I18nProviderProps}.
94
- *
95
- * @returns The context provider.
96
- */
97
- function I18nProvider(_a) {
98
- var _b;
99
- var children = _a.children, _c = _a.defaultLocale, defaultLocale = _c === void 0 ? 'en' : _c, translations = _a.translations, _d = _a.changeLocaleStrategy, changeLocaleStrategy = _d === void 0 ? 'path' : _d;
100
- var _e = (0, react_router_1.useLocation)(), pathname = _e.pathname, search = _e.search, hash = _e.hash;
101
- var url = "".concat(pathname).concat(search).concat(hash);
102
- var supportedLocales = Object.keys(translations);
103
- if (supportedLocales.indexOf(defaultLocale) < 0) {
104
- console.warn("Provided supported locales do not contain the default locale <".concat(defaultLocale, ">"));
105
- supportedLocales.push(defaultLocale);
106
- }
107
- var polyglots = (0, react_1.useMemo)(function () { return supportedLocales.reduce(function (out, locale) {
108
- var _a;
109
- return (__assign(__assign({}, out), (_a = {}, _a[locale] = new node_polyglot_1.default({ locale: locale, phrases: translations[locale] }), _a)));
110
- }, {}); }, [translations]);
111
- switch (changeLocaleStrategy) {
112
- case 'action': {
113
- var _f = __read((0, react_1.useReducer)(reducer, {
114
- changeLocaleStrategy: changeLocaleStrategy,
115
- defaultLocale: defaultLocale,
116
- locale: defaultLocale,
117
- polyglots: polyglots,
118
- supportedLocales: supportedLocales,
119
- getLocalizedString: function () {
120
- var _a, _b;
121
- var args = [];
122
- for (var _i = 0; _i < arguments.length; _i++) {
123
- args[_i] = arguments[_i];
124
- }
125
- return (_b = (_a = polyglots[defaultLocale]) === null || _a === void 0 ? void 0 : _a.t.apply(_a, __spreadArray([], __read(args), false))) !== null && _b !== void 0 ? _b : args[0];
126
- },
127
- }), 2), state = _f[0], dispatch = _f[1];
128
- return (react_1.default.createElement(exports.I18nContext.Provider, { value: { state: state, dispatch: dispatch } }, children));
129
- }
130
- default: {
131
- var resolveStrategy_1 = changeLocaleStrategy === 'path' ? 'path' : 'query';
132
- var localeInfo = getLocaleFromURL(url, { defaultLocale: defaultLocale, resolveStrategy: resolveStrategy_1, supportedLocales: supportedLocales });
133
- if (!localeInfo)
134
- console.warn("Unable to infer locale from path <".concat(url, ">"));
135
- var locale_1 = (_b = localeInfo === null || localeInfo === void 0 ? void 0 : localeInfo.locale) !== null && _b !== void 0 ? _b : defaultLocale;
136
- var polyglot_1 = polyglots[locale_1];
137
- if (!polyglot_1)
138
- console.warn("Missing transtions for locale <".concat(locale_1, ">"));
139
- var state = {
140
- changeLocaleStrategy: changeLocaleStrategy,
141
- defaultLocale: defaultLocale,
142
- locale: locale_1,
143
- polyglots: polyglots,
144
- supportedLocales: supportedLocales,
145
- getLocalizedPath: function (path) { return locale_1 === defaultLocale ? getUnlocalizedURL(path, { resolveStrategy: resolveStrategy_1, supportedLocales: supportedLocales }) : getLocalizedURL(path, locale_1, { defaultLocale: defaultLocale, resolveStrategy: changeLocaleStrategy, supportedLocales: supportedLocales }); },
146
- getLocalizedString: function () {
147
- var _a;
148
- var args = [];
149
- for (var _i = 0; _i < arguments.length; _i++) {
150
- args[_i] = arguments[_i];
151
- }
152
- return (_a = polyglot_1 === null || polyglot_1 === void 0 ? void 0 : polyglot_1.t.apply(polyglot_1, __spreadArray([], __read(args), false))) !== null && _a !== void 0 ? _a : args[0];
153
- },
154
- };
155
- return (react_1.default.createElement(exports.I18nContext.Provider, { value: { state: state } }, children));
156
- }
157
- }
158
- }
159
- exports.default = I18nProvider;
160
- /** @namespace Components */
161
- /**
162
- * Custom {@link Routes} container that generates child {@link Route} components
163
- * for all locales supported by {@link I18nProvider}.
164
- */
165
- function I18nRoutes(_a) {
166
- var children = _a.children;
167
- var context = (0, react_1.useContext)(exports.I18nContext);
168
- if (!context)
169
- throw Error('Cannot fetch the value of I18nContext, is the corresponding provider instated?');
170
- var _b = context.state, defaultLocale = _b.defaultLocale, supportedLocales = _b.supportedLocales, changeLocaleStrategy = _b.changeLocaleStrategy;
171
- switch (changeLocaleStrategy) {
172
- case 'path':
173
- return (react_1.default.createElement(react_router_1.Routes, null, supportedLocales.map(function (locale) { return (react_1.default.createElement(react_router_1.Route, { key: locale, path: locale === defaultLocale ? '/' : locale }, children)); })));
174
- default:
175
- return (react_1.default.createElement(react_router_1.Routes, null,
176
- react_1.default.createElement(react_router_1.Route, { path: '/' }, children)));
177
- }
178
- }
179
- exports.I18nRoutes = I18nRoutes;
180
- /** @namespace Hooks */
181
- /**
182
- * Hook for retrieving the change locale function.
183
- *
184
- * @returns The change locale function.
185
- */
186
- function useChangeLocale() {
187
- var context = (0, react_1.useContext)(exports.I18nContext);
188
- if (!context)
189
- throw Error('Cannot fetch the current i18n context, is the corresponding provider instated?');
190
- if (context.state.changeLocaleStrategy === 'action') {
191
- return function (locale) {
192
- var _a;
193
- return (_a = context.dispatch) === null || _a === void 0 ? void 0 : _a.call(context, {
194
- locale: locale,
195
- type: '@i18n/CHANGE_LOCALE',
196
- });
197
- };
198
- }
199
- else {
200
- var _a = context.state, defaultLocale_1 = _a.defaultLocale, changeLocaleStrategy = _a.changeLocaleStrategy, supportedLocales_1 = _a.supportedLocales;
201
- var _b = (0, react_router_1.useLocation)(), pathname = _b.pathname, search = _b.search, hash = _b.hash;
202
- var path_1 = "".concat(pathname).concat(search).concat(hash);
203
- var navigate_1 = (0, react_router_1.useNavigate)();
204
- var resolveStrategy_2 = changeLocaleStrategy === 'path' ? 'path' : 'query';
205
- return function (locale) {
206
- var newPath = locale === defaultLocale_1
207
- ? getUnlocalizedURL(path_1, { resolveStrategy: resolveStrategy_2, supportedLocales: supportedLocales_1 })
208
- : getLocalizedURL(path_1, locale, { defaultLocale: defaultLocale_1, resolveStrategy: resolveStrategy_2, supportedLocales: supportedLocales_1 });
209
- navigate_1(newPath);
210
- };
211
- }
212
- }
213
- exports.useChangeLocale = useChangeLocale;
214
- /**
215
- * Hook for retrieving the current locale.
216
- *
217
- * @returns The current locale.
218
- */
219
- function useLocale() {
220
- var context = (0, react_1.useContext)(exports.I18nContext);
221
- if (!context)
222
- throw Error('Cannot fetch the current i18n context, is the corresponding provider instated?');
223
- return context.state.locale;
224
- }
225
- exports.useLocale = useLocale;
226
- /**
227
- * Hook for retrieving the path localizing function for the current locale.
228
- *
229
- * @returns The path localizing function.
230
- */
231
- function useLocalizedPath() {
232
- var _a;
233
- var context = (0, react_1.useContext)(exports.I18nContext);
234
- if (!context)
235
- throw Error('Cannot fetch the current i18n context, is the corresponding provider instated?');
236
- return (_a = context.state.getLocalizedPath) !== null && _a !== void 0 ? _a : (function (path) { return path; });
237
- }
238
- exports.useLocalizedPath = useLocalizedPath;
239
- /**
240
- * Hook for retrieving the string localizing function for the current locale.
241
- *
242
- * @returns The string localizing function.
243
- */
244
- function useLocalizedString() {
245
- var context = (0, react_1.useContext)(exports.I18nContext);
246
- if (!context)
247
- throw Error('Cannot fetch the current i18n context, is the corresponding provider instated?');
248
- return context.state.getLocalizedString;
249
- }
250
- exports.useLocalizedString = useLocalizedString;
251
- /**
252
- * Hook for retrieving all supported locales.
253
- *
254
- * @returns All supported locales.
255
- */
256
- function useSupportedLocales() {
257
- var context = (0, react_1.useContext)(exports.I18nContext);
258
- if (!context)
259
- throw Error('Cannot fetch the current i18n context, is the corresponding provider instated?');
260
- return context.state.supportedLocales;
261
- }
262
- exports.useSupportedLocales = useSupportedLocales;
263
- /**
264
- * Parses a URL into parts.
265
- *
266
- * @param url - The URL to parse.
267
- *
268
- * @returns The parsed result.
269
- */
270
- function parseURL(url) {
271
- var regex = /((?:(.*):\/\/)?((?:[A-Za-z0-9-]+\.?)+)?(?::([0-9]+))?)([^?#]*)(?:\?([^#]*))?(?:#(.*))?/;
272
- var parts = url.match(regex);
273
- if (!parts)
274
- return {};
275
- return {
276
- base: parts[1],
277
- hash: parts[7],
278
- host: parts[3],
279
- path: parts[5],
280
- port: parts[4],
281
- protocol: parts[2],
282
- query: parts[6],
283
- };
284
- }
285
- /**
286
- * Constructs a URL from {@link URLParts}.
287
- *
288
- * @param parts - See {@link URLParts}.
289
- *
290
- * @returns The constructed URL.
291
- */
292
- function constructURL(parts) {
293
- var _a, _b, _c, _d;
294
- var protocol = (_b = (_a = parts.protocol) === null || _a === void 0 ? void 0 : _a.concat('://')) !== null && _b !== void 0 ? _b : '';
295
- var host = (_d = (_c = parts.host) === null || _c === void 0 ? void 0 : _c.concat('/')) !== null && _d !== void 0 ? _d : '';
296
- var port = parts.port ? ":".concat(parts.port) : '';
297
- var path = parts.path ? "/".concat(parts.path.split('/').filter(function (t) { return t; }).join('/')) : '';
298
- var query = parts.query ? "?".concat(parts.query) : '';
299
- var hash = parts.hash ? "#".concat(parts.hash) : '';
300
- return "".concat(protocol).concat(host).concat(port).concat(path).concat(query).concat(hash);
301
- }
302
- /**
303
- * Resolves the specified locale with the provided options. All parameters are
304
- * optional.
305
- *
306
- * @param locale - The locale to resolve.
307
- * @param options - See {@link ResolveLocaleOptions}.
308
- *
309
- * @returns - The resolved locale.
310
- */
311
- function resolveLocale(locale, _a) {
312
- var _b = _a === void 0 ? {} : _a, defaultLocale = _b.defaultLocale, supportedLocales = _b.supportedLocales;
313
- if (supportedLocales) {
314
- if (locale && supportedLocales.indexOf(locale) >= 0)
315
- return locale;
316
- if (defaultLocale && supportedLocales.indexOf(defaultLocale) >= 0)
317
- return defaultLocale;
318
- return undefined;
319
- }
320
- return locale !== null && locale !== void 0 ? locale : defaultLocale;
321
- }
322
- exports.resolveLocale = resolveLocale;
323
- /**
324
- * Retrieves the locale identifier from a URL. The default behavior of this
325
- * function to look for the locale identifier in the domain first followed by
326
- * the first directory of the path. You can provide a custom resolver.
327
- *
328
- * @param url - The URL, can be a full URL or a valid path.
329
- * @param options - See {@link ResolveLocalizedURLOptions}.
330
- *
331
- * @returns The inferred locale if it exists.
332
- */
333
- function getLocaleFromURL(url, _a) {
334
- var _b, _c;
335
- var _d = _a === void 0 ? {} : _a, defaultLocale = _d.defaultLocale, _e = _d.resolveStrategy, resolveStrategy = _e === void 0 ? 'auto' : _e, resolver = _d.resolver, supportedLocales = _d.supportedLocales;
336
- var parts = parseURL(url);
337
- if (resolver) {
338
- var matchedLocale = resolver(parts);
339
- if (matchedLocale && (!supportedLocales || supportedLocales.indexOf(matchedLocale) >= 0))
340
- return { locale: matchedLocale, resolveStrategy: 'custom' };
341
- if (defaultLocale && (!supportedLocales || supportedLocales.indexOf(defaultLocale) >= 0))
342
- return { locale: defaultLocale, resolveStrategy: 'auto' };
343
- return undefined;
344
- }
345
- else {
346
- var matchedLocaleFromHost = (_b = parts.host) === null || _b === void 0 ? void 0 : _b.split('.').filter(function (t) { return t; })[0];
347
- var matchedLocaleFromPath = (_c = parts.path) === null || _c === void 0 ? void 0 : _c.split('/').filter(function (t) { return t; })[0];
348
- var matchedLocaleFromQuery = new URLSearchParams(parts.query).get('locale');
349
- if (matchedLocaleFromHost && (resolveStrategy === 'auto' || resolveStrategy === 'domain') && (!supportedLocales || supportedLocales.indexOf(matchedLocaleFromHost) >= 0))
350
- return { locale: matchedLocaleFromHost, resolveStrategy: 'domain' };
351
- if (matchedLocaleFromPath && (resolveStrategy === 'auto' || resolveStrategy === 'path') && (!supportedLocales || supportedLocales.indexOf(matchedLocaleFromPath) >= 0))
352
- return { locale: matchedLocaleFromPath, resolveStrategy: 'path' };
353
- if (matchedLocaleFromQuery && (resolveStrategy === 'auto' || resolveStrategy === 'query') && (!supportedLocales || supportedLocales.indexOf(matchedLocaleFromQuery) >= 0))
354
- return { locale: matchedLocaleFromQuery, resolveStrategy: 'query' };
355
- if (defaultLocale && (!supportedLocales || supportedLocales.indexOf(defaultLocale) >= 0))
356
- return { locale: defaultLocale, resolveStrategy: 'auto' };
357
- return undefined;
358
- }
359
- }
360
- exports.getLocaleFromURL = getLocaleFromURL;
361
- /**
362
- * Returns the unlocalized version of a URL.
363
- *
364
- * @param url - The URL.
365
- * @param options - See {@link ResolveLocalizedURLOptions}.
366
- *
367
- * @returns The unlocalized URL.
368
- */
369
- function getUnlocalizedURL(url, _a) {
370
- var _b = _a === void 0 ? {} : _a, _c = _b.resolveStrategy, resolveStrategy = _c === void 0 ? 'auto' : _c, resolver = _b.resolver, supportedLocales = _b.supportedLocales;
371
- var currLocaleInfo = getLocaleFromURL(url, { resolveStrategy: resolveStrategy, resolver: resolver, supportedLocales: supportedLocales });
372
- var parts = parseURL(url);
373
- if (!currLocaleInfo)
374
- return url;
375
- switch (currLocaleInfo.resolveStrategy) {
376
- case 'domain':
377
- return constructURL(__assign(__assign({}, parts), { host: parts.host ? parts.host.split('.').filter(function (t) { return t; }).slice(1).join('.') : undefined }));
378
- case 'query': {
379
- if (!parts.query)
380
- return url;
381
- var searchParams = new URLSearchParams(parts.query);
382
- searchParams.delete('locale');
383
- return constructURL(__assign(__assign({}, parts), { query: searchParams.toString() }));
384
- }
385
- case 'path':
386
- case 'auto':
387
- default:
388
- return constructURL(__assign(__assign({}, parts), { path: parts.path ? __spreadArray([], __read(parts.path.split('/').filter(function (t) { return t; }).slice(1)), false).join('/') : undefined }));
389
- }
390
- }
391
- exports.getUnlocalizedURL = getUnlocalizedURL;
392
- /**
393
- * Returns the localized version of a URL.
394
- *
395
- * @param url - The URL.
396
- * @param locale - The target locale.
397
- * @param options - See {@link ResolveLocalizedURLOptions}.
398
- *
399
- * @returns The localized URL.
400
- */
401
- function getLocalizedURL(url, locale, _a) {
402
- var _b = _a === void 0 ? {} : _a, defaultLocale = _b.defaultLocale, _c = _b.resolveStrategy, resolveStrategy = _c === void 0 ? 'auto' : _c, resolver = _b.resolver, supportedLocales = _b.supportedLocales;
403
- var currLocaleInfo = getLocaleFromURL(url, { resolveStrategy: resolveStrategy, resolver: resolver, supportedLocales: supportedLocales });
404
- var parts = parseURL(url);
405
- var targetLocale = resolveLocale(locale, { defaultLocale: defaultLocale, supportedLocales: supportedLocales });
406
- if (!targetLocale)
407
- return url;
408
- if (targetLocale === defaultLocale)
409
- return getUnlocalizedURL(url, { resolveStrategy: resolveStrategy, resolver: resolver, supportedLocales: supportedLocales });
410
- if (currLocaleInfo) {
411
- switch (currLocaleInfo.resolveStrategy) {
412
- case 'domain':
413
- return constructURL(__assign(__assign({}, parts), { host: parts.host ? "".concat(targetLocale, ".").concat(parts.host.split('.').filter(function (t) { return t; }).slice(1).join('.')) : undefined }));
414
- case 'query': {
415
- if (!parts.query)
416
- return url;
417
- var searchParams = new URLSearchParams(parts.query);
418
- if (searchParams.get('locale')) {
419
- searchParams.set('locale', targetLocale);
420
- }
421
- else {
422
- searchParams.set('locale', targetLocale);
423
- }
424
- return constructURL(__assign(__assign({}, parts), { query: searchParams.toString() }));
425
- }
426
- case 'path':
427
- case 'auto':
428
- default:
429
- return constructURL(__assign(__assign({}, parts), { path: parts.path ? __spreadArray([targetLocale], __read(parts.path.split('/').filter(function (t) { return t; }).slice(1)), false).join('/') : undefined }));
430
- }
431
- }
432
- else {
433
- switch (resolveStrategy) {
434
- case 'domain':
435
- return constructURL(__assign(__assign({}, parts), { host: parts.host ? "".concat(targetLocale, ".").concat(parts.host) : undefined }));
436
- case 'query': {
437
- var searchParams = new URLSearchParams(parts.query);
438
- if (targetLocale === defaultLocale) {
439
- searchParams.delete('locale');
440
- }
441
- else {
442
- searchParams.set('locale', targetLocale);
443
- }
444
- return constructURL(__assign(__assign({}, parts), { query: searchParams.toString() }));
445
- }
446
- case 'path':
447
- case 'auto':
448
- default:
449
- return constructURL(__assign(__assign({}, parts), { path: parts.path ? __spreadArray([targetLocale], __read(parts.path.split('/').filter(function (t) { return t; })), false).join('/') : undefined }));
450
- }
451
- }
452
- }
453
- exports.getLocalizedURL = getLocalizedURL;
454
- /**
455
- * Returns all localized versions of a URL based on the specified
456
- * `supportedLocales`.
457
- *
458
- * @param url - The URL.
459
- * @param options - See {@link ResolveLocalizedURLOptions}.
460
- *
461
- * @returns The localized URLs.
462
- */
463
- function getLocalizedURLs(url, _a) {
464
- var _b = _a === void 0 ? {} : _a, defaultLocale = _b.defaultLocale, _c = _b.resolveStrategy, resolveStrategy = _c === void 0 ? 'auto' : _c, resolver = _b.resolver, supportedLocales = _b.supportedLocales;
465
- if (!supportedLocales)
466
- return [];
467
- return supportedLocales.map(function (locale) { return getLocalizedURL(url, locale, { defaultLocale: defaultLocale, resolveStrategy: resolveStrategy, resolver: resolver, supportedLocales: supportedLocales }); });
468
- }
469
- exports.getLocalizedURLs = getLocalizedURLs;
470
- //# sourceMappingURL=I18nProvider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"I18nProvider.js","sourceRoot":"/","sources":["providers/I18nProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAAoC;AACpC,6CAA0G;AAC1G,6CAAsE;AA8BtE,IAAM,OAAO,GAAG,UAAC,KAAgB,EAAE,MAA8B;IAC/D,Q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AAK,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,EAAD,CAAC,CAAC,UAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,IAAG,CAAA;SACtI;KACF;AACH,CAAC;AAtDD,0CAsDC;AAED;;;;;;;;GAQG;AACH,SAAgB,gBAAgB,CAAC,GAAW,EAAE,EAAwG;QAAxG,qBAAsG,EAAE,KAAA,EAAtG,aAAa,mBAAA,EAAE,uBAAwB,EAAxB,eAAe,mBAAG,MAAM,KAAA,EAAE,QAAQ,cAAA,EAAE,gBAAgB,sBAAA;IACjH,IAAI,CAAC,gBAAgB;QAAE,OAAO,EAAE,CAAA;IAEhC,OAAO,gBAAgB,CAAC,GAAG,CAAC,UAAA,MAAM,IAAI,OAAA,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,aAAa,eAAA,EAAE,eAAe,iBAAA,EAAE,QAAQ,UAAA,EAAE,gBAAgB,kBAAA,EAAE,CAAC,EAA5F,CAA4F,CAAC,CAAA;AACrI,CAAC;AAJD,4CAIC","sourcesContent":["import Polyglot from 'node-polyglot'\nimport React, { createContext, Dispatch, PropsWithChildren, useContext, useMemo, useReducer } from 'react'\nimport { Route, Routes, useLocation, useNavigate } from 'react-router'\n\ninterface Translation { [key: string]: Translation | string }\n\ntype I18nState = {\n changeLocaleStrategy: 'action' | 'path' | 'query'\n defaultLocale: string\n locale: string\n polyglots: Record<string, Polyglot>\n supportedLocales: string[]\n getLocalizedPath?: (path: string) => string\n getLocalizedString: typeof Polyglot.prototype.t\n}\n\ntype I18nContextValue = {\n state: I18nState\n dispatch?: Dispatch<I18nChangeLocaleAction>\n}\n\ntype I18nProviderProps = PropsWithChildren<{\n changeLocaleStrategy?: I18nState['changeLocaleStrategy']\n defaultLocale?: I18nState['defaultLocale']\n translations: Record<string, Translation>\n}>\n\ntype I18nChangeLocaleAction = {\n type: '@i18n/CHANGE_LOCALE'\n locale: string\n}\n\nconst reducer = (state: I18nState, action: I18nChangeLocaleAction): I18nState => {\n switch (action.type) {\n case '@i18n/CHANGE_LOCALE':\n return {\n ...state,\n locale: action.locale,\n getLocalizedString: (...args) => state.polyglots[action.locale]?.t(...args) ?? args[0],\n }\n default:\n return state\n }\n}\n\nexport const I18nContext = createContext<I18nContextValue | undefined>(undefined)\n\n/**\n * Context provider whose value consists of the current i18n state. The method\n * of modifying the locale is specified by `changeLocaleStrategy`, as follows:\n * - If set to `action`, the locale can be modified by dispatching an action\n * - If set to `path`, the locale is inferred from the current path name\n * - If set to `query`, the locale is inferred from the search parameter\n * `locale` in the current path\n *\n * @param props - See {@link I18nProviderProps}.\n *\n * @returns The context provider.\n */\nexport default function I18nProvider({\n children,\n defaultLocale = 'en',\n translations,\n changeLocaleStrategy = 'path',\n}: I18nProviderProps) {\n const { pathname, search, hash } = useLocation()\n const url = `${pathname}${search}${hash}`\n const supportedLocales = Object.keys(translations)\n\n if (supportedLocales.indexOf(defaultLocale) < 0) {\n console.warn(`Provided supported locales do not contain the default locale <${defaultLocale}>`)\n supportedLocales.push(defaultLocale)\n }\n\n const polyglots = useMemo<Record<string, Polyglot>>(() => supportedLocales.reduce((out, locale) => ({\n ...out,\n [locale]: new Polyglot({ locale, phrases: translations[locale] }),\n }), {}), [translations])\n\n switch (changeLocaleStrategy) {\n case 'action': {\n const [state, dispatch] = useReducer(reducer, {\n changeLocaleStrategy,\n defaultLocale,\n locale: defaultLocale,\n polyglots,\n supportedLocales,\n getLocalizedString: (...args) => polyglots[defaultLocale]?.t(...args) ?? args[0],\n })\n\n return (\n <I18nContext.Provider value={{ state, dispatch }}>\n {children}\n </I18nContext.Provider>\n )\n }\n default: {\n const resolveStrategy = changeLocaleStrategy === 'path' ? 'path' : 'query'\n const localeInfo = getLocaleFromURL(url, { defaultLocale, resolveStrategy, supportedLocales })\n if (!localeInfo) console.warn(`Unable to infer locale from path <${url}>`)\n\n const locale = localeInfo?.locale ?? defaultLocale\n\n const polyglot = polyglots[locale]\n if (!polyglot) console.warn(`Missing transtions for locale <${locale}>`)\n\n const state: I18nState = {\n changeLocaleStrategy,\n defaultLocale,\n locale,\n polyglots,\n supportedLocales,\n getLocalizedPath: path => locale === defaultLocale ? getUnlocalizedURL(path, { resolveStrategy, supportedLocales }) : getLocalizedURL(path, locale, { defaultLocale, resolveStrategy: changeLocaleStrategy, supportedLocales }),\n getLocalizedString: (...args) => polyglot?.t(...args) ?? args[0],\n }\n\n return (\n <I18nContext.Provider value={{ state }}>\n {children}\n </I18nContext.Provider>\n )\n }\n }\n}\n\n/** @namespace Components */\n\n/**\n * Custom {@link Routes} container that generates child {@link Route} components\n * for all locales supported by {@link I18nProvider}.\n */\nexport function I18nRoutes({ children }: PropsWithChildren) {\n const context = useContext(I18nContext)\n if (!context) throw Error('Cannot fetch the value of I18nContext, is the corresponding provider instated?')\n\n const { defaultLocale, supportedLocales, changeLocaleStrategy } = context.state\n\n switch (changeLocaleStrategy) {\n case 'path':\n return (\n <Routes>\n {supportedLocales.map(locale => (\n <Route key={locale} path={locale === defaultLocale ? '/' : locale}>\n {children}\n </Route>\n ))}\n </Routes>\n )\n default:\n return (\n <Routes>\n <Route path={'/'}>\n {children}\n </Route>\n </Routes>\n )\n }\n}\n\n/** @namespace Hooks */\n\n/**\n * Hook for retrieving the change locale function.\n *\n * @returns The change locale function.\n */\nexport function useChangeLocale() {\n const context = useContext(I18nContext)\n if (!context) throw Error('Cannot fetch the current i18n context, is the corresponding provider instated?')\n\n if (context.state.changeLocaleStrategy === 'action') {\n return (locale: string) => context.dispatch?.({\n locale,\n type: '@i18n/CHANGE_LOCALE',\n })\n }\n else {\n const { defaultLocale, changeLocaleStrategy, supportedLocales } = context.state\n const { pathname, search, hash } = useLocation()\n const path = `${pathname}${search}${hash}`\n const navigate = useNavigate()\n const resolveStrategy = changeLocaleStrategy === 'path' ? 'path' : 'query'\n\n return (locale: string) => {\n const newPath = locale === defaultLocale\n ? getUnlocalizedURL(path, { resolveStrategy, supportedLocales })\n : getLocalizedURL(path, locale, { defaultLocale, resolveStrategy, supportedLocales })\n\n navigate(newPath)\n }\n }\n}\n\n/**\n * Hook for retrieving the current locale.\n *\n * @returns The current locale.\n */\nexport function useLocale() {\n const context = useContext(I18nContext)\n if (!context) throw Error('Cannot fetch the current i18n context, is the corresponding provider instated?')\n\n return context.state.locale\n}\n\n/**\n * Hook for retrieving the path localizing function for the current locale.\n *\n * @returns The path localizing function.\n */\nexport function useLocalizedPath() {\n const context = useContext(I18nContext)\n if (!context) throw Error('Cannot fetch the current i18n context, is the corresponding provider instated?')\n\n return context.state.getLocalizedPath ?? ((path: string) => path)\n}\n\n/**\n * Hook for retrieving the string localizing function for the current locale.\n *\n * @returns The string localizing function.\n */\nexport function useLocalizedString() {\n const context = useContext(I18nContext)\n if (!context) throw Error('Cannot fetch the current i18n context, is the corresponding provider instated?')\n\n return context.state.getLocalizedString\n}\n\n/**\n * Hook for retrieving all supported locales.\n *\n * @returns All supported locales.\n */\nexport function useSupportedLocales() {\n const context = useContext(I18nContext)\n if (!context) throw Error('Cannot fetch the current i18n context, is the corresponding provider instated?')\n\n return context.state.supportedLocales\n}\n\n/** @namespace Utilities */\n\ntype URLParts = {\n base?: string\n hash?: string\n host?: string\n path?: string\n port?: string\n protocol?: string\n query?: string\n}\n\ntype ResolveLocaleOptions = {\n /**\n * The locale to fallback to if one cannot be inferred from the provided URL.\n */\n defaultLocale?: string\n\n /**\n * An array of supported locales to validate the inferred locale against. If\n * it doesn't exist in the list of supported locales, the default locale (if\n * specified) or `undefined` will be returned.\n */\n supportedLocales?: string[]\n}\n\ntype ResolveLocalizedURLOptions = ResolveLocaleOptions & {\n /**\n * Specifies where in the URL the locale should be matched. If `resolver` is\n * provided, this option is ignored.\n */\n resolveStrategy?: 'auto' | 'domain' | 'path' | 'query'\n\n /**\n * Custom resolver function.\n *\n * @param protocol - The matched protocol of the provided url, if available.\n * @param host - The matched host of the provided url, if available.\n * @param port - The matched port of the provided url, if available.\n * @param path - The matched path of the provided url, if available.\n *\n * @returns The resolved locale.\n */\n resolver?: (urlParts: URLParts) => string | undefined\n}\n\ntype LocalizedURLInfo = {\n /**\n * The matched locale.\n */\n locale: string\n\n /**\n * Specifies where in the URL the locale was matched.\n */\n resolveStrategy: ResolveLocalizedURLOptions['resolveStrategy'] | 'custom'\n}\n\n/**\n * Parses a URL into parts.\n *\n * @param url - The URL to parse.\n *\n * @returns The parsed result.\n */\nfunction parseURL(url: string): URLParts {\n const regex = /((?:(.*):\\/\\/)?((?:[A-Za-z0-9-]+\\.?)+)?(?::([0-9]+))?)([^?#]*)(?:\\?([^#]*))?(?:#(.*))?/\n const parts = url.match(regex)\n\n if (!parts) return {}\n\n return {\n base: parts[1],\n hash: parts[7],\n host: parts[3],\n path: parts[5],\n port: parts[4],\n protocol: parts[2],\n query: parts[6],\n }\n}\n\n/**\n * Constructs a URL from {@link URLParts}.\n *\n * @param parts - See {@link URLParts}.\n *\n * @returns The constructed URL.\n */\nfunction constructURL(parts: URLParts): string {\n const protocol = parts.protocol?.concat('://') ?? ''\n const host = parts.host?.concat('/') ?? ''\n const port = parts.port ? `:${parts.port}` : ''\n const path = parts.path ? `/${parts.path.split('/').filter(t => t).join('/')}` : ''\n const query = parts.query ? `?${parts.query}` : ''\n const hash = parts.hash ? `#${parts.hash}` : ''\n\n return `${protocol}${host}${port}${path}${query}${hash}`\n}\n\n/**\n * Resolves the specified locale with the provided options. All parameters are\n * optional.\n *\n * @param locale - The locale to resolve.\n * @param options - See {@link ResolveLocaleOptions}.\n *\n * @returns - The resolved locale.\n */\nexport function resolveLocale(locale?: string, { defaultLocale, supportedLocales }: ResolveLocaleOptions = {}): string | undefined {\n if (supportedLocales) {\n if (locale && supportedLocales.indexOf(locale) >= 0) return locale\n if (defaultLocale && supportedLocales.indexOf(defaultLocale) >= 0) return defaultLocale\n\n return undefined\n }\n\n return locale ?? defaultLocale\n}\n\n/**\n * Retrieves the locale identifier from a URL. The default behavior of this\n * function to look for the locale identifier in the domain first followed by\n * the first directory of the path. You can provide a custom resolver.\n *\n * @param url - The URL, can be a full URL or a valid path.\n * @param options - See {@link ResolveLocalizedURLOptions}.\n *\n * @returns The inferred locale if it exists.\n */\nexport function getLocaleFromURL(url: string, { defaultLocale, resolveStrategy = 'auto', resolver, supportedLocales }: ResolveLocalizedURLOptions = {}): LocalizedURLInfo | undefined {\n const parts = parseURL(url)\n\n if (resolver) {\n const matchedLocale = resolver(parts)\n\n if (matchedLocale && (!supportedLocales || supportedLocales.indexOf(matchedLocale) >= 0)) return { locale: matchedLocale, resolveStrategy: 'custom' }\n if (defaultLocale && (!supportedLocales || supportedLocales.indexOf(defaultLocale) >= 0)) return { locale: defaultLocale, resolveStrategy: 'auto' }\n\n return undefined\n }\n else {\n const matchedLocaleFromHost = parts.host?.split('.').filter(t => t)[0]\n const matchedLocaleFromPath = parts.path?.split('/').filter(t => t)[0]\n const matchedLocaleFromQuery = new URLSearchParams(parts.query).get('locale')\n\n if (matchedLocaleFromHost && (resolveStrategy === 'auto' || resolveStrategy === 'domain') && (!supportedLocales || supportedLocales.indexOf(matchedLocaleFromHost) >= 0)) return { locale: matchedLocaleFromHost, resolveStrategy: 'domain' }\n if (matchedLocaleFromPath && (resolveStrategy === 'auto' || resolveStrategy === 'path') && (!supportedLocales || supportedLocales.indexOf(matchedLocaleFromPath) >= 0)) return { locale: matchedLocaleFromPath, resolveStrategy: 'path' }\n if (matchedLocaleFromQuery && (resolveStrategy === 'auto' || resolveStrategy === 'query') && (!supportedLocales || supportedLocales.indexOf(matchedLocaleFromQuery) >= 0)) return { locale: matchedLocaleFromQuery, resolveStrategy: 'query' }\n if (defaultLocale && (!supportedLocales || supportedLocales.indexOf(defaultLocale) >= 0)) return { locale: defaultLocale, resolveStrategy: 'auto' }\n\n return undefined\n }\n}\n\n/**\n * Returns the unlocalized version of a URL.\n *\n * @param url - The URL.\n * @param options - See {@link ResolveLocalizedURLOptions}.\n *\n * @returns The unlocalized URL.\n */\nexport function getUnlocalizedURL(url: string, { resolveStrategy = 'auto', resolver, supportedLocales }: ResolveLocalizedURLOptions = {}): string {\n const currLocaleInfo = getLocaleFromURL(url, { resolveStrategy, resolver, supportedLocales })\n const parts = parseURL(url)\n\n if (!currLocaleInfo) return url\n\n switch (currLocaleInfo.resolveStrategy) {\n case 'domain':\n return constructURL({ ...parts, host: parts.host ? parts.host.split('.').filter(t => t).slice(1).join('.') : undefined })\n case 'query': {\n if (!parts.query) return url\n\n const searchParams = new URLSearchParams(parts.query)\n searchParams.delete('locale')\n\n return constructURL({ ...parts, query: searchParams.toString() })\n }\n case 'path':\n case 'auto':\n default:\n return constructURL({ ...parts, path: parts.path ? [...parts.path.split('/').filter(t => t).slice(1)].join('/') : undefined })\n }\n}\n\n/**\n * Returns the localized version of a URL.\n *\n * @param url - The URL.\n * @param locale - The target locale.\n * @param options - See {@link ResolveLocalizedURLOptions}.\n *\n * @returns The localized URL.\n */\nexport function getLocalizedURL(url: string, locale: string, { defaultLocale, resolveStrategy = 'auto', resolver, supportedLocales }: ResolveLocalizedURLOptions = {}): string {\n const currLocaleInfo = getLocaleFromURL(url, { resolveStrategy, resolver, supportedLocales })\n const parts = parseURL(url)\n const targetLocale = resolveLocale(locale, { defaultLocale, supportedLocales })\n\n if (!targetLocale) return url\n\n if (targetLocale === defaultLocale) return getUnlocalizedURL(url, { resolveStrategy, resolver, supportedLocales })\n\n if (currLocaleInfo) {\n switch (currLocaleInfo.resolveStrategy) {\n case 'domain':\n return constructURL({ ...parts, host: parts.host ? `${targetLocale}.${parts.host.split('.').filter(t => t).slice(1).join('.')}` : undefined })\n case 'query': {\n if (!parts.query) return url\n\n const searchParams = new URLSearchParams(parts.query)\n if (searchParams.get('locale')) {\n searchParams.set('locale', targetLocale)\n }\n else {\n searchParams.set('locale', targetLocale)\n }\n\n return constructURL({ ...parts, query: searchParams.toString() })\n }\n case 'path':\n case 'auto':\n default:\n return constructURL({ ...parts, path: parts.path ? [targetLocale, ...parts.path.split('/').filter(t => t).slice(1)].join('/') : undefined })\n }\n }\n else {\n switch (resolveStrategy) {\n case 'domain':\n return constructURL({ ...parts, host: parts.host ? `${targetLocale}.${parts.host}` : undefined })\n case 'query': {\n const searchParams = new URLSearchParams(parts.query)\n\n if (targetLocale === defaultLocale) {\n searchParams.delete('locale')\n }\n else {\n searchParams.set('locale', targetLocale)\n }\n\n return constructURL({ ...parts, query: searchParams.toString() })\n }\n case 'path':\n case 'auto':\n default:\n return constructURL({ ...parts, path: parts.path ? [targetLocale, ...parts.path.split('/').filter(t => t)].join('/') : undefined })\n }\n }\n}\n\n/**\n * Returns all localized versions of a URL based on the specified\n * `supportedLocales`.\n *\n * @param url - The URL.\n * @param options - See {@link ResolveLocalizedURLOptions}.\n *\n * @returns The localized URLs.\n */\nexport function getLocalizedURLs(url: string, { defaultLocale, resolveStrategy = 'auto', resolver, supportedLocales }: ResolveLocalizedURLOptions = {}): string[] {\n if (!supportedLocales) return []\n\n return supportedLocales.map(locale => getLocalizedURL(url, locale, { defaultLocale, resolveStrategy, resolver, supportedLocales }))\n}\n"]}