react-intlayer 9.0.0-canary.15 → 9.0.0-canary.16

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.
Files changed (74) hide show
  1. package/dist/cjs/analytics/AnalyticsProvider.cjs +16 -0
  2. package/dist/cjs/analytics/AnalyticsProvider.cjs.map +1 -0
  3. package/dist/cjs/analytics/exposureSink.cjs +27 -0
  4. package/dist/cjs/analytics/exposureSink.cjs.map +1 -0
  5. package/dist/cjs/analytics/index.cjs +10 -0
  6. package/dist/cjs/analytics/useAnalytics.cjs +55 -0
  7. package/dist/cjs/analytics/useAnalytics.cjs.map +1 -0
  8. package/dist/cjs/analytics/useConversion.cjs +33 -0
  9. package/dist/cjs/analytics/useConversion.cjs.map +1 -0
  10. package/dist/cjs/analytics/useExperiment.cjs +66 -0
  11. package/dist/cjs/analytics/useExperiment.cjs.map +1 -0
  12. package/dist/cjs/client/IntlayerProvider.cjs +6 -1
  13. package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
  14. package/dist/cjs/index.cjs +8 -0
  15. package/dist/cjs/index.cjs.map +1 -1
  16. package/dist/cjs/plugins.cjs +31 -14
  17. package/dist/cjs/plugins.cjs.map +1 -1
  18. package/dist/esm/analytics/AnalyticsProvider.mjs +15 -0
  19. package/dist/esm/analytics/AnalyticsProvider.mjs.map +1 -0
  20. package/dist/esm/analytics/exposureSink.mjs +24 -0
  21. package/dist/esm/analytics/exposureSink.mjs.map +1 -0
  22. package/dist/esm/analytics/index.mjs +6 -0
  23. package/dist/esm/analytics/useAnalytics.mjs +53 -0
  24. package/dist/esm/analytics/useAnalytics.mjs.map +1 -0
  25. package/dist/esm/analytics/useConversion.mjs +31 -0
  26. package/dist/esm/analytics/useConversion.mjs.map +1 -0
  27. package/dist/esm/analytics/useExperiment.mjs +64 -0
  28. package/dist/esm/analytics/useExperiment.mjs.map +1 -0
  29. package/dist/esm/client/IntlayerProvider.mjs +6 -1
  30. package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
  31. package/dist/esm/index.mjs +5 -1
  32. package/dist/esm/index.mjs.map +1 -1
  33. package/dist/esm/plugins.mjs +31 -14
  34. package/dist/esm/plugins.mjs.map +1 -1
  35. package/dist/types/analytics/AnalyticsProvider.d.ts +11 -0
  36. package/dist/types/analytics/AnalyticsProvider.d.ts.map +1 -0
  37. package/dist/types/analytics/exposureSink.d.ts +33 -0
  38. package/dist/types/analytics/exposureSink.d.ts.map +1 -0
  39. package/dist/types/analytics/index.d.ts +5 -0
  40. package/dist/types/analytics/useAnalytics.d.ts +15 -0
  41. package/dist/types/analytics/useAnalytics.d.ts.map +1 -0
  42. package/dist/types/analytics/useConversion.d.ts +27 -0
  43. package/dist/types/analytics/useConversion.d.ts.map +1 -0
  44. package/dist/types/analytics/useExperiment.d.ts +41 -0
  45. package/dist/types/analytics/useExperiment.d.ts.map +1 -0
  46. package/dist/types/client/IntlayerProvider.d.ts.map +1 -1
  47. package/dist/types/client/format/useCompact.d.ts +2 -2
  48. package/dist/types/client/format/useCompact.d.ts.map +1 -1
  49. package/dist/types/client/format/useCurrency.d.ts +2 -2
  50. package/dist/types/client/format/useCurrency.d.ts.map +1 -1
  51. package/dist/types/client/format/useList.d.ts +2 -2
  52. package/dist/types/client/format/useList.d.ts.map +1 -1
  53. package/dist/types/client/format/useNumber.d.ts +2 -2
  54. package/dist/types/client/format/useNumber.d.ts.map +1 -1
  55. package/dist/types/client/format/usePercentage.d.ts +2 -2
  56. package/dist/types/client/format/usePercentage.d.ts.map +1 -1
  57. package/dist/types/client/format/useRelativeTime.d.ts +2 -2
  58. package/dist/types/client/format/useRelativeTime.d.ts.map +1 -1
  59. package/dist/types/client/format/useUnit.d.ts +2 -2
  60. package/dist/types/client/format/useUnit.d.ts.map +1 -1
  61. package/dist/types/client/useDictionary.d.ts +1 -1
  62. package/dist/types/client/useI18n.d.ts +1 -1
  63. package/dist/types/client/useLocaleBase.d.ts +3 -3
  64. package/dist/types/client/useLocaleBase.d.ts.map +1 -1
  65. package/dist/types/client/useLocaleStorage.d.ts +5 -5
  66. package/dist/types/client/useLocaleStorage.d.ts.map +1 -1
  67. package/dist/types/index.d.ts +5 -4
  68. package/dist/types/index.d.ts.map +1 -1
  69. package/dist/types/intlayer/dist/types/index.d.ts +4 -0
  70. package/dist/types/plugins.d.ts.map +1 -1
  71. package/dist/types/server/useDictionary.d.ts +1 -1
  72. package/dist/types/server/useDictionaryAsync.d.ts +1 -1
  73. package/dist/types/server/useI18n.d.ts +1 -1
  74. package/package.json +19 -9
