move the parsing from VisualEditor to App component
This commit is contained in:
parent
65b6a343d1
commit
4f9a546fd1
11 changed files with 107 additions and 116 deletions
|
|
@ -28,7 +28,7 @@ export type History = {
|
|||
};
|
||||
|
||||
// independently moveable parts of our shapes:
|
||||
export type RountanglePart = "left" | "top" | "right" | "bottom";
|
||||
export type RectSide = "left" | "top" | "right" | "bottom";
|
||||
export type ArrowPart = "start" | "end";
|
||||
|
||||
export const emptyState: VisualEditorState = {
|
||||
|
|
@ -36,9 +36,9 @@ export const emptyState: VisualEditorState = {
|
|||
};
|
||||
|
||||
// used to find which rountangle an arrow connects to (src/tgt)
|
||||
export function findNearestSide(arrow: Line2D, arrowPart: "start" | "end", candidates: (Rountangle|Diamond)[]): {uid: string, part: RountanglePart} | undefined {
|
||||
export function findNearestSide(arrow: Line2D, arrowPart: "start" | "end", candidates: (Rountangle|Diamond)[]): {uid: string, part: RectSide} | undefined {
|
||||
let best = Infinity;
|
||||
let bestSide: undefined | {uid: string, part: RountanglePart};
|
||||
let bestSide: undefined | {uid: string, part: RectSide};
|
||||
for (const rountangle of candidates) {
|
||||
for (const [side, getSide] of sides) {
|
||||
const asLine = getSide(rountangle);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { VisualEditorState } from "@/VisualEditor/VisualEditor";
|
||||
import { findNearestArrow, findNearestHistory, findNearestSide, findRountangle, RountanglePart } from "./concrete_syntax";
|
||||
import { findNearestArrow, findNearestHistory, findNearestSide, findRountangle, RectSide } from "./concrete_syntax";
|
||||
|
||||
export type Connections = {
|
||||
arrow2SideMap: Map<string,[{ uid: string; part: RountanglePart; } | undefined, { uid: string; part: RountanglePart; } | undefined]>,
|
||||
arrow2SideMap: Map<string,[{ uid: string; part: RectSide; } | undefined, { uid: string; part: RectSide; } | undefined]>,
|
||||
side2ArrowMap: Map<string, Set<["start"|"end", string]>>,
|
||||
text2ArrowMap: Map<string,string>,
|
||||
arrow2TextMap: Map<string,string[]>,
|
||||
|
|
@ -14,7 +14,7 @@ export type Connections = {
|
|||
|
||||
export function detectConnections(state: VisualEditorState): Connections {
|
||||
// detect what is 'connected'
|
||||
const arrow2SideMap = new Map<string,[{ uid: string; part: RountanglePart; } | undefined, { uid: string; part: RountanglePart; } | undefined]>();
|
||||
const arrow2SideMap = new Map<string,[{ uid: string; part: RectSide; } | undefined, { uid: string; part: RectSide; } | undefined]>();
|
||||
const side2ArrowMap = new Map<string, Set<["start"|"end", string]>>();
|
||||
const text2ArrowMap = new Map<string,string>();
|
||||
const arrow2TextMap = new Map<string,string[]>();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue