refactor: Move MathJax into src/element/subtypes for the

`excalidraw-app` separation, maintaining lazy-loading of MathJax.
This commit is contained in:
Daniel J. Geiger 2023-09-22 14:25:15 -05:00
parent 4d6d6cf129
commit 8eb3191b3f
23 changed files with 32 additions and 41 deletions

View File

@ -12,7 +12,7 @@ import { newElement, newLinearElement, newTextElement } from "./element";
import { NonDeletedExcalidrawElement } from "./element/types";
import { randomId } from "./random";
import { AppState } from "./types";
import { selectSubtype } from "./subtypes";
import { selectSubtype } from "./element/subtypes";
export type ChartElements = readonly NonDeletedExcalidrawElement[];

View File

@ -278,7 +278,7 @@ import {
prepareSubtype,
selectSubtype,
subtypeActionPredicate,
} from "../subtypes";
} from "../element/subtypes";
import {
dataURLToFile,
generateIdFromFile,
@ -583,7 +583,6 @@ class App extends React.Component<AppProps, AppState> {
this.actionManager.registerAction(createUndoAction(this.history));
this.actionManager.registerAction(createRedoAction(this.history));
// Call `this.addSubtype()` here for `@excalidraw/excalidraw`-specific subtypes
this.actionManager.registerActionPredicate(subtypeActionPredicate);
}

View File

@ -10,7 +10,7 @@ import { useApp } from "./App";
import { Dialog } from "./Dialog";
import "./PasteChartDialog.scss";
import { ensureSubtypesLoaded } from "../subtypes";
import { ensureSubtypesLoaded } from "../element/subtypes";
import { isTextElement } from "../element";
import {
getContainerElement,

View File

@ -9,7 +9,7 @@ import {
isSubtypeAction,
isValidSubtype,
subtypeCollides,
} from "../subtypes";
} from "../element/subtypes";
import { ExcalidrawElement, Theme } from "../element/types";
import {
useExcalidrawActionManager,

View File

@ -36,7 +36,7 @@ import { LinearElementEditor } from "../element/linearElementEditor";
import { bumpVersion } from "../element/mutateElement";
import { getUpdatedTimestamp, updateActiveTool } from "../utils";
import { arrayToMap } from "../utils";
import { isValidSubtype } from "../subtypes";
import { isValidSubtype } from "../element/subtypes";
import { MarkOptional, Mutable } from "../utility-types";
import {
detectLineHeight,

View File

@ -7,7 +7,7 @@ import { getUpdatedTimestamp } from "../utils";
import { Mutable } from "../utility-types";
import { ShapeCache } from "../scene/ShapeCache";
import { maybeGetSubtypeProps } from "./newElement";
import { getSubtypeMethods } from "../subtypes";
import { getSubtypeMethods } from "./subtypes";
type ElementUpdate<TElement extends ExcalidrawElement> = Omit<
Partial<TElement>,

View File

@ -40,7 +40,7 @@ import {
VERTICAL_ALIGN,
} from "../constants";
import { MarkOptional, Merge, Mutable } from "../utility-types";
import { getSubtypeMethods, isValidSubtype } from "../subtypes";
import { getSubtypeMethods, isValidSubtype } from "./subtypes";
export const maybeGetSubtypeProps = (
obj: {

View File

@ -1,27 +1,23 @@
import {
ExcalidrawElement,
ExcalidrawTextElement,
NonDeleted,
} from "./element/types";
import { getNonDeletedElements } from "./element";
import { getSelectedElements } from "./scene";
import { AppState } from "./types";
import { registerAuxLangData } from "./i18n";
import { ExcalidrawElement, ExcalidrawTextElement, NonDeleted } from "../types";
import { getNonDeletedElements } from "../";
import { getSelectedElements } from "../../scene";
import { AppState } from "../../types";
import { registerAuxLangData } from "../../i18n";
import { Action, ActionName, ActionPredicateFn } from "./actions/types";
import { Action, ActionName, ActionPredicateFn } from "../../actions/types";
import {
CustomShortcutName,
registerCustomShortcuts,
} from "./actions/shortcuts";
import { register } from "./actions/register";
import { hasBoundTextElement, isTextElement } from "./element/typeChecks";
} from "../../actions/shortcuts";
import { register } from "../../actions/register";
import { hasBoundTextElement, isTextElement } from "../typeChecks";
import {
getBoundTextElement,
getContainerElement,
redrawTextBoundingBox,
} from "./element/textElement";
import { ShapeCache } from "./scene/ShapeCache";
import Scene from "./scene/Scene";
} from "../textElement";
import { ShapeCache } from "../../scene/ShapeCache";
import Scene from "../../scene/Scene";
// Use "let" instead of "const" so we can dynamically add subtypes
let subtypeNames: readonly Subtype[] = [];

View File

@ -37,11 +37,7 @@ import { getNonDeletedElements, redrawTextBoundingBox } from "../../../element";
import { ButtonIconSelect } from "../../../components/ButtonIconSelect";
// Subtype imports
import {
SubtypeLoadedCb,
SubtypeMethods,
SubtypePrepFn,
} from "../../../subtypes";
import { SubtypeLoadedCb, SubtypeMethods, SubtypePrepFn } from "../";
import { mathSubtypeIcon } from "./icon";
import { getMathSubtypeRecord } from "./types";
import { SubtypeButton } from "../../../components/Subtypes";

View File

@ -1,6 +1,6 @@
import { useEffect } from "react";
import { ExcalidrawImperativeAPI } from "../../../types";
import { addSubtypeMethods } from "../../../subtypes";
import { addSubtypeMethods } from "../";
import { getMathSubtypeRecord } from "./types";
import { prepareMathSubtype } from "./implementation";

View File

@ -1,9 +1,9 @@
import { render } from "../../../../tests/test-utils";
import { API } from "../../../../tests/helpers/api";
import ExcalidrawApp from "../../../";
import ExcalidrawApp from "../../../../excalidraw-app";
import { measureTextElement } from "../../../../element/textElement";
import { ensureSubtypesLoaded } from "../../../../subtypes";
import { measureTextElement } from "../../../textElement";
import { ensureSubtypesLoaded } from "../../";
describe("mathjax", () => {
it("text-only measurements match", async () => {

View File

@ -1,5 +1,5 @@
import { getShortcutKey } from "../../../utils";
import { SubtypeRecord } from "../../../subtypes";
import { SubtypeRecord } from "../";
// Exports
export const getMathSubtypeRecord = () => mathSubtype;

View File

@ -1,4 +1,4 @@
import { getSubtypeMethods, SubtypeMethods } from "../subtypes";
import { getSubtypeMethods, SubtypeMethods } from "./subtypes";
import { getFontString, arrayToMap, isTestEnv } from "../utils";
import {
ExcalidrawElement,

View File

@ -44,7 +44,7 @@ import { actionZoomIn, actionZoomOut } from "../actions/actionCanvas";
import App from "../components/App";
import { LinearElementEditor } from "./linearElementEditor";
import { parseClipboard } from "../clipboard";
import { SubtypeMethods, getSubtypeMethods } from "../subtypes";
import { SubtypeMethods, getSubtypeMethods } from "./subtypes";
const getTransform = (
offsetX: number,

View File

@ -5,7 +5,7 @@ import { trackEvent } from "../analytics";
import { getDefaultAppState } from "../appState";
import { ErrorDialog } from "../components/ErrorDialog";
import { TopErrorBoundary } from "../components/TopErrorBoundary";
import { useSubtypes } from "./subtypes";
import { useSubtypes } from "../element/subtypes/use";
import {
APP_NAME,
EVENT,

View File

@ -31,7 +31,7 @@ import {
InteractiveCanvasAppState,
} from "../types";
import { getDefaultAppState } from "../appState";
import { getSubtypeMethods } from "../subtypes";
import { getSubtypeMethods } from "../element/subtypes";
import {
BOUND_TEXT_PADDING,
FRAME_STYLE,

View File

@ -23,7 +23,7 @@ import {
prepareSubtype,
selectSubtype,
subtypeActionPredicate,
} from "../../subtypes";
} from "../../element/subtypes";
import {
maybeGetSubtypeProps,
newEmbeddableElement,

View File

@ -12,7 +12,7 @@ import {
isValidSubtype,
selectSubtype,
subtypeCollides,
} from "../subtypes";
} from "../element/subtypes";
import { render } from "./test-utils";
import { API } from "./helpers/api";

View File

@ -37,7 +37,7 @@ import {
Subtype,
SubtypePrepFn,
SubtypeRecord,
} from "./subtypes";
} from "./element/subtypes";
import type { FileSystemHandle } from "./data/filesystem";
import type { IMAGE_MIME_TYPES, MIME_TYPES } from "./constants";
import { ContextMenuItems } from "./components/ContextMenu";