@portabletext/editor 2.8.0 → 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.
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs +10 -4
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -1
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs +0 -1
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs +3 -6
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-dts/behavior.types.action.d.cts +73 -73
- package/lib/_chunks-dts/behavior.types.action.d.ts +9 -9
- package/lib/_chunks-es/selector.is-selection-expanded.js +10 -4
- package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -1
- package/lib/_chunks-es/util.merge-text-blocks.js +0 -1
- package/lib/_chunks-es/util.merge-text-blocks.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js +3 -6
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/index.cjs +0 -10
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +0 -10
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +3 -3
- package/lib/plugins/index.d.ts +3 -3
- package/lib/utils/index.d.ts +2 -2
- package/package.json +5 -5
- package/src/behaviors/behavior.abstract.split.ts +0 -1
- package/src/converters/converter.portable-text.ts +0 -1
- package/src/converters/converter.text-html.ts +0 -1
- package/src/converters/converter.text-plain.ts +0 -1
- package/src/editor/Editable.tsx +0 -1
- package/src/internal-utils/parse-blocks.test.ts +23 -23
- package/src/internal-utils/parse-blocks.ts +11 -23
- package/src/internal-utils/test-editor.tsx +15 -21
- package/src/operations/behavior.operation.annotation.add.ts +1 -1
- package/src/operations/behavior.operation.block.set.ts +1 -1
- package/src/operations/behavior.operation.block.unset.ts +2 -2
- package/src/operations/behavior.operation.insert.block.ts +1 -1
- package/src/plugins/plugin.internal.auto-close-brackets.test.tsx +25 -71
- package/src/plugins/plugin.markdown.test.tsx +12 -30
- package/src/selectors/selector.get-selected-value.test.ts +748 -0
- package/src/selectors/selector.get-selected-value.ts +28 -7
- package/src/selectors/selector.get-trimmed-selection.test.ts +0 -1
- package/src/utils/util.merge-text-blocks.ts +1 -1
- package/src/utils/util.slice-blocks.ts +3 -3
- package/src/utils/util.slice-blocks.test.ts +0 -499
|
@@ -1,117 +1,71 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {page, userEvent} from '@vitest/browser/context'
|
|
4
|
-
import React from 'react'
|
|
1
|
+
import {getTersePt} from '@portabletext/test'
|
|
2
|
+
import {userEvent} from '@vitest/browser/context'
|
|
5
3
|
import {describe, expect, test, vi} from 'vitest'
|
|
6
|
-
import {
|
|
7
|
-
import {EditorProvider, PortableTextEditable, type Editor} from '..'
|
|
8
|
-
import {EditorRefPlugin} from './plugin.editor-ref'
|
|
4
|
+
import {createTestEditor} from '../internal-utils/test-editor'
|
|
9
5
|
import {AutoCloseBracketsPlugin} from './plugin.internal.auto-close-brackets'
|
|
10
6
|
|
|
11
7
|
describe(AutoCloseBracketsPlugin.name, () => {
|
|
12
8
|
test('One-character text insertion', async () => {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
initialConfig={{
|
|
18
|
-
keyGenerator: createTestKeyGenerator(),
|
|
19
|
-
schemaDefinition: defineSchema({}),
|
|
20
|
-
}}
|
|
21
|
-
>
|
|
22
|
-
<EditorRefPlugin ref={editorRef} />
|
|
23
|
-
<PortableTextEditable />
|
|
24
|
-
<AutoCloseBracketsPlugin />
|
|
25
|
-
</EditorProvider>,
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
const locator = page.getByRole('textbox')
|
|
29
|
-
await vi.waitFor(() => expect.element(locator).toBeInTheDocument())
|
|
9
|
+
const {editor, locator} = await createTestEditor({
|
|
10
|
+
children: <AutoCloseBracketsPlugin />,
|
|
11
|
+
})
|
|
12
|
+
|
|
30
13
|
await userEvent.click(locator)
|
|
31
14
|
|
|
32
|
-
|
|
15
|
+
editor.send({type: 'insert.text', text: '('})
|
|
33
16
|
|
|
34
17
|
await vi.waitFor(() => {
|
|
35
|
-
expect(getTersePt(
|
|
36
|
-
'()',
|
|
37
|
-
])
|
|
18
|
+
expect(getTersePt(editor.getSnapshot().context)).toEqual(['()'])
|
|
38
19
|
})
|
|
39
20
|
|
|
40
21
|
await userEvent.type(locator, 'foo')
|
|
41
22
|
|
|
42
23
|
await vi.waitFor(() => {
|
|
43
|
-
expect(getTersePt(
|
|
44
|
-
'(foo)',
|
|
45
|
-
])
|
|
24
|
+
expect(getTersePt(editor.getSnapshot().context)).toEqual(['(foo)'])
|
|
46
25
|
})
|
|
47
26
|
|
|
48
|
-
|
|
27
|
+
editor.send({type: 'history.undo'})
|
|
49
28
|
|
|
50
29
|
await vi.waitFor(() => {
|
|
51
|
-
expect(getTersePt(
|
|
52
|
-
'()',
|
|
53
|
-
])
|
|
30
|
+
expect(getTersePt(editor.getSnapshot().context)).toEqual(['()'])
|
|
54
31
|
})
|
|
55
32
|
|
|
56
|
-
|
|
33
|
+
editor.send({type: 'history.undo'})
|
|
57
34
|
|
|
58
35
|
await vi.waitFor(() => {
|
|
59
|
-
expect(getTersePt(
|
|
60
|
-
'(',
|
|
61
|
-
])
|
|
36
|
+
expect(getTersePt(editor.getSnapshot().context)).toEqual(['('])
|
|
62
37
|
})
|
|
63
38
|
})
|
|
64
39
|
|
|
65
40
|
test('Two-character text insertion', async () => {
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
initialConfig={{
|
|
71
|
-
keyGenerator: createTestKeyGenerator(),
|
|
72
|
-
schemaDefinition: defineSchema({}),
|
|
73
|
-
}}
|
|
74
|
-
>
|
|
75
|
-
<EditorRefPlugin ref={editorRef} />
|
|
76
|
-
<PortableTextEditable />
|
|
77
|
-
<AutoCloseBracketsPlugin />
|
|
78
|
-
</EditorProvider>,
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
const locator = page.getByRole('textbox')
|
|
82
|
-
await vi.waitFor(() => expect.element(locator).toBeInTheDocument())
|
|
41
|
+
const {editor, locator} = await createTestEditor({
|
|
42
|
+
children: <AutoCloseBracketsPlugin />,
|
|
43
|
+
})
|
|
44
|
+
|
|
83
45
|
await userEvent.click(locator)
|
|
84
46
|
|
|
85
|
-
|
|
47
|
+
editor.send({type: 'insert.text', text: '(f'})
|
|
86
48
|
|
|
87
49
|
await vi.waitFor(() => {
|
|
88
|
-
expect(getTersePt(
|
|
89
|
-
'(f)',
|
|
90
|
-
])
|
|
50
|
+
expect(getTersePt(editor.getSnapshot().context)).toEqual(['(f)'])
|
|
91
51
|
})
|
|
92
52
|
|
|
93
53
|
await userEvent.type(locator, 'oo')
|
|
94
54
|
|
|
95
55
|
await vi.waitFor(() => {
|
|
96
|
-
expect(getTersePt(
|
|
97
|
-
'(foo)',
|
|
98
|
-
])
|
|
56
|
+
expect(getTersePt(editor.getSnapshot().context)).toEqual(['(foo)'])
|
|
99
57
|
})
|
|
100
58
|
|
|
101
|
-
|
|
59
|
+
editor.send({type: 'history.undo'})
|
|
102
60
|
|
|
103
61
|
await vi.waitFor(() => {
|
|
104
|
-
expect(getTersePt(
|
|
105
|
-
'(f)',
|
|
106
|
-
])
|
|
62
|
+
expect(getTersePt(editor.getSnapshot().context)).toEqual(['(f)'])
|
|
107
63
|
})
|
|
108
64
|
|
|
109
|
-
|
|
65
|
+
editor.send({type: 'history.undo'})
|
|
110
66
|
|
|
111
67
|
await vi.waitFor(() => {
|
|
112
|
-
expect(getTersePt(
|
|
113
|
-
'(f',
|
|
114
|
-
])
|
|
68
|
+
expect(getTersePt(editor.getSnapshot().context)).toEqual(['(f'])
|
|
115
69
|
})
|
|
116
70
|
})
|
|
117
71
|
})
|
|
@@ -1,58 +1,40 @@
|
|
|
1
1
|
import {defineSchema} from '@portabletext/schema'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import React from 'react'
|
|
2
|
+
import {getTersePt} from '@portabletext/test'
|
|
3
|
+
import {userEvent} from '@vitest/browser/context'
|
|
5
4
|
import {describe, expect, test, vi} from 'vitest'
|
|
6
|
-
import {
|
|
7
|
-
import {PortableTextEditable, type Editor} from '..'
|
|
8
|
-
import {EditorProvider} from '../editor/editor-provider'
|
|
5
|
+
import {createTestEditor} from '../internal-utils/test-editor'
|
|
9
6
|
import {getTextMarks} from '../internal-utils/text-marks'
|
|
10
|
-
import {EditorRefPlugin} from './plugin.editor-ref'
|
|
11
7
|
import {MarkdownPlugin} from './plugin.markdown'
|
|
12
8
|
|
|
13
9
|
describe(MarkdownPlugin.name, () => {
|
|
14
10
|
test('Scenario: Undoing bold shortcut', async () => {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
render(
|
|
18
|
-
<EditorProvider
|
|
19
|
-
initialConfig={{
|
|
20
|
-
keyGenerator: createTestKeyGenerator(),
|
|
21
|
-
schemaDefinition: defineSchema({decorators: [{name: 'strong'}]}),
|
|
22
|
-
}}
|
|
23
|
-
>
|
|
24
|
-
<EditorRefPlugin ref={editorRef} />
|
|
25
|
-
<PortableTextEditable />
|
|
11
|
+
const {editor, locator} = await createTestEditor({
|
|
12
|
+
children: (
|
|
26
13
|
<MarkdownPlugin
|
|
27
14
|
config={{
|
|
28
15
|
boldDecorator: () => 'strong',
|
|
29
16
|
}}
|
|
30
17
|
/>
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const locator = page.getByRole('textbox')
|
|
35
|
-
|
|
36
|
-
await vi.waitFor(() => expect.element(locator).toBeInTheDocument())
|
|
18
|
+
),
|
|
19
|
+
schemaDefinition: defineSchema({decorators: [{name: 'strong'}]}),
|
|
20
|
+
})
|
|
37
21
|
|
|
38
22
|
await userEvent.type(locator, '**Hello world!**')
|
|
39
23
|
|
|
40
24
|
await vi.waitFor(() => {
|
|
41
|
-
expect(getTersePt(
|
|
42
|
-
'Hello world!',
|
|
43
|
-
])
|
|
25
|
+
expect(getTersePt(editor.getSnapshot().context)).toEqual(['Hello world!'])
|
|
44
26
|
})
|
|
45
27
|
|
|
46
28
|
await vi.waitFor(() => {
|
|
47
29
|
expect(
|
|
48
|
-
getTextMarks(
|
|
30
|
+
getTextMarks(editor.getSnapshot().context, 'Hello world!'),
|
|
49
31
|
).toEqual(['strong'])
|
|
50
32
|
})
|
|
51
33
|
|
|
52
|
-
|
|
34
|
+
editor.send({type: 'history.undo'})
|
|
53
35
|
|
|
54
36
|
await vi.waitFor(() => {
|
|
55
|
-
expect(getTersePt(
|
|
37
|
+
expect(getTersePt(editor.getSnapshot().context)).toEqual([
|
|
56
38
|
'**Hello world!**',
|
|
57
39
|
])
|
|
58
40
|
})
|