@portabletext/editor 1.20.0 → 1.21.0
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/behavior.core.cjs +8 -68
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +11 -39
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/util.get-block-start-point.cjs +30 -0
- package/lib/_chunks-cjs/util.get-block-start-point.cjs.map +1 -0
- package/lib/_chunks-cjs/util.is-empty-text-block.cjs +71 -0
- package/lib/_chunks-cjs/util.is-empty-text-block.cjs.map +1 -0
- package/lib/_chunks-cjs/util.is-keyed-segment.cjs +6 -0
- package/lib/_chunks-cjs/util.is-keyed-segment.cjs.map +1 -0
- package/lib/_chunks-es/behavior.core.js +7 -66
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +5 -31
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/util.get-block-start-point.js +31 -0
- package/lib/_chunks-es/util.get-block-start-point.js.map +1 -0
- package/lib/_chunks-es/util.is-empty-text-block.js +73 -0
- package/lib/_chunks-es/util.is-empty-text-block.js.map +1 -0
- package/lib/_chunks-es/util.is-keyed-segment.js +7 -0
- package/lib/_chunks-es/util.is-keyed-segment.js.map +1 -0
- package/lib/behaviors/index.cjs +7 -7
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +179 -119
- package/lib/behaviors/index.d.ts +179 -119
- package/lib/behaviors/index.js +3 -2
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +29 -6
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +844 -141
- package/lib/index.d.ts +844 -141
- package/lib/index.js +28 -4
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.cjs +73 -1
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +14 -0
- package/lib/selectors/index.d.ts +14 -0
- package/lib/selectors/index.js +73 -0
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +11 -0
- package/lib/utils/index.cjs.map +1 -0
- package/lib/utils/index.d.cts +87 -0
- package/lib/utils/index.d.ts +87 -0
- package/lib/utils/index.js +13 -0
- package/lib/utils/index.js.map +1 -0
- package/package.json +15 -9
- package/src/behavior-actions/behavior.action-utils.insert-block.ts +1 -1
- package/src/behavior-actions/behavior.action.insert-block-object.ts +1 -1
- package/src/behavior-actions/behavior.action.insert-inline-object.ts +1 -1
- package/src/behavior-actions/behavior.action.text-block.set.ts +1 -1
- package/src/behavior-actions/behavior.action.text-block.unset.ts +1 -1
- package/src/behavior-actions/behavior.actions.ts +5 -5
- package/src/behaviors/behavior.code-editor.ts +1 -1
- package/src/behaviors/behavior.core.block-objects.ts +2 -2
- package/src/behaviors/behavior.core.decorators.ts +1 -1
- package/src/behaviors/behavior.core.lists.ts +2 -2
- package/src/behaviors/behavior.emoji-picker.ts +1 -1
- package/src/behaviors/behavior.links.ts +1 -1
- package/src/behaviors/behavior.markdown.ts +2 -2
- package/src/behaviors/behavior.types.ts +52 -19
- package/src/behaviors/index.ts +1 -0
- package/src/editor/Editable.tsx +12 -12
- package/src/editor/PortableTextEditor.tsx +2 -2
- package/src/editor/components/DraggableBlock.tsx +2 -2
- package/src/editor/components/Element.tsx +3 -3
- package/src/editor/components/Leaf.tsx +1 -1
- package/src/editor/components/Synchronizer.tsx +1 -1
- package/src/editor/create-editor.ts +22 -20
- package/src/editor/create-slate-editor.tsx +5 -2
- package/src/editor/editor-machine.ts +42 -14
- package/src/editor/get-value.ts +2 -2
- package/src/editor/hooks/usePortableTextEditorSelection.tsx +1 -1
- package/src/editor/mutation-machine.ts +2 -2
- package/src/editor/plugins/create-with-event-listeners.ts +11 -3
- package/src/editor/plugins/createWithEditableAPI.ts +7 -7
- package/src/editor/plugins/createWithHotKeys.ts +2 -2
- package/src/editor/plugins/createWithInsertData.ts +7 -7
- package/src/editor/plugins/createWithMaxBlocks.ts +2 -2
- package/src/editor/plugins/createWithObjectKeys.ts +2 -2
- package/src/editor/plugins/createWithPatches.ts +10 -10
- package/src/editor/plugins/createWithPlaceholderBlock.ts +3 -3
- package/src/editor/plugins/createWithPortableTextBlockStyle.ts +1 -1
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +4 -4
- package/src/editor/plugins/createWithPortableTextSelections.ts +6 -6
- package/src/editor/plugins/createWithSchemaTypes.ts +1 -1
- package/src/editor/plugins/createWithUndoRedo.ts +5 -5
- package/src/editor/plugins/createWithUtils.ts +2 -2
- package/src/editor/plugins/with-plugins.ts +1 -1
- package/src/editor/sync-machine.ts +8 -5
- package/src/index.ts +5 -1
- package/src/selectors/index.ts +2 -0
- package/src/selectors/selector.get-selection-text.test.ts +75 -0
- package/src/selectors/selector.get-selection-text.ts +3 -3
- package/src/selectors/selector.get-text-before.ts +7 -4
- package/src/selectors/selector.is-point-after-selection.ts +82 -0
- package/src/selectors/selector.is-point-before-selection.ts +82 -0
- package/src/utils/_exports/index.ts +1 -0
- package/src/utils/index.ts +11 -0
- package/src/{editor/utils/utils.block-offset.test.ts → utils/util.block-offset.test.ts} +1 -1
- package/src/{editor/utils/utils.block-offset.ts → utils/util.block-offset.ts} +23 -7
- package/src/{editor/utils/utils.get-start-point.ts → utils/util.get-block-start-point.ts} +5 -2
- package/src/utils/util.get-text-block-text.ts +8 -0
- package/src/{editor/utils/utils.ts → utils/util.is-empty-text-block.ts} +4 -5
- package/src/{editor/utils/utils.is-keyed-segment.ts → utils/util.is-keyed-segment.ts} +3 -0
- package/src/{editor/utils/utils.reverse-selection.ts → utils/util.reverse-selection.ts} +4 -1
- /package/src/{utils → internal-utils}/__tests__/dmpToOperations.test.ts +0 -0
- /package/src/{utils → internal-utils}/__tests__/operationToPatches.test.ts +0 -0
- /package/src/{utils → internal-utils}/__tests__/patchToOperations.test.ts +0 -0
- /package/src/{utils → internal-utils}/__tests__/ranges.test.ts +0 -0
- /package/src/{utils → internal-utils}/__tests__/valueNormalization.test.tsx +0 -0
- /package/src/{utils → internal-utils}/__tests__/values.test.ts +0 -0
- /package/src/{utils → internal-utils}/applyPatch.ts +0 -0
- /package/src/{utils → internal-utils}/debug.ts +0 -0
- /package/src/{utils → internal-utils}/is-hotkey.test.ts +0 -0
- /package/src/{utils → internal-utils}/is-hotkey.ts +0 -0
- /package/src/{utils → internal-utils}/looks-like-url.test.ts +0 -0
- /package/src/{utils → internal-utils}/looks-like-url.ts +0 -0
- /package/src/{utils → internal-utils}/operationToPatches.ts +0 -0
- /package/src/{utils → internal-utils}/paths.ts +0 -0
- /package/src/{utils → internal-utils}/ranges.ts +0 -0
- /package/src/{utils → internal-utils}/schema.ts +0 -0
- /package/src/{utils → internal-utils}/selection.ts +0 -0
- /package/src/{utils → internal-utils}/sibling-utils.ts +0 -0
- /package/src/{utils → internal-utils}/validateValue.ts +0 -0
- /package/src/{utils → internal-utils}/values.ts +0 -0
- /package/src/{utils → internal-utils}/weakMaps.ts +0 -0
- /package/src/{utils → internal-utils}/withChanges.ts +0 -0
- /package/src/{utils → internal-utils}/withUndoRedo.ts +0 -0
- /package/src/{utils → internal-utils}/withoutPatching.ts +0 -0
|
@@ -4,8 +4,13 @@ import {
|
|
|
4
4
|
type KeyedSegment,
|
|
5
5
|
type PortableTextBlock,
|
|
6
6
|
} from '@sanity/types'
|
|
7
|
-
import type {BlockOffset} from '
|
|
7
|
+
import type {BlockOffset} from '../behaviors/behavior.types'
|
|
8
|
+
import type {EditorSelectionPoint} from '../types/editor'
|
|
9
|
+
import {isKeyedSegment} from './util.is-keyed-segment'
|
|
8
10
|
|
|
11
|
+
/**
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
9
14
|
export function blockOffsetToSpanSelectionPoint({
|
|
10
15
|
value,
|
|
11
16
|
blockOffset,
|
|
@@ -55,20 +60,31 @@ export function blockOffsetToSpanSelectionPoint({
|
|
|
55
60
|
return selectionPoint
|
|
56
61
|
}
|
|
57
62
|
|
|
63
|
+
/**
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
58
66
|
export function spanSelectionPointToBlockOffset({
|
|
59
67
|
value,
|
|
60
68
|
selectionPoint,
|
|
61
69
|
}: {
|
|
62
70
|
value: Array<PortableTextBlock>
|
|
63
|
-
selectionPoint:
|
|
64
|
-
path: [KeyedSegment, 'children', KeyedSegment]
|
|
65
|
-
offset: number
|
|
66
|
-
}
|
|
71
|
+
selectionPoint: EditorSelectionPoint
|
|
67
72
|
}): BlockOffset | undefined {
|
|
68
73
|
let offset = 0
|
|
69
74
|
|
|
75
|
+
const blockKey = isKeyedSegment(selectionPoint.path[0])
|
|
76
|
+
? selectionPoint.path[0]._key
|
|
77
|
+
: undefined
|
|
78
|
+
const spanKey = isKeyedSegment(selectionPoint.path[2])
|
|
79
|
+
? selectionPoint.path[2]._key
|
|
80
|
+
: undefined
|
|
81
|
+
|
|
82
|
+
if (!blockKey || !spanKey) {
|
|
83
|
+
return undefined
|
|
84
|
+
}
|
|
85
|
+
|
|
70
86
|
for (const block of value) {
|
|
71
|
-
if (block._key !==
|
|
87
|
+
if (block._key !== blockKey) {
|
|
72
88
|
continue
|
|
73
89
|
}
|
|
74
90
|
|
|
@@ -81,7 +97,7 @@ export function spanSelectionPointToBlockOffset({
|
|
|
81
97
|
continue
|
|
82
98
|
}
|
|
83
99
|
|
|
84
|
-
if (child._key ===
|
|
100
|
+
if (child._key === spanKey) {
|
|
85
101
|
return {
|
|
86
102
|
path: [{_key: block._key}],
|
|
87
103
|
offset: offset + selectionPoint.offset,
|
|
@@ -3,9 +3,12 @@ import {
|
|
|
3
3
|
type KeyedSegment,
|
|
4
4
|
type PortableTextBlock,
|
|
5
5
|
} from '@sanity/types'
|
|
6
|
-
import type {EditorSelectionPoint} from '
|
|
6
|
+
import type {EditorSelectionPoint} from '../types/editor'
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export function getBlockStartPoint({
|
|
9
12
|
node,
|
|
10
13
|
path,
|
|
11
14
|
}: {
|
|
@@ -2,9 +2,12 @@ import {
|
|
|
2
2
|
isPortableTextSpan,
|
|
3
3
|
isPortableTextTextBlock,
|
|
4
4
|
type PortableTextBlock,
|
|
5
|
-
type PortableTextTextBlock,
|
|
6
5
|
} from '@sanity/types'
|
|
6
|
+
import {getTextBlockText} from './util.get-text-block-text'
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
8
11
|
export function isEmptyTextBlock(block: PortableTextBlock) {
|
|
9
12
|
if (!isPortableTextTextBlock(block)) {
|
|
10
13
|
return false
|
|
@@ -15,7 +18,3 @@ export function isEmptyTextBlock(block: PortableTextBlock) {
|
|
|
15
18
|
|
|
16
19
|
return onlyText && blockText === ''
|
|
17
20
|
}
|
|
18
|
-
|
|
19
|
-
export function getTextBlockText(block: PortableTextTextBlock) {
|
|
20
|
-
return block.children.map((child) => child.text ?? '').join('')
|
|
21
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|