@portabletext/editor 1.57.4 → 1.57.5

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.57.4",
3
+ "version": "1.57.5",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -80,16 +80,16 @@
80
80
  "slate-react": "0.117.3",
81
81
  "use-effect-event": "^1.0.2",
82
82
  "xstate": "^5.20.1",
83
- "@portabletext/block-tools": "1.1.37",
84
83
  "@portabletext/keyboard-shortcuts": "1.1.0",
85
- "@portabletext/patches": "1.1.5"
84
+ "@portabletext/patches": "1.1.5",
85
+ "@portabletext/block-tools": "1.1.38"
86
86
  },
87
87
  "devDependencies": {
88
88
  "@portabletext/toolkit": "^2.0.17",
89
89
  "@sanity/diff-match-patch": "^3.2.0",
90
- "@sanity/pkg-utils": "^7.9.2",
91
- "@sanity/schema": "^3.98.0",
92
- "@sanity/types": "^3.98.0",
90
+ "@sanity/pkg-utils": "^7.9.3",
91
+ "@sanity/schema": "^3.98.1",
92
+ "@sanity/types": "^3.98.1",
93
93
  "@testing-library/react": "^16.3.0",
94
94
  "@types/debug": "^4.1.12",
95
95
  "@types/lodash": "^4.17.16",
@@ -1,5 +1,6 @@
1
1
  import {Transforms} from 'slate'
2
2
  import {createPlaceholderBlock} from '../internal-utils/create-placeholder-block'
3
+ import {isTextBlock} from '../internal-utils/parse-blocks'
3
4
  import {getBlockPath} from '../internal-utils/slate-utils'
4
5
  import {toSlateRange} from '../internal-utils/to-slate-range'
5
6
  import {getBlockKeyFromSelectionPoint} from '../selection/selection-point'
@@ -10,6 +11,26 @@ export const deleteOperationImplementation: BehaviorOperationImplementation<
10
11
  > = ({context, operation}) => {
11
12
  const anchorBlockKey = getBlockKeyFromSelectionPoint(operation.at.anchor)
12
13
  const focusBlockKey = getBlockKeyFromSelectionPoint(operation.at.focus)
14
+ const endBlockKey = operation.at.backward ? anchorBlockKey : focusBlockKey
15
+ const endOffset = operation.at.backward
16
+ ? operation.at.focus.offset
17
+ : operation.at.anchor.offset
18
+
19
+ if (!endBlockKey) {
20
+ throw new Error('Failed to get end block key')
21
+ }
22
+
23
+ const endBlockIndex = operation.editor.blockIndexMap.get(endBlockKey)
24
+
25
+ if (endBlockIndex === undefined) {
26
+ throw new Error('Failed to get end block index')
27
+ }
28
+
29
+ const endBlock = operation.editor.value.at(endBlockIndex)
30
+
31
+ if (!endBlock) {
32
+ throw new Error('Failed to get end block')
33
+ }
13
34
 
14
35
  const anchorBlockPath =
15
36
  anchorBlockKey !== undefined
@@ -59,9 +80,12 @@ export const deleteOperationImplementation: BehaviorOperationImplementation<
59
80
  )
60
81
  }
61
82
 
83
+ const hanging = isTextBlock(context, endBlock) && endOffset === 0
84
+
62
85
  operation.editor.delete({
63
86
  at: range,
64
87
  reverse: operation.direction === 'backward',
65
88
  unit: operation.unit,
89
+ hanging,
66
90
  })
67
91
  }