@@ -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;AACxE,8CAAc;AAEd,QAAO"}
@@ -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;AAClE,QAAO;;;;;;;;AAST,MAAa,kBAAkB,UAA+B;AAC5D,QAAO,MAAM"}
@@ -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,55 @@
1
+ 'use client';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
5
+ const require_analytics_exposureSink = require('./exposureSink.cjs');
6
+ const require_client_IntlayerProvider = require('../client/IntlayerProvider.cjs');
7
+ let react = require("react");
8
+ let _intlayer_analytics_isEnabled = require("@intlayer/analytics/isEnabled");
9
+
10
+ //#region src/analytics/useAnalytics.tsx
11
+ /**
12
+ * Initializes the Intlayer analytics client singleton when analytics is enabled
13
+ * and keeps it aware of the current locale.
14
+ *
15
+ * Mirrors {@link useEditor}: the module is loaded via a dynamic `import()` so it
16
+ * ships as its own async chunk, off the critical rendering path. Apps that
17
+ * don't opt in (`analytics.enabled !== true`) pay nothing — the whole body is
18
+ * guarded by `INTLAYER_ANALYTICS_ENABLED` and dead-code-eliminated at build
19
+ * time.
20
+ */
21
+ const useAnalytics = () => {
22
+ const { locale } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {};
23
+ const clientRef = (0, react.useRef)(null);
24
+ (0, react.useEffect)(() => {
25
+ if (process.env.INTLAYER_ANALYTICS_ENABLED === "false" || !_intlayer_analytics_isEnabled.isEnabled) return;
26
+ let cancelled = false;
27
+ let initialized = false;
28
+ import("@intlayer/analytics").then(({ initAnalyticsClient, buildContentExposure }) => {
29
+ if (cancelled) return;
30
+ const client = initAnalyticsClient();
31
+ initialized = true;
32
+ clientRef.current = client;
33
+ if (locale) client.setLocale(locale);
34
+ client.trackPageView({ reason: "initial" });
35
+ require_analytics_exposureSink.setExposureSink((input) => client.trackContentExposure(buildContentExposure(input)));
36
+ }).catch(() => {});
37
+ return () => {
38
+ cancelled = true;
39
+ clientRef.current = null;
40
+ require_analytics_exposureSink.setExposureSink(null);
41
+ import("@intlayer/analytics").then(({ stopAnalyticsClient }) => {
42
+ if (initialized) stopAnalyticsClient();
43
+ }).catch(() => {});
44
+ };
45
+ }, []);
46
+ (0, react.useEffect)(() => {
47
+ if (!locale || !clientRef.current) return;
48
+ clientRef.current.setLocale(locale);
49
+ clientRef.current.trackPageView({ reason: "locale_change" });
50
+ }, [locale]);
51
+ };
52
+
53
+ //#endregion
54
+ exports.useAnalytics = useAnalytics;
55
+ //# 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,sDAAsB,IAAI,EAAE;CAC1D,MAAM,8BAA2C,KAAK;AAEtD,4BAAgB;AACd,MAAI,QAAQ,IAAI,+BAA+B,WAAW,CAACC,wCACzD;EAGF,IAAI,YAAY;EAKhB,IAAI,cAAc;AAElB,SAAO,uBACJ,MAAM,EAAE,qBAAqB,2BAA2B;AACvD,OAAI,UAAW;GAEf,MAAM,SAAS,qBAAqB;AACpC,iBAAc;AACd,aAAU,UAAU;AAEpB,OAAI,OAAQ,QAAO,UAAU,OAAO;AACpC,UAAO,cAAc,EAAE,QAAQ,WAAW,CAAC;AAI3C,mDAAiB,UACf,OAAO,qBAAqB,qBAAqB,MAAM,CAAC,CACzD;IACD,CACD,YAAY,GAEX;AAEJ,eAAa;AACX,eAAY;AACZ,aAAU,UAAU;AACpB,kDAAgB,KAAK;AACrB,UAAO,uBACJ,MAAM,EAAE,0BAA0B;AACjC,QAAI,YAAa,sBAAqB;KACtC,CACD,YAAY,GAAG;;IAInB,EAAE,CAAC;AAEN,4BAAgB;AACd,MAAI,CAAC,UAAU,CAAC,UAAU,QAAS;AAEnC,YAAU,QAAQ,UAAU,OAAO;AACnC,YAAU,QAAQ,cAAc,EAAE,QAAQ,iBAAiB,CAAC;IAC3D,CAAC,OAAO,CAAC"}
@@ -0,0 +1,33 @@
1
+ 'use client';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
5
+ let react = require("react");
6
+ let _intlayer_analytics_isEnabled = require("@intlayer/analytics/isEnabled");
7
+
8
+ //#region src/analytics/useConversion.tsx
9
+ /**
10
+ * Returns a stable `trackConversion` callback for content A/B testing. Safe to
11
+ * call from any component: it resolves to a no-op when analytics is disabled
12
+ * or the client has not been initialized yet.
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * const trackConversion = useConversion();
17
+ * <button onClick={() => trackConversion({
18
+ * experimentKey: 'homepage-hero', variant: 'b', goal: 'cta_click',
19
+ * })}>Get started</button>
20
+ * ```
21
+ */
22
+ const useConversion = () => {
23
+ return (0, react.useCallback)((params) => {
24
+ if (process.env.INTLAYER_ANALYTICS_ENABLED === "false" || !_intlayer_analytics_isEnabled.isEnabled) return;
25
+ import("@intlayer/analytics").then(({ getGlobalAnalyticsClient }) => {
26
+ getGlobalAnalyticsClient()?.trackConversion(params);
27
+ }).catch(() => {});
28
+ }, []);
29
+ };
30
+
31
+ //#endregion
32
+ exports.useConversion = useConversion;
33
+ //# 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;AACjC,gCAAoB,WAA6B;AAC/C,MAAI,QAAQ,IAAI,+BAA+B,WAAW,CAACA,wCACzD;AAGF,SAAO,uBACJ,MAAM,EAAE,+BAA+B;AACtC,6BAA0B,EAAE,gBAAgB,OAAO;IACnD,CACD,YAAY,GAAG;IACjB,EAAE,CAAC"}
@@ -0,0 +1,66 @@
1
+ 'use client';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
5
+ let react = require("react");
6
+ let _intlayer_analytics_isEnabled = require("@intlayer/analytics/isEnabled");
7
+
8
+ //#region src/analytics/useExperiment.tsx
9
+ /**
10
+ * Assigns this session to a variant of an A/B experiment and records the
11
+ * exposure, scoped to `experimentKey`, so the backend can compute per-variant
12
+ * conversion rates against `useConversion` events.
13
+ *
14
+ * Assignment is deterministic per session (no server round-trip, stable across
15
+ * re-mounts). The exposure is recorded once per mount.
16
+ *
17
+ * @param experimentKey - Unique key identifying the experiment.
18
+ * @param variants - The candidate variant names; the first one is the control.
19
+ * @param weights - Optional relative weights, one per variant (e.g. `[9, 1]`).
20
+ * @returns The {@link ExperimentState} for this session.
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * const { variant } = useExperiment('homepage-hero', ['a', 'b']);
25
+ * const content = useIntlayer(variant === 'b' ? 'hero-b' : 'hero');
26
+ * ```
27
+ */
28
+ const useExperiment = (experimentKey, variants, weights) => {
29
+ const [state, setState] = (0, react.useState)({
30
+ variant: variants[0] ?? "",
31
+ isAssigned: false
32
+ });
33
+ (0, react.useEffect)(() => {
34
+ if (process.env.INTLAYER_ANALYTICS_ENABLED === "false" || !_intlayer_analytics_isEnabled.isEnabled) return;
35
+ let cancelled = false;
36
+ let initialized = false;
37
+ import("@intlayer/analytics").then(({ initAnalyticsClient }) => {
38
+ if (cancelled) return;
39
+ const client = initAnalyticsClient();
40
+ initialized = true;
41
+ const variant = client.getVariant(experimentKey, variants, weights);
42
+ setState({
43
+ variant,
44
+ isAssigned: true
45
+ });
46
+ client.trackContentExposure({
47
+ dictionaryKey: experimentKey,
48
+ keyPath: "",
49
+ nodeType: "experiment",
50
+ experimentKey,
51
+ variant
52
+ });
53
+ }).catch(() => {});
54
+ return () => {
55
+ cancelled = true;
56
+ import("@intlayer/analytics").then(({ stopAnalyticsClient }) => {
57
+ if (initialized) stopAnalyticsClient();
58
+ }).catch(() => {});
59
+ };
60
+ }, [experimentKey]);
61
+ return state;
62
+ };
63
+
64
+ //#endregion
65
+ exports.useExperiment = useExperiment;
66
+ //# 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;EACb,CAAC;AAEF,4BAAgB;AACd,MAAI,QAAQ,IAAI,+BAA+B,WAAW,CAACA,wCACzD;EAGF,IAAI,YAAY;EAChB,IAAI,cAAc;AAElB,SAAO,uBACJ,MAAM,EAAE,0BAA0B;AACjC,OAAI,UAAW;GAIf,MAAM,SAAS,qBAAqB;AACpC,iBAAc;GAEd,MAAM,UAAU,OAAO,WAAW,eAAe,UAAU,QAAQ;AACnE,YAAS;IAAE;IAAS,YAAY;IAAM,CAAC;AAGvC,UAAO,qBAAqB;IAC1B,eAAe;IACf,SAAS;IACT,UAAU;IACV;IACA;IACD,CAAC;IACF,CACD,YAAY,GAEX;AAEJ,eAAa;AACX,eAAY;AACZ,UAAO,uBACJ,MAAM,EAAE,0BAA0B;AACjC,QAAI,YAAa,sBAAqB;KACtC,CACD,YAAY,GAAG;;IAKnB,CAAC,cAAc,CAAC;AAEnB,QAAO"}
@@ -4,6 +4,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
  const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
5
5
  const require_editor_EditorProvider = require('../editor/EditorProvider.cjs');
6
6
  const require_client_useLocaleStorage = require('./useLocaleStorage.cjs');
7
+ const require_analytics_AnalyticsProvider = require('../analytics/AnalyticsProvider.cjs');
7
8
  let _intlayer_config_built = require("@intlayer/config/built");
8
9
  let react = require("react");
9
10
  let react_jsx_runtime = require("react/jsx-runtime");
@@ -84,7 +85,11 @@ const IntlayerProviderContent = ({ locale: localeProp, defaultLocale: defaultLoc
84
85
  */
85
86
  const IntlayerProvider = ({ children, ...props }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(IntlayerProviderContent, {
86
87
  ...props,
87
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_editor_EditorProvider.EditorProvider, {}), children]
88
+ children: [
89
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_editor_EditorProvider.EditorProvider, {}),
90
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_analytics_AnalyticsProvider.AnalyticsProvider, {}),
91
+ children
92
+ ]
88
93
  });
