-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[add] Render methods for JSX runtime
- Loading branch information
Showing
10 changed files
with
171 additions
and
21 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 |
---|---|---|
|
@@ -3,5 +3,6 @@ package-lock.json | |
yarn.lock | ||
.parcel-cache/ | ||
dist/ | ||
/jsx-runtime.* | ||
docs/ | ||
.vscode/settings.json |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,27 @@ | ||
import { HTMLProps, IndexKey } from 'web-utility'; | ||
|
||
export type DataObject = Record<string, any>; | ||
|
||
export interface VNode { | ||
key?: IndexKey; | ||
text?: string; | ||
tagName?: string; | ||
props?: DataObject; | ||
style?: DataObject; | ||
children?: VNode[]; | ||
node?: Node; | ||
} | ||
|
||
type HTMLTags = { | ||
[tagName in keyof HTMLElementTagNameMap]: HTMLProps< | ||
HTMLElementTagNameMap[tagName] | ||
>; | ||
} & { | ||
[tagName: string]: HTMLProps<HTMLElement>; | ||
}; | ||
|
||
declare global { | ||
namespace JSX { | ||
interface IntrinsicElements extends HTMLTags {} | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './VDOM'; | ||
export * from './DOMRenderer'; |
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,31 @@ | ||
import { IndexKey } from 'web-utility'; | ||
|
||
import { DataObject, VNode } from './VDOM'; | ||
|
||
/** | ||
* @see {@link https://github.com/reactjs/rfcs/blob/createlement-rfc/text/0000-create-element-changes.md} | ||
* @see {@link https://babeljs.io/docs/babel-plugin-transform-react-jsx} | ||
*/ | ||
export const jsx = ( | ||
type: string | Function, | ||
{ style, children, ...props }: DataObject, | ||
key?: IndexKey | ||
): VNode => | ||
typeof type === 'string' | ||
? { | ||
key, | ||
tagName: type, | ||
props, | ||
style, | ||
children: (children instanceof Array | ||
? children | ||
: children && [children] | ||
) | ||
?.map(node => | ||
typeof node === 'string' ? { text: node } : node | ||
) | ||
.flat(Infinity) | ||
} | ||
: type({ style, children, ...props }); | ||
|
||
export const jsxs = 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
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