@honed/table 0.6.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -145,7 +145,7 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
145
145
  modelValue: unknown;
146
146
  } | undefined;
147
147
  type: string;
148
- value: FilterValue; /** Determine if the record is selected */
148
+ value: FilterValue;
149
149
  options: Option_2[];
150
150
  name: string;
151
151
  label: string;
@@ -225,6 +225,9 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
225
225
  isSorting: boolean | undefined;
226
226
  toggleSort: (options?: VisitOptions) => void;
227
227
  name: keyof RecordType;
228
+ /**
229
+ * The heading columns for the table.
230
+ */
228
231
  label: string;
229
232
  type: string;
230
233
  hidden: boolean;
@@ -241,6 +244,9 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
241
244
  columns: {
242
245
  toggle: (options?: VisitOptions) => void;
243
246
  name: keyof RecordType;
247
+ /**
248
+ * The heading columns for the table.
249
+ */
244
250
  label: string;
245
251
  type: string;
246
252
  hidden: boolean;
@@ -258,8 +264,6 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
258
264
  record: Omit<AsRecord<RecordType> & {
259
265
  actions: InlineAction[];
260
266
  }, "actions">;
261
- /** Perform this action when the record is clicked */
262
- default: (options?: VisitOptions) => void;
263
267
  /** The actions available for the record */
264
268
  actions: {
265
269
  /** Executes this action */
@@ -274,6 +278,8 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
274
278
  confirm?: Confirm | undefined;
275
279
  route?: Route | undefined;
276
280
  }[];
281
+ /** Perform this action when the record is clicked */
282
+ default: (options?: VisitOptions) => void;
277
283
  /** Selects this record */
278
284
  select: () => void;
279
285
  /** Deselects this record */
@@ -295,7 +301,6 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
295
301
  }[];
296
302
  inline: boolean;
297
303
  bulkActions: {
298
- /** Executes this bulk action */
299
304
  execute: (options?: VisitOptions) => void;
300
305
  type: "bulk";
301
306
  keepSelected: boolean;
@@ -308,7 +313,6 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
308
313
  route?: Route | undefined;
309
314
  }[];
310
315
  pageActions: {
311
- /** Executes this page action */
312
316
  execute: (options?: VisitOptions) => void;
313
317
  type: "page";
314
318
  name: string;
@@ -320,7 +324,6 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
320
324
  route?: Route | undefined;
321
325
  }[];
