@honed/table 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -105,7 +105,7 @@ export declare interface Table<T extends Record<string, any> = Record<string, an
105
105
  record?: string;
106
106
  page?: string;
107
107
  records: Array<TableEntry<T> & {
108
- actions: InlineOperation[];
108
+ operations: InlineOperation[];
109
109
  }>;
110
110
  paginate: PaginateMap[K];
111
111
  columns: BaseColumn<T>[];
@@ -134,13 +134,13 @@ export declare interface TableOptions<RecordType extends Record<string, any> = R
134
134
  /**
135
135
  * Mappings of operations to be applied on a record in JavaScript.
136
136
  */
137
- recordActions?: Record<string, (record: TableEntry<RecordType>) => void>;
137
+ recordOperations?: Record<string, (record: TableEntry<RecordType>) => void>;
138
138
  }
139
139
 
140
140
  export declare interface TableRecord<RecordType extends Record<string, any> = Record<string, any>> {
141
141
  record: RecordType;
142
142
  default: (options?: VisitOptions) => void;
143
- actions: InlineOperation[];
143
+ operations: InlineOperation[];
144
144
  select: () => void;
145
145
  deselect: () => void;
146
146
  toggle: () => void;
@@ -159,11 +159,11 @@ export declare function useTable<T extends Record<string, Table>, K extends Reco
159
159
  bind: () => void | {
160
160
  "onUpdate:modelValue": PromisifyFn<(value: any) => void>;
161
161
  modelValue: FilterValue;
162
- }; /** Bind the record to a checkbox */
162
+ };
163
163
  type: string;
164
164
  value: FilterValue;
165
165
  options: Option_2[];
166
- name: string; /** Get the value of the record for the column */
166
+ name: string;
167
167
  label: string;
168
168
  active: boolean;
169
169
  meta: Record<string, any>;
@@ -231,6 +231,9 @@ export declare function useTable<T extends Record<string, Table>, K extends Reco
231
231
  };
232
232
  bindMatch: (match: string | Search, options?: BindingOptions | undefined) => void | {
233
233
  "onUpdate:modelValue": PromisifyFn<(value: any) => void>;
234
+ /**
235
+ * Create operations with execute methods
236
+ */
234
237
  modelValue: boolean;
235
238
  value: string;
236
239
  };
@@ -245,13 +248,13 @@ export declare function useTable<T extends Record<string, Table>, K extends Reco
245
248
  columns: Column<K>[];
246
249
  records: {
247
250
  record: Omit<TableEntry<K> & {
248
- actions: InlineOperation[];
249
- }, "actions">;
250
- /** The actions available for the record */
251
- actions: (InlineOperation & {
251
+ operations: InlineOperation[];
252
+ }, "operations">;
253
+ /** The operations available for the record */
254
+ operations: (InlineOperation & {
252
255
  execute: (data?: any, options?: Partial<Visit & VisitCallbacks> | undefined) => boolean;
253
256
  })[];
254
- /** Perform this action when the record is clicked */
257
+ /** Perform this operation when the record is clicked */
255
258
  default: (options?: VisitOptions) => void;
256
259
  /** Selects this record */
257
260
  select: () => void;
package/dist/index.es.js CHANGED
@@ -14,7 +14,7 @@ function ee(r, v, c, l = {}) {
14
14
  l
15
15
  ), !0) : !1;
16
16
  }
