@portabletext/editor 1.0.18 → 1.1.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/index.d.mts +140 -66
- package/lib/index.d.ts +140 -66
- package/lib/index.esm.js +1164 -410
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +1164 -410
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +1164 -410
- package/lib/index.mjs.map +1 -1
- package/package.json +8 -4
- package/src/editor/Editable.tsx +107 -36
- package/src/editor/PortableTextEditor.tsx +47 -12
- package/src/editor/__tests__/PortableTextEditor.test.tsx +42 -15
- package/src/editor/__tests__/PortableTextEditorTester.tsx +50 -38
- package/src/editor/__tests__/RangeDecorations.test.tsx +0 -1
- package/src/editor/__tests__/handleClick.test.tsx +28 -9
- package/src/editor/__tests__/insert-block.test.tsx +22 -6
- package/src/editor/__tests__/pteWarningsSelfSolving.test.tsx +30 -62
- package/src/editor/__tests__/utils.ts +10 -3
- package/src/editor/components/DraggableBlock.tsx +36 -13
- package/src/editor/components/Element.tsx +59 -17
- package/src/editor/components/Leaf.tsx +106 -68
- package/src/editor/components/SlateContainer.tsx +12 -5
- package/src/editor/components/Synchronizer.tsx +5 -2
- package/src/editor/hooks/usePortableTextEditor.ts +2 -2
- package/src/editor/hooks/usePortableTextEditorSelection.tsx +9 -3
- package/src/editor/hooks/useSyncValue.test.tsx +9 -4
- package/src/editor/hooks/useSyncValue.ts +199 -130
- package/src/editor/nodes/DefaultAnnotation.tsx +6 -3
- package/src/editor/plugins/__tests__/createWithInsertData.test.tsx +25 -7
- package/src/editor/plugins/__tests__/withEditableAPIDelete.test.tsx +26 -9
- package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +15 -5
- package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +60 -19
- package/src/editor/plugins/__tests__/withEditableAPISelectionsOverlapping.test.tsx +4 -2
- package/src/editor/plugins/__tests__/withPortableTextLists.test.tsx +4 -2
- package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +61 -550
- package/src/editor/plugins/__tests__/withPortableTextSelections.test.tsx +6 -3
- package/src/editor/plugins/__tests__/withUndoRedo.test.tsx +30 -13
- package/src/editor/plugins/createWithEditableAPI.ts +354 -115
- package/src/editor/plugins/createWithHotKeys.ts +41 -121
- package/src/editor/plugins/createWithInsertBreak.ts +166 -27
- package/src/editor/plugins/createWithInsertData.ts +60 -23
- package/src/editor/plugins/createWithMaxBlocks.ts +5 -2
- package/src/editor/plugins/createWithObjectKeys.ts +7 -3
- package/src/editor/plugins/createWithPatches.ts +60 -16
- package/src/editor/plugins/createWithPlaceholderBlock.ts +7 -3
- package/src/editor/plugins/createWithPortableTextBlockStyle.ts +17 -7
- package/src/editor/plugins/createWithPortableTextLists.ts +21 -8
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +301 -155
- package/src/editor/plugins/createWithPortableTextSelections.ts +4 -2
- package/src/editor/plugins/createWithSchemaTypes.ts +25 -9
- package/src/editor/plugins/createWithUndoRedo.ts +107 -24
- package/src/editor/plugins/createWithUtils.ts +32 -10
- package/src/editor/plugins/index.ts +31 -10
- package/src/types/editor.ts +44 -15
- package/src/types/options.ts +4 -2
- package/src/types/slate.ts +2 -2
- package/src/utils/__tests__/dmpToOperations.test.ts +38 -13
- package/src/utils/__tests__/operationToPatches.test.ts +3 -2
- package/src/utils/__tests__/patchToOperations.test.ts +15 -4
- package/src/utils/__tests__/ranges.test.ts +8 -3
- package/src/utils/__tests__/valueNormalization.test.tsx +12 -4
- package/src/utils/__tests__/values.test.ts +0 -1
- package/src/utils/applyPatch.ts +71 -20
- package/src/utils/getPortableTextMemberSchemaTypes.ts +30 -15
- package/src/utils/operationToPatches.ts +126 -43
- package/src/utils/paths.ts +24 -7
- package/src/utils/ranges.ts +12 -5
- package/src/utils/selection.ts +19 -7
- package/src/utils/validateValue.ts +118 -45
- package/src/utils/values.ts +31 -10
- package/src/utils/weakMaps.ts +18 -8
- package/src/utils/withChanges.ts +4 -2
- package/src/editor/plugins/__tests__/withHotkeys.test.tsx +0 -212
- package/src/editor/plugins/__tests__/withInsertBreak.test.tsx +0 -220
- package/src/editor/plugins/__tests__/withPlaceholderBlock.test.tsx +0 -133
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {describe, expect, it, jest} from '@jest/globals'
|
|
2
2
|
import {render, waitFor} from '@testing-library/react'
|
|
3
3
|
import {createRef, type RefObject} from 'react'
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
PortableTextEditorTester,
|
|
6
|
+
schemaType,
|
|
7
|
+
} from '../../__tests__/PortableTextEditorTester'
|
|
6
8
|
import {PortableTextEditor} from '../../PortableTextEditor'
|
|
7
9
|
|
|
8
10
|
const initialValue = [
|
|
@@ -56,7 +58,8 @@ describe('plugin:withPortableTextSelections', () => {
|
|
|
56
58
|
if (editorRef.current) {
|
|
57
59
|
PortableTextEditor.focus(editorRef.current)
|
|
58
60
|
PortableTextEditor.select(editorRef.current, initialSelection)
|
|
59
|
-
expect(PortableTextEditor.getSelection(editorRef.current))
|
|
61
|
+
expect(PortableTextEditor.getSelection(editorRef.current))
|
|
62
|
+
.toMatchInlineSnapshot(`
|
|
60
63
|
Object {
|
|
61
64
|
"anchor": Object {
|
|
62
65
|
"offset": 9,
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {describe, expect, it, jest} from '@jest/globals'
|
|
2
2
|
import {render, waitFor} from '@testing-library/react'
|
|
3
3
|
import {createRef, type RefObject} from 'react'
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
PortableTextEditorTester,
|
|
6
|
+
schemaType,
|
|
7
|
+
} from '../../__tests__/PortableTextEditorTester'
|
|
6
8
|
import {PortableTextEditor} from '../../PortableTextEditor'
|
|
7
9
|
|
|
8
10
|
const initialValue = [
|
|
@@ -56,7 +58,10 @@ describe('plugin:withUndoRedo', () => {
|
|
|
56
58
|
|
|
57
59
|
await waitFor(() => {
|
|
58
60
|
if (editorRef.current) {
|
|
59
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
61
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
62
|
+
type: 'value',
|
|
63
|
+
value: initialValue,
|
|
64
|
+
})
|
|
60
65
|
expect(onChange).toHaveBeenCalledWith({type: 'ready'})
|
|
61
66
|
}
|
|
62
67
|
})
|
|
@@ -70,7 +75,8 @@ describe('plugin:withUndoRedo', () => {
|
|
|
70
75
|
PortableTextEditor.getSelection(editorRef.current),
|
|
71
76
|
{mode: 'blocks'},
|
|
72
77
|
)
|
|
73
|
-
expect(PortableTextEditor.getValue(editorRef.current))
|
|
78
|
+
expect(PortableTextEditor.getValue(editorRef.current))
|
|
79
|
+
.toMatchInlineSnapshot(`
|
|
74
80
|
Array [
|
|
75
81
|
Object {
|
|
76
82
|
"_key": "a",
|
|
@@ -89,7 +95,9 @@ describe('plugin:withUndoRedo', () => {
|
|
|
89
95
|
]
|
|
90
96
|
`)
|
|
91
97
|
PortableTextEditor.undo(editorRef.current)
|
|
92
|
-
expect(PortableTextEditor.getValue(editorRef.current)).toEqual(
|
|
98
|
+
expect(PortableTextEditor.getValue(editorRef.current)).toEqual(
|
|
99
|
+
initialValue,
|
|
100
|
+
)
|
|
93
101
|
}
|
|
94
102
|
})
|
|
95
103
|
})
|
|
@@ -108,7 +116,10 @@ describe('plugin:withUndoRedo', () => {
|
|
|
108
116
|
|
|
109
117
|
await waitFor(() => {
|
|
110
118
|
if (editorRef.current) {
|
|
111
|
-
expect(onChange).toHaveBeenCalledWith({
|
|
119
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
120
|
+
type: 'value',
|
|
121
|
+
value: initialValue,
|
|
122
|
+
})
|
|
112
123
|
expect(onChange).toHaveBeenCalledWith({type: 'ready'})
|
|
113
124
|
}
|
|
114
125
|
})
|
|
@@ -117,15 +128,21 @@ describe('plugin:withUndoRedo', () => {
|
|
|
117
128
|
if (editorRef.current) {
|
|
118
129
|
PortableTextEditor.focus(editorRef.current)
|
|
119
130
|
PortableTextEditor.select(editorRef.current, initialSelection)
|
|
120
|
-
PortableTextEditor.insertBlock(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
131
|
+
PortableTextEditor.insertBlock(
|
|
132
|
+
editorRef.current,
|
|
133
|
+
editorRef.current.schemaTypes.block,
|
|
134
|
+
{
|
|
135
|
+
children: [{_key: 'c1', _type: 'span', marks: [], text: 'Block C'}],
|
|
136
|
+
},
|
|
137
|
+
)
|
|
138
|
+
const producedKey = PortableTextEditor.getValue(
|
|
139
|
+
editorRef.current,
|
|
140
|
+
)?.slice(-1)[0]?._key
|
|
124
141
|
PortableTextEditor.undo(editorRef.current)
|
|
125
142
|
PortableTextEditor.redo(editorRef.current)
|
|
126
|
-
expect(
|
|
127
|
-
|
|
128
|
-
)
|
|
143
|
+
expect(
|
|
144
|
+
PortableTextEditor.getValue(editorRef.current)?.slice(-1)[0]?._key,
|
|
145
|
+
).toEqual(producedKey)
|
|
129
146
|
}
|
|
130
147
|
})
|
|
131
148
|
})
|