@honed/table 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.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;
@@ -169,6 +169,9 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
169
169
  searches: {
170
170
  apply: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
171
171
  clear: (options?: Partial<Visit & VisitCallbacks> | undefined) => void;
172
+ /**
173
+ * Get the bulk actions.
174
+ */
172
175
  bind: () => {
173
176
  "onUpdate:modelValue": PromisifyFn<(value: any) => void>;
174
177
  modelValue: boolean;
@@ -178,6 +181,9 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
178
181
  name: string;
179
182
  label: string;
180
183
  active: boolean;
184
+ /**
185
+ * Get page actions.
186
+ */
181
187
  meta: Record<string, any>;
182
188
  }[] | undefined;
183
189
  getFilter: (name: string) => Filter | undefined;
@@ -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 */
@@ -284,7 +290,9 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
284
290
  selected: boolean;
285
291
  /** Bind the record to a checkbox */
286
292
  bind: () => {
287
- "onUpdate:modelValue": (checked: boolean | "indeterminate") => void;
293
+ "onUpdate:modelValue": (checked: boolean | "indeterminate") => void; /**
294
+ * The current number of records to display per page.
295
+ */
288
296
  modelValue: boolean;
289
297
  value: Identifier;
290
298
  };
@@ -295,7 +303,6 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
295
303
  }[];
296
304
  inline: boolean;
297
305
  bulkActions: {
298
- /** Executes this bulk action */
299
306
  execute: (options?: VisitOptions) => void;
300
307
  type: "bulk";
301
308
  keepSelected: boolean;
@@ -308,7 +315,6 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
308
315
  route?: Route | undefined;
309
316
  }[];
310
317
  pageActions: {
311
- /** Executes this page action */
312
318
  execute: (options?: VisitOptions) => void;
313
319
  type: "page";
314
320
  name: string;
@@ -320,7 +326,6 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
320
326
  route?: Route | undefined;
321
327
  }[];
