fix: decouple pure functions from hyperlink to prevent mermaid bundling (#7710)

* move hyperlink code into its folder

* move pure js functions to hyperlink/helpers and move actionLink to actions

* fix tests

* fix
This commit is contained in:
Aakansha Doshi 2024-02-20 20:59:01 +05:30 committed by GitHub
parent 79d9dc2f8f
commit 2e719ff671
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 198 additions and 176 deletions

View file

@ -326,9 +326,7 @@ import {
showHyperlinkTooltip,
hideHyperlinkToolip,
Hyperlink,
isPointHittingLink,
isPointHittingLinkIcon,
} from "../element/Hyperlink";
} from "../components/hyperlink/Hyperlink";
import { isLocalLink, normalizeLink, toValidURL } from "../data/url";
import { shouldShowBoundingBox } from "../element/transformHandles";
import { actionUnlockAllElements } from "../actions/actionElementLock";
@ -410,6 +408,10 @@ import { withBatchedUpdates, withBatchedUpdatesThrottled } from "../reactUtils";
import { getRenderOpacity } from "../renderer/renderElement";
import { textWysiwyg } from "../element/textWysiwyg";
import { isOverScrollBars } from "../scene/scrollbars";
import {
isPointHittingLink,
isPointHittingLinkIcon,
} from "./hyperlink/helpers";
const AppContext = React.createContext<AppClassProperties>(null!);
const AppPropsContext = React.createContext<AppProps>(null!);
@ -9571,7 +9573,6 @@ class App extends React.Component<AppProps, AppState> {
// -----------------------------------------------------------------------------
// TEST HOOKS
// -----------------------------------------------------------------------------
declare global {
interface Window {
h: {
@ -9584,20 +9585,23 @@ declare global {
}
}
if (import.meta.env.MODE === ENV.TEST || import.meta.env.DEV) {
window.h = window.h || ({} as Window["h"]);
export const createTestHook = () => {
if (import.meta.env.MODE === ENV.TEST || import.meta.env.DEV) {
window.h = window.h || ({} as Window["h"]);
Object.defineProperties(window.h, {
elements: {
configurable: true,
get() {
return this.app?.scene.getElementsIncludingDeleted();
Object.defineProperties(window.h, {
elements: {
configurable: true,
get() {
return this.app?.scene.getElementsIncludingDeleted();
},
set(elements: ExcalidrawElement[]) {
return this.app?.scene.replaceAllElements(elements);
},
},
set(elements: ExcalidrawElement[]) {
return this.app?.scene.replaceAllElements(elements);
},
},
});
}
});
}
};
createTestHook();
export default App;