Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F3010228
block.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
block.ts
View Options
import
{
predicates
,
ShapeToType
}
from
"@sealcode/ts-predicates"
;
import
{
ConstPredicate
}
from
"@sealcode/ts-predicates/@types/predicates/const"
;
import
{
LazyPredicate
}
from
"@sealcode/ts-predicates/@types/predicates/lazy"
;
import
{
HeadingPrimitive
,
HeadingShape
}
from
"./heading"
;
import
{
ImageShape
}
from
"./image"
;
import
{
parse_primitives
}
from
"./parse_primitives"
;
import
{
Primitive
,
PrimitiveJSON
}
from
"./primitive"
;
import
{
TextShape
}
from
"./text"
;
export
const
BlockShape
:
{
readonly
type
:
ConstPredicate
<
"block"
>
;
readonly
content
:
LazyPredicate
<
PrimitiveJSON
[]
>
;
}
=
<
const
>
{
type
:
predicates
.
const
(
<
const
>
"block"
),
content
:
predicates
.
lazy
(()
=>
predicates
.
array
<
PrimitiveJSON
>
(
predicates
.
or
(
predicates
.
shape
(
BlockShape
),
predicates
.
shape
(
HeadingShape
),
predicates
.
shape
(
ImageShape
),
predicates
.
shape
(
TextShape
)
)
)
),
};
export
type
BlockJSON
=
ShapeToType
<
typeof
BlockShape
>
;
export
class
BlockPrimitive
extends
Primitive
{
content
:
Primitive
[];
id
:
string
|
null
=
null
;
constructor
(
json
:
Record
<
string
,
unknown
>
)
{
super
();
this
.
content
=
parse_primitives
(
json
[
"content"
]
as
Record
<
string
,
unknown
>
[]
);
this
.
id
=
json
[
"id"
]
as
string
|
null
;
}
to_html
()
:
string
{
let
html
=
`<div>`
;
for
(
const
comp
of
this
.
content
)
{
html
+=
comp
.
to_html
();
}
return
`
${
html
}
</div>`
;
}
extract_headings
()
:
HeadingPrimitive
[]
{
const
headings
:
HeadingPrimitive
[]
=
[];
for
(
const
primitive
of
this
.
content
)
{
headings
.
push
(...
primitive
.
extract_headings
());
}
return
headings
;
}
extract_images
()
:
string
[]
{
const
ret
:
string
[]
=
[];
for
(
const
comp
of
this
.
content
)
{
ret
.
push
(...
comp
.
extract_images
());
}
return
ret
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Wed, May 7, 19:38 (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
624746
Default Alt Text
block.ts (1 KB)
Attached To
Mode
rJDD jdd
Attached
Detach File
Event Timeline
Log In to Comment