@quilted/preact-localize 0.3.5 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/build/esm/hooks/formatting.mjs +4 -2
  3. package/build/esm/hooks/locale.mjs +4 -2
  4. package/build/esm/index.mjs +1 -4
  5. package/build/esm/routing/LocalizedLink.mjs +4 -4
  6. package/build/esm/routing/LocalizedNavigation.mjs +32 -41
  7. package/build/esm/routing/context.mjs +10 -4
  8. package/build/esnext/hooks/formatting.esnext +4 -2
  9. package/build/esnext/hooks/locale.esnext +4 -2
  10. package/build/esnext/index.esnext +1 -4
  11. package/build/esnext/routing/LocalizedLink.esnext +4 -4
  12. package/build/esnext/routing/LocalizedNavigation.esnext +27 -29
  13. package/build/esnext/routing/context.esnext +12 -4
  14. package/build/tsconfig.tsbuildinfo +1 -1
  15. package/build/typescript/context.d.ts +12 -3
  16. package/build/typescript/context.d.ts.map +1 -1
  17. package/build/typescript/hooks/formatting.d.ts +1 -1
  18. package/build/typescript/hooks/formatting.d.ts.map +1 -1
  19. package/build/typescript/hooks/locale.d.ts +1 -1
  20. package/build/typescript/hooks/locale.d.ts.map +1 -1
  21. package/build/typescript/index.d.ts +1 -3
  22. package/build/typescript/index.d.ts.map +1 -1
  23. package/build/typescript/routing/LocalizedLink.d.ts.map +1 -1
  24. package/build/typescript/routing/LocalizedNavigation.d.ts +8 -11
  25. package/build/typescript/routing/LocalizedNavigation.d.ts.map +1 -1
  26. package/build/typescript/routing/context.d.ts +1 -2
  27. package/build/typescript/routing/context.d.ts.map +1 -1
  28. package/build/typescript/routing.d.ts +0 -1
  29. package/build/typescript/routing.d.ts.map +1 -1
  30. package/package.json +7 -28
  31. package/source/context.ts +12 -6
  32. package/source/hooks/formatting.ts +4 -2
  33. package/source/hooks/locale.ts +4 -2
  34. package/source/index.ts +1 -6
  35. package/source/routing/LocalizedLink.tsx +4 -4
  36. package/source/routing/LocalizedNavigation.tsx +45 -59
  37. package/source/routing/context.ts +13 -4
  38. package/source/routing.ts +0 -1
  39. package/tsconfig.json +0 -1
  40. package/build/esm/Localization.mjs +0 -37
  41. package/build/esm/context.mjs +0 -6
  42. package/build/esm/request-router.mjs +0 -49
  43. package/build/esm/routing/LocalizedRouter.mjs +0 -34
  44. package/build/esnext/Localization.esnext +0 -44
  45. package/build/esnext/context.esnext +0 -6
  46. package/build/esnext/request-router.esnext +0 -48
  47. package/build/esnext/routing/LocalizedRouter.esnext +0 -32
  48. package/build/typescript/request-router.d.ts +0 -16
  49. package/build/typescript/request-router.d.ts.map +0 -1
  50. package/source/Localization.tsx +0 -61
  51. package/source/request-router.ts +0 -98
  52. package/source/routing/LocalizedRouter.ts +0 -46
@@ -1,46 +0,0 @@
1
- import {Router, type RouterOptions} from '@quilted/preact-router';
2
-
3
- import type {RouteLocalization, ResolvedRouteLocalization} from './types.ts';
4
-
5
- export class LocalizedRouter extends Router {
6
- readonly localization: ResolvedRouteLocalization;
7
-
8
- constructor(
9
- initial: ConstructorParameters<typeof Router>[0],
10
- {
11
- localization,
12
- isExternal: explicitIsExternal,
13
- }: {localization: RouteLocalization} & Pick<RouterOptions, 'isExternal'>,
14
- ) {
15
- const {localeFromURL} = localization;
16
-
17
- super(initial, {
18
- isExternal(url, currentURL) {
19
- return (
20
- matchedLocale !== localeFromURL(url) ||
21
- (explicitIsExternal?.(url, currentURL) ?? false)
22
- );
23
- },
24
- });
25
-
26
- const currentURL = this.currentRequest.url;
27
-
28
- const matchedLocale = localeFromURL(currentURL);
29
-
30
- const resolvedLocalization: ResolvedRouteLocalization = {
31
- locale: matchedLocale ?? localization.defaultLocale,
32
- ...localization,
33
- };
34
-
35
- this.localization = resolvedLocalization;
36
-
37
- const {pathname: rootPath} = localization.redirectURL(
38
- new URL('/', currentURL),
39
- {
40
- to: resolvedLocalization.locale,
41
- },
42
- );
43
-
44
- if (rootPath.length > 1) Object.assign(this, {base: rootPath});
45
- }
46
- }