-
Notifications
You must be signed in to change notification settings - Fork 0
/
Expressions.ts
74 lines (67 loc) · 2.2 KB
/
Expressions.ts
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
import type { Operators, Operands } from '../types';
type Condition = `${string} ${Operators} ${string}`;
type ComparisonOperation = {operator: Operators, operands: [Operands, Operands]};
export class Expressions {
static If(
condition: Condition,
trueValue: string,
falseValue: string,
/**Set this to true if your `if` is not at the beginning of the expression (string). */
removeEq = false
): string {
return `=if(${condition}, ${trueValue}, ${falseValue}`.replace('=', removeEq ? '' : '=');
}
static And(...operands: Operands[]): [Operators, Operands] {
return ["&&", operands];
}
static Or(...operands: Operands[]): [Operators, Operands] {
return ["||", operands];
}
static Equals(leftOperand: Operands, rightOperand: Operands): ComparisonOperation {
return {
operator: "==",
operands: [leftOperand, rightOperand]
};
}
static NotEquals(leftOperand: Operands, rightOperand: Operands): ComparisonOperation {
return {
operator: "!=",
operands: [leftOperand, rightOperand]
};
}
}
export const FIELD_HELPERS = {
CURRENT_FIELD: "@currentField",
ME: "@me",
FIELD: (name: string) => `\$[${name}]` as const,
CURRENT_WEB: "@currentWeb",
NOW: "@now",
ROW_IDX: "@rowIndex",
WIN_HEIGHT: "@window.innerHeight",
WIN_WIDTH: "@window.innerWidth",
THUMBNAILS: {
SMALL: "@thumbnails.small",
MEDIUM: "@thumbnails.medium",
LARGE: "@thumbnails.large",
SIZE: (size: number) => `@thumbnails.${size}` as const,
SIZE_WH: (width: number, height: number) => `@thumbnails.${width}x${height}` as const
},
IS_SELECTED: "@isSelected",
LCID: "@lcid",
UILCID: "@UIlcid"
} as const;
/*
Proposal state machine for the new expression builder:
function function createStateMachine<States extends string, TagIds extends string>(
events: {
for: [States, TagIds, FormatterOptions][],
transitions: Array<{
from: States,
to: States,
when: {
operator: Operators,
operands: Operands
}
}>
}
)*/