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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
import { Deserializable } from '../client/util/SerializationHelper';
import { serializable, primitive } from 'serializr';
import { ObjectField } from './ObjectField';
import { Copy, ToScriptString, ToString, FieldChanged, ToJavascriptString } from './FieldSymbols';
import { scriptingGlobal, ScriptingGlobals } from '../client/util/ScriptingGlobals';
import { ColumnType } from '../client/views/collections/collectionSchema/CollectionSchemaView';
export const PastelSchemaPalette = new Map<string, string>([
// ["pink1", "#FFB4E8"],
['pink2', '#ff9cee'],
['pink3', '#ffccf9'],
['pink4', '#fcc2ff'],
['pink5', '#f6a6ff'],
['purple1', '#b28dff'],
['purple2', '#c5a3ff'],
['purple3', '#d5aaff'],
['purple4', '#ecd4ff'],
// ["purple5", "#fb34ff"],
['purple6', '#dcd3ff'],
['purple7', '#a79aff'],
['purple8', '#b5b9ff'],
['purple9', '#97a2ff'],
['bluegreen1', '#afcbff'],
['bluegreen2', '#aff8db'],
['bluegreen3', '#c4faf8'],
['bluegreen4', '#85e3ff'],
['bluegreen5', '#ace7ff'],
// ["bluegreen6", "#6eb5ff"],
['bluegreen7', '#bffcc6'],
['bluegreen8', '#dbffd6'],
['yellow1', '#f3ffe3'],
['yellow2', '#e7ffac'],
['yellow3', '#ffffd1'],
['yellow4', '#fff5ba'],
// ["red1", "#ffc9de"],
['red2', '#ffabab'],
['red3', '#ffbebc'],
['red4', '#ffcbc1'],
['orange1', '#ffd5b3'],
['gray', '#f1efeb'],
]);
export const RandomPastel = () => Array.from(PastelSchemaPalette.values())[Math.floor(Math.random() * PastelSchemaPalette.size)];
export const DarkPastelSchemaPalette = new Map<string, string>([
['pink2', '#c932b0'],
['purple4', '#913ad6'],
['bluegreen1', '#3978ed'],
['bluegreen7', '#2adb3e'],
['bluegreen5', '#21b0eb'],
['yellow4', '#edcc0c'],
['red2', '#eb3636'],
['orange1', '#f2740f'],
]);
@scriptingGlobal
@Deserializable('schemaheader')
export class SchemaHeaderField extends ObjectField {
@serializable(primitive())
heading: string;
@serializable(primitive())
color: string;
@serializable(primitive())
type: number;
@serializable(primitive())
width: number;
@serializable(primitive())
collapsed: boolean | undefined;
@serializable(primitive())
desc: boolean | undefined; // boolean determines sort order, undefined when no sort
constructor(heading: string = '', color: string = RandomPastel(), type?: ColumnType, width?: number, desc?: boolean, collapsed?: boolean) {
super();
this.heading = heading;
this.color = color;
this.type = type ? type : 0;
this.width = width ? width : -1;
this.desc = desc;
this.collapsed = collapsed;
}
setHeading(heading: string) {
this.heading = heading;
this[FieldChanged]?.();
}
setColor(color: string) {
this.color = color;
this[FieldChanged]?.();
}
setType(type: ColumnType) {
this.type = type;
this[FieldChanged]?.();
}
setWidth(width: number) {
this.width = width;
this[FieldChanged]?.();
}
setDesc(desc: boolean | undefined) {
this.desc = desc;
this[FieldChanged]?.();
}
setCollapsed(collapsed: boolean | undefined) {
this.collapsed = collapsed;
this[FieldChanged]?.();
}
[Copy]() {
return new SchemaHeaderField(this.heading, this.color, this.type, this.width, this.desc, this.collapsed);
}
[ToJavascriptString]() {
return `["${this.heading}","${this.color}",${this.type},${this.width},${this.desc},${this.collapsed}]`;
}
[ToScriptString]() {
return `schemaHeaderField("${this.heading}","${this.color}",${this.type},${this.width},${this.desc},${this.collapsed})`;
}
[ToString]() {
return `SchemaHeaderField`;
}
}
ScriptingGlobals.add(function schemaHeaderField(heading: string, color: string, type: number, width: number, desc?: boolean, collapsed?: boolean) {
return new SchemaHeaderField(heading, color, type, width, desc, collapsed);
});
|