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