@portabletext/editor 2.13.2 → 2.13.4
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 +270 -270
- package/lib/_chunks-dts/behavior.types.action.d.ts +273 -273
- 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 +429 -363
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +225 -159
- 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.d.cts +4 -1
- package/lib/selectors/index.d.ts +4 -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 +12 -12
- 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 +18 -78
- 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/editor/validate-selection-machine.test.ts +47 -0
- package/src/editor/validate-selection-machine.ts +149 -0
- 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/index.ts +1 -1
- 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 +4 -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 +1 -1
- 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
|
@@ -2,8 +2,8 @@ import {compileSchema, defineSchema} from '@portabletext/schema'
|
|
|
2
2
|
import {createTestKeyGenerator} from '@portabletext/test'
|
|
3
3
|
import type {PortableTextBlock, PortableTextTextBlock} from '@sanity/types'
|
|
4
4
|
import {describe, expect, test} from 'vitest'
|
|
5
|
-
import {getSelectedValue} from '.'
|
|
6
5
|
import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
|
|
6
|
+
import {getSelectedValue} from './selector.get-selected-value'
|
|
7
7
|
|
|
8
8
|
const b1: PortableTextTextBlock = {
|
|
9
9
|
_type: 'block',
|
|
@@ -73,6 +73,7 @@ const b4: PortableTextTextBlock = {
|
|
|
73
73
|
|
|
74
74
|
const schema = compileSchema(
|
|
75
75
|
defineSchema({
|
|
76
|
+
decorators: [{name: 'strong'}],
|
|
76
77
|
blockObjects: [{name: 'image'}],
|
|
77
78
|
inlineObjects: [{name: 'stock-ticker'}],
|
|
78
79
|
}),
|
|
@@ -745,4 +746,89 @@ describe(getSelectedValue.name, () => {
|
|
|
745
746
|
},
|
|
746
747
|
])
|
|
747
748
|
})
|
|
749
|
+
|
|
750
|
+
test('starts and ends in different blocks with same span _key', () => {
|
|
751
|
+
const keyGenerator = createTestKeyGenerator()
|
|
752
|
+
const blockKey = keyGenerator()
|
|
753
|
+
const spanAKey = keyGenerator()
|
|
754
|
+
const spanBKey = keyGenerator()
|
|
755
|
+
const spanCKey = keyGenerator()
|
|
756
|
+
const blockBKey = keyGenerator()
|
|
757
|
+
const value = [
|
|
758
|
+
{
|
|
759
|
+
_type: 'block',
|
|
760
|
+
_key: blockKey,
|
|
761
|
+
children: [
|
|
762
|
+
{
|
|
763
|
+
_type: 'span',
|
|
764
|
+
_key: spanAKey,
|
|
765
|
+
text: 'foo ',
|
|
766
|
+
marks: [],
|
|
767
|
+
},
|
|
768
|
+
{
|
|
769
|
+
_type: 'span',
|
|
770
|
+
_key: spanBKey,
|
|
771
|
+
text: 'bar',
|
|
772
|
+
marks: ['strong'],
|
|
773
|
+
},
|
|
774
|
+
{
|
|
775
|
+
_type: 'span',
|
|
776
|
+
_key: spanCKey,
|
|
777
|
+
text: ' baz',
|
|
778
|
+
marks: [],
|
|
779
|
+
},
|
|
780
|
+
],
|
|
781
|
+
markDefs: [],
|
|
782
|
+
style: 'normal',
|
|
783
|
+
},
|
|
784
|
+
{
|
|
785
|
+
_type: 'block',
|
|
786
|
+
_key: blockBKey,
|
|
787
|
+
children: [
|
|
788
|
+
{_type: 'span', _key: spanAKey, text: 'fizz buzz', marks: []},
|
|
789
|
+
],
|
|
790
|
+
markDefs: [],
|
|
791
|
+
style: 'normal',
|
|
792
|
+
},
|
|
793
|
+
]
|
|
794
|
+
const selection = {
|
|
795
|
+
anchor: {
|
|
796
|
+
path: [
|
|
797
|
+
{
|
|
798
|
+
_key: blockBKey,
|
|
799
|
+
},
|
|
800
|
+
'children',
|
|
801
|
+
{
|
|
802
|
+
_key: spanAKey,
|
|
803
|
+
},
|
|
804
|
+
],
|
|
805
|
+
offset: 9,
|
|
806
|
+
},
|
|
807
|
+
focus: {
|
|
808
|
+
path: [
|
|
809
|
+
{
|
|
810
|
+
_key: blockKey,
|
|
811
|
+
},
|
|
812
|
+
'children',
|
|
813
|
+
{
|
|
814
|
+
_key: spanAKey,
|
|
815
|
+
},
|
|
816
|
+
],
|
|
817
|
+
offset: 0,
|
|
818
|
+
},
|
|
819
|
+
backward: true,
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
expect(
|
|
823
|
+
getSelectedValue(
|
|
824
|
+
createTestSnapshot({
|
|
825
|
+
context: {
|
|
826
|
+
schema,
|
|
827
|
+
value,
|
|
828
|
+
selection,
|
|
829
|
+
},
|
|
830
|
+
}),
|
|
831
|
+
),
|
|
832
|
+
).toEqual(value)
|
|
833
|
+
})
|
|
748
834
|
})
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type {PortableTextBlock} from '@sanity/types'
|
|
2
2
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
sliceBlocks,
|
|
8
|
-
} from '../utils'
|
|
3
|
+
import {getSelectionEndPoint} from '../utils/util.get-selection-end-point'
|
|
4
|
+
import {getSelectionStartPoint} from '../utils/util.get-selection-start-point'
|
|
5
|
+
import {getBlockKeyFromSelectionPoint} from '../utils/util.selection-point'
|
|
6
|
+
import {sliceBlocks} from '../utils/util.slice-blocks'
|
|
9
7
|
|
|
10
8
|
/**
|
|
11
9
|
* @public
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {compileSchema, defineSchema} from '@portabletext/schema'
|
|
2
2
|
import type {PortableTextBlock} from '@sanity/types'
|
|
3
3
|
import {expect, test} from 'vitest'
|
|
4
|
-
import type {EditorSelection} from '..'
|
|
5
4
|
import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
|
|
5
|
+
import type {EditorSelection} from '../types/editor'
|
|
6
6
|
import {getSelectionText} from './selector.get-selection-text'
|
|
7
7
|
|
|
8
8
|
const brokenBlock = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
2
|
-
import {getSelectionStartPoint} from '../utils'
|
|
3
2
|
import {getBlockStartPoint} from '../utils/util.get-block-start-point'
|
|
3
|
+
import {getSelectionStartPoint} from '../utils/util.get-selection-start-point'
|
|
4
4
|
import {getFocusBlock} from './selector.get-focus-block'
|
|
5
5
|
import {getSelectionText} from './selector.get-selection-text'
|
|
6
6
|
|
|
@@ -3,8 +3,8 @@ import {createTestKeyGenerator} from '@portabletext/test'
|
|
|
3
3
|
import type {PortableTextBlock} from '@sanity/types'
|
|
4
4
|
import {describe, expect, test} from 'vitest'
|
|
5
5
|
import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
|
|
6
|
-
import {parseBlock} from '../internal-utils/parse-blocks'
|
|
7
6
|
import type {EditorSelection} from '../types/editor'
|
|
7
|
+
import {parseBlock} from '../utils/parse-blocks'
|
|
8
8
|
import {getTrimmedSelection} from './selector.get-trimmed-selection'
|
|
9
9
|
|
|
10
10
|
const keyGenerator = createTestKeyGenerator()
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import {isSpan, isTextBlock} from '@portabletext/schema'
|
|
2
2
|
import type {PortableTextSpan} from '@sanity/types'
|
|
3
3
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
4
|
+
import type {EditorSelection, EditorSelectionPoint} from '../types/editor'
|
|
5
|
+
import {getSelectionEndPoint} from '../utils/util.get-selection-end-point'
|
|
6
|
+
import {getSelectionStartPoint} from '../utils/util.get-selection-start-point'
|
|
7
|
+
import {isEmptyTextBlock} from '../utils/util.is-empty-text-block'
|
|
4
8
|
import {
|
|
5
9
|
getBlockKeyFromSelectionPoint,
|
|
6
10
|
getChildKeyFromSelectionPoint,
|
|
7
|
-
} from '../
|
|
8
|
-
import type {EditorSelection, EditorSelectionPoint} from '../types/editor'
|
|
9
|
-
import {
|
|
10
|
-
getSelectionEndPoint,
|
|
11
|
-
getSelectionStartPoint,
|
|
12
|
-
isEmptyTextBlock,
|
|
13
|
-
} from '../utils'
|
|
11
|
+
} from '../utils/util.selection-point'
|
|
14
12
|
import {getFocusTextBlock} from './selector.get-focus-text-block'
|
|
15
13
|
import {isSelectionCollapsed} from './selector.is-selection-collapsed'
|
|
16
14
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type {PortableTextBlock} from '@portabletext/schema'
|
|
1
2
|
import {expect, test} from 'vitest'
|
|
2
|
-
import type {EditorSelection, PortableTextBlock} from '..'
|
|
3
3
|
import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
|
|
4
|
+
import type {EditorSelection} from '../types/editor'
|
|
4
5
|
import {isActiveDecorator} from './selector.is-active-decorator'
|
|
5
6
|
|
|
6
7
|
test(isActiveDecorator.name, () => {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type {PortableTextBlock} from '@sanity/types'
|
|
2
2
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
3
3
|
import type {BlockPath} from '../types/paths'
|
|
4
|
-
import
|
|
4
|
+
import {getBlockEndPoint} from '../utils/util.get-block-end-point'
|
|
5
|
+
import {isEqualSelectionPoints} from '../utils/util.is-equal-selection-points'
|
|
5
6
|
import {isSelectionCollapsed} from './selector.is-selection-collapsed'
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -16,12 +17,12 @@ export function isAtTheEndOfBlock(block: {
|
|
|
16
17
|
return false
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
const blockEndPoint =
|
|
20
|
+
const blockEndPoint = getBlockEndPoint({
|
|
20
21
|
context: snapshot.context,
|
|
21
22
|
block,
|
|
22
23
|
})
|
|
23
24
|
|
|
24
|
-
return
|
|
25
|
+
return isEqualSelectionPoints(
|
|
25
26
|
snapshot.context.selection.focus,
|
|
26
27
|
blockEndPoint,
|
|
27
28
|
)
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type {PortableTextBlock} from '@sanity/types'
|
|
2
2
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
3
3
|
import type {BlockPath} from '../types/paths'
|
|
4
|
-
import
|
|
4
|
+
import {getBlockStartPoint} from '../utils/util.get-block-start-point'
|
|
5
|
+
import {isEqualSelectionPoints} from '../utils/util.is-equal-selection-points'
|
|
5
6
|
import {isSelectionCollapsed} from './selector.is-selection-collapsed'
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -16,12 +17,12 @@ export function isAtTheStartOfBlock(block: {
|
|
|
16
17
|
return false
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
const blockStartPoint =
|
|
20
|
+
const blockStartPoint = getBlockStartPoint({
|
|
20
21
|
context: snapshot.context,
|
|
21
22
|
block,
|
|
22
23
|
})
|
|
23
24
|
|
|
24
|
-
return
|
|
25
|
+
return isEqualSelectionPoints(
|
|
25
26
|
snapshot.context.selection.focus,
|
|
26
27
|
blockStartPoint,
|
|
27
28
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {describe, expect, test} from 'vitest'
|
|
2
|
-
import {defaultKeyGenerator} from '../editor/key-generator'
|
|
3
2
|
import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
|
|
4
3
|
import type {EditorSelection} from '../types/editor'
|
|
4
|
+
import {defaultKeyGenerator} from '../utils/key-generator'
|
|
5
5
|
import {isOverlappingSelection} from './selector.is-overlapping-selection'
|
|
6
6
|
|
|
7
7
|
function snapshot(selection: EditorSelection) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {EditorSelection} from '../types/editor'
|
|
2
|
-
import {isEqualSelectionPoints} from '../utils'
|
|
2
|
+
import {isEqualSelectionPoints} from '../utils/util.is-equal-selection-points'
|
|
3
3
|
import type {EditorSelector} from './../editor/editor-selector'
|
|
4
4
|
import {getSelectionEndPoint} from './selector.get-selection-end-point'
|
|
5
5
|
import {getSelectionStartPoint} from './selector.get-selection-start-point'
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {isTextBlock} from '@portabletext/schema'
|
|
2
2
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
3
|
+
import type {EditorSelectionPoint} from '../types/editor'
|
|
4
|
+
import {getSelectionEndPoint} from '../utils/util.get-selection-end-point'
|
|
3
5
|
import {
|
|
4
6
|
getBlockKeyFromSelectionPoint,
|
|
5
7
|
getChildKeyFromSelectionPoint,
|
|
6
|
-
} from '../
|
|
7
|
-
import type {EditorSelectionPoint} from '../types/editor'
|
|
8
|
-
import {getSelectionEndPoint} from '../utils'
|
|
8
|
+
} from '../utils/util.selection-point'
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @public
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {isTextBlock} from '@portabletext/schema'
|
|
2
2
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
3
|
+
import type {EditorSelectionPoint} from '../types/editor'
|
|
4
|
+
import {getSelectionStartPoint} from '../utils/util.get-selection-start-point'
|
|
3
5
|
import {
|
|
4
6
|
getBlockKeyFromSelectionPoint,
|
|
5
7
|
getChildKeyFromSelectionPoint,
|
|
6
|
-
} from '../
|
|
7
|
-
import type {EditorSelectionPoint} from '../types/editor'
|
|
8
|
-
import {getSelectionStartPoint} from '../utils'
|
|
8
|
+
} from '../utils/util.selection-point'
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @public
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
2
|
-
import
|
|
2
|
+
import {getBlockEndPoint} from '../utils/util.get-block-end-point'
|
|
3
|
+
import {getBlockStartPoint} from '../utils/util.get-block-start-point'
|
|
4
|
+
import {isEqualSelectionPoints} from '../utils/util.is-equal-selection-points'
|
|
3
5
|
import {getSelectionEndBlock} from './selector.get-selection-end-block'
|
|
4
6
|
import {getSelectionStartBlock} from './selector.get-selection-start-block'
|
|
5
7
|
|
|
@@ -25,17 +27,17 @@ export const isSelectingEntireBlocks: EditorSelector<boolean> = (snapshot) => {
|
|
|
25
27
|
return false
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
const startBlockStartPoint =
|
|
30
|
+
const startBlockStartPoint = getBlockStartPoint({
|
|
29
31
|
context: snapshot.context,
|
|
30
32
|
block: startBlock,
|
|
31
33
|
})
|
|
32
|
-
const endBlockEndPoint =
|
|
34
|
+
const endBlockEndPoint = getBlockEndPoint({
|
|
33
35
|
context: snapshot.context,
|
|
34
36
|
block: endBlock,
|
|
35
37
|
})
|
|
36
38
|
|
|
37
39
|
return (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
isEqualSelectionPoints(startBlockStartPoint, startPoint) &&
|
|
41
|
+
isEqualSelectionPoints(endBlockEndPoint, endPoint)
|
|
40
42
|
)
|
|
41
43
|
}
|
|
@@ -4,11 +4,6 @@ import {userEvent} from '@vitest/browser/context'
|
|
|
4
4
|
import {Given, Then, When} from 'racejar'
|
|
5
5
|
import {assert, expect, vi} from 'vitest'
|
|
6
6
|
import {getEditorSelection} from '../../internal-utils/editor-selection'
|
|
7
|
-
import {
|
|
8
|
-
parseBlocks,
|
|
9
|
-
parseInlineObject,
|
|
10
|
-
parseSpan,
|
|
11
|
-
} from '../../internal-utils/parse-blocks'
|
|
12
7
|
import {getSelectionText} from '../../internal-utils/selection-text'
|
|
13
8
|
import {getTextBlockKey} from '../../internal-utils/text-block-key'
|
|
14
9
|
import {getTextMarks} from '../../internal-utils/text-marks'
|
|
@@ -20,10 +15,13 @@ import {
|
|
|
20
15
|
import {getValueAnnotations} from '../../internal-utils/value-annotations'
|
|
21
16
|
import {createTestEditor} from '../../test/vitest'
|
|
22
17
|
import {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
} from '../../utils'
|
|
18
|
+
parseBlocks,
|
|
19
|
+
parseInlineObject,
|
|
20
|
+
parseSpan,
|
|
21
|
+
} from '../../utils/parse-blocks'
|
|
22
|
+
import {spanSelectionPointToBlockOffset} from '../../utils/util.block-offset'
|
|
23
|
+
import {reverseSelection} from '../../utils/util.reverse-selection'
|
|
24
|
+
import {selectionPointToBlockOffset} from '../../utils/util.selection-point-to-block-offset'
|
|
27
25
|
import type {Parameter} from '../gherkin-parameter-types'
|
|
28
26
|
import type {Context} from './step-context'
|
|
29
27
|
|
|
@@ -232,6 +230,12 @@ export const stepDefinitions = [
|
|
|
232
230
|
at: selection,
|
|
233
231
|
})
|
|
234
232
|
})
|
|
233
|
+
|
|
234
|
+
await vi.waitFor(() => {
|
|
235
|
+
expect(context.editor.getSnapshot().context.selection).toEqual(
|
|
236
|
+
getSelectionBeforeText(context.editor.getSnapshot().context, text),
|
|
237
|
+
)
|
|
238
|
+
})
|
|
235
239
|
},
|
|
236
240
|
),
|
|
237
241
|
Then(
|
|
@@ -264,6 +268,12 @@ export const stepDefinitions = [
|
|
|
264
268
|
at: getSelectionAfterText(context.editor.getSnapshot().context, text),
|
|
265
269
|
})
|
|
266
270
|
})
|
|
271
|
+
|
|
272
|
+
await vi.waitFor(() => {
|
|
273
|
+
expect(context.editor.getSnapshot().context.selection).toEqual(
|
|
274
|
+
getSelectionAfterText(context.editor.getSnapshot().context, text),
|
|
275
|
+
)
|
|
276
|
+
})
|
|
267
277
|
},
|
|
268
278
|
),
|
|
269
279
|
Then(
|
package/src/types/paths.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type {Path} from '@sanity/types'
|
|
2
|
-
import {isRecord} from '../internal-utils/asserters'
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* @public
|
|
@@ -21,6 +20,10 @@ export function isBlockPath(path: Path): path is BlockPath {
|
|
|
21
20
|
)
|
|
22
21
|
}
|
|
23
22
|
|
|
23
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
24
|
+
return !!value && (typeof value === 'object' || typeof value === 'function')
|
|
25
|
+
}
|
|
26
|
+
|
|
24
27
|
/**
|
|
25
28
|
* @public
|
|
26
29
|
*/
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {isTextBlock} from '@portabletext/schema'
|
|
2
2
|
import type {PortableTextBlock} from '@sanity/types'
|
|
3
3
|
import type {EditorContext} from '../editor/editor-snapshot'
|
|
4
|
-
import {getChildKeyFromSelectionPoint} from '../selection/selection-point'
|
|
5
4
|
import {isSelectionCollapsed} from './util.is-selection-collapsed'
|
|
5
|
+
import {getChildKeyFromSelectionPoint} from './util.selection-point'
|
|
6
6
|
|
|
7
7
|
export function isAtTheBeginningOfBlock({
|
|
8
8
|
context,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {isSpan, isTextBlock} from '@portabletext/schema'
|
|
2
2
|
import type {EditorContext} from '../editor/editor-snapshot'
|
|
3
|
-
import {
|
|
4
|
-
getBlockKeyFromSelectionPoint,
|
|
5
|
-
getChildKeyFromSelectionPoint,
|
|
6
|
-
} from '../selection/selection-point'
|
|
7
3
|
import type {BlockOffset} from '../types/block-offset'
|
|
8
4
|
import type {EditorSelectionPoint} from '../types/editor'
|
|
9
5
|
import type {ChildPath} from '../types/paths'
|
|
6
|
+
import {
|
|
7
|
+
getBlockKeyFromSelectionPoint,
|
|
8
|
+
getChildKeyFromSelectionPoint,
|
|
9
|
+
} from './util.selection-point'
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @public
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {EditorSelection} from '..'
|
|
2
1
|
import type {EditorContext} from '../editor/editor-snapshot'
|
|
3
2
|
import type {BlockOffset} from '../types/block-offset'
|
|
3
|
+
import type {EditorSelection} from '../types/editor'
|
|
4
4
|
import {blockOffsetToSelectionPoint} from './util.block-offset-to-selection-point'
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {isSpan, isTextBlock} from '@portabletext/schema'
|
|
2
2
|
import type {EditorContext} from '../editor/editor-snapshot'
|
|
3
|
+
import type {BlockOffset} from '../types/block-offset'
|
|
4
|
+
import type {EditorSelectionPoint} from '../types/editor'
|
|
3
5
|
import {
|
|
4
6
|
getBlockKeyFromSelectionPoint,
|
|
5
7
|
getChildKeyFromSelectionPoint,
|
|
6
|
-
} from '
|
|
7
|
-
import type {BlockOffset} from '../types/block-offset'
|
|
8
|
-
import type {EditorSelectionPoint} from '../types/editor'
|
|
8
|
+
} from './util.selection-point'
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @public
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {isTextBlock} from '@portabletext/schema'
|
|
2
2
|
import type {PortableTextTextBlock} from '@sanity/types'
|
|
3
|
-
import type {EditorContext} from '
|
|
4
|
-
import {parseBlock} from '
|
|
3
|
+
import type {EditorContext} from '../editor/editor-snapshot'
|
|
4
|
+
import {parseBlock} from './parse-blocks'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @beta
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type {EditorContext} from '../editor/editor-snapshot'
|
|
2
|
-
import {getBlockKeyFromSelectionPoint} from '../selection/selection-point'
|
|
3
2
|
import type {BlockOffset} from '../types/block-offset'
|
|
4
3
|
import type {EditorSelectionPoint} from '../types/editor'
|
|
5
4
|
import {childSelectionPointToBlockOffset} from './util.child-selection-point-to-block-offset'
|
|
5
|
+
import {getBlockKeyFromSelectionPoint} from './util.selection-point'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @public
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {EditorSelectionPoint} from '../types/editor'
|
|
2
|
-
import {isKeyedSegment} from '
|
|
2
|
+
import {isKeyedSegment} from './util.is-keyed-segment'
|
|
3
3
|
|
|
4
4
|
export function getBlockKeyFromSelectionPoint(point: EditorSelectionPoint) {
|
|
5
5
|
const blockPathSegment = point.path.at(0)
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {isSpan, isTextBlock} from '@portabletext/schema'
|
|
2
2
|
import type {PortableTextBlock} from '@sanity/types'
|
|
3
3
|
import type {EditorContext} from '../editor/editor-snapshot'
|
|
4
|
-
import {defaultKeyGenerator} from '
|
|
5
|
-
import {parseBlock} from '
|
|
4
|
+
import {defaultKeyGenerator} from './key-generator'
|
|
5
|
+
import {parseBlock} from './parse-blocks'
|
|
6
|
+
import {getSelectionEndPoint} from './util.get-selection-end-point'
|
|
7
|
+
import {getSelectionStartPoint} from './util.get-selection-start-point'
|
|
6
8
|
import {
|
|
7
9
|
getBlockKeyFromSelectionPoint,
|
|
8
10
|
getChildKeyFromSelectionPoint,
|
|
9
|
-
} from '
|
|
10
|
-
import {getSelectionEndPoint} from '../utils/util.get-selection-end-point'
|
|
11
|
-
import {getSelectionStartPoint} from '../utils/util.get-selection-start-point'
|
|
11
|
+
} from './util.selection-point'
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* @public
|
|
@@ -80,7 +80,7 @@ export function sliceBlocks({
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
if (startChildKey === endChildKey) {
|
|
83
|
+
if (block._key === endBlockKey && startChildKey === endChildKey) {
|
|
84
84
|
break
|
|
85
85
|
}
|
|
86
86
|
continue
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import {compileSchema, defineSchema} from '@portabletext/schema'
|
|
2
|
+
import {createTestKeyGenerator} from '@portabletext/test'
|
|
2
3
|
import type {
|
|
3
4
|
PortableTextObject,
|
|
4
5
|
PortableTextSpan,
|
|
5
6
|
PortableTextTextBlock,
|
|
6
7
|
} from '@sanity/types'
|
|
7
8
|
import {describe, expect, test} from 'vitest'
|
|
8
|
-
import {keyGenerator} from '..'
|
|
9
9
|
import {sliceTextBlock} from './util.slice-text-block'
|
|
10
10
|
|
|
11
|
+
const keyGenerator = createTestKeyGenerator()
|
|
12
|
+
|
|
11
13
|
const schema = compileSchema(
|
|
12
14
|
defineSchema({
|
|
13
15
|
inlineObjects: [{name: 'stock-ticker'}],
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {isSpan} from '@portabletext/schema'
|
|
2
2
|
import type {PortableTextChild, PortableTextTextBlock} from '@sanity/types'
|
|
3
3
|
import type {EditorContext} from '../editor/editor-snapshot'
|
|
4
|
+
import {getSelectionEndPoint} from './util.get-selection-end-point'
|
|
5
|
+
import {getSelectionStartPoint} from './util.get-selection-start-point'
|
|
4
6
|
import {
|
|
5
7
|
getBlockKeyFromSelectionPoint,
|
|
6
8
|
getChildKeyFromSelectionPoint,
|
|
7
|
-
} from '
|
|
8
|
-
import {getSelectionEndPoint} from './util.get-selection-end-point'
|
|
9
|
-
import {getSelectionStartPoint} from './util.get-selection-start-point'
|
|
9
|
+
} from './util.selection-point'
|
|
10
10
|
|
|
11
11
|
export function sliceTextBlock({
|
|
12
12
|
context,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {isSpan} from '@portabletext/schema'
|
|
2
2
|
import type {PortableTextTextBlock} from '@sanity/types'
|
|
3
|
-
import type {EditorSelectionPoint} from '..'
|
|
4
3
|
import type {EditorContext} from '../editor/editor-snapshot'
|
|
4
|
+
import type {EditorSelectionPoint} from '../types/editor'
|
|
5
5
|
import {sliceTextBlock} from './util.slice-text-block'
|
|
6
6
|
|
|
7
7
|
/**
|