lit-intlayer 8.4.10
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/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 +7 -0
- package/dist/esm/client/installIntlayer.mjs +25 -0
- package/dist/esm/client/useDictionary.mjs +44 -0
- package/dist/esm/client/useIntlayer.mjs +44 -0
- package/dist/esm/client/useLocale.mjs +36 -0
- package/dist/esm/client/useLocaleStorage.mjs +24 -0
- package/dist/esm/client/useRewriteURL.mjs +30 -0
- package/dist/esm/editor/useEditor.mjs +33 -0
- package/dist/esm/format/index.mjs +2 -0
- package/dist/esm/format/useIntl.mjs +24 -0
- package/dist/esm/getDictionary.mjs +6 -0
- package/dist/esm/getIntlayer.mjs +6 -0
- package/dist/esm/html/HTMLRenderer.mjs +24 -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 +21 -0
- package/dist/esm/markdown/MarkdownRenderer.mjs +55 -0
- package/dist/esm/markdown/compiler.mjs +6 -0
- package/dist/esm/markdown/index.mjs +5 -0
- package/dist/esm/markdown/installIntlayerMarkdown.mjs +31 -0
- package/dist/esm/markdown/runtime.mjs +51 -0
- package/dist/esm/plugins.mjs +109 -0
- package/dist/esm/renderIntlayerNode.mjs +25 -0
- package/dist/types/src/client/index.d.ts +6 -0
- package/dist/types/src/client/installIntlayer.d.ts +37 -0
- package/dist/types/src/client/useDictionary.d.ts +30 -0
- package/dist/types/src/client/useIntlayer.d.ts +29 -0
- package/dist/types/src/client/useLocale.d.ts +62 -0
- package/dist/types/src/client/useLocaleStorage.d.ts +31 -0
- package/dist/types/src/client/useRewriteURL.d.ts +2 -0
- package/dist/types/src/editor/useEditor.d.ts +22 -0
- package/dist/types/src/format/index.d.ts +1 -0
- package/dist/types/src/format/useIntl.d.ts +50 -0
- package/dist/types/src/getDictionary.d.ts +4 -0
- package/dist/types/src/getIntlayer.d.ts +3 -0
- package/dist/types/src/html/HTMLRenderer.d.ts +49 -0
- package/dist/types/src/html/index.d.ts +3 -0
- package/dist/types/src/html/installIntlayerHTML.d.ts +40 -0
- package/dist/types/src/html/types.d.ts +42 -0
- package/dist/types/src/index.d.ts +14 -0
- package/dist/types/src/markdown/MarkdownRenderer.d.ts +78 -0
- package/dist/types/src/markdown/compiler.d.ts +25 -0
- package/dist/types/src/markdown/index.d.ts +4 -0
- package/dist/types/src/markdown/installIntlayerMarkdown.d.ts +50 -0
- package/dist/types/src/markdown/runtime.d.ts +12 -0
- package/dist/types/src/plugins.d.ts +75 -0
- package/dist/types/src/renderIntlayerNode.d.ts +22 -0
- package/package.json +132 -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,22 @@
|
|
|
1
|
+
import { ReactiveControllerHost } from 'lit';
|
|
2
|
+
/**
|
|
3
|
+
* Initialises the Intlayer visual editor client on the given host element.
|
|
4
|
+
*
|
|
5
|
+
* Does nothing when `INTLAYER_EDITOR_ENABLED` is `"false"` or the editor
|
|
6
|
+
* package reports that it is disabled.
|
|
7
|
+
*
|
|
8
|
+
* Call this once, typically from your root/shell element.
|
|
9
|
+
*
|
|
10
|
+
* @param host - The LitElement (or any ReactiveControllerHost).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* class AppShell extends LitElement {
|
|
15
|
+
* constructor() {
|
|
16
|
+
* super();
|
|
17
|
+
* useEditor(this);
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const useEditor: (host: ReactiveControllerHost) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useIntl';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { WrappedIntl } from '@intlayer/core/utils';
|
|
2
|
+
import { LocalesValues } from '@intlayer/types/module_augmentation';
|
|
3
|
+
import { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
4
|
+
/**
|
|
5
|
+
* ReactiveController that provides a locale-bound `Intl` object.
|
|
6
|
+
*
|
|
7
|
+
* Acts exactly like the native `Intl` namespace but automatically uses the
|
|
8
|
+
* current application locale, updating the host whenever the locale changes.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
declare class IntlController implements ReactiveController {
|
|
13
|
+
private readonly host;
|
|
14
|
+
private readonly _overrideLocale;
|
|
15
|
+
private _unsubscribe;
|
|
16
|
+
/** The locale-bound Intl object. */
|
|
17
|
+
value: WrappedIntl;
|
|
18
|
+
constructor(host: ReactiveControllerHost, locale?: LocalesValues);
|
|
19
|
+
hostConnected(): void;
|
|
20
|
+
hostDisconnected(): void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Reactive hook that provides a locale-bound `Intl` object.
|
|
24
|
+
*
|
|
25
|
+
* The returned controller's `.value` property gives access to locale-aware
|
|
26
|
+
* `NumberFormat`, `DateTimeFormat`, `RelativeTimeFormat`, etc. without
|
|
27
|
+
* needing to pass the current locale manually.
|
|
28
|
+
*
|
|
29
|
+
* @param host - The LitElement (or any ReactiveControllerHost).
|
|
30
|
+
* @param locale - Optional locale override.
|
|
31
|
+
* @returns An `IntlController` with a `.value: WrappedIntl` property.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* class PriceTag extends LitElement {
|
|
36
|
+
* private intl = useIntl(this);
|
|
37
|
+
*
|
|
38
|
+
* render() {
|
|
39
|
+
* const formatted = new this.intl.value.NumberFormat({
|
|
40
|
+
* style: 'currency',
|
|
41
|
+
* currency: 'USD',
|
|
42
|
+
* }).format(9.99);
|
|
43
|
+
*
|
|
44
|
+
* return html`<span>${formatted}</span>`;
|
|
45
|
+
* }
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare const useIntl: (host: ReactiveControllerHost, locale?: LocalesValues) => IntlController;
|
|
50
|
+
export {};
|
|
@@ -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,49 @@
|
|
|
1
|
+
import { LitElement, nothing } from 'lit';
|
|
2
|
+
import { HTMLComponents } from './types';
|
|
3
|
+
export type RenderHTMLProps = {
|
|
4
|
+
components?: HTMLComponents<'permissive', {}>;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Renders an HTML string directly, without a global provider.
|
|
8
|
+
* Returns the raw string; pass to `unsafeHTML()` in a Lit template.
|
|
9
|
+
*/
|
|
10
|
+
export declare const renderHTML: (content: string, _props?: RenderHTMLProps) => string;
|
|
11
|
+
/**
|
|
12
|
+
* Returns a render function that uses the global provider's configuration
|
|
13
|
+
* (installed via `installIntlayerHTML`), falling back to identity.
|
|
14
|
+
*/
|
|
15
|
+
export declare const useHTMLRenderer: ({ components, }?: RenderHTMLProps) => ((content: string) => string);
|
|
16
|
+
/**
|
|
17
|
+
* `<intlayer-html-renderer>` — renders an HTML string into the light DOM.
|
|
18
|
+
*
|
|
19
|
+
* Uses the globally installed HTML renderer when available
|
|
20
|
+
* (see `installIntlayerHTML`), or falls back to `unsafeHTML` with the raw string.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```html
|
|
24
|
+
* <intlayer-html-renderer content="<strong>Hello</strong> World">
|
|
25
|
+
* </intlayer-html-renderer>
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare class HTMLRenderer extends LitElement {
|
|
29
|
+
static properties: {
|
|
30
|
+
content: {
|
|
31
|
+
type: StringConstructor;
|
|
32
|
+
};
|
|
33
|
+
components: {
|
|
34
|
+
attribute: boolean;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
/** The HTML string to render. */
|
|
38
|
+
content: string;
|
|
39
|
+
/** Optional component overrides for HTML tags. */
|
|
40
|
+
components?: HTMLComponents<'permissive', {}>;
|
|
41
|
+
/** Render into light DOM so host-page CSS can style the output. */
|
|
42
|
+
createRenderRoot(): this;
|
|
43
|
+
render(): typeof nothing | import('lit').TemplateResult<1>;
|
|
44
|
+
}
|
|
45
|
+
declare global {
|
|
46
|
+
interface HTMLElementTagNameMap {
|
|
47
|
+
'intlayer-html-renderer': HTMLRenderer;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 Lit application.
|
|
19
|
+
*
|
|
20
|
+
* The installed renderer is used by `<intlayer-html-renderer>` and
|
|
21
|
+
* `useHTMLRenderer()`.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { installIntlayerHTML } from 'lit-intlayer';
|
|
26
|
+
*
|
|
27
|
+
* installIntlayerHTML({
|
|
28
|
+
* components: {
|
|
29
|
+
* a: ({ href, children }) => `<a class="styled-link" href="${href}">${children}</a>`,
|
|
30
|
+
* },
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare const installIntlayerHTML: (pluginOptions?: IntlayerHTMLPluginOptions | RenderHTMLFunction) => IntlayerHTMLProvider;
|
|
35
|
+
/**
|
|
36
|
+
* Access the installed IntlayerHTMLProvider.
|
|
37
|
+
* Returns a fallback renderer that outputs the raw HTML string if no
|
|
38
|
+
* provider has been installed.
|
|
39
|
+
*/
|
|
40
|
+
export declare const useHTML: () => 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 Lit.
|
|
8
|
+
* Components receive these as a plain object.
|
|
9
|
+
*/
|
|
10
|
+
type ElementProps = Record<string, unknown> & {
|
|
11
|
+
children?: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Lit component type — a function that takes props and returns a string of HTML.
|
|
15
|
+
*/
|
|
16
|
+
type LitHTMLComponent<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]: LitHTMLComponent<PropsFromConfig<T[K]>>;
|
|
22
|
+
} : {
|
|
23
|
+
[K in keyof T]?: LitHTMLComponent<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>]?: LitHTMLComponent;
|
|
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 Lit.
|
|
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]: LitHTMLComponent;
|
|
41
|
+
} : DefinedComponents<T, false> & RestHTMLComponents<T>;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { LocalesValues } from '@intlayer/types/module_augmentation';
|
|
2
|
+
import { IInterpreterPluginLit } from './plugins';
|
|
3
|
+
declare module '@intlayer/core/interpreter' {
|
|
4
|
+
interface IInterpreterPlugin<T, S, L extends LocalesValues> extends IInterpreterPluginLit<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 './html';
|
|
13
|
+
export * from './markdown';
|
|
14
|
+
export * from './plugins';
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { LitElement, nothing } from 'lit';
|
|
2
|
+
import { HTMLComponents } from '../html/types';
|
|
3
|
+
import { MarkdownProviderOptions, RenderMarkdownFunction } from './installIntlayerMarkdown';
|
|
4
|
+
export type RenderMarkdownProps = MarkdownProviderOptions & {
|
|
5
|
+
components?: HTMLComponents<'permissive', {}>;
|
|
6
|
+
wrapper?: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Renders markdown to an HTML string without using the global provider.
|
|
10
|
+
* Pass the result to `unsafeHTML()` in a Lit template.
|
|
11
|
+
*/
|
|
12
|
+
export declare const renderMarkdown: (content: string, { forceBlock, forceInline, preserveFrontmatter, tagfilter, }?: RenderMarkdownProps) => string;
|
|
13
|
+
/**
|
|
14
|
+
* Returns a render function that uses the global provider's configuration
|
|
15
|
+
* (installed via `installIntlayerMarkdown`), falling back to `compileMarkdown`.
|
|
16
|
+
*/
|
|
17
|
+
export declare const useMarkdownRenderer: (props?: RenderMarkdownProps) => ((content: string) => string);
|
|
18
|
+
/**
|
|
19
|
+
* `<intlayer-markdown-renderer>` — renders a markdown string as HTML.
|
|
20
|
+
*
|
|
21
|
+
* Renders into the light DOM (no shadow root) so that the host page's CSS
|
|
22
|
+
* can style the generated markup.
|
|
23
|
+
*
|
|
24
|
+
* Uses the globally installed markdown renderer when available
|
|
25
|
+
* (see `installIntlayerMarkdown`), or falls back to the default compiler.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```html
|
|
29
|
+
* <intlayer-markdown-renderer content="# Hello **World**">
|
|
30
|
+
* </intlayer-markdown-renderer>
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { html } from 'lit';
|
|
36
|
+
* import 'lit-intlayer/markdown'; // registers the element
|
|
37
|
+
*
|
|
38
|
+
* html`<intlayer-markdown-renderer .content=${myMarkdown}></intlayer-markdown-renderer>`
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare class MarkdownRenderer extends LitElement {
|
|
42
|
+
static properties: {
|
|
43
|
+
content: {
|
|
44
|
+
type: StringConstructor;
|
|
45
|
+
};
|
|
46
|
+
forceBlock: {
|
|
47
|
+
type: BooleanConstructor;
|
|
48
|
+
};
|
|
49
|
+
forceInline: {
|
|
50
|
+
type: BooleanConstructor;
|
|
51
|
+
};
|
|
52
|
+
preserveFrontmatter: {
|
|
53
|
+
type: BooleanConstructor;
|
|
54
|
+
};
|
|
55
|
+
tagfilter: {
|
|
56
|
+
type: BooleanConstructor;
|
|
57
|
+
};
|
|
58
|
+
renderMarkdown: {
|
|
59
|
+
attribute: boolean;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
/** The markdown string to compile and render. */
|
|
63
|
+
content: string;
|
|
64
|
+
forceBlock?: boolean;
|
|
65
|
+
forceInline?: boolean;
|
|
66
|
+
preserveFrontmatter?: boolean;
|
|
67
|
+
tagfilter?: boolean;
|
|
68
|
+
/** Optional custom render function — overrides the global provider. */
|
|
69
|
+
renderMarkdownFn?: RenderMarkdownFunction;
|
|
70
|
+
/** Render into light DOM so host-page CSS can style the output. */
|
|
71
|
+
createRenderRoot(): this;
|
|
72
|
+
render(): typeof nothing | import('lit').TemplateResult<1>;
|
|
73
|
+
}
|
|
74
|
+
declare global {
|
|
75
|
+
interface HTMLElementTagNameMap {
|
|
76
|
+
'intlayer-markdown-renderer': MarkdownRenderer;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 rendered in a Lit template using the
|
|
8
|
+
* `unsafeHTML` directive or the `<intlayer-markdown-renderer>` element.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { compileMarkdown } from 'lit-intlayer/markdown';
|
|
13
|
+
* import { unsafeHTML } from 'lit/directives/unsafe-html.js';
|
|
14
|
+
*
|
|
15
|
+
* class MyElement extends LitElement {
|
|
16
|
+
* render() {
|
|
17
|
+
* const html = compileMarkdown('# Hello **World**');
|
|
18
|
+
* return html`${unsafeHTML(html)}`;
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const compileMarkdown: (markdown?: string, options?: MarkdownCompilerOptions) => string;
|
|
24
|
+
export declare const compiler: (markdown?: string, options?: MarkdownCompilerOptions) => string;
|
|
25
|
+
export declare const compile: (markdown?: string, options?: MarkdownCompilerOptions) => string;
|
|
@@ -0,0 +1,50 @@
|
|
|
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;
|
|
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 Lit application.
|
|
32
|
+
*
|
|
33
|
+
* Call once at startup, before any elements that render markdown are connected.
|
|
34
|
+
* The installed renderer is used by `<intlayer-markdown-renderer>` and
|
|
35
|
+
* `useMarkdownRenderer()`.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { installIntlayerMarkdown } from 'lit-intlayer/markdown';
|
|
40
|
+
*
|
|
41
|
+
* installIntlayerMarkdown({ forceBlock: true });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare const installIntlayerMarkdown: (pluginOptions?: IntlayerMarkdownPluginOptions | RenderMarkdownFunction) => IntlayerMarkdownProvider;
|
|
45
|
+
/**
|
|
46
|
+
* Access the installed IntlayerMarkdownProvider.
|
|
47
|
+
* Returns a fallback renderer that outputs the raw markdown string if no
|
|
48
|
+
* provider has been installed.
|
|
49
|
+
*/
|
|
50
|
+
export declare const useMarkdown: () => IntlayerMarkdownProvider;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MarkdownRuntime } from '@intlayer/core/markdown';
|
|
2
|
+
/**
|
|
3
|
+
* Lit-specific MarkdownRuntime that produces HTML strings.
|
|
4
|
+
*/
|
|
5
|
+
export declare const litRuntime: MarkdownRuntime;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a Lit runtime with a custom createElement for advanced use cases.
|
|
8
|
+
*/
|
|
9
|
+
export declare const createLitRuntime: (options?: {
|
|
10
|
+
onCreateElement?: (type: any, props: Record<string, any> | null, children: any[]) => string;
|
|
11
|
+
}) => MarkdownRuntime;
|
|
12
|
+
export default litRuntime;
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
/**
|
|
13
|
+
* Wraps string/number leaf values in an IntlayerNode so they carry
|
|
14
|
+
* `.value`, `.raw`, `toString()`, and `__update()`.
|
|
15
|
+
*/
|
|
16
|
+
export declare const intlayerNodePlugins: Plugins;
|
|
17
|
+
/** ---------------------------------------------
|
|
18
|
+
* INSERTION PLUGIN
|
|
19
|
+
* --------------------------------------------- */
|
|
20
|
+
export type InsertionCond<T, _S, _L> = T extends {
|
|
21
|
+
nodeType: NodeType | string;
|
|
22
|
+
[NodeTypes.INSERTION]: string;
|
|
23
|
+
fields: readonly string[];
|
|
24
|
+
} ? <V extends {
|
|
25
|
+
[K in T['fields'][number]]: string | number;
|
|
26
|
+
}>(values: V) => IntlayerNode<string> : never;
|
|
27
|
+
export declare const insertionPlugin: Plugins;
|
|
28
|
+
/** ---------------------------------------------
|
|
29
|
+
* MARKDOWN PLUGIN
|
|
30
|
+
* --------------------------------------------- */
|
|
31
|
+
export type MarkdownStringCond<T> = T extends string ? IntlayerNode<string, {
|
|
32
|
+
metadata: DeepTransformContent<string>;
|
|
33
|
+
/** Returns the raw markdown string; render with compileMarkdown() or <intlayer-markdown>. */
|
|
34
|
+
use: (components?: HTMLComponents<'permissive', {}>) => string;
|
|
35
|
+
}> : never;
|
|
36
|
+
export declare const markdownStringPlugin: Plugins;
|
|
37
|
+
export type MarkdownCond<T> = T extends {
|
|
38
|
+
nodeType: NodeType | string;
|
|
39
|
+
[NodeTypes.MARKDOWN]: infer M;
|
|
40
|
+
metadata?: infer U;
|
|
41
|
+
tags?: infer U;
|
|
42
|
+
} ? {
|
|
43
|
+
use: (components?: HTMLComponents<'permissive', U>) => IntlayerNode<M>;
|
|
44
|
+
metadata: DeepTransformContent<U>;
|
|
45
|
+
} : never;
|
|
46
|
+
export declare const markdownPlugin: Plugins;
|
|
47
|
+
/** ---------------------------------------------
|
|
48
|
+
* HTML PLUGIN
|
|
49
|
+
* --------------------------------------------- */
|
|
50
|
+
export type HTMLPluginCond<T> = T extends {
|
|
51
|
+
nodeType: NodeType | string;
|
|
52
|
+
[NodeTypes.HTML]: infer I;
|
|
53
|
+
tags?: infer U;
|
|
54
|
+
} ? {
|
|
55
|
+
/** Returns the raw HTML string; render with unsafeHTML() or <intlayer-html>. */
|
|
56
|
+
use: (components?: HTMLComponents<'permissive', U>) => IntlayerNode<I>;
|
|
57
|
+
} : never;
|
|
58
|
+
export declare const htmlPlugin: Plugins;
|
|
59
|
+
/** ---------------------------------------------
|
|
60
|
+
* PLUGINS RESULT
|
|
61
|
+
* --------------------------------------------- */
|
|
62
|
+
export interface IInterpreterPluginLit<T, S, L extends LocalesValues> {
|
|
63
|
+
litIntlayerNode: IntlayerNodeCond<T>;
|
|
64
|
+
litInsertion: InsertionCond<T, S, L>;
|
|
65
|
+
litMarkdown: MarkdownCond<T>;
|
|
66
|
+
litHtml: HTMLPluginCond<T>;
|
|
67
|
+
}
|
|
68
|
+
export type IInterpreterPluginState = Omit<IInterpreterPluginStateCore, 'insertion'> & {
|
|
69
|
+
litIntlayerNode: true;
|
|
70
|
+
litInsertion: true;
|
|
71
|
+
litMarkdown: true;
|
|
72
|
+
litHtml: true;
|
|
73
|
+
};
|
|
74
|
+
export type DeepTransformContent<T, L extends LocalesValues = DeclaredLocales> = DeepTransformContentCore<T, IInterpreterPluginState, L>;
|
|
75
|
+
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>;
|