niuma-ui 1.0.0 → 1.0.2

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.
Files changed (159) hide show
  1. package/CHANGELOG.md +50 -1
  2. package/NOTICE +2 -2
  3. package/package.json +13 -5
  4. package/src/__tests__/RsButton.spec.ts +47 -0
  5. package/src/__tests__/RsCard.spec.ts +160 -1
  6. package/src/__tests__/RsConfirmDialog.spec.ts +127 -0
  7. package/src/__tests__/RsContextMenu.spec.ts +12 -0
  8. package/src/__tests__/RsDateTimePicker.spec.ts +11 -0
  9. package/src/__tests__/RsDescriptions.spec.ts +50 -0
  10. package/src/__tests__/RsDialog.spec.ts +117 -0
  11. package/src/__tests__/RsDrawer.spec.ts +96 -3
  12. package/src/__tests__/RsDynamicTags.spec.ts +52 -0
  13. package/src/__tests__/RsForm.spec.ts +245 -1
  14. package/src/__tests__/RsInput.spec.ts +15 -1
  15. package/src/__tests__/RsMenu.spec.ts +406 -14
  16. package/src/__tests__/RsPagination.spec.ts +67 -2
  17. package/src/__tests__/RsSelect.spec.ts +42 -1
  18. package/src/__tests__/RsSwitch.spec.ts +44 -0
  19. package/src/__tests__/RsTable.a11y.spec.ts +83 -0
  20. package/src/__tests__/RsTable.dom-baseline.spec.ts +87 -0
  21. package/src/__tests__/RsTable.perf.spec.ts +23 -4
  22. package/src/__tests__/RsTable.spec.ts +63 -8
  23. package/src/__tests__/RsTable.ssr.spec.ts +71 -0
  24. package/src/__tests__/RsTable.summary.spec.ts +45 -0
  25. package/src/__tests__/RsTabs.spec.ts +102 -4
  26. package/src/__tests__/RsTerminal.spec.ts +1 -1
  27. package/src/__tests__/RsTimePicker.spec.ts +11 -0
  28. package/src/__tests__/RsUpload.spec.ts +62 -6
  29. package/src/__tests__/createRsDialog.spec.ts +145 -0
  30. package/src/__tests__/form-rules.spec.ts +76 -0
  31. package/src/__tests__/perf-budgets.ts +32 -0
  32. package/src/__tests__/rs-table-api.spec.ts +206 -0
  33. package/src/__tests__/rs-table-compat-matrix.spec.ts +108 -0
  34. package/src/__tests__/rs-table-echarts-adapter.spec.ts +43 -0
  35. package/src/__tests__/rs-table-grid-nav.spec.ts +63 -0
  36. package/src/__tests__/rs-table-isolation.spec.ts +158 -0
  37. package/src/__tests__/split-pane-utils.spec.ts +21 -0
  38. package/src/__tests__/table-chart-utils.spec.ts +88 -0
  39. package/src/__tests__/table-summary-utils.spec.ts +62 -0
  40. package/src/__tests__/table-utils.spec.ts +124 -0
  41. package/src/__tests__/theme.spec.ts +25 -0
  42. package/src/__tests__/useRsTableColumnResize.spec.ts +25 -0
  43. package/src/__tests__/useRsTableCore.perf.spec.ts +170 -0
  44. package/src/components/RsAlert.vue +212 -0
  45. package/src/components/RsButton.vue +145 -21
  46. package/src/components/RsCard.vue +200 -16
  47. package/src/components/RsConfirmDialog.vue +215 -28
  48. package/src/components/RsContextMenu.vue +51 -13
  49. package/src/components/RsDatePicker.vue +267 -34
  50. package/src/components/RsDateTimePicker.vue +19 -2
  51. package/src/components/RsDescriptions.vue +186 -0
  52. package/src/components/RsDescriptionsItem.vue +32 -0
  53. package/src/components/RsDialog.vue +363 -51
  54. package/src/components/RsDivider.vue +89 -0
  55. package/src/components/RsDrawer.vue +558 -33
  56. package/src/components/RsDropdown.vue +33 -2
  57. package/src/components/RsDynamicTags.vue +517 -0
  58. package/src/components/RsForm.vue +97 -8
  59. package/src/components/RsInput.vue +80 -82
  60. package/src/components/RsInputNumber.vue +64 -23
  61. package/src/components/RsLabel.vue +20 -5
  62. package/src/components/RsLoadingBar.vue +151 -0
  63. package/src/components/RsMenu.vue +73 -15
  64. package/src/components/RsMenuItems.vue +147 -9
  65. package/src/components/RsPagination.vue +93 -14
  66. package/src/components/RsRadio.vue +81 -0
  67. package/src/components/RsRadioItem.vue +156 -0
  68. package/src/components/RsSelect.vue +67 -58
  69. package/src/components/RsSplitPane.vue +69 -1
  70. package/src/components/RsSwitch.vue +179 -0
  71. package/src/components/RsTable.vue +653 -2555
  72. package/src/components/RsTabs.vue +415 -83
  73. package/src/components/RsTag.vue +191 -0
  74. package/src/components/RsTerminal.vue +3 -3
  75. package/src/components/RsTimePicker.vue +44 -5
  76. package/src/components/RsTimePickerColumns.vue +136 -77
  77. package/src/components/RsToaster.vue +58 -18
  78. package/src/components/RsTree.vue +39 -21
  79. package/src/components/RsUpload.vue +145 -12
  80. package/src/components/RsVNodeHost.vue +20 -0
  81. package/src/components/button-utils.ts +39 -0
  82. package/src/components/context-menu-utils.ts +6 -0
  83. package/src/components/date-picker-utils.ts +84 -4
  84. package/src/components/descriptions-utils.ts +24 -0
  85. package/src/components/dialog-utils.ts +147 -0
  86. package/src/components/dialog-window.ts +74 -9
  87. package/src/components/drawer-utils.ts +73 -0
  88. package/src/components/form-rules.ts +257 -0
  89. package/src/components/form-utils.ts +52 -2
  90. package/src/components/menu-utils.ts +11 -0
  91. package/src/components/overlay-utils.ts +3 -0
  92. package/src/components/radio-utils.ts +12 -0
  93. package/src/components/reka.ts +5 -0
  94. package/src/components/select-utils.ts +21 -2
  95. package/src/components/split-pane-utils.ts +65 -12
  96. package/src/components/table/RsTableBody.vue +217 -0
  97. package/src/components/table/RsTableBodyRow.vue +90 -1
  98. package/src/components/table/RsTableColGroup.vue +41 -0
  99. package/src/components/table/RsTableHeader.vue +158 -0
  100. package/src/components/table/RsTableSummaryRow.vue +52 -0
  101. package/src/components/table/rs-table-api.ts +99 -0
  102. package/src/components/table/rs-table-compat-matrix.ts +71 -0
  103. package/src/components/table/rs-table-echarts-adapter.ts +81 -0
  104. package/src/components/table/rs-table-feature-host.ts +178 -0
  105. package/src/components/table/rs-table-grid-nav.ts +122 -0
  106. package/src/components/table/rs-table-header-types.ts +47 -0
  107. package/src/components/table/rs-table-module-registry.ts +72 -0
  108. package/src/components/table/rs-table-props.ts +274 -0
  109. package/src/components/table/rs-table-view-context.ts +258 -0
  110. package/src/components/table/rs-table.css +84 -6
  111. package/src/components/table/table-chart-utils.ts +165 -0
  112. package/src/components/table/table-features.ts +284 -0
  113. package/src/components/table/table-summary-utils.ts +194 -0
  114. package/src/components/table-utils.ts +452 -2
  115. package/src/components/tabs-utils.ts +142 -2
  116. package/src/components/terminal-utils.ts +1 -1
  117. package/src/components/terminal-wheel.ts +1 -1
  118. package/src/components/time-picker-utils.ts +76 -3
  119. package/src/components/upload-utils.ts +122 -0
  120. package/src/components/virtual-list-utils.ts +15 -2
  121. package/src/composables/assembleRsTableApi.ts +79 -0
  122. package/src/composables/bindRsTableViewContext.ts +269 -0
  123. package/src/composables/createRsDialog.ts +357 -0
  124. package/src/composables/createRsTableEditEmitBridge.ts +38 -0
  125. package/src/composables/useRsLoadingBar.ts +36 -0
  126. package/src/composables/useRsTable.ts +134 -0
  127. package/src/composables/useRsTableA11y.ts +52 -0
  128. package/src/composables/useRsTableChartBridge.ts +79 -0
  129. package/src/composables/useRsTableColumnLayout.ts +320 -0
  130. package/src/composables/useRsTableColumnResize.ts +244 -0
  131. package/src/composables/useRsTableColumnVirtual.ts +180 -0
  132. package/src/composables/useRsTableColumns.ts +200 -0
  133. package/src/composables/useRsTableContextMenu.ts +257 -0
  134. package/src/composables/useRsTableCore.ts +256 -0
  135. package/src/composables/useRsTableEditActions.ts +606 -0
  136. package/src/composables/useRsTableEditLayer.ts +251 -0
  137. package/src/composables/useRsTableEngine.ts +357 -0
  138. package/src/composables/useRsTableGridKeyboard.ts +123 -0
  139. package/src/composables/useRsTableHeadless.ts +137 -0
  140. package/src/composables/useRsTableInteraction.ts +433 -0
  141. package/src/composables/useRsTableScrollHost.ts +75 -0
  142. package/src/composables/useRsTableScrollLayout.ts +255 -0
  143. package/src/composables/useRsTableSelectionSource.ts +89 -0
  144. package/src/composables/useRsTableShell.ts +416 -0
  145. package/src/composables/useRsTableShellChrome.ts +170 -0
  146. package/src/composables/useRsTableSummary.ts +113 -0
  147. package/src/composables/useRsTableViewProvide.ts +263 -0
  148. package/src/composables/useRsTableVirtual.ts +154 -0
  149. package/src/composables/useRsTabsNav.ts +4 -0
  150. package/src/composables/useTableEdit.ts +1 -1
  151. package/src/icons/lucide.ts +2 -2
  152. package/src/index.ts +309 -9
  153. package/src/locale/messages.ts +30 -0
  154. package/src/styles.css +305 -52
  155. package/src/theme/brand.example.css +21 -2
  156. package/src/theme/presets.ts +4 -0
  157. package/src/theme/types.ts +67 -0
  158. package/src/components/RsTableColgroup.vue +0 -17
  159. package/src/components/RsTableHeaderRow.vue +0 -30
