dazscript-framework 0.1.15 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +365 -93
- package/babel.config.js +33 -33
- package/dist/babel/trace-babel-plugin.js +243 -243
- package/dist/babel/trace-log-babel-plugin.js +164 -164
- package/dist/scripts/install-generator.js +185 -185
- package/package.json +72 -70
- package/src/common/dz-dump.ts +120 -120
- package/src/common/log.ts +56 -56
- package/src/common/trace.ts +26 -26
- package/src/core/action-decorator.ts +15 -15
- package/src/core/base-script.ts +30 -30
- package/src/core/custom-action.ts +11 -11
- package/src/core/global.ts +4 -4
- package/src/dialog/basic-dialog.ts +40 -32
- package/src/dialog/builders/button-builder.ts +52 -52
- package/src/dialog/builders/checkbox-builder.ts +29 -29
- package/src/dialog/builders/color-picker-builder.ts +35 -35
- package/src/dialog/builders/combo-box-builder.ts +38 -35
- package/src/dialog/builders/combo-edit-builder.ts +35 -35
- package/src/dialog/builders/dialog-builder.ts +49 -49
- package/src/dialog/builders/groupbox-builder.ts +121 -82
- package/src/dialog/builders/label-builder.ts +33 -28
- package/src/dialog/builders/layout-builder.ts +59 -59
- package/src/dialog/builders/line-edit-builder.ts +124 -119
- package/src/dialog/builders/list-box-builder.ts +103 -0
- package/src/dialog/builders/list-view-builder.ts +396 -328
- package/src/dialog/builders/node-selection-builder.ts +55 -55
- package/src/dialog/builders/path-combo-box-builder.ts +24 -24
- package/src/dialog/builders/popup-menu-builder.ts +46 -46
- package/src/dialog/builders/radio-builder.ts +42 -42
- package/src/dialog/builders/slider-builder.ts +39 -22
- package/src/dialog/builders/splitter-builder.ts +88 -88
- package/src/dialog/builders/tab-builder.ts +120 -106
- package/src/dialog/builders/widget-builder.ts +136 -124
- package/src/dialog/builders/widgets-builder.ts +140 -135
- package/src/dialog/input-dialog.ts +30 -27
- package/src/dialog/input-validator.ts +8 -8
- package/src/dialog/selection-dialog.ts +47 -0
- package/src/dialog/shared.ts +8 -8
- package/src/helpers/action-helper.ts +214 -81
- package/src/helpers/array-helper.ts +170 -145
- package/src/helpers/camera-helper.ts +12 -12
- package/src/helpers/custom-action-helper.ts +176 -176
- package/src/helpers/directory-helper.ts +14 -0
- package/src/helpers/file-helper.ts +90 -90
- package/src/helpers/http-helper.ts +186 -0
- package/src/helpers/input-helper.ts +18 -18
- package/src/helpers/list-view-helper.ts +105 -89
- package/src/helpers/menu-helper.ts +28 -28
- package/src/helpers/message-box-helper.ts +25 -15
- package/src/helpers/node-helper.ts +461 -236
- package/src/helpers/number-helper.ts +10 -10
- package/src/helpers/numeric-property-helper.ts +91 -91
- package/src/helpers/object-helper.ts +2 -2
- package/src/helpers/pane-helper.ts +28 -20
- package/src/helpers/progress-helper.ts +51 -33
- package/src/helpers/property-helper.ts +61 -52
- package/src/helpers/record-helper.ts +16 -16
- package/src/helpers/scene-helper.ts +144 -94
- package/src/helpers/script-helper.ts +15 -15
- package/src/helpers/skeleton-helper.ts +26 -26
- package/src/helpers/splitter-helper.ts +8 -8
- package/src/helpers/string-helper.ts +39 -31
- package/src/helpers/surface-helper.ts +5 -5
- package/src/helpers/undo-helper.ts +8 -8
- package/src/helpers/viewport-helper.ts +21 -8
- package/src/lib/delayed.ts +38 -38
- package/src/lib/dictionary.ts +3 -0
- package/src/lib/frame-keys.ts +67 -67
- package/src/lib/guid.ts +2 -2
- package/src/lib/menu-item.ts +10 -9
- package/src/lib/observable.ts +147 -94
- package/src/lib/set.ts +50 -25
- package/src/lib/settings.ts +112 -104
- package/src/lib/tree-node.ts +149 -145
- package/src/samples/config.ts +2 -2
- package/src/samples/hello-world.dsa.ts +12 -12
- package/src/samples/sample-dialog.dsa.ts +51 -51
- package/src/samples/sample-dialog.ts +48 -48
- package/src/shared/set-keyboard-shortcut.ts +146 -102
- package/tsconfig.json +116 -116
- package/webpack.config.js +70 -70
|
@@ -1,82 +1,121 @@
|
|
|
1
|
-
import { Observable } from '@dsf/lib/observable';
|
|
2
|
-
import { Direction } from '../shared';
|
|
3
|
-
import LayoutBuilder from './layout-builder';
|
|
4
|
-
import { IWidgetBuilder, createWidget } from './widget-builder';
|
|
5
|
-
import { WidgetBuilderContext } from './widgets-builder';
|
|
6
|
-
|
|
7
|
-
export default class GroupBoxBuilder implements IWidgetBuilder<DzGroupBox> {
|
|
8
|
-
private _title: Observable<string>
|
|
9
|
-
private _direction: Direction = 'vertical'
|
|
10
|
-
private _style: { flat?: boolean }
|
|
11
|
-
private _visible: Observable<boolean>
|
|
12
|
-
private
|
|
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
|
-
|
|
1
|
+
import { Observable } from '@dsf/lib/observable';
|
|
2
|
+
import { Direction } from '../shared';
|
|
3
|
+
import LayoutBuilder from './layout-builder';
|
|
4
|
+
import { IWidgetBuilder, createWidget } from './widget-builder';
|
|
5
|
+
import { WidgetBuilderContext } from './widgets-builder';
|
|
6
|
+
|
|
7
|
+
export default class GroupBoxBuilder implements IWidgetBuilder<DzGroupBox> {
|
|
8
|
+
private _title: Observable<string>
|
|
9
|
+
private _direction: Direction = 'vertical'
|
|
10
|
+
private _style: { flat?: boolean }
|
|
11
|
+
private _visible: Observable<boolean>
|
|
12
|
+
private _enabled: Observable<boolean>
|
|
13
|
+
private _columns: number = 1
|
|
14
|
+
private _height: number | null = null
|
|
15
|
+
private _minHeight: number | null = null
|
|
16
|
+
|
|
17
|
+
constructor(private context: WidgetBuilderContext) {
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
title(text: string | Observable<string>): this {
|
|
21
|
+
this._title = typeof text === 'string'
|
|
22
|
+
? new Observable(text)
|
|
23
|
+
: text
|
|
24
|
+
return this
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
vertical(): this {
|
|
28
|
+
this._direction = 'vertical'
|
|
29
|
+
return this
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
horizontal(): this {
|
|
33
|
+
this._direction = 'horizontal'
|
|
34
|
+
return this
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
orientation(direction: Direction): this {
|
|
38
|
+
this._direction = direction
|
|
39
|
+
return this
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
style(options: { flat?: boolean }): this {
|
|
43
|
+
this._style = options
|
|
44
|
+
return this
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
flat(): this {
|
|
48
|
+
this._style = { flat: true }
|
|
49
|
+
return this
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
visible(value: boolean | Observable<boolean>): this {
|
|
53
|
+
this._visible = typeof value === 'boolean'
|
|
54
|
+
? new Observable(value)
|
|
55
|
+
: value
|
|
56
|
+
return this
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
enabled(value: boolean | Observable<boolean>): this {
|
|
60
|
+
this._enabled = typeof value === 'boolean'
|
|
61
|
+
? new Observable(value)
|
|
62
|
+
: value
|
|
63
|
+
return this
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
height(value: number): this {
|
|
67
|
+
this._height = value
|
|
68
|
+
return this
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
minHeight(value: number): this {
|
|
72
|
+
this._minHeight = value
|
|
73
|
+
return this
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
columns(value: number): this {
|
|
77
|
+
this._columns = value
|
|
78
|
+
return this
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
build(then?: (layout: DzVBoxLayout | DzHBoxLayout, groupBox: DzGroupBox) => void): DzGroupBox {
|
|
82
|
+
let groupBox = createWidget(this.context).build(DzGroupBox)
|
|
83
|
+
|
|
84
|
+
groupBox.title = this._title?.value
|
|
85
|
+
groupBox.flat = this._style?.flat
|
|
86
|
+
groupBox.columns = this._columns
|
|
87
|
+
if (this._height !== null) groupBox.height = this._height
|
|
88
|
+
if (this._minHeight !== null) groupBox.minHeight = this._minHeight
|
|
89
|
+
|
|
90
|
+
this._title?.connect((text) => {
|
|
91
|
+
groupBox.title = text
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
new LayoutBuilder(this.context)
|
|
95
|
+
.parent(groupBox)
|
|
96
|
+
.direction(this._direction)
|
|
97
|
+
.build((layout) => {
|
|
98
|
+
then?.(layout, groupBox)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
if (this._visible) {
|
|
102
|
+
if (this._visible.value === false)
|
|
103
|
+
groupBox.hide()
|
|
104
|
+
this._visible.connect((visible) => {
|
|
105
|
+
if (visible)
|
|
106
|
+
groupBox.show()
|
|
107
|
+
else
|
|
108
|
+
groupBox.hide()
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (this._enabled) {
|
|
113
|
+
groupBox.enabled = this._enabled.value
|
|
114
|
+
this._enabled.connect((enabled) => {
|
|
115
|
+
groupBox.enabled = enabled
|
|
116
|
+
})
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return groupBox
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -1,28 +1,33 @@
|
|
|
1
|
-
import { WidgetBuilderBase, createWidget } from './widget-builder';
|
|
2
|
-
import { WidgetBuilderContext } from './widgets-builder';
|
|
3
|
-
|
|
4
|
-
export default class LabelBuilder extends WidgetBuilderBase<DzLabel> {
|
|
5
|
-
constructor(context: WidgetBuilderContext) {
|
|
6
|
-
super(createWidget(context).build(DzLabel));
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
text(text: string): this {
|
|
11
|
-
this.widget.text = text;
|
|
12
|
-
return this;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this.widget.
|
|
17
|
-
return this
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this.widget.
|
|
22
|
-
return this;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
1
|
+
import { WidgetBuilderBase, createWidget } from './widget-builder';
|
|
2
|
+
import { WidgetBuilderContext } from './widgets-builder';
|
|
3
|
+
|
|
4
|
+
export default class LabelBuilder extends WidgetBuilderBase<DzLabel> {
|
|
5
|
+
constructor(context: WidgetBuilderContext) {
|
|
6
|
+
super(createWidget(context).build(DzLabel));
|
|
7
|
+
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
text(text: string): this {
|
|
11
|
+
this.widget.text = text;
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
wordWrap(enabled: boolean = true): this {
|
|
16
|
+
this.widget.wordWrap = enabled
|
|
17
|
+
return this
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
minWidth(width: number): this {
|
|
21
|
+
this.widget.minWidth = width
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
align(alignment: AlignmentFlags): this {
|
|
26
|
+
this.widget.alignment = alignment
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
build(): DzLabel {
|
|
31
|
+
return this.widget;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
import { Direction } from '@dsf/dialog/shared';
|
|
2
|
-
import { WidgetBuilderContext } from './widgets-builder';
|
|
3
|
-
|
|
4
|
-
export enum LayoutOrientation {
|
|
5
|
-
LeftToRight = 0,
|
|
6
|
-
RightToLeft = 1,
|
|
7
|
-
TopToBottom = 2,
|
|
8
|
-
BottomToTop = 3
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default class LayoutBuilder {
|
|
12
|
-
private widgetParent: DzWidget | DzLayout | null;
|
|
13
|
-
private _direction: Direction = 'vertical';
|
|
14
|
-
private _orientation?: LayoutOrientation;
|
|
15
|
-
|
|
16
|
-
constructor(protected context: WidgetBuilderContext) { }
|
|
17
|
-
|
|
18
|
-
static create(context: WidgetBuilderContext): LayoutBuilder {
|
|
19
|
-
return new LayoutBuilder(context)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
orientation(orientation: LayoutOrientation): this {
|
|
23
|
-
this._orientation = orientation;
|
|
24
|
-
return this
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
direction(direction: Direction): this {
|
|
28
|
-
this._direction = direction;
|
|
29
|
-
return this;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
parent(parent: DzWidget | DzLayout): this {
|
|
33
|
-
this.widgetParent = parent;
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
build(then?: (layout: DzVBoxLayout | DzHBoxLayout) => void): DzVBoxLayout | DzHBoxLayout {
|
|
38
|
-
let parent = this.widgetParent ?? this.context.parent;
|
|
39
|
-
let type = this.getLayoutFor(this._direction);
|
|
40
|
-
let layout = new type(parent);
|
|
41
|
-
if (this._orientation) layout.direction = this._orientation;
|
|
42
|
-
|
|
43
|
-
let currentLayout = this.context.layout;
|
|
44
|
-
this.context.layout = layout;
|
|
45
|
-
|
|
46
|
-
if (parent.inherits("DzWidget") && (parent as any).addLayout)
|
|
47
|
-
(parent as DzBasicDialog).addLayout(layout);
|
|
48
|
-
|
|
49
|
-
then?.(layout);
|
|
50
|
-
|
|
51
|
-
this.context.layout = currentLayout;
|
|
52
|
-
return layout;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
private getLayoutFor(direction: string): new (arg: any) => DzVBoxLayout | DzHBoxLayout {
|
|
56
|
-
return direction === 'horizontal' ? DzHBoxLayout : DzVBoxLayout;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
1
|
+
import { Direction } from '@dsf/dialog/shared';
|
|
2
|
+
import { WidgetBuilderContext } from './widgets-builder';
|
|
3
|
+
|
|
4
|
+
export enum LayoutOrientation {
|
|
5
|
+
LeftToRight = 0,
|
|
6
|
+
RightToLeft = 1,
|
|
7
|
+
TopToBottom = 2,
|
|
8
|
+
BottomToTop = 3
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default class LayoutBuilder {
|
|
12
|
+
private widgetParent: DzWidget | DzLayout | null;
|
|
13
|
+
private _direction: Direction = 'vertical';
|
|
14
|
+
private _orientation?: LayoutOrientation;
|
|
15
|
+
|
|
16
|
+
constructor(protected context: WidgetBuilderContext) { }
|
|
17
|
+
|
|
18
|
+
static create(context: WidgetBuilderContext): LayoutBuilder {
|
|
19
|
+
return new LayoutBuilder(context)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
orientation(orientation: LayoutOrientation): this {
|
|
23
|
+
this._orientation = orientation;
|
|
24
|
+
return this
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
direction(direction: Direction): this {
|
|
28
|
+
this._direction = direction;
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
parent(parent: DzWidget | DzLayout): this {
|
|
33
|
+
this.widgetParent = parent;
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
build(then?: (layout: DzVBoxLayout | DzHBoxLayout) => void): DzVBoxLayout | DzHBoxLayout {
|
|
38
|
+
let parent = this.widgetParent ?? this.context.parent;
|
|
39
|
+
let type = this.getLayoutFor(this._direction);
|
|
40
|
+
let layout = new type(parent);
|
|
41
|
+
if (this._orientation) layout.direction = this._orientation;
|
|
42
|
+
|
|
43
|
+
let currentLayout = this.context.layout;
|
|
44
|
+
this.context.layout = layout;
|
|
45
|
+
|
|
46
|
+
if (parent.inherits("DzWidget") && (parent as any).addLayout)
|
|
47
|
+
(parent as DzBasicDialog).addLayout(layout);
|
|
48
|
+
|
|
49
|
+
then?.(layout);
|
|
50
|
+
|
|
51
|
+
this.context.layout = currentLayout;
|
|
52
|
+
return layout;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private getLayoutFor(direction: string): new (arg: any) => DzVBoxLayout | DzHBoxLayout {
|
|
56
|
+
return direction === 'horizontal' ? DzHBoxLayout : DzVBoxLayout;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
@@ -1,119 +1,124 @@
|
|
|
1
|
-
import { Observable } from '@dsf/lib/observable';
|
|
2
|
-
import { InputValidator } from '../input-validator';
|
|
3
|
-
import { WidgetBuilderBase, createWidget } from './widget-builder';
|
|
4
|
-
import { WidgetBuilderContext } from './widgets-builder';
|
|
5
|
-
|
|
6
|
-
export default class LineEditBuilder extends WidgetBuilderBase<DzLineEdit> {
|
|
7
|
-
private inputValidator: InputValidator
|
|
8
|
-
private minValue?: number
|
|
9
|
-
private maxValue?: number
|
|
10
|
-
|
|
11
|
-
constructor(context: WidgetBuilderContext) {
|
|
12
|
-
super(createWidget(context).build(DzLineEdit))
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this.widget.
|
|
17
|
-
return this
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this.widget.
|
|
22
|
-
return this
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return this
|
|
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
|
-
|
|
1
|
+
import { Observable } from '@dsf/lib/observable';
|
|
2
|
+
import { InputValidator } from '../input-validator';
|
|
3
|
+
import { WidgetBuilderBase, createWidget } from './widget-builder';
|
|
4
|
+
import { WidgetBuilderContext } from './widgets-builder';
|
|
5
|
+
|
|
6
|
+
export default class LineEditBuilder extends WidgetBuilderBase<DzLineEdit> {
|
|
7
|
+
private inputValidator: InputValidator
|
|
8
|
+
private minValue?: number
|
|
9
|
+
private maxValue?: number
|
|
10
|
+
|
|
11
|
+
constructor(context: WidgetBuilderContext) {
|
|
12
|
+
super(createWidget(context).build(DzLineEdit))
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
password(): this {
|
|
16
|
+
this.widget.echoMode = (DzLineEdit as any).Password ?? 2
|
|
17
|
+
return this
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
placeholder(text: string): this {
|
|
21
|
+
this.widget.placeholderText = text
|
|
22
|
+
return this
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
focus(): this {
|
|
26
|
+
this.widget.getWidget().setFocus()
|
|
27
|
+
return this
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
validator(validator: InputValidator | null): this {
|
|
31
|
+
if (validator === null) return this
|
|
32
|
+
this.inputValidator = validator
|
|
33
|
+
let settings = new DzSettings()
|
|
34
|
+
settings.setStringValue("validator", InputValidator[validator]);
|
|
35
|
+
this.widget.setValidator(settings)
|
|
36
|
+
return this
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Sets the min value of the input when validator is set to in or float
|
|
41
|
+
* @param minValue
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
min(minValue: number): this {
|
|
45
|
+
this.minValue = minValue
|
|
46
|
+
return this
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Sets the max value of the input when validator is set to in or float
|
|
51
|
+
* @param maxValue
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
max(maxValue: number): this {
|
|
55
|
+
this.maxValue = maxValue
|
|
56
|
+
return this
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Clamps the input to min and max values. Only works when validator is set to int or float
|
|
61
|
+
* @param min
|
|
62
|
+
* @param max
|
|
63
|
+
* @returns
|
|
64
|
+
*/
|
|
65
|
+
clamp(min: number, max: number): this {
|
|
66
|
+
return this.min(min).max(max)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
readOnly(onOff?: Observable<boolean> | null): this {
|
|
70
|
+
if (onOff == null) {
|
|
71
|
+
this.widget.readOnly = true
|
|
72
|
+
return this
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
this.widget.readOnly = onOff.value
|
|
76
|
+
onOff.connect((value) => {
|
|
77
|
+
this.widget.readOnly = value
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
return this
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
value(text_: string | Observable<string>): this {
|
|
84
|
+
if (typeof text_ === 'string') {
|
|
85
|
+
this.widget.text = text_
|
|
86
|
+
}
|
|
87
|
+
else if (text_ instanceof Observable) {
|
|
88
|
+
this.widget.text = text_.value;
|
|
89
|
+
this.widget.textChanged.scriptConnect((text: string) => {
|
|
90
|
+
text_.value = this.clampValue(text);
|
|
91
|
+
});
|
|
92
|
+
text_.connect((text: string) => {
|
|
93
|
+
this.widget.text = text;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private clampValue(text: string): string {
|
|
101
|
+
if (this.inputValidator === InputValidator.int || this.inputValidator === InputValidator.float) {
|
|
102
|
+
let value = Number(text);
|
|
103
|
+
if (!isNaN(value)) {
|
|
104
|
+
if (this.minValue !== undefined) {
|
|
105
|
+
value = Math.max(value, this.minValue);
|
|
106
|
+
}
|
|
107
|
+
if (this.maxValue !== undefined) {
|
|
108
|
+
value = Math.min(value, this.maxValue);
|
|
109
|
+
}
|
|
110
|
+
return String(value);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else if (this.maxValue && text.length > this.maxValue)
|
|
114
|
+
text = text[this.maxValue]
|
|
115
|
+
|
|
116
|
+
return text;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
build(then?: (lineEdit: DzLineEdit) => void): DzLineEdit {
|
|
121
|
+
then?.(this.widget);
|
|
122
|
+
return this.widget;
|
|
123
|
+
}
|
|
124
|
+
}
|