@portabletext/editor 2.7.2 → 2.8.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.
Files changed (50) hide show
  1. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +3 -1
  2. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
  3. package/lib/_chunks-cjs/util.slice-blocks.cjs +60 -6
  4. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
  5. package/lib/_chunks-dts/behavior.types.action.d.cts +95 -95
  6. package/lib/_chunks-dts/behavior.types.action.d.ts +95 -95
  7. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +4 -2
  8. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
  9. package/lib/_chunks-es/util.slice-blocks.js +56 -5
  10. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  11. package/lib/index.cjs +94 -121
  12. package/lib/index.cjs.map +1 -1
  13. package/lib/index.js +90 -118
  14. package/lib/index.js.map +1 -1
  15. package/lib/plugins/index.d.cts +3 -3
  16. package/lib/plugins/index.d.ts +3 -3
  17. package/lib/selectors/index.d.cts +13 -3
  18. package/lib/selectors/index.d.ts +13 -3
  19. package/lib/utils/index.d.ts +2 -2
  20. package/package.json +13 -14
  21. package/src/behaviors/behavior.abstract.insert.ts +58 -1
  22. package/src/behaviors/behavior.core.annotations.ts +24 -2
  23. package/src/behaviors/behavior.core.ts +1 -1
  24. package/src/behaviors/behavior.types.event.ts +18 -18
  25. package/src/converters/converter.text-html.serialize.test.ts +27 -17
  26. package/src/converters/converter.text-plain.test.ts +1 -1
  27. package/src/editor/plugins/createWithEditableAPI.ts +16 -0
  28. package/src/internal-utils/parse-blocks.ts +2 -1
  29. package/src/operations/behavior.operation.annotation.add.ts +1 -12
  30. package/src/operations/behavior.operations.ts +0 -18
  31. package/src/selectors/selector.is-active-annotation.test.ts +320 -0
  32. package/src/selectors/selector.is-active-annotation.ts +24 -0
  33. package/src/utils/util.slice-blocks.test.ts +39 -5
  34. package/src/utils/util.slice-blocks.ts +36 -3
  35. package/src/editor/__tests__/PortableTextEditor.test.tsx +0 -430
  36. package/src/editor/__tests__/PortableTextEditorTester.tsx +0 -58
  37. package/src/editor/__tests__/RangeDecorations.test.tsx +0 -213
  38. package/src/editor/__tests__/insert-block.test.tsx +0 -224
  39. package/src/editor/__tests__/self-solving.test.tsx +0 -183
  40. package/src/editor/plugins/__tests__/withEditableAPIDelete.test.tsx +0 -298
  41. package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +0 -177
  42. package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +0 -538
  43. package/src/editor/plugins/__tests__/withEditableAPISelectionsOverlapping.test.tsx +0 -162
  44. package/src/editor/plugins/__tests__/withPortableTextLists.test.tsx +0 -65
  45. package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +0 -612
  46. package/src/editor/plugins/__tests__/withPortableTextSelections.test.tsx +0 -103
  47. package/src/editor/plugins/__tests__/withUndoRedo.test.tsx +0 -147
  48. package/src/internal-utils/__tests__/valueNormalization.test.tsx +0 -79
  49. package/src/operations/behavior.operation.insert-inline-object.ts +0 -59
  50. package/src/operations/behavior.operation.insert-span.ts +0 -48
