Skip to content

Commit

Permalink
Fix the right order of parameters in normalizeExternalData.js (#5347)
Browse files Browse the repository at this point in the history
Co-authored-by: Alin Voinea <[email protected]>
Co-authored-by: Claudia Ifrim <[email protected]>
Co-authored-by: David Glick <[email protected]>
Co-authored-by: Víctor Fernández de Alba <[email protected]>
  • Loading branch information
5 people authored Dec 1, 2023
1 parent b451fcd commit 9cfaa85
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/volto-slate/news/5347.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the right order of parameters in normalizeExternalData.js @dobri1408
4 changes: 3 additions & 1 deletion packages/volto-slate/src/editor/extensions/insertData.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ export const insertData = (editor) => {
if (Editor.string(editor, [])) {
if (
Array.isArray(fragment) &&
fragment.findIndex((b) => Editor.isInline(b) || Text.isText(b)) > -1
fragment.findIndex(
(b) => Editor.isInline(editor, b) || Text.isText(b),
) > -1
) {
// console.log('insert fragment', fragment);
// TODO: we want normalization also when dealing with fragments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { normalizeExternalData as normalize } from '@plone/volto-slate/utils';

export function normalizeExternalData(editor) {
editor.normalizeExternalData = (fragment) => {
return normalize(fragment);
return normalize(editor, fragment);
};
return editor;
}
8 changes: 6 additions & 2 deletions packages/volto-slate/src/utils/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,19 @@ export const normalizeExternalData = (editor, nodes) => {
// put all the non-blocks (e.g. images which are inline Elements) inside p-s
Editor.withoutNormalizing(fakeEditor, () => {
//for htmlSlateWidget compatibility
if (nodes && !Editor.isBlock(fakeEditor, nodes[0]))
if (
nodes &&
(!Editor.isBlock(fakeEditor, nodes[0]) || Text.isText(nodes[0]))
)
Transforms.wrapNodes(
fakeEditor,
{ type: 'p' },
{
at: [],
match: (node, path) =>
(!Editor.isEditor(node) && !Editor.isBlock(fakeEditor, node)) ||
fakeEditor.isInline(node),
fakeEditor.isInline(node) ||
Text.isText(node),
mode: 'highest',
},
);
Expand Down
1 change: 1 addition & 0 deletions packages/volto/news/5347.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the right order of parameters in normalizeExternalData.js @dobri1408

0 comments on commit 9cfaa85

Please sign in to comment.