Skip to content

Commit 6ba77df

Browse files
committed
feat!: remove @sanity/* dependencies
1 parent e0a58c1 commit 6ba77df

24 files changed

Lines changed: 281 additions & 483 deletions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@portabletext/editor': major
3+
---
4+
5+
feat!: remove `@sanity/*` dependencies
6+
7+
BREAKING CHANGES:
8+
9+
- `EditorConfig` no longer accepts `schema` — use `schemaDefinition` instead
10+
- `PortableTextMemberSchemaTypes` removed from exports (available from `@portabletext/sanity-bridge`)
11+
- `PasteData.schemaTypes` type changed from `PortableTextMemberSchemaTypes` to `EditorSchema`
12+
- Render prop `schemaType` fields now use PTE schema types (`BlockObjectSchemaType`, `InlineObjectSchemaType`, `AnnotationSchemaType`, `DecoratorSchemaType`, `ListSchemaType`, `StyleSchemaType`) instead of Sanity types (`ObjectSchemaType`, `BlockDecoratorDefinition`, `BlockListDefinition`, `BlockStyleDefinition`)
13+
- Deprecated `type` prop removed from `BlockRenderProps`, `BlockChildRenderProps`, `BlockAnnotationRenderProps`, and `BlockDecoratorRenderProps`
14+
- Converters are now static exports (no factory functions)

packages/editor/biome.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,6 @@
44
"rules": {
55
"complexity": {
66
"useLiteralKeys": "off"
7-
},
8-
"style": {
9-
"noRestrictedImports": {
10-
"level": "error",
11-
"options": {
12-
"paths": {
13-
"@sanity/types": "Import from 'types/sanity-types' instead to maintain visibility over @sanity/types usage."
14-
}
15-
}
16-
}
177
}
188
}
199
}

packages/editor/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@
9090
"@portabletext/patches": "workspace:^",
9191
"@portabletext/schema": "workspace:^",
9292
"@portabletext/to-html": "^5.0.1",
93-
"@sanity/schema": "^5.9.0",
94-
"@sanity/types": "^5.9.0",
9593
"@xstate/react": "^6.0.0",
9694
"debug": "^4.4.3",
9795
"slate": "^0.120.0",
@@ -100,7 +98,6 @@
10098
"xstate": "^5.25.0"
10199
},
102100
"devDependencies": {
103-
"@portabletext/sanity-bridge": "workspace:*",
104101
"@portabletext/test": "workspace:^",
105102
"@sanity/diff-match-patch": "^3.2.0",
106103
"@sanity/pkg-utils": "^10.2.1",

packages/editor/src/converters/converter.text-html.deserialize.test.ts

Lines changed: 5 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import {compileSchemaDefinitionToPortableTextMemberSchemaTypes} from '@portabletext/sanity-bridge'
21
import {
32
compileSchema,
43
defineSchema,
54
type SchemaDefinition,
65
} from '@portabletext/schema'
76
import {describe, expect, test} from 'vitest'
87
import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
9-
import {createConverterTextHtml} from './converter.text-html'
8+
import {converterTextHtml} from './converter.text-html'
109

11-
function createSnapshot(schema: SchemaDefinition) {
10+
function createSnapshot(schemaDefinition: SchemaDefinition) {
11+
const schema = compileSchema(schemaDefinition)
1212
return createTestSnapshot({
1313
context: {
1414
converters: [],
15-
schema: compileSchema(schema),
15+
schema,
1616
},
1717
})
1818
}
@@ -25,12 +25,8 @@ const unorderedList = '<ul><li>foo</li><li>bar</li></ul>'
2525
const orderedList = '<ol><li>foo</li><li>bar</li></ol>'
2626
const nestedList = '<ol><li>foo<ul><li>bar</li></ul></li></ol>'
2727

28-
describe(createConverterTextHtml.name, () => {
28+
describe(converterTextHtml.mimeType, () => {
2929
test('paragraph with unknown decorators', () => {
30-
const converterTextHtml = createConverterTextHtml(
31-
compileSchemaDefinitionToPortableTextMemberSchemaTypes(defineSchema({})),
32-
)
33-
3430
expect(
3531
converterTextHtml.deserialize({
3632
snapshot: createSnapshot(defineSchema({})),
@@ -60,14 +56,6 @@ describe(createConverterTextHtml.name, () => {
6056
})
6157

6258
test('paragraph with known decorators', () => {
63-
const converterTextHtml = createConverterTextHtml(
64-
compileSchemaDefinitionToPortableTextMemberSchemaTypes(
65-
defineSchema({
66-
decorators: [{name: 'strong'}, {name: 'em'}, {name: 'code'}],
67-
}),
68-
),
69-
)
70-
7159
expect(
7260
converterTextHtml.deserialize({
7361
snapshot: createSnapshot(
@@ -113,13 +101,6 @@ describe(createConverterTextHtml.name, () => {
113101
})
114102

115103
test('image', () => {
116-
const converterTextHtml = createConverterTextHtml(
117-
compileSchemaDefinitionToPortableTextMemberSchemaTypes(
118-
defineSchema({
119-
blockObjects: [{name: 'image'}],
120-
}),
121-
),
122-
)
123104
expect(
124105
converterTextHtml.deserialize({
125106
snapshot: createSnapshot(
@@ -138,10 +119,6 @@ describe(createConverterTextHtml.name, () => {
138119
})
139120

140121
test('paragraph with unknown link', () => {
141-
const converterTextHtml = createConverterTextHtml(
142-
compileSchemaDefinitionToPortableTextMemberSchemaTypes(defineSchema({})),
143-
)
144-
145122
expect(
146123
converterTextHtml.deserialize({
147124
snapshot: createSnapshot(defineSchema({})),
@@ -171,16 +148,6 @@ describe(createConverterTextHtml.name, () => {
171148
})
172149

173150
test('paragraph with known link', () => {
174-
const converterTextHtml = createConverterTextHtml(
175-
compileSchemaDefinitionToPortableTextMemberSchemaTypes(
176-
defineSchema({
177-
annotations: [
178-
{name: 'link', fields: [{name: 'href', type: 'string'}]},
179-
],
180-
}),
181-
),
182-
)
183-
184151
expect(
185152
converterTextHtml.deserialize({
186153
snapshot: createSnapshot(
@@ -228,14 +195,6 @@ describe(createConverterTextHtml.name, () => {
228195
})
229196

230197
test('unordered list', () => {
231-
const converterTextHtml = createConverterTextHtml(
232-
compileSchemaDefinitionToPortableTextMemberSchemaTypes(
233-
defineSchema({
234-
lists: [{name: 'bullet'}],
235-
}),
236-
),
237-
)
238-
239198
expect(
240199
converterTextHtml.deserialize({
241200
snapshot: createSnapshot(
@@ -287,14 +246,6 @@ describe(createConverterTextHtml.name, () => {
287246
})
288247

289248
test('ordered list', () => {
290-
const converterTextHtml = createConverterTextHtml(
291-
compileSchemaDefinitionToPortableTextMemberSchemaTypes(
292-
defineSchema({
293-
lists: [{name: 'number'}],
294-
}),
295-
),
296-
)
297-
298249
expect(
299250
converterTextHtml.deserialize({
300251
snapshot: createSnapshot(
@@ -346,14 +297,6 @@ describe(createConverterTextHtml.name, () => {
346297
})
347298

348299
test('nested list', () => {
349-
const converterTextHtml = createConverterTextHtml(
350-
compileSchemaDefinitionToPortableTextMemberSchemaTypes(
351-
defineSchema({
352-
lists: [{name: 'bullet'}, {name: 'number'}],
353-
}),
354-
),
355-
)
356-
357300
expect(
358301
converterTextHtml.deserialize({
359302
snapshot: createSnapshot(

packages/editor/src/converters/converter.text-html.serialize.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {compileSchemaDefinitionToPortableTextMemberSchemaTypes} from '@portabletext/sanity-bridge'
21
import {
32
compileSchema,
43
defineSchema,
@@ -9,7 +8,7 @@ import {
98
import {describe, expect, test} from 'vitest'
109
import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
1110
import type {EditorSelection} from '../types/editor'
12-
import {createConverterTextHtml} from './converter.text-html'
11+
import {converterTextHtml} from './converter.text-html'
1312

1413
const decoratedParagraph: PortableTextTextBlock = {
1514
_key: 'k0',
@@ -76,22 +75,22 @@ const paragraphWithInlineBlock: PortableTextTextBlock = {
7675
],
7776
}
7877

79-
function createSnapshot(schema: SchemaDefinition, selection: EditorSelection) {
78+
function createSnapshot(
79+
schemaDefinition: SchemaDefinition,
80+
selection: EditorSelection,
81+
) {
82+
const schema = compileSchema(schemaDefinition)
8083
return createTestSnapshot({
8184
context: {
8285
converters: [],
83-
schema: compileSchema(schema),
86+
schema,
8487
selection,
8588
value: [decoratedParagraph, image, b2, paragraphWithInlineBlock],
8689
},
8790
})
8891
}
8992

90-
const converterTextHtml = createConverterTextHtml(
91-
compileSchemaDefinitionToPortableTextMemberSchemaTypes(defineSchema({})),
92-
)
93-
94-
describe(converterTextHtml.serialize.name, () => {
93+
describe(converterTextHtml.mimeType, () => {
9594
test('paragraph with decorators', () => {
9695
expect(
9796
converterTextHtml.serialize({
@@ -183,15 +182,16 @@ describe(converterTextHtml.serialize.name, () => {
183182
})
184183

185184
test('lists', () => {
185+
const schema = compileSchema(
186+
defineSchema({
187+
lists: [{name: 'bullet'}, {name: 'number'}],
188+
}),
189+
)
186190
expect(
187191
converterTextHtml.serialize({
188192
snapshot: createTestSnapshot({
189193
context: {
190-
schema: compileSchema(
191-
defineSchema({
192-
lists: [{name: 'bullet'}, {name: 'number'}],
193-
}),
194-
),
194+
schema,
195195
converters: [],
196196
value: [
197197
{
Lines changed: 58 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,79 @@
11
import {htmlToBlocks} from '@portabletext/block-tools'
2-
import type {PortableTextBlock} from '@portabletext/schema'
32
import {toHTML} from '@portabletext/to-html'
43
import {getSelectedValue} from '../selectors/selector.get-selected-value'
5-
import type {PortableTextMemberSchemaTypes} from '../types/editor'
64
import {parseBlock} from '../utils/parse-blocks'
75
import {defineConverter} from './converter.types'
86

9-
export function createConverterTextHtml(
10-
legacySchema: PortableTextMemberSchemaTypes,
11-
) {
12-
return defineConverter({
13-
mimeType: 'text/html',
14-
serialize: ({snapshot, event}) => {
15-
const selection = snapshot.context.selection
7+
export const converterTextHtml = defineConverter({
8+
mimeType: 'text/html',
9+
serialize: ({snapshot, event}) => {
10+
const selection = snapshot.context.selection
1611

17-
if (!selection) {
18-
return {
19-
type: 'serialization.failure',
20-
mimeType: 'text/html',
21-
originEvent: event.originEvent,
22-
reason: 'No selection',
23-
}
12+
if (!selection) {
13+
return {
14+
type: 'serialization.failure',
15+
mimeType: 'text/html',
16+
originEvent: event.originEvent,
17+
reason: 'No selection',
2418
}
19+
}
2520

26-
const blocks = getSelectedValue(snapshot)
27-
28-
const html = toHTML(blocks, {
29-
onMissingComponent: false,
30-
components: {
31-
unknownType: ({children}) =>
32-
children !== undefined ? `${children}` : '',
33-
},
34-
})
21+
const blocks = getSelectedValue(snapshot)
3522

36-
if (html === '') {
37-
return {
38-
type: 'serialization.failure',
39-
mimeType: 'text/html',
40-
originEvent: event.originEvent,
41-
reason: 'Serialized HTML is empty',
42-
}
43-
}
23+
const html = toHTML(blocks, {
24+
onMissingComponent: false,
25+
components: {
26+
unknownType: ({children}) =>
27+
children !== undefined ? `${children}` : '',
28+
},
29+
})
4430

31+
if (html === '') {
4532
return {
46-
type: 'serialization.success',
47-
data: html,
33+
type: 'serialization.failure',
4834
mimeType: 'text/html',
4935
originEvent: event.originEvent,
36+
reason: 'Serialized HTML is empty',
5037
}
51-
},
52-
deserialize: ({snapshot, event}) => {
53-
const blocks = htmlToBlocks(event.data, legacySchema.portableText, {
54-
keyGenerator: snapshot.context.keyGenerator,
55-
unstable_whitespaceOnPasteMode:
56-
legacySchema.block.options.unstable_whitespaceOnPasteMode,
57-
}) as Array<PortableTextBlock>
38+
}
5839

59-
const parsedBlocks = blocks.flatMap((block) => {
60-
const parsedBlock = parseBlock({
61-
context: snapshot.context,
62-
block,
63-
options: {
64-
normalize: false,
65-
removeUnusedMarkDefs: true,
66-
validateFields: false,
67-
},
68-
})
69-
return parsedBlock ? [parsedBlock] : []
70-
})
40+
return {
41+
type: 'serialization.success',
42+
data: html,
43+
mimeType: 'text/html',
44+
originEvent: event.originEvent,
45+
}
46+
},
47+
deserialize: ({snapshot, event}) => {
48+
const blocks = htmlToBlocks(event.data, snapshot.context.schema, {
49+
keyGenerator: snapshot.context.keyGenerator,
50+
})
7151

72-
if (parsedBlocks.length === 0) {
73-
return {
74-
type: 'deserialization.failure',
75-
mimeType: 'text/html',
76-
reason: 'No blocks deserialized',
77-
}
78-
}
52+
const parsedBlocks = blocks.flatMap((block) => {
53+
const parsedBlock = parseBlock({
54+
context: snapshot.context,
55+
block,
56+
options: {
57+
normalize: false,
58+
removeUnusedMarkDefs: true,
59+
validateFields: false,
60+
},
61+
})
62+
return parsedBlock ? [parsedBlock] : []
63+
})
7964

65+
if (parsedBlocks.length === 0) {
8066
return {
81-
type: 'deserialization.success',
82-
data: parsedBlocks,
67+
type: 'deserialization.failure',
8368
mimeType: 'text/html',
69+
reason: 'No blocks deserialized',
8470
}
85-
},
86-
})
87-
}
71+
}
72+
73+
return {
74+
type: 'deserialization.success',
75+
data: parsedBlocks,
76+
mimeType: 'text/html',
77+
}
78+
},
79+
})

0 commit comments

Comments
 (0)