dazscript-framework 1.0.11 → 1.0.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": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "author": "Freddy Diaz",
5
5
  "license": "MPL-2.0",
6
6
  "description": "",
@@ -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>
@@ -83,6 +85,11 @@ export class ListViewBuilder<TItem, TData> implements IWidgetBuilder<DzListView>
83
85
  return this
84
86
  }
85
87
 
88
+ selectionMode(mode: number): this {
89
+ this.context.selectionMode = mode
90
+ return this
91
+ }
92
+
86
93
  expanded(onOff: boolean | Observable<boolean>): this {
87
94
  if (typeof onOff === 'boolean')
88
95
  this.context.expanded = new Observable(onOff)
@@ -109,6 +116,11 @@ export class ListViewBuilder<TItem, TData> implements IWidgetBuilder<DzListView>
109
116
  return this
110
117
  }
111
118
 
119
+ rebuildOnItemsChanged(): this {
120
+ this.context.itemsChangeMode = 'rebuild'
121
+ return this
122
+ }
123
+
112
124
  contextMenu(fn: (listView: DzListView, item: DzListViewItem, pos: Point) => DzPopupMenu): this {
113
125
  this.context.contextMenu = fn
114
126
  return this
@@ -130,6 +142,7 @@ class ListViewBuilderContext<TItem, TData> {
130
142
  sorting: number = 0
131
143
  sortAscending: boolean = true
132
144
  sortOnBuild: boolean = true
145
+ selectionMode: number | null = null
133
146
  selected: Observable<TData>
134
147
  filter: ListViewFilterOptions
135
148
  doubleClicked: Observable<TData>
@@ -144,6 +157,7 @@ class ListViewBuilderContext<TItem, TData> {
144
157
  decorated: boolean
145
158
  flat: Observable<boolean>
146
159
  refreshWhat: ListViewRefreshOptions = ListViewRefreshOptions.All
160
+ itemsChangeMode: ListViewItemsChangeMode = 'update'
147
161
  constructor(public readonly dialogContext: WidgetBuilderContext) { }
148
162
  }
149
163
 
@@ -199,6 +213,16 @@ class ListViewBindBuilder<TItem, TData> {
199
213
  return this
200
214
  }
201
215
 
216
+ rebuildOnItemsChanged(): this {
217
+ this.context.itemsChangeMode = 'rebuild'
218
+ return this
219
+ }
220
+
221
+ selectionMode(mode: number): this {
222
+ this.context.selectionMode = mode
223
+ return this
224
+ }
225
+
202
226
  contextMenu(fn: (listView: DzListView, item: DzListViewItem, pos: Point) => DzPopupMenu): this {
203
227
  this.context.contextMenu = fn
204
228
  return this
@@ -281,6 +305,7 @@ const build = <TItem, TData>(context: ListViewBuilderContext<TItem, TData>): DzL
281
305
  if (!context.text)
282
306
  return warn('No text function provided for list builder')
283
307
 
308
+ const previousColumnWidths = context.columns?.value.map((_, index) => listView.columnWidth(index)) ?? []
284
309
  listView.clear()
285
310
  context.columns?.value.forEach((_, index) => {
286
311
  listView.setColumnWidth(index, 0)
@@ -300,6 +325,11 @@ const build = <TItem, TData>(context: ListViewBuilderContext<TItem, TData>): DzL
300
325
  context.columns?.value.forEach((_, index) => {
301
326
  listView.setColumnWidth(index, context.columnsWidth!(index, listView.columnWidth(index), listView))
302
327
  })
328
+ } else {
329
+ context.columns?.value.forEach((_, index) => {
330
+ const previousWidth = previousColumnWidths[index]
331
+ if (previousWidth > 0) listView.setColumnWidth(index, previousWidth)
332
+ })
303
333
  }
304
334
 
305
335
  listView.rootIsDecorated = context.decorated
@@ -388,9 +418,15 @@ const build = <TItem, TData>(context: ListViewBuilderContext<TItem, TData>): DzL
388
418
  })
389
419
 
390
420
  listView.setSorting(context.sorting, context.sortAscending)
421
+ if (context.selectionMode !== null) {
422
+ listView.selectionMode = context.selectionMode
423
+ }
391
424
  buildList(context.items?.value)
392
425
  context.items.connect((items) => {
393
- updateList(items)
426
+ if (context.itemsChangeMode === 'rebuild')
427
+ buildList(items, listView.selectedItem()?.id)
428
+ else
429
+ updateList(items)
394
430
  })
395
431
 
396
432
  context.refreshWhen?.connect(() => {