@next-box/i18n 0.0.13 → 0.1.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/cjs/client.cjs +1 -1
- package/dist/cjs/client.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/macros.cjs +1 -1
- package/dist/cjs/macros.cjs.map +1 -1
- package/dist/esm/client.mjs +1 -1
- package/dist/esm/client.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/macros.mjs +1 -1
- package/dist/esm/macros.mjs.map +1 -1
- package/dist/production.analysis.txt +13 -13
- package/dist/types/cjs/components/I18nProvider.d.cts +12 -8
- package/dist/types/cjs/components/I18nProvider.d.cts.map +1 -1
- package/dist/types/cjs/components/Md.d.cts +2 -2
- package/dist/types/cjs/components/Md.d.cts.map +1 -1
- package/dist/types/cjs/helpers/loadConfig.d.cts.map +1 -1
- package/dist/types/cjs/main.d.cts.map +1 -1
- package/dist/types/esm/components/I18nProvider.d.ts +12 -8
- package/dist/types/esm/components/I18nProvider.d.ts.map +1 -1
- package/dist/types/esm/components/Md.d.ts +2 -2
- package/dist/types/esm/components/Md.d.ts.map +1 -1
- package/dist/types/esm/helpers/loadConfig.d.ts.map +1 -1
- package/dist/types/esm/main.d.ts.map +1 -1
- package/dist/types/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +18 -15
- package/src/components/I18nProvider.tsx +3 -7
- package/src/components/Md.tsx +4 -4
- package/src/helpers/loadConfig.ts +3 -3
- package/src/macros.ts +1 -1
- package/src/main.ts +3 -2
package/package.json
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next-box/i18n",
|
|
3
3
|
"description": "A type-safe content resolver with content path auto-complete and value preview.",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.1.0",
|
|
5
5
|
"author": "miami-man",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/badbatch/next-box",
|
|
8
8
|
"repository": {
|
|
9
9
|
"directory": "packages/i18n",
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/badbatch/next-box
|
|
11
|
+
"url": "https://github.com/badbatch/next-box.git"
|
|
12
12
|
},
|
|
13
13
|
"bugs": "https://github.com/badbatch/next-box/issues",
|
|
14
14
|
"type": "module",
|
|
15
|
-
"main": "./dist/cjs/index.
|
|
15
|
+
"main": "./dist/cjs/index.mjs",
|
|
16
16
|
"module": "./dist/esm/index.mjs",
|
|
17
|
-
"types": "./dist/types/cjs/index.d.
|
|
17
|
+
"types": "./dist/types/cjs/index.d.ts",
|
|
18
18
|
"imports": {
|
|
19
19
|
"#*": "./src/*"
|
|
20
20
|
},
|
|
21
21
|
"exports": {
|
|
22
22
|
".": {
|
|
23
|
+
"source": "./src/index.ts",
|
|
23
24
|
"types": {
|
|
24
25
|
"import": "./dist/types/esm/index.d.ts",
|
|
25
26
|
"require": "./dist/types/cjs/index.d.cts"
|
|
@@ -28,6 +29,7 @@
|
|
|
28
29
|
"require": "./dist/cjs/index.cjs"
|
|
29
30
|
},
|
|
30
31
|
"./client": {
|
|
32
|
+
"source": "./src/client.ts",
|
|
31
33
|
"types": {
|
|
32
34
|
"import": "./dist/types/esm/client.d.ts",
|
|
33
35
|
"require": "./dist/types/cjs/client.d.cts"
|
|
@@ -36,6 +38,7 @@
|
|
|
36
38
|
"require": "./dist/cjs/client.cjs"
|
|
37
39
|
},
|
|
38
40
|
"./macros": {
|
|
41
|
+
"source": "./src/macros.ts",
|
|
39
42
|
"types": {
|
|
40
43
|
"import": "./dist/types/esm/macros.d.ts",
|
|
41
44
|
"require": "./dist/types/cjs/macros.d.cts"
|
|
@@ -49,23 +52,23 @@
|
|
|
49
52
|
},
|
|
50
53
|
"dependencies": {
|
|
51
54
|
"callsites": "^4.2.0",
|
|
52
|
-
"markdown-to-jsx": "^
|
|
53
|
-
"type-fest": "^
|
|
54
|
-
"zcb": "^0.3.
|
|
55
|
+
"markdown-to-jsx": "^9.10.2",
|
|
56
|
+
"type-fest": "^5.8.0",
|
|
57
|
+
"zcb": "^0.3.9"
|
|
55
58
|
},
|
|
56
59
|
"peerDependencies": {
|
|
57
60
|
"react": "<20",
|
|
58
61
|
"react-dom": "<20"
|
|
59
62
|
},
|
|
60
63
|
"devDependencies": {
|
|
61
|
-
"@jest/globals": "^
|
|
62
|
-
"@testing-library/react": "^16.3.
|
|
63
|
-
"@types/react": "^19.
|
|
64
|
-
"@types/react-dom": "^19.
|
|
65
|
-
"cts-types": "^0.0.
|
|
66
|
-
"del-cli": "^
|
|
67
|
-
"react": "^19.
|
|
68
|
-
"react-dom": "^19.
|
|
64
|
+
"@jest/globals": "^30.4.1",
|
|
65
|
+
"@testing-library/react": "^16.3.2",
|
|
66
|
+
"@types/react": "^19.2.18",
|
|
67
|
+
"@types/react-dom": "^19.2.4",
|
|
68
|
+
"cts-types": "^0.0.15",
|
|
69
|
+
"del-cli": "^7.0.0",
|
|
70
|
+
"react": "^19.2.8",
|
|
71
|
+
"react-dom": "^19.2.8"
|
|
69
72
|
},
|
|
70
73
|
"scripts": {
|
|
71
74
|
"build": "pnpm run clean:dist && pnpm run compile",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type MarkdownToJSX } from 'markdown-to-jsx';
|
|
2
|
-
import { type
|
|
2
|
+
import { type FC, type ReactNode, createContext } from 'react';
|
|
3
3
|
|
|
4
4
|
export const I18nContext = createContext<
|
|
5
5
|
{
|
|
@@ -14,10 +14,6 @@ export type I18nProviderProps = {
|
|
|
14
14
|
componentMapper: MarkdownToJSX.Overrides;
|
|
15
15
|
} & Omit<MarkdownToJSX.Options, 'overrides'>;
|
|
16
16
|
|
|
17
|
-
export const I18nProvider = ({
|
|
18
|
-
children
|
|
19
|
-
componentMapper,
|
|
20
|
-
...markdownToJsxOptions
|
|
21
|
-
}: I18nProviderProps): JSX.Element => {
|
|
22
|
-
return <I18nContext.Provider value={{ componentMapper, ...markdownToJsxOptions }}>{children}</I18nContext.Provider>;
|
|
17
|
+
export const I18nProvider: FC<I18nProviderProps> = ({ children, componentMapper, ...markdownToJsxOptions }) => {
|
|
18
|
+
return <I18nContext value={{ componentMapper, ...markdownToJsxOptions }}>{children}</I18nContext>;
|
|
23
19
|
};
|
package/src/components/Md.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import MarkdownToJsx, { type MarkdownToJSX } from 'markdown-to-jsx';
|
|
2
|
-
import { type
|
|
2
|
+
import { type FC, use } from 'react';
|
|
3
3
|
import { I18nContext } from '#components/I18nProvider.tsx';
|
|
4
4
|
import { injectVariables } from '#helpers/injectVariables.ts';
|
|
5
5
|
|
|
@@ -16,13 +16,13 @@ export type MdProps = {
|
|
|
16
16
|
variables?: Record<string, string | number>;
|
|
17
17
|
} & Omit<MarkdownToJSX.Options, 'overrides'>;
|
|
18
18
|
|
|
19
|
-
export const Md = ({
|
|
19
|
+
export const Md: FC<MdProps> = ({
|
|
20
20
|
children,
|
|
21
21
|
componentMapper: componentMapperOverrides,
|
|
22
22
|
variables,
|
|
23
23
|
...markdownToJsxOptionOverrides
|
|
24
|
-
}
|
|
25
|
-
const { componentMapper, ...markdownToJsxOptions } =
|
|
24
|
+
}) => {
|
|
25
|
+
const { componentMapper, ...markdownToJsxOptions } = use(I18nContext);
|
|
26
26
|
|
|
27
27
|
return (
|
|
28
28
|
<MarkdownToJsx
|
|
@@ -3,15 +3,15 @@ import { resolve } from 'node:path';
|
|
|
3
3
|
import { CONFIG_FILENAME } from '#constants.ts';
|
|
4
4
|
import { type MacrosConfig } from '#types.ts';
|
|
5
5
|
|
|
6
|
+
const cwd = process.cwd();
|
|
7
|
+
|
|
6
8
|
export const loadConfig = (): Partial<MacrosConfig> => {
|
|
7
9
|
let config: Partial<MacrosConfig> = {};
|
|
8
10
|
|
|
9
11
|
try {
|
|
10
12
|
// JSON.parse returns an any time
|
|
11
13
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
12
|
-
config = JSON.parse(
|
|
13
|
-
readFileSync(resolve(process.cwd(), CONFIG_FILENAME), { encoding: 'utf8' }),
|
|
14
|
-
) as Partial<MacrosConfig>;
|
|
14
|
+
config = JSON.parse(readFileSync(resolve(cwd, CONFIG_FILENAME), { encoding: 'utf8' })) as Partial<MacrosConfig>;
|
|
15
15
|
} catch {
|
|
16
16
|
// no catch
|
|
17
17
|
}
|
package/src/macros.ts
CHANGED
|
@@ -14,7 +14,7 @@ export const md = <P extends string>(path: P): P => {
|
|
|
14
14
|
|
|
15
15
|
if (markdownDir) {
|
|
16
16
|
if (NEXT_PUBLIC_LANGUAGE_CODE) {
|
|
17
|
-
markdownDir = markdownDir.replaceAll('{{NEXT_PUBLIC_LANGUAGE_CODE}}', NEXT_PUBLIC_LANGUAGE_CODE);
|
|
17
|
+
markdownDir = markdownDir.replaceAll('{{NEXT_PUBLIC_LANGUAGE_CODE}}', () => NEXT_PUBLIC_LANGUAGE_CODE);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
dir = resolve(dir, markdownDir);
|
package/src/main.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Get } from 'type-fest';
|
|
1
2
|
import { type AnyRecord, type Path, createConfigReader } from 'zcb';
|
|
2
3
|
import { type CreateI18nResult } from '#types.ts';
|
|
3
4
|
|
|
@@ -8,12 +9,12 @@ export const createI18n = <U extends object>(i18n: U): CreateI18nResult<U> => {
|
|
|
8
9
|
// @ts-expect-error intentionally ignoring the type checking here as
|
|
9
10
|
// function is supposed to be untyped.
|
|
10
11
|
t: (key: string, variables?: AnyRecord): string | undefined => reader.read(key, variables),
|
|
11
|
-
tt: <P extends Path<U>>(path: P, variables?: AnyRecord) => {
|
|
12
|
+
tt: <P extends Path<U>>(path: P, variables?: AnyRecord): Get<U, P> => {
|
|
12
13
|
const result = reader.read(path, variables);
|
|
13
14
|
|
|
14
15
|
// This can resolve to a falsy value at runtime
|
|
15
16
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
16
|
-
if (
|
|
17
|
+
if (result === undefined) {
|
|
17
18
|
throw new Error(`Path "${String(path)}" did not resolve to a value`);
|
|
18
19
|
}
|
|
19
20
|
|