dazscript-framework 1.0.11 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dazscript-framework",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
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>
@@ -109,6 +111,11 @@ export class ListViewBuilder<TItem, TData> implements IWidgetBuilder<DzListView>
109
111
  return this
110
112
  }
111
113
 
114
+ rebuildOnItemsChanged(): this {
115
+ this.context.itemsChangeMode = 'rebuild'
116
+ return this
117
+ }
118
+
112
119
  contextMenu(fn: (listView: DzListView, item: DzListViewItem, pos: Point) => DzPopupMenu): this {
113
120
  this.context.contextMenu = fn
114
121
  return this
@@ -144,6 +151,7 @@ class ListViewBuilderContext<TItem, TData> {
144
151
  decorated: boolean
145
152
  flat: Observable<boolean>
146
153
  refreshWhat: ListViewRefreshOptions = ListViewRefreshOptions.All
154
+ itemsChangeMode: ListViewItemsChangeMode = 'update'
147
155
  constructor(public readonly dialogContext: WidgetBuilderContext) { }
148
156
  }
149
157
 
@@ -199,6 +207,11 @@ class ListViewBindBuilder<TItem, TData> {
199
207
  return this
200
208
  }
201
209
 
210
+ rebuildOnItemsChanged(): this {
211
+ this.context.itemsChangeMode = 'rebuild'
212
+ return this
213
+ }
214
+
202
215
  contextMenu(fn: (listView: DzListView, item: DzListViewItem, pos: Point) => DzPopupMenu): this {
203
216
  this.context.contextMenu = fn
204
217
  return this
@@ -281,6 +294,7 @@ const build = <TItem, TData>(context: ListViewBuilderContext<TItem, TData>): DzL
281
294
  if (!context.text)
282
295
  return warn('No text function provided for list builder')
283
296
 
297
+ const previousColumnWidths = context.columns?.value.map((_, index) => listView.columnWidth(index)) ?? []
284
298
  listView.clear()
285
299
  context.columns?.value.forEach((_, index) => {
286
300
  listView.setColumnWidth(index, 0)
@@ -300,6 +314,11 @@ const build = <TItem, TData>(context: ListViewBuilderContext<TItem, TData>): DzL
300
314
  context.columns?.value.forEach((_, index) => {
301
315
  listView.setColumnWidth(index, context.columnsWidth!(index, listView.columnWidth(index), listView))
302
316
  })
317
+ } else {
318
+ context.columns?.value.forEach((_, index) => {
319
+ const previousWidth = previousColumnWidths[index]
320
+ if (previousWidth > 0) listView.setColumnWidth(index, previousWidth)
321
+ })
303
322
  }
304
323
 
305
324
  listView.rootIsDecorated = context.decorated
@@ -390,7 +409,10 @@ const build = <TItem, TData>(context: ListViewBuilderContext<TItem, TData>): DzL
390
409
  listView.setSorting(context.sorting, context.sortAscending)
391
410
  buildList(context.items?.value)
392
411
  context.items.connect((items) => {
393
- updateList(items)
412
+ if (context.itemsChangeMode === 'rebuild')
413
+ buildList(items, listView.selectedItem()?.id)
414
+ else
415
+ updateList(items)
394
416
  })
395
417
 
396
418
  context.refreshWhen?.connect(() => {