Skip to content

Commit

Permalink
fixes multiple blocks creation on image upload from os clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
aryan7081 committed Mar 7, 2024
1 parent 04be832 commit 138a634
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/volto-slate/src/utils/volto-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { v4 as uuid } from 'uuid';
import {
addBlock,
changeBlock,
insertBlock,
blockHasValue,
getBlocksFieldname,
getBlocksLayoutFieldname,
} from '@plone/volto/helpers';
Expand Down Expand Up @@ -53,6 +55,7 @@ export function mergeSlateWithBlockBackward(editor, prevBlock, event) {
let endPoint;

Transforms.insertNodes(editor, { text: '' }, { at: end });

Check failure on line 58 in packages/volto-slate/src/utils/volto-blocks.js

View workflow job for this annotation

GitHub Actions / ESlint

Delete `····⏎`

end = Editor.end(editor, [0]);

Expand Down Expand Up @@ -121,8 +124,16 @@ export function createImageBlock(url, index, props) {
const blocksFieldname = getBlocksFieldname(properties);
const blocksLayoutFieldname = getBlocksLayoutFieldname(properties);

const [id, formData] = addBlock(properties, 'image', index + 1);
const newFormData = changeBlock(formData, id, { '@type': 'image', url });
const currBlockId = properties.blocks_layout.items[index];
const currBlockHasValue = blockHasValue(properties.blocks[currBlockId]);
let id, newFormData;

if (currBlockHasValue) {
[id, newFormData] = addBlock(properties, 'image', index + 1);
newFormData = changeBlock(newFormData, id, { '@type': 'image', url });
} else {
[id, newFormData] = insertBlock(properties, currBlockId, { '@type': 'image', url });

Check failure on line 135 in packages/volto-slate/src/utils/volto-blocks.js

View workflow job for this annotation

GitHub Actions / ESlint

Replace `·'@type':·'image',·url` with `⏎······'@type':·'image',⏎······url,⏎···`
}

ReactDOM.unstable_batchedUpdates(() => {
onChangeField(blocksFieldname, newFormData[blocksFieldname]);
Expand Down

0 comments on commit 138a634

Please sign in to comment.