@starter-solutions/inertia-data-table-vue 0.2.0 → 0.3.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.
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { InertiaDataTableOptions, PaginatedRequest } from '../types';
|
|
2
|
+
import { MaybeRefOrGetter } from 'vue';
|
|
3
|
+
|
|
4
|
+
export declare const useDataTable: <T>(tableKey: MaybeRefOrGetter<string>, options?: MaybeRefOrGetter<InertiaDataTableOptions>) => {
|
|
5
|
+
data: import('vue').ComputedRef<T[]>;
|
|
6
|
+
pagination: import('vue').ComputedRef<Required<import('../types').NormalizedPagination>>;
|
|
7
|
+
reloadData: (request?: Partial<PaginatedRequest>) => void;
|
|
8
|
+
firstPage: () => void;
|
|
9
|
+
previousPage: () => void;
|
|
10
|
+
nextPage: () => void;
|
|
11
|
+
lastPage: () => void;
|
|
12
|
+
goToPage: (newPage: number) => void;
|
|
13
|
+
itemsPerPage: (perPage: number) => void;
|
|
14
|
+
sortBy: (sort_by: string, descending?: boolean) => void;
|
|
15
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InertiaDataTableDefaults, InertiaDataTableOptions, InertiaDataTableQueryParams, InertiaDataTableSettings, InertiaDataTableStateRoutes } from '../types
|
|
1
|
+
import { InertiaDataTableDefaults, InertiaDataTableOptions, InertiaDataTableQueryParams, InertiaDataTableSettings, InertiaDataTableStateRoutes } from '../types';
|
|
2
2
|
import { MaybeRefOrGetter } from 'vue';
|
|
3
3
|
|
|
4
4
|
export declare const useInertiaDataTableConfig: (tableKey: MaybeRefOrGetter<string>, options?: MaybeRefOrGetter<InertiaDataTableOptions>) => {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { MaybeRefOrGetter } from 'vue';
|
|
2
|
-
import { NormalizedPagination, Paginated, PaginatedRequest, PaginatedResource } from '../types
|
|
2
|
+
import { NormalizedPagination, Paginated, PaginatedRequest, PaginatedResource } from '../types';
|
|
3
3
|
|
|
4
4
|
export declare const useLaravelPagination: <T>(paginated?: MaybeRefOrGetter<Paginated<T> | null | undefined>) => {
|
|
5
5
|
data: import('vue').ComputedRef<T[]>;
|
|
6
|
-
pagination: import('vue').ComputedRef<NormalizedPagination
|
|
6
|
+
pagination: import('vue').ComputedRef<Required<NormalizedPagination>>;
|
|
7
7
|
getPaginatedRequest: (override?: Partial<PaginatedRequest>) => PaginatedRequest;
|
|
8
8
|
validPage: (page: number) => boolean;
|
|
9
9
|
};
|
|
10
10
|
export declare const normalizePagination: <T>(paginated?: Paginated<T> | null) => {
|
|
11
11
|
data: T[];
|
|
12
|
-
pagination: NormalizedPagination
|
|
12
|
+
pagination: Required<NormalizedPagination>;
|
|
13
13
|
};
|
|
14
14
|
export declare const isResource: (p: Paginated<unknown>) => p is PaginatedResource<unknown>;
|
|
15
|
-
export declare const getPaginationMeta: (paginated?: Paginated<unknown> | null) => NormalizedPagination
|
|
15
|
+
export declare const getPaginationMeta: (paginated?: Paginated<unknown> | null) => Required<NormalizedPagination>;
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("@inertiajs/vue3"),r=require("vue"),b=(e,o)=>{const n=_.usePage(),t=r.computed(()=>{const a=r.toValue(o);return{tableKey:r.toValue(e),pagePropsKey:r.toValue(a==null?void 0:a.pagePropsKey)??r.toValue(e),useUrlQuery:r.toValue(a==null?void 0:a.useUrlQuery)??!1}}),u=r.computed(()=>n.props.inertiaDataTable.stateRoutes),p=r.computed(()=>n.props.inertiaDataTable.queryParams),s=r.computed(()=>n.props.inertiaDataTable.defaults);return{settings:t,stateRoutes:u,queryParams:p,defaults:s}},f=e=>{const o=r.computed(()=>D(r.toValue(e))),n=r.computed(()=>o.value.data),t=r.computed(()=>o.value.pagination);return{data:n,pagination:t,getPaginatedRequest:(s={})=>({page:s.page??t.value.current_page,per_page:s.per_page??t.value.per_page,sort_by:s.sort_by??t.value.sort_by,descending:s.descending??t.value.descending}),validPage:s=>s>0&&s<=t.value.last_page}},D=e=>({data:(e==null?void 0:e.data)??[],pagination:T(e)}),K=e=>"meta"in e&&typeof e.meta=="object"&&e.meta!==null,T=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(K(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:o,last_page:n,per_page:t,total:u,from:p,to:s,path:a,links:c,first_page_url:v,last_page_url:g,next_page_url:m,prev_page_url:d,sort_by:y,descending:P}=e;return{current_page:o,last_page:n,per_page:t,total:u,from:p,to:s,path:a,links:c,first_page_url:v,last_page_url:g,next_page_url:m,prev_page_url:d,sort_by:y??"id",descending:P??!1}},S=(e,o)=>{const{stateRoutes:n,settings:t}=b(e,o);r.onBeforeUnmount(()=>{_.router.delete(n.value.drop,{preserveScroll:!0,preserveState:!0,data:{tableKey:t.value.tableKey}})});const u=_.usePage(),p=r.computed(()=>u.props[t.value.pagePropsKey]??null),{data:s,pagination:a,getPaginatedRequest:c,validPage:v}=f(p),g=l=>{l=c(l),t.value.useUrlQuery?_.router.reload({only:[t.value.pagePropsKey],data:{tableKey:t.value.tableKey,...l}}):_.router.post(n.value.set,{tableKey:t.value.tableKey,data:{...l}},{preserveState:!0,preserveScroll:!0,only:[t.value.pagePropsKey]})},m=()=>{i(1)},d=()=>{i(a.value.current_page-1)},y=()=>{i(a.value.current_page+1)},P=()=>{i(a.value.last_page)},i=l=>{if(!v(l)){console.error(`Invalid page: ${l}`);return}g(c({page:l}))};return{data:s,pagination:a,reloadData:g,firstPage:m,previousPage:d,nextPage:y,lastPage:P,goToPage:i,itemsPerPage:l=>{g(c({per_page:l,page:1}))},sortBy:(l,k)=>{const R=k??a.value.sort_by===l?!a.value.descending:!1;g(c({sort_by:l,descending:R}))}}};function V(){return{install(e){}}}exports.createInertiaDataTable=V;exports.getPaginationMeta=T;exports.isResource=K;exports.normalizePagination=D;exports.useDataTable=S;exports.useInertiaDataTableConfig=b;exports.useLaravelPagination=f;
|
package/dist/index.js
CHANGED
|
@@ -1,43 +1,45 @@
|
|
|
1
|
-
import { usePage as b } from "@inertiajs/vue3";
|
|
2
|
-
import { computed as
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
1
|
+
import { usePage as b, router as P } from "@inertiajs/vue3";
|
|
2
|
+
import { computed as o, toValue as _, onBeforeUnmount as k } from "vue";
|
|
3
|
+
const R = (e, n) => {
|
|
4
|
+
const l = b(), t = o(() => {
|
|
5
|
+
const a = _(n);
|
|
6
6
|
return {
|
|
7
|
-
tableKey:
|
|
8
|
-
pagePropsKey:
|
|
9
|
-
useUrlQuery:
|
|
7
|
+
tableKey: _(e),
|
|
8
|
+
pagePropsKey: _(a == null ? void 0 : a.pagePropsKey) ?? _(e),
|
|
9
|
+
useUrlQuery: _(a == null ? void 0 : a.useUrlQuery) ?? !1
|
|
10
10
|
};
|
|
11
|
-
}),
|
|
12
|
-
() =>
|
|
13
|
-
),
|
|
14
|
-
() =>
|
|
15
|
-
),
|
|
16
|
-
() =>
|
|
11
|
+
}), u = o(
|
|
12
|
+
() => l.props.inertiaDataTable.stateRoutes
|
|
13
|
+
), p = o(
|
|
14
|
+
() => l.props.inertiaDataTable.queryParams
|
|
15
|
+
), r = o(
|
|
16
|
+
() => l.props.inertiaDataTable.defaults
|
|
17
17
|
);
|
|
18
18
|
return {
|
|
19
|
-
settings:
|
|
20
|
-
stateRoutes:
|
|
21
|
-
queryParams:
|
|
22
|
-
defaults:
|
|
19
|
+
settings: t,
|
|
20
|
+
stateRoutes: u,
|
|
21
|
+
queryParams: p,
|
|
22
|
+
defaults: r
|
|
23
23
|
};
|
|
24
|
-
},
|
|
25
|
-
const n =
|
|
24
|
+
}, T = (e) => {
|
|
25
|
+
const n = o(() => x(_(e))), l = o(() => n.value.data), t = o(
|
|
26
|
+
() => n.value.pagination
|
|
27
|
+
);
|
|
26
28
|
return {
|
|
27
|
-
data:
|
|
28
|
-
pagination:
|
|
29
|
-
getPaginatedRequest: (
|
|
30
|
-
page:
|
|
31
|
-
per_page:
|
|
32
|
-
sort_by:
|
|
33
|
-
descending:
|
|
29
|
+
data: l,
|
|
30
|
+
pagination: t,
|
|
31
|
+
getPaginatedRequest: (r = {}) => ({
|
|
32
|
+
page: r.page ?? t.value.current_page,
|
|
33
|
+
per_page: r.per_page ?? t.value.per_page,
|
|
34
|
+
sort_by: r.sort_by ?? t.value.sort_by,
|
|
35
|
+
descending: r.descending ?? t.value.descending
|
|
34
36
|
}),
|
|
35
|
-
validPage: (
|
|
37
|
+
validPage: (r) => r > 0 && r <= t.value.last_page
|
|
36
38
|
};
|
|
37
|
-
},
|
|
39
|
+
}, x = (e) => ({
|
|
38
40
|
data: (e == null ? void 0 : e.data) ?? [],
|
|
39
|
-
pagination:
|
|
40
|
-
}),
|
|
41
|
+
pagination: S(e)
|
|
42
|
+
}), h = (e) => "meta" in e && typeof e.meta == "object" && e.meta !== null, S = (e) => {
|
|
41
43
|
if (!e)
|
|
42
44
|
return {
|
|
43
45
|
current_page: 1,
|
|
@@ -57,7 +59,7 @@ const D = (e, n) => {
|
|
|
57
59
|
sort_by: "id",
|
|
58
60
|
descending: !1
|
|
59
61
|
};
|
|
60
|
-
if (
|
|
62
|
+
if (h(e))
|
|
61
63
|
return {
|
|
62
64
|
current_page: e.meta.current_page,
|
|
63
65
|
last_page: e.meta.last_page,
|
|
@@ -78,52 +80,115 @@ const D = (e, n) => {
|
|
|
78
80
|
};
|
|
79
81
|
const {
|
|
80
82
|
current_page: n,
|
|
81
|
-
last_page:
|
|
82
|
-
per_page:
|
|
83
|
-
total:
|
|
84
|
-
from:
|
|
85
|
-
to:
|
|
86
|
-
path:
|
|
87
|
-
links:
|
|
83
|
+
last_page: l,
|
|
84
|
+
per_page: t,
|
|
85
|
+
total: u,
|
|
86
|
+
from: p,
|
|
87
|
+
to: r,
|
|
88
|
+
path: a,
|
|
89
|
+
links: g,
|
|
88
90
|
//links
|
|
89
|
-
first_page_url:
|
|
91
|
+
first_page_url: v,
|
|
90
92
|
last_page_url: c,
|
|
91
|
-
next_page_url:
|
|
92
|
-
prev_page_url:
|
|
93
|
+
next_page_url: m,
|
|
94
|
+
prev_page_url: y,
|
|
93
95
|
//custom
|
|
94
96
|
sort_by: f,
|
|
95
|
-
descending:
|
|
97
|
+
descending: d
|
|
96
98
|
} = e;
|
|
97
99
|
return {
|
|
98
100
|
current_page: n,
|
|
99
|
-
last_page:
|
|
100
|
-
per_page:
|
|
101
|
-
total:
|
|
102
|
-
from:
|
|
103
|
-
to:
|
|
104
|
-
path:
|
|
105
|
-
links:
|
|
101
|
+
last_page: l,
|
|
102
|
+
per_page: t,
|
|
103
|
+
total: u,
|
|
104
|
+
from: p,
|
|
105
|
+
to: r,
|
|
106
|
+
path: a,
|
|
107
|
+
links: g,
|
|
106
108
|
//links
|
|
107
|
-
first_page_url:
|
|
109
|
+
first_page_url: v,
|
|
108
110
|
last_page_url: c,
|
|
109
|
-
next_page_url:
|
|
110
|
-
prev_page_url:
|
|
111
|
+
next_page_url: m,
|
|
112
|
+
prev_page_url: y,
|
|
111
113
|
//custom
|
|
112
114
|
sort_by: f ?? "id",
|
|
113
|
-
descending:
|
|
115
|
+
descending: d ?? !1
|
|
116
|
+
};
|
|
117
|
+
}, q = (e, n) => {
|
|
118
|
+
const { stateRoutes: l, settings: t } = R(
|
|
119
|
+
e,
|
|
120
|
+
n
|
|
121
|
+
);
|
|
122
|
+
k(() => {
|
|
123
|
+
P.delete(l.value.drop, {
|
|
124
|
+
preserveScroll: !0,
|
|
125
|
+
preserveState: !0,
|
|
126
|
+
data: { tableKey: t.value.tableKey }
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
const u = b(), p = o(
|
|
130
|
+
() => u.props[t.value.pagePropsKey] ?? null
|
|
131
|
+
), { data: r, pagination: a, getPaginatedRequest: g, validPage: v } = T(p), c = (s) => {
|
|
132
|
+
s = g(s), t.value.useUrlQuery ? P.reload({
|
|
133
|
+
only: [t.value.pagePropsKey],
|
|
134
|
+
data: { tableKey: t.value.tableKey, ...s }
|
|
135
|
+
}) : P.post(
|
|
136
|
+
l.value.set,
|
|
137
|
+
{
|
|
138
|
+
tableKey: t.value.tableKey,
|
|
139
|
+
data: { ...s }
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
preserveState: !0,
|
|
143
|
+
preserveScroll: !0,
|
|
144
|
+
only: [t.value.pagePropsKey]
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
}, m = () => {
|
|
148
|
+
i(1);
|
|
149
|
+
}, y = () => {
|
|
150
|
+
i(a.value.current_page - 1);
|
|
151
|
+
}, f = () => {
|
|
152
|
+
i(a.value.current_page + 1);
|
|
153
|
+
}, d = () => {
|
|
154
|
+
i(a.value.last_page);
|
|
155
|
+
}, i = (s) => {
|
|
156
|
+
if (!v(s)) {
|
|
157
|
+
console.error(`Invalid page: ${s}`);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
c(g({ page: s }));
|
|
161
|
+
};
|
|
162
|
+
return {
|
|
163
|
+
data: r,
|
|
164
|
+
pagination: a,
|
|
165
|
+
reloadData: c,
|
|
166
|
+
firstPage: m,
|
|
167
|
+
previousPage: y,
|
|
168
|
+
nextPage: f,
|
|
169
|
+
lastPage: d,
|
|
170
|
+
goToPage: i,
|
|
171
|
+
itemsPerPage: (s) => {
|
|
172
|
+
c(g({ per_page: s, page: 1 }));
|
|
173
|
+
},
|
|
174
|
+
sortBy: (s, K) => {
|
|
175
|
+
const D = K ?? a.value.sort_by === s ? !a.value.descending : !1;
|
|
176
|
+
c(g({ sort_by: s, descending: D }));
|
|
177
|
+
}
|
|
114
178
|
};
|
|
115
179
|
};
|
|
116
|
-
function
|
|
180
|
+
function z() {
|
|
117
181
|
return {
|
|
118
182
|
install(e) {
|
|
119
183
|
}
|
|
120
184
|
};
|
|
121
185
|
}
|
|
122
186
|
export {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
R as
|
|
187
|
+
z as createInertiaDataTable,
|
|
188
|
+
S as getPaginationMeta,
|
|
189
|
+
h as isResource,
|
|
190
|
+
x as normalizePagination,
|
|
191
|
+
q as useDataTable,
|
|
192
|
+
R as useInertiaDataTableConfig,
|
|
193
|
+
T as useLaravelPagination
|
|
129
194
|
};
|