@honed/table 0.15.0 → 0.16.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.es.js CHANGED
@@ -1,135 +1,135 @@
1
- import { ref as te, computed as v, reactive as ee, toValue as Y } from "vue";
1
+ import { ref as ee, computed as f, toValue as X, reactive as te } from "vue";
2
2
  import { router as k } from "@inertiajs/vue3";
3
- import Q from "axios";
4
- function X(l, p = {}, c = {}) {
3
+ import Y from "axios";
4
+ function Q(l, m = {}, i = {}) {
5
5
  if (!l.href || !l.method)
6
6
  return !1;
7
7
  if (l.type === "inertia")
8
- l.method === "delete" ? k.delete(l.href, c) : k[l.method](l.href, p, c);
8
+ l.method === "delete" ? k.delete(l.href, i) : k[l.method](l.href, m, i);
9
9
  else {
10
- const u = (g) => {
10
+ const u = (p) => {
11
11
  var o;
12
- return (o = c.onError) == null ? void 0 : o.call(c, g);
12
+ return (o = i.onError) == null ? void 0 : o.call(i, p);
13
13
  };
14
- l.method === "get" ? window.location.href = l.href : l.method === "delete" ? Q.delete(l.href).catch(u) : Q[l.method](l.href, p).catch(u);
14
+ l.method === "get" ? window.location.href = l.href : l.method === "delete" ? Y.delete(l.href).catch(u) : Y[l.method](l.href, m).catch(u);
15
15
  }
16
16
  return !0;
17
17
  }
18
18
  function ne() {
19
- const l = te({
19
+ const l = ee({
20
20
  all: !1,
21
21
  only: /* @__PURE__ */ new Set(),
22
22
  except: /* @__PURE__ */ new Set()
23
23
  });
24
- function p() {
24
+ function m() {
25
25
  l.value.all = !0, l.value.only.clear(), l.value.except.clear();
26
26
  }
27
- function c() {
27
+ function i() {
28
28
  l.value.all = !1, l.value.only.clear(), l.value.except.clear();
29
29
  }
30
- function u(...d) {
31
- d.forEach((y) => l.value.except.delete(y)), d.forEach((y) => l.value.only.add(y));
30
+ function u(...v) {
31
+ v.forEach((h) => l.value.except.delete(h)), v.forEach((h) => l.value.only.add(h));
32
32
  }
33
- function g(...d) {
34
- d.forEach((y) => l.value.except.add(y)), d.forEach((y) => l.value.only.delete(y));
33
+ function p(...v) {
34
+ v.forEach((h) => l.value.except.add(h)), v.forEach((h) => l.value.only.delete(h));
35
35
  }
36
- function o(d, y) {
37
- if (b(d) || y === !1) return g(d);
38
- if (!b(d) || y === !0) return u(d);
36
+ function o(v, h) {
37
+ if (b(v) || h === !1) return p(v);
38
+ if (!b(v) || h === !0) return u(v);
39
39
  }
40
- function b(d) {
41
- return l.value.all ? !l.value.except.has(d) : l.value.only.has(d);
40
+ function b(v) {
41
+ return l.value.all ? !l.value.except.has(v) : l.value.only.has(v);
42
42
  }
43
- const s = v(() => l.value.all && l.value.except.size === 0), i = v(() => l.value.only.size > 0 || s.value);
44
- function _(d) {
43
+ const c = f(() => l.value.all && l.value.except.size === 0), _ = f(() => l.value.only.size > 0 || c.value);
44
+ function S(v) {
45
45
  return {
46
- "onUpdate:modelValue": (y) => {
47
- y ? u(d) : g(d);
46
+ "onUpdate:modelValue": (h) => {
47
+ h ? u(v) : p(v);
48
48
  },
49
- modelValue: b(d),
50
- value: d
49
+ modelValue: b(v),
50
+ value: v
51
51
  };
52
52
  }
53
53
  function x() {
54
54
  return {
55
- "onUpdate:modelValue": (d) => {
56
- d ? p() : c();
55
+ "onUpdate:modelValue": (v) => {
56
+ v ? m() : i();
57
57
  },
58
- modelValue: s.value
58
+ modelValue: c.value
59
59
  };
60
60
  }
61
61
  return {
62
- allSelected: s,
62
+ allSelected: c,
63
63
  selection: l,
64
- hasSelected: i,
65
- selectAll: p,
66
- deselectAll: c,
64
+ hasSelected: _,
65
+ selectAll: m,
66
+ deselectAll: i,
67
67
  select: u,
68
- deselect: g,
68
+ deselect: p,
69
69
  toggle: o,
70
70
  selected: b,
71
- bind: _,
71
+ bind: S,
72
72
  bindAll: x
73
73
  };
74
74
  }
75
75
  typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
76
76
  const Z = () => {
77
77
  };
78
- function le(l, p) {
79
- function c(...u) {
80
- return new Promise((g, o) => {
81
- Promise.resolve(l(() => p.apply(this, u), { fn: p, thisArg: this, args: u })).then(g).catch(o);
78
+ function le(l, m) {
79
+ function i(...u) {
80
+ return new Promise((p, o) => {
81
+ Promise.resolve(l(() => m.apply(this, u), { fn: m, thisArg: this, args: u })).then(p).catch(o);
82
82
  });
83
83
  }
84
- return c;
84
+ return i;
85
85
  }
86
- function ae(l, p = {}) {
87
- let c, u, g = Z;
88
- const o = (s) => {
89
- clearTimeout(s), g(), g = Z;
86
+ function ae(l, m = {}) {
87
+ let i, u, p = Z;
88
+ const o = (c) => {
89
+ clearTimeout(c), p(), p = Z;
90
90
  };
91
91
  let b;
92
- return (s) => {
93
- const i = Y(l), _ = Y(p.maxWait);
94
- return c && o(c), i <= 0 || _ !== void 0 && _ <= 0 ? (u && (o(u), u = null), Promise.resolve(s())) : new Promise((x, d) => {
95
- g = p.rejectOnCancel ? d : x, b = s, _ && !u && (u = setTimeout(() => {
96
- c && o(c), u = null, x(b());
97
- }, _)), c = setTimeout(() => {
98
- u && o(u), u = null, x(s());
99
- }, i);
92
+ return (c) => {
93
+ const _ = X(l), S = X(m.maxWait);
94
+ return i && o(i), _ <= 0 || S !== void 0 && S <= 0 ? (u && (o(u), u = null), Promise.resolve(c())) : new Promise((x, v) => {
95
+ p = m.rejectOnCancel ? v : x, b = c, S && !u && (u = setTimeout(() => {
96
+ i && o(i), u = null, x(b());
97
+ }, S)), i = setTimeout(() => {
98
+ u && o(u), u = null, x(c());
99
+ }, _);
100
100
  });
101
101
  };
102
102
  }
103
- function I(l, p = 200, c = {}) {
103
+ function I(l, m = 200, i = {}) {
104
104
  return le(
105
- ae(p, c),
105
+ ae(m, i),
106
106
  l
107
107
  );
108
108
  }
109
- function re(l, p, c = {}) {
110
- if (!(l != null && l[p]))
109
+ function re(l, m, i = {}) {
110
+ if (!(l != null && l[m]))
111
111
  throw new Error("The refine must be provided with valid props and key.");
112
- const u = v(() => l[p]), g = v(() => !!u.value._sort_key), o = v(() => !!u.value._search_key), b = v(() => !!u.value._match_key), s = v(
112
+ const u = f(() => l[m]), p = f(() => !!u.value._sort_key), o = f(() => !!u.value._search_key), b = f(() => !!u.value._match_key), c = f(
113
113
  () => {
114
114
  var t;
115
115
  return (t = u.value.filters) == null ? void 0 : t.map((n) => ({
116
116
  ...n,
117
- apply: (r, m = {}) => A(n, r, m),
117
+ apply: (r, d = {}) => V(n, r, d),
118
118
  clear: (r = {}) => O(n, r),
119
- bind: () => R(n.name)
119
+ bind: () => F(n.name)
120
120
  }));
121
121
  }
122
- ), i = v(
122
+ ), _ = f(
123
123
  () => {
124
124
  var t;
125
125
  return (t = u.value.sorts) == null ? void 0 : t.map((n) => ({
126
126
  ...n,
127
- apply: (r = {}) => L(n, n.direction, r),
127
+ apply: (r = {}) => T(n, n.direction, r),
128
128
  clear: (r = {}) => W(r),
129
129
  bind: () => z(n)
130
130
  }));
131
131
  }
132
- ), _ = v(
132
+ ), S = f(
133
133
  () => {
134
134
  var t;
135
135
  return (t = u.value.searches) == null ? void 0 : t.map((n) => ({
@@ -139,25 +139,25 @@ function re(l, p, c = {}) {
139
139
  bind: () => H(n)
140
140
  }));
141
141
  }
142
- ), x = v(
143
- () => s.value.filter(({ active: t }) => t)
144
- ), d = v(
145
- () => i.value.find(({ active: t }) => t)
146
- ), y = v(
147
- () => _.value.filter(({ active: t }) => t)
142
+ ), x = f(
143
+ () => c.value.filter(({ active: t }) => t)
144
+ ), v = f(
145
+ () => _.value.find(({ active: t }) => t)
146
+ ), h = f(
147
+ () => S.value.filter(({ active: t }) => t)
148
148
  );
149
- function T(t) {
149
+ function j(t) {
150
150
  return Array.isArray(t) ? t.join(u.value._delimiter) : t;
151
151
  }
152
- function P(t) {
152
+ function R(t) {
153
153
  return typeof t != "string" ? t : t.trim().replace(/\s+/g, "+");
154
154
  }
155
- function V(t) {
155
+ function A(t) {
156
156
  if (!["", null, void 0, []].includes(t))
157
157
  return t;
158
158
  }
159
- function j(t) {
160
- return [T, P, V].reduce(
159
+ function $(t) {
160
+ return [j, R, A].reduce(
161
161
  (n, r) => r(n),
162
162
  t
163
163
  );
@@ -165,70 +165,70 @@ function re(l, p, c = {}) {
165
165
  function B(t, n) {
166
166
  return n = Array.isArray(n) ? n : [n], n.includes(t) ? n.filter((r) => r !== t) : [...n, t];
167
167
  }
168
- function $(t) {
169
- return typeof t != "string" ? t : s.value.find(({ name: n }) => n === t);
168
+ function M(t) {
169
+ return typeof t != "string" ? t : c.value.find(({ name: n }) => n === t);
170
170
  }
171
171
  function U(t, n = null) {
172
- return typeof t != "string" ? t : i.value.find(
173
- ({ name: r, direction: m }) => r === t && m === n
172
+ return typeof t != "string" ? t : _.value.find(
173
+ ({ name: r, direction: d }) => r === t && d === n
174
174
  );
175
175
  }
176
176
  function C(t) {
177
- return typeof t != "string" ? t : _.value.find(({ name: n }) => n === t);
177
+ return typeof t != "string" ? t : S.value.find(({ name: n }) => n === t);
178
178
  }
179
179
  function J(t) {
180
180
  return t ? typeof t == "string" ? x.value.some((n) => n.name === t) : t.active : !!x.value.length;
181
181
  }
182
182
  function N(t) {
183
183
  var n;
184
- return t ? typeof t == "string" ? ((n = d.value) == null ? void 0 : n.name) === t : t.active : !!d.value;
184
+ return t ? typeof t == "string" ? ((n = v.value) == null ? void 0 : n.name) === t : t.active : !!v.value;
185
185
  }
186
186
  function D(t) {
187
187
  var n;
188
- return t ? typeof t == "string" ? (n = y.value) == null ? void 0 : n.some((r) => r.name === t) : t.active : !!u.value.term;
188
+ return t ? typeof t == "string" ? (n = h.value) == null ? void 0 : n.some((r) => r.name === t) : t.active : !!u.value.term;
189
189
  }
190
- function S(t, n = {}) {
190
+ function y(t, n = {}) {
191
191
  const r = Object.fromEntries(
192
- Object.entries(t).map(([m, e]) => [m, j(e)])
192
+ Object.entries(t).map(([d, e]) => [d, $(e)])
193
193
  );
194
194
  k.reload({
195
- ...c,
195
+ ...i,
196
196
  ...n,
197
197
  data: r
198
198
  });
199
199
  }
200
- function A(t, n, r = {}) {
201
- const m = $(t);
202
- if (!m) return console.warn(`Filter [${t}] does not exist.`);
200
+ function V(t, n, r = {}) {
201
+ const d = M(t);
202
+ if (!d) return console.warn(`Filter [${t}] does not exist.`);
203
203
  k.reload({
204
- ...c,
204
+ ...i,
205
205
  ...r,
206
206
  data: {
207
- [m.name]: j(n)
207
+ [d.name]: $(n)
208
208
  }
209
209
  });
210
210
  }
211
- function L(t, n = null, r = {}) {
212
- if (!g.value)
211
+ function T(t, n = null, r = {}) {
212
+ if (!p.value)
213
213
  return console.warn("Refine cannot perform sorting.");
214
- const m = U(t, n);
215
- if (!m) return console.warn(`Sort [${t}] does not exist.`);
214
+ const d = U(t, n);
215
+ if (!d) return console.warn(`Sort [${t}] does not exist.`);
216
216
  k.reload({
217
- ...c,
217
+ ...i,
218
218
  ...r,
219
219
  data: {
220
- [u.value._sort_key]: V(m.next)
220
+ [u.value._sort_key]: A(d.next)
221
221
  }
222
222
  });
223
223
  }
224
- function h(t, n = {}) {
224
+ function g(t, n = {}) {
225
225
  if (!o.value)
226
226
  return console.warn("Refine cannot perform searching.");
227
- t = [P, V].reduce(
228
- (r, m) => m(r),
227
+ t = [R, A].reduce(
228
+ (r, d) => d(r),
229
229
  t
230
230
  ), k.reload({
231
- ...c,
231
+ ...i,
232
232
  ...n,
233
233
  data: {
234
234
  [u.value._search_key]: t
@@ -240,22 +240,22 @@ function re(l, p, c = {}) {
240
240
  return console.warn("Refine cannot perform matching.");
241
241
  const r = C(t);
242
242
  if (!r) return console.warn(`Match [${t}] does not exist.`);
243
- const m = B(
243
+ const d = B(
244
244
  r.name,
245
- y.value.map(({ name: e }) => e)
245
+ h.value.map(({ name: e }) => e)
246
246
  );
247
247
  k.reload({
248
- ...c,
248
+ ...i,
249
249
  ...n,
250
250
  data: {
251
- [u.value._match_key]: T(m)
251
+ [u.value._match_key]: j(d)
252
252
  }
253
253
  });
254
254
  }
255
255
  function O(t, n = {}) {
256
- if (t) return A(t, null, n);
256
+ if (t) return V(t, null, n);
257
257
  k.reload({
258
- ...c,
258
+ ...i,
259
259
  ...n,
260
260
  data: Object.fromEntries(
261
261
  x.value.map(({ name: r }) => [r, null])
@@ -263,10 +263,10 @@ function re(l, p, c = {}) {
263
263
  });
264
264
  }
265
265
  function W(t = {}) {
266
- if (!g.value)
266
+ if (!p.value)
267
267
  return console.warn("Refine cannot perform sorting.");
268
268
  k.reload({
269
- ...c,
269
+ ...i,
270
270
  ...t,
271
271
  data: {
272
272
  [u.value._sort_key]: null
@@ -274,23 +274,23 @@ function re(l, p, c = {}) {
274
274
  });
275
275
  }
276
276
  function G(t = {}) {
277
- h(null, t);
277
+ g(null, t);
278
278
  }
279
279
  function K(t = {}) {
280
280
  if (!b.value)
281
281
  return console.warn("Refine cannot perform matching.");
282
282
  k.reload({
283
- ...c,
283
+ ...i,
284
284
  ...t,
285
285
  data: {
286
286
  [u.value._match_key]: null
287
287
  }
288
288
  });
289
289
  }
290
- function F(t = {}) {
290
+ function E(t = {}) {
291
291
  var n;
292
292
  k.reload({
293
- ...c,
293
+ ...i,
294
294
  ...t,
295
295
  data: {
296
296
  [u.value._search_key ?? ""]: void 0,
@@ -305,42 +305,42 @@ function re(l, p, c = {}) {
305
305
  }
306
306
  });
307
307
  }
308
- function R(t, n = {}) {
309
- const r = $(t);
308
+ function F(t, n = {}) {
309
+ const r = M(t);
310
310
  if (!r) return console.warn(`Filter [${t}] does not exist.`);
311
311
  const {
312
- debounce: m = 150,
313
- transform: e = (f) => f,
312
+ debounce: d = 150,
313
+ transform: e = (s) => s,
314
314
  ...a
315
315
  } = n;
316
316
  return {
317
- "onUpdate:modelValue": I((f) => {
318
- A(r, e(f), a);
319
- }, m),
317
+ "onUpdate:modelValue": I((s) => {
318
+ V(r, e(s), a);
319
+ }, d),
320
320
  modelValue: r.value
321
321
  };
322
322
  }
323
323
  function z(t, n = {}) {
324
- if (!g.value)
324
+ if (!p.value)
325
325
  return console.warn("Refine cannot perform sorting.");
326
326
  const r = U(t);
327
327
  if (!r) return console.warn(`Sort [${t}] does not exist.`);
328
- const { debounce: m = 0, transform: e, ...a } = n;
328
+ const { debounce: d = 0, transform: e, ...a } = n;
329
329
  return {
330
330
  onClick: I(() => {
331
- var f;
332
- L(r, (f = d.value) == null ? void 0 : f.direction, a);
333
- }, m)
331
+ var s;
332
+ T(r, (s = v.value) == null ? void 0 : s.direction, a);
333
+ }, d)
334
334
  };
335
335
  }
336
336
  function q(t = {}) {
337
337
  if (!o.value)
338
338
  return console.warn("Refine cannot perform searching.");
339
- const { debounce: n = 700, transform: r, ...m } = t;
339
+ const { debounce: n = 700, transform: r, ...d } = t;
340
340
  return {
341
341
  "onUpdate:modelValue": I(
342
342
  (e) => {
343
- h(e, m);
343
+ g(e, d);
344
344
  },
345
345
  n
346
346
  ),
@@ -352,98 +352,98 @@ function re(l, p, c = {}) {
352
352
  return console.warn("Refine cannot perform matching.");
353
353
  const r = C(t);
354
354
  if (!r) return console.warn(`Match [${t}] does not exist.`);
355
- const { debounce: m = 0, transform: e, ...a } = n;
355
+ const { debounce: d = 0, transform: e, ...a } = n;
356
356
  return {
357
- "onUpdate:modelValue": I((f) => {
358
- w(f, a);
359
- }, m),
357
+ "onUpdate:modelValue": I((s) => {
358
+ w(s, a);
359
+ }, d),
360
360
  modelValue: D(r),
361
361
  value: r.name
362
362
  };
363
363
  }
364
- return ee({
365
- filters: s,
366
- sorts: i,
367
- searches: _,
364
+ return {
365
+ filters: c,
366
+ sorts: _,
367
+ searches: S,
368
368
  currentFilters: x,
369
- currentSort: d,
370
- currentSearches: y,
371
- isSortable: g,
369
+ currentSort: v,
370
+ currentSearches: h,
371
+ isSortable: p,
372
372
  isSearchable: o,
373
373
  isMatchable: b,
374
374
  isFiltering: J,
375
375
  isSorting: N,
376
376
  isSearching: D,
377
- getFilter: $,
377
+ getFilter: M,
378
378
  getSort: U,
379
379
  getSearch: C,
380
- apply: S,
381
- applyFilter: A,
382
- applySort: L,
383
- applySearch: h,
380
+ apply: y,
381
+ applyFilter: V,
382
+ applySort: T,
383
+ applySearch: g,
384
384
  applyMatch: w,
385
385
  clearFilter: O,
386
386
  clearSort: W,
387
387
  clearSearch: G,
388
388
  clearMatch: K,
389
- reset: F,
390
- bindFilter: R,
389
+ reset: E,
390
+ bindFilter: F,
391
391
  bindSort: z,
392
392
  bindSearch: q,
393
393
  bindMatch: H,
394
- stringValue: P,
395
- omitValue: V,
394
+ stringValue: R,
395
+ omitValue: A,
396
396
  toggleValue: B,
397
- delimitArray: T
398
- });
397
+ delimitArray: j
398
+ };
399
399
  }
400
- function ce(l, p, c = {}) {
401
- if (!(l != null && l[p]))
400
+ function ce(l, m, i = {}) {
401
+ if (!(l != null && l[m]))
402
402
  throw new Error("The table must be provided with valid props and key.");
403
- const { recordOperations: u = {}, ...g } = {
404
- only: [...c.only ?? [], p.toString()],
405
- ...c
406
- }, o = v(() => l[p]), b = v(() => o.value._id), s = ne(), i = re(l, p, g), _ = v(() => o.value.meta), x = v(() => o.value.views ?? []), d = v(() => o.value.state ?? null), y = v(() => o.value.placeholder ?? null), T = v(() => !!o.value.state), P = v(
403
+ const { recordOperations: u = {}, ...p } = {
404
+ only: [...i.only ?? [], m.toString()],
405
+ ...i
406
+ }, o = f(() => l[m]), b = f(() => o.value._id), c = ne(), _ = re(l, m, p), S = f(() => o.value.meta), x = f(() => o.value.views ?? []), v = f(() => o.value.state ?? null), h = f(() => o.value.placeholder ?? null), j = f(() => !!o.value.state), R = f(
407
407
  () => !!o.value._page_key && !!o.value._record_key
408
- ), V = v(() => !!o.value._column_key), j = v(
408
+ ), A = f(() => !!o.value._column_key), $ = f(
409
409
  () => o.value.columns.filter(({ active: e, hidden: a }) => e && !a).map((e) => {
410
410
  var a;
411
411
  return {
412
412
  ...e,
413
413
  isSorting: !!((a = e.sort) != null && a.active),
414
- toggleSort: (f = {}) => i.applySort(e.sort, null, f)
414
+ toggleSort: (s = {}) => _.applySort(e.sort, null, s)
415
415
  };
416
416
  })
417
- ), B = v(
417
+ ), B = f(
418
418
  () => o.value.columns.filter(({ hidden: e }) => !e).map((e) => ({
419
419
  ...e,
420
420
  toggle: (a = {}) => t(e.name, a)
421
421
  }))
422
- ), $ = v(
422
+ ), M = f(
423
423
  () => o.value.records.map((e) => ({
424
424
  ...e,
425
425
  /** The operations available for the record */
426
426
  operations: e.operations.map((a) => ({
427
427
  ...a,
428
- execute: (f = {}) => R(a, e, f)
428
+ execute: (s = {}) => F(a, e, s)
429
429
  })),
430
430
  /** Determine if the record is selected */
431
- selected: s.selected(h(e)),
431
+ selected: c.selected(g(e)),
432
432
  /** Perform this operation when the record is clicked */
433
433
  default: (a = {}) => {
434
- const f = e.operations.find(
435
- ({ default: M }) => M
434
+ const s = e.operations.find(
435
+ ({ default: P }) => P
436
436
  );
437
- f && R(f, e, a);
437
+ s && F(s, e, a);
438
438
  },
439
439
  /** Selects this record */
440
- select: () => s.select(h(e)),
440
+ select: () => c.select(g(e)),
441
441
  /** Deselects this record */
442
- deselect: () => s.deselect(h(e)),
442
+ deselect: () => c.deselect(g(e)),
443
443
  /** Toggles the selection of this record */
444
- toggle: () => s.toggle(h(e)),
444
+ toggle: () => c.toggle(g(e)),
445
445
  /** Bind the record to a checkbox */
446
- bind: () => s.bind(h(e)),
446
+ bind: () => c.bind(g(e)),
447
447
  /** Get the entry of the record for the column */
448
448
  entry: (a) => w(e, a),
449
449
  /** Get the value of the record for the column */
@@ -451,105 +451,105 @@ function ce(l, p, c = {}) {
451
451
  /** Get the extra data of the record for the column */
452
452
  extra: (a) => W(e, a)
453
453
  }))
454
- ), U = v(() => !!o.value.operations.inline), C = v(
454
+ ), U = f(() => !!o.value.operations.inline), C = f(
455
455
  () => o.value.operations.bulk.map((e) => ({
456
456
  ...e,
457
457
  execute: (a = {}) => z(e, a)
458
458
  }))
459
- ), J = v(
459
+ ), J = f(
460
460
  () => o.value.operations.page.map((e) => ({
461
461
  ...e,
462
462
  execute: (a = {}) => q(e, a)
463
463
  }))
464
- ), N = v(
464
+ ), N = f(
465
465
  () => o.value.pages.find(({ active: e }) => e)
466
- ), D = v(() => o.value.pages), S = v(() => ({
466
+ ), D = f(() => o.value.pages), y = f(() => ({
467
467
  ...o.value.paginate,
468
468
  next: (e = {}) => {
469
- "nextLink" in S.value && S.value.nextLink && F(S.value.nextLink, e);
469
+ "nextLink" in y.value && y.value.nextLink && E(y.value.nextLink, e);
470
470
  },
471
471
  previous: (e = {}) => {
472
- "prevLink" in S.value && S.value.prevLink && F(S.value.prevLink, e);
472
+ "prevLink" in y.value && y.value.prevLink && E(y.value.prevLink, e);
473
473
  },
474
474
  first: (e = {}) => {
475
- "firstLink" in S.value && S.value.firstLink && F(S.value.firstLink, e);
475
+ "firstLink" in y.value && y.value.firstLink && E(y.value.firstLink, e);
476
476
  },
477
477
  last: (e = {}) => {
478
- "lastLink" in S.value && S.value.lastLink && F(S.value.lastLink, e);
478
+ "lastLink" in y.value && y.value.lastLink && E(y.value.lastLink, e);
479
479
  },
480
480
  ..."links" in o.value.paginate && o.value.paginate.links ? {
481
481
  links: o.value.paginate.links.map((e) => ({
482
482
  ...e,
483
- navigate: (a = {}) => e.url && F(e.url, a)
483
+ navigate: (a = {}) => e.url && E(e.url, a)
484
484
  }))
485
485
  } : {}
486
- })), A = v(
486
+ })), V = f(
487
487
  () => o.value.records.length > 0 && o.value.records.every(
488
- (e) => s.selected(h(e))
488
+ (e) => c.selected(g(e))
489
489
  )
490
490
  );
491
- function L(e) {
491
+ function T(e) {
492
492
  return typeof e == "string" ? e : e.name;
493
493
  }
494
- function h(e) {
494
+ function g(e) {
495
495
  return e._key;
496
496
  }
497
497
  function w(e, a) {
498
- const f = L(a);
499
- return e[f];
498
+ const s = T(a);
499
+ return e[s];
500
500
  }
501
501
  function O(e, a) {
502
- var f;
503
- return ((f = w(e, a)) == null ? void 0 : f.v) ?? null;
502
+ var s;
503
+ return ((s = w(e, a)) == null ? void 0 : s.v) ?? null;
504
504
  }
505
505
  function W(e, a) {
506
- var f;
507
- return (f = w(e, a)) == null ? void 0 : f.e;
506
+ var s;
507
+ return (s = w(e, a)) == null ? void 0 : s.e;
508
508
  }
509
509
  function G(e) {
510
- return { id: h(e) };
510
+ return { id: g(e) };
511
511
  }
512
512
  function K() {
513
513
  return {
514
- all: s.selection.value.all,
515
- only: Array.from(s.selection.value.only),
516
- except: Array.from(s.selection.value.except)
514
+ all: c.selection.value.all,
515
+ only: Array.from(c.selection.value.only),
516
+ except: Array.from(c.selection.value.except)
517
517
  };
518
518
  }
519
- function F(e, a = {}) {
519
+ function E(e, a = {}) {
520
520
  k.visit(e, {
521
521
  preserveScroll: !0,
522
522
  preserveState: !0,
523
- ...g,
523
+ ...p,
524
524
  ...a,
525
525
  method: "get"
526
526
  });
527
527
  }
528
- function R(e, a, f = {}) {
529
- var E;
530
- X(e, G(a), {
531
- ...c,
532
- ...f
533
- }) || (E = u == null ? void 0 : u[e.name]) == null || E.call(u, a);
528
+ function F(e, a, s = {}) {
529
+ var L;
530
+ Q(e, G(a), {
531
+ ...i,
532
+ ...s
533
+ }) || (L = u == null ? void 0 : u[e.name]) == null || L.call(u, a);
534
534
  }
535
535
  function z(e, a = {}) {
536
- return X(e, K(), {
537
- ...c,
536
+ return Q(e, K(), {
537
+ ...i,
538
538
  ...a,
539
- onSuccess: (f) => {
540
- var M, E;
541
- (M = a.onSuccess) == null || M.call(a, f), (E = c.onSuccess) == null || E.call(c, f), e.keep || s.deselectAll();
539
+ onSuccess: (s) => {
540
+ var P, L;
541
+ (P = a.onSuccess) == null || P.call(a, s), (L = i.onSuccess) == null || L.call(i, s), e.keep || c.deselectAll();
542
542
  }
543
543
  });
544
544
  }
545
- function q(e, a = {}, f = {}) {
546
- return X(e, a, { ...c, ...f });
545
+ function q(e, a = {}, s = {}) {
546
+ return Q(e, a, { ...i, ...s });
547
547
  }
548
548
  function H(e, a = {}) {
549
- if (!P.value)
549
+ if (!R.value)
550
550
  return console.warn("The table does not support pagination changes.");
551
551
  k.reload({
552
- ...g,
552
+ ...p,
553
553
  ...a,
554
554
  data: {
555
555
  [o.value._record_key]: e.value,
@@ -558,61 +558,61 @@ function ce(l, p, c = {}) {
558
558
  });
559
559
  }
560
560
  function t(e, a = {}) {
561
- if (!V.value)
561
+ if (!A.value)
562
562
  return console.warn("The table does not support column toggling.");
563
- const f = L(e);
564
- if (!f) return console.log(`Column [${e}] does not exist.`);
565
- const M = i.toggleValue(
566
- f,
567
- j.value.map(({ name: E }) => E)
563
+ const s = T(e);
564
+ if (!s) return console.log(`Column [${e}] does not exist.`);
565
+ const P = _.toggleValue(
566
+ s,
567
+ $.value.map(({ name: L }) => L)
568
568
  );
569
569
  k.reload({
570
- ...g,
570
+ ...p,
571
571
  ...a,
572
572
  data: {
573
- [o.value._column_key]: i.delimitArray(M)
573
+ [o.value._column_key]: _.delimitArray(P)
574
574
  }
575
575
  });
576
576
  }
577
577
  function n() {
578
- s.select(
578
+ c.select(
579
579
  ...o.value.records.map(
580
- (e) => h(e)
580
+ (e) => g(e)
581
581
  )
582
582
  );
583
583
  }
584
584
  function r() {
585
- s.deselect(
585
+ c.deselect(
586
586
  ...o.value.records.map(
587
- (e) => h(e)
587
+ (e) => g(e)
588
588
  )
589
589
  );
590
590
  }
591
- function m() {
591
+ function d() {
592
592
  return {
593
593
  "onUpdate:modelValue": (e) => {
594
594
  e ? n() : r();
595
595
  },
596
- modelValue: A.value
596
+ modelValue: V.value
597
597
  };
598
598
  }
599
- return ee({
599
+ return te({
600
600
  /** The identifier of the table */
601
601
  id: b,
602
602
  /** Table-specific metadata */
603
- meta: _,
603
+ meta: S,
604
604
  /** The views for the table */
605
605
  views: x,
606
606
  /** The empty state for the table */
607
- emptyState: d,
607
+ emptyState: v,
608
608
  /** The placeholder for the search term.*/
609
- placeholder: y,
609
+ placeholder: h,
610
610
  /** Whether the table is empty */
611
- isEmpty: T,
611
+ isEmpty: j,
612
612
  /** Whether the table supports changing the number of records to display per page */
613
- isPageable: P,
613
+ isPageable: R,
614
614
  /** Whether the table supports toggling columns */
615
- isToggleable: V,
615
+ isToggleable: A,
616
616
  /** Get the entry of the record for the column */
617
617
  getEntry: w,
618
618
  /** Get the value of the record for the column */
@@ -620,13 +620,13 @@ function ce(l, p, c = {}) {
620
620
  /** Get the extra data of the record for the column */
621
621
  getExtra: W,
622
622
  /** Retrieve a record's identifier */
623
- getRecordKey: h,
623
+ getRecordKey: g,
624
624
  /** The heading columns for the table */
625
- headings: j,
625
+ headings: $,
626
626
  /** All of the table's columns */
627
627
  columns: B,
628
628
  /** The records of the table */
629
- records: $,
629
+ records: M,
630
630
  /** Whether the table has record operations */
631
631
  inline: U,
632
632
  /** The available bulk operations */
@@ -638,9 +638,9 @@ function ce(l, p, c = {}) {
638
638
  /** The current record per page item */
639
639
  currentPage: N,
640
640
  /** The pagination metadata */
641
- paginator: S,
641
+ paginator: y,
642
642
  /** Execute an inline operation */
643
- executeInline: R,
643
+ executeInline: F,
644
644
  /** Execute a bulk operation */
645
645
  executeBulk: z,
646
646
  /** Execute a page operation */
@@ -652,70 +652,38 @@ function ce(l, p, c = {}) {
652
652
  /** Apply a new page by changing the number of records to display */
653
653
  applyPage: H,
654
654
  /** The current selection of records */
655
- selection: s.selection,
655
+ selection: c.selection,
656
656
  /** Select the given records */
657
- select: (e) => s.select(h(e)),
657
+ select: (e) => c.select(g(e)),
658
658
  /** Deselect the given records */
659
- deselect: (e) => s.deselect(h(e)),
659
+ deselect: (e) => c.deselect(g(e)),
660
660
  /** Select records on the current page */
661
661
  selectPage: n,
662
662
  /** Deselect records on the current page */
663
663
  deselectPage: r,
664
664
  /** Toggle the selection of the given records */
665
- toggle: (e) => s.toggle(h(e)),
665
+ toggle: (e) => c.toggle(g(e)),
666
666
  /** Determine if the given record is selected */
667
- selected: (e) => s.selected(h(e)),
667
+ selected: (e) => c.selected(g(e)),
668
668
  /** Select all records */
669
- selectAll: s.selectAll,
669
+ selectAll: c.selectAll,
670
670
  /** Deselect all records */
671
- deselectAll: s.deselectAll,
671
+ deselectAll: c.deselectAll,
672
672
  /** Whether all records on the current page are selected */
673
- isPageSelected: A,
673
+ isPageSelected: V,
674
674
  /** Determine if any records are selected */
675
- hasSelected: s.hasSelected,
675
+ hasSelected: c.hasSelected,
676
676
  /** Bind the given record to a checkbox */
677
- bindCheckbox: (e) => s.bind(h(e)),
677
+ bindCheckbox: (e) => c.bind(g(e)),
678
678
  /** Bind the select all checkbox to the current page */
679
- bindPage: m,
679
+ bindPage: d,
680
680
  /** Bind select all records to the checkbox */
681
- bindAll: s.bindAll,
682
- filters: i.filters,
683
- sorts: i.sorts,
684
- searches: i.searches,
685
- currentFilters: i.currentFilters,
686
- currentSort: i.currentSort,
687
- currentSearches: i.currentSearches,
688
- isSortable: i.isSortable,
689
- isSearchable: i.isSearchable,
690
- isMatchable: i.isMatchable,
691
- isFiltering: i.isFiltering,
692
- isSorting: i.isSorting,
693
- isSearching: i.isSearching,
694
- getFilter: i.getFilter,
695
- getSort: i.getSort,
696
- getSearch: i.getSearch,
697
- apply: i.apply,
698
- applyFilter: i.applyFilter,
699
- applySort: i.applySort,
700
- applySearch: i.applySearch,
701
- applyMatch: i.applyMatch,
702
- clearFilter: i.clearFilter,
703
- clearSort: i.clearSort,
704
- clearSearch: i.clearSearch,
705
- clearMatch: i.clearMatch,
706
- reset: i.reset,
707
- bindFilter: i.bindFilter,
708
- bindSort: i.bindSort,
709
- bindSearch: i.bindSearch,
710
- bindMatch: i.bindMatch,
711
- stringValue: i.stringValue,
712
- omitValue: i.omitValue,
713
- toggleValue: i.toggleValue,
714
- delimitArray: i.delimitArray
681
+ bindAll: c.bindAll,
682
+ ..._
715
683
  });
716
684
  }
717
- function se(l, p) {
718
- return l ? typeof l == "object" ? l.type === p : l === p : !1;
685
+ function se(l, m) {
686
+ return l ? typeof l == "object" ? l.type === m : l === m : !1;
719
687
  }
720
688
  export {
721
689
  se as is,
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(w,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("vue"),require("@inertiajs/vue3"),require("axios")):typeof define=="function"&&define.amd?define(["exports","vue","@inertiajs/vue3","axios"],u):(w=typeof globalThis<"u"?globalThis:w||self,u(w["@honed/table"]={},w.Vue,w.Inertia,w.axios))})(this,function(w,u,b,Q){"use strict";function N(r,v={},s={}){if(!r.href||!r.method)return!1;if(r.type==="inertia")r.method==="delete"?b.router.delete(r.href,s):b.router[r.method](r.href,v,s);else{const c=g=>{var o;return(o=s.onError)==null?void 0:o.call(s,g)};r.method==="get"?window.location.href=r.href:r.method==="delete"?Q.delete(r.href).catch(c):Q[r.method](r.href,v).catch(c)}return!0}function ee(){const r=u.ref({all:!1,only:new Set,except:new Set});function v(){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 c(...p){p.forEach(y=>r.value.except.delete(y)),p.forEach(y=>r.value.only.add(y))}function g(...p){p.forEach(y=>r.value.except.add(y)),p.forEach(y=>r.value.only.delete(y))}function o(p,y){if(k(p)||y===!1)return g(p);if(!k(p)||y===!0)return c(p)}function k(p){return r.value.all?!r.value.except.has(p):r.value.only.has(p)}const d=u.computed(()=>r.value.all&&r.value.except.size===0),i=u.computed(()=>r.value.only.size>0||d.value);function _(p){return{"onUpdate:modelValue":y=>{y?c(p):g(p)},modelValue:k(p),value:p}}function x(){return{"onUpdate:modelValue":p=>{p?v():s()},modelValue:d.value}}return{allSelected:d,selection:r,hasSelected:i,selectAll:v,deselectAll:s,select:c,deselect:g,toggle:o,selected:k,bind:_,bindAll:x}}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Z=()=>{};function te(r,v){function s(...c){return new Promise((g,o)=>{Promise.resolve(r(()=>v.apply(this,c),{fn:v,thisArg:this,args:c})).then(g).catch(o)})}return s}function ne(r,v={}){let s,c,g=Z;const o=d=>{clearTimeout(d),g(),g=Z};let k;return d=>{const i=u.toValue(r),_=u.toValue(v.maxWait);return s&&o(s),i<=0||_!==void 0&&_<=0?(c&&(o(c),c=null),Promise.resolve(d())):new Promise((x,p)=>{g=v.rejectOnCancel?p:x,k=d,_&&!c&&(c=setTimeout(()=>{s&&o(s),c=null,x(k())},_)),s=setTimeout(()=>{c&&o(c),c=null,x(d())},i)})}}function B(r,v=200,s={}){return te(ne(v,s),r)}function re(r,v,s={}){if(!(r!=null&&r[v]))throw new Error("The refine must be provided with valid props and key.");const c=u.computed(()=>r[v]),g=u.computed(()=>!!c.value._sort_key),o=u.computed(()=>!!c.value._search_key),k=u.computed(()=>!!c.value._match_key),d=u.computed(()=>{var t;return(t=c.value.filters)==null?void 0:t.map(n=>({...n,apply:(l,m={})=>F(n,l,m),clear:(l={})=>q(n,l),bind:()=>j(n.name)}))}),i=u.computed(()=>{var t;return(t=c.value.sorts)==null?void 0:t.map(n=>({...n,apply:(l={})=>L(n,n.direction,l),clear:(l={})=>W(l),bind:()=>z(n)}))}),_=u.computed(()=>{var t;return(t=c.value.searches)==null?void 0:t.map(n=>({...n,apply:(l={})=>V(n,l),clear:(l={})=>V(n,l),bind:()=>J(n)}))}),x=u.computed(()=>d.value.filter(({active:t})=>t)),p=u.computed(()=>i.value.find(({active:t})=>t)),y=u.computed(()=>_.value.filter(({active:t})=>t));function R(t){return Array.isArray(t)?t.join(c.value._delimiter):t}function E(t){return typeof t!="string"?t:t.trim().replace(/\s+/g,"+")}function A(t){if(!["",null,void 0,[]].includes(t))return t}function $(t){return[R,E,A].reduce((n,l)=>l(n),t)}function D(t,n){return n=Array.isArray(n)?n:[n],n.includes(t)?n.filter(l=>l!==t):[...n,t]}function U(t){return typeof t!="string"?t:d.value.find(({name:n})=>n===t)}function C(t,n=null){return typeof t!="string"?t:i.value.find(({name:l,direction:m})=>l===t&&m===n)}function O(t){return typeof t!="string"?t:_.value.find(({name:n})=>n===t)}function X(t){return t?typeof t=="string"?x.value.some(n=>n.name===t):t.active:!!x.value.length}function Y(t){var n;return t?typeof t=="string"?((n=p.value)==null?void 0:n.name)===t:t.active:!!p.value}function G(t){var n;return t?typeof t=="string"?(n=y.value)==null?void 0:n.some(l=>l.name===t):t.active:!!c.value.term}function S(t,n={}){const l=Object.fromEntries(Object.entries(t).map(([m,e])=>[m,$(e)]));b.router.reload({...s,...n,data:l})}function F(t,n,l={}){const m=U(t);if(!m)return console.warn(`Filter [${t}] does not exist.`);b.router.reload({...s,...l,data:{[m.name]:$(n)}})}function L(t,n=null,l={}){if(!g.value)return console.warn("Refine cannot perform sorting.");const m=C(t,n);if(!m)return console.warn(`Sort [${t}] does not exist.`);b.router.reload({...s,...l,data:{[c.value._sort_key]:A(m.next)}})}function h(t,n={}){if(!o.value)return console.warn("Refine cannot perform searching.");t=[E,A].reduce((l,m)=>m(l),t),b.router.reload({...s,...n,data:{[c.value._search_key]:t}})}function V(t,n={}){if(!k.value||!o.value)return console.warn("Refine cannot perform matching.");const l=O(t);if(!l)return console.warn(`Match [${t}] does not exist.`);const m=D(l.name,y.value.map(({name:e})=>e));b.router.reload({...s,...n,data:{[c.value._match_key]:R(m)}})}function q(t,n={}){if(t)return F(t,null,n);b.router.reload({...s,...n,data:Object.fromEntries(x.value.map(({name:l})=>[l,null]))})}function W(t={}){if(!g.value)return console.warn("Refine cannot perform sorting.");b.router.reload({...s,...t,data:{[c.value._sort_key]:null}})}function I(t={}){h(null,t)}function K(t={}){if(!k.value)return console.warn("Refine cannot perform matching.");b.router.reload({...s,...t,data:{[c.value._match_key]:null}})}function M(t={}){var n;b.router.reload({...s,...t,data:{[c.value._search_key??""]:void 0,[c.value._sort_key??""]:void 0,[c.value._match_key??""]:void 0,...Object.fromEntries(((n=c.value.filters)==null?void 0:n.map(l=>[l.name,void 0]))??[])}})}function j(t,n={}){const l=U(t);if(!l)return console.warn(`Filter [${t}] does not exist.`);const{debounce:m=150,transform:e=f=>f,...a}=n;return{"onUpdate:modelValue":B(f=>{F(l,e(f),a)},m),modelValue:l.value}}function z(t,n={}){if(!g.value)return console.warn("Refine cannot perform sorting.");const l=C(t);if(!l)return console.warn(`Sort [${t}] does not exist.`);const{debounce:m=0,transform:e,...a}=n;return{onClick:B(()=>{var f;L(l,(f=p.value)==null?void 0:f.direction,a)},m)}}function H(t={}){if(!o.value)return console.warn("Refine cannot perform searching.");const{debounce:n=700,transform:l,...m}=t;return{"onUpdate:modelValue":B(e=>{h(e,m)},n),modelValue:c.value.term??""}}function J(t,n={}){if(!k.value)return console.warn("Refine cannot perform matching.");const l=O(t);if(!l)return console.warn(`Match [${t}] does not exist.`);const{debounce:m=0,transform:e,...a}=n;return{"onUpdate:modelValue":B(f=>{V(f,a)},m),modelValue:G(l),value:l.name}}return u.reactive({filters:d,sorts:i,searches:_,currentFilters:x,currentSort:p,currentSearches:y,isSortable:g,isSearchable:o,isMatchable:k,isFiltering:X,isSorting:Y,isSearching:G,getFilter:U,getSort:C,getSearch:O,apply:S,applyFilter:F,applySort:L,applySearch:h,applyMatch:V,clearFilter:q,clearSort:W,clearSearch:I,clearMatch:K,reset:M,bindFilter:j,bindSort:z,bindSearch:H,bindMatch:J,stringValue:E,omitValue:A,toggleValue:D,delimitArray:R})}function ae(r,v,s={}){if(!(r!=null&&r[v]))throw new Error("The table must be provided with valid props and key.");const{recordOperations:c={},...g}={only:[...s.only??[],v.toString()],...s},o=u.computed(()=>r[v]),k=u.computed(()=>o.value._id),d=ee(),i=re(r,v,g),_=u.computed(()=>o.value.meta),x=u.computed(()=>o.value.views??[]),p=u.computed(()=>o.value.state??null),y=u.computed(()=>o.value.placeholder??null),R=u.computed(()=>!!o.value.state),E=u.computed(()=>!!o.value._page_key&&!!o.value._record_key),A=u.computed(()=>!!o.value._column_key),$=u.computed(()=>o.value.columns.filter(({active:e,hidden:a})=>e&&!a).map(e=>{var a;return{...e,isSorting:!!((a=e.sort)!=null&&a.active),toggleSort:(f={})=>i.applySort(e.sort,null,f)}})),D=u.computed(()=>o.value.columns.filter(({hidden:e})=>!e).map(e=>({...e,toggle:(a={})=>t(e.name,a)}))),U=u.computed(()=>o.value.records.map(e=>({...e,operations:e.operations.map(a=>({...a,execute:(f={})=>j(a,e,f)})),selected:d.selected(h(e)),default:(a={})=>{const f=e.operations.find(({default:P})=>P);f&&j(f,e,a)},select:()=>d.select(h(e)),deselect:()=>d.deselect(h(e)),toggle:()=>d.toggle(h(e)),bind:()=>d.bind(h(e)),entry:a=>V(e,a),value:a=>q(e,a),extra:a=>W(e,a)}))),C=u.computed(()=>!!o.value.operations.inline),O=u.computed(()=>o.value.operations.bulk.map(e=>({...e,execute:(a={})=>z(e,a)}))),X=u.computed(()=>o.value.operations.page.map(e=>({...e,execute:(a={})=>H(e,a)}))),Y=u.computed(()=>o.value.pages.find(({active:e})=>e)),G=u.computed(()=>o.value.pages),S=u.computed(()=>({...o.value.paginate,next:(e={})=>{"nextLink"in S.value&&S.value.nextLink&&M(S.value.nextLink,e)},previous:(e={})=>{"prevLink"in S.value&&S.value.prevLink&&M(S.value.prevLink,e)},first:(e={})=>{"firstLink"in S.value&&S.value.firstLink&&M(S.value.firstLink,e)},last:(e={})=>{"lastLink"in S.value&&S.value.lastLink&&M(S.value.lastLink,e)},..."links"in o.value.paginate&&o.value.paginate.links?{links:o.value.paginate.links.map(e=>({...e,navigate:(a={})=>e.url&&M(e.url,a)}))}:{}})),F=u.computed(()=>o.value.records.length>0&&o.value.records.every(e=>d.selected(h(e))));function L(e){return typeof e=="string"?e:e.name}function h(e){return e._key}function V(e,a){const f=L(a);return e[f]}function q(e,a){var f;return((f=V(e,a))==null?void 0:f.v)??null}function W(e,a){var f;return(f=V(e,a))==null?void 0:f.e}function I(e){return{id:h(e)}}function K(){return{all:d.selection.value.all,only:Array.from(d.selection.value.only),except:Array.from(d.selection.value.except)}}function M(e,a={}){b.router.visit(e,{preserveScroll:!0,preserveState:!0,...g,...a,method:"get"})}function j(e,a,f={}){var T;N(e,I(a),{...s,...f})||(T=c==null?void 0:c[e.name])==null||T.call(c,a)}function z(e,a={}){return N(e,K(),{...s,...a,onSuccess:f=>{var P,T;(P=a.onSuccess)==null||P.call(a,f),(T=s.onSuccess)==null||T.call(s,f),e.keep||d.deselectAll()}})}function H(e,a={},f={}){return N(e,a,{...s,...f})}function J(e,a={}){if(!E.value)return console.warn("The table does not support pagination changes.");b.router.reload({...g,...a,data:{[o.value._record_key]:e.value,[o.value._page_key]:void 0}})}function t(e,a={}){if(!A.value)return console.warn("The table does not support column toggling.");const f=L(e);if(!f)return console.log(`Column [${e}] does not exist.`);const P=i.toggleValue(f,$.value.map(({name:T})=>T));b.router.reload({...g,...a,data:{[o.value._column_key]:i.delimitArray(P)}})}function n(){d.select(...o.value.records.map(e=>h(e)))}function l(){d.deselect(...o.value.records.map(e=>h(e)))}function m(){return{"onUpdate:modelValue":e=>{e?n():l()},modelValue:F.value}}return u.reactive({id:k,meta:_,views:x,emptyState:p,placeholder:y,isEmpty:R,isPageable:E,isToggleable:A,getEntry:V,getValue:q,getExtra:W,getRecordKey:h,headings:$,columns:D,records:U,inline:C,bulk:O,page:X,pages:G,currentPage:Y,paginator:S,executeInline:j,executeBulk:z,executePage:H,getBulkData:K,getRecordData:I,applyPage:J,selection:d.selection,select:e=>d.select(h(e)),deselect:e=>d.deselect(h(e)),selectPage:n,deselectPage:l,toggle:e=>d.toggle(h(e)),selected:e=>d.selected(h(e)),selectAll:d.selectAll,deselectAll:d.deselectAll,isPageSelected:F,hasSelected:d.hasSelected,bindCheckbox:e=>d.bind(h(e)),bindPage:m,bindAll:d.bindAll,filters:i.filters,sorts:i.sorts,searches:i.searches,currentFilters:i.currentFilters,currentSort:i.currentSort,currentSearches:i.currentSearches,isSortable:i.isSortable,isSearchable:i.isSearchable,isMatchable:i.isMatchable,isFiltering:i.isFiltering,isSorting:i.isSorting,isSearching:i.isSearching,getFilter:i.getFilter,getSort:i.getSort,getSearch:i.getSearch,apply:i.apply,applyFilter:i.applyFilter,applySort:i.applySort,applySearch:i.applySearch,applyMatch:i.applyMatch,clearFilter:i.clearFilter,clearSort:i.clearSort,clearSearch:i.clearSearch,clearMatch:i.clearMatch,reset:i.reset,bindFilter:i.bindFilter,bindSort:i.bindSort,bindSearch:i.bindSearch,bindMatch:i.bindMatch,stringValue:i.stringValue,omitValue:i.omitValue,toggleValue:i.toggleValue,delimitArray:i.delimitArray})}function le(r,v){return r?typeof r=="object"?r.type===v:r===v:!1}w.is=le,w.useTable=ae,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
1
+ (function(w,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("vue"),require("@inertiajs/vue3"),require("axios")):typeof define=="function"&&define.amd?define(["exports","vue","@inertiajs/vue3","axios"],i):(w=typeof globalThis<"u"?globalThis:w||self,i(w["@honed/table"]={},w.Vue,w.Inertia,w.axios))})(this,function(w,i,b,Y){"use strict";function N(l,p={},c={}){if(!l.href||!l.method)return!1;if(l.type==="inertia")l.method==="delete"?b.router.delete(l.href,c):b.router[l.method](l.href,p,c);else{const u=v=>{var o;return(o=c.onError)==null?void 0:o.call(c,v)};l.method==="get"?window.location.href=l.href:l.method==="delete"?Y.delete(l.href).catch(u):Y[l.method](l.href,p).catch(u)}return!0}function ee(){const l=i.ref({all:!1,only:new Set,except:new Set});function p(){l.value.all=!0,l.value.only.clear(),l.value.except.clear()}function c(){l.value.all=!1,l.value.only.clear(),l.value.except.clear()}function u(...f){f.forEach(h=>l.value.except.delete(h)),f.forEach(h=>l.value.only.add(h))}function v(...f){f.forEach(h=>l.value.except.add(h)),f.forEach(h=>l.value.only.delete(h))}function o(f,h){if(k(f)||h===!1)return v(f);if(!k(f)||h===!0)return u(f)}function k(f){return l.value.all?!l.value.except.has(f):l.value.only.has(f)}const s=i.computed(()=>l.value.all&&l.value.except.size===0),_=i.computed(()=>l.value.only.size>0||s.value);function S(f){return{"onUpdate:modelValue":h=>{h?u(f):v(f)},modelValue:k(f),value:f}}function x(){return{"onUpdate:modelValue":f=>{f?p():c()},modelValue:s.value}}return{allSelected:s,selection:l,hasSelected:_,selectAll:p,deselectAll:c,select:u,deselect:v,toggle:o,selected:k,bind:S,bindAll:x}}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Z=()=>{};function te(l,p){function c(...u){return new Promise((v,o)=>{Promise.resolve(l(()=>p.apply(this,u),{fn:p,thisArg:this,args:u})).then(v).catch(o)})}return c}function ne(l,p={}){let c,u,v=Z;const o=s=>{clearTimeout(s),v(),v=Z};let k;return s=>{const _=i.toValue(l),S=i.toValue(p.maxWait);return c&&o(c),_<=0||S!==void 0&&S<=0?(u&&(o(u),u=null),Promise.resolve(s())):new Promise((x,f)=>{v=p.rejectOnCancel?f:x,k=s,S&&!u&&(u=setTimeout(()=>{c&&o(c),u=null,x(k())},S)),c=setTimeout(()=>{u&&o(u),u=null,x(s())},_)})}}function B(l,p=200,c={}){return te(ne(p,c),l)}function le(l,p,c={}){if(!(l!=null&&l[p]))throw new Error("The refine must be provided with valid props and key.");const u=i.computed(()=>l[p]),v=i.computed(()=>!!u.value._sort_key),o=i.computed(()=>!!u.value._search_key),k=i.computed(()=>!!u.value._match_key),s=i.computed(()=>{var t;return(t=u.value.filters)==null?void 0:t.map(n=>({...n,apply:(r,m={})=>P(n,r,m),clear:(r={})=>q(n,r),bind:()=>F(n.name)}))}),_=i.computed(()=>{var t;return(t=u.value.sorts)==null?void 0:t.map(n=>({...n,apply:(r={})=>R(n,n.direction,r),clear:(r={})=>W(r),bind:()=>z(n)}))}),S=i.computed(()=>{var t;return(t=u.value.searches)==null?void 0:t.map(n=>({...n,apply:(r={})=>V(n,r),clear:(r={})=>V(n,r),bind:()=>J(n)}))}),x=i.computed(()=>s.value.filter(({active:t})=>t)),f=i.computed(()=>_.value.find(({active:t})=>t)),h=i.computed(()=>S.value.filter(({active:t})=>t));function M(t){return Array.isArray(t)?t.join(u.value._delimiter):t}function j(t){return typeof t!="string"?t:t.trim().replace(/\s+/g,"+")}function A(t){if(!["",null,void 0,[]].includes(t))return t}function $(t){return[M,j,A].reduce((n,r)=>r(n),t)}function D(t,n){return n=Array.isArray(n)?n:[n],n.includes(t)?n.filter(r=>r!==t):[...n,t]}function U(t){return typeof t!="string"?t:s.value.find(({name:n})=>n===t)}function C(t,n=null){return typeof t!="string"?t:_.value.find(({name:r,direction:m})=>r===t&&m===n)}function O(t){return typeof t!="string"?t:S.value.find(({name:n})=>n===t)}function Q(t){return t?typeof t=="string"?x.value.some(n=>n.name===t):t.active:!!x.value.length}function X(t){var n;return t?typeof t=="string"?((n=f.value)==null?void 0:n.name)===t:t.active:!!f.value}function G(t){var n;return t?typeof t=="string"?(n=h.value)==null?void 0:n.some(r=>r.name===t):t.active:!!u.value.term}function y(t,n={}){const r=Object.fromEntries(Object.entries(t).map(([m,e])=>[m,$(e)]));b.router.reload({...c,...n,data:r})}function P(t,n,r={}){const m=U(t);if(!m)return console.warn(`Filter [${t}] does not exist.`);b.router.reload({...c,...r,data:{[m.name]:$(n)}})}function R(t,n=null,r={}){if(!v.value)return console.warn("Refine cannot perform sorting.");const m=C(t,n);if(!m)return console.warn(`Sort [${t}] does not exist.`);b.router.reload({...c,...r,data:{[u.value._sort_key]:A(m.next)}})}function g(t,n={}){if(!o.value)return console.warn("Refine cannot perform searching.");t=[j,A].reduce((r,m)=>m(r),t),b.router.reload({...c,...n,data:{[u.value._search_key]:t}})}function V(t,n={}){if(!k.value||!o.value)return console.warn("Refine cannot perform matching.");const r=O(t);if(!r)return console.warn(`Match [${t}] does not exist.`);const m=D(r.name,h.value.map(({name:e})=>e));b.router.reload({...c,...n,data:{[u.value._match_key]:M(m)}})}function q(t,n={}){if(t)return P(t,null,n);b.router.reload({...c,...n,data:Object.fromEntries(x.value.map(({name:r})=>[r,null]))})}function W(t={}){if(!v.value)return console.warn("Refine cannot perform sorting.");b.router.reload({...c,...t,data:{[u.value._sort_key]:null}})}function I(t={}){g(null,t)}function K(t={}){if(!k.value)return console.warn("Refine cannot perform matching.");b.router.reload({...c,...t,data:{[u.value._match_key]:null}})}function T(t={}){var n;b.router.reload({...c,...t,data:{[u.value._search_key??""]:void 0,[u.value._sort_key??""]:void 0,[u.value._match_key??""]:void 0,...Object.fromEntries(((n=u.value.filters)==null?void 0:n.map(r=>[r.name,void 0]))??[])}})}function F(t,n={}){const r=U(t);if(!r)return console.warn(`Filter [${t}] does not exist.`);const{debounce:m=150,transform:e=d=>d,...a}=n;return{"onUpdate:modelValue":B(d=>{P(r,e(d),a)},m),modelValue:r.value}}function z(t,n={}){if(!v.value)return console.warn("Refine cannot perform sorting.");const r=C(t);if(!r)return console.warn(`Sort [${t}] does not exist.`);const{debounce:m=0,transform:e,...a}=n;return{onClick:B(()=>{var d;R(r,(d=f.value)==null?void 0:d.direction,a)},m)}}function H(t={}){if(!o.value)return console.warn("Refine cannot perform searching.");const{debounce:n=700,transform:r,...m}=t;return{"onUpdate:modelValue":B(e=>{g(e,m)},n),modelValue:u.value.term??""}}function J(t,n={}){if(!k.value)return console.warn("Refine cannot perform matching.");const r=O(t);if(!r)return console.warn(`Match [${t}] does not exist.`);const{debounce:m=0,transform:e,...a}=n;return{"onUpdate:modelValue":B(d=>{V(d,a)},m),modelValue:G(r),value:r.name}}return{filters:s,sorts:_,searches:S,currentFilters:x,currentSort:f,currentSearches:h,isSortable:v,isSearchable:o,isMatchable:k,isFiltering:Q,isSorting:X,isSearching:G,getFilter:U,getSort:C,getSearch:O,apply:y,applyFilter:P,applySort:R,applySearch:g,applyMatch:V,clearFilter:q,clearSort:W,clearSearch:I,clearMatch:K,reset:T,bindFilter:F,bindSort:z,bindSearch:H,bindMatch:J,stringValue:j,omitValue:A,toggleValue:D,delimitArray:M}}function ae(l,p,c={}){if(!(l!=null&&l[p]))throw new Error("The table must be provided with valid props and key.");const{recordOperations:u={},...v}={only:[...c.only??[],p.toString()],...c},o=i.computed(()=>l[p]),k=i.computed(()=>o.value._id),s=ee(),_=le(l,p,v),S=i.computed(()=>o.value.meta),x=i.computed(()=>o.value.views??[]),f=i.computed(()=>o.value.state??null),h=i.computed(()=>o.value.placeholder??null),M=i.computed(()=>!!o.value.state),j=i.computed(()=>!!o.value._page_key&&!!o.value._record_key),A=i.computed(()=>!!o.value._column_key),$=i.computed(()=>o.value.columns.filter(({active:e,hidden:a})=>e&&!a).map(e=>{var a;return{...e,isSorting:!!((a=e.sort)!=null&&a.active),toggleSort:(d={})=>_.applySort(e.sort,null,d)}})),D=i.computed(()=>o.value.columns.filter(({hidden:e})=>!e).map(e=>({...e,toggle:(a={})=>t(e.name,a)}))),U=i.computed(()=>o.value.records.map(e=>({...e,operations:e.operations.map(a=>({...a,execute:(d={})=>F(a,e,d)})),selected:s.selected(g(e)),default:(a={})=>{const d=e.operations.find(({default:E})=>E);d&&F(d,e,a)},select:()=>s.select(g(e)),deselect:()=>s.deselect(g(e)),toggle:()=>s.toggle(g(e)),bind:()=>s.bind(g(e)),entry:a=>V(e,a),value:a=>q(e,a),extra:a=>W(e,a)}))),C=i.computed(()=>!!o.value.operations.inline),O=i.computed(()=>o.value.operations.bulk.map(e=>({...e,execute:(a={})=>z(e,a)}))),Q=i.computed(()=>o.value.operations.page.map(e=>({...e,execute:(a={})=>H(e,a)}))),X=i.computed(()=>o.value.pages.find(({active:e})=>e)),G=i.computed(()=>o.value.pages),y=i.computed(()=>({...o.value.paginate,next:(e={})=>{"nextLink"in y.value&&y.value.nextLink&&T(y.value.nextLink,e)},previous:(e={})=>{"prevLink"in y.value&&y.value.prevLink&&T(y.value.prevLink,e)},first:(e={})=>{"firstLink"in y.value&&y.value.firstLink&&T(y.value.firstLink,e)},last:(e={})=>{"lastLink"in y.value&&y.value.lastLink&&T(y.value.lastLink,e)},..."links"in o.value.paginate&&o.value.paginate.links?{links:o.value.paginate.links.map(e=>({...e,navigate:(a={})=>e.url&&T(e.url,a)}))}:{}})),P=i.computed(()=>o.value.records.length>0&&o.value.records.every(e=>s.selected(g(e))));function R(e){return typeof e=="string"?e:e.name}function g(e){return e._key}function V(e,a){const d=R(a);return e[d]}function q(e,a){var d;return((d=V(e,a))==null?void 0:d.v)??null}function W(e,a){var d;return(d=V(e,a))==null?void 0:d.e}function I(e){return{id:g(e)}}function K(){return{all:s.selection.value.all,only:Array.from(s.selection.value.only),except:Array.from(s.selection.value.except)}}function T(e,a={}){b.router.visit(e,{preserveScroll:!0,preserveState:!0,...v,...a,method:"get"})}function F(e,a,d={}){var L;N(e,I(a),{...c,...d})||(L=u==null?void 0:u[e.name])==null||L.call(u,a)}function z(e,a={}){return N(e,K(),{...c,...a,onSuccess:d=>{var E,L;(E=a.onSuccess)==null||E.call(a,d),(L=c.onSuccess)==null||L.call(c,d),e.keep||s.deselectAll()}})}function H(e,a={},d={}){return N(e,a,{...c,...d})}function J(e,a={}){if(!j.value)return console.warn("The table does not support pagination changes.");b.router.reload({...v,...a,data:{[o.value._record_key]:e.value,[o.value._page_key]:void 0}})}function t(e,a={}){if(!A.value)return console.warn("The table does not support column toggling.");const d=R(e);if(!d)return console.log(`Column [${e}] does not exist.`);const E=_.toggleValue(d,$.value.map(({name:L})=>L));b.router.reload({...v,...a,data:{[o.value._column_key]:_.delimitArray(E)}})}function n(){s.select(...o.value.records.map(e=>g(e)))}function r(){s.deselect(...o.value.records.map(e=>g(e)))}function m(){return{"onUpdate:modelValue":e=>{e?n():r()},modelValue:P.value}}return i.reactive({id:k,meta:S,views:x,emptyState:f,placeholder:h,isEmpty:M,isPageable:j,isToggleable:A,getEntry:V,getValue:q,getExtra:W,getRecordKey:g,headings:$,columns:D,records:U,inline:C,bulk:O,page:Q,pages:G,currentPage:X,paginator:y,executeInline:F,executeBulk:z,executePage:H,getBulkData:K,getRecordData:I,applyPage:J,selection:s.selection,select:e=>s.select(g(e)),deselect:e=>s.deselect(g(e)),selectPage:n,deselectPage:r,toggle:e=>s.toggle(g(e)),selected:e=>s.selected(g(e)),selectAll:s.selectAll,deselectAll:s.deselectAll,isPageSelected:P,hasSelected:s.hasSelected,bindCheckbox:e=>s.bind(g(e)),bindPage:m,bindAll:s.bindAll,..._})}function re(l,p){return l?typeof l=="object"?l.type===p:l===p:!1}w.is=re,w.useTable=ae,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.15.0",
4
+ "version": "0.16.0",
5
5
  "license": "MIT",
6
6
  "description": "-",
7
7
  "keywords": [
@@ -58,7 +58,7 @@
58
58
  },
59
59
  "peerDependencies": {
60
60
  "@honed/action": "^0.14.0",
61
- "@honed/refine": "^0.9.0",
61
+ "@honed/refine": "^0.10.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",