17
- function Y(r, v, c, l = {}, f = {}) {
17
+ function Y(r, v, c, l = {}, d = {}) {
18
18
  return ee(
19
19
  r,
20
20
  v,
@@ -23,14 +23,14 @@ function Y(r, v, c, l = {}, f = {}) {
23
23
  id: c ?? void 0
24
24
  },
25
25
  {
26
- ...f
26
+ ...d
27
27
  }
28
28
  );
29
29
  }
30
30
  function ne(r, v, c, l = {}) {
31
- return r.map((f) => ({
32
- ...f,
33
- execute: (o = {}, u = {}) => Y(f, v, c, o, { ...l, ...u })
31
+ return r.map((d) => ({
32
+ ...d,
33
+ execute: (o = {}, u = {}) => Y(d, v, c, o, { ...l, ...u })
34
34
  }));
35
35
  }
36
36
  function te() {
@@ -48,11 +48,11 @@ function te() {
48
48
  function l(...s) {
49
49
  s.forEach((g) => r.value.except.delete(g)), s.forEach((g) => r.value.only.add(g));
50
50
  }
51
- function f(...s) {
51
+ function d(...s) {
52
52
  s.forEach((g) => r.value.except.add(g)), s.forEach((g) => r.value.only.delete(g));
53
53
  }
54
54
  function o(s, g) {
55
- if (u(s) || g === !1) return f(s);
55
+ if (u(s) || g === !1) return d(s);
56
56
  if (!u(s) || g === !0) return l(s);
57
57
  }
58
58
  function u(s) {
@@ -62,7 +62,7 @@ function te() {
62
62
  function w(s) {
63
63
  return {
64
64
  "onUpdate:modelValue": (g) => {
65
- g ? l(s) : f(s);
65
+ g ? l(s) : d(s);
66
66
  },
67
67
  modelValue: u(s),
68
68
  value: s
@@ -83,7 +83,7 @@ function te() {
83
83
  selectAll: v,
84
84
  deselectAll: c,
85
85
  select: l,
86
- deselect: f,
86
+ deselect: d,
87
87
  toggle: o,
88
88
  selected: u,
89
89
  bind: w,
@@ -95,22 +95,22 @@ const X = () => {
95
95
  };
96
96
  function le(r, v) {
97
97
  function c(...l) {
98
- return new Promise((f, o) => {
99
- Promise.resolve(r(() => v.apply(this, l), { fn: v, thisArg: this, args: l })).then(f).catch(o);
98
+ return new Promise((d, o) => {
99
+ Promise.resolve(r(() => v.apply(this, l), { fn: v, thisArg: this, args: l })).then(d).catch(o);
100
100
  });
101
101
  }
102
102
  return c;
103
103
  }
104
104
  function ae(r, v = {}) {
105
- let c, l, f = X;
105
+ let c, l, d = X;
106
106
  const o = (b) => {
107
- clearTimeout(b), f(), f = X;
107
+ clearTimeout(b), d(), d = X;
108
108
  };
109
109
  let u;
110
110
  return (b) => {
111
111
  const V = Q(r), w = Q(v.maxWait);
112
112
  return c && o(c), V <= 0 || w !== void 0 && w <= 0 ? (l && (o(l), l = null), Promise.resolve(b())) : new Promise((x, s) => {
113
- f = v.rejectOnCancel ? s : x, u = b, w && !l && (l = setTimeout(() => {
113
+ d = v.rejectOnCancel ? s : x, u = b, w && !l && (l = setTimeout(() => {
114
114
  c && o(c), l = null, x(u());
115
115
  }, w)), c = setTimeout(() => {
116
116
  l && o(l), l = null, x(b());
@@ -125,7 +125,7 @@ function N(r, v = 200, c = {}) {
125
125
  );
126
126
  }
127
127
  function re(r, v, c = {}) {
128
- const l = p(() => r[v]), f = p(() => !!l.value.sort), o = p(() => !!l.value.search), u = p(() => !!l.value.match), b = p(
128
+ const l = p(() => r[v]), d = p(() => !!l.value.sort), o = p(() => !!l.value.search), u = p(() => !!l.value.match), b = p(
129
129
  () => {
130
130
  var e;
131
131
  return (e = l.value.filters) == null ? void 0 : e.map((t) => ({
@@ -166,13 +166,13 @@ function re(r, v, c = {}) {
166
166
  var e;
167
167
  return (e = x(l.value.sorts)) == null ? void 0 : e[0];
168
168
  }
169
- ), R = p(
169
+ ), U = p(
170
170
  () => x(l.value.searches)
171
171
  );
172
- function U(e) {
172
+ function C(e) {
173
173
  return Array.isArray(e) ? e.join(l.value.delimiter) : e;
174
174
  }
175
- function C(e) {
175
+ function O(e) {
176
176
  return typeof e != "string" ? e : e.trim().replace(/\s+/g, "+");
177
177
  }
178
178
  function h(e) {
@@ -180,7 +180,7 @@ function re(r, v, c = {}) {
180
180
  return e;
181
181
  }
182
182
  function W(e) {
183
- return [U, C, h].reduce(
183
+ return [C, O, h].reduce(
184
184
  (t, a) => a(t),
185
185
  e
186
186
  );
@@ -211,7 +211,7 @@ function re(r, v, c = {}) {
211
211
  }
212
212
  function I(e) {
213
213
  var t;
214
- return e ? typeof e == "string" ? (t = R.value) == null ? void 0 : t.some((a) => a.name === e) : e.active : !!l.value.term;
214
+ return e ? typeof e == "string" ? (t = U.value) == null ? void 0 : t.some((a) => a.name === e) : e.active : !!l.value.term;
215
215
  }
216
216
  function D(e, t = {}) {
217
217
  const a = Object.fromEntries(
@@ -237,7 +237,7 @@ function re(r, v, c = {}) {
237
237
  function z(e, t = null, a = {}) {
238
238
  const m = T(e, t);
239
239
  if (!m) return console.warn(`Sort [${e}] does not exist.`);
240
- if (!f.value)
240
+ if (!d.value)
241
241
  return console.warn("Refine cannot perform sorting.");
242
242
  S.reload({
243
243
  ...c,
@@ -247,8 +247,8 @@ function re(r, v, c = {}) {
247
247
  }
248
248
  });
249
249
  }
250
- function O(e, t = {}) {
251
- if (e = [C, h].reduce(
250
+ function R(e, t = {}) {
251
+ if (e = [O, h].reduce(
252
252
  (a, m) => m(a),
253
253
  e
254
254
  ), !o.value)
@@ -268,13 +268,13 @@ function re(r, v, c = {}) {
268
268
  return console.warn("Refine cannot perform matching.");
269
269
  const m = y(
270
270
  a.name,
271
- R.value.map(({ name: k }) => k)
271
+ U.value.map(({ name: k }) => k)
272
272
  );
273
273
  S.reload({
274
274
  ...c,
275
275
  ...t,
276
276
  data: {
277
- [l.value.match]: U(m)
277
+ [l.value.match]: C(m)
278
278
  }
279
279
  });
280
280
  }
@@ -289,7 +289,7 @@ function re(r, v, c = {}) {
289
289
  });
290
290
  }
291
291
  function n(e = {}) {
292
- if (!f.value)
292
+ if (!d.value)
293
293
  return console.warn("Refine cannot perform sorting.");
294
294
  S.reload({
295
295
  ...c,
@@ -300,9 +300,9 @@ function re(r, v, c = {}) {
300
300
  });
301
301
  }
302
302
  function i(e = {}) {
303
- O(null, e);
303
+ R(null, e);
304
304
  }
305
- function d(e = {}) {
305
+ function f(e = {}) {
306
306
  if (!u.value)
307
307
  return console.warn("Refine cannot perform matching.");
308
308
  S.reload({
@@ -362,7 +362,7 @@ function re(r, v, c = {}) {
362
362
  return {
363
363
  "onUpdate:modelValue": N(
364
364
  (k) => {
365
- O(k, m);
365
+ R(k, m);
366
366
  },
367
367
  t
368
368
  ),
@@ -387,8 +387,8 @@ function re(r, v, c = {}) {
387
387
  searches: w,
388
388
  currentFilters: s,
389
389
  currentSort: g,
390
- currentSearches: R,
391
- isSortable: f,
390
+ currentSearches: U,
391
+ isSortable: d,
392
392
  isSearchable: o,
393
393
  isMatchable: u,
394
394
  isFiltering: F,
@@ -400,36 +400,36 @@ function re(r, v, c = {}) {
400
400
  apply: D,
401
401
  applyFilter: M,
402
402
  applySort: z,
403
- applySearch: O,
403
+ applySearch: R,
404
404
  applyMatch: j,
405
405
  clearFilter: K,
406
406
  clearSort: n,
407
407
  clearSearch: i,
408
- clearMatch: d,
408
+ clearMatch: f,
409
409
  reset: A,
410
410
  bindFilter: $,
411
411
  bindSort: H,
412
412
  bindSearch: _,
413
413
  bindMatch: J,
414
- stringValue: C,
414
+ stringValue: O,
415
415
  omitValue: h,
416
416
  toggleValue: y,
417
- delimitArray: U
417
+ delimitArray: C
418
418
  };
419
419
  }
420
420
  function ie(r, v, c = {}) {
421
421
  if (!(r != null && r[v]))
422
422
  throw new Error("The table must be provided with valid props and key.");
423
- const { recordActions: l = {}, ...f } = {
423
+ const { recordOperations: l = {}, ...d } = {
424
424
  only: [...c.only ?? [], v.toString()],
425
425
  ...c
426
- }, o = p(() => r[v]), u = te(), b = re(r, v, f), V = p(() => !!o.value.page && !!o.value.record), w = p(() => !!o.value.column), x = p(
426
+ }, o = p(() => r[v]), u = te(), b = re(r, v, d), V = p(() => !!o.value.page && !!o.value.record), w = p(() => !!o.value.column), x = p(
427
427
  () => o.value.columns.filter(({ active: n, hidden: i }) => n && !i).map((n) => {
428
428
  var i;
429
429
  return {
430
430
  ...n,
431
431
  isSorting: !!((i = n.sort) != null && i.active),
432
- toggleSort: (d = {}) => b.applySort(n.sort, null, d)
432
+ toggleSort: (f = {}) => b.applySort(n.sort, null, f)
433
433
  };
434
434
  })
435
435
  ), s = p(
@@ -439,13 +439,15 @@ function ie(r, v, c = {}) {
439
439
  }))
440
440
  ), g = p(
441
441
  () => o.value.records.map((n) => ({
442
- record: (({ actions: i, ...d }) => d)(n),
443
- /** The actions available for the record */
444
- actions: E(n.actions),
445
- /** Perform this action when the record is clicked */
442
+ record: (({ operations: i, ...f }) => f)(n),
443
+ /** The operations available for the record */
444
+ operations: E(n.operations),
445
+ /** Perform this operation when the record is clicked */
446
446
  default: (i = {}) => {
447
- const d = n.actions.find(({ default: A }) => A);
448
- d && B(d, n, i);
447
+ const f = n.operations.find(
448
+ ({ default: A }) => A
449
+ );
450
+ f && B(f, n, i);
449
451
  },
450
452
  /** Selects this record */
451
453
  select: () => u.select(y(n)),
@@ -459,16 +461,16 @@ function ie(r, v, c = {}) {
459
461
  bind: () => u.bind(y(n)),
460
462
  /** Get the value of the record for the column */
461
463
  value: (i) => {
462
- const d = L(i);
463
- return d in n ? n[d].v : null;
464
+ const f = L(i);
465
+ return f in n ? n[f].v : null;
464
466
  },
465
467
  /** Get the extra data of the record for the column */
466
468
  extra: (i) => {
467
- const d = L(i);
468
- return d in n ? n[d].e : null;
469
+ const f = L(i);
470
+ return console.log(f, n), f in n ? n[f].e : null;
469
471
  }
470
472
  }))
471
- ), R = p(() => E(o.value.operations.bulk)), U = p(() => E(o.value.operations.page)), C = p(
473
+ ), U = p(() => E(o.value.operations.bulk)), C = p(() => E(o.value.operations.page)), O = p(
472
474
  () => o.value.pages.find(({ active: n }) => n)
473
475
  ), h = p(() => ({
474
476
  ...o.value.paginate,
@@ -501,15 +503,15 @@ function ie(r, v, c = {}) {
501
503
  function L(n) {
502
504
  return typeof n == "string" ? n : n.name;
503
505
  }
504
- function T(n, i = {}, d = {}) {
506
+ function T(n, i = {}, f = {}) {
505
507
  return Y(
506
508
  n,
507
509
  o.value.endpoint,
508
510
  o.value.id,
509
511
  i,
510
512
  {
511
- ...f,
512
- ...d
513
+ ...d,
514
+ ...f
513
515
  }
514
516
  );
515
517
  }
@@ -518,26 +520,26 @@ function ie(r, v, c = {}) {
518
520
  n,
519
521
  o.value.endpoint,
520
522
  o.value.id,
521
- f
523
+ d
522
524
  );
523
525
  }
524
526
  function F(n, i = {}) {
525
527
  S.visit(n, {
526
528
  preserveScroll: !0,
527
529
  preserveState: !0,
528
- ...f,
530
+ ...d,
529
531
  ...i,
530
532
  method: "get"
531
533
  });
532
534
  }
533
- function B(n, i, d = {}) {
535
+ function B(n, i, f = {}) {
534
536
  var $;
535
537
  T(
536
538
  n,
537
539
  {
538
540
  record: y(i)
539
541
  },
540
- d
542
+ f
541
543
  ) || ($ = l == null ? void 0 : l[n.name]) == null || $.call(l, i);
542
544
  }
543
545
  function I(n, i = {}) {
@@ -550,21 +552,21 @@ function ie(r, v, c = {}) {
550
552
  },
551
553
  {
552
554
  ...i,
553
- onSuccess: (d) => {
555
+ onSuccess: (f) => {
554
556
  var A;
555
- (A = i.onSuccess) == null || A.call(i, d), n.keepSelected || u.deselectAll();
557
+ (A = i.onSuccess) == null || A.call(i, f), n.keepSelected || u.deselectAll();
556
558
  }
557
559
  }
558
560
  );
559
561
  }
560
- function D(n, i = {}, d = {}) {
561
- return T(n, i, d);
562
+ function D(n, i = {}, f = {}) {
563
+ return T(n, i, f);
562
564
  }
563
565
  function M(n, i = {}) {
564
566
  if (!V.value)
565
567
  return console.warn("The table does not support pagination changes.");
566
568
  S.reload({
567
- ...f,
569
+ ...d,
568
570
  ...i,
569
571
  data: {
570
572
  [o.value.record]: n.value,
@@ -575,21 +577,21 @@ function ie(r, v, c = {}) {
575
577
  function z(n, i = {}) {
576
578
  if (!w.value)
577
579
  return console.warn("The table does not support column toggling.");
578
- const d = L(n);
579
- if (!d) return console.log(`Column [${n}] does not exist.`);
580
+ const f = L(n);
581
+ if (!f) return console.log(`Column [${n}] does not exist.`);
580
582
  const A = b.toggleValue(
581
- d,
583
+ f,
582
584
  x.value.map(({ name: $ }) => $)
583
585
  );
584
586
  S.reload({
585
- ...f,
587
+ ...d,
586
588
  ...i,
587
589
  data: {
588
590
  [o.value.column]: b.delimitArray(A)
589
591
  }
590
592
  });
591
593
  }
592
- function O() {
594
+ function R() {
593
595
  u.select(
594
596
  ...o.value.records.map(
595
597
  (n) => y(n)
@@ -606,7 +608,7 @@ function ie(r, v, c = {}) {
606
608
  function K() {
607
609
  return {
608
610
  "onUpdate:modelValue": (n) => {
609
- n ? O() : j();
611
+ n ? R() : j();
610
612
  },
611
613
  modelValue: W.value
612
614
  };
@@ -624,23 +626,23 @@ function ie(r, v, c = {}) {
624
626
  columns: s,
625
627
  /** The records of the table */
626
628
  records: g,
627
- /** Whether the table has record actions */
629
+ /** Whether the table has record operations */
628
630
  inline: o.value.operations.inline,
629
- /** The available bulk actions */
630
- bulk: R,
631
- /** The available page actions */
632
- page: U,
631
+ /** The available bulk operations */
632
+ bulk: U,
633
+ /** The available page operations */
634
+ page: C,
633
635
  /** The available number of records to display per page */
634
636
  pages: o.value.pages,
635
637
  /** The current record per page item */
636
- currentPage: C,
638
+ currentPage: O,
637
639
  /** The pagination metadata */
638
640
  paginator: h,
639
- /** Execute an inline action */
641
+ /** Execute an inline operation */
640
642
  executeInline: B,
641
- /** Execute a bulk action */
643
+ /** Execute a bulk operation */
642
644
  executeBulk: I,
643
- /** Execute a page action */
645
+ /** Execute a page operation */
644
646
  executePage: D,
645
647
  /** Apply a new page by changing the number of records to display */
646
648
  applyPage: M,
@@ -651,7 +653,7 @@ function ie(r, v, c = {}) {
651
653
  /** Deselect the given records */
652
654
  deselect: (n) => u.deselect(y(n)),
653
655
  /** Select records on the current page */
654
- selectPage: O,
656
+ selectPage: R,
655
657
  /** Deselect records on the current page */
656
658
  deselectPage: j,
657
659
  /** Toggle the selection of the given records */
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(V,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):(V=typeof globalThis<"u"?globalThis:V||self,c(V["@honed/table"]={},V.Vue,V.Inertia))})(this,function(V,c,S){"use strict";function Y(r,f,s,l={}){return r.route?(S.router.visit(r.route.url,{...l,method:r.route.method}),!0):r.action&&f?(S.router.post(f,{...s,name:r.name,type:r.type},l),!0):!1}function H(r,f,s,l={},v={}){return Y(r,f,{...l,id:s??void 0},{...v})}function _(r,f,s,l={}){return r.map(v=>({...v,execute:(o={},u={})=>H(v,f,s,o,{...l,...u})}))}function Z(){const r=c.ref({all:!1,only:new Set,except:new Set});function f(){r.value.all=!0,r.value.only.clear(),r.value.except.clear()}function s(){r.value.all=!1,r.value.only.clear(),r.value.except.clear()}function l(...d){d.forEach(g=>r.value.except.delete(g)),d.forEach(g=>r.value.only.add(g))}function v(...d){d.forEach(g=>r.value.except.add(g)),d.forEach(g=>r.value.only.delete(g))}function o(d,g){if(u(d)||g===!1)return v(d);if(!u(d)||g===!0)return l(d)}function u(d){return r.value.all?!r.value.except.has(d):r.value.only.has(d)}const b=c.computed(()=>r.value.all&&r.value.except.size===0),P=c.computed(()=>r.value.only.size>0||b.value);function w(d){return{"onUpdate:modelValue":g=>{g?l(d):v(d)},modelValue:u(d),value:d}}function x(){return{"onUpdate:modelValue":d=>{d?f():s()},modelValue:b.value}}return{allSelected:b,selection:r,hasSelected:P,selectAll:f,deselectAll:s,select:l,deselect:v,toggle:o,selected:u,bind:w,bindAll:x}}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const J=()=>{};function ee(r,f){function s(...l){return new Promise((v,o)=>{Promise.resolve(r(()=>f.apply(this,l),{fn:f,thisArg:this,args:l})).then(v).catch(o)})}return s}function te(r,f={}){let s,l,v=J;const o=b=>{clearTimeout(b),v(),v=J};let u;return b=>{const P=c.toValue(r),w=c.toValue(f.maxWait);return s&&o(s),P<=0||w!==void 0&&w<=0?(l&&(o(l),l=null),Promise.resolve(b())):new Promise((x,d)=>{v=f.rejectOnCancel?d:x,u=b,w&&!l&&(l=setTimeout(()=>{s&&o(s),l=null,x(u())},w)),s=setTimeout(()=>{l&&o(l),l=null,x(b())},P)})}}function q(r,f=200,s={}){return ee(te(f,s),r)}function ne(r,f,s={}){const l=c.computed(()=>r[f]),v=c.computed(()=>!!l.value.sort),o=c.computed(()=>!!l.value.search),u=c.computed(()=>!!l.value.match),b=c.computed(()=>{var e;return(e=l.value.filters)==null?void 0:e.map(n=>({...n,apply:(a,p={})=>$(n,a,p),clear:(a={})=>N(n,a),bind:()=>O(n.name)}))}),P=c.computed(()=>{var e;return(e=l.value.sorts)==null?void 0:e.map(n=>({...n,apply:(a={})=>G(n,n.direction,a),clear:(a={})=>t(a),bind:()=>Q(n)}))}),w=c.computed(()=>{var e;return(e=l.value.searches)==null?void 0:e.map(n=>({...n,apply:(a={})=>M(n,a),clear:(a={})=>M(n,a),bind:()=>X(n)}))});function x(e){return e.filter(({active:n})=>n)}const d=c.computed(()=>x(l.value.filters)),g=c.computed(()=>{var e;return(e=x(l.value.sorts))==null?void 0:e[0]}),U=c.computed(()=>x(l.value.searches));function C(e){return Array.isArray(e)?e.join(l.value.delimiter):e}function W(e){return typeof e!="string"?e:e.trim().replace(/\s+/g,"+")}function h(e){if(!["",null,void 0,[]].includes(e))return e}function z(e){return[C,W,h].reduce((n,a)=>a(n),e)}function y(e,n){return n=Array.isArray(n)?n:[n],n.includes(e)?n.filter(a=>a!==e):[...n,e]}function L(e){var n;return typeof e!="string"?e:(n=l.value.filters)==null?void 0:n.find(({name:a})=>a===e)}function j(e,n=null){var a;return typeof e!="string"?e:(a=l.value.sorts)==null?void 0:a.find(({name:p,direction:k})=>p===e&&k===n)}function E(e){var n;return typeof e!="string"?e:(n=l.value.searches)==null?void 0:n.find(({name:a})=>a===e)}function F(e){return e?typeof e=="string"?d.value.some(n=>n.name===e):e.active:!!d.value.length}function B(e){var n;return e?typeof e=="string"?((n=g.value)==null?void 0:n.name)===e:e.active:!!g.value}function K(e){var n;return e?typeof e=="string"?(n=U.value)==null?void 0:n.some(a=>a.name===e):e.active:!!l.value.term}function D(e,n={}){const a=Object.fromEntries(Object.entries(e).map(([p,k])=>[p,z(k)]));S.router.reload({...s,...n,data:a})}function $(e,n,a={}){const p=L(e);if(!p)return console.warn(`Filter [${e}] does not exist.`);S.router.reload({...s,...a,data:{[p.name]:z(n)}})}function G(e,n=null,a={}){const p=j(e,n);if(!p)return console.warn(`Sort [${e}] does not exist.`);if(!v.value)return console.warn("Refine cannot perform sorting.");S.router.reload({...s,...a,data:{[l.value.sort]:h(p.next)}})}function R(e,n={}){if(e=[W,h].reduce((a,p)=>p(a),e),!o.value)return console.warn("Refine cannot perform searching.");S.router.reload({...s,...n,data:{[l.value.search]:e}})}function M(e,n={}){const a=E(e);if(!a)return console.warn(`Match [${e}] does not exist.`);if(!u.value||!o.value)return console.warn("Refine cannot perform matching.");const p=y(a.name,U.value.map(({name:k})=>k));S.router.reload({...s,...n,data:{[l.value.match]:C(p)}})}function N(e,n={}){if(e)return $(e,null,n);S.router.reload({...s,...n,data:Object.fromEntries(d.value.map(({name:a})=>[a,null]))})}function t(e={}){if(!v.value)return console.warn("Refine cannot perform sorting.");S.router.reload({...s,...e,data:{[l.value.sort]:null}})}function i(e={}){R(null,e)}function m(e={}){if(!u.value)return console.warn("Refine cannot perform matching.");S.router.reload({...s,...e,data:{[l.value.match]:null}})}function A(e={}){var n;S.router.reload({...s,...e,data:{[l.value.search??""]:void 0,[l.value.sort??""]:void 0,[l.value.match??""]:void 0,...Object.fromEntries(((n=l.value.filters)==null?void 0:n.map(a=>[a.name,void 0]))??[])}})}function O(e,n={}){const a=L(e);if(!a)return console.warn(`Filter [${e}] does not exist.`);const{debounce:p=250,transform:k=T=>T,...I}=n;return{"onUpdate:modelValue":q(T=>{$(a,k(T),I)},p),modelValue:a.value}}function Q(e,n={}){const a=j(e);if(!a)return console.warn(`Sort [${e}] does not exist.`);const{debounce:p=0,transform:k,...I}=n;return{onClick:q(()=>{var T;G(a,(T=g.value)==null?void 0:T.direction,I)},p)}}function re(e={}){const{debounce:n=700,transform:a,...p}=e;return{"onUpdate:modelValue":q(k=>{R(k,p)},n),modelValue:l.value.term??""}}function X(e,n={}){const a=E(e);if(!a)return console.warn(`Match [${e}] does not exist.`);const{debounce:p=0,transform:k,...I}=n;return{"onUpdate:modelValue":q(T=>{M(T,I)},p),modelValue:K(a),value:a.name}}return{filters:b,sorts:P,searches:w,currentFilters:d,currentSort:g,currentSearches:U,isSortable:v,isSearchable:o,isMatchable:u,isFiltering:F,isSorting:B,isSearching:K,getFilter:L,getSort:j,getSearch:E,apply:D,applyFilter:$,applySort:G,applySearch:R,applyMatch:M,clearFilter:N,clearSort:t,clearSearch:i,clearMatch:m,reset:A,bindFilter:O,bindSort:Q,bindSearch:re,bindMatch:X,stringValue:W,omitValue:h,toggleValue:y,delimitArray:C}}function le(r,f,s={}){if(!(r!=null&&r[f]))throw new Error("The table must be provided with valid props and key.");const{recordActions:l={},...v}={only:[...s.only??[],f.toString()],...s},o=c.computed(()=>r[f]),u=Z(),b=ne(r,f,v),P=c.computed(()=>!!o.value.page&&!!o.value.record),w=c.computed(()=>!!o.value.column),x=c.computed(()=>o.value.columns.filter(({active:t,hidden:i})=>t&&!i).map(t=>{var i;return{...t,isSorting:!!((i=t.sort)!=null&&i.active),toggleSort:(m={})=>b.applySort(t.sort,null,m)}})),d=c.computed(()=>o.value.columns.filter(({hidden:t})=>!t).map(t=>({...t,toggle:(i={})=>G(t.name,i)}))),g=c.computed(()=>o.value.records.map(t=>({record:(({actions:i,...m})=>m)(t),actions:E(t.actions),default:(i={})=>{const m=t.actions.find(({default:A})=>A);m&&B(m,t,i)},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:i=>{const m=L(i);return m in t?t[m].v:null},extra:i=>{const m=L(i);return m in t?t[m].e:null}}))),U=c.computed(()=>E(o.value.operations.bulk)),C=c.computed(()=>E(o.value.operations.page)),W=c.computed(()=>o.value.pages.find(({active:t})=>t)),h=c.computed(()=>({...o.value.paginate,next:(t={})=>{"nextLink"in h.value&&h.value.nextLink&&F(h.value.nextLink,t)},previous:(t={})=>{"prevLink"in h.value&&h.value.prevLink&&F(h.value.prevLink,t)},first:(t={})=>{"firstLink"in h.value&&h.value.firstLink&&F(h.value.firstLink,t)},last:(t={})=>{"lastLink"in h.value&&h.value.lastLink&&F(h.value.lastLink,t)},..."links"in o.value.paginate&&o.value.paginate.links?{links:o.value.paginate.links.map(t=>({...t,navigate:(i={})=>t.url&&F(t.url,i)}))}:{}})),z=c.computed(()=>o.value.records.length>0&&o.value.records.every(t=>u.selected(y(t))));function y(t){return t[o.value.key].v}function L(t){return typeof t=="string"?t:t.name}function j(t,i={},m={}){return H(t,o.value.endpoint,o.value.id,i,{...v,...m})}function E(t){return _(t,o.value.endpoint,o.value.id,v)}function F(t,i={}){S.router.visit(t,{preserveScroll:!0,preserveState:!0,...v,...i,method:"get"})}function B(t,i,m={}){var O;j(t,{record:y(i)},m)||(O=l==null?void 0:l[t.name])==null||O.call(l,i)}function K(t,i={}){j(t,{all:u.selection.value.all,only:Array.from(u.selection.value.only),except:Array.from(u.selection.value.except)},{...i,onSuccess:m=>{var A;(A=i.onSuccess)==null||A.call(i,m),t.keepSelected||u.deselectAll()}})}function D(t,i={},m={}){return j(t,i,m)}function $(t,i={}){if(!P.value)return console.warn("The table does not support pagination changes.");S.router.reload({...v,...i,data:{[o.value.record]:t.value,[o.value.page]:void 0}})}function G(t,i={}){if(!w.value)return console.warn("The table does not support column toggling.");const m=L(t);if(!m)return console.log(`Column [${t}] does not exist.`);const A=b.toggleValue(m,x.value.map(({name:O})=>O));S.router.reload({...v,...i,data:{[o.value.column]:b.delimitArray(A)}})}function R(){u.select(...o.value.records.map(t=>y(t)))}function M(){u.deselect(...o.value.records.map(t=>y(t)))}function N(){return{"onUpdate:modelValue":t=>{t?R():M()},modelValue:z.value}}return c.reactive({table:o,getRecordKey:y,meta:o.value.meta,headings:x,columns:d,records:g,inline:o.value.operations.inline,bulk:U,page:C,pages:o.value.pages,currentPage:W,paginator:h,executeInline:B,executeBulk:K,executePage:D,applyPage:$,selection:u.selection,select:t=>u.select(y(t)),deselect:t=>u.deselect(y(t)),selectPage:R,deselectPage:M,toggle:t=>u.toggle(y(t)),selected:t=>u.selected(y(t)),selectAll:u.selectAll,deselectAll:u.deselectAll,isPageSelected:z,hasSelected:u.hasSelected,bindCheckbox:t=>u.bind(y(t)),bindPage:N,bindAll:u.bindAll,...b})}function ae(r,f){return r?typeof r=="object"?r.type===f:r===f:!1}V.is=ae,V.useTable=le,Object.defineProperty(V,Symbol.toStringTag,{value:"Module"})});
1
+ (function(A,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):(A=typeof globalThis<"u"?globalThis:A||self,c(A["@honed/table"]={},A.Vue,A.Inertia))})(this,function(A,c,S){"use strict";function Y(r,f,s,l={}){return r.route?(S.router.visit(r.route.url,{...l,method:r.route.method}),!0):r.action&&f?(S.router.post(f,{...s,name:r.name,type:r.type},l),!0):!1}function H(r,f,s,l={},p={}){return Y(r,f,{...l,id:s??void 0},{...p})}function _(r,f,s,l={}){return r.map(p=>({...p,execute:(o={},u={})=>H(p,f,s,o,{...l,...u})}))}function Z(){const r=c.ref({all:!1,only:new Set,except:new Set});function f(){r.value.all=!0,r.value.only.clear(),r.value.except.clear()}function s(){r.value.all=!1,r.value.only.clear(),r.value.except.clear()}function l(...d){d.forEach(g=>r.value.except.delete(g)),d.forEach(g=>r.value.only.add(g))}function p(...d){d.forEach(g=>r.value.except.add(g)),d.forEach(g=>r.value.only.delete(g))}function o(d,g){if(u(d)||g===!1)return p(d);if(!u(d)||g===!0)return l(d)}function u(d){return r.value.all?!r.value.except.has(d):r.value.only.has(d)}const b=c.computed(()=>r.value.all&&r.value.except.size===0),P=c.computed(()=>r.value.only.size>0||b.value);function w(d){return{"onUpdate:modelValue":g=>{g?l(d):p(d)},modelValue:u(d),value:d}}function x(){return{"onUpdate:modelValue":d=>{d?f():s()},modelValue:b.value}}return{allSelected:b,selection:r,hasSelected:P,selectAll:f,deselectAll:s,select:l,deselect:p,toggle:o,selected:u,bind:w,bindAll:x}}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const J=()=>{};function ee(r,f){function s(...l){return new Promise((p,o)=>{Promise.resolve(r(()=>f.apply(this,l),{fn:f,thisArg:this,args:l})).then(p).catch(o)})}return s}function te(r,f={}){let s,l,p=J;const o=b=>{clearTimeout(b),p(),p=J};let u;return b=>{const P=c.toValue(r),w=c.toValue(f.maxWait);return s&&o(s),P<=0||w!==void 0&&w<=0?(l&&(o(l),l=null),Promise.resolve(b())):new Promise((x,d)=>{p=f.rejectOnCancel?d:x,u=b,w&&!l&&(l=setTimeout(()=>{s&&o(s),l=null,x(u())},w)),s=setTimeout(()=>{l&&o(l),l=null,x(b())},P)})}}function q(r,f=200,s={}){return ee(te(f,s),r)}function ne(r,f,s={}){const l=c.computed(()=>r[f]),p=c.computed(()=>!!l.value.sort),o=c.computed(()=>!!l.value.search),u=c.computed(()=>!!l.value.match),b=c.computed(()=>{var e;return(e=l.value.filters)==null?void 0:e.map(n=>({...n,apply:(a,m={})=>R(n,a,m),clear:(a={})=>N(n,a),bind:()=>$(n.name)}))}),P=c.computed(()=>{var e;return(e=l.value.sorts)==null?void 0:e.map(n=>({...n,apply:(a={})=>G(n,n.direction,a),clear:(a={})=>t(a),bind:()=>Q(n)}))}),w=c.computed(()=>{var e;return(e=l.value.searches)==null?void 0:e.map(n=>({...n,apply:(a={})=>M(n,a),clear:(a={})=>M(n,a),bind:()=>X(n)}))});function x(e){return e.filter(({active:n})=>n)}const d=c.computed(()=>x(l.value.filters)),g=c.computed(()=>{var e;return(e=x(l.value.sorts))==null?void 0:e[0]}),C=c.computed(()=>x(l.value.searches));function O(e){return Array.isArray(e)?e.join(l.value.delimiter):e}function W(e){return typeof e!="string"?e:e.trim().replace(/\s+/g,"+")}function h(e){if(!["",null,void 0,[]].includes(e))return e}function z(e){return[O,W,h].reduce((n,a)=>a(n),e)}function y(e,n){return n=Array.isArray(n)?n:[n],n.includes(e)?n.filter(a=>a!==e):[...n,e]}function L(e){var n;return typeof e!="string"?e:(n=l.value.filters)==null?void 0:n.find(({name:a})=>a===e)}function j(e,n=null){var a;return typeof e!="string"?e:(a=l.value.sorts)==null?void 0:a.find(({name:m,direction:k})=>m===e&&k===n)}function E(e){var n;return typeof e!="string"?e:(n=l.value.searches)==null?void 0:n.find(({name:a})=>a===e)}function F(e){return e?typeof e=="string"?d.value.some(n=>n.name===e):e.active:!!d.value.length}function B(e){var n;return e?typeof e=="string"?((n=g.value)==null?void 0:n.name)===e:e.active:!!g.value}function K(e){var n;return e?typeof e=="string"?(n=C.value)==null?void 0:n.some(a=>a.name===e):e.active:!!l.value.term}function D(e,n={}){const a=Object.fromEntries(Object.entries(e).map(([m,k])=>[m,z(k)]));S.router.reload({...s,...n,data:a})}function R(e,n,a={}){const m=L(e);if(!m)return console.warn(`Filter [${e}] does not exist.`);S.router.reload({...s,...a,data:{[m.name]:z(n)}})}function G(e,n=null,a={}){const m=j(e,n);if(!m)return console.warn(`Sort [${e}] does not exist.`);if(!p.value)return console.warn("Refine cannot perform sorting.");S.router.reload({...s,...a,data:{[l.value.sort]:h(m.next)}})}function U(e,n={}){if(e=[W,h].reduce((a,m)=>m(a),e),!o.value)return console.warn("Refine cannot perform searching.");S.router.reload({...s,...n,data:{[l.value.search]:e}})}function M(e,n={}){const a=E(e);if(!a)return console.warn(`Match [${e}] does not exist.`);if(!u.value||!o.value)return console.warn("Refine cannot perform matching.");const m=y(a.name,C.value.map(({name:k})=>k));S.router.reload({...s,...n,data:{[l.value.match]:O(m)}})}function N(e,n={}){if(e)return R(e,null,n);S.router.reload({...s,...n,data:Object.fromEntries(d.value.map(({name:a})=>[a,null]))})}function t(e={}){if(!p.value)return console.warn("Refine cannot perform sorting.");S.router.reload({...s,...e,data:{[l.value.sort]:null}})}function i(e={}){U(null,e)}function v(e={}){if(!u.value)return console.warn("Refine cannot perform matching.");S.router.reload({...s,...e,data:{[l.value.match]:null}})}function V(e={}){var n;S.router.reload({...s,...e,data:{[l.value.search??""]:void 0,[l.value.sort??""]:void 0,[l.value.match??""]:void 0,...Object.fromEntries(((n=l.value.filters)==null?void 0:n.map(a=>[a.name,void 0]))??[])}})}function $(e,n={}){const a=L(e);if(!a)return console.warn(`Filter [${e}] does not exist.`);const{debounce:m=250,transform:k=T=>T,...I}=n;return{"onUpdate:modelValue":q(T=>{R(a,k(T),I)},m),modelValue:a.value}}function Q(e,n={}){const a=j(e);if(!a)return console.warn(`Sort [${e}] does not exist.`);const{debounce:m=0,transform:k,...I}=n;return{onClick:q(()=>{var T;G(a,(T=g.value)==null?void 0:T.direction,I)},m)}}function re(e={}){const{debounce:n=700,transform:a,...m}=e;return{"onUpdate:modelValue":q(k=>{U(k,m)},n),modelValue:l.value.term??""}}function X(e,n={}){const a=E(e);if(!a)return console.warn(`Match [${e}] does not exist.`);const{debounce:m=0,transform:k,...I}=n;return{"onUpdate:modelValue":q(T=>{M(T,I)},m),modelValue:K(a),value:a.name}}return{filters:b,sorts:P,searches:w,currentFilters:d,currentSort:g,currentSearches:C,isSortable:p,isSearchable:o,isMatchable:u,isFiltering:F,isSorting:B,isSearching:K,getFilter:L,getSort:j,getSearch:E,apply:D,applyFilter:R,applySort:G,applySearch:U,applyMatch:M,clearFilter:N,clearSort:t,clearSearch:i,clearMatch:v,reset:V,bindFilter:$,bindSort:Q,bindSearch:re,bindMatch:X,stringValue:W,omitValue:h,toggleValue:y,delimitArray:O}}function le(r,f,s={}){if(!(r!=null&&r[f]))throw new Error("The table must be provided with valid props and key.");const{recordOperations:l={},...p}={only:[...s.only??[],f.toString()],...s},o=c.computed(()=>r[f]),u=Z(),b=ne(r,f,p),P=c.computed(()=>!!o.value.page&&!!o.value.record),w=c.computed(()=>!!o.value.column),x=c.computed(()=>o.value.columns.filter(({active:t,hidden:i})=>t&&!i).map(t=>{var i;return{...t,isSorting:!!((i=t.sort)!=null&&i.active),toggleSort:(v={})=>b.applySort(t.sort,null,v)}})),d=c.computed(()=>o.value.columns.filter(({hidden:t})=>!t).map(t=>({...t,toggle:(i={})=>G(t.name,i)}))),g=c.computed(()=>o.value.records.map(t=>({record:(({operations:i,...v})=>v)(t),operations:E(t.operations),default:(i={})=>{const v=t.operations.find(({default:V})=>V);v&&B(v,t,i)},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:i=>{const v=L(i);return v in t?t[v].v:null},extra:i=>{const v=L(i);return console.log(v,t),v in t?t[v].e:null}}))),C=c.computed(()=>E(o.value.operations.bulk)),O=c.computed(()=>E(o.value.operations.page)),W=c.computed(()=>o.value.pages.find(({active:t})=>t)),h=c.computed(()=>({...o.value.paginate,next:(t={})=>{"nextLink"in h.value&&h.value.nextLink&&F(h.value.nextLink,t)},previous:(t={})=>{"prevLink"in h.value&&h.value.prevLink&&F(h.value.prevLink,t)},first:(t={})=>{"firstLink"in h.value&&h.value.firstLink&&F(h.value.firstLink,t)},last:(t={})=>{"lastLink"in h.value&&h.value.lastLink&&F(h.value.lastLink,t)},..."links"in o.value.paginate&&o.value.paginate.links?{links:o.value.paginate.links.map(t=>({...t,navigate:(i={})=>t.url&&F(t.url,i)}))}:{}})),z=c.computed(()=>o.value.records.length>0&&o.value.records.every(t=>u.selected(y(t))));function y(t){return t[o.value.key].v}function L(t){return typeof t=="string"?t:t.name}function j(t,i={},v={}){return H(t,o.value.endpoint,o.value.id,i,{...p,...v})}function E(t){return _(t,o.value.endpoint,o.value.id,p)}function F(t,i={}){S.router.visit(t,{preserveScroll:!0,preserveState:!0,...p,...i,method:"get"})}function B(t,i,v={}){var $;j(t,{record:y(i)},v)||($=l==null?void 0:l[t.name])==null||$.call(l,i)}function K(t,i={}){j(t,{all:u.selection.value.all,only:Array.from(u.selection.value.only),except:Array.from(u.selection.value.except)},{...i,onSuccess:v=>{var V;(V=i.onSuccess)==null||V.call(i,v),t.keepSelected||u.deselectAll()}})}function D(t,i={},v={}){return j(t,i,v)}function R(t,i={}){if(!P.value)return console.warn("The table does not support pagination changes.");S.router.reload({...p,...i,data:{[o.value.record]:t.value,[o.value.page]:void 0}})}function G(t,i={}){if(!w.value)return console.warn("The table does not support column toggling.");const v=L(t);if(!v)return console.log(`Column [${t}] does not exist.`);const V=b.toggleValue(v,x.value.map(({name:$})=>$));S.router.reload({...p,...i,data:{[o.value.column]:b.delimitArray(V)}})}function U(){u.select(...o.value.records.map(t=>y(t)))}function M(){u.deselect(...o.value.records.map(t=>y(t)))}function N(){return{"onUpdate:modelValue":t=>{t?U():M()},modelValue:z.value}}return c.reactive({table:o,getRecordKey:y,meta:o.value.meta,headings:x,columns:d,records:g,inline:o.value.operations.inline,bulk:C,page:O,pages:o.value.pages,currentPage:W,paginator:h,executeInline:B,executeBulk:K,executePage:D,applyPage:R,selection:u.selection,select:t=>u.select(y(t)),deselect:t=>u.deselect(y(t)),selectPage:U,deselectPage:M,toggle:t=>u.toggle(y(t)),selected:t=>u.selected(y(t)),selectAll:u.selectAll,deselectAll:u.deselectAll,isPageSelected:z,hasSelected:u.hasSelected,bindCheckbox:t=>u.bind(y(t)),bindPage:N,bindAll:u.bindAll,...b})}function ae(r,f){return r?typeof r=="object"?r.type===f:r===f:!1}A.is=ae,A.useTable=le,Object.defineProperty(A,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.8.0",
4
+ "version": "0.8.1",
5
5
  "license": "MIT",
6
6
  "description": "-",
7
7
  "keywords": [