@contentful/field-editor-rich-text 6.6.4-canary.0 → 6.6.4

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.
@@ -281,3 +281,60 @@ _vitest.describe.each(linkOptions)('$type', (options)=>{
281
281
  });
282
282
  });
283
283
  });
284
+ (0, _vitest.it)('replaces the label of an existing link', ()=>{
285
+ const { editor } = (0, _createTestEditor.createTestEditor)({});
286
+ editor.children = [
287
+ {
288
+ type: _richtexttypes.BLOCKS.PARAGRAPH,
289
+ children: [
290
+ {
291
+ text: ''
292
+ },
293
+ {
294
+ type: _richtexttypes.INLINES.HYPERLINK,
295
+ data: {
296
+ uri: 'https://old.example'
297
+ },
298
+ children: [
299
+ {
300
+ text: 'old'
301
+ }
302
+ ]
303
+ },
304
+ {
305
+ text: ''
306
+ }
307
+ ]
308
+ }
309
+ ];
310
+ editor.tf.select({
311
+ path: [
312
+ 0,
313
+ 1,
314
+ 0
315
+ ],
316
+ offset: 1
317
+ });
318
+ editor.tf.withoutNormalizing(()=>{
319
+ (0, _editor.wrapLink)(editor, {
320
+ type: _richtexttypes.INLINES.HYPERLINK,
321
+ url: 'https://new.example',
322
+ text: 'new',
323
+ path: [
324
+ 0,
325
+ 1
326
+ ]
327
+ });
328
+ });
329
+ (0, _vitest.expect)(editor.children[0].children[1]).toEqual({
330
+ type: _richtexttypes.INLINES.HYPERLINK,
331
+ data: {
332
+ uri: 'https://new.example'
333
+ },
334
+ children: [
335
+ {
336
+ text: 'new'
337
+ }
338
+ ]
339
+ });
340
+ });
@@ -138,3 +138,52 @@ const guardAgainstTextGrowth = (editor)=>{
138
138
  ]);
139
139
  });
140
140
  });
141
+ (0, _vitest.it)('inserts text at an explicit location instead of the caret', ()=>{
142
+ const { editor } = (0, _testutils.createTestEditor)({});
143
+ editor.children = [
144
+ {
145
+ type: _richtexttypes.BLOCKS.PARAGRAPH,
146
+ children: [
147
+ {
148
+ text: 'aaa'
149
+ }
150
+ ]
151
+ },
152
+ {
153
+ type: _richtexttypes.BLOCKS.PARAGRAPH,
154
+ children: [
155
+ {
156
+ text: 'bbb'
157
+ }
158
+ ]
159
+ }
160
+ ];
161
+ editor.tf.select({
162
+ path: [
163
+ 1,
164
+ 0
165
+ ],
166
+ offset: 1
167
+ });
168
+ editor.tf.insertText('X', {
169
+ at: {
170
+ path: [
171
+ 0,
172
+ 0
173
+ ],
174
+ offset: 0
175
+ }
176
+ });
177
+ (0, _vitest.expect)(editor.children.map((node)=>node.children)).toEqual([
178
+ [
179
+ {
180
+ text: 'Xaaa'
181
+ }
182
+ ],
183
+ [
184
+ {
185
+ text: 'bbb'
186
+ }
187
+ ]
188
+ ]);
189
+ });
@@ -448,9 +448,7 @@ 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, text, options)=>{
452
- _slate.Transforms.insertText(editor, text, options);
453
- };
451
+ const insertText = (editor, ...args)=>editor.tf.insertText(...args);
454
452
  const deleteText = (editor, ...args)=>editor.tf.delete(...args);
455
453
  const removeNodes = (editor, ...args)=>editor.tf.removeNodes(...args);
456
454
  const moveNodes = (editor, ...args)=>editor.tf.moveNodes(...args);
@@ -60,7 +60,7 @@ const unwrapTextContainerAtStart = (nodes)=>{
60
60
  };
61
61
  const insertListFragment = (editor)=>{
62
62
  const { insertFragment } = editor;
63
- return (fragment)=>{
63
+ return (fragment, options)=>{
64
64
  if (!editor.selection) {
65
65
  return;
66
66
  }
@@ -93,6 +93,6 @@ const insertListFragment = (editor)=>{
93
93
  },
94
94
  ...fragment
95
95
  ] : fragment;
96
- return insertFragment(filtered);
96
+ return insertFragment(filtered, options);
97
97
  };
98
98
  };
@@ -19,9 +19,9 @@ const withList = (editor)=>{
19
19
  if ((0, _list.deleteForwardList)(editor, deleteForward, unit)) return;
20
20
  deleteForward(unit);
21
21
  };