@@ -0,0 +1,43 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { mapRsTableSeriesToEChartsOption } from '../components/table/rs-table-echarts-adapter'
3
+ import type { RsTableChartSeries } from '../components/table/table-chart-utils'
4
+
5
+ const bar: RsTableChartSeries = {
6
+ id: 'by-status',
7
+ kind: 'bar',
8
+ points: [
9
+ { key: 'ok', name: 'ok', value: 2, count: 2 },
10
+ { key: 'wait', name: 'wait', value: 1, count: 1 },
11
+ ],
12
+ categories: ['ok', 'wait'],
13
+ values: [2, 1],
14
+ }
15
+
16
+ const pie: RsTableChartSeries = {
17
+ ...bar,
18
+ id: 'pie',
19
+ kind: 'pie',
20
+ }
21
+
22
+ describe('mapRsTableSeriesToEChartsOption', () => {
23
+ it('柱状图产出类目轴 + values', () => {
24
+ const option = mapRsTableSeriesToEChartsOption([bar])
25
+ expect(option.tooltip?.trigger).toBe('axis')
26
+ expect(option.xAxis).toEqual({ type: 'category', data: ['ok', 'wait'] })
27
+ expect(option.series[0]).toMatchObject({
28
+ id: 'by-status',
29
+ type: 'bar',
30
+ data: [2, 1],
31
+ })
32
+ })
33
+
34
+ it('饼图产出 item tooltip 与 name/value 点', () => {
35
+ const option = mapRsTableSeriesToEChartsOption([pie])
36
+ expect(option.tooltip?.trigger).toBe('item')
37
+ expect(option.series[0]?.type).toBe('pie')
38
+ expect(option.series[0]?.data).toEqual([
39
+ { name: 'ok', value: 2 },
40
+ { name: 'wait', value: 1 },
41
+ ])
42
+ })
43
+ })
@@ -0,0 +1,63 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import {
3
+ navigateGridCell,
4
+ resolveGridNavDirection,
5
+ } from '../components/table/rs-table-grid-nav'
6
+
7
+ const rows = [
8
+ { rowKey: '1', rowIndex: 0 },
9
+ { rowKey: '2', rowIndex: 1 },
10
+ { rowKey: '3', rowIndex: 2 },
11
+ ]
12
+ const cols = ['a', 'b', 'c']
13
+
14
+ describe('navigateGridCell', () => {
15
+ it('无焦点时以左上角为种子', () => {
16
+ expect(navigateGridCell(rows, cols, null, 'right')).toEqual({
17
+ rowKey: '1',
18
+ colKey: 'b',
19
+ rowIndex: 0,
20
+ })
21
+ })
22
+
23
+ it('箭头在边界钳制', () => {
24
+ const at = { rowKey: '1', colKey: 'a', rowIndex: 0 }
25
+ expect(navigateGridCell(rows, cols, at, 'left')?.colKey).toBe('a')
26
+ expect(navigateGridCell(rows, cols, at, 'up')?.rowKey).toBe('1')
27
+ const br = { rowKey: '3', colKey: 'c', rowIndex: 2 }
28
+ expect(navigateGridCell(rows, cols, br, 'right')?.colKey).toBe('c')
29
+ expect(navigateGridCell(rows, cols, br, 'down')?.rowKey).toBe('3')
30
+ })
31
+
32
+ it('Home/End 与 Ctrl 角点', () => {
33
+ const mid = { rowKey: '2', colKey: 'b', rowIndex: 1 }
34
+ expect(navigateGridCell(rows, cols, mid, 'home')?.colKey).toBe('a')
35
+ expect(navigateGridCell(rows, cols, mid, 'end')?.colKey).toBe('c')
36
+ expect(navigateGridCell(rows, cols, mid, 'first')).toEqual({
37
+ rowKey: '1',
38
+ colKey: 'a',
39
+ rowIndex: 0,
40
+ })
41
+ expect(navigateGridCell(rows, cols, mid, 'last')).toEqual({
42
+ rowKey: '3',
43
+ colKey: 'c',
44
+ rowIndex: 2,
45
+ })
46
+ })
47
+
48
+ it('PageDown 按 pageSize 跳行', () => {
49
+ const at = { rowKey: '1', colKey: 'a', rowIndex: 0 }
50
+ expect(navigateGridCell(rows, cols, at, 'pageDown', 2)?.rowKey).toBe('3')
51
+ })
52
+ })
53
+
54
+ describe('resolveGridNavDirection', () => {
55
+ it('映射常用键', () => {
56
+ expect(resolveGridNavDirection({ key: 'ArrowRight' } as KeyboardEvent)).toBe('right')
57
+ expect(resolveGridNavDirection({ key: 'Home' } as KeyboardEvent)).toBe('home')
58
+ expect(resolveGridNavDirection({ key: 'Home', ctrlKey: true } as KeyboardEvent)).toBe(
59
+ 'first',
60
+ )
61
+ expect(resolveGridNavDirection({ key: 'a' } as KeyboardEvent)).toBeNull()
62
+ })
63
+ })
@@ -0,0 +1,158 @@
1
+ import { mount } from '@vue/test-utils'
2
+ import { defineComponent, h, nextTick } from 'vue'
3
+ import { describe, expect, it, beforeEach } from 'vitest'
4
+ import RsTable from '../components/RsTable.vue'
5
+ import { createRsTableFeatureHost } from '../components/table/rs-table-feature-host'
6
+ import {
7
+ resolveInstanceFeatures,
8
+ RsTableModuleRegistry,
9
+ } from '../components/table/rs-table-module-registry'
10
+ import {
11
+ createOverlayTableFeature,
12
+ createToolbarTableFeature,
13
+ } from '../components/table/table-features'
14
+ import { useRsTableHeadless } from '../composables/useRsTableHeadless'
15
+ import type { RsTableRowData } from '../components/table-utils'
16
+
17
+ type Row = RsTableRowData & { id: string; name: string }
18
+
19
+ const columns = [{ key: 'name', title: 'Name' }]
20
+
21
+ function analyticsStub() {
22
+ return {
23
+ getViewRows: () => [] as Row[],
24
+ getSelectedRows: () => [] as Row[],
25
+ getAnalyticsSnapshot: () => ({
26
+ sourceRows: [] as Row[],
27
+ viewRows: [] as Row[],
28
+ selectedRows: [] as Row[],
29
+ sourceMode: 'view' as const,
30
+ selectedCount: 0,
31
+ viewCount: 0,
32
+ }),
33
+ subscribeAnalytics: () => () => undefined,
34
+ }
35
+ }
36
+
37
+ describe('RsTable 多表隔离', () => {
38
+ beforeEach(() => {
39
+ RsTableModuleRegistry.clear()
40
+ })
41
+
42
+ it('两个 FeatureHost 贡献袋互不污染', () => {
43
+ const a = createRsTableFeatureHost<Row>()
44
+ const b = createRsTableFeatureHost<Row>()
45
+ const stub = analyticsStub()
46
+ a.setup(
47
+ [createToolbarTableFeature({ items: [{ key: 'a-only', label: 'A' }] })],
48
+ a.createContext(stub),
49
+ )
50
+ b.setup(
51
+ [createToolbarTableFeature({ items: [{ key: 'b-only', label: 'B' }] })],
52
+ b.createContext(stub),
53
+ )
54
+ expect(a.getToolbarItems().map((i) => i.key)).toEqual(['a-only'])
55
+ expect(b.getToolbarItems().map((i) => i.key)).toEqual(['b-only'])
56
+ })
57
+
58
+ it('同页两表选中与 viewRows 互不影响', async () => {
59
+ const t1 = mount(RsTable, {
60
+ props: {
61
+ columns,
62
+ data: [{ id: '1', name: 'a' }] as Row[],
63
+ rowKey: 'id',
64
+ selectable: true,
65
+ selectedRowKeys: ['1'],
66
+ },
67
+ })
68
+ const t2 = mount(RsTable, {
69
+ props: {
70
+ columns,
71
+ data: [{ id: '2', name: 'b' }] as Row[],
72
+ rowKey: 'id',
73
+ selectable: true,
74
+ selectedRowKeys: [],
75
+ },
76
+ })
77
+ await nextTick()
78
+
79
+ const api1 = t1.vm as unknown as {
80
+ getSelectedRowKeys: () => string[]
81
+ getViewRows: () => Row[]
82
+ getToolbarItems: () => Array<{ key: string }>
83
+ }
84
+ const api2 = t2.vm as unknown as {
85
+ getSelectedRowKeys: () => string[]
86
+ getViewRows: () => Row[]
87
+ }
88
+ expect(api1.getSelectedRowKeys()).toEqual(['1'])
89
+ expect(api2.getSelectedRowKeys()).toEqual([])
90
+ expect(api1.getViewRows()[0]?.id).toBe('1')
91
+ expect(api2.getViewRows()[0]?.id).toBe('2')
92
+
93
+ t1.unmount()
94
+ t2.unmount()
95
+ })
96
+
97
+ it('ModuleRegistry 全局生效;实例同 id 可覆盖', () => {
98
+ RsTableModuleRegistry.register(
99
+ createOverlayTableFeature({
100
+ items: [{ key: 'global-chart', slot: 'chart' }],
101
+ }),
102
+ )
103
+ const hostA = createRsTableFeatureHost<Row>()
104
+ const hostB = createRsTableFeatureHost<Row>()
105
+ const stub = analyticsStub()
106
+ const featuresA = resolveInstanceFeatures<Row>([
107
+ createOverlayTableFeature({
108
+ id: 'overlayExtra',
109
+ items: [{ key: 'a-chart', slot: 'chart-a' }],
110
+ }),
111
+ ])
112
+ const featuresB = resolveInstanceFeatures<Row>([])
113
+ hostA.setup(featuresA, hostA.createContext(stub))
114
+ hostB.setup(featuresB, hostB.createContext(stub))
115
+ expect(hostA.getOverlayContributions().map((i) => i.key)).toEqual(['a-chart'])
116
+ expect(hostB.getOverlayContributions().map((i) => i.key)).toEqual(['global-chart'])
117
+ })
118
+
119
+ it('useRsTableHeadless 两实例状态与 toolbar 隔离', async () => {
120
+ const Host = defineComponent({
121
+ setup() {
122
+ const h1 = useRsTableHeadless<Row>({
123
+ columns: () => columns,
124
+ data: () => [{ id: '1', name: 'a' }],
125
+ rowKey: 'id',
126
+ features: () => [
127
+ createToolbarTableFeature({ items: [{ key: 't1', label: 'T1' }] }),
128
+ ],
129
+ })
130
+ const h2 = useRsTableHeadless<Row>({
131
+ columns: () => columns,
132
+ data: () => [
133
+ { id: '2', name: 'b' },
134
+ { id: '3', name: 'c' },
135
+ ],
136
+ rowKey: 'id',
137
+ features: () => [
138
+ createToolbarTableFeature({ items: [{ key: 't2', label: 'T2' }] }),
139
+ ],
140
+ })
141
+ return () =>
142
+ h('div', {
143
+ 'data-v1': String(h1.api.getViewRows().length),
144
+ 'data-v2': String(h2.api.getViewRows().length),
145
+ 'data-t1': h1.getToolbarItems()[0]?.key ?? '',
146
+ 'data-t2': h2.getToolbarItems()[0]?.key ?? '',
147
+ })
148
+ },
149
+ })
150
+ const wrapper = mount(Host)
151
+ await nextTick()
152
+ expect(wrapper.attributes('data-v1')).toBe('1')
153
+ expect(wrapper.attributes('data-v2')).toBe('2')
154
+ expect(wrapper.attributes('data-t1')).toBe('t1')
155
+ expect(wrapper.attributes('data-t2')).toBe('t2')
156
+ wrapper.unmount()
157
+ })
158
+ })
@@ -51,6 +51,27 @@ describe('normalizeSplitSizes', () => {
51
51
  const sizes = normalizeSplitSizes([{ key: 'a', size: 0 }, { key: 'b', size: 0 }])
52
52
  expect(sizes).toEqual([50, 50])
53
53
  })
