@saykit/react 0.0.0-beta-20260728002240 → 0.0.0-beta-20260729112211
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.mjs +21 -7
- package/dist/index.server.mjs +21 -7
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -47,9 +47,20 @@ function Renderer({ html, components, whitespace = true }) {
|
|
|
47
47
|
}
|
|
48
48
|
//#endregion
|
|
49
49
|
//#region src/types.ts
|
|
50
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Map the props the transform compiled a message's values into back to the
|
|
52
|
+
* identifiers they carry. Every value is emitted with one underscore in front,
|
|
53
|
+
* which is what keeps a numbered identifier a valid prop name and what keeps
|
|
54
|
+
* any name a message chooses out of `Say`'s own namespace, so stripping exactly
|
|
55
|
+
* one is the whole inverse — `_0` is `0`, and `__link` is a tag named `_link`.
|
|
56
|
+
*
|
|
57
|
+
* The result is deliberately not typed as the props that went in: renaming the
|
|
58
|
+
* keys is the point, so claiming they survived would be a lie the only caller
|
|
59
|
+
* cannot use anyway, it looks tags up by a name that comes from a translation.
|
|
60
|
+
*/
|
|
61
|
+
function resolveValuePropKeys(props) {
|
|
51
62
|
const result = {};
|
|
52
|
-
for (const key in props) if (
|
|
63
|
+
for (const key in props) if (key.startsWith("_")) result[key.slice(1)] = props[key];
|
|
53
64
|
else result[key] = props[key];
|
|
54
65
|
return result;
|
|
55
66
|
}
|
|
@@ -58,14 +69,17 @@ function resolveJsxSafePropKeys(props) {
|
|
|
58
69
|
function Say(props) {
|
|
59
70
|
if (!("id" in props)) throw new Error("'Say' is a macro and must be used with the relevant saykit plugin", { cause: /* @__PURE__ */ new Error("The 'id' property is required for a descriptor") });
|
|
60
71
|
const say = GET_SAY();
|
|
61
|
-
const { whitespace, ...rest } = props;
|
|
62
|
-
const
|
|
72
|
+
const { id, whitespace, ...rest } = props;
|
|
73
|
+
const values = resolveValuePropKeys(rest);
|
|
63
74
|
return createElement(Renderer, {
|
|
64
|
-
html: say.call(
|
|
75
|
+
html: say.call({
|
|
76
|
+
...values,
|
|
77
|
+
id
|
|
78
|
+
}),
|
|
65
79
|
whitespace,
|
|
66
80
|
components(tag) {
|
|
67
|
-
if (tag && tag in
|
|
68
|
-
const element =
|
|
81
|
+
if (tag && tag in values && isValidElement(values[tag])) {
|
|
82
|
+
const element = values[tag];
|
|
69
83
|
return (props) => cloneElement(element, {
|
|
70
84
|
...element.props,
|
|
71
85
|
...props
|
package/dist/index.server.mjs
CHANGED
|
@@ -47,9 +47,20 @@ function Renderer({ html, components, whitespace = true }) {
|
|
|
47
47
|
}
|
|
48
48
|
//#endregion
|
|
49
49
|
//#region src/types.ts
|
|
50
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Map the props the transform compiled a message's values into back to the
|
|
52
|
+
* identifiers they carry. Every value is emitted with one underscore in front,
|
|
53
|
+
* which is what keeps a numbered identifier a valid prop name and what keeps
|
|
54
|
+
* any name a message chooses out of `Say`'s own namespace, so stripping exactly
|
|
55
|
+
* one is the whole inverse — `_0` is `0`, and `__link` is a tag named `_link`.
|
|
56
|
+
*
|
|
57
|
+
* The result is deliberately not typed as the props that went in: renaming the
|
|
58
|
+
* keys is the point, so claiming they survived would be a lie the only caller
|
|
59
|
+
* cannot use anyway, it looks tags up by a name that comes from a translation.
|
|
60
|
+
*/
|
|
61
|
+
function resolveValuePropKeys(props) {
|
|
51
62
|
const result = {};
|
|
52
|
-
for (const key in props) if (
|
|
63
|
+
for (const key in props) if (key.startsWith("_")) result[key.slice(1)] = props[key];
|
|
53
64
|
else result[key] = props[key];
|
|
54
65
|
return result;
|
|
55
66
|
}
|
|
@@ -58,14 +69,17 @@ function resolveJsxSafePropKeys(props) {
|
|
|
58
69
|
function Say(props) {
|
|
59
70
|
if (!("id" in props)) throw new Error("'Say' is a macro and must be used with the relevant saykit plugin", { cause: /* @__PURE__ */ new Error("The 'id' property is required for a descriptor") });
|
|
60
71
|
const say = GET_SAY();
|
|
61
|
-
const { whitespace, ...rest } = props;
|
|
62
|
-
const
|
|
72
|
+
const { id, whitespace, ...rest } = props;
|
|
73
|
+
const values = resolveValuePropKeys(rest);
|
|
63
74
|
return createElement(Renderer, {
|
|
64
|
-
html: say.call(
|
|
75
|
+
html: say.call({
|
|
76
|
+
...values,
|
|
77
|
+
id
|
|
78
|
+
}),
|
|
65
79
|
whitespace,
|
|
66
80
|
components(tag) {
|
|
67
|
-
if (tag && tag in
|
|
68
|
-
const element =
|
|
81
|
+
if (tag && tag in values && isValidElement(values[tag])) {
|
|
82
|
+
const element = values[tag];
|
|
69
83
|
return (props) => cloneElement(element, {
|
|
70
84
|
...element.props,
|
|
71
85
|
...props
|
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-20260729112211",
|
|
4
4
|
"description": "React integration for saykit, i18n hooks and components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -52,11 +52,11 @@
|
|
|
52
52
|
"jsdom": "^29.1.1",
|
|
53
53
|
"react": "^19.2.8",
|
|
54
54
|
"react-dom": "^19.2.8",
|
|
55
|
-
"saykit": "^0.0.0-beta-
|
|
55
|
+
"saykit": "^0.0.0-beta-20260729112211"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"react": "*",
|
|
59
|
-
"saykit": "0.0.0-beta-
|
|
59
|
+
"saykit": "0.0.0-beta-20260729112211"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"check": "tsc --noEmit",
|