dazscript-framework 1.0.42 → 1.0.43

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.42",
3
+ "version": "1.0.43",
4
4
  "author": "Freddy Diaz",
5
5
  "license": "MPL-2.0",
6
6
  "description": "",
@@ -2,6 +2,8 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
2
2
  import { Observable } from '@dsf/lib/observable'
3
3
  import { TreeNode } from '@dsf/lib/tree-node'
4
4
 
5
+ const buildEvents = vi.hoisted(() => [] as string[])
6
+
5
7
  const listView = vi.hoisted(() => ({
6
8
  items: [] as any[],
7
9
  addColumn: vi.fn(),
@@ -12,7 +14,7 @@ const listView = vi.hoisted(() => ({
12
14
  deleteItem: vi.fn(function (this: any, item: any) {
13
15
  this.items = this.items.filter((candidate: any) => candidate !== item)
14
16
  }),
15
- setSorting: vi.fn(),
17
+ setSorting: vi.fn((column: number) => buildEvents.push(`sorting:${column}`)),
16
18
  hide: vi.fn(),
17
19
  show: vi.fn(),
18
20
  getWidget: vi.fn(() => focusWidget),
@@ -42,6 +44,7 @@ class FakeListViewItem {
42
44
  textByColumn: Record<number, string> = {}
43
45
 
44
46
  constructor(parent: any, public id: number) {
47
+ buildEvents.push('item')
45
48
  parent.items.push(this)
46
49
  }
47
50
 
@@ -63,6 +66,19 @@ describe('ListViewBuilder item updates', () => {
63
66
  vi.clearAllMocks()
64
67
  vi.mocked(filter).mockReset()
65
68
  focusWidget.focusPolicy = 15
69
+ buildEvents.length = 0
70
+ })
71
+
72
+ it('suspends sorting while building rows and restores it afterward', () => {
73
+ new ListViewBuilder<any, any>({ dialog: {}, layout: null } as any)
74
+ .sorting(true)
75
+ .items(new Observable([new TreeNode('Action A', '', { name: 'ActionA' })]))
76
+ .columns(['Name'])
77
+ .text(item => [item.name])
78
+ .data(item => item.value)
79
+ .build()
80
+
81
+ expect(buildEvents).toEqual(['sorting:-1', 'item', 'sorting:0'])
66
82
  })
67
83
 
68
84
  it('keeps unchanged rows when data has no explicit id', () => {
@@ -314,7 +314,7 @@ const build = <TItem, TData>(context: ListViewBuilderContext<TItem, TData>): DzL
314
314
  }
315
315
  let delayedFilter: Delayed | null = null
316
316
 
317
- const buildList = (items: TreeNode<TItem>[], selectedId?: number) => {
317
+ const buildListRows = (items: TreeNode<TItem>[], selectedId?: number) => {
318
318
  rowId = -1
319
319
  context.decorated = false
320
320
  if (!context.text)
@@ -370,6 +370,15 @@ const build = <TItem, TData>(context: ListViewBuilderContext<TItem, TData>): DzL
370
370
  }
371
371
  }
372
372
 
373
+ const buildList = (items: TreeNode<TItem>[], selectedId?: number) => {
374
+ listView.setSorting(-1, context.sortAscending)
375
+ try {
376
+ buildListRows(items, selectedId)
377
+ } finally {
378
+ listView.setSorting(context.sorting, context.sortAscending)
379
+ }
380
+ }
381
+
373
382
  const updateList = (items: TreeNode<TItem>[]) => {
374
383
  if (!context.text) return
375
384
  if (!items) return
@@ -440,7 +449,6 @@ const build = <TItem, TData>(context: ListViewBuilderContext<TItem, TData>): DzL
440
449
  })
441
450
 
442
451
  listView.showSortIndicator = context.sorting >= 0
443
- listView.setSorting(context.sorting, context.sortAscending)
444
452
  if (context.selectionMode !== null) {
445
453
  listView.selectionMode = context.selectionMode
446
454
  }