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 { NonDeletedExcalidrawElement } from "./element/types";
import { randomId } from "./random"; import { randomId } from "./random";
import { AppState } from "./types"; import { AppState } from "./types";
import { selectSubtype } from "./subtypes"; import { selectSubtype } from "./element/subtypes";
export type ChartElements = readonly NonDeletedExcalidrawElement[]; export type ChartElements = readonly NonDeletedExcalidrawElement[];

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
import { getShortcutKey } from "../../../utils"; import { getShortcutKey } from "../../../utils";
import { SubtypeRecord } from "../../../subtypes"; import { SubtypeRecord } from "../";
// Exports // Exports
export const getMathSubtypeRecord = () => mathSubtype; 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 { getFontString, arrayToMap, isTestEnv } from "../utils";
import { import {
ExcalidrawElement, ExcalidrawElement,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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