@honed/table 0.4.2 → 0.4.3

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