@portabletext/editor 2.13.3 → 2.13.5
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/{selector.is-selection-expanded.cjs → selector.get-selection-text.cjs} +25 -25
- package/lib/_chunks-cjs/selector.get-selection-text.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.get-text-before.cjs +4 -4
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/{selector.is-selecting-entire-blocks.cjs → selector.is-active-style.cjs} +408 -399
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -0
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs +3 -3
- package/lib/_chunks-cjs/util.child-selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-cjs/{util.slice-blocks.cjs → util.get-text-block-text.cjs} +25 -26
- package/lib/_chunks-cjs/util.get-text-block-text.cjs.map +1 -0
- package/lib/_chunks-cjs/{util.is-selection-collapsed.cjs → util.is-empty-text-block.cjs} +9 -9
- package/lib/_chunks-cjs/util.is-empty-text-block.cjs.map +1 -0
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs +2 -2
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-text-block.cjs +5 -5
- package/lib/_chunks-cjs/util.slice-text-block.cjs.map +1 -1
- package/lib/_chunks-dts/behavior.types.action.d.cts +271 -271
- package/lib/_chunks-dts/behavior.types.action.d.ts +322 -322
- package/lib/_chunks-es/{selector.is-selection-expanded.js → selector.get-selection-text.js} +20 -20
- package/lib/_chunks-es/selector.get-selection-text.js.map +1 -0
- package/lib/_chunks-es/selector.get-text-before.js +2 -2
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/{selector.is-selecting-entire-blocks.js → selector.is-active-style.js} +385 -376
- package/lib/_chunks-es/selector.is-active-style.js.map +1 -0
- package/lib/_chunks-es/util.child-selection-point-to-block-offset.js +1 -1
- package/lib/_chunks-es/util.child-selection-point-to-block-offset.js.map +1 -1
- package/lib/_chunks-es/{util.slice-blocks.js → util.get-text-block-text.js} +25 -26
- package/lib/_chunks-es/util.get-text-block-text.js.map +1 -0
- package/lib/_chunks-es/{util.is-selection-collapsed.js → util.is-empty-text-block.js} +8 -8
- package/lib/_chunks-es/util.is-empty-text-block.js.map +1 -0
- package/lib/_chunks-es/util.merge-text-blocks.js +1 -1
- package/lib/_chunks-es/util.merge-text-blocks.js.map +1 -1
- package/lib/_chunks-es/util.slice-text-block.js +1 -1
- package/lib/_chunks-es/util.slice-text-block.js.map +1 -1
- package/lib/index.cjs +225 -225
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +18 -18
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +21 -21
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +4 -4
- package/lib/plugins/index.d.ts +4 -4
- package/lib/plugins/index.js +3 -3
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs +52 -52
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.js +5 -5
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +14 -14
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.ts +2 -2
- package/lib/utils/index.js +3 -3
- package/lib/utils/index.js.map +1 -1
- package/package.json +14 -14
- package/src/behaviors/behavior.abstract.annotation.ts +3 -3
- package/src/behaviors/behavior.abstract.decorator.ts +2 -2
- package/src/behaviors/behavior.abstract.delete.ts +25 -16
- package/src/behaviors/behavior.abstract.deserialize.ts +4 -3
- package/src/behaviors/behavior.abstract.insert.ts +6 -7
- package/src/behaviors/behavior.abstract.keyboard.ts +7 -8
- package/src/behaviors/behavior.abstract.list-item.ts +2 -1
- package/src/behaviors/behavior.abstract.move.ts +2 -1
- package/src/behaviors/behavior.abstract.select.ts +4 -2
- package/src/behaviors/behavior.abstract.split.ts +33 -24
- package/src/behaviors/behavior.abstract.style.ts +2 -1
- package/src/behaviors/behavior.abstract.ts +8 -7
- package/src/behaviors/behavior.core.annotations.ts +8 -7
- package/src/behaviors/behavior.core.block-element.ts +7 -5
- package/src/behaviors/behavior.core.block-objects.ts +25 -27
- package/src/behaviors/behavior.core.dnd.ts +10 -8
- package/src/behaviors/behavior.core.insert-break.ts +45 -36
- package/src/behaviors/behavior.core.lists.ts +31 -25
- package/src/behaviors/behavior.decorator-pair.ts +26 -23
- package/src/behaviors/behavior.markdown.ts +26 -21
- package/src/converters/converter.portable-text.ts +3 -3
- package/src/converters/converter.text-html.serialize.test.ts +1 -1
- package/src/converters/converter.text-html.ts +3 -3
- package/src/converters/converter.text-plain.test.ts +1 -1
- package/src/converters/converter.text-plain.ts +3 -3
- package/src/editor/Editable.tsx +2 -2
- package/src/editor/components/render-span.tsx +3 -5
- package/src/editor/create-editor.ts +2 -2
- package/src/editor/create-slate-editor.tsx +1 -4
- package/src/editor/editor-dom.ts +2 -2
- package/src/editor/plugins/createWithEditableAPI.ts +5 -10
- package/src/editor/plugins/createWithMaxBlocks.ts +2 -2
- package/src/editor/plugins/createWithObjectKeys.ts +2 -2
- package/src/editor/plugins/createWithPatches.ts +3 -10
- package/src/editor/plugins/createWithPlaceholderBlock.ts +2 -2
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +2 -2
- package/src/editor/plugins/createWithSchemaTypes.ts +1 -1
- package/src/editor/plugins/createWithUndoRedo.ts +6 -6
- package/src/editor/plugins/slate-plugin.update-selection.ts +1 -1
- package/src/editor/sync-machine.ts +2 -5
- package/src/{internal-utils → editor}/weakMaps.ts +1 -1
- package/src/editor/with-undo-step.ts +1 -1
- package/src/index.ts +1 -1
- package/src/internal-utils/applyPatch.ts +2 -2
- package/src/internal-utils/build-index-maps.test.ts +1 -1
- package/src/internal-utils/create-test-snapshot.ts +1 -1
- package/src/internal-utils/event-position.ts +11 -9
- package/src/internal-utils/operation-to-patches.test.ts +1 -1
- package/src/internal-utils/portable-text-node.ts +1 -1
- package/src/internal-utils/selection-block-keys.ts +1 -1
- package/src/internal-utils/selection-focus-text.ts +1 -1
- package/src/internal-utils/to-slate-range.ts +4 -4
- package/src/operations/behavior.operation.annotation.add.ts +1 -1
- package/src/operations/behavior.operation.block.set.ts +1 -1
- package/src/operations/behavior.operation.block.unset.ts +2 -2
- package/src/operations/behavior.operation.decorator.add.ts +11 -9
- package/src/operations/behavior.operation.delete.ts +1 -1
- package/src/operations/behavior.operation.insert.block.ts +2 -2
- package/src/operations/behavior.operation.insert.child.ts +1 -1
- package/src/operations/behavior.operation.move.block.ts +1 -1
- package/src/plugins/plugin.behavior.tsx +1 -1
- package/src/plugins/plugin.decorator-shortcut.ts +3 -3
- package/src/plugins/plugin.internal.auto-close-brackets.ts +2 -1
- package/src/plugins/plugin.one-line.tsx +11 -11
- package/src/priority/priority.types.ts +1 -1
- package/src/{internal-utils → selectors}/drag-selection.test.ts +1 -1
- package/src/{internal-utils → selectors}/drag-selection.ts +26 -19
- package/src/selectors/selector.get-anchor-block.ts +1 -1
- package/src/selectors/selector.get-anchor-child.ts +1 -1
- package/src/selectors/selector.get-block-offsets.ts +3 -3
- package/src/selectors/selector.get-caret-word-selection.test.ts +1 -1
- package/src/selectors/selector.get-focus-block.ts +1 -1
- package/src/selectors/selector.get-focus-child.ts +1 -1
- package/src/selectors/selector.get-focus-list-block.ts +1 -1
- package/src/selectors/selector.get-list-state.test.ts +1 -1
- package/src/selectors/selector.get-mark-state.ts +1 -1
- package/src/selectors/selector.get-next-inline-object.ts +1 -1
- package/src/selectors/selector.get-next-span.ts +1 -1
- package/src/selectors/selector.get-previous-inline-object.ts +1 -1
- package/src/selectors/selector.get-previous-span.ts +1 -1
- package/src/selectors/selector.get-selected-blocks.ts +1 -1
- package/src/selectors/selector.get-selected-spans.test.ts +1 -1
- package/src/selectors/selector.get-selected-spans.ts +2 -2
- package/src/selectors/selector.get-selected-text-blocks.ts +3 -2
- package/src/selectors/selector.get-selected-value.test.ts +87 -1
- package/src/selectors/selector.get-selected-value.ts +4 -6
- package/src/selectors/selector.get-selection-end-point.ts +1 -1
- package/src/selectors/selector.get-selection-start-point.ts +1 -1
- package/src/selectors/selector.get-selection-text.test.ts +1 -1
- package/src/selectors/selector.get-selection.ts +1 -1
- package/src/selectors/selector.get-text-before.ts +1 -1
- package/src/selectors/selector.get-trimmed-selection.test.ts +1 -1
- package/src/selectors/selector.get-trimmed-selection.ts +5 -7
- package/src/selectors/selector.is-active-decorator.test.ts +2 -1
- package/src/selectors/selector.is-at-the-end-of-block.ts +4 -3
- package/src/selectors/selector.is-at-the-start-of-block.ts +4 -3
- package/src/selectors/selector.is-overlapping-selection.test.ts +1 -1
- package/src/selectors/selector.is-overlapping-selection.ts +1 -1
- package/src/selectors/selector.is-point-after-selection.ts +3 -3
- package/src/selectors/selector.is-point-before-selection.ts +3 -3
- package/src/selectors/selector.is-selecting-entire-blocks.ts +7 -5
- package/src/test/gherkin-parameter-types.ts +3 -3
- package/src/test/vitest/step-definitions.tsx +19 -9
- package/src/types/paths.ts +4 -1
- package/src/utils/util.at-the-beginning-of-block.ts +1 -1
- package/src/utils/util.block-offset.ts +4 -4
- package/src/utils/util.block-offsets-to-selection.ts +1 -1
- package/src/utils/util.child-selection-point-to-block-offset.ts +3 -3
- package/src/utils/util.get-selection-end-point.ts +1 -1
- package/src/utils/util.get-selection-start-point.ts +1 -1
- package/src/utils/util.merge-text-blocks.ts +2 -2
- package/src/utils/util.selection-point-to-block-offset.ts +1 -1
- package/src/{selection/selection-point.ts → utils/util.selection-point.ts} +1 -1
- package/src/utils/util.slice-blocks.ts +6 -6
- package/src/utils/util.slice-text-block.test.ts +3 -1
- package/src/utils/util.slice-text-block.ts +3 -3
- package/src/utils/util.split-text-block.ts +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +0 -1
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +0 -1
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +0 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +0 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +0 -1
- package/lib/_chunks-es/selector.is-selection-expanded.js.map +0 -1
- package/lib/_chunks-es/util.is-selection-collapsed.js.map +0 -1
- package/lib/_chunks-es/util.slice-blocks.js.map +0 -1
- /package/src/{internal-utils → editor}/withChanges.ts +0 -0
- /package/src/{internal-utils → editor}/withUndoRedo.ts +0 -0
- /package/src/{internal-utils → editor}/withoutPatching.ts +0 -0
- /package/src/{internal-utils → utils}/asserters.ts +0 -0
- /package/src/{editor → utils}/key-generator.ts +0 -0
- /package/src/{internal-utils → utils}/parse-blocks.test.ts +0 -0
- /package/src/{internal-utils → utils}/parse-blocks.ts +0 -0
|
@@ -6,8 +6,8 @@ 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 {isListBlock} from '../../internal-utils/parse-blocks'
|
|
10
9
|
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
10
|
+
import {isListBlock} from '../../utils/parse-blocks'
|
|
11
11
|
import type {EditorActor} from '../editor-machine'
|
|
12
12
|
|
|
13
13
|
const debug = debugWithName('plugin:withSchemaTypes')
|
|
@@ -22,7 +22,11 @@ import {
|
|
|
22
22
|
} from 'slate'
|
|
23
23
|
import {debugWithName} from '../../internal-utils/debug'
|
|
24
24
|
import {fromSlateValue} from '../../internal-utils/values'
|
|
25
|
-
import {
|
|
25
|
+
import type {BehaviorOperationImplementation} from '../../operations/behavior.operations'
|
|
26
|
+
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
27
|
+
import type {EditorActor} from '../editor-machine'
|
|
28
|
+
import {getCurrentUndoStepId} from '../with-undo-step'
|
|
29
|
+
import {isChangingRemotely} from '../withChanges'
|
|
26
30
|
import {
|
|
27
31
|
isRedoing,
|
|
28
32
|
isUndoing,
|
|
@@ -30,11 +34,7 @@ import {
|
|
|
30
34
|
setIsUndoing,
|
|
31
35
|
withRedoing,
|
|
32
36
|
withUndoing,
|
|
33
|
-
} from '
|
|
34
|
-
import type {BehaviorOperationImplementation} from '../../operations/behavior.operations'
|
|
35
|
-
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
36
|
-
import type {EditorActor} from '../editor-machine'
|
|
37
|
-
import {getCurrentUndoStepId} from '../with-undo-step'
|
|
37
|
+
} from '../withUndoRedo'
|
|
38
38
|
|
|
39
39
|
const debug = debugWithName('plugin:withUndoRedo')
|
|
40
40
|
const debugVerbose = debug.enabled && false
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {slateRangeToSelection} from '../../internal-utils/slate-utils'
|
|
2
|
-
import {SLATE_TO_PORTABLE_TEXT_RANGE} from '../../internal-utils/weakMaps'
|
|
3
2
|
import type {PortableTextSlateEditor} from '../../types/editor'
|
|
4
3
|
import type {EditorActor} from '../editor-machine'
|
|
4
|
+
import {SLATE_TO_PORTABLE_TEXT_RANGE} from '../weakMaps'
|
|
5
5
|
|
|
6
6
|
export function pluginUpdateSelection({
|
|
7
7
|
editor,
|
|
@@ -25,11 +25,6 @@ import type {ActorRefFrom} from 'xstate'
|
|
|
25
25
|
import {debugWithName} from '../internal-utils/debug'
|
|
26
26
|
import {validateValue} from '../internal-utils/validateValue'
|
|
27
27
|
import {toSlateValue, VOID_CHILD_KEY} from '../internal-utils/values'
|
|
28
|
-
import {
|
|
29
|
-
isChangingRemotely,
|
|
30
|
-
withRemoteChanges,
|
|
31
|
-
} from '../internal-utils/withChanges'
|
|
32
|
-
import {withoutPatching} from '../internal-utils/withoutPatching'
|
|
33
28
|
import type {PickFromUnion} from '../type-utils'
|
|
34
29
|
import type {
|
|
35
30
|
InvalidValueResolution,
|
|
@@ -37,6 +32,8 @@ import type {
|
|
|
37
32
|
} from '../types/editor'
|
|
38
33
|
import type {EditorSchema} from './editor-schema'
|
|
39
34
|
import {withoutSaving} from './plugins/createWithUndoRedo'
|
|
35
|
+
import {isChangingRemotely, withRemoteChanges} from './withChanges'
|
|
36
|
+
import {withoutPatching} from './withoutPatching'
|
|
40
37
|
|
|
41
38
|
const debug = debugWithName('sync machine')
|
|
42
39
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {Editor, Range} from 'slate'
|
|
2
|
-
import type {EditorSelection} from '
|
|
2
|
+
import type {EditorSelection} from '../types/editor'
|
|
3
3
|
|
|
4
4
|
// Is the editor currently receiving remote changes that are being applied to the content?
|
|
5
5
|
export const IS_PROCESSING_REMOTE_CHANGES: WeakMap<Editor, boolean> =
|
package/src/index.ts
CHANGED
|
@@ -40,7 +40,7 @@ export {useEditorSelector, type EditorSelector} from './editor/editor-selector'
|
|
|
40
40
|
export type {EditorContext, EditorSnapshot} from './editor/editor-snapshot'
|
|
41
41
|
export {usePortableTextEditor} from './editor/hooks/usePortableTextEditor'
|
|
42
42
|
export {usePortableTextEditorSelection} from './editor/hooks/usePortableTextEditorSelection'
|
|
43
|
-
export {defaultKeyGenerator as keyGenerator} from './
|
|
43
|
+
export {defaultKeyGenerator as keyGenerator} from './utils/key-generator'
|
|
44
44
|
export {PortableTextEditor} from './editor/PortableTextEditor'
|
|
45
45
|
export type {PortableTextEditorProps} from './editor/PortableTextEditor'
|
|
46
46
|
export type {EditorEmittedEvent, MutationEvent} from './editor/relay-machine'
|
|
@@ -18,10 +18,10 @@ import {
|
|
|
18
18
|
import type {Path, PortableTextBlock, PortableTextChild} from '@sanity/types'
|
|
19
19
|
import {Element, Node, Text, Transforms, type Descendant} from 'slate'
|
|
20
20
|
import type {EditorSchema} from '../editor/editor-schema'
|
|
21
|
+
import {KEY_TO_SLATE_ELEMENT} from '../editor/weakMaps'
|
|
21
22
|
import type {PortableTextSlateEditor} from '../types/editor'
|
|
22
|
-
import {isKeyedSegment} from '../utils'
|
|
23
|
+
import {isKeyedSegment} from '../utils/util.is-keyed-segment'
|
|
23
24
|
import {isEqualToEmptyEditor, toSlateValue} from './values'
|
|
24
|
-
import {KEY_TO_SLATE_ELEMENT} from './weakMaps'
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Creates a function that can apply a patch onto a PortableTextSlateEditor.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {compileSchema, defineSchema} from '@portabletext/schema'
|
|
2
2
|
import type {PortableTextBlock} from '@sanity/types'
|
|
3
3
|
import {describe, expect, test} from 'vitest'
|
|
4
|
-
import {defaultKeyGenerator} from '../
|
|
4
|
+
import {defaultKeyGenerator} from '../utils/key-generator'
|
|
5
5
|
import {buildIndexMaps} from './build-index-maps'
|
|
6
6
|
|
|
7
7
|
function blockObject(_key: string, name: string) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {compileSchema, defineSchema} from '@portabletext/schema'
|
|
2
2
|
import {createTestKeyGenerator} from '@portabletext/test'
|
|
3
|
-
import type {EditorSnapshot} from '
|
|
3
|
+
import type {EditorSnapshot} from '../editor/editor-snapshot'
|
|
4
4
|
|
|
5
5
|
export function createTestSnapshot(snapshot: {
|
|
6
6
|
context?: Partial<EditorSnapshot['context']>
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {Editor, type BaseRange, type Node} from 'slate'
|
|
2
2
|
import {DOMEditor, isDOMNode} from 'slate-dom'
|
|
3
|
-
import type {EditorSchema, EditorSelection} from '..'
|
|
4
3
|
import type {EditorActor} from '../editor/editor-machine'
|
|
5
|
-
import {
|
|
6
|
-
import type {PortableTextSlateEditor} from '../types/editor'
|
|
7
|
-
import
|
|
4
|
+
import type {EditorSchema} from '../editor/editor-schema'
|
|
5
|
+
import type {EditorSelection, PortableTextSlateEditor} from '../types/editor'
|
|
6
|
+
import {getBlockEndPoint} from '../utils/util.get-block-end-point'
|
|
7
|
+
import {getBlockStartPoint} from '../utils/util.get-block-start-point'
|
|
8
|
+
import {isSelectionCollapsed} from '../utils/util.is-selection-collapsed'
|
|
9
|
+
import {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'
|
|
8
10
|
import {
|
|
9
11
|
getFirstBlock,
|
|
10
12
|
getLastBlock,
|
|
@@ -69,14 +71,14 @@ export function getEventPosition({
|
|
|
69
71
|
block: eventPositionBlock,
|
|
70
72
|
isEditor: false,
|
|
71
73
|
selection: {
|
|
72
|
-
anchor:
|
|
74
|
+
anchor: getBlockStartPoint({
|
|
73
75
|
context: editorActor.getSnapshot().context,
|
|
74
76
|
block: {
|
|
75
77
|
node: eventBlock,
|
|
76
78
|
path: [{_key: eventBlock._key}],
|
|
77
79
|
},
|
|
78
80
|
}),
|
|
79
|
-
focus:
|
|
81
|
+
focus: getBlockEndPoint({
|
|
80
82
|
context: editorActor.getSnapshot().context,
|
|
81
83
|
block: {
|
|
82
84
|
node: eventBlock,
|
|
@@ -100,7 +102,7 @@ export function getEventPosition({
|
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
if (
|
|
103
|
-
|
|
105
|
+
isSelectionCollapsed(eventSelection) &&
|
|
104
106
|
eventBlock &&
|
|
105
107
|
eventSelectionFocusBlockKey !== eventBlock._key
|
|
106
108
|
) {
|
|
@@ -110,14 +112,14 @@ export function getEventPosition({
|
|
|
110
112
|
block: eventPositionBlock,
|
|
111
113
|
isEditor: false,
|
|
112
114
|
selection: {
|
|
113
|
-
anchor:
|
|
115
|
+
anchor: getBlockStartPoint({
|
|
114
116
|
context: editorActor.getSnapshot().context,
|
|
115
117
|
block: {
|
|
116
118
|
node: eventBlock,
|
|
117
119
|
path: [{_key: eventBlock._key}],
|
|
118
120
|
},
|
|
119
121
|
}),
|
|
120
|
-
focus:
|
|
122
|
+
focus: getBlockEndPoint({
|
|
121
123
|
context: editorActor.getSnapshot().context,
|
|
122
124
|
block: {
|
|
123
125
|
node: eventBlock,
|
|
@@ -5,9 +5,9 @@ import {createEditor, type Descendant} from 'slate'
|
|
|
5
5
|
import {beforeEach, describe, expect, it} from 'vitest'
|
|
6
6
|
import {createActor} from 'xstate'
|
|
7
7
|
import {editorMachine} from '../editor/editor-machine'
|
|
8
|
-
import {defaultKeyGenerator} from '../editor/key-generator'
|
|
9
8
|
import {withPlugins} from '../editor/plugins/with-plugins'
|
|
10
9
|
import {relayMachine} from '../editor/relay-machine'
|
|
10
|
+
import {defaultKeyGenerator} from '../utils/key-generator'
|
|
11
11
|
import {
|
|
12
12
|
insertNodePatch,
|
|
13
13
|
insertTextPatch,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {getBlockKeyFromSelectionPoint} from '../selection/selection-point'
|
|
2
1
|
import type {EditorSelection} from '../types/editor'
|
|
2
|
+
import {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'
|
|
3
3
|
|
|
4
4
|
export function getSelectionBlockKeys(selection: EditorSelection) {
|
|
5
5
|
if (!selection) {
|
|
@@ -3,7 +3,7 @@ import type {EditorContext} from '../editor/editor-snapshot'
|
|
|
3
3
|
import {
|
|
4
4
|
getBlockKeyFromSelectionPoint,
|
|
5
5
|
getChildKeyFromSelectionPoint,
|
|
6
|
-
} from '../
|
|
6
|
+
} from '../utils/util.selection-point'
|
|
7
7
|
|
|
8
8
|
export function getSelectionFocusText(
|
|
9
9
|
context: Pick<EditorContext, 'schema' | 'value' | 'selection'>,
|
|
@@ -2,13 +2,13 @@ import {isSpan, isTextBlock} from '@portabletext/schema'
|
|
|
2
2
|
import type {PortableTextObject, PortableTextSpan} from '@sanity/types'
|
|
3
3
|
import type {Path, Range} from 'slate'
|
|
4
4
|
import type {EditorContext, EditorSnapshot} from '../editor/editor-snapshot'
|
|
5
|
+
import type {EditorSelectionPoint} from '../types/editor'
|
|
6
|
+
import {blockOffsetToSpanSelectionPoint} from '../utils/util.block-offset'
|
|
7
|
+
import {isEqualSelectionPoints} from '../utils/util.is-equal-selection-points'
|
|
5
8
|
import {
|
|
6
9
|
getBlockKeyFromSelectionPoint,
|
|
7
10
|
getChildKeyFromSelectionPoint,
|
|
8
|
-
} from '../
|
|
9
|
-
import type {EditorSelectionPoint} from '../types/editor'
|
|
10
|
-
import {isEqualSelectionPoints} from '../utils'
|
|
11
|
-
import {blockOffsetToSpanSelectionPoint} from '../utils/util.block-offset'
|
|
11
|
+
} from '../utils/util.selection-point'
|
|
12
12
|
|
|
13
13
|
export function toSlateRange(
|
|
14
14
|
snapshot: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {Editor, Node, Range, Text, Transforms} from 'slate'
|
|
2
|
-
import {parseAnnotation} from '../
|
|
2
|
+
import {parseAnnotation} from '../utils/parse-blocks'
|
|
3
3
|
import type {BehaviorOperationImplementation} from './behavior.operations'
|
|
4
4
|
|
|
5
5
|
export const addAnnotationOperationImplementation: BehaviorOperationImplementation<
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {Transforms, type Element as SlateElement} from 'slate'
|
|
2
|
-
import {parseBlock} from '../internal-utils/parse-blocks'
|
|
3
2
|
import {toSlateValue} from '../internal-utils/values'
|
|
3
|
+
import {parseBlock} from '../utils/parse-blocks'
|
|
4
4
|
import type {BehaviorOperationImplementation} from './behavior.operations'
|
|
5
5
|
|
|
6
6
|
export const blockSetOperationImplementation: BehaviorOperationImplementation<
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {isTextBlock} from '@portabletext/schema'
|
|
2
2
|
import {omit} from 'lodash'
|
|
3
3
|
import {Editor, Transforms} from 'slate'
|
|
4
|
-
import {
|
|
4
|
+
import {KEY_TO_VALUE_ELEMENT} from '../editor/weakMaps'
|
|
5
5
|
import {toSlateRange} from '../internal-utils/to-slate-range'
|
|
6
6
|
import {fromSlateValue} from '../internal-utils/values'
|
|
7
|
-
import {
|
|
7
|
+
import {parseBlock} from '../utils/parse-blocks'
|
|
8
8
|
import type {BehaviorOperationImplementation} from './behavior.operations'
|
|
9
9
|
|
|
10
10
|
export const blockUnsetOperationImplementation: BehaviorOperationImplementation<
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {Editor, Range, Text, Transforms} from 'slate'
|
|
2
|
+
import {KEY_TO_VALUE_ELEMENT} from '../editor/weakMaps'
|
|
2
3
|
import {slateRangeToSelection} from '../internal-utils/slate-utils'
|
|
3
4
|
import {toSlateRange} from '../internal-utils/to-slate-range'
|
|
4
5
|
import {fromSlateValue} from '../internal-utils/values'
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import
|
|
6
|
+
import {getTrimmedSelection} from '../selectors/selector.get-trimmed-selection'
|
|
7
|
+
import {blockOffsetToSpanSelectionPoint} from '../utils/util.block-offset'
|
|
8
|
+
import {blockOffsetsToSelection} from '../utils/util.block-offsets-to-selection'
|
|
9
|
+
import {selectionPointToBlockOffset} from '../utils/util.selection-point-to-block-offset'
|
|
8
10
|
import type {BehaviorOperationImplementation} from './behavior.operations'
|
|
9
11
|
|
|
10
12
|
export const decoratorAddOperationImplementation: BehaviorOperationImplementation<
|
|
@@ -19,7 +21,7 @@ export const decoratorAddOperationImplementation: BehaviorOperationImplementatio
|
|
|
19
21
|
)
|
|
20
22
|
|
|
21
23
|
const manualAnchor = operation.at?.anchor
|
|
22
|
-
?
|
|
24
|
+
? blockOffsetToSpanSelectionPoint({
|
|
23
25
|
context: {
|
|
24
26
|
...context,
|
|
25
27
|
value,
|
|
@@ -29,7 +31,7 @@ export const decoratorAddOperationImplementation: BehaviorOperationImplementatio
|
|
|
29
31
|
})
|
|
30
32
|
: undefined
|
|
31
33
|
const manualFocus = operation.at?.focus
|
|
32
|
-
?
|
|
34
|
+
? blockOffsetToSpanSelectionPoint({
|
|
33
35
|
context: {
|
|
34
36
|
...context,
|
|
35
37
|
value,
|
|
@@ -67,7 +69,7 @@ export const decoratorAddOperationImplementation: BehaviorOperationImplementatio
|
|
|
67
69
|
range: selection,
|
|
68
70
|
})
|
|
69
71
|
const anchorOffset = editorSelection
|
|
70
|
-
?
|
|
72
|
+
? selectionPointToBlockOffset({
|
|
71
73
|
context: {
|
|
72
74
|
...context,
|
|
73
75
|
value,
|
|
@@ -76,7 +78,7 @@ export const decoratorAddOperationImplementation: BehaviorOperationImplementatio
|
|
|
76
78
|
})
|
|
77
79
|
: undefined
|
|
78
80
|
const focusOffset = editorSelection
|
|
79
|
-
?
|
|
81
|
+
? selectionPointToBlockOffset({
|
|
80
82
|
context: {
|
|
81
83
|
...context,
|
|
82
84
|
value,
|
|
@@ -105,7 +107,7 @@ export const decoratorAddOperationImplementation: BehaviorOperationImplementatio
|
|
|
105
107
|
)
|
|
106
108
|
// We need to find the new selection from the original offsets because the
|
|
107
109
|
// split operation might have changed the value.
|
|
108
|
-
const newSelection =
|
|
110
|
+
const newSelection = blockOffsetsToSelection({
|
|
109
111
|
context: {
|
|
110
112
|
...context,
|
|
111
113
|
value: newValue,
|
|
@@ -114,7 +116,7 @@ export const decoratorAddOperationImplementation: BehaviorOperationImplementatio
|
|
|
114
116
|
backward: editorSelection?.backward,
|
|
115
117
|
})
|
|
116
118
|
|
|
117
|
-
const trimmedSelection =
|
|
119
|
+
const trimmedSelection = getTrimmedSelection({
|
|
118
120
|
blockIndexMap: editor.blockIndexMap,
|
|
119
121
|
context: {
|
|
120
122
|
converters: [],
|
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
import {DOMEditor} from 'slate-dom'
|
|
11
11
|
import {createPlaceholderBlock} from '../internal-utils/create-placeholder-block'
|
|
12
12
|
import {toSlateRange} from '../internal-utils/to-slate-range'
|
|
13
|
-
import {getBlockKeyFromSelectionPoint} from '../selection/selection-point'
|
|
14
13
|
import type {PortableTextSlateEditor} from '../types/editor'
|
|
14
|
+
import {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'
|
|
15
15
|
import type {BehaviorOperationImplementation} from './behavior.operations'
|
|
16
16
|
|
|
17
17
|
export const deleteOperationImplementation: BehaviorOperationImplementation<
|
|
@@ -2,7 +2,6 @@ import {isSpan} from '@portabletext/schema'
|
|
|
2
2
|
import {isEqual} from 'lodash'
|
|
3
3
|
import {Editor, Path, Point, Range, Transforms, type Descendant} from 'slate'
|
|
4
4
|
import {DOMEditor} from 'slate-dom'
|
|
5
|
-
import {parseBlock} from '../internal-utils/parse-blocks'
|
|
6
5
|
import {
|
|
7
6
|
getFocusBlock,
|
|
8
7
|
getFocusChild,
|
|
@@ -12,7 +11,8 @@ import {
|
|
|
12
11
|
} from '../internal-utils/slate-utils'
|
|
13
12
|
import {isEqualToEmptyEditor, toSlateValue} from '../internal-utils/values'
|
|
14
13
|
import type {PortableTextSlateEditor} from '../types/editor'
|
|
15
|
-
import {
|
|
14
|
+
import {parseBlock} from '../utils/parse-blocks'
|
|
15
|
+
import {isEmptyTextBlock} from '../utils/util.is-empty-text-block'
|
|
16
16
|
import type {
|
|
17
17
|
BehaviorOperationImplementation,
|
|
18
18
|
BehaviorOperationImplementationContext,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {isTextBlock} from '@portabletext/schema'
|
|
2
2
|
import {Transforms} from 'slate'
|
|
3
3
|
import {EDITOR_TO_PENDING_SELECTION} from 'slate-dom'
|
|
4
|
-
import {parseInlineObject, parseSpan} from '../internal-utils/parse-blocks'
|
|
5
4
|
import {getFocusBlock, getFocusSpan} from '../internal-utils/slate-utils'
|
|
6
5
|
import {VOID_CHILD_KEY} from '../internal-utils/values'
|
|
6
|
+
import {parseInlineObject, parseSpan} from '../utils/parse-blocks'
|
|
7
7
|
import type {BehaviorOperationImplementation} from './behavior.operations'
|
|
8
8
|
|
|
9
9
|
export const insertChildOperationImplementation: BehaviorOperationImplementation<
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {Transforms} from 'slate'
|
|
2
|
-
import {getBlockKeyFromSelectionPoint} from '../
|
|
2
|
+
import {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'
|
|
3
3
|
import type {BehaviorOperationImplementation} from './behavior.operations'
|
|
4
4
|
|
|
5
5
|
export const moveBlockOperationImplementation: BehaviorOperationImplementation<
|
|
@@ -14,7 +14,7 @@ import type {Editor} from '../editor'
|
|
|
14
14
|
import type {EditorSchema} from '../editor/editor-schema'
|
|
15
15
|
import {useEditor} from '../editor/use-editor'
|
|
16
16
|
import type {BlockOffset} from '../types/block-offset'
|
|
17
|
-
import
|
|
17
|
+
import {spanSelectionPointToBlockOffset} from '../utils/util.block-offset'
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* @beta
|
|
@@ -88,11 +88,11 @@ const selectionListenerCallback: CallbackLogicFunction<
|
|
|
88
88
|
return {blockOffsets: undefined}
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
const anchor =
|
|
91
|
+
const anchor = spanSelectionPointToBlockOffset({
|
|
92
92
|
context: snapshot.context,
|
|
93
93
|
selectionPoint: event.at.anchor,
|
|
94
94
|
})
|
|
95
|
-
const focus =
|
|
95
|
+
const focus = spanSelectionPointToBlockOffset({
|
|
96
96
|
context: snapshot.context,
|
|
97
97
|
selectionPoint: event.at.focus,
|
|
98
98
|
})
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {useEffect} from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import {execute} from '../behaviors/behavior.types.action'
|
|
3
|
+
import {defineBehavior} from '../behaviors/behavior.types.behavior'
|
|
3
4
|
import {useEditor} from '../editor/use-editor'
|
|
4
5
|
|
|
5
6
|
export function AutoCloseBracketsPlugin() {
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import {isTextBlock} from '@portabletext/schema'
|
|
2
|
+
import {execute, raise} from '../behaviors/behavior.types.action'
|
|
3
|
+
import {defineBehavior} from '../behaviors/behavior.types.behavior'
|
|
4
|
+
import {getFocusTextBlock} from '../selectors/selector.get-focus-text-block'
|
|
5
|
+
import {isSelectionExpanded} from '../selectors/selector.is-selection-expanded'
|
|
6
|
+
import {mergeTextBlocks} from '../utils/util.merge-text-blocks'
|
|
4
7
|
import {BehaviorPlugin} from './plugin.behavior'
|
|
5
8
|
|
|
6
9
|
const oneLineBehaviors = [
|
|
@@ -11,7 +14,7 @@ const oneLineBehaviors = [
|
|
|
11
14
|
defineBehavior({
|
|
12
15
|
on: 'insert.break',
|
|
13
16
|
guard: ({snapshot}) =>
|
|
14
|
-
snapshot.context.selection &&
|
|
17
|
+
snapshot.context.selection && isSelectionExpanded(snapshot)
|
|
15
18
|
? {selection: snapshot.context.selection}
|
|
16
19
|
: false,
|
|
17
20
|
actions: [(_, {selection}) => [execute({type: 'delete', at: selection})]],
|
|
@@ -39,12 +42,9 @@ const oneLineBehaviors = [
|
|
|
39
42
|
defineBehavior({
|
|
40
43
|
on: 'insert.block',
|
|
41
44
|
guard: ({snapshot, event}) => {
|
|
42
|
-
const focusTextBlock =
|
|
45
|
+
const focusTextBlock = getFocusTextBlock(snapshot)
|
|
43
46
|
|
|
44
|
-
if (
|
|
45
|
-
!focusTextBlock ||
|
|
46
|
-
!utils.isTextBlock(snapshot.context, event.block)
|
|
47
|
-
) {
|
|
47
|
+
if (!focusTextBlock || !isTextBlock(snapshot.context, event.block)) {
|
|
48
48
|
return false
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -77,7 +77,7 @@ const oneLineBehaviors = [
|
|
|
77
77
|
on: 'insert.blocks',
|
|
78
78
|
guard: ({snapshot, event}) => {
|
|
79
79
|
const textBlocks = event.blocks.filter((block) =>
|
|
80
|
-
|
|
80
|
+
isTextBlock(snapshot.context, block),
|
|
81
81
|
)
|
|
82
82
|
|
|
83
83
|
if (textBlocks.length === 0) {
|
|
@@ -85,7 +85,7 @@ const oneLineBehaviors = [
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
return textBlocks.reduce((targetBlock, incomingBlock) => {
|
|
88
|
-
return
|
|
88
|
+
return mergeTextBlocks({
|
|
89
89
|
context: snapshot.context,
|
|
90
90
|
targetBlock,
|
|
91
91
|
incomingBlock,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {compileSchema, defineSchema} from '@portabletext/schema'
|
|
2
2
|
import {createTestKeyGenerator} from '@portabletext/test'
|
|
3
3
|
import {describe, expect, test} from 'vitest'
|
|
4
|
+
import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
|
|
4
5
|
import type {EditorSelection} from '../types/editor'
|
|
5
|
-
import {createTestSnapshot} from './create-test-snapshot'
|
|
6
6
|
import {getDragSelection} from './drag-selection'
|
|
7
7
|
|
|
8
8
|
describe(getDragSelection.name, () => {
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import type {EditorSnapshot} from '
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import type {EditorSnapshot} from '../editor/editor-snapshot'
|
|
2
|
+
import type {EventPosition} from '../internal-utils/event-position'
|
|
3
|
+
import {getBlockEndPoint} from '../utils/util.get-block-end-point'
|
|
4
|
+
import {getBlockStartPoint} from '../utils/util.get-block-start-point'
|
|
5
|
+
import {getFocusInlineObject} from './selector.get-focus-inline-object'
|
|
6
|
+
import {getFocusSpan} from './selector.get-focus-span'
|
|
7
|
+
import {getFocusTextBlock} from './selector.get-focus-text-block'
|
|
8
|
+
import {getSelectedBlocks} from './selector.get-selected-blocks'
|
|
9
|
+
import {getSelectionEndBlock} from './selector.get-selection-end-block'
|
|
10
|
+
import {getSelectionStartBlock} from './selector.get-selection-start-block'
|
|
11
|
+
import {isOverlappingSelection} from './selector.is-overlapping-selection'
|
|
12
|
+
import {isSelectionCollapsed} from './selector.is-selection-collapsed'
|
|
13
|
+
import {isSelectionExpanded} from './selector.is-selection-expanded'
|
|
5
14
|
|
|
6
15
|
/**
|
|
7
16
|
* Given the current editor `snapshot` and an `eventSelection` representing
|
|
@@ -17,7 +26,7 @@ export function getDragSelection({
|
|
|
17
26
|
}) {
|
|
18
27
|
let dragSelection = eventSelection
|
|
19
28
|
|
|
20
|
-
const draggedInlineObject =
|
|
29
|
+
const draggedInlineObject = getFocusInlineObject({
|
|
21
30
|
...snapshot,
|
|
22
31
|
context: {
|
|
23
32
|
...snapshot.context,
|
|
@@ -29,21 +38,21 @@ export function getDragSelection({
|
|
|
29
38
|
return dragSelection
|
|
30
39
|
}
|
|
31
40
|
|
|
32
|
-
const draggingCollapsedSelection =
|
|
41
|
+
const draggingCollapsedSelection = isSelectionCollapsed({
|
|
33
42
|
...snapshot,
|
|
34
43
|
context: {
|
|
35
44
|
...snapshot.context,
|
|
36
45
|
selection: eventSelection,
|
|
37
46
|
},
|
|
38
47
|
})
|
|
39
|
-
const draggedTextBlock =
|
|
48
|
+
const draggedTextBlock = getFocusTextBlock({
|
|
40
49
|
...snapshot,
|
|
41
50
|
context: {
|
|
42
51
|
...snapshot.context,
|
|
43
52
|
selection: eventSelection,
|
|
44
53
|
},
|
|
45
54
|
})
|
|
46
|
-
const draggedSpan =
|
|
55
|
+
const draggedSpan = getFocusSpan({
|
|
47
56
|
...snapshot,
|
|
48
57
|
context: {
|
|
49
58
|
...snapshot.context,
|
|
@@ -55,43 +64,41 @@ export function getDragSelection({
|
|
|
55
64
|
// Looks like we are dragging an empty span
|
|
56
65
|
// Let's drag the entire block instead
|
|
57
66
|
dragSelection = {
|
|
58
|
-
anchor:
|
|
67
|
+
anchor: getBlockStartPoint({
|
|
59
68
|
context: snapshot.context,
|
|
60
69
|
block: draggedTextBlock,
|
|
61
70
|
}),
|
|
62
|
-
focus:
|
|
71
|
+
focus: getBlockEndPoint({
|
|
63
72
|
context: snapshot.context,
|
|
64
73
|
block: draggedTextBlock,
|
|
65
74
|
}),
|
|
66
75
|
}
|
|
67
76
|
}
|
|
68
77
|
|
|
69
|
-
const selectedBlocks =
|
|
78
|
+
const selectedBlocks = getSelectedBlocks(snapshot)
|
|
70
79
|
|
|
71
80
|
if (
|
|
72
81
|
snapshot.context.selection &&
|
|
73
|
-
|
|
82
|
+
isSelectionExpanded(snapshot) &&
|
|
74
83
|
selectedBlocks.length > 1
|
|
75
84
|
) {
|
|
76
|
-
const selectionStartBlock =
|
|
77
|
-
const selectionEndBlock =
|
|
85
|
+
const selectionStartBlock = getSelectionStartBlock(snapshot)
|
|
86
|
+
const selectionEndBlock = getSelectionEndBlock(snapshot)
|
|
78
87
|
|
|
79
88
|
if (!selectionStartBlock || !selectionEndBlock) {
|
|
80
89
|
return dragSelection
|
|
81
90
|
}
|
|
82
91
|
|
|
83
|
-
const selectionStartPoint =
|
|
92
|
+
const selectionStartPoint = getBlockStartPoint({
|
|
84
93
|
context: snapshot.context,
|
|
85
94
|
block: selectionStartBlock,
|
|
86
95
|
})
|
|
87
|
-
const selectionEndPoint =
|
|
96
|
+
const selectionEndPoint = getBlockEndPoint({
|
|
88
97
|
context: snapshot.context,
|
|
89
98
|
block: selectionEndBlock,
|
|
90
99
|
})
|
|
91
100
|
|
|
92
|
-
const eventSelectionInsideBlocks =
|
|
93
|
-
eventSelection,
|
|
94
|
-
)({
|
|
101
|
+
const eventSelectionInsideBlocks = isOverlappingSelection(eventSelection)({
|
|
95
102
|
...snapshot,
|
|
96
103
|
context: {
|
|
97
104
|
...snapshot.context,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {PortableTextBlock} from '@sanity/types'
|
|
2
2
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
3
|
-
import {getBlockKeyFromSelectionPoint} from '../selection/selection-point'
|
|
4
3
|
import type {BlockPath} from '../types/paths'
|
|
4
|
+
import {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @public
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {PortableTextObject, PortableTextSpan} from '@sanity/types'
|
|
2
2
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
3
|
-
import {getChildKeyFromSelectionPoint} from '../selection/selection-point'
|
|
4
3
|
import type {ChildPath} from '../types/paths'
|
|
4
|
+
import {getChildKeyFromSelectionPoint} from '../utils/util.selection-point'
|
|
5
5
|
import {getAnchorTextBlock} from './selector.get-anchor-text-block'
|
|
6
6
|
|
|
7
7
|
/**
|