angular-intlayer 8.4.10 → 8.5.1
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/@intlayer/editor/src/isEnabled.cjs +10 -0
- package/dist/cjs/@intlayer/editor/src/isEnabled.cjs.map +1 -0
- package/dist/cjs/UI/IntlayerNode.component.cjs +53 -0
- package/dist/cjs/UI/IntlayerNode.component.cjs.map +1 -0
- package/dist/cjs/UI/index.cjs +9 -0
- package/dist/cjs/client/index.cjs +4 -10
- package/dist/cjs/client/installIntlayer.cjs +19 -48
- package/dist/cjs/client/installIntlayer.cjs.map +1 -1
- package/dist/cjs/client/intlayerToken.cjs +36 -0
- package/dist/cjs/client/intlayerToken.cjs.map +1 -0
- package/dist/cjs/client/useDictionary.cjs +2 -2
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +2 -2
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +2 -2
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +2 -2
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +2 -2
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/editor/EditorProvider.component.cjs +27 -0
- package/dist/cjs/editor/EditorProvider.component.cjs.map +1 -0
- package/dist/cjs/editor/index.cjs +19 -0
- package/dist/cjs/editor/useEditor.cjs +47 -12
- package/dist/cjs/editor/useEditor.cjs.map +1 -1
- package/dist/cjs/format/index.cjs +20 -0
- package/dist/cjs/format/useCompact.cjs +18 -0
- package/dist/cjs/format/useCompact.cjs.map +1 -0
- package/dist/cjs/format/useCurrency.cjs +18 -0
- package/dist/cjs/format/useCurrency.cjs.map +1 -0
- package/dist/cjs/format/useDate.cjs +28 -0
- package/dist/cjs/format/useDate.cjs.map +1 -0
- package/dist/cjs/format/useIntl.cjs +20 -0
- package/dist/cjs/format/useIntl.cjs.map +1 -0
- package/dist/cjs/format/useList.cjs +18 -0
- package/dist/cjs/format/useList.cjs.map +1 -0
- package/dist/cjs/format/useNumber.cjs +21 -0
- package/dist/cjs/format/useNumber.cjs.map +1 -0
- package/dist/cjs/format/usePercentage.cjs +18 -0
- package/dist/cjs/format/usePercentage.cjs.map +1 -0
- package/dist/cjs/format/useRelativeTime.cjs +18 -0
- package/dist/cjs/format/useRelativeTime.cjs.map +1 -0
- package/dist/cjs/format/useUnit.cjs +18 -0
- package/dist/cjs/format/useUnit.cjs.map +1 -0
- package/dist/cjs/html/index.cjs +12 -0
- package/dist/cjs/html/installIntlayerHTML.cjs +47 -0
- package/dist/cjs/html/installIntlayerHTML.cjs.map +1 -0
- package/dist/cjs/index.cjs +8 -18
- package/dist/cjs/markdown/index.cjs +0 -1
- package/dist/cjs/markdown/installIntlayerMarkdown.cjs +1 -1
- package/dist/cjs/markdown/installIntlayerMarkdown.cjs.map +1 -1
- package/dist/cjs/plugins.cjs +14 -22
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/renderIntlayerNode.cjs +2 -1
- package/dist/cjs/renderIntlayerNode.cjs.map +1 -1
- package/dist/esm/@intlayer/editor/src/isEnabled.mjs +8 -0
- package/dist/esm/@intlayer/editor/src/isEnabled.mjs.map +1 -0
- package/dist/esm/UI/IntlayerNode.component.mjs +46 -0
- package/dist/esm/UI/IntlayerNode.component.mjs.map +1 -0
- package/dist/esm/UI/index.mjs +3 -0
- package/dist/esm/client/index.mjs +3 -3
- package/dist/esm/client/installIntlayer.mjs +15 -37
- package/dist/esm/client/installIntlayer.mjs.map +1 -1
- package/dist/esm/client/intlayerToken.mjs +31 -0
- package/dist/esm/client/intlayerToken.mjs.map +1 -0
- package/dist/esm/client/useDictionary.mjs +1 -1
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +1 -1
- 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/useLocale.mjs +1 -1
- package/dist/esm/editor/EditorProvider.component.mjs +20 -0
- package/dist/esm/editor/EditorProvider.component.mjs.map +1 -0
- package/dist/esm/editor/index.mjs +5 -0
- package/dist/esm/editor/useEditor.mjs +48 -14
- package/dist/esm/editor/useEditor.mjs.map +1 -1
- package/dist/esm/format/index.mjs +11 -0
- package/dist/esm/format/useCompact.mjs +16 -0
- package/dist/esm/format/useCompact.mjs.map +1 -0
- package/dist/esm/format/useCurrency.mjs +16 -0
- package/dist/esm/format/useCurrency.mjs.map +1 -0
- package/dist/esm/format/useDate.mjs +26 -0
- package/dist/esm/format/useDate.mjs.map +1 -0
- package/dist/esm/format/useIntl.mjs +18 -0
- package/dist/esm/format/useIntl.mjs.map +1 -0
- package/dist/esm/format/useList.mjs +16 -0
- package/dist/esm/format/useList.mjs.map +1 -0
- package/dist/esm/format/useNumber.mjs +19 -0
- package/dist/esm/format/useNumber.mjs.map +1 -0
- package/dist/esm/format/usePercentage.mjs +16 -0
- package/dist/esm/format/usePercentage.mjs.map +1 -0
- package/dist/esm/format/useRelativeTime.mjs +16 -0
- package/dist/esm/format/useRelativeTime.mjs.map +1 -0
- package/dist/esm/format/useUnit.mjs +16 -0
- package/dist/esm/format/useUnit.mjs.map +1 -0
- package/dist/esm/html/index.mjs +3 -0
- package/dist/esm/html/installIntlayerHTML.mjs +37 -0
- package/dist/esm/html/installIntlayerHTML.mjs.map +1 -0
- package/dist/esm/index.mjs +4 -4
- package/dist/esm/markdown/index.mjs +2 -2
- package/dist/esm/markdown/installIntlayerMarkdown.mjs +1 -1
- package/dist/esm/markdown/installIntlayerMarkdown.mjs.map +1 -1
- package/dist/esm/plugins.mjs +14 -22
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/renderIntlayerNode.mjs +2 -1
- package/dist/esm/renderIntlayerNode.mjs.map +1 -1
- package/dist/types/UI/IntlayerNode.component.d.ts +27 -0
- package/dist/types/UI/IntlayerNode.component.d.ts.map +1 -0
- package/dist/types/UI/index.d.ts +2 -0
- package/dist/types/client/index.d.ts +3 -3
- package/dist/types/client/installIntlayer.d.ts +10 -21
- package/dist/types/client/installIntlayer.d.ts.map +1 -1
- package/dist/types/client/intlayerToken.d.ts +19 -0
- package/dist/types/client/intlayerToken.d.ts.map +1 -0
- package/dist/types/client/useDictionaryAsync.d.ts.map +1 -1
- package/dist/types/client/useDictionaryDynamic.d.ts +2 -2
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/client/useIntlayer.d.ts.map +1 -1
- package/dist/types/client/useLocale.d.ts +3 -3
- package/dist/types/client/useLocaleStorage.d.ts +5 -5
- package/dist/types/client/useLocaleStorage.d.ts.map +1 -1
- package/dist/types/editor/EditorProvider.component.d.ts +33 -0
- package/dist/types/editor/EditorProvider.component.d.ts.map +1 -0
- package/dist/types/editor/index.d.ts +4 -0
- package/dist/types/editor/useEditor.d.ts +35 -2
- package/dist/types/editor/useEditor.d.ts.map +1 -1
- package/dist/types/format/index.d.ts +10 -0
- package/dist/types/format/useCompact.d.ts +10 -0
- package/dist/types/format/useCompact.d.ts.map +1 -0
- package/dist/types/format/useCurrency.d.ts +10 -0
- package/dist/types/format/useCurrency.d.ts.map +1 -0
- package/dist/types/format/useDate.d.ts +14 -0
- package/dist/types/format/useDate.d.ts.map +1 -0
- package/dist/types/format/useIntl.d.ts +12 -0
- package/dist/types/format/useIntl.d.ts.map +1 -0
- package/dist/types/format/useList.d.ts +14 -0
- package/dist/types/format/useList.d.ts.map +1 -0
- package/dist/types/format/useNumber.d.ts +13 -0
- package/dist/types/format/useNumber.d.ts.map +1 -0
- package/dist/types/format/usePercentage.d.ts +10 -0
- package/dist/types/format/usePercentage.d.ts.map +1 -0
- package/dist/types/format/useRelativeTime.d.ts +11 -0
- package/dist/types/format/useRelativeTime.d.ts.map +1 -0
- package/dist/types/format/useUnit.d.ts +10 -0
- package/dist/types/format/useUnit.d.ts.map +1 -0
- package/dist/types/html/index.d.ts +2 -0
- package/dist/types/html/installIntlayerHTML.d.ts +34 -0
- package/dist/types/html/installIntlayerHTML.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -4
- package/dist/types/intlayer/dist/types/index.d.ts +4 -0
- package/dist/types/markdown/index.d.ts +2 -2
- package/dist/types/markdown/installIntlayerMarkdown.d.ts +3 -3
- package/dist/types/markdown/installIntlayerMarkdown.d.ts.map +1 -1
- package/dist/types/plugins.d.ts.map +1 -1
- package/package.json +32 -8
- package/dist/cjs/client/useIntl.cjs +0 -41
- package/dist/cjs/client/useIntl.cjs.map +0 -1
- package/dist/esm/client/useIntl.mjs +0 -39
- package/dist/esm/client/useIntl.mjs.map +0 -1
- package/dist/types/client/useIntl.d.ts +0 -33
- package/dist/types/client/useIntl.d.ts.map +0 -1
package/dist/cjs/plugins.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.cjs","names":["renderIntlayerNode","configuration","ContentSelectorWrapperComponent","NodeTypes","enumerationPlugin","conditionPlugin","filePlugin","genderPlugin"],"sources":["../../src/plugins.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n nestedPlugin,\n type Plugins,\n translationPlugin,\n} from '@intlayer/core/interpreter';\nimport type { MarkdownContent } 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\n// Lazy pre-load heavy modules — creates separate code-split chunks\nlet _getMarkdownMetadata: ((s: string) => any) | null = null;\nlet _compile: ((s: string, opts: any) => any) | null = null;\nvoid import('@intlayer/core/markdown').then((m) => {\n _getMarkdownMetadata = m.getMarkdownMetadata;\n _compile = m.compile;\n});\n\nlet _markdownInstall: {\n htmlRuntime: any;\n useMarkdown: () => { renderMarkdown: (s: string, components?: any) => any };\n} | null = null;\nvoid import('./markdown/installIntlayerMarkdown').then((m) => {\n _markdownInstall = m as any;\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: configuration?.editor.enabled\n ? ContentSelectorWrapperComponent\n : children,\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 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: configuration?.editor.enabled\n ? () => ({\n component: ContentSelectorWrapperComponent,\n props: {\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n ...components,\n },\n children: () => {\n const { renderMarkdown } = _markdownInstall?.useMarkdown() ?? {\n renderMarkdown: () => node,\n };\n return renderMarkdown(node, components);\n },\n })\n : () => {\n const { renderMarkdown } = _markdownInstall?.useMarkdown() ?? {\n renderMarkdown: () => node,\n };\n return renderMarkdown(node, components);\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 = { ...components, ...newComponents };\n return createProxy(render(mergedComponents), mergedComponents);\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 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 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: configuration?.editor.enabled\n ? () => ({\n component: ContentSelectorWrapperComponent,\n props: {\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n ...userComponents,\n },\n children: html,\n })\n : html,\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 = { ...components, ...userComponents };\n return createProxy(render(mergedComponents), mergedComponents);\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 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\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 translationPlugin(\n locale ?? configuration.internationalization.defaultLocale,\n fallback ? configuration.internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n conditionPlugin,\n nestedPlugin(locale ?? configuration.internationalization.defaultLocale),\n filePlugin,\n genderPlugin,\n intlayerNodePlugins,\n markdownPlugin,\n htmlPlugin,\n insertionPlugin,\n];\n"],"mappings":";;;;;;;;;;;AAyBA,IAAI,uBAAoD;AACxD,IAAI,WAAmD;AAClD,OAAO,2BAA2B,MAAM,MAAM;AACjD,wBAAuB,EAAE;AACzB,YAAW,EAAE;EACb;AAEF,IAAI,mBAGO;qCACN,2CAA6C,MAAM,MAAM;AAC5D,oBAAmB;EACnB;;;;AAMF,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,WAAWC,gCAAe,OAAO,UAC7BC,2EACA;GACJ,OAAO;IACL,eAAe,KAAK;IACpB,SAAS,KAAK;IACf;GACS;GACX;EACF,CAAC;CACL;;AAWD,MAAa,uBAAgC;CAC3C,IAAI;CACJ,YAAY,SAAS,OAAO,SAAS;CACrC,YAAY,MAAc,OAAO,sBAAsB;EACrD,MAAM,EACJ,SACA,GAAG,SACD;EAoB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AAc,qBAAqB,eAC7C,WAAWA,+BAAc,qBAAqB,gBAAgB,OAC/D;CACDG;CACAC;8CACa,UAAUJ,+BAAc,qBAAqB,cAAc;CACxEK;CACAC;CACA;CACA;CACA;CACA;CACD"}
|
|
1
|
+
{"version":3,"file":"plugins.cjs","names":["renderIntlayerNode","isEnabled","ContentSelectorWrapperComponent","compile","NodeTypes","configuration","enumerationPlugin","conditionPlugin","filePlugin","genderPlugin"],"sources":["../../src/plugins.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n nestedPlugin,\n type Plugins,\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 { isEnabled } from '../../@intlayer/editor/src/isEnabled';\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;\nvoid import('./markdown/installIntlayerMarkdown').then((m) => {\n _markdownInstall = m as any;\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: isEnabled ? ContentSelectorWrapperComponent : children,\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 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: isEnabled\n ? () => ({\n component: ContentSelectorWrapperComponent,\n props: {\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n ...components,\n },\n children: () => {\n const { renderMarkdown } = _markdownInstall?.useMarkdown() ?? {\n renderMarkdown: () => node,\n };\n return renderMarkdown(node, components);\n },\n })\n : () => {\n const { renderMarkdown } = _markdownInstall?.useMarkdown() ?? {\n renderMarkdown: () => node,\n };\n return renderMarkdown(node, components);\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 = { ...components, ...newComponents };\n return createProxy(render(mergedComponents), mergedComponents);\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 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 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: isEnabled\n ? () => ({\n component: ContentSelectorWrapperComponent,\n props: {\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n ...userComponents,\n },\n children: html,\n })\n : html,\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 = { ...components, ...userComponents };\n return createProxy(render(mergedComponents), mergedComponents);\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 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\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 translationPlugin(\n locale ?? configuration.internationalization.defaultLocale,\n fallback ? configuration.internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n conditionPlugin,\n nestedPlugin(locale ?? configuration.internationalization.defaultLocale),\n filePlugin,\n genderPlugin,\n intlayerNodePlugins,\n markdownPlugin,\n htmlPlugin,\n insertionPlugin,\n];\n"],"mappings":";;;;;;;;;;;;;AA0BA,IAAI,mBAGO;qCACN,2CAA6C,MAAM,MAAM;AAC5D,oBAAmB;EACnB;;;;AAMF,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,M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AAK;GAC7D,IAAI,OAAO,KAAKA,yBAAU;AAC1B,OAAI,KACF,QAAO,QAAQ,KAAK,CAAC,SAAS,CAAC,KAAK,WAAW;AAC7C,WAAO,KAAK,QACV,IAAI,OAAO,SAAS,IAAI,SAAS,IAAI,EACrC,OAAO,MAAM,CACd;KACD;AAEJ,UAAO;;AAGT,SAAOJ,8CAAmB;GACxB,GAAG;GACH,OAAO;GACP,UAAU;GACX,CAAC;;CAEL;;;;;AAiCD,MAAa,cACX,QACA,WAAoB,SACN;mDAEZ,UAAUK,+BAAc,qBAAqB,eAC7C,WAAWA,+BAAc,qBAAqB,gBAAgB,OAC/D;CACDC;CACAC;8CACa,UAAUF,+BAAc,qBAAqB,cAAc;CACxEG;CACAC;CACA;CACA;CACA;CACA;CACD"}
|
|
@@ -7,7 +7,8 @@ const renderIntlayerNode = ({ children, value, additionalProps = {} }) => {
|
|
|
7
7
|
if (additionalProps && Object.keys(additionalProps).includes(prop)) return additionalProps[prop];
|
|
8
8
|
return Reflect.get(target, prop, receiver);
|
|
9
9
|
} });
|
|
10
|
-
|
|
10
|
+
const target = typeof children === "object" || typeof children === "function" ? children : {};
|
|
11
|
+
return new Proxy(target, {
|
|
11
12
|
apply(target, thisArg, argumentsList) {
|
|
12
13
|
if (typeof value === "function") return Reflect.apply(value, thisArg, argumentsList);
|
|
13
14
|
return Reflect.apply(target, thisArg, argumentsList);
|
|
@@ -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\ntype RenderIntlayerNodeProps<T> = {\n value: T;\n children: any;\n additionalProps?: { [key: string]: any };\n};\n\nexport const renderIntlayerNode = <\n T extends number | string | boolean | undefined | null,\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') {\n return value;\n }\n\n if (\n additionalProps &&\n Object.keys(additionalProps).includes(prop as string)\n ) {\n return additionalProps[prop as keyof typeof additionalProps];\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as IntlayerNode<T>;\n }\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(
|
|
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\ntype RenderIntlayerNodeProps<T> = {\n value: T;\n children: any;\n additionalProps?: { [key: string]: any };\n};\n\nexport const renderIntlayerNode = <\n T extends number | string | boolean | undefined | null,\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') {\n return value;\n }\n\n if (\n additionalProps &&\n Object.keys(additionalProps).includes(prop as string)\n ) {\n return additionalProps[prop as keyof typeof additionalProps];\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') {\n return value;\n }\n\n if (prop === 'toString') {\n return () => {\n // console.log('renderIntlayerNode toString called for:', value);\n return String(value);\n };\n }\n\n if (prop === Symbol.toPrimitive) {\n return () => value;\n }\n\n if (\n additionalProps &&\n Object.keys(additionalProps).includes(prop as string)\n ) {\n return additionalProps[prop as keyof typeof additionalProps];\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as IntlayerNode<T>;\n};\n"],"mappings":";;;AAeA,MAAa,sBAEX,EACA,UACA,OACA,kBAAkB,EAAE,OAC6B;AAEjD,KAAI,YAAY,KACd,QAAO,IAAI,MAAM,EAAE,EAAS,EAC1B,IAAI,QAAQ,MAAM,UAAU;AAC1B,MAAI,SAAS,QACX,QAAO;AAGT,MACE,mBACA,OAAO,KAAK,gBAAgB,CAAC,SAAS,KAAe,CAErD,QAAO,gBAAgB;AAGzB,SAAO,QAAQ,IAAI,QAAQ,MAAM,SAAS;IAE7C,CAAC;CAIJ,MAAM,SACJ,OAAO,aAAa,YAAY,OAAO,aAAa,aAChD,WACC,EAAE;AAIT,QAAO,IAAI,MAAM,QAAQ;EACvB,MAAM,QAAQ,SAAS,eAAe;AACpC,OAAI,OAAO,UAAU,WACnB,QAAO,QAAQ,MAAM,OAAmB,SAAS,cAAc;AAEjE,UAAO,QAAQ,MAAM,QAAoB,SAAS,cAAc;;EAElE,IAAI,QAAQ,MAAM,UAAU;AAC1B,OAAI,SAAS,QACX,QAAO;AAGT,OAAI,SAAS,WACX,cAAa;AAEX,WAAO,OAAO,MAAM;;AAIxB,OAAI,SAAS,OAAO,YAClB,cAAa;AAGf,OACE,mBACA,OAAO,KAAK,gBAAgB,CAAC,SAAS,KAAe,CAErD,QAAO,gBAAgB;AAGzB,UAAO,QAAQ,IAAI,QAAQ,MAAM,SAAS;;EAE7C,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import configuration from "@intlayer/config/built";
|
|
2
|
+
|
|
3
|
+
//#region ../@intlayer/editor/src/isEnabled.ts
|
|
4
|
+
const isEnabled = process.env["INTLAYER_EDITOR_ENABLED"] !== "false" && configuration.editor?.enabled && typeof window !== "undefined" && window.self !== window.top;
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
export { isEnabled };
|
|
8
|
+
//# sourceMappingURL=isEnabled.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isEnabled.mjs","names":[],"sources":["../../../../../../@intlayer/editor/src/isEnabled.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\n\nexport const isEnabled =\n process.env['INTLAYER_EDITOR_ENABLED'] !== 'false' && // Allow purging a build time using bundler + env var // Keep env['INTLAYER_EDITOR_ENABLED'] syntax for angular to treat it as\n configuration.editor?.enabled && // Editor enabled in config\n typeof window !== 'undefined' && // Client side\n window.self !== window.top; // Is in iframe\n"],"mappings":";;;AAEA,MAAa,YACX,QAAQ,IAAI,+BAA+B,WAC3C,cAAc,QAAQ,WACtB,OAAO,WAAW,eAClB,OAAO,SAAS,OAAO"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { __decorateMetadata } from "../_virtual/_@oxc-project_runtime@0.115.0/helpers/decorateMetadata.mjs";
|
|
2
|
+
import { __decorate } from "../_virtual/_@oxc-project_runtime@0.115.0/helpers/decorate.mjs";
|
|
3
|
+
import { ChangeDetectorRef, Component, ElementRef, Input, ViewContainerRef, inject } from "@angular/core";
|
|
4
|
+
|
|
5
|
+
//#region src/UI/IntlayerNode.component.ts
|
|
6
|
+
let IntlayerNodeComponent = class IntlayerNodeComponent {
|
|
7
|
+
node;
|
|
8
|
+
vcr = inject(ViewContainerRef);
|
|
9
|
+
elRef = inject(ElementRef);
|
|
10
|
+
cdr = inject(ChangeDetectorRef);
|
|
11
|
+
ngOnChanges(changes) {
|
|
12
|
+
if (changes["node"]) this.render();
|
|
13
|
+
}
|
|
14
|
+
render() {
|
|
15
|
+
this.vcr.clear();
|
|
16
|
+
const host = this.elRef.nativeElement;
|
|
17
|
+
host.childNodes.forEach((n) => {
|
|
18
|
+
if (n.nodeType === Node.TEXT_NODE) n.parentNode?.removeChild(n);
|
|
19
|
+
});
|
|
20
|
+
if (!this.node) return;
|
|
21
|
+
const nodeInfo = typeof this.node?.children === "function" ? this.node.children() : this.node;
|
|
22
|
+
if (nodeInfo?.component && typeof nodeInfo.component !== "string") {
|
|
23
|
+
const componentRef = this.vcr.createComponent(nodeInfo.component);
|
|
24
|
+
if (nodeInfo.props) for (const [key, value] of Object.entries(nodeInfo.props)) componentRef.instance[key] = value;
|
|
25
|
+
if (nodeInfo.children) {
|
|
26
|
+
const content = nodeInfo.children;
|
|
27
|
+
if (typeof content === "string" || typeof content === "number") componentRef.location.nativeElement.appendChild(document.createTextNode(String(content)));
|
|
28
|
+
}
|
|
29
|
+
this.cdr.markForCheck();
|
|
30
|
+
} else {
|
|
31
|
+
const text = this.node?.value ?? this.node?.toString?.() ?? String(this.node);
|
|
32
|
+
host.appendChild(document.createTextNode(text));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
__decorate([Input(), __decorateMetadata("design:type", Object)], IntlayerNodeComponent.prototype, "node", void 0);
|
|
37
|
+
IntlayerNodeComponent = __decorate([Component({
|
|
38
|
+
selector: "intlayer-node",
|
|
39
|
+
standalone: true,
|
|
40
|
+
template: `<ng-container #anchor></ng-container>`,
|
|
41
|
+
styles: [`:host { display: contents; }`]
|
|
42
|
+
})], IntlayerNodeComponent);
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { IntlayerNodeComponent };
|
|
46
|
+
//# sourceMappingURL=IntlayerNode.component.mjs.map
|
|
@@ -0,0 +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,kCAAM,sBAA2C;CACtD,AAAS;CAET,AAAQ,MAAM,OAAO,iBAAiB;CACtC,AAAQ,QAAQ,OAAgC,WAAW;CAC3D,AAAQ,MAAM,OAAO,kBAAkB;CAEvC,YAAY,SAA8B;AACxC,MAAI,QAAQ,QACV,MAAK,QAAQ;;CAIjB,AAAQ,SAAS;AAEf,OAAK,IAAI,OAAO;EAChB,MAAM,OAAO,KAAK,MAAM;AAExB,OAAK,WAAW,SAAS,MAAM;AAC7B,OAAI,EAAE,aAAa,KAAK,UAAW,GAAE,YAAY,YAAY,EAAE;IAC/D;AAEF,MAAI,CAAC,KAAK,KAAM;EAKhB,MAAM,WACJ,OAAO,KAAK,MAAM,aAAa,aAC3B,KAAK,KAAK,UAAU,GACpB,KAAK;AAEX,MAAI,UAAU,aAAa,OAAO,SAAS,cAAc,UAAU;GAEjE,MAAM,eAAe,KAAK,IAAI,gBAC5B,SAAS,UACV;AAED,OAAI,SAAS,MACX,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,SAAS,MAAM,CACvD,CAAC,aAAa,SAAiB,OAAO;AAI1C,OAAI,SAAS,UAAU;IACrB,MAAM,UAAU,SAAS;AACzB,QAAI,OAAO,YAAY,YAAY,OAAO,YAAY,SACpD,cAAa,SAAS,cAAc,YAClC,SAAS,eAAe,OAAO,QAAQ,CAAC,CACzC;;AAIL,QAAK,IAAI,cAAc;SAClB;GAEL,MAAM,OACJ,KAAK,MAAM,SAAS,KAAK,MAAM,YAAY,IAAI,OAAO,KAAK,KAAK;AAIlE,QAAK,YAAY,SAAS,eAAe,KAAK,CAAC;;;;YA5DlD,OAAO;oCAVT,UAAU;CACT,UAAU;CACV,YAAY;CAGZ,UAAU;CAEV,QAAQ,CAAC,+BAA+B;CACzC,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { INTLAYER_TOKEN, IntlayerProvider, createIntlayerClient
|
|
1
|
+
import { INTLAYER_TOKEN, IntlayerProvider, createIntlayerClient } from "./intlayerToken.mjs";
|
|
2
|
+
import { installIntlayer, provideIntlayer } from "./installIntlayer.mjs";
|
|
2
3
|
import { useDictionary } from "./useDictionary.mjs";
|
|
3
4
|
import { useDictionaryAsync } from "./useDictionaryAsync.mjs";
|
|
4
5
|
import { useLoadDynamic } from "./useLoadDynamic.mjs";
|
|
5
6
|
import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
|
|
6
|
-
import { useIntl } from "./useIntl.mjs";
|
|
7
7
|
import { isUpdatableNode, useIntlayer } from "./useIntlayer.mjs";
|
|
8
8
|
import { useLocale } from "./useLocale.mjs";
|
|
9
9
|
|
|
10
|
-
export { INTLAYER_TOKEN, IntlayerProvider, createIntlayerClient, installIntlayer, isUpdatableNode, provideIntlayer, useDictionary, useDictionaryAsync, useDictionaryDynamic,
|
|
10
|
+
export { INTLAYER_TOKEN, IntlayerProvider, createIntlayerClient, installIntlayer, isUpdatableNode, provideIntlayer, useDictionary, useDictionaryAsync, useDictionaryDynamic, useIntlayer, useLoadDynamic, useLocale };
|
|
@@ -1,41 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { Injectable, InjectionToken, signal } from "@angular/core";
|
|
1
|
+
import { INTLAYER_TOKEN, IntlayerProvider, createIntlayerClient } from "./intlayerToken.mjs";
|
|
2
|
+
import { provideIntlayerEditor } from "../editor/useEditor.mjs";
|
|
4
3
|
|
|
5
4
|
//#region src/client/installIntlayer.ts
|
|
6
|
-
const INTLAYER_TOKEN = new InjectionToken("intlayer");
|
|
7
|
-
/**
|
|
8
|
-
* Singleton instance
|
|
9
|
-
*/
|
|
10
|
-
let instance = null;
|
|
11
|
-
let IntlayerProvider = class IntlayerProvider {
|
|
12
|
-
isCookieEnabled = signal(true);
|
|
13
|
-
_locale = signal(configuration.internationalization?.defaultLocale);
|
|
14
|
-
locale = this._locale.asReadonly();
|
|
15
|
-
setLocale = (locale) => {
|
|
16
|
-
this._locale.set(locale);
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
IntlayerProvider = __decorate([Injectable({ providedIn: "root" })], IntlayerProvider);
|
|
20
|
-
/**
|
|
21
|
-
* Create and return a single IntlayerProvider instance
|
|
22
|
-
*/
|
|
23
|
-
const createIntlayerClient = (locale, isCookieEnabled = true) => {
|
|
24
|
-
if (instance) return instance;
|
|
25
|
-
instance = new IntlayerProvider();
|
|
26
|
-
if (locale) instance.setLocale(locale);
|
|
27
|
-
instance.isCookieEnabled.set(isCookieEnabled);
|
|
28
|
-
return instance;
|
|
29
|
-
};
|
|
30
5
|
/**
|
|
31
6
|
* Provides Intlayer to your Angular application.
|
|
32
7
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
8
|
+
* Registers the Intlayer locale token **and** automatically starts the Intlayer
|
|
9
|
+
* editor client (when the editor is enabled) via `provideAppInitializer`.
|
|
10
|
+
*
|
|
11
|
+
* This is the recommended way to set up Intlayer in `app.config.ts`.
|
|
35
12
|
*
|
|
36
13
|
* @param locale - Initial locale to use.
|
|
37
14
|
* @param isCookieEnabled - Whether to store the locale in cookies.
|
|
38
|
-
* @returns
|
|
15
|
+
* @returns An array of Angular providers for Intlayer.
|
|
39
16
|
*
|
|
40
17
|
* @example
|
|
41
18
|
* ```ts
|
|
@@ -44,16 +21,17 @@ const createIntlayerClient = (locale, isCookieEnabled = true) => {
|
|
|
44
21
|
* import { provideIntlayer } from 'angular-intlayer';
|
|
45
22
|
*
|
|
46
23
|
* export const appConfig: ApplicationConfig = {
|
|
47
|
-
* providers: [
|
|
48
|
-
* provideIntlayer({ locale: 'en' }),
|
|
49
|
-
* ],
|
|
24
|
+
* providers: [provideIntlayer()],
|
|
50
25
|
* };
|
|
51
26
|
* ```
|
|
52
27
|
*/
|
|
53
|
-
const provideIntlayer = (locale, isCookieEnabled = true) =>
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
28
|
+
const provideIntlayer = (locale, isCookieEnabled = true) => {
|
|
29
|
+
const client = installIntlayer(locale, isCookieEnabled);
|
|
30
|
+
return [{
|
|
31
|
+
provide: INTLAYER_TOKEN,
|
|
32
|
+
useValue: client
|
|
33
|
+
}, provideIntlayerEditor(client)];
|
|
34
|
+
};
|
|
57
35
|
/**
|
|
58
36
|
* Helper to install the Intlayer provider.
|
|
59
37
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installIntlayer.mjs","names":[],"sources":["../../../src/client/installIntlayer.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"installIntlayer.mjs","names":[],"sources":["../../../src/client/installIntlayer.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { provideIntlayerEditor } from '../editor/useEditor';\nimport {\n createIntlayerClient,\n INTLAYER_TOKEN,\n IntlayerProvider,\n} from './intlayerToken';\n\nexport { createIntlayerClient, INTLAYER_TOKEN, IntlayerProvider };\n\n/**\n * Provides Intlayer to your Angular application.\n *\n * Registers the Intlayer locale token **and** automatically starts the Intlayer\n * editor client (when the editor is enabled) via `provideAppInitializer`.\n *\n * This is the recommended way to set up Intlayer in `app.config.ts`.\n *\n * @param locale - Initial locale to use.\n * @param isCookieEnabled - Whether to store the locale in cookies.\n * @returns An array of Angular providers for Intlayer.\n *\n * @example\n * ```ts\n * // app.config.ts\n * import { ApplicationConfig } from '@angular/core';\n * import { provideIntlayer } from 'angular-intlayer';\n *\n * export const appConfig: ApplicationConfig = {\n * providers: [provideIntlayer()],\n * };\n * ```\n */\nexport const provideIntlayer = (\n locale?: LocalesValues,\n isCookieEnabled = true\n) => {\n const client = installIntlayer(locale, isCookieEnabled);\n\n return [\n { provide: INTLAYER_TOKEN, useValue: client },\n provideIntlayerEditor(client),\n ];\n};\n\n/**\n * Helper to install the Intlayer provider.\n */\nexport const installIntlayer = (\n locale?: LocalesValues,\n isCookieEnabled = true\n) => {\n return createIntlayerClient(locale, isCookieEnabled);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAa,mBACX,QACA,kBAAkB,SACf;CACH,MAAM,SAAS,gBAAgB,QAAQ,gBAAgB;AAEvD,QAAO,CACL;EAAE,SAAS;EAAgB,UAAU;EAAQ,EAC7C,sBAAsB,OAAO,CAC9B;;;;;AAMH,MAAa,mBACX,QACA,kBAAkB,SACf;AACH,QAAO,qBAAqB,QAAQ,gBAAgB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import configuration from "@intlayer/config/built";
|
|
2
|
+
import { InjectionToken, signal } from "@angular/core";
|
|
3
|
+
|
|
4
|
+
//#region src/client/intlayerToken.ts
|
|
5
|
+
var IntlayerProvider = class {
|
|
6
|
+
isCookieEnabled = signal(true);
|
|
7
|
+
_locale = signal(configuration.internationalization?.defaultLocale);
|
|
8
|
+
locale = this._locale.asReadonly();
|
|
9
|
+
setLocale = (locale) => {
|
|
10
|
+
this._locale.set(locale);
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
const INTLAYER_TOKEN = new InjectionToken("intlayer");
|
|
14
|
+
/**
|
|
15
|
+
* Singleton instance
|
|
16
|
+
*/
|
|
17
|
+
let instance = null;
|
|
18
|
+
/**
|
|
19
|
+
* Create and return a single IntlayerProvider instance
|
|
20
|
+
*/
|
|
21
|
+
const createIntlayerClient = (locale, isCookieEnabled = true) => {
|
|
22
|
+
if (instance) return instance;
|
|
23
|
+
instance = new IntlayerProvider();
|
|
24
|
+
if (locale) instance.setLocale(locale);
|
|
25
|
+
instance.isCookieEnabled.set(isCookieEnabled);
|
|
26
|
+
return instance;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { INTLAYER_TOKEN, IntlayerProvider, createIntlayerClient };
|
|
31
|
+
//# sourceMappingURL=intlayerToken.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intlayerToken.mjs","names":[],"sources":["../../../src/client/intlayerToken.ts"],"sourcesContent":["import { InjectionToken, type Signal, signal } from '@angular/core';\nimport configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\nexport class IntlayerProvider {\n isCookieEnabled = signal(true);\n private _locale = signal<LocalesValues>(\n configuration.internationalization?.defaultLocale as LocalesValues\n );\n\n readonly locale: Signal<LocalesValues> = this._locale.asReadonly();\n\n setLocale = (locale: LocalesValues) => {\n this._locale.set(locale);\n };\n}\n\nexport const INTLAYER_TOKEN = new InjectionToken<IntlayerProvider>('intlayer');\n\n/**\n * Singleton instance\n */\nlet instance: IntlayerProvider | null = null;\n\n/**\n * Create and return a single IntlayerProvider instance\n */\nexport const createIntlayerClient = (\n locale?: LocalesValues,\n isCookieEnabled = true\n): IntlayerProvider => {\n if (instance) return instance;\n\n instance = new IntlayerProvider();\n\n if (locale) {\n instance.setLocale(locale);\n }\n instance.isCookieEnabled.set(isCookieEnabled);\n\n return instance;\n};\n"],"mappings":";;;;AAIA,IAAa,mBAAb,MAA8B;CAC5B,kBAAkB,OAAO,KAAK;CAC9B,AAAQ,UAAU,OAChB,cAAc,sBAAsB,cACrC;CAED,AAAS,SAAgC,KAAK,QAAQ,YAAY;CAElE,aAAa,WAA0B;AACrC,OAAK,QAAQ,IAAI,OAAO;;;AAI5B,MAAa,iBAAiB,IAAI,eAAiC,WAAW;;;;AAK9E,IAAI,WAAoC;;;;AAKxC,MAAa,wBACX,QACA,kBAAkB,SACG;AACrB,KAAI,SAAU,QAAO;AAErB,YAAW,IAAI,kBAAkB;AAEjC,KAAI,OACF,UAAS,UAAU,OAAO;AAE5B,UAAS,gBAAgB,IAAI,gBAAgB;AAE7C,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import { computed, inject, type Signal } from '@angular/core';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport type { DeepTransformContent } from '../plugins';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\n\nexport const useDictionary = <T extends Dictionary>(\n dictionary: T,\n locale?: LocalesValues\n): Signal<DeepTransformContent<T['content']>> => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n const localeTarget = computed(() => locale ?? intlayer?.locale());\n\n /** a *stable* reactive dictionary object */\n const content = computed(()
|
|
1
|
+
{"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import { computed, inject, type Signal } from '@angular/core';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport type { DeepTransformContent } from '../plugins';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\n\nexport const useDictionary = <T extends Dictionary>(\n dictionary: T,\n locale?: LocalesValues\n): Signal<DeepTransformContent<T['content']>> => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n const localeTarget = computed(() => locale ?? intlayer?.locale());\n\n /** a *stable* reactive dictionary object */\n const content = computed(\n () => getDictionary<T, LocalesValues>(dictionary, localeTarget()) as any\n );\n\n return content; // all consumers keep full reactivity\n};\n"],"mappings":";;;;;AAOA,MAAa,iBACX,YACA,WAC+C;CAC/C,MAAM,WAAW,OAAyB,eAAe;CAEzD,MAAM,eAAe,eAAe,UAAU,UAAU,QAAQ,CAAC;AAOjE,QAJgB,eACR,cAAgC,YAAY,cAAc,CAAC,CAClE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { INTLAYER_TOKEN } from "./
|
|
3
|
+
import { INTLAYER_TOKEN } from "./intlayerToken.mjs";
|
|
4
4
|
import { useDictionary } from "./useDictionary.mjs";
|
|
5
5
|
import configuration from "@intlayer/config/built";
|
|
6
6
|
import { computed, inject } from "@angular/core";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryAsync.mjs","names":[],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["'use client';\n\nimport { computed, inject } from '@angular/core';\nimport configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.mjs","names":[],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["'use client';\n\nimport { computed, inject } from '@angular/core';\nimport configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\nimport { useDictionary } from './useDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryAsync = async <T extends Dictionary>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: LocalesValues\n) => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n const localeTarget = computed(\n () =>\n locale ??\n intlayer?.locale() ??\n configuration?.internationalization.defaultLocale\n );\n\n const dictionary = await (dictionaryPromise as any)[localeTarget()]?.();\n\n return useDictionary(dictionary, localeTarget() as any);\n};\n"],"mappings":";;;;;;;;;;;;;AAiBA,MAAa,qBAAqB,OAChC,mBACA,WACG;CACH,MAAM,WAAW,OAAyB,eAAe;CAEzD,MAAM,eAAe,eAEjB,UACA,UAAU,QAAQ,IAClB,eAAe,qBAAqB,cACvC;AAID,QAAO,cAFY,MAAO,kBAA0B,cAAc,KAAK,EAEtC,cAAc,CAAQ"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { INTLAYER_TOKEN } from "./
|
|
3
|
+
import { INTLAYER_TOKEN } from "./intlayerToken.mjs";
|
|
4
4
|
import { useDictionary } from "./useDictionary.mjs";
|
|
5
5
|
import { useLoadDynamic } from "./useLoadDynamic.mjs";
|
|
6
6
|
import configuration from "@intlayer/config/built";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.mjs","names":[],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport { computed, inject } from '@angular/core';\nimport configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.mjs","names":[],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport { computed, inject } from '@angular/core';\nimport configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n K extends DictionaryKeys,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n locale?: LocalesValues\n) => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n const localeTarget = computed(\n () =>\n locale ??\n intlayer?.locale() ??\n configuration?.internationalization.defaultLocale\n );\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget()}`,\n (dictionaryPromise as any)[localeTarget()]?.()\n ) as T;\n\n return useDictionary(dictionary, localeTarget() as any);\n};\n"],"mappings":";;;;;;;;;;;;;;AAmBA,MAAa,wBAIX,mBACA,KACA,WACG;CACH,MAAM,WAAW,OAAyB,eAAe;CAEzD,MAAM,eAAe,eAEjB,UACA,UAAU,QAAQ,IAClB,eAAe,qBAAqB,cACvC;AAOD,QAAO,cALY,eACjB,GAAG,OAAO,IAAI,CAAC,GAAG,cAAc,IAC/B,kBAA0B,cAAc,KAAK,CAC/C,EAEgC,cAAc,CAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import { computed, inject, type Signal } from '@angular/core';\nimport type {
|
|
1
|
+
{"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import { computed, inject, type Signal } from '@angular/core';\nimport type {\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\n\n/** guard utility - true only for objects generated by `renderIntlayerNode()` */\nexport const isUpdatableNode = (\n val: unknown\n): val is { __update: (n: unknown) => void } =>\n !!val &&\n typeof val === 'object' &&\n typeof (val as any).__update === 'function';\n\n/**\n * Angular hook that picks one dictionary by its key and returns its reactive content.\n *\n * It utilizes Angular signals to provide deep reactivity, ensuring your components\n * update automatically when the locale changes.\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param locale - Optional locale to override the current context locale.\n * @returns The transformed dictionary content.\n *\n * @example\n * ```ts\n * import { Component } from '@angular/core';\n * import { useIntlayer } from 'angular-intlayer';\n *\n * @Component({\n * standalone: true,\n * selector: 'app-my-component',\n * template: `<div>{{ content().myField.value }}</div>`,\n * })\n * export class MyComponent {\n * content = useIntlayer('my-dictionary-key');\n * }\n * ```\n */\nexport const useIntlayer = <T extends DictionaryKeys, L extends LocalesValues>(\n key: T,\n locale?: LocalesValues\n): Signal<DeepTransformContent<DictionaryRegistryContent<T>>> => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN)!;\n\n /** which locale should we use right now? */\n const localeTarget = computed(() => locale ?? intlayer.locale());\n\n /** a *stable* reactive dictionary object */\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n const content = computed(\n () => getIntlayer<T, L>(key, localeTarget() as L) as any\n );\n\n return content; // all consumers keep full reactivity\n};\n"],"mappings":";;;;;;AAWA,MAAa,mBACX,QAEA,CAAC,CAAC,OACF,OAAO,QAAQ,YACf,OAAQ,IAAY,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BnC,MAAa,eACX,KACA,WAC+D;CAC/D,MAAM,WAAW,OAAyB,eAAe;;CAGzD,MAAM,eAAe,eAAe,UAAU,SAAS,QAAQ,CAAC;AAQhE,QAJgB,eACR,YAAkB,KAAK,cAAc,CAAM,CAClD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { INTLAYER_TOKEN } from "./
|
|
1
|
+
import { INTLAYER_TOKEN } from "./intlayerToken.mjs";
|
|
2
2
|
import { setLocaleInStorage } from "./useLocaleStorage.mjs";
|
|
3
3
|
import configuration from "@intlayer/config/built";
|
|
4
4
|
import { computed, inject } from "@angular/core";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { __decorateMetadata } from "../_virtual/_@oxc-project_runtime@0.115.0/helpers/decorateMetadata.mjs";
|
|
2
|
+
import { __decorate } from "../_virtual/_@oxc-project_runtime@0.115.0/helpers/decorate.mjs";
|
|
3
|
+
import { useEditor } from "./useEditor.mjs";
|
|
4
|
+
import { Component } from "@angular/core";
|
|
5
|
+
|
|
6
|
+
//#region src/editor/EditorProvider.component.ts
|
|
7
|
+
let EditorProviderComponent = class EditorProviderComponent {
|
|
8
|
+
constructor() {
|
|
9
|
+
useEditor();
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
EditorProviderComponent = __decorate([Component({
|
|
13
|
+
selector: "intlayer-editor-provider",
|
|
14
|
+
standalone: true,
|
|
15
|
+
template: `<ng-content />`
|
|
16
|
+
}), __decorateMetadata("design:paramtypes", [])], EditorProviderComponent);
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { EditorProviderComponent };
|
|
20
|
+
//# sourceMappingURL=EditorProvider.component.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EditorProvider.component.mjs","names":[],"sources":["../../../src/editor/EditorProvider.component.ts"],"sourcesContent":["import { Component } from '@angular/core';\nimport { useEditor } from './useEditor';\n\n/**\n * Drop-in Angular equivalent of React's `EditorProvider`.\n *\n * Wrap your root component (or any subtree) with this component to automatically\n * start the Intlayer editor client. The editor will be started on mount and\n * stopped when this component is destroyed.\n *\n * @example\n * ```html\n * <!-- app.component.html -->\n * <intlayer-editor-provider>\n * <router-outlet />\n * </intlayer-editor-provider>\n * ```\n *\n * ```ts\n * // app.component.ts\n * import { EditorProviderComponent } from 'angular-intlayer';\n *\n * @Component({\n * imports: [EditorProviderComponent],\n * …\n * })\n * export class AppComponent {}\n * ```\n */\n@Component({\n selector: 'intlayer-editor-provider',\n standalone: true,\n template: `<ng-content />`,\n})\nexport class EditorProviderComponent {\n constructor() {\n useEditor();\n }\n}\n"],"mappings":";;;;;;AAkCO,oCAAM,wBAAwB;CACnC,cAAc;AACZ,aAAW;;;sCAPd,UAAU;CACT,UAAU;CACV,YAAY;CACZ,UAAU;CACX,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ContentSelectorWrapperComponent } from "./ContentSelector.component.mjs";
|
|
2
|
+
import { provideIntlayerEditor, useEditor } from "./useEditor.mjs";
|
|
3
|
+
import { EditorProviderComponent } from "./EditorProvider.component.mjs";
|
|
4
|
+
|
|
5
|
+
export { ContentSelectorWrapperComponent, EditorProviderComponent, provideIntlayerEditor, useEditor };
|
|
@@ -1,30 +1,64 @@
|
|
|
1
|
-
import { INTLAYER_TOKEN } from "../client/
|
|
2
|
-
import { DestroyRef, Injector, effect, inject, runInInjectionContext } from "@angular/core";
|
|
1
|
+
import { INTLAYER_TOKEN } from "../client/intlayerToken.mjs";
|
|
2
|
+
import { DestroyRef, Injector, effect, inject, provideAppInitializer, runInInjectionContext, signal } from "@angular/core";
|
|
3
3
|
import { isEnabled } from "@intlayer/editor/isEnabled";
|
|
4
4
|
|
|
5
5
|
//#region src/editor/useEditor.ts
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Initialises the Intlayer editor client singleton when the editor is enabled.
|
|
8
|
+
* Syncs the current locale from the provided Intlayer client into the editor
|
|
9
|
+
* manager so the editor always knows which locale the app is displaying.
|
|
10
|
+
*
|
|
11
|
+
* Must be called inside an Angular injection context (e.g. a component
|
|
12
|
+
* constructor, `provideAppInitializer`, or `runInInjectionContext`).
|
|
13
|
+
*
|
|
14
|
+
* @param client - The IntlayerProvider instance to sync locale from.
|
|
15
|
+
* When omitted the function injects `INTLAYER_TOKEN` from the DI tree,
|
|
16
|
+
* so it still works when called directly from a component.
|
|
17
|
+
*/
|
|
18
|
+
const useEditor = (client) => {
|
|
19
|
+
if (!isEnabled) return;
|
|
8
20
|
const destroyRef = inject(DestroyRef, { optional: true });
|
|
9
|
-
const client = inject(INTLAYER_TOKEN, { optional: true });
|
|
10
21
|
const injector = inject(Injector);
|
|
22
|
+
const resolvedClient = client ?? inject(INTLAYER_TOKEN, { optional: true });
|
|
23
|
+
const manager = signal(null);
|
|
24
|
+
let stopped = false;
|
|
11
25
|
import("@intlayer/editor").then(({ initEditorClient }) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const effectRef = runInInjectionContext(injector, () => effect(() => {
|
|
15
|
-
const locale = client.locale();
|
|
16
|
-
if (locale) manager.currentLocale.set(locale);
|
|
17
|
-
}));
|
|
18
|
-
destroyRef?.onDestroy(() => effectRef.destroy());
|
|
19
|
-
}
|
|
26
|
+
if (stopped) return;
|
|
27
|
+
manager.set(initEditorClient());
|
|
20
28
|
});
|
|
29
|
+
const effectRef = runInInjectionContext(injector, () => effect(() => {
|
|
30
|
+
const m = manager();
|
|
31
|
+
const locale = resolvedClient?.locale();
|
|
32
|
+
if (m && locale) m.currentLocale.set(locale);
|
|
33
|
+
}));
|
|
21
34
|
destroyRef?.onDestroy(() => {
|
|
35
|
+
stopped = true;
|
|
36
|
+
effectRef.destroy();
|
|
37
|
+
manager.set(null);
|
|
22
38
|
import("@intlayer/editor").then(({ stopEditorClient }) => {
|
|
23
39
|
stopEditorClient();
|
|
24
40
|
});
|
|
25
41
|
});
|
|
26
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* Angular provider that wires `useEditor` into the application initialisation
|
|
45
|
+
* phase via `provideAppInitializer`.
|
|
46
|
+
*
|
|
47
|
+
* `provideIntlayer()` already calls this internally, so you only need this
|
|
48
|
+
* function when you want to manage providers individually.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* // app.config.ts
|
|
53
|
+
* import { provideIntlayer, provideIntlayerEditor } from 'angular-intlayer';
|
|
54
|
+
*
|
|
55
|
+
* export const appConfig: ApplicationConfig = {
|
|
56
|
+
* providers: [provideIntlayer(), provideIntlayerEditor()],
|
|
57
|
+
* };
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
const provideIntlayerEditor = (client) => provideAppInitializer(() => useEditor(client));
|
|
27
61
|
|
|
28
62
|
//#endregion
|
|
29
|
-
export { useEditor };
|
|
63
|
+
export { provideIntlayerEditor, useEditor };
|
|
30
64
|
//# sourceMappingURL=useEditor.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEditor.mjs","names":[],"sources":["../../../src/editor/useEditor.ts"],"sourcesContent":["import {\n DestroyRef,\n effect,\n Injector,\n inject,\n runInInjectionContext,\n} from '@angular/core';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from '../client';\n\nexport const useEditor = () => {\n if (
|
|
1
|
+
{"version":3,"file":"useEditor.mjs","names":[],"sources":["../../../src/editor/useEditor.ts"],"sourcesContent":["import {\n DestroyRef,\n effect,\n Injector,\n inject,\n provideAppInitializer,\n runInInjectionContext,\n signal,\n} from '@angular/core';\nimport type { EditorStateManager } from '@intlayer/editor';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { Locale } from '@intlayer/types/allLocales';\n// Import from the standalone token file to avoid a circular dependency:\n// installIntlayer.ts → useEditor.ts → ../client → installIntlayer.ts\nimport { INTLAYER_TOKEN, type IntlayerProvider } from '../client/intlayerToken';\n\n/**\n * Initialises the Intlayer editor client singleton when the editor is enabled.\n * Syncs the current locale from the provided Intlayer client into the editor\n * manager so the editor always knows which locale the app is displaying.\n *\n * Must be called inside an Angular injection context (e.g. a component\n * constructor, `provideAppInitializer`, or `runInInjectionContext`).\n *\n * @param client - The IntlayerProvider instance to sync locale from.\n * When omitted the function injects `INTLAYER_TOKEN` from the DI tree,\n * so it still works when called directly from a component.\n */\nexport const useEditor = (client?: IntlayerProvider | null): void => {\n if (!isEnabled) return;\n\n const destroyRef = inject(DestroyRef, { optional: true });\n const injector = inject(Injector);\n\n // Resolve the client: use the passed-in reference or fall back to injection.\n const resolvedClient =\n client ??\n inject<IntlayerProvider>(INTLAYER_TOKEN, { optional: true } as any);\n\n // `manager` signal is set once the async import resolves.\n // Using a signal lets an `effect()` react to it becoming available.\n const manager = signal<EditorStateManager | null>(null);\n\n // Guard: prevents the async callback from acting after the view is destroyed.\n let stopped = false;\n\n // Initialise the editor client\n import('@intlayer/editor').then(({ initEditorClient }) => {\n if (stopped) return;\n manager.set(initEditorClient());\n });\n\n // Keep the editor locale in sync with the Angular locale signal\n const effectRef = runInInjectionContext(injector, () =>\n effect(() => {\n const m = manager();\n const locale = resolvedClient?.locale();\n if (m && locale) m.currentLocale.set(locale as Locale);\n })\n );\n\n // Tear down on destroy\n destroyRef?.onDestroy(() => {\n stopped = true;\n effectRef.destroy();\n manager.set(null);\n import('@intlayer/editor').then(({ stopEditorClient }) => {\n stopEditorClient();\n });\n });\n};\n\n/**\n * Angular provider that wires `useEditor` into the application initialisation\n * phase via `provideAppInitializer`.\n *\n * `provideIntlayer()` already calls this internally, so you only need this\n * function when you want to manage providers individually.\n *\n * @example\n * ```ts\n * // app.config.ts\n * import { provideIntlayer, provideIntlayerEditor } from 'angular-intlayer';\n *\n * export const appConfig: ApplicationConfig = {\n * providers: [provideIntlayer(), provideIntlayerEditor()],\n * };\n * ```\n */\nexport const provideIntlayerEditor = (client?: IntlayerProvider | null) =>\n provideAppInitializer(() => useEditor(client));\n"],"mappings":";;;;;;;;;;;;;;;;;AA4BA,MAAa,aAAa,WAA2C;AACnE,KAAI,CAAC,UAAW;CAEhB,MAAM,aAAa,OAAO,YAAY,EAAE,UAAU,MAAM,CAAC;CACzD,MAAM,WAAW,OAAO,SAAS;CAGjC,MAAM,iBACJ,UACA,OAAyB,gBAAgB,EAAE,UAAU,MAAM,CAAQ;CAIrE,MAAM,UAAU,OAAkC,KAAK;CAGvD,IAAI,UAAU;AAGd,QAAO,oBAAoB,MAAM,EAAE,uBAAuB;AACxD,MAAI,QAAS;AACb,UAAQ,IAAI,kBAAkB,CAAC;GAC/B;CAGF,MAAM,YAAY,sBAAsB,gBACtC,aAAa;EACX,MAAM,IAAI,SAAS;EACnB,MAAM,SAAS,gBAAgB,QAAQ;AACvC,MAAI,KAAK,OAAQ,GAAE,cAAc,IAAI,OAAiB;GACtD,CACH;AAGD,aAAY,gBAAgB;AAC1B,YAAU;AACV,YAAU,SAAS;AACnB,UAAQ,IAAI,KAAK;AACjB,SAAO,oBAAoB,MAAM,EAAE,uBAAuB;AACxD,qBAAkB;IAClB;GACF;;;;;;;;;;;;;;;;;;;AAoBJ,MAAa,yBAAyB,WACpC,4BAA4B,UAAU,OAAO,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useUnit } from "./useUnit.mjs";
|
|
2
|
+
import { useDate } from "./useDate.mjs";
|
|
3
|
+
import { useNumber } from "./useNumber.mjs";
|
|
4
|
+
import { useRelativeTime } from "./useRelativeTime.mjs";
|
|
5
|
+
import { useCompact } from "./useCompact.mjs";
|
|
6
|
+
import { useIntl } from "./useIntl.mjs";
|
|
7
|
+
import { useList } from "./useList.mjs";
|
|
8
|
+
import { usePercentage } from "./usePercentage.mjs";
|
|
9
|
+
import { useCurrency } from "./useCurrency.mjs";
|
|
10
|
+
|
|
11
|
+
export { useCompact, useCurrency, useDate, useIntl, useList, useNumber, usePercentage, useRelativeTime, useUnit };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { INTLAYER_TOKEN } from "../client/intlayerToken.mjs";
|
|
2
|
+
import { computed, inject } from "@angular/core";
|
|
3
|
+
import { compact } from "@intlayer/core/formatters";
|
|
4
|
+
|
|
5
|
+
//#region src/format/useCompact.ts
|
|
6
|
+
const useCompact = () => {
|
|
7
|
+
const intlayer = inject(INTLAYER_TOKEN);
|
|
8
|
+
return computed(() => (...args) => compact(args[0], {
|
|
9
|
+
...args[1],
|
|
10
|
+
locale: args[1]?.locale ?? intlayer.locale()
|
|
11
|
+
}));
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { useCompact };
|
|
16
|
+
//# sourceMappingURL=useCompact.mjs.map
|