Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
bhouston committed Jun 18, 2023
1 parent ea0a189 commit 640bbb9
Show file tree
Hide file tree
Showing 17 changed files with 217 additions and 237 deletions.
56 changes: 1 addition & 55 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
"plugins": [
"@typescript-eslint",
"unused-imports",
"unicorn",
"promise",
"simple-import-sort",
"prettier",
"import",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"react",
"react-hooks"
],
Expand Down Expand Up @@ -48,57 +45,6 @@
"promise/avoid-new": "warn",
"promise/no-new-statics": "error",
"promise/no-return-in-finally": "warn",
"promise/valid-params": "warn",
"unicorn/better-regex": "error",
"unicorn/error-message": "error",
"unicorn/custom-error-definition": "error",
"unicorn/consistent-destructuring": "error",
"unicorn/escape-case": "error",
"unicorn/explicit-length-check": "error",
"unicorn/no-array-callback-reference": "error",
"unicorn/no-array-method-this-argument": "error",
"unicorn/no-array-push-push": "error",
"unicorn/no-await-expression-member": "error",
"unicorn/no-new-buffer": "warn",
"unicorn/no-this-assignment": "error",
"unicorn/no-unreadable-array-destructuring": "error",
"unicorn/no-unreadable-iife": "error",
"unicorn/no-unsafe-regex": "error",
"unicorn/no-unused-properties": "error",
"unicorn/no-useless-length-check": "error",
"unicorn/no-useless-promise-resolve-reject": "error",
"unicorn/no-useless-spread": "error",
"unicorn/no-useless-switch-case": "error",
"unicorn/no-zero-fractions": "error",
"unicorn/prefer-array-find": "error",
"unicorn/prefer-array-flat": "error",
"unicorn/prefer-array-flat-map": "error",
"unicorn/prefer-array-index-of": "error",
"unicorn/prefer-array-some": "error",
"unicorn/prefer-at": "error",
"unicorn/prefer-code-point": "error",
"unicorn/prefer-date-now": "error",
"unicorn/prefer-default-parameters": "error",
"unicorn/prefer-export-from": "error",
"unicorn/prefer-includes": "error",
"unicorn/prefer-json-parse-buffer": "error",
"unicorn/prefer-logical-operator-over-ternary": "error",
"unicorn/prefer-modern-math-apis": "error",
"unicorn/prefer-negative-index": "error",
"unicorn/prefer-node-protocol": "error",
"unicorn/prefer-number-properties": "error",
"unicorn/prefer-object-from-entries": "error",
"unicorn/prefer-optional-catch-binding": "error",
"unicorn/prefer-prototype-methods": "error",
"unicorn/prefer-reflect-apply": "error",
"unicorn/prefer-string-replace-all": "error",
"unicorn/prefer-string-slice": "error",
"unicorn/prefer-switch": "error",
"unicorn/prefer-ternary": "error",
"unicorn/prefer-type-error": "error",
"unicorn/require-array-join-separator": "error",
"unicorn/require-number-to-fixed-digits-argument": "error",
"unicorn/string-content": "error",
"unicorn/throw-new-error": "error"
"promise/valid-params": "warn"
}
}
33 changes: 17 additions & 16 deletions apps/graph-editor/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
import React from "react";
import ReactDOM from "react-dom/client";
import { Examples, Flow } from "@behave-graph/flow";
import { GraphJSON } from "@behave-graph/core";
import rawGraph from "./graph.json"
import 'reactflow/dist/style.css';
import './index.css';

import "reactflow/dist/style.css";
import "./index.css";
import { GraphJSON } from '@behave-graph/core';
import { Examples, Flow } from '@behave-graph/flow';
import React from 'react';
import ReactDOM from 'react-dom/client';

const graph = rawGraph as GraphJSON
import rawGraph from './graph.json';

const graph = rawGraph as GraphJSON;

const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement
document.getElementById('root') as HTMLElement
);

import Branch from "../../../graphs/core/flow/Branch.json";
import Delay from "../../../graphs/core/time/Delay.json";
import HelloWorld from "../../../graphs/core//HelloWorld.json";
import Polynomial from "../../../graphs/core/logic/Polynomial.json";
import SetGet from "../../../graphs/core/variables/SetGet.json";
import HelloWorld from '../../../graphs/core//HelloWorld.json';
import Branch from '../../../graphs/core/flow/Branch.json';
import Polynomial from '../../../graphs/core/logic/Polynomial.json';
import Delay from '../../../graphs/core/time/Delay.json';
import SetGet from '../../../graphs/core/variables/SetGet.json';

// TODO remove when json types fixed in behave-graph
const examples: Examples = {
branch: Branch as unknown as GraphJSON,
delay: Delay as unknown as GraphJSON,
helloWorld: HelloWorld as unknown as GraphJSON,
polynomial: Polynomial as unknown as GraphJSON,
setGet: SetGet as unknown as GraphJSON,
setGet: SetGet as unknown as GraphJSON
} as Record<string, GraphJSON>;

