feat: add props.onDuplicate (#9117)

* feat: add `props.onDuplicate`

* docs

* clarify docs

* fix docs
This commit is contained in:
David Luzar
2025-02-10 14:20:18 +00:00
committed by GitHub
parent 9e49c9254b
commit c8f4a4cb41
4 changed files with 51 additions and 4 deletions
@@ -69,8 +69,20 @@ export const actionDuplicateSelection = register({
}
}
const nextState = duplicateElements(elements, appState);
if (app.props.onDuplicate && nextState.elements) {
const mappedElements = app.props.onDuplicate(
nextState.elements,
elements,
);
if (mappedElements) {
nextState.elements = mappedElements;
}
}
return {
...duplicateElements(elements, appState),
...nextState,
storeAction: StoreAction.CAPTURE,
};
},
@@ -92,7 +104,7 @@ export const actionDuplicateSelection = register({
const duplicateElements = (
elements: readonly ExcalidrawElement[],
appState: AppState,
): Partial<ActionResult> => {
): Partial<Exclude<ActionResult, false>> => {
// ---------------------------------------------------------------------------
const groupIdMap = new Map();