89
94
 
90
95
  //#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":";;;;;;;;;;;;;;;;AA2BA,MAAa,iDAAqD;CAChE,QAAQA,mDAAmBC,6CAAsB;CACjD,iBAAiB;CACjB,iBAAiB;CAClB,CAAC;;;;;;AAOF,MAAa,iDAAsC,sBAAsB,IAAI,EAAE;;;;;;;;;AAoC/E,MAAa,2BAAsD,EACjE,QAAQ,YACR,eAAe,mBACf,UACA,WAAW,eACX,eACA,sBACI;CACJ,MAAM,EAAE,SAAS,kBAAkB,eAAe,wBAChDA,+CAAwB,EAAE;CAK5B,MAAM,CAAC,eAAe,wCAFpB,cAAcD,mDAAmB,qBAAqB,oBAGhB;AAGxC,4BAAgB;AACd,MAAI,cAAc,eAAe,cAC/B,kBAAiB,WAAW;IAE7B,CAAC,WAAW,CAAC;AAEhB,4BAAgB;AACd,sDAAuB;IACtB,EAAE,CAAC;CAEN,MAAM,iBAAiB,cAA6B;AAClD,MAAI,cAAc,UAAU,KAAK,UAAU,UAAU,CAAE;AAEvD,MAAI,CAAC,kBAAkB,IAAI,OAAO,CAAC,SAAS,UAAU,EAAE;AACtD,WAAQ,MAAM,UAAU,UAAU,mBAAmB;AACrD;;AAGF,mBAAiB,UAAU;AAC3B,qDAAmB,WAAW,gBAAgB;;CAGhD,MAAM,YAAY,iBAAiB;CAGnC,MAAM,iEAAgC,cAAc;AAEpD,QACE,2CAAC,sBAAsB,UAAvB;EACE,OAAO;GACL,QAAQ;GACR;GACA;GACD;EAEA;EAC8B;;;;;;;;;;;;;;;;;;;;;;AAwBrC,MAAa,oBAA+C,EAC1D,UACA,GAAG,YAEH,4CAAC,yBAAD;CAAyB,GAAI;WAA7B,CACE,2CAACE,8CAAD,EAAkB,GACjB,SACuB"}
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;CAClB,CAAC;;;;;;AAOF,MAAa,iDAAsC,sBAAsB,IAAI,EAAE;;;;;;;;;AAoC/E,MAAa,2BAAsD,EACjE,QAAQ,YACR,eAAe,mBACf,UACA,WAAW,eACX,eACA,sBACI;CACJ,MAAM,EAAE,SAAS,kBAAkB,eAAe,wBAChDA,+CAAwB,EAAE;CAK5B,MAAM,CAAC,eAAe,wCAFpB,cAAcD,mDAAmB,qBAAqB,oBAGhB;AAGxC,4BAAgB;AACd,MAAI,cAAc,eAAe,cAC/B,kBAAiB,WAAW;IAE7B,CAAC,WAAW,CAAC;AAEhB,4BAAgB;AACd,sDAAuB;IACtB,EAAE,CAAC;CAEN,MAAM,iBAAiB,cAA6B;AAClD,MAAI,cAAc,UAAU,KAAK,UAAU,UAAU,CAAE;AAEvD,MAAI,CAAC,kBAAkB,IAAI,OAAO,CAAC,SAAS,UAAU,EAAE;AACtD,WAAQ,MAAM,UAAU,UAAU,mBAAmB;AACrD;;AAGF,mBAAiB,UAAU;AAC3B,qDAAmB,WAAW,gBAAgB;;CAGhD,MAAM,YAAY,iBAAiB;CAGnC,MAAM,iEAAgC,cAAc;AAEpD,QACE,2CAAC,sBAAsB,UAAvB;EACE,OAAO;GACL,QAAQ;GACR;GACA;GACD;EAEA;EAC8B;;;;;;;;;;;;;;;;;;;;;;AAwBrC,MAAa,oBAA+C,EAC1D,UACA,GAAG,YAEH,4CAAC,yBAAD;CAAyB,GAAI;WAA7B;EACE,2CAACE,8CAAD,EAAkB;EAClB,2CAACC,uDAAD,EAAqB;EACpB;EACuB"}
@@ -4,6 +4,10 @@ const require_getIntlayer = require('./getIntlayer.cjs');
4
4
  const require_getDictionary = require('./getDictionary.cjs');
5
5
  const require_client_useLocaleStorage = require('./client/useLocaleStorage.cjs');
6
6
  const require_client_IntlayerProvider = require('./client/IntlayerProvider.cjs');
7
+ const require_analytics_useAnalytics = require('./analytics/useAnalytics.cjs');
8
+ const require_analytics_AnalyticsProvider = require('./analytics/AnalyticsProvider.cjs');
9
+ const require_analytics_useConversion = require('./analytics/useConversion.cjs');
10
+ const require_analytics_useExperiment = require('./analytics/useExperiment.cjs');
7
11
  const require_client_format_useIntl = require('./client/format/useIntl.cjs');
8
12
  const require_client_t = require('./client/t.cjs');
9
13
  const require_client_useDictionary = require('./client/useDictionary.cjs');
@@ -40,6 +44,7 @@ const useMarkdownRenderer = require_markdown_MarkdownRenderer.useMarkdownRendere
40
44
  const MarkdownRenderer = require_markdown_MarkdownRenderer.MarkdownRenderer;
41
45
 
42
46
  //#endregion
47
+ exports.AnalyticsProvider = require_analytics_AnalyticsProvider.AnalyticsProvider;
43
48
  exports.IntlayerClientContext = require_client_IntlayerProvider.IntlayerClientContext;
44
49
  exports.IntlayerProvider = require_client_IntlayerProvider.IntlayerProvider;
45
50
  exports.IntlayerProviderContent = require_client_IntlayerProvider.IntlayerProviderContent;
@@ -53,9 +58,12 @@ exports.renderMarkdown = renderMarkdown;
53
58
  exports.setLocaleCookie = require_client_useLocaleStorage.setLocaleCookie;
54
59
  exports.setLocaleInStorage = require_client_useLocaleStorage.setLocaleInStorage;
55
60
  exports.t = require_client_t.t;
61
+ exports.useAnalytics = require_analytics_useAnalytics.useAnalytics;
62
+ exports.useConversion = require_analytics_useConversion.useConversion;
56
63
  exports.useDictionary = require_client_useDictionary.useDictionary;
57
64
  exports.useDictionaryAsync = require_client_useDictionaryAsync.useDictionaryAsync;
58
65
  exports.useDictionaryDynamic = require_client_useDictionaryDynamic.useDictionaryDynamic;
66
+ exports.useExperiment = require_analytics_useExperiment.useExperiment;
59
67
  exports.useI18n = require_client_useI18n.useI18n;
60
68
  exports.useIntl = require_client_format_useIntl.useIntl;
