@saykit/react 0.8.0 → 0.9.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/dist/client.mjs CHANGED
@@ -4,17 +4,6 @@ import { Say } from "saykit";
4
4
  //#region src/runtime/client.ts
5
5
  const SayContext = createContext({ current: null });
6
6
  SayContext.displayName = "SayContext";
7
- /**
8
- * Provide a localised {@link runtime.Say} instance to descendant **client** components via context.
9
- * Must wrap any component tree using {@link useSay} or {@link Say}.
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
- *
15
- * @param props.locale The current locale
16
- * @param props.messages The current messages for the locale
17
- */
18
7
  function SayProvider({ locale, messages, children }) {
19
8
  const ref = useMemo(() => {
20
9
  const instance = new Say({
@@ -27,13 +16,6 @@ function SayProvider({ locale, messages, children }) {
27
16
  }, [locale, messages]);
28
17
  return createElement(SayContext.Provider, { value: ref }, children);
29
18
  }
30
- /**
31
- * Get the current {@link Say} **client** instance.
32
- * Must be called within a {@link SayProvider}.
33
- *
34
- * @returns The current {@link Say} instance
35
- * @throws If no provider is in the component tree
36
- */
37
19
  function useSay() {
38
20
  const ref = useContext(SayContext);
39
21
  if (!ref.current) throw new Error("'useSay' must be used within a 'SayProvider'");
package/dist/index.d.mts CHANGED
@@ -100,10 +100,12 @@ declare namespace Say {
100
100
  * ```tsx
101
101
  * <Say>You have <Say.Number _={items.length} /> items</Say>
102
102
  * <Say>Battery at <Say.Number _={level} style="percent" /></Say>
103
+ * <Say>Total <Say.Number _={total} style="::currency/EUR" /></Say>
103
104
  * ```
104
105
  *
105
106
  * @param props._ Number to format
106
- * @param props.style Formatting style, either a named style or a literal number pattern
107
+ * @param props.style Formatting style: a named style, an ICU skeleton such as
108
+ * `::currency/EUR`, or a literal number pattern such as `#,##0.00`
107
109
  * @returns The formatted number, as a React node
108
110
  * @remark This is a macro and must be used with the relevant saykit plugin
109
111
  */
@@ -116,10 +118,12 @@ declare namespace Say {
116
118
  * @example
117
119
  * ```tsx
118
120
  * <Say>Published <Say.Date _={post.publishedAt} style="medium" /></Say>
121
+ * <Say>Published <Say.Date _={post.publishedAt} style="::yMMMM" /></Say>
119
122
  * ```
120
123
  *
121
124
  * @param props._ Date to format
122
- * @param props.style Formatting style
125
+ * @param props.style Formatting style, either a named style or an ICU
126
+ * skeleton such as `::yyyyMMdd`
123
127
  * @returns The formatted date, as a React node
124
128
  * @remark This is a macro and must be used with the relevant saykit plugin
125
129
  */
@@ -132,10 +136,12 @@ declare namespace Say {
132
136
  * @example
133
137
  * ```tsx
134
138
  * <Say>Doors open at <Say.Time _={opensAt} style="short" /></Say>
139
+ * <Say>Doors open at <Say.Time _={opensAt} style="::Hm" /></Say>
135
140
  * ```
136
141
  *
137
142
  * @param props._ Date to format
138
- * @param props.style Formatting style
143
+ * @param props.style Formatting style, either a named style or an ICU
144
+ * skeleton such as `::Hm`
139
145
  * @returns The formatted time, as a React node
140
146
  * @remark This is a macro and must be used with the relevant saykit plugin
141
147
  */
package/dist/index.mjs CHANGED
@@ -47,17 +47,6 @@ function Renderer({ html, components, whitespace = true }) {
47
47
  }
48
48
  //#endregion
49
49
  //#region src/types.ts
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
50
  function resolveValuePropKeys(props) {
62
51
  const result = {};
63
52
  for (const key in props) if (key.startsWith("_")) result[key.slice(1)] = props[key];
@@ -47,17 +47,6 @@ function Renderer({ html, components, whitespace = true }) {
47
47
  }
48
48
  //#endregion
49
49
  //#region src/types.ts
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
50
  function resolveValuePropKeys(props) {
62
51
  const result = {};
63
52
  for (const key in props) if (key.startsWith("_")) result[key.slice(1)] = props[key];
package/dist/server.mjs CHANGED
@@ -3,40 +3,17 @@ import { Say } from "saykit";
3
3
  import "server-only";
4
4
  //#region src/runtime/server.ts
5
5
  const serverContext = cache(() => ({ current: null }));
6
- /**
7
- * Set the current {@link Say} **server** instance.
8
- * Must be called before any {@link getSay} calls.
9
- *
10
- * @param say The current {@link Say} instance
11
- */
12
6
  function setSay(say) {
13
7
  const ref = serverContext();
14
8
  if (say instanceof Say) ref.current = say.clone().freeze();
15
9
  else ref.current = say().clone().freeze();
16
10
  }
17
- /**
18
- * Get the current {@link Say} **server** instance.
19
- * Must only be called after any {@link setSay} calls.
20
- *
21
- * @returns The current {@link Say} instance
22
- * @throws If no {@link Say} instance has been set
23
- */
24
11
  function getSay() {
25
12
  const ref = serverContext();
26
13
  if (!ref.current) throw new Error("Attempt to access the server-only Say instance before initialisation", { cause: /* @__PURE__ */ new Error("'getSay' must be called after 'setSay'") });
27
14
  return ref.current;
28
15
  }
29
- /**
30
- * Create a {@link withSay} higher-order component factory bound to a specific {@link Say} instance.
31
- *
32
- * @param say The {@link Say} instance to bind into the server context
33
- *
34
- * @returns A {@link withSay} higher-order component factory
35
- */
36
16
  function unstable_createWithSay(say) {
37
- /**
38
- * Wrap a server component so that a {@link Say} instance is initialised before render.
39
- */
40
17
  return function withSay(Component, getLocale) {
41
18
  return async function WithSay(props) {
42
19
  const guess = await getLocale(props);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saykit/react",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "React integration for saykit, i18n hooks and components",
5
5
  "keywords": [
6
6
  "i18n",
@@ -52,7 +52,7 @@
52
52
  "jsdom": "^29.1.1",
53
53
  "react": "^19.2.8",
54
54
  "react-dom": "^19.2.8",
55
- "saykit": "^0.8.0"
55
+ "saykit": "^0.9.0"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "react": "*",