@next-box/i18n 0.0.9 → 0.0.11

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/package.json CHANGED
@@ -1,7 +1,7 @@
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.9",
4
+ "version": "0.0.11",
5
5
  "author": "miami-man",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/badbatch/next-box",
@@ -1,19 +1,18 @@
1
- import type MarkdownToJsx from 'markdown-to-jsx';
2
- import { type ComponentProps, type JSX, type ReactNode, createContext } from 'react';
3
- import { type ComponentMapper } from '#types.ts';
1
+ import { type MarkdownToJSX } from 'markdown-to-jsx';
2
+ import { type JSX, type ReactNode, createContext } from 'react';
4
3
 
5
4
  export const I18nContext = createContext<
6
5
  {
7
- componentMapper: ComponentMapper;
8
- } & Omit<ComponentProps<typeof MarkdownToJsx>['options'], 'overrides'>
6
+ componentMapper: MarkdownToJSX.Overrides;
7
+ } & Omit<MarkdownToJSX.Options, 'overrides'>
9
8
  >({
10
9
  componentMapper: {},
11
10
  });
12
11
 
13
12
  export type I18nProviderProps = {
14
13
  children: ReactNode;
15
- componentMapper: ComponentMapper;
16
- } & Omit<ComponentProps<typeof MarkdownToJsx>['options'], 'overrides'>;
14
+ componentMapper: MarkdownToJSX.Overrides;
15
+ } & Omit<MarkdownToJSX.Options, 'overrides'>;
17
16
 
18
17
  export const I18nProvider = ({
19
18
  children,
@@ -2,17 +2,19 @@
2
2
  * @jest-environment jsdom
3
3
  */
4
4
  import { render } from '@testing-library/react';
5
+ import { type MarkdownToJSX } from 'markdown-to-jsx';
5
6
  import { type ReactNode } from 'react';
6
7
  import { I18nProvider } from '#components/I18nProvider.tsx';
7
- import { type ComponentMapper } from '#types.js';
8
8
  import { Md } from './Md.tsx';
9
9
 
10
10
  type ComponentProps = {
11
11
  children: ReactNode;
12
12
  };
13
13
 
14
- const componentMapper: ComponentMapper = {
15
- CustomComponent: ({ children }: ComponentProps) => <div data-display-name="CustomComponent">{children}</div>,
14
+ const componentMapper: MarkdownToJSX.Overrides = {
15
+ CustomComponent: {
16
+ component: ({ children }: ComponentProps) => <div data-display-name="CustomComponent">{children}</div>,
17
+ },
16
18
  p: ({ children }: ComponentProps) => <p data-disaplay-name="p">{children}</p>,
17
19
  };
18
20
 
@@ -1,8 +1,7 @@
1
- import MarkdownToJsx from 'markdown-to-jsx';
2
- import { type ComponentProps, type JSX, useContext } from 'react';
1
+ import MarkdownToJsx, { type MarkdownToJSX } from 'markdown-to-jsx';
2
+ import { type JSX, useContext } from 'react';
3
3
  import { I18nContext } from '#components/I18nProvider.tsx';
4
4
  import { injectVariables } from '#helpers/injectVariables.ts';
5
- import { type ComponentMapper } from '#types.ts';
6
5
 
7
6
  export type MdProps = {
8
7
  // The markdown to convert into JSX.
@@ -12,10 +11,10 @@ export type MdProps = {
12
11
  // the name of a React component, and the value being a
13
12
  // React component. This prop is designed as an override
14
13
  // for the componentMapper passed into the I18nProvider.
15
- componentMapper?: ComponentMapper;
14
+ componentMapper?: MarkdownToJSX.Overrides;
16
15
  // An object of key/value pairs for content with template variables.
17
16
  variables?: Record<string, string | number>;
18
- } & Omit<ComponentProps<typeof MarkdownToJsx>['options'], 'overrides'>;
17
+ } & Omit<MarkdownToJSX.Options, 'overrides'>;
19
18
 
20
19
  export const Md = ({
21
20
  children,
@@ -1,4 +1,5 @@
1
1
  import { readFileSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
2
3
  import { CONFIG_FILENAME } from '#constants.ts';
3
4
  import { type MacrosConfig } from '#types.ts';
4
5
 
@@ -8,7 +9,9 @@ export const loadConfig = (): Partial<MacrosConfig> => {
8
9
  try {
9
10
  // JSON.parse returns an any time
10
11
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
11
- config = JSON.parse(readFileSync(CONFIG_FILENAME, { encoding: 'utf8' })) as Partial<MacrosConfig>;
12
+ config = JSON.parse(
13
+ readFileSync(resolve(process.cwd(), CONFIG_FILENAME), { encoding: 'utf8' }),
14
+ ) as Partial<MacrosConfig>;
12
15
  } catch {
13
16
  // no catch
14
17
  }
package/src/types.ts CHANGED
@@ -1,10 +1,5 @@
1
- import { type ComponentType } from 'react';
2
1
  import { type AnyRecord, type ConfigReader } from 'zcb';
3
2
 
4
- // Need to keep as generic as possible.
5
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
- export type ComponentMapper = Record<string, ComponentType<any>>;
7
-
8
3
  export type CreateI18nResult<U extends object> = {
9
4
  // Untyped content lookup. Function takes a string and returns the
10
5
  // value that path resolves in the i18n object passed into createI18n.