54
+
55
+ it('keeps auto panes out of percentage pool', () => {
56
+ const sizes = normalizeSplitSizes([
57
+ { key: 'search', size: 'auto' },
58
+ { key: 'table' },
59
+ ])
60
+ expect(sizes[0]).toBe(0)
61
+ expect(sizes[1]).toBeCloseTo(100)
62
+ })
63
+
64
+ it('distributes remaining percent among non-auto panes only', () => {
65
+ const sizes = normalizeSplitSizes([
66
+ { key: 'a', size: 'auto' },
67
+ { key: 'b', size: 40 },
68
+ { key: 'c' },
69
+ ])
70
+ expect(sizes[0]).toBe(0)
71
+ expect(sizes[1]).toBeCloseTo(40)
72
+ expect(sizes[2]).toBeCloseTo(60)
73
+ expect(sizes[1]! + sizes[2]!).toBeCloseTo(100)
74
+ })
54
75
  })
55
76
 
56
77
  describe('applySplitResize', () => {
@@ -0,0 +1,88 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { ref } from 'vue'
3
+ import { buildTableChartSeries } from '../components/table/table-chart-utils'
4
+ import { useRsTableChartBridge } from '../composables/useRsTableChartBridge'
5
+ import { useRsTableSelectionSource } from '../composables/useRsTableSelectionSource'
6
+
7
+ const rows = [
8
+ { id: '1', status: 'ok', amount: 10 },
9
+ { id: '2', status: 'ok', amount: 20 },
10
+ { id: '3', status: 'wait', amount: 5 },
11
+ { id: '4', status: 'wait', amount: 15 },
12
+ { id: '5', status: 'fail', amount: 3 },
13
+ ]
14
+
15
+ describe('buildTableChartSeries', () => {
16
+ it('groups by category with count', () => {
17
+ const series = buildTableChartSeries(rows, {
18
+ id: 'by-status',
19
+ kind: 'pie',
20
+ categoryField: 'status',
21
+ valueAgg: 'count',
22
+ })
23
+ expect(series.kind).toBe('pie')
24
+ expect(series.categories).toEqual(['ok', 'wait', 'fail'])
25
+ expect(series.values).toEqual([2, 2, 1])
26
+ })
27
+
28
+ it('sums valueField for bar', () => {
29
+ const series = buildTableChartSeries(rows, {
30
+ id: 'amount',
31
+ kind: 'bar',
32
+ categoryField: 'status',
33
+ valueField: 'amount',
34
+ valueAgg: 'sum',
35
+ })
36
+ const byName = Object.fromEntries(series.points.map((p) => [p.name, p.value]))
37
+ expect(byName.ok).toBe(30)
38
+ expect(byName.wait).toBe(20)
39
+ expect(byName.fail).toBe(3)
40
+ })
41
+
42
+ it('merges tail into other when topN set', () => {
43
+ const series = buildTableChartSeries(rows, {
44
+ id: 'top1',
45
+ kind: 'pie',
46
+ categoryField: 'status',
47
+ valueAgg: 'count',
48
+ topN: 1,
49
+ otherLabel: '其余',
50
+ })
51
+ expect(series.points).toHaveLength(2)
52
+ expect(series.points[0]?.name).toBe('ok')
53
+ expect(series.points[1]?.name).toBe('其余')
54
+ expect(series.points[1]?.value).toBe(3)
55
+ })
56
+ })
57
+
58
+ describe('useRsTableSelectionSource', () => {
59
+ it('prefers selected rows as source', () => {
60
+ const viewRows = ref(rows)
61
+ const selectedRows = ref([rows[2]!])
62
+ const src = useRsTableSelectionSource({ viewRows, selectedRows })
63
+ expect(src.sourceMode.value).toBe('selected')
64
+ expect(src.sourceRows.value).toEqual([rows[2]])
65
+ selectedRows.value = []
66
+ expect(src.sourceMode.value).toBe('view')
67
+ expect(src.sourceRows.value).toHaveLength(5)
68
+ })
69
+ })
70
+
71
+ describe('useRsTableChartBridge', () => {
72
+ it('rebuilds pie series when selection changes', () => {
73
+ const viewRows = ref(rows)
74
+ const selectedRows = ref<typeof rows>([])
75
+ const bridge = useRsTableChartBridge({
76
+ viewRows,
77
+ selectedRows,
78
+ seriesDefs: [
79
+ { id: 'status-pie', kind: 'pie', categoryField: 'status', valueAgg: 'count' },
80
+ ],
81
+ })
82
+ expect(bridge.series.value[0]?.values).toEqual([2, 2, 1])
83
+ selectedRows.value = [rows[0]!, rows[1]!]
84
+ expect(bridge.sourceMode.value).toBe('selected')
85
+ expect(bridge.series.value[0]?.categories).toEqual(['ok'])
86
+ expect(bridge.series.value[0]?.values).toEqual([2])
87
+ })
88
+ })
@@ -0,0 +1,62 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import {
3
+ aggregateColumnSummary,
4
+ buildTableSummaryCells,
5
+ hasTableSummaryConfig,
6
+ } from '../components/table/table-summary-utils'
7
+ import type { RsTableColumn } from '../components/table-utils'
8
+
9
+ type Row = { id: number; name: string; amount: number }
10
+
11
+ const columns: Array<RsTableColumn<Row> & { summary?: any }> = [
12
+ { key: 'name', title: '名称' },
13
+ {
14
+ key: 'amount',
15
+ title: '金额',
16
+ summary: { type: 'sum', formatter: (v: number | string) => `¥${v}` },
17
+ },
18
+ ]
19
+
20
+ const rows: Row[] = [
21
+ { id: 1, name: 'A', amount: 10 },
22
+ { id: 2, name: 'B', amount: 20 },
23
+ ]
24
+
25
+ describe('table-summary-utils', () => {
26
+ it('aggregates sum with formatter', () => {
27
+ const cell = aggregateColumnSummary(columns[1]!, rows)
28
+ expect(cell?.value).toBe(30)
29
+ expect(cell?.text).toBe('¥30')
30
+ })
31
+
32
+ it('builds client summary cells', () => {
33
+ const cells = buildTableSummaryCells({
34
+ columns,
35
+ rows,
36
+ mode: 'client',
37
+ })
38
+ expect(cells.find((c) => c.key === 'amount')?.text).toBe('¥30')
39
+ expect(cells.find((c) => c.key === 'name')?.text).toBe('')
40
+ })
41
+
42
+ it('uses server summaryData without local reduce', () => {
43
+ const cells = buildTableSummaryCells({
44
+ columns,
45
+ rows,
46
+ mode: 'server',
47
+ summaryData: { amount: 999 },
48
+ })
49
+ expect(cells.find((c) => c.key === 'amount')?.text).toBe('¥999')
50
+ })
51
+
52
+ it('detects summary config', () => {
53
+ expect(hasTableSummaryConfig({ columns, mode: 'client' })).toBe(true)
54
+ expect(
55
+ hasTableSummaryConfig({
56
+ columns: [{ key: 'name', title: '名称' }],
57
+ mode: 'server',
58
+ summaryData: { name: 'x' },
59
+ }),
60
+ ).toBe(true)
61
+ })
62
+ })
@@ -1,9 +1,14 @@
1
1
  import { describe, expect, it } from 'vitest'
2
2
  import {
3
3
  buildTableEntries,
4
+ buildTableTreeEntries,
5
+ buildTableTreeNodeIndex,
4
6
  clampColumnWidth,
7
+ collectTableTreeExpandableKeys,
5
8
  filterTableRows,
6
9
  filterTableRowsByColumnFilters,
10
+ filterTableTreeRows,
11
+ flattenVisibleTableTreeEntries,
7
12
  isColumnFilterActive,
8
13
  fixedCellStyle,
9
14
  groupTableRows,
@@ -12,6 +17,7 @@ import {
12
17
  resolveFixedColumnStyles,
13
18
  resolveSelectableRowKeys,
14
19
  resolveSelectAllState,
20
+ resolveTableTreeCheckState,
15
21
  resolveTableVirtualEnabled,
16
22
  selectRowKeys,
17
23
  selectRowKeysByClick,
@@ -22,6 +28,7 @@ import {
22
28
  toggleRowSelection,
23
29
  toggleSelectAll,
24
30
  toggleSortState,
31
+ toggleTableTreeCheck,
25
32
  reorderColumnKeys,
26
33
  reorderTableRows,
27
34
  resolveColumnOrder,
@@ -283,4 +290,121 @@ describe('table-utils', () => {
283
290
  const dataRows = entries.filter((entry) => entry.type === 'row')
284
291
  expect(dataRows[0].type === 'row' && dataRows[0].row.name).toBe('Gamma')
285
292
  })
293
+
294
+ it('flattens tree rows by expanded keys with depth', () => {
295
+ const treeRows = [
296
+ {
297
+ id: 'p',
298
+ name: 'Parent',
299
+ status: 'running',
300
+ count: 1,
301
+ children: [
302
+ { id: 'c1', name: 'Child1', status: 'running', count: 2 },
303
+ {
304
+ id: 'c2',
305
+ name: 'Child2',
306
+ status: 'stopped',
307
+ count: 3,
308
+ children: [{ id: 'g1', name: 'Grand', status: 'running', count: 4 }],
309
+ },
310
+ ],
311
+ },
312
+ ]
313
+ const collapsed = flattenVisibleTableTreeEntries(treeRows, new Set(), { rowKey: 'id' })
314
+ expect(collapsed.map((e) => e.row.id)).toEqual(['p'])
315
+ expect(collapsed[0]?.depth).toBe(0)
316
+ expect(collapsed[0]?.hasChildren).toBe(true)
317
+
318
+ const expanded = flattenVisibleTableTreeEntries(treeRows, new Set(['p', 'c2']), { rowKey: 'id' })
319
+ expect(expanded.map((e) => e.row.id)).toEqual(['p', 'c1', 'c2', 'g1'])
320
+ expect(expanded.map((e) => e.depth)).toEqual([0, 1, 1, 2])
321
+ })
322
+
323
+ it('collects expandable keys and filters tree keeping ancestors', () => {
324
+ const treeRows = [
325
+ {
326
+ id: 'p',
327
+ name: 'Parent',
328
+ status: 'running',
329
+ count: 1,
330
+ children: [
331
+ { id: 'c1', name: 'AlphaChild', status: 'running', count: 2 },
332
+ { id: 'c2', name: 'BetaChild', status: 'stopped', count: 3 },
333
+ ],
334
+ },
335
+ ]
336
+ expect(collectTableTreeExpandableKeys(treeRows, { rowKey: 'id' })).toEqual(['p'])
337
+
338
+ const filtered = filterTableTreeRows(treeRows, 'Alpha', columns, { childrenField: 'children' })
339
+ expect(filtered).toHaveLength(1)
340
+ expect(filtered[0]?.id).toBe('p')
341
+ expect((filtered[0] as { children: typeof treeRows }).children.map((c) => c.id)).toEqual(['c1'])
342
+ })
343
+
344
+ it('builds tree entries with sibling sort', () => {
345
+ const treeRows = [
346
+ {
347
+ id: 'p',
348
+ name: 'Parent',
349
+ status: 'running',
350
+ count: 1,
351
+ children: [
352
+ { id: 'c2', name: 'Beta', status: 'stopped', count: 3 },
353
+ { id: 'c1', name: 'Alpha', status: 'running', count: 2 },
354
+ ],
355
+ },
356
+ ]
357
+ const entries = buildTableTreeEntries(treeRows, columns, new Set(['p']), {
358
+ tree: { childrenField: 'children', expandColumnKey: 'name' },
359
+ rowKey: 'id',
360
+ sort: { key: 'name', order: 'asc' },
361
+ })
362
+ expect(entries.filter((e) => e.type === 'row').map((e) => (e.type === 'row' ? e.row.id : ''))).toEqual([
363
+ 'p',
364
+ 'c1',
365
+ 'c2',
366
+ ])
367
+ })
368
+
369
+ it('uses path fallback keys when rowKey missing to avoid sibling collisions', () => {
370
+ const treeRows = [
371
+ {
372
+ name: 'A',
373
+ status: 'running',
374
+ count: 1,
375
+ children: [{ name: 'A1', status: 'running', count: 2 }],
376
+ },
377
+ {
378
+ name: 'B',
379
+ status: 'stopped',
380
+ count: 3,
381
+ children: [{ name: 'B1', status: 'stopped', count: 4 }],
382
+ },
383
+ ]
384
+ const expanded = flattenVisibleTableTreeEntries(treeRows, new Set(['tree:0', 'tree:1']))
385
+ const keys = expanded.map((e) => e.treeKey)
386
+ expect(keys).toEqual(['tree:0', 'tree:0/0', 'tree:1', 'tree:1/0'])
387
+ })
388
+
389
+ it('cascades tree check when checkStrictly is false', () => {
390
+ const treeRows = [
391
+ {
392
+ id: 'p',
393
+ name: 'Parent',
394
+ status: 'running',
395
+ count: 1,
396
+ children: [
397
+ { id: 'c1', name: 'C1', status: 'running', count: 2 },
398
+ { id: 'c2', name: 'C2', status: 'stopped', count: 3 },
399
+ ],
400
+ },
401
+ ]
402
+ const index = buildTableTreeNodeIndex(treeRows, { rowKey: 'id' })
403
+ const checked = toggleTableTreeCheck('c1', new Set(), index, false)
404
+ expect(checked.sort()).toEqual(['c1'])
405
+ expect(resolveTableTreeCheckState('p', new Set(checked), index, false)).toBe('indeterminate')
406
+
407
+ const all = toggleTableTreeCheck('p', new Set(), index, false)
408
+ expect(all.sort()).toEqual(['c1', 'c2', 'p'])
409
+ })
286
410
  })
@@ -1,6 +1,13 @@
1
1
  import { describe, expect, it } from 'vitest'
2
2
  import { createRsConfigState } from '../composables/useRsConfig'
3
3
  import { applyTheme } from '../theme/apply'
4
+ import { themePresets } from '../theme/presets'
5
+ import {
6
+ RS_FONT_SIZES,
7
+ RS_FONT_SIZE_CSS,
8
+ RS_FONT_WEIGHTS,
9
+ RS_FONT_WEIGHT_CSS,
10
+ } from '../theme/types'
4
11
 
5
12
  describe('useRsConfig / theme', () => {
6
13
  it('translates by locale', () => {
@@ -19,4 +26,22 @@ describe('useRsConfig / theme', () => {
19
26
  applyTheme('dark')
20
27
  expect(document.documentElement.dataset.rsTheme).toBe('dark')
21
28
  })
29
+
30
+ it('exposes typography token ladders', () => {
31
+ expect(RS_FONT_SIZES).toEqual(['xs', 'sm', 'base', 'lg', 'xl', '2xl', '3xl'])
32
+ expect(RS_FONT_SIZE_CSS['3xl']).toBe('var(--rs-font-size-3xl)')
33
+ expect(RS_FONT_WEIGHTS).toEqual(['regular', 'medium', 'semibold', 'bold'])
34
+ expect(RS_FONT_WEIGHT_CSS.semibold).toBe('var(--rs-font-weight-semibold)')
35
+ })
36
+
37
+ it('theme presets include text semantic fields', () => {
38
+ for (const mode of ['light', 'dark'] as const) {
39
+ const p = themePresets[mode]
40
+ expect(p.text).toBeTruthy()
41
+ expect(p.muted).toBeTruthy()
42
+ expect(p.placeholder).toBeTruthy()
43
+ expect(p.textDisabled).toBeTruthy()
44
+ expect(p.textInverse).toBe('#ffffff')
45
+ }
46
+ })
22
47
  })
@@ -0,0 +1,25 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { measureRsTablePrefixWidth } from '../composables/useRsTableColumnVirtual'
3
+
4
+ describe('measureRsTablePrefixWidth', () => {
5
+ it('sums visible prefix columns only', () => {
6
+ expect(
7
+ measureRsTablePrefixWidth({
8
+ showRowDragHandle: true,
9
+ detailExpandable: true,
10
+ showSelectColumn: true,
11
+ showIndexColumn: true,
12
+ indexWidth: 48,
13
+ }),
14
+ ).toBe(40 + 40 + 40 + 48)
15
+
16
+ expect(
17
+ measureRsTablePrefixWidth({
18
+ showEditGutterColumn: true,
19
+ gutterWidth: 32,
20
+ showIndexColumn: true,
21
+ indexWidth: 48,
22
+ }),
23
+ ).toBe(32)
24
+ })
25
+ })