@portabletext/editor 1.42.0 → 1.43.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/editor-provider.cjs +522 -418
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-active-style.cjs +14 -0
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +2 -2
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +527 -423
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/selector.is-active-style.js +15 -1
- package/lib/_chunks-es/selector.is-active-style.js.map +1 -1
- package/lib/_chunks-es/selector.is-overlapping-selection.js +2 -2
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
- package/lib/behaviors/index.d.cts +11 -11
- package/lib/behaviors/index.d.ts +11 -11
- package/lib/index.d.cts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/plugins/index.d.cts +1 -1
- package/lib/plugins/index.d.ts +1 -1
- package/lib/selectors/index.cjs +3 -8
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +1 -1
- package/lib/selectors/index.d.ts +1 -1
- package/lib/selectors/index.js +5 -11
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.d.cts +1 -1
- package/lib/utils/index.d.ts +1 -1
- package/package.json +7 -7
- package/src/behavior-actions/behavior.actions.ts +6 -0
- package/src/behaviors/behavior.default.ts +67 -1
- package/src/behaviors/behavior.perform-event.ts +266 -0
- package/src/editor/editor-machine.ts +31 -254
- package/src/editor/with-applying-behavior-actions.ts +13 -4
- package/src/internal-utils/parse-blocks.ts +14 -0
- package/src/plugins/plugin.markdown.test.tsx +64 -0
- package/src/selectors/selector.get-active-annotations.test.ts +28 -0
- package/src/selectors/selector.get-active-annotations.ts +15 -2
|
@@ -96,6 +96,20 @@ test(getActiveAnnotations.name, () => {
|
|
|
96
96
|
}),
|
|
97
97
|
),
|
|
98
98
|
).toEqual([link, comment])
|
|
99
|
+
expect(
|
|
100
|
+
getActiveAnnotations(
|
|
101
|
+
snapshot([block], {
|
|
102
|
+
anchor: {
|
|
103
|
+
path: [{_key: 'k0'}, 'children', {_key: 'k3'}],
|
|
104
|
+
offset: 0,
|
|
105
|
+
},
|
|
106
|
+
focus: {
|
|
107
|
+
path: [{_key: 'k0'}, 'children', {_key: 'k3'}],
|
|
108
|
+
offset: 0,
|
|
109
|
+
},
|
|
110
|
+
}),
|
|
111
|
+
),
|
|
112
|
+
).toEqual([])
|
|
99
113
|
expect(
|
|
100
114
|
getActiveAnnotations(
|
|
101
115
|
snapshot([block], {
|
|
@@ -110,4 +124,18 @@ test(getActiveAnnotations.name, () => {
|
|
|
110
124
|
}),
|
|
111
125
|
),
|
|
112
126
|
).toEqual([comment])
|
|
127
|
+
expect(
|
|
128
|
+
getActiveAnnotations(
|
|
129
|
+
snapshot([block], {
|
|
130
|
+
anchor: {
|
|
131
|
+
path: [{_key: 'k0'}, 'children', {_key: 'k3'}],
|
|
132
|
+
offset: 3,
|
|
133
|
+
},
|
|
134
|
+
focus: {
|
|
135
|
+
path: [{_key: 'k0'}, 'children', {_key: 'k3'}],
|
|
136
|
+
offset: 3,
|
|
137
|
+
},
|
|
138
|
+
}),
|
|
139
|
+
),
|
|
140
|
+
).toEqual([])
|
|
113
141
|
})
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {isPortableTextTextBlock, type PortableTextObject} from '@sanity/types'
|
|
2
2
|
import type {EditorSelector} from '../editor/editor-selector'
|
|
3
3
|
import {getSelectedSpans} from './selector.get-selected-spans'
|
|
4
|
-
import {
|
|
4
|
+
import {isSelectionCollapsed} from './selector.is-selection-collapsed'
|
|
5
|
+
import {getFocusSpan, getSelectedBlocks} from './selectors'
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @public
|
|
@@ -15,11 +16,23 @@ export const getActiveAnnotations: EditorSelector<Array<PortableTextObject>> = (
|
|
|
15
16
|
|
|
16
17
|
const selectedBlocks = getSelectedBlocks(snapshot)
|
|
17
18
|
const selectedSpans = getSelectedSpans(snapshot)
|
|
19
|
+
const focusSpan = getFocusSpan(snapshot)
|
|
18
20
|
|
|
19
|
-
if (selectedSpans.length === 0) {
|
|
21
|
+
if (selectedSpans.length === 0 || !focusSpan) {
|
|
20
22
|
return []
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
if (selectedSpans.length === 1 && isSelectionCollapsed(snapshot)) {
|
|
26
|
+
if (snapshot.context.selection.focus.offset === 0) {
|
|
27
|
+
return []
|
|
28
|
+
}
|
|
29
|
+
if (
|
|
30
|
+
snapshot.context.selection.focus.offset === focusSpan.node.text.length
|
|
31
|
+
) {
|
|
32
|
+
return []
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
23
36
|
const selectionMarkDefs = selectedBlocks.flatMap((block) =>
|
|
24
37
|
isPortableTextTextBlock(block.node) ? (block.node.markDefs ?? []) : [],
|
|
25
38
|
)
|