@oneflowui/ui 0.5.7 → 0.5.9

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.
Files changed (34) hide show
  1. package/README.md +11 -0
  2. package/dist/components/ContextMenu/index.vue.js +2 -2
  3. package/dist/components/Dashboard/index.vue.d.ts +1 -1
  4. package/dist/components/Dashboard/index.vue.js +3 -3
  5. package/dist/components/database/DatabaseView.vue.d.ts +6 -1
  6. package/dist/components/database/DatabaseView.vue.js +2 -2
  7. package/dist/components/database/DatabaseView.vue2.js +438 -293
  8. package/dist/components/overlay/Drawer.vue.d.ts +1 -1
  9. package/dist/components/overlay/Modal.vue.d.ts +1 -1
  10. package/dist/components/table/ColumnHeaderMenu.vue.d.ts +2 -2
  11. package/dist/components/table/DataTable.vue.d.ts +3 -1
  12. package/dist/components/table/DataTable.vue.js +2 -2
  13. package/dist/components/table/DataTable.vue2.js +598 -526
  14. package/dist/components/table/DetailSheet.vue.d.ts +2 -0
  15. package/dist/components/table/DetailSheet.vue.js +2 -2
  16. package/dist/components/table/DetailSheet.vue2.js +155 -76
  17. package/dist/components/table/TableDataRow.vue.d.ts +3 -1
  18. package/dist/components/table/TableDataRow.vue.js +3 -3
  19. package/dist/components/table/TableDataRow.vue2.js +95 -68
  20. package/dist/components/table/TableHeaderRow.vue.d.ts +3 -1
  21. package/dist/components/table/TableHeaderRow.vue.js +3 -3
  22. package/dist/components/table/TableHeaderRow.vue2.js +96 -60
  23. package/dist/composables/useColumnResize.d.ts +4 -1
  24. package/dist/composables/useColumnResize.js +114 -45
  25. package/dist/composables/useRowDrag.d.ts +1 -1
  26. package/dist/composables/useVirtualList.d.ts +1 -0
  27. package/dist/composables/useVirtualList.js +89 -77
  28. package/dist/plugin.js +240 -171
  29. package/dist/style.css +1 -1
  30. package/dist/types/index.d.ts +2 -1
  31. package/dist/utils/icon.js +25 -68
  32. package/dist/utils/iconRegistry.d.ts +7 -0
  33. package/dist/utils/iconRegistry.js +60 -0
  34. package/package.json +1 -1
