vue3-smart-table 0.0.5 → 1.0.0

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.
@@ -1,15 +1,101 @@
1
- import { defineComponent as O, ref as F, watch as $, resolveComponent as V, createBlock as _, openBlock as g, mergeProps as x, withKeys as R, withCtx as P, createElementBlock as z, Fragment as J, renderList as K, h as f, computed as W, toRefs as X, createCommentVNode as Z, unref as s, createTextVNode as q, toDisplayString as T, renderSlot as G, normalizeProps as ee, resolveDynamicComponent as te, normalizeClass as ne, normalizeStyle as le, resolveDirective as re, withDirectives as oe, createSlots as ie } from "vue";
2
- import { ElImage as D, ElTag as se, ElMessage as A, ElButton as ae } from "element-plus";
3
- function C(t, e) {
1
+ var ie = Object.defineProperty;
2
+ var se = (t, e, n) => e in t ? ie(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
+ var D = (t, e, n) => se(t, typeof e != "symbol" ? e + "" : e, n);
4
+ import { defineComponent as M, h as f, ref as R, watch as z, resolveComponent as O, createBlock as _, openBlock as h, mergeProps as B, withKeys as U, withCtx as V, createElementBlock as I, Fragment as H, renderList as K, computed as $, toRefs as ae, createCommentVNode as ce, unref as a, createTextVNode as Z, toDisplayString as W, renderSlot as ne, normalizeProps as ue, resolveDynamicComponent as de, normalizeClass as me, normalizeStyle as fe, resolveDirective as ye, withDirectives as pe, createSlots as ge } from "vue";
5
+ import { ElImage as q, ElTag as he, ElMessage as F, ElButton as Ce } from "element-plus";
6
+ import { CopyDocument as ve, DocumentCopy as be } from "@element-plus/icons-vue";
7
+ class ke {
8
+ constructor() {
9
+ D(this, "renderers", /* @__PURE__ */ new Map());
10
+ }
11
+ register(e, n) {
12
+ this.renderers.has(e) && process.env.NODE_ENV === "development" && console.debug(`[SmartTable] Renderer "${e}" already registered, skipping.`), this.renderers.set(e, n);
13
+ }
14
+ registerMultiple(e) {
15
+ Object.entries(e).forEach(([n, o]) => {
16
+ this.renderers.has(n) || this.renderers.set(n, o);
17
+ });
18
+ }
19
+ get(e) {
20
+ return this.renderers.get(e);
21
+ }
22
+ has(e) {
23
+ return this.renderers.has(e);
24
+ }
25
+ unregister(e) {
26
+ return this.renderers.delete(e);
27
+ }
28
+ clear() {
29
+ this.renderers.clear();
30
+ }
31
+ names() {
32
+ return Array.from(this.renderers.keys());
33
+ }
34
+ }
35
+ let P = null;
36
+ function J() {
37
+ return P || (P = new ke()), P;
38
+ }
39
+ function Y(t) {
40
+ return M({
41
+ props: ["row", "col", "onCellChange", "onCellBlur", "onCellEnter", "onClick"],
42
+ setup(e) {
43
+ return () => f(t, e);
44
+ }
45
+ });
46
+ }
47
+ function E(t) {
48
+ return M({
49
+ props: ["row", "col", "onCellChange", "onCellBlur", "onCellEnter", "onClick"],
50
+ setup(e) {
51
+ return () => t(e);
52
+ }
53
+ });
54
+ }
55
+ function Ge(t, e) {
56
+ if (process.env.NODE_ENV !== "production" && e)
57
+ switch (t) {
58
+ case "dict":
59
+ (!e.options || !Array.isArray(e.options)) && console.warn(
60
+ "[SmartTable] 'dict' renderer requires 'options' array, received:",
61
+ e.options
62
+ );
63
+ break;
64
+ case "select":
65
+ !e.options || !Array.isArray(e.options) ? console.warn(
66
+ "[SmartTable] 'select' renderer requires 'options' array, received:",
67
+ e.options
68
+ ) : e.options.length === 0 && console.warn("[SmartTable] 'select' renderer 'options' array is empty");
69
+ break;
70
+ case "map":
71
+ (!e.options || typeof e.options != "object") && console.warn(
72
+ "[SmartTable] 'map' renderer requires 'options' object, received:",
73
+ e.options
74
+ );
75
+ break;
76
+ case "link":
77
+ (!e.href || typeof e.href != "string") && console.warn(
78
+ "[SmartTable] 'link' renderer requires 'href' string, received:",
79
+ e.href
80
+ );
81
+ break;
82
+ case "input-number":
83
+ e.min !== void 0 && e.max !== void 0 && e.min > e.max && console.warn(
84
+ `[SmartTable] 'input-number' renderer: min (${e.min}) should not be greater than max (${e.max})`
85
+ );
86
+ break;
87
+ }
88
+ }
89
+ function b(t, e) {
4
90
  if (!(!t || !e))
5
- return e.split(".").reduce((n, r) => n == null ? void 0 : n[r], t);
91
+ return e.split(".").reduce((n, o) => n == null ? void 0 : n[o], t);
6
92
  }
7
- function U(t, e, n) {
93
+ function G(t, e, n) {
8
94
  if (!t || !e) return;
9
- const r = e.split("."), o = r.pop(), l = r.reduce((i, c) => (i[c] || (i[c] = {}), i[c]), t);
10
- l[o] = n;
95
+ const o = e.split("."), l = o.pop(), r = o.reduce((i, c) => (i[c] || (i[c] = {}), i[c]), t);
96
+ r[l] = n;
11
97
  }
12
- const ce = /* @__PURE__ */ O({
98
+ const we = /* @__PURE__ */ M({
13
99
  __name: "input",
14
100
  props: {
15
101
  row: {},
@@ -18,29 +104,29 @@ const ce = /* @__PURE__ */ O({
18
104
  onCellEnter: { type: Function }
19
105
  },
20
106
  setup(t) {
21
- const e = t, n = F(C(e.row, e.col.key));
22
- $(n, (l) => {
23
- U(e.row, e.col.key, l);
107
+ const e = t, n = R(b(e.row, e.col.key));
108
+ z(n, (r) => {
109
+ G(e.row, e.col.key, r);
24
110
  });
25
- const r = () => {
26
- var l;
27
- return (l = e.onCellBlur) == null ? void 0 : l.call(e, e.row, e.col);
28
- }, o = () => {
29
- var l;
30
- return (l = e.onCellEnter) == null ? void 0 : l.call(e, e.row, e.col);
111
+ const o = () => {
112
+ var r;
113
+ return (r = e.onCellBlur) == null ? void 0 : r.call(e, e.row, e.col);
114
+ }, l = () => {
115
+ var r;
116
+ return (r = e.onCellEnter) == null ? void 0 : r.call(e, e.row, e.col);
31
117
  };
32
- return (l, i) => {
33
- const c = V("el-input");
34
- return g(), _(c, x({
118
+ return (r, i) => {
119
+ const c = O("el-input");
120
+ return h(), _(c, B({
35
121
  modelValue: n.value,
36
- "onUpdate:modelValue": i[0] || (i[0] = (u) => n.value = u)
122
+ "onUpdate:modelValue": i[0] || (i[0] = (d) => n.value = d)
37
123
  }, { placeholder: "", size: "small", clearable: !0, ...t.col.renderProps }, {
38
- onBlur: r,
39
- onKeyup: R(o, ["enter"])
124
+ onBlur: o,
125
+ onKeyup: U(l, ["enter"])
40
126
  }), null, 16, ["modelValue"]);
41
127
  };
42
128
  }
43
- }), ue = /* @__PURE__ */ O({
129
+ }), _e = /* @__PURE__ */ M({
44
130
  __name: "inputNumber",
45
131
  props: {
46
132
  row: {},
@@ -50,30 +136,30 @@ const ce = /* @__PURE__ */ O({
50
136
  onCellEnter: { type: Function }
51
137
  },
52
138
  setup(t) {
53
- const e = t, n = F(C(e.row, e.col.key));
54
- $(n, (l) => {
139
+ const e = t, n = R(b(e.row, e.col.key));
140
+ z(n, (r) => {
55
141
  var i;
56
- U(e.row, e.col.key, l), (i = e.onCellChange) == null || i.call(e, e.row, e.col);
142
+ G(e.row, e.col.key, r), (i = e.onCellChange) == null || i.call(e, e.row, e.col);
57
143
  });
58
- const r = () => {
59
- var l;
60
- return (l = e.onCellBlur) == null ? void 0 : l.call(e, e.row, e.col);
61
- }, o = () => {
62
- var l;
63
- return (l = e.onCellEnter) == null ? void 0 : l.call(e, e.row, e.col);
144
+ const o = () => {
145
+ var r;
146
+ return (r = e.onCellBlur) == null ? void 0 : r.call(e, e.row, e.col);
147
+ }, l = () => {
148
+ var r;
149
+ return (r = e.onCellEnter) == null ? void 0 : r.call(e, e.row, e.col);
64
150
  };
65
- return (l, i) => {
66
- const c = V("el-input-number");
67
- return g(), _(c, x({
151
+ return (r, i) => {
152
+ const c = O("el-input-number");
153
+ return h(), _(c, B({
68
154
  modelValue: n.value,
69
- "onUpdate:modelValue": i[0] || (i[0] = (u) => n.value = u)
155
+ "onUpdate:modelValue": i[0] || (i[0] = (d) => n.value = d)
70
156
  }, { min: 0, max: 99999, controls: !1, size: "small", ...t.col.renderProps }, {
71
- onBlur: r,
72
- onKeyup: R(o, ["enter"])
157
+ onBlur: o,
158
+ onKeyup: U(l, ["enter"])
73
159
  }), null, 16, ["modelValue"]);
74
160
  };
75
161
  }
76
- }), de = /* @__PURE__ */ O({
162
+ }), xe = /* @__PURE__ */ M({
77
163
  __name: "select",
78
164
  props: {
79
165
  row: {},
@@ -83,37 +169,37 @@ const ce = /* @__PURE__ */ O({
83
169
  onCellEnter: { type: Function }
84
170
  },
85
171
  setup(t) {
86
- const e = t, n = F(C(e.row, e.col.key));
87
- $(n, (i) => {
88
- U(e.row, e.col.key, i);
172
+ const e = t, n = R(b(e.row, e.col.key));
173
+ z(n, (i) => {
174
+ G(e.row, e.col.key, i);
89
175
  });
90
- const r = () => {
176
+ const o = () => {
91
177
  var i;
92
178
  return (i = e.onCellChange) == null ? void 0 : i.call(e, e.row, e.col);
93
- }, o = () => {
179
+ }, l = () => {
94
180
  var i;
95
181
  return (i = e.onCellBlur) == null ? void 0 : i.call(e, e.row, e.col);
96
- }, l = () => {
182
+ }, r = () => {
97
183
  var i;
98
184
  return (i = e.onCellEnter) == null ? void 0 : i.call(e, e.row, e.col);
99
185
  };
100
186
  return (i, c) => {
101
- const u = V("el-option"), h = V("el-select");
102
- return g(), _(h, x({
187
+ const d = O("el-option"), g = O("el-select");
188
+ return h(), _(g, B({
103
189
  modelValue: n.value,
104
190
  "onUpdate:modelValue": c[0] || (c[0] = (v) => n.value = v)
105
191
  }, { placeholder: "请选择", size: "small", clearable: !0, ...t.col.renderProps }, {
106
- onChange: r,
107
- onBlur: o,
108
- onKeyup: R(l, ["enter"])
192
+ onChange: o,
193
+ onBlur: l,
194
+ onKeyup: U(r, ["enter"])
109
195
  }), {
110
- default: P(() => {
196
+ default: V(() => {
111
197
  var v;
112
198
  return [
113
- (g(!0), z(J, null, K(((v = t.col.renderProps) == null ? void 0 : v.options) || [], (d) => (g(), _(u, {
114
- key: d.value,
115
- label: d.label,
116
- value: d.value
199
+ (h(!0), I(H, null, K(((v = t.col.renderProps) == null ? void 0 : v.options) || [], (m) => (h(), _(d, {
200
+ key: m.value,
201
+ label: m.label,
202
+ value: m.value
117
203
  }, null, 8, ["label", "value"]))), 128))
118
204
  ];
119
205
  }),
@@ -121,220 +207,206 @@ const ce = /* @__PURE__ */ O({
121
207
  }, 16, ["modelValue"]);
122
208
  };
123
209
  }
124
- }), N = (t) => O({
125
- props: ["row", "col", "onCellChange", "onCellBlur", "onCellEnter", "onClick"],
126
- setup(e) {
127
- return () => f(t, e);
128
- }
129
- });
130
- function ye(t) {
131
- return typeof t.formatter == "function";
132
- }
133
- function me() {
134
- return {
135
- input: N(ce),
136
- "input-number": N(ue),
137
- select: N(de),
138
- button: (t) => {
139
- const e = t.col.renderProps || {}, n = C(t.row, t.col.key);
140
- return f(ae, {
141
- type: e.type || "primary",
142
- ...e,
143
- onClick: () => {
144
- var r;
145
- return (r = t.onClick) == null ? void 0 : r.call(t, t.row, t.col);
146
- }
147
- }, () => e.label || n);
148
- },
149
- link: (t) => {
150
- const e = t.col.renderProps || {}, n = C(t.row, t.col.key);
151
- return f("a", {
152
- href: e.href || "#",
153
- target: e.blank ? "_blank" : "_self",
154
- style: e.style || "color:#409EFF;cursor:pointer;",
155
- onClick: (r) => {
156
- var o;
157
- r.preventDefault(), (o = t.onClick) == null || o.call(t, t.row, t.col);
158
- }
159
- }, e.label || n);
160
- },
161
- html: (t) => {
162
- var n;
163
- const e = C(t.row, t.col.key);
164
- return f("div", {
165
- class: "line-clamp-2",
166
- innerHTML: e ?? "",
167
- ...((n = t.col) == null ? void 0 : n.renderProps) || {}
168
- });
210
+ }), Be = Y(we), Ee = Y(_e), Se = Y(xe), Ae = E((t) => {
211
+ const e = t.col.renderProps || {}, n = b(t.row, t.col.key);
212
+ return f(Ce, {
213
+ type: e.type || "primary",
214
+ ...e,
215
+ onClick: () => {
216
+ var o;
217
+ return (o = t.onClick) == null ? void 0 : o.call(t, t.row, t.col);
218
+ }
219
+ }, () => e.label || n);
220
+ }), Te = E((t) => {
221
+ const e = t.col.renderProps || {}, n = b(t.row, t.col.key);
222
+ return f("a", {
223
+ href: e.href || "#",
224
+ target: e.blank ? "_blank" : "_self",
225
+ style: e.style || "color:#409EFF;cursor:pointer;"
226
+ }, e.label || n);
227
+ }), Ve = E((t) => {
228
+ var n;
229
+ const e = b(t.row, t.col.key);
230
+ return f("div", {
231
+ class: "line-clamp-2",
232
+ innerHTML: e ?? "",
233
+ ...((n = t.col) == null ? void 0 : n.renderProps) || {}
234
+ });
235
+ }), Oe = E((t) => {
236
+ const e = b(t.row, t.col.key) ?? "", n = t.col.renderProps ?? {}, o = {
237
+ position: "absolute",
238
+ right: "-5px",
239
+ top: "50%",
240
+ transform: "translateY(-50%)",
241
+ cursor: "pointer",
242
+ display: "none",
243
+ "font-size": "12px",
244
+ color: n.iconColor || "#409EFF",
245
+ "user-select": "none"
246
+ };
247
+ return f(
248
+ "div",
249
+ {
250
+ class: "st_copy_wrapper",
251
+ style: "width: 100%; position: relative; display: inline-block;"
169
252
  },
170
- copy: (t) => {
171
- const e = C(t.row, t.col.key) ?? "";
172
- return f(
173
- "div",
174
- {
175
- class: "copy-wrapper",
176
- style: "position: relative; display: inline-block;"
177
- },
178
- [
179
- f("span", {
180
- class: "copy-text line-clamp-1",
181
- style: "padding-right: 20px;"
182
- }, e),
183
- f(
184
- "span",
185
- {
186
- class: "copy-btn",
187
- style: `
188
- position: absolute;
189
- right: 0;
190
- top: 50%;
191
- transform: translateY(-50%);
192
- cursor: pointer;
193
- display: none;
194
- font-size: 12px;
195
- color: #409EFF;
196
- user-select: none;
197
- `,
198
- onClick: () => {
199
- if (e)
200
- try {
201
- if (navigator.clipboard && navigator.clipboard.writeText)
202
- navigator.clipboard.writeText(e).then(() => {
203
- A.success("复制成功");
204
- }).catch(() => {
205
- A.error("复制失败");
206
- });
207
- else {
208
- const n = document.createElement("textarea");
209
- n.value = e, n.style.position = "fixed", n.style.opacity = "0", document.body.appendChild(n), n.select();
210
- const r = document.execCommand("copy");
211
- document.body.removeChild(n), r ? A.success("复制成功") : A.error("复制失败");
212
- }
213
- } catch {
214
- A.error("复制失败");
215
- }
253
+ [
254
+ f("span", {
255
+ class: "st_copy_text line-clamp-1",
256
+ style: "padding-right: 10px; display: block;"
257
+ }, e),
258
+ e && f("span", {
259
+ class: "st_copy_btn",
260
+ style: o,
261
+ title: n.copyTitle || "复制",
262
+ onClick: () => {
263
+ if (e)
264
+ try {
265
+ if (navigator.clipboard && navigator.clipboard.writeText)
266
+ navigator.clipboard.writeText(e).then(() => {
267
+ F.success(n.successText ?? "复制成功");
268
+ }).catch(() => {
269
+ F.error(n.errorText ?? "复制失败");
270
+ });
271
+ else {
272
+ const l = document.createElement("textarea");
273
+ l.value = e, l.style.position = "fixed", l.style.opacity = "0", document.body.appendChild(l), l.select();
274
+ const r = document.execCommand("copy");
275
+ document.body.removeChild(l), r ? F.success(n.successText ?? "复制成功") : F.error(n.errorText ?? "复制失败");
216
276
  }
217
- },
218
- "📋"
219
- // 复制图标,可用 Element Plus 图标替换
220
- )
221
- ]
222
- );
277
+ } catch {
278
+ F.error(n.errorText ?? "复制失败");
279
+ }
280
+ }
281
+ }, [f(be, {
282
+ style: "width: 1em; height: 1em;"
283
+ })])
284
+ ].filter(Boolean)
285
+ );
286
+ }), Me = E((t) => {
287
+ var i;
288
+ const e = b(t.row, t.col.key) ?? "", n = ((i = t.col) == null ? void 0 : i.renderProps) || {}, l = e ? Array.isArray(e) ? e.filter((c) => c && typeof c == "string") : [e] : [];
289
+ if (l.length === 0)
290
+ return n.placeholder || "";
291
+ const r = {
292
+ width: n.width || "80px",
293
+ height: n.height || "80px",
294
+ marginRight: l.length > 1 ? "4px" : "0",
295
+ ...n.style || {}
296
+ };
297
+ return l.length === 1 ? f(q, {
298
+ src: l[0],
299
+ previewSrcList: n.previewSrcList || l,
300
+ fit: n.fit || "contain",
301
+ style: r,
302
+ ...n
303
+ }) : f(
304
+ "div",
305
+ {
306
+ class: "st_img_wrapper",
307
+ style: "display: flex; align-items: center; position: relative"
223
308
  },
224
- img: (t) => {
225
- var i;
226
- const e = C(t.row, t.col.key) ?? "", n = ((i = t.col) == null ? void 0 : i.renderProps) || {}, o = e ? Array.isArray(e) ? e.filter((c) => c && typeof c == "string") : [e] : [];
227
- if (o.length === 0)
228
- return n.placeholder || "";
229
- const l = {
230
- width: n.width || "80px",
231
- height: n.height || "80px",
232
- marginRight: o.length > 1 ? "4px" : "0",
233
- ...n.style || {}
234
- };
235
- return o.length === 1 ? f(D, {
236
- src: o[0],
237
- previewSrcList: n.previewSrcList || o,
309
+ [
310
+ f(q, {
311
+ src: l[0],
312
+ previewSrcList: n.previewSrcList || l,
238
313
  fit: n.fit || "contain",
239
- style: l,
314
+ style: r,
240
315
  ...n
241
- }) : (console.log(n.previewSrcList), f("div", {
242
- style: "display: flex; align-items: center; position: relative"
243
- }, [
244
- // 显示第一张图片,点击可预览所有
245
- f(D, {
246
- src: o[0],
247
- previewSrcList: n.previewSrcList || o,
248
- fit: n.fit || "contain",
249
- style: l,
250
- ...n
251
- }),
252
- // 如果图片数量大于1,显示剩余图片数量
253
- o.length > 1 && f("span", {
254
- style: `
255
- margin-left: 8px;
256
- font-size: 12px;
257
- color: #666;
258
- background: #f0f0f0;
259
- padding: 2px 6px;
260
- border-radius: 2px;
261
- position: absolute;
262
- top: 0;
263
- right: 0;
264
- `,
265
- title: `共 ${o.length} 张图片`
266
- }, `+${o.length - 1}`)
267
- ]));
268
- },
269
- dict: (t) => {
270
- const e = C(t.row, t.col.key) ?? "", n = t.col.renderProps || {}, r = n.options ?? [], o = n.showValue ?? !1;
271
- if (e == null || e === "") return "";
272
- const l = Array.isArray(e) ? e.map(String) : [String(e)], i = r.filter((h) => l.includes(String(h.value))), c = l.filter((h) => !r.some((v) => String(v.value) === h)), u = i.map((h, v) => f(
273
- se,
274
- { key: h.value, type: h.listClass, class: h.cssClass, disableTransitions: !0 },
275
- { default: () => h.label + " " }
276
- ));
277
- return o && c.length > 0 && u.push(f("span", {}, c.join(" "))), f("div", {}, u);
278
- },
279
- map: (t) => {
280
- var r;
281
- const e = C(t.row, t.col.key) ?? "", n = ((r = t.col.renderProps) == null ? void 0 : r.options) ?? {};
282
- return e != null ? n[e] ?? "" : "";
283
- },
284
- formatter: (t) => {
285
- var o;
286
- const { col: e, row: n } = t, r = C(t.row, t.col.key) ?? "";
287
- return ye(e) ? (o = e.formatter) == null ? void 0 : o.call(e, r, n) : r ?? "";
288
- },
289
- icon: (t) => {
290
- const e = C(t.row, t.col.key) ?? "", n = t.col.renderProps || {};
291
- return e ? /^https?:\/\//.test(e) ? f(D, {
292
- src: e,
293
- previewSrcList: [e],
294
- fit: "contain",
295
- style: "width:40px;height:40px",
296
- ...n
297
- }) : /^\s*<svg[\s\S]*<\/svg>\s*$/.test(e) ? f("div", {
298
- innerHTML: e,
299
- style: `width:40px;height:40px;display:inline-block;${n.style || ""}`,
300
- ...n
301
- }) : f("i", {
302
- class: e,
303
- // val 直接当 className
304
- style: `font-size:20px;${n.style || ""}`,
305
- ...n
306
- }) : "";
307
- }
308
- };
316
+ }),
317
+ l.length > 1 && f("span", {
318
+ class: "st_img_total",
319
+ style: "position: absolute; top: 0; right: 0; ",
320
+ title: `${l.length}`
321
+ }, [f(ve, { style: "width: 1em; height: 1em; " })])
322
+ ]
323
+ );
324
+ }), Fe = E((t) => {
325
+ const e = b(t.row, t.col.key) ?? "", n = t.col.renderProps || {}, o = n.options ?? [], l = n.showValue ?? !1;
326
+ if (e == null || e === "") return "";
327
+ const r = Array.isArray(e) ? e.map(String) : [String(e)], i = o.filter((g) => r.includes(String(g.value))), c = r.filter((g) => !o.some((v) => String(v.value) === g)), d = i.map((g, v) => f(
328
+ he,
329
+ { key: g.value, type: g.listClass, class: g.cssClass, disableTransitions: !0 },
330
+ { default: () => g.label + " " }
331
+ ));
332
+ return l && c.length > 0 && d.push(f("span", {}, c.join(" "))), f("div", {}, d);
333
+ }), $e = E((t) => {
334
+ var o;
335
+ const e = b(t.row, t.col.key) ?? "", n = ((o = t.col.renderProps) == null ? void 0 : o.options) ?? {};
336
+ return e != null ? n[e] ?? "" : "";
337
+ });
338
+ function Re(t) {
339
+ return typeof t.formatter == "function";
340
+ }
341
+ const ze = E((t) => {
342
+ var l;
343
+ const { col: e, row: n } = t, o = b(t.row, t.col.key) ?? "";
344
+ return Re(e) ? (l = e.formatter) == null ? void 0 : l.call(e, o, n) : o ?? "";
345
+ }), Ie = E((t) => {
346
+ const e = b(t.row, t.col.key) ?? "", n = t.col.renderProps || {};
347
+ return e ? /^https?:\/\//.test(e) ? f(q, {
348
+ src: e,
349
+ previewSrcList: [e],
350
+ fit: "contain",
351
+ style: "width:40px;height:40px",
352
+ ...n
353
+ }) : /^\s*<svg[\s\S]*<\/svg>\s*$/.test(e) ? f("div", {
354
+ innerHTML: e,
355
+ style: `width:40px;height:40px;display:inline-block;${n.style || ""}`,
356
+ ...n
357
+ }) : f("i", {
358
+ class: e,
359
+ style: `font-size:20px;${n.style || ""}`,
360
+ ...n
361
+ }) : "";
362
+ }), re = {
363
+ input: Be,
364
+ "input-number": Ee,
365
+ select: Se,
366
+ button: Ae,
367
+ link: Te,
368
+ html: Ve,
369
+ copy: Oe,
370
+ img: Me,
371
+ dict: Fe,
372
+ map: $e,
373
+ formatter: ze,
374
+ icon: Ie
375
+ };
376
+ function Ke(t) {
377
+ t.registerMultiple(re);
378
+ }
379
+ function Qe() {
380
+ return re;
309
381
  }
310
- function pe(t, e = 10, n = []) {
311
- const o = "*:*:*", l = (a) => {
312
- if (!a) return !0;
313
- const m = Array.isArray(a) ? a : [a];
382
+ function Le(t, e = 10, n = []) {
383
+ const l = "*:*:*", r = (s) => {
384
+ if (!s) return !0;
385
+ const y = Array.isArray(s) ? s : [s];
314
386
  return n.some(
315
- (p) => p === o || m.includes(p)
387
+ (p) => p === l || y.includes(p)
316
388
  );
317
- }, i = W(() => t.some((a) => l(a.permission))), c = W(() => t.filter((m) => l(m.permission)).slice(0, e).reduce(
318
- (m, p) => m + (p.width ?? 60),
389
+ }, i = $(() => t.some((s) => r(s.permission))), c = $(() => t.filter((y) => r(y.permission)).slice(0, e).reduce(
390
+ (y, p) => y + (p.width ?? 60),
319
391
  0
320
- )), u = (a, m) => l(a.permission) && (a.visible ? a.visible(m) : !0), h = (a) => t.filter((p) => u(p, a)).slice(0, e).reduce(
321
- (p, B) => p + (B.width ?? 60),
392
+ )), d = (s, y) => r(s.permission) && (s.visible ? s.visible(y) : !0), g = (s) => t.filter((p) => d(p, s)).slice(0, e).reduce(
393
+ (p, S) => p + (S.width ?? 60),
322
394
  0
323
395
  );
324
396
  return {
325
397
  hasAnyButton: i,
326
398
  optWidth: c,
327
- hasAnyVisibleButton: (a) => a != null && a.length ? a.some(
328
- (m) => t.some((p) => u(p, m))
399
+ hasAnyVisibleButton: (s) => s != null && s.length ? s.some(
400
+ (y) => t.some((p) => d(p, y))
329
401
  ) : !1,
330
- getMaxOptWidth: (a) => a != null && a.length ? a.reduce(
331
- (m, p) => Math.max(m, h(p)),
402
+ getMaxOptWidth: (s) => s != null && s.length ? s.reduce(
403
+ (y, p) => Math.max(y, g(p)),
332
404
  0
333
405
  ) : c.value,
334
- getVisibleButtons: (a) => t.filter((m) => u(m, a)).slice(0, e)
406
+ getVisibleButtons: (s) => t.filter((y) => d(y, s)).slice(0, e)
335
407
  };
336
408
  }
337
- const fe = ["title"], he = /* @__PURE__ */ O({
409
+ const Ne = ["title"], De = /* @__PURE__ */ M({
338
410
  __name: "index",
339
411
  props: {
340
412
  col: { type: Object, required: !0 },
@@ -343,120 +415,128 @@ const fe = ["title"], he = /* @__PURE__ */ O({
343
415
  },
344
416
  emits: ["cellBlur", "cellEnter", "cellChange", "cellClick"],
345
417
  setup(t, { emit: e }) {
346
- const n = t, r = e, o = (y) => {
347
- var L, w;
348
- const b = (L = n.pagination) == null ? void 0 : L.page, E = (w = n.pagination) == null ? void 0 : w.size;
349
- return b && E ? (b - 1) * E + y + 1 : y + 1;
350
- }, { col: l } = X(n), i = (y, b) => r("cellChange", y, b), c = (y, b) => r("cellBlur", y, b), u = (y, b) => r("cellEnter", y, b), h = (y, b) => r("cellClick", y, b), v = me(), {
351
- hasAnyButton: d,
418
+ const n = t, o = e, l = (u) => {
419
+ var A, w;
420
+ const C = (A = n.pagination) == null ? void 0 : A.page, x = (w = n.pagination) == null ? void 0 : w.size;
421
+ return C && x ? (C - 1) * x + u + 1 : u + 1;
422
+ }, { col: r } = ae(n), i = (u, C) => o("cellChange", u, C), c = (u, C) => o("cellBlur", u, C), d = (u, C) => o("cellEnter", u, C), g = (u, C) => o("cellClick", u, C);
423
+ Ke(J());
424
+ const v = $(() => {
425
+ const u = J(), C = {};
426
+ return u.names().forEach((x) => {
427
+ const A = u.get(x);
428
+ A && (C[x] = A);
429
+ }), C;
430
+ }), {
431
+ hasAnyButton: m,
352
432
  hasAnyVisibleButton: k,
353
- optWidth: a,
354
- getMaxOptWidth: m,
433
+ optWidth: s,
434
+ getMaxOptWidth: y,
355
435
  getVisibleButtons: p
356
- } = pe(
357
- l.value.buttons || [],
358
- l.value.maxbtn ?? 10,
436
+ } = Le(
437
+ r.value.buttons || [],
438
+ r.value.maxbtn ?? 10,
359
439
  n.permissions || []
360
- ), B = W(() => (l.value.buttons || []).length ? (l.value.__rows || []).length ? k(l.value.__rows || []) : d.value : !1), I = W(() => l.value.__rows ? m(l.value.__rows) : a.value);
361
- function Q(y) {
362
- return !(y.type === "selection" || y.type === "index" || y.type === "operation" && !B.value || y.visible === !1);
440
+ ), S = $(() => (r.value.buttons || []).length ? (r.value.__rows || []).length ? k(r.value.__rows || []) : m.value : !1), L = $(() => r.value.__rows ? y(r.value.__rows) : s.value);
441
+ function oe(u) {
442
+ return !(u.type === "selection" || u.type === "index" || u.type === "operation" && !S.value || u.visible === !1);
363
443
  }
364
- return (y, b) => {
365
- const E = V("el-table-column"), L = V("el-button");
366
- return s(l).type === "selection" ? (g(), _(E, x({
444
+ return (u, C) => {
445
+ const x = O("el-table-column"), A = O("el-button");
446
+ return a(r).type === "selection" ? (h(), _(x, B({
367
447
  key: 0,
368
448
  type: "selection"
369
- }, s(l).columnProps), null, 16)) : s(l).type === "index" ? (g(), _(E, x({
449
+ }, a(r).columnProps), null, 16)) : a(r).type === "index" ? (h(), _(x, B({
370
450
  key: 1,
371
451
  type: "index",
372
- label: s(l).label || "#",
452
+ label: a(r).label || "#",
373
453
  align: "center"
374
- }, s(l).columnProps), {
375
- default: P(({ $index: w }) => [
376
- q(T(o(w)), 1)
454
+ }, a(r).columnProps), {
455
+ default: V(({ $index: w }) => [
456
+ Z(W(l(w)), 1)
377
457
  ]),
378
458
  _: 1
379
- }, 16, ["label"])) : s(l).type === "operation" && B.value ? (g(), _(E, x({
459
+ }, 16, ["label"])) : a(r).type === "operation" && S.value ? (h(), _(x, B({
380
460
  key: 2,
381
- label: s(l).label || "操作",
461
+ label: a(r).label || "操作",
382
462
  align: "center"
383
463
  }, {
384
- ...s(l).columnProps,
385
- width: I.value
464
+ ...a(r).columnProps,
465
+ width: L.value
386
466
  }), {
387
- default: P(({ row: w }) => [
388
- (g(!0), z(J, null, K(s(p)(w), (S) => (g(), _(L, {
389
- key: S.label,
390
- type: S.type || "primary",
467
+ default: V(({ row: w }) => [
468
+ (h(!0), I(H, null, K(a(p)(w), (T) => (h(), _(A, {
469
+ key: T.label,
470
+ type: T.type || "primary",
391
471
  link: "",
392
- onClick: (M) => S.action(w)
472
+ onClick: (N) => T.action(w)
393
473
  }, {
394
- default: P(() => [
395
- q(T(S.label), 1)
474
+ default: V(() => [
475
+ Z(W(T.label), 1)
396
476
  ]),
397
477
  _: 2
398
478
  }, 1032, ["type", "onClick"]))), 128))
399
479
  ]),
400
480
  _: 1
401
- }, 16, ["label"])) : Q(s(l)) ? (g(), _(E, x({
481
+ }, 16, ["label"])) : oe(a(r)) ? (h(), _(x, B({
402
482
  key: 3,
403
- label: s(l).label,
483
+ label: a(r).label,
404
484
  align: "center"
405
- }, s(l).columnProps || {}), {
406
- default: P((w) => {
407
- var S, M, j, H;
485
+ }, a(r).columnProps || {}), {
486
+ default: V((w) => {
487
+ var T, N, Q, X;
408
488
  return [
409
- s(l).render === "slot" && y.$slots[((S = s(l)) == null ? void 0 : S.slot) || s(l).key] ? G(y.$slots, ((M = s(l)) == null ? void 0 : M.slot) || s(l).key, ee(x({ key: 0 }, w))) : s(l).render && s(v)[s(l).render] ? (g(), _(te(s(v)[s(l).render]), {
489
+ a(r).render === "slot" && u.$slots[((T = a(r)) == null ? void 0 : T.slot) || a(r).key] ? ne(u.$slots, ((N = a(r)) == null ? void 0 : N.slot) || a(r).key, ue(B({ key: 0 }, w))) : a(r).render && v.value[a(r).render] ? (h(), _(de(v.value[a(r).render]), {
410
490
  key: 1,
411
491
  row: w.row,
412
- col: s(l),
492
+ col: a(r),
413
493
  onCellChange: i,
414
494
  onCellBlur: c,
415
- onCellEnter: u,
416
- onClick: h
417
- }, null, 40, ["row", "col"])) : (g(), z("span", {
495
+ onCellEnter: d,
496
+ onClick: g
497
+ }, null, 40, ["row", "col"])) : (h(), I("span", {
418
498
  key: 2,
419
- style: le(((j = s(l).renderProps) == null ? void 0 : j.style) || ""),
420
- class: ne(((H = s(l).renderProps) == null ? void 0 : H.class) || ""),
421
- title: s(C)(w.row, s(l).key)
422
- }, T(s(C)(w.row, s(l).key)), 15, fe))
499
+ style: fe(((Q = a(r).renderProps) == null ? void 0 : Q.style) || ""),
500
+ class: me(((X = a(r).renderProps) == null ? void 0 : X.class) || ""),
501
+ title: a(b)(w.row, a(r).key)
502
+ }, W(a(b)(w.row, a(r).key)), 15, Ne))
423
503
  ];
424
504
  }),
425
505
  _: 3
426
- }, 16, ["label"])) : Z("", !0);
506
+ }, 16, ["label"])) : ce("", !0);
427
507
  };
428
508
  }
429
509
  });
430
- function Y(t, e) {
510
+ function ee(t, e) {
431
511
  if (!(e != null && e.length)) return t;
432
512
  const n = new Map(
433
- e.map((r) => [r.key, r])
513
+ e.map((o) => [o.key, o])
434
514
  );
435
- return t.map((r) => {
436
- const o = n.get(r.key);
437
- return o ? {
438
- ...r,
439
- visible: typeof o.visible == "boolean" ? o.visible : r.visible
440
- } : r;
515
+ return t.map((o) => {
516
+ const l = n.get(o.key);
517
+ return l ? {
518
+ ...o,
519
+ visible: typeof l.visible == "boolean" ? l.visible : o.visible
520
+ } : o;
441
521
  });
442
522
  }
443
- function ge(t, e) {
444
- const { cacheKey: n, storage: r = localStorage } = e || {}, o = n ? r.getItem(n) : null, l = F(
445
- Y(
523
+ function We(t, e) {
524
+ const { cacheKey: n, storage: o = localStorage } = e || {}, l = n ? o.getItem(n) : null, r = R(
525
+ ee(
446
526
  t,
447
- o ? JSON.parse(o) : []
527
+ l ? JSON.parse(l) : []
448
528
  )
449
529
  );
450
- return $(
451
- l,
530
+ return z(
531
+ r,
452
532
  (i) => {
453
533
  if (!n) return;
454
- const c = i.map((u) => ({
455
- key: u.key,
456
- visible: u.visible,
457
- columnOpts: u.columnOpts
534
+ const c = i.map((d) => ({
535
+ key: d.key,
536
+ visible: d.visible,
537
+ columnOpts: d.columnOpts
458
538
  }));
459
- r.setItem(
539
+ o.setItem(
460
540
  n,
461
541
  JSON.stringify(c)
462
542
  );
@@ -464,16 +544,16 @@ function ge(t, e) {
464
544
  { deep: !0 }
465
545
  ), {
466
546
  /** 当前列配置(响应式) */
467
- columns: l,
547
+ columns: r,
468
548
  /**
469
549
  * 主动设置列配置
470
550
  * 常用于:列设置弹窗 / 拖拽排序完成
471
551
  */
472
552
  setColumns(i) {
473
- l.value = Y(
553
+ r.value = ee(
474
554
  t,
475
555
  i
476
- ), n && r.setItem(
556
+ ), n && o.setItem(
477
557
  n,
478
558
  JSON.stringify(i)
479
559
  );
@@ -482,11 +562,11 @@ function ge(t, e) {
482
562
  * 重置为默认列配置
483
563
  */
484
564
  resetColumns() {
485
- l.value = t, n && r.removeItem(n);
565
+ r.value = t, n && o.removeItem(n);
486
566
  }
487
567
  };
488
568
  }
489
- const ve = /* @__PURE__ */ O({
569
+ const Pe = /* @__PURE__ */ M({
490
570
  __name: "index",
491
571
  props: {
492
572
  data: { type: Array, default: () => [] },
@@ -508,64 +588,145 @@ const ve = /* @__PURE__ */ O({
508
588
  "cell-click"
509
589
  ],
510
590
  setup(t, { expose: e, emit: n }) {
511
- const r = t, o = n, { columns: l } = ge(r.columns, {
512
- cacheKey: r.cacheKey ?? ""
591
+ const o = t, l = n, { columns: r } = We(o.columns, {
592
+ cacheKey: o.cacheKey ?? ""
513
593
  });
514
- $(
515
- l,
516
- (d) => o("update:columns", d),
594
+ z(
595
+ r,
596
+ (m) => l("update:columns", m),
517
597
  { deep: !0, immediate: !0 }
518
598
  );
519
- const i = (d, k) => o("cellChange", d, k), c = (d, k) => {
520
- o("cellBlur", d, k);
521
- }, u = (d, k) => {
522
- console.log("enter"), o("cellEnter", d, k);
523
- }, h = (d, k) => {
524
- k && o("cell-click", d, k);
525
- }, v = F();
599
+ const i = (m, k) => l("cellChange", m, k), c = (m, k) => {
600
+ l("cellBlur", m, k);
601
+ }, d = (m, k) => {
602
+ console.log("enter"), l("cellEnter", m, k);
603
+ }, g = (m, k) => {
604
+ k && l("cell-click", m, k);
605
+ }, v = R();
526
606
  return e({
527
607
  tableRef: v
528
- }), (d, k) => {
529
- const a = V("el-table"), m = re("loading");
530
- return oe((g(), _(a, x({
608
+ }), (m, k) => {
609
+ const s = O("el-table"), y = ye("loading");
610
+ return pe((h(), _(s, B({
531
611
  ref_key: "tableRef",
532
612
  ref: v
533
- }, d.$attrs, {
613
+ }, m.$attrs, {
534
614
  data: t.data,
535
615
  "row-key": t.rowKey,
536
616
  class: "smart-table"
537
617
  }), {
538
- default: P(() => [
539
- (g(!0), z(J, null, K(s(l), (p) => (g(), _(he, {
618
+ default: V(() => [
619
+ (h(!0), I(H, null, K(a(r), (p) => (h(), _(De, {
540
620
  key: p.key,
541
621
  col: p,
542
622
  permissions: t.permissions,
543
623
  pagination: t.pagination,
544
624
  onCellChange: i,
545
625
  onCellBlur: c,
546
- onCellEnter: u,
547
- onCellClick: h
548
- }, ie({ _: 2 }, [
549
- K(s(l), (B) => ({
550
- name: B.key,
551
- fn: P((I) => [
552
- G(d.$slots, B.key, x({ ref_for: !0 }, I), void 0, !0)
626
+ onCellEnter: d,
627
+ onCellClick: g
628
+ }, ge({ _: 2 }, [
629
+ K(a(r), (S) => ({
630
+ name: S.key,
631
+ fn: V((L) => [
632
+ ne(m.$slots, S.key, B({ ref_for: !0 }, L), void 0, !0)
553
633
  ])
554
634
  }))
555
635
  ]), 1032, ["col", "permissions", "pagination"]))), 128))
556
636
  ]),
557
637
  _: 3
558
638
  }, 16, ["data", "row-key"])), [
559
- [m, t.loading]
639
+ [y, t.loading]
560
640
  ]);
561
641
  };
562
642
  }
563
- }), Ce = (t, e) => {
643
+ }), je = (t, e) => {
564
644
  const n = t.__vccOpts || t;
565
- for (const [r, o] of e)
566
- n[r] = o;
645
+ for (const [o, l] of e)
646
+ n[o] = l;
567
647
  return n;
568
- }, we = /* @__PURE__ */ Ce(ve, [["__scopeId", "data-v-f4c8de68"]]);
648
+ }, Xe = /* @__PURE__ */ je(Pe, [["__scopeId", "data-v-f4c8de68"]]), te = {
649
+ defaultPagination: {
650
+ page: 1,
651
+ size: 10,
652
+ total: 0
653
+ },
654
+ defaultTableProps: {},
655
+ defaultColumnProps: {},
656
+ theme: {
657
+ primaryColor: "#409EFF",
658
+ successColor: "#67C23A",
659
+ warningColor: "#E6A23C",
660
+ dangerColor: "#F56C6C",
661
+ infoColor: "#909399"
662
+ }
663
+ };
664
+ class qe {
665
+ constructor() {
666
+ D(this, "config", { ...te });
667
+ }
668
+ /**
669
+ * 获取所有配置
670
+ */
671
+ getConfig() {
672
+ return { ...this.config };
673
+ }
674
+ /**
675
+ * 设置配置
676
+ */
677
+ setConfig(e) {
678
+ this.config = this.mergeConfig(this.config, e), e.renderers && J().registerMultiple(e.renderers);
679
+ }
680
+ /**
681
+ * 获取特定配置项
682
+ */
683
+ get(e) {
684
+ return this.config[e];
685
+ }
686
+ /**
687
+ * 重置为默认配置
688
+ */
689
+ reset() {
690
+ this.config = { ...te };
691
+ }
692
+ /**
693
+ * 深度合并配置
694
+ */
695
+ mergeConfig(e, n) {
696
+ const o = { ...e };
697
+ for (const l in n)
698
+ n[l] && typeof n[l] == "object" && !Array.isArray(n[l]) ? o[l] = this.mergeConfig(e[l] || {}, n[l]) : o[l] = n[l];
699
+ return o;
700
+ }
701
+ }
702
+ let j = null;
703
+ function le() {
704
+ return j || (j = new qe()), j;
705
+ }
706
+ function Ze(t) {
707
+ le().setConfig(t);
708
+ }
709
+ function et() {
710
+ return le().getConfig();
711
+ }
712
+ function tt(t, e) {
713
+ return {
714
+ key: t,
715
+ ...e
716
+ };
717
+ }
569
718
  export {
570
- we as SmartTable
719
+ Xe as SmartTable,
720
+ re as builtInRenderers,
721
+ E as createFunctionalRenderer,
722
+ Qe as createRenderer,
723
+ Xe as default,
724
+ tt as defineColumn,
725
+ J as getRendererManager,
726
+ et as getSmartTableConfig,
727
+ Ke as registerBuiltInRenderers,
728
+ Ze as setSmartTableConfig,
729
+ Ge as validateRendererProps,
730
+ Y as wrapSFCComponent
571
731
  };
732
+ //# sourceMappingURL=vue3-smart-table.es.js.map