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