322
326
  rowsPerPage: {
323
- /** Changes the number of records to display per page */
324
327
  apply: (options?: VisitOptions) => void;
325
328
  value: number;
326
329
  active: boolean;
package/dist/index.es.js CHANGED
@@ -1,5 +1,19 @@
1
1
  import { ref as _, computed as g, toValue as J, reactive as Q } from "vue";
2
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,
9
+ {
10
+ ...v,
11
+ name: o.name,
12
+ type: o.type
13
+ },
14
+ a
15
+ ), !0) : !1;
16
+ }
3
17
  function X() {
4
18
  const o = _({
5
19
  all: !1,
@@ -12,35 +26,35 @@ function X() {
12
26
  function v() {
13
27
  o.value.all = !1, o.value.only.clear(), o.value.except.clear();
14
28
  }
15
- function l(...c) {
16
- c.forEach((p) => o.value.except.delete(p)), c.forEach((p) => o.value.only.add(p));
29
+ function a(...s) {
30
+ s.forEach((p) => o.value.except.delete(p)), s.forEach((p) => o.value.only.add(p));
17
31
  }
18
- function i(...c) {
19
- c.forEach((p) => o.value.except.add(p)), c.forEach((p) => o.value.only.delete(p));
32
+ function i(...s) {
33
+ s.forEach((p) => o.value.except.add(p)), s.forEach((p) => o.value.only.delete(p));
20
34
  }
21
- function u(c, p) {
22
- if (b(c) || p === !1)
23
- return i(c);
24
- if (!b(c) || p === !0)
25
- return l(c);
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);
26
40
  }
27
- function b(c) {
28
- return o.value.all ? !o.value.except.has(c) : o.value.only.has(c);
41
+ function b(s) {
42
+ return o.value.all ? !o.value.except.has(s) : o.value.only.has(s);
29
43
  }
30
44
  const f = g(() => o.value.all && o.value.except.size === 0), A = g(() => o.value.only.size > 0 || f.value);
31
- function S(c) {
45
+ function S(s) {
32
46
  return {
33
47
  "onUpdate:modelValue": (p) => {
34
- p ? l(c) : i(c);
48
+ p ? a(s) : i(s);
35
49
  },
36
- modelValue: b(c),
37
- value: c
50
+ modelValue: b(s),
51
+ value: s
38
52
  };
39
53
  }
40
54
  function k() {
41
55
  return {
42
- "onUpdate:modelValue": (c) => {
43
- c ? m() : v();
56
+ "onUpdate:modelValue": (s) => {
57
+ s ? m() : v();
44
58
  },
45
59
  modelValue: f.value,
46
60
  value: f.value
@@ -52,7 +66,7 @@ function X() {
52
66
  hasSelected: A,
53
67
  selectAll: m,
54
68
  deselectAll: v,
55
- select: l,
69
+ select: a,
56
70
  deselect: i,
57
71
  toggle: u,
58
72
  selected: b,
@@ -60,44 +74,30 @@ function X() {
60
74
  bindAll: k
61
75
  };
62
76
  }
63
- function I(o, m, v = {}, l = {}) {
64
- return o.route ? (x.visit(o.route.url, {
65
- ...l,
66
- method: o.route.method
67
- }), !0) : o.action && m ? (x.post(
68
- m,
69
- {
70
- ...v,
71
- name: o.name,
72
- type: o.type
73
- },
74
- l
75
- ), !0) : !1;
76
- }
77
77
  typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
78
78
  const Y = () => {
79
79
  };
80
80
  function Z(o, m) {
81
- function v(...l) {
81
+ function v(...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 v;
87
87
  }
88
88
  function O(o, m = {}) {
89
- let v, l, i = Y;
89
+ let v, 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 v && u(v), A <= 0 || S !== void 0 && S <= 0 ? (l && (u(l), l = null), Promise.resolve(f())) : new Promise((k, c) => {
97
- i = m.rejectOnCancel ? c : k, b = f, S && !l && (l = setTimeout(() => {
98
- v && u(v), l = null, k(b());
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
99
  }, S)), v = 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,30 +109,30 @@ function q(o, m = 200, v = {}) {
109
109
  );
110
110
  }
111
111
  function ee(o, m, v = {}) {
112
- const l = g(() => o[m]), i = g(
112
+ const a = g(() => o[m]), i = g(
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, d = {}) => L(n, r, d),
118
118
  clear: (r = {}) => N(n, r),
119
- bind: () => a(n.name)
119
+ bind: () => l(n.name)
120
120
  }))) ?? [];
121
121
  }
122
122
  ), u = g(
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 = {}) => W(r),
129
- bind: () => s(n)
129
+ bind: () => c(n)
130
130
  }))) ?? [];
131
131
  }
132
132
  ), b = g(
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),
@@ -142,23 +142,23 @@ function ee(o, m, v = {}) {
142
142
  ), f = g(
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
147
  ), A = g(
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
152
  ), S = g(
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 c(e) {
161
+ function s(e) {
162
162
  return typeof e != "string" ? e : e.trim().replace(/\s+/g, "+");
163
163
  }
164
164
  function p(e) {
@@ -166,7 +166,7 @@ function ee(o, m, v = {}) {
166
166
  return e;
167
167
  }
168
168
  function G(e) {
169
- return [k, c, p].reduce(
169
+ return [k, s, p].reduce(
170
170
  (n, r) => r(n),
171
171
  e
172
172
  );
@@ -176,17 +176,17 @@ function ee(o, m, v = {}) {
176
176
  }
177
177
  function j(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
  (d) => d.name === e && d.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, v = {}) {
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 P(e) {
198
+ function w(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.term;
200
+ return e ? typeof e == "string" ? (n = S.value) == null ? void 0 : n.some((r) => r.name === e) : e.active : !!a.value.config.term;
201
201
  }
202
202
  function C(e, n = {}) {
203
203
  const r = Object.fromEntries(
204
- Object.entries(e).map(([d, V]) => [d, G(V)])
204
+ Object.entries(e).map(([d, P]) => [d, G(P)])
205
205
  );
206
206
  x.reload({
207
207
  ...v,
@@ -233,19 +233,19 @@ function ee(o, m, v = {}) {
233
233
  ...v,
234
234
  ...r,
235
235
  data: {
236
- [l.value.config.sort]: p(d.next)
236
+ [a.value.config.sort]: p(d.next)
237
237
  }
238
238
  });
239
239
  }
240
240
  function T(e, n = {}) {
241
- e = [c, p].reduce(
241
+ e = [s, p].reduce(
242
242
  (r, d) => d(r),
243
243
  e
244
244
  ), x.reload({
245
245
  ...v,
246
246
  ...n,
247
247
  data: {
248
- [l.value.config.search]: e
248
+ [a.value.config.search]: e
249
249
  }
250
250
  });
251
251
  }
@@ -257,13 +257,13 @@ function ee(o, m, v = {}) {
257
257
  }
258
258
  const d = B(
259
259
  r.name,
260
- S.value.map(({ name: V }) => V)
260
+ S.value.map(({ name: P }) => P)
261
261
  );
262
262
  x.reload({
263
263
  ...v,
264
264
  ...n,
265
265
  data: {
266
- [l.value.config.match]: k(d)
266
+ [a.value.config.match]: k(d)
267
267
  }
268
268
  });
269
269
  }
@@ -275,7 +275,7 @@ function ee(o, m, v = {}) {
275
275
  ...v,
276
276
  ...e,
277
277
  data: {
278
- [l.value.config.sort]: void 0
278
+ [a.value.config.sort]: void 0
279
279
  }
280
280
  });
281
281
  }
@@ -283,7 +283,7 @@ function ee(o, m, v = {}) {
283
283
  T(void 0, e);
284
284
  }
285
285
  function D(e = {}) {
286
- if (!l.value.config.match) {
286
+ if (!a.value.config.match) {
287
287
  console.warn("Matches key is not set.");
288
288
  return;
289
289
  }
@@ -291,7 +291,7 @@ function ee(o, m, v = {}) {
291
291
  ...v,
292
292
  ...e,
293
293
  data: {
294
- [l.value.config.match]: void 0
294
+ [a.value.config.match]: void 0
295
295
  }
296
296
  });
297
297
  }
@@ -301,11 +301,11 @@ function ee(o, m, v = {}) {
301
301
  ...v,
302
302
  ...e,
303
303
  data: {
304
- [l.value.config.search]: void 0,
305
- [l.value.config.sort]: void 0,
306
- [l.value.config.match]: void 0,
304
+ [a.value.config.search]: void 0,
305
+ [a.value.config.sort]: void 0,
306
+ [a.value.config.match]: void 0,
307
307
  ...Object.fromEntries(
308
- ((n = l.value.filters) == null ? void 0 : n.map((r) => [
308
+ ((n = a.value.filters) == null ? void 0 : n.map((r) => [
309
309
  r.name,
310
310
  void 0
311
311
  ])) ?? []
@@ -313,31 +313,31 @@ function ee(o, m, v = {}) {
313
313
  }
314
314
  });
315
315
  }
316
- function a(e, n = {}) {
316
+ function l(e, n = {}) {
317
317
  const r = typeof e == "string" ? j(e) : e;
318
318
  if (!r) {
319
319
  console.warn(`Filter [${e}] does not exist.`);
320
320
  return;
321
321
  }
322
322
  const d = r.value, {
323
- debounce: V = 250,
323
+ debounce: P = 250,
324
324
  transform: z = (H) => H,
325
325
  ...$
326
326
  } = n;
327
327
  return {
328
328
  "onUpdate:modelValue": q((H) => {
329
329
  L(r, z(H), $);
330
- }, V),
330
+ }, P),
331
331
  modelValue: d
332
332
  };
333
333
  }
334
- function s(e, n = {}) {
334
+ function c(e, n = {}) {
335
335
  const r = typeof e == "string" ? h(e) : e;
336
336
  if (!r) {
337
337
  console.warn(`Sort [${e}] does not exist.`);
338
338
  return;
339
339
  }
340
- const { debounce: d = 0, transform: V, ...z } = n;
340
+ const { debounce: d = 0, transform: P, ...z } = n;
341
341
  return {
342
342
  onClick: q(() => {
343
343
  var $;
@@ -345,16 +345,16 @@ function ee(o, m, v = {}) {
345
345
  }, d)
346
346
  };
347
347
  }
348
- function w(e = {}) {
348
+ function V(e = {}) {
349
349
  const { debounce: n = 700, transform: r, ...d } = e;
350
350
  return {
351
351
  "onUpdate:modelValue": q(
352
- (V) => {
353
- T(V, d);
352
+ (P) => {
353
+ T(P, d);
354
354
  },
355
355
  n
356
356
  ),
357
- modelValue: l.value.config.term ?? ""
357
+ modelValue: a.value.config.term ?? ""
358
358
  };
359
359
  }
360
360
  function F(e, n = {}) {
@@ -363,12 +363,12 @@ function ee(o, m, v = {}) {
363
363
  console.warn(`Match [${e}] does not exist.`);
364
364
  return;
365
365
  }
366
- const { debounce: d = 0, transform: V, ...z } = n;
366
+ const { debounce: d = 0, transform: P, ...z } = n;
367
367
  return {
368
368
  "onUpdate:modelValue": q(($) => {
369
369
  U($, z);
370
370
  }, d),
371
- modelValue: P(r),
371
+ modelValue: w(r),
372
372
  value: r.name
373
373
  };
374
374
  }
@@ -384,7 +384,7 @@ function ee(o, m, v = {}) {
384
384
  currentSearches: S,
385
385
  isFiltering: y,
386
386
  isSorting: K,
387
- isSearching: P,
387
+ isSearching: w,
388
388
  apply: C,
389
389
  applyFilter: L,
390
390
  applySort: M,
@@ -395,59 +395,59 @@ function ee(o, m, v = {}) {
395
395
  clearSearch: R,
396
396
  clearMatch: D,
397
397
  reset: t,
398
- bindFilter: a,
399
- bindSort: s,
400
- bindSearch: w,
398
+ bindFilter: l,
399
+ bindSort: c,
400
+ bindSearch: V,
401
401
  bindMatch: F,
402
- stringValue: c,
402
+ stringValue: s,
403
403
  omitValue: p,
404
404
  toggleValue: B,
405
405
  delimitArray: k
406
406
  };
407
407
  }
408
- function le(o, m, v = {}, l = {}) {
408
+ function le(o, m, v = {}, a = {}) {
409
409
  if (!o || !m || !o[m])
410
410
  throw new Error("Table has not been provided with valid props and key.");
411
- l = {
412
- ...l,
413
- only: [...l.only ?? [], m.toString()]
411
+ a = {
412
+ ...a,
413
+ only: [...a.only ?? [], m.toString()]
414
414
  };
415
- const i = g(() => o[m]), u = X(), b = ee(o, m, l), f = g(() => i.value.config), A = g(() => i.value.meta), S = g(
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
416
  () => {
417
417
  var t;
418
- return ((t = i.value.columns) == null ? void 0 : t.filter(({ active: a, hidden: s }) => a && !s).map((a) => {
419
- var s;
418
+ return ((t = i.value.columns) == null ? void 0 : t.filter(({ active: l, hidden: c }) => l && !c).map((l) => {
419
+ var c;
420
420
  return {
421
- ...a,
422
- isSorting: (s = a.sort) == null ? void 0 : s.active,
423
- toggleSort: (w = {}) => U(a, w)
421
+ ...l,
422
+ isSorting: (c = l.sort) == null ? void 0 : c.active,
423
+ toggleSort: (V = {}) => U(l, V)
424
424
  };
425
425
  })) ?? [];
426
426
  }
427
427
  ), k = g(
428
428
  () => {
429
429
  var t;
430
- return ((t = i.value.columns) == null ? void 0 : t.filter(({ hidden: a }) => !a).map((a) => ({
431
- ...a,
432
- toggle: (s = {}) => N(a, s)
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
433
  }))) ?? [];
434
434
  }
435
- ), c = g(
435
+ ), s = g(
436
436
  () => i.value.records.map((t) => ({
437
- record: (({ actions: a, ...s }) => s)(t),
438
- /** Perform this action when the record is clicked */
439
- default: (a = {}) => {
440
- const s = t.actions.find(
441
- (w) => w.default
442
- );
443
- s && C(s, t, a);
444
- },
437
+ record: (({ actions: l, ...c }) => c)(t),
445
438
  /** The actions available for the record */
446
- actions: t.actions.map((a) => ({
447
- ...a,
439
+ actions: t.actions.map((l) => ({
440
+ ...l,
448
441
  /** Executes this action */
449
- execute: (s = {}) => C(a, t, s)
442
+ execute: (c = {}) => C(l, t, c)
450
443
  })),
444
+ /** Perform this action when the record is clicked */
445
+ default: (l = {}) => {
446
+ const c = t.actions.find(
447
+ (V) => V.default
448
+ );
449
+ c && C(c, t, l);
450
+ },
451
451
  /** Selects this record */
452
452
  select: () => u.select(y(t)),
453
453
  /** Deselects this record */
@@ -459,60 +459,57 @@ function le(o, m, v = {}, l = {}) {
459
459
  /** Bind the record to a checkbox */
460
460
  bind: () => u.bind(y(t)),
461
461
  /** Get the value of the record for the column */
462
- value: (a) => {
463
- const s = K(a);
464
- return s in t ? t[s].value : null;
462
+ value: (l) => {
463
+ const c = K(l);
464
+ return c in t ? t[c].value : null;
465
465
  },
466
466
  /** Get the extra data of the record for the column */
467
- extra: (a) => {
468
- const s = K(a);
469
- return s in t ? t[s].extra : null;
467
+ extra: (l) => {
468
+ const c = K(l);
469
+ return c in t ? t[c].extra : null;
470
470
  }
471
471
  }))
472
472
  ), p = g(
473
473
  () => i.value.actions.bulk.map((t) => ({
474
474
  ...t,
475
- /** Executes this bulk action */
476
- execute: (a = {}) => L(t, a)
475
+ execute: (l = {}) => L(t, l)
477
476
  }))
478
477
  ), G = g(
479
478
  () => i.value.actions.page.map((t) => ({
480
479
  ...t,
481
- /** Executes this page action */
482
- execute: (a = {}) => M(t, a)
480
+ execute: (l = {}) => M(t, l)
483
481
  }))
484
482
  ), B = g(
485
483
  () => {
486
484
  var t;
487
- return ((t = i.value.recordsPerPage) == null ? void 0 : t.map((a) => ({
488
- ...a,
489
- /** Changes the number of records to display per page */
490
- apply: (s = {}) => T(a, s)
485
+ return ((t = i.value.recordsPerPage) == null ? void 0 : t.map((l) => ({
486
+ ...l,
487
+ apply: (c = {}) => T(l, c)
491
488
  }))) ?? [];
492
489
  }
493
490
  ), j = g(
494
491
  () => {
495
492
  var t;
496
- return (t = i.value.recordsPerPage) == null ? void 0 : t.find(({ active: a }) => a);
493
+ return (t = i.value.recordsPerPage) == null ? void 0 : t.find(({ active: l }) => l);
497
494
  }
498
495
  ), h = g(() => ({
499
496
  ...i.value.paginator,
500
497
  next: (t = {}) => {
501
- "nextLink" in h.value && h.value.nextLink && P(h.value.nextLink, t);
498
+ "nextLink" in h.value && h.value.nextLink && w(h.value.nextLink, t);
502
499
  },
503
500
  previous: (t = {}) => {
504
- "prevLink" in h.value && h.value.prevLink && P(h.value.prevLink, t);
501
+ "prevLink" in h.value && h.value.prevLink && w(h.value.prevLink, t);
505
502
  },
506
503
  first: (t = {}) => {
507
- "firstLink" in h.value && h.value.firstLink && P(h.value.firstLink, t);
504
+ "firstLink" in h.value && h.value.firstLink && w(h.value.firstLink, t);
508
505
  },
509
506
  last: (t = {}) => {
510
- "lastLink" in h.value && h.value.lastLink && P(h.value.lastLink, t);
507
+ "lastLink" in h.value && h.value.lastLink && w(h.value.lastLink, t);
511
508
  },
512
509
  ..."links" in i.value.paginator && i.value.paginator.links ? {
513
510
  links: i.value.paginator.links.map((t) => ({
514
511
  ...t,
515
- navigate: (a = {}) => t.url && P(t.url, a)
512
+ navigate: (l = {}) => t.url && w(t.url, l)
516
513
  }))
517
514
  } : {}
518
515
  })), E = g(
@@ -526,79 +523,85 @@ function le(o, m, v = {}, l = {}) {
526
523
  function K(t) {
527
524
  return typeof t == "string" ? t : t.name;
528
525
  }
529
- function P(t, a = {}) {
526
+ function w(t, l = {}) {
530
527
  x.visit(t, {
531
528
  preserveScroll: !0,
532
529
  preserveState: !0,
533
- ...l,
534
530
  ...a,
531
+ ...l,
535
532
  method: "get"
536
533
  });
537
534
  }
538
- function C(t, a, s = {}) {
535
+ function C(t, l, c = {}) {
539
536
  var F, e;
540
537
  I(
541
538
  t,
542
539
  f.value.endpoint,
543
540
  {
544
- table: i.value.id,
545
- id: y(a)
541
+ id: i.value.id,
542
+ record: y(l)
546
543
  },
547
- s
548
- ) || (e = (F = v.recordActions) == null ? void 0 : F[t.name]) == null || e.call(F, a);
544
+ c
545
+ ) || (e = (F = v.recordActions) == null ? void 0 : F[t.name]) == null || e.call(F, l);
549
546
  }
550
- function L(t, a = {}) {
547
+ function L(t, l = {}) {
551
548
  I(
552
549
  t,
553
550
  f.value.endpoint,
554
551
  {
555
- table: i.value.id,
552
+ id: i.value.id,
556
553
  all: u.selection.value.all,
557
554
  only: Array.from(u.selection.value.only),
558
555
  except: Array.from(u.selection.value.except)
559
556
  },
560
- a
557
+ {
558
+ ...l,
559
+ onSuccess: (c) => {
560
+ var V;
561
+ (V = l.onSuccess) == null || V.call(l, c), t.keepSelected || u.deselectAll();
562
+ }
563
+ }
561
564
  );
562
565
  }
563
- function M(t, a = {}) {
566
+ function M(t, l = {}) {
564
567
  I(
565
568
  t,
566
569
  f.value.endpoint,
567
570
  {
568
- table: i.value.id
571
+ id: i.value.id
569
572
  },
570
- a
573
+ l
571
574
  );
572
575
  }
573
- function T(t, a = {}) {
576
+ function T(t, l = {}) {
574
577
  x.reload({
575
- ...l,
576
578
  ...a,
579
+ ...l,
577
580
  data: {
578
581
  [f.value.record]: t.value,
579
582
  [f.value.page]: void 0
580
583
  }
581
584
  });
582
585
  }
583
- function U(t, a = {}) {
586
+ function U(t, l = {}) {
584
587
  t.sort && x.reload({
585
- ...l,
586
588
  ...a,
589
+ ...l,
587
590
  data: {
588
591
  [f.value.sort]: b.omitValue(t.sort.next)
589
592
  }
590
593
  });
591
594
  }
592
- function N(t, a = {}) {
593
- const s = b.toggleValue(
595
+ function N(t, l = {}) {
596
+ const c = b.toggleValue(
594
597
  t.name,
595
- S.value.map(({ name: w }) => w)
598
+ S.value.map(({ name: V }) => V)
596
599
  );
597
600
  x.reload({
598
- ...l,
599
601
  ...a,
602
+ ...l,
600
603
  data: {
601
- [f.value.column]: b.delimitArray(s)
604
+ [f.value.column]: b.delimitArray(c)
602
605
  }
603
606
  });
604
607
  }
@@ -634,7 +637,7 @@ function le(o, m, v = {}, l = {}) {
634
637
  /** All of the table's columns */
635
638
  columns: k,
636
639
  /** The records of the table */
637
- records: c,
640
+ records: s,
638
641
  /** Whether the table has record actions */
639
642
  inline: i.value.actions.inline,
640
643
  /** The available bulk actions */
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
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 f(){r.value.all=!1,r.value.only.clear(),r.value.except.clear()}function l(...s){s.forEach(g=>r.value.except.delete(g)),s.forEach(g=>r.value.only.add(g))}function i(...s){s.forEach(g=>r.value.except.add(g)),s.forEach(g=>r.value.only.delete(g))}function u(s,g){if(x(s)||g===!1)return i(s);if(!x(s)||g===!0)return l(s)}function x(s){return r.value.all?!r.value.except.has(s):r.value.only.has(s)}const m=c.computed(()=>r.value.all&&r.value.except.size===0),A=c.computed(()=>r.value.only.size>0||m.value);function S(s){return{"onUpdate:modelValue":g=>{g?l(s):i(s)},modelValue:x(s),value:s}}function k(){return{"onUpdate:modelValue":s=>{s?p():f()},modelValue:m.value,value:m.value}}return{allSelected:m,selection:r,hasSelected:A,selectAll:p,deselectAll:f,select:l,deselect:i,toggle:u,selected:x,bind:S,bindAll:k}}function D(r,p,f={},l={}){return r.route?(b.router.visit(r.route.url,{...l,method:r.route.method}),!0):r.action&&p?(b.router.post(p,{...f,name:r.name,type:r.type},l),!0):!1}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Y=()=>{};function Q(r,p){function f(...l){return new Promise((i,u)=>{Promise.resolve(r(()=>p.apply(this,l),{fn:p,thisArg:this,args:l})).then(i).catch(u)})}return f}function X(r,p={}){let f,l,i=Y;const u=m=>{clearTimeout(m),i(),i=Y};let x;return m=>{const A=c.toValue(r),S=c.toValue(p.maxWait);return f&&u(f),A<=0||S!==void 0&&S<=0?(l&&(u(l),l=null),Promise.resolve(m())):new Promise((k,s)=>{i=p.rejectOnCancel?s:k,x=m,S&&!l&&(l=setTimeout(()=>{f&&u(f),l=null,k(x())},S)),f=setTimeout(()=>{l&&u(l),l=null,k(m())},A)})}}function G(r,p=200,f={}){return Q(X(p,f),r)}function Z(r,p,f={}){const l=c.computed(()=>r[p]),i=c.computed(()=>{var e;return((e=l.value.filters)==null?void 0:e.map(n=>({...n,apply:(o,v={})=>T(n,o,v),clear:(o={})=>N(n,o),bind:()=>a(n.name)})))??[]}),u=c.computed(()=>{var e;return((e=l.value.sorts)==null?void 0:e.map(n=>({...n,apply:(o={})=>E(n,n.direction,o),clear:(o={})=>q(o),bind:()=>d(n)})))??[]}),x=c.computed(()=>{var e;return(e=l.value.searches)==null?void 0:e.map(n=>({...n,apply:(o={})=>U(n,o),clear:(o={})=>U(n,o),bind:()=>j(n)}))}),m=c.computed(()=>{var e;return((e=l.value.filters)==null?void 0:e.filter(({active:n})=>n))??[]}),A=c.computed(()=>{var e;return(e=l.value.sorts)==null?void 0:e.find(({active:n})=>n)}),S=c.computed(()=>{var e;return((e=l.value.searches)==null?void 0:e.filter(({active:n})=>n))??[]});function k(e){return Array.isArray(e)?e.join(l.value.config.delimiter):e}function s(e){return typeof e!="string"?e:e.trim().replace(/\s+/g,"+")}function g(e){if(!["",null,void 0,[]].includes(e))return e}function B(e){return[k,s,g].reduce((n,o)=>o(n),e)}function I(e,n){return n=Array.isArray(n)?n:[n],n.includes(e)?n.filter(o=>o!==e):[...n,e]}function C(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(v=>v.name===e&&v.direction===n)}function F(e){var n;return(n=l.value.searches)==null?void 0:n.find(o=>o.name===e)}function y(e){return e?typeof e=="string"?m.value.some(n=>n.name===e):e.active:!!m.value.length}function K(e){var n;return e?typeof e=="string"?((n=A.value)==null?void 0:n.name)===e:e.active:!!A.value}function w(e){var n;return e?typeof e=="string"?(n=S.value)==null?void 0:n.some(o=>o.name===e):e.active:!!l.value.config.term}function W(e,n={}){const o=Object.fromEntries(Object.entries(e).map(([v,V])=>[v,B(V)]));b.router.reload({...f,...n,data:o})}function T(e,n,o={}){const v=typeof e=="string"?C(e):e;if(!v){console.warn(`Filter [${e}] does not exist.`);return}b.router.reload({...f,...o,data:{[v.name]:B(n)}})}function E(e,n=null,o={}){const v=typeof e=="string"?h(e,n):e;if(!v){console.warn(`Sort [${e}] does not exist.`);return}b.router.reload({...f,...o,data:{[l.value.config.sort]:g(v.next)}})}function M(e,n={}){e=[s,g].reduce((o,v)=>v(o),e),b.router.reload({...f,...n,data:{[l.value.config.search]:e}})}function U(e,n={}){const o=typeof e=="string"?F(e):e;if(!o){console.warn(`Match [${e}] does not exist.`);return}const v=I(o.name,S.value.map(({name:V})=>V));b.router.reload({...f,...n,data:{[l.value.config.match]:k(v)}})}function N(e,n={}){T(e,void 0,n)}function q(e={}){b.router.reload({...f,...e,data:{[l.value.config.sort]:void 0}})}function R(e={}){M(void 0,e)}function H(e={}){if(!l.value.config.match){console.warn("Matches key is not set.");return}b.router.reload({...f,...e,data:{[l.value.config.match]:void 0}})}function t(e={}){var n;b.router.reload({...f,...e,data:{[l.value.config.search]:void 0,[l.value.config.sort]:void 0,[l.value.config.match]:void 0,...Object.fromEntries(((n=l.value.filters)==null?void 0:n.map(o=>[o.name,void 0]))??[])}})}function a(e,n={}){const o=typeof e=="string"?C(e):e;if(!o){console.warn(`Filter [${e}] does not exist.`);return}const v=o.value,{debounce:V=250,transform:z=J=>J,...$}=n;return{"onUpdate:modelValue":G(J=>{T(o,z(J),$)},V),modelValue:v}}function d(e,n={}){const o=typeof e=="string"?h(e):e;if(!o){console.warn(`Sort [${e}] does not exist.`);return}const{debounce:v=0,transform:V,...z}=n;return{onClick:G(()=>{var $;E(o,($=A.value)==null?void 0:$.direction,z)},v)}}function L(e={}){const{debounce:n=700,transform:o,...v}=e;return{"onUpdate:modelValue":G(V=>{M(V,v)},n),modelValue:l.value.config.term??""}}function j(e,n={}){const o=typeof e=="string"?F(e):e;if(!o){console.warn(`Match [${e}] does not exist.`);return}const{debounce:v=0,transform:V,...z}=n;return{"onUpdate:modelValue":G($=>{U($,z)},v),modelValue:w(o),value:o.name}}return{filters:i,sorts:u,searches:x,getFilter:C,getSort:h,getSearch:F,currentFilters:m,currentSort:A,currentSearches:S,isFiltering:y,isSorting:K,isSearching:w,apply:W,applyFilter:T,applySort:E,applySearch:M,applyMatch:U,clearFilter:N,clearSort:q,clearSearch:R,clearMatch:H,reset:t,bindFilter:a,bindSort:d,bindSearch:L,bindMatch:j,stringValue:s,omitValue:g,toggleValue:I,delimitArray:k}}function O(r,p,f={},l={}){if(!r||!p||!r[p])throw new Error("Table has not been provided with valid props and key.");l={...l,only:[...l.only??[],p.toString()]};const i=c.computed(()=>r[p]),u=_(),x=Z(r,p,l),m=c.computed(()=>i.value.config),A=c.computed(()=>i.value.meta),S=c.computed(()=>{var t;return((t=i.value.columns)==null?void 0:t.filter(({active:a,hidden:d})=>a&&!d).map(a=>{var d;return{...a,isSorting:(d=a.sort)==null?void 0:d.active,toggleSort:(L={})=>U(a,L)}}))??[]}),k=c.computed(()=>{var t;return((t=i.value.columns)==null?void 0:t.filter(({hidden:a})=>!a).map(a=>({...a,toggle:(d={})=>N(a,d)})))??[]}),s=c.computed(()=>i.value.records.map(t=>({record:(({actions:a,...d})=>d)(t),default:(a={})=>{const d=t.actions.find(L=>L.default);d&&W(d,t,a)},actions:t.actions.map(a=>({...a,execute:(d={})=>W(a,t,d)})),select:()=>u.select(y(t)),deselect:()=>u.deselect(y(t)),toggle:()=>u.toggle(y(t)),selected:u.selected(y(t)),bind:()=>u.bind(y(t)),value:a=>{const d=K(a);return d in t?t[d].value:null},extra:a=>{const d=K(a);return d in t?t[d].extra:null}}))),g=c.computed(()=>i.value.actions.bulk.map(t=>({...t,execute:(a={})=>T(t,a)}))),B=c.computed(()=>i.value.actions.page.map(t=>({...t,execute:(a={})=>E(t,a)}))),I=c.computed(()=>{var t;return((t=i.value.recordsPerPage)==null?void 0:t.map(a=>({...a,apply:(d={})=>M(a,d)})))??[]}),C=c.computed(()=>{var t;return(t=i.value.recordsPerPage)==null?void 0:t.find(({active:a})=>a)}),h=c.computed(()=>({...i.value.paginator,next:(t={})=>{"nextLink"in h.value&&h.value.nextLink&&w(h.value.nextLink,t)},previous:(t={})=>{"prevLink"in h.value&&h.value.prevLink&&w(h.value.prevLink,t)},first:(t={})=>{"firstLink"in h.value&&h.value.firstLink&&w(h.value.firstLink,t)},last:(t={})=>{"lastLink"in h.value&&h.value.lastLink&&w(h.value.lastLink,t)},..."links"in i.value.paginator&&i.value.paginator.links?{links:i.value.paginator.links.map(t=>({...t,navigate:(a={})=>t.url&&w(t.url,a)}))}:{}})),F=c.computed(()=>i.value.records.length>0&&i.value.records.every(t=>u.selected(y(t))));function y(t){return t[m.value.key].value}function K(t){return typeof t=="string"?t:t.name}function w(t,a={}){b.router.visit(t,{preserveScroll:!0,preserveState:!0,...l,...a,method:"get"})}function W(t,a,d={}){var j,e;D(t,m.value.endpoint,{table:i.value.id,id:y(a)},d)||(e=(j=f.recordActions)==null?void 0:j[t.name])==null||e.call(j,a)}function T(t,a={}){D(t,m.value.endpoint,{table:i.value.id,all:u.selection.value.all,only:Array.from(u.selection.value.only),except:Array.from(u.selection.value.except)},a)}function E(t,a={}){D(t,m.value.endpoint,{table:i.value.id},a)}function M(t,a={}){b.router.reload({...l,...a,data:{[m.value.record]:t.value,[m.value.page]:void 0}})}function U(t,a={}){t.sort&&b.router.reload({...l,...a,data:{[m.value.sort]:x.omitValue(t.sort.next)}})}function N(t,a={}){const d=x.toggleValue(t.name,S.value.map(({name:L})=>L));b.router.reload({...l,...a,data:{[m.value.column]:x.delimitArray(d)}})}function q(){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?q():R()},modelValue:F.value}}return c.reactive({getRecordKey:y,meta:A,headings:S,columns:k,records:s,inline:i.value.actions.inline,bulkActions:g,pageActions:B,rowsPerPage:I,currentPage:C,paginator:h,executeInlineAction:W,executeBulkAction:T,executePageAction:E,applyPage:M,selection:u.selection,select:t=>u.select(y(t)),deselect:t=>u.deselect(y(t)),selectPage:q,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"})});
1
+ (function(w,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("vue"),require("@inertiajs/vue3")):typeof define=="function"&&define.amd?define(["exports","vue","@inertiajs/vue3"],s):(w=typeof globalThis<"u"?globalThis:w||self,s(w["@honed/table"]={},w.Vue,w.Inertia))})(this,function(w,s,b){"use strict";function D(o,p,f={},a={}){return o.route?(b.router.visit(o.route.url,{...a,method:o.route.method}),!0):o.action&&p?(b.router.post(p,{...f,name:o.name,type:o.type},a),!0):!1}function _(){const o=s.ref({all:!1,only:new Set,except:new Set});function p(){o.value.all=!0,o.value.only.clear(),o.value.except.clear()}function f(){o.value.all=!1,o.value.only.clear(),o.value.except.clear()}function a(...d){d.forEach(g=>o.value.except.delete(g)),d.forEach(g=>o.value.only.add(g))}function i(...d){d.forEach(g=>o.value.except.add(g)),d.forEach(g=>o.value.only.delete(g))}function u(d,g){if(S(d)||g===!1)return i(d);if(!S(d)||g===!0)return a(d)}function S(d){return o.value.all?!o.value.except.has(d):o.value.only.has(d)}const m=s.computed(()=>o.value.all&&o.value.except.size===0),A=s.computed(()=>o.value.only.size>0||m.value);function x(d){return{"onUpdate:modelValue":g=>{g?a(d):i(d)},modelValue:S(d),value:d}}function k(){return{"onUpdate:modelValue":d=>{d?p():f()},modelValue:m.value,value:m.value}}return{allSelected:m,selection:o,hasSelected:A,selectAll:p,deselectAll:f,select:a,deselect:i,toggle:u,selected:S,bind:x,bindAll:k}}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Y=()=>{};function Q(o,p){function f(...a){return new Promise((i,u)=>{Promise.resolve(o(()=>p.apply(this,a),{fn:p,thisArg:this,args:a})).then(i).catch(u)})}return f}function X(o,p={}){let f,a,i=Y;const u=m=>{clearTimeout(m),i(),i=Y};let S;return m=>{const A=s.toValue(o),x=s.toValue(p.maxWait);return f&&u(f),A<=0||x!==void 0&&x<=0?(a&&(u(a),a=null),Promise.resolve(m())):new Promise((k,d)=>{i=p.rejectOnCancel?d:k,S=m,x&&!a&&(a=setTimeout(()=>{f&&u(f),a=null,k(S())},x)),f=setTimeout(()=>{a&&u(a),a=null,k(m())},A)})}}function G(o,p=200,f={}){return Q(X(p,f),o)}function Z(o,p,f={}){const a=s.computed(()=>o[p]),i=s.computed(()=>{var e;return((e=a.value.filters)==null?void 0:e.map(n=>({...n,apply:(r,v={})=>T(n,r,v),clear:(r={})=>N(n,r),bind:()=>l(n.name)})))??[]}),u=s.computed(()=>{var e;return((e=a.value.sorts)==null?void 0:e.map(n=>({...n,apply:(r={})=>E(n,n.direction,r),clear:(r={})=>q(r),bind:()=>c(n)})))??[]}),S=s.computed(()=>{var e;return(e=a.value.searches)==null?void 0:e.map(n=>({...n,apply:(r={})=>U(n,r),clear:(r={})=>U(n,r),bind:()=>j(n)}))}),m=s.computed(()=>{var e;return((e=a.value.filters)==null?void 0:e.filter(({active:n})=>n))??[]}),A=s.computed(()=>{var e;return(e=a.value.sorts)==null?void 0:e.find(({active:n})=>n)}),x=s.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 d(e){return typeof e!="string"?e:e.trim().replace(/\s+/g,"+")}function g(e){if(!["",null,void 0,[]].includes(e))return e}function B(e){return[k,d,g].reduce((n,r)=>r(n),e)}function I(e,n){return n=Array.isArray(n)?n:[n],n.includes(e)?n.filter(r=>r!==e):[...n,e]}function C(e){var n;return(n=a.value.filters)==null?void 0:n.find(r=>r.name===e)}function h(e,n=null){var r;return(r=a.value.sorts)==null?void 0:r.find(v=>v.name===e&&v.direction===n)}function F(e){var n;return(n=a.value.searches)==null?void 0:n.find(r=>r.name===e)}function y(e){return e?typeof e=="string"?m.value.some(n=>n.name===e):e.active:!!m.value.length}function K(e){var n;return e?typeof e=="string"?((n=A.value)==null?void 0:n.name)===e:e.active:!!A.value}function L(e){var n;return e?typeof e=="string"?(n=x.value)==null?void 0:n.some(r=>r.name===e):e.active:!!a.value.config.term}function W(e,n={}){const r=Object.fromEntries(Object.entries(e).map(([v,P])=>[v,B(P)]));b.router.reload({...f,...n,data:r})}function T(e,n,r={}){const v=typeof e=="string"?C(e):e;if(!v){console.warn(`Filter [${e}] does not exist.`);return}b.router.reload({...f,...r,data:{[v.name]:B(n)}})}function E(e,n=null,r={}){const v=typeof e=="string"?h(e,n):e;if(!v){console.warn(`Sort [${e}] does not exist.`);return}b.router.reload({...f,...r,data:{[a.value.config.sort]:g(v.next)}})}function M(e,n={}){e=[d,g].reduce((r,v)=>v(r),e),b.router.reload({...f,...n,data:{[a.value.config.search]:e}})}function U(e,n={}){const r=typeof e=="string"?F(e):e;if(!r){console.warn(`Match [${e}] does not exist.`);return}const v=I(r.name,x.value.map(({name:P})=>P));b.router.reload({...f,...n,data:{[a.value.config.match]:k(v)}})}function N(e,n={}){T(e,void 0,n)}function q(e={}){b.router.reload({...f,...e,data:{[a.value.config.sort]:void 0}})}function R(e={}){M(void 0,e)}function H(e={}){if(!a.value.config.match){console.warn("Matches key is not set.");return}b.router.reload({...f,...e,data:{[a.value.config.match]:void 0}})}function t(e={}){var n;b.router.reload({...f,...e,data:{[a.value.config.search]:void 0,[a.value.config.sort]:void 0,[a.value.config.match]:void 0,...Object.fromEntries(((n=a.value.filters)==null?void 0:n.map(r=>[r.name,void 0]))??[])}})}function l(e,n={}){const r=typeof e=="string"?C(e):e;if(!r){console.warn(`Filter [${e}] does not exist.`);return}const v=r.value,{debounce:P=250,transform:z=J=>J,...$}=n;return{"onUpdate:modelValue":G(J=>{T(r,z(J),$)},P),modelValue:v}}function c(e,n={}){const r=typeof e=="string"?h(e):e;if(!r){console.warn(`Sort [${e}] does not exist.`);return}const{debounce:v=0,transform:P,...z}=n;return{onClick:G(()=>{var $;E(r,($=A.value)==null?void 0:$.direction,z)},v)}}function V(e={}){const{debounce:n=700,transform:r,...v}=e;return{"onUpdate:modelValue":G(P=>{M(P,v)},n),modelValue:a.value.config.term??""}}function j(e,n={}){const r=typeof e=="string"?F(e):e;if(!r){console.warn(`Match [${e}] does not exist.`);return}const{debounce:v=0,transform:P,...z}=n;return{"onUpdate:modelValue":G($=>{U($,z)},v),modelValue:L(r),value:r.name}}return{filters:i,sorts:u,searches:S,getFilter:C,getSort:h,getSearch:F,currentFilters:m,currentSort:A,currentSearches:x,isFiltering:y,isSorting:K,isSearching:L,apply:W,applyFilter:T,applySort:E,applySearch:M,applyMatch:U,clearFilter:N,clearSort:q,clearSearch:R,clearMatch:H,reset:t,bindFilter:l,bindSort:c,bindSearch:V,bindMatch:j,stringValue:d,omitValue:g,toggleValue:I,delimitArray:k}}function O(o,p,f={},a={}){if(!o||!p||!o[p])throw new Error("Table has not been provided with valid props and key.");a={...a,only:[...a.only??[],p.toString()]};const i=s.computed(()=>o[p]),u=_(),S=Z(o,p,a),m=s.computed(()=>i.value.config),A=s.computed(()=>i.value.meta),x=s.computed(()=>{var t;return((t=i.value.columns)==null?void 0:t.filter(({active:l,hidden:c})=>l&&!c).map(l=>{var c;return{...l,isSorting:(c=l.sort)==null?void 0:c.active,toggleSort:(V={})=>U(l,V)}}))??[]}),k=s.computed(()=>{var t;return((t=i.value.columns)==null?void 0:t.filter(({hidden:l})=>!l).map(l=>({...l,toggle:(c={})=>N(l,c)})))??[]}),d=s.computed(()=>i.value.records.map(t=>({record:(({actions:l,...c})=>c)(t),actions:t.actions.map(l=>({...l,execute:(c={})=>W(l,t,c)})),default:(l={})=>{const c=t.actions.find(V=>V.default);c&&W(c,t,l)},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 c=K(l);return c in t?t[c].value:null},extra:l=>{const c=K(l);return c in t?t[c].extra:null}}))),g=s.computed(()=>i.value.actions.bulk.map(t=>({...t,execute:(l={})=>T(t,l)}))),B=s.computed(()=>i.value.actions.page.map(t=>({...t,execute:(l={})=>E(t,l)}))),I=s.computed(()=>{var t;return((t=i.value.recordsPerPage)==null?void 0:t.map(l=>({...l,apply:(c={})=>M(l,c)})))??[]}),C=s.computed(()=>{var t;return(t=i.value.recordsPerPage)==null?void 0:t.find(({active:l})=>l)}),h=s.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:(l={})=>t.url&&L(t.url,l)}))}:{}})),F=s.computed(()=>i.value.records.length>0&&i.value.records.every(t=>u.selected(y(t))));function y(t){return t[m.value.key].value}function K(t){return typeof t=="string"?t:t.name}function L(t,l={}){b.router.visit(t,{preserveScroll:!0,preserveState:!0,...a,...l,method:"get"})}function W(t,l,c={}){var j,e;D(t,m.value.endpoint,{id:i.value.id,record:y(l)},c)||(e=(j=f.recordActions)==null?void 0:j[t.name])==null||e.call(j,l)}function T(t,l={}){D(t,m.value.endpoint,{id:i.value.id,all:u.selection.value.all,only:Array.from(u.selection.value.only),except:Array.from(u.selection.value.except)},{...l,onSuccess:c=>{var V;(V=l.onSuccess)==null||V.call(l,c),t.keepSelected||u.deselectAll()}})}function E(t,l={}){D(t,m.value.endpoint,{id:i.value.id},l)}function M(t,l={}){b.router.reload({...a,...l,data:{[m.value.record]:t.value,[m.value.page]:void 0}})}function U(t,l={}){t.sort&&b.router.reload({...a,...l,data:{[m.value.sort]:S.omitValue(t.sort.next)}})}function N(t,l={}){const c=S.toggleValue(t.name,x.value.map(({name:V})=>V));b.router.reload({...a,...l,data:{[m.value.column]:S.delimitArray(c)}})}function q(){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?q():R()},modelValue:F.value}}return s.reactive({getRecordKey:y,meta:A,headings:x,columns:k,records:d,inline:i.value.actions.inline,bulkActions:g,pageActions:B,rowsPerPage:I,currentPage:C,paginator:h,executeInlineAction:W,executeBulkAction:T,executePageAction:E,applyPage:M,selection:u.selection,select:t=>u.select(y(t)),deselect:t=>u.deselect(y(t)),selectPage:q,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,...S})}w.useTable=O,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@honed/table",
3
3
  "private": false,
4
- "version": "0.6.0",
4
+ "version": "0.7.1",
5
5
  "license": "MIT",
6
6
  "description": "-",
7
7
  "keywords": [
@@ -57,7 +57,7 @@
57
57
  }
58
58
  },
59
59
  "peerDependencies": {
60
- "@honed/action": "^0.5.0",
60
+ "@honed/action": "^0.6.1",
61
61
  "@honed/refine": "^0.5.3",
62
62
  "@inertiajs/vue3": "^1.2.0||^2.0.0",
63
63
  "@vueuse/core": "^11.0.0||^12.0.0",