angular-intlayer 8.4.4 → 8.4.5
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/_virtual/_@oxc-project_runtime@0.115.0/helpers/decorate.cjs +11 -0
- package/dist/cjs/_virtual/_@oxc-project_runtime@0.115.0/helpers/decorateMetadata.cjs +8 -0
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/cjs/client/index.cjs +28 -1
- package/dist/cjs/client/installIntlayer.cjs +77 -1
- package/dist/cjs/client/installIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +15 -1
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +24 -1
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +25 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useIntl.cjs +40 -1
- package/dist/cjs/client/useIntl.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +44 -1
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLoadDynamic.cjs +28 -1
- package/dist/cjs/client/useLoadDynamic.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +60 -1
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +61 -1
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelector.component.cjs +38 -1
- package/dist/cjs/editor/ContentSelector.component.cjs.map +1 -0
- package/dist/cjs/editor/useEditor.cjs +31 -1
- package/dist/cjs/editor/useEditor.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs +10 -1
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +10 -1
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/index.cjs +50 -1
- package/dist/cjs/markdown/index.cjs +13 -1
- package/dist/cjs/markdown/installIntlayerMarkdown.cjs +79 -1
- package/dist/cjs/markdown/installIntlayerMarkdown.cjs.map +1 -1
- package/dist/cjs/plugins.cjs +212 -1
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/renderIntlayerNode.cjs +28 -1
- package/dist/cjs/renderIntlayerNode.cjs.map +1 -1
- package/dist/cjs/webpack/index.cjs +4 -1
- package/dist/cjs/webpack/mergeConfig.cjs +45 -1
- package/dist/cjs/webpack/mergeConfig.cjs.map +1 -1
- package/dist/esm/_virtual/_@oxc-project_runtime@0.115.0/helpers/decorate.mjs +10 -0
- package/dist/esm/_virtual/_@oxc-project_runtime@0.115.0/helpers/decorateMetadata.mjs +7 -0
- package/dist/esm/client/index.mjs +10 -1
- package/dist/esm/client/installIntlayer.mjs +65 -1
- package/dist/esm/client/installIntlayer.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +13 -1
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +21 -1
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +22 -1
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useIntl.mjs +38 -1
- package/dist/esm/client/useIntl.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +41 -1
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLoadDynamic.mjs +26 -1
- package/dist/esm/client/useLoadDynamic.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +57 -1
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleStorage.mjs +54 -1
- package/dist/esm/client/useLocaleStorage.mjs.map +1 -1
- package/dist/esm/editor/ContentSelector.component.mjs +31 -1
- package/dist/esm/editor/ContentSelector.component.mjs.map +1 -0
- package/dist/esm/editor/useEditor.mjs +29 -1
- package/dist/esm/editor/useEditor.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs +8 -1
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs +8 -1
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/esm/index.mjs +14 -1
- package/dist/esm/markdown/index.mjs +3 -1
- package/dist/esm/markdown/installIntlayerMarkdown.mjs +68 -1
- package/dist/esm/markdown/installIntlayerMarkdown.mjs.map +1 -1
- package/dist/esm/plugins.mjs +203 -1
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/renderIntlayerNode.mjs +26 -1
- package/dist/esm/renderIntlayerNode.mjs.map +1 -1
- package/dist/esm/webpack/index.mjs +3 -1
- package/dist/esm/webpack/mergeConfig.mjs +43 -1
- package/dist/esm/webpack/mergeConfig.mjs.map +1 -1
- package/dist/types/client/index.d.ts +8 -8
- package/dist/types/client/installIntlayer.d.ts +50 -2
- package/dist/types/client/installIntlayer.d.ts.map +1 -0
- package/dist/types/client/useDictionary.d.ts +10 -2
- package/dist/types/client/useDictionary.d.ts.map +1 -0
- package/dist/types/client/useDictionaryAsync.d.ts +14 -2
- package/dist/types/client/useDictionaryAsync.d.ts.map +1 -0
- package/dist/types/client/useDictionaryDynamic.d.ts +17 -2
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -0
- package/dist/types/client/useIntl.d.ts +33 -2
- package/dist/types/client/useIntl.d.ts.map +1 -0
- package/dist/types/client/useIntlayer.d.ts +38 -2
- package/dist/types/client/useIntlayer.d.ts.map +1 -0
- package/dist/types/client/useLoadDynamic.d.ts +11 -2
- package/dist/types/client/useLoadDynamic.d.ts.map +1 -0
- package/dist/types/client/useLocale.d.ts +48 -2
- package/dist/types/client/useLocale.d.ts.map +1 -0
- package/dist/types/getDictionary.d.ts +9 -2
- package/dist/types/getDictionary.d.ts.map +1 -0
- package/dist/types/getIntlayer.d.ts +8 -2
- package/dist/types/getIntlayer.d.ts.map +1 -0
- package/dist/types/index.d.ts +21 -13
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/markdown/index.d.ts +1 -1
- package/dist/types/markdown/installIntlayerMarkdown.d.ts +36 -2
- package/dist/types/markdown/installIntlayerMarkdown.d.ts.map +1 -0
- package/dist/types/plugins.d.ts +90 -2
- package/dist/types/plugins.d.ts.map +1 -0
- package/dist/types/webpack/index.d.ts +2 -5
- package/dist/types/webpack/mergeConfig.d.ts +5 -2
- package/dist/types/webpack/mergeConfig.d.ts.map +1 -0
- package/package.json +8 -8
- package/dist/cjs/ContentSelector.component-Dfy-4WRH.cjs +0 -9
- package/dist/cjs/ContentSelector.component-Dfy-4WRH.cjs.map +0 -1
- package/dist/cjs/chunk-Bmb41Sf3.cjs +0 -1
- package/dist/cjs/decorate-B_4qGGx3.cjs +0 -1
- package/dist/esm/ContentSelector.component-B9Uvy9gY.mjs +0 -9
- package/dist/esm/ContentSelector.component-B9Uvy9gY.mjs.map +0 -1
- package/dist/esm/decorate-EVKP5RjP.mjs +0 -1
- package/dist/types/getDictionary-DDjZzxAC.d.ts +0 -9
- package/dist/types/getDictionary-DDjZzxAC.d.ts.map +0 -1
- package/dist/types/getIntlayer-CWM6qsJJ.d.ts +0 -8
- package/dist/types/getIntlayer-CWM6qsJJ.d.ts.map +0 -1
- package/dist/types/index-Cf8zm5QQ.d.ts +0 -1
- package/dist/types/index-D5QAgZ5v.d.ts +0 -22
- package/dist/types/index-D5QAgZ5v.d.ts.map +0 -1
- package/dist/types/installIntlayer-Ce7kST5N.d.ts +0 -50
- package/dist/types/installIntlayer-Ce7kST5N.d.ts.map +0 -1
- package/dist/types/installIntlayerMarkdown-BIU3FTDH.d.ts +0 -36
- package/dist/types/installIntlayerMarkdown-BIU3FTDH.d.ts.map +0 -1
- package/dist/types/plugins-C_v3w-vC.d.ts +0 -89
- package/dist/types/plugins-C_v3w-vC.d.ts.map +0 -1
- package/dist/types/useDictionary-Dq9yu0X_.d.ts +0 -10
- package/dist/types/useDictionary-Dq9yu0X_.d.ts.map +0 -1
- package/dist/types/useDictionaryAsync-BYUsr8w4.d.ts +0 -14
- package/dist/types/useDictionaryAsync-BYUsr8w4.d.ts.map +0 -1
- package/dist/types/useIntl-CHizZCR2.d.ts +0 -33
- package/dist/types/useIntl-CHizZCR2.d.ts.map +0 -1
- package/dist/types/useIntlayer-m3n_upwm.d.ts +0 -38
- package/dist/types/useIntlayer-m3n_upwm.d.ts.map +0 -1
- package/dist/types/useLoadDynamic-C4pltPcC.d.ts +0 -11
- package/dist/types/useLoadDynamic-C4pltPcC.d.ts.map +0 -1
- package/dist/types/useLocale-BzfAmXlx.d.ts +0 -48
- package/dist/types/useLocale-BzfAmXlx.d.ts.map +0 -1
- package/dist/types/webpack/index.d.ts.map +0 -1
|
@@ -1,2 +1,58 @@
|
|
|
1
|
-
import{INTLAYER_TOKEN
|
|
1
|
+
import { INTLAYER_TOKEN } from "./installIntlayer.mjs";
|
|
2
|
+
import { setLocaleInStorage } from "./useLocaleStorage.mjs";
|
|
3
|
+
import configuration from "@intlayer/config/built";
|
|
4
|
+
import { computed, inject } from "@angular/core";
|
|
5
|
+
|
|
6
|
+
//#region src/client/useLocale.ts
|
|
7
|
+
/**
|
|
8
|
+
* Angular hook to manage the current locale and related functions.
|
|
9
|
+
*
|
|
10
|
+
* @param props - Optional configuration for locale management.
|
|
11
|
+
* @returns An object containing the current locale (signal), default locale, available locales, and a function to update the locale.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { Component } from '@angular/core';
|
|
16
|
+
* import { useLocale } from 'angular-intlayer';
|
|
17
|
+
*
|
|
18
|
+
* @Component({
|
|
19
|
+
* standalone: true,
|
|
20
|
+
* selector: 'app-locale-switcher',
|
|
21
|
+
* template: `
|
|
22
|
+
* <select [value]="locale()" (change)="setLocale($any($event.target).value)">
|
|
23
|
+
* @for (loc of availableLocales; track loc) {
|
|
24
|
+
* <option [value]="loc">{{ loc }}</option>
|
|
25
|
+
* }
|
|
26
|
+
* </select>
|
|
27
|
+
* `,
|
|
28
|
+
* })
|
|
29
|
+
* export class LocaleSwitcher {
|
|
30
|
+
* const { locale, setLocale, availableLocales } = useLocale();
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
const useLocale = ({ isCookieEnabled, onLocaleChange } = {}) => {
|
|
35
|
+
const { defaultLocale, locales: availableLocales } = configuration?.internationalization ?? {};
|
|
36
|
+
const intlayer = inject(INTLAYER_TOKEN);
|
|
37
|
+
const locale = computed(() => intlayer?.locale() ?? defaultLocale);
|
|
38
|
+
const isCookieEnabledContext = computed(() => intlayer?.isCookieEnabled() ?? true);
|
|
39
|
+
const setLocale = (newLocale) => {
|
|
40
|
+
if (!availableLocales?.map(String).includes(newLocale)) {
|
|
41
|
+
console.error(`Locale ${newLocale} is not available`);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (intlayer) intlayer.setLocale(newLocale);
|
|
45
|
+
setLocaleInStorage(newLocale, isCookieEnabled ?? isCookieEnabledContext() ?? true);
|
|
46
|
+
onLocaleChange?.(newLocale);
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
locale,
|
|
50
|
+
defaultLocale,
|
|
51
|
+
availableLocales,
|
|
52
|
+
setLocale
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
export { useLocale };
|
|
2
58
|
//# sourceMappingURL=useLocale.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.mjs","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["import { computed, inject } from '@angular/core';\nimport configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\ntype useLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: LocalesValues) => void;\n};\n\n/**\n * Angular hook to manage the current locale and related functions.\n *\n * @param props - Optional configuration for locale management.\n * @returns An object containing the current locale (signal), default locale, available locales, and a function to update the locale.\n *\n * @example\n * ```ts\n * import { Component } from '@angular/core';\n * import { useLocale } from 'angular-intlayer';\n *\n * @Component({\n * standalone: true,\n * selector: 'app-locale-switcher',\n * template: `\n * <select [value]=\"locale()\" (change)=\"setLocale($any($event.target).value)\">\n * @for (loc of availableLocales; track loc) {\n * <option [value]=\"loc\">{{ loc }}</option>\n * }\n * </select>\n * `,\n * })\n * export class LocaleSwitcher {\n * const { locale, setLocale, availableLocales } = useLocale();\n * }\n * ```\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: useLocaleProps = {}) => {\n const { defaultLocale, locales: availableLocales } =\n configuration?.internationalization ?? {};\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n // Create a reactive reference for the locale\n const locale = computed(() => intlayer?.locale() ?? defaultLocale);\n const isCookieEnabledContext = computed(\n () => intlayer?.isCookieEnabled() ?? true\n );\n\n const setLocale = (newLocale: LocalesValues) => {\n if (!availableLocales?.map(String).includes(newLocale)) {\n console.error(`Locale ${newLocale} is not available`);\n return;\n }\n\n if (intlayer) {\n intlayer.setLocale(newLocale);\n }\n setLocaleInStorage(\n newLocale,\n isCookieEnabled ?? isCookieEnabledContext() ?? true\n );\n onLocaleChange?.(newLocale);\n };\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocale.mjs","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["import { computed, inject } from '@angular/core';\nimport configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\ntype useLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: LocalesValues) => void;\n};\n\n/**\n * Angular hook to manage the current locale and related functions.\n *\n * @param props - Optional configuration for locale management.\n * @returns An object containing the current locale (signal), default locale, available locales, and a function to update the locale.\n *\n * @example\n * ```ts\n * import { Component } from '@angular/core';\n * import { useLocale } from 'angular-intlayer';\n *\n * @Component({\n * standalone: true,\n * selector: 'app-locale-switcher',\n * template: `\n * <select [value]=\"locale()\" (change)=\"setLocale($any($event.target).value)\">\n * @for (loc of availableLocales; track loc) {\n * <option [value]=\"loc\">{{ loc }}</option>\n * }\n * </select>\n * `,\n * })\n * export class LocaleSwitcher {\n * const { locale, setLocale, availableLocales } = useLocale();\n * }\n * ```\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: useLocaleProps = {}) => {\n const { defaultLocale, locales: availableLocales } =\n configuration?.internationalization ?? {};\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n // Create a reactive reference for the locale\n const locale = computed(() => intlayer?.locale() ?? defaultLocale);\n const isCookieEnabledContext = computed(\n () => intlayer?.isCookieEnabled() ?? true\n );\n\n const setLocale = (newLocale: LocalesValues) => {\n if (!availableLocales?.map(String).includes(newLocale)) {\n console.error(`Locale ${newLocale} is not available`);\n return;\n }\n\n if (intlayer) {\n intlayer.setLocale(newLocale);\n }\n setLocaleInStorage(\n newLocale,\n isCookieEnabled ?? isCookieEnabledContext() ?? true\n );\n onLocaleChange?.(newLocale);\n };\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,aAAa,EACxB,iBACA,mBACkB,EAAE,KAAK;CACzB,MAAM,EAAE,eAAe,SAAS,qBAC9B,eAAe,wBAAwB,EAAE;CAC3C,MAAM,WAAW,OAAyB,eAAe;CAGzD,MAAM,SAAS,eAAe,UAAU,QAAQ,IAAI,cAAc;CAClE,MAAM,yBAAyB,eACvB,UAAU,iBAAiB,IAAI,KACtC;CAED,MAAM,aAAa,cAA6B;AAC9C,MAAI,CAAC,kBAAkB,IAAI,OAAO,CAAC,SAAS,UAAU,EAAE;AACtD,WAAQ,MAAM,UAAU,UAAU,mBAAmB;AACrD;;AAGF,MAAI,SACF,UAAS,UAAU,UAAU;AAE/B,qBACE,WACA,mBAAmB,wBAAwB,IAAI,KAChD;AACD,mBAAiB,UAAU;;AAG7B,QAAO;EACL;EACA;EACA;EACA;EACD"}
|
|
@@ -1,2 +1,55 @@
|
|
|
1
|
-
import{localeStorageOptions
|
|
1
|
+
import { localeStorageOptions } from "@intlayer/core/localization";
|
|
2
|
+
import { LocaleStorage, getLocaleFromStorage, setLocaleInStorage as setLocaleInStorage$1 } from "@intlayer/core/utils";
|
|
3
|
+
|
|
4
|
+
//#region src/client/useLocaleStorage.ts
|
|
5
|
+
/**
|
|
6
|
+
* Get the locale cookie
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Get the locale cookie
|
|
10
|
+
*/
|
|
11
|
+
const localeInStorage = getLocaleFromStorage(localeStorageOptions);
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Use localeInStorage instead
|
|
14
|
+
*
|
|
15
|
+
* Get the locale cookie
|
|
16
|
+
*/
|
|
17
|
+
const localeCookie = localeInStorage;
|
|
18
|
+
/**
|
|
19
|
+
* Set the locale cookie
|
|
20
|
+
*/
|
|
21
|
+
const setLocaleInStorage = (locale, isCookieEnabled) => setLocaleInStorage$1(locale, {
|
|
22
|
+
...localeStorageOptions,
|
|
23
|
+
isCookieEnabled
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated Use setLocaleInStorage instead
|
|
27
|
+
*
|
|
28
|
+
* Set the locale cookie
|
|
29
|
+
*/
|
|
30
|
+
const setLocaleCookie = setLocaleInStorage;
|
|
31
|
+
/**
|
|
32
|
+
* Hook that provides the locale storage and a function to set it
|
|
33
|
+
*/
|
|
34
|
+
const useLocaleStorage = (isCookieEnabled) => LocaleStorage({
|
|
35
|
+
...localeStorageOptions,
|
|
36
|
+
isCookieEnabled
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated Use useLocaleStorage instead
|
|
40
|
+
*
|
|
41
|
+
* For GDPR compliance, use useLocaleStorage instead
|
|
42
|
+
*
|
|
43
|
+
* Hook that provides the locale cookie and a function to set it
|
|
44
|
+
*/
|
|
45
|
+
const useLocaleCookie = (isCookieEnabled) => {
|
|
46
|
+
const storage = useLocaleStorage(isCookieEnabled);
|
|
47
|
+
return {
|
|
48
|
+
localeCookie: storage.getLocale(),
|
|
49
|
+
setLocaleCookie: storage.setLocale
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
export { localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage };
|
|
2
55
|
//# sourceMappingURL=useLocaleStorage.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocaleStorage.mjs","names":["setLocaleInStorageCore"],"sources":["../../../src/client/useLocaleStorage.ts"],"sourcesContent":["import { localeStorageOptions } from '@intlayer/core/localization';\nimport {\n getLocaleFromStorage,\n LocaleStorage,\n setLocaleInStorage as setLocaleInStorageCore,\n} from '@intlayer/core/utils';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\n/**\n * Get the locale cookie\n */\n/**\n * Get the locale cookie\n */\nexport const localeInStorage = getLocaleFromStorage(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 LocaleStorage({\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":"
|
|
1
|
+
{"version":3,"file":"useLocaleStorage.mjs","names":["setLocaleInStorageCore"],"sources":["../../../src/client/useLocaleStorage.ts"],"sourcesContent":["import { localeStorageOptions } from '@intlayer/core/localization';\nimport {\n getLocaleFromStorage,\n LocaleStorage,\n setLocaleInStorage as setLocaleInStorageCore,\n} from '@intlayer/core/utils';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\n/**\n * Get the locale cookie\n */\n/**\n * Get the locale cookie\n */\nexport const localeInStorage = getLocaleFromStorage(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 LocaleStorage({\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":";;;;;;;;;;AAcA,MAAa,kBAAkB,qBAAqB,qBAAqB;;;;;;AAMzE,MAAa,eAAe;;;;AAK5B,MAAa,sBACX,QACA,oBAEAA,qBAAuB,QAAQ;CAC7B,GAAG;CACH;CACD,CAAC;;;;;;AAOJ,MAAa,kBAAkB;;;;AAK/B,MAAa,oBAAoB,oBAC/B,cAAc;CACZ,GAAG;CACH;CACD,CAAC;;;;;;;;AASJ,MAAa,mBAAmB,oBAA8B;CAC5D,MAAM,UAAU,iBAAiB,gBAAgB;AAEjD,QAAO;EACL,cAAc,QAAQ,WAAW;EACjC,iBAAiB,QAAQ;EAC1B"}
|
|
@@ -1 +1,31 @@
|
|
|
1
|
-
import{
|
|
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 { CUSTOM_ELEMENTS_SCHEMA, Component, Input } from "@angular/core";
|
|
4
|
+
|
|
5
|
+
//#region src/editor/ContentSelector.component.ts
|
|
6
|
+
let ContentSelectorWrapperComponent = class ContentSelectorWrapperComponent {
|
|
7
|
+
dictionaryKey;
|
|
8
|
+
keyPath;
|
|
9
|
+
get keyPathJson() {
|
|
10
|
+
return JSON.stringify(this.keyPath);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
__decorate([Input(), __decorateMetadata("design:type", String)], ContentSelectorWrapperComponent.prototype, "dictionaryKey", void 0);
|
|
14
|
+
__decorate([Input(), __decorateMetadata("design:type", Array)], ContentSelectorWrapperComponent.prototype, "keyPath", void 0);
|
|
15
|
+
ContentSelectorWrapperComponent = __decorate([Component({
|
|
16
|
+
selector: "app-content-selector-wrapper",
|
|
17
|
+
standalone: true,
|
|
18
|
+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
|
19
|
+
template: `
|
|
20
|
+
<intlayer-content-selector-wrapper
|
|
21
|
+
[attr.key-path]="keyPathJson"
|
|
22
|
+
[attr.dictionary-key]="dictionaryKey"
|
|
23
|
+
>
|
|
24
|
+
<ng-content></ng-content>
|
|
25
|
+
</intlayer-content-selector-wrapper>
|
|
26
|
+
`
|
|
27
|
+
})], ContentSelectorWrapperComponent);
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
export { ContentSelectorWrapperComponent };
|
|
31
|
+
//# sourceMappingURL=ContentSelector.component.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentSelector.component.mjs","names":[],"sources":["../../../src/editor/ContentSelector.component.ts"],"sourcesContent":["import { Component, CUSTOM_ELEMENTS_SCHEMA, Input } from '@angular/core';\n\n@Component({\n selector: 'app-content-selector-wrapper',\n standalone: true,\n schemas: [CUSTOM_ELEMENTS_SCHEMA],\n template: `\n <intlayer-content-selector-wrapper\n [attr.key-path]=\"keyPathJson\"\n [attr.dictionary-key]=\"dictionaryKey\"\n >\n <ng-content></ng-content>\n </intlayer-content-selector-wrapper>\n `,\n})\nexport class ContentSelectorWrapperComponent {\n @Input() dictionaryKey!: string;\n @Input() keyPath!: any[];\n\n get keyPathJson() {\n return JSON.stringify(this.keyPath);\n }\n}\n"],"mappings":";;;;;AAeO,4CAAM,gCAAgC;CAC3C,AAAS;CACT,AAAS;CAET,IAAI,cAAc;AAChB,SAAO,KAAK,UAAU,KAAK,QAAQ;;;YAJpC,OAAO;YACP,OAAO;8CAfT,UAAU;CACT,UAAU;CACV,YAAY;CACZ,SAAS,CAAC,uBAAuB;CACjC,UAAU;;;;;;;;CAQX,CAAC"}
|
|
@@ -1,2 +1,30 @@
|
|
|
1
|
-
import{INTLAYER_TOKEN
|
|
1
|
+
import { INTLAYER_TOKEN } from "../client/installIntlayer.mjs";
|
|
2
|
+
import { DestroyRef, Injector, effect, inject, runInInjectionContext } from "@angular/core";
|
|
3
|
+
import { isEnabled } from "@intlayer/editor/isEnabled";
|
|
4
|
+
|
|
5
|
+
//#region src/editor/useEditor.ts
|
|
6
|
+
const useEditor = () => {
|
|
7
|
+
if (process.env.INTLAYER_EDITOR_ENABLED === "false" || !isEnabled) return;
|
|
8
|
+
const destroyRef = inject(DestroyRef, { optional: true });
|
|
9
|
+
const client = inject(INTLAYER_TOKEN, { optional: true });
|
|
10
|
+
const injector = inject(Injector);
|
|
11
|
+
import("@intlayer/editor").then(({ initEditorClient }) => {
|
|
12
|
+
const manager = initEditorClient();
|
|
13
|
+
if (client) {
|
|
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
|
+
}
|
|
20
|
+
});
|
|
21
|
+
destroyRef?.onDestroy(() => {
|
|
22
|
+
import("@intlayer/editor").then(({ stopEditorClient }) => {
|
|
23
|
+
stopEditorClient();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { useEditor };
|
|
2
30
|
//# 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 (process.env.INTLAYER_EDITOR_ENABLED === 'false' || !isEnabled) return;\n\n const destroyRef = inject(DestroyRef, { optional: true });\n const client = inject<IntlayerProvider>(INTLAYER_TOKEN, {\n optional: true,\n } as any);\n const injector = inject(Injector);\n\n import('@intlayer/editor').then(({ initEditorClient }) => {\n const manager = initEditorClient();\n\n if (client) {\n const effectRef = runInInjectionContext(injector, () =>\n effect(() => {\n const locale = client.locale();\n if (locale) manager.currentLocale.set(locale as Locale);\n })\n );\n destroyRef?.onDestroy(() => effectRef.destroy());\n }\n });\n\n destroyRef?.onDestroy(() => {\n import('@intlayer/editor').then(({ stopEditorClient }) => {\n stopEditorClient();\n });\n });\n};\n"],"mappings":"
|
|
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 (process.env.INTLAYER_EDITOR_ENABLED === 'false' || !isEnabled) return;\n\n const destroyRef = inject(DestroyRef, { optional: true });\n const client = inject<IntlayerProvider>(INTLAYER_TOKEN, {\n optional: true,\n } as any);\n const injector = inject(Injector);\n\n import('@intlayer/editor').then(({ initEditorClient }) => {\n const manager = initEditorClient();\n\n if (client) {\n const effectRef = runInInjectionContext(injector, () =>\n effect(() => {\n const locale = client.locale();\n if (locale) manager.currentLocale.set(locale as Locale);\n })\n );\n destroyRef?.onDestroy(() => effectRef.destroy());\n }\n });\n\n destroyRef?.onDestroy(() => {\n import('@intlayer/editor').then(({ stopEditorClient }) => {\n stopEditorClient();\n });\n });\n};\n"],"mappings":";;;;;AAWA,MAAa,kBAAkB;AAC7B,KAAI,QAAQ,IAAI,4BAA4B,WAAW,CAAC,UAAW;CAEnE,MAAM,aAAa,OAAO,YAAY,EAAE,UAAU,MAAM,CAAC;CACzD,MAAM,SAAS,OAAyB,gBAAgB,EACtD,UAAU,MACX,CAAQ;CACT,MAAM,WAAW,OAAO,SAAS;AAEjC,QAAO,oBAAoB,MAAM,EAAE,uBAAuB;EACxD,MAAM,UAAU,kBAAkB;AAElC,MAAI,QAAQ;GACV,MAAM,YAAY,sBAAsB,gBACtC,aAAa;IACX,MAAM,SAAS,OAAO,QAAQ;AAC9B,QAAI,OAAQ,SAAQ,cAAc,IAAI,OAAiB;KACvD,CACH;AACD,eAAY,gBAAgB,UAAU,SAAS,CAAC;;GAElD;AAEF,aAAY,gBAAgB;AAC1B,SAAO,oBAAoB,MAAM,EAAE,uBAAuB;AACxD,qBAAkB;IAClB;GACF"}
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
import{getPlugins
|
|
1
|
+
import { getPlugins } from "./plugins.mjs";
|
|
2
|
+
import { getDictionary as getDictionary$1 } from "@intlayer/core/interpreter";
|
|
3
|
+
|
|
4
|
+
//#region src/getDictionary.ts
|
|
5
|
+
const getDictionary = (dictionary, locale) => getDictionary$1(dictionary, locale, getPlugins(locale));
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { getDictionary };
|
|
2
9
|
//# sourceMappingURL=getDictionary.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDictionary.mjs","names":["getDictionaryCore"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import { getDictionary as getDictionaryCore } from '@intlayer/core/interpreter';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getPlugins } from './plugins';\n\nexport const getDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n) => getDictionaryCore<T, L>(dictionary,
|
|
1
|
+
{"version":3,"file":"getDictionary.mjs","names":["getDictionaryCore"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import { getDictionary as getDictionaryCore } from '@intlayer/core/interpreter';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getPlugins } from './plugins';\n\nexport const getDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n) => getDictionaryCore<T, L>(dictionary, locale, getPlugins(locale));\n"],"mappings":";;;;AAQA,MAAa,iBAIX,YACA,WACGA,gBAAwB,YAAY,QAAQ,WAAW,OAAO,CAAC"}
|
package/dist/esm/getIntlayer.mjs
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
import{getPlugins
|
|
1
|
+
import { getPlugins } from "./plugins.mjs";
|
|
2
|
+
import { getIntlayer as getIntlayer$1 } from "@intlayer/core/interpreter";
|
|
3
|
+
|
|
4
|
+
//#region src/getIntlayer.ts
|
|
5
|
+
const getIntlayer = (key, locale) => getIntlayer$1(key, locale, getPlugins(locale));
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { getIntlayer };
|
|
2
9
|
//# sourceMappingURL=getIntlayer.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIntlayer.mjs","names":["getIntlayerCore"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore } from '@intlayer/core/interpreter';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\nexport const getIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L\n) =>\n getIntlayerCore<T, L>(\n key,\n locale,\n getPlugins(locale)\n ) as DeepTransformContent<DictionaryRegistryContent<T>>;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getIntlayer.mjs","names":["getIntlayerCore"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore } from '@intlayer/core/interpreter';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\nexport const getIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L\n) =>\n getIntlayerCore<T, L>(\n key,\n locale,\n getPlugins(locale)\n ) as DeepTransformContent<DictionaryRegistryContent<T>>;\n"],"mappings":";;;;AASA,MAAa,eAIX,KACA,WAEAA,cACE,KACA,QACA,WAAW,OAAO,CACnB"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { INTLAYER_MARKDOWN_TOKEN, IntlayerMarkdownService, createIntlayerMarkdownProvider, htmlRuntime, useMarkdown } from "./markdown/installIntlayerMarkdown.mjs";
|
|
2
|
+
import { getPlugins, htmlPlugin, insertionPlugin, intlayerNodePlugins, markdownPlugin, markdownStringPlugin } from "./plugins.mjs";
|
|
3
|
+
import { getIntlayer } from "./getIntlayer.mjs";
|
|
4
|
+
import { getDictionary } from "./getDictionary.mjs";
|
|
5
|
+
import { INTLAYER_TOKEN, IntlayerProvider, createIntlayerClient, installIntlayer, provideIntlayer } from "./client/installIntlayer.mjs";
|
|
6
|
+
import { useDictionary } from "./client/useDictionary.mjs";
|
|
7
|
+
import { useDictionaryAsync } from "./client/useDictionaryAsync.mjs";
|
|
8
|
+
import { useLoadDynamic } from "./client/useLoadDynamic.mjs";
|
|
9
|
+
import { useDictionaryDynamic } from "./client/useDictionaryDynamic.mjs";
|
|
10
|
+
import { useIntl } from "./client/useIntl.mjs";
|
|
11
|
+
import { isUpdatableNode, useIntlayer } from "./client/useIntlayer.mjs";
|
|
12
|
+
import { useLocale } from "./client/useLocale.mjs";
|
|
13
|
+
|
|
14
|
+
export { INTLAYER_MARKDOWN_TOKEN, INTLAYER_TOKEN, IntlayerMarkdownService, IntlayerProvider, createIntlayerClient, createIntlayerMarkdownProvider, getDictionary, getIntlayer, getPlugins, htmlPlugin, htmlRuntime, insertionPlugin, installIntlayer, intlayerNodePlugins, isUpdatableNode, markdownPlugin, markdownStringPlugin, provideIntlayer, useDictionary, useDictionaryAsync, useDictionaryDynamic, useIntl, useIntlayer, useLoadDynamic, useLocale, useMarkdown };
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
import{INTLAYER_MARKDOWN_TOKEN
|
|
1
|
+
import { INTLAYER_MARKDOWN_TOKEN, IntlayerMarkdownService, createIntlayerMarkdownProvider, htmlRuntime, useMarkdown } from "./installIntlayerMarkdown.mjs";
|
|
2
|
+
|
|
3
|
+
export { INTLAYER_MARKDOWN_TOKEN, IntlayerMarkdownService, createIntlayerMarkdownProvider, htmlRuntime, useMarkdown };
|
|
@@ -1,2 +1,69 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { __decorate } from "../_virtual/_@oxc-project_runtime@0.115.0/helpers/decorate.mjs";
|
|
2
|
+
import { compile } from "@intlayer/core/markdown";
|
|
3
|
+
import { Injectable, InjectionToken, inject } from "@angular/core";
|
|
4
|
+
|
|
5
|
+
//#region src/markdown/installIntlayerMarkdown.ts
|
|
6
|
+
const INTLAYER_MARKDOWN_TOKEN = new InjectionToken("intlayerMarkdown");
|
|
7
|
+
const htmlRuntime = {
|
|
8
|
+
createElement: (tag, props, ...children) => {
|
|
9
|
+
if (typeof tag !== "string") {
|
|
10
|
+
if (tag === htmlRuntime.Fragment) return children.join("");
|
|
11
|
+
return "";
|
|
12
|
+
}
|
|
13
|
+
const attrs = props ? Object.entries(props).map(([k, v]) => {
|
|
14
|
+
if (k === "key" || v === void 0 || v === null) return "";
|
|
15
|
+
return `${k === "className" ? "class" : k}="${String(v).replace(/"/g, """)}"`;
|
|
16
|
+
}).filter(Boolean).join(" ") : "";
|
|
17
|
+
const childrenStr = children.join("");
|
|
18
|
+
if ([
|
|
19
|
+
"area",
|
|
20
|
+
"base",
|
|
21
|
+
"br",
|
|
22
|
+
"col",
|
|
23
|
+
"embed",
|
|
24
|
+
"hr",
|
|
25
|
+
"img",
|
|
26
|
+
"input",
|
|
27
|
+
"link",
|
|
28
|
+
"meta",
|
|
29
|
+
"param",
|
|
30
|
+
"source",
|
|
31
|
+
"track",
|
|
32
|
+
"wbr"
|
|
33
|
+
].includes(tag)) return `<${tag} ${attrs} />`;
|
|
34
|
+
return `<${tag}${attrs ? ` ${attrs}` : ""}>${childrenStr}</${tag}>`;
|
|
35
|
+
},
|
|
36
|
+
cloneElement: (element, _props) => element,
|
|
37
|
+
Fragment: Symbol("Fragment")
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Default markdown renderer that converts markdown to HTML string
|
|
41
|
+
*/
|
|
42
|
+
const defaultMarkdownRenderer = (markdown) => compile(markdown, { runtime: htmlRuntime });
|
|
43
|
+
/**
|
|
44
|
+
* Create IntlayerMarkdown provider configuration
|
|
45
|
+
*/
|
|
46
|
+
const createIntlayerMarkdownProvider = (renderMarkdown = defaultMarkdownRenderer) => ({
|
|
47
|
+
provide: INTLAYER_MARKDOWN_TOKEN,
|
|
48
|
+
useValue: { renderMarkdown }
|
|
49
|
+
});
|
|
50
|
+
let IntlayerMarkdownService = class IntlayerMarkdownService {
|
|
51
|
+
markdownProvider = inject(INTLAYER_MARKDOWN_TOKEN, { optional: true });
|
|
52
|
+
renderMarkdown(markdown, overrides) {
|
|
53
|
+
if (!this.markdownProvider) return markdown;
|
|
54
|
+
return this.markdownProvider.renderMarkdown(markdown, overrides);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
IntlayerMarkdownService = __decorate([Injectable({ providedIn: "root" })], IntlayerMarkdownService);
|
|
58
|
+
/**
|
|
59
|
+
* Function to inject markdown provider
|
|
60
|
+
*/
|
|
61
|
+
const useMarkdown = () => {
|
|
62
|
+
const markdownProvider = inject(INTLAYER_MARKDOWN_TOKEN, { optional: true });
|
|
63
|
+
if (!markdownProvider) return { renderMarkdown: defaultMarkdownRenderer };
|
|
64
|
+
return markdownProvider;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { INTLAYER_MARKDOWN_TOKEN, IntlayerMarkdownService, createIntlayerMarkdownProvider, htmlRuntime, useMarkdown };
|
|
2
69
|
//# sourceMappingURL=installIntlayerMarkdown.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installIntlayerMarkdown.mjs","names":[],"sources":["../../../src/markdown/installIntlayerMarkdown.ts"],"sourcesContent":["import {\n Injectable,\n InjectionToken,\n inject,\n type TemplateRef,\n} from '@angular/core';\nimport type { MarkdownRuntime } from '@intlayer/core/markdown';\nimport { compile } from '@intlayer/core/markdown';\n\nexport const INTLAYER_MARKDOWN_TOKEN =\n new InjectionToken<IntlayerMarkdownProvider>('intlayerMarkdown');\n\ntype RenderMarkdownOptions = {\n components?: any;\n wrapper?: any;\n options?: any;\n};\n\ntype RenderMarkdownFunction = (\n markdown: string,\n overrides?: any | RenderMarkdownOptions\n) => string | TemplateRef<any>;\n\nexport type IntlayerMarkdownProvider = {\n renderMarkdown: RenderMarkdownFunction;\n};\n\n// Minimal runtime to generate HTML strings\nexport const htmlRuntime: MarkdownRuntime = {\n createElement: (tag: string | any, props: any, ...children: any[]) => {\n if (typeof tag !== 'string') {\n // Handle non-string tags if necessary (e.g. components), or fallback to div\n if (tag === htmlRuntime.Fragment) {\n return children.join('');\n }\n return '';\n }\n\n const attrs = props\n ? Object.entries(props)\n .map(([k, v]) => {\n if (k === 'key' || v === undefined || v === null) return '';\n const key = k === 'className' ? 'class' : k;\n return `${key}=\"${String(v).replace(/\"/g, '"')}\"`;\n })\n .filter(Boolean)\n .join(' ')\n : '';\n\n const childrenStr = children.join('');\n const voidTags = [\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n ];\n\n if (voidTags.includes(tag)) {\n return `<${tag} ${attrs} />`;\n }\n\n return `<${tag}${attrs ? ` ${attrs}` : ''}>${childrenStr}</${tag}>`;\n },\n cloneElement: (element: any, _props: any) => element, // Not really supported for strings\n Fragment: Symbol('Fragment'),\n};\n\n/**\n * Default markdown renderer that converts markdown to HTML string\n */\nconst defaultMarkdownRenderer: RenderMarkdownFunction = (markdown: string) =>\n compile(markdown, { runtime: htmlRuntime }) as string;\n\n/**\n * Create IntlayerMarkdown provider configuration\n */\nexport const createIntlayerMarkdownProvider = (\n renderMarkdown: RenderMarkdownFunction = defaultMarkdownRenderer\n) => ({\n provide: INTLAYER_MARKDOWN_TOKEN,\n useValue: {\n renderMarkdown,\n } as IntlayerMarkdownProvider,\n});\n\n/**\n * Injectable service for markdown rendering\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class IntlayerMarkdownService {\n private markdownProvider = inject(INTLAYER_MARKDOWN_TOKEN, {\n optional: true,\n });\n\n renderMarkdown(markdown: string, overrides?: any): string | TemplateRef<any> {\n if (!this.markdownProvider) {\n return markdown; // Fallback to returning markdown as is\n }\n return this.markdownProvider.renderMarkdown(markdown, overrides);\n }\n}\n\n/**\n * Function to inject markdown provider\n */\nexport const useMarkdown = (): IntlayerMarkdownProvider => {\n const markdownProvider = inject(INTLAYER_MARKDOWN_TOKEN, { optional: true });\n\n if (!markdownProvider) {\n return {\n renderMarkdown: defaultMarkdownRenderer,\n };\n }\n\n return markdownProvider;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"installIntlayerMarkdown.mjs","names":[],"sources":["../../../src/markdown/installIntlayerMarkdown.ts"],"sourcesContent":["import {\n Injectable,\n InjectionToken,\n inject,\n type TemplateRef,\n} from '@angular/core';\nimport type { MarkdownRuntime } from '@intlayer/core/markdown';\nimport { compile } from '@intlayer/core/markdown';\n\nexport const INTLAYER_MARKDOWN_TOKEN =\n new InjectionToken<IntlayerMarkdownProvider>('intlayerMarkdown');\n\ntype RenderMarkdownOptions = {\n components?: any;\n wrapper?: any;\n options?: any;\n};\n\ntype RenderMarkdownFunction = (\n markdown: string,\n overrides?: any | RenderMarkdownOptions\n) => string | TemplateRef<any>;\n\nexport type IntlayerMarkdownProvider = {\n renderMarkdown: RenderMarkdownFunction;\n};\n\n// Minimal runtime to generate HTML strings\nexport const htmlRuntime: MarkdownRuntime = {\n createElement: (tag: string | any, props: any, ...children: any[]) => {\n if (typeof tag !== 'string') {\n // Handle non-string tags if necessary (e.g. components), or fallback to div\n if (tag === htmlRuntime.Fragment) {\n return children.join('');\n }\n return '';\n }\n\n const attrs = props\n ? Object.entries(props)\n .map(([k, v]) => {\n if (k === 'key' || v === undefined || v === null) return '';\n const key = k === 'className' ? 'class' : k;\n return `${key}=\"${String(v).replace(/\"/g, '"')}\"`;\n })\n .filter(Boolean)\n .join(' ')\n : '';\n\n const childrenStr = children.join('');\n const voidTags = [\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n ];\n\n if (voidTags.includes(tag)) {\n return `<${tag} ${attrs} />`;\n }\n\n return `<${tag}${attrs ? ` ${attrs}` : ''}>${childrenStr}</${tag}>`;\n },\n cloneElement: (element: any, _props: any) => element, // Not really supported for strings\n Fragment: Symbol('Fragment'),\n};\n\n/**\n * Default markdown renderer that converts markdown to HTML string\n */\nconst defaultMarkdownRenderer: RenderMarkdownFunction = (markdown: string) =>\n compile(markdown, { runtime: htmlRuntime }) as string;\n\n/**\n * Create IntlayerMarkdown provider configuration\n */\nexport const createIntlayerMarkdownProvider = (\n renderMarkdown: RenderMarkdownFunction = defaultMarkdownRenderer\n) => ({\n provide: INTLAYER_MARKDOWN_TOKEN,\n useValue: {\n renderMarkdown,\n } as IntlayerMarkdownProvider,\n});\n\n/**\n * Injectable service for markdown rendering\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class IntlayerMarkdownService {\n private markdownProvider = inject(INTLAYER_MARKDOWN_TOKEN, {\n optional: true,\n });\n\n renderMarkdown(markdown: string, overrides?: any): string | TemplateRef<any> {\n if (!this.markdownProvider) {\n return markdown; // Fallback to returning markdown as is\n }\n return this.markdownProvider.renderMarkdown(markdown, overrides);\n }\n}\n\n/**\n * Function to inject markdown provider\n */\nexport const useMarkdown = (): IntlayerMarkdownProvider => {\n const markdownProvider = inject(INTLAYER_MARKDOWN_TOKEN, { optional: true });\n\n if (!markdownProvider) {\n return {\n renderMarkdown: defaultMarkdownRenderer,\n };\n }\n\n return markdownProvider;\n};\n"],"mappings":";;;;;AASA,MAAa,0BACX,IAAI,eAAyC,mBAAmB;AAkBlE,MAAa,cAA+B;CAC1C,gBAAgB,KAAmB,OAAY,GAAG,aAAoB;AACpE,MAAI,OAAO,QAAQ,UAAU;AAE3B,OAAI,QAAQ,YAAY,SACtB,QAAO,SAAS,KAAK,GAAG;AAE1B,UAAO;;EAGT,MAAM,QAAQ,QACV,OAAO,QAAQ,MAAM,CAClB,KAAK,CAAC,GAAG,OAAO;AACf,OAAI,MAAM,SAAS,MAAM,UAAa,MAAM,KAAM,QAAO;AAEzD,UAAO,GADK,MAAM,cAAc,UAAU,EAC5B,IAAI,OAAO,EAAE,CAAC,QAAQ,MAAM,SAAS,CAAC;IACpD,CACD,OAAO,QAAQ,CACf,KAAK,IAAI,GACZ;EAEJ,MAAM,cAAc,SAAS,KAAK,GAAG;AAkBrC,MAjBiB;GACf;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACD,CAEY,SAAS,IAAI,CACxB,QAAO,IAAI,IAAI,GAAG,MAAM;AAG1B,SAAO,IAAI,MAAM,QAAQ,IAAI,UAAU,GAAG,GAAG,YAAY,IAAI,IAAI;;CAEnE,eAAe,SAAc,WAAgB;CAC7C,UAAU,OAAO,WAAW;CAC7B;;;;AAKD,MAAM,2BAAmD,aACvD,QAAQ,UAAU,EAAE,SAAS,aAAa,CAAC;;;;AAK7C,MAAa,kCACX,iBAAyC,6BACrC;CACJ,SAAS;CACT,UAAU,EACR,gBACD;CACF;AAQM,oCAAM,wBAAwB;CACnC,AAAQ,mBAAmB,OAAO,yBAAyB,EACzD,UAAU,MACX,CAAC;CAEF,eAAe,UAAkB,WAA4C;AAC3E,MAAI,CAAC,KAAK,iBACR,QAAO;AAET,SAAO,KAAK,iBAAiB,eAAe,UAAU,UAAU;;;sCAZnE,WAAW,EACV,YAAY,QACb,CAAC;;;;AAiBF,MAAa,oBAA8C;CACzD,MAAM,mBAAmB,OAAO,yBAAyB,EAAE,UAAU,MAAM,CAAC;AAE5E,KAAI,CAAC,iBACH,QAAO,EACL,gBAAgB,yBACjB;AAGH,QAAO"}
|
package/dist/esm/plugins.mjs
CHANGED
|
@@ -1,2 +1,204 @@
|
|
|
1
|
-
import{renderIntlayerNode
|
|
1
|
+
import { renderIntlayerNode } from "./renderIntlayerNode.mjs";
|
|
2
|
+
import { ContentSelectorWrapperComponent } from "./editor/ContentSelector.component.mjs";
|
|
3
|
+
import { htmlRuntime, useMarkdown } from "./markdown/installIntlayerMarkdown.mjs";
|
|
4
|
+
import { conditionPlugin, enumerationPlugin, filePlugin, genderPlugin, nestedPlugin, translationPlugin } from "@intlayer/core/interpreter";
|
|
5
|
+
import configuration from "@intlayer/config/built";
|
|
6
|
+
import { compile, getMarkdownMetadata } from "@intlayer/core/markdown";
|
|
7
|
+
import * as NodeTypes from "@intlayer/types/nodeType";
|
|
8
|
+
|
|
9
|
+
//#region src/plugins.ts
|
|
10
|
+
/** ---------------------------------------------
|
|
11
|
+
* UTILS
|
|
12
|
+
* --------------------------------------------- */
|
|
13
|
+
const createRuntimeWithOverides = (baseRuntime, overrides) => ({
|
|
14
|
+
...baseRuntime,
|
|
15
|
+
createElement: (tag, props, ...children) => {
|
|
16
|
+
const override = overrides?.[tag];
|
|
17
|
+
if (override) {
|
|
18
|
+
const newProps = {
|
|
19
|
+
...props,
|
|
20
|
+
...override
|
|
21
|
+
};
|
|
22
|
+
const originalClass = props?.class || props?.className;
|
|
23
|
+
const overrideClass = override.class || override.className;
|
|
24
|
+
if (originalClass && overrideClass) {
|
|
25
|
+
newProps.class = `${originalClass} ${overrideClass}`;
|
|
26
|
+
newProps.className = void 0;
|
|
27
|
+
}
|
|
28
|
+
return baseRuntime.createElement(tag, newProps, ...children);
|
|
29
|
+
}
|
|
30
|
+
return baseRuntime.createElement(tag, props, ...children);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
|
|
34
|
+
const intlayerNodePlugins = {
|
|
35
|
+
id: "intlayer-node-plugin",
|
|
36
|
+
canHandle: (node) => typeof node === "bigint" || typeof node === "string" || typeof node === "number",
|
|
37
|
+
transform: (_node, { children, ...rest }) => renderIntlayerNode({
|
|
38
|
+
...rest,
|
|
39
|
+
value: children,
|
|
40
|
+
children: () => ({
|
|
41
|
+
component: configuration?.editor.enabled ? ContentSelectorWrapperComponent : children,
|
|
42
|
+
props: {
|
|
43
|
+
dictionaryKey: rest.dictionaryKey,
|
|
44
|
+
keyPath: rest.keyPath
|
|
45
|
+
},
|
|
46
|
+
children
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
};
|
|
50
|
+
/** Markdown string plugin. Replaces string node with a component that render the markdown. */
|
|
51
|
+
const markdownStringPlugin = {
|
|
52
|
+
id: "markdown-string-plugin",
|
|
53
|
+
canHandle: (node) => typeof node === "string",
|
|
54
|
+
transform: (node, props, deepTransformNode) => {
|
|
55
|
+
const { plugins, ...rest } = props;
|
|
56
|
+
const metadataNodes = deepTransformNode(getMarkdownMetadata(node), {
|
|
57
|
+
plugins: [{
|
|
58
|
+
id: "markdown-metadata-plugin",
|
|
59
|
+
canHandle: (metadataNode) => typeof metadataNode === "string" || typeof metadataNode === "number" || typeof metadataNode === "boolean" || !metadataNode,
|
|
60
|
+
transform: (metadataNode, props) => renderIntlayerNode({
|
|
61
|
+
...props,
|
|
62
|
+
value: metadataNode,
|
|
63
|
+
children: node
|
|
64
|
+
})
|
|
65
|
+
}],
|
|
66
|
+
dictionaryKey: rest.dictionaryKey,
|
|
67
|
+
keyPath: []
|
|
68
|
+
});
|
|
69
|
+
const render = (components) => renderIntlayerNode({
|
|
70
|
+
...rest,
|
|
71
|
+
value: node,
|
|
72
|
+
children: configuration?.editor.enabled ? () => ({
|
|
73
|
+
component: ContentSelectorWrapperComponent,
|
|
74
|
+
props: {
|
|
75
|
+
dictionaryKey: rest.dictionaryKey,
|
|
76
|
+
keyPath: rest.keyPath,
|
|
77
|
+
...components
|
|
78
|
+
},
|
|
79
|
+
children: () => {
|
|
80
|
+
const { renderMarkdown } = useMarkdown();
|
|
81
|
+
return renderMarkdown(node, components);
|
|
82
|
+
}
|
|
83
|
+
}) : () => {
|
|
84
|
+
const { renderMarkdown } = useMarkdown();
|
|
85
|
+
return renderMarkdown(node, components);
|
|
86
|
+
},
|
|
87
|
+
additionalProps: { metadata: metadataNodes }
|
|
88
|
+
});
|
|
89
|
+
const createProxy = (element, components) => new Proxy(element, { get(target, prop, receiver) {
|
|
90
|
+
if (prop === "value") return node;
|
|
91
|
+
if (prop === "metadata") return metadataNodes;
|
|
92
|
+
if (prop === "toString") return () => {
|
|
93
|
+
return compile(node, { runtime: components ? createRuntimeWithOverides(htmlRuntime, components) : htmlRuntime });
|
|
94
|
+
};
|
|
95
|
+
if (prop === Symbol.toPrimitive) return () => {
|
|
96
|
+
return compile(node, { runtime: components ? createRuntimeWithOverides(htmlRuntime, components) : htmlRuntime });
|
|
97
|
+
};
|
|
98
|
+
if (prop === "use") return (newComponents) => {
|
|
99
|
+
const mergedComponents = {
|
|
100
|
+
...components,
|
|
101
|
+
...newComponents
|
|
102
|
+
};
|
|
103
|
+
return createProxy(render(mergedComponents), mergedComponents);
|
|
104
|
+
};
|
|
105
|
+
return Reflect.get(target, prop, receiver);
|
|
106
|
+
} });
|
|
107
|
+
return createProxy(render());
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const markdownPlugin = {
|
|
111
|
+
id: "markdown-plugin",
|
|
112
|
+
canHandle: (node) => typeof node === "object" && node?.nodeType === NodeTypes.MARKDOWN,
|
|
113
|
+
transform: (node, props, deepTransformNode) => {
|
|
114
|
+
const newKeyPath = [...props.keyPath, { type: NodeTypes.MARKDOWN }];
|
|
115
|
+
const children = node[NodeTypes.MARKDOWN];
|
|
116
|
+
return deepTransformNode(children, {
|
|
117
|
+
...props,
|
|
118
|
+
children,
|
|
119
|
+
keyPath: newKeyPath,
|
|
120
|
+
plugins: [markdownStringPlugin, ...props.plugins ?? []]
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
/** HTML plugin. Replaces node with a function that takes components => IntlayerNode. */
|
|
125
|
+
const htmlPlugin = {
|
|
126
|
+
id: "html-plugin",
|
|
127
|
+
canHandle: (node) => typeof node === "object" && node?.nodeType === NodeTypes.HTML,
|
|
128
|
+
transform: (node, props) => {
|
|
129
|
+
const html = node[NodeTypes.HTML];
|
|
130
|
+
const { plugins, ...rest } = props;
|
|
131
|
+
const render = (userComponents) => renderIntlayerNode({
|
|
132
|
+
...rest,
|
|
133
|
+
value: html,
|
|
134
|
+
children: configuration?.editor.enabled ? () => ({
|
|
135
|
+
component: ContentSelectorWrapperComponent,
|
|
136
|
+
props: {
|
|
137
|
+
dictionaryKey: rest.dictionaryKey,
|
|
138
|
+
keyPath: rest.keyPath,
|
|
139
|
+
...userComponents
|
|
140
|
+
},
|
|
141
|
+
children: html
|
|
142
|
+
}) : html
|
|
143
|
+
});
|
|
144
|
+
const createProxy = (element, components) => new Proxy(element, { get(target, prop, receiver) {
|
|
145
|
+
if (prop === "value") return html;
|
|
146
|
+
if (prop === "toString") return () => {
|
|
147
|
+
if (!components || typeof components === "object" && Object.keys(components).length === 0) return String(html);
|
|
148
|
+
return compile(html, { runtime: createRuntimeWithOverides(htmlRuntime, components) });
|
|
149
|
+
};
|
|
150
|
+
if (prop === Symbol.toPrimitive) return () => {
|
|
151
|
+
if (!components || typeof components === "object" && Object.keys(components).length === 0) return String(html);
|
|
152
|
+
return compile(html, { runtime: createRuntimeWithOverides(htmlRuntime, components) });
|
|
153
|
+
};
|
|
154
|
+
if (prop === "use") return (userComponents) => {
|
|
155
|
+
const mergedComponents = {
|
|
156
|
+
...components,
|
|
157
|
+
...userComponents
|
|
158
|
+
};
|
|
159
|
+
return createProxy(render(mergedComponents), mergedComponents);
|
|
160
|
+
};
|
|
161
|
+
return Reflect.get(target, prop, receiver);
|
|
162
|
+
} });
|
|
163
|
+
return createProxy(render());
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
const insertionPlugin = {
|
|
167
|
+
id: "insertion-plugin",
|
|
168
|
+
canHandle: (node) => typeof node === "object" && node?.nodeType === NodeTypes.INSERTION,
|
|
169
|
+
transform: (node, props) => {
|
|
170
|
+
const { plugins, ...rest } = props;
|
|
171
|
+
const render = (args = {}) => {
|
|
172
|
+
let text = node[NodeTypes.INSERTION];
|
|
173
|
+
if (args) Object.entries(args).forEach(([key, value]) => {
|
|
174
|
+
text = text.replace(new RegExp(`{{\\s*${key}\\s*}}`, "g"), String(value));
|
|
175
|
+
});
|
|
176
|
+
return text;
|
|
177
|
+
};
|
|
178
|
+
return renderIntlayerNode({
|
|
179
|
+
...rest,
|
|
180
|
+
value: render,
|
|
181
|
+
children: render
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Get the plugins array for Angular content transformation.
|
|
187
|
+
* This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.
|
|
188
|
+
*/
|
|
189
|
+
const getPlugins = (locale, fallback = true) => [
|
|
190
|
+
translationPlugin(locale ?? configuration.internationalization.defaultLocale, fallback ? configuration.internationalization.defaultLocale : void 0),
|
|
191
|
+
enumerationPlugin,
|
|
192
|
+
conditionPlugin,
|
|
193
|
+
nestedPlugin(locale ?? configuration.internationalization.defaultLocale),
|
|
194
|
+
filePlugin,
|
|
195
|
+
genderPlugin,
|
|
196
|
+
intlayerNodePlugins,
|
|
197
|
+
markdownPlugin,
|
|
198
|
+
htmlPlugin,
|
|
199
|
+
insertionPlugin
|
|
200
|
+
];
|
|
201
|
+
|
|
202
|
+
//#endregion
|
|
203
|
+
export { getPlugins, htmlPlugin, insertionPlugin, intlayerNodePlugins, markdownPlugin, markdownStringPlugin };
|
|
2
204
|
//# sourceMappingURL=plugins.mjs.map
|