@portabletext/editor 1.52.1 → 1.52.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/lib/index.cjs +34 -63
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +35 -64
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/editor/plugins/with-plugins.ts +10 -15
- package/src/internal-utils/create-placeholder-block.ts +2 -1
- package/src/operations/behavior.operation.delete.ts +6 -1
- package/src/editor/plugins/createWithPortableTextBlockStyle.ts +0 -51
package/package.json
CHANGED
|
@@ -7,7 +7,6 @@ import {createWithMaxBlocks} from './createWithMaxBlocks'
|
|
|
7
7
|
import {createWithObjectKeys} from './createWithObjectKeys'
|
|
8
8
|
import {createWithPatches} from './createWithPatches'
|
|
9
9
|
import {createWithPlaceholderBlock} from './createWithPlaceholderBlock'
|
|
10
|
-
import {createWithPortableTextBlockStyle} from './createWithPortableTextBlockStyle'
|
|
11
10
|
import {createWithPortableTextMarkModel} from './createWithPortableTextMarkModel'
|
|
12
11
|
import {createWithPortableTextSelections} from './createWithPortableTextSelections'
|
|
13
12
|
import {createWithSchemaTypes} from './createWithSchemaTypes'
|
|
@@ -49,8 +48,6 @@ export const withPlugins = <T extends Editor>(
|
|
|
49
48
|
subscriptions: options.subscriptions,
|
|
50
49
|
})
|
|
51
50
|
const withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor)
|
|
52
|
-
const withPortableTextBlockStyle =
|
|
53
|
-
createWithPortableTextBlockStyle(editorActor)
|
|
54
51
|
|
|
55
52
|
const withPlaceholderBlock = createWithPlaceholderBlock(editorActor)
|
|
56
53
|
|
|
@@ -66,19 +63,17 @@ export const withPlugins = <T extends Editor>(
|
|
|
66
63
|
withSchemaTypes(
|
|
67
64
|
withObjectKeys(
|
|
68
65
|
withPortableTextMarkModel(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
66
|
+
withPlaceholderBlock(
|
|
67
|
+
withUtils(
|
|
68
|
+
withMaxBlocks(
|
|
69
|
+
withUndoRedo(
|
|
70
|
+
withPatches(
|
|
71
|
+
withPortableTextSelections(
|
|
72
|
+
pluginUpdateValue(
|
|
73
|
+
editorActor.getSnapshot().context,
|
|
74
|
+
pluginUpdateMarkState(
|
|
77
75
|
editorActor.getSnapshot().context,
|
|
78
|
-
|
|
79
|
-
editorActor.getSnapshot().context,
|
|
80
|
-
e,
|
|
81
|
-
),
|
|
76
|
+
e,
|
|
82
77
|
),
|
|
83
78
|
),
|
|
84
79
|
),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type {PortableTextSpan} from '@sanity/types'
|
|
1
2
|
import type {EditorContext} from '../editor/editor-snapshot'
|
|
2
3
|
|
|
3
4
|
export function createPlaceholderBlock(
|
|
@@ -14,7 +15,7 @@ export function createPlaceholderBlock(
|
|
|
14
15
|
_key: context.keyGenerator(),
|
|
15
16
|
text: '',
|
|
16
17
|
marks: [],
|
|
17
|
-
},
|
|
18
|
+
} as PortableTextSpan,
|
|
18
19
|
],
|
|
19
20
|
}
|
|
20
21
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {Transforms} from 'slate'
|
|
2
|
+
import {createPlaceholderBlock} from '../internal-utils/create-placeholder-block'
|
|
2
3
|
import {toSlateRange} from '../internal-utils/ranges'
|
|
3
4
|
import {getBlockPath} from '../internal-utils/slate-utils'
|
|
4
5
|
import {getBlockKeyFromSelectionPoint} from '../selection/selection-point'
|
|
@@ -6,7 +7,7 @@ import type {BehaviorOperationImplementation} from './behavior.operations'
|
|
|
6
7
|
|
|
7
8
|
export const deleteOperationImplementation: BehaviorOperationImplementation<
|
|
8
9
|
'delete'
|
|
9
|
-
> = ({operation}) => {
|
|
10
|
+
> = ({context, operation}) => {
|
|
10
11
|
const anchorBlockKey = getBlockKeyFromSelectionPoint(operation.at.anchor)
|
|
11
12
|
const focusBlockKey = getBlockKeyFromSelectionPoint(operation.at.focus)
|
|
12
13
|
|
|
@@ -36,6 +37,10 @@ export const deleteOperationImplementation: BehaviorOperationImplementation<
|
|
|
36
37
|
at: [anchorBlockPath[0]],
|
|
37
38
|
})
|
|
38
39
|
|
|
40
|
+
if (operation.editor.children.length === 0) {
|
|
41
|
+
Transforms.insertNodes(operation.editor, createPlaceholderBlock(context))
|
|
42
|
+
}
|
|
43
|
+
|
|
39
44
|
return
|
|
40
45
|
}
|
|
41
46
|
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import {Editor, Path, Text as SlateText, Transforms} from 'slate'
|
|
2
|
-
import {debugWithName} from '../../internal-utils/debug'
|
|
3
|
-
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
4
|
-
import type {EditorActor} from '../editor-machine'
|
|
5
|
-
|
|
6
|
-
const debug = debugWithName('plugin:withPortableTextBlockStyle')
|
|
7
|
-
|
|
8
|
-
export function createWithPortableTextBlockStyle(
|
|
9
|
-
editorActor: EditorActor,
|
|
10
|
-
): (editor: PortableTextSlateEditor) => PortableTextSlateEditor {
|
|
11
|
-
const defaultStyle = editorActor.getSnapshot().context.schema.styles[0].name
|
|
12
|
-
return function withPortableTextBlockStyle(
|
|
13
|
-
editor: PortableTextSlateEditor,
|
|
14
|
-
): PortableTextSlateEditor {
|
|
15
|
-
// Extend Slate's default normalization to reset split node to normal style
|
|
16
|
-
// if there is no text at the right end of the split.
|
|
17
|
-
const {normalizeNode} = editor
|
|
18
|
-
|
|
19
|
-
editor.normalizeNode = (nodeEntry) => {
|
|
20
|
-
const [, path] = nodeEntry
|
|
21
|
-
|
|
22
|
-
for (const op of editor.operations) {
|
|
23
|
-
if (
|
|
24
|
-
op.type === 'split_node' &&
|
|
25
|
-
op.path.length === 1 &&
|
|
26
|
-
editor.isTextBlock(op.properties) &&
|
|
27
|
-
op.properties.style !== defaultStyle &&
|
|
28
|
-
op.path[0] === path[0] &&
|
|
29
|
-
!Path.equals(path, op.path)
|
|
30
|
-
) {
|
|
31
|
-
const [child] = Editor.node(editor, [op.path[0] + 1, 0])
|
|
32
|
-
if (SlateText.isText(child) && child.text === '') {
|
|
33
|
-
debug(`Normalizing split node to ${defaultStyle} style`, op)
|
|
34
|
-
editorActor.send({type: 'normalizing'})
|
|
35
|
-
Transforms.setNodes(
|
|
36
|
-
editor,
|
|
37
|
-
{style: defaultStyle},
|
|
38
|
-
{at: [op.path[0] + 1], voids: false},
|
|
39
|
-
)
|
|
40
|
-
editorActor.send({type: 'done normalizing'})
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
normalizeNode(nodeEntry)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return editor
|
|
50
|
-
}
|
|
51
|
-
}
|