@soft-stech/bootsman-ui-shadcn 2.0.23 → 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 +430 -424
- package/dist/index.js +1 -1
- package/dist/lib/useResizeColumns.d.ts +2 -2
- package/dist/lib/useResizeColumns.js +159 -99
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/table/BuiDataTable.vue +49 -33
- package/src/components/table/BuiTable.vue +1 -0
- package/src/lib/useResizeColumns.ts +255 -171
|
@@ -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,156 +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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
})
|
|
44
|
-
}
|
|
33
|
+
if (!tableHeaderElement.value?.headRef || !columnSizing) return
|
|
34
|
+
|
|
35
|
+
const headerCells = [...tableHeaderElement.value.headRef.querySelectorAll('th')]
|
|
36
|
+
|
|
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
|
+
})
|
|
45
44
|
}
|
|
46
45
|
|
|
47
46
|
const getCells = () => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
tableHeaderElement.value.headRef &&
|
|
51
|
-
tableElement.value &&
|
|
52
|
-
tableElement.value?.tableRef
|
|
53
|
-
) {
|
|
54
|
-
const headerCells = [...tableHeaderElement.value.headRef.querySelectorAll('th')]
|
|
55
|
-
|
|
56
|
-
if (calculatedColumnSizing.value && calculatedColumnSizing.value['table'] === 0) {
|
|
57
|
-
calculatedColumnSizing.value = {}
|
|
58
|
-
tableElement.value.tableRef.style.width = ''
|
|
59
|
-
}
|
|
47
|
+
const tableRef = tableElement.value?.tableRef
|
|
48
|
+
const headRef = tableHeaderElement.value?.headRef
|
|
60
49
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
...acc,
|
|
70
|
-
[cellId]: {
|
|
71
|
-
cell: cell,
|
|
72
|
-
isLast: index === array.length - 1,
|
|
73
|
-
initialWidth: Math.floor(cell.offsetWidth),
|
|
74
|
-
baseWidth: Math.floor(cell.offsetWidth),
|
|
75
|
-
minWidth:
|
|
76
|
-
cellId === 'actions'
|
|
77
|
-
? ACTIONS_CELL_MIN_WIDTH
|
|
78
|
-
: cell.offsetWidth < MIN_CELL_WIDTH
|
|
79
|
-
? MIN_CELL_WIDTH
|
|
80
|
-
: cell.offsetWidth
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}, {})
|
|
50
|
+
if (!headRef || !tableRef) return undefined
|
|
51
|
+
|
|
52
|
+
const headerCells = [...headRef.querySelectorAll('th')]
|
|
53
|
+
|
|
54
|
+
if (calculatedColumnSizing.value?.[TABLE_ID] === 0) {
|
|
55
|
+
calculatedColumnSizing.value = {}
|
|
56
|
+
tableRef.style.width = ''
|
|
57
|
+
}
|
|
84
58
|
|
|
85
|
-
|
|
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
|
+
}, {})
|
|
86
83
|
|
|
87
|
-
|
|
88
|
-
cellElement.baseWidth = Math.floor(cellElement.cell.offsetWidth)
|
|
89
|
-
})
|
|
84
|
+
tableRef.style.width = ''
|
|
90
85
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
86
|
+
Object.values(headerCellsWidths).forEach((cellElement) => {
|
|
87
|
+
cellElement.baseWidth = Math.floor(cellElement.cell.offsetWidth)
|
|
88
|
+
})
|
|
94
89
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
})
|
|
90
|
+
setProvidedCellWidths(calculatedColumnSizing.value)
|
|
91
|
+
tableRef.style.width = (calculatedColumnSizing.value?.[TABLE_ID] || tableInitialWidth) + 'px'
|
|
98
92
|
|
|
99
|
-
|
|
100
|
-
|
|
93
|
+
Object.values(headerCellsWidths).forEach((cellElement) => {
|
|
94
|
+
cellElement.initialWidth = Math.floor(cellElement.cell.offsetWidth)
|
|
95
|
+
})
|
|
101
96
|
|
|
102
|
-
return
|
|
97
|
+
return headerCellsWidths
|
|
103
98
|
}
|
|
104
99
|
|
|
105
|
-
const isMouseDownOnHandler = ref<boolean>(false)
|
|
106
|
-
const isMouseUpOnHandler = ref<boolean>(false)
|
|
107
|
-
|
|
108
100
|
const handleResizeControlMouseDown = (cellId: string, enableColumnResizing: boolean) => {
|
|
109
101
|
if (!enableColumnResizing) return
|
|
110
102
|
|
|
111
103
|
isResizing.value = true
|
|
112
104
|
resizingCellId.value = cellId
|
|
113
|
-
|
|
114
|
-
if (cells.value) {
|
|
115
|
-
const resizingCell = cells.value[cellId].cell
|
|
116
|
-
let neighborCell = resizingCell.nextElementSibling as HTMLTableCellElement
|
|
117
|
-
|
|
118
|
-
if (!neighborCell) {
|
|
119
|
-
neighborCell = resizingCell.previousElementSibling as HTMLTableCellElement
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
neighborCellId.value = neighborCell ? neighborCell.id.split('_')[0] : ''
|
|
123
|
-
|
|
124
|
-
unregisterMouseMove.value = useEventListener(document, 'mousemove', handleCellResize)
|
|
125
|
-
}
|
|
105
|
+
unregisterMouseMove.value = useEventListener(document, 'mousemove', handleCellResize)
|
|
126
106
|
}
|
|
127
107
|
|
|
128
108
|
const handleResizeControlMouseUp = (e: Event) => {
|
|
129
109
|
const targetHTMLElement = e.target as HTMLElement
|
|
130
|
-
isMouseUpOnHandler.value =
|
|
131
|
-
targetHTMLElement.className.includes && targetHTMLElement.className.includes('resize-handler')
|
|
110
|
+
isMouseUpOnHandler.value = targetHTMLElement.className?.includes?.('resize-handler') || false
|
|
132
111
|
|
|
133
112
|
if (!isResizing.value) return
|
|
134
113
|
|
|
114
|
+
cleanupResizeState()
|
|
115
|
+
updateColumnSizingAfterResize()
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const cleanupResizeState = () => {
|
|
135
119
|
isResizing.value = false
|
|
136
120
|
resizingCellId.value = ''
|
|
137
|
-
neighborCellId.value = ''
|
|
138
121
|
|
|
139
122
|
if (unregisterMouseMove.value) {
|
|
140
123
|
unregisterMouseMove.value()
|
|
124
|
+
unregisterMouseMove.value = undefined
|
|
141
125
|
}
|
|
126
|
+
}
|
|
142
127
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
for (const cell in cells.value) {
|
|
147
|
-
const currentCell = cells.value[cell]
|
|
148
|
-
const newWidth = !currentCell.cell.hasAttribute('can-resize')
|
|
149
|
-
? currentCell.initialWidth
|
|
150
|
-
: Math.floor(currentCell.cell.offsetWidth) <= currentCell.minWidth
|
|
151
|
-
? currentCell.minWidth
|
|
152
|
-
: currentCell.cell.offsetWidth
|
|
128
|
+
const updateColumnSizingAfterResize = () => {
|
|
129
|
+
if (!cells.value || !tableElement.value?.tableRef) return
|
|
153
130
|
|
|
154
|
-
|
|
155
|
-
updatedColumnSizingValue[cell] = newWidth
|
|
156
|
-
}
|
|
131
|
+
const updatedColumnSizingValue: Record<string, number> = {}
|
|
157
132
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
|
161
140
|
|
|
162
|
-
|
|
141
|
+
currentCell.cell.style.width = newWidth + 'px'
|
|
142
|
+
updatedColumnSizingValue[cell] = newWidth
|
|
163
143
|
}
|
|
164
|
-
}
|
|
165
144
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
145
|
+
updatedColumnSizingValue[TABLE_ID] = tableElement.value.tableRef.offsetWidth
|
|
146
|
+
calculatedColumnSizing.value = updatedColumnSizingValue
|
|
147
|
+
}
|
|
170
148
|
|
|
171
|
-
|
|
149
|
+
const getLastCellOnTheRightExtraSpace = (cellId: string) => {
|
|
150
|
+
return cellId === 'actions' ? LAST_CELL_EXTRA_SPACE : 0
|
|
172
151
|
}
|
|
173
152
|
|
|
174
153
|
const lastCell = computed(() => {
|
|
175
|
-
if (cells.value)
|
|
176
|
-
|
|
177
|
-
|
|
154
|
+
if (!cells.value || !tableHeaderElement.value?.headRef) return undefined
|
|
155
|
+
|
|
156
|
+
const headerCells = [...tableHeaderElement.value.headRef.querySelectorAll('th')]
|
|
157
|
+
if (headerCells.length === 0) return undefined
|
|
178
158
|
|
|
179
|
-
|
|
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)]
|
|
180
171
|
})
|
|
181
172
|
|
|
182
173
|
const getCellId = (cell: HTMLTableCellElement) => {
|
|
@@ -186,7 +177,6 @@ export function useResizeColumns() {
|
|
|
186
177
|
const resizeCells = (cell: HTMLTableCellElement | null, e: MouseEvent) => {
|
|
187
178
|
if (!cell || !tableElement.value?.tableRef || !lastCell.value) {
|
|
188
179
|
resizingCellId.value = ''
|
|
189
|
-
neighborCellId.value = ''
|
|
190
180
|
|
|
191
181
|
return
|
|
192
182
|
}
|
|
@@ -194,8 +184,8 @@ export function useResizeColumns() {
|
|
|
194
184
|
const movementX = e.movementX
|
|
195
185
|
const direction: 'left' | 'right' = movementX < 0 ? 'left' : 'right'
|
|
196
186
|
const newCellWidth = Math.floor(parseInt(cell.style.width)) + movementX
|
|
197
|
-
|
|
198
|
-
|
|
187
|
+
|
|
188
|
+
const newTableWidth = Math.floor(parseInt(tableElement.value.tableRef.style.width)) + movementX
|
|
199
189
|
const newLastCellWidth = Math.floor(parseInt(lastCell.value.cell.style.width)) - movementX
|
|
200
190
|
|
|
201
191
|
if (direction === 'left') {
|
|
@@ -217,10 +207,10 @@ export function useResizeColumns() {
|
|
|
217
207
|
return
|
|
218
208
|
}
|
|
219
209
|
} else {
|
|
210
|
+
const lastCellId = getCellId(lastCell.value.cell)
|
|
220
211
|
const min =
|
|
221
|
-
cells.value && cells.value[
|
|
222
|
-
? cells.value[
|
|
223
|
-
getLastCellOnTheRightExtraSpace(lastCell.value.cell)
|
|
212
|
+
cells.value && cells.value[lastCellId]
|
|
213
|
+
? cells.value[lastCellId].minWidth + getLastCellOnTheRightExtraSpace(lastCellId)
|
|
224
214
|
: MIN_CELL_WIDTH
|
|
225
215
|
|
|
226
216
|
if (
|
|
@@ -239,104 +229,196 @@ export function useResizeColumns() {
|
|
|
239
229
|
const handleCellResize = (e: MouseEvent) => {
|
|
240
230
|
e.preventDefault()
|
|
241
231
|
|
|
242
|
-
if (cells.value)
|
|
243
|
-
const resizingCell = cells.value[resizingCellId.value]?.cell
|
|
232
|
+
if (!cells.value) return
|
|
244
233
|
|
|
245
|
-
|
|
246
|
-
|
|
234
|
+
const resizingCell = cells.value[resizingCellId.value]?.cell
|
|
235
|
+
resizeCells(resizingCell, e)
|
|
247
236
|
}
|
|
248
237
|
|
|
249
238
|
const resetCells = () => {
|
|
250
|
-
if (cells.value
|
|
251
|
-
tableElement.value.tableRef.style.width = ''
|
|
239
|
+
if (!cells.value || !tableElement.value?.tableRef) return
|
|
252
240
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
241
|
+
tableElement.value.tableRef.style.width = ''
|
|
242
|
+
calculatedColumnSizing.value = {}
|
|
243
|
+
setInitialColumnWidths()
|
|
256
244
|
}
|
|
257
245
|
|
|
258
246
|
const resetCell = (cellId: string) => {
|
|
259
247
|
if (
|
|
260
|
-
cells.value
|
|
261
|
-
calculatedColumnSizing.value
|
|
262
|
-
lastCell.value
|
|
263
|
-
tableElement.value
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
const diff = thisCellBaseWidth - thisCellCurrentWidth
|
|
269
|
-
|
|
270
|
-
let newTableWidth = calculatedColumnSizing.value['table'] + diff
|
|
271
|
-
|
|
272
|
-
if (newTableWidth < minTableWidth.value) {
|
|
273
|
-
const tableWidthDiff = minTableWidth.value - newTableWidth
|
|
274
|
-
const newLastCellWidth =
|
|
275
|
-
calculatedColumnSizing.value[getCellId(lastCell.value.cell)] + tableWidthDiff
|
|
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 }
|
|
276
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)
|
|
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
|
|
277
282
|
lastCell.value.cell.style.width = newLastCellWidth + 'px'
|
|
278
|
-
newTableWidth = minTableWidth.value
|
|
279
283
|
}
|
|
280
284
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
calculatedColumnSizing.value[cellId] = thisCellBaseWidth
|
|
284
|
-
calculatedColumnSizing.value['table'] = newTableWidth
|
|
285
|
+
newTableWidth = minTableWidth.value
|
|
286
|
+
updatedColumnSizingValue[lastCellId] = newLastCellWidth
|
|
285
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
|
|
286
295
|
}
|
|
287
296
|
|
|
288
297
|
const getTableWrapperWidth = () => {
|
|
289
|
-
|
|
290
|
-
return tableElement.value.scrollAreaElementRef?.tableWrapperRef.$el.offsetWidth - 3
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
return 0
|
|
298
|
+
return tableElement.value?.scrollAreaElementRef?.tableWrapperRef?.$el.offsetWidth - 3 || 0
|
|
294
299
|
}
|
|
295
300
|
|
|
296
301
|
const getTableWidth = () => {
|
|
297
|
-
|
|
298
|
-
return tableElement.value.tableRef.offsetWidth
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
return 0
|
|
302
|
+
return tableElement.value?.tableRef?.offsetWidth || 0
|
|
302
303
|
}
|
|
303
304
|
|
|
304
305
|
const setInitialColumnWidths = () => {
|
|
305
306
|
cells.value = getCells()
|
|
306
307
|
|
|
307
|
-
if (cells.value)
|
|
308
|
-
const updatedColumnSizingValue: Record<string, number> = {}
|
|
309
|
-
|
|
310
|
-
for (const cell in cells.value) {
|
|
311
|
-
if (!cells.value[cell].cell.style.width) {
|
|
312
|
-
cells.value[cell].cell.style.width = cells.value[cell].initialWidth + 'px'
|
|
313
|
-
}
|
|
308
|
+
if (!cells.value) return
|
|
314
309
|
|
|
315
|
-
|
|
310
|
+
const updatedColumnSizingValue: Record<string, number> = {}
|
|
316
311
|
|
|
317
|
-
|
|
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'
|
|
318
315
|
}
|
|
319
316
|
|
|
320
|
-
|
|
321
|
-
|
|
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')
|
|
322
326
|
|
|
323
|
-
|
|
324
|
-
|
|
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()
|
|
325
332
|
} else {
|
|
326
333
|
initialTableWidth.value = tableOffsetWidth
|
|
327
334
|
tableElement.value.tableRef.style.width = tableOffsetWidth + 'px'
|
|
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
|
+
}
|
|
328
355
|
|
|
329
|
-
|
|
330
|
-
|
|
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
|
|
331
370
|
}
|
|
371
|
+
} else {
|
|
372
|
+
const newLastCellWidth = cells.value?.[cellId]?.baseWidth || cell.offsetWidth
|
|
373
|
+
updatedColumnSizingValue[cellId] = newLastCellWidth
|
|
332
374
|
}
|
|
375
|
+
})
|
|
376
|
+
|
|
377
|
+
const wouldBeTableWidth = Object.values(updatedColumnSizingValue).reduce(
|
|
378
|
+
(acc, value) => (acc += value),
|
|
379
|
+
0
|
|
380
|
+
)
|
|
333
381
|
|
|
382
|
+
if (tableElement.value?.tableRef) {
|
|
334
383
|
minTableWidth.value = getTableWrapperWidth()
|
|
384
|
+
const newTableWidth = Math.max(wouldBeTableWidth, minTableWidth.value)
|
|
385
|
+
tableElement.value.tableRef.style.width = newTableWidth + 'px'
|
|
386
|
+
updatedColumnSizingValue[TABLE_ID] = newTableWidth
|
|
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()
|
|
335
402
|
|
|
336
|
-
|
|
403
|
+
if (tableWidth < minTableWidth.value) {
|
|
404
|
+
setTableFullScreen()
|
|
337
405
|
}
|
|
338
406
|
}
|
|
339
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'
|
|
420
|
+
}
|
|
421
|
+
|
|
340
422
|
return {
|
|
341
423
|
cells,
|
|
342
424
|
tableElement,
|
|
@@ -350,6 +432,8 @@ export function useResizeColumns() {
|
|
|
350
432
|
resetCells,
|
|
351
433
|
setInitialColumnWidths,
|
|
352
434
|
setProvidedCellWidths,
|
|
435
|
+
setColumnWidthsOnColumnVisibilityChange,
|
|
436
|
+
setColumnWidthsOnWindowResize,
|
|
353
437
|
isMouseDownOnHandler,
|
|
354
438
|
isMouseUpOnHandler
|
|
355
439
|
}
|