@portabletext/editor 1.5.1 → 1.5.2
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 +151 -133
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +151 -133
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +151 -133
- 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/editor-machine.ts +2 -4
- 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,
|
|
@@ -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,
|
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'
|