22
- editor.deleteFragment = ()=>{
22
+ editor.deleteFragment = (options)=>{
23
23
  if ((0, _list.deleteFragmentList)(editor)) return;
24
- deleteFragment();
24
+ deleteFragment(options);
25
25
  };
26
26
  editor.insertBreak = (0, _insertListBreak.insertListBreak)(editor);
27
27
  editor.insertFragment = (0, _insertListFragment.insertListFragment)(editor);
@@ -14,7 +14,7 @@ const _queries = require("../../internal/queries");
14
14
  const _transforms = require("../../internal/transforms");
15
15
  const withQuote = (editor)=>{
16
16
  const { insertFragment } = editor;
17
- editor.insertFragment = (fragment)=>{
17
+ editor.insertFragment = (fragment, options)=>{
18
18
  const startingNode = fragment.length && fragment[0];
19
19
  const startsWithBlockquote = _slate.Element.isElement(startingNode) && startingNode.type === _richtexttypes.BLOCKS.QUOTE;
20
20
  const containerEntry = (0, _queries.getAboveNode)(editor, {
@@ -42,7 +42,7 @@ const withQuote = (editor)=>{
42
42
  return;
43
43
  }
44
44
  }
45
- insertFragment(fragment);
45
+ insertFragment(fragment, options);
46
46
  };
47
47
  return editor;
48
48
  };
@@ -34,7 +34,7 @@ const trimUnnecessaryTableWrapper = (node)=>{
34
34
  };
35
35
  const insertTableFragment = (editor)=>{
36
36
  const { insertFragment } = editor;
37
- return (fragments)=>{
37
+ return (fragments, options)=>{
38
38
  if (!editor.selection) {
39
39
  return;
40
40
  }
@@ -45,6 +45,6 @@ const insertTableFragment = (editor)=>{
45
45
  if (isInsertingTable && isTableFirstFragment && currentLineHasText) {
46
46
  (0, _editor.insertEmptyParagraph)(editor);
47
47
  }
48
- return insertFragment(fragments);
48
+ return insertFragment(fragments, options);
49
49
  };
50
50
  };
@@ -24,9 +24,9 @@ function createTextPlugin(restrictedMarks = []) {
24
24
  },
25
25
  withOverrides: (editor)=>{
26
26
  const { insertText } = editor;
27
- editor.insertText = (text)=>{
27
+ editor.insertText = (text, options)=>{
28
28
  const { selection } = editor;
29
- if (selection && (0, _queries.isRangeCollapsed)(selection)) {
29
+ if (!options?.at && selection && (0, _queries.isRangeCollapsed)(selection)) {
30
30
  const inlinePath = (0, _queries.getAboveNode)(editor, {
31
31
  match: (n)=>(0, _queries.isInline)(editor, n),
32
32
  mode: 'highest'
@@ -41,7 +41,7 @@ function createTextPlugin(restrictedMarks = []) {
41
41
  }
42
42
  }
43
43
  }
44
- return insertText(text);
44
+ return insertText(text, options);
45
45
  };
46
46
  const { deleteForward, deleteBackward } = editor;
47
47
  editor.deleteBackward = (unit)=>{
@@ -15,7 +15,7 @@ const createVoidsPlugin = ()=>({
15
15
  key: 'VoidsPlugin',
16
16
  withOverrides: (editor)=>{
17
17
  const { insertFragment } = editor;
18
- editor.insertFragment = (fragment)=>{
18
+ editor.insertFragment = (fragment, options)=>{
19
19
  if (fragment.length > 0 && fragment.every((node)=>(0, _queries.isElement)(node) && editor.api.isBlock(node) && editor.api.isVoid(node))) {
20
20
  const block = editor.api.block();
21
21
  const replaceEmptyParagraph = editor.api.isCollapsed() && block && block[1].length === 1 && block[0].type === _richtexttypes.BLOCKS.PARAGRAPH && editor.api.isEmpty(block[0]);
@@ -36,7 +36,7 @@ const createVoidsPlugin = ()=>({
36
36
  });
37
37
  return;
38
38
  }
39
- insertFragment(fragment);
39
+ insertFragment(fragment, options);
40
40
  };
41
41
  return editor;
42
42
  },
@@ -277,3 +277,60 @@ describe.each(linkOptions)('$type', (options)=>{
277
277
  });
278
278
  });
279
279
  });
280
+ it('replaces the label of an existing link', ()=>{
281
+ const { editor } = createTestEditor({});
282
+ editor.children = [
283
+ {
284
+ type: BLOCKS.PARAGRAPH,
285
+ children: [
286
+ {
287
+ text: ''
288
+ },
289
+ {
290
+ type: INLINES.HYPERLINK,
291
+ data: {
292
+ uri: 'https://old.example'
293
+ },
294
+ children: [
295
+ {
296
+ text: 'old'
297
+ }
298
+ ]
299
+ },
300
+ {
301
+ text: ''
302
+ }
303
+ ]
304
+ }
305
+ ];
306
+ editor.tf.select({
307
+ path: [
308
+ 0,
309
+ 1,
310
+ 0
311
+ ],
312
+ offset: 1
313
+ });
314
+ editor.tf.withoutNormalizing(()=>{
315
+ wrapLink(editor, {
316
+ type: INLINES.HYPERLINK,
317
+ url: 'https://new.example',
318
+ text: 'new',
319
+ path: [
320
+ 0,
321
+ 1
322
+ ]
323
+ });
324
+ });
325
+ expect(editor.children[0].children[1]).toEqual({
326
+ type: INLINES.HYPERLINK,
327
+ data: {
328
+ uri: 'https://new.example'
329
+ },
330
+ children: [
331
+ {
332
+ text: 'new'
333
+ }
334
+ ]
335
+ });
336
+ });
@@ -134,3 +134,52 @@ describe('plain-text paste with the full plugin set', ()=>{
134
134
  ]);
135
135
  });
136
136
  });
137
+ it('inserts text at an explicit location instead of the caret', ()=>{
138
+ const { editor } = createTestEditor({});
139
+ editor.children = [
140
+ {
141
+ type: BLOCKS.PARAGRAPH,
142
+ children: [
143
+ {
144
+ text: 'aaa'
145
+ }
146
+ ]
147
+ },
148
+ {
149
+ type: BLOCKS.PARAGRAPH,
150
+ children: [
151
+ {
152
+ text: 'bbb'
153
+ }
154
+ ]
155
+ }
156
+ ];
157
+ editor.tf.select({
158
+ path: [
159
+ 1,
160
+ 0
161
+ ],
162
+ offset: 1
163
+ });
164
+ editor.tf.insertText('X', {
165
+ at: {
166
+ path: [
167
+ 0,
168
+ 0
169
+ ],
170
+ offset: 0
171
+ }
172
+ });
173
+ expect(editor.children.map((node)=>node.children)).toEqual([
174
+ [
175
+ {
176
+ text: 'Xaaa'
177
+ }
178
+ ],
179
+ [
180
+ {
181
+ text: 'bbb'
182
+ }
183
+ ]
184
+ ]);
185
+ });
@@ -1,5 +1,5 @@
1
1
  import * as p from 'platejs';
2
- import { Editor as SlateEditor, Transforms as SlateTransforms } from 'slate';
2
+ import { Editor as SlateEditor } 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,9 +128,7 @@ 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, text, options)=>{
132
- SlateTransforms.insertText(editor, text, options);
133
- };
131
+ export const insertText = (editor, ...args)=>editor.tf.insertText(...args);
134
132
  export const deleteText = (editor, ...args)=>editor.tf.delete(...args);
135
133
  export const removeNodes = (editor, ...args)=>editor.tf.removeNodes(...args);
136
134
  export const moveNodes = (editor, ...args)=>editor.tf.moveNodes(...args);
@@ -50,7 +50,7 @@ const unwrapTextContainerAtStart = (nodes)=>{
50
50
  };
51
51
  export const insertListFragment = (editor)=>{
52
52
  const { insertFragment } = editor;
53
- return (fragment)=>{
53
+ return (fragment, options)=>{
54
54
  if (!editor.selection) {
55
55
  return;
56
56
  }
@@ -83,6 +83,6 @@ export const insertListFragment = (editor)=>{
83
83
  },
84
84
  ...fragment
85
85
  ] : fragment;
86
- return insertFragment(filtered);
86
+ return insertFragment(filtered, options);
87
87
  };
88
88
  };
@@ -9,9 +9,9 @@ export const withList = (editor)=>{
9
9
  if (deleteForwardList(editor, deleteForward, unit)) return;
10
10
  deleteForward(unit);
11
11
  };
12
- editor.deleteFragment = ()=>{
12
+ editor.deleteFragment = (options)=>{
13
13
  if (deleteFragmentList(editor)) return;
14
- deleteFragment();
14
+ deleteFragment(options);
15
15
  };
16
16
  editor.insertBreak = insertListBreak(editor);
17
17
  editor.insertFragment = insertListFragment(editor);
@@ -4,7 +4,7 @@ import { getAboveNode, getText } from '../../internal/queries';
4
4
  import { deleteText, insertNodes } from '../../internal/transforms';
5
5
  export const withQuote = (editor)=>{
6
6
  const { insertFragment } = editor;
7
- editor.insertFragment = (fragment)=>{
7
+ editor.insertFragment = (fragment, options)=>{
8
8
  const startingNode = fragment.length && fragment[0];
9
9
  const startsWithBlockquote = Element.isElement(startingNode) && startingNode.type === BLOCKS.QUOTE;
10
10
  const containerEntry = getAboveNode(editor, {
@@ -32,7 +32,7 @@ export const withQuote = (editor)=>{
32
32
  return;
33
33
  }
34
34
  }
35
- insertFragment(fragment);
35
+ insertFragment(fragment, options);
36
36
  };
37
37
  return editor;
38
38
  };
@@ -24,7 +24,7 @@ const trimUnnecessaryTableWrapper = (node)=>{
24
24
  };
25
25
  export const insertTableFragment = (editor)=>{
26
26
  const { insertFragment } = editor;
27
- return (fragments)=>{
27
+ return (fragments, options)=>{
28
28
  if (!editor.selection) {
29
29
  return;
30
30
  }
@@ -35,6 +35,6 @@ export const insertTableFragment = (editor)=>{
35
35
  if (isInsertingTable && isTableFirstFragment && currentLineHasText) {
36
36
  insertEmptyParagraph(editor);
37
37
  }
38
- return insertFragment(fragments);
38
+ return insertFragment(fragments, options);
39
39
  };
40
40
  };
@@ -14,9 +14,9 @@ export function createTextPlugin(restrictedMarks = []) {
14
14
  },
15
15
  withOverrides: (editor)=>{
16
16
  const { insertText } = editor;
17
- editor.insertText = (text)=>{
17
+ editor.insertText = (text, options)=>{
18
18
  const { selection } = editor;
19
- if (selection && isRangeCollapsed(selection)) {
19
+ if (!options?.at && selection && isRangeCollapsed(selection)) {
20
20
  const inlinePath = getAboveNode(editor, {
21
21
  match: (n)=>isInline(editor, n),
22
22
  mode: 'highest'
@@ -31,7 +31,7 @@ export function createTextPlugin(restrictedMarks = []) {
31
31
  }
32
32
  }
33
33
  }
34
- return insertText(text);
34
+ return insertText(text, options);
35
35
  };
36
36
  const { deleteForward, deleteBackward } = editor;
37
37
  editor.deleteBackward = (unit)=>{
@@ -5,7 +5,7 @@ export const createVoidsPlugin = ()=>({
5
5
  key: 'VoidsPlugin',
6
6
  withOverrides: (editor)=>{
7
7
  const { insertFragment } = editor;
8
- editor.insertFragment = (fragment)=>{
8
+ editor.insertFragment = (fragment, options)=>{
9
9
  if (fragment.length > 0 && fragment.every((node)=>isElement(node) && editor.api.isBlock(node) && editor.api.isVoid(node))) {
10
10
  const block = editor.api.block();
11
11
  const replaceEmptyParagraph = editor.api.isCollapsed() && block && block[1].length === 1 && block[0].type === BLOCKS.PARAGRAPH && editor.api.isEmpty(block[0]);
@@ -26,7 +26,7 @@ export const createVoidsPlugin = ()=>({
26
26
  });
27
27
  return;
28
28
  }
29
- insertFragment(fragment);
29
+ insertFragment(fragment, options);
30
30
  };
31
31
  return editor;
32
32
  },
@@ -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, TextInsertTextOptions } from './types/editor';
3
+ import type { PlateEditor as ContentfulEditor } 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?: TextInsertTextOptions) => void;
120
+ export declare const insertText: (editor: ContentfulEditor, text: string, options?: p.InsertTextOptions | undefined) => 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;
@@ -1,2 +1,2 @@
1
1
  import { PlateEditor, Node } from '../../internal/types';
2
- export declare const insertListFragment: (editor: PlateEditor) => (fragment: Node[]) => void;
2
+ export declare const insertListFragment: (editor: PlateEditor) => (fragment: Node[], options?: Parameters<PlateEditor['insertFragment']>[1]) => void;
@@ -1,3 +1,3 @@
1
1
  import { Node } from '../../internal/types';
2
2
  import { PlateEditor } from '../../internal/types';
3
- export declare const insertTableFragment: (editor: PlateEditor) => (fragments: Node[]) => void;
3
+ export declare const insertTableFragment: (editor: PlateEditor) => (fragments: Node[], options?: Parameters<PlateEditor['insertFragment']>[1]) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-rich-text",
3
- "version": "6.6.4-canary.0+5528c590",
3
+ "version": "6.6.4",
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": "5528c5902d1514706a338ab0224f63cbbf55c642"
99
+ "gitHead": "67b16bd52fc17ed8bd578d6f405e68dc49e2e5a4"
100
100
  }