@honed/table 0.4.2 → 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/index.d.ts +11 -12
- package/dist/index.es.js +109 -115
- 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[];
|
|
@@ -146,7 +146,6 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
|
|
|
146
146
|
} | undefined;
|
|
147
147
|
type: string;
|
|
148
148
|
value: FilterValue;
|
|
149
|
-
/** Selects this record */
|
|
150
149
|
options: Option_2[];
|
|
151
150
|
multiple: boolean;
|
|
152
151
|
name: string;
|
|
@@ -293,7 +292,7 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
|
|
|
293
292
|
/** Get the value of the record for the column */
|
|
294
293
|
value: (column: Column<RecordType> | string) => RecordType[string] | RecordType[number] | RecordType[symbol] | null;
|
|
295
294
|
/** Get the extra data of the record for the column */
|
|
296
|
-
extra: (column: Column<RecordType> | string) => any;
|
|
295
|
+
extra: (column: Column<RecordType> | string) => Record<string, any> | null;
|
|
297
296
|
}[];
|
|
298
297
|
bulkActions: {
|
|
299
298
|
/** Executes this bulk action */
|
package/dist/index.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ref as _, computed as
|
|
1
|
+
import { ref as _, computed as p, 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 = _({
|
|
@@ -12,35 +12,35 @@ function X() {
|
|
|
12
12
|
function d() {
|
|
13
13
|
o.value.all = !1, o.value.only.clear(), o.value.except.clear();
|
|
14
14
|
}
|
|
15
|
-
function l(...
|
|
16
|
-
|
|
15
|
+
function l(...c) {
|
|
16
|
+
c.forEach((g) => o.value.except.delete(g)), c.forEach((g) => o.value.only.add(g));
|
|
17
17
|
}
|
|
18
|
-
function i(...
|
|
19
|
-
|
|
18
|
+
function i(...c) {
|
|
19
|
+
c.forEach((g) => o.value.except.add(g)), c.forEach((g) => o.value.only.delete(g));
|
|
20
20
|
}
|
|
21
|
-
function u(
|
|
22
|
-
if (b(
|
|
23
|
-
return i(
|
|
24
|
-
if (!b(
|
|
25
|
-
return l(
|
|
21
|
+
function u(c, g) {
|
|
22
|
+
if (b(c) || g === !1)
|
|
23
|
+
return i(c);
|
|
24
|
+
if (!b(c) || g === !0)
|
|
25
|
+
return l(c);
|
|
26
26
|
}
|
|
27
|
-
function b(
|
|
28
|
-
return o.value.all ? !o.value.except.has(
|
|
27
|
+
function b(c) {
|
|
28
|
+
return o.value.all ? !o.value.except.has(c) : o.value.only.has(c);
|
|
29
29
|
}
|
|
30
|
-
const f =
|
|
31
|
-
function S(
|
|
30
|
+
const f = p(() => o.value.all && o.value.except.size === 0), A = p(() => o.value.only.size > 0 || f.value);
|
|
31
|
+
function S(c) {
|
|
32
32
|
return {
|
|
33
|
-
"onUpdate:modelValue": (
|
|
34
|
-
|
|
33
|
+
"onUpdate:modelValue": (g) => {
|
|
34
|
+
g ? l(c) : i(c);
|
|
35
35
|
},
|
|
36
|
-
modelValue: b(
|
|
37
|
-
value:
|
|
36
|
+
modelValue: b(c),
|
|
37
|
+
value: c
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
function k() {
|
|
41
41
|
return {
|
|
42
|
-
"onUpdate:modelValue": (
|
|
43
|
-
|
|
42
|
+
"onUpdate:modelValue": (c) => {
|
|
43
|
+
c ? m() : d();
|
|
44
44
|
},
|
|
45
45
|
modelValue: f.value,
|
|
46
46
|
value: f.value
|
|
@@ -61,7 +61,7 @@ function X() {
|
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
63
|
function I(o, m, d = {}, l = {}) {
|
|
64
|
-
return o.route ? (x.visit(o.route.
|
|
64
|
+
return o.route ? (x.visit(o.route.url, {
|
|
65
65
|
...l,
|
|
66
66
|
method: o.route.method
|
|
67
67
|
}), !0) : o.action && m ? (x.post(
|
|
@@ -93,8 +93,8 @@ function O(o, m = {}) {
|
|
|
93
93
|
let b;
|
|
94
94
|
return (f) => {
|
|
95
95
|
const A = J(o), S = J(m.maxWait);
|
|
96
|
-
return d && u(d), A <= 0 || S !== void 0 && S <= 0 ? (l && (u(l), l = null), Promise.resolve(f())) : new Promise((k,
|
|
97
|
-
i = m.rejectOnCancel ?
|
|
96
|
+
return d && u(d), 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
98
|
d && u(d), l = null, k(b());
|
|
99
99
|
}, S)), d = setTimeout(() => {
|
|
100
100
|
l && u(l), l = null, k(f());
|
|
@@ -109,7 +109,7 @@ function q(o, m = 200, d = {}) {
|
|
|
109
109
|
);
|
|
110
110
|
}
|
|
111
111
|
function ee(o, m, d = {}) {
|
|
112
|
-
const l =
|
|
112
|
+
const l = p(() => o[m]), i = p(
|
|
113
113
|
() => {
|
|
114
114
|
var e;
|
|
115
115
|
return ((e = l.value.filters) == null ? void 0 : e.map((n) => ({
|
|
@@ -119,17 +119,17 @@ function ee(o, m, d = {}) {
|
|
|
119
119
|
bind: () => a(n.name)
|
|
120
120
|
}))) ?? [];
|
|
121
121
|
}
|
|
122
|
-
), u =
|
|
122
|
+
), u = p(
|
|
123
123
|
() => {
|
|
124
124
|
var e;
|
|
125
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 = {}) =>
|
|
129
|
-
bind: () =>
|
|
128
|
+
clear: (r = {}) => G(r),
|
|
129
|
+
bind: () => s(n)
|
|
130
130
|
}))) ?? [];
|
|
131
131
|
}
|
|
132
|
-
), b =
|
|
132
|
+
), b = p(
|
|
133
133
|
() => {
|
|
134
134
|
var e;
|
|
135
135
|
return (e = l.value.searches) == null ? void 0 : e.map((n) => ({
|
|
@@ -139,17 +139,17 @@ function ee(o, m, d = {}) {
|
|
|
139
139
|
bind: () => F(n)
|
|
140
140
|
}));
|
|
141
141
|
}
|
|
142
|
-
), f =
|
|
142
|
+
), f = p(
|
|
143
143
|
() => {
|
|
144
144
|
var e;
|
|
145
145
|
return ((e = l.value.filters) == null ? void 0 : e.filter(({ active: n }) => n)) ?? [];
|
|
146
146
|
}
|
|
147
|
-
), A =
|
|
147
|
+
), A = p(
|
|
148
148
|
() => {
|
|
149
149
|
var e;
|
|
150
150
|
return (e = l.value.sorts) == null ? void 0 : e.find(({ active: n }) => n);
|
|
151
151
|
}
|
|
152
|
-
), S =
|
|
152
|
+
), S = p(
|
|
153
153
|
() => {
|
|
154
154
|
var e;
|
|
155
155
|
return ((e = l.value.searches) == null ? void 0 : e.filter(({ active: n }) => n)) ?? [];
|
|
@@ -158,15 +158,15 @@ function ee(o, m, d = {}) {
|
|
|
158
158
|
function k(e) {
|
|
159
159
|
return Array.isArray(e) ? e.join(l.value.config.delimiter) : e;
|
|
160
160
|
}
|
|
161
|
-
function
|
|
161
|
+
function c(e) {
|
|
162
162
|
return typeof e != "string" ? e : e.trim().replace(/\s+/g, "+");
|
|
163
163
|
}
|
|
164
|
-
function
|
|
164
|
+
function g(e) {
|
|
165
165
|
if (!["", null, void 0, []].includes(e))
|
|
166
166
|
return e;
|
|
167
167
|
}
|
|
168
168
|
function B(e) {
|
|
169
|
-
return [k,
|
|
169
|
+
return [k, c, g].reduce(
|
|
170
170
|
(n, r) => r(n),
|
|
171
171
|
e
|
|
172
172
|
);
|
|
@@ -195,11 +195,11 @@ function ee(o, m, d = {}) {
|
|
|
195
195
|
var n;
|
|
196
196
|
return e ? typeof e == "string" ? ((n = A.value) == null ? void 0 : n.name) === e : e.active : !!A.value;
|
|
197
197
|
}
|
|
198
|
-
function
|
|
198
|
+
function V(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 : !!l.value.config.
|
|
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 z(e, n = {}) {
|
|
203
203
|
const r = Object.fromEntries(
|
|
204
204
|
Object.entries(e).map(([v, P]) => [v, B(P)])
|
|
205
205
|
);
|
|
@@ -233,27 +233,23 @@ function ee(o, m, d = {}) {
|
|
|
233
233
|
...d,
|
|
234
234
|
...r,
|
|
235
235
|
data: {
|
|
236
|
-
[l.value.config.
|
|
236
|
+
[l.value.config.sort]: g(v.next)
|
|
237
237
|
}
|
|
238
238
|
});
|
|
239
239
|
}
|
|
240
240
|
function T(e, n = {}) {
|
|
241
|
-
e = [
|
|
241
|
+
e = [c, g].reduce(
|
|
242
242
|
(r, v) => v(r),
|
|
243
243
|
e
|
|
244
244
|
), x.reload({
|
|
245
245
|
...d,
|
|
246
246
|
...n,
|
|
247
247
|
data: {
|
|
248
|
-
[l.value.config.
|
|
248
|
+
[l.value.config.search]: e
|
|
249
249
|
}
|
|
250
250
|
});
|
|
251
251
|
}
|
|
252
252
|
function U(e, n = {}) {
|
|
253
|
-
if (!l.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.`);
|
|
@@ -267,19 +263,19 @@ function ee(o, m, d = {}) {
|
|
|
267
263
|
...d,
|
|
268
264
|
...n,
|
|
269
265
|
data: {
|
|
270
|
-
[l.value.config.
|
|
266
|
+
[l.value.config.match]: k(v)
|
|
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 G(e = {}) {
|
|
278
274
|
x.reload({
|
|
279
275
|
...d,
|
|
280
276
|
...e,
|
|
281
277
|
data: {
|
|
282
|
-
[l.value.config.
|
|
278
|
+
[l.value.config.sort]: void 0
|
|
283
279
|
}
|
|
284
280
|
});
|
|
285
281
|
}
|
|
@@ -287,7 +283,7 @@ function ee(o, m, d = {}) {
|
|
|
287
283
|
T(void 0, e);
|
|
288
284
|
}
|
|
289
285
|
function D(e = {}) {
|
|
290
|
-
if (!l.value.config.
|
|
286
|
+
if (!l.value.config.match) {
|
|
291
287
|
console.warn("Matches key is not set.");
|
|
292
288
|
return;
|
|
293
289
|
}
|
|
@@ -295,7 +291,7 @@ function ee(o, m, d = {}) {
|
|
|
295
291
|
...d,
|
|
296
292
|
...e,
|
|
297
293
|
data: {
|
|
298
|
-
[l.value.config.
|
|
294
|
+
[l.value.config.match]: void 0
|
|
299
295
|
}
|
|
300
296
|
});
|
|
301
297
|
}
|
|
@@ -305,9 +301,9 @@ function ee(o, m, d = {}) {
|
|
|
305
301
|
...d,
|
|
306
302
|
...e,
|
|
307
303
|
data: {
|
|
308
|
-
[l.value.config.
|
|
309
|
-
[l.value.config.
|
|
310
|
-
[l.value.config.
|
|
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
308
|
((n = l.value.filters) == null ? void 0 : n.map((r) => [
|
|
313
309
|
r.name,
|
|
@@ -325,31 +321,31 @@ function ee(o, m, d = {}) {
|
|
|
325
321
|
}
|
|
326
322
|
const v = r.value, {
|
|
327
323
|
debounce: P = 250,
|
|
328
|
-
transform:
|
|
324
|
+
transform: W = (H) => H,
|
|
329
325
|
...$
|
|
330
326
|
} = n;
|
|
331
327
|
return {
|
|
332
328
|
"onUpdate:modelValue": q((H) => {
|
|
333
|
-
L(r,
|
|
329
|
+
L(r, W(H), $);
|
|
334
330
|
}, P),
|
|
335
331
|
modelValue: v
|
|
336
332
|
};
|
|
337
333
|
}
|
|
338
|
-
function
|
|
334
|
+
function s(e, n = {}) {
|
|
339
335
|
const r = typeof e == "string" ? h(e) : e;
|
|
340
336
|
if (!r) {
|
|
341
337
|
console.warn(`Sort [${e}] does not exist.`);
|
|
342
338
|
return;
|
|
343
339
|
}
|
|
344
|
-
const { debounce: v = 0, transform: P, ...
|
|
340
|
+
const { debounce: v = 0, transform: P, ...W } = n;
|
|
345
341
|
return {
|
|
346
342
|
onClick: q(() => {
|
|
347
343
|
var $;
|
|
348
|
-
M(r, ($ = A.value) == null ? void 0 : $.direction,
|
|
344
|
+
M(r, ($ = A.value) == null ? void 0 : $.direction, W);
|
|
349
345
|
}, v)
|
|
350
346
|
};
|
|
351
347
|
}
|
|
352
|
-
function
|
|
348
|
+
function w(e = {}) {
|
|
353
349
|
const { debounce: n = 700, transform: r, ...v } = e;
|
|
354
350
|
return {
|
|
355
351
|
"onUpdate:modelValue": q(
|
|
@@ -367,12 +363,12 @@ function ee(o, m, d = {}) {
|
|
|
367
363
|
console.warn(`Match [${e}] does not exist.`);
|
|
368
364
|
return;
|
|
369
365
|
}
|
|
370
|
-
const { debounce: v = 0, transform: P, ...
|
|
366
|
+
const { debounce: v = 0, transform: P, ...W } = n;
|
|
371
367
|
return {
|
|
372
368
|
"onUpdate:modelValue": q(($) => {
|
|
373
|
-
U($,
|
|
369
|
+
U($, W);
|
|
374
370
|
}, v),
|
|
375
|
-
modelValue:
|
|
371
|
+
modelValue: V(r),
|
|
376
372
|
value: r.name
|
|
377
373
|
};
|
|
378
374
|
}
|
|
@@ -388,23 +384,23 @@ function ee(o, m, d = {}) {
|
|
|
388
384
|
currentSearches: S,
|
|
389
385
|
isFiltering: y,
|
|
390
386
|
isSorting: K,
|
|
391
|
-
isSearching:
|
|
392
|
-
apply:
|
|
387
|
+
isSearching: V,
|
|
388
|
+
apply: z,
|
|
393
389
|
applyFilter: L,
|
|
394
390
|
applySort: M,
|
|
395
391
|
applySearch: T,
|
|
396
392
|
applyMatch: U,
|
|
397
393
|
clearFilter: N,
|
|
398
|
-
clearSort:
|
|
394
|
+
clearSort: G,
|
|
399
395
|
clearSearch: R,
|
|
400
396
|
clearMatch: D,
|
|
401
397
|
reset: t,
|
|
402
398
|
bindFilter: a,
|
|
403
|
-
bindSort:
|
|
404
|
-
bindSearch:
|
|
399
|
+
bindSort: s,
|
|
400
|
+
bindSearch: w,
|
|
405
401
|
bindMatch: F,
|
|
406
|
-
stringValue:
|
|
407
|
-
omitValue:
|
|
402
|
+
stringValue: c,
|
|
403
|
+
omitValue: g,
|
|
408
404
|
toggleValue: j,
|
|
409
405
|
delimitArray: k
|
|
410
406
|
};
|
|
@@ -416,41 +412,41 @@ function le(o, m, d = {}, l = {}) {
|
|
|
416
412
|
...l,
|
|
417
413
|
only: [...l.only ?? [], m.toString()]
|
|
418
414
|
};
|
|
419
|
-
const i =
|
|
415
|
+
const i = p(() => o[m]), u = X(), b = ee(o, m, l), f = p(() => i.value.config), A = p(() => i.value.meta), S = p(
|
|
420
416
|
() => {
|
|
421
417
|
var t;
|
|
422
|
-
return ((t = i.value.columns) == null ? void 0 : t.filter(({ active: a, hidden:
|
|
423
|
-
var
|
|
418
|
+
return ((t = i.value.columns) == null ? void 0 : t.filter(({ active: a, hidden: s }) => a && !s).map((a) => {
|
|
419
|
+
var s;
|
|
424
420
|
return {
|
|
425
421
|
...a,
|
|
426
|
-
isSorting: (
|
|
427
|
-
toggleSort: (
|
|
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 = p(
|
|
432
428
|
() => {
|
|
433
429
|
var t;
|
|
434
430
|
return ((t = i.value.columns) == null ? void 0 : t.filter(({ hidden: a }) => !a).map((a) => ({
|
|
435
431
|
...a,
|
|
436
|
-
toggle: (
|
|
432
|
+
toggle: (s = {}) => N(a, s)
|
|
437
433
|
}))) ?? [];
|
|
438
434
|
}
|
|
439
|
-
),
|
|
435
|
+
), c = p(
|
|
440
436
|
() => i.value.records.map((t) => ({
|
|
441
|
-
record: (({ actions: a, ...
|
|
437
|
+
record: (({ actions: a, ...s }) => s)(t),
|
|
442
438
|
/** Perform this action when the record is clicked */
|
|
443
439
|
default: (a = {}) => {
|
|
444
|
-
const
|
|
445
|
-
(
|
|
440
|
+
const s = t.actions.find(
|
|
441
|
+
(w) => w.default
|
|
446
442
|
);
|
|
447
|
-
|
|
443
|
+
s && z(s, t, a);
|
|
448
444
|
},
|
|
449
445
|
/** The actions available for the record */
|
|
450
446
|
actions: t.actions.map((a) => ({
|
|
451
447
|
...a,
|
|
452
448
|
/** Executes this action */
|
|
453
|
-
execute: (
|
|
449
|
+
execute: (s = {}) => z(a, t, s)
|
|
454
450
|
})),
|
|
455
451
|
/** Selects this record */
|
|
456
452
|
select: () => u.select(y(t)),
|
|
@@ -464,75 +460,73 @@ function le(o, m, d = {}, l = {}) {
|
|
|
464
460
|
bind: () => u.bind(y(t)),
|
|
465
461
|
/** Get the value of the record for the column */
|
|
466
462
|
value: (a) => {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
return console.log(c), c ? c.value : null;
|
|
463
|
+
const s = K(a);
|
|
464
|
+
return s in t ? t[s].value : null;
|
|
470
465
|
},
|
|
471
466
|
/** Get the extra data of the record for the column */
|
|
472
467
|
extra: (a) => {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
return c ? c.value : null;
|
|
468
|
+
const s = K(a);
|
|
469
|
+
return s in t ? t[s].extra : null;
|
|
476
470
|
}
|
|
477
471
|
}))
|
|
478
|
-
),
|
|
472
|
+
), g = p(
|
|
479
473
|
() => i.value.actions.bulk.map((t) => ({
|
|
480
474
|
...t,
|
|
481
475
|
/** Executes this bulk action */
|
|
482
476
|
execute: (a = {}) => L(t, a)
|
|
483
477
|
}))
|
|
484
|
-
), B =
|
|
478
|
+
), B = p(
|
|
485
479
|
() => i.value.actions.page.map((t) => ({
|
|
486
480
|
...t,
|
|
487
481
|
/** Executes this page action */
|
|
488
482
|
execute: (a = {}) => M(t, a)
|
|
489
483
|
}))
|
|
490
|
-
), j =
|
|
484
|
+
), j = p(
|
|
491
485
|
() => {
|
|
492
486
|
var t;
|
|
493
487
|
return ((t = i.value.recordsPerPage) == null ? void 0 : t.map((a) => ({
|
|
494
488
|
...a,
|
|
495
489
|
/** Changes the number of records to display per page */
|
|
496
|
-
apply: (
|
|
490
|
+
apply: (s = {}) => T(a, s)
|
|
497
491
|
}))) ?? [];
|
|
498
492
|
}
|
|
499
|
-
), C =
|
|
493
|
+
), C = p(
|
|
500
494
|
() => {
|
|
501
495
|
var t;
|
|
502
496
|
return (t = i.value.recordsPerPage) == null ? void 0 : t.find(({ active: a }) => a);
|
|
503
497
|
}
|
|
504
|
-
), h =
|
|
498
|
+
), h = p(() => ({
|
|
505
499
|
...i.value.paginator,
|
|
506
500
|
next: (t = {}) => {
|
|
507
|
-
"nextLink" in h.value && h.value.nextLink &&
|
|
501
|
+
"nextLink" in h.value && h.value.nextLink && V(h.value.nextLink, t);
|
|
508
502
|
},
|
|
509
503
|
previous: (t = {}) => {
|
|
510
|
-
"prevLink" in h.value && h.value.prevLink &&
|
|
504
|
+
"prevLink" in h.value && h.value.prevLink && V(h.value.prevLink, t);
|
|
511
505
|
},
|
|
512
506
|
first: (t = {}) => {
|
|
513
|
-
"firstLink" in h.value && h.value.firstLink &&
|
|
507
|
+
"firstLink" in h.value && h.value.firstLink && V(h.value.firstLink, t);
|
|
514
508
|
},
|
|
515
509
|
last: (t = {}) => {
|
|
516
|
-
"lastLink" in h.value && h.value.lastLink &&
|
|
510
|
+
"lastLink" in h.value && h.value.lastLink && V(h.value.lastLink, t);
|
|
517
511
|
},
|
|
518
512
|
..."links" in i.value.paginator && i.value.paginator.links ? {
|
|
519
513
|
links: i.value.paginator.links.map((t) => ({
|
|
520
514
|
...t,
|
|
521
|
-
navigate: (a = {}) => t.url &&
|
|
515
|
+
navigate: (a = {}) => t.url && V(t.url, a)
|
|
522
516
|
}))
|
|
523
517
|
} : {}
|
|
524
|
-
})), E =
|
|
518
|
+
})), E = p(
|
|
525
519
|
() => i.value.records.length > 0 && i.value.records.every(
|
|
526
520
|
(t) => u.selected(y(t))
|
|
527
521
|
)
|
|
528
522
|
);
|
|
529
523
|
function y(t) {
|
|
530
|
-
return t[f.value.
|
|
524
|
+
return t[f.value.key].value;
|
|
531
525
|
}
|
|
532
526
|
function K(t) {
|
|
533
527
|
return typeof t == "string" ? t : t.name;
|
|
534
528
|
}
|
|
535
|
-
function
|
|
529
|
+
function V(t, a = {}) {
|
|
536
530
|
x.visit(t, {
|
|
537
531
|
preserveScroll: !0,
|
|
538
532
|
preserveState: !0,
|
|
@@ -541,7 +535,7 @@ function le(o, m, d = {}, l = {}) {
|
|
|
541
535
|
method: "get"
|
|
542
536
|
});
|
|
543
537
|
}
|
|
544
|
-
function
|
|
538
|
+
function z(t, a, s = {}) {
|
|
545
539
|
var F, e;
|
|
546
540
|
I(
|
|
547
541
|
t,
|
|
@@ -550,7 +544,7 @@ function le(o, m, d = {}, l = {}) {
|
|
|
550
544
|
table: i.value.id,
|
|
551
545
|
id: y(a)
|
|
552
546
|
},
|
|
553
|
-
|
|
547
|
+
s
|
|
554
548
|
) || (e = (F = d.recordActions) == null ? void 0 : F[t.name]) == null || e.call(F, a);
|
|
555
549
|
}
|
|
556
550
|
function L(t, a = {}) {
|
|
@@ -581,8 +575,8 @@ function le(o, m, d = {}, l = {}) {
|
|
|
581
575
|
...l,
|
|
582
576
|
...a,
|
|
583
577
|
data: {
|
|
584
|
-
[f.value.
|
|
585
|
-
[f.value.
|
|
578
|
+
[f.value.record]: t.value,
|
|
579
|
+
[f.value.page]: void 0
|
|
586
580
|
}
|
|
587
581
|
});
|
|
588
582
|
}
|
|
@@ -591,24 +585,24 @@ function le(o, m, d = {}, l = {}) {
|
|
|
591
585
|
...l,
|
|
592
586
|
...a,
|
|
593
587
|
data: {
|
|
594
|
-
[f.value.
|
|
588
|
+
[f.value.sort]: b.omitValue(t.sort.next)
|
|
595
589
|
}
|
|
596
590
|
});
|
|
597
591
|
}
|
|
598
592
|
function N(t, a = {}) {
|
|
599
|
-
const
|
|
593
|
+
const s = b.toggleValue(
|
|
600
594
|
t.name,
|
|
601
|
-
S.value.map(({ name:
|
|
595
|
+
S.value.map(({ name: w }) => w)
|
|
602
596
|
);
|
|
603
597
|
x.reload({
|
|
604
598
|
...l,
|
|
605
599
|
...a,
|
|
606
600
|
data: {
|
|
607
|
-
[f.value.
|
|
601
|
+
[f.value.column]: b.delimitArray(s)
|
|
608
602
|
}
|
|
609
603
|
});
|
|
610
604
|
}
|
|
611
|
-
function
|
|
605
|
+
function G() {
|
|
612
606
|
u.select(
|
|
613
607
|
...i.value.records.map(
|
|
614
608
|
(t) => y(t)
|
|
@@ -625,7 +619,7 @@ function le(o, m, d = {}, l = {}) {
|
|
|
625
619
|
function D() {
|
|
626
620
|
return {
|
|
627
621
|
"onUpdate:modelValue": (t) => {
|
|
628
|
-
t ?
|
|
622
|
+
t ? G() : R();
|
|
629
623
|
},
|
|
630
624
|
modelValue: E.value
|
|
631
625
|
};
|
|
@@ -640,9 +634,9 @@ function le(o, m, d = {}, l = {}) {
|
|
|
640
634
|
/** All of the table's columns */
|
|
641
635
|
columns: k,
|
|
642
636
|
/** The records of the table */
|
|
643
|
-
records:
|
|
637
|
+
records: c,
|
|
644
638
|
/** The available bulk actions */
|
|
645
|
-
bulkActions:
|
|
639
|
+
bulkActions: g,
|
|
646
640
|
/** The available page actions */
|
|
647
641
|
pageActions: B,
|
|
648
642
|
/** The available number of records to display per page */
|
|
@@ -652,7 +646,7 @@ function le(o, m, d = {}, l = {}) {
|
|
|
652
646
|
/** The pagination metadata */
|
|
653
647
|
paginator: h,
|
|
654
648
|
/** Execute an inline action */
|
|
655
|
-
executeInlineAction:
|
|
649
|
+
executeInlineAction: z,
|
|
656
650
|
/** Execute a bulk action */
|
|
657
651
|
executeBulkAction: L,
|
|
658
652
|
/** Execute a page action */
|
|
@@ -666,7 +660,7 @@ function le(o, m, d = {}, l = {}) {
|
|
|
666
660
|
/** Deselect the given records */
|
|
667
661
|
deselect: (t) => u.deselect(y(t)),
|
|
668
662
|
/** Select records on the current page */
|
|
669
|
-
selectPage:
|
|
663
|
+
selectPage: G,
|
|
670
664
|
/** Deselect records on the current page */
|
|
671
665
|
deselectPage: R,
|
|
672
666
|
/** Toggle the selection of the given records */
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(w,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):(w=typeof globalThis<"u"?globalThis:w||self,c(w["@honed/table"]={},w.Vue,w.Inertia))})(this,function(w,c,b){"use strict";function _(){const r=c.ref({all:!1,only:new Set,except:new Set});function m(){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 l(...d){d.forEach(g=>r.value.except.delete(g)),d.forEach(g=>r.value.only.add(g))}function i(...d){d.forEach(g=>r.value.except.add(g)),d.forEach(g=>r.value.only.delete(g))}function u(d,g){if(x(d)||g===!1)return i(d);if(!x(d)||g===!0)return l(d)}function x(d){return r.value.all?!r.value.except.has(d):r.value.only.has(d)}const p=c.computed(()=>r.value.all&&r.value.except.size===0),A=c.computed(()=>r.value.only.size>0||p.value);function S(d){return{"onUpdate:modelValue":g=>{g?l(d):i(d)},modelValue:x(d),value:d}}function k(){return{"onUpdate:modelValue":d=>{d?m():v()},modelValue:p.value,value:p.value}}return{allSelected:p,selection:r,hasSelected:A,selectAll:m,deselectAll:v,select:l,deselect:i,toggle:u,selected:x,bind:S,bindAll:k}}function D(r,m,v={},l={}){return r.route?(b.router.visit(r.route.href,{...l,method:r.route.method}),!0):r.action&&m?(b.router.post(m,{...v,name:r.name,type:r.type},l),!0):!1}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Y=()=>{};function Q(r,m){function v(...l){return new Promise((i,u)=>{Promise.resolve(r(()=>m.apply(this,l),{fn:m,thisArg:this,args:l})).then(i).catch(u)})}return v}function X(r,m={}){let v,l,i=Y;const u=p=>{clearTimeout(p),i(),i=Y};let x;return p=>{const A=c.toValue(r),S=c.toValue(m.maxWait);return v&&u(v),A<=0||S!==void 0&&S<=0?(l&&(u(l),l=null),Promise.resolve(p())):new Promise((k,d)=>{i=m.rejectOnCancel?d:k,x=p,S&&!l&&(l=setTimeout(()=>{v&&u(v),l=null,k(x())},S)),v=setTimeout(()=>{l&&u(l),l=null,k(p())},A)})}}function B(r,m=200,v={}){return Q(X(m,v),r)}function Z(r,m,v={}){const l=c.computed(()=>r[m]),i=c.computed(()=>{var e;return((e=l.value.filters)==null?void 0:e.map(n=>({...n,apply:(o,f={})=>T(n,o,f),clear:(o={})=>N(n,o),bind:()=>a(n.name)})))??[]}),u=c.computed(()=>{var e;return((e=l.value.sorts)==null?void 0:e.map(n=>({...n,apply:(o={})=>M(n,n.direction,o),clear:(o={})=>z(o),bind:()=>s(n)})))??[]}),x=c.computed(()=>{var e;return(e=l.value.searches)==null?void 0:e.map(n=>({...n,apply:(o={})=>U(n,o),clear:(o={})=>U(n,o),bind:()=>j(n)}))}),p=c.computed(()=>{var e;return((e=l.value.filters)==null?void 0:e.filter(({active:n})=>n))??[]}),A=c.computed(()=>{var e;return(e=l.value.sorts)==null?void 0:e.find(({active:n})=>n)}),S=c.computed(()=>{var e;return((e=l.value.searches)==null?void 0:e.filter(({active:n})=>n))??[]});function k(e){return Array.isArray(e)?e.join(l.value.config.delimiter):e}function d(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,d,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=l.value.filters)==null?void 0:n.find(o=>o.name===e)}function h(e,n=null){var o;return(o=l.value.sorts)==null?void 0:o.find(f=>f.name===e&&f.direction===n)}function F(e){var n;return(n=l.value.searches)==null?void 0:n.find(o=>o.name===e)}function y(e){return e?typeof e=="string"?p.value.some(n=>n.name===e):e.active:!!p.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 L(e){var n;return e?typeof e=="string"?(n=S.value)==null?void 0:n.some(o=>o.name===e):e.active:!!l.value.config.search}function q(e,n={}){const o=Object.fromEntries(Object.entries(e).map(([f,P])=>[f,I(P)]));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:{[l.value.config.sorts]:g(f.next)}})}function E(e,n={}){e=[d,g].reduce((o,f)=>f(o),e),b.router.reload({...v,...n,data:{[l.value.config.searches]:e}})}function U(e,n={}){if(!l.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:P})=>P));b.router.reload({...v,...n,data:{[l.value.config.matches]:k(f)}})}function N(e,n={}){T(e,void 0,n)}function z(e={}){b.router.reload({...v,...e,data:{[l.value.config.sorts]:void 0}})}function R(e={}){E(void 0,e)}function H(e={}){if(!l.value.config.matches){console.warn("Matches key is not set.");return}b.router.reload({...v,...e,data:{[l.value.config.matches]:void 0}})}function t(e={}){var n;b.router.reload({...v,...e,data:{[l.value.config.searches]:void 0,[l.value.config.sorts]:void 0,[l.value.config.matches]:void 0,...Object.fromEntries(((n=l.value.filters)==null?void 0:n.map(o=>[o.name,void 0]))??[])}})}function a(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:P=250,transform:G=J=>J,...$}=n;return{"onUpdate:modelValue":B(J=>{T(o,G(J),$)},P),modelValue:f}}function s(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:P,...G}=n;return{onClick:B(()=>{var $;M(o,($=A.value)==null?void 0:$.direction,G)},f)}}function V(e={}){const{debounce:n=700,transform:o,...f}=e;return{"onUpdate:modelValue":B(P=>{E(P,f)},n),modelValue:l.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:P,...G}=n;return{"onUpdate:modelValue":B($=>{U($,G)},f),modelValue:L(o),value:o.name}}return{filters:i,sorts:u,searches:x,getFilter:W,getSort:h,getSearch:F,currentFilters:p,currentSort:A,currentSearches:S,isFiltering:y,isSorting:K,isSearching:L,apply:q,applyFilter:T,applySort:M,applySearch:E,applyMatch:U,clearFilter:N,clearSort:z,clearSearch:R,clearMatch:H,reset:t,bindFilter:a,bindSort:s,bindSearch:V,bindMatch:j,stringValue:d,omitValue:g,toggleValue:C,delimitArray:k}}function O(r,m,v={},l={}){if(!r||!m||!r[m])throw new Error("Table has not been provided with valid props and key.");l={...l,only:[...l.only??[],m.toString()]};const i=c.computed(()=>r[m]),u=_(),x=Z(r,m,l),p=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:a,hidden:s})=>a&&!s).map(a=>{var s;return{...a,isSorting:(s=a.sort)==null?void 0:s.active,toggleSort:(V={})=>U(a,V)}}))??[]}),k=c.computed(()=>{var t;return((t=i.value.columns)==null?void 0:t.filter(({hidden:a})=>!a).map(a=>({...a,toggle:(s={})=>N(a,s)})))??[]}),d=c.computed(()=>i.value.records.map(t=>({record:(({actions:a,...s})=>s)(t),default:(a={})=>{const s=t.actions.find(V=>V.default);s&&q(s,t,a)},actions:t.actions.map(a=>({...a,execute:(s={})=>q(a,t,s)})),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:a=>{console.log(a);const s=t[K(a)];return console.log(s),s?s.value:null},extra:a=>{var V;const s=(V=t[K(a)])==null?void 0:V.extra;return s?s.value:null}}))),g=c.computed(()=>i.value.actions.bulk.map(t=>({...t,execute:(a={})=>T(t,a)}))),I=c.computed(()=>i.value.actions.page.map(t=>({...t,execute:(a={})=>M(t,a)}))),C=c.computed(()=>{var t;return((t=i.value.recordsPerPage)==null?void 0:t.map(a=>({...a,apply:(s={})=>E(a,s)})))??[]}),W=c.computed(()=>{var t;return(t=i.value.recordsPerPage)==null?void 0:t.find(({active:a})=>a)}),h=c.computed(()=>({...i.value.paginator,next:(t={})=>{"nextLink"in h.value&&h.value.nextLink&&L(h.value.nextLink,t)},previous:(t={})=>{"prevLink"in h.value&&h.value.prevLink&&L(h.value.prevLink,t)},first:(t={})=>{"firstLink"in h.value&&h.value.firstLink&&L(h.value.firstLink,t)},last:(t={})=>{"lastLink"in h.value&&h.value.lastLink&&L(h.value.lastLink,t)},..."links"in i.value.paginator&&i.value.paginator.links?{links:i.value.paginator.links.map(t=>({...t,navigate:(a={})=>t.url&&L(t.url,a)}))}:{}})),F=c.computed(()=>i.value.records.length>0&&i.value.records.every(t=>u.selected(y(t))));function y(t){return t[p.value.record].value}function K(t){return typeof t=="string"?t:t.name}function L(t,a={}){b.router.visit(t,{preserveScroll:!0,preserveState:!0,...l,...a,method:"get"})}function q(t,a,s={}){var j,e;D(t,p.value.endpoint,{table:i.value.id,id:y(a)},s)||(e=(j=v.recordActions)==null?void 0:j[t.name])==null||e.call(j,a)}function T(t,a={}){D(t,p.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)},a)}function M(t,a={}){D(t,p.value.endpoint,{table:i.value.id},a)}function E(t,a={}){b.router.reload({...l,...a,data:{[p.value.records]:t.value,[p.value.pages]:void 0}})}function U(t,a={}){t.sort&&b.router.reload({...l,...a,data:{[p.value.sorts]:x.omitValue(t.sort.next)}})}function N(t,a={}){const s=x.toggleValue(t.name,S.value.map(({name:V})=>V));b.router.reload({...l,...a,data:{[p.value.columns]:x.delimitArray(s)}})}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:d,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})}w.useTable=O,Object.defineProperty(w,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 v(){r.value.all=!1,r.value.only.clear(),r.value.except.clear()}function l(...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 l(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?l(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:l,deselect:i,toggle:u,selected:x,bind:S,bindAll:k}}function D(r,p,v={},l={}){return r.route?(b.router.visit(r.route.url,{...l,method:r.route.method}),!0):r.action&&p?(b.router.post(p,{...v,name:r.name,type:r.type},l),!0):!1}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Y=()=>{};function Q(r,p){function v(...l){return new Promise((i,u)=>{Promise.resolve(r(()=>p.apply(this,l),{fn:p,thisArg:this,args:l})).then(i).catch(u)})}return v}function X(r,p={}){let v,l,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?(l&&(u(l),l=null),Promise.resolve(m())):new Promise((k,s)=>{i=p.rejectOnCancel?s:k,x=m,S&&!l&&(l=setTimeout(()=>{v&&u(v),l=null,k(x())},S)),v=setTimeout(()=>{l&&u(l),l=null,k(m())},A)})}}function B(r,p=200,v={}){return Q(X(p,v),r)}function Z(r,p,v={}){const l=c.computed(()=>r[p]),i=c.computed(()=>{var e;return((e=l.value.filters)==null?void 0:e.map(n=>({...n,apply:(o,f={})=>T(n,o,f),clear:(o={})=>N(n,o),bind:()=>a(n.name)})))??[]}),u=c.computed(()=>{var e;return((e=l.value.sorts)==null?void 0:e.map(n=>({...n,apply:(o={})=>E(n,n.direction,o),clear:(o={})=>G(o),bind:()=>d(n)})))??[]}),x=c.computed(()=>{var e;return(e=l.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=l.value.filters)==null?void 0:e.filter(({active:n})=>n))??[]}),A=c.computed(()=>{var e;return(e=l.value.sorts)==null?void 0:e.find(({active:n})=>n)}),S=c.computed(()=>{var e;return((e=l.value.searches)==null?void 0:e.filter(({active:n})=>n))??[]});function k(e){return Array.isArray(e)?e.join(l.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 q(e){var n;return(n=l.value.filters)==null?void 0:n.find(o=>o.name===e)}function h(e,n=null){var o;return(o=l.value.sorts)==null?void 0:o.find(f=>f.name===e&&f.direction===n)}function F(e){var n;return(n=l.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:!!l.value.config.term}function z(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"?q(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 E(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:{[l.value.config.sort]:g(f.next)}})}function M(e,n={}){e=[s,g].reduce((o,f)=>f(o),e),b.router.reload({...v,...n,data:{[l.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 f=C(o.name,S.value.map(({name:V})=>V));b.router.reload({...v,...n,data:{[l.value.config.match]:k(f)}})}function N(e,n={}){T(e,void 0,n)}function G(e={}){b.router.reload({...v,...e,data:{[l.value.config.sort]:void 0}})}function R(e={}){M(void 0,e)}function H(e={}){if(!l.value.config.match){console.warn("Matches key is not set.");return}b.router.reload({...v,...e,data:{[l.value.config.match]:void 0}})}function t(e={}){var n;b.router.reload({...v,...e,data:{[l.value.config.search]:void 0,[l.value.config.sort]:void 0,[l.value.config.match]:void 0,...Object.fromEntries(((n=l.value.filters)==null?void 0:n.map(o=>[o.name,void 0]))??[])}})}function a(e,n={}){const o=typeof e=="string"?q(e):e;if(!o){console.warn(`Filter [${e}] does not exist.`);return}const f=o.value,{debounce:V=250,transform:W=J=>J,...$}=n;return{"onUpdate:modelValue":B(J=>{T(o,W(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,...W}=n;return{onClick:B(()=>{var $;E(o,($=A.value)==null?void 0:$.direction,W)},f)}}function L(e={}){const{debounce:n=700,transform:o,...f}=e;return{"onUpdate:modelValue":B(V=>{M(V,f)},n),modelValue:l.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,...W}=n;return{"onUpdate:modelValue":B($=>{U($,W)},f),modelValue:w(o),value:o.name}}return{filters:i,sorts:u,searches:x,getFilter:q,getSort:h,getSearch:F,currentFilters:m,currentSort:A,currentSearches:S,isFiltering:y,isSorting:K,isSearching:w,apply:z,applyFilter:T,applySort:E,applySearch:M,applyMatch:U,clearFilter:N,clearSort:G,clearSearch:R,clearMatch:H,reset:t,bindFilter:a,bindSort:d,bindSearch:L,bindMatch:j,stringValue:s,omitValue:g,toggleValue:C,delimitArray:k}}function O(r,p,v={},l={}){if(!r||!p||!r[p])throw new Error("Table has not been provided with valid props and key.");l={...l,only:[...l.only??[],p.toString()]};const i=c.computed(()=>r[p]),u=_(),x=Z(r,p,l),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:a,hidden:d})=>a&&!d).map(a=>{var d;return{...a,isSorting:(d=a.sort)==null?void 0:d.active,toggleSort:(L={})=>U(a,L)}}))??[]}),k=c.computed(()=>{var t;return((t=i.value.columns)==null?void 0:t.filter(({hidden:a})=>!a).map(a=>({...a,toggle:(d={})=>N(a,d)})))??[]}),s=c.computed(()=>i.value.records.map(t=>({record:(({actions:a,...d})=>d)(t),default:(a={})=>{const d=t.actions.find(L=>L.default);d&&z(d,t,a)},actions:t.actions.map(a=>({...a,execute:(d={})=>z(a,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:a=>{const d=K(a);return d in t?t[d].value:null},extra:a=>{const d=K(a);return d in t?t[d].extra:null}}))),g=c.computed(()=>i.value.actions.bulk.map(t=>({...t,execute:(a={})=>T(t,a)}))),I=c.computed(()=>i.value.actions.page.map(t=>({...t,execute:(a={})=>E(t,a)}))),C=c.computed(()=>{var t;return((t=i.value.recordsPerPage)==null?void 0:t.map(a=>({...a,apply:(d={})=>M(a,d)})))??[]}),q=c.computed(()=>{var t;return(t=i.value.recordsPerPage)==null?void 0:t.find(({active:a})=>a)}),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:(a={})=>t.url&&w(t.url,a)}))}:{}})),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,a={}){b.router.visit(t,{preserveScroll:!0,preserveState:!0,...l,...a,method:"get"})}function z(t,a,d={}){var j,e;D(t,m.value.endpoint,{table:i.value.id,id:y(a)},d)||(e=(j=v.recordActions)==null?void 0:j[t.name])==null||e.call(j,a)}function T(t,a={}){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)},a)}function E(t,a={}){D(t,m.value.endpoint,{table:i.value.id},a)}function M(t,a={}){b.router.reload({...l,...a,data:{[m.value.record]:t.value,[m.value.page]:void 0}})}function U(t,a={}){t.sort&&b.router.reload({...l,...a,data:{[m.value.sort]:x.omitValue(t.sort.next)}})}function N(t,a={}){const d=x.toggleValue(t.name,S.value.map(({name:L})=>L));b.router.reload({...l,...a,data:{[m.value.column]:x.delimitArray(d)}})}function G(){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?G():R()},modelValue:F.value}}return c.reactive({getRecordKey:y,meta:A,headings:S,columns:k,records:s,bulkActions:g,pageActions:I,rowsPerPage:C,currentPage:q,paginator:h,executeInlineAction:z,executeBulkAction:T,executePageAction:E,applyPage:M,selection:u.selection,select:t=>u.select(y(t)),deselect:t=>u.deselect(y(t)),selectPage:G,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.0",
|
|
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.0",
|
|
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",
|