@soft-stech/bootsman-ui-shadcn 2.0.22 → 2.0.24
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/{BuiTable.vue_vue_type_script_setup_true_lang-BQRl7YR1.js → BuiTable.vue_vue_type_script_setup_true_lang-CHEsIAc7.js} +8 -7
- package/dist/components/table/BuiTable.js +1 -1
- package/dist/components/table/index.js +485 -470
- package/dist/index.js +1 -1
- package/dist/lib/useResizeColumns.d.ts +2 -2
- package/dist/lib/useResizeColumns.js +159 -97
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/table/BuiDataTable.vue +70 -35
- package/src/components/table/BuiTable.vue +1 -0
- package/src/lib/useResizeColumns.ts +256 -160
|
@@ -6,6 +6,7 @@ import { useEventListener } from '@vueuse/core'
|
|
|
6
6
|
const MIN_CELL_WIDTH = 90
|
|
7
7
|
const LAST_CELL_EXTRA_SPACE = 56
|
|
8
8
|
const ACTIONS_CELL_MIN_WIDTH = 10
|
|
9
|
+
const TABLE_ID = 'table'
|
|
9
10
|
|
|
10
11
|
export function useResizeColumns() {
|
|
11
12
|
type CELL = {
|
|
@@ -14,12 +15,10 @@ export function useResizeColumns() {
|
|
|
14
15
|
initialWidth: number
|
|
15
16
|
minWidth: number
|
|
16
17
|
baseWidth: number
|
|
17
|
-
isLast: boolean
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
const isResizing = ref<boolean>(false)
|
|
21
21
|
const resizingCellId = ref<string>('')
|
|
22
|
-
const neighborCellId = ref<string>('')
|
|
23
22
|
const cells = ref<CELL | undefined>(undefined)
|
|
24
23
|
const calculatedColumnSizing = ref<Record<string, number> | undefined>(undefined)
|
|
25
24
|
const tableHeaderElement = ref<InstanceType<typeof BuiTableHeader> | null>(null)
|
|
@@ -27,147 +26,148 @@ export function useResizeColumns() {
|
|
|
27
26
|
const initialTableWidth = ref<number>(0)
|
|
28
27
|
const minTableWidth = ref<number>(0)
|
|
29
28
|
const unregisterMouseMove = ref<(() => void) | undefined>(undefined)
|
|
29
|
+
const isMouseDownOnHandler = ref<boolean>(false)
|
|
30
|
+
const isMouseUpOnHandler = ref<boolean>(false)
|
|
30
31
|
|
|
31
32
|
const setProvidedCellWidths = (columnSizing: Record<string, number> | undefined) => {
|
|
32
|
-
if (tableHeaderElement.value
|
|
33
|
-
const headerCells = [...tableHeaderElement.value.headRef.querySelectorAll('th')]
|
|
33
|
+
if (!tableHeaderElement.value?.headRef || !columnSizing) return
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
headerCells.forEach((cell) => {
|
|
37
|
-
const cellId = getCellId(cell)
|
|
35
|
+
const headerCells = [...tableHeaderElement.value.headRef.querySelectorAll('th')]
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
//установить заданные как модель изначальные размеры
|
|
38
|
+
headerCells.forEach((cell) => {
|
|
39
|
+
const cellId = getCellId(cell)
|
|
40
|
+
const width = columnSizing[cellId]
|
|
41
|
+
|
|
42
|
+
cell.style.width = width && width !== 0 ? columnSizing[cellId] + 'px' : ''
|
|
43
|
+
})
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
const getCells = () => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
tableHeaderElement.value.headRef &&
|
|
48
|
-
tableElement.value &&
|
|
49
|
-
tableElement.value?.tableRef
|
|
50
|
-
) {
|
|
51
|
-
const headerCells = [...tableHeaderElement.value.headRef.querySelectorAll('th')]
|
|
52
|
-
const tableInitialWidth = getTableWidth()
|
|
53
|
-
|
|
54
|
-
tableElement.value.tableRef.style.width = 'min-content'
|
|
55
|
-
|
|
56
|
-
const headerCellsWidths: CELL = headerCells.reduce((acc, cell, index, array) => {
|
|
57
|
-
const cellId = getCellId(cell)
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
...acc,
|
|
61
|
-
[cellId]: {
|
|
62
|
-
cell: cell,
|
|
63
|
-
isLast: index === array.length - 1,
|
|
64
|
-
initialWidth: Math.floor(cell.offsetWidth),
|
|
65
|
-
baseWidth: Math.floor(cell.offsetWidth),
|
|
66
|
-
minWidth:
|
|
67
|
-
cellId === 'actions'
|
|
68
|
-
? ACTIONS_CELL_MIN_WIDTH
|
|
69
|
-
: cell.offsetWidth < MIN_CELL_WIDTH
|
|
70
|
-
? MIN_CELL_WIDTH
|
|
71
|
-
: cell.offsetWidth
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}, {})
|
|
47
|
+
const tableRef = tableElement.value?.tableRef
|
|
48
|
+
const headRef = tableHeaderElement.value?.headRef
|
|
75
49
|
|
|
76
|
-
|
|
50
|
+
if (!headRef || !tableRef) return undefined
|
|
77
51
|
|
|
78
|
-
|
|
79
|
-
cellElement.baseWidth = Math.floor(cellElement.cell.offsetWidth)
|
|
80
|
-
})
|
|
52
|
+
const headerCells = [...headRef.querySelectorAll('th')]
|
|
81
53
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
54
|
+
if (calculatedColumnSizing.value?.[TABLE_ID] === 0) {
|
|
55
|
+
calculatedColumnSizing.value = {}
|
|
56
|
+
tableRef.style.width = ''
|
|
57
|
+
}
|
|
85
58
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
59
|
+
const tableInitialWidth = getTableWidth()
|
|
60
|
+
|
|
61
|
+
tableRef.style.width = 'min-content'
|
|
62
|
+
|
|
63
|
+
const headerCellsWidths: CELL = headerCells.reduce((acc, cell) => {
|
|
64
|
+
const cellId = getCellId(cell)
|
|
65
|
+
const offsetWidth = Math.floor(cell.offsetWidth)
|
|
66
|
+
const minWidth =
|
|
67
|
+
cellId === 'actions'
|
|
68
|
+
? ACTIONS_CELL_MIN_WIDTH
|
|
69
|
+
: cell.offsetWidth < MIN_CELL_WIDTH
|
|
70
|
+
? MIN_CELL_WIDTH
|
|
71
|
+
: cell.offsetWidth
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
...acc,
|
|
75
|
+
[cellId]: {
|
|
76
|
+
cell: cell,
|
|
77
|
+
initialWidth: offsetWidth,
|
|
78
|
+
baseWidth: offsetWidth,
|
|
79
|
+
minWidth: minWidth
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}, {})
|
|
89
83
|
|
|
90
|
-
|
|
91
|
-
}
|
|
84
|
+
tableRef.style.width = ''
|
|
92
85
|
|
|
93
|
-
|
|
94
|
-
|
|
86
|
+
Object.values(headerCellsWidths).forEach((cellElement) => {
|
|
87
|
+
cellElement.baseWidth = Math.floor(cellElement.cell.offsetWidth)
|
|
88
|
+
})
|
|
95
89
|
|
|
96
|
-
|
|
97
|
-
|
|
90
|
+
setProvidedCellWidths(calculatedColumnSizing.value)
|
|
91
|
+
tableRef.style.width = (calculatedColumnSizing.value?.[TABLE_ID] || tableInitialWidth) + 'px'
|
|
92
|
+
|
|
93
|
+
Object.values(headerCellsWidths).forEach((cellElement) => {
|
|
94
|
+
cellElement.initialWidth = Math.floor(cellElement.cell.offsetWidth)
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
return headerCellsWidths
|
|
98
|
+
}
|
|
98
99
|
|
|
99
100
|
const handleResizeControlMouseDown = (cellId: string, enableColumnResizing: boolean) => {
|
|
100
101
|
if (!enableColumnResizing) return
|
|
101
102
|
|
|
102
103
|
isResizing.value = true
|
|
103
104
|
resizingCellId.value = cellId
|
|
104
|
-
|
|
105
|
-
if (cells.value) {
|
|
106
|
-
const resizingCell = cells.value[cellId].cell
|
|
107
|
-
let neighborCell = resizingCell.nextElementSibling as HTMLTableCellElement
|
|
108
|
-
|
|
109
|
-
if (!neighborCell) {
|
|
110
|
-
neighborCell = resizingCell.previousElementSibling as HTMLTableCellElement
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
neighborCellId.value = neighborCell ? neighborCell.id.split('_')[0] : ''
|
|
114
|
-
|
|
115
|
-
unregisterMouseMove.value = useEventListener(document, 'mousemove', handleCellResize)
|
|
116
|
-
}
|
|
105
|
+
unregisterMouseMove.value = useEventListener(document, 'mousemove', handleCellResize)
|
|
117
106
|
}
|
|
118
107
|
|
|
119
108
|
const handleResizeControlMouseUp = (e: Event) => {
|
|
120
109
|
const targetHTMLElement = e.target as HTMLElement
|
|
121
|
-
isMouseUpOnHandler.value =
|
|
122
|
-
targetHTMLElement.className.includes && targetHTMLElement.className.includes('resize-handler')
|
|
110
|
+
isMouseUpOnHandler.value = targetHTMLElement.className?.includes?.('resize-handler') || false
|
|
123
111
|
|
|
124
112
|
if (!isResizing.value) return
|
|
125
113
|
|
|
114
|
+
cleanupResizeState()
|
|
115
|
+
updateColumnSizingAfterResize()
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const cleanupResizeState = () => {
|
|
126
119
|
isResizing.value = false
|
|
127
120
|
resizingCellId.value = ''
|
|
128
|
-
neighborCellId.value = ''
|
|
129
121
|
|
|
130
122
|
if (unregisterMouseMove.value) {
|
|
131
123
|
unregisterMouseMove.value()
|
|
124
|
+
unregisterMouseMove.value = undefined
|
|
132
125
|
}
|
|
126
|
+
}
|
|
133
127
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
for (const cell in cells.value) {
|
|
138
|
-
const currentCell = cells.value[cell]
|
|
139
|
-
const newWidth = !currentCell.cell.hasAttribute('can-resize')
|
|
140
|
-
? currentCell.initialWidth
|
|
141
|
-
: Math.floor(currentCell.cell.offsetWidth) <= currentCell.minWidth
|
|
142
|
-
? currentCell.minWidth
|
|
143
|
-
: currentCell.cell.offsetWidth
|
|
128
|
+
const updateColumnSizingAfterResize = () => {
|
|
129
|
+
if (!cells.value || !tableElement.value?.tableRef) return
|
|
144
130
|
|
|
145
|
-
|
|
146
|
-
updatedColumnSizingValue[cell] = newWidth
|
|
147
|
-
}
|
|
131
|
+
const updatedColumnSizingValue: Record<string, number> = {}
|
|
148
132
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
133
|
+
for (const cell in cells.value) {
|
|
134
|
+
const currentCell = cells.value[cell]
|
|
135
|
+
const newWidth = !currentCell.cell.hasAttribute('can-resize')
|
|
136
|
+
? currentCell.initialWidth
|
|
137
|
+
: Math.floor(currentCell.cell.offsetWidth) <= currentCell.minWidth
|
|
138
|
+
? currentCell.minWidth
|
|
139
|
+
: currentCell.cell.offsetWidth
|
|
152
140
|
|
|
153
|
-
|
|
141
|
+
currentCell.cell.style.width = newWidth + 'px'
|
|
142
|
+
updatedColumnSizingValue[cell] = newWidth
|
|
154
143
|
}
|
|
155
|
-
}
|
|
156
144
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
145
|
+
updatedColumnSizingValue[TABLE_ID] = tableElement.value.tableRef.offsetWidth
|
|
146
|
+
calculatedColumnSizing.value = updatedColumnSizingValue
|
|
147
|
+
}
|
|
161
148
|
|
|
162
|
-
|
|
149
|
+
const getLastCellOnTheRightExtraSpace = (cellId: string) => {
|
|
150
|
+
return cellId === 'actions' ? LAST_CELL_EXTRA_SPACE : 0
|
|
163
151
|
}
|
|
164
152
|
|
|
165
153
|
const lastCell = computed(() => {
|
|
166
|
-
if (cells.value)
|
|
167
|
-
return Object.values(cells.value).find((cell) => cell.isLast)
|
|
168
|
-
}
|
|
154
|
+
if (!cells.value || !tableHeaderElement.value?.headRef) return undefined
|
|
169
155
|
|
|
170
|
-
|
|
156
|
+
const headerCells = [...tableHeaderElement.value.headRef.querySelectorAll('th')]
|
|
157
|
+
if (headerCells.length === 0) return undefined
|
|
158
|
+
|
|
159
|
+
const lastCellElement = headerCells[headerCells.length - 1]
|
|
160
|
+
return cells.value[getCellId(lastCellElement)]
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
const secondToLastCell = computed(() => {
|
|
164
|
+
if (!cells.value || !tableHeaderElement.value?.headRef) return undefined
|
|
165
|
+
|
|
166
|
+
const headerCells = [...tableHeaderElement.value.headRef.querySelectorAll('th')]
|
|
167
|
+
if (headerCells.length < 2) return undefined
|
|
168
|
+
|
|
169
|
+
const secondToLastCellElement = headerCells[headerCells.length - 2]
|
|
170
|
+
return cells.value[getCellId(secondToLastCellElement)]
|
|
171
171
|
})
|
|
172
172
|
|
|
173
173
|
const getCellId = (cell: HTMLTableCellElement) => {
|
|
@@ -177,7 +177,6 @@ export function useResizeColumns() {
|
|
|
177
177
|
const resizeCells = (cell: HTMLTableCellElement | null, e: MouseEvent) => {
|
|
178
178
|
if (!cell || !tableElement.value?.tableRef || !lastCell.value) {
|
|
179
179
|
resizingCellId.value = ''
|
|
180
|
-
neighborCellId.value = ''
|
|
181
180
|
|
|
182
181
|
return
|
|
183
182
|
}
|
|
@@ -185,8 +184,8 @@ export function useResizeColumns() {
|
|
|
185
184
|
const movementX = e.movementX
|
|
186
185
|
const direction: 'left' | 'right' = movementX < 0 ? 'left' : 'right'
|
|
187
186
|
const newCellWidth = Math.floor(parseInt(cell.style.width)) + movementX
|
|
188
|
-
|
|
189
|
-
|
|
187
|
+
|
|
188
|
+
const newTableWidth = Math.floor(parseInt(tableElement.value.tableRef.style.width)) + movementX
|
|
190
189
|
const newLastCellWidth = Math.floor(parseInt(lastCell.value.cell.style.width)) - movementX
|
|
191
190
|
|
|
192
191
|
if (direction === 'left') {
|
|
@@ -208,10 +207,10 @@ export function useResizeColumns() {
|
|
|
208
207
|
return
|
|
209
208
|
}
|
|
210
209
|
} else {
|
|
210
|
+
const lastCellId = getCellId(lastCell.value.cell)
|
|
211
211
|
const min =
|
|
212
|
-
cells.value && cells.value[
|
|
213
|
-
? cells.value[
|
|
214
|
-
getLastCellOnTheRightExtraSpace(lastCell.value.cell)
|
|
212
|
+
cells.value && cells.value[lastCellId]
|
|
213
|
+
? cells.value[lastCellId].minWidth + getLastCellOnTheRightExtraSpace(lastCellId)
|
|
215
214
|
: MIN_CELL_WIDTH
|
|
216
215
|
|
|
217
216
|
if (
|
|
@@ -230,99 +229,194 @@ export function useResizeColumns() {
|
|
|
230
229
|
const handleCellResize = (e: MouseEvent) => {
|
|
231
230
|
e.preventDefault()
|
|
232
231
|
|
|
233
|
-
if (cells.value)
|
|
234
|
-
const resizingCell = cells.value[resizingCellId.value]?.cell
|
|
232
|
+
if (!cells.value) return
|
|
235
233
|
|
|
236
|
-
|
|
237
|
-
|
|
234
|
+
const resizingCell = cells.value[resizingCellId.value]?.cell
|
|
235
|
+
resizeCells(resizingCell, e)
|
|
238
236
|
}
|
|
239
237
|
|
|
240
238
|
const resetCells = () => {
|
|
241
|
-
if (cells.value
|
|
242
|
-
tableElement.value.tableRef.style.width = ''
|
|
239
|
+
if (!cells.value || !tableElement.value?.tableRef) return
|
|
243
240
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
241
|
+
tableElement.value.tableRef.style.width = ''
|
|
242
|
+
calculatedColumnSizing.value = {}
|
|
243
|
+
setInitialColumnWidths()
|
|
247
244
|
}
|
|
248
245
|
|
|
249
246
|
const resetCell = (cellId: string) => {
|
|
250
247
|
if (
|
|
251
|
-
cells.value
|
|
252
|
-
calculatedColumnSizing.value
|
|
253
|
-
lastCell.value
|
|
254
|
-
tableElement.value
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
248
|
+
!cells.value ||
|
|
249
|
+
!calculatedColumnSizing.value ||
|
|
250
|
+
!lastCell.value ||
|
|
251
|
+
!tableElement.value?.tableRef
|
|
252
|
+
)
|
|
253
|
+
return
|
|
254
|
+
|
|
255
|
+
const updatedColumnSizingValue: Record<string, number> = { ...calculatedColumnSizing.value }
|
|
256
|
+
|
|
257
|
+
const cellData = cells.value[cellId]
|
|
258
|
+
const thisCellBaseWidth = cellData.baseWidth
|
|
259
|
+
const thisCellCurrentWidth = calculatedColumnSizing.value[cellId]
|
|
260
|
+
const diff = thisCellBaseWidth - thisCellCurrentWidth
|
|
261
|
+
|
|
262
|
+
let newTableWidth = calculatedColumnSizing.value[TABLE_ID] + diff
|
|
263
|
+
let lastCellId = getCellId(lastCell.value.cell)
|
|
267
264
|
|
|
265
|
+
if (newTableWidth < minTableWidth.value) {
|
|
266
|
+
const tableWidthDiff = minTableWidth.value - newTableWidth
|
|
267
|
+
let newLastCellWidth: number
|
|
268
|
+
|
|
269
|
+
if (cellId === lastCellId) {
|
|
270
|
+
//если ресетим последнюю колонку, то восстанавливаем ее ширину за счет соседней слева
|
|
271
|
+
if (!secondToLastCell.value) {
|
|
272
|
+
resetCells()
|
|
273
|
+
return
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
lastCellId = getCellId(secondToLastCell.value.cell)
|
|
277
|
+
newLastCellWidth = calculatedColumnSizing.value[lastCellId] + tableWidthDiff
|
|
278
|
+
secondToLastCell.value.cell.style.width = newLastCellWidth + 'px'
|
|
279
|
+
} else {
|
|
280
|
+
newLastCellWidth =
|
|
281
|
+
calculatedColumnSizing.value[getCellId(lastCell.value.cell)] + tableWidthDiff
|
|
268
282
|
lastCell.value.cell.style.width = newLastCellWidth + 'px'
|
|
269
|
-
newTableWidth = minTableWidth.value
|
|
270
283
|
}
|
|
271
284
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
calculatedColumnSizing.value[cellId] = thisCellBaseWidth
|
|
275
|
-
calculatedColumnSizing.value['table'] = newTableWidth
|
|
285
|
+
newTableWidth = minTableWidth.value
|
|
286
|
+
updatedColumnSizingValue[lastCellId] = newLastCellWidth
|
|
276
287
|
}
|
|
288
|
+
|
|
289
|
+
cells.value[cellId].cell.style.width = thisCellBaseWidth + 'px'
|
|
290
|
+
tableElement.value.tableRef.style.width = newTableWidth + 'px'
|
|
291
|
+
updatedColumnSizingValue[cellId] = thisCellBaseWidth
|
|
292
|
+
updatedColumnSizingValue[TABLE_ID] = newTableWidth
|
|
293
|
+
|
|
294
|
+
calculatedColumnSizing.value = updatedColumnSizingValue
|
|
277
295
|
}
|
|
278
296
|
|
|
279
297
|
const getTableWrapperWidth = () => {
|
|
280
|
-
|
|
281
|
-
return tableElement.value.scrollAreaElementRef?.tableWrapperRef.$el.offsetWidth - 3
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
return 0
|
|
298
|
+
return tableElement.value?.scrollAreaElementRef?.tableWrapperRef?.$el.offsetWidth - 3 || 0
|
|
285
299
|
}
|
|
286
300
|
|
|
287
301
|
const getTableWidth = () => {
|
|
288
|
-
|
|
289
|
-
return tableElement.value.tableRef.offsetWidth
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
return 0
|
|
302
|
+
return tableElement.value?.tableRef?.offsetWidth || 0
|
|
293
303
|
}
|
|
294
304
|
|
|
295
305
|
const setInitialColumnWidths = () => {
|
|
296
306
|
cells.value = getCells()
|
|
297
307
|
|
|
298
|
-
if (cells.value)
|
|
299
|
-
const updatedColumnSizingValue: Record<string, number> = {}
|
|
308
|
+
if (!cells.value) return
|
|
300
309
|
|
|
301
|
-
|
|
302
|
-
if (!cells.value[cell].cell.style.width) {
|
|
303
|
-
cells.value[cell].cell.style.width = cells.value[cell].initialWidth + 'px'
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
cells.value[cell].cell.style.minWidth = cells.value[cell].minWidth + 'px'
|
|
310
|
+
const updatedColumnSizingValue: Record<string, number> = {}
|
|
307
311
|
|
|
308
|
-
|
|
312
|
+
for (const cell in cells.value) {
|
|
313
|
+
if (!cells.value[cell].cell.style.width) {
|
|
314
|
+
cells.value[cell].cell.style.width = cells.value[cell].initialWidth + 'px'
|
|
309
315
|
}
|
|
310
316
|
|
|
311
|
-
|
|
312
|
-
|
|
317
|
+
cells.value[cell].cell.style.minWidth = cells.value[cell].minWidth + 'px'
|
|
318
|
+
updatedColumnSizingValue[cell] = cells.value[cell].cell.offsetWidth
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (tableElement.value?.tableRef) {
|
|
322
|
+
const tableOffsetWidth = getTableWidth()
|
|
323
|
+
const tableWrapperWidth = getTableWrapperWidth()
|
|
324
|
+
minTableWidth.value = tableWrapperWidth
|
|
325
|
+
tableElement.value.tableRef.setAttribute('initialResize', 'set')
|
|
313
326
|
|
|
314
|
-
|
|
315
|
-
|
|
327
|
+
if (calculatedColumnSizing.value?.[TABLE_ID] && !tableElement.value.tableRef.style.width) {
|
|
328
|
+
tableElement.value.tableRef.style.width = calculatedColumnSizing.value[TABLE_ID] + 'px'
|
|
329
|
+
} else {
|
|
330
|
+
if (tableOffsetWidth < minTableWidth.value) {
|
|
331
|
+
setTableFullScreen()
|
|
316
332
|
} else {
|
|
317
333
|
initialTableWidth.value = tableOffsetWidth
|
|
318
334
|
tableElement.value.tableRef.style.width = tableOffsetWidth + 'px'
|
|
319
|
-
updatedColumnSizingValue[
|
|
335
|
+
updatedColumnSizingValue[TABLE_ID] = tableOffsetWidth
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
calculatedColumnSizing.value = updatedColumnSizingValue
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const setColumnWidthsOnColumnVisibilityChange = () => {
|
|
344
|
+
if (!tableHeaderElement.value?.headRef || !cells.value) return
|
|
345
|
+
|
|
346
|
+
const headerCells = [...tableHeaderElement.value.headRef.querySelectorAll('th')]
|
|
347
|
+
const updatedColumnSizingValue: Record<string, number> = {}
|
|
348
|
+
|
|
349
|
+
headerCells.forEach((cell, index, array) => {
|
|
350
|
+
const cellId = getCellId(cell)
|
|
351
|
+
|
|
352
|
+
if (cells.value) {
|
|
353
|
+
cells.value[cellId].cell = cell
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (index < array.length - 1) {
|
|
357
|
+
const storedWidth = calculatedColumnSizing.value?.[cellId]
|
|
358
|
+
|
|
359
|
+
if (storedWidth) {
|
|
360
|
+
cell.style.width = storedWidth + 'px'
|
|
361
|
+
updatedColumnSizingValue[cellId] = storedWidth
|
|
362
|
+
} else {
|
|
363
|
+
cell.style.width = ''
|
|
364
|
+
|
|
365
|
+
const baseWidth = cells.value?.[cellId]?.baseWidth || cell.offsetWidth
|
|
366
|
+
const minWidth = cells.value?.[cellId]?.minWidth || MIN_CELL_WIDTH
|
|
367
|
+
cell.style.width = baseWidth + 'px'
|
|
368
|
+
cell.style.minWidth = minWidth + 'px'
|
|
369
|
+
updatedColumnSizingValue[cellId] = baseWidth
|
|
320
370
|
}
|
|
371
|
+
} else {
|
|
372
|
+
const newLastCellWidth = cells.value?.[cellId]?.baseWidth || cell.offsetWidth
|
|
373
|
+
updatedColumnSizingValue[cellId] = newLastCellWidth
|
|
321
374
|
}
|
|
375
|
+
})
|
|
322
376
|
|
|
377
|
+
const wouldBeTableWidth = Object.values(updatedColumnSizingValue).reduce(
|
|
378
|
+
(acc, value) => (acc += value),
|
|
379
|
+
0
|
|
380
|
+
)
|
|
381
|
+
|
|
382
|
+
if (tableElement.value?.tableRef) {
|
|
323
383
|
minTableWidth.value = getTableWrapperWidth()
|
|
324
|
-
|
|
384
|
+
const newTableWidth = Math.max(wouldBeTableWidth, minTableWidth.value)
|
|
385
|
+
tableElement.value.tableRef.style.width = newTableWidth + 'px'
|
|
386
|
+
updatedColumnSizingValue[TABLE_ID] = newTableWidth
|
|
325
387
|
}
|
|
388
|
+
|
|
389
|
+
if (lastCell.value) {
|
|
390
|
+
lastCell.value.cell.style.width = ''
|
|
391
|
+
const newLastCellWidth = Math.floor(lastCell.value.cell.offsetWidth)
|
|
392
|
+
updatedColumnSizingValue[getCellId(lastCell.value.cell)] = newLastCellWidth
|
|
393
|
+
lastCell.value.cell.style.width = newLastCellWidth + 'px'
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
calculatedColumnSizing.value = updatedColumnSizingValue
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
const setColumnWidthsOnWindowResize = () => {
|
|
400
|
+
const tableWidth = getTableWidth()
|
|
401
|
+
minTableWidth.value = getTableWrapperWidth()
|
|
402
|
+
|
|
403
|
+
if (tableWidth < minTableWidth.value) {
|
|
404
|
+
setTableFullScreen()
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const setTableFullScreen = () => {
|
|
409
|
+
if (!lastCell.value || !calculatedColumnSizing.value || !tableElement.value?.tableRef) return
|
|
410
|
+
|
|
411
|
+
const lastCellId = getCellId(lastCell.value.cell)
|
|
412
|
+
|
|
413
|
+
calculatedColumnSizing.value[TABLE_ID] = minTableWidth.value
|
|
414
|
+
tableElement.value.tableRef.style.width = minTableWidth.value + 'px'
|
|
415
|
+
lastCell.value.cell.style.width = ''
|
|
416
|
+
|
|
417
|
+
const newLastCellWidth = Math.floor(lastCell.value.cell.offsetWidth)
|
|
418
|
+
calculatedColumnSizing.value[lastCellId] = newLastCellWidth
|
|
419
|
+
lastCell.value.cell.style.width = newLastCellWidth + 'px'
|
|
326
420
|
}
|
|
327
421
|
|
|
328
422
|
return {
|
|
@@ -338,6 +432,8 @@ export function useResizeColumns() {
|
|
|
338
432
|
resetCells,
|
|
339
433
|
setInitialColumnWidths,
|
|
340
434
|
setProvidedCellWidths,
|
|
435
|
+
setColumnWidthsOnColumnVisibilityChange,
|
|
436
|
+
setColumnWidthsOnWindowResize,
|
|
341
437
|
isMouseDownOnHandler,
|
|
342
438
|
isMouseUpOnHandler
|
|
343
439
|
}
|