@saykit/react 0.1.0 → 0.2.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.
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  > React integration for [SayKit](https://saykit.js.org).
4
4
 
5
+ [![Coverage](https://codecov.io/gh/k0d13/saykit/graph/badge.svg?flag=integration-react)](https://codecov.io/gh/k0d13/saykit?flags%5B0%5D=integration-react)
6
+
5
7
  A `<Say>` component for rendering translated content in server and client components, a `<SayProvider>` and `useSay()` for client trees, and a small server runtime (`setSay`, `getSay`, `unstable_createWithSay`).
6
8
 
7
9
  ## Install
@@ -1,8 +1,10 @@
1
1
  "use client"; import { useSay as GET_SAY } from "./client.mjs";import { Fragment, cloneElement, createElement, isValidElement } from "react";
2
2
  //#region src/components/renderer.ts
3
- function Renderer({ html, components }) {
3
+ function Renderer({ html, components, whitespace = true }) {
4
4
  function getComponent(tag) {
5
- if (typeof components === "function") return components(tag) ?? tag ?? Fragment;
5
+ if (typeof components === "function")
6
+ /* v8 ignore next */
7
+ return components(tag) ?? tag ?? Fragment;
6
8
  return tag && tag in components ? components[tag] : Fragment;
7
9
  }
8
10
  let nodeKey = 0;
@@ -36,7 +38,7 @@ function Renderer({ html, components }) {
36
38
  let textEnd = input.indexOf("<", i);
37
39
  if (textEnd === -1) textEnd = input.length;
38
40
  const text = input.slice(i, textEnd);
39
- current.push(text);
41
+ if (whitespace || text.trim() !== "") current.push(text);
40
42
  i = textEnd;
41
43
  }
42
44
  return current;
@@ -56,9 +58,11 @@ function resolveJsxSafePropKeys(props) {
56
58
  function Say(props) {
57
59
  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") });
58
60
  const say = GET_SAY();
59
- const descriptor = resolveJsxSafePropKeys(props);
61
+ const { whitespace, ...rest } = props;
62
+ const descriptor = resolveJsxSafePropKeys(rest);
60
63
  return createElement(Renderer, {
61
64
  html: say.call(descriptor),
65
+ whitespace,
62
66
  components(tag) {
63
67
  if (tag && tag in descriptor && isValidElement(descriptor[tag])) {
64
68
  const element = descriptor[tag];
package/dist/index.d.mts CHANGED
@@ -14,6 +14,7 @@ type PropsWithJSXSafeKeys<T> = { [K in keyof T as K extends number | `${number}$
14
14
  */
15
15
  declare function Say(props: PropsWithChildren<Disallow<{
16
16
  context?: string;
17
+ whitespace?: boolean;
17
18
  }, 'id'>>): ReactElement;
18
19
  declare namespace Say {
19
20
  /**
@@ -1,8 +1,10 @@
1
1
  import { getSay as GET_SAY } from "./server.mjs";import { Fragment, cloneElement, createElement, isValidElement } from "react";
2
2
  //#region src/components/renderer.ts
3
- function Renderer({ html, components }) {
3
+ function Renderer({ html, components, whitespace = true }) {
4
4
  function getComponent(tag) {
5
- if (typeof components === "function") return components(tag) ?? tag ?? Fragment;
5
+ if (typeof components === "function")
6
+ /* v8 ignore next */
7
+ return components(tag) ?? tag ?? Fragment;
6
8
  return tag && tag in components ? components[tag] : Fragment;
7
9
  }
8
10
  let nodeKey = 0;
@@ -36,7 +38,7 @@ function Renderer({ html, components }) {
36
38
  let textEnd = input.indexOf("<", i);
37
39
  if (textEnd === -1) textEnd = input.length;
38
40
  const text = input.slice(i, textEnd);
39
- current.push(text);
41
+ if (whitespace || text.trim() !== "") current.push(text);
40
42
  i = textEnd;
41
43
  }
42
44
  return current;
@@ -56,9 +58,11 @@ function resolveJsxSafePropKeys(props) {
56
58
  function Say(props) {
57
59
  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") });
58
60
  const say = GET_SAY();
59
- const descriptor = resolveJsxSafePropKeys(props);
61
+ const { whitespace, ...rest } = props;
62
+ const descriptor = resolveJsxSafePropKeys(rest);
60
63
  return createElement(Renderer, {
61
64
  html: say.call(descriptor),
65
+ whitespace,
62
66
  components(tag) {
63
67
  if (tag && tag in descriptor && isValidElement(descriptor[tag])) {
64
68
  const element = descriptor[tag];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saykit/react",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "React integration for saykit, i18n hooks and components",
5
5
  "keywords": [
6
6
  "i18n",
@@ -46,9 +46,11 @@
46
46
  "server-only": "^0.0.1"
47
47
  },
48
48
  "devDependencies": {
49
- "@types/react": "^19.2.14",
50
- "react": "^19.2.6",
51
- "saykit": "^0.1.0"
49
+ "@types/react": "^19.2.17",
50
+ "@types/react-dom": "^19.2.3",
51
+ "react": "^19.2.7",
52
+ "react-dom": "^19.2.7",
53
+ "saykit": "^0.2.0"
52
54
  },
53
55
  "peerDependencies": {
54
56
  "react": "*",