@portabletext/editor 1.44.14 → 1.44.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.44.14",
3
+ "version": "1.44.15",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -91,7 +91,7 @@
91
91
  "@testing-library/jest-dom": "^6.6.3",
92
92
  "@testing-library/react": "^16.3.0",
93
93
  "@types/debug": "^4.1.12",
94
- "@types/lodash": "^4.17.13",
94
+ "@types/lodash": "^4.17.16",
95
95
  "@types/lodash.startcase": "^4.4.9",
96
96
  "@types/react": "^19.1.0",
97
97
  "@types/react-dom": "^19.1.1",
@@ -1,5 +1,7 @@
1
+ import type {ConverterEvent} from '../converters/converter.types'
1
2
  import {isTextBlock} from '../internal-utils/parse-blocks'
2
3
  import * as selectors from '../selectors'
4
+ import type {PickFromUnion} from '../type-utils'
3
5
  import {getTextBlockText} from '../utils'
4
6
  import {abstractAnnotationBehaviors} from './behavior.abstract.annotation'
5
7
  import {abstractDecoratorBehaviors} from './behavior.abstract.decorator'
@@ -15,44 +17,44 @@ import {defineBehavior} from './behavior.types.behavior'
15
17
  const raiseDeserializationSuccessOrFailure = defineBehavior({
16
18
  on: 'deserialize',
17
19
  guard: ({snapshot, event}) => {
18
- const deserializeEvents = snapshot.context.converters.flatMap(
19
- (converter) => {
20
- const data = event.originEvent.originEvent.dataTransfer.getData(
21
- converter.mimeType,
22
- )
20
+ let success:
21
+ | PickFromUnion<ConverterEvent, 'type', 'deserialization.success'>
22
+ | undefined
23
+ const failures: Array<
24
+ PickFromUnion<ConverterEvent, 'type', 'deserialization.failure'>
25
+ > = []
23
26
 
24
- if (!data) {
25
- return []
26
- }
27
+ for (const converter of snapshot.context.converters) {
28
+ const data = event.originEvent.originEvent.dataTransfer.getData(
29
+ converter.mimeType,
30
+ )
27
31
 
28
- return [
29
- converter.deserialize({
30
- snapshot,
31
- event: {type: 'deserialize', data},
32
- }),
33
- ]
34
- },
35
- )
32
+ if (!data) {
33
+ continue
34
+ }
36
35
 
37
- const firstSuccess = deserializeEvents.find(
38
- (deserializeEvent) => deserializeEvent.type === 'deserialization.success',
39
- )
36
+ const deserializeEvent = converter.deserialize({
37
+ snapshot,
38
+ event: {type: 'deserialize', data},
39
+ })
40
+
41
+ if (deserializeEvent.type === 'deserialization.success') {
42
+ success = deserializeEvent
43
+ break
44
+ } else {
45
+ failures.push(deserializeEvent)
46
+ }
47
+ }
40
48
 
41
- if (!firstSuccess) {
49
+ if (!success) {
42
50
  return {
43
51
  type: 'deserialization.failure',
44
52
  mimeType: '*/*',
45
- reason: deserializeEvents
46
- .map((deserializeEvent) =>
47
- deserializeEvent.type === 'deserialization.failure'
48
- ? deserializeEvent.reason
49
- : '',
50
- )
51
- .join(', '),
53
+ reason: failures.map((failure) => failure.reason).join(', '),
52
54
  } as const
53
55
  }
54
56
 
55
- return firstSuccess
57
+ return success
56
58
  },
57
59
  actions: [
58
60
  ({event}, deserializeEvent) => [