@sheet-i18n/react-client 1.6.0-canary.6 → 1.6.0-canary.8
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/dist/index.d.mts +59 -55
- package/dist/index.d.ts +59 -55
- package/dist/index.js +0 -4
- package/dist/index.mjs +0 -2
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,46 +1,8 @@
|
|
|
1
1
|
import { I18nStore } from '@sheet-i18n/react-core';
|
|
2
|
-
import { ObserverManager } from '@sheet-i18n/shared-utils';
|
|
3
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
-
import {
|
|
3
|
+
import { ObserverManager } from '@sheet-i18n/shared-utils';
|
|
5
4
|
import * as react from 'react';
|
|
6
5
|
|
|
7
|
-
interface IStorageService<V extends string> {
|
|
8
|
-
getItem(key: string): V;
|
|
9
|
-
setItem(key: string, value: V): boolean;
|
|
10
|
-
removeItem(key: string): boolean;
|
|
11
|
-
clear(): boolean;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* locale storage manager
|
|
15
|
-
* implements ILocaleStorageManager (injected StorageService)
|
|
16
|
-
*/
|
|
17
|
-
interface ILocaleStorageManager<TSupportedLocales extends readonly string[]> {
|
|
18
|
-
getLocale(): TSupportedLocales[number];
|
|
19
|
-
setLocale(locale: TSupportedLocales[number]): void;
|
|
20
|
-
}
|
|
21
|
-
declare class LocaleStorageManager<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> implements ILocaleStorageManager<TSupportedLocales> {
|
|
22
|
-
private readonly storageService;
|
|
23
|
-
private readonly i18nStore;
|
|
24
|
-
private readonly localeStorageKey;
|
|
25
|
-
observerManager: ObserverManager<TSupportedLocales[number]>;
|
|
26
|
-
constructor(storageService: IStorageService<TSupportedLocales[number]>, i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, localeStorageKey?: string);
|
|
27
|
-
private initializeCurrentLocale;
|
|
28
|
-
getLocale: () => TSupportedLocales[number];
|
|
29
|
-
setLocale: (locale: TSupportedLocales[number]) => void;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* getter of locale storage manager
|
|
33
|
-
* @description getLocaleStorageManager is a function that returns a locale storage manager
|
|
34
|
-
* @param i18nStore - i18n store
|
|
35
|
-
* @param(optional) storage - storage service
|
|
36
|
-
* If storage is not provided, it will use the window.localStorage.
|
|
37
|
-
*/
|
|
38
|
-
declare const getLocaleStorageManager: <TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false>(i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, storage?: IStorageService<string>) => LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
39
|
-
|
|
40
|
-
declare function useLocaleStorage<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false>(localeStorageManager: LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>): {
|
|
41
|
-
locale: TSupportedLocales[number] | undefined;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
6
|
type IntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> = {
|
|
45
7
|
i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
46
8
|
currentLocale?: TSupportedLocales[number];
|
|
@@ -48,7 +10,28 @@ type IntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet e
|
|
|
48
10
|
};
|
|
49
11
|
declare function IntlProvider<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false>({ i18nStore, currentLocale, children, }: IntlProviderProps<TSupportedLocales, TLocaleSet, TTypeSafe>): react_jsx_runtime.JSX.Element;
|
|
50
12
|
|
|
51
|
-
|
|
13
|
+
interface Message {
|
|
14
|
+
}
|
|
15
|
+
type MessageIds = Message extends {
|
|
16
|
+
ids: infer T;
|
|
17
|
+
} ? T extends string ? T : string : string;
|
|
18
|
+
interface MessageDescriptor {
|
|
19
|
+
id?: MessageIds;
|
|
20
|
+
description?: string | object;
|
|
21
|
+
defaultMessage?: any[];
|
|
22
|
+
}
|
|
23
|
+
type PrimitiveType = string | number | boolean | null | undefined | Date;
|
|
24
|
+
type FormatXMLElementFn<T, R = string | T | (string | T)[]> = (parts: Array<string | T>) => R;
|
|
25
|
+
interface ParserOptions {
|
|
26
|
+
ignoreTag?: boolean;
|
|
27
|
+
requiresOtherClause?: boolean;
|
|
28
|
+
shouldParseSkeletons?: boolean;
|
|
29
|
+
captureLocation?: boolean;
|
|
30
|
+
}
|
|
31
|
+
interface Options extends ParserOptions {
|
|
32
|
+
}
|
|
33
|
+
type $T<T extends unknown = unknown> = (this: void, descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>, opts?: Options) => string | T | (T | string)[];
|
|
34
|
+
type UseIntlParams<D = MessageDescriptor> = Parameters<$T> extends [D, ...infer R] ? [...R, Omit<D, 'id'>] : never;
|
|
52
35
|
type ExtendedUseIntlParams<D = MessageDescriptor> = UseIntlParams<D> extends [infer A, infer B, ...infer Rest] ? A extends Record<string, infer V> ? [Record<string, V | React.ReactNode>, B, ...Rest] : [A, B, ...Rest] : UseIntlParams<D>;
|
|
53
36
|
type $TParams = Partial<ExtendedUseIntlParams>;
|
|
54
37
|
/**
|
|
@@ -80,10 +63,6 @@ type UseTranslationReturn<TSupportedLocales extends readonly string[], TLocaleSe
|
|
|
80
63
|
};
|
|
81
64
|
};
|
|
82
65
|
|
|
83
|
-
interface GetTranslationParams<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false, TSheetTitle = TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]] : string> {
|
|
84
|
-
sheetTitle: TSheetTitle;
|
|
85
|
-
i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
86
|
-
}
|
|
87
66
|
type GetTranslationReturn<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean, TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>> = {
|
|
88
67
|
t: <TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>, TValues extends $TParams[0], TOpts extends $TParams[1], TDescriptor extends $TParams[2]>(id: TMessageId, values?: TValues, opts?: TOpts, _descriptor?: TDescriptor) => TTypeSafe extends true ? TMessageId : any;
|
|
89
68
|
} & {
|
|
@@ -92,28 +71,53 @@ type GetTranslationReturn<TSupportedLocales extends readonly string[], TLocaleSe
|
|
|
92
71
|
promise: <TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>, TValues extends $TParams[0], TOpts extends $TParams[1], TDescriptor extends $TParams[2]>(id: TMessageId, values?: TValues, opts?: TOpts, _descriptor?: TDescriptor) => TTypeSafe extends true ? Promise<TMessageId> : any;
|
|
93
72
|
};
|
|
94
73
|
};
|
|
95
|
-
declare function getTranslation<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean, TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>, TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>>({ sheetTitle, i18nStore, }: GetTranslationParams<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle>): GetTranslationReturn<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle>;
|
|
96
74
|
|
|
97
|
-
|
|
75
|
+
interface IStorageService<V extends string> {
|
|
76
|
+
getItem(key: string): V;
|
|
77
|
+
setItem(key: string, value: V): boolean;
|
|
78
|
+
removeItem(key: string): boolean;
|
|
79
|
+
clear(): boolean;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* locale storage manager
|
|
83
|
+
* implements ILocaleStorageManager (injected StorageService)
|
|
84
|
+
*/
|
|
85
|
+
interface ILocaleStorageManager<TSupportedLocales extends readonly string[]> {
|
|
86
|
+
getLocale(): TSupportedLocales[number];
|
|
87
|
+
setLocale(locale: TSupportedLocales[number]): void;
|
|
88
|
+
}
|
|
89
|
+
declare class LocaleStorageManager<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> implements ILocaleStorageManager<TSupportedLocales> {
|
|
90
|
+
private readonly storageService;
|
|
91
|
+
private readonly i18nStore;
|
|
92
|
+
private readonly localeStorageKey;
|
|
93
|
+
observerManager: ObserverManager<TSupportedLocales[number]>;
|
|
94
|
+
constructor(storageService: IStorageService<TSupportedLocales[number]>, i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, localeStorageKey?: string);
|
|
95
|
+
private initializeCurrentLocale;
|
|
96
|
+
getLocale: () => TSupportedLocales[number];
|
|
97
|
+
setLocale: (locale: TSupportedLocales[number]) => void;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
declare function useLocaleStorage<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false>(localeStorageManager: LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>): {
|
|
101
|
+
locale: TSupportedLocales[number] | undefined;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
interface StorageBasedIntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> {
|
|
98
105
|
i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
99
106
|
storageManager: LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
100
107
|
fallbackUI?: React.ReactNode;
|
|
101
108
|
children: React.ReactNode;
|
|
102
|
-
}
|
|
109
|
+
}
|
|
103
110
|
declare function StorageBasedIntlProvider<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false>({ i18nStore, storageManager, fallbackUI, children, }: StorageBasedIntlProviderProps<TSupportedLocales, TLocaleSet, TTypeSafe>): string | number | bigint | boolean | Iterable<react.ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | null | undefined> | react_jsx_runtime.JSX.Element | null;
|
|
104
111
|
|
|
105
112
|
interface Plugins<TRules extends Rules> {
|
|
106
113
|
rules?: TRules;
|
|
107
114
|
}
|
|
108
115
|
type CreateI18nContextReturn<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TRules extends Rules, TTypeSafe extends boolean = false> = {
|
|
109
|
-
IntlProvider: (props:
|
|
110
|
-
|
|
111
|
-
children?: React.ReactNode;
|
|
112
|
-
}) => ReturnType<typeof IntlProvider>;
|
|
113
|
-
StorageBasedIntlProvider: (props: Omit<StorageBasedIntlProviderProps<TSupportedLocales, TLocaleSet, TTypeSafe>, 'i18nStore'>) => ReturnType<typeof StorageBasedIntlProvider>;
|
|
116
|
+
IntlProvider: (props: IntlProviderProps<TSupportedLocales, TLocaleSet, TTypeSafe>) => ReturnType<typeof IntlProvider<TSupportedLocales, TLocaleSet, TTypeSafe>>;
|
|
117
|
+
StorageBasedIntlProvider: (props: StorageBasedIntlProviderProps<TSupportedLocales, TLocaleSet, TTypeSafe>) => ReturnType<typeof StorageBasedIntlProvider<TSupportedLocales, TLocaleSet, TTypeSafe>>;
|
|
114
118
|
useTranslation: <TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>>(sheetTitle: TSheetTitle) => UseTranslationReturn<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle, TRules>;
|
|
115
|
-
getTranslation: <TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>>(sheetTitle: TSheetTitle) =>
|
|
116
|
-
getLocaleStorageManager: (storageService?: IStorageService<string>) =>
|
|
119
|
+
getTranslation: <TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>>(sheetTitle: TSheetTitle) => GetTranslationReturn<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle>;
|
|
120
|
+
getLocaleStorageManager: (storageService?: IStorageService<string>) => LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
117
121
|
useLocaleStorage: typeof useLocaleStorage;
|
|
118
122
|
};
|
|
119
123
|
declare function createI18nContext<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TRules extends Rules, TTypeSafe extends boolean = false>(i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, plugins?: Plugins<TRules>): CreateI18nContextReturn<TSupportedLocales, TLocaleSet, TRules, TTypeSafe>;
|
|
@@ -125,4 +129,4 @@ declare class RuleService<TSupportedLocales extends SupportedLocales, TLocaleSet
|
|
|
125
129
|
}
|
|
126
130
|
declare const ruleFactory: <TSupportedLocales extends SupportedLocales, TLocaleSet extends LocaleSet, TTypeSafe extends TypeSafe>(i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>) => RuleService<TSupportedLocales, TLocaleSet, TTypeSafe, SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>, SafeMessageId<TSupportedLocales, TLocaleSet, SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>, TTypeSafe>>;
|
|
127
131
|
|
|
128
|
-
export { type
|
|
132
|
+
export { type IStorageService as Storage, createI18nContext, ruleFactory };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,46 +1,8 @@
|
|
|
1
1
|
import { I18nStore } from '@sheet-i18n/react-core';
|
|
2
|
-
import { ObserverManager } from '@sheet-i18n/shared-utils';
|
|
3
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
-
import {
|
|
3
|
+
import { ObserverManager } from '@sheet-i18n/shared-utils';
|
|
5
4
|
import * as react from 'react';
|
|
6
5
|
|
|
7
|
-
interface IStorageService<V extends string> {
|
|
8
|
-
getItem(key: string): V;
|
|
9
|
-
setItem(key: string, value: V): boolean;
|
|
10
|
-
removeItem(key: string): boolean;
|
|
11
|
-
clear(): boolean;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* locale storage manager
|
|
15
|
-
* implements ILocaleStorageManager (injected StorageService)
|
|
16
|
-
*/
|
|
17
|
-
interface ILocaleStorageManager<TSupportedLocales extends readonly string[]> {
|
|
18
|
-
getLocale(): TSupportedLocales[number];
|
|
19
|
-
setLocale(locale: TSupportedLocales[number]): void;
|
|
20
|
-
}
|
|
21
|
-
declare class LocaleStorageManager<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> implements ILocaleStorageManager<TSupportedLocales> {
|
|
22
|
-
private readonly storageService;
|
|
23
|
-
private readonly i18nStore;
|
|
24
|
-
private readonly localeStorageKey;
|
|
25
|
-
observerManager: ObserverManager<TSupportedLocales[number]>;
|
|
26
|
-
constructor(storageService: IStorageService<TSupportedLocales[number]>, i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, localeStorageKey?: string);
|
|
27
|
-
private initializeCurrentLocale;
|
|
28
|
-
getLocale: () => TSupportedLocales[number];
|
|
29
|
-
setLocale: (locale: TSupportedLocales[number]) => void;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* getter of locale storage manager
|
|
33
|
-
* @description getLocaleStorageManager is a function that returns a locale storage manager
|
|
34
|
-
* @param i18nStore - i18n store
|
|
35
|
-
* @param(optional) storage - storage service
|
|
36
|
-
* If storage is not provided, it will use the window.localStorage.
|
|
37
|
-
*/
|
|
38
|
-
declare const getLocaleStorageManager: <TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false>(i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, storage?: IStorageService<string>) => LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
39
|
-
|
|
40
|
-
declare function useLocaleStorage<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false>(localeStorageManager: LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>): {
|
|
41
|
-
locale: TSupportedLocales[number] | undefined;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
6
|
type IntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> = {
|
|
45
7
|
i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
46
8
|
currentLocale?: TSupportedLocales[number];
|
|
@@ -48,7 +10,28 @@ type IntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet e
|
|
|
48
10
|
};
|
|
49
11
|
declare function IntlProvider<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false>({ i18nStore, currentLocale, children, }: IntlProviderProps<TSupportedLocales, TLocaleSet, TTypeSafe>): react_jsx_runtime.JSX.Element;
|
|
50
12
|
|
|
51
|
-
|
|
13
|
+
interface Message {
|
|
14
|
+
}
|
|
15
|
+
type MessageIds = Message extends {
|
|
16
|
+
ids: infer T;
|
|
17
|
+
} ? T extends string ? T : string : string;
|
|
18
|
+
interface MessageDescriptor {
|
|
19
|
+
id?: MessageIds;
|
|
20
|
+
description?: string | object;
|
|
21
|
+
defaultMessage?: any[];
|
|
22
|
+
}
|
|
23
|
+
type PrimitiveType = string | number | boolean | null | undefined | Date;
|
|
24
|
+
type FormatXMLElementFn<T, R = string | T | (string | T)[]> = (parts: Array<string | T>) => R;
|
|
25
|
+
interface ParserOptions {
|
|
26
|
+
ignoreTag?: boolean;
|
|
27
|
+
requiresOtherClause?: boolean;
|
|
28
|
+
shouldParseSkeletons?: boolean;
|
|
29
|
+
captureLocation?: boolean;
|
|
30
|
+
}
|
|
31
|
+
interface Options extends ParserOptions {
|
|
32
|
+
}
|
|
33
|
+
type $T<T extends unknown = unknown> = (this: void, descriptor: MessageDescriptor, values?: Record<string, PrimitiveType | T | FormatXMLElementFn<T>>, opts?: Options) => string | T | (T | string)[];
|
|
34
|
+
type UseIntlParams<D = MessageDescriptor> = Parameters<$T> extends [D, ...infer R] ? [...R, Omit<D, 'id'>] : never;
|
|
52
35
|
type ExtendedUseIntlParams<D = MessageDescriptor> = UseIntlParams<D> extends [infer A, infer B, ...infer Rest] ? A extends Record<string, infer V> ? [Record<string, V | React.ReactNode>, B, ...Rest] : [A, B, ...Rest] : UseIntlParams<D>;
|
|
53
36
|
type $TParams = Partial<ExtendedUseIntlParams>;
|
|
54
37
|
/**
|
|
@@ -80,10 +63,6 @@ type UseTranslationReturn<TSupportedLocales extends readonly string[], TLocaleSe
|
|
|
80
63
|
};
|
|
81
64
|
};
|
|
82
65
|
|
|
83
|
-
interface GetTranslationParams<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false, TSheetTitle = TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]] : string> {
|
|
84
|
-
sheetTitle: TSheetTitle;
|
|
85
|
-
i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
86
|
-
}
|
|
87
66
|
type GetTranslationReturn<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean, TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>> = {
|
|
88
67
|
t: <TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>, TValues extends $TParams[0], TOpts extends $TParams[1], TDescriptor extends $TParams[2]>(id: TMessageId, values?: TValues, opts?: TOpts, _descriptor?: TDescriptor) => TTypeSafe extends true ? TMessageId : any;
|
|
89
68
|
} & {
|
|
@@ -92,28 +71,53 @@ type GetTranslationReturn<TSupportedLocales extends readonly string[], TLocaleSe
|
|
|
92
71
|
promise: <TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>, TValues extends $TParams[0], TOpts extends $TParams[1], TDescriptor extends $TParams[2]>(id: TMessageId, values?: TValues, opts?: TOpts, _descriptor?: TDescriptor) => TTypeSafe extends true ? Promise<TMessageId> : any;
|
|
93
72
|
};
|
|
94
73
|
};
|
|
95
|
-
declare function getTranslation<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean, TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>, TMessageId extends SafeMessageId<TSupportedLocales, TLocaleSet, TSheetTitle, TTypeSafe>>({ sheetTitle, i18nStore, }: GetTranslationParams<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle>): GetTranslationReturn<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle>;
|
|
96
74
|
|
|
97
|
-
|
|
75
|
+
interface IStorageService<V extends string> {
|
|
76
|
+
getItem(key: string): V;
|
|
77
|
+
setItem(key: string, value: V): boolean;
|
|
78
|
+
removeItem(key: string): boolean;
|
|
79
|
+
clear(): boolean;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* locale storage manager
|
|
83
|
+
* implements ILocaleStorageManager (injected StorageService)
|
|
84
|
+
*/
|
|
85
|
+
interface ILocaleStorageManager<TSupportedLocales extends readonly string[]> {
|
|
86
|
+
getLocale(): TSupportedLocales[number];
|
|
87
|
+
setLocale(locale: TSupportedLocales[number]): void;
|
|
88
|
+
}
|
|
89
|
+
declare class LocaleStorageManager<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> implements ILocaleStorageManager<TSupportedLocales> {
|
|
90
|
+
private readonly storageService;
|
|
91
|
+
private readonly i18nStore;
|
|
92
|
+
private readonly localeStorageKey;
|
|
93
|
+
observerManager: ObserverManager<TSupportedLocales[number]>;
|
|
94
|
+
constructor(storageService: IStorageService<TSupportedLocales[number]>, i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, localeStorageKey?: string);
|
|
95
|
+
private initializeCurrentLocale;
|
|
96
|
+
getLocale: () => TSupportedLocales[number];
|
|
97
|
+
setLocale: (locale: TSupportedLocales[number]) => void;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
declare function useLocaleStorage<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false>(localeStorageManager: LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>): {
|
|
101
|
+
locale: TSupportedLocales[number] | undefined;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
interface StorageBasedIntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> {
|
|
98
105
|
i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
99
106
|
storageManager: LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
100
107
|
fallbackUI?: React.ReactNode;
|
|
101
108
|
children: React.ReactNode;
|
|
102
|
-
}
|
|
109
|
+
}
|
|
103
110
|
declare function StorageBasedIntlProvider<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false>({ i18nStore, storageManager, fallbackUI, children, }: StorageBasedIntlProviderProps<TSupportedLocales, TLocaleSet, TTypeSafe>): string | number | bigint | boolean | Iterable<react.ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | null | undefined> | react_jsx_runtime.JSX.Element | null;
|
|
104
111
|
|
|
105
112
|
interface Plugins<TRules extends Rules> {
|
|
106
113
|
rules?: TRules;
|
|
107
114
|
}
|
|
108
115
|
type CreateI18nContextReturn<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TRules extends Rules, TTypeSafe extends boolean = false> = {
|
|
109
|
-
IntlProvider: (props:
|
|
110
|
-
|
|
111
|
-
children?: React.ReactNode;
|
|
112
|
-
}) => ReturnType<typeof IntlProvider>;
|
|
113
|
-
StorageBasedIntlProvider: (props: Omit<StorageBasedIntlProviderProps<TSupportedLocales, TLocaleSet, TTypeSafe>, 'i18nStore'>) => ReturnType<typeof StorageBasedIntlProvider>;
|
|
116
|
+
IntlProvider: (props: IntlProviderProps<TSupportedLocales, TLocaleSet, TTypeSafe>) => ReturnType<typeof IntlProvider<TSupportedLocales, TLocaleSet, TTypeSafe>>;
|
|
117
|
+
StorageBasedIntlProvider: (props: StorageBasedIntlProviderProps<TSupportedLocales, TLocaleSet, TTypeSafe>) => ReturnType<typeof StorageBasedIntlProvider<TSupportedLocales, TLocaleSet, TTypeSafe>>;
|
|
114
118
|
useTranslation: <TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>>(sheetTitle: TSheetTitle) => UseTranslationReturn<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle, TRules>;
|
|
115
|
-
getTranslation: <TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>>(sheetTitle: TSheetTitle) =>
|
|
116
|
-
getLocaleStorageManager: (storageService?: IStorageService<string>) =>
|
|
119
|
+
getTranslation: <TSheetTitle extends SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>>(sheetTitle: TSheetTitle) => GetTranslationReturn<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle>;
|
|
120
|
+
getLocaleStorageManager: (storageService?: IStorageService<string>) => LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
117
121
|
useLocaleStorage: typeof useLocaleStorage;
|
|
118
122
|
};
|
|
119
123
|
declare function createI18nContext<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TRules extends Rules, TTypeSafe extends boolean = false>(i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, plugins?: Plugins<TRules>): CreateI18nContextReturn<TSupportedLocales, TLocaleSet, TRules, TTypeSafe>;
|
|
@@ -125,4 +129,4 @@ declare class RuleService<TSupportedLocales extends SupportedLocales, TLocaleSet
|
|
|
125
129
|
}
|
|
126
130
|
declare const ruleFactory: <TSupportedLocales extends SupportedLocales, TLocaleSet extends LocaleSet, TTypeSafe extends TypeSafe>(i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>) => RuleService<TSupportedLocales, TLocaleSet, TTypeSafe, SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>, SafeMessageId<TSupportedLocales, TLocaleSet, SafeSheetTitle<TSupportedLocales, TLocaleSet, TTypeSafe>, TTypeSafe>>;
|
|
127
131
|
|
|
128
|
-
export { type
|
|
132
|
+
export { type IStorageService as Storage, createI18nContext, ruleFactory };
|
package/dist/index.js
CHANGED
|
@@ -38,8 +38,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
38
38
|
// src/index.ts
|
|
39
39
|
var src_exports = {};
|
|
40
40
|
__export(src_exports, {
|
|
41
|
-
IntlProvider: () => IntlProvider,
|
|
42
|
-
LocaleStorageManager: () => LocaleStorageManager,
|
|
43
41
|
createI18nContext: () => createI18nContext,
|
|
44
42
|
ruleFactory: () => ruleFactory
|
|
45
43
|
});
|
|
@@ -564,8 +562,6 @@ var ruleFactory = (i18nStore) => {
|
|
|
564
562
|
};
|
|
565
563
|
// Annotate the CommonJS export names for ESM import in node:
|
|
566
564
|
0 && (module.exports = {
|
|
567
|
-
IntlProvider,
|
|
568
|
-
LocaleStorageManager,
|
|
569
565
|
createI18nContext,
|
|
570
566
|
ruleFactory
|
|
571
567
|
});
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sheet-i18n/react-client",
|
|
3
|
-
"version": "1.6.0-canary.
|
|
3
|
+
"version": "1.6.0-canary.8",
|
|
4
4
|
"description": "a client package for react modules used by sheet-i18n",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
},
|
|
26
26
|
"license": "ISC",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@sheet-i18n/shared-utils": "1.8.2",
|
|
29
28
|
"@sheet-i18n/errors": "1.8.1",
|
|
30
|
-
"@sheet-i18n/
|
|
29
|
+
"@sheet-i18n/shared-utils": "1.8.2",
|
|
30
|
+
"@sheet-i18n/react-core": "1.6.0-canary.8"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/react": "^19.0.2",
|