@starter-solutions/inertia-data-table-vue 0.4.1 → 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.
- package/dist/composables/useDataTable.d.ts +2 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +95 -90
- package/package.json +1 -1
|
@@ -20,4 +20,6 @@ export declare const useDataTable: <T>(tableKey: MaybeRefOrGetter<string>, optio
|
|
|
20
20
|
}>) => void;
|
|
21
21
|
removeFilter: (key: string) => void;
|
|
22
22
|
resetFilters: () => void;
|
|
23
|
+
additional: import('vue').ComputedRef<Record<string, any>>;
|
|
24
|
+
getAdditional: (key: string, defaultValue?: any) => any;
|
|
23
25
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("@inertiajs/vue3"),l=require("vue"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("@inertiajs/vue3"),l=require("vue"),k=(e,u)=>{const o=m.usePage(),r=l.computed(()=>{const a=l.toValue(u),_=l.toValue(e),p=l.toValue(a==null?void 0:a.pagePropsKey)??_,n=l.toValue(a==null?void 0:a.useUrlQuery)??!1,y=l.toValue(a==null?void 0:a.reloadOnly)?[p,...l.toValue(a==null?void 0:a.reloadOnly)]:[p];return{tableKey:_,pagePropsKey:p,useUrlQuery:n,reloadOnly:y}}),g=l.computed(()=>o.props.inertiaDataTable.stateRoutes),d=l.computed(()=>o.props.inertiaDataTable.queryParams),s=l.computed(()=>o.props.inertiaDataTable.defaults);return{settings:r,stateRoutes:g,queryParams:d,defaults:s}},O=e=>{const u=l.computed(()=>R(l.toValue(e))),o=l.computed(()=>u.value.data),r=l.computed(()=>u.value.pagination);return{data:o,pagination:r,getPaginatedRequest:(s={})=>({page:s.page??r.value.current_page,per_page:s.per_page??r.value.per_page,sort_by:s.sort_by??r.value.sort_by,descending:s.descending??r.value.descending}),validPage:s=>s>0&&s<=r.value.last_page}},R=e=>({data:(e==null?void 0:e.data)??[],pagination:V(e)}),q=e=>"meta"in e&&typeof e.meta=="object"&&e.meta!==null,V=e=>{if(!e)return{current_page:1,last_page:1,per_page:10,total:0,from:null,to:null,path:"",links:[],first_page_url:null,last_page_url:null,next_page_url:null,prev_page_url:null,sort_by:"id",descending:!1};if(q(e))return{current_page:e.meta.current_page,last_page:e.meta.last_page,per_page:e.meta.per_page,total:e.meta.total,from:e.meta.from,to:e.meta.to,path:e.meta.path,links:e.meta.links,first_page_url:e.links.first,last_page_url:e.links.last,next_page_url:e.links.next,prev_page_url:e.links.prev,sort_by:e.meta.sort_by??"id",descending:e.meta.descending??!1};const{current_page:u,last_page:o,per_page:r,total:g,from:d,to:s,path:a,links:_,first_page_url:p,last_page_url:n,next_page_url:y,prev_page_url:f,sort_by:P,descending:K}=e;return{current_page:u,last_page:o,per_page:r,total:g,from:d,to:s,path:a,links:_,first_page_url:p,last_page_url:n,next_page_url:y,prev_page_url:f,sort_by:P??"id",descending:K??!1}},j=(e,u)=>{const{stateRoutes:o,settings:r}=k(e,u);l.onBeforeUnmount(()=>{m.router.delete(o.value.drop,{preserveScroll:!0,preserveState:!0,data:{tableKey:r.value.tableKey}})});const g=m.usePage(),d=l.computed(()=>g.props[r.value.pagePropsKey]??null),{data:s,pagination:a,getPaginatedRequest:_,validPage:p}=O(d),n=t=>{t=_(t),r.value.useUrlQuery?m.router.reload({only:r.value.reloadOnly,data:{tableKey:r.value.tableKey,filter:c,...t}}):m.router.post(o.value.set,{tableKey:r.value.tableKey,filter:c,pagination:t},{preserveState:!0,preserveScroll:!0,only:r.value.reloadOnly})},y=()=>{v(1)},f=()=>{v(a.value.current_page-1)},P=()=>{v(a.value.current_page+1)},K=()=>{v(a.value.last_page)},v=t=>{if(!p(t)){console.error(`Invalid page: ${t}`);return}n({page:t})},h=t=>{n({per_page:t,page:1})},S=(t,i)=>{const b=i??a.value.sort_by===t?!a.value.descending:!1;n({sort_by:t,descending:b})},c=l.reactive({}),x=(t,i)=>{c[t]=i,n({page:1})},I=t=>{t.forEach(({key:i,value:b})=>{c[i]=b}),n({page:1})},U=t=>{delete c[t],n({page:1})},F=()=>{Object.keys(c).forEach(t=>delete c[t]),n({page:1})},T=l.computed(()=>g.props[r.value.pagePropsKey].additional);return{data:s,reload:n,pagination:a,firstPage:y,previousPage:f,nextPage:P,lastPage:K,goToPage:v,itemsPerPage:h,sortBy:S,filter:c,setFilter:x,setFilters:I,removeFilter:U,resetFilters:F,additional:T,getAdditional:(t,i=void 0)=>t.split(".").reduce((D,Q)=>D==null?void 0:D[Q],T.value)??i}};function z(){return{install(e){}}}exports.createInertiaDataTable=z;exports.getPaginationMeta=V;exports.isResource=q;exports.normalizePagination=R;exports.useDataTable=j;exports.useInertiaDataTableConfig=k;exports.useLaravelPagination=O;
|
package/dist/index.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { usePage as
|
|
2
|
-
import { computed as
|
|
3
|
-
const
|
|
4
|
-
const n =
|
|
5
|
-
const
|
|
1
|
+
import { usePage as R, router as D } from "@inertiajs/vue3";
|
|
2
|
+
import { computed as o, toValue as _, onBeforeUnmount as S, reactive as I } from "vue";
|
|
3
|
+
const j = (e, u) => {
|
|
4
|
+
const n = R(), r = o(() => {
|
|
5
|
+
const a = _(u), y = _(e), g = _(a == null ? void 0 : a.pagePropsKey) ?? y, s = _(a == null ? void 0 : a.useUrlQuery) ?? !1, v = _(a == null ? void 0 : a.reloadOnly) ? [g, ..._(a == null ? void 0 : a.reloadOnly)] : [g];
|
|
6
6
|
return {
|
|
7
7
|
tableKey: y,
|
|
8
8
|
pagePropsKey: g,
|
|
9
9
|
useUrlQuery: s,
|
|
10
10
|
reloadOnly: v
|
|
11
11
|
};
|
|
12
|
-
}),
|
|
12
|
+
}), p = o(
|
|
13
13
|
() => n.props.inertiaDataTable.stateRoutes
|
|
14
|
-
),
|
|
14
|
+
), d = o(
|
|
15
15
|
() => n.props.inertiaDataTable.queryParams
|
|
16
|
-
), l =
|
|
16
|
+
), l = o(
|
|
17
17
|
() => n.props.inertiaDataTable.defaults
|
|
18
18
|
);
|
|
19
19
|
return {
|
|
20
20
|
settings: r,
|
|
21
|
-
stateRoutes:
|
|
22
|
-
queryParams:
|
|
21
|
+
stateRoutes: p,
|
|
22
|
+
queryParams: d,
|
|
23
23
|
defaults: l
|
|
24
24
|
};
|
|
25
|
-
},
|
|
26
|
-
const
|
|
27
|
-
() =>
|
|
25
|
+
}, z = (e) => {
|
|
26
|
+
const u = o(() => A(_(e))), n = o(() => u.value.data), r = o(
|
|
27
|
+
() => u.value.pagination
|
|
28
28
|
);
|
|
29
29
|
return {
|
|
30
30
|
data: n,
|
|
@@ -37,10 +37,10 @@ const h = (e, o) => {
|
|
|
37
37
|
}),
|
|
38
38
|
validPage: (l) => l > 0 && l <= r.value.last_page
|
|
39
39
|
};
|
|
40
|
-
},
|
|
40
|
+
}, A = (e) => ({
|
|
41
41
|
data: (e == null ? void 0 : e.data) ?? [],
|
|
42
|
-
pagination:
|
|
43
|
-
}),
|
|
42
|
+
pagination: E(e)
|
|
43
|
+
}), B = (e) => "meta" in e && typeof e.meta == "object" && e.meta !== null, E = (e) => {
|
|
44
44
|
if (!e)
|
|
45
45
|
return {
|
|
46
46
|
current_page: 1,
|
|
@@ -60,7 +60,7 @@ const h = (e, o) => {
|
|
|
60
60
|
sort_by: "id",
|
|
61
61
|
descending: !1
|
|
62
62
|
};
|
|
63
|
-
if (
|
|
63
|
+
if (B(e))
|
|
64
64
|
return {
|
|
65
65
|
current_page: e.meta.current_page,
|
|
66
66
|
last_page: e.meta.last_page,
|
|
@@ -80,69 +80,69 @@ const h = (e, o) => {
|
|
|
80
80
|
descending: e.meta.descending ?? !1
|
|
81
81
|
};
|
|
82
82
|
const {
|
|
83
|
-
current_page:
|
|
83
|
+
current_page: u,
|
|
84
84
|
last_page: n,
|
|
85
85
|
per_page: r,
|
|
86
|
-
total:
|
|
87
|
-
from:
|
|
86
|
+
total: p,
|
|
87
|
+
from: d,
|
|
88
88
|
to: l,
|
|
89
|
-
path:
|
|
89
|
+
path: a,
|
|
90
90
|
links: y,
|
|
91
91
|
//links
|
|
92
92
|
first_page_url: g,
|
|
93
93
|
last_page_url: s,
|
|
94
94
|
next_page_url: v,
|
|
95
|
-
prev_page_url:
|
|
95
|
+
prev_page_url: b,
|
|
96
96
|
//custom
|
|
97
|
-
sort_by:
|
|
98
|
-
descending:
|
|
97
|
+
sort_by: P,
|
|
98
|
+
descending: K
|
|
99
99
|
} = e;
|
|
100
100
|
return {
|
|
101
|
-
current_page:
|
|
101
|
+
current_page: u,
|
|
102
102
|
last_page: n,
|
|
103
103
|
per_page: r,
|
|
104
|
-
total:
|
|
105
|
-
from:
|
|
104
|
+
total: p,
|
|
105
|
+
from: d,
|
|
106
106
|
to: l,
|
|
107
|
-
path:
|
|
107
|
+
path: a,
|
|
108
108
|
links: y,
|
|
109
109
|
//links
|
|
110
110
|
first_page_url: g,
|
|
111
111
|
last_page_url: s,
|
|
112
112
|
next_page_url: v,
|
|
113
|
-
prev_page_url:
|
|
113
|
+
prev_page_url: b,
|
|
114
114
|
//custom
|
|
115
|
-
sort_by:
|
|
116
|
-
descending:
|
|
115
|
+
sort_by: P ?? "id",
|
|
116
|
+
descending: K ?? !1
|
|
117
117
|
};
|
|
118
|
-
},
|
|
119
|
-
const { stateRoutes: n, settings: r } =
|
|
118
|
+
}, V = (e, u) => {
|
|
119
|
+
const { stateRoutes: n, settings: r } = j(
|
|
120
120
|
e,
|
|
121
|
-
|
|
121
|
+
u
|
|
122
122
|
);
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
S(() => {
|
|
124
|
+
D.delete(n.value.drop, {
|
|
125
125
|
preserveScroll: !0,
|
|
126
126
|
preserveState: !0,
|
|
127
127
|
data: { tableKey: r.value.tableKey }
|
|
128
128
|
});
|
|
129
129
|
});
|
|
130
|
-
const
|
|
131
|
-
() =>
|
|
132
|
-
), { data: l, pagination:
|
|
133
|
-
|
|
130
|
+
const p = R(), d = o(
|
|
131
|
+
() => p.props[r.value.pagePropsKey] ?? null
|
|
132
|
+
), { data: l, pagination: a, getPaginatedRequest: y, validPage: g } = z(d), s = (t) => {
|
|
133
|
+
t = y(t), r.value.useUrlQuery ? D.reload({
|
|
134
134
|
only: r.value.reloadOnly,
|
|
135
135
|
data: {
|
|
136
136
|
tableKey: r.value.tableKey,
|
|
137
|
-
filter:
|
|
138
|
-
...
|
|
137
|
+
filter: c,
|
|
138
|
+
...t
|
|
139
139
|
}
|
|
140
|
-
}) :
|
|
140
|
+
}) : D.post(
|
|
141
141
|
n.value.set,
|
|
142
142
|
{
|
|
143
143
|
tableKey: r.value.tableKey,
|
|
144
|
-
filter:
|
|
145
|
-
pagination:
|
|
144
|
+
filter: c,
|
|
145
|
+
pagination: t
|
|
146
146
|
},
|
|
147
147
|
{
|
|
148
148
|
preserveState: !0,
|
|
@@ -151,65 +151,70 @@ const h = (e, o) => {
|
|
|
151
151
|
}
|
|
152
152
|
);
|
|
153
153
|
}, v = () => {
|
|
154
|
-
|
|
155
|
-
}, f = () => {
|
|
156
|
-
d(t.value.current_page - 1);
|
|
154
|
+
f(1);
|
|
157
155
|
}, b = () => {
|
|
158
|
-
|
|
156
|
+
f(a.value.current_page - 1);
|
|
159
157
|
}, P = () => {
|
|
160
|
-
|
|
161
|
-
},
|
|
162
|
-
|
|
163
|
-
|
|
158
|
+
f(a.value.current_page + 1);
|
|
159
|
+
}, K = () => {
|
|
160
|
+
f(a.value.last_page);
|
|
161
|
+
}, f = (t) => {
|
|
162
|
+
if (!g(t)) {
|
|
163
|
+
console.error(`Invalid page: ${t}`);
|
|
164
164
|
return;
|
|
165
165
|
}
|
|
166
|
-
s({ page:
|
|
167
|
-
},
|
|
168
|
-
s({ per_page:
|
|
169
|
-
},
|
|
170
|
-
const
|
|
171
|
-
s({ sort_by:
|
|
172
|
-
},
|
|
166
|
+
s({ page: t });
|
|
167
|
+
}, T = (t) => {
|
|
168
|
+
s({ per_page: t, page: 1 });
|
|
169
|
+
}, h = (t, i) => {
|
|
170
|
+
const m = i ?? a.value.sort_by === t ? !a.value.descending : !1;
|
|
171
|
+
s({ sort_by: t, descending: m });
|
|
172
|
+
}, c = I({}), x = (t, i) => {
|
|
173
|
+
c[t] = i, s({ page: 1 });
|
|
174
|
+
}, q = (t) => {
|
|
175
|
+
t.forEach(({ key: i, value: m }) => {
|
|
176
|
+
c[i] = m;
|
|
177
|
+
}), s({ page: 1 });
|
|
178
|
+
}, U = (t) => {
|
|
179
|
+
delete c[t], s({ page: 1 });
|
|
180
|
+
}, F = () => {
|
|
181
|
+
Object.keys(c).forEach((t) => delete c[t]), s({ page: 1 });
|
|
182
|
+
}, O = o(() => p.props[r.value.pagePropsKey].additional);
|
|
173
183
|
return {
|
|
174
184
|
data: l,
|
|
175
185
|
reload: s,
|
|
176
|
-
pagination:
|
|
186
|
+
pagination: a,
|
|
177
187
|
firstPage: v,
|
|
178
|
-
previousPage:
|
|
179
|
-
nextPage:
|
|
180
|
-
lastPage:
|
|
181
|
-
goToPage:
|
|
182
|
-
itemsPerPage:
|
|
183
|
-
sortBy:
|
|
184
|
-
filter:
|
|
185
|
-
setFilter:
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
delete u[a], s({ page: 1 });
|
|
195
|
-
},
|
|
196
|
-
resetFilters: () => {
|
|
197
|
-
Object.keys(u).forEach((a) => delete u[a]), s({ page: 1 });
|
|
198
|
-
}
|
|
188
|
+
previousPage: b,
|
|
189
|
+
nextPage: P,
|
|
190
|
+
lastPage: K,
|
|
191
|
+
goToPage: f,
|
|
192
|
+
itemsPerPage: T,
|
|
193
|
+
sortBy: h,
|
|
194
|
+
filter: c,
|
|
195
|
+
setFilter: x,
|
|
196
|
+
setFilters: q,
|
|
197
|
+
removeFilter: U,
|
|
198
|
+
resetFilters: F,
|
|
199
|
+
additional: O,
|
|
200
|
+
getAdditional: (t, i = void 0) => t.split(".").reduce(
|
|
201
|
+
(k, Q) => k == null ? void 0 : k[Q],
|
|
202
|
+
O.value
|
|
203
|
+
) ?? i
|
|
199
204
|
};
|
|
200
205
|
};
|
|
201
|
-
function
|
|
206
|
+
function $() {
|
|
202
207
|
return {
|
|
203
208
|
install(e) {
|
|
204
209
|
}
|
|
205
210
|
};
|
|
206
211
|
}
|
|
207
212
|
export {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
213
|
+
$ as createInertiaDataTable,
|
|
214
|
+
E as getPaginationMeta,
|
|
215
|
+
B as isResource,
|
|
216
|
+
A as normalizePagination,
|
|
217
|
+
V as useDataTable,
|
|
218
|
+
j as useInertiaDataTableConfig,
|
|
219
|
+
z as useLaravelPagination
|
|
215
220
|
};
|