vs-datatable 0.3.0 → 0.5.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,11 +1,49 @@
1
- import { defineComponent as N, computed as v, createElementBlock as i, openBlock as d, createElementVNode as l, createCommentVNode as C, Fragment as B, renderList as D, normalizeClass as k, toDisplayString as m, useAttrs as ee, ref as I, watch as te, onMounted as se, onUnmounted as ae, onBeforeMount as oe, createVNode as j, renderSlot as M, normalizeStyle as le, withModifiers as Q, createTextVNode as ne } from "vue";
2
- import './index.css';const re = ["id"], ie = ["disabled"], de = {
1
+ import { defineComponent as L, computed as C, createElementBlock as g, openBlock as f, createElementVNode as n, createCommentVNode as R, Fragment as A, renderList as B, normalizeClass as S, toDisplayString as p, unref as c, ref as H, watch as F, useAttrs as W, onMounted as X, onUnmounted as Y, onBeforeMount as q, createVNode as z, renderSlot as K, isRef as N, normalizeStyle as ee, withModifiers as te, createTextVNode as se } from "vue";
2
+ import './index.css';function E(e, l) {
3
+ return l.split(".").reduce((s, t) => s?.[t], e) ?? "";
4
+ }
5
+ function k(e, l, s = "id") {
6
+ return typeof s == "function" ? s(e, l) : e[s] || l;
7
+ }
8
+ function Z(e, l, s = "id") {
9
+ return l.some(
10
+ (t) => k(t, -1, s) === k(e, -1, s)
11
+ );
12
+ }
13
+ function le(e, l) {
14
+ return e.length + (l ? 1 : 0);
15
+ }
16
+ function ae(e, l) {
17
+ if (!l.length) return e;
18
+ const s = (t, i) => i.split(".").reduce((r, o) => r?.[o], t) ?? "";
19
+ return [...e].sort((t, i) => {
20
+ for (const { field: r, order: o } of l) {
21
+ const h = s(t, r), v = s(i, r);
22
+ if (h !== v)
23
+ return o === "asc" ? h > v ? 1 : -1 : h < v ? 1 : -1;
24
+ }
25
+ return 0;
26
+ });
27
+ }
28
+ function oe(e, l, s) {
29
+ if (!s) return e;
30
+ const t = (l - 1) * s, i = t + s;
31
+ return e.slice(t, i);
32
+ }
33
+ function ne(e, l, s) {
34
+ const t = (e - 1) * l + 1, i = Math.min(e * l, s);
35
+ return { start: t, end: i };
36
+ }
37
+ function j(e, l) {
38
+ return Math.ceil(e / l);
39
+ }
40
+ const re = ["id"], ce = ["disabled"], de = {
3
41
  key: 1,
4
42
  class: "vs-pagination-ellipsis"
5
- }, ce = ["id", "onClick"], ue = {
43
+ }, ie = ["id", "onClick"], ue = {
6
44
  key: 2,
7
45
  class: "vs-pagination-ellipsis"
8
- }, ve = ["disabled"], he = /* @__PURE__ */ N({
46
+ }, ve = ["disabled"], he = /* @__PURE__ */ L({
9
47
  __name: "VsPagination",
10
48
  props: {
11
49
  modelValue: {},
@@ -16,138 +54,341 @@ import './index.css';const re = ["id"], ie = ["disabled"], de = {
16
54
  paginationClass: {}
17
55
  },
18
56
  emits: ["update:modelValue", "page-changed"],
19
- setup(o, { emit: P }) {
20
- const s = o, n = P, g = s.maxVisible ?? 3, u = v({
57
+ setup(e, { emit: l }) {
58
+ const s = e, t = l, i = s.maxVisible ?? 3, r = C({
21
59
  get: () => s.modelValue,
22
- set: (p) => {
23
- n("update:modelValue", p), n("page-changed", p);
60
+ set: (d) => {
61
+ t("update:modelValue", d), t("page-changed", d);
24
62
  }
25
- }), x = v(() => u.value <= Math.floor(g / 2) ? 1 : u.value >= f.value - Math.floor(g / 2) ? Math.max(f.value - g + 1, 1) : u.value - Math.floor(g / 2)), h = v(() => Math.min(x.value + g - 1, f.value)), f = v(() => Math.ceil(s.totalRecords / s.rowsPerPage)), S = v(() => {
26
- const p = [];
27
- for (let b = x.value; b <= h.value; b++)
28
- p.push(b);
29
- return p;
30
- }), O = (p) => {
31
- p >= 1 && p <= f.value && (u.value = p);
32
- }, $ = () => {
33
- u.value > 1 && u.value--;
34
- }, R = () => {
35
- u.value < f.value && u.value++;
63
+ }), o = C(() => r.value <= Math.floor(i / 2) ? 1 : r.value >= v.value - Math.floor(i / 2) ? Math.max(v.value - i + 1, 1) : r.value - Math.floor(i / 2)), h = C(() => Math.min(o.value + i - 1, v.value)), v = C(() => j(s.totalRecords, s.rowsPerPage)), y = C(() => {
64
+ const d = [];
65
+ for (let m = o.value; m <= h.value; m++)
66
+ d.push(m);
67
+ return d;
68
+ }), T = (d) => {
69
+ d >= 1 && d <= v.value && (r.value = d);
70
+ }, M = () => {
71
+ r.value > 1 && r.value--;
72
+ }, D = () => {
73
+ r.value < v.value && r.value++;
36
74
  };
37
- return (p, b) => (d(), i("div", {
75
+ return (d, m) => (f(), g("div", {
38
76
  class: "vs-pagination",
39
- id: o.tablename + "-pagination"
77
+ id: e.tablename + "-pagination"
40
78
  }, [
41
- l("button", {
42
- onClick: $,
79
+ n("button", {
80
+ onClick: M,
43
81
  type: "button",
44
82
  class: "vs-pagination-button vs-pagination-nav",
45
- disabled: u.value === 1
46
- }, " ‹‹ ", 8, ie),
47
- x.value > 1 ? (d(), i("button", {
83
+ disabled: r.value === 1
84
+ }, " ‹‹ ", 8, ce),
85
+ o.value > 1 ? (f(), g("button", {
48
86
  key: 0,
49
87
  type: "button",
50
88
  class: "vs-pagination-button",
51
- onClick: b[0] || (b[0] = (w) => O(1))
52
- }, " 1 ")) : C("", !0),
53
- x.value > 2 ? (d(), i("span", de, "...")) : C("", !0),
54
- (d(!0), i(B, null, D(S.value, (w) => (d(), i("button", {
55
- key: w,
89
+ onClick: m[0] || (m[0] = (a) => T(1))
90
+ }, " 1 ")) : R("", !0),
91
+ o.value > 2 ? (f(), g("span", de, "...")) : R("", !0),
92
+ (f(!0), g(A, null, B(y.value, (a) => (f(), g("button", {
93
+ key: a,
56
94
  type: "button",
57
- class: k([
95
+ class: S([
58
96
  "vs-pagination-button",
59
- { "vs-active": u.value === w }
97
+ { "vs-active": r.value === a }
60
98
  ]),
61
- id: o.tablename + "-page-" + w,
62
- onClick: (A) => O(w)
63
- }, m(w), 11, ce))), 128)),
64
- h.value < f.value - 1 ? (d(), i("span", ue, "...")) : C("", !0),
65
- h.value < f.value ? (d(), i("button", {
99
+ id: e.tablename + "-page-" + a,
100
+ onClick: (b) => T(a)
101
+ }, p(a), 11, ie))), 128)),
102
+ h.value < v.value - 1 ? (f(), g("span", ue, "...")) : R("", !0),
103
+ h.value < v.value ? (f(), g("button", {
66
104
  key: 3,
67
105
  type: "button",
68
106
  class: "vs-pagination-button",
69
- onClick: b[1] || (b[1] = (w) => O(f.value))
70
- }, m(f.value), 1)) : C("", !0),
71
- l("button", {
72
- onClick: R,
107
+ onClick: m[1] || (m[1] = (a) => T(v.value))
108
+ }, p(v.value), 1)) : R("", !0),
109
+ n("button", {
110
+ onClick: D,
73
111
  type: "button",
74
112
  class: "vs-pagination-button vs-pagination-nav",
75
- disabled: u.value === f.value
113
+ disabled: r.value === v.value
76
114
  }, " ›› ", 8, ve)
77
115
  ], 8, re));
78
116
  }
79
- }), q = (o, P) => {
80
- const s = o.__vccOpts || o;
81
- for (const [n, g] of P)
82
- s[n] = g;
117
+ }), Q = (e, l) => {
118
+ const s = e.__vccOpts || e;
119
+ for (const [t, i] of l)
120
+ s[t] = i;
83
121
  return s;
84
- }, pe = /* @__PURE__ */ q(he, [["__scopeId", "data-v-a6d89ca2"]]), ge = { class: "vs-search" }, fe = ["placeholder", "value"], be = /* @__PURE__ */ N({
122
+ }, ge = /* @__PURE__ */ Q(he, [["__scopeId", "data-v-dd26d1ca"]]), fe = { class: "vs-search" }, be = ["placeholder", "value"], me = /* @__PURE__ */ L({
85
123
  __name: "VsSearch",
86
124
  props: {
87
125
  modelValue: {},
88
126
  placeholder: {}
89
127
  },
90
128
  emits: ["update:modelValue", "input-typed"],
91
- setup(o, { emit: P }) {
92
- const s = P, n = (g) => {
93
- const u = g.target;
94
- s("update:modelValue", u.value), s("input-typed", u.value);
129
+ setup(e, { emit: l }) {
130
+ const s = l, t = (i) => {
131
+ const r = i.target;
132
+ s("update:modelValue", r.value), s("input-typed", r.value);
95
133
  };
96
- return (g, u) => (d(), i("div", ge, [
97
- u[0] || (u[0] = l("div", { class: "vs-search-icon" }, [
98
- l("svg", {
134
+ return (i, r) => (f(), g("div", fe, [
135
+ r[0] || (r[0] = n("div", { class: "vs-search-icon" }, [
136
+ n("svg", {
99
137
  viewBox: "0 0 24 24",
100
138
  fill: "currentColor"
101
139
  }, [
102
- l("path", { d: "M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" })
140
+ n("path", { d: "M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" })
103
141
  ])
104
142
  ], -1)),
105
- l("input", {
143
+ n("input", {
106
144
  type: "text",
107
145
  class: "vs-search-input",
108
- placeholder: o.placeholder,
109
- value: o.modelValue,
110
- onInput: n
111
- }, null, 40, fe)
146
+ placeholder: e.placeholder,
147
+ value: e.modelValue,
148
+ onInput: t
149
+ }, null, 40, be)
150
+ ]));
151
+ }
152
+ }), we = { class: "vs-rows-per-page" }, ye = ["value"], Ce = ["value"], ke = /* @__PURE__ */ L({
153
+ __name: "VsRowsPerPage",
154
+ props: {
155
+ modelValue: {},
156
+ options: {}
157
+ },
158
+ emits: ["update:modelValue", "rows-per-page-changed"],
159
+ setup(e, { emit: l }) {
160
+ const s = e, t = l, i = s.options ?? [10, 25, 50, 100], r = (o) => {
161
+ const h = Number(o.target.value);
162
+ t("update:modelValue", h), t("rows-per-page-changed", h);
163
+ };
164
+ return (o, h) => (f(), g("div", we, [
165
+ h[0] || (h[0] = n("span", { class: "vs-rows-label" }, "Items Per Page", -1)),
166
+ n("select", {
167
+ class: "vs-items-dropdown",
168
+ value: e.modelValue,
169
+ onChange: r
170
+ }, [
171
+ (f(!0), g(A, null, B(c(i), (v) => (f(), g("option", {
172
+ key: v,
173
+ value: v
174
+ }, p(v), 9, Ce))), 128))
175
+ ], 40, ye)
112
176
  ]));
113
177
  }
114
- }), me = { class: "vs-datatable" }, we = {
178
+ }), pe = /* @__PURE__ */ Q(ke, [["__scopeId", "data-v-dd11bb0e"]]);
179
+ function Pe(e, l, s, t) {
180
+ const i = H(1), r = H(e.sort ?? []);
181
+ F(
182
+ () => e.sort,
183
+ (d) => {
184
+ d && (r.value = [...d]);
185
+ },
186
+ { deep: !0 }
187
+ );
188
+ const o = C(
189
+ () => e.serverOptions?.sort ?? r.value ?? []
190
+ );
191
+ return {
192
+ sortedRows: C(() => {
193
+ let d = e.rows;
194
+ return o.value.length && (d = ae(e.rows, o.value)), e.rowsPerPage && (d = oe(d, s.value, t.value)), d;
195
+ }),
196
+ activeSort: o,
197
+ sortHelpers: {
198
+ isColumnSorted: (d) => o.value.some((m) => m.field === d),
199
+ getSortPriority: (d) => {
200
+ const m = o.value.find((a) => a.field === d);
201
+ return m ? m.priority ?? null : null;
202
+ },
203
+ getSortOrder: (d) => o.value.find((m) => m.field === d)?.order ?? null,
204
+ handleSort: (d, m) => {
205
+ let a = [];
206
+ e.serverOptions ? a = [...e.serverOptions.sort ?? []] : e.sort && (a = [...e.sort]);
207
+ const b = a.findIndex((P) => P.field === d);
208
+ m.shiftKey ? b === -1 ? a.push({ field: d, order: "asc" }) : a[b]?.order === "asc" ? a[b].order = "desc" : a.splice(b, 1) : b === -1 ? a = [{ field: d, order: "asc" }] : a[b]?.order === "asc" ? a = [{ field: d, order: "desc" }] : a = [], a = a.map((P, V) => ({ ...P, priority: V + 1 })), e.serverOptions ? l("update:serverOptions", { ...e.serverOptions, sort: a }) : l("update:sort", a), s.value = i.value, l("sort-changed", { sort: a });
209
+ }
210
+ }
211
+ };
212
+ }
213
+ function Se(e, l, s, t) {
214
+ const i = C({
215
+ get: () => e.serverItemsLength !== void 0 ? e.serverItemsLength : e.rows.length,
216
+ set: (y) => {
217
+ e.serverItemsLength !== void 0 && l("update:serverItemsLength", y);
218
+ }
219
+ }), r = C({
220
+ get: () => e.serverOptions?.page ?? s.value,
221
+ set: (y) => {
222
+ e.serverOptions ? l("update:serverOptions", { ...e.serverOptions, page: y }) : s.value = y;
223
+ }
224
+ }), o = C(() => {
225
+ const y = t.value;
226
+ return ne(s.value, y, i.value);
227
+ }), h = (y) => {
228
+ e.serverOptions && l("update:serverOptions", { ...e.serverOptions, page: y }), l("page-updated", y);
229
+ };
230
+ return {
231
+ currentPage: r,
232
+ totalRecords: i,
233
+ recordRange: o,
234
+ handlePageChange: h,
235
+ paginationHelpers: {
236
+ page: s,
237
+ totalRecords: i,
238
+ recordRange: o,
239
+ handlePageChange: h
240
+ }
241
+ };
242
+ }
243
+ function Re(e, l, s, t) {
244
+ const i = C({
245
+ get: () => t.value,
246
+ set: (o) => t.value = o
247
+ });
248
+ return F(t, (o) => {
249
+ const h = e.serverItemsLength ?? e.rows.length, v = j(h, o);
250
+ s.value > v ? s.value = v || 1 : s.value < 1 && (s.value = 1);
251
+ }), {
252
+ vsRowsPerPage: i,
253
+ handleRowsPerPage: (o) => {
254
+ t.value = o, l("rows-per-page-changed", o);
255
+ }
256
+ };
257
+ }
258
+ function Ve(e, l) {
259
+ const s = H(1), t = H(e.serverOptions?.rowsPerPage ?? e.rowsPerPage), { totalRecords: i, recordRange: r, handlePageChange: o } = Se(e, l, s, t), { handleRowsPerPage: h } = Re(e, l, s, t), { sortedRows: v, sortHelpers: y } = Pe(e, l, s, t);
260
+ return {
261
+ page: s,
262
+ rowsPerPage: t,
263
+ totalRecords: i,
264
+ recordRange: r,
265
+ handlePageChange: o,
266
+ handleRowsPerPage: h,
267
+ sortedRows: v,
268
+ sortHelpers: y
269
+ };
270
+ }
271
+ function xe(e, l) {
272
+ const s = H(e.itemSelected || []);
273
+ F(
274
+ () => e.itemSelected,
275
+ (a) => {
276
+ a ? s.value = [...a] : s.value = [];
277
+ },
278
+ { immediate: !0, deep: !0 }
279
+ );
280
+ const t = C({
281
+ get: () => s.value,
282
+ set: (a) => {
283
+ s.value = a, l("update:itemSelected", a);
284
+ }
285
+ }), i = C(() => e.itemSelected !== null), r = C(
286
+ () => e.rows.length > 0 && t.value.length === e.rows.length
287
+ ), o = C(() => !e.rows.length || !t.value.length ? !1 : !r.value && e.rows.some(
288
+ (a, b) => t.value.some(
289
+ (P, V) => k(P, V, e.rowKey) === k(a, b, e.rowKey)
290
+ )
291
+ )), h = (a, b) => {
292
+ const P = k(a, b, e.rowKey);
293
+ t.value.some(
294
+ (I, O) => k(I, O, e.rowKey) === P
295
+ ) ? (t.value = t.value.filter(
296
+ (I, O) => k(I, O, e.rowKey) !== P
297
+ ), l("row-deselected", a, b)) : (t.value = [...t.value, a], l("row-selected", a, b));
298
+ }, v = (a) => {
299
+ const b = a.target;
300
+ t.value = b.checked ? [...e.rows] : [], l("all-rows-selected", t.value);
301
+ };
302
+ return {
303
+ selectedItems: t,
304
+ isItemSelectedControlled: i,
305
+ isAllChecked: r,
306
+ isSomeChecked: o,
307
+ toggleRow: h,
308
+ toggleAll: v,
309
+ selectRow: (a, b) => {
310
+ Z(a, t.value, e.rowKey) || (t.value = [...t.value, a], l("row-selected", a, b));
311
+ },
312
+ deselectRow: (a, b) => {
313
+ const P = k(a, b, e.rowKey);
314
+ t.value = t.value.filter(
315
+ (V, I) => k(V, I, e.rowKey) !== P
316
+ ), l("row-deselected", a, b);
317
+ },
318
+ selectAll: () => {
319
+ t.value = [...e.rows], l("all-rows-selected", t.value);
320
+ },
321
+ deselectAll: () => {
322
+ t.value = [], l("all-rows-selected", []);
323
+ },
324
+ clearSelection: () => {
325
+ t.value = [];
326
+ },
327
+ selectionHelpers: {
328
+ selectedItems: t,
329
+ isItemSelectedControlled: i,
330
+ isAllChecked: r,
331
+ isSomeChecked: o,
332
+ toggleRow: h,
333
+ toggleAll: v
334
+ }
335
+ };
336
+ }
337
+ function $e(e) {
338
+ const l = H(""), s = (o) => {
339
+ l.value = o, e("input-typed", o);
340
+ };
341
+ return {
342
+ searchQuery: l,
343
+ onInputTyped: s,
344
+ clearSearch: () => {
345
+ l.value = "", e("input-typed", "");
346
+ },
347
+ setSearchQuery: (o) => {
348
+ l.value = o, e("input-typed", o);
349
+ },
350
+ searchHelpers: {
351
+ searchQuery: l,
352
+ onInputTyped: s
353
+ }
354
+ };
355
+ }
356
+ const Te = { class: "vs-datatable" }, Ie = {
115
357
  key: 0,
116
358
  class: "vs-search-container"
117
- }, ke = {
359
+ }, Oe = {
118
360
  ref: "tableResponsiveRef",
119
361
  class: "vs-table-wrapper"
120
- }, ye = {
362
+ }, _e = {
121
363
  key: 0,
122
364
  class: "vs-checkbox-column",
123
365
  style: { width: "5%" }
124
- }, Ce = { class: "vs-checkbox" }, Pe = ["id", "checked"], Ve = ["for"], xe = ["onClick"], Oe = { class: "vs-header-content" }, Se = { class: "vs-header-label" }, $e = {
366
+ }, De = { class: "vs-checkbox" }, He = ["id", "checked", "indeterminate"], Me = ["for"], Ae = ["onClick"], Be = { class: "vs-header-content" }, Ke = { class: "vs-header-label" }, Le = {
125
367
  key: 0,
126
368
  class: "vs-sort-icons"
127
- }, Re = {
369
+ }, ze = {
128
370
  key: 1,
129
371
  class: "vs-sort-priority"
130
- }, _e = { key: 0 }, Te = ["colspan"], Ie = { key: 1 }, Me = ["colspan"], Be = { class: "vs-no-data-message" }, De = { class: "vs-no-data-description" }, Le = ["onClick"], ze = { class: "vs-checkbox" }, He = ["id", "value", "checked", "onChange"], Ke = ["for"], Ne = ["onClick"], Ae = { class: "vs-table-footer" }, Ee = {
131
- key: 0,
132
- class: "vs-table-info"
133
- }, Ue = {
372
+ }, Ne = { key: 0 }, Fe = ["colspan"], Qe = { key: 1 }, Ue = ["colspan"], Ee = { class: "vs-no-data-message" }, Ze = { class: "vs-no-data-description" }, je = ["onClick"], Ge = { class: "vs-checkbox" }, Je = ["id", "value", "checked", "onChange"], We = ["for"], Xe = {
134
373
  key: 1,
135
- class: "vs-table-info"
136
- }, Fe = /* @__PURE__ */ N({
374
+ class: "vs-table-footer"
375
+ }, Ye = { class: "vs-footer-left" }, qe = { class: "vs-table-info" }, et = /* @__PURE__ */ L({
137
376
  __name: "VsDataTable",
138
377
  props: {
139
- rows: {},
140
- columns: {},
378
+ rows: { default: () => [] },
141
379
  itemSelected: { default: null },
142
380
  tablename: { default: "default-table" },
381
+ sort: {},
143
382
  serverItemsLength: {},
383
+ serverOptions: { default: null },
144
384
  showHeader: { type: Boolean, default: !0 },
145
385
  headerText: { default: "" },
146
386
  loading: { type: Boolean, default: !1 },
387
+ columns: {},
147
388
  showSearch: { type: Boolean, default: !0 },
148
389
  tableClass: {},
149
390
  rowClass: {},
150
- showRowEntries: { type: Boolean, default: !0 },
391
+ showFooter: { type: Boolean, default: !0 },
151
392
  containerClass: {},
152
393
  headerClass: {},
153
394
  cellClass: {},
@@ -159,262 +400,223 @@ import './index.css';const re = ["id"], ie = ["disabled"], de = {
159
400
  noDataDescription: { default: "Try adjusting your search criteria" },
160
401
  entriesText: { default: "entries" },
161
402
  maxVisiblePages: { default: 5 },
162
- rowKey: { type: [String, Function], default: "id" },
163
- sort: {},
164
- serverOptions: {}
403
+ rowsPerPage: { default: 10 },
404
+ rowKey: { type: [String, Function], default: "id" }
165
405
  },
166
- emits: ["table:before-mount", "table:mounted", "table:unmounted", "data-loaded", "data-error", "row-selected", "row-deselected", "row-toggled", "rows-toggled", "all-rows-selected", "cell-click", "update:itemSelected", "update:serverItemsLength", "input-typed", "page-updated", "row-click", "sort-changed", "update:sort", "update:serverOptions"],
167
- setup(o, { emit: P }) {
168
- const s = o, n = P, g = ee(), u = v(() => s.columns.length + (H.value ? 1 : 0)), x = v(() => !!g.onRowClick), h = (t, a) => typeof s.rowKey == "function" ? s.rowKey(t, a ?? -1) : t[s.rowKey] || a, f = (t) => y.value.some((a) => h(a, -1) === h(t, -1));
169
- function S(t, a) {
170
- return a.split(".").reduce((e, r) => e?.[r], t) ?? "";
171
- }
172
- const O = (t) => b.value.some((a) => a.field === t), $ = (t) => {
173
- const a = b.value.find((e) => e.field === t);
174
- return a ? a.priority ?? null : null;
175
- }, R = (t) => b.value.find((a) => a.field === t)?.order ?? null, p = I(s.sort ?? []);
176
- te(
177
- () => s.sort,
178
- (t) => {
179
- t && (p.value = [...t]);
180
- },
181
- { deep: !0 }
406
+ emits: ["update:itemSelected", "update:serverItemsLength", "update:serverOptions", "update:sort", "input-typed", "page-updated", "sort-changed", "row-click", "row-selected", "row-deselected", "all-rows-selected", "table:mounted", "table:unmounted", "table:before-mount", "data-loaded", "data-error"],
407
+ setup(e, { emit: l }) {
408
+ const s = e, t = l, i = W(), r = C(() => !!i.onRowClick), {
409
+ page: o,
410
+ rowsPerPage: h,
411
+ totalRecords: v,
412
+ recordRange: y,
413
+ handlePageChange: T,
414
+ handleRowsPerPage: M,
415
+ sortedRows: D,
416
+ sortHelpers: d
417
+ } = Ve(s, t), {
418
+ selectedItems: m,
419
+ isItemSelectedControlled: a,
420
+ isAllChecked: b,
421
+ isSomeChecked: P,
422
+ toggleAll: V,
423
+ toggleRow: I
424
+ } = xe(s, t), { searchQuery: O, onInputTyped: G } = $e(t), U = C(
425
+ () => le(s.columns, a.value)
182
426
  );
183
- const b = v(() => s.serverOptions?.sort ?? p.value ?? []), w = v(() => {
184
- if (s.serverOptions)
185
- return s.rows;
186
- const t = s.sort ?? [];
187
- if (!t.length) return s.rows;
188
- const a = (e, r) => r.split(".").reduce((c, V) => c?.[V], e) ?? "";
189
- return [...s.rows].sort((e, r) => {
190
- for (const { field: c, order: V } of t) {
191
- const T = a(e, c), K = a(r, c);
192
- if (T !== K)
193
- return V === "asc" ? T > K ? 1 : -1 : T < K ? 1 : -1;
194
- }
195
- return 0;
196
- });
197
- }), A = (t, a) => {
198
- let e = [];
199
- s.serverOptions ? e = [...s.serverOptions.sort ?? []] : s.sort && (e = [...s.sort]);
200
- const r = e.findIndex((c) => c.field === t);
201
- a.shiftKey ? r === -1 ? e.push({ field: t, order: "asc" }) : e[r]?.order === "asc" ? e[r].order = "desc" : e.splice(r, 1) : r === -1 ? e = [{ field: t, order: "asc" }] : e[r]?.order === "asc" ? e = [{ field: t, order: "desc" }] : e = [], e = e.map((c, V) => ({ ...c, priority: V + 1 })), s.serverOptions ? n("update:serverOptions", { ...s.serverOptions, sort: e }) : n("update:sort", e), n("sort-changed", { sort: e });
202
- }, E = I(""), G = (t) => n("input-typed", t), U = I(10), J = v({
203
- get: () => s.serverOptions?.rowsPerPage ?? U.value,
204
- set: (t) => {
205
- s.serverOptions ? n("update:serverOptions", { ...s.serverOptions, rowsPerPage: t }) : U.value = t;
206
- }
207
- }), F = I(1), L = v({
208
- get: () => s.serverItemsLength !== void 0 ? s.serverItemsLength : s.rows.length,
209
- set: (t) => {
210
- s.serverItemsLength !== void 0 && n("update:serverItemsLength", t);
211
- }
212
- }), _ = v({
213
- get: () => s.serverOptions?.page ?? F.value,
214
- set: (t) => {
215
- s.serverOptions ? n("update:serverOptions", { ...s.serverOptions, page: t }) : F.value = t;
216
- }
217
- }), W = (t) => {
218
- s.serverOptions && n("update:serverOptions", { ...s.serverOptions, page: t }), n("page-updated", t);
219
- }, z = v(() => {
220
- const t = s.serverOptions?.rowsPerPage ?? 10, a = (_.value - 1) * t + 1, e = Math.min(_.value * t, L.value);
221
- return { start: a, end: e };
222
- }), y = v({
223
- get: () => s.itemSelected || [],
224
- set: (t) => n("update:itemSelected", t)
225
- }), H = v(() => s.itemSelected !== null), Z = v(
226
- () => s.rows.length > 0 && y.value.length === s.rows.length
227
- ), X = (t, a, e) => {
228
- e.target.checked ? (y.value.some((c) => h(c) === h(t)) || y.value.push(t), n("row-selected", t, a)) : (y.value = y.value.filter(
229
- (c) => h(c) !== h(t)
230
- ), n("row-deselected", t, a));
231
- }, Y = () => {
232
- y.value = Z.value ? [] : [...s.rows], n("all-rows-selected", y.value);
233
- };
234
- return se(() => {
235
- n("table:mounted");
427
+ return X(() => {
428
+ t("table:mounted");
236
429
  try {
237
- n("data-loaded", s.rows);
238
- } catch (t) {
239
- n("data-error", t);
430
+ t("data-loaded", s.rows);
431
+ } catch (_) {
432
+ t("data-error", _);
240
433
  }
241
- }), ae(() => {
242
- n("table:unmounted");
243
- }), oe(() => {
244
- n("table:before-mount");
245
- }), (t, a) => (d(), i("div", me, [
246
- o.showSearch ? (d(), i("div", we, [
247
- j(be, {
248
- modelValue: E.value,
249
- "onUpdate:modelValue": a[0] || (a[0] = (e) => E.value = e),
250
- onInputTyped: G,
251
- placeholder: o.searchPlaceholder,
252
- class: k(o.searchClass)
253
- }, null, 8, ["modelValue", "placeholder", "class"]),
254
- M(t.$slots, "filterArea", {}, void 0, !0)
255
- ])) : C("", !0),
256
- l("div", {
257
- class: k(["vs-table-container", o.containerClass])
434
+ }), Y(() => {
435
+ t("table:unmounted");
436
+ }), q(() => {
437
+ t("table:before-mount");
438
+ }), (_, w) => (f(), g("div", Te, [
439
+ e.showSearch ? (f(), g("div", Ie, [
440
+ z(me, {
441
+ modelValue: c(O),
442
+ "onUpdate:modelValue": w[0] || (w[0] = (u) => N(O) ? O.value = u : null),
443
+ onInputTyped: c(G),
444
+ placeholder: e.searchPlaceholder,
445
+ class: S(e.searchClass)
446
+ }, null, 8, ["modelValue", "onInputTyped", "placeholder", "class"]),
447
+ K(_.$slots, "filterArea", {}, void 0, !0)
448
+ ])) : R("", !0),
449
+ n("div", {
450
+ class: S(["vs-table-container", e.containerClass])
258
451
  }, [
259
- l("div", ke, [
260
- l("table", {
261
- class: k(["vs-table", o.tableClass])
452
+ n("div", Oe, [
453
+ n("table", {
454
+ class: S(["vs-table", e.tableClass])
262
455
  }, [
263
- l("thead", null, [
264
- l("tr", null, [
265
- H.value ? (d(), i("th", ye, [
266
- l("div", Ce, [
267
- l("input", {
456
+ n("thead", null, [
457
+ n("tr", null, [
458
+ c(a) ? (f(), g("th", _e, [
459
+ n("div", De, [
460
+ n("input", {
268
461
  type: "checkbox",
269
- id: o.tablename + "-main-checkbox",
270
- checked: Z.value,
271
- onChange: Y
272
- }, null, 40, Pe),
273
- l("label", {
274
- for: o.tablename + "-main-checkbox"
275
- }, null, 8, Ve)
462
+ id: e.tablename + "-main-checkbox",
463
+ checked: c(b),
464
+ indeterminate: c(P),
465
+ onChange: w[1] || (w[1] = //@ts-ignore
466
+ (...u) => c(V) && c(V)(...u))
467
+ }, null, 40, He),
468
+ n("label", {
469
+ for: e.tablename + "-main-checkbox"
470
+ }, null, 8, Me)
276
471
  ])
277
- ])) : C("", !0),
278
- (d(!0), i(B, null, D(o.columns, (e) => (d(), i("th", {
279
- key: e.field,
280
- onClick: (r) => e.sortable ? A(e.field, r) : null,
281
- style: le({ width: e.width + "%" }),
282
- class: k([e.sortable ? "vs-sortable" : "", o.headerClass])
472
+ ])) : R("", !0),
473
+ (f(!0), g(A, null, B(e.columns, (u) => (f(), g("th", {
474
+ key: u.field,
475
+ onClick: (x) => u.sortable ? c(d).handleSort(u.field, x) : null,
476
+ style: ee({ width: u.width + "%" }),
477
+ class: S([u.sortable ? "vs-sortable" : "", e.headerClass])
283
478
  }, [
284
- M(t.$slots, `header-${e.field}`, { column: e }, () => [
285
- l("div", Oe, [
286
- l("span", Se, m(e.label), 1),
287
- e.sortable ? (d(), i("div", $e, [
288
- l("span", {
289
- class: k(["vs-sort-icon vs-sort-asc", {
290
- "vs-active": O(e.field) && R(e.field) === "asc"
479
+ K(_.$slots, `header-${u.field}`, { column: u }, () => [
480
+ n("div", Be, [
481
+ n("span", Ke, p(u.label), 1),
482
+ u.sortable ? (f(), g("div", Le, [
483
+ n("span", {
484
+ class: S(["vs-sort-icon vs-sort-asc", {
485
+ "vs-active": c(d).isColumnSorted(u.field) && c(d).getSortOrder(u.field) === "asc"
291
486
  }])
292
- }, [...a[3] || (a[3] = [
293
- l("svg", {
487
+ }, [...w[5] || (w[5] = [
488
+ n("svg", {
294
489
  xmlns: "http://www.w3.org/2000/svg",
295
490
  height: "24px",
296
491
  viewBox: "0 -960 960 960",
297
492
  width: "24px"
298
493
  }, [
299
- l("path", { d: "m280-400 200-200 200 200H280Z" })
494
+ n("path", { d: "m280-400 200-200 200 200H280Z" })
300
495
  ], -1)
301
496
  ])], 2),
302
- l("span", {
303
- class: k(["vs-sort-icon vs-sort-desc", {
304
- "vs-active": O(e.field) && R(e.field) === "desc"
497
+ n("span", {
498
+ class: S(["vs-sort-icon vs-sort-desc", {
499
+ "vs-active": c(d).isColumnSorted(u.field) && c(d).getSortOrder(u.field) === "desc"
305
500
  }])
306
- }, [...a[4] || (a[4] = [
307
- l("svg", {
501
+ }, [...w[6] || (w[6] = [
502
+ n("svg", {
308
503
  xmlns: "http://www.w3.org/2000/svg",
309
504
  height: "24px",
310
505
  viewBox: "0 -960 960 960",
311
506
  width: "24px"
312
507
  }, [
313
- l("path", { d: "M480-360 280-560h400L480-360Z" })
508
+ n("path", { d: "M480-360 280-560h400L480-360Z" })
314
509
  ], -1)
315
510
  ])], 2)
316
- ])) : C("", !0),
317
- $(e.field) !== null ? (d(), i("span", Re, m($(e.field)), 1)) : C("", !0)
511
+ ])) : R("", !0),
512
+ c(d).getSortPriority(u.field) !== null ? (f(), g("span", ze, p(c(d).getSortPriority(u.field)), 1)) : R("", !0)
318
513
  ])
319
514
  ], !0)
320
- ], 14, xe))), 128))
515
+ ], 14, Ae))), 128))
321
516
  ])
322
517
  ]),
323
- l("tbody", null, [
324
- o.loading ? (d(), i("tr", _e, [
325
- l("td", {
326
- colspan: u.value,
518
+ n("tbody", null, [
519
+ e.loading ? (f(), g("tr", Ne, [
520
+ n("td", {
521
+ colspan: U.value,
327
522
  class: "vs-loading"
328
523
  }, [
329
- a[5] || (a[5] = l("div", { class: "vs-spinner" }, null, -1)),
330
- l("span", null, m(o.loadingText), 1)
331
- ], 8, Te)
332
- ])) : w.value.length ? (d(!0), i(B, { key: 2 }, D(w.value, (e, r) => (d(), i("tr", {
333
- key: h(e, r),
334
- class: k([
335
- o.rowClass,
336
- { "vs-row-clickable": x.value },
337
- { "vs-row-selected": f(e) }
524
+ w[7] || (w[7] = n("div", { class: "vs-spinner" }, null, -1)),
525
+ n("span", null, p(e.loadingText), 1)
526
+ ], 8, Fe)
527
+ ])) : c(D).length ? (f(!0), g(A, { key: 2 }, B(c(D), (u, x) => (f(), g("tr", {
528
+ key: c(k)(u, x),
529
+ class: S([
530
+ e.rowClass,
531
+ { "vs-row-clickable": r.value },
532
+ { "vs-row-selected": c(Z)(u, c(m), e.rowKey) }
338
533
  ]),
339
- onClick: (c) => t.$emit("row-click", e, r)
534
+ onClick: ($) => _.$emit("row-click", u, x)
340
535
  }, [
341
- H.value ? (d(), i("td", {
536
+ c(a) ? (f(), g("td", {
342
537
  key: 0,
343
- onClick: a[1] || (a[1] = Q(() => {
538
+ onClick: w[2] || (w[2] = te(() => {
344
539
  }, ["stop"])),
345
540
  class: "vs-checkbox-column"
346
541
  }, [
347
- l("div", ze, [
348
- l("input", {
542
+ n("div", Ge, [
543
+ n("input", {
349
544
  type: "checkbox",
350
- id: o.tablename + "-checkbox-" + h(e, r),
351
- value: e,
352
- checked: y.value.some((c) => h(c) === h(e, r)),
353
- onChange: (c) => X(e, r, c)
354
- }, null, 40, He),
355
- l("label", {
356
- for: o.tablename + "-checkbox-" + h(e, r)
357
- }, null, 8, Ke)
545
+ id: e.tablename + "-checkbox-" + c(k)(u, x),
546
+ value: u,
547
+ checked: c(m).some(($, J) => c(k)($, J) === c(k)(u, x)),
548
+ onChange: ($) => c(I)(u, x)
549
+ }, null, 40, Je),
550
+ n("label", {
551
+ for: e.tablename + "-checkbox-" + c(k)(u, x)
552
+ }, null, 8, We)
358
553
  ])
359
- ])) : C("", !0),
360
- (d(!0), i(B, null, D(o.columns, (c, V) => (d(), i("td", {
361
- key: V,
362
- class: k(o.cellClass),
363
- onClick: Q((T) => n("cell-click", t.row, c, r), ["stop"])
554
+ ])) : R("", !0),
555
+ (f(!0), g(A, null, B(e.columns, ($) => (f(), g("td", {
556
+ key: $.field,
557
+ class: S(e.cellClass)
364
558
  }, [
365
- M(t.$slots, `cell-${c.field}`, {
366
- item: e,
367
- value: S(e, c.field),
368
- column: c,
369
- index: r
559
+ K(_.$slots, `cell-${$.field}`, {
560
+ item: u,
561
+ value: c(E)(u, $.field),
562
+ column: $,
563
+ index: x
370
564
  }, () => [
371
- ne(m(S(e, c.field)), 1)
565
+ se(p(c(E)(u, $.field)), 1)
372
566
  ], !0)
373
- ], 10, Ne))), 128))
374
- ], 10, Le))), 128)) : (d(), i("tr", Ie, [
375
- l("td", {
376
- colspan: u.value,
567
+ ], 2))), 128))
568
+ ], 10, je))), 128)) : (f(), g("tr", Qe, [
569
+ n("td", {
570
+ colspan: U.value,
377
571
  class: "vs-no-data"
378
572
  }, [
379
- M(t.$slots, "no-data", {}, () => [
380
- a[6] || (a[6] = l("div", { class: "vs-no-data-icon" }, [
381
- l("svg", {
573
+ K(_.$slots, "no-data", {}, () => [
574
+ w[8] || (w[8] = n("div", { class: "vs-no-data-icon" }, [
575
+ n("svg", {
382
576
  viewBox: "0 0 24 24",
383
577
  fill: "currentColor"
384
578
  }, [
385
- l("path", { d: "M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-5 14H7v-2h7v2zm3-4H7v-2h10v2zm0-4H7V7h10v2z" })
579
+ n("path", { d: "M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-5 14H7v-2h7v2zm3-4H7v-2h10v2zm0-4H7V7h10v2z" })
386
580
  ])
387
581
  ], -1)),
388
- l("div", Be, m(o.noDataText), 1),
389
- l("div", De, m(o.noDataDescription), 1)
582
+ n("div", Ee, p(e.noDataText), 1),
583
+ n("div", Ze, p(e.noDataDescription), 1)
390
584
  ], !0)
391
- ], 8, Me)
585
+ ], 8, Ue)
392
586
  ]))
393
587
  ])
394
588
  ], 2)
395
589
  ], 512)
396
590
  ], 2),
397
- l("div", Ae, [
398
- o.showRowEntries ? (d(), i("div", Ee, " showing " + m(z.value.start < 1 ? 0 : z.value.start) + " - " + m(z.value.end) + " of " + m(L.value) + " " + m(o.entriesText), 1)) : (d(), i("div", Ue)),
399
- j(pe, {
400
- modelValue: _.value,
401
- "onUpdate:modelValue": a[2] || (a[2] = (e) => _.value = e),
402
- totalRecords: L.value,
403
- rowsPerPage: J.value,
404
- maxVisible: o.maxVisiblePages,
405
- tablename: o.tablename,
406
- class: k(o.paginationClass),
407
- onPageChanged: W
408
- }, null, 8, ["modelValue", "totalRecords", "rowsPerPage", "maxVisible", "tablename", "class"])
409
- ])
591
+ e.showFooter ? (f(), g("div", Xe, [
592
+ n("div", Ye, [
593
+ z(pe, {
594
+ modelValue: c(h),
595
+ "onUpdate:modelValue": w[3] || (w[3] = (u) => N(h) ? h.value = u : null),
596
+ onRowsPerPageChanged: c(M)
597
+ }, null, 8, ["modelValue", "onRowsPerPageChanged"]),
598
+ w[9] || (w[9] = n("div", { class: "vs-divider" }, null, -1)),
599
+ n("div", qe, p(c(y).start < 1 ? 0 : c(y).start) + " - " + p(c(y).end) + " of " + p(c(v)) + " " + p(e.entriesText), 1)
600
+ ]),
601
+ z(ge, {
602
+ modelValue: c(o),
603
+ "onUpdate:modelValue": w[4] || (w[4] = (u) => N(o) ? o.value = u : null),
604
+ totalRecords: c(v),
605
+ rowsPerPage: c(h),
606
+ maxVisible: e.maxVisiblePages,
607
+ tablename: e.tablename,
608
+ class: S(e.paginationClass),
609
+ onPageChanged: c(T)
610
+ }, null, 8, ["modelValue", "totalRecords", "rowsPerPage", "maxVisible", "tablename", "class", "onPageChanged"])
611
+ ])) : R("", !0)
410
612
  ]));
411
613
  }
412
- }), Ze = /* @__PURE__ */ q(Fe, [["__scopeId", "data-v-fa66e546"]]), Qe = {
413
- install(o) {
414
- o.component("VsDataTable", Ze);
614
+ }), tt = /* @__PURE__ */ Q(et, [["__scopeId", "data-v-b1f39b67"]]), lt = {
615
+ install(e) {
616
+ e.component("VsDataTable", tt);
415
617
  }
416
618
  };
417
619
  export {
418
- Ze as VsDataTable,
419
- Qe as default
620
+ tt as VsDataTable,
621
+ lt as default
420
622
  };