@npm-questionpro/wick-ui-lib 2.3.0 → 2.5.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.
@@ -13,26 +13,23 @@ interface IWuTranslateContextProps {
13
13
  locale: string;
14
14
  setLocale: (locale: string) => void;
15
15
  isLoading: boolean;
16
+ /** `true` only while an `addExtraKeys` delta POST is in flight. Use to gate a section without blanking the whole page. */
17
+ deltaLoading: boolean;
16
18
  isRtl: boolean;
17
19
  characterSet: string;
18
- /** Reactive alternative to `wt()`. Use inside components to avoid stale values on reload. */
19
- translate: (key: string) => string;
20
+ /** Register runtime/BE-driven strings for translation. Accumulated for the session; sets `deltaLoading` while fetching. */
21
+ addExtraKeys: (keys: string[]) => void;
20
22
  }
21
23
  export declare const useTranslate: () => IWuTranslateContextProps;
22
- /**
23
- * Reactive translate hook for use inside components.
24
- * Re-renders the component when the dictionary updates.
25
- *
26
- * @example
27
- * const t = useWt()
28
- * return <button>{t('Submit')}</button>
29
- */
24
+ /** Reactive translate hook. Re-renders on dictionary updates. */
30
25
  export declare const useWt: () => ((key: string) => string);
31
26
  export interface IWuTranslateProviderProps {
32
27
  children: React.ReactNode;
33
28
  defaultLocale?: string;
34
29
  baseApi?: string;
35
30
  keys?: string;
31
+ /** localStorage cache TTL for fetched dictionaries, in ms. Defaults to 1 hour. */
32
+ cacheTtlMs?: number;
36
33
  }
37
34
  export declare const WuTranslateProvider: React.FC<IWuTranslateProviderProps>;
38
35
  export {};
@@ -0,0 +1,15 @@
1
+ /** localStorage cache for translated dictionaries. TTL-based, keyed by keysUrl+locale. */
2
+ export declare const DEFAULT_WT_CACHE_TTL_MS: number;
3
+ export interface IWtCacheEntry {
4
+ data: Record<string, string>;
5
+ isRtl: boolean;
6
+ characterSet: string;
7
+ ts: number;
8
+ }
9
+ /** Returns cached entry if present and not expired, else null. Never throws (storage may be disabled/full). */
10
+ export declare function getWtCache(keysUrl: string, locale: string, ttlMs?: number): IWtCacheEntry | null;
11
+ /** Full write — call only on a successful base fetch. Refreshes `ts`, restarting the 1hr window. */
12
+ export declare function setWtCache(keysUrl: string, locale: string, data: Record<string, string>, isRtl: boolean, characterSet: string): void;
13
+ /** Merges extra translated keys into an existing cache entry without touching `ts`. Call only on a
14
+ * successful delta fetch. No-op if no entry exists yet (base fetch hasn't cached anything to patch). */
15
+ export declare function patchWtCacheData(keysUrl: string, locale: string, extra: Record<string, string>): void;