intor 2.2.4 → 2.2.6

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.
@@ -1,11 +1,91 @@
1
- import { Level, NormalizerConfig, FormatterConfig, LoggerPreset } from 'logry/edge';
2
- import { Locale, LocaleMessages, FallbackLocalesMap, TranslateHandlers, ScopedLeafKeys, LocalizedLeafKeys, Replacement, LocalizedNodeKeys } from 'intor-translator';
3
- import * as React from 'react';
1
+ import { LocaleMessages, Locale, FallbackLocalesMap, TranslateHandlers, ScopedLeafKeys, LocalizedLeafKeys, Replacement, LocalizedNodeKeys } from 'intor-translator';
4
2
  import { Url } from 'next/dist/shared/lib/router/router';
5
3
  import { LinkProps as LinkProps$1 } from 'next/link';
4
+ import * as React from 'react';
6
5
  import * as next_dist_shared_lib_app_router_context_shared_runtime from 'next/dist/shared/lib/app-router-context.shared-runtime';
7
6
  import { NavigateOptions } from 'next/dist/shared/lib/app-router-context.shared-runtime';
7
+ import { Level, NormalizerConfig, FormatterConfig, LoggerPreset } from 'logry/edge';
8
8
  import { RedirectType } from 'next/navigation';
9
+ import * as react_jsx_runtime from 'react/jsx-runtime';
10
+
11
+ declare const PREFIX_PLACEHOLDER = "{locale}";
12
+
13
+ /**
14
+ * Conditional type for generated types.
15
+ * - Returns `Then` if `IntorGeneratedTypes` exists, otherwise `Else`.
16
+ */
17
+ type IfGen<Then, Else = never> = IntorGeneratedTypes extends void ? Else : Then;
18
+ /**
19
+ * Union of all configuration keys.
20
+ * - Defaults to `string` if `IntorGeneratedTypes` does not exist.
21
+ */
22
+ type GenConfigKeys = IfGen<keyof IntorGeneratedTypes, string>;
23
+ /**
24
+ * Configuration shape for a given config key.
25
+ * - If `IntorGeneratedTypes` is not defined, falls back to default shape.
26
+ * Otherwise, picks `Locales` and `Messages` according to the key.
27
+ */
28
+ type GenConfig<CK extends GenConfigKeys = "__default__"> = IntorGeneratedTypes extends void ? {
29
+ Locales: string;
30
+ Messages: LocaleMessages;
31
+ } : CK extends keyof IntorGeneratedTypes ? {
32
+ Locales: IntorGeneratedTypes[CK]["Locales"];
33
+ Messages: {
34
+ [K in IntorGeneratedTypes[CK]["Locales"]]: IntorGeneratedTypes[CK]["Messages"][typeof PREFIX_PLACEHOLDER];
35
+ };
36
+ } : never;
37
+ /** Extracts messages for a given config key */
38
+ type GenMessages<CK extends GenConfigKeys = "__default__"> = GenConfig<CK>["Messages"];
39
+ /** Extracts locales for a given config key */
40
+ type GenLocale<CK extends GenConfigKeys = "__default__"> = GenConfig<CK>["Locales"];
41
+
42
+ interface LinkProps extends Omit<LinkProps$1, "href">, Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "href"> {
43
+ href?: Url;
44
+ locale?: GenLocale;
45
+ }
46
+ /**
47
+ * Localized Link component
48
+ *
49
+ * - Wraps Next.js Link and handles locale switching.
50
+ * - Full reload occurs only if the locale changes and requires it; otherwise updates context.
51
+ */
52
+ declare const Link: ({ href, locale, children, onClick, ...props }: LinkProps) => React.JSX.Element;
53
+
54
+ /**
55
+ * Custom hook to get the current pathname in different forms based on the active locale.
56
+ *
57
+ * This hook wraps Next.js `usePathname` and processes the pathname according to the app's
58
+ * locale configuration.
59
+ *
60
+ * @example
61
+ * const { localizedPathname, standardizedPathname, unprefixedPathname } = usePathname();
62
+ * console.log(localizedPathname); // e.g. "/en/about"
63
+ * console.log(standardizedPathname); // e.g. "/{locale}/about"
64
+ * console.log(unprefixedPathname); // e.g. "/about"
65
+ */
66
+ declare const usePathname: () => {
67
+ localizedPathname: string;
68
+ standardizedPathname: string;
69
+ unprefixedPathname: string;
70
+ };
71
+
72
+ /**
73
+ * useRouter hook.
74
+ *
75
+ * Wraps Next.js useRouter and provides push/replace methods that automatically switch locale.
76
+ */
77
+ declare const useRouter: () => {
78
+ back(): void;
79
+ forward(): void;
80
+ refresh(): void;
81
+ prefetch(href: string, options?: next_dist_shared_lib_app_router_context_shared_runtime.PrefetchOptions): void;
82
+ push: (href: string, options?: NavigateOptions & {
83
+ locale?: GenLocale;
84
+ }) => void;
85
+ replace: (href: string, options?: NavigateOptions & {
86
+ locale?: Locale;
87
+ }) => void;
88
+ };
9
89
 
