react-intlayer 9.5.9-canary.0 → 9.5.10
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/IntlayerNode.cjs +18 -18
- package/dist/cjs/IntlayerNode.cjs.map +1 -1
- package/dist/cjs/analytics/useAnalytics.cjs +2 -2
- package/dist/cjs/analytics/useConversion.cjs +1 -1
- package/dist/cjs/analytics/useExperiment.cjs +1 -1
- package/dist/cjs/client/IntlayerProvider.cjs +30 -16
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/format/index.cjs +4 -4
- package/dist/cjs/client/index.cjs +2 -2
- package/dist/cjs/client/t.cjs +1 -1
- package/dist/cjs/client/useDictionary.cjs +2 -2
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +2 -2
- package/dist/cjs/client/useI18n.cjs +1 -1
- package/dist/cjs/client/useIntlayer.cjs +2 -2
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +1 -1
- package/dist/cjs/client/useLocaleBase.cjs +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +10 -2
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
- package/dist/cjs/client/useRewriteURL.cjs +1 -1
- package/dist/cjs/client/useTraduction.cjs +1 -1
- package/dist/cjs/html/HTMLRenderer.cjs +1 -1
- package/dist/cjs/index.cjs +5 -3
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/plugins.cjs +32 -47
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/server/format/index.cjs +4 -4
- package/dist/cjs/server/index.cjs +3 -3
- package/dist/cjs/server/useDictionaryDynamic.cjs +1 -1
- package/dist/esm/IntlayerNode.mjs +18 -18
- package/dist/esm/IntlayerNode.mjs.map +1 -1
- package/dist/esm/analytics/useAnalytics.mjs +2 -2
- package/dist/esm/analytics/useConversion.mjs +1 -1
- package/dist/esm/analytics/useExperiment.mjs +1 -1
- package/dist/esm/client/IntlayerProvider.mjs +31 -17
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/format/index.mjs +4 -4
- package/dist/esm/client/index.mjs +2 -2
- package/dist/esm/client/t.mjs +1 -1
- package/dist/esm/client/useDictionary.mjs +2 -2
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +2 -2
- package/dist/esm/client/useI18n.mjs +1 -1
- package/dist/esm/client/useIntlayer.mjs +2 -2
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +1 -1
- package/dist/esm/client/useLocaleBase.mjs +1 -1
- package/dist/esm/client/useLocaleStorage.mjs +11 -4
- package/dist/esm/client/useLocaleStorage.mjs.map +1 -1
- package/dist/esm/client/useRewriteURL.mjs +1 -1
- package/dist/esm/client/useTraduction.mjs +1 -1
- package/dist/esm/html/HTMLRenderer.mjs +1 -1
- package/dist/esm/index.mjs +5 -4
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/plugins.mjs +32 -47
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/server/format/index.mjs +4 -4
- package/dist/esm/server/index.mjs +3 -3
- package/dist/esm/server/useDictionaryDynamic.mjs +1 -1
- package/dist/types/IntlayerNode.d.ts +12 -0
- package/dist/types/IntlayerNode.d.ts.map +1 -1
- package/dist/types/client/IntlayerProvider.d.ts.map +1 -1
- package/dist/types/client/useLocaleStorage.d.ts +8 -1
- package/dist/types/client/useLocaleStorage.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/markdown/index.d.ts +2 -2
- package/dist/types/plugins.d.ts.map +1 -1
- package/package.json +9 -9
package/dist/cjs/plugins.cjs
CHANGED
|
@@ -5,13 +5,13 @@ const require_client_useLoadDynamic = require('./client/useLoadDynamic.cjs');
|
|
|
5
5
|
const require_editor_ContentSelector = require('./editor/ContentSelector.cjs');
|
|
6
6
|
const require_IntlayerNode = require('./IntlayerNode.cjs');
|
|
7
7
|
const require_reactElement_renderReactElement = require('./reactElement/renderReactElement.cjs');
|
|
8
|
-
let react = require("react");
|
|
9
|
-
let _intlayer_config_built = require("@intlayer/config/built");
|
|
10
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
11
8
|
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
9
|
+
let _intlayer_config_built = require("@intlayer/config/built");
|
|
12
10
|
let _intlayer_core_markdown = require("@intlayer/core/markdown");
|
|
13
11
|
let _intlayer_types_nodeType = require("@intlayer/types/nodeType");
|
|
14
12
|
_intlayer_types_nodeType = require_runtime.__toESM(_intlayer_types_nodeType);
|
|
13
|
+
let react = require("react");
|
|
14
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
15
15
|
|
|
16
16
|
//#region src/plugins.tsx
|
|
17
17
|
const markdownRendererModulePromise = process.env.INTLAYER_NODE_TYPE_MARKDOWN !== "false" ? Promise.resolve().then(() => require("./markdown/MarkdownRendererPlugin.cjs")).then((m) => m.MarkdownRendererPlugin) : null;
|
|
@@ -22,20 +22,26 @@ htmlRendererModulePromise?.catch(() => {});
|
|
|
22
22
|
const intlayerNodePlugins = {
|
|
23
23
|
id: "intlayer-node-plugin",
|
|
24
24
|
canHandle: (node) => typeof node === "bigint" || typeof node === "string" || typeof node === "number",
|
|
25
|
-
transform: (_node,
|
|
25
|
+
transform: (_node, props) => {
|
|
26
26
|
if (process.env.INTLAYER_ANALYTICS_ENABLED !== "false") require_analytics_exposureSink.reportExposure({
|
|
27
|
-
dictionaryKey:
|
|
28
|
-
keyPath:
|
|
29
|
-
locale:
|
|
27
|
+
dictionaryKey: props.dictionaryKey,
|
|
28
|
+
keyPath: props.keyPath,
|
|
29
|
+
locale: props.locale,
|
|
30
30
|
nodeType: "text"
|
|
31
31
|
});
|
|
32
|
+
if (process.env.INTLAYER_EDITOR_ENABLED !== "false" && _intlayer_config_built.editor.enabled) {
|
|
33
|
+
const { plugins, ...rest } = props;
|
|
34
|
+
return require_IntlayerNode.renderIntlayerNode({
|
|
35
|
+
value: rest.children,
|
|
36
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_editor_ContentSelector.ContentSelector, {
|
|
37
|
+
...rest,
|
|
38
|
+
children: rest.children
|
|
39
|
+
})
|
|
40
|
+
});
|
|
41
|
+
}
|
|
32
42
|
return require_IntlayerNode.renderIntlayerNode({
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
children: process.env.INTLAYER_EDITOR_ENABLED !== "false" && _intlayer_config_built.editor.enabled ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_editor_ContentSelector.ContentSelector, {
|
|
36
|
-
...rest,
|
|
37
|
-
children: rest.children
|
|
38
|
-
}) : rest.children
|
|
43
|
+
value: props.children,
|
|
44
|
+
children: props.children
|
|
39
45
|
});
|
|
40
46
|
}
|
|
41
47
|
};
|
|
@@ -149,22 +155,12 @@ const markdownStringPlugin = process.env.INTLAYER_NODE_TYPE_MARKDOWN === "false"
|
|
|
149
155
|
components,
|
|
150
156
|
children: node
|
|
151
157
|
}),
|
|
152
|
-
additionalProps: {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return new Proxy(element, { get(target, prop, receiver) {
|
|
156
|
-
if (prop === "value") return node;
|
|
157
|
-
if (prop === Symbol.toPrimitive) return () => node;
|
|
158
|
-
if (prop === "toString") return () => node;
|
|
159
|
-
if (prop === "valueOf") return () => node;
|
|
160
|
-
if (typeof prop === "string" && prop !== "constructor") {
|
|
161
|
-
const method = String.prototype[prop];
|
|
162
|
-
if (typeof method === "function") return method.bind(node);
|
|
158
|
+
additionalProps: {
|
|
159
|
+
metadata: metadataNodes,
|
|
160
|
+
use: render
|
|
163
161
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
return Reflect.get(target, prop, receiver);
|
|
167
|
-
} });
|
|
162
|
+
});
|
|
163
|
+
return render();
|
|
168
164
|
}
|
|
169
165
|
};
|
|
170
166
|
const markdownPlugin = process.env.INTLAYER_NODE_TYPE_MARKDOWN === "false" ? _intlayer_core_interpreter.fallbackPlugin : {
|
|
@@ -206,21 +202,10 @@ const htmlPlugin = process.env.INTLAYER_NODE_TYPE_HTML === "false" ? _intlayer_c
|
|
|
206
202
|
...rest,
|
|
207
203
|
html,
|
|
208
204
|
userComponents
|
|
209
|
-
})
|
|
205
|
+
}),
|
|
206
|
+
additionalProps: { use: render }
|
|
210
207
|
});
|
|
211
|
-
|
|
212
|
-
return new Proxy(element, { get(target, prop, receiver) {
|
|
213
|
-
if (prop === "value") return html;
|
|
214
|
-
if (prop === Symbol.toPrimitive) return () => html;
|
|
215
|
-
if (prop === "toString") return () => html;
|
|
216
|
-
if (prop === "valueOf") return () => html;
|
|
217
|
-
if (typeof prop === "string" && prop !== "constructor") {
|
|
218
|
-
const method = String.prototype[prop];
|
|
219
|
-
if (typeof method === "function") return method.bind(html);
|
|
220
|
-
}
|
|
221
|
-
if (prop === "use") return (userComponents) => render(userComponents);
|
|
222
|
-
return Reflect.get(target, prop, receiver);
|
|
223
|
-
} });
|
|
208
|
+
return render();
|
|
224
209
|
}
|
|
225
210
|
};
|
|
226
211
|
const pluginsCache = /* @__PURE__ */ new Map();
|
|
@@ -231,7 +216,8 @@ const pluginsCache = /* @__PURE__ */ new Map();
|
|
|
231
216
|
const getPlugins = (locale, fallback = true) => {
|
|
232
217
|
const cacheKey = `${locale ?? _intlayer_config_built.internationalization.defaultLocale}_${fallback}`;
|
|
233
218
|
if (pluginsCache.has(cacheKey)) return pluginsCache.get(cacheKey);
|
|
234
|
-
const
|
|
219
|
+
const enabledPlugins = [
|
|
220
|
+
intlayerNodePlugins,
|
|
235
221
|
(0, _intlayer_core_interpreter.translationPlugin)(locale ?? _intlayer_config_built.internationalization.defaultLocale, fallback ? _intlayer_config_built.internationalization.defaultLocale : void 0),
|
|
236
222
|
_intlayer_core_interpreter.enumerationPlugin,
|
|
237
223
|
(0, _intlayer_core_interpreter.pluralPlugin)(locale ?? _intlayer_config_built.internationalization.defaultLocale),
|
|
@@ -240,14 +226,13 @@ const getPlugins = (locale, fallback = true) => {
|
|
|
240
226
|
_intlayer_core_interpreter.filePlugin,
|
|
241
227
|
_intlayer_core_interpreter.genderPlugin,
|
|
242
228
|
_intlayer_core_interpreter.selectPlugin,
|
|
243
|
-
intlayerNodePlugins,
|
|
244
229
|
reactNodePlugins,
|
|
245
230
|
insertionPlugin,
|
|
246
231
|
markdownPlugin,
|
|
247
232
|
htmlPlugin
|
|
248
|
-
];
|
|
249
|
-
pluginsCache.set(cacheKey,
|
|
250
|
-
return
|
|
233
|
+
].filter((plugin) => plugin !== _intlayer_core_interpreter.fallbackPlugin);
|
|
234
|
+
pluginsCache.set(cacheKey, enabledPlugins);
|
|
235
|
+
return enabledPlugins;
|
|
251
236
|
};
|
|
252
237
|
|
|
253
238
|
//#endregion
|
package/dist/cjs/plugins.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.cjs","names":["renderIntlayerNode","editor","ContentSelector","fallbackPlugin","renderReactElement","splitInsertionTemplate","createElement","Fragment","NodeTypes","isInterpolableWrapperNode","transformInterpolableNode","resolveInsertedSelector","useLoadDynamic","getMarkdownMetadata","internationalization","translationPlugin","enumerationPlugin","pluralPlugin","conditionPlugin","nestedPlugin","filePlugin","genderPlugin","selectPlugin"],"sources":["../../src/plugins.tsx"],"sourcesContent":["import { editor, internationalization } from '@intlayer/config/built';\nimport {\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n fallbackPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n isInterpolableWrapperNode,\n nestedPlugin,\n type Plugins,\n pluralPlugin,\n resolveInsertedSelector,\n selectPlugin,\n splitInsertionTemplate,\n transformInterpolableNode,\n translationPlugin,\n} from '@intlayer/core/interpreter';\nimport { getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type {\n HTMLContent,\n InsertionContent,\n MarkdownContent,\n} from '@intlayer/core/transpiler';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport {\n createElement,\n type FC,\n Fragment,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport { reportExposure } from './analytics/exposureSink';\nimport { useLoadDynamic } from './client/useLoadDynamic';\nimport { ContentSelector } from './editor/ContentSelector';\nimport type { HTMLComponents } from './html/HTMLComponentTypes';\nimport { type IntlayerNode, renderIntlayerNode } from './IntlayerNode';\nimport { renderReactElement } from './reactElement/renderReactElement';\n\nconst markdownRendererModulePromise =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN !== 'false'\n ? import('./markdown/MarkdownRendererPlugin').then(\n (m) => m.MarkdownRendererPlugin\n )\n : null;\n\nconst htmlRendererModulePromise =\n process.env.INTLAYER_NODE_TYPE_HTML !== 'false'\n ? import('./html/HTMLRendererPlugin').then((m) => m.HTMLRendererPlugin)\n : null;\n\n// These preloads are read later by `useLoadDynamic`, so the rejection must stay\n// on the promise: a `.catch()` chained into it would resolve with `undefined`\n// and be mistaken for a loaded module. Handle it on the side instead, so an\n// aborted chunk load never escapes as an unhandled rejection.\nmarkdownRendererModulePromise?.catch(() => {});\nhtmlRendererModulePromise?.catch(() => {});\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const intlayerNodePlugins: Plugins = {\n id: 'intlayer-node-plugin',\n canHandle: (node) =>\n typeof node === 'bigint' ||\n typeof node === 'string' ||\n typeof node === 'number',\n transform: (\n _node,\n {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n }\n ) => {\n // Node-level analytics: record which content is resolved for display.\n // No-op (and dead-code-eliminated) when analytics is disabled.\n if (process.env.INTLAYER_ANALYTICS_ENABLED !== 'false') {\n reportExposure({\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n locale: rest.locale,\n nodeType: 'text',\n });\n }\n\n return renderIntlayerNode({\n ...rest,\n value: rest.children,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' && editor.enabled ? (\n <ContentSelector {...rest}>{rest.children}</ContentSelector>\n ) : (\n rest.children\n ),\n });\n },\n};\n\n/** ---------------------------------------------\n * REACT NODE PLUGIN\n * --------------------------------------------- */\n\nexport type ReactNodeCond<T> = T extends {\n props: any;\n key: any;\n}\n ? ReactNode\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const reactNodePlugins: Plugins =\n process.env.INTLAYER_NODE_TYPE_REACT_NODE === 'false'\n ? fallbackPlugin\n : {\n id: 'react-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' &&\n typeof node?.props !== 'undefined' &&\n typeof node.key !== 'undefined',\n\n transform: (\n node,\n {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n }\n ) => {\n if (process.env.INTLAYER_ANALYTICS_ENABLED !== 'false') {\n reportExposure({\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n locale: rest.locale,\n nodeType: 'react-node',\n });\n }\n\n return renderIntlayerNode({\n ...rest,\n value: '[[react-element]]',\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n {renderReactElement(node)}\n </ContentSelector>\n ) : (\n renderReactElement(node)\n ),\n });\n },\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer I;\n fields: readonly string[];\n}\n ? <V extends { [K in T['fields'][number]]: ReactNode }>(\n values: V\n ) => I extends string\n ? V[keyof V] extends string | number\n ? IntlayerNode<string>\n : IntlayerNode<ReactNode>\n : DeepTransformContent<I>\n : never;\n\n/**\n * Split insertion string and join with React nodes using shared core logic\n */\nconst splitAndJoinInsertion = (\n template: string,\n values: Record<string, string | number | ReactNode>\n): ReactNode => {\n const result = splitInsertionTemplate(template, values);\n\n if (result.isSimple) {\n // Simple string replacement\n return result.parts as string;\n }\n\n // Return as Fragment with proper keys\n return createElement(\n Fragment,\n null,\n ...(result.parts as any[]).map((part, index) =>\n createElement(Fragment, { key: index }, part)\n )\n );\n};\n\n/** Insertion plugin for React. Handles component/node insertion. */\nexport const insertionPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_INSERTION === 'false'\n ? fallbackPlugin\n : {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.INSERTION,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.INSERTION,\n },\n ];\n\n const children = node[NodeTypes.INSERTION];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) =>\n typeof node === 'string' || isInterpolableWrapperNode(node),\n transform: (node, subProps, deepTransformNode) => {\n // `html()`/`markdown()` nodes carry their `{{ … }}` placeholders\n // inside a raw string. Interpolate into that string, then re-run\n // the transform so the html/markdown renderer applies afterwards.\n // React nodes cannot be injected into a raw markup string, so\n // string interpolation (not `splitAndJoinInsertion`) is used here.\n if (isInterpolableWrapperNode(node)) {\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) =>\n transformInterpolableNode(\n node,\n values,\n subProps,\n props.plugins,\n deepTransformNode\n );\n }\n\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]:\n | string\n | number\n | ReactNode;\n }\n ) => {\n const result = splitAndJoinInsertion(transformedResult, values);\n\n return deepTransformNode(result, {\n ...subProps,\n plugins: props.plugins,\n children: result,\n });\n };\n },\n };\n\n const result = deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n\n return resolveInsertedSelector(children, result);\n },\n };\n\n/**\n * MARKDOWN PLUGIN\n */\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<\n string,\n {\n metadata: DeepTransformContent<string>;\n use: (components: HTMLComponents<'permissive', {}>) => ReactNode;\n }\n >\n : never;\n\nconst MarkdownSuspenseRenderer: FC<Record<string, any>> = ({\n children,\n ...props\n}) => {\n const MarkdownRendererPlugin = useLoadDynamic(\n 'markdown-renderer-plugin',\n markdownRendererModulePromise!\n );\n return createElement(MarkdownRendererPlugin as any, { ...props, children });\n};\n\n/** Markdown string plugin. Replaces string node with a component that render the markdown. */\nexport const markdownStringPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, props, deepTransformNode) => {\n const {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n } = props;\n\n const metadata = getMarkdownMetadata(node) ?? {};\n\n const metadataPlugins: Plugins = {\n id: 'markdown-metadata-plugin',\n canHandle: (metadataNode) =>\n typeof metadataNode === 'string' ||\n typeof metadataNode === 'number' ||\n typeof metadataNode === 'boolean' ||\n !metadataNode,\n transform: (metadataNode, props) =>\n renderIntlayerNode({\n ...props,\n value: metadataNode,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>{node}</ContentSelector>\n ) : (\n node\n ),\n }),\n };\n\n // Transform metadata while keeping the same structure\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n const render = (components?: HTMLComponents) =>\n renderIntlayerNode({\n ...props,\n value: node,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n <MarkdownSuspenseRenderer {...rest} components={components}>\n {node}\n </MarkdownSuspenseRenderer>\n </ContentSelector>\n ) : (\n <MarkdownSuspenseRenderer {...rest} components={components}>\n {node}\n </MarkdownSuspenseRenderer>\n ),\n additionalProps: {\n metadata: metadataNodes,\n },\n });\n\n const element = render() as unknown as ReactElement;\n\n return new Proxy(element, {\n get(target, prop, receiver) {\n if (prop === 'value') return node;\n if (prop === Symbol.toPrimitive) return () => node;\n if (prop === 'toString') return () => node;\n if (prop === 'valueOf') return () => node;\n if (typeof prop === 'string' && prop !== 'constructor') {\n const method = (String.prototype as any)[prop];\n if (typeof method === 'function') return method.bind(node);\n }\n if (prop === 'metadata') return metadataNodes;\n if (prop === 'use')\n return (components?: HTMLComponents) => render(components);\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n },\n };\n\nexport type MarkdownCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.MARKDOWN]: infer M;\n tags?: infer U;\n metadata?: infer V;\n}\n ? IntlayerNode<\n M,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n metadata: DeepTransformContent<V>;\n }\n >\n : never;\n\nexport const markdownPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.MARKDOWN,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.MARKDOWN,\n },\n ];\n\n const children = node[NodeTypes.MARKDOWN];\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [markdownStringPlugin, ...(props.plugins ?? [])],\n });\n },\n };\n\n/** ---------------------------------------------\n * HTML PLUGIN\n * --------------------------------------------- */\n\n/**\n * HTML conditional type that enforces:\n * - All components (Standard or Custom) are OPTIONAL in the `use()` method.\n * - Custom components props are strictly inferred from the dictionary definition.\n *\n * This ensures type safety:\n * - `html('<div>Hello <CustomComponent /></div>').use({ CustomComponent: ... })` - optional but typed\n */\nexport type HTMLPluginCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.HTML]: infer I;\n tags?: infer U;\n}\n ? IntlayerNode<\n I,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n }\n >\n : never;\n\nconst HTMLSuspenseRenderer: FC<Record<string, any>> = (props) => {\n const HTMLRendererPlugin = useLoadDynamic(\n 'html-renderer-plugin',\n htmlRendererModulePromise!\n );\n return createElement(HTMLRendererPlugin as any, props);\n};\n\n/** HTML plugin. Replaces node with a function that takes components => ReactNode. */\nexport const htmlPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_HTML === 'false'\n ? fallbackPlugin\n : {\n id: 'html-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.HTML,\n\n transform: (node: HTMLContent<string>, props) => {\n const html = node[NodeTypes.HTML];\n const { plugins, ...rest } = props;\n\n // Type-safe render function that accepts properly typed components\n const render = (userComponents?: HTMLComponents): ReactNode =>\n renderIntlayerNode({\n ...rest,\n value: html,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n <HTMLSuspenseRenderer\n {...rest}\n html={html}\n userComponents={userComponents}\n />\n </ContentSelector>\n ) : (\n <HTMLSuspenseRenderer\n {...rest}\n html={html}\n userComponents={userComponents}\n />\n ),\n });\n\n const element = render() as unknown as ReactElement;\n\n return new Proxy(element, {\n get(target, prop, receiver) {\n if (prop === 'value') return html;\n if (prop === Symbol.toPrimitive) return () => html;\n if (prop === 'toString') return () => html;\n if (prop === 'valueOf') return () => html;\n if (typeof prop === 'string' && prop !== 'constructor') {\n const method = (String.prototype as any)[prop];\n if (typeof method === 'function') return method.bind(html);\n }\n if (prop === 'use')\n return (userComponents?: HTMLComponents) =>\n render(userComponents);\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n },\n };\n\n/** ---------------------------------------------\n * PLUGINS RESULT\n * --------------------------------------------- */\n\nexport type IInterpreterPluginReact<T, _S, _L extends LocalesValues> = {\n reactNode: ReactNodeCond<T>;\n reactIntlayerNode: IntlayerNodeCond<T>;\n reactInsertion: InsertionCond<T>;\n reactMarkdown: MarkdownCond<T>;\n reactHtml: HTMLPluginCond<T>;\n};\n\n/**\n * Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.\n *\n * Otherwise the the `react-intlayer` plugins will override the types of `intlayer` functions.\n */\nexport type IInterpreterPluginState = Omit<\n IInterpreterPluginStateCore,\n 'insertion' // Remove insertion type from core package\n> & {\n reactNode: true;\n reactIntlayerNode: true;\n reactMarkdown: true;\n reactHtml: true;\n reactInsertion: true;\n};\n\nexport type DeepTransformContent<\n T,\n L extends LocalesValues = DeclaredLocales,\n> = DeepTransformContentCore<T, IInterpreterPluginState, L>;\n\nconst pluginsCache = new Map<string, Plugins[]>();\n\n/**\n * Get the plugins array for React content transformation.\n * This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.\n */\nexport const getPlugins = (\n locale?: LocalesValues,\n fallback: boolean = true\n): Plugins[] => {\n const currentLocale = locale ?? internationalization.defaultLocale;\n const cacheKey = `${currentLocale}_${fallback}`;\n\n if (pluginsCache.has(cacheKey)) {\n return pluginsCache.get(cacheKey)!;\n }\n\n const plugins = [\n // Env var allows the bundler to to remove the plugin if not used to make the bundle smaller\n translationPlugin(\n locale ?? internationalization.defaultLocale,\n fallback ? internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n pluralPlugin(locale ?? internationalization.defaultLocale),\n conditionPlugin,\n nestedPlugin(locale ?? internationalization.defaultLocale),\n\n filePlugin,\n genderPlugin,\n selectPlugin,\n // Always include: handle plain strings/numbers and React elements\n intlayerNodePlugins,\n reactNodePlugins,\n insertionPlugin,\n markdownPlugin,\n htmlPlugin,\n ] as Plugins[];\n\n pluginsCache.set(cacheKey, plugins);\n\n return plugins;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AA8CA,MAAM,gCACJ,QAAQ,IAAI,gCAAgC,+CACxC,0CAA4C,MACzC,MAAM,EAAE,sBACX,IACA;AAEN,MAAM,4BACJ,QAAQ,IAAI,4BAA4B,+CACpC,kCAAoC,MAAM,MAAM,EAAE,kBAAkB,IACpE;AAMN,+BAA+B,YAAY,CAAC,CAAC;AAC7C,2BAA2B,YAAY,CAAC,CAAC;;AAWzC,MAAa,sBAA+B;CAC1C,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAChB,OAAO,SAAS,YAChB,OAAO,SAAS;CAClB,YACE,OACA,EACE,SACA,GAAG,WAEF;EAGH,IAAI,QAAQ,IAAI,+BAA+B,SAC7C,8CAAe;GACb,eAAe,KAAK;GACpB,SAAS,KAAK;GACd,QAAQ,KAAK;GACb,UAAU;EACZ,CAAC;EAGH,OAAOA,wCAAmB;GACxB,GAAG;GACH,OAAO,KAAK;GACZ,UACE,QAAQ,IAAI,4BAA4B,WAAWC,8BAAO,UACxD,2CAACC,gDAAD;IAAiB,GAAI;cAAO,KAAK;GAA0B,KAE3D,KAAK;EAEX,CAAC;CACH;AACF;;AAcA,MAAa,mBACX,QAAQ,IAAI,kCAAkC,UAC1CC,4CACA;CACE,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAChB,OAAO,MAAM,UAAU,eACvB,OAAO,KAAK,QAAQ;CAEtB,YACE,MACA,EACE,SACA,GAAG,WAEF;EACH,IAAI,QA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":"plugins.cjs","names":["editor","renderIntlayerNode","ContentSelector","fallbackPlugin","renderReactElement","splitInsertionTemplate","createElement","Fragment","NodeTypes","isInterpolableWrapperNode","transformInterpolableNode","resolveInsertedSelector","useLoadDynamic","getMarkdownMetadata","internationalization","translationPlugin","enumerationPlugin","pluralPlugin","conditionPlugin","nestedPlugin","filePlugin","genderPlugin","selectPlugin"],"sources":["../../src/plugins.tsx"],"sourcesContent":["import { editor, internationalization } from '@intlayer/config/built';\nimport {\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n fallbackPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n isInterpolableWrapperNode,\n nestedPlugin,\n type Plugins,\n pluralPlugin,\n resolveInsertedSelector,\n selectPlugin,\n splitInsertionTemplate,\n transformInterpolableNode,\n translationPlugin,\n} from '@intlayer/core/interpreter';\nimport { getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type {\n HTMLContent,\n InsertionContent,\n MarkdownContent,\n} from '@intlayer/core/transpiler';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport { createElement, type FC, Fragment, type ReactNode } from 'react';\nimport { reportExposure } from './analytics/exposureSink';\nimport { useLoadDynamic } from './client/useLoadDynamic';\nimport { ContentSelector } from './editor/ContentSelector';\nimport type { HTMLComponents } from './html/HTMLComponentTypes';\nimport { type IntlayerNode, renderIntlayerNode } from './IntlayerNode';\nimport { renderReactElement } from './reactElement/renderReactElement';\n\nconst markdownRendererModulePromise =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN !== 'false'\n ? import('./markdown/MarkdownRendererPlugin').then(\n (m) => m.MarkdownRendererPlugin\n )\n : null;\n\nconst htmlRendererModulePromise =\n process.env.INTLAYER_NODE_TYPE_HTML !== 'false'\n ? import('./html/HTMLRendererPlugin').then((m) => m.HTMLRendererPlugin)\n : null;\n\n// These preloads are read later by `useLoadDynamic`, so the rejection must stay\n// on the promise: a `.catch()` chained into it would resolve with `undefined`\n// and be mistaken for a loaded module. Handle it on the side instead, so an\n// aborted chunk load never escapes as an unhandled rejection.\nmarkdownRendererModulePromise?.catch(() => {});\nhtmlRendererModulePromise?.catch(() => {});\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const intlayerNodePlugins: Plugins = {\n id: 'intlayer-node-plugin',\n canHandle: (node) =>\n typeof node === 'bigint' ||\n typeof node === 'string' ||\n typeof node === 'number',\n transform: (_node, props) => {\n // Node-level analytics: record which content is resolved for display.\n // No-op (and dead-code-eliminated) when analytics is disabled.\n if (process.env.INTLAYER_ANALYTICS_ENABLED !== 'false') {\n reportExposure({\n dictionaryKey: props.dictionaryKey,\n keyPath: props.keyPath,\n locale: props.locale,\n nodeType: 'text',\n });\n }\n\n // Props are only forwarded to the editor selector: copying them for every\n // leaf would cost an allocation per rendered string\n if (process.env.INTLAYER_EDITOR_ENABLED !== 'false' && editor.enabled) {\n const {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n } = props;\n\n return renderIntlayerNode({\n value: rest.children,\n children: <ContentSelector {...rest}>{rest.children}</ContentSelector>,\n });\n }\n\n return renderIntlayerNode({\n value: props.children,\n children: props.children,\n });\n },\n};\n\n/** ---------------------------------------------\n * REACT NODE PLUGIN\n * --------------------------------------------- */\n\nexport type ReactNodeCond<T> = T extends {\n props: any;\n key: any;\n}\n ? ReactNode\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const reactNodePlugins: Plugins =\n process.env.INTLAYER_NODE_TYPE_REACT_NODE === 'false'\n ? fallbackPlugin\n : {\n id: 'react-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' &&\n typeof node?.props !== 'undefined' &&\n typeof node.key !== 'undefined',\n\n transform: (\n node,\n {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n }\n ) => {\n if (process.env.INTLAYER_ANALYTICS_ENABLED !== 'false') {\n reportExposure({\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n locale: rest.locale,\n nodeType: 'react-node',\n });\n }\n\n return renderIntlayerNode({\n ...rest,\n value: '[[react-element]]',\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n {renderReactElement(node)}\n </ContentSelector>\n ) : (\n renderReactElement(node)\n ),\n });\n },\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer I;\n fields: readonly string[];\n}\n ? <V extends { [K in T['fields'][number]]: ReactNode }>(\n values: V\n ) => I extends string\n ? V[keyof V] extends string | number\n ? IntlayerNode<string>\n : IntlayerNode<ReactNode>\n : DeepTransformContent<I>\n : never;\n\n/**\n * Split insertion string and join with React nodes using shared core logic\n */\nconst splitAndJoinInsertion = (\n template: string,\n values: Record<string, string | number | ReactNode>\n): ReactNode => {\n const result = splitInsertionTemplate(template, values);\n\n if (result.isSimple) {\n // Simple string replacement\n return result.parts as string;\n }\n\n // Return as Fragment with proper keys\n return createElement(\n Fragment,\n null,\n ...(result.parts as any[]).map((part, index) =>\n createElement(Fragment, { key: index }, part)\n )\n );\n};\n\n/** Insertion plugin for React. Handles component/node insertion. */\nexport const insertionPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_INSERTION === 'false'\n ? fallbackPlugin\n : {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.INSERTION,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.INSERTION,\n },\n ];\n\n const children = node[NodeTypes.INSERTION];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) =>\n typeof node === 'string' || isInterpolableWrapperNode(node),\n transform: (node, subProps, deepTransformNode) => {\n // `html()`/`markdown()` nodes carry their `{{ … }}` placeholders\n // inside a raw string. Interpolate into that string, then re-run\n // the transform so the html/markdown renderer applies afterwards.\n // React nodes cannot be injected into a raw markup string, so\n // string interpolation (not `splitAndJoinInsertion`) is used here.\n if (isInterpolableWrapperNode(node)) {\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) =>\n transformInterpolableNode(\n node,\n values,\n subProps,\n props.plugins,\n deepTransformNode\n );\n }\n\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]:\n | string\n | number\n | ReactNode;\n }\n ) => {\n const result = splitAndJoinInsertion(transformedResult, values);\n\n return deepTransformNode(result, {\n ...subProps,\n plugins: props.plugins,\n children: result,\n });\n };\n },\n };\n\n const result = deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n\n return resolveInsertedSelector(children, result);\n },\n };\n\n/**\n * MARKDOWN PLUGIN\n */\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<\n string,\n {\n metadata: DeepTransformContent<string>;\n use: (components: HTMLComponents<'permissive', {}>) => ReactNode;\n }\n >\n : never;\n\nconst MarkdownSuspenseRenderer: FC<Record<string, any>> = ({\n children,\n ...props\n}) => {\n const MarkdownRendererPlugin = useLoadDynamic(\n 'markdown-renderer-plugin',\n markdownRendererModulePromise!\n );\n return createElement(MarkdownRendererPlugin as any, { ...props, children });\n};\n\n/** Markdown string plugin. Replaces string node with a component that render the markdown. */\nexport const markdownStringPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, props, deepTransformNode) => {\n const {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n } = props;\n\n const metadata = getMarkdownMetadata(node) ?? {};\n\n const metadataPlugins: Plugins = {\n id: 'markdown-metadata-plugin',\n canHandle: (metadataNode) =>\n typeof metadataNode === 'string' ||\n typeof metadataNode === 'number' ||\n typeof metadataNode === 'boolean' ||\n !metadataNode,\n transform: (metadataNode, props) =>\n renderIntlayerNode({\n ...props,\n value: metadataNode,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>{node}</ContentSelector>\n ) : (\n node\n ),\n }),\n };\n\n // Transform metadata while keeping the same structure\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n const render = (components?: HTMLComponents) =>\n renderIntlayerNode({\n ...props,\n value: node,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n <MarkdownSuspenseRenderer {...rest} components={components}>\n {node}\n </MarkdownSuspenseRenderer>\n </ContentSelector>\n ) : (\n <MarkdownSuspenseRenderer {...rest} components={components}>\n {node}\n </MarkdownSuspenseRenderer>\n ),\n additionalProps: {\n metadata: metadataNodes,\n use: render,\n },\n });\n\n return render();\n },\n };\n\nexport type MarkdownCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.MARKDOWN]: infer M;\n tags?: infer U;\n metadata?: infer V;\n}\n ? IntlayerNode<\n M,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n metadata: DeepTransformContent<V>;\n }\n >\n : never;\n\nexport const markdownPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.MARKDOWN,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.MARKDOWN,\n },\n ];\n\n const children = node[NodeTypes.MARKDOWN];\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [markdownStringPlugin, ...(props.plugins ?? [])],\n });\n },\n };\n\n/** ---------------------------------------------\n * HTML PLUGIN\n * --------------------------------------------- */\n\n/**\n * HTML conditional type that enforces:\n * - All components (Standard or Custom) are OPTIONAL in the `use()` method.\n * - Custom components props are strictly inferred from the dictionary definition.\n *\n * This ensures type safety:\n * - `html('<div>Hello <CustomComponent /></div>').use({ CustomComponent: ... })` - optional but typed\n */\nexport type HTMLPluginCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.HTML]: infer I;\n tags?: infer U;\n}\n ? IntlayerNode<\n I,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n }\n >\n : never;\n\nconst HTMLSuspenseRenderer: FC<Record<string, any>> = (props) => {\n const HTMLRendererPlugin = useLoadDynamic(\n 'html-renderer-plugin',\n htmlRendererModulePromise!\n );\n return createElement(HTMLRendererPlugin as any, props);\n};\n\n/** HTML plugin. Replaces node with a function that takes components => ReactNode. */\nexport const htmlPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_HTML === 'false'\n ? fallbackPlugin\n : {\n id: 'html-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.HTML,\n\n transform: (node: HTMLContent<string>, props) => {\n const html = node[NodeTypes.HTML];\n const { plugins, ...rest } = props;\n\n // Type-safe render function that accepts properly typed components\n const render = (userComponents?: HTMLComponents): ReactNode =>\n renderIntlayerNode({\n ...rest,\n value: html,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n <HTMLSuspenseRenderer\n {...rest}\n html={html}\n userComponents={userComponents}\n />\n </ContentSelector>\n ) : (\n <HTMLSuspenseRenderer\n {...rest}\n html={html}\n userComponents={userComponents}\n />\n ),\n additionalProps: { use: render },\n });\n\n return render();\n },\n };\n\n/** ---------------------------------------------\n * PLUGINS RESULT\n * --------------------------------------------- */\n\nexport type IInterpreterPluginReact<T, _S, _L extends LocalesValues> = {\n reactNode: ReactNodeCond<T>;\n reactIntlayerNode: IntlayerNodeCond<T>;\n reactInsertion: InsertionCond<T>;\n reactMarkdown: MarkdownCond<T>;\n reactHtml: HTMLPluginCond<T>;\n};\n\n/**\n * Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.\n *\n * Otherwise the the `react-intlayer` plugins will override the types of `intlayer` functions.\n */\nexport type IInterpreterPluginState = Omit<\n IInterpreterPluginStateCore,\n 'insertion' // Remove insertion type from core package\n> & {\n reactNode: true;\n reactIntlayerNode: true;\n reactMarkdown: true;\n reactHtml: true;\n reactInsertion: true;\n};\n\nexport type DeepTransformContent<\n T,\n L extends LocalesValues = DeclaredLocales,\n> = DeepTransformContentCore<T, IInterpreterPluginState, L>;\n\nconst pluginsCache = new Map<string, Plugins[]>();\n\n/**\n * Get the plugins array for React content transformation.\n * This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.\n */\nexport const getPlugins = (\n locale?: LocalesValues,\n fallback: boolean = true\n): Plugins[] => {\n const currentLocale = locale ?? internationalization.defaultLocale;\n const cacheKey = `${currentLocale}_${fallback}`;\n\n if (pluginsCache.has(cacheKey)) {\n return pluginsCache.get(cacheKey)!;\n }\n\n const plugins = [\n // First: most nodes are plain strings, which every other plugin rejects\n intlayerNodePlugins,\n // Env var allows the bundler to to remove the plugin if not used to make the bundle smaller\n translationPlugin(\n locale ?? internationalization.defaultLocale,\n fallback ? internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n pluralPlugin(locale ?? internationalization.defaultLocale),\n conditionPlugin,\n nestedPlugin(locale ?? internationalization.defaultLocale),\n\n filePlugin,\n genderPlugin,\n selectPlugin,\n // Always include: handle React elements\n reactNodePlugins,\n insertionPlugin,\n markdownPlugin,\n htmlPlugin,\n ] as Plugins[];\n\n // Plugins disabled at build time never match: skip them on every node\n const enabledPlugins = plugins.filter((plugin) => plugin !== fallbackPlugin);\n\n pluginsCache.set(cacheKey, enabledPlugins);\n\n return enabledPlugins;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAwCA,MAAM,gCACJ,QAAQ,IAAI,gCAAgC,+CACxC,0CAA4C,MACzC,MAAM,EAAE,sBACX,IACA;AAEN,MAAM,4BACJ,QAAQ,IAAI,4BAA4B,+CACpC,kCAAoC,MAAM,MAAM,EAAE,kBAAkB,IACpE;AAMN,+BAA+B,YAAY,CAAC,CAAC;AAC7C,2BAA2B,YAAY,CAAC,CAAC;;AAWzC,MAAa,sBAA+B;CAC1C,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAChB,OAAO,SAAS,YAChB,OAAO,SAAS;CAClB,YAAY,OAAO,UAAU;EAG3B,IAAI,QAAQ,IAAI,+BAA+B,SAC7C,8CAAe;GACb,eAAe,MAAM;GACrB,SAAS,MAAM;GACf,QAAQ,MAAM;GACd,UAAU;EACZ,CAAC;EAKH,IAAI,QAAQ,IAAI,4BAA4B,WAAWA,8BAAO,SAAS;GACrE,MAAM,EACJ,SACA,GAAG,SACD;GAEJ,OAAOC,wCAAmB;IACxB,OAAO,KAAK;IACZ,UAAU,2CAACC,gDAAD;KAAiB,GAAI;eAAO,KAAK;IAA0B;GACvE,CAAC;EACH;EAEA,OAAOD,wCAAmB;GACxB,OAAO,MAAM;GACb,UAAU,MAAM;EAClB,CAAC;CACH;AACF;;AAcA,MAAa,mBACX,QAAQ,IAAI,kCAAkC,UAC1CE,4CACA;CACE,IAAI;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AChB;AACF;AAmCN,MAAM,+BAAe,IAAI,IAAuB;;;;;AAMhD,MAAa,cACX,QACA,WAAoB,SACN;CAEd,MAAM,WAAW,GADK,UAAUY,4CAAqB,cACnB,GAAG;CAErC,IAAI,aAAa,IAAI,QAAQ,GAC3B,OAAO,aAAa,IAAI,QAAQ;CA2BlC,MAAM,iBAAiB;EAtBrB;MAEAC,8CACE,UAAUD,4CAAqB,eAC/B,WAAWA,4CAAqB,gBAAgB,MAClD;EACAE;MACAC,yCAAa,UAAUH,4CAAqB,aAAa;EACzDI;MACAC,yCAAa,UAAUL,4CAAqB,aAAa;EAEzDM;EACAC;EACAC;EAEA;EACA;EACA;EACA;CAI2B,CAAC,CAAC,QAAQ,WAAW,WAAWnB,yCAAc;CAE3E,aAAa,IAAI,UAAU,cAAc;CAEzC,OAAO;AACT"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const
|
|
2
|
+
const require_server_format_usePercentage = require('./usePercentage.cjs');
|
|
3
3
|
const require_server_format_useUnit = require('./useUnit.cjs');
|
|
4
|
-
const require_server_format_useDate = require('./useDate.cjs');
|
|
5
4
|
const require_server_format_useCompact = require('./useCompact.cjs');
|
|
6
|
-
const require_server_format_useList = require('./useList.cjs');
|
|
7
5
|
const require_server_format_useNumber = require('./useNumber.cjs');
|
|
8
|
-
const
|
|
6
|
+
const require_server_format_useList = require('./useList.cjs');
|
|
7
|
+
const require_server_format_useCurrency = require('./useCurrency.cjs');
|
|
8
|
+
const require_server_format_useDate = require('./useDate.cjs');
|
|
9
9
|
const require_server_format_useRelativeTime = require('./useRelativeTime.cjs');
|
|
10
10
|
|
|
11
11
|
exports.useCompact = require_server_format_useCompact.useCompact;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_server_useLoadDynamic = require('./useLoadDynamic.cjs');
|
|
2
3
|
const require_server_serverContext = require('./serverContext.cjs');
|
|
3
4
|
const require_server_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
|
|
4
5
|
const require_server_useIntlayer = require('./useIntlayer.cjs');
|
|
6
|
+
const require_server_useDictionaryDynamic = require('./useDictionaryDynamic.cjs');
|
|
7
|
+
const require_server_useLocale = require('./useLocale.cjs');
|
|
5
8
|
const require_server_format_useIntl = require('./format/useIntl.cjs');
|
|
6
9
|
const require_server_t = require('./t.cjs');
|
|
7
10
|
const require_server_useDictionary = require('./useDictionary.cjs');
|
|
8
11
|
const require_server_useDictionaryAsync = require('./useDictionaryAsync.cjs');
|
|
9
|
-
const require_server_useLoadDynamic = require('./useLoadDynamic.cjs');
|
|
10
|
-
const require_server_useDictionaryDynamic = require('./useDictionaryDynamic.cjs');
|
|
11
12
|
const require_server_useI18n = require('./useI18n.cjs');
|
|
12
|
-
const require_server_useLocale = require('./useLocale.cjs');
|
|
13
13
|
|
|
14
14
|
exports.IntlayerServer = require_server_IntlayerServerProvider.IntlayerServerContext;
|
|
15
15
|
exports.IntlayerServerProvider = require_server_IntlayerServerProvider.IntlayerServerProvider;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_getDictionary = require('../getDictionary.cjs');
|
|
3
|
+
const require_server_useLoadDynamic = require('./useLoadDynamic.cjs');
|
|
3
4
|
const require_server_serverContext = require('./serverContext.cjs');
|
|
4
5
|
const require_server_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
|
|
5
|
-
const require_server_useLoadDynamic = require('./useLoadDynamic.cjs');
|
|
6
6
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
7
7
|
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
8
8
|
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import { isValidElement } from "react";
|
|
2
|
+
import { getIntlayerNodePrototype } from "@intlayer/core/utils";
|
|
2
3
|
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
3
4
|
|
|
4
5
|
//#region src/IntlayerNode.tsx
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
6
|
+
/**
|
|
7
|
+
* Renders content as a React element that also behaves like its value
|
|
8
|
+
* (`node.value`, `${node}`, `node.toUpperCase()`).
|
|
9
|
+
*
|
|
10
|
+
* The node is a copy of the element built on a shared prototype serving the
|
|
11
|
+
* value's members, rather than a Proxy: React reads an element's fields many
|
|
12
|
+
* times while reconciling, and a Proxy trap makes each read several times
|
|
13
|
+
* slower.
|
|
14
|
+
*
|
|
15
|
+
* @param props - The value, the rendered children and extra node members.
|
|
16
|
+
* @returns The renderable node.
|
|
17
|
+
*/
|
|
18
|
+
const renderIntlayerNode = ({ children, value, additionalProps }) => Object.setPrototypeOf({
|
|
19
|
+
...isValidElement(children) ? children : /* @__PURE__ */ jsx(Fragment$1, { children }),
|
|
20
|
+
value,
|
|
21
|
+
...additionalProps
|
|
22
|
+
}, getIntlayerNodePrototype(value));
|
|
23
23
|
|
|
24
24
|
//#endregion
|
|
25
25
|
export { renderIntlayerNode };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerNode.mjs","names":[],"sources":["../../src/IntlayerNode.tsx"],"sourcesContent":["import type { NodeProps } from '@intlayer/core/interpreter';\nimport type { ResolvedEditor } from '@intlayer/types/module_augmentation';\nimport {
|
|
1
|
+
{"version":3,"file":"IntlayerNode.mjs","names":[],"sources":["../../src/IntlayerNode.tsx"],"sourcesContent":["import type { NodeProps } from '@intlayer/core/interpreter';\nimport { getIntlayerNodePrototype } from '@intlayer/core/utils';\nimport type { ResolvedEditor } from '@intlayer/types/module_augmentation';\nimport { isValidElement, type PropsWithChildren, type ReactNode } from 'react';\n\nexport type IntlayerNode<\n T = NodeProps['children'],\n AdditionalProps = Record<string, never>,\n> = ResolvedEditor<T, ReactNode> & {\n value: T;\n} & AdditionalProps &\n T;\n\ntype RenderIntlayerNodeProps<T> = PropsWithChildren<{\n value: T;\n children: ReactNode;\n additionalProps?: { [key: string]: any };\n}>;\n\n/**\n * Renders content as a React element that also behaves like its value\n * (`node.value`, `${node}`, `node.toUpperCase()`).\n *\n * The node is a copy of the element built on a shared prototype serving the\n * value's members, rather than a Proxy: React reads an element's fields many\n * times while reconciling, and a Proxy trap makes each read several times\n * slower.\n *\n * @param props - The value, the rendered children and extra node members.\n * @returns The renderable node.\n */\nexport const renderIntlayerNode = <\n T, // Broadened to support arrays, numbers, objects, etc.\n>({\n children,\n value,\n additionalProps,\n}: RenderIntlayerNodeProps<T>): IntlayerNode<T> =>\n // Fields first, prototype last: set the other way round, each field would\n // first look for a setter along the prototype chain, through its Proxy\n Object.setPrototypeOf(\n {\n ...(isValidElement(children) ? children : <>{children}</>),\n value,\n ...additionalProps,\n },\n getIntlayerNodePrototype(value)\n );\n"],"mappings":";;;;;;;;;;;;;;;;;AA+BA,MAAa,sBAEX,EACA,UACA,OACA,sBAIA,OAAO,eACL;CACE,GAAI,eAAe,QAAQ,IAAI,WAAW,kCAAG,SAAW;CACxD;CACA,GAAG;AACL,GACA,yBAAyB,KAAK,CAChC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { IntlayerClientContext } from "../client/IntlayerProvider.mjs";
|
|
4
3
|
import { setExposureSink } from "./exposureSink.mjs";
|
|
5
|
-
import {
|
|
4
|
+
import { IntlayerClientContext } from "../client/IntlayerProvider.mjs";
|
|
6
5
|
import { useContext, useEffect, useRef } from "react";
|
|
6
|
+
import { isEnabled } from "@intlayer/analytics/isEnabled";
|
|
7
7
|
|
|
8
8
|
//#region src/analytics/useAnalytics.tsx
|
|
9
9
|
/**
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { EditorProvider } from "../editor/EditorProvider.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { getLocaleInStorage, setLocaleInStorage } from "./useLocaleStorage.mjs";
|
|
5
5
|
import { AnalyticsProvider } from "../analytics/AnalyticsProvider.mjs";
|
|
6
|
-
import { createContext, useContext, useEffect, useState } from "react";
|
|
7
6
|
import { internationalization } from "@intlayer/config/built";
|
|
7
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
9
|
import { setIntlayerIdentifier } from "@intlayer/config/client";
|
|
9
10
|
import { localeResolver } from "@intlayer/core/localization";
|
|
10
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
|
|
12
12
|
//#region src/client/IntlayerProvider.tsx
|
|
13
13
|
/**
|
|
14
14
|
* Context that stores the current locale on the client side.
|
|
15
15
|
*/
|
|
16
16
|
const IntlayerClientContext = createContext({
|
|
17
|
-
locale
|
|
17
|
+
get locale() {
|
|
18
|
+
return getLocaleInStorage() ?? internationalization?.defaultLocale;
|
|
19
|
+
},
|
|
18
20
|
setLocale: () => null,
|
|
19
21
|
isCookieEnabled: true
|
|
20
22
|
});
|
|
@@ -34,14 +36,16 @@ const useIntlayerContext = () => useContext(IntlayerClientContext) ?? {};
|
|
|
34
36
|
*/
|
|
35
37
|
const IntlayerProviderContent = ({ locale: localeProp, defaultLocale: defaultLocaleProp, variant, children, setLocale: setLocaleProp, disableEditor, isCookieEnabled }) => {
|
|
36
38
|
const { locales: availableLocales, defaultLocale: defaultLocaleConfig } = internationalization ?? {};
|
|
37
|
-
const [currentLocale, setCurrentLocale] = useState(localeProp ??
|
|
38
|
-
|
|
39
|
+
const [currentLocale, setCurrentLocale] = useState(() => localeProp ?? getLocaleInStorage() ?? defaultLocaleProp ?? defaultLocaleConfig);
|
|
40
|
+
const [adoptedLocaleProp, setAdoptedLocaleProp] = useState(localeProp);
|
|
41
|
+
if (localeProp !== adoptedLocaleProp) {
|
|
42
|
+
setAdoptedLocaleProp(localeProp);
|
|
39
43
|
if (localeProp && localeProp !== currentLocale) setCurrentLocale(localeProp);
|
|
40
|
-
}
|
|
44
|
+
}
|
|
41
45
|
useEffect(() => {
|
|
42
46
|
setIntlayerIdentifier();
|
|
43
47
|
}, []);
|
|
44
|
-
const setLocaleBase = (newLocale) => {
|
|
48
|
+
const setLocaleBase = useCallback((newLocale) => {
|
|
45
49
|
if (currentLocale.toString() === newLocale.toString()) return;
|
|
46
50
|
if (!availableLocales?.map(String).includes(newLocale)) {
|
|
47
51
|
console.error(`Locale ${newLocale} is not available`);
|
|
@@ -49,16 +53,26 @@ const IntlayerProviderContent = ({ locale: localeProp, defaultLocale: defaultLoc
|
|
|
49
53
|
}
|
|
50
54
|
setCurrentLocale(newLocale);
|
|
51
55
|
setLocaleInStorage(newLocale, isCookieEnabled);
|
|
52
|
-
}
|
|
56
|
+
}, [
|
|
57
|
+
currentLocale,
|
|
58
|
+
availableLocales,
|
|
59
|
+
isCookieEnabled
|
|
60
|
+
]);
|
|
53
61
|
const setLocale = setLocaleProp ?? setLocaleBase;
|
|
54
62
|
const resolvedLocale = localeResolver(currentLocale);
|
|
63
|
+
const contextValue = useMemo(() => ({
|
|
64
|
+
locale: resolvedLocale,
|
|
65
|
+
setLocale,
|
|
66
|
+
variant,
|
|
67
|
+
disableEditor
|
|
68
|
+
}), [
|
|
69
|
+
resolvedLocale,
|
|
70
|
+
setLocale,
|
|
71
|
+
variant,
|
|
72
|
+
disableEditor
|
|
73
|
+
]);
|
|
55
74
|
return /* @__PURE__ */ jsx(IntlayerClientContext.Provider, {
|
|
56
|
-
value:
|
|
57
|
-
locale: resolvedLocale,
|
|
58
|
-
setLocale,
|
|
59
|
-
variant,
|
|
60
|
-
disableEditor
|
|
61
|
-
},
|
|
75
|
+
value: contextValue,
|
|
62
76
|
children
|
|
63
77
|
});
|
|
64
78
|
};
|
|
@@ -85,8 +99,8 @@ const IntlayerProviderContent = ({ locale: localeProp, defaultLocale: defaultLoc
|
|
|
85
99
|
const IntlayerProvider = ({ children, ...props }) => /* @__PURE__ */ jsxs(IntlayerProviderContent, {
|
|
86
100
|
...props,
|
|
87
101
|
children: [
|
|
88
|
-
/* @__PURE__ */ jsx(EditorProvider, {}),
|
|
89
|
-
/* @__PURE__ */ jsx(AnalyticsProvider, {}),
|
|
102
|
+
process.env.INTLAYER_EDITOR_ENABLED !== "false" && /* @__PURE__ */ jsx(EditorProvider, {}),
|
|
103
|
+
process.env.INTLAYER_ANALYTICS_ENABLED !== "false" && /* @__PURE__ */ jsx(AnalyticsProvider, {}),
|
|
90
104
|
children
|
|
91
105
|
]
|
|
92
106
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerProvider.mjs","names":[],"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport { internationalization } from '@intlayer/config/built';\nimport { setIntlayerIdentifier } from '@intlayer/config/client';\nimport { localeResolver } from '@intlayer/core/localization';\nimport type {\n LocalesValues,\n ProviderVariant,\n} from '@intlayer/types/module_augmentation';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n useEffect,\n useState,\n} from 'react';\nimport { AnalyticsProvider } from '../analytics/AnalyticsProvider';\nimport { EditorProvider } from '../editor/EditorProvider';\nimport {
|
|
1
|
+
{"version":3,"file":"IntlayerProvider.mjs","names":[],"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport { internationalization } from '@intlayer/config/built';\nimport { setIntlayerIdentifier } from '@intlayer/config/client';\nimport { localeResolver } from '@intlayer/core/localization';\nimport type {\n LocalesValues,\n ProviderVariant,\n} from '@intlayer/types/module_augmentation';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from 'react';\nimport { AnalyticsProvider } from '../analytics/AnalyticsProvider';\nimport { EditorProvider } from '../editor/EditorProvider';\nimport { getLocaleInStorage, setLocaleInStorage } from './useLocaleStorage';\n\ntype IntlayerValue = {\n locale: LocalesValues;\n setLocale: (newLocale: LocalesValues) => void;\n /**\n * Ambient variant applied to every dictionary read below the provider, the\n * same way `locale` is. Overridden per call by an explicit selector.\n */\n variant?: ProviderVariant;\n disableEditor?: boolean;\n isCookieEnabled?: boolean;\n};\n\n/**\n * Context that stores the current locale on the client side.\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n // Read on demand: only a tree rendered without a provider needs it\n get locale() {\n return getLocaleInStorage() ?? internationalization?.defaultLocale;\n },\n setLocale: () => null,\n isCookieEnabled: true,\n});\n\n/**\n * Hook that provides the current Intlayer client context.\n *\n * @returns The current Intlayer context values.\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext) ?? {};\n\n/**\n * Props for the IntlayerProvider component.\n */\nexport type IntlayerProviderProps = PropsWithChildren<{\n /**\n * The locale to use. If not provided, it will be detected from storage or configuration.\n */\n locale?: LocalesValues;\n /**\n * Ambient variant applied to every dictionary read below this provider — for\n * a dimension that is fixed for the whole session (tenant, school type, plan\n * tier…) and that therefore no component should have to pass by hand.\n *\n * Accepts three forms:\n * - `variant=\"school1\"` — one named variant for every key\n * - `variant={['school1', 'default']}` — an ordered preference chain: the\n * first variant the key actually declares wins\n * - `variant={{ key1: 'school1', key2: ['school1', 'default'], default: 'base' }}`\n * — per dictionary key, with `default` covering every key not listed\n *\n * A plain object is always read as the per-key map. To pin a structured\n * variant globally, nest it: `variant={{ default: { id: 'prod_abc' } }}`.\n *\n * A call-site selector always wins: `useIntlayer('key', { variant: 'x' })`\n * replaces this default rather than extending it.\n */\n variant?: ProviderVariant;\n /**\n * The default locale to use as a fallback.\n */\n defaultLocale?: LocalesValues;\n /**\n * Function to set the locale.\n */\n setLocale?: (locale: LocalesValues) => void;\n /**\n * Whether to disable the editor.\n */\n disableEditor?: boolean;\n /**\n * Whether to enable cookies for storing the locale.\n */\n isCookieEnabled?: boolean;\n}>;\n\n/**\n * Provider that stores the current locale on the client side.\n *\n * This component is focused on content delivery without the editor features.\n *\n * @param props - The provider props.\n * @returns The provider component.\n */\nexport const IntlayerProviderContent: FC<IntlayerProviderProps> = ({\n locale: localeProp,\n defaultLocale: defaultLocaleProp,\n variant,\n children,\n setLocale: setLocaleProp,\n disableEditor,\n isCookieEnabled,\n}) => {\n const { locales: availableLocales, defaultLocale: defaultLocaleConfig } =\n internationalization ?? {};\n\n // Storage is only read when no locale is passed, and only on mount\n const [currentLocale, setCurrentLocale] = useState<LocalesValues>(\n () =>\n localeProp ??\n getLocaleInStorage() ??\n defaultLocaleProp ??\n defaultLocaleConfig\n );\n const [adoptedLocaleProp, setAdoptedLocaleProp] = useState(localeProp);\n\n // Adopt a new `locale` prop during render rather than in an effect: an\n // effect commits the whole subtree once with the stale locale, then renders\n // it again with the new one.\n if (localeProp !== adoptedLocaleProp) {\n setAdoptedLocaleProp(localeProp);\n\n if (localeProp && localeProp !== currentLocale) {\n setCurrentLocale(localeProp);\n }\n }\n\n useEffect(() => {\n setIntlayerIdentifier();\n }, []);\n\n const setLocaleBase = useCallback(\n (newLocale: LocalesValues) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales?.map(String).includes(newLocale)) {\n console.error(`Locale ${newLocale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale);\n setLocaleInStorage(newLocale, isCookieEnabled);\n },\n [currentLocale, availableLocales, isCookieEnabled]\n );\n\n const setLocale = setLocaleProp ?? setLocaleBase;\n\n // Resolve based on currentLocale (the state), not the prop directly\n const resolvedLocale = localeResolver(currentLocale);\n\n // Stable value so a parent re-render does not re-render every consumer\n const contextValue = useMemo<IntlayerValue>(\n () => ({\n locale: resolvedLocale,\n setLocale,\n variant,\n disableEditor,\n }),\n [resolvedLocale, setLocale, variant, disableEditor]\n );\n\n return (\n <IntlayerClientContext.Provider value={contextValue}>\n {children}\n </IntlayerClientContext.Provider>\n );\n};\n\n/**\n * Main provider for Intlayer in React applications.\n *\n * It includes the editor provider by default, allowing for live content editing\n * if configured.\n *\n * @param props - The provider props.\n * @returns The provider component with editor support.\n *\n * @example\n * ```tsx\n * import { IntlayerProvider } from 'react-intlayer';\n *\n * const App = () => (\n * <IntlayerProvider>\n * <MyComponent />\n * </IntlayerProvider>\n * );\n * ```\n */\nexport const IntlayerProvider: FC<IntlayerProviderProps> = ({\n children,\n ...props\n}) => (\n <IntlayerProviderContent {...props}>\n {/* Build flags drop these, and their modules, when the feature is off */}\n {process.env.INTLAYER_EDITOR_ENABLED !== 'false' && <EditorProvider />}\n {process.env.INTLAYER_ANALYTICS_ENABLED !== 'false' && (\n <AnalyticsProvider />\n )}\n {children}\n </IntlayerProviderContent>\n);\n"],"mappings":";;;;;;;;;;;;;;;AAsCA,MAAa,wBAAwB,cAA6B;CAEhE,IAAI,SAAS;EACX,OAAO,mBAAmB,KAAK,sBAAsB;CACvD;CACA,iBAAiB;CACjB,iBAAiB;AACnB,CAAC;;;;;;AAOD,MAAa,2BAA2B,WAAW,qBAAqB,KAAK,CAAC;;;;;;;;;AAuD9E,MAAa,2BAAsD,EACjE,QAAQ,YACR,eAAe,mBACf,SACA,UACA,WAAW,eACX,eACA,sBACI;CACJ,MAAM,EAAE,SAAS,kBAAkB,eAAe,wBAChD,wBAAwB,CAAC;CAG3B,MAAM,CAAC,eAAe,oBAAoB,eAEtC,cACA,mBAAmB,KACnB,qBACA,mBACJ;CACA,MAAM,CAAC,mBAAmB,wBAAwB,SAAS,UAAU;CAKrE,IAAI,eAAe,mBAAmB;EACpC,qBAAqB,UAAU;EAE/B,IAAI,cAAc,eAAe,eAC/B,iBAAiB,UAAU;CAE/B;CAEA,gBAAgB;EACd,sBAAsB;CACxB,GAAG,CAAC,CAAC;CAEL,MAAM,gBAAgB,aACnB,cAA6B;EAC5B,IAAI,cAAc,SAAS,MAAM,UAAU,SAAS,GAAG;EAEvD,IAAI,CAAC,kBAAkB,IAAI,MAAM,CAAC,CAAC,SAAS,SAAS,GAAG;GACtD,QAAQ,MAAM,UAAU,UAAU,kBAAkB;GACpD;EACF;EAEA,iBAAiB,SAAS;EAC1B,mBAAmB,WAAW,eAAe;CAC/C,GACA;EAAC;EAAe;EAAkB;CAAe,CACnD;CAEA,MAAM,YAAY,iBAAiB;CAGnC,MAAM,iBAAiB,eAAe,aAAa;CAGnD,MAAM,eAAe,eACZ;EACL,QAAQ;EACR;EACA;EACA;CACF,IACA;EAAC;EAAgB;EAAW;EAAS;CAAa,CACpD;CAEA,OACE,oBAAC,sBAAsB,UAAvB;EAAgC,OAAO;EACpC;CAC6B;AAEpC;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,oBAA+C,EAC1D,UACA,GAAG,YAEH,qBAAC,yBAAD;CAAyB,GAAI;WAA7B;EAEG,QAAQ,IAAI,4BAA4B,WAAW,oBAAC,gBAAD,CAAiB;EACpE,QAAQ,IAAI,+BAA+B,WAC1C,oBAAC,mBAAD,CAAoB;EAErB;CACsB"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { useIntl } from "./useIntl.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { usePercentage } from "./usePercentage.mjs";
|
|
3
3
|
import { useUnit } from "./useUnit.mjs";
|
|
4
|
-
import { useDate } from "./useDate.mjs";
|
|
5
4
|
import { useCompact } from "./useCompact.mjs";
|
|
6
|
-
import { useList } from "./useList.mjs";
|
|
7
5
|
import { useNumber } from "./useNumber.mjs";
|
|
8
|
-
import {
|
|
6
|
+
import { useList } from "./useList.mjs";
|
|
7
|
+
import { useCurrency } from "./useCurrency.mjs";
|
|
8
|
+
import { useDate } from "./useDate.mjs";
|
|
9
9
|
import { useRelativeTime } from "./useRelativeTime.mjs";
|
|
10
10
|
|
|
11
11
|
export { useCompact, useCurrency, useDate, useIntl, useList, useNumber, usePercentage, useRelativeTime, useUnit };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { useLoadDynamic } from "./useLoadDynamic.mjs";
|
|
1
2
|
import { localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage } from "./useLocaleStorage.mjs";
|
|
2
3
|
import { IntlayerClientContext, IntlayerProvider, IntlayerProviderContent, useIntlayerContext } from "./IntlayerProvider.mjs";
|
|
3
4
|
import { t } from "./t.mjs";
|
|
4
|
-
import { useLoadDynamic } from "./useLoadDynamic.mjs";
|
|
5
5
|
import { useDictionary } from "./useDictionary.mjs";
|
|
6
6
|
import { useDictionaryAsync } from "./useDictionaryAsync.mjs";
|
|
7
7
|
import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
|
|
@@ -9,7 +9,7 @@ import { useI18n } from "./useI18n.mjs";
|
|
|
9
9
|
import { useIntlayer } from "./useIntlayer.mjs";
|
|
10
10
|
import { useLocale } from "./useLocale.mjs";
|
|
11
11
|
import { useLocaleBase } from "./useLocaleBase.mjs";
|
|
12
|
-
import { useRewriteURL } from "./useRewriteURL.mjs";
|
|
13
12
|
import { usePathname } from "./usePathname.mjs";
|
|
13
|
+
import { useRewriteURL } from "./useRewriteURL.mjs";
|
|
14
14
|
|
|
15
15
|
export { IntlayerClientContext, IntlayerProvider, IntlayerProviderContent, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useI18n, useIntlayer, useIntlayerContext, useLoadDynamic, useLocale, useLocaleBase, useLocaleCookie, useLocaleStorage, usePathname, useRewriteURL };
|
package/dist/esm/client/t.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
4
3
|
import { getDictionary } from "../getDictionary.mjs";
|
|
4
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
5
5
|
import { useContext, useMemo } from "react";
|
|
6
6
|
import { getDictionarySelectorCacheKey, resolveDictionaryArgument } from "@intlayer/core/dictionaryManipulator";
|
|
7
7
|
|
|
@@ -22,7 +22,7 @@ const useDictionary = (dictionary, localeOrSelector) => {
|
|
|
22
22
|
contextVariant,
|
|
23
23
|
dictionaryKey: dictionary.key
|
|
24
24
|
}) : localeOrSelector ?? currentLocale;
|
|
25
|
-
const argumentIdentity = typeof argument === "object" && argument !== null ? `${argument.locale ?? ""}|${getDictionarySelectorCacheKey(argument)}` : argument;
|
|
25
|
+
const argumentIdentity = process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && typeof argument === "object" && argument !== null ? `${argument.locale ?? ""}|${getDictionarySelectorCacheKey(argument)}` : argument;
|
|
26
26
|
return useMemo(() => getDictionary(dictionary, argument), [dictionary.key, argumentIdentity]);
|
|
27
27
|
};
|
|
28
28
|
|