lkt-table 1.0.13 → 1.0.15

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,27 +1,44 @@
1
- var ae = Object.defineProperty;
2
- var ne = (e, t, a) => t in e ? ae(e, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : e[t] = a;
3
- var $ = (e, t, a) => (ne(e, typeof t != "symbol" ? t + "" : t, a), a);
4
- import { defineComponent as x, openBlock as s, createElementBlock as o, createCommentVNode as C, normalizeClass as ie, Fragment as k, renderList as g, unref as v, renderSlot as B, createTextVNode as Y, toDisplayString as L, withDirectives as re, createElementVNode as p, vShow as se, useSlots as oe, ref as V, computed as I, onMounted as de, watch as Q, createBlock as N, withCtx as H, createSlots as M } from "vue";
5
- import ue from "vuedraggable";
6
- import { createLktEvent as U } from "lkt-events";
7
- import { generateRandomString as ce } from "lkt-string-tools";
8
- class Z {
9
- constructor(t = "", a = "") {
10
- $(this, "key");
11
- $(this, "label");
12
- $(this, "sortable");
13
- $(this, "hidden");
14
- $(this, "formatter");
15
- $(this, "checkEmpty");
16
- $(this, "colspan");
17
- this.key = t, this.label = a, this.sortable = !0, this.hidden = !1, this.formatter = void 0, this.checkEmpty = void 0, this.colspan = void 0;
1
+ var se = Object.defineProperty;
2
+ var ue = (e, t, l) => t in e ? se(e, t, { enumerable: !0, configurable: !0, writable: !0, value: l }) : e[t] = l;
3
+ var y = (e, t, l) => (ue(e, typeof t != "symbol" ? t + "" : t, l), l);
4
+ import { reactive as w, defineComponent as M, ref as p, watch as T, nextTick as re, resolveComponent as H, openBlock as n, createBlock as b, withCtx as O, createTextVNode as _, toDisplayString as U, unref as V, createElementBlock as h, Fragment as I, createCommentVNode as E, normalizeClass as de, renderList as $, renderSlot as R, withDirectives as ce, createElementVNode as D, vShow as me, useSlots as fe, computed as B, onMounted as he, createSlots as W } from "vue";
5
+ import ye from "vuedraggable";
6
+ import { httpCall as ve } from "lkt-http-client";
7
+ import { createLktEvent as X } from "lkt-events";
8
+ import { generateRandomString as ke } from "lkt-string-tools";
9
+ class L {
10
+ constructor(t = "", l = "") {
11
+ y(this, "key");
12
+ y(this, "label");
13
+ y(this, "sortable");
14
+ y(this, "hidden");
15
+ y(this, "editable");
16
+ y(this, "formatter");
17
+ y(this, "checkEmpty");
18
+ y(this, "colspan");
19
+ y(this, "type");
20
+ y(this, "link");
21
+ y(this, "action");
22
+ y(this, "options");
23
+ y(this, "resource");
24
+ y(this, "resourceData");
25
+ y(this, "isMultiple");
26
+ y(this, "isLoading");
27
+ y(this, "resourceLoaded");
28
+ this.key = t, this.label = l, this.sortable = !0, this.hidden = !1, this.formatter = void 0, this.checkEmpty = void 0, this.colspan = void 0, this.resource = "", this.resourceData = {}, this.isMultiple = !1, this.isLoading = !1, this.resourceLoaded = !1;
18
29
  }
19
30
  setIsSortable(t = !0) {
20
31
  return this.sortable = t, this;
21
32
  }
33
+ setIsEditable(t = !0) {
34
+ return this.editable = t, this;
35
+ }
22
36
  setIsHidden(t = !0) {
23
37
  return this.hidden = t, this;
24
38
  }
39
+ setIsLoading(t = !0) {
40
+ return this.isLoading = t, this;
41
+ }
25
42
  setFormatter(t = void 0) {
26
43
  return this.formatter = t, this;
27
44
  }
@@ -31,58 +48,205 @@ class Z {
31
48
  setColSpan(t = void 0) {
32
49
  return this.colspan = void 0, this;
33
50
  }
51
+ getHref(t) {
52
+ return typeof this.link == "function" ? this.link(t) : this.link;
53
+ }
54
+ doAction(t) {
55
+ if (typeof this.action == "function")
56
+ return this.action(t);
57
+ console.warn("No action defined");
58
+ }
59
+ defineAsLink(t) {
60
+ return this.type = "link", this.link = t, this;
61
+ }
62
+ defineAsText() {
63
+ return this.type = "text", this;
64
+ }
65
+ defineAsEmail() {
66
+ return this.type = "email", this;
67
+ }
68
+ defineAsTel() {
69
+ return this.type = "tel", this;
70
+ }
71
+ defineAsInt() {
72
+ return this.type = "int", this;
73
+ }
74
+ defineAsFloat() {
75
+ return this.type = "float", this;
76
+ }
77
+ defineAsCheck() {
78
+ return this.type = "check", this;
79
+ }
80
+ defineAsSwitch() {
81
+ return this.type = "switch", this;
82
+ }
83
+ defineAsAction(t) {
84
+ return this.type = "action", this.action = t, this;
85
+ }
86
+ defineAsSelect(t) {
87
+ return this.type = "select", this.options = t, this;
88
+ }
89
+ showLoading() {
90
+ return this.resource !== "" && !this.resourceLoaded;
91
+ }
92
+ hasToLoadResource() {
93
+ return this.resource !== "" && !this.resourceLoaded && !this.isLoading;
94
+ }
95
+ setIsMultiple(t = !0) {
96
+ return this.isMultiple = t, this;
97
+ }
98
+ setResource(t) {
99
+ return this.resource = t, this;
100
+ }
101
+ setResourceData(t) {
102
+ return this.resourceData = t, this;
103
+ }
104
+ async loadResource() {
105
+ if (this.resourceLoaded)
106
+ return this;
107
+ if (!this.resource)
108
+ return this;
109
+ try {
110
+ this.isLoading = !0;
111
+ const t = await ve(this.resource, this.resourceData);
112
+ this.options = t.data, this.isLoading = !1, this.resourceLoaded = !0;
113
+ } catch {
114
+ this.isLoading = !1;
115
+ }
116
+ return this;
117
+ }
34
118
  }
35
- const qe = (e, t, a = !0) => new Z(e, t).setIsSortable(a), Me = (e, t, a = !0) => new Z(e, t).setIsSortable(a).setIsHidden(!0), W = (e, t, a, c) => {
36
- if (!a)
119
+ const We = (e, t, l = !0) => w(new L(e, t).setIsSortable(l)), Xe = (e, t, l, i = !0) => w(new L(e, t).setIsSortable(i).defineAsLink(l)), Ye = (e, t, l, i = !0) => w(new L(e, t).setIsSortable(i).defineAsAction(l)), Ze = (e, t, l = !0) => w(new L(e, t).setIsSortable(l).defineAsText()), _e = (e, t, l = !0) => w(new L(e, t).setIsSortable(l).defineAsEmail()), et = (e, t, l = !0) => w(new L(e, t).setIsSortable(l).defineAsTel()), tt = (e, t, l = !0) => w(new L(e, t).setIsSortable(l).defineAsCheck()), lt = (e, t, l = !0) => w(new L(e, t).setIsSortable(l).defineAsSwitch()), at = (e, t, l, i = !0) => w(new L(e, t).setIsSortable(i).defineAsSelect(l)), nt = (e, t, l = !0) => w(new L(e, t).setIsSortable(l).setIsHidden(!0)), ee = (e, t, l, i) => {
120
+ if (!l)
37
121
  return 0;
38
- let f = e[a.key], n = t[a.key];
39
- if (c === "asc") {
40
- if (f > n)
122
+ let s = e[l.key], a = t[l.key];
123
+ if (i === "asc") {
124
+ if (s > a)
41
125
  return 1;
42
- if (n > f)
126
+ if (a > s)
43
127
  return -1;
44
128
  } else {
45
- if (f > n)
129
+ if (s > a)
46
130
  return -1;
47
- if (n > f)
131
+ if (a > s)
48
132
  return 1;
49
133
  }
50
134
  return 0;
51
- }, T = (e, t, a) => e.formatter && typeof e.formatter == "function" ? e.formatter(t[e.key], t, e, a) : t[e.key], fe = (e, t, a) => {
135
+ }, F = (e, t, l) => e.formatter && typeof e.formatter == "function" ? e.formatter(t[e.key], t, e, l) : t[e.key], be = (e, t, l) => {
52
136
  if (!e.colspan)
53
137
  return -1;
54
- let c = t;
55
- return a.forEach((f) => {
56
- let n = G(e, f);
57
- n > 0 && n < c && (c = n);
58
- }), c;
59
- }, G = (e, t) => e.colspan === !1 ? !1 : typeof e.colspan == "function" ? e.colspan(t) : e.colspan, me = (e, t, a) => {
138
+ let i = t;
139
+ return l.forEach((s) => {
140
+ let a = Y(e, s);
141
+ a > 0 && a < i && (i = a);
142
+ }), i;
143
+ }, Y = (e, t) => e.colspan === !1 ? !1 : typeof e.colspan == "function" ? e.colspan(t) : e.colspan, ge = (e, t, l) => {
60
144
  if (typeof e != "object" || !e.key || t.indexOf(e.key) > -1)
61
145
  return !1;
62
- let c = G(e, a);
63
- return typeof e.colspan > "u" ? !0 : (typeof e.colspan < "u" && (typeof e.colspan == "function" ? c = parseInt(e.colspan()) : c = parseInt(e.colspan)), c > 0);
64
- }, ye = (e = []) => {
146
+ let i = Y(e, l);
147
+ return typeof e.colspan > "u" ? !0 : (typeof e.colspan < "u" && (typeof e.colspan == "function" ? i = parseInt(e.colspan()) : i = parseInt(e.colspan)), i > 0);
148
+ }, Ce = (e = []) => {
65
149
  if (e.length > 0) {
66
150
  for (let t = 0; t < e.length; ++t)
67
151
  if (e[t].sortable)
68
152
  return e[t].key;
69
153
  }
70
154
  return "";
71
- }, he = (e, t) => {
155
+ }, pe = (e, t) => {
72
156
  if (e.length > 0) {
73
- for (let a = 0; a < e.length; ++a)
74
- if (e[a].key === t)
75
- return e[a];
157
+ for (let l = 0; l < e.length; ++l)
158
+ if (e[l].key === t)
159
+ return e[l];
76
160
  }
77
161
  return null;
78
- }, be = ["data-i", "data-handle-drag"], ve = {
162
+ }, Ve = { name: "LktTableCell", inheritAttrs: !1 }, le = /* @__PURE__ */ M({
163
+ ...Ve,
164
+ props: {
165
+ modelValue: { type: Object, default: () => ({}) },
166
+ column: { type: Object, default: () => ({}) },
167
+ i: { type: [Number], default: 0 }
168
+ },
169
+ emits: ["edited"],
170
+ setup(e, { emit: t }) {
171
+ const l = t, i = e, s = p(i.modelValue), a = p(s.value[i.column.key]), v = p(null), S = p(i.column.showLoading());
172
+ return T(a, () => {
173
+ const u = JSON.parse(JSON.stringify(s.value));
174
+ u[i.column.key] = a.value, l("edited", u, i.i);
175
+ }), T(() => i.modelValue, (u) => {
176
+ s.value = u, a.value = s.value[i.column.key];
177
+ }), T(() => i.column, () => {
178
+ i.column.resourceLoaded && re(() => S.value = !1);
179
+ }, { deep: !0 }), i.column.hasToLoadResource() && i.column.loadResource(), (u, r) => {
180
+ const d = H("router-link"), C = H("lkt-field-text"), K = H("lkt-field-check"), x = H("lkt-field-switch"), j = H("lkt-loader"), N = H("lkt-field-select");
181
+ return e.column.type === "link" ? (n(), b(d, {
182
+ key: 0,
183
+ to: e.column.getHref(s.value)
184
+ }, {
185
+ default: O(() => [
186
+ _(U(V(F)(e.column, s.value, e.i)), 1)
187
+ ]),
188
+ _: 1
189
+ }, 8, ["to"])) : e.column.type === "action" ? (n(), h("a", {
190
+ key: 1,
191
+ href: "#",
192
+ onClick: r[0] || (r[0] = (f) => e.column.doAction(s.value))
193
+ }, U(V(F)(e.column, s.value, e.i)), 1)) : e.column.type === "text" ? (n(), b(C, {
194
+ key: 2,
195
+ "read-mode": !e.column.editable,
196
+ ref: (f) => v.value = f,
197
+ modelValue: a.value,
198
+ "onUpdate:modelValue": r[1] || (r[1] = (f) => a.value = f)
199
+ }, null, 8, ["read-mode", "modelValue"])) : e.column.type === "email" ? (n(), b(C, {
200
+ key: 3,
201
+ "read-mode": !e.column.editable,
202
+ ref: (f) => v.value = f,
203
+ "is-email": "",
204
+ modelValue: a.value,
205
+ "onUpdate:modelValue": r[2] || (r[2] = (f) => a.value = f)
206
+ }, null, 8, ["read-mode", "modelValue"])) : e.column.type === "tel" ? (n(), b(C, {
207
+ key: 4,
208
+ "read-mode": !e.column.editable,
209
+ ref: (f) => v.value = f,
210
+ "is-tel": "",
211
+ modelValue: a.value,
212
+ "onUpdate:modelValue": r[3] || (r[3] = (f) => a.value = f)
213
+ }, null, 8, ["read-mode", "modelValue"])) : e.column.type === "check" ? (n(), b(K, {
214
+ key: 5,
215
+ "read-mode": !e.column.editable,
216
+ ref: (f) => v.value = f,
217
+ modelValue: a.value,
218
+ "onUpdate:modelValue": r[4] || (r[4] = (f) => a.value = f)
219
+ }, null, 8, ["read-mode", "modelValue"])) : e.column.type === "switch" ? (n(), b(x, {
220
+ key: 6,
221
+ "read-mode": !e.column.editable,
222
+ ref: (f) => v.value = f,
223
+ modelValue: a.value,
224
+ "onUpdate:modelValue": r[5] || (r[5] = (f) => a.value = f)
225
+ }, null, 8, ["read-mode", "modelValue"])) : e.column.type === "select" ? (n(), h(I, { key: 7 }, [
226
+ S.value ? (n(), b(j, { key: 0 })) : (n(), b(N, {
227
+ key: 1,
228
+ "read-mode": !e.column.editable,
229
+ ref: (f) => v.value = f,
230
+ modelValue: a.value,
231
+ "onUpdate:modelValue": r[6] || (r[6] = (f) => a.value = f),
232
+ resource: e.column.resource,
233
+ "resource-data": e.column.resourceData,
234
+ options: e.column.options,
235
+ multiple: e.column.isMultiple
236
+ }, null, 8, ["read-mode", "modelValue", "resource", "resource-data", "options", "multiple"]))
237
+ ], 64)) : (n(), h(I, { key: 8 }, [
238
+ _(U(V(F)(e.column, s.value, e.i)), 1)
239
+ ], 64));
240
+ };
241
+ }
242
+ }), Se = ["data-i", "data-handle-drag"], Ae = {
79
243
  key: 0,
80
244
  "data-role": "drag-indicator"
81
- }, ke = {
245
+ }, Ie = {
82
246
  key: 1,
83
247
  "data-role": "invalid-drag-indicator"
84
- }, ge = ["data-column", "colspan", "title", "onClick"], Ce = { name: "LktTableRow", inheritAttrs: !1 }, X = /* @__PURE__ */ x({
85
- ...Ce,
248
+ }, we = ["data-column", "colspan", "title", "onClick"], Le = { name: "LktTableRow", inheritAttrs: !1 }, te = /* @__PURE__ */ M({
249
+ ...Le,
86
250
  props: {
87
251
  isDraggable: { type: Boolean, default: !0 },
88
252
  sortable: { type: Boolean, default: !0 },
@@ -93,47 +257,54 @@ const qe = (e, t, a = !0) => new Z(e, t).setIsSortable(a), Me = (e, t, a = !0) =
93
257
  hiddenIsVisible: { type: Boolean, default: !1 },
94
258
  item: { type: Object, default: () => ({}) }
95
259
  },
96
- emits: ["click", "show"],
260
+ emits: ["edited", "click", "show"],
97
261
  setup(e, { emit: t }) {
98
- const a = t, c = (n, d, u) => {
99
- a("click", n, U("", { item: d, column: u }));
100
- }, f = (n, d) => {
101
- a("show", n, U("", { i: d }));
262
+ const l = t, i = e, s = p(i.item), a = (u, r, d) => {
263
+ l("click", u, X("", { item: r, column: d }));
264
+ }, v = (u, r) => {
265
+ l("show", u, X("", { i: r }));
266
+ }, S = (u, r) => {
267
+ s.value = u;
102
268
  };
103
- return (n, d) => (s(), o("tr", {
269
+ return T(() => i.item, (u) => s.value = u), T(s, () => l("edited", s.value, i.i)), (u, r) => (n(), h("tr", {
104
270
  "data-i": e.i,
105
271
  "data-handle-drag": e.isDraggable
106
272
  }, [
107
- e.sortable && e.isDraggable ? (s(), o("td", ve)) : e.sortable ? (s(), o("td", ke)) : C("", !0),
108
- e.displayHiddenColumnsIndicator ? (s(), o("td", {
273
+ e.sortable && e.isDraggable ? (n(), h("td", Ae)) : e.sortable ? (n(), h("td", Ie)) : E("", !0),
274
+ e.displayHiddenColumnsIndicator ? (n(), h("td", {
109
275
  key: 2,
110
- onClick: d[0] || (d[0] = (u) => f(u, e.i)),
276
+ onClick: r[0] || (r[0] = (d) => v(d, e.i)),
111
277
  "data-role": "show-more",
112
- class: ie(e.hiddenIsVisible ? "state-open" : "")
113
- }, null, 2)) : C("", !0),
114
- (s(!0), o(k, null, g(e.visibleColumns, (u) => (s(), o(k, null, [
115
- v(me)(u, e.emptyColumns, e.item) ? (s(), o("td", {
278
+ class: de(e.hiddenIsVisible ? "state-open" : "")
279
+ }, null, 2)) : E("", !0),
280
+ (n(!0), h(I, null, $(e.visibleColumns, (d) => (n(), h(I, null, [
281
+ V(ge)(d, e.emptyColumns, e.item) ? (n(), h("td", {
116
282
  key: 0,
117
- "data-column": u.key,
118
- colspan: v(G)(u, e.item),
119
- title: v(T)(u, e.item, e.i),
120
- onClick: (S) => c(S, e.item, u)
283
+ "data-column": d.key,
284
+ colspan: V(Y)(d, e.item),
285
+ title: V(F)(d, e.item, e.i),
286
+ onClick: (C) => a(C, e.item, d)
121
287
  }, [
122
- n.$slots[u.key] ? B(n.$slots, u.key, {
288
+ u.$slots[d.key] ? R(u.$slots, d.key, {
123
289
  key: 0,
124
- value: e.item[u.key],
290
+ value: e.item[d.key],
125
291
  item: e.item,
126
- column: u,
292
+ column: d,
127
293
  i: e.i
128
- }) : e.item ? (s(), o(k, { key: 1 }, [
129
- Y(L(v(T)(u, e.item, e.i)), 1)
130
- ], 64)) : C("", !0)
131
- ], 8, ge)) : C("", !0)
294
+ }) : e.item ? (n(), b(le, {
295
+ key: 1,
296
+ column: d,
297
+ modelValue: s.value,
298
+ "onUpdate:modelValue": r[1] || (r[1] = (C) => s.value = C),
299
+ i: e.i,
300
+ onEdited: S
301
+ }, null, 8, ["column", "modelValue", "i"])) : E("", !0)
302
+ ], 8, we)) : E("", !0)
132
303
  ], 64))), 256))
133
- ], 8, be));
304
+ ], 8, Se));
134
305
  }
135
- }), pe = { "data-role": "hidden-row" }, Se = ["colspan"], $e = ["data-column"], Ie = ["data-i"], Ve = ["data-column", "title", "onClick"], Be = { name: "LktHiddenRow", inheritAttrs: !1 }, Ee = /* @__PURE__ */ x({
136
- ...Be,
306
+ }), $e = { "data-role": "hidden-row" }, Ee = ["colspan"], De = ["data-column"], Te = ["data-i"], Be = ["data-column", "title", "onClick"], Ne = { name: "LktHiddenRow", inheritAttrs: !1 }, He = /* @__PURE__ */ M({
307
+ ...Ne,
137
308
  props: {
138
309
  isDraggable: { type: Boolean, default: !0 },
139
310
  sortable: { type: Boolean, default: !0 },
@@ -143,58 +314,62 @@ const qe = (e, t, a = !0) => new Z(e, t).setIsSortable(a), Me = (e, t, a = !0) =
143
314
  hiddenColumns: { type: Array, default: () => [] },
144
315
  emptyColumns: { type: Array, default: () => [] },
145
316
  hiddenIsVisible: { type: Boolean, default: !1 },
146
- item: { type: Object, default: () => ({}) }
317
+ modelValue: { type: Object, default: () => ({}) }
147
318
  },
148
- emits: ["click"],
319
+ emits: ["update:modelValue", "click"],
149
320
  setup(e, { emit: t }) {
150
- const a = t, c = (f, n, d) => {
151
- a("click", f, U("", { item: n, column: d }));
321
+ const l = t, i = e, s = p(i.modelValue), a = (v, S, u) => {
322
+ l("click", v, X("", { item: S, column: u }));
152
323
  };
153
- return (f, n) => re((s(), o("tr", pe, [
154
- p("td", { colspan: e.hiddenColumnsColSpan }, [
155
- p("table", null, [
156
- p("tr", null, [
157
- (s(!0), o(k, null, g(e.hiddenColumns, (d) => (s(), o("th", {
158
- "data-column": d.key
324
+ return T(() => i.modelValue, (v) => s.value = v), T(s, () => l("update:modelValue", s.value)), (v, S) => ce((n(), h("tr", $e, [
325
+ D("td", { colspan: e.hiddenColumnsColSpan }, [
326
+ D("table", null, [
327
+ D("tr", null, [
328
+ (n(!0), h(I, null, $(e.hiddenColumns, (u) => (n(), h("th", {
329
+ "data-column": u.key
159
330
  }, [
160
- p("div", null, L(d.label), 1)
161
- ], 8, $e))), 256))
331
+ D("div", null, U(u.label), 1)
332
+ ], 8, De))), 256))
162
333
  ]),
163
- p("tr", { "data-i": e.i }, [
164
- (s(!0), o(k, null, g(e.hiddenColumns, (d, u) => (s(), o("td", {
165
- "data-column": d.key,
166
- title: v(T)(d, e.item, u),
167
- onClick: (S) => c(S, e.item, d)
334
+ D("tr", { "data-i": e.i }, [
335
+ (n(!0), h(I, null, $(e.hiddenColumns, (u, r) => (n(), h("td", {
336
+ "data-column": u.key,
337
+ title: V(F)(u, s.value, r),
338
+ onClick: (d) => a(d, s.value, u)
168
339
  }, [
169
- f.$slots[d.key] ? B(f.$slots, d.key, {
340
+ v.$slots[u.key] ? R(v.$slots, u.key, {
170
341
  key: 0,
171
- value: e.item[d.key],
172
- item: e.item,
173
- column: d,
174
- i: u
175
- }) : (s(), o(k, { key: 1 }, [
176
- Y(L(v(T)(d, e.item, u)), 1)
177
- ], 64))
178
- ], 8, Ve))), 256))
179
- ], 8, Ie)
342
+ value: s.value[u.key],
343
+ item: s.value,
344
+ column: u,
345
+ i: r
346
+ }) : (n(), b(le, {
347
+ key: 1,
348
+ column: u,
349
+ modelValue: s.value,
350
+ "onUpdate:modelValue": S[0] || (S[0] = (d) => s.value = d),
351
+ i: r
352
+ }, null, 8, ["column", "modelValue", "i"]))
353
+ ], 8, Be))), 256))
354
+ ], 8, Te)
180
355
  ])
181
- ], 8, Se)
356
+ ], 8, Ee)
182
357
  ], 512)), [
183
- [se, e.hiddenIsVisible]
358
+ [me, e.hiddenIsVisible]
184
359
  ]);
185
360
  }
186
- }), De = ["data-sortable"], we = {
361
+ }), Re = ["data-sortable"], xe = {
187
362
  key: 0,
188
363
  "data-role": "drag-indicator"
189
- }, Ae = { key: 1 }, Ne = ["data-column", "data-sortable", "data-sort", "colspan", "title", "onClick"], He = { key: 1 }, Le = {
364
+ }, Oe = { key: 1 }, Ue = ["data-column", "data-sortable", "data-sort", "colspan", "title", "onClick"], Fe = { key: 1 }, Ke = {
190
365
  key: 1,
191
366
  class: "lkt-empty-table"
192
- }, Te = { name: "LktTable", inheritAttrs: !1 }, Ke = /* @__PURE__ */ x({
193
- ...Te,
367
+ }, Me = { name: "LktTable", inheritAttrs: !1 }, je = /* @__PURE__ */ M({
368
+ ...Me,
194
369
  props: {
195
370
  modelValue: { type: Array, default: () => [] },
196
371
  columns: { type: Array, default: () => [] },
197
- sorter: { type: Function, default: W },
372
+ sorter: { type: Function, default: ee },
198
373
  sortable: { type: Boolean, default: !1 },
199
374
  hideEmptyColumns: { type: Boolean, default: !1 },
200
375
  draggableChecker: { type: Function, default: (e) => !0 },
@@ -202,172 +377,185 @@ const qe = (e, t, a = !0) => new Z(e, t).setIsSortable(a), Me = (e, t, a = !0) =
202
377
  draggableItemKey: { type: String, default: "name" }
203
378
  },
204
379
  emits: ["update:modelValue", "sort", "click"],
205
- setup(e, { expose: t, emit: a }) {
206
- const c = a, f = oe(), n = e, d = {}, u = V(typeof n.sorter == "function" ? n.sorter : W), S = V(ye(n.columns)), E = V("asc"), h = V(n.modelValue), w = V(d), J = V(!1), K = ce(12), _ = I(() => h.value.length > 0), A = I(() => {
207
- if (!n.hideEmptyColumns)
380
+ setup(e, { expose: t, emit: l }) {
381
+ const i = l, s = fe(), a = e, v = {}, S = p(typeof a.sorter == "function" ? a.sorter : ee), u = p(Ce(a.columns)), r = p("asc"), d = p(a.modelValue), C = p(v), K = p(!1), x = ke(12), j = B(() => d.value.length > 0), N = B(() => {
382
+ if (!a.hideEmptyColumns)
208
383
  return [];
209
- let l = [];
210
- return n.columns.forEach((i) => {
211
- let r = i.key, m = !1;
212
- h.value.forEach((y) => {
213
- if (typeof y.checkEmpty == "function")
214
- return y.checkEmpty(y);
215
- y[r] && (m = !0);
216
- }), m || l.push(r);
217
- }), l;
218
- }), D = I(() => n.columns.filter((l) => !l.hidden)), F = I(() => n.columns.filter((l) => l.hidden)), ee = I(() => {
219
- let l = D.value.length + 1;
220
- return n.sortable && ++l, l;
221
- }), O = I(() => F.value.length > 0 && !n.sortable), te = I(() => n.columns.map((l) => l.key)), R = I(() => {
222
- let l = [];
223
- for (let i in f)
224
- te.value.indexOf(i) !== -1 && l.push(i);
225
- return l;
226
- }), le = (l) => {
227
- let i = l.target;
228
- if (typeof i.dataset.column > "u")
384
+ let o = [];
385
+ return a.columns.forEach((c) => {
386
+ let m = c.key, k = !1;
387
+ d.value.forEach((g) => {
388
+ if (typeof g.checkEmpty == "function")
389
+ return g.checkEmpty(g);
390
+ g[m] && (k = !0);
391
+ }), k || o.push(m);
392
+ }), o;
393
+ }), f = B(() => a.columns.filter((o) => !o.hidden)), z = B(() => a.columns.filter((o) => o.hidden)), ae = B(() => {
394
+ let o = f.value.length + 1;
395
+ return a.sortable && ++o, o;
396
+ }), J = B(() => z.value.length > 0 && !a.sortable), ne = B(() => a.columns.map((o) => o.key)), q = B(() => {
397
+ let o = [];
398
+ for (let c in s)
399
+ ne.value.indexOf(c) !== -1 && o.push(c);
400
+ return o;
401
+ }), ie = (o) => {
402
+ let c = o.target;
403
+ if (typeof c.dataset.column > "u")
229
404
  do
230
- i = i.parentNode;
231
- while (typeof i.dataset.column > "u" && i.tagName !== "TABLE" && i.tagName !== "body");
232
- if (i.tagName === "TD" && (i = i.parentNode, i = i.dataset.i, typeof i < "u"))
233
- return h.value[i];
234
- }, j = (l) => w.value["tr_" + l] === !0, P = (l) => {
235
- !l || l.sortable && (h.value = h.value.sort((i, r) => u.value(i, r, l, E.value)), E.value = E.value === "asc" ? "desc" : "asc", S.value = l.key, c("sort", [S.value, E.value]));
236
- }, z = (l, i) => {
237
- c("click", l, i);
238
- }, q = (l, i) => {
239
- let r = "tr_" + i.value.i;
240
- w.value[r] = typeof w.value[r] > "u" ? !0 : !w.value[r];
405
+ c = c.parentNode;
406
+ while (typeof c.dataset.column > "u" && c.tagName !== "TABLE" && c.tagName !== "body");
407
+ if (c.tagName === "TD" && (c = c.parentNode, c = c.dataset.i, typeof c < "u"))
408
+ return d.value[c];
409
+ }, G = (o) => C.value["tr_" + o] === !0, Z = (o) => {
410
+ !o || o.sortable && (d.value = d.value.sort((c, m) => S.value(c, m, o, r.value)), r.value = r.value === "asc" ? "desc" : "asc", u.value = o.key, i("sort", [u.value, r.value]));
411
+ }, P = (o, c) => {
412
+ i("click", o, c);
413
+ }, Q = (o, c) => {
414
+ let m = "tr_" + c.value.i;
415
+ C.value[m] = typeof C.value[m] > "u" ? !0 : !C.value[m];
416
+ }, oe = (o, c) => {
417
+ d.value[c] = o;
241
418
  };
242
- return de(() => {
243
- P(he(n.columns, S.value));
244
- }), Q(() => n.modelValue, (l) => h.value = l), Q(h, (l) => c("update:modelValue", l)), t({ getItemByEvent: le }), (l, i) => _.value ? (s(), o("div", {
419
+ return he(() => {
420
+ Z(pe(a.columns, u.value));
421
+ }), T(() => a.modelValue, (o) => d.value = o), T(d, (o) => {
422
+ i("update:modelValue", o);
423
+ }), t({ getItemByEvent: ie }), (o, c) => j.value ? (n(), h("div", {
245
424
  key: 0,
246
425
  class: "lkt-table",
247
426
  "data-sortable": e.sortable
248
427
  }, [
249
- p("table", null, [
250
- p("thead", null, [
251
- p("tr", null, [
252
- e.sortable ? (s(), o("th", we)) : C("", !0),
253
- O.value ? (s(), o("th", Ae)) : C("", !0),
254
- (s(!0), o(k, null, g(D.value, (r) => (s(), o(k, null, [
255
- A.value.indexOf(r.key) === -1 ? (s(), o("th", {
428
+ D("table", null, [
429
+ D("thead", null, [
430
+ D("tr", null, [
431
+ e.sortable ? (n(), h("th", xe)) : E("", !0),
432
+ J.value ? (n(), h("th", Oe)) : E("", !0),
433
+ (n(!0), h(I, null, $(f.value, (m) => (n(), h(I, null, [
434
+ N.value.indexOf(m.key) === -1 ? (n(), h("th", {
256
435
  key: 0,
257
- "data-column": r.key,
258
- "data-sortable": r.sortable === !0,
259
- "data-sort": r.sortable === !0 && S.value === r.key ? E.value : "",
260
- colspan: v(fe)(r, e.columns.length, h.value),
261
- title: r.label,
262
- onClick: (m) => P(r)
436
+ "data-column": m.key,
437
+ "data-sortable": m.sortable === !0,
438
+ "data-sort": m.sortable === !0 && u.value === m.key ? r.value : "",
439
+ colspan: V(be)(m, e.columns.length, d.value),
440
+ title: m.label,
441
+ onClick: (k) => Z(m)
263
442
  }, [
264
- p("div", null, L(r.label), 1)
265
- ], 8, Ne)) : C("", !0)
443
+ D("div", null, U(m.label), 1)
444
+ ], 8, Ue)) : E("", !0)
266
445
  ], 64))), 256))
267
446
  ])
268
447
  ]),
269
- e.sortable ? (s(), N(v(ue), {
448
+ e.sortable ? (n(), b(V(ye), {
270
449
  key: 0,
271
- modelValue: h.value,
272
- "onUpdate:modelValue": i[0] || (i[0] = (r) => h.value = r),
450
+ modelValue: d.value,
451
+ "onUpdate:modelValue": c[0] || (c[0] = (m) => d.value = m),
273
452
  move: e.checkValidDrag,
274
453
  itemKey: e.draggableItemKey,
275
- onStart: i[1] || (i[1] = (r) => J.value = !0),
276
- onEnd: i[2] || (i[2] = (r) => J.value = !1),
454
+ onStart: c[1] || (c[1] = (m) => K.value = !0),
455
+ onEnd: c[2] || (c[2] = (m) => K.value = !1),
277
456
  tag: "tbody",
278
457
  class: "lkt-sortable-table",
279
458
  handle: "[data-handle-drag]"
280
459
  }, {
281
- item: H(({ element: r, index: m }) => [
282
- (s(), N(X, {
283
- key: v(K) + "-" + m,
284
- i: m,
285
- item: r,
286
- "display-hidden-columns-indicator": O.value,
287
- "is-draggable": e.draggableChecker ? e.draggableChecker(r) : !0,
460
+ item: O(({ element: m, index: k }) => [
461
+ (n(), b(te, {
462
+ key: V(x) + "-" + k,
463
+ i: k,
464
+ item: m,
465
+ "display-hidden-columns-indicator": J.value,
466
+ "is-draggable": e.draggableChecker ? e.draggableChecker(m) : !0,
288
467
  sortable: e.sortable,
289
- "visible-columns": D.value,
290
- "empty-columns": A.value,
291
- "hidden-is-visible": j(m),
292
- onClick: z,
293
- onShow: q
294
- }, M({ _: 2 }, [
295
- g(R.value, (y) => ({
296
- name: y,
297
- fn: H((b) => [
298
- B(l.$slots, y, {
299
- item: b.item,
300
- value: b.value,
301
- column: b.column
468
+ "visible-columns": f.value,
469
+ "empty-columns": N.value,
470
+ "hidden-is-visible": G(k),
471
+ onClick: P,
472
+ onShow: Q
473
+ }, W({ _: 2 }, [
474
+ $(q.value, (g) => ({
475
+ name: g,
476
+ fn: O((A) => [
477
+ R(o.$slots, g, {
478
+ item: A.item,
479
+ value: A.value,
480
+ column: A.column
302
481
  })
303
482
  ])
304
483
  }))
305
484
  ]), 1032, ["i", "item", "display-hidden-columns-indicator", "is-draggable", "sortable", "visible-columns", "empty-columns", "hidden-is-visible"]))
306
485
  ]),
307
486
  _: 3
308
- }, 8, ["modelValue", "move", "itemKey"])) : (s(), o("tbody", He, [
309
- (s(!0), o(k, null, g(h.value, (r, m) => (s(), N(X, {
310
- key: v(K) + "-" + m,
311
- i: m,
312
- item: r,
313
- "display-hidden-columns-indicator": O.value,
314
- "is-draggable": e.draggableChecker ? e.draggableChecker(r) : !0,
487
+ }, 8, ["modelValue", "move", "itemKey"])) : (n(), h("tbody", Fe, [
488
+ (n(!0), h(I, null, $(d.value, (m, k) => (n(), b(te, {
489
+ key: V(x) + "-" + k,
490
+ i: k,
491
+ item: m,
492
+ "display-hidden-columns-indicator": J.value,
493
+ "is-draggable": e.draggableChecker ? e.draggableChecker(m) : !0,
315
494
  sortable: e.sortable,
316
- "visible-columns": D.value,
317
- "empty-columns": A.value,
318
- "hidden-is-visible": j(m),
319
- onClick: z,
320
- onShow: q
321
- }, M({ _: 2 }, [
322
- g(R.value, (y) => ({
323
- name: y,
324
- fn: H((b) => [
325
- B(l.$slots, y, {
326
- item: b.item,
327
- value: b.value,
328
- column: b.column
495
+ "visible-columns": f.value,
496
+ "empty-columns": N.value,
497
+ "hidden-is-visible": G(k),
498
+ onClick: P,
499
+ onShow: Q,
500
+ onEdited: oe
501
+ }, W({ _: 2 }, [
502
+ $(q.value, (g) => ({
503
+ name: g,
504
+ fn: O((A) => [
505
+ R(o.$slots, g, {
506
+ item: A.item,
507
+ value: A.value,
508
+ column: A.column
329
509
  })
330
510
  ])
331
511
  }))
332
512
  ]), 1032, ["i", "item", "display-hidden-columns-indicator", "is-draggable", "sortable", "visible-columns", "empty-columns", "hidden-is-visible"]))), 128)),
333
- F.value.length > 0 ? (s(!0), o(k, { key: 0 }, g(h.value, (r, m) => (s(), N(Ee, {
334
- key: v(K) + "-" + m,
335
- i: m,
336
- item: r,
337
- "hidden-columns": F.value,
338
- "hidden-columns-col-span": ee.value,
339
- "is-draggable": e.draggableChecker ? e.draggableChecker(r) : !0,
513
+ z.value.length > 0 ? (n(!0), h(I, { key: 0 }, $(d.value, (m, k) => (n(), b(He, {
514
+ key: V(x) + "-" + k,
515
+ i: k,
516
+ item: m,
517
+ "hidden-columns": z.value,
518
+ "hidden-columns-col-span": ae.value,
519
+ "is-draggable": e.draggableChecker ? e.draggableChecker(m) : !0,
340
520
  sortable: e.sortable,
341
- "visible-columns": D.value,
342
- "empty-columns": A.value,
343
- "hidden-is-visible": j(m),
344
- onClick: z,
345
- onShow: q
346
- }, M({ _: 2 }, [
347
- g(R.value, (y) => ({
348
- name: y,
349
- fn: H((b) => [
350
- B(l.$slots, y, {
351
- item: b.item,
352
- value: b.value,
353
- column: b.column
521
+ "visible-columns": f.value,
522
+ "empty-columns": N.value,
523
+ "hidden-is-visible": G(k),
524
+ onClick: P,
525
+ onShow: Q
526
+ }, W({ _: 2 }, [
527
+ $(q.value, (g) => ({
528
+ name: g,
529
+ fn: O((A) => [
530
+ R(o.$slots, g, {
531
+ item: A.item,
532
+ value: A.value,
533
+ column: A.column
354
534
  })
355
535
  ])
356
536
  }))
357
- ]), 1032, ["i", "item", "hidden-columns", "hidden-columns-col-span", "is-draggable", "sortable", "visible-columns", "empty-columns", "hidden-is-visible"]))), 128)) : C("", !0)
537
+ ]), 1032, ["i", "item", "hidden-columns", "hidden-columns-col-span", "is-draggable", "sortable", "visible-columns", "empty-columns", "hidden-is-visible"]))), 128)) : E("", !0)
358
538
  ]))
359
539
  ])
360
- ], 8, De)) : l.$slots["no-items"] ? (s(), o("div", Le, [
361
- B(l.$slots, "no-items")
362
- ])) : C("", !0);
540
+ ], 8, Re)) : o.$slots["no-items"] ? (n(), h("div", Ke, [
541
+ R(o.$slots, "no-items")
542
+ ])) : E("", !0);
363
543
  }
364
- }), Ue = {
544
+ }), it = {
365
545
  install: (e) => {
366
- e.component("lkt-table", Ke);
546
+ e.component("lkt-table", je);
367
547
  }
368
548
  };
369
549
  export {
370
- qe as createColumn,
371
- Me as createHiddenColumn,
372
- Ue as default
550
+ Ye as createActionColumn,
551
+ tt as createCheckColumn,
552
+ We as createColumn,
553
+ _e as createEmailColumn,
554
+ nt as createHiddenColumn,
555
+ Xe as createLinkColumn,
556
+ at as createSelectColumn,
557
+ lt as createSwitchColumn,
558
+ et as createTelColumn,
559
+ Ze as createTextColumn,
560
+ it as default
373
561
  };