dazscript-framework 0.1.11 → 0.1.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dazscript-framework",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "author": "Freddy Diaz",
5
5
  "license": "MPL-2.0",
6
6
  "description": "",
@@ -53,7 +53,7 @@
53
53
  "babel-plugin-transform-typescript-metadata": "^0.3.2",
54
54
  "commander": "^11.1.0",
55
55
  "cross-env": "^7.0.3",
56
- "dazscript-types": "^0.1.0",
56
+ "dazscript-types": "file:C:/src/DazScript.Framework/dazscript-types",
57
57
  "glob": "^7.2.0",
58
58
  "ts-file-parser": "^0.0.21",
59
59
  "ts-loader": "^9.5.0",
@@ -1,3 +1,4 @@
1
+ import { AlignmentFlags } from '@dst/types/common/alignmentFlags';
1
2
  import { WidgetBuilderBase, createWidget } from './widget-builder';
2
3
  import { WidgetBuilderContext } from './widgets-builder';
3
4
 
@@ -12,6 +13,16 @@ export default class LabelBuilder extends WidgetBuilderBase<DzLabel> {
12
13
  return this;
13
14
  }
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
+
15
26
  build(): DzLabel {
16
27
  return this.widget;
17
28
  }
@@ -1,9 +1,17 @@
1
1
  import { Direction } from '@dsf/dialog/shared';
2
2
  import { WidgetBuilderContext } from './widgets-builder';
3
3
 
