Compare commits

...
15 Commits
Author SHA1 Message Date
ari b76dc672f3 v0.0.13 2022-05-05 15:21:08 -04:00
ari 6821bb8714 cleaned up 2022-05-05 15:20:08 -04:00
ari c256400518 fixed up styling for autos 2022-05-05 15:03:33 -04:00
ari 634f3e9219 automation editor fixed up 2022-05-05 13:57:44 -04:00
ari a56c7ff964 stable editor 2022-05-05 13:48:51 -04:00
ari b29596fe78 added add node to end of flow 2022-05-01 21:14:24 -04:00
ari 1620d04624 stable flow 2022-05-01 20:55:04 -04:00
ari 1ed1e63330 aligned graph 2022-04-30 23:10:04 -04:00
ari 7ae50e634a removed numerics 2022-04-30 22:52:26 -04:00
ari 56d68d9065 choose flow 2022-04-30 22:51:51 -04:00
ari 468a022582 dagflow triggers 2022-04-27 19:28:09 -04:00
Ari Sosnovsky 5dcd17ad17 Merge pull request #7 from asosnovsky/dependabot/npm_and_yarn/webapp/node-fetch-2.6.7
Bump node-fetch from 2.6.6 to 2.6.7 in /webapp
2022-04-27 17:02:05 -04:00
ari b1df6aebe2 better on click 2022-04-27 17:01:01 -04:00
ari b98d4a8812 tag mod 2022-04-27 17:00:55 -04:00
dependabot[bot] 7a278c856a Bump node-fetch from 2.6.6 to 2.6.7 in /webapp
Bumps [node-fetch](https://github.com/node-fetch/node-fetch) from 2.6.6 to 2.6.7.
- [Release notes](https://github.com/node-fetch/node-fetch/releases)
- [Commits](https://github.com/node-fetch/node-fetch/compare/v2.6.6...v2.6.7)

---
updated-dependencies:
- dependency-name: node-fetch
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-27 02:16:24 +00:00
52 changed files with 1475 additions and 1889 deletions

No files matched your search

+5
View File
@@ -1,5 +1,10 @@
# Changelog
## [0.0.13] - Better Styling with react-flow
- Fixed up styling (using react-flow)
- cleaned up some button styles
## [0.0.12] - Tags
- Added tag management system for automations
+1 -1
View File
@@ -1,5 +1,5 @@
name: Shortumation
version: 0.0.12
version: 0.0.13
slug: shortumation
url: "https://github.com/asosnovsky/Shortumation"
description: "A homeassitant addon which provides better UI for automations & scripts."
+1
View File
@@ -10,3 +10,4 @@
Type: Vent
Room: Bathroom
Floor: First
5: {}
+2 -1
View File
@@ -12,6 +12,7 @@
"jss": "^10.8.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-flow-renderer": "^10.1.2",
"react-jss": "^10.8.2",
"react-router-dom": "6",
"react-scripts": "4.0.3",
@@ -77,4 +78,4 @@
"node_modules",
"src"
]
}
}
@@ -1,5 +1,5 @@
import "./AutoInfoBox.css";
import { AutomationData, AutomationMetadata } from "types/automations";
import { AutomationMetadata } from "types/automations";
import InputList from "components/Inputs/InputList";
import InputText from "components/Inputs/InputText";
import InputTextArea from "components/Inputs/InputTextArea";
@@ -41,6 +41,7 @@ export const AutoInfoBox: FC<Props> = ({
if (newName.length <= 0) {
return "Name must be at least 1 character long"
}
// eslint-disable-next-line
for (const [name, _] of tags) {
if (name.trim() === newName.trim()) {
return `The tag '${name}' already exists`
@@ -1,10 +1,69 @@
.automation-editor--info-icon {
.automation-editor {
display: flex;
flex-direction: row;
width: 100%;
height: 100%;
}
.automation-editor--flow-wrapper {
flex: 1;
padding: 0 0.5em 0 0.5em;
max-height: 100%;
max-width: 100%;
display: flex;
flex-direction: column;
gap: 0.5em;
}
.automation-editor--flow-wrapper--toolbar {
display: flex;
flex-direction: row;
justify-content: flex-end;
}
.automation-editor--flow-wrapper.unchanged>.automation-editor--flow-wrapper--toolbar {
height: 0;
opacity: 0;
overflow: hidden;
}
.automation-editor--flow-wrapper.changed>.automation-editor--flow-wrapper--toolbar * {
border-color: var(--change);
color: var(--change)
}
.automation-editor--flow-wrapper--toolbar--save-btn {
display: flex;
gap: 0.5em;
align-items: center;
padding: 0.25em;
}
.automation-editor--flow-wrapper.changed>.automation-editor--flow-wrapper--flow {
border-color: var(--change);
}
.automation-editor--flow-wrapper--flow {
flex: 1;
border: 1px solid var(--secondary-accent);
margin: 0 0 0.5em 0;
z-index: 1;
}
.automation-editor--info-box {
position: relative;
}
.automation-editor--info-box--icon {
position: absolute;
right: 1.5em;
right: 0em;
bottom: 0.5em;
z-index: 10;
}
.automation-editor--info-box.hide>.automation-editor--info-icon {
.automation-editor--info-box.hide>.automation-editor--info-box--icon {
transform: rotate(180deg);
z-index: 2;
}
@@ -1,8 +1,8 @@
import React from "react";
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { AutomationEditor } from './index';
import { NODE_HEIGHT, NODE_WIDTH, DISTANCE_FACTOR, ADD_HEIGHT, ADD_WIDTH, CIRCLE_SIZE } from '../DAGSvgs/constants';
import { useState } from 'react';
import * as dgconst from 'components/DAGSvgs/constants';
export default {
@@ -11,12 +11,14 @@ export default {
parameters: { actions: { argTypesRegex: '^on.*' } },
args: {
dims: {
nodeHeight: NODE_HEIGHT,
nodeWidth: NODE_WIDTH,
addHeight: ADD_HEIGHT,
addWidth: ADD_WIDTH,
circleSize: CIRCLE_SIZE,
distanceFactor: DISTANCE_FACTOR,
nodeHeight: dgconst.NODE_HEIGHT,
nodeWidth: dgconst.NODE_WIDTH,
distanceFactor: dgconst.DISTANCE_FACTOR,
circleSize: dgconst.CIRCLE_SIZE,
padding: {
x: dgconst.PADDING,
y: dgconst.PADDING,
},
}
}
} as ComponentMeta<typeof AutomationEditor>
@@ -34,6 +36,9 @@ const Template: ComponentStory<typeof AutomationEditor> = args => {
</div>
}
export const Loading = Template.bind({});
export const Simple = Template.bind({})
Simple.args = {
...Simple.args,
@@ -1,28 +1,17 @@
import "./index.css";
import { DAGBoardElmDims } from "components/DAGSvgs/DAGBoard";
import { ArrowIcon, CheckMarkIcon, ZoomIcon } from "components/Icons";
import { SequenceNodes } from "components/SequenceNodes";
import { FC, useEffect, useState } from "react";
import { AutomationData, AutomationSequenceNode } from "types/automations";
import useWindowSize from "utils/useWindowSize";
import { ArrowIcon, CheckMarkIcon } from "components/Icons";
import { FC, useState } from "react";
import { AutomationData } from "types/automations";
import { AutoInfoBox } from "./AutoInfoBox";
import { useEditorStyles } from "./styles";
import { computeTriggerPos, computeExtraField } from './positions';
import { chain } from "utils/iter";
import { AutomationTrigger } from 'types/automations/triggers';
import { Modal } from "components/Modal";
import { NodeEditor } from "components/NodeEditor";
import { ButtonIcon } from "components/Icons/ButtonIcons";
import { Button } from "components/Inputs/Button";
import { useAutomatioEditorState } from "./state";
import { DAGAutomationFlow } from "components/DAGFlow";
import { DAGAutomationFlowDims } from "components/DAGFlow/types";
interface TriggerEditorModalState {
trigger: AutomationTrigger;
onSave: (node: AutomationTrigger) => void;
}
interface Props {
automation: AutomationData;
dims: DAGBoardElmDims;
automation?: AutomationData;
dims: DAGAutomationFlowDims;
onUpdate: (auto: AutomationData) => void;
}
export const AutomationEditor: FC<Props> = ({
@@ -39,35 +28,15 @@ export const AutomationEditor: FC<Props> = ({
save,
} = useAutomatioEditorState(propsAutos, propsOnUpdate);
const [zoomLevel, setZoomLevel] = useState(40);
const { ratioWbh } = useWindowSize();
const [closeInfo, setCloseInfo] = useState(false);
const [modalState, setModalState] = useState<null | TriggerEditorModalState>(null);
const { classes } = useEditorStyles({
closeInfo,
horizontalMode: ratioWbh < 0.75,
autoChanged: state.status,
});
// render
if (state.status === 'loading') {
return <div className={classes.root}>
return <div className="automation-editor loading">
Loading...
</div>
}
return <div className={classes.root}>
<Modal open={!!modalState}>
{!!modalState && <NodeEditor
node={modalState.trigger}
onClose={() => setModalState(null)}
onSave={(n) => {
modalState.onSave(n as any);
setModalState(null);
}}
allowedTypes={['trigger']}
/>}
</Modal>
return <div className="automation-editor">
<AutoInfoBox
className={closeInfo ? "hide" : "show"}
metadata={state.data.metadata}
@@ -75,64 +44,29 @@ export const AutomationEditor: FC<Props> = ({
onUpdate={updateMetadata}
>
<ButtonIcon
className={`${classes.infoIcon} automation-editor--info-icon`}
className="automation-editor--info-box--icon"
onClick={() => setCloseInfo(!closeInfo)}
title={closeInfo ? "Show Metadata" : "Hide Metadata"}
>{ArrowIcon}</ButtonIcon>
</AutoInfoBox>
<div className={classes.wrapper}>
<div className={classes.toolbar}>
<div style={{ display: 'flex' }}>
<ZoomIcon className={classes.zoomImg} size={1} color="white" />
<input
type="number"
min={1} max={100} step={1}
className={classes.zoom}
value={zoomLevel}
onChange={z => setZoomLevel(z.target.valueAsNumber ?? 40)}
/>
</div>
<div className={["automation-editor--flow-wrapper", state.status].join(" ")}>
<div className="automation-editor--flow-wrapper--toolbar">
<Button
className={classes.saveBtn}
className={"automation-editor--flow-wrapper--toolbar--save-btn"}
onClick={save}
disabled={state.status !== 'changed'}
>
Save <CheckMarkIcon color="#bf4" />
</Button>
</div>
<SequenceNodes
zoomLevel={zoomLevel * 200 / 100 + 50}
startPoint={[2, 0.5]}
dims={dims}
<DAGAutomationFlow
className="automation-editor--flow-wrapper--flow"
sequence={state.data.sequence}
onChange={updateSequence}
additionalElements={() => chain([
computeExtraField([1, 0.5], [2, 0.5]),
computeTriggerPos(
[0.5, 0.5],
state.data.trigger,
[1.5, 0.5],
updateTrigger,
() => {
setModalState({
trigger: {
$smType: "trigger",
platform: "device",
device_id: "",
domain: "",
type: "",
subtype: ""
},
onSave: (t) => updateTrigger([...state.data.trigger, t])
});
},
(trigger, onSave) => setModalState({
trigger,
onSave,
})
),
])}
trigger={state.data.trigger}
onSequenceUpdate={updateSequence}
onTriggerUpdate={updateTrigger}
dims={dims}
/>
</div>
</div>
@@ -1,78 +0,0 @@
import { DAGElement } from "components/DAGSvgs/DAGBoard";
import { Point } from "types/graphs";
import { AutomationTrigger } from 'types/automations/triggers';
import { avgPoints } from "utils/graph";
export function* computeTriggerPos(
startPoint: Point,
triggers: AutomationTrigger[],
toPath: Point,
onUpdate: (ts: AutomationTrigger[]) => void,
onAdd: () => void,
onEdit: (nt: AutomationTrigger, onSave: (ts: AutomationTrigger) => void) => void,
): Generator<DAGElement> {
// functions
const makeRemoveNode = (i: number) => () => onUpdate([
...triggers.slice(0, i),
...triggers.slice(i + 1),
]);
const updateNode = (n: AutomationTrigger, i: number) => onUpdate([
...triggers.slice(0, i),
n,
...triggers.slice(i + 1),
])
// main loop
for (let i = 0; i < triggers.length; i++) {
const node = triggers[i];
const nodeLoc: Point = [startPoint[0], startPoint[1] + i];
yield {
type: "node",
node,
loc: nodeLoc,
onRemove: makeRemoveNode(i),
onOpen: () => onEdit(node, up => updateNode(up, i))
}
yield {
type: "edge",
p1: nodeLoc,
p2: toPath,
direction: "1->2",
}
}
// if we had nothing to loop on
if (triggers.length === 0) {
yield {
type: "edge",
p1: [startPoint[0] - 0.25, startPoint[1] + triggers.length],
p2: toPath,
direction: "1->2",
}
}
// add circle
yield {
type: 'circle',
icon: 'add',
loc: [startPoint[0] + 0.25, startPoint[1] + triggers.length],
onAdd
}
}
export function* computeExtraField(
triggerEndPos: Point,
sequenceStartPos: Point,
): Generator<DAGElement> {
yield {
type: 'circle',
loc: avgPoints(triggerEndPos, sequenceStartPos),
icon: 'color',
color: 'blue',
}
yield {
type: 'edge',
p1: triggerEndPos,
p2: sequenceStartPos,
direction: '1->2',
}
}
@@ -12,7 +12,7 @@ export type EditorState = {
export type EditorStatus = EditorState['status'];
export const useAutomatioEditorState = (
automation: AutomationData,
automation: AutomationData | undefined,
onSave: (a: AutomationData) => void,
) => {
const [state, update] = useState<EditorState>({
@@ -30,10 +30,12 @@ export const useAutomatioEditorState = (
})
useEffect(() => {
update({
status: 'unchanged',
data: genEditorData(automation),
})
if (automation) {
update({
status: 'unchanged',
data: genEditorData(automation),
})
}
}, [automation]);
return {
@@ -1,62 +0,0 @@
import { createAppUseStyles } from "styles/theme";
export const useEditorStyles = createAppUseStyles<{
closeInfo: boolean;
horizontalMode: boolean;
autoChanged: string;
}>(theme => ({
wrapper: {
display: 'flex',
flexDirection: 'column',
alignItems: "flex-end",
height: '100%',
width: '100%',
overflow: 'hidden',
},
root: ({ horizontalMode }) => ({
height: '100%',
width: '100%',
color: theme.primaryAccent,
display: 'flex',
flexDirection: horizontalMode ? 'column' : 'row',
}),
dag: {
borderWidth: 1,
borderStyle: 'solid',
borderColor: theme.secondaryAccent,
width: '100%',
},
infoIcon: ({ horizontalMode }) => ({
bottom: horizontalMode ? '90%' : 10
}),
zoom: {
backgroundColor: theme.secondary,
color: theme.secondaryAccent,
textAlign: 'center',
maxWidth: "3em",
},
zoomImg: {
},
toolbar: {
width: "100%",
display: "flex",
flexDirection: "row",
justifyContent: 'space-between',
alignItems: "center",
padding: "0.5em",
},
saveBtn: ({ autoChanged }) => ({
display: "flex",
opacity: autoChanged === "changed" ? 1 : 0,
height: autoChanged === "changed" ? undefined : 0,
fontSize: autoChanged === "changed" ? undefined : 0,
gap: '0.5em',
maxHeight: '1em',
justifyContent: 'center',
alignItems: 'center',
borderColor: "#bf4 !important",
color: "#bf4 !important"
}),
}))
@@ -2,8 +2,8 @@ import "styles/root.css";
import { ComponentMeta, ComponentStory } from "@storybook/react";
import { useState } from "react";
import { AutomationList } from ".";
import { NODE_HEIGHT, NODE_WIDTH, ADD_HEIGHT, ADD_WIDTH, CIRCLE_SIZE, DISTANCE_FACTOR } from 'components/DAGSvgs/constants';
import { createMockAuto } from "utils/mocks";
import * as dgconst from 'components/DAGSvgs/constants';
export default {
title: 'App/AutomationList',
@@ -11,12 +11,14 @@ export default {
parameters: { actions: { argTypesRegex: '^on.*' } },
args: {
dims: {
nodeHeight: NODE_HEIGHT,
nodeWidth: NODE_WIDTH,
addHeight: ADD_HEIGHT,
addWidth: ADD_WIDTH,
circleSize: CIRCLE_SIZE,
distanceFactor: DISTANCE_FACTOR,
nodeHeight: dgconst.NODE_HEIGHT,
nodeWidth: dgconst.NODE_WIDTH,
distanceFactor: dgconst.DISTANCE_FACTOR,
circleSize: dgconst.CIRCLE_SIZE,
padding: {
x: dgconst.PADDING,
y: dgconst.PADDING,
},
}
}
} as ComponentMeta<typeof AutomationList>;
@@ -131,10 +131,10 @@ const convertGroupsToItems = (
key={i}
className="automation-list-box--body--item"
title={`Name = ${auto.metadata.alias}\nID = ${auto.metadata.id}\nDescription = ${auto.metadata.description}`}
onClick={() => onSelectAutomation(autoIndex)}
>
<div
className="automation-list-box--body--item--title"
onClick={() => onSelectAutomation(autoIndex)}
>
<b>{auto.metadata.alias.slice(0, 15)} <span>({auto.metadata.id.slice(0, 5)})</span></b>
<span>{auto.metadata.description.slice(0, 25)}</span>
@@ -1,8 +1,8 @@
import { ComponentMeta, ComponentStory } from "@storybook/react";
import { ConnectedAutomationList } from ".";
import { NODE_HEIGHT, NODE_WIDTH, ADD_HEIGHT, ADD_WIDTH, CIRCLE_SIZE, DISTANCE_FACTOR } from 'components/DAGSvgs/constants';
import { createMockAuto } from "utils/mocks";
import { useMockApiService } from "apiService";
import * as dgconst from 'components/DAGSvgs/constants';
export default {
title: 'App/AutomationList/Connected',
@@ -10,12 +10,14 @@ export default {
parameters: { actions: { argTypesRegex: '^on.*' } },
args: {
dims: {
nodeHeight: NODE_HEIGHT,
nodeWidth: NODE_WIDTH,
addHeight: ADD_HEIGHT,
addWidth: ADD_WIDTH,
circleSize: CIRCLE_SIZE,
distanceFactor: DISTANCE_FACTOR,
nodeHeight: dgconst.NODE_HEIGHT,
nodeWidth: dgconst.NODE_WIDTH,
distanceFactor: dgconst.DISTANCE_FACTOR,
circleSize: dgconst.CIRCLE_SIZE,
padding: {
x: dgconst.PADDING,
y: dgconst.PADDING,
},
},
initialAutomations: [],
}
+10 -9
View File
@@ -1,21 +1,22 @@
/* root elements */
.automation-list--root {
width : 100%;
height : 100%;
display : flex;
width: 100%;
height: 100%;
display: flex;
flex-direction: row;
overflow : hidden;
overflow: hidden;
}
.automation-list--list {
flex : 1;
flex: 1;
min-width: 400px;
max-width: 400px;
position : relative;
position: relative;
}
.automation-list--viewer {
overflow: hidden;
flex: 1;
}
/* list children: on hide */
@@ -41,6 +42,6 @@
.automation-list--list-hide {
position: absolute;
bottom : 10px;
right : 5px;
}
bottom: 0.5em;
right: 0.5em;
}
@@ -2,12 +2,12 @@ import "./index.css";
import { AutomationEditor } from "components/AutomationEditor";
import { FC, useState } from "react";
import { AutomationData } from "types/automations";
import { DAGBoardElmDims } from 'components/DAGSvgs/DAGBoard';
import { defaultAutomation } from '../../utils/defaults';
import { defaultAutomation } from 'utils/defaults';
import { ArrowIcon } from "components/Icons";
import { ButtonIcon } from "components/Icons/ButtonIcons";
import { ApiService } from "apiService/core";
import { AutomationListBox } from "./AutomationListBox";
import { DAGAutomationFlowDims } from 'components/DAGFlow/types';
interface AutomationListParams {
@@ -15,7 +15,7 @@ interface AutomationListParams {
onUpdate: (i: number, auto: AutomationData) => void;
onAdd: (auto: AutomationData) => void;
onRemove: (i: number) => void;
dims: DAGBoardElmDims;
dims: DAGAutomationFlowDims;
}
export const AutomationList: FC<AutomationListParams> = ({
@@ -63,7 +63,7 @@ export const AutomationList: FC<AutomationListParams> = ({
}
interface ConnectedAutomationListParams {
dims: DAGBoardElmDims;
dims: DAGAutomationFlowDims;
api: ApiService;
}
export const ConnectedAutomationList: FC<ConnectedAutomationListParams> = ({
@@ -0,0 +1,66 @@
import { FC } from "react";
import { AddIcon, PencilIcon, TrashIcon } from '../Icons/index';
import { useCircleStyles } from './styles';
import { Handle, Position, XYPosition } from 'react-flow-renderer';
export interface DAGCircleProps {
onEdit?: () => void;
onAdd?: () => void;
onRemove?: () => void;
size: number,
backgroundColor?: string;
disableSource?: boolean;
disableTarget?: boolean;
}
export const makeFlowCircle = (
circleId: string,
position: XYPosition,
data: DAGCircleProps,
) => ({
id: circleId,
type: 'dagcircle',
position,
data
})
export const DAGCircle: FC<{ data: DAGCircleProps }> = ({
data: {
size,
onEdit,
onAdd,
onRemove,
backgroundColor,
disableSource = false,
disableTarget = false,
}
}) => {
const { classes } = useCircleStyles({
size,
hasOnFunction: !!onEdit || !!onAdd,
hasRemoveFunction: !!onRemove,
backgroundColor,
});
return <>
{!disableSource && <Handle type="source" position={Position.Right} />}
{!disableTarget && <Handle type="target" position={Position.Left} />}
<div className={classes.root}>
{
onEdit ?
<PencilIcon
size={70} units="%"
className={classes.icon}
onClick={onEdit}
/> : onAdd ?
<AddIcon
size={70} units="%"
className={classes.icon}
onClick={onAdd}
/>
: backgroundColor ? "" : "else"
}
{onRemove ? <TrashIcon className={classes.trashIcon} onClick={onRemove} /> : <></>}
</div>
</>
}
+57
View File
@@ -0,0 +1,57 @@
import Color from "chroma-js";
import { PencilIcon } from "components/Icons"
import { NodeColor } from "types/graphs";
import { useNodeStyles } from "./styles";
import { Handle, Position } from 'react-flow-renderer';
import { FC } from "react";
export interface DAGNodeProps {
height: number;
width: number;
onXClick?: () => void;
onEditClick?: () => void;
color: NodeColor;
label: string;
hasInput?: boolean;
}
export const DAGNode: FC<{ data: DAGNodeProps }> = ({
data: {
label,
height,
width,
onXClick = () => { },
onEditClick = () => { },
color,
hasInput = false,
},
}) => {
const { classes, theme } = useNodeStyles({
color,
nodeHeight: height,
nodeWidth: width,
});
return <>
{hasInput && <Handle type="target" position={Position.Left} />}
<Handle type="source" position={Position.Right} />
<div className={classes.root}>
<div className={classes.inner}>
<div className={classes.leftEdge} onClick={onXClick}>
<button className={classes.buttonDelete}>X</button>
</div>
<div className={classes.textWrap}>
<span className={classes.text} title={label}>
{label}
</span>
</div>
<div className={classes.rightEdge} onClick={() => {
console.log('editing me', label, onEditClick, onEditClick())
}}>
<button className={classes.buttonEdit}>
<PencilIcon size={1.1} color={Color(theme.primary).set('rgb.g', 200).hex()} />
</button>
</div>
</div>
</div>
</>
}
@@ -0,0 +1,290 @@
import React from "react";
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { DAGAutomationFlow } from '.';
import { useState } from 'react';
import * as dgconst from "components/DAGSvgs/constants";
export default {
title: 'DAGAutomationFlow/Viewer',
component: DAGAutomationFlow,
parameters: { actions: { argTypesRegex: '^on.*' } },
args: {
dims: {
nodeHeight: dgconst.NODE_HEIGHT,
nodeWidth: dgconst.NODE_WIDTH,
distanceFactor: dgconst.DISTANCE_FACTOR,
circleSize: dgconst.CIRCLE_SIZE,
padding: {
x: dgconst.PADDING,
y: dgconst.PADDING,
},
}
}
} as ComponentMeta<typeof DAGAutomationFlow>
const Template: ComponentStory<typeof DAGAutomationFlow> = args => {
const [state, setState] = useState({
trigger: args.trigger,
sequence: args.sequence,
})
console.log(state)
return <div className="page">
<DAGAutomationFlow
{...args}
{...state}
onTriggerUpdate={trigger => {
console.log({ trigger })
setState({ ...state, trigger })
}}
onSequenceUpdate={sequence => setState({ ...state, sequence })}
/>
</div>
}
export const Simple = Template.bind({})
Simple.args = {
...Simple.args,
trigger: [
{
"$smType": undefined,
"platform": "numeric_state",
"entity_id": "test",
},
{
"$smType": undefined,
"platform": "homeassistant",
"event": "start",
}
],
sequence: [
{
$smType: "condition",
condition: 'and',
condition_data: {
conditions: [
{
$smType: 'condition',
condition: 'numeric_state',
condition_data: {
entity_id: 'sensor.temperature_kitchen',
below: '15',
}
},
{
$smType: "condition",
condition: 'template',
condition_data: {
value_template: 'states(switch.kitchen_light) == "on"'
}
}
]
}
},
{
$smType: "action",
action: "service",
action_data: {
alias: "Start Music In Kitchen",
service: 'media_player.play_media',
target: {
entity_id: "media_player.kitchen_dot"
},
data: {
media_content_id: "Good Morning",
media_content_type: "SPOTIFY",
}
}
}
]
}
export const Complex = Template.bind({})
Complex.args = {
...Complex.args,
trigger: [
{
"$smType": undefined,
"platform": "numeric_state",
"entity_id": "test",
},
{
"$smType": undefined,
"platform": "homeassistant",
"event": "start",
}
],
sequence: [
{
"$smType": "condition",
"condition": "and",
"condition_data": {
"conditions": [
{
"$smType": "condition",
"condition": "numeric_state",
"condition_data": {
"entity_id": "sensor.temperature_kitchen",
"below": "15"
}
},
{
"$smType": "condition",
"condition": "template",
"condition_data": {
"value_template": "states(switch.kitchen_light) == \"on\""
}
}
]
}
},
{
"$smType": "action",
"action": "service",
"action_data": {
"alias": "Start Music In Kitchen",
"service": "media_player.play_media",
"target": {
"entity_id": "media_player.kitchen_dot"
},
"data": {
"media_content_id": "Good Morning",
"media_content_type": "SPOTIFY"
}
}
},
{
"$smType": "action",
"action": "choose",
"action_data": {
"choose": [
{
"conditions": [
{
"$smType": "condition",
"condition": "state",
"condition_data": {
"entity_id": "lights.bathroom",
"state": "off",
}
}
],
"sequence": [
{
"$smType": "action",
"action": "service",
"action_data": {
"service": "light.turn_on",
"target": {
"entity_id": "lights.bathroom"
},
"data": {}
}
},
{
"$smType": "action",
"action": "service",
"action_data": {
"alias": "Turn off bedroom",
"service": "light.turn_off",
"target": {
"entity_id": "lights.bedroom"
},
"data": {}
}
}
]
},
{
"conditions": [
{
"$smType": "condition",
"condition": "state",
"condition_data": {
"entity_id": "lights.bedroom",
"state": "off",
}
}
],
"sequence": [
{
"$smType": "action",
"action": "service",
"action_data": {
"alias": "Turn on bedroom",
"service": "light.turn_on",
"target": {
"entity_id": "lights.bedroom"
},
"data": {}
}
},
{
"$smType": "action",
"action": "choose",
"action_data": {
"choose": [
{
"conditions": [],
"sequence": [
{
"$smType": "action",
"action": "choose",
"action_data": {
"choose": [],
"default": [],
}
}
]
}
],
"default": [
{
"$smType": "action",
"action": "choose",
"action_data": {
"choose": [],
"default": [],
}
}
],
}
}
]
}
],
"default": [
{
"$smType": "action",
"action": "service",
"action_data": {
"service": "light.turn_off",
"target": {
"entity_id": "lights.bathroom"
},
"data": {}
}
}
]
}
},
{
"$smType": "condition",
"condition": "and",
"condition_data": {
"conditions": []
}
}
]
}
export const EmptyStart = Template.bind({})
EmptyStart.args = {
...EmptyStart.args,
trigger: [
],
sequence: []
}
+136
View File
@@ -0,0 +1,136 @@
import { FC, useState } from "react";
import ReactFlow, { MiniMap, Controls } from 'react-flow-renderer';
import { AutomationSequenceNode } from "types/automations";
import { AutomationTrigger } from 'types/automations/triggers';
import { triggerToFlow } from "./triggerConvertor";
import { DAGNode } from "./DAGNode";
import { DAGAutomationFlowDims, FlowData, ModalState } from './types';
import { DAGCircle } from './DAGCircle';
import { sequenceToFlow } from "./sequenceConvertor";
import { makeSequenceUpdater } from "./updater";
import { NodeEditor } from "components/NodeEditor";
import { MultiNodeEditor } from "components/MultiNodeEditors";
import { Modal } from "components/Modal";
const nodeTypes = {
'dagnode': DAGNode,
'dagcircle': DAGCircle,
}
interface Props {
className?: string;
sequence: AutomationSequenceNode[];
trigger: AutomationTrigger[];
dims: DAGAutomationFlowDims;
onTriggerUpdate: (t: AutomationTrigger[]) => void;
onSequenceUpdate: (s: AutomationSequenceNode[]) => void;
}
export const DAGAutomationFlow: FC<Props> = ({
className,
sequence,
trigger,
onTriggerUpdate,
onSequenceUpdate,
dims,
}) => {
// state
const [modalState, setModalState] = useState<ModalState | null>(null);
// modal
let modalBody = <></>
if (modalState) {
if (modalState.single) {
modalBody = <NodeEditor
node={modalState.node}
onClose={() => setModalState(null)}
onSave={n => { modalState.update(n as any); setModalState(null); }}
allowedTypes={modalState.allowedTypes}
saveBtnCreateText={modalState.saveBtnCreateText}
/>
} else {
modalBody = <MultiNodeEditor
sequence={modalState.node}
onClose={() => setModalState(null)}
onSave={(n) => {
modalState.update(n as any);
setModalState(null);
}}
allowedTypes={['condition']}
/>
}
}
// convert automation to flow data
const condPoint = makeConditionPoint(dims);
const flowData: FlowData = {
nodes: [condPoint],
edges: [],
}
triggerToFlow(flowData, trigger, condPoint.id, dims, {
onAdd: () => onTriggerUpdate([
...trigger, {
platform: 'event',
$smType: 'trigger',
event_type: 'test',
}
]),
onDelete: i => onTriggerUpdate([
...trigger.slice(0, i),
...trigger.slice(i + 1)
]),
onEdit: i => setModalState({
single: true,
node: trigger[i],
update: t => onTriggerUpdate([
...trigger.slice(0, i),
t,
...trigger.slice(i + 1)
]),
allowedTypes: ['trigger'],
})
});
sequenceToFlow(
flowData,
sequence,
condPoint.id,
dims,
makeSequenceUpdater(sequence, onSequenceUpdate, setModalState),
);
// render
return <>
<Modal open={!!modalState}>
{modalBody}
</Modal>
<ReactFlow
className={className}
nodeTypes={nodeTypes}
snapToGrid
onlyRenderVisibleElements
nodesConnectable={false}
nodesDraggable={false}
{...flowData}
>
<MiniMap />
<Controls />
</ReactFlow>
</>;
}
const makeConditionPoint = ({
padding,
nodeWidth,
nodeHeight,
circleSize,
}: DAGAutomationFlowDims) => ({
id: `c`,
type: 'dagcircle',
position: { x: padding.x + nodeWidth * 2, y: padding.y + nodeHeight * 0.25 },
data: {
size: circleSize,
backgroundColor: 'blue',
}
})
@@ -0,0 +1,209 @@
import { AutomationSequenceNode } from 'types/automations';
import { DAGAutomationFlowDims, FlowData } from './types';
import { getDescriptionFromAutomationNode } from 'utils/formatting';
import { XYPosition } from 'react-flow-renderer';
import { ChooseAction } from 'types/automations/actions';
import { makeFlowCircle } from './DAGCircle';
import { createOnRemoveForChooseNode, SequenceUpdater } from './updater';
export const sequenceToFlow = (
flowData: FlowData,
sequence: AutomationSequenceNode[],
fromPoint: string,
dims: DAGAutomationFlowDims,
updater: SequenceUpdater,
prefix: string = "",
) => {
let lastPointId = fromPoint;
let lasPos: XYPosition | null = null;
// sequence
for (let i = 0; i < sequence.length; i++) {
const node = sequence[i];
const nodeId = `${prefix}n-${i}`;
let position: XYPosition;
if (lasPos) {
position = {
x: lasPos.x + dims.nodeWidth * dims.distanceFactor,
y: dims.padding.y
}
} else {
position = {
x: dims.padding.x + dims.nodeWidth * dims.distanceFactor * (i + 2),
y: dims.padding.y
};
}
// draw node
if (node.$smType === 'action') {
if (node.action === 'choose') {
position = addChooseNode(flowData, node, position, nodeId, dims, updater, i)
} else {
addSingleNode(flowData, node, position, nodeId, dims, {
onEditClick: updater.makeOnModalOpenForNode(i, node),
onXClick: () => updater.removeNode(i)
});
}
} else {
addSingleNode(flowData, node, position, nodeId, dims, {
onEditClick: updater.makeOnModalOpenForNode(i, node),
onXClick: () => updater.removeNode(i)
});
}
addEdge(flowData, lastPointId, nodeId, false)
lastPointId = nodeId;
lasPos = position;
}
// add button
const addCircle = makeFlowCircle(
`${prefix}-+`,
{
x: (lasPos === null ? dims.padding.x + dims.nodeWidth * dims.distanceFactor * (sequence.length + 1) : lasPos.x) + dims.nodeWidth * dims.distanceFactor,
y: dims.padding.y + dims.circleSize / 2
},
{ onAdd: updater.addNode, size: dims.circleSize, disableSource: true, }
)
flowData.nodes.push(addCircle)
addEdge(flowData, lastPointId, addCircle.id, false)
return {
position: lasPos,
pointId: lastPointId,
};
}
const xyApply = (p1: XYPosition, p2: XYPosition, fcn: (a: number, b: number) => number): XYPosition => ({
x: fcn(p1.x, p2.x), y: fcn(p1.y, p2.y)
})
const addEdge = (flowData: FlowData, source: string, target: string, animated: boolean = false) => flowData.edges.push({
id: `${source}-${target}`,
source,
target,
animated,
})
const addSingleNode = (
flowData: FlowData,
node: AutomationSequenceNode,
position: XYPosition,
nodeId: string,
{
nodeHeight,
nodeWidth,
}: DAGAutomationFlowDims,
opts: {
onEditClick: () => void;
onXClick: () => void;
}
) => flowData.nodes.push({
id: nodeId,
type: 'dagnode',
data: {
label: getDescriptionFromAutomationNode(node),
height: nodeHeight,
width: nodeWidth,
color: node.$smType === 'action' ? 'green' : 'blue',
hasInput: true,
...opts,
},
position,
});
const addChooseNode = (
flowData: FlowData,
node: ChooseAction,
position: XYPosition,
nodeId: string,
dims: DAGAutomationFlowDims,
updater: SequenceUpdater,
i: number,
) => {
addSingleNode(flowData, node, position, nodeId, dims, {
onEditClick: updater.makeOnModalOpenForNode(i, node),
onXClick: () => updater.removeNode(i),
});
let lastPos: XYPosition = position;
// conditions
node.action_data.choose.forEach(({ sequence, conditions }, j) => {
const sequenceId = `${nodeId}.${j}`;
// edit/delete circle
const circle = makeFlowCircle(`${sequenceId}>cond`, {
x: position.x + dims.nodeWidth * dims.distanceFactor,
y: lastPos.y + dims.nodeHeight * dims.distanceFactor,
}, {
size: dims.circleSize * dims.distanceFactor,
onEdit: updater.makeOnEditConditionsForChooseNode(i, j),
onRemove: createOnRemoveForChooseNode(
node,
d => updater.updateNode(i, d),
j,
),
})
flowData.nodes.push(circle)
addEdge(flowData, nodeId, circle.id, true)
// actual sub sequence
const lastPoint = sequenceToFlow(flowData, sequence, circle.id, {
...dims,
padding: {
x: position.x - dims.nodeWidth,
y: circle.position.y,
},
}, updater.makeChildUpdaterForChooseAction(i, j), `${sequenceId}.`);
if (lastPoint.position) {
lastPos = xyApply(lastPos, lastPoint.position, Math.max)
} else {
lastPos = xyApply(lastPos, { x: lastPos.x, y: lastPos.y + dims.nodeHeight * dims.distanceFactor }, Math.max)
}
})
const totalChildren = node.action_data.choose.length;
// add button
const addCirlce = makeFlowCircle(
`${nodeId}>add`, {
x: position.x + dims.nodeWidth * dims.distanceFactor,
y: lastPos.y + dims.nodeHeight * dims.distanceFactor,
},
{
size: dims.circleSize * dims.distanceFactor,
onAdd: () => updater.updateNode(i, {
...node,
action_data: {
...node.action_data,
choose: [
...node.action_data.choose,
{
sequence: [],
conditions: [],
}
]
}
}),
disableSource: true,
}
);
flowData.nodes.push(addCirlce)
addEdge(flowData, nodeId, addCirlce.id, true)
// default
const elseCircle = makeFlowCircle(`${nodeId}>else`, {
x: position.x + dims.nodeWidth * dims.distanceFactor,
y: lastPos.y + dims.nodeHeight * dims.distanceFactor * 2,
}, { size: dims.circleSize * dims.distanceFactor })
flowData.nodes.push(elseCircle)
addEdge(flowData, nodeId, elseCircle.id, true)
const lastPoint = sequenceToFlow(flowData, node.action_data.default, elseCircle.id, {
...dims,
padding: {
x: position.x - dims.nodeWidth,
y: elseCircle.position.y,
},
}, updater.makeChildUpdaterForChooseAction(i, null), `${nodeId}.${totalChildren}.`)
if (lastPoint.position) {
lastPos = xyApply(lastPos, lastPoint.position, Math.max)
} else {
lastPos = xyApply(lastPos, elseCircle.position, Math.max)
}
return lastPos
}
@@ -3,43 +3,6 @@ import Color from 'chroma-js';
import { createAppUseStyles } from "styles/theme";
import { Node } from "types/graphs";
export const useBoardStyles = createAppUseStyles<{
boardHeight: number,
boardWidth: number,
}>(theme => ({
dag: {
borderWidth: 1,
borderStyle: 'solid',
borderColor: theme.secondaryAccent,
color: theme.primaryAccent,
background: theme.primary,
width: '100%',
height: '100%',
overflow: 'scroll'
},
svg: ({ boardHeight, boardWidth }) => ({
minHeight: `${boardHeight}px`,
minWidth: `${boardWidth}px`,
padding: 0,
margin: 0,
}),
circle: {
fill: Color(theme.secondary).set('rgb.b', 125).hex(),
},
infoBox: {
paddingLeft: '10px',
paddingRight: '10px',
display: 'flex',
flexDirection: 'column',
justifyContent: 'flex-start',
overflow: 'auto',
},
dagEdge: {
stroke: theme.secondaryAccent,
},
}))
export const useNodeStyles = createAppUseStyles<{
color: Node['color'],
nodeHeight: number,
@@ -68,16 +31,16 @@ export const useNodeStyles = createAppUseStyles<{
cursor: 'pointer',
}
return {
root: {
root: ({ nodeHeight, nodeWidth }) => ({
display: 'flex',
flexDirection: 'column',
justifyContent: 'flex-end',
height: `100%`,
maxHeight: `100%`,
maxWidth: '100%',
width: '100%',
height: nodeHeight,
maxHeight: nodeHeight,
maxWidth: nodeWidth,
width: nodeWidth,
fontSize: 10,
},
}),
inner: ({ color }) => ({
position: 'relative',
display: 'flex',
@@ -0,0 +1,57 @@
import { AutomationTrigger } from 'types/automations/triggers';
import { DAGAutomationFlowDims, FlowData, TriggerMakerOptions } from './types';
import { makeFlowCircle } from './DAGCircle';
export const triggerToFlow = (
flowData: FlowData,
trigger: AutomationTrigger[],
toPoint: string,
{
distanceFactor,
nodeHeight,
nodeWidth,
circleSize,
padding,
}: DAGAutomationFlowDims,
opts: TriggerMakerOptions,
) => {
// convert all triggers to dag nodes
trigger.forEach((t, i) => {
const flowId = `t-${i}`;
flowData.nodes.push({
id: flowId,
type: 'dagnode',
data: {
label: t.alias ?? t.platform,
height: nodeHeight,
width: nodeWidth,
color: 'red',
onEditClick: () => opts.onEdit(i),
onXClick: () => opts.onDelete(i),
},
position: { x: padding.x, y: padding.y + nodeHeight * distanceFactor * i }
})
flowData.edges.push({
id: `e(${flowId})-(${toPoint})`,
source: flowId,
target: toPoint,
})
});
// create a 'add button'
flowData.nodes.push(makeFlowCircle(
'trigger-add',
{
x: padding.x + nodeWidth * 0.4,
y: padding.y + nodeHeight * distanceFactor * trigger.length,
},
{
size: circleSize,
backgroundColor: 'green',
onAdd: opts.onAdd,
disableSource: true,
disableTarget: true,
}
))
}
+44
View File
@@ -0,0 +1,44 @@
import { Edge, Node, XYPosition } from 'react-flow-renderer';
import { AutomationSequenceNode } from 'types/automations';
import { DAGCircleProps } from './DAGCircle';
import { DAGNodeProps } from './DAGNode';
import { AutomationTrigger } from 'types/automations/triggers';
import { MultiNodeEditorProps } from 'components/MultiNodeEditors';
export type DAGAutomationFlowDims = {
padding: XYPosition;
nodeHeight: number;
nodeWidth: number;
circleSize: number;
distanceFactor: number;
}
export type DAGAutomationFlowNode = Node<DAGNodeProps | DAGCircleProps | any>;
export type FlowData = {
nodes: DAGAutomationFlowNode[],
edges: Edge[],
}
export type TriggerMakerOptions = {
onAdd: () => void,
onEdit: (i: number) => void,
onDelete: (i: number) => void,
}
export type UpdateModalState<T extends AutomationSequenceNode | AutomationTrigger = any> = (
s: ModalState<T>
) => void;
export type ModalState<T extends AutomationSequenceNode | AutomationTrigger = any> = {
single: true,
node: T
update: (n: T) => void;
saveBtnCreateText?: boolean;
allowedTypes: MultiNodeEditorProps['allowedTypes'],
} | {
single: false,
node: AutomationSequenceNode[]
update: (n: AutomationSequenceNode[]) => void;
allowedTypes: ['condition']
}
@@ -0,0 +1,85 @@
import { AutomationSequenceNode } from "types/automations"
import { ChooseAction } from "types/automations/actions";
import { ModalState } from "./types";
import { makeSequenceUpdater } from "./updater"
const mockSequenceUpdater = (defaultState: AutomationSequenceNode[] = []) => {
let state: AutomationSequenceNode[] = [...defaultState]
const modalStates: ModalState[] = [];
const updater = makeSequenceUpdater(
state,
s => {
state = s
console.log(state, s)
},
ms => modalStates.push(ms)
);
return {
get state() {
return state
},
modalStates,
updater
};
}
test("sequence updater updates nodes", () => {
const mock = mockSequenceUpdater([
{
"$smType": "action",
"action": "choose",
"action_data": {
"choose": [
{
"conditions": [],
"sequence": [],
}
],
"default": [],
}
}
]);
expect(mock.state.length).toBe(1)
expect((mock.state[0] as ChooseAction).action_data.alias).toBe(undefined)
mock.updater.updateNode(0, {
...mock.state[0],
action_data: {
...(mock.state[0] as ChooseAction).action_data,
alias: "Hello"
}
} as any)
expect((mock.state[0] as ChooseAction).action_data.alias).toBe("Hello")
})
test('update conditions for node', () => {
const mock = mockSequenceUpdater([
{
"$smType": "action",
"action": "choose",
"action_data": {
"choose": [
{
"conditions": [],
"sequence": [],
}
],
"default": [],
}
}
]);
mock.updater.makeOnEditConditionsForChooseNode(0, 0)();
expect(mock.modalStates.length).toBe(1)
expect((mock.modalStates[0].node as AutomationSequenceNode[]).length).toBe(0)
mock.modalStates[0].update([
{
"$smType": "condition",
"condition": "and",
"condition_data": {
"conditions": [],
}
}
] as any)
expect((mock.state[0] as ChooseAction).action_data.choose[0].conditions.length).toBe(1)
expect((mock.state[0] as ChooseAction).action_data.choose[0].conditions[0].condition).toBe("and")
})
@@ -1,10 +1,11 @@
import { AutomationSequenceNode } from "types/automations";
import { ChooseAction } from "types/automations/actions";
import { AutomationCondition } from "types/automations/conditions";
import { UpdateModalState } from "./types";
export type Updater = ReturnType<typeof makeUpdater>;
export type SequenceUpdater = ReturnType<typeof makeSequenceUpdater>;
export const makeUpdater = (
export const makeSequenceUpdater = (
sequence: AutomationSequenceNode[],
onChange: (s: AutomationSequenceNode[]) => void,
openModal: UpdateModalState,
@@ -14,7 +15,7 @@ export const makeUpdater = (
removeNode(i: number) {
return onChange([
...sequence.slice(0, i),
...sequence.slice(i+1),
...sequence.slice(i + 1),
])
},
addNode() {
@@ -33,14 +34,14 @@ export const makeUpdater = (
...sequence,
n,
]),
onlyConditions: false,
allowedTypes: ['action', 'condition']
})
},
updateNode(i: number, node: AutomationSequenceNode) {
return onChange([
...sequence.slice(0, i),
node,
...sequence.slice(i+1),
...sequence.slice(i + 1),
])
},
updateChooseActionData(i: number, data: ChooseAction['action_data']) {
@@ -50,11 +51,11 @@ export const makeUpdater = (
action_data: data,
})
},
makeChildUpdaterForChooseAction(i: number, j:number | null) {
makeChildUpdaterForChooseAction(i: number, j: number | null) {
const node = sequence[i];
if ((node.$smType === 'action') && (node.action === 'choose')) {
if (j !== null) {
return makeUpdater(
return makeSequenceUpdater(
node.action_data.choose[j].sequence,
seq => this.updateNode(i, {
...node,
@@ -66,14 +67,14 @@ export const makeUpdater = (
...node.action_data.choose[j],
sequence: seq,
},
...node.action_data.choose.slice(j+1),
...node.action_data.choose.slice(j + 1),
]
}
}),
openModal,
)
} else {
return makeUpdater(
return makeSequenceUpdater(
node.action_data.default,
seq => this.updateNode(i, {
...node,
@@ -87,5 +88,59 @@ export const makeUpdater = (
}
}
throw new Error(`Cannot create sub-updater for ${node}`)
},
makeOnModalOpenForNode(
i: number,
node: AutomationSequenceNode,
) {
return () => openModal({
single: true,
node,
allowedTypes: ['action', 'condition'],
update: n => this.updateNode(i, n),
})
},
makeOnEditConditionsForChooseNode(
i: number,
j: number,
) {
return () => {
const node = sequence[i] as ChooseAction;
return openModal({
single: false,
node: node.action_data.choose[j].conditions,
allowedTypes: ['condition'],
update: conditions => this.updateNode(i, {
...node,
action_data: {
...node.action_data,
choose: [
...node.action_data.choose.slice(0, j),
{
sequence: node.action_data.choose[j].sequence,
conditions: conditions as AutomationCondition[],
},
...node.action_data.choose.slice(j + 1),
]
}
}),
})
}
}
});
export const createOnRemoveForChooseNode = (
action: ChooseAction,
update: (data: ChooseAction) => void,
j: number
) => () => update({
...action,
action_data: {
...action.action_data,
choose: [
...action.action_data.choose.slice(0, j),
...action.action_data.choose.slice(j + 1),
]
}
})
@@ -1,11 +0,0 @@
.dag-svg--add-btn > a {
height: 100%;
width: 100%;
}
.dag-svg--add-btn > a:hover > svg {
fill: rgb(48, 189, 59);
}
.dag-svg--add-btn:hover {
cursor: pointer;
}
@@ -1,24 +0,0 @@
import React from "react";
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { SVGBoard } from './Board';
import { AddButton } from "./AddButton";
export default {
title: 'DAGSvgs/AddButton',
component: AddButton,
parameters: { actions: { argTypesRegex: '^on.*' } },
args: {
height: 10,
width: 10,
loc: [50, 50]
}
} as ComponentMeta<typeof AddButton>
export const Basic: ComponentStory<typeof AddButton> = args => {
return <SVGBoard>
<AddButton
{...args}
/>
</SVGBoard>
}
@@ -1,24 +0,0 @@
import "./AddButton.css";
import { Point } from "types/graphs";
import { AddIcon } from '../Icons/index';
export interface AddProps {
onClick?: () => void;
loc: Point,
height: number,
width: number,
}
export const AddButton = ({
loc: [x, y],
height,
width,
onClick = () => { },
}: AddProps) => {
return <>
<foreignObject className="dag-svg--add-btn" x={x} y={y} width={width} height={height}>
<AddIcon onClick={onClick} />
</foreignObject>
</>
}
-51
View File
@@ -1,51 +0,0 @@
import { FC } from 'react';
import useWindowSize from "utils/useWindowSize";
import { useBoardStyles } from "./styles";
import { NODE_HEIGHT, NODE_WIDTH } from './constants';
export const SVGBoard: FC<{
graphHeight?: number,
minGraphWidth?: number,
nodeHeight?: number,
nodeWidth?: number,
zoomLevel?: number,
}> = ({
children,
graphHeight = 300,
minGraphWidth = 300,
nodeHeight = NODE_HEIGHT,
nodeWidth = NODE_WIDTH,
zoomLevel = 100,
}) => {
// state
const { ratioWbh } = useWindowSize();
// alias
const paddedZoomLevel = zoomLevel / 100;
const graphWidth = Math.max(
Math.round(graphHeight * ratioWbh),
minGraphWidth
);
const { classes, theme } = useBoardStyles({
boardHeight: Math.max(nodeHeight, graphHeight) * paddedZoomLevel,
boardWidth: Math.max(4 * nodeWidth, graphWidth) * paddedZoomLevel,
});
// render
return <div className={classes.dag} >
<svg
className={classes.svg}
viewBox={[0, 0, graphWidth / paddedZoomLevel, graphHeight / paddedZoomLevel].join(" ")}
xmlns="http://www.w3.org/2000/svg"
>
<defs>
<marker id="arrow" viewBox="0 0 10 10" refX="10" refY="5"
markerWidth="6" markerHeight="6"
orient="auto-start-reverse">
<path d="M 0 0 L 10 5 L 0 10 z" fill={theme.secondaryAccent} />
</marker>
</defs>
{children}
</svg>
</div>
}
@@ -1,160 +0,0 @@
import React from "react";
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { DAGBoard, DAGElement, DAGNodeElm } from "./DAGBoard";
import { NODE_HEIGHT, NODE_WIDTH, ADD_HEIGHT, ADD_WIDTH, DISTANCE_FACTOR, CIRCLE_SIZE } from './constants';
import { AutomationAction } from 'types/automations/actions';
export default {
title: 'DAGSvgs/DAGBoard',
component: DAGBoard,
parameters: { actions: { argTypesRegex: '^on.*' } },
args: {
zoomLevel: 100,
settings: {
nodeHeight: NODE_HEIGHT,
nodeWidth: NODE_WIDTH,
addHeight: ADD_HEIGHT,
addWidth: ADD_WIDTH,
circleSize: CIRCLE_SIZE,
distanceFactor: DISTANCE_FACTOR,
edgeChildColor: 'blue',
edgeNextColor: 'white',
},
}
} as ComponentMeta<typeof DAGBoard>;
const nodeFromPoint = ([x, y, add = true]: any): DAGNodeElm => ({
type: 'node',
loc: [x, y],
onRemove() { },
onAdd: add ? () => { } : undefined,
node: ({
alias: `${x},${y}`,
"$smType": "action",
"action": "wait",
"action_data": {
"wait_template": "",
}
} as AutomationAction)
});
function* makeDummyData(pts: Array<any>, extras: DAGElement[]): Generator<DAGElement> {
for (const p of pts) {
yield nodeFromPoint(p);
};
for (const e of extras) {
yield e;
}
}
export const Simple: ComponentStory<typeof DAGBoard> = args => {
return <div className="page">
<DAGBoard {...args} />
</div>
}
Simple.args = {
...Simple.args,
elements: Array.from(makeDummyData(
[
[0, 0, false],
[1, 0, false],
[2, 1, false],
],
[
{
type: 'edge',
p1: [0, 0],
p2: [1, 0],
direction: '1->2'
},
{
type: 'edge',
p1: [2, 1],
p2: [2, 3],
direction: '1->2'
},
{
type: 'circle',
icon: 'blank',
loc: [2, 3]
},
{
type: 'edge',
p1: [2, 1],
p2: [2, 2],
direction: '1->2'
},
{
type: 'circle',
loc: [2, 2],
icon: 'color',
color: 'red',
}
]))
}
export const Complex: ComponentStory<typeof DAGBoard> = args => {
return <div className="page">
<DAGBoard {...args} />
</div>
}
Complex.args = {
...Complex.args,
elements: Array.from(makeDummyData(
[
[0, 0, false],
[1, 0, false],
[2, 1, false],
[4, 1],
[3, 2],
[2, 3],
[5, 0, false],
[6, 0],
[0, 6],
],
[
{
type: 'edge',
p1: [0, 0],
p2: [1, 0],
direction: '1->2'
},
{
type: 'edge',
p1: [2, 1],
p2: [4, 1],
direction: '1->2',
},
{
type: 'edge',
p1: [1, 0],
p2: [2, 1],
direction: '1->2',
},
{
type: 'edge',
p1: [2, 1],
p2: [3, 2],
direction: '1->2',
},
{
type: 'edge',
p1: [1, 0],
p2: [2, 3],
direction: '1->2',
},
{
type: 'edge',
p1: [1, 0],
p2: [5, 0],
direction: '1->2'
},
]
))
}
-205
View File
@@ -1,205 +0,0 @@
import { FC, useRef } from "react";
import { SVGBoard } from "./Board";
import { AutomationNode } from '../../types/automations/index';
import { Point, EdgeDirection, BBox } from 'types/graphs';
import { DAGNode } from "./DAGNode";
import { DAGEdge } from "./DAGEdge";
import { AddButton } from "./AddButton";
import { IteratorWrap } from "utils/iter";
import { DAGCircle, AddProps } from "./DAGCircle";
import { getDescriptionFromAutomationNode } from "utils/formatting";
import { minPoints } from "utils/graph";
import { maxPoints } from '../../utils/graph';
export type DAGCircleElm = {
type: 'circle';
loc: Point;
} & (
{
icon: 'add',
onAdd: () => void;
} |
{
icon: 'edit',
onEdit: () => void;
onRemove?: () => void;
} |
{
icon: 'blank',
onRemove?: () => void;
} |
{
icon: 'color',
color: string,
}
)
export interface DAGNodeElm {
type: 'node';
loc: Point;
node: AutomationNode;
onRemove: () => void;
onAdd?: () => void;
onOpen?: () => void;
}
export interface DAGEdgeElm {
type: 'edge';
p1: Point;
p2: Point;
direction: EdgeDirection;
fromCircle?: boolean;
onAdd?: () => void;
}
export type DAGElement = DAGEdgeElm | DAGNodeElm | DAGCircleElm;
export interface DAGBoardSettings extends DAGBoardElmDims {
edgeChildColor: string;
edgeNextColor: string;
}
export interface DAGBoardElmDims {
nodeHeight: number;
nodeWidth: number;
addHeight: number;
addWidth: number;
circleSize: number;
distanceFactor: number;
}
export interface Props {
elements: Generator<DAGElement> | Array<DAGElement>;
settings: DAGBoardSettings;
}
export function* mapDataToElements({
elements,
settings: st,
}: Props) {
let bbox: BBox = [[0, 0], [0, 0]];
const updateBBox = (p: Point) => {
bbox = [
[Math.min(bbox[0][0], p[0]), Math.min(bbox[0][1], p[1])],
[Math.max(bbox[1][0], p[0] + st.nodeWidth), Math.max(bbox[1][1], p[1] + st.nodeHeight)],
]
return p;
}
const offsetPoint = (
[x, y]: Point,
[ox, oy]: Point = [0, 0]
): Point => updateBBox([x + ox, y + oy]);
const mapWithNode = (
[x, y]: Point,
[ox, oy]: Point = [0, 0],
): Point => updateBBox([
x * st.nodeWidth * st.distanceFactor + ox,
y * st.nodeHeight * st.distanceFactor + oy,
])
for (let elm of elements) {
switch (elm.type) {
case 'node':
const nodeLoc = mapWithNode(elm.loc);
const addLoc = mapWithNode(elm.loc, [
st.nodeWidth * st.distanceFactor,
st.addHeight + st.addHeight / 2
])
yield <DAGNode
key={`(${elm.loc})-*`}
height={st.nodeHeight}
width={st.nodeWidth}
loc={nodeLoc}
text={getDescriptionFromAutomationNode(elm.node)}
color={elm.node.$smType === 'action' ? 'green' : 'blue'}
onXClick={elm.onRemove}
onOpenClick={elm.onOpen}
/>
if (elm.onAdd) {
yield <DAGEdge
key={`(${elm.loc})->+`}
p1={offsetPoint(nodeLoc, [st.nodeWidth, st.nodeHeight / 2])}
p2={offsetPoint(addLoc, [0, st.addHeight / 2])}
direction="1->2"
color={st.edgeNextColor}
/>
yield <AddButton
key={`(${elm.loc})-+`}
loc={addLoc}
height={st.addHeight}
width={st.addWidth}
onClick={elm.onAdd}
/>
}
break
case 'edge':
const p2 = mapWithNode(elm.p2, [0, st.nodeHeight / 2]);
let p1: Point;
if (elm.fromCircle) {
p1 = mapWithNode(elm.p1, [st.circleSize * 0.95, 1.3 * st.circleSize / 2])
} else {
p1 = mapWithNode(elm.p1, [st.nodeWidth, st.nodeHeight / 2])
}
yield <DAGEdge
key={`(${elm.p1})->(${elm.p2})`}
p1={p1}
p2={p2}
direction={elm.direction}
color={st.edgeNextColor}
/>
if (elm.onAdd) {
yield <AddButton
key={`(${elm.p2})-+`}
loc={offsetPoint(p2, [0, -st.addHeight / 2])}
height={st.addHeight}
width={st.addWidth}
onClick={elm.onAdd}
/>
}
break
case 'circle':
const loc = mapWithNode(elm.loc, [0, st.nodeHeight / 2 - st.circleSize / 2]);
const clickProps: Partial<AddProps> = {}
if (elm.icon === 'add') {
clickProps.onAdd = elm.onAdd;
} else if (elm.icon === 'edit') {
clickProps.onEdit = elm.onEdit
clickProps.onRemove = elm.onRemove
} else if (elm.icon === 'blank') {
clickProps.onRemove = elm.onRemove
} else {
clickProps.backgroundColor = elm.color
}
yield <DAGCircle
key={`(${elm.loc})-o`}
loc={loc}
size={st.circleSize}
{...clickProps}
/>
break
default:
break
}
}
return bbox;
}
export const DAGBoard: FC<Props & { zoomLevel: number }> = props => {
const graphDims = useRef<BBox>([[0, 0], [0, 0]]);
const it = new IteratorWrap(mapDataToElements(props));
const el = it.toArray();
const [p0, p1] = it.returnValue as BBox;
const [[x0, y0], [x1, y1]] = graphDims.current = [
minPoints(p0, graphDims.current[0]),
maxPoints(p1, graphDims.current[1])
];
return <SVGBoard
graphHeight={y1 - y0}
minGraphWidth={Math.max(x1 - x0, props.settings.nodeWidth * 8)}
nodeHeight={props.settings.nodeHeight}
nodeWidth={props.settings.nodeWidth}
zoomLevel={props.zoomLevel}
>
{el}
{props.children}
</SVGBoard>
}
@@ -1,46 +0,0 @@
import React from "react";
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { SVGBoard } from './Board';
import { DAGCircle } from "./DAGCircle";
export default {
title: 'DAGSvgs/DAGCircle',
component: DAGCircle,
parameters: { actions: { argTypesRegex: '^on.*' } },
args: {
size: 20,
loc: [50, 50]
}
} as ComponentMeta<typeof DAGCircle>
export const Basic: ComponentStory<typeof DAGCircle> = args => {
return <SVGBoard>
<DAGCircle
size={args.size}
loc={args.loc}
/>
<DAGCircle
size={args.size}
loc={[args.loc[0] + args.size, args.loc[1]]}
onAdd={args.onAdd}
/>
<DAGCircle
size={args.size}
loc={[args.loc[0] + 2 * args.size, args.loc[1]]}
onEdit={args.onEdit}
/>
<DAGCircle
size={args.size}
loc={[args.loc[0] + 3 * args.size, args.loc[1]]}
onEdit={args.onEdit}
onRemove={args.onRemove}
/>
<DAGCircle
size={args.size}
loc={[args.loc[0] + 4 * args.size, args.loc[1]]}
onRemove={args.onRemove}
/>
</SVGBoard>
}
@@ -1,51 +0,0 @@
// import "./DAGCircle.css";
import { Point } from "types/graphs";
import { AddIcon, PencilIcon, TrashIcon } from '../Icons/index';
import { useCircleStyles } from './styles';
export interface AddProps {
onEdit?: () => void;
onAdd?: () => void;
onRemove?: () => void;
loc: Point,
size: number,
backgroundColor?: string;
}
export const DAGCircle = ({
loc: [x, y],
size,
onEdit,
onAdd,
onRemove,
backgroundColor,
}: AddProps) => {
const { classes } = useCircleStyles({
size: size * 0.9,
hasOnFunction: !!onEdit || !!onAdd,
hasRemoveFunction: !!onRemove,
backgroundColor,
});
return <>
<foreignObject x={x} y={y} width={size} height={size}>
<div className={classes.root}>
{
onEdit ?
<PencilIcon
size={70} units="%"
className={classes.icon}
onClick={onEdit}
/> : onAdd ?
<AddIcon
size={70} units="%"
className={classes.icon}
onClick={onAdd}
/>
: backgroundColor ? "" : "else"
}
{onRemove ? <TrashIcon className={classes.trashIcon} onClick={onRemove} /> : <></>}
</div>
</foreignObject>
</>
}
-59
View File
@@ -1,59 +0,0 @@
import { EdgeDirection, Point } from "types/graphs"
export interface EdgeProp {
p1: Point,
p2: Point,
direction: EdgeDirection,
color: string,
debug?: boolean,
}
export const DAGEdge = ({
p1: [x1, y1],
p2: [x2, y2],
direction,
color,
debug = false,
}: EdgeProp) => {
const [mx, my] = [(x1 + x2) / 2, (y1 + y2) / 2]
let [cx1, cy1] = [(x1 + mx) / 2, (y1 + my) / 2]
let [cx2, cy2] = [(x2 + mx) / 2, (y2 + my) / 2]
const l1 = Math.sqrt((cy1 - y1) ** 2 + (cx1 - x1) ** 2)
const l2 = Math.sqrt((cy2 - y2) ** 2 + (cx2 - x2) ** 2)
const theta = Math.atan2(y2 - y1, x2 - x1)
if ((theta < Math.PI / 2) && (theta > -Math.PI / 2)) {
cy1 = y1 - 0.5 * l1 * Math.sin(theta)
cx1 = x1 + 2 * l1 * Math.cos(theta)
cy2 = y2
cx2 = x2 - 3 * l2 * Math.cos(theta)
} else if ((theta > Math.PI / 2) && (theta < Math.PI)) {
cy2 += l2 * Math.sin(theta)
cx2 += 10 * l2 * Math.cos(theta)
cx1 -= 10 * l1 * Math.cos(theta)
}
return <>
{debug && <>
<circle cx={cx1} cy={cy1} r="5" fill="yellow" />
<line x1={cx1} y1={cy1} x2={x1} y2={y1} stroke="yellow" />
<line x1={cx1} y1={cy1} x2={x2} y2={y2} stroke="yellow" />
<circle cx={cx2} cy={cy2} r="5" fill="green" />
<line x1={cx2} y1={cy2} x2={x1} y2={y1} stroke="green" />
<line x1={cx2} y1={cy2} x2={x2} y2={y2} stroke="green" />
<text x={mx} y={my} stroke="white">{theta}</text>
</>}
<path stroke={color}
d={`M${x1} ${y1} C${cx1} ${cy1}, ${cx2} ${cy2}, ${x2} ${y2}`}
fill="none"
markerStart={
(direction === '1<-2' || direction === '1<->2') ?
"url(#arrow)" : ''
}
markerEnd={
(direction === '1->2' || direction === '1<->2') ?
"url(#arrow)" : ''
}
/>
</>
}
@@ -1,75 +0,0 @@
import React from "react";
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { DAGNode } from "./DAGNode";
import { SVGBoard } from './Board';
import { NODE_HEIGHT, NODE_WIDTH } from './constants';
import { DAGEdge } from "./DAGEdge";
const GRAPH_HEIGHT = 300;
export default {
title: 'DAGSvgs/DAGNode',
component: DAGNode,
parameters: { actions: { argTypesRegex: '^on.*' } },
args: {
height: NODE_HEIGHT,
width: NODE_WIDTH,
text: "Test",
loc: [NODE_WIDTH * 2,GRAPH_HEIGHT / 2]
}
} as ComponentMeta<typeof DAGNode>;
export const Basic: ComponentStory<typeof DAGNode> = args => <SVGBoard
graphHeight={GRAPH_HEIGHT}
>
<DAGNode {...args}/>
</SVGBoard>
export const WithFromEdge: ComponentStory<typeof DAGNode> = args => <SVGBoard
graphHeight={GRAPH_HEIGHT}
>
<DAGNode {...args} />
</SVGBoard>
WithFromEdge.args = {
...(WithFromEdge.args ?? {}),
edge: {
color: 'white',
loc: [NODE_WIDTH * 4, NODE_HEIGHT * 2],
direction: '1->2',
}
}
export const WithToEdge: ComponentStory<typeof DAGNode> = args => <SVGBoard
graphHeight={GRAPH_HEIGHT}
>
<DAGNode {...args} edge={{
color: 'white',
loc: [args.loc[0] - args.width, args.loc[1] + args.height / 2],
direction: '1<-2',
}}/>
</SVGBoard>
export const WithManyEdges: ComponentStory<typeof DAGNode> = args => <SVGBoard
graphHeight={GRAPH_HEIGHT}
>
<DAGNode {...args} />
{[
// TODO: make it nicer to view when from behind
// [0, 0],
// [args.loc[0] - args.width, args.loc[1] + args.height / 2], // behind
// [args.loc[0] - 0.5*args.width, args.loc[1] + args.height ], // behind
// [args.loc[0], args.loc[1] + args.height ], // behind
// [args.loc[0], args.loc[1] + 2 * args.height ], // behind
[args.loc[0] + args.width / 2, args.loc[1] + 2 * args.height ], // below
[args.loc[0] + args.width, args.loc[1] + args.height * 2], // down
[args.loc[0] + args.width, args.loc[1] - args.height * 2], // up
[args.loc[0] + 2*args.width, args.loc[1] + args.height * 2], // down right
[args.loc[0] + 2*args.width, args.loc[1] + args.height / 2], // forward
[args.loc[0] + 2*args.width, args.loc[1] - args.height * 2], // up right
].map((p: any) => <DAGEdge
p1={[args.loc[0] + args.width, args.loc[1] + args.height / 2]}
p2={p}
direction="1->2"
color="white"
// debug
/>)}
</SVGBoard>
-75
View File
@@ -1,75 +0,0 @@
import Color from "chroma-js";
import { PencilIcon } from "components/Icons"
import { useNodeStyles } from "./styles"
import { EdgeDirection, Node, Point } from "types/graphs";
import { DAGEdge } from "./DAGEdge";
export interface NodeProp extends Node {
height: number;
width: number;
onXClick?: () => void;
onOpenClick?: () => void;
debug?: boolean;
edge?: {
color: string;
loc: Point;
direction: EdgeDirection;
}
}
export const DAGNode = ({
loc: [x, y],
text,
height,
width,
onXClick = () => { },
onOpenClick = () => { },
color,
edge,
debug = false,
}: NodeProp) => {
const { classes, theme } = useNodeStyles({
color,
nodeHeight: height,
nodeWidth: width,
});
return <>
<foreignObject x={x} y={y} width={width} height={height}>
<div className={classes.root}>
<div className={classes.inner}>
<div className={classes.leftEdge} onClick={onXClick}>
<button className={classes.buttonDelete}>X</button>
</div>
<div className={classes.textWrap}>
<span className={classes.text} title={text}>
{text}
</span>
</div>
<div className={classes.rightEdge} onClick={onOpenClick}>
<button className={classes.buttonEdit}>
<PencilIcon size={1.1} color={Color(theme.primary).set('rgb.g', 200).hex()} />
</button>
</div>
</div>
</div>
</foreignObject>
{
edge && (edge.direction === '1->2' ?
<DAGEdge
p1={[x + width, y + height / 2]}
p2={edge.loc}
direction={edge.direction}
color={edge.color}
debug={debug}
/> :
<DAGEdge
p1={[x, y + height / 2]}
p2={edge.loc}
direction={edge.direction}
color={edge.color}
debug={debug}
/>)
}
</>
}
+8 -9
View File
@@ -1,19 +1,18 @@
import { DAGBoardElmDims } from 'components/DAGSvgs/DAGBoard';
export const NODE_WIDTH = 150 as const;
export const NODE_HEIGHT = 60 as const;
export const ADD_HEIGHT = 10 as const;
export const ADD_WIDTH = 10 as const;
export const CIRCLE_SIZE = 30 as const;
export const DISTANCE_FACTOR = 1.5 as const;
export const PADDING = 50 as const;
export const DEFAULT_DIMS: DAGBoardElmDims = {
export const DEFAULT_DIMS = {
nodeHeight: NODE_HEIGHT,
nodeWidth: NODE_WIDTH,
addHeight: ADD_HEIGHT,
addWidth: ADD_WIDTH,
circleSize: CIRCLE_SIZE,
distanceFactor: DISTANCE_FACTOR,
};
circleSize: CIRCLE_SIZE,
padding: {
x: PADDING,
y: PADDING,
},
}
+2 -2
View File
@@ -27,8 +27,8 @@ const commonInputStyle = (theme: AppTheme) => ({
export const useButtonStyles = createAppUseStyles<{}>(theme => ({
input: {
...commonInputStyle(theme).input,
paddingTop: '1em',
paddingBottom: '1em',
paddingTop: '0.5em',
paddingBottom: '0.5em',
cursor: 'pointer',
},
}));
@@ -50,14 +50,7 @@ export const InAModal: ComponentStory<typeof MultiNodeEditor> = props => {
{...props}
sequence={state}
onClose={() => setOpen(!open)}
onAdd={(n, slide) => { setState([...state, n]); slide(state.length) }}
onRemove={(n, slide) => {
setState([
...state.slice(0, n),
...state.slice(n + 1)
]);
slide(state.length - 2)
}}
onSave={setState}
/>
</Modal>
</div>
@@ -36,43 +36,84 @@ const makeDefault = (nodeType: keyof AutomationNodeMapping): AutomationNode => {
}
}
export interface Props {
export interface MultiNodeEditorProps {
sequence: AutomationNode[];
allowedTypes?: Array<keyof AutomationNodeMapping>;
onAdd?: (n: AutomationNode, slide: (i: number) => void) => void;
onClose?: () => void;
onSave?: (i: number, n: AutomationNode) => void;
onRemove?: (i: number, slide: (i: number) => void) => void;
onSave?: (n: AutomationNode[]) => void;
}
export const MultiNodeEditor: FC<Props> = ({
sequence,
export const MultiNodeEditor: FC<MultiNodeEditorProps> = ({
sequence: initialState,
allowedTypes = ['action', 'condition'],
onClose,
onAdd = () => { },
onClose = () => { },
onSave = () => { },
onRemove = () => { },
}) => {
const [slide, setSlide] = useState(0);
// state
const [{ slide, state, isNodeModified, isModified, isReady }, setState] = useState({
slide: 0,
state: initialState,
isModified: false,
isNodeModified: false,
isReady: true,
})
// alias
const areYouSureItsModified = () => isNodeModified ?
window.confirm("You've made changes, by pressing this you will lose them!") :
true
const areYouSureItsNotReady = () => !isReady ?
window.confirm("The node is not ready, are you sure you want to move?") :
true
const onAdd = () => setState({
slide: state.length,
state: [...state, makeDefault(allowedTypes[0])],
isNodeModified: false,
isReady,
isModified: true,
});
const onRemove = () => setState({
slide: slide > 0 ? slide - 1 : 0,
state: [...state.slice(0, slide), ...state.slice(slide + 1)],
isNodeModified: false,
isReady,
isModified: true,
});
const onNodeSave = (n: AutomationNode) => setState({
slide,
state: [...state.slice(0, slide), n, ...state.slice(slide + 1)],
isNodeModified: false,
isReady,
isModified: true,
});
const onSaveAll = () => isNodeModified ?
window.alert("Please save the node data first!") :
onSave(state)
const onNextOrAdd = () => {
if (!areYouSureItsModified()) {
return
}
if (!areYouSureItsNotReady()) {
return
}
if (slide >= state.length - 1) {
onAdd()
} else {
setState({ slide: slide + 1, state, isNodeModified, isReady, isModified, })
}
}
const onBack = () => areYouSureItsModified() &&
areYouSureItsNotReady() &&
setState({ slide: slide - 1, state, isNodeModified, isReady, isModified, })
// components
const nextOrAddBtn = <Button
onClick={() => {
if (slide >= sequence.length - 1) {
onAdd(makeDefault(allowedTypes[0]), setSlide)
} else {
setSlide(slide + 1)
}
}}
onClick={onNextOrAdd}
>
{(slide < sequence.length - 1) ? ">>" : "+"}
{(slide < state.length - 1) ? ">>" : "+"}
</Button>;
// branch
if (sequence.length === 0) {
return <div style={{
display: 'flex',
flexDirection: 'column',
flex: 1,
justifyContent: 'center',
if (state.length === 0) {
return <div className='column center' style={{
minWidth: '20vw',
}}>
<div style={{
flex: 1,
@@ -82,20 +123,22 @@ export const MultiNodeEditor: FC<Props> = ({
}}>
{nextOrAddBtn}
</div>
<Button onClick={onClose}>Close</Button>
<div className='column center' style={{ marginTop: '1em' }}>
<Button onClick={() => areYouSureItsModified() && onClose()}>Close</Button>
</div>
</div>
}
return <>
<div style={{
display: 'flex',
flexDirection: 'row',
justifyContent: 'center',
justifyContent: 'space-evenly',
alignItems: 'center',
minWidth: '20vw',
}}>
<Button onClick={() => setSlide(slide - 1)} disabled={slide === 0}>{"<<"}</Button>
<span>{slide + 1}/{sequence.length}</span>
<Button onClick={onBack} disabled={slide === 0}>{"<<"}</Button>
<Button
onClick={() => onRemove(slide, setSlide)}
onClick={onRemove}
>
Delete
</Button>
@@ -103,10 +146,22 @@ export const MultiNodeEditor: FC<Props> = ({
</div>
<NodeEditor
key={slide}
node={sequence[slide]}
node={state[slide]}
allowedTypes={allowedTypes}
onClose={onClose}
onSave={n => onSave(slide, n)}
/>
onSave={onNodeSave}
onFlags={
(ir, inm) => ((inm !== isNodeModified) || (ir !== isReady)) &&
setState({ slide, state, isNodeModified: inm, isReady: ir, isModified })
}
>
<Button onClick={onSaveAll} style={{
borderColor: isModified ? "var(--change)" : undefined,
color: isModified ? "var(--change)" : undefined,
}}>Save All</Button>
</NodeEditor>
<div className='column center'>
<span>{slide + 1}/{state.length}</span>
</div>
</>
}
@@ -1,22 +1,32 @@
import { useState } from 'react';
import { useEffect, useState } from 'react';
import { AutomationNode, AutomationNodeTypes } from 'types/automations';
import { AutomationNodeSubtype } from 'types/automations';
import { getOptionManager } from './getOptionManager';
export const useEditorNodeState = (node: AutomationNode) => {
const [state, setState] = useState(node);
const [{ node: state, isModified }, setAllState] = useState({
node,
isModified: false,
});
useEffect(() => {
setAllState({ node, isModified: false })
}, [node])
const setState = (node: AutomationNode) => setAllState(({ node, isModified: true }))
const nodeType: AutomationNodeTypes = state.$smType ?? 'trigger';
const subType: AutomationNodeSubtype =
state.$smType === 'action' ? state.action :
state.$smType === 'condition' ? state.condition :
state.platform;
const subTypes = getSubTypeList(nodeType)
const subTypes = getSubTypeList(nodeType)
const optionManager = getOptionManager(nodeType, subType as any);
return {
nodeType,
subType,
subTypes,
get isModified() {
return isModified
},
get data() {
return state
},
@@ -101,7 +111,7 @@ const getSubTypeList = <T extends AutomationNodeTypes>(nodeType: T): AutomationN
'time',
'trigger',
'zone',
]as any
] as any
case 'trigger':
return [
'event',
@@ -116,7 +126,7 @@ const getSubTypeList = <T extends AutomationNodeTypes>(nodeType: T): AutomationN
'webhook',
'zone',
'device',
]as any
] as any
default:
return [];
}
+30 -18
View File
@@ -1,16 +1,27 @@
.node-editor--root {
display : flex;
flex-direction : column;
display: flex;
flex-direction: column;
justify-content: center;
align-items : center;
height : 100%;
align-items: center;
height: 100%;
padding: 1em;
margin-top: 0.5em;
}
.node-editor--root.modded {
border: 1px solid var(--change);
border-radius: 5px;
}
.node-editor--root.modded * {
border-color: var(--change);
}
.node-editor--body-title {
display : flex;
flex-direction : row;
display: flex;
flex-direction: row;
justify-content: space-between;
margin-bottom : 6px;
margin-bottom: 6px;
}
.node-editor--body-title>* {
@@ -18,21 +29,22 @@
}
.node-editor--body {
overflow : overlay;
padding-left : 1%;
overflow: overlay;
padding-left: 1%;
padding-right: 1%;
min-width : 100%;
min-width: 100%;
min-height: fit-content;
}
.node-editor--footer {
bottom : 0;
left : 0;
display : flex;
flex-direction : row;
bottom: 0;
left: 0;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items : center;
width : 100%;
min-height : 50px;
}
align-items: center;
width: 100%;
min-height: 50px;
min-width: 25vw;
}
+16 -3
View File
@@ -11,6 +11,7 @@ export interface Props {
allowedTypes?: Array<keyof AutomationNodeMapping>;
onClose?: () => void;
onSave?: (n: AutomationNode) => void;
onFlags?: (isReady: boolean, isModified: boolean) => void;
saveBtnCreateText?: boolean;
}
@@ -19,11 +20,22 @@ export const NodeEditor: FC<Props> = ({
allowedTypes = ["action", "condition", "trigger"],
onClose = () => { },
onSave = () => { },
onFlags = () => { },
saveBtnCreateText = false,
children
}) => {
// state
const state = useEditorNodeState(node);
return <div className="node-editor--root">
// state
const isModified = state.isModified;
const isReady = state.isReady();
// events
onFlags(isReady, isModified);
// render
return <div className={["node-editor--root", isModified ? "modded" : ""].join(" ")}>
<div className="node-editor--body">
<div className="node-editor--body-title">
{allowedTypes.length > 1 ? <InputList
@@ -44,8 +56,9 @@ export const NodeEditor: FC<Props> = ({
<div className="node-editor--footer">
<Button onClick={onClose}>Close</Button>
<Button onClick={() => {
state.isReady() && onSave(state.data)
}} disabled={!state.isReady()}>{saveBtnCreateText ? "Create" : "Save"}</Button>
isReady && onSave(state.data)
}} disabled={!isReady}>{saveBtnCreateText ? "Create" : "Save"}</Button>
{children}
</div>
</div>
}
@@ -1,328 +0,0 @@
import React from "react";
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { SequenceNodes } from './index';
import { NODE_HEIGHT, NODE_WIDTH, DISTANCE_FACTOR, ADD_HEIGHT, ADD_WIDTH, CIRCLE_SIZE } from '../DAGSvgs/constants';
import { useState } from 'react';
import { DAGElement } from "components/DAGSvgs/DAGBoard";
export default {
title: 'DAGSvgs/SequenceNodes',
component: SequenceNodes,
parameters: { actions: { argTypesRegex: '^on.*' } },
args: {
zoomLevel: 100,
startPoint: [0.5, 0.5],
dims: {
nodeHeight: NODE_HEIGHT,
nodeWidth: NODE_WIDTH,
addHeight: ADD_HEIGHT,
addWidth: ADD_WIDTH,
circleSize: CIRCLE_SIZE,
distanceFactor: DISTANCE_FACTOR,
}
}
} as ComponentMeta<typeof SequenceNodes>
const Template: ComponentStory<typeof SequenceNodes> = args => {
const [state, setState] = useState(args.sequence)
return <SequenceNodes
{...args}
sequence={state}
onChange={setState}
/>
}
export const Simple = Template.bind({})
Simple.args = {
...Simple.args,
sequence: [
{
$smType: "condition",
condition: 'and',
condition_data: {
conditions: [
{
$smType: 'condition',
condition: 'numeric_state',
condition_data: {
entity_id: 'sensor.temperature_kitchen',
below: '15',
}
},
{
$smType: "condition",
condition: 'template',
condition_data: {
value_template: 'states(switch.kitchen_light) == "on"'
}
}
]
}
},
{
$smType: "action",
action: "service",
action_data: {
alias: "Start Music In Kitchen",
service: 'media_player.play_media',
target: {
entity_id: "media_player.kitchen_dot"
},
data: {
media_content_id: "Good Morning",
media_content_type: "SPOTIFY",
}
}
}
]
}
export const EmptyStart = Template.bind({})
EmptyStart.args = {
...EmptyStart.args,
sequence: [
]
}
export const AdditionalElemets = Template.bind({})
AdditionalElemets.args = {
...Simple.args,
additionalElements: function* (): Generator<DAGElement> {
yield {
type: 'circle',
loc: [1, 0],
icon: "blank"
}
yield {
type: 'edge',
p1: [0, 0],
p2: [1, 0],
direction: '1->2'
}
},
}
export const Multinode = Template.bind({})
Multinode.args = {
...Multinode.args,
sequence: [
{
$smType: "condition",
condition: 'and',
condition_data: {
conditions: [
{
$smType: 'condition',
condition: 'numeric_state',
condition_data: {
entity_id: 'sensor.temperature_kitchen',
below: '15',
}
},
{
$smType: "condition",
condition: 'template',
condition_data: {
value_template: 'states(switch.kitchen_light) == "on"'
}
}
]
}
},
{
$smType: "action",
action: "choose",
action_data: {
choose: [
{
conditions: [],
sequence: []
},
{
conditions: [
{
$smType: "condition",
condition: 'time',
condition_data: {
after: {
hours: 16,
minutes: 30
}
}
}
],
sequence: [
{
$smType: 'action',
action: 'event',
action_data: {
event: "superImportant_time",
event_data: {
time: '4:30PM'
}
}
}
]
},
{
conditions: [
{
$smType: "condition",
condition: 'time',
condition_data: {
after: {
hours: 18,
minutes: 45
}
}
}
],
sequence: [
{
$smType: 'action',
action: 'event',
action_data: {
event: "superImportant_time",
event_data: {
time: '6:45PM'
}
}
}
]
}
],
default: [],
}
},
{
$smType: 'action',
action: "service",
action_data: {
service: "light.turn_on",
data: {
entity_id: "light.kitchen"
}
}
} as any
]
}
export const DeepNested = Template.bind({})
DeepNested.args = {
...DeepNested.args,
sequence: [
{
"$smType": "action",
"action": "choose",
"action_data": {
"choose": [{
"sequence": [{
"$smType": "action",
"action": "choose",
"action_data": {
"choose": [],
"default": []
}
}],
"conditions": [],
}],
"default": [
{
"$smType": "action",
"action": "choose",
"action_data": {
"choose": [
{
"sequence": [{
"$smType": "action",
"action": "choose",
"action_data": {
"choose": [],
"default": []
}
}],
"conditions": [],
}
],
"default": [
]
}
},
{
"$smType": "action",
"action": "choose",
"action_data": {
"choose": [],
"default": []
}
}
]
}
},
{
"$smType": "action",
"action": "choose",
"action_data": {
"choose": [],
"default": []
}
}
]
}
export const SubsequentIssue = Template.bind({})
SubsequentIssue.args = {
...SubsequentIssue.args,
sequence: [{ "$smType": "condition", "condition": "and", "condition_data": { "conditions": [{ "$smType": "condition", "condition": "numeric_state", "condition_data": { "entity_id": "sensor.temperature_kitchen", "below": "15" } }, { "$smType": "condition", "condition": "template", "condition_data": { "value_template": "states(switch.kitchen_light) == \"on\"" } }] } }, { "$smType": "action", "action": "service", "action_data": { "alias": "Start Music In Kitchen", "service": "media_player.play_media", "target": { "entity_id": "media_player.kitchen_dot" }, "data": { "media_content_id": "Good Morning", "media_content_type": "SPOTIFY" } } }, { "$smType": "action", "action": "choose", "action_data": { "choose": [], "default": [{ "$smType": "action", "action": "choose", "action_data": { "choose": [], "default": [] } }] } }, { "$smType": "action", "action": "choose", "action_data": { "choose": [], "default": [] } }, { "$smType": "action", "action": "choose", "action_data": { "choose": [], "default": [] } }]
}
export const ChooseNestingIssue = Template.bind({})
ChooseNestingIssue.args = {
...ChooseNestingIssue.args,
sequence: [
{
"$smType": "condition",
"condition": "and",
"condition_data": {
"conditions": [
{
"$smType": "condition",
"condition": "numeric_state",
"condition_data": {
"entity_id": "sensor.temperature_kitchen",
"below": "15"
}
},
{
"$smType": "condition",
"condition": "template",
"condition_data": {
"value_template": "states(switch.kitchen_light) == \"on\""
}
}
]
}
},
{
"$smType": "action",
"action": "choose",
"action_data": {
"choose": [],
"default": [
{
"$smType": "action",
"action": "choose",
"action_data": {
"choose": [],
"default": []
}
}
]
}
}
]
}
@@ -1,82 +0,0 @@
import { DAGBoard } from "components/DAGSvgs/DAGBoard";
import { FC, useState } from "react";
import { useTheme } from "styles/theme";
import { SequenceNodeProps, ModalState } from './types';
import Color from 'chroma-js';
import { computeNodesEdgesPos } from './positions';
import { Modal } from 'components/Modal';
import { NodeEditor } from 'components/NodeEditor';
import { MultiNodeEditor } from "components/MultiNodeEditors";
import { chain } from "utils/iter";
export const SequenceNodes: FC<SequenceNodeProps & { zoomLevel: number }> = (props) => {
// state
const theme = useTheme();
const [modalState, setModalState] = useState<ModalState | null>(null);
// modal
let modalBody = <></>
if (modalState) {
if (modalState.single) {
modalBody = <NodeEditor
node={modalState.node}
onClose={() => setModalState(null)}
onSave={n => { modalState.update(n as any); setModalState(null) }}
allowedTypes={modalState.onlyConditions ? ['condition'] : ['action', 'condition']}
saveBtnCreateText={modalState.saveBtnCreateText}
/>
} else {
modalBody = <MultiNodeEditor
sequence={modalState.node}
onClose={() => setModalState(null)}
onSave={(i, n) => {
modalState.update([
...modalState.node.slice(0, i),
n as any,
...modalState.node.slice(i + 1),
]); setModalState(null)
}}
onAdd={(n, slide) => {
modalState.update([...modalState.node, n as any]);
slide(modalState.node.length)
}}
onRemove={(i, slide) => {
modalState.update([
...modalState.node.slice(0, i),
...modalState.node.slice(i + 1),
]);
slide(modalState.node.length - 2);
}}
allowedTypes={modalState.onlyConditions ? ['condition'] : ['action', 'condition']}
/>
}
}
// compute elemets
let elmIter = computeNodesEdgesPos(
props.startPoint,
props.sequence,
props.onChange,
s => setModalState(s)
);
if (props.additionalElements) {
elmIter = chain([elmIter, props.additionalElements()]);
}
// render
return <>
<DAGBoard
zoomLevel={props.zoomLevel}
elements={elmIter}
settings={{
...props.dims,
edgeNextColor: theme.secondaryAccent,
edgeChildColor: Color(theme.secondaryAccent).set('rgb.b', 200).hex(),
}}
children={props.children}
/>
<Modal open={!!modalState}>
{modalBody}
</Modal>
</>
}
@@ -1,240 +0,0 @@
import { DAGElement } from "components/DAGSvgs/DAGBoard";
import { AutomationSequenceNode } from "types/automations";
import { Point } from "types/graphs";
import { makeUpdater, Updater } from './updater';
import { ChooseAction } from 'types/automations/actions';
import { AutomationCondition } from "types/automations/conditions";
import { UpdateModalState } from "./types";
import { offsetPoint, makeOffsetMaintainer} from "utils/graph";
function* dealWithNested(
nodeLoc: Point,
innerStartLoc: Point,
updater: Updater,
sequence: AutomationSequenceNode[],
openModal: UpdateModalState,
onEdit?: () => void,
onRemove?: () => void,
): Generator<DAGElement> {
const np = offsetPoint(innerStartLoc, [0.5, 0]);
yield {
type: 'edge',
p1: nodeLoc,
p2: innerStartLoc,
direction: '1->2',
}
if (onEdit) {
yield {
type: 'circle',
loc: innerStartLoc,
icon: 'edit',
onEdit,
onRemove,
}
} else {
yield {
type: 'circle',
loc: innerStartLoc,
icon: 'blank',
onRemove,
}
}
yield {
type: 'edge',
p1: innerStartLoc,
p2: np,
direction: '1->2',
onAdd: sequence.length === 0 ? updater.addNode : undefined,
fromCircle: true,
}
for (let childNode of computeNodesEdgesPos(
np,
sequence,
updater.onChange,
openModal,
)) {
yield childNode
}
}
function* dealWithChoose(
node: ChooseAction,
nodeLoc: Point,
makeUpdater: (j: number | null) => Updater,
updateData: (data: ChooseAction['action_data']) => void,
openModal: UpdateModalState,
offset: ReturnType<typeof makeOffsetMaintainer>,
): Generator<DAGElement> {
offset.resetY()
// conditions
for (let j = 0; j < node.action_data.choose.length; j++) {
const innerStartLoc = offsetPoint(nodeLoc, [1, j + 1 + offset.y]);
const updater = makeUpdater(j);
for (let elm of dealWithNested(
nodeLoc,
innerStartLoc ,
updater,
node.action_data.choose[j].sequence,
openModal,
onModalOpenForConditions(
openModal, j,
node.action_data,
updateData,
),
createOnRemoveForChooseNode(node.action_data, updateData, j)
)) {
yield elm
if (elm.type === 'node') {
offset.update(elm.loc, innerStartLoc)
}
if (elm.type === 'circle') {
offset.update(offsetPoint(elm.loc, [0, -1]), innerStartLoc)
}
}
}
// default
const innerStartLoc = offsetPoint(
nodeLoc,
[1, node.action_data.choose.length + 2 + offset.y],
);
for (let elm of dealWithNested(
nodeLoc,
innerStartLoc,
makeUpdater(null),
node.action_data.default,
openModal
)) {
yield elm
if (elm.type === 'node') {
offset.update(elm.loc, innerStartLoc)
}
}
// add new conditions
const newCondLoc = offsetPoint(
nodeLoc,
[1, node.action_data.choose.length + 2.5 + offset.y],
);
yield {
type: 'circle',
loc: newCondLoc,
icon: 'add',
onAdd: () => updateData({
...node.action_data,
choose: [
...node.action_data.choose,
{
conditions: [],
sequence: [],
}
]
}),
}
}
export function* computeNodesEdgesPos(
startPoint: Point,
sequence: AutomationSequenceNode[],
onChange: (s: AutomationSequenceNode[]) => void,
openModal: UpdateModalState,
): Generator<DAGElement> {
const rootUpdater = makeUpdater(sequence, onChange, openModal);
const offset = makeOffsetMaintainer(startPoint);
if (sequence.length === 0) {
yield {
type: "circle",
icon: 'add',
loc: offsetPoint(startPoint, [offset.x, 0]),
onAdd: rootUpdater.addNode,
}
return
}
let lastNodeLoc: Point | null = null;
for (let i = 0; i < sequence.length; i++) {
offset.setI(i)
const node = sequence[i];
const nodeLoc = offsetPoint(startPoint, [i + offset.x, 0]);
yield {
type: 'node',
loc: nodeLoc,
node,
onOpen: onModalOpenForNode(openModal, i, node, rootUpdater),
onRemove: () => rootUpdater.removeNode(i),
onAdd: i === sequence.length - 1 ? rootUpdater.addNode : undefined,
}
if (lastNodeLoc) {
yield {
type: 'edge',
p1: lastNodeLoc,
p2: nodeLoc,
direction: '1->2',
}
}
lastNodeLoc = [...nodeLoc];
if (
(node.$smType === 'action') && (node.action === 'choose')
) {
yield* dealWithChoose(
node,
nodeLoc,
j => rootUpdater.makeChildUpdaterForChooseAction(i, j),
actionData => rootUpdater.updateChooseActionData(i, actionData),
openModal,
offset,
)
}
}
}
export const onModalOpenForNode = (
openModal: UpdateModalState,
i: number,
node: AutomationSequenceNode,
rootUpdater: Updater,
) => () => openModal({
single: true,
node,
onlyConditions: false,
update: n => rootUpdater.updateNode(i, n),
})
export const onModalOpenForConditions = (
openModal: UpdateModalState,
j: number,
data: ChooseAction['action_data'],
updateData: (data: ChooseAction['action_data']) => void,
) => () => openModal({
single: false,
node: data.choose[j].conditions,
onlyConditions: true,
update: conditions => updateData({
...data,
choose: [
...data.choose.slice(0, j),
{
sequence: data.choose[j].sequence,
conditions: conditions as AutomationCondition[],
},
...data.choose.slice(j+1),
]
}),
})
const createOnRemoveForChooseNode = (
data: ChooseAction['action_data'],
updateData: (data: ChooseAction['action_data']) => void,
j: number
) => () => updateData({
...data,
choose: [
...data.choose.slice(0, j),
...data.choose.slice(j+1),
]
})
@@ -1,28 +0,0 @@
import { DAGBoardElmDims, DAGElement } from "components/DAGSvgs/DAGBoard";
import { AutomationSequenceNode } from "types/automations";
import { Point } from "types/graphs";
export type UpdateModalState = (
s: ModalState
) => void;
export interface SequenceNodeProps {
startPoint: Point;
dims: DAGBoardElmDims;
sequence: AutomationSequenceNode[],
onChange: (s: AutomationSequenceNode[]) => void;
additionalElements?: () => Generator<DAGElement>;
}
export type ModalState = {
single: true,
node: AutomationSequenceNode
update: (n: AutomationSequenceNode) => void;
saveBtnCreateText?: boolean;
onlyConditions: boolean;
} | {
single: false,
node: AutomationSequenceNode[]
update: (n: AutomationSequenceNode[]) => void;
onlyConditions: boolean;
}
+16
View File
@@ -4,6 +4,7 @@
--primary-accent: #bbbbbb;
--secondary-accent: #929191;
--error: #c55;
--change: #0f9;
touch-action: pan-x pan-y;
height: 100%;
}
@@ -45,4 +46,19 @@ body,
* {
transition: all 200ms ease-out;
}
.column {
display: flex;
flex-direction: column;
}
.center {
justify-content: center;
align-items: center;
}
.row {
display: flex;
flex-direction: row;
}
+2 -1
View File
@@ -1,9 +1,10 @@
export type Point = [number, number];
export type BBox = [Point, Point];
export type NodeColor = 'red' | 'blue' | 'green';
export interface Node {
loc: Point;
text: string;
color: 'red' | 'blue' | 'green';
color: NodeColor;
}
export type EdgeDirection = '1->2' | '1<->2' | '1<-2';
export interface BoundedObj<J> {
+40
View File
@@ -0,0 +1,40 @@
import { AutomationData, AutomationSequenceNode } from "types/automations";
import { AutomationTrigger } from '../types/automations/triggers';
export type AumationStateEditor = ReturnType<typeof makeAumationStateEditor>;
export type AutomationStateTriggerEditor = AumationStateEditor['triggers'];
export const makeAumationStateEditor = (
automation: AutomationData,
onUpdate: (a: AutomationData) => void,
) => ({
onUpdate,
triggers: {
update: (i: number, t: AutomationTrigger) => onUpdate({
...automation,
trigger: automation.trigger
.slice(0, i)
.concat([t])
.concat(
automation.trigger.slice(i + 1)
)
}),
delete: (i: number) => onUpdate({
...automation,
trigger: automation.trigger
.slice(0, i)
.concat(
automation.trigger.slice(i + 1)
)
}),
add: (t: AutomationTrigger) => onUpdate({
...automation,
trigger: automation.trigger
.concat([t])
}),
},
updateSequence: (s: AutomationSequenceNode[]) => onUpdate({
...automation,
sequence: s,
})
})
+100 -29
View File
@@ -2675,7 +2675,7 @@
dependencies:
regenerator-runtime "^0.13.4"
"@babel/runtime@^7.16.3":
"@babel/runtime@^7.16.3", "@babel/runtime@^7.17.8":
version "7.17.9"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.17.9.tgz#d19fbf802d01a8cb6cf053a64e472d42c434ba72"
integrity sha512-lSiBBvodq29uShpWGNbgFdKYNiFDo5/HIYsaCEY9ff4sb10x9jizo2+pRrSyF4jKZCXqgzuqBOQKbUm90gQwJg==
@@ -6751,6 +6751,11 @@ class-utils@^0.3.5:
isobject "^3.0.0"
static-extend "^0.1.1"
classcat@^5.0.3:
version "5.0.3"
resolved "https://registry.yarnpkg.com/classcat/-/classcat-5.0.3.tgz#38eaa0ec6eb1b10faf101bbcef2afb319c23c17b"
integrity sha512-6dK2ke4VEJZOFx2ZfdDAl5OhEL8lvkl6EHF92IfRePfHxQTqir5NlcNVUv+2idjDqCX2NDc8m8YSAI5NI975ZQ==
clean-css@^4.2.3:
version "4.2.3"
resolved "https://registry.npmjs.org/clean-css/-/clean-css-4.2.3.tgz"
@@ -7564,6 +7569,68 @@ cyclist@^1.0.1:
resolved "https://registry.npmjs.org/cyclist/-/cyclist-1.0.1.tgz"
integrity sha1-WW6WmP0MgOEgOMK4LW6xs1tiJNk=
"d3-color@1 - 3":
version "3.1.0"
resolved "https://registry.yarnpkg.com/d3-color/-/d3-color-3.1.0.tgz#395b2833dfac71507f12ac2f7af23bf819de24e2"
integrity sha512-zg/chbXyeBtMQ1LbD/WSoW2DpC3I0mpmPdW+ynRTj/x2DAWYrIY7qeZIHidozwV24m4iavr15lNwIwLxRmOxhA==
"d3-dispatch@1 - 3":
version "3.0.1"
resolved "https://registry.yarnpkg.com/d3-dispatch/-/d3-dispatch-3.0.1.tgz#5fc75284e9c2375c36c839411a0cf550cbfc4d5e"
integrity sha512-rzUyPU/S7rwUflMyLc1ETDeBj0NRuHKKAcvukozwhshr6g6c5d8zh4c2gQjY2bZ0dXeGLWc1PF174P2tVvKhfg==
"d3-drag@2 - 3":
version "3.0.0"
resolved "https://registry.yarnpkg.com/d3-drag/-/d3-drag-3.0.0.tgz#994aae9cd23c719f53b5e10e3a0a6108c69607ba"
integrity sha512-pWbUJLdETVA8lQNJecMxoXfH6x+mO2UQo8rSmZ+QqxcbyA3hfeprFgIT//HW2nlHChWeIIMwS2Fq+gEARkhTkg==
dependencies:
d3-dispatch "1 - 3"
d3-selection "3"
"d3-ease@1 - 3":
version "3.0.1"
resolved "https://registry.yarnpkg.com/d3-ease/-/d3-ease-3.0.1.tgz#9658ac38a2140d59d346160f1f6c30fda0bd12f4"
integrity sha512-wR/XK3D3XcLIZwpbvQwQ5fK+8Ykds1ip7A2Txe0yxncXSdq1L9skcG7blcedkOX+ZcgxGAmLX1FrRGbADwzi0w==
"d3-interpolate@1 - 3":
version "3.0.1"
resolved "https://registry.yarnpkg.com/d3-interpolate/-/d3-interpolate-3.0.1.tgz#3c47aa5b32c5b3dfb56ef3fd4342078a632b400d"
integrity sha512-3bYs1rOD33uo8aqJfKP3JWPAibgw8Zm2+L9vBKEHJ2Rg+viTR7o5Mmv5mZcieN+FRYaAOWX5SJATX6k1PWz72g==
dependencies:
d3-color "1 - 3"
"d3-selection@2 - 3", d3-selection@3, d3-selection@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/d3-selection/-/d3-selection-3.0.0.tgz#c25338207efa72cc5b9bd1458a1a41901f1e1b31"
integrity sha512-fmTRWbNMmsmWq6xJV8D19U/gw/bwrHfNXxrIN+HfZgnzqTHp9jOmKMhsTUjXOJnZOdZY9Q28y4yebKzqDKlxlQ==
"d3-timer@1 - 3":
version "3.0.1"
resolved "https://registry.yarnpkg.com/d3-timer/-/d3-timer-3.0.1.tgz#6284d2a2708285b1abb7e201eda4380af35e63b0"
integrity sha512-ndfJ/JxxMd3nw31uyKoY2naivF+r29V+Lc0svZxe1JvvIRmi8hUsrMvdOwgS1o6uBHmiz91geQ0ylPP0aj1VUA==
"d3-transition@2 - 3":
version "3.0.1"
resolved "https://registry.yarnpkg.com/d3-transition/-/d3-transition-3.0.1.tgz#6869fdde1448868077fdd5989200cb61b2a1645f"
integrity sha512-ApKvfjsSR6tg06xrL434C0WydLr7JewBB3V+/39RMHsaXTOG0zmt/OAXeng5M5LBm0ojmxJrpomQVZ1aPvBL4w==
dependencies:
d3-color "1 - 3"
d3-dispatch "1 - 3"
d3-ease "1 - 3"
d3-interpolate "1 - 3"
d3-timer "1 - 3"
d3-zoom@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/d3-zoom/-/d3-zoom-3.0.0.tgz#d13f4165c73217ffeaa54295cd6969b3e7aee8f3"
integrity sha512-b8AmV3kfQaqWAuacbPuNbL6vahnOJflOhexLzMMNLga62+/nh0JzvJ0aO/5a5MVgUFGS7Hu1P9P03o3fJkDCyw==
dependencies:
d3-dispatch "1 - 3"
d3-drag "2 - 3"
d3-interpolate "1 - 3"
d3-selection "2 - 3"
d3-transition "2 - 3"
d@1, d@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/d/-/d-1.0.1.tgz#8698095372d58dbee346ffd0c7093f99f8f9eb5a"
@@ -11682,11 +11749,6 @@ lodash.merge@^4.6.2:
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==
lodash.sortby@^4.7.0:
version "4.7.0"
resolved "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz"
integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=
lodash.template@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.template/-/lodash.template-4.5.0.tgz#f976195cf3f347d0d5f52483569fe8031ccce8ab"
@@ -12269,9 +12331,9 @@ node-dir@^0.1.10:
minimatch "^3.0.2"
node-fetch@^2.6.1:
version "2.6.6"
resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.6.tgz"
integrity sha512-Z8/6vRlTUChSdIgMa51jxQ4lrw/Jy5SOW10ObaA47/RElsAN2c5Pn8bTgFGWn/ibwzXTE8qwr1Yzx28vsecXEA==
version "2.6.7"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
dependencies:
whatwg-url "^5.0.0"
@@ -14208,6 +14270,14 @@ react-draggable@^4.4.3:
clsx "^1.1.1"
prop-types "^15.6.0"
react-draggable@^4.4.4:
version "4.4.5"
resolved "https://registry.yarnpkg.com/react-draggable/-/react-draggable-4.4.5.tgz#9e37fe7ce1a4cf843030f521a0a4cc41886d7e7c"
integrity sha512-OMHzJdyJbYTZo4uQE393fHcqqPYsEtkjfMgvCHr6rejT+Ezn4OZbNyGH50vv+SunC1RMvwOTSWkEODQLzw1M9g==
dependencies:
clsx "^1.1.1"
prop-types "^15.8.1"
react-element-to-jsx-string@^14.3.4:
version "14.3.4"
resolved "https://registry.yarnpkg.com/react-element-to-jsx-string/-/react-element-to-jsx-string-14.3.4.tgz#709125bc72f06800b68f9f4db485f2c7d31218a8"
@@ -14227,6 +14297,18 @@ react-fast-compare@^3.0.1, react-fast-compare@^3.2.0:
resolved "https://registry.npmjs.org/react-fast-compare/-/react-fast-compare-3.2.0.tgz"
integrity sha512-rtGImPZ0YyLrscKI9xTpV8psd6I8VAtjKCzQDlzyDvqJA8XOW78TXYQwNRNd8g8JZnDu8q9Fu/1v4HPAVwVdHA==
react-flow-renderer@^10.1.2:
version "10.1.2"
resolved "https://registry.yarnpkg.com/react-flow-renderer/-/react-flow-renderer-10.1.2.tgz#633dabeb7f42308726056b45b93c9153964d58b9"
integrity sha512-gWDYmXSz0pT3fbUoDI4L49GSzKJNBhp0z1h1hN4L9YbzqBITowCQodxKHHkIQHW9V103xdd+SSZOmRvrA9uybg==
dependencies:
"@babel/runtime" "^7.17.8"
classcat "^5.0.3"
d3-selection "^3.0.0"
d3-zoom "^3.0.0"
react-draggable "^4.4.4"
zustand "^3.7.1"
react-helmet-async@^1.0.7:
version "1.1.2"
resolved "https://registry.npmjs.org/react-helmet-async/-/react-helmet-async-1.1.2.tgz"
@@ -16201,13 +16283,6 @@ tough-cookie@^4.0.0:
punycode "^2.1.1"
universalify "^0.1.2"
tr46@^2.0.2:
version "2.0.2"
resolved "https://registry.npmjs.org/tr46/-/tr46-2.0.2.tgz"
integrity sha512-3n1qG+/5kg+jrbTzwAykB5yRYtQCTqOGKq5U5PE3b0a1/mzo6snDhjGS0zJVJunO0NrT3Dg1MLy5TjWP/UJppg==
dependencies:
punycode "^2.1.1"
tr46@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-2.1.0.tgz#fa87aa81ca5d5941da8cbf1f9b749dc969a4e240"
@@ -16217,7 +16292,7 @@ tr46@^2.1.0:
tr46@~0.0.3:
version "0.0.3"
resolved "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=
trim-trailing-lines@^1.0.0:
@@ -16878,7 +16953,7 @@ web-vitals@^1.0.1:
webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=
webidl-conversions@^5.0.0:
@@ -17088,22 +17163,13 @@ whatwg-mimetype@^2.3.0:
whatwg-url@^5.0.0:
version "5.0.0"
resolved "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0=
dependencies:
tr46 "~0.0.3"
webidl-conversions "^3.0.0"
whatwg-url@^8.0.0:
version "8.4.0"
resolved "https://registry.npmjs.org/whatwg-url/-/whatwg-url-8.4.0.tgz"
integrity sha512-vwTUFf6V4zhcPkWp/4CQPr1TW9Ml6SF4lVyaIMBdJw5i6qUUJ1QWM4Z6YYVkfka0OUIzVo/0aNtGVGk256IKWw==
dependencies:
lodash.sortby "^4.7.0"
tr46 "^2.0.2"
webidl-conversions "^6.1.0"
whatwg-url@^8.5.0:
whatwg-url@^8.0.0, whatwg-url@^8.5.0:
version "8.7.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-8.7.0.tgz#656a78e510ff8f3937bc0bcbe9f5c0ac35941b77"
integrity sha512-gAojqb/m9Q8a5IV96E3fHJM70AzCkgt4uXYX2O7EmuyOnLrViCQlsEBmF9UQIu3/aeAIp2U17rtbpZWNntQqdg==
@@ -17514,6 +17580,11 @@ yocto-queue@^0.1.0:
resolved "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz"
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==
zustand@^3.7.1:
version "3.7.2"
resolved "https://registry.yarnpkg.com/zustand/-/zustand-3.7.2.tgz#7b44c4f4a5bfd7a8296a3957b13e1c346f42514d"
integrity sha512-PIJDIZKtokhof+9+60cpockVOq05sJzHCriyvaLBmEJixseQ1a5Kdov6fWZfWOu5SK9c+FhH1jU0tntLxRJYMA==
zwitch@^1.0.0:
version "1.0.5"
resolved "https://registry.npmjs.org/zwitch/-/zwitch-1.0.5.tgz"