@saykit/react 0.0.0-beta-20260726152813 → 0.0.0-beta-20260728002240
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/client.d.mts +6 -8
- package/dist/client.mjs +9 -5
- package/dist/index.d.mts +1 -2
- package/dist/server.d.mts +2 -2
- package/package.json +7 -5
package/dist/client.d.mts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import * as _$react from "react";
|
|
2
1
|
import { PropsWithChildren } from "react";
|
|
3
2
|
import { ReadonlySay, Say } from "saykit";
|
|
4
|
-
|
|
5
3
|
//#region src/runtime/client.d.ts
|
|
6
4
|
type SayRef = {
|
|
7
5
|
current: ReadonlySay | null;
|
|
@@ -10,17 +8,17 @@ type SayRef = {
|
|
|
10
8
|
* Provide a localised {@link runtime.Say} instance to descendant **client** components via context.
|
|
11
9
|
* Must wrap any component tree using {@link useSay} or {@link Say}.
|
|
12
10
|
*
|
|
11
|
+
* The instance is rebuilt whenever `locale` or `messages` changes, so keep `messages`
|
|
12
|
+
* referentially stable (module scope, or memoised) rather than passing a fresh object
|
|
13
|
+
* literal on every render.
|
|
14
|
+
*
|
|
13
15
|
* @param props.locale The current locale
|
|
14
16
|
* @param props.messages The current messages for the locale
|
|
15
17
|
*/
|
|
16
|
-
declare function SayProvider({
|
|
17
|
-
locale,
|
|
18
|
-
messages,
|
|
19
|
-
children
|
|
20
|
-
}: PropsWithChildren<{
|
|
18
|
+
declare function SayProvider({ locale, messages, children }: PropsWithChildren<{
|
|
21
19
|
locale: string;
|
|
22
20
|
messages: Say.Messages;
|
|
23
|
-
}>):
|
|
21
|
+
}>): import("react").FunctionComponentElement<import("react").ProviderProps<SayRef>>;
|
|
24
22
|
/**
|
|
25
23
|
* Get the current {@link Say} **client** instance.
|
|
26
24
|
* Must be called within a {@link SayProvider}.
|
package/dist/client.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { createContext, createElement, useContext,
|
|
2
|
+
import { createContext, createElement, useContext, useMemo } from "react";
|
|
3
3
|
import { Say } from "saykit";
|
|
4
4
|
//#region src/runtime/client.ts
|
|
5
5
|
const SayContext = createContext({ current: null });
|
|
@@ -8,20 +8,24 @@ SayContext.displayName = "SayContext";
|
|
|
8
8
|
* Provide a localised {@link runtime.Say} instance to descendant **client** components via context.
|
|
9
9
|
* Must wrap any component tree using {@link useSay} or {@link Say}.
|
|
10
10
|
*
|
|
11
|
+
* The instance is rebuilt whenever `locale` or `messages` changes, so keep `messages`
|
|
12
|
+
* referentially stable (module scope, or memoised) rather than passing a fresh object
|
|
13
|
+
* literal on every render.
|
|
14
|
+
*
|
|
11
15
|
* @param props.locale The current locale
|
|
12
16
|
* @param props.messages The current messages for the locale
|
|
13
17
|
*/
|
|
14
18
|
function SayProvider({ locale, messages, children }) {
|
|
15
|
-
const
|
|
19
|
+
const ref = useMemo(() => {
|
|
16
20
|
const instance = new Say({
|
|
17
21
|
locales: [locale],
|
|
18
22
|
loader: () => messages
|
|
19
23
|
});
|
|
20
24
|
instance.load(locale);
|
|
21
25
|
instance.activate(locale);
|
|
22
|
-
return instance.freeze();
|
|
23
|
-
});
|
|
24
|
-
return createElement(SayContext.Provider, { value:
|
|
26
|
+
return { current: instance.freeze() };
|
|
27
|
+
}, [locale, messages]);
|
|
28
|
+
return createElement(SayContext.Provider, { value: ref }, children);
|
|
25
29
|
}
|
|
26
30
|
/**
|
|
27
31
|
* Get the current {@link Say} **client** instance.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { PropsWithChildren, ReactElement, ReactNode } from "react";
|
|
2
2
|
import { Disallow, NumeralOptions, SelectOptions } from "saykit";
|
|
3
|
-
|
|
4
3
|
//#region src/types.d.ts
|
|
5
|
-
type PropsWithJSXSafeKeys<T> = { [K in keyof T as K extends number | `${number}${string}` ? `_${K}` : K extends `_${number}${string}` ? never : K]: T[K] };
|
|
4
|
+
type PropsWithJSXSafeKeys<T> = { [K in keyof T as K extends number | `${number}${string}` ? `_${K}` : K extends `_${number}${string}` ? never : K]: T[K]; };
|
|
6
5
|
//#endregion
|
|
7
6
|
//#region src/runtime/index.d.ts
|
|
8
7
|
/**
|
package/dist/server.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as _$react from "react";
|
|
2
1
|
import { ReactNode } from "react";
|
|
3
2
|
import { ReadonlySay, Say } from "saykit";
|
|
3
|
+
import "server-only";
|
|
4
4
|
//#region src/runtime/server.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Set the current {@link Say} **server** instance.
|
|
@@ -24,7 +24,7 @@ declare function getSay(): ReadonlySay;
|
|
|
24
24
|
*
|
|
25
25
|
* @returns A {@link withSay} higher-order component factory
|
|
26
26
|
*/
|
|
27
|
-
declare function unstable_createWithSay(say: Say): <P = unknown>(Component: (props: PropsWithSay<P>) => ReactNode, getLocale: (props: P) => string | Promise<string>) => (props: P) => Promise<
|
|
27
|
+
declare function unstable_createWithSay(say: Say): <P = unknown>(Component: (props: PropsWithSay<P>) => ReactNode, getLocale: (props: P) => string | Promise<string>) => (props: P) => Promise<import("react").FunctionComponentElement<PropsWithSay<P>>>;
|
|
28
28
|
type PropsWithSay<P = unknown> = P & {
|
|
29
29
|
locale: string;
|
|
30
30
|
messages: Say.Messages;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saykit/react",
|
|
3
|
-
"version": "0.0.0-beta-
|
|
3
|
+
"version": "0.0.0-beta-20260728002240",
|
|
4
4
|
"description": "React integration for saykit, i18n hooks and components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -46,15 +46,17 @@
|
|
|
46
46
|
"server-only": "^0.0.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
+
"@testing-library/react": "^16.3.2",
|
|
49
50
|
"@types/react": "^19.2.17",
|
|
50
51
|
"@types/react-dom": "^19.2.3",
|
|
51
|
-
"
|
|
52
|
-
"react
|
|
53
|
-
"
|
|
52
|
+
"jsdom": "^29.1.1",
|
|
53
|
+
"react": "^19.2.8",
|
|
54
|
+
"react-dom": "^19.2.8",
|
|
55
|
+
"saykit": "^0.0.0-beta-20260728002240"
|
|
54
56
|
},
|
|
55
57
|
"peerDependencies": {
|
|
56
58
|
"react": "*",
|
|
57
|
-
"saykit": "0.0.0-beta-
|
|
59
|
+
"saykit": "0.0.0-beta-20260728002240"
|
|
58
60
|
},
|
|
59
61
|
"scripts": {
|
|
60
62
|
"check": "tsc --noEmit",
|