dazscript-framework 0.1.14 → 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.
Files changed (82) hide show
  1. package/README.md +365 -93
  2. package/babel.config.js +33 -33
  3. package/dist/babel/trace-babel-plugin.js +243 -243
  4. package/dist/babel/trace-log-babel-plugin.js +164 -164
  5. package/dist/scripts/install-generator.js +185 -185
  6. package/package.json +72 -70
  7. package/src/common/dz-dump.ts +120 -120
  8. package/src/common/log.ts +56 -57
  9. package/src/common/trace.ts +26 -26
  10. package/src/core/action-decorator.ts +15 -15
  11. package/src/core/base-script.ts +30 -30
  12. package/src/core/custom-action.ts +11 -11
  13. package/src/core/global.ts +4 -4
  14. package/src/dialog/basic-dialog.ts +40 -32
  15. package/src/dialog/builders/button-builder.ts +52 -52
  16. package/src/dialog/builders/checkbox-builder.ts +29 -29
  17. package/src/dialog/builders/color-picker-builder.ts +36 -0
  18. package/src/dialog/builders/combo-box-builder.ts +38 -35
  19. package/src/dialog/builders/combo-edit-builder.ts +35 -35
  20. package/src/dialog/builders/dialog-builder.ts +49 -49
  21. package/src/dialog/builders/groupbox-builder.ts +121 -73
  22. package/src/dialog/builders/label-builder.ts +33 -29
  23. package/src/dialog/builders/layout-builder.ts +59 -59
  24. package/src/dialog/builders/line-edit-builder.ts +124 -119
  25. package/src/dialog/builders/list-box-builder.ts +103 -0
  26. package/src/dialog/builders/list-view-builder.ts +396 -328
  27. package/src/dialog/builders/node-selection-builder.ts +55 -55
  28. package/src/dialog/builders/path-combo-box-builder.ts +24 -24
  29. package/src/dialog/builders/popup-menu-builder.ts +46 -46
  30. package/src/dialog/builders/radio-builder.ts +42 -42
  31. package/src/dialog/builders/slider-builder.ts +40 -0
  32. package/src/dialog/builders/splitter-builder.ts +88 -88
  33. package/src/dialog/builders/tab-builder.ts +120 -106
  34. package/src/dialog/builders/widget-builder.ts +136 -124
  35. package/src/dialog/builders/widgets-builder.ts +140 -125
  36. package/src/dialog/input-dialog.ts +30 -27
  37. package/src/dialog/input-validator.ts +8 -8
  38. package/src/dialog/selection-dialog.ts +47 -0
  39. package/src/dialog/shared.ts +8 -8
  40. package/src/helpers/action-helper.ts +214 -81
  41. package/src/helpers/array-helper.ts +170 -145
  42. package/src/helpers/camera-helper.ts +12 -12
  43. package/src/helpers/custom-action-helper.ts +176 -176
  44. package/src/helpers/directory-helper.ts +14 -0
  45. package/src/helpers/file-helper.ts +90 -90
  46. package/src/helpers/http-helper.ts +186 -0
  47. package/src/helpers/input-helper.ts +18 -18
  48. package/src/helpers/list-view-helper.ts +105 -89
  49. package/src/helpers/menu-helper.ts +28 -28
  50. package/src/helpers/message-box-helper.ts +25 -15
  51. package/src/helpers/node-helper.ts +461 -236
  52. package/src/helpers/number-helper.ts +10 -10
  53. package/src/helpers/numeric-property-helper.ts +91 -91
  54. package/src/helpers/object-helper.ts +2 -2
  55. package/src/helpers/pane-helper.ts +28 -20
  56. package/src/helpers/progress-helper.ts +51 -33
  57. package/src/helpers/property-helper.ts +61 -52
  58. package/src/helpers/record-helper.ts +16 -16
  59. package/src/helpers/scene-helper.ts +144 -95
  60. package/src/helpers/script-helper.ts +15 -15
  61. package/src/helpers/skeleton-helper.ts +26 -26
  62. package/src/helpers/splitter-helper.ts +8 -8
  63. package/src/helpers/string-helper.ts +39 -31
  64. package/src/helpers/surface-helper.ts +5 -5
  65. package/src/helpers/undo-helper.ts +8 -7
  66. package/src/helpers/viewport-helper.ts +21 -8
  67. package/src/lib/delayed.ts +38 -38
  68. package/src/lib/dictionary.ts +3 -0
  69. package/src/lib/frame-keys.ts +67 -67
  70. package/src/lib/guid.ts +2 -2
  71. package/src/lib/menu-item.ts +10 -9
  72. package/src/lib/observable.ts +147 -94
  73. package/src/lib/set.ts +50 -25
  74. package/src/lib/settings.ts +112 -104
  75. package/src/lib/tree-node.ts +149 -145
  76. package/src/samples/config.ts +2 -2
  77. package/src/samples/hello-world.dsa.ts +12 -12
  78. package/src/samples/sample-dialog.dsa.ts +51 -51
  79. package/src/samples/sample-dialog.ts +48 -48
  80. package/src/shared/set-keyboard-shortcut.ts +146 -102
  81. package/tsconfig.json +116 -116
  82. package/webpack.config.js +70 -70
