Handling async navigator.clipboard in handlePaste

hello.

i have a plugin where inside the props-> handleDOMEvents → handlePaste

i have the following.

handlePaste(view, event, slice) {
		fieldsPasteData = null;
		navigator.clipboard.read().then((clipboardItems) => {
			for (const clipboardItem of clipboardItems) {
				for (const type of clipboardItem.types) {
					// Discard any types that are not web custom formats.
					if (!type.startsWith('web ')) {
						continue;
					}
					clipboardItem.getType(type).then((blob) => {
						blob.text().then((reportingMetaData) => {
							// Sanitize the blob if you need to, then process it in your app.
							fieldsPasteData = JSON.parse(reportingMetaData) as            Partial<IFieldProperties>[];
							let fixedSlice = utils.fixFieldsIntegrity(slice, editorSchema);
							fixedSlice = fixNodesGuid(fixedSlice, editorSchema);
						});
					});
				}
			}
		});

}

I’m reading data from the clipboard using navigator.clipboard.read(). It contains a custom MIME type with some data.

The issue is that the text is being pasted into the editor before it reaches the .then() block. Also, the event parameter of handlePaste doesn’t contain the custom MIME type.

How can I make it work?

Return true from the handler to indicate you’re handling the event, and do your async thing.

Thank you Marijn that helped a bunch :slight_smile: