fix: Better legibility when editing some math elements.
This commit is contained in:
parent
089aaa8792
commit
b988f67759
@ -44,6 +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";
|
||||||
|
|
||||||
const getTransform = (
|
const getTransform = (
|
||||||
offsetX: number,
|
offsetX: number,
|
||||||
@ -99,6 +100,14 @@ export const getOriginalContainerHeightFromCache = (
|
|||||||
return originalContainerCache[id]?.height ?? null;
|
return originalContainerCache[id]?.height ?? null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getEditorStyle = function (element) {
|
||||||
|
const map = getSubtypeMethods(element.subtype);
|
||||||
|
if (map?.getEditorStyle) {
|
||||||
|
return map.getEditorStyle(element);
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
} as SubtypeMethods["getEditorStyle"];
|
||||||
|
|
||||||
export const textWysiwyg = ({
|
export const textWysiwyg = ({
|
||||||
id,
|
id,
|
||||||
onChange,
|
onChange,
|
||||||
@ -395,6 +404,7 @@ export const textWysiwyg = ({
|
|||||||
whiteSpace,
|
whiteSpace,
|
||||||
overflowWrap: "break-word",
|
overflowWrap: "break-word",
|
||||||
boxSizing: "content-box",
|
boxSizing: "content-box",
|
||||||
|
...getEditorStyle(element),
|
||||||
});
|
});
|
||||||
updateWysiwygStyle();
|
updateWysiwygStyle();
|
||||||
|
|
||||||
|
@ -876,6 +876,13 @@ const cleanMathElementUpdate = function (updates) {
|
|||||||
return oldUpdates;
|
return oldUpdates;
|
||||||
} as SubtypeMethods["clean"];
|
} as SubtypeMethods["clean"];
|
||||||
|
|
||||||
|
const getMathEditorStyle = function (element) {
|
||||||
|
if (isMathElement(element)) {
|
||||||
|
return { background: undefined };
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
} as SubtypeMethods["getEditorStyle"];
|
||||||
|
|
||||||
const measureMathElement = function (element, next) {
|
const measureMathElement = function (element, next) {
|
||||||
ensureMathElement(element);
|
ensureMathElement(element);
|
||||||
const isMathJaxLoaded = mathJaxLoaded;
|
const isMathJaxLoaded = mathJaxLoaded;
|
||||||
@ -1542,6 +1549,7 @@ export const prepareMathSubtype = function (
|
|||||||
const methods = {} as SubtypeMethods;
|
const methods = {} as SubtypeMethods;
|
||||||
methods.clean = cleanMathElementUpdate;
|
methods.clean = cleanMathElementUpdate;
|
||||||
methods.ensureLoaded = ensureMathJaxLoaded;
|
methods.ensureLoaded = ensureMathJaxLoaded;
|
||||||
|
methods.getEditorStyle = getMathEditorStyle;
|
||||||
methods.measureText = measureMathElement;
|
methods.measureText = measureMathElement;
|
||||||
methods.render = renderMathElement;
|
methods.render = renderMathElement;
|
||||||
methods.renderSvg = renderSvgMathElement;
|
methods.renderSvg = renderSvgMathElement;
|
||||||
|
@ -220,6 +220,7 @@ export type SubtypeMethods = {
|
|||||||
"id" | "version" | "versionNonce"
|
"id" | "version" | "versionNonce"
|
||||||
>,
|
>,
|
||||||
) => Omit<Partial<ExcalidrawElement>, "id" | "version" | "versionNonce">;
|
) => Omit<Partial<ExcalidrawElement>, "id" | "version" | "versionNonce">;
|
||||||
|
getEditorStyle: (element: ExcalidrawTextElement) => Record<string, any>;
|
||||||
ensureLoaded: (callback?: () => void) => Promise<void>;
|
ensureLoaded: (callback?: () => void) => Promise<void>;
|
||||||
measureText: (
|
measureText: (
|
||||||
element: Pick<
|
element: Pick<
|
||||||
@ -261,7 +262,9 @@ type MethodMap = { subtype: Subtype; methods: Partial<SubtypeMethods> };
|
|||||||
const methodMaps = [] as Array<MethodMap>;
|
const methodMaps = [] as Array<MethodMap>;
|
||||||
|
|
||||||
// Use `getSubtypeMethods` to call subtype-specialized methods, like `render`.
|
// Use `getSubtypeMethods` to call subtype-specialized methods, like `render`.
|
||||||
export const getSubtypeMethods = (subtype: Subtype | undefined) => {
|
export const getSubtypeMethods = (
|
||||||
|
subtype: Subtype | undefined,
|
||||||
|
): Partial<SubtypeMethods> | undefined => {
|
||||||
const map = methodMaps.find((method) => method.subtype === subtype);
|
const map = methodMaps.find((method) => method.subtype === subtype);
|
||||||
return map?.methods;
|
return map?.methods;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user