@portabletext/editor 1.45.1 → 1.45.3
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/_chunks-cjs/behavior.markdown.cjs +8 -8
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +36 -39
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/parse-blocks.cjs +4 -1
- package/lib/_chunks-cjs/parse-blocks.cjs.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +9 -9
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +36 -39
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/parse-blocks.js +4 -1
- package/lib/_chunks-es/parse-blocks.js.map +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +1 -1
- package/lib/behaviors/index.cjs +4 -4
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +282 -282
- package/lib/behaviors/index.d.ts +282 -282
- package/lib/behaviors/index.js +4 -4
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.d.cts +8 -8
- package/lib/index.d.ts +8 -8
- package/lib/plugins/index.cjs +4 -4
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +8 -8
- package/lib/plugins/index.d.ts +8 -8
- package/lib/plugins/index.js +4 -4
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.cts +8 -8
- package/lib/selectors/index.d.ts +8 -8
- package/lib/utils/index.d.cts +8 -8
- package/lib/utils/index.d.ts +8 -8
- package/package.json +6 -6
- package/src/behavior-actions/behavior.action.insert.text.ts +2 -1
- package/src/behavior-actions/behavior.actions.ts +0 -9
- package/src/behaviors/behavior.abstract.delete.ts +42 -0
- package/src/behaviors/behavior.decorator-pair.ts +5 -4
- package/src/behaviors/behavior.default.ts +2 -0
- package/src/behaviors/behavior.emoji-picker.ts +5 -4
- package/src/behaviors/behavior.markdown.ts +9 -8
- package/src/behaviors/behavior.types.event.ts +8 -8
- package/src/internal-utils/parse-blocks.ts +6 -1
- package/src/behavior-actions/behavior.action.delete.text.ts +0 -53
|
@@ -3,6 +3,7 @@ import type {EditorSchema} from '../editor/define-schema'
|
|
|
3
3
|
import * as selectors from '../selectors'
|
|
4
4
|
import {spanSelectionPointToBlockOffset} from '../utils/util.block-offset'
|
|
5
5
|
import {getTextBlockText} from '../utils/util.get-text-block-text'
|
|
6
|
+
import {raise} from './behavior.types.action'
|
|
6
7
|
import {defineBehavior} from './behavior.types.behavior'
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -135,7 +136,7 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
135
136
|
props: {style},
|
|
136
137
|
at: focusTextBlock.path,
|
|
137
138
|
},
|
|
138
|
-
{
|
|
139
|
+
raise({
|
|
139
140
|
type: 'delete.text',
|
|
140
141
|
at: {
|
|
141
142
|
anchor: {
|
|
@@ -147,7 +148,7 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
147
148
|
offset: 2,
|
|
148
149
|
},
|
|
149
150
|
},
|
|
150
|
-
},
|
|
151
|
+
}),
|
|
151
152
|
],
|
|
152
153
|
],
|
|
153
154
|
})
|
|
@@ -213,10 +214,10 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
213
214
|
...(hrObject.value ?? {}),
|
|
214
215
|
},
|
|
215
216
|
},
|
|
216
|
-
{
|
|
217
|
+
raise({
|
|
217
218
|
type: 'delete.text',
|
|
218
219
|
at: hrBlockOffsets,
|
|
219
|
-
},
|
|
220
|
+
}),
|
|
220
221
|
],
|
|
221
222
|
],
|
|
222
223
|
})
|
|
@@ -348,7 +349,7 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
348
349
|
props: {style},
|
|
349
350
|
at: focusTextBlock.path,
|
|
350
351
|
},
|
|
351
|
-
{
|
|
352
|
+
raise({
|
|
352
353
|
type: 'delete.text',
|
|
353
354
|
at: {
|
|
354
355
|
anchor: {
|
|
@@ -360,7 +361,7 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
360
361
|
offset: level + 1,
|
|
361
362
|
},
|
|
362
363
|
},
|
|
363
|
-
},
|
|
364
|
+
}),
|
|
364
365
|
],
|
|
365
366
|
],
|
|
366
367
|
})
|
|
@@ -487,7 +488,7 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
487
488
|
},
|
|
488
489
|
at: focusTextBlock.path,
|
|
489
490
|
},
|
|
490
|
-
{
|
|
491
|
+
raise({
|
|
491
492
|
type: 'delete.text',
|
|
492
493
|
at: {
|
|
493
494
|
anchor: {
|
|
@@ -499,7 +500,7 @@ export function createMarkdownBehaviors(config: MarkdownBehaviorsConfig) {
|
|
|
499
500
|
offset: listItemLength + 1,
|
|
500
501
|
},
|
|
501
502
|
},
|
|
502
|
-
},
|
|
503
|
+
}),
|
|
503
504
|
],
|
|
504
505
|
],
|
|
505
506
|
})
|
|
@@ -68,7 +68,6 @@ const syntheticBehaviorEventTypes = [
|
|
|
68
68
|
'delete.backward',
|
|
69
69
|
'delete.block',
|
|
70
70
|
'delete.forward',
|
|
71
|
-
'delete.text',
|
|
72
71
|
'focus',
|
|
73
72
|
'history.redo',
|
|
74
73
|
'history.undo',
|
|
@@ -144,13 +143,6 @@ export type SyntheticBehaviorEvent =
|
|
|
144
143
|
type: StrictExtract<SyntheticBehaviorEventType, 'delete.forward'>
|
|
145
144
|
unit: TextUnit
|
|
146
145
|
}
|
|
147
|
-
| {
|
|
148
|
-
type: StrictExtract<SyntheticBehaviorEventType, 'delete.text'>
|
|
149
|
-
at: {
|
|
150
|
-
anchor: BlockOffset
|
|
151
|
-
focus: BlockOffset
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
146
|
| {
|
|
155
147
|
type: StrictExtract<SyntheticBehaviorEventType, 'focus'>
|
|
156
148
|
}
|
|
@@ -214,6 +206,7 @@ export function isKeyboardBehaviorEvent(
|
|
|
214
206
|
const abstractBehaviorEventTypes = [
|
|
215
207
|
'annotation.toggle',
|
|
216
208
|
'decorator.toggle',
|
|
209
|
+
'delete.text',
|
|
217
210
|
'deserialize',
|
|
218
211
|
'deserialization.success',
|
|
219
212
|
'deserialization.failure',
|
|
@@ -253,6 +246,13 @@ export type AbstractBehaviorEvent =
|
|
|
253
246
|
decorator: string
|
|
254
247
|
at?: {anchor: BlockOffset; focus: BlockOffset}
|
|
255
248
|
}
|
|
249
|
+
| {
|
|
250
|
+
type: StrictExtract<AbstractBehaviorEventType, 'delete.text'>
|
|
251
|
+
at: {
|
|
252
|
+
anchor: BlockOffset
|
|
253
|
+
focus: BlockOffset
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
256
|
| {
|
|
257
257
|
type: StrictExtract<AbstractBehaviorEventType, 'deserialize'>
|
|
258
258
|
originEvent:
|
|
@@ -369,7 +369,12 @@ function parseObject({
|
|
|
369
369
|
// the name of a field
|
|
370
370
|
const values = context.schemaType.fields.reduce<Record<string, unknown>>(
|
|
371
371
|
(fieldValues, field) => {
|
|
372
|
-
|
|
372
|
+
const fieldValue = object[field.name]
|
|
373
|
+
|
|
374
|
+
if (fieldValue !== undefined) {
|
|
375
|
+
fieldValues[field.name] = fieldValue
|
|
376
|
+
}
|
|
377
|
+
|
|
373
378
|
return fieldValues
|
|
374
379
|
},
|
|
375
380
|
{},
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import {Transforms} from 'slate'
|
|
2
|
-
import {toSlateRange} from '../internal-utils/ranges'
|
|
3
|
-
import {fromSlateValue} from '../internal-utils/values'
|
|
4
|
-
import {KEY_TO_VALUE_ELEMENT} from '../internal-utils/weakMaps'
|
|
5
|
-
import * as selectors from '../selectors'
|
|
6
|
-
import * as utils from '../utils'
|
|
7
|
-
import type {BehaviorActionImplementation} from './behavior.actions'
|
|
8
|
-
|
|
9
|
-
export const deleteTextActionImplementation: BehaviorActionImplementation<
|
|
10
|
-
'delete.text'
|
|
11
|
-
> = ({context, action}) => {
|
|
12
|
-
const value = fromSlateValue(
|
|
13
|
-
action.editor.children,
|
|
14
|
-
context.schema.block.name,
|
|
15
|
-
KEY_TO_VALUE_ELEMENT.get(action.editor),
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
const selection = utils.blockOffsetsToSelection({
|
|
19
|
-
value,
|
|
20
|
-
offsets: action.at,
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
if (!selection) {
|
|
24
|
-
throw new Error('Unable to find selection from block offsets')
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const trimmedSelection = selectors.getTrimmedSelection({
|
|
28
|
-
beta: {hasTag: () => false, internalDrag: undefined},
|
|
29
|
-
context: {
|
|
30
|
-
converters: [],
|
|
31
|
-
schema: context.schema,
|
|
32
|
-
keyGenerator: context.keyGenerator,
|
|
33
|
-
activeDecorators: [],
|
|
34
|
-
readOnly: false,
|
|
35
|
-
value,
|
|
36
|
-
selection,
|
|
37
|
-
},
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
if (!trimmedSelection) {
|
|
41
|
-
throw new Error('Unable to find trimmed selection')
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const range = toSlateRange(trimmedSelection, action.editor)
|
|
45
|
-
|
|
46
|
-
if (!range) {
|
|
47
|
-
throw new Error('Unable to find Slate range from trimmed selection')
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
Transforms.delete(action.editor, {
|
|
51
|
-
at: range,
|
|
52
|
-
})
|
|
53
|
-
}
|