@soft-stech/bootsman-ui-shadcn 2.0.24 → 2.0.25
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/lib/useResizeColumns.js +101 -88
- package/package.json +1 -1
- package/src/lib/useResizeColumns.ts +19 -1
|
@@ -1,54 +1,55 @@
|
|
|
1
1
|
import { ref as c, computed as S } from "vue";
|
|
2
2
|
import "vee-validate";
|
|
3
|
-
import { useEventListener as
|
|
4
|
-
const
|
|
3
|
+
import { useEventListener as $ } from "@vueuse/core";
|
|
4
|
+
const p = 90, k = 56, A = 10, C = "table";
|
|
5
5
|
function Q() {
|
|
6
|
-
const y = c(!1),
|
|
6
|
+
const y = c(!1), R = c(""), l = c(void 0), n = c(void 0), W = c(null), i = c(null), O = c(0), f = c(0), m = c(void 0), _ = c(!1), T = c(!1), z = (e) => {
|
|
7
7
|
if (!W.value?.headRef || !e) return;
|
|
8
8
|
[...W.value.headRef.querySelectorAll("th")].forEach((u) => {
|
|
9
|
-
const a = r(u),
|
|
10
|
-
u.style.width =
|
|
9
|
+
const a = r(u), h = e[a];
|
|
10
|
+
u.style.width = h && h !== 0 ? e[a] + "px" : "";
|
|
11
11
|
});
|
|
12
|
-
},
|
|
13
|
-
const e =
|
|
12
|
+
}, D = () => {
|
|
13
|
+
const e = i.value?.tableRef, t = W.value?.headRef;
|
|
14
14
|
if (!t || !e) return;
|
|
15
15
|
const u = [...t.querySelectorAll("th")];
|
|
16
16
|
n.value?.[C] === 0 && (n.value = {}, e.style.width = "");
|
|
17
17
|
const a = M();
|
|
18
18
|
e.style.width = "min-content";
|
|
19
|
-
const
|
|
20
|
-
|
|
19
|
+
const h = u.reduce((v, s) => {
|
|
20
|
+
s.style.width = "";
|
|
21
|
+
const o = r(s), b = Math.floor(s.offsetWidth), w = o === "actions" ? A : s.offsetWidth < p ? p : s.offsetWidth;
|
|
21
22
|
return {
|
|
22
|
-
...
|
|
23
|
-
[
|
|
24
|
-
cell:
|
|
23
|
+
...v,
|
|
24
|
+
[o]: {
|
|
25
|
+
cell: s,
|
|
25
26
|
initialWidth: b,
|
|
26
27
|
baseWidth: b,
|
|
27
|
-
minWidth:
|
|
28
|
+
minWidth: w
|
|
28
29
|
}
|
|
29
30
|
};
|
|
30
31
|
}, {});
|
|
31
|
-
return e.style.width = "", Object.values(
|
|
32
|
-
|
|
33
|
-
}), z(n.value), e.style.width = (n.value?.[C] || a) + "px", Object.values(
|
|
34
|
-
|
|
35
|
-
}),
|
|
36
|
-
},
|
|
37
|
-
t && (y.value = !0,
|
|
38
|
-
},
|
|
32
|
+
return e.style.width = "", Object.values(h).forEach((v) => {
|
|
33
|
+
v.baseWidth = Math.floor(v.cell.offsetWidth);
|
|
34
|
+
}), z(n.value), e.style.width = (n.value?.[C] || a) + "px", Object.values(h).forEach((v) => {
|
|
35
|
+
v.initialWidth = Math.floor(v.cell.offsetWidth);
|
|
36
|
+
}), h;
|
|
37
|
+
}, H = (e, t) => {
|
|
38
|
+
t && (y.value = !0, R.value = e, m.value = $(document, "mousemove", X));
|
|
39
|
+
}, q = (e) => {
|
|
39
40
|
const t = e.target;
|
|
40
|
-
T.value = t.className?.includes?.("resize-handler") || !1, y.value && (
|
|
41
|
-
}, q = () => {
|
|
42
|
-
y.value = !1, w.value = "", m.value && (m.value(), m.value = void 0);
|
|
41
|
+
T.value = t.className?.includes?.("resize-handler") || !1, y.value && (V(), N());
|
|
43
42
|
}, V = () => {
|
|
44
|
-
|
|
43
|
+
y.value = !1, R.value = "", m.value && (m.value(), m.value = void 0);
|
|
44
|
+
}, N = () => {
|
|
45
|
+
if (!l.value || !i.value?.tableRef) return;
|
|
45
46
|
const e = {};
|
|
46
47
|
for (const t in l.value) {
|
|
47
48
|
const u = l.value[t], a = u.cell.hasAttribute("can-resize") ? Math.floor(u.cell.offsetWidth) <= u.minWidth ? u.minWidth : u.cell.offsetWidth : u.initialWidth;
|
|
48
49
|
u.cell.style.width = a + "px", e[t] = a;
|
|
49
50
|
}
|
|
50
|
-
e[C] =
|
|
51
|
-
},
|
|
51
|
+
e[C] = i.value.tableRef.offsetWidth, n.value = e;
|
|
52
|
+
}, j = (e) => e === "actions" ? k : 0, d = S(() => {
|
|
52
53
|
if (!l.value || !W.value?.headRef) return;
|
|
53
54
|
const e = [...W.value.headRef.querySelectorAll("th")];
|
|
54
55
|
if (e.length === 0) return;
|
|
@@ -60,117 +61,129 @@ function Q() {
|
|
|
60
61
|
if (e.length < 2) return;
|
|
61
62
|
const t = e[e.length - 2];
|
|
62
63
|
return l.value[r(t)];
|
|
63
|
-
}), r = (e) => e.id.split("_")[0],
|
|
64
|
-
if (!e || !
|
|
65
|
-
|
|
64
|
+
}), r = (e) => e.id.split("_")[0], B = (e, t) => {
|
|
65
|
+
if (!e || !i.value?.tableRef || !d.value) {
|
|
66
|
+
R.value = "";
|
|
66
67
|
return;
|
|
67
68
|
}
|
|
68
|
-
const u = t.movementX, a = u < 0 ? "left" : "right",
|
|
69
|
+
const u = t.movementX, a = u < 0 ? "left" : "right", h = Math.floor(parseInt(e.style.width)) + u, v = Math.floor(parseInt(i.value.tableRef.style.width)) + u, s = Math.floor(parseInt(d.value.cell.style.width)) - u;
|
|
69
70
|
if (a === "left") {
|
|
70
|
-
const
|
|
71
|
-
if (
|
|
72
|
-
e.style.width =
|
|
71
|
+
const o = l.value && l.value[r(e)] ? l.value[r(e)].minWidth : p;
|
|
72
|
+
if (h >= o)
|
|
73
|
+
e.style.width = h + "px", v >= f.value ? i.value.tableRef.style.width = v + "px" : (i.value.tableRef.style.width = f.value + "px", d.value.cell.style.width = s + "px");
|
|
73
74
|
else
|
|
74
75
|
return;
|
|
75
76
|
} else {
|
|
76
|
-
const
|
|
77
|
-
|
|
77
|
+
const o = r(d.value.cell), b = l.value && l.value[o] ? l.value[o].minWidth + j(o) : p;
|
|
78
|
+
s >= b && i.value.tableRef.offsetWidth <= f.value ? d.value.cell.style.width = s + "px" : i.value.tableRef.style.width = v + "px", e.style.width = h + "px";
|
|
78
79
|
}
|
|
79
|
-
},
|
|
80
|
+
}, X = (e) => {
|
|
80
81
|
if (e.preventDefault(), !l.value) return;
|
|
81
|
-
const t = l.value[
|
|
82
|
-
|
|
82
|
+
const t = l.value[R.value]?.cell;
|
|
83
|
+
B(t, e);
|
|
83
84
|
}, L = () => {
|
|
84
|
-
!l.value || !
|
|
85
|
-
},
|
|
86
|
-
if (!l.value || !n.value || !
|
|
85
|
+
!l.value || !i.value?.tableRef || (i.value.tableRef.style.width = "", n.value = {}, E());
|
|
86
|
+
}, P = (e) => {
|
|
87
|
+
if (!l.value || !n.value || !d.value || !i.value?.tableRef)
|
|
87
88
|
return;
|
|
88
|
-
const t = { ...n.value }, a = l.value[e].baseWidth,
|
|
89
|
-
let
|
|
90
|
-
if (
|
|
91
|
-
const b = f.value -
|
|
92
|
-
let
|
|
93
|
-
if (e ===
|
|
89
|
+
const t = { ...n.value }, a = l.value[e].baseWidth, h = n.value[e], v = a - h;
|
|
90
|
+
let s = n.value[C] + v, o = r(d.value.cell);
|
|
91
|
+
if (s < f.value) {
|
|
92
|
+
const b = f.value - s;
|
|
93
|
+
let w;
|
|
94
|
+
if (e === o) {
|
|
94
95
|
if (!x.value) {
|
|
95
96
|
L();
|
|
96
97
|
return;
|
|
97
98
|
}
|
|
98
|
-
|
|
99
|
+
o = r(x.value.cell), w = n.value[o] + b, x.value.cell.style.width = w + "px";
|
|
99
100
|
} else
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
w = n.value[r(d.value.cell)] + b, d.value.cell.style.width = w + "px";
|
|
102
|
+
s = f.value, t[o] = w;
|
|
102
103
|
}
|
|
103
|
-
l.value[e].cell.style.width = a + "px",
|
|
104
|
-
}, g = () =>
|
|
105
|
-
if (l.value =
|
|
104
|
+
l.value[e].cell.style.width = a + "px", i.value.tableRef.style.width = s + "px", t[e] = a, t[C] = s, n.value = t;
|
|
105
|
+
}, g = () => i.value?.scrollAreaElementRef?.tableWrapperRef?.$el.offsetWidth - 3 || 0, M = () => i.value?.tableRef?.offsetWidth || 0, E = () => {
|
|
106
|
+
if (l.value = D(), !l.value) return;
|
|
106
107
|
const e = {};
|
|
107
108
|
for (const t in l.value)
|
|
108
109
|
l.value[t].cell.style.width || (l.value[t].cell.style.width = l.value[t].initialWidth + "px"), l.value[t].cell.style.minWidth = l.value[t].minWidth + "px", e[t] = l.value[t].cell.offsetWidth;
|
|
109
|
-
if (
|
|
110
|
+
if (i.value?.tableRef) {
|
|
110
111
|
const t = M(), u = g();
|
|
111
|
-
f.value = u,
|
|
112
|
+
f.value = u, i.value.tableRef.setAttribute("initialResize", "set"), n.value?.[C] && !i.value.tableRef.style.width ? i.value.tableRef.style.width = n.value[C] + "px" : t < f.value ? I() : (O.value = t, i.value.tableRef.style.width = t + "px", e[C] = t);
|
|
112
113
|
}
|
|
113
114
|
n.value = e;
|
|
114
|
-
},
|
|
115
|
+
}, U = () => {
|
|
115
116
|
if (!W.value?.headRef || !l.value) return;
|
|
116
117
|
const e = [...W.value.headRef.querySelectorAll("th")], t = {};
|
|
117
|
-
e.forEach((a,
|
|
118
|
-
const
|
|
119
|
-
if (l.value
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
e.forEach((a, h, v) => {
|
|
119
|
+
const s = r(a);
|
|
120
|
+
if (l.value)
|
|
121
|
+
if (l.value[s])
|
|
122
|
+
l.value[s].cell = a;
|
|
123
|
+
else {
|
|
124
|
+
const o = s === "actions" ? A : a.offsetWidth < p ? p : a.offsetWidth;
|
|
125
|
+
l.value[s] = {
|
|
126
|
+
cell: a,
|
|
127
|
+
baseWidth: a.offsetWidth,
|
|
128
|
+
minWidth: o,
|
|
129
|
+
initialWidth: a.offsetWidth
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
if (h < v.length - 1) {
|
|
133
|
+
const o = n.value?.[s];
|
|
134
|
+
if (o)
|
|
135
|
+
a.style.width = o + "px", t[s] = o;
|
|
123
136
|
else {
|
|
124
137
|
a.style.width = "";
|
|
125
|
-
const b = l.value?.[
|
|
126
|
-
a.style.width = b + "px", a.style.minWidth =
|
|
138
|
+
const b = l.value?.[s]?.baseWidth || a.offsetWidth, w = l.value?.[s]?.minWidth || p;
|
|
139
|
+
a.style.width = b + "px", a.style.minWidth = w + "px", t[s] = b;
|
|
127
140
|
}
|
|
128
141
|
} else {
|
|
129
|
-
const
|
|
130
|
-
t[
|
|
142
|
+
const o = l.value?.[s]?.baseWidth || a.offsetWidth;
|
|
143
|
+
t[s] = o;
|
|
131
144
|
}
|
|
132
145
|
});
|
|
133
146
|
const u = Object.values(t).reduce(
|
|
134
|
-
(a,
|
|
147
|
+
(a, h) => a += h,
|
|
135
148
|
0
|
|
136
149
|
);
|
|
137
|
-
if (
|
|
150
|
+
if (i.value?.tableRef) {
|
|
138
151
|
f.value = g();
|
|
139
152
|
const a = Math.max(u, f.value);
|
|
140
|
-
|
|
153
|
+
i.value.tableRef.style.width = a + "px", t[C] = a;
|
|
141
154
|
}
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
const a = Math.floor(
|
|
145
|
-
t[r(
|
|
155
|
+
if (d.value) {
|
|
156
|
+
d.value.cell.style.width = "";
|
|
157
|
+
const a = Math.floor(d.value.cell.offsetWidth);
|
|
158
|
+
t[r(d.value.cell)] = a, d.value.cell.style.width = a + "px";
|
|
146
159
|
}
|
|
147
160
|
n.value = t;
|
|
148
|
-
},
|
|
161
|
+
}, F = () => {
|
|
149
162
|
const e = M();
|
|
150
163
|
f.value = g(), e < f.value && I();
|
|
151
164
|
}, I = () => {
|
|
152
|
-
if (!
|
|
153
|
-
const e = r(
|
|
154
|
-
n.value[C] = f.value,
|
|
155
|
-
const t = Math.floor(
|
|
156
|
-
n.value[e] = t,
|
|
165
|
+
if (!d.value || !n.value || !i.value?.tableRef) return;
|
|
166
|
+
const e = r(d.value.cell);
|
|
167
|
+
n.value[C] = f.value, i.value.tableRef.style.width = f.value + "px", d.value.cell.style.width = "";
|
|
168
|
+
const t = Math.floor(d.value.cell.offsetWidth);
|
|
169
|
+
n.value[e] = t, d.value.cell.style.width = t + "px";
|
|
157
170
|
};
|
|
158
171
|
return {
|
|
159
172
|
cells: l,
|
|
160
|
-
tableElement:
|
|
173
|
+
tableElement: i,
|
|
161
174
|
tableHeaderElement: W,
|
|
162
175
|
calculatedColumnSizing: n,
|
|
163
176
|
isResizing: y,
|
|
164
|
-
resizingCellId:
|
|
165
|
-
handleResizeControlMouseDown:
|
|
166
|
-
handleResizeControlMouseUp:
|
|
167
|
-
resetCell:
|
|
177
|
+
resizingCellId: R,
|
|
178
|
+
handleResizeControlMouseDown: H,
|
|
179
|
+
handleResizeControlMouseUp: q,
|
|
180
|
+
resetCell: P,
|
|
168
181
|
resetCells: L,
|
|
169
182
|
setInitialColumnWidths: E,
|
|
170
183
|
setProvidedCellWidths: z,
|
|
171
|
-
setColumnWidthsOnColumnVisibilityChange:
|
|
172
|
-
setColumnWidthsOnWindowResize:
|
|
173
|
-
isMouseDownOnHandler:
|
|
184
|
+
setColumnWidthsOnColumnVisibilityChange: U,
|
|
185
|
+
setColumnWidthsOnWindowResize: F,
|
|
186
|
+
isMouseDownOnHandler: _,
|
|
174
187
|
isMouseUpOnHandler: T
|
|
175
188
|
};
|
|
176
189
|
}
|
package/package.json
CHANGED
|
@@ -61,6 +61,8 @@ export function useResizeColumns() {
|
|
|
61
61
|
tableRef.style.width = 'min-content'
|
|
62
62
|
|
|
63
63
|
const headerCellsWidths: CELL = headerCells.reduce((acc, cell) => {
|
|
64
|
+
cell.style.width = ''
|
|
65
|
+
|
|
64
66
|
const cellId = getCellId(cell)
|
|
65
67
|
const offsetWidth = Math.floor(cell.offsetWidth)
|
|
66
68
|
const minWidth =
|
|
@@ -350,7 +352,23 @@ export function useResizeColumns() {
|
|
|
350
352
|
const cellId = getCellId(cell)
|
|
351
353
|
|
|
352
354
|
if (cells.value) {
|
|
353
|
-
cells.value[cellId]
|
|
355
|
+
if (cells.value[cellId]) {
|
|
356
|
+
cells.value[cellId].cell = cell
|
|
357
|
+
} else {
|
|
358
|
+
const minWidth =
|
|
359
|
+
cellId === 'actions'
|
|
360
|
+
? ACTIONS_CELL_MIN_WIDTH
|
|
361
|
+
: cell.offsetWidth < MIN_CELL_WIDTH
|
|
362
|
+
? MIN_CELL_WIDTH
|
|
363
|
+
: cell.offsetWidth
|
|
364
|
+
|
|
365
|
+
cells.value[cellId] = {
|
|
366
|
+
cell: cell,
|
|
367
|
+
baseWidth: cell.offsetWidth,
|
|
368
|
+
minWidth: minWidth,
|
|
369
|
+
initialWidth: cell.offsetWidth
|
|
370
|
+
}
|
|
371
|
+
}
|
|
354
372
|
}
|
|
355
373
|
|
|
356
374
|
if (index < array.length - 1) {
|