svelte-intlayer 8.4.10 → 8.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/IntlayerNodeWrapper.svelte +13 -5
  2. package/dist/IntlayerNodeWrapper.svelte.d.ts +3 -3
  3. package/dist/client/index.d.ts +0 -1
  4. package/dist/client/index.js +0 -1
  5. package/dist/client/useLocale.d.ts +2 -2
  6. package/dist/client/useLocaleStorage.d.ts +2 -2
  7. package/dist/format/index.d.ts +9 -0
  8. package/dist/format/index.js +9 -0
  9. package/dist/format/useCompact.d.ts +3 -0
  10. package/dist/format/useCompact.js +10 -0
  11. package/dist/format/useCurrency.d.ts +3 -0
  12. package/dist/format/useCurrency.js +10 -0
  13. package/dist/format/useDate.d.ts +9 -0
  14. package/dist/format/useDate.js +18 -0
  15. package/dist/format/useIntl.d.ts +6 -0
  16. package/dist/format/useIntl.js +13 -0
  17. package/dist/format/useList.d.ts +7 -0
  18. package/dist/format/useList.js +10 -0
  19. package/dist/format/useNumber.d.ts +9 -0
  20. package/dist/format/useNumber.js +16 -0
  21. package/dist/format/usePercentage.d.ts +3 -0
  22. package/dist/format/usePercentage.js +10 -0
  23. package/dist/format/useRelativeTime.d.ts +4 -0
  24. package/dist/format/useRelativeTime.js +10 -0
  25. package/dist/format/useUnit.d.ts +3 -0
  26. package/dist/format/useUnit.js +10 -0
  27. package/dist/html/context.d.ts +1 -0
  28. package/dist/html/context.js +1 -0
  29. package/dist/html/index.d.ts +2 -2
  30. package/dist/html/index.js +3 -3
  31. package/dist/index.d.ts +0 -5
  32. package/dist/index.js +0 -5
  33. package/dist/markdown/MarkdownProvider.svelte +5 -5
  34. package/dist/markdown/MarkdownProvider.svelte.d.ts +3 -3
  35. package/dist/markdown/MarkdownRenderer.svelte +3 -1
  36. package/dist/markdown/context.d.ts +3 -2
  37. package/dist/markdown/context.js +1 -1
  38. package/dist/markdown/index.d.ts +5 -6
  39. package/dist/markdown/index.js +5 -8
  40. package/dist/plugins.js +19 -6
  41. package/dist/renderIntlayerNode.js +3 -5
  42. package/package.json +17 -7
  43. package/dist/client/useIntl.d.ts +0 -25
  44. package/dist/client/useIntl.js +0 -32
@@ -1,10 +1,18 @@
1
1
  <script lang="ts">
2
- export let Renderer: any;
3
- export let rendererProps: Record<string, any>;
4
- export let value: any;
2
+ export let Renderer: any = undefined;
3
+ export let rendererProps: Record<string, any> = {};
4
+ export let value: any = undefined;
5
5
  </script>
6
6
 
7
- <svelte:component this={Renderer} {...rendererProps}>
7
+ {#if typeof Renderer === 'string'}
8
+ <svelte:element this={Renderer} {...rendererProps}>
9
+ {value}
10
+ </svelte:element>
11
+ {:else if typeof Renderer === 'function'}
12
+ <svelte:component this={Renderer} {...rendererProps}>
13
+ {value}
14
+ </svelte:component>
15
+ {:else}
8
16
  {value}
9
- </svelte:component>
17
+ {/if}
10
18
 
@@ -12,9 +12,9 @@ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> =
12
12
  z_$$bindings?: Bindings;
13
13
  }
14
14
  declare const IntlayerNodeWrapper: $$__sveltets_2_IsomorphicComponent<{
15
- Renderer: any;
16
- rendererProps: Record<string, any>;
17
- value: any;
15
+ Renderer?: any;
16
+ rendererProps?: Record<string, any>;
17
+ value?: any;
18
18
  }, {
19
19
  [evt: string]: CustomEvent<any>;
20
20
  }, {}, {}, string>;
@@ -6,7 +6,6 @@ export { setupIntlayer } from './setupIntlayer.svelte';
6
6
  export { useDictionary } from './useDictionary';
7
7
  export { useDictionaryAsync } from './useDictionaryAsync';
8
8
  export { useDictionaryDynamic } from './useDictionaryDynamic';
9
- export { useIntl } from './useIntl';
10
9
  export { useIntlayer } from './useIntlayer';