root.render(
<React.StrictMode>
<Flow graph={graph} examples={examples}/>
<Flow graph={graph} examples={examples} />
</React.StrictMode>
);
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {
vec2Dot,
vec2FromArray,
vec2Length,
vec2MultiplyByScalar,
vec2Negate,
vec2Normalize,
vec2Parse,
vec2MultiplyByScalar,
vec2Subtract,
vec2ToArray,
vec2ToString
Expand Down
20 changes: 10 additions & 10 deletions packages/flow/src/components/AutoSizeInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ import {
useCallback,
useEffect,
useRef,
useState,
} from "react";
useState
} from 'react';

export type AutoSizeInputProps = HTMLProps<HTMLInputElement> & {
minWidth?: number;
};

const baseStyles: CSSProperties = {
position: "absolute",
position: 'absolute',
top: 0,
left: 0,
visibility: "hidden",
visibility: 'hidden',
height: 0,
width: "auto",
whiteSpace: "pre",
width: 'auto',
whiteSpace: 'pre'
};

export const AutoSizeInput: FC<AutoSizeInputProps> = ({
Expand All @@ -35,9 +35,9 @@ export const AutoSizeInput: FC<AutoSizeInputProps> = ({
if (input) {
const styles = window.getComputedStyle(input);
setStyles({
fontSize: styles.getPropertyValue("font-size"),
paddingLeft: styles.getPropertyValue("padding-left"),
paddingRight: styles.getPropertyValue("padding-right"),
fontSize: styles.getPropertyValue('font-size'),
paddingLeft: styles.getPropertyValue('padding-left'),
paddingRight: styles.getPropertyValue('padding-right')
});
}
inputRef.current = input;
Expand All @@ -49,7 +49,7 @@ export const AutoSizeInput: FC<AutoSizeInputProps> = ({
if (inputRef.current === null) return;

const width = measureRef.current.clientWidth;
inputRef.current.style.width = Math.max(minWidth, width) + "px";
inputRef.current.style.width = Math.max(minWidth, width) + 'px';
}, [props.value, minWidth, styles]);

return (
Expand Down
44 changes: 27 additions & 17 deletions packages/flow/src/components/Controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,51 @@ import {
Engine,
ManualLifecycleEventEmitter,
readGraphFromJSON,
Registry,
} from "@behave-graph/core";
import { useState } from "react";
import { ClearModal } from "./modals/ClearModal";
import { HelpModal } from "./modals/HelpModal";
Registry
} from '@behave-graph/core';
import {
faDownload,
faPlay,
faQuestion,
faTrash,
faUpload,
} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
faUpload
} from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { useState } from 'react';
import { ControlButton, Controls, useReactFlow } from 'reactflow';

import { flowToBehave } from '../transformers/flowToBehave';
import { sleep } from '../util/sleep';
import { ClearModal } from './modals/ClearModal';
import { HelpModal } from './modals/HelpModal';
import { Examples, LoadModal } from './modals/LoadModal';
import { SaveModal } from './modals/SaveModal';
import { flowToBehave } from "../transformers/flowToBehave";
import { useReactFlow, Controls, ControlButton } from "reactflow";
import { sleep } from "../util/sleep";

export type CustomControlsProps = {examples: Examples, registry: Registry, manualLifecycleEventEmitter: ManualLifecycleEventEmitter};
export type CustomControlsProps = {
examples: Examples;
registry: Registry;
manualLifecycleEventEmitter: ManualLifecycleEventEmitter;
};

const CustomControls = ({examples, registry, manualLifecycleEventEmitter}: CustomControlsProps) => {
const CustomControls = ({
examples,
registry,
manualLifecycleEventEmitter
}: CustomControlsProps) => {
const [loadModalOpen, setLoadModalOpen] = useState(false);
const [saveModalOpen, setSaveModalOpen] = useState(false);
const [helpModalOpen, setHelpModalOpen] = useState(false);
const [clearModalOpen, setClearModalOpen] = useState(false);
const instance = useReactFlow();

const handleRun = async () => {

const nodes = instance.getNodes();
const edges = instance.getEdges();
const graphJson = flowToBehave(nodes, edges);
const graph = readGraphFromJSON(graphJson, registry);

const engine = new Engine(graph);


if (manualLifecycleEventEmitter.startEvent.listenerCount > 0) {
manualLifecycleEventEmitter.startEvent.emit();
await engine.executeAllAsync(5);
Expand All @@ -52,7 +58,7 @@ const CustomControls = ({examples, registry, manualLifecycleEventEmitter}: Custo
for (let tick = 0; tick < iterations; tick++) {
manualLifecycleEventEmitter.tickEvent.emit();
engine.executeAllSync(tickDuration);
await sleep( tickDuration );
await sleep(tickDuration);
}
}

Expand Down Expand Up @@ -81,7 +87,11 @@ const CustomControls = ({examples, registry, manualLifecycleEventEmitter}: Custo
<FontAwesomeIcon icon={faPlay} />
</ControlButton>
</Controls>
<LoadModal open={loadModalOpen} onClose={() => setLoadModalOpen(false)} examples={examples} />
<LoadModal
open={loadModalOpen}
onClose={() => setLoadModalOpen(false)}
examples={examples}
/>
<SaveModal open={saveModalOpen} onClose={() => setSaveModalOpen(false)} />
<HelpModal open={helpModalOpen} onClose={() => setHelpModalOpen(false)} />
<ClearModal
Expand Down
Loading

0 comments on commit 640bbb9

Please sign in to comment.