Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Commit d09ef3e

Browse files
Tee Xiefacebook-github-bot
Tee Xie
authored andcommitted
Fix the issue of draft JS does not do copy and paste correctly with custom entities.
Summary: details are here: #1784 in the comment, nivedita mentioned we need to test this out for intern editor hence not merging the PR. since that comment was made back in Jan, so it's probably gonna take a while for this to be merged into FB codebase. In the mean time this is blocking CMS Editor's embeded CMS use case. So I figured we should do a branching to merge the fix just for CMS Editor. Unfortunately, the logic is pretty deep in the DraftJS stack, so I had to make a couple changes to pass down the copy paste behavior. Differential Revision: D14626028 fbshipit-source-id: 4826ea33abf2618835841200af81e10d707aa23b
1 parent 75a89ff commit d09ef3e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/component/base/DraftEditor.react.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,26 @@ class DraftEditor extends React.Component<DraftEditorProps, State> {
520520
* the active mode.
521521
*/
522522
setMode: DraftEditorModes => void = (mode: DraftEditorModes): void => {
523-
this._handler = handlerMap[mode];
523+
const {onPaste, onCut, onCopy} = this.props;
524+
const editHandler = {...handlerMap.edit};
525+
526+
if (onPaste) {
527+
editHandler.onPaste = onPaste;
528+
}
529+
530+
if (onCut) {
531+
editHandler.onCut = onCut;
532+
}
533+
534+
if (onCopy) {
535+
editHandler.onCopy = onCopy;
536+
}
537+
538+
const handler = {
539+
...handlerMap,
540+
edit: editHandler,
541+
};
542+
this._handler = handler[mode];
524543
};
525544

526545
exitCurrentMode: () => void = (): void => {

src/component/base/DraftEditorProps.js

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import type {BlockNodeRecord} from 'BlockNodeRecord';
1515
import type {DraftBlockRenderMap} from 'DraftBlockRenderMap';
1616
import type {DraftDragType} from 'DraftDragType';
17+
import type DraftEditor from 'DraftEditor.react';
1718
import type {DraftEditorCommand} from 'DraftEditorCommand';
1819
import type {DraftHandleValue} from 'DraftHandleValue';
1920
import type {DraftInlineStyle} from 'DraftInlineStyle';
@@ -178,6 +179,12 @@ export type DraftEditorProps = {
178179
// an element tag and an optional react element wrapper. This configuration
179180
// is used for both rendering and paste processing.
180181
blockRenderMap: DraftBlockRenderMap,
182+
183+
// Overrides for cut, copy & paste, which can be used to implement custom
184+
// behavior like entity cut/copy/paste (see PR #1784)."
185+
onPaste?: (DraftEditor, SyntheticClipboardEvent<>) => void,
186+
onCut?: (DraftEditor, SyntheticClipboardEvent<>) => void,
187+
onCopy?: (DraftEditor, SyntheticClipboardEvent<>) => void,
181188
};
182189

183190
export type DraftEditorDefaultProps = {

0 commit comments

Comments
 (0)