@portabletext/editor 1.47.7 → 1.47.9

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.47.7",
3
+ "version": "1.47.9",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -1,4 +1,5 @@
1
1
  import {getFocusTextBlock} from '../selectors'
2
+ import {isEmptyTextBlock} from '../utils'
2
3
  import {raise} from './behavior.types.action'
3
4
  import {defineBehavior} from './behavior.types.behavior'
4
5
 
@@ -46,10 +47,10 @@ export const abstractInsertBehaviors = [
46
47
  return false
47
48
  }
48
49
 
49
- return true
50
+ return {focusTextBlock}
50
51
  },
51
52
  actions: [
52
- ({event}) =>
53
+ ({event}, {focusTextBlock}) =>
53
54
  event.blocks.length === 1
54
55
  ? [
55
56
  raise({
@@ -59,45 +60,54 @@ export const abstractInsertBehaviors = [
59
60
  select: 'end',
60
61
  }),
61
62
  ]
62
- : event.blocks.flatMap((block, index) =>
63
- index === 0
64
- ? [
65
- raise({
66
- type: 'split.block',
67
- }),
68
- raise({
69
- type: 'select.previous block',
70
- select: 'end',
71
- }),
72
- raise({
73
- type: 'insert.block',
74
- block,
75
- placement: 'auto',
76
- select: 'end',
77
- }),
78
- ]
79
- : index === event.blocks.length - 1
63
+ : isEmptyTextBlock(focusTextBlock.node)
64
+ ? event.blocks.map((block, index) =>
65
+ raise({
66
+ type: 'insert.block',
67
+ block,
68
+ placement: index === 0 ? 'auto' : 'after',
69
+ select: 'end',
70
+ }),
71
+ )
72
+ : event.blocks.flatMap((block, index) =>
73
+ index === 0
80
74
  ? [
81
75
  raise({
82
- type: 'select.next block',
83
- select: 'start',
76
+ type: 'split.block',
84
77
  }),
85
78
  raise({
86
- type: 'insert.block',
87
- block,
88
- placement: 'auto',
79
+ type: 'select.previous block',
89
80
  select: 'end',
90
81
  }),
91
- ]
92
- : [
93
82
  raise({
94
83
  type: 'insert.block',
95
84
  block,
96
- placement: 'after',
85
+ placement: 'auto',
97
86
  select: 'end',
98
87
  }),
99
- ],
100
- ),
88
+ ]
89
+ : index === event.blocks.length - 1
90
+ ? [
91
+ raise({
92
+ type: 'select.next block',
93
+ select: 'start',
94
+ }),
95
+ raise({
96
+ type: 'insert.block',
97
+ block,
98
+ placement: 'auto',
99
+ select: 'end',
100
+ }),
101
+ ]
102
+ : [
103
+ raise({
104
+ type: 'insert.block',
105
+ block,
106
+ placement: 'after',
107
+ select: 'end',
108
+ }),
109
+ ],
110
+ ),
101
111
  ],
102
112
  }),
103
113
  defineBehavior({
@@ -9,7 +9,6 @@ import {
9
9
  } from 'slate'
10
10
  import {
11
11
  and,
12
- assertEvent,
13
12
  assign,
14
13
  fromCallback,
15
14
  setup,
@@ -82,16 +81,16 @@ export const rangeDecorationsMachine = setup({
82
81
  },
83
82
  actions: {
84
83
  'update pending range decorations': assign({
85
- pendingRangeDecorations: ({event}) => {
86
- assertEvent(event, 'range decorations updated')
84
+ pendingRangeDecorations: ({context, event}) => {
85
+ if (event.type !== 'range decorations updated') {
86
+ return context.pendingRangeDecorations
87
+ }
87
88
 
88
89
  return event.rangeDecorations
89
90
  },
90
91
  }),
91
92
  'set up initial range decorations': assign({
92
- decoratedRanges: ({context, event}) => {
93
- assertEvent(event, 'ready')
94
-
93
+ decoratedRanges: ({context}) => {
95
94
  const rangeDecorationState: Array<DecoratedRange> = []
96
95
 
97
96
  for (const rangeDecoration of context.pendingRangeDecorations) {
@@ -120,7 +119,9 @@ export const rangeDecorationsMachine = setup({
120
119
  }),
121
120
  'update range decorations': assign({
122
121
  decoratedRanges: ({context, event}) => {
123
- assertEvent(event, 'range decorations updated')
122
+ if (event.type !== 'range decorations updated') {
123
+ return context.decoratedRanges
124
+ }
124
125
 
125
126
  const rangeDecorationState: Array<DecoratedRange> = []
126
127
 
@@ -150,7 +151,9 @@ export const rangeDecorationsMachine = setup({
150
151
  }),
151
152
  'move range decorations': assign({
152
153
  decoratedRanges: ({context, event}) => {
153
- assertEvent(event, 'slate operation')
154
+ if (event.type !== 'slate operation') {
155
+ return context.decoratedRanges
156
+ }
154
157
 
155
158
  const rangeDecorationState: Array<DecoratedRange> = []
156
159
 
@@ -212,8 +215,11 @@ export const rangeDecorationsMachine = setup({
212
215
  },
213
216
  }),
214
217
  'assign readOnly': assign({
215
- readOnly: ({event}) => {
216
- assertEvent(event, 'update read only')
218
+ readOnly: ({context, event}) => {
219
+ if (event.type !== 'update read only') {
220
+ return context.readOnly
221
+ }
222
+
217
223
  return event.readOnly
218
224
  },
219
225
  }),
@@ -231,7 +237,9 @@ export const rangeDecorationsMachine = setup({
231
237
  context.pendingRangeDecorations.length > 0,
232
238
  'has range decorations': ({context}) => context.decoratedRanges.length > 0,
233
239
  'has different decorations': ({context, event}) => {
234
- assertEvent(event, 'range decorations updated')
240
+ if (event.type !== 'range decorations updated') {
241
+ return false
242
+ }
235
243
 
236
244
  const existingRangeDecorations = context.decoratedRanges.map(
237
245
  (decoratedRange) => ({