61
69
  exports.useIntlayer = require_client_useIntlayer.useIntlayer;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["_MarkdownProvider","_useMarkdownContext","_renderMarkdown","_useMarkdownRenderer","_MarkdownRenderer"],"sources":["../../src/index.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { IInterpreterPluginReact } from './plugins';\n\ndeclare module '@intlayer/core/interpreter' {\n interface IInterpreterPlugin<T, S, L extends LocalesValues>\n extends IInterpreterPluginReact<T, S, L> {}\n}\n\n/**\n * @deprecated import from react-intlayer/format instead\n */\nexport { useIntl } from './client/format/useIntl';\n// Import directly from individual files to avoid circular dependency issues\nexport type { IntlayerProviderProps } from './client/IntlayerProvider';\nexport {\n IntlayerClientContext,\n IntlayerProvider,\n IntlayerProviderContent,\n useIntlayerContext,\n} from './client/IntlayerProvider';\nexport { t } from './client/t';\nexport { useDictionary } from './client/useDictionary';\nexport { useDictionaryAsync } from './client/useDictionaryAsync';\nexport { useDictionaryDynamic } from './client/useDictionaryDynamic';\nexport { useI18n } from './client/useI18n';\nexport { useIntlayer } from './client/useIntlayer';\nexport { useLoadDynamic } from './client/useLoadDynamic';\nexport type { UseLocaleProps, UseLocaleResult } from './client/useLocale';\nexport { useLocale } from './client/useLocale';\nexport { useLocaleBase } from './client/useLocaleBase';\nexport {\n localeCookie,\n localeInStorage,\n setLocaleCookie,\n setLocaleInStorage,\n useLocaleCookie,\n useLocaleStorage,\n} from './client/useLocaleStorage';\nexport { useRewriteURL } from './client/useRewriteURL';\nexport { getDictionary } from './getDictionary';\nexport { getIntlayer } from './getIntlayer';\nexport type { IntlayerNode } from './IntlayerNode';\n\nimport type {\n MarkdownProviderOptions as _MarkdownProviderOptions,\n MarkdownRendererProps as _MarkdownRendererProps,\n RenderMarkdownProps as _RenderMarkdownProps,\n} from './markdown';\nimport {\n MarkdownProvider as _MarkdownProvider,\n MarkdownRenderer as _MarkdownRenderer,\n renderMarkdown as _renderMarkdown,\n useMarkdownContext as _useMarkdownContext,\n useMarkdownRenderer as _useMarkdownRenderer,\n} from './markdown';\n/**\n * @deprecated import from react-intlayer/markdown instead\n */\nexport const MarkdownProvider = _MarkdownProvider;\n/**\n * @deprecated import from react-intlayer/markdown instead\n */\nexport const useMarkdownContext = _useMarkdownContext;\n/**\n * @deprecated import from react-intlayer/markdown instead\n */\nexport type MarkdownProviderOptions = _MarkdownProviderOptions;\n/**\n * @deprecated import from react-intlayer/markdown instead\n */\nexport const renderMarkdown = _renderMarkdown;\n/**\n * @deprecated import from react-intlayer/markdown instead\n */\nexport const useMarkdownRenderer = _useMarkdownRenderer;\n/**\n * @deprecated import from react-intlayer/markdown instead\n */\nexport const MarkdownRenderer = _MarkdownRenderer;\n/**\n * @deprecated import from react-intlayer/markdown instead\n */\nexport type RenderMarkdownProps = _RenderMarkdownProps;\n/**\n * @deprecated import from react-intlayer/markdown instead\n */\nexport type MarkdownRendererProps = _MarkdownRendererProps;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA0DA,MAAa,mBAAmBA;;;;AAIhC,MAAa,qBAAqBC;;;;AAQlC,MAAa,iBAAiBC;;;;AAI9B,MAAa,sBAAsBC;;;;AAInC,MAAa,mBAAmBC"}
1
+ {"version":3,"file":"index.cjs","names":["_MarkdownProvider","_useMarkdownContext","_renderMarkdown","_useMarkdownRenderer","_MarkdownRenderer"],"sources":["../../src/index.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { IInterpreterPluginReact } from './plugins';\n\ndeclare module '@intlayer/core/interpreter' {\n interface IInterpreterPlugin<T, S, L extends LocalesValues>\n extends IInterpreterPluginReact<T, S, L> {}\n}\n\nexport { AnalyticsProvider } from './analytics/AnalyticsProvider';\nexport { useAnalytics } from './analytics/useAnalytics';\nexport type { ConversionParams } from './analytics/useConversion';\nexport { useConversion } from './analytics/useConversion';\nexport type { ExperimentState } from './analytics/useExperiment';\nexport { useExperiment } from './analytics/useExperiment';\n/**\n * @deprecated import from react-intlayer/format instead\n */\nexport { useIntl } from './client/format/useIntl';\n// Import directly from individual files to avoid circular dependency issues\nexport type { IntlayerProviderProps } from './client/IntlayerProvider';\nexport {\n IntlayerClientContext,\n IntlayerProvider,\n IntlayerProviderContent,\n useIntlayerContext,\n} from './client/IntlayerProvider';\nexport { t } from './client/t';\nexport { useDictionary } from './client/useDictionary';\nexport { useDictionaryAsync } from './client/useDictionaryAsync';\nexport { useDictionaryDynamic } from './client/useDictionaryDynamic';\nexport { useI18n } from './client/useI18n';\nexport { useIntlayer } from './client/useIntlayer';\nexport { useLoadDynamic } from './client/useLoadDynamic';\nexport type { UseLocaleProps, UseLocaleResult } from './client/useLocale';\nexport { useLocale } from './client/useLocale';\nexport { useLocaleBase } from './client/useLocaleBase';\nexport {\n localeCookie,\n localeInStorage,\n setLocaleCookie,\n setLocaleInStorage,\n useLocaleCookie,\n useLocaleStorage,\n} from './client/useLocaleStorage';\nexport { useRewriteURL } from './client/useRewriteURL';\nexport { getDictionary } from './getDictionary';\nexport { getIntlayer } from './getIntlayer';\nexport type { IntlayerNode } from './IntlayerNode';\n\nimport type {\n MarkdownProviderOptions as _MarkdownProviderOptions,\n MarkdownRendererProps as _MarkdownRendererProps,\n RenderMarkdownProps as _RenderMarkdownProps,\n} from './markdown';\nimport {\n MarkdownProvider as _MarkdownProvider,\n MarkdownRenderer as _MarkdownRenderer,\n renderMarkdown as _renderMarkdown,\n useMarkdownContext as _useMarkdownContext,\n useMarkdownRenderer as _useMarkdownRenderer,\n} from './markdown';\n/**\n * @deprecated import from react-intlayer/markdown instead\n */\nexport const MarkdownProvider = _MarkdownProvider;\n/**\n * @deprecated import from react-intlayer/markdown instead\n */\nexport const useMarkdownContext = _useMarkdownContext;\n/**\n * @deprecated import from react-intlayer/markdown instead\n */\nexport type MarkdownProviderOptions = _MarkdownProviderOptions;\n/**\n * @deprecated import from react-intlayer/markdown instead\n */\nexport const renderMarkdown = _renderMarkdown;\n/**\n * @deprecated import from react-intlayer/markdown instead\n */\nexport const useMarkdownRenderer = _useMarkdownRenderer;\n/**\n * @deprecated import from react-intlayer/markdown instead\n */\nexport const MarkdownRenderer = _MarkdownRenderer;\n/**\n * @deprecated import from react-intlayer/markdown instead\n */\nexport type RenderMarkdownProps = _RenderMarkdownProps;\n/**\n * @deprecated import from react-intlayer/markdown instead\n */\nexport type MarkdownRendererProps = _MarkdownRendererProps;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,MAAa,mBAAmBA;;;;AAIhC,MAAa,qBAAqBC;;;;AAQlC,MAAa,iBAAiBC;;;;AAI9B,MAAa,sBAAsBC;;;;AAInC,MAAa,mBAAmBC"}
@@ -1,5 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ const require_analytics_exposureSink = require('./analytics/exposureSink.cjs');
3
4
  const require_client_useLoadDynamic = require('./client/useLoadDynamic.cjs');
4
5
  const require_editor_ContentSelector = require('./editor/ContentSelector.cjs');
5
6
  const require_IntlayerNode = require('./IntlayerNode.cjs');
@@ -19,27 +20,43 @@ const htmlRendererModulePromise = process.env.INTLAYER_NODE_TYPE_HTML !== "false
19
20
  const intlayerNodePlugins = {
20
21
  id: "intlayer-node-plugin",
21
22
  canHandle: (node) => typeof node === "bigint" || typeof node === "string" || typeof node === "number",
22
- transform: (_node, { plugins, ...rest }) => require_IntlayerNode.renderIntlayerNode({
23
- ...rest,
24
- value: rest.children,
25
- children: process.env.INTLAYER_EDITOR_ENABLED !== "false" && _intlayer_config_built.editor.enabled ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_editor_ContentSelector.ContentSelector, {
23
+ transform: (_node, { plugins, ...rest }) => {
24
+ if (process.env.INTLAYER_ANALYTICS_ENABLED !== "false") require_analytics_exposureSink.reportExposure({
25
+ dictionaryKey: rest.dictionaryKey,
26
+ keyPath: rest.keyPath,
27
+ locale: rest.locale,
28
+ nodeType: "text"
29
+ });
30
+ return require_IntlayerNode.renderIntlayerNode({
26
31
  ...rest,
27
- children: rest.children
28
- }) : rest.children
29
- })
32
+ value: rest.children,
33
+ children: process.env.INTLAYER_EDITOR_ENABLED !== "false" && _intlayer_config_built.editor.enabled ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_editor_ContentSelector.ContentSelector, {
34
+ ...rest,
35
+ children: rest.children
36
+ }) : rest.children
37
+ });
38
+ }
30
39
  };