@@ -1,17 +1,9 @@
1
- import { defineComponent as z, openBlock as o, createElementBlock as i, createElementVNode as r, createCommentVNode as f, Fragment as w, renderList as C, withModifiers as d, normalizeStyle as v, normalizeClass as B, toDisplayString as g, createBlock as u, unref as c, createVNode as D } from "vue";
2
- import { ChevronUp as K, ChevronDown as k, Plus as S } from "lucide-vue-next";
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
- }, p = ["checked", "indeterminate"], O = ["aria-sort", "onClick", "onKeydown", "onContextmenu", "onDblclick"], R = { class: "of-th-label" }, E = { class: "of-th-sort-icon" }, N = ["onMousedown", "onDblclick"], H = /* @__PURE__ */ z({
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(e, { emit: y }) {
29
- const a = y;
30
- function b(t) {
31
- if (t.width === "fill") {
32
- const n = `${t.minWidth ?? 220}px`;
33
- return { flex: `1 1 ${n}`, minWidth: n };
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
- return { width: `${t.width}px`, flexShrink: "0", flexGrow: "0" };
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 h(t) {
38
- a("sort", t);
62
+ function p(l) {
63
+ o("sort", l);
39
64
  }
40
- function m(t, n) {
41
- t.target === t.currentTarget && (t.key !== "Enter" && t.key !== " " || (t.preventDefault(), a("sort", n)));
65
+ function S(l, n) {
66
+ l.target === l.currentTarget && (l.key !== "Enter" && l.key !== " " || (l.preventDefault(), o("sort", n)));
42
67
  }
43
- function x(t, n) {
44
- t.stopPropagation(), a("resize-start", t, n);
68
+ function $(l, n) {
69
+ l.stopPropagation(), o("resize-start", l, n);
45
70
  }
46
- return (t, n) => (o(), i("div", $, [
47
- e.selectable ? (o(), i("div", F, [
48
- r("label", M, [
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: e.allSelected,
54
- indeterminate: e.indeterminate,
55
- onChange: n[0] || (n[0] = (l) => a("select-all"))
56
- }, null, 40, p),
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
- ])) : f("", !0),
60
- (o(!0), i(w, null, C(e.columns, (l) => (o(), i("div", {
61
- key: l.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: B(["of-th", { "of-th--sortable": !0, "of-th--active": e.sortKey === l.key }]),
65
- style: v(b(l)),
66
- "aria-sort": e.sortKey === l.key ? e.sortOrder === "asc" ? "ascending" : "descending" : "none",
67
- onClick: (s) => h(l.key),
68
- onKeydown: (s) => m(s, l.key),
69
- onContextmenu: d((s) => e.enableFieldMenu && a("header-contextmenu", s, l.key), ["prevent"]),
70
- onDblclick: d((s) => e.enableFieldMenu && a("header-dblclick", l.key), ["stop"])
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", R, g(l.label), 1),
73
- r("span", E, [
74
- e.sortKey === l.key && e.sortOrder === "asc" ? (o(), u(c(K), {
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
- })) : e.sortKey === l.key && e.sortOrder === "desc" ? (o(), u(c(k), {
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
- })) : (o(), u(c(k), {
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
- e.enableResize ? (o(), i("button", {
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] = d(() => {
128
+ onClick: n[1] || (n[1] = c(() => {
94
129
  }, ["stop"])),
95
- onMousedown: (s) => x(s, l.key),
96
- onDblclick: d((s) => a("resize-dblclick", l.key), ["stop"])
97
- }, null, 40, N)) : f("", !0)
98
- ], 46, O))), 128)),
99
- e.enableAddField ? (o(), i("button", {
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
- onClick: n[2] || (n[2] = d((l) => a("add-field"), ["stop"]))
140
+ style: f(w.value),
141
+ onClick: n[2] || (n[2] = c((e) => o("add-field"), ["stop"]))
106
142
  }, [
107
- D(c(S), { size: 14 })
108
- ])) : f("", !0)
109
- ]));
143
+ K(h(F), { size: 14 })
144
+ ], 4)) : k("", !0)
145
+ ], 4));
110
146
  }
111
147
  });
112
148
  export {
113
- H as default
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 o, onUnmounted as b, readonly as a } from "vue";
2
- function E(u) {
3
- const d = u.minWidth ?? 60, m = o(!1), v = o(null), i = o(/* @__PURE__ */ new Map()), f = o(0), h = o(!1);
4
- let n = null, y = "", W = "";
5
- function X(e) {
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 t = u.columns.value.find((s) => s.key === e);
9
- return !t || t.width === "fill" ? 200 : t.width ?? 200;
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 w(e) {
12
- var r;
13
- if (!n) return;
14
- const t = e.clientX - n.startX, s = Math.max(d, n.initialWidth + t), l = new Map(i.value);
15
- l.set(n.colKey, s), i.value = l, f.value = e.clientX, (r = u.onResize) == null || r.call(u, n.colKey, s);
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 z() {
18
- n && (document.body.style.cursor = y, document.body.style.userSelect = W, document.removeEventListener("mousemove", w), document.removeEventListener("mouseup", z), m.value = !1, v.value = null, h.value = !1, n = null);
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 R(e, t) {
21
- e.preventDefault(), e.stopPropagation(), n = {
22
- colKey: t,
89
+ function I(e, n) {
90
+ e.preventDefault(), e.stopPropagation(), r = {
91
+ colKey: n,
23
92
  startX: e.clientX,
24
- initialWidth: X(t)
25
- }, m.value = !0, v.value = t, f.value = e.clientX, h.value = !0, y = document.body.style.cursor, W = document.body.style.userSelect, document.body.style.cursor = "col-resize", document.body.style.userSelect = "none", document.addEventListener("mousemove", w), document.addEventListener("mouseup", z);
26
- }
27
- function g(e) {
28
- return X(e);
29
- }
30
- function C(e, t) {
31
- var r;
32
- if (!t) return;
33
- const s = t.querySelectorAll(`[data-col-key="${e}"]`);
34
- let l = d;
35
- if (s.forEach((c) => {
36
- const M = c.firstElementChild;
37
- M && (l = Math.max(l, M.scrollWidth + 24));
38
- }), l > d) {
39
- const c = new Map(i.value);
40
- c.set(e, l), i.value = c, (r = u.onResize) == null || r.call(u, e, l);
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 b(() => {
44
- n && z();
112
+ return E(() => {
113
+ r && f();
45
114
  }), {
46
- startResize: R,
47
- isResizing: a(m),
48
- resizingColumn: a(v),
49
- columnWidthOverrides: a(i),
50
- resolvedWidth: g,
51
- autoFitColumn: C,
52
- resizeIndicatorX: a(f),
53
- showResizeIndicator: a(h)
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
- E as useColumnResize
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<"before" | "after" | "into-group", "before" | "after" | "into-group">>;
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 w, computed as p, watch as L, getCurrentScope as Q, onScopeDispose as W } from "vue";
2
- function Z(I) {
3
- var F;
4
- const { items: n, itemHeight: c, overscan: V = 5, containerRef: B } = I, s = w(0), f = w(0), v = typeof c == "number", g = Math.max(0, V), a = /* @__PURE__ */ new Map(), T = w(0);
5
- let d = null, h = null, r = null;
6
- function A(e) {
7
- return a.has(e) ? a.get(e) : v ? c : c(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 D() {
10
- !I.measureRow || typeof ResizeObserver > "u" || (h = new ResizeObserver((e) => {
9
+ function K() {
10
+ !x.measureRow || typeof ResizeObserver > "u" || (f = new ResizeObserver((e) => {
11
11
  let t = !1;
12
- for (const l of e) {
13
- const i = l.target.dataset.virtualIndex;
14
- if (i == null) continue;
15
- const u = parseInt(i, 10), m = l.contentRect.height;
16
- a.get(u) !== m && (a.set(u, m), t = !0);
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 && T.value++;
18
+ t && b.value++;
19
19
  }));
20
20
  }
21
- D();
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 || !h || (e.dataset.virtualIndex = String(t), h.observe(e));
26
+ !e || !f || (e.dataset.virtualIndex = String(t), f.observe(e));
24
27
  }
25
- const M = p(() => {
26
- if (T.value, v && a.size === 0) return [];
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, A(t));
32
+ e[t + 1] = e[t] + Math.max(0, D(t));
30
33
  return e;
31
- }), x = p(() => v && a.size === 0 ? n.value.length * c : M.value[n.value.length] ?? 0);
32
- function C(e) {
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 v && a.size === 0 ? t * c : M.value[t] ?? 0;
37
+ return h && a.size === 0 ? t * c : w.value[t] ?? 0;
35
38
  }
36
- function H(e) {
39
+ function R(e) {
37
40
  if (n.value.length === 0) return 0;
38
- if (v && a.size === 0) {
39
- const i = c;
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) / i))
45
+ Math.min(n.value.length - 1, Math.floor(Math.max(0, e) / r))
43
46
  );
44
47
  }
45
- const t = M.value;
46
- let l = 0, o = n.value.length;
47
- for (; l < o; ) {
48
- const i = Math.floor((l + o) / 2);
49
- t[i + 1] <= e ? l = i + 1 : o = i;
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(l, n.value.length - 1));
54
+ return Math.max(0, Math.min(i, n.value.length - 1));
52
55
  }
53
- const R = p(() => {
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 (f.value <= 0)
58
- return { start: 0, end: Math.min(e, g * 2 + 1) };
59
- if (v && a.size === 0) {
60
- const u = c, m = Math.floor(s.value / u), J = Math.ceil(f.value / u), K = Math.max(0, m - g), N = Math.min(e, m + J + g);
61
- return { start: K, end: N };
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), l = t + f.value, o = H(t), i = Math.min(e - 1, H(l));
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 - g),
66
- end: Math.min(e, i + g + 1)
68
+ start: Math.max(0, o - m),
69
+ end: Math.min(e, r + m + 1)
67
70
  };
68
- }), U = p(() => C(R.value.start)), Y = p(() => {
69
- const { start: e, end: t } = R.value;
70
- return n.value.slice(e, t).map((l, o) => ({
71
- data: l,
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 b(e) {
78
+ function M(e) {
76
79
  if (!e) {
77
- s.value = 0, f.value = 0;
80
+ s.value = 0, v.value = 0;
78
81
  return;
79
82
  }
80
- s.value = e.scrollTop, f.value = e.clientHeight;
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 y(e) {
89
- e && e.removeEventListener("scroll", z);
91
+ function E(e) {
92
+ e && e.removeEventListener("scroll", S);
90
93
  }
91
94
  function j(e) {
92
95
  if (!e) {
93
- r = null, b(null);
96
+ l = null, M(null);
94
97
  return;
95
98
  }
96
- r = e, e.addEventListener("scroll", z, { passive: !0 }), b(e), typeof ResizeObserver < "u" && (d = new ResizeObserver(() => {
97
- b(e);
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
- L(
101
- B,
103
+ z(
104
+ A,
102
105
  (e, t) => {
103
- y(t), S(), j(e);
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 O = n.value.length, E = n.value.length > 0 ? (F = n.value[0]) == null ? void 0 : F.id : void 0;
108
- L(n, (e) => {
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, l = t > 0 ? (u = e[0]) == null ? void 0 : u.id : void 0, o = t === O && l === E;
111
- if (O = t, E = l, o)
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
- a.clear();
114
- const i = Math.max(0, x.value - f.value);
115
- s.value > i && (s.value = i, r && (r.scrollTop = i));
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 (!r || n.value.length === 0) return;
119
- const t = Math.max(0, Math.min(e, n.value.length - 1)), l = C(t);
120
- r.scrollTop = l, s.value = l;
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 (!r) return;
124
- const e = Math.max(0, x.value - r.clientHeight);
125
- r.scrollTop = e, s.value = e;
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
- y(r), S(), h == null || h.disconnect(), h = null, r = null;
140
+ E(l), O(), f == null || f.disconnect(), f = null, l = null;
129
141
  };
130
- return Q() && W(G), {
142
+ return W() && X(G), {
131
143
  visibleItems: Y,
132
- totalHeight: x,
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
- Z as useVirtualList
152
+ _ as useVirtualList
141
153
  };