@portabletext/editor 3.0.9 → 3.1.1
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-dts/index.d.ts +16 -10
- package/lib/index.js +176 -262
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/behaviors/behavior.types.event.ts +1 -1
- package/src/editor/PortableTextEditor.tsx +14 -0
- package/src/editor/create-slate-editor.tsx +1 -8
- package/src/editor/plugins/createWithEditableAPI.ts +18 -83
- package/src/editor/plugins/createWithPatches.ts +3 -1
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +14 -0
- package/src/editor/plugins/with-plugins.ts +8 -19
- package/src/editor/range-decorations-machine.ts +13 -3
- package/src/editor/sync-machine.ts +0 -18
- package/src/internal-utils/applyPatch.ts +31 -41
- package/src/internal-utils/values.ts +22 -0
- package/src/operations/behavior.operation.delete.ts +17 -4
- package/src/operations/behavior.operation.insert.block.ts +5 -0
- package/src/types/editor.ts +0 -9
- package/src/editor/plugins/createWithPlaceholderBlock.ts +0 -67
- package/src/editor/plugins/createWithUtils.ts +0 -52
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import {Editor} from 'slate'
|
|
2
|
-
import {isRedoing} from '../../history/slate-plugin.redoing'
|
|
3
|
-
import {isUndoing} from '../../history/slate-plugin.undoing'
|
|
4
|
-
import {debugWithName} from '../../internal-utils/debug'
|
|
5
|
-
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
6
|
-
import type {EditorActor} from '../editor-machine'
|
|
7
|
-
import {isChangingRemotely} from '../withChanges'
|
|
8
|
-
|
|
9
|
-
const debug = debugWithName('plugin:withPlaceholderBlock')
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Keep a "placeholder" block present when the editor is empty
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
export function createWithPlaceholderBlock(
|
|
16
|
-
editorActor: EditorActor,
|
|
17
|
-
): (editor: PortableTextSlateEditor) => PortableTextSlateEditor {
|
|
18
|
-
return function withPlaceholderBlock(
|
|
19
|
-
editor: PortableTextSlateEditor,
|
|
20
|
-
): PortableTextSlateEditor {
|
|
21
|
-
const {apply} = editor
|
|
22
|
-
|
|
23
|
-
editor.apply = (op) => {
|
|
24
|
-
if (editorActor.getSnapshot().matches({'edit mode': 'read only'})) {
|
|
25
|
-
apply(op)
|
|
26
|
-
return
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* We don't want to run any side effects when the editor is processing
|
|
31
|
-
* remote changes.
|
|
32
|
-
*/
|
|
33
|
-
if (isChangingRemotely(editor)) {
|
|
34
|
-
apply(op)
|
|
35
|
-
return
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* We don't want to run any side effects when the editor is undoing or
|
|
40
|
-
* redoing operations.
|
|
41
|
-
*/
|
|
42
|
-
if (isUndoing(editor) || isRedoing(editor)) {
|
|
43
|
-
apply(op)
|
|
44
|
-
return
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (op.type === 'remove_node') {
|
|
48
|
-
const blockIndex = op.path.at(0)
|
|
49
|
-
const isLonelyBlock =
|
|
50
|
-
op.path.length === 1 &&
|
|
51
|
-
blockIndex === 0 &&
|
|
52
|
-
editor.children.length === 1
|
|
53
|
-
const isBlockObject =
|
|
54
|
-
op.node._type !== editorActor.getSnapshot().context.schema.block.name
|
|
55
|
-
|
|
56
|
-
if (isLonelyBlock && isBlockObject) {
|
|
57
|
-
debug('Adding placeholder block')
|
|
58
|
-
Editor.insertNode(editor, editor.pteCreateTextBlock({decorators: []}))
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
apply(op)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return editor
|
|
66
|
-
}
|
|
67
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import {toSlateBlock} from '../../internal-utils/values'
|
|
2
|
-
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
3
|
-
import type {EditorActor} from '../editor-machine'
|
|
4
|
-
|
|
5
|
-
interface Options {
|
|
6
|
-
editorActor: EditorActor
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* This plugin makes various util commands available in the editor
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
export function createWithUtils({editorActor}: Options) {
|
|
14
|
-
return function withUtils(
|
|
15
|
-
editor: PortableTextSlateEditor,
|
|
16
|
-
): PortableTextSlateEditor {
|
|
17
|
-
editor.pteCreateTextBlock = (options: {
|
|
18
|
-
decorators: Array<string>
|
|
19
|
-
listItem?: string
|
|
20
|
-
level?: number
|
|
21
|
-
}) => {
|
|
22
|
-
return toSlateBlock(
|
|
23
|
-
{
|
|
24
|
-
_type: editorActor.getSnapshot().context.schema.block.name,
|
|
25
|
-
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
26
|
-
style:
|
|
27
|
-
editorActor.getSnapshot().context.schema.styles[0].name || 'normal',
|
|
28
|
-
...(options.listItem ? {listItem: options.listItem} : {}),
|
|
29
|
-
...(options.level ? {level: options.level} : {}),
|
|
30
|
-
markDefs: [],
|
|
31
|
-
children: [
|
|
32
|
-
{
|
|
33
|
-
_type: 'span',
|
|
34
|
-
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
35
|
-
text: '',
|
|
36
|
-
marks: options.decorators.filter((decorator) =>
|
|
37
|
-
editorActor
|
|
38
|
-
.getSnapshot()
|
|
39
|
-
.context.schema.decorators.find(
|
|
40
|
-
({name}) => name === decorator,
|
|
41
|
-
),
|
|
42
|
-
),
|
|
43
|
-
},
|
|
44
|
-
],
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
{schemaTypes: editorActor.getSnapshot().context.schema},
|
|
48
|
-
)
|
|
49
|
-
}
|
|
50
|
-
return editor
|
|
51
|
-
}
|
|
52
|
-
}
|