/
StringColumnBuilder.ts
55 lines (49 loc) · 1.37 KB
/
StringColumnBuilder.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
import type { EAlignment, ILinkColumnDesc } from '../../model';
import ColumnBuilder from './ColumnBuilder';
export default class StringColumnBuilder extends ColumnBuilder<ILinkColumnDesc> {
constructor(column: string) {
super('string', column);
}
/**
* makes the text editable within a cell and switches to the annotate type
*/
editable() {
this.desc.type = 'annotate';
return this;
}
/**
* changes the alignment of the column
*/
alignment(align: EAlignment) {
this.desc.alignment = align;
return this;
}
/**
* allow html text as values
*/
html() {
this.desc.escape = false;
return this;
}
/**
* provide a pattern with which the value will be wrapped, use `${value}` for the current and and `${item}` for the whole item
* @param {string} pattern pattern to apply
* @param {string[]} templates optional templates for patterns to provide in the edit pattern dialog
*/
pattern(pattern: string, templates?: string[]) {
this.desc.type = 'link';
this.desc.pattern = pattern;
if (templates) {
this.desc.patternTemplates = templates;
}
return this;
}
}
/**
* builds a string column builder
* @param {string} column column which contains the associated data
* @returns {StringColumnBuilder}
*/
export function buildStringColumn(column: string) {
return new StringColumnBuilder(column);
}