@contentful/field-editor-rich-text 6.6.3 → 6.6.4-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/dist/cjs/internal/__tests__/plainTextPaste.test.js +140 -0
- package/dist/cjs/internal/plate.js +3 -1
- package/dist/esm/internal/__tests__/plainTextPaste.test.js +136 -0
- package/dist/esm/internal/plate.js +4 -2
- package/dist/types/internal/__tests__/plainTextPaste.test.d.ts +1 -0
- package/dist/types/internal/plate.d.ts +2 -2
- package/package.json +2 -2
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _richtexttypes = require("@contentful/rich-text-types");
|
|
6
|
+
const _vitest = require("vitest");
|
|
7
|
+
const _testutils = require("../../test-utils");
|
|
8
|
+
const guardAgainstTextGrowth = (editor)=>{
|
|
9
|
+
const { apply } = editor;
|
|
10
|
+
editor.apply = (operation)=>{
|
|
11
|
+
if (operation.type === 'insert_text' && operation.text.length > 4096) {
|
|
12
|
+
throw new Error('Normalization repeatedly inserted text instead of replacing it');
|
|
13
|
+
}
|
|
14
|
+
apply(operation);
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
(0, _vitest.describe)('plain-text paste with the full plugin set', ()=>{
|
|
18
|
+
_vitest.it.each([
|
|
19
|
+
[
|
|
20
|
+
'Windows line endings',
|
|
21
|
+
'First\r\nSecond',
|
|
22
|
+
[
|
|
23
|
+
'First\nSecond'
|
|
24
|
+
]
|
|
25
|
+
],
|
|
26
|
+
[
|
|
27
|
+
'Windows blank lines',
|
|
28
|
+
'First\r\n\r\nSecond',
|
|
29
|
+
[
|
|
30
|
+
'First\n\nSecond'
|
|
31
|
+
]
|
|
32
|
+
],
|
|
33
|
+
[
|
|
34
|
+
'carriage returns',
|
|
35
|
+
'First\rSecond',
|
|
36
|
+
[
|
|
37
|
+
'FirstSecond'
|
|
38
|
+
]
|
|
39
|
+
],
|
|
40
|
+
[
|
|
41
|
+
'Unix line endings',
|
|
42
|
+
'First\nSecond',
|
|
43
|
+
[
|
|
44
|
+
'First\nSecond'
|
|
45
|
+
]
|
|
46
|
+
],
|
|
47
|
+
[
|
|
48
|
+
'Unix blank lines',
|
|
49
|
+
'First\n\nSecond',
|
|
50
|
+
[
|
|
51
|
+
'First',
|
|
52
|
+
'Second'
|
|
53
|
+
]
|
|
54
|
+
],
|
|
55
|
+
[
|
|
56
|
+
'single-line text',
|
|
57
|
+
'First Second',
|
|
58
|
+
[
|
|
59
|
+
'First Second'
|
|
60
|
+
]
|
|
61
|
+
]
|
|
62
|
+
])('pastes %s without duplicating text', (_description, text, paragraphs)=>{
|
|
63
|
+
const { editor } = (0, _testutils.createTestEditor)({});
|
|
64
|
+
editor.children = [
|
|
65
|
+
{
|
|
66
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
67
|
+
children: [
|
|
68
|
+
{
|
|
69
|
+
text: ''
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
];
|
|
74
|
+
editor.tf.select({
|
|
75
|
+
path: [
|
|
76
|
+
0,
|
|
77
|
+
0
|
|
78
|
+
],
|
|
79
|
+
offset: 0
|
|
80
|
+
});
|
|
81
|
+
guardAgainstTextGrowth(editor);
|
|
82
|
+
editor.insertData({
|
|
83
|
+
types: [
|
|
84
|
+
'text/plain'
|
|
85
|
+
],
|
|
86
|
+
files: [],
|
|
87
|
+
getData: (type)=>type === 'text/plain' ? text : ''
|
|
88
|
+
});
|
|
89
|
+
(0, _vitest.expect)(editor.children.map((node)=>node.children)).toEqual(paragraphs.map((text)=>[
|
|
90
|
+
{
|
|
91
|
+
text
|
|
92
|
+
}
|
|
93
|
+
]));
|
|
94
|
+
(0, _vitest.expect)(editor.children.every((node)=>node.type === _richtexttypes.BLOCKS.PARAGRAPH)).toBe(true);
|
|
95
|
+
});
|
|
96
|
+
(0, _vitest.it)('cleans an existing text node without inserting into the selected paragraph', ()=>{
|
|
97
|
+
const { editor, normalize } = (0, _testutils.createTestEditor)({});
|
|
98
|
+
editor.children = [
|
|
99
|
+
{
|
|
100
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
101
|
+
children: [
|
|
102
|
+
{
|
|
103
|
+
text: 'First\r\nSecond',
|
|
104
|
+
bold: true
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
type: _richtexttypes.BLOCKS.PARAGRAPH,
|
|
110
|
+
children: [
|
|
111
|
+
{
|
|
112
|
+
text: 'Keep this paragraph'
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
];
|
|
117
|
+
editor.tf.select({
|
|
118
|
+
path: [
|
|
119
|
+
1,
|
|
120
|
+
0
|
|
121
|
+
],
|
|
122
|
+
offset: 4
|
|
123
|
+
});
|
|
124
|
+
guardAgainstTextGrowth(editor);
|
|
125
|
+
normalize();
|
|
126
|
+
(0, _vitest.expect)(editor.children.map((node)=>node.children)).toEqual([
|
|
127
|
+
[
|
|
128
|
+
{
|
|
129
|
+
text: 'First\nSecond',
|
|
130
|
+
bold: true
|
|
131
|
+
}
|
|
132
|
+
],
|
|
133
|
+
[
|
|
134
|
+
{
|
|
135
|
+
text: 'Keep this paragraph'
|
|
136
|
+
}
|
|
137
|
+
]
|
|
138
|
+
]);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
@@ -448,7 +448,9 @@ const liftNodes = (editor, ...args)=>editor.tf.liftNodes(...args);
|
|
|
448
448
|
const unwrapNodes = (editor, ...args)=>editor.tf.unwrapNodes(...args);
|
|
449
449
|
const wrapNodes = (editor, ...args)=>editor.tf.wrapNodes(...args);
|
|
450
450
|
const addMark = (editor, ...args)=>editor.tf.addMark(...args);
|
|
451
|
-
const insertText = (editor,
|
|
451
|
+
const insertText = (editor, text, options)=>{
|
|
452
|
+
_slate.Transforms.insertText(editor, text, options);
|
|
453
|
+
};
|
|
452
454
|
const deleteText = (editor, ...args)=>editor.tf.delete(...args);
|
|
453
455
|
const removeNodes = (editor, ...args)=>editor.tf.removeNodes(...args);
|
|
454
456
|
const moveNodes = (editor, ...args)=>editor.tf.moveNodes(...args);
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { BLOCKS } from '@contentful/rich-text-types';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { createTestEditor } from '../../test-utils';
|
|
4
|
+
const guardAgainstTextGrowth = (editor)=>{
|
|
5
|
+
const { apply } = editor;
|
|
6
|
+
editor.apply = (operation)=>{
|
|
7
|
+
if (operation.type === 'insert_text' && operation.text.length > 4096) {
|
|
8
|
+
throw new Error('Normalization repeatedly inserted text instead of replacing it');
|
|
9
|
+
}
|
|
10
|
+
apply(operation);
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
describe('plain-text paste with the full plugin set', ()=>{
|
|
14
|
+
it.each([
|
|
15
|
+
[
|
|
16
|
+
'Windows line endings',
|
|
17
|
+
'First\r\nSecond',
|
|
18
|
+
[
|
|
19
|
+
'First\nSecond'
|
|
20
|
+
]
|
|
21
|
+
],
|
|
22
|
+
[
|
|
23
|
+
'Windows blank lines',
|
|
24
|
+
'First\r\n\r\nSecond',
|
|
25
|
+
[
|
|
26
|
+
'First\n\nSecond'
|
|
27
|
+
]
|
|
28
|
+
],
|
|
29
|
+
[
|
|
30
|
+
'carriage returns',
|
|
31
|
+
'First\rSecond',
|
|
32
|
+
[
|
|
33
|
+
'FirstSecond'
|
|
34
|
+
]
|
|
35
|
+
],
|
|
36
|
+
[
|
|
37
|
+
'Unix line endings',
|
|
38
|
+
'First\nSecond',
|
|
39
|
+
[
|
|
40
|
+
'First\nSecond'
|
|
41
|
+
]
|
|
42
|
+
],
|
|
43
|
+
[
|
|
44
|
+
'Unix blank lines',
|
|
45
|
+
'First\n\nSecond',
|
|
46
|
+
[
|
|
47
|
+
'First',
|
|
48
|
+
'Second'
|
|
49
|
+
]
|
|
50
|
+
],
|
|
51
|
+
[
|
|
52
|
+
'single-line text',
|
|
53
|
+
'First Second',
|
|
54
|
+
[
|
|
55
|
+
'First Second'
|
|
56
|
+
]
|
|
57
|
+
]
|
|
58
|
+
])('pastes %s without duplicating text', (_description, text, paragraphs)=>{
|
|
59
|
+
const { editor } = createTestEditor({});
|
|
60
|
+
editor.children = [
|
|
61
|
+
{
|
|
62
|
+
type: BLOCKS.PARAGRAPH,
|
|
63
|
+
children: [
|
|
64
|
+
{
|
|
65
|
+
text: ''
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
];
|
|
70
|
+
editor.tf.select({
|
|
71
|
+
path: [
|
|
72
|
+
0,
|
|
73
|
+
0
|
|
74
|
+
],
|
|
75
|
+
offset: 0
|
|
76
|
+
});
|
|
77
|
+
guardAgainstTextGrowth(editor);
|
|
78
|
+
editor.insertData({
|
|
79
|
+
types: [
|
|
80
|
+
'text/plain'
|
|
81
|
+
],
|
|
82
|
+
files: [],
|
|
83
|
+
getData: (type)=>type === 'text/plain' ? text : ''
|
|
84
|
+
});
|
|
85
|
+
expect(editor.children.map((node)=>node.children)).toEqual(paragraphs.map((text)=>[
|
|
86
|
+
{
|
|
87
|
+
text
|
|
88
|
+
}
|
|
89
|
+
]));
|
|
90
|
+
expect(editor.children.every((node)=>node.type === BLOCKS.PARAGRAPH)).toBe(true);
|
|
91
|
+
});
|
|
92
|
+
it('cleans an existing text node without inserting into the selected paragraph', ()=>{
|
|
93
|
+
const { editor, normalize } = createTestEditor({});
|
|
94
|
+
editor.children = [
|
|
95
|
+
{
|
|
96
|
+
type: BLOCKS.PARAGRAPH,
|
|
97
|
+
children: [
|
|
98
|
+
{
|
|
99
|
+
text: 'First\r\nSecond',
|
|
100
|
+
bold: true
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
type: BLOCKS.PARAGRAPH,
|
|
106
|
+
children: [
|
|
107
|
+
{
|
|
108
|
+
text: 'Keep this paragraph'
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
}
|
|
112
|
+
];
|
|
113
|
+
editor.tf.select({
|
|
114
|
+
path: [
|
|
115
|
+
1,
|
|
116
|
+
0
|
|
117
|
+
],
|
|
118
|
+
offset: 4
|
|
119
|
+
});
|
|
120
|
+
guardAgainstTextGrowth(editor);
|
|
121
|
+
normalize();
|
|
122
|
+
expect(editor.children.map((node)=>node.children)).toEqual([
|
|
123
|
+
[
|
|
124
|
+
{
|
|
125
|
+
text: 'First\nSecond',
|
|
126
|
+
bold: true
|
|
127
|
+
}
|
|
128
|
+
],
|
|
129
|
+
[
|
|
130
|
+
{
|
|
131
|
+
text: 'Keep this paragraph'
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
]);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as p from 'platejs';
|
|
2
|
-
import { Editor as SlateEditor } from 'slate';
|
|
2
|
+
import { Editor as SlateEditor, Transforms as SlateTransforms } from 'slate';
|
|
3
3
|
export * from 'platejs';
|
|
4
4
|
export { Plate, PlateContent, useEditorRef, useEditorState, usePlateEditor, usePlateSet, useEditorValue, createPlatePlugin } from 'platejs/react';
|
|
5
5
|
export { createPlateEditor, mockPlugin } from './pluginAdapter';
|
|
@@ -128,7 +128,9 @@ export const liftNodes = (editor, ...args)=>editor.tf.liftNodes(...args);
|
|
|
128
128
|
export const unwrapNodes = (editor, ...args)=>editor.tf.unwrapNodes(...args);
|
|
129
129
|
export const wrapNodes = (editor, ...args)=>editor.tf.wrapNodes(...args);
|
|
130
130
|
export const addMark = (editor, ...args)=>editor.tf.addMark(...args);
|
|
131
|
-
export const insertText = (editor,
|
|
131
|
+
export const insertText = (editor, text, options)=>{
|
|
132
|
+
SlateTransforms.insertText(editor, text, options);
|
|
133
|
+
};
|
|
132
134
|
export const deleteText = (editor, ...args)=>editor.tf.delete(...args);
|
|
133
135
|
export const removeNodes = (editor, ...args)=>editor.tf.removeNodes(...args);
|
|
134
136
|
export const moveNodes = (editor, ...args)=>editor.tf.moveNodes(...args);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Domain-facing operations shared by Contentful's editor plugins. */
|
|
2
2
|
import * as p from 'platejs';
|
|
3
|
-
import type { PlateEditor as ContentfulEditor } from './types/editor';
|
|
3
|
+
import type { PlateEditor as ContentfulEditor, TextInsertTextOptions } from './types/editor';
|
|
4
4
|
export * from 'platejs';
|
|
5
5
|
export { Plate, PlateContent, useEditorRef, useEditorState, usePlateEditor, usePlateSet, useEditorValue, createPlatePlugin, } from 'platejs/react';
|
|
6
6
|
export type { TPlateEditor, PlateContentProps, PlateProps } from 'platejs/react';
|
|
@@ -117,7 +117,7 @@ export declare const liftNodes: (editor: ContentfulEditor, options?: p.LiftNodes
|
|
|
117
117
|
export declare const unwrapNodes: (editor: ContentfulEditor, options?: p.UnwrapNodesOptions<import("./types/editor").Value> | undefined) => void;
|
|
118
118
|
export declare const wrapNodes: (editor: ContentfulEditor, element: p.TElement, options?: p.WrapNodesOptions<import("./types/editor").Value> | undefined) => void;
|
|
119
119
|
export declare const addMark: (editor: ContentfulEditor, key: string, value: any) => void;
|
|
120
|
-
export declare const insertText: (editor: ContentfulEditor, text: string, options?:
|
|
120
|
+
export declare const insertText: (editor: ContentfulEditor, text: string, options?: TextInsertTextOptions) => void;
|
|
121
121
|
export declare const deleteText: (editor: ContentfulEditor, options?: p.DeleteTextOptions | undefined) => void;
|
|
122
122
|
export declare const removeNodes: (editor: ContentfulEditor, options?: p.RemoveNodesOptions<import("./types/editor").Value> | undefined) => void;
|
|
123
123
|
export declare const moveNodes: (editor: ContentfulEditor, options: p.MoveNodesOptions<import("./types/editor").Value>) => boolean | void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-rich-text",
|
|
3
|
-
"version": "6.6.
|
|
3
|
+
"version": "6.6.4-canary.0+5528c590",
|
|
4
4
|
"source": "./src/index.tsx",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -96,5 +96,5 @@
|
|
|
96
96
|
"prettier --write"
|
|
97
97
|
]
|
|
98
98
|
},
|
|
99
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "5528c5902d1514706a338ab0224f63cbbf55c642"
|
|
100
100
|
}
|