@sheet-i18n/react-client 0.1.1-canary.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 ADDED
@@ -0,0 +1,3 @@
1
+ # React
2
+
3
+ This is the `react` utility package.
@@ -0,0 +1,33 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { I18nStore } from '@sheet-i18n/react-core';
3
+ import * as react from 'react';
4
+ import { MessageDescriptor, IntlShape } from 'react-intl';
5
+
6
+ type IntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet extends Record<TSupportedLocales[number], Record<string, any>>> = {
7
+ i18nStore: I18nStore<TSupportedLocales, TLocaleSet>;
8
+ currentLocale: TSupportedLocales[number];
9
+ children: React.ReactNode;
10
+ };
11
+ declare function IntlProvider<TSupportedLocales extends readonly string[], TLocaleSet extends Record<TSupportedLocales[number], Record<string, any>>>({ i18nStore, currentLocale, children, }: IntlProviderProps<TSupportedLocales, TLocaleSet>): react_jsx_runtime.JSX.Element;
12
+
13
+ type UseIntlParams<D = MessageDescriptor> = Parameters<IntlShape['$t']> extends [D, ...infer R] ? [...R, Omit<D, 'id'>] : never;
14
+ type $TParams = Partial<UseIntlParams>;
15
+ interface UseTranslationParams<TSupportedLocales extends readonly string[], TLocaleSet extends Record<TSupportedLocales[number], Record<string, any>>, TSheetTitle = keyof TLocaleSet[TSupportedLocales[number]]> {
16
+ sheetTitle: TSheetTitle;
17
+ i18nStore: I18nStore<TSupportedLocales, TLocaleSet>;
18
+ }
19
+ declare function useTranslation<TSupportedLocales extends readonly string[], TLocaleSet extends Record<TSupportedLocales[number], Record<string, any>>, TSheetTitle extends keyof TLocaleSet[TSupportedLocales[number]], TMessageId extends keyof TLocaleSet[TSupportedLocales[number]][TSheetTitle]>({ sheetTitle, }: UseTranslationParams<TSupportedLocales, TLocaleSet, TSheetTitle>): {
20
+ t: <TValues extends $TParams["0"], TOpts extends $TParams["1"], T_Descriptor extends $TParams["2"]>(id: TMessageId, values?: TValues, opts?: TOpts, _descriptor?: T_Descriptor) => string | number | bigint | boolean | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | react.ReactPortal | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | null | undefined> | (string | number | bigint | boolean | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | react.ReactPortal | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | null | undefined> | null | undefined)[] | null | undefined;
21
+ };
22
+
23
+ interface I18nContextState<TSupportedLocales extends readonly string[], TLocaleSet extends Record<TSupportedLocales[number], Record<string, any>>> {
24
+ supportedLocales: Readonly<TSupportedLocales>;
25
+ defaultLocale: TSupportedLocales[number];
26
+ localeSet: TLocaleSet;
27
+ }
28
+ declare function createI18nContext<TSupportedLocales extends readonly string[], TLocaleSet extends Record<TSupportedLocales[number], Record<string, any>>>(i18nStore: I18nStore<TSupportedLocales, TLocaleSet>): {
29
+ IntlProvider: ({ currentLocale, children, }: Omit<IntlProviderProps<TSupportedLocales, TLocaleSet>, "i18nStore">) => react_jsx_runtime.JSX.Element;
30
+ useTranslation: <SheetTitle extends keyof TLocaleSet[TSupportedLocales[number]]>(sheetTitle: SheetTitle) => ReturnType<typeof useTranslation<TSupportedLocales, TLocaleSet, SheetTitle, keyof TLocaleSet[TSupportedLocales[number]][SheetTitle]>>;
31
+ };
32
+
33
+ export { type I18nContextState, IntlProvider, type IntlProviderProps, createI18nContext, useTranslation };
@@ -0,0 +1,33 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { I18nStore } from '@sheet-i18n/react-core';
3
+ import * as react from 'react';
4
+ import { MessageDescriptor, IntlShape } from 'react-intl';
5
+
6
+ type IntlProviderProps<TSupportedLocales extends readonly string[], TLocaleSet extends Record<TSupportedLocales[number], Record<string, any>>> = {
7
+ i18nStore: I18nStore<TSupportedLocales, TLocaleSet>;
8
+ currentLocale: TSupportedLocales[number];
9
+ children: React.ReactNode;
10
+ };
11
+ declare function IntlProvider<TSupportedLocales extends readonly string[], TLocaleSet extends Record<TSupportedLocales[number], Record<string, any>>>({ i18nStore, currentLocale, children, }: IntlProviderProps<TSupportedLocales, TLocaleSet>): react_jsx_runtime.JSX.Element;
12
+
13
+ type UseIntlParams<D = MessageDescriptor> = Parameters<IntlShape['$t']> extends [D, ...infer R] ? [...R, Omit<D, 'id'>] : never;
14
+ type $TParams = Partial<UseIntlParams>;
15
+ interface UseTranslationParams<TSupportedLocales extends readonly string[], TLocaleSet extends Record<TSupportedLocales[number], Record<string, any>>, TSheetTitle = keyof TLocaleSet[TSupportedLocales[number]]> {
16
+ sheetTitle: TSheetTitle;
17
+ i18nStore: I18nStore<TSupportedLocales, TLocaleSet>;
18
+ }
19
+ declare function useTranslation<TSupportedLocales extends readonly string[], TLocaleSet extends Record<TSupportedLocales[number], Record<string, any>>, TSheetTitle extends keyof TLocaleSet[TSupportedLocales[number]], TMessageId extends keyof TLocaleSet[TSupportedLocales[number]][TSheetTitle]>({ sheetTitle, }: UseTranslationParams<TSupportedLocales, TLocaleSet, TSheetTitle>): {
20
+ t: <TValues extends $TParams["0"], TOpts extends $TParams["1"], T_Descriptor extends $TParams["2"]>(id: TMessageId, values?: TValues, opts?: TOpts, _descriptor?: T_Descriptor) => string | number | bigint | boolean | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | react.ReactPortal | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | null | undefined> | (string | number | bigint | boolean | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | react.ReactPortal | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<react.ReactNode> | null | undefined> | null | undefined)[] | null | undefined;
21
+ };
22
+
23
+ interface I18nContextState<TSupportedLocales extends readonly string[], TLocaleSet extends Record<TSupportedLocales[number], Record<string, any>>> {
24
+ supportedLocales: Readonly<TSupportedLocales>;
25
+ defaultLocale: TSupportedLocales[number];
26
+ localeSet: TLocaleSet;
27
+ }
28
+ declare function createI18nContext<TSupportedLocales extends readonly string[], TLocaleSet extends Record<TSupportedLocales[number], Record<string, any>>>(i18nStore: I18nStore<TSupportedLocales, TLocaleSet>): {
29
+ IntlProvider: ({ currentLocale, children, }: Omit<IntlProviderProps<TSupportedLocales, TLocaleSet>, "i18nStore">) => react_jsx_runtime.JSX.Element;
30
+ useTranslation: <SheetTitle extends keyof TLocaleSet[TSupportedLocales[number]]>(sheetTitle: SheetTitle) => ReturnType<typeof useTranslation<TSupportedLocales, TLocaleSet, SheetTitle, keyof TLocaleSet[TSupportedLocales[number]][SheetTitle]>>;
31
+ };
32
+
33
+ export { type I18nContextState, IntlProvider, type IntlProviderProps, createI18nContext, useTranslation };
package/dist/index.js ADDED
@@ -0,0 +1,126 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __export = (target, all) => {
25
+ for (var name in all)
26
+ __defProp(target, name, { get: all[name], enumerable: true });
27
+ };
28
+ var __copyProps = (to, from, except, desc) => {
29
+ if (from && typeof from === "object" || typeof from === "function") {
30
+ for (let key of __getOwnPropNames(from))
31
+ if (!__hasOwnProp.call(to, key) && key !== except)
32
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
+ }
34
+ return to;
35
+ };
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+
38
+ // src/index.ts
39
+ var src_exports = {};
40
+ __export(src_exports, {
41
+ IntlProvider: () => IntlProvider,
42
+ createI18nContext: () => createI18nContext,
43
+ useTranslation: () => useTranslation
44
+ });
45
+ module.exports = __toCommonJS(src_exports);
46
+
47
+ // src/createI18nContext.tsx
48
+ var import_shared_utils = require("@sheet-i18n/shared-utils");
49
+ var import_react_core = require("@sheet-i18n/react-core");
50
+
51
+ // src/IntlProvider.tsx
52
+ var import_react_intl = require("react-intl");
53
+ var import_jsx_runtime = require("react/jsx-runtime");
54
+ function IntlProvider({
55
+ i18nStore,
56
+ currentLocale,
57
+ children
58
+ }) {
59
+ const { defaultLocale, localeSet } = i18nStore;
60
+ const locale = currentLocale != null ? currentLocale : defaultLocale;
61
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
62
+ import_react_intl.IntlProvider,
63
+ {
64
+ locale,
65
+ messages: localeSet[currentLocale],
66
+ children
67
+ }
68
+ );
69
+ }
70
+
71
+ // src/useTranslation.ts
72
+ var import_react_intl2 = require("react-intl");
73
+ var intlCache = (0, import_react_intl2.createIntlCache)();
74
+ function useTranslation({
75
+ sheetTitle
76
+ }) {
77
+ const currentIntl = (0, import_react_intl2.useIntl)();
78
+ const totalMessages = currentIntl.messages;
79
+ const targetMessages = totalMessages[sheetTitle];
80
+ const newIntl = (0, import_react_intl2.createIntl)(
81
+ __spreadProps(__spreadValues({}, currentIntl), { messages: targetMessages }),
82
+ intlCache
83
+ );
84
+ const t = (id, values, opts, _descriptor) => {
85
+ const descriptor = __spreadProps(__spreadValues({}, _descriptor != null ? _descriptor : {}), { id });
86
+ return newIntl.$t(descriptor, values, opts);
87
+ };
88
+ return { t };
89
+ }
90
+
91
+ // src/Errors.ts
92
+ var import_errors = require("@sheet-i18n/errors");
93
+ var InvalidI18nContextStateError = class extends import_errors.CustomError {
94
+ };
95
+ var IsNotInstanceOfI18nStoreError = class extends import_errors.CustomError {
96
+ };
97
+
98
+ // src/createI18nContext.tsx
99
+ var import_jsx_runtime2 = require("react/jsx-runtime");
100
+ function createI18nContext(i18nStore) {
101
+ if (import_shared_utils.validator.isNullish(i18nStore)) {
102
+ throw new InvalidI18nContextStateError(
103
+ "\u26A0\uFE0F no i18nStore provided. To use createI18nContext, you must provide an i18nStore as a parameter"
104
+ );
105
+ }
106
+ if (i18nStore instanceof import_react_core.I18nStore !== true) {
107
+ throw new IsNotInstanceOfI18nStoreError(
108
+ "\u26A0\uFE0F The provided i18nStore is invalid. Please ensure a store instance you passed is an instance of I18nStore."
109
+ );
110
+ }
111
+ const IntlProviderImpl = ({
112
+ currentLocale,
113
+ children
114
+ }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IntlProvider, { currentLocale, i18nStore, children });
115
+ const useTranslationImpl = (sheetTitle) => useTranslation({ sheetTitle, i18nStore });
116
+ return {
117
+ IntlProvider: IntlProviderImpl,
118
+ useTranslation: useTranslationImpl
119
+ };
120
+ }
121
+ // Annotate the CommonJS export names for ESM import in node:
122
+ 0 && (module.exports = {
123
+ IntlProvider,
124
+ createI18nContext,
125
+ useTranslation
126
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,104 @@
1
+ "use client";
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __spreadValues = (a, b) => {
10
+ for (var prop in b || (b = {}))
11
+ if (__hasOwnProp.call(b, prop))
12
+ __defNormalProp(a, prop, b[prop]);
13
+ if (__getOwnPropSymbols)
14
+ for (var prop of __getOwnPropSymbols(b)) {
15
+ if (__propIsEnum.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ }
18
+ return a;
19
+ };
20
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
+
22
+ // src/createI18nContext.tsx
23
+ import { validator } from "@sheet-i18n/shared-utils";
24
+ import { I18nStore } from "@sheet-i18n/react-core";
25
+
26
+ // src/IntlProvider.tsx
27
+ import { IntlProvider as ReactIntlProvider } from "react-intl";
28
+ import { jsx } from "react/jsx-runtime";
29
+ function IntlProvider({
30
+ i18nStore,
31
+ currentLocale,
32
+ children
33
+ }) {
34
+ const { defaultLocale, localeSet } = i18nStore;
35
+ const locale = currentLocale != null ? currentLocale : defaultLocale;
36
+ return /* @__PURE__ */ jsx(
37
+ ReactIntlProvider,
38
+ {
39
+ locale,
40
+ messages: localeSet[currentLocale],
41
+ children
42
+ }
43
+ );
44
+ }
45
+
46
+ // src/useTranslation.ts
47
+ import {
48
+ createIntlCache,
49
+ createIntl,
50
+ useIntl
51
+ } from "react-intl";
52
+ var intlCache = createIntlCache();
53
+ function useTranslation({
54
+ sheetTitle
55
+ }) {
56
+ const currentIntl = useIntl();
57
+ const totalMessages = currentIntl.messages;
58
+ const targetMessages = totalMessages[sheetTitle];
59
+ const newIntl = createIntl(
60
+ __spreadProps(__spreadValues({}, currentIntl), { messages: targetMessages }),
61
+ intlCache
62
+ );
63
+ const t = (id, values, opts, _descriptor) => {
64
+ const descriptor = __spreadProps(__spreadValues({}, _descriptor != null ? _descriptor : {}), { id });
65
+ return newIntl.$t(descriptor, values, opts);
66
+ };
67
+ return { t };
68
+ }
69
+
70
+ // src/Errors.ts
71
+ import { CustomError } from "@sheet-i18n/errors";
72
+ var InvalidI18nContextStateError = class extends CustomError {
73
+ };
74
+ var IsNotInstanceOfI18nStoreError = class extends CustomError {
75
+ };
76
+
77
+ // src/createI18nContext.tsx
78
+ import { jsx as jsx2 } from "react/jsx-runtime";
79
+ function createI18nContext(i18nStore) {
80
+ if (validator.isNullish(i18nStore)) {
81
+ throw new InvalidI18nContextStateError(
82
+ "\u26A0\uFE0F no i18nStore provided. To use createI18nContext, you must provide an i18nStore as a parameter"
83
+ );
84
+ }
85
+ if (i18nStore instanceof I18nStore !== true) {
86
+ throw new IsNotInstanceOfI18nStoreError(
87
+ "\u26A0\uFE0F The provided i18nStore is invalid. Please ensure a store instance you passed is an instance of I18nStore."
88
+ );
89
+ }
90
+ const IntlProviderImpl = ({
91
+ currentLocale,
92
+ children
93
+ }) => /* @__PURE__ */ jsx2(IntlProvider, { currentLocale, i18nStore, children });
94
+ const useTranslationImpl = (sheetTitle) => useTranslation({ sheetTitle, i18nStore });
95
+ return {
96
+ IntlProvider: IntlProviderImpl,
97
+ useTranslation: useTranslationImpl
98
+ };
99
+ }
100
+ export {
101
+ IntlProvider,
102
+ createI18nContext,
103
+ useTranslation
104
+ };
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@sheet-i18n/react-client",
3
+ "version": "0.1.1-canary.0",
4
+ "description": "a client package for react modules used by sheet-i18n",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist/**/*"
10
+ ],
11
+ "exports": {
12
+ ".": {
13
+ "require": "./dist/index.js",
14
+ "import": "./dist/index.mjs"
15
+ }
16
+ },
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "keywords": [],
21
+ "author": {
22
+ "name": "devAnderson",
23
+ "email": "chltjdrhd777@gmail.com",
24
+ "url": "https://github.com/chltjdrhd777"
25
+ },
26
+ "license": "ISC",
27
+ "dependencies": {
28
+ "react": "^19.0.0",
29
+ "react-intl": "^7.0.4",
30
+ "@sheet-i18n/shared-utils": "0.2.2-canary.3",
31
+ "@sheet-i18n/errors": "0.2.2-canary.3",
32
+ "@sheet-i18n/react-core": "0.1.1-canary.0"
33
+ },
34
+ "devDependencies": {
35
+ "@types/react": "^19.0.2",
36
+ "@types/react-dom": "^19.0.2",
37
+ "@sheet-i18n/typescript-config": "0.2.2-canary.3"
38
+ },
39
+ "scripts": {
40
+ "build": "tsup",
41
+ "dev": "tsup --watch"
42
+ }
43
+ }