4
+ export enum LayoutOrientation {
5
+ LeftToRight = 0,
6
+ RightToLeft = 1,
7
+ TopToBottom = 2,
8
+ BottomToTop = 3
9
+ }
10
+
4
11
  export default class LayoutBuilder {
5
12
  private widgetParent: DzWidget | DzLayout | null;
6
13
  private _direction: Direction = 'vertical';
14
+ private _orientation?: LayoutOrientation;
7
15
 
8
16
  constructor(protected context: WidgetBuilderContext) { }
9
17
 
@@ -11,6 +19,11 @@ export default class LayoutBuilder {
11
19
  return new LayoutBuilder(context)
12
20
  }
13
21
 
22
+ orientation(orientation: LayoutOrientation): this {
23
+ this._orientation = orientation;
24
+ return this
25
+ }
26
+
14
27
  direction(direction: Direction): this {
15
28
  this._direction = direction;
16
29
  return this;
@@ -25,6 +38,7 @@ export default class LayoutBuilder {
25
38
  let parent = this.widgetParent ?? this.context.parent;
26
39
  let type = this.getLayoutFor(this._direction);
27
40
  let layout = new type(parent);
41
+ if (this._orientation) layout.direction = this._orientation;
28
42
 
29
43
  let currentLayout = this.context.layout;
30
44
  this.context.layout = layout;
@@ -38,7 +52,6 @@ export default class LayoutBuilder {
38
52
  return layout;
39
53
  }
40
54
 
41
-
42
55
  private getLayoutFor(direction: string): new (arg: any) => DzVBoxLayout | DzHBoxLayout {
43
56
  return direction === 'horizontal' ? DzHBoxLayout : DzVBoxLayout;
44
57
  }
@@ -61,9 +61,10 @@ export default class LineEditBuilder extends WidgetBuilderBase<DzLineEdit> {
61
61
  return this.min(min).max(max)
62
62
  }
63
63
 
64
- readOnly(onOff: boolean | Observable<boolean>): this {
65
- if (typeof onOff === 'boolean') {
66
- this.widget.readOnly = onOff
64
+ readOnly(onOff?: Observable<boolean> | null): this {
65
+ if (onOff == null) {
66
+ this.widget.readOnly = true
67
+ return this
67
68
  }
68
69
  else {
69
70
  this.widget.readOnly = onOff.value
@@ -10,7 +10,8 @@ type ListViewFilterOptions = {
10
10
  keywords: Observable<string>,
11
11
  field: (listItem: DzListViewItem) => string,
12
12
  selectOnFilter?: boolean,
13
- filters?: (viewItem: DzListViewItem) => boolean
13
+ filters?: (viewItem: DzListViewItem) => boolean,
14
+ delay?: { min: number, max: number }
14
15
  }
15
16
 
16
17
  export enum ListViewRefreshOptions {
@@ -309,7 +310,7 @@ const build = <TItem, TData>(context: ListViewBuilderContext<TItem, TData>): DzL
309
310
  context.filter.keywords.connect((keywords) => {
310
311
  new Delayed(() => {
311
312
  filterList(keywords)
312
- }, 100, 400).trigger()
313
+ }, context.filter.delay?.min ?? 100, context.filter.delay?.max ?? 400).trigger()
313
314
  })
314
315
  }
315
316
 
@@ -0,0 +1,24 @@
1
+ import { Observable } from '@dsf/lib/observable';
2
+ import { createWidget, WidgetBuilderBase } from './widget-builder';
3
+ import { WidgetBuilderContext } from './widgets-builder';
4
+
5
+
6
+ export class PathComboBoxBuilder extends WidgetBuilderBase<DzPathComboBox> {
7
+ constructor(context: WidgetBuilderContext, checkBoxes: boolean = false) {
8
+ super(createWidget(context).withArgs([checkBoxes]).build(DzPathComboBox))
9
+ }
10
+
11
+ items(items: string[] | Observable<string[]>): this {
12
+ if (items instanceof Array) {
13
+ this.widget.setTypes(items)
14
+ }
15
+ else {
16
+ this.widget.setTypes(items.value)
17
+ items.connect((items) => {
18
+ this.widget.setTypes(items)
19
+ })
20
+ }
21
+
22
+ return this
23
+ }
24
+ }
@@ -23,6 +23,21 @@ export abstract class WidgetBuilderBase<T extends DzWidget> implements IWidgetBu
23
23
  return this
24
24
  }
25
25
 
26
+ clickFocus(): this {
27
+ this.widget.getWidget().focusPolicy = DzWidget.ClickFocus
28
+ return this
29
+ }
30
+
31
+ tabFocus(): this {
32
+ this.widget.getWidget().focusPolicy = DzWidget.TabFocus
33
+ return this
34
+ }
35
+
36
+ noFocus(): this {
37
+ this.widget.getWidget().focusPolicy = DzWidget.NoFocus
38
+ return this
39
+ }
40
+
26
41
  toolTip(toolTip: string): this {
27
42
  this.widget.toolTip = toolTip
28
43
  this.widget.whatsThis = toolTip
@@ -5,7 +5,7 @@ import { ComboBoxBuilder } from './combo-box-builder'
5
5
  import { ComboEditBuilder } from './combo-edit-builder'
6
6
  import GroupBoxBuilder from './groupbox-builder'
7
7
  import LabelBuilder from './label-builder'
8
- import LayoutBuilder from './layout-builder'
8
+ import LayoutBuilder, { LayoutOrientation } from './layout-builder'
9
9
  import LineEditBuilder from './line-edit-builder'
10
10
  import { ListViewBuilder } from './list-view-builder'
11
11
  import { NodeSelectionComboBoxBuilder } from './node-selection-builder'
@@ -36,16 +36,18 @@ export class WidgetsBuilder {
36
36
  this.splitterContext = new SplitterBuilderContext(this.context)
37
37
  }
38
38
 
39
- vertical(then?: (layout: DzVBoxLayout) => void): DzVBoxLayout {
39
+ vertical(then: (layout: DzVBoxLayout) => void, orientation: LayoutOrientation = LayoutOrientation.LeftToRight): DzVBoxLayout {
40
40
  return LayoutBuilder
41
41
  .create(this.context)
42
+ .orientation(orientation)
42
43
  .direction('vertical')
43
44
  .build(then)
44
45
  }
45
46
 
46
- horizontal(then?: (layout: DzHBoxLayout) => void): DzHBoxLayout {
47
+ horizontal(then: (layout: DzHBoxLayout) => void, orientation: LayoutOrientation = LayoutOrientation.LeftToRight): DzHBoxLayout {
47
48
  return LayoutBuilder
48
49
  .create(this.context)
50
+ .orientation(orientation)
49
51
  .direction('horizontal')
50
52
  .build(then)
51
53
  }
@@ -98,6 +100,10 @@ export class WidgetsBuilder {
98
100
  return new ComboEditBuilder(this.context)
99
101
  }
100
102
 
103
+ // pathComboBox(checkBoxes: boolean = false): PathComboBoxBuilder {
104
+ // return new PathComboBoxBuilder(this.context, checkBoxes)
105
+ // }
106
+
101
107
  /**
102
108
  *
103
109
  * @returns
@@ -143,47 +143,67 @@ export const getScales = (node: DzNode): DzFloatProperty[] => {
143
143
  return [node.getXScaleControl(), node.getYScaleControl(), node.getZScaleControl(), node.getScaleControl()];
144
144
  }
145
145
 
146
- export const getPropertiesTree = <T = DzProperty>(node: DzNode, map?: (property: DzProperty) => T, filter?: (property: DzProperty) => boolean): TreeNode<T>[] => {
147
- let items = entries(group(sceneHelper.getPropertiesOnNode(node), (p) => p.getPath())).map(x => ({ path: x[0], properties: x[1] }))
146
+ export const getPropertiesTree = <T = DzProperty>(node: DzNode, map?: (property: DzProperty) => T/*, filter?: (property: DzProperty) => boolean*/, showProgress: boolean = false): TreeNode<T>[] => {
147
+ if (showProgress) startProgress(`Collecting Properties`, 3)
148
+ let root: TreeNode<T>;
148
149
 
149
- const root = new TreeNode<T>('root', '')
150
- const pathMap: { [key: string]: TreeNode<T> } = { '': root }
150
+ // Fetch properties and group them by their path
151
+ const properties = sceneHelper.getPropertiesOnNode(node);
152
+ if (showProgress) stepProgress()
151
153
 
152
- items.forEach(element => {
153
- const paths = element.path.split('/')
154
- let currentPath = ''
154
+ const grouped = group(properties, (p) => p.getPath());
155
+ if (showProgress) stepProgress()
155
156
 
156
- paths.forEach((path, index) => {
157
- currentPath += `${index === 0 ? '' : '/'}${path}`
158
- if (!pathMap[currentPath]) {
159
- const newNode = new TreeNode<T>(path, currentPath)
160
- pathMap[currentPath] = newNode
161
-
162
- if (index !== 0) {
163
- const parentPath = currentPath.substring(0, currentPath.lastIndexOf('/'))
164
- const parentNode = pathMap[parentPath]
165
- parentNode?.addChild(newNode)
166
- newNode.parent = parentNode
167
- }
168
- }
169
- })
157
+ // Root TreeNode
158
+ root = new TreeNode<T>('root', '');
159
+ const pathMap: Record<string, TreeNode<T>> = { '': root };
170
160
 
171
- element.properties.forEach(property => {
172
- const currentNode = pathMap[property.getPath()]
173
- const newNode = new TreeNode<T>(
174
- property.getLabel(),
175
- property.getPath(),
176
- map?.(property) ?? property as T
177
- )
161
+ // Process grouped entries
162
+ const groupedEntries = entries(grouped);
163
+ if (showProgress) stepProgress()
178
164
 
179
- currentNode?.addChild(newNode)
180
- newNode.parent = currentNode
181
- })
182
- })
165
+ if (showProgress) startProgress(`Processing ${groupedEntries.length} properties`, groupedEntries.length)
166
+ for (const [path, props] of groupedEntries) {
167
+ const paths = path.split('/');
168
+ let currentPath = '';
183
169
 
184
- const rootChildren = pathMap[''].children
185
- return rootChildren && rootChildren.length > 0 ? rootChildren : root.children
186
- }
170
+ // Create nodes for the path hierarchy
171
+ for (let i = 0; i < paths.length; i++) {
172
+ currentPath = paths.slice(0, i + 1).join('/');
173
+ if (!pathMap[currentPath]) {
174
+ const newNode = new TreeNode<T>(paths[i], currentPath);
175
+ pathMap[currentPath] = newNode;
176
+
177
+ if (i > 0) {
178
+ const parentPath = paths.slice(0, i).join('/');
179
+ const parentNode = pathMap[parentPath];
180
+ parentNode?.addChild(newNode);
181
+ newNode.parent = parentNode;
182
+ }
183
+ }
184
+ }
185
+
186
+ // Add property nodes to the current path
187
+ const currentNode = pathMap[path];
188
+ if (currentNode) {
189
+ for (const property of props) {
190
+ const newNode = new TreeNode<T>(
191
+ property.getLabel(),
192
+ property.getPath(),
193
+ map?.(property) ?? (property as T)
194
+ );
195
+ currentNode.addChild(newNode);
196
+ newNode.parent = currentNode;
197
+ }
198
+ }
199
+ if (showProgress) stepProgress()
200
+ }
201
+ if (showProgress) finishProgress()
202
+ if (showProgress) finishProgress()
203
+
204
+ // Return root children or an empty array if none exist
205
+ return root.children.length > 0 ? root.children : [];
206
+ };
187
207
 
188
208
  export const getPropertiesPathsTree = (node: DzNode): TreeNode<string>[] => {
189
209
  let items = entries(group(sceneHelper.getPropertiesOnNode(node), (p) => p.getPath())).map(x => ({ path: x[0], properties: x[1] }))
@@ -18,6 +18,10 @@ export const remove = (source: string, search: string): string => {
18
18
  return source.replace(search, "")
19
19
  }
20
20
 
21
+ export const trimEnd = (source: string, search: string): string => {
22
+ return source.endsWith(search) ? source.slice(0, -search.length) : source
23
+ }
24
+
21
25
  export const count = (source: string, search: string): number => {
22
26
  return source.split(search).length - 1
23
27
  }
@@ -63,14 +63,14 @@ class KeyboardShortcutDialog extends BasicDialog {
63
63
 
64
64
  add.group('Assign Keyboard Shortcut').build((layout) => {
65
65
  layout.spacing = 5
66
- add.edit().value(model.actionLabel).readOnly(true)
66
+ add.edit().value(model.actionLabel).readOnly()
67
67
  add.comboEdit().focus().items([...letters, ...keys]).changed(this.key).edited(this.key)
68
68
  add.checkbox('Control').value(model.control)
69
69
  add.checkbox('Option / Alt').value(model.alt)
70
70
  add.checkbox('Shift').value(model.shift)
71
71
  add.checkbox('Command / Windows').value(model.windows)
72
72
  add.group('Shortcut:').style({ flat: true }).build(() => {
73
- add.edit().value(model.shortcut).readOnly(true)
73
+ add.edit().value(model.shortcut).readOnly()
74
74
  })
75
75
  })
76
76
  }