-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
110 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"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/*" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
packages/ui-kit/src/rendering/jsx.spec.tsx → packages/ui-kit/src/jsx/jsx-runtime.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* eslint-disable import/export */ | ||
/* eslint-disable @typescript-eslint/no-namespace */ | ||
|
||
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< | ||
{ | ||
[K in keyof B]: Exclude<B[K], undefined> extends Block | Block[] | ||
? JSXInternal.Element | ||
: B[K]; | ||
}, | ||
'type' | ||
>; | ||
|
||
namespace JSXInternal { | ||
export type Element = Block | Block[]; | ||
export type IntrinsicElements = { | ||
[B in Block as B['type']]: PropsForBlock<B>; | ||
}; | ||
} | ||
|
||
export function jsx( | ||
type: undefined, | ||
props: { | ||
children: Block; | ||
} | ||
): [Block]; | ||
|
||
export function jsx( | ||
type: TextObject['type'], | ||
props: TypeToPropsMap[TextObject['type']] | ||
): TextObject; | ||
|
||
export function jsx<B extends Block>( | ||
type: B['type'], | ||
props: PropsForBlock<B>, | ||
...children: never | ||
): B; | ||
|
||
export function jsx( | ||
type: undefined | TextObject['type'] | unknown, | ||
props: | ||
| { | ||
children: Block; | ||
} | ||
| TypeToPropsMap[TextObject['type']] | ||
| Record<string, unknown> | ||
): unknown { | ||
switch (type) { | ||
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 }; | ||
} | ||
} | ||
|
||
export function jsxs<B extends Block[]>( | ||
type: undefined, | ||
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 import JSX = JSXInternal; | ||
} | ||
|
||
export { JSXInternal as JSX }; |
This file was deleted.
Oops, something went wrong.