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