@portabletext/editor 3.3.1 → 3.3.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-dts/index.d.ts +1710 -68
- package/lib/index.d.ts +1 -1
- package/lib/index.js +9012 -510
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.ts +1 -1
- package/package.json +14 -16
- package/src/behaviors/behavior.perform-event.ts +1 -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 +1 -1
- 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 +2 -4
- 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/index.ts +9 -0
- package/src/internal-utils/apply-operation-to-portable-text.ts +7 -0
- package/src/internal-utils/applyPatch.ts +1 -1
- package/src/internal-utils/event-position.ts +2 -1
- 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/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.3",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -63,26 +63,23 @@
|
|
|
63
63
|
],
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@portabletext/to-html": "^4.0.1",
|
|
66
|
+
"@sanity/schema": "^4.20.3",
|
|
67
|
+
"@sanity/types": "^4.20.3",
|
|
66
68
|
"@xstate/react": "^6.0.0",
|
|
67
69
|
"debug": "^4.4.3",
|
|
68
70
|
"lodash": "^4.17.21",
|
|
69
71
|
"lodash.startcase": "^4.4.0",
|
|
70
|
-
"react-compiler-runtime": "1.0.0",
|
|
71
|
-
"slate": "^0.120.0",
|
|
72
|
-
"slate-dom": "^0.119.0",
|
|
73
|
-
"slate-react": "^0.120.0",
|
|
72
|
+
"react-compiler-runtime": "^1.0.0",
|
|
74
73
|
"xstate": "^5.24.0",
|
|
75
|
-
"@portabletext/block-tools": "^4.1.
|
|
76
|
-
"@portabletext/markdown": "^1.0.3",
|
|
74
|
+
"@portabletext/block-tools": "^4.1.8",
|
|
77
75
|
"@portabletext/keyboard-shortcuts": "^2.1.0",
|
|
76
|
+
"@portabletext/markdown": "^1.0.3",
|
|
78
77
|
"@portabletext/patches": "^2.0.0",
|
|
79
78
|
"@portabletext/schema": "^2.0.0"
|
|
80
79
|
},
|
|
81
80
|
"devDependencies": {
|
|
82
81
|
"@sanity/diff-match-patch": "^3.2.0",
|
|
83
82
|
"@sanity/pkg-utils": "^10.1.1",
|
|
84
|
-
"@sanity/schema": "^4.20.3",
|
|
85
|
-
"@sanity/types": "^4.20.3",
|
|
86
83
|
"@types/debug": "^4.1.12",
|
|
87
84
|
"@types/lodash": "^4.17.20",
|
|
88
85
|
"@types/lodash.startcase": "^4.4.9",
|
|
@@ -93,27 +90,28 @@
|
|
|
93
90
|
"@vitest/browser": "^4.0.14",
|
|
94
91
|
"@vitest/browser-playwright": "^4.0.14",
|
|
95
92
|
"@vitest/coverage-istanbul": "^4.0.14",
|
|
96
|
-
"babel-plugin-react-compiler": "1.0.0",
|
|
93
|
+
"babel-plugin-react-compiler": "^1.0.0",
|
|
97
94
|
"eslint": "^9.39.1",
|
|
98
95
|
"eslint-formatter-gha": "^1.6.0",
|
|
99
|
-
"eslint-plugin-react-hooks": "7.0.1",
|
|
96
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
100
97
|
"jsdom": "^27.0.0",
|
|
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",
|
|
107
107
|
"vitest": "^4.0.14",
|
|
108
108
|
"vitest-browser-react": "^2.0.2",
|
|
109
|
-
"@portabletext/sanity-bridge": "1.2.
|
|
110
|
-
"@portabletext/test": "^1.0.
|
|
109
|
+
"@portabletext/sanity-bridge": "1.2.11",
|
|
110
|
+
"@portabletext/test": "^1.0.1",
|
|
111
111
|
"racejar": "2.0.0"
|
|
112
112
|
},
|
|
113
113
|
"peerDependencies": {
|
|
114
|
-
"@portabletext/sanity-bridge": "^1.2.
|
|
115
|
-
"@sanity/schema": "^4.20.3",
|
|
116
|
-
"@sanity/types": "^4.20.3",
|
|
114
|
+
"@portabletext/sanity-bridge": "^1.2.11",
|
|
117
115
|
"react": "^18.3 || ^19",
|
|
118
116
|
"rxjs": "^7.8.2"
|
|
119
117
|
},
|
|
@@ -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'
|
|
@@ -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'
|
|
@@ -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'
|
|
@@ -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
|
package/src/index.ts
CHANGED
|
@@ -96,3 +96,12 @@ export type {
|
|
|
96
96
|
} from './types/editor'
|
|
97
97
|
export type {HotkeyOptions} from './types/options'
|
|
98
98
|
export type {AnnotationPath, BlockPath, ChildPath} from './types/paths'
|
|
99
|
+
|
|
100
|
+
// Fixes an issue where slate aliased types from (https://github.com/ianstormtaylor/slate/blob/eae2474124949a4e2239568876663ce201357ac6/packages/slate-dom/src/utils/dom.ts#L5-L15)
|
|
101
|
+
// does not make it into the generated dts.
|
|
102
|
+
declare global {
|
|
103
|
+
type DOMNode = typeof globalThis.Node
|
|
104
|
+
type DOMRange = typeof globalThis.Range
|
|
105
|
+
type DOMSelection = typeof globalThis.Selection
|
|
106
|
+
type DOMStaticRange = typeof globalThis.StaticRange
|
|
107
|
+
}
|
|
@@ -168,6 +168,13 @@ function applyOperationToPortableTextImmutable(
|
|
|
168
168
|
|
|
169
169
|
case 'merge_node': {
|
|
170
170
|
const {path} = operation
|
|
171
|
+
|
|
172
|
+
const lastPathIndex = path.at(-1)
|
|
173
|
+
|
|
174
|
+
if (lastPathIndex === 0) {
|
|
175
|
+
return root
|
|
176
|
+
}
|
|
177
|
+
|
|
171
178
|
const node = getNode(context, root, path)
|
|
172
179
|
const prevPath = Path.previous(path)
|
|
173
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'
|
|
@@ -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) => {
|
package/src/types/editor.ts
CHANGED
|
@@ -8,9 +8,7 @@ import type {
|
|
|
8
8
|
Path,
|
|
9
9
|
PortableTextBlock,
|
|
10
10
|
PortableTextChild,
|
|
11
|
-
PortableTextListBlock,
|
|
12
11
|
PortableTextObject,
|
|
13
|
-
PortableTextSpan,
|
|
14
12
|
PortableTextTextBlock,
|
|
15
13
|
TypedObject,
|
|
16
14
|
} from '@sanity/types'
|
|
@@ -18,18 +16,13 @@ import type {
|
|
|
18
16
|
ClipboardEvent,
|
|
19
17
|
FocusEvent,
|
|
20
18
|
JSX,
|
|
21
|
-
KeyboardEvent,
|
|
22
19
|
PropsWithChildren,
|
|
23
20
|
ReactElement,
|
|
24
21
|
RefObject,
|
|
25
22
|
} from 'react'
|
|
26
23
|
import type {Observable, Subject} from 'rxjs'
|
|
27
|
-
import type {Descendant, Operation as SlateOperation} from 'slate'
|
|
28
|
-
import type {DOMNode} from 'slate-dom'
|
|
29
|
-
import type {ReactEditor} from 'slate-react'
|
|
30
24
|
import type {PortableTextEditableProps} from '../editor/Editable'
|
|
31
25
|
import type {PortableTextEditor} from '../editor/PortableTextEditor'
|
|
32
|
-
import type {DecoratedRange} from '../editor/range-decorations-machine'
|
|
33
26
|
import type {BlockPath} from './paths'
|
|
34
27
|
|
|
35
28
|
/** @beta */
|
|
@@ -73,7 +66,7 @@ export interface EditableAPI {
|
|
|
73
66
|
) => [PortableTextBlock | PortableTextChild | undefined, Path | undefined]
|
|
74
67
|
findDOMNode: (
|
|
75
68
|
element: PortableTextBlock | PortableTextChild,
|
|
76
|
-
) =>
|
|
69
|
+
) => Node | undefined
|
|
77
70
|
focus: () => void
|
|
78
71
|
focusBlock: () => PortableTextBlock | undefined
|
|
79
72
|
focusChild: () => PortableTextChild | undefined
|
|
@@ -111,16 +104,6 @@ export interface EditableAPI {
|
|
|
111
104
|
undo: () => void
|
|
112
105
|
}
|
|
113
106
|
|
|
114
|
-
type HistoryItem = {
|
|
115
|
-
operations: SlateOperation[]
|
|
116
|
-
timestamp: Date
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
interface History {
|
|
120
|
-
redos: HistoryItem[]
|
|
121
|
-
undos: HistoryItem[]
|
|
122
|
-
}
|
|
123
|
-
|
|
124
107
|
/** @public */
|
|
125
108
|
export type EditorSelectionPoint = {path: Path; offset: number}
|
|
126
109
|
/** @public */
|
|
@@ -130,39 +113,6 @@ export type EditorSelection = {
|
|
|
130
113
|
backward?: boolean
|
|
131
114
|
} | null
|
|
132
115
|
|
|
133
|
-
export interface PortableTextSlateEditor extends ReactEditor {
|
|
134
|
-
_key: 'editor'
|
|
135
|
-
_type: 'editor'
|
|
136
|
-
createPlaceholderBlock: () => Descendant
|
|
137
|
-
editable: EditableAPI
|
|
138
|
-
history: History
|
|
139
|
-
insertPortableTextData: (data: DataTransfer) => boolean
|
|
140
|
-
insertTextOrHTMLData: (data: DataTransfer) => boolean
|
|
141
|
-
isTextBlock: (value: unknown) => value is PortableTextTextBlock
|
|
142
|
-
isTextSpan: (value: unknown) => value is PortableTextSpan
|
|
143
|
-
isListBlock: (value: unknown) => value is PortableTextListBlock
|
|
144
|
-
value: Array<PortableTextBlock>
|
|
145
|
-
decoratedRanges: Array<DecoratedRange>
|
|
146
|
-
decoratorState: Record<string, boolean | undefined>
|
|
147
|
-
blockIndexMap: Map<string, number>
|
|
148
|
-
listIndexMap: Map<string, number>
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Use hotkeys
|
|
152
|
-
*/
|
|
153
|
-
pteWithHotKeys: (event: KeyboardEvent<HTMLDivElement>) => void
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Undo
|
|
157
|
-
*/
|
|
158
|
-
undo: () => void
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Redo
|
|
162
|
-
*/
|
|
163
|
-
redo: () => void
|
|
164
|
-
}
|
|
165
|
-
|
|
166
116
|
/**
|
|
167
117
|
* The editor has mutated it's content.
|
|
168
118
|
* @beta */
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
PortableTextBlock,
|
|
3
|
+
PortableTextListBlock,
|
|
4
|
+
PortableTextSpan,
|
|
5
|
+
PortableTextTextBlock,
|
|
6
|
+
} from '@sanity/types'
|
|
7
|
+
import type {KeyboardEvent} from 'react'
|
|
8
|
+
import type {Descendant, Operation as SlateOperation} from 'slate'
|
|
9
|
+
import type {ReactEditor} from 'slate-react'
|
|
10
|
+
import type {DecoratedRange} from '../editor/range-decorations-machine'
|
|
11
|
+
|
|
12
|
+
type HistoryItem = {
|
|
13
|
+
operations: SlateOperation[]
|
|
14
|
+
timestamp: Date
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface History {
|
|
18
|
+
redos: HistoryItem[]
|
|
19
|
+
undos: HistoryItem[]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface PortableTextSlateEditor extends ReactEditor {
|
|
23
|
+
_key: 'editor'
|
|
24
|
+
_type: 'editor'
|
|
25
|
+
createPlaceholderBlock: () => Descendant
|
|
26
|
+
history: History
|
|
27
|
+
isTextBlock: (value: unknown) => value is PortableTextTextBlock
|
|
28
|
+
isTextSpan: (value: unknown) => value is PortableTextSpan
|
|
29
|
+
isListBlock: (value: unknown) => value is PortableTextListBlock
|
|
30
|
+
value: Array<PortableTextBlock>
|
|
31
|
+
decoratedRanges: Array<DecoratedRange>
|
|
32
|
+
decoratorState: Record<string, boolean | undefined>
|
|
33
|
+
blockIndexMap: Map<string, number>
|
|
34
|
+
listIndexMap: Map<string, number>
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Use hotkeys
|
|
38
|
+
*/
|
|
39
|
+
pteWithHotKeys: (event: KeyboardEvent<HTMLDivElement>) => void
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Undo
|
|
43
|
+
*/
|
|
44
|
+
undo: () => void
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Redo
|
|
48
|
+
*/
|
|
49
|
+
redo: () => void
|
|
50
|
+
}
|
package/src/types/slate.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {PortableTextSpan, PortableTextTextBlock} from '@sanity/types'
|
|
2
2
|
import type {BaseEditor, Descendant} from 'slate'
|
|
3
3
|
import type {ReactEditor} from 'slate-react'
|
|
4
|
-
import type {PortableTextSlateEditor} from './editor'
|
|
4
|
+
import type {PortableTextSlateEditor} from './slate-editor'
|
|
5
5
|
|
|
6
6
|
export interface VoidElement {
|
|
7
7
|
_type: string
|