From 439993569001f8c5dc9e68194c198d430a4ef4bc Mon Sep 17 00:00:00 2001 From: Jason Cheatham Date: Thu, 16 Mar 2023 09:00:41 -0400 Subject: [PATCH] Directly paste ClipboardEvents in Safari (#5362) * Directly paste ClipboardEvents in Safari * Add changeset --- .changeset/lovely-papayas-hug.md | 5 +++++ packages/slate-react/src/components/editable.tsx | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changeset/lovely-papayas-hug.md diff --git a/.changeset/lovely-papayas-hug.md b/.changeset/lovely-papayas-hug.md new file mode 100644 index 000000000..94379af97 --- /dev/null +++ b/.changeset/lovely-papayas-hug.md @@ -0,0 +1,5 @@ +--- +'slate-react': patch +--- + +Fix an issue where pastes in Safari wouldn't include application/x-slate-fragment data diff --git a/packages/slate-react/src/components/editable.tsx b/packages/slate-react/src/components/editable.tsx index 20672e46a..90eb4efc2 100644 --- a/packages/slate-react/src/components/editable.tsx +++ b/packages/slate-react/src/components/editable.tsx @@ -1619,9 +1619,13 @@ export const Editable = (props: EditableProps) => { // fall back to React's `onPaste` here instead. // COMPAT: Firefox, Chrome and Safari don't emit `beforeinput` events // when "paste without formatting" is used, so fallback. (2020/02/20) + // COMPAT: Safari InputEvents generated by pasting won't include + // application/x-slate-fragment items, so use the + // ClipboardEvent here. (2023/03/15) if ( !HAS_BEFORE_INPUT_SUPPORT || - isPlainTextOnlyPaste(event.nativeEvent) + isPlainTextOnlyPaste(event.nativeEvent) || + IS_SAFARI ) { event.preventDefault() ReactEditor.insertData(editor, event.clipboardData)