mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
remove shared global scene and attach it to every instance (#1706)
Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
parent
54f8d8f820
commit
20500b7822
9 changed files with 219 additions and 184 deletions
|
@ -9,7 +9,8 @@ import { getElementPointsCoords } from "./bounds";
|
|||
import { Point, AppState } from "../types";
|
||||
import { mutateElement } from "./mutateElement";
|
||||
import { SceneHistory } from "../history";
|
||||
import { globalSceneState } from "../scene";
|
||||
|
||||
import Scene from "../scene/Scene";
|
||||
|
||||
export class LinearElementEditor {
|
||||
public elementId: ExcalidrawElement["id"] & {
|
||||
|
@ -19,12 +20,13 @@ export class LinearElementEditor {
|
|||
public draggingElementPointIndex: number | null;
|
||||
public lastUncommittedPoint: Point | null;
|
||||
|
||||
constructor(element: NonDeleted<ExcalidrawLinearElement>) {
|
||||
LinearElementEditor.normalizePoints(element);
|
||||
|
||||
constructor(element: NonDeleted<ExcalidrawLinearElement>, scene: Scene) {
|
||||
this.elementId = element.id as string & {
|
||||
_brand: "excalidrawLinearElementId";
|
||||
};
|
||||
Scene.mapElementToScene(this.elementId, scene);
|
||||
LinearElementEditor.normalizePoints(element);
|
||||
|
||||
this.activePointIndex = null;
|
||||
this.lastUncommittedPoint = null;
|
||||
this.draggingElementPointIndex = null;
|
||||
|
@ -41,7 +43,7 @@ export class LinearElementEditor {
|
|||
* statically guarantee this method returns an ExcalidrawLinearElement)
|
||||
*/
|
||||
static getElement(id: InstanceType<typeof LinearElementEditor>["elementId"]) {
|
||||
const element = globalSceneState.getNonDeletedElement(id);
|
||||
const element = Scene.getScene(id)?.getNonDeletedElement(id);
|
||||
if (element) {
|
||||
return element as NonDeleted<ExcalidrawLinearElement>;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { ExcalidrawElement } from "./types";
|
||||
import { invalidateShapeForElement } from "../renderer/renderElement";
|
||||
import { globalSceneState } from "../scene";
|
||||
import Scene from "../scene/Scene";
|
||||
import { getSizeFromPoints } from "../points";
|
||||
import { randomInteger } from "../random";
|
||||
import { Point } from "../types";
|
||||
|
@ -81,8 +81,7 @@ export const mutateElement = <TElement extends Mutable<ExcalidrawElement>>(
|
|||
|
||||
element.version++;
|
||||
element.versionNonce = randomInteger();
|
||||
|
||||
globalSceneState.informMutation();
|
||||
Scene.getScene(element)?.informMutation();
|
||||
};
|
||||
|
||||
export const newElementWith = <TElement extends ExcalidrawElement>(
|
||||
|
|
|
@ -125,7 +125,6 @@ export const newTextElement = (
|
|||
},
|
||||
{},
|
||||
);
|
||||
|
||||
return textElement;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { KEYS } from "../keys";
|
||||
import { isWritableElement, getFontString } from "../utils";
|
||||
import { globalSceneState } from "../scene";
|
||||
import Scene from "../scene/Scene";
|
||||
import { isTextElement } from "./typeChecks";
|
||||
import { CLASSES } from "../constants";
|
||||
import { ExcalidrawElement } from "./types";
|
||||
|
@ -37,16 +37,18 @@ export const textWysiwyg = ({
|
|||
onChange,
|
||||
onSubmit,
|
||||
getViewportCoords,
|
||||
element,
|
||||
}: {
|
||||
id: ExcalidrawElement["id"];
|
||||
appState: AppState;
|
||||
onChange?: (text: string) => void;
|
||||
onSubmit: (text: string) => void;
|
||||
getViewportCoords: (x: number, y: number) => [number, number];
|
||||
element: ExcalidrawElement;
|
||||
}) => {
|
||||
function updateWysiwygStyle() {
|
||||
const updatedElement = globalSceneState.getElement(id);
|
||||
if (isTextElement(updatedElement)) {
|
||||
const updatedElement = Scene.getScene(element)?.getElement(id);
|
||||
if (updatedElement && isTextElement(updatedElement)) {
|
||||
const [viewportX, viewportY] = getViewportCoords(
|
||||
updatedElement.x,
|
||||
updatedElement.y,
|
||||
|
@ -183,7 +185,7 @@ export const textWysiwyg = ({
|
|||
};
|
||||
|
||||
// handle updates of textElement properties of editing element
|
||||
const unbindUpdate = globalSceneState.addCallback(() => {
|
||||
const unbindUpdate = Scene.getScene(element)!.addCallback(() => {
|
||||
updateWysiwygStyle();
|
||||
editable.focus();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue