@portabletext/editor 1.57.3 → 1.57.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.get-text-before.cjs +3 -3
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +114 -114
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/{selector.get-focus-span.cjs → selector.is-selection-expanded.cjs} +25 -25
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -0
- package/lib/_chunks-es/selector.get-text-before.js +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +93 -93
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/{selector.get-focus-span.js → selector.is-selection-expanded.js} +26 -26
- package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -0
- package/lib/index.cjs +130 -135
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +95 -100
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +16 -16
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.js +1 -1
- package/lib/selectors/index.cjs +14 -14
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.js +2 -2
- package/package.json +8 -8
- package/src/editor/Editable.tsx +1 -1
- package/src/editor/editor-dom.ts +1 -1
- package/src/editor/plugins/createWithEditableAPI.ts +1 -1
- package/src/editor/range-decorations-machine.ts +2 -1
- package/src/internal-utils/__tests__/ranges.test.ts +1 -1
- package/src/internal-utils/move-range-by-operation.ts +19 -0
- package/src/internal-utils/{ranges.test.ts → to-slate-range.test.ts} +101 -1
- package/src/internal-utils/to-slate-range.ts +171 -0
- package/src/operations/behavior.operation.block.set.ts +1 -1
- package/src/operations/behavior.operation.block.unset.ts +1 -1
- package/src/operations/behavior.operation.child.set.ts +1 -1
- package/src/operations/behavior.operation.child.unset.ts +1 -1
- package/src/operations/behavior.operation.decorator.add.ts +1 -1
- package/src/operations/behavior.operation.delete.ts +1 -1
- package/src/operations/behavior.operation.move.block.ts +34 -28
- package/src/operations/behavior.operation.select.ts +1 -1
- package/src/selectors/selector.get-mark-state.ts +3 -1
- package/lib/_chunks-cjs/selector.get-focus-span.cjs.map +0 -1
- package/lib/_chunks-es/selector.get-focus-span.js.map +0 -1
- package/src/internal-utils/paths.ts +0 -110
- package/src/internal-utils/ranges.ts +0 -70
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import type {Path} from 'slate'
|
|
2
|
-
import type {
|
|
3
|
-
EditorContext,
|
|
4
|
-
EditorSelectionPoint,
|
|
5
|
-
EditorSnapshot,
|
|
6
|
-
PortableTextBlock,
|
|
7
|
-
PortableTextObject,
|
|
8
|
-
PortableTextSpan,
|
|
9
|
-
} from '..'
|
|
10
|
-
import {
|
|
11
|
-
getBlockKeyFromSelectionPoint,
|
|
12
|
-
getChildKeyFromSelectionPoint,
|
|
13
|
-
} from '../selection/selection-point'
|
|
14
|
-
import {isSpan, isTextBlock} from './parse-blocks'
|
|
15
|
-
|
|
16
|
-
export function toSlatePath(
|
|
17
|
-
snapshot: {
|
|
18
|
-
context: Pick<EditorContext, 'schema' | 'value'>
|
|
19
|
-
} & Pick<EditorSnapshot, 'blockIndexMap'>,
|
|
20
|
-
path: EditorSelectionPoint['path'],
|
|
21
|
-
): {
|
|
22
|
-
block: PortableTextBlock | undefined
|
|
23
|
-
child: PortableTextSpan | PortableTextObject | undefined
|
|
24
|
-
path: Path
|
|
25
|
-
} {
|
|
26
|
-
const blockKey = getBlockKeyFromSelectionPoint({
|
|
27
|
-
path,
|
|
28
|
-
offset: 0,
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
if (!blockKey) {
|
|
32
|
-
return {
|
|
33
|
-
block: undefined,
|
|
34
|
-
child: undefined,
|
|
35
|
-
path: [],
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const blockIndex = snapshot.blockIndexMap.get(blockKey)
|
|
40
|
-
|
|
41
|
-
if (blockIndex === undefined) {
|
|
42
|
-
return {
|
|
43
|
-
block: undefined,
|
|
44
|
-
child: undefined,
|
|
45
|
-
path: [],
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const block = snapshot.context.value.at(blockIndex)
|
|
50
|
-
|
|
51
|
-
if (!block) {
|
|
52
|
-
return {
|
|
53
|
-
block: undefined,
|
|
54
|
-
child: undefined,
|
|
55
|
-
path: [],
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (!isTextBlock(snapshot.context, block)) {
|
|
60
|
-
return {
|
|
61
|
-
block,
|
|
62
|
-
child: undefined,
|
|
63
|
-
path: [blockIndex, 0],
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const childKey = getChildKeyFromSelectionPoint({
|
|
68
|
-
path,
|
|
69
|
-
offset: 0,
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
if (!childKey) {
|
|
73
|
-
return {
|
|
74
|
-
block,
|
|
75
|
-
child: undefined,
|
|
76
|
-
path: [blockIndex, 0],
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
let childPath: Array<number> = []
|
|
81
|
-
let childIndex = -1
|
|
82
|
-
let pathChild: PortableTextSpan | PortableTextObject | undefined = undefined
|
|
83
|
-
|
|
84
|
-
for (const child of block.children) {
|
|
85
|
-
childIndex++
|
|
86
|
-
if (child._key === childKey) {
|
|
87
|
-
pathChild = child
|
|
88
|
-
if (isSpan(snapshot.context, child)) {
|
|
89
|
-
childPath = [childIndex]
|
|
90
|
-
} else {
|
|
91
|
-
childPath = [childIndex, 0]
|
|
92
|
-
}
|
|
93
|
-
break
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (childPath.length === 0) {
|
|
98
|
-
return {
|
|
99
|
-
block,
|
|
100
|
-
child: undefined,
|
|
101
|
-
path: [blockIndex, 0],
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return {
|
|
106
|
-
block,
|
|
107
|
-
child: pathChild,
|
|
108
|
-
path: [blockIndex].concat(childPath),
|
|
109
|
-
}
|
|
110
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import {Point, type Operation, type Range} from 'slate'
|
|
2
|
-
import type {EditorContext, EditorSnapshot} from '../editor/editor-snapshot'
|
|
3
|
-
import {isSpan} from './parse-blocks'
|
|
4
|
-
import {toSlatePath} from './paths'
|
|
5
|
-
|
|
6
|
-
export function toSlateRange(
|
|
7
|
-
snapshot: {
|
|
8
|
-
context: Pick<EditorContext, 'schema' | 'value' | 'selection'>
|
|
9
|
-
} & Pick<EditorSnapshot, 'blockIndexMap'>,
|
|
10
|
-
): Range | null {
|
|
11
|
-
if (!snapshot.context.selection) {
|
|
12
|
-
return null
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const anchorPath = toSlatePath(
|
|
16
|
-
snapshot,
|
|
17
|
-
snapshot.context.selection.anchor.path,
|
|
18
|
-
)
|
|
19
|
-
const focusPath = toSlatePath(snapshot, snapshot.context.selection.focus.path)
|
|
20
|
-
|
|
21
|
-
if (anchorPath.path.length === 0 || focusPath.path.length === 0) {
|
|
22
|
-
return null
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const anchorOffset = anchorPath.child
|
|
26
|
-
? isSpan(snapshot.context, anchorPath.child)
|
|
27
|
-
? Math.min(
|
|
28
|
-
anchorPath.child.text.length,
|
|
29
|
-
snapshot.context.selection.anchor.offset,
|
|
30
|
-
)
|
|
31
|
-
: 0
|
|
32
|
-
: 0
|
|
33
|
-
const focusOffset = focusPath.child
|
|
34
|
-
? isSpan(snapshot.context, focusPath.child)
|
|
35
|
-
? Math.min(
|
|
36
|
-
focusPath.child.text.length,
|
|
37
|
-
snapshot.context.selection.focus.offset,
|
|
38
|
-
)
|
|
39
|
-
: 0
|
|
40
|
-
: 0
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
anchor: {
|
|
44
|
-
path: anchorPath.path,
|
|
45
|
-
offset: anchorOffset,
|
|
46
|
-
},
|
|
47
|
-
focus: {
|
|
48
|
-
path: focusPath.path,
|
|
49
|
-
offset: focusOffset,
|
|
50
|
-
},
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function moveRangeByOperation(
|
|
55
|
-
range: Range,
|
|
56
|
-
operation: Operation,
|
|
57
|
-
): Range | null {
|
|
58
|
-
const anchor = Point.transform(range.anchor, operation)
|
|
59
|
-
const focus = Point.transform(range.focus, operation)
|
|
60
|
-
|
|
61
|
-
if (anchor === null || focus === null) {
|
|
62
|
-
return null
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (Point.equals(anchor, range.anchor) && Point.equals(focus, range.focus)) {
|
|
66
|
-
return range
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return {anchor, focus}
|
|
70
|
-
}
|