@oneflowui/ui 0.5.7 → 0.5.8
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/README.md +11 -0
- package/dist/components/Dashboard/index.vue.d.ts +1 -1
- package/dist/components/database/DatabaseView.vue.d.ts +6 -1
- package/dist/components/database/DatabaseView.vue.js +2 -2
- package/dist/components/database/DatabaseView.vue2.js +438 -293
- package/dist/components/overlay/Drawer.vue.d.ts +1 -1
- package/dist/components/overlay/Modal.vue.d.ts +1 -1
- package/dist/components/table/ColumnHeaderMenu.vue.d.ts +2 -2
- package/dist/components/table/DataTable.vue.d.ts +3 -1
- package/dist/components/table/DataTable.vue.js +2 -2
- package/dist/components/table/DataTable.vue2.js +598 -526
- package/dist/components/table/DetailSheet.vue.d.ts +2 -0
- package/dist/components/table/DetailSheet.vue.js +2 -2
- package/dist/components/table/DetailSheet.vue2.js +155 -76
- package/dist/components/table/TableDataRow.vue.d.ts +3 -1
- package/dist/components/table/TableDataRow.vue.js +3 -3
- package/dist/components/table/TableDataRow.vue2.js +95 -68
- package/dist/components/table/TableHeaderRow.vue.d.ts +3 -1
- package/dist/components/table/TableHeaderRow.vue.js +3 -3
- package/dist/components/table/TableHeaderRow.vue2.js +96 -60
- package/dist/composables/useColumnResize.d.ts +4 -1
- package/dist/composables/useColumnResize.js +114 -45
- package/dist/composables/useRowDrag.d.ts +1 -1
- package/dist/composables/useVirtualList.d.ts +1 -0
- package/dist/composables/useVirtualList.js +89 -77
- package/dist/style.css +1 -1
- package/dist/types/index.d.ts +2 -1
- package/package.json +1 -1
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { ChevronUp as
|
|
3
|
-
const
|
|
4
|
-
class: "of-table-header",
|
|
5
|
-
role: "row"
|
|
6
|
-
}, F = {
|
|
7
|
-
key: 0,
|
|
8
|
-
class: "of-th of-th-checkbox",
|
|
9
|
-
role: "columnheader",
|
|
10
|
-
"aria-label": "选择全部行"
|
|
11
|
-
}, M = {
|
|
1
|
+
import { defineComponent as M, computed as u, openBlock as a, createElementBlock as i, normalizeStyle as f, createElementVNode as r, createCommentVNode as k, Fragment as B, renderList as P, withModifiers as c, normalizeClass as W, toDisplayString as D, createBlock as b, unref as h, createVNode as K } from "vue";
|
|
2
|
+
import { ChevronUp as H, ChevronDown as m, Plus as F } from "lucide-vue-next";
|
|
3
|
+
const Y = {
|
|
12
4
|
class: "of-th-checkbox__label",
|
|
13
5
|
for: "of-table-select-all-checkbox"
|
|
14
|
-
},
|
|
6
|
+
}, O = ["checked", "indeterminate"], E = ["aria-sort", "onClick", "onKeydown", "onContextmenu", "onDblclick"], N = { class: "of-th-label" }, R = { class: "of-th-sort-icon" }, T = ["onMousedown", "onDblclick"], V = /* @__PURE__ */ M({
|
|
15
7
|
__name: "TableHeaderRow",
|
|
16
8
|
props: {
|
|
17
9
|
columns: {},
|
|
@@ -22,93 +14,137 @@ const $ = {
|
|
|
22
14
|
indeterminate: { type: Boolean, default: !1 },
|
|
23
15
|
enableResize: { type: Boolean, default: !1 },
|
|
24
16
|
enableFieldMenu: { type: Boolean, default: !1 },
|
|
25
|
-
enableAddField: { type: Boolean, default: !1 }
|
|
17
|
+
enableAddField: { type: Boolean, default: !1 },
|
|
18
|
+
density: { default: "standard" }
|
|
26
19
|
},
|
|
27
20
|
emits: ["sort", "select-all", "resize-start", "resize-dblclick", "header-contextmenu", "header-dblclick", "add-field"],
|
|
28
|
-
setup(
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
setup(t, { emit: x }) {
|
|
22
|
+
const g = t, o = x, v = {
|
|
23
|
+
compact: {
|
|
24
|
+
headerHeight: 32,
|
|
25
|
+
cellPaddingX: 10,
|
|
26
|
+
cellPaddingY: 6,
|
|
27
|
+
addColumnWidth: 32,
|
|
28
|
+
fillMinWidth: 180
|
|
29
|
+
},
|
|
30
|
+
standard: {
|
|
31
|
+
headerHeight: 36,
|
|
32
|
+
cellPaddingX: 12,
|
|
33
|
+
cellPaddingY: 8,
|
|
34
|
+
addColumnWidth: 36,
|
|
35
|
+
fillMinWidth: 220
|
|
36
|
+
},
|
|
37
|
+
comfortable: {
|
|
38
|
+
headerHeight: 40,
|
|
39
|
+
cellPaddingX: 14,
|
|
40
|
+
cellPaddingY: 10,
|
|
41
|
+
addColumnWidth: 40,
|
|
42
|
+
fillMinWidth: 240
|
|
34
43
|
}
|
|
35
|
-
|
|
44
|
+
}, s = u(() => v[g.density]), C = u(() => ({
|
|
45
|
+
minHeight: `${s.value.headerHeight}px`
|
|
46
|
+
})), y = u(() => ({
|
|
47
|
+
padding: `${s.value.cellPaddingY}px ${s.value.cellPaddingX}px`
|
|
48
|
+
})), w = u(() => ({
|
|
49
|
+
...y.value,
|
|
50
|
+
width: `${s.value.addColumnWidth}px`,
|
|
51
|
+
flexShrink: "0",
|
|
52
|
+
flexGrow: "0"
|
|
53
|
+
}));
|
|
54
|
+
function z(l) {
|
|
55
|
+
const n = y.value;
|
|
56
|
+
if (l.width === "fill") {
|
|
57
|
+
const e = `${l.minWidth ?? s.value.fillMinWidth}px`;
|
|
58
|
+
return { ...n, flex: `1 1 ${e}`, minWidth: e };
|
|
59
|
+
}
|
|
60
|
+
return { ...n, width: `${l.width}px`, flexShrink: "0", flexGrow: "0" };
|
|
36
61
|
}
|
|
37
|
-
function
|
|
38
|
-
|
|
62
|
+
function p(l) {
|
|
63
|
+
o("sort", l);
|
|
39
64
|
}
|
|
40
|
-
function
|
|
41
|
-
|
|
65
|
+
function S(l, n) {
|
|
66
|
+
l.target === l.currentTarget && (l.key !== "Enter" && l.key !== " " || (l.preventDefault(), o("sort", n)));
|
|
42
67
|
}
|
|
43
|
-
function
|
|
44
|
-
|
|
68
|
+
function $(l, n) {
|
|
69
|
+
l.stopPropagation(), o("resize-start", l, n);
|
|
45
70
|
}
|
|
46
|
-
return (
|
|
47
|
-
|
|
48
|
-
|
|
71
|
+
return (l, n) => (a(), i("div", {
|
|
72
|
+
class: "of-table-header",
|
|
73
|
+
role: "row",
|
|
74
|
+
style: f(C.value)
|
|
75
|
+
}, [
|
|
76
|
+
t.selectable ? (a(), i("div", {
|
|
77
|
+
key: 0,
|
|
78
|
+
class: "of-th of-th-checkbox",
|
|
79
|
+
role: "columnheader",
|
|
80
|
+
"aria-label": "选择全部行",
|
|
81
|
+
style: f(y.value)
|
|
82
|
+
}, [
|
|
83
|
+
r("label", Y, [
|
|
49
84
|
r("input", {
|
|
50
85
|
id: "of-table-select-all-checkbox",
|
|
51
86
|
type: "checkbox",
|
|
52
87
|
class: "of-checkbox",
|
|
53
|
-
checked:
|
|
54
|
-
indeterminate:
|
|
55
|
-
onChange: n[0] || (n[0] = (
|
|
56
|
-
}, null, 40,
|
|
88
|
+
checked: t.allSelected,
|
|
89
|
+
indeterminate: t.indeterminate,
|
|
90
|
+
onChange: n[0] || (n[0] = (e) => o("select-all"))
|
|
91
|
+
}, null, 40, O),
|
|
57
92
|
n[3] || (n[3] = r("span", { class: "of-sr-only" }, "选择全部行", -1))
|
|
58
93
|
])
|
|
59
|
-
])) :
|
|
60
|
-
(
|
|
61
|
-
key:
|
|
94
|
+
], 4)) : k("", !0),
|
|
95
|
+
(a(!0), i(B, null, P(t.columns, (e) => (a(), i("div", {
|
|
96
|
+
key: e.key,
|
|
62
97
|
role: "columnheader",
|
|
63
98
|
tabindex: "0",
|
|
64
|
-
class:
|
|
65
|
-
style:
|
|
66
|
-
"aria-sort":
|
|
67
|
-
onClick: (
|
|
68
|
-
onKeydown: (
|
|
69
|
-
onContextmenu:
|
|
70
|
-
onDblclick:
|
|
99
|
+
class: W(["of-th", { "of-th--sortable": !0, "of-th--active": t.sortKey === e.key }]),
|
|
100
|
+
style: f(z(e)),
|
|
101
|
+
"aria-sort": t.sortKey === e.key ? t.sortOrder === "asc" ? "ascending" : "descending" : "none",
|
|
102
|
+
onClick: (d) => p(e.key),
|
|
103
|
+
onKeydown: (d) => S(d, e.key),
|
|
104
|
+
onContextmenu: c((d) => t.enableFieldMenu && o("header-contextmenu", d, e.key), ["prevent"]),
|
|
105
|
+
onDblclick: c((d) => t.enableFieldMenu && o("header-dblclick", e.key), ["stop"])
|
|
71
106
|
}, [
|
|
72
|
-
r("span",
|
|
73
|
-
r("span",
|
|
74
|
-
|
|
107
|
+
r("span", N, D(e.label), 1),
|
|
108
|
+
r("span", R, [
|
|
109
|
+
t.sortKey === e.key && t.sortOrder === "asc" ? (a(), b(h(H), {
|
|
75
110
|
key: 0,
|
|
76
111
|
size: 12,
|
|
77
112
|
class: "of-sort-icon-active"
|
|
78
|
-
})) :
|
|
113
|
+
})) : t.sortKey === e.key && t.sortOrder === "desc" ? (a(), b(h(m), {
|
|
79
114
|
key: 1,
|
|
80
115
|
size: 12,
|
|
81
116
|
class: "of-sort-icon-active"
|
|
82
|
-
})) : (
|
|
117
|
+
})) : (a(), b(h(m), {
|
|
83
118
|
key: 2,
|
|
84
119
|
size: 12,
|
|
85
120
|
class: "of-sort-icon-idle"
|
|
86
121
|
}))
|
|
87
122
|
]),
|
|
88
|
-
|
|
123
|
+
t.enableResize ? (a(), i("button", {
|
|
89
124
|
key: 0,
|
|
90
125
|
type: "button",
|
|
91
126
|
class: "of-th-resizer",
|
|
92
127
|
"aria-label": "调整列宽",
|
|
93
|
-
onClick: n[1] || (n[1] =
|
|
128
|
+
onClick: n[1] || (n[1] = c(() => {
|
|
94
129
|
}, ["stop"])),
|
|
95
|
-
onMousedown: (
|
|
96
|
-
onDblclick:
|
|
97
|
-
}, null, 40,
|
|
98
|
-
], 46,
|
|
99
|
-
|
|
130
|
+
onMousedown: (d) => $(d, e.key),
|
|
131
|
+
onDblclick: c((d) => o("resize-dblclick", e.key), ["stop"])
|
|
132
|
+
}, null, 40, T)) : k("", !0)
|
|
133
|
+
], 46, E))), 128)),
|
|
134
|
+
t.enableAddField ? (a(), i("button", {
|
|
100
135
|
key: 1,
|
|
101
136
|
type: "button",
|
|
102
137
|
class: "of-th of-th-add",
|
|
103
138
|
tabindex: "0",
|
|
104
139
|
"aria-label": "添加字段",
|
|
105
|
-
|
|
140
|
+
style: f(w.value),
|
|
141
|
+
onClick: n[2] || (n[2] = c((e) => o("add-field"), ["stop"]))
|
|
106
142
|
}, [
|
|
107
|
-
|
|
108
|
-
])) :
|
|
109
|
-
]));
|
|
143
|
+
K(h(F), { size: 14 })
|
|
144
|
+
], 4)) : k("", !0)
|
|
145
|
+
], 4));
|
|
110
146
|
}
|
|
111
147
|
});
|
|
112
148
|
export {
|
|
113
|
-
|
|
149
|
+
V as default
|
|
114
150
|
};
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { Ref } from 'vue';
|
|
2
|
-
import { TableColumn } from '../types';
|
|
2
|
+
import { Density, TableColumn } from '../types';
|
|
3
3
|
export interface UseColumnResizeOptions {
|
|
4
4
|
columns: Ref<TableColumn[]>;
|
|
5
|
+
rows?: Ref<ReadonlyArray<Record<string, unknown>>>;
|
|
6
|
+
density?: Ref<Density>;
|
|
7
|
+
sampleSize?: number;
|
|
5
8
|
/** Minimum column width in px (default 60) */
|
|
6
9
|
minWidth?: number;
|
|
7
10
|
/** Called on every mousemove during resize */
|
|
@@ -1,58 +1,127 @@
|
|
|
1
|
-
import { ref as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { ref as g, onUnmounted as E, readonly as M } from "vue";
|
|
2
|
+
const z = {
|
|
3
|
+
compact: {
|
|
4
|
+
fillMinWidth: 180,
|
|
5
|
+
basePadding: 18,
|
|
6
|
+
labelPadding: 22,
|
|
7
|
+
autoFitPadding: 18,
|
|
8
|
+
clampMax: 360
|
|
9
|
+
},
|
|
10
|
+
standard: {
|
|
11
|
+
fillMinWidth: 220,
|
|
12
|
+
basePadding: 24,
|
|
13
|
+
labelPadding: 26,
|
|
14
|
+
autoFitPadding: 24,
|
|
15
|
+
clampMax: 420
|
|
16
|
+
},
|
|
17
|
+
comfortable: {
|
|
18
|
+
fillMinWidth: 240,
|
|
19
|
+
basePadding: 28,
|
|
20
|
+
labelPadding: 30,
|
|
21
|
+
autoFitPadding: 30,
|
|
22
|
+
clampMax: 480
|
|
23
|
+
}
|
|
24
|
+
}, F = {
|
|
25
|
+
string: 180,
|
|
26
|
+
number: 110,
|
|
27
|
+
date: 140,
|
|
28
|
+
status: 124,
|
|
29
|
+
priority: 124
|
|
30
|
+
};
|
|
31
|
+
function S(t) {
|
|
32
|
+
return t ?? "standard";
|
|
33
|
+
}
|
|
34
|
+
function k(t) {
|
|
35
|
+
if (t == null) return "";
|
|
36
|
+
if (typeof t == "string") return t;
|
|
37
|
+
if (typeof t == "number" || typeof t == "boolean" || typeof t == "bigint")
|
|
38
|
+
return String(t);
|
|
39
|
+
if (t instanceof Date) return t.toISOString();
|
|
40
|
+
if (Array.isArray(t)) return t.map((a) => k(a)).join(", ");
|
|
41
|
+
if (typeof t == "object")
|
|
42
|
+
try {
|
|
43
|
+
return JSON.stringify(t);
|
|
44
|
+
} catch {
|
|
45
|
+
return String(t);
|
|
46
|
+
}
|
|
47
|
+
return String(t);
|
|
48
|
+
}
|
|
49
|
+
function w(t) {
|
|
50
|
+
let a = 0;
|
|
51
|
+
for (const s of t)
|
|
52
|
+
a += s.charCodeAt(0) <= 127 ? 7 : 14;
|
|
53
|
+
return a;
|
|
54
|
+
}
|
|
55
|
+
function D(t, a, s, m) {
|
|
56
|
+
const i = z[s], h = t.type ? F[t.type] : 168, y = w(t.label) + i.labelPadding, r = a.slice(0, Math.max(1, m));
|
|
57
|
+
let c = 0;
|
|
58
|
+
for (const p of r) {
|
|
59
|
+
const f = k(p[t.key]);
|
|
60
|
+
f && (c = Math.max(c, w(f) + i.basePadding));
|
|
61
|
+
}
|
|
62
|
+
const W = t.key === "id" ? 120 : t.key === "title" ? 220 : t.key === "description" ? 260 : 0, b = Math.max(h, y, c, W, i.fillMinWidth);
|
|
63
|
+
return Math.min(Math.max(b, i.fillMinWidth), i.clampMax);
|
|
64
|
+
}
|
|
65
|
+
function T(t) {
|
|
66
|
+
const a = t.minWidth ?? 60, s = g(!1), m = g(null), i = g(/* @__PURE__ */ new Map()), h = g(0), y = g(!1);
|
|
67
|
+
let r = null, c = "", W = "";
|
|
68
|
+
function b(e) {
|
|
69
|
+
var u, d;
|
|
6
70
|
if (i.value.has(e))
|
|
7
71
|
return i.value.get(e);
|
|
8
|
-
const
|
|
9
|
-
return
|
|
72
|
+
const n = t.columns.value.find((x) => x.key === e), l = S((u = t.density) == null ? void 0 : u.value), o = z[l];
|
|
73
|
+
return n ? n.width === "fill" ? n.minWidth ?? o.fillMinWidth : typeof n.width == "number" ? n.width : D(
|
|
74
|
+
n,
|
|
75
|
+
((d = t.rows) == null ? void 0 : d.value) ?? [],
|
|
76
|
+
l,
|
|
77
|
+
t.sampleSize ?? 8
|
|
78
|
+
) : o.fillMinWidth;
|
|
10
79
|
}
|
|
11
|
-
function
|
|
12
|
-
var
|
|
13
|
-
if (!
|
|
14
|
-
const
|
|
15
|
-
|
|
80
|
+
function p(e) {
|
|
81
|
+
var u;
|
|
82
|
+
if (!r) return;
|
|
83
|
+
const n = e.clientX - r.startX, l = Math.max(a, r.initialWidth + n), o = new Map(i.value);
|
|
84
|
+
o.set(r.colKey, l), i.value = o, h.value = e.clientX, (u = t.onResize) == null || u.call(t, r.colKey, l);
|
|
16
85
|
}
|
|
17
|
-
function
|
|
18
|
-
|
|
86
|
+
function f() {
|
|
87
|
+
r && (document.body.style.cursor = c, document.body.style.userSelect = W, document.removeEventListener("mousemove", p), document.removeEventListener("mouseup", f), s.value = !1, m.value = null, y.value = !1, r = null);
|
|
19
88
|
}
|
|
20
|
-
function
|
|
21
|
-
e.preventDefault(), e.stopPropagation(),
|
|
22
|
-
colKey:
|
|
89
|
+
function I(e, n) {
|
|
90
|
+
e.preventDefault(), e.stopPropagation(), r = {
|
|
91
|
+
colKey: n,
|
|
23
92
|
startX: e.clientX,
|
|
24
|
-
initialWidth:
|
|
25
|
-
},
|
|
26
|
-
}
|
|
27
|
-
function
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
function
|
|
31
|
-
var
|
|
32
|
-
if (!
|
|
33
|
-
const
|
|
34
|
-
let
|
|
35
|
-
if (
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
}),
|
|
39
|
-
const
|
|
40
|
-
|
|
93
|
+
initialWidth: b(n)
|
|
94
|
+
}, s.value = !0, m.value = n, h.value = e.clientX, y.value = !0, c = document.body.style.cursor, W = document.body.style.userSelect, document.body.style.cursor = "col-resize", document.body.style.userSelect = "none", document.addEventListener("mousemove", p), document.addEventListener("mouseup", f);
|
|
95
|
+
}
|
|
96
|
+
function X(e) {
|
|
97
|
+
return b(e);
|
|
98
|
+
}
|
|
99
|
+
function R(e, n) {
|
|
100
|
+
var x, C;
|
|
101
|
+
if (!n) return;
|
|
102
|
+
const l = S((x = t.density) == null ? void 0 : x.value), o = z[l].autoFitPadding, u = n.querySelectorAll(`[data-col-key="${e}"]`);
|
|
103
|
+
let d = a;
|
|
104
|
+
if (u.forEach((v) => {
|
|
105
|
+
const P = v.firstElementChild;
|
|
106
|
+
P && (d = Math.max(d, P.scrollWidth + o));
|
|
107
|
+
}), d > a) {
|
|
108
|
+
const v = new Map(i.value);
|
|
109
|
+
v.set(e, d), i.value = v, (C = t.onResize) == null || C.call(t, e, d);
|
|
41
110
|
}
|
|
42
111
|
}
|
|
43
|
-
return
|
|
44
|
-
|
|
112
|
+
return E(() => {
|
|
113
|
+
r && f();
|
|
45
114
|
}), {
|
|
46
|
-
startResize:
|
|
47
|
-
isResizing:
|
|
48
|
-
resizingColumn:
|
|
49
|
-
columnWidthOverrides:
|
|
50
|
-
resolvedWidth:
|
|
51
|
-
autoFitColumn:
|
|
52
|
-
resizeIndicatorX:
|
|
53
|
-
showResizeIndicator:
|
|
115
|
+
startResize: I,
|
|
116
|
+
isResizing: M(s),
|
|
117
|
+
resizingColumn: M(m),
|
|
118
|
+
columnWidthOverrides: M(i),
|
|
119
|
+
resolvedWidth: X,
|
|
120
|
+
autoFitColumn: R,
|
|
121
|
+
resizeIndicatorX: M(h),
|
|
122
|
+
showResizeIndicator: M(y)
|
|
54
123
|
};
|
|
55
124
|
}
|
|
56
125
|
export {
|
|
57
|
-
|
|
126
|
+
T as useColumnResize
|
|
58
127
|
};
|
|
@@ -22,7 +22,7 @@ export declare function useRowDrag<T extends Record<string, unknown>>(options: U
|
|
|
22
22
|
isDragging: Readonly<Ref<boolean, boolean>>;
|
|
23
23
|
draggedRowId: Readonly<Ref<string | null, string | null>>;
|
|
24
24
|
dropTargetId: Readonly<Ref<string | null, string | null>>;
|
|
25
|
-
dropPosition: Readonly<Ref<"
|
|
25
|
+
dropPosition: Readonly<Ref<"after" | "before" | "into-group", "after" | "before" | "into-group">>;
|
|
26
26
|
handleDragStart: (e: DragEvent, item: RowDragItem<T>) => void;
|
|
27
27
|
handleDragOver: (e: DragEvent, targetItem: RowDragItem<T>) => void;
|
|
28
28
|
handleDrop: (e: DragEvent, targetItem: RowDragItem<T>, callbacks: {
|
|
@@ -4,6 +4,7 @@ export interface UseVirtualListOptions<T> {
|
|
|
4
4
|
itemHeight: number | ((index: number) => number);
|
|
5
5
|
overscan?: number;
|
|
6
6
|
containerRef: Ref<HTMLElement | null>;
|
|
7
|
+
invalidateKey?: Ref<unknown>;
|
|
7
8
|
/** Optional callback to measure actual row height after render. When provided, measured heights override itemHeight. */
|
|
8
9
|
measureRow?: boolean;
|
|
9
10
|
}
|
|
@@ -1,135 +1,147 @@
|
|
|
1
|
-
import { ref as
|
|
2
|
-
function
|
|
3
|
-
var
|
|
4
|
-
const { items: n, itemHeight: c, overscan:
|
|
5
|
-
let d = null,
|
|
6
|
-
function
|
|
7
|
-
return a.has(e) ? a.get(e) :
|
|
1
|
+
import { ref as T, computed as p, watch as z, getCurrentScope as W, onScopeDispose as X } from "vue";
|
|
2
|
+
function _(x) {
|
|
3
|
+
var V;
|
|
4
|
+
const { items: n, itemHeight: c, overscan: B = 5, containerRef: A } = x, s = T(0), v = T(0), h = typeof c == "number", m = Math.max(0, B), a = /* @__PURE__ */ new Map(), b = T(0);
|
|
5
|
+
let d = null, f = null, l = null;
|
|
6
|
+
function D(e) {
|
|
7
|
+
return a.has(e) ? a.get(e) : h ? c : c(e);
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
!
|
|
9
|
+
function K() {
|
|
10
|
+
!x.measureRow || typeof ResizeObserver > "u" || (f = new ResizeObserver((e) => {
|
|
11
11
|
let t = !1;
|
|
12
|
-
for (const
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
15
|
-
const u = parseInt(
|
|
16
|
-
a.get(u) !==
|
|
12
|
+
for (const i of e) {
|
|
13
|
+
const r = i.target.dataset.virtualIndex;
|
|
14
|
+
if (r == null) continue;
|
|
15
|
+
const u = parseInt(r, 10), g = i.contentRect.height;
|
|
16
|
+
a.get(u) !== g && (a.set(u, g), t = !0);
|
|
17
17
|
}
|
|
18
|
-
t &&
|
|
18
|
+
t && b.value++;
|
|
19
19
|
}));
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
K();
|
|
22
|
+
function C() {
|
|
23
|
+
a.size !== 0 && (a.clear(), b.value++, l && M(l));
|
|
24
|
+
}
|
|
22
25
|
function P(e, t) {
|
|
23
|
-
!e || !
|
|
26
|
+
!e || !f || (e.dataset.virtualIndex = String(t), f.observe(e));
|
|
24
27
|
}
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
28
|
+
const w = p(() => {
|
|
29
|
+
if (b.value, h && a.size === 0) return [];
|
|
27
30
|
const e = new Array(n.value.length + 1).fill(0);
|
|
28
31
|
for (let t = 0; t < n.value.length; t += 1)
|
|
29
|
-
e[t + 1] = e[t] + Math.max(0,
|
|
32
|
+
e[t + 1] = e[t] + Math.max(0, D(t));
|
|
30
33
|
return e;
|
|
31
|
-
}),
|
|
32
|
-
function
|
|
34
|
+
}), I = p(() => h && a.size === 0 ? n.value.length * c : w.value[n.value.length] ?? 0);
|
|
35
|
+
function H(e) {
|
|
33
36
|
const t = Math.max(0, Math.min(e, n.value.length));
|
|
34
|
-
return
|
|
37
|
+
return h && a.size === 0 ? t * c : w.value[t] ?? 0;
|
|
35
38
|
}
|
|
36
|
-
function
|
|
39
|
+
function R(e) {
|
|
37
40
|
if (n.value.length === 0) return 0;
|
|
38
|
-
if (
|
|
39
|
-
const
|
|
41
|
+
if (h && a.size === 0) {
|
|
42
|
+
const r = c;
|
|
40
43
|
return Math.max(
|
|
41
44
|
0,
|
|
42
|
-
Math.min(n.value.length - 1, Math.floor(Math.max(0, e) /
|
|
45
|
+
Math.min(n.value.length - 1, Math.floor(Math.max(0, e) / r))
|
|
43
46
|
);
|
|
44
47
|
}
|
|
45
|
-
const t =
|
|
46
|
-
let
|
|
47
|
-
for (;
|
|
48
|
-
const
|
|
49
|
-
t[
|
|
48
|
+
const t = w.value;
|
|
49
|
+
let i = 0, o = n.value.length;
|
|
50
|
+
for (; i < o; ) {
|
|
51
|
+
const r = Math.floor((i + o) / 2);
|
|
52
|
+
t[r + 1] <= e ? i = r + 1 : o = r;
|
|
50
53
|
}
|
|
51
|
-
return Math.max(0, Math.min(
|
|
54
|
+
return Math.max(0, Math.min(i, n.value.length - 1));
|
|
52
55
|
}
|
|
53
|
-
const
|
|
56
|
+
const y = p(() => {
|
|
54
57
|
const e = n.value.length;
|
|
55
58
|
if (e === 0)
|
|
56
59
|
return { start: 0, end: 0 };
|
|
57
|
-
if (
|
|
58
|
-
return { start: 0, end: Math.min(e,
|
|
59
|
-
if (
|
|
60
|
-
const u = c,
|
|
61
|
-
return { start:
|
|
60
|
+
if (v.value <= 0)
|
|
61
|
+
return { start: 0, end: Math.min(e, m * 2 + 1) };
|
|
62
|
+
if (h && a.size === 0) {
|
|
63
|
+
const u = c, g = Math.floor(s.value / u), J = Math.ceil(v.value / u), N = Math.max(0, g - m), Q = Math.min(e, g + J + m);
|
|
64
|
+
return { start: N, end: Q };
|
|
62
65
|
}
|
|
63
|
-
const t = Math.max(0, s.value),
|
|
66
|
+
const t = Math.max(0, s.value), i = t + v.value, o = R(t), r = Math.min(e - 1, R(i));
|
|
64
67
|
return {
|
|
65
|
-
start: Math.max(0, o -
|
|
66
|
-
end: Math.min(e,
|
|
68
|
+
start: Math.max(0, o - m),
|
|
69
|
+
end: Math.min(e, r + m + 1)
|
|
67
70
|
};
|
|
68
|
-
}), U = p(() =>
|
|
69
|
-
const { start: e, end: t } =
|
|
70
|
-
return n.value.slice(e, t).map((
|
|
71
|
-
data:
|
|
71
|
+
}), U = p(() => H(y.value.start)), Y = p(() => {
|
|
72
|
+
const { start: e, end: t } = y.value;
|
|
73
|
+
return n.value.slice(e, t).map((i, o) => ({
|
|
74
|
+
data: i,
|
|
72
75
|
index: e + o
|
|
73
76
|
}));
|
|
74
77
|
});
|
|
75
|
-
function
|
|
78
|
+
function M(e) {
|
|
76
79
|
if (!e) {
|
|
77
|
-
s.value = 0,
|
|
80
|
+
s.value = 0, v.value = 0;
|
|
78
81
|
return;
|
|
79
82
|
}
|
|
80
|
-
s.value = e.scrollTop,
|
|
81
|
-
}
|
|
82
|
-
function z() {
|
|
83
|
-
r && (s.value = r.scrollTop);
|
|
83
|
+
s.value = e.scrollTop, v.value = e.clientHeight;
|
|
84
84
|
}
|
|
85
85
|
function S() {
|
|
86
|
+
l && (s.value = l.scrollTop);
|
|
87
|
+
}
|
|
88
|
+
function O() {
|
|
86
89
|
d == null || d.disconnect(), d = null;
|
|
87
90
|
}
|
|
88
|
-
function
|
|
89
|
-
e && e.removeEventListener("scroll",
|
|
91
|
+
function E(e) {
|
|
92
|
+
e && e.removeEventListener("scroll", S);
|
|
90
93
|
}
|
|
91
94
|
function j(e) {
|
|
92
95
|
if (!e) {
|
|
93
|
-
|
|
96
|
+
l = null, M(null);
|
|
94
97
|
return;
|
|
95
98
|
}
|
|
96
|
-
|
|
97
|
-
|
|
99
|
+
l = e, e.addEventListener("scroll", S, { passive: !0 }), M(e), typeof ResizeObserver < "u" && (d = new ResizeObserver(() => {
|
|
100
|
+
M(e);
|
|
98
101
|
}), d.observe(e));
|
|
99
102
|
}
|
|
100
|
-
|
|
101
|
-
|
|
103
|
+
z(
|
|
104
|
+
A,
|
|
102
105
|
(e, t) => {
|
|
103
|
-
|
|
106
|
+
E(t), O(), j(e);
|
|
107
|
+
},
|
|
108
|
+
{ immediate: !0 }
|
|
109
|
+
), z(
|
|
110
|
+
() => {
|
|
111
|
+
var e;
|
|
112
|
+
return (e = x.invalidateKey) == null ? void 0 : e.value;
|
|
113
|
+
},
|
|
114
|
+
() => {
|
|
115
|
+
C();
|
|
104
116
|
},
|
|
105
117
|
{ immediate: !0 }
|
|
106
118
|
);
|
|
107
|
-
let
|
|
108
|
-
|
|
119
|
+
let F = n.value.length, L = n.value.length > 0 ? (V = n.value[0]) == null ? void 0 : V.id : void 0;
|
|
120
|
+
z(n, (e) => {
|
|
109
121
|
var u;
|
|
110
|
-
const t = e.length,
|
|
111
|
-
if (
|
|
122
|
+
const t = e.length, i = t > 0 ? (u = e[0]) == null ? void 0 : u.id : void 0, o = t === F && i === L;
|
|
123
|
+
if (F = t, L = i, o)
|
|
112
124
|
return;
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
s.value >
|
|
125
|
+
C();
|
|
126
|
+
const r = Math.max(0, I.value - v.value);
|
|
127
|
+
s.value > r && (s.value = r, l && (l.scrollTop = r));
|
|
116
128
|
});
|
|
117
129
|
function k(e) {
|
|
118
|
-
if (!
|
|
119
|
-
const t = Math.max(0, Math.min(e, n.value.length - 1)),
|
|
120
|
-
|
|
130
|
+
if (!l || n.value.length === 0) return;
|
|
131
|
+
const t = Math.max(0, Math.min(e, n.value.length - 1)), i = H(t);
|
|
132
|
+
l.scrollTop = i, s.value = i;
|
|
121
133
|
}
|
|
122
134
|
function q() {
|
|
123
|
-
if (!
|
|
124
|
-
const e = Math.max(0,
|
|
125
|
-
|
|
135
|
+
if (!l) return;
|
|
136
|
+
const e = Math.max(0, I.value - l.clientHeight);
|
|
137
|
+
l.scrollTop = e, s.value = e;
|
|
126
138
|
}
|
|
127
139
|
const G = () => {
|
|
128
|
-
|
|
140
|
+
E(l), O(), f == null || f.disconnect(), f = null, l = null;
|
|
129
141
|
};
|
|
130
|
-
return
|
|
142
|
+
return W() && X(G), {
|
|
131
143
|
visibleItems: Y,
|
|
132
|
-
totalHeight:
|
|
144
|
+
totalHeight: I,
|
|
133
145
|
offsetY: U,
|
|
134
146
|
scrollToIndex: k,
|
|
135
147
|
scrollToBottom: q,
|
|
@@ -137,5 +149,5 @@ function Z(I) {
|
|
|
137
149
|
};
|
|
138
150
|
}
|
|
139
151
|
export {
|
|
140
|
-
|
|
152
|
+
_ as useVirtualList
|
|
141
153
|
};
|