Require the use of hex, rgb, rgba or rainbow for colors and refactor config types

This commit is contained in:
uwap 2018-02-04 03:43:22 +01:00
parent 436abf682f
commit a96fa1622b
14 changed files with 178 additions and 147 deletions

View file

@ -1,138 +1,12 @@
// @flow
import type { Color } from "config/colors";
declare type Map<K,V> = { [K]: V };
declare type Classes = {
classes: Map<string, string>
};
declare type Topic = {
state: string,
command: string,
defaultValue: any,
values: Map<string,any>,
parseState?: (msg: Object) => any
};
declare type Topics = Map<string,Topic>;
declare type TopicDependentOption<T> = (
internal: string, actual: any, state: State
) => T;
declare type StateDependentOption<T> = (
internals: Map<string, string>, actuals: Map<string, any>, state: State
) => T;
interface UIControl {
+type: string,
+text: string,
+topic: string
};
interface Enableable {
enableCondition?: TopicDependentOption<boolean>
};
declare type UIToggle = $ReadOnly<{|
type: "toggle",
text: string,
topic: string,
icon?: string,
enableCondition?: TopicDependentOption<boolean>,
on?: string,
off?: string,
toggled?: TopicDependentOption<boolean>
|}>;
declare type UIDropDown = $ReadOnly<{|
type: "dropDown",
text: string,
topic: string,
icon?: string,
enableCondition?: TopicDependentOption<boolean>,
options: Map<string, any>,
renderValue?: (value: string) => string
|}>;
declare type UISlider = $ReadOnly<{|
type: "slider",
text: string,
topic: string,
icon?: string,
enableCondition?: TopicDependentOption<boolean>,
min?: number,
max?: number,
step?: number
|}>;
declare type UISection = $ReadOnly<{|
type: "section",
text: string
|}>;
declare type UILink = $ReadOnly<{|
type: "link",
text: string,
link: string,
enableCondition?: StateDependentOption<boolean>,
// TODO: check if both the following options are implemented
icon?: string
|}>;
declare type UIText = $ReadOnly<{|
type: "text",
text: string,
topic: string,
icon?: string
|}>;
declare type UIProgress = $ReadOnly<{|
type: "progress",
text: string,
topic: string,
icon?: string,
min?: number,
max?: number
|}>;
declare type ControlUI =
UIToggle
| UIDropDown
| UISlider
| UISection
| UILink
| UIText
| UIProgress
declare type Control = {
name: string,
position: [number, number],
icon: string | (
internals: Map<string, string>,
actuals: Map<string, any>,
state: State
) => string,
iconColor?: (
internals: Map<string, string>,
actuals: Map<string, any>,
state: State
) => string,
ui: Array<ControlUI>
};
declare type Controls = Map<string,Control>;
declare type Config = {
space: Space,
topics: Topics | Array<Topics>,
controls: Controls,
layers: Array<Layer>
};
declare type Space = {
name: string,
color: "red"|"pink"|"purple"|"deepPurple"|"indigo"|"blue"|"lightBlue"|"cyan"|"teal"|
"green"|"lightGreen"|"lime"|"yellow"|"amber"|"orange"|"deepOrange"|"brown"|"grey"|"blueGrey",
mqtt: string
};
declare type Internal = string;
declare type Actual = any;
declare type StateValue = {