Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c933589998 | ||
|
|
f66895d0eb | ||
|
|
08a50051d5 | ||
|
|
126f1df657 | ||
|
|
70eba32b34 | ||
|
|
53ec0d417b | ||
|
|
32fd7f2dff |
No files matched your search
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"js-yaml": "^4.1.0",
|
||||
"parcel": "^2.0.0",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
@@ -9,6 +10,7 @@
|
||||
"@parcel/transformer-sass": "^2.0.0",
|
||||
"@parcel/transformer-yaml": "^2.0.0",
|
||||
"@types/jest": "^27.0.2",
|
||||
"@types/js-yaml": "^4.0.4",
|
||||
"@types/node": "^16.11.6",
|
||||
"@types/react": "^17.0.33",
|
||||
"@types/react-dom": "^17.0.10",
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
import { useState } from "react";
|
||||
|
||||
|
||||
|
||||
export abstract class BaseStateManager<T> {
|
||||
abstract defaultState(): T ;
|
||||
abstract isReady(): boolean;
|
||||
abstract renderOptionList(): JSX.Element;
|
||||
|
||||
public state: T;
|
||||
public setState: (s:T) => void;
|
||||
|
||||
constructor(){
|
||||
[this.state, this.setState] = useState(this.defaultState());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { useState } from "react";
|
||||
|
||||
|
||||
|
||||
export abstract class BaseState<T> {
|
||||
abstract defaultState(): T ;
|
||||
abstract isReady(s: T): boolean;
|
||||
abstract renderOptionList(s: T): JSX.Element;
|
||||
|
||||
constructor(public setState: (s: T) => void) {}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import InputBoolean from "../../components/InputBoolean";
|
||||
import InputYaml from "../../components/InputYaml";
|
||||
import InputNumber from "../../components/InputNumber";
|
||||
import InputText from "../../components/InputText";
|
||||
import { BaseState } from "./BaseState";
|
||||
import { LogicCondition } from "../types/condition";
|
||||
import InputList from "../../components/InputList";
|
||||
|
||||
|
||||
export default class ConditionLogicState extends BaseState<LogicCondition> {
|
||||
defaultState = () => ({
|
||||
alias: "",
|
||||
condition: 'and',
|
||||
conditions: [],
|
||||
} as LogicCondition)
|
||||
isReady(state: LogicCondition): boolean {
|
||||
return state.alias !== '' &&
|
||||
(state?.conditions)?.length > 0
|
||||
}
|
||||
renderOptionList(state: LogicCondition): JSX.Element {
|
||||
return <div className="state-manager-options">
|
||||
<InputText
|
||||
label="Description"
|
||||
value={state.alias}
|
||||
onChange={alias => this.setState({...state, alias})}
|
||||
/>
|
||||
<InputList
|
||||
label="Condition"
|
||||
current={state.condition}
|
||||
options={['and', 'or', 'not']}
|
||||
onChange={(condition: any) => this.setState({...state, condition})}
|
||||
/>
|
||||
<InputYaml
|
||||
label="Sequence"
|
||||
value={state.conditions}
|
||||
onChange={conditions => this.setState({...state, conditions})}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import InputBoolean from "../../components/InputBoolean";
|
||||
import InputYaml from "../../components/InputYaml";
|
||||
import InputNumber from "../../components/InputNumber";
|
||||
import InputText from "../../components/InputText";
|
||||
import { BaseState } from "./BaseState";
|
||||
import { NumericCondition } from "../types/condition";
|
||||
import InputList from "../../components/InputList";
|
||||
|
||||
|
||||
export default class ConditionNumStateState extends BaseState<NumericCondition> {
|
||||
defaultState = () => ({
|
||||
alias: "",
|
||||
condition: 'numeric_state',
|
||||
entity_id: '',
|
||||
// above: '',
|
||||
// below: '',
|
||||
// attribute: '',
|
||||
value_template: '',
|
||||
} as NumericCondition)
|
||||
isReady(state: NumericCondition): boolean {
|
||||
return state.alias !== '' &&
|
||||
state.entity_id !== '' &&
|
||||
state.value_template !== '';
|
||||
}
|
||||
renderOptionList(state: NumericCondition): JSX.Element {
|
||||
return <div className="state-manager-options">
|
||||
<InputText
|
||||
label="Description"
|
||||
value={state.alias}
|
||||
onChange={alias => this.setState({...state, alias})}
|
||||
/>
|
||||
<InputText
|
||||
textBoxFor="entity_id"
|
||||
label="Entity ID"
|
||||
value={state.entity_id}
|
||||
onChange={entity_id => this.setState({...state, entity_id})}
|
||||
/>
|
||||
<InputText
|
||||
label="Template"
|
||||
value={state.value_template ?? ""}
|
||||
onChange={value_template => this.setState({...state, value_template})}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import InputText from "../../components/InputText";
|
||||
import { ServiceScript } from "../types/script";
|
||||
import { BaseState } from "./BaseState";
|
||||
|
||||
|
||||
export default class Generic extends BaseState<{alias: string}> {
|
||||
defaultState = () => ({
|
||||
alias: "Unknown",
|
||||
})
|
||||
isReady(state: ServiceScript): boolean {
|
||||
return true;
|
||||
}
|
||||
renderOptionList(state: ServiceScript): JSX.Element {
|
||||
return <div className="state-manager-options">
|
||||
<InputText label="Description"
|
||||
value={state.alias}
|
||||
onChange={alias => this.setState({...state, alias})}
|
||||
/>
|
||||
<br/>
|
||||
<b>THIS IS NOT SUPPORTED YET!</b>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import InputBoolean from "../../components/InputBoolean";
|
||||
import InputYaml from "../../components/InputYaml";
|
||||
import InputNumber from "../../components/InputNumber";
|
||||
import InputText from "../../components/InputText";
|
||||
import { ChooseScript } from "../types/script";
|
||||
import { BaseState } from "./BaseState";
|
||||
|
||||
|
||||
export default class ScriptChooseState extends BaseState<ChooseScript> {
|
||||
defaultState = () => ({
|
||||
alias: "Choose",
|
||||
default: [],
|
||||
choose: [],
|
||||
})
|
||||
isReady(state: ChooseScript): boolean {
|
||||
return state.alias !== ''
|
||||
}
|
||||
renderOptionList(state: ChooseScript): JSX.Element {
|
||||
return <div className="state-manager-options">
|
||||
<InputText
|
||||
label="Description"
|
||||
value={state.alias}
|
||||
onChange={alias => this.setState({...state, alias})}
|
||||
/>
|
||||
<InputYaml
|
||||
label="Choose Sequence"
|
||||
value={state.choose}
|
||||
onChange={choose => this.setState({...state, choose})}
|
||||
/>
|
||||
<InputYaml
|
||||
label="Default Sequence"
|
||||
value={state.default}
|
||||
onChange={d => this.setState({...state, default: d})}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import InputBoolean from "../../components/InputBoolean";
|
||||
import InputYaml from "../../components/InputYaml";
|
||||
import InputNumber from "../../components/InputNumber";
|
||||
import InputText from "../../components/InputText";
|
||||
import { DeviceScript } from "../types/script";
|
||||
import { BaseState } from "./BaseState";
|
||||
|
||||
|
||||
export default class ScriptDeviceState extends BaseState<DeviceScript> {
|
||||
defaultState = () => ({
|
||||
alias: "Device",
|
||||
type: "",
|
||||
entity_id: "",
|
||||
device_id: "",
|
||||
domain: "",
|
||||
})
|
||||
isReady(state: DeviceScript): boolean {
|
||||
return state.alias !== '' &&
|
||||
state.type !== "" &&
|
||||
state.entity_id !== "" &&
|
||||
state.device_id !== "" &&
|
||||
state.domain !== ""
|
||||
}
|
||||
renderOptionList(state: DeviceScript): JSX.Element {
|
||||
return <div className="state-manager-options">
|
||||
<InputText
|
||||
label="Description"
|
||||
value={state.alias}
|
||||
onChange={alias => this.setState({...state, alias})}
|
||||
/>
|
||||
<InputText
|
||||
textBoxFor="device_id"
|
||||
label="Device"
|
||||
value={state.device_id}
|
||||
onChange={device_id => this.setState({...state, device_id})}
|
||||
/>
|
||||
<InputText
|
||||
textBoxFor="type"
|
||||
label="Action"
|
||||
value={state.type}
|
||||
onChange={type => this.setState({...state, type})}
|
||||
/>
|
||||
<InputText
|
||||
textBoxFor="entity_id"
|
||||
label="Entity ID"
|
||||
value={state.entity_id}
|
||||
onChange={entity_id => this.setState({...state, entity_id, domain: entity_id.split('.')[0]})}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import InputBoolean from "../../components/InputBoolean";
|
||||
import InputYaml from "../../components/InputYaml";
|
||||
import InputNumber from "../../components/InputNumber";
|
||||
import InputText from "../../components/InputText";
|
||||
import { FireEventScript } from "../types/script";
|
||||
import { BaseState } from "./BaseState";
|
||||
|
||||
|
||||
export default class ScriptEventState extends BaseState<FireEventScript> {
|
||||
defaultState = () => ({
|
||||
alias: "Fire Event",
|
||||
event: "",
|
||||
event_data: {},
|
||||
})
|
||||
isReady(state: FireEventScript): boolean {
|
||||
return state.alias !== '' &&
|
||||
state.event !== ""
|
||||
}
|
||||
renderOptionList(state: FireEventScript): JSX.Element {
|
||||
return <div className="state-manager-options">
|
||||
<InputText
|
||||
label="Description"
|
||||
value={state.alias}
|
||||
onChange={alias => this.setState({...state, alias})}
|
||||
/>
|
||||
<InputText
|
||||
textBoxFor="event"
|
||||
label="Event"
|
||||
value={state.event}
|
||||
onChange={event => this.setState({...state, event})}
|
||||
/>
|
||||
<InputYaml
|
||||
label="Event Data"
|
||||
value={state.event_data}
|
||||
onChange={event_data => this.setState({...state, event_data})}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import InputNumber from "../../components/InputNumber";
|
||||
import InputText from "../../components/InputText";
|
||||
import InputYaml from "../../components/InputYaml";
|
||||
import { RepeatScript } from "../types/script";
|
||||
import { BaseState } from "./BaseState";
|
||||
|
||||
|
||||
export default class ScriptRepeatState extends BaseState<RepeatScript> {
|
||||
defaultState = () => ({
|
||||
alias: "Repeat",
|
||||
repeat: {
|
||||
count: 1,
|
||||
sequence: [],
|
||||
}
|
||||
})
|
||||
isReady(state: RepeatScript): boolean {
|
||||
return state.alias !== '' &&
|
||||
state?.repeat?.sequence.length > 0
|
||||
}
|
||||
renderOptionList(state: RepeatScript): JSX.Element {
|
||||
return <div className="state-manager-options">
|
||||
<InputText
|
||||
label="Description"
|
||||
value={state.alias}
|
||||
onChange={alias => this.setState({...state, alias})}
|
||||
/>
|
||||
<InputNumber
|
||||
label="How many times?"
|
||||
value={state?.repeat?.count}
|
||||
onChange={count => this.setState({...state, repeat: {...state.repeat, count}})}
|
||||
/>
|
||||
<InputYaml
|
||||
label="Sequence"
|
||||
value={state?.repeat?.sequence ?? {}}
|
||||
onChange={sequence => this.setState({...state, repeat: {...state.repeat, sequence}})}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -1,47 +1,39 @@
|
||||
import InputText from "../../components/InputText";
|
||||
import InputWrapper from "../../components/InputWrapper";
|
||||
import { ServiceScript } from "../types/script";
|
||||
import { BaseStateManager } from "./BaseManager";
|
||||
import { BaseState } from "./BaseState";
|
||||
|
||||
|
||||
export class ScriptCallService extends BaseStateManager<ServiceScript> {
|
||||
defaultState(): ServiceScript {
|
||||
return {
|
||||
service: "",
|
||||
alias: "Call Service",
|
||||
target: "",
|
||||
data: {},
|
||||
}
|
||||
export default class ScriptCallServiceState extends BaseState<ServiceScript> {
|
||||
defaultState = () => ({
|
||||
service: "",
|
||||
alias: "Call Service",
|
||||
target: "",
|
||||
data: {},
|
||||
})
|
||||
isReady(state: ServiceScript): boolean {
|
||||
return state.service !== '' &&
|
||||
state.alias !== '' &&
|
||||
state.target !== ''
|
||||
}
|
||||
isReady(): boolean {
|
||||
return this.state.service !== '' &&
|
||||
this.state.alias !== '' &&
|
||||
this.state.target !== ''
|
||||
}
|
||||
renderOptionList(): JSX.Element {
|
||||
renderOptionList(state: ServiceScript): JSX.Element {
|
||||
return <div className="state-manager-options">
|
||||
<label htmlFor="#alias">Description</label>
|
||||
<input id="alias" value={this.state.alias} onChange={e => {
|
||||
e.preventDefault();
|
||||
this.setState({
|
||||
...this.state,
|
||||
alias: e.target.value,
|
||||
})
|
||||
}}/>
|
||||
<label htmlFor="#service">Service</label>
|
||||
<input id="service" value={this.state.service} onChange={e => {
|
||||
e.preventDefault();
|
||||
this.setState({
|
||||
...this.state,
|
||||
service: e.target.value,
|
||||
})
|
||||
}}/>
|
||||
<label htmlFor="#target">Target</label>
|
||||
<input id="target" value={this.state.target} onChange={e => {
|
||||
e.preventDefault();
|
||||
this.setState({
|
||||
...this.state,
|
||||
target: e.target.value,
|
||||
})
|
||||
}}/>
|
||||
<InputText
|
||||
label="Description"
|
||||
value={state.alias}
|
||||
onChange={alias => this.setState({...state, alias})}
|
||||
/>
|
||||
<InputText
|
||||
textBoxFor="service"
|
||||
label="Service"
|
||||
value={state.service}
|
||||
onChange={service => this.setState({...state, service})}
|
||||
/>
|
||||
<InputText
|
||||
label="Target"
|
||||
value={state.target}
|
||||
onChange={target => this.setState({...state, target})}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import InputBoolean from "../../components/InputBoolean";
|
||||
import InputNumber from "../../components/InputNumber";
|
||||
import InputText from "../../components/InputText";
|
||||
import { WaitScript } from "../types/script";
|
||||
import { BaseState } from "./BaseState";
|
||||
|
||||
|
||||
export default class ScriptWaitState extends BaseState<WaitScript> {
|
||||
defaultState = () => ({
|
||||
alias: "Wait",
|
||||
wait_template: "",
|
||||
timeout: 0,
|
||||
continue_on_timeout: false,
|
||||
})
|
||||
isReady(state: WaitScript): boolean {
|
||||
return state.alias !== '' &&
|
||||
state.wait_template !== ""
|
||||
}
|
||||
renderOptionList(state: WaitScript): JSX.Element {
|
||||
return <div className="state-manager-options">
|
||||
<InputText
|
||||
label="Description"
|
||||
value={state.alias}
|
||||
onChange={alias => this.setState({...state, alias})}
|
||||
/>
|
||||
<InputText
|
||||
textBoxFor="template"
|
||||
label="Template"
|
||||
value={state.wait_template}
|
||||
onChange={wait_template => this.setState({...state, wait_template})}
|
||||
/>
|
||||
<InputNumber
|
||||
label="Timeout"
|
||||
value={state.timeout ?? 0}
|
||||
onChange={timeout => this.setState({...state, timeout})}
|
||||
/>
|
||||
<InputBoolean
|
||||
label="Continue on Timeout"
|
||||
value={state.continue_on_timeout ?? false}
|
||||
onChange={continue_on_timeout => this.setState({...state, continue_on_timeout})}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { AutomationNodeType, NodeSubType } from "../types"
|
||||
import ConditionLogicState from "./ConditionLogic"
|
||||
import ScriptChooseState from "./ScriptChoose"
|
||||
import ScriptDeviceState from "./ScriptDevice"
|
||||
import ScriptEventState from "./ScriptEvent"
|
||||
import ScriptRepeatState from "./ScriptRepeat"
|
||||
import ScriptCallServiceState from "./ScriptService"
|
||||
import ScriptWaitState from "./ScriptWait"
|
||||
|
||||
|
||||
export const getBaseState = <T extends AutomationNodeType>(
|
||||
node_type: T,
|
||||
node_subtype: NodeSubType<T>
|
||||
) : any => {
|
||||
if ( node_type === 'action') {
|
||||
switch (node_subtype) {
|
||||
case 'Service':
|
||||
return ScriptCallServiceState
|
||||
case "Repeat":
|
||||
return ScriptRepeatState;
|
||||
case "Wait":
|
||||
return ScriptWaitState;
|
||||
case "Event":
|
||||
return ScriptEventState;
|
||||
case "Device":
|
||||
return ScriptDeviceState;
|
||||
case "Choose":
|
||||
return ScriptChooseState;
|
||||
}
|
||||
}
|
||||
if (node_type === 'condition') {
|
||||
switch (node_subtype) {
|
||||
case 'Logic':
|
||||
return ConditionLogicState
|
||||
}
|
||||
}
|
||||
throw new Error(`Invalid or Not implemented node type ${node_type} -> ${node_subtype}`)
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { AutomationNodeType, NodeSubType } from "../types";
|
||||
import { BaseState } from "./BaseState";
|
||||
import Generic from "./Generic";
|
||||
import { getBaseState } from "./getBaseState";
|
||||
|
||||
export default class StateManager {
|
||||
public state: any;
|
||||
private setState: (s: any) => void;
|
||||
private baseState: BaseState<any>;
|
||||
|
||||
constructor(
|
||||
public nodeType: AutomationNodeType,
|
||||
public nodeSubtype: NodeSubType,
|
||||
initialState: any | undefined = undefined,
|
||||
){
|
||||
[this.state, this.setState] = useState(initialState ?? {});
|
||||
this.baseState = this.swapBaseState(this.nodeType, this.nodeSubtype);
|
||||
if (!initialState) {
|
||||
useEffect(() => {
|
||||
this.setState(this.baseState.defaultState());
|
||||
}, [this.nodeType, this.nodeSubtype]);
|
||||
}
|
||||
}
|
||||
swapBaseState(nodeType: AutomationNodeType, nodeSubtype: NodeSubType) {
|
||||
try {
|
||||
this.baseState = new (getBaseState(nodeType, nodeSubtype))(this.setState);
|
||||
} catch (error) {
|
||||
this.baseState = new Generic(this.setState);
|
||||
}
|
||||
this.nodeType = nodeType;
|
||||
this.nodeSubtype = nodeSubtype;
|
||||
return this.baseState;
|
||||
}
|
||||
renderOptionList() {
|
||||
return this.baseState.renderOptionList(this.state)
|
||||
}
|
||||
get isReady() {
|
||||
return this.baseState.isReady(this.state);
|
||||
}
|
||||
}
|
||||
@@ -56,3 +56,14 @@ export type AutomationCondition =
|
||||
| ZoneCondition
|
||||
| GenericCondition
|
||||
;
|
||||
export const conditionTypes = [
|
||||
'Logic',
|
||||
'Numeric State',
|
||||
'State',
|
||||
'Template',
|
||||
'Time',
|
||||
'Trigger',
|
||||
'Zone',
|
||||
'Generic',
|
||||
] as const;
|
||||
export type ConditionType = typeof conditionTypes[number];
|
||||
@@ -1,6 +1,6 @@
|
||||
import { AutomationCondition } from "./condition";
|
||||
import { AutomationScript } from "./script";
|
||||
import { AutomationTrigger } from "./triggers";
|
||||
import { AutomationCondition, ConditionType, conditionTypes } from "./condition";
|
||||
import { AutomationScript, ScriptType, scriptTypes } from "./script";
|
||||
import { AutomationTrigger, TriggerType, triggerTypes } from "./triggers";
|
||||
|
||||
export interface Automation {
|
||||
id: string;
|
||||
@@ -19,3 +19,14 @@ export type AutomationAction = AutomationScript | AutomationCondition;
|
||||
export type AutomationNode<T extends AutomationNodeType> =
|
||||
AutomationNodeTypes[T][number];
|
||||
|
||||
export type NodeSubType<T=any> =
|
||||
T extends 'action' ? ScriptType :
|
||||
T extends 'condition' ? ConditionType :
|
||||
T extends 'trigger' ? TriggerType :
|
||||
never;
|
||||
|
||||
export const typeList = {
|
||||
'action': scriptTypes,
|
||||
'condition': conditionTypes,
|
||||
'trigger': triggerTypes,
|
||||
} as const;
|
||||
@@ -46,3 +46,12 @@ export type AutomationScript =
|
||||
| DeviceScript
|
||||
| ChooseScript
|
||||
;
|
||||
export const scriptTypes = [
|
||||
'Service',
|
||||
'Repeat',
|
||||
'Wait',
|
||||
'Event',
|
||||
'Device',
|
||||
'Choose'
|
||||
] as const;
|
||||
export type ScriptType = typeof scriptTypes[number];
|
||||
@@ -87,4 +87,20 @@ export type AutomationTrigger =
|
||||
| AutomationTriggerZone
|
||||
| AutomationTriggerDevice
|
||||
| AutomationTriggerGeneric
|
||||
;
|
||||
;
|
||||
export const triggerTypes = [
|
||||
'Event',
|
||||
'Home Assistant',
|
||||
'MQTT',
|
||||
'Numeric State',
|
||||
'State',
|
||||
'Tag',
|
||||
'Template',
|
||||
'Time',
|
||||
'Time Pattern',
|
||||
'Webhook',
|
||||
'Zone',
|
||||
'Device',
|
||||
'Generic',
|
||||
] as const;
|
||||
export type TriggerType = typeof triggerTypes[number];
|
||||
@@ -1,112 +0,0 @@
|
||||
import { BaseStateManager } from "./StateManager/BaseManager";
|
||||
import { ScriptCallService } from "./StateManager/ScriptService";
|
||||
import { AutomationNode, AutomationNodeType } from "./types";
|
||||
|
||||
export const triggerTypes = [
|
||||
'Event',
|
||||
'Home Assistant',
|
||||
'MQTT',
|
||||
'Numeric State',
|
||||
'State',
|
||||
'Tag',
|
||||
'Template',
|
||||
'Time',
|
||||
'Time Pattern',
|
||||
'Webhook',
|
||||
'Zone',
|
||||
'Device',
|
||||
] as const;
|
||||
export type TriggerType = typeof triggerTypes[number];
|
||||
export const conditionTypes = [
|
||||
'And' ,
|
||||
'Or' ,
|
||||
'Not',
|
||||
'Numeric State',
|
||||
'State',
|
||||
'Template',
|
||||
'Time',
|
||||
'Trigger',
|
||||
'Zone',
|
||||
] as const;
|
||||
export type ConditionType = typeof conditionTypes[number];
|
||||
export const scriptTypes = [
|
||||
'Service',
|
||||
'Repeat',
|
||||
'Wait',
|
||||
'Event',
|
||||
'Device',
|
||||
'Choose'
|
||||
] as const;
|
||||
export type ScriptType = typeof scriptTypes[number];
|
||||
export type NodeStateType<T> =
|
||||
T extends 'action' ? ScriptType :
|
||||
T extends 'condition' ? ConditionType :
|
||||
T extends 'trigger' ? TriggerType :
|
||||
never;
|
||||
|
||||
export const typeList = {
|
||||
'action': scriptTypes,
|
||||
'condition': conditionTypes,
|
||||
'trigger': triggerTypes,
|
||||
} as const;
|
||||
|
||||
export const useNewNodeState = <T extends AutomationNodeType>(
|
||||
node_type: T,
|
||||
node_subtype: NodeStateType<T>
|
||||
) : BaseStateManager<AutomationNode<T>> => {
|
||||
if ( node_type === 'action') {
|
||||
switch (node_subtype) {
|
||||
case 'Service':
|
||||
return new ScriptCallService() as any;
|
||||
// case 'Repeat':
|
||||
// return {
|
||||
// repeat: {
|
||||
// count: 0,
|
||||
// sequence: [],
|
||||
// }
|
||||
// }
|
||||
// case 'Wait':
|
||||
// return {
|
||||
// wait_template: ""
|
||||
// }
|
||||
// case 'Event':
|
||||
// return {
|
||||
// event: "",
|
||||
// event_data: {}
|
||||
// }
|
||||
// case "Device":
|
||||
// return {
|
||||
// type: "",
|
||||
// device_id: "",
|
||||
// entity_id: "",
|
||||
// domain: "",
|
||||
// }
|
||||
// case "Choose":
|
||||
// return {
|
||||
// choose: [],
|
||||
// default: [],
|
||||
// }
|
||||
}
|
||||
}
|
||||
// else if (node_type === "condition") {
|
||||
// if (node_subtype in ['And', 'Or', 'Noe']) {
|
||||
// return {
|
||||
// condition: node_subtype.toLowerCase(),
|
||||
// conditions: [],
|
||||
// }
|
||||
// } else if (node_subtype === 'Numeric State') {
|
||||
// return {
|
||||
// condition: "numeric_state",
|
||||
// entity_id: ""
|
||||
// }
|
||||
// } else if (node_subtype === 'State') {
|
||||
// return {
|
||||
// condition: "state",
|
||||
// entity_id: "",
|
||||
// state: "",
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
throw new Error(`Invalid or Not implemented node type ${node_type} -> ${node_subtype}`)
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { AutomationNode } from "./types";
|
||||
import { AutomationNode, AutomationNodeType, NodeSubType } from "./types";
|
||||
|
||||
|
||||
export const getNameFromAction = (action: AutomationNode): string => {
|
||||
export const getNameFromAction = (action: AutomationNode<any>): string => {
|
||||
if(typeof action === 'string') {
|
||||
return action;
|
||||
}
|
||||
@@ -27,4 +27,78 @@ export const getNameFromAction = (action: AutomationNode): string => {
|
||||
return 'Choose'
|
||||
}
|
||||
return 'n/a'
|
||||
}
|
||||
|
||||
export const determineNodeTypes = (action: AutomationNode<any>) : [AutomationNodeType, NodeSubType] => {
|
||||
if ('condition' in action) {
|
||||
switch (action.condition) {
|
||||
case 'and':
|
||||
return ['condition', 'Logic']
|
||||
case 'or':
|
||||
return ['condition', 'Logic']
|
||||
case 'not':
|
||||
return ['condition', 'Logic']
|
||||
case 'numeric_state':
|
||||
return ['condition', 'Numeric State']
|
||||
case 'state':
|
||||
return ['condition', 'State']
|
||||
case 'template':
|
||||
return ['condition', 'Template']
|
||||
case 'trigger':
|
||||
return ['condition', 'Trigger']
|
||||
case 'zone':
|
||||
return ['condition', 'Zone']
|
||||
default:
|
||||
return ['condition', 'Generic']
|
||||
|
||||
}
|
||||
}
|
||||
if ('platform' in action) {
|
||||
switch (action.platform) {
|
||||
case 'event':
|
||||
return ['trigger', 'Event']
|
||||
case 'homeassistant':
|
||||
return ['trigger', 'Home Assistant']
|
||||
case 'mqtt':
|
||||
return ['trigger', 'MQTT']
|
||||
case 'numeric_state':
|
||||
return ['trigger', 'Numeric State']
|
||||
case 'state':
|
||||
return ['trigger', 'State']
|
||||
case 'tag':
|
||||
return ['trigger', 'Tag']
|
||||
case 'template':
|
||||
return ['trigger', 'Template']
|
||||
case 'time':
|
||||
return ['trigger', 'Time']
|
||||
case 'time_pattern':
|
||||
return ['trigger', 'Time Pattern']
|
||||
case 'webhook':
|
||||
return ['trigger', 'Webhook']
|
||||
case 'zone':
|
||||
return ['trigger', 'Zone']
|
||||
default:
|
||||
return ['trigger', 'Generic']
|
||||
|
||||
}
|
||||
}
|
||||
if ('service' in action) {
|
||||
return ["action", "Service"]
|
||||
}
|
||||
if ('repeat' in action) {
|
||||
return ["action", "Repeat"]
|
||||
}
|
||||
if ('wait_template' in action) {
|
||||
return ["action", "Wait"]
|
||||
}
|
||||
if ('event' in action) {
|
||||
return ["action", "Event"]
|
||||
}
|
||||
if (('type' in action) && ('device_id' in action)) {
|
||||
return ["action", "Device"]
|
||||
}
|
||||
if ('choose' in action) {
|
||||
return ["action", "Choose"]
|
||||
}
|
||||
throw Error(`Could not determine node type ${JSON.stringify(action)}`)
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
import { useState } from "react";
|
||||
import { AutomationNodeType, AutomationNodeTypes } from "../../automation/types";
|
||||
import { typeList } from "../../automation/useNodeState";
|
||||
import { useState, useEffect } from "react";
|
||||
import StateManager from "../../automation/StateManager";
|
||||
import { AutomationNodeType, AutomationNodeTypes, NodeSubType, typeList } from "../../automation/types";
|
||||
import InputList from "../InputList";
|
||||
import InputWrapper from "../InputWrapper";
|
||||
|
||||
export interface Props<T extends AutomationNodeType> {
|
||||
node_type: T,
|
||||
@@ -14,20 +13,33 @@ export default function NewNodeModal<T extends AutomationNodeType>({
|
||||
onClose,
|
||||
onCreate,
|
||||
}: Props<T>) {
|
||||
const [selectedSubType, setSubType] = useState<string>(typeList[node_type][0]);
|
||||
const [selectedSubType, setSubType] = useState<NodeSubType>(typeList[node_type][0]);
|
||||
const stateManager = new StateManager(node_type, selectedSubType);
|
||||
|
||||
useEffect(() => {
|
||||
if (stateManager.nodeType !== node_type || stateManager.nodeSubtype !== selectedSubType) {
|
||||
stateManager.swapBaseState(node_type, selectedSubType)
|
||||
}
|
||||
}, [node_type, selectedSubType]);
|
||||
|
||||
return <div className="new-node-modal">
|
||||
<div className="new-node-modal--background" onClick={() => onClose()}></div>
|
||||
<div className="new-node-modal--inner" onClick={e => e.preventDefault()}>
|
||||
<div className="new-node-modal--title">Create {node_type[0].toUpperCase()}{node_type.slice(1)}</div>
|
||||
<div className="new-node-modal--body">
|
||||
<InputWrapper label="Type:">
|
||||
<InputList options={typeList[node_type]} current={selectedSubType} onChange={n => setSubType(n)}/>
|
||||
</InputWrapper>
|
||||
<InputList label="Type:"
|
||||
options={typeList[node_type]}
|
||||
current={selectedSubType}
|
||||
onChange={n => setSubType(n as NodeSubType)}
|
||||
/>
|
||||
{stateManager.renderOptionList()}
|
||||
</div>
|
||||
<div className="new-node-modal--footer">
|
||||
<button className="secondary" onClick={() => onClose()}>Close</button>
|
||||
<button onClick={() => onCreate({} as any)}>Create</button>
|
||||
<button onClick={() => onClose()}>Close</button>
|
||||
<button onClick={() => onCreate(stateManager.state)}
|
||||
disabled={!stateManager.isReady}>
|
||||
Create
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import StateManager from "../../automation/StateManager";
|
||||
import { AutomationAction } from "../../automation/types";
|
||||
import { determineNodeTypes, getNameFromAction } from "../../automation/utils";
|
||||
import AutomationNode from "../Node";
|
||||
|
||||
|
||||
export interface Props {
|
||||
data: AutomationAction;
|
||||
onDelete: () => void;
|
||||
}
|
||||
export default function ScriptNode({
|
||||
data,
|
||||
onDelete,
|
||||
}: Props) {
|
||||
const [nodeType, nodeSubType] = determineNodeTypes(data);
|
||||
const stateManager = new StateManager(nodeType, nodeSubType, data);
|
||||
|
||||
return <AutomationNode title={getNameFromAction(data)} onXClick={onDelete}>
|
||||
{stateManager.renderOptionList()}
|
||||
</AutomationNode>
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import * as types from "../../automation/types";
|
||||
import { getNameFromAction } from "../../automation/utils";
|
||||
import AutomationNode from "../Node";
|
||||
import NewNodeModal from "./NewNodeModal";
|
||||
import ScriptNode from "./ScriptNode";
|
||||
|
||||
export interface Props {
|
||||
automation: types.Automation;
|
||||
@@ -14,14 +15,14 @@ export default function AutomationEditor({ automation }: Props) {
|
||||
|
||||
// helper state functions
|
||||
const addNode = <T extends types.AutomationNodeType>(node_type: T, node: types.AutomationNodeTypes[T]) => {
|
||||
const nodes: types.AutomationNode[] = state[node_type];
|
||||
const nodes: types.AutomationNode<T>[] = state[node_type];
|
||||
setState({
|
||||
...state,
|
||||
[node_type]: nodes.concat([node as any])
|
||||
});
|
||||
}
|
||||
const removeNode = <T extends types.AutomationNodeType>(node_type: T, node_id: number) => {
|
||||
const nodes: types.AutomationNode[] = state[node_type];
|
||||
const nodes: types.AutomationNode<T>[] = state[node_type];
|
||||
setState({
|
||||
...state,
|
||||
[node_type]: nodes
|
||||
@@ -35,17 +36,14 @@ export default function AutomationEditor({ automation }: Props) {
|
||||
});
|
||||
}
|
||||
// helper element functions
|
||||
const makeChild = (node_type: types.AutomationNodeType) => {
|
||||
const nodes: types.AutomationNode[] = state[node_type];
|
||||
const makeChild = <T extends types.AutomationNodeType>(node_type: T) => {
|
||||
return [
|
||||
<div className="automation-box--elm-list" key="list">
|
||||
<div className="automation-editor--elm-list" key="list">
|
||||
{state[node_type].map((n, i) => (
|
||||
<AutomationNode
|
||||
<ScriptNode
|
||||
key={i}
|
||||
title={getNameFromAction(n)}
|
||||
showX={false}
|
||||
initialOpenState={false}
|
||||
onXClick={() => removeNode(node_type, i)}
|
||||
onDelete={() => removeNode(node_type, i)}
|
||||
data={n as any}
|
||||
/>
|
||||
))}
|
||||
</div>,
|
||||
@@ -63,16 +61,19 @@ export default function AutomationEditor({ automation }: Props) {
|
||||
<AutomationNode
|
||||
title={`${automation.alias} (${automation.mode})`}
|
||||
initialOpenState={true}
|
||||
showChildren={true}
|
||||
showX={false}
|
||||
>
|
||||
<div className="automation-editor--root">
|
||||
<h4>Trigger</h4>
|
||||
{makeChild("trigger")}
|
||||
<h4>Condition</h4>
|
||||
{makeChild("condition")}
|
||||
<h4>Actions</h4>
|
||||
{makeChild("action")}
|
||||
<div className="automation-editor--triggers">
|
||||
<h4>Trigger</h4>
|
||||
{makeChild("trigger")}
|
||||
<h4>Condition</h4>
|
||||
{makeChild("condition")}
|
||||
</div>
|
||||
<div className="automation-editor--playground">
|
||||
<h4>Actions</h4>
|
||||
{makeChild("action")}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</AutomationNode>
|
||||
{modalState && <NewNodeModal
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import InputWrapper from "./InputWrapper";
|
||||
|
||||
export interface Props {
|
||||
label: string;
|
||||
value: boolean;
|
||||
onChange: (v: boolean) => void;
|
||||
}
|
||||
export default function InputBoolean({
|
||||
label,
|
||||
value=false,
|
||||
onChange,
|
||||
}: Props) {
|
||||
return <InputWrapper label={label} style={{
|
||||
flexDirection: 'row',
|
||||
justifyContent: 'space-between',
|
||||
marginTop: '3%',
|
||||
marginBottom: '3%'
|
||||
}}>
|
||||
<span className="checkbox" onClick={e => {
|
||||
e.preventDefault()
|
||||
onChange(!value)
|
||||
}}>
|
||||
{value ? '✔️' : ' '}
|
||||
</span>
|
||||
</InputWrapper>
|
||||
}
|
||||
@@ -1,18 +1,25 @@
|
||||
import { SelectHTMLAttributes } from "react";
|
||||
import InputWrapper from "./InputWrapper";
|
||||
|
||||
|
||||
export interface Props {
|
||||
current: string;
|
||||
options: readonly string[];
|
||||
export interface Props<T extends string> {
|
||||
current: T;
|
||||
options: readonly T[];
|
||||
onChange: (n: string) => void;
|
||||
id?: string;
|
||||
className?: string;
|
||||
label: string;
|
||||
}
|
||||
export default function InputList({current, options, onChange, ...selattr}: Props) {
|
||||
return <select {...selattr} value={current} onChange={e => {
|
||||
e.preventDefault();
|
||||
onChange(e.currentTarget.value);
|
||||
}}>
|
||||
{options.map((t, i) => <option id={String(i)} key={i}>{t}</option>)}
|
||||
</select>
|
||||
export default function InputList<T extends string>({
|
||||
current, options, onChange, label,
|
||||
...selattr
|
||||
}: Props<T>) {
|
||||
return <InputWrapper label={label}>
|
||||
<select {...selattr} value={current} onChange={e => {
|
||||
e.preventDefault();
|
||||
onChange(e.currentTarget.value);
|
||||
}}>
|
||||
{options.map((t, i) => <option id={String(i)} key={i}>{t}</option>)}
|
||||
</select>
|
||||
</InputWrapper>
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { useToolTip } from "../tooltip/context";
|
||||
import InputWrapper from "./InputWrapper";
|
||||
|
||||
export interface Props {
|
||||
label: string;
|
||||
value: number;
|
||||
onChange: (v: number) => void;
|
||||
}
|
||||
export default function InputNumber({
|
||||
label,
|
||||
value=0,
|
||||
onChange,
|
||||
}: Props) {
|
||||
const tooltip = useToolTip();
|
||||
return <InputWrapper label={label}>
|
||||
<input
|
||||
type="number"
|
||||
value={value}
|
||||
onChange={e => {
|
||||
e.preventDefault();
|
||||
onChange(Number(e.target.value))
|
||||
}}
|
||||
/>
|
||||
</InputWrapper>
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { useToolTip } from "../tooltip/context";
|
||||
import InputWrapper from "./InputWrapper";
|
||||
|
||||
export interface Props {
|
||||
textBoxFor?: string;
|
||||
label: string;
|
||||
value: string;
|
||||
onChange: (v: string) => void;
|
||||
additionalTooltipFilters?: Record<string, string>;
|
||||
}
|
||||
export default function InputText({
|
||||
label,
|
||||
textBoxFor,
|
||||
value="",
|
||||
onChange,
|
||||
additionalTooltipFilters={},
|
||||
}: Props) {
|
||||
const tooltip = useToolTip();
|
||||
return <InputWrapper label={label}>
|
||||
<input
|
||||
value={value}
|
||||
onChange={e => {
|
||||
e.preventDefault();
|
||||
onChange(e.target.value)
|
||||
}}
|
||||
onFocus={e => textBoxFor && tooltip.setFocus(
|
||||
e.target.getBoundingClientRect(),
|
||||
{
|
||||
searchObject: textBoxFor,
|
||||
textInput: value,
|
||||
filterObjects: additionalTooltipFilters,
|
||||
},
|
||||
onChange
|
||||
)}
|
||||
/>
|
||||
</InputWrapper>
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
import { PropsWithChildren } from "react";
|
||||
import { CSSProperties, PropsWithChildren } from "react";
|
||||
|
||||
|
||||
export interface Props {
|
||||
label: string;
|
||||
style?: CSSProperties;
|
||||
}
|
||||
export default function InputWrapper({label, children}: PropsWithChildren<Props>) {
|
||||
return <div className="input-wrapper">
|
||||
export default function InputWrapper({label, children, style={}}: PropsWithChildren<Props>) {
|
||||
return <div className="input-wrapper" style={style}>
|
||||
<label>{label}</label>
|
||||
{children}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import InputWrapper from "./InputWrapper";
|
||||
import * as yaml from "js-yaml";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
|
||||
export interface Props<T> {
|
||||
label: string;
|
||||
value: T;
|
||||
onChange: (v: T) => void;
|
||||
}
|
||||
export default function InputYaml<T>({
|
||||
label,
|
||||
value={} as any,
|
||||
onChange,
|
||||
}: Props<T>) {
|
||||
const [text, setText] = useState("");
|
||||
useEffect(() => {
|
||||
setText(yaml.dump(value));
|
||||
}, [value]);
|
||||
const delayId = useRef<null | number>(null);
|
||||
const delayedUpdate = (update: string) => {
|
||||
if (delayId.current) {
|
||||
window.clearTimeout(delayId.current);
|
||||
delayId.current = null;
|
||||
}
|
||||
delayId.current = window.setTimeout(() => {
|
||||
onChange(yaml.load(update))
|
||||
}, 1000);
|
||||
}
|
||||
return <InputWrapper label={label}>
|
||||
<textarea
|
||||
value={text}
|
||||
onChange={e => {
|
||||
e.preventDefault();
|
||||
setText(e.target.value);
|
||||
delayedUpdate(e.target.value);
|
||||
}}
|
||||
/>
|
||||
</InputWrapper>
|
||||
}
|
||||
@@ -2,41 +2,34 @@ import { PropsWithChildren, useState } from "react";
|
||||
|
||||
export interface Props {
|
||||
title: string;
|
||||
showX?: boolean;
|
||||
showChildren?: boolean;
|
||||
initialOpenState?: boolean;
|
||||
onXClick?: () => void;
|
||||
}
|
||||
export default function AutomationNode({
|
||||
children,
|
||||
title,
|
||||
showX=false,
|
||||
showChildren=false,
|
||||
initialOpenState=false,
|
||||
onXClick = () => {},
|
||||
}: PropsWithChildren<Props>) {
|
||||
const [isOpen, setOpen] = useState(initialOpenState);
|
||||
console.log(children);
|
||||
return <div className="automation-node">
|
||||
<div className="automation-node-inner">
|
||||
<div
|
||||
className="automation-node-inner-edge left"
|
||||
onClick={() => onXClick()}
|
||||
>
|
||||
{showX && (
|
||||
<div className="automation-node-side-button">X</div>
|
||||
)}
|
||||
<div className="automation-node-side-button">X</div>
|
||||
</div>
|
||||
<div className="automation-node-inner-text">{title}</div>
|
||||
<div
|
||||
className="automation-node-inner-edge right"
|
||||
onClick={() => setOpen(!isOpen)}
|
||||
>
|
||||
{showChildren && <div className="automation-node-side-button">{isOpen ? "▲" : "▼"}</div>}
|
||||
<div className="automation-node-side-button">{isOpen ? "▲" : "▼"}</div>
|
||||
</div>
|
||||
</div>
|
||||
{showChildren&&<div className={`automation-node-children ${isOpen ? "open" : "closed"}`}>
|
||||
<div className={`automation-node-children ${isOpen ? "open" : "closed"}`}>
|
||||
{children}
|
||||
</div>}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
import AutomationEditor from "../components/AutomationEditor";
|
||||
import sample from "../sample/auto_01.yaml";
|
||||
|
||||
console.log(sample)
|
||||
|
||||
export function Home() {
|
||||
return (
|
||||
<div id="page--home" className="page">
|
||||
|
||||
+25
-8
@@ -1,17 +1,34 @@
|
||||
import React from "react";
|
||||
import React, { useState } from "react";
|
||||
import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";
|
||||
import NewNodeModal from "./components/AutomationEditor/NewNodeModal";
|
||||
import { Home } from "./pages/Home";
|
||||
import Tooltip from "./tooltip";
|
||||
import { TooltipContext, TooltipState } from "./tooltip/context";
|
||||
|
||||
export default function App() {
|
||||
const [tooltipState, updateState] = useState<TooltipState>({
|
||||
updateState(s) { updateState(s) },
|
||||
searchResults: [
|
||||
"Option #1"
|
||||
],
|
||||
});
|
||||
return (
|
||||
<Router>
|
||||
<div>
|
||||
<Switch>
|
||||
<Route path="/">
|
||||
<Home />
|
||||
</Route>
|
||||
</Switch>
|
||||
</div>
|
||||
<TooltipContext.Provider value={tooltipState}>
|
||||
<div>
|
||||
<Switch>
|
||||
<Route path="/">
|
||||
<Home />
|
||||
{/* <NewNodeModal
|
||||
node_type="action"
|
||||
onClose={()=>{}}
|
||||
onCreate={()=>{}}
|
||||
/> */}
|
||||
</Route>
|
||||
</Switch>
|
||||
</div>
|
||||
<Tooltip {...tooltipState}/>
|
||||
</TooltipContext.Provider>
|
||||
</Router>
|
||||
);
|
||||
}
|
||||
@@ -5,5 +5,6 @@ $secondary-accent: #929191;
|
||||
|
||||
$font-color-primary: #e1e1e1;
|
||||
|
||||
$gray: #403f3f;
|
||||
$green: #68caa4;
|
||||
$blue: #68aaca;
|
||||
@@ -0,0 +1,127 @@
|
||||
html,
|
||||
body,
|
||||
#app {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
height: 100vh;
|
||||
width: 100vw;
|
||||
overflow: hidden;
|
||||
font-family: Tahoma, Geneva, sans-serif;
|
||||
background-color: $primary;
|
||||
display: grid;
|
||||
align-items: center;
|
||||
justify-items: center;
|
||||
color: $font-color-primary;
|
||||
}
|
||||
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5 {
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
display: flex;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* width */
|
||||
::-webkit-scrollbar {
|
||||
width: 10px;
|
||||
}
|
||||
|
||||
/* Track */
|
||||
::-webkit-scrollbar-track {
|
||||
background: $secondary;
|
||||
}
|
||||
|
||||
/* Handle */
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: $secondary-accent;
|
||||
}
|
||||
|
||||
/* Handle on hover */
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background: $primary-accent;
|
||||
}
|
||||
|
||||
:root {
|
||||
touch-action: pan-x pan-y;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: $secondary;
|
||||
color: $primary-accent;
|
||||
border-color: $primary-accent;
|
||||
|
||||
&:hover {
|
||||
background-color: $primary;
|
||||
border-color: $secondary-accent;
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
background-color: $gray;
|
||||
border-color: $gray;
|
||||
color: darken($gray, 50);
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
&.secondary {
|
||||
background-color: $primary;
|
||||
color: $secondary-accent;
|
||||
border-color: $secondary-accent;
|
||||
&:hover {
|
||||
background-color: $secondary;
|
||||
border-color: $primary-accent;
|
||||
}
|
||||
}
|
||||
|
||||
border-style: solid;
|
||||
border-width: 1px;
|
||||
padding: 2.5px;
|
||||
margin-left: 5px;
|
||||
margin-right: 5px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
select {
|
||||
@extend button;
|
||||
margin: 0;
|
||||
}
|
||||
input {
|
||||
@extend button;
|
||||
margin: 0;
|
||||
cursor: text;
|
||||
}
|
||||
input[type="number"]::-webkit-inner-spin-button,
|
||||
::-webkit-outer-spin-button {
|
||||
opacity: 0;
|
||||
}
|
||||
textarea {
|
||||
@extend button;
|
||||
cursor: text;
|
||||
margin: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
span.checkbox {
|
||||
height: 16px;
|
||||
width: 16px;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
border: 1px $primary-accent solid;
|
||||
align-content: center;
|
||||
text-align: center;
|
||||
justify-content: center;
|
||||
display: flex;
|
||||
background-color: $primary;
|
||||
color: $primary-accent;
|
||||
overflow: hidden;
|
||||
|
||||
&:hover {
|
||||
background-color: $secondary;
|
||||
color: $secondary-accent;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,44 @@
|
||||
.automation-editor {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
|
||||
.automation-node {
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
> &-inner {
|
||||
min-width: 100%;
|
||||
}
|
||||
}
|
||||
&--root {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
width: 100%;
|
||||
// justify-content: center;
|
||||
// align-items: center;
|
||||
}
|
||||
&--triggers {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
&--playground {
|
||||
width: 100%;
|
||||
> .automation-editor--elm-list {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: start;
|
||||
}
|
||||
}
|
||||
button.elm-list {
|
||||
width: 90%;
|
||||
}
|
||||
&--elm-list {
|
||||
max-height: 300px;
|
||||
max-height: 20vh;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
overflow-x: auto;
|
||||
padding: 5%;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@
|
||||
}
|
||||
&-children {
|
||||
min-width: 250px;
|
||||
padding: 2.5px;
|
||||
padding: 20px;
|
||||
|
||||
&.closed {
|
||||
height: 0;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
.input-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-bottom: 8px;
|
||||
label {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
.state-manager-options {
|
||||
}
|
||||
@@ -2,3 +2,7 @@
|
||||
@import "./AutomationEditor.scss";
|
||||
@import "./NewNodeModal.scss";
|
||||
@import "./InputWrapper.scss";
|
||||
|
||||
* {
|
||||
transition: all 200ms ease-in;
|
||||
}
|
||||
+2
-101
@@ -1,105 +1,6 @@
|
||||
@import "./colors.scss";
|
||||
@import "./pages/index.scss";
|
||||
@import "./utils.scss";
|
||||
@import "./common.scss";
|
||||
@import "./components/index.scss";
|
||||
|
||||
html,
|
||||
body,
|
||||
#app {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
height: 100vh;
|
||||
width: 100vw;
|
||||
overflow: hidden;
|
||||
font-family: Tahoma, Geneva, sans-serif;
|
||||
background-color: $primary;
|
||||
display: grid;
|
||||
align-items: center;
|
||||
justify-items: center;
|
||||
color: $font-color-primary;
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.col {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.center {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5 {
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
display: flex;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* width */
|
||||
::-webkit-scrollbar {
|
||||
width: 10px;
|
||||
}
|
||||
|
||||
/* Track */
|
||||
::-webkit-scrollbar-track {
|
||||
background: $secondary;
|
||||
}
|
||||
|
||||
/* Handle */
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: $secondary-accent;
|
||||
}
|
||||
|
||||
/* Handle on hover */
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background: $primary-accent;
|
||||
}
|
||||
|
||||
:root {
|
||||
touch-action: pan-x pan-y;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: $secondary;
|
||||
color: $primary-accent;
|
||||
border-color: $primary-accent;
|
||||
&:hover {
|
||||
background-color: $primary;
|
||||
border-color: $secondary-accent;
|
||||
}
|
||||
|
||||
&.secondary {
|
||||
background-color: $primary;
|
||||
color: $secondary-accent;
|
||||
border-color: $secondary-accent;
|
||||
&:hover {
|
||||
background-color: $secondary;
|
||||
border-color: $primary-accent;
|
||||
}
|
||||
}
|
||||
|
||||
border-style: solid;
|
||||
border-width: 1px;
|
||||
padding: 2.5%;
|
||||
margin-left: 5%;
|
||||
margin-right: 5%;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
select {
|
||||
@extend button;
|
||||
margin: 0;
|
||||
}
|
||||
@import "./tooltip.scss";
|
||||
@@ -0,0 +1,30 @@
|
||||
.tooltip {
|
||||
&.hide {
|
||||
width: 0;
|
||||
height: 0;
|
||||
display: none;
|
||||
}
|
||||
&-bg {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
z-index: 9;
|
||||
}
|
||||
ul {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
z-index: 10;
|
||||
|
||||
li {
|
||||
@extend button;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { createContext, useContext } from "react"
|
||||
|
||||
export interface TooltipSearchOption {
|
||||
searchObject: string;
|
||||
textInput: string;
|
||||
filterObjects: Record<string, string>;
|
||||
}
|
||||
export interface TooltipState {
|
||||
domrect?: DOMRect;
|
||||
searchOptions?: TooltipSearchOption;
|
||||
onSelected?: (s: string) => void;
|
||||
searchResults: string[];
|
||||
updateState: (s: TooltipState) => void;
|
||||
}
|
||||
export const TooltipContext = createContext<TooltipState>({
|
||||
updateState(s) {},
|
||||
searchResults: [],
|
||||
})
|
||||
|
||||
export const useToolTip = () => {
|
||||
const state = useContext(TooltipContext);
|
||||
|
||||
return {
|
||||
setFocus(
|
||||
domrect: DOMRect,
|
||||
searchOptions: TooltipSearchOption,
|
||||
onSelected: (s: string) => void
|
||||
){
|
||||
state.updateState({
|
||||
...state,
|
||||
domrect, searchOptions, onSelected
|
||||
})
|
||||
},
|
||||
setSearchResults(searchResults: string[]){
|
||||
state.updateState({
|
||||
...state,
|
||||
searchResults
|
||||
})
|
||||
},
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
import { TooltipState } from "./context";
|
||||
|
||||
export default function Tooltip({
|
||||
domrect,
|
||||
searchOptions,
|
||||
searchResults=[],
|
||||
onSelected=()=>{},
|
||||
updateState,
|
||||
}: TooltipState) {
|
||||
|
||||
// state alias
|
||||
const rootClassName = !!domrect && !!searchOptions ? "tooltip show" : "tooltip hide";
|
||||
let tooltipStyle = {};
|
||||
if (domrect) {
|
||||
const {left=0, top=0, height=0, width=0} = domrect;
|
||||
tooltipStyle = {
|
||||
top: `${top + height}px`,
|
||||
left: `${left}px`,
|
||||
width: `${width}px`,
|
||||
}
|
||||
}
|
||||
const unFocus = () => updateState({
|
||||
updateState,
|
||||
onSelected,
|
||||
searchResults: [],
|
||||
});
|
||||
|
||||
return <div className={rootClassName}>
|
||||
<div className="tooltip-bg" onClick={() => unFocus()}></div>
|
||||
<ul style={tooltipStyle}>
|
||||
{searchResults.map((r, i) => <li key={i} onClick={() => {
|
||||
onSelected(r);
|
||||
unFocus();
|
||||
}}>
|
||||
{r}
|
||||
</li>)}
|
||||
{searchResults.length === 0 ? <li onClick={() => unFocus()}>No Options...</li> : ""}
|
||||
</ul>
|
||||
</div>
|
||||
}
|
||||
@@ -1327,6 +1327,11 @@
|
||||
jest-diff "^27.0.0"
|
||||
pretty-format "^27.0.0"
|
||||
|
||||
"@types/js-yaml@^4.0.4":
|
||||
version "4.0.4"
|
||||
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-4.0.4.tgz#cc38781257612581a1a0eb25f1709d2b06812fce"
|
||||
integrity sha512-AuHubXUmg0AzkXH0Mx6sIxeY/1C110mm/EkE/gB1sTRz3h2dao2W/63q42SlVST+lICxz5Oki2hzYA6+KnnieQ==
|
||||
|
||||
"@types/node@*", "@types/node@^16.11.6":
|
||||
version "16.11.6"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.6.tgz#6bef7a2a0ad684cf6e90fcfe31cecabd9ce0a3ae"
|
||||
@@ -1543,6 +1548,11 @@ argparse@^1.0.7:
|
||||
dependencies:
|
||||
sprintf-js "~1.0.2"
|
||||
|
||||
argparse@^2.0.1:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38"
|
||||
integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==
|
||||
|
||||
array-equal@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/array-equal/-/array-equal-1.0.0.tgz#8c2a5ef2472fd9ea742b04c77a75093ba2757c93"
|
||||
@@ -4209,6 +4219,13 @@ js-yaml@^3.10.0, js-yaml@^3.13.1:
|
||||
argparse "^1.0.7"
|
||||
esprima "^4.0.0"
|
||||
|
||||
js-yaml@^4.1.0:
|
||||
version "4.1.0"
|
||||
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602"
|
||||
integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==
|
||||
dependencies:
|
||||
argparse "^2.0.1"
|
||||
|
||||
jsbn@~0.1.0:
|
||||
version "0.1.1"
|
||||
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"
|
||||
|
||||
Reference in new issue
Block a user