@veltra/desktop 1.5.0 → 1.6.1

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.
@@ -46,7 +46,7 @@ export class ColumnNode extends TreeNode<TableColumn, ColumnNode> {
46
46
 
47
47
  /** 宽度 */
48
48
  get width(): number | undefined {
49
- const { width } = this.data
49
+ const width = this.data.width ?? this.derived.allocatedWidth
50
50
  if (!width || (this.minWidth && width && width < this.minWidth)) {
51
51
  return this.minWidth
52
52
  }
@@ -57,6 +57,21 @@ export class ColumnNode extends TreeNode<TableColumn, ColumnNode> {
57
57
  val = this.minWidth
58
58
  }
59
59
  this.data.width = val
60
+ // 显式宽度(配置/拖拽)优先于分配宽度,旧的分配结果直接作废
61
+ this.derived.allocatedWidth = undefined
62
+ }
63
+
64
+ /**
65
+ * 列宽分配算法写入的宽度。
66
+ * 与用户列配置 `data.width` 隔离:分配结果不回写列配置对象,
67
+ * 避免列森林重建(重挂载 / v-if / columns 引用变化)时把上一次的
68
+ * 分配残留误判为显式 width,导致列宽被永久锁定、容器变窄后出现滚动条。
69
+ */
70
+ get allocatedWidth(): number | undefined {
71
+ return this.derived.allocatedWidth
72
+ }
73
+ set allocatedWidth(val: number | undefined) {
74
+ this.derived.allocatedWidth = val
60
75
  }
61
76
  /** 最小宽度 */
62
77
  get minWidth(): number | undefined {
@@ -102,6 +117,11 @@ export class ColumnNode extends TreeNode<TableColumn, ColumnNode> {
102
117
 
103
118
  style: Record<string, number> = reactive({})
104
119
 
120
+ /** 派生状态(响应式),与用户列配置 data 隔离 */
121
+ private readonly derived = shallowReactive<{ allocatedWidth?: number }>({
122
+ allocatedWidth: undefined
123
+ })
124
+
105
125
  constructor(val: TableColumn, index: number, depth: number, parent?: ColumnNode) {
106
126
  super(isReactive(val) ? val : shallowReactive(val), index, depth, parent)
107
127
  this.explicitWidth = val.width !== undefined
@@ -1,4 +1,6 @@
1
- import { nextTick, provide, shallowRef, watchEffect, type ShallowRef } from 'vue'
1
+ import { debounce } from '@cat-kit/core'
2
+ import { useResizeObserver } from '@veltra/compositions'
3
+ import { computed, nextTick, provide, shallowRef, watchEffect, type ShallowRef } from 'vue'
2
4
 
3
5
  import type { ScrollExposed } from '../../types'
4
6
  import { allocateLeafColumnWidths } from './allocate-column-widths'
@@ -53,6 +55,12 @@ export function useColResize(options: Options): UseColResizeReturned {
53
55
 
54
56
  watchEffect(correctColumnStyle)
55
57
 
58
+ // 容器宽度变化(窗口缩放、父布局变化、纵向滚动条出现/消失等)时重新分配列宽,
59
+ // 直到所有未显式设宽的列回落到 minWidth。计算开销较大,用防抖合并连续的 resize 触发。
60
+ const debouncedCorrectColumnStyle = debounce(correctColumnStyle)
61
+ const containerRef = computed(() => scrollRef.value?.containerRef ?? null)
62
+ useResizeObserver({ targets: containerRef, onResize: debouncedCorrectColumnStyle })
63
+
56
64
  function updateResizeLine(transformX: number): void {
57
65
  if (!resizeLineRef.value) return
58
66
  resizeLineRef.value.style.transform = `translateX(${transformX}px)`
@@ -52,7 +52,7 @@ export interface CollapseItemProps {
52
52
  */
53
53
  modelValue?: boolean
54
54
 
55
- /** 标题文本(也可使用 #title 插槽) */
55
+ /** 标题文本(也可通过 #header 插槽自定义整个头部) */
56
56
  title?: string
57
57
 
58
58
  /** 是否禁用 */
@@ -63,6 +63,13 @@ export interface CollapseItemProps {
63
63
  * 在 `UCollapse` 内由父组件 `expandIcon` 统一管理。
64
64
  */
65
65
  expandIcon?: Component
66
+
67
+ /**
68
+ * 折叠动画结束后卸载内容 DOM(展开时重新挂载),减少长列表的内存与渲染成本。
69
+ * 注意:卸载会丢失内容区的本地组件状态。
70
+ * @default false
71
+ */
72
+ destroyOnCollapse?: boolean
66
73
  }
67
74
 
68
75
  export interface CollapseItemEmits {
@@ -38,10 +38,25 @@ export interface LayoutProps {
38
38
  * @description 注意:当为true时,gap固定且需要有一项宽度为固定像素才能够拖拽
39
39
  */
40
40
  resizable?: boolean
41
+ /**
42
+ * 每列的最小宽度(px),按列索引与 cols 对应,仅 resizable 拖拽时生效。
43
+ * 未指定的列不限制(可被压至 0)。
44
+ * @example
45
+ * ```ts
46
+ * // 三栏拖拽时,左栏不小于 120px,右栏不小于 200px
47
+ * :cols="['1fr', '2fr', '300px']" :col-min-sizes="[120, undefined, 200]"
48
+ * ```
49
+ */
50
+ colMinSizes?: (number | undefined)[]
41
51
  }
42
52
 
43
53
  /** 布局组件定义的事件 */
44
- export interface LayoutEmits {}
54
+ export interface LayoutEmits {
55
+ /** 开始拖拽调节某条间隔(index 为间隔左侧列的索引) */
56
+ (e: 'resize-start', index: number): void
57
+ /** 拖拽调节结束 */
58
+ (e: 'resize-end', index: number): void
59
+ }
45
60
 
46
61
  /** 布局组件暴露的属性和方法(组件内部使用) */
47
62
  export interface _LayoutExposed {}