Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F969579
jsx.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
jsx.ts
View Options
import
{
Readable
}
from
"stream"
;
import
{
tempstream
}
from
"."
;
import
{
VOID_HTML_TAGS
}
from
"./html"
;
import
classNames
from
"classnames"
;
type
Component
=
string
;
type
ComponentProps
=
Record
<
string
,
JSX
.
HtmlAttribute
|
Promise
<
JSX
.
HtmlAttribute
>
>
|
null
;
type
CreateElementFuntion
=
(
tag
:
JSX
.
HtmlElement
|
((
properties
:
ComponentProps
)
=>
Readable
),
properties
:
ComponentProps
,
...
children
:
Component
[]
)
=>
Readable
;
const
resolveGenericProperty
=
(
name
:
string
,
value
:
JSX
.
HtmlAttribute
)
=>
{
if
(
typeof
value
===
"boolean"
&&
value
)
{
return
name
;
}
if
(
typeof
value
===
"string"
)
{
return
tempstream
`
${
name
}
="
${
value
}
"`
;
}
if
(
typeof
value
===
"object"
||
Array
.
isArray
(
value
))
{
return
tempstream
`
${
name
}
="
${
classNames
(
value
)
}
"`
;
}
return
""
;
};
const
createElement
:
CreateElementFuntion
=
(
tag
,
properties
,
...
children
)
=>
{
// just typescript being anoying
const
voidElements
:
string
[]
=
[...
VOID_HTML_TAGS
];
const
props
=
properties
?
Object
.
entries
(
properties
).
map
(([
name
,
value
])
=>
value
instanceof
Promise
?
value
.
then
((
val
)
=>
resolveGenericProperty
(
name
,
val
))
:
resolveGenericProperty
(
name
,
value
)
)
:
""
;
if
(
typeof
tag
===
"string"
)
{
if
(
voidElements
.
includes
(
tag
))
{
return
tempstream
`<
${
tag
}
${
props
}
/>`
;
}
return
tempstream
`<
${
tag
}
${
props
}
>
${
children
}
</
${
tag
}
>`
;
}
return
tag
(
properties
);
};
const
TempstreamJSX
=
{
createElement
};
export
{
TempstreamJSX
};
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Sat, Nov 23, 06:19 (1 d, 17 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
547887
Default Alt Text
jsx.ts (1 KB)
Attached To
Mode
rSTREAM tempstream
Attached
Detach File
Event Timeline
Log In to Comment