niuma-ui 1.0.1 → 1.1.0
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/CHANGELOG.md +65 -1
- package/package.json +10 -2
- package/src/__tests__/RsButton.spec.ts +47 -0
- package/src/__tests__/RsCard.spec.ts +160 -1
- package/src/__tests__/RsConfirmDialog.spec.ts +127 -0
- package/src/__tests__/RsContextMenu.spec.ts +12 -0
- package/src/__tests__/RsDatePicker.spec.ts +21 -0
- package/src/__tests__/RsDateTimePicker.spec.ts +11 -0
- package/src/__tests__/RsDescriptions.spec.ts +50 -0
- package/src/__tests__/RsDialog.spec.ts +178 -0
- package/src/__tests__/RsDrawer.spec.ts +96 -3
- package/src/__tests__/RsDynamicTags.spec.ts +52 -0
- package/src/__tests__/RsForm.spec.ts +250 -6
- package/src/__tests__/RsFormItem.spec.ts +478 -0
- package/src/__tests__/RsFormList.spec.ts +109 -0
- package/src/__tests__/RsInput.spec.ts +108 -1
- package/src/__tests__/RsInputNumber.spec.ts +33 -0
- package/src/__tests__/RsMenu.spec.ts +406 -14
- package/src/__tests__/RsPagination.spec.ts +67 -2
- package/src/__tests__/RsSelect.spec.ts +465 -2
- package/src/__tests__/RsSwitch.spec.ts +74 -0
- package/src/__tests__/RsTable.a11y.spec.ts +83 -0
- package/src/__tests__/RsTable.dom-baseline.spec.ts +87 -0
- package/src/__tests__/RsTable.perf.spec.ts +23 -4
- package/src/__tests__/RsTable.spec.ts +63 -8
- package/src/__tests__/RsTable.ssr.spec.ts +71 -0
- package/src/__tests__/RsTable.summary.spec.ts +45 -0
- package/src/__tests__/RsTabs.spec.ts +102 -4
- package/src/__tests__/RsTimePicker.spec.ts +20 -0
- package/src/__tests__/RsTooltip.spec.ts +43 -0
- package/src/__tests__/RsUpload.spec.ts +62 -6
- package/src/__tests__/createRsDialog.spec.ts +145 -0
- package/src/__tests__/css-token.spec.ts +51 -0
- package/src/__tests__/date-picker-utils.spec.ts +49 -0
- package/src/__tests__/dialog-utils.spec.ts +43 -0
- package/src/__tests__/form-path.spec.ts +46 -0
- package/src/__tests__/form-rules.spec.ts +139 -0
- package/src/__tests__/perf-budgets.ts +32 -0
- package/src/__tests__/rs-table-api.spec.ts +206 -0
- package/src/__tests__/rs-table-compat-matrix.spec.ts +108 -0
- package/src/__tests__/rs-table-echarts-adapter.spec.ts +43 -0
- package/src/__tests__/rs-table-grid-nav.spec.ts +63 -0
- package/src/__tests__/rs-table-isolation.spec.ts +158 -0
- package/src/__tests__/split-pane-utils.spec.ts +21 -0
- package/src/__tests__/table-chart-utils.spec.ts +88 -0
- package/src/__tests__/table-summary-utils.spec.ts +62 -0
- package/src/__tests__/table-utils.spec.ts +124 -0
- package/src/__tests__/theme.spec.ts +27 -0
- package/src/__tests__/useRsTableColumnResize.spec.ts +25 -0
- package/src/__tests__/useRsTableCore.perf.spec.ts +170 -0
- package/src/components/RsAlert.vue +212 -0
- package/src/components/RsAvatar.vue +1 -1
- package/src/components/RsBadge.vue +1 -1
- package/src/components/RsBreadcrumb.vue +1 -1
- package/src/components/RsButton.vue +147 -23
- package/src/components/RsCalendarGrid.vue +3 -3
- package/src/components/RsCard.vue +204 -20
- package/src/components/RsCodeBlock.vue +4 -4
- package/src/components/RsCodeEditor.vue +8 -8
- package/src/components/RsConfirmDialog.vue +217 -30
- package/src/components/RsContextMenu.vue +57 -17
- package/src/components/RsDatePicker.vue +316 -39
- package/src/components/RsDateTimePicker.vue +27 -2
- package/src/components/RsDescriptions.vue +186 -0
- package/src/components/RsDescriptionsItem.vue +32 -0
- package/src/components/RsDialog.vue +374 -52
- package/src/components/RsDivider.vue +89 -0
- package/src/components/RsDrawer.vue +559 -34
- package/src/components/RsDropdown.vue +34 -3
- package/src/components/RsDynamicTags.vue +531 -0
- package/src/components/RsEmpty.vue +1 -1
- package/src/components/RsForm.vue +164 -8
- package/src/components/RsFormItem.vue +423 -0
- package/src/components/RsFormItemControl.vue +21 -0
- package/src/components/RsFormList.vue +117 -0
- package/src/components/RsInput.vue +491 -100
- package/src/components/RsInputNumber.vue +77 -27
- package/src/components/RsLabel.vue +20 -5
- package/src/components/RsLink.vue +1 -1
- package/src/components/RsLoadingBar.vue +151 -0
- package/src/components/RsMarkdown.vue +5 -5
- package/src/components/RsMenu.vue +74 -16
- package/src/components/RsMenuItems.vue +147 -9
- package/src/components/RsMonacoEditor.vue +9 -3
- package/src/components/RsPagination.vue +93 -14
- package/src/components/RsProseEditor.vue +3 -3
- package/src/components/RsRadio.vue +81 -0
- package/src/components/RsRadioItem.vue +156 -0
- package/src/components/RsSelect.vue +372 -642
- package/src/components/RsSidebarGroup.vue +1 -1
- package/src/components/RsSplitPane.vue +90 -1
- package/src/components/RsStatCard.vue +2 -2
- package/src/components/RsSteps.vue +2 -2
- package/src/components/RsSwitch.vue +192 -0
- package/src/components/RsTable.vue +653 -2555
- package/src/components/RsTabs.vue +422 -90
- package/src/components/RsTag.vue +191 -0
- package/src/components/RsTerminal.vue +58 -19
- package/src/components/RsTimePicker.vue +72 -9
- package/src/components/RsTimePickerColumns.vue +137 -78
- package/src/components/RsToaster.vue +64 -24
- package/src/components/RsTooltip.vue +10 -1
- package/src/components/RsTooltipProvider.vue +11 -1
- package/src/components/RsTree.vue +45 -27
- package/src/components/RsUpload.vue +147 -14
- package/src/components/RsVNodeHost.vue +20 -0
- package/src/components/button-utils.ts +39 -0
- package/src/components/context-menu-utils.ts +6 -0
- package/src/components/date-picker-utils.ts +195 -4
- package/src/components/descriptions-utils.ts +24 -0
- package/src/components/dialog-utils.ts +182 -0
- package/src/components/dialog-window.ts +74 -9
- package/src/components/drawer-utils.ts +73 -0
- package/src/components/form-item-control.ts +55 -0
- package/src/components/form-path.ts +92 -0
- package/src/components/form-rules.ts +311 -0
- package/src/components/form-utils.ts +145 -3
- package/src/components/menu-utils.ts +11 -0
- package/src/components/overlay-utils.ts +3 -0
- package/src/components/radio-utils.ts +12 -0
- package/src/components/reka.ts +5 -0
- package/src/components/select-utils.ts +285 -6
- package/src/components/split-pane-utils.ts +65 -12
- package/src/components/table/RsTableBody.vue +217 -0
- package/src/components/table/RsTableBodyRow.vue +90 -1
- package/src/components/table/RsTableColGroup.vue +41 -0
- package/src/components/table/RsTableHeader.vue +158 -0
- package/src/components/table/RsTableHeaderFilter.vue +1 -1
- package/src/components/table/RsTableSummaryRow.vue +52 -0
- package/src/components/table/rs-table-api.ts +99 -0
- package/src/components/table/rs-table-compat-matrix.ts +71 -0
- package/src/components/table/rs-table-echarts-adapter.ts +81 -0
- package/src/components/table/rs-table-feature-host.ts +178 -0
- package/src/components/table/rs-table-grid-nav.ts +122 -0
- package/src/components/table/rs-table-header-types.ts +47 -0
- package/src/components/table/rs-table-module-registry.ts +72 -0
- package/src/components/table/rs-table-props.ts +274 -0
- package/src/components/table/rs-table-view-context.ts +258 -0
- package/src/components/table/rs-table.css +85 -7
- package/src/components/table/table-chart-utils.ts +165 -0
- package/src/components/table/table-features.ts +284 -0
- package/src/components/table/table-summary-utils.ts +194 -0
- package/src/components/table-utils.ts +452 -2
- package/src/components/tabs-utils.ts +142 -2
- package/src/components/time-picker-utils.ts +76 -3
- package/src/components/upload-utils.ts +122 -0
- package/src/components/use-rs-select.ts +436 -0
- package/src/components/virtual-list-utils.ts +15 -2
- package/src/composables/assembleRsTableApi.ts +79 -0
- package/src/composables/bindRsTableViewContext.ts +269 -0
- package/src/composables/createRsDialog.ts +357 -0
- package/src/composables/createRsTableEditEmitBridge.ts +38 -0
- package/src/composables/useRsConfig.ts +10 -3
- package/src/composables/useRsI18n.ts +16 -5
- package/src/composables/useRsLoadingBar.ts +36 -0
- package/src/composables/useRsTable.ts +134 -0
- package/src/composables/useRsTableA11y.ts +52 -0
- package/src/composables/useRsTableChartBridge.ts +79 -0
- package/src/composables/useRsTableColumnLayout.ts +320 -0
- package/src/composables/useRsTableColumnResize.ts +244 -0
- package/src/composables/useRsTableColumnVirtual.ts +180 -0
- package/src/composables/useRsTableColumns.ts +200 -0
- package/src/composables/useRsTableContextMenu.ts +257 -0
- package/src/composables/useRsTableCore.ts +256 -0
- package/src/composables/useRsTableEditActions.ts +606 -0
- package/src/composables/useRsTableEditLayer.ts +251 -0
- package/src/composables/useRsTableEngine.ts +357 -0
- package/src/composables/useRsTableGridKeyboard.ts +123 -0
- package/src/composables/useRsTableHeadless.ts +137 -0
- package/src/composables/useRsTableInteraction.ts +433 -0
- package/src/composables/useRsTableScrollHost.ts +75 -0
- package/src/composables/useRsTableScrollLayout.ts +255 -0
- package/src/composables/useRsTableSelectionSource.ts +89 -0
- package/src/composables/useRsTableShell.ts +416 -0
- package/src/composables/useRsTableShellChrome.ts +170 -0
- package/src/composables/useRsTableSummary.ts +113 -0
- package/src/composables/useRsTableViewProvide.ts +263 -0
- package/src/composables/useRsTableVirtual.ts +154 -0
- package/src/composables/useRsTabsNav.ts +4 -0
- package/src/composables/useTableEdit.ts +1 -1
- package/src/index.ts +378 -10
- package/src/locale/interpolate.ts +32 -0
- package/src/locale/messages.ts +40 -0
- package/src/styles.css +365 -56
- package/src/theme/brand.example.css +24 -2
- package/src/theme/css-token.ts +107 -0
- package/src/theme/presets.ts +4 -0
- package/src/theme/types.ts +68 -0
- package/src/components/RsTableColgroup.vue +0 -17
- package/src/components/RsTableHeaderRow.vue +0 -30
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RsTable 视图上下文(provide/inject)。
|
|
3
|
+
*
|
|
4
|
+
* 多表隔离(关键):
|
|
5
|
+
* - 每个 RsTable 实例在自身 setup 内 provide,子树 inject 最近祖先
|
|
6
|
+
* - 同页多表互不影响:A 的 Header/Body 不会读到 B 的 view
|
|
7
|
+
* - 禁止把 view 存到模块级单例;instanceId 仅用于诊断
|
|
8
|
+
*
|
|
9
|
+
* 对比:RsTableModuleRegistry 是进程级全局(同 AG Grid ModuleRegistry),
|
|
10
|
+
* 会作用于所有实例;实例专属能力请用 props.features。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { inject, provide, type InjectionKey } from 'vue'
|
|
14
|
+
import type { CSSProperties } from 'vue'
|
|
15
|
+
import type {
|
|
16
|
+
RsTableColumn,
|
|
17
|
+
RsTableRowData,
|
|
18
|
+
RsTableRowDropPosition,
|
|
19
|
+
RsTableRowEntry,
|
|
20
|
+
RsTableRowKey,
|
|
21
|
+
RsTableSelectionType,
|
|
22
|
+
} from '../table-utils'
|
|
23
|
+
import type {
|
|
24
|
+
RsTableCellEditFocusMode,
|
|
25
|
+
RsTableCellEditTrigger,
|
|
26
|
+
RsTableCellNavigateDirection,
|
|
27
|
+
} from './table-edit-utils'
|
|
28
|
+
|
|
29
|
+
/** 每实例递增,仅诊断用,不参与业务逻辑 */
|
|
30
|
+
let viewInstanceSeq = 0
|
|
31
|
+
|
|
32
|
+
export const RS_TABLE_VIEW_KEY: InjectionKey<RsTableViewContext> = Symbol('rsTableView')
|
|
33
|
+
|
|
34
|
+
/** 视图层内联样式(Vue CSSProperties 或普通字符串字典) */
|
|
35
|
+
export type RsTableViewStyle = CSSProperties | Record<string, string> | undefined
|
|
36
|
+
|
|
37
|
+
export type RsTableHeaderLabels = {
|
|
38
|
+
selectAll: string
|
|
39
|
+
index: string
|
|
40
|
+
rowStatus: string
|
|
41
|
+
dragColumn: string
|
|
42
|
+
filterColumn: string
|
|
43
|
+
filterPlaceholder: string
|
|
44
|
+
filterClear: string
|
|
45
|
+
filterApply: string
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type RsTableBodyLabels = {
|
|
49
|
+
loading: string
|
|
50
|
+
empty: string
|
|
51
|
+
loadingMore: string
|
|
52
|
+
dragRow: string
|
|
53
|
+
expandRow: string
|
|
54
|
+
collapseRow: string
|
|
55
|
+
selectRow: string
|
|
56
|
+
rowCommit: string
|
|
57
|
+
rowRollback: string
|
|
58
|
+
gutterCommit: string
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
type RowEntry<T extends RsTableRowData> = Extract<RsTableRowEntry<T>, { type: 'row' }>
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 视图只读状态 + 事件处理。
|
|
65
|
+
* 状态字段经 getter 暴露,子组件 render 访问时收集依赖;多表各自刷新、互不串扰。
|
|
66
|
+
*/
|
|
67
|
+
export interface RsTableViewContext<T extends RsTableRowData = RsTableRowData> {
|
|
68
|
+
readonly instanceId: string
|
|
69
|
+
|
|
70
|
+
readonly useFixedColumnLayout: boolean
|
|
71
|
+
readonly showRowDragHandle: boolean
|
|
72
|
+
readonly detailExpandable: boolean
|
|
73
|
+
readonly showSelectColumn: boolean
|
|
74
|
+
readonly showEditGutterColumn: boolean
|
|
75
|
+
readonly showIndexColumn: boolean
|
|
76
|
+
readonly showRowStatusColumn: boolean
|
|
77
|
+
readonly columnPadLeft: number
|
|
78
|
+
readonly columnPadRight: number
|
|
79
|
+
readonly visibleDataColumns: RsTableColumn<T>[]
|
|
80
|
+
readonly prefixWidths: { drag: number; expand: number; select: number; status: number }
|
|
81
|
+
readonly resolvedGutterWidth: number
|
|
82
|
+
readonly resolvedIndexWidth: number
|
|
83
|
+
resolvedDataColumnWidth: (key: string, fallback?: number | string) => number
|
|
84
|
+
|
|
85
|
+
readonly isRadioSelection: boolean
|
|
86
|
+
readonly selectAllState: 'checked' | 'indeterminate' | 'unchecked'
|
|
87
|
+
readonly columnDraggable: boolean
|
|
88
|
+
readonly resizable: boolean
|
|
89
|
+
readonly multiSort: boolean
|
|
90
|
+
readonly columnFiltersState: Record<string, string>
|
|
91
|
+
readonly dragColumnKey: string | null
|
|
92
|
+
readonly dropColumnKey: string | null
|
|
93
|
+
readonly dragLeadHeaderStyle: RsTableViewStyle
|
|
94
|
+
readonly expandLeadHeaderStyle: RsTableViewStyle
|
|
95
|
+
readonly selectLeadHeaderStyle: RsTableViewStyle
|
|
96
|
+
readonly gutterLeadHeaderStyle: RsTableViewStyle
|
|
97
|
+
readonly indexLeadHeaderStyle: RsTableViewStyle
|
|
98
|
+
readonly columnHeaderStyleMap: Map<string, Record<string, string> | undefined>
|
|
99
|
+
readonly headerLabels: RsTableHeaderLabels
|
|
100
|
+
columnFilterValue: (key: string) => string
|
|
101
|
+
isColumnFilterActive: (filters: Record<string, string>, key: string) => boolean
|
|
102
|
+
sortOrderFor: (key: string) => string | null | undefined
|
|
103
|
+
sortPriorityFor: (key: string) => number
|
|
104
|
+
sortIconName: (key: string) => string
|
|
105
|
+
onToggleSelectAll: () => void
|
|
106
|
+
onColumnDragOver: (key: string, event: DragEvent) => void
|
|
107
|
+
onColumnDrop: (key: string, event: DragEvent) => void
|
|
108
|
+
onColumnDragStart: (key: string, event: DragEvent) => void
|
|
109
|
+
onColumnDragEnd: () => void
|
|
110
|
+
updateColumnFilter: (key: string, value: string) => void
|
|
111
|
+
onHeaderClick: (column: RsTableColumn<T>) => void
|
|
112
|
+
onResizeStart: (key: string, event: MouseEvent) => void
|
|
113
|
+
onHeaderPointerOver: (event: PointerEvent) => void
|
|
114
|
+
onHeaderPointerOut: (event: PointerEvent) => void
|
|
115
|
+
|
|
116
|
+
readonly loading: boolean
|
|
117
|
+
readonly hasData: boolean
|
|
118
|
+
readonly loadingMore: boolean
|
|
119
|
+
readonly infinite: boolean
|
|
120
|
+
readonly bodyColspan: number
|
|
121
|
+
readonly emptyContentStyle: RsTableViewStyle
|
|
122
|
+
readonly virtualScrollEnabled: boolean
|
|
123
|
+
readonly virtualSlice: { paddingTop: number; paddingBottom: number }
|
|
124
|
+
readonly visibleEntries: RsTableRowEntry<T>[]
|
|
125
|
+
readonly rowKey: RsTableRowKey<T> | undefined
|
|
126
|
+
readonly treeMode: boolean
|
|
127
|
+
readonly treeIndentPx: number
|
|
128
|
+
readonly treeExpandColumnKey: string | null
|
|
129
|
+
readonly treeLoadingKeySet: Set<string>
|
|
130
|
+
readonly striped: boolean
|
|
131
|
+
readonly selectionType: RsTableSelectionType
|
|
132
|
+
readonly editable: boolean
|
|
133
|
+
readonly editTrigger: RsTableCellEditTrigger
|
|
134
|
+
readonly rowCommit: boolean
|
|
135
|
+
readonly allowNull: boolean
|
|
136
|
+
readonly editFocusMode: RsTableCellEditFocusMode
|
|
137
|
+
readonly nullLabel: string
|
|
138
|
+
readonly dragLeadStyle: Record<string, string>
|
|
139
|
+
readonly expandLeadStyle: Record<string, string>
|
|
140
|
+
readonly selectLeadStyle: Record<string, string>
|
|
141
|
+
readonly indexLeadStyle: Record<string, string>
|
|
142
|
+
readonly gutterLeadStyle: Record<string, string>
|
|
143
|
+
readonly columnTdClassMap: Map<string, string[]>
|
|
144
|
+
readonly columnStyleMap: Map<string, Record<string, string> | undefined>
|
|
145
|
+
readonly dragRowKeys: string[]
|
|
146
|
+
readonly dropRowTargetKey: string | null
|
|
147
|
+
readonly dropRowPosition: RsTableRowDropPosition | null
|
|
148
|
+
readonly activeEditCellKey: string
|
|
149
|
+
readonly activeFocusCellKey: string
|
|
150
|
+
readonly activeErrorMapSize: number
|
|
151
|
+
readonly activeValidatingMapSize: number
|
|
152
|
+
readonly stagedMapSize: number
|
|
153
|
+
readonly editingDraft: string
|
|
154
|
+
readonly editingCell: { rowKey: string; colKey: string } | null
|
|
155
|
+
readonly focusCell: { rowKey: string; colKey: string } | null
|
|
156
|
+
readonly bodyLabels: RsTableBodyLabels
|
|
157
|
+
rowKeyFor: (entry: RowEntry<T>) => string
|
|
158
|
+
isRowSelected: (entry: RowEntry<T>) => boolean
|
|
159
|
+
isRowIndeterminate: (entry: RowEntry<T>) => boolean
|
|
160
|
+
isRowExpanded: (entry: RowEntry<T>) => boolean
|
|
161
|
+
isHighlighted: (rowKey: string) => boolean
|
|
162
|
+
rowEditPending: (entry: RowEntry<T>) => boolean
|
|
163
|
+
isExternalRowPending: (entry: RowEntry<T>) => boolean
|
|
164
|
+
treeDepthOf: (entry: RowEntry<T>) => number
|
|
165
|
+
canExpandRow: (entry: RowEntry<T>) => boolean
|
|
166
|
+
canSelectRow: (entry: RowEntry<T>) => boolean
|
|
167
|
+
isRowDragByRow: (entry: RowEntry<T>) => boolean
|
|
168
|
+
isRowDragging: (entry: RowEntry<T>) => boolean
|
|
169
|
+
isRowDropTarget: (entry: RowEntry<T>) => boolean
|
|
170
|
+
isRowDirty: (rowKey: string) => boolean
|
|
171
|
+
hasColumnSlot: (key: string) => boolean
|
|
172
|
+
hasEditSlot: (key: string) => boolean
|
|
173
|
+
cellTooltipEnabled: (column: RsTableColumn<T>, rowIndex: number) => boolean
|
|
174
|
+
cellTooltipMode: (column: RsTableColumn<T>, rowIndex: number) => string | undefined
|
|
175
|
+
cellTooltipText: (column: RsTableColumn<T>, row: T, rowIndex: number) => string | undefined
|
|
176
|
+
cellTooltipFallbackTitle: (column: RsTableColumn<T>, row: T, rowIndex: number) => string | undefined
|
|
177
|
+
getCellDraft: (rowKey: string, colKey: string) => string | undefined
|
|
178
|
+
isCellDirty: (rowKey: string, colKey: string) => boolean
|
|
179
|
+
getCellError: (rowKey: string, colKey: string) => string | undefined
|
|
180
|
+
isCellValidating: (rowKey: string, colKey: string) => boolean
|
|
181
|
+
onBodyPointerOver: (event: PointerEvent) => void
|
|
182
|
+
onBodyPointerOut: (event: PointerEvent) => void
|
|
183
|
+
onRowClick: (entry: RowEntry<T>, event: MouseEvent) => void
|
|
184
|
+
onRowSelectMouseDown: (event: MouseEvent) => void
|
|
185
|
+
onCellClick: (entry: RowEntry<T>, colKey: string, event: MouseEvent) => void
|
|
186
|
+
onCellDblclick: (entry: RowEntry<T>, colKey: string, event: MouseEvent) => void
|
|
187
|
+
onCellContextmenu: (entry: RowEntry<T>, colKey: string, event: MouseEvent) => void
|
|
188
|
+
onRowDblclick: (entry: RowEntry<T>, event: MouseEvent) => void
|
|
189
|
+
onRowContextmenu: (entry: RowEntry<T>, event: MouseEvent) => void
|
|
190
|
+
onRowDragOver: (entry: RowEntry<T>, event: DragEvent) => void
|
|
191
|
+
onRowDragLeave: (event: DragEvent) => void
|
|
192
|
+
onRowDrop: (entry: RowEntry<T>, event: DragEvent) => void
|
|
193
|
+
onRowDragStart: (entry: RowEntry<T>, event: DragEvent) => void
|
|
194
|
+
onRowDragEnd: () => void
|
|
195
|
+
onToggleExpand: (entry: RowEntry<T>) => void
|
|
196
|
+
onToggleSelect: (entry: RowEntry<T>) => void
|
|
197
|
+
onCellStartEdit: (entry: RowEntry<T>, colKey: string) => void
|
|
198
|
+
onCellCommit: (entry: RowEntry<T>, colKey: string, value: string) => void
|
|
199
|
+
onCellCancel: (entry: RowEntry<T>, colKey: string) => void
|
|
200
|
+
onCellUpdateDraft: (entry: RowEntry<T>, colKey: string, value: string) => void
|
|
201
|
+
onCellNavigate: (
|
|
202
|
+
entry: RowEntry<T>,
|
|
203
|
+
colKey: string,
|
|
204
|
+
direction: RsTableCellNavigateDirection,
|
|
205
|
+
) => void
|
|
206
|
+
onRowCommit: (entry: RowEntry<T>) => void
|
|
207
|
+
onRowRollback: (entry: RowEntry<T>) => void
|
|
208
|
+
onGutterCommit: (entry: RowEntry<T>) => void
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* 显式区分 state getters 与 handlers,避免把零参 handler 误当成状态 getter。
|
|
213
|
+
*/
|
|
214
|
+
export function createRsTableViewContext<T extends RsTableRowData>(parts: {
|
|
215
|
+
state: { [K in keyof RsTableViewContext<T>]?: () => RsTableViewContext<T>[K] }
|
|
216
|
+
handlers: { [K in keyof RsTableViewContext<T>]?: RsTableViewContext<T>[K] }
|
|
217
|
+
}): RsTableViewContext<T> {
|
|
218
|
+
const instanceId = `rs-table-view-${++viewInstanceSeq}`
|
|
219
|
+
const ctx: Record<string, unknown> = { instanceId }
|
|
220
|
+
for (const [key, getter] of Object.entries(parts.state)) {
|
|
221
|
+
if (!getter) continue
|
|
222
|
+
Object.defineProperty(ctx, key, {
|
|
223
|
+
enumerable: true,
|
|
224
|
+
configurable: true,
|
|
225
|
+
get: getter as () => unknown,
|
|
226
|
+
})
|
|
227
|
+
}
|
|
228
|
+
for (const [key, fn] of Object.entries(parts.handlers)) {
|
|
229
|
+
if (fn !== undefined) ctx[key] = fn
|
|
230
|
+
}
|
|
231
|
+
return ctx as unknown as RsTableViewContext<T>
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** 在 RsTable 内 provide(每个实例调用一次) */
|
|
235
|
+
export function provideRsTableView<T extends RsTableRowData>(ctx: RsTableViewContext<T>): void {
|
|
236
|
+
// 与 useRsTableView 对称:泛型 T 与默认 object 行类型在函数/数组位不重叠,经 unknown 擦除
|
|
237
|
+
provide(RS_TABLE_VIEW_KEY, ctx as unknown as RsTableViewContext)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* 子视图 inject;必须在某个 RsTable 子树内。
|
|
242
|
+
* 多表场景下自动绑定到最近的表格实例。
|
|
243
|
+
*/
|
|
244
|
+
export function useRsTableView<T extends RsTableRowData = RsTableRowData>(): RsTableViewContext<T> {
|
|
245
|
+
const ctx = inject(RS_TABLE_VIEW_KEY, null)
|
|
246
|
+
if (!ctx) {
|
|
247
|
+
throw new Error(
|
|
248
|
+
'[RsTable] useRsTableView() 必须在 RsTable 子树内调用(每表独立 provide,多表互不串扰)',
|
|
249
|
+
)
|
|
250
|
+
}
|
|
251
|
+
// InjectionKey 无泛型实参;经 unknown 收窄到调用方 T(实例隔离由 provide 树保证)
|
|
252
|
+
return ctx as unknown as RsTableViewContext<T>
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** 测试用:重置 instance 序号 */
|
|
256
|
+
export function resetRsTableViewInstanceSeqForTest(): void {
|
|
257
|
+
viewInstanceSeq = 0
|
|
258
|
+
}
|
|
@@ -130,6 +130,18 @@
|
|
|
130
130
|
font-size: var(--rs-table-cell-size, var(--rs-font-size-xs));
|
|
131
131
|
font-weight: var(--rs-table-cell-weight, 400);
|
|
132
132
|
}
|
|
133
|
+
/* showHeader=false:保留 th 供 AT / 静态表头规则,视觉隐藏 */
|
|
134
|
+
.rs-table__head--sr-only {
|
|
135
|
+
position: absolute;
|
|
136
|
+
width: 1px;
|
|
137
|
+
height: 1px;
|
|
138
|
+
padding: 0;
|
|
139
|
+
margin: -1px;
|
|
140
|
+
overflow: hidden;
|
|
141
|
+
clip: rect(0, 0, 0, 0);
|
|
142
|
+
white-space: nowrap;
|
|
143
|
+
border: 0;
|
|
144
|
+
}
|
|
133
145
|
.rs-table__th,
|
|
134
146
|
.rs-table__td {
|
|
135
147
|
padding: var(--rs-space-sm) var(--rs-space-md);
|
|
@@ -295,6 +307,35 @@
|
|
|
295
307
|
.rs-table__expand-btn--expanded {
|
|
296
308
|
transform: rotate(90deg);
|
|
297
309
|
}
|
|
310
|
+
.rs-table__tree-cell {
|
|
311
|
+
display: flex;
|
|
312
|
+
align-items: center;
|
|
313
|
+
gap: 0.125rem;
|
|
314
|
+
min-width: 0;
|
|
315
|
+
width: 100%;
|
|
316
|
+
}
|
|
317
|
+
.rs-table__tree-toggle {
|
|
318
|
+
flex: 0 0 auto;
|
|
319
|
+
}
|
|
320
|
+
.rs-table__tree-toggle--loading {
|
|
321
|
+
opacity: 0.5;
|
|
322
|
+
cursor: wait;
|
|
323
|
+
}
|
|
324
|
+
.rs-table__tree-leaf {
|
|
325
|
+
display: inline-flex;
|
|
326
|
+
flex: 0 0 auto;
|
|
327
|
+
width: 1.25rem;
|
|
328
|
+
height: 1.25rem;
|
|
329
|
+
}
|
|
330
|
+
.rs-table__tree-content {
|
|
331
|
+
display: inline-flex;
|
|
332
|
+
align-items: center;
|
|
333
|
+
min-width: 0;
|
|
334
|
+
flex: 1 1 auto;
|
|
335
|
+
}
|
|
336
|
+
.rs-table__td--tree {
|
|
337
|
+
overflow: hidden;
|
|
338
|
+
}
|
|
298
339
|
.rs-table__expand-row {
|
|
299
340
|
background: var(--rs-table-expand-bg);
|
|
300
341
|
}
|
|
@@ -312,6 +353,26 @@
|
|
|
312
353
|
color: var(--rs-table-muted-fg);
|
|
313
354
|
font-weight: var(--rs-table-header-weight);
|
|
314
355
|
}
|
|
356
|
+
.rs-table__summary-row .rs-table__summary-cell {
|
|
357
|
+
padding: var(--rs-space-sm) var(--rs-space-md);
|
|
358
|
+
color: var(--rs-table-muted-fg);
|
|
359
|
+
font-weight: var(--rs-table-header-weight);
|
|
360
|
+
background: var(--rs-table-footer-bg);
|
|
361
|
+
border-top: 1px solid var(--rs-table-border, var(--rs-border));
|
|
362
|
+
white-space: nowrap;
|
|
363
|
+
}
|
|
364
|
+
.rs-table__summary-cell--left {
|
|
365
|
+
text-align: left;
|
|
366
|
+
}
|
|
367
|
+
.rs-table__summary-cell--center {
|
|
368
|
+
text-align: center;
|
|
369
|
+
}
|
|
370
|
+
.rs-table__summary-cell--right {
|
|
371
|
+
text-align: right;
|
|
372
|
+
}
|
|
373
|
+
.rs-table__summary-cell--pad {
|
|
374
|
+
padding: 0;
|
|
375
|
+
}
|
|
315
376
|
.rs-table__checkbox-box--radio {
|
|
316
377
|
border-radius: 999px;
|
|
317
378
|
}
|
|
@@ -470,16 +531,21 @@
|
|
|
470
531
|
}
|
|
471
532
|
.rs-table__th--selection,
|
|
472
533
|
.rs-table__td--selection {
|
|
473
|
-
width:
|
|
474
|
-
|
|
534
|
+
/* 与序号列一样锁死宽度,避免 table-layout:auto + width:100% 时被分到多余空白 */
|
|
535
|
+
width: var(--rs-table-select-width, 40px);
|
|
536
|
+
min-width: var(--rs-table-select-width, 40px);
|
|
537
|
+
max-width: var(--rs-table-select-width, 40px);
|
|
538
|
+
padding-inline: 0;
|
|
539
|
+
box-sizing: border-box;
|
|
475
540
|
text-align: center;
|
|
476
541
|
vertical-align: middle;
|
|
477
542
|
}
|
|
478
543
|
.rs-table__th--index,
|
|
479
544
|
.rs-table__td--index {
|
|
480
|
-
width: var(--rs-table-index-width,
|
|
481
|
-
min-width: var(--rs-table-index-width,
|
|
482
|
-
max-width: var(--rs-table-index-width,
|
|
545
|
+
width: var(--rs-table-index-width, 48px);
|
|
546
|
+
min-width: var(--rs-table-index-width, 48px);
|
|
547
|
+
max-width: var(--rs-table-index-width, 48px);
|
|
548
|
+
padding-inline: 0;
|
|
483
549
|
box-sizing: border-box;
|
|
484
550
|
color: var(--rs-table-muted-fg);
|
|
485
551
|
}
|
|
@@ -712,7 +778,7 @@
|
|
|
712
778
|
padding: var(--rs-space-xs) var(--rs-space-md);
|
|
713
779
|
color: var(--rs-table-muted-fg);
|
|
714
780
|
font-size: var(--rs-font-size-xs);
|
|
715
|
-
font-weight:
|
|
781
|
+
font-weight: var(--rs-font-weight-semibold);
|
|
716
782
|
}
|
|
717
783
|
.rs-table__virtual-pad td {
|
|
718
784
|
padding: 0;
|
|
@@ -729,10 +795,19 @@
|
|
|
729
795
|
text-align: right;
|
|
730
796
|
}
|
|
731
797
|
.rs-table__empty {
|
|
732
|
-
padding:
|
|
798
|
+
padding: 0;
|
|
733
799
|
color: var(--rs-table-muted-fg);
|
|
734
800
|
text-align: center;
|
|
735
801
|
}
|
|
802
|
+
/* 宽表时 td 远大于视口;内层 sticky + 视口宽度,保证空态落在可见区域中心 */
|
|
803
|
+
.rs-table__empty-content {
|
|
804
|
+
position: sticky;
|
|
805
|
+
left: 0;
|
|
806
|
+
box-sizing: border-box;
|
|
807
|
+
max-width: 100%;
|
|
808
|
+
padding: var(--rs-space-xl);
|
|
809
|
+
text-align: center;
|
|
810
|
+
}
|
|
736
811
|
.rs-table:has(> .rs-table__table > tbody > tr:only-child > .rs-table__empty) .rs-table__empty {
|
|
737
812
|
height: 100%;
|
|
738
813
|
vertical-align: middle;
|
|
@@ -740,6 +815,9 @@
|
|
|
740
815
|
.rs-table__empty--more {
|
|
741
816
|
padding: var(--rs-space-md);
|
|
742
817
|
}
|
|
818
|
+
.rs-table__empty--more .rs-table__empty-content {
|
|
819
|
+
padding: var(--rs-space-md);
|
|
820
|
+
}
|
|
743
821
|
.rs-table__sort--active {
|
|
744
822
|
color: var(--rs-table-sort-active-fg);
|
|
745
823
|
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 表格 → 图表系列纯函数(库无关)。
|
|
3
|
+
*
|
|
4
|
+
* 产出结构可直接喂给 ECharts / Chart.js 等:
|
|
5
|
+
* - pie / 普通 bar:points[{ name, value }]
|
|
6
|
+
* - 分类轴 bar:categories + values
|
|
7
|
+
*
|
|
8
|
+
* 不引入任何图表依赖,避免拖重内核。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { RsTableRowData } from '../table-utils'
|
|
12
|
+
|
|
13
|
+
/** 图表意图类型(渲染层自行映射到具体库) */
|
|
14
|
+
export type RsTableChartKind = 'bar' | 'pie' | 'line'
|
|
15
|
+
|
|
16
|
+
/** 单点:饼图扇区 / 柱条 */
|
|
17
|
+
export interface RsTableChartPoint {
|
|
18
|
+
/** 分类名(展示) */
|
|
19
|
+
name: string
|
|
20
|
+
/** 聚合值 */
|
|
21
|
+
value: number
|
|
22
|
+
/** 原始分类 key(与 name 通常相同,供下钻) */
|
|
23
|
+
key: string
|
|
24
|
+
/** 该分类下的行数(便于 tooltip) */
|
|
25
|
+
count: number
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** 一组图表系列 */
|
|
29
|
+
export interface RsTableChartSeries {
|
|
30
|
+
id: string
|
|
31
|
+
kind: RsTableChartKind
|
|
32
|
+
points: RsTableChartPoint[]
|
|
33
|
+
/** 分类轴(与 points 顺序一致) */
|
|
34
|
+
categories: string[]
|
|
35
|
+
/** 数值轴(与 points 顺序一致) */
|
|
36
|
+
values: number[]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type RsTableChartValueAgg = 'count' | 'sum' | 'avg' | 'min' | 'max'
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 图表系列定义。
|
|
43
|
+
* - categoryField:分组字段
|
|
44
|
+
* - valueField + valueAgg:度量;仅 count 时可省略 valueField
|
|
45
|
+
*/
|
|
46
|
+
export interface RsTableChartSeriesDef {
|
|
47
|
+
id: string
|
|
48
|
+
kind: RsTableChartKind
|
|
49
|
+
categoryField: string
|
|
50
|
+
valueField?: string
|
|
51
|
+
valueAgg?: RsTableChartValueAgg
|
|
52
|
+
/** 最多保留前 N 类,其余合并为 otherLabel;0/不传表示不截断 */
|
|
53
|
+
topN?: number
|
|
54
|
+
otherLabel?: string
|
|
55
|
+
/** 空分类展示名 */
|
|
56
|
+
emptyCategoryLabel?: string
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function readField(row: RsTableRowData, field: string): unknown {
|
|
60
|
+
return (row as Record<string, unknown>)[field]
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function toNumber(value: unknown): number | null {
|
|
64
|
+
if (typeof value === 'number' && Number.isFinite(value)) return value
|
|
65
|
+
if (typeof value === 'string' && value.trim() !== '') {
|
|
66
|
+
const n = Number(value)
|
|
67
|
+
return Number.isFinite(n) ? n : null
|
|
68
|
+
}
|
|
69
|
+
return null
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function categoryKey(raw: unknown, emptyLabel: string): string {
|
|
73
|
+
if (raw == null || raw === '') return emptyLabel
|
|
74
|
+
return String(raw)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
interface Bucket {
|
|
78
|
+
key: string
|
|
79
|
+
name: string
|
|
80
|
+
count: number
|
|
81
|
+
nums: number[]
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function aggregateBucket(bucket: Bucket, agg: RsTableChartValueAgg): number {
|
|
85
|
+
if (agg === 'count') return bucket.count
|
|
86
|
+
if (!bucket.nums.length) return 0
|
|
87
|
+
if (agg === 'sum') return bucket.nums.reduce((a, b) => a + b, 0)
|
|
88
|
+
if (agg === 'avg') return bucket.nums.reduce((a, b) => a + b, 0) / bucket.nums.length
|
|
89
|
+
if (agg === 'min') return Math.min(...bucket.nums)
|
|
90
|
+
if (agg === 'max') return Math.max(...bucket.nums)
|
|
91
|
+
return 0
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 按分类字段对行做聚合,生成库无关图表系列。
|
|
96
|
+
*
|
|
97
|
+
* @param rows 通常为 SelectionSource.sourceRows(选中优先)
|
|
98
|
+
* @param def 系列定义
|
|
99
|
+
*/
|
|
100
|
+
export function buildTableChartSeries<T extends RsTableRowData>(
|
|
101
|
+
rows: readonly T[],
|
|
102
|
+
def: RsTableChartSeriesDef,
|
|
103
|
+
): RsTableChartSeries {
|
|
104
|
+
const emptyLabel = def.emptyCategoryLabel ?? '(空)'
|
|
105
|
+
const agg = def.valueAgg ?? (def.valueField ? 'sum' : 'count')
|
|
106
|
+
const map = new Map<string, Bucket>()
|
|
107
|
+
|
|
108
|
+
for (let i = 0; i < rows.length; i += 1) {
|
|
109
|
+
const row = rows[i] as T
|
|
110
|
+
const key = categoryKey(readField(row, def.categoryField), emptyLabel)
|
|
111
|
+
let bucket = map.get(key)
|
|
112
|
+
if (!bucket) {
|
|
113
|
+
bucket = { key, name: key, count: 0, nums: [] }
|
|
114
|
+
map.set(key, bucket)
|
|
115
|
+
}
|
|
116
|
+
bucket.count += 1
|
|
117
|
+
if (def.valueField && agg !== 'count') {
|
|
118
|
+
const n = toNumber(readField(row, def.valueField))
|
|
119
|
+
if (n != null) bucket.nums.push(n)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
let points: RsTableChartPoint[] = [...map.values()].map((bucket) => ({
|
|
124
|
+
key: bucket.key,
|
|
125
|
+
name: bucket.name,
|
|
126
|
+
value: aggregateBucket(bucket, agg),
|
|
127
|
+
count: bucket.count,
|
|
128
|
+
}))
|
|
129
|
+
|
|
130
|
+
// 按 value 降序,便于 topN / 饼图可读性
|
|
131
|
+
points.sort((a, b) => b.value - a.value || a.name.localeCompare(b.name))
|
|
132
|
+
|
|
133
|
+
const topN = def.topN ?? 0
|
|
134
|
+
if (topN > 0 && points.length > topN) {
|
|
135
|
+
const head = points.slice(0, topN)
|
|
136
|
+
const rest = points.slice(topN)
|
|
137
|
+
const otherValue = rest.reduce((s, p) => s + p.value, 0)
|
|
138
|
+
const otherCount = rest.reduce((s, p) => s + p.count, 0)
|
|
139
|
+
head.push({
|
|
140
|
+
key: '__other__',
|
|
141
|
+
name: def.otherLabel ?? '其他',
|
|
142
|
+
value: otherValue,
|
|
143
|
+
count: otherCount,
|
|
144
|
+
})
|
|
145
|
+
points = head
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
id: def.id,
|
|
150
|
+
kind: def.kind,
|
|
151
|
+
points,
|
|
152
|
+
categories: points.map((p) => p.name),
|
|
153
|
+
values: points.map((p) => p.value),
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 批量构建多组系列(同一 sourceRows,多套分组/度量)。
|
|
159
|
+
*/
|
|
160
|
+
export function buildTableChartSeriesList<T extends RsTableRowData>(
|
|
161
|
+
rows: readonly T[],
|
|
162
|
+
defs: readonly RsTableChartSeriesDef[],
|
|
163
|
+
): RsTableChartSeries[] {
|
|
164
|
+
return defs.map((def) => buildTableChartSeries(rows, def))
|
|
165
|
+
}
|