@portabletext/editor 1.5.2 → 1.5.3
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.esm.js +27 -7
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +27 -7
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +27 -7
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/editor/define-schema.ts +22 -2
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +18 -0
package/package.json
CHANGED
|
@@ -3,8 +3,10 @@ import {
|
|
|
3
3
|
defineField,
|
|
4
4
|
defineType,
|
|
5
5
|
type BlockDecoratorDefinition,
|
|
6
|
+
type ObjectSchemaType,
|
|
6
7
|
} from '@sanity/types'
|
|
7
8
|
import startCase from 'lodash.startcase'
|
|
9
|
+
import type {PortableTextMemberSchemaTypes} from '../types/editor'
|
|
8
10
|
import {getPortableTextMemberSchemaTypes} from '../utils/getPortableTextMemberSchemaTypes'
|
|
9
11
|
|
|
10
12
|
/**
|
|
@@ -46,7 +48,9 @@ export function compileSchemaDefinition<
|
|
|
46
48
|
definition?.blockObjects?.map((blockObject) =>
|
|
47
49
|
defineType({
|
|
48
50
|
type: 'object',
|
|
49
|
-
|
|
51
|
+
// Very naive way to work around `SanitySchema.compile` adding default
|
|
52
|
+
// fields to objects with the name `image`
|
|
53
|
+
name: blockObject.name === 'image' ? 'tmp-image' : blockObject.name,
|
|
50
54
|
title: blockObject.title,
|
|
51
55
|
icon: blockObject.icon,
|
|
52
56
|
fields: [],
|
|
@@ -107,5 +111,21 @@ export function compileSchemaDefinition<
|
|
|
107
111
|
types: [portableTextSchema, ...blockObjects, ...inlineObjects],
|
|
108
112
|
}).get('portable-text')
|
|
109
113
|
|
|
110
|
-
|
|
114
|
+
const pteSchema = getPortableTextMemberSchemaTypes(schema)
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
...pteSchema,
|
|
118
|
+
blockObjects: pteSchema.blockObjects.map((blockObject) =>
|
|
119
|
+
blockObject.name === 'tmp-image'
|
|
120
|
+
? ({
|
|
121
|
+
...blockObject,
|
|
122
|
+
name: 'image',
|
|
123
|
+
type: {
|
|
124
|
+
...blockObject.type,
|
|
125
|
+
name: 'image',
|
|
126
|
+
},
|
|
127
|
+
} as ObjectSchemaType)
|
|
128
|
+
: blockObject,
|
|
129
|
+
),
|
|
130
|
+
} satisfies PortableTextMemberSchemaTypes
|
|
111
131
|
}
|
|
@@ -411,6 +411,24 @@ export function createWithPortableTextMarkModel(
|
|
|
411
411
|
})
|
|
412
412
|
return
|
|
413
413
|
}
|
|
414
|
+
|
|
415
|
+
const nextSpanDecorators =
|
|
416
|
+
nextSpan?.marks?.filter((mark) => decorators.includes(mark)) ?? []
|
|
417
|
+
const decoratorStarting = nextSpanDecorators.length > 0
|
|
418
|
+
|
|
419
|
+
if (
|
|
420
|
+
decoratorStarting &&
|
|
421
|
+
atTheEndOfAnnotation &&
|
|
422
|
+
!atTheStartOfAnnotation &&
|
|
423
|
+
isPortableTextSpan(op.node) &&
|
|
424
|
+
op.node.marks?.length === 0
|
|
425
|
+
) {
|
|
426
|
+
Transforms.insertNodes(editor, {
|
|
427
|
+
...op.node,
|
|
428
|
+
marks: nextSpanDecorators,
|
|
429
|
+
})
|
|
430
|
+
return
|
|
431
|
+
}
|
|
414
432
|
}
|
|
415
433
|
}
|
|
416
434
|
|