dazscript-framework 1.0.10 → 1.0.12
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 +1 -1
- package/src/dialog/builders/dialog-builder.ts +7 -1
- package/src/dialog/builders/groupbox-builder.ts +7 -0
- package/src/dialog/builders/list-view-builder.ts +62 -8
- package/src/dialog/builders/tab-builder.ts +7 -0
- package/src/dialog/builders/widget-builder.ts +6 -0
- package/src/dialog/shared.ts +2 -0
package/package.json
CHANGED
|
@@ -30,11 +30,17 @@ export class DialogBuilder extends WidgetsBuilder {
|
|
|
30
30
|
private resize() {
|
|
31
31
|
let dialogWidget = this.context.dialog.getWidget();
|
|
32
32
|
let sizeHint = dialogWidget.minimumSizeHint;
|
|
33
|
+
let maxHeight = this.properties.maxHeight;
|
|
33
34
|
let height = this.properties.height ?? sizeHint.height;
|
|
34
|
-
|
|
35
|
+
if (maxHeight !== undefined && height > maxHeight) height = maxHeight;
|
|
36
|
+
this.context.dialog.minHeight = maxHeight !== undefined
|
|
37
|
+
? Math.min(sizeHint.height, maxHeight)
|
|
38
|
+
: sizeHint.height;
|
|
35
39
|
this.context.dialog.height = height;
|
|
36
40
|
|
|
37
41
|
if (this.properties.width) this.context.dialog.width = this.properties.width;
|
|
42
|
+
if (this.properties.maxWidth !== undefined) this.context.dialog.maxWidth = this.properties.maxWidth;
|
|
43
|
+
if (maxHeight !== undefined) this.context.dialog.maxHeight = maxHeight;
|
|
38
44
|
|
|
39
45
|
if (this.properties.resizable === true) {
|
|
40
46
|
this.context.dialog.sizeGripEnabled = true;
|
|
@@ -13,6 +13,7 @@ export default class GroupBoxBuilder implements IWidgetBuilder<DzGroupBox> {
|
|
|
13
13
|
private _columns: number = 1
|
|
14
14
|
private _height: number | null = null
|
|
15
15
|
private _minHeight: number | null = null
|
|
16
|
+
private _maxHeight: number | null = null
|
|
16
17
|
|
|
17
18
|
constructor(private context: WidgetBuilderContext) {
|
|
18
19
|
}
|
|
@@ -73,6 +74,11 @@ export default class GroupBoxBuilder implements IWidgetBuilder<DzGroupBox> {
|
|
|
73
74
|
return this
|
|
74
75
|
}
|
|
75
76
|
|
|
77
|
+
maxHeight(value: number): this {
|
|
78
|
+
this._maxHeight = value
|
|
79
|
+
return this
|
|
80
|
+
}
|
|
81
|
+
|
|
76
82
|
columns(value: number): this {
|
|
77
83
|
this._columns = value
|
|
78
84
|
return this
|
|
@@ -86,6 +92,7 @@ export default class GroupBoxBuilder implements IWidgetBuilder<DzGroupBox> {
|
|
|
86
92
|
groupBox.columns = this._columns
|
|
87
93
|
if (this._height !== null) groupBox.height = this._height
|
|
88
94
|
if (this._minHeight !== null) groupBox.minHeight = this._minHeight
|
|
95
|
+
if (this._maxHeight !== null) groupBox.maxHeight = this._maxHeight
|
|
89
96
|
|
|
90
97
|
this._title?.connect((text) => {
|
|
91
98
|
groupBox.title = text
|
|
@@ -19,6 +19,8 @@ export enum ListViewRefreshOptions {
|
|
|
19
19
|
Filters
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
type ListViewItemsChangeMode = 'update' | 'rebuild'
|
|
23
|
+
|
|
22
24
|
export class ListViewBuilder<TItem, TData> implements IWidgetBuilder<DzListView> {
|
|
23
25
|
|
|
24
26
|
private readonly context: ListViewBuilderContext<TItem, TData>
|
|
@@ -44,6 +46,11 @@ export class ListViewBuilder<TItem, TData> implements IWidgetBuilder<DzListView>
|
|
|
44
46
|
return this
|
|
45
47
|
}
|
|
46
48
|
|
|
49
|
+
maxHeight(value: number): this {
|
|
50
|
+
this.context.maxHeight = value
|
|
51
|
+
return this
|
|
52
|
+
}
|
|
53
|
+
|
|
47
54
|
/**
|
|
48
55
|
* Binds the list rows to a collection of items
|
|
49
56
|
* @param items
|
|
@@ -104,6 +111,11 @@ export class ListViewBuilder<TItem, TData> implements IWidgetBuilder<DzListView>
|
|
|
104
111
|
return this
|
|
105
112
|
}
|
|
106
113
|
|
|
114
|
+
rebuildOnItemsChanged(): this {
|
|
115
|
+
this.context.itemsChangeMode = 'rebuild'
|
|
116
|
+
return this
|
|
117
|
+
}
|
|
118
|
+
|
|
107
119
|
contextMenu(fn: (listView: DzListView, item: DzListViewItem, pos: Point) => DzPopupMenu): this {
|
|
108
120
|
this.context.contextMenu = fn
|
|
109
121
|
return this
|
|
@@ -135,9 +147,11 @@ class ListViewBuilderContext<TItem, TData> {
|
|
|
135
147
|
visible: Observable<boolean> = new Observable(true)
|
|
136
148
|
height: number | null = null
|
|
137
149
|
minHeight: number | null = null
|
|
150
|
+
maxHeight: number | null = null
|
|
138
151
|
decorated: boolean
|
|
139
152
|
flat: Observable<boolean>
|
|
140
153
|
refreshWhat: ListViewRefreshOptions = ListViewRefreshOptions.All
|
|
154
|
+
itemsChangeMode: ListViewItemsChangeMode = 'update'
|
|
141
155
|
constructor(public readonly dialogContext: WidgetBuilderContext) { }
|
|
142
156
|
}
|
|
143
157
|
|
|
@@ -193,6 +207,11 @@ class ListViewBindBuilder<TItem, TData> {
|
|
|
193
207
|
return this
|
|
194
208
|
}
|
|
195
209
|
|
|
210
|
+
rebuildOnItemsChanged(): this {
|
|
211
|
+
this.context.itemsChangeMode = 'rebuild'
|
|
212
|
+
return this
|
|
213
|
+
}
|
|
214
|
+
|
|
196
215
|
contextMenu(fn: (listView: DzListView, item: DzListViewItem, pos: Point) => DzPopupMenu): this {
|
|
197
216
|
this.context.contextMenu = fn
|
|
198
217
|
return this
|
|
@@ -228,6 +247,10 @@ const build = <TItem, TData>(context: ListViewBuilderContext<TItem, TData>): DzL
|
|
|
228
247
|
listView.minHeight = context.minHeight
|
|
229
248
|
}
|
|
230
249
|
|
|
250
|
+
if (context.maxHeight !== null) {
|
|
251
|
+
listView.maxHeight = context.maxHeight
|
|
252
|
+
}
|
|
253
|
+
|
|
231
254
|
const buildColumns = (columns: string[]) => {
|
|
232
255
|
clearColumns(listView)
|
|
233
256
|
columns.forEach(column => {
|
|
@@ -271,6 +294,7 @@ const build = <TItem, TData>(context: ListViewBuilderContext<TItem, TData>): DzL
|
|
|
271
294
|
if (!context.text)
|
|
272
295
|
return warn('No text function provided for list builder')
|
|
273
296
|
|
|
297
|
+
const previousColumnWidths = context.columns?.value.map((_, index) => listView.columnWidth(index)) ?? []
|
|
274
298
|
listView.clear()
|
|
275
299
|
context.columns?.value.forEach((_, index) => {
|
|
276
300
|
listView.setColumnWidth(index, 0)
|
|
@@ -290,6 +314,11 @@ const build = <TItem, TData>(context: ListViewBuilderContext<TItem, TData>): DzL
|
|
|
290
314
|
context.columns?.value.forEach((_, index) => {
|
|
291
315
|
listView.setColumnWidth(index, context.columnsWidth!(index, listView.columnWidth(index), listView))
|
|
292
316
|
})
|
|
317
|
+
} else {
|
|
318
|
+
context.columns?.value.forEach((_, index) => {
|
|
319
|
+
const previousWidth = previousColumnWidths[index]
|
|
320
|
+
if (previousWidth > 0) listView.setColumnWidth(index, previousWidth)
|
|
321
|
+
})
|
|
293
322
|
}
|
|
294
323
|
|
|
295
324
|
listView.rootIsDecorated = context.decorated
|
|
@@ -320,22 +349,44 @@ const build = <TItem, TData>(context: ListViewBuilderContext<TItem, TData>): DzL
|
|
|
320
349
|
existingByPath[path] = li
|
|
321
350
|
})
|
|
322
351
|
|
|
352
|
+
const itemKey = (item: TreeNode<TItem>) => {
|
|
353
|
+
const data = context.data?.(item) as any
|
|
354
|
+
return data?.id ?? item.path
|
|
355
|
+
}
|
|
356
|
+
|
|
323
357
|
const incomingPaths: Record<string, boolean> = {}
|
|
324
|
-
|
|
325
|
-
incomingPaths[item
|
|
326
|
-
|
|
358
|
+
const markIncoming = (item: TreeNode<TItem>) => {
|
|
359
|
+
incomingPaths[itemKey(item)] = true
|
|
360
|
+
item.children.forEach(markIncoming)
|
|
361
|
+
}
|
|
362
|
+
items.forEach(markIncoming)
|
|
363
|
+
|
|
364
|
+
const updateItem = (item: TreeNode<TItem>, parent: DzListView | DzListViewItem) => {
|
|
365
|
+
const key = itemKey(item)
|
|
366
|
+
const existing = existingByPath[key]
|
|
327
367
|
if (existing) {
|
|
328
368
|
context.text(item).forEach((text, idx) => {
|
|
369
|
+
if (idx >= context.columns.value.length) return
|
|
329
370
|
existing.setText(idx, text ?? '')
|
|
330
371
|
})
|
|
331
372
|
const data = context.data?.(item)
|
|
332
373
|
if (data) setDataItem(existing, data)
|
|
374
|
+
item.children.forEach((child) => {
|
|
375
|
+
updateItem(child, context.flat?.value === true ? listView : existing)
|
|
376
|
+
})
|
|
333
377
|
} else {
|
|
334
|
-
buildItem(item,
|
|
378
|
+
buildItem(item, parent)
|
|
335
379
|
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
|
|
380
|
+
}
|
|
381
|
+
items.forEach((item) => updateItem(item, listView))
|
|
382
|
+
|
|
383
|
+
listView.getItems(DzListView.All).sort((left, right) => {
|
|
384
|
+
const leftData = getDataItem<any>(left)
|
|
385
|
+
const rightData = getDataItem<any>(right)
|
|
386
|
+
const leftPath = leftData?.id ?? String(left.id)
|
|
387
|
+
const rightPath = rightData?.id ?? String(right.id)
|
|
388
|
+
return rightPath.length - leftPath.length
|
|
389
|
+
}).forEach((li) => {
|
|
339
390
|
const data = getDataItem<any>(li)
|
|
340
391
|
const path = data?.id ?? String(li.id)
|
|
341
392
|
if (!incomingPaths[path]) listView.deleteItem(li)
|
|
@@ -358,7 +409,10 @@ const build = <TItem, TData>(context: ListViewBuilderContext<TItem, TData>): DzL
|
|
|
358
409
|
listView.setSorting(context.sorting, context.sortAscending)
|
|
359
410
|
buildList(context.items?.value)
|
|
360
411
|
context.items.connect((items) => {
|
|
361
|
-
|
|
412
|
+
if (context.itemsChangeMode === 'rebuild')
|
|
413
|
+
buildList(items, listView.selectedItem()?.id)
|
|
414
|
+
else
|
|
415
|
+
updateList(items)
|
|
362
416
|
})
|
|
363
417
|
|
|
364
418
|
context.refreshWhen?.connect(() => {
|
|
@@ -11,6 +11,7 @@ export class TabBuilder implements IWidgetBuilder<DzTabWidget> {
|
|
|
11
11
|
private currentChanged: (index: number) => void;
|
|
12
12
|
private height_: number | null = null;
|
|
13
13
|
private minHeight_: number | null = null;
|
|
14
|
+
private maxHeight_: number | null = null;
|
|
14
15
|
|
|
15
16
|
constructor(private layoutBuilder: LayoutBuilder, private context: TabBuilderContext) {
|
|
16
17
|
}
|
|
@@ -32,6 +33,11 @@ export class TabBuilder implements IWidgetBuilder<DzTabWidget> {
|
|
|
32
33
|
return this
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
maxHeight(value: number): this {
|
|
37
|
+
this.maxHeight_ = value
|
|
38
|
+
return this
|
|
39
|
+
}
|
|
40
|
+
|
|
35
41
|
static create(context: TabBuilderContext): TabBuilder {
|
|
36
42
|
return new TabBuilder(new LayoutBuilder(context.widgetContext), context)
|
|
37
43
|
}
|
|
@@ -65,6 +71,7 @@ export class TabBuilder implements IWidgetBuilder<DzTabWidget> {
|
|
|
65
71
|
return this.context.add((tabWidget) => {
|
|
66
72
|
if (this.height_ !== null) tabWidget.height = this.height_
|
|
67
73
|
if (this.minHeight_ !== null) tabWidget.minHeight = this.minHeight_
|
|
74
|
+
if (this.maxHeight_ !== null) tabWidget.maxHeight = this.maxHeight_
|
|
68
75
|
let tab = new DzWidget(this.context.widgetContext.dialog)
|
|
69
76
|
tabWidget.addTab(tab, this.titleText)
|
|
70
77
|
this.context.widgetContext.layout.addWidget(tabWidget)
|
|
@@ -77,6 +77,11 @@ export abstract class WidgetBuilderBase<T extends DzWidget> implements IWidgetBu
|
|
|
77
77
|
return this
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
maxHeight(value: number): this {
|
|
81
|
+
this.widget.maxHeight = value
|
|
82
|
+
return this
|
|
83
|
+
}
|
|
84
|
+
|
|
80
85
|
build(): T {
|
|
81
86
|
return this.widget
|
|
82
87
|
}
|
|
@@ -86,6 +91,7 @@ export interface IWidgetBuilder<T extends DzWidget> {
|
|
|
86
91
|
visible(value: boolean | Observable<boolean>): this
|
|
87
92
|
height(value: number): this
|
|
88
93
|
minHeight(value: number): this
|
|
94
|
+
maxHeight(value: number): this
|
|
89
95
|
build(): T
|
|
90
96
|
}
|
|
91
97
|
|