@sheet-i18n/react-client 1.5.0-canary.0 → 1.5.0-canary.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.
- package/dist/index.d.mts +37 -28
- package/dist/index.d.ts +37 -28
- package/dist/index.js +46 -20
- package/dist/index.mjs +46 -20
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,32 @@
|
|
|
1
|
-
import { MessageDescriptor, IntlShape } from 'react-intl';
|
|
2
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
1
|
import { I18nStore } from '@sheet-i18n/react-core';
|
|
4
2
|
import { ObserverManager } from '@sheet-i18n/shared-utils';
|
|
3
|
+
import { MessageDescriptor, IntlShape } from 'react-intl';
|
|
4
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
interface IStorageService<V extends string> {
|
|
7
|
+
getItem(key: string): V;
|
|
8
|
+
setItem(key: string, value: V): boolean;
|
|
9
|
+
removeItem(key: string): boolean;
|
|
10
|
+
clear(): boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* locale storage manager
|
|
14
|
+
* implements ILocaleStorageManager (injected StorageService)
|
|
15
|
+
*/
|
|
16
|
+
interface ILocaleStorageManager<TSupportedLocales extends readonly string[]> {
|
|
17
|
+
getLocale(): TSupportedLocales[number];
|
|
18
|
+
setLocale(locale: TSupportedLocales[number]): void;
|
|
19
|
+
}
|
|
20
|
+
declare class LocaleStorageManager<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> implements ILocaleStorageManager<TSupportedLocales> {
|
|
21
|
+
private readonly storageService;
|
|
22
|
+
private readonly i18nStore;
|
|
23
|
+
private readonly localeStorageKey;
|
|
24
|
+
observerManager: ObserverManager<TSupportedLocales[number]>;
|
|
25
|
+
constructor(storageService: IStorageService<TSupportedLocales[number]>, i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, localeStorageKey?: string);
|
|
26
|
+
private initializeCurrentLocale;
|
|
27
|
+
getLocale: () => TSupportedLocales[number];
|
|
28
|
+
setLocale: (locale: TSupportedLocales[number]) => void;
|
|
29
|
+
}
|
|
5
30
|
|
|
6
31
|
type UseIntlParams<D = MessageDescriptor> = Parameters<IntlShape['$t']> extends [D, ...infer R] ? [...R, Omit<D, 'id'>] : never;
|
|
7
32
|
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>;
|
|
@@ -40,41 +65,25 @@ type IntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet e
|
|
|
40
65
|
children: React.ReactNode;
|
|
41
66
|
};
|
|
42
67
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
removeItem(key: string): boolean;
|
|
47
|
-
clear(): boolean;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* locale storage manager
|
|
51
|
-
* implements ILocaleStorageManager (injected StorageService)
|
|
52
|
-
*/
|
|
53
|
-
interface ILocaleStorageManager<TSupportedLocales extends readonly string[]> {
|
|
54
|
-
getLocale(): TSupportedLocales[number];
|
|
55
|
-
setLocale(locale: TSupportedLocales[number]): void;
|
|
56
|
-
}
|
|
57
|
-
declare class LocaleStorageManager<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> implements ILocaleStorageManager<TSupportedLocales> {
|
|
58
|
-
private readonly storageService;
|
|
59
|
-
private readonly i18nStore;
|
|
60
|
-
private readonly localeStorageKey;
|
|
61
|
-
observerManager: ObserverManager<TSupportedLocales[number]>;
|
|
62
|
-
constructor(storageService: IStorageService<TSupportedLocales[number]>, i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, localeStorageKey?: string);
|
|
63
|
-
private initializeCurrentLocale;
|
|
64
|
-
getLocale: () => TSupportedLocales[number];
|
|
65
|
-
setLocale: (locale: TSupportedLocales[number]) => void;
|
|
66
|
-
}
|
|
68
|
+
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>): {
|
|
69
|
+
locale: TSupportedLocales[number];
|
|
70
|
+
};
|
|
67
71
|
|
|
68
|
-
|
|
72
|
+
interface StorageBasedIntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> {
|
|
73
|
+
i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
74
|
+
storageManager: LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
75
|
+
children: React.ReactNode;
|
|
76
|
+
}
|
|
69
77
|
|
|
70
78
|
declare function createI18nContext<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false>(i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>): {
|
|
71
79
|
IntlProvider: ({ currentLocale, children, }: Omit<IntlProviderProps<TSupportedLocales, TLocaleSet>, "currentLocale" | "i18nStore"> & {
|
|
72
80
|
currentLocale?: string;
|
|
73
81
|
children?: React.ReactNode;
|
|
74
82
|
}) => react_jsx_runtime.JSX.Element;
|
|
83
|
+
StorageBasedIntlProvider: ({ storageManager, children, }: Omit<StorageBasedIntlProviderProps<TSupportedLocales, TLocaleSet, TTypeSafe>, "i18nStore">) => react_jsx_runtime.JSX.Element;
|
|
75
84
|
useTranslation: <TSheetTitle extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]] extends never ? string : keyof TLocaleSet[TSupportedLocales[number]] : string>(sheetTitle: TSheetTitle) => UseTranslationReturn<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle>;
|
|
76
85
|
getTranslation: <TSheetTitle extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]] extends never ? string : keyof TLocaleSet[TSupportedLocales[number]] : string>(sheetTitle: TSheetTitle) => GetTranslationReturn<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle>;
|
|
77
|
-
getLocaleStorageManager: (
|
|
86
|
+
getLocaleStorageManager: (storageService?: IStorageService<string>) => LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
78
87
|
useLocaleStorage: typeof useLocaleStorage;
|
|
79
88
|
};
|
|
80
89
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,32 @@
|
|
|
1
|
-
import { MessageDescriptor, IntlShape } from 'react-intl';
|
|
2
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
1
|
import { I18nStore } from '@sheet-i18n/react-core';
|
|
4
2
|
import { ObserverManager } from '@sheet-i18n/shared-utils';
|
|
3
|
+
import { MessageDescriptor, IntlShape } from 'react-intl';
|
|
4
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
interface IStorageService<V extends string> {
|
|
7
|
+
getItem(key: string): V;
|
|
8
|
+
setItem(key: string, value: V): boolean;
|
|
9
|
+
removeItem(key: string): boolean;
|
|
10
|
+
clear(): boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* locale storage manager
|
|
14
|
+
* implements ILocaleStorageManager (injected StorageService)
|
|
15
|
+
*/
|
|
16
|
+
interface ILocaleStorageManager<TSupportedLocales extends readonly string[]> {
|
|
17
|
+
getLocale(): TSupportedLocales[number];
|
|
18
|
+
setLocale(locale: TSupportedLocales[number]): void;
|
|
19
|
+
}
|
|
20
|
+
declare class LocaleStorageManager<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> implements ILocaleStorageManager<TSupportedLocales> {
|
|
21
|
+
private readonly storageService;
|
|
22
|
+
private readonly i18nStore;
|
|
23
|
+
private readonly localeStorageKey;
|
|
24
|
+
observerManager: ObserverManager<TSupportedLocales[number]>;
|
|
25
|
+
constructor(storageService: IStorageService<TSupportedLocales[number]>, i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, localeStorageKey?: string);
|
|
26
|
+
private initializeCurrentLocale;
|
|
27
|
+
getLocale: () => TSupportedLocales[number];
|
|
28
|
+
setLocale: (locale: TSupportedLocales[number]) => void;
|
|
29
|
+
}
|
|
5
30
|
|
|
6
31
|
type UseIntlParams<D = MessageDescriptor> = Parameters<IntlShape['$t']> extends [D, ...infer R] ? [...R, Omit<D, 'id'>] : never;
|
|
7
32
|
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>;
|
|
@@ -40,41 +65,25 @@ type IntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet e
|
|
|
40
65
|
children: React.ReactNode;
|
|
41
66
|
};
|
|
42
67
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
removeItem(key: string): boolean;
|
|
47
|
-
clear(): boolean;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* locale storage manager
|
|
51
|
-
* implements ILocaleStorageManager (injected StorageService)
|
|
52
|
-
*/
|
|
53
|
-
interface ILocaleStorageManager<TSupportedLocales extends readonly string[]> {
|
|
54
|
-
getLocale(): TSupportedLocales[number];
|
|
55
|
-
setLocale(locale: TSupportedLocales[number]): void;
|
|
56
|
-
}
|
|
57
|
-
declare class LocaleStorageManager<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> implements ILocaleStorageManager<TSupportedLocales> {
|
|
58
|
-
private readonly storageService;
|
|
59
|
-
private readonly i18nStore;
|
|
60
|
-
private readonly localeStorageKey;
|
|
61
|
-
observerManager: ObserverManager<TSupportedLocales[number]>;
|
|
62
|
-
constructor(storageService: IStorageService<TSupportedLocales[number]>, i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>, localeStorageKey?: string);
|
|
63
|
-
private initializeCurrentLocale;
|
|
64
|
-
getLocale: () => TSupportedLocales[number];
|
|
65
|
-
setLocale: (locale: TSupportedLocales[number]) => void;
|
|
66
|
-
}
|
|
68
|
+
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>): {
|
|
69
|
+
locale: TSupportedLocales[number];
|
|
70
|
+
};
|
|
67
71
|
|
|
68
|
-
|
|
72
|
+
interface StorageBasedIntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false> {
|
|
73
|
+
i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
74
|
+
storageManager: LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
75
|
+
children: React.ReactNode;
|
|
76
|
+
}
|
|
69
77
|
|
|
70
78
|
declare function createI18nContext<TSupportedLocales extends readonly string[], TLocaleSet extends Partial<Record<TSupportedLocales[number], Record<string, any>>>, TTypeSafe extends boolean = false>(i18nStore: I18nStore<TSupportedLocales, TLocaleSet, TTypeSafe>): {
|
|
71
79
|
IntlProvider: ({ currentLocale, children, }: Omit<IntlProviderProps<TSupportedLocales, TLocaleSet>, "currentLocale" | "i18nStore"> & {
|
|
72
80
|
currentLocale?: string;
|
|
73
81
|
children?: React.ReactNode;
|
|
74
82
|
}) => react_jsx_runtime.JSX.Element;
|
|
83
|
+
StorageBasedIntlProvider: ({ storageManager, children, }: Omit<StorageBasedIntlProviderProps<TSupportedLocales, TLocaleSet, TTypeSafe>, "i18nStore">) => react_jsx_runtime.JSX.Element;
|
|
75
84
|
useTranslation: <TSheetTitle extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]] extends never ? string : keyof TLocaleSet[TSupportedLocales[number]] : string>(sheetTitle: TSheetTitle) => UseTranslationReturn<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle>;
|
|
76
85
|
getTranslation: <TSheetTitle extends TTypeSafe extends true ? keyof TLocaleSet[TSupportedLocales[number]] extends never ? string : keyof TLocaleSet[TSupportedLocales[number]] : string>(sheetTitle: TSheetTitle) => GetTranslationReturn<TSupportedLocales, TLocaleSet, TTypeSafe, TSheetTitle>;
|
|
77
|
-
getLocaleStorageManager: (
|
|
86
|
+
getLocaleStorageManager: (storageService?: IStorageService<string>) => LocaleStorageManager<TSupportedLocales, TLocaleSet, TTypeSafe>;
|
|
78
87
|
useLocaleStorage: typeof useLocaleStorage;
|
|
79
88
|
};
|
|
80
89
|
|
package/dist/index.js
CHANGED
|
@@ -46,11 +46,11 @@ module.exports = __toCommonJS(src_exports);
|
|
|
46
46
|
var import_shared_utils5 = require("@sheet-i18n/shared-utils");
|
|
47
47
|
var import_react_core = require("@sheet-i18n/react-core");
|
|
48
48
|
|
|
49
|
-
// src/IntlProvider.tsx
|
|
49
|
+
// src/Provider/IntlProvider.tsx
|
|
50
50
|
var import_react_intl2 = require("react-intl");
|
|
51
51
|
var import_react2 = require("react");
|
|
52
52
|
|
|
53
|
-
// src/useDynamicLocale.ts
|
|
53
|
+
// src/hooks/useDynamicLocale.ts
|
|
54
54
|
var import_shared_utils2 = require("@sheet-i18n/shared-utils");
|
|
55
55
|
var import_react = require("react");
|
|
56
56
|
|
|
@@ -122,7 +122,7 @@ var IntlInstanceCache = class _IntlInstanceCache {
|
|
|
122
122
|
};
|
|
123
123
|
var intlInstanceCache = IntlInstanceCache.init();
|
|
124
124
|
|
|
125
|
-
// src/useDynamicLocale.ts
|
|
125
|
+
// src/hooks/useDynamicLocale.ts
|
|
126
126
|
function useDynamicLocale(useDynamicLocaleProps) {
|
|
127
127
|
const { i18nStore } = useDynamicLocaleProps != null ? useDynamicLocaleProps : {};
|
|
128
128
|
const currentLocale = i18nStore == null ? void 0 : i18nStore.getCurrentLocale();
|
|
@@ -154,7 +154,7 @@ ${err}`);
|
|
|
154
154
|
};
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
// src/IntlProvider.tsx
|
|
157
|
+
// src/Provider/IntlProvider.tsx
|
|
158
158
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
159
159
|
function IntlProvider({
|
|
160
160
|
i18nStore,
|
|
@@ -247,7 +247,7 @@ var TranslationService = class {
|
|
|
247
247
|
}
|
|
248
248
|
};
|
|
249
249
|
|
|
250
|
-
// src/useTranslation.ts
|
|
250
|
+
// src/hooks/useTranslation.ts
|
|
251
251
|
function useTranslation({
|
|
252
252
|
sheetTitle,
|
|
253
253
|
i18nStore
|
|
@@ -274,7 +274,7 @@ var InvalidI18nContextStateError = class extends import_errors.CustomError {
|
|
|
274
274
|
var IsNotInstanceOfI18nStoreError = class extends import_errors.CustomError {
|
|
275
275
|
};
|
|
276
276
|
|
|
277
|
-
// src/getTranslation.ts
|
|
277
|
+
// src/hooks/getTranslation.ts
|
|
278
278
|
function getTranslation({
|
|
279
279
|
sheetTitle,
|
|
280
280
|
i18nStore
|
|
@@ -318,9 +318,9 @@ function getTranslation({
|
|
|
318
318
|
return { t };
|
|
319
319
|
}
|
|
320
320
|
|
|
321
|
-
// src/Service/
|
|
321
|
+
// src/Service/StorageService.ts
|
|
322
322
|
var import_shared_utils4 = require("@sheet-i18n/shared-utils");
|
|
323
|
-
var
|
|
323
|
+
var StorageService = class {
|
|
324
324
|
constructor(storage) {
|
|
325
325
|
this.storage = null;
|
|
326
326
|
this.isClientSide = typeof window !== "undefined";
|
|
@@ -442,8 +442,16 @@ var LocaleStorageManager = class {
|
|
|
442
442
|
this.initializeCurrentLocale();
|
|
443
443
|
}
|
|
444
444
|
};
|
|
445
|
+
var getLocaleStorageManager = (i18nStore, storage) => {
|
|
446
|
+
const localeStorageService = new StorageService(storage);
|
|
447
|
+
const localeStorageManager = new LocaleStorageManager(
|
|
448
|
+
localeStorageService,
|
|
449
|
+
i18nStore
|
|
450
|
+
);
|
|
451
|
+
return localeStorageManager;
|
|
452
|
+
};
|
|
445
453
|
|
|
446
|
-
// src/useLocaleStorage.ts
|
|
454
|
+
// src/hooks/useLocaleStorage.ts
|
|
447
455
|
var import_react3 = require("react");
|
|
448
456
|
var LISTENER_ID = "LOCALE_STORAGE_LISTENER_ID";
|
|
449
457
|
function useLocaleStorage(localeStorageManager) {
|
|
@@ -462,11 +470,22 @@ function useLocaleStorage(localeStorageManager) {
|
|
|
462
470
|
(_a3 = localeStorageManager == null ? void 0 : localeStorageManager.observerManager) == null ? void 0 : _a3.removeListener(LISTENER_ID);
|
|
463
471
|
};
|
|
464
472
|
}, []);
|
|
465
|
-
return locale;
|
|
473
|
+
return { locale };
|
|
466
474
|
}
|
|
467
475
|
|
|
468
|
-
// src/
|
|
476
|
+
// src/Provider/StorageBasedIntlProvider.tsx
|
|
469
477
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
478
|
+
function StorageBasedIntlProvider({
|
|
479
|
+
i18nStore,
|
|
480
|
+
storageManager,
|
|
481
|
+
children
|
|
482
|
+
}) {
|
|
483
|
+
const { locale } = useLocaleStorage(storageManager);
|
|
484
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IntlProvider, { currentLocale: locale, i18nStore, children });
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// src/createI18nContext.tsx
|
|
488
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
470
489
|
function createI18nContext(i18nStore) {
|
|
471
490
|
if (import_shared_utils5.validator.isNullish(i18nStore)) {
|
|
472
491
|
throw new InvalidI18nContextStateError(
|
|
@@ -481,7 +500,7 @@ function createI18nContext(i18nStore) {
|
|
|
481
500
|
const IntlProviderImpl = ({
|
|
482
501
|
currentLocale,
|
|
483
502
|
children
|
|
484
|
-
}) => /* @__PURE__ */ (0,
|
|
503
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
485
504
|
IntlProvider,
|
|
486
505
|
{
|
|
487
506
|
currentLocale,
|
|
@@ -489,21 +508,28 @@ function createI18nContext(i18nStore) {
|
|
|
489
508
|
children
|
|
490
509
|
}
|
|
491
510
|
);
|
|
511
|
+
const StorageBasedIntlProviderImpl = ({
|
|
512
|
+
storageManager,
|
|
513
|
+
children
|
|
514
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
515
|
+
StorageBasedIntlProvider,
|
|
516
|
+
{
|
|
517
|
+
i18nStore,
|
|
518
|
+
storageManager,
|
|
519
|
+
children
|
|
520
|
+
}
|
|
521
|
+
);
|
|
492
522
|
const useTranslationImpl = (sheetTitle) => useTranslation({ sheetTitle, i18nStore });
|
|
493
523
|
const getTranslationImpl = (sheetTitle) => getTranslation({ sheetTitle, i18nStore });
|
|
494
|
-
const
|
|
495
|
-
|
|
496
|
-
const localeStorageManager = new LocaleStorageManager(
|
|
497
|
-
localStorageService,
|
|
498
|
-
i18nStore
|
|
499
|
-
);
|
|
500
|
-
return localeStorageManager;
|
|
524
|
+
const getLocaleStorageManagerImpl = (storageService) => {
|
|
525
|
+
return getLocaleStorageManager(i18nStore, storageService);
|
|
501
526
|
};
|
|
502
527
|
return {
|
|
503
528
|
IntlProvider: IntlProviderImpl,
|
|
529
|
+
StorageBasedIntlProvider: StorageBasedIntlProviderImpl,
|
|
504
530
|
useTranslation: useTranslationImpl,
|
|
505
531
|
getTranslation: getTranslationImpl,
|
|
506
|
-
getLocaleStorageManager,
|
|
532
|
+
getLocaleStorageManager: getLocaleStorageManagerImpl,
|
|
507
533
|
useLocaleStorage
|
|
508
534
|
};
|
|
509
535
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -23,11 +23,11 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
23
23
|
import { validator as validator4 } from "@sheet-i18n/shared-utils";
|
|
24
24
|
import { I18nStore } from "@sheet-i18n/react-core";
|
|
25
25
|
|
|
26
|
-
// src/IntlProvider.tsx
|
|
26
|
+
// src/Provider/IntlProvider.tsx
|
|
27
27
|
import { IntlProvider as ReactIntlProvider } from "react-intl";
|
|
28
28
|
import { useEffect } from "react";
|
|
29
29
|
|
|
30
|
-
// src/useDynamicLocale.ts
|
|
30
|
+
// src/hooks/useDynamicLocale.ts
|
|
31
31
|
import { validator as validator2 } from "@sheet-i18n/shared-utils";
|
|
32
32
|
import { useLayoutEffect, useState } from "react";
|
|
33
33
|
|
|
@@ -99,7 +99,7 @@ var IntlInstanceCache = class _IntlInstanceCache {
|
|
|
99
99
|
};
|
|
100
100
|
var intlInstanceCache = IntlInstanceCache.init();
|
|
101
101
|
|
|
102
|
-
// src/useDynamicLocale.ts
|
|
102
|
+
// src/hooks/useDynamicLocale.ts
|
|
103
103
|
function useDynamicLocale(useDynamicLocaleProps) {
|
|
104
104
|
const { i18nStore } = useDynamicLocaleProps != null ? useDynamicLocaleProps : {};
|
|
105
105
|
const currentLocale = i18nStore == null ? void 0 : i18nStore.getCurrentLocale();
|
|
@@ -131,7 +131,7 @@ ${err}`);
|
|
|
131
131
|
};
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
// src/IntlProvider.tsx
|
|
134
|
+
// src/Provider/IntlProvider.tsx
|
|
135
135
|
import { jsx } from "react/jsx-runtime";
|
|
136
136
|
function IntlProvider({
|
|
137
137
|
i18nStore,
|
|
@@ -224,7 +224,7 @@ var TranslationService = class {
|
|
|
224
224
|
}
|
|
225
225
|
};
|
|
226
226
|
|
|
227
|
-
// src/useTranslation.ts
|
|
227
|
+
// src/hooks/useTranslation.ts
|
|
228
228
|
function useTranslation({
|
|
229
229
|
sheetTitle,
|
|
230
230
|
i18nStore
|
|
@@ -251,7 +251,7 @@ var InvalidI18nContextStateError = class extends CustomError {
|
|
|
251
251
|
var IsNotInstanceOfI18nStoreError = class extends CustomError {
|
|
252
252
|
};
|
|
253
253
|
|
|
254
|
-
// src/getTranslation.ts
|
|
254
|
+
// src/hooks/getTranslation.ts
|
|
255
255
|
function getTranslation({
|
|
256
256
|
sheetTitle,
|
|
257
257
|
i18nStore
|
|
@@ -295,9 +295,9 @@ function getTranslation({
|
|
|
295
295
|
return { t };
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
-
// src/Service/
|
|
298
|
+
// src/Service/StorageService.ts
|
|
299
299
|
import { ObserverManager } from "@sheet-i18n/shared-utils";
|
|
300
|
-
var
|
|
300
|
+
var StorageService = class {
|
|
301
301
|
constructor(storage) {
|
|
302
302
|
this.storage = null;
|
|
303
303
|
this.isClientSide = typeof window !== "undefined";
|
|
@@ -419,8 +419,16 @@ var LocaleStorageManager = class {
|
|
|
419
419
|
this.initializeCurrentLocale();
|
|
420
420
|
}
|
|
421
421
|
};
|
|
422
|
+
var getLocaleStorageManager = (i18nStore, storage) => {
|
|
423
|
+
const localeStorageService = new StorageService(storage);
|
|
424
|
+
const localeStorageManager = new LocaleStorageManager(
|
|
425
|
+
localeStorageService,
|
|
426
|
+
i18nStore
|
|
427
|
+
);
|
|
428
|
+
return localeStorageManager;
|
|
429
|
+
};
|
|
422
430
|
|
|
423
|
-
// src/useLocaleStorage.ts
|
|
431
|
+
// src/hooks/useLocaleStorage.ts
|
|
424
432
|
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
425
433
|
var LISTENER_ID = "LOCALE_STORAGE_LISTENER_ID";
|
|
426
434
|
function useLocaleStorage(localeStorageManager) {
|
|
@@ -439,11 +447,22 @@ function useLocaleStorage(localeStorageManager) {
|
|
|
439
447
|
(_a3 = localeStorageManager == null ? void 0 : localeStorageManager.observerManager) == null ? void 0 : _a3.removeListener(LISTENER_ID);
|
|
440
448
|
};
|
|
441
449
|
}, []);
|
|
442
|
-
return locale;
|
|
450
|
+
return { locale };
|
|
443
451
|
}
|
|
444
452
|
|
|
445
|
-
// src/
|
|
453
|
+
// src/Provider/StorageBasedIntlProvider.tsx
|
|
446
454
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
455
|
+
function StorageBasedIntlProvider({
|
|
456
|
+
i18nStore,
|
|
457
|
+
storageManager,
|
|
458
|
+
children
|
|
459
|
+
}) {
|
|
460
|
+
const { locale } = useLocaleStorage(storageManager);
|
|
461
|
+
return /* @__PURE__ */ jsx2(IntlProvider, { currentLocale: locale, i18nStore, children });
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// src/createI18nContext.tsx
|
|
465
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
447
466
|
function createI18nContext(i18nStore) {
|
|
448
467
|
if (validator4.isNullish(i18nStore)) {
|
|
449
468
|
throw new InvalidI18nContextStateError(
|
|
@@ -458,7 +477,7 @@ function createI18nContext(i18nStore) {
|
|
|
458
477
|
const IntlProviderImpl = ({
|
|
459
478
|
currentLocale,
|
|
460
479
|
children
|
|
461
|
-
}) => /* @__PURE__ */
|
|
480
|
+
}) => /* @__PURE__ */ jsx3(
|
|
462
481
|
IntlProvider,
|
|
463
482
|
{
|
|
464
483
|
currentLocale,
|
|
@@ -466,21 +485,28 @@ function createI18nContext(i18nStore) {
|
|
|
466
485
|
children
|
|
467
486
|
}
|
|
468
487
|
);
|
|
488
|
+
const StorageBasedIntlProviderImpl = ({
|
|
489
|
+
storageManager,
|
|
490
|
+
children
|
|
491
|
+
}) => /* @__PURE__ */ jsx3(
|
|
492
|
+
StorageBasedIntlProvider,
|
|
493
|
+
{
|
|
494
|
+
i18nStore,
|
|
495
|
+
storageManager,
|
|
496
|
+
children
|
|
497
|
+
}
|
|
498
|
+
);
|
|
469
499
|
const useTranslationImpl = (sheetTitle) => useTranslation({ sheetTitle, i18nStore });
|
|
470
500
|
const getTranslationImpl = (sheetTitle) => getTranslation({ sheetTitle, i18nStore });
|
|
471
|
-
const
|
|
472
|
-
|
|
473
|
-
const localeStorageManager = new LocaleStorageManager(
|
|
474
|
-
localStorageService,
|
|
475
|
-
i18nStore
|
|
476
|
-
);
|
|
477
|
-
return localeStorageManager;
|
|
501
|
+
const getLocaleStorageManagerImpl = (storageService) => {
|
|
502
|
+
return getLocaleStorageManager(i18nStore, storageService);
|
|
478
503
|
};
|
|
479
504
|
return {
|
|
480
505
|
IntlProvider: IntlProviderImpl,
|
|
506
|
+
StorageBasedIntlProvider: StorageBasedIntlProviderImpl,
|
|
481
507
|
useTranslation: useTranslationImpl,
|
|
482
508
|
getTranslation: getTranslationImpl,
|
|
483
|
-
getLocaleStorageManager,
|
|
509
|
+
getLocaleStorageManager: getLocaleStorageManagerImpl,
|
|
484
510
|
useLocaleStorage
|
|
485
511
|
};
|
|
486
512
|
}
|