322
328
  rowsPerPage: {
323
- /** Changes the number of records to display per page */
324
329
  apply: (options?: VisitOptions) => void;
325
330
  value: number;
326
331
  active: boolean;
@@ -354,7 +359,9 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
354
359
  isPageSelected: boolean;
355
360
  hasSelected: boolean;
356
361
  bindCheckbox: (record: AsRecord<RecordType>) => {
357
- "onUpdate:modelValue": (checked: boolean | "indeterminate") => void;
362
+ "onUpdate:modelValue": (checked: boolean | "indeterminate") => void; /**
363
+ * The current number of records to display per page.
364
+ */
358
365
  modelValue: boolean;
359
366
  value: Identifier;
360
367
  };
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
- import { router as x } from "@inertiajs/vue3";
2
+ import { router as S } from "@inertiajs/vue3";
3
+ function I(o, m, v = {}, l = {}) {
4
+ return o.route ? (S.visit(o.route.url, {
5
+ ...l,
6
+ method: o.route.method
7
+ }), !0) : o.action && m ? (S.post(
8
+ m,
9
+ {
10
+ ...v,
11
+ name: o.name,
12
+ type: o.type
13
+ },
14
+ l
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 l(...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 l(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 x(s) {
32
46
  return {
33
47
  "onUpdate:modelValue": (p) => {
34
- p ? l(c) : i(c);
48
+ p ? l(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
@@ -56,24 +70,10 @@ function X() {
56
70
  deselect: i,
57
71
  toggle: u,
58
72
  selected: b,
59
- bind: S,
73
+ bind: 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
  };
@@ -92,11 +92,11 @@ function O(o, m = {}) {
92
92
  };
93
93
  let b;
94
94
  return (f) => {
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(() => {
95
+ const A = J(o), x = J(m.maxWait);
96
+ return v && u(v), A <= 0 || x !== void 0 && x <= 0 ? (l && (u(l), l = null), Promise.resolve(f())) : new Promise((k, s) => {
97
+ i = m.rejectOnCancel ? s : k, b = f, x && !l && (l = setTimeout(() => {
98
98
  v && u(v), l = null, k(b());
99
- }, S)), v = setTimeout(() => {
99
+ }, x)), v = setTimeout(() => {
100
100
  l && u(l), l = null, k(f());
101
101
  }, A);
102
102
  });
@@ -114,7 +114,7 @@ function ee(o, m, v = {}) {
114
114
  var e;
115
115
  return ((e = l.value.filters) == null ? void 0 : e.map((n) => ({
116
116
  ...n,
117
- apply: (r, d = {}) => L(n, r, d),
117
+ apply: (r, d = {}) => F(n, r, d),
118
118
  clear: (r = {}) => N(n, r),
119
119
  bind: () => a(n.name)
120
120
  }))) ?? [];
@@ -126,7 +126,7 @@ function ee(o, m, v = {}) {
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(
@@ -136,7 +136,7 @@ function ee(o, m, v = {}) {
136
136
  ...n,
137
137
  apply: (r = {}) => U(n, r),
138
138
  clear: (r = {}) => U(n, r),
139
- bind: () => F(n)
139
+ bind: () => P(n)
140
140
  }));
141
141
  }
142
142
  ), f = g(
@@ -149,7 +149,7 @@ function ee(o, m, v = {}) {
149
149
  var e;
150
150
  return (e = l.value.sorts) == null ? void 0 : e.find(({ active: n }) => n);
151
151
  }
152
- ), S = g(
152
+ ), x = g(
153
153
  () => {
154
154
  var e;
155
155
  return ((e = l.value.searches) == null ? void 0 : e.filter(({ active: n }) => n)) ?? [];
@@ -158,7 +158,7 @@ function ee(o, m, v = {}) {
158
158
  function k(e) {
159
159
  return Array.isArray(e) ? e.join(l.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
  );
@@ -195,27 +195,27 @@ 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 L(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 = x.value) == null ? void 0 : n.some((r) => r.name === e) : e.active : !!l.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, w]) => [d, G(w)])
205
205
  );
206
- x.reload({
206
+ S.reload({
207
207
  ...v,
208
208
  ...n,
209
209
  data: r
210
210
  });
211
211
  }
212
- function L(e, n, r = {}) {
212
+ function F(e, n, r = {}) {
213
213
  const d = typeof e == "string" ? j(e) : e;
214
214
  if (!d) {
215
215
  console.warn(`Filter [${e}] does not exist.`);
216
216
  return;
217
217
  }
218
- x.reload({
218
+ S.reload({
219
219
  ...v,
220
220
  ...r,
221
221
  data: {
@@ -229,7 +229,7 @@ function ee(o, m, v = {}) {
229
229
  console.warn(`Sort [${e}] does not exist.`);
230
230
  return;
231
231
  }
232
- x.reload({
232
+ S.reload({
233
233
  ...v,
234
234
  ...r,
235
235
  data: {
@@ -238,10 +238,10 @@ function ee(o, m, v = {}) {
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
- ), x.reload({
244
+ ), S.reload({
245
245
  ...v,
246
246
  ...n,
247
247
  data: {
@@ -257,9 +257,9 @@ function ee(o, m, v = {}) {
257
257
  }
258
258
  const d = B(
259
259
  r.name,
260
- S.value.map(({ name: V }) => V)
260
+ x.value.map(({ name: w }) => w)
261
261
  );
262
- x.reload({
262
+ S.reload({
263
263
  ...v,
264
264
  ...n,
265
265
  data: {
@@ -268,10 +268,10 @@ function ee(o, m, v = {}) {
268
268
  });
269
269
  }
270
270
  function N(e, n = {}) {
271
- L(e, void 0, n);
271
+ F(e, void 0, n);
272
272
  }
273
273
  function W(e = {}) {
274
- x.reload({
274
+ S.reload({
275
275
  ...v,
276
276
  ...e,
277
277
  data: {
@@ -287,7 +287,7 @@ function ee(o, m, v = {}) {
287
287
  console.warn("Matches key is not set.");
288
288
  return;
289
289
  }
290
- x.reload({
290
+ S.reload({
291
291
  ...v,
292
292
  ...e,
293
293
  data: {
@@ -297,7 +297,7 @@ function ee(o, m, v = {}) {
297
297
  }
298
298
  function t(e = {}) {
299
299
  var n;
300
- x.reload({
300
+ S.reload({
301
301
  ...v,
302
302
  ...e,
303
303
  data: {
@@ -320,24 +320,24 @@ function ee(o, m, v = {}) {
320
320
  return;
321
321
  }
322
322
  const d = r.value, {
323
- debounce: V = 250,
323
+ debounce: w = 250,
324
324
  transform: z = (H) => H,
325
325
  ...$
326
326
  } = n;
327
327
  return {
328
328
  "onUpdate:modelValue": q((H) => {
329
- L(r, z(H), $);
330
- }, V),
329
+ F(r, z(H), $);
330
+ }, w),
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: w, ...z } = n;
341
341
  return {
342
342
  onClick: q(() => {
343
343
  var $;
@@ -345,30 +345,30 @@ 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
+ (w) => {
353
+ T(w, d);
354
354
  },
355
355
  n
356
356
  ),
357
357
  modelValue: l.value.config.term ?? ""
358
358
  };
359
359
  }
360
- function F(e, n = {}) {
360
+ function P(e, n = {}) {
361
361
  const r = typeof e == "string" ? E(e) : e;
362
362
  if (!r) {
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: w, ...z } = n;
367
367
  return {
368
368
  "onUpdate:modelValue": q(($) => {
369
369
  U($, z);
370
370
  }, d),
371
- modelValue: P(r),
371
+ modelValue: L(r),
372
372
  value: r.name
373
373
  };
374
374
  }
@@ -381,12 +381,12 @@ function ee(o, m, v = {}) {
381
381
  getSearch: E,
382
382
  currentFilters: f,
383
383
  currentSort: A,
384
- currentSearches: S,
384
+ currentSearches: x,
385
385
  isFiltering: y,
386
386
  isSorting: K,
387
- isSearching: P,
387
+ isSearching: L,
388
388
  apply: C,
389
- applyFilter: L,
389
+ applyFilter: F,
390
390
  applySort: M,
391
391
  applySearch: T,
392
392
  applyMatch: U,
@@ -396,10 +396,10 @@ function ee(o, m, v = {}) {
396
396
  clearMatch: D,
397
397
  reset: t,
398
398
  bindFilter: a,
399
- bindSort: s,
400
- bindSearch: w,
401
- bindMatch: F,
402
- stringValue: c,
399
+ bindSort: c,
400
+ bindSearch: V,
401
+ bindMatch: P,
402
+ stringValue: s,
403
403
  omitValue: p,
404
404
  toggleValue: B,
405
405
  delimitArray: k
@@ -407,20 +407,22 @@ function ee(o, m, v = {}) {
407
407
  }
408
408
  function le(o, m, v = {}, l = {}) {
409
409
  if (!o || !m || !o[m])
410
- throw new Error("Table has not been provided with valid props and key.");
410
+ throw new Error(
411
+ "The table has not been provided with valid props and key."
412
+ );
411
413
  l = {
412
414
  ...l,
413
415
  only: [...l.only ?? [], m.toString()]
414
416
  };
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(
417
+ const i = g(() => o[m]), u = X(), b = ee(o, m, l), f = g(() => i.value.config), A = g(() => i.value.meta), x = g(
416
418
  () => {
417
419
  var t;
418
- return ((t = i.value.columns) == null ? void 0 : t.filter(({ active: a, hidden: s }) => a && !s).map((a) => {
419
- var s;
420
+ return ((t = i.value.columns) == null ? void 0 : t.filter(({ active: a, hidden: c }) => a && !c).map((a) => {
421
+ var c;
420
422
  return {
421
423
  ...a,
422
- isSorting: (s = a.sort) == null ? void 0 : s.active,
423
- toggleSort: (w = {}) => U(a, w)
424
+ isSorting: (c = a.sort) == null ? void 0 : c.active,
425
+ toggleSort: (V = {}) => U(a, V)
424
426
  };
425
427
  })) ?? [];
426
428
  }
@@ -429,25 +431,25 @@ function le(o, m, v = {}, l = {}) {
429
431
  var t;
430
432
  return ((t = i.value.columns) == null ? void 0 : t.filter(({ hidden: a }) => !a).map((a) => ({
431
433
  ...a,
432
- toggle: (s = {}) => N(a, s)
434
+ toggle: (c = {}) => N(a, c)
433
435
  }))) ?? [];
434
436
  }
435
- ), c = g(
437
+ ), s = g(
436
438
  () => 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
- },
439
+ record: (({ actions: a, ...c }) => c)(t),
445
440
  /** The actions available for the record */
446
441
  actions: t.actions.map((a) => ({
447
442
  ...a,
448
443
  /** Executes this action */
449
- execute: (s = {}) => C(a, t, s)
444
+ execute: (c = {}) => C(a, t, c)
450
445
  })),
446
+ /** Perform this action when the record is clicked */
447
+ default: (a = {}) => {
448
+ const c = t.actions.find(
449
+ (V) => V.default
450
+ );
451
+ c && C(c, t, a);
452
+ },
451
453
  /** Selects this record */
452
454
  select: () => u.select(y(t)),
453
455
  /** Deselects this record */
@@ -460,25 +462,23 @@ function le(o, m, v = {}, l = {}) {
460
462
  bind: () => u.bind(y(t)),
461
463
  /** Get the value of the record for the column */
462
464
  value: (a) => {
463
- const s = K(a);
464
- return s in t ? t[s].value : null;
465
+ const c = K(a);
466
+ return c in t ? t[c].value : null;
465
467
  },
466
468
  /** Get the extra data of the record for the column */
467
469
  extra: (a) => {
468
- const s = K(a);
469
- return s in t ? t[s].extra : null;
470
+ const c = K(a);
471
+ return c in t ? t[c].extra : null;
470
472
  }
471
473
  }))
472
474
  ), p = g(
473
475
  () => i.value.actions.bulk.map((t) => ({
474
476
  ...t,
475
- /** Executes this bulk action */
476
- execute: (a = {}) => L(t, a)
477
+ execute: (a = {}) => F(t, a)
477
478
  }))
478
479
  ), G = g(
479
480
  () => i.value.actions.page.map((t) => ({
480
481
  ...t,
481
- /** Executes this page action */
482
482
  execute: (a = {}) => M(t, a)
483
483
  }))
484
484
  ), B = g(
@@ -486,8 +486,7 @@ function le(o, m, v = {}, l = {}) {
486
486
  var t;
487
487
  return ((t = i.value.recordsPerPage) == null ? void 0 : t.map((a) => ({
488
488
  ...a,
489
- /** Changes the number of records to display per page */
490
- apply: (s = {}) => T(a, s)
489
+ apply: (c = {}) => T(a, c)
491
490
  }))) ?? [];
492
491
  }
493
492
  ), j = g(
@@ -498,21 +497,21 @@ function le(o, m, v = {}, l = {}) {
498
497
  ), h = g(() => ({
499
498
  ...i.value.paginator,
500
499
  next: (t = {}) => {
501
- "nextLink" in h.value && h.value.nextLink && P(h.value.nextLink, t);
500
+ "nextLink" in h.value && h.value.nextLink && L(h.value.nextLink, t);
502
501
  },
503
502
  previous: (t = {}) => {
504
- "prevLink" in h.value && h.value.prevLink && P(h.value.prevLink, t);
503
+ "prevLink" in h.value && h.value.prevLink && L(h.value.prevLink, t);
505
504
  },
506
505
  first: (t = {}) => {
507
- "firstLink" in h.value && h.value.firstLink && P(h.value.firstLink, t);
506
+ "firstLink" in h.value && h.value.firstLink && L(h.value.firstLink, t);
508
507
  },
509
508
  last: (t = {}) => {
510
- "lastLink" in h.value && h.value.lastLink && P(h.value.lastLink, t);
509
+ "lastLink" in h.value && h.value.lastLink && L(h.value.lastLink, t);
511
510
  },
512
511
  ..."links" in i.value.paginator && i.value.paginator.links ? {
513
512
  links: i.value.paginator.links.map((t) => ({
514
513
  ...t,
515
- navigate: (a = {}) => t.url && P(t.url, a)
514
+ navigate: (a = {}) => t.url && L(t.url, a)
516
515
  }))
517
516
  } : {}
518
517
  })), E = g(
@@ -526,8 +525,8 @@ function le(o, m, v = {}, l = {}) {
526
525
  function K(t) {
527
526
  return typeof t == "string" ? t : t.name;
528
527
  }
529
- function P(t, a = {}) {
530
- x.visit(t, {
528
+ function L(t, a = {}) {
529
+ S.visit(t, {
531
530
  preserveScroll: !0,
532
531
  preserveState: !0,
533
532
  ...l,
@@ -535,29 +534,39 @@ function le(o, m, v = {}, l = {}) {
535
534
  method: "get"
536
535
  });
537
536
  }
538
- function C(t, a, s = {}) {
539
- var F, e;
537
+ function C(t, a, c = {}) {
538
+ var P, e;
540
539
  I(
541
540
  t,
542
541
  f.value.endpoint,
543
542
  {
544
- table: i.value.id,
545
- id: y(a)
543
+ id: i.value.id,
544
+ record: y(a)
546
545
  },
547
- s
548
- ) || (e = (F = v.recordActions) == null ? void 0 : F[t.name]) == null || e.call(F, a);
546
+ {
547
+ ...l,
548
+ ...c
549
+ }
550
+ ) || (e = (P = v.recordActions) == null ? void 0 : P[t.name]) == null || e.call(P, a);
549
551
  }
550
- function L(t, a = {}) {
552
+ function F(t, a = {}) {
551
553
  I(
552
554
  t,
553
555
  f.value.endpoint,
554
556
  {
555
- table: i.value.id,
557
+ id: i.value.id,
556
558
  all: u.selection.value.all,
557
559
  only: Array.from(u.selection.value.only),
558
560
  except: Array.from(u.selection.value.except)
559
561
  },
560
- a
562
+ {
563
+ ...l,
564
+ ...a,
565
+ onSuccess: (c) => {
566
+ var V, P;
567
+ (V = l.onSuccess) == null || V.call(l, c), (P = a.onSuccess) == null || P.call(a, c), t.keepSelected || u.deselectAll();
568
+ }
569
+ }
561
570
  );
562
571
  }
563
572
  function M(t, a = {}) {
@@ -565,13 +574,16 @@ function le(o, m, v = {}, l = {}) {
565
574
  t,
566
575
  f.value.endpoint,
567
576
  {
568
- table: i.value.id
577
+ id: i.value.id
569
578
  },
570
- a
579
+ {
580
+ ...l,
581
+ ...a
582
+ }
571
583
  );
572
584
  }
573
585
  function T(t, a = {}) {
574
- x.reload({
586
+ S.reload({
575
587
  ...l,
576
588
  ...a,
577
589
  data: {
@@ -581,7 +593,7 @@ function le(o, m, v = {}, l = {}) {
581
593
  });
582
594
  }
583
595
  function U(t, a = {}) {
584
- t.sort && x.reload({
596
+ t.sort && S.reload({
585
597
  ...l,
586
598
  ...a,
587
599
  data: {
@@ -590,15 +602,15 @@ function le(o, m, v = {}, l = {}) {
590
602
  });
591
603
  }
592
604
  function N(t, a = {}) {
593
- const s = b.toggleValue(
605
+ const c = b.toggleValue(
594
606
  t.name,
595
- S.value.map(({ name: w }) => w)
607
+ x.value.map(({ name: V }) => V)
596
608
  );
597
- x.reload({
609
+ S.reload({
598
610
  ...l,
599
611
  ...a,
600
612
  data: {
601
- [f.value.column]: b.delimitArray(s)
613
+ [f.value.column]: b.delimitArray(c)
602
614
  }
603
615
  });
604
616
  }
@@ -630,11 +642,11 @@ function le(o, m, v = {}, l = {}) {
630
642
  /** Table-specific metadata */
631
643
  meta: A,
632
644
  /** The heading columns for the table */
633
- headings: S,
645
+ headings: x,
634
646
  /** All of the table's columns */
635
647
  columns: k,
636
648
  /** The records of the table */
637
- records: c,
649
+ records: s,
638
650
  /** Whether the table has record actions */
639
651
  inline: i.value.actions.inline,
640
652
  /** The available bulk actions */
@@ -650,7 +662,7 @@ function le(o, m, v = {}, l = {}) {
650
662
  /** Execute an inline action */
651
663
  executeInlineAction: C,
652
664
  /** Execute a bulk action */
653
- executeBulkAction: L,
665
+ executeBulkAction: F,
654
666
  /** Execute a page action */
655
667
  executePageAction: M,
656
668
  /** Apply a new page by changing the number of records to display */
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(L,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):(L=typeof globalThis<"u"?globalThis:L||self,s(L["@honed/table"]={},L.Vue,L.Inertia))})(this,function(L,s,b){"use strict";function D(o,p,f={},l={}){return o.route?(b.router.visit(o.route.url,{...l,method:o.route.method}),!0):o.action&&p?(b.router.post(p,{...f,name:o.name,type:o.type},l),!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 l(...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 l(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?l(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:l,deselect:i,toggle:u,selected:S,bind:x,bindAll:k}}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Y=()=>{};function Q(o,p){function f(...l){return new Promise((i,u)=>{Promise.resolve(o(()=>p.apply(this,l),{fn:p,thisArg:this,args:l})).then(i).catch(u)})}return f}function X(o,p={}){let f,l,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?(l&&(u(l),l=null),Promise.resolve(m())):new Promise((k,d)=>{i=p.rejectOnCancel?d:k,S=m,x&&!l&&(l=setTimeout(()=>{f&&u(f),l=null,k(S())},x)),f=setTimeout(()=>{l&&u(l),l=null,k(m())},A)})}}function G(o,p=200,f={}){return Q(X(p,f),o)}function Z(o,p,f={}){const l=s.computed(()=>o[p]),i=s.computed(()=>{var e;return((e=l.value.filters)==null?void 0:e.map(n=>({...n,apply:(r,v={})=>j(n,r,v),clear:(r={})=>N(n,r),bind:()=>a(n.name)})))??[]}),u=s.computed(()=>{var e;return((e=l.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=l.value.searches)==null?void 0:e.map(n=>({...n,apply:(r={})=>U(n,r),clear:(r={})=>U(n,r),bind:()=>P(n)}))}),m=s.computed(()=>{var e;return((e=l.value.filters)==null?void 0:e.filter(({active:n})=>n))??[]}),A=s.computed(()=>{var e;return(e=l.value.sorts)==null?void 0:e.find(({active:n})=>n)}),x=s.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 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=l.value.filters)==null?void 0:n.find(r=>r.name===e)}function h(e,n=null){var r;return(r=l.value.sorts)==null?void 0:r.find(v=>v.name===e&&v.direction===n)}function F(e){var n;return(n=l.value.searches)==null?void 0:n.find(r=>r.name===e)}function y(e){return e?typeof e=="string"?m.value.some(n=>n.name===e):e.active:!!m.value.length}function K(e){var n;return e?typeof e=="string"?((n=A.value)==null?void 0:n.name)===e:e.active:!!A.value}function T(e){var n;return e?typeof e=="string"?(n=x.value)==null?void 0:n.some(r=>r.name===e):e.active:!!l.value.config.term}function W(e,n={}){const r=Object.fromEntries(Object.entries(e).map(([v,w])=>[v,B(w)]));b.router.reload({...f,...n,data:r})}function j(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:{[l.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:{[l.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:w})=>w));b.router.reload({...f,...n,data:{[l.value.config.match]:k(v)}})}function N(e,n={}){j(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(r=>[r.name,void 0]))??[])}})}function a(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:w=250,transform:z=J=>J,...$}=n;return{"onUpdate:modelValue":G(J=>{j(r,z(J),$)},w),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:w,...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(w=>{M(w,v)},n),modelValue:l.value.config.term??""}}function P(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:w,...z}=n;return{"onUpdate:modelValue":G($=>{U($,z)},v),modelValue:T(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:T,apply:W,applyFilter:j,applySort:E,applySearch:M,applyMatch:U,clearFilter:N,clearSort:q,clearSearch:R,clearMatch:H,reset:t,bindFilter:a,bindSort:c,bindSearch:V,bindMatch:P,stringValue:d,omitValue:g,toggleValue:I,delimitArray:k}}function O(o,p,f={},l={}){if(!o||!p||!o[p])throw new Error("The table has not been provided with valid props and key.");l={...l,only:[...l.only??[],p.toString()]};const i=s.computed(()=>o[p]),u=_(),S=Z(o,p,l),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:a,hidden:c})=>a&&!c).map(a=>{var c;return{...a,isSorting:(c=a.sort)==null?void 0:c.active,toggleSort:(V={})=>U(a,V)}}))??[]}),k=s.computed(()=>{var t;return((t=i.value.columns)==null?void 0:t.filter(({hidden:a})=>!a).map(a=>({...a,toggle:(c={})=>N(a,c)})))??[]}),d=s.computed(()=>i.value.records.map(t=>({record:(({actions:a,...c})=>c)(t),actions:t.actions.map(a=>({...a,execute:(c={})=>W(a,t,c)})),default:(a={})=>{const c=t.actions.find(V=>V.default);c&&W(c,t,a)},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 c=K(a);return c in t?t[c].value:null},extra:a=>{const c=K(a);return c in t?t[c].extra:null}}))),g=s.computed(()=>i.value.actions.bulk.map(t=>({...t,execute:(a={})=>j(t,a)}))),B=s.computed(()=>i.value.actions.page.map(t=>({...t,execute:(a={})=>E(t,a)}))),I=s.computed(()=>{var t;return((t=i.value.recordsPerPage)==null?void 0:t.map(a=>({...a,apply:(c={})=>M(a,c)})))??[]}),C=s.computed(()=>{var t;return(t=i.value.recordsPerPage)==null?void 0:t.find(({active:a})=>a)}),h=s.computed(()=>({...i.value.paginator,next:(t={})=>{"nextLink"in h.value&&h.value.nextLink&&T(h.value.nextLink,t)},previous:(t={})=>{"prevLink"in h.value&&h.value.prevLink&&T(h.value.prevLink,t)},first:(t={})=>{"firstLink"in h.value&&h.value.firstLink&&T(h.value.firstLink,t)},last:(t={})=>{"lastLink"in h.value&&h.value.lastLink&&T(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&&T(t.url,a)}))}:{}})),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 T(t,a={}){b.router.visit(t,{preserveScroll:!0,preserveState:!0,...l,...a,method:"get"})}function W(t,a,c={}){var P,e;D(t,m.value.endpoint,{id:i.value.id,record:y(a)},{...l,...c})||(e=(P=f.recordActions)==null?void 0:P[t.name])==null||e.call(P,a)}function j(t,a={}){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,...a,onSuccess:c=>{var V,P;(V=l.onSuccess)==null||V.call(l,c),(P=a.onSuccess)==null||P.call(a,c),t.keepSelected||u.deselectAll()}})}function E(t,a={}){D(t,m.value.endpoint,{id:i.value.id},{...l,...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]:S.omitValue(t.sort.next)}})}function N(t,a={}){const c=S.toggleValue(t.name,x.value.map(({name:V})=>V));b.router.reload({...l,...a,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:j,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})}L.useTable=O,Object.defineProperty(L,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.0",
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",