@veltra/sheet 2.6.0 → 2.7.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/dist/components/sheet/sheet.js +7 -2
- package/dist/components/sheet/use-sheet-grid.js +4 -1
- package/dist/types/sheet.d.ts +10 -0
- package/package.json +1 -1
- package/src/components/sheet/__test__/sheet-component.test.ts +46 -0
- package/src/components/sheet/sheet.vue +4 -2
- package/src/components/sheet/use-sheet-grid.ts +6 -1
- package/src/types/sheet.ts +7 -0
|
@@ -53,9 +53,13 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
53
53
|
readonly: {
|
|
54
54
|
type: Boolean,
|
|
55
55
|
default: false
|
|
56
|
+
},
|
|
57
|
+
colResize: {
|
|
58
|
+
type: Boolean,
|
|
59
|
+
default: false
|
|
56
60
|
}
|
|
57
61
|
},
|
|
58
|
-
emits: ["active-sheet-change"],
|
|
62
|
+
emits: ["active-sheet-change", "col-resize-end"],
|
|
59
63
|
setup(__props, { expose: __expose, emit: __emit }) {
|
|
60
64
|
const props = __props;
|
|
61
65
|
const emit = __emit;
|
|
@@ -117,7 +121,8 @@ const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
|
117
121
|
getActiveSheet: () => activeSheet.value,
|
|
118
122
|
context,
|
|
119
123
|
formulaBarRef,
|
|
120
|
-
isFunctionPopupOpen: () => popupTool.value?.popup === "functions"
|
|
124
|
+
isFunctionPopupOpen: () => popupTool.value?.popup === "functions",
|
|
125
|
+
onColResizeEnd: (event) => emit("col-resize-end", event)
|
|
121
126
|
});
|
|
122
127
|
__expose({
|
|
123
128
|
workbook,
|
|
@@ -71,9 +71,11 @@ function useSheetGrid(options) {
|
|
|
71
71
|
resolveCellRenderer: props.resolveCellRenderer,
|
|
72
72
|
header: props.header,
|
|
73
73
|
editors: props.editors,
|
|
74
|
+
colResize: props.colResize,
|
|
74
75
|
onContextMenu: handleContextMenu,
|
|
75
76
|
onEditStart: (addr) => formulaBarRef.value?.mirrorGridEdit(addr),
|
|
76
77
|
onEditEnd: (addr) => formulaBarRef.value?.exitMirror(addr),
|
|
78
|
+
onColResizeEnd: options.onColResizeEnd,
|
|
77
79
|
interceptSelection: () => (formulaBarRef.value?.isRefSelecting() ?? false) || (formulaBarRef.value?.isFunctionPopupOpen() ?? false) || (options.isFunctionPopupOpen?.() ?? false),
|
|
78
80
|
onSelectionIntercept: (range) => formulaBarRef.value?.handleRefSelect(range)
|
|
79
81
|
});
|
|
@@ -182,7 +184,8 @@ function useSheetGrid(options) {
|
|
|
182
184
|
props.showRowHeader,
|
|
183
185
|
props.showColHeader,
|
|
184
186
|
props.header,
|
|
185
|
-
props.editors
|
|
187
|
+
props.editors,
|
|
188
|
+
props.colResize
|
|
186
189
|
], ([nextRows, nextCols]) => {
|
|
187
190
|
const sheet = getActiveSheet();
|
|
188
191
|
if (nextRows != null) sheet.ensureTableSize(nextRows, 0);
|
package/dist/types/sheet.d.ts
CHANGED
|
@@ -49,6 +49,11 @@ export interface SheetProps {
|
|
|
49
49
|
showColHeader?: boolean;
|
|
50
50
|
/** 只读预览(关闭编辑回写、填充柄等写入口) */
|
|
51
51
|
readonly?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* 列宽拖拽(透传 SheetGrid):readonly 下置 true 仅放开列头 resize 手柄,编辑仍
|
|
54
|
+
* 关闭;缺省 false 行为不变。变化触发网格重建(构造期选项)
|
|
55
|
+
*/
|
|
56
|
+
colResize?: boolean;
|
|
52
57
|
}
|
|
53
58
|
export interface SheetEmits {
|
|
54
59
|
/** 激活 sheet 切换(点击 tab 或宿主调用 workbook.activateSheet) */
|
|
@@ -56,6 +61,11 @@ export interface SheetEmits {
|
|
|
56
61
|
sheet: Sheet;
|
|
57
62
|
index: number;
|
|
58
63
|
}): void;
|
|
64
|
+
/** 列宽拖拽落定(写模型之后):载荷含列索引与最终宽度 */
|
|
65
|
+
(name: 'col-resize-end', payload: {
|
|
66
|
+
col: number;
|
|
67
|
+
width: number;
|
|
68
|
+
}): void;
|
|
59
69
|
}
|
|
60
70
|
/** 在组件内部引用 */
|
|
61
71
|
export interface _SheetExposed {
|
package/package.json
CHANGED
|
@@ -1186,6 +1186,52 @@ describe('USheet 行高/列宽右键菜单', () => {
|
|
|
1186
1186
|
})
|
|
1187
1187
|
})
|
|
1188
1188
|
|
|
1189
|
+
describe('USheet colResize(readonly 列宽拖拽)', () => {
|
|
1190
|
+
it('readonly + colResize:列头拖宽写模型并 emit col-resize-end(col + 最终宽度)', async () => {
|
|
1191
|
+
const workbook = createWorkbook()
|
|
1192
|
+
const events: Array<{ col: number; width: number }> = []
|
|
1193
|
+
const { el } = mount(() => ({
|
|
1194
|
+
workbook,
|
|
1195
|
+
rows: 10,
|
|
1196
|
+
cols: 6,
|
|
1197
|
+
readonly: true,
|
|
1198
|
+
colResize: true,
|
|
1199
|
+
onColResizeEnd: (event: { col: number; width: number }) => events.push(event)
|
|
1200
|
+
}))
|
|
1201
|
+
await nextTick()
|
|
1202
|
+
|
|
1203
|
+
// 第 0 列右缘(46 + 80 = 126,±4 手柄区)列头带内拖拽:宽 = 起始 80 + 指针位移 42
|
|
1204
|
+
const instance = el.querySelector<HTMLElement>('.u-sheet__grid-instance')!
|
|
1205
|
+
fire(instance, 'pointerdown', { clientX: 124, clientY: 10 })
|
|
1206
|
+
fire(instance, 'pointermove', { clientX: 166, clientY: 10 })
|
|
1207
|
+
fire(instance, 'pointerup', { clientX: 166, clientY: 10 })
|
|
1208
|
+
await nextTick()
|
|
1209
|
+
expect(events).toEqual([{ col: 0, width: 122 }])
|
|
1210
|
+
expect(workbook.activeSheet.getColWidth(0)).toBe(122)
|
|
1211
|
+
})
|
|
1212
|
+
|
|
1213
|
+
it('缺省 readonly 仍禁列宽拖拽(不 emit)', async () => {
|
|
1214
|
+
const workbook = createWorkbook()
|
|
1215
|
+
const events: Array<{ col: number; width: number }> = []
|
|
1216
|
+
const { el } = mount(() => ({
|
|
1217
|
+
workbook,
|
|
1218
|
+
rows: 10,
|
|
1219
|
+
cols: 6,
|
|
1220
|
+
readonly: true,
|
|
1221
|
+
onColResizeEnd: (event: { col: number; width: number }) => events.push(event)
|
|
1222
|
+
}))
|
|
1223
|
+
await nextTick()
|
|
1224
|
+
|
|
1225
|
+
const instance = el.querySelector<HTMLElement>('.u-sheet__grid-instance')!
|
|
1226
|
+
fire(instance, 'pointerdown', { clientX: 124, clientY: 10 })
|
|
1227
|
+
fire(instance, 'pointermove', { clientX: 166, clientY: 10 })
|
|
1228
|
+
fire(instance, 'pointerup', { clientX: 166, clientY: 10 })
|
|
1229
|
+
await nextTick()
|
|
1230
|
+
expect(events).toEqual([])
|
|
1231
|
+
expect(workbook.activeSheet.getColWidth(0)).toBeUndefined()
|
|
1232
|
+
})
|
|
1233
|
+
})
|
|
1234
|
+
|
|
1189
1235
|
describe('fx 选区锚点', () => {
|
|
1190
1236
|
const A1_ANCHOR = { minCol: 0, minRow: 0, maxCol: 0, maxRow: 0 }
|
|
1191
1237
|
|
|
@@ -111,7 +111,8 @@ const props = withDefaults(defineProps<SheetProps>(), {
|
|
|
111
111
|
showTabs: true,
|
|
112
112
|
showRowHeader: true,
|
|
113
113
|
showColHeader: true,
|
|
114
|
-
readonly: false
|
|
114
|
+
readonly: false,
|
|
115
|
+
colResize: false
|
|
115
116
|
})
|
|
116
117
|
|
|
117
118
|
const emit = defineEmits<SheetEmits>()
|
|
@@ -215,7 +216,8 @@ const { rebuildGrid, activateGrid, pruneCache, getGrid, setSelectionAnchor } = u
|
|
|
215
216
|
context,
|
|
216
217
|
formulaBarRef,
|
|
217
218
|
// 工具栏「函数」弹框打开期间与 fx 入口一致:画布点击不清除目标格高亮
|
|
218
|
-
isFunctionPopupOpen: () => popupTool.value?.popup === 'functions'
|
|
219
|
+
isFunctionPopupOpen: () => popupTool.value?.popup === 'functions',
|
|
220
|
+
onColResizeEnd: (event) => emit('col-resize-end', event)
|
|
219
221
|
})
|
|
220
222
|
|
|
221
223
|
const exposed: _SheetExposed = {
|
|
@@ -39,6 +39,8 @@ interface UseSheetGridOptions {
|
|
|
39
39
|
formulaBarRef: ElRef<FormulaBarMirror>
|
|
40
40
|
/** 函数弹框打开中(宿主侧入口,如工具栏「函数」按钮) */
|
|
41
41
|
isFunctionPopupOpen?: () => boolean
|
|
42
|
+
/** 列宽拖拽落定(SheetGrid 透传 → 宿主 emit col-resize-end) */
|
|
43
|
+
onColResizeEnd?: (event: { col: number; width: number }) => void
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
/** 缓存实例(LRU 淘汰):每个 sheet 一个独立容器 div,非激活容器 visibility:hidden 堆叠 */
|
|
@@ -128,9 +130,11 @@ export function useSheetGrid(options: UseSheetGridOptions) {
|
|
|
128
130
|
resolveCellRenderer: props.resolveCellRenderer,
|
|
129
131
|
header: props.header,
|
|
130
132
|
editors: props.editors,
|
|
133
|
+
colResize: props.colResize,
|
|
131
134
|
onContextMenu: handleContextMenu,
|
|
132
135
|
onEditStart: (addr) => formulaBarRef.value?.mirrorGridEdit(addr),
|
|
133
136
|
onEditEnd: (addr) => formulaBarRef.value?.exitMirror(addr),
|
|
137
|
+
onColResizeEnd: options.onColResizeEnd,
|
|
134
138
|
// 引用选择:不回写模型选区,序列化为 A1 / A1:B2 交给公式栏;
|
|
135
139
|
// 函数弹框打开期间(fx / 工具栏两入口)同样拦截,画布点击不离开目标格
|
|
136
140
|
interceptSelection: () =>
|
|
@@ -268,7 +272,8 @@ export function useSheetGrid(options: UseSheetGridOptions) {
|
|
|
268
272
|
props.showRowHeader,
|
|
269
273
|
props.showColHeader,
|
|
270
274
|
props.header,
|
|
271
|
-
props.editors
|
|
275
|
+
props.editors,
|
|
276
|
+
props.colResize
|
|
272
277
|
] as const,
|
|
273
278
|
([nextRows, nextCols]) => {
|
|
274
279
|
const sheet = getActiveSheet()
|
package/src/types/sheet.ts
CHANGED
|
@@ -57,11 +57,18 @@ export interface SheetProps {
|
|
|
57
57
|
showColHeader?: boolean
|
|
58
58
|
/** 只读预览(关闭编辑回写、填充柄等写入口) */
|
|
59
59
|
readonly?: boolean
|
|
60
|
+
/**
|
|
61
|
+
* 列宽拖拽(透传 SheetGrid):readonly 下置 true 仅放开列头 resize 手柄,编辑仍
|
|
62
|
+
* 关闭;缺省 false 行为不变。变化触发网格重建(构造期选项)
|
|
63
|
+
*/
|
|
64
|
+
colResize?: boolean
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
export interface SheetEmits {
|
|
63
68
|
/** 激活 sheet 切换(点击 tab 或宿主调用 workbook.activateSheet) */
|
|
64
69
|
(name: 'active-sheet-change', payload: { sheet: Sheet; index: number }): void
|
|
70
|
+
/** 列宽拖拽落定(写模型之后):载荷含列索引与最终宽度 */
|
|
71
|
+
(name: 'col-resize-end', payload: { col: number; width: number }): void
|
|
65
72
|
}
|
|
66
73
|
|
|
67
74
|
/** 在组件内部引用 */
|