@ithinkdt/ui 4.0.17 → 4.0.19

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.
@@ -0,0 +1,261 @@
1
+ import e, { c as t, cB as n, cE as r, cM as i, useClsPrefix as a } from "./use-style.js";
2
+ import { i as o } from "./directives-Chz4DK1u.js";
3
+ import { C as s } from "./components-DLa9-kdK.js";
4
+ import { t as c } from "./use-table-range-select-Da6t9Vlf.js";
5
+ import { computed as l, createVNode as u, defineComponent as d, inject as f, isVNode as p, ref as m, shallowRef as h, toValue as g, useTemplateRef as _, watch as v, withDirectives as y } from "vue";
6
+ import { toReactive as b, until as x } from "@vueuse/core";
7
+ import { NButton as S, NDataTable as C, NFlex as w, NIcon as T, NTooltip as E, dataTableProps as D } from "ithinkdt-ui";
8
+ import { PAGE_INJECTION as O } from "@ithinkdt/page";
9
+ //#region src/components/DataTable.jsx
10
+ function k(e) {
11
+ return typeof e == "function" || Object.prototype.toString.call(e) === "[object Object]" && !p(e);
12
+ }
13
+ function A(e, t) {
14
+ return (e ?? []).map((e) => {
15
+ let n = {
16
+ csvTitle: e.exportTitle,
17
+ ...e,
18
+ title: () => {
19
+ let t = g(e.title), n = t && y(u("div", null, [t]), [[
20
+ o,
21
+ () => g(e.title),
22
+ void 0,
23
+ { auto: !0 }
24
+ ]]);
25
+ return e.tooltip ? u(w, {
26
+ size: 3,
27
+ wrap: !1,
28
+ inline: !0,
29
+ style: "max-width: 100%"
30
+ }, { default: () => [n, u(E, null, {
31
+ default: g(e.tooltip),
32
+ trigger: () => u(S, {
33
+ text: !0,
34
+ style: "font-size: 1.25em; opacity: 0.8"
35
+ }, { default: () => [u(T, null, { default: () => [u(s, null, null)] })] })
36
+ })] }) : n;
37
+ }
38
+ };
39
+ if (e.children?.length) n.children = A(e.children, t);
40
+ else {
41
+ e.hidden !== !0 && (n.width ??= 100, t.value += Number(n.width));
42
+ let r = e.render ?? ((e) => e);
43
+ e.ellipsis !== !1 && (n.ellipsis = !1, n.render = (...t) => {
44
+ let n = r(...t);
45
+ return n && (p(n) || ((function() {
46
+ return n;
47
+ })(), n = u("span", null, [n])), y(n, [[
48
+ o,
49
+ () => e.ellipsisTooltip ? e.ellipsisTooltip(...t) : n,
50
+ void 0,
51
+ {
52
+ auto: !0,
53
+ expandable: e.ellipsisExpandable,
54
+ [`ell${e.ellipsis}`]: !0
55
+ }
56
+ ]]));
57
+ }, e.ellipsisTooltip === !0 && (n.ellipsisTooltip = r)), Object.assign(n, {
58
+ resizable: e.resizable !== !1,
59
+ sorter: e.sortable,
60
+ type: ["selection", "expand"].includes(e.type) ? e.type : void 0,
61
+ disabled: e.selectable ? (t) => e.selectable(t) === !1 : void 0
62
+ });
63
+ }
64
+ return n.key === "$actions" && (n.cellProps ??= () => ({ style: { padding: "0 2px" } })), n;
65
+ }).filter((e) => e?.hidden !== !0);
66
+ }
67
+ var j = /* @__PURE__ */ d({
68
+ name: "DataTable",
69
+ props: {
70
+ data: {
71
+ type: Array,
72
+ default: () => []
73
+ },
74
+ columns: {
75
+ type: Array,
76
+ default: () => []
77
+ },
78
+ keyField: { type: String },
79
+ sorter: {
80
+ type: Object,
81
+ default: () => ({})
82
+ },
83
+ selectedKeys: { type: Array },
84
+ rangeSelect: {
85
+ type: Boolean,
86
+ default: void 0
87
+ },
88
+ highlight: {
89
+ type: [
90
+ Boolean,
91
+ String,
92
+ Number,
93
+ Object
94
+ ],
95
+ default: !0
96
+ },
97
+ highlightColor: String,
98
+ appear: {
99
+ type: String,
100
+ default: "normal"
101
+ },
102
+ rowClassName: D.rowClassName,
103
+ rowProps: D.rowProps,
104
+ maxHeight: [String, Number]
105
+ },
106
+ emits: [
107
+ "sort",
108
+ "select",
109
+ "custom",
110
+ "highlight"
111
+ ],
112
+ setup(t, { slots: n, emit: r, expose: i }) {
113
+ let { keyField: o } = f(O), s = a(), d = `${s.value}-datatable`;
114
+ e("-datatable", M, s);
115
+ let p = _("table-ref"), g = ({ sortField: e, sortOrder: t } = {}, n) => {
116
+ e == n?.sortField && t == n?.sortOrder || p.value?.sort(e, t ? t + "end" : !1);
117
+ };
118
+ v(() => ({ ...t.sorter }), g, { deep: !0 });
119
+ let y = l(() => {
120
+ let e = t.keyField || o || "key";
121
+ return (t) => t[e];
122
+ }), S = h({
123
+ cache: [],
124
+ scrollToView(...e) {
125
+ S.value.cache.push(e);
126
+ }
127
+ });
128
+ x(p).changed().then(() => {
129
+ g(t.sorter);
130
+ let e = S.value.cache;
131
+ S.value = p.value, S.value.scrollToView = (e) => {
132
+ let n = t.data.findIndex((t) => y.value(t) === e);
133
+ if (n === -1) return;
134
+ let r = p.value.$el.querySelector(`.${d}__row-marker:nth-child(${n + 1})`);
135
+ p.value.scrollTo({
136
+ top: r.offsetTop,
137
+ behavior: "smooth"
138
+ });
139
+ };
140
+ for (let t of e) S.value.scrollToView(...t);
141
+ }), i(b(S));
142
+ let w = m(0), T = h([]);
143
+ v(() => t.columns, () => {
144
+ w.value = 0, T.value = A(t.columns, w);
145
+ }, {
146
+ immediate: !0,
147
+ deep: 2
148
+ });
149
+ let E = m();
150
+ v(() => t.highlight, (e) => {
151
+ E.value = typeof e == "boolean" ? null : e ?? null;
152
+ }, { immediate: !0 });
153
+ let D = l(() => (e, n) => [
154
+ t.rowClassName?.(e, n) || "",
155
+ `${d}__row-marker`,
156
+ E.value != null && y.value(e) === E.value ? `${d}__row-highlight` : ""
157
+ ].join(" ")), j = l(() => (e, n) => {
158
+ let i = t.rowProps?.(e, n);
159
+ return {
160
+ ...i,
161
+ "data-row-key": y.value(e),
162
+ onClick: (n) => {
163
+ let a = y.value(e);
164
+ t.highlight === !0 && (E.value = a), r("highlight", a), i?.onClick?.(n);
165
+ }
166
+ };
167
+ }), N = (e) => {
168
+ if (t.sorter) {
169
+ let { sortField: n, sortOrder: r } = t.sorter;
170
+ if (e?.columnKey == n && (e?.order ? e.order === r + "end" : !r)) return;
171
+ }
172
+ r("sort", {
173
+ sortField: e?.order ? e?.columnKey : void 0,
174
+ sortOrder: e?.order ? e.order.replace("end", "") : void 0
175
+ });
176
+ }, P = (e) => {
177
+ r("select", e);
178
+ }, F = (e, t, n) => {
179
+ r("custom", {
180
+ key: n.key,
181
+ width: e
182
+ });
183
+ }, { range: I, pause: L, resume: R } = c(p, {
184
+ immediate: t.rangeSelect,
185
+ clsPrefix: l(() => `${s.value}-`)
186
+ });
187
+ return v(() => t.rangeSelect, (e) => {
188
+ e ? R() : L();
189
+ }), () => u(C, {
190
+ ref: "table-ref",
191
+ class: [
192
+ d,
193
+ t.appear === "sticky" ? `${d}--sticky` : "",
194
+ I.value?.ing ? `${d}--cell-selecting` : ""
195
+ ],
196
+ data: t.data,
197
+ columns: T.value,
198
+ rowKey: y.value,
199
+ tableLayout: "fixed",
200
+ scrollX: w.value,
201
+ rowClassName: D.value,
202
+ rowProps: j.value,
203
+ checkedRowKeys: t.selectedKeys,
204
+ style: { "--n-tr-highlight-color": t.highlightColor },
205
+ maxHeight: t.maxHeight ?? (t.appear === "sticky" ? "auto" : void 0),
206
+ onUpdateSorter: N,
207
+ onUpdateCheckedRowKeys: P,
208
+ onUnstableColumnResize: F
209
+ }, k(n) ? n : { default: () => [n] });
210
+ }
211
+ }), M = /* @__PURE__ */ n("datatable", [
212
+ r("row-highlight", [t("& > td", { backgroundColor: "var(--n-tr-highlight-color, var(--n-merged-border-color)) !important" })]),
213
+ i("cell-selecting", { userSelect: "none" }),
214
+ n("cell-selected", { position: "relative" }, [
215
+ t("&:not(.n-data-table-td--fixed-right)::before, &:is(.n-data-table-td--fixed-right)::after", {
216
+ content: "' '",
217
+ position: "absolute",
218
+ zIndex: 2,
219
+ top: 0,
220
+ left: 0,
221
+ width: "100%",
222
+ height: "100%",
223
+ background: "color-mix(in srgb, var(--color-primary) 30%, transparent)",
224
+ borderStyle: "solid",
225
+ borderWidth: "1px",
226
+ borderTopColor: "var(--n-cell-selected-border-top-color, transparent)",
227
+ borderBottomColor: "var(--n-cell-selected-border-bottom-color, transparent)",
228
+ borderLeftColor: "var(--n-cell-selected-border-left-color, transparent)",
229
+ borderRightColor: "var(--n-cell-selected-border-right-color, transparent)"
230
+ }),
231
+ i("first-row", { "--n-cell-selected-border-top-color": "var(--color-primary)" }),
232
+ i("first-col", { "--n-cell-selected-border-left-color": "var(--color-primary)" }),
233
+ i("last-row", { "--n-cell-selected-border-bottom-color": "var(--color-primary)" }),
234
+ i("last-col", { "--n-cell-selected-border-right-color": "var(--color-primary)" })
235
+ ]),
236
+ i("sticky", [
237
+ t(".n-data-table-base-table-header", {
238
+ position: "sticky",
239
+ top: "-1px",
240
+ zIndex: 10,
241
+ overflowY: "hidden"
242
+ }),
243
+ t(".n-data-table-base-table-body", { overflow: "initial" }, [t("& > .n-scrollbar-container", {
244
+ overflow: "initial",
245
+ overflowX: "scroll"
246
+ }), t("& > .n-scrollbar-rail--horizontal", {
247
+ position: "sticky",
248
+ bottom: "0"
249
+ })]),
250
+ t(".n-data-table-base-table:has(.n-data-table-empty) .n-data-table-base-table-header", {
251
+ scrollbarWidth: "thin",
252
+ overflowX: "auto"
253
+ }),
254
+ t(".n-data-table-td > *", {
255
+ verticalAlign: "middle",
256
+ contentVisibility: "auto"
257
+ })
258
+ ])
259
+ ]);
260
+ //#endregion
261
+ export { j as DataTable };
@@ -2162,6 +2162,6 @@ var Mt = /* @__PURE__ */ d({
2162
2162
  });
