@honed/table 0.4.3 → 0.5.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
@@ -18,7 +18,7 @@ import { Visit } from '@inertiajs/core';
18
18
  import { VisitCallbacks } from '@inertiajs/core';
19
19
  import { VisitOptions } from '@inertiajs/core';
20
20
 
21
- export declare type AsRecord<RecordType extends Record<string, any>> = {
21
+ export declare type AsRecord<RecordType extends Record<string, any> = any> = {
22
22
  [K in keyof RecordType]: {
23
23
  value: RecordType[K];
24
24
  extra: Record<string, any>;
@@ -29,10 +29,10 @@ export declare interface CollectionPaginator {
29
29
  empty: boolean;
30
30
  }
31
31
 
32
- export declare interface Column<T extends Record<string, any>> {
32
+ export declare interface Column<T extends Record<string, any> = Record<string, any>> {
33
33
  name: keyof T;
34
34
  label: string;
35
- type: "text" | "number" | "date" | "boolean" | "hidden" | "key" | string;
35
+ type: "array" | "badge" | "boolean" | "currency" | "date" | "hidden" | "key" | "number" | "text" | string;
36
36
  hidden: boolean;
37
37
  active: boolean;
38
38
  toggleable: boolean;
@@ -47,10 +47,10 @@ export declare interface Column<T extends Record<string, any>> {
47
47
 
48
48
  export declare interface Config extends Config_2 {
49
49
  endpoint: string;
50
+ key: string;
50
51
  record: string;
51
- records: string;
52
- columns: string;
53
- pages: string;
52
+ column: string;
53
+ page: string;
54
54
  }
55
55
 
56
56
  export declare interface CursorPaginator extends CollectionPaginator {
@@ -105,23 +105,23 @@ export declare interface Table<RecordType extends Record<string, any> = any, Pag
105
105
  meta: Record<string, any>;
106
106
  }
107
107
 
108
- export declare interface TableColumn<T extends Record<string, any>> extends Column<T> {
108
+ export declare interface TableColumn<T extends Record<string, any> = Record<string, any>> extends Column<T> {
109
109
  toggle: (options: VisitOptions) => void;
110
110
  }
111
111
 
112
- export declare interface TableHeading<T extends Record<string, any>> extends Column<T> {
112
+ export declare interface TableHeading<T extends Record<string, any> = Record<string, any>> extends Column<T> {
113
113
  isSorting: boolean;
114
114
  toggleSort: (options: VisitOptions) => void;
115
115
  }
116
116
 
117
- export declare interface TableOptions<RecordType extends Record<string, any>> {
117
+ export declare interface TableOptions<RecordType extends Record<string, any> = Record<string, any>> {
118
118
  /**
119
119
  * Actions to be applied on a record in JavaScript.
120
120
  */
121
121
  recordActions?: Record<string, (record: AsRecord<RecordType>) => void>;
122
122
  }
123
123
 
124
- export declare interface TableRecord<RecordType extends Record<string, any>> {
124
+ export declare interface TableRecord<RecordType extends Record<string, any> = Record<string, any>> {
125
125
  record: RecordType;
126
126
  default: (options?: VisitOptions) => void;
127
127
  actions: InlineAction[];
@@ -146,7 +146,6 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
146
146
  } | undefined;
147
147
  type: string;
148
148
  value: FilterValue;
149
- /** Selects this record */
150
149
  options: Option_2[];
151
150
  multiple: boolean;
152
151
  name: string;
@@ -180,9 +179,6 @@ export declare function useTable<Props extends object, Key extends Props[keyof P
180
179
  name: string;
181
180
  label: string;
182
181
  active: boolean;
183
- /**
184
- * The available bulk actions.
185
- */
186
182
  meta: Record<string, any>;
187
183
  }[] | undefined;
188
184
  getFilter: (name: string) => Filter | undefined;
package/dist/index.es.js CHANGED
@@ -12,7 +12,7 @@ function X() {
12
12
  function d() {
13
13
  o.value.all = !1, o.value.only.clear(), o.value.except.clear();
14
14
  }
15
- function a(...c) {
15
+ function l(...c) {
16
16
  c.forEach((g) => o.value.except.delete(g)), c.forEach((g) => o.value.only.add(g));
17
17
  }
18
18
  function i(...c) {
@@ -22,7 +22,7 @@ function X() {
22
22
  if (b(c) || g === !1)
23
23
  return i(c);
24
24
  if (!b(c) || g === !0)
25
- return a(c);
25
+ return l(c);
26
26
  }
27
27
  function b(c) {
28
28
  return o.value.all ? !o.value.except.has(c) : o.value.only.has(c);
@@ -31,7 +31,7 @@ function X() {
31
31
  function S(c) {
32
32
  return {
33
33
  "onUpdate:modelValue": (g) => {
34
- g ? a(c) : i(c);
34
+ g ? l(c) : i(c);
35
35
  },
36
36
  modelValue: b(c),
37
37
  value: c
@@ -52,7 +52,7 @@ function X() {
52
52
  hasSelected: A,
53
53
  selectAll: m,
54
54
  deselectAll: d,
55
- select: a,
55
+ select: l,
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 = {}, a = {}) {
64
- return o.route ? (x.visit(o.route.href, {
65
- ...a,
63
+ function I(o, m, d = {}, l = {}) {
64
+ return o.route ? (x.visit(o.route.url, {
65
+ ...l,
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 = {}, a = {}) {
71
71
  name: o.name,
72
72
  type: o.type
73
73
  },
74
- a
74
+ l
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(...a) {
81
+ function d(...l) {
82
82
  return new Promise((i, u) => {
83
- Promise.resolve(o(() => m.apply(this, a), { fn: m, thisArg: this, args: a })).then(i).catch(u);
83
+ Promise.resolve(o(() => m.apply(this, l), { fn: m, thisArg: this, args: l })).then(i).catch(u);
84
84
  });
85
85
  }
86
86
  return d;
87
87
  }
88
88
  function O(o, m = {}) {
89
- let d, a, i = Y;
89
+ let d, l, 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 ? (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());
96
+ return d && u(d), 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
+ d && u(d), l = null, k(b());
99
99
  }, S)), d = setTimeout(() => {
100
- a && u(a), a = null, k(f());
100
+ l && u(l), l = null, k(f());
101
101
  }, A);
102
102
  });
103
103
  };
@@ -109,30 +109,30 @@ function q(o, m = 200, d = {}) {
109
109
  );
110
110
  }
111
111
  function ee(o, m, d = {}) {
112
- const a = p(() => o[m]), i = p(
112
+ const l = p(() => o[m]), i = p(
113
113
  () => {
114
114
  var e;
115
- return ((e = a.value.filters) == null ? void 0 : e.map((n) => ({
115
+ return ((e = l.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: () => l(n.name)
119
+ bind: () => a(n.name)
120
120
  }))) ?? [];
121
121
  }
122
122
  ), u = p(
123
123
  () => {
124
124
  var e;
125
- return ((e = a.value.sorts) == null ? void 0 : e.map((n) => ({
125
+ return ((e = l.value.sorts) == null ? void 0 : e.map((n) => ({
126
126
  ...n,
127
127
  apply: (r = {}) => M(n, n.direction, r),
128
- clear: (r = {}) => z(r),
128
+ clear: (r = {}) => G(r),
129
129
  bind: () => s(n)
130
130
  }))) ?? [];
131
131
  }
132
132
  ), b = p(
133
133
  () => {
134
134
  var e;
135
- return (e = a.value.searches) == null ? void 0 : e.map((n) => ({
135
+ return (e = l.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,21 +142,21 @@ function ee(o, m, d = {}) {
142
142
  ), f = p(
143
143
  () => {
144
144
  var e;
145
- return ((e = a.value.filters) == null ? void 0 : e.filter(({ active: n }) => n)) ?? [];
145
+ return ((e = l.value.filters) == null ? void 0 : e.filter(({ active: n }) => n)) ?? [];
146
146
  }
147
147
  ), A = p(
148
148
  () => {
149
149
  var e;
150
- return (e = a.value.sorts) == null ? void 0 : e.find(({ active: n }) => n);
150
+ return (e = l.value.sorts) == null ? void 0 : e.find(({ active: n }) => n);
151
151
  }
152
152
  ), S = p(
153
153
  () => {
154
154
  var e;
155
- return ((e = a.value.searches) == null ? void 0 : e.filter(({ active: n }) => n)) ?? [];
155
+ return ((e = l.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(a.value.config.delimiter) : e;
159
+ return Array.isArray(e) ? e.join(l.value.config.delimiter) : e;
160
160
  }
161
161
  function c(e) {
162
162
  return typeof e != "string" ? e : e.trim().replace(/\s+/g, "+");
@@ -176,17 +176,17 @@ function ee(o, m, d = {}) {
176
176
  }
177
177
  function C(e) {
178
178
  var n;
179
- return (n = a.value.filters) == null ? void 0 : n.find((r) => r.name === e);
179
+ return (n = l.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 = a.value.sorts) == null ? void 0 : r.find(
183
+ return (r = l.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 = a.value.searches) == null ? void 0 : n.find((r) => r.name === e);
189
+ return (n = l.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 P(e) {
198
+ function V(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 : !!a.value.config.search;
200
+ return e ? typeof e == "string" ? (n = S.value) == null ? void 0 : n.some((r) => r.name === e) : e.active : !!l.value.config.term;
201
201
  }
202
- function W(e, n = {}) {
202
+ function z(e, n = {}) {
203
203
  const r = Object.fromEntries(
204
- Object.entries(e).map(([v, V]) => [v, B(V)])
204
+ Object.entries(e).map(([v, P]) => [v, B(P)])
205
205
  );
206
206
  x.reload({
207
207
  ...d,
@@ -233,7 +233,7 @@ function ee(o, m, d = {}) {
233
233
  ...d,
234
234
  ...r,
235
235
  data: {
236
- [a.value.config.sorts]: g(v.next)
236
+ [l.value.config.sort]: g(v.next)
237
237
  }
238
238
  });
239
239
  }
@@ -245,15 +245,11 @@ function ee(o, m, d = {}) {
245
245
  ...d,
246
246
  ...n,
247
247
  data: {
248
- [a.value.config.searches]: e
248
+ [l.value.config.search]: e
249
249
  }
250
250
  });
251
251
  }
252
252
  function U(e, n = {}) {
253
- if (!a.value.config.matches) {
254
- console.warn("Matches key is not set.");
255
- return;
256
- }
257
253
  const r = typeof e == "string" ? E(e) : e;
258
254
  if (!r) {
259
255
  console.warn(`Match [${e}] does not exist.`);
@@ -261,25 +257,25 @@ function ee(o, m, d = {}) {
261
257
  }
262
258
  const v = j(
263
259
  r.name,
264
- S.value.map(({ name: V }) => V)
260
+ S.value.map(({ name: P }) => P)
265
261
  );
266
262
  x.reload({
267
263
  ...d,
268
264
  ...n,
269
265
  data: {
270
- [a.value.config.matches]: k(v)
266
+ [l.value.config.match]: k(v)
271
267
  }
272
268
  });
273
269
  }
274
270
  function N(e, n = {}) {
275
271
  L(e, void 0, n);
276
272
  }
277
- function z(e = {}) {
273
+ function G(e = {}) {
278
274
  x.reload({
279
275
  ...d,
280
276
  ...e,
281
277
  data: {
282
- [a.value.config.sorts]: void 0
278
+ [l.value.config.sort]: void 0
283
279
  }
284
280
  });
285
281
  }
@@ -287,7 +283,7 @@ function ee(o, m, d = {}) {
287
283
  T(void 0, e);
288
284
  }
289
285
  function D(e = {}) {
290
- if (!a.value.config.matches) {
286
+ if (!l.value.config.match) {
291
287
  console.warn("Matches key is not set.");
292
288
  return;
293
289
  }
@@ -295,7 +291,7 @@ function ee(o, m, d = {}) {
295
291
  ...d,
296
292
  ...e,
297
293
  data: {
298
- [a.value.config.matches]: void 0
294
+ [l.value.config.match]: void 0
299
295
  }
300
296
  });
301
297
  }
@@ -305,11 +301,11 @@ function ee(o, m, d = {}) {
305
301
  ...d,
306
302
  ...e,
307
303
  data: {
308
- [a.value.config.searches]: void 0,
309
- [a.value.config.sorts]: void 0,
310
- [a.value.config.matches]: void 0,
304
+ [l.value.config.search]: void 0,
305
+ [l.value.config.sort]: void 0,
306
+ [l.value.config.match]: void 0,
311
307
  ...Object.fromEntries(
312
- ((n = a.value.filters) == null ? void 0 : n.map((r) => [
308
+ ((n = l.value.filters) == null ? void 0 : n.map((r) => [
313
309
  r.name,
314
310
  void 0
315
311
  ])) ?? []
@@ -317,21 +313,21 @@ function ee(o, m, d = {}) {
317
313
  }
318
314
  });
319
315
  }
320
- function l(e, n = {}) {
316
+ function a(e, n = {}) {
321
317
  const r = typeof e == "string" ? C(e) : e;
322
318
  if (!r) {
323
319
  console.warn(`Filter [${e}] does not exist.`);
324
320
  return;
325
321
  }
326
322
  const v = r.value, {
327
- debounce: V = 250,
328
- transform: G = (H) => H,
323
+ debounce: P = 250,
324
+ transform: W = (H) => H,
329
325
  ...$
330
326
  } = n;
331
327
  return {
332
328
  "onUpdate:modelValue": q((H) => {
333
- L(r, G(H), $);
334
- }, V),
329
+ L(r, W(H), $);
330
+ }, P),
335
331
  modelValue: v
336
332
  };
337
333
  }
@@ -341,11 +337,11 @@ function ee(o, m, d = {}) {
341
337
  console.warn(`Sort [${e}] does not exist.`);
342
338
  return;
343
339
  }
344
- const { debounce: v = 0, transform: V, ...G } = n;
340
+ const { debounce: v = 0, transform: P, ...W } = n;
345
341
  return {
346
342
  onClick: q(() => {
347
343
  var $;
348
- M(r, ($ = A.value) == null ? void 0 : $.direction, G);
344
+ M(r, ($ = A.value) == null ? void 0 : $.direction, W);
349
345
  }, v)
350
346
  };
351
347
  }
@@ -353,12 +349,12 @@ function ee(o, m, d = {}) {
353
349
  const { debounce: n = 700, transform: r, ...v } = e;
354
350
  return {
355
351
  "onUpdate:modelValue": q(
356
- (V) => {
357
- T(V, v);
352
+ (P) => {
353
+ T(P, v);
358
354
  },
359
355
  n
360
356
  ),
361
- modelValue: a.value.config.search ?? ""
357
+ modelValue: l.value.config.search ?? ""
362
358
  };
363
359
  }
364
360
  function F(e, n = {}) {
@@ -367,12 +363,12 @@ function ee(o, m, d = {}) {
367
363
  console.warn(`Match [${e}] does not exist.`);
368
364
  return;
369
365
  }
370
- const { debounce: v = 0, transform: V, ...G } = n;
366
+ const { debounce: v = 0, transform: P, ...W } = n;
371
367
  return {
372
368
  "onUpdate:modelValue": q(($) => {
373
- U($, G);
369
+ U($, W);
374
370
  }, v),
375
- modelValue: P(r),
371
+ modelValue: V(r),
376
372
  value: r.name
377
373
  };
378
374
  }
@@ -388,18 +384,18 @@ function ee(o, m, d = {}) {
388
384
  currentSearches: S,
389
385
  isFiltering: y,
390
386
  isSorting: K,
391
- isSearching: P,
392
- apply: W,
387
+ isSearching: V,
388
+ apply: z,
393
389
  applyFilter: L,
394
390
  applySort: M,
395
391
  applySearch: T,
396
392
  applyMatch: U,
397
393
  clearFilter: N,
398
- clearSort: z,
394
+ clearSort: G,
399
395
  clearSearch: R,
400
396
  clearMatch: D,
401
397
  reset: t,
402
- bindFilter: l,
398
+ bindFilter: a,
403
399
  bindSort: s,
404
400
  bindSearch: w,
405
401
  bindMatch: F,
@@ -409,48 +405,48 @@ function ee(o, m, d = {}) {
409
405
  delimitArray: k
410
406
  };
411
407
  }
412
- function ae(o, m, d = {}, a = {}) {
408
+ function le(o, m, d = {}, l = {}) {
413
409
  if (!o || !m || !o[m])
414
410
  throw new Error("Table has not been provided with valid props and key.");
415
- a = {
416
- ...a,
417
- only: [...a.only ?? [], m.toString()]
411
+ l = {
412
+ ...l,
413
+ only: [...l.only ?? [], m.toString()]
418
414
  };
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(
415
+ const i = p(() => o[m]), u = X(), b = ee(o, m, l), f = p(() => i.value.config), A = p(() => i.value.meta), S = p(
420
416
  () => {
421
417
  var t;
422
- return ((t = i.value.columns) == null ? void 0 : t.filter(({ active: l, hidden: s }) => l && !s).map((l) => {
418
+ return ((t = i.value.columns) == null ? void 0 : t.filter(({ active: a, hidden: s }) => a && !s).map((a) => {
423
419
  var s;
424
420
  return {
425
- ...l,
426
- isSorting: (s = l.sort) == null ? void 0 : s.active,
427
- toggleSort: (w = {}) => U(l, w)
421
+ ...a,
422
+ isSorting: (s = a.sort) == null ? void 0 : s.active,
423
+ toggleSort: (w = {}) => U(a, w)
428
424
  };
429
425
  })) ?? [];
430
426
  }
431
427
  ), k = p(
432
428
  () => {
433
429
  var t;
434
- return ((t = i.value.columns) == null ? void 0 : t.filter(({ hidden: l }) => !l).map((l) => ({
435
- ...l,
436
- toggle: (s = {}) => N(l, s)
430
+ return ((t = i.value.columns) == null ? void 0 : t.filter(({ hidden: a }) => !a).map((a) => ({
431
+ ...a,
432
+ toggle: (s = {}) => N(a, s)
437
433
  }))) ?? [];
438
434
  }
439
435
  ), c = p(
440
436
  () => i.value.records.map((t) => ({
441
- record: (({ actions: l, ...s }) => s)(t),
437
+ record: (({ actions: a, ...s }) => s)(t),
442
438
  /** Perform this action when the record is clicked */
443
- default: (l = {}) => {
439
+ default: (a = {}) => {
444
440
  const s = t.actions.find(
445
441
  (w) => w.default
446
442
  );
447
- s && W(s, t, l);
443
+ s && z(s, t, a);
448
444
  },
449
445
  /** The actions available for the record */
450
- actions: t.actions.map((l) => ({
451
- ...l,
446
+ actions: t.actions.map((a) => ({
447
+ ...a,
452
448
  /** Executes this action */
453
- execute: (s = {}) => W(l, t, s)
449
+ execute: (s = {}) => z(a, t, s)
454
450
  })),
455
451
  /** Selects this record */
456
452
  select: () => u.select(y(t)),
@@ -463,13 +459,13 @@ function ae(o, m, d = {}, a = {}) {
463
459
  /** Bind the record to a checkbox */
464
460
  bind: () => u.bind(y(t)),
465
461
  /** Get the value of the record for the column */
466
- value: (l) => {
467
- const s = K(l);
462
+ value: (a) => {
463
+ const s = K(a);
468
464
  return s in t ? t[s].value : null;
469
465
  },
470
466
  /** Get the extra data of the record for the column */
471
- extra: (l) => {
472
- const s = K(l);
467
+ extra: (a) => {
468
+ const s = K(a);
473
469
  return s in t ? t[s].extra : null;
474
470
  }
475
471
  }))
@@ -477,46 +473,46 @@ function ae(o, m, d = {}, a = {}) {
477
473
  () => i.value.actions.bulk.map((t) => ({
478
474
  ...t,
479
475
  /** Executes this bulk action */
480
- execute: (l = {}) => L(t, l)
476
+ execute: (a = {}) => L(t, a)
481
477
  }))
482
478
  ), B = p(
483
479
  () => i.value.actions.page.map((t) => ({
484
480
  ...t,
485
481
  /** Executes this page action */
486
- execute: (l = {}) => M(t, l)
482
+ execute: (a = {}) => M(t, a)
487
483
  }))
488
484
  ), j = p(
489
485
  () => {
490
486
  var t;
491
- return ((t = i.value.recordsPerPage) == null ? void 0 : t.map((l) => ({
492
- ...l,
487
+ return ((t = i.value.recordsPerPage) == null ? void 0 : t.map((a) => ({
488
+ ...a,
493
489
  /** Changes the number of records to display per page */
494
- apply: (s = {}) => T(l, s)
490
+ apply: (s = {}) => T(a, s)
495
491
  }))) ?? [];
496
492
  }
497
493
  ), C = p(
498
494
  () => {
499
495
  var t;
500
- return (t = i.value.recordsPerPage) == null ? void 0 : t.find(({ active: l }) => l);
496
+ return (t = i.value.recordsPerPage) == null ? void 0 : t.find(({ active: a }) => a);
501
497
  }
502
498
  ), h = p(() => ({
503
499
  ...i.value.paginator,
504
500
  next: (t = {}) => {
505
- "nextLink" in h.value && h.value.nextLink && P(h.value.nextLink, t);
501
+ "nextLink" in h.value && h.value.nextLink && V(h.value.nextLink, t);
506
502
  },
507
503
  previous: (t = {}) => {
508
- "prevLink" in h.value && h.value.prevLink && P(h.value.prevLink, t);
504
+ "prevLink" in h.value && h.value.prevLink && V(h.value.prevLink, t);
509
505
  },
510
506
  first: (t = {}) => {
511
- "firstLink" in h.value && h.value.firstLink && P(h.value.firstLink, t);
507
+ "firstLink" in h.value && h.value.firstLink && V(h.value.firstLink, t);
512
508
  },
513
509
  last: (t = {}) => {
514
- "lastLink" in h.value && h.value.lastLink && P(h.value.lastLink, t);
510
+ "lastLink" in h.value && h.value.lastLink && V(h.value.lastLink, t);
515
511
  },
516
512
  ..."links" in i.value.paginator && i.value.paginator.links ? {
517
513
  links: i.value.paginator.links.map((t) => ({
518
514
  ...t,
519
- navigate: (l = {}) => t.url && P(t.url, l)
515
+ navigate: (a = {}) => t.url && V(t.url, a)
520
516
  }))
521
517
  } : {}
522
518
  })), E = p(
@@ -525,33 +521,33 @@ function ae(o, m, d = {}, a = {}) {
525
521
  )
526
522
  );
527
523
  function y(t) {
528
- return t[f.value.record].value;
524
+ return t[f.value.key].value;
529
525
  }
530
526
  function K(t) {
531
527
  return typeof t == "string" ? t : t.name;
532
528
  }
533
- function P(t, l = {}) {
529
+ function V(t, a = {}) {
534
530
  x.visit(t, {
535
531
  preserveScroll: !0,
536
532
  preserveState: !0,
537
- ...a,
538
533
  ...l,
534
+ ...a,
539
535
  method: "get"
540
536
  });
541
537
  }
542
- function W(t, l, s = {}) {
538
+ function z(t, a, s = {}) {
543
539
  var F, e;
544
540
  I(
545
541
  t,
546
542
  f.value.endpoint,
547
543
  {
548
544
  table: i.value.id,
549
- id: y(l)
545
+ id: y(a)
550
546
  },
551
547
  s
552
- ) || (e = (F = d.recordActions) == null ? void 0 : F[t.name]) == null || e.call(F, l);
548
+ ) || (e = (F = d.recordActions) == null ? void 0 : F[t.name]) == null || e.call(F, a);
553
549
  }
554
- function L(t, l = {}) {
550
+ function L(t, a = {}) {
555
551
  I(
556
552
  t,
557
553
  f.value.endpoint,
@@ -561,52 +557,52 @@ function ae(o, m, d = {}, a = {}) {
561
557
  only: Array.from(u.selection.value.only),
562
558
  except: Array.from(u.selection.value.except)
563
559
  },
564
- l
560
+ a
565
561
  );
566
562
  }
567
- function M(t, l = {}) {
563
+ function M(t, a = {}) {
568
564
  I(
569
565
  t,
570
566
  f.value.endpoint,
571
567
  {
572
568
  table: i.value.id
573
569
  },
574
- l
570
+ a
575
571
  );
576
572
  }
577
- function T(t, l = {}) {
573
+ function T(t, a = {}) {
578
574
  x.reload({
579
- ...a,
580
575
  ...l,
576
+ ...a,
581
577
  data: {
582
- [f.value.records]: t.value,
583
- [f.value.pages]: void 0
578
+ [f.value.record]: t.value,
579
+ [f.value.page]: void 0
584
580
  }
585
581
  });
586
582
  }
587
- function U(t, l = {}) {
583
+ function U(t, a = {}) {
588
584
  t.sort && x.reload({
589
- ...a,
590
585
  ...l,
586
+ ...a,
591
587
  data: {
592
- [f.value.sorts]: b.omitValue(t.sort.next)
588
+ [f.value.sort]: b.omitValue(t.sort.next)
593
589
  }
594
590
  });
595
591
  }
596
- function N(t, l = {}) {
592
+ function N(t, a = {}) {
597
593
  const s = b.toggleValue(
598
594
  t.name,
599
595
  S.value.map(({ name: w }) => w)
600
596
  );
601
597
  x.reload({
602
- ...a,
603
598
  ...l,
599
+ ...a,
604
600
  data: {
605
- [f.value.columns]: b.delimitArray(s)
601
+ [f.value.column]: b.delimitArray(s)
606
602
  }
607
603
  });
608
604
  }
609
- function z() {
605
+ function G() {
610
606
  u.select(
611
607
  ...i.value.records.map(
612
608
  (t) => y(t)
@@ -623,7 +619,7 @@ function ae(o, m, d = {}, a = {}) {
623
619
  function D() {
624
620
  return {
625
621
  "onUpdate:modelValue": (t) => {
626
- t ? z() : R();
622
+ t ? G() : R();
627
623
  },
628
624
  modelValue: E.value
629
625
  };
@@ -650,7 +646,7 @@ function ae(o, m, d = {}, a = {}) {
650
646
  /** The pagination metadata */
651
647
  paginator: h,
652
648
  /** Execute an inline action */
653
- executeInlineAction: W,
649
+ executeInlineAction: z,
654
650
  /** Execute a bulk action */
655
651
  executeBulkAction: L,
656
652
  /** Execute a page action */
@@ -664,7 +660,7 @@ function ae(o, m, d = {}, a = {}) {
664
660
  /** Deselect the given records */
665
661
  deselect: (t) => u.deselect(y(t)),
666
662
  /** Select records on the current page */
667
- selectPage: z,
663
+ selectPage: G,
668
664
  /** Deselect records on the current page */
669
665
  deselectPage: R,
670
666
  /** Toggle the selection of the given records */
@@ -690,5 +686,5 @@ function ae(o, m, d = {}, a = {}) {
690
686
  });
691
687
  }
692
688
  export {
693
- ae as useTable
689
+ le as useTable
694
690
  };
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 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"})});
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 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():v()},modelValue:m.value,value:m.value}}return{allSelected:m,selection:r,hasSelected:A,selectAll:p,deselectAll:v,select:l,deselect:i,toggle:u,selected:x,bind:S,bindAll:k}}function D(r,p,v={},l={}){return r.route?(b.router.visit(r.route.url,{...l,method:r.route.method}),!0):r.action&&p?(b.router.post(p,{...v,name:r.name,type:r.type},l),!0):!1}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Y=()=>{};function Q(r,p){function v(...l){return new Promise((i,u)=>{Promise.resolve(r(()=>p.apply(this,l),{fn:p,thisArg:this,args:l})).then(i).catch(u)})}return v}function X(r,p={}){let v,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 v&&u(v),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(()=>{v&&u(v),l=null,k(x())},S)),v=setTimeout(()=>{l&&u(l),l=null,k(m())},A)})}}function B(r,p=200,v={}){return Q(X(p,v),r)}function Z(r,p,v={}){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,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={})=>E(n,n.direction,o),clear:(o={})=>G(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 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 q(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"?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 z(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"?q(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 E(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.sort]:g(f.next)}})}function M(e,n={}){e=[s,g].reduce((o,f)=>f(o),e),b.router.reload({...v,...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 f=C(o.name,S.value.map(({name:V})=>V));b.router.reload({...v,...n,data:{[l.value.config.match]:k(f)}})}function N(e,n={}){T(e,void 0,n)}function G(e={}){b.router.reload({...v,...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({...v,...e,data:{[l.value.config.match]:void 0}})}function t(e={}){var n;b.router.reload({...v,...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"?q(e):e;if(!o){console.warn(`Filter [${e}] does not exist.`);return}const f=o.value,{debounce:V=250,transform:W=J=>J,...$}=n;return{"onUpdate:modelValue":B(J=>{T(o,W(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,...W}=n;return{onClick:B(()=>{var $;E(o,($=A.value)==null?void 0:$.direction,W)},f)}}function L(e={}){const{debounce:n=700,transform:o,...f}=e;return{"onUpdate:modelValue":B(V=>{M(V,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:V,...W}=n;return{"onUpdate:modelValue":B($=>{U($,W)},f),modelValue:w(o),value:o.name}}return{filters:i,sorts:u,searches:x,getFilter:q,getSort:h,getSearch:F,currentFilters:m,currentSort:A,currentSearches:S,isFiltering:y,isSorting:K,isSearching:w,apply:z,applyFilter:T,applySort:E,applySearch:M,applyMatch:U,clearFilter:N,clearSort:G,clearSearch:R,clearMatch:H,reset:t,bindFilter:a,bindSort:d,bindSearch:L,bindMatch:j,stringValue:s,omitValue:g,toggleValue:C,delimitArray:k}}function O(r,p,v={},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&&z(d,t,a)},actions:t.actions.map(a=>({...a,execute:(d={})=>z(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)}))),I=c.computed(()=>i.value.actions.page.map(t=>({...t,execute:(a={})=>E(t,a)}))),C=c.computed(()=>{var t;return((t=i.value.recordsPerPage)==null?void 0:t.map(a=>({...a,apply:(d={})=>M(a,d)})))??[]}),q=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 z(t,a,d={}){var j,e;D(t,m.value.endpoint,{table:i.value.id,id:y(a)},d)||(e=(j=v.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 G(){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?G():R()},modelValue:F.value}}return c.reactive({getRecordKey:y,meta:A,headings:S,columns:k,records:s,bulkActions:g,pageActions:I,rowsPerPage:C,currentPage:q,paginator:h,executeInlineAction:z,executeBulkAction:T,executePageAction:E,applyPage:M,selection:u.selection,select:t=>u.select(y(t)),deselect:t=>u.deselect(y(t)),selectPage:G,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.3",
4
+ "version": "0.5.0",
5
5
  "license": "MIT",
6
6
  "description": "-",
7
7
  "keywords": [
@@ -57,8 +57,8 @@
57
57
  }
58
58
  },
59
59
  "peerDependencies": {
60
- "@honed/action": "^0.4.0",
61
- "@honed/refine": "^0.4.0",
60
+ "@honed/action": "^0.5.0",
61
+ "@honed/refine": "^0.5.0",
62
62
  "@inertiajs/vue3": "^1.2.0||^2.0.0",
63
63
  "@vueuse/core": "^11.0.0||^12.0.0",
64
64
  "axios": "^1.2.0",