etudes 2.0.0 → 2.2.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.
- package/lib/Accordion.d.ts +4 -4
- package/lib/BurgerButton.d.ts +1 -1
- package/lib/Conditional.d.ts +1 -1
- package/lib/DebugConsole.d.ts +1 -1
- package/lib/Dial.d.ts +1 -1
- package/lib/Dropdown.d.ts +4 -4
- package/lib/Each.d.ts +1 -1
- package/lib/ExtractChild.d.ts +1 -1
- package/lib/ExtractChildren.d.ts +1 -1
- package/lib/FlatSVG.d.ts +1 -1
- package/lib/List.d.ts +3 -3
- package/lib/MasonryGrid.d.ts +2 -2
- package/lib/Panorama.d.ts +1 -1
- package/lib/PanoramaSlider.d.ts +1 -1
- package/lib/RangeSlider.d.ts +3 -3
- package/lib/Repeat.d.ts +1 -1
- package/lib/RotatingGallery.d.ts +1 -1
- package/lib/SelectableButton.d.ts +1 -1
- package/lib/Slider.d.ts +2 -2
- package/lib/StepwiseSlider.d.ts +2 -2
- package/lib/SwipeContainer.d.ts +1 -1
- package/lib/TextField.d.ts +1 -1
- package/lib/Video.d.ts +1 -1
- package/lib/WithTooltip.d.ts +1 -1
- package/lib/hooks/useDragEffect.d.ts +3 -3
- package/lib/hooks/useInterval.d.ts +1 -1
- package/lib/hooks/useLoadImageEffect.d.ts +2 -2
- package/lib/hooks/useMounted.d.ts +1 -0
- package/lib/hooks/useMounted.js +31 -0
- package/lib/hooks/useMounted.js.map +1 -0
- package/lib/hooks/useResizeEffect.d.ts +1 -1
- package/lib/hooks/useSearchParamState.d.ts +1 -1
- package/lib/providers/I18nProvider.d.ts +179 -0
- package/lib/providers/I18nProvider.js +470 -0
- package/lib/providers/I18nProvider.js.map +1 -0
- package/lib/providers/ScrollPositionProvider.d.ts +15 -0
- package/lib/providers/ScrollPositionProvider.js +112 -0
- package/lib/providers/ScrollPositionProvider.js.map +1 -0
- package/lib/utils/asComponentDict.d.ts +2 -2
- package/package.json +20 -19
|
@@ -0,0 +1,470 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,QAAQ,MAAM,CAAC,IAAI,EAAE;QACnB,KAAK,qBAAqB;YACxB,6BACK,KAAK,KACR,MAAM,EAAE,MAAM,CAAC,MAAM,EACrB,kBAAkB,EAAE;;oBAAC,cAAO;yBAAP,UAAO,EAAP,qBAAO,EAAP,IAAO;wBAAP,yBAAO;;oBAAK,OAAA,MAAA,MAAA,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,0CAAE,CAAC,oCAAI,IAAI,UAAC,mCAAI,IAAI,CAAC,CAAC,CAAC,CAAA;iBAAA,IACvF;QACH;YACE,OAAO,KAAK,CAAA;KACf;AACH,CAAC,CAAA;AAEY,QAAA,WAAW,GAAG,IAAA,qBAAa,EAA+B,SAAS,CAAC,CAAA;AAEjF;;;;;;;;;;;GAWG;AACH,SAAwB,YAAY,CAAC,EAKjB;;QAJlB,QAAQ,cAAA,EACR,qBAAoB,EAApB,aAAa,mBAAG,IAAI,KAAA,EACpB,YAAY,kBAAA,EACZ,4BAA6B,EAA7B,oBAAoB,mBAAG,MAAM,KAAA;IAEvB,IAAA,KAA6B,IAAA,0BAAW,GAAE,EAAxC,QAAQ,cAAA,E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C","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"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React, { PropsWithChildren, RefObject } from 'react';
|
|
2
|
+
import { Point } from 'spase';
|
|
3
|
+
type ScrollPosition = {
|
|
4
|
+
pos: Point;
|
|
5
|
+
step: Point;
|
|
6
|
+
};
|
|
7
|
+
type ScrollPositionContextValue = ScrollPosition & {
|
|
8
|
+
minPos: Point;
|
|
9
|
+
maxPos: Point;
|
|
10
|
+
};
|
|
11
|
+
type ScrollPositionProviderProps = PropsWithChildren;
|
|
12
|
+
export declare const ScrollPositionContext: React.Context<ScrollPositionContextValue | undefined>;
|
|
13
|
+
export default function ScrollPositionProvider({ children, }: ScrollPositionProviderProps): JSX.Element;
|
|
14
|
+
export declare function useScrollPosition(targetRef?: RefObject<Element>): ScrollPosition;
|
|
15
|
+
export {};
|