2163
2163
  };
2164
2164
  }
2165
- }), It = u(() => import("./DataTable-BvLINmq3.js").then((e) => e.DataTable));
2165
+ }), It = u(() => import("./DataTable-2vtI02wP.js").then((e) => e.DataTable));
2166
2166
  //#endregion
2167
2167
  export { Re as C, ot as S, gt as _, jt as a, pt as b, At as c, Tt as d, Ct as f, _t as g, yt as h, Mt as i, Ot as l, bt as m, Ft as n, Nt as o, X as p, Pt as r, $ as s, It as t, Et as u, Y as v, Le as w, ct as x, J as y };
@@ -227,6 +227,7 @@ export interface DataTableProps<Data extends {}, KeyField extends keyof Data>
227
227
  data?: ArrayLike<Data> | undefined
228
228
  keyField?: KeyField | undefined
229
229
  selectedKeys?: ArrayLike<Data[KeyField]> | undefined
230
+ rangeSelect?: boolean | undefined
230
231
  highlight?: boolean | Data[KeyField] | undefined
231
232
  highlightColor?: string | undefined
232
233
  appear?: 'normal' | 'sticky' | undefined
package/esm/components.js CHANGED
@@ -1,2 +1,2 @@
1
- import { S as e, _ as t, a as n, b as r, c as i, d as a, f as o, g as s, h as c, i as l, l as u, m as d, n as f, o as p, p as m, r as h, s as g, t as _, u as v, v as y, w as b, x, y as S } from "./components-DfV9ybsT.js";
1
+ import { S as e, _ as t, a as n, b as r, c as i, d as a, f as o, g as s, h as c, i as l, l as u, m as d, n as f, o as p, p as m, r as h, s as g, t as _, u as v, v as y, w as b, x, y as S } from "./components-DLa9-kdK.js";
2
2
  export { e as DataActions, x as DataCustom, r as DataDescriptions, s as DataFilter, t as DataForm, y as DataFormActions, d as DataLocaleInput, m as DataPagination, a as DataSelection, _ as DataTable, l as DtDeptRender, n as DtUserDept, p as DtUserRender, v as FullscreenButton, u as FullscreenWrapper, b as NCheckboxes, i as NRadios, f as NStateButton, h as StateButtonProps, o as ViewProfile, S as dataFormActionsProps, g as renderUsers, c as useLocaleEdit };
