preact-intlayer 9.5.9-canary.0 → 9.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/IntlayerNode.cjs +16 -18
- package/dist/cjs/IntlayerNode.cjs.map +1 -1
- package/dist/cjs/analytics/useAnalytics.cjs +2 -2
- package/dist/cjs/analytics/useConversion.cjs +1 -1
- package/dist/cjs/analytics/useExperiment.cjs +1 -1
- package/dist/cjs/client/IntlayerProvider.cjs +30 -24
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/t.cjs +1 -1
- package/dist/cjs/client/useDictionary.cjs +2 -2
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +2 -2
- package/dist/cjs/client/useIntlayer.cjs +2 -2
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +1 -1
- package/dist/cjs/client/useLocaleBase.cjs +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +12 -1
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
- package/dist/cjs/client/useTraduction.cjs +1 -1
- package/dist/cjs/editor/ContentSelector.cjs +1 -1
- package/dist/cjs/editor/useEditor.cjs +1 -1
- package/dist/cjs/format/index.cjs +4 -4
- package/dist/cjs/html/HTMLProvider.cjs +1 -1
- package/dist/cjs/html/HTMLRenderer.cjs +1 -1
- package/dist/cjs/index.cjs +5 -3
- package/dist/cjs/markdown/MarkdownProvider.cjs +1 -1
- package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs +1 -1
- package/dist/cjs/markdown/compiler.cjs.map +1 -1
- package/dist/cjs/plugins.cjs +32 -47
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/esm/IntlayerNode.mjs +16 -18
- package/dist/esm/IntlayerNode.mjs.map +1 -1
- package/dist/esm/analytics/useAnalytics.mjs +2 -2
- package/dist/esm/analytics/useConversion.mjs +1 -1
- package/dist/esm/analytics/useExperiment.mjs +1 -1
- package/dist/esm/client/IntlayerProvider.mjs +31 -25
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/t.mjs +1 -1
- package/dist/esm/client/useDictionary.mjs +2 -2
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +2 -2
- package/dist/esm/client/useIntlayer.mjs +2 -2
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +1 -1
- package/dist/esm/client/useLocaleBase.mjs +1 -1
- package/dist/esm/client/useLocaleStorage.mjs +13 -3
- package/dist/esm/client/useLocaleStorage.mjs.map +1 -1
- package/dist/esm/client/useTraduction.mjs +1 -1
- package/dist/esm/editor/ContentSelector.mjs +1 -1
- package/dist/esm/editor/useEditor.mjs +1 -1
- package/dist/esm/format/index.mjs +4 -4
- package/dist/esm/html/HTMLProvider.mjs +1 -1
- package/dist/esm/html/HTMLRenderer.mjs +1 -1
- package/dist/esm/index.mjs +4 -3
- package/dist/esm/markdown/MarkdownProvider.mjs +1 -1
- package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs +1 -1
- package/dist/esm/markdown/compiler.mjs.map +1 -1
- package/dist/esm/plugins.mjs +32 -47
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/types/IntlayerNode.d.ts +10 -0
- package/dist/types/IntlayerNode.d.ts.map +1 -1
- package/dist/types/client/IntlayerProvider.d.ts.map +1 -1
- package/dist/types/client/useContent.d.ts +1 -2
- package/dist/types/client/useContent.d.ts.map +1 -1
- package/dist/types/client/useLocaleBase.d.ts +4 -5
- package/dist/types/client/useLocaleBase.d.ts.map +1 -1
- package/dist/types/client/useLocaleStorage.d.ts +14 -5
- package/dist/types/client/useLocaleStorage.d.ts.map +1 -1
- package/dist/types/format/useCompact.d.ts +1 -2
- package/dist/types/format/useCompact.d.ts.map +1 -1
- package/dist/types/format/useCurrency.d.ts +1 -2
- package/dist/types/format/useCurrency.d.ts.map +1 -1
- package/dist/types/format/useList.d.ts +1 -2
- package/dist/types/format/useList.d.ts.map +1 -1
- package/dist/types/format/useNumber.d.ts +1 -2
- package/dist/types/format/useNumber.d.ts.map +1 -1
- package/dist/types/format/usePercentage.d.ts +1 -2
- package/dist/types/format/usePercentage.d.ts.map +1 -1
- package/dist/types/format/useRelativeTime.d.ts +1 -2
- package/dist/types/format/useRelativeTime.d.ts.map +1 -1
- package/dist/types/format/useUnit.d.ts +1 -2
- package/dist/types/format/useUnit.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/markdown/MarkdownProvider.d.ts +3 -3
- package/dist/types/markdown/MarkdownProvider.d.ts.map +1 -1
- package/dist/types/markdown/compiler.d.ts +6 -1
- package/dist/types/markdown/compiler.d.ts.map +1 -1
- package/dist/types/plugins.d.ts.map +1 -1
- package/package.json +9 -9
- package/dist/types/intlayer/dist/types/index.d.ts +0 -14
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
let preact = require("preact");
|
|
3
|
+
let _intlayer_core_utils = require("@intlayer/core/utils");
|
|
3
4
|
|
|
4
5
|
//#region src/IntlayerNode.tsx
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return Reflect.get(target, prop, receiver);
|
|
21
|
-
} });
|
|
22
|
-
};
|
|
6
|
+
/**
|
|
7
|
+
* Renders content as a Preact vnode that also behaves like its value
|
|
8
|
+
* (`node.value`, `${node}`, `node.toUpperCase()`).
|
|
9
|
+
*
|
|
10
|
+
* The node is a copy of the vnode built on a shared prototype serving the
|
|
11
|
+
* value's members, rather than a Proxy, so the renderer reads plain fields.
|
|
12
|
+
*
|
|
13
|
+
* @param props - The value, the rendered children and extra node members.
|
|
14
|
+
* @returns The renderable node.
|
|
15
|
+
*/
|
|
16
|
+
const renderIntlayerNode = ({ children, value, additionalProps }) => Object.setPrototypeOf({
|
|
17
|
+
...(0, preact.isValidElement)(children) ? children : (0, preact.h)(preact.Fragment, {}, children),
|
|
18
|
+
value,
|
|
19
|
+
...additionalProps
|
|
20
|
+
}, (0, _intlayer_core_utils.getIntlayerNodePrototype)(value));
|
|
23
21
|
|
|
24
22
|
//#endregion
|
|
25
23
|
exports.renderIntlayerNode = renderIntlayerNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerNode.cjs","names":["isValidElement","h","Fragment"],"sources":["../../src/IntlayerNode.tsx"],"sourcesContent":["import type { NodeProps } from '@intlayer/core/interpreter';\nimport type { ResolvedEditor } from '@intlayer/types/module_augmentation';\nimport {\n type ComponentChildren,\n Fragment,\n h,\n isValidElement,\n type VNode,\n} from 'preact';\n\nexport type IntlayerNode<\n T = NodeProps['children'],\n AdditionalProps = {},\n> = ResolvedEditor<T, VNode> & {\n value: T;\n} & AdditionalProps &\n T;\n\ntype RenderIntlayerNodeProps<T> = {\n value: T;\n children: ComponentChildren;\n additionalProps?: { [key: string]: any };\n};\n\
|
|
1
|
+
{"version":3,"file":"IntlayerNode.cjs","names":["isValidElement","h","Fragment","getIntlayerNodePrototype"],"sources":["../../src/IntlayerNode.tsx"],"sourcesContent":["import type { NodeProps } from '@intlayer/core/interpreter';\nimport { getIntlayerNodePrototype } from '@intlayer/core/utils';\nimport type { ResolvedEditor } from '@intlayer/types/module_augmentation';\nimport {\n type ComponentChildren,\n Fragment,\n h,\n isValidElement,\n type VNode,\n} from 'preact';\n\nexport type IntlayerNode<\n T = NodeProps['children'],\n AdditionalProps = {},\n> = ResolvedEditor<T, VNode> & {\n value: T;\n} & AdditionalProps &\n T;\n\ntype RenderIntlayerNodeProps<T> = {\n value: T;\n children: ComponentChildren;\n additionalProps?: { [key: string]: any };\n};\n\n/**\n * Renders content as a Preact vnode that also behaves like its value\n * (`node.value`, `${node}`, `node.toUpperCase()`).\n *\n * The node is a copy of the vnode built on a shared prototype serving the\n * value's members, rather than a Proxy, so the renderer reads plain fields.\n *\n * @param props - The value, the rendered children and extra node members.\n * @returns The renderable node.\n */\nexport const renderIntlayerNode = <\n T, // Broadened to support arrays, numbers, objects, etc.\n>({\n children,\n value,\n additionalProps,\n}: RenderIntlayerNodeProps<T>): IntlayerNode<T> =>\n // Fields first, prototype last: set the other way round, each field would\n // first look for a setter along the prototype chain, through its Proxy\n Object.setPrototypeOf(\n {\n ...(isValidElement(children) ? children : h(Fragment, {}, children)),\n value,\n ...additionalProps,\n },\n getIntlayerNodePrototype(value)\n );\n"],"mappings":";;;;;;;;;;;;;;;AAmCA,MAAa,sBAEX,EACA,UACA,OACA,sBAIA,OAAO,eACL;CACE,OAAIA,uBAAe,QAAQ,IAAI,eAAWC,UAAEC,iBAAU,CAAC,GAAG,QAAQ;CAClE;CACA,GAAG;AACL,OACAC,+CAAyB,KAAK,CAChC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_client_IntlayerProvider = require('../client/IntlayerProvider.cjs');
|
|
3
2
|
const require_analytics_exposureSink = require('./exposureSink.cjs');
|
|
4
|
-
|
|
3
|
+
const require_client_IntlayerProvider = require('../client/IntlayerProvider.cjs');
|
|
5
4
|
let preact_hooks = require("preact/hooks");
|
|
5
|
+
let _intlayer_analytics_isEnabled = require("@intlayer/analytics/isEnabled");
|
|
6
6
|
|
|
7
7
|
//#region src/analytics/useAnalytics.tsx
|
|
8
8
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
let _intlayer_analytics_isEnabled = require("@intlayer/analytics/isEnabled");
|
|
3
2
|
let preact_hooks = require("preact/hooks");
|
|
3
|
+
let _intlayer_analytics_isEnabled = require("@intlayer/analytics/isEnabled");
|
|
4
4
|
|
|
5
5
|
//#region src/analytics/useConversion.ts
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
let _intlayer_analytics_isEnabled = require("@intlayer/analytics/isEnabled");
|
|
3
2
|
let preact_hooks = require("preact/hooks");
|
|
3
|
+
let _intlayer_analytics_isEnabled = require("@intlayer/analytics/isEnabled");
|
|
4
4
|
|
|
5
5
|
//#region src/analytics/useExperiment.ts
|
|
6
6
|
/**
|
|
@@ -2,19 +2,21 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_editor_EditorProvider = require('../editor/EditorProvider.cjs');
|
|
3
3
|
const require_client_useLocaleStorage = require('./useLocaleStorage.cjs');
|
|
4
4
|
const require_analytics_AnalyticsProvider = require('../analytics/AnalyticsProvider.cjs');
|
|
5
|
-
let preact_hooks = require("preact/hooks");
|
|
6
5
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
7
|
-
let _intlayer_config_client = require("@intlayer/config/client");
|
|
8
|
-
let _intlayer_core_localization = require("@intlayer/core/localization");
|
|
9
6
|
let preact = require("preact");
|
|
7
|
+
let preact_hooks = require("preact/hooks");
|
|
10
8
|
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
9
|
+
let _intlayer_config_client = require("@intlayer/config/client");
|
|
10
|
+
let _intlayer_core_localization = require("@intlayer/core/localization");
|
|
11
11
|
|
|
12
12
|
//#region src/client/IntlayerProvider.tsx
|
|
13
13
|
/**
|
|
14
14
|
* Context that store the current locale on the client side
|
|
15
15
|
*/
|
|
16
16
|
const IntlayerClientContext = (0, preact.createContext)({
|
|
17
|
-
locale
|
|
17
|
+
get locale() {
|
|
18
|
+
return require_client_useLocaleStorage.getLocaleInStorage() ?? _intlayer_config_built.internationalization?.defaultLocale;
|
|
19
|
+
},
|
|
18
20
|
setLocale: () => null
|
|
19
21
|
});
|
|
20
22
|
/**
|
|
@@ -26,35 +28,39 @@ const useIntlayerContext = () => (0, preact_hooks.useContext)(IntlayerClientCont
|
|
|
26
28
|
*/
|
|
27
29
|
const IntlayerProviderContent = ({ locale: localeProp, defaultLocale: defaultLocaleProp, variant, children, setLocale: setLocaleProp, isCookieEnabled }) => {
|
|
28
30
|
const { defaultLocale: defaultLocaleConfig, locales: availableLocales } = _intlayer_config_built.internationalization ?? {};
|
|
29
|
-
const [currentLocale, setCurrentLocale] = (0, preact_hooks.useState)(localeProp ?? require_client_useLocaleStorage.
|
|
30
|
-
(0, preact_hooks.useEffect)(() => {
|
|
31
|
-
if (localeProp && localeProp !== currentLocale) setCurrentLocale(localeProp);
|
|
32
|
-
}, [
|
|
33
|
-
localeProp,
|
|
34
|
-
currentLocale,
|
|
35
|
-
setCurrentLocale
|
|
36
|
-
]);
|
|
31
|
+
const [currentLocale, setCurrentLocale] = (0, preact_hooks.useState)(() => localeProp ?? require_client_useLocaleStorage.getLocaleInStorage() ?? defaultLocaleProp ?? defaultLocaleConfig);
|
|
37
32
|
(0, preact_hooks.useEffect)(() => {
|
|
38
33
|
(0, _intlayer_config_client.setIntlayerIdentifier)();
|
|
39
34
|
}, []);
|
|
40
|
-
const
|
|
41
|
-
|
|
35
|
+
const activeLocale = localeProp ?? currentLocale;
|
|
36
|
+
const setLocaleBase = (0, preact_hooks.useCallback)((newLocale) => {
|
|
37
|
+
if (activeLocale.toString() === newLocale.toString()) return;
|
|
42
38
|
if (!availableLocales?.map(String).includes(newLocale)) {
|
|
43
39
|
console.error(`Locale ${newLocale} is not available`);
|
|
44
40
|
return;
|
|
45
41
|
}
|
|
46
42
|
setCurrentLocale(newLocale);
|
|
47
43
|
require_client_useLocaleStorage.setLocaleInStorage(newLocale, isCookieEnabled ?? true);
|
|
48
|
-
}
|
|
44
|
+
}, [
|
|
45
|
+
activeLocale,
|
|
46
|
+
availableLocales,
|
|
47
|
+
isCookieEnabled
|
|
48
|
+
]);
|
|
49
49
|
const setLocale = setLocaleProp ?? setLocaleBase;
|
|
50
|
-
const resolvedLocale = (0, _intlayer_core_localization.localeResolver)(
|
|
50
|
+
const resolvedLocale = (0, _intlayer_core_localization.localeResolver)(activeLocale);
|
|
51
|
+
const contextValue = (0, preact_hooks.useMemo)(() => ({
|
|
52
|
+
locale: resolvedLocale,
|
|
53
|
+
setLocale,
|
|
54
|
+
variant,
|
|
55
|
+
isCookieEnabled
|
|
56
|
+
}), [
|
|
57
|
+
resolvedLocale,
|
|
58
|
+
setLocale,
|
|
59
|
+
variant,
|
|
60
|
+
isCookieEnabled
|
|
61
|
+
]);
|
|
51
62
|
return /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(IntlayerClientContext.Provider, {
|
|
52
|
-
value:
|
|
53
|
-
locale: resolvedLocale,
|
|
54
|
-
setLocale,
|
|
55
|
-
variant,
|
|
56
|
-
isCookieEnabled
|
|
57
|
-
},
|
|
63
|
+
value: contextValue,
|
|
58
64
|
children
|
|
59
65
|
});
|
|
60
66
|
};
|
|
@@ -81,8 +87,8 @@ const IntlayerProviderContent = ({ locale: localeProp, defaultLocale: defaultLoc
|
|
|
81
87
|
const IntlayerProvider = ({ children, ...props }) => /* @__PURE__ */ (0, preact_jsx_runtime.jsxs)(IntlayerProviderContent, {
|
|
82
88
|
...props,
|
|
83
89
|
children: [
|
|
84
|
-
/* @__PURE__ */ (0, preact_jsx_runtime.jsx)(require_editor_EditorProvider.EditorProvider, {}),
|
|
85
|
-
/* @__PURE__ */ (0, preact_jsx_runtime.jsx)(require_analytics_AnalyticsProvider.AnalyticsProvider, {}),
|
|
90
|
+
process.env.INTLAYER_EDITOR_ENABLED !== "false" && /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(require_editor_EditorProvider.EditorProvider, {}),
|
|
91
|
+
process.env.INTLAYER_ANALYTICS_ENABLED !== "false" && /* @__PURE__ */ (0, preact_jsx_runtime.jsx)(require_analytics_AnalyticsProvider.AnalyticsProvider, {}),
|
|
86
92
|
children
|
|
87
93
|
]
|
|
88
94
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerProvider.cjs","names":["createContext","
|
|
1
|
+
{"version":3,"file":"IntlayerProvider.cjs","names":["createContext","getLocaleInStorage","internationalization","useContext","useState","useCallback","localeResolver","useMemo","EditorProvider","AnalyticsProvider"],"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport { setIntlayerIdentifier } from '@intlayer/config/client';\nimport { localeResolver } from '@intlayer/core/localization';\nimport type {\n LocalesValues,\n ProviderVariant,\n} from '@intlayer/types/module_augmentation';\nimport {\n type ComponentChild,\n createContext,\n type FunctionComponent,\n} from 'preact';\nimport {\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from 'preact/hooks';\nimport { AnalyticsProvider } from '../analytics/AnalyticsProvider';\nimport { EditorProvider } from '../editor/EditorProvider';\nimport { getLocaleInStorage, setLocaleInStorage } from './useLocaleStorage';\n\ntype IntlayerValue = {\n locale: LocalesValues;\n setLocale: (newLocale: LocalesValues) => void;\n /**\n * Ambient variant applied to every dictionary read below the provider, the\n * same way `locale` is. Overridden per call by an explicit selector.\n */\n variant?: ProviderVariant;\n isCookieEnabled?: boolean;\n};\n\n/**\n * Context that store the current locale on the client side\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n // Read on demand: only a tree rendered without a provider needs it\n get locale() {\n return getLocaleInStorage() ?? internationalization?.defaultLocale;\n },\n setLocale: () => null,\n});\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext) ?? {};\n\nexport type IntlayerProviderProps = {\n children?: ComponentChild;\n locale?: LocalesValues;\n defaultLocale?: LocalesValues;\n /**\n * Ambient variant applied to every dictionary read below this provider — for\n * a dimension that is fixed for the whole session (tenant, school type, plan\n * tier…) and that therefore no component should have to pass by hand.\n *\n * Accepts three forms:\n * - `variant=\"school1\"` — one named variant for every key\n * - `variant={['school1', 'default']}` — an ordered preference chain: the\n * first variant the key actually declares wins\n * - `variant={{ key1: 'school1', default: 'base' }}` — per dictionary key,\n * with `default` covering every key not listed\n *\n * A plain object is always read as the per-key map. To pin a structured\n * variant globally, nest it: `variant={{ default: { id: 'prod_abc' } }}`.\n *\n * A call-site selector always wins.\n */\n variant?: ProviderVariant;\n setLocale?: (locale: LocalesValues) => void;\n isCookieEnabled?: boolean;\n};\n\n/**\n * Provider that store the current locale on the client side\n */\nexport const IntlayerProviderContent: FunctionComponent<\n IntlayerProviderProps\n> = ({\n locale: localeProp,\n defaultLocale: defaultLocaleProp,\n variant,\n children,\n setLocale: setLocaleProp,\n isCookieEnabled,\n}) => {\n const { defaultLocale: defaultLocaleConfig, locales: availableLocales } =\n internationalization ?? {};\n\n // Storage is only read when no locale is passed, and only on mount\n const [currentLocale, setCurrentLocale] = useState<LocalesValues>(\n () =>\n (localeProp ??\n getLocaleInStorage() ??\n defaultLocaleProp ??\n defaultLocaleConfig) as LocalesValues\n );\n\n useEffect(() => {\n setIntlayerIdentifier();\n }, []);\n\n // The prop wins over the state. It is read directly instead of being mirrored\n // into state by an effect, which re-rendered the subtree after every change.\n const activeLocale = localeProp ?? currentLocale;\n\n const setLocaleBase = useCallback(\n (newLocale: LocalesValues) => {\n if (activeLocale.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); // Update state\n setLocaleInStorage(newLocale, isCookieEnabled ?? true); // Optionally set cookie for persistence\n },\n [activeLocale, availableLocales, isCookieEnabled]\n );\n\n const setLocale = setLocaleProp ?? setLocaleBase;\n\n const resolvedLocale = localeResolver(activeLocale);\n\n // Stable value so a parent re-render does not re-render every consumer\n const contextValue = useMemo<IntlayerValue>(\n () => ({\n locale: resolvedLocale,\n setLocale,\n variant,\n isCookieEnabled,\n }),\n [resolvedLocale, setLocale, variant, isCookieEnabled]\n );\n\n return (\n <IntlayerClientContext.Provider value={contextValue}>\n {children}\n </IntlayerClientContext.Provider>\n );\n};\n\n/**\n * Main provider for Intlayer in Preact applications.\n *\n * It provides the Intlayer context to your application, allowing the use\n * of hooks like `useIntlayer` and `useLocale`.\n *\n * @param props - The provider props.\n * @returns The provider component.\n *\n * @example\n * ```tsx\n * import { IntlayerProvider } from 'preact-intlayer';\n *\n * const App = () => (\n * <IntlayerProvider>\n * <MyComponent />\n * </IntlayerProvider>\n * );\n * ```\n */\nexport const IntlayerProvider: FunctionComponent<IntlayerProviderProps> = ({\n children,\n ...props\n}) => (\n <IntlayerProviderContent {...props}>\n {/* Build flags drop these, and their modules, when the feature is off */}\n {process.env.INTLAYER_EDITOR_ENABLED !== 'false' && <EditorProvider />}\n {process.env.INTLAYER_ANALYTICS_ENABLED !== 'false' && (\n <AnalyticsProvider />\n )}\n {children}\n </IntlayerProviderContent>\n);\n"],"mappings":";;;;;;;;;;;;;;;AAqCA,MAAa,4BAAwBA,sBAA6B;CAEhE,IAAI,SAAS;EACX,OAAOC,mDAAmB,KAAKC,6CAAsB;CACvD;CACA,iBAAiB;AACnB,CAAC;;;;AAKD,MAAa,+BAA2BC,yBAAW,qBAAqB,KAAK,CAAC;;;;AA+B9E,MAAa,2BAER,EACH,QAAQ,YACR,eAAe,mBACf,SACA,UACA,WAAW,eACX,sBACI;CACJ,MAAM,EAAE,eAAe,qBAAqB,SAAS,qBACnDD,+CAAwB,CAAC;CAG3B,MAAM,CAAC,eAAe,wBAAoBE,6BAErC,cACCH,mDAAmB,KACnB,qBACA,mBACN;CAEA,kCAAgB;EACd,mDAAsB;CACxB,GAAG,CAAC,CAAC;CAIL,MAAM,eAAe,cAAc;CAEnC,MAAM,oBAAgBI,2BACnB,cAA6B;EAC5B,IAAI,aAAa,SAAS,MAAM,UAAU,SAAS,GAAG;EAEtD,IAAI,CAAC,kBAAkB,IAAI,MAAM,CAAC,CAAC,SAAS,SAAS,GAAG;GACtD,QAAQ,MAAM,UAAU,UAAU,kBAAkB;GACpD;EACF;EAEA,iBAAiB,SAAS;EAC1B,mDAAmB,WAAW,mBAAmB,IAAI;CACvD,GACA;EAAC;EAAc;EAAkB;CAAe,CAClD;CAEA,MAAM,YAAY,iBAAiB;CAEnC,MAAM,qBAAiBC,4CAAe,YAAY;CAGlD,MAAM,mBAAeC,6BACZ;EACL,QAAQ;EACR;EACA;EACA;CACF,IACA;EAAC;EAAgB;EAAW;EAAS;CAAe,CACtD;CAEA,OACE,4CAAC,sBAAsB,UAAvB;EAAgC,OAAO;EACpC;CAC6B;AAEpC;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,oBAA8D,EACzE,UACA,GAAG,YAEH,6CAAC,yBAAD;CAAyB,GAAI;WAA7B;EAEG,QAAQ,IAAI,4BAA4B,WAAW,4CAACC,8CAAD,CAAiB;EACpE,QAAQ,IAAI,+BAA+B,WAC1C,4CAACC,uDAAD,CAAoB;EAErB;CACsB"}
|
package/dist/cjs/client/t.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
3
|
-
let preact_hooks = require("preact/hooks");
|
|
4
3
|
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
4
|
+
let preact_hooks = require("preact/hooks");
|
|
5
5
|
|
|
6
6
|
//#region src/client/t.ts
|
|
7
7
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
3
2
|
const require_getDictionary = require('../getDictionary.cjs');
|
|
3
|
+
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
4
4
|
let preact_hooks = require("preact/hooks");
|
|
5
5
|
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
6
6
|
|
|
@@ -20,7 +20,7 @@ const useDictionary = (dictionary, localeOrSelector) => {
|
|
|
20
20
|
contextVariant,
|
|
21
21
|
dictionaryKey: dictionary.key
|
|
22
22
|
}) : localeOrSelector ?? currentLocale;
|
|
23
|
-
const argumentIdentity = typeof argument === "object" && argument !== null ? `${argument.locale ?? ""}|${(0, _intlayer_core_dictionaryManipulator.getDictionarySelectorCacheKey)(argument)}` : argument;
|
|
23
|
+
const argumentIdentity = process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && typeof argument === "object" && argument !== null ? `${argument.locale ?? ""}|${(0, _intlayer_core_dictionaryManipulator.getDictionarySelectorCacheKey)(argument)}` : argument;
|
|
24
24
|
return (0, preact_hooks.useMemo)(() => require_getDictionary.getDictionary(dictionary, argument), [dictionary.key, argumentIdentity]);
|
|
25
25
|
};
|
|
26
26
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.cjs","names":["useContext","IntlayerClientContext","resolveDictionaryArgument","getDictionarySelectorCacheKey","useMemo","getDictionary"],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import {\n getDictionarySelectorCacheKey,\n resolveDictionaryArgument,\n} from '@intlayer/core/dictionaryManipulator';\nimport type {\n Dictionary,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Preact hook that transforms a dictionary (or qualified dictionary group) and\n * returns the content.\n *\n * If the locale is not provided (directly or through the selector), it will use\n * the locale from the client context.\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale, variant: contextVariant } =\n useContext(IntlayerClientContext) ?? {};\n\n // Layers the provider's locale and variant under the call-site argument.\n // This is the seam the build-time optimize transform lands on: it rewrites\n // `useIntlayer('key', selector)` into `useDictionary(dict, selector)`, so an\n // ambient variant has to be applied here to survive the rewrite.\n const argument =\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false'\n ? resolveDictionaryArgument({\n localeOrSelector,\n contextLocale: currentLocale,\n contextVariant,\n dictionaryKey: dictionary.key,\n })\n : (localeOrSelector ?? currentLocale);\n\n // Stable identity of the resolved argument for memoization — a provider\n // variant is often a fresh object literal on every render, so the dependency\n // has to be its serialization, never its reference.\n const argumentIdentity =\n typeof argument === 'object'
|
|
1
|
+
{"version":3,"file":"useDictionary.cjs","names":["useContext","IntlayerClientContext","resolveDictionaryArgument","getDictionarySelectorCacheKey","useMemo","getDictionary"],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import {\n getDictionarySelectorCacheKey,\n resolveDictionaryArgument,\n} from '@intlayer/core/dictionaryManipulator';\nimport type {\n Dictionary,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Preact hook that transforms a dictionary (or qualified dictionary group) and\n * returns the content.\n *\n * If the locale is not provided (directly or through the selector), it will use\n * the locale from the client context.\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale, variant: contextVariant } =\n useContext(IntlayerClientContext) ?? {};\n\n // Layers the provider's locale and variant under the call-site argument.\n // This is the seam the build-time optimize transform lands on: it rewrites\n // `useIntlayer('key', selector)` into `useDictionary(dict, selector)`, so an\n // ambient variant has to be applied here to survive the rewrite.\n const argument =\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false'\n ? resolveDictionaryArgument({\n localeOrSelector,\n contextLocale: currentLocale,\n contextVariant,\n dictionaryKey: dictionary.key,\n })\n : (localeOrSelector ?? currentLocale);\n\n // Stable identity of the resolved argument for memoization — a provider\n // variant is often a fresh object literal on every render, so the dependency\n // has to be its serialization, never its reference.\n const argumentIdentity =\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&\n typeof argument === 'object' &&\n argument !== null\n ? `${argument.locale ?? ''}|${getDictionarySelectorCacheKey(argument)}`\n : argument;\n\n return useMemo(\n () => getDictionary<T, A>(dictionary, argument as A),\n [dictionary.key, argumentIdentity]\n );\n};\n"],"mappings":";;;;;;;;;;;;;;AAwBA,MAAa,iBAMX,YACA,qBACG;CACH,MAAM,EAAE,QAAQ,eAAe,SAAS,uBACtCA,yBAAWC,qDAAqB,KAAK,CAAC;CAMxC,MAAM,WACJ,QAAQ,IAAI,iCAAiC,cACzCC,gEAA0B;EACxB;EACA,eAAe;EACf;EACA,eAAe,WAAW;CAC5B,CAAC,IACA,oBAAoB;CAK3B,MAAM,mBACJ,QAAQ,IAAI,iCAAiC,WAC7C,OAAO,aAAa,YACpB,aAAa,OACT,GAAG,SAAS,UAAU,GAAG,OAAGC,oEAA8B,QAAQ,MAClE;CAEN,WAAOC,4BACCC,oCAAoB,YAAY,QAAa,GACnD,CAAC,WAAW,KAAK,gBAAgB,CACnC;AACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
3
3
|
const require_client_useDictionary = require('./useDictionary.cjs');
|
|
4
|
-
let preact_hooks = require("preact/hooks");
|
|
5
4
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
5
|
+
let preact_hooks = require("preact/hooks");
|
|
6
6
|
|
|
7
7
|
//#region src/client/useDictionaryAsync.ts
|
|
8
8
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
3
2
|
const require_getDictionary = require('../getDictionary.cjs');
|
|
3
|
+
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
4
4
|
const require_client_useLoadDynamic = require('./useLoadDynamic.cjs');
|
|
5
|
-
let preact_hooks = require("preact/hooks");
|
|
6
5
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
6
|
+
let preact_hooks = require("preact/hooks");
|
|
7
7
|
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
8
8
|
|
|
9
9
|
//#region src/client/useDictionaryDynamic.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
3
2
|
const require_getIntlayer = require('../getIntlayer.cjs');
|
|
3
|
+
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
4
4
|
let preact_hooks = require("preact/hooks");
|
|
5
5
|
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
6
6
|
|
|
@@ -37,7 +37,7 @@ const useIntlayer = (key, localeOrSelector) => {
|
|
|
37
37
|
contextVariant,
|
|
38
38
|
dictionaryKey: key
|
|
39
39
|
}) : localeOrSelector ?? currentLocale;
|
|
40
|
-
const argumentIdentity = typeof argument === "object" && argument !== null ? `${argument.locale ?? ""}|${(0, _intlayer_core_dictionaryManipulator.getDictionarySelectorCacheKey)(argument)}` : argument;
|
|
40
|
+
const argumentIdentity = process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && typeof argument === "object" && argument !== null ? `${argument.locale ?? ""}|${(0, _intlayer_core_dictionaryManipulator.getDictionarySelectorCacheKey)(argument)}` : argument;
|
|
41
41
|
return (0, preact_hooks.useMemo)(() => require_getIntlayer.getIntlayer(key, argument), [key, argumentIdentity]);
|
|
42
42
|
};
|
|
43
43
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.cjs","names":["useContext","IntlayerClientContext","resolveDictionaryArgument","getDictionarySelectorCacheKey","useMemo","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import {\n getDictionarySelectorCacheKey,\n resolveDictionaryArgument,\n} from '@intlayer/core/dictionaryManipulator';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Preact hook that picks one dictionary by its key and returns its content.\n *\n * The second argument is either a locale or a selector object:\n * - `{ item: 2 }` — collection item (omit `item` to get every item as array)\n * - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)\n * - `locale` composes with any selector and overrides the context locale\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param localeOrSelector - Optional locale or selector.\n * @returns The transformed dictionary content.\n *\n * @example\n * ```tsx\n * import { useIntlayer } from 'preact-intlayer';\n *\n * const MyComponent = () => {\n * const content = useIntlayer('my-dictionary-key');\n * const faq2 = useIntlayer('faq', { item: 2 });\n *\n * return <div>{content.myField.value}</div>;\n * };\n * ```\n */\nexport const useIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale, variant: contextVariant } =\n useContext(IntlayerClientContext) ?? {};\n\n // Layers the provider's locale and variant under the call-site argument.\n // Selectors disabled project-wide (build-time flag) ⇒ the argument can only\n // be a locale, so the merge is dead code and is dropped by the bundler.\n const argument =\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false'\n ? resolveDictionaryArgument({\n localeOrSelector,\n contextLocale: currentLocale,\n contextVariant,\n dictionaryKey: key as string,\n })\n : (localeOrSelector ?? currentLocale);\n\n // Stable identity of the resolved argument for memoization — a provider\n // variant is often a fresh object literal on every render, so the dependency\n // has to be its serialization, never its reference.\n const argumentIdentity =\n typeof argument === 'object'
|
|
1
|
+
{"version":3,"file":"useIntlayer.cjs","names":["useContext","IntlayerClientContext","resolveDictionaryArgument","getDictionarySelectorCacheKey","useMemo","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import {\n getDictionarySelectorCacheKey,\n resolveDictionaryArgument,\n} from '@intlayer/core/dictionaryManipulator';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Preact hook that picks one dictionary by its key and returns its content.\n *\n * The second argument is either a locale or a selector object:\n * - `{ item: 2 }` — collection item (omit `item` to get every item as array)\n * - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)\n * - `locale` composes with any selector and overrides the context locale\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param localeOrSelector - Optional locale or selector.\n * @returns The transformed dictionary content.\n *\n * @example\n * ```tsx\n * import { useIntlayer } from 'preact-intlayer';\n *\n * const MyComponent = () => {\n * const content = useIntlayer('my-dictionary-key');\n * const faq2 = useIntlayer('faq', { item: 2 });\n *\n * return <div>{content.myField.value}</div>;\n * };\n * ```\n */\nexport const useIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale, variant: contextVariant } =\n useContext(IntlayerClientContext) ?? {};\n\n // Layers the provider's locale and variant under the call-site argument.\n // Selectors disabled project-wide (build-time flag) ⇒ the argument can only\n // be a locale, so the merge is dead code and is dropped by the bundler.\n const argument =\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false'\n ? resolveDictionaryArgument({\n localeOrSelector,\n contextLocale: currentLocale,\n contextVariant,\n dictionaryKey: key as string,\n })\n : (localeOrSelector ?? currentLocale);\n\n // Stable identity of the resolved argument for memoization — a provider\n // variant is often a fresh object literal on every render, so the dependency\n // has to be its serialization, never its reference.\n const argumentIdentity =\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&\n typeof argument === 'object' &&\n argument !== null\n ? `${argument.locale ?? ''}|${getDictionarySelectorCacheKey(argument)}`\n : argument;\n\n return useMemo(\n () => getIntlayer<T, A>(key, argument as A),\n [key, argumentIdentity]\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,eAIX,KACA,qBACG;CACH,MAAM,EAAE,QAAQ,eAAe,SAAS,uBACtCA,yBAAWC,qDAAqB,KAAK,CAAC;CAKxC,MAAM,WACJ,QAAQ,IAAI,iCAAiC,cACzCC,gEAA0B;EACxB;EACA,eAAe;EACf;EACA,eAAe;CACjB,CAAC,IACA,oBAAoB;CAK3B,MAAM,mBACJ,QAAQ,IAAI,iCAAiC,WAC7C,OAAO,aAAa,YACpB,aAAa,OACT,GAAG,SAAS,UAAU,GAAG,OAAGC,oEAA8B,QAAQ,MAClE;CAEN,WAAOC,4BACCC,gCAAkB,KAAK,QAAa,GAC1C,CAAC,KAAK,gBAAgB,CACxB;AACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_client_useLocaleStorage = require('./useLocaleStorage.cjs');
|
|
3
3
|
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
4
|
-
let preact_hooks = require("preact/hooks");
|
|
5
4
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
5
|
+
let preact_hooks = require("preact/hooks");
|
|
6
6
|
|
|
7
7
|
//#region src/client/useLocale.ts
|
|
8
8
|
const { defaultLocale, locales: availableLocales } = _intlayer_config_built.internationalization ?? {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
3
|
-
let preact_hooks = require("preact/hooks");
|
|
4
3
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
4
|
+
let preact_hooks = require("preact/hooks");
|
|
5
5
|
|
|
6
6
|
//#region src/client/useLocaleBase.ts
|
|
7
7
|
const { defaultLocale, locales: availableLocales } = _intlayer_config_built.internationalization;
|
|
@@ -4,9 +4,19 @@ let _intlayer_core_utils = require("@intlayer/core/utils");
|
|
|
4
4
|
|
|
5
5
|
//#region src/client/useLocaleStorage.ts
|
|
6
6
|
/**
|
|
7
|
+
* Reads the locale persisted in the browser storage (cookie, localStorage…).
|
|
8
|
+
*
|
|
9
|
+
* Unlike `localeInStorage`, read on first call rather than at import, then
|
|
10
|
+
* cached until the next `setLocaleInStorage`. Never cached on the server.
|
|
11
|
+
*/
|
|
12
|
+
const getLocaleInStorage = _intlayer_core_utils.getCachedLocaleFromStorageClient;
|
|
13
|
+
/**
|
|
7
14
|
* Get the locale cookie
|
|
15
|
+
*
|
|
16
|
+
* Read once at import time; marked pure so bundlers drop the read when nothing
|
|
17
|
+
* imports it.
|
|
8
18
|
*/
|
|
9
|
-
const localeInStorage = (0, _intlayer_core_utils.getLocaleFromStorageClient)(_intlayer_core_utils.localeStorageOptions);
|
|
19
|
+
const localeInStorage = /* @__PURE__ */ (0, _intlayer_core_utils.getLocaleFromStorageClient)(_intlayer_core_utils.localeStorageOptions);
|
|
10
20
|
/**
|
|
11
21
|
* @deprecated Use localeInStorage instead
|
|
12
22
|
*
|
|
@@ -43,6 +53,7 @@ const useLocaleStorage = (isCookieEnabled) => (0, preact_hooks.useMemo)(() => (0
|
|
|
43
53
|
const useLocaleCookie = useLocaleStorage;
|
|
44
54
|
|
|
45
55
|
//#endregion
|
|
56
|
+
exports.getLocaleInStorage = getLocaleInStorage;
|
|
46
57
|
exports.localeCookie = localeCookie;
|
|
47
58
|
exports.localeInStorage = localeInStorage;
|
|
48
59
|
exports.setLocaleCookie = setLocaleCookie;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocaleStorage.cjs","names":["
|
|
1
|
+
{"version":3,"file":"useLocaleStorage.cjs","names":["getCachedLocaleFromStorageClient","localeStorageOptions","setLocaleInStorageCore","useMemo","LocaleStorageClient"],"sources":["../../../src/client/useLocaleStorage.ts"],"sourcesContent":["import {\n getCachedLocaleFromStorageClient,\n getLocaleFromStorageClient,\n LocaleStorageClient,\n localeStorageOptions,\n setLocaleInStorageClient as setLocaleInStorageCore,\n} from '@intlayer/core/utils';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useMemo } from 'preact/hooks';\n\n/**\n * Reads the locale persisted in the browser storage (cookie, localStorage…).\n *\n * Unlike `localeInStorage`, read on first call rather than at import, then\n * cached until the next `setLocaleInStorage`. Never cached on the server.\n */\nexport const getLocaleInStorage = getCachedLocaleFromStorageClient;\n\n/**\n * Get the locale cookie\n *\n * Read once at import time; marked pure so bundlers drop the read when nothing\n * imports it.\n */\nexport const localeInStorage =\n /* @__PURE__ */ getLocaleFromStorageClient(localeStorageOptions);\n/**\n * @deprecated Use localeInStorage instead\n *\n * Get the locale cookie\n */\nexport const localeCookie = localeInStorage;\n\n/**\n * Set the locale cookie\n */\nexport const setLocaleInStorage = (\n locale: LocalesValues,\n isCookieEnabled?: boolean\n) =>\n setLocaleInStorageCore(locale, {\n ...localeStorageOptions,\n isCookieEnabled,\n });\n\n/**\n * @deprecated Use setLocaleInStorage instead\n *\n * Set the locale cookie\n */\nexport const setLocaleCookie = setLocaleInStorage;\n\n/**\n * Hook that provides the locale storage and a function to set it\n */\nexport const useLocaleStorage = (isCookieEnabled?: boolean) =>\n useMemo(\n () =>\n LocaleStorageClient({\n ...localeStorageOptions,\n isCookieEnabled,\n }),\n [isCookieEnabled]\n );\n\n/**\n * @deprecated Use useLocaleStorage instead\n *\n * For GDPR compliance, use useLocaleStorage instead\n *\n * Hook that provides the locale cookie and a function to set it\n */\nexport const useLocaleCookie = useLocaleStorage;\n"],"mappings":";;;;;;;;;;;AAgBA,MAAa,qBAAqBA;;;;;;;AAQlC,MAAa,kBACK,qEAA2BC,yCAAoB;;;;;;AAMjE,MAAa,eAAe;;;;AAK5B,MAAa,sBACX,QACA,wBAEAC,+CAAuB,QAAQ;CAC7B,GAAGD;CACH;AACF,CAAC;;;;;;AAOH,MAAa,kBAAkB;;;;AAK/B,MAAa,oBAAoB,wBAC/BE,gCAEIC,0CAAoB;CAClB,GAAGH;CACH;AACF,CAAC,GACH,CAAC,eAAe,CAClB;;;;;;;;AASF,MAAa,kBAAkB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
3
|
-
let preact_hooks = require("preact/hooks");
|
|
4
3
|
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
4
|
+
let preact_hooks = require("preact/hooks");
|
|
5
5
|
|
|
6
6
|
//#region src/client/useTraduction.ts
|
|
7
7
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
let preact_hooks = require("preact/hooks");
|
|
3
2
|
let _intlayer_editor_isEnabled = require("@intlayer/editor/isEnabled");
|
|
3
|
+
let preact_hooks = require("preact/hooks");
|
|
4
4
|
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
5
5
|
|
|
6
6
|
//#region src/editor/ContentSelector.tsx
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_client_IntlayerProvider = require('../client/IntlayerProvider.cjs');
|
|
3
|
-
let preact_hooks = require("preact/hooks");
|
|
4
3
|
let _intlayer_editor_isEnabled = require("@intlayer/editor/isEnabled");
|
|
4
|
+
let preact_hooks = require("preact/hooks");
|
|
5
5
|
|
|
6
6
|
//#region src/editor/useEditor.tsx
|
|
7
7
|
/**
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const
|
|
2
|
+
const require_format_usePercentage = require('./usePercentage.cjs');
|
|
3
3
|
const require_format_useUnit = require('./useUnit.cjs');
|
|
4
|
-
const require_format_useDate = require('./useDate.cjs');
|
|
5
4
|
const require_format_useCompact = require('./useCompact.cjs');
|
|
5
|
+
const require_format_useNumber = require('./useNumber.cjs');
|
|
6
6
|
const require_format_useIntl = require('./useIntl.cjs');
|
|
7
7
|
const require_format_useList = require('./useList.cjs');
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const require_format_useCurrency = require('./useCurrency.cjs');
|
|
9
|
+
const require_format_useDate = require('./useDate.cjs');
|
|
10
10
|
const require_format_useRelativeTime = require('./useRelativeTime.cjs');
|
|
11
11
|
|
|
12
12
|
exports.useCompact = require_format_useCompact.useCompact;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
let preact_hooks = require("preact/hooks");
|
|
3
2
|
let preact = require("preact");
|
|
3
|
+
let preact_hooks = require("preact/hooks");
|
|
4
4
|
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
5
5
|
|
|
6
6
|
//#region src/html/HTMLProvider.tsx
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_html_HTMLProvider = require('./HTMLProvider.cjs');
|
|
3
|
-
let preact = require("preact");
|
|
4
3
|
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
4
|
+
let preact = require("preact");
|
|
5
5
|
let _intlayer_core_transpiler = require("@intlayer/core/transpiler");
|
|
6
6
|
|
|
7
7
|
//#region src/html/HTMLRenderer.tsx
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_getDictionary = require('./getDictionary.cjs');
|
|
3
|
+
const require_getIntlayer = require('./getIntlayer.cjs');
|
|
2
4
|
const require_client_useLocaleStorage = require('./client/useLocaleStorage.cjs');
|
|
3
5
|
const require_client_IntlayerProvider = require('./client/IntlayerProvider.cjs');
|
|
4
6
|
const require_analytics_useAnalytics = require('./analytics/useAnalytics.cjs');
|
|
@@ -6,15 +8,14 @@ const require_analytics_AnalyticsProvider = require('./analytics/AnalyticsProvid
|
|
|
6
8
|
const require_analytics_useConversion = require('./analytics/useConversion.cjs');
|
|
7
9
|
const require_analytics_useExperiment = require('./analytics/useExperiment.cjs');
|
|
8
10
|
const require_client_t = require('./client/t.cjs');
|
|
9
|
-
const require_getDictionary = require('./getDictionary.cjs');
|
|
10
11
|
const require_client_useDictionary = require('./client/useDictionary.cjs');
|
|
11
12
|
const require_client_useDictionaryAsync = require('./client/useDictionaryAsync.cjs');
|
|
12
13
|
const require_client_useLoadDynamic = require('./client/useLoadDynamic.cjs');
|
|
13
14
|
const require_client_useDictionaryDynamic = require('./client/useDictionaryDynamic.cjs');
|
|
14
|
-
const require_getIntlayer = require('./getIntlayer.cjs');
|
|
15
15
|
const require_client_useIntlayer = require('./client/useIntlayer.cjs');
|
|
16
16
|
const require_client_useLocale = require('./client/useLocale.cjs');
|
|
17
17
|
const require_client_useLocaleBase = require('./client/useLocaleBase.cjs');
|
|
18
|
+
const require_client_usePathname = require('./client/usePathname.cjs');
|
|
18
19
|
|
|
19
20
|
exports.AnalyticsProvider = require_analytics_AnalyticsProvider.AnalyticsProvider;
|
|
20
21
|
exports.IntlayerClientContext = require_client_IntlayerProvider.IntlayerClientContext;
|
|
@@ -38,4 +39,5 @@ exports.useLoadDynamic = require_client_useLoadDynamic.useLoadDynamic;
|
|
|
38
39
|
exports.useLocale = require_client_useLocale.useLocale;
|
|
39
40
|
exports.useLocaleBase = require_client_useLocaleBase.useLocaleBase;
|
|
40
41
|
exports.useLocaleCookie = require_client_useLocaleStorage.useLocaleCookie;
|
|
41
|
-
exports.useLocaleStorage = require_client_useLocaleStorage.useLocaleStorage;
|
|
42
|
+
exports.useLocaleStorage = require_client_useLocaleStorage.useLocaleStorage;
|
|
43
|
+
exports.usePathname = require_client_usePathname.usePathname;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_markdown_compiler = require('./compiler.cjs');
|
|
3
|
-
let preact_hooks = require("preact/hooks");
|
|
4
3
|
let preact = require("preact");
|
|
4
|
+
let preact_hooks = require("preact/hooks");
|
|
5
5
|
let preact_jsx_runtime = require("preact/jsx-runtime");
|
|
6
6
|
|
|
7
7
|
//#region src/markdown/MarkdownProvider.tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownProvider.cjs","names":["createContext","useContext","compileMarkdown"],"sources":["../../../src/markdown/MarkdownProvider.tsx"],"sourcesContent":["import {\n type ComponentChildren,\n type ComponentType,\n createContext,\n type FunctionComponent,\n type JSX,\n} from 'preact';\nimport { useContext } from 'preact/hooks';\nimport type { HTMLComponents } from '../html/types';\nimport { compileMarkdown, type ParsedMarkdown } from './compiler';\n\ntype PropsWithChildren<P = {}> = P & { children?: ComponentChildren };\n\n/**\n * Refined options for the MarkdownProvider.\n */\nexport type MarkdownProviderOptions = {\n /**\n * Forces the compiler to always output content with a block-level wrapper.\n */\n forceBlock?: boolean;\n /**\n * Forces the compiler to always output content with an inline wrapper.\n */\n forceInline?: boolean;\n /**\n * Whether to preserve frontmatter in the markdown content.\n */\n preserveFrontmatter?: boolean;\n /**\n * Whether to use the GitHub Tag Filter.\n */\n tagfilter?: boolean;\n};\n\ntype RenderMarkdownOptions = MarkdownProviderOptions & {\n components?: HTMLComponents<'permissive', {}>;\n wrapper?: ComponentType<
|
|
1
|
+
{"version":3,"file":"MarkdownProvider.cjs","names":["createContext","useContext","compileMarkdown"],"sources":["../../../src/markdown/MarkdownProvider.tsx"],"sourcesContent":["import {\n type ComponentChildren,\n type ComponentType,\n createContext,\n type FunctionComponent,\n type JSX,\n} from 'preact';\nimport { useContext } from 'preact/hooks';\nimport type { HTMLComponents } from '../html/types';\nimport { compileMarkdown, type ParsedMarkdown } from './compiler';\n\ntype PropsWithChildren<P = {}> = P & { children?: ComponentChildren };\n\n/**\n * Refined options for the MarkdownProvider.\n */\nexport type MarkdownProviderOptions = {\n /**\n * Forces the compiler to always output content with a block-level wrapper.\n */\n forceBlock?: boolean;\n /**\n * Forces the compiler to always output content with an inline wrapper.\n */\n forceInline?: boolean;\n /**\n * Whether to preserve frontmatter in the markdown content.\n */\n preserveFrontmatter?: boolean;\n /**\n * Whether to use the GitHub Tag Filter.\n */\n tagfilter?: boolean;\n};\n\ntype RenderMarkdownOptions = MarkdownProviderOptions & {\n components?: HTMLComponents<'permissive', {}>;\n wrapper?: ComponentType<unknown> | keyof JSX.IntrinsicElements;\n forceWrapper?: boolean;\n};\n\ntype MarkdownContextValue = {\n components?: HTMLComponents<'permissive', {}>;\n renderMarkdown: (\n markdown: string | ParsedMarkdown,\n options?: MarkdownProviderOptions,\n components?: HTMLComponents<'permissive', {}>,\n wrapper?: ComponentType<unknown> | keyof JSX.IntrinsicElements\n ) => ComponentChildren | Promise<ComponentChildren>;\n};\n\ntype MarkdownProviderProps = PropsWithChildren<\n MarkdownProviderOptions & {\n /**\n * Component overrides for HTML tags.\n */\n components?: HTMLComponents<'permissive', {}>;\n /**\n * Wrapper element or component to be used when there are multiple children.\n */\n wrapper?: ComponentType<unknown> | keyof JSX.IntrinsicElements;\n /**\n * Custom render function for markdown.\n * If provided, it will overwrite all rules and default rendering.\n */\n renderMarkdown?: (\n markdown: string | ParsedMarkdown,\n options?: MarkdownProviderOptions,\n components?: HTMLComponents<'permissive', {}>,\n wrapper?: ComponentType<unknown> | keyof JSX.IntrinsicElements\n ) => ComponentChildren | Promise<ComponentChildren>;\n }\n>;\n\nconst MarkdownContext = createContext<MarkdownContextValue | undefined>(\n undefined\n);\n\nexport const useMarkdownContext = () => useContext(MarkdownContext);\n\nconst mergeOptions = (\n baseComponents: HTMLComponents<'permissive', {}> | undefined,\n baseOptions: Omit<RenderMarkdownOptions, 'components'>,\n options: MarkdownProviderOptions = {},\n components: HTMLComponents<'permissive', {}> = {},\n wrapper?: ComponentType<unknown> | keyof JSX.IntrinsicElements\n): RenderMarkdownOptions => {\n return {\n ...baseOptions,\n ...options,\n forceBlock: options.forceBlock ?? baseOptions.forceBlock,\n forceInline: options.forceInline ?? baseOptions.forceInline,\n preserveFrontmatter:\n options.preserveFrontmatter ?? baseOptions.preserveFrontmatter,\n tagfilter: options.tagfilter ?? baseOptions.tagfilter,\n wrapper: wrapper || baseOptions.wrapper,\n forceWrapper: !!(wrapper || baseOptions.wrapper),\n components: { ...baseComponents, ...components },\n };\n};\n\nexport const MarkdownProvider: FunctionComponent<MarkdownProviderProps> = ({\n children,\n components,\n wrapper,\n forceBlock,\n forceInline,\n preserveFrontmatter,\n tagfilter,\n renderMarkdown: customRenderFn,\n}) => {\n const baseOptions: Omit<RenderMarkdownOptions, 'components'> = {\n forceBlock,\n forceInline,\n wrapper,\n forceWrapper: !!wrapper,\n preserveFrontmatter,\n tagfilter,\n };\n\n // Standard internal renderer\n const defaultRenderMarkdown = (\n markdown: string | ParsedMarkdown,\n options?: MarkdownProviderOptions,\n componentsOverride?: HTMLComponents<'permissive', {}>,\n wrapperOverride?: ComponentType<unknown> | keyof JSX.IntrinsicElements\n ): ComponentChildren => {\n const mergedOptions = mergeOptions(\n components,\n baseOptions,\n options,\n componentsOverride ?? {},\n wrapperOverride\n );\n return compileMarkdown(markdown, mergedOptions) as ComponentChildren;\n };\n\n // Wrapper for user-provided custom renderer\n // Note: We wrap in a clean Provider to prevent infinite recursion\n const customRenderMarkdownWrapper = (\n markdown: string | ParsedMarkdown,\n options?: MarkdownProviderOptions,\n componentsOverride?: HTMLComponents<'permissive', {}>,\n wrapperOverride?: ComponentType<unknown> | keyof JSX.IntrinsicElements\n ): ComponentChildren => (\n <MarkdownContext.Provider value={undefined}>\n {customRenderFn?.(markdown, options, componentsOverride, wrapperOverride)}\n </MarkdownContext.Provider>\n );\n\n return (\n <MarkdownContext.Provider\n value={{\n components,\n renderMarkdown: customRenderFn\n ? customRenderMarkdownWrapper\n : defaultRenderMarkdown,\n }}\n >\n {children}\n </MarkdownContext.Provider>\n );\n};\n"],"mappings":";;;;;;;AA0EA,MAAM,sBAAkBA,sBACtB,MACF;AAEA,MAAa,+BAA2BC,yBAAW,eAAe;AAElE,MAAM,gBACJ,gBACA,aACA,UAAmC,CAAC,GACpC,aAA+C,CAAC,GAChD,YAC0B;CAC1B,OAAO;EACL,GAAG;EACH,GAAG;EACH,YAAY,QAAQ,cAAc,YAAY;EAC9C,aAAa,QAAQ,eAAe,YAAY;EAChD,qBACE,QAAQ,uBAAuB,YAAY;EAC7C,WAAW,QAAQ,aAAa,YAAY;EAC5C,SAAS,WAAW,YAAY;EAChC,cAAc,CAAC,EAAE,WAAW,YAAY;EACxC,YAAY;GAAE,GAAG;GAAgB,GAAG;EAAW;CACjD;AACF;AAEA,MAAa,oBAA8D,EACzE,UACA,YACA,SACA,YACA,aACA,qBACA,WACA,gBAAgB,qBACZ;CACJ,MAAM,cAAyD;EAC7D;EACA;EACA;EACA,cAAc,CAAC,CAAC;EAChB;EACA;CACF;CAGA,MAAM,yBACJ,UACA,SACA,oBACA,oBACsB;EACtB,MAAM,gBAAgB,aACpB,YACA,aACA,SACA,sBAAsB,CAAC,GACvB,eACF;EACA,OAAOC,0CAAgB,UAAU,aAAa;CAChD;CAIA,MAAM,+BACJ,UACA,SACA,oBACA,oBAEA,4CAAC,gBAAgB,UAAjB;EAA0B,OAAO;YAC9B,iBAAiB,UAAU,SAAS,oBAAoB,eAAe;CAChD;CAG5B,OACE,4CAAC,gBAAgB,UAAjB;EACE,OAAO;GACL;GACA,gBAAgB,iBACZ,8BACA;EACN;EAEC;CACuB;AAE9B"}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
const require_client_useLocale = require('../client/useLocale.cjs');
|
|
5
5
|
const require_markdown_MarkdownProvider = require('./MarkdownProvider.cjs');
|
|
6
|
-
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
7
6
|
let _intlayer_core_markdown = require("@intlayer/core/markdown");
|
|
7
|
+
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
8
8
|
|
|
9
9
|
//#region src/markdown/MarkdownRendererPlugin.tsx
|
|
10
10
|
const MarkdownRendererPlugin = (props) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.cjs","names":["coreParseMarkdown","preactRuntime","compileWithOptions","coreRenderMarkdownAst"],"sources":["../../../src/markdown/compiler.ts"],"sourcesContent":["/**\n * Preact adapter for the framework-agnostic markdown processor.\n */\n\nimport {\n type CompileOptions,\n compileWithOptions,\n parseMarkdown as coreParseMarkdown,\n renderMarkdownAst as coreRenderMarkdownAst,\n type MarkdownContext,\n type ParsedMarkdown,\n} from '@intlayer/core/markdown';\nimport { preactRuntime } from './runtime';\n\n/**\n * Options accepted by `compileMarkdown` and `parseMarkdown` to customise\n * rendering behaviour (custom components, sanitizer, slugify, rule hooks, …).\n */\nexport type MarkdownCompilerOptions = CompileOptions;\n\n/**\n * Intermediate AST produced by `parseMarkdown`.\n * Pass this to `compileMarkdown` to skip re-parsing when the same content is\n * rendered multiple times.\n */\nexport type { ParsedMarkdown };\n\n/**\n * **Step 1 of 2 — parse only.**\n * Converts a raw markdown string into a `ParsedMarkdown` AST without rendering\n * any Preact elements. Use this when you need to:\n * - Cache the parsed result and render it several times with different options.\n * - Inspect or transform the AST before rendering.\n * - Defer the render step to a later point.\n *\n * @param markdown - The markdown source string.\n * @param options - Options that affect parsing (sanitizer, slugify, …).\n * @returns A `ParsedMarkdown` AST ready to be passed to `compileMarkdown`.\n *\n * @example\n * ```tsx\n * const ast = parseMarkdown('# Hello **world**');\n * const element = compileMarkdown(ast, { forceBlock: true });\n * ```\n */\nexport const parseMarkdown = (\n markdown: string = '',\n options: MarkdownCompilerOptions = {}\n): ParsedMarkdown => {\n const {\n components,\n namedCodesToUnicode,\n sanitizer,\n slugify,\n ...compilerOptions\n } = options;\n\n const ctx: MarkdownContext<
|
|
1
|
+
{"version":3,"file":"compiler.cjs","names":["coreParseMarkdown","preactRuntime","compileWithOptions","coreRenderMarkdownAst"],"sources":["../../../src/markdown/compiler.ts"],"sourcesContent":["/**\n * Preact adapter for the framework-agnostic markdown processor.\n */\n\nimport {\n type CompileOptions,\n compileWithOptions,\n parseMarkdown as coreParseMarkdown,\n renderMarkdownAst as coreRenderMarkdownAst,\n type HTMLTag,\n type MarkdownContext,\n type ParsedMarkdown,\n} from '@intlayer/core/markdown';\nimport type { ComponentType, JSX } from 'preact';\nimport type { HTMLComponents } from '../html/types';\nimport { preactRuntime } from './runtime';\n\n/**\n * Options accepted by `compileMarkdown` and `parseMarkdown` to customise\n * rendering behaviour (custom components, sanitizer, slugify, rule hooks, …).\n */\nexport type MarkdownCompilerOptions = Omit<\n CompileOptions<HTMLComponents<'permissive', {}>>,\n 'wrapper' | 'components'\n> & {\n wrapper?: ComponentType<unknown> | keyof JSX.IntrinsicElements | null;\n components?: HTMLComponents<'permissive', {}>;\n};\n\n/**\n * Intermediate AST produced by `parseMarkdown`.\n * Pass this to `compileMarkdown` to skip re-parsing when the same content is\n * rendered multiple times.\n */\nexport type { ParsedMarkdown };\n\n/**\n * **Step 1 of 2 — parse only.**\n * Converts a raw markdown string into a `ParsedMarkdown` AST without rendering\n * any Preact elements. Use this when you need to:\n * - Cache the parsed result and render it several times with different options.\n * - Inspect or transform the AST before rendering.\n * - Defer the render step to a later point.\n *\n * @param markdown - The markdown source string.\n * @param options - Options that affect parsing (sanitizer, slugify, …).\n * @returns A `ParsedMarkdown` AST ready to be passed to `compileMarkdown`.\n *\n * @example\n * ```tsx\n * const ast = parseMarkdown('# Hello **world**');\n * const element = compileMarkdown(ast, { forceBlock: true });\n * ```\n */\nexport const parseMarkdown = (\n markdown: string = '',\n options: MarkdownCompilerOptions = {}\n): ParsedMarkdown => {\n const {\n components,\n namedCodesToUnicode,\n sanitizer,\n slugify,\n ...compilerOptions\n } = options;\n\n const ctx: MarkdownContext<unknown> = {\n runtime: preactRuntime,\n components: components as unknown as Record<string, unknown>,\n namedCodesToUnicode,\n sanitizer: sanitizer as\n | ((value: string, tag: HTMLTag, attribute: string) => string | null)\n | undefined,\n slugify,\n };\n\n return coreParseMarkdown(\n markdown,\n ctx,\n compilerOptions as unknown as CompileOptions\n );\n};\n\n/**\n * **Steps 1 + 2 — parse and render in one shot.**\n * Accepts a raw markdown string or a pre-parsed `ParsedMarkdown` AST and\n * returns a Preact element. Use `parseMarkdown` first when you need to reuse\n * the same AST with different options.\n *\n * @param input - Markdown string or pre-parsed AST.\n * @param options - Rendering options (custom components, sanitizer, slugify, …).\n * @returns A Preact element representing the rendered markdown.\n *\n * @example\n * ```tsx\n * const element = compileMarkdown('# Hello **world**', { forceBlock: true });\n * ```\n */\nexport const compileMarkdown = (\n input: string | ParsedMarkdown = '',\n options: MarkdownCompilerOptions = {}\n) => {\n if (typeof input === 'string') {\n return compileWithOptions(\n input,\n preactRuntime,\n options as unknown as CompileOptions\n );\n }\n\n const {\n components,\n namedCodesToUnicode,\n sanitizer,\n slugify,\n ...compilerOptions\n } = options;\n\n const ctx: MarkdownContext<unknown> = {\n runtime: preactRuntime,\n components: components as unknown as Record<string, unknown>,\n namedCodesToUnicode,\n sanitizer: sanitizer as\n | ((value: string, tag: HTMLTag, attribute: string) => string | null)\n | undefined,\n slugify,\n };\n\n return coreRenderMarkdownAst(\n input,\n ctx,\n compilerOptions as unknown as CompileOptions\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,MAAa,iBACX,WAAmB,IACnB,UAAmC,CAAC,MACjB;CACnB,MAAM,EACJ,YACA,qBACA,WACA,SACA,GAAG,oBACD;CAYJ,WAAOA,uCACL,UACA;EAXA,SAASC;EACG;EACZ;EACW;EAGX;CAKE,GACF,eACF;AACF;;;;;;;;;;;;;;;;AAiBA,MAAa,mBACX,QAAiC,IACjC,UAAmC,CAAC,MACjC;CACH,IAAI,OAAO,UAAU,UACnB,WAAOC,4CACL,OACAD,kCACA,OACF;CAGF,MAAM,EACJ,YACA,qBACA,WACA,SACA,GAAG,oBACD;CAYJ,WAAOE,2CACL,OACA;EAXA,SAASF;EACG;EACZ;EACW;EAGX;CAKE,GACF,eACF;AACF"}
|