@portabletext/editor 3.3.0 → 3.3.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/_chunks-dts/index.d.ts +1705 -69
- package/lib/_chunks-es/use-editor.js +8 -4
- package/lib/_chunks-es/use-editor.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +9047 -511
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.ts +1 -1
- package/package.json +4 -4
- package/src/behaviors/behavior.perform-event.ts +1 -1
- package/src/editor/PortableTextEditor.tsx +3 -1
- package/src/editor/create-editor.ts +2 -1
- package/src/editor/create-slate-editor.tsx +1 -1
- package/src/editor/editor-dom.ts +1 -1
- package/src/editor/editor-machine.ts +1 -1
- package/src/editor/editor-selector.ts +1 -1
- package/src/editor/editor-snapshot.ts +2 -1
- package/src/editor/mutation-machine.ts +1 -1
- package/src/editor/plugins/createWithEditableAPI.ts +3 -4
- package/src/editor/plugins/createWithHotKeys.ts +1 -1
- package/src/editor/plugins/createWithObjectKeys.ts +1 -1
- package/src/editor/plugins/createWithPatches.ts +5 -3
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +1 -1
- package/src/editor/plugins/createWithSchemaTypes.ts +1 -1
- package/src/editor/plugins/slate-plugin.update-selection.ts +1 -1
- package/src/editor/plugins/slate-plugin.update-value.ts +1 -1
- package/src/editor/plugins/with-plugins.ts +1 -1
- package/src/editor/range-decorations-machine.ts +2 -1
- package/src/editor/sync-machine.ts +10 -7
- package/src/editor/validate-selection-machine.ts +1 -1
- package/src/history/slate-plugin.history.ts +1 -1
- package/src/history/transform-operation.ts +1 -1
- package/src/internal-utils/apply-operation-to-portable-text.ts +10 -1
- package/src/internal-utils/applyPatch.ts +1 -1
- package/src/internal-utils/event-position.ts +45 -5
- package/src/internal-utils/global-scope.ts +12 -4
- package/src/internal-utils/sibling-utils.ts +1 -1
- package/src/internal-utils/slate-utils.test.tsx +1 -1
- package/src/internal-utils/slate-utils.ts +2 -1
- package/src/operations/behavior.operation.delete.ts +1 -1
- package/src/operations/behavior.operation.insert.block.ts +2 -1
- package/src/operations/behavior.operations.ts +1 -1
- package/src/plugins/plugin.internal.slate-editor-ref.tsx +1 -1
- package/src/priority/priority.sort.ts +3 -1
- package/src/types/editor.ts +1 -51
- package/src/types/slate-editor.ts +50 -0
- package/src/types/slate.ts +1 -1
package/lib/plugins/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.2",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -68,9 +68,6 @@
|
|
|
68
68
|
"lodash": "^4.17.21",
|
|
69
69
|
"lodash.startcase": "^4.4.0",
|
|
70
70
|
"react-compiler-runtime": "1.0.0",
|
|
71
|
-
"slate": "^0.120.0",
|
|
72
|
-
"slate-dom": "^0.119.0",
|
|
73
|
-
"slate-react": "^0.120.0",
|
|
74
71
|
"xstate": "^5.24.0",
|
|
75
72
|
"@portabletext/block-tools": "^4.1.7",
|
|
76
73
|
"@portabletext/keyboard-shortcuts": "^2.1.0",
|
|
@@ -101,6 +98,9 @@
|
|
|
101
98
|
"react": "^19.2.1",
|
|
102
99
|
"react-dom": "^19.2.1",
|
|
103
100
|
"rxjs": "^7.8.2",
|
|
101
|
+
"slate": "^0.120.0",
|
|
102
|
+
"slate-dom": "^0.119.0",
|
|
103
|
+
"slate-react": "^0.120.0",
|
|
104
104
|
"typescript": "5.9.3",
|
|
105
105
|
"typescript-eslint": "^8.48.0",
|
|
106
106
|
"vite": "^7.1.12",
|
|
@@ -6,7 +6,7 @@ import {withoutNormalizingConditional} from '../editor/without-normalizing-condi
|
|
|
6
6
|
import {clearUndoStepId, createUndoStepId} from '../history/undo-step'
|
|
7
7
|
import {debugWithName} from '../internal-utils/debug'
|
|
8
8
|
import {performOperation} from '../operations/behavior.operations'
|
|
9
|
-
import type {PortableTextSlateEditor} from '../types/editor'
|
|
9
|
+
import type {PortableTextSlateEditor} from '../types/slate-editor'
|
|
10
10
|
import {abstractBehaviors} from './behavior.abstract'
|
|
11
11
|
import type {BehaviorAction} from './behavior.types.action'
|
|
12
12
|
import type {Behavior} from './behavior.types.behavior'
|
|
@@ -599,7 +599,9 @@ export class PortableTextEditor extends Component<
|
|
|
599
599
|
}
|
|
600
600
|
|
|
601
601
|
static isObjectPath = (_editor: PortableTextEditor, path: Path): boolean => {
|
|
602
|
-
if (!path || !Array.isArray(path))
|
|
602
|
+
if (!path || !Array.isArray(path)) {
|
|
603
|
+
return false
|
|
604
|
+
}
|
|
603
605
|
const isChildObjectEditPath = path.length > 3 && path[1] === 'children'
|
|
604
606
|
const isBlockObjectEditPath = path.length > 1 && path[1] !== 'children'
|
|
605
607
|
return isBlockObjectEditPath || isChildObjectEditPath
|
|
@@ -11,7 +11,8 @@ import {debugWithName} from '../internal-utils/debug'
|
|
|
11
11
|
import {compileType} from '../internal-utils/schema'
|
|
12
12
|
import {corePriority} from '../priority/priority.core'
|
|
13
13
|
import {createEditorPriority} from '../priority/priority.types'
|
|
14
|
-
import type {EditableAPI
|
|
14
|
+
import type {EditableAPI} from '../types/editor'
|
|
15
|
+
import type {PortableTextSlateEditor} from '../types/slate-editor'
|
|
15
16
|
import {defaultKeyGenerator} from '../utils/key-generator'
|
|
16
17
|
import {createSlateEditor, type SlateEditor} from './create-slate-editor'
|
|
17
18
|
import {createEditorDom} from './editor-dom'
|
|
@@ -3,7 +3,7 @@ import {withReact} from 'slate-react'
|
|
|
3
3
|
import {buildIndexMaps} from '../internal-utils/build-index-maps'
|
|
4
4
|
import {createPlaceholderBlock} from '../internal-utils/create-placeholder-block'
|
|
5
5
|
import {debugWithName} from '../internal-utils/debug'
|
|
6
|
-
import type {PortableTextSlateEditor} from '../types/editor'
|
|
6
|
+
import type {PortableTextSlateEditor} from '../types/slate-editor'
|
|
7
7
|
import type {EditorActor} from './editor-machine'
|
|
8
8
|
import {withPlugins} from './plugins/with-plugins'
|
|
9
9
|
import type {RelayActor} from './relay-machine'
|
package/src/editor/editor-dom.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type {BehaviorEvent} from '../behaviors/behavior.types.event'
|
|
|
4
4
|
import {toSlateRange} from '../internal-utils/to-slate-range'
|
|
5
5
|
import {getSelectionEndBlock, getSelectionStartBlock} from '../selectors'
|
|
6
6
|
import type {PickFromUnion} from '../type-utils'
|
|
7
|
-
import type {PortableTextSlateEditor} from '../types/editor'
|
|
7
|
+
import type {PortableTextSlateEditor} from '../types/slate-editor'
|
|
8
8
|
import type {EditorSnapshot} from './editor-snapshot'
|
|
9
9
|
|
|
10
10
|
export type EditorDom = {
|
|
@@ -25,8 +25,8 @@ import type {NamespaceEvent, OmitFromUnion} from '../type-utils'
|
|
|
25
25
|
import type {
|
|
26
26
|
EditorSelection,
|
|
27
27
|
PortableTextMemberSchemaTypes,
|
|
28
|
-
PortableTextSlateEditor,
|
|
29
28
|
} from '../types/editor'
|
|
29
|
+
import type {PortableTextSlateEditor} from '../types/slate-editor'
|
|
30
30
|
import type {EditorSchema} from './editor-schema'
|
|
31
31
|
import {createEditorSnapshot} from './editor-snapshot'
|
|
32
32
|
import type {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {useSelector} from '@xstate/react'
|
|
2
2
|
import type {Editor} from '../editor'
|
|
3
3
|
import {slateRangeToSelection} from '../internal-utils/slate-utils'
|
|
4
|
-
import type {PortableTextSlateEditor} from '../types/editor'
|
|
4
|
+
import type {PortableTextSlateEditor} from '../types/slate-editor'
|
|
5
5
|
import type {InternalEditor} from './create-editor'
|
|
6
6
|
import type {EditorActor} from './editor-machine'
|
|
7
7
|
import type {EditorSnapshot} from './editor-snapshot'
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type {PortableTextBlock} from '@sanity/types'
|
|
2
2
|
import type {Converter} from '../converters/converter.types'
|
|
3
3
|
import {slateRangeToSelection} from '../internal-utils/slate-utils'
|
|
4
|
-
import type {EditorSelection
|
|
4
|
+
import type {EditorSelection} from '../types/editor'
|
|
5
|
+
import type {PortableTextSlateEditor} from '../types/slate-editor'
|
|
5
6
|
import type {EditorSchema} from './editor-schema'
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
type AnyEventObject,
|
|
16
16
|
} from 'xstate'
|
|
17
17
|
import {debugWithName} from '../internal-utils/debug'
|
|
18
|
-
import type {PortableTextSlateEditor} from '../types/editor'
|
|
18
|
+
import type {PortableTextSlateEditor} from '../types/slate-editor'
|
|
19
19
|
import type {EditorSchema} from './editor-schema'
|
|
20
20
|
import type {PatchEvent} from './relay-machine'
|
|
21
21
|
|
|
@@ -6,7 +6,6 @@ import type {
|
|
|
6
6
|
PortableTextObject,
|
|
7
7
|
} from '@sanity/types'
|
|
8
8
|
import {Editor, Range, Text, Transforms} from 'slate'
|
|
9
|
-
import type {DOMNode} from 'slate-dom'
|
|
10
9
|
import {ReactEditor} from 'slate-react'
|
|
11
10
|
import {
|
|
12
11
|
isListItemActive,
|
|
@@ -24,8 +23,8 @@ import type {
|
|
|
24
23
|
EditableAPI,
|
|
25
24
|
EditableAPIDeleteOptions,
|
|
26
25
|
EditorSelection,
|
|
27
|
-
PortableTextSlateEditor,
|
|
28
26
|
} from '../../types/editor'
|
|
27
|
+
import type {PortableTextSlateEditor} from '../../types/slate-editor'
|
|
29
28
|
import {
|
|
30
29
|
getBlockKeyFromSelectionPoint,
|
|
31
30
|
getChildKeyFromSelectionPoint,
|
|
@@ -290,8 +289,8 @@ export function createEditableAPI(
|
|
|
290
289
|
},
|
|
291
290
|
findDOMNode: (
|
|
292
291
|
element: PortableTextBlock | PortableTextChild,
|
|
293
|
-
):
|
|
294
|
-
let node:
|
|
292
|
+
): Node | undefined => {
|
|
293
|
+
let node: Node | undefined
|
|
295
294
|
try {
|
|
296
295
|
const [item] = Array.from(
|
|
297
296
|
Editor.nodes(editor, {
|
|
@@ -2,8 +2,8 @@ import type {KeyboardEvent} from 'react'
|
|
|
2
2
|
import type {ReactEditor} from 'slate-react'
|
|
3
3
|
import {debugWithName} from '../../internal-utils/debug'
|
|
4
4
|
import {isHotkey} from '../../internal-utils/is-hotkey'
|
|
5
|
-
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
6
5
|
import type {HotkeyOptions} from '../../types/options'
|
|
6
|
+
import type {PortableTextSlateEditor} from '../../types/slate-editor'
|
|
7
7
|
import type {EditorActor} from '../editor-machine'
|
|
8
8
|
import type {PortableTextEditor} from '../PortableTextEditor'
|
|
9
9
|
|
|
@@ -3,7 +3,7 @@ import {isEqual} from 'lodash'
|
|
|
3
3
|
import {Editor, Element, Node, Path, Transforms} from 'slate'
|
|
4
4
|
import {isRedoing} from '../../history/slate-plugin.redoing'
|
|
5
5
|
import {isUndoing} from '../../history/slate-plugin.undoing'
|
|
6
|
-
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
6
|
+
import type {PortableTextSlateEditor} from '../../types/slate-editor'
|
|
7
7
|
import type {EditorActor} from '../editor-machine'
|
|
8
8
|
import {withNormalizeNode} from '../with-normalizing-node'
|
|
9
9
|
import {isChangingRemotely} from '../withChanges'
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
splitNodePatch,
|
|
17
17
|
} from '../../internal-utils/operation-to-patches'
|
|
18
18
|
import {isEqualToEmptyEditor} from '../../internal-utils/values'
|
|
19
|
-
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
19
|
+
import type {PortableTextSlateEditor} from '../../types/slate-editor'
|
|
20
20
|
import type {EditorActor} from '../editor-machine'
|
|
21
21
|
import type {RelayActor} from '../relay-machine'
|
|
22
22
|
import {IS_PROCESSING_REMOTE_CHANGES} from '../weakMaps'
|
|
@@ -64,8 +64,9 @@ export function createWithPatches({
|
|
|
64
64
|
withoutPatching(editor, () => {
|
|
65
65
|
pluginWithoutHistory(editor, () => {
|
|
66
66
|
for (const patch of patches) {
|
|
67
|
-
if (debug.enabled)
|
|
67
|
+
if (debug.enabled) {
|
|
68
68
|
debug(`Handling remote patch ${JSON.stringify(patch)}`)
|
|
69
|
+
}
|
|
69
70
|
|
|
70
71
|
try {
|
|
71
72
|
changed = applyPatch(editor, patch)
|
|
@@ -125,11 +126,12 @@ export function createWithPatches({
|
|
|
125
126
|
)
|
|
126
127
|
|
|
127
128
|
if (!isPatching(editor)) {
|
|
128
|
-
if (debugVerbose && debug.enabled)
|
|
129
|
+
if (debugVerbose && debug.enabled) {
|
|
129
130
|
debug(
|
|
130
131
|
`Editor is not producing patch for operation ${operation.type}`,
|
|
131
132
|
operation,
|
|
132
133
|
)
|
|
134
|
+
}
|
|
133
135
|
return editor
|
|
134
136
|
}
|
|
135
137
|
|
|
@@ -15,7 +15,7 @@ import {debugWithName} from '../../internal-utils/debug'
|
|
|
15
15
|
import {getNextSpan, getPreviousSpan} from '../../internal-utils/sibling-utils'
|
|
16
16
|
import type {BehaviorOperationImplementation} from '../../operations/behavior.operations'
|
|
17
17
|
import {getActiveDecorators} from '../../selectors/selector.get-active-decorators'
|
|
18
|
-
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
18
|
+
import type {PortableTextSlateEditor} from '../../types/slate-editor'
|
|
19
19
|
import type {EditorActor} from '../editor-machine'
|
|
20
20
|
import {getEditorSnapshot} from '../editor-selector'
|
|
21
21
|
import {withNormalizeNode} from '../with-normalizing-node'
|
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
} from '@sanity/types'
|
|
7
7
|
import {Editor, Transforms, type Element} from 'slate'
|
|
8
8
|
import {debugWithName} from '../../internal-utils/debug'
|
|
9
|
-
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
9
|
+
import type {PortableTextSlateEditor} from '../../types/slate-editor'
|
|
10
10
|
import {isListBlock} from '../../utils/parse-blocks'
|
|
11
11
|
import type {EditorActor} from '../editor-machine'
|
|
12
12
|
import {withNormalizeNode} from '../with-normalizing-node'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {slateRangeToSelection} from '../../internal-utils/slate-utils'
|
|
2
|
-
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
2
|
+
import type {PortableTextSlateEditor} from '../../types/slate-editor'
|
|
3
3
|
import type {EditorActor} from '../editor-machine'
|
|
4
4
|
import {SLATE_TO_PORTABLE_TEXT_RANGE} from '../weakMaps'
|
|
5
5
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {applyOperationToPortableText} from '../../internal-utils/apply-operation-to-portable-text'
|
|
2
2
|
import {buildIndexMaps} from '../../internal-utils/build-index-maps'
|
|
3
|
-
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
3
|
+
import type {PortableTextSlateEditor} from '../../types/slate-editor'
|
|
4
4
|
import type {EditorContext} from '../editor-snapshot'
|
|
5
5
|
|
|
6
6
|
export function pluginUpdateValue(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {BaseOperation, Editor, Node, NodeEntry} from 'slate'
|
|
2
2
|
import {pluginHistory} from '../../history/slate-plugin.history'
|
|
3
|
-
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
3
|
+
import type {PortableTextSlateEditor} from '../../types/slate-editor'
|
|
4
4
|
import type {EditorActor} from '../editor-machine'
|
|
5
5
|
import type {RelayActor} from '../relay-machine'
|
|
6
6
|
import {createWithEventListeners} from './create-with-event-listeners'
|
|
@@ -18,7 +18,8 @@ import {
|
|
|
18
18
|
import {moveRangeByOperation} from '../internal-utils/move-range-by-operation'
|
|
19
19
|
import {slateRangeToSelection} from '../internal-utils/slate-utils'
|
|
20
20
|
import {toSlateRange} from '../internal-utils/to-slate-range'
|
|
21
|
-
import type {
|
|
21
|
+
import type {RangeDecoration} from '../types/editor'
|
|
22
|
+
import type {PortableTextSlateEditor} from '../types/slate-editor'
|
|
22
23
|
import {isEmptyTextBlock} from '../utils'
|
|
23
24
|
import type {EditorSchema} from './editor-schema'
|
|
24
25
|
|
|
@@ -21,10 +21,8 @@ import {debugWithName} from '../internal-utils/debug'
|
|
|
21
21
|
import {validateValue} from '../internal-utils/validateValue'
|
|
22
22
|
import {toSlateBlock, VOID_CHILD_KEY} from '../internal-utils/values'
|
|
23
23
|
import type {PickFromUnion} from '../type-utils'
|
|
24
|
-
import type {
|
|
25
|
-
|
|
26
|
-
PortableTextSlateEditor,
|
|
27
|
-
} from '../types/editor'
|
|
24
|
+
import type {InvalidValueResolution} from '../types/editor'
|
|
25
|
+
import type {PortableTextSlateEditor} from '../types/slate-editor'
|
|
28
26
|
import type {EditorSchema} from './editor-schema'
|
|
29
27
|
import {isChangingRemotely, withRemoteChanges} from './withChanges'
|
|
30
28
|
import {withoutPatching} from './withoutPatching'
|
|
@@ -663,8 +661,9 @@ function syncBlock({
|
|
|
663
661
|
context.keyGenerator,
|
|
664
662
|
)
|
|
665
663
|
|
|
666
|
-
if (debug.enabled)
|
|
664
|
+
if (debug.enabled) {
|
|
667
665
|
debug('Validating and inserting new block in the end of the value', block)
|
|
666
|
+
}
|
|
668
667
|
|
|
669
668
|
if (validation.valid || validation.resolution?.autoResolve) {
|
|
670
669
|
const slateBlock = toSlateBlock(block, {
|
|
@@ -740,7 +739,9 @@ function syncBlock({
|
|
|
740
739
|
|
|
741
740
|
if (validation.valid || validation.resolution?.autoResolve) {
|
|
742
741
|
if (oldBlock._key === block._key) {
|
|
743
|
-
if (debug.enabled)
|
|
742
|
+
if (debug.enabled) {
|
|
743
|
+
debug('Updating block', oldBlock, block)
|
|
744
|
+
}
|
|
744
745
|
|
|
745
746
|
Editor.withoutNormalizing(slateEditor, () => {
|
|
746
747
|
withRemoteChanges(slateEditor, () => {
|
|
@@ -756,7 +757,9 @@ function syncBlock({
|
|
|
756
757
|
})
|
|
757
758
|
})
|
|
758
759
|
} else {
|
|
759
|
-
if (debug.enabled)
|
|
760
|
+
if (debug.enabled) {
|
|
761
|
+
debug('Replacing block', oldBlock, block)
|
|
762
|
+
}
|
|
760
763
|
|
|
761
764
|
Editor.withoutNormalizing(slateEditor, () => {
|
|
762
765
|
withRemoteChanges(slateEditor, () => {
|
|
@@ -2,7 +2,7 @@ import {Editor, Transforms} from 'slate'
|
|
|
2
2
|
import {ReactEditor} from 'slate-react'
|
|
3
3
|
import {setup} from 'xstate'
|
|
4
4
|
import {debugWithName} from '../internal-utils/debug'
|
|
5
|
-
import type {PortableTextSlateEditor} from '../types/editor'
|
|
5
|
+
import type {PortableTextSlateEditor} from '../types/slate-editor'
|
|
6
6
|
|
|
7
7
|
const debug = debugWithName('validate selection machine')
|
|
8
8
|
|
|
@@ -8,7 +8,7 @@ import type {Operation} from 'slate'
|
|
|
8
8
|
import type {EditorActor} from '../editor/editor-machine'
|
|
9
9
|
import {isChangingRemotely} from '../editor/withChanges'
|
|
10
10
|
import {debugWithName} from '../internal-utils/debug'
|
|
11
|
-
import type {PortableTextSlateEditor} from '../types/editor'
|
|
11
|
+
import type {PortableTextSlateEditor} from '../types/slate-editor'
|
|
12
12
|
import {getRemotePatches} from './remote-patches'
|
|
13
13
|
import {isRedoing} from './slate-plugin.redoing'
|
|
14
14
|
import {isUndoing} from './slate-plugin.undoing'
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
import {isEqual} from 'lodash'
|
|
10
10
|
import type {Descendant, Operation} from 'slate'
|
|
11
11
|
import {debugWithName} from '../internal-utils/debug'
|
|
12
|
-
import type {PortableTextSlateEditor} from '../types/editor'
|
|
12
|
+
import type {PortableTextSlateEditor} from '../types/slate-editor'
|
|
13
13
|
|
|
14
14
|
const debug = debugWithName('transformOperation')
|
|
15
15
|
const debugVerbose = debug.enabled && false
|
|
@@ -145,7 +145,9 @@ function applyOperationToPortableTextImmutable(
|
|
|
145
145
|
|
|
146
146
|
case 'insert_text': {
|
|
147
147
|
const {path, offset, text} = operation
|
|
148
|
-
if (text.length === 0)
|
|
148
|
+
if (text.length === 0) {
|
|
149
|
+
return root
|
|
150
|
+
}
|
|
149
151
|
|
|
150
152
|
const span = getSpan(context, root, path)
|
|
151
153
|
if (!span) {
|
|
@@ -166,6 +168,13 @@ function applyOperationToPortableTextImmutable(
|
|
|
166
168
|
|
|
167
169
|
case 'merge_node': {
|
|
168
170
|
const {path} = operation
|
|
171
|
+
|
|
172
|
+
const lastPathIndex = path.at(-1)
|
|
173
|
+
|
|
174
|
+
if (lastPathIndex === 0) {
|
|
175
|
+
return root
|
|
176
|
+
}
|
|
177
|
+
|
|
169
178
|
const node = getNode(context, root, path)
|
|
170
179
|
const prevPath = Path.previous(path)
|
|
171
180
|
const prev = getNode(context, root, prevPath)
|
|
@@ -19,7 +19,7 @@ import type {Path, PortableTextBlock, PortableTextChild} from '@sanity/types'
|
|
|
19
19
|
import {Editor, Element, Node, Text, Transforms, type Descendant} from 'slate'
|
|
20
20
|
import type {EditorContext} from '../editor/editor-snapshot'
|
|
21
21
|
import {KEY_TO_SLATE_ELEMENT} from '../editor/weakMaps'
|
|
22
|
-
import type {PortableTextSlateEditor} from '../types/editor'
|
|
22
|
+
import type {PortableTextSlateEditor} from '../types/slate-editor'
|
|
23
23
|
import {isKeyedSegment} from '../utils/util.is-keyed-segment'
|
|
24
24
|
import {isEqualToEmptyEditor, toSlateBlock} from './values'
|
|
25
25
|
|
|
@@ -2,7 +2,8 @@ import {Editor, type BaseRange, type Node} from 'slate'
|
|
|
2
2
|
import {DOMEditor, isDOMNode} from 'slate-dom'
|
|
3
3
|
import type {EditorActor} from '../editor/editor-machine'
|
|
4
4
|
import type {EditorSchema} from '../editor/editor-schema'
|
|
5
|
-
import type {EditorSelection
|
|
5
|
+
import type {EditorSelection} from '../types/editor'
|
|
6
|
+
import type {PortableTextSlateEditor} from '../types/slate-editor'
|
|
6
7
|
import {getBlockEndPoint} from '../utils/util.get-block-end-point'
|
|
7
8
|
import {getBlockStartPoint} from '../utils/util.get-block-start-point'
|
|
8
9
|
import {isSelectionCollapsed} from '../utils/util.is-selection-collapsed'
|
|
@@ -148,7 +149,13 @@ export function getEventNode({
|
|
|
148
149
|
return undefined
|
|
149
150
|
}
|
|
150
151
|
|
|
151
|
-
|
|
152
|
+
let node: Node | undefined
|
|
153
|
+
|
|
154
|
+
try {
|
|
155
|
+
node = DOMEditor.toSlateNode(slateEditor, event.target)
|
|
156
|
+
} catch (error) {
|
|
157
|
+
console.error(error)
|
|
158
|
+
}
|
|
152
159
|
|
|
153
160
|
return node
|
|
154
161
|
}
|
|
@@ -168,7 +175,18 @@ function getEventPositionBlock({
|
|
|
168
175
|
return undefined
|
|
169
176
|
}
|
|
170
177
|
|
|
171
|
-
|
|
178
|
+
let firstBlockElement: HTMLElement | undefined
|
|
179
|
+
|
|
180
|
+
try {
|
|
181
|
+
firstBlockElement = DOMEditor.toDOMNode(slateEditor, firstBlock)
|
|
182
|
+
} catch (error) {
|
|
183
|
+
console.error(error)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (!firstBlockElement) {
|
|
187
|
+
return undefined
|
|
188
|
+
}
|
|
189
|
+
|
|
172
190
|
const firstBlockRect = firstBlockElement.getBoundingClientRect()
|
|
173
191
|
|
|
174
192
|
if (event.pageY < firstBlockRect.top) {
|
|
@@ -181,14 +199,36 @@ function getEventPositionBlock({
|
|
|
181
199
|
return undefined
|
|
182
200
|
}
|
|
183
201
|
|
|
184
|
-
|
|
202
|
+
let lastBlockElement: HTMLElement | undefined
|
|
203
|
+
|
|
204
|
+
try {
|
|
205
|
+
lastBlockElement = DOMEditor.toDOMNode(slateEditor, lastBlock)
|
|
206
|
+
} catch (error) {
|
|
207
|
+
console.error(error)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (!lastBlockElement) {
|
|
211
|
+
return undefined
|
|
212
|
+
}
|
|
213
|
+
|
|
185
214
|
const lastBlockRef = lastBlockElement.getBoundingClientRect()
|
|
186
215
|
|
|
187
216
|
if (event.pageY > lastBlockRef.bottom) {
|
|
188
217
|
return 'end'
|
|
189
218
|
}
|
|
190
219
|
|
|
191
|
-
|
|
220
|
+
let element: HTMLElement | undefined
|
|
221
|
+
|
|
222
|
+
try {
|
|
223
|
+
element = DOMEditor.toDOMNode(slateEditor, node)
|
|
224
|
+
} catch (error) {
|
|
225
|
+
console.error(error)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (!element) {
|
|
229
|
+
return undefined
|
|
230
|
+
}
|
|
231
|
+
|
|
192
232
|
const elementRect = element.getBoundingClientRect()
|
|
193
233
|
const top = elementRect.top
|
|
194
234
|
const height = elementRect.height
|
|
@@ -8,10 +8,18 @@
|
|
|
8
8
|
* - The `global` variable is the global scope in Node.js
|
|
9
9
|
*/
|
|
10
10
|
function getGlobalScope() {
|
|
11
|
-
if (typeof globalThis !== 'undefined')
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (typeof
|
|
11
|
+
if (typeof globalThis !== 'undefined') {
|
|
12
|
+
return globalThis
|
|
13
|
+
}
|
|
14
|
+
if (typeof window !== 'undefined') {
|
|
15
|
+
return window
|
|
16
|
+
}
|
|
17
|
+
if (typeof self !== 'undefined') {
|
|
18
|
+
return self
|
|
19
|
+
}
|
|
20
|
+
if (typeof global !== 'undefined') {
|
|
21
|
+
return global
|
|
22
|
+
}
|
|
15
23
|
|
|
16
24
|
throw new Error('@portabletext/editor: could not locate global scope')
|
|
17
25
|
}
|
|
@@ -4,7 +4,7 @@ import React from 'react'
|
|
|
4
4
|
import {describe, expect, test} from 'vitest'
|
|
5
5
|
import {InternalSlateEditorRefPlugin} from '../plugins/plugin.internal.slate-editor-ref'
|
|
6
6
|
import {createTestEditor} from '../test/vitest'
|
|
7
|
-
import type {PortableTextSlateEditor} from '../types/editor'
|
|
7
|
+
import type {PortableTextSlateEditor} from '../types/slate-editor'
|
|
8
8
|
import {getFocusSpan} from './slate-utils'
|
|
9
9
|
|
|
10
10
|
describe(getFocusSpan.name, () => {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type {PortableTextSpan} from '@sanity/types'
|
|
2
2
|
import {Editor, Element, Node, Range, type Path, type Point} from 'slate'
|
|
3
3
|
import type {EditorSchema} from '../editor/editor-schema'
|
|
4
|
-
import type {EditorSelection
|
|
4
|
+
import type {EditorSelection} from '../types/editor'
|
|
5
|
+
import type {PortableTextSlateEditor} from '../types/slate-editor'
|
|
5
6
|
import {fromSlateBlock} from './values'
|
|
6
7
|
|
|
7
8
|
export function getBlockPath({
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
import {DOMEditor} from 'slate-dom'
|
|
13
13
|
import {toSlateRange} from '../internal-utils/to-slate-range'
|
|
14
14
|
import {VOID_CHILD_KEY} from '../internal-utils/values'
|
|
15
|
-
import type {PortableTextSlateEditor} from '../types/editor'
|
|
15
|
+
import type {PortableTextSlateEditor} from '../types/slate-editor'
|
|
16
16
|
import type {BehaviorOperationImplementation} from './behavior.operations'
|
|
17
17
|
|
|
18
18
|
export const deleteOperationImplementation: BehaviorOperationImplementation<
|
|
@@ -14,7 +14,8 @@ import {createPlaceholderBlock} from '../internal-utils/create-placeholder-block
|
|
|
14
14
|
import {getFocusBlock, getFocusChild} from '../internal-utils/slate-utils'
|
|
15
15
|
import {toSlateRange} from '../internal-utils/to-slate-range'
|
|
16
16
|
import {toSlateBlock} from '../internal-utils/values'
|
|
17
|
-
import type {EditorSelection
|
|
17
|
+
import type {EditorSelection} from '../types/editor'
|
|
18
|
+
import type {PortableTextSlateEditor} from '../types/slate-editor'
|
|
18
19
|
import {parseBlock} from '../utils/parse-blocks'
|
|
19
20
|
import {isEmptyTextBlock} from '../utils/util.is-empty-text-block'
|
|
20
21
|
import type {
|
|
@@ -8,7 +8,7 @@ import {removeDecoratorOperationImplementation} from '../editor/plugins/createWi
|
|
|
8
8
|
import {historyRedoOperationImplementation} from '../history/behavior.operation.history.redo'
|
|
9
9
|
import {historyUndoOperationImplementation} from '../history/behavior.operation.history.undo'
|
|
10
10
|
import type {OmitFromUnion, PickFromUnion} from '../type-utils'
|
|
11
|
-
import type {PortableTextSlateEditor} from '../types/editor'
|
|
11
|
+
import type {PortableTextSlateEditor} from '../types/slate-editor'
|
|
12
12
|
import {addAnnotationOperationImplementation} from './behavior.operation.annotation.add'
|
|
13
13
|
import {removeAnnotationOperationImplementation} from './behavior.operation.annotation.remove'
|
|
14
14
|
import {blockSetOperationImplementation} from './behavior.operation.block.set'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import {useSlateStatic} from 'slate-react'
|
|
3
|
-
import type {PortableTextSlateEditor} from '../types/editor'
|
|
3
|
+
import type {PortableTextSlateEditor} from '../types/slate-editor'
|
|
4
4
|
|
|
5
5
|
export const InternalSlateEditorRefPlugin =
|
|
6
6
|
React.forwardRef<PortableTextSlateEditor | null>((_, ref) => {
|
|
@@ -47,7 +47,9 @@ export function sortByPriority<
|
|
|
47
47
|
|
|
48
48
|
// Helper function to add an edge to the graph
|
|
49
49
|
function addEdge(fromId: string, toId: string) {
|
|
50
|
-
if (!graph.has(fromId) || !graph.has(toId))
|
|
50
|
+
if (!graph.has(fromId) || !graph.has(toId)) {
|
|
51
|
+
return
|
|
52
|
+
}
|
|
51
53
|
graph.get(fromId)?.add(toId)
|
|
52
54
|
inDegree.set(toId, (inDegree.get(toId) ?? 0) + 1)
|
|
53
55
|
}
|