@portabletext/block-tools 3.3.3 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.cjs +142 -124
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +4 -36
- package/lib/index.d.ts +4 -36
- package/lib/index.js +114 -95
- package/lib/index.js.map +1 -1
- package/package.json +7 -6
- package/src/HtmlDeserializer/flatten-nested-blocks.test.ts +112 -1
- package/src/HtmlDeserializer/flatten-nested-blocks.ts +174 -0
- package/src/HtmlDeserializer/helpers.ts +24 -159
- package/src/HtmlDeserializer/index.ts +7 -7
- package/src/HtmlDeserializer/rules/html.ts +12 -0
- package/src/index.ts +1 -1
- package/src/types.ts +1 -1
- package/src/util/normalizeBlock.ts +6 -6
- package/src/types.portable-text.ts +0 -79
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import type {Schema} from '@portabletext/schema'
|
|
2
|
-
import {isArbitraryTypedObject} from './types'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
export type PortableTextBlock = PortableTextTextBlock | PortableTextObject
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @public
|
|
11
|
-
*/
|
|
12
|
-
export interface PortableTextTextBlock<
|
|
13
|
-
TChild = PortableTextSpan | PortableTextObject,
|
|
14
|
-
> {
|
|
15
|
-
_type: string
|
|
16
|
-
_key: string
|
|
17
|
-
children: TChild[]
|
|
18
|
-
markDefs?: PortableTextObject[]
|
|
19
|
-
listItem?: string
|
|
20
|
-
style?: string
|
|
21
|
-
level?: number
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function isTextBlock(
|
|
25
|
-
schema: Schema,
|
|
26
|
-
block: unknown,
|
|
27
|
-
): block is PortableTextTextBlock {
|
|
28
|
-
if (!isArbitraryTypedObject(block)) {
|
|
29
|
-
return false
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (block._type !== schema.block.name) {
|
|
33
|
-
return false
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (!Array.isArray(block.children)) {
|
|
37
|
-
return false
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return true
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @public
|
|
45
|
-
*/
|
|
46
|
-
export interface PortableTextSpan {
|
|
47
|
-
_key: string
|
|
48
|
-
_type: 'span'
|
|
49
|
-
text: string
|
|
50
|
-
marks?: string[]
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function isSpan(
|
|
54
|
-
schema: Schema,
|
|
55
|
-
child: unknown,
|
|
56
|
-
): child is PortableTextSpan {
|
|
57
|
-
if (!isArbitraryTypedObject(child)) {
|
|
58
|
-
return false
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (child._type !== schema.span.name) {
|
|
62
|
-
return false
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (typeof child.text !== 'string') {
|
|
66
|
-
return false
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return true
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @public
|
|
74
|
-
*/
|
|
75
|
-
export interface PortableTextObject {
|
|
76
|
-
_type: string
|
|
77
|
-
_key: string
|
|
78
|
-
[other: string]: unknown
|
|
79
|
-
}
|