summaryrefslogtreecommitdiff
path: root/src/client/scripts/hpml/block.ts
blob: 804c5c1124c036e476403650a9ee8a4e1a64dc51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// blocks

export type BlockBase = {
	id: string;
	type: string;
};

export type TextBlock = BlockBase & {
	type: 'text';
	text: string;
};

export type SectionBlock = BlockBase & {
	type: 'section';
	title: string;
	children: (Block | VarBlock)[];
};

export type ImageBlock = BlockBase & {
	type: 'image';
	fileId: string | null;
};

export type ButtonBlock = BlockBase & {
	type: 'button';
	text: any;
	primary: boolean;
	action: string;
	content: string;
	event: string;
	message: string;
	var: string;
	fn: string;
};

export type IfBlock = BlockBase & {
	type: 'if';
	var: string;
	children: Block[];
};

export type TextareaBlock = BlockBase & {
	type: 'textarea';
	text: string;
};

export type PostBlock = BlockBase & {
	type: 'post';
	text: string;
	attachCanvasImage: boolean;
	canvasId: string;
};

export type CanvasBlock = BlockBase & {
	type: 'canvas';
	name: string; // canvas id
	width: number;
	height: number;
};

export type NoteBlock = BlockBase & {
	type: 'note';
	detailed: boolean;
	note: string | null;
};

export type Block =
	TextBlock | SectionBlock | ImageBlock | ButtonBlock | IfBlock | TextareaBlock | PostBlock | CanvasBlock | NoteBlock | VarBlock;

// variable blocks

export type VarBlockBase = BlockBase & {
	name: string;
};

export type NumberInputVarBlock = VarBlockBase & {
	type: 'numberInput';
	text: string;
};

export type TextInputVarBlock = VarBlockBase & {
	type: 'textInput';
	text: string;
};

export type SwitchVarBlock = VarBlockBase & {
	type: 'switch';
	text: string;
};

export type RadioButtonVarBlock = VarBlockBase & {
	type: 'radioButton';
	title: string;
	values: string[];
};

export type CounterVarBlock = VarBlockBase & {
	type: 'counter';
	text: string;
	inc: number;
};

export type VarBlock =
	NumberInputVarBlock | TextInputVarBlock | SwitchVarBlock | RadioButtonVarBlock | CounterVarBlock;

const varBlock = ['numberInput', 'textInput', 'switch', 'radioButton', 'counter'];
export function isVarBlock(block: Block): block is VarBlock {
	return varBlock.includes(block.type);
}