feat: add props.onDuplicate (#9117)

* feat: add `props.onDuplicate`

* docs

* clarify docs

* fix docs
This commit is contained in:
David Luzar 2025-02-10 15:20:18 +01:00 committed by GitHub
parent 9e49c9254b
commit c8f4a4cb41
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 51 additions and 4 deletions

View file

@ -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();