@@ -1,10 +1,150 @@
1
+ import { MaybeComputedElementRef, Pausable } from '@vueuse/core'
1
2
  import Sortable from 'sortablejs'
2
- import { MaybeRef, TemplateRef } from 'vue'
3
+ import { InjectionKey, MaybeRef, ShallowRef, TemplateRef } from 'vue'
3
4
 
4
5
  export declare function useDataTableDrag<T>(
5
6
  tableRef: TemplateRef<HTMLElement>,
6
- { data, onSort, ...options }: {
7
+ options: {
7
8
  data: MaybeRef<T[]>
8
9
  onSort: (info: { from: number, to: number }) => void
9
10
  } & Omit<Sortable.Options, 'onSort'>,
10
11
  ): void
12
+
13
+ /**
14
+ * options for {@link useTableRangeSelect}
15
+ */
16
+ export interface UseTableRangeSelectOptions {
17
+ /**
18
+ * 是否立即启用,默认值从 vue 依赖注入获取
19
+ */
20
+ immediate?: boolean
21
+ /**
22
+ * 是否复制到剪贴板,默认值从 vue 依赖注入获取
23
+ */
24
+ toClipboard?: MaybeRef<boolean | 'onCopy' | undefined>
25
+
26
+ /**
27
+ * 获取单元格内容,默认值从 vue 依赖注入获取
28
+ *
29
+ * @param cell - 单元格
30
+ * @returns 单元格内容
31
+ */
32
+ getCellContent?: (cell: HTMLTableCellElement) => string
33
+
34
+ /**
35
+ * 类名前缀
36
+ * @defaultValue ''
37
+ */
38
+ clsPrefix?: MaybeRef<string | undefined>
39
+
40
+ /**
41
+ * 鼠标按下回调
42
+ * @param event - 鼠标事件
43
+ * @returns false 阻止选择
44
+ */
45
+ onMousedown?: (event: MouseEvent, data: { tr: HTMLTableRowElement, td: HTMLTableCellElement, tbody: HTMLTableSectionElement }) => void | false
46
+
47
+ /**
48
+ * 选中回调
49
+ * @param data - 选中范围数据
50
+ * @returns 是否继续复制到剪贴板(toClipboard 为 'auto')
51
+ */
52
+ onSelect?: (data: {
53
+ /**
54
+ * 选中范围的起始行
55
+ */
56
+ fromRow: number
57
+ /**
58
+ * 选中范围的起始列
59
+ */
60
+ fromCol: number
61
+ /**
62
+ * 选中范围的结束行
63
+ */
64
+ toRow: number
65
+ /**
66
+ * 选中范围的结束列
67
+ */
68
+ toCol: number
69
+ /**
70
+ * 获取选中范围的单元格内容
71
+ */
72
+ getContent: () => string[][]
73
+ /**
74
+ * tbody 元素
75
+ */
76
+ tbody: HTMLTableSectionElement
77
+ }) => void | false
78
+ }
79
+
80
+ export interface UseTableRangeSelectDefaultOptions {
81
+ /**
82
+ * 是否立即启用
83
+ * @defaultValue true
84
+ */
85
+ immediate?: MaybeRef<boolean>
86
+
87
+ /**
88
+ * 是否复制到剪贴板
89
+ * @defaultValue 'onCopy'
90
+ */
91
+ toClipboard?: MaybeRef<'auto' | 'onCopy' | false>
92
+
93
+ /**
94
+ * 获取单元格内容
95
+ * @defaultValue cell =&gt; cell.textContent
96
+ *
97
+ * @param cell - 单元格
98
+ * @returns 单元格内容
99
+ */
100
+ getCellContent?: (cell: HTMLTableCellElement) => string
101
+
102
+ /**
103
+ * 默认类名前缀
104
+ * @defaultValue ''
105
+ */
106
+ clsPrefix?: MaybeRef<string>
107
+ }
108
+
109
+ type UseTableRangeSelectFn = ((target: MaybeComputedElementRef, options?: UseTableRangeSelectOptions) => Pausable & {
110
+ range: Readonly<ShallowRef<{
111
+ /**
112
+ * 是否正在选择中
113
+ */
114
+ ing: boolean
115
+ /**
116
+ * 是否按下鼠标
117
+ */
118
+ mousedown: boolean
119
+ /**
120
+ * 选中范围的起始列
121
+ */
122
+ x0: number
123
+ /**
124
+ * 选中范围的起始行
125
+ */
126
+ y0: number
127
+ /**
128
+ * 选中范围的结束列
129
+ */
130
+ x1: number
131
+ /**
132
+ * 选中范围的结束行
133
+ */
134
+ y1: number
135
+ }>>
136
+ }) & {
137
+ /**
138
+ * 默认选项从 vue 注入 Key
139
+ */
140
+ DEFAULT_OPTIONS: InjectionKey<UseTableRangeSelectDefaultOptions>
141
+ }
142
+
143
+ /**
144
+ * 使用表格范围选择
145
+ * - vue-composable
146
+ *
147
+ * @param target - 目标元素
148
+ * @param options - 配置
149
+ */
150
+ export declare const useTableRangeSelect: UseTableRangeSelectFn & {}
@@ -1,14 +1,15 @@
1
- import { nextTick as e, ref as t, watch as n } from "vue";
2
- import { unrefElement as r } from "@vueuse/core";
3
- import { Sortable as i } from "sortablejs";
1
+ import { t as e } from "./use-table-range-select-Da6t9Vlf.js";
2
+ import { nextTick as t, ref as n, watch as r } from "vue";
3
+ import { unrefElement as i } from "@vueuse/core";
4
+ import { Sortable as a } from "sortablejs";
4
5
  //#region src/composables/use-data-table-drag.js
5
- function a(a, { data: o, onSort: s, ...c }) {
6
- n([t(o), a], async ([t, n]) => {
7
- if (t.length === 0) return;
8
- await e();
9
- let a = r(n)?.querySelector(".n-data-table-base-table-body .n-data-table-tbody");
10
- if (!a) return;
11
- let o = i.create(a, {
6
+ function o(e, { data: o, onSort: s, ...c }) {
7
+ r([n(o), e], async ([e, n]) => {
8
+ if (e.length === 0) return;
9
+ await t();
10
+ let r = i(n)?.querySelector(".n-data-table-base-table-body .n-data-table-tbody");
11
+ if (!r) return;
12
+ let o = a.create(r, {
12
13
  animation: 150,
13
14
  ...c,
14
15
  onSort(e) {
@@ -24,4 +25,4 @@ function a(a, { data: o, onSort: s, ...c }) {
24
25
  }, { immediate: !0 });
25
26
  }
26
27
  //#endregion
27
- export { a as useDataTableDrag };
28
+ export { o as useDataTableDrag, e as useTableRangeSelect };
package/esm/page.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { n as e } from "./use-i18n-BUP_StIp.js";
2
- import { _ as t, a as n, c as r, i, o as a, w as o } from "./components-DfV9ybsT.js";
2
+ import { _ as t, a as n, c as r, i, o as a, w as o } from "./components-DLa9-kdK.js";
3
3
  import { computed as s, createVNode as c, defineAsyncComponent as l, defineComponent as u, h as d, isVNode as f, mergeProps as p, nextTick as m, ref as h, renderSlot as g, shallowRef as _, toValue as v, unref as y } from "vue";
4
4
  import { until as b, useClipboard as x } from "@vueuse/core";
5
5
  import { NButton as S, NCheckbox as C, NColorPicker as w, NDrawer as T, NDrawerContent as E, NFlex as D, NIcon as O, NInput as k, NInputNumber as A, NModal as j, NScrollbar as M, NSelect as N, NText as P, NUpload as F, useMessage as I } from "ithinkdt-ui";
@@ -0,0 +1,111 @@
1
+ import { computed as e, inject as t, readonly as n, ref as r, shallowRef as i, unref as a, watch as o } from "vue";
2
+ import { onClickOutside as s, unrefElement as c, useClipboard as l, useEventListener as u } from "@vueuse/core";
3
+ import { isNullish as d } from "@ithinkdt/common/object";
4
+ //#region src/composables/use-table-range-select.js
5
+ var f = Symbol();
6
+ function p(p, m = {}) {
7
+ let h = i(), g = e(() => c(p)), _ = t(f, {}), v = e(() => a(m.clsPrefix) ?? a(_.clsPrefix) ?? ""), y = e(() => a(m.toClipboard) ?? a(_.toClipboard) ?? "onCopy"), b = m.getCellContent ?? _.getCellContent ?? ((e) => e.textContent), x = r(a(m.immediate) ?? a(_.immediate) ?? !0);
8
+ u(g, "mousedown", (e) => {
9
+ if (h.value &&= void 0, !x.value) return;
10
+ let t = e.target.closest("td"), n = t?.closest("tr"), r = n?.closest("tbody");
11
+ !t || !n || !r || m?.onMousedown?.(e, {
12
+ tr: n,
13
+ td: t,
14
+ tbody: r
15
+ }) === !1 || (h.value = {
16
+ ing: !1,
17
+ mousedown: !0,
18
+ x0: t.cellIndex,
19
+ y0: n.rowIndex
20
+ });
21
+ }, {
22
+ passive: !0,
23
+ capture: !0
24
+ }), u(g, "mousemove", (e) => {
25
+ if (!x.value || !h.value?.mousedown) return;
26
+ let t = e.target.closest("td"), n = t?.closest("tr"), r = n?.closest("tbody");
27
+ !t || !n || !r || !h.value.x1 && t.cellIndex === h.value.x0 && n.rowIndex === h.value.y0 || (h.value = {
28
+ ...h.value,
29
+ ing: !0,
30
+ x1: t.cellIndex,
31
+ y1: n.rowIndex
32
+ }, globalThis.getSelection ? globalThis.getSelection().removeAllRanges() : document.selection && document.selection.empty());
33
+ }, {
34
+ passive: !0,
35
+ capture: !0
36
+ });
37
+ let { copy: S } = l({ legacy: !0 });
38
+ u("mouseup", () => {
39
+ if (!x.value || !h.value) return;
40
+ h.value = {
41
+ ...h.value,
42
+ ing: !1,
43
+ mousedown: !1
44
+ };
45
+ let e = g.value?.querySelector("tbody"), { x0: t, x1: n, y0: r, y1: i } = h.value ?? {};
46
+ if (!m?.onSelect && y.value !== "auto" || !e || d(n)) return;
47
+ let [a, o] = [t, n].toSorted((e, t) => e - t), [s, c] = [r, i].toSorted((e, t) => e - t);
48
+ m?.onSelect?.({
49
+ fromRow: s,
50
+ fromCol: a,
51
+ toRow: c,
52
+ toCol: o,
53
+ getContent: C,
54
+ tbody: e
55
+ }) !== !1 && y.value === "auto" && S(C().map((e) => e.join(" ")).join("\n")).catch(() => {
56
+ console.warn("[useTableRangeSelect] 复制到剪贴板失败");
57
+ });
58
+ }, {
59
+ passive: !0,
60
+ capture: !0
61
+ }), s(g, () => {
62
+ h.value &&= void 0;
63
+ });
64
+ let C = () => {
65
+ let e = g.value?.querySelector("tbody"), { x0: t, x1: n, y0: r, y1: i } = h.value ?? {};
66
+ if (!x.value || !e || d(n)) return [];
67
+ let [a, o] = [t, n].toSorted((e, t) => e - t), [s, c] = [r, i].toSorted((e, t) => e - t), l = [];
68
+ for (let t = s; t <= c; t++) {
69
+ let n = e.rows[t];
70
+ if (!n) continue;
71
+ let r = [];
72
+ for (let e = a; e <= o; e++) {
73
+ let i = n.cells[e];
74
+ if (i && t >= s && t <= c && e >= a && e <= o) {
75
+ let e = b(i) || "";
76
+ e = e.replace(/\t/g, " ").replace(/\r/g, "").replace(/\n/g, ""), r.push(e);
77
+ }
78
+ }
79
+ r.length > 0 && l.push(r);
80
+ }
81
+ return l;
82
+ };
83
+ return o([g, h], ([e, { x0: t, x1: n, y0: r, y1: i } = {}]) => {
84
+ let a = e?.querySelector("tbody");
85
+ if (!a) return;
86
+ let [o, s] = [t, n].toSorted((e, t) => e - t), [c, l] = [r, i].toSorted((e, t) => e - t);
87
+ for (let e = 0; e < a.rows.length; e++) {
88
+ let t = a.rows[e];
89
+ for (let n = 0; n < t.cells.length; n++) {
90
+ let r = t.cells[n];
91
+ r.classList.toggle(`${v.value}cell-selected`, e >= c && e <= l && n >= o && n <= s), r.classList.toggle(`${v.value}cell-selected--first-row`, e === c), r.classList.toggle(`${v.value}cell-selected--first-col`, n === o), r.classList.toggle(`${v.value}cell-selected--last-row`, e === l), r.classList.toggle(`${v.value}cell-selected--last-col`, n === s);
92
+ }
93
+ }
94
+ }), u(document, "copy", (e) => {
95
+ if (y.value !== "onCopy") return;
96
+ let t = C();
97
+ !x.value || t.length === 0 || (e.clipboardData.setData("text/plain", t.map((e) => e.join(" ")).join("\n")), e.preventDefault());
98
+ }, { passive: !1 }), {
99
+ range: n(h),
100
+ isActive: n(x),
101
+ pause: () => {
102
+ x.value = !1, h.value = void 0;
103
+ },
104
+ resume: () => {
105
+ x.value = !0;
106
+ }
107
+ };
108
+ }
109
+ p.DEFAULT_OPTIONS = f;
110
+ //#endregion
111
+ export { p as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ithinkdt/ui",
3
- "version": "4.0.17",
3
+ "version": "4.0.19",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "iThinkDT UI",
@@ -62,12 +62,12 @@
62
62
  "sideEffects": false,
63
63
  "dependencies": {
64
64
  "@vueuse/core": "^14.3.0",
65
- "date-fns": "^4.3.0",
65
+ "date-fns": "^4.4.0",
66
66
  "vueuc": ">=0.4.65",
67
67
  "sortablejs": "^1.15.7",
68
68
  "@types/sortablejs": "^1.15.9",
69
69
  "nanoid": "^5.1.11",
70
- "@ithinkdt/common": "^4.0.9"
70
+ "@ithinkdt/common": "^4.0.12"
71
71
  },
72
72
  "peerDependencies": {
73
73
  "@ithinkdt/page": ">=4.0",
@@ -89,11 +89,11 @@
89
89
  "ithinkdt-ui": "^1.9.4",
90
90
  "typescript": "~6.0.3",
91
91
  "unocss": "^66.7.0",
92
- "vite": "^8.0.14",
93
- "vue": "^3.5.34",
94
- "vue-router": "^5.0.7",
95
- "@vue/test-utils": "^2.4.10",
96
- "@ithinkdt/page": "^4.0.20"
92
+ "vite": "^8.0.16",
93
+ "vue": "^3.5.35",
94
+ "vue-router": "^5.1.0",
95
+ "@vue/test-utils": "^2.4.11",
96
+ "@ithinkdt/page": "^4.0.22"
97
97
  },
98
98
  "scripts": {
99
99
  "dev": "vite build --watch",
@@ -1,221 +0,0 @@
1
- import e, { c as t, cB as n, cE as r, cM as i, useClsPrefix as a } from "./use-style.js";
2
- import { i as o } from "./directives-Chz4DK1u.js";
3
- import { C as s } from "./components-DfV9ybsT.js";
4
- import { computed as c, createVNode as l, defineComponent as u, inject as d, isVNode as f, ref as p, shallowRef as m, toValue as h, useTemplateRef as g, watch as _, withDirectives as v } from "vue";
5
- import { toReactive as y, until as b } from "@vueuse/core";
6
- import { NButton as x, NDataTable as S, NFlex as C, NIcon as w, NTooltip as T, dataTableProps as E } from "ithinkdt-ui";
7
- import { PAGE_INJECTION as D } from "@ithinkdt/page";
8
- //#region src/components/DataTable.jsx
9
- function O(e) {
10
- return typeof e == "function" || Object.prototype.toString.call(e) === "[object Object]" && !f(e);
11
- }
12
- function k(e, t) {
13
- return (e ?? []).map((e) => {
14
- let n = {
15
- csvTitle: e.exportTitle,
16
- ...e,
17
- title: () => {
18
- let t = h(e.title), n = t && v(l("div", null, [t]), [[
19
- o,
20
- () => h(e.title),
21
- void 0,
22
- { auto: !0 }
23
- ]]);
24
- return e.tooltip ? l(C, {
25
- size: 3,
26
- wrap: !1,
27
- inline: !0,
28
- style: "max-width: 100%"
29
- }, { default: () => [n, l(T, null, {
30
- default: h(e.tooltip),
31
- trigger: () => l(x, {
32
- text: !0,
33
- style: "font-size: 1.25em; opacity: 0.8"
34
- }, { default: () => [l(w, null, { default: () => [l(s, null, null)] })] })
35
- })] }) : n;
36
- }
37
- };
38
- if (e.children?.length) n.children = k(e.children, t);
39
- else {
40
- e.hidden !== !0 && (n.width ??= 100, t.value += Number(n.width));
41
- let r = e.render ?? ((e) => e);
42
- e.ellipsis !== !1 && (n.ellipsis = !1, n.render = (...t) => {
43
- let n = r(...t);
44
- return n && (f(n) || ((function() {
45
- return n;
46
- })(), n = l("span", null, [n])), v(n, [[
47
- o,
48
- () => e.ellipsisTooltip ? e.ellipsisTooltip(...t) : n,
49
- void 0,
50
- {
51
- auto: !0,
52
- expandable: e.ellipsisExpandable,
53
- [`ell${e.ellipsis}`]: !0
54
- }
55
- ]]));
56
- }, e.ellipsisTooltip === !0 && (n.ellipsisTooltip = r)), Object.assign(n, {
57
- resizable: e.resizable !== !1,
58
- sorter: e.sortable,
59
- type: ["selection", "expand"].includes(e.type) ? e.type : void 0,
60
- disabled: e.selectable ? (t) => e.selectable(t) === !1 : void 0
61
- });
62
- }
63
- return n.key === "$actions" && (n.cellProps ??= () => ({ style: { padding: "0 2px" } })), n;
64
- }).filter((e) => e?.hidden !== !0);
65
- }
66
- var A = /* @__PURE__ */ u({
67
- name: "DataTable",
68
- props: {
69
- data: {
70
- type: Array,
71
- default: () => []
72
- },
73
- columns: {
74
- type: Array,
75
- default: () => []
76
- },
77
- keyField: { type: String },
78
- sorter: {
79
- type: Object,
80
- default: () => ({})
81
- },
82
- selectedKeys: { type: Array },
83
- highlight: {
84
- type: [
85
- Boolean,
86
- String,
87
- Number,
88
- Object
89
- ],
90
- default: !0
91
- },
92
- highlightColor: String,
93
- appear: {
94
- type: String,
95
- default: "normal"
96
- },
97
- rowClassName: E.rowClassName,
98
- rowProps: E.rowProps,
99
- maxHeight: [String, Number]
100
- },
101
- emits: [
102
- "sort",
103
- "select",
104
- "custom",
105
- "highlight"
106
- ],
107
- setup(t, { slots: n, emit: r, expose: i }) {
108
- let { keyField: o } = d(D), s = a(), u = `${s.value}-datatable`;
109
- e("-datatable", j, s);
110
- let f = g("table-ref"), h = ({ sortField: e, sortOrder: t } = {}, n) => {
111
- e == n?.sortField && t == n?.sortOrder || f.value?.sort(e, t ? t + "end" : !1);
112
- };
113
- _(() => ({ ...t.sorter }), h, { deep: !0 });
114
- let v = c(() => {
115
- let e = t.keyField || o || "key";
116
- return (t) => t[e];
117
- }), x = m({
118
- cache: [],
119
- scrollToView(...e) {
120
- this.cache.push(e);
121
- }
122
- });
123
- b(f).changed().then(() => {
124
- h(t.sorter);
125
- let e = x.value.cache;
126
- x.value = f.value, x.value.scrollToView = (e) => {
127
- let n = t.data.findIndex((t) => v.value(t) === e);
128
- if (n === -1) return;
129
- let r = f.value.$el.querySelector(`.${u}__row-marker:nth-child(${n + 1})`);
130
- f.value.scrollTo({
131
- top: r.offsetTop,
132
- behavior: "smooth"
133
- });
134
- };
135
- for (let t of e) x.value.scrollToView(...t);
136
- }), i(y(x));
137
- let C = p(0), w = m([]);
138
- _(() => t.columns, () => {
139
- C.value = 0, w.value = k(t.columns, C);
140
- }, {
141
- immediate: !0,
142
- deep: 2
143
- });
144
- let T = p();
145
- _(() => t.highlight, (e) => {
146
- T.value = typeof e == "boolean" ? null : e ?? null;
147
- }, { immediate: !0 });
148
- let E = c(() => (e, n) => [
149
- t.rowClassName?.(e, n) || "",
150
- `${u}__row-marker`,
151
- T.value != null && v.value(e) === T.value ? `${u}__row-highlight` : ""
152
- ].join(" ")), A = c(() => (e, n) => {
153
- let i = t.rowProps?.(e, n);
154
- return {
155
- ...i,
156
- "data-row-key": v.value(e),
157
- onClick: (n) => {
158
- let a = v.value(e);
159
- t.highlight === !0 && (T.value = a), r("highlight", a), i?.onClick?.(n);
160
- }
161
- };
162
- }), M = (e) => {
163
- if (t.sorter) {
164
- let { sortField: n, sortOrder: r } = t.sorter;
165
- if (e?.columnKey == n && (e?.order ? e.order === r + "end" : !r)) return;
166
- }
167
- r("sort", {
168
- sortField: e?.order ? e?.columnKey : void 0,
169
- sortOrder: e?.order ? e.order.replace("end", "") : void 0
170
- });
171
- }, N = (e) => {
172
- r("select", e);
173
- }, P = (e, t, n) => {
174
- r("custom", {
175
- key: n.key,
176
- width: e
177
- });
178
- };
179
- return () => l(S, {
180
- class: [u, t.appear === "sticky" ? `${u}--sticky` : ""],
181
- data: t.data,
182
- columns: w.value,
183
- rowKey: v.value,
184
- tableLayout: "fixed",
185
- ref: "table-ref",
186
- scrollX: C.value,
187
- rowClassName: E.value,
188
- rowProps: A.value,
189
- checkedRowKeys: t.selectedKeys,
190
- style: { "--n-tr-highlight-color": t.highlightColor },
191
- maxHeight: t.maxHeight ?? (t.appear === "sticky" ? "auto" : void 0),
192
- onUpdateSorter: M,
193
- onUpdateCheckedRowKeys: N,
194
- onUnstableColumnResize: P
195
- }, O(n) ? n : { default: () => [n] });
196
- }
197
- }), j = /* @__PURE__ */ n("datatable", [r("row-highlight", [t("& > td", { backgroundColor: "var(--n-tr-highlight-color, var(--n-merged-border-color)) !important" })]), i("sticky", [
198
- t(".n-data-table-base-table-header", {
199
- position: "sticky",
200
- top: "-1px",
201
- zIndex: 10,
202
- overflowY: "hidden"
203
- }),
204
- t(".n-data-table-base-table-body", { overflow: "initial" }, [t("& > .n-scrollbar-container", {
205
- overflow: "initial",
206
- overflowX: "scroll"
207
- }), t("& > .n-scrollbar-rail--horizontal", {
208
- position: "sticky",
209
- bottom: "0"
210
- })]),
211
- t(".n-data-table-base-table:has(.n-data-table-empty) .n-data-table-base-table-header", {
212
- scrollbarWidth: "thin",
213
- overflowX: "auto"
214
- }),
215
- t(".n-data-table-td > *", {
216
- verticalAlign: "middle",
217
- contentVisibility: "auto"
218
- })
219
- ])]);
220
- //#endregion
221
- export { A as DataTable };