Merge remote-tracking branch 'origin/master' into aakansha-create-text-containers-programmatically

This commit is contained in:
Aakansha Doshi
2023-07-17 12:56:35 +05:30
27 changed files with 454 additions and 3758 deletions

View File

@@ -331,6 +331,7 @@ import { actionWrapTextInContainer } from "../actions/actionBoundText";
import BraveMeasureTextError from "./BraveMeasureTextError";
import { activeEyeDropperAtom } from "./EyeDropper";
import { convertToExcalidrawElements } from "../data/transform";
import { isSidebarDockedAtom } from "./Sidebar/Sidebar";
const AppContext = React.createContext<AppClassProperties>(null!);
const AppPropsContext = React.createContext<AppProps>(null!);
@@ -474,8 +475,6 @@ class App extends React.Component<AppProps, AppState> {
name,
width: window.innerWidth,
height: window.innerHeight,
showHyperlinkPopup: false,
defaultSidebarDockedPreference: false,
};
this.id = nanoid();
@@ -800,10 +799,7 @@ class App extends React.Component<AppProps, AppState> {
};
public render() {
const selectedElement = getSelectedElements(
this.scene.getNonDeletedElements(),
this.state,
);
const selectedElement = this.scene.getSelectedElements(this.state);
const { renderTopRightUI, renderCustomStats } = this.props;
return (
@@ -860,6 +856,7 @@ class App extends React.Component<AppProps, AppState> {
!this.state.zenModeEnabled &&
!this.scene.getElementsIncludingDeleted().length
}
app={this}
>
{this.props.children}
</LayerUI>
@@ -965,10 +962,7 @@ class App extends React.Component<AppProps, AppState> {
const shouldUpdateStrokeColor =
(type === "background" && event.altKey) ||
(type === "stroke" && !event.altKey);
const selectedElements = getSelectedElements(
this.scene.getElementsIncludingDeleted(),
this.state,
);
const selectedElements = this.scene.getSelectedElements(this.state);
if (
!selectedElements.length ||
this.state.activeTool.type !== "selection"
@@ -2034,7 +2028,7 @@ class App extends React.Component<AppProps, AppState> {
openSidebar:
this.state.openSidebar &&
this.device.canDeviceFitSidebar &&
this.state.defaultSidebarDockedPreference
jotaiStore.get(isSidebarDockedAtom)
? this.state.openSidebar
: null,
selectedElementIds: nextElementsToSelect.reduce(
@@ -2050,6 +2044,7 @@ class App extends React.Component<AppProps, AppState> {
},
this.scene.getNonDeletedElements(),
this.state,
this,
),
() => {
if (opts.files) {
@@ -2614,14 +2609,11 @@ class App extends React.Component<AppProps, AppState> {
offsetY = step;
}
const selectedElements = getSelectedElements(
this.scene.getNonDeletedElements(),
this.state,
{
includeBoundTextElement: true,
includeElementsInFrames: true,
},
);
const selectedElements = this.scene.getSelectedElements({
selectedElementIds: this.state.selectedElementIds,
includeBoundTextElement: true,
includeElementsInFrames: true,
});
selectedElements.forEach((element) => {
mutateElement(element, {
@@ -2638,10 +2630,7 @@ class App extends React.Component<AppProps, AppState> {
event.preventDefault();
} else if (event.key === KEYS.ENTER) {
const selectedElements = getSelectedElements(
this.scene.getNonDeletedElements(),
this.state,
);
const selectedElements = this.scene.getSelectedElements(this.state);
if (selectedElements.length === 1) {
const selectedElement = selectedElements[0];
if (event[KEYS.CTRL_OR_CMD]) {
@@ -2717,10 +2706,7 @@ class App extends React.Component<AppProps, AppState> {
!event.altKey &&
!event[KEYS.CTRL_OR_CMD]
) {
const selectedElements = getSelectedElements(
this.scene.getNonDeletedElements(),
this.state,
);
const selectedElements = this.scene.getSelectedElements(this.state);
if (
this.state.activeTool.type === "selection" &&
!selectedElements.length
@@ -2792,10 +2778,7 @@ class App extends React.Component<AppProps, AppState> {
this.setState({ isBindingEnabled: true });
}
if (isArrowKey(event.key)) {
const selectedElements = getSelectedElements(
this.scene.getNonDeletedElements(),
this.state,
);
const selectedElements = this.scene.getSelectedElements(this.state);
isBindingEnabled(this.state)
? bindOrUnbindSelectedElements(selectedElements)
: unbindLinearElements(selectedElements);
@@ -3145,10 +3128,7 @@ class App extends React.Component<AppProps, AppState> {
}
let existingTextElement: NonDeleted<ExcalidrawTextElement> | null = null;
const selectedElements = getSelectedElements(
this.scene.getNonDeletedElements(),
this.state,
);
const selectedElements = this.scene.getSelectedElements(this.state);
if (selectedElements.length === 1) {
if (isTextElement(selectedElements[0])) {
@@ -3278,10 +3258,7 @@ class App extends React.Component<AppProps, AppState> {
return;
}
const selectedElements = getSelectedElements(
this.scene.getNonDeletedElements(),
this.state,
);
const selectedElements = this.scene.getSelectedElements(this.state);
if (selectedElements.length === 1 && isLinearElement(selectedElements[0])) {
if (
@@ -3332,6 +3309,7 @@ class App extends React.Component<AppProps, AppState> {
},
this.scene.getNonDeletedElements(),
prevState,
this,
),
);
return;
@@ -3708,7 +3686,7 @@ class App extends React.Component<AppProps, AppState> {
const elements = this.scene.getNonDeletedElements();
const selectedElements = getSelectedElements(elements, this.state);
const selectedElements = this.scene.getSelectedElements(this.state);
if (
selectedElements.length === 1 &&
!isOverScrollBar &&
@@ -4411,10 +4389,7 @@ class App extends React.Component<AppProps, AppState> {
event: React.PointerEvent<HTMLElement>,
): PointerDownState {
const origin = viewportCoordsToSceneCoords(event, this.state);
const selectedElements = getSelectedElements(
this.scene.getNonDeletedElements(),
this.state,
);
const selectedElements = this.scene.getSelectedElements(this.state);
const [minX, minY, maxX, maxY] = getCommonBounds(selectedElements);
return {
@@ -4532,7 +4507,7 @@ class App extends React.Component<AppProps, AppState> {
): boolean => {
if (this.state.activeTool.type === "selection") {
const elements = this.scene.getNonDeletedElements();
const selectedElements = getSelectedElements(elements, this.state);
const selectedElements = this.scene.getSelectedElements(this.state);
if (selectedElements.length === 1 && !this.state.editingLinearElement) {
const elementWithTransformHandleType =
getElementWithTransformHandleType(
@@ -4775,6 +4750,7 @@ class App extends React.Component<AppProps, AppState> {
},
this.scene.getNonDeletedElements(),
prevState,
this,
);
});
pointerDownState.hit.wasAddedToSelection = true;
@@ -5202,7 +5178,7 @@ class App extends React.Component<AppProps, AppState> {
if (pointerDownState.drag.offset === null) {
pointerDownState.drag.offset = tupleToCoors(
getDragOffsetXY(
getSelectedElements(this.scene.getNonDeletedElements(), this.state),
this.scene.getSelectedElements(this.state),
pointerDownState.origin.x,
pointerDownState.origin.y,
),
@@ -5365,10 +5341,7 @@ class App extends React.Component<AppProps, AppState> {
pointerDownState.hit.hasHitCommonBoundingBoxOfSelectedElements) &&
!isSelectingPointsInLineEditor
) {
const selectedElements = getSelectedElements(
this.scene.getNonDeletedElements(),
this.state,
);
const selectedElements = this.scene.getSelectedElements(this.state);
if (selectedElements.every((element) => element.locked)) {
return;
@@ -5439,14 +5412,18 @@ class App extends React.Component<AppProps, AppState> {
const groupIdMap = new Map();
const oldIdToDuplicatedId = new Map();
const hitElement = pointerDownState.hit.element;
const elements = this.scene.getElementsIncludingDeleted();
const selectedElementIds = new Set(
getSelectedElements(elements, this.state, {
includeBoundTextElement: true,
includeElementsInFrames: true,
}).map((element) => element.id),
this.scene
.getSelectedElements({
selectedElementIds: this.state.selectedElementIds,
includeBoundTextElement: true,
includeElementsInFrames: true,
})
.map((element) => element.id),
);
const elements = this.scene.getNonDeletedElements();
for (const element of elements) {
if (
selectedElementIds.has(element.id) ||
@@ -5588,6 +5565,7 @@ class App extends React.Component<AppProps, AppState> {
},
this.scene.getNonDeletedElements(),
prevState,
this,
),
);
}
@@ -5645,6 +5623,7 @@ class App extends React.Component<AppProps, AppState> {
},
this.scene.getNonDeletedElements(),
prevState,
this,
);
});
}
@@ -5744,10 +5723,7 @@ class App extends React.Component<AppProps, AppState> {
pointerDownState.hit?.element?.id !==
this.state.selectedLinearElement.elementId
) {
const selectedELements = getSelectedElements(
this.scene.getNonDeletedElements(),
this.state,
);
const selectedELements = this.scene.getSelectedElements(this.state);
// set selectedLinearElement to null if there is more than one element selected since we don't want to show linear element handles
if (selectedELements.length > 1) {
this.setState({ selectedLinearElement: null });
@@ -5989,10 +5965,7 @@ class App extends React.Component<AppProps, AppState> {
const topLayerFrame =
this.getTopLayerFrameAtSceneCoords(sceneCoords);
const selectedElements = getSelectedElements(
this.scene.getNonDeletedElements(),
this.state,
);
const selectedElements = this.scene.getSelectedElements(this.state);
let nextElements = this.scene.getElementsIncludingDeleted();
const updateGroupIdsAfterEditingGroup = (
@@ -6071,6 +6044,7 @@ class App extends React.Component<AppProps, AppState> {
nextElements = updateFrameMembershipOfSelectedElements(
this.scene.getElementsIncludingDeleted(),
this.state,
this,
);
this.scene.replaceAllElements(nextElements);
@@ -6115,14 +6089,14 @@ class App extends React.Component<AppProps, AppState> {
let nextElements = updateFrameMembershipOfSelectedElements(
this.scene.getElementsIncludingDeleted(),
this.state,
this,
);
const selectedFrames = getSelectedElements(
this.scene.getElementsIncludingDeleted(),
this.state,
).filter(
(element) => element.type === "frame",
) as ExcalidrawFrameElement[];
const selectedFrames = this.scene
.getSelectedElements(this.state)
.filter(
(element) => element.type === "frame",
) as ExcalidrawFrameElement[];
for (const frame of selectedFrames) {
nextElements = replaceAllElementsInFrame(
@@ -6147,10 +6121,7 @@ class App extends React.Component<AppProps, AppState> {
this.state.selectedLinearElement?.elementId !== hitElement?.id &&
isLinearElement(hitElement)
) {
const selectedELements = getSelectedElements(
this.scene.getNonDeletedElements(),
this.state,
);
const selectedELements = this.scene.getSelectedElements(this.state);
// set selectedLinearElement when no other element selected except
// the one we've hit
if (selectedELements.length === 1) {
@@ -6252,7 +6223,7 @@ class App extends React.Component<AppProps, AppState> {
delete newSelectedElementIds[hitElement!.id];
const newSelectedElements = getSelectedElements(
this.scene.getNonDeletedElements(),
{ ...prevState, selectedElementIds: newSelectedElementIds },
{ selectedElementIds: newSelectedElementIds },
);
return selectGroupsForSelectedElements(
@@ -6271,6 +6242,7 @@ class App extends React.Component<AppProps, AppState> {
},
this.scene.getNonDeletedElements(),
prevState,
this,
);
});
}
@@ -6307,6 +6279,7 @@ class App extends React.Component<AppProps, AppState> {
},
this.scene.getNonDeletedElements(),
prevState,
this,
);
});
} else {
@@ -6337,6 +6310,7 @@ class App extends React.Component<AppProps, AppState> {
},
this.scene.getNonDeletedElements(),
prevState,
this,
),
}));
}
@@ -6396,9 +6370,7 @@ class App extends React.Component<AppProps, AppState> {
if (pointerDownState.drag.hasOccurred || isResizing || isRotating) {
(isBindingEnabled(this.state)
? bindOrUnbindSelectedElements
: unbindLinearElements)(
getSelectedElements(this.scene.getNonDeletedElements(), this.state),
);
: unbindLinearElements)(this.scene.getSelectedElements(this.state));
}
if (!activeTool.locked && activeTool.type !== "freedraw") {
@@ -7105,10 +7077,7 @@ class App extends React.Component<AppProps, AppState> {
includeLockedElements: true,
});
const selectedElements = getSelectedElements(
this.scene.getNonDeletedElements(),
this.state,
);
const selectedElements = this.scene.getSelectedElements(this.state);
const isHittignCommonBoundBox =
this.isHittingCommonBoundingBoxOfSelectedElements(
{ x, y },
@@ -7138,6 +7107,7 @@ class App extends React.Component<AppProps, AppState> {
},
this.scene.getNonDeletedElements(),
this.state,
this,
)
: this.state),
showHyperlinkPopup: false,
@@ -7225,10 +7195,7 @@ class App extends React.Component<AppProps, AppState> {
pointerDownState: PointerDownState,
event: MouseEvent | KeyboardEvent,
): boolean => {
const selectedElements = getSelectedElements(
this.scene.getNonDeletedElements(),
this.state,
);
const selectedElements = this.scene.getSelectedElements(this.state);
const selectedFrames = selectedElements.filter(
(element) => element.type === "frame",
) as ExcalidrawFrameElement[];