31
40
  /** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
32
41
  const reactNodePlugins = process.env.INTLAYER_NODE_TYPE_REACT_NODE === "false" ? _intlayer_core_interpreter.fallbackPlugin : {
33
42
  id: "react-node-plugin",
34
43
  canHandle: (node) => typeof node === "object" && typeof node?.props !== "undefined" && typeof node.key !== "undefined",
35
- transform: (node, { plugins, ...rest }) => require_IntlayerNode.renderIntlayerNode({
36
- ...rest,
37
- value: "[[react-element]]",
38
- children: process.env.INTLAYER_EDITOR_ENABLED !== "false" && _intlayer_config_built.editor.enabled ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_editor_ContentSelector.ContentSelector, {
44
+ transform: (node, { plugins, ...rest }) => {
45
+ if (process.env.INTLAYER_ANALYTICS_ENABLED !== "false") require_analytics_exposureSink.reportExposure({
46
+ dictionaryKey: rest.dictionaryKey,
47
+ keyPath: rest.keyPath,
48
+ locale: rest.locale,
49
+ nodeType: "react-node"
50
+ });
51
+ return require_IntlayerNode.renderIntlayerNode({
39
52
  ...rest,
40
- children: require_reactElement_renderReactElement.renderReactElement(node)
41
- }) : require_reactElement_renderReactElement.renderReactElement(node)
42
- })
53
+ value: "[[react-element]]",
54
+ children: process.env.INTLAYER_EDITOR_ENABLED !== "false" && _intlayer_config_built.editor.enabled ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_editor_ContentSelector.ContentSelector, {
55
+ ...rest,
56
+ children: require_reactElement_renderReactElement.renderReactElement(node)
57
+ }) : require_reactElement_renderReactElement.renderReactElement(node)
58
+ });
59
+ }
43
60
  };
44
61
  /**
45
62
  * Split insertion string and join with React nodes using shared core logic
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.cjs","names":["renderIntlayerNode","editor","ContentSelector","fallbackPlugin","renderReactElement","Fragment","NodeTypes","func","useLoadDynamic","internationalization","enumerationPlugin","conditionPlugin","filePlugin","genderPlugin"],"sources":["../../src/plugins.tsx"],"sourcesContent":["import { editor, internationalization } from '@intlayer/config/built';\nimport {\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n fallbackPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n nestedPlugin,\n type Plugins,\n pluralPlugin,\n splitInsertionTemplate,\n translationPlugin,\n} from '@intlayer/core/interpreter';\nimport { getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type {\n HTMLContent,\n InsertionContent,\n MarkdownContent,\n} from '@intlayer/core/transpiler';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport {\n createElement,\n type FC,\n Fragment,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport { useLoadDynamic } from './client/useLoadDynamic';\nimport { ContentSelector } from './editor/ContentSelector';\nimport type { HTMLComponents } from './html/HTMLComponentTypes';\nimport { type IntlayerNode, renderIntlayerNode } from './IntlayerNode';\nimport { renderReactElement } from './reactElement/renderReactElement';\n\nconst markdownRendererModulePromise =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN !== 'false'\n ? import('./markdown/MarkdownRendererPlugin').then(\n (m) => m.MarkdownRendererPlugin\n )\n : null;\n\nconst htmlRendererModulePromise =\n process.env.INTLAYER_NODE_TYPE_HTML !== 'false'\n ? import('./html/HTMLRendererPlugin').then((m) => m.HTMLRendererPlugin)\n : null;\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const intlayerNodePlugins: Plugins = {\n id: 'intlayer-node-plugin',\n canHandle: (node) =>\n typeof node === 'bigint' ||\n typeof node === 'string' ||\n typeof node === 'number',\n transform: (\n _node,\n {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n }\n ) =>\n renderIntlayerNode({\n ...rest,\n value: rest.children,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' && editor.enabled ? (\n <ContentSelector {...rest}>{rest.children}</ContentSelector>\n ) : (\n rest.children\n ),\n }),\n};\n\n/** ---------------------------------------------\n * REACT NODE PLUGIN\n * --------------------------------------------- */\n\nexport type ReactNodeCond<T> = T extends {\n props: any;\n key: any;\n}\n ? ReactNode\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const reactNodePlugins: Plugins =\n process.env.INTLAYER_NODE_TYPE_REACT_NODE === 'false'\n ? fallbackPlugin\n : {\n id: 'react-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' &&\n typeof node?.props !== 'undefined' &&\n typeof node.key !== 'undefined',\n\n transform: (\n node,\n {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n }\n ) =>\n renderIntlayerNode({\n ...rest,\n value: '[[react-element]]',\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n {renderReactElement(node)}\n </ContentSelector>\n ) : (\n renderReactElement(node)\n ),\n }),\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer I;\n fields: readonly string[];\n}\n ? <V extends { [K in T['fields'][number]]: ReactNode }>(\n values: V\n ) => I extends string\n ? V[keyof V] extends string | number\n ? IntlayerNode<string>\n : IntlayerNode<ReactNode>\n : DeepTransformContent<I>\n : never;\n\n/**\n * Split insertion string and join with React nodes using shared core logic\n */\nconst splitAndJoinInsertion = (\n template: string,\n values: Record<string, string | number | ReactNode>\n): ReactNode => {\n const result = splitInsertionTemplate(template, values);\n\n if (result.isSimple) {\n // Simple string replacement\n return result.parts as string;\n }\n\n // Return as Fragment with proper keys\n return createElement(\n Fragment,\n null,\n ...(result.parts as any[]).map((part, index) =>\n createElement(Fragment, { key: index }, part)\n )\n );\n};\n\n/** Insertion plugin for React. Handles component/node insertion. */\nexport const insertionPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_INSERTION === 'false'\n ? fallbackPlugin\n : {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.INSERTION,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.INSERTION,\n },\n ];\n\n const children = node[NodeTypes.INSERTION];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]:\n | string\n | number\n | ReactNode;\n }\n ) => {\n const result = splitAndJoinInsertion(transformedResult, values);\n\n return deepTransformNode(result, {\n ...subProps,\n plugins: props.plugins,\n children: result,\n });\n };\n },\n };\n\n const result = deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n\n if (\n typeof children === 'object' &&\n children !== null &&\n 'nodeType' in children &&\n [NodeTypes.ENUMERATION, NodeTypes.CONDITION].includes(\n children.nodeType as\n | typeof NodeTypes.ENUMERATION\n | typeof NodeTypes.CONDITION\n )\n ) {\n return (values: any) => (arg: any) => {\n const func = result as Function;\n const inner = func(arg);\n\n if (typeof inner === 'function') {\n return inner(values);\n }\n return inner;\n };\n }\n\n return result;\n },\n };\n\n/**\n * MARKDOWN PLUGIN\n */\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<\n string,\n {\n metadata: DeepTransformContent<string>;\n use: (components: HTMLComponents<'permissive', {}>) => ReactNode;\n }\n >\n : never;\n\nconst MarkdownSuspenseRenderer: FC<Record<string, any>> = ({\n children,\n ...props\n}) => {\n const MarkdownRendererPlugin = useLoadDynamic(\n 'markdown-renderer-plugin',\n markdownRendererModulePromise!\n );\n return createElement(MarkdownRendererPlugin as any, { ...props, children });\n};\n\n/** Markdown string plugin. Replaces string node with a component that render the markdown. */\nexport const markdownStringPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, props, deepTransformNode) => {\n const {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n } = props;\n\n const metadata = getMarkdownMetadata(node) ?? {};\n\n const metadataPlugins: Plugins = {\n id: 'markdown-metadata-plugin',\n canHandle: (metadataNode) =>\n typeof metadataNode === 'string' ||\n typeof metadataNode === 'number' ||\n typeof metadataNode === 'boolean' ||\n !metadataNode,\n transform: (metadataNode, props) =>\n renderIntlayerNode({\n ...props,\n value: metadataNode,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>{node}</ContentSelector>\n ) : (\n node\n ),\n }),\n };\n\n // Transform metadata while keeping the same structure\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n const render = (components?: HTMLComponents) =>\n renderIntlayerNode({\n ...props,\n value: node,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n <MarkdownSuspenseRenderer {...rest} components={components}>\n {node}\n </MarkdownSuspenseRenderer>\n </ContentSelector>\n ) : (\n <MarkdownSuspenseRenderer {...rest} components={components}>\n {node}\n </MarkdownSuspenseRenderer>\n ),\n additionalProps: {\n metadata: metadataNodes,\n },\n });\n\n const element = render() as unknown as ReactElement;\n\n return new Proxy(element, {\n get(target, prop, receiver) {\n if (prop === 'value') return node;\n if (prop === Symbol.toPrimitive) return () => node;\n if (prop === 'toString') return () => node;\n if (prop === 'valueOf') return () => node;\n if (typeof prop === 'string' && prop !== 'constructor') {\n const method = (String.prototype as any)[prop];\n if (typeof method === 'function') return method.bind(node);\n }\n if (prop === 'metadata') return metadataNodes;\n if (prop === 'use')\n return (components?: HTMLComponents) => render(components);\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n },\n };\n\nexport type MarkdownCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.MARKDOWN]: infer M;\n tags?: infer U;\n metadata?: infer V;\n}\n ? IntlayerNode<\n M,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n metadata: DeepTransformContent<V>;\n }\n >\n : never;\n\nexport const markdownPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.MARKDOWN,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.MARKDOWN,\n },\n ];\n\n const children = node[NodeTypes.MARKDOWN];\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [markdownStringPlugin, ...(props.plugins ?? [])],\n });\n },\n };\n\n/** ---------------------------------------------\n * HTML PLUGIN\n * --------------------------------------------- */\n\n/**\n * HTML conditional type that enforces:\n * - All components (Standard or Custom) are OPTIONAL in the `use()` method.\n * - Custom components props are strictly inferred from the dictionary definition.\n *\n * This ensures type safety:\n * - `html('<div>Hello <CustomComponent /></div>').use({ CustomComponent: ... })` - optional but typed\n */\nexport type HTMLPluginCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.HTML]: infer I;\n tags?: infer U;\n}\n ? IntlayerNode<\n I,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n }\n >\n : never;\n\nconst HTMLSuspenseRenderer: FC<Record<string, any>> = (props) => {\n const HTMLRendererPlugin = useLoadDynamic(\n 'html-renderer-plugin',\n htmlRendererModulePromise!\n );\n return createElement(HTMLRendererPlugin as any, props);\n};\n\n/** HTML plugin. Replaces node with a function that takes components => ReactNode. */\nexport const htmlPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_HTML === 'false'\n ? fallbackPlugin\n : {\n id: 'html-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.HTML,\n\n transform: (node: HTMLContent<string>, props) => {\n const html = node[NodeTypes.HTML];\n const { plugins, ...rest } = props;\n\n // Type-safe render function that accepts properly typed components\n const render = (userComponents?: HTMLComponents): ReactNode =>\n renderIntlayerNode({\n ...rest,\n value: html,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n <HTMLSuspenseRenderer\n {...rest}\n html={html}\n userComponents={userComponents}\n />\n </ContentSelector>\n ) : (\n <HTMLSuspenseRenderer\n {...rest}\n html={html}\n userComponents={userComponents}\n />\n ),\n });\n\n const element = render() as unknown as ReactElement;\n\n return new Proxy(element, {\n get(target, prop, receiver) {\n if (prop === 'value') return html;\n if (prop === Symbol.toPrimitive) return () => html;\n if (prop === 'toString') return () => html;\n if (prop === 'valueOf') return () => html;\n if (typeof prop === 'string' && prop !== 'constructor') {\n const method = (String.prototype as any)[prop];\n if (typeof method === 'function') return method.bind(html);\n }\n if (prop === 'use')\n return (userComponents?: HTMLComponents) =>\n render(userComponents);\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n },\n };\n\n/** ---------------------------------------------\n * PLUGINS RESULT\n * --------------------------------------------- */\n\nexport type IInterpreterPluginReact<T, _S, _L extends LocalesValues> = {\n reactNode: ReactNodeCond<T>;\n reactIntlayerNode: IntlayerNodeCond<T>;\n reactInsertion: InsertionCond<T>;\n reactMarkdown: MarkdownCond<T>;\n reactHtml: HTMLPluginCond<T>;\n};\n\n/**\n * Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.\n *\n * Otherwise the the `react-intlayer` plugins will override the types of `intlayer` functions.\n */\nexport type IInterpreterPluginState = Omit<\n IInterpreterPluginStateCore,\n 'insertion' // Remove insertion type from core package\n> & {\n reactNode: true;\n reactIntlayerNode: true;\n reactMarkdown: true;\n reactHtml: true;\n reactInsertion: true;\n};\n\nexport type DeepTransformContent<\n T,\n L extends LocalesValues = DeclaredLocales,\n> = DeepTransformContentCore<T, IInterpreterPluginState, L>;\n\nconst pluginsCache = new Map<string, Plugins[]>();\n\n/**\n * Get the plugins array for React content transformation.\n * This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.\n */\nexport const getPlugins = (\n locale?: LocalesValues,\n fallback: boolean = true\n): Plugins[] => {\n const currentLocale = locale ?? internationalization.defaultLocale;\n const cacheKey = `${currentLocale}_${fallback}`;\n\n if (pluginsCache.has(cacheKey)) {\n return pluginsCache.get(cacheKey)!;\n }\n\n const plugins = [\n // Env var allows the bundler to to remove the plugin if not used to make the bundle smaller\n translationPlugin(\n locale ?? internationalization.defaultLocale,\n fallback ? internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n pluralPlugin(locale ?? internationalization.defaultLocale),\n conditionPlugin,\n nestedPlugin(locale ?? internationalization.defaultLocale),\n\n filePlugin,\n genderPlugin,\n // Always include: handle plain strings/numbers and React elements\n intlayerNodePlugins,\n reactNodePlugins,\n insertionPlugin,\n markdownPlugin,\n htmlPlugin,\n ] as Plugins[];\n\n pluginsCache.set(cacheKey, plugins);\n\n return plugins;\n};\n"],"mappings":";;;;;;;;;;;;;;;A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AAM,SAAS;KAE7C,CAAC;;CAEL;AAmCP,MAAM,+BAAe,IAAI,KAAwB;;;;;AAMjD,MAAa,cACX,QACA,WAAoB,SACN;CAEd,MAAM,WAAW,GADK,UAAUO,4CAAqB,cACnB,GAAG;AAErC,KAAI,aAAa,IAAI,SAAS,CAC5B,QAAO,aAAa,IAAI,SAAS;CAGnC,MAAM,UAAU;oDAGZ,UAAUA,4CAAqB,eAC/B,WAAWA,4CAAqB,gBAAgB,OACjD;EACDC;+CACa,UAAUD,4CAAqB,cAAc;EAC1DE;+CACa,UAAUF,4CAAqB,cAAc;EAE1DG;EACAC;EAEA;EACA;EACA;EACA;EACA;EACD;AAED,cAAa,IAAI,UAAU,QAAQ;AAEnC,QAAO"}
1
+ {"version":3,"file":"plugins.cjs","names":["renderIntlayerNode","editor","ContentSelector","fallbackPlugin","renderReactElement","Fragment","NodeTypes","func","useLoadDynamic","internationalization","enumerationPlugin","conditionPlugin","filePlugin","genderPlugin"],"sources":["../../src/plugins.tsx"],"sourcesContent":["import { editor, internationalization } from '@intlayer/config/built';\nimport {\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n fallbackPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n nestedPlugin,\n type Plugins,\n pluralPlugin,\n splitInsertionTemplate,\n translationPlugin,\n} from '@intlayer/core/interpreter';\nimport { getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type {\n HTMLContent,\n InsertionContent,\n MarkdownContent,\n} from '@intlayer/core/transpiler';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport {\n createElement,\n type FC,\n Fragment,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport { reportExposure } from './analytics/exposureSink';\nimport { useLoadDynamic } from './client/useLoadDynamic';\nimport { ContentSelector } from './editor/ContentSelector';\nimport type { HTMLComponents } from './html/HTMLComponentTypes';\nimport { type IntlayerNode, renderIntlayerNode } from './IntlayerNode';\nimport { renderReactElement } from './reactElement/renderReactElement';\n\nconst markdownRendererModulePromise =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN !== 'false'\n ? import('./markdown/MarkdownRendererPlugin').then(\n (m) => m.MarkdownRendererPlugin\n )\n : null;\n\nconst htmlRendererModulePromise =\n process.env.INTLAYER_NODE_TYPE_HTML !== 'false'\n ? import('./html/HTMLRendererPlugin').then((m) => m.HTMLRendererPlugin)\n : null;\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const intlayerNodePlugins: Plugins = {\n id: 'intlayer-node-plugin',\n canHandle: (node) =>\n typeof node === 'bigint' ||\n typeof node === 'string' ||\n typeof node === 'number',\n transform: (\n _node,\n {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n }\n ) => {\n // Node-level analytics: record which content is resolved for display.\n // No-op (and dead-code-eliminated) when analytics is disabled.\n if (process.env.INTLAYER_ANALYTICS_ENABLED !== 'false') {\n reportExposure({\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n locale: rest.locale,\n nodeType: 'text',\n });\n }\n\n return renderIntlayerNode({\n ...rest,\n value: rest.children,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' && editor.enabled ? (\n <ContentSelector {...rest}>{rest.children}</ContentSelector>\n ) : (\n rest.children\n ),\n });\n },\n};\n\n/** ---------------------------------------------\n * REACT NODE PLUGIN\n * --------------------------------------------- */\n\nexport type ReactNodeCond<T> = T extends {\n props: any;\n key: any;\n}\n ? ReactNode\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const reactNodePlugins: Plugins =\n process.env.INTLAYER_NODE_TYPE_REACT_NODE === 'false'\n ? fallbackPlugin\n : {\n id: 'react-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' &&\n typeof node?.props !== 'undefined' &&\n typeof node.key !== 'undefined',\n\n transform: (\n node,\n {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n }\n ) => {\n if (process.env.INTLAYER_ANALYTICS_ENABLED !== 'false') {\n reportExposure({\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n locale: rest.locale,\n nodeType: 'react-node',\n });\n }\n\n return renderIntlayerNode({\n ...rest,\n value: '[[react-element]]',\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n {renderReactElement(node)}\n </ContentSelector>\n ) : (\n renderReactElement(node)\n ),\n });\n },\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer I;\n fields: readonly string[];\n}\n ? <V extends { [K in T['fields'][number]]: ReactNode }>(\n values: V\n ) => I extends string\n ? V[keyof V] extends string | number\n ? IntlayerNode<string>\n : IntlayerNode<ReactNode>\n : DeepTransformContent<I>\n : never;\n\n/**\n * Split insertion string and join with React nodes using shared core logic\n */\nconst splitAndJoinInsertion = (\n template: string,\n values: Record<string, string | number | ReactNode>\n): ReactNode => {\n const result = splitInsertionTemplate(template, values);\n\n if (result.isSimple) {\n // Simple string replacement\n return result.parts as string;\n }\n\n // Return as Fragment with proper keys\n return createElement(\n Fragment,\n null,\n ...(result.parts as any[]).map((part, index) =>\n createElement(Fragment, { key: index }, part)\n )\n );\n};\n\n/** Insertion plugin for React. Handles component/node insertion. */\nexport const insertionPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_INSERTION === 'false'\n ? fallbackPlugin\n : {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.INSERTION,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.INSERTION,\n },\n ];\n\n const children = node[NodeTypes.INSERTION];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]:\n | string\n | number\n | ReactNode;\n }\n ) => {\n const result = splitAndJoinInsertion(transformedResult, values);\n\n return deepTransformNode(result, {\n ...subProps,\n plugins: props.plugins,\n children: result,\n });\n };\n },\n };\n\n const result = deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n\n if (\n typeof children === 'object' &&\n children !== null &&\n 'nodeType' in children &&\n [NodeTypes.ENUMERATION, NodeTypes.CONDITION].includes(\n children.nodeType as\n | typeof NodeTypes.ENUMERATION\n | typeof NodeTypes.CONDITION\n )\n ) {\n return (values: any) => (arg: any) => {\n const func = result as Function;\n const inner = func(arg);\n\n if (typeof inner === 'function') {\n return inner(values);\n }\n return inner;\n };\n }\n\n return result;\n },\n };\n\n/**\n * MARKDOWN PLUGIN\n */\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<\n string,\n {\n metadata: DeepTransformContent<string>;\n use: (components: HTMLComponents<'permissive', {}>) => ReactNode;\n }\n >\n : never;\n\nconst MarkdownSuspenseRenderer: FC<Record<string, any>> = ({\n children,\n ...props\n}) => {\n const MarkdownRendererPlugin = useLoadDynamic(\n 'markdown-renderer-plugin',\n markdownRendererModulePromise!\n );\n return createElement(MarkdownRendererPlugin as any, { ...props, children });\n};\n\n/** Markdown string plugin. Replaces string node with a component that render the markdown. */\nexport const markdownStringPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, props, deepTransformNode) => {\n const {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n } = props;\n\n const metadata = getMarkdownMetadata(node) ?? {};\n\n const metadataPlugins: Plugins = {\n id: 'markdown-metadata-plugin',\n canHandle: (metadataNode) =>\n typeof metadataNode === 'string' ||\n typeof metadataNode === 'number' ||\n typeof metadataNode === 'boolean' ||\n !metadataNode,\n transform: (metadataNode, props) =>\n renderIntlayerNode({\n ...props,\n value: metadataNode,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>{node}</ContentSelector>\n ) : (\n node\n ),\n }),\n };\n\n // Transform metadata while keeping the same structure\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n const render = (components?: HTMLComponents) =>\n renderIntlayerNode({\n ...props,\n value: node,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n <MarkdownSuspenseRenderer {...rest} components={components}>\n {node}\n </MarkdownSuspenseRenderer>\n </ContentSelector>\n ) : (\n <MarkdownSuspenseRenderer {...rest} components={components}>\n {node}\n </MarkdownSuspenseRenderer>\n ),\n additionalProps: {\n metadata: metadataNodes,\n },\n });\n\n const element = render() as unknown as ReactElement;\n\n return new Proxy(element, {\n get(target, prop, receiver) {\n if (prop === 'value') return node;\n if (prop === Symbol.toPrimitive) return () => node;\n if (prop === 'toString') return () => node;\n if (prop === 'valueOf') return () => node;\n if (typeof prop === 'string' && prop !== 'constructor') {\n const method = (String.prototype as any)[prop];\n if (typeof method === 'function') return method.bind(node);\n }\n if (prop === 'metadata') return metadataNodes;\n if (prop === 'use')\n return (components?: HTMLComponents) => render(components);\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n },\n };\n\nexport type MarkdownCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.MARKDOWN]: infer M;\n tags?: infer U;\n metadata?: infer V;\n}\n ? IntlayerNode<\n M,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n metadata: DeepTransformContent<V>;\n }\n >\n : never;\n\nexport const markdownPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.MARKDOWN,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.MARKDOWN,\n },\n ];\n\n const children = node[NodeTypes.MARKDOWN];\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [markdownStringPlugin, ...(props.plugins ?? [])],\n });\n },\n };\n\n/** ---------------------------------------------\n * HTML PLUGIN\n * --------------------------------------------- */\n\n/**\n * HTML conditional type that enforces:\n * - All components (Standard or Custom) are OPTIONAL in the `use()` method.\n * - Custom components props are strictly inferred from the dictionary definition.\n *\n * This ensures type safety:\n * - `html('<div>Hello <CustomComponent /></div>').use({ CustomComponent: ... })` - optional but typed\n */\nexport type HTMLPluginCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.HTML]: infer I;\n tags?: infer U;\n}\n ? IntlayerNode<\n I,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n }\n >\n : never;\n\nconst HTMLSuspenseRenderer: FC<Record<string, any>> = (props) => {\n const HTMLRendererPlugin = useLoadDynamic(\n 'html-renderer-plugin',\n htmlRendererModulePromise!\n );\n return createElement(HTMLRendererPlugin as any, props);\n};\n\n/** HTML plugin. Replaces node with a function that takes components => ReactNode. */\nexport const htmlPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_HTML === 'false'\n ? fallbackPlugin\n : {\n id: 'html-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.HTML,\n\n transform: (node: HTMLContent<string>, props) => {\n const html = node[NodeTypes.HTML];\n const { plugins, ...rest } = props;\n\n // Type-safe render function that accepts properly typed components\n const render = (userComponents?: HTMLComponents): ReactNode =>\n renderIntlayerNode({\n ...rest,\n value: html,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n <HTMLSuspenseRenderer\n {...rest}\n html={html}\n userComponents={userComponents}\n />\n </ContentSelector>\n ) : (\n <HTMLSuspenseRenderer\n {...rest}\n html={html}\n userComponents={userComponents}\n />\n ),\n });\n\n const element = render() as unknown as ReactElement;\n\n return new Proxy(element, {\n get(target, prop, receiver) {\n if (prop === 'value') return html;\n if (prop === Symbol.toPrimitive) return () => html;\n if (prop === 'toString') return () => html;\n if (prop === 'valueOf') return () => html;\n if (typeof prop === 'string' && prop !== 'constructor') {\n const method = (String.prototype as any)[prop];\n if (typeof method === 'function') return method.bind(html);\n }\n if (prop === 'use')\n return (userComponents?: HTMLComponents) =>\n render(userComponents);\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n },\n };\n\n/** ---------------------------------------------\n * PLUGINS RESULT\n * --------------------------------------------- */\n\nexport type IInterpreterPluginReact<T, _S, _L extends LocalesValues> = {\n reactNode: ReactNodeCond<T>;\n reactIntlayerNode: IntlayerNodeCond<T>;\n reactInsertion: InsertionCond<T>;\n reactMarkdown: MarkdownCond<T>;\n reactHtml: HTMLPluginCond<T>;\n};\n\n/**\n * Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.\n *\n * Otherwise the the `react-intlayer` plugins will override the types of `intlayer` functions.\n */\nexport type IInterpreterPluginState = Omit<\n IInterpreterPluginStateCore,\n 'insertion' // Remove insertion type from core package\n> & {\n reactNode: true;\n reactIntlayerNode: true;\n reactMarkdown: true;\n reactHtml: true;\n reactInsertion: true;\n};\n\nexport type DeepTransformContent<\n T,\n L extends LocalesValues = DeclaredLocales,\n> = DeepTransformContentCore<T, IInterpreterPluginState, L>;\n\nconst pluginsCache = new Map<string, Plugins[]>();\n\n/**\n * Get the plugins array for React content transformation.\n * This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.\n */\nexport const getPlugins = (\n locale?: LocalesValues,\n fallback: boolean = true\n): Plugins[] => {\n const currentLocale = locale ?? internationalization.defaultLocale;\n const cacheKey = `${currentLocale}_${fallback}`;\n\n if (pluginsCache.has(cacheKey)) {\n return pluginsCache.get(cacheKey)!;\n }\n\n const plugins = [\n // Env var allows the bundler to to remove the plugin if not used to make the bundle smaller\n translationPlugin(\n locale ?? internationalization.defaultLocale,\n fallback ? internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n pluralPlugin(locale ?? internationalization.defaultLocale),\n conditionPlugin,\n nestedPlugin(locale ?? internationalization.defaultLocale),\n\n filePlugin,\n genderPlugin,\n // Always include: handle plain strings/numbers and React elements\n intlayerNodePlugins,\n reactNodePlugins,\n insertionPlugin,\n markdownPlugin,\n htmlPlugin,\n ] as Plugins[];\n\n pluginsCache.set(cacheKey, plugins);\n\n return plugins;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AA0CA,MAAM,gCACJ,QAAQ,IAAI,gCAAgC,+CACxC,0CAA4C,MACzC,MAAM,EAAE,uBACV,GACD;AAEN,MAAM,4BACJ,QAAQ,IAAI,4BAA4B,+CACpC,kCAAoC,MAAM,MAAM,EAAE,mBAAmB,GACrE;;AAWN,MAAa,sBAA+B;CAC1C,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAChB,OAAO,SAAS,YAChB,OAAO,SAAS;CAClB,YACE,OACA,EACE,SACA,GAAG,WAEF;AAGH,MAAI,QAAQ,IAAI,+BAA+B,QAC7C,+CAAe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cACX,QACA,WAAoB,SACN;CAEd,MAAM,WAAW,GADK,UAAUO,4CAAqB,cACnB,GAAG;AAErC,KAAI,aAAa,IAAI,SAAS,CAC5B,QAAO,aAAa,IAAI,SAAS;CAGnC,MAAM,UAAU;oDAGZ,UAAUA,4CAAqB,eAC/B,WAAWA,4CAAqB,gBAAgB,OACjD;EACDC;+CACa,UAAUD,4CAAqB,cAAc;EAC1DE;+CACa,UAAUF,4CAAqB,cAAc;EAE1DG;EACAC;EAEA;EACA;EACA;EACA;EACA;EACD;AAED,cAAa,IAAI,UAAU,QAAQ;AAEnC,QAAO"}
@@ -0,0 +1,15 @@
1
+ import { useAnalytics } from "./useAnalytics.mjs";
2
+
3
+ //#region src/analytics/AnalyticsProvider.tsx
4
+ /**
5
+ * Runs {@link useAnalytics} and renders its children unchanged. Mounted inside
6
+ * {@link IntlayerProvider} alongside `EditorProvider`.
7
+ */
8
+ const AnalyticsProvider = ({ children }) => {
9
+ useAnalytics();
10
+ return children;
11
+ };
12
+
13
+ //#endregion
14
+ export { AnalyticsProvider };
15
+ //# sourceMappingURL=AnalyticsProvider.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnalyticsProvider.mjs","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;AACxE,eAAc;AAEd,QAAO"}
@@ -0,0 +1,24 @@
1
+ //#region src/analytics/exposureSink.ts
2
+ let sink = null;
3
+ /**
4
+ * Installs (or clears) the exposure sink. `useAnalytics` sets this once the
5
+ * analytics client has loaded, and clears it on unmount.
6
+ *
7
+ * @param next - The sink to install, or `null` to clear.
8
+ */
9
+ const setExposureSink = (next) => {
10
+ sink = next;
11
+ };
12
+ /**
13
+ * Forwards a content exposure to the installed sink. A cheap null-check when
14
+ * analytics is not running, so it is safe to call from every node resolution.
15
+ *
16
+ * @param input - The node metadata to report.
17
+ */
18
+ const reportExposure = (input) => {
19
+ sink?.(input);
20
+ };
21
+
22
+ //#endregion
23
+ export { reportExposure, setExposureSink };
24
+ //# sourceMappingURL=exposureSink.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exposureSink.mjs","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;AAClE,QAAO;;;;;;;;AAST,MAAa,kBAAkB,UAA+B;AAC5D,QAAO,MAAM"}
@@ -0,0 +1,6 @@
1
+ import { useAnalytics } from "./useAnalytics.mjs";
2
+ import { AnalyticsProvider } from "./AnalyticsProvider.mjs";
3
+ import { useConversion } from "./useConversion.mjs";
4
+ import { useExperiment } from "./useExperiment.mjs";
5
+
6
+ export { AnalyticsProvider, useAnalytics, useConversion, useExperiment };