@contentful/field-editor-rich-text 6.6.15 → 6.6.16-canary.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/README.md +3 -1
- package/dist/cjs/plugins/Heading/__tests__/createHeadingPlugin.test.js +82 -0
- package/dist/cjs/plugins/List/__tests__/createListPlugin.test.js +198 -0
- package/dist/cjs/plugins/List/withList.js +25 -1
- package/dist/cjs/plugins/Table/__tests__/createTablePlugin.test.js +328 -0
- package/dist/cjs/plugins/Table/createTablePlugin.js +2 -0
- package/dist/cjs/plugins/Table/onKeyDownTable.js +0 -14
- package/dist/cjs/plugins/Table/withDeleteBackwardTable.js +59 -0
- package/dist/cjs/plugins/Text/__tests__/createTextPlugin.test.js +63 -0
- package/dist/cjs/plugins/Text/createTextPlugin.js +21 -5
- package/dist/esm/plugins/Heading/__tests__/createHeadingPlugin.test.js +83 -1
- package/dist/esm/plugins/List/__tests__/createListPlugin.test.js +200 -2
- package/dist/esm/plugins/List/withList.js +26 -2
- package/dist/esm/plugins/Table/__tests__/createTablePlugin.test.js +329 -1
- package/dist/esm/plugins/Table/createTablePlugin.js +2 -0
- package/dist/esm/plugins/Table/onKeyDownTable.js +1 -15
- package/dist/esm/plugins/Table/withDeleteBackwardTable.js +49 -0
- package/dist/esm/plugins/Text/__tests__/createTextPlugin.test.js +64 -1
- package/dist/esm/plugins/Text/createTextPlugin.js +22 -6
- package/dist/types/plugins/Table/withDeleteBackwardTable.d.ts +2 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -12,7 +12,9 @@ import { RichTextEditor } from '@contentful/field-editor-rich-text';
|
|
|
12
12
|
|
|
13
13
|
## Clearing a field
|
|
14
14
|
|
|
15
|
-
When an edit leaves only empty paragraphs or list items, the editor removes the locale's field value. Blank paragraphs within documents containing
|
|
15
|
+
When an edit leaves only empty paragraphs or list items, the editor removes the locale's field value. Blank paragraphs within documents containing content are preserved. Whitespace, embedded entities, horizontal rules, and tables count as content.
|
|
16
|
+
|
|
17
|
+
Backspace removes a wholly empty list at its start. It removes a wholly empty table from the start of its first cell or the paragraph immediately after it. A heading keeps its formatting when its final character is deleted; pressing Backspace again removes the empty heading and returns to normal text.
|
|
16
18
|
|
|
17
19
|
## ⚠️ Important: Package Configuration
|
|
18
20
|
|
|
@@ -6,6 +6,88 @@ const _richtexttypes = require("@contentful/rich-text-types");
|
|
|
6
6
|
const _vitest = require("vitest");
|
|
7
7
|
const _testutils = require("../../../test-utils");
|
|
8
8
|
const _createHeadingPlugin = require("../createHeadingPlugin");
|
|
9
|
+
(0, _vitest.describe)('backward deletion', ()=>{
|
|
10
|
+
_vitest.it.each(_richtexttypes.HEADINGS)('keeps a non-empty %s when Backspace is pressed at the document start', (type)=>{
|
|
11
|
+
const { editor } = (0, _testutils.createTestEditor)({});
|
|
12
|
+
editor.children = [
|
|
13
|
+
{
|
|
14
|
+
type,
|
|
15
|
+
children: [
|
|
16
|
+
{
|
|
17
|
+
text: 'x'
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
23
|
+
children: [
|
|
24
|
+
{
|
|
25
|
+
text: ''
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
];
|
|
30
|
+
editor.tf.select({
|
|
31
|
+
path: [
|
|
32
|
+
0,
|
|
33
|
+
0
|
|
34
|
+
],
|
|
35
|
+
offset: 0
|
|
36
|
+
});
|
|
37
|
+
editor.deleteBackward('character');
|
|
38
|
+
(0, _vitest.expect)(editor.children[0]).toMatchObject({
|
|
39
|
+
type,
|
|
40
|
+
children: [
|
|
41
|
+
{
|
|
42
|
+
text: 'x'
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
_vitest.it.each(_richtexttypes.HEADINGS)('removes an empty %s on an additional Backspace', (type)=>{
|
|
48
|
+
const { editor } = (0, _testutils.createTestEditor)({});
|
|
49
|
+
editor.children = [
|
|
50
|
+
{
|
|
51
|
+
type,
|
|
52
|
+
children: [
|
|
53
|
+
{
|
|
54
|
+
text: 'x'
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
60
|
+
children: [
|
|
61
|
+
{
|
|
62
|
+
text: ''
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
];
|
|
67
|
+
editor.tf.select({
|
|
68
|
+
path: [
|
|
69
|
+
0,
|
|
70
|
+
0
|
|
71
|
+
],
|
|
72
|
+
offset: 1
|
|
73
|
+
});
|
|
74
|
+
editor.deleteBackward('character');
|
|
75
|
+
(0, _vitest.expect)(editor.children[0]).toMatchObject({
|
|
76
|
+
type,
|
|
77
|
+
children: [
|
|
78
|
+
{
|
|
79
|
+
text: ''
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
});
|
|
83
|
+
editor.deleteBackward('character');
|
|
84
|
+
(0, _vitest.expect)(editor.children[0].type).toBe(_richtexttypes.BLOCKS.PARAGRAPH);
|
|
85
|
+
(0, _vitest.expect)(editor.selection?.anchor.path).toEqual([
|
|
86
|
+
0,
|
|
87
|
+
0
|
|
88
|
+
]);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
9
91
|
(0, _vitest.describe)('normalization', ()=>{
|
|
10
92
|
(0, _vitest.it)('can contain inline entries & hyperlinks', ()=>{
|
|
11
93
|
const input = (0, _testutils.jsx)("editor", null, (0, _testutils.jsx)("hh1", null, "some text before", (0, _testutils.jsx)("hinline", {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
+
const _richtexttypes = require("@contentful/rich-text-types");
|
|
5
6
|
const _vitest = require("vitest");
|
|
6
7
|
const _testutils = require("../../../test-utils");
|
|
7
8
|
(0, _vitest.describe)('normalization', ()=>{
|
|
@@ -46,3 +47,200 @@ const _testutils = require("../../../test-utils");
|
|
|
46
47
|
});
|
|
47
48
|
});
|
|
48
49
|
});
|
|
50
|
+
(0, _vitest.describe)('backward deletion', ()=>{
|
|
51
|
+
_vitest.it.each([
|
|
52
|
+
{
|
|
53
|
+
type: 'hul',
|
|
54
|
+
listName: 'unordered list'
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
type: 'hol',
|
|
58
|
+
listName: 'ordered list'
|
|
59
|
+
}
|
|
60
|
+
])('removes an empty $listName at the start of the document', ({ type })=>{
|
|
61
|
+
const input = (0, _testutils.jsx)("editor", null, type === 'hul' ? (0, _testutils.jsx)("hul", null, (0, _testutils.jsx)("hli", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null)))) : (0, _testutils.jsx)("hol", null, (0, _testutils.jsx)("hli", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null)))), (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("htext", null)));
|
|
62
|
+
const { editor } = (0, _testutils.createTestEditor)({
|
|
63
|
+
input
|
|
64
|
+
});
|
|
65
|
+
editor.deleteBackward('character');
|
|
66
|
+
const expected = (0, _testutils.jsx)("editor", null, (0, _testutils.jsx)("hp", null, (0, _testutils.jsx)("cursor", null)));
|
|
67
|
+
(0, _testutils.assertOutput)({
|
|
68
|
+
editor,
|
|
69
|
+
expected
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
_vitest.it.each([
|
|
73
|
+
{
|
|
74
|
+
title: 'whitespace',
|
|
75
|
+
itemChildren: [
|
|
76
|
+
{
|
|
77
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
78
|
+
children: [
|
|
79
|
+
{
|
|
80
|
+
text: ' '
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
],
|
|
85
|
+
expectedContent: ' '
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
title: 'a later paragraph in a multi-paragraph item',
|
|
89
|
+
itemChildren: [
|
|
90
|
+
{
|
|
91
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
92
|
+
children: [
|
|
93
|
+
{
|
|
94
|
+
text: ''
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
100
|
+
children: [
|
|
101
|
+
{
|
|
102
|
+
text: 'content'
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
],
|
|
107
|
+
expectedContent: 'content'
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
title: 'a nested list',
|
|
111
|
+
itemChildren: [
|
|
112
|
+
{
|
|
113
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
114
|
+
children: [
|
|
115
|
+
{
|
|
116
|
+
text: ''
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
type: _richtexttypes.BLOCKS.UL_LIST,
|
|
122
|
+
children: [
|
|
123
|
+
{
|
|
124
|
+
type: _richtexttypes.BLOCKS.LIST_ITEM,
|
|
125
|
+
children: [
|
|
126
|
+
{
|
|
127
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
128
|
+
children: [
|
|
129
|
+
{
|
|
130
|
+
text: 'nested'
|
|
131
|
+
}
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
}
|
|
138
|
+
],
|
|
139
|
+
expectedContent: 'nested'
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
title: 'a heading',
|
|
143
|
+
itemChildren: [
|
|
144
|
+
{
|
|
145
|
+
type: _richtexttypes.BLOCKS.HEADING_1,
|
|
146
|
+
children: [
|
|
147
|
+
{
|
|
148
|
+
text: 'heading'
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
}
|
|
152
|
+
],
|
|
153
|
+
expectedContent: 'heading'
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
title: 'an embedded entry',
|
|
157
|
+
itemChildren: [
|
|
158
|
+
{
|
|
159
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
160
|
+
children: [
|
|
161
|
+
{
|
|
162
|
+
text: ''
|
|
163
|
+
}
|
|
164
|
+
]
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
type: _richtexttypes.BLOCKS.EMBEDDED_ENTRY,
|
|
168
|
+
data: {
|
|
169
|
+
target: {}
|
|
170
|
+
},
|
|
171
|
+
children: [
|
|
172
|
+
{
|
|
173
|
+
text: ''
|
|
174
|
+
}
|
|
175
|
+
]
|
|
176
|
+
}
|
|
177
|
+
],
|
|
178
|
+
expectedContent: _richtexttypes.BLOCKS.EMBEDDED_ENTRY
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
title: 'an embedded inline',
|
|
182
|
+
itemChildren: [
|
|
183
|
+
{
|
|
184
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
185
|
+
children: [
|
|
186
|
+
{
|
|
187
|
+
text: ''
|
|
188
|
+
}
|
|
189
|
+
]
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
193
|
+
children: [
|
|
194
|
+
{
|
|
195
|
+
type: _richtexttypes.INLINES.EMBEDDED_ENTRY,
|
|
196
|
+
data: {
|
|
197
|
+
target: {}
|
|
198
|
+
},
|
|
199
|
+
children: [
|
|
200
|
+
{
|
|
201
|
+
text: ''
|
|
202
|
+
}
|
|
203
|
+
]
|
|
204
|
+
}
|
|
205
|
+
]
|
|
206
|
+
}
|
|
207
|
+
],
|
|
208
|
+
expectedContent: _richtexttypes.INLINES.EMBEDDED_ENTRY
|
|
209
|
+
}
|
|
210
|
+
])('preserves a list containing $title', ({ itemChildren, expectedContent })=>{
|
|
211
|
+
const { editor } = (0, _testutils.createTestEditor)({});
|
|
212
|
+
const list = {
|
|
213
|
+
type: _richtexttypes.BLOCKS.UL_LIST,
|
|
214
|
+
children: [
|
|
215
|
+
{
|
|
216
|
+
type: _richtexttypes.BLOCKS.LIST_ITEM,
|
|
217
|
+
children: itemChildren
|
|
218
|
+
}
|
|
219
|
+
]
|
|
220
|
+
};
|
|
221
|
+
editor.children = [
|
|
222
|
+
list,
|
|
223
|
+
{
|
|
224
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
225
|
+
children: [
|
|
226
|
+
{
|
|
227
|
+
text: ''
|
|
228
|
+
}
|
|
229
|
+
]
|
|
230
|
+
}
|
|
231
|
+
];
|
|
232
|
+
editor.tf.select({
|
|
233
|
+
path: [
|
|
234
|
+
0,
|
|
235
|
+
0,
|
|
236
|
+
0,
|
|
237
|
+
0
|
|
238
|
+
],
|
|
239
|
+
offset: 0
|
|
240
|
+
});
|
|
241
|
+
editor.deleteBackward('character');
|
|
242
|
+
const updatedList = JSON.stringify(editor.children[0]);
|
|
243
|
+
(0, _vitest.expect)(editor.children[0].type).toBe(_richtexttypes.BLOCKS.UL_LIST);
|
|
244
|
+
(0, _vitest.expect)(updatedList).toContain(expectedContent);
|
|
245
|
+
});
|
|
246
|
+
});
|
|
@@ -10,11 +10,35 @@ Object.defineProperty(exports, "withList", {
|
|
|
10
10
|
});
|
|
11
11
|
const _richtexttypes = require("@contentful/rich-text-types");
|
|
12
12
|
const _list = require("../../internal/list");
|
|
13
|
+
const _queries = require("../../internal/queries");
|
|
13
14
|
const _insertListBreak = require("./insertListBreak");
|
|
14
15
|
const _insertListFragment = require("./insertListFragment");
|
|
15
16
|
const validLiChildrenTypes = _richtexttypes.LIST_ITEM_BLOCKS;
|
|
17
|
+
const isEmptyList = (node)=>(node.type === _richtexttypes.BLOCKS.UL_LIST || node.type === _richtexttypes.BLOCKS.OL_LIST) && node.children.length > 0 && node.children.every((item)=>!(0, _queries.isText)(item) && item.type === _richtexttypes.BLOCKS.LIST_ITEM && item.children.length > 0 && item.children.every((block)=>!(0, _queries.isText)(block) && block.type === _richtexttypes.BLOCKS.PARAGRAPH && block.children.length > 0 && block.children.every((child)=>(0, _queries.isText)(child) && child.text.length === 0)));
|
|
16
18
|
const withList = (editor)=>{
|
|
17
|
-
const { deleteForward, deleteFragment } = editor;
|
|
19
|
+
const { deleteBackward, deleteForward, deleteFragment } = editor;
|
|
20
|
+
editor.deleteBackward = (unit)=>{
|
|
21
|
+
const listEntry = (0, _queries.getAboveNode)(editor, {
|
|
22
|
+
match: {
|
|
23
|
+
type: [
|
|
24
|
+
_richtexttypes.BLOCKS.UL_LIST,
|
|
25
|
+
_richtexttypes.BLOCKS.OL_LIST
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
if (editor.selection && editor.api.isCollapsed() && listEntry && listEntry[1].length === 1 && isEmptyList(listEntry[0]) && editor.api.isStart(editor.selection.anchor, listEntry[1])) {
|
|
30
|
+
editor.tf.removeNodes({
|
|
31
|
+
at: listEntry[1]
|
|
32
|
+
});
|
|
33
|
+
const nextBlockIndex = Math.min(listEntry[1][0], editor.children.length - 1);
|
|
34
|
+
const nextBlockStart = editor.api.start([
|
|
35
|
+
nextBlockIndex
|
|
36
|
+
]);
|
|
37
|
+
if (nextBlockStart) editor.tf.select(nextBlockStart);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
deleteBackward(unit);
|
|
41
|
+
};
|
|
18
42
|
editor.deleteForward = (unit)=>{
|
|
19
43
|
if ((0, _list.deleteForwardList)(editor, deleteForward, unit)) return;
|
|
20
44
|
deleteForward(unit);
|
|
@@ -210,3 +210,331 @@ const _testutils = require("../../../test-utils");
|
|
|
210
210
|
]);
|
|
211
211
|
});
|
|
212
212
|
});
|
|
213
|
+
(0, _vitest.describe)('backward deletion', ()=>{
|
|
214
|
+
const paragraph = (value = '')=>({
|
|
215
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
216
|
+
children: [
|
|
217
|
+
{
|
|
218
|
+
text: value
|
|
219
|
+
}
|
|
220
|
+
]
|
|
221
|
+
});
|
|
222
|
+
const emptyTable = {
|
|
223
|
+
type: _richtexttypes.BLOCKS.TABLE,
|
|
224
|
+
children: [
|
|
225
|
+
{
|
|
226
|
+
type: _richtexttypes.BLOCKS.TABLE_ROW,
|
|
227
|
+
children: [
|
|
228
|
+
{
|
|
229
|
+
type: _richtexttypes.BLOCKS.TABLE_HEADER_CELL,
|
|
230
|
+
children: [
|
|
231
|
+
paragraph()
|
|
232
|
+
]
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
type: _richtexttypes.BLOCKS.TABLE_HEADER_CELL,
|
|
236
|
+
children: [
|
|
237
|
+
paragraph()
|
|
238
|
+
]
|
|
239
|
+
}
|
|
240
|
+
]
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
type: _richtexttypes.BLOCKS.TABLE_ROW,
|
|
244
|
+
children: [
|
|
245
|
+
{
|
|
246
|
+
type: _richtexttypes.BLOCKS.TABLE_CELL,
|
|
247
|
+
children: [
|
|
248
|
+
paragraph()
|
|
249
|
+
]
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
type: _richtexttypes.BLOCKS.TABLE_CELL,
|
|
253
|
+
children: [
|
|
254
|
+
paragraph()
|
|
255
|
+
]
|
|
256
|
+
}
|
|
257
|
+
]
|
|
258
|
+
}
|
|
259
|
+
]
|
|
260
|
+
};
|
|
261
|
+
(0, _vitest.it)('removes an empty table when Backspace is pressed at the start of its first cell', ()=>{
|
|
262
|
+
const { editor } = (0, _testutils.createTestEditor)({});
|
|
263
|
+
editor.children = [
|
|
264
|
+
emptyTable,
|
|
265
|
+
paragraph()
|
|
266
|
+
];
|
|
267
|
+
editor.tf.select({
|
|
268
|
+
path: [
|
|
269
|
+
0,
|
|
270
|
+
0,
|
|
271
|
+
0,
|
|
272
|
+
0,
|
|
273
|
+
0
|
|
274
|
+
],
|
|
275
|
+
offset: 0
|
|
276
|
+
});
|
|
277
|
+
editor.deleteBackward('character');
|
|
278
|
+
(0, _vitest.expect)(editor.children).toMatchObject([
|
|
279
|
+
paragraph()
|
|
280
|
+
]);
|
|
281
|
+
(0, _vitest.expect)(editor.selection?.anchor.path).toEqual([
|
|
282
|
+
0,
|
|
283
|
+
0
|
|
284
|
+
]);
|
|
285
|
+
});
|
|
286
|
+
(0, _vitest.it)('removes an empty table when Backspace is pressed at the start of the following paragraph', ()=>{
|
|
287
|
+
const { editor } = (0, _testutils.createTestEditor)({});
|
|
288
|
+
editor.children = [
|
|
289
|
+
emptyTable,
|
|
290
|
+
paragraph()
|
|
291
|
+
];
|
|
292
|
+
editor.tf.select({
|
|
293
|
+
path: [
|
|
294
|
+
1,
|
|
295
|
+
0
|
|
296
|
+
],
|
|
297
|
+
offset: 0
|
|
298
|
+
});
|
|
299
|
+
editor.deleteBackward('character');
|
|
300
|
+
(0, _vitest.expect)(editor.children).toMatchObject([
|
|
301
|
+
paragraph()
|
|
302
|
+
]);
|
|
303
|
+
(0, _vitest.expect)(editor.selection?.anchor.path).toEqual([
|
|
304
|
+
0,
|
|
305
|
+
0
|
|
306
|
+
]);
|
|
307
|
+
});
|
|
308
|
+
(0, _vitest.it)('keeps a populated table when Backspace is pressed at the start of its first cell', ()=>{
|
|
309
|
+
const { editor } = (0, _testutils.createTestEditor)({});
|
|
310
|
+
const populatedTable = {
|
|
311
|
+
...emptyTable,
|
|
312
|
+
children: emptyTable.children.map((row, rowIndex)=>({
|
|
313
|
+
...row,
|
|
314
|
+
children: row.children.map((cell, cellIndex)=>rowIndex === 0 && cellIndex === 0 ? {
|
|
315
|
+
...cell,
|
|
316
|
+
children: [
|
|
317
|
+
paragraph('content')
|
|
318
|
+
]
|
|
319
|
+
} : cell)
|
|
320
|
+
}))
|
|
321
|
+
};
|
|
322
|
+
editor.children = [
|
|
323
|
+
populatedTable,
|
|
324
|
+
paragraph()
|
|
325
|
+
];
|
|
326
|
+
editor.tf.select({
|
|
327
|
+
path: [
|
|
328
|
+
0,
|
|
329
|
+
0,
|
|
330
|
+
0,
|
|
331
|
+
0,
|
|
332
|
+
0
|
|
333
|
+
],
|
|
334
|
+
offset: 0
|
|
335
|
+
});
|
|
336
|
+
editor.deleteBackward('character');
|
|
337
|
+
(0, _vitest.expect)(editor.children).toMatchObject([
|
|
338
|
+
populatedTable,
|
|
339
|
+
paragraph()
|
|
340
|
+
]);
|
|
341
|
+
});
|
|
342
|
+
(0, _vitest.it)('does not remove the empty table before a populated table', ()=>{
|
|
343
|
+
const { editor } = (0, _testutils.createTestEditor)({});
|
|
344
|
+
const populatedTable = {
|
|
345
|
+
...emptyTable,
|
|
346
|
+
children: emptyTable.children.map((row, rowIndex)=>({
|
|
347
|
+
...row,
|
|
348
|
+
children: row.children.map((cell, cellIndex)=>rowIndex === 0 && cellIndex === 0 ? {
|
|
349
|
+
...cell,
|
|
350
|
+
children: [
|
|
351
|
+
paragraph('content')
|
|
352
|
+
]
|
|
353
|
+
} : cell)
|
|
354
|
+
}))
|
|
355
|
+
};
|
|
356
|
+
editor.children = [
|
|
357
|
+
emptyTable,
|
|
358
|
+
populatedTable,
|
|
359
|
+
paragraph()
|
|
360
|
+
];
|
|
361
|
+
editor.tf.select({
|
|
362
|
+
path: [
|
|
363
|
+
1,
|
|
364
|
+
0,
|
|
365
|
+
0,
|
|
366
|
+
0,
|
|
367
|
+
0
|
|
368
|
+
],
|
|
369
|
+
offset: 0
|
|
370
|
+
});
|
|
371
|
+
editor.deleteBackward('character');
|
|
372
|
+
(0, _vitest.expect)(editor.children).toMatchObject([
|
|
373
|
+
emptyTable,
|
|
374
|
+
populatedTable,
|
|
375
|
+
paragraph()
|
|
376
|
+
]);
|
|
377
|
+
});
|
|
378
|
+
_vitest.it.each([
|
|
379
|
+
{
|
|
380
|
+
title: 'whitespace in another cell',
|
|
381
|
+
table: {
|
|
382
|
+
...emptyTable,
|
|
383
|
+
children: emptyTable.children.map((row, rowIndex)=>({
|
|
384
|
+
...row,
|
|
385
|
+
children: row.children.map((cell, cellIndex)=>rowIndex === 1 && cellIndex === 1 ? {
|
|
386
|
+
...cell,
|
|
387
|
+
children: [
|
|
388
|
+
paragraph(' ')
|
|
389
|
+
]
|
|
390
|
+
} : cell)
|
|
391
|
+
}))
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
title: 'an embedded inline in another cell',
|
|
396
|
+
table: {
|
|
397
|
+
...emptyTable,
|
|
398
|
+
children: emptyTable.children.map((row, rowIndex)=>({
|
|
399
|
+
...row,
|
|
400
|
+
children: row.children.map((cell, cellIndex)=>rowIndex === 1 && cellIndex === 1 ? {
|
|
401
|
+
...cell,
|
|
402
|
+
children: [
|
|
403
|
+
{
|
|
404
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
405
|
+
children: [
|
|
406
|
+
{
|
|
407
|
+
type: _richtexttypes.INLINES.EMBEDDED_ENTRY,
|
|
408
|
+
data: {
|
|
409
|
+
target: {}
|
|
410
|
+
},
|
|
411
|
+
children: [
|
|
412
|
+
{
|
|
413
|
+
text: ''
|
|
414
|
+
}
|
|
415
|
+
]
|
|
416
|
+
}
|
|
417
|
+
]
|
|
418
|
+
}
|
|
419
|
+
]
|
|
420
|
+
} : cell)
|
|
421
|
+
}))
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
])('keeps a table with $title', ({ table })=>{
|
|
425
|
+
const { editor } = (0, _testutils.createTestEditor)({});
|
|
426
|
+
editor.children = [
|
|
427
|
+
table,
|
|
428
|
+
paragraph()
|
|
429
|
+
];
|
|
430
|
+
editor.tf.select({
|
|
431
|
+
path: [
|
|
432
|
+
0,
|
|
433
|
+
0,
|
|
434
|
+
0,
|
|
435
|
+
0,
|
|
436
|
+
0
|
|
437
|
+
],
|
|
438
|
+
offset: 0
|
|
439
|
+
});
|
|
440
|
+
editor.deleteBackward('character');
|
|
441
|
+
(0, _vitest.expect)(editor.children).toMatchObject([
|
|
442
|
+
table,
|
|
443
|
+
paragraph()
|
|
444
|
+
]);
|
|
445
|
+
});
|
|
446
|
+
(0, _vitest.it)('keeps a table when Backspace is pressed inside a non-first cell', ()=>{
|
|
447
|
+
const { editor } = (0, _testutils.createTestEditor)({});
|
|
448
|
+
const populatedTable = {
|
|
449
|
+
...emptyTable,
|
|
450
|
+
children: emptyTable.children.map((row, rowIndex)=>({
|
|
451
|
+
...row,
|
|
452
|
+
children: row.children.map((cell, cellIndex)=>rowIndex === 0 && cellIndex === 1 ? {
|
|
453
|
+
...cell,
|
|
454
|
+
children: [
|
|
455
|
+
paragraph('x')
|
|
456
|
+
]
|
|
457
|
+
} : cell)
|
|
458
|
+
}))
|
|
459
|
+
};
|
|
460
|
+
editor.children = [
|
|
461
|
+
populatedTable,
|
|
462
|
+
paragraph()
|
|
463
|
+
];
|
|
464
|
+
editor.tf.select({
|
|
465
|
+
path: [
|
|
466
|
+
0,
|
|
467
|
+
0,
|
|
468
|
+
1,
|
|
469
|
+
0,
|
|
470
|
+
0
|
|
471
|
+
],
|
|
472
|
+
offset: 1
|
|
473
|
+
});
|
|
474
|
+
editor.deleteBackward('character');
|
|
475
|
+
(0, _vitest.expect)(editor.children).toMatchObject([
|
|
476
|
+
emptyTable,
|
|
477
|
+
paragraph()
|
|
478
|
+
]);
|
|
479
|
+
});
|
|
480
|
+
(0, _vitest.it)('keeps an unselected preceding table when a range in the following paragraph is deleted', ()=>{
|
|
481
|
+
const { editor } = (0, _testutils.createTestEditor)({});
|
|
482
|
+
editor.children = [
|
|
483
|
+
emptyTable,
|
|
484
|
+
paragraph('selected')
|
|
485
|
+
];
|
|
486
|
+
editor.tf.select({
|
|
487
|
+
anchor: {
|
|
488
|
+
path: [
|
|
489
|
+
1,
|
|
490
|
+
0
|
|
491
|
+
],
|
|
492
|
+
offset: 0
|
|
493
|
+
},
|
|
494
|
+
focus: {
|
|
495
|
+
path: [
|
|
496
|
+
1,
|
|
497
|
+
0
|
|
498
|
+
],
|
|
499
|
+
offset: 8
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
editor.deleteBackward('character');
|
|
503
|
+
(0, _vitest.expect)(editor.children[0]).toMatchObject(emptyTable);
|
|
504
|
+
});
|
|
505
|
+
(0, _vitest.it)('keeps an empty table before a heading when Backspace is pressed in the heading', ()=>{
|
|
506
|
+
const { editor } = (0, _testutils.createTestEditor)({});
|
|
507
|
+
editor.children = [
|
|
508
|
+
emptyTable,
|
|
509
|
+
{
|
|
510
|
+
type: _richtexttypes.BLOCKS.HEADING_1,
|
|
511
|
+
children: [
|
|
512
|
+
{
|
|
513
|
+
text: 'content'
|
|
514
|
+
}
|
|
515
|
+
]
|
|
516
|
+
},
|
|
517
|
+
paragraph()
|
|
518
|
+
];
|
|
519
|
+
editor.tf.select({
|
|
520
|
+
path: [
|
|
521
|
+
1,
|
|
522
|
+
0
|
|
523
|
+
],
|
|
524
|
+
offset: 0
|
|
525
|
+
});
|
|
526
|
+
editor.deleteBackward('character');
|
|
527
|
+
(0, _vitest.expect)(editor.children).toMatchObject([
|
|
528
|
+
emptyTable,
|
|
529
|
+
{
|
|
530
|
+
type: _richtexttypes.BLOCKS.HEADING_1,
|
|
531
|
+
children: [
|
|
532
|
+
{
|
|
533
|
+
text: 'content'
|
|
534
|
+
}
|
|
535
|
+
]
|
|
536
|
+
},
|
|
537
|
+
paragraph()
|
|
538
|
+
]);
|
|
539
|
+
});
|
|
540
|
+
});
|
|
@@ -23,6 +23,7 @@ const _helpers = require("./helpers");
|
|
|
23
23
|
const _insertTableFragment = require("./insertTableFragment");
|
|
24
24
|
const _onKeyDownTable = require("./onKeyDownTable");
|
|
25
25
|
const _tableTracking = require("./tableTracking");
|
|
26
|
+
const _withDeleteBackwardTable = require("./withDeleteBackwardTable");
|
|
26
27
|
const _withInsertFragmentTableOverride = require("./withInsertFragmentTableOverride");
|
|
27
28
|
const createTablePlugin = ()=>(0, _pluginFactories.createTablePlugin)({
|
|
28
29
|
type: _richtexttypes.BLOCKS.TABLE,
|
|
@@ -32,6 +33,7 @@ const createTablePlugin = ()=>(0, _pluginFactories.createTablePlugin)({
|
|
|
32
33
|
withOverrides: (editor, plugin)=>{
|
|
33
34
|
const { normalizeNode } = editor;
|
|
34
35
|
editor = (0, _table.withDeleteTable)(editor);
|
|
36
|
+
editor = (0, _withDeleteBackwardTable.withDeleteBackwardTable)(editor);
|
|
35
37
|
editor = (0, _table.withGetFragmentTable)(editor, plugin);
|
|
36
38
|
editor = (0, _table.withInsertFragmentTable)(editor, plugin);
|
|
37
39
|
editor = (0, _withInsertFragmentTableOverride.withInsertFragmentTableOverride)(editor);
|