Unverified Commit 4761c66a authored by Tasso Evangelista's avatar Tasso Evangelista
Browse files

Prepare jsx-runtime

parent 630044c3
{
"private": true,
"main": "../dist/cjs/jsx/jsx-runtime.js",
"module": "../dist/esm/jsx/jsx-runtime.js",
"types": "../dist/esm/jsx/jsx-runtime.d.ts",
"typesVersions": {
"<4.1": {
"*": [
"../dist/ts3.4/jsx/*"
]
}
}
}
...@@ -47,5 +47,3 @@ export { uiKitModal } from './rendering/surfaces/uiKitModal'; ...@@ -47,5 +47,3 @@ export { uiKitModal } from './rendering/surfaces/uiKitModal';
export { UiKitParserBanner } from './rendering/surfaces/UiKitParserBanner'; export { UiKitParserBanner } from './rendering/surfaces/UiKitParserBanner';
export { UiKitParserMessage } from './rendering/surfaces/UiKitParserMessage'; export { UiKitParserMessage } from './rendering/surfaces/UiKitParserMessage';
export { UiKitParserModal } from './rendering/surfaces/UiKitParserModal'; export { UiKitParserModal } from './rendering/surfaces/UiKitParserModal';
export { jsx } from './rendering/jsx';
/** @jsx jsx */ /** @jsxImportSource . */
/** @jsxFrag jsxFrag */
import { Option } from '../blocks/Option'; import { Option } from '../blocks/Option';
import { jsx, jsxFrag } from './jsx';
describe('divider', () => { describe('divider', () => {
it('renders', () => { it('renders', () => {
......
...@@ -2,6 +2,14 @@ ...@@ -2,6 +2,14 @@
/* eslint-disable @typescript-eslint/no-namespace */ /* eslint-disable @typescript-eslint/no-namespace */
import { Block } from '../blocks/Block'; import { Block } from '../blocks/Block';
import { TextObject } from '../blocks/TextObject';
import { TextObjectType } from '../blocks/TextObjectType';
type TypeToPropsMap = {
[T in TextObject as T['type']]: Omit<T, 'type' | 'text'> & {
children?: string;
};
};
type PropsForBlock<B extends Block> = Omit< type PropsForBlock<B extends Block> = Omit<
{ {
...@@ -19,15 +27,17 @@ namespace JSXInternal { ...@@ -19,15 +27,17 @@ namespace JSXInternal {
}; };
} }
export { JSXInternal as JSX }; export function jsx(
type: undefined,
export const jsxFrag = Symbol('jsxFrag'); props: {
children: Block;
}
): [Block];
export function jsx<B extends Block>( export function jsx(
type: typeof jsxFrag, type: TextObject['type'],
props: never, props: TypeToPropsMap[TextObject['type']]
...children: B[] ): TextObject;
): B;
export function jsx<B extends Block>( export function jsx<B extends Block>(
type: B['type'], type: B['type'],
...@@ -36,20 +46,51 @@ export function jsx<B extends Block>( ...@@ -36,20 +46,51 @@ export function jsx<B extends Block>(
): B; ): B;
export function jsx( export function jsx(
type: unknown, type: undefined | TextObject['type'] | unknown,
props: Record<string, unknown>, props:
...children: Block[] | {
children: Block;
}
| TypeToPropsMap[TextObject['type']]
| Record<string, unknown>
): unknown { ): unknown {
if (type === jsxFrag) { switch (type) {
return children; case undefined:
return [props.children];
case TextObjectType.PLAIN_TEXT:
case TextObjectType.MARKDOWN: {
const { children, ...rest } = props;
return { type, text: children, ...rest };
}
default:
return { type, ...props };
} }
}
return { export function jsxs<B extends Block[]>(
type, type: undefined,
...props, props: {
}; children: B;
}
): B;
export function jsxs(
type: Block['type'] | undefined,
props: Record<string, unknown>
) {
switch (type) {
case undefined:
return props.children;
default:
return jsx(type, props);
}
} }
export namespace jsx { export namespace jsx {
export import JSX = JSXInternal; export import JSX = JSXInternal;
} }
export { JSXInternal as JSX };
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment