@portabletext/editor 1.5.1 → 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/README.md +1 -1
- package/lib/index.d.mts +74 -18
- package/lib/index.d.ts +74 -18
- package/lib/index.esm.js +178 -140
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +178 -140
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +178 -140
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/editor/behavior/behavior.core.block-objects.ts +4 -4
- package/src/editor/behavior/behavior.core.lists.ts +1 -1
- package/src/editor/behavior/behavior.core.ts +17 -2
- package/src/editor/behavior/behavior.markdown.ts +5 -0
- package/src/editor/define-schema.ts +22 -2
- package/src/editor/editor-machine.ts +2 -4
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +18 -0
- package/src/index.ts +2 -1
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
selectionIsCollapsed,
|
|
10
10
|
} from './behavior.utils'
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const breakingBlockObject = defineBehavior({
|
|
13
13
|
on: 'insert break',
|
|
14
14
|
guard: ({context}) => {
|
|
15
15
|
const focusBlockObject = getFocusBlockObject(context)
|
|
@@ -99,8 +99,8 @@ const deletingEmptyTextBlockBeforeBlockObject = defineBehavior({
|
|
|
99
99
|
],
|
|
100
100
|
})
|
|
101
101
|
|
|
102
|
-
export const coreBlockObjectBehaviors =
|
|
103
|
-
|
|
102
|
+
export const coreBlockObjectBehaviors = {
|
|
103
|
+
breakingBlockObject,
|
|
104
104
|
deletingEmptyTextBlockAfterBlockObject,
|
|
105
105
|
deletingEmptyTextBlockBeforeBlockObject,
|
|
106
|
-
|
|
106
|
+
}
|
|
@@ -7,8 +7,23 @@ const softReturn = defineBehavior({
|
|
|
7
7
|
actions: [() => [{type: 'insert text', text: '\n'}]],
|
|
8
8
|
})
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* @alpha
|
|
12
|
+
*/
|
|
10
13
|
export const coreBehaviors = [
|
|
11
14
|
softReturn,
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
coreBlockObjectBehaviors.breakingBlockObject,
|
|
16
|
+
coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject,
|
|
17
|
+
coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject,
|
|
18
|
+
coreListBehaviors.clearListOnBackspace,
|
|
19
|
+
coreListBehaviors.unindentListOnBackspace,
|
|
14
20
|
]
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @alpha
|
|
24
|
+
*/
|
|
25
|
+
export const coreBehavior = {
|
|
26
|
+
softReturn,
|
|
27
|
+
blockObjects: coreBlockObjectBehaviors,
|
|
28
|
+
lists: coreListBehaviors,
|
|
29
|
+
}
|
|
@@ -74,6 +74,11 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
74
74
|
},
|
|
75
75
|
],
|
|
76
76
|
(_, {focusTextBlock, focusSpan, style}) => [
|
|
77
|
+
{
|
|
78
|
+
type: 'unset block',
|
|
79
|
+
props: ['listItem', 'level'],
|
|
80
|
+
paths: [focusTextBlock.path],
|
|
81
|
+
},
|
|
77
82
|
{
|
|
78
83
|
type: 'set block',
|
|
79
84
|
style,
|
|
@@ -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
|
}
|
|
@@ -153,7 +153,7 @@ export const editorMachine = setup({
|
|
|
153
153
|
'assign behaviors': assign({
|
|
154
154
|
behaviors: ({event}) => {
|
|
155
155
|
assertEvent(event, 'update behaviors')
|
|
156
|
-
return
|
|
156
|
+
return event.behaviors
|
|
157
157
|
},
|
|
158
158
|
}),
|
|
159
159
|
'assign schema': assign({
|
|
@@ -274,9 +274,7 @@ export const editorMachine = setup({
|
|
|
274
274
|
}).createMachine({
|
|
275
275
|
id: 'editor',
|
|
276
276
|
context: ({input}) => ({
|
|
277
|
-
behaviors: input.behaviors
|
|
278
|
-
? [...coreBehaviors, ...input.behaviors]
|
|
279
|
-
: coreBehaviors,
|
|
277
|
+
behaviors: input.behaviors ?? coreBehaviors,
|
|
280
278
|
keyGenerator: input.keyGenerator,
|
|
281
279
|
pendingEvents: [],
|
|
282
280
|
schema: input.schema,
|
|
@@ -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
|
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type {Patch} from '@portabletext/patches'
|
|
2
2
|
export type {PortableTextBlock, PortableTextChild} from '@sanity/types'
|
|
3
|
+
export {coreBehavior, coreBehaviors} from './editor/behavior/behavior.core'
|
|
3
4
|
export {
|
|
4
5
|
createMarkdownBehaviors,
|
|
5
6
|
type MarkdownBehaviorsConfig,
|
|
@@ -16,8 +17,8 @@ export {
|
|
|
16
17
|
} from './editor/behavior/behavior.types'
|
|
17
18
|
export {
|
|
18
19
|
defineSchema,
|
|
19
|
-
type SchemaDefinition,
|
|
20
20
|
type BaseDefinition,
|
|
21
|
+
type SchemaDefinition,
|
|
21
22
|
} from './editor/define-schema'
|
|
22
23
|
export {PortableTextEditable} from './editor/Editable'
|
|
23
24
|
export type {PortableTextEditableProps} from './editor/Editable'
|