@honed/table 0.4.1 → 0.4.2

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.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { ref as _, computed as p, toValue as J, reactive as Q } from "vue";
1
+ import { ref as _, computed as g, toValue as J, reactive as Q } from "vue";
2
2
  import { router as x } from "@inertiajs/vue3";
3
3
  function X() {
4
4
  const o = _({
@@ -12,35 +12,35 @@ function X() {
12
12
  function d() {
13
13
  o.value.all = !1, o.value.only.clear(), o.value.except.clear();
14
14
  }
15
- function l(...c) {
16
- c.forEach((g) => o.value.except.delete(g)), c.forEach((g) => o.value.only.add(g));
15
+ function l(...s) {
16
+ s.forEach((p) => o.value.except.delete(p)), s.forEach((p) => o.value.only.add(p));
17
17
  }
18
- function i(...c) {
19
- c.forEach((g) => o.value.except.add(g)), c.forEach((g) => o.value.only.delete(g));
18
+ function i(...s) {
19
+ s.forEach((p) => o.value.except.add(p)), s.forEach((p) => o.value.only.delete(p));
20
20
  }
21
- function u(c, g) {
22
- if (b(c) || g === !1)
23
- return i(c);
24
- if (!b(c) || g === !0)
25
- return l(c);
21
+ function u(s, p) {
22
+ if (b(s) || p === !1)
23
+ return i(s);
24
+ if (!b(s) || p === !0)
25
+ return l(s);
26
26
  }
27
- function b(c) {
28
- return o.value.all ? !o.value.except.has(c) : o.value.only.has(c);
27
+ function b(s) {
28
+ return o.value.all ? !o.value.except.has(s) : o.value.only.has(s);
29
29
  }
30
- const f = p(() => o.value.all && o.value.except.size === 0), A = p(() => o.value.only.size > 0 || f.value);
31
- function S(c) {
30
+ const f = g(() => o.value.all && o.value.except.size === 0), A = g(() => o.value.only.size > 0 || f.value);
31
+ function S(s) {
32
32
  return {
33
- "onUpdate:modelValue": (g) => {
34
- g ? l(c) : i(c);
33
+ "onUpdate:modelValue": (p) => {
34
+ p ? l(s) : i(s);
35
35
  },
36
- modelValue: b(c),
37
- value: c
36
+ modelValue: b(s),
37
+ value: s
38
38
  };
39
39
  }
40
40
  function k() {
41
41
  return {
42
- "onUpdate:modelValue": (c) => {
43
- c ? m() : d();
42
+ "onUpdate:modelValue": (s) => {
43
+ s ? m() : d();
44
44
  },
45
45
  modelValue: f.value,
46
46
  value: f.value
@@ -93,8 +93,8 @@ function O(o, m = {}) {
93
93
  let b;
94
94
  return (f) => {
95
95
  const A = J(o), S = J(m.maxWait);
96
- return d && u(d), A <= 0 || S !== void 0 && S <= 0 ? (l && (u(l), l = null), Promise.resolve(f())) : new Promise((k, c) => {
97
- i = m.rejectOnCancel ? c : k, b = f, S && !l && (l = setTimeout(() => {
96
+ return d && u(d), A <= 0 || S !== void 0 && S <= 0 ? (l && (u(l), l = null), Promise.resolve(f())) : new Promise((k, s) => {
97
+ i = m.rejectOnCancel ? s : k, b = f, S && !l && (l = setTimeout(() => {
98
98
  d && u(d), l = null, k(b());
99
99
  }, S)), d = setTimeout(() => {
100
100
  l && u(l), l = null, k(f());
@@ -109,7 +109,7 @@ function q(o, m = 200, d = {}) {
109
109
  );
110
110
  }
111
111
  function ee(o, m, d = {}) {
112
- const l = p(() => o[m]), i = p(
112
+ const l = g(() => o[m]), i = g(
113
113
  () => {
114
114
  var e;
115
115
  return ((e = l.value.filters) == null ? void 0 : e.map((n) => ({
@@ -119,17 +119,17 @@ function ee(o, m, d = {}) {
119
119
  bind: () => a(n.name)
120
120
  }))) ?? [];
121
121
  }
122
- ), u = p(
122
+ ), u = g(
123
123
  () => {
124
124
  var e;
125
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
128
  clear: (r = {}) => z(r),
129
- bind: () => s(n)
129
+ bind: () => c(n)
130
130
  }))) ?? [];
131
131
  }
132
- ), b = p(
132
+ ), b = g(
133
133
  () => {
134
134
  var e;
135
135
  return (e = l.value.searches) == null ? void 0 : e.map((n) => ({
@@ -139,17 +139,17 @@ function ee(o, m, d = {}) {
139
139
  bind: () => F(n)
140
140
  }));
141
141
  }
142
- ), f = p(
142
+ ), f = g(
143
143
  () => {
144
144
  var e;
145
145
  return ((e = l.value.filters) == null ? void 0 : e.filter(({ active: n }) => n)) ?? [];
146
146
  }
147
- ), A = p(
147
+ ), A = g(
148
148
  () => {
149
149
  var e;
150
150
  return (e = l.value.sorts) == null ? void 0 : e.find(({ active: n }) => n);
151
151
  }
152
- ), S = p(
152
+ ), S = g(
153
153
  () => {
154
154
  var e;
155
155
  return ((e = l.value.searches) == null ? void 0 : e.filter(({ active: n }) => n)) ?? [];
@@ -158,15 +158,15 @@ function ee(o, m, d = {}) {
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
- function g(e) {
164
+ function p(e) {
165
165
  if (!["", null, void 0, []].includes(e))
166
166
  return e;
167
167
  }
168
168
  function B(e) {
169
- return [k, c, g].reduce(
169
+ return [k, s, p].reduce(
170
170
  (n, r) => r(n),
171
171
  e
172
172
  );
@@ -233,12 +233,12 @@ function ee(o, m, d = {}) {
233
233
  ...d,
234
234
  ...r,
235
235
  data: {
236
- [l.value.config.sorts]: g(v.next)
236
+ [l.value.config.sorts]: p(v.next)
237
237
  }
238
238
  });
239
239
  }
240
240
  function T(e, n = {}) {
241
- e = [c, g].reduce(
241
+ e = [s, p].reduce(
242
242
  (r, v) => v(r),
243
243
  e
244
244
  ), x.reload({
@@ -335,7 +335,7 @@ function ee(o, m, d = {}) {
335
335
  modelValue: v
336
336
  };
337
337
  }
338
- function s(e, n = {}) {
338
+ function c(e, n = {}) {
339
339
  const r = typeof e == "string" ? h(e) : e;
340
340
  if (!r) {
341
341
  console.warn(`Sort [${e}] does not exist.`);
@@ -400,11 +400,11 @@ function ee(o, m, d = {}) {
400
400
  clearMatch: D,
401
401
  reset: t,
402
402
  bindFilter: a,
403
- bindSort: s,
403
+ bindSort: c,
404
404
  bindSearch: V,
405
405
  bindMatch: F,
406
- stringValue: c,
407
- omitValue: g,
406
+ stringValue: s,
407
+ omitValue: p,
408
408
  toggleValue: j,
409
409
  delimitArray: k
410
410
  };
@@ -416,41 +416,41 @@ function le(o, m, d = {}, l = {}) {
416
416
  ...l,
417
417
  only: [...l.only ?? [], m.toString()]
418
418
  };
419
- const i = p(() => o[m]), u = X(), b = ee(o, m, l), f = p(() => i.value.config), A = p(() => i.value.meta), S = p(
419
+ const i = g(() => o[m]), u = X(), b = ee(o, m, l), f = g(() => i.value.config), A = g(() => i.value.meta), S = g(
420
420
  () => {
421
421
  var t;
422
- return ((t = i.value.columns) == null ? void 0 : t.filter(({ active: a, hidden: s }) => a && !s).map((a) => {
423
- var s;
422
+ return ((t = i.value.columns) == null ? void 0 : t.filter(({ active: a, hidden: c }) => a && !c).map((a) => {
423
+ var c;
424
424
  return {
425
425
  ...a,
426
- isSorting: (s = a.sort) == null ? void 0 : s.active,
426
+ isSorting: (c = a.sort) == null ? void 0 : c.active,
427
427
  toggleSort: (V = {}) => U(a, V)
428
428
  };
429
429
  })) ?? [];
430
430
  }
431
- ), k = p(
431
+ ), k = g(
432
432
  () => {
433
433
  var t;
434
434
  return ((t = i.value.columns) == null ? void 0 : t.filter(({ hidden: a }) => !a).map((a) => ({
435
435
  ...a,
436
- toggle: (s = {}) => N(a, s)
436
+ toggle: (c = {}) => N(a, c)
437
437
  }))) ?? [];
438
438
  }
439
- ), c = p(
439
+ ), s = g(
440
440
  () => i.value.records.map((t) => ({
441
- record: (({ actions: a, ...s }) => s)(t),
441
+ record: (({ actions: a, ...c }) => c)(t),
442
442
  /** Perform this action when the record is clicked */
443
443
  default: (a = {}) => {
444
- const s = t.actions.find(
444
+ const c = t.actions.find(
445
445
  (V) => V.default
446
446
  );
447
- s && W(s, t, a);
447
+ c && W(c, t, a);
448
448
  },
449
449
  /** The actions available for the record */
450
450
  actions: t.actions.map((a) => ({
451
451
  ...a,
452
452
  /** Executes this action */
453
- execute: (s = {}) => W(a, t, s)
453
+ execute: (c = {}) => W(a, t, c)
454
454
  })),
455
455
  /** Selects this record */
456
456
  select: () => u.select(y(t)),
@@ -464,43 +464,44 @@ function le(o, m, d = {}, l = {}) {
464
464
  bind: () => u.bind(y(t)),
465
465
  /** Get the value of the record for the column */
466
466
  value: (a) => {
467
- const s = t[K(a)];
468
- return s ? s.value : null;
467
+ console.log(a);
468
+ const c = t[K(a)];
469
+ return console.log(c), c ? c.value : null;
469
470
  },
470
471
  /** Get the extra data of the record for the column */
471
472
  extra: (a) => {
472
473
  var V;
473
- const s = (V = t[K(a)]) == null ? void 0 : V.extra;
474
- return s ? s.value : null;
474
+ const c = (V = t[K(a)]) == null ? void 0 : V.extra;
475
+ return c ? c.value : null;
475
476
  }
476
477
  }))
477
- ), g = p(
478
+ ), p = g(
478
479
  () => i.value.actions.bulk.map((t) => ({
479
480
  ...t,
480
481
  /** Executes this bulk action */
481
482
  execute: (a = {}) => L(t, a)
482
483
  }))
483
- ), B = p(
484
+ ), B = g(
484
485
  () => i.value.actions.page.map((t) => ({
485
486
  ...t,
486
487
  /** Executes this page action */
487
488
  execute: (a = {}) => M(t, a)
488
489
  }))
489
- ), j = p(
490
+ ), j = g(
490
491
  () => {
491
492
  var t;
492
493
  return ((t = i.value.recordsPerPage) == null ? void 0 : t.map((a) => ({
493
494
  ...a,
494
495
  /** Changes the number of records to display per page */
495
- apply: (s = {}) => T(a, s)
496
+ apply: (c = {}) => T(a, c)
496
497
  }))) ?? [];
497
498
  }
498
- ), C = p(
499
+ ), C = g(
499
500
  () => {
500
501
  var t;
501
502
  return (t = i.value.recordsPerPage) == null ? void 0 : t.find(({ active: a }) => a);
502
503
  }
503
- ), h = p(() => ({
504
+ ), h = g(() => ({
504
505
  ...i.value.paginator,
505
506
  next: (t = {}) => {
506
507
  "nextLink" in h.value && h.value.nextLink && w(h.value.nextLink, t);
@@ -520,7 +521,7 @@ function le(o, m, d = {}, l = {}) {
520
521
  navigate: (a = {}) => t.url && w(t.url, a)
521
522
  }))
522
523
  } : {}
523
- })), E = p(
524
+ })), E = g(
524
525
  () => i.value.records.length > 0 && i.value.records.every(
525
526
  (t) => u.selected(y(t))
526
527
  )
@@ -540,7 +541,7 @@ function le(o, m, d = {}, l = {}) {
540
541
  method: "get"
541
542
  });
542
543
  }
543
- function W(t, a, s = {}) {
544
+ function W(t, a, c = {}) {
544
545
  var F, e;
545
546
  I(
546
547
  t,
@@ -549,7 +550,7 @@ function le(o, m, d = {}, l = {}) {
549
550
  table: i.value.id,
550
551
  id: y(a)
551
552
  },
552
- s
553
+ c
553
554
  ) || (e = (F = d.recordActions) == null ? void 0 : F[t.name]) == null || e.call(F, a);
554
555
  }
555
556
  function L(t, a = {}) {
@@ -595,7 +596,7 @@ function le(o, m, d = {}, l = {}) {
595
596
  });
596
597
  }
597
598
  function N(t, a = {}) {
598
- const s = b.toggleValue(
599
+ const c = b.toggleValue(
599
600
  t.name,
600
601
  S.value.map(({ name: V }) => V)
601
602
  );
@@ -603,7 +604,7 @@ function le(o, m, d = {}, l = {}) {
603
604
  ...l,
604
605
  ...a,
605
606
  data: {
606
- [f.value.columns]: b.delimitArray(s)
607
+ [f.value.columns]: b.delimitArray(c)
607
608
  }
608
609
  });
609
610
  }
@@ -639,9 +640,9 @@ function le(o, m, d = {}, l = {}) {
639
640
  /** All of the table's columns */
640
641
  columns: k,
641
642
  /** The records of the table */
642
- records: c,
643
+ records: s,
643
644
  /** The available bulk actions */
644
- bulkActions: g,
645
+ bulkActions: p,
645
646
  /** The available page actions */
646
647
  pageActions: B,
647
648
  /** The available number of records to display per page */
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(w,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("vue"),require("@inertiajs/vue3")):typeof define=="function"&&define.amd?define(["exports","vue","@inertiajs/vue3"],c):(w=typeof globalThis<"u"?globalThis:w||self,c(w["@honed/table"]={},w.Vue,w.Inertia))})(this,function(w,c,b){"use strict";function _(){const o=c.ref({all:!1,only:new Set,except:new Set});function p(){o.value.all=!0,o.value.only.clear(),o.value.except.clear()}function v(){o.value.all=!1,o.value.only.clear(),o.value.except.clear()}function l(...s){s.forEach(g=>o.value.except.delete(g)),s.forEach(g=>o.value.only.add(g))}function i(...s){s.forEach(g=>o.value.except.add(g)),s.forEach(g=>o.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 o.value.all?!o.value.except.has(s):o.value.only.has(s)}const m=c.computed(()=>o.value.all&&o.value.except.size===0),A=c.computed(()=>o.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:o,hasSelected:A,selectAll:p,deselectAll:v,select:l,deselect:i,toggle:u,selected:x,bind:S,bindAll:k}}function D(o,p,v={},l={}){return o.route?(b.router.visit(o.route.href,{...l,method:o.route.method}),!0):o.action&&p?(b.router.post(p,{...v,name:o.name,type:o.type},l),!0):!1}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Y=()=>{};function Q(o,p){function v(...l){return new Promise((i,u)=>{Promise.resolve(o(()=>p.apply(this,l),{fn:p,thisArg:this,args:l})).then(i).catch(u)})}return v}function X(o,p={}){let v,l,i=Y;const u=m=>{clearTimeout(m),i(),i=Y};let x;return m=>{const A=c.toValue(o),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(o,p=200,v={}){return Q(X(p,v),o)}function Z(o,p,v={}){const l=c.computed(()=>o[p]),i=c.computed(()=>{var e;return((e=l.value.filters)==null?void 0:e.map(n=>({...n,apply:(r,f={})=>T(n,r,f),clear:(r={})=>N(n,r),bind:()=>a(n.name)})))??[]}),u=c.computed(()=>{var e;return((e=l.value.sorts)==null?void 0:e.map(n=>({...n,apply:(r={})=>M(n,n.direction,r),clear:(r={})=>z(r),bind:()=>d(n)})))??[]}),x=c.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:()=>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,r)=>r(n),e)}function C(e,n){return n=Array.isArray(n)?n:[n],n.includes(e)?n.filter(r=>r!==e):[...n,e]}function W(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(f=>f.name===e&&f.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 L(e){var n;return e?typeof e=="string"?(n=S.value)==null?void 0:n.some(r=>r.name===e):e.active:!!l.value.config.search}function q(e,n={}){const r=Object.fromEntries(Object.entries(e).map(([f,P])=>[f,I(P)]));b.router.reload({...v,...n,data:r})}function T(e,n,r={}){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,...r,data:{[f.name]:I(n)}})}function M(e,n=null,r={}){const f=typeof e=="string"?h(e,n):e;if(!f){console.warn(`Sort [${e}] does not exist.`);return}b.router.reload({...v,...r,data:{[l.value.config.sorts]:g(f.next)}})}function E(e,n={}){e=[s,g].reduce((r,f)=>f(r),e),b.router.reload({...v,...n,data:{[l.value.config.searches]:e}})}function U(e,n={}){if(!l.value.config.matches){console.warn("Matches key is not set.");return}const r=typeof e=="string"?F(e):e;if(!r){console.warn(`Match [${e}] does not exist.`);return}const f=C(r.name,S.value.map(({name:P})=>P));b.router.reload({...v,...n,data:{[l.value.config.matches]:k(f)}})}function N(e,n={}){T(e,void 0,n)}function z(e={}){b.router.reload({...v,...e,data:{[l.value.config.sorts]:void 0}})}function R(e={}){E(void 0,e)}function H(e={}){if(!l.value.config.matches){console.warn("Matches key is not set.");return}b.router.reload({...v,...e,data:{[l.value.config.matches]:void 0}})}function t(e={}){var n;b.router.reload({...v,...e,data:{[l.value.config.searches]:void 0,[l.value.config.sorts]:void 0,[l.value.config.matches]:void 0,...Object.fromEntries(((n=l.value.filters)==null?void 0:n.map(r=>[r.name,void 0]))??[])}})}function a(e,n={}){const r=typeof e=="string"?W(e):e;if(!r){console.warn(`Filter [${e}] does not exist.`);return}const f=r.value,{debounce:P=250,transform:G=J=>J,...$}=n;return{"onUpdate:modelValue":B(J=>{T(r,G(J),$)},P),modelValue:f}}function d(e,n={}){const r=typeof e=="string"?h(e):e;if(!r){console.warn(`Sort [${e}] does not exist.`);return}const{debounce:f=0,transform:P,...G}=n;return{onClick:B(()=>{var $;M(r,($=A.value)==null?void 0:$.direction,G)},f)}}function V(e={}){const{debounce:n=700,transform:r,...f}=e;return{"onUpdate:modelValue":B(P=>{E(P,f)},n),modelValue:l.value.config.search??""}}function j(e,n={}){const r=typeof e=="string"?F(e):e;if(!r){console.warn(`Match [${e}] does not exist.`);return}const{debounce:f=0,transform:P,...G}=n;return{"onUpdate:modelValue":B($=>{U($,G)},f),modelValue:L(r),value:r.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:L,apply:q,applyFilter:T,applySort:M,applySearch:E,applyMatch:U,clearFilter:N,clearSort:z,clearSearch:R,clearMatch:H,reset:t,bindFilter:a,bindSort:d,bindSearch:V,bindMatch:j,stringValue:s,omitValue:g,toggleValue:C,delimitArray:k}}function O(o,p,v={},l={}){if(!o||!p||!o[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(()=>o[p]),u=_(),x=Z(o,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:(V={})=>U(a,V)}}))??[]}),k=c.computed(()=>{var t;return((t=i.value.columns)==null?void 0:t.filter(({hidden:a})=>!a).map(a=>({...a,toggle:(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(V=>V.default);d&&q(d,t,a)},actions:t.actions.map(a=>({...a,execute:(d={})=>q(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=t[K(a)];return d?d.value:null},extra:a=>{var V;const d=(V=t[K(a)])==null?void 0:V.extra;return d?d.value:null}}))),g=c.computed(()=>i.value.actions.bulk.map(t=>({...t,execute:(a={})=>T(t,a)}))),I=c.computed(()=>i.value.actions.page.map(t=>({...t,execute:(a={})=>M(t,a)}))),C=c.computed(()=>{var t;return((t=i.value.recordsPerPage)==null?void 0:t.map(a=>({...a,apply:(d={})=>E(a,d)})))??[]}),W=c.computed(()=>{var t;return(t=i.value.recordsPerPage)==null?void 0:t.find(({active:a})=>a)}),h=c.computed(()=>({...i.value.paginator,next:(t={})=>{"nextLink"in h.value&&h.value.nextLink&&L(h.value.nextLink,t)},previous:(t={})=>{"prevLink"in h.value&&h.value.prevLink&&L(h.value.prevLink,t)},first:(t={})=>{"firstLink"in h.value&&h.value.firstLink&&L(h.value.firstLink,t)},last:(t={})=>{"lastLink"in h.value&&h.value.lastLink&&L(h.value.lastLink,t)},..."links"in i.value.paginator&&i.value.paginator.links?{links:i.value.paginator.links.map(t=>({...t,navigate:(a={})=>t.url&&L(t.url,a)}))}:{}})),F=c.computed(()=>i.value.records.length>0&&i.value.records.every(t=>u.selected(y(t))));function y(t){return t[m.value.record].value}function K(t){return typeof t=="string"?t:t.name}function L(t,a={}){b.router.visit(t,{preserveScroll:!0,preserveState:!0,...l,...a,method:"get"})}function q(t,a,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 M(t,a={}){D(t,m.value.endpoint,{table:i.value.id},a)}function E(t,a={}){b.router.reload({...l,...a,data:{[m.value.records]:t.value,[m.value.pages]:void 0}})}function U(t,a={}){t.sort&&b.router.reload({...l,...a,data:{[m.value.sorts]:x.omitValue(t.sort.next)}})}function N(t,a={}){const d=x.toggleValue(t.name,S.value.map(({name:V})=>V));b.router.reload({...l,...a,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})}w.useTable=O,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
1
+ (function(w,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("vue"),require("@inertiajs/vue3")):typeof define=="function"&&define.amd?define(["exports","vue","@inertiajs/vue3"],c):(w=typeof globalThis<"u"?globalThis:w||self,c(w["@honed/table"]={},w.Vue,w.Inertia))})(this,function(w,c,b){"use strict";function _(){const r=c.ref({all:!1,only:new Set,except:new Set});function m(){r.value.all=!0,r.value.only.clear(),r.value.except.clear()}function v(){r.value.all=!1,r.value.only.clear(),r.value.except.clear()}function l(...d){d.forEach(g=>r.value.except.delete(g)),d.forEach(g=>r.value.only.add(g))}function i(...d){d.forEach(g=>r.value.except.add(g)),d.forEach(g=>r.value.only.delete(g))}function u(d,g){if(x(d)||g===!1)return i(d);if(!x(d)||g===!0)return l(d)}function x(d){return r.value.all?!r.value.except.has(d):r.value.only.has(d)}const p=c.computed(()=>r.value.all&&r.value.except.size===0),A=c.computed(()=>r.value.only.size>0||p.value);function S(d){return{"onUpdate:modelValue":g=>{g?l(d):i(d)},modelValue:x(d),value:d}}function k(){return{"onUpdate:modelValue":d=>{d?m():v()},modelValue:p.value,value:p.value}}return{allSelected:p,selection:r,hasSelected:A,selectAll:m,deselectAll:v,select:l,deselect:i,toggle:u,selected:x,bind:S,bindAll:k}}function D(r,m,v={},l={}){return r.route?(b.router.visit(r.route.href,{...l,method:r.route.method}),!0):r.action&&m?(b.router.post(m,{...v,name:r.name,type:r.type},l),!0):!1}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Y=()=>{};function Q(r,m){function v(...l){return new Promise((i,u)=>{Promise.resolve(r(()=>m.apply(this,l),{fn:m,thisArg:this,args:l})).then(i).catch(u)})}return v}function X(r,m={}){let v,l,i=Y;const u=p=>{clearTimeout(p),i(),i=Y};let x;return p=>{const A=c.toValue(r),S=c.toValue(m.maxWait);return v&&u(v),A<=0||S!==void 0&&S<=0?(l&&(u(l),l=null),Promise.resolve(p())):new Promise((k,d)=>{i=m.rejectOnCancel?d:k,x=p,S&&!l&&(l=setTimeout(()=>{v&&u(v),l=null,k(x())},S)),v=setTimeout(()=>{l&&u(l),l=null,k(p())},A)})}}function B(r,m=200,v={}){return Q(X(m,v),r)}function Z(r,m,v={}){const l=c.computed(()=>r[m]),i=c.computed(()=>{var e;return((e=l.value.filters)==null?void 0:e.map(n=>({...n,apply:(o,f={})=>T(n,o,f),clear:(o={})=>N(n,o),bind:()=>a(n.name)})))??[]}),u=c.computed(()=>{var e;return((e=l.value.sorts)==null?void 0:e.map(n=>({...n,apply:(o={})=>M(n,n.direction,o),clear:(o={})=>z(o),bind:()=>s(n)})))??[]}),x=c.computed(()=>{var e;return(e=l.value.searches)==null?void 0:e.map(n=>({...n,apply:(o={})=>U(n,o),clear:(o={})=>U(n,o),bind:()=>j(n)}))}),p=c.computed(()=>{var e;return((e=l.value.filters)==null?void 0:e.filter(({active:n})=>n))??[]}),A=c.computed(()=>{var e;return(e=l.value.sorts)==null?void 0:e.find(({active:n})=>n)}),S=c.computed(()=>{var e;return((e=l.value.searches)==null?void 0:e.filter(({active:n})=>n))??[]});function k(e){return Array.isArray(e)?e.join(l.value.config.delimiter):e}function d(e){return typeof e!="string"?e:e.trim().replace(/\s+/g,"+")}function g(e){if(!["",null,void 0,[]].includes(e))return e}function I(e){return[k,d,g].reduce((n,o)=>o(n),e)}function C(e,n){return n=Array.isArray(n)?n:[n],n.includes(e)?n.filter(o=>o!==e):[...n,e]}function W(e){var n;return(n=l.value.filters)==null?void 0:n.find(o=>o.name===e)}function h(e,n=null){var o;return(o=l.value.sorts)==null?void 0:o.find(f=>f.name===e&&f.direction===n)}function F(e){var n;return(n=l.value.searches)==null?void 0:n.find(o=>o.name===e)}function y(e){return e?typeof e=="string"?p.value.some(n=>n.name===e):e.active:!!p.value.length}function K(e){var n;return e?typeof e=="string"?((n=A.value)==null?void 0:n.name)===e:e.active:!!A.value}function L(e){var n;return e?typeof e=="string"?(n=S.value)==null?void 0:n.some(o=>o.name===e):e.active:!!l.value.config.search}function q(e,n={}){const o=Object.fromEntries(Object.entries(e).map(([f,P])=>[f,I(P)]));b.router.reload({...v,...n,data:o})}function T(e,n,o={}){const f=typeof e=="string"?W(e):e;if(!f){console.warn(`Filter [${e}] does not exist.`);return}"multiple"in f&&f.multiple&&n!==void 0&&(n=C(n,f.value)),b.router.reload({...v,...o,data:{[f.name]:I(n)}})}function M(e,n=null,o={}){const f=typeof e=="string"?h(e,n):e;if(!f){console.warn(`Sort [${e}] does not exist.`);return}b.router.reload({...v,...o,data:{[l.value.config.sorts]:g(f.next)}})}function E(e,n={}){e=[d,g].reduce((o,f)=>f(o),e),b.router.reload({...v,...n,data:{[l.value.config.searches]:e}})}function U(e,n={}){if(!l.value.config.matches){console.warn("Matches key is not set.");return}const o=typeof e=="string"?F(e):e;if(!o){console.warn(`Match [${e}] does not exist.`);return}const f=C(o.name,S.value.map(({name:P})=>P));b.router.reload({...v,...n,data:{[l.value.config.matches]:k(f)}})}function N(e,n={}){T(e,void 0,n)}function z(e={}){b.router.reload({...v,...e,data:{[l.value.config.sorts]:void 0}})}function R(e={}){E(void 0,e)}function H(e={}){if(!l.value.config.matches){console.warn("Matches key is not set.");return}b.router.reload({...v,...e,data:{[l.value.config.matches]:void 0}})}function t(e={}){var n;b.router.reload({...v,...e,data:{[l.value.config.searches]:void 0,[l.value.config.sorts]:void 0,[l.value.config.matches]:void 0,...Object.fromEntries(((n=l.value.filters)==null?void 0:n.map(o=>[o.name,void 0]))??[])}})}function a(e,n={}){const o=typeof e=="string"?W(e):e;if(!o){console.warn(`Filter [${e}] does not exist.`);return}const f=o.value,{debounce:P=250,transform:G=J=>J,...$}=n;return{"onUpdate:modelValue":B(J=>{T(o,G(J),$)},P),modelValue:f}}function s(e,n={}){const o=typeof e=="string"?h(e):e;if(!o){console.warn(`Sort [${e}] does not exist.`);return}const{debounce:f=0,transform:P,...G}=n;return{onClick:B(()=>{var $;M(o,($=A.value)==null?void 0:$.direction,G)},f)}}function V(e={}){const{debounce:n=700,transform:o,...f}=e;return{"onUpdate:modelValue":B(P=>{E(P,f)},n),modelValue:l.value.config.search??""}}function j(e,n={}){const o=typeof e=="string"?F(e):e;if(!o){console.warn(`Match [${e}] does not exist.`);return}const{debounce:f=0,transform:P,...G}=n;return{"onUpdate:modelValue":B($=>{U($,G)},f),modelValue:L(o),value:o.name}}return{filters:i,sorts:u,searches:x,getFilter:W,getSort:h,getSearch:F,currentFilters:p,currentSort:A,currentSearches:S,isFiltering:y,isSorting:K,isSearching:L,apply:q,applyFilter:T,applySort:M,applySearch:E,applyMatch:U,clearFilter:N,clearSort:z,clearSearch:R,clearMatch:H,reset:t,bindFilter:a,bindSort:s,bindSearch:V,bindMatch:j,stringValue:d,omitValue:g,toggleValue:C,delimitArray:k}}function O(r,m,v={},l={}){if(!r||!m||!r[m])throw new Error("Table has not been provided with valid props and key.");l={...l,only:[...l.only??[],m.toString()]};const i=c.computed(()=>r[m]),u=_(),x=Z(r,m,l),p=c.computed(()=>i.value.config),A=c.computed(()=>i.value.meta),S=c.computed(()=>{var t;return((t=i.value.columns)==null?void 0:t.filter(({active:a,hidden:s})=>a&&!s).map(a=>{var s;return{...a,isSorting:(s=a.sort)==null?void 0:s.active,toggleSort:(V={})=>U(a,V)}}))??[]}),k=c.computed(()=>{var t;return((t=i.value.columns)==null?void 0:t.filter(({hidden:a})=>!a).map(a=>({...a,toggle:(s={})=>N(a,s)})))??[]}),d=c.computed(()=>i.value.records.map(t=>({record:(({actions:a,...s})=>s)(t),default:(a={})=>{const s=t.actions.find(V=>V.default);s&&q(s,t,a)},actions:t.actions.map(a=>({...a,execute:(s={})=>q(a,t,s)})),select:()=>u.select(y(t)),deselect:()=>u.deselect(y(t)),toggle:()=>u.toggle(y(t)),selected:u.selected(y(t)),bind:()=>u.bind(y(t)),value:a=>{console.log(a);const s=t[K(a)];return console.log(s),s?s.value:null},extra:a=>{var V;const s=(V=t[K(a)])==null?void 0:V.extra;return s?s.value:null}}))),g=c.computed(()=>i.value.actions.bulk.map(t=>({...t,execute:(a={})=>T(t,a)}))),I=c.computed(()=>i.value.actions.page.map(t=>({...t,execute:(a={})=>M(t,a)}))),C=c.computed(()=>{var t;return((t=i.value.recordsPerPage)==null?void 0:t.map(a=>({...a,apply:(s={})=>E(a,s)})))??[]}),W=c.computed(()=>{var t;return(t=i.value.recordsPerPage)==null?void 0:t.find(({active:a})=>a)}),h=c.computed(()=>({...i.value.paginator,next:(t={})=>{"nextLink"in h.value&&h.value.nextLink&&L(h.value.nextLink,t)},previous:(t={})=>{"prevLink"in h.value&&h.value.prevLink&&L(h.value.prevLink,t)},first:(t={})=>{"firstLink"in h.value&&h.value.firstLink&&L(h.value.firstLink,t)},last:(t={})=>{"lastLink"in h.value&&h.value.lastLink&&L(h.value.lastLink,t)},..."links"in i.value.paginator&&i.value.paginator.links?{links:i.value.paginator.links.map(t=>({...t,navigate:(a={})=>t.url&&L(t.url,a)}))}:{}})),F=c.computed(()=>i.value.records.length>0&&i.value.records.every(t=>u.selected(y(t))));function y(t){return t[p.value.record].value}function K(t){return typeof t=="string"?t:t.name}function L(t,a={}){b.router.visit(t,{preserveScroll:!0,preserveState:!0,...l,...a,method:"get"})}function q(t,a,s={}){var j,e;D(t,p.value.endpoint,{table:i.value.id,id:y(a)},s)||(e=(j=v.recordActions)==null?void 0:j[t.name])==null||e.call(j,a)}function T(t,a={}){D(t,p.value.endpoint,{table:i.value.id,all:u.selection.value.all,only:Array.from(u.selection.value.only),except:Array.from(u.selection.value.except)},a)}function M(t,a={}){D(t,p.value.endpoint,{table:i.value.id},a)}function E(t,a={}){b.router.reload({...l,...a,data:{[p.value.records]:t.value,[p.value.pages]:void 0}})}function U(t,a={}){t.sort&&b.router.reload({...l,...a,data:{[p.value.sorts]:x.omitValue(t.sort.next)}})}function N(t,a={}){const s=x.toggleValue(t.name,S.value.map(({name:V})=>V));b.router.reload({...l,...a,data:{[p.value.columns]:x.delimitArray(s)}})}function z(){u.select(...i.value.records.map(t=>y(t)))}function R(){u.deselect(...i.value.records.map(t=>y(t)))}function H(){return{"onUpdate:modelValue":t=>{t?z():R()},modelValue:F.value}}return c.reactive({getRecordKey:y,meta:A,headings:S,columns:k,records:d,bulkActions:g,pageActions:I,rowsPerPage:C,currentPage:W,paginator:h,executeInlineAction:q,executeBulkAction:T,executePageAction:M,applyPage:E,selection:u.selection,select:t=>u.select(y(t)),deselect:t=>u.deselect(y(t)),selectPage:z,deselectPage:R,toggle:t=>u.toggle(y(t)),selected:t=>u.selected(y(t)),selectAll:u.selectAll,deselectAll:u.deselectAll,isPageSelected:F,hasSelected:u.hasSelected,bindCheckbox:t=>u.bind(y(t)),bindPage:H,bindAll:u.bindAll,...x})}w.useTable=O,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@honed/table",
3
3
  "private": false,
4
- "version": "0.4.1",
4
+ "version": "0.4.2",
5
5
  "license": "MIT",
6
6
  "description": "-",
7
7
  "keywords": [