vanilla-intlayer 8.5.0
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/README.md +290 -0
- package/dist/chunk-C91j1N6u.js +1 -0
- package/dist/cjs/client/index.cjs +1 -0
- package/dist/cjs/client/installIntlayer.cjs +1 -0
- package/dist/cjs/client/useDictionary.cjs +1 -0
- package/dist/cjs/client/useDictionaryDynamic.cjs +1 -0
- package/dist/cjs/client/useIntlayer.cjs +1 -0
- package/dist/cjs/client/useLocale.cjs +1 -0
- package/dist/cjs/client/useLocaleStorage.cjs +1 -0
- package/dist/cjs/client/useRewriteURL.cjs +1 -0
- package/dist/cjs/editor/useEditor.cjs +1 -0
- package/dist/cjs/format/index.cjs +1 -0
- package/dist/cjs/format/useIntl.cjs +1 -0
- package/dist/cjs/getDictionary.cjs +1 -0
- package/dist/cjs/getIntlayer.cjs +1 -0
- package/dist/cjs/html/HTMLRenderer.cjs +1 -0
- package/dist/cjs/html/index.cjs +1 -0
- package/dist/cjs/html/installIntlayerHTML.cjs +1 -0
- package/dist/cjs/html/types.cjs +1 -0
- package/dist/cjs/index.cjs +1 -0
- package/dist/cjs/markdown/MarkdownRenderer.cjs +1 -0
- package/dist/cjs/markdown/compiler.cjs +1 -0
- package/dist/cjs/markdown/index.cjs +1 -0
- package/dist/cjs/markdown/installIntlayerMarkdown.cjs +1 -0
- package/dist/cjs/markdown/runtime.cjs +1 -0
- package/dist/cjs/plugins.cjs +1 -0
- package/dist/cjs/renderIntlayerNode.cjs +1 -0
- package/dist/esm/client/index.mjs +8 -0
- package/dist/esm/client/installIntlayer.mjs +2 -0
- package/dist/esm/client/useDictionary.mjs +11 -0
- package/dist/esm/client/useDictionaryDynamic.mjs +37 -0
- package/dist/esm/client/useIntlayer.mjs +11 -0
- package/dist/esm/client/useLocale.mjs +22 -0
- package/dist/esm/client/useLocaleStorage.mjs +24 -0
- package/dist/esm/client/useRewriteURL.mjs +17 -0
- package/dist/esm/editor/useEditor.mjs +2 -0
- package/dist/esm/format/index.mjs +2 -0
- package/dist/esm/format/useIntl.mjs +14 -0
- package/dist/esm/getDictionary.mjs +6 -0
- package/dist/esm/getIntlayer.mjs +6 -0
- package/dist/esm/html/HTMLRenderer.mjs +8 -0
- package/dist/esm/html/index.mjs +3 -0
- package/dist/esm/html/installIntlayerHTML.mjs +18 -0
- package/dist/esm/html/types.mjs +0 -0
- package/dist/esm/index.mjs +13 -0
- package/dist/esm/markdown/MarkdownRenderer.mjs +19 -0
- package/dist/esm/markdown/compiler.mjs +6 -0
- package/dist/esm/markdown/index.mjs +4 -0
- package/dist/esm/markdown/installIntlayerMarkdown.mjs +31 -0
- package/dist/esm/markdown/runtime.mjs +51 -0
- package/dist/esm/plugins.mjs +135 -0
- package/dist/esm/renderIntlayerNode.mjs +25 -0
- package/dist/installIntlayer-BRDzSdO3.mjs +46 -0
- package/dist/installIntlayer-CieE91lh.js +1 -0
- package/dist/types/client/index.d.ts +7 -0
- package/dist/types/client/installIntlayer.d.ts +58 -0
- package/dist/types/client/useDictionary.d.ts +57 -0
- package/dist/types/client/useDictionaryDynamic.d.ts +35 -0
- package/dist/types/client/useIntlayer.d.ts +49 -0
- package/dist/types/client/useLocale.d.ts +40 -0
- package/dist/types/client/useLocaleStorage.d.ts +31 -0
- package/dist/types/client/useRewriteURL.d.ts +23 -0
- package/dist/types/editor/useEditor.d.ts +19 -0
- package/dist/types/format/index.d.ts +1 -0
- package/dist/types/format/useIntl.d.ts +31 -0
- package/dist/types/getDictionary.d.ts +4 -0
- package/dist/types/getIntlayer.d.ts +3 -0
- package/dist/types/html/HTMLRenderer.d.ts +14 -0
- package/dist/types/html/index.d.ts +3 -0
- package/dist/types/html/installIntlayerHTML.d.ts +62 -0
- package/dist/types/html/types.d.ts +42 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/markdown/MarkdownRenderer.d.ts +22 -0
- package/dist/types/markdown/compiler.d.ts +19 -0
- package/dist/types/markdown/index.d.ts +3 -0
- package/dist/types/markdown/installIntlayerMarkdown.d.ts +70 -0
- package/dist/types/markdown/runtime.d.ts +12 -0
- package/dist/types/plugins.d.ts +71 -0
- package/dist/types/renderIntlayerNode.d.ts +22 -0
- package/package.json +137 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { LocalesValues } from '@intlayer/types/module_augmentation';
|
|
2
|
+
/**
|
|
3
|
+
* Get the current locale from storage (cookie or localStorage).
|
|
4
|
+
*/
|
|
5
|
+
export declare const localeInStorage: import('intlayer').Locale | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Use localeInStorage instead.
|
|
8
|
+
*/
|
|
9
|
+
export declare const localeCookie: import('intlayer').Locale | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Persist the locale to storage (cookie and/or localStorage).
|
|
12
|
+
*/
|
|
13
|
+
export declare const setLocaleInStorage: (locale: LocalesValues, isCookieEnabled: boolean) => void;
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use setLocaleInStorage instead.
|
|
16
|
+
*/
|
|
17
|
+
export declare const setLocaleCookie: (locale: LocalesValues, isCookieEnabled: boolean) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Returns the current locale from storage and a setter.
|
|
20
|
+
*/
|
|
21
|
+
export declare const useLocaleStorage: (isCookieEnabled?: boolean) => {
|
|
22
|
+
localeStorage: import('intlayer').Locale;
|
|
23
|
+
setLocaleStorage: (locale: LocalesValues) => void;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated Use useLocaleStorage instead.
|
|
27
|
+
*/
|
|
28
|
+
export declare const useLocaleCookie: (isCookieEnabled?: boolean) => {
|
|
29
|
+
localeCookie: import('intlayer').Locale;
|
|
30
|
+
setLocaleCookie: (locale: LocalesValues) => void;
|
|
31
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keep the browser URL in sync with the current locale.
|
|
3
|
+
*
|
|
4
|
+
* Rewrites the current URL immediately and subscribes to future locale changes.
|
|
5
|
+
* Returns an `unsubscribe` function to stop listening.
|
|
6
|
+
*
|
|
7
|
+
* Uses `window.history.replaceState` — no full-page navigation.
|
|
8
|
+
*
|
|
9
|
+
* @returns A cleanup function that removes the locale change listener.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { installIntlayer, useRewriteURL } from 'vanilla-intlayer';
|
|
14
|
+
*
|
|
15
|
+
* installIntlayer('en');
|
|
16
|
+
*
|
|
17
|
+
* const unsubscribe = useRewriteURL();
|
|
18
|
+
*
|
|
19
|
+
* // Later, if you want to stop URL rewriting:
|
|
20
|
+
* unsubscribe();
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const useRewriteURL: () => (() => void);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initialises the Intlayer visual editor client.
|
|
3
|
+
*
|
|
4
|
+
* Does nothing when `INTLAYER_EDITOR_ENABLED` is `"false"` or the editor
|
|
5
|
+
* package reports that it is disabled.
|
|
6
|
+
*
|
|
7
|
+
* Call this once at application startup.
|
|
8
|
+
*
|
|
9
|
+
* @returns A cleanup function that stops the editor.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { installIntlayer, useEditor } from 'vanilla-intlayer';
|
|
14
|
+
*
|
|
15
|
+
* installIntlayer('en');
|
|
16
|
+
* const stopEditor = useEditor();
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const useEditor: () => (() => void);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useIntl';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { WrappedIntl } from '@intlayer/core/utils';
|
|
2
|
+
import { LocalesValues } from '@intlayer/types/module_augmentation';
|
|
3
|
+
/**
|
|
4
|
+
* Get a locale-bound `Intl` object and subscribe to locale changes.
|
|
5
|
+
*
|
|
6
|
+
* The returned `intl` property acts like the native `Intl` namespace but
|
|
7
|
+
* automatically uses the current application locale, so you do not need to
|
|
8
|
+
* pass the locale manually to `NumberFormat`, `DateTimeFormat`, etc.
|
|
9
|
+
*
|
|
10
|
+
* @param locale - Optional locale override.
|
|
11
|
+
* @returns An object with `intl: WrappedIntl` and a `subscribe` function.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { installIntlayer, useIntl } from 'vanilla-intlayer';
|
|
16
|
+
*
|
|
17
|
+
* installIntlayer('en');
|
|
18
|
+
*
|
|
19
|
+
* const { intl, subscribe } = useIntl();
|
|
20
|
+
*
|
|
21
|
+
* console.log(new intl.NumberFormat({ style: 'currency', currency: 'USD' }).format(9.99));
|
|
22
|
+
*
|
|
23
|
+
* const unsubscribe = subscribe((newIntl) => {
|
|
24
|
+
* console.log(new newIntl.NumberFormat({ style: 'currency', currency: 'USD' }).format(9.99));
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare const useIntl: (locale?: LocalesValues) => {
|
|
29
|
+
intl: WrappedIntl;
|
|
30
|
+
subscribe: (callback: (intl: WrappedIntl) => void) => () => void;
|
|
31
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Dictionary } from '@intlayer/types/dictionary';
|
|
2
|
+
import { DeclaredLocales, LocalesValues } from '@intlayer/types/module_augmentation';
|
|
3
|
+
import { DeepTransformContent } from './plugins';
|
|
4
|
+
export declare const getDictionary: <T extends Dictionary, L extends LocalesValues = DeclaredLocales>(dictionary: T, locale?: L) => DeepTransformContent<T["content"], L>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { DeclaredLocales, DictionaryKeys, DictionaryRegistryContent, LocalesValues } from '@intlayer/types/module_augmentation';
|
|
2
|
+
import { DeepTransformContent } from './plugins';
|
|
3
|
+
export declare const getIntlayer: <T extends DictionaryKeys, L extends LocalesValues = DeclaredLocales>(key: T, locale?: L) => DeepTransformContent<DictionaryRegistryContent<T>, L>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { HTMLComponents } from './types';
|
|
2
|
+
export type RenderHTMLProps = {
|
|
3
|
+
components?: HTMLComponents<'permissive', {}>;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Renders an HTML string directly, without a global provider.
|
|
7
|
+
* Returns the raw string unchanged.
|
|
8
|
+
*/
|
|
9
|
+
export declare const renderHTML: (content: string, _props?: RenderHTMLProps) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Returns a render function that uses the global provider's configuration
|
|
12
|
+
* (installed via `installIntlayerHTML`), falling back to identity.
|
|
13
|
+
*/
|
|
14
|
+
export declare const useHTMLRenderer: ({ components, }?: RenderHTMLProps) => ((content: string) => string);
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { type RenderHTMLProps, renderHTML, useHTMLRenderer, } from './HTMLRenderer';
|
|
2
|
+
export { type IntlayerHTMLPluginOptions, type IntlayerHTMLProvider, installIntlayerHTML, installIntlayerHTMLDynamic, type RenderHTMLFunction, type RenderHTMLOptions, useHTML, } from './installIntlayerHTML';
|
|
3
|
+
export type { HTMLComponents } from './types';
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { HTMLComponents } from './types';
|
|
2
|
+
export type RenderHTMLOptions = {
|
|
3
|
+
components?: HTMLComponents<'permissive', {}>;
|
|
4
|
+
};
|
|
5
|
+
export type RenderHTMLFunction = (html: string, overrides?: HTMLComponents<'permissive', {}> | RenderHTMLOptions) => string;
|
|
6
|
+
export type IntlayerHTMLProvider = {
|
|
7
|
+
renderHTML: RenderHTMLFunction;
|
|
8
|
+
};
|
|
9
|
+
export type IntlayerHTMLPluginOptions = {
|
|
10
|
+
components?: HTMLComponents<'permissive', {}>;
|
|
11
|
+
renderHTML?: RenderHTMLFunction;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Create and return a single IntlayerHTMLProvider instance.
|
|
15
|
+
*/
|
|
16
|
+
export declare const createIntlayerHTMLClient: (renderHTML: RenderHTMLFunction) => IntlayerHTMLProvider;
|
|
17
|
+
/**
|
|
18
|
+
* Install the Intlayer HTML provider for your vanilla JS application.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { installIntlayerHTML } from 'vanilla-intlayer';
|
|
23
|
+
*
|
|
24
|
+
* installIntlayerHTML({
|
|
25
|
+
* components: {
|
|
26
|
+
* a: ({ href, children }) => `<a class="styled-link" href="${href}">${children}</a>`,
|
|
27
|
+
* },
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare const installIntlayerHTML: (pluginOptions?: IntlayerHTMLPluginOptions | RenderHTMLFunction) => IntlayerHTMLProvider;
|
|
32
|
+
/**
|
|
33
|
+
* Access the installed IntlayerHTMLProvider.
|
|
34
|
+
* Returns a fallback renderer that outputs the raw HTML string if no
|
|
35
|
+
* provider has been installed.
|
|
36
|
+
*/
|
|
37
|
+
export declare const useHTML: () => IntlayerHTMLProvider;
|
|
38
|
+
/**
|
|
39
|
+
* Asynchronously install an HTML renderer whose implementation is loaded
|
|
40
|
+
* via a dynamic `import()`.
|
|
41
|
+
*
|
|
42
|
+
* Use this to keep a heavy HTML sanitiser / component renderer out of the
|
|
43
|
+
* initial bundle — the loader is only called the first time this function
|
|
44
|
+
* is executed.
|
|
45
|
+
*
|
|
46
|
+
* The returned promise resolves once the provider is ready. Any calls to
|
|
47
|
+
* `useHTML()` before the promise resolves will use the fallback (identity)
|
|
48
|
+
* renderer.
|
|
49
|
+
*
|
|
50
|
+
* @param loader - A zero-argument async function that resolves to either a
|
|
51
|
+
* `RenderHTMLFunction` or an `IntlayerHTMLPluginOptions` object.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* // Load a custom HTML sanitiser only when needed
|
|
56
|
+
* await installIntlayerHTMLDynamic(async () => {
|
|
57
|
+
* const DOMPurify = await import('dompurify');
|
|
58
|
+
* return (html) => DOMPurify.sanitize(html);
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare const installIntlayerHTMLDynamic: (loader: () => Promise<IntlayerHTMLPluginOptions | RenderHTMLFunction>) => Promise<IntlayerHTMLProvider>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { HTMLTagsType } from '@intlayer/core/transpiler';
|
|
2
|
+
/**
|
|
3
|
+
* Helper to extract specific props from the configuration value.
|
|
4
|
+
*/
|
|
5
|
+
type PropsFromConfig<Value> = Value extends true ? {} : Value extends object ? Value : {};
|
|
6
|
+
/**
|
|
7
|
+
* Common props for HTML elements rendered in vanilla JS.
|
|
8
|
+
* Components receive these as a plain object and return an HTML string.
|
|
9
|
+
*/
|
|
10
|
+
type ElementProps = Record<string, unknown> & {
|
|
11
|
+
children?: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Vanilla component type — a function that takes props and returns a string of HTML.
|
|
15
|
+
*/
|
|
16
|
+
type VanillaHTMLComponent<P = {}> = (props: P & ElementProps) => string;
|
|
17
|
+
/**
|
|
18
|
+
* Helper: Defines the mapping for the explicitly listed keys in T.
|
|
19
|
+
*/
|
|
20
|
+
type DefinedComponents<T, IsRequired extends boolean> = IsRequired extends true ? {
|
|
21
|
+
[K in keyof T]: VanillaHTMLComponent<PropsFromConfig<T[K]>>;
|
|
22
|
+
} : {
|
|
23
|
+
[K in keyof T]?: VanillaHTMLComponent<PropsFromConfig<T[K]>>;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Helper: Defines the standard HTML tags NOT listed in T.
|
|
27
|
+
*/
|
|
28
|
+
type RestHTMLComponents<T> = {
|
|
29
|
+
[K in Exclude<keyof HTMLTagsType, keyof T>]?: VanillaHTMLComponent;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* The supported modes for the HTMLComponents type.
|
|
33
|
+
*/
|
|
34
|
+
export type HTMLComponentMode = 'permissive' | 'optional' | 'inclusive' | 'strict';
|
|
35
|
+
/**
|
|
36
|
+
* Component map for HTML rendering in vanilla JS.
|
|
37
|
+
* Each component receives props and children and returns an HTML string.
|
|
38
|
+
*/
|
|
39
|
+
export type HTMLComponents<Mode extends HTMLComponentMode = 'optional', T = {}> = Mode extends 'strict' ? DefinedComponents<T, true> : Mode extends 'inclusive' ? DefinedComponents<T, true> & RestHTMLComponents<T> : Mode extends 'permissive' ? DefinedComponents<T, false> & RestHTMLComponents<T> & {
|
|
40
|
+
[key: string]: VanillaHTMLComponent;
|
|
41
|
+
} : DefinedComponents<T, false> & RestHTMLComponents<T>;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LocalesValues } from '@intlayer/types/module_augmentation';
|
|
2
|
+
import { IInterpreterPluginVanilla } from './plugins';
|
|
3
|
+
declare module '@intlayer/core/interpreter' {
|
|
4
|
+
interface IInterpreterPlugin<T, S, L extends LocalesValues> extends IInterpreterPluginVanilla<T, S, L> {
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export * from './client';
|
|
8
|
+
export * from './editor/useEditor';
|
|
9
|
+
export * from './format/useIntl';
|
|
10
|
+
export * from './getDictionary';
|
|
11
|
+
export * from './getIntlayer';
|
|
12
|
+
export * from './plugins';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { HTMLComponents } from '../html/types';
|
|
2
|
+
import { MarkdownProviderOptions } from './installIntlayerMarkdown';
|
|
3
|
+
export type RenderMarkdownProps = MarkdownProviderOptions & {
|
|
4
|
+
components?: HTMLComponents<'permissive', {}>;
|
|
5
|
+
wrapper?: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Renders markdown to an HTML string without using the global provider.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { renderMarkdown } from 'vanilla-intlayer/markdown';
|
|
13
|
+
*
|
|
14
|
+
* document.querySelector('#content').innerHTML = renderMarkdown('# Hello **World**');
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const renderMarkdown: (content: string, { forceBlock, forceInline, preserveFrontmatter, tagfilter, }?: RenderMarkdownProps) => string;
|
|
18
|
+
/**
|
|
19
|
+
* Returns a render function that uses the global provider's configuration
|
|
20
|
+
* (installed via `installIntlayerMarkdown`), falling back to `compileMarkdown`.
|
|
21
|
+
*/
|
|
22
|
+
export declare const useMarkdownRenderer: (props?: RenderMarkdownProps) => ((content: string) => string);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CompileOptions, sanitizer as defaultSanitizer, slugify as defaultSlugify, RuleType } from '@intlayer/core/markdown';
|
|
2
|
+
export { defaultSanitizer as sanitizer, defaultSlugify as slugify, RuleType };
|
|
3
|
+
export type MarkdownCompilerOptions = CompileOptions;
|
|
4
|
+
/**
|
|
5
|
+
* Compile markdown to an HTML string.
|
|
6
|
+
*
|
|
7
|
+
* The resulting string can be inserted into the DOM via `element.innerHTML`
|
|
8
|
+
* or the `renderMarkdown` helper.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { compileMarkdown } from 'vanilla-intlayer/markdown';
|
|
13
|
+
*
|
|
14
|
+
* document.querySelector('#content').innerHTML = compileMarkdown('# Hello **World**');
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const compileMarkdown: (markdown?: string, options?: MarkdownCompilerOptions) => string;
|
|
18
|
+
export declare const compiler: (markdown?: string, options?: MarkdownCompilerOptions) => string;
|
|
19
|
+
export declare const compile: (markdown?: string, options?: MarkdownCompilerOptions) => string;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { compileMarkdown } from './compiler';
|
|
2
|
+
export { type IntlayerMarkdownPluginOptions, type IntlayerMarkdownProvider, installIntlayerMarkdown, installIntlayerMarkdownDynamic, type MarkdownProviderOptions, type RenderMarkdownFunction, useMarkdown, } from './installIntlayerMarkdown';
|
|
3
|
+
export { type RenderMarkdownProps, renderMarkdown, useMarkdownRenderer, } from './MarkdownRenderer';
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { HTMLComponents } from '../html/types';
|
|
2
|
+
export type MarkdownProviderOptions = {
|
|
3
|
+
/** Forces the compiler to always output content with a block-level wrapper. */
|
|
4
|
+
forceBlock?: boolean;
|
|
5
|
+
/** Forces the compiler to always output content with an inline wrapper. */
|
|
6
|
+
forceInline?: boolean;
|
|
7
|
+
/** Whether to preserve frontmatter in the markdown content. */
|
|
8
|
+
preserveFrontmatter?: boolean;
|
|
9
|
+
/** Whether to use the GitHub Tag Filter. */
|
|
10
|
+
tagfilter?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export type RenderMarkdownOptions = MarkdownProviderOptions & {
|
|
13
|
+
components?: HTMLComponents<'permissive', {}>;
|
|
14
|
+
wrapper?: string;
|
|
15
|
+
};
|
|
16
|
+
export type RenderMarkdownFunction = (markdown: string, options?: MarkdownProviderOptions, components?: HTMLComponents<'permissive', {}>, wrapper?: string) => string | Promise<string>;
|
|
17
|
+
export type IntlayerMarkdownProvider = {
|
|
18
|
+
components?: HTMLComponents<'permissive', {}>;
|
|
19
|
+
renderMarkdown: RenderMarkdownFunction;
|
|
20
|
+
};
|
|
21
|
+
export type IntlayerMarkdownPluginOptions = MarkdownProviderOptions & {
|
|
22
|
+
components?: HTMLComponents<'permissive', {}>;
|
|
23
|
+
wrapper?: string;
|
|
24
|
+
renderMarkdown?: RenderMarkdownFunction;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Create and return a single IntlayerMarkdownProvider instance.
|
|
28
|
+
*/
|
|
29
|
+
export declare const createIntlayerMarkdownClient: (renderMarkdown: RenderMarkdownFunction, components?: HTMLComponents<"permissive", {}>) => IntlayerMarkdownProvider;
|
|
30
|
+
/**
|
|
31
|
+
* Install the Intlayer Markdown provider for your vanilla JS application.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { installIntlayerMarkdown } from 'vanilla-intlayer/markdown';
|
|
36
|
+
*
|
|
37
|
+
* installIntlayerMarkdown({ forceBlock: true });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare const installIntlayerMarkdown: (pluginOptions?: IntlayerMarkdownPluginOptions | RenderMarkdownFunction) => IntlayerMarkdownProvider;
|
|
41
|
+
/**
|
|
42
|
+
* Access the installed IntlayerMarkdownProvider.
|
|
43
|
+
* Returns a fallback renderer that compiles with default options if no
|
|
44
|
+
* provider has been installed.
|
|
45
|
+
*/
|
|
46
|
+
export declare const useMarkdown: () => IntlayerMarkdownProvider;
|
|
47
|
+
/**
|
|
48
|
+
* Asynchronously install a markdown renderer whose implementation is loaded
|
|
49
|
+
* via a dynamic `import()`.
|
|
50
|
+
*
|
|
51
|
+
* Use this to keep the markdown compiler out of the initial bundle — the
|
|
52
|
+
* loader is only called the first time this function is executed.
|
|
53
|
+
*
|
|
54
|
+
* The returned promise resolves once the provider is ready. Any calls to
|
|
55
|
+
* `useMarkdown()` before the promise resolves will use the fallback
|
|
56
|
+
* (raw-string) renderer.
|
|
57
|
+
*
|
|
58
|
+
* @param loader - A zero-argument async function that resolves to either a
|
|
59
|
+
* `RenderMarkdownFunction` or an `IntlayerMarkdownPluginOptions` object.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* // Load a custom markdown renderer (e.g. marked) only when needed
|
|
64
|
+
* await installIntlayerMarkdownDynamic(async () => {
|
|
65
|
+
* const { marked } = await import('marked');
|
|
66
|
+
* return (markdown) => marked(markdown) as string;
|
|
67
|
+
* });
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare const installIntlayerMarkdownDynamic: (loader: () => Promise<IntlayerMarkdownPluginOptions | RenderMarkdownFunction>) => Promise<IntlayerMarkdownProvider>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MarkdownRuntime } from '@intlayer/core/markdown';
|
|
2
|
+
/**
|
|
3
|
+
* Vanilla-specific MarkdownRuntime that produces HTML strings.
|
|
4
|
+
*/
|
|
5
|
+
export declare const vanillaRuntime: MarkdownRuntime;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a vanilla runtime with a custom createElement for advanced use cases.
|
|
8
|
+
*/
|
|
9
|
+
export declare const createVanillaRuntime: (options?: {
|
|
10
|
+
onCreateElement?: (type: any, props: Record<string, any> | null, children: any[]) => string;
|
|
11
|
+
}) => MarkdownRuntime;
|
|
12
|
+
export default vanillaRuntime;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { DeepTransformContent as DeepTransformContentCore, IInterpreterPluginState as IInterpreterPluginStateCore, Plugins } from '@intlayer/core/interpreter';
|
|
2
|
+
import { DeclaredLocales, LocalesValues } from '@intlayer/types/module_augmentation';
|
|
3
|
+
import { NodeType } from '@intlayer/types/nodeType';
|
|
4
|
+
import { HTMLComponents } from './html/types';
|
|
5
|
+
import { IntlayerNode as IntlayerNodeCore } from './renderIntlayerNode';
|
|
6
|
+
import * as NodeTypes from '@intlayer/types/nodeType';
|
|
7
|
+
/** ---------------------------------------------
|
|
8
|
+
* INTLAYER NODE PLUGIN
|
|
9
|
+
* --------------------------------------------- */
|
|
10
|
+
export type IntlayerNodeCond<T> = T extends number | string ? IntlayerNode<T> : never;
|
|
11
|
+
export type IntlayerNode<T, P = {}> = IntlayerNodeCore<T> & P;
|
|
12
|
+
export declare const intlayerNodePlugins: Plugins;
|
|
13
|
+
/** ---------------------------------------------
|
|
14
|
+
* INSERTION PLUGIN
|
|
15
|
+
* --------------------------------------------- */
|
|
16
|
+
export type InsertionCond<T, _S, L extends LocalesValues> = T extends {
|
|
17
|
+
nodeType: NodeType | string;
|
|
18
|
+
[NodeTypes.INSERTION]: infer I;
|
|
19
|
+
fields: readonly (infer F)[];
|
|
20
|
+
} ? <V extends {
|
|
21
|
+
[K in Extract<F, string>]: string | number;
|
|
22
|
+
}>(values: V) => I extends string ? IntlayerNode<string> : DeepTransformContent<I, L> : never;
|
|
23
|
+
export declare const insertionPlugin: Plugins;
|
|
24
|
+
/** ---------------------------------------------
|
|
25
|
+
* MARKDOWN PLUGIN
|
|
26
|
+
* --------------------------------------------- */
|
|
27
|
+
export type MarkdownStringCond<T> = T extends string ? IntlayerNode<string, {
|
|
28
|
+
metadata: DeepTransformContent<string>;
|
|
29
|
+
/** Returns the raw markdown string; render with compileMarkdown(). */
|
|
30
|
+
use: (components?: HTMLComponents<'permissive', {}>) => string;
|
|
31
|
+
}> : never;
|
|
32
|
+
export declare const markdownStringPlugin: Plugins;
|
|
33
|
+
export type MarkdownCond<T> = T extends {
|
|
34
|
+
nodeType: NodeType | string;
|
|
35
|
+
[NodeTypes.MARKDOWN]: infer M;
|
|
36
|
+
metadata?: infer U;
|
|
37
|
+
tags?: infer U;
|
|
38
|
+
} ? {
|
|
39
|
+
use: (components?: HTMLComponents<'permissive', U>) => IntlayerNode<M>;
|
|
40
|
+
metadata: DeepTransformContent<U>;
|
|
41
|
+
} : never;
|
|
42
|
+
export declare const markdownPlugin: Plugins;
|
|
43
|
+
/** ---------------------------------------------
|
|
44
|
+
* HTML PLUGIN
|
|
45
|
+
* --------------------------------------------- */
|
|
46
|
+
export type HTMLPluginCond<T> = T extends {
|
|
47
|
+
nodeType: NodeType | string;
|
|
48
|
+
[NodeTypes.HTML]: infer I;
|
|
49
|
+
tags?: infer U;
|
|
50
|
+
} ? {
|
|
51
|
+
/** Returns the raw HTML string. */
|
|
52
|
+
use: (components?: HTMLComponents<'permissive', U>) => IntlayerNode<I>;
|
|
53
|
+
} : never;
|
|
54
|
+
export declare const htmlPlugin: Plugins;
|
|
55
|
+
/** ---------------------------------------------
|
|
56
|
+
* PLUGINS RESULT
|
|
57
|
+
* --------------------------------------------- */
|
|
58
|
+
export interface IInterpreterPluginVanilla<T, S, L extends LocalesValues> {
|
|
59
|
+
vanillaIntlayerNode: IntlayerNodeCond<T>;
|
|
60
|
+
vanillaInsertion: InsertionCond<T, S, L>;
|
|
61
|
+
vanillaMarkdown: MarkdownCond<T>;
|
|
62
|
+
vanillaHtml: HTMLPluginCond<T>;
|
|
63
|
+
}
|
|
64
|
+
export type IInterpreterPluginState = Omit<IInterpreterPluginStateCore, 'insertion'> & {
|
|
65
|
+
vanillaIntlayerNode: true;
|
|
66
|
+
vanillaInsertion: true;
|
|
67
|
+
vanillaMarkdown: true;
|
|
68
|
+
vanillaHtml: true;
|
|
69
|
+
};
|
|
70
|
+
export type DeepTransformContent<T, L extends LocalesValues = DeclaredLocales> = DeepTransformContentCore<T, IInterpreterPluginState, L>;
|
|
71
|
+
export declare const getPlugins: (locale?: LocalesValues, fallback?: boolean) => Plugins[];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ResolvedEditor } from '@intlayer/types/module_augmentation';
|
|
2
|
+
export type IntlayerNode<T = string> = ResolvedEditor<T & {
|
|
3
|
+
raw: T;
|
|
4
|
+
value: T;
|
|
5
|
+
toString: () => string;
|
|
6
|
+
valueOf: () => T;
|
|
7
|
+
toJSON: () => T;
|
|
8
|
+
__update: (next: IntlayerNode<T>) => void;
|
|
9
|
+
}, {
|
|
10
|
+
raw: T;
|
|
11
|
+
value: T;
|
|
12
|
+
toString: () => string;
|
|
13
|
+
valueOf: () => T;
|
|
14
|
+
toJSON: () => T;
|
|
15
|
+
__update: (next: IntlayerNode<T>) => void;
|
|
16
|
+
}>;
|
|
17
|
+
export declare const renderIntlayerNode: <T extends string | number | boolean | null | undefined>({ value, additionalProps, }: {
|
|
18
|
+
value: T;
|
|
19
|
+
children?: any;
|
|
20
|
+
additionalProps?: Record<string, unknown>;
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
}) => IntlayerNode<T>;
|
package/package.json
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vanilla-intlayer",
|
|
3
|
+
"version": "8.5.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Easily internationalize i18n your Vanilla JS, HTML, and PHP applications with type-safe multilingual content management.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"intlayer",
|
|
8
|
+
"data",
|
|
9
|
+
"internationalization",
|
|
10
|
+
"multilingual",
|
|
11
|
+
"i18n",
|
|
12
|
+
"typescript",
|
|
13
|
+
"vanilla",
|
|
14
|
+
"json"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://intlayer.org",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/aymericzip/intlayer/issues"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/aymericzip/intlayer.git"
|
|
23
|
+
},
|
|
24
|
+
"license": "Apache-2.0",
|
|
25
|
+
"author": {
|
|
26
|
+
"name": "Aymeric PINEAU",
|
|
27
|
+
"url": "https://github.com/aymericzip"
|
|
28
|
+
},
|
|
29
|
+
"contributors": [
|
|
30
|
+
{
|
|
31
|
+
"name": "Aymeric Pineau",
|
|
32
|
+
"email": "ay.pineau@gmail.com",
|
|
33
|
+
"url": "https://github.com/aymericzip"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"sideEffects": false,
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"types": "./dist/types/index.d.ts",
|
|
40
|
+
"require": "./dist/cjs/index.cjs",
|
|
41
|
+
"import": "./dist/esm/index.mjs"
|
|
42
|
+
},
|
|
43
|
+
"./markdown": {
|
|
44
|
+
"types": "./dist/types/markdown/index.d.ts",
|
|
45
|
+
"require": "./dist/cjs/markdown/index.cjs",
|
|
46
|
+
"import": "./dist/esm/markdown/index.mjs"
|
|
47
|
+
},
|
|
48
|
+
"./html": {
|
|
49
|
+
"types": "./dist/types/html/index.d.ts",
|
|
50
|
+
"require": "./dist/cjs/html/index.cjs",
|
|
51
|
+
"import": "./dist/esm/html/index.mjs"
|
|
52
|
+
},
|
|
53
|
+
"./format": {
|
|
54
|
+
"types": "./dist/types/format/index.d.ts",
|
|
55
|
+
"require": "./dist/cjs/format/index.cjs",
|
|
56
|
+
"import": "./dist/esm/format/index.mjs"
|
|
57
|
+
},
|
|
58
|
+
"./package.json": "./package.json"
|
|
59
|
+
},
|
|
60
|
+
"main": "dist/cjs/index.cjs",
|
|
61
|
+
"module": "dist/esm/index.mjs",
|
|
62
|
+
"types": "dist/types/index.d.ts",
|
|
63
|
+
"typesVersions": {
|
|
64
|
+
"*": {
|
|
65
|
+
".": [
|
|
66
|
+
"./dist/types/index.d.ts"
|
|
67
|
+
],
|
|
68
|
+
"markdown": [
|
|
69
|
+
"./dist/types/markdown/index.d.ts"
|
|
70
|
+
],
|
|
71
|
+
"html": [
|
|
72
|
+
"./dist/types/html/index.d.ts"
|
|
73
|
+
],
|
|
74
|
+
"format": [
|
|
75
|
+
"./dist/types/format/index.d.ts"
|
|
76
|
+
],
|
|
77
|
+
"package.json": [
|
|
78
|
+
"./package.json"
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"files": [
|
|
83
|
+
"./dist",
|
|
84
|
+
"./package.json"
|
|
85
|
+
],
|
|
86
|
+
"scripts": {
|
|
87
|
+
"build": "vite build",
|
|
88
|
+
"build:ci": "vite build",
|
|
89
|
+
"clean": "bun --bun rimraf ./dist .turbo",
|
|
90
|
+
"dev": "vite build --watch",
|
|
91
|
+
"format": "bun --bun biome format . --check",
|
|
92
|
+
"format:fix": "bun --bun biome format --write .",
|
|
93
|
+
"lint": "bun --bun biome lint .",
|
|
94
|
+
"lint:fix": "bun --bun biome lint --write .",
|
|
95
|
+
"prepublish": "cp -f ../../README.md ./README.md",
|
|
96
|
+
"publish": "bun publish || true",
|
|
97
|
+
"publish:canary": "bun publish --access public --tag canary || true",
|
|
98
|
+
"publish:latest": "bun publish --access public --tag latest || true",
|
|
99
|
+
"test": "bun --bun vitest run",
|
|
100
|
+
"test:watch": "bun --bun vitest",
|
|
101
|
+
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
102
|
+
},
|
|
103
|
+
"dependencies": {
|
|
104
|
+
"@intlayer/api": "8.5.0",
|
|
105
|
+
"@intlayer/config": "8.5.0",
|
|
106
|
+
"@intlayer/core": "8.5.0",
|
|
107
|
+
"@intlayer/editor": "8.5.0",
|
|
108
|
+
"@intlayer/types": "8.5.0"
|
|
109
|
+
},
|
|
110
|
+
"devDependencies": {
|
|
111
|
+
"@types/node": "25.5.0",
|
|
112
|
+
"@utils/ts-config": "1.0.4",
|
|
113
|
+
"@utils/ts-config-types": "1.0.4",
|
|
114
|
+
"@utils/tsdown-config": "1.0.4",
|
|
115
|
+
"fast-glob": "3.3.3",
|
|
116
|
+
"rimraf": "6.1.3",
|
|
117
|
+
"tsdown": "0.21.4",
|
|
118
|
+
"typescript": "6.0.2",
|
|
119
|
+
"vite": "8.0.2",
|
|
120
|
+
"vite-plugin-dts": "4.5.4",
|
|
121
|
+
"vitest": "4.1.1"
|
|
122
|
+
},
|
|
123
|
+
"peerDependencies": {
|
|
124
|
+
"intlayer": "8.5.0"
|
|
125
|
+
},
|
|
126
|
+
"peerDependenciesMeta": {
|
|
127
|
+
"intlayer": {
|
|
128
|
+
"optional": true
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
"engines": {
|
|
132
|
+
"node": ">=14.18"
|
|
133
|
+
},
|
|
134
|
+
"bug": {
|
|
135
|
+
"url": "https://github.com/aymericzip/intlayer/issues"
|
|
136
|
+
}
|
|
137
|
+
}
|