feat: Support binding text to container via context menu (#4935)

* feat: Support binding text to closest container

* Bind text to selected container

* show bind action in canvas and selected container after binding

* allow binding if container has no bound text

* fix

* move logic to show/hide bind actions to contextMenuPredicate

* don't show bind action when clicking on bounding box and not elemnts
This commit is contained in:
Aakansha Doshi 2022-03-21 17:54:54 +05:30 committed by GitHub
parent ceb43ed8fb
commit 625ecc64ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 159 additions and 81 deletions

View file

@ -27,6 +27,7 @@ import {
actionToggleStats,
actionToggleZenMode,
actionUnbindText,
actionBindText,
actionUngroup,
actionLink,
} from "../actions";
@ -5391,6 +5392,16 @@ class App extends React.Component<AppProps, AppState> {
this.actionManager.getAppState(),
);
const mayBeAllowUnbinding = actionUnbindText.contextItemPredicate(
this.actionManager.getElementsIncludingDeleted(),
this.actionManager.getAppState(),
);
const mayBeAllowBinding = actionBindText.contextItemPredicate(
this.actionManager.getElementsIncludingDeleted(),
this.actionManager.getAppState(),
);
const separator = "separator";
const elements = this.scene.getElements();
@ -5467,10 +5478,6 @@ class App extends React.Component<AppProps, AppState> {
});
}
} else if (type === "element") {
const elementsWithUnbindedText = getSelectedElements(
elements,
this.state,
).some((element) => !hasBoundTextElement(element));
if (this.state.viewModeEnabled) {
ContextMenu.push({
options: [navigator.clipboard && actionCopy, ...options],
@ -5504,7 +5511,8 @@ class App extends React.Component<AppProps, AppState> {
actionPasteStyles,
separator,
maybeGroupAction && actionGroup,
!elementsWithUnbindedText && actionUnbindText,
mayBeAllowUnbinding && actionUnbindText,
mayBeAllowBinding && actionBindText,
maybeUngroupAction && actionUngroup,
(maybeGroupAction || maybeUngroupAction) && separator,
actionAddToLibrary,