angular-intlayer 9.0.0-canary.2 → 9.0.0-canary.21
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/UI/IntlayerNode.component.cjs +4 -5
- package/dist/cjs/UI/IntlayerNode.component.cjs.map +1 -1
- package/dist/cjs/_virtual/{_@oxc-project_runtime@0.127.0/helpers → _@oxc-project_runtime@0.140.0/helpers/esm}/decorate.cjs +2 -2
- package/dist/{esm/_virtual/_@oxc-project_runtime@0.127.0/helpers/decorateMetadata.mjs → cjs/_virtual/_@oxc-project_runtime@0.140.0/helpers/esm/decorateMetadata.cjs} +3 -2
- package/dist/cjs/analytics/exposureSink.cjs +27 -0
- package/dist/cjs/analytics/exposureSink.cjs.map +1 -0
- package/dist/cjs/analytics/index.cjs +9 -0
- package/dist/cjs/analytics/useAnalytics.cjs +84 -0
- package/dist/cjs/analytics/useAnalytics.cjs.map +1 -0
- package/dist/cjs/analytics/useConversion.cjs +36 -0
- package/dist/cjs/analytics/useConversion.cjs.map +1 -0
- package/dist/cjs/analytics/useExperiment.cjs +69 -0
- package/dist/cjs/analytics/useExperiment.cjs.map +1 -0
- package/dist/cjs/client/index.cjs +3 -1
- package/dist/cjs/client/installIntlayer.cjs +9 -4
- package/dist/cjs/client/installIntlayer.cjs.map +1 -1
- package/dist/cjs/client/intlayerToken.cjs +0 -1
- package/dist/cjs/client/intlayerToken.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +1 -2
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +0 -1
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +2 -3
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +1 -2
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLoadDynamic.cjs +0 -1
- package/dist/cjs/client/useLoadDynamic.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +0 -1
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +0 -1
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
- package/dist/cjs/client/usePathname.cjs +52 -0
- package/dist/cjs/client/usePathname.cjs.map +1 -0
- package/dist/cjs/editor/ContentSelector.component.cjs +5 -6
- package/dist/cjs/editor/ContentSelector.component.cjs.map +1 -1
- package/dist/cjs/editor/EditorProvider.component.cjs +4 -5
- package/dist/cjs/editor/EditorProvider.component.cjs.map +1 -1
- package/dist/cjs/editor/useEditor.cjs +1 -2
- package/dist/cjs/editor/useEditor.cjs.map +1 -1
- package/dist/cjs/esbuild/plugin.cjs +19 -12
- package/dist/cjs/esbuild/plugin.cjs.map +1 -1
- package/dist/cjs/format/useCompact.cjs +0 -1
- package/dist/cjs/format/useCompact.cjs.map +1 -1
- package/dist/cjs/format/useCurrency.cjs +0 -1
- package/dist/cjs/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/format/useDate.cjs +0 -1
- package/dist/cjs/format/useDate.cjs.map +1 -1
- package/dist/cjs/format/useIntl.cjs +0 -1
- package/dist/cjs/format/useIntl.cjs.map +1 -1
- package/dist/cjs/format/useList.cjs +0 -1
- package/dist/cjs/format/useList.cjs.map +1 -1
- package/dist/cjs/format/useNumber.cjs +0 -1
- package/dist/cjs/format/useNumber.cjs.map +1 -1
- package/dist/cjs/format/usePercentage.cjs +0 -1
- package/dist/cjs/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/format/useRelativeTime.cjs +0 -1
- package/dist/cjs/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/format/useUnit.cjs +0 -1
- package/dist/cjs/format/useUnit.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs +1 -2
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +1 -2
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/html/installIntlayerHTML.cjs +2 -3
- package/dist/cjs/html/installIntlayerHTML.cjs.map +1 -1
- package/dist/cjs/index.cjs +10 -1
- package/dist/cjs/markdown/installIntlayerMarkdown.cjs +2 -3
- package/dist/cjs/markdown/installIntlayerMarkdown.cjs.map +1 -1
- package/dist/cjs/plugins.cjs +32 -21
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/renderIntlayerNode.cjs.map +1 -1
- package/dist/cjs/webpack/mergeConfig.cjs +5 -4
- package/dist/cjs/webpack/mergeConfig.cjs.map +1 -1
- package/dist/esm/UI/IntlayerNode.component.mjs +2 -2
- package/dist/esm/UI/IntlayerNode.component.mjs.map +1 -1
- package/dist/esm/_virtual/{_@oxc-project_runtime@0.127.0/helpers → _@oxc-project_runtime@0.140.0/helpers/esm}/decorate.mjs +2 -2
- package/dist/{cjs/_virtual/_@oxc-project_runtime@0.127.0/helpers/decorateMetadata.cjs → esm/_virtual/_@oxc-project_runtime@0.140.0/helpers/esm/decorateMetadata.mjs} +2 -3
- package/dist/esm/_virtual/_rolldown/runtime.mjs +8 -0
- package/dist/esm/analytics/exposureSink.mjs +24 -0
- package/dist/esm/analytics/exposureSink.mjs.map +1 -0
- package/dist/esm/analytics/index.mjs +5 -0
- package/dist/esm/analytics/useAnalytics.mjs +82 -0
- package/dist/esm/analytics/useAnalytics.mjs.map +1 -0
- package/dist/esm/analytics/useConversion.mjs +35 -0
- package/dist/esm/analytics/useConversion.mjs.map +1 -0
- package/dist/esm/analytics/useExperiment.mjs +68 -0
- package/dist/esm/analytics/useExperiment.mjs.map +1 -0
- package/dist/esm/client/index.mjs +2 -1
- package/dist/esm/client/installIntlayer.mjs +9 -4
- package/dist/esm/client/installIntlayer.mjs.map +1 -1
- package/dist/esm/client/intlayerToken.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +1 -1
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +2 -2
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +1 -1
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLoadDynamic.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleStorage.mjs.map +1 -1
- package/dist/esm/client/usePathname.mjs +51 -0
- package/dist/esm/client/usePathname.mjs.map +1 -0
- package/dist/esm/editor/ContentSelector.component.mjs +2 -2
- package/dist/esm/editor/ContentSelector.component.mjs.map +1 -1
- package/dist/esm/editor/EditorProvider.component.mjs +2 -2
- package/dist/esm/editor/EditorProvider.component.mjs.map +1 -1
- package/dist/esm/editor/useEditor.mjs +1 -1
- package/dist/esm/editor/useEditor.mjs.map +1 -1
- package/dist/esm/esbuild/plugin.mjs +16 -8
- package/dist/esm/esbuild/plugin.mjs.map +1 -1
- package/dist/esm/format/useCompact.mjs.map +1 -1
- package/dist/esm/format/useCurrency.mjs.map +1 -1
- package/dist/esm/format/useDate.mjs.map +1 -1
- package/dist/esm/format/useIntl.mjs.map +1 -1
- package/dist/esm/format/useList.mjs.map +1 -1
- package/dist/esm/format/useNumber.mjs.map +1 -1
- package/dist/esm/format/usePercentage.mjs.map +1 -1
- package/dist/esm/format/useRelativeTime.mjs.map +1 -1
- package/dist/esm/format/useUnit.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs +1 -1
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs +1 -1
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/esm/html/installIntlayerHTML.mjs +1 -1
- package/dist/esm/html/installIntlayerHTML.mjs.map +1 -1
- package/dist/esm/index.mjs +5 -1
- package/dist/esm/markdown/installIntlayerMarkdown.mjs +1 -1
- package/dist/esm/markdown/installIntlayerMarkdown.mjs.map +1 -1
- package/dist/esm/plugins.mjs +32 -21
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/renderIntlayerNode.mjs.map +1 -1
- package/dist/esm/webpack/mergeConfig.mjs +6 -3
- package/dist/esm/webpack/mergeConfig.mjs.map +1 -1
- package/dist/types/UI/IntlayerNode.component.d.ts +0 -1
- package/dist/types/UI/IntlayerNode.component.d.ts.map +1 -1
- package/dist/types/analytics/exposureSink.d.ts +32 -0
- package/dist/types/analytics/exposureSink.d.ts.map +1 -0
- package/dist/types/analytics/index.d.ts +4 -0
- package/dist/types/analytics/useAnalytics.d.ts +36 -0
- package/dist/types/analytics/useAnalytics.d.ts.map +1 -0
- package/dist/types/analytics/useConversion.d.ts +38 -0
- package/dist/types/analytics/useConversion.d.ts.map +1 -0
- package/dist/types/analytics/useExperiment.d.ts +47 -0
- package/dist/types/analytics/useExperiment.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +2 -1
- package/dist/types/client/installIntlayer.d.ts +2 -4
- package/dist/types/client/installIntlayer.d.ts.map +1 -1
- package/dist/types/client/intlayerToken.d.ts +1 -3
- package/dist/types/client/intlayerToken.d.ts.map +1 -1
- package/dist/types/client/useDictionary.d.ts +0 -1
- package/dist/types/client/useDictionary.d.ts.map +1 -1
- package/dist/types/client/useDictionaryAsync.d.ts +1 -3
- package/dist/types/client/useDictionaryAsync.d.ts.map +1 -1
- package/dist/types/client/useDictionaryDynamic.d.ts +2 -4
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/client/useIntlayer.d.ts +0 -1
- package/dist/types/client/useIntlayer.d.ts.map +1 -1
- package/dist/types/client/useLoadDynamic.d.ts.map +1 -1
- package/dist/types/client/useLocale.d.ts +1 -5
- package/dist/types/client/useLocale.d.ts.map +1 -1
- package/dist/types/client/useLocaleStorage.d.ts +5 -7
- package/dist/types/client/useLocaleStorage.d.ts.map +1 -1
- package/dist/types/client/usePathname.d.ts +35 -0
- package/dist/types/client/usePathname.d.ts.map +1 -0
- package/dist/types/editor/ContentSelector.component.d.ts.map +1 -1
- package/dist/types/editor/EditorProvider.component.d.ts.map +1 -1
- package/dist/types/editor/useEditor.d.ts +1 -3
- package/dist/types/editor/useEditor.d.ts.map +1 -1
- package/dist/types/esbuild/plugin.d.ts +2 -2
- package/dist/types/esbuild/plugin.d.ts.map +1 -1
- package/dist/types/format/useCompact.d.ts +2 -5
- package/dist/types/format/useCompact.d.ts.map +1 -1
- package/dist/types/format/useCurrency.d.ts +2 -5
- package/dist/types/format/useCurrency.d.ts.map +1 -1
- package/dist/types/format/useDate.d.ts +3 -7
- package/dist/types/format/useDate.d.ts.map +1 -1
- package/dist/types/format/useIntl.d.ts +1 -3
- package/dist/types/format/useIntl.d.ts.map +1 -1
- package/dist/types/format/useList.d.ts +5 -8
- package/dist/types/format/useList.d.ts.map +1 -1
- package/dist/types/format/useNumber.d.ts +2 -5
- package/dist/types/format/useNumber.d.ts.map +1 -1
- package/dist/types/format/usePercentage.d.ts +2 -5
- package/dist/types/format/usePercentage.d.ts.map +1 -1
- package/dist/types/format/useRelativeTime.d.ts +2 -5
- package/dist/types/format/useRelativeTime.d.ts.map +1 -1
- package/dist/types/format/useUnit.d.ts +2 -5
- package/dist/types/format/useUnit.d.ts.map +1 -1
- package/dist/types/getDictionary.d.ts +1 -2
- package/dist/types/getDictionary.d.ts.map +1 -1
- package/dist/types/getIntlayer.d.ts +1 -2
- package/dist/types/getIntlayer.d.ts.map +1 -1
- package/dist/types/html/installIntlayerHTML.d.ts +0 -1
- package/dist/types/html/installIntlayerHTML.d.ts.map +1 -1
- package/dist/types/index.d.ts +8 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/markdown/installIntlayerMarkdown.d.ts +0 -1
- package/dist/types/markdown/installIntlayerMarkdown.d.ts.map +1 -1
- package/dist/types/plugins.d.ts +0 -1
- package/dist/types/plugins.d.ts.map +1 -1
- package/dist/types/renderIntlayerNode.d.ts +1 -6
- package/dist/types/renderIntlayerNode.d.ts.map +1 -1
- package/dist/types/webpack/mergeConfig.d.ts +1 -1
- package/dist/types/webpack/mergeConfig.d.ts.map +1 -1
- package/package.json +19 -13
package/dist/cjs/index.cjs
CHANGED
|
@@ -3,6 +3,9 @@ const require_plugins = require('./plugins.cjs');
|
|
|
3
3
|
const require_getIntlayer = require('./getIntlayer.cjs');
|
|
4
4
|
const require_getDictionary = require('./getDictionary.cjs');
|
|
5
5
|
const require_client_intlayerToken = require('./client/intlayerToken.cjs');
|
|
6
|
+
const require_analytics_useAnalytics = require('./analytics/useAnalytics.cjs');
|
|
7
|
+
const require_analytics_useConversion = require('./analytics/useConversion.cjs');
|
|
8
|
+
const require_analytics_useExperiment = require('./analytics/useExperiment.cjs');
|
|
6
9
|
const require_client_installIntlayer = require('./client/installIntlayer.cjs');
|
|
7
10
|
const require_client_useDictionary = require('./client/useDictionary.cjs');
|
|
8
11
|
const require_client_useDictionaryAsync = require('./client/useDictionaryAsync.cjs');
|
|
@@ -10,6 +13,7 @@ const require_client_useLoadDynamic = require('./client/useLoadDynamic.cjs');
|
|
|
10
13
|
const require_client_useDictionaryDynamic = require('./client/useDictionaryDynamic.cjs');
|
|
11
14
|
const require_client_useIntlayer = require('./client/useIntlayer.cjs');
|
|
12
15
|
const require_client_useLocale = require('./client/useLocale.cjs');
|
|
16
|
+
const require_client_usePathname = require('./client/usePathname.cjs');
|
|
13
17
|
const require_UI_IntlayerNode_component = require('./UI/IntlayerNode.component.cjs');
|
|
14
18
|
|
|
15
19
|
exports.INTLAYER_TOKEN = require_client_intlayerToken.INTLAYER_TOKEN;
|
|
@@ -32,9 +36,14 @@ exports.isUpdatableNode = require_client_useIntlayer.isUpdatableNode;
|
|
|
32
36
|
exports.markdownPlugin = require_plugins.markdownPlugin;
|
|
33
37
|
exports.markdownStringPlugin = require_plugins.markdownStringPlugin;
|
|
34
38
|
exports.provideIntlayer = require_client_installIntlayer.provideIntlayer;
|
|
39
|
+
exports.provideIntlayerAnalytics = require_analytics_useAnalytics.provideIntlayerAnalytics;
|
|
40
|
+
exports.useAnalytics = require_analytics_useAnalytics.useAnalytics;
|
|
41
|
+
exports.useConversion = require_analytics_useConversion.useConversion;
|
|
35
42
|
exports.useDictionary = require_client_useDictionary.useDictionary;
|
|
36
43
|
exports.useDictionaryAsync = require_client_useDictionaryAsync.useDictionaryAsync;
|
|
37
44
|
exports.useDictionaryDynamic = require_client_useDictionaryDynamic.useDictionaryDynamic;
|
|
45
|
+
exports.useExperiment = require_analytics_useExperiment.useExperiment;
|
|
38
46
|
exports.useIntlayer = require_client_useIntlayer.useIntlayer;
|
|
39
47
|
exports.useLoadDynamic = require_client_useLoadDynamic.useLoadDynamic;
|
|
40
|
-
exports.useLocale = require_client_useLocale.useLocale;
|
|
48
|
+
exports.useLocale = require_client_useLocale.useLocale;
|
|
49
|
+
exports.usePathname = require_client_usePathname.usePathname;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const
|
|
3
|
-
const require_decorate = require('../_virtual/_@oxc-project_runtime@0.127.0/helpers/decorate.cjs');
|
|
2
|
+
const require_decorate = require('../_virtual/_@oxc-project_runtime@0.140.0/helpers/esm/decorate.cjs');
|
|
4
3
|
let _intlayer_core_markdown = require("@intlayer/core/markdown");
|
|
5
4
|
let _angular_core = require("@angular/core");
|
|
6
5
|
|
|
@@ -132,7 +131,7 @@ let IntlayerMarkdownService = class IntlayerMarkdownService {
|
|
|
132
131
|
return this.markdownProvider.renderMarkdown(markdown, overrides);
|
|
133
132
|
}
|
|
134
133
|
};
|
|
135
|
-
IntlayerMarkdownService = require_decorate.
|
|
134
|
+
IntlayerMarkdownService = require_decorate.default([(0, _angular_core.Injectable)({ providedIn: "root" })], IntlayerMarkdownService);
|
|
136
135
|
/**
|
|
137
136
|
* Reads the active markdown provider from the current Angular injector context.
|
|
138
137
|
* Returns a fallback object that uses the built-in HTML string renderer when
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installIntlayerMarkdown.cjs","names":["InjectionToken"],"sources":["../../../src/markdown/installIntlayerMarkdown.ts"],"sourcesContent":["import {\n Injectable,\n InjectionToken,\n inject,\n type TemplateRef,\n} from '@angular/core';\nimport type {\n MarkdownContext,\n MarkdownRuntime,\n ParsedMarkdown,\n} from '@intlayer/core/markdown';\nimport {\n type CompileOptions,\n compile,\n parseMarkdown as coreParseMarkdown,\n renderMarkdownAst as coreRenderMarkdownAst,\n} from '@intlayer/core/markdown';\n\n/**\n * Options accepted by `compileMarkdown` and `parseMarkdown` to customise\n * rendering behaviour (custom components, sanitizer, slugify, rule hooks, …).\n */\nexport type MarkdownRendererOptions = CompileOptions;\n\n/**\n * Angular `InjectionToken` used to provide a custom markdown renderer via the\n * DI system. Use `createIntlayerMarkdownProvider` to create the provider value\n * and register it in a module or component's `providers` array.\n */\nexport const INTLAYER_MARKDOWN_TOKEN =\n new InjectionToken<IntlayerMarkdownProvider>('intlayerMarkdown');\n\ntype RenderMarkdownOptions = {\n components?: any;\n wrapper?: string;\n options?: any;\n};\n\ntype RenderMarkdownFunction = (\n markdown: string | ParsedMarkdown,\n overrides?: any | RenderMarkdownOptions\n) => string | TemplateRef<any> | Promise<string | TemplateRef<any>>;\n\nexport type IntlayerMarkdownProvider = {\n renderMarkdown: RenderMarkdownFunction;\n};\n\n// Minimal runtime to generate HTML strings\nexport const htmlRuntime: MarkdownRuntime = {\n createElement: (tag: string | any, props: any, ...children: any[]) => {\n if (typeof tag !== 'string') {\n // Handle non-string tags if necessary (e.g. components), or fallback to div\n if (tag === htmlRuntime.Fragment) {\n return children.join('');\n }\n return '';\n }\n\n const attrs = props\n ? Object.entries(props)\n .map(([k, v]) => {\n if (k === 'key' || v === undefined || v === null) return '';\n const key = k === 'className' ? 'class' : k;\n return `${key}=\"${String(v).replace(/\"/g, '"')}\"`;\n })\n .filter(Boolean)\n .join(' ')\n : '';\n\n const childrenStr = children.join('');\n const voidTags = [\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n ];\n\n if (voidTags.includes(tag)) {\n return `<${tag} ${attrs} />`;\n }\n\n return `<${tag}${attrs ? ` ${attrs}` : ''}>${childrenStr}</${tag}>`;\n },\n cloneElement: (element: any, _props: any) => element, // Not really supported for strings\n Fragment: Symbol('Fragment'),\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 HTML. 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.\n * @returns A `ParsedMarkdown` AST ready to be passed to `compileMarkdown`.\n *\n * @example\n * ```ts\n * const ast = parseMarkdown('# Hello **world**');\n * const html = compileMarkdown(ast);\n * ```\n */\nexport const parseMarkdown = (\n markdown: string = '',\n options: any = {}\n): ParsedMarkdown => {\n const {\n components,\n namedCodesToUnicode,\n sanitizer,\n slugify,\n ...compilerOptions\n } = options;\n\n const ctx: MarkdownContext<any> = {\n runtime: htmlRuntime,\n components,\n namedCodesToUnicode,\n sanitizer: sanitizer as any,\n slugify,\n };\n\n return coreParseMarkdown(markdown, ctx, compilerOptions);\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 an HTML string. Use with Angular's `[innerHTML]` binding or\n * `IntlayerMarkdownService.renderMarkdown`.\n *\n * @param input - Markdown string or pre-parsed AST.\n * @param options - Rendering options (components, sanitizer, slugify, …).\n * @returns An HTML string representing the rendered markdown.\n *\n * @example\n * ```ts\n * const html = compileMarkdown('# Hello **world**');\n * ```\n */\nexport const compileMarkdown = (\n input: string | ParsedMarkdown = '',\n options: any = {}\n): string => {\n if (typeof input === 'string') {\n return compile(input, { ...options, runtime: htmlRuntime }) as string;\n }\n\n const {\n components,\n namedCodesToUnicode,\n sanitizer,\n slugify,\n ...compilerOptions\n } = options;\n\n const ctx: MarkdownContext<any> = {\n runtime: htmlRuntime,\n components,\n namedCodesToUnicode,\n sanitizer: sanitizer as any,\n slugify,\n };\n\n return coreRenderMarkdownAst(input, ctx, compilerOptions) as string;\n};\n\n/**\n * Default markdown renderer that converts markdown to HTML string\n */\nconst defaultMarkdownRenderer: RenderMarkdownFunction = (\n markdown: string | ParsedMarkdown\n) => compileMarkdown(markdown) as string;\n\n/**\n * Returns an Angular `Provider` object that registers a custom markdown render\n * function under `INTLAYER_MARKDOWN_TOKEN`. Pass the returned provider to a\n * module or component's `providers` array.\n *\n * @param renderMarkdown - Custom render function. Defaults to the built-in\n * HTML string renderer when omitted.\n *\n * @example\n * ```ts\n * // app.module.ts\n * @NgModule({\n * providers: [createIntlayerMarkdownProvider(myCustomRenderer)],\n * })\n * export class AppModule {}\n * ```\n */\nexport const createIntlayerMarkdownProvider = (\n renderMarkdown: RenderMarkdownFunction = defaultMarkdownRenderer\n) => ({\n provide: INTLAYER_MARKDOWN_TOKEN,\n useValue: {\n renderMarkdown,\n } as IntlayerMarkdownProvider,\n});\n\n/**\n * Angular injectable service that wraps the active markdown renderer. Inject\n * this service anywhere in your app to call `renderMarkdown` without touching\n * the DI token directly. Falls back to returning the raw markdown string when\n * no provider is registered.\n *\n * @example\n * ```ts\n * @Component({ ... })\n * export class MyComponent {\n * private markdownService = inject(IntlayerMarkdownService);\n *\n * get html() {\n * return this.markdownService.renderMarkdown('# Hello');\n * }\n * }\n * ```\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class IntlayerMarkdownService {\n private markdownProvider = inject(INTLAYER_MARKDOWN_TOKEN, {\n optional: true,\n });\n\n renderMarkdown(\n markdown: string | ParsedMarkdown,\n overrides?: any\n ): string | TemplateRef<any> | Promise<string | TemplateRef<any>> {\n if (!this.markdownProvider) {\n return typeof markdown === 'string' ? markdown : ''; // Fallback to returning markdown as is\n }\n return this.markdownProvider.renderMarkdown(markdown, overrides);\n }\n}\n\n/**\n * Reads the active markdown provider from the current Angular injector context.\n * Returns a fallback object that uses the built-in HTML string renderer when\n * `createIntlayerMarkdownProvider` has not been registered.\n *\n * @returns An `IntlayerMarkdownProvider` with a `renderMarkdown` method.\n *\n * @example\n * ```ts\n * @Component({ ... })\n * export class MyComponent {\n * private markdown = useMarkdown();\n *\n * get html() {\n * return this.markdown.renderMarkdown('# Hello');\n * }\n * }\n * ```\n */\nexport const useMarkdown = (): IntlayerMarkdownProvider => {\n const markdownProvider = inject(INTLAYER_MARKDOWN_TOKEN, { optional: true });\n\n if (!markdownProvider) {\n return {\n renderMarkdown: defaultMarkdownRenderer,\n };\n }\n\n return markdownProvider;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"installIntlayerMarkdown.cjs","names":["InjectionToken"],"sources":["../../../src/markdown/installIntlayerMarkdown.ts"],"sourcesContent":["import {\n Injectable,\n InjectionToken,\n inject,\n type TemplateRef,\n} from '@angular/core';\nimport type {\n MarkdownContext,\n MarkdownRuntime,\n ParsedMarkdown,\n} from '@intlayer/core/markdown';\nimport {\n type CompileOptions,\n compile,\n parseMarkdown as coreParseMarkdown,\n renderMarkdownAst as coreRenderMarkdownAst,\n} from '@intlayer/core/markdown';\n\n/**\n * Options accepted by `compileMarkdown` and `parseMarkdown` to customise\n * rendering behaviour (custom components, sanitizer, slugify, rule hooks, …).\n */\nexport type MarkdownRendererOptions = CompileOptions;\n\n/**\n * Angular `InjectionToken` used to provide a custom markdown renderer via the\n * DI system. Use `createIntlayerMarkdownProvider` to create the provider value\n * and register it in a module or component's `providers` array.\n */\nexport const INTLAYER_MARKDOWN_TOKEN =\n new InjectionToken<IntlayerMarkdownProvider>('intlayerMarkdown');\n\ntype RenderMarkdownOptions = {\n components?: any;\n wrapper?: string;\n options?: any;\n};\n\ntype RenderMarkdownFunction = (\n markdown: string | ParsedMarkdown,\n overrides?: any | RenderMarkdownOptions\n) => string | TemplateRef<any> | Promise<string | TemplateRef<any>>;\n\nexport type IntlayerMarkdownProvider = {\n renderMarkdown: RenderMarkdownFunction;\n};\n\n// Minimal runtime to generate HTML strings\nexport const htmlRuntime: MarkdownRuntime = {\n createElement: (tag: string | any, props: any, ...children: any[]) => {\n if (typeof tag !== 'string') {\n // Handle non-string tags if necessary (e.g. components), or fallback to div\n if (tag === htmlRuntime.Fragment) {\n return children.join('');\n }\n return '';\n }\n\n const attrs = props\n ? Object.entries(props)\n .map(([k, v]) => {\n if (k === 'key' || v === undefined || v === null) return '';\n const key = k === 'className' ? 'class' : k;\n return `${key}=\"${String(v).replace(/\"/g, '"')}\"`;\n })\n .filter(Boolean)\n .join(' ')\n : '';\n\n const childrenStr = children.join('');\n const voidTags = [\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n ];\n\n if (voidTags.includes(tag)) {\n return `<${tag} ${attrs} />`;\n }\n\n return `<${tag}${attrs ? ` ${attrs}` : ''}>${childrenStr}</${tag}>`;\n },\n cloneElement: (element: any, _props: any) => element, // Not really supported for strings\n Fragment: Symbol('Fragment'),\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 HTML. 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.\n * @returns A `ParsedMarkdown` AST ready to be passed to `compileMarkdown`.\n *\n * @example\n * ```ts\n * const ast = parseMarkdown('# Hello **world**');\n * const html = compileMarkdown(ast);\n * ```\n */\nexport const parseMarkdown = (\n markdown: string = '',\n options: any = {}\n): ParsedMarkdown => {\n const {\n components,\n namedCodesToUnicode,\n sanitizer,\n slugify,\n ...compilerOptions\n } = options;\n\n const ctx: MarkdownContext<any> = {\n runtime: htmlRuntime,\n components,\n namedCodesToUnicode,\n sanitizer: sanitizer as any,\n slugify,\n };\n\n return coreParseMarkdown(markdown, ctx, compilerOptions);\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 an HTML string. Use with Angular's `[innerHTML]` binding or\n * `IntlayerMarkdownService.renderMarkdown`.\n *\n * @param input - Markdown string or pre-parsed AST.\n * @param options - Rendering options (components, sanitizer, slugify, …).\n * @returns An HTML string representing the rendered markdown.\n *\n * @example\n * ```ts\n * const html = compileMarkdown('# Hello **world**');\n * ```\n */\nexport const compileMarkdown = (\n input: string | ParsedMarkdown = '',\n options: any = {}\n): string => {\n if (typeof input === 'string') {\n return compile(input, { ...options, runtime: htmlRuntime }) as string;\n }\n\n const {\n components,\n namedCodesToUnicode,\n sanitizer,\n slugify,\n ...compilerOptions\n } = options;\n\n const ctx: MarkdownContext<any> = {\n runtime: htmlRuntime,\n components,\n namedCodesToUnicode,\n sanitizer: sanitizer as any,\n slugify,\n };\n\n return coreRenderMarkdownAst(input, ctx, compilerOptions) as string;\n};\n\n/**\n * Default markdown renderer that converts markdown to HTML string\n */\nconst defaultMarkdownRenderer: RenderMarkdownFunction = (\n markdown: string | ParsedMarkdown\n) => compileMarkdown(markdown) as string;\n\n/**\n * Returns an Angular `Provider` object that registers a custom markdown render\n * function under `INTLAYER_MARKDOWN_TOKEN`. Pass the returned provider to a\n * module or component's `providers` array.\n *\n * @param renderMarkdown - Custom render function. Defaults to the built-in\n * HTML string renderer when omitted.\n *\n * @example\n * ```ts\n * // app.module.ts\n * @NgModule({\n * providers: [createIntlayerMarkdownProvider(myCustomRenderer)],\n * })\n * export class AppModule {}\n * ```\n */\nexport const createIntlayerMarkdownProvider = (\n renderMarkdown: RenderMarkdownFunction = defaultMarkdownRenderer\n) => ({\n provide: INTLAYER_MARKDOWN_TOKEN,\n useValue: {\n renderMarkdown,\n } as IntlayerMarkdownProvider,\n});\n\n/**\n * Angular injectable service that wraps the active markdown renderer. Inject\n * this service anywhere in your app to call `renderMarkdown` without touching\n * the DI token directly. Falls back to returning the raw markdown string when\n * no provider is registered.\n *\n * @example\n * ```ts\n * @Component({ ... })\n * export class MyComponent {\n * private markdownService = inject(IntlayerMarkdownService);\n *\n * get html() {\n * return this.markdownService.renderMarkdown('# Hello');\n * }\n * }\n * ```\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class IntlayerMarkdownService {\n private markdownProvider = inject(INTLAYER_MARKDOWN_TOKEN, {\n optional: true,\n });\n\n renderMarkdown(\n markdown: string | ParsedMarkdown,\n overrides?: any\n ): string | TemplateRef<any> | Promise<string | TemplateRef<any>> {\n if (!this.markdownProvider) {\n return typeof markdown === 'string' ? markdown : ''; // Fallback to returning markdown as is\n }\n return this.markdownProvider.renderMarkdown(markdown, overrides);\n }\n}\n\n/**\n * Reads the active markdown provider from the current Angular injector context.\n * Returns a fallback object that uses the built-in HTML string renderer when\n * `createIntlayerMarkdownProvider` has not been registered.\n *\n * @returns An `IntlayerMarkdownProvider` with a `renderMarkdown` method.\n *\n * @example\n * ```ts\n * @Component({ ... })\n * export class MyComponent {\n * private markdown = useMarkdown();\n *\n * get html() {\n * return this.markdown.renderMarkdown('# Hello');\n * }\n * }\n * ```\n */\nexport const useMarkdown = (): IntlayerMarkdownProvider => {\n const markdownProvider = inject(INTLAYER_MARKDOWN_TOKEN, { optional: true });\n\n if (!markdownProvider) {\n return {\n renderMarkdown: defaultMarkdownRenderer,\n };\n }\n\n return markdownProvider;\n};\n"],"mappings":";;;;;;;;;;;AA6BA,MAAa,0BACX,IAAIA,6BAAyC,kBAAkB;AAkBjE,MAAa,cAA+B;CAC1C,gBAAgB,KAAmB,OAAY,GAAG,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,aACG,gBAAgB,QAAQ;;;;;;;;;;;;;;;;;;AAmB7B,MAAa,kCACX,iBAAyC,6BACrC;CACJ,SAAS;CACT,UAAU,EACR,eACF;AACF;AAuBO,IAAM,0BAAN,MAAM,wBAAwB;CACnC,AAAQ,6CAA0B,yBAAyB,EACzD,UAAU,KACZ,CAAC;CAED,eACE,UACA,WACgE;EAChE,IAAI,CAAC,KAAK,kBACR,OAAO,OAAO,aAAa,WAAW,WAAW;EAEnD,OAAO,KAAK,iBAAiB,eAAe,UAAU,SAAS;CACjE;AACF;kFAjBY,EACV,YAAY,OACd,CAAC;;;;;;;;;;;;;;;;;;;;AAoCD,MAAa,oBAA8C;CACzD,MAAM,6CAA0B,yBAAyB,EAAE,UAAU,KAAK,CAAC;CAE3E,IAAI,CAAC,kBACH,OAAO,EACL,gBAAgB,wBAClB;CAGF,OAAO;AACT"}
|
package/dist/cjs/plugins.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
3
|
const require_renderIntlayerNode = require('./renderIntlayerNode.cjs');
|
|
4
|
+
const require_analytics_exposureSink = require('./analytics/exposureSink.cjs');
|
|
4
5
|
const require_editor_ContentSelector_component = require('./editor/ContentSelector.component.cjs');
|
|
5
6
|
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
6
7
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
@@ -10,7 +11,7 @@ _intlayer_types_nodeType = require_runtime.__toESM(_intlayer_types_nodeType);
|
|
|
10
11
|
|
|
11
12
|
//#region src/plugins.ts
|
|
12
13
|
let _markdownInstall = null;
|
|
13
|
-
if (process.env
|
|
14
|
+
if (process.env.INTLAYER_NODE_TYPE_MARKDOWN !== "false" || process.env.INTLAYER_NODE_TYPE_HTML !== "false") Promise.resolve().then(() => require("./markdown/installIntlayerMarkdown.cjs")).then((m) => {
|
|
14
15
|
_markdownInstall = m;
|
|
15
16
|
});
|
|
16
17
|
/** ---------------------------------------------
|
|
@@ -40,21 +41,29 @@ const createRuntimeWithOverides = (baseRuntime, overrides) => ({
|
|
|
40
41
|
const intlayerNodePlugins = {
|
|
41
42
|
id: "intlayer-node-plugin",
|
|
42
43
|
canHandle: (node) => typeof node === "bigint" || typeof node === "string" || typeof node === "number",
|
|
43
|
-
transform: (_node, { children, ...rest }) =>
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
children
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
transform: (_node, { children, ...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: "text"
|
|
50
|
+
});
|
|
51
|
+
return require_renderIntlayerNode.renderIntlayerNode({
|
|
52
|
+
...rest,
|
|
53
|
+
value: children,
|
|
54
|
+
children: () => ({
|
|
55
|
+
component: process.env.INTLAYER_EDITOR_ENABLED === "false" || !_intlayer_config_built.editor.enabled ? children : require_editor_ContentSelector_component.ContentSelectorWrapperComponent,
|
|
56
|
+
props: {
|
|
57
|
+
dictionaryKey: rest.dictionaryKey,
|
|
58
|
+
keyPath: rest.keyPath
|
|
59
|
+
},
|
|
60
|
+
children
|
|
61
|
+
})
|
|
62
|
+
});
|
|
63
|
+
}
|
|
55
64
|
};
|
|
56
65
|
/** Markdown string plugin. Replaces string node with a component that render the markdown. */
|
|
57
|
-
const markdownStringPlugin = process.env
|
|
66
|
+
const markdownStringPlugin = process.env.INTLAYER_NODE_TYPE_MARKDOWN === "false" ? _intlayer_core_interpreter.fallbackPlugin : {
|
|
58
67
|
id: "markdown-string-plugin",
|
|
59
68
|
canHandle: (node) => typeof node === "string",
|
|
60
69
|
transform: (node, props, deepTransformNode) => {
|
|
@@ -75,7 +84,7 @@ const markdownStringPlugin = process.env["INTLAYER_NODE_TYPE_MARKDOWN"] === "fal
|
|
|
75
84
|
const render = (components) => require_renderIntlayerNode.renderIntlayerNode({
|
|
76
85
|
...rest,
|
|
77
86
|
value: node,
|
|
78
|
-
children: process.env
|
|
87
|
+
children: process.env.INTLAYER_EDITOR_ENABLED === "false" || !_intlayer_config_built.editor.enabled ? () => {
|
|
79
88
|
const { renderMarkdown } = _markdownInstall?.useMarkdown() ?? { renderMarkdown: () => node };
|
|
80
89
|
return renderMarkdown(node, components);
|
|
81
90
|
} : () => ({
|
|
@@ -117,7 +126,7 @@ const markdownStringPlugin = process.env["INTLAYER_NODE_TYPE_MARKDOWN"] === "fal
|
|
|
117
126
|
return createProxy(render());
|
|
118
127
|
}
|
|
119
128
|
};
|
|
120
|
-
const markdownPlugin = process.env
|
|
129
|
+
const markdownPlugin = process.env.INTLAYER_NODE_TYPE_MARKDOWN === "false" ? _intlayer_core_interpreter.fallbackPlugin : {
|
|
121
130
|
id: "markdown-plugin",
|
|
122
131
|
canHandle: (node) => typeof node === "object" && node?.nodeType === _intlayer_types_nodeType.MARKDOWN,
|
|
123
132
|
transform: (node, props, deepTransformNode) => {
|
|
@@ -132,7 +141,7 @@ const markdownPlugin = process.env["INTLAYER_NODE_TYPE_MARKDOWN"] === "false" ?
|
|
|
132
141
|
}
|
|
133
142
|
};
|
|
134
143
|
/** HTML plugin. Replaces node with a function that takes components => IntlayerNode. */
|
|
135
|
-
const htmlPlugin = process.env
|
|
144
|
+
const htmlPlugin = process.env.INTLAYER_NODE_TYPE_HTML === "false" ? _intlayer_core_interpreter.fallbackPlugin : {
|
|
136
145
|
id: "html-plugin",
|
|
137
146
|
canHandle: (node) => typeof node === "object" && node?.nodeType === _intlayer_types_nodeType.HTML,
|
|
138
147
|
transform: (node, props) => {
|
|
@@ -141,7 +150,7 @@ const htmlPlugin = process.env["INTLAYER_NODE_TYPE_HTML"] === "false" ? _intlaye
|
|
|
141
150
|
const render = (userComponents) => require_renderIntlayerNode.renderIntlayerNode({
|
|
142
151
|
...rest,
|
|
143
152
|
value: html,
|
|
144
|
-
children: process.env
|
|
153
|
+
children: process.env.INTLAYER_EDITOR_ENABLED === "false" || !_intlayer_config_built.editor.enabled ? html : () => ({
|
|
145
154
|
component: require_editor_ContentSelector_component.ContentSelectorWrapperComponent,
|
|
146
155
|
props: {
|
|
147
156
|
dictionaryKey: rest.dictionaryKey,
|
|
@@ -157,13 +166,15 @@ const htmlPlugin = process.env["INTLAYER_NODE_TYPE_HTML"] === "false" ? _intlaye
|
|
|
157
166
|
if (!components || typeof components === "object" && Object.keys(components).length === 0) return String(html);
|
|
158
167
|
const htmlRuntime = _markdownInstall?.htmlRuntime;
|
|
159
168
|
if (!htmlRuntime || !_intlayer_core_markdown.compile) return String(html);
|
|
160
|
-
|
|
169
|
+
const runtime = createRuntimeWithOverides(htmlRuntime, components);
|
|
170
|
+
return (0, _intlayer_core_markdown.compile)(html, { runtime });
|
|
161
171
|
};
|
|
162
172
|
if (prop === Symbol.toPrimitive) return () => {
|
|
163
173
|
if (!components || typeof components === "object" && Object.keys(components).length === 0) return String(html);
|
|
164
174
|
const htmlRuntime = _markdownInstall?.htmlRuntime;
|
|
165
175
|
if (!htmlRuntime || !_intlayer_core_markdown.compile) return String(html);
|
|
166
|
-
|
|
176
|
+
const runtime = createRuntimeWithOverides(htmlRuntime, components);
|
|
177
|
+
return (0, _intlayer_core_markdown.compile)(html, { runtime });
|
|
167
178
|
};
|
|
168
179
|
if (prop === "use") return (userComponents) => {
|
|
169
180
|
const mergedComponents = {
|
|
@@ -177,7 +188,7 @@ const htmlPlugin = process.env["INTLAYER_NODE_TYPE_HTML"] === "false" ? _intlaye
|
|
|
177
188
|
return createProxy(render());
|
|
178
189
|
}
|
|
179
190
|
};
|
|
180
|
-
const insertionPlugin = process.env
|
|
191
|
+
const insertionPlugin = process.env.INTLAYER_NODE_TYPE_INSERTION === "false" ? _intlayer_core_interpreter.fallbackPlugin : {
|
|
181
192
|
id: "insertion-plugin",
|
|
182
193
|
canHandle: (node) => typeof node === "object" && node?.nodeType === _intlayer_types_nodeType.INSERTION,
|
|
183
194
|
transform: (node, props) => {
|
package/dist/cjs/plugins.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.cjs","names":["renderIntlayerNode","editor","ContentSelectorWrapperComponent","fallbackPlugin","compile","NodeTypes","internationalization","enumerationPlugin","conditionPlugin","filePlugin","genderPlugin"],"sources":["../../src/plugins.ts"],"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 translationPlugin,\n} from '@intlayer/core/interpreter';\nimport type { MarkdownContent } from '@intlayer/core/markdown';\nimport { compile, getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type { HTMLContent, InsertionContent } 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 { ContentSelectorWrapperComponent } from './editor/ContentSelector.component';\nimport { renderIntlayerNode } from './renderIntlayerNode';\n\nlet _markdownInstall: {\n htmlRuntime: any;\n useMarkdown: () => { renderMarkdown: (s: string, components?: any) => any };\n} | null = null;\nif (\n process.env['INTLAYER_NODE_TYPE_MARKDOWN'] !== 'false' ||\n process.env['INTLAYER_NODE_TYPE_HTML'] !== 'false'\n) {\n void import('./markdown/installIntlayerMarkdown').then((m) => {\n _markdownInstall = m as any;\n });\n}\n\n/** ---------------------------------------------\n * UTILS\n * --------------------------------------------- */\n\nconst createRuntimeWithOverides = (baseRuntime: any, overrides: any) => ({\n ...baseRuntime,\n createElement: (tag: string, props: any, ...children: any[]) => {\n const override = overrides?.[tag];\n\n if (override) {\n const newProps = { ...props, ...override };\n\n // Merge class attributes intelligently\n const originalClass = props?.class || props?.className;\n const overrideClass = override.class || override.className;\n\n if (originalClass && overrideClass) {\n newProps.class = `${originalClass} ${overrideClass}`;\n newProps.className = undefined;\n }\n\n return baseRuntime.createElement(tag, newProps, ...children);\n }\n\n return baseRuntime.createElement(tag, props, ...children);\n },\n});\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\nexport interface IntlayerNode<T, P = {}> {\n value: T;\n children?: any;\n additionalProps?: P;\n}\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const intlayerNodePlugins: Plugins = {\n id: 'intlayer-node-plugin',\n canHandle: (node) =>\n typeof node === 'bigint' ||\n typeof node === 'string' ||\n typeof node === 'number',\n transform: (_node, { children, ...rest }) =>\n renderIntlayerNode({\n ...rest,\n value: children,\n children: () => ({\n component:\n process.env['INTLAYER_EDITOR_ENABLED'] === 'false' || !editor.enabled\n ? children\n : ContentSelectorWrapperComponent,\n props: {\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n },\n children: children,\n }),\n }),\n};\n\n/**\n * MARKDOWN PLUGIN\n */\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<string, { metadata: DeepTransformContent<string> }>\n : never;\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: node,\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?: any) =>\n renderIntlayerNode({\n ...rest,\n value: node,\n children:\n process.env['INTLAYER_EDITOR_ENABLED'] === 'false' ||\n !editor.enabled\n ? () => {\n const { renderMarkdown } =\n _markdownInstall?.useMarkdown() ?? {\n renderMarkdown: () => node,\n };\n return renderMarkdown(node, components);\n }\n : () => ({\n component: ContentSelectorWrapperComponent,\n props: {\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n ...components,\n },\n children: () => {\n const { renderMarkdown } =\n _markdownInstall?.useMarkdown() ?? {\n renderMarkdown: () => node,\n };\n return renderMarkdown(node, components);\n },\n }),\n additionalProps: {\n metadata: metadataNodes,\n },\n });\n\n const createProxy = (element: any, components?: any) =>\n new Proxy(element, {\n get(target, prop, receiver) {\n if (prop === 'value') {\n return node;\n }\n if (prop === 'metadata') {\n return metadataNodes;\n }\n\n if (prop === 'toString') {\n return () => {\n const htmlRuntime = _markdownInstall?.htmlRuntime;\n if (!htmlRuntime || !compile) return node;\n const runtime = components\n ? createRuntimeWithOverides(htmlRuntime, components)\n : htmlRuntime;\n return compile(node, { runtime }) as string;\n };\n }\n\n if (prop === Symbol.toPrimitive) {\n return () => {\n const htmlRuntime = _markdownInstall?.htmlRuntime;\n if (!htmlRuntime || !compile) return node;\n const runtime = components\n ? createRuntimeWithOverides(htmlRuntime, components)\n : htmlRuntime;\n return compile(node, { runtime }) as string;\n };\n }\n\n if (prop === 'use') {\n return (newComponents?: any) => {\n const mergedComponents = {\n ...components,\n ...newComponents,\n };\n return createProxy(\n render(mergedComponents),\n mergedComponents\n );\n };\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n\n return createProxy(render() as any);\n },\n };\n\nexport type MarkdownCond<T, _S, _L extends LocalesValues> = 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?: Record<keyof U, any>) => any;\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.\n *\n * This ensures type safety:\n * - `html('<div>Hello <CustomComponent /></div>').use({ CustomComponent: ... })` - optional but typed\n */\nexport type HTMLPluginCond<T, _S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.HTML]: infer I;\n tags?: infer U;\n}\n ? IntlayerNode<\n I,\n {\n use: (components?: Record<keyof U, any>) => any;\n }\n >\n : never;\n\n/** HTML plugin. Replaces node with a function that takes components => IntlayerNode. */\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?: any) =>\n renderIntlayerNode({\n ...rest,\n value: html,\n children:\n process.env['INTLAYER_EDITOR_ENABLED'] === 'false' ||\n !editor.enabled\n ? html\n : () => ({\n component: ContentSelectorWrapperComponent,\n props: {\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n ...userComponents,\n },\n children: html,\n }),\n });\n\n const createProxy = (element: any, components?: any) =>\n new Proxy(element, {\n get(target, prop, receiver) {\n if (prop === 'value') {\n return html;\n }\n\n if (prop === 'toString') {\n return () => {\n if (\n !components ||\n (typeof components === 'object' &&\n Object.keys(components).length === 0)\n ) {\n return String(html);\n }\n const htmlRuntime = _markdownInstall?.htmlRuntime;\n if (!htmlRuntime || !compile) return String(html);\n const runtime = createRuntimeWithOverides(\n htmlRuntime,\n components\n );\n return compile(html, { runtime }) as string;\n };\n }\n\n if (prop === Symbol.toPrimitive) {\n return () => {\n if (\n !components ||\n (typeof components === 'object' &&\n Object.keys(components).length === 0)\n ) {\n return String(html);\n }\n const htmlRuntime = _markdownInstall?.htmlRuntime;\n if (!htmlRuntime || !compile) return String(html);\n const runtime = createRuntimeWithOverides(\n htmlRuntime,\n components\n );\n return compile(html, { runtime }) as string;\n };\n }\n\n if (prop === 'use') {\n // Return a properly typed function based on custom components\n return (userComponents?: any) => {\n const mergedComponents = {\n ...components,\n ...userComponents,\n };\n return createProxy(\n render(mergedComponents),\n mergedComponents\n );\n };\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n\n return createProxy(render() as any);\n },\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\n/**\n * Insertion conditional type.\n */\nexport type InsertionPluginCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer _I;\n}\n ? (args: Record<string, string | number>) => string\n : never;\n\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) => {\n const { plugins, ...rest } = props;\n\n // Return a function that performs the interpolation\n const render = (args: Record<string, string | number> = {}) => {\n let text = node[NodeTypes.INSERTION] as string;\n if (args) {\n Object.entries(args).forEach(([key, value]) => {\n text = text.replace(\n new RegExp(`{{\\\\s*${key}\\\\s*}}`, 'g'),\n String(value)\n );\n });\n }\n return text;\n };\n\n return renderIntlayerNode({\n ...rest,\n value: render as any,\n children: render,\n });\n },\n };\n\nexport interface IInterpreterPluginAngular<T, S, L extends LocalesValues> {\n angularIntlayerNode: IntlayerNodeCond<T>;\n angularMarkdown: MarkdownCond<T, S, L>;\n angularHtml: HTMLPluginCond<T, S, L>;\n angularInsertion: InsertionPluginCond<T>;\n}\n\n/**\n * Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.\n *\n * Otherwise the the `angular-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 angularIntlayerNode: true;\n angularMarkdown: true;\n angularHtml: true;\n angularInsertion: 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 Angular 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 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 filePlugin,\n genderPlugin,\n intlayerNodePlugins,\n markdownPlugin,\n htmlPlugin,\n insertionPlugin,\n ] as Plugins[];\n\n pluginsCache.set(cacheKey, plugins);\n\n return plugins;\n};\n"],"mappings":";;;;;;;;;;;AA2BA,IAAI,mBAGO;AACX,IACE,QAAQ,IAAI,mCAAmC,WAC/C,QAAQ,IAAI,+BAA+B,QAE3C,sCAAK,2CAA6C,MAAM,MAAM;AAC5D,oBAAmB;EACnB;;;;AAOJ,MAAM,6BAA6B,aAAkB,eAAoB;CACvE,GAAG;CACH,gBAAgB,KAAa,OAAY,GAAG,aAAoB;EAC9D,MAAM,WAAW,YAAY;AAE7B,MAAI,UAAU;GACZ,MAAM,WAAW;IAAE,GAAG;IAAO,GAAG;IAAU;GAG1C,MAAM,gBAAgB,OAAO,SAAS,OAAO;GAC7C,MAAM,gBAAgB,SAAS,SAAS,SAAS;AAEjD,OAAI,iBAAiB,eAAe;AAClC,aAAS,QAAQ,GAAG,cAAc,GAAG;AACrC,aAAS,YAAY;;AAGvB,UAAO,YAAY,cAAc,KAAK,UAAU,GAAG,SAAS;;AAG9D,SAAO,YAAY,cAAc,KAAK,OAAO,GAAG,SAAS;;CAE5D;;AAiBD,MAAa,sBAA+B;CAC1C,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAChB,OAAO,SAAS,YAChB,OAAO,SAAS;CAClB,YAAY,OAAO,EAAE,UAAU,GAAG,WAChCA,8CAAmB;EACjB,GAAG;EACH,OAAO;EACP,iBAAiB;GACf,WACE,QAAQ,IAAI,+BAA+B,WAAW,CAACC,8BAAO,UAC1D,WACAC;GACN,OAAO;IACL,eAAe,KAAK;IACpB,SAAS,KAAK;IACf;GACS;GACX;EACF,CAAC;CACL;;AAWD,MAAa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,KAAK,QACV,IAAI,OAAO,SAAS,IAAI,SAAS,IAAI,EACrC,OAAO,MAAM,CACd;KACD;AAEJ,UAAO;;AAGT,SAAOL,8CAAmB;GACxB,GAAG;GACH,OAAO;GACP,UAAU;GACX,CAAC;;CAEL;AA6BP,MAAM,+BAAe,IAAI,KAAwB;;;;;AAMjD,MAAa,cACX,QACA,WAAoB,SACN;CAEd,MAAM,WAAW,GADK,UAAUM,4CAAqB,cACnB,GAAG;AAErC,KAAI,aAAa,IAAI,SAAS,CAC5B,QAAO,aAAa,IAAI,SAAS;CAGnC,MAAM,UAAU;oDAEZ,UAAUA,4CAAqB,eAC/B,WAAWA,4CAAqB,gBAAgB,OACjD;EACDC;+CACa,UAAUD,4CAAqB,cAAc;EAC1DE;+CACa,UAAUF,4CAAqB,cAAc;EAC1DG;EACAC;EACA;EACA;EACA;EACA;EACD;AAED,cAAa,IAAI,UAAU,QAAQ;AAEnC,QAAO"}
|
|
1
|
+
{"version":3,"file":"plugins.cjs","names":["renderIntlayerNode","editor","ContentSelectorWrapperComponent","fallbackPlugin","compile","NodeTypes","internationalization","enumerationPlugin","conditionPlugin","filePlugin","genderPlugin"],"sources":["../../src/plugins.ts"],"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 translationPlugin,\n} from '@intlayer/core/interpreter';\nimport type { MarkdownContent } from '@intlayer/core/markdown';\nimport { compile, getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type { HTMLContent, InsertionContent } 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 { reportExposure } from './analytics/exposureSink';\nimport { ContentSelectorWrapperComponent } from './editor/ContentSelector.component';\nimport { renderIntlayerNode } from './renderIntlayerNode';\n\nlet _markdownInstall: {\n htmlRuntime: any;\n useMarkdown: () => { renderMarkdown: (s: string, components?: any) => any };\n} | null = null;\nif (\n process.env.INTLAYER_NODE_TYPE_MARKDOWN !== 'false' ||\n process.env.INTLAYER_NODE_TYPE_HTML !== 'false'\n) {\n void import('./markdown/installIntlayerMarkdown').then((m) => {\n _markdownInstall = m as any;\n });\n}\n\n/** ---------------------------------------------\n * UTILS\n * --------------------------------------------- */\n\nconst createRuntimeWithOverides = (baseRuntime: any, overrides: any) => ({\n ...baseRuntime,\n createElement: (tag: string, props: any, ...children: any[]) => {\n const override = overrides?.[tag];\n\n if (override) {\n const newProps = { ...props, ...override };\n\n // Merge class attributes intelligently\n const originalClass = props?.class || props?.className;\n const overrideClass = override.class || override.className;\n\n if (originalClass && overrideClass) {\n newProps.class = `${originalClass} ${overrideClass}`;\n newProps.className = undefined;\n }\n\n return baseRuntime.createElement(tag, newProps, ...children);\n }\n\n return baseRuntime.createElement(tag, props, ...children);\n },\n});\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\nexport interface IntlayerNode<T, P = {}> {\n value: T;\n children?: any;\n additionalProps?: P;\n}\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const intlayerNodePlugins: Plugins = {\n id: 'intlayer-node-plugin',\n canHandle: (node) =>\n typeof node === 'bigint' ||\n typeof node === 'string' ||\n typeof node === 'number',\n transform: (_node, { children, ...rest }) => {\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: children,\n children: () => ({\n component:\n process.env.INTLAYER_EDITOR_ENABLED === 'false' || !editor.enabled\n ? children\n : ContentSelectorWrapperComponent,\n props: {\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n },\n children: children,\n }),\n });\n },\n};\n\n/**\n * MARKDOWN PLUGIN\n */\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<string, { metadata: DeepTransformContent<string> }>\n : never;\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: node,\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?: any) =>\n renderIntlayerNode({\n ...rest,\n value: node,\n children:\n process.env.INTLAYER_EDITOR_ENABLED === 'false' ||\n !editor.enabled\n ? () => {\n const { renderMarkdown } =\n _markdownInstall?.useMarkdown() ?? {\n renderMarkdown: () => node,\n };\n return renderMarkdown(node, components);\n }\n : () => ({\n component: ContentSelectorWrapperComponent,\n props: {\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n ...components,\n },\n children: () => {\n const { renderMarkdown } =\n _markdownInstall?.useMarkdown() ?? {\n renderMarkdown: () => node,\n };\n return renderMarkdown(node, components);\n },\n }),\n additionalProps: {\n metadata: metadataNodes,\n },\n });\n\n const createProxy = (element: any, components?: any) =>\n new Proxy(element, {\n get(target, prop, receiver) {\n if (prop === 'value') {\n return node;\n }\n if (prop === 'metadata') {\n return metadataNodes;\n }\n\n if (prop === 'toString') {\n return () => {\n const htmlRuntime = _markdownInstall?.htmlRuntime;\n if (!htmlRuntime || !compile) return node;\n const runtime = components\n ? createRuntimeWithOverides(htmlRuntime, components)\n : htmlRuntime;\n return compile(node, { runtime }) as string;\n };\n }\n\n if (prop === Symbol.toPrimitive) {\n return () => {\n const htmlRuntime = _markdownInstall?.htmlRuntime;\n if (!htmlRuntime || !compile) return node;\n const runtime = components\n ? createRuntimeWithOverides(htmlRuntime, components)\n : htmlRuntime;\n return compile(node, { runtime }) as string;\n };\n }\n\n if (prop === 'use') {\n return (newComponents?: any) => {\n const mergedComponents = {\n ...components,\n ...newComponents,\n };\n return createProxy(\n render(mergedComponents),\n mergedComponents\n );\n };\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n\n return createProxy(render() as any);\n },\n };\n\nexport type MarkdownCond<T, _S, _L extends LocalesValues> = 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?: Record<keyof U, any>) => any;\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.\n *\n * This ensures type safety:\n * - `html('<div>Hello <CustomComponent /></div>').use({ CustomComponent: ... })` - optional but typed\n */\nexport type HTMLPluginCond<T, _S, _L> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.HTML]: infer I;\n tags?: infer U;\n}\n ? IntlayerNode<\n I,\n {\n use: (components?: Record<keyof U, any>) => any;\n }\n >\n : never;\n\n/** HTML plugin. Replaces node with a function that takes components => IntlayerNode. */\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?: any) =>\n renderIntlayerNode({\n ...rest,\n value: html,\n children:\n process.env.INTLAYER_EDITOR_ENABLED === 'false' ||\n !editor.enabled\n ? html\n : () => ({\n component: ContentSelectorWrapperComponent,\n props: {\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n ...userComponents,\n },\n children: html,\n }),\n });\n\n const createProxy = (element: any, components?: any) =>\n new Proxy(element, {\n get(target, prop, receiver) {\n if (prop === 'value') {\n return html;\n }\n\n if (prop === 'toString') {\n return () => {\n if (\n !components ||\n (typeof components === 'object' &&\n Object.keys(components).length === 0)\n ) {\n return String(html);\n }\n const htmlRuntime = _markdownInstall?.htmlRuntime;\n if (!htmlRuntime || !compile) return String(html);\n const runtime = createRuntimeWithOverides(\n htmlRuntime,\n components\n );\n return compile(html, { runtime }) as string;\n };\n }\n\n if (prop === Symbol.toPrimitive) {\n return () => {\n if (\n !components ||\n (typeof components === 'object' &&\n Object.keys(components).length === 0)\n ) {\n return String(html);\n }\n const htmlRuntime = _markdownInstall?.htmlRuntime;\n if (!htmlRuntime || !compile) return String(html);\n const runtime = createRuntimeWithOverides(\n htmlRuntime,\n components\n );\n return compile(html, { runtime }) as string;\n };\n }\n\n if (prop === 'use') {\n // Return a properly typed function based on custom components\n return (userComponents?: any) => {\n const mergedComponents = {\n ...components,\n ...userComponents,\n };\n return createProxy(\n render(mergedComponents),\n mergedComponents\n );\n };\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as any;\n\n return createProxy(render() as any);\n },\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\n/**\n * Insertion conditional type.\n */\nexport type InsertionPluginCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer _I;\n}\n ? (args: Record<string, string | number>) => string\n : never;\n\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) => {\n const { plugins, ...rest } = props;\n\n // Return a function that performs the interpolation\n const render = (args: Record<string, string | number> = {}) => {\n let text = node[NodeTypes.INSERTION] as string;\n if (args) {\n Object.entries(args).forEach(([key, value]) => {\n text = text.replace(\n new RegExp(`{{\\\\s*${key}\\\\s*}}`, 'g'),\n String(value)\n );\n });\n }\n return text;\n };\n\n return renderIntlayerNode({\n ...rest,\n value: render as any,\n children: render,\n });\n },\n };\n\nexport interface IInterpreterPluginAngular<T, S, L extends LocalesValues> {\n angularIntlayerNode: IntlayerNodeCond<T>;\n angularMarkdown: MarkdownCond<T, S, L>;\n angularHtml: HTMLPluginCond<T, S, L>;\n angularInsertion: InsertionPluginCond<T>;\n}\n\n/**\n * Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.\n *\n * Otherwise the the `angular-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 angularIntlayerNode: true;\n angularMarkdown: true;\n angularHtml: true;\n angularInsertion: 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 Angular 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 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 filePlugin,\n genderPlugin,\n intlayerNodePlugins,\n markdownPlugin,\n htmlPlugin,\n insertionPlugin,\n ] as Plugins[];\n\n pluginsCache.set(cacheKey, plugins);\n\n return plugins;\n};\n"],"mappings":";;;;;;;;;;;;AA4BA,IAAI,mBAGO;AACX,IACE,QAAQ,IAAI,gCAAgC,WAC5C,QAAQ,IAAI,4BAA4B,SAExC,qCAAK,2CAA6C,MAAM,MAAM;CAC5D,mBAAmB;AACrB,CAAC;;;;AAOH,MAAM,6BAA6B,aAAkB,eAAoB;CACvE,GAAG;CACH,gBAAgB,KAAa,OAAY,GAAG,aAAoB;EAC9D,MAAM,WAAW,YAAY;EAE7B,IAAI,UAAU;GACZ,MAAM,WAAW;IAAE,GAAG;IAAO,GAAG;GAAS;GAGzC,MAAM,gBAAgB,OAAO,SAAS,OAAO;GAC7C,MAAM,gBAAgB,SAA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AAUD,4CAAqB,aAAa;EACzDE;+CACa,UAAUF,4CAAqB,aAAa;EACzDG;EACAC;EACA;EACA;EACA;EACA;CACF;CAEA,aAAa,IAAI,UAAU,OAAO;CAElC,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderIntlayerNode.cjs","names":[],"sources":["../../src/renderIntlayerNode.ts"],"sourcesContent":["import type { ResolvedEditor } from '@intlayer/types/module_augmentation';\n\nexport type IntlayerNode<T = string, AdditionalProps = {}> = ResolvedEditor<\n T,\n any\n> & {\n value: T;\n} & AdditionalProps &\n T;\n\ntype RenderIntlayerNodeProps<T> = {\n value: T;\n children: any;\n additionalProps?: { [key: string]: any };\n};\n\nexport const renderIntlayerNode = <\n T, // Broadened to support arrays, numbers, objects, etc.\n>({\n children,\n value,\n additionalProps = {},\n}: RenderIntlayerNodeProps<T>): IntlayerNode<T> => {\n // If children is null or undefined, return a simple object with the value\n if (children == null) {\n return new Proxy({} as any, {\n get(target, prop, receiver) {\n if (prop === 'value') return value;\n if (prop === Symbol.toPrimitive) return () => value ?? '';\n if (prop === 'toString') return () => String(value ?? '');\n if (prop === 'valueOf') return () => value;\n\n // Additional Props take precedence\n if (additionalProps && prop in additionalProps) {\n return additionalProps[prop as keyof typeof additionalProps];\n }\n\n // Delegate native methods/properties to the underlying value\n if (\n value !== null &&\n value !== undefined &&\n typeof prop === 'string' &&\n prop !== 'constructor' &&\n !(prop in target)\n ) {\n const valObj = Object(value); // Safely boxes primitives (e.g., 50 -> Number object)\n if (prop in valObj) {\n const valProp = valObj[prop];\n return typeof valProp === 'function'\n ? valProp.bind(value)\n : valProp;\n }\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as IntlayerNode<T>;\n }\n\n // Proxy target must be an object or function; wrap primitives\n const target =\n typeof children === 'object' || typeof children === 'function'\n ? children\n : ({} as any);\n\n // Return a Proxy that pretends to be the original content\n // but also has a .value getter and additional props.\n return new Proxy(target, {\n apply(target, thisArg, argumentsList) {\n if (typeof value === 'function') {\n return Reflect.apply(value as Function, thisArg, argumentsList);\n }\n return Reflect.apply(target as Function, thisArg, argumentsList);\n },\n get(target, prop, receiver) {\n if (prop === 'value') return value;\n if (prop === Symbol.toPrimitive) return () => value ?? '';\n if (prop === 'toString') return () => String(value ?? '');\n if (prop === 'valueOf') return () => value;\n\n // Additional Props take precedence\n if (additionalProps && prop in additionalProps) {\n return additionalProps[prop as keyof typeof additionalProps];\n }\n\n // Delegate native methods/properties to the underlying value\n if (\n value !== null &&\n value !== undefined &&\n typeof prop === 'string' &&\n prop !== 'constructor' &&\n !(prop in target)\n ) {\n const valObj = Object(value); // Safely boxes primitives (e.g., 50 -> Number object)\n if (prop in valObj) {\n const valProp = valObj[prop];\n return typeof valProp === 'function' ? valProp.bind(value) : valProp;\n }\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as IntlayerNode<T>;\n};\n"],"mappings":";;;AAgBA,MAAa,sBAEX,EACA,UACA,OACA,kBAAkB,
|
|
1
|
+
{"version":3,"file":"renderIntlayerNode.cjs","names":[],"sources":["../../src/renderIntlayerNode.ts"],"sourcesContent":["import type { ResolvedEditor } from '@intlayer/types/module_augmentation';\n\nexport type IntlayerNode<T = string, AdditionalProps = {}> = ResolvedEditor<\n T,\n any\n> & {\n value: T;\n} & AdditionalProps &\n T;\n\ntype RenderIntlayerNodeProps<T> = {\n value: T;\n children: any;\n additionalProps?: { [key: string]: any };\n};\n\nexport const renderIntlayerNode = <\n T, // Broadened to support arrays, numbers, objects, etc.\n>({\n children,\n value,\n additionalProps = {},\n}: RenderIntlayerNodeProps<T>): IntlayerNode<T> => {\n // If children is null or undefined, return a simple object with the value\n if (children == null) {\n return new Proxy({} as any, {\n get(target, prop, receiver) {\n if (prop === 'value') return value;\n if (prop === Symbol.toPrimitive) return () => value ?? '';\n if (prop === 'toString') return () => String(value ?? '');\n if (prop === 'valueOf') return () => value;\n\n // Additional Props take precedence\n if (additionalProps && prop in additionalProps) {\n return additionalProps[prop as keyof typeof additionalProps];\n }\n\n // Delegate native methods/properties to the underlying value\n if (\n value !== null &&\n value !== undefined &&\n typeof prop === 'string' &&\n prop !== 'constructor' &&\n !(prop in target)\n ) {\n const valObj = Object(value); // Safely boxes primitives (e.g., 50 -> Number object)\n if (prop in valObj) {\n const valProp = valObj[prop];\n return typeof valProp === 'function'\n ? valProp.bind(value)\n : valProp;\n }\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as IntlayerNode<T>;\n }\n\n // Proxy target must be an object or function; wrap primitives\n const target =\n typeof children === 'object' || typeof children === 'function'\n ? children\n : ({} as any);\n\n // Return a Proxy that pretends to be the original content\n // but also has a .value getter and additional props.\n return new Proxy(target, {\n apply(target, thisArg, argumentsList) {\n if (typeof value === 'function') {\n return Reflect.apply(value as Function, thisArg, argumentsList);\n }\n return Reflect.apply(target as Function, thisArg, argumentsList);\n },\n get(target, prop, receiver) {\n if (prop === 'value') return value;\n if (prop === Symbol.toPrimitive) return () => value ?? '';\n if (prop === 'toString') return () => String(value ?? '');\n if (prop === 'valueOf') return () => value;\n\n // Additional Props take precedence\n if (additionalProps && prop in additionalProps) {\n return additionalProps[prop as keyof typeof additionalProps];\n }\n\n // Delegate native methods/properties to the underlying value\n if (\n value !== null &&\n value !== undefined &&\n typeof prop === 'string' &&\n prop !== 'constructor' &&\n !(prop in target)\n ) {\n const valObj = Object(value); // Safely boxes primitives (e.g., 50 -> Number object)\n if (prop in valObj) {\n const valProp = valObj[prop];\n return typeof valProp === 'function' ? valProp.bind(value) : valProp;\n }\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as IntlayerNode<T>;\n};\n"],"mappings":";;;AAgBA,MAAa,sBAEX,EACA,UACA,OACA,kBAAkB,CAAC,QAC8B;CAEjD,IAAI,YAAY,MACd,OAAO,IAAI,MAAM,CAAC,GAAU,EAC1B,IAAI,QAAQ,MAAM,UAAU;EAC1B,IAAI,SAAS,SAAS,OAAO;EAC7B,IAAI,SAAS,OAAO,aAAa,aAAa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object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
2
|
let node_path = require("node:path");
|
|
4
3
|
let _intlayer_config_node = require("@intlayer/config/node");
|
|
5
4
|
let _intlayer_config_utils = require("@intlayer/config/utils");
|
|
5
|
+
let node_module = require("node:module");
|
|
6
6
|
let _intlayer_webpack = require("@intlayer/webpack");
|
|
7
7
|
let defu = require("defu");
|
|
8
8
|
|
|
9
9
|
//#region src/webpack/mergeConfig.ts
|
|
10
|
+
const _require = typeof require !== "undefined" ? require : (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
10
11
|
const mergeConfig = (baseConfig) => {
|
|
11
12
|
const intlayerConfig = (0, _intlayer_config_node.getConfiguration)();
|
|
12
13
|
return (0, defu.defu)({
|
|
@@ -30,10 +31,10 @@ const mergeConfig = (baseConfig) => {
|
|
|
30
31
|
type: "javascript/auto",
|
|
31
32
|
enforce: "pre",
|
|
32
33
|
use: {
|
|
33
|
-
loader: "babel-loader",
|
|
34
|
+
loader: _require.resolve("babel-loader"),
|
|
34
35
|
options: {
|
|
35
|
-
presets: [["@babel/preset-env", { modules: "commonjs" }]],
|
|
36
|
-
plugins: [["@babel/plugin-syntax-import-attributes", { deprecatedAssert: true }]]
|
|
36
|
+
presets: [[_require.resolve("@babel/preset-env"), { modules: "commonjs" }]],
|
|
37
|
+
plugins: [[_require.resolve("@babel/plugin-syntax-import-attributes"), { deprecatedAssert: true }]]
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
}] },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeConfig.cjs","names":["IntlayerPlugin"],"sources":["../../../src/webpack/mergeConfig.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { getAlias } from '@intlayer/config/utils';\nimport { IntlayerPlugin } from '@intlayer/webpack'; // adjust path if needed\nimport { defu } from 'defu';\n\nexport const mergeConfig = (\n baseConfig: import('webpack').Configuration\n): import('webpack').Configuration => {\n const intlayerConfig = getConfiguration();\n\n const config = {\n resolve: {\n alias: getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => resolve(value), // get absolute path\n }),\n },\n externals: {\n esbuild: 'esbuild',\n module: 'module',\n fs: 'fs',\n chokidar: 'chokidar',\n fsevents: 'fsevents',\n },\n module: {\n rules: [\n {\n test: /\\.node$/,\n loader: 'node-loader',\n },\n\n // Fix `import _48DQ2FD8DPGT8SPgqAmt from '../dictionary/app.json' with { type: 'json' };` syntax\n {\n test: /\\.mjs$/,\n include: [/[\\\\/]\\.intlayer[\\\\/]/],\n type: 'javascript/auto',\n enforce: 'pre',\n use: {\n loader: 'babel-loader',\n options: {\n presets: [['@babel/preset-env'
|
|
1
|
+
{"version":3,"file":"mergeConfig.cjs","names":["IntlayerPlugin"],"sources":["../../../src/webpack/mergeConfig.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { resolve } from 'node:path';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { getAlias } from '@intlayer/config/utils';\nimport { IntlayerPlugin } from '@intlayer/webpack'; // adjust path if needed\nimport { defu } from 'defu';\n\nconst _require =\n typeof require !== 'undefined' ? require : createRequire(import.meta.url);\nexport const mergeConfig = (\n baseConfig: import('webpack').Configuration\n): import('webpack').Configuration => {\n const intlayerConfig = getConfiguration();\n\n const config = {\n resolve: {\n alias: getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => resolve(value), // get absolute path\n }),\n },\n externals: {\n esbuild: 'esbuild',\n module: 'module',\n fs: 'fs',\n chokidar: 'chokidar',\n fsevents: 'fsevents',\n },\n module: {\n rules: [\n {\n test: /\\.node$/,\n loader: 'node-loader',\n },\n\n // Fix `import _48DQ2FD8DPGT8SPgqAmt from '../dictionary/app.json' with { type: 'json' };` syntax\n {\n test: /\\.mjs$/,\n include: [/[\\\\/]\\.intlayer[\\\\/]/],\n type: 'javascript/auto',\n enforce: 'pre',\n use: {\n loader: _require.resolve('babel-loader'),\n options: {\n presets: [\n [\n _require.resolve('@babel/preset-env'),\n { modules: 'commonjs' },\n ],\n ],\n plugins: [\n [\n _require.resolve('@babel/plugin-syntax-import-attributes'),\n { deprecatedAssert: true },\n ],\n ],\n },\n },\n },\n ],\n },\n plugins: [new IntlayerPlugin(intlayerConfig)],\n };\n\n return defu(config, baseConfig) as import('webpack').Configuration;\n};\n"],"mappings":";;;;;;;;;AAOA,MAAM,WACJ,OAAO,YAAY,cAAc,sFAAuC;AAC1E,MAAa,eACX,eACoC;CACpC,MAAM,6DAAkC;CAoDxC,sBAAY;EAjDV,SAAS,EACP,4CAAgB;GACd,eAAe;GACf,YAAY,iCAA0B,KAAK;EAC7C,CAAC,EACH;EACA,WAAW;GACT,SAAS;GACT,QAAQ;GACR,IAAI;GACJ,UAAU;GACV,UAAU;EACZ;EACA,QAAQ,EACN,OAAO,CACL;GACE,MAAM;GACN,QAAQ;EACV,GAGA;GACE,MAAM;GACN,SAAS,CAAC,sBAAsB;GAChC,MAAM;GACN,SAAS;GACT,KAAK;IACH,QAAQ,SAAS,QAAQ,cAAc;IACvC,SAAS;KACP,SAAS,CACP,CACE,SAAS,QAAQ,mBAAmB,GACpC,EAAE,SAAS,WAAW,CACxB,CACF;KACA,SAAS,CACP,CACE,SAAS,QAAQ,wCAAwC,GACzD,EAAE,kBAAkB,KAAK,CAC3B,CACF;IACF;GACF;EACF,CACF,EACF;EACA,SAAS,CAAC,IAAIA,iCAAe,cAAc,CAAC;CAG7B,GAAG,UAAU;AAChC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import __decorateMetadata from "../_virtual/_@oxc-project_runtime@0.140.0/helpers/esm/decorateMetadata.mjs";
|
|
2
|
+
import __decorate from "../_virtual/_@oxc-project_runtime@0.140.0/helpers/esm/decorate.mjs";
|
|
3
3
|
import { ChangeDetectorRef, Component, ElementRef, Input, ViewContainerRef, inject } from "@angular/core";
|
|
4
4
|
|
|
5
5
|
//#region src/UI/IntlayerNode.component.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerNode.component.mjs","names":[],"sources":["../../../src/UI/IntlayerNode.component.ts"],"sourcesContent":["import {\n ChangeDetectorRef,\n Component,\n ElementRef,\n Input,\n inject,\n type OnChanges,\n type SimpleChanges,\n type Type,\n ViewContainerRef,\n} from '@angular/core';\n\n/**\n * A transparent host element that renders Intlayer content nodes.\n *\n * `display: contents` makes the `<intlayer-node>` element invisible in the\n * layout — its children appear as if they were direct children of the parent,\n * so placing this component inside `<h1>`, `<p>`, etc. does not break the\n * document structure.\n *\n * ### Usage\n * ```html\n * <h1><intlayer-node [node]=\"content().title\"></intlayer-node></h1>\n * ```\n */\n@Component({\n selector: 'intlayer-node',\n standalone: true,\n // The ng-content slot is the anchor point for ViewContainerRef.\n // Wrapping text renders directly inside this host thanks to display:contents.\n template: `<ng-container #anchor></ng-container>`,\n // display:contents collapses the host box so it is layout-transparent.\n styles: [`:host { display: contents; }`],\n})\nexport class IntlayerNodeComponent implements OnChanges {\n @Input() node: any;\n\n private vcr = inject(ViewContainerRef);\n private elRef = inject<ElementRef<HTMLElement>>(ElementRef);\n private cdr = inject(ChangeDetectorRef);\n\n ngOnChanges(changes: SimpleChanges): void {\n if (changes['node']) {\n this.render();\n }\n }\n\n private render() {\n // Clear previously created views / text nodes\n this.vcr.clear();\n const host = this.elRef.nativeElement;\n // Remove any raw text nodes we injected directly on previous renders\n host.childNodes.forEach((n) => {\n if (n.nodeType === Node.TEXT_NODE) n.parentNode?.removeChild(n);\n });\n\n if (!this.node) return;\n\n // The node returned by the Angular plugin is a Proxy whose `.children`\n // property is a function returning component info (editor on) or the raw\n // value (editor off).\n const nodeInfo =\n typeof this.node?.children === 'function'\n ? this.node.children()\n : this.node;\n\n if (nodeInfo?.component && typeof nodeInfo.component !== 'string') {\n // ── Editor enabled path: create the ContentSelectorWrapper component ──\n const componentRef = this.vcr.createComponent(\n nodeInfo.component as Type<any>\n );\n\n if (nodeInfo.props) {\n for (const [key, value] of Object.entries(nodeInfo.props)) {\n (componentRef.instance as any)[key] = value;\n }\n }\n\n if (nodeInfo.children) {\n const content = nodeInfo.children;\n if (typeof content === 'string' || typeof content === 'number') {\n componentRef.location.nativeElement.appendChild(\n document.createTextNode(String(content))\n );\n }\n }\n\n this.cdr.markForCheck();\n } else {\n // ── Editor disabled path: render plain text inside the host ──────────\n const text =\n this.node?.value ?? this.node?.toString?.() ?? String(this.node);\n // Append a text node directly inside the host element.\n // Because the host has `display: contents`, this text is layout-wise a\n // direct child of the surrounding element (e.g. <h1>).\n host.appendChild(document.createTextNode(text));\n }\n }\n}\n"],"mappings":";;;;;AAkCO,
|
|
1
|
+
{"version":3,"file":"IntlayerNode.component.mjs","names":[],"sources":["../../../src/UI/IntlayerNode.component.ts"],"sourcesContent":["import {\n ChangeDetectorRef,\n Component,\n ElementRef,\n Input,\n inject,\n type OnChanges,\n type SimpleChanges,\n type Type,\n ViewContainerRef,\n} from '@angular/core';\n\n/**\n * A transparent host element that renders Intlayer content nodes.\n *\n * `display: contents` makes the `<intlayer-node>` element invisible in the\n * layout — its children appear as if they were direct children of the parent,\n * so placing this component inside `<h1>`, `<p>`, etc. does not break the\n * document structure.\n *\n * ### Usage\n * ```html\n * <h1><intlayer-node [node]=\"content().title\"></intlayer-node></h1>\n * ```\n */\n@Component({\n selector: 'intlayer-node',\n standalone: true,\n // The ng-content slot is the anchor point for ViewContainerRef.\n // Wrapping text renders directly inside this host thanks to display:contents.\n template: `<ng-container #anchor></ng-container>`,\n // display:contents collapses the host box so it is layout-transparent.\n styles: [`:host { display: contents; }`],\n})\nexport class IntlayerNodeComponent implements OnChanges {\n @Input() node: any;\n\n private vcr = inject(ViewContainerRef);\n private elRef = inject<ElementRef<HTMLElement>>(ElementRef);\n private cdr = inject(ChangeDetectorRef);\n\n ngOnChanges(changes: SimpleChanges): void {\n if (changes['node']) {\n this.render();\n }\n }\n\n private render() {\n // Clear previously created views / text nodes\n this.vcr.clear();\n const host = this.elRef.nativeElement;\n // Remove any raw text nodes we injected directly on previous renders\n host.childNodes.forEach((n) => {\n if (n.nodeType === Node.TEXT_NODE) n.parentNode?.removeChild(n);\n });\n\n if (!this.node) return;\n\n // The node returned by the Angular plugin is a Proxy whose `.children`\n // property is a function returning component info (editor on) or the raw\n // value (editor off).\n const nodeInfo =\n typeof this.node?.children === 'function'\n ? this.node.children()\n : this.node;\n\n if (nodeInfo?.component && typeof nodeInfo.component !== 'string') {\n // ── Editor enabled path: create the ContentSelectorWrapper component ──\n const componentRef = this.vcr.createComponent(\n nodeInfo.component as Type<any>\n );\n\n if (nodeInfo.props) {\n for (const [key, value] of Object.entries(nodeInfo.props)) {\n (componentRef.instance as any)[key] = value;\n }\n }\n\n if (nodeInfo.children) {\n const content = nodeInfo.children;\n if (typeof content === 'string' || typeof content === 'number') {\n componentRef.location.nativeElement.appendChild(\n document.createTextNode(String(content))\n );\n }\n }\n\n this.cdr.markForCheck();\n } else {\n // ── Editor disabled path: render plain text inside the host ──────────\n const text =\n this.node?.value ?? this.node?.toString?.() ?? String(this.node);\n // Append a text node directly inside the host element.\n // Because the host has `display: contents`, this text is layout-wise a\n // direct child of the surrounding element (e.g. <h1>).\n host.appendChild(document.createTextNode(text));\n }\n }\n}\n"],"mappings":";;;;;AAkCO,IAAM,wBAAN,MAAM,sBAA2C;CACtD,AAAS;CAET,AAAQ,MAAM,OAAO,gBAAgB;CACrC,AAAQ,QAAQ,OAAgC,UAAU;CAC1D,AAAQ,MAAM,OAAO,iBAAiB;CAEtC,YAAY,SAA8B;EACxC,IAAI,QAAQ,SACV,KAAK,OAAO;CAEhB;CAEA,AAAQ,SAAS;EAEf,KAAK,IAAI,MAAM;EACf,MAAM,OAAO,KAAK,MAAM;EAExB,KAAK,WAAW,SAAS,MAAM;GAC7B,IAAI,EAAE,aAAa,KAAK,WAAW,EAAE,YAAY,YAAY,CAAC;EAChE,CAAC;EAED,IAAI,CAAC,KAAK,MAAM;EAKhB,MAAM,WACJ,OAAO,KAAK,MAAM,aAAa,aAC3B,KAAK,KAAK,SAAS,IACnB,KAAK;EAEX,IAAI,UAAU,aAAa,OAAO,SAAS,cAAc,UAAU;GAEjE,MAAM,eAAe,KAAK,IAAI,gBAC5B,SAAS,SACX;GAEA,IAAI,SAAS,OACX,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,SAAS,KAAK,GACtD,AAAC,aAAa,SAAiB,OAAO;GAI1C,IAAI,SAAS,UAAU;IACrB,MAAM,UAAU,SAAS;IACzB,IAAI,OAAO,YAAY,YAAY,OAAO,YAAY,UACpD,aAAa,SAAS,cAAc,YAClC,SAAS,eAAe,OAAO,OAAO,CAAC,CACzC;GAEJ;GAEA,KAAK,IAAI,aAAa;EACxB,OAAO;GAEL,MAAM,OACJ,KAAK,MAAM,SAAS,KAAK,MAAM,WAAW,KAAK,OAAO,KAAK,IAAI;GAIjE,KAAK,YAAY,SAAS,eAAe,IAAI,CAAC;EAChD;CACF;AACF;YA/DG,MAAM;oCAVR,UAAU;CACT,UAAU;CACV,YAAY;CAGZ,UAAU;CAEV,QAAQ,CAAC,8BAA8B;AACzC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region \0@oxc-project+runtime@0.
|
|
1
|
+
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
|
|
2
2
|
function __decorate(decorators, target, key, desc) {
|
|
3
3
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
4
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -7,4 +7,4 @@ function __decorate(decorators, target, key, desc) {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
//#endregion
|
|
10
|
-
export { __decorate };
|
|
10
|
+
export { __decorate as default };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
//#region \0@oxc-project+runtime@0.127.0/helpers/decorateMetadata.js
|
|
1
|
+
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateMetadata.js
|
|
3
2
|
function __decorateMetadata(k, v) {
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
5
4
|
}
|
|
6
5
|
|
|
7
6
|
//#endregion
|
|
8
|
-
|
|
7
|
+
export { __decorateMetadata as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
|
|
3
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
4
|
+
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { __require };
|
|
@@ -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.ts` never statically imports\n * `@intlayer/analytics` — the package stays optional and tree-shakeable.\n */\nexport type ExposureInput = {\n dictionaryKey: string;\n keyPath: KeyPath[];\n locale?: string;\n nodeType?: string;\n};\n\n/** Consumer of exposure reports, installed by `useAnalytics` after init. */\nexport type ExposureSink = (input: ExposureInput) => void;\n\nlet sink: ExposureSink | null = null;\n\n/**\n * Installs (or clears) the exposure sink. `useAnalytics` sets this once the\n * analytics client has loaded, and clears it on unmount.\n *\n * @param next - The sink to install, or `null` to clear.\n */\nexport const setExposureSink = (next: ExposureSink | null): void => {\n sink = next;\n};\n\n/**\n * Forwards a content exposure to the installed sink. A cheap null-check when\n * analytics is not running, so it is safe to call from every node resolution.\n *\n * @param input - The node metadata to report.\n */\nexport const reportExposure = (input: ExposureInput): void => {\n sink?.(input);\n};\n"],"mappings":";AAiBA,IAAI,OAA4B;;;;;;;AAQhC,MAAa,mBAAmB,SAAoC;CAClE,OAAO;AACT;;;;;;;AAQA,MAAa,kBAAkB,UAA+B;CAC5D,OAAO,KAAK;AACd"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { setExposureSink } from "./exposureSink.mjs";
|
|
2
|
+
import { INTLAYER_TOKEN } from "../client/intlayerToken.mjs";
|
|
3
|
+
import { DestroyRef, Injector, effect, inject, provideAppInitializer, runInInjectionContext, signal } from "@angular/core";
|
|
4
|
+
import { isEnabled } from "@intlayer/analytics/isEnabled";
|
|
5
|
+
|
|
6
|
+
//#region src/analytics/useAnalytics.ts
|
|
7
|
+
/**
|
|
8
|
+
* Initializes the Intlayer analytics client singleton when analytics is
|
|
9
|
+
* enabled (mirrors {@link useEditor}). Records an initial page view, keeps the
|
|
10
|
+
* client aware of the current locale, and wires node-level content exposures.
|
|
11
|
+
*
|
|
12
|
+
* Must be called inside an Angular injection context (e.g. a component
|
|
13
|
+
* constructor, `provideAppInitializer`, or `runInInjectionContext`).
|
|
14
|
+
*
|
|
15
|
+
* @param client - The IntlayerProvider instance to sync locale from.
|
|
16
|
+
* When omitted the function injects `INTLAYER_TOKEN` from the DI tree,
|
|
17
|
+
* so it still works when called directly from a component.
|
|
18
|
+
*/
|
|
19
|
+
const useAnalytics = (client) => {
|
|
20
|
+
if (process.env.INTLAYER_ANALYTICS_ENABLED === "false" || !isEnabled) return;
|
|
21
|
+
const destroyRef = inject(DestroyRef, { optional: true });
|
|
22
|
+
const injector = inject(Injector);
|
|
23
|
+
const resolvedClient = client ?? inject(INTLAYER_TOKEN, { optional: true });
|
|
24
|
+
const analyticsClient = signal(null);
|
|
25
|
+
let stopped = false;
|
|
26
|
+
let initialized = false;
|
|
27
|
+
import("@intlayer/analytics").then(({ initAnalyticsClient, buildContentExposure }) => {
|
|
28
|
+
if (stopped) return;
|
|
29
|
+
const clientInstance = initAnalyticsClient();
|
|
30
|
+
initialized = true;
|
|
31
|
+
const currentLocale = resolvedClient?.locale();
|
|
32
|
+
if (currentLocale) clientInstance.setLocale(currentLocale);
|
|
33
|
+
clientInstance.trackPageView({ reason: "initial" });
|
|
34
|
+
setExposureSink((input) => clientInstance.trackContentExposure(buildContentExposure(input)));
|
|
35
|
+
analyticsClient.set(clientInstance);
|
|
36
|
+
}).catch(() => {});
|
|
37
|
+
let previousLocale;
|
|
38
|
+
const effectRef = runInInjectionContext(injector, () => effect(() => {
|
|
39
|
+
const clientInstance = analyticsClient();
|
|
40
|
+
const locale = resolvedClient?.locale();
|
|
41
|
+
if (!clientInstance || !locale) return;
|
|
42
|
+
if (previousLocale === void 0) {
|
|
43
|
+
previousLocale = locale;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (previousLocale === locale) return;
|
|
47
|
+
previousLocale = locale;
|
|
48
|
+
clientInstance.setLocale(locale);
|
|
49
|
+
clientInstance.trackPageView({ reason: "locale_change" });
|
|
50
|
+
}));
|
|
51
|
+
destroyRef?.onDestroy(() => {
|
|
52
|
+
stopped = true;
|
|
53
|
+
effectRef.destroy();
|
|
54
|
+
analyticsClient.set(null);
|
|
55
|
+
setExposureSink(null);
|
|
56
|
+
import("@intlayer/analytics").then(({ stopAnalyticsClient }) => {
|
|
57
|
+
if (initialized) stopAnalyticsClient();
|
|
58
|
+
}).catch(() => {});
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Angular provider that wires `useAnalytics` into the application
|
|
63
|
+
* initialisation phase via `provideAppInitializer`.
|
|
64
|
+
*
|
|
65
|
+
* `provideIntlayer()` already calls this internally, so you only need this
|
|
66
|
+
* function when you want to manage providers individually.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* // app.config.ts
|
|
71
|
+
* import { provideIntlayer, provideIntlayerAnalytics } from 'angular-intlayer';
|
|
72
|
+
*
|
|
73
|
+
* export const appConfig: ApplicationConfig = {
|
|
74
|
+
* providers: [provideIntlayer(), provideIntlayerAnalytics()],
|
|
75
|
+
* };
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
const provideIntlayerAnalytics = (client) => provideAppInitializer(() => useAnalytics(client));
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
export { provideIntlayerAnalytics, useAnalytics };
|
|
82
|
+
//# sourceMappingURL=useAnalytics.mjs.map
|