mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
More actionFinalize
Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
This commit is contained in:
parent
be69271fcd
commit
9b643abcee
2 changed files with 54 additions and 47 deletions
|
@ -3,6 +3,7 @@ import { pointFrom } from "@excalidraw/math";
|
||||||
import {
|
import {
|
||||||
maybeBindLinearElement,
|
maybeBindLinearElement,
|
||||||
bindOrUnbindLinearElement,
|
bindOrUnbindLinearElement,
|
||||||
|
isBindingEnabled,
|
||||||
} from "@excalidraw/element/binding";
|
} from "@excalidraw/element/binding";
|
||||||
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
|
import { LinearElementEditor } from "@excalidraw/element/linearElementEditor";
|
||||||
|
|
||||||
|
@ -36,10 +37,43 @@ export const actionFinalize = register({
|
||||||
name: "finalize",
|
name: "finalize",
|
||||||
label: "",
|
label: "",
|
||||||
trackEvent: false,
|
trackEvent: false,
|
||||||
perform: (elements, appState, _, app) => {
|
perform: (elements, appState, data, app) => {
|
||||||
const { interactiveCanvas, focusContainer, scene } = app;
|
const { interactiveCanvas, focusContainer, scene } = app;
|
||||||
|
|
||||||
const elementsMap = scene.getNonDeletedElementsMap();
|
const elementsMap = scene.getNonDeletedElementsMap();
|
||||||
|
console.log("actionFinalize");
|
||||||
|
if (data?.event && appState.selectedLinearElement) {
|
||||||
|
const linearElementEditor = LinearElementEditor.handlePointerUp(
|
||||||
|
data.event,
|
||||||
|
appState.selectedLinearElement,
|
||||||
|
appState,
|
||||||
|
app.scene,
|
||||||
|
);
|
||||||
|
|
||||||
|
const { startBindingElement, endBindingElement } = linearElementEditor;
|
||||||
|
const element = app.scene.getElement(linearElementEditor.elementId);
|
||||||
|
if (isBindingElement(element)) {
|
||||||
|
bindOrUnbindLinearElement(
|
||||||
|
element,
|
||||||
|
startBindingElement,
|
||||||
|
endBindingElement,
|
||||||
|
app.scene,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (linearElementEditor !== appState.selectedLinearElement) {
|
||||||
|
return {
|
||||||
|
appState: {
|
||||||
|
selectedLinearElement: {
|
||||||
|
...linearElementEditor,
|
||||||
|
selectedPointsIndices: null,
|
||||||
|
},
|
||||||
|
suggestedBindings: [],
|
||||||
|
},
|
||||||
|
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (appState.editingLinearElement) {
|
if (appState.editingLinearElement) {
|
||||||
const { elementId, startBindingElement, endBindingElement } =
|
const { elementId, startBindingElement, endBindingElement } =
|
||||||
|
@ -125,7 +159,7 @@ export const actionFinalize = register({
|
||||||
|
|
||||||
if (element && isInvisiblySmallElement(element)) {
|
if (element && isInvisiblySmallElement(element)) {
|
||||||
// TODO: #7348 in theory this gets recorded by the store, so the invisible elements could be restored by the undo/redo, which might be not what we would want
|
// TODO: #7348 in theory this gets recorded by the store, so the invisible elements could be restored by the undo/redo, which might be not what we would want
|
||||||
newElements = newElements.filter((el) => el.id !== element.id);
|
newElements = newElements.filter((el) => el.id !== element!.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the multi point line closes the loop,
|
// If the multi point line closes the loop,
|
||||||
|
@ -150,7 +184,8 @@ export const actionFinalize = register({
|
||||||
isBindingElement(element) &&
|
isBindingElement(element) &&
|
||||||
!isLoop &&
|
!isLoop &&
|
||||||
element.points.length > 1 &&
|
element.points.length > 1 &&
|
||||||
!appState.selectedElementIds[element.id]
|
!appState.selectedElementIds[element.id] &&
|
||||||
|
isBindingEnabled(appState)
|
||||||
) {
|
) {
|
||||||
const [x, y] = LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
const [x, y] = LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
||||||
element,
|
element,
|
||||||
|
|
|
@ -109,13 +109,11 @@ import {
|
||||||
} from "@excalidraw/element/bounds";
|
} from "@excalidraw/element/bounds";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
bindOrUnbindLinearElement,
|
|
||||||
bindOrUnbindLinearElements,
|
bindOrUnbindLinearElements,
|
||||||
fixBindingsAfterDeletion,
|
fixBindingsAfterDeletion,
|
||||||
getHoveredElementForBinding,
|
getHoveredElementForBinding,
|
||||||
isBindingEnabled,
|
isBindingEnabled,
|
||||||
isLinearElementSimpleAndAlreadyBound,
|
isLinearElementSimpleAndAlreadyBound,
|
||||||
maybeBindLinearElement,
|
|
||||||
shouldEnableBindingForPointerEvent,
|
shouldEnableBindingForPointerEvent,
|
||||||
updateBoundElements,
|
updateBoundElements,
|
||||||
getSuggestedBindingsForArrows,
|
getSuggestedBindingsForArrows,
|
||||||
|
@ -2781,7 +2779,6 @@ class App extends React.Component<AppProps, AppState> {
|
||||||
this.updateEmbeddables();
|
this.updateEmbeddables();
|
||||||
const elements = this.scene.getElementsIncludingDeleted();
|
const elements = this.scene.getElementsIncludingDeleted();
|
||||||
const elementsMap = this.scene.getElementsMapIncludingDeleted();
|
const elementsMap = this.scene.getElementsMapIncludingDeleted();
|
||||||
const nonDeletedElementsMap = this.scene.getNonDeletedElementsMap();
|
|
||||||
|
|
||||||
if (!this.state.showWelcomeScreen && !elements.length) {
|
if (!this.state.showWelcomeScreen && !elements.length) {
|
||||||
this.setState({ showWelcomeScreen: true });
|
this.setState({ showWelcomeScreen: true });
|
||||||
|
@ -2935,18 +2932,19 @@ class App extends React.Component<AppProps, AppState> {
|
||||||
isBindingEnabled(this.state) &&
|
isBindingEnabled(this.state) &&
|
||||||
isBindingElement(multiElement, false)
|
isBindingElement(multiElement, false)
|
||||||
) {
|
) {
|
||||||
maybeBindLinearElement(
|
this.actionManager.executeAction(actionFinalize);
|
||||||
multiElement,
|
// maybeBindLinearElement(
|
||||||
this.state,
|
// multiElement,
|
||||||
tupleToCoors(
|
// this.state,
|
||||||
LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
// tupleToCoors(
|
||||||
multiElement,
|
// LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
||||||
-1,
|
// multiElement,
|
||||||
nonDeletedElementsMap,
|
// -1,
|
||||||
),
|
// nonDeletedElementsMap,
|
||||||
),
|
// ),
|
||||||
this.scene,
|
// ),
|
||||||
);
|
// this.scene,
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
this.store.commit(elementsMap, this.state);
|
this.store.commit(elementsMap, this.state);
|
||||||
|
@ -9011,35 +9009,9 @@ class App extends React.Component<AppProps, AppState> {
|
||||||
this.setState({ selectedLinearElement: null });
|
this.setState({ selectedLinearElement: null });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const linearElementEditor = LinearElementEditor.handlePointerUp(
|
this.actionManager.executeAction(actionFinalize, "ui", {
|
||||||
childEvent,
|
event: childEvent,
|
||||||
this.state.selectedLinearElement,
|
});
|
||||||
this.state,
|
|
||||||
this.scene,
|
|
||||||
);
|
|
||||||
|
|
||||||
const { startBindingElement, endBindingElement } =
|
|
||||||
linearElementEditor;
|
|
||||||
const element = this.scene.getElement(linearElementEditor.elementId);
|
|
||||||
if (isBindingElement(element)) {
|
|
||||||
this.actionManager.executeAction(actionFinalize);
|
|
||||||
bindOrUnbindLinearElement(
|
|
||||||
element,
|
|
||||||
startBindingElement,
|
|
||||||
endBindingElement,
|
|
||||||
this.scene,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (linearElementEditor !== this.state.selectedLinearElement) {
|
|
||||||
this.setState({
|
|
||||||
selectedLinearElement: {
|
|
||||||
...linearElementEditor,
|
|
||||||
selectedPointsIndices: null,
|
|
||||||
},
|
|
||||||
suggestedBindings: [],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue