@portabletext/block-tools 1.1.38 → 2.0.0-canary.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.d.cts CHANGED
@@ -1,121 +1,102 @@
1
- import type {
2
- ArraySchemaType,
3
- I18nTitledListValue,
4
- ObjectSchemaType,
5
- SpanSchemaType,
6
- TitledListValue,
7
- } from '@sanity/types'
8
- import {PortableTextSpan, PortableTextTextBlock} from '@sanity/types'
9
- import type {ComponentType} from 'react'
10
-
1
+ import { ArraySchemaType, I18nTitledListValue, ObjectSchemaType, PortableTextSpan, PortableTextTextBlock, SpanSchemaType, TitledListValue } from "@sanity/types";
2
+ import { ComponentType } from "react";
11
3
  /**
12
4
  * @public
13
5
  */
14
- export declare interface ArbitraryTypedObject extends TypedObject {
15
- [key: string]: unknown
6
+ interface BlockContentFeatures {
7
+ styles: TitledListValue<string>[];
8
+ decorators: TitledListValue<string>[];
9
+ annotations: ResolvedAnnotationType[];
10
+ lists: I18nTitledListValue<string>[];
11
+ types: {
12
+ block: ArraySchemaType;
13
+ span: SpanSchemaType;
14
+ inlineObjects: ObjectSchemaType[];
15
+ blockObjects: ObjectSchemaType[];
16
+ };
17
+ }
18
+ /**
19
+ * @beta
20
+ */
21
+ interface BlockEditorSchemaProps {
22
+ icon?: string | ComponentType;
23
+ render?: ComponentType;
16
24
  }
17
-
18
25
  /**
19
26
  * @public
20
27
  */
21
- export declare interface BlockContentFeatures {
22
- styles: TitledListValue<string>[]
23
- decorators: TitledListValue<string>[]
24
- annotations: ResolvedAnnotationType[]
25
- lists: I18nTitledListValue<string>[]
26
- types: {
27
- block: ArraySchemaType
28
- span: SpanSchemaType
29
- inlineObjects: ObjectSchemaType[]
30
- blockObjects: ObjectSchemaType[]
31
- }
28
+ interface ResolvedAnnotationType {
29
+ blockEditor?: BlockEditorSchemaProps;
30
+ title: string | undefined;
31
+ value: string;
32
+ type: ObjectSchemaType;
33
+ icon: ComponentType | undefined;
32
34
  }
33
-
34
35
  /**
35
- * @beta
36
+ * @public
36
37
  */
37
- export declare interface BlockEditorSchemaProps {
38
- icon?: string | ComponentType
39
- render?: ComponentType
38
+ interface TypedObject {
39
+ _type: string;
40
+ _key?: string;
40
41
  }
41
-
42
42
  /**
43
- * Block normalization options
44
- *
45
43
  * @public
46
44
  */
47
- export declare interface BlockNormalizationOptions {
48
- /**
49
- * Decorator names that are allowed within portable text blocks, eg `em`, `strong`
50
- */
51
- allowedDecorators?: string[]
52
- /**
53
- * Name of the portable text block type, if not `block`
54
- */
55
- blockTypeName?: string
56
- /**
57
- * Custom key generator function
58
- */
59
- keyGenerator?: () => string
45
+ interface ArbitraryTypedObject extends TypedObject {
46
+ [key: string]: unknown;
60
47
  }
61
-
62
48
  /**
63
49
  * @public
64
50
  */
65
- export declare interface DeserializerRule {
66
- deserialize: (
67
- el: Node,
68
- next: (
69
- elements: Node | Node[] | NodeList,
70
- ) => TypedObject | TypedObject[] | undefined,
71
- createBlock: (props: ArbitraryTypedObject) => {
72
- _type: string
73
- block: ArbitraryTypedObject
74
- },
75
- ) => TypedObject | TypedObject[] | undefined
51
+ type HtmlParser = (html: string) => Document;
52
+ /**
53
+ * @public
54
+ */
55
+ type WhiteSpacePasteMode = 'preserve' | 'remove' | 'normalize';
56
+ /**
57
+ * @public
58
+ */
59
+ interface HtmlDeserializerOptions {
60
+ keyGenerator?: () => string;
61
+ rules?: DeserializerRule[];
62
+ parseHtml?: HtmlParser;
63
+ unstable_whitespaceOnPasteMode?: WhiteSpacePasteMode;
76
64
  }
77
-
78
65
  /**
79
- * Normalize and extract features of an schema type containing a block type
80
- *
81
- * @param blockContentType - Schema type for the block type
82
- * @returns Returns the featureset of a compiled block content type.
83
66
  * @public
84
67
  */
85
- export declare function getBlockContentFeatures(
86
- blockContentType: ArraySchemaType,
87
- ): BlockContentFeatures
88
68
 
89
69
  /**
90
70
  * @public
91
71
  */
92
- export declare interface HtmlDeserializerOptions {
93
- keyGenerator?: () => string
94
- rules?: DeserializerRule[]
95
- parseHtml?: HtmlParser
96
- unstable_whitespaceOnPasteMode?: WhiteSpacePasteMode
72
+ interface DeserializerRule {
73
+ deserialize: (el: Node, next: (elements: Node | Node[] | NodeList) => TypedObject | TypedObject[] | undefined, createBlock: (props: ArbitraryTypedObject) => {
74
+ _type: string;
75
+ block: ArbitraryTypedObject;
76
+ }) => TypedObject | TypedObject[] | undefined;
97
77
  }
98
-
99
78
  /**
100
79
  * @public
101
80
  */
102
- export declare type HtmlParser = (html: string) => Document
103
-
104
81
  /**
105
- * Convert HTML to blocks respecting the block content type's schema
82
+ * Block normalization options
106
83
  *
107
- * @param html - The HTML to convert to blocks
108
- * @param blockContentType - A compiled version of the schema type for the block content
109
- * @param options - Options for deserializing HTML to blocks
110
- * @returns Array of blocks
111
84
  * @public
112
85
  */
113
- export declare function htmlToBlocks(
114
- html: string,
115
- blockContentType: ArraySchemaType,
116
- options?: HtmlDeserializerOptions,
117
- ): (TypedObject | PortableTextTextBlock)[]
118
-
86
+ interface BlockNormalizationOptions {
87
+ /**
88
+ * Decorator names that are allowed within portable text blocks, eg `em`, `strong`
89
+ */
90
+ allowedDecorators?: string[];
91
+ /**
92
+ * Name of the portable text block type, if not `block`
93
+ */
94
+ blockTypeName?: string;
95
+ /**
96
+ * Custom key generator function
97
+ */
98
+ keyGenerator?: () => string;
99
+ }
119
100
  /**
120
101
  * Normalizes a block by ensuring it has a `_key` property. If the block is a
121
102
  * portable text block, additional normalization is applied:
@@ -131,16 +112,9 @@ export declare function htmlToBlocks(
131
112
  * @returns Normalized block
132
113
  * @public
133
114
  */
134
- export declare function normalizeBlock(
135
- node: TypedObject,
136
- options?: BlockNormalizationOptions,
137
- ): Omit<
138
- TypedObject | PortableTextTextBlock<TypedObject | PortableTextSpan>,
139
- '_key'
140
- > & {
141
- _key: string
142
- }
143
-
115
+ declare function normalizeBlock(node: TypedObject, options?: BlockNormalizationOptions): Omit<TypedObject | PortableTextTextBlock<TypedObject | PortableTextSpan>, '_key'> & {
116
+ _key: string;
117
+ };
144
118
  /**
145
119
  * Generate a random key of the given length
146
120
  *
@@ -148,30 +122,23 @@ export declare function normalizeBlock(
148
122
  * @returns A string of the given length
149
123
  * @public
150
124
  */
151
- export declare function randomKey(length: number): string
152
-
153
- /**
154
- * @public
155
- */
156
- export declare interface ResolvedAnnotationType {
157
- blockEditor?: BlockEditorSchemaProps
158
- title: string | undefined
159
- value: string
160
- type: ObjectSchemaType
161
- icon: ComponentType | undefined
162
- }
163
-
125
+ declare function randomKey(length: number): string;
164
126
  /**
127
+ * Convert HTML to blocks respecting the block content type's schema
128
+ *
129
+ * @param html - The HTML to convert to blocks
130
+ * @param blockContentType - A compiled version of the schema type for the block content
131
+ * @param options - Options for deserializing HTML to blocks
132
+ * @returns Array of blocks
165
133
  * @public
166
134
  */
167
- export declare interface TypedObject {
168
- _type: string
169
- _key?: string
170
- }
171
-
135
+ declare function htmlToBlocks(html: string, blockContentType: ArraySchemaType, options?: HtmlDeserializerOptions): (TypedObject | PortableTextTextBlock)[];
172
136
  /**
137
+ * Normalize and extract features of an schema type containing a block type
138
+ *
139
+ * @param blockContentType - Schema type for the block type
140
+ * @returns Returns the featureset of a compiled block content type.
173
141
  * @public
174
142
  */
175
- declare type WhiteSpacePasteMode = 'preserve' | 'remove' | 'normalize'
176
-
177
- export {}
143
+ declare function getBlockContentFeatures(blockContentType: ArraySchemaType): BlockContentFeatures;
144
+ export { type ArbitraryTypedObject, type BlockContentFeatures, type BlockEditorSchemaProps, type BlockNormalizationOptions, type DeserializerRule, type HtmlDeserializerOptions, type HtmlParser, type ResolvedAnnotationType, type TypedObject, getBlockContentFeatures, htmlToBlocks, normalizeBlock, randomKey };
package/lib/index.d.ts CHANGED
@@ -1,121 +1,102 @@
1
- import type {
2
- ArraySchemaType,
3
- I18nTitledListValue,
4
- ObjectSchemaType,
5
- SpanSchemaType,
6
- TitledListValue,
7
- } from '@sanity/types'
8
- import {PortableTextSpan, PortableTextTextBlock} from '@sanity/types'
9
- import type {ComponentType} from 'react'
10
-
1
+ import { ArraySchemaType, I18nTitledListValue, ObjectSchemaType, PortableTextSpan, PortableTextTextBlock, SpanSchemaType, TitledListValue } from "@sanity/types";
2
+ import { ComponentType } from "react";
11
3
  /**
12
4
  * @public
13
5
  */
14
- export declare interface ArbitraryTypedObject extends TypedObject {
15
- [key: string]: unknown
6
+ interface BlockContentFeatures {
7
+ styles: TitledListValue<string>[];
8
+ decorators: TitledListValue<string>[];
9
+ annotations: ResolvedAnnotationType[];
10
+ lists: I18nTitledListValue<string>[];
11
+ types: {
12
+ block: ArraySchemaType;
13
+ span: SpanSchemaType;
14
+ inlineObjects: ObjectSchemaType[];
15
+ blockObjects: ObjectSchemaType[];
16
+ };
17
+ }
18
+ /**
19
+ * @beta
20
+ */
21
+ interface BlockEditorSchemaProps {
22
+ icon?: string | ComponentType;
23
+ render?: ComponentType;
16
24
  }
17
-
18
25
  /**
19
26
  * @public
20
27
  */
21
- export declare interface BlockContentFeatures {
22
- styles: TitledListValue<string>[]
23
- decorators: TitledListValue<string>[]
24
- annotations: ResolvedAnnotationType[]
25
- lists: I18nTitledListValue<string>[]
26
- types: {
27
- block: ArraySchemaType
28
- span: SpanSchemaType
29
- inlineObjects: ObjectSchemaType[]
30
- blockObjects: ObjectSchemaType[]
31
- }
28
+ interface ResolvedAnnotationType {
29
+ blockEditor?: BlockEditorSchemaProps;
30
+ title: string | undefined;
31
+ value: string;
32
+ type: ObjectSchemaType;
33
+ icon: ComponentType | undefined;
32
34
  }
33
-
34
35
  /**
35
- * @beta
36
+ * @public
36
37
  */
37
- export declare interface BlockEditorSchemaProps {
38
- icon?: string | ComponentType
39
- render?: ComponentType
38
+ interface TypedObject {
39
+ _type: string;
40
+ _key?: string;
40
41
  }
41
-
42
42
  /**
43
- * Block normalization options
44
- *
45
43
  * @public
46
44
  */
47
- export declare interface BlockNormalizationOptions {
48
- /**
49
- * Decorator names that are allowed within portable text blocks, eg `em`, `strong`
50
- */
51
- allowedDecorators?: string[]
52
- /**
53
- * Name of the portable text block type, if not `block`
54
- */
55
- blockTypeName?: string
56
- /**
57
- * Custom key generator function
58
- */
59
- keyGenerator?: () => string
45
+ interface ArbitraryTypedObject extends TypedObject {
46
+ [key: string]: unknown;
60
47
  }
61
-
62
48
  /**
63
49
  * @public
64
50
  */
65
- export declare interface DeserializerRule {
66
- deserialize: (
67
- el: Node,
68
- next: (
69
- elements: Node | Node[] | NodeList,
70
- ) => TypedObject | TypedObject[] | undefined,
71
- createBlock: (props: ArbitraryTypedObject) => {
72
- _type: string
73
- block: ArbitraryTypedObject
74
- },
75
- ) => TypedObject | TypedObject[] | undefined
51
+ type HtmlParser = (html: string) => Document;
52
+ /**
53
+ * @public
54
+ */
55
+ type WhiteSpacePasteMode = 'preserve' | 'remove' | 'normalize';
56
+ /**
57
+ * @public
58
+ */
59
+ interface HtmlDeserializerOptions {
60
+ keyGenerator?: () => string;
61
+ rules?: DeserializerRule[];
62
+ parseHtml?: HtmlParser;
63
+ unstable_whitespaceOnPasteMode?: WhiteSpacePasteMode;
76
64
  }
77
-
78
65
  /**
79
- * Normalize and extract features of an schema type containing a block type
80
- *
81
- * @param blockContentType - Schema type for the block type
82
- * @returns Returns the featureset of a compiled block content type.
83
66
  * @public
84
67
  */
85
- export declare function getBlockContentFeatures(
86
- blockContentType: ArraySchemaType,
87
- ): BlockContentFeatures
88
68
 
89
69
  /**
90
70
  * @public
91
71
  */
92
- export declare interface HtmlDeserializerOptions {
93
- keyGenerator?: () => string
94
- rules?: DeserializerRule[]
95
- parseHtml?: HtmlParser
96
- unstable_whitespaceOnPasteMode?: WhiteSpacePasteMode
72
+ interface DeserializerRule {
73
+ deserialize: (el: Node, next: (elements: Node | Node[] | NodeList) => TypedObject | TypedObject[] | undefined, createBlock: (props: ArbitraryTypedObject) => {
74
+ _type: string;
75
+ block: ArbitraryTypedObject;
76
+ }) => TypedObject | TypedObject[] | undefined;
97
77
  }
98
-
99
78
  /**
100
79
  * @public
101
80
  */
102
- export declare type HtmlParser = (html: string) => Document
103
-
104
81
  /**
105
- * Convert HTML to blocks respecting the block content type's schema
82
+ * Block normalization options
106
83
  *
107
- * @param html - The HTML to convert to blocks
108
- * @param blockContentType - A compiled version of the schema type for the block content
109
- * @param options - Options for deserializing HTML to blocks
110
- * @returns Array of blocks
111
84
  * @public
112
85
  */
113
- export declare function htmlToBlocks(
114
- html: string,
115
- blockContentType: ArraySchemaType,
116
- options?: HtmlDeserializerOptions,
117
- ): (TypedObject | PortableTextTextBlock)[]
118
-
86
+ interface BlockNormalizationOptions {
87
+ /**
88
+ * Decorator names that are allowed within portable text blocks, eg `em`, `strong`
89
+ */
90
+ allowedDecorators?: string[];
91
+ /**
92
+ * Name of the portable text block type, if not `block`
93
+ */
94
+ blockTypeName?: string;
95
+ /**
96
+ * Custom key generator function
97
+ */
98
+ keyGenerator?: () => string;
99
+ }
119
100
  /**
120
101
  * Normalizes a block by ensuring it has a `_key` property. If the block is a
121
102
  * portable text block, additional normalization is applied:
@@ -131,16 +112,9 @@ export declare function htmlToBlocks(
131
112
  * @returns Normalized block
132
113
  * @public
133
114
  */
134
- export declare function normalizeBlock(
135
- node: TypedObject,
136
- options?: BlockNormalizationOptions,
137
- ): Omit<
138
- TypedObject | PortableTextTextBlock<TypedObject | PortableTextSpan>,
139
- '_key'
140
- > & {
141
- _key: string
142
- }
143
-
115
+ declare function normalizeBlock(node: TypedObject, options?: BlockNormalizationOptions): Omit<TypedObject | PortableTextTextBlock<TypedObject | PortableTextSpan>, '_key'> & {
116
+ _key: string;
117
+ };
144
118
  /**
145
119
  * Generate a random key of the given length
146
120
  *
@@ -148,30 +122,23 @@ export declare function normalizeBlock(
148
122
  * @returns A string of the given length
149
123
  * @public
150
124
  */
151
- export declare function randomKey(length: number): string
152
-
153
- /**
154
- * @public
155
- */
156
- export declare interface ResolvedAnnotationType {
157
- blockEditor?: BlockEditorSchemaProps
158
- title: string | undefined
159
- value: string
160
- type: ObjectSchemaType
161
- icon: ComponentType | undefined
162
- }
163
-
125
+ declare function randomKey(length: number): string;
164
126
  /**
127
+ * Convert HTML to blocks respecting the block content type's schema
128
+ *
129
+ * @param html - The HTML to convert to blocks
130
+ * @param blockContentType - A compiled version of the schema type for the block content
131
+ * @param options - Options for deserializing HTML to blocks
132
+ * @returns Array of blocks
165
133
  * @public
166
134
  */
167
- export declare interface TypedObject {
168
- _type: string
169
- _key?: string
170
- }
171
-
135
+ declare function htmlToBlocks(html: string, blockContentType: ArraySchemaType, options?: HtmlDeserializerOptions): (TypedObject | PortableTextTextBlock)[];
172
136
  /**
137
+ * Normalize and extract features of an schema type containing a block type
138
+ *
139
+ * @param blockContentType - Schema type for the block type
140
+ * @returns Returns the featureset of a compiled block content type.
173
141
  * @public
174
142
  */
175
- declare type WhiteSpacePasteMode = 'preserve' | 'remove' | 'normalize'
176
-
177
- export {}
143
+ declare function getBlockContentFeatures(blockContentType: ArraySchemaType): BlockContentFeatures;
144
+ export { type ArbitraryTypedObject, type BlockContentFeatures, type BlockEditorSchemaProps, type BlockNormalizationOptions, type DeserializerRule, type HtmlDeserializerOptions, type HtmlParser, type ResolvedAnnotationType, type TypedObject, getBlockContentFeatures, htmlToBlocks, normalizeBlock, randomKey };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/block-tools",
3
- "version": "1.1.38",
3
+ "version": "2.0.0-canary.0",
4
4
  "description": "Can format HTML, Slate JSON or Sanity block array into any other format.",
5
5
  "keywords": [
6
6
  "portable-text",
@@ -40,9 +40,9 @@
40
40
  "lodash": "^4.17.21"
41
41
  },
42
42
  "devDependencies": {
43
- "@sanity/pkg-utils": "^7.9.3",
44
- "@sanity/schema": "^3.98.1",
45
- "@sanity/types": "^3.98.1",
43
+ "@sanity/pkg-utils": "^7.9.6",
44
+ "@sanity/schema": "^4.0.1",
45
+ "@sanity/types": "^4.0.1",
46
46
  "@types/jsdom": "^20.0.0",
47
47
  "@types/lodash": "^4.17.16",
48
48
  "@types/react": "^19.1.8",
@@ -53,8 +53,8 @@
53
53
  "vitest": "^3.2.4"
54
54
  },
55
55
  "peerDependencies": {
56
- "@sanity/types": "^3.98.0 || ^4.0.0-0",
57
- "@types/react": "18 || 19"
56
+ "@sanity/types": "^4.0.1",
57
+ "@types/react": "^18.3 || ^19"
58
58
  },
59
59
  "publishConfig": {
60
60
  "access": "public"