@@ -1,29 +1,33 @@
1
- import { AlignmentFlags } from '@dst/common/alignmentFlags';
2
- import { WidgetBuilderBase, createWidget } from './widget-builder';
3
- import { WidgetBuilderContext } from './widgets-builder';
4
-
5
- export default class LabelBuilder extends WidgetBuilderBase<DzLabel> {
6
- constructor(context: WidgetBuilderContext) {
7
- super(createWidget(context).build(DzLabel));
8
-
9
- }
10
-
11
- text(text: string): this {
12
- this.widget.text = text;
13
- return this;
14
- }
15
-
16
- minWidth(width: number): this {
17
- this.widget.minWidth = width
18
- return this;
19
- }
20
-
21
- align(alignment: AlignmentFlags): this {
22
- this.widget.alignment = alignment
23
- return this;
24
- }
25
-
26
- build(): DzLabel {
27
- return this.widget;
28
- }
29
- }
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
- placeholder(text: string): this {
16
- this.widget.placeholderText = text
17
- return this
18
- }
19
-
20
- focus(): this {
21
- this.widget.getWidget().setFocus()
22
- return this
23
- }
24
-
25
- validator(validator: InputValidator | null): this {
26
- if (validator === null) return this
27
- this.inputValidator = validator
28
- let settings = new DzSettings()
29
- settings.setStringValue("validator", InputValidator[validator]);
30
- this.widget.setValidator(settings)
31
- return this
32
- }
33
-
34
- /**
35
- * Sets the min value of the input when validator is set to in or float
36
- * @param minValue
37
- * @returns
38
- */
39
- min(minValue: number): this {
40
- this.minValue = minValue
41
- return this
42
- }
43
-
44
- /**
45
- * Sets the max value of the input when validator is set to in or float
46
- * @param maxValue
47
- * @returns
48
- */
49
- max(maxValue: number): this {
50
- this.maxValue = maxValue
51
- return this
52
- }
53
-
54
- /**
55
- * Clamps the input to min and max values. Only works when validator is set to int or float
56
- * @param min
57
- * @param max
58
- * @returns
59
- */
60
- clamp(min: number, max: number): this {
61
- return this.min(min).max(max)
62
- }
63
-
64
- readOnly(onOff?: Observable<boolean> | null): this {
65
- if (onOff == null) {
66
- this.widget.readOnly = true
67
- return this
68
- }
69
- else {
70
- this.widget.readOnly = onOff.value
71
- onOff.connect((value) => {
72
- this.widget.readOnly = value
73
- })
74
- }
75
- return this
76
- }
77
-
78
- value(text_: string | Observable<string>): this {
79
- if (typeof text_ === 'string') {
80
- this.widget.text = text_
81
- }
82
- else if (text_ instanceof Observable) {
83
- this.widget.text = text_.value;
84
- this.widget.textChanged.scriptConnect((text: string) => {
85
- text_.value = this.clampValue(text);
86
- });
87
- text_.connect((text: string) => {
88
- this.widget.text = text;
89
- });
90
- }
91
-
92
- return this;
93
- }
94
-
95
- private clampValue(text: string): string {
96
- if (this.inputValidator === InputValidator.int || this.inputValidator === InputValidator.float) {
97
- let value = Number(text);
98
- if (!isNaN(value)) {
99
- if (this.minValue !== undefined) {
100
- value = Math.max(value, this.minValue);
101
- }
102
- if (this.maxValue !== undefined) {
103
- value = Math.min(value, this.maxValue);
104
- }
105
- return String(value);
106
- }
107
- }
108
- else if (this.maxValue && text.length > this.maxValue)
109
- text = text[this.maxValue]
110
-
111
- return text;
112
- }
113
-
114
-
115
- build(then?: (lineEdit: DzLineEdit) => void): DzLineEdit {
116
- then?.(this.widget);
117
- return this.widget;
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
+ }
@@ -0,0 +1,103 @@
1
+ import { Dictionary } from '@dsf/lib/dictionary';
2
+ import { Observable } from '@dsf/lib/observable';
3
+ import { createWidget, WidgetBuilderBase } from './widget-builder';
4
+ import { WidgetBuilderContext } from './widgets-builder';
5
+
6
+ export class ListBoxBuilder extends WidgetBuilderBase<DzListBox> {
7
+ private _items: Dictionary<number, string> | null = null
8
+ private _mode: 'single' | 'multi' | 'extended' = 'single'
9
+
10
+ constructor(context: WidgetBuilderContext) {
11
+ super(createWidget(context).build(DzListBox))
12
+ }
13
+
14
+ items(items$: string[] | Observable<string[]>): this {
15
+ this.widget.clear()
16
+ if (items$ instanceof Observable) {
17
+ this._items = {}
18
+ items$.value.forEach((item, idx) => {
19
+ this._items[idx] = item
20
+ })
21
+
22
+ const setItems = (items: string[]) => {
23
+ this.widget.clear()
24
+ items.forEach((item, idx) => {
25
+ this.widget.insertItem(item)
26
+ })
27
+ }
28
+
29
+ setItems(items$.value)
30
+ items$.connect(value => {
31
+ this.widget.clear()
32
+ setItems(value)
33
+ })
34
+ }
35
+ else {
36
+ this._items = {}
37
+ items$.forEach((item, idx) => {
38
+ this._items[idx] = item
39
+ this.widget.insertItem(item)
40
+ })
41
+ }
42
+
43
+ return this
44
+ }
45
+
46
+ mode(mode: 'single' | 'multi' | 'extended'): this {
47
+ this._mode = mode
48
+ switch (mode) {
49
+ case 'single':
50
+ this.widget.selectionMode = DzListBox.Single
51
+ break
52
+ case 'multi':
53
+ this.widget.selectionMode = DzListBox.Multi
54
+ break
55
+ case 'extended':
56
+ this.widget.selectionMode = DzListBox.Extended
57
+ break
58
+ }
59
+ return this
60
+ }
61
+
62
+ selected(selected$: Observable<string[]>): this {
63
+ const setSelected = (selected: string[] | null) => {
64
+ this.widget.clearSelection()
65
+ if (selected$.value?.length > 0 && this._items) {
66
+ selected.forEach(sel => {
67
+ const idx = Object.keys(this._items)
68
+ .map(key => this._items[Number(key)])
69
+ .indexOf(sel)
70
+ if (idx >= 0) {
71
+ this.widget.setSelected(idx, true)
72
+ }
73
+ })
74
+ }
75
+ }
76
+
77
+ this.widget.currentChanged.scriptConnect((idx) => {
78
+ if (!selected$ || !this._items) return
79
+ if (this._mode === 'single') {
80
+ const item = this._items[idx]
81
+ selected$.value = item ? [item] : []
82
+ }
83
+ else {
84
+ selected$.value = Object.keys(this._items)
85
+ .map(key => this.widget.isSelected(Number(key)) ? this._items[Number(key)] : null)
86
+ .filter((item): item is string => item !== null)
87
+ }
88
+ })
89
+
90
+ if (selected$.value?.length === 0) {
91
+ return this
92
+ }
93
+
94
+ setSelected(selected$.value)
95
+
96
+ return this
97
+ }
98
+
99
+ build(then?: (listBox: DzListBox) => void) {
100
+ then?.(this.widget)
101
+ return this.widget
102
+ }
103
+ }