angular-intlayer 9.5.9 → 9.5.11
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/client/intlayerToken.cjs +3 -1
- package/dist/cjs/client/intlayerToken.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +10 -2
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
- package/dist/cjs/esbuild/plugin.cjs +3 -3
- package/dist/cjs/plugins.cjs +63 -69
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/renderIntlayerNode.cjs +17 -36
- package/dist/cjs/renderIntlayerNode.cjs.map +1 -1
- package/dist/cjs/webpack/mergeConfig.cjs +1 -1
- package/dist/esm/client/intlayerToken.mjs +3 -1
- package/dist/esm/client/intlayerToken.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +1 -1
- package/dist/esm/client/useLocaleStorage.mjs +11 -4
- package/dist/esm/client/useLocaleStorage.mjs.map +1 -1
- package/dist/esm/plugins.mjs +63 -69
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/renderIntlayerNode.mjs +17 -36
- package/dist/esm/renderIntlayerNode.mjs.map +1 -1
- package/dist/types/client/intlayerToken.d.ts.map +1 -1
- package/dist/types/client/useLocaleStorage.d.ts +12 -6
- package/dist/types/client/useLocaleStorage.d.ts.map +1 -1
- package/dist/types/format/useCompact.d.ts +1 -2
- package/dist/types/format/useCompact.d.ts.map +1 -1
- package/dist/types/format/useCurrency.d.ts +1 -2
- package/dist/types/format/useCurrency.d.ts.map +1 -1
- package/dist/types/format/useDate.d.ts +1 -2
- package/dist/types/format/useDate.d.ts.map +1 -1
- package/dist/types/format/useList.d.ts +1 -2
- package/dist/types/format/useList.d.ts.map +1 -1
- package/dist/types/format/useNumber.d.ts +1 -2
- package/dist/types/format/useNumber.d.ts.map +1 -1
- package/dist/types/format/usePercentage.d.ts +1 -2
- package/dist/types/format/usePercentage.d.ts.map +1 -1
- package/dist/types/format/useRelativeTime.d.ts +1 -2
- package/dist/types/format/useRelativeTime.d.ts.map +1 -1
- package/dist/types/format/useUnit.d.ts +1 -2
- package/dist/types/format/useUnit.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/plugins.d.ts +2 -5
- package/dist/types/plugins.d.ts.map +1 -1
- package/dist/types/renderIntlayerNode.d.ts +22 -2
- package/dist/types/renderIntlayerNode.d.ts.map +1 -1
- package/package.json +10 -10
- package/dist/types/intlayer/dist/types/index.d.ts +0 -14
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_client_useLocaleStorage = require('./useLocaleStorage.cjs');
|
|
2
3
|
let _angular_core = require("@angular/core");
|
|
3
4
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
4
5
|
let _intlayer_config_client = require("@intlayer/config/client");
|
|
@@ -35,7 +36,8 @@ let instance = null;
|
|
|
35
36
|
const createIntlayerClient = (locale, isCookieEnabled = true, variant) => {
|
|
36
37
|
if (instance) return instance;
|
|
37
38
|
instance = new IntlayerProvider();
|
|
38
|
-
|
|
39
|
+
const initialLocale = locale ?? require_client_useLocaleStorage.getLocaleInStorage();
|
|
40
|
+
if (initialLocale) instance.setLocale(initialLocale);
|
|
39
41
|
if (variant !== void 0) instance.setVariant(variant);
|
|
40
42
|
instance.isCookieEnabled.set(isCookieEnabled);
|
|
41
43
|
return instance;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerToken.cjs","names":["signal","internationalization","InjectionToken"],"sources":["../../../src/client/intlayerToken.ts"],"sourcesContent":["import { InjectionToken, type Signal, signal } from '@angular/core';\nimport { internationalization } from '@intlayer/config/built';\nimport { setIntlayerIdentifier } from '@intlayer/config/client';\nimport type {\n LocalesValues,\n ProviderVariant,\n} from '@intlayer/types/module_augmentation';\n\nexport class IntlayerProvider {\n isCookieEnabled = signal(true);\n private _locale = signal<LocalesValues>(\n internationalization.defaultLocale as LocalesValues\n );\n\n private _variant = signal<ProviderVariant | undefined>(undefined);\n\n readonly locale: Signal<LocalesValues> = this._locale.asReadonly();\n\n /**\n * Ambient variant applied to every dictionary read in the app, the same way\n * `locale` is. Overridden per call by an explicit selector.\n */\n readonly variant: Signal<ProviderVariant | undefined> =\n this._variant.asReadonly();\n\n constructor() {\n setIntlayerIdentifier();\n }\n\n setLocale = (locale: LocalesValues) => {\n this._locale.set(locale);\n };\n\n setVariant = (variant: ProviderVariant | undefined) => {\n this._variant.set(variant);\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 variant?: ProviderVariant\n): IntlayerProvider => {\n if (instance) return instance;\n\n instance = new IntlayerProvider();\n\n if (
|
|
1
|
+
{"version":3,"file":"intlayerToken.cjs","names":["signal","internationalization","InjectionToken","getLocaleInStorage"],"sources":["../../../src/client/intlayerToken.ts"],"sourcesContent":["import { InjectionToken, type Signal, signal } from '@angular/core';\nimport { internationalization } from '@intlayer/config/built';\nimport { setIntlayerIdentifier } from '@intlayer/config/client';\nimport type {\n LocalesValues,\n ProviderVariant,\n} from '@intlayer/types/module_augmentation';\nimport { getLocaleInStorage } from './useLocaleStorage';\n\nexport class IntlayerProvider {\n isCookieEnabled = signal(true);\n private _locale = signal<LocalesValues>(\n internationalization.defaultLocale as LocalesValues\n );\n\n private _variant = signal<ProviderVariant | undefined>(undefined);\n\n readonly locale: Signal<LocalesValues> = this._locale.asReadonly();\n\n /**\n * Ambient variant applied to every dictionary read in the app, the same way\n * `locale` is. Overridden per call by an explicit selector.\n */\n readonly variant: Signal<ProviderVariant | undefined> =\n this._variant.asReadonly();\n\n constructor() {\n setIntlayerIdentifier();\n }\n\n setLocale = (locale: LocalesValues) => {\n this._locale.set(locale);\n };\n\n setVariant = (variant: ProviderVariant | undefined) => {\n this._variant.set(variant);\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 variant?: ProviderVariant\n): IntlayerProvider => {\n if (instance) return instance;\n\n instance = new IntlayerProvider();\n\n // Returning visitors keep their language when no locale is passed\n const initialLocale = locale ?? getLocaleInStorage();\n\n if (initialLocale) {\n instance.setLocale(initialLocale);\n }\n if (variant !== undefined) {\n instance.setVariant(variant);\n }\n instance.isCookieEnabled.set(isCookieEnabled);\n\n return instance;\n};\n"],"mappings":";;;;;;;AASA,IAAa,mBAAb,MAA8B;CAC5B,sBAAkBA,sBAAO,IAAI;CAC7B,AAAQ,cAAUA,sBAChBC,4CAAqB,aACvB;CAEA,AAAQ,eAAWD,sBAAoC,MAAS;CAEhE,AAAS,SAAgC,KAAK,QAAQ,WAAW;;;;;CAMjE,AAAS,UACP,KAAK,SAAS,WAAW;CAE3B,cAAc;EACZ,mDAAsB;CACxB;CAEA,aAAa,WAA0B;EACrC,KAAK,QAAQ,IAAI,MAAM;CACzB;CAEA,cAAc,YAAyC;EACrD,KAAK,SAAS,IAAI,OAAO;CAC3B;AACF;AAEA,MAAa,iBAAiB,IAAIE,6BAAiC,UAAU;;;;AAK7E,IAAI,WAAoC;;;;AAKxC,MAAa,wBACX,QACA,kBAAkB,MAClB,YACqB;CACrB,IAAI,UAAU,OAAO;CAErB,WAAW,IAAI,iBAAiB;CAGhC,MAAM,gBAAgB,UAAUC,mDAAmB;CAEnD,IAAI,eACF,SAAS,UAAU,aAAa;CAElC,IAAI,YAAY,QACd,SAAS,WAAW,OAAO;CAE7B,SAAS,gBAAgB,IAAI,eAAe;CAE5C,OAAO;AACT"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_client_intlayerToken = require('./intlayerToken.cjs');
|
|
3
2
|
const require_client_useLocaleStorage = require('./useLocaleStorage.cjs');
|
|
3
|
+
const require_client_intlayerToken = require('./intlayerToken.cjs');
|
|
4
4
|
let _angular_core = require("@angular/core");
|
|
5
5
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
6
6
|
|
|
@@ -3,12 +3,19 @@ let _intlayer_core_utils = require("@intlayer/core/utils");
|
|
|
3
3
|
|
|
4
4
|
//#region src/client/useLocaleStorage.ts
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Reads the locale persisted in the browser storage (cookie, localStorage…).
|
|
7
|
+
*
|
|
8
|
+
* Unlike `localeInStorage`, read on first call rather than at import, then
|
|
9
|
+
* cached until the next `setLocaleInStorage`. Never cached on the server.
|
|
7
10
|
*/
|
|
11
|
+
const getLocaleInStorage = _intlayer_core_utils.getCachedLocaleFromStorageClient;
|
|
8
12
|
/**
|
|
9
13
|
* Get the locale cookie
|
|
14
|
+
*
|
|
15
|
+
* Read once at import time; marked pure so bundlers drop the read when nothing
|
|
16
|
+
* imports it.
|
|
10
17
|
*/
|
|
11
|
-
const localeInStorage = (0, _intlayer_core_utils.getLocaleFromStorageClient)(_intlayer_core_utils.localeStorageOptions);
|
|
18
|
+
const localeInStorage = /* @__PURE__ */ (0, _intlayer_core_utils.getLocaleFromStorageClient)(_intlayer_core_utils.localeStorageOptions);
|
|
12
19
|
/**
|
|
13
20
|
* @deprecated Use localeInStorage instead
|
|
14
21
|
*
|
|
@@ -51,6 +58,7 @@ const useLocaleCookie = (isCookieEnabled) => {
|
|
|
51
58
|
};
|
|
52
59
|
|
|
53
60
|
//#endregion
|
|
61
|
+
exports.getLocaleInStorage = getLocaleInStorage;
|
|
54
62
|
exports.localeCookie = localeCookie;
|
|
55
63
|
exports.localeInStorage = localeInStorage;
|
|
56
64
|
exports.setLocaleCookie = setLocaleCookie;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocaleStorage.cjs","names":["
|
|
1
|
+
{"version":3,"file":"useLocaleStorage.cjs","names":["getCachedLocaleFromStorageClient","localeStorageOptions","setLocaleInStorageCore","LocaleStorageClient"],"sources":["../../../src/client/useLocaleStorage.ts"],"sourcesContent":["import {\n getCachedLocaleFromStorageClient,\n getLocaleFromStorageClient,\n LocaleStorageClient,\n localeStorageOptions,\n setLocaleInStorageClient as setLocaleInStorageCore,\n} from '@intlayer/core/utils';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\n/**\n * Reads the locale persisted in the browser storage (cookie, localStorage…).\n *\n * Unlike `localeInStorage`, read on first call rather than at import, then\n * cached until the next `setLocaleInStorage`. Never cached on the server.\n */\nexport const getLocaleInStorage = getCachedLocaleFromStorageClient;\n\n/**\n * Get the locale cookie\n *\n * Read once at import time; marked pure so bundlers drop the read when nothing\n * imports it.\n */\nexport const localeInStorage =\n /* @__PURE__ */ getLocaleFromStorageClient(localeStorageOptions);\n/**\n * @deprecated Use localeInStorage instead\n *\n * Get the locale cookie\n */\nexport const localeCookie = localeInStorage;\n\n/**\n * Set the locale cookie\n */\nexport const setLocaleInStorage = (\n locale: LocalesValues,\n isCookieEnabled: boolean\n) =>\n setLocaleInStorageCore(locale, {\n ...localeStorageOptions,\n isCookieEnabled,\n });\n\n/**\n * @deprecated Use setLocaleInStorage instead\n *\n * Set the locale cookie\n */\nexport const setLocaleCookie = setLocaleInStorage;\n\n/**\n * Hook that provides the locale storage and a function to set it\n */\nexport const useLocaleStorage = (isCookieEnabled?: boolean) =>\n LocaleStorageClient({\n ...localeStorageOptions,\n isCookieEnabled,\n });\n\n/**\n * @deprecated Use useLocaleStorage instead\n *\n * For GDPR compliance, use useLocaleStorage instead\n *\n * Hook that provides the locale cookie and a function to set it\n */\nexport const useLocaleCookie = (isCookieEnabled?: boolean) => {\n const storage = useLocaleStorage(isCookieEnabled);\n\n return {\n localeCookie: storage.getLocale(),\n setLocaleCookie: storage.setLocale,\n };\n};\n"],"mappings":";;;;;;;;;;AAeA,MAAa,qBAAqBA;;;;;;;AAQlC,MAAa,kBACK,qEAA2BC,yCAAoB;;;;;;AAMjE,MAAa,eAAe;;;;AAK5B,MAAa,sBACX,QACA,wBAEAC,+CAAuB,QAAQ;CAC7B,GAAGD;CACH;AACF,CAAC;;;;;;AAOH,MAAa,kBAAkB;;;;AAK/B,MAAa,oBAAoB,wBAC/BE,0CAAoB;CAClB,GAAGF;CACH;AACF,CAAC;;;;;;;;AASH,MAAa,mBAAmB,oBAA8B;CAC5D,MAAM,UAAU,iBAAiB,eAAe;CAEhD,OAAO;EACL,cAAc,QAAQ,UAAU;EAChC,iBAAiB,QAAQ;CAC3B;AACF"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_esbuild_hiddenDirectory = require('./hiddenDirectory.cjs');
|
|
3
3
|
const require_esbuild_resolvePackageExport = require('./resolvePackageExport.cjs');
|
|
4
|
+
let node_module = require("node:module");
|
|
4
5
|
let node_path = require("node:path");
|
|
6
|
+
let _intlayer_config_node = require("@intlayer/config/node");
|
|
7
|
+
let _intlayer_config_utils = require("@intlayer/config/utils");
|
|
5
8
|
let node_fs_promises = require("node:fs/promises");
|
|
6
|
-
let node_module = require("node:module");
|
|
7
9
|
let _intlayer_config_dictionaryPreload = require("@intlayer/config/dictionaryPreload");
|
|
8
10
|
let _intlayer_config_envVars = require("@intlayer/config/envVars");
|
|
9
11
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
10
|
-
let _intlayer_config_node = require("@intlayer/config/node");
|
|
11
|
-
let _intlayer_config_utils = require("@intlayer/config/utils");
|
|
12
12
|
let _intlayer_dictionaries_entry = require("@intlayer/dictionaries-entry");
|
|
13
13
|
let _intlayer_engine_build = require("@intlayer/engine/build");
|
|
14
14
|
let _intlayer_engine_cli = require("@intlayer/engine/cli");
|
package/dist/cjs/plugins.cjs
CHANGED
|
@@ -63,21 +63,21 @@ const compileToHtml = (source, components) => {
|
|
|
63
63
|
const intlayerNodePlugins = {
|
|
64
64
|
id: "intlayer-node-plugin",
|
|
65
65
|
canHandle: (node) => typeof node === "bigint" || typeof node === "string" || typeof node === "number",
|
|
66
|
-
transform: (_node,
|
|
66
|
+
transform: (_node, props) => {
|
|
67
|
+
const { children, dictionaryKey, keyPath } = props;
|
|
67
68
|
if (process.env.INTLAYER_ANALYTICS_ENABLED !== "false") require_analytics_exposureSink.reportExposure({
|
|
68
|
-
dictionaryKey
|
|
69
|
-
keyPath
|
|
70
|
-
locale:
|
|
69
|
+
dictionaryKey,
|
|
70
|
+
keyPath,
|
|
71
|
+
locale: props.locale,
|
|
71
72
|
nodeType: "text"
|
|
72
73
|
});
|
|
73
74
|
return require_renderIntlayerNode.renderIntlayerNode({
|
|
74
|
-
...rest,
|
|
75
75
|
value: children,
|
|
76
76
|
children: () => ({
|
|
77
77
|
component: process.env.INTLAYER_EDITOR_ENABLED === "false" || !_intlayer_config_built.editor.enabled ? children : require_editor_ContentSelector_component.ContentSelectorWrapperComponent,
|
|
78
78
|
props: {
|
|
79
|
-
dictionaryKey
|
|
80
|
-
keyPath
|
|
79
|
+
dictionaryKey,
|
|
80
|
+
keyPath
|
|
81
81
|
},
|
|
82
82
|
children
|
|
83
83
|
})
|
|
@@ -104,34 +104,32 @@ const markdownStringPlugin = process.env.INTLAYER_NODE_TYPE_MARKDOWN === "false"
|
|
|
104
104
|
keyPath: []
|
|
105
105
|
});
|
|
106
106
|
const renderMarkdown = (components) => (0, _angular_core.untracked)(markdownRendererModule)?.useMarkdown().renderMarkdown(node, components) ?? node;
|
|
107
|
-
const render = (components) =>
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
} });
|
|
134
|
-
return createProxy(render());
|
|
107
|
+
const render = (components) => {
|
|
108
|
+
const toHtml = () => compileToHtml(node, components);
|
|
109
|
+
return require_renderIntlayerNode.renderIntlayerNode({
|
|
110
|
+
...rest,
|
|
111
|
+
value: node,
|
|
112
|
+
children: process.env.INTLAYER_EDITOR_ENABLED === "false" || !_intlayer_config_built.editor.enabled ? () => renderMarkdown(components) : () => ({
|
|
113
|
+
component: require_editor_ContentSelector_component.ContentSelectorWrapperComponent,
|
|
114
|
+
props: {
|
|
115
|
+
dictionaryKey: rest.dictionaryKey,
|
|
116
|
+
keyPath: rest.keyPath,
|
|
117
|
+
...components
|
|
118
|
+
},
|
|
119
|
+
children: () => renderMarkdown(components)
|
|
120
|
+
}),
|
|
121
|
+
additionalProps: {
|
|
122
|
+
metadata: metadataNodes,
|
|
123
|
+
toString: toHtml,
|
|
124
|
+
[Symbol.toPrimitive]: toHtml,
|
|
125
|
+
use: (newComponents) => render({
|
|
126
|
+
...components,
|
|
127
|
+
...newComponents
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
return render();
|
|
135
133
|
}
|
|
136
134
|
};
|
|
137
135
|
const markdownPlugin = process.env.INTLAYER_NODE_TYPE_MARKDOWN === "false" ? _intlayer_core_interpreter.fallbackPlugin : {
|
|
@@ -155,35 +153,31 @@ const htmlPlugin = process.env.INTLAYER_NODE_TYPE_HTML === "false" ? _intlayer_c
|
|
|
155
153
|
transform: (node, props) => {
|
|
156
154
|
const html = node[_intlayer_types_nodeType.HTML];
|
|
157
155
|
const { plugins, ...rest } = props;
|
|
158
|
-
const render = (userComponents) =>
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
};
|
|
184
|
-
return Reflect.get(target, prop, receiver);
|
|
185
|
-
} });
|
|
186
|
-
return createProxy(render());
|
|
156
|
+
const render = (userComponents) => {
|
|
157
|
+
const toHtml = () => !userComponents || Object.keys(userComponents).length === 0 ? String(html) : compileToHtml(String(html), userComponents);
|
|
158
|
+
return require_renderIntlayerNode.renderIntlayerNode({
|
|
159
|
+
...rest,
|
|
160
|
+
value: html,
|
|
161
|
+
children: process.env.INTLAYER_EDITOR_ENABLED === "false" || !_intlayer_config_built.editor.enabled ? html : () => ({
|
|
162
|
+
component: require_editor_ContentSelector_component.ContentSelectorWrapperComponent,
|
|
163
|
+
props: {
|
|
164
|
+
dictionaryKey: rest.dictionaryKey,
|
|
165
|
+
keyPath: rest.keyPath,
|
|
166
|
+
...userComponents
|
|
167
|
+
},
|
|
168
|
+
children: html
|
|
169
|
+
}),
|
|
170
|
+
additionalProps: {
|
|
171
|
+
toString: toHtml,
|
|
172
|
+
[Symbol.toPrimitive]: toHtml,
|
|
173
|
+
use: (newComponents) => render({
|
|
174
|
+
...userComponents,
|
|
175
|
+
...newComponents
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
return render();
|
|
187
181
|
}
|
|
188
182
|
};
|
|
189
183
|
const insertionPlugin = process.env.INTLAYER_NODE_TYPE_INSERTION === "false" ? _intlayer_core_interpreter.fallbackPlugin : {
|
|
@@ -241,7 +235,8 @@ const pluginsCache = /* @__PURE__ */ new Map();
|
|
|
241
235
|
const getPlugins = (locale, fallback = true) => {
|
|
242
236
|
const cacheKey = `${locale ?? _intlayer_config_built.internationalization.defaultLocale}_${fallback}_${markdownRendererModule() !== null}`;
|
|
243
237
|
if (pluginsCache.has(cacheKey)) return pluginsCache.get(cacheKey);
|
|
244
|
-
const
|
|
238
|
+
const enabledPlugins = [
|
|
239
|
+
intlayerNodePlugins,
|
|
245
240
|
(0, _intlayer_core_interpreter.translationPlugin)(locale ?? _intlayer_config_built.internationalization.defaultLocale, fallback ? _intlayer_config_built.internationalization.defaultLocale : void 0),
|
|
246
241
|
_intlayer_core_interpreter.enumerationPlugin,
|
|
247
242
|
(0, _intlayer_core_interpreter.pluralPlugin)(locale ?? _intlayer_config_built.internationalization.defaultLocale),
|
|
@@ -250,13 +245,12 @@ const getPlugins = (locale, fallback = true) => {
|
|
|
250
245
|
_intlayer_core_interpreter.filePlugin,
|
|
251
246
|
_intlayer_core_interpreter.genderPlugin,
|
|
252
247
|
_intlayer_core_interpreter.selectPlugin,
|
|
253
|
-
intlayerNodePlugins,
|
|
254
248
|
markdownPlugin,
|
|
255
249
|
htmlPlugin,
|
|
256
250
|
insertionPlugin
|
|
257
|
-
];
|
|
258
|
-
pluginsCache.set(cacheKey,
|
|
259
|
-
return
|
|
251
|
+
].filter((plugin) => plugin !== _intlayer_core_interpreter.fallbackPlugin);
|
|
252
|
+
pluginsCache.set(cacheKey, enabledPlugins);
|
|
253
|
+
return enabledPlugins;
|
|
260
254
|
};
|
|
261
255
|
|
|
262
256
|
//#endregion
|
package/dist/cjs/plugins.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.cjs","names":["signal","untracked","compile","renderIntlayerNode","editor","ContentSelectorWrapperComponent","fallbackPlugin","getMarkdownMetadata","NodeTypes","isInterpolableWrapperNode","transformInterpolableNode","getInsertion","bindInsertedValues","internationalization","translationPlugin","enumerationPlugin","pluralPlugin","conditionPlugin","nestedPlugin","filePlugin","genderPlugin","selectPlugin"],"sources":["../../src/plugins.ts"],"sourcesContent":["import { signal, untracked } from '@angular/core';\nimport { editor, internationalization } from '@intlayer/config/built';\nimport {\n bindInsertedValues,\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n fallbackPlugin,\n filePlugin,\n genderPlugin,\n getInsertion,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n isInterpolableWrapperNode,\n nestedPlugin,\n type Plugins,\n pluralPlugin,\n selectPlugin,\n transformInterpolableNode,\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\ntype MarkdownRendererModule = Pick<\n typeof import('./markdown/installIntlayerMarkdown'),\n 'htmlRuntime' | 'useMarkdown'\n>;\n\n/**\n * Code-split markdown renderer, held in a signal.\n *\n * The chunk loads asynchronously, so the first dictionary evaluation may run\n * before it lands. `getPlugins` reads this signal inside the `computed` of\n * `useIntlayer`/`useDictionary`, which makes that computed depend on it: nodes\n * stringify to their raw source until the module resolves, then the signal\n * flip re-evaluates the dictionary and every binding re-renders with compiled\n * HTML. This is the Angular counterpart of the `Suspense` boundary the React\n * and Solid packages wrap their markdown renderer in.\n */\nconst markdownRendererModule = signal<MarkdownRendererModule | null>(null);\n\nif (\n process.env.INTLAYER_NODE_TYPE_MARKDOWN !== 'false' ||\n process.env.INTLAYER_NODE_TYPE_HTML !== 'false'\n) {\n void import('./markdown/installIntlayerMarkdown')\n .then((module) => markdownRendererModule.set(module))\n .catch(() => {});\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 * Compiles a markdown/HTML source to an HTML string with the code-split\n * runtime, or returns the raw source while the renderer chunk is still\n * loading. Runs at stringify time, so a node kept outside any reactive\n * context still picks the renderer up once it has landed.\n */\nconst compileToHtml = (\n source: string,\n components?: Record<string, unknown>\n): string => {\n const rendererModule = untracked(markdownRendererModule);\n\n if (!rendererModule) return source;\n\n const runtime = components\n ? createRuntimeWithOverides(rendererModule.htmlRuntime, components)\n : rendererModule.htmlRuntime;\n\n return compile(source, { runtime }) as string;\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 renderMarkdown = (components?: any) =>\n untracked(markdownRendererModule)\n ?.useMarkdown()\n .renderMarkdown(node, components) ?? node;\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 ? () => renderMarkdown(components)\n : () => ({\n component: ContentSelectorWrapperComponent,\n props: {\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n ...components,\n },\n children: () => renderMarkdown(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' || prop === Symbol.toPrimitive) {\n return () => compileToHtml(node, components);\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' || prop === Symbol.toPrimitive) {\n return () => {\n // Without component overrides the source is already HTML.\n if (!components || Object.keys(components).length === 0) {\n return String(html);\n }\n\n return compileToHtml(String(html), components);\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, S, L extends LocalesValues> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer Content;\n}\n ? (\n args: Record<string, string | number>\n ) => Content extends string\n ? string\n : DeepTransformContentCore<Content, S, L>\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, deepTransformNode) => {\n const { plugins, ...rest } = props;\n const content = node[NodeTypes.INSERTION];\n\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.INSERTION,\n },\n ];\n\n // `html()`/`markdown()` nodes carry their `{{ … }}` placeholders\n // inside a raw string. Interpolate into that string, then re-run the\n // transform so the html/markdown renderer applies afterwards.\n if (isInterpolableWrapperNode(content)) {\n return (args: Record<string, string | number> = {}) =>\n transformInterpolableNode(\n content,\n args,\n { ...props, keyPath: newKeyPath },\n props.plugins,\n deepTransformNode\n );\n }\n\n // Container content (`insert(enu(…))`, `insert(plural(…))`, …):\n // interpolate every branch string, then bind the values to the\n // selector so the call reads `(values) => (selector) => content`.\n if (typeof content === 'object' && content !== null) {\n return (args: Record<string, string | number> = {}) => {\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (branch) =>\n typeof branch === 'string' ||\n isInterpolableWrapperNode(branch),\n transform: (branch, subProps, deepTransformBranch) => {\n if (isInterpolableWrapperNode(branch)) {\n return transformInterpolableNode(\n branch,\n args,\n subProps,\n plugins,\n deepTransformBranch\n );\n }\n\n const interpolated = getInsertion(branch, args);\n\n return deepTransformBranch(interpolated, {\n ...subProps,\n children: interpolated,\n plugins,\n });\n },\n };\n\n const result = deepTransformNode(content, {\n ...props,\n children: content,\n keyPath: [...props.keyPath, { type: NodeTypes.INSERTION }],\n plugins: [insertionStringPlugin, ...(plugins ?? [])],\n });\n\n return bindInsertedValues(content, result, args, true);\n };\n }\n\n // Return a function that performs the interpolation\n const render = (args: Record<string, string | number> = {}) => {\n let text = content 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, S, L>;\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 // Tracked read: called inside the dictionary `computed` of the hooks, so the\n // computed re-evaluates once the renderer chunk lands. The core interpreter\n // memoizes transformed content per plugin-array identity, and the transform\n // itself is lazy (property getters resolved from the template), so handing\n // out a fresh array is what discards the proxies built while pending and\n // gives every binding a new value to re-render.\n const isRendererLoaded = markdownRendererModule() !== null;\n const cacheKey = `${currentLocale}_${fallback}_${isRendererLoaded}`;\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 selectPlugin,\n intlayerNodePlugins,\n markdownPlugin,\n htmlPlugin,\n insertionPlugin,\n ] as Plugins[];\n\n pluginsCache.set(cacheKey, plugins);\n\n return plugins;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAkDA,MAAM,6BAAyBA,sBAAsC,IAAI;AAEzE,IACE,QAAQ,IAAI,gCAAgC,WAC5C,QAAQ,IAAI,4BAA4B,SAExC,qCAAK,2CACF,MAAM,WAAW,uBAAuB,IAAI,MAAM,CAAC,CAAC,CACpD,YAAY,CAAC,CAAC;;;;AAOnB,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,SAAS,SAAS,SAAS;GAEjD,IAAI,iBAAiB,eAAe;IAClC,SAAS,QAAQ,GAAG,cAAc,GAAG;IACrC,SAAS,YAAY;GACvB;GAEA,OAAO,YAAY,cAAc,KAAK,UAAU,GAAG,QAAQ;EAC7D;EAEA,OAAO,YAAY,cAAc,KAAK,OAAO,GAAG,QAAQ;CAC1D;AACF;;;;;;;AAQA,MAAM,iBACJ,QACA,eACW;CACX,MAAM,qBAAiBC,yBAAU,sBAAsB;CAEvD,IAAI,CAAC,gBAAgB,OAAO;CAE5B,MAAM,UAAU,aACZ,0BAA0B,eAAe,aAAa,UAAU,IAChE,eAAe;CAEnB,WAAOC,iCAAQ,QAAQ,EAAE,QAAQ,CAAC;AACpC;;AAiBA,MAAa,sBAA+B;CAC1C,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAChB,OAAO,SAAS,YAChB,OAAO,SAAS;CAClB,YAAY,OAAO,EAAE,UAAU,GAAG,WAAW;EAG3C,IAAI,QAAQ,IAA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a,QAAQ,IAAI;KAE9C,OAAO,oBAAoB,cAAc;MACvC,GAAG;MACH,UAAU;MACV;KACF,CAAC;IACH;GACF;GAEA,MAAM,SAAS,kBAAkB,SAAS;IACxC,GAAG;IACH,UAAU;IACV,SAAS,CAAC,GAAG,MAAM,SAAS,EAAE,MAAMH,yBAAU,UAAU,CAAC;IACzD,SAAS,CAAC,uBAAuB,GAAI,WAAW,CAAC,CAAE;GACrD,CAAC;GAED,WAAOI,+CAAmB,SAAS,QAAQ,MAAM,IAAI;EACvD;EAIF,MAAM,UAAU,OAAwC,CAAC,MAAM;GAC7D,IAAI,OAAO;GACX,IAAI,MACF,OAAO,QAAQ,IAAI,CAAC,CAAC,SAAS,CAAC,KAAK,WAAW;IAC7C,OAAO,KAAK,QACV,IAAI,OAAO,SAAS,IAAI,SAAS,GAAG,GACpC,OAAO,KAAK,CACd;GACF,CAAC;GAEH,OAAO;EACT;EAEA,OAAOT,8CAAmB;GACxB,GAAG;GACH,OAAO;GACP,UAAU;EACZ,CAAC;CACH;AACF;AA6BN,MAAM,+BAAe,IAAI,IAAuB;;;;;AAMhD,MAAa,cACX,QACA,WAAoB,SACN;CASd,MAAM,WAAW,GARK,UAAUU,4CAAqB,cAQnB,GAAG,SAAS,GADrB,uBAAuB,MAAM;CAGtD,IAAI,aAAa,IAAI,QAAQ,GAC3B,OAAO,aAAa,IAAI,QAAQ;CAGlC,MAAM,UAAU;MACdC,8CACE,UAAUD,4CAAqB,eAC/B,WAAWA,4CAAqB,gBAAgB,MAClD;EACAE;MACAC,yCAAa,UAAUH,4CAAqB,aAAa;EACzDI;MACAC,yCAAa,UAAUL,4CAAqB,aAAa;EACzDM;EACAC;EACAC;EACA;EACA;EACA;EACA;CACF;CAEA,aAAa,IAAI,UAAU,OAAO;CAElC,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"plugins.cjs","names":["signal","untracked","compile","renderIntlayerNode","editor","ContentSelectorWrapperComponent","fallbackPlugin","getMarkdownMetadata","NodeTypes","isInterpolableWrapperNode","transformInterpolableNode","getInsertion","bindInsertedValues","internationalization","translationPlugin","enumerationPlugin","pluralPlugin","conditionPlugin","nestedPlugin","filePlugin","genderPlugin","selectPlugin"],"sources":["../../src/plugins.ts"],"sourcesContent":["import { signal, untracked } from '@angular/core';\nimport { editor, internationalization } from '@intlayer/config/built';\nimport {\n bindInsertedValues,\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n fallbackPlugin,\n filePlugin,\n genderPlugin,\n getInsertion,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n isInterpolableWrapperNode,\n nestedPlugin,\n type Plugins,\n pluralPlugin,\n selectPlugin,\n transformInterpolableNode,\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 { type IntlayerNode, renderIntlayerNode } from './renderIntlayerNode';\n\ntype MarkdownRendererModule = Pick<\n typeof import('./markdown/installIntlayerMarkdown'),\n 'htmlRuntime' | 'useMarkdown'\n>;\n\n/**\n * Code-split markdown renderer, held in a signal.\n *\n * The chunk loads asynchronously, so the first dictionary evaluation may run\n * before it lands. `getPlugins` reads this signal inside the `computed` of\n * `useIntlayer`/`useDictionary`, which makes that computed depend on it: nodes\n * stringify to their raw source until the module resolves, then the signal\n * flip re-evaluates the dictionary and every binding re-renders with compiled\n * HTML. This is the Angular counterpart of the `Suspense` boundary the React\n * and Solid packages wrap their markdown renderer in.\n */\nconst markdownRendererModule = signal<MarkdownRendererModule | null>(null);\n\nif (\n process.env.INTLAYER_NODE_TYPE_MARKDOWN !== 'false' ||\n process.env.INTLAYER_NODE_TYPE_HTML !== 'false'\n) {\n void import('./markdown/installIntlayerMarkdown')\n .then((module) => markdownRendererModule.set(module))\n .catch(() => {});\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 * Compiles a markdown/HTML source to an HTML string with the code-split\n * runtime, or returns the raw source while the renderer chunk is still\n * loading. Runs at stringify time, so a node kept outside any reactive\n * context still picks the renderer up once it has landed.\n */\nconst compileToHtml = (\n source: string,\n components?: Record<string, unknown>\n): string => {\n const rendererModule = untracked(markdownRendererModule);\n\n if (!rendererModule) return source;\n\n const runtime = components\n ? createRuntimeWithOverides(rendererModule.htmlRuntime, components)\n : rendererModule.htmlRuntime;\n\n return compile(source, { runtime }) as string;\n};\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\nexport type { IntlayerNode };\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, props) => {\n const { children, dictionaryKey, keyPath } = props;\n\n // Node-level analytics: record which content is resolved for display.\n // No-op (and dead-code-eliminated) when analytics is disabled.\n if (process.env.INTLAYER_ANALYTICS_ENABLED !== 'false') {\n reportExposure({\n dictionaryKey,\n keyPath,\n locale: props.locale,\n nodeType: 'text',\n });\n }\n\n return renderIntlayerNode({\n value: children,\n children: () => ({\n component:\n process.env.INTLAYER_EDITOR_ENABLED === 'false' || !editor.enabled\n ? children\n : ContentSelectorWrapperComponent,\n props: { dictionaryKey, keyPath },\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 renderMarkdown = (components?: any) =>\n untracked(markdownRendererModule)\n ?.useMarkdown()\n .renderMarkdown(node, components) ?? node;\n\n const render = (components?: any): any => {\n const toHtml = () => compileToHtml(node, components);\n\n return renderIntlayerNode({\n ...rest,\n value: node,\n children:\n process.env.INTLAYER_EDITOR_ENABLED === 'false' ||\n !editor.enabled\n ? () => renderMarkdown(components)\n : () => ({\n component: ContentSelectorWrapperComponent,\n props: {\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n ...components,\n },\n children: () => renderMarkdown(components),\n }),\n additionalProps: {\n metadata: metadataNodes,\n toString: toHtml,\n [Symbol.toPrimitive]: toHtml,\n use: (newComponents?: any) =>\n render({ ...components, ...newComponents }),\n },\n });\n };\n\n return render();\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): any => {\n // Without component overrides the source is already HTML\n const toHtml = () =>\n !userComponents || Object.keys(userComponents).length === 0\n ? String(html)\n : compileToHtml(String(html), userComponents);\n\n return 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 additionalProps: {\n toString: toHtml,\n [Symbol.toPrimitive]: toHtml,\n use: (newComponents?: any) =>\n render({ ...userComponents, ...newComponents }),\n },\n });\n };\n\n return render();\n },\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\n/**\n * Insertion conditional type.\n */\nexport type InsertionPluginCond<T, S, L extends LocalesValues> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer Content;\n}\n ? (\n args: Record<string, string | number>\n ) => Content extends string\n ? string\n : DeepTransformContentCore<Content, S, L>\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, deepTransformNode) => {\n const { plugins, ...rest } = props;\n const content = node[NodeTypes.INSERTION];\n\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.INSERTION,\n },\n ];\n\n // `html()`/`markdown()` nodes carry their `{{ … }}` placeholders\n // inside a raw string. Interpolate into that string, then re-run the\n // transform so the html/markdown renderer applies afterwards.\n if (isInterpolableWrapperNode(content)) {\n return (args: Record<string, string | number> = {}) =>\n transformInterpolableNode(\n content,\n args,\n { ...props, keyPath: newKeyPath },\n props.plugins,\n deepTransformNode\n );\n }\n\n // Container content (`insert(enu(…))`, `insert(plural(…))`, …):\n // interpolate every branch string, then bind the values to the\n // selector so the call reads `(values) => (selector) => content`.\n if (typeof content === 'object' && content !== null) {\n return (args: Record<string, string | number> = {}) => {\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (branch) =>\n typeof branch === 'string' ||\n isInterpolableWrapperNode(branch),\n transform: (branch, subProps, deepTransformBranch) => {\n if (isInterpolableWrapperNode(branch)) {\n return transformInterpolableNode(\n branch,\n args,\n subProps,\n plugins,\n deepTransformBranch\n );\n }\n\n const interpolated = getInsertion(branch, args);\n\n return deepTransformBranch(interpolated, {\n ...subProps,\n children: interpolated,\n plugins,\n });\n },\n };\n\n const result = deepTransformNode(content, {\n ...props,\n children: content,\n keyPath: [...props.keyPath, { type: NodeTypes.INSERTION }],\n plugins: [insertionStringPlugin, ...(plugins ?? [])],\n });\n\n return bindInsertedValues(content, result, args, true);\n };\n }\n\n // Return a function that performs the interpolation\n const render = (args: Record<string, string | number> = {}) => {\n let text = content 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, S, L>;\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 // Tracked read: called inside the dictionary `computed` of the hooks, so the\n // computed re-evaluates once the renderer chunk lands. The core interpreter\n // memoizes transformed content per plugin-array identity, and the transform\n // itself is lazy (property getters resolved from the template), so handing\n // out a fresh array is what discards the proxies built while pending and\n // gives every binding a new value to re-render.\n const isRendererLoaded = markdownRendererModule() !== null;\n const cacheKey = `${currentLocale}_${fallback}_${isRendererLoaded}`;\n\n if (pluginsCache.has(cacheKey)) {\n return pluginsCache.get(cacheKey)!;\n }\n\n const plugins = [\n // First: most nodes are plain strings, which every other plugin rejects\n intlayerNodePlugins,\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 selectPlugin,\n markdownPlugin,\n htmlPlugin,\n insertionPlugin,\n ] as Plugins[];\n\n // Plugins disabled at build time never match: skip them on every node\n const enabledPlugins = plugins.filter((plugin) => plugin !== fallbackPlugin);\n\n pluginsCache.set(cacheKey, enabledPlugins);\n\n return enabledPlugins;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAkDA,MAAM,6BAAyBA,sBAAsC,IAAI;AAEzE,IACE,QAAQ,IAAI,gCAAgC,WAC5C,QAAQ,IAAI,4BAA4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AAa,IAAI,QAAQ;CAuBlC,MAAM,iBAAiB;EAlBrB;MACAC,8CACE,UAAUD,4CAAqB,eAC/B,WAAWA,4CAAqB,gBAAgB,MAClD;EACAE;MACAC,yCAAa,UAAUH,4CAAqB,aAAa;EACzDI;MACAC,yCAAa,UAAUL,4CAAqB,aAAa;EACzDM;EACAC;EACAC;EACA;EACA;EACA;CAI2B,CAAC,CAAC,QAAQ,WAAW,WAAWf,yCAAc;CAE3E,aAAa,IAAI,UAAU,cAAc;CAEzC,OAAO;AACT"}
|
|
@@ -1,42 +1,23 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _intlayer_core_utils = require("@intlayer/core/utils");
|
|
3
|
+
|
|
2
4
|
//#region src/renderIntlayerNode.ts
|
|
5
|
+
/**
|
|
6
|
+
* Builds a node that renders its content and also behaves like its value
|
|
7
|
+
* (`node.value`, `${node}`, `node.toUpperCase()`), through a shared prototype
|
|
8
|
+
* rather than a Proxy.
|
|
9
|
+
*
|
|
10
|
+
* @param props - The value, the rendered content and extra node members.
|
|
11
|
+
* @returns The node.
|
|
12
|
+
*/
|
|
3
13
|
const renderIntlayerNode = ({ children, value, additionalProps = {} }) => {
|
|
4
|
-
if (children
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const valObj = Object(value);
|
|
12
|
-
if (prop in valObj) {
|
|
13
|
-
const valProp = valObj[prop];
|
|
14
|
-
return typeof valProp === "function" ? valProp.bind(value) : valProp;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return Reflect.get(target, prop, receiver);
|
|
18
|
-
} });
|
|
19
|
-
return new Proxy(typeof children === "object" || typeof children === "function" ? children : {}, {
|
|
20
|
-
apply(target, thisArg, argumentsList) {
|
|
21
|
-
if (typeof value === "function") return Reflect.apply(value, thisArg, argumentsList);
|
|
22
|
-
return Reflect.apply(target, thisArg, argumentsList);
|
|
23
|
-
},
|
|
24
|
-
get(target, prop, receiver) {
|
|
25
|
-
if (prop === "value") return value;
|
|
26
|
-
if (prop === Symbol.toPrimitive) return () => value ?? "";
|
|
27
|
-
if (prop === "toString") return () => String(value ?? "");
|
|
28
|
-
if (prop === "valueOf") return () => value;
|
|
29
|
-
if (additionalProps && prop in additionalProps) return additionalProps[prop];
|
|
30
|
-
if (value !== null && value !== void 0 && typeof prop === "string" && prop !== "constructor" && !(prop in target)) {
|
|
31
|
-
const valObj = Object(value);
|
|
32
|
-
if (prop in valObj) {
|
|
33
|
-
const valProp = valObj[prop];
|
|
34
|
-
return typeof valProp === "function" ? valProp.bind(value) : valProp;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return Reflect.get(target, prop, receiver);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
14
|
+
if (typeof children !== "function") return Object.setPrototypeOf({
|
|
15
|
+
...typeof children === "object" ? children : {},
|
|
16
|
+
...additionalProps,
|
|
17
|
+
value
|
|
18
|
+
}, (0, _intlayer_core_utils.getIntlayerNodePrototype)(value));
|
|
19
|
+
Object.assign(children, additionalProps, { value });
|
|
20
|
+
return Object.setPrototypeOf(children, (0, _intlayer_core_utils.getIntlayerNodePrototype)(value, Function.prototype));
|
|
40
21
|
};
|
|
41
22
|
|
|
42
23
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderIntlayerNode.cjs","names":[],"sources":["../../src/renderIntlayerNode.ts"],"sourcesContent":["import type { ResolvedEditor } from '@intlayer/types/module_augmentation';\n\
|
|
1
|
+
{"version":3,"file":"renderIntlayerNode.cjs","names":["getIntlayerNodePrototype"],"sources":["../../src/renderIntlayerNode.ts"],"sourcesContent":["import { getIntlayerNodePrototype } from '@intlayer/core/utils';\nimport type { ResolvedEditor } from '@intlayer/types/module_augmentation';\n\n/**\n * Content node returned by `useIntlayer`.\n *\n * Without the editor it is typed as its value (`\"Hello\" & { value: \"Hello\" }`)\n * so it can be bound straight to string inputs and attributes. With the\n * editor, it must be rendered through `<intlayer-node>`, so string bindings\n * must use `.value`.\n */\nexport type IntlayerNode<\n T = string,\n AdditionalProps = unknown,\n> = ResolvedEditor<\n T & { value: T } & AdditionalProps,\n IntlayerNodeRenderer & { value: T } & AdditionalProps\n>;\n\n/** Renderer the node is built on, consumed by `<intlayer-node>`. */\ntype IntlayerNodeRenderer = () => unknown;\n\ntype RenderIntlayerNodeProps<T> = {\n value: T;\n children: any;\n additionalProps?: { [key: string]: any };\n};\n\n/**\n * Builds a node that renders its content and also behaves like its value\n * (`node.value`, `${node}`, `node.toUpperCase()`), through a shared prototype\n * rather than a Proxy.\n *\n * @param props - The value, the rendered content and extra node members.\n * @returns The node.\n */\nexport const renderIntlayerNode = <\n T, // Broadened to support arrays, numbers, objects, etc.\n>({\n children,\n value,\n additionalProps = {},\n}: RenderIntlayerNodeProps<T>): IntlayerNode<T> => {\n // Callable content (renderers built by the plugins) stays callable; any other\n // content becomes a plain object node\n if (typeof children !== 'function') {\n return Object.setPrototypeOf(\n {\n ...(typeof children === 'object' ? children : {}),\n ...additionalProps,\n value,\n },\n getIntlayerNodePrototype(value)\n );\n }\n\n Object.assign(children, additionalProps, { value });\n\n // Serves the value's members, after the assignments above so they never\n // walk a Proxy in the prototype chain\n return Object.setPrototypeOf(\n children,\n getIntlayerNodePrototype(value, Function.prototype)\n );\n};\n"],"mappings":";;;;;;;;;;;;AAoCA,MAAa,sBAEX,EACA,UACA,OACA,kBAAkB,CAAC,QAC8B;CAGjD,IAAI,OAAO,aAAa,YACtB,OAAO,OAAO,eACZ;EACE,GAAI,OAAO,aAAa,WAAW,WAAW,CAAC;EAC/C,GAAG;EACH;CACF,OACAA,+CAAyB,KAAK,CAChC;CAGF,OAAO,OAAO,UAAU,iBAAiB,EAAE,MAAM,CAAC;CAIlD,OAAO,OAAO,eACZ,cACAA,+CAAyB,OAAO,SAAS,SAAS,CACpD;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
let node_path = require("node:path");
|
|
3
2
|
let node_module = require("node:module");
|
|
3
|
+
let node_path = require("node:path");
|
|
4
4
|
let _intlayer_config_node = require("@intlayer/config/node");
|
|
5
5
|
let _intlayer_config_utils = require("@intlayer/config/utils");
|
|
6
6
|
let _intlayer_webpack = require("@intlayer/webpack");
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getLocaleInStorage } from "./useLocaleStorage.mjs";
|
|
1
2
|
import { InjectionToken, signal } from "@angular/core";
|
|
2
3
|
import { internationalization } from "@intlayer/config/built";
|
|
3
4
|
import { setIntlayerIdentifier } from "@intlayer/config/client";
|
|
@@ -34,7 +35,8 @@ let instance = null;
|
|
|
34
35
|
const createIntlayerClient = (locale, isCookieEnabled = true, variant) => {
|
|
35
36
|
if (instance) return instance;
|
|
36
37
|
instance = new IntlayerProvider();
|
|
37
|
-
|
|
38
|
+
const initialLocale = locale ?? getLocaleInStorage();
|
|
39
|
+
if (initialLocale) instance.setLocale(initialLocale);
|
|
38
40
|
if (variant !== void 0) instance.setVariant(variant);
|
|
39
41
|
instance.isCookieEnabled.set(isCookieEnabled);
|
|
40
42
|
return instance;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerToken.mjs","names":[],"sources":["../../../src/client/intlayerToken.ts"],"sourcesContent":["import { InjectionToken, type Signal, signal } from '@angular/core';\nimport { internationalization } from '@intlayer/config/built';\nimport { setIntlayerIdentifier } from '@intlayer/config/client';\nimport type {\n LocalesValues,\n ProviderVariant,\n} from '@intlayer/types/module_augmentation';\n\nexport class IntlayerProvider {\n isCookieEnabled = signal(true);\n private _locale = signal<LocalesValues>(\n internationalization.defaultLocale as LocalesValues\n );\n\n private _variant = signal<ProviderVariant | undefined>(undefined);\n\n readonly locale: Signal<LocalesValues> = this._locale.asReadonly();\n\n /**\n * Ambient variant applied to every dictionary read in the app, the same way\n * `locale` is. Overridden per call by an explicit selector.\n */\n readonly variant: Signal<ProviderVariant | undefined> =\n this._variant.asReadonly();\n\n constructor() {\n setIntlayerIdentifier();\n }\n\n setLocale = (locale: LocalesValues) => {\n this._locale.set(locale);\n };\n\n setVariant = (variant: ProviderVariant | undefined) => {\n this._variant.set(variant);\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 variant?: ProviderVariant\n): IntlayerProvider => {\n if (instance) return instance;\n\n instance = new IntlayerProvider();\n\n if (
|
|
1
|
+
{"version":3,"file":"intlayerToken.mjs","names":[],"sources":["../../../src/client/intlayerToken.ts"],"sourcesContent":["import { InjectionToken, type Signal, signal } from '@angular/core';\nimport { internationalization } from '@intlayer/config/built';\nimport { setIntlayerIdentifier } from '@intlayer/config/client';\nimport type {\n LocalesValues,\n ProviderVariant,\n} from '@intlayer/types/module_augmentation';\nimport { getLocaleInStorage } from './useLocaleStorage';\n\nexport class IntlayerProvider {\n isCookieEnabled = signal(true);\n private _locale = signal<LocalesValues>(\n internationalization.defaultLocale as LocalesValues\n );\n\n private _variant = signal<ProviderVariant | undefined>(undefined);\n\n readonly locale: Signal<LocalesValues> = this._locale.asReadonly();\n\n /**\n * Ambient variant applied to every dictionary read in the app, the same way\n * `locale` is. Overridden per call by an explicit selector.\n */\n readonly variant: Signal<ProviderVariant | undefined> =\n this._variant.asReadonly();\n\n constructor() {\n setIntlayerIdentifier();\n }\n\n setLocale = (locale: LocalesValues) => {\n this._locale.set(locale);\n };\n\n setVariant = (variant: ProviderVariant | undefined) => {\n this._variant.set(variant);\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 variant?: ProviderVariant\n): IntlayerProvider => {\n if (instance) return instance;\n\n instance = new IntlayerProvider();\n\n // Returning visitors keep their language when no locale is passed\n const initialLocale = locale ?? getLocaleInStorage();\n\n if (initialLocale) {\n instance.setLocale(initialLocale);\n }\n if (variant !== undefined) {\n instance.setVariant(variant);\n }\n instance.isCookieEnabled.set(isCookieEnabled);\n\n return instance;\n};\n"],"mappings":";;;;;;AASA,IAAa,mBAAb,MAA8B;CAC5B,kBAAkB,OAAO,IAAI;CAC7B,AAAQ,UAAU,OAChB,qBAAqB,aACvB;CAEA,AAAQ,WAAW,OAAoC,MAAS;CAEhE,AAAS,SAAgC,KAAK,QAAQ,WAAW;;;;;CAMjE,AAAS,UACP,KAAK,SAAS,WAAW;CAE3B,cAAc;EACZ,sBAAsB;CACxB;CAEA,aAAa,WAA0B;EACrC,KAAK,QAAQ,IAAI,MAAM;CACzB;CAEA,cAAc,YAAyC;EACrD,KAAK,SAAS,IAAI,OAAO;CAC3B;AACF;AAEA,MAAa,iBAAiB,IAAI,eAAiC,UAAU;;;;AAK7E,IAAI,WAAoC;;;;AAKxC,MAAa,wBACX,QACA,kBAAkB,MAClB,YACqB;CACrB,IAAI,UAAU,OAAO;CAErB,WAAW,IAAI,iBAAiB;CAGhC,MAAM,gBAAgB,UAAU,mBAAmB;CAEnD,IAAI,eACF,SAAS,UAAU,aAAa;CAElC,IAAI,YAAY,QACd,SAAS,WAAW,OAAO;CAE7B,SAAS,gBAAgB,IAAI,eAAe;CAE5C,OAAO;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { INTLAYER_TOKEN } from "./intlayerToken.mjs";
|
|
2
1
|
import { setLocaleInStorage } from "./useLocaleStorage.mjs";
|
|
2
|
+
import { INTLAYER_TOKEN } from "./intlayerToken.mjs";
|
|
3
3
|
import { computed, inject } from "@angular/core";
|
|
4
4
|
import { internationalization } from "@intlayer/config/built";
|
|
5
5
|
|
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
import { LocaleStorageClient, getLocaleFromStorageClient, localeStorageOptions, setLocaleInStorageClient } from "@intlayer/core/utils";
|
|
1
|
+
import { LocaleStorageClient, getCachedLocaleFromStorageClient, getLocaleFromStorageClient, localeStorageOptions, setLocaleInStorageClient } from "@intlayer/core/utils";
|
|
2
2
|
|
|
3
3
|
//#region src/client/useLocaleStorage.ts
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Reads the locale persisted in the browser storage (cookie, localStorage…).
|
|
6
|
+
*
|
|
7
|
+
* Unlike `localeInStorage`, read on first call rather than at import, then
|
|
8
|
+
* cached until the next `setLocaleInStorage`. Never cached on the server.
|
|
6
9
|
*/
|
|
10
|
+
const getLocaleInStorage = getCachedLocaleFromStorageClient;
|
|
7
11
|
/**
|
|
8
12
|
* Get the locale cookie
|
|
13
|
+
*
|
|
14
|
+
* Read once at import time; marked pure so bundlers drop the read when nothing
|
|
15
|
+
* imports it.
|
|
9
16
|
*/
|
|
10
|
-
const localeInStorage = getLocaleFromStorageClient(localeStorageOptions);
|
|
17
|
+
const localeInStorage = /* @__PURE__ */ getLocaleFromStorageClient(localeStorageOptions);
|
|
11
18
|
/**
|
|
12
19
|
* @deprecated Use localeInStorage instead
|
|
13
20
|
*
|
|
@@ -50,5 +57,5 @@ const useLocaleCookie = (isCookieEnabled) => {
|
|
|
50
57
|
};
|
|
51
58
|
|
|
52
59
|
//#endregion
|
|
53
|
-
export { localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage };
|
|
60
|
+
export { getLocaleInStorage, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage };
|
|
54
61
|
//# sourceMappingURL=useLocaleStorage.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocaleStorage.mjs","names":["setLocaleInStorageCore"],"sources":["../../../src/client/useLocaleStorage.ts"],"sourcesContent":["import {\n getLocaleFromStorageClient,\n LocaleStorageClient,\n localeStorageOptions,\n setLocaleInStorageClient as setLocaleInStorageCore,\n} from '@intlayer/core/utils';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"useLocaleStorage.mjs","names":["setLocaleInStorageCore"],"sources":["../../../src/client/useLocaleStorage.ts"],"sourcesContent":["import {\n getCachedLocaleFromStorageClient,\n getLocaleFromStorageClient,\n LocaleStorageClient,\n localeStorageOptions,\n setLocaleInStorageClient as setLocaleInStorageCore,\n} from '@intlayer/core/utils';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\n/**\n * Reads the locale persisted in the browser storage (cookie, localStorage…).\n *\n * Unlike `localeInStorage`, read on first call rather than at import, then\n * cached until the next `setLocaleInStorage`. Never cached on the server.\n */\nexport const getLocaleInStorage = getCachedLocaleFromStorageClient;\n\n/**\n * Get the locale cookie\n *\n * Read once at import time; marked pure so bundlers drop the read when nothing\n * imports it.\n */\nexport const localeInStorage =\n /* @__PURE__ */ getLocaleFromStorageClient(localeStorageOptions);\n/**\n * @deprecated Use localeInStorage instead\n *\n * Get the locale cookie\n */\nexport const localeCookie = localeInStorage;\n\n/**\n * Set the locale cookie\n */\nexport const setLocaleInStorage = (\n locale: LocalesValues,\n isCookieEnabled: boolean\n) =>\n setLocaleInStorageCore(locale, {\n ...localeStorageOptions,\n isCookieEnabled,\n });\n\n/**\n * @deprecated Use setLocaleInStorage instead\n *\n * Set the locale cookie\n */\nexport const setLocaleCookie = setLocaleInStorage;\n\n/**\n * Hook that provides the locale storage and a function to set it\n */\nexport const useLocaleStorage = (isCookieEnabled?: boolean) =>\n LocaleStorageClient({\n ...localeStorageOptions,\n isCookieEnabled,\n });\n\n/**\n * @deprecated Use useLocaleStorage instead\n *\n * For GDPR compliance, use useLocaleStorage instead\n *\n * Hook that provides the locale cookie and a function to set it\n */\nexport const useLocaleCookie = (isCookieEnabled?: boolean) => {\n const storage = useLocaleStorage(isCookieEnabled);\n\n return {\n localeCookie: storage.getLocale(),\n setLocaleCookie: storage.setLocale,\n };\n};\n"],"mappings":";;;;;;;;;AAeA,MAAa,qBAAqB;;;;;;;AAQlC,MAAa,kBACK,2CAA2B,oBAAoB;;;;;;AAMjE,MAAa,eAAe;;;;AAK5B,MAAa,sBACX,QACA,oBAEAA,yBAAuB,QAAQ;CAC7B,GAAG;CACH;AACF,CAAC;;;;;;AAOH,MAAa,kBAAkB;;;;AAK/B,MAAa,oBAAoB,oBAC/B,oBAAoB;CAClB,GAAG;CACH;AACF,CAAC;;;;;;;;AASH,MAAa,mBAAmB,oBAA8B;CAC5D,MAAM,UAAU,iBAAiB,eAAe;CAEhD,OAAO;EACL,cAAc,QAAQ,UAAU;EAChC,iBAAiB,QAAQ;CAC3B;AACF"}
|