react-intlayer 9.0.0-canary.9 → 9.0.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/IntlayerNode.cjs +1 -2
- package/dist/cjs/IntlayerNode.cjs.map +1 -1
- package/dist/cjs/UI/ContentSelector.cjs +0 -1
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
- package/dist/cjs/analytics/AnalyticsProvider.cjs +16 -0
- package/dist/cjs/analytics/AnalyticsProvider.cjs.map +1 -0
- package/dist/cjs/analytics/exposureSink.cjs +27 -0
- package/dist/cjs/analytics/exposureSink.cjs.map +1 -0
- package/dist/cjs/analytics/index.cjs +10 -0
- package/dist/cjs/analytics/useAnalytics.cjs +54 -0
- package/dist/cjs/analytics/useAnalytics.cjs.map +1 -0
- package/dist/cjs/analytics/useConversion.cjs +32 -0
- package/dist/cjs/analytics/useConversion.cjs.map +1 -0
- package/dist/cjs/analytics/useExperiment.cjs +65 -0
- package/dist/cjs/analytics/useExperiment.cjs.map +1 -0
- package/dist/cjs/client/IntlayerProvider.cjs +6 -2
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/format/useCompact.cjs +0 -1
- package/dist/cjs/client/format/useCompact.cjs.map +1 -1
- package/dist/cjs/client/format/useCurrency.cjs +0 -1
- package/dist/cjs/client/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/client/format/useDate.cjs +0 -1
- package/dist/cjs/client/format/useDate.cjs.map +1 -1
- package/dist/cjs/client/format/useIntl.cjs +0 -1
- package/dist/cjs/client/format/useIntl.cjs.map +1 -1
- package/dist/cjs/client/format/useList.cjs +0 -1
- package/dist/cjs/client/format/useList.cjs.map +1 -1
- package/dist/cjs/client/format/useNumber.cjs +0 -1
- package/dist/cjs/client/format/useNumber.cjs.map +1 -1
- package/dist/cjs/client/format/usePercentage.cjs +0 -1
- package/dist/cjs/client/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/client/format/useRelativeTime.cjs +0 -1
- package/dist/cjs/client/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/client/format/useUnit.cjs +0 -1
- package/dist/cjs/client/format/useUnit.cjs.map +1 -1
- package/dist/cjs/client/t.cjs +0 -1
- package/dist/cjs/client/t.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +0 -1
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +0 -1
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +0 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useI18n.cjs +0 -1
- package/dist/cjs/client/useI18n.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +0 -1
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLoadDynamic.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +0 -1
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleBase.cjs +0 -1
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +0 -1
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
- package/dist/cjs/client/usePathname.cjs +0 -1
- package/dist/cjs/client/usePathname.cjs.map +1 -1
- package/dist/cjs/client/useRewriteURL.cjs +0 -1
- package/dist/cjs/client/useRewriteURL.cjs.map +1 -1
- package/dist/cjs/client/useTraduction.cjs +0 -1
- package/dist/cjs/client/useTraduction.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelector.cjs +0 -1
- package/dist/cjs/editor/ContentSelector.cjs.map +1 -1
- package/dist/cjs/editor/EditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/useEditor.cjs +0 -1
- package/dist/cjs/editor/useEditor.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs +0 -1
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +0 -1
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/html/HTMLProvider.cjs +0 -1
- package/dist/cjs/html/HTMLProvider.cjs.map +1 -1
- package/dist/cjs/html/HTMLRenderer.cjs +0 -1
- package/dist/cjs/html/HTMLRenderer.cjs.map +1 -1
- package/dist/cjs/html/HTMLRendererPlugin.cjs.map +1 -1
- package/dist/cjs/index.cjs +8 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownProvider.cjs +0 -1
- package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs +0 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs.map +1 -1
- package/dist/cjs/markdown/processor.cjs +0 -1
- package/dist/cjs/markdown/processor.cjs.map +1 -1
- package/dist/cjs/markdown/runtime.cjs +0 -1
- package/dist/cjs/markdown/runtime.cjs.map +1 -1
- package/dist/cjs/plugins.cjs +33 -15
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/reactElement/renderReactElement.cjs +0 -1
- package/dist/cjs/reactElement/renderReactElement.cjs.map +1 -1
- package/dist/cjs/server/IntlayerServerProvider.cjs +0 -1
- package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
- package/dist/cjs/server/format/useCompact.cjs +0 -1
- package/dist/cjs/server/format/useCompact.cjs.map +1 -1
- package/dist/cjs/server/format/useCurrency.cjs +0 -1
- package/dist/cjs/server/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/server/format/useDate.cjs +0 -1
- package/dist/cjs/server/format/useDate.cjs.map +1 -1
- package/dist/cjs/server/format/useIntl.cjs +0 -1
- package/dist/cjs/server/format/useIntl.cjs.map +1 -1
- package/dist/cjs/server/format/useList.cjs +0 -1
- package/dist/cjs/server/format/useList.cjs.map +1 -1
- package/dist/cjs/server/format/useNumber.cjs +0 -1
- package/dist/cjs/server/format/useNumber.cjs.map +1 -1
- package/dist/cjs/server/format/usePercentage.cjs +0 -1
- package/dist/cjs/server/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/server/format/useRelativeTime.cjs +0 -1
- package/dist/cjs/server/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/server/format/useUnit.cjs +0 -1
- package/dist/cjs/server/format/useUnit.cjs.map +1 -1
- package/dist/cjs/server/serverContext.cjs.map +1 -1
- package/dist/cjs/server/t.cjs +0 -1
- package/dist/cjs/server/t.cjs.map +1 -1
- package/dist/cjs/server/useDictionary.cjs.map +1 -1
- package/dist/cjs/server/useDictionaryAsync.cjs +0 -1
- package/dist/cjs/server/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/server/useDictionaryDynamic.cjs +0 -1
- package/dist/cjs/server/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/server/useI18n.cjs.map +1 -1
- package/dist/cjs/server/useIntlayer.cjs.map +1 -1
- package/dist/cjs/server/useLoadDynamic.cjs.map +1 -1
- package/dist/cjs/server/useLocale.cjs +0 -1
- package/dist/cjs/server/useLocale.cjs.map +1 -1
- package/dist/esm/IntlayerNode.mjs +1 -1
- package/dist/esm/IntlayerNode.mjs.map +1 -1
- package/dist/esm/UI/ContentSelector.mjs.map +1 -1
- package/dist/esm/analytics/AnalyticsProvider.mjs +15 -0
- package/dist/esm/analytics/AnalyticsProvider.mjs.map +1 -0
- package/dist/esm/analytics/exposureSink.mjs +24 -0
- package/dist/esm/analytics/exposureSink.mjs.map +1 -0
- package/dist/esm/analytics/index.mjs +6 -0
- package/dist/esm/analytics/useAnalytics.mjs +53 -0
- package/dist/esm/analytics/useAnalytics.mjs.map +1 -0
- package/dist/esm/analytics/useConversion.mjs +31 -0
- package/dist/esm/analytics/useConversion.mjs.map +1 -0
- package/dist/esm/analytics/useExperiment.mjs +64 -0
- package/dist/esm/analytics/useExperiment.mjs.map +1 -0
- package/dist/esm/client/IntlayerProvider.mjs +6 -1
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/format/useCompact.mjs.map +1 -1
- package/dist/esm/client/format/useCurrency.mjs.map +1 -1
- package/dist/esm/client/format/useDate.mjs.map +1 -1
- package/dist/esm/client/format/useIntl.mjs.map +1 -1
- package/dist/esm/client/format/useList.mjs.map +1 -1
- package/dist/esm/client/format/useNumber.mjs.map +1 -1
- package/dist/esm/client/format/usePercentage.mjs.map +1 -1
- package/dist/esm/client/format/useRelativeTime.mjs.map +1 -1
- package/dist/esm/client/format/useUnit.mjs.map +1 -1
- package/dist/esm/client/t.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useI18n.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLoadDynamic.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleBase.mjs.map +1 -1
- package/dist/esm/client/useLocaleStorage.mjs.map +1 -1
- package/dist/esm/client/usePathname.mjs.map +1 -1
- package/dist/esm/client/useRewriteURL.mjs.map +1 -1
- package/dist/esm/client/useTraduction.mjs.map +1 -1
- package/dist/esm/editor/ContentSelector.mjs.map +1 -1
- package/dist/esm/editor/EditorProvider.mjs.map +1 -1
- package/dist/esm/editor/useEditor.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/esm/html/HTMLProvider.mjs.map +1 -1
- package/dist/esm/html/HTMLRenderer.mjs.map +1 -1
- package/dist/esm/html/HTMLRendererPlugin.mjs.map +1 -1
- package/dist/esm/index.mjs +5 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs.map +1 -1
- package/dist/esm/markdown/processor.mjs.map +1 -1
- package/dist/esm/markdown/runtime.mjs.map +1 -1
- package/dist/esm/plugins.mjs +34 -16
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/reactElement/renderReactElement.mjs.map +1 -1
- package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
- package/dist/esm/server/format/useCompact.mjs.map +1 -1
- package/dist/esm/server/format/useCurrency.mjs.map +1 -1
- package/dist/esm/server/format/useDate.mjs.map +1 -1
- package/dist/esm/server/format/useIntl.mjs.map +1 -1
- package/dist/esm/server/format/useList.mjs.map +1 -1
- package/dist/esm/server/format/useNumber.mjs.map +1 -1
- package/dist/esm/server/format/usePercentage.mjs.map +1 -1
- package/dist/esm/server/format/useRelativeTime.mjs.map +1 -1
- package/dist/esm/server/format/useUnit.mjs.map +1 -1
- package/dist/esm/server/serverContext.mjs.map +1 -1
- package/dist/esm/server/t.mjs.map +1 -1
- package/dist/esm/server/useDictionary.mjs.map +1 -1
- package/dist/esm/server/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/server/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/server/useI18n.mjs.map +1 -1
- package/dist/esm/server/useIntlayer.mjs.map +1 -1
- package/dist/esm/server/useLoadDynamic.mjs.map +1 -1
- package/dist/esm/server/useLocale.mjs.map +1 -1
- package/dist/types/IntlayerNode.d.ts +1 -6
- package/dist/types/IntlayerNode.d.ts.map +1 -1
- package/dist/types/UI/ContentSelector.d.ts +0 -1
- package/dist/types/UI/ContentSelector.d.ts.map +1 -1
- package/dist/types/analytics/AnalyticsProvider.d.ts +10 -0
- package/dist/types/analytics/AnalyticsProvider.d.ts.map +1 -0
- package/dist/types/analytics/exposureSink.d.ts +32 -0
- package/dist/types/analytics/exposureSink.d.ts.map +1 -0
- package/dist/types/analytics/index.d.ts +5 -0
- package/dist/types/analytics/useAnalytics.d.ts +15 -0
- package/dist/types/analytics/useAnalytics.d.ts.map +1 -0
- package/dist/types/analytics/useConversion.d.ts +31 -0
- package/dist/types/analytics/useConversion.d.ts.map +1 -0
- package/dist/types/analytics/useExperiment.d.ts +41 -0
- package/dist/types/analytics/useExperiment.d.ts.map +1 -0
- package/dist/types/client/IntlayerProvider.d.ts +1 -3
- package/dist/types/client/IntlayerProvider.d.ts.map +1 -1
- package/dist/types/client/format/useCompact.d.ts +1 -3
- package/dist/types/client/format/useCompact.d.ts.map +1 -1
- package/dist/types/client/format/useCurrency.d.ts +1 -3
- package/dist/types/client/format/useCurrency.d.ts.map +1 -1
- package/dist/types/client/format/useDate.d.ts +0 -1
- package/dist/types/client/format/useDate.d.ts.map +1 -1
- package/dist/types/client/format/useIntl.d.ts +0 -1
- package/dist/types/client/format/useIntl.d.ts.map +1 -1
- package/dist/types/client/format/useList.d.ts +4 -6
- package/dist/types/client/format/useList.d.ts.map +1 -1
- package/dist/types/client/format/useNumber.d.ts +1 -3
- package/dist/types/client/format/useNumber.d.ts.map +1 -1
- package/dist/types/client/format/usePercentage.d.ts +1 -3
- package/dist/types/client/format/usePercentage.d.ts.map +1 -1
- package/dist/types/client/format/useRelativeTime.d.ts +1 -3
- package/dist/types/client/format/useRelativeTime.d.ts.map +1 -1
- package/dist/types/client/format/useUnit.d.ts +1 -3
- package/dist/types/client/format/useUnit.d.ts.map +1 -1
- package/dist/types/client/t.d.ts +0 -1
- package/dist/types/client/t.d.ts.map +1 -1
- package/dist/types/client/useDictionary.d.ts +2 -5
- package/dist/types/client/useDictionary.d.ts.map +1 -1
- package/dist/types/client/useDictionaryAsync.d.ts +0 -1
- package/dist/types/client/useDictionaryAsync.d.ts.map +1 -1
- package/dist/types/client/useDictionaryDynamic.d.ts +0 -1
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/client/useI18n.d.ts +0 -1
- package/dist/types/client/useI18n.d.ts.map +1 -1
- package/dist/types/client/useIntlayer.d.ts +2 -5
- package/dist/types/client/useIntlayer.d.ts.map +1 -1
- package/dist/types/client/useLoadDynamic.d.ts.map +1 -1
- package/dist/types/client/useLocale.d.ts +1 -5
- package/dist/types/client/useLocale.d.ts.map +1 -1
- package/dist/types/client/useLocaleBase.d.ts +2 -4
- package/dist/types/client/useLocaleBase.d.ts.map +1 -1
- package/dist/types/client/useLocaleStorage.d.ts +5 -10
- package/dist/types/client/useLocaleStorage.d.ts.map +1 -1
- package/dist/types/client/usePathname.d.ts.map +1 -1
- package/dist/types/client/useRewriteURL.d.ts.map +1 -1
- package/dist/types/client/useTraduction.d.ts +0 -1
- package/dist/types/client/useTraduction.d.ts.map +1 -1
- package/dist/types/editor/ContentSelector.d.ts +0 -1
- package/dist/types/editor/ContentSelector.d.ts.map +1 -1
- package/dist/types/editor/EditorProvider.d.ts +0 -1
- package/dist/types/editor/EditorProvider.d.ts.map +1 -1
- package/dist/types/editor/useEditor.d.ts.map +1 -1
- package/dist/types/getDictionary.d.ts +0 -1
- package/dist/types/getDictionary.d.ts.map +1 -1
- package/dist/types/getIntlayer.d.ts +0 -1
- package/dist/types/getIntlayer.d.ts.map +1 -1
- package/dist/types/html/HTMLComponentTypes.d.ts +8 -9
- package/dist/types/html/HTMLComponentTypes.d.ts.map +1 -1
- package/dist/types/html/HTMLProvider.d.ts +0 -1
- package/dist/types/html/HTMLProvider.d.ts.map +1 -1
- package/dist/types/html/HTMLRenderer.d.ts +2 -7
- package/dist/types/html/HTMLRenderer.d.ts.map +1 -1
- package/dist/types/html/HTMLRendererPlugin.d.ts +0 -1
- package/dist/types/html/HTMLRendererPlugin.d.ts.map +1 -1
- package/dist/types/html/types.d.ts +0 -1
- package/dist/types/html/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +18 -35
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/markdown/MarkdownProvider.d.ts +7 -4
- package/dist/types/markdown/MarkdownProvider.d.ts.map +1 -1
- package/dist/types/markdown/MarkdownRenderer.d.ts +2 -17
- package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -1
- package/dist/types/markdown/MarkdownRendererPlugin.d.ts +0 -1
- package/dist/types/markdown/MarkdownRendererPlugin.d.ts.map +1 -1
- package/dist/types/markdown/processor.d.ts +0 -1
- package/dist/types/markdown/processor.d.ts.map +1 -1
- package/dist/types/markdown/runtime.d.ts +0 -1
- package/dist/types/markdown/runtime.d.ts.map +1 -1
- package/dist/types/plugins.d.ts +1 -2
- package/dist/types/plugins.d.ts.map +1 -1
- package/dist/types/reactElement/renderReactElement.d.ts +0 -1
- package/dist/types/reactElement/renderReactElement.d.ts.map +1 -1
- package/dist/types/server/IntlayerServerProvider.d.ts +1 -3
- package/dist/types/server/IntlayerServerProvider.d.ts.map +1 -1
- package/dist/types/server/format/useCompact.d.ts +0 -1
- package/dist/types/server/format/useCompact.d.ts.map +1 -1
- package/dist/types/server/format/useCurrency.d.ts +0 -1
- package/dist/types/server/format/useCurrency.d.ts.map +1 -1
- package/dist/types/server/format/useDate.d.ts +0 -1
- package/dist/types/server/format/useDate.d.ts.map +1 -1
- package/dist/types/server/format/useIntl.d.ts +0 -1
- package/dist/types/server/format/useIntl.d.ts.map +1 -1
- package/dist/types/server/format/useList.d.ts +0 -1
- package/dist/types/server/format/useList.d.ts.map +1 -1
- package/dist/types/server/format/useNumber.d.ts +0 -1
- package/dist/types/server/format/useNumber.d.ts.map +1 -1
- package/dist/types/server/format/usePercentage.d.ts +0 -1
- package/dist/types/server/format/usePercentage.d.ts.map +1 -1
- package/dist/types/server/format/useRelativeTime.d.ts +0 -1
- package/dist/types/server/format/useRelativeTime.d.ts.map +1 -1
- package/dist/types/server/format/useUnit.d.ts +0 -1
- package/dist/types/server/format/useUnit.d.ts.map +1 -1
- package/dist/types/server/serverContext.d.ts +1 -5
- package/dist/types/server/serverContext.d.ts.map +1 -1
- package/dist/types/server/t.d.ts +0 -1
- package/dist/types/server/t.d.ts.map +1 -1
- package/dist/types/server/useDictionary.d.ts +2 -5
- package/dist/types/server/useDictionary.d.ts.map +1 -1
- package/dist/types/server/useDictionaryAsync.d.ts +2 -5
- package/dist/types/server/useDictionaryAsync.d.ts.map +1 -1
- package/dist/types/server/useDictionaryDynamic.d.ts +0 -1
- package/dist/types/server/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/server/useI18n.d.ts +0 -1
- package/dist/types/server/useI18n.d.ts.map +1 -1
- package/dist/types/server/useIntlayer.d.ts +2 -5
- package/dist/types/server/useIntlayer.d.ts.map +1 -1
- package/dist/types/server/useLoadDynamic.d.ts.map +1 -1
- package/dist/types/server/useLocale.d.ts +0 -1
- package/dist/types/server/useLocale.d.ts.map +1 -1
- package/package.json +22 -12
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
let react = require("react");
|
|
4
3
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
4
|
|
|
@@ -11,7 +10,7 @@ const renderIntlayerNode = ({ children, value, additionalProps }) => {
|
|
|
11
10
|
if (prop === Symbol.toPrimitive) return () => value ?? "";
|
|
12
11
|
if (prop === "toString") return () => String(value ?? "");
|
|
13
12
|
if (prop === "valueOf") return () => value;
|
|
14
|
-
if (additionalProps && prop
|
|
13
|
+
if (additionalProps && Object.hasOwn(additionalProps, prop)) return additionalProps[prop];
|
|
15
14
|
if (value !== null && value !== void 0 && typeof prop === "string" && prop !== "constructor" && !(prop in target)) {
|
|
16
15
|
const valObj = Object(value);
|
|
17
16
|
if (prop in valObj) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerNode.cjs","names":[],"sources":["../../src/IntlayerNode.tsx"],"sourcesContent":["import type { NodeProps } from '@intlayer/core/interpreter';\nimport type { ResolvedEditor } from '@intlayer/types/module_augmentation';\nimport {\n isValidElement,\n type PropsWithChildren,\n type ReactElement,\n type ReactNode,\n} 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\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 const element: ReactElement<any> = isValidElement(children) ? (\n children\n ) : (\n <>{children}</>\n );\n\n return new Proxy(element as ReactElement, {\n get(target, prop, receiver) {\n if (prop === 'value') return value;\n if (prop === Symbol.toPrimitive) return () => value ?? '';\n if (prop === 'toString') return () => String(value ?? '');\n if (prop === 'valueOf') return () => value;\n\n // Additional Props take precedence\n if (additionalProps && prop
|
|
1
|
+
{"version":3,"file":"IntlayerNode.cjs","names":[],"sources":["../../src/IntlayerNode.tsx"],"sourcesContent":["import type { NodeProps } from '@intlayer/core/interpreter';\nimport type { ResolvedEditor } from '@intlayer/types/module_augmentation';\nimport {\n isValidElement,\n type PropsWithChildren,\n type ReactElement,\n type ReactNode,\n} 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\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 const element: ReactElement<any> = isValidElement(children) ? (\n children\n ) : (\n <>{children}</>\n );\n\n return new Proxy(element as ReactElement, {\n get(target, prop, receiver) {\n if (prop === 'value') return value;\n if (prop === Symbol.toPrimitive) return () => value ?? '';\n if (prop === 'toString') return () => String(value ?? '');\n if (prop === 'valueOf') return () => value;\n\n // Additional Props take precedence. Own keys only: `in` would also match\n // inherited `Object.prototype` members such as `constructor`, which are\n // never meant to be served as additional props.\n if (additionalProps && Object.hasOwn(additionalProps, prop)) {\n return additionalProps[prop as keyof typeof additionalProps];\n }\n\n // Delegate native methods/properties to the underlying value\n if (\n value !== null &&\n value !== undefined &&\n typeof prop === 'string' &&\n prop !== 'constructor' &&\n !(prop in target) // Prevents overwriting React internals (type, props, key)\n ) {\n const valObj = Object(value); // Safely boxes primitives (e.g., 50 -> Number object)\n\n if (prop in valObj) {\n const valProp = valObj[prop];\n return typeof valProp === 'function' ? valProp.bind(value) : valProp;\n }\n }\n\n // Fallback to React Element\n return Reflect.get(target, prop, receiver);\n },\n }) as unknown as IntlayerNode<T>;\n};\n"],"mappings":";;;;;AAuBA,MAAa,sBAEX,EACA,UACA,OACA,sBACiD;CACjD,MAAM,oCAA4C,QAAQ,IACxD,WAEA,yEAAG,SAAW;CAGhB,OAAO,IAAI,MAAM,SAAyB,EACxC,IAAI,QAAQ,MAAM,UAAU;EAC1B,IAAI,SAAS,SAAS,OAAO;EAC7B,IAAI,SAAS,OAAO,aAAa,aAAa,SAAS;EACvD,IAAI,SAAS,YAAY,aAAa,OAAO,SAAS,EAAE;EACxD,IAAI,SAAS,WAAW,aAAa;EAKrC,IAAI,mBAAmB,OAAO,OAAO,iBAAiB,IAAI,GACxD,OAAO,gBAAgB;EAIzB,IACE,UAAU,QACV,UAAU,UACV,OAAO,SAAS,YAChB,SAAS,iBACT,EAAE,QAAQ,SACV;GACA,MAAM,SAAS,OAAO,KAAK;GAE3B,IAAI,QAAQ,QAAQ;IAClB,MAAM,UAAU,OAAO;IACvB,OAAO,OAAO,YAAY,aAAa,QAAQ,KAAK,KAAK,IAAI;GAC/D;EACF;EAGA,OAAO,QAAQ,IAAI,QAAQ,MAAM,QAAQ;CAC3C,EACF,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSelector.cjs","names":[],"sources":["../../../src/UI/ContentSelector.tsx"],"sourcesContent":["'use client';\n\nimport {\n type FC,\n type HTMLAttributes,\n type MouseEventHandler,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nconst DEFAULT_PRESS_DETECT_DURATION = 250;\n\ntype ContentSelectorProps = {\n onPress: () => void;\n onHover?: () => void;\n onUnhover?: () => void;\n onClickOutside?: () => void;\n pressDuration?: number;\n isSelecting?: boolean;\n} & Omit<HTMLAttributes<HTMLDivElement>, 'content'>;\n\nexport const ContentSelector: FC<ContentSelectorProps> = ({\n children,\n onPress,\n onHover,\n onUnhover,\n onClickOutside: onUnselect,\n pressDuration = DEFAULT_PRESS_DETECT_DURATION,\n isSelecting: isSelectingProp,\n ...props\n}) => {\n const divRef = useRef<HTMLDivElement>(null);\n const [isHovered, setIsHovered] = useState(false);\n const [isSelectingState, setIsSelectingState] = useState(isSelectingProp);\n const pressTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const isChildrenString = typeof children === 'string';\n\n const handleOnLongPress = () => {\n setIsSelectingState(true);\n onPress();\n };\n\n const startPressTimer = () => {\n pressTimerRef.current = setTimeout(() => {\n handleOnLongPress();\n }, pressDuration);\n };\n\n const clearPressTimer = () => {\n if (pressTimerRef.current) {\n clearTimeout(pressTimerRef.current);\n pressTimerRef.current = null;\n }\n };\n\n const handleMouseDown = () => {\n clearPressTimer(); // Ensure any previous timer is cleared\n startPressTimer();\n };\n\n const handleMouseEnter = () => {\n setIsHovered(true);\n onHover?.();\n };\n\n const handleMouseUp = () => {\n onUnhover?.();\n setIsHovered(false);\n clearPressTimer();\n };\n\n // Use useCallback to ensure the function identity remains stable\n const handleClickOutside = useCallback(\n (event: MouseEvent) => {\n if (divRef.current && !divRef.current.contains(event.target as Node)) {\n setIsSelectingState(false);\n onUnselect?.();\n }\n },\n [onUnselect]\n );\n\n useEffect(() => {\n // Attach click outside listener\n document.addEventListener('mousedown', handleClickOutside);\n\n return () => {\n // Cleanup\n document.removeEventListener('mousedown', handleClickOutside);\n // clearPressTimer(); // Ensure to clear the timer when component unmounts\n };\n }, [handleClickOutside]);\n\n const handleOnClick: MouseEventHandler<HTMLDivElement> = (e) => {\n if (isSelectingState) {\n e.preventDefault();\n e.stopPropagation();\n }\n };\n\n const handleOnBlur = () => {\n // Stop editing when the element loses focus\n setIsSelectingState(false);\n };\n\n return (\n <span\n style={{\n display: isChildrenString ? 'inline' : 'inline-block',\n cursor: 'pointer',\n userSelect: 'none',\n borderRadius: '0.375rem',\n outlineWidth: '2px',\n outlineOffset: '4px',\n outlineStyle: 'solid',\n outlineColor:\n isSelectingProp || isSelectingState || isHovered\n ? 'inherit'\n : 'transparent',\n transition: 'all 100ms 50ms ease-in-out',\n }}\n role=\"button\"\n tabIndex={0}\n onKeyUp={() => null}\n onClick={handleOnClick}\n onMouseDown={handleMouseDown}\n onMouseUp={handleMouseUp}\n onMouseLeave={handleMouseUp}\n onTouchStart={handleMouseDown}\n onTouchEnd={handleMouseUp}\n onTouchCancel={handleMouseUp}\n onBlur={handleOnBlur}\n onMouseEnter={handleMouseEnter}\n ref={divRef}\n {...props}\n >\n {children}\n </span>\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ContentSelector.cjs","names":[],"sources":["../../../src/UI/ContentSelector.tsx"],"sourcesContent":["'use client';\n\nimport {\n type FC,\n type HTMLAttributes,\n type MouseEventHandler,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nconst DEFAULT_PRESS_DETECT_DURATION = 250;\n\ntype ContentSelectorProps = {\n onPress: () => void;\n onHover?: () => void;\n onUnhover?: () => void;\n onClickOutside?: () => void;\n pressDuration?: number;\n isSelecting?: boolean;\n} & Omit<HTMLAttributes<HTMLDivElement>, 'content'>;\n\nexport const ContentSelector: FC<ContentSelectorProps> = ({\n children,\n onPress,\n onHover,\n onUnhover,\n onClickOutside: onUnselect,\n pressDuration = DEFAULT_PRESS_DETECT_DURATION,\n isSelecting: isSelectingProp,\n ...props\n}) => {\n const divRef = useRef<HTMLDivElement>(null);\n const [isHovered, setIsHovered] = useState(false);\n const [isSelectingState, setIsSelectingState] = useState(isSelectingProp);\n const pressTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const isChildrenString = typeof children === 'string';\n\n const handleOnLongPress = () => {\n setIsSelectingState(true);\n onPress();\n };\n\n const startPressTimer = () => {\n pressTimerRef.current = setTimeout(() => {\n handleOnLongPress();\n }, pressDuration);\n };\n\n const clearPressTimer = () => {\n if (pressTimerRef.current) {\n clearTimeout(pressTimerRef.current);\n pressTimerRef.current = null;\n }\n };\n\n const handleMouseDown = () => {\n clearPressTimer(); // Ensure any previous timer is cleared\n startPressTimer();\n };\n\n const handleMouseEnter = () => {\n setIsHovered(true);\n onHover?.();\n };\n\n const handleMouseUp = () => {\n onUnhover?.();\n setIsHovered(false);\n clearPressTimer();\n };\n\n // Use useCallback to ensure the function identity remains stable\n const handleClickOutside = useCallback(\n (event: MouseEvent) => {\n if (divRef.current && !divRef.current.contains(event.target as Node)) {\n setIsSelectingState(false);\n onUnselect?.();\n }\n },\n [onUnselect]\n );\n\n useEffect(() => {\n // Attach click outside listener\n document.addEventListener('mousedown', handleClickOutside);\n\n return () => {\n // Cleanup\n document.removeEventListener('mousedown', handleClickOutside);\n // clearPressTimer(); // Ensure to clear the timer when component unmounts\n };\n }, [handleClickOutside]);\n\n const handleOnClick: MouseEventHandler<HTMLDivElement> = (e) => {\n if (isSelectingState) {\n e.preventDefault();\n e.stopPropagation();\n }\n };\n\n const handleOnBlur = () => {\n // Stop editing when the element loses focus\n setIsSelectingState(false);\n };\n\n return (\n <span\n style={{\n display: isChildrenString ? 'inline' : 'inline-block',\n cursor: 'pointer',\n userSelect: 'none',\n borderRadius: '0.375rem',\n outlineWidth: '2px',\n outlineOffset: '4px',\n outlineStyle: 'solid',\n outlineColor:\n isSelectingProp || isSelectingState || isHovered\n ? 'inherit'\n : 'transparent',\n transition: 'all 100ms 50ms ease-in-out',\n }}\n role=\"button\"\n tabIndex={0}\n onKeyUp={() => null}\n onClick={handleOnClick}\n onMouseDown={handleMouseDown}\n onMouseUp={handleMouseUp}\n onMouseLeave={handleMouseUp}\n onTouchStart={handleMouseDown}\n onTouchEnd={handleMouseUp}\n onTouchCancel={handleMouseUp}\n onBlur={handleOnBlur}\n onMouseEnter={handleMouseEnter}\n ref={divRef}\n {...props}\n >\n {children}\n </span>\n );\n};\n"],"mappings":";;;;;;;AAYA,MAAM,gCAAgC;AAWtC,MAAa,mBAA6C,EACxD,UACA,SACA,SACA,WACA,gBAAgB,YAChB,gBAAgB,+BAChB,aAAa,iBACb,GAAG,YACC;CACJ,MAAM,2BAAgC,IAAI;CAC1C,MAAM,CAAC,WAAW,oCAAyB,KAAK;CAChD,MAAM,CAAC,kBAAkB,2CAAgC,eAAe;CACxE,MAAM,kCAA6D,IAAI;CACvE,MAAM,mBAAmB,OAAO,aAAa;CAE7C,MAAM,0BAA0B;EAC9B,oBAAoB,IAAI;EACxB,QAAQ;CACV;CAEA,MAAM,wBAAwB;EAC5B,cAAc,UAAU,iBAAiB;GACvC,kBAAkB;EACpB,GAAG,aAAa;CAClB;CAEA,MAAM,wBAAwB;EAC5B,IAAI,cAAc,SAAS;GACzB,aAAa,cAAc,OAAO;GAClC,cAAc,UAAU;EAC1B;CACF;CAEA,MAAM,wBAAwB;EAC5B,gBAAgB;EAChB,gBAAgB;CAClB;CAEA,MAAM,yBAAyB;EAC7B,aAAa,IAAI;EACjB,UAAU;CACZ;CAEA,MAAM,sBAAsB;EAC1B,YAAY;EACZ,aAAa,KAAK;EAClB,gBAAgB;CAClB;CAGA,MAAM,6CACH,UAAsB;EACrB,IAAI,OAAO,WAAW,CAAC,OAAO,QAAQ,SAAS,MAAM,MAAc,GAAG;GACpE,oBAAoB,KAAK;GACzB,aAAa;EACf;CACF,GACA,CAAC,UAAU,CACb;CAEA,2BAAgB;EAEd,SAAS,iBAAiB,aAAa,kBAAkB;EAEzD,aAAa;GAEX,SAAS,oBAAoB,aAAa,kBAAkB;EAE9D;CACF,GAAG,CAAC,kBAAkB,CAAC;CAEvB,MAAM,iBAAoD,MAAM;EAC9D,IAAI,kBAAkB;GACpB,EAAE,eAAe;GACjB,EAAE,gBAAgB;EACpB;CACF;CAEA,MAAM,qBAAqB;EAEzB,oBAAoB,KAAK;CAC3B;CAEA,OACE,2CAAC,QAAD;EACE,OAAO;GACL,SAAS,mBAAmB,WAAW;GACvC,QAAQ;GACR,YAAY;GACZ,cAAc;GACd,cAAc;GACd,eAAe;GACf,cAAc;GACd,cACE,mBAAmB,oBAAoB,YACnC,YACA;GACN,YAAY;EACd;EACA,MAAK;EACL,UAAU;EACV,eAAe;EACf,SAAS;EACT,aAAa;EACb,WAAW;EACX,cAAc;EACd,cAAc;EACd,YAAY;EACZ,eAAe;EACf,QAAQ;EACR,cAAc;EACd,KAAK;EACL,GAAI;EAEH;CACG;AAEV"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_analytics_useAnalytics = require('./useAnalytics.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/analytics/AnalyticsProvider.tsx
|
|
5
|
+
/**
|
|
6
|
+
* Runs {@link useAnalytics} and renders its children unchanged. Mounted inside
|
|
7
|
+
* {@link IntlayerProvider} alongside `EditorProvider`.
|
|
8
|
+
*/
|
|
9
|
+
const AnalyticsProvider = ({ children }) => {
|
|
10
|
+
require_analytics_useAnalytics.useAnalytics();
|
|
11
|
+
return children;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
exports.AnalyticsProvider = AnalyticsProvider;
|
|
16
|
+
//# sourceMappingURL=AnalyticsProvider.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnalyticsProvider.cjs","names":[],"sources":["../../../src/analytics/AnalyticsProvider.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from 'react';\nimport { useAnalytics } from './useAnalytics';\n\n/**\n * Runs {@link useAnalytics} and renders its children unchanged. Mounted inside\n * {@link IntlayerProvider} alongside `EditorProvider`.\n */\nexport const AnalyticsProvider: FC<PropsWithChildren> = ({ children }) => {\n useAnalytics();\n\n return children;\n};\n"],"mappings":";;;;;;;;AAOA,MAAa,qBAA4C,EAAE,eAAe;CACxE,4CAAa;CAEb,OAAO;AACT"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
//#region src/analytics/exposureSink.ts
|
|
4
|
+
let sink = null;
|
|
5
|
+
/**
|
|
6
|
+
* Installs (or clears) the exposure sink. `useAnalytics` sets this once the
|
|
7
|
+
* analytics client has loaded, and clears it on unmount.
|
|
8
|
+
*
|
|
9
|
+
* @param next - The sink to install, or `null` to clear.
|
|
10
|
+
*/
|
|
11
|
+
const setExposureSink = (next) => {
|
|
12
|
+
sink = next;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Forwards a content exposure to the installed sink. A cheap null-check when
|
|
16
|
+
* analytics is not running, so it is safe to call from every node resolution.
|
|
17
|
+
*
|
|
18
|
+
* @param input - The node metadata to report.
|
|
19
|
+
*/
|
|
20
|
+
const reportExposure = (input) => {
|
|
21
|
+
sink?.(input);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.reportExposure = reportExposure;
|
|
26
|
+
exports.setExposureSink = setExposureSink;
|
|
27
|
+
//# sourceMappingURL=exposureSink.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exposureSink.cjs","names":[],"sources":["../../../src/analytics/exposureSink.ts"],"sourcesContent":["import type { KeyPath } from '@intlayer/types/keyPath';\n\n/**\n * Node metadata reported for a content exposure. Kept dependency-free (types\n * only) so the interpreter hot path in `plugins.tsx` never statically imports\n * `@intlayer/analytics` — the package stays optional and tree-shakeable.\n */\nexport type ExposureInput = {\n dictionaryKey: string;\n keyPath: KeyPath[];\n locale?: string;\n nodeType?: string;\n};\n\n/** Consumer of exposure reports, installed by `useAnalytics` after init. */\nexport type ExposureSink = (input: ExposureInput) => void;\n\nlet sink: ExposureSink | null = null;\n\n/**\n * Installs (or clears) the exposure sink. `useAnalytics` sets this once the\n * analytics client has loaded, and clears it on unmount.\n *\n * @param next - The sink to install, or `null` to clear.\n */\nexport const setExposureSink = (next: ExposureSink | null): void => {\n sink = next;\n};\n\n/**\n * Forwards a content exposure to the installed sink. A cheap null-check when\n * analytics is not running, so it is safe to call from every node resolution.\n *\n * @param input - The node metadata to report.\n */\nexport const reportExposure = (input: ExposureInput): void => {\n sink?.(input);\n};\n"],"mappings":";;;AAiBA,IAAI,OAA4B;;;;;;;AAQhC,MAAa,mBAAmB,SAAoC;CAClE,OAAO;AACT;;;;;;;AAQA,MAAa,kBAAkB,UAA+B;CAC5D,OAAO,KAAK;AACd"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_analytics_useAnalytics = require('./useAnalytics.cjs');
|
|
3
|
+
const require_analytics_AnalyticsProvider = require('./AnalyticsProvider.cjs');
|
|
4
|
+
const require_analytics_useConversion = require('./useConversion.cjs');
|
|
5
|
+
const require_analytics_useExperiment = require('./useExperiment.cjs');
|
|
6
|
+
|
|
7
|
+
exports.AnalyticsProvider = require_analytics_AnalyticsProvider.AnalyticsProvider;
|
|
8
|
+
exports.useAnalytics = require_analytics_useAnalytics.useAnalytics;
|
|
9
|
+
exports.useConversion = require_analytics_useConversion.useConversion;
|
|
10
|
+
exports.useExperiment = require_analytics_useExperiment.useExperiment;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_analytics_exposureSink = require('./exposureSink.cjs');
|
|
5
|
+
const require_client_IntlayerProvider = require('../client/IntlayerProvider.cjs');
|
|
6
|
+
let react = require("react");
|
|
7
|
+
let _intlayer_analytics_isEnabled = require("@intlayer/analytics/isEnabled");
|
|
8
|
+
|
|
9
|
+
//#region src/analytics/useAnalytics.tsx
|
|
10
|
+
/**
|
|
11
|
+
* Initializes the Intlayer analytics client singleton when analytics is enabled
|
|
12
|
+
* and keeps it aware of the current locale.
|
|
13
|
+
*
|
|
14
|
+
* Mirrors {@link useEditor}: the module is loaded via a dynamic `import()` so it
|
|
15
|
+
* ships as its own async chunk, off the critical rendering path. Apps that
|
|
16
|
+
* don't opt in (`analytics.enabled !== true`) pay nothing — the whole body is
|
|
17
|
+
* guarded by `INTLAYER_ANALYTICS_ENABLED` and dead-code-eliminated at build
|
|
18
|
+
* time.
|
|
19
|
+
*/
|
|
20
|
+
const useAnalytics = () => {
|
|
21
|
+
const { locale } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {};
|
|
22
|
+
const clientRef = (0, react.useRef)(null);
|
|
23
|
+
(0, react.useEffect)(() => {
|
|
24
|
+
if (process.env.INTLAYER_ANALYTICS_ENABLED === "false" || !_intlayer_analytics_isEnabled.isEnabled) return;
|
|
25
|
+
let cancelled = false;
|
|
26
|
+
let initialized = false;
|
|
27
|
+
import("@intlayer/analytics").then(({ initAnalyticsClient, buildContentExposure }) => {
|
|
28
|
+
if (cancelled) return;
|
|
29
|
+
const client = initAnalyticsClient();
|
|
30
|
+
initialized = true;
|
|
31
|
+
clientRef.current = client;
|
|
32
|
+
if (locale) client.setLocale(locale);
|
|
33
|
+
client.trackPageView({ reason: "initial" });
|
|
34
|
+
require_analytics_exposureSink.setExposureSink((input) => client.trackContentExposure(buildContentExposure(input)));
|
|
35
|
+
}).catch(() => {});
|
|
36
|
+
return () => {
|
|
37
|
+
cancelled = true;
|
|
38
|
+
clientRef.current = null;
|
|
39
|
+
require_analytics_exposureSink.setExposureSink(null);
|
|
40
|
+
import("@intlayer/analytics").then(({ stopAnalyticsClient }) => {
|
|
41
|
+
if (initialized) stopAnalyticsClient();
|
|
42
|
+
}).catch(() => {});
|
|
43
|
+
};
|
|
44
|
+
}, []);
|
|
45
|
+
(0, react.useEffect)(() => {
|
|
46
|
+
if (!locale || !clientRef.current) return;
|
|
47
|
+
clientRef.current.setLocale(locale);
|
|
48
|
+
clientRef.current.trackPageView({ reason: "locale_change" });
|
|
49
|
+
}, [locale]);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
exports.useAnalytics = useAnalytics;
|
|
54
|
+
//# sourceMappingURL=useAnalytics.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAnalytics.cjs","names":["IntlayerClientContext","isEnabled"],"sources":["../../../src/analytics/useAnalytics.tsx"],"sourcesContent":["'use client';\n\nimport type { AnalyticsClient } from '@intlayer/analytics';\nimport { isEnabled } from '@intlayer/analytics/isEnabled';\nimport { useContext, useEffect, useRef } from 'react';\nimport { IntlayerClientContext } from '../client/IntlayerProvider';\nimport { setExposureSink } from './exposureSink';\n\n/**\n * Initializes the Intlayer analytics client singleton when analytics is enabled\n * and keeps it aware of the current locale.\n *\n * Mirrors {@link useEditor}: the module is loaded via a dynamic `import()` so it\n * ships as its own async chunk, off the critical rendering path. Apps that\n * don't opt in (`analytics.enabled !== true`) pay nothing — the whole body is\n * guarded by `INTLAYER_ANALYTICS_ENABLED` and dead-code-eliminated at build\n * time.\n */\nexport const useAnalytics = () => {\n const { locale } = useContext(IntlayerClientContext) ?? {};\n const clientRef = useRef<AnalyticsClient | null>(null);\n\n useEffect(() => {\n if (process.env.INTLAYER_ANALYTICS_ENABLED === 'false' || !isEnabled) {\n return;\n }\n\n let cancelled = false;\n // Tracks whether initAnalyticsClient actually ran, so cleanup never calls\n // stopAnalyticsClient for an init that was cancelled — that would decrement\n // the shared reference count once too many and could stop a client another\n // provider still uses.\n let initialized = false;\n\n import('@intlayer/analytics')\n .then(({ initAnalyticsClient, buildContentExposure }) => {\n if (cancelled) return;\n\n const client = initAnalyticsClient();\n initialized = true;\n clientRef.current = client;\n\n if (locale) client.setLocale(locale);\n client.trackPageView({ reason: 'initial' });\n\n // Route node-level exposures (from the interpreter plugins) into the\n // client. Serialization happens here, off the hot render path.\n setExposureSink((input) =>\n client.trackContentExposure(buildContentExposure(input))\n );\n })\n .catch(() => {\n /* chunk failed to load — analytics stays a no-op */\n });\n\n return () => {\n cancelled = true;\n clientRef.current = null;\n setExposureSink(null);\n import('@intlayer/analytics')\n .then(({ stopAnalyticsClient }) => {\n if (initialized) stopAnalyticsClient();\n })\n .catch(() => {});\n };\n // Run once on mount; locale updates are handled by the effect below.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n if (!locale || !clientRef.current) return;\n\n clientRef.current.setLocale(locale);\n clientRef.current.trackPageView({ reason: 'locale_change' });\n }, [locale]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,MAAa,qBAAqB;CAChC,MAAM,EAAE,iCAAsBA,qDAAqB,KAAK,CAAC;CACzD,MAAM,8BAA2C,IAAI;CAErD,2BAAgB;EACd,IAAI,QAAQ,IAAI,+BAA+B,WAAW,CAACC,yCACzD;EAGF,IAAI,YAAY;EAKhB,IAAI,cAAc;EAElB,OAAO,sBAAsB,CAC1B,MAAM,EAAE,qBAAqB,2BAA2B;GACvD,IAAI,WAAW;GAEf,MAAM,SAAS,oBAAoB;GACnC,cAAc;GACd,UAAU,UAAU;GAEpB,IAAI,QAAQ,OAAO,UAAU,MAAM;GACnC,OAAO,cAAc,EAAE,QAAQ,UAAU,CAAC;GAI1C,gDAAiB,UACf,OAAO,qBAAqB,qBAAqB,KAAK,CAAC,CACzD;EACF,CAAC,CAAC,CACD,YAAY,CAEb,CAAC;EAEH,aAAa;GACX,YAAY;GACZ,UAAU,UAAU;GACpB,+CAAgB,IAAI;GACpB,OAAO,sBAAsB,CAC1B,MAAM,EAAE,0BAA0B;IACjC,IAAI,aAAa,oBAAoB;GACvC,CAAC,CAAC,CACD,YAAY,CAAC,CAAC;EACnB;CAGF,GAAG,CAAC,CAAC;CAEL,2BAAgB;EACd,IAAI,CAAC,UAAU,CAAC,UAAU,SAAS;EAEnC,UAAU,QAAQ,UAAU,MAAM;EAClC,UAAU,QAAQ,cAAc,EAAE,QAAQ,gBAAgB,CAAC;CAC7D,GAAG,CAAC,MAAM,CAAC;AACb"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
let react = require("react");
|
|
5
|
+
let _intlayer_analytics_isEnabled = require("@intlayer/analytics/isEnabled");
|
|
6
|
+
|
|
7
|
+
//#region src/analytics/useConversion.tsx
|
|
8
|
+
/**
|
|
9
|
+
* Returns a stable `trackConversion` callback for content A/B testing. Safe to
|
|
10
|
+
* call from any component: it resolves to a no-op when analytics is disabled
|
|
11
|
+
* or the client has not been initialized yet.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* const trackConversion = useConversion();
|
|
16
|
+
* <button onClick={() => trackConversion({
|
|
17
|
+
* experimentKey: 'homepage-hero', variant: 'b', goal: 'cta_click',
|
|
18
|
+
* })}>Get started</button>
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
const useConversion = () => {
|
|
22
|
+
return (0, react.useCallback)((params) => {
|
|
23
|
+
if (process.env.INTLAYER_ANALYTICS_ENABLED === "false" || !_intlayer_analytics_isEnabled.isEnabled) return;
|
|
24
|
+
import("@intlayer/analytics").then(({ getGlobalAnalyticsClient }) => {
|
|
25
|
+
getGlobalAnalyticsClient()?.trackConversion(params);
|
|
26
|
+
}).catch(() => {});
|
|
27
|
+
}, []);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
exports.useConversion = useConversion;
|
|
32
|
+
//# sourceMappingURL=useConversion.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConversion.cjs","names":["isEnabled"],"sources":["../../../src/analytics/useConversion.tsx"],"sourcesContent":["'use client';\n\nimport { isEnabled } from '@intlayer/analytics/isEnabled';\nimport { useCallback } from 'react';\n\n/**\n * Parameters describing a conversion to record.\n */\nexport type ConversionParams = {\n /** The experiment this conversion is attributed to. */\n experimentKey: string;\n /** The variant the session was assigned. */\n variant: string;\n /** The goal reached (e.g. `\"signup\"`, `\"cta_click\"`). */\n goal: string;\n /** Optional numeric value (e.g. revenue). */\n value?: number;\n};\n\n/**\n * Returns a stable `trackConversion` callback for content A/B testing. Safe to\n * call from any component: it resolves to a no-op when analytics is disabled\n * or the client has not been initialized yet.\n *\n * @example\n * ```tsx\n * const trackConversion = useConversion();\n * <button onClick={() => trackConversion({\n * experimentKey: 'homepage-hero', variant: 'b', goal: 'cta_click',\n * })}>Get started</button>\n * ```\n */\nexport const useConversion = () => {\n return useCallback((params: ConversionParams) => {\n if (process.env.INTLAYER_ANALYTICS_ENABLED === 'false' || !isEnabled) {\n return;\n }\n\n import('@intlayer/analytics')\n .then(({ getGlobalAnalyticsClient }) => {\n getGlobalAnalyticsClient()?.trackConversion(params);\n })\n .catch(() => {});\n }, []);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAgCA,MAAa,sBAAsB;CACjC,+BAAoB,WAA6B;EAC/C,IAAI,QAAQ,IAAI,+BAA+B,WAAW,CAACA,yCACzD;EAGF,OAAO,sBAAsB,CAC1B,MAAM,EAAE,+BAA+B;GACtC,yBAAyB,CAAC,EAAE,gBAAgB,MAAM;EACpD,CAAC,CAAC,CACD,YAAY,CAAC,CAAC;CACnB,GAAG,CAAC,CAAC;AACP"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
let react = require("react");
|
|
5
|
+
let _intlayer_analytics_isEnabled = require("@intlayer/analytics/isEnabled");
|
|
6
|
+
|
|
7
|
+
//#region src/analytics/useExperiment.tsx
|
|
8
|
+
/**
|
|
9
|
+
* Assigns this session to a variant of an A/B experiment and records the
|
|
10
|
+
* exposure, scoped to `experimentKey`, so the backend can compute per-variant
|
|
11
|
+
* conversion rates against `useConversion` events.
|
|
12
|
+
*
|
|
13
|
+
* Assignment is deterministic per session (no server round-trip, stable across
|
|
14
|
+
* re-mounts). The exposure is recorded once per mount.
|
|
15
|
+
*
|
|
16
|
+
* @param experimentKey - Unique key identifying the experiment.
|
|
17
|
+
* @param variants - The candidate variant names; the first one is the control.
|
|
18
|
+
* @param weights - Optional relative weights, one per variant (e.g. `[9, 1]`).
|
|
19
|
+
* @returns The {@link ExperimentState} for this session.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* const { variant } = useExperiment('homepage-hero', ['a', 'b']);
|
|
24
|
+
* const content = useIntlayer(variant === 'b' ? 'hero-b' : 'hero');
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
const useExperiment = (experimentKey, variants, weights) => {
|
|
28
|
+
const [state, setState] = (0, react.useState)({
|
|
29
|
+
variant: variants[0] ?? "",
|
|
30
|
+
isAssigned: false
|
|
31
|
+
});
|
|
32
|
+
(0, react.useEffect)(() => {
|
|
33
|
+
if (process.env.INTLAYER_ANALYTICS_ENABLED === "false" || !_intlayer_analytics_isEnabled.isEnabled) return;
|
|
34
|
+
let cancelled = false;
|
|
35
|
+
let initialized = false;
|
|
36
|
+
import("@intlayer/analytics").then(({ initAnalyticsClient }) => {
|
|
37
|
+
if (cancelled) return;
|
|
38
|
+
const client = initAnalyticsClient();
|
|
39
|
+
initialized = true;
|
|
40
|
+
const variant = client.getVariant(experimentKey, variants, weights);
|
|
41
|
+
setState({
|
|
42
|
+
variant,
|
|
43
|
+
isAssigned: true
|
|
44
|
+
});
|
|
45
|
+
client.trackContentExposure({
|
|
46
|
+
dictionaryKey: experimentKey,
|
|
47
|
+
keyPath: "",
|
|
48
|
+
nodeType: "experiment",
|
|
49
|
+
experimentKey,
|
|
50
|
+
variant
|
|
51
|
+
});
|
|
52
|
+
}).catch(() => {});
|
|
53
|
+
return () => {
|
|
54
|
+
cancelled = true;
|
|
55
|
+
import("@intlayer/analytics").then(({ stopAnalyticsClient }) => {
|
|
56
|
+
if (initialized) stopAnalyticsClient();
|
|
57
|
+
}).catch(() => {});
|
|
58
|
+
};
|
|
59
|
+
}, [experimentKey]);
|
|
60
|
+
return state;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
exports.useExperiment = useExperiment;
|
|
65
|
+
//# sourceMappingURL=useExperiment.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useExperiment.cjs","names":["isEnabled"],"sources":["../../../src/analytics/useExperiment.tsx"],"sourcesContent":["'use client';\n\nimport { isEnabled } from '@intlayer/analytics/isEnabled';\nimport { useEffect, useState } from 'react';\n\n/**\n * The state of an A/B experiment for the current session.\n */\nexport type ExperimentState = {\n /**\n * The variant assigned to this session. Until assignment resolves (and on\n * the server, or when analytics is disabled), this is the first variant —\n * treat the first variant as the control.\n */\n variant: string;\n /**\n * `true` once the variant has been deterministically assigned and its\n * exposure recorded. Useful to defer rendering when a flash of the control\n * variant is not acceptable.\n */\n isAssigned: boolean;\n};\n\n/**\n * Assigns this session to a variant of an A/B experiment and records the\n * exposure, scoped to `experimentKey`, so the backend can compute per-variant\n * conversion rates against `useConversion` events.\n *\n * Assignment is deterministic per session (no server round-trip, stable across\n * re-mounts). The exposure is recorded once per mount.\n *\n * @param experimentKey - Unique key identifying the experiment.\n * @param variants - The candidate variant names; the first one is the control.\n * @param weights - Optional relative weights, one per variant (e.g. `[9, 1]`).\n * @returns The {@link ExperimentState} for this session.\n *\n * @example\n * ```tsx\n * const { variant } = useExperiment('homepage-hero', ['a', 'b']);\n * const content = useIntlayer(variant === 'b' ? 'hero-b' : 'hero');\n * ```\n */\nexport const useExperiment = (\n experimentKey: string,\n variants: string[],\n weights?: number[]\n): ExperimentState => {\n const [state, setState] = useState<ExperimentState>({\n variant: variants[0] ?? '',\n isAssigned: false,\n });\n\n useEffect(() => {\n if (process.env.INTLAYER_ANALYTICS_ENABLED === 'false' || !isEnabled) {\n return;\n }\n\n let cancelled = false;\n let initialized = false;\n\n import('@intlayer/analytics')\n .then(({ initAnalyticsClient }) => {\n if (cancelled) return;\n\n // Ref-counted: guarantees a live client even when this hook's import\n // resolves before the provider's. Balanced by stop in the cleanup.\n const client = initAnalyticsClient();\n initialized = true;\n\n const variant = client.getVariant(experimentKey, variants, weights);\n setState({ variant, isAssigned: true });\n\n // Experiment-level exposure — the denominator of the conversion rate.\n client.trackContentExposure({\n dictionaryKey: experimentKey,\n keyPath: '',\n nodeType: 'experiment',\n experimentKey,\n variant,\n });\n })\n .catch(() => {\n /* chunk failed to load — control variant stays in place */\n });\n\n return () => {\n cancelled = true;\n import('@intlayer/analytics')\n .then(({ stopAnalyticsClient }) => {\n if (initialized) stopAnalyticsClient();\n })\n .catch(() => {});\n };\n // Assignment is deterministic; re-running on variant-array identity churn\n // would double-record exposures.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [experimentKey]);\n\n return state;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAa,iBACX,eACA,UACA,YACoB;CACpB,MAAM,CAAC,OAAO,gCAAsC;EAClD,SAAS,SAAS,MAAM;EACxB,YAAY;CACd,CAAC;CAED,2BAAgB;EACd,IAAI,QAAQ,IAAI,+BAA+B,WAAW,CAACA,yCACzD;EAGF,IAAI,YAAY;EAChB,IAAI,cAAc;EAElB,OAAO,sBAAsB,CAC1B,MAAM,EAAE,0BAA0B;GACjC,IAAI,WAAW;GAIf,MAAM,SAAS,oBAAoB;GACnC,cAAc;GAEd,MAAM,UAAU,OAAO,WAAW,eAAe,UAAU,OAAO;GAClE,SAAS;IAAE;IAAS,YAAY;GAAK,CAAC;GAGtC,OAAO,qBAAqB;IAC1B,eAAe;IACf,SAAS;IACT,UAAU;IACV;IACA;GACF,CAAC;EACH,CAAC,CAAC,CACD,YAAY,CAEb,CAAC;EAEH,aAAa;GACX,YAAY;GACZ,OAAO,sBAAsB,CAC1B,MAAM,EAAE,0BAA0B;IACjC,IAAI,aAAa,oBAAoB;GACvC,CAAC,CAAC,CACD,YAAY,CAAC,CAAC;EACnB;CAIF,GAAG,CAAC,aAAa,CAAC;CAElB,OAAO;AACT"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
4
|
const require_editor_EditorProvider = require('../editor/EditorProvider.cjs');
|
|
6
5
|
const require_client_useLocaleStorage = require('./useLocaleStorage.cjs');
|
|
6
|
+
const require_analytics_AnalyticsProvider = require('../analytics/AnalyticsProvider.cjs');
|
|
7
7
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
8
8
|
let react = require("react");
|
|
9
9
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -84,7 +84,11 @@ const IntlayerProviderContent = ({ locale: localeProp, defaultLocale: defaultLoc
|
|
|
84
84
|
*/
|
|
85
85
|
const IntlayerProvider = ({ children, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(IntlayerProviderContent, {
|
|
86
86
|
...props,
|
|
87
|
-
children: [
|
|
87
|
+
children: [
|
|
88
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_editor_EditorProvider.EditorProvider, {}),
|
|
89
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_analytics_AnalyticsProvider.AnalyticsProvider, {}),
|
|
90
|
+
children
|
|
91
|
+
]
|
|
88
92
|
});
|
|
89
93
|
|
|
90
94
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerProvider.cjs","names":["localeInStorage","internationalization","EditorProvider"],"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 { LocalesValues } from '@intlayer/types/module_augmentation';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n useEffect,\n useState,\n} from 'react';\nimport { EditorProvider } from '../editor/EditorProvider';\nimport { localeInStorage, setLocaleInStorage } from './useLocaleStorage';\n\ntype IntlayerValue = {\n locale: LocalesValues;\n setLocale: (newLocale: LocalesValues) => void;\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 locale: localeInStorage ?? internationalization?.defaultLocale,\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 * 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 children,\n setLocale: setLocaleProp,\n disableEditor,\n isCookieEnabled,\n}) => {\n const { locales: availableLocales, defaultLocale: defaultLocaleConfig } =\n internationalization ?? {};\n\n const initialLocale =\n localeProp ?? localeInStorage ?? defaultLocaleProp ?? defaultLocaleConfig;\n\n const [currentLocale, setCurrentLocale] =\n useState<LocalesValues>(initialLocale);\n\n // Sync the prop to state if the prop changes from the parent\n useEffect(() => {\n if (localeProp && localeProp !== currentLocale) {\n setCurrentLocale(localeProp);\n }\n }, [localeProp]);\n\n useEffect(() => {\n setIntlayerIdentifier();\n }, []);\n\n const setLocaleBase = (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\n const setLocale = setLocaleProp ?? setLocaleBase;\n\n // Resolve based on currentLocale (the state), not the prop directly\n const resolvedLocale = localeResolver(currentLocale);\n\n return (\n <IntlayerClientContext.Provider\n value={{\n locale: resolvedLocale,\n setLocale,\n disableEditor,\n }}\n >\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 <EditorProvider />\n {children}\n </IntlayerProviderContent>\n);\n"],"mappings":";;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"IntlayerProvider.cjs","names":["localeInStorage","internationalization","EditorProvider","AnalyticsProvider"],"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 { LocalesValues } 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 { localeInStorage, setLocaleInStorage } from './useLocaleStorage';\n\ntype IntlayerValue = {\n locale: LocalesValues;\n setLocale: (newLocale: LocalesValues) => void;\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 locale: localeInStorage ?? internationalization?.defaultLocale,\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 * 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 children,\n setLocale: setLocaleProp,\n disableEditor,\n isCookieEnabled,\n}) => {\n const { locales: availableLocales, defaultLocale: defaultLocaleConfig } =\n internationalization ?? {};\n\n const initialLocale =\n localeProp ?? localeInStorage ?? defaultLocaleProp ?? defaultLocaleConfig;\n\n const [currentLocale, setCurrentLocale] =\n useState<LocalesValues>(initialLocale);\n\n // Sync the prop to state if the prop changes from the parent\n useEffect(() => {\n if (localeProp && localeProp !== currentLocale) {\n setCurrentLocale(localeProp);\n }\n }, [localeProp]);\n\n useEffect(() => {\n setIntlayerIdentifier();\n }, []);\n\n const setLocaleBase = (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\n const setLocale = setLocaleProp ?? setLocaleBase;\n\n // Resolve based on currentLocale (the state), not the prop directly\n const resolvedLocale = localeResolver(currentLocale);\n\n return (\n <IntlayerClientContext.Provider\n value={{\n locale: resolvedLocale,\n setLocale,\n disableEditor,\n }}\n >\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 <EditorProvider />\n <AnalyticsProvider />\n {children}\n </IntlayerProviderContent>\n);\n"],"mappings":";;;;;;;;;;;;;;;;AA4BA,MAAa,iDAAqD;CAChE,QAAQA,mDAAmBC,6CAAsB;CACjD,iBAAiB;CACjB,iBAAiB;AACnB,CAAC;;;;;;AAOD,MAAa,iDAAsC,qBAAqB,KAAK,CAAC;;;;;;;;;AAoC9E,MAAa,2BAAsD,EACjE,QAAQ,YACR,eAAe,mBACf,UACA,WAAW,eACX,eACA,sBACI;CACJ,MAAM,EAAE,SAAS,kBAAkB,eAAe,wBAChDA,+CAAwB,CAAC;CAK3B,MAAM,CAAC,eAAe,wCAFpB,cAAcD,mDAAmB,qBAAqB,mBAGjB;CAGvC,2BAAgB;EACd,IAAI,cAAc,eAAe,eAC/B,iBAAiB,UAAU;CAE/B,GAAG,CAAC,UAAU,CAAC;CAEf,2BAAgB;EACd,mDAAsB;CACxB,GAAG,CAAC,CAAC;CAEL,MAAM,iBAAiB,cAA6B;EAClD,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,mDAAmB,WAAW,eAAe;CAC/C;CAEA,MAAM,YAAY,iBAAiB;CAGnC,MAAM,iEAAgC,aAAa;CAEnD,OACE,2CAAC,sBAAsB,UAAvB;EACE,OAAO;GACL,QAAQ;GACR;GACA;EACF;EAEC;CAC6B;AAEpC;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,oBAA+C,EAC1D,UACA,GAAG,YAEH,4CAAC,yBAAD;CAAyB,GAAI;WAA7B;EACE,2CAACE,8CAAD,CAAiB;EACjB,2CAACC,uDAAD,CAAoB;EACnB;CACsB"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
5
4
|
const require_client_IntlayerProvider = require('../IntlayerProvider.cjs');
|
|
6
5
|
let react = require("react");
|
|
7
6
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCompact.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useCompact.ts"],"sourcesContent":["'use client';\n\nimport { compact } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a compact number formatter\n * bound to the current application locale.\n *\n * @example\n * ```tsx\n * const formatCompact = useCompact();\n * formatCompact(1500); // \"1.5K\"\n * ```\n */\nexport const useCompact = () => {\n const { locale } = useContext(IntlayerClientContext) ?? {};\n\n return useCallback(\n (...args: Parameters<typeof compact>) =>\n compact(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useCompact.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useCompact.ts"],"sourcesContent":["'use client';\n\nimport { compact } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a compact number formatter\n * bound to the current application locale.\n *\n * @example\n * ```tsx\n * const formatCompact = useCompact();\n * formatCompact(1500); // \"1.5K\"\n * ```\n */\nexport const useCompact = () => {\n const { locale } = useContext(IntlayerClientContext) ?? {};\n\n return useCallback(\n (...args: Parameters<typeof compact>) =>\n compact(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgBA,MAAa,mBAAmB;CAC9B,MAAM,EAAE,iCAAsBA,qDAAqB,KAAK,CAAC;CAEzD,+BACG,GAAG,gDACM,KAAK,IAAI;EACf,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU;CAC7B,CAAC,GACH,CAAC,MAAM,CACT;AACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
5
4
|
const require_client_IntlayerProvider = require('../IntlayerProvider.cjs');
|
|
6
5
|
let react = require("react");
|
|
7
6
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCurrency.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useCurrency.ts"],"sourcesContent":["'use client';\n\nimport { currency } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a currency formatter\n * bound to the current application locale.\n *\n * @returns {(value: string | number, options?: CurrencyProps) => string}\n * A function to format numbers into localized currency strings.\n *\n * @example\n * ```tsx\n * const formatCurrency = useCurrency();\n *\n * formatCurrency(1500, { currency: \"USD\" });\n * // \"$1,500.00\"\n *\n * formatCurrency(1500, { currency: \"EUR\", locale: \"de-DE\" });\n * // \"1.500,00 €\"\n *\n * formatCurrency(9876543.21, {\n * currency: \"JPY\",\n * fractionDigits: 0,\n * });\n * // \"¥9,876,543\"\n * ```\n */\nexport const useCurrency = () => {\n const { locale } = useContext(IntlayerClientContext) ?? {};\n\n return useCallback(\n (...args: Parameters<typeof currency>) =>\n currency(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useCurrency.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useCurrency.ts"],"sourcesContent":["'use client';\n\nimport { currency } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a currency formatter\n * bound to the current application locale.\n *\n * @returns {(value: string | number, options?: CurrencyProps) => string}\n * A function to format numbers into localized currency strings.\n *\n * @example\n * ```tsx\n * const formatCurrency = useCurrency();\n *\n * formatCurrency(1500, { currency: \"USD\" });\n * // \"$1,500.00\"\n *\n * formatCurrency(1500, { currency: \"EUR\", locale: \"de-DE\" });\n * // \"1.500,00 €\"\n *\n * formatCurrency(9876543.21, {\n * currency: \"JPY\",\n * fractionDigits: 0,\n * });\n * // \"¥9,876,543\"\n * ```\n */\nexport const useCurrency = () => {\n const { locale } = useContext(IntlayerClientContext) ?? {};\n\n return useCallback(\n (...args: Parameters<typeof currency>) =>\n currency(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAa,oBAAoB;CAC/B,MAAM,EAAE,iCAAsBA,qDAAqB,KAAK,CAAC;CAEzD,+BACG,GAAG,iDACO,KAAK,IAAI;EAChB,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU;CAC7B,CAAC,GACH,CAAC,MAAM,CACT;AACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
5
4
|
const require_client_IntlayerProvider = require('../IntlayerProvider.cjs');
|
|
6
5
|
let react = require("react");
|
|
7
6
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDate.cjs","names":["IntlayerClientContext","presets"],"sources":["../../../../src/client/format/useDate.ts"],"sourcesContent":["'use client';\n\nimport { date, presets } from '@intlayer/core/formatters';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a localized date/time formatter\n * bound to the current application locale.\n *\n * @returns {(date: Date | string | number, options?: DateProps) => string}\n * A function to format dates or timestamps into localized date/time strings.\n *\n * @example\n * ```tsx\n * const formatDate = useDate();\n *\n * formatDate(new Date(\"2025-01-01\"));\n * // \"Jan 1, 2025\"\n *\n * formatDate(\"2025-01-01T15:30:00Z\", {\n * dateStyle: \"full\",\n * timeStyle: \"short\",\n * });\n * // \"Wednesday, January 1, 2025 at 3:30 PM\"\n *\n * formatDate(1735689600000, { locale: \"fr-FR\", dateStyle: \"long\" });\n * // \"1 janvier 2025\"\n * ```\n *\n * @see createDate\n */\nexport const useDate = () => {\n const { locale } = useContext(IntlayerClientContext) ?? {};\n\n return (...args: Parameters<typeof date>) => {\n const options =\n typeof args[1] === 'string'\n ? { ...presets[args[1]], locale: locale }\n : { ...args[1], locale: args[1]?.locale ?? locale };\n\n return date(args[0], options as Parameters<typeof date>[1]);\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDate.cjs","names":["IntlayerClientContext","presets"],"sources":["../../../../src/client/format/useDate.ts"],"sourcesContent":["'use client';\n\nimport { date, presets } from '@intlayer/core/formatters';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a localized date/time formatter\n * bound to the current application locale.\n *\n * @returns {(date: Date | string | number, options?: DateProps) => string}\n * A function to format dates or timestamps into localized date/time strings.\n *\n * @example\n * ```tsx\n * const formatDate = useDate();\n *\n * formatDate(new Date(\"2025-01-01\"));\n * // \"Jan 1, 2025\"\n *\n * formatDate(\"2025-01-01T15:30:00Z\", {\n * dateStyle: \"full\",\n * timeStyle: \"short\",\n * });\n * // \"Wednesday, January 1, 2025 at 3:30 PM\"\n *\n * formatDate(1735689600000, { locale: \"fr-FR\", dateStyle: \"long\" });\n * // \"1 janvier 2025\"\n * ```\n *\n * @see createDate\n */\nexport const useDate = () => {\n const { locale } = useContext(IntlayerClientContext) ?? {};\n\n return (...args: Parameters<typeof date>) => {\n const options =\n typeof args[1] === 'string'\n ? { ...presets[args[1]], locale: locale }\n : { ...args[1], locale: args[1]?.locale ?? locale };\n\n return date(args[0], options as Parameters<typeof date>[1]);\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAa,gBAAgB;CAC3B,MAAM,EAAE,iCAAsBA,qDAAqB,KAAK,CAAC;CAEzD,QAAQ,GAAG,SAAkC;EAC3C,MAAM,UACJ,OAAO,KAAK,OAAO,WACf;GAAE,GAAGC,kCAAQ,KAAK;GAAa;EAAO,IACtC;GAAE,GAAG,KAAK;GAAI,QAAQ,KAAK,EAAE,EAAE,UAAU;EAAO;EAEtD,2CAAY,KAAK,IAAI,OAAqC;CAC5D;AACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
5
4
|
const require_client_IntlayerProvider = require('../IntlayerProvider.cjs');
|
|
6
5
|
let react = require("react");
|
|
7
6
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntl.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useIntl.ts"],"sourcesContent":["'use client';\n\nimport { bindIntl, type WrappedIntl } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a locale-bound `Intl` object.\n *\n * It acts exactly like the native `Intl` object, but acts as a proxy to:\n * 1. Inject the current locale automatically if none is provided.\n * 2. Use the performance-optimized `CachedIntl` under the hood.\n *\n * @example\n * ```tsx\n * const intl = useIntl(); // uses context locale\n *\n * // Standard API, but no need to pass 'en-US' as the first argument\n * const formatted = new intl.NumberFormat({\n * style: 'currency',\n * currency: 'USD'\n * }).format(123.45);\n * ```\n *\n * @example\n * ```tsx\n * const intl = useIntl();\n *\n * // You can still override the locale if needed\n * const date = new intl.DateTimeFormat({ locale: 'fr-FR' }).format(new Date());\n * // or\n * const date2 = new intl.DateTimeFormat('fr-FR').format(new Date());\n * ```\n */\nexport const useIntl = (locale?: LocalesValues) => {\n const { locale: contextLocale } = useContext(IntlayerClientContext) ?? {};\n const currentLocale = locale ?? contextLocale;\n\n return useMemo<WrappedIntl>(() => bindIntl(currentLocale), [currentLocale]);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useIntl.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useIntl.ts"],"sourcesContent":["'use client';\n\nimport { bindIntl, type WrappedIntl } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a locale-bound `Intl` object.\n *\n * It acts exactly like the native `Intl` object, but acts as a proxy to:\n * 1. Inject the current locale automatically if none is provided.\n * 2. Use the performance-optimized `CachedIntl` under the hood.\n *\n * @example\n * ```tsx\n * const intl = useIntl(); // uses context locale\n *\n * // Standard API, but no need to pass 'en-US' as the first argument\n * const formatted = new intl.NumberFormat({\n * style: 'currency',\n * currency: 'USD'\n * }).format(123.45);\n * ```\n *\n * @example\n * ```tsx\n * const intl = useIntl();\n *\n * // You can still override the locale if needed\n * const date = new intl.DateTimeFormat({ locale: 'fr-FR' }).format(new Date());\n * // or\n * const date2 = new intl.DateTimeFormat('fr-FR').format(new Date());\n * ```\n */\nexport const useIntl = (locale?: LocalesValues) => {\n const { locale: contextLocale } = useContext(IntlayerClientContext) ?? {};\n const currentLocale = locale ?? contextLocale;\n\n return useMemo<WrappedIntl>(() => bindIntl(currentLocale), [currentLocale]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,WAAW,WAA2B;CACjD,MAAM,EAAE,QAAQ,wCAA6BA,qDAAqB,KAAK,CAAC;CACxE,MAAM,gBAAgB,UAAU;CAEhC,wEAA2C,aAAa,GAAG,CAAC,aAAa,CAAC;AAC5E"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
5
4
|
const require_client_IntlayerProvider = require('../IntlayerProvider.cjs');
|
|
6
5
|
let react = require("react");
|
|
7
6
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useList.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useList.ts"],"sourcesContent":["'use client';\n\nimport { list } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a list formatter\n * bound to the current application locale.\n *\n * @returns {(values: (string | number)[], options?: ListProps) => string}\n * A function to format arrays into localized list strings.\n *\n * @example\n * ```tsx\n * const formatList = useList();\n *\n * formatList(['apple', 'banana', 'orange']);\n * // \"apple, banana, and orange\"\n *\n * formatList(['red', 'green', 'blue'], { type: 'disjunction' });\n * // \"red, green, or blue\"\n *\n * formatList([1, 2, 3], { type: 'unit', locale: 'de-DE' });\n * // \"1, 2 und 3\"\n * ```\n */\nexport const useList = () => {\n const { locale } = useContext(IntlayerClientContext) ?? {};\n\n return useCallback(\n (...args: Parameters<typeof list>) =>\n list(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useList.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useList.ts"],"sourcesContent":["'use client';\n\nimport { list } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a list formatter\n * bound to the current application locale.\n *\n * @returns {(values: (string | number)[], options?: ListProps) => string}\n * A function to format arrays into localized list strings.\n *\n * @example\n * ```tsx\n * const formatList = useList();\n *\n * formatList(['apple', 'banana', 'orange']);\n * // \"apple, banana, and orange\"\n *\n * formatList(['red', 'green', 'blue'], { type: 'disjunction' });\n * // \"red, green, or blue\"\n *\n * formatList([1, 2, 3], { type: 'unit', locale: 'de-DE' });\n * // \"1, 2 und 3\"\n * ```\n */\nexport const useList = () => {\n const { locale } = useContext(IntlayerClientContext) ?? {};\n\n return useCallback(\n (...args: Parameters<typeof list>) =>\n list(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAa,gBAAgB;CAC3B,MAAM,EAAE,iCAAsBA,qDAAqB,KAAK,CAAC;CAEzD,+BACG,GAAG,6CACG,KAAK,IAAI;EACZ,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU;CAC7B,CAAC,GACH,CAAC,MAAM,CACT;AACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
5
4
|
const require_client_IntlayerProvider = require('../IntlayerProvider.cjs');
|
|
6
5
|
let react = require("react");
|
|
7
6
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNumber.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useNumber.ts"],"sourcesContent":["'use client';\n\nimport { number } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a localized number formatter.\n *\n * Uses the current locale from {@link useLocaleBase} and returns\n * a function that can be used to format numbers consistently\n * according to the user's locale.\n *\n * @example\n * ```tsx\n * const formatNumber = useNumber();\n *\n * formatNumber(12345);\n * // e.g. \"12,345\" (en-US)\n * // e.g. \"12 345\" (fr-FR)\n *\n * formatNumber(0.75, { style: \"percent\" });\n * // e.g. \"75%\"\n * ```\n *\n * @returns {(value: string | number, options?: import(\"../createNumber\").NumberProps) => string}\n * A number formatting function bound to the active locale.\n */\nexport const useNumber = () => {\n const { locale } = useContext(IntlayerClientContext) ?? {};\n\n return useCallback(\n (...args: Parameters<typeof number>) =>\n number(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useNumber.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useNumber.ts"],"sourcesContent":["'use client';\n\nimport { number } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a localized number formatter.\n *\n * Uses the current locale from {@link useLocaleBase} and returns\n * a function that can be used to format numbers consistently\n * according to the user's locale.\n *\n * @example\n * ```tsx\n * const formatNumber = useNumber();\n *\n * formatNumber(12345);\n * // e.g. \"12,345\" (en-US)\n * // e.g. \"12 345\" (fr-FR)\n *\n * formatNumber(0.75, { style: \"percent\" });\n * // e.g. \"75%\"\n * ```\n *\n * @returns {(value: string | number, options?: import(\"../createNumber\").NumberProps) => string}\n * A number formatting function bound to the active locale.\n */\nexport const useNumber = () => {\n const { locale } = useContext(IntlayerClientContext) ?? {};\n\n return useCallback(\n (...args: Parameters<typeof number>) =>\n number(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAa,kBAAkB;CAC7B,MAAM,EAAE,iCAAsBA,qDAAqB,KAAK,CAAC;CAEzD,+BACG,GAAG,+CACK,KAAK,IAAI;EACd,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU;CAC7B,CAAC,GACH,CAAC,MAAM,CACT;AACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
5
4
|
const require_client_IntlayerProvider = require('../IntlayerProvider.cjs');
|
|
6
5
|
let react = require("react");
|
|
7
6
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePercentage.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/usePercentage.ts"],"sourcesContent":["'use client';\n\nimport { percentage } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React hook to provide a percentage formatter function\n * based on the current application locale.\n *\n * This hook retrieves the active locale using {@link useLocaleBase}\n * and memoizes a `createPercentage` instance for that locale.\n *\n * @example\n * ```tsx\n * const formatPercentage = usePercentage();\n *\n * const result = formatPercentage(0.875, { maximumFractionDigits: 1 });\n * // \"87.5%\" (depending on locale)\n * ```\n *\n * @returns {(value: string | number, options?: Omit<PercentageOptions, \"value\">) => string}\n * A function that formats numbers or numeric strings into localized percentages.\n */\nexport const usePercentage = () => {\n const { locale } = useContext(IntlayerClientContext) ?? {};\n\n return useCallback(\n (...args: Parameters<typeof percentage>) =>\n percentage(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePercentage.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/usePercentage.ts"],"sourcesContent":["'use client';\n\nimport { percentage } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React hook to provide a percentage formatter function\n * based on the current application locale.\n *\n * This hook retrieves the active locale using {@link useLocaleBase}\n * and memoizes a `createPercentage` instance for that locale.\n *\n * @example\n * ```tsx\n * const formatPercentage = usePercentage();\n *\n * const result = formatPercentage(0.875, { maximumFractionDigits: 1 });\n * // \"87.5%\" (depending on locale)\n * ```\n *\n * @returns {(value: string | number, options?: Omit<PercentageOptions, \"value\">) => string}\n * A function that formats numbers or numeric strings into localized percentages.\n */\nexport const usePercentage = () => {\n const { locale } = useContext(IntlayerClientContext) ?? {};\n\n return useCallback(\n (...args: Parameters<typeof percentage>) =>\n percentage(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAa,sBAAsB;CACjC,MAAM,EAAE,iCAAsBA,qDAAqB,KAAK,CAAC;CAEzD,+BACG,GAAG,mDACS,KAAK,IAAI;EAClB,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU;CAC7B,CAAC,GACH,CAAC,MAAM,CACT;AACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
5
4
|
const require_client_IntlayerProvider = require('../IntlayerProvider.cjs');
|
|
6
5
|
let react = require("react");
|
|
7
6
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRelativeTime.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useRelativeTime.ts"],"sourcesContent":["'use client';\n\nimport { relativeTime } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * Client-side React hook for accessing a localized relative time formatter.\n *\n * This hook:\n * - Reads the current locale from {@link useLocaleBase}.\n * - Creates a new relative time formatter with {@link createRelativeTime}.\n * - Returns a function that can format time differences into localized strings.\n *\n * Example:\n * ```tsx\n * const relativeTime = useRelativeTime();\n * const formatted = relativeTime(new Date(\"2024-08-01\"), new Date());\n * // e.g., \"2 weeks ago\"\n * ```\n *\n * @returns {ReturnType<typeof createRelativeTime>} A relative time formatting function\n * bound to the current client locale.\n */\nexport const useRelativeTime = () => {\n const { locale } = useContext(IntlayerClientContext) ?? {};\n\n return useCallback(\n (...args: Parameters<typeof relativeTime>) =>\n relativeTime(args[0], args[1], {\n ...args[2],\n locale: args[2]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRelativeTime.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useRelativeTime.ts"],"sourcesContent":["'use client';\n\nimport { relativeTime } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * Client-side React hook for accessing a localized relative time formatter.\n *\n * This hook:\n * - Reads the current locale from {@link useLocaleBase}.\n * - Creates a new relative time formatter with {@link createRelativeTime}.\n * - Returns a function that can format time differences into localized strings.\n *\n * Example:\n * ```tsx\n * const relativeTime = useRelativeTime();\n * const formatted = relativeTime(new Date(\"2024-08-01\"), new Date());\n * // e.g., \"2 weeks ago\"\n * ```\n *\n * @returns {ReturnType<typeof createRelativeTime>} A relative time formatting function\n * bound to the current client locale.\n */\nexport const useRelativeTime = () => {\n const { locale } = useContext(IntlayerClientContext) ?? {};\n\n return useCallback(\n (...args: Parameters<typeof relativeTime>) =>\n relativeTime(args[0], args[1], {\n ...args[2],\n locale: args[2]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAa,wBAAwB;CACnC,MAAM,EAAE,iCAAsBA,qDAAqB,KAAK,CAAC;CAEzD,+BACG,GAAG,qDACW,KAAK,IAAI,KAAK,IAAI;EAC7B,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU;CAC7B,CAAC,GACH,CAAC,MAAM,CACT;AACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
5
4
|
const require_client_IntlayerProvider = require('../IntlayerProvider.cjs');
|
|
6
5
|
let react = require("react");
|
|
7
6
|
let _intlayer_core_formatters = require("@intlayer/core/formatters");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUnit.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useUnit.ts"],"sourcesContent":["'use client';\n\nimport { units } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React hook that provides a unit formatting function\n * based on the current locale from {@link useLocaleBase}.\n *\n * This hook wraps {@link createUnit} to return a formatter\n * that can convert values into human-readable localized units\n * (e.g., \"10 km\", \"5 lbs\").\n *\n * @example\n * ```tsx\n * const formatUnit = useUnit();\n * const distance = formatUnit(10, { unit: \"kilometer\" });\n * // \"10 km\" (depending on locale)\n * ```\n *\n * @returns {Function} A unit formatting function that accepts a value and optional formatting options.\n */\nexport const useUnit = () => {\n const { locale } = useContext(IntlayerClientContext) ?? {};\n\n return useCallback(\n (...args: Parameters<typeof units>) =>\n units(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useUnit.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useUnit.ts"],"sourcesContent":["'use client';\n\nimport { units } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React hook that provides a unit formatting function\n * based on the current locale from {@link useLocaleBase}.\n *\n * This hook wraps {@link createUnit} to return a formatter\n * that can convert values into human-readable localized units\n * (e.g., \"10 km\", \"5 lbs\").\n *\n * @example\n * ```tsx\n * const formatUnit = useUnit();\n * const distance = formatUnit(10, { unit: \"kilometer\" });\n * // \"10 km\" (depending on locale)\n * ```\n *\n * @returns {Function} A unit formatting function that accepts a value and optional formatting options.\n */\nexport const useUnit = () => {\n const { locale } = useContext(IntlayerClientContext) ?? {};\n\n return useCallback(\n (...args: Parameters<typeof units>) =>\n units(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,gBAAgB;CAC3B,MAAM,EAAE,iCAAsBA,qDAAqB,KAAK,CAAC;CAEzD,+BACG,GAAG,8CACI,KAAK,IAAI;EACb,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU;CAC7B,CAAC,GACH,CAAC,MAAM,CACT;AACF"}
|
package/dist/cjs/client/t.cjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
4
|
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
6
5
|
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
7
6
|
let react = require("react");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"t.cjs","names":["IntlayerClientContext"],"sources":["../../../src/client/t.ts"],"sourcesContent":["'use client';\n\nimport { getTranslation } from '@intlayer/core/interpreter';\nimport type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Client-side translation function that returns the translation of the provided multilang content.\n *\n * If the locale is not provided, it will use the locale from the client context.\n *\n * @param multilangContent - An object mapping locales to their respective content.\n * @param locale - Optional locale to override the current context locale.\n * @returns The translation for the specified locale.\n *\n * @example\n * ```tsx\n * import { t } from 'react-intlayer';\n *\n * const MyComponent = () => {\n * const greeting = t({\n * en: 'Hello',\n * fr: 'Bonjour',\n * es: 'Hola',\n * });\n *\n * return <h1>{greeting}</h1>;\n * };\n * ```\n */\nexport const t = <Content = string>(\n multilangContent: StrictModeLocaleMap<Content>,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n const localeTarget = locale ?? currentLocale;\n\n return getTranslation<Content>(multilangContent, localeTarget);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"t.cjs","names":["IntlayerClientContext"],"sources":["../../../src/client/t.ts"],"sourcesContent":["'use client';\n\nimport { getTranslation } from '@intlayer/core/interpreter';\nimport type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Client-side translation function that returns the translation of the provided multilang content.\n *\n * If the locale is not provided, it will use the locale from the client context.\n *\n * @param multilangContent - An object mapping locales to their respective content.\n * @param locale - Optional locale to override the current context locale.\n * @returns The translation for the specified locale.\n *\n * @example\n * ```tsx\n * import { t } from 'react-intlayer';\n *\n * const MyComponent = () => {\n * const greeting = t({\n * en: 'Hello',\n * fr: 'Bonjour',\n * es: 'Hola',\n * });\n *\n * return <h1>{greeting}</h1>;\n * };\n * ```\n */\nexport const t = <Content = string>(\n multilangContent: StrictModeLocaleMap<Content>,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n const localeTarget = locale ?? currentLocale;\n\n return getTranslation<Content>(multilangContent, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,KACX,kBACA,WACG;CACH,MAAM,EAAE,QAAQ,wCAA6BA,qDAAqB,KAAK,CAAC;CAGxE,sDAA+B,kBAFV,UAAU,aAE8B;AAC/D"}
|