@portabletext/editor 2.2.0 → 2.3.0
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/lib/index.cjs +62 -0
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +62 -0
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +3 -3
- package/package.json +3 -3
- package/src/behaviors/behavior.abstract.delete.ts +91 -1
package/lib/plugins/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Behavior, Editor, EditorEmittedEvent, EditorSchema } from "../_chunks-dts/behavior.types.action.cjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as react22 from "react";
|
|
3
3
|
import React from "react";
|
|
4
4
|
/**
|
|
5
5
|
* @beta
|
|
@@ -181,7 +181,7 @@ type MarkdownPluginConfig = MarkdownBehaviorsConfig & {
|
|
|
181
181
|
*/
|
|
182
182
|
declare function MarkdownPlugin(props: {
|
|
183
183
|
config: MarkdownPluginConfig;
|
|
184
|
-
}):
|
|
184
|
+
}): react22.JSX.Element;
|
|
185
185
|
/**
|
|
186
186
|
* @beta
|
|
187
187
|
* Restrict the editor to one line. The plugin takes care of blocking
|
|
@@ -192,5 +192,5 @@ declare function MarkdownPlugin(props: {
|
|
|
192
192
|
*
|
|
193
193
|
* @deprecated Install the plugin from `@portabletext/plugin-one-line`
|
|
194
194
|
*/
|
|
195
|
-
declare function OneLinePlugin():
|
|
195
|
+
declare function OneLinePlugin(): react22.JSX.Element;
|
|
196
196
|
export { BehaviorPlugin, DecoratorShortcutPlugin, EditorRefPlugin, EventListenerPlugin, MarkdownPlugin, type MarkdownPluginConfig, OneLinePlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -80,8 +80,8 @@
|
|
|
80
80
|
"slate-react": "0.117.4",
|
|
81
81
|
"xstate": "^5.20.2",
|
|
82
82
|
"@portabletext/block-tools": "2.0.8",
|
|
83
|
-
"@portabletext/
|
|
84
|
-
"@portabletext/
|
|
83
|
+
"@portabletext/patches": "1.1.6",
|
|
84
|
+
"@portabletext/keyboard-shortcuts": "1.1.1"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@portabletext/toolkit": "^2.0.17",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {isSpan} from '../internal-utils/parse-blocks'
|
|
1
|
+
import {isSpan, isTextBlock} from '../internal-utils/parse-blocks'
|
|
2
2
|
import * as selectors from '../selectors'
|
|
3
3
|
import * as utils from '../utils'
|
|
4
4
|
import {raise} from './behavior.types.action'
|
|
@@ -25,6 +25,57 @@ export const abstractDeleteBehaviors = [
|
|
|
25
25
|
],
|
|
26
26
|
],
|
|
27
27
|
}),
|
|
28
|
+
defineBehavior({
|
|
29
|
+
on: 'delete',
|
|
30
|
+
guard: ({snapshot, event}) => {
|
|
31
|
+
if (event.direction !== 'backward') {
|
|
32
|
+
return false
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const previousBlock = selectors.getPreviousBlock(snapshot)
|
|
36
|
+
const focusTextBlock = selectors.getFocusTextBlock(snapshot)
|
|
37
|
+
|
|
38
|
+
if (!previousBlock || !focusTextBlock) {
|
|
39
|
+
return false
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!selectors.isAtTheStartOfBlock(focusTextBlock)(snapshot)) {
|
|
43
|
+
return false
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const previousBlockEndPoint = utils.getBlockEndPoint({
|
|
47
|
+
context: snapshot.context,
|
|
48
|
+
block: previousBlock,
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
if (!isTextBlock(snapshot.context, previousBlock.node)) {
|
|
52
|
+
return false
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return {previousBlockEndPoint, focusTextBlock}
|
|
56
|
+
},
|
|
57
|
+
actions: [
|
|
58
|
+
(_, {previousBlockEndPoint, focusTextBlock}) => [
|
|
59
|
+
raise({
|
|
60
|
+
type: 'delete.block',
|
|
61
|
+
at: focusTextBlock.path,
|
|
62
|
+
}),
|
|
63
|
+
raise({
|
|
64
|
+
type: 'select',
|
|
65
|
+
at: {
|
|
66
|
+
anchor: previousBlockEndPoint,
|
|
67
|
+
focus: previousBlockEndPoint,
|
|
68
|
+
},
|
|
69
|
+
}),
|
|
70
|
+
raise({
|
|
71
|
+
type: 'insert.block',
|
|
72
|
+
block: focusTextBlock.node,
|
|
73
|
+
placement: 'auto',
|
|
74
|
+
select: 'start',
|
|
75
|
+
}),
|
|
76
|
+
],
|
|
77
|
+
],
|
|
78
|
+
}),
|
|
28
79
|
defineBehavior({
|
|
29
80
|
on: 'delete.forward',
|
|
30
81
|
guard: ({snapshot}) => {
|
|
@@ -45,6 +96,45 @@ export const abstractDeleteBehaviors = [
|
|
|
45
96
|
],
|
|
46
97
|
],
|
|
47
98
|
}),
|
|
99
|
+
defineBehavior({
|
|
100
|
+
on: 'delete',
|
|
101
|
+
guard: ({snapshot, event}) => {
|
|
102
|
+
if (event.direction !== 'forward') {
|
|
103
|
+
return false
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const nextBlock = selectors.getNextBlock(snapshot)
|
|
107
|
+
const focusTextBlock = selectors.getFocusTextBlock(snapshot)
|
|
108
|
+
|
|
109
|
+
if (!nextBlock || !focusTextBlock) {
|
|
110
|
+
return false
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (!selectors.isAtTheEndOfBlock(focusTextBlock)(snapshot)) {
|
|
114
|
+
return false
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (!isTextBlock(snapshot.context, nextBlock.node)) {
|
|
118
|
+
return false
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return {nextBlock}
|
|
122
|
+
},
|
|
123
|
+
actions: [
|
|
124
|
+
(_, {nextBlock}) => [
|
|
125
|
+
raise({
|
|
126
|
+
type: 'delete.block',
|
|
127
|
+
at: nextBlock.path,
|
|
128
|
+
}),
|
|
129
|
+
raise({
|
|
130
|
+
type: 'insert.block',
|
|
131
|
+
block: nextBlock.node,
|
|
132
|
+
placement: 'auto',
|
|
133
|
+
select: 'none',
|
|
134
|
+
}),
|
|
135
|
+
],
|
|
136
|
+
],
|
|
137
|
+
}),
|
|
48
138
|
defineBehavior({
|
|
49
139
|
on: 'delete.block',
|
|
50
140
|
actions: [
|