@soft-stech/bootsman-ui-shadcn 1.4.36 → 1.4.37
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/BuiTableHead.vue_vue_type_script_setup_true_lang-JNDLoSoG.js +37 -0
- package/dist/BuiTableHeader.vue_vue_type_script_setup_true_lang-18MBtNeo.js +30 -0
- package/dist/components/ui/table/BuiDataTable.vue.d.ts +7 -6
- package/dist/components/ui/table/BuiTableHead.js +1 -1
- package/dist/components/ui/table/BuiTableHeader.js +1 -1
- package/dist/components/ui/table/BuiTableHeader.vue.d.ts +6 -2
- package/dist/components/ui/table/index.js +810 -278
- package/dist/index.js +2 -2
- package/dist/lib/useResizeColumns.d.ts +127 -0
- package/dist/lib/useResizeColumns.js +89 -0
- package/package.json +3 -1
- package/src/components/stories/BuiDataTable.story.vue +4 -4
- package/src/components/ui/table/BuiDataTable.vue +56 -20
- package/src/components/ui/table/BuiTableHead.vue +6 -2
- package/src/components/ui/table/BuiTableHeader.vue +6 -0
- package/src/lib/useResizeColumns.ts +202 -0
- package/dist/BuiTableHead.vue_vue_type_script_setup_true_lang-Bz1T89Vm.js +0 -32
- package/dist/BuiTableHeader.vue_vue_type_script_setup_true_lang-H9TKoH8p.js +0 -26
@@ -0,0 +1,202 @@
|
|
1
|
+
import { ref } from 'vue'
|
2
|
+
import BuiTableHeader from '@/components/ui/table/BuiTableHeader.vue'
|
3
|
+
import { useEventListener } from '@vueuse/core'
|
4
|
+
|
5
|
+
export function useResizeColumns() {
|
6
|
+
const isResizing = ref<boolean>(false)
|
7
|
+
const resizingCellId = ref<string>('')
|
8
|
+
const neighborCellId = ref<string>('')
|
9
|
+
const cells = ref<
|
10
|
+
| {
|
11
|
+
[key: string]: { cell: HTMLTableCellElement; initialWidth: number }
|
12
|
+
}
|
13
|
+
| undefined
|
14
|
+
>(undefined)
|
15
|
+
const minCellWidth = ref<number>(90)
|
16
|
+
const calculatedColumnSizing = ref<Record<string, number> | undefined>(undefined)
|
17
|
+
const tableHeaderElement = ref<InstanceType<typeof BuiTableHeader> | null>(null)
|
18
|
+
const unregisterMouseMove = ref<Function | undefined>(undefined)
|
19
|
+
|
20
|
+
const setProvidedCellWidths = (columnSizing: Record<string, number> | undefined) => {
|
21
|
+
if (tableHeaderElement.value && tableHeaderElement.value.headRef) {
|
22
|
+
const headerCells = [...tableHeaderElement.value.headRef.querySelectorAll('th')]
|
23
|
+
|
24
|
+
//установить заданные как модель изначальные размеры
|
25
|
+
headerCells.forEach((cell) => {
|
26
|
+
const cellId = cell.id.split('_')[0]
|
27
|
+
|
28
|
+
if (columnSizing && columnSizing[cellId]) {
|
29
|
+
cell.style.width = columnSizing[cellId] + 'px'
|
30
|
+
}
|
31
|
+
})
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
const getCells = () => {
|
36
|
+
if (tableHeaderElement.value && tableHeaderElement.value.headRef) {
|
37
|
+
const headerCells = [...tableHeaderElement.value.headRef.querySelectorAll('th')]
|
38
|
+
const headerCellsWidths: {
|
39
|
+
[key: string]: { cell: HTMLTableCellElement; initialWidth: number }
|
40
|
+
} = headerCells.reduce((acc, cell) => {
|
41
|
+
const cellId = cell.id.split('_')[0]
|
42
|
+
return {
|
43
|
+
...acc,
|
44
|
+
[cellId]: {
|
45
|
+
cell: cell,
|
46
|
+
initialWidth: cell.offsetWidth
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}, {})
|
50
|
+
|
51
|
+
return headerCellsWidths
|
52
|
+
}
|
53
|
+
|
54
|
+
return undefined
|
55
|
+
}
|
56
|
+
|
57
|
+
const handleResizeControlMouseDown = (cellId: string, enableColumnResizing: boolean) => {
|
58
|
+
if (!enableColumnResizing) return
|
59
|
+
|
60
|
+
isResizing.value = true
|
61
|
+
resizingCellId.value = cellId
|
62
|
+
|
63
|
+
if (cells.value) {
|
64
|
+
const resizingCell = cells.value[cellId].cell
|
65
|
+
let neighborCell = resizingCell.nextElementSibling as HTMLTableCellElement
|
66
|
+
|
67
|
+
if (!neighborCell) {
|
68
|
+
neighborCell = resizingCell.previousElementSibling as HTMLTableCellElement
|
69
|
+
}
|
70
|
+
|
71
|
+
neighborCellId.value = neighborCell ? neighborCell.id.split('_')[0] : ''
|
72
|
+
|
73
|
+
unregisterMouseMove.value = useEventListener(document, 'mousemove', handleCellResize)
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
const handleResizeControlMouseUp = () => {
|
78
|
+
if (!isResizing.value) return
|
79
|
+
|
80
|
+
isResizing.value = false
|
81
|
+
resizingCellId.value = ''
|
82
|
+
neighborCellId.value = ''
|
83
|
+
|
84
|
+
if (unregisterMouseMove.value) {
|
85
|
+
unregisterMouseMove.value()
|
86
|
+
}
|
87
|
+
|
88
|
+
if (cells.value) {
|
89
|
+
const updatedColumnSizingValue: Record<string, number> = {}
|
90
|
+
|
91
|
+
for (let cell in cells.value) {
|
92
|
+
const currentCell = cells.value[cell]
|
93
|
+
const newWidth = !currentCell.cell.hasAttribute('can-resize')
|
94
|
+
? currentCell.initialWidth
|
95
|
+
: Math.floor(currentCell.cell.offsetWidth) <= minCellWidth.value
|
96
|
+
? minCellWidth.value
|
97
|
+
: currentCell.cell.offsetWidth
|
98
|
+
|
99
|
+
currentCell.cell.style.width = newWidth + 'px'
|
100
|
+
updatedColumnSizingValue[cell] = newWidth
|
101
|
+
}
|
102
|
+
|
103
|
+
calculatedColumnSizing.value = updatedColumnSizingValue
|
104
|
+
}
|
105
|
+
}
|
106
|
+
const getLastCellOnTheRightExtraSpace = (cell: HTMLTableCellElement) => {
|
107
|
+
if (!cell.nextElementSibling) {
|
108
|
+
const cellWrapperElement = cell.querySelector('.header-cell_wrapper') as HTMLElement | null
|
109
|
+
|
110
|
+
if (cellWrapperElement) {
|
111
|
+
return parseInt(window.getComputedStyle(cellWrapperElement).paddingRight)
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
return 0
|
116
|
+
}
|
117
|
+
|
118
|
+
const resizeCells = (
|
119
|
+
cell: HTMLTableCellElement | null,
|
120
|
+
neighborCell: HTMLTableCellElement | null,
|
121
|
+
e: MouseEvent
|
122
|
+
) => {
|
123
|
+
if (!cell || !neighborCell) {
|
124
|
+
resizingCellId.value = ''
|
125
|
+
neighborCellId.value = ''
|
126
|
+
|
127
|
+
return
|
128
|
+
}
|
129
|
+
|
130
|
+
const movementX = e.movementX
|
131
|
+
const direction: 'left' | 'right' = movementX < 0 ? 'left' : 'right'
|
132
|
+
const newCellWidth = Math.floor(parseInt(cell.style.width)) + movementX
|
133
|
+
const newNeighborCellWidth = Math.floor(parseInt(neighborCell.style.width)) - movementX
|
134
|
+
|
135
|
+
if (direction === 'left') {
|
136
|
+
if (newCellWidth <= minCellWidth.value || !cell.hasAttribute('can-resize')) {
|
137
|
+
const nextCell = cell.previousElementSibling as HTMLTableCellElement | null
|
138
|
+
|
139
|
+
resizeCells(nextCell, neighborCell, e)
|
140
|
+
} else {
|
141
|
+
cell.style.width = newCellWidth + 'px'
|
142
|
+
neighborCell.style.width = newNeighborCellWidth + 'px'
|
143
|
+
}
|
144
|
+
} else {
|
145
|
+
if (
|
146
|
+
newNeighborCellWidth <=
|
147
|
+
minCellWidth.value + getLastCellOnTheRightExtraSpace(neighborCell) ||
|
148
|
+
!neighborCell.hasAttribute('can-resize')
|
149
|
+
) {
|
150
|
+
const nextNeighborCell = neighborCell.nextElementSibling as HTMLTableCellElement | null
|
151
|
+
|
152
|
+
resizeCells(cell, nextNeighborCell, e)
|
153
|
+
} else {
|
154
|
+
cell.style.width = newCellWidth + 'px'
|
155
|
+
neighborCell.style.width = newNeighborCellWidth + 'px'
|
156
|
+
}
|
157
|
+
}
|
158
|
+
}
|
159
|
+
|
160
|
+
const handleCellResize = (e: MouseEvent) => {
|
161
|
+
e.preventDefault()
|
162
|
+
|
163
|
+
if (cells.value) {
|
164
|
+
const resizingCell = cells.value[resizingCellId.value]?.cell
|
165
|
+
const neighborCell = cells.value[neighborCellId.value]?.cell
|
166
|
+
|
167
|
+
resizeCells(resizingCell, neighborCell, e)
|
168
|
+
}
|
169
|
+
}
|
170
|
+
|
171
|
+
const resetCells = () => {
|
172
|
+
if (cells.value) {
|
173
|
+
for (let cell in cells.value) {
|
174
|
+
cells.value[cell].cell.style.width = cells.value[cell].initialWidth + 'px'
|
175
|
+
}
|
176
|
+
}
|
177
|
+
}
|
178
|
+
|
179
|
+
const setInitialColumnWidths = () => {
|
180
|
+
cells.value = getCells()
|
181
|
+
|
182
|
+
if (cells.value) {
|
183
|
+
for (let cell in cells.value) {
|
184
|
+
if (!cells.value[cell].cell.style.width) {
|
185
|
+
cells.value[cell].cell.style.width = cells.value[cell].initialWidth + 'px'
|
186
|
+
}
|
187
|
+
}
|
188
|
+
}
|
189
|
+
}
|
190
|
+
|
191
|
+
return {
|
192
|
+
tableHeaderElement,
|
193
|
+
calculatedColumnSizing,
|
194
|
+
isResizing,
|
195
|
+
resizingCellId,
|
196
|
+
handleResizeControlMouseDown,
|
197
|
+
handleResizeControlMouseUp,
|
198
|
+
resetCells,
|
199
|
+
setInitialColumnWidths,
|
200
|
+
setProvidedCellWidths
|
201
|
+
}
|
202
|
+
}
|
@@ -1,32 +0,0 @@
|
|
1
|
-
import { defineComponent as l, openBlock as n, createElementBlock as a, normalizeClass as r, unref as d, createElementVNode as o, renderSlot as c } from "vue";
|
2
|
-
import { g as f } from "./utils-C11OfLQK.js";
|
3
|
-
const p = { class: "flex h-full w-full items-center whitespace-nowrap border-r border-border/[0.16] px-2 text-sm font-semibold" }, u = /* @__PURE__ */ l({
|
4
|
-
__name: "BuiTableHead",
|
5
|
-
props: {
|
6
|
-
class: {},
|
7
|
-
freezeHeader: { type: Boolean }
|
8
|
-
},
|
9
|
-
setup(t) {
|
10
|
-
const e = t;
|
11
|
-
return (s, i) => (n(), a("th", {
|
12
|
-
class: r(
|
13
|
-
d(f)(
|
14
|
-
"h-10 text-left align-middle text-foreground [&:has([role=checkbox])]:pr-0 ",
|
15
|
-
e.class,
|
16
|
-
e.freezeHeader ? "bg-background p-0" : "bg-foreground/[0.04] p-0"
|
17
|
-
)
|
18
|
-
)
|
19
|
-
}, [
|
20
|
-
o("div", {
|
21
|
-
class: r(["flex h-full items-center !border-b !border-border/[0.16]", { "bg-foreground/[0.04]": e.freezeHeader }])
|
22
|
-
}, [
|
23
|
-
o("div", p, [
|
24
|
-
c(s.$slots, "default")
|
25
|
-
])
|
26
|
-
], 2)
|
27
|
-
], 2));
|
28
|
-
}
|
29
|
-
});
|
30
|
-
export {
|
31
|
-
u as _
|
32
|
-
};
|
@@ -1,26 +0,0 @@
|
|
1
|
-
import { defineComponent as d, openBlock as l, createElementBlock as o, normalizeClass as s, unref as i, renderSlot as a } from "vue";
|
2
|
-
import { g as c } from "./utils-C11OfLQK.js";
|
3
|
-
const _ = /* @__PURE__ */ d({
|
4
|
-
__name: "BuiTableHeader",
|
5
|
-
props: {
|
6
|
-
class: {},
|
7
|
-
freezeHeader: { type: Boolean }
|
8
|
-
},
|
9
|
-
setup(r) {
|
10
|
-
const e = r;
|
11
|
-
return (t, n) => (l(), o("thead", {
|
12
|
-
class: s(
|
13
|
-
i(c)(
|
14
|
-
"[&_tr]:border-border/[0.16]",
|
15
|
-
e.class,
|
16
|
-
e.freezeHeader ? "sticky top-0 z-[1] [&_th:first-child>div>div]:pl-3 [&_th:last-child>div>div]:border-r-0 [&_th:last-child>div>div]:pr-14 [&_tr:last-child]:border-b-0" : "[&_th:first-child>div]:pl-3 [&_th:last-child>div]:border-0 [&_th:last-child>div]:pr-14 [&_tr]:border-b"
|
17
|
-
)
|
18
|
-
)
|
19
|
-
}, [
|
20
|
-
a(t.$slots, "default")
|
21
|
-
], 2));
|
22
|
-
}
|
23
|
-
});
|
24
|
-
export {
|
25
|
-
_
|
26
|
-
};
|