@@ -1,162 +0,0 @@
1
- import {createTestKeyGenerator} from '@portabletext/test'
2
- import type {PortableTextBlock} from '@sanity/types'
3
- import {render, waitFor} from '@testing-library/react'
4
- import {createRef, type RefObject} from 'react'
5
- import {describe, expect, it, vi} from 'vitest'
6
- import {PortableTextEditorTester} from '../../__tests__/PortableTextEditorTester'
7
- import {PortableTextEditor} from '../../PortableTextEditor'
8
-
9
- const INITIAL_VALUE: PortableTextBlock[] = [
10
- {
11
- _key: 'a',
12
- _type: 'block',
13
- children: [
14
- {
15
- _key: 'a1',
16
- _type: 'span',
17
- marks: [],
18
- text: 'This is some text in the block',
19
- },
20
- ],
21
- markDefs: [],
22
- style: 'normal',
23
- },
24
- ]
25
-
26
- describe('plugin:withEditableAPI: .isSelectionsOverlapping', () => {
27
- it('returns true if the selections are partially overlapping', async () => {
28
- const editorRef: RefObject<PortableTextEditor | null> = createRef()
29
- const onChange = vi.fn()
30
- render(
31
- <PortableTextEditorTester
32
- keyGenerator={createTestKeyGenerator()}
33
- onChange={onChange}
34
- ref={editorRef}
35
- value={INITIAL_VALUE}
36
- />,
37
- )
38
- const selectionA = {
39
- focus: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 4},
40
- anchor: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 8},
41
- }
42
-
43
- const selectionB = {
44
- focus: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 2},
45
- anchor: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 6},
46
- }
47
-
48
- await waitFor(() => {
49
- if (editorRef.current) {
50
- const isOverlapping = PortableTextEditor.isSelectionsOverlapping(
51
- editorRef.current,
52
- selectionA,
53
- selectionB,
54
- )
55
-
56
- expect(isOverlapping).toBe(true)
57
- }
58
- })
59
- })
60
-
61
- it('returns true if the selections are fully overlapping', async () => {
62
- const editorRef: RefObject<PortableTextEditor | null> = createRef()
63
- const onChange = vi.fn()
64
- render(
65
- <PortableTextEditorTester
66
- keyGenerator={createTestKeyGenerator()}
67
- onChange={onChange}
68
- ref={editorRef}
69
- value={INITIAL_VALUE}
70
- />,
71
- )
72
- const selectionA = {
73
- focus: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 4},
74
- anchor: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 8},
75
- }
76
-
77
- const selectionB = {
78
- focus: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 4},
79
- anchor: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 8},
80
- }
81
-
82
- await waitFor(() => {
83
- if (editorRef.current) {
84
- const isOverlapping = PortableTextEditor.isSelectionsOverlapping(
85
- editorRef.current,
86
- selectionA,
87
- selectionB,
88
- )
89
-
90
- expect(isOverlapping).toBe(true)
91
- }
92
- })
93
- })
94
-
95
- it('return true if selection is fully inside another selection', async () => {
96
- const editorRef: RefObject<PortableTextEditor | null> = createRef()
97
- const onChange = vi.fn()
98
- render(
99
- <PortableTextEditorTester
100
- keyGenerator={createTestKeyGenerator()}
101
- onChange={onChange}
102
- ref={editorRef}
103
- value={INITIAL_VALUE}
104
- />,
105
- )
106
- const selectionA = {
107
- focus: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 2},
108
- anchor: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 10},
109
- }
110
-
111
- const selectionB = {
112
- focus: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 4},
113
- anchor: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 6},
114
- }
115
-
116
- await waitFor(() => {
117
- if (editorRef.current) {
118
- const isOverlapping = PortableTextEditor.isSelectionsOverlapping(
119
- editorRef.current,
120
- selectionA,
121
- selectionB,
122
- )
123
-
124
- expect(isOverlapping).toBe(true)
125
- }
126
- })
127
- })
128
-
129
- it('returns false if the selections are not overlapping', async () => {
130
- const editorRef: RefObject<PortableTextEditor | null> = createRef()
131
- const onChange = vi.fn()
132
- render(
133
- <PortableTextEditorTester
134
- keyGenerator={createTestKeyGenerator()}
135
- onChange={onChange}
136
- ref={editorRef}
137
- value={INITIAL_VALUE}
138
- />,
139
- )
140
- const selectionA = {
141
- focus: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 4},
142
- anchor: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 8},
143
- }
144
-
145
- const selectionB = {
146
- focus: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 10},
147
- anchor: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 12},
148
- }
149
-
150
- await waitFor(() => {
151
- if (editorRef.current) {
152
- const isOverlapping = PortableTextEditor.isSelectionsOverlapping(
153
- editorRef.current,
154
- selectionA,
155
- selectionB,
156
- )
157
-
158
- expect(isOverlapping).toBe(false)
159
- }
160
- })
161
- })
162
- })
@@ -1,65 +0,0 @@
1
- import {createTestKeyGenerator} from '@portabletext/test'
2
- import {render, waitFor} from '@testing-library/react'
3
- import {createRef, type RefObject} from 'react'
4
- import {describe, expect, it, vi} from 'vitest'
5
- import {PortableTextEditorTester} from '../../__tests__/PortableTextEditorTester'
6
- import {PortableTextEditor} from '../../PortableTextEditor'
7
-
8
- describe('plugin:withPortableTextLists', () => {
9
- it('should return active list styles that cover the whole selection', async () => {
10
- const editorRef: RefObject<PortableTextEditor | null> = createRef()
11
- const initialValue = [
12
- {
13
- _key: 'a',
14
- _type: 'block',
15
- children: [
16
- {
17
- _key: 'a1',
18
- _type: 'span',
19
- marks: [],
20
- text: '12',
21
- },
22
- ],
23
- markDefs: [],
24
- style: 'normal',
25
- },
26
- {
27
- _key: 'b',
28
- _type: 'block',
29
- children: [
30
- {
31
- _key: '2',
32
- _type: 'span',
33
- marks: [],
34
- text: '34',
35
- level: 1,
36
- listItem: 'bullet',
37
- },
38
- ],
39
- markDefs: [],
40
- style: 'normal',
41
- },
42
- ]
43
- const onChange = vi.fn()
44
- await waitFor(() => {
45
- render(
46
- <PortableTextEditorTester
47
- keyGenerator={createTestKeyGenerator()}
48
- onChange={onChange}
49
- ref={editorRef}
50
- value={initialValue}
51
- />,
52
- )
53
- })
54
- const editor = editorRef.current!
55
- expect(editor).toBeDefined()
56
- await waitFor(() => {
57
- PortableTextEditor.focus(editor)
58
- PortableTextEditor.select(editor, {
59
- focus: {path: [{_key: 'a'}, 'children', {_key: 'a1'}], offset: 0},
60
- anchor: {path: [{_key: '2'}, 'children', {_key: '2'}], offset: 2},
61
- })
62
- expect(PortableTextEditor.hasListStyle(editor, 'bullet')).toBe(false)
63
- })
64
- })
65
- })