@honed/table 0.4.3 → 0.5.1
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/index.d.ts +11 -16
- package/dist/index.es.js +175 -179
- package/dist/index.umd.js +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { Visit } from '@inertiajs/core';
|
|
|
18
18
|
import { VisitCallbacks } from '@inertiajs/core';
|
|
19
19
|
import { VisitOptions } from '@inertiajs/core';
|
|
20
20
|
|
|
21
|
-
export declare type AsRecord<RecordType extends Record<string, any
|
|
21
|
+
export declare type AsRecord<RecordType extends Record<string, any> = any> = {
|
|
22
22
|
[K in keyof RecordType]: {
|
|
23
23
|
value: RecordType[K];
|
|
24
24
|
extra: Record<string, any>;
|
|
@@ -29,10 +29,10 @@ export declare interface CollectionPaginator {
|
|
|
29
29
|
empty: boolean;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
export declare interface Column<T extends Record<string, any>> {
|
|
32
|
+
export declare interface Column<T extends Record<string, any> = Record<string, any>> {
|
|
33
33
|
name: keyof T;
|
|
34
34
|
label: string;
|
|
35
|
-
type: "
|
|
35
|
+
type: "array" | "badge" | "boolean" | "currency" | "date" | "hidden" | "key" | "number" | "text" | string;
|
|
36
36
|
hidden: boolean;
|
|
37
37
|
active: boolean;
|
|
38
38
|
toggleable: boolean;
|
|
@@ -47,10 +47,10 @@ export declare interface Column<T extends Record<string, any>> {
|
|
|
47
47
|
|
|
48
48
|
export declare interface Config extends Config_2 {
|
|
49
49
|
endpoint: string;
|
|
50
|
+
key: string;
|
|
50
51
|
record: string;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
pages: string;
|
|
52
|
+
column: string;
|
|
53
|
+
page: string;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
export declare interface CursorPaginator extends CollectionPaginator {
|
|
@@ -105,23 +105,23 @@ export declare interface Table<RecordType extends Record<string, any> = any, Pag
|
|
|
105
105
|
meta: Record<string, any>;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
export declare interface TableColumn<T extends Record<string, any>> extends Column<T> {
|
|
108
|
+
export declare interface TableColumn<T extends Record<string, any> = Record<string, any>> extends Column<T> {
|
|
109
109
|
toggle: (options: VisitOptions) => void;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
export declare interface TableHeading<T extends Record<string, any>> extends Column<T> {
|
|
112
|
+
export declare interface TableHeading<T extends Record<string, any> = Record<string, any>> extends Column<T> {
|
|
113
113
|
isSorting: boolean;
|
|
114
114
|
toggleSort: (options: VisitOptions) => void;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
export declare interface TableOptions<RecordType extends Record<string, any>> {
|
|
117
|
+
export declare interface TableOptions<RecordType extends Record<string, any> = Record<string, any>> {
|
|
118
118
|
/**
|
|
119
119
|
* Actions to be applied on a record in JavaScript.
|
|
120
120
|
*/
|
|
121
121
|
recordActions?: Record<string, (record: AsRecord<RecordType>) => void>;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
export declare interface TableRecord<RecordType extends Record<string, any>> {
|
|
124
|
+
export declare interface TableRecord<RecordType extends Record<string, any> = Record<string, any>> {
|
|
125
125
|
record: RecordType;
|
|
126
126
|
default: (options?: VisitOptions) => void;
|
|
127
127
|
actions: InlineAction[];
|
|
@@ -145,10 +145,8 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
|
|
|
145
145
|
modelValue: unknown;
|
|
146
146
|
} | undefined;
|
|
147
147
|
type: string;
|
|
148
|
-
value: FilterValue;
|
|
149
|
-
/** Selects this record */
|
|
148
|
+
value: FilterValue; /** Determine if the record is selected */
|
|
150
149
|
options: Option_2[];
|
|
151
|
-
multiple: boolean;
|
|
152
150
|
name: string;
|
|
153
151
|
label: string;
|
|
154
152
|
active: boolean;
|
|
@@ -180,9 +178,6 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
|
|
|
180
178
|
name: string;
|
|
181
179
|
label: string;
|
|
182
180
|
active: boolean;
|
|
183
|
-
/**
|
|
184
|
-
* The available bulk actions.
|
|
185
|
-
*/
|
|
186
181
|
meta: Record<string, any>;
|
|
187
182
|
}[] | undefined;
|
|
188
183
|
getFilter: (name: string) => Filter | undefined;
|
package/dist/index.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ref as _, computed as
|
|
1
|
+
import { ref as _, computed as g, toValue as J, reactive as Q } from "vue";
|
|
2
2
|
import { router as x } from "@inertiajs/vue3";
|
|
3
3
|
function X() {
|
|
4
4
|
const o = _({
|
|
@@ -9,29 +9,29 @@ function X() {
|
|
|
9
9
|
function m() {
|
|
10
10
|
o.value.all = !0, o.value.only.clear(), o.value.except.clear();
|
|
11
11
|
}
|
|
12
|
-
function
|
|
12
|
+
function v() {
|
|
13
13
|
o.value.all = !1, o.value.only.clear(), o.value.except.clear();
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
c.forEach((
|
|
15
|
+
function l(...c) {
|
|
16
|
+
c.forEach((p) => o.value.except.delete(p)), c.forEach((p) => o.value.only.add(p));
|
|
17
17
|
}
|
|
18
18
|
function i(...c) {
|
|
19
|
-
c.forEach((
|
|
19
|
+
c.forEach((p) => o.value.except.add(p)), c.forEach((p) => o.value.only.delete(p));
|
|
20
20
|
}
|
|
21
|
-
function u(c,
|
|
22
|
-
if (b(c) ||
|
|
21
|
+
function u(c, p) {
|
|
22
|
+
if (b(c) || p === !1)
|
|
23
23
|
return i(c);
|
|
24
|
-
if (!b(c) ||
|
|
25
|
-
return
|
|
24
|
+
if (!b(c) || p === !0)
|
|
25
|
+
return l(c);
|
|
26
26
|
}
|
|
27
27
|
function b(c) {
|
|
28
28
|
return o.value.all ? !o.value.except.has(c) : o.value.only.has(c);
|
|
29
29
|
}
|
|
30
|
-
const f =
|
|
30
|
+
const f = g(() => o.value.all && o.value.except.size === 0), A = g(() => o.value.only.size > 0 || f.value);
|
|
31
31
|
function S(c) {
|
|
32
32
|
return {
|
|
33
|
-
"onUpdate:modelValue": (
|
|
34
|
-
|
|
33
|
+
"onUpdate:modelValue": (p) => {
|
|
34
|
+
p ? l(c) : i(c);
|
|
35
35
|
},
|
|
36
36
|
modelValue: b(c),
|
|
37
37
|
value: c
|
|
@@ -40,7 +40,7 @@ function X() {
|
|
|
40
40
|
function k() {
|
|
41
41
|
return {
|
|
42
42
|
"onUpdate:modelValue": (c) => {
|
|
43
|
-
c ? m() :
|
|
43
|
+
c ? m() : v();
|
|
44
44
|
},
|
|
45
45
|
modelValue: f.value,
|
|
46
46
|
value: f.value
|
|
@@ -51,8 +51,8 @@ function X() {
|
|
|
51
51
|
selection: o,
|
|
52
52
|
hasSelected: A,
|
|
53
53
|
selectAll: m,
|
|
54
|
-
deselectAll:
|
|
55
|
-
select:
|
|
54
|
+
deselectAll: v,
|
|
55
|
+
select: l,
|
|
56
56
|
deselect: i,
|
|
57
57
|
toggle: u,
|
|
58
58
|
selected: b,
|
|
@@ -60,133 +60,133 @@ function X() {
|
|
|
60
60
|
bindAll: k
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
-
function I(o, m,
|
|
64
|
-
return o.route ? (x.visit(o.route.
|
|
65
|
-
...
|
|
63
|
+
function I(o, m, v = {}, l = {}) {
|
|
64
|
+
return o.route ? (x.visit(o.route.url, {
|
|
65
|
+
...l,
|
|
66
66
|
method: o.route.method
|
|
67
67
|
}), !0) : o.action && m ? (x.post(
|
|
68
68
|
m,
|
|
69
69
|
{
|
|
70
|
-
...
|
|
70
|
+
...v,
|
|
71
71
|
name: o.name,
|
|
72
72
|
type: o.type
|
|
73
73
|
},
|
|
74
|
-
|
|
74
|
+
l
|
|
75
75
|
), !0) : !1;
|
|
76
76
|
}
|
|
77
77
|
typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
|
|
78
78
|
const Y = () => {
|
|
79
79
|
};
|
|
80
80
|
function Z(o, m) {
|
|
81
|
-
function
|
|
81
|
+
function v(...l) {
|
|
82
82
|
return new Promise((i, u) => {
|
|
83
|
-
Promise.resolve(o(() => m.apply(this,
|
|
83
|
+
Promise.resolve(o(() => m.apply(this, l), { fn: m, thisArg: this, args: l })).then(i).catch(u);
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
|
-
return
|
|
86
|
+
return v;
|
|
87
87
|
}
|
|
88
88
|
function O(o, m = {}) {
|
|
89
|
-
let
|
|
89
|
+
let v, l, i = Y;
|
|
90
90
|
const u = (f) => {
|
|
91
91
|
clearTimeout(f), i(), i = Y;
|
|
92
92
|
};
|
|
93
93
|
let b;
|
|
94
94
|
return (f) => {
|
|
95
95
|
const A = J(o), S = J(m.maxWait);
|
|
96
|
-
return
|
|
97
|
-
i = m.rejectOnCancel ? c : k, b = f, S && !
|
|
98
|
-
|
|
99
|
-
}, S)),
|
|
100
|
-
|
|
96
|
+
return v && u(v), A <= 0 || S !== void 0 && S <= 0 ? (l && (u(l), l = null), Promise.resolve(f())) : new Promise((k, c) => {
|
|
97
|
+
i = m.rejectOnCancel ? c : k, b = f, S && !l && (l = setTimeout(() => {
|
|
98
|
+
v && u(v), l = null, k(b());
|
|
99
|
+
}, S)), v = setTimeout(() => {
|
|
100
|
+
l && u(l), l = null, k(f());
|
|
101
101
|
}, A);
|
|
102
102
|
});
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
|
-
function q(o, m = 200,
|
|
105
|
+
function q(o, m = 200, v = {}) {
|
|
106
106
|
return Z(
|
|
107
|
-
O(m,
|
|
107
|
+
O(m, v),
|
|
108
108
|
o
|
|
109
109
|
);
|
|
110
110
|
}
|
|
111
|
-
function ee(o, m,
|
|
112
|
-
const
|
|
111
|
+
function ee(o, m, v = {}) {
|
|
112
|
+
const l = g(() => o[m]), i = g(
|
|
113
113
|
() => {
|
|
114
114
|
var e;
|
|
115
|
-
return ((e =
|
|
115
|
+
return ((e = l.value.filters) == null ? void 0 : e.map((n) => ({
|
|
116
116
|
...n,
|
|
117
|
-
apply: (r,
|
|
117
|
+
apply: (r, d = {}) => L(n, r, d),
|
|
118
118
|
clear: (r = {}) => N(n, r),
|
|
119
|
-
bind: () =>
|
|
119
|
+
bind: () => a(n.name)
|
|
120
120
|
}))) ?? [];
|
|
121
121
|
}
|
|
122
|
-
), u =
|
|
122
|
+
), u = g(
|
|
123
123
|
() => {
|
|
124
124
|
var e;
|
|
125
|
-
return ((e =
|
|
125
|
+
return ((e = l.value.sorts) == null ? void 0 : e.map((n) => ({
|
|
126
126
|
...n,
|
|
127
127
|
apply: (r = {}) => M(n, n.direction, r),
|
|
128
|
-
clear: (r = {}) =>
|
|
128
|
+
clear: (r = {}) => W(r),
|
|
129
129
|
bind: () => s(n)
|
|
130
130
|
}))) ?? [];
|
|
131
131
|
}
|
|
132
|
-
), b =
|
|
132
|
+
), b = g(
|
|
133
133
|
() => {
|
|
134
134
|
var e;
|
|
135
|
-
return (e =
|
|
135
|
+
return (e = l.value.searches) == null ? void 0 : e.map((n) => ({
|
|
136
136
|
...n,
|
|
137
137
|
apply: (r = {}) => U(n, r),
|
|
138
138
|
clear: (r = {}) => U(n, r),
|
|
139
139
|
bind: () => F(n)
|
|
140
140
|
}));
|
|
141
141
|
}
|
|
142
|
-
), f =
|
|
142
|
+
), f = g(
|
|
143
143
|
() => {
|
|
144
144
|
var e;
|
|
145
|
-
return ((e =
|
|
145
|
+
return ((e = l.value.filters) == null ? void 0 : e.filter(({ active: n }) => n)) ?? [];
|
|
146
146
|
}
|
|
147
|
-
), A =
|
|
147
|
+
), A = g(
|
|
148
148
|
() => {
|
|
149
149
|
var e;
|
|
150
|
-
return (e =
|
|
150
|
+
return (e = l.value.sorts) == null ? void 0 : e.find(({ active: n }) => n);
|
|
151
151
|
}
|
|
152
|
-
), S =
|
|
152
|
+
), S = g(
|
|
153
153
|
() => {
|
|
154
154
|
var e;
|
|
155
|
-
return ((e =
|
|
155
|
+
return ((e = l.value.searches) == null ? void 0 : e.filter(({ active: n }) => n)) ?? [];
|
|
156
156
|
}
|
|
157
157
|
);
|
|
158
158
|
function k(e) {
|
|
159
|
-
return Array.isArray(e) ? e.join(
|
|
159
|
+
return Array.isArray(e) ? e.join(l.value.config.delimiter) : e;
|
|
160
160
|
}
|
|
161
161
|
function c(e) {
|
|
162
162
|
return typeof e != "string" ? e : e.trim().replace(/\s+/g, "+");
|
|
163
163
|
}
|
|
164
|
-
function
|
|
164
|
+
function p(e) {
|
|
165
165
|
if (!["", null, void 0, []].includes(e))
|
|
166
166
|
return e;
|
|
167
167
|
}
|
|
168
|
-
function
|
|
169
|
-
return [k, c,
|
|
168
|
+
function G(e) {
|
|
169
|
+
return [k, c, p].reduce(
|
|
170
170
|
(n, r) => r(n),
|
|
171
171
|
e
|
|
172
172
|
);
|
|
173
173
|
}
|
|
174
|
-
function
|
|
174
|
+
function B(e, n) {
|
|
175
175
|
return n = Array.isArray(n) ? n : [n], n.includes(e) ? n.filter((r) => r !== e) : [...n, e];
|
|
176
176
|
}
|
|
177
|
-
function
|
|
177
|
+
function j(e) {
|
|
178
178
|
var n;
|
|
179
|
-
return (n =
|
|
179
|
+
return (n = l.value.filters) == null ? void 0 : n.find((r) => r.name === e);
|
|
180
180
|
}
|
|
181
181
|
function h(e, n = null) {
|
|
182
182
|
var r;
|
|
183
|
-
return (r =
|
|
184
|
-
(
|
|
183
|
+
return (r = l.value.sorts) == null ? void 0 : r.find(
|
|
184
|
+
(d) => d.name === e && d.direction === n
|
|
185
185
|
);
|
|
186
186
|
}
|
|
187
187
|
function E(e) {
|
|
188
188
|
var n;
|
|
189
|
-
return (n =
|
|
189
|
+
return (n = l.value.searches) == null ? void 0 : n.find((r) => r.name === e);
|
|
190
190
|
}
|
|
191
191
|
function y(e) {
|
|
192
192
|
return e ? typeof e == "string" ? f.value.some((n) => n.name === e) : e.active : !!f.value.length;
|
|
@@ -197,89 +197,85 @@ function ee(o, m, d = {}) {
|
|
|
197
197
|
}
|
|
198
198
|
function P(e) {
|
|
199
199
|
var n;
|
|
200
|
-
return e ? typeof e == "string" ? (n = S.value) == null ? void 0 : n.some((r) => r.name === e) : e.active : !!
|
|
200
|
+
return e ? typeof e == "string" ? (n = S.value) == null ? void 0 : n.some((r) => r.name === e) : e.active : !!l.value.config.term;
|
|
201
201
|
}
|
|
202
|
-
function
|
|
202
|
+
function C(e, n = {}) {
|
|
203
203
|
const r = Object.fromEntries(
|
|
204
|
-
Object.entries(e).map(([
|
|
204
|
+
Object.entries(e).map(([d, V]) => [d, G(V)])
|
|
205
205
|
);
|
|
206
206
|
x.reload({
|
|
207
|
-
...
|
|
207
|
+
...v,
|
|
208
208
|
...n,
|
|
209
209
|
data: r
|
|
210
210
|
});
|
|
211
211
|
}
|
|
212
212
|
function L(e, n, r = {}) {
|
|
213
|
-
const
|
|
214
|
-
if (!
|
|
213
|
+
const d = typeof e == "string" ? j(e) : e;
|
|
214
|
+
if (!d) {
|
|
215
215
|
console.warn(`Filter [${e}] does not exist.`);
|
|
216
216
|
return;
|
|
217
217
|
}
|
|
218
|
-
|
|
219
|
-
...
|
|
218
|
+
x.reload({
|
|
219
|
+
...v,
|
|
220
220
|
...r,
|
|
221
221
|
data: {
|
|
222
|
-
[
|
|
222
|
+
[d.name]: G(n)
|
|
223
223
|
}
|
|
224
224
|
});
|
|
225
225
|
}
|
|
226
226
|
function M(e, n = null, r = {}) {
|
|
227
|
-
const
|
|
228
|
-
if (!
|
|
227
|
+
const d = typeof e == "string" ? h(e, n) : e;
|
|
228
|
+
if (!d) {
|
|
229
229
|
console.warn(`Sort [${e}] does not exist.`);
|
|
230
230
|
return;
|
|
231
231
|
}
|
|
232
232
|
x.reload({
|
|
233
|
-
...
|
|
233
|
+
...v,
|
|
234
234
|
...r,
|
|
235
235
|
data: {
|
|
236
|
-
[
|
|
236
|
+
[l.value.config.sort]: p(d.next)
|
|
237
237
|
}
|
|
238
238
|
});
|
|
239
239
|
}
|
|
240
240
|
function T(e, n = {}) {
|
|
241
|
-
e = [c,
|
|
242
|
-
(r,
|
|
241
|
+
e = [c, p].reduce(
|
|
242
|
+
(r, d) => d(r),
|
|
243
243
|
e
|
|
244
244
|
), x.reload({
|
|
245
|
-
...
|
|
245
|
+
...v,
|
|
246
246
|
...n,
|
|
247
247
|
data: {
|
|
248
|
-
[
|
|
248
|
+
[l.value.config.search]: e
|
|
249
249
|
}
|
|
250
250
|
});
|
|
251
251
|
}
|
|
252
252
|
function U(e, n = {}) {
|
|
253
|
-
if (!a.value.config.matches) {
|
|
254
|
-
console.warn("Matches key is not set.");
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
253
|
const r = typeof e == "string" ? E(e) : e;
|
|
258
254
|
if (!r) {
|
|
259
255
|
console.warn(`Match [${e}] does not exist.`);
|
|
260
256
|
return;
|
|
261
257
|
}
|
|
262
|
-
const
|
|
258
|
+
const d = B(
|
|
263
259
|
r.name,
|
|
264
260
|
S.value.map(({ name: V }) => V)
|
|
265
261
|
);
|
|
266
262
|
x.reload({
|
|
267
|
-
...
|
|
263
|
+
...v,
|
|
268
264
|
...n,
|
|
269
265
|
data: {
|
|
270
|
-
[
|
|
266
|
+
[l.value.config.match]: k(d)
|
|
271
267
|
}
|
|
272
268
|
});
|
|
273
269
|
}
|
|
274
270
|
function N(e, n = {}) {
|
|
275
271
|
L(e, void 0, n);
|
|
276
272
|
}
|
|
277
|
-
function
|
|
273
|
+
function W(e = {}) {
|
|
278
274
|
x.reload({
|
|
279
|
-
...
|
|
275
|
+
...v,
|
|
280
276
|
...e,
|
|
281
277
|
data: {
|
|
282
|
-
[
|
|
278
|
+
[l.value.config.sort]: void 0
|
|
283
279
|
}
|
|
284
280
|
});
|
|
285
281
|
}
|
|
@@ -287,29 +283,29 @@ function ee(o, m, d = {}) {
|
|
|
287
283
|
T(void 0, e);
|
|
288
284
|
}
|
|
289
285
|
function D(e = {}) {
|
|
290
|
-
if (!
|
|
286
|
+
if (!l.value.config.match) {
|
|
291
287
|
console.warn("Matches key is not set.");
|
|
292
288
|
return;
|
|
293
289
|
}
|
|
294
290
|
x.reload({
|
|
295
|
-
...
|
|
291
|
+
...v,
|
|
296
292
|
...e,
|
|
297
293
|
data: {
|
|
298
|
-
[
|
|
294
|
+
[l.value.config.match]: void 0
|
|
299
295
|
}
|
|
300
296
|
});
|
|
301
297
|
}
|
|
302
298
|
function t(e = {}) {
|
|
303
299
|
var n;
|
|
304
300
|
x.reload({
|
|
305
|
-
...
|
|
301
|
+
...v,
|
|
306
302
|
...e,
|
|
307
303
|
data: {
|
|
308
|
-
[
|
|
309
|
-
[
|
|
310
|
-
[
|
|
304
|
+
[l.value.config.search]: void 0,
|
|
305
|
+
[l.value.config.sort]: void 0,
|
|
306
|
+
[l.value.config.match]: void 0,
|
|
311
307
|
...Object.fromEntries(
|
|
312
|
-
((n =
|
|
308
|
+
((n = l.value.filters) == null ? void 0 : n.map((r) => [
|
|
313
309
|
r.name,
|
|
314
310
|
void 0
|
|
315
311
|
])) ?? []
|
|
@@ -317,22 +313,22 @@ function ee(o, m, d = {}) {
|
|
|
317
313
|
}
|
|
318
314
|
});
|
|
319
315
|
}
|
|
320
|
-
function
|
|
321
|
-
const r = typeof e == "string" ?
|
|
316
|
+
function a(e, n = {}) {
|
|
317
|
+
const r = typeof e == "string" ? j(e) : e;
|
|
322
318
|
if (!r) {
|
|
323
319
|
console.warn(`Filter [${e}] does not exist.`);
|
|
324
320
|
return;
|
|
325
321
|
}
|
|
326
|
-
const
|
|
322
|
+
const d = r.value, {
|
|
327
323
|
debounce: V = 250,
|
|
328
|
-
transform:
|
|
324
|
+
transform: z = (H) => H,
|
|
329
325
|
...$
|
|
330
326
|
} = n;
|
|
331
327
|
return {
|
|
332
328
|
"onUpdate:modelValue": q((H) => {
|
|
333
|
-
L(r,
|
|
329
|
+
L(r, z(H), $);
|
|
334
330
|
}, V),
|
|
335
|
-
modelValue:
|
|
331
|
+
modelValue: d
|
|
336
332
|
};
|
|
337
333
|
}
|
|
338
334
|
function s(e, n = {}) {
|
|
@@ -341,24 +337,24 @@ function ee(o, m, d = {}) {
|
|
|
341
337
|
console.warn(`Sort [${e}] does not exist.`);
|
|
342
338
|
return;
|
|
343
339
|
}
|
|
344
|
-
const { debounce:
|
|
340
|
+
const { debounce: d = 0, transform: V, ...z } = n;
|
|
345
341
|
return {
|
|
346
342
|
onClick: q(() => {
|
|
347
343
|
var $;
|
|
348
|
-
M(r, ($ = A.value) == null ? void 0 : $.direction,
|
|
349
|
-
},
|
|
344
|
+
M(r, ($ = A.value) == null ? void 0 : $.direction, z);
|
|
345
|
+
}, d)
|
|
350
346
|
};
|
|
351
347
|
}
|
|
352
348
|
function w(e = {}) {
|
|
353
|
-
const { debounce: n = 700, transform: r, ...
|
|
349
|
+
const { debounce: n = 700, transform: r, ...d } = e;
|
|
354
350
|
return {
|
|
355
351
|
"onUpdate:modelValue": q(
|
|
356
352
|
(V) => {
|
|
357
|
-
T(V,
|
|
353
|
+
T(V, d);
|
|
358
354
|
},
|
|
359
355
|
n
|
|
360
356
|
),
|
|
361
|
-
modelValue:
|
|
357
|
+
modelValue: l.value.config.term ?? ""
|
|
362
358
|
};
|
|
363
359
|
}
|
|
364
360
|
function F(e, n = {}) {
|
|
@@ -367,11 +363,11 @@ function ee(o, m, d = {}) {
|
|
|
367
363
|
console.warn(`Match [${e}] does not exist.`);
|
|
368
364
|
return;
|
|
369
365
|
}
|
|
370
|
-
const { debounce:
|
|
366
|
+
const { debounce: d = 0, transform: V, ...z } = n;
|
|
371
367
|
return {
|
|
372
368
|
"onUpdate:modelValue": q(($) => {
|
|
373
|
-
U($,
|
|
374
|
-
},
|
|
369
|
+
U($, z);
|
|
370
|
+
}, d),
|
|
375
371
|
modelValue: P(r),
|
|
376
372
|
value: r.name
|
|
377
373
|
};
|
|
@@ -380,7 +376,7 @@ function ee(o, m, d = {}) {
|
|
|
380
376
|
filters: i,
|
|
381
377
|
sorts: u,
|
|
382
378
|
searches: b,
|
|
383
|
-
getFilter:
|
|
379
|
+
getFilter: j,
|
|
384
380
|
getSort: h,
|
|
385
381
|
getSearch: E,
|
|
386
382
|
currentFilters: f,
|
|
@@ -389,68 +385,68 @@ function ee(o, m, d = {}) {
|
|
|
389
385
|
isFiltering: y,
|
|
390
386
|
isSorting: K,
|
|
391
387
|
isSearching: P,
|
|
392
|
-
apply:
|
|
388
|
+
apply: C,
|
|
393
389
|
applyFilter: L,
|
|
394
390
|
applySort: M,
|
|
395
391
|
applySearch: T,
|
|
396
392
|
applyMatch: U,
|
|
397
393
|
clearFilter: N,
|
|
398
|
-
clearSort:
|
|
394
|
+
clearSort: W,
|
|
399
395
|
clearSearch: R,
|
|
400
396
|
clearMatch: D,
|
|
401
397
|
reset: t,
|
|
402
|
-
bindFilter:
|
|
398
|
+
bindFilter: a,
|
|
403
399
|
bindSort: s,
|
|
404
400
|
bindSearch: w,
|
|
405
401
|
bindMatch: F,
|
|
406
402
|
stringValue: c,
|
|
407
|
-
omitValue:
|
|
408
|
-
toggleValue:
|
|
403
|
+
omitValue: p,
|
|
404
|
+
toggleValue: B,
|
|
409
405
|
delimitArray: k
|
|
410
406
|
};
|
|
411
407
|
}
|
|
412
|
-
function
|
|
408
|
+
function le(o, m, v = {}, l = {}) {
|
|
413
409
|
if (!o || !m || !o[m])
|
|
414
410
|
throw new Error("Table has not been provided with valid props and key.");
|
|
415
|
-
|
|
416
|
-
...
|
|
417
|
-
only: [...
|
|
411
|
+
l = {
|
|
412
|
+
...l,
|
|
413
|
+
only: [...l.only ?? [], m.toString()]
|
|
418
414
|
};
|
|
419
|
-
const i =
|
|
415
|
+
const i = g(() => o[m]), u = X(), b = ee(o, m, l), f = g(() => i.value.config), A = g(() => i.value.meta), S = g(
|
|
420
416
|
() => {
|
|
421
417
|
var t;
|
|
422
|
-
return ((t = i.value.columns) == null ? void 0 : t.filter(({ active:
|
|
418
|
+
return ((t = i.value.columns) == null ? void 0 : t.filter(({ active: a, hidden: s }) => a && !s).map((a) => {
|
|
423
419
|
var s;
|
|
424
420
|
return {
|
|
425
|
-
...
|
|
426
|
-
isSorting: (s =
|
|
427
|
-
toggleSort: (w = {}) => U(
|
|
421
|
+
...a,
|
|
422
|
+
isSorting: (s = a.sort) == null ? void 0 : s.active,
|
|
423
|
+
toggleSort: (w = {}) => U(a, w)
|
|
428
424
|
};
|
|
429
425
|
})) ?? [];
|
|
430
426
|
}
|
|
431
|
-
), k =
|
|
427
|
+
), k = g(
|
|
432
428
|
() => {
|
|
433
429
|
var t;
|
|
434
|
-
return ((t = i.value.columns) == null ? void 0 : t.filter(({ hidden:
|
|
435
|
-
...
|
|
436
|
-
toggle: (s = {}) => N(
|
|
430
|
+
return ((t = i.value.columns) == null ? void 0 : t.filter(({ hidden: a }) => !a).map((a) => ({
|
|
431
|
+
...a,
|
|
432
|
+
toggle: (s = {}) => N(a, s)
|
|
437
433
|
}))) ?? [];
|
|
438
434
|
}
|
|
439
|
-
), c =
|
|
435
|
+
), c = g(
|
|
440
436
|
() => i.value.records.map((t) => ({
|
|
441
|
-
record: (({ actions:
|
|
437
|
+
record: (({ actions: a, ...s }) => s)(t),
|
|
442
438
|
/** Perform this action when the record is clicked */
|
|
443
|
-
default: (
|
|
439
|
+
default: (a = {}) => {
|
|
444
440
|
const s = t.actions.find(
|
|
445
441
|
(w) => w.default
|
|
446
442
|
);
|
|
447
|
-
s &&
|
|
443
|
+
s && C(s, t, a);
|
|
448
444
|
},
|
|
449
445
|
/** The actions available for the record */
|
|
450
|
-
actions: t.actions.map((
|
|
451
|
-
...
|
|
446
|
+
actions: t.actions.map((a) => ({
|
|
447
|
+
...a,
|
|
452
448
|
/** Executes this action */
|
|
453
|
-
execute: (s = {}) =>
|
|
449
|
+
execute: (s = {}) => C(a, t, s)
|
|
454
450
|
})),
|
|
455
451
|
/** Selects this record */
|
|
456
452
|
select: () => u.select(y(t)),
|
|
@@ -463,43 +459,43 @@ function ae(o, m, d = {}, a = {}) {
|
|
|
463
459
|
/** Bind the record to a checkbox */
|
|
464
460
|
bind: () => u.bind(y(t)),
|
|
465
461
|
/** Get the value of the record for the column */
|
|
466
|
-
value: (
|
|
467
|
-
const s = K(
|
|
462
|
+
value: (a) => {
|
|
463
|
+
const s = K(a);
|
|
468
464
|
return s in t ? t[s].value : null;
|
|
469
465
|
},
|
|
470
466
|
/** Get the extra data of the record for the column */
|
|
471
|
-
extra: (
|
|
472
|
-
const s = K(
|
|
467
|
+
extra: (a) => {
|
|
468
|
+
const s = K(a);
|
|
473
469
|
return s in t ? t[s].extra : null;
|
|
474
470
|
}
|
|
475
471
|
}))
|
|
476
|
-
),
|
|
472
|
+
), p = g(
|
|
477
473
|
() => i.value.actions.bulk.map((t) => ({
|
|
478
474
|
...t,
|
|
479
475
|
/** Executes this bulk action */
|
|
480
|
-
execute: (
|
|
476
|
+
execute: (a = {}) => L(t, a)
|
|
481
477
|
}))
|
|
482
|
-
),
|
|
478
|
+
), G = g(
|
|
483
479
|
() => i.value.actions.page.map((t) => ({
|
|
484
480
|
...t,
|
|
485
481
|
/** Executes this page action */
|
|
486
|
-
execute: (
|
|
482
|
+
execute: (a = {}) => M(t, a)
|
|
487
483
|
}))
|
|
488
|
-
),
|
|
484
|
+
), B = g(
|
|
489
485
|
() => {
|
|
490
486
|
var t;
|
|
491
|
-
return ((t = i.value.recordsPerPage) == null ? void 0 : t.map((
|
|
492
|
-
...
|
|
487
|
+
return ((t = i.value.recordsPerPage) == null ? void 0 : t.map((a) => ({
|
|
488
|
+
...a,
|
|
493
489
|
/** Changes the number of records to display per page */
|
|
494
|
-
apply: (s = {}) => T(
|
|
490
|
+
apply: (s = {}) => T(a, s)
|
|
495
491
|
}))) ?? [];
|
|
496
492
|
}
|
|
497
|
-
),
|
|
493
|
+
), j = g(
|
|
498
494
|
() => {
|
|
499
495
|
var t;
|
|
500
|
-
return (t = i.value.recordsPerPage) == null ? void 0 : t.find(({ active:
|
|
496
|
+
return (t = i.value.recordsPerPage) == null ? void 0 : t.find(({ active: a }) => a);
|
|
501
497
|
}
|
|
502
|
-
), h =
|
|
498
|
+
), h = g(() => ({
|
|
503
499
|
...i.value.paginator,
|
|
504
500
|
next: (t = {}) => {
|
|
505
501
|
"nextLink" in h.value && h.value.nextLink && P(h.value.nextLink, t);
|
|
@@ -516,42 +512,42 @@ function ae(o, m, d = {}, a = {}) {
|
|
|
516
512
|
..."links" in i.value.paginator && i.value.paginator.links ? {
|
|
517
513
|
links: i.value.paginator.links.map((t) => ({
|
|
518
514
|
...t,
|
|
519
|
-
navigate: (
|
|
515
|
+
navigate: (a = {}) => t.url && P(t.url, a)
|
|
520
516
|
}))
|
|
521
517
|
} : {}
|
|
522
|
-
})), E =
|
|
518
|
+
})), E = g(
|
|
523
519
|
() => i.value.records.length > 0 && i.value.records.every(
|
|
524
520
|
(t) => u.selected(y(t))
|
|
525
521
|
)
|
|
526
522
|
);
|
|
527
523
|
function y(t) {
|
|
528
|
-
return t[f.value.
|
|
524
|
+
return t[f.value.key].value;
|
|
529
525
|
}
|
|
530
526
|
function K(t) {
|
|
531
527
|
return typeof t == "string" ? t : t.name;
|
|
532
528
|
}
|
|
533
|
-
function P(t,
|
|
529
|
+
function P(t, a = {}) {
|
|
534
530
|
x.visit(t, {
|
|
535
531
|
preserveScroll: !0,
|
|
536
532
|
preserveState: !0,
|
|
537
|
-
...a,
|
|
538
533
|
...l,
|
|
534
|
+
...a,
|
|
539
535
|
method: "get"
|
|
540
536
|
});
|
|
541
537
|
}
|
|
542
|
-
function
|
|
538
|
+
function C(t, a, s = {}) {
|
|
543
539
|
var F, e;
|
|
544
540
|
I(
|
|
545
541
|
t,
|
|
546
542
|
f.value.endpoint,
|
|
547
543
|
{
|
|
548
544
|
table: i.value.id,
|
|
549
|
-
id: y(
|
|
545
|
+
id: y(a)
|
|
550
546
|
},
|
|
551
547
|
s
|
|
552
|
-
) || (e = (F =
|
|
548
|
+
) || (e = (F = v.recordActions) == null ? void 0 : F[t.name]) == null || e.call(F, a);
|
|
553
549
|
}
|
|
554
|
-
function L(t,
|
|
550
|
+
function L(t, a = {}) {
|
|
555
551
|
I(
|
|
556
552
|
t,
|
|
557
553
|
f.value.endpoint,
|
|
@@ -561,52 +557,52 @@ function ae(o, m, d = {}, a = {}) {
|
|
|
561
557
|
only: Array.from(u.selection.value.only),
|
|
562
558
|
except: Array.from(u.selection.value.except)
|
|
563
559
|
},
|
|
564
|
-
|
|
560
|
+
a
|
|
565
561
|
);
|
|
566
562
|
}
|
|
567
|
-
function M(t,
|
|
563
|
+
function M(t, a = {}) {
|
|
568
564
|
I(
|
|
569
565
|
t,
|
|
570
566
|
f.value.endpoint,
|
|
571
567
|
{
|
|
572
568
|
table: i.value.id
|
|
573
569
|
},
|
|
574
|
-
|
|
570
|
+
a
|
|
575
571
|
);
|
|
576
572
|
}
|
|
577
|
-
function T(t,
|
|
573
|
+
function T(t, a = {}) {
|
|
578
574
|
x.reload({
|
|
579
|
-
...a,
|
|
580
575
|
...l,
|
|
576
|
+
...a,
|
|
581
577
|
data: {
|
|
582
|
-
[f.value.
|
|
583
|
-
[f.value.
|
|
578
|
+
[f.value.record]: t.value,
|
|
579
|
+
[f.value.page]: void 0
|
|
584
580
|
}
|
|
585
581
|
});
|
|
586
582
|
}
|
|
587
|
-
function U(t,
|
|
583
|
+
function U(t, a = {}) {
|
|
588
584
|
t.sort && x.reload({
|
|
589
|
-
...a,
|
|
590
585
|
...l,
|
|
586
|
+
...a,
|
|
591
587
|
data: {
|
|
592
|
-
[f.value.
|
|
588
|
+
[f.value.sort]: b.omitValue(t.sort.next)
|
|
593
589
|
}
|
|
594
590
|
});
|
|
595
591
|
}
|
|
596
|
-
function N(t,
|
|
592
|
+
function N(t, a = {}) {
|
|
597
593
|
const s = b.toggleValue(
|
|
598
594
|
t.name,
|
|
599
595
|
S.value.map(({ name: w }) => w)
|
|
600
596
|
);
|
|
601
597
|
x.reload({
|
|
602
|
-
...a,
|
|
603
598
|
...l,
|
|
599
|
+
...a,
|
|
604
600
|
data: {
|
|
605
|
-
[f.value.
|
|
601
|
+
[f.value.column]: b.delimitArray(s)
|
|
606
602
|
}
|
|
607
603
|
});
|
|
608
604
|
}
|
|
609
|
-
function
|
|
605
|
+
function W() {
|
|
610
606
|
u.select(
|
|
611
607
|
...i.value.records.map(
|
|
612
608
|
(t) => y(t)
|
|
@@ -623,7 +619,7 @@ function ae(o, m, d = {}, a = {}) {
|
|
|
623
619
|
function D() {
|
|
624
620
|
return {
|
|
625
621
|
"onUpdate:modelValue": (t) => {
|
|
626
|
-
t ?
|
|
622
|
+
t ? W() : R();
|
|
627
623
|
},
|
|
628
624
|
modelValue: E.value
|
|
629
625
|
};
|
|
@@ -640,17 +636,17 @@ function ae(o, m, d = {}, a = {}) {
|
|
|
640
636
|
/** The records of the table */
|
|
641
637
|
records: c,
|
|
642
638
|
/** The available bulk actions */
|
|
643
|
-
bulkActions:
|
|
639
|
+
bulkActions: p,
|
|
644
640
|
/** The available page actions */
|
|
645
|
-
pageActions:
|
|
641
|
+
pageActions: G,
|
|
646
642
|
/** The available number of records to display per page */
|
|
647
|
-
rowsPerPage:
|
|
643
|
+
rowsPerPage: B,
|
|
648
644
|
/** The current record per page item */
|
|
649
|
-
currentPage:
|
|
645
|
+
currentPage: j,
|
|
650
646
|
/** The pagination metadata */
|
|
651
647
|
paginator: h,
|
|
652
648
|
/** Execute an inline action */
|
|
653
|
-
executeInlineAction:
|
|
649
|
+
executeInlineAction: C,
|
|
654
650
|
/** Execute a bulk action */
|
|
655
651
|
executeBulkAction: L,
|
|
656
652
|
/** Execute a page action */
|
|
@@ -664,7 +660,7 @@ function ae(o, m, d = {}, a = {}) {
|
|
|
664
660
|
/** Deselect the given records */
|
|
665
661
|
deselect: (t) => u.deselect(y(t)),
|
|
666
662
|
/** Select records on the current page */
|
|
667
|
-
selectPage:
|
|
663
|
+
selectPage: W,
|
|
668
664
|
/** Deselect records on the current page */
|
|
669
665
|
deselectPage: R,
|
|
670
666
|
/** Toggle the selection of the given records */
|
|
@@ -690,5 +686,5 @@ function ae(o, m, d = {}, a = {}) {
|
|
|
690
686
|
});
|
|
691
687
|
}
|
|
692
688
|
export {
|
|
693
|
-
|
|
689
|
+
le as useTable
|
|
694
690
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(P,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("vue"),require("@inertiajs/vue3")):typeof define=="function"&&define.amd?define(["exports","vue","@inertiajs/vue3"],c):(P=typeof globalThis<"u"?globalThis:P||self,c(P["@honed/table"]={},P.Vue,P.Inertia))})(this,function(P,c,b){"use strict";function _(){const r=c.ref({all:!1,only:new Set,except:new Set});function p(){r.value.all=!0,r.value.only.clear(),r.value.except.clear()}function v(){r.value.all=!1,r.value.only.clear(),r.value.except.clear()}function a(...s){s.forEach(g=>r.value.except.delete(g)),s.forEach(g=>r.value.only.add(g))}function i(...s){s.forEach(g=>r.value.except.add(g)),s.forEach(g=>r.value.only.delete(g))}function u(s,g){if(x(s)||g===!1)return i(s);if(!x(s)||g===!0)return a(s)}function x(s){return r.value.all?!r.value.except.has(s):r.value.only.has(s)}const m=c.computed(()=>r.value.all&&r.value.except.size===0),A=c.computed(()=>r.value.only.size>0||m.value);function S(s){return{"onUpdate:modelValue":g=>{g?a(s):i(s)},modelValue:x(s),value:s}}function k(){return{"onUpdate:modelValue":s=>{s?p():v()},modelValue:m.value,value:m.value}}return{allSelected:m,selection:r,hasSelected:A,selectAll:p,deselectAll:v,select:a,deselect:i,toggle:u,selected:x,bind:S,bindAll:k}}function D(r,p,v={},a={}){return r.route?(b.router.visit(r.route.href,{...a,method:r.route.method}),!0):r.action&&p?(b.router.post(p,{...v,name:r.name,type:r.type},a),!0):!1}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Y=()=>{};function Q(r,p){function v(...a){return new Promise((i,u)=>{Promise.resolve(r(()=>p.apply(this,a),{fn:p,thisArg:this,args:a})).then(i).catch(u)})}return v}function X(r,p={}){let v,a,i=Y;const u=m=>{clearTimeout(m),i(),i=Y};let x;return m=>{const A=c.toValue(r),S=c.toValue(p.maxWait);return v&&u(v),A<=0||S!==void 0&&S<=0?(a&&(u(a),a=null),Promise.resolve(m())):new Promise((k,s)=>{i=p.rejectOnCancel?s:k,x=m,S&&!a&&(a=setTimeout(()=>{v&&u(v),a=null,k(x())},S)),v=setTimeout(()=>{a&&u(a),a=null,k(m())},A)})}}function B(r,p=200,v={}){return Q(X(p,v),r)}function Z(r,p,v={}){const a=c.computed(()=>r[p]),i=c.computed(()=>{var e;return((e=a.value.filters)==null?void 0:e.map(n=>({...n,apply:(o,f={})=>T(n,o,f),clear:(o={})=>N(n,o),bind:()=>l(n.name)})))??[]}),u=c.computed(()=>{var e;return((e=a.value.sorts)==null?void 0:e.map(n=>({...n,apply:(o={})=>M(n,n.direction,o),clear:(o={})=>z(o),bind:()=>d(n)})))??[]}),x=c.computed(()=>{var e;return(e=a.value.searches)==null?void 0:e.map(n=>({...n,apply:(o={})=>U(n,o),clear:(o={})=>U(n,o),bind:()=>j(n)}))}),m=c.computed(()=>{var e;return((e=a.value.filters)==null?void 0:e.filter(({active:n})=>n))??[]}),A=c.computed(()=>{var e;return(e=a.value.sorts)==null?void 0:e.find(({active:n})=>n)}),S=c.computed(()=>{var e;return((e=a.value.searches)==null?void 0:e.filter(({active:n})=>n))??[]});function k(e){return Array.isArray(e)?e.join(a.value.config.delimiter):e}function s(e){return typeof e!="string"?e:e.trim().replace(/\s+/g,"+")}function g(e){if(!["",null,void 0,[]].includes(e))return e}function I(e){return[k,s,g].reduce((n,o)=>o(n),e)}function C(e,n){return n=Array.isArray(n)?n:[n],n.includes(e)?n.filter(o=>o!==e):[...n,e]}function W(e){var n;return(n=a.value.filters)==null?void 0:n.find(o=>o.name===e)}function h(e,n=null){var o;return(o=a.value.sorts)==null?void 0:o.find(f=>f.name===e&&f.direction===n)}function F(e){var n;return(n=a.value.searches)==null?void 0:n.find(o=>o.name===e)}function y(e){return e?typeof e=="string"?m.value.some(n=>n.name===e):e.active:!!m.value.length}function K(e){var n;return e?typeof e=="string"?((n=A.value)==null?void 0:n.name)===e:e.active:!!A.value}function w(e){var n;return e?typeof e=="string"?(n=S.value)==null?void 0:n.some(o=>o.name===e):e.active:!!a.value.config.search}function q(e,n={}){const o=Object.fromEntries(Object.entries(e).map(([f,V])=>[f,I(V)]));b.router.reload({...v,...n,data:o})}function T(e,n,o={}){const f=typeof e=="string"?W(e):e;if(!f){console.warn(`Filter [${e}] does not exist.`);return}"multiple"in f&&f.multiple&&n!==void 0&&(n=C(n,f.value)),b.router.reload({...v,...o,data:{[f.name]:I(n)}})}function M(e,n=null,o={}){const f=typeof e=="string"?h(e,n):e;if(!f){console.warn(`Sort [${e}] does not exist.`);return}b.router.reload({...v,...o,data:{[a.value.config.sorts]:g(f.next)}})}function E(e,n={}){e=[s,g].reduce((o,f)=>f(o),e),b.router.reload({...v,...n,data:{[a.value.config.searches]:e}})}function U(e,n={}){if(!a.value.config.matches){console.warn("Matches key is not set.");return}const o=typeof e=="string"?F(e):e;if(!o){console.warn(`Match [${e}] does not exist.`);return}const f=C(o.name,S.value.map(({name:V})=>V));b.router.reload({...v,...n,data:{[a.value.config.matches]:k(f)}})}function N(e,n={}){T(e,void 0,n)}function z(e={}){b.router.reload({...v,...e,data:{[a.value.config.sorts]:void 0}})}function R(e={}){E(void 0,e)}function H(e={}){if(!a.value.config.matches){console.warn("Matches key is not set.");return}b.router.reload({...v,...e,data:{[a.value.config.matches]:void 0}})}function t(e={}){var n;b.router.reload({...v,...e,data:{[a.value.config.searches]:void 0,[a.value.config.sorts]:void 0,[a.value.config.matches]:void 0,...Object.fromEntries(((n=a.value.filters)==null?void 0:n.map(o=>[o.name,void 0]))??[])}})}function l(e,n={}){const o=typeof e=="string"?W(e):e;if(!o){console.warn(`Filter [${e}] does not exist.`);return}const f=o.value,{debounce:V=250,transform:G=J=>J,...$}=n;return{"onUpdate:modelValue":B(J=>{T(o,G(J),$)},V),modelValue:f}}function d(e,n={}){const o=typeof e=="string"?h(e):e;if(!o){console.warn(`Sort [${e}] does not exist.`);return}const{debounce:f=0,transform:V,...G}=n;return{onClick:B(()=>{var $;M(o,($=A.value)==null?void 0:$.direction,G)},f)}}function L(e={}){const{debounce:n=700,transform:o,...f}=e;return{"onUpdate:modelValue":B(V=>{E(V,f)},n),modelValue:a.value.config.search??""}}function j(e,n={}){const o=typeof e=="string"?F(e):e;if(!o){console.warn(`Match [${e}] does not exist.`);return}const{debounce:f=0,transform:V,...G}=n;return{"onUpdate:modelValue":B($=>{U($,G)},f),modelValue:w(o),value:o.name}}return{filters:i,sorts:u,searches:x,getFilter:W,getSort:h,getSearch:F,currentFilters:m,currentSort:A,currentSearches:S,isFiltering:y,isSorting:K,isSearching:w,apply:q,applyFilter:T,applySort:M,applySearch:E,applyMatch:U,clearFilter:N,clearSort:z,clearSearch:R,clearMatch:H,reset:t,bindFilter:l,bindSort:d,bindSearch:L,bindMatch:j,stringValue:s,omitValue:g,toggleValue:C,delimitArray:k}}function O(r,p,v={},a={}){if(!r||!p||!r[p])throw new Error("Table has not been provided with valid props and key.");a={...a,only:[...a.only??[],p.toString()]};const i=c.computed(()=>r[p]),u=_(),x=Z(r,p,a),m=c.computed(()=>i.value.config),A=c.computed(()=>i.value.meta),S=c.computed(()=>{var t;return((t=i.value.columns)==null?void 0:t.filter(({active:l,hidden:d})=>l&&!d).map(l=>{var d;return{...l,isSorting:(d=l.sort)==null?void 0:d.active,toggleSort:(L={})=>U(l,L)}}))??[]}),k=c.computed(()=>{var t;return((t=i.value.columns)==null?void 0:t.filter(({hidden:l})=>!l).map(l=>({...l,toggle:(d={})=>N(l,d)})))??[]}),s=c.computed(()=>i.value.records.map(t=>({record:(({actions:l,...d})=>d)(t),default:(l={})=>{const d=t.actions.find(L=>L.default);d&&q(d,t,l)},actions:t.actions.map(l=>({...l,execute:(d={})=>q(l,t,d)})),select:()=>u.select(y(t)),deselect:()=>u.deselect(y(t)),toggle:()=>u.toggle(y(t)),selected:u.selected(y(t)),bind:()=>u.bind(y(t)),value:l=>{const d=K(l);return d in t?t[d].value:null},extra:l=>{const d=K(l);return d in t?t[d].extra:null}}))),g=c.computed(()=>i.value.actions.bulk.map(t=>({...t,execute:(l={})=>T(t,l)}))),I=c.computed(()=>i.value.actions.page.map(t=>({...t,execute:(l={})=>M(t,l)}))),C=c.computed(()=>{var t;return((t=i.value.recordsPerPage)==null?void 0:t.map(l=>({...l,apply:(d={})=>E(l,d)})))??[]}),W=c.computed(()=>{var t;return(t=i.value.recordsPerPage)==null?void 0:t.find(({active:l})=>l)}),h=c.computed(()=>({...i.value.paginator,next:(t={})=>{"nextLink"in h.value&&h.value.nextLink&&w(h.value.nextLink,t)},previous:(t={})=>{"prevLink"in h.value&&h.value.prevLink&&w(h.value.prevLink,t)},first:(t={})=>{"firstLink"in h.value&&h.value.firstLink&&w(h.value.firstLink,t)},last:(t={})=>{"lastLink"in h.value&&h.value.lastLink&&w(h.value.lastLink,t)},..."links"in i.value.paginator&&i.value.paginator.links?{links:i.value.paginator.links.map(t=>({...t,navigate:(l={})=>t.url&&w(t.url,l)}))}:{}})),F=c.computed(()=>i.value.records.length>0&&i.value.records.every(t=>u.selected(y(t))));function y(t){return t[m.value.record].value}function K(t){return typeof t=="string"?t:t.name}function w(t,l={}){b.router.visit(t,{preserveScroll:!0,preserveState:!0,...a,...l,method:"get"})}function q(t,l,d={}){var j,e;D(t,m.value.endpoint,{table:i.value.id,id:y(l)},d)||(e=(j=v.recordActions)==null?void 0:j[t.name])==null||e.call(j,l)}function T(t,l={}){D(t,m.value.endpoint,{table:i.value.id,all:u.selection.value.all,only:Array.from(u.selection.value.only),except:Array.from(u.selection.value.except)},l)}function M(t,l={}){D(t,m.value.endpoint,{table:i.value.id},l)}function E(t,l={}){b.router.reload({...a,...l,data:{[m.value.records]:t.value,[m.value.pages]:void 0}})}function U(t,l={}){t.sort&&b.router.reload({...a,...l,data:{[m.value.sorts]:x.omitValue(t.sort.next)}})}function N(t,l={}){const d=x.toggleValue(t.name,S.value.map(({name:L})=>L));b.router.reload({...a,...l,data:{[m.value.columns]:x.delimitArray(d)}})}function z(){u.select(...i.value.records.map(t=>y(t)))}function R(){u.deselect(...i.value.records.map(t=>y(t)))}function H(){return{"onUpdate:modelValue":t=>{t?z():R()},modelValue:F.value}}return c.reactive({getRecordKey:y,meta:A,headings:S,columns:k,records:s,bulkActions:g,pageActions:I,rowsPerPage:C,currentPage:W,paginator:h,executeInlineAction:q,executeBulkAction:T,executePageAction:M,applyPage:E,selection:u.selection,select:t=>u.select(y(t)),deselect:t=>u.deselect(y(t)),selectPage:z,deselectPage:R,toggle:t=>u.toggle(y(t)),selected:t=>u.selected(y(t)),selectAll:u.selectAll,deselectAll:u.deselectAll,isPageSelected:F,hasSelected:u.hasSelected,bindCheckbox:t=>u.bind(y(t)),bindPage:H,bindAll:u.bindAll,...x})}P.useTable=O,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(P,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("vue"),require("@inertiajs/vue3")):typeof define=="function"&&define.amd?define(["exports","vue","@inertiajs/vue3"],c):(P=typeof globalThis<"u"?globalThis:P||self,c(P["@honed/table"]={},P.Vue,P.Inertia))})(this,function(P,c,b){"use strict";function _(){const r=c.ref({all:!1,only:new Set,except:new Set});function p(){r.value.all=!0,r.value.only.clear(),r.value.except.clear()}function f(){r.value.all=!1,r.value.only.clear(),r.value.except.clear()}function a(...s){s.forEach(g=>r.value.except.delete(g)),s.forEach(g=>r.value.only.add(g))}function i(...s){s.forEach(g=>r.value.except.add(g)),s.forEach(g=>r.value.only.delete(g))}function u(s,g){if(x(s)||g===!1)return i(s);if(!x(s)||g===!0)return a(s)}function x(s){return r.value.all?!r.value.except.has(s):r.value.only.has(s)}const m=c.computed(()=>r.value.all&&r.value.except.size===0),A=c.computed(()=>r.value.only.size>0||m.value);function S(s){return{"onUpdate:modelValue":g=>{g?a(s):i(s)},modelValue:x(s),value:s}}function k(){return{"onUpdate:modelValue":s=>{s?p():f()},modelValue:m.value,value:m.value}}return{allSelected:m,selection:r,hasSelected:A,selectAll:p,deselectAll:f,select:a,deselect:i,toggle:u,selected:x,bind:S,bindAll:k}}function D(r,p,f={},a={}){return r.route?(b.router.visit(r.route.url,{...a,method:r.route.method}),!0):r.action&&p?(b.router.post(p,{...f,name:r.name,type:r.type},a),!0):!1}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Y=()=>{};function Q(r,p){function f(...a){return new Promise((i,u)=>{Promise.resolve(r(()=>p.apply(this,a),{fn:p,thisArg:this,args:a})).then(i).catch(u)})}return f}function X(r,p={}){let f,a,i=Y;const u=m=>{clearTimeout(m),i(),i=Y};let x;return m=>{const A=c.toValue(r),S=c.toValue(p.maxWait);return f&&u(f),A<=0||S!==void 0&&S<=0?(a&&(u(a),a=null),Promise.resolve(m())):new Promise((k,s)=>{i=p.rejectOnCancel?s:k,x=m,S&&!a&&(a=setTimeout(()=>{f&&u(f),a=null,k(x())},S)),f=setTimeout(()=>{a&&u(a),a=null,k(m())},A)})}}function G(r,p=200,f={}){return Q(X(p,f),r)}function Z(r,p,f={}){const a=c.computed(()=>r[p]),i=c.computed(()=>{var e;return((e=a.value.filters)==null?void 0:e.map(n=>({...n,apply:(o,v={})=>T(n,o,v),clear:(o={})=>N(n,o),bind:()=>l(n.name)})))??[]}),u=c.computed(()=>{var e;return((e=a.value.sorts)==null?void 0:e.map(n=>({...n,apply:(o={})=>E(n,n.direction,o),clear:(o={})=>q(o),bind:()=>d(n)})))??[]}),x=c.computed(()=>{var e;return(e=a.value.searches)==null?void 0:e.map(n=>({...n,apply:(o={})=>U(n,o),clear:(o={})=>U(n,o),bind:()=>j(n)}))}),m=c.computed(()=>{var e;return((e=a.value.filters)==null?void 0:e.filter(({active:n})=>n))??[]}),A=c.computed(()=>{var e;return(e=a.value.sorts)==null?void 0:e.find(({active:n})=>n)}),S=c.computed(()=>{var e;return((e=a.value.searches)==null?void 0:e.filter(({active:n})=>n))??[]});function k(e){return Array.isArray(e)?e.join(a.value.config.delimiter):e}function s(e){return typeof e!="string"?e:e.trim().replace(/\s+/g,"+")}function g(e){if(!["",null,void 0,[]].includes(e))return e}function B(e){return[k,s,g].reduce((n,o)=>o(n),e)}function I(e,n){return n=Array.isArray(n)?n:[n],n.includes(e)?n.filter(o=>o!==e):[...n,e]}function C(e){var n;return(n=a.value.filters)==null?void 0:n.find(o=>o.name===e)}function h(e,n=null){var o;return(o=a.value.sorts)==null?void 0:o.find(v=>v.name===e&&v.direction===n)}function F(e){var n;return(n=a.value.searches)==null?void 0:n.find(o=>o.name===e)}function y(e){return e?typeof e=="string"?m.value.some(n=>n.name===e):e.active:!!m.value.length}function K(e){var n;return e?typeof e=="string"?((n=A.value)==null?void 0:n.name)===e:e.active:!!A.value}function w(e){var n;return e?typeof e=="string"?(n=S.value)==null?void 0:n.some(o=>o.name===e):e.active:!!a.value.config.term}function W(e,n={}){const o=Object.fromEntries(Object.entries(e).map(([v,V])=>[v,B(V)]));b.router.reload({...f,...n,data:o})}function T(e,n,o={}){const v=typeof e=="string"?C(e):e;if(!v){console.warn(`Filter [${e}] does not exist.`);return}b.router.reload({...f,...o,data:{[v.name]:B(n)}})}function E(e,n=null,o={}){const v=typeof e=="string"?h(e,n):e;if(!v){console.warn(`Sort [${e}] does not exist.`);return}b.router.reload({...f,...o,data:{[a.value.config.sort]:g(v.next)}})}function M(e,n={}){e=[s,g].reduce((o,v)=>v(o),e),b.router.reload({...f,...n,data:{[a.value.config.search]:e}})}function U(e,n={}){const o=typeof e=="string"?F(e):e;if(!o){console.warn(`Match [${e}] does not exist.`);return}const v=I(o.name,S.value.map(({name:V})=>V));b.router.reload({...f,...n,data:{[a.value.config.match]:k(v)}})}function N(e,n={}){T(e,void 0,n)}function q(e={}){b.router.reload({...f,...e,data:{[a.value.config.sort]:void 0}})}function R(e={}){M(void 0,e)}function H(e={}){if(!a.value.config.match){console.warn("Matches key is not set.");return}b.router.reload({...f,...e,data:{[a.value.config.match]:void 0}})}function t(e={}){var n;b.router.reload({...f,...e,data:{[a.value.config.search]:void 0,[a.value.config.sort]:void 0,[a.value.config.match]:void 0,...Object.fromEntries(((n=a.value.filters)==null?void 0:n.map(o=>[o.name,void 0]))??[])}})}function l(e,n={}){const o=typeof e=="string"?C(e):e;if(!o){console.warn(`Filter [${e}] does not exist.`);return}const v=o.value,{debounce:V=250,transform:z=J=>J,...$}=n;return{"onUpdate:modelValue":G(J=>{T(o,z(J),$)},V),modelValue:v}}function d(e,n={}){const o=typeof e=="string"?h(e):e;if(!o){console.warn(`Sort [${e}] does not exist.`);return}const{debounce:v=0,transform:V,...z}=n;return{onClick:G(()=>{var $;E(o,($=A.value)==null?void 0:$.direction,z)},v)}}function L(e={}){const{debounce:n=700,transform:o,...v}=e;return{"onUpdate:modelValue":G(V=>{M(V,v)},n),modelValue:a.value.config.term??""}}function j(e,n={}){const o=typeof e=="string"?F(e):e;if(!o){console.warn(`Match [${e}] does not exist.`);return}const{debounce:v=0,transform:V,...z}=n;return{"onUpdate:modelValue":G($=>{U($,z)},v),modelValue:w(o),value:o.name}}return{filters:i,sorts:u,searches:x,getFilter:C,getSort:h,getSearch:F,currentFilters:m,currentSort:A,currentSearches:S,isFiltering:y,isSorting:K,isSearching:w,apply:W,applyFilter:T,applySort:E,applySearch:M,applyMatch:U,clearFilter:N,clearSort:q,clearSearch:R,clearMatch:H,reset:t,bindFilter:l,bindSort:d,bindSearch:L,bindMatch:j,stringValue:s,omitValue:g,toggleValue:I,delimitArray:k}}function O(r,p,f={},a={}){if(!r||!p||!r[p])throw new Error("Table has not been provided with valid props and key.");a={...a,only:[...a.only??[],p.toString()]};const i=c.computed(()=>r[p]),u=_(),x=Z(r,p,a),m=c.computed(()=>i.value.config),A=c.computed(()=>i.value.meta),S=c.computed(()=>{var t;return((t=i.value.columns)==null?void 0:t.filter(({active:l,hidden:d})=>l&&!d).map(l=>{var d;return{...l,isSorting:(d=l.sort)==null?void 0:d.active,toggleSort:(L={})=>U(l,L)}}))??[]}),k=c.computed(()=>{var t;return((t=i.value.columns)==null?void 0:t.filter(({hidden:l})=>!l).map(l=>({...l,toggle:(d={})=>N(l,d)})))??[]}),s=c.computed(()=>i.value.records.map(t=>({record:(({actions:l,...d})=>d)(t),default:(l={})=>{const d=t.actions.find(L=>L.default);d&&W(d,t,l)},actions:t.actions.map(l=>({...l,execute:(d={})=>W(l,t,d)})),select:()=>u.select(y(t)),deselect:()=>u.deselect(y(t)),toggle:()=>u.toggle(y(t)),selected:u.selected(y(t)),bind:()=>u.bind(y(t)),value:l=>{const d=K(l);return d in t?t[d].value:null},extra:l=>{const d=K(l);return d in t?t[d].extra:null}}))),g=c.computed(()=>i.value.actions.bulk.map(t=>({...t,execute:(l={})=>T(t,l)}))),B=c.computed(()=>i.value.actions.page.map(t=>({...t,execute:(l={})=>E(t,l)}))),I=c.computed(()=>{var t;return((t=i.value.recordsPerPage)==null?void 0:t.map(l=>({...l,apply:(d={})=>M(l,d)})))??[]}),C=c.computed(()=>{var t;return(t=i.value.recordsPerPage)==null?void 0:t.find(({active:l})=>l)}),h=c.computed(()=>({...i.value.paginator,next:(t={})=>{"nextLink"in h.value&&h.value.nextLink&&w(h.value.nextLink,t)},previous:(t={})=>{"prevLink"in h.value&&h.value.prevLink&&w(h.value.prevLink,t)},first:(t={})=>{"firstLink"in h.value&&h.value.firstLink&&w(h.value.firstLink,t)},last:(t={})=>{"lastLink"in h.value&&h.value.lastLink&&w(h.value.lastLink,t)},..."links"in i.value.paginator&&i.value.paginator.links?{links:i.value.paginator.links.map(t=>({...t,navigate:(l={})=>t.url&&w(t.url,l)}))}:{}})),F=c.computed(()=>i.value.records.length>0&&i.value.records.every(t=>u.selected(y(t))));function y(t){return t[m.value.key].value}function K(t){return typeof t=="string"?t:t.name}function w(t,l={}){b.router.visit(t,{preserveScroll:!0,preserveState:!0,...a,...l,method:"get"})}function W(t,l,d={}){var j,e;D(t,m.value.endpoint,{table:i.value.id,id:y(l)},d)||(e=(j=f.recordActions)==null?void 0:j[t.name])==null||e.call(j,l)}function T(t,l={}){D(t,m.value.endpoint,{table:i.value.id,all:u.selection.value.all,only:Array.from(u.selection.value.only),except:Array.from(u.selection.value.except)},l)}function E(t,l={}){D(t,m.value.endpoint,{table:i.value.id},l)}function M(t,l={}){b.router.reload({...a,...l,data:{[m.value.record]:t.value,[m.value.page]:void 0}})}function U(t,l={}){t.sort&&b.router.reload({...a,...l,data:{[m.value.sort]:x.omitValue(t.sort.next)}})}function N(t,l={}){const d=x.toggleValue(t.name,S.value.map(({name:L})=>L));b.router.reload({...a,...l,data:{[m.value.column]:x.delimitArray(d)}})}function q(){u.select(...i.value.records.map(t=>y(t)))}function R(){u.deselect(...i.value.records.map(t=>y(t)))}function H(){return{"onUpdate:modelValue":t=>{t?q():R()},modelValue:F.value}}return c.reactive({getRecordKey:y,meta:A,headings:S,columns:k,records:s,bulkActions:g,pageActions:B,rowsPerPage:I,currentPage:C,paginator:h,executeInlineAction:W,executeBulkAction:T,executePageAction:E,applyPage:M,selection:u.selection,select:t=>u.select(y(t)),deselect:t=>u.deselect(y(t)),selectPage:q,deselectPage:R,toggle:t=>u.toggle(y(t)),selected:t=>u.selected(y(t)),selectAll:u.selectAll,deselectAll:u.deselectAll,isPageSelected:F,hasSelected:u.hasSelected,bindCheckbox:t=>u.bind(y(t)),bindPage:H,bindAll:u.bindAll,...x})}P.useTable=O,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@honed/table",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "-",
|
|
7
7
|
"keywords": [
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@honed/action": "^0.
|
|
61
|
-
"@honed/refine": "^0.
|
|
60
|
+
"@honed/action": "^0.5.0",
|
|
61
|
+
"@honed/refine": "^0.5.3",
|
|
62
62
|
"@inertiajs/vue3": "^1.2.0||^2.0.0",
|
|
63
63
|
"@vueuse/core": "^11.0.0||^12.0.0",
|
|
64
64
|
"axios": "^1.2.0",
|