@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -9,7 +9,7 @@ import {
9
9
  selectionIsCollapsed,
10
10
  } from './behavior.utils'
11
11
 
12
- const breakingVoidBlock = defineBehavior({
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
- breakingVoidBlock,
102
+ export const coreBlockObjectBehaviors = {
103
+ breakingBlockObject,
104
104
  deletingEmptyTextBlockAfterBlockObject,
105
105
  deletingEmptyTextBlockBeforeBlockObject,
106
- ]
106
+ }
@@ -73,4 +73,4 @@ const unindentListOnBackspace = defineBehavior({
73
73
  ],
74
74
  })
75
75
 
76
- export const coreListBehaviors = [clearListOnBackspace, unindentListOnBackspace]
76
+ export const coreListBehaviors = {clearListOnBackspace, unindentListOnBackspace}
@@ -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
- ...coreBlockObjectBehaviors,
13
- ...coreListBehaviors,
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 [...coreBehaviors, ...event.behaviors]
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'