11
10
  export { useLocale } from './useLocale';
12
11
  export { useRewriteURL } from './useRewriteURL';
@@ -5,7 +5,6 @@ export { setupIntlayer } from './setupIntlayer.svelte';
5
5
  export { useDictionary } from './useDictionary';
6
6
  export { useDictionaryAsync } from './useDictionaryAsync';
7
7
  export { useDictionaryDynamic } from './useDictionaryDynamic';
8
- export { useIntl } from './useIntl';
9
8
  export { useIntlayer } from './useIntlayer';
10
9
  export { useLocale } from './useLocale';
11
10
  export { useRewriteURL } from './useRewriteURL';
@@ -26,7 +26,7 @@ type useLocaleProps = {
26
26
  export declare const useLocale: ({ isCookieEnabled, onLocaleChange, }?: useLocaleProps) => {
27
27
  locale: import("svelte/store").Readable<LocalesValues>;
28
28
  setLocale: (locale: LocalesValues) => void;
29
- defaultLocale: import("@intlayer/types/allLocales").Locale;
30
- availableLocales: import("@intlayer/types/allLocales").Locale[];
29
+ defaultLocale: import("intlayer").Locale;
30
+ availableLocales: import("intlayer").Locale[];
31
31
  };
32
32
  export {};
@@ -2,13 +2,13 @@ import type { LocalesValues } from '@intlayer/types/module_augmentation';
2
2
  /**
3
3
  * Get the locale cookie
4
4
  */
5
- export declare const localeInStorage: import("@intlayer/types/allLocales").Locale | undefined;
5
+ export declare const localeInStorage: import("intlayer").Locale | undefined;
6
6
  /**
7
7
  * @deprecated Use localeInStorage instead
8
8
  *
9
9
  * Get the locale cookie
10
10
  */
11
- export declare const localeCookie: import("@intlayer/types/allLocales").Locale | undefined;
11
+ export declare const localeCookie: import("intlayer").Locale | undefined;
12
12
  /**
13
13
  * Set the locale cookie
14
14
  */
@@ -0,0 +1,9 @@
1
+ export { useCompact } from './useCompact';
2
+ export { useCurrency } from './useCurrency';
3
+ export { useDate } from './useDate';
4
+ export { useIntl } from './useIntl';
5
+ export { useList } from './useList';
6
+ export { useNumber } from './useNumber';
7
+ export { usePercentage } from './usePercentage';
8
+ export { useRelativeTime } from './useRelativeTime';
9
+ export { useUnit } from './useUnit';
@@ -0,0 +1,9 @@
1
+ export { useCompact } from './useCompact';
2
+ export { useCurrency } from './useCurrency';
3
+ export { useDate } from './useDate';
4
+ export { useIntl } from './useIntl';
5
+ export { useList } from './useList';
6
+ export { useNumber } from './useNumber';
7
+ export { usePercentage } from './usePercentage';
8
+ export { useRelativeTime } from './useRelativeTime';
9
+ export { useUnit } from './useUnit';
@@ -0,0 +1,3 @@
1
+ export declare const useCompact: () => import("svelte/store").Readable<(value: string | number, options?: (Intl.NumberFormatOptions & {
2
+ locale?: import("intlayer").LocalesValues;
3
+ }) | undefined) => string>;
@@ -0,0 +1,10 @@
1
+ import { compact } from '@intlayer/core/formatters';
2
+ import { derived } from 'svelte/store';
3
+ import { useLocale } from '../client/useLocale';
4
+ export const useCompact = () => {
5
+ const { locale } = useLocale();
6
+ return derived(locale, ($locale) => (...args) => compact(args[0], {
7
+ ...args[1],
8
+ locale: args[1]?.locale ?? $locale,
9
+ }));
10
+ };
@@ -0,0 +1,3 @@
1
+ export declare const useCurrency: () => import("svelte/store").Readable<(value: string | number, options?: (Intl.NumberFormatOptions & {
2
+ locale?: import("intlayer").LocalesValues;
3
+ }) | undefined) => string>;
@@ -0,0 +1,10 @@
1
+ import { currency } from '@intlayer/core/formatters';
2
+ import { derived } from 'svelte/store';
3
+ import { useLocale } from '../client/useLocale';
4
+ export const useCurrency = () => {
5
+ const { locale } = useLocale();
6
+ return derived(locale, ($locale) => (...args) => currency(args[0], {
7
+ ...args[1],
8
+ locale: args[1]?.locale ?? $locale,
9
+ }));
10
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Svelte store that provides a localized date/time formatter.
3
+ *
4
+ * @returns {import('svelte/store').Readable<(...args: Parameters<typeof date>) => string>}
5
+ * A store containing a date/time formatting function bound to the active locale.
6
+ */
7
+ export declare const useDate: () => import("svelte/store").Readable<(date: string | number | Date, options?: import("@intlayer/core/formatters").DateTimePreset | (Intl.DateTimeFormatOptions & {
8
+ locale?: import("intlayer").LocalesValues;
9
+ }) | undefined) => string>;
@@ -0,0 +1,18 @@
1
+ import { date, presets } from '@intlayer/core/formatters';
2
+ import { derived } from 'svelte/store';
3
+ import { useLocale } from '../client/useLocale';
4
+ /**
5
+ * Svelte store that provides a localized date/time formatter.
6
+ *
7
+ * @returns {import('svelte/store').Readable<(...args: Parameters<typeof date>) => string>}
8
+ * A store containing a date/time formatting function bound to the active locale.
9
+ */
10
+ export const useDate = () => {
11
+ const { locale } = useLocale();
12
+ return derived(locale, ($locale) => (...args) => {
13
+ const options = typeof args[1] === 'string'
14
+ ? { ...presets[args[1]], locale: $locale }
15
+ : { ...args[1], locale: args[1]?.locale ?? $locale };
16
+ return date(args[0], options);
17
+ });
18
+ };
@@ -0,0 +1,6 @@
1
+ import { type WrappedIntl } from '@intlayer/core/formatters';
2
+ import type { LocalesValues } from '@intlayer/types/module_augmentation';
3
+ /**
4
+ * Svelte store that provides a locale-bound `Intl` object.
5
+ */
6
+ export declare const useIntl: (locale?: LocalesValues) => import("svelte/store").Readable<WrappedIntl>;
@@ -0,0 +1,13 @@
1
+ import { bindIntl } from '@intlayer/core/formatters';
2
+ import { derived } from 'svelte/store';
3
+ import { useLocale } from '../client/useLocale';
4
+ /**
5
+ * Svelte store that provides a locale-bound `Intl` object.
6
+ */
7
+ export const useIntl = (locale) => {
8
+ const { locale: contextLocale } = useLocale();
9
+ return derived(contextLocale, ($locale) => {
10
+ const currentLocale = locale ?? $locale;
11
+ return bindIntl(currentLocale);
12
+ });
13
+ };
@@ -0,0 +1,7 @@
1
+ export declare const useList: () => import("svelte/store").Readable<(values: (string | number)[], options?: ({
2
+ localeMatcher?: "lookup" | "best fit";
3
+ type?: "conjunction" | "disjunction" | "unit";
4
+ style?: "long" | "short" | "narrow";
5
+ } & {
6
+ locale?: import("intlayer").LocalesValues;
7
+ }) | undefined) => string>;
@@ -0,0 +1,10 @@
1
+ import { list } from '@intlayer/core/formatters';
2
+ import { derived } from 'svelte/store';
3
+ import { useLocale } from '../client/useLocale';
4
+ export const useList = () => {
5
+ const { locale } = useLocale();
6
+ return derived(locale, ($locale) => (...args) => list(args[0], {
7
+ ...args[1],
8
+ locale: args[1]?.locale ?? $locale,
9
+ }));
10
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Svelte store that provides a localized number formatter.
3
+ *
4
+ * @returns {import('svelte/store').Readable<(...args: Parameters<typeof number>) => string>}
5
+ * A store containing a number formatting function bound to the active locale.
6
+ */
7
+ export declare const useNumber: () => import("svelte/store").Readable<(value: string | number, options?: (Intl.NumberFormatOptions & {
8
+ locale?: import("intlayer").LocalesValues;
9
+ }) | undefined) => string>;
@@ -0,0 +1,16 @@
1
+ import { number } from '@intlayer/core/formatters';
2
+ import { derived } from 'svelte/store';
3
+ import { useLocale } from '../client/useLocale';
4
+ /**
5
+ * Svelte store that provides a localized number formatter.
6
+ *
7
+ * @returns {import('svelte/store').Readable<(...args: Parameters<typeof number>) => string>}
8
+ * A store containing a number formatting function bound to the active locale.
9
+ */
10
+ export const useNumber = () => {
11
+ const { locale } = useLocale();
12
+ return derived(locale, ($locale) => (...args) => number(args[0], {
13
+ ...args[1],
14
+ locale: args[1]?.locale ?? $locale,
15
+ }));
16
+ };
@@ -0,0 +1,3 @@
1
+ export declare const usePercentage: () => import("svelte/store").Readable<(value: string | number, options?: (Intl.NumberFormatOptions & {
2
+ locale?: import("intlayer").LocalesValues;
3
+ }) | undefined) => string>;
@@ -0,0 +1,10 @@
1
+ import { percentage } from '@intlayer/core/formatters';
2
+ import { derived } from 'svelte/store';
3
+ import { useLocale } from '../client/useLocale';
4
+ export const usePercentage = () => {
5
+ const { locale } = useLocale();
6
+ return derived(locale, ($locale) => (...args) => percentage(args[0], {
7
+ ...args[1],
8
+ locale: args[1]?.locale ?? $locale,
9
+ }));
10
+ };
@@ -0,0 +1,4 @@
1
+ export declare const useRelativeTime: () => import("svelte/store").Readable<(from: string | number | Date, to?: string | number | Date | undefined, options?: (Intl.RelativeTimeFormatOptions & {
2
+ locale?: import("intlayer").LocalesValues;
3
+ unit?: Intl.RelativeTimeFormatUnit;
4
+ }) | undefined) => string>;
@@ -0,0 +1,10 @@
1
+ import { relativeTime } from '@intlayer/core/formatters';
2
+ import { derived } from 'svelte/store';
3
+ import { useLocale } from '../client/useLocale';
4
+ export const useRelativeTime = () => {
5
+ const { locale } = useLocale();
6
+ return derived(locale, ($locale) => (...args) => relativeTime(args[0], args[1], {
7
+ ...args[2],
8
+ locale: args[2]?.locale ?? $locale,
9
+ }));
10
+ };
@@ -0,0 +1,3 @@
1
+ export declare const useUnit: () => import("svelte/store").Readable<(value: string | number, options?: (Intl.NumberFormatOptions & {
2
+ locale?: import("intlayer").LocalesValues;
3
+ }) | undefined) => string>;
@@ -0,0 +1,10 @@
1
+ import { units } from '@intlayer/core/formatters';
2
+ import { derived } from 'svelte/store';
3
+ import { useLocale } from '../client/useLocale';
4
+ export const useUnit = () => {
5
+ const { locale } = useLocale();
6
+ return derived(locale, ($locale) => (...args) => units(args[0], {
7
+ ...args[1],
8
+ locale: args[1]?.locale ?? $locale,
9
+ }));
10
+ };
@@ -6,4 +6,5 @@ export type HTMLContextValue = {
6
6
  renderHTML: (html: string, overrides?: HTMLComponents<'permissive', {}> | RenderHTMLOptions) => string;
7
7
  };
8
8
  export declare const setHTMLContext: (value: HTMLContextValue) => void;
9
+ export { setHTMLContext as setIntlayerHTML };
9
10
  export declare const getHTMLContext: () => HTMLContextValue;
@@ -3,6 +3,7 @@ const INTLAYER_HTML_CONTEXT_KEY = Symbol('intlayer-html-context');
3
3
  export const setHTMLContext = (value) => {
4
4
  setContext(INTLAYER_HTML_CONTEXT_KEY, value);
5
5
  };
6
+ export { setHTMLContext as setIntlayerHTML };
6
7
  export const getHTMLContext = () => {
7
8
  const context = getContext(INTLAYER_HTML_CONTEXT_KEY);
8
9
  return (context || {
@@ -1,7 +1,7 @@
1
- export * from './context';
1
+ import { type RenderHTMLOptions } from './context';
2
+ export { getHTMLContext, type HTMLContext, type RenderHTMLOptions, setHTMLContext, setHTMLContext as setIntlayerHTML, } from './context';
2
3
  export { default as HTMLProvider } from './HTMLProvider.svelte';
3
4
  export { default as HTMLRenderer } from './HTMLRenderer.svelte';
4
- import { type RenderHTMLOptions } from './context';
5
5
  export type RenderHTMLProps = RenderHTMLOptions;
6
6
  export declare const renderHTML: (html: string, options?: RenderHTMLProps) => any;
7
7
  export declare const useHTMLRenderer: (options?: RenderHTMLProps) => (html: string) => string;
@@ -1,8 +1,8 @@
1
- export * from './context';
2
- export { default as HTMLProvider } from './HTMLProvider.svelte';
3
- export { default as HTMLRenderer } from './HTMLRenderer.svelte';
4
1
  import { getHTML } from '@intlayer/core/interpreter';
5
2
  import { getHTMLContext } from './context';
3
+ export { getHTMLContext, setHTMLContext, setHTMLContext as setIntlayerHTML, } from './context';
4
+ export { default as HTMLProvider } from './HTMLProvider.svelte';
5
+ export { default as HTMLRenderer } from './HTMLRenderer.svelte';
6
6
  export const renderHTML = (html, options = {}) => {
7
7
  return getHTML(html, (options.components || {}));
8
8
  };
package/dist/index.d.ts CHANGED
@@ -7,9 +7,4 @@ declare module '@intlayer/core/interpreter' {
7
7
  export * from './client';
8
8
  export * from './getDictionary';
9
9
  export * from './getIntlayer';
10
- export * from './html';
11
- export * from './markdown';
12
10
  export * from './plugins';
13
- import { setHTMLContext } from './html';
14
- import { setMarkdownContext } from './markdown';
15
- export { setHTMLContext as setIntlayerHTML, setMarkdownContext as setIntlayerMarkdown, };
package/dist/index.js CHANGED
@@ -1,9 +1,4 @@
1
1
  export * from './client';
2
2
  export * from './getDictionary';
3
3
  export * from './getIntlayer';
4
- export * from './html';
5
- export * from './markdown';
6
4
  export * from './plugins';
7
- import { setHTMLContext } from './html';
8
- import { setMarkdownContext } from './markdown';
9
- export { setHTMLContext as setIntlayerHTML, setMarkdownContext as setIntlayerMarkdown, };
@@ -5,7 +5,7 @@ import { setMarkdownContext } from './context';
5
5
 
6
6
  export const components: HTMLComponents<'permissive', {}> | undefined =
7
7
  undefined;
8
- export const wrapper: any = undefined;
8
+ export const wrapper: string | import('svelte').ComponentType | undefined = undefined;
9
9
  export const forceBlock: boolean | undefined = undefined;
10
10
  export const forceInline: boolean | undefined = undefined;
11
11
  export const preserveFrontmatter: boolean | undefined = undefined;
@@ -16,8 +16,8 @@ let customRenderMarkdown:
16
16
  markdown: string,
17
17
  options?: any,
18
18
  components?: HTMLComponents<'permissive', {}>,
19
- wrapper?: any
20
- ) => string)
19
+ wrapper?: string | import('svelte').ComponentType
20
+ ) => string | Promise<string>)
21
21
  | undefined;
22
22
  export { customRenderMarkdown as renderMarkdown };
23
23
 
@@ -39,7 +39,7 @@ const internalRenderMarkdown = (
39
39
  tagfilter?: boolean;
40
40
  },
41
41
  componentsOverride?: HTMLComponents<'permissive', {}>,
42
- wrapperOverride?: any
42
+ wrapperOverride?: string | import('svelte').ComponentType
43
43
  ) => {
44
44
  if (typeof customRenderMarkdown === 'function') {
45
45
  return customRenderMarkdown(
@@ -56,7 +56,7 @@ const internalRenderMarkdown = (
56
56
  preserveFrontmatter:
57
57
  options?.preserveFrontmatter ?? baseOptions.preserveFrontmatter,
58
58
  tagfilter: options?.tagfilter ?? baseOptions.tagfilter,
59
- wrapper: wrapperOverride || baseOptions.wrapper,
59
+ wrapper: (wrapperOverride || baseOptions.wrapper) as string,
60
60
  forceWrapper: !!(wrapperOverride || baseOptions.wrapper),
61
61
  components: {
62
62
  ...baseOptions.components,
@@ -19,12 +19,12 @@ type $$__sveltets_2_PropsWithChildren<Props, Slots> = Props & (Slots extends {
19
19
  } : {});
20
20
  declare const MarkdownProvider: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWithChildren<{
21
21
  components?: HTMLComponents<"permissive", {}> | undefined;
22
- wrapper?: any;
22
+ wrapper?: string | import("svelte").ComponentType | undefined;
23
23
  forceBlock?: boolean | undefined;
24
24
  forceInline?: boolean | undefined;
25
25
  preserveFrontmatter?: boolean | undefined;
26
26
  tagfilter?: boolean | undefined;
27
- renderMarkdown: ((markdown: string, options?: any, components?: HTMLComponents<"permissive", {}>, wrapper?: any) => string) | undefined;
27
+ renderMarkdown: ((markdown: string, options?: any, components?: HTMLComponents<"permissive", {}>, wrapper?: string | import("svelte").ComponentType) => string | Promise<string>) | undefined;
28
28
  }, {
29
29
  default: {};
30
30
  }>, {
@@ -33,7 +33,7 @@ declare const MarkdownProvider: $$__sveltets_2_IsomorphicComponent<$$__sveltets_
33
33
  default: {};
34
34
  }, {
35
35
  components: HTMLComponents<"permissive", {}> | undefined;
36
- wrapper: any;
36
+ wrapper: string | import("svelte").ComponentType | undefined;
37
37
  forceBlock: boolean | undefined;
38
38
  forceInline: boolean | undefined;
39
39
  preserveFrontmatter: boolean | undefined;
@@ -29,4 +29,6 @@ $: htmlContent = context.renderMarkdown(
29
29
  );
30
30
  </script>
31
31
 
32
- {@html htmlContent}
32
+ {#await htmlContent then resolvedHtmlContent}
33
+ {@html resolvedHtmlContent}
34
+ {/await}
@@ -1,3 +1,4 @@
1
+ import { type ComponentType } from 'svelte';
1
2
  import type { HTMLComponents } from '../html/types';
2
3
  export declare const MARKDOWN_CONTEXT_KEY: unique symbol;
3
4
  export type MarkdownProviderOptions = {
@@ -8,11 +9,11 @@ export type MarkdownProviderOptions = {
8
9
  };
9
10
  export type RenderMarkdownOptions = MarkdownProviderOptions & {
10
11
  components?: HTMLComponents<'permissive', {}>;
11
- wrapper?: any;
12
+ wrapper?: string | ComponentType;
12
13
  };
13
14
  export interface MarkdownContext {
14
15
  components?: HTMLComponents<'permissive', {}>;
15
- renderMarkdown: (markdown: string, options?: MarkdownProviderOptions, components?: HTMLComponents<'permissive', {}>, wrapper?: any) => string;
16
+ renderMarkdown: (markdown: string, options?: MarkdownProviderOptions, components?: HTMLComponents<'permissive', {}>, wrapper?: string | ComponentType) => string | Promise<string>;
16
17
  }
17
18
  export declare const getMarkdownContext: () => MarkdownContext;
18
19
  export declare const setMarkdownContext: (context: MarkdownContext) => void;
@@ -5,7 +5,7 @@ export const getMarkdownContext = () => {
5
5
  return (getContext(MARKDOWN_CONTEXT_KEY) || {
6
6
  renderMarkdown: (md, _options, components, wrapper) => compileMarkdown(md, {
7
7
  components,
8
- wrapper,
8
+ wrapper: wrapper,
9
9
  forceWrapper: !!wrapper,
10
10
  }),
11
11
  });
@@ -1,10 +1,9 @@
1
- export * from './compiler';
2
- export * from './context';
1
+ export { compileMarkdown } from './compiler';
2
+ export { getMarkdownContext, type MarkdownContext, type RenderMarkdownOptions, setMarkdownContext, setMarkdownContext as setIntlayerMarkdown, } from './context';
3
+ import { type RenderMarkdownOptions } from './context';
3
4
  export { default as MarkdownMetadataRenderer } from './MarkdownMetadataRenderer.svelte';
4
5
  export { default as MarkdownProvider } from './MarkdownProvider.svelte';
5
6
  export { default as MarkdownRenderer } from './MarkdownRenderer.svelte';
6
- export * from './runtime';
7
- import { type RenderMarkdownOptions } from './context';
8
7
  export type RenderMarkdownProps = RenderMarkdownOptions;
9
- export declare const renderMarkdown: (content: string, options?: RenderMarkdownProps) => string;
10
- export declare const useMarkdownRenderer: (options?: RenderMarkdownProps) => (content: string) => string;
8
+ export declare const renderMarkdown: (markdown?: string, options?: any) => unknown;
9
+ export declare const useMarkdownRenderer: (options?: RenderMarkdownProps) => (content: string) => string | Promise<string>;
@@ -1,14 +1,11 @@
1
- export * from './compiler';
2
- export * from './context';
1
+ export { compileMarkdown } from './compiler';
2
+ export { getMarkdownContext, setMarkdownContext, setMarkdownContext as setIntlayerMarkdown, } from './context';
3
+ import { compileMarkdown } from './compiler';
4
+ import { getMarkdownContext } from './context';
3
5
  export { default as MarkdownMetadataRenderer } from './MarkdownMetadataRenderer.svelte';
4
6
  export { default as MarkdownProvider } from './MarkdownProvider.svelte';
5
7
  export { default as MarkdownRenderer } from './MarkdownRenderer.svelte';
6
- export * from './runtime';
7
- import { compileMarkdown } from './compiler';
8
- import { getMarkdownContext } from './context';
9
- export const renderMarkdown = (content, options = {}) => {
10
- return compileMarkdown(content, options);
11
- };
8
+ export const renderMarkdown = compileMarkdown;
12
9
  export const useMarkdownRenderer = (options = {}) => {
13
10
  const context = getMarkdownContext();
14
11
  return (content) => context.renderMarkdown(content, options);
package/dist/plugins.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import configuration from '@intlayer/config/built';
2
2
  import { conditionPlugin, enumerationPlugin, filePlugin, genderPlugin, getHTML, nestedPlugin, translationPlugin, } from '@intlayer/core/interpreter';
3
3
  import { HTML_TAGS, } from '@intlayer/core/transpiler';
4
+ import { isEnabled } from '@intlayer/editor/isEnabled';
4
5
  import * as NodeTypes from '@intlayer/types/nodeType';
5
6
  import { default as ContentSelector } from './editor/ContentSelector.svelte';
6
7
  import { renderIntlayerNode } from './renderIntlayerNode';
@@ -34,9 +35,7 @@ export const intlayerNodePlugins = {
34
35
  typeof node === 'number',
35
36
  transform: (node, { children, ...rest }) => renderIntlayerNode({
36
37
  value: children ?? node,
37
- component: configuration?.editor.enabled
38
- ? ContentSelector
39
- : (children ?? node),
38
+ component: isEnabled ? ContentSelector : undefined,
40
39
  props: rest,
41
40
  }),
42
41
  };
@@ -128,12 +127,26 @@ export const insertionPlugin = {
128
127
  };
129
128
  },
130
129
  };
131
- return deepTransformNode(children, {
130
+ const result = deepTransformNode(children, {
132
131
  ...props,
133
132
  children,
134
133
  keyPath: newKeyPath,
135
134
  plugins: [insertionStringPlugin, ...(props.plugins ?? [])],
136
135
  });
136
+ if (typeof children === 'object' &&
137
+ children !== null &&
138
+ 'nodeType' in children &&
139
+ [NodeTypes.ENUMERATION, NodeTypes.CONDITION].includes(children.nodeType)) {
140
+ return (values) => (arg) => {
141
+ const func = result;
142
+ const inner = func(arg);
143
+ if (typeof inner === 'function') {
144
+ return inner(values);
145
+ }
146
+ return inner;
147
+ };
148
+ }
149
+ return result;
137
150
  },
138
151
  };
139
152
  /** Markdown string plugin. Replaces string node with a component that render the markdown. */
@@ -151,7 +164,7 @@ export const markdownStringPlugin = {
151
164
  !metadataNode,
152
165
  transform: (metadataNode, props) => renderIntlayerNode({
153
166
  value: metadataNode,
154
- component: configuration?.editor.enabled
167
+ component: isEnabled
155
168
  ? (_MarkdownMetadataWithSelector ?? _MarkdownMetadataRenderer)
156
169
  : _MarkdownMetadataRenderer,
157
170
  props: {
@@ -170,7 +183,7 @@ export const markdownStringPlugin = {
170
183
  const render = (components) => {
171
184
  const nodeResult = renderIntlayerNode({
172
185
  value: node,
173
- component: configuration?.editor.enabled
186
+ component: isEnabled
174
187
  ? (_MarkdownWithSelector ?? _MarkdownRenderer)
175
188
  : _MarkdownRenderer,
176
189
  props: {
@@ -20,14 +20,12 @@ export const renderIntlayerNode = (args) => {
20
20
  }
21
21
  else {
22
22
  // Functional component (Svelte 5)
23
- Node = (anchor, props) => {
24
- const mergedProps = {
25
- ...props,
23
+ Node = (props) => {
24
+ return IntlayerNodeWrapper(props, {
26
25
  Renderer: args.component,
27
26
  rendererProps: args.props,
28
27
  value: args.value,
29
- };
30
- return IntlayerNodeWrapper(anchor, mergedProps);
28
+ });
31
29
  };
32
30
  }
33
31
  Object.defineProperty(Node, 'value', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-intlayer",
3
- "version": "8.4.10",
3
+ "version": "8.5.1",
4
4
  "description": "Easily internationalize i18n your Svelte applications with type-safe multilingual content management.",
5
5
  "keywords": [
6
6
  "intlayer",
@@ -44,6 +44,16 @@
44
44
  "svelte": "./dist/markdown/index.js",
45
45
  "default": "./dist/markdown/index.js"
46
46
  },
47
+ "./html": {
48
+ "types": "./dist/html/index.d.ts",
49
+ "svelte": "./dist/html/index.js",
50
+ "default": "./dist/html/index.js"
51
+ },
52
+ "./format": {
53
+ "types": "./dist/format/index.d.ts",
54
+ "svelte": "./dist/format/index.js",
55
+ "default": "./dist/format/index.js"
56
+ },
47
57
  "./package.json": "./package.json"
48
58
  },
49
59
  "main": "dist/index.js",
@@ -72,11 +82,11 @@
72
82
  "typecheck": "tsc --noEmit --project tsconfig.types.json"
73
83
  },
74
84
  "dependencies": {
75
- "@intlayer/api": "8.4.10",
76
- "@intlayer/config": "8.4.10",
77
- "@intlayer/core": "8.4.10",
78
- "@intlayer/editor": "8.4.10",
79
- "@intlayer/types": "8.4.10"
85
+ "@intlayer/api": "8.5.1",
86
+ "@intlayer/config": "8.5.1",
87
+ "@intlayer/core": "8.5.1",
88
+ "@intlayer/editor": "8.5.1",
89
+ "@intlayer/types": "8.5.1"
80
90
  },
81
91
  "devDependencies": {
82
92
  "@sveltejs/adapter-auto": "7.0.1",
@@ -87,7 +97,7 @@
87
97
  "@utils/ts-config-types": "1.0.4",
88
98
  "@utils/tsdown-config": "1.0.4",
89
99
  "rimraf": "6.1.3",
90
- "svelte": "5.53.11",
100
+ "svelte": "5.55.0",
91
101
  "svelte-check": "4.4.5",
92
102
  "tsdown": "0.21.4",
93
103
  "typescript": "6.0.2",
@@ -1,25 +0,0 @@
1
- import { type WrappedIntl } from '@intlayer/core/formatters';
2
- import type { LocalesValues } from '@intlayer/types/module_augmentation';
3
- /**
4
- * Svelte hook that provides a locale-bound `Intl` object.
5
- *
6
- * It acts exactly like the native `Intl` object, but acts as a proxy to:
7
- * 1. Inject the current locale automatically if none is provided.
8
- * 2. Use the performance-optimized `CachedIntl` under the hood.
9
- *
10
- * @example
11
- * ```svelte
12
- * <script>
13
- * import { useIntl } from "svelte-intlayer";
14
- *
15
- * const intl = useIntl();
16
- *
17
- * // Standard API, but no need to pass locale as the first argument
18
- * $: formatted = new $intl.NumberFormat({
19
- * style: 'currency',
20
- * currency: 'USD'
21
- * }).format(123.45);
22
- * </script>
23
- * ```
24
- */
25
- export declare const useIntl: (locale?: LocalesValues) => import("svelte/store").Readable<WrappedIntl>;
@@ -1,32 +0,0 @@
1
- import { bindIntl } from '@intlayer/core/formatters';
2
- import { derived } from 'svelte/store';
3
- import { useLocale } from './useLocale';
4
- /**
5
- * Svelte hook that provides a locale-bound `Intl` object.
6
- *
7
- * It acts exactly like the native `Intl` object, but acts as a proxy to:
8
- * 1. Inject the current locale automatically if none is provided.
9
- * 2. Use the performance-optimized `CachedIntl` under the hood.
10
- *
11
- * @example
12
- * ```svelte
13
- * <script>
14
- * import { useIntl } from "svelte-intlayer";
15
- *
16
- * const intl = useIntl();
17
- *
18
- * // Standard API, but no need to pass locale as the first argument
19
- * $: formatted = new $intl.NumberFormat({
20
- * style: 'currency',
21
- * currency: 'USD'
22
- * }).format(123.45);
23
- * </script>
24
- * ```
25
- */
26
- export const useIntl = (locale) => {
27
- const { locale: contextLocale } = useLocale();
28
- return derived(contextLocale, ($locale) => {
29
- const currentLocale = locale ?? $locale;
30
- return bindIntl(currentLocale);
31
- });
32
- };