@orchidui/core 1.8.1-115 → 1.8.1-117

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,82 +1,83 @@
1
1
  import { ref as s } from "vue";
2
- function j(w) {
3
- const { id: B, name: _, localDb: I, options: g } = w, C = s(B), n = s(_), f = s(I), m = s([]), a = s([]), r = s({
2
+ function k(m) {
3
+ const { id: L, name: w, localDb: B, options: g } = m, _ = s(L), i = s(w), u = s(B), v = s([]), o = s([]), c = s({
4
4
  page: 1,
5
5
  per_page: 10
6
- }), y = s({
6
+ }), d = s({
7
7
  total: 0,
8
8
  last_page: 0
9
- }), b = s(!1);
10
- let v = null;
11
- const p = async () => {
12
- b.value = !0, v && clearTimeout(v), v = setTimeout(async () => {
13
- let t = f.value.table(n.value);
14
- const l = T();
15
- l.filter && Object.entries(l.filter).forEach(([c, o]) => {
16
- o && Array.isArray(o) ? t = t.filter((d) => {
17
- const u = d[c];
18
- return o.some((D) => typeof D == "string" && typeof u == "string" ? u.toLowerCase().includes(D.toLowerCase()) : u === D);
19
- }) : o && typeof o == "string" ? t = t.filter((d) => {
20
- const u = d[c];
21
- return typeof u == "string" && u.toLowerCase().includes(o.toLowerCase());
22
- }) : o != null && (t = t.filter((d) => d[c] === o));
23
- }), l.sortBy && l.sortBy.length > 0 && l.sortBy.forEach((c) => {
24
- t = t.sortBy(c.column), c.direction === "desc" && (t = t.reverse());
25
- });
26
- const e = (parseInt(r.value.page) - 1) * parseInt(r.value.per_page), i = await t.offset(e).limit(parseInt(r.value.per_page)).toArray();
27
- m.value = i;
28
- const L = await t.count();
29
- y.value = {
30
- total: L,
31
- last_page: Math.ceil(L / parseInt(r.value.per_page))
32
- }, b.value = !1;
9
+ }), y = s(!1);
10
+ let b = null;
11
+ const D = () => {
12
+ let e = u.value.table(i.value);
13
+ const a = I();
14
+ return a.filter && Object.entries(a.filter).forEach(([t, l]) => {
15
+ l && (Array.isArray(l) ? e = e.filter((n) => {
16
+ const r = n[t];
17
+ return r == null ? !1 : l.some((f) => f == null ? !1 : typeof f == "string" && typeof r == "string" ? r.toLowerCase().includes(f.toLowerCase()) : r === f);
18
+ }) : typeof l == "string" ? e = e.filter((n) => {
19
+ const r = n[t];
20
+ return typeof r != "string" ? !1 : r.toLowerCase().includes(l.toLowerCase());
21
+ }) : e = e.filter((n) => n[t] === l));
22
+ }), a.sortBy && a.sortBy.length > 0 && a.sortBy.forEach((t) => {
23
+ e = e.sortBy(t.column), t.direction === "desc" && (e = e.reverse());
24
+ }), e;
25
+ }, p = async () => {
26
+ y.value = !0, b && clearTimeout(b), b = setTimeout(async () => {
27
+ const e = D(), a = (parseInt(c.value.page) - 1) * parseInt(c.value.per_page), t = await e.offset(a).limit(parseInt(c.value.per_page)).toArray();
28
+ v.value = t;
29
+ const n = await D().count();
30
+ console.log("totalField", n), d.value = {
31
+ total: n,
32
+ last_page: Math.ceil(parseInt(n) / parseInt(c.value.per_page))
33
+ }, console.log("paginationData", d.value), y.value = !1;
33
34
  }, 500);
34
- }, T = () => {
35
- const t = {}, l = (g == null ? void 0 : g.filterable_fields) ?? [];
36
- return Object.entries(r.value).forEach(([e, i]) => {
37
- l.includes(e) && i !== void 0 && i !== null && i !== "" && (t[e] = i);
35
+ }, I = () => {
36
+ const e = {}, a = (g == null ? void 0 : g.filterable_fields) ?? [];
37
+ return Object.entries(c.value).forEach(([t, l]) => {
38
+ a.includes(t) && l !== void 0 && l !== null && l !== "" && (e[t] = l);
38
39
  }), {
39
- filter: t,
40
- sortBy: a.value,
41
- pagination: y.value
40
+ filter: e,
41
+ sortBy: o.value,
42
+ pagination: d.value
42
43
  };
43
44
  };
44
45
  return {
45
46
  // State
46
- sortBy: a,
47
- localData: m,
48
- dataTableId: C,
49
- dbTablename: n,
50
- paginationData: y,
51
- isLoading: b,
47
+ sortBy: o,
48
+ localData: v,
49
+ dataTableId: _,
50
+ dbTablename: i,
51
+ paginationData: d,
52
+ isLoading: y,
52
53
  // Methods
53
- toggleSort: (t) => {
54
- const l = a.value.find((e) => e.column === t);
55
- l ? l.direction === "asc" ? a.value = a.value.map(
56
- (e) => e.column === t ? { ...e, direction: "desc" } : e
57
- ) : a.value = a.value.filter((e) => e.column !== t) : a.value = [...a.value, { column: t, direction: "asc" }], p();
54
+ toggleSort: (e) => {
55
+ const a = o.value.find((t) => t.column === e);
56
+ a ? a.direction === "asc" ? o.value = o.value.map(
57
+ (t) => t.column === e ? { ...t, direction: "desc" } : t
58
+ ) : o.value = o.value.filter((t) => t.column !== e) : o.value = [...o.value, { column: e, direction: "asc" }], p();
58
59
  },
59
- bulkPutLocalData: async (t) => {
60
- await f.value.table(n.value).bulkPut(t);
60
+ bulkPutLocalData: async (e) => {
61
+ await u.value.table(i.value).bulkPut(e);
61
62
  },
62
- bulkDeleteLocalData: async (t) => {
63
- await f.value.table(n.value).bulkDelete(t);
63
+ bulkDeleteLocalData: async (e) => {
64
+ await u.value.table(i.value).bulkDelete(e);
64
65
  },
65
66
  getLocalDataUpdatedAt: async () => {
66
- const t = await f.value.table(n.value).orderBy("updated_at").reverse().limit(1).first();
67
- return t == null ? void 0 : t.updated_at;
67
+ const e = await u.value.table(i.value).orderBy("updated_at").reverse().limit(1).first();
68
+ return e == null ? void 0 : e.updated_at;
68
69
  },
69
- getLocalDataIds: async () => await f.value.table(n.value).toCollection().primaryKeys(),
70
+ getLocalDataIds: async () => await u.value.table(i.value).toCollection().primaryKeys(),
70
71
  syncLocalData: p,
71
72
  // Setters
72
- setFilter: (t) => {
73
- r.value = { ...t }, p();
73
+ setFilter: (e) => {
74
+ c.value = { ...e }, p();
74
75
  },
75
- setSortBy: (t) => {
76
- a.value = { ...t }, p();
76
+ setSortBy: (e) => {
77
+ o.value = { ...e }, p();
77
78
  }
78
79
  };
79
80
  }
80
81
  export {
81
- j as useDataTable
82
+ k as useDataTable
82
83
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orchidui/core",
3
3
  "description": "Orchid UI, Library Vue 3 tailwind css",
4
- "version": "1.8.1-115",
4
+ "version": "1.8.1-117",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "vite build"