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