10
90
  type CookieRawOptions = {
11
91
  /** Completely disable cookie usage (no read, no write, no lookup by name) - default: false */
@@ -125,55 +205,38 @@ type IntorResolvedConfig = (WithLoader | WithoutLoader) & {
125
205
  readonly cache: CacheResolvedOptions;
126
206
  };
127
207
 
208
+ /**
209
+ * redirect utility.
210
+ *
211
+ * - Wraps Next.js redirect and applies locale-aware navigation.
212
+ * - Automatically prefixes the pathname with the correct locale.
213
+ * - External URLs are redirected directly without modification.
214
+ */
215
+ declare const redirect: ({ config, locale, url, type, }: {
216
+ config: IntorResolvedConfig;
217
+ locale?: GenLocale;
218
+ url: string;
219
+ type?: RedirectType | undefined;
220
+ }) => Promise<never>;
221
+
128
222
  interface IntorProviderProps {
129
223
  value: {
130
224
  config: IntorResolvedConfig;
131
225
  initialLocale: Locale;
132
- pathname: string;
133
- messages: Readonly<LocaleMessages>;
226
+ pathname?: string;
227
+ messages?: Readonly<LocaleMessages>;
134
228
  };
135
229
  children: React.ReactNode;
136
230
  }
137
231
 
138
- declare const IntorProvider: ({ value: { config, pathname, initialLocale, messages }, children, }: IntorProviderProps) => React.JSX.Element;
232
+ declare const IntorProvider: ({ value: { config, pathname, initialLocale, messages }, children, }: IntorProviderProps) => react_jsx_runtime.JSX.Element;
139
233
 
140
234
  type TranslateHandlersProviderProps = {
141
235
  children: React.ReactNode;
142
236
  handlers: TranslateHandlers;
143
237
  };
144
238
 
145
- declare const TranslateHandlersProvider: ({ children, handlers, }: TranslateHandlersProviderProps) => React.JSX.Element;
146
-
147
- declare const PREFIX_PLACEHOLDER = "{locale}";
148
-
149
- /**
150
- * Conditional type for generated types.
151
- * - Returns `Then` if `IntorGeneratedTypes` exists, otherwise `Else`.
152
- */
153
- type IfGen<Then, Else = never> = IntorGeneratedTypes extends void ? Else : Then;
154
- /**
155
- * Union of all configuration keys.
156
- * - Defaults to `string` if `IntorGeneratedTypes` does not exist.
157
- */
158
- type GenConfigKeys = IfGen<keyof IntorGeneratedTypes, string>;
159
- /**
160
- * Configuration shape for a given config key.
161
- * - If `IntorGeneratedTypes` is not defined, falls back to default shape.
162
- * Otherwise, picks `Locales` and `Messages` according to the key.
163
- */
164
- type GenConfig<CK extends GenConfigKeys = "__default__"> = IntorGeneratedTypes extends void ? {
165
- Locales: string;
166
- Messages: LocaleMessages;
167
- } : CK extends keyof IntorGeneratedTypes ? {
168
- Locales: IntorGeneratedTypes[CK]["Locales"];
169
- Messages: {
170
- [K in IntorGeneratedTypes[CK]["Locales"]]: IntorGeneratedTypes[CK]["Messages"][typeof PREFIX_PLACEHOLDER];
171
- };
172
- } : never;
173
- /** Extracts messages for a given config key */
174
- type GenMessages<CK extends GenConfigKeys = "__default__"> = GenConfig<CK>["Messages"];
175
- /** Extracts locales for a given config key */
176
- type GenLocale<CK extends GenConfigKeys = "__default__"> = GenConfig<CK>["Locales"];
239
+ declare const TranslateHandlersProvider: ({ children, handlers, }: TranslateHandlersProviderProps) => react_jsx_runtime.JSX.Element;
177
240
 
178
241
  /** Base properties shared by all translator instances. */
179
242
  interface TranslatorBaseProps<M = unknown> {
@@ -216,57 +279,4 @@ type TranslatorInstance<M, PK extends string | undefined = undefined> = {
216
279
  declare function useTranslator<CK extends GenConfigKeys = "__default__">(): TranslatorInstance<GenMessages<CK>>;
217
280
  declare function useTranslator<CK extends GenConfigKeys = "__default__", PK extends string = LocalizedNodeKeys<GenMessages<CK>>>(preKey: IfGen<PK, string>): TranslatorInstance<GenMessages<CK>, PK>;
218
281
 
219
- interface LinkProps extends Omit<LinkProps$1, "href">, Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "href"> {
220
- href?: Url;
221
- locale?: GenLocale;
222
- }
223
- /**
224
- * Localized Link component
225
- *
226
- * - Wraps Next.js Link and handles locale switching.
227
- * - Full reload occurs only if the locale changes and requires it; otherwise updates context.
228
- */
229
- declare const Link: ({ href, locale, children, onClick, ...props }: LinkProps) => React.JSX.Element;
230
-
231
- /**
232
- * usePathname hook
233
- *
234
- * Wraps Next.js usePathname and returns the current pathname prefixed with the active locale.
235
- */
236
- declare const usePathname: () => string;
237
-
238
- /**
239
- * useRouter hook.
240
- *
241
- * Wraps Next.js useRouter and provides push/replace methods that automatically switch locale.
242
- */
243
- declare const useRouter: () => {
244
- back(): void;
245
- forward(): void;
246
- refresh(): void;
247
- prefetch(href: string, options?: next_dist_shared_lib_app_router_context_shared_runtime.PrefetchOptions): void;
248
- push: (href: string, options?: NavigateOptions & {
249
- locale?: GenLocale;
250
- }) => void;
251
- replace: (href: string, options?: NavigateOptions & {
252
- locale?: Locale;
253
- }) => void;
254
- };
255
-
256
- /**
257
- * redirect utility.
258
- *
259
- * - Wraps Next.js redirect and applies locale-aware navigation.
260
- * - Automatically prefixes the pathname with the correct locale.
261
- * - External URLs are redirected directly without modification.
262
- */
263
- declare const redirect: ({ config, locale, url, type, }: {
264
- config: IntorResolvedConfig;
265
- locale?: GenLocale;
266
- url: string;
267
- type?: RedirectType | undefined;
268
- }) => Promise<never>;
269
-
270
- declare const PATHNAME_HEADER_NAME = "x-intor-pathname";
271
-
272
- export { IntorProvider, type IntorProviderProps, Link, PATHNAME_HEADER_NAME, TranslateHandlersProvider, type TranslateHandlersProviderProps, redirect, usePathname, useRouter, useTranslator };
282
+ export { IntorProvider, type IntorProviderProps, Link, TranslateHandlersProvider, type TranslateHandlersProviderProps, redirect, usePathname, useRouter, useTranslator };
@@ -1,11 +1,91 @@
1
- import { Level, NormalizerConfig, FormatterConfig, LoggerPreset } from 'logry/edge';
2
- import { Locale, LocaleMessages, FallbackLocalesMap, TranslateHandlers, ScopedLeafKeys, LocalizedLeafKeys, Replacement, LocalizedNodeKeys } from 'intor-translator';
3
- import * as React from 'react';
1
+ import { LocaleMessages, Locale, FallbackLocalesMap, TranslateHandlers, ScopedLeafKeys, LocalizedLeafKeys, Replacement, LocalizedNodeKeys } from 'intor-translator';
4
2
  import { Url } from 'next/dist/shared/lib/router/router';
5
3
  import { LinkProps as LinkProps$1 } from 'next/link';
4
+ import * as React from 'react';
6
5
  import * as next_dist_shared_lib_app_router_context_shared_runtime from 'next/dist/shared/lib/app-router-context.shared-runtime';
7
6
  import { NavigateOptions } from 'next/dist/shared/lib/app-router-context.shared-runtime';
7
+ import { Level, NormalizerConfig, FormatterConfig, LoggerPreset } from 'logry/edge';
8
8
  import { RedirectType } from 'next/navigation';
9
+ import * as react_jsx_runtime from 'react/jsx-runtime';
10
+
11
+ declare const PREFIX_PLACEHOLDER = "{locale}";
12
+
13
+ /**
14
+ * Conditional type for generated types.
15
+ * - Returns `Then` if `IntorGeneratedTypes` exists, otherwise `Else`.
16
+ */
17
+ type IfGen<Then, Else = never> = IntorGeneratedTypes extends void ? Else : Then;
18
+ /**
19
+ * Union of all configuration keys.
20
+ * - Defaults to `string` if `IntorGeneratedTypes` does not exist.
21
+ */
22
+ type GenConfigKeys = IfGen<keyof IntorGeneratedTypes, string>;
23
+ /**
24
+ * Configuration shape for a given config key.
25
+ * - If `IntorGeneratedTypes` is not defined, falls back to default shape.
26
+ * Otherwise, picks `Locales` and `Messages` according to the key.
27
+ */
28
+ type GenConfig<CK extends GenConfigKeys = "__default__"> = IntorGeneratedTypes extends void ? {
29
+ Locales: string;
30
+ Messages: LocaleMessages;
31
+ } : CK extends keyof IntorGeneratedTypes ? {
32
+ Locales: IntorGeneratedTypes[CK]["Locales"];
33
+ Messages: {
34
+ [K in IntorGeneratedTypes[CK]["Locales"]]: IntorGeneratedTypes[CK]["Messages"][typeof PREFIX_PLACEHOLDER];
35
+ };
36
+ } : never;
37
+ /** Extracts messages for a given config key */
38
+ type GenMessages<CK extends GenConfigKeys = "__default__"> = GenConfig<CK>["Messages"];
39
+ /** Extracts locales for a given config key */
40
+ type GenLocale<CK extends GenConfigKeys = "__default__"> = GenConfig<CK>["Locales"];
41
+
42
+ interface LinkProps extends Omit<LinkProps$1, "href">, Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "href"> {
43
+ href?: Url;
44
+ locale?: GenLocale;
45
+ }
46
+ /**
47
+ * Localized Link component
48
+ *
49
+ * - Wraps Next.js Link and handles locale switching.
50
+ * - Full reload occurs only if the locale changes and requires it; otherwise updates context.
51
+ */
52
+ declare const Link: ({ href, locale, children, onClick, ...props }: LinkProps) => React.JSX.Element;
53
+
54
+ /**
55
+ * Custom hook to get the current pathname in different forms based on the active locale.
56
+ *
57
+ * This hook wraps Next.js `usePathname` and processes the pathname according to the app's
58
+ * locale configuration.
59
+ *
60
+ * @example
61
+ * const { localizedPathname, standardizedPathname, unprefixedPathname } = usePathname();
62
+ * console.log(localizedPathname); // e.g. "/en/about"
63
+ * console.log(standardizedPathname); // e.g. "/{locale}/about"
64
+ * console.log(unprefixedPathname); // e.g. "/about"
65
+ */
66
+ declare const usePathname: () => {
67
+ localizedPathname: string;
68
+ standardizedPathname: string;
69
+ unprefixedPathname: string;
70
+ };
71
+
72
+ /**
73
+ * useRouter hook.
74
+ *
75
+ * Wraps Next.js useRouter and provides push/replace methods that automatically switch locale.
76
+ */
77
+ declare const useRouter: () => {
78
+ back(): void;
79
+ forward(): void;
80
+ refresh(): void;
81
+ prefetch(href: string, options?: next_dist_shared_lib_app_router_context_shared_runtime.PrefetchOptions): void;
82
+ push: (href: string, options?: NavigateOptions & {
83
+ locale?: GenLocale;
84
+ }) => void;
85
+ replace: (href: string, options?: NavigateOptions & {
86
+ locale?: Locale;
87
+ }) => void;
88
+ };
9
89
 
10
90
  type CookieRawOptions = {
11
91
  /** Completely disable cookie usage (no read, no write, no lookup by name) - default: false */
@@ -125,55 +205,38 @@ type IntorResolvedConfig = (WithLoader | WithoutLoader) & {
125
205
  readonly cache: CacheResolvedOptions;
126
206
  };
127
207
 
208
+ /**
209
+ * redirect utility.
210
+ *
211
+ * - Wraps Next.js redirect and applies locale-aware navigation.
212
+ * - Automatically prefixes the pathname with the correct locale.
213
+ * - External URLs are redirected directly without modification.
214
+ */
215
+ declare const redirect: ({ config, locale, url, type, }: {
216
+ config: IntorResolvedConfig;
217
+ locale?: GenLocale;
218
+ url: string;
219
+ type?: RedirectType | undefined;
220
+ }) => Promise<never>;
221
+
128
222
  interface IntorProviderProps {
129
223
  value: {
130
224
  config: IntorResolvedConfig;
131
225
  initialLocale: Locale;
132
- pathname: string;
133
- messages: Readonly<LocaleMessages>;
226
+ pathname?: string;
227
+ messages?: Readonly<LocaleMessages>;
134
228
  };
135
229
  children: React.ReactNode;
136
230
  }
137
231
 
138
- declare const IntorProvider: ({ value: { config, pathname, initialLocale, messages }, children, }: IntorProviderProps) => React.JSX.Element;
232
+ declare const IntorProvider: ({ value: { config, pathname, initialLocale, messages }, children, }: IntorProviderProps) => react_jsx_runtime.JSX.Element;
139
233
 
140
234
  type TranslateHandlersProviderProps = {
141
235
  children: React.ReactNode;
142
236
  handlers: TranslateHandlers;
143
237
  };
144
238
 
145
- declare const TranslateHandlersProvider: ({ children, handlers, }: TranslateHandlersProviderProps) => React.JSX.Element;
146
-
147
- declare const PREFIX_PLACEHOLDER = "{locale}";
148
-
149
- /**
150
- * Conditional type for generated types.
151
- * - Returns `Then` if `IntorGeneratedTypes` exists, otherwise `Else`.
152
- */
153
- type IfGen<Then, Else = never> = IntorGeneratedTypes extends void ? Else : Then;
154
- /**
155
- * Union of all configuration keys.
156
- * - Defaults to `string` if `IntorGeneratedTypes` does not exist.
157
- */
158
- type GenConfigKeys = IfGen<keyof IntorGeneratedTypes, string>;
159
- /**
160
- * Configuration shape for a given config key.
161
- * - If `IntorGeneratedTypes` is not defined, falls back to default shape.
162
- * Otherwise, picks `Locales` and `Messages` according to the key.
163
- */
164
- type GenConfig<CK extends GenConfigKeys = "__default__"> = IntorGeneratedTypes extends void ? {
165
- Locales: string;
166
- Messages: LocaleMessages;
167
- } : CK extends keyof IntorGeneratedTypes ? {
168
- Locales: IntorGeneratedTypes[CK]["Locales"];
169
- Messages: {
170
- [K in IntorGeneratedTypes[CK]["Locales"]]: IntorGeneratedTypes[CK]["Messages"][typeof PREFIX_PLACEHOLDER];
171
- };
172
- } : never;
173
- /** Extracts messages for a given config key */
174
- type GenMessages<CK extends GenConfigKeys = "__default__"> = GenConfig<CK>["Messages"];
175
- /** Extracts locales for a given config key */
176
- type GenLocale<CK extends GenConfigKeys = "__default__"> = GenConfig<CK>["Locales"];
239
+ declare const TranslateHandlersProvider: ({ children, handlers, }: TranslateHandlersProviderProps) => react_jsx_runtime.JSX.Element;
177
240
 
178
241
  /** Base properties shared by all translator instances. */
179
242
  interface TranslatorBaseProps<M = unknown> {
@@ -216,57 +279,4 @@ type TranslatorInstance<M, PK extends string | undefined = undefined> = {
216
279
  declare function useTranslator<CK extends GenConfigKeys = "__default__">(): TranslatorInstance<GenMessages<CK>>;
217
280
  declare function useTranslator<CK extends GenConfigKeys = "__default__", PK extends string = LocalizedNodeKeys<GenMessages<CK>>>(preKey: IfGen<PK, string>): TranslatorInstance<GenMessages<CK>, PK>;
218
281
 
219
- interface LinkProps extends Omit<LinkProps$1, "href">, Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "href"> {
220
- href?: Url;
221
- locale?: GenLocale;
222
- }
223
- /**
224
- * Localized Link component
225
- *
226
- * - Wraps Next.js Link and handles locale switching.
227
- * - Full reload occurs only if the locale changes and requires it; otherwise updates context.
228
- */
229
- declare const Link: ({ href, locale, children, onClick, ...props }: LinkProps) => React.JSX.Element;
230
-
231
- /**
232
- * usePathname hook
233
- *
234
- * Wraps Next.js usePathname and returns the current pathname prefixed with the active locale.
235
- */
236
- declare const usePathname: () => string;
237
-
238
- /**
239
- * useRouter hook.
240
- *
241
- * Wraps Next.js useRouter and provides push/replace methods that automatically switch locale.
242
- */
243
- declare const useRouter: () => {
244
- back(): void;
245
- forward(): void;
246
- refresh(): void;
247
- prefetch(href: string, options?: next_dist_shared_lib_app_router_context_shared_runtime.PrefetchOptions): void;
248
- push: (href: string, options?: NavigateOptions & {
249
- locale?: GenLocale;
250
- }) => void;
251
- replace: (href: string, options?: NavigateOptions & {
252
- locale?: Locale;
253
- }) => void;
254
- };
255
-
256
- /**
257
- * redirect utility.
258
- *
259
- * - Wraps Next.js redirect and applies locale-aware navigation.
260
- * - Automatically prefixes the pathname with the correct locale.
261
- * - External URLs are redirected directly without modification.
262
- */
263
- declare const redirect: ({ config, locale, url, type, }: {
264
- config: IntorResolvedConfig;
265
- locale?: GenLocale;
266
- url: string;
267
- type?: RedirectType | undefined;
268
- }) => Promise<never>;
269
-
270
- declare const PATHNAME_HEADER_NAME = "x-intor-pathname";
271
-
272
- export { IntorProvider, type IntorProviderProps, Link, PATHNAME_HEADER_NAME, TranslateHandlersProvider, type TranslateHandlersProviderProps, redirect, usePathname, useRouter, useTranslator };
282
+ export { IntorProvider, type IntorProviderProps, Link, TranslateHandlersProvider, type TranslateHandlersProviderProps, redirect, usePathname, useRouter, useTranslator };