react-intlayer
Version:
Easily internationalize i18n your React applications with type-safe multilingual content management.
104 lines (103 loc) • 4.75 kB
TypeScript
import { IntlayerNode } from "./IntlayerNode.js";
import { HTMLComponents } from "./html/HTMLComponentTypes.js";
import { DeepTransformContent as DeepTransformContent$1, IInterpreterPluginState as IInterpreterPluginState$1, Plugins } from "@intlayer/core/interpreter";
import { DeclaredLocales, LocalesValues } from "@intlayer/types/module_augmentation";
import { ReactNode } from "react";
import * as NodeTypes from "@intlayer/types/nodeType";
import { NodeType } from "@intlayer/types/nodeType";
//#region src/plugins.d.ts
/** ---------------------------------------------
* INTLAYER NODE PLUGIN
* --------------------------------------------- */
type IntlayerNodeCond<T> = T extends number | string ? IntlayerNode<T> : never;
/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
declare const intlayerNodePlugins: Plugins;
/** ---------------------------------------------
* REACT NODE PLUGIN
* --------------------------------------------- */
type ReactNodeCond<T> = T extends {
props: any;
key: any;
} ? ReactNode : never;
/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
declare const reactNodePlugins: Plugins;
/** ---------------------------------------------
* INSERTION PLUGIN
* --------------------------------------------- */
type InsertionCond<T> = T extends {
nodeType: NodeType | string;
[NodeTypes.INSERTION]: infer I;
fields: readonly string[];
} ? <V extends { [K in T['fields'][number]]: ReactNode }>(values: V) => I extends string ? V[keyof V] extends string | number ? IntlayerNode<string> : IntlayerNode<ReactNode> : DeepTransformContent<I> : never;
/** Insertion plugin for React. Handles component/node insertion. */
declare const insertionPlugin: Plugins;
/**
* MARKDOWN PLUGIN
*/
type MarkdownStringCond<T> = T extends string ? IntlayerNode<string, {
metadata: DeepTransformContent<string>;
use: (components: HTMLComponents<'permissive', {}>) => ReactNode;
}> : never;
/** Markdown string plugin. Replaces string node with a component that render the markdown. */
declare const markdownStringPlugin: Plugins;
type MarkdownCond<T> = T extends {
nodeType: NodeType | string;
[NodeTypes.MARKDOWN]: infer M;
tags?: infer U;
metadata?: infer V;
} ? IntlayerNode<M, {
use: (components?: HTMLComponents<'permissive', U>) => ReactNode;
metadata: DeepTransformContent<V>;
}> : never;
declare const markdownPlugin: Plugins;
/** ---------------------------------------------
* HTML PLUGIN
* --------------------------------------------- */
/**
* HTML conditional type that enforces:
* - All components (Standard or Custom) are OPTIONAL in the `use()` method.
* - Custom components props are strictly inferred from the dictionary definition.
*
* This ensures type safety:
* - `html('<div>Hello <CustomComponent /></div>').use({ CustomComponent: ... })` - optional but typed
*/
type HTMLPluginCond<T> = T extends {
nodeType: NodeType | string;
[NodeTypes.HTML]: infer I;
tags?: infer U;
} ? IntlayerNode<I, {
use: (components?: HTMLComponents<'permissive', U>) => ReactNode;
}> : never;
/** HTML plugin. Replaces node with a function that takes components => ReactNode. */
declare const htmlPlugin: Plugins;
/** ---------------------------------------------
* PLUGINS RESULT
* --------------------------------------------- */
type IInterpreterPluginReact<T, _S, _L extends LocalesValues> = {
reactNode: ReactNodeCond<T>;
reactIntlayerNode: IntlayerNodeCond<T>;
reactInsertion: InsertionCond<T>;
reactMarkdown: MarkdownCond<T>;
reactHtml: HTMLPluginCond<T>;
};
/**
* Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.
*
* Otherwise the the `react-intlayer` plugins will override the types of `intlayer` functions.
*/
type IInterpreterPluginState = Omit<IInterpreterPluginState$1, 'insertion'> & {
reactNode: true;
reactIntlayerNode: true;
reactMarkdown: true;
reactHtml: true;
reactInsertion: true;
};
type DeepTransformContent<T, L extends LocalesValues = DeclaredLocales> = DeepTransformContent$1<T, IInterpreterPluginState, L>;
/**
* Get the plugins array for React content transformation.
* This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.
*/
declare const getPlugins: (locale?: LocalesValues, fallback?: boolean) => Plugins[];
//#endregion
export { DeepTransformContent, HTMLPluginCond, IInterpreterPluginReact, IInterpreterPluginState, InsertionCond, IntlayerNodeCond, MarkdownCond, MarkdownStringCond, ReactNodeCond, getPlugins, htmlPlugin, insertionPlugin, intlayerNodePlugins, markdownPlugin, markdownStringPlugin, reactNodePlugins };
//# sourceMappingURL=plugins.d.ts.map