@portabletext/editor 2.7.2 → 2.8.1

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 (72) 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/selector.is-selection-expanded.cjs +10 -4
  4. package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -1
  5. package/lib/_chunks-cjs/util.merge-text-blocks.cjs +0 -1
  6. package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
  7. package/lib/_chunks-cjs/util.slice-blocks.cjs +60 -9
  8. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
  9. package/lib/_chunks-dts/behavior.types.action.d.cts +149 -149
  10. package/lib/_chunks-dts/behavior.types.action.d.ts +86 -86
  11. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +4 -2
  12. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
  13. package/lib/_chunks-es/selector.is-selection-expanded.js +10 -4
  14. package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -1
  15. package/lib/_chunks-es/util.merge-text-blocks.js +0 -1
  16. package/lib/_chunks-es/util.merge-text-blocks.js.map +1 -1
  17. package/lib/_chunks-es/util.slice-blocks.js +56 -8
  18. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  19. package/lib/index.cjs +94 -131
  20. package/lib/index.cjs.map +1 -1
  21. package/lib/index.js +90 -128
  22. package/lib/index.js.map +1 -1
  23. package/lib/plugins/index.d.cts +3 -3
  24. package/lib/selectors/index.d.cts +13 -3
  25. package/lib/selectors/index.d.ts +13 -3
  26. package/package.json +13 -14
  27. package/src/behaviors/behavior.abstract.insert.ts +58 -1
  28. package/src/behaviors/behavior.abstract.split.ts +0 -1
  29. package/src/behaviors/behavior.core.annotations.ts +24 -2
  30. package/src/behaviors/behavior.core.ts +1 -1
  31. package/src/behaviors/behavior.types.event.ts +18 -18
  32. package/src/converters/converter.portable-text.ts +0 -1
  33. package/src/converters/converter.text-html.serialize.test.ts +27 -17
  34. package/src/converters/converter.text-html.ts +0 -1
  35. package/src/converters/converter.text-plain.test.ts +1 -1
  36. package/src/converters/converter.text-plain.ts +0 -1
  37. package/src/editor/Editable.tsx +0 -1
  38. package/src/editor/plugins/createWithEditableAPI.ts +16 -0
  39. package/src/internal-utils/parse-blocks.test.ts +23 -23
  40. package/src/internal-utils/parse-blocks.ts +13 -24
  41. package/src/internal-utils/test-editor.tsx +15 -21
  42. package/src/operations/behavior.operation.annotation.add.ts +2 -13
  43. package/src/operations/behavior.operation.block.set.ts +1 -1
  44. package/src/operations/behavior.operation.block.unset.ts +2 -2
  45. package/src/operations/behavior.operation.insert.block.ts +1 -1
  46. package/src/operations/behavior.operations.ts +0 -18
  47. package/src/plugins/plugin.internal.auto-close-brackets.test.tsx +25 -71
  48. package/src/plugins/plugin.markdown.test.tsx +12 -30
  49. package/src/selectors/selector.get-selected-value.test.ts +748 -0
  50. package/src/selectors/selector.get-selected-value.ts +28 -7
  51. package/src/selectors/selector.get-trimmed-selection.test.ts +0 -1
  52. package/src/selectors/selector.is-active-annotation.test.ts +320 -0
  53. package/src/selectors/selector.is-active-annotation.ts +24 -0
  54. package/src/utils/util.merge-text-blocks.ts +1 -1
  55. package/src/utils/util.slice-blocks.ts +36 -3
  56. package/src/editor/__tests__/PortableTextEditor.test.tsx +0 -430
  57. package/src/editor/__tests__/PortableTextEditorTester.tsx +0 -58
  58. package/src/editor/__tests__/RangeDecorations.test.tsx +0 -213
  59. package/src/editor/__tests__/insert-block.test.tsx +0 -224
  60. package/src/editor/__tests__/self-solving.test.tsx +0 -183
  61. package/src/editor/plugins/__tests__/withEditableAPIDelete.test.tsx +0 -298
  62. package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +0 -177
  63. package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +0 -538
  64. package/src/editor/plugins/__tests__/withEditableAPISelectionsOverlapping.test.tsx +0 -162
  65. package/src/editor/plugins/__tests__/withPortableTextLists.test.tsx +0 -65
  66. package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +0 -612
  67. package/src/editor/plugins/__tests__/withPortableTextSelections.test.tsx +0 -103
  68. package/src/editor/plugins/__tests__/withUndoRedo.test.tsx +0 -147
  69. package/src/internal-utils/__tests__/valueNormalization.test.tsx +0 -79
  70. package/src/operations/behavior.operation.insert-inline-object.ts +0 -59
  71. package/src/operations/behavior.operation.insert-span.ts +0 -48
  72. package/src/utils/util.slice-blocks.test.